diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-11-05 23:03:26 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-11-05 23:03:26 +0300 |
commit | 93dbd81796df663598df26119e1e1a5c595be840 (patch) | |
tree | 2b4daae9ddd660057b66eba40444c9de82aa1ada /source/blender | |
parent | 5b26c36008a2672d49e815c7a14a957a841d2a12 (diff) |
Gawain: manage batch API's current shader program + uniform funcs
Typical pattern:
Batch_set_program
Batch_Uniform(s)
Batch_draw
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpu/gawain/batch.c | 46 | ||||
-rw-r--r-- | source/blender/gpu/gawain/batch.h | 8 |
2 files changed, 47 insertions, 7 deletions
diff --git a/source/blender/gpu/gawain/batch.c b/source/blender/gpu/gawain/batch.c index d11ac6b0a9d..0e817e1baaa 100644 --- a/source/blender/gpu/gawain/batch.c +++ b/source/blender/gpu/gawain/batch.c @@ -55,6 +55,8 @@ void Batch_set_program(Batch* batch, GLuint program) batch->program = program; batch->program_dirty = true; + + Batch_use_program(batch); // hack! to make Batch_Uniform* simpler } static void Batch_update_program_bindings(Batch* batch) @@ -102,8 +104,12 @@ static void Batch_update_program_bindings(Batch* batch) batch->program_dirty = false; } -static void Batch_use_program(Batch* batch) +void Batch_use_program(Batch* batch) { + // NOTE: use_program & done_using_program are fragile, depend on staying in sync with + // the GL context's active program. use_program doesn't mark other programs as "not used". + // TODO: make not fragile (somehow) + if (!batch->program_in_use) { glUseProgram(batch->program); @@ -111,7 +117,7 @@ static void Batch_use_program(Batch* batch) } } -static void Batch_done_using_program(Batch* batch) +void Batch_done_using_program(Batch* batch) { if (batch->program_in_use) { @@ -128,10 +134,42 @@ void Batch_Uniform1b(Batch* batch, const char* name, bool value) assert(loc != -1); #endif - Batch_use_program(batch); glUniform1i(loc, value ? GL_TRUE : GL_FALSE); } +void Batch_Uniform2f(Batch* batch, const char* name, float x, float y) + { + int loc = glGetUniformLocation(batch->program, name); + +#if TRUST_NO_ONE + assert(loc != -1); +#endif + + glUniform2f(loc, x, y); + } + +void Batch_Uniform4f(Batch* batch, const char* name, float x, float y, float z, float w) + { + int loc = glGetUniformLocation(batch->program, name); + +#if TRUST_NO_ONE + assert(loc != -1); +#endif + + glUniform4f(loc, x, y, z, w); + } + +void Batch_Uniform1f(Batch* batch, const char* name, float x) + { + int loc = glGetUniformLocation(batch->program, name); + +#if TRUST_NO_ONE + assert(loc != -1); +#endif + + glUniform1f(loc, x); + } + void Batch_Uniform3fv(Batch* batch, const char* name, const float data[3]) { int loc = glGetUniformLocation(batch->program, name); @@ -140,7 +178,6 @@ void Batch_Uniform3fv(Batch* batch, const char* name, const float data[3]) assert(loc != -1); #endif - Batch_use_program(batch); glUniform3fv(loc, 1, data); } @@ -152,7 +189,6 @@ void Batch_Uniform4fv(Batch* batch, const char* name, const float data[4]) assert(loc != -1); #endif - Batch_use_program(batch); glUniform4fv(loc, 1, data); } diff --git a/source/blender/gpu/gawain/batch.h b/source/blender/gpu/gawain/batch.h index c0f0e93ce9a..40d87dd3d14 100644 --- a/source/blender/gpu/gawain/batch.h +++ b/source/blender/gpu/gawain/batch.h @@ -46,9 +46,13 @@ void Batch_set_program(Batch*, GLuint program); // Entire batch draws with one shader program, but can be redrawn later with another program. // Vertex shader's inputs must be compatible with the batch's vertex format. +void Batch_use_program(Batch*); // call before Batch_Uniform (temp hack?) +void Batch_done_using_program(Batch*); + void Batch_Uniform1b(Batch*, const char* name, bool value); -// void Batch_Uniform1f(Batch*, float value); -// void Batch_Uniform4f(Batch*, float x, float y, float z, float w); +void Batch_Uniform1f(Batch*, const char* name, float value); +void Batch_Uniform2f(Batch*, const char* name, float x, float y); +void Batch_Uniform4f(Batch*, const char* name, float x, float y, float z, float w); void Batch_Uniform3fv(Batch*, const char* name, const float data[3]); void Batch_Uniform4fv(Batch*, const char* name, const float data[4]); |