[Bf-blender-cvs] [93dbd81] blender2.8: Gawain: manage batch API's current shader program + uniform funcs
Mike Erwin
noreply at git.blender.org
Sun Nov 6 20:09:51 CET 2016
Commit: 93dbd81796df663598df26119e1e1a5c595be840
Author: Mike Erwin
Date: Sat Nov 5 21:03:26 2016 +0100
Branches: blender2.8
https://developer.blender.org/rB93dbd81796df663598df26119e1e1a5c595be840
Gawain: manage batch API's current shader program + uniform funcs
Typical pattern:
Batch_set_program
Batch_Uniform(s)
Batch_draw
===================================================================
M source/blender/gpu/gawain/batch.c
M source/blender/gpu/gawain/batch.h
===================================================================
diff --git a/source/blender/gpu/gawain/batch.c b/source/blender/gpu/gawain/batch.c
index d11ac6b..0e817e1b 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 c0f0e93..40d87dd 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]);
More information about the Bf-blender-cvs
mailing list