2008-11-10 18:53:14 +00:00
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
2009-01-20 21:12:44 +00:00
|
|
|
/* This test verifies that the simplest usage of the vertex buffer API,
|
|
|
|
* where we add contiguous (x,y) GLfloat vertices, and RGBA GLubyte color
|
|
|
|
* attributes to a buffer, submit, and draw.
|
2008-11-10 18:53:14 +00:00
|
|
|
*
|
|
|
|
* It also tries to verify that the enable/disable attribute APIs are working
|
|
|
|
* too.
|
|
|
|
*
|
|
|
|
* If you want visual feedback of what this test paints for debugging purposes,
|
|
|
|
* then remove the call to clutter_main_quit() in validate_result.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2009-01-20 21:12:44 +00:00
|
|
|
CoglHandle buffer;
|
2009-02-06 16:10:28 +00:00
|
|
|
CoglHandle texture;
|
|
|
|
CoglHandle material;
|
2008-11-10 18:53:14 +00:00
|
|
|
ClutterGeometry stage_geom;
|
|
|
|
} TestState;
|
|
|
|
|
|
|
|
static void
|
|
|
|
validate_result (TestState *state)
|
|
|
|
{
|
|
|
|
GLubyte pixel[4];
|
2009-06-17 13:30:44 +00:00
|
|
|
GLint y_off = 90;
|
2008-11-18 12:54:34 +00:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("y_off = %d\n", y_off);
|
|
|
|
|
2008-11-10 18:53:14 +00:00
|
|
|
/* NB: We ignore the alpha, since we don't know if our render target is
|
|
|
|
* RGB or RGBA */
|
|
|
|
|
|
|
|
#define RED 0
|
|
|
|
#define GREEN 1
|
|
|
|
#define BLUE 2
|
|
|
|
|
|
|
|
/* Should see a blue pixel */
|
2009-06-17 13:30:44 +00:00
|
|
|
cogl_read_pixels (10, y_off, 1, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
2010-03-01 18:08:41 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2009-06-17 13:30:44 +00:00
|
|
|
pixel);
|
2008-11-18 12:54:34 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
|
2008-11-10 18:53:14 +00:00
|
|
|
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
|
2009-01-20 21:12:44 +00:00
|
|
|
|
2008-11-10 18:53:14 +00:00
|
|
|
/* Should see a red pixel */
|
2009-06-17 13:30:44 +00:00
|
|
|
cogl_read_pixels (110, y_off, 1, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
2010-03-01 18:08:41 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2009-06-17 13:30:44 +00:00
|
|
|
pixel);
|
2008-11-18 12:54:34 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("pixel 1 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
|
2008-11-10 18:53:14 +00:00
|
|
|
g_assert (pixel[RED] != 0 && pixel[GREEN] == 0 && pixel[BLUE] == 0);
|
|
|
|
|
|
|
|
/* Should see a blue pixel */
|
2009-06-17 13:30:44 +00:00
|
|
|
cogl_read_pixels (210, y_off, 1, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
2010-03-01 18:08:41 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2009-06-17 13:30:44 +00:00
|
|
|
pixel);
|
2008-11-18 12:54:34 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("pixel 2 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
|
2008-11-10 18:53:14 +00:00
|
|
|
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
|
2009-01-20 21:12:44 +00:00
|
|
|
|
2009-02-23 16:33:42 +00:00
|
|
|
/* Should see a green pixel, at bottom of 4th triangle */
|
2009-06-17 13:30:44 +00:00
|
|
|
cogl_read_pixels (310, y_off, 1, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
2010-03-01 18:08:41 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2009-06-17 13:30:44 +00:00
|
|
|
pixel);
|
2009-02-23 16:33:42 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("pixel 3 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
|
|
|
|
g_assert (pixel[GREEN] > pixel[RED] && pixel[GREEN] > pixel[BLUE]);
|
|
|
|
|
|
|
|
/* Should see a red pixel, at top of 4th triangle */
|
2009-06-17 13:30:44 +00:00
|
|
|
cogl_read_pixels (310, y_off - 70, 1, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
2010-03-01 18:08:41 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2009-06-17 13:30:44 +00:00
|
|
|
pixel);
|
2009-02-23 16:33:42 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("pixel 4 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
|
|
|
|
g_assert (pixel[RED] > pixel[GREEN] && pixel[RED] > pixel[BLUE]);
|
|
|
|
|
|
|
|
|
2008-11-10 18:53:14 +00:00
|
|
|
#undef RED
|
|
|
|
#undef GREEN
|
|
|
|
#undef BLUE
|
2009-01-20 21:12:44 +00:00
|
|
|
|
2008-11-10 18:53:14 +00:00
|
|
|
/* Comment this out if you want visual feedback of what this test
|
|
|
|
* paints.
|
|
|
|
*/
|
|
|
|
clutter_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_paint (ClutterActor *actor, TestState *state)
|
|
|
|
{
|
|
|
|
/* Draw a faded blue triangle */
|
2009-01-20 21:12:44 +00:00
|
|
|
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
|
2008-11-13 14:28:16 +00:00
|
|
|
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
2009-01-20 21:12:44 +00:00
|
|
|
cogl_vertex_buffer_draw (state->buffer,
|
2009-02-06 16:10:28 +00:00
|
|
|
GL_TRIANGLE_STRIP, /* mode */
|
|
|
|
0, /* first */
|
|
|
|
3); /* count */
|
2009-01-20 21:12:44 +00:00
|
|
|
|
2008-11-10 18:53:14 +00:00
|
|
|
/* Draw a red triangle */
|
|
|
|
/* Here we are testing that the disable attribute works; if it doesn't
|
|
|
|
* the triangle will remain faded blue */
|
|
|
|
cogl_translate (100, 0, 0);
|
2009-01-20 21:12:44 +00:00
|
|
|
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
|
2008-11-13 14:28:16 +00:00
|
|
|
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
2009-01-20 21:12:44 +00:00
|
|
|
cogl_vertex_buffer_draw (state->buffer,
|
|
|
|
GL_TRIANGLE_STRIP, /* mode */
|
|
|
|
0, /* first */
|
|
|
|
3); /* count */
|
2008-11-10 18:53:14 +00:00
|
|
|
|
|
|
|
/* Draw a faded blue triangle */
|
|
|
|
/* Here we are testing that the re-enable works; if it doesn't
|
|
|
|
* the triangle will remain red */
|
|
|
|
cogl_translate (100, 0, 0);
|
2009-01-20 21:12:44 +00:00
|
|
|
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
|
2008-11-13 14:28:16 +00:00
|
|
|
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
2009-01-20 21:12:44 +00:00
|
|
|
cogl_vertex_buffer_draw (state->buffer,
|
|
|
|
GL_TRIANGLE_STRIP, /* mode */
|
|
|
|
0, /* first */
|
|
|
|
3); /* count */
|
|
|
|
|
2009-02-06 16:10:28 +00:00
|
|
|
/* Draw a textured triangle */
|
|
|
|
cogl_translate (100, 0, 0);
|
|
|
|
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
|
|
|
|
cogl_set_source (state->material);
|
2009-02-23 16:33:42 +00:00
|
|
|
cogl_material_set_color4ub (state->material, 0xff, 0xff, 0xff, 0xff);
|
2009-02-06 16:10:28 +00:00
|
|
|
cogl_vertex_buffer_draw (state->buffer,
|
|
|
|
GL_TRIANGLE_STRIP, /* mode */
|
|
|
|
0, /* first */
|
|
|
|
3); /* count */
|
|
|
|
|
2010-07-08 18:20:33 +00:00
|
|
|
validate_result (state);
|
2008-11-10 18:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
queue_redraw (gpointer stage)
|
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
2008-11-12 10:55:06 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2008-11-10 18:53:14 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 16:33:42 +00:00
|
|
|
|
|
|
|
|
2008-11-10 18:53:14 +00:00
|
|
|
void
|
2009-11-27 00:28:39 +00:00
|
|
|
test_cogl_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2008-11-10 18:53:14 +00:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
|
|
|
|
ClutterActor *group;
|
2008-11-28 16:25:20 +00:00
|
|
|
guint idle_source;
|
2009-02-23 16:33:42 +00:00
|
|
|
guchar tex_data[] = {
|
|
|
|
0xff, 0x00, 0x00, 0xff,
|
|
|
|
0xff, 0x00, 0x00, 0xff,
|
|
|
|
0x00, 0xff, 0x00, 0xff,
|
|
|
|
0x00, 0xff, 0x00, 0xff
|
|
|
|
};
|
2008-11-10 18:53:14 +00:00
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
|
|
|
|
clutter_actor_get_geometry (stage, &state.stage_geom);
|
|
|
|
|
|
|
|
group = clutter_group_new ();
|
|
|
|
clutter_actor_set_size (group,
|
|
|
|
state.stage_geom.width,
|
|
|
|
state.stage_geom.height);
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
|
|
|
|
|
2010-07-08 18:20:33 +00:00
|
|
|
/* We force continuous redrawing incase someone comments out the
|
|
|
|
* clutter_main_quit and wants visual feedback for the test since we
|
|
|
|
* wont be doing anything else that will trigger redrawing. */
|
2008-11-28 16:25:20 +00:00
|
|
|
idle_source = g_idle_add (queue_redraw, stage);
|
2008-11-10 18:53:14 +00:00
|
|
|
|
|
|
|
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
2009-01-20 21:12:44 +00:00
|
|
|
|
2009-02-23 16:33:42 +00:00
|
|
|
state.texture = cogl_texture_new_from_data (2, 2,
|
[cogl] Remove max_waste argument from Texture ctors
The CoglTexture constructors expose the "max-waste" argument for
controlling the maximum amount of wasted areas for slicing or,
if set to -1, disables slicing.
Slicing is really relevant only for large images that are never
repeated, so it's a useful feature only in controlled use cases.
Specifying the amount of wasted area is, on the other hand, just
a way to mess up this feature; 99% the times, you either pull this
number out of thin air, hoping it's right, or you try to do the
right thing and you choose the wrong number anyway.
Instead, we can use the CoglTextureFlags to control whether the
texture should not be sliced (useful for Clutter-GST and for the
texture-from-pixmap actors) and provide a reasonable value for
enabling the slicing ourself. At some point, we might even
provide a way to change the default at compile time or at run time,
for particular platforms.
Since max_waste is gone, the :tile-waste property of ClutterTexture
becomes read-only, and it proxies the cogl_texture_get_max_waste()
function.
Inside Clutter, the only cases where the max_waste argument was
not set to -1 are in the Pango glyph cache (which is a POT texture
anyway) and inside the test cases where we want to force slicing;
for the latter we can create larger textures that will be bigger than
the threshold we set.
Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
Signed-off-by: Robert Bragg <robert@linux.intel.com>
Signed-off-by: Neil Roberts <neil@linux.intel.com>
2009-05-23 18:18:18 +00:00
|
|
|
COGL_TEXTURE_NO_SLICING,
|
2009-02-23 16:33:42 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
2009-02-06 16:10:28 +00:00
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
2009-02-23 16:33:42 +00:00
|
|
|
0, /* auto calc row stride */
|
|
|
|
tex_data);
|
2009-02-06 16:10:28 +00:00
|
|
|
|
|
|
|
state.material = cogl_material_new ();
|
|
|
|
cogl_material_set_color4ub (state.material, 0x00, 0xff, 0x00, 0xff);
|
|
|
|
cogl_material_set_layer (state.material, 0, state.texture);
|
|
|
|
|
2008-11-10 18:53:14 +00:00
|
|
|
{
|
|
|
|
GLfloat triangle_verts[3][2] =
|
|
|
|
{
|
|
|
|
{0.0, 0.0},
|
|
|
|
{100.0, 100.0},
|
|
|
|
{0.0, 100.0}
|
|
|
|
};
|
|
|
|
GLbyte triangle_colors[3][4] =
|
|
|
|
{
|
|
|
|
{0x00, 0x00, 0xff, 0xff}, /* blue */
|
|
|
|
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
|
|
|
|
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
|
|
|
|
};
|
2009-02-06 16:10:28 +00:00
|
|
|
GLfloat triangle_tex_coords[3][2] =
|
|
|
|
{
|
|
|
|
{0.0, 0.0},
|
|
|
|
{1.0, 1.0},
|
|
|
|
{0.0, 1.0}
|
|
|
|
};
|
2009-01-20 21:12:44 +00:00
|
|
|
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
|
|
|
|
cogl_vertex_buffer_add (state.buffer,
|
|
|
|
"gl_Vertex",
|
|
|
|
2, /* n components */
|
|
|
|
GL_FLOAT,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
triangle_verts);
|
|
|
|
cogl_vertex_buffer_add (state.buffer,
|
|
|
|
"gl_Color::blue",
|
|
|
|
4, /* n components */
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
triangle_colors);
|
2009-02-06 16:10:28 +00:00
|
|
|
cogl_vertex_buffer_add (state.buffer,
|
|
|
|
"gl_MultiTexCoord0",
|
|
|
|
2, /* n components */
|
|
|
|
GL_FLOAT,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
triangle_tex_coords);
|
|
|
|
|
2009-01-20 21:12:44 +00:00
|
|
|
cogl_vertex_buffer_submit (state.buffer);
|
2008-11-10 18:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2009-04-01 16:16:44 +00:00
|
|
|
cogl_handle_unref (state.buffer);
|
|
|
|
cogl_handle_unref (state.material);
|
|
|
|
cogl_handle_unref (state.texture);
|
2008-11-10 18:53:14 +00:00
|
|
|
|
2008-11-28 16:25:20 +00:00
|
|
|
g_source_remove (idle_source);
|
|
|
|
|
2008-11-18 12:54:34 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("OK\n");
|
2008-11-10 18:53:14 +00:00
|
|
|
}
|
|
|
|
|