Browse Source

add getUBOByName helper

main
cinnaboot 4 years ago
parent
commit
92411decf2
  1. 19
      src/main.cpp
  2. 18
      src/shader.cpp
  3. 2
      src/shader.h

19
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];

18
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)
{

2
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);

Loading…
Cancel
Save