cogl: Move GL-specific uniform code to the driver vtable

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1194
This commit is contained in:
Adam Jackson 2020-01-15 16:02:29 -05:00
parent e2c2a332e6
commit 0b6f5c6f55
6 changed files with 105 additions and 87 deletions

View File

@ -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);
}

View File

@ -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 ())

View File

@ -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 */

View File

@ -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;
}
}

View File

@ -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... */
};

View File

@ -429,4 +429,5 @@ _cogl_driver_gles =
_cogl_buffer_gl_set_data,
_cogl_sampler_gl_init,
_cogl_sampler_gl_free,
_cogl_gl_set_uniform,
};