fixes to uniforms

This commit is contained in:
aap 2021-03-02 17:23:39 +01:00
parent 0102f88367
commit 427b67c14c
4 changed files with 16 additions and 5 deletions

View File

@ -481,8 +481,10 @@ uint32
bindTexture(uint32 texid) bindTexture(uint32 texid)
{ {
uint32 prev = boundTexture[activeTexture]; uint32 prev = boundTexture[activeTexture];
if(prev != texid){
boundTexture[activeTexture] = texid; boundTexture[activeTexture] = texid;
glBindTexture(GL_TEXTURE_2D, texid); glBindTexture(GL_TEXTURE_2D, texid);
}
return prev; return prev;
} }
@ -1781,6 +1783,9 @@ initOpenGL(void)
u_matColor = registerUniform("u_matColor", UNIFORM_VEC4); u_matColor = registerUniform("u_matColor", UNIFORM_VEC4);
u_surfProps = registerUniform("u_surfProps", 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); glClearColor(0.25, 0.25, 0.25, 1.0);
byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF}; byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF};

View File

@ -53,6 +53,7 @@ static int primTypeMap[] = {
void void
openIm2D(void) openIm2D(void)
{ {
// must already be registered by device. we just need the value
u_xform = registerUniform("u_xform", UNIFORM_VEC4); u_xform = registerUniform("u_xform", UNIFORM_VEC4);
#include "shaders/im2d_gl.inc" #include "shaders/im2d_gl.inc"

View File

@ -54,7 +54,6 @@ registerUniform(const char *name, UniformType type, int32 num)
Uniform *u = &uniformRegistry.uniforms[uniformRegistry.numUniforms]; Uniform *u = &uniformRegistry.uniforms[uniformRegistry.numUniforms];
u->name = shader_strdup(name); u->name = shader_strdup(name);
u->type = type; u->type = type;
// u->dirty = false;
u->serialNum = 0; u->serialNum = 0;
if(type == UNIFORM_NA){ if(type == UNIFORM_NA){
u->num = 0; u->num = 0;
@ -118,12 +117,17 @@ void
flushUniforms(void) flushUniforms(void)
{ {
for(int i = 0; i < uniformRegistry.numUniforms; i++){ 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]; int32 loc = currentShader->uniformLocations[i];
if(loc == -1) if(loc == -1)
continue; continue;
Uniform *u = &uniformRegistry.uniforms[i]; Uniform *u = &uniformRegistry.uniforms[i];
// if(force || u->dirty)
if(currentShader->serialNums[i] != u->serialNum) if(currentShader->serialNums[i] != u->serialNum)
switch(u->type){ switch(u->type){
case UNIFORM_NA: case UNIFORM_NA:
@ -139,7 +143,6 @@ flushUniforms(void)
break; break;
} }
currentShader->serialNums[i] = u->serialNum; currentShader->serialNums[i] = u->serialNum;
//u->dirty = false;
} }
} }
@ -297,6 +300,7 @@ Shader::create(const char **vsrc, const char **fsrc)
// query uniform locations // query uniform locations
sh->program = program; sh->program = program;
sh->numUniforms = uniformRegistry.numUniforms;
sh->uniformLocations = rwNewT(GLint, uniformRegistry.numUniforms, MEMDUR_EVENT | ID_DRIVER); sh->uniformLocations = rwNewT(GLint, uniformRegistry.numUniforms, MEMDUR_EVENT | ID_DRIVER);
sh->serialNums = rwNewT(uint32, uniformRegistry.numUniforms, MEMDUR_EVENT | ID_DRIVER); sh->serialNums = rwNewT(uint32, uniformRegistry.numUniforms, MEMDUR_EVENT | ID_DRIVER);
for(i = 0; i < uniformRegistry.numUniforms; i++){ for(i = 0; i < uniformRegistry.numUniforms; i++){

View File

@ -52,6 +52,7 @@ struct Shader
// same number of elements as UniformRegistry::numUniforms // same number of elements as UniformRegistry::numUniforms
GLint *uniformLocations; GLint *uniformLocations;
uint32 *serialNums; uint32 *serialNums;
int32 numUniforms; // just to be sure!
static Shader *create(const char **vsrc, const char **fsrc); static Shader *create(const char **vsrc, const char **fsrc);
// static Shader *fromFiles(const char *vs, const char *fs); // static Shader *fromFiles(const char *vs, const char *fs);