tests: Dynamically resolve GL symbols

Some of the tests are making direct GL calls. Eventually we want
Clutter not to link directly against any GL library so that it can
leave Cogl to load it dynamically. As a step towards getting this to
work this patch changes the tests to resolve the symbols using
cogl_get_proc_address instead of linking directly.
This commit is contained in:
Neil Roberts 2011-07-13 14:10:47 +01:00
parent 5cc5e566e6
commit cbe1e8321b
5 changed files with 119 additions and 39 deletions

View File

@ -8,6 +8,8 @@
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
static TestConformGLFunctions gl_functions;
#define QUAD_WIDTH 20
#define RED 0
@ -131,7 +133,7 @@ using_gles2_driver (void)
{
/* FIXME: This should probably be replaced with some way to query
the driver from Cogl */
return g_str_has_prefix ((const char *) glGetString (GL_VERSION),
return g_str_has_prefix ((const char *) gl_functions.glGetString (GL_VERSION),
"OpenGL ES 2");
}
@ -168,10 +170,10 @@ test_using_all_layers (TestState *state, int x, int y)
GLint n_image_units, n_attribs;
/* GLES 2 doesn't have GL_MAX_TEXTURE_UNITS and it uses
GL_MAX_TEXTURE_IMAGE_UNITS instead */
glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS, &n_image_units);
gl_functions.glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS, &n_image_units);
/* Cogl needs a vertex attrib for each layer to upload the texture
coordinates */
glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, &n_attribs);
gl_functions.glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, &n_attribs);
/* We can't use two of the attribs because they are used by the
position and color */
n_attribs -= 2;
@ -181,7 +183,7 @@ test_using_all_layers (TestState *state, int x, int y)
#endif
{
#if defined(COGL_HAS_GLES1) || defined(COGL_HAS_GL)
glGetIntegerv (GL_MAX_TEXTURE_UNITS, &n_layers);
gl_functions.glGetIntegerv (GL_MAX_TEXTURE_UNITS, &n_layers);
#endif
}
@ -319,6 +321,8 @@ test_cogl_materials (TestConformSimpleFixture *fixture,
ClutterActor *group;
guint idle_source;
test_conform_get_gl_functions (&gl_functions);
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

View File

@ -5,6 +5,8 @@
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
static TestConformGLFunctions gl_functions;
typedef struct _TestState
{
ClutterActor *stage;
@ -39,33 +41,34 @@ create_source_rect (void)
* 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);
gl_functions.glGetIntegerv (GL_UNPACK_ROW_LENGTH, &prev_unpack_row_length);
gl_functions.glGetIntegerv (GL_UNPACK_ALIGNMENT, &prev_unpack_alignment);
gl_functions.glGetIntegerv (GL_UNPACK_SKIP_ROWS, &prev_unpack_skip_rows);
gl_functions.glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &prev_unpack_skip_pixles);
gl_functions.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);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
gl_functions.glPixelStorei (GL_UNPACK_ROW_LENGTH, 256);
gl_functions.glPixelStorei (GL_UNPACK_ALIGNMENT, 8);
gl_functions.glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
gl_functions.glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
glGenTextures (1, &gl_tex);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, gl_tex);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_RGBA, 256, 256, 0,
GL_RGBA,
GL_UNSIGNED_BYTE,
data);
gl_functions.glGenTextures (1, &gl_tex);
gl_functions.glBindTexture (GL_TEXTURE_RECTANGLE_ARB, gl_tex);
gl_functions.glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_RGBA, 256, 256, 0,
GL_RGBA,
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);
gl_functions.glPixelStorei (GL_UNPACK_ROW_LENGTH, prev_unpack_row_length);
gl_functions.glPixelStorei (GL_UNPACK_ALIGNMENT, prev_unpack_alignment);
gl_functions.glPixelStorei (GL_UNPACK_SKIP_ROWS, prev_unpack_skip_rows);
gl_functions.glPixelStorei (GL_UNPACK_SKIP_PIXELS, prev_unpack_skip_pixles);
gl_functions.glBindTexture (GL_TEXTURE_RECTANGLE_ARB, prev_rectangle_binding);
g_assert (glGetError () == GL_NO_ERROR);
g_assert (gl_functions.glGetError () == GL_NO_ERROR);
g_free (data);
@ -153,7 +156,7 @@ draw_frame (TestState *state)
/* Cogl doesn't destroy foreign textures so we have to do it manually */
cogl_texture_get_gl_texture (tex_rect, &gl_tex, NULL);
glDeleteTextures (1, &gl_tex);
gl_functions.glDeleteTextures (1, &gl_tex);
cogl_handle_unref (tex_rect);
}
@ -214,7 +217,8 @@ static gboolean
check_rectangle_extension (void)
{
static const char rect_extension[] = "GL_ARB_texture_rectangle";
const char *extensions = (const char *) glGetString (GL_EXTENSIONS);
const char *extensions =
(const char *) gl_functions.glGetString (GL_EXTENSIONS);
const char *extensions_end;
extensions_end = extensions + strlen (extensions);
@ -246,6 +250,8 @@ test_cogl_texture_rectangle (TestConformSimpleFixture *fixture,
state.stage = clutter_stage_get_default ();
test_conform_get_gl_functions (&gl_functions);
/* Check whether GL supports the rectangle extension. If not we'll
just assume the test passes */
if (check_rectangle_extension ())

View File

@ -74,3 +74,27 @@ test_conform_simple_fixture_teardown (TestConformSimpleFixture *fixture,
/* const TestConformSharedState *shared_state = data; */
}
void
test_conform_get_gl_functions (TestConformGLFunctions *functions)
{
functions->glGetString = (void *) cogl_get_proc_address ("glGetString");
g_assert (functions->glGetString != NULL);
functions->glGetIntegerv = (void *) cogl_get_proc_address ("glGetIntegerv");
g_assert (functions->glGetIntegerv != NULL);
functions->glPixelStorei = (void *) cogl_get_proc_address ("glPixelStorei");
g_assert (functions->glPixelStorei != NULL);
functions->glBindTexture = (void *) cogl_get_proc_address ("glBindTexture");
g_assert (functions->glBindTexture != NULL);
functions->glGenTextures = (void *) cogl_get_proc_address ("glGenTextures");
g_assert (functions->glGenTextures != NULL);
functions->glGetError = (void *) cogl_get_proc_address ("glGetError");
g_assert (functions->glGetError != NULL);
functions->glDeleteTextures =
(void *) cogl_get_proc_address ("glDeleteTextures");
g_assert (functions->glDeleteTextures != NULL);
functions->glTexImage2D = (void *) cogl_get_proc_address ("glTexImage2D");
g_assert (functions->glTexImage2D != NULL);
functions->glTexParameteri =
(void *) cogl_get_proc_address ("glTexParameteri");
g_assert (functions->glTexParameteri != NULL);
}

View File

@ -25,6 +25,25 @@ typedef struct _TestConformTodo
void (* func) (TestConformSimpleFixture *, gconstpointer);
} TestConformTodo;
typedef struct _TestConformGLFunctions
{
const GLubyte * (* glGetString) (GLenum name);
void (* glGetIntegerv) (GLenum pname, GLint *params);
void (* glPixelStorei) (GLenum pname, GLint param);
void (* glBindTexture) (GLenum target, GLuint texture);
void (* glGenTextures) (GLsizei n, GLuint *textures);
GLenum (* glGetError) (void);
void (* glDeleteTextures) (GLsizei n, const GLuint *textures);
void (* glTexImage2D) (GLenum target, GLint level,
GLint internalFormat,
GLsizei width, GLsizei height,
GLint border, GLenum format, GLenum type,
const GLvoid *pixels);
void (* glTexParameteri) (GLenum target, GLenum pname, GLint param);
} TestConformGLFunctions;
void test_conform_get_gl_functions (TestConformGLFunctions *functions);
void test_conform_simple_fixture_setup (TestConformSimpleFixture *fixture,
gconstpointer data);
void test_conform_simple_fixture_teardown (TestConformSimpleFixture *fixture,

View File

@ -70,6 +70,25 @@ struct _TestCoglboxPrivate
{
GLuint gl_handle;
CoglHandle cogl_handle;
void
(* glGetIntegerv) (GLenum pname, GLint *params);
void
(* glPixelStorei) (GLenum pname, GLint param);
void
(* glTexParameteri) (GLenum target, GLenum pname, GLint param);
void
(* glTexImage2D) (GLenum target, GLint level,
GLint internalFormat,
GLsizei width, GLsizei height,
GLint border, GLenum format, GLenum type,
const GLvoid *pixels);
void
(* glGenTextures) (GLsizei n, GLuint *textures);
void
(* glDeleteTextures) (GLsizei n, const GLuint *textures);
void
(* glBindTexture) (GLenum target, GLuint texture);
};
/* Coglbox implementation
@ -111,7 +130,7 @@ test_coglbox_dispose (GObject *object)
priv = TEST_COGLBOX_GET_PRIVATE (object);
cogl_handle_unref (priv->cogl_handle);
glDeleteTextures (1, &priv->gl_handle);
priv->glDeleteTextures (1, &priv->gl_handle);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
}
@ -133,27 +152,35 @@ test_coglbox_init (TestCoglbox *self)
data[6] = 0; data[7] = 0; data[8] = 255;
data[9] = 0; data[10] = 0; data[11] = 0;
priv->glGetIntegerv = (void *) cogl_get_proc_address ("glGetIntegerv");
priv->glPixelStorei = (void *) cogl_get_proc_address ("glPixelStorei");
priv->glTexParameteri = (void *) cogl_get_proc_address ("glTexParameteri");
priv->glTexImage2D = (void *) cogl_get_proc_address ("glTexImage2D");
priv->glGenTextures = (void *) cogl_get_proc_address ("glGenTextures");
priv->glDeleteTextures = (void *) cogl_get_proc_address ("glDeleteTextures");
priv->glBindTexture = (void *) cogl_get_proc_address ("glBindTexture");
/* We are about to use OpenGL directly to create a TEXTURE_2D
* 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_ALIGNMENT, &prev_unpack_alignment);
glGetIntegerv (GL_TEXTURE_BINDING_2D, &prev_2d_texture_binding);
priv->glGetIntegerv (GL_UNPACK_ALIGNMENT, &prev_unpack_alignment);
priv->glGetIntegerv (GL_TEXTURE_BINDING_2D, &prev_2d_texture_binding);
glGenTextures (1, &priv->gl_handle);
glBindTexture (GL_TEXTURE_2D, priv->gl_handle);
priv->glGenTextures (1, &priv->gl_handle);
priv->glBindTexture (GL_TEXTURE_2D, priv->gl_handle);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
priv->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
priv->glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
/* Now restore the original GL state as Cogl had left it */
glPixelStorei (GL_UNPACK_ALIGNMENT, prev_unpack_alignment);
glBindTexture (GL_TEXTURE_2D, prev_2d_texture_binding);
priv->glPixelStorei (GL_UNPACK_ALIGNMENT, prev_unpack_alignment);
priv->glBindTexture (GL_TEXTURE_2D, prev_2d_texture_binding);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
priv->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
priv->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
/* Create texture from foreign */