2011-12-02 10:55:41 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-01-20 10:41:48 +00:00
|
|
|
#include "test-declarations.h"
|
2011-12-02 10:55:41 +00:00
|
|
|
#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;
|
2013-08-16 20:23:37 +00:00
|
|
|
int16_t r, g, b, a;
|
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;
|
2013-07-09 23:39:18 +00:00
|
|
|
CoglPrimitive *primitive;
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
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 }
|
|
|
|
};
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
buffer = cogl_attribute_buffer_new (test_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);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_push_matrix (test_fb);
|
|
|
|
cogl_framebuffer_translate (test_fb, offset_x, offset_y, 0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-07-09 23:39:18 +00:00
|
|
|
primitive = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
6, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
2); /* n_attributes */
|
|
|
|
cogl_primitive_draw (primitive, test_fb, state->pipeline);
|
|
|
|
cogl_object_unref (primitive);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_pop_matrix (test_fb);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[1]);
|
|
|
|
cogl_object_unref (attributes[0]);
|
|
|
|
cogl_object_unref (buffer);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_pixel (test_fb, offset_x + 5, offset_y + 5, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (test_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;
|
2013-07-09 23:39:18 +00:00
|
|
|
CoglPrimitive *primitive;
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
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 },
|
|
|
|
};
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
buffer = cogl_attribute_buffer_new (test_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);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_push_matrix (test_fb);
|
|
|
|
cogl_framebuffer_translate (test_fb, offset_x, offset_y, 0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-07-09 23:39:18 +00:00
|
|
|
primitive = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
6, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
2); /* n_attributes */
|
|
|
|
cogl_primitive_draw (primitive, test_fb, state->pipeline);
|
|
|
|
cogl_object_unref (primitive);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[1]);
|
|
|
|
|
|
|
|
/* Test again with unnormalized attributes */
|
2013-01-18 17:57:06 +00:00
|
|
|
unnorm_buffer = cogl_attribute_buffer_new (test_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);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_translate (test_fb, 20, 0, 0);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-07-09 23:39:18 +00:00
|
|
|
primitive = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
3, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
2); /* n_attributes */
|
|
|
|
cogl_primitive_draw (primitive, test_fb, state->pipeline);
|
|
|
|
cogl_object_unref (primitive);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_pop_matrix (test_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);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_pixel (test_fb, offset_x + 5, offset_y + 5, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (test_fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
|
|
|
|
test_utils_check_pixel (test_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)
|
|
|
|
{
|
2013-08-16 20:23:37 +00:00
|
|
|
CoglAttribute *attributes[2];
|
2011-12-02 10:55:41 +00:00
|
|
|
CoglAttributeBuffer *buffer;
|
|
|
|
CoglPipeline *pipeline, *pipeline2;
|
|
|
|
CoglSnippet *snippet;
|
2013-07-09 23:39:18 +00:00
|
|
|
CoglPrimitive *primitive;
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
static const ShortVert short_verts[] =
|
|
|
|
{
|
2013-08-16 20:23:37 +00:00
|
|
|
{ -10, -10, /**/ 0xffff, 0, 0, 0xffff },
|
|
|
|
{ -1, -10, /**/ 0xffff, 0, 0, 0xffff },
|
|
|
|
{ -5, -1, /**/ 0xffff, 0, 0, 0xffff }
|
2011-12-02 10:55:41 +00:00
|
|
|
};
|
|
|
|
|
2013-08-16 20:23:37 +00:00
|
|
|
|
|
|
|
pipeline = cogl_pipeline_copy (state->pipeline);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
buffer = cogl_attribute_buffer_new (test_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,
|
2013-08-16 20:23:37 +00:00
|
|
|
"cogl_position_in",
|
2011-12-02 10:55:41 +00:00
|
|
|
sizeof (ShortVert),
|
|
|
|
G_STRUCT_OFFSET (ShortVert, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_SHORT);
|
2013-08-16 20:23:37 +00:00
|
|
|
attributes[1] = cogl_attribute_new (buffer,
|
|
|
|
"color",
|
|
|
|
sizeof (ShortVert),
|
|
|
|
G_STRUCT_OFFSET (ShortVert, r),
|
|
|
|
4, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_SHORT);
|
|
|
|
cogl_attribute_set_normalized (attributes[1], TRUE);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_push_matrix (test_fb);
|
|
|
|
cogl_framebuffer_translate (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
offset_x + 10.0f,
|
|
|
|
offset_y + 10.0f,
|
|
|
|
0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-07-09 23:39:18 +00:00
|
|
|
primitive = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
3, /* n_vertices */
|
|
|
|
attributes,
|
2013-08-16 20:23:37 +00:00
|
|
|
2); /* n_attributes */
|
2013-07-09 23:39:18 +00:00
|
|
|
cogl_primitive_draw (primitive, test_fb, pipeline);
|
|
|
|
cogl_object_unref (primitive);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_pop_matrix (test_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,
|
2013-08-16 20:23:37 +00:00
|
|
|
"cogl_position_in",
|
2011-12-02 10:55:41 +00:00
|
|
|
sizeof (ShortVert),
|
|
|
|
G_STRUCT_OFFSET (ShortVert, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_SHORT);
|
|
|
|
|
2013-08-16 20:23:37 +00:00
|
|
|
/* XXX: this is a hack to force the pipeline to use the glsl backend
|
|
|
|
* because we know it's not possible to test short vertex position
|
|
|
|
* components with the legacy GL backend since which might otherwise
|
|
|
|
* be used internally... */
|
|
|
|
pipeline2 = cogl_pipeline_new (test_ctx);
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
|
|
|
|
"attribute vec4 color;",
|
|
|
|
"cogl_color_out = vec4 (0.0, 1.0, 0.0, 1.0);");
|
|
|
|
cogl_pipeline_add_snippet (pipeline2, snippet);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_push_matrix (test_fb);
|
|
|
|
cogl_framebuffer_translate (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
offset_x + 10.0f - 65525.0f,
|
|
|
|
offset_y - 65525,
|
|
|
|
0.0f);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-07-09 23:39:18 +00:00
|
|
|
primitive = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
|
|
|
|
3, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
1); /* n_attributes */
|
|
|
|
cogl_primitive_draw (primitive, test_fb, pipeline2);
|
|
|
|
cogl_object_unref (primitive);
|
2011-12-02 10:55:41 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_pop_matrix (test_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);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_pixel (test_fb, offset_x + 5, offset_y + 5, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (test_fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
|
2011-12-02 10:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint (TestState *state)
|
|
|
|
{
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_clear4f (test_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
|
|
|
{
|
2012-11-09 15:14:33 +00:00
|
|
|
CoglSnippet *snippet;
|
|
|
|
TestState state;
|
|
|
|
|
|
|
|
cogl_framebuffer_orthographic (test_fb,
|
|
|
|
0, 0,
|
|
|
|
cogl_framebuffer_get_width (test_fb),
|
|
|
|
cogl_framebuffer_get_height (test_fb),
|
|
|
|
-1,
|
|
|
|
100);
|
|
|
|
|
|
|
|
state.pipeline = cogl_pipeline_new (test_ctx);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (cogl_test_verbose ())
|
|
|
|
g_print ("OK\n");
|
2011-12-02 10:55:41 +00:00
|
|
|
}
|