2012-10-17 16:40:26 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
tex_data[2 * 2 * 4] =
|
|
|
|
{
|
|
|
|
0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
|
|
|
|
0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Vertex data for a quad with all of the texture coordinates set to
|
|
|
|
* the top left (red) pixel */
|
|
|
|
static CoglVertexP2T2
|
|
|
|
vertex_data[4] =
|
|
|
|
{
|
|
|
|
{ -1, -1, 0, 0 },
|
|
|
|
{ 1, -1, 0, 0 },
|
|
|
|
{ -1, 1, 0, 0 },
|
|
|
|
{ 1, 1, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_map_buffer_range (void)
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex;
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
int fb_width, fb_height;
|
|
|
|
CoglAttributeBuffer *buffer;
|
|
|
|
CoglVertexP2T2 *data;
|
|
|
|
CoglAttribute *pos_attribute;
|
|
|
|
CoglAttribute *tex_coord_attribute;
|
2013-07-09 19:39:18 -04:00
|
|
|
CoglPrimitive *primitive;
|
2012-10-17 16:40:26 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
tex = cogl_texture_2d_new_from_data (test_ctx,
|
2012-10-17 16:40:26 -04:00
|
|
|
2, 2, /* width/height */
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
2 * 4, /* rowstride */
|
|
|
|
tex_data,
|
|
|
|
NULL /* error */);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2012-10-17 16:40:26 -04:00
|
|
|
|
2013-10-09 08:31:12 -04:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
|
2012-10-17 16:40:26 -04:00
|
|
|
cogl_pipeline_set_layer_filters (pipeline,
|
|
|
|
0, /* layer */
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode (pipeline,
|
|
|
|
0, /* layer */
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
fb_width = cogl_framebuffer_get_width (test_fb);
|
|
|
|
fb_height = cogl_framebuffer_get_height (test_fb);
|
2012-10-17 16:40:26 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
buffer = cogl_attribute_buffer_new (test_ctx,
|
2012-10-17 16:40:26 -04:00
|
|
|
sizeof (vertex_data),
|
|
|
|
vertex_data);
|
|
|
|
|
|
|
|
/* Replace the texture coordinates of the third vertex with the
|
|
|
|
* coordinates for a green texel */
|
2013-10-09 08:31:12 -04:00
|
|
|
data = cogl_buffer_map_range (buffer,
|
2012-10-17 16:40:26 -04:00
|
|
|
sizeof (vertex_data[0]) * 2,
|
|
|
|
sizeof (vertex_data[0]),
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
2012-11-08 12:54:10 -05:00
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD_RANGE,
|
|
|
|
NULL); /* don't catch errors */
|
2012-10-17 16:40:26 -04:00
|
|
|
g_assert (data != NULL);
|
|
|
|
|
|
|
|
data->x = vertex_data[2].x;
|
|
|
|
data->y = vertex_data[2].y;
|
|
|
|
data->s = 1.0f;
|
|
|
|
data->t = 0.0f;
|
|
|
|
|
2013-10-09 08:31:12 -04:00
|
|
|
cogl_buffer_unmap (buffer);
|
2012-10-17 16:40:26 -04:00
|
|
|
|
|
|
|
pos_attribute =
|
|
|
|
cogl_attribute_new (buffer,
|
|
|
|
"cogl_position_in",
|
|
|
|
sizeof (vertex_data[0]),
|
|
|
|
offsetof (CoglVertexP2T2, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
|
|
|
tex_coord_attribute =
|
|
|
|
cogl_attribute_new (buffer,
|
|
|
|
"cogl_tex_coord_in",
|
|
|
|
sizeof (vertex_data[0]),
|
|
|
|
offsetof (CoglVertexP2T2, s),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_clear4f (test_fb,
|
2012-10-17 16:40:26 -04:00
|
|
|
COGL_BUFFER_BIT_COLOR,
|
|
|
|
0, 0, 0, 1);
|
|
|
|
|
2013-07-09 19:39:18 -04:00
|
|
|
primitive =
|
|
|
|
cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLE_STRIP,
|
|
|
|
4, /* n_vertices */
|
|
|
|
pos_attribute,
|
|
|
|
tex_coord_attribute,
|
|
|
|
NULL);
|
|
|
|
cogl_primitive_draw (primitive, test_fb, pipeline);
|
|
|
|
cogl_object_unref (primitive);
|
2012-10-17 16:40:26 -04:00
|
|
|
|
|
|
|
/* Top left pixel should be the one that is replaced to be green */
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 1, 1, 0x00ff00ff);
|
2012-10-17 16:40:26 -04:00
|
|
|
/* The other three corners should be left as red */
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, fb_width - 2, 1, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (test_fb, 1, fb_height - 2, 0xff0000ff);
|
|
|
|
test_utils_check_pixel (test_fb, fb_width - 2, fb_height - 2, 0xff0000ff);
|
2012-10-17 16:40:26 -04:00
|
|
|
|
|
|
|
cogl_object_unref (buffer);
|
|
|
|
cogl_object_unref (pos_attribute);
|
|
|
|
cogl_object_unref (tex_coord_attribute);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
cogl_object_unref (tex);
|
|
|
|
|
|
|
|
if (cogl_test_verbose ())
|
|
|
|
g_print ("OK\n");
|
|
|
|
}
|