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)
{
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};

View File

@ -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"

View File

@ -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++){

View File

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