|
|
|
@ -32,13 +32,13 @@ addShaderProgram(memory_arena* arena, |
|
|
|
const char* fs, |
|
|
|
const char* fs, |
|
|
|
const char* name) |
|
|
|
const char* name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (gl_ctx->shader_arr->count >= gl_ctx->shader_arr->max) { |
|
|
|
if (gl_ctx->num_shaders >= gl_ctx->max_shaders) { |
|
|
|
std::cout << "ShaderArray full\n"; |
|
|
|
printf("%s(), GLContext->shaders full\n", __FUNCTION__); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
shader_program* s = &gl_ctx->shader_arr->shaders[gl_ctx->shader_arr->count]; |
|
|
|
shader_program* s = &gl_ctx->shaders[gl_ctx->num_shaders]; |
|
|
|
gl_ctx->shader_arr->count++; |
|
|
|
gl_ctx->num_shaders++; |
|
|
|
|
|
|
|
|
|
|
|
u32 name_len = std::strlen(name) + 1; |
|
|
|
u32 name_len = std::strlen(name) + 1; |
|
|
|
s->name = (char*) arenaAllocateBlock(arena, name_len); |
|
|
|
s->name = (char*) arenaAllocateBlock(arena, name_len); |
|
|
|
@ -73,6 +73,10 @@ addShaderProgram(memory_arena* arena, |
|
|
|
glGetProgramiv(s->prog_id, GL_LINK_STATUS, &is_linked); |
|
|
|
glGetProgramiv(s->prog_id, GL_LINK_STATUS, &is_linked); |
|
|
|
|
|
|
|
|
|
|
|
if (is_linked) { |
|
|
|
if (is_linked) { |
|
|
|
|
|
|
|
// NOTE: need to set context maximums after at least one shader has
|
|
|
|
|
|
|
|
// been linked
|
|
|
|
|
|
|
|
initCTXSizes(gl_ctx); |
|
|
|
|
|
|
|
dumpShader(s->prog_id); |
|
|
|
s->model_xform_id = glGetUniformLocation(s->prog_id, "model_xform"); |
|
|
|
s->model_xform_id = glGetUniformLocation(s->prog_id, "model_xform"); |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: testing
|
|
|
|
// FIXME: testing
|
|
|
|
@ -195,8 +199,19 @@ parseShaderUniforms(memory_arena* arena, shader_program* s, GLContext* gl_ctx) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gl_buffer |
|
|
|
bool |
|
|
|
initTransforms(transforms* xforms, |
|
|
|
parseAttributes(memory_arena* arena, shader_program* s, GLContext* gl_ctx) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// TODO: parse buffers (vert, normal, uv), glGetActiveAttrib()
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
printf("%s(), FIXME:\n", __FUNCTION__); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
initTransforms(memory_arena* arena, |
|
|
|
|
|
|
|
transforms* xforms, |
|
|
|
|
|
|
|
gl_buffer* xform_ubo, |
|
|
|
GLContext* gl_ctx, |
|
|
|
GLContext* gl_ctx, |
|
|
|
float fov, |
|
|
|
float fov, |
|
|
|
float near_clip_plane, |
|
|
|
float near_clip_plane, |
|
|
|
@ -208,22 +223,51 @@ initTransforms(transforms* xforms, |
|
|
|
xforms->proj_xform = glm::infinitePerspective( |
|
|
|
xforms->proj_xform = glm::infinitePerspective( |
|
|
|
glm::radians(fov), aspect_ratio, near_clip_plane); |
|
|
|
glm::radians(fov), aspect_ratio, near_clip_plane); |
|
|
|
|
|
|
|
|
|
|
|
gl_buffer ubo = {0}; |
|
|
|
glGenBuffers(1, &xform_ubo->id); |
|
|
|
glGenBuffers(1, &ubo.id); |
|
|
|
xform_ubo->target = GL_UNIFORM_BUFFER; |
|
|
|
ubo.target = GL_UNIFORM_BUFFER; |
|
|
|
xform_ubo->data_type = GL_FLOAT; |
|
|
|
ubo.data_type = GL_FLOAT; |
|
|
|
xform_ubo->data_size = sizeof(*xforms); |
|
|
|
ubo.data_size = sizeof(*xforms); |
|
|
|
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo.id); |
|
|
|
// TODO: make an arenaAddCStr(arena, char*& str_ref) for this nonsense
|
|
|
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(*xforms), xforms, GL_DYNAMIC_DRAW); |
|
|
|
const char* block_name = "matrices"; |
|
|
|
|
|
|
|
u32 name_len = std::strlen(block_name) + 1; |
|
|
|
// NOTE: need to manually keep track of block bindings
|
|
|
|
xform_ubo->name = (char*) arenaAllocateBlock(arena, name_len); |
|
|
|
glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &gl_ctx->max_binding_points); |
|
|
|
std::strncpy(xform_ubo->name, block_name, name_len); |
|
|
|
glBindBufferBase(GL_UNIFORM_BUFFER, gl_ctx->binding_count, ubo.id); |
|
|
|
// END TODO:
|
|
|
|
ubo.binding_idx = gl_ctx->binding_count; |
|
|
|
|
|
|
|
gl_ctx->binding_count++; |
|
|
|
glBindBuffer(xform_ubo->target, xform_ubo->id); |
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0); |
|
|
|
glBufferData(xform_ubo->target, sizeof(*xforms), xforms, |
|
|
|
|
|
|
|
GL_DYNAMIC_DRAW); |
|
|
|
return ubo; |
|
|
|
// bindbufferbase
|
|
|
|
|
|
|
|
xform_ubo->binding_idx = gl_ctx->binding_count++; |
|
|
|
|
|
|
|
glBindBufferBase(xform_ubo->target, xform_ubo->binding_idx, xform_ubo->id); |
|
|
|
|
|
|
|
glBindBuffer(xform_ubo->target, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
initCTXSizes(GLContext* gl_ctx) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// NOTE: see https://docs.gl/gl3/glGet for other useful context info
|
|
|
|
|
|
|
|
if (gl_ctx->max_binding_points == 0) { |
|
|
|
|
|
|
|
glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, |
|
|
|
|
|
|
|
&gl_ctx->max_binding_points); |
|
|
|
|
|
|
|
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_BLOCKS, &gl_ctx->max_vertex_blocks); |
|
|
|
|
|
|
|
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, |
|
|
|
|
|
|
|
&gl_ctx->max_fragment_blocks); |
|
|
|
|
|
|
|
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &gl_ctx->max_ublock_size); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 1 |
|
|
|
|
|
|
|
printf("%s(), context size info set\n", __FUNCTION__); |
|
|
|
|
|
|
|
printf("GL_MAX_UNIFORM_BUFFER_BINDINGS: %d\n", |
|
|
|
|
|
|
|
gl_ctx->max_binding_points); |
|
|
|
|
|
|
|
printf("GL_MAX_VERTEX_UNIFORM_BLOCKS: %d\n", |
|
|
|
|
|
|
|
gl_ctx->max_vertex_blocks); |
|
|
|
|
|
|
|
printf("GL_MAX_FRAGMENT_UNIFORM_BLOCKS: %d\n", |
|
|
|
|
|
|
|
gl_ctx->max_fragment_blocks); |
|
|
|
|
|
|
|
printf("GL_MAX_UNIFORM_BLOCK_SIZE: %d\n", |
|
|
|
|
|
|
|
gl_ctx->max_ublock_size); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gl_mesh |
|
|
|
gl_mesh |
|
|
|
|