2011-05-05 18:34:38 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
2012-11-09 11:28:53 -05:00
|
|
|
#include <string.h>
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2019-01-20 05:41:48 -05:00
|
|
|
#include "test-declarations.h"
|
2012-11-09 11:28:53 -05:00
|
|
|
#include "test-utils.h"
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
/* Non-power-of-two sized texture that should cause slicing */
|
|
|
|
#define TEXTURE_SIZE 384
|
|
|
|
/* Number of times to split the texture up on each axis */
|
|
|
|
#define PARTS 2
|
|
|
|
/* The texture is split into four parts, each with a different colour */
|
|
|
|
#define PART_SIZE (TEXTURE_SIZE / PARTS)
|
|
|
|
|
|
|
|
/* Amount of pixels to skip off the top, bottom, left and right of the
|
|
|
|
texture when reading back the stage */
|
|
|
|
#define TEST_INSET 4
|
|
|
|
|
|
|
|
/* Size to actually render the texture at */
|
|
|
|
#define TEXTURE_RENDER_SIZE TEXTURE_SIZE
|
|
|
|
/* The size of a part once rendered */
|
|
|
|
#define PART_RENDER_SIZE (TEXTURE_RENDER_SIZE / PARTS)
|
|
|
|
|
2012-11-09 11:28:53 -05:00
|
|
|
static const uint32_t corner_colors[PARTS * PARTS] =
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2012-11-09 11:28:53 -05:00
|
|
|
/* Top left - red */ 0xff0000ff,
|
|
|
|
/* Top right - green */ 0x00ff00ff,
|
|
|
|
/* Bottom left - blue */ 0x0000ffff,
|
|
|
|
/* Bottom right - yellow */ 0xffff00ff
|
2011-05-05 18:34:38 -04:00
|
|
|
};
|
|
|
|
|
2012-11-09 11:28:53 -05:00
|
|
|
static void
|
|
|
|
validate_part (int xnum,
|
|
|
|
int ynum,
|
|
|
|
uint32_t color)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_region (test_fb,
|
2012-11-09 11:28:53 -05:00
|
|
|
xnum * PART_RENDER_SIZE + TEST_INSET,
|
|
|
|
ynum * PART_RENDER_SIZE + TEST_INSET,
|
|
|
|
PART_RENDER_SIZE - TEST_INSET * 2,
|
|
|
|
PART_RENDER_SIZE - TEST_INSET * 2,
|
|
|
|
color);
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-09 11:28:53 -05:00
|
|
|
validate_result (void)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
|
|
|
/* Validate that all four corners of the texture are drawn in the
|
|
|
|
right color */
|
2012-11-09 11:28:53 -05:00
|
|
|
validate_part (0, 0, corner_colors[0]);
|
|
|
|
validate_part (1, 0, corner_colors[1]);
|
|
|
|
validate_part (0, 1, corner_colors[2]);
|
|
|
|
validate_part (1, 1, corner_colors[3]);
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
2012-11-09 11:28:53 -05:00
|
|
|
static CoglTexture *
|
2011-05-05 18:34:38 -04:00
|
|
|
make_texture (void)
|
|
|
|
{
|
2012-11-09 11:28:53 -05:00
|
|
|
void *tex_data;
|
|
|
|
uint32_t *p;
|
|
|
|
CoglTexture *tex;
|
2011-05-05 18:34:38 -04:00
|
|
|
int partx, party, width, height;
|
|
|
|
|
|
|
|
p = tex_data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);
|
|
|
|
|
|
|
|
/* Make a texture with a different color for each part */
|
|
|
|
for (party = 0; party < PARTS; party++)
|
|
|
|
{
|
|
|
|
height = (party < PARTS - 1
|
|
|
|
? PART_SIZE
|
|
|
|
: TEXTURE_SIZE - PART_SIZE * (PARTS - 1));
|
|
|
|
|
|
|
|
for (partx = 0; partx < PARTS; partx++)
|
|
|
|
{
|
2012-11-09 11:28:53 -05:00
|
|
|
uint32_t color = corner_colors[party * PARTS + partx];
|
2011-05-05 18:34:38 -04:00
|
|
|
width = (partx < PARTS - 1
|
|
|
|
? PART_SIZE
|
|
|
|
: TEXTURE_SIZE - PART_SIZE * (PARTS - 1));
|
|
|
|
|
|
|
|
while (width-- > 0)
|
2012-11-09 11:28:53 -05:00
|
|
|
*(p++) = GUINT32_TO_BE (color);
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (--height > 0)
|
|
|
|
{
|
2012-11-09 11:28:53 -05:00
|
|
|
memcpy (p, p - TEXTURE_SIZE, TEXTURE_SIZE * 4);
|
|
|
|
p += TEXTURE_SIZE;
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 20:09:04 -04:00
|
|
|
tex = test_utils_texture_new_from_data (test_ctx,
|
|
|
|
TEXTURE_SIZE,
|
|
|
|
TEXTURE_SIZE,
|
|
|
|
TEST_UTILS_TEXTURE_NO_ATLAS,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
TEXTURE_SIZE * 4,
|
|
|
|
tex_data);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
g_free (tex_data);
|
|
|
|
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
|
|
|
if (cogl_texture_is_sliced (tex))
|
|
|
|
g_print ("Texture is sliced\n");
|
|
|
|
else
|
|
|
|
g_print ("Texture is not sliced\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The texture should be sliced unless NPOTs are supported */
|
2013-01-18 12:57:06 -05:00
|
|
|
g_assert (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT)
|
2011-05-05 18:34:38 -04:00
|
|
|
? !cogl_texture_is_sliced (tex)
|
|
|
|
: cogl_texture_is_sliced (tex));
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2012-11-09 11:28:53 -05:00
|
|
|
static void
|
|
|
|
paint (void)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2013-01-18 12:57:06 -05:00
|
|
|
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
|
2012-11-09 11:28:53 -05:00
|
|
|
CoglTexture *texture = make_texture ();
|
|
|
|
int y, x;
|
|
|
|
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, texture);
|
|
|
|
|
|
|
|
/* Just render the texture in the top left corner */
|
|
|
|
/* Render the texture using four separate rectangles */
|
|
|
|
for (y = 0; y < 2; y++)
|
|
|
|
for (x = 0; x < 2; x++)
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-11-09 11:28:53 -05:00
|
|
|
pipeline,
|
|
|
|
x * TEXTURE_RENDER_SIZE / 2,
|
|
|
|
y * TEXTURE_RENDER_SIZE / 2,
|
|
|
|
(x + 1) *
|
|
|
|
TEXTURE_RENDER_SIZE / 2,
|
|
|
|
(y + 1) *
|
|
|
|
TEXTURE_RENDER_SIZE / 2,
|
|
|
|
x / 2.0f,
|
|
|
|
y / 2.0f,
|
|
|
|
(x + 1) / 2.0f,
|
|
|
|
(y + 1) / 2.0f);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
cogl_object_unref (texture);
|
|
|
|
}
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-11-09 11:28:53 -05:00
|
|
|
void
|
|
|
|
test_npot_texture (void)
|
|
|
|
{
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2013-01-18 12:57:06 -05:00
|
|
|
if (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT))
|
2011-05-05 18:34:38 -04:00
|
|
|
g_print ("NPOT textures are supported\n");
|
|
|
|
else
|
|
|
|
g_print ("NPOT textures are not supported\n");
|
|
|
|
}
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_orthographic (test_fb,
|
2012-11-09 11:28:53 -05:00
|
|
|
0, 0,
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_get_width (test_fb),
|
|
|
|
cogl_framebuffer_get_height (test_fb),
|
2012-11-09 11:28:53 -05:00
|
|
|
-1,
|
|
|
|
100);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-11-09 11:28:53 -05:00
|
|
|
paint ();
|
|
|
|
validate_result ();
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 18:34:38 -04:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|
|
|
|
|