1
0
Fork 0

Don't use the transpose argument of glUniformMatrix*

According to the GLES1/2 spec, the transpose argument of
glUniformMatrix* should always be FALSE. Cogl directly exposes the
transposedness of the uniform value in
cogl_pipeline_set_uniform_matrix and we were previously passing this
value on to GL. This patch makes it instead just always transpose the
matrix in Cogl itself when copying the value to the CoglBoxedValue. It
doesn't seem like there could be much advantage to letting GL
transpose the uniform value and at least Mesa just does a very similar
loop to handle the transpose.

Mesa has started being more pedantic about this which was making
test_pipeline_uniforms fail.

http://cgit.freedesktop.org/mesa/mesa/commit/?id=60e8a4944081b42127b3

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit f42ee670ff663d03073d6b1038b21a0aa1b3ec2b)
This commit is contained in:
Neil Roberts 2012-06-20 14:23:50 +01:00 committed by Robert Bragg
parent 93d0de1d9a
commit 7cdaaf2bd5
2 changed files with 41 additions and 9 deletions

View file

@ -80,8 +80,7 @@ _cogl_boxed_value_equal (const CoglBoxedValue *bva,
case COGL_BOXED_MATRIX: case COGL_BOXED_MATRIX:
if (bva->size != bvb->size || if (bva->size != bvb->size ||
bva->count != bvb->count || bva->count != bvb->count)
bva->transpose != bvb->transpose)
return FALSE; return FALSE;
if (bva->count == 1) if (bva->count == 1)
@ -104,6 +103,24 @@ _cogl_boxed_value_equal (const CoglBoxedValue *bva,
return FALSE; return FALSE;
} }
static void
_cogl_boxed_value_tranpose (float *dst,
int size,
const float *src)
{
int y, x;
/* If the value is transposed we'll just transpose it now as it
* is copied into the boxed value instead of passing TRUE to
* glUniformMatrix because that is not supported on GLES and it
* doesn't seem like the GL driver would be able to do anything
* much smarter than this anyway */
for (y = 0; y < size; y++)
for (x = 0; x < size; x++)
*(dst++) = src[y + x * size];
}
static void static void
_cogl_boxed_value_set_x (CoglBoxedValue *bv, _cogl_boxed_value_set_x (CoglBoxedValue *bv,
int size, int size,
@ -118,6 +135,11 @@ _cogl_boxed_value_set_x (CoglBoxedValue *bv,
if (bv->count > 1) if (bv->count > 1)
g_free (bv->v.array); g_free (bv->v.array);
if (transpose)
_cogl_boxed_value_tranpose (bv->v.float_value,
size,
value);
else
memcpy (bv->v.float_value, value, value_size); memcpy (bv->v.float_value, value, value_size);
} }
else else
@ -135,13 +157,24 @@ _cogl_boxed_value_set_x (CoglBoxedValue *bv,
else else
bv->v.array = g_malloc (count * value_size); bv->v.array = g_malloc (count * value_size);
if (transpose)
{
int value_num;
for (value_num = 0; value_num < count; value_num++)
_cogl_boxed_value_tranpose (bv->v.float_array +
value_num * size * size,
size,
(const float *) value +
value_num * size * size);
}
else
memcpy (bv->v.array, value, count * value_size); memcpy (bv->v.array, value, count * value_size);
} }
bv->type = type; bv->type = type;
bv->size = size; bv->size = size;
bv->count = count; bv->count = count;
bv->transpose = transpose;
} }
void void
@ -319,15 +352,15 @@ _cogl_boxed_value_set_uniform (CoglContext *ctx,
{ {
case 2: case 2:
GE( ctx, glUniformMatrix2fv (location, value->count, GE( ctx, glUniformMatrix2fv (location, value->count,
value->transpose, ptr) ); FALSE, ptr) );
break; break;
case 3: case 3:
GE( ctx, glUniformMatrix3fv (location, value->count, GE( ctx, glUniformMatrix3fv (location, value->count,
value->transpose, ptr) ); FALSE, ptr) );
break; break;
case 4: case 4:
GE( ctx, glUniformMatrix4fv (location, value->count, GE( ctx, glUniformMatrix4fv (location, value->count,
value->transpose, ptr) ); FALSE, ptr) );
break; break;
} }
} }

View file

@ -39,7 +39,6 @@ typedef struct _CoglBoxedValue
{ {
CoglBoxedType type; CoglBoxedType type;
int size, count; int size, count;
CoglBool transpose;
union { union {
float float_value[4]; float float_value[4];