OpenGL: Redo uniform loading
Jeffrey Pfau jeffrey@endrift.com
Thu, 17 Dec 2015 21:58:17 -0800
2 files changed,
12 insertions(+),
12 deletions(-)
M
res/shaders/ags001.shader/manifest.ini
→
res/shaders/ags001.shader/manifest.ini
@@ -15,21 +15,18 @@ fragmentShader=ags001-light.fs
width=960 height=640 -[uniform.lightBrightness] +[pass.1.uniform.lightBrightness] type=float default=1 -pass[0]=false readableName=Light brightness -[uniform.reflectionBrightness] +[pass.1.uniform.reflectionBrightness] type=float default=0.07 -pass[0]=false readableName=Reflection brightness -[uniform.reflectionDistance] +[pass.1.uniform.reflectionDistance] type=float2 default[0]=0 default[1]=0.025 -pass[0]=false readableName=Reflection distance
M
src/platform/opengl/gles2.c
→
src/platform/opengl/gles2.c
@@ -439,7 +439,9 @@ DEFINE_VECTOR(GBAGLES2UniformList, struct GBAGLES2Uniform);
static void _uniformHandler(const char* sectionName, void* user) { struct GBAGLES2UniformList* uniforms = user; - if (strstr(sectionName, "uniform.") != sectionName) { + unsigned passId; + int sentinel; + if (sscanf(sectionName, "pass.%u.uniform.%n", &passId, &sentinel) < 1) { return; } struct GBAGLES2Uniform* u = GBAGLES2UniformListAppend(uniforms);@@ -658,13 +660,14 @@ }
} static bool _loadUniform(struct Configuration* description, size_t pass, struct GBAGLES2Uniform* uniform) { - char passId[12]; - snprintf(passId, sizeof(passId), "pass[%zu]", pass); - GLboolean inPass; - if (_lookupBoolValue(description, uniform->name, passId, &inPass) && !inPass) { + unsigned passId; + if (sscanf(uniform->name, "pass.%u.uniform.", &passId) < 1 || passId != pass) { return false; } const char* type = ConfigurationGetValue(description, uniform->name, "type"); + if (!type) { + return false; + } if (!strcmp(type, "float")) { uniform->type = GL_FLOAT; } else if (!strcmp(type, "float2")) {@@ -707,7 +710,7 @@ uniform->readableName = strdup(readable);
} else { uniform->readableName = 0; } - uniform->name = strdup(uniform->name + strlen("uniform.")); + uniform->name = strdup(strstr(uniform->name, "uniform.") + strlen("uniform.")); return true; }