From 427b67c14c1ef95a63bf499ec906419eb20b71f4 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 2 Mar 2021 17:23:39 +0100 Subject: [PATCH] fixes to uniforms --- src/gl/gl3device.cpp | 9 +++++++-- src/gl/gl3immed.cpp | 1 + src/gl/gl3shader.cpp | 10 +++++++--- src/gl/rwgl3shader.h | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index 972b053..ecb781f 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -481,8 +481,10 @@ uint32 bindTexture(uint32 texid) { uint32 prev = boundTexture[activeTexture]; - boundTexture[activeTexture] = texid; - glBindTexture(GL_TEXTURE_2D, texid); + if(prev != texid){ + boundTexture[activeTexture] = texid; + glBindTexture(GL_TEXTURE_2D, texid); + } return prev; } @@ -1781,6 +1783,9 @@ initOpenGL(void) u_matColor = registerUniform("u_matColor", UNIFORM_VEC4); u_surfProps = registerUniform("u_surfProps", UNIFORM_VEC4); + // for im2d + registerUniform("u_xform", UNIFORM_VEC4); + glClearColor(0.25, 0.25, 0.25, 1.0); byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF}; diff --git a/src/gl/gl3immed.cpp b/src/gl/gl3immed.cpp index de2cf7f..3b4aae4 100644 --- a/src/gl/gl3immed.cpp +++ b/src/gl/gl3immed.cpp @@ -53,6 +53,7 @@ static int primTypeMap[] = { void openIm2D(void) { + // must already be registered by device. we just need the value u_xform = registerUniform("u_xform", UNIFORM_VEC4); #include "shaders/im2d_gl.inc" diff --git a/src/gl/gl3shader.cpp b/src/gl/gl3shader.cpp index a98ef50..98408a7 100644 --- a/src/gl/gl3shader.cpp +++ b/src/gl/gl3shader.cpp @@ -54,7 +54,6 @@ registerUniform(const char *name, UniformType type, int32 num) Uniform *u = &uniformRegistry.uniforms[uniformRegistry.numUniforms]; u->name = shader_strdup(name); u->type = type; -// u->dirty = false; u->serialNum = 0; if(type == UNIFORM_NA){ u->num = 0; @@ -118,12 +117,17 @@ void flushUniforms(void) { for(int i = 0; i < uniformRegistry.numUniforms; i++){ + // this is bad! + if(i >= currentShader->numUniforms){ + printf("trying to set uniform %d %s that doesn't exist!\n", i, uniformRegistry.uniforms[i].name); + continue; + } + int32 loc = currentShader->uniformLocations[i]; if(loc == -1) continue; Uniform *u = &uniformRegistry.uniforms[i]; -// if(force || u->dirty) if(currentShader->serialNums[i] != u->serialNum) switch(u->type){ case UNIFORM_NA: @@ -139,7 +143,6 @@ flushUniforms(void) break; } currentShader->serialNums[i] = u->serialNum; - //u->dirty = false; } } @@ -297,6 +300,7 @@ Shader::create(const char **vsrc, const char **fsrc) // query uniform locations sh->program = program; + sh->numUniforms = uniformRegistry.numUniforms; sh->uniformLocations = rwNewT(GLint, uniformRegistry.numUniforms, MEMDUR_EVENT | ID_DRIVER); sh->serialNums = rwNewT(uint32, uniformRegistry.numUniforms, MEMDUR_EVENT | ID_DRIVER); for(i = 0; i < uniformRegistry.numUniforms; i++){ diff --git a/src/gl/rwgl3shader.h b/src/gl/rwgl3shader.h index 414f1ac..890f12b 100644 --- a/src/gl/rwgl3shader.h +++ b/src/gl/rwgl3shader.h @@ -52,6 +52,7 @@ struct Shader // same number of elements as UniformRegistry::numUniforms GLint *uniformLocations; uint32 *serialNums; + int32 numUniforms; // just to be sure! static Shader *create(const char **vsrc, const char **fsrc); // static Shader *fromFiles(const char *vs, const char *fs);