2011-05-05 22:34:38 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <cogl/cogl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
|
|
|
static const ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
|
|
|
|
|
|
|
|
#define TEX_SIZE 64
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
unsigned int padding;
|
|
|
|
} TestState;
|
|
|
|
|
|
|
|
/* Creates a texture where the pixels are evenly divided between
|
|
|
|
selecting just one of the R,G and B components */
|
|
|
|
static CoglHandle
|
|
|
|
make_texture (void)
|
|
|
|
{
|
|
|
|
guchar *tex_data = g_malloc (TEX_SIZE * TEX_SIZE * 3), *p = tex_data;
|
|
|
|
CoglHandle tex;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < TEX_SIZE; y++)
|
|
|
|
for (x = 0; x < TEX_SIZE; x++)
|
|
|
|
{
|
|
|
|
memset (p, 0, 3);
|
|
|
|
/* Set one of the components to full. The components should be
|
|
|
|
evenly represented so that each gets a third of the
|
|
|
|
texture */
|
|
|
|
p[(p - tex_data) / (TEX_SIZE * TEX_SIZE * 3 / 3)] = 255;
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
|
2013-06-09 00:09:04 +00:00
|
|
|
tex = test_utils_texture_new_from_data (TEX_SIZE, TEX_SIZE, TEST_UTILS_TEXTURE_NONE,
|
2011-05-05 22:34:38 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGB_888,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
TEX_SIZE * 3,
|
|
|
|
tex_data);
|
|
|
|
|
|
|
|
g_free (tex_data);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-13 21:21:58 +00:00
|
|
|
on_paint (ClutterActor *actor,
|
|
|
|
ClutterPaintContext *paint_context,
|
|
|
|
TestState *state)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
CoglHandle tex;
|
|
|
|
CoglHandle material;
|
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 pixels[8];
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
tex = make_texture ();
|
|
|
|
material = cogl_material_new ();
|
|
|
|
cogl_material_set_layer (material, 0, tex);
|
2019-02-20 13:51:12 +00:00
|
|
|
cogl_object_unref (tex);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Render a 1x1 pixel quad without mipmaps */
|
|
|
|
cogl_set_source (material);
|
|
|
|
cogl_material_set_layer_filters (material, 0,
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST,
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST);
|
|
|
|
cogl_rectangle (0, 0, 1, 1);
|
|
|
|
/* Then with mipmaps */
|
|
|
|
cogl_material_set_layer_filters (material, 0,
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST_MIPMAP_NEAREST,
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST);
|
|
|
|
cogl_rectangle (1, 0, 2, 1);
|
|
|
|
|
2019-02-20 13:51:12 +00:00
|
|
|
cogl_object_unref (material);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Read back the two pixels we rendered */
|
|
|
|
cogl_read_pixels (0, 0, 2, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
pixels);
|
|
|
|
|
|
|
|
/* The first pixel should be just one of the colors from the
|
|
|
|
texture. It doesn't matter which one */
|
|
|
|
g_assert ((pixels[0] == 255 && pixels[1] == 0 && pixels[2] == 0) ||
|
|
|
|
(pixels[0] == 0 && pixels[1] == 255 && pixels[2] == 0) ||
|
|
|
|
(pixels[0] == 0 && pixels[1] == 0 && pixels[2] == 255));
|
|
|
|
/* The second pixel should be more or less the average of all of the
|
|
|
|
pixels in the texture. Each component gets a third of the image
|
|
|
|
so each component should be approximately 255/3 */
|
|
|
|
g_assert (ABS (pixels[4] - 255 / 3) <= 3 &&
|
|
|
|
ABS (pixels[5] - 255 / 3) <= 3 &&
|
|
|
|
ABS (pixels[6] - 255 / 3) <= 3);
|
|
|
|
|
|
|
|
/* Comment this out if you want visual feedback for what this test paints */
|
|
|
|
#if 1
|
2020-07-09 19:28:57 +00:00
|
|
|
clutter_test_quit ();
|
2011-05-05 22:34:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
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
|
|
|
queue_redraw (void *stage)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_texture_mipmaps (TestUtilsGTestFixture *fixture,
|
2011-05-05 22:34:38 +00:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *group;
|
|
|
|
unsigned int idle_source;
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
|
2020-06-26 19:43:45 +00:00
|
|
|
clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &stage_color);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2020-06-26 19:26:49 +00:00
|
|
|
group = clutter_actor_new ();
|
2011-05-05 22:34:38 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
|
|
|
|
|
|
|
|
/* We force continuous redrawing of the stage, since we need to skip
|
|
|
|
* the first few frames, and we wont be doing anything else that
|
|
|
|
* will trigger redrawing. */
|
|
|
|
idle_source = g_idle_add (queue_redraw, stage);
|
|
|
|
|
|
|
|
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
|
|
|
|
2020-06-26 18:23:46 +00:00
|
|
|
clutter_actor_show (stage);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2020-07-09 19:28:57 +00:00
|
|
|
clutter_test_main ();
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2019-11-21 23:25:30 +00:00
|
|
|
g_clear_handle_id (&idle_source, g_source_remove);
|
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");
|
|
|
|
}
|