mutter/tests/conform/test-conform-main.c
Neil Roberts 19ccb72b80 cogl-gles2-context: Wrap glCopyTex{Sub,}Image2D to flip the result
When the CoglGLES2Context is bound to read from a CoglOffscreen then
the result will be upside down from what GL expects if
glCopyTexImage2D is used directly. To fix that, this patch now wraps
glCopyTexImage2D and glCopyTexSubImage2D so that the copy is doing by
binding an FBO to the target texture and then rendering a quad
sampling from the texture in the offscreen framebuffer.

The rendering is done using the Cogl context rather than the GLES2
context because otherwise it would have to do a fair bit of work to
try and stash the old state on the context before setting up the state
to do the blit. The down side of this is that the contexts need to be
synchronized so that the rendering will be up-to-date. As far as I
understand from the GL spec, this requires a glFinish and then the
texture needs to be rebound in the new context because updates to
shared objects are guaranteed to be reflected until the object is
rebound.

GLES2 supports using glCopyTexImage2D for cube map textures. As Cogl
doesn't currently have support for cube maps, it is quite hard to get
that to work with this patch. For now attempts to copy to a cube map
texture will just be sliently ignored.

This patch also includes a test case which renders an image to the
framebuffer and then copies it to a texture. The texture is then
rendered back to the framebuffer and the contents are checked for the
correct orientation using glReadPixels.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 30b6da8134bad95267265e26685c7475f6c351c9)
2012-08-15 13:46:20 +01:00

115 lines
3.2 KiB
C

#include "config.h"
#include <cogl/cogl.h>
#include <glib.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include "test-utils.h"
/* A bit of sugar for adding new conformance tests */
#define ADD_TEST(FUNC, REQUIREMENTS) G_STMT_START { \
extern void FUNC (void); \
if (strcmp (#FUNC, argv[1]) == 0) \
{ \
test_utils_init (REQUIREMENTS); \
FUNC (); \
test_utils_fini (); \
exit (0); \
} \
} G_STMT_END
#define UNPORTED_TEST(FUNC)
int
main (int argc, char **argv)
{
int i;
if (argc != 2)
{
g_printerr ("usage %s UNIT_TEST\n", argv[0]);
exit (1);
}
/* Just for convenience in case people try passing the wrapper
* filenames for the UNIT_TEST argument we normalize '-' characters
* to '_' characters... */
for (i = 0; argv[1][i]; i++)
{
if (argv[1][i] == '-')
argv[1][i] = '_';
}
/* This file is run through a sed script during the make step so the
* lines containing the tests need to be formatted on a single line
* each.
*/
UNPORTED_TEST (test_object);
UNPORTED_TEST (test_fixed);
UNPORTED_TEST (test_materials);
ADD_TEST (test_pipeline_user_matrix, 0);
ADD_TEST (test_blend_strings, 0);
ADD_TEST (test_premult, 0);
UNPORTED_TEST (test_readpixels);
ADD_TEST (test_path, 0);
ADD_TEST (test_depth_test, 0);
ADD_TEST (test_color_mask, 0);
ADD_TEST (test_backface_culling, TEST_REQUIREMENT_NPOT);
ADD_TEST (test_layer_remove, 0);
ADD_TEST (test_sparse_pipeline, 0);
UNPORTED_TEST (test_npot_texture);
UNPORTED_TEST (test_multitexture);
UNPORTED_TEST (test_texture_mipmaps);
ADD_TEST (test_sub_texture, 0);
ADD_TEST (test_pixel_buffer, 0);
UNPORTED_TEST (test_texture_rectangle);
ADD_TEST (test_texture_3d, 0);
ADD_TEST (test_wrap_modes, 0);
UNPORTED_TEST (test_texture_pixmap_x11);
UNPORTED_TEST (test_texture_get_set_data);
ADD_TEST (test_atlas_migration, 0);
ADD_TEST (test_read_texture_formats, 0);
ADD_TEST (test_write_texture_formats, 0);
UNPORTED_TEST (test_vertex_buffer_contiguous);
UNPORTED_TEST (test_vertex_buffer_interleved);
UNPORTED_TEST (test_vertex_buffer_mutability);
ADD_TEST (test_primitive, 0);
ADD_TEST (test_just_vertex_shader, 0);
ADD_TEST (test_pipeline_uniforms, 0);
ADD_TEST (test_snippets, 0);
ADD_TEST (test_custom_attributes, 0);
ADD_TEST (test_bitmask, 0);
ADD_TEST (test_offscreen, 0);
ADD_TEST (test_point_size, 0);
ADD_TEST (test_point_sprite,
TEST_REQUIREMENT_POINT_SPRITE);
ADD_TEST (test_point_sprite_orientation,
TEST_KNOWN_FAILURE | TEST_REQUIREMENT_POINT_SPRITE);
ADD_TEST (test_version, 0);
UNPORTED_TEST (test_viewport);
ADD_TEST (test_gles2_context, TEST_REQUIREMENT_GLES2_CONTEXT);
ADD_TEST (test_gles2_context_fbo, TEST_REQUIREMENT_GLES2_CONTEXT);
ADD_TEST (test_gles2_context_copy_tex_image, TEST_REQUIREMENT_GLES2_CONTEXT);
ADD_TEST (test_euler_quaternion, 0);
g_printerr ("Unknown test name \"%s\"\n", argv[1]);
return 1;
}