2008-06-06 14:56:08 +00:00
|
|
|
#include <stdlib.h>
|
2008-11-07 19:32:28 +00:00
|
|
|
#include <gmodule.h>
|
2008-06-06 14:56:08 +00:00
|
|
|
|
2007-05-04 23:53:49 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2008-06-10 06:37:46 +00:00
|
|
|
guchar*
|
|
|
|
make_rgba_data (int width, int height, int bpp, int has_alpha, int *rowstride_p)
|
2007-05-04 23:53:49 +00:00
|
|
|
{
|
|
|
|
#define CHECK_SIZE 20
|
|
|
|
|
2008-06-13 15:01:34 +00:00
|
|
|
gint x,y, rowstride, i = 0;
|
2008-06-10 06:37:46 +00:00
|
|
|
guchar *pixels;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2008-06-10 06:37:46 +00:00
|
|
|
g_assert(bpp == 4);
|
|
|
|
g_assert(has_alpha == TRUE);
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2008-06-10 06:37:46 +00:00
|
|
|
rowstride = width * bpp;
|
|
|
|
*rowstride_p = rowstride;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2008-06-10 06:37:46 +00:00
|
|
|
pixels = g_try_malloc (height * rowstride);
|
|
|
|
if (!pixels)
|
|
|
|
return NULL;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
for (y = 0; y < height; y++)
|
2007-05-04 23:53:49 +00:00
|
|
|
{
|
|
|
|
i = 0;
|
2007-07-26 11:04:04 +00:00
|
|
|
for (x = 0; x < width; x++)
|
2007-05-04 23:53:49 +00:00
|
|
|
{
|
2007-07-26 11:04:04 +00:00
|
|
|
guchar *p;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2008-06-10 06:37:46 +00:00
|
|
|
p = pixels + y * rowstride + x * bpp;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
|
|
|
p[0] = p[1] = p[2] = 0; p[3] = 0xff;
|
|
|
|
|
|
|
|
if (x && y && y % CHECK_SIZE && x % CHECK_SIZE)
|
|
|
|
{
|
|
|
|
if (x % CHECK_SIZE == 1)
|
|
|
|
{
|
|
|
|
if (++i > 3)
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
p[i] = 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-10 06:37:46 +00:00
|
|
|
return pixels;
|
2007-05-04 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2011-11-09 13:41:15 +00:00
|
|
|
static void
|
|
|
|
exit_on_destroy (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2007-05-04 23:53:49 +00:00
|
|
|
#define SPIN() while (g_main_context_pending (NULL)) \
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_textures_main (int argc, char *argv[])
|
2007-05-04 23:53:49 +00:00
|
|
|
{
|
|
|
|
ClutterActor *texture;
|
|
|
|
ClutterActor *stage;
|
2008-04-25 13:37:36 +00:00
|
|
|
gint i, j;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2011-02-22 00:19:35 +00:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2011-11-09 13:41:15 +00:00
|
|
|
stage = clutter_stage_new ();
|
2007-05-04 23:53:49 +00:00
|
|
|
clutter_actor_show_all (CLUTTER_ACTOR (stage));
|
2011-11-09 13:41:15 +00:00
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (exit_on_destroy), NULL);
|
2007-05-04 23:53:49 +00:00
|
|
|
|
|
|
|
SPIN();
|
|
|
|
|
2008-06-10 06:37:46 +00:00
|
|
|
for (i=100; i<=5000; i += 100)
|
2007-05-09 23:31:08 +00:00
|
|
|
for (j=0; j<4; j++)
|
|
|
|
{
|
2008-06-14 22:07:23 +00:00
|
|
|
const int width = i+j;
|
|
|
|
const int height = i+j;
|
2008-06-10 06:37:46 +00:00
|
|
|
const gboolean has_alpha = TRUE;
|
|
|
|
const int bpp = has_alpha ? 4 : 3;
|
2008-06-14 22:07:23 +00:00
|
|
|
int rowstride;
|
|
|
|
guchar *pixels;
|
2008-06-10 06:37:46 +00:00
|
|
|
|
2008-06-14 22:07:23 +00:00
|
|
|
pixels = make_rgba_data (width, height, bpp, has_alpha, &rowstride);
|
2008-06-10 06:37:46 +00:00
|
|
|
if (!pixels)
|
|
|
|
g_error("No memory for %ix%i RGBA data failed", width, height);
|
|
|
|
|
|
|
|
printf("o %ix%i texture... ", width, height);
|
2008-06-14 22:07:23 +00:00
|
|
|
|
|
|
|
texture = clutter_texture_new ();
|
2008-06-10 06:37:46 +00:00
|
|
|
if (!clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture),
|
|
|
|
pixels,
|
|
|
|
has_alpha,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
rowstride,
|
|
|
|
bpp,
|
|
|
|
0, NULL))
|
|
|
|
g_error("texture creation failed");
|
2008-06-14 22:07:23 +00:00
|
|
|
g_free(pixels);
|
2007-05-09 23:31:08 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
printf("uploaded to texture...\n");
|
2007-05-09 23:31:08 +00:00
|
|
|
|
2008-06-14 22:07:23 +00:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (stage), texture, NULL);
|
|
|
|
clutter_actor_set_size (texture, 400, 400);
|
|
|
|
clutter_actor_show (texture);
|
2007-07-29 22:55:04 +00:00
|
|
|
|
|
|
|
/* Hide & show to unreaise then realise the texture */
|
|
|
|
clutter_actor_hide (texture);
|
|
|
|
clutter_actor_show (texture);
|
|
|
|
|
2007-05-09 23:31:08 +00:00
|
|
|
SPIN();
|
2007-05-04 23:53:49 +00:00
|
|
|
|
2008-06-14 22:07:23 +00:00
|
|
|
clutter_container_remove (CLUTTER_CONTAINER (stage), texture, NULL);
|
2007-05-04 23:53:49 +00:00
|
|
|
}
|
2008-06-06 14:56:08 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2007-05-04 23:53:49 +00:00
|
|
|
}
|
2011-09-28 12:32:57 +00:00
|
|
|
|
|
|
|
G_MODULE_EXPORT const char *
|
|
|
|
test_texture_slicing_describe (void)
|
|
|
|
{
|
|
|
|
return "Check texture slicing support in CoglTexture";
|
|
|
|
}
|