Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--intern/gawain/gawain/batch.h4
-rw-r--r--intern/gawain/gawain/immediate.h3
-rw-r--r--intern/gawain/src/batch.c79
-rw-r--r--intern/gawain/src/immediate.c120
-rw-r--r--intern/opencolorio/ocio_impl_glsl.cc48
-rw-r--r--source/blender/draw/intern/draw_manager.c2
-rw-r--r--source/blender/gpu/GPU_matrix.h3
-rw-r--r--source/blender/gpu/intern/gpu_batch.c2
-rw-r--r--source/blender/gpu/intern/gpu_compositing.c22
-rw-r--r--source/blender/gpu/intern/gpu_immediate.c2
-rw-r--r--source/blender/gpu/intern/gpu_matrix.c49
-rw-r--r--source/blender/gpu/intern/gpu_shader.c2
12 files changed, 130 insertions, 206 deletions
diff --git a/intern/gawain/gawain/batch.h b/intern/gawain/gawain/batch.h
index 2802dad3db3..9915b0b57f4 100644
--- a/intern/gawain/gawain/batch.h
+++ b/intern/gawain/gawain/batch.h
@@ -13,6 +13,7 @@
#include "vertex_buffer.h"
#include "element.h"
+#include "shader_interface.h"
typedef enum {
READY_TO_FORMAT,
@@ -38,6 +39,7 @@ typedef struct Batch {
// state
GLuint program;
+ const ShaderInterface* interface;
} Batch;
Batch* Batch_create(PrimitiveType, VertexBuffer*, ElementList*);
@@ -48,7 +50,7 @@ void Batch_discard_all(Batch*); // including verts & elem
int Batch_add_VertexBuffer(Batch*, VertexBuffer*);
-void Batch_set_program(Batch*, GLuint program);
+void Batch_set_program(Batch*, GLuint program, const ShaderInterface*);
// 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.
diff --git a/intern/gawain/gawain/immediate.h b/intern/gawain/gawain/immediate.h
index 62754306abe..b08be688cf4 100644
--- a/intern/gawain/gawain/immediate.h
+++ b/intern/gawain/gawain/immediate.h
@@ -13,13 +13,14 @@
#include "vertex_format.h"
#include "primitive.h"
+#include "shader_interface.h"
#define IMM_BATCH_COMBO 1
VertexFormat* immVertexFormat(void); // returns a cleared vertex format, ready for add_attrib
-void immBindProgram(GLuint program); // every immBegin must have a program bound first
+void immBindProgram(GLuint program, const ShaderInterface*); // every immBegin must have a program bound first
void immUnbindProgram(void); // call after your last immEnd, or before binding another program
void immBegin(PrimitiveType, unsigned vertex_ct); // must supply exactly vertex_ct vertices
diff --git a/intern/gawain/src/batch.c b/intern/gawain/src/batch.c
index 7e904cbd487..5de6335e0bb 100644
--- a/intern/gawain/src/batch.c
+++ b/intern/gawain/src/batch.c
@@ -88,13 +88,14 @@ int Batch_add_VertexBuffer(Batch* batch, VertexBuffer* verts)
return -1;
}
-void Batch_set_program(Batch* batch, GLuint program)
+void Batch_set_program(Batch* batch, GLuint program, const ShaderInterface* shaderface)
{
#if TRUST_NO_ONE
assert(glIsProgram(program));
#endif
batch->program = program;
+ batch->interface = shaderface;
batch->program_dirty = true;
Batch_use_program(batch); // hack! to make Batch_Uniform* simpler
@@ -172,92 +173,58 @@ void Batch_done_using_program(Batch* batch)
}
}
-void Batch_Uniform1i(Batch* batch, const char* name, int value)
- {
- int loc = glGetUniformLocation(batch->program, name);
-
#if TRUST_NO_ONE
- assert(loc != -1);
+ #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(batch->interface, name); assert(uniform);
+#else
+ #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(batch->interface, name);
#endif
- glUniform1i(loc, value);
+void Batch_Uniform1i(Batch* batch, const char* name, int value)
+ {
+ GET_UNIFORM
+ glUniform1i(uniform->location, value);
}
void Batch_Uniform1b(Batch* batch, const char* name, bool value)
{
- int loc = glGetUniformLocation(batch->program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform1i(loc, value ? GL_TRUE : GL_FALSE);
+ GET_UNIFORM
+ glUniform1i(uniform->location, 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);
+ GET_UNIFORM
+ glUniform2f(uniform->location, x, y);
}
void Batch_Uniform3f(Batch* batch, const char* name, float x, float y, float z)
{
- int loc = glGetUniformLocation(batch->program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform3f(loc, x, y, z);
+ GET_UNIFORM
+ glUniform3f(uniform->location, x, y, z);
}
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);
+ GET_UNIFORM
+ glUniform4f(uniform->location, 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);
+ GET_UNIFORM
+ glUniform1f(uniform->location, x);
}
void Batch_Uniform3fv(Batch* batch, const char* name, const float data[3])
{
- int loc = glGetUniformLocation(batch->program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform3fv(loc, 1, data);
+ GET_UNIFORM
+ glUniform3fv(uniform->location, 1, data);
}
void Batch_Uniform4fv(Batch* batch, const char* name, const float data[4])
{
- int loc = glGetUniformLocation(batch->program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform4fv(loc, 1, data);
+ GET_UNIFORM
+ glUniform4fv(uniform->location, 1, data);
}
static void Batch_prime(Batch* batch)
diff --git a/intern/gawain/src/immediate.c b/intern/gawain/src/immediate.c
index 2fd2d2480a7..f384887a2ad 100644
--- a/intern/gawain/src/immediate.c
+++ b/intern/gawain/src/immediate.c
@@ -15,7 +15,7 @@
#include <string.h>
// necessary functions from matrix API
-extern void gpuBindMatrices(GLuint program);
+extern void gpuBindMatrices(const ShaderInterface*);
extern bool gpuMatricesDirty(void);
typedef struct {
@@ -44,6 +44,7 @@ typedef struct {
GLuint vao_id;
GLuint bound_program;
+ const ShaderInterface* shader_interface;
AttribBinding attrib_binding;
uint16_t prev_enabled_attrib_bits; // <-- only affects this VAO, so we're ok
} Immediate;
@@ -117,21 +118,22 @@ VertexFormat* immVertexFormat(void)
return &imm.vertex_format;
}
-void immBindProgram(GLuint program)
+void immBindProgram(GLuint program, const ShaderInterface* shaderface)
{
#if TRUST_NO_ONE
assert(imm.bound_program == 0);
assert(glIsProgram(program));
#endif
+ imm.bound_program = program;
+ imm.shader_interface = shaderface;
+
if (!imm.vertex_format.packed)
VertexFormat_pack(&imm.vertex_format);
glUseProgram(program);
get_attrib_locations(&imm.vertex_format, &imm.attrib_binding, program);
- imm.bound_program = program;
-
- gpuBindMatrices(program);
+ gpuBindMatrices(shaderface);
}
void immUnbindProgram(void)
@@ -267,7 +269,7 @@ Batch* immBeginBatch(PrimitiveType prim_type, unsigned vertex_ct)
imm.batch = Batch_create(prim_type, verts, NULL);
imm.batch->phase = BUILDING;
- Batch_set_program(imm.batch, imm.bound_program);
+ Batch_set_program(imm.batch, imm.bound_program, imm.shader_interface);
return imm.batch;
}
@@ -336,7 +338,7 @@ static void immDrawSetup(void)
}
if (gpuMatricesDirty())
- gpuBindMatrices(imm.bound_program);
+ gpuBindMatrices(imm.shader_interface);
}
void immEnd(void)
@@ -716,126 +718,76 @@ void immVertex2iv(unsigned attrib_id, const int data[2])
// --- generic uniform functions ---
-void immUniform1f(const char* name, float x)
- {
- int loc = glGetUniformLocation(imm.bound_program, name);
-
#if TRUST_NO_ONE
- assert(loc != -1);
+ #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(imm.shader_interface, name); assert(uniform);
+#else
+ #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(imm.shader_interface, name);
#endif
- glUniform1f(loc, x);
+void immUniform1f(const char* name, float x)
+ {
+ GET_UNIFORM
+ glUniform1f(uniform->location, x);
}
void immUniform2f(const char* name, float x, float y)
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform2f(loc, x, y);
+ GET_UNIFORM
+ glUniform2f(uniform->location, x, y);
}
void immUniform2fv(const char* name, const float data[2])
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform2fv(loc, 1, data);
+ GET_UNIFORM
+ glUniform2fv(uniform->location, 1, data);
}
void immUniform3f(const char* name, float x, float y, float z)
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform3f(loc, x, y, z);
+ GET_UNIFORM
+ glUniform3f(uniform->location, x, y, z);
}
void immUniform3fv(const char* name, const float data[3])
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform3fv(loc, 1, data);
+ GET_UNIFORM
+ glUniform3fv(uniform->location, 1, data);
}
void immUniformArray3fv(const char* name, const float *data, int count)
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
- assert(count > 0);
-#endif
-
- glUniform3fv(loc, count, data);
+ GET_UNIFORM
+ glUniform3fv(uniform->location, count, data);
}
void immUniform4f(const char* name, float x, float y, float z, float w)
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform4f(loc, x, y, z, w);
+ GET_UNIFORM
+ glUniform4f(uniform->location, x, y, z, w);
}
void immUniform4fv(const char* name, const float data[4])
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform4fv(loc, 1, data);
+ GET_UNIFORM
+ glUniform4fv(uniform->location, 1, data);
}
void immUniformMatrix4fv(const char* name, const float data[4][4])
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniformMatrix4fv(loc, 1, GL_FALSE, (float *)data);
+ GET_UNIFORM
+ glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (float *)data);
}
void immUniform1i(const char* name, int x)
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform1i(loc, x);
+ GET_UNIFORM
+ glUniform1i(uniform->location, x);
}
void immUniform4iv(const char* name, const int data[4])
{
- int loc = glGetUniformLocation(imm.bound_program, name);
-
-#if TRUST_NO_ONE
- assert(loc != -1);
-#endif
-
- glUniform4iv(loc, 1, data);
+ GET_UNIFORM
+ glUniform4iv(uniform->location, 1, data);
}
// --- convenience functions for setting "uniform vec4 color" ---
diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc
index 819dd6632b3..5d1d170c2cb 100644
--- a/intern/opencolorio/ocio_impl_glsl.cc
+++ b/intern/opencolorio/ocio_impl_glsl.cc
@@ -95,6 +95,7 @@ typedef struct OCIO_GLSLDrawState {
GLuint ocio_shader;
GLuint vert_shader;
GLuint program;
+ ShaderInterface *shader_interface;
/* Previous OpenGL state. */
GLint last_texture, last_texture_unit;
@@ -411,10 +412,12 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc
glActiveTexture(GL_TEXTURE0);
- immBindProgram(state->program);
+ state->shader_interface = ShaderInterface_create(state->program);
- glUniform1i(glGetUniformLocation(state->program, "image_texture"), 0);
- glUniform1i(glGetUniformLocation(state->program, "lut3d_texture"), 1);
+ immBindProgram(state->program, state->shader_interface);
+
+ immUniform1i("image_texture", 0);
+ immUniform1i("lut3d_texture", 1);
if (state->texture_size_used) {
/* we use textureSize() if possible for best performance, if not
@@ -424,30 +427,30 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
- glUniform1f(glGetUniformLocation(state->program, "image_texture_width"), (float)width);
- glUniform1f(glGetUniformLocation(state->program, "image_texture_height"), (float)height);
+ immUniform1f("image_texture_width", (float)width);
+ immUniform1f("image_texture_height", (float)height);
}
if (use_dither) {
- glUniform1f(glGetUniformLocation(state->program, "dither"), dither);
+ immUniform1f("dither", dither);
}
if (use_curve_mapping) {
- glUniform1i(glGetUniformLocation(state->program, "curve_mapping_texture"), 2);
- glUniform1i(glGetUniformLocation(state->program, "curve_mapping_lut_size"), curve_mapping_settings->lut_size);
- glUniform4iv(glGetUniformLocation(state->program, "use_curve_mapping_extend_extrapolate"), 1, curve_mapping_settings->use_extend_extrapolate);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_mintable"), 1, curve_mapping_settings->mintable);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_range"), 1, curve_mapping_settings->range);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_in_x"), 1, curve_mapping_settings->ext_in_x);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_in_y"), 1, curve_mapping_settings->ext_in_y);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_out_x"), 1, curve_mapping_settings->ext_out_x);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_out_y"), 1, curve_mapping_settings->ext_out_y);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_first_x"), 1, curve_mapping_settings->first_x);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_first_y"), 1, curve_mapping_settings->first_y);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_last_x"), 1, curve_mapping_settings->last_x);
- glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_last_y"), 1, curve_mapping_settings->last_y);
- glUniform3fv(glGetUniformLocation(state->program, "curve_mapping_black"), 1, curve_mapping_settings->black);
- glUniform3fv(glGetUniformLocation(state->program, "curve_mapping_bwmul"), 1, curve_mapping_settings->bwmul);
+ immUniform1i("curve_mapping_texture", 2);
+ immUniform1i("curve_mapping_lut_size", curve_mapping_settings->lut_size);
+ immUniform4iv("use_curve_mapping_extend_extrapolate", curve_mapping_settings->use_extend_extrapolate);
+ immUniform4fv("curve_mapping_mintable", curve_mapping_settings->mintable);
+ immUniform4fv("curve_mapping_range", curve_mapping_settings->range);
+ immUniform4fv("curve_mapping_ext_in_x", curve_mapping_settings->ext_in_x);
+ immUniform4fv("curve_mapping_ext_in_y", curve_mapping_settings->ext_in_y);
+ immUniform4fv("curve_mapping_ext_out_x", curve_mapping_settings->ext_out_x);
+ immUniform4fv("curve_mapping_ext_out_y", curve_mapping_settings->ext_out_y);
+ immUniform4fv("curve_mapping_first_x", curve_mapping_settings->first_x);
+ immUniform4fv("curve_mapping_first_y", curve_mapping_settings->first_y);
+ immUniform4fv("curve_mapping_last_x", curve_mapping_settings->last_x);
+ immUniform4fv("curve_mapping_last_y", curve_mapping_settings->last_y);
+ immUniform3fv("curve_mapping_black", curve_mapping_settings->black);
+ immUniform3fv("curve_mapping_bwmul", curve_mapping_settings->bwmul);
}
return true;
@@ -480,6 +483,9 @@ void OCIOImpl::freeGLState(struct OCIO_GLSLDrawState *state)
if (state->program)
glDeleteProgram(state->program);
+ if (state->shader_interface)
+ ShaderInterface_discard(state->shader_interface);
+
if (state->ocio_shader)
glDeleteShader(state->ocio_shader);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 3cb6c57eef6..19938605290 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -1002,7 +1002,7 @@ static void draw_geometry(DRWShadingGroup *shgroup, Batch *geom, const float (*o
}
/* step 2 : bind vertex array & draw */
- Batch_set_program(geom, GPU_shader_get_program(shgroup->shader));
+ Batch_set_program(geom, GPU_shader_get_program(shgroup->shader), GPU_shader_get_interface(shgroup->shader));
if (interface->instance_vbo) {
Batch_draw_stupid_instanced(geom, interface->instance_vbo, interface->instance_count, interface->attribs_count,
interface->attribs_stride, interface->attribs_size, interface->attribs_loc);
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index 85b1b5c7acf..07e4ff80f57 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -34,6 +34,7 @@
#include "BLI_sys_types.h"
#include "GPU_glew.h"
+#include "../../../intern/gawain/gawain/shader_interface.h"
#ifdef __cplusplus
extern "C" {
@@ -132,7 +133,7 @@ const float *gpuGetNormalMatrixInverse(float m[3][3]);
/* set uniform values for currently bound shader */
-void gpuBindMatrices(GLuint program);
+void gpuBindMatrices(const ShaderInterface*);
bool gpuMatricesDirty(void); /* since last bind */
#ifdef __cplusplus
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index a36830cf277..e98f07cb0e9 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -34,7 +34,7 @@
void Batch_set_builtin_program(Batch *batch, GPUBuiltinShader shader_id)
{
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
- Batch_set_program(batch, shader->program);
+ Batch_set_program(batch, shader->program, shader->interface);
}
static Batch *sphere_high = NULL;
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 719708ff7aa..72f2525c64e 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -734,7 +734,7 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
GPUDepthResolveInterface *interface = GPU_fx_shader_get_interface(depth_resolve_shader);
/* set up quad buffer */
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(depth_resolve_shader));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(depth_resolve_shader), GPU_shader_get_interface(depth_resolve_shader));
GPU_texture_bind(fx->depth_buffer_xray, 0);
GPU_texture_compare_mode(fx->depth_buffer_xray, false);
@@ -838,7 +838,7 @@ bool GPU_fx_do_composite_pass(
GPUSSAOShaderInterface *interface = GPU_fx_shader_get_interface(ssao_shader);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(ssao_shader));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(ssao_shader), GPU_shader_get_interface(ssao_shader));
GPU_shader_uniform_vector(ssao_shader, interface->ssao_uniform, 4, 1, ssao_params);
GPU_shader_uniform_vector(ssao_shader, interface->ssao_color_uniform, 4, 1, fx_ssao->color);
@@ -931,7 +931,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFHQPassOneInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass1);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1), GPU_shader_get_interface(dof_shader_pass1));
GPU_shader_uniform_vector(dof_shader_pass1, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
@@ -983,7 +983,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFHQPassTwoInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass2);
- Batch_set_program(fx->point_batch, GPU_shader_get_program(dof_shader_pass2));
+ Batch_set_program(fx->point_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2));
GPU_texture_bind(fx->dof_nearfar_coc, numslots++);
GPU_texture_bind(fx->dof_half_downsampled_far, numslots++);
@@ -1046,7 +1046,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFHQPassThreeInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass3);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3), GPU_shader_get_interface(dof_shader_pass3));
GPU_shader_uniform_vector(dof_shader_pass3, interface->dof_uniform, 4, 1, dof_params);
@@ -1125,7 +1125,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFPassOneInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass1);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1), GPU_shader_get_interface(dof_shader_pass1));
GPU_shader_uniform_vector(dof_shader_pass1, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
@@ -1167,7 +1167,7 @@ bool GPU_fx_do_composite_pass(
dof_params[2] = GPU_texture_width(fx->dof_near_coc_blurred_buffer) / (scale_camera * fx_dof->sensor);
/* Blurring vertically */
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2));
GPU_shader_uniform_vector(dof_shader_pass2, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass2, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
@@ -1188,7 +1188,7 @@ bool GPU_fx_do_composite_pass(
Batch_draw(fx->quad_batch);
/* Rebind Shader */
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2));
/* *unbind/detach */
GPU_texture_unbind(fx->dof_near_coc_buffer);
@@ -1224,7 +1224,7 @@ bool GPU_fx_do_composite_pass(
{
GPUDOFPassThreeInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass3);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3), GPU_shader_get_interface(dof_shader_pass3));
GPU_texture_bind(fx->dof_near_coc_buffer, numslots++);
GPU_shader_uniform_texture(dof_shader_pass3, interface->near_coc_downsampled, fx->dof_near_coc_buffer);
@@ -1252,7 +1252,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFPassFourInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass4);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass4));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass4), GPU_shader_get_interface(dof_shader_pass4));
GPU_texture_bind(fx->dof_near_coc_final_buffer, numslots++);
GPU_shader_uniform_texture(dof_shader_pass4, interface->near_coc_downsampled, fx->dof_near_coc_final_buffer);
@@ -1277,7 +1277,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFPassFiveInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass5);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass5));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass5), GPU_shader_get_interface(dof_shader_pass5));
GPU_shader_uniform_vector(dof_shader_pass5, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass5, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
index 34d32be15ed..5f22b7f9279 100644
--- a/source/blender/gpu/intern/gpu_immediate.c
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -35,7 +35,7 @@
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
{
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
- immBindProgram(shader->program);
+ immBindProgram(shader->program, shader->interface);
}
void immUniformThemeColor(int color_id)
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index 8f8754f612d..8195722917d 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -829,74 +829,69 @@ const float *gpuGetNormalMatrixInverse(float m[3][3])
return (const float*)m;
}
-void gpuBindMatrices(GLuint program)
+void gpuBindMatrices(const ShaderInterface* shaderface)
{
- /* TODO: split this into 2 functions
- * 1) get uniform locations & determine 2D or 3D
+ /* set uniform values to matrix stack values
+ * call this before a draw call if desired matrices are dirty
+ * call glUseProgram before this, as glUniform expects program to be bound
*/
- GLint loc_MV = glGetUniformLocation(program, "ModelViewMatrix");
- GLint loc_P = glGetUniformLocation(program, "ProjectionMatrix");
- GLint loc_MVP = glGetUniformLocation(program, "ModelViewProjectionMatrix");
- GLint loc_N = glGetUniformLocation(program, "NormalMatrix");
-
- /* 2) set uniform values to matrix stack values
- * program needs to be bound
- */
- glUseProgram(program);
+ const ShaderInput *MV = ShaderInterface_builtin_uniform(shaderface, UNIFORM_MODELVIEW_3D);
+ const ShaderInput *P = ShaderInterface_builtin_uniform(shaderface, UNIFORM_PROJECTION_3D);
+ const ShaderInput *MVP = ShaderInterface_builtin_uniform(shaderface, UNIFORM_MVP_3D);
+ const ShaderInput *N = ShaderInterface_builtin_uniform(shaderface, UNIFORM_NORMAL_3D);
- /* call this portion before a draw call if desired matrices are dirty */
- if (loc_MV != -1) {
+ if (MV) {
#if DEBUG_MATRIX_BIND
puts("setting 3D MV matrix");
#endif
- glUniformMatrix4fv(loc_MV, 1, GL_FALSE, gpuGetModelViewMatrix3D(NULL));
+ glUniformMatrix4fv(MV->location, 1, GL_FALSE, gpuGetModelViewMatrix3D(NULL));
}
- if (loc_P != -1) {
+ if (P) {
#if DEBUG_MATRIX_BIND
puts("setting 3D P matrix");
#endif
- glUniformMatrix4fv(loc_P, 1, GL_FALSE, gpuGetProjectionMatrix3D(NULL));
+ glUniformMatrix4fv(P->location, 1, GL_FALSE, gpuGetProjectionMatrix3D(NULL));
}
- if (loc_MVP != -1) {
+ if (MVP) {
#if DEBUG_MATRIX_BIND
puts("setting 3D MVP matrix");
#endif
- glUniformMatrix4fv(loc_MVP, 1, GL_FALSE, gpuGetModelViewProjectionMatrix3D(NULL));
+ glUniformMatrix4fv(MVP->location, 1, GL_FALSE, gpuGetModelViewProjectionMatrix3D(NULL));
}
- if (loc_N != -1) {
+ if (N) {
#if DEBUG_MATRIX_BIND
puts("setting 3D normal matrix");
#endif
- glUniformMatrix3fv(loc_N, 1, GL_FALSE, gpuGetNormalMatrix(NULL));
+ glUniformMatrix3fv(N->location, 1, GL_FALSE, gpuGetNormalMatrix(NULL));
}
/* also needed by material.glsl
* - ProjectionMatrixInverse
* - ModelViewMatrixInverse
*/
- GLint loc_MV_inv = glGetUniformLocation(program, "ModelViewInverseMatrix");
- GLint loc_P_inv = glGetUniformLocation(program, "ProjectionInverseMatrix");
+ const ShaderInput *MV_inv = ShaderInterface_builtin_uniform(shaderface, UNIFORM_MODELVIEW_INV_3D);
+ const ShaderInput *P_inv = ShaderInterface_builtin_uniform(shaderface, UNIFORM_PROJECTION_INV_3D);
- if (loc_MV_inv != -1) {
+ if (MV_inv) {
Mat4 m;
gpuGetModelViewMatrix3D(m);
invert_m4(m);
- glUniformMatrix4fv(loc_MV_inv, 1, GL_FALSE, (const float*) m);
+ glUniformMatrix4fv(MV_inv->location, 1, GL_FALSE, (const float*) m);
}
- if (loc_P_inv != -1) {
+ if (P_inv) {
Mat4 m;
gpuGetProjectionMatrix3D(m);
invert_m4(m);
- glUniformMatrix4fv(loc_P_inv, 1, GL_FALSE, (const float*) m);
+ glUniformMatrix4fv(P_inv->location, 1, GL_FALSE, (const float*) m);
}
state.dirty = false;
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 7ea148e15d6..fa63dff1458 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -490,7 +490,7 @@ void GPU_shader_bind(GPUShader *shader)
BLI_assert(shader && shader->program);
glUseProgram(shader->program);
- gpuBindMatrices(shader->program);
+ gpuBindMatrices(shader->interface);
}
void GPU_shader_unbind(void)