2013-03-22 21:18:53 +00:00
|
|
|
#define COGL_VERSION_MIN_REQUIRED COGL_VERSION_1_0
|
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
#include <cogl/cogl.h>
|
2011-05-05 22:34:38 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-01-20 10:41:48 +00:00
|
|
|
#include "test-declarations.h"
|
2011-10-12 16:12:08 +00:00
|
|
|
#include "test-utils.h"
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
#define TEX_SIZE 4
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
CoglTexture *texture;
|
2011-05-05 22:34:38 +00:00
|
|
|
} TestState;
|
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
static CoglTexture *
|
2013-06-09 00:09:04 +00:00
|
|
|
create_texture (TestUtilsTextureFlags flags)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
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
|
|
|
uint8_t *data = g_malloc (TEX_SIZE * TEX_SIZE * 4), *p = data;
|
2011-10-12 16:12:08 +00:00
|
|
|
CoglTexture *tex;
|
2011-05-05 22:34:38 +00:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < TEX_SIZE; y++)
|
|
|
|
for (x = 0; x < TEX_SIZE; x++)
|
|
|
|
{
|
|
|
|
*(p++) = 0;
|
|
|
|
*(p++) = (x & 1) * 255;
|
|
|
|
*(p++) = (y & 1) * 255;
|
|
|
|
*(p++) = 255;
|
|
|
|
}
|
|
|
|
|
2013-06-09 00:09:04 +00:00
|
|
|
tex = test_utils_texture_new_from_data (test_ctx,
|
|
|
|
TEX_SIZE, TEX_SIZE, flags,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
TEX_SIZE * 4,
|
|
|
|
data);
|
2011-05-05 22:34:38 +00:00
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
static CoglPipeline *
|
|
|
|
create_pipeline (TestState *state,
|
|
|
|
CoglPipelineWrapMode wrap_mode_s,
|
|
|
|
CoglPipelineWrapMode wrap_mode_t)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
CoglPipeline *pipeline;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-10-12 16:12:08 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, state->texture);
|
|
|
|
cogl_pipeline_set_layer_filters (pipeline, 0,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_s (pipeline, 0, wrap_mode_s);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_t (pipeline, 0, wrap_mode_t);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
return pipeline;
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
static CoglPipelineWrapMode
|
2012-03-16 19:54:13 +00:00
|
|
|
wrap_modes[] =
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
COGL_PIPELINE_WRAP_MODE_AUTOMATIC,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_AUTOMATIC,
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
COGL_PIPELINE_WRAP_MODE_AUTOMATIC,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE
|
2011-05-05 22:34:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_tests (TestState *state)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
|
|
|
|
CoglPipeline *pipeline;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
/* Create a separate pipeline for each pair of wrap modes so
|
2011-05-05 22:34:38 +00:00
|
|
|
that we can verify whether the batch splitting works */
|
2012-03-16 19:54:13 +00:00
|
|
|
wrap_mode_s = wrap_modes[i];
|
|
|
|
wrap_mode_t = wrap_modes[i + 1];
|
2011-10-12 16:12:08 +00:00
|
|
|
pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
|
|
|
|
/* Render the pipeline at four times the size of the texture */
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
pipeline,
|
|
|
|
i * TEX_SIZE,
|
|
|
|
0,
|
|
|
|
(i + 2) * TEX_SIZE,
|
|
|
|
TEX_SIZE * 2,
|
|
|
|
0, 0, 2, 2);
|
|
|
|
cogl_object_unref (pipeline);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const CoglTextureVertex vertices[4] =
|
|
|
|
{
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
|
|
|
|
{ 0.0f, TEX_SIZE * 2, 0.0f, 0.0f, 2.0f },
|
|
|
|
{ TEX_SIZE * 2, TEX_SIZE * 2, 0.0f, 2.0f, 2.0f },
|
|
|
|
{ TEX_SIZE * 2, 0.0f, 0.0f, 2.0f, 0.0f }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_tests_polygon (TestState *state)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
|
|
|
|
CoglPipeline *pipeline;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
wrap_mode_s = wrap_modes[i];
|
|
|
|
wrap_mode_t = wrap_modes[i + 1];
|
2011-10-12 16:12:08 +00:00
|
|
|
pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
|
|
|
|
cogl_set_source (pipeline);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_unref (pipeline);
|
2011-05-05 22:34:38 +00:00
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_translate (TEX_SIZE * i, 0.0f, 0.0f);
|
2011-10-12 16:12:08 +00:00
|
|
|
/* Render the pipeline at four times the size of the texture */
|
2011-05-05 22:34:38 +00:00
|
|
|
cogl_polygon (vertices, G_N_ELEMENTS (vertices), FALSE);
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_tests_vbo (TestState *state)
|
|
|
|
{
|
|
|
|
CoglHandle vbo;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vbo = cogl_vertex_buffer_new (4);
|
|
|
|
cogl_vertex_buffer_add (vbo, "gl_Vertex", 3,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT, FALSE,
|
|
|
|
sizeof (vertices[0]),
|
|
|
|
&vertices[0].x);
|
|
|
|
cogl_vertex_buffer_add (vbo, "gl_MultiTexCoord0", 2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT, FALSE,
|
|
|
|
sizeof (vertices[0]),
|
|
|
|
&vertices[0].tx);
|
|
|
|
cogl_vertex_buffer_submit (vbo);
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
|
|
|
|
CoglPipeline *pipeline;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
wrap_mode_s = wrap_modes[i];
|
|
|
|
wrap_mode_t = wrap_modes[i + 1];
|
2011-10-12 16:12:08 +00:00
|
|
|
pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
|
|
|
|
cogl_set_source (pipeline);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_unref (pipeline);
|
2011-05-05 22:34:38 +00:00
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_translate (TEX_SIZE * i, 0.0f, 0.0f);
|
2011-10-12 16:12:08 +00:00
|
|
|
/* Render the pipeline at four times the size of the texture */
|
2011-05-05 22:34:38 +00:00
|
|
|
cogl_vertex_buffer_draw (vbo, COGL_VERTICES_MODE_TRIANGLE_FAN, 0, 4);
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:51:12 +00:00
|
|
|
cogl_object_unref (vbo);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
validate_set (TestState *state, int offset)
|
|
|
|
{
|
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
|
|
|
uint8_t data[TEX_SIZE * 2 * TEX_SIZE * 2 * 4], *p;
|
2011-05-05 22:34:38 +00:00
|
|
|
int x, y, i;
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
wrap_mode_s = wrap_modes[i];
|
|
|
|
wrap_mode_t = wrap_modes[i + 1];
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_read_pixels (test_fb, i * TEX_SIZE, offset * TEX_SIZE * 2,
|
2012-03-16 19:54:13 +00:00
|
|
|
TEX_SIZE * 2, TEX_SIZE * 2,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
data);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
p = data;
|
|
|
|
|
|
|
|
for (y = 0; y < TEX_SIZE * 2; y++)
|
|
|
|
for (x = 0; x < TEX_SIZE * 2; x++)
|
|
|
|
{
|
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
|
|
|
uint8_t green, blue;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
if (x < TEX_SIZE ||
|
2011-10-12 16:12:08 +00:00
|
|
|
wrap_mode_s == COGL_PIPELINE_WRAP_MODE_REPEAT ||
|
|
|
|
wrap_mode_s == COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2011-05-05 22:34:38 +00:00
|
|
|
green = (x & 1) * 255;
|
|
|
|
else
|
|
|
|
green = ((TEX_SIZE - 1) & 1) * 255;
|
|
|
|
|
|
|
|
if (y < TEX_SIZE ||
|
2011-10-12 16:12:08 +00:00
|
|
|
wrap_mode_t == COGL_PIPELINE_WRAP_MODE_REPEAT ||
|
|
|
|
wrap_mode_t == COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2011-05-05 22:34:38 +00:00
|
|
|
blue = (y & 1) * 255;
|
|
|
|
else
|
|
|
|
blue = ((TEX_SIZE - 1) & 1) * 255;
|
|
|
|
|
|
|
|
g_assert_cmpint (p[0], ==, 0);
|
|
|
|
g_assert_cmpint (p[1], ==, green);
|
|
|
|
g_assert_cmpint (p[2], ==, blue);
|
|
|
|
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
validate_result (TestState *state)
|
|
|
|
{
|
|
|
|
validate_set (state, 0); /* non-atlased rectangle */
|
|
|
|
#if 0 /* this doesn't currently work */
|
|
|
|
validate_set (state, 1); /* atlased rectangle */
|
|
|
|
#endif
|
|
|
|
validate_set (state, 2); /* cogl_polygon */
|
|
|
|
validate_set (state, 3); /* vertex buffer */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-12 16:12:08 +00:00
|
|
|
paint (TestState *state)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-12 16:12:08 +00:00
|
|
|
/* Draw the tests first with a non atlased texture */
|
2013-06-09 00:09:04 +00:00
|
|
|
state->texture = create_texture (TEST_UTILS_TEXTURE_NO_ATLAS);
|
2011-10-12 16:12:08 +00:00
|
|
|
draw_tests (state);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_unref (state->texture);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
/* Draw the tests again with a possible atlased texture. This should
|
|
|
|
end up testing software repeats */
|
2013-06-09 00:09:04 +00:00
|
|
|
state->texture = create_texture (TEST_UTILS_TEXTURE_NONE);
|
|
|
|
cogl_framebuffer_push_matrix (test_fb);
|
|
|
|
cogl_framebuffer_translate (test_fb, 0.0f, TEX_SIZE * 2.0f, 0.0f);
|
2011-10-12 16:12:08 +00:00
|
|
|
draw_tests (state);
|
|
|
|
cogl_pop_matrix ();
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_unref (state->texture);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
/* Draw the tests using cogl_polygon */
|
|
|
|
state->texture = create_texture (COGL_TEXTURE_NO_ATLAS);
|
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_translate (0.0f, TEX_SIZE * 4.0f, 0.0f);
|
|
|
|
draw_tests_polygon (state);
|
|
|
|
cogl_pop_matrix ();
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_unref (state->texture);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-12 16:12:08 +00:00
|
|
|
/* Draw the tests using a vertex buffer */
|
|
|
|
state->texture = create_texture (COGL_TEXTURE_NO_ATLAS);
|
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_translate (0.0f, TEX_SIZE * 6.0f, 0.0f);
|
|
|
|
draw_tests_vbo (state);
|
|
|
|
cogl_pop_matrix ();
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_unref (state->texture);
|
2011-10-12 16:12:08 +00:00
|
|
|
|
|
|
|
validate_result (state);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_wrap_modes (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
state.width = cogl_framebuffer_get_width (test_fb);
|
|
|
|
state.height = cogl_framebuffer_get_height (test_fb);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_orthographic (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
0, 0,
|
|
|
|
state.width,
|
|
|
|
state.height,
|
|
|
|
-1,
|
|
|
|
100);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
/* XXX: we have to push/pop a framebuffer since this test currently
|
|
|
|
* uses the legacy cogl_vertex_buffer_draw() api. */
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_push_framebuffer (test_fb);
|
2011-10-12 16:12:08 +00:00
|
|
|
paint (&state);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_pop_framebuffer ();
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-02-23 12:30:51 +00:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 22:34:38 +00:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|