[878/906] tests: update for glmem api change

This commit is contained in:
Matthew Waters 2014-02-05 01:53:04 +11:00 committed by Tim-Philipp Müller
parent b6f6d585c3
commit 54d70702cc
3 changed files with 153 additions and 141 deletions

View file

@ -89,21 +89,23 @@ init (gpointer data)
fail_if (tex == 0, "failed to create texture");
#if GST_GL_HAVE_GLES2
shader = gst_gl_shader_new (context);
fail_if (shader == NULL, "failed to create shader object");
if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) {
shader = gst_gl_shader_new (context);
fail_if (shader == NULL, "failed to create shader object");
gst_gl_shader_set_vertex_source (shader, vertex_shader_str_gles2);
gst_gl_shader_set_fragment_source (shader, fragment_shader_str_gles2);
gst_gl_shader_set_vertex_source (shader, vertex_shader_str_gles2);
gst_gl_shader_set_fragment_source (shader, fragment_shader_str_gles2);
error = NULL;
gst_gl_shader_compile (shader, &error);
fail_if (error != NULL, "Error compiling shader %s\n",
error ? error->message : "Unknown Error");
error = NULL;
gst_gl_shader_compile (shader, &error);
fail_if (error != NULL, "Error compiling shader %s\n",
error ? error->message : "Unknown Error");
shader_attr_position_loc =
gst_gl_shader_get_attribute_location (shader, "a_position");
shader_attr_texture_loc =
gst_gl_shader_get_attribute_location (shader, "a_texCoord");
shader_attr_position_loc =
gst_gl_shader_get_attribute_location (shader, "a_position");
shader_attr_texture_loc =
gst_gl_shader_get_attribute_location (shader, "a_texCoord");
}
#endif
}
@ -151,72 +153,76 @@ draw_render (gpointer data)
/* redraw the texture into the system provided framebuffer */
#if GST_GL_HAVE_OPENGL
GLfloat verts[8] = { 1.0f, 1.0f,
-1.0f, 1.0f,
-1.0f, -1.0f,
1.0f, -1.0f
};
GLfloat texcoords[8] = { 1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f
};
if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) {
GLfloat verts[8] = { 1.0f, 1.0f,
-1.0f, 1.0f,
-1.0f, -1.0f,
1.0f, -1.0f
};
GLfloat texcoords[8] = { 1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f
};
gl->Viewport (0, 0, 320, 240);
gl->Viewport (0, 0, 320, 240);
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, tex);
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, tex);
gl->EnableClientState (GL_VERTEX_ARRAY);
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
gl->EnableClientState (GL_VERTEX_ARRAY);
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
gl->DisableClientState (GL_VERTEX_ARRAY);
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
gl->DisableClientState (GL_VERTEX_ARRAY);
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
gl->Disable (GL_TEXTURE_2D);
gl->Disable (GL_TEXTURE_2D);
}
#endif
#if GST_GL_HAVE_GLES2
const GLfloat vVertices[] = { 1.0f, 1.0f, 0.0f,
1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
0.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
0.0f, 1.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f
};
if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) {
const GLfloat vVertices[] = { 1.0f, 1.0f, 0.0f,
1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
0.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
0.0f, 1.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f
};
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
gl->Clear (GL_COLOR_BUFFER_BIT);
gl->Clear (GL_COLOR_BUFFER_BIT);
gst_gl_shader_use (shader);
gst_gl_shader_use (shader);
/* Load the vertex position */
gl->VertexAttribPointer (shader_attr_position_loc, 3,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
/* Load the vertex position */
gl->VertexAttribPointer (shader_attr_position_loc, 3,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
/* Load the texture coordinate */
gl->VertexAttribPointer (shader_attr_texture_loc, 2,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
/* Load the texture coordinate */
gl->VertexAttribPointer (shader_attr_texture_loc, 2,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
gl->EnableVertexAttribArray (shader_attr_position_loc);
gl->EnableVertexAttribArray (shader_attr_texture_loc);
gl->EnableVertexAttribArray (shader_attr_position_loc);
gl->EnableVertexAttribArray (shader_attr_texture_loc);
gl->ActiveTexture (GL_TEXTURE0);
gl->BindTexture (GL_TEXTURE_2D, tex);
gst_gl_shader_set_uniform_1i (shader, "s_texture", 0);
gl->ActiveTexture (GL_TEXTURE0);
gl->BindTexture (GL_TEXTURE_2D, tex);
gst_gl_shader_set_uniform_1i (shader, "s_texture", 0);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
}
#endif
context_class->swap_buffers (context);

View file

@ -73,14 +73,14 @@ GST_START_TEST (test_basic)
/* test allocator creation */
ASSERT_WARNING (mem = gst_allocator_alloc (gl_allocator, 0, NULL););
mem = gst_gl_memory_alloc (context, formats[i], width, height);
mem = gst_gl_memory_alloc (context, vinfo);
fail_if (mem == NULL);
gl_mem = (GstGLMemory *) mem;
/* test init params */
fail_if (gl_mem->width != width);
fail_if (gl_mem->height != height);
fail_if (gl_mem->v_format != formats[i]);
fail_if (GST_VIDEO_INFO_WIDTH (&gl_mem->v_info) != width);
fail_if (GST_VIDEO_INFO_HEIGHT (&gl_mem->v_info) != height);
fail_if (GST_VIDEO_INFO_FORMAT (&gl_mem->v_info) != formats[i]);
fail_if (gl_mem->context != context);
fail_if (gl_mem->tex_id == 0);
@ -91,9 +91,12 @@ GST_START_TEST (test_basic)
/* test params */
fail_if (gl_mem->tex_id == gl_mem2->tex_id);
fail_if (gl_mem->width != gl_mem->width);
fail_if (gl_mem->height != gl_mem->height);
fail_if (gl_mem->v_format != gl_mem->v_format);
fail_if (GST_VIDEO_INFO_FORMAT (&gl_mem->v_info) !=
GST_VIDEO_INFO_FORMAT (&gl_mem2->v_info));
fail_if (GST_VIDEO_INFO_WIDTH (&gl_mem->v_info) !=
GST_VIDEO_INFO_WIDTH (&gl_mem2->v_info));
fail_if (GST_VIDEO_INFO_HEIGHT (&gl_mem->v_info) !=
GST_VIDEO_INFO_HEIGHT (&gl_mem2->v_info));
fail_if (gl_mem->gl_format != gl_mem->gl_format);
fail_if (gl_mem->context != gl_mem->context);
fail_if (gl_mem->tex_id == 0);

View file

@ -119,21 +119,23 @@ void
init (gpointer data)
{
#if GST_GL_HAVE_GLES2
shader = gst_gl_shader_new (context);
fail_if (shader == NULL, "failed to create shader object");
if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) {
shader = gst_gl_shader_new (context);
fail_if (shader == NULL, "failed to create shader object");
gst_gl_shader_set_vertex_source (shader, vertex_shader_str_gles2);
gst_gl_shader_set_fragment_source (shader, fragment_shader_str_gles2);
gst_gl_shader_set_vertex_source (shader, vertex_shader_str_gles2);
gst_gl_shader_set_fragment_source (shader, fragment_shader_str_gles2);
error = NULL;
gst_gl_shader_compile (shader, &error);
fail_if (error != NULL, "Error compiling shader %s\n",
error ? error->message : "Unknown Error");
error = NULL;
gst_gl_shader_compile (shader, &error);
fail_if (error != NULL, "Error compiling shader %s\n",
error ? error->message : "Unknown Error");
shader_attr_position_loc =
gst_gl_shader_get_attribute_location (shader, "a_position");
shader_attr_texture_loc =
gst_gl_shader_get_attribute_location (shader, "a_texCoord");
shader_attr_position_loc =
gst_gl_shader_get_attribute_location (shader, "a_position");
shader_attr_texture_loc =
gst_gl_shader_get_attribute_location (shader, "a_texCoord");
}
#endif
}
@ -147,72 +149,76 @@ draw_render (gpointer data)
/* redraw the texture into the system provided framebuffer */
#if GST_GL_HAVE_OPENGL
GLfloat verts[8] = { 1.0f, 1.0f,
-1.0f, 1.0f,
-1.0f, -1.0f,
1.0f, -1.0f
};
GLfloat texcoords[8] = { 1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f
};
if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) {
GLfloat verts[8] = { 1.0f, 1.0f,
-1.0f, 1.0f,
-1.0f, -1.0f,
1.0f, -1.0f
};
GLfloat texcoords[8] = { 1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f
};
gl->Viewport (0, 0, WIDTH, HEIGHT);
gl->Viewport (0, 0, 320, 240);
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, tex_id);
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, tex_id);
gl->EnableClientState (GL_VERTEX_ARRAY);
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
gl->EnableClientState (GL_VERTEX_ARRAY);
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
gl->DisableClientState (GL_VERTEX_ARRAY);
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
gl->DisableClientState (GL_VERTEX_ARRAY);
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
gl->Disable (GL_TEXTURE_2D);
gl->Disable (GL_TEXTURE_2D);
}
#endif
#if GST_GL_HAVE_GLES2
const GLfloat vVertices[] = { 1.0f, 1.0f, 0.0f,
1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
0.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
0.0f, 1.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f
};
if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) {
const GLfloat vVertices[] = { 1.0f, 1.0f, 0.0f,
1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
0.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
0.0f, 1.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f
};
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
gl->Clear (GL_COLOR_BUFFER_BIT);
gl->Clear (GL_COLOR_BUFFER_BIT);
gst_gl_shader_use (shader);
gst_gl_shader_use (shader);
/* Load the vertex position */
gl->VertexAttribPointer (shader_attr_position_loc, 3,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
/* Load the vertex position */
gl->VertexAttribPointer (shader_attr_position_loc, 3,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
/* Load the texture coordinate */
gl->VertexAttribPointer (shader_attr_texture_loc, 2,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
/* Load the texture coordinate */
gl->VertexAttribPointer (shader_attr_texture_loc, 2,
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
gl->EnableVertexAttribArray (shader_attr_position_loc);
gl->EnableVertexAttribArray (shader_attr_texture_loc);
gl->EnableVertexAttribArray (shader_attr_position_loc);
gl->EnableVertexAttribArray (shader_attr_texture_loc);
gl->ActiveTexture (GL_TEXTURE0);
gl->BindTexture (GL_TEXTURE_2D, tex_id);
gst_gl_shader_set_uniform_1i (shader, "s_texture", 0);
gl->ActiveTexture (GL_TEXTURE0);
gl->BindTexture (GL_TEXTURE_2D, tex_id);
gst_gl_shader_set_uniform_1i (shader, "s_texture", 0);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
}
#endif
context_class->swap_buffers (context);
@ -288,12 +294,11 @@ GST_START_TEST (test_upload_memory)
gboolean res;
gint i = 0;
gl_mem = gst_gl_memory_wrapped (context, FORMAT, WIDTH, HEIGHT, rgba_data,
NULL, NULL);
gst_video_info_set_format (&in_info, FORMAT, WIDTH, HEIGHT);
gst_video_info_set_format (&out_info, FORMAT, WIDTH, HEIGHT);
gl_mem = gst_gl_memory_wrapped (context, in_info, rgba_data, NULL, NULL);
gst_gl_upload_init_format (upload, in_info, out_info);
res = gst_gl_upload_perform_with_memory (upload, gl_mem);
@ -323,15 +328,14 @@ GST_START_TEST (test_upload_buffer)
gint i = 0;
gboolean res;
/* create GL buffer */
buffer = gst_buffer_new ();
gl_mem = gst_gl_memory_wrapped (context, FORMAT, WIDTH, HEIGHT, rgba_data,
NULL, NULL);
gst_buffer_append_memory (buffer, (GstMemory *) gl_mem);
gst_video_info_set_format (&in_info, FORMAT, WIDTH, HEIGHT);
gst_video_info_set_format (&out_info, FORMAT, WIDTH, HEIGHT);
/* create GL buffer */
buffer = gst_buffer_new ();
gl_mem = gst_gl_memory_wrapped (context, in_info, rgba_data, NULL, NULL);
gst_buffer_append_memory (buffer, (GstMemory *) gl_mem);
gst_gl_upload_init_format (upload, in_info, out_info);
res = gst_gl_upload_perform_with_buffer (upload, buffer, &tex_id);
@ -363,17 +367,16 @@ GST_START_TEST (test_upload_meta_producer)
gboolean res;
gint i = 0;
gst_video_info_set_format (&in_info, FORMAT, WIDTH, HEIGHT);
gst_video_info_set_format (&out_info, FORMAT, WIDTH, HEIGHT);
/* create GL buffer */
buffer = gst_buffer_new ();
gl_mem = gst_gl_memory_wrapped (context, FORMAT, WIDTH, HEIGHT, rgba_data,
NULL, NULL);
gl_mem = gst_gl_memory_wrapped (context, in_info, rgba_data, NULL, NULL);
gst_buffer_append_memory (buffer, (GstMemory *) gl_mem);
gst_gl_context_gen_texture (context, &tex_ids[0], FORMAT, WIDTH, HEIGHT);
gst_video_info_set_format (&in_info, FORMAT, WIDTH, HEIGHT);
gst_video_info_set_format (&out_info, FORMAT, WIDTH, HEIGHT);
gst_gl_upload_init_format (upload, in_info, out_info);
gst_gl_upload_add_video_gl_texture_upload_meta (upload, buffer);