2013-03-22 17:18:53 -04:00
|
|
|
#define COGL_VERSION_MIN_REQUIRED COGL_VERSION_1_0
|
|
|
|
|
2011-05-05 18:34:38 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
#include <string.h>
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
#include "test-utils.h"
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
/* Size the texture so that it is just off a power of two to encourage
|
2011-05-05 18:34:38 -04:00
|
|
|
it so use software tiling when NPOTs aren't available */
|
|
|
|
#define TEXTURE_SIZE 257
|
|
|
|
|
|
|
|
/* Amount of pixels to skip off the top, bottom, left and right of the
|
|
|
|
texture when reading back the stage */
|
2011-11-08 09:02:47 -05:00
|
|
|
#define TEST_INSET 2
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
/* Size to actually render the texture at */
|
2011-11-08 09:02:47 -05:00
|
|
|
#define TEXTURE_RENDER_SIZE 8
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglTexture *texture;
|
2011-09-19 10:24:36 -04:00
|
|
|
CoglFramebuffer *offscreen;
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglTexture *offscreen_tex;
|
2011-09-19 10:24:36 -04:00
|
|
|
int width, height;
|
2011-05-05 18:34:38 -04:00
|
|
|
} TestState;
|
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
static void
|
2012-03-16 15:54:13 -04:00
|
|
|
validate_part (CoglFramebuffer *framebuffer,
|
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 16:56:40 -04:00
|
|
|
int xnum, int ynum, CoglBool shown)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2012-03-16 15:54:13 -04:00
|
|
|
test_utils_check_region (framebuffer,
|
|
|
|
xnum * TEXTURE_RENDER_SIZE + TEST_INSET,
|
2011-11-08 09:02:47 -05:00
|
|
|
ynum * TEXTURE_RENDER_SIZE + TEST_INSET,
|
|
|
|
TEXTURE_RENDER_SIZE - TEST_INSET * 2,
|
|
|
|
TEXTURE_RENDER_SIZE - TEST_INSET * 2,
|
|
|
|
shown ? 0xff0000ff : 0x000000ff);
|
|
|
|
}
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
/* We draw everything 16 times. The draw number is used as a bitmask
|
|
|
|
to test all of the combinations of enabling legacy state, both
|
|
|
|
winding orders and all four culling modes */
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
#define USE_LEGACY_STATE(draw_num) (((draw_num) & 0x01) >> 0)
|
|
|
|
#define FRONT_WINDING(draw_num) (((draw_num) & 0x02) >> 1)
|
|
|
|
#define CULL_FACE_MODE(draw_num) (((draw_num) & 0x0c) >> 2)
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
static void
|
2012-03-16 15:54:13 -04:00
|
|
|
paint_test_backface_culling (TestState *state,
|
|
|
|
CoglFramebuffer *framebuffer)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2011-11-08 09:02:47 -05:00
|
|
|
int draw_num;
|
2013-01-18 12:57:06 -05:00
|
|
|
CoglPipeline *base_pipeline = cogl_pipeline_new (test_ctx);
|
2011-09-19 10:24:36 -04:00
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_framebuffer_orthographic (framebuffer,
|
|
|
|
0, 0,
|
|
|
|
state->width,
|
|
|
|
state->height,
|
|
|
|
-1,
|
|
|
|
100);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_framebuffer_clear4f (framebuffer,
|
|
|
|
COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_STENCIL,
|
|
|
|
0, 0, 0, 1);
|
2011-09-19 10:24:36 -04:00
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
cogl_pipeline_set_layer_texture (base_pipeline, 0, state->texture);
|
2011-09-19 10:24:36 -04:00
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
cogl_pipeline_set_layer_filters (base_pipeline, 0,
|
2011-09-19 10:24:36 -04:00
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_push_framebuffer (framebuffer);
|
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
/* Render the scene sixteen times to test all of the combinations of
|
|
|
|
cull face mode, legacy state and winding orders */
|
|
|
|
for (draw_num = 0; draw_num < 16; draw_num++)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
|
|
|
float x1 = 0, x2, y1 = 0, y2 = (float)(TEXTURE_RENDER_SIZE);
|
|
|
|
CoglTextureVertex verts[4];
|
2011-11-08 09:02:47 -05:00
|
|
|
CoglPipeline *pipeline;
|
|
|
|
|
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_translate (0, TEXTURE_RENDER_SIZE * draw_num, 0);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
pipeline = cogl_pipeline_copy (base_pipeline);
|
|
|
|
|
|
|
|
cogl_set_backface_culling_enabled (USE_LEGACY_STATE (draw_num));
|
|
|
|
cogl_pipeline_set_front_face_winding (pipeline, FRONT_WINDING (draw_num));
|
|
|
|
cogl_pipeline_set_cull_face_mode (pipeline, CULL_FACE_MODE (draw_num));
|
|
|
|
|
|
|
|
cogl_push_source (pipeline);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
memset (verts, 0, sizeof (verts));
|
|
|
|
|
|
|
|
x2 = x1 + (float)(TEXTURE_RENDER_SIZE);
|
|
|
|
|
|
|
|
/* Draw a front-facing texture */
|
|
|
|
cogl_rectangle (x1, y1, x2, y2);
|
|
|
|
|
|
|
|
x1 = x2;
|
|
|
|
x2 = x1 + (float)(TEXTURE_RENDER_SIZE);
|
|
|
|
|
|
|
|
/* Draw a front-facing texture with flipped texcoords */
|
|
|
|
cogl_rectangle_with_texture_coords (x1, y1, x2, y2,
|
|
|
|
1.0, 0.0, 0.0, 1.0);
|
|
|
|
|
|
|
|
x1 = x2;
|
|
|
|
x2 = x1 + (float)(TEXTURE_RENDER_SIZE);
|
|
|
|
|
|
|
|
/* Draw a back-facing texture */
|
|
|
|
cogl_rectangle (x2, y1, x1, y2);
|
|
|
|
|
|
|
|
x1 = x2;
|
|
|
|
x2 = x1 + (float)(TEXTURE_RENDER_SIZE);
|
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
/* If the texture is sliced then cogl_polygon doesn't work so
|
|
|
|
we'll just use a solid color instead */
|
|
|
|
if (cogl_texture_is_sliced (state->texture))
|
|
|
|
cogl_set_source_color4ub (255, 0, 0, 255);
|
|
|
|
|
|
|
|
/* Draw a front-facing polygon */
|
2011-05-05 18:34:38 -04:00
|
|
|
verts[0].x = x1; verts[0].y = y2;
|
|
|
|
verts[1].x = x2; verts[1].y = y2;
|
|
|
|
verts[2].x = x2; verts[2].y = y1;
|
|
|
|
verts[3].x = x1; verts[3].y = y1;
|
|
|
|
verts[0].tx = 0; verts[0].ty = 0;
|
|
|
|
verts[1].tx = 1.0; verts[1].ty = 0;
|
|
|
|
verts[2].tx = 1.0; verts[2].ty = 1.0;
|
|
|
|
verts[3].tx = 0; verts[3].ty = 1.0;
|
|
|
|
cogl_polygon (verts, 4, FALSE);
|
|
|
|
|
|
|
|
x1 = x2;
|
|
|
|
x2 = x1 + (float)(TEXTURE_RENDER_SIZE);
|
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
/* Draw a back-facing polygon */
|
2011-05-05 18:34:38 -04:00
|
|
|
verts[0].x = x1; verts[0].y = y1;
|
|
|
|
verts[1].x = x2; verts[1].y = y1;
|
|
|
|
verts[2].x = x2; verts[2].y = y2;
|
|
|
|
verts[3].x = x1; verts[3].y = y2;
|
|
|
|
verts[0].tx = 0; verts[0].ty = 0;
|
|
|
|
verts[1].tx = 1.0; verts[1].ty = 0;
|
|
|
|
verts[2].tx = 1.0; verts[2].ty = 1.0;
|
|
|
|
verts[3].tx = 0; verts[3].ty = 1.0;
|
|
|
|
cogl_polygon (verts, 4, FALSE);
|
|
|
|
|
|
|
|
x1 = x2;
|
|
|
|
x2 = x1 + (float)(TEXTURE_RENDER_SIZE);
|
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
cogl_pop_matrix ();
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
cogl_pop_source ();
|
|
|
|
cogl_object_unref (pipeline);
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
|
2011-11-08 09:02:47 -05:00
|
|
|
cogl_object_unref (base_pipeline);
|
2011-09-19 10:24:36 -04:00
|
|
|
}
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
static void
|
2012-03-16 15:54:13 -04:00
|
|
|
validate_result (CoglFramebuffer *framebuffer, int y_offset)
|
2011-09-19 10:24:36 -04:00
|
|
|
{
|
2011-11-08 09:02:47 -05:00
|
|
|
int draw_num;
|
|
|
|
|
|
|
|
for (draw_num = 0; draw_num < 16; draw_num++)
|
|
|
|
{
|
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 16:56:40 -04:00
|
|
|
CoglBool cull_front, cull_back;
|
2011-11-08 09:02:47 -05:00
|
|
|
CoglPipelineCullFaceMode cull_mode;
|
|
|
|
|
|
|
|
if (USE_LEGACY_STATE (draw_num))
|
|
|
|
cull_mode = COGL_PIPELINE_CULL_FACE_MODE_BACK;
|
|
|
|
else
|
|
|
|
cull_mode = CULL_FACE_MODE (draw_num);
|
|
|
|
|
|
|
|
switch (cull_mode)
|
|
|
|
{
|
|
|
|
case COGL_PIPELINE_CULL_FACE_MODE_NONE:
|
|
|
|
cull_front = FALSE;
|
|
|
|
cull_back = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PIPELINE_CULL_FACE_MODE_FRONT:
|
|
|
|
cull_front = TRUE;
|
|
|
|
cull_back = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PIPELINE_CULL_FACE_MODE_BACK:
|
|
|
|
cull_front = FALSE;
|
|
|
|
cull_back = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PIPELINE_CULL_FACE_MODE_BOTH:
|
|
|
|
cull_front = TRUE;
|
|
|
|
cull_back = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FRONT_WINDING (draw_num) == COGL_WINDING_CLOCKWISE)
|
|
|
|
{
|
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 16:56:40 -04:00
|
|
|
CoglBool tmp = cull_front;
|
2011-11-08 09:02:47 -05:00
|
|
|
cull_front = cull_back;
|
|
|
|
cull_back = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Front-facing texture */
|
2012-03-16 15:54:13 -04:00
|
|
|
validate_part (framebuffer,
|
|
|
|
0, y_offset + draw_num, !cull_front);
|
2011-11-08 09:02:47 -05:00
|
|
|
/* Front-facing texture with flipped tex coords */
|
2012-03-16 15:54:13 -04:00
|
|
|
validate_part (framebuffer,
|
|
|
|
1, y_offset + draw_num, !cull_front);
|
2011-11-08 09:02:47 -05:00
|
|
|
/* Back-facing texture */
|
2012-03-16 15:54:13 -04:00
|
|
|
validate_part (framebuffer,
|
|
|
|
2, y_offset + draw_num, !cull_back);
|
2011-11-08 09:02:47 -05:00
|
|
|
/* Front-facing texture polygon */
|
2012-03-16 15:54:13 -04:00
|
|
|
validate_part (framebuffer,
|
|
|
|
3, y_offset + draw_num, !cull_front);
|
2011-11-08 09:02:47 -05:00
|
|
|
/* Back-facing texture polygon */
|
2012-03-16 15:54:13 -04:00
|
|
|
validate_part (framebuffer,
|
|
|
|
4, y_offset + draw_num, !cull_back);
|
2011-11-08 09:02:47 -05:00
|
|
|
}
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-19 10:24:36 -04:00
|
|
|
paint (TestState *state)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglPipeline *pipeline;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
paint_test_backface_culling (state, test_fb);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
/*
|
2011-09-19 10:24:36 -04:00
|
|
|
* Now repeat the test but rendered to an offscreen
|
|
|
|
* framebuffer. Note that by default the conformance tests are
|
|
|
|
* always run to an offscreen buffer but we might as well have this
|
|
|
|
* check anyway in case it is being run with COGL_TEST_ONSCREEN=1
|
2011-05-05 18:34:38 -04:00
|
|
|
*/
|
2012-03-16 15:54:13 -04:00
|
|
|
paint_test_backface_culling (state, state->offscreen);
|
|
|
|
|
|
|
|
/* Copy the result of the offscreen rendering for validation and
|
|
|
|
* also so we can have visual feedback. */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, state->offscreen_tex);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
0, TEXTURE_RENDER_SIZE * 16,
|
|
|
|
state->width,
|
|
|
|
state->height + TEXTURE_RENDER_SIZE * 16);
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
validate_result (test_fb, 0);
|
|
|
|
validate_result (test_fb, 16);
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
static CoglTexture *
|
2011-05-05 18:34:38 -04:00
|
|
|
make_texture (void)
|
|
|
|
{
|
|
|
|
guchar *tex_data, *p;
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglTexture *tex;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
tex_data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);
|
|
|
|
|
|
|
|
for (p = tex_data + TEXTURE_SIZE * TEXTURE_SIZE * 4; p > tex_data;)
|
|
|
|
{
|
|
|
|
*(--p) = 255;
|
|
|
|
*(--p) = 0;
|
|
|
|
*(--p) = 0;
|
|
|
|
*(--p) = 255;
|
|
|
|
}
|
|
|
|
|
2013-06-08 20:09:04 -04:00
|
|
|
tex = test_utils_texture_new_from_data (test_ctx,
|
|
|
|
TEXTURE_SIZE,
|
|
|
|
TEXTURE_SIZE,
|
|
|
|
TEST_UTILS_TEXTURE_NO_ATLAS,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
TEXTURE_SIZE * 4,
|
|
|
|
tex_data);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
g_free (tex_data);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 15:54:13 -04:00
|
|
|
test_backface_culling (void)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
|
|
|
TestState state;
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglTexture *tex;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
state.width = cogl_framebuffer_get_width (test_fb);
|
|
|
|
state.height = cogl_framebuffer_get_height (test_fb);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
state.offscreen = NULL;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
state.texture = make_texture ();
|
|
|
|
|
2013-06-08 20:09:04 -04:00
|
|
|
tex = test_utils_texture_new_with_size (test_ctx,
|
|
|
|
state.width, state.height,
|
|
|
|
TEST_UTILS_TEXTURE_NO_SLICING,
|
|
|
|
COGL_PIXEL_FORMAT_ANY); /* internal
|
|
|
|
format */
|
2012-02-18 10:22:15 -05:00
|
|
|
state.offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_to_texture (tex));
|
2011-05-05 18:34:38 -04:00
|
|
|
state.offscreen_tex = tex;
|
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
paint (&state);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-09-19 10:24:36 -04:00
|
|
|
cogl_object_unref (state.offscreen);
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_object_unref (state.offscreen_tex);
|
|
|
|
cogl_object_unref (state.texture);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 18:34:38 -04:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|
|
|
|
|