From 92411decf2997a2d83c5a682a1af1d6680372999 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Fri, 4 Feb 2022 20:05:57 -0500 Subject: [PATCH] add getUBOByName helper --- src/main.cpp | 19 ++----------------- src/shader.cpp | 18 ++++++++++++++++++ src/shader.h | 2 ++ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 174746d..fda4b8c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -141,29 +141,14 @@ render_cb_pre(RenderState* rs) cam_pos += cam_mov; rs->xforms->view_xform = glm::lookAt(cam_pos, look_pos, glm::vec3(0, 1, 0)); -#if 1 - // TODO: make helper function for getting UBO by name in shader.h static GLBuffer* xform_ubo = nullptr; - u64 h_search = utilFNV64a_str("matrices"); if (!xform_ubo) { - for (u32 i = 0; i < rs->gl_ctx->num_ubos; i++) { - GLBuffer* buf = &rs->gl_ctx->uniform_buffers[i]; - - if (buf->name != nullptr) { - u64 hash = utilFNV64a_str(buf->name); - if (hash == h_search) - xform_ubo = buf; - } - } - - if (!xform_ubo) - LOGF(Error, "matrices ubo not found\n"); + xform_ubo = getUBOByName(rs->gl_ctx, "matrices"); + assert(xform_ubo != nullptr); } updateCameraTransforms(rs->xforms, xform_ubo); - //// -#endif #if 0 for (u32 i = 0; i < rs->num_render_groups; i++) { RenderGroup& rg = rs->render_groups[i]; diff --git a/src/shader.cpp b/src/shader.cpp index 2581cfa..726d877 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -169,6 +169,24 @@ getFreeUBO(GLContext* gl_ctx) return nullptr; } +GLBuffer* +getUBOByName(GLContext* gl_ctx, const char* name) +{ + GLBuffer* ubo_out = nullptr; + + for (u32 i = 0; i < gl_ctx->num_ubos; i++) { + GLBuffer* buf = &gl_ctx->uniform_buffers[i]; + + if (utilCStrMatch(name, buf->name)) + ubo_out = buf; + } + + if (ubo_out == nullptr) + LOGF(Error, "GLBuffer, \"%s\", not found\n", name); + + return ubo_out; +} + GLTexture* getGLTexture(GLContext* gl_ctx, Texture* diffuse_img) { diff --git a/src/shader.h b/src/shader.h index 5a52652..f2f8ad9 100644 --- a/src/shader.h +++ b/src/shader.h @@ -188,6 +188,8 @@ ShaderProgram* getFreeShader(GLContext* gl_ctx); GLBuffer* getFreeUBO(GLContext* gl_ctx); +GLBuffer* getUBOByName(GLContext* gl_ctx, const char* name); + GLTexture* getGLTexture(GLContext* gl_ctx, Texture* diffuse_img); void updateCameraTransforms(Transforms* xforms, GLBuffer* xform_ubo);