2011-12-02 10:55:41 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
} TestState;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
int16_t x, y;
|
2011-12-02 10:55:41 +00:00
|
|
|
float r, g, b, a;
|
|
|
|
} FloatVert;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
int16_t x, y;
|
|
|
|
uint8_t r, g, b, a;
|
2011-12-02 10:55:41 +00:00
|
|
|
} ByteVert;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
int16_t x, y;
|
2011-12-02 10:55:41 +00:00
|
|
|
} ShortVert;
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_float_verts (TestState *state, int offset_x, int offset_y)
|
|
|
|
{
|
|
|
|
CoglAttribute *attributes[2];
|
|
|
|
CoglAttributeBuffer *buffer;
|
|
|
|
|
|
|
|
static const FloatVert float_verts[] =
|
|
|
|
{
|
|
|
|
{ 0, 10, /**/ 1, 0, 0, 1 },
|
|
|
|
{ 10, 10, /**/ 1, 0, 0, 1 },
|
|
|
|
{ 5, 0, /**/ 1, 0, 0, 1 },
|
|
|
|
|
|
|
|
{ 10, 10, /**/ 0, 1, 0, 1 },
|
|
|
|
{ 20, 10, /**/ 0, 1, 0, 1 },
|
|
|
|
{ 15, 0, /**/ 0, 1, 0, 1 }
|
|
|
|
};
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
buffer = cogl_attribute_buffer_new (ctx,
|
2012-02-06 17:08:58 +00:00
|
|
|
sizeof (float_verts), float_verts);
|
2011-12-02 10:55:41 +00:00
|
|
|
attributes[0] = cogl_attribute_new (buffer,
|
|
|
|
"cogl_position_in",
|
|
|
|
sizeof (FloatVert),
|
|
|
|
G_STRUCT_OFFSET (FloatVert, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_SHORT);
|
|
|
|
attributes[1] = cogl_attribute_new (buffer,
|
|
|
|
"color",
|
|
|
|
sizeof (FloatVert),
|
|
|
|
G_STRUCT_OFFSET (FloatVert, r),
|
|
|
|
4, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_push_matrix (fb);
|
|
|
|
cogl_framebuffer_translate (fb, offset_x, offset_y, 0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_draw_attributes (fb,
|
2012-01-08 02:59:04 +00:00
|
|
|
state->pipeline,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
0, /* first_vertex */
|
|
|
|
6, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
2 /* n_attributes */);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_pop_matrix (fb);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[1]);
|
|
|
|
cogl_object_unref (attributes[0]);
|
|
|
|
cogl_object_unref (buffer);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_check_pixel (fb, offset_x + 5, offset_y + 5, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
|
2011-12-02 10:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_byte_verts (TestState *state, int offset_x, int offset_y)
|
|
|
|
{
|
|
|
|
CoglAttribute *attributes[2];
|
|
|
|
CoglAttributeBuffer *buffer, *unnorm_buffer;
|
|
|
|
|
|
|
|
static const ByteVert norm_verts[] =
|
|
|
|
{
|
|
|
|
{ 0, 10, /**/ 255, 0, 0, 255 },
|
|
|
|
{ 10, 10, /**/ 255, 0, 0, 255 },
|
|
|
|
{ 5, 0, /**/ 255, 0, 0, 255 },
|
|
|
|
|
|
|
|
{ 10, 10, /**/ 0, 255, 0, 255 },
|
|
|
|
{ 20, 10, /**/ 0, 255, 0, 255 },
|
|
|
|
{ 15, 0, /**/ 0, 255, 0, 255 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ByteVert unnorm_verts[] =
|
|
|
|
{
|
|
|
|
{ 0, 0, /**/ 0, 0, 1, 1 },
|
|
|
|
{ 0, 0, /**/ 0, 0, 1, 1 },
|
|
|
|
{ 0, 0, /**/ 0, 0, 1, 1 },
|
|
|
|
};
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
buffer = cogl_attribute_buffer_new (ctx,
|
2012-02-06 17:08:58 +00:00
|
|
|
sizeof (norm_verts), norm_verts);
|
2011-12-02 10:55:41 +00:00
|
|
|
attributes[0] = cogl_attribute_new (buffer,
|
|
|
|
"cogl_position_in",
|
|
|
|
sizeof (ByteVert),
|
|
|
|
G_STRUCT_OFFSET (ByteVert, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_SHORT);
|
|
|
|
attributes[1] = cogl_attribute_new (buffer,
|
|
|
|
"color",
|
|
|
|
sizeof (ByteVert),
|
|
|
|
G_STRUCT_OFFSET (ByteVert, r),
|
|
|
|
4, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
|
|
|
cogl_attribute_set_normalized (attributes[1], TRUE);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_push_matrix (fb);
|
|
|
|
cogl_framebuffer_translate (fb, offset_x, offset_y, 0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_draw_attributes (fb,
|
2012-01-08 02:59:04 +00:00
|
|
|
state->pipeline,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
0, /* first_vertex */
|
|
|
|
6, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
2 /* n_attributes */);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[1]);
|
|
|
|
|
|
|
|
/* Test again with unnormalized attributes */
|
2012-03-16 19:54:13 +00:00
|
|
|
unnorm_buffer = cogl_attribute_buffer_new (ctx,
|
2012-02-06 17:08:58 +00:00
|
|
|
sizeof (unnorm_verts),
|
2011-12-02 10:55:41 +00:00
|
|
|
unnorm_verts);
|
|
|
|
attributes[1] = cogl_attribute_new (unnorm_buffer,
|
|
|
|
"color",
|
|
|
|
sizeof (ByteVert),
|
|
|
|
G_STRUCT_OFFSET (ByteVert, r),
|
|
|
|
4, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_BYTE);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_translate (fb, 20, 0, 0);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_draw_attributes (fb,
|
2012-01-08 02:59:04 +00:00
|
|
|
state->pipeline,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
0, /* first_vertex */
|
|
|
|
3, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
2 /* n_attributes */);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_pop_matrix (fb);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[0]);
|
|
|
|
cogl_object_unref (attributes[1]);
|
|
|
|
cogl_object_unref (buffer);
|
|
|
|
cogl_object_unref (unnorm_buffer);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_check_pixel (fb, offset_x + 5, offset_y + 5, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
|
|
|
|
test_utils_check_pixel (fb, offset_x + 25, offset_y + 5, 0x0000ffff);
|
2011-12-02 10:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_short_verts (TestState *state, int offset_x, int offset_y)
|
|
|
|
{
|
|
|
|
CoglAttribute *attributes[1];
|
|
|
|
CoglAttributeBuffer *buffer;
|
|
|
|
CoglPipeline *pipeline, *pipeline2;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
|
|
|
static const ShortVert short_verts[] =
|
|
|
|
{
|
|
|
|
{ -10, -10 },
|
|
|
|
{ -1, -10 },
|
|
|
|
{ -5, -1 }
|
|
|
|
};
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
pipeline = cogl_pipeline_new (ctx);
|
2011-12-02 10:55:41 +00:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX_TRANSFORM,
|
|
|
|
"attribute vec2 pos;",
|
|
|
|
NULL);
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"cogl_position_out = "
|
|
|
|
"cogl_modelview_projection_matrix * "
|
|
|
|
"vec4 (pos, 0.0, 1.0);");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
buffer = cogl_attribute_buffer_new (ctx,
|
2012-02-06 17:08:58 +00:00
|
|
|
sizeof (short_verts), short_verts);
|
2011-12-02 10:55:41 +00:00
|
|
|
attributes[0] = cogl_attribute_new (buffer,
|
|
|
|
"pos",
|
|
|
|
sizeof (ShortVert),
|
|
|
|
G_STRUCT_OFFSET (ShortVert, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_SHORT);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_push_matrix (fb);
|
|
|
|
cogl_framebuffer_translate (fb,
|
|
|
|
offset_x + 10.0f,
|
|
|
|
offset_y + 10.0f,
|
|
|
|
0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_draw_attributes (fb,
|
2012-01-08 02:59:04 +00:00
|
|
|
pipeline,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
0, /* first_vertex */
|
|
|
|
3, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
1 /* n_attributes */);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_pop_matrix (fb);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[0]);
|
|
|
|
|
|
|
|
/* Test again treating the attribute as unsigned */
|
|
|
|
attributes[0] = cogl_attribute_new (buffer,
|
|
|
|
"pos",
|
|
|
|
sizeof (ShortVert),
|
|
|
|
G_STRUCT_OFFSET (ShortVert, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_SHORT);
|
|
|
|
|
|
|
|
pipeline2 = cogl_pipeline_copy (pipeline);
|
|
|
|
cogl_pipeline_set_color4ub (pipeline2, 0, 255, 0, 255);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_push_matrix (fb);
|
|
|
|
cogl_framebuffer_translate (fb,
|
|
|
|
offset_x + 10.0f - 65525.0f,
|
|
|
|
offset_y - 65525,
|
|
|
|
0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_draw_attributes (fb,
|
2012-01-08 02:59:04 +00:00
|
|
|
pipeline2,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
0, /* first_vertex */
|
|
|
|
3, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
1 /* n_attributes */);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_pop_matrix (fb);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[0]);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline2);
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
cogl_object_unref (buffer);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_check_pixel (fb, offset_x + 5, offset_y + 5, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
|
2011-12-02 10:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint (TestState *state)
|
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
test_float_verts (state, 0, 0);
|
|
|
|
test_byte_verts (state, 0, 10);
|
|
|
|
test_short_verts (state, 0, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_custom_attributes (void)
|
2011-12-02 10:55:41 +00:00
|
|
|
{
|
|
|
|
/* If shaders aren't supported then we can't run the test */
|
|
|
|
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
|
|
|
|
{
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
TestState state;
|
2012-02-06 17:08:58 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_orthographic (fb,
|
|
|
|
0, 0,
|
|
|
|
cogl_framebuffer_get_width (fb),
|
|
|
|
cogl_framebuffer_get_height (fb),
|
|
|
|
-1,
|
|
|
|
100);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
state.pipeline = cogl_pipeline_new (ctx);
|
2011-12-02 10:55:41 +00:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
|
|
|
|
"attribute vec4 color;",
|
|
|
|
"cogl_color_out = color;");
|
|
|
|
cogl_pipeline_add_snippet (state.pipeline, snippet);
|
|
|
|
|
|
|
|
paint (&state);
|
|
|
|
|
|
|
|
cogl_object_unref (state.pipeline);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2012-02-23 12:30:51 +00:00
|
|
|
if (cogl_test_verbose ())
|
2011-12-02 10:55:41 +00:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|
2012-02-23 12:30:51 +00:00
|
|
|
else if (cogl_test_verbose ())
|
2011-12-02 10:55:41 +00:00
|
|
|
g_print ("Skipping\n");
|
|
|
|
}
|