2011-05-05 22:34:38 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-10-28 18:10:01 +00:00
|
|
|
#include "test-utils.h"
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
#define SOURCE_SIZE 32
|
|
|
|
#define SOURCE_DIVISIONS_X 2
|
|
|
|
#define SOURCE_DIVISIONS_Y 2
|
|
|
|
#define DIVISION_WIDTH (SOURCE_SIZE / SOURCE_DIVISIONS_X)
|
|
|
|
#define DIVISION_HEIGHT (SOURCE_SIZE / SOURCE_DIVISIONS_Y)
|
|
|
|
|
|
|
|
#define TEST_INSET 1
|
|
|
|
|
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
|
|
|
static const uint32_t
|
2011-05-05 22:34:38 +00:00
|
|
|
corner_colors[SOURCE_DIVISIONS_X * SOURCE_DIVISIONS_Y] =
|
|
|
|
{
|
2011-10-28 18:10:01 +00:00
|
|
|
0xff0000ff, /* red top left */
|
|
|
|
0x00ff00ff, /* green top right */
|
|
|
|
0x0000ffff, /* blue bottom left */
|
|
|
|
0xff00ffff /* purple bottom right */
|
2011-05-05 22:34:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2011-10-28 18:10:01 +00:00
|
|
|
CoglTexture2D *tex;
|
2011-05-05 22:34:38 +00:00
|
|
|
} TestState;
|
|
|
|
|
2011-10-28 18:10:01 +00:00
|
|
|
static CoglTexture2D *
|
|
|
|
create_source (TestState *state)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
int dx, dy;
|
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 *data = g_malloc (SOURCE_SIZE * SOURCE_SIZE * 4);
|
2011-10-28 18:10:01 +00:00
|
|
|
CoglTexture2D *tex;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Create a texture with a different coloured rectangle at each
|
|
|
|
corner */
|
|
|
|
for (dy = 0; dy < SOURCE_DIVISIONS_Y; dy++)
|
|
|
|
for (dx = 0; dx < SOURCE_DIVISIONS_X; dx++)
|
|
|
|
{
|
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 *p = (data + dy * DIVISION_HEIGHT * SOURCE_SIZE * 4 +
|
2011-05-05 22:34:38 +00:00
|
|
|
dx * DIVISION_WIDTH * 4);
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < DIVISION_HEIGHT; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < DIVISION_WIDTH; x++)
|
|
|
|
{
|
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
|
|
|
uint32_t color = GUINT32_FROM_BE (corner_colors[dx + dy * SOURCE_DIVISIONS_X]);
|
2011-10-28 18:10:01 +00:00
|
|
|
memcpy (p, &color, 4);
|
2011-05-05 22:34:38 +00:00
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
p += SOURCE_SIZE * 4 - DIVISION_WIDTH * 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
tex = cogl_texture_2d_new_from_data (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
SOURCE_SIZE, SOURCE_SIZE,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
SOURCE_SIZE * 4,
|
|
|
|
data,
|
2012-08-31 18:28:27 +00:00
|
|
|
NULL);
|
2011-10-28 18:10:01 +00:00
|
|
|
return tex;
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 18:10:01 +00:00
|
|
|
static CoglTexture2D *
|
|
|
|
create_test_texture (TestState *state)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-28 18:10:01 +00:00
|
|
|
CoglTexture2D *tex;
|
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 *data = g_malloc (256 * 256 * 4), *p = data;
|
2011-05-05 22:34:38 +00:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Create a texture that is 256x256 where the red component ranges
|
|
|
|
from 0->255 along the x axis and the green component ranges from
|
|
|
|
0->255 along the y axis. The blue and alpha components are all
|
|
|
|
255 */
|
|
|
|
for (y = 0; y < 256; y++)
|
|
|
|
for (x = 0; x < 256; x++)
|
|
|
|
{
|
|
|
|
*(p++) = x;
|
|
|
|
*(p++) = y;
|
|
|
|
*(p++) = 255;
|
|
|
|
*(p++) = 255;
|
|
|
|
}
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
tex = cogl_texture_2d_new_from_data (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
256, 256,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
256 * 4,
|
|
|
|
data,
|
2012-08-31 18:28:27 +00:00
|
|
|
NULL);
|
2011-05-05 22:34:38 +00:00
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-28 18:10:01 +00:00
|
|
|
paint (TestState *state)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-28 18:10:01 +00:00
|
|
|
CoglTexture2D *full_texture;
|
|
|
|
CoglSubTexture *sub_texture, *sub_sub_texture;
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglPipeline *pipeline = cogl_pipeline_new (ctx);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Create a sub texture of the bottom right quarter of the texture */
|
2012-03-16 19:54:13 +00:00
|
|
|
sub_texture = cogl_sub_texture_new (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
COGL_TEXTURE (state->tex),
|
|
|
|
DIVISION_WIDTH,
|
|
|
|
DIVISION_HEIGHT,
|
|
|
|
DIVISION_WIDTH,
|
|
|
|
DIVISION_HEIGHT);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Paint it */
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (sub_texture));
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_object_unref (sub_texture);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_draw_rectangle (fb, pipeline,
|
|
|
|
0.0f, 0.0f, DIVISION_WIDTH, DIVISION_HEIGHT);
|
|
|
|
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Repeat a sub texture of the top half of the full texture. This is
|
|
|
|
documented to be undefined so it doesn't technically have to work
|
|
|
|
but it will with the current implementation */
|
2012-03-16 19:54:13 +00:00
|
|
|
sub_texture = cogl_sub_texture_new (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
COGL_TEXTURE (state->tex),
|
|
|
|
0, 0,
|
|
|
|
SOURCE_SIZE,
|
|
|
|
DIVISION_HEIGHT);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (sub_texture));
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_object_unref (sub_texture);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (fb, pipeline,
|
|
|
|
0.0f,
|
|
|
|
SOURCE_SIZE,
|
|
|
|
SOURCE_SIZE * 2.0f,
|
|
|
|
SOURCE_SIZE * 1.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
2.0f, 1.0f);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Create a sub texture of a sub texture */
|
2011-10-28 18:10:01 +00:00
|
|
|
full_texture = create_test_texture (state);
|
2012-03-16 19:54:13 +00:00
|
|
|
sub_texture = cogl_sub_texture_new (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
COGL_TEXTURE (full_texture),
|
|
|
|
20, 10, 30, 20);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_unref (full_texture);
|
|
|
|
sub_sub_texture = cogl_sub_texture_new (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
COGL_TEXTURE (sub_texture),
|
|
|
|
20, 10, 10, 10);
|
|
|
|
cogl_object_unref (sub_texture);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (sub_sub_texture));
|
|
|
|
cogl_object_unref (sub_sub_texture);
|
|
|
|
cogl_framebuffer_draw_rectangle (fb, pipeline,
|
|
|
|
0.0f, SOURCE_SIZE * 2.0f,
|
|
|
|
10.0f, SOURCE_SIZE * 2.0f + 10.0f);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 18:10:01 +00:00
|
|
|
static void
|
|
|
|
validate_part (int xpos, int ypos,
|
2011-05-05 22:34:38 +00:00
|
|
|
int width, int height,
|
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
|
|
|
uint32_t color)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_check_region (fb,
|
|
|
|
xpos + TEST_INSET,
|
2011-10-28 18:10:01 +00:00
|
|
|
ypos + TEST_INSET,
|
|
|
|
width - TEST_INSET - 2,
|
|
|
|
height - TEST_INSET - 2,
|
|
|
|
color);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static uint8_t *
|
2011-05-05 22:34:38 +00:00
|
|
|
create_update_data (void)
|
|
|
|
{
|
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 *data = g_malloc (256 * 256 * 4), *p = data;
|
2011-05-05 22:34:38 +00:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Create some image data that is 256x256 where the blue component
|
|
|
|
ranges from 0->255 along the x axis and the alpha component
|
|
|
|
ranges from 0->255 along the y axis. The red and green components
|
|
|
|
are all zero */
|
|
|
|
for (y = 0; y < 256; y++)
|
|
|
|
for (x = 0; x < 256; x++)
|
|
|
|
{
|
|
|
|
*(p++) = 0;
|
|
|
|
*(p++) = 0;
|
|
|
|
*(p++) = x;
|
|
|
|
*(p++) = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
validate_result (TestState *state)
|
|
|
|
{
|
|
|
|
int i, division_num, x, y;
|
2011-10-28 18:10:01 +00:00
|
|
|
CoglTexture2D *test_tex;
|
|
|
|
CoglSubTexture *sub_texture;
|
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 *texture_data, *p;
|
2011-05-05 22:34:38 +00:00
|
|
|
int tex_width, tex_height;
|
|
|
|
|
|
|
|
/* Sub texture of the bottom right corner of the texture */
|
2011-10-28 18:10:01 +00:00
|
|
|
validate_part (0, 0, DIVISION_WIDTH, DIVISION_HEIGHT,
|
|
|
|
corner_colors[
|
|
|
|
(SOURCE_DIVISIONS_Y - 1) * SOURCE_DIVISIONS_X +
|
|
|
|
SOURCE_DIVISIONS_X - 1]);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Sub texture of the top half repeated horizontally */
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
for (division_num = 0; division_num < SOURCE_DIVISIONS_X; division_num++)
|
2011-10-28 18:10:01 +00:00
|
|
|
validate_part (i * SOURCE_SIZE + division_num * DIVISION_WIDTH,
|
|
|
|
SOURCE_SIZE,
|
|
|
|
DIVISION_WIDTH, DIVISION_HEIGHT,
|
|
|
|
corner_colors[division_num]);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Sub sub texture */
|
2011-10-28 18:10:01 +00:00
|
|
|
p = texture_data = g_malloc (10 * 10 * 4);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_flush ();
|
|
|
|
cogl_framebuffer_read_pixels (fb,
|
|
|
|
0, SOURCE_SIZE * 2, 10, 10,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
p);
|
2011-05-05 22:34:38 +00:00
|
|
|
for (y = 0; y < 10; y++)
|
|
|
|
for (x = 0; x < 10; x++)
|
|
|
|
{
|
|
|
|
g_assert (*(p++) == x + 40);
|
|
|
|
g_assert (*(p++) == y + 20);
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
g_free (texture_data);
|
|
|
|
|
|
|
|
/* Try reading back the texture data */
|
2012-03-16 19:54:13 +00:00
|
|
|
sub_texture = cogl_sub_texture_new (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
COGL_TEXTURE (state->tex),
|
|
|
|
SOURCE_SIZE / 4,
|
|
|
|
SOURCE_SIZE / 4,
|
|
|
|
SOURCE_SIZE / 2,
|
|
|
|
SOURCE_SIZE / 2);
|
|
|
|
tex_width = cogl_texture_get_width (COGL_TEXTURE (sub_texture));
|
|
|
|
tex_height = cogl_texture_get_height (COGL_TEXTURE (sub_texture));
|
2011-05-05 22:34:38 +00:00
|
|
|
p = texture_data = g_malloc (tex_width * tex_height * 4);
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_texture_get_data (COGL_TEXTURE (sub_texture),
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
2011-05-05 22:34:38 +00:00
|
|
|
tex_width * 4,
|
|
|
|
texture_data);
|
|
|
|
for (y = 0; y < tex_height; y++)
|
|
|
|
for (x = 0; x < tex_width; x++)
|
|
|
|
{
|
|
|
|
int div_x = ((x * SOURCE_SIZE / 2 / tex_width + SOURCE_SIZE / 4) /
|
|
|
|
DIVISION_WIDTH);
|
|
|
|
int div_y = ((y * SOURCE_SIZE / 2 / tex_height + SOURCE_SIZE / 4) /
|
|
|
|
DIVISION_HEIGHT);
|
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
|
|
|
uint32_t reference = corner_colors[div_x + div_y * SOURCE_DIVISIONS_X] >> 8;
|
|
|
|
uint32_t color = GUINT32_FROM_BE (*((uint32_t *)p)) >> 8;
|
2011-10-28 18:10:01 +00:00
|
|
|
g_assert (color == reference);
|
2011-05-05 22:34:38 +00:00
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
g_free (texture_data);
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_object_unref (sub_texture);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Create a 256x256 test texture */
|
2011-10-28 18:10:01 +00:00
|
|
|
test_tex = create_test_texture (state);
|
2011-05-05 22:34:38 +00:00
|
|
|
/* Create a sub texture the views the center half of the texture */
|
2012-03-16 19:54:13 +00:00
|
|
|
sub_texture = cogl_sub_texture_new (ctx,
|
2011-10-28 18:10:01 +00:00
|
|
|
COGL_TEXTURE (test_tex),
|
|
|
|
64, 64, 128, 128);
|
2011-05-05 22:34:38 +00:00
|
|
|
/* Update the center half of the sub texture */
|
|
|
|
texture_data = create_update_data ();
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_texture_set_region (COGL_TEXTURE (sub_texture),
|
|
|
|
0, 0, 32, 32, 64, 64, 256, 256,
|
2011-05-05 22:34:38 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE, 256 * 4,
|
|
|
|
texture_data);
|
|
|
|
g_free (texture_data);
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_object_unref (sub_texture);
|
2011-05-05 22:34:38 +00:00
|
|
|
/* Get the texture data */
|
|
|
|
p = texture_data = g_malloc (256 * 256 * 4);
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_texture_get_data (COGL_TEXTURE (test_tex),
|
2012-02-23 18:07:55 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2011-05-05 22:34:38 +00:00
|
|
|
256 * 4, texture_data);
|
|
|
|
|
|
|
|
/* Verify the texture data */
|
|
|
|
for (y = 0; y < 256; y++)
|
|
|
|
for (x = 0; x < 256; x++)
|
|
|
|
{
|
|
|
|
/* If we're in the center quarter */
|
|
|
|
if (x >= 96 && x < 160 && y >= 96 && y < 160)
|
|
|
|
{
|
|
|
|
g_assert ((*p++) == 0);
|
|
|
|
g_assert ((*p++) == 0);
|
|
|
|
g_assert ((*p++) == x - 96);
|
|
|
|
g_assert ((*p++) == y - 96);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert ((*p++) == x);
|
|
|
|
g_assert ((*p++) == y);
|
|
|
|
g_assert ((*p++) == 255);
|
|
|
|
g_assert ((*p++) == 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (texture_data);
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_object_unref (test_tex);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_sub_texture (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
|
2011-10-28 18:10:01 +00:00
|
|
|
state.tex = create_source (&state);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_framebuffer_orthographic (fb,
|
|
|
|
0, 0,
|
|
|
|
cogl_framebuffer_get_width (fb),
|
|
|
|
cogl_framebuffer_get_height (fb),
|
|
|
|
-1,
|
|
|
|
100);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-28 18:10:01 +00:00
|
|
|
paint (&state);
|
|
|
|
validate_result (&state);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-28 18:10:01 +00:00
|
|
|
cogl_object_unref (state.tex);
|
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");
|
|
|
|
}
|
|
|
|
|