No longer using string to represent vertex attr.
This commit is contained in:
parent
bfc78434f5
commit
8ecd91715e
2
external/gamekit
vendored
2
external/gamekit
vendored
@ -1 +1 @@
|
||||
Subproject commit 4e596b89a75ba47870c6919c6de8d486752394df
|
||||
Subproject commit 5deae1a0ea6cc21ed88bda8104b78bc6b8f733c1
|
@ -40,15 +40,15 @@ struct Vertex {
|
||||
|
||||
namespace VertexAttribute {
|
||||
enum {
|
||||
Coord3d = 8,
|
||||
TexCoord = 16,
|
||||
Color = 32,
|
||||
Normal = 64,
|
||||
LightValue = 128,
|
||||
AmbientOcclusion = 256,
|
||||
Coord3d = 3,
|
||||
TexCoord = 4,
|
||||
Color = 5,
|
||||
Normal = 6,
|
||||
LightValue = 7,
|
||||
AmbientOcclusion = 8,
|
||||
|
||||
Basic = Coord3d | TexCoord | Color,
|
||||
All = Basic | Normal | LightValue | AmbientOcclusion
|
||||
Basic = (1 << Coord3d) | (1 << TexCoord) | (1 << Color),
|
||||
All = Basic | (1 << Normal) | (1 << LightValue) | (1 << AmbientOcclusion)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <gk/core/GameClock.hpp>
|
||||
#include <gk/gl/GLCheck.hpp>
|
||||
#include <gk/gl/Texture.hpp>
|
||||
#include <gk/gl/Vertex.hpp>
|
||||
#include <gk/resource/ResourceHandler.hpp>
|
||||
|
||||
#include "CelestialObject.hpp"
|
||||
@ -47,7 +48,7 @@ void CelestialObject::updateVertexBuffer() const {
|
||||
return;
|
||||
}
|
||||
|
||||
Vertex vertices[4] = {
|
||||
gk::Vertex vertices[4] = {
|
||||
// Rectangle vertices
|
||||
{{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 *= getTransform();
|
||||
|
||||
states.vertexAttributes = VertexAttribute::All;
|
||||
states.vertexAttributes = gk::VertexAttribute::All;
|
||||
|
||||
if (m_texture)
|
||||
states.texture = m_texture;
|
||||
|
@ -24,6 +24,7 @@
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <gk/gl/RenderStates.hpp>
|
||||
#include <gk/resource/ResourceHandler.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.texture = &m_font.texture();
|
||||
states.vertexAttributes = VertexAttribute::Basic;
|
||||
states.vertexAttributes = gk::VertexAttribute::All;
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
@ -88,7 +89,7 @@ void Text::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
void Text::updateVertexBuffer() const {
|
||||
if (!m_isUpdateNeeded) return;
|
||||
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<gk::Vertex> vertices;
|
||||
|
||||
u32 x = 0;
|
||||
u32 y = 0;
|
||||
@ -134,7 +135,7 @@ void Text::updateVertexBuffer() const {
|
||||
m_verticesCount = vertices.size();
|
||||
|
||||
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);
|
||||
|
||||
m_size.x = std::max(x, maxX);
|
||||
@ -146,7 +147,7 @@ void Text::updateVertexBuffer() const {
|
||||
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] = {
|
||||
{1, 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) {
|
||||
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[1] = y + coords[i][1] * m_font.getTileSize().y;
|
||||
|
@ -30,10 +30,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <gk/gl/Vertex.hpp>
|
||||
#include <gk/graphics/RectangleShape.hpp>
|
||||
|
||||
#include "Vertex.hpp"
|
||||
|
||||
class Font;
|
||||
|
||||
class Text : public gk::Drawable, public gk::Transformable {
|
||||
@ -64,7 +63,7 @@ class Text : public gk::Drawable, public gk::Transformable {
|
||||
private:
|
||||
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;
|
||||
|
||||
|
@ -119,7 +119,6 @@ void HUD::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
states.shader = &m_shader;
|
||||
states.projectionMatrix = m_orthoMatrix;
|
||||
states.viewMatrix = gk::Transform::Identity;
|
||||
states.vertexAttributes = VertexAttribute::Basic;
|
||||
|
||||
states.transform *= getTransform();
|
||||
|
||||
|
@ -203,11 +203,17 @@ void GameState::update() {
|
||||
}
|
||||
|
||||
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_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/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_fbo.loadShader("screen");
|
||||
|
Loading…
x
Reference in New Issue
Block a user