No longer using string to represent vertex attr.

This commit is contained in:
Quentin Bazin 2021-05-20 02:10:04 +02:00
parent bfc78434f5
commit 8ecd91715e
7 changed files with 27 additions and 21 deletions

2
external/gamekit vendored

@ -1 +1 @@
Subproject commit 4e596b89a75ba47870c6919c6de8d486752394df Subproject commit 5deae1a0ea6cc21ed88bda8104b78bc6b8f733c1

View File

@ -40,15 +40,15 @@ struct Vertex {
namespace VertexAttribute { namespace VertexAttribute {
enum { enum {
Coord3d = 8, Coord3d = 3,
TexCoord = 16, TexCoord = 4,
Color = 32, Color = 5,
Normal = 64, Normal = 6,
LightValue = 128, LightValue = 7,
AmbientOcclusion = 256, AmbientOcclusion = 8,
Basic = Coord3d | TexCoord | Color, Basic = (1 << Coord3d) | (1 << TexCoord) | (1 << Color),
All = Basic | Normal | LightValue | AmbientOcclusion All = Basic | (1 << Normal) | (1 << LightValue) | (1 << AmbientOcclusion)
}; };
} }

View File

@ -27,6 +27,7 @@
#include <gk/core/GameClock.hpp> #include <gk/core/GameClock.hpp>
#include <gk/gl/GLCheck.hpp> #include <gk/gl/GLCheck.hpp>
#include <gk/gl/Texture.hpp> #include <gk/gl/Texture.hpp>
#include <gk/gl/Vertex.hpp>
#include <gk/resource/ResourceHandler.hpp> #include <gk/resource/ResourceHandler.hpp>
#include "CelestialObject.hpp" #include "CelestialObject.hpp"
@ -47,7 +48,7 @@ void CelestialObject::updateVertexBuffer() const {
return; return;
} }
Vertex vertices[4] = { gk::Vertex vertices[4] = {
// Rectangle vertices // Rectangle vertices
{{0, m_width / 2.f, -m_height / 2.f, -1}}, {{0, m_width / 2.f, -m_height / 2.f, -1}},
{{0, -m_width / 2.f, -m_height / 2.f, -1}}, {{0, -m_width / 2.f, -m_height / 2.f, -1}},
@ -160,7 +161,7 @@ void CelestialObject::draw(gk::RenderTarget &target, gk::RenderStates states) co
states.transform.rotateY(-GameTime::getCurrentTime(m_rotationOffset, m_rotationSpeed) * 360.f); states.transform.rotateY(-GameTime::getCurrentTime(m_rotationOffset, m_rotationSpeed) * 360.f);
states.transform *= getTransform(); states.transform *= getTransform();
states.vertexAttributes = VertexAttribute::All; states.vertexAttributes = gk::VertexAttribute::All;
if (m_texture) if (m_texture)
states.texture = m_texture; states.texture = m_texture;

View File

@ -24,6 +24,7 @@
* *
* ===================================================================================== * =====================================================================================
*/ */
#include <gk/gl/RenderStates.hpp>
#include <gk/resource/ResourceHandler.hpp> #include <gk/resource/ResourceHandler.hpp>
#include "Color.hpp" #include "Color.hpp"
@ -77,7 +78,7 @@ void Text::draw(gk::RenderTarget &target, gk::RenderStates states) const {
states.transform.translate(m_padding.x, m_padding.y); states.transform.translate(m_padding.x, m_padding.y);
states.texture = &m_font.texture(); states.texture = &m_font.texture();
states.vertexAttributes = VertexAttribute::Basic; states.vertexAttributes = gk::VertexAttribute::All;
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
@ -88,7 +89,7 @@ void Text::draw(gk::RenderTarget &target, gk::RenderStates states) const {
void Text::updateVertexBuffer() const { void Text::updateVertexBuffer() const {
if (!m_isUpdateNeeded) return; if (!m_isUpdateNeeded) return;
std::vector<Vertex> vertices; std::vector<gk::Vertex> vertices;
u32 x = 0; u32 x = 0;
u32 y = 0; u32 y = 0;
@ -134,7 +135,7 @@ void Text::updateVertexBuffer() const {
m_verticesCount = vertices.size(); m_verticesCount = vertices.size();
gk::VertexBuffer::bind(&m_vbo); gk::VertexBuffer::bind(&m_vbo);
m_vbo.setData(sizeof(Vertex) * m_verticesCount, vertices.data(), GL_DYNAMIC_DRAW); m_vbo.setData(sizeof(gk::Vertex) * m_verticesCount, vertices.data(), GL_DYNAMIC_DRAW);
gk::VertexBuffer::bind(nullptr); gk::VertexBuffer::bind(nullptr);
m_size.x = std::max(x, maxX); m_size.x = std::max(x, maxX);
@ -146,7 +147,7 @@ void Text::updateVertexBuffer() const {
m_background.setSize(backgroundX, backgroundY); m_background.setSize(backgroundX, backgroundY);
} }
void Text::addCharacter(u32 x, u32 y, const gk::Color &color, u8 c, std::vector<Vertex> &vertices) const { void Text::addCharacter(u32 x, u32 y, const gk::Color &color, u8 c, std::vector<gk::Vertex> &vertices) const {
static const u8 coords[6][2] = { static const u8 coords[6][2] = {
{1, 0}, {1, 0},
{0, 0}, {0, 0},
@ -159,7 +160,7 @@ void Text::addCharacter(u32 x, u32 y, const gk::Color &color, u8 c, std::vector<
for (int i = 0 ; i < 6 ; ++i) { for (int i = 0 ; i < 6 ; ++i) {
vertices.emplace_back(); vertices.emplace_back();
Vertex &vertex = vertices.back(); gk::Vertex &vertex = vertices.back();
vertex.coord3d[0] = x + coords[i][0] * m_font.getTileSize().x; vertex.coord3d[0] = x + coords[i][0] * m_font.getTileSize().x;
vertex.coord3d[1] = y + coords[i][1] * m_font.getTileSize().y; vertex.coord3d[1] = y + coords[i][1] * m_font.getTileSize().y;

View File

@ -30,10 +30,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <gk/gl/Vertex.hpp>
#include <gk/graphics/RectangleShape.hpp> #include <gk/graphics/RectangleShape.hpp>
#include "Vertex.hpp"
class Font; class Font;
class Text : public gk::Drawable, public gk::Transformable { class Text : public gk::Drawable, public gk::Transformable {
@ -64,7 +63,7 @@ class Text : public gk::Drawable, public gk::Transformable {
private: private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override; void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
void addCharacter(u32 x, u32 y, const gk::Color &color, u8 c, std::vector<Vertex> &vertices) const; void addCharacter(u32 x, u32 y, const gk::Color &color, u8 c, std::vector<gk::Vertex> &vertices) const;
std::string m_string; std::string m_string;

View File

@ -119,7 +119,6 @@ void HUD::draw(gk::RenderTarget &target, gk::RenderStates states) const {
states.shader = &m_shader; states.shader = &m_shader;
states.projectionMatrix = m_orthoMatrix; states.projectionMatrix = m_orthoMatrix;
states.viewMatrix = gk::Transform::Identity; states.viewMatrix = gk::Transform::Identity;
states.vertexAttributes = VertexAttribute::Basic;
states.transform *= getTransform(); states.transform *= getTransform();

View File

@ -203,11 +203,17 @@ void GameState::update() {
} }
void GameState::initShaders() { void GameState::initShaders() {
m_shader.createProgram(); m_shader.createProgram(false);
m_shader.addShader(GL_VERTEX_SHADER, "resources/shaders/game.v.glsl"); m_shader.addShader(GL_VERTEX_SHADER, "resources/shaders/game.v.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/light.f.glsl"); m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/light.f.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/fog.f.glsl"); m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/fog.f.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/game.f.glsl"); m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/game.f.glsl");
m_shader.bindAttributeLocation(VertexAttribute::Coord3d, "coord3d");
m_shader.bindAttributeLocation(VertexAttribute::TexCoord, "texCoord");
m_shader.bindAttributeLocation(VertexAttribute::Color, "color");
m_shader.bindAttributeLocation(VertexAttribute::Normal, "normal");
m_shader.bindAttributeLocation(VertexAttribute::LightValue, "lightValue");
m_shader.bindAttributeLocation(VertexAttribute::AmbientOcclusion, "ambientOcclusion");
m_shader.linkProgram(); m_shader.linkProgram();
m_fbo.loadShader("screen"); m_fbo.loadShader("screen");