From 0b6f5c6f55bf5f0964b4e452d378cedf5d0cf36e Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 15 Jan 2020 16:02:29 -0500 Subject: [PATCH] cogl: Move GL-specific uniform code to the driver vtable https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1194 --- cogl/cogl/cogl-boxed-value.c | 88 +----------------- cogl/cogl/cogl-driver.h | 5 + .../driver/gl/cogl-pipeline-opengl-private.h | 5 + cogl/cogl/driver/gl/cogl-pipeline-opengl.c | 92 +++++++++++++++++++ cogl/cogl/driver/gl/gl/cogl-driver-gl.c | 1 + cogl/cogl/driver/gl/gles/cogl-driver-gles.c | 1 + 6 files changed, 105 insertions(+), 87 deletions(-) diff --git a/cogl/cogl/cogl-boxed-value.c b/cogl/cogl/cogl-boxed-value.c index 7d55231c0..9a9ba41c2 100644 --- a/cogl/cogl/cogl-boxed-value.c +++ b/cogl/cogl/cogl-boxed-value.c @@ -34,7 +34,6 @@ #include "cogl-boxed-value.h" #include "cogl-context-private.h" -#include "driver/gl/cogl-util-gl-private.h" gboolean _cogl_boxed_value_equal (const CoglBoxedValue *bva, @@ -286,90 +285,5 @@ _cogl_boxed_value_set_uniform (CoglContext *ctx, GLint location, const CoglBoxedValue *value) { - switch (value->type) - { - case COGL_BOXED_NONE: - break; - - case COGL_BOXED_INT: - { - const int *ptr; - - if (value->count == 1) - ptr = value->v.int_value; - else - ptr = value->v.int_array; - - switch (value->size) - { - case 1: - GE( ctx, glUniform1iv (location, value->count, ptr) ); - break; - case 2: - GE( ctx, glUniform2iv (location, value->count, ptr) ); - break; - case 3: - GE( ctx, glUniform3iv (location, value->count, ptr) ); - break; - case 4: - GE( ctx, glUniform4iv (location, value->count, ptr) ); - break; - } - } - break; - - case COGL_BOXED_FLOAT: - { - const float *ptr; - - if (value->count == 1) - ptr = value->v.float_value; - else - ptr = value->v.float_array; - - switch (value->size) - { - case 1: - GE( ctx, glUniform1fv (location, value->count, ptr) ); - break; - case 2: - GE( ctx, glUniform2fv (location, value->count, ptr) ); - break; - case 3: - GE( ctx, glUniform3fv (location, value->count, ptr) ); - break; - case 4: - GE( ctx, glUniform4fv (location, value->count, ptr) ); - break; - } - } - break; - - case COGL_BOXED_MATRIX: - { - const float *ptr; - - if (value->count == 1) - ptr = value->v.matrix; - else - ptr = value->v.float_array; - - switch (value->size) - { - case 2: - GE( ctx, glUniformMatrix2fv (location, value->count, - FALSE, ptr) ); - break; - case 3: - GE( ctx, glUniformMatrix3fv (location, value->count, - FALSE, ptr) ); - break; - case 4: - GE( ctx, glUniformMatrix4fv (location, value->count, - FALSE, ptr) ); - break; - } - } - break; - } + ctx->driver_vtable->set_uniform (ctx, location, value); } diff --git a/cogl/cogl/cogl-driver.h b/cogl/cogl/cogl-driver.h index 6ad24d65c..04c5d2e58 100644 --- a/cogl/cogl/cogl-driver.h +++ b/cogl/cogl/cogl-driver.h @@ -274,6 +274,11 @@ struct _CoglDriverVtable void (*sampler_free) (CoglContext *context, CoglSamplerCacheEntry *entry); + + void + (* set_uniform) (CoglContext *ctx, + GLint location, + const CoglBoxedValue *value); }; #define COGL_DRIVER_ERROR (_cogl_driver_error_quark ()) diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h b/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h index e10ca69dc..62846237c 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h @@ -163,5 +163,10 @@ void _cogl_sampler_gl_free (CoglContext *context, CoglSamplerCacheEntry *entry); +void +_cogl_gl_set_uniform (CoglContext *ctx, + GLint location, + const CoglBoxedValue *value); + #endif /* __COGL_PIPELINE_OPENGL_PRIVATE_H */ diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c index 3264a0029..da13e293b 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c @@ -1190,3 +1190,95 @@ done: COGL_TIMER_STOP (_cogl_uprof_context, pipeline_flush_timer); } +void +_cogl_gl_set_uniform (CoglContext *ctx, + GLint location, + const CoglBoxedValue *value) +{ + switch (value->type) + { + case COGL_BOXED_NONE: + break; + + case COGL_BOXED_INT: + { + const int *ptr; + + if (value->count == 1) + ptr = value->v.int_value; + else + ptr = value->v.int_array; + + switch (value->size) + { + case 1: + GE( ctx, glUniform1iv (location, value->count, ptr) ); + break; + case 2: + GE( ctx, glUniform2iv (location, value->count, ptr) ); + break; + case 3: + GE( ctx, glUniform3iv (location, value->count, ptr) ); + break; + case 4: + GE( ctx, glUniform4iv (location, value->count, ptr) ); + break; + } + } + break; + + case COGL_BOXED_FLOAT: + { + const float *ptr; + + if (value->count == 1) + ptr = value->v.float_value; + else + ptr = value->v.float_array; + + switch (value->size) + { + case 1: + GE( ctx, glUniform1fv (location, value->count, ptr) ); + break; + case 2: + GE( ctx, glUniform2fv (location, value->count, ptr) ); + break; + case 3: + GE( ctx, glUniform3fv (location, value->count, ptr) ); + break; + case 4: + GE( ctx, glUniform4fv (location, value->count, ptr) ); + break; + } + } + break; + + case COGL_BOXED_MATRIX: + { + const float *ptr; + + if (value->count == 1) + ptr = value->v.matrix; + else + ptr = value->v.float_array; + + switch (value->size) + { + case 2: + GE( ctx, glUniformMatrix2fv (location, value->count, + FALSE, ptr) ); + break; + case 3: + GE( ctx, glUniformMatrix3fv (location, value->count, + FALSE, ptr) ); + break; + case 4: + GE( ctx, glUniformMatrix4fv (location, value->count, + FALSE, ptr) ); + break; + } + } + break; + } +} diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c index d066ff072..950cbe662 100644 --- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c @@ -565,4 +565,5 @@ _cogl_driver_gl = _cogl_buffer_gl_set_data, _cogl_sampler_gl_init, _cogl_sampler_gl_free, + _cogl_gl_set_uniform, /* XXX name is weird... */ }; diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c index 34f850fd5..32f8c526a 100644 --- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c @@ -429,4 +429,5 @@ _cogl_driver_gles = _cogl_buffer_gl_set_data, _cogl_sampler_gl_init, _cogl_sampler_gl_free, + _cogl_gl_set_uniform, };