diff --git a/src/shader.cpp b/src/shader.cpp index 4d6deae..3a03e6b 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -437,33 +437,39 @@ parseUniformBlocks(memory_arena* arena, shader_program* s, GLContext* gl_ctx) bool parseAttributes(memory_arena* arena, shader_program* s, GLContext* gl_ctx) { - // TODO: parse buffers (vert, normal, uv), glGetActiveAttrib() - /// printf("\n---------------------------------\n"); printf("%s(), FIXME: dumping attrib info for programe: %s\n", __FUNCTION__, s->name); - GLint active_attribs; - glGetProgramiv(s->prog_id, GL_ACTIVE_ATTRIBUTES, &active_attribs); - printf("active attributes: %d\n", active_attribs); + GLint num_attribs; + glGetProgramiv(s->prog_id, GL_ACTIVE_ATTRIBUTES, &num_attribs); + printf("active attributes: %d\n", num_attribs); - GLchar attrib_name[256]; + s->num_vertex_attribs = num_attribs; + s->vertex_attribs = ARENA_ALLOC(arena, GLVertexAttrib, num_attribs); + + GLchar attrib_name[256] = {0} ; GLsizei length; GLint size; GLenum type; - for (int i = 0; i < active_attribs; i++) { + for (int i = 0; i < num_attribs; i++) { glGetActiveAttrib(s->prog_id, i, sizeof(attrib_name), &length, &size, &type, attrib_name); GLint location = glGetAttribLocation(s->prog_id, attrib_name); printf("attrib idx: %d, location: %d, type: %s, name: %s \n", i, location, glEnumToString(type), attrib_name); - // TODO: create a gl_buffer for each vertex attrib... - // TODO: store attrib location on attrib struct + GLVertexAttrib* attrib = &s->vertex_attribs[i]; + attrib->data_type = type; + attrib->location = location; + attrib->name = arenaCopyCStr(arena, attrib_name, sizeof(attrib_name)); // TODO: replace POSITION, NORMAL, UV... etc enums in loadGLMesh() // with extra logic to detect mesh to shader mapping + // TODO: we still need a way to map the shader attribute name to a + // vertex buffer object... could maybe pass in an array of mappings to + // loadGLMesh? ie) [{ "position", gm.vert_buf_id }, ...] } printf("---------------------------------\n\n"); diff --git a/src/shader.h b/src/shader.h index 55686fe..d60abdf 100644 --- a/src/shader.h +++ b/src/shader.h @@ -18,6 +18,17 @@ struct gl_buffer char* name; }; +// NOTE: we need another struct for vertex attributes that mirrors gl_buffer +// because an attribute is associated with a shader_programe while a buffer is +// associated with the vertex data passed to glBufferData() +struct GLVertexAttrib +{ + GLenum data_type; + u32 num_components; + GLuint location; + char* name; +}; + struct gl_uniform { // NOTE: would be nice to use idx as the location parameter because it seems @@ -53,9 +64,8 @@ struct shader_program u32 num_uniforms; gl_uniform* uniforms; - // FIXME: better name would be vertex_attribs - u32 num_buffers; - gl_buffer* buffers; + u32 num_vertex_attribs; + GLVertexAttrib* vertex_attribs; char* name; u64 hash; // NOTE: hash of vs filpath + fs filepath concat