all repos — mgba @ 0de98898a328e6449766a27cb0fc53cdb2a9edeb

mGBA Game Boy Advance Emulator

OpenGL: Generalize shader loading a bit
Jeffrey Pfau jeffrey@endrift.com
Thu, 19 Nov 2015 22:14:51 -0800
commit

0de98898a328e6449766a27cb0fc53cdb2a9edeb

parent

a89bb0b814072869723edc05cc1dcf8249dd2c9a

M res/shaders/ags001.shader/manifest.inires/shaders/ags001.shader/manifest.ini

@@ -1,7 +1,7 @@

[shader] name=AGS-001 author=endrift -description=A pristine recreation of the illumated Game Boy Advance SP +description=A pristine recreation of the illuminated Game Boy Advance SP passes=2 [pass.0]

@@ -18,12 +18,15 @@

[uniform.lightBrightness] type=float default=1 +pass[0]=false [uniform.reflectionBrightness] type=float default=0.07 +pass[0]=false [uniform.reflectionDistance] type=float2 default[0]=0 default[1]=0.025 +pass[0]=false
M src/platform/opengl/gles2.csrc/platform/opengl/gles2.c

@@ -639,7 +639,13 @@ break;

} } -static bool _loadUniform(struct Configuration* description, struct GBAGLES2Uniform* uniform) { +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) { + return false; + } const char* type = ConfigurationGetValue(description, uniform->name, "type"); if (!strcmp(type, "float")) { uniform->type = GL_FLOAT;

@@ -687,7 +693,7 @@ }

return true; } -bool GBAGLES2ShaderLoad(struct GBAGLES2Shader** shaders, size_t* nShaders, struct GBAGLES2ShaderMetadata* metadata, struct VDir* dir) { +bool GBAGLES2ShaderLoad(struct VideoShader* shader, struct VDir* dir) { struct VFile* manifest = dir->openFile(dir, "manifest.ini", O_RDONLY); if (!manifest) { return false;

@@ -702,20 +708,6 @@ if (inShaders > MAX_PASSES || inShaders < 1) {

success = false; } if (success) { - if (metadata) { - metadata->name = ConfigurationGetValue(&description, "shader", "name"); - if (metadata->name) { - metadata->name = strdup(metadata->name); - } - metadata->author = ConfigurationGetValue(&description, "shader", "author"); - if (metadata->author) { - metadata->author = strdup(metadata->author); - } - metadata->description = ConfigurationGetValue(&description, "shader", "description"); - if (metadata->description) { - metadata->description = strdup(metadata->description); - } - } struct GBAGLES2Shader* shaderBlock = malloc(sizeof(struct GBAGLES2Shader) * inShaders); int n; for (n = 0; n < inShaders; ++n) {

@@ -767,8 +759,8 @@ ConfigurationEnumerateSections(&description, _uniformHandler, &uniformVector);

size_t u; for (u = 0; u < GBAGLES2UniformListSize(&uniformVector); ++u) { struct GBAGLES2Uniform* uniform = GBAGLES2UniformListGetPointer(&uniformVector, u); - if (!_loadUniform(&description, uniform)) { - GBAGLES2UniformListUnshift(&uniformVector, u, 1); + if (!_loadUniform(&description, n, uniform)) { + GBAGLES2UniformListShift(&uniformVector, u, 1); --u; } }

@@ -792,8 +784,20 @@ free(fssrc);

free(vssrc); } if (success) { - *nShaders = inShaders; - *shaders = shaderBlock; + shader->nPasses = inShaders; + shader->passes = shaderBlock; + shader->name = ConfigurationGetValue(&description, "shader", "name"); + if (shader->name) { + shader->name = strdup(shader->name); + } + shader->author = ConfigurationGetValue(&description, "shader", "author"); + if (shader->author) { + shader->author = strdup(shader->author); + } + shader->description = ConfigurationGetValue(&description, "shader", "description"); + if (shader->description) { + shader->description = strdup(shader->description); + } } else { inShaders = n; for (n = 0; n < inShaders; ++n) {

@@ -806,9 +810,13 @@ ConfigurationDeinit(&description);

return success; } -void GBAGLES2ShaderFree(struct GBAGLES2Shader* shaders, size_t nShaders) { +void GBAGLES2ShaderFree(struct VideoShader* shader) { + free((void*) shader->name); + free((void*) shader->author); + free((void*) shader->description); + struct GBAGLES2Shader* shaders = shader->passes; size_t n; - for (n = 0; n < nShaders; ++n) { + for (n = 0; n < shader->nPasses; ++n) { GBAGLES2ShaderDeinit(&shaders[n]); size_t u; for (u = 0; u < shaders[n].nUniforms; ++u) {
M src/platform/opengl/gles2.hsrc/platform/opengl/gles2.h

@@ -81,12 +81,6 @@ struct GBAGLES2Shader* shaders;

size_t nShaders; }; -struct GBAGLES2ShaderMetadata { - const char* name; - const char* author; - const char* description; -}; - void GBAGLES2ContextCreate(struct GBAGLES2Context*); void GBAGLES2ShaderInit(struct GBAGLES2Shader*, const char* vs, const char* fs, int width, int height, struct GBAGLES2Uniform* uniforms, size_t nUniforms);

@@ -95,7 +89,7 @@ void GBAGLES2ShaderAttach(struct GBAGLES2Context*, struct GBAGLES2Shader*, size_t nShaders);

void GBAGLES2ShaderDetach(struct GBAGLES2Context*); struct VDir; -bool GBAGLES2ShaderLoad(struct GBAGLES2Shader**, size_t* nShaders, struct GBAGLES2ShaderMetadata*, struct VDir*); -void GBAGLES2ShaderFree(struct GBAGLES2Shader*, size_t nShaders); +bool GBAGLES2ShaderLoad(struct VideoShader*, struct VDir*); +void GBAGLES2ShaderFree(struct VideoShader*); #endif
M src/platform/video-backend.hsrc/platform/video-backend.h

@@ -32,4 +32,12 @@ bool filter;

bool lockAspectRatio; }; +struct VideoShader { + const char* name; + const char* author; + const char* description; + void* passes; + size_t nPasses; +}; + #endif