2011-09-15 08:12:27 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
#define TEX_SIZE 128
|
|
|
|
|
|
|
|
#define NUM_FBOS 3
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglTexture *tex[NUM_FBOS];
|
2011-09-15 08:12:27 -04:00
|
|
|
CoglFramebuffer *fbo[NUM_FBOS];
|
|
|
|
} TestState;
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint (TestState *state)
|
|
|
|
{
|
|
|
|
CoglColor bg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cogl_set_source_color4ub (255, 255, 255, 255);
|
|
|
|
|
|
|
|
/* We push the third framebuffer first so that later we can switch
|
|
|
|
back to it by popping to test that that works */
|
|
|
|
cogl_push_framebuffer (state->fbo[2]);
|
|
|
|
|
|
|
|
cogl_push_framebuffer (state->fbo[0]);
|
|
|
|
cogl_rectangle (-1.0, -1.0, 1.0, 1.0);
|
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
|
|
|
|
cogl_push_framebuffer (state->fbo[1]);
|
|
|
|
cogl_rectangle (-1.0, -1.0, 1.0, 1.0);
|
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
|
|
|
|
/* We should now be back on the third framebuffer */
|
|
|
|
cogl_rectangle (-1.0, -1.0, 1.0, 1.0);
|
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
|
|
|
|
cogl_color_init_from_4ub (&bg, 128, 128, 128, 255);
|
|
|
|
cogl_clear (&bg, COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_DEPTH);
|
|
|
|
|
|
|
|
/* Render all of the textures to the screen */
|
|
|
|
for (i = 0; i < NUM_FBOS; i++)
|
|
|
|
{
|
2013-01-18 12:57:06 -05:00
|
|
|
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, state->tex[i]);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline,
|
2012-03-16 15:54:13 -04:00
|
|
|
2.0f / NUM_FBOS * i - 1.0f, -1.0f,
|
|
|
|
2.0f / NUM_FBOS * (i + 1) - 1.0f, 1.0f);
|
|
|
|
cogl_object_unref (pipeline);
|
2011-09-15 08:12:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify all of the fbos drew the right color */
|
|
|
|
for (i = 0; i < NUM_FBOS; i++)
|
|
|
|
{
|
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
|
|
|
uint8_t expected_colors[NUM_FBOS][4] =
|
2011-09-15 08:12:27 -04:00
|
|
|
{ { 0xff, 0x00, 0x00, 0xff },
|
|
|
|
{ 0x00, 0xff, 0x00, 0xff },
|
|
|
|
{ 0x00, 0x00, 0xff, 0xff } };
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel_rgb (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
state->width * (i + 0.5f) / NUM_FBOS,
|
2011-10-26 09:15:14 -04:00
|
|
|
state->height / 2,
|
|
|
|
expected_colors[i][0],
|
|
|
|
expected_colors[i][1],
|
|
|
|
expected_colors[i][2]);
|
2011-09-15 08:12:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 15:54:13 -04:00
|
|
|
test_color_mask (void)
|
2011-09-15 08:12:27 -04:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
int i;
|
|
|
|
|
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-09-28 14:48:45 -04:00
|
|
|
|
2011-09-15 08:12:27 -04:00
|
|
|
for (i = 0; i < NUM_FBOS; i++)
|
|
|
|
{
|
2013-06-08 20:09:04 -04:00
|
|
|
state.tex[i] = test_utils_texture_new_with_size (test_ctx, 128, 128,
|
|
|
|
TEST_UTILS_TEXTURE_NO_ATLAS,
|
2011-09-15 08:12:27 -04:00
|
|
|
COGL_PIXEL_FORMAT_RGB_888);
|
|
|
|
|
|
|
|
|
2013-10-09 08:31:12 -04:00
|
|
|
state.fbo[i] = cogl_offscreen_new_with_texture (state.tex[i]);
|
2011-09-28 14:48:45 -04:00
|
|
|
|
|
|
|
/* Clear the texture color bits */
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_framebuffer_clear4f (state.fbo[i],
|
|
|
|
COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
|
2011-09-28 14:48:45 -04:00
|
|
|
|
2011-09-15 08:12:27 -04:00
|
|
|
cogl_framebuffer_set_color_mask (state.fbo[i],
|
|
|
|
i == 0 ? COGL_COLOR_MASK_RED :
|
|
|
|
i == 1 ? COGL_COLOR_MASK_GREEN :
|
|
|
|
COGL_COLOR_MASK_BLUE);
|
|
|
|
}
|
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
/* XXX: we have to push/pop a framebuffer since this test currently
|
|
|
|
* uses the legacy cogl_rectangle() api. */
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_push_framebuffer (test_fb);
|
2011-09-15 08:12:27 -04:00
|
|
|
paint (&state);
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_pop_framebuffer ();
|
2011-09-15 08:12:27 -04:00
|
|
|
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-09-15 08:12:27 -04:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|
|
|
|
|