Browse Source

rename instances of model_matrix to node_matrix

model matrix is the transform that should be applied at the entity
level. Anything with and entity as parent should be transformed with a
node matrix
main
cinnaboot 5 years ago
parent
commit
8d0f3be381
  1. BIN
      data/colored_vertices.frag
  2. BIN
      data/colored_vertices.vert
  3. BIN
      data/debug.vert
  4. BIN
      data/shader.frag
  5. BIN
      data/shader.vert
  6. 11
      src/entity.cpp
  7. 2
      src/entity.h
  8. 12
      src/shader.cpp
  9. 8
      src/shader.h
  10. 3
      src/tangerine.cpp
  11. 5
      src/tangerine.h

BIN
data/colored_vertices.frag (Stored with Git LFS)

Binary file not shown.

BIN
data/colored_vertices.vert (Stored with Git LFS)

Binary file not shown.

BIN
data/debug.vert (Stored with Git LFS)

Binary file not shown.

BIN
data/shader.frag (Stored with Git LFS)

Binary file not shown.

BIN
data/shader.vert (Stored with Git LFS)

Binary file not shown.

11
src/entity.cpp

@ -16,8 +16,8 @@ initEntity(Entity* e,
{ {
e->num_meshes = mdl->num_meshes; e->num_meshes = mdl->num_meshes;
e->meshes = ARENA_ALLOC(arena, GLmesh, e->num_meshes); e->meshes = ARENA_ALLOC(arena, GLmesh, e->num_meshes);
e->xform = ARENA_ALLOC(arena, glm::mat4, 1); e->model_xform = ARENA_ALLOC(arena, glm::mat4, 1);
*e->xform = glm::mat4(1.f); *e->model_xform = glm::mat4(1.f);
e->name = arenaCopyCStr(arena, name); e->name = arenaCopyCStr(arena, name);
e->diffuse_texture = getGLTexture(gl_ctx, mdl->diffuse_texture); e->diffuse_texture = getGLTexture(gl_ctx, mdl->diffuse_texture);
@ -44,18 +44,19 @@ initEntity(Entity* e,
void void
setEntityPosition(Entity* e, glm::vec3 pos) setEntityPosition(Entity* e, glm::vec3 pos)
{ {
*e->xform = glm::translate(*e->xform, pos); *e->model_xform = glm::translate(*e->model_xform, pos);
} }
void void
rotateEntity(Entity* e, glm::vec3 axis, float radians) rotateEntity(Entity* e, glm::vec3 axis, float radians)
{ {
*e->xform = glm::rotate(*e->xform, radians, axis); *e->model_xform = glm::rotate(*e->model_xform, radians, axis);
} }
void void
scaleEntity(Entity* e, float scale) scaleEntity(Entity* e, float scale)
{ {
*e->xform = glm::scale(*e->xform, glm::vec3(scale, scale, scale)); *e->model_xform =
glm::scale(*e->model_xform, glm::vec3(scale, scale, scale));
} }

2
src/entity.h

@ -12,7 +12,7 @@ struct Entity
u32 num_meshes; u32 num_meshes;
GLmesh* meshes; GLmesh* meshes;
GLTexture* diffuse_texture; // NOTE: pointer into gl_ctx->textures array GLTexture* diffuse_texture; // NOTE: pointer into gl_ctx->textures array
glm::mat4* xform; glm::mat4* model_xform;
char* name; char* name;
}; };

12
src/shader.cpp

@ -68,7 +68,7 @@ addShaderProgram(MemoryArena* arena,
// NOTE: we call this here because we can only make the GL_MAX* // NOTE: we call this here because we can only make the GL_MAX*
// queries after at least one shader has been linked // queries after at least one shader has been linked
initCTXSizes(gl_ctx); initCTXSizes(gl_ctx);
s->model_xform_id = glGetUniformLocation(s->prog_id, "model_xform"); s->node_xform_id = glGetUniformLocation(s->prog_id, "node_xform");
// TODO: add sampler uniform detection in dynamic shader parsing // TODO: add sampler uniform detection in dynamic shader parsing
s->sampler_id = glGetUniformLocation(s->prog_id, "sampler"); s->sampler_id = glGetUniformLocation(s->prog_id, "sampler");
glDetachShader(s->prog_id, vs_id); glDetachShader(s->prog_id, vs_id);
@ -166,14 +166,14 @@ getGLTexture(GLContext* gl_ctx, Texture* diffuse_img)
void void
renderVAO(GLmesh* glmesh, renderVAO(GLmesh* glmesh,
glm::mat4* model_xform, glm::mat4* node_xform,
ShaderProgram* shader, ShaderProgram* shader,
GLuint tex_id) GLuint tex_id)
{ {
glUseProgram(shader->prog_id); glUseProgram(shader->prog_id);
glBindVertexArray(glmesh->vao_id); glBindVertexArray(glmesh->vao_id);
glUniformMatrix4fv(shader->model_xform_id, 1, GL_FALSE, glUniformMatrix4fv(shader->node_xform_id, 1, GL_FALSE,
(float*) model_xform); (float*) node_xform);
if (tex_id > 0) { if (tex_id > 0) {
glBindTexture(GL_TEXTURE_2D, tex_id); glBindTexture(GL_TEXTURE_2D, tex_id);
@ -237,8 +237,8 @@ initGLmesh(const Mesh& m, u32 num_mappings, GLenum draw_mode)
glm.num_vertex_attrib_buffers = num_mappings; glm.num_vertex_attrib_buffers = num_mappings;
glm.vertex_attrib_buffers = UTIL_ALLOC(num_mappings, GLBuffer); glm.vertex_attrib_buffers = UTIL_ALLOC(num_mappings, GLBuffer);
glm.element_buf = UTIL_ALLOC(1, GLBuffer); glm.element_buf = UTIL_ALLOC(1, GLBuffer);
glm.model_xform = UTIL_ALLOC(1, glm::mat4); glm.node_xform = UTIL_ALLOC(1, glm::mat4);
*glm.model_xform = glm::mat4(1); *glm.node_xform = glm::mat4(1);
return glm; return glm;
} }

8
src/shader.h

@ -64,7 +64,7 @@ struct ShaderProgram
{ {
GLuint prog_id; GLuint prog_id;
GLuint xforms_ubo_id; GLuint xforms_ubo_id;
GLuint model_xform_id; GLuint node_xform_id;
GLint sampler_id; GLint sampler_id;
u32 num_blocks; u32 num_blocks;
@ -131,7 +131,7 @@ struct GLmesh
GLenum draw_mode; // NOTE: GL_LINES, GL_TRIANGLES GLenum draw_mode; // NOTE: GL_LINES, GL_TRIANGLES
GLenum usage; // NOTE: GL_STATIC_DRAW, GL_DYNAMIC_DRAW GLenum usage; // NOTE: GL_STATIC_DRAW, GL_DYNAMIC_DRAW
glm::mat4* model_xform; glm::mat4* node_xform;
u32 num_vertex_attrib_buffers; u32 num_vertex_attrib_buffers;
GLBuffer* vertex_attrib_buffers; GLBuffer* vertex_attrib_buffers;
@ -164,7 +164,7 @@ const glm::vec3 DEFAULT_LOOK_POS = { 0, 0, 0 };
// NOTE: every shader program is assumed to have one uniform block named // NOTE: every shader program is assumed to have one uniform block named
// "matrices" that contains the projection and view matrices, and one uniform // "matrices" that contains the projection and view matrices, and one uniform
// named "model_xform" for the model matrix // named "node_xform" for the node matrix
bool addShaderProgram(MemoryArena* arena, bool addShaderProgram(MemoryArena* arena,
GLContext* gl_ctx, GLContext* gl_ctx,
const char* vs, const char* vs,
@ -182,7 +182,7 @@ ShaderProgram* getFreeShader(GLContext* gl_ctx);
GLTexture* getGLTexture(GLContext* gl_ctx, Texture* diffuse_img); GLTexture* getGLTexture(GLContext* gl_ctx, Texture* diffuse_img);
void renderVAO(GLmesh* glmesh, void renderVAO(GLmesh* glmesh,
glm::mat4* model_xform, glm::mat4* node_xform,
ShaderProgram* shader, ShaderProgram* shader,
GLuint tex_id = 0); GLuint tex_id = 0);

3
src/tangerine.cpp

@ -174,7 +174,8 @@ renderFrame(RenderState* rs, const GLClearColor& clear_col)
for (u32 k = 0; k < e->num_meshes; k++) { for (u32 k = 0; k < e->num_meshes; k++) {
GLmesh& glm = e->meshes[k]; GLmesh& glm = e->meshes[k];
renderVAO(&glm, e->xform, rg->shader, e->diffuse_texture->id); renderVAO(&glm, e->model_xform, rg->shader,
e->diffuse_texture->id);
} }
} }
} }

5
src/tangerine.h

@ -14,8 +14,7 @@
/* /*
* === TODO: === * === TODO: ===
* - rename instances of 'model_xform' that refer to a mesh node to something * - move default shaders out of git-lfs
* like node_xform. model_xform should be reserved for the entity node
* - full lighting model * - full lighting model
* - test complex entities * - test complex entities
* - need a separate GLBufferToAttribMapping for each mesh on an entity * - need a separate GLBufferToAttribMapping for each mesh on an entity
@ -45,6 +44,8 @@
* - add a LOGF macro for printf style logging * - add a LOGF macro for printf style logging
* - replace instances of printf * - replace instances of printf
* - rename data structures to be in the new format, eg) UpperCaseStyleNames * - rename data structures to be in the new format, eg) UpperCaseStyleNames
* - rename instances of 'model_xform' that refer to a mesh node to something
* like node_xform. model_xform should be reserved for the entity node
*/ */

Loading…
Cancel
Save