From 3907825d059407362023f7409a7c0e8992244ac3 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 26 Apr 2010 16:27:59 +0100 Subject: [PATCH] test-cogl-texture-rectangle: save restore GL state correctly This test breaks out into raw OpenGL to create a RECTANGLE texture so it needs to be careful not to trample on any state that may be cached by Cogl internally. --- tests/conform/test-cogl-texture-rectangle.c | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/conform/test-cogl-texture-rectangle.c b/tests/conform/test-cogl-texture-rectangle.c index f8a03baf0..3822c710a 100644 --- a/tests/conform/test-cogl-texture-rectangle.c +++ b/tests/conform/test-cogl-texture-rectangle.c @@ -17,6 +17,11 @@ create_source_rect (void) #ifdef GL_TEXTURE_RECTANGLE_ARB int x, y; + GLint prev_unpack_row_length; + GLint prev_unpack_alignment; + GLint prev_unpack_skip_rows; + GLint prev_unpack_skip_pixles; + GLint prev_rectangle_binding; guint8 *data = g_malloc (256 * 256 * 4), *p = data; CoglHandle tex; GLuint gl_tex; @@ -30,6 +35,17 @@ create_source_rect (void) *(p++) = 255; } + /* We are about to use OpenGL directly to create a TEXTURE_RECTANGLE + * texture so we need to save the state that we modify so we can + * restore it afterwards and be sure not to interfere with any state + * caching that Cogl may do internally. + */ + glGetIntegerv (GL_UNPACK_ROW_LENGTH, &prev_unpack_row_length); + glGetIntegerv (GL_UNPACK_ALIGNMENT, &prev_unpack_alignment); + glGetIntegerv (GL_UNPACK_SKIP_ROWS, &prev_unpack_skip_rows); + glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &prev_unpack_skip_pixles); + glGetIntegerv (GL_TEXTURE_BINDING_RECTANGLE_ARB, &prev_rectangle_binding); + glPixelStorei (GL_UNPACK_ROW_LENGTH, 256); glPixelStorei (GL_UNPACK_ALIGNMENT, 8); glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); @@ -43,6 +59,13 @@ create_source_rect (void) GL_UNSIGNED_BYTE, data); + /* Now restore the original GL state as Cogl had left it */ + glPixelStorei (GL_UNPACK_ROW_LENGTH, prev_unpack_row_length); + glPixelStorei (GL_UNPACK_ALIGNMENT, prev_unpack_alignment); + glPixelStorei (GL_UNPACK_SKIP_ROWS, prev_unpack_skip_rows); + glPixelStorei (GL_UNPACK_SKIP_PIXELS, prev_unpack_skip_pixles); + glBindTexture (GL_TEXTURE_RECTANGLE_ARB, prev_rectangle_binding); + g_assert (glGetError () == GL_NO_ERROR); g_free (data);