|
|
|
|
@ -82,10 +82,7 @@ addShaderProgram(memory_arena* arena,
|
|
|
|
|
block_idx, |
|
|
|
|
gl_ctx->xform_ubo.binding_idx); |
|
|
|
|
|
|
|
|
|
// FIXME: fill out new shader extra uniforms and buffers here
|
|
|
|
|
dumpShader(s->prog_id); |
|
|
|
|
printf("offset of RenderState.xforms: %lu bytes\n", |
|
|
|
|
offsetof(RenderState, xforms)); |
|
|
|
|
//dumpShader(s->prog_id);
|
|
|
|
|
parseShaderUniforms(arena, s, gl_ctx); |
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
@ -134,6 +131,53 @@ dumpTextFile(const char* filepath)
|
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NOTE: returns sizes based on GLSL layout std140
|
|
|
|
|
// https://www.khronos.org/opengl/wiki/Interface_Block_(GLSL)#Memory_layout
|
|
|
|
|
u32 |
|
|
|
|
getGLTypeSize(GLenum e) |
|
|
|
|
{ |
|
|
|
|
switch (e) { |
|
|
|
|
case 0x8b51: return 4 * sizeof(GLfloat); // GL_FLOAT_VEC3
|
|
|
|
|
case 0x8b52: return 4 * sizeof(GLfloat); // GL_FLOAT_VEC4
|
|
|
|
|
case 0x8b5c: return 16 * sizeof(GLfloat); // GL_FLOAT_MAT4
|
|
|
|
|
default: return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl_uniform |
|
|
|
|
parseUniform(memory_arena* arena, shader_program* s, u32 uniform_idx) |
|
|
|
|
{ |
|
|
|
|
assert(uniform_idx < s->num_uniforms); |
|
|
|
|
gl_uniform& unif = s->uniforms[uniform_idx]; |
|
|
|
|
|
|
|
|
|
GLchar unif_name[256] = {0}; |
|
|
|
|
GLsizei length; |
|
|
|
|
GLint size; |
|
|
|
|
GLenum type; |
|
|
|
|
|
|
|
|
|
glGetActiveUniform(s->prog_id, uniform_idx, sizeof(unif_name), |
|
|
|
|
&length, &size, &type, unif_name); |
|
|
|
|
|
|
|
|
|
unif.data_type = type; |
|
|
|
|
unif.name = (char*) arenaAllocateBlock( |
|
|
|
|
arena, (length + 1) * sizeof(char)); |
|
|
|
|
std::strncpy(unif.name, unif_name, length); |
|
|
|
|
|
|
|
|
|
// FIXME: testing idx == unif location
|
|
|
|
|
unif.idx = uniform_idx; |
|
|
|
|
#if 1 |
|
|
|
|
GLuint location = glGetUniformLocation(s->prog_id, unif.name); |
|
|
|
|
printf("uniform idx: %d, loc: %d, block idx: %d \n", |
|
|
|
|
unif.idx, location, unif.block_idx); |
|
|
|
|
#endif |
|
|
|
|
unif.data_size = getGLTypeSize(unif.data_type); |
|
|
|
|
|
|
|
|
|
if (unif.data_size == 0) |
|
|
|
|
printf("%s(), error getting data_size\n", __FUNCTION__); |
|
|
|
|
|
|
|
|
|
return unif; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
parseShaderUniforms(memory_arena* arena, shader_program* s, GLContext* gl_ctx) |
|
|
|
|
{ |
|
|
|
|
@ -144,45 +188,11 @@ parseShaderUniforms(memory_arena* arena, shader_program* s, GLContext* gl_ctx)
|
|
|
|
|
arena, s->num_uniforms * sizeof(gl_uniform)); |
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < s->num_uniforms; i++) { |
|
|
|
|
GLchar unif_name[256] = {0}; |
|
|
|
|
GLsizei length; |
|
|
|
|
GLint size; |
|
|
|
|
GLenum type; |
|
|
|
|
|
|
|
|
|
glGetActiveUniform(s->prog_id, i, sizeof(unif_name), |
|
|
|
|
&length, &size, &type, unif_name); |
|
|
|
|
|
|
|
|
|
s->uniforms[i].data_type = type; |
|
|
|
|
s->uniforms[i].name = (char*) arenaAllocateBlock( |
|
|
|
|
arena, (length + 1) * sizeof(char)); |
|
|
|
|
std::strncpy(s->uniforms[i].name, unif_name, length); |
|
|
|
|
|
|
|
|
|
glGetActiveUniformsiv(s->prog_id, 1, &i, |
|
|
|
|
GL_UNIFORM_BLOCK_INDEX, &s->uniforms[i].block_idx); |
|
|
|
|
|
|
|
|
|
// FIXME: testing idx == unif location
|
|
|
|
|
s->uniforms[i].idx = i; |
|
|
|
|
GLuint location = glGetUniformLocation(s->prog_id, s->uniforms[i].name); |
|
|
|
|
printf("idx: %d, loc: %d, block idx: %d \n", |
|
|
|
|
i, location, s->uniforms[i].block_idx); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: get uniform.data_size from data_type
|
|
|
|
|
//printf("i: %d, uniform name: %s, l: %d \n", i, unif_name, length);
|
|
|
|
|
parseUniform(arena, s, i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GLint max_vert_ublocks; |
|
|
|
|
GLint max_frag_ublocks; |
|
|
|
|
GLint max_ublock_size; |
|
|
|
|
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_BLOCKS, &max_vert_ublocks); |
|
|
|
|
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &max_frag_ublocks); |
|
|
|
|
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_ublock_size); |
|
|
|
|
printf("max vert uniform blocks: %d, max frag uniform blocks: %d," |
|
|
|
|
"max uniform block size: %d bytes \n", |
|
|
|
|
max_vert_ublocks, max_frag_ublocks, max_ublock_size); |
|
|
|
|
GLint max_ubo_bindings; |
|
|
|
|
glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_ubo_bindings); |
|
|
|
|
printf("max uniform buffer object binding points: %d \n", max_ubo_bindings); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl_buffer |
|
|
|
|
|