diff options
author | Joshua Rowe <omniscient.oce@gmail.com> | 2024-08-04 01:14:12 +1000 |
---|---|---|
committer | Joshua Rowe <omniscient.oce@gmail.com> | 2024-08-04 01:14:12 +1000 |
commit | 389faeb198941077306a81a8f5d5d325dcfb01da (patch) | |
tree | e970a3b8b2fbdb2f937da7880ae19e1db54d1b40 | |
parent | bd1687896395fb8d59a3903303ef3e57f0e57348 (diff) |
copy binding bytes code
-rw-r--r-- | examples/game_demo/game_demo.c | 8 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 28 |
2 files changed, 31 insertions, 5 deletions
diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c index a179d10..88c95bf 100644 --- a/examples/game_demo/game_demo.c +++ b/examples/game_demo/game_demo.c @@ -21,9 +21,9 @@ #include "skybox.h" #include "terrain.h" -static const char* faces[6] = { "assets/demo/skybox/right.jpg", "assets/demo/skybox/left.jpg", - "assets/demo/skybox/top.jpg", "assets/demo/skybox/bottom.jpg", - "assets/demo/skybox/front.jpg", "assets/demo/skybox/back.jpg" }; +static const char* faces[6] = { "assets/skybox/right.jpg", "assets/skybox/left.jpg", + "assets/skybox/top.jpg", "assets/skybox/bottom.jpg", + "assets/skybox/front.jpg", "assets/skybox/back.jpg" }; int main() { Core_Bringup(NULL); @@ -106,7 +106,7 @@ int main() { if (draw_debug) { // draw the player model with shadows - Render_RenderEntities(render_entities->data, render_entities->len); + // Render_RenderEntities(render_entities->data, render_entities->len); // Render_DrawTerrain(); Skybox_Draw(&skybox, cam); } else { diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index fc7d3b4..d70a598 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -402,7 +402,32 @@ void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderDataLayo CASSERT_MSG(binding.data.bytes.data, "void* data pointer should be non null"); CASSERT_MSG(binding.data.bytes.size > 0, "size should be greater than 0 bytes"); #endif - // TODO + BufferHandle b; + GPU_Buffer* ubo_buf; + bool found = false; + for (u32 i = 0; i < encoder->pipeline->uniform_count; i++) { + b = encoder->pipeline->uniform_bindings[i]; + ubo_buf = BUFFER_GET(b); + assert(ubo_buf->name != NULL); + if (strcmp(ubo_buf->name, binding.label) == 0) { + found = true; + break; + } + } + if (!found) { + ERROR("Couldnt find uniform buffer object for %s!!", binding.label); + } + + i32 blockIndex = glGetUniformBlockIndex(encoder->pipeline->shader_id, binding.label); + if (blockIndex < 0) { + WARN("Couldn't retrieve block index for uniform block '%s'", binding.label); + } else { + // DEBUG("Retrived block index %d for %s", blockIndex, binding.label); + } + + glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo); + glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, binding.data.bytes.data); + break; } case BINDING_TEXTURE: { GPU_Texture* tex = TEXTURE_GET(binding.data.texture.handle); @@ -414,6 +439,7 @@ void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderDataLayo glUniform1i(tex_slot, binding_i); glActiveTexture(GL_TEXTURE0 + binding_i); glBindTexture(opengl_tex_type(tex->type), tex->id); + break; } default: WARN("Unsupported binding kind"); |