gl: add and use gst_gl_internal_format_rgba

Previously when compiling GstGL with both GL and GLES2,
GL_RGBA8 was picked from GL/gl.h. But a clash may happen at
runtime when one is selecting GLES2.

gst_gl_internal_format_rgba allows to check at runtime
if it should use GL_RGBA or GL_RGBA8.
This commit is contained in:
Julien Isorce 2015-05-27 16:28:39 +01:00 committed by Tim-Philipp Müller
parent 2efeb71c83
commit fce0e0ba3c
8 changed files with 31 additions and 15 deletions

View file

@ -285,10 +285,11 @@ gst_gl_effects_init_gl_resources (GstGLFilter * filter)
gl->GenTextures (1, &effects->midtexture[i]);
gl->BindTexture (GL_TEXTURE_2D, effects->midtexture[i]);
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8,
gl->TexImage2D (GL_TEXTURE_2D, 0,
gst_gl_internal_format_rgba (GST_GL_BASE_FILTER (filter)->context),
GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info),
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
GST_VIDEO_INFO_HEIGHT (&filter->out_info), 0, GL_RGBA, GL_UNSIGNED_BYTE,
NULL);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

View file

@ -93,10 +93,11 @@ static void gst_gl_filtershader_hcallback (gint width, gint height,
static void
gst_gl_filtershader_init_resources (GstGLFilter * filter)
{
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8,
glTexImage2D (GL_TEXTURE_2D, 0,
gst_gl_internal_format_rgba (GST_GL_BASE_FILTER (filter)->context),
GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info),
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
GST_VIDEO_INFO_HEIGHT (&filter->out_info), 0, GL_RGBA, GL_UNSIGNED_BYTE,
NULL);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

View file

@ -31,7 +31,6 @@ G_BEGIN_DECLS
//FIXME:
#define GL_RGB16 GL_RGB565
#define GL_RGB8 GL_RGB
#define GL_RGBA8 GL_RGBA
//END FIXME
/* UNSUPPORTED */

View file

@ -1463,8 +1463,9 @@ _init_convert_fbo (GstGLColorConvert * convert)
/* a fake texture is attached to the convert FBO (cannot init without it) */
gl->GenTextures (1, &fake_texture);
gl->BindTexture (GL_TEXTURE_2D, fake_texture);
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, out_width, out_height,
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexImage2D (GL_TEXTURE_2D, 0,
gst_gl_internal_format_rgba (convert->context), out_width, out_height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

View file

@ -125,8 +125,9 @@ gst_gl_framebuffer_generate (GstGLFramebuffer * frame, gint width, gint height,
/* setup a texture to render to */
gl->GenTextures (1, &fake_texture);
gl->BindTexture (GL_TEXTURE_2D, fake_texture);
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8,
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexImage2D (GL_TEXTURE_2D, 0,
gst_gl_internal_format_rgba (frame->context), width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

View file

@ -303,7 +303,7 @@ _sized_gl_format_from_gl_format_type (GstGLContext * context, GLenum format,
case GL_RGBA:
switch (type) {
case GL_UNSIGNED_BYTE:
return GL_RGBA8;
return gst_gl_internal_format_rgba (context);
break;
}
break;

View file

@ -113,8 +113,8 @@ _gen_texture (GstGLContext * context, GenTexture * data)
gl->BindTexture (GL_TEXTURE_2D, data->result);
if (data->width > 0 && data->height > 0)
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, data->width,
data->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexImage2D (GL_TEXTURE_2D, 0, gst_gl_internal_format_rgba (context),
data->width, data->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -193,7 +193,7 @@ _gen_texture_full (GstGLContext * context, GenTextureFull * data)
case GST_VIDEO_FORMAT_xBGR:
case GST_VIDEO_FORMAT_AYUV:
{
glinternalformat = GL_RGBA8;
glinternalformat = gst_gl_internal_format_rgba (context);
glformat = GL_RGBA;
gltype = GL_UNSIGNED_BYTE;
break;
@ -904,3 +904,15 @@ gst_gl_caps_replace_all_caps_features (const GstCaps * caps,
return tmp;
}
GLint
gst_gl_internal_format_rgba (GstGLContext * context)
{
#if GST_GL_HAVE_GLES2 && (GST_GL_HAVE_OPENGL || GST_GL_HAVE_GLES3)
return USING_GLES2 (context) ? GL_RGBA : GL_RGBA8;
#elif GST_GL_HAVE_OPENGL || GST_GL_HAVE_GLES3
return GL_RGBA8;
#else
return GL_RGBA;
#endif
}

View file

@ -105,6 +105,7 @@ gsize gst_gl_get_plane_data_size (GstVideoInfo * info, GstVideoAlignment * align
guint plane);
GstCaps * gst_gl_caps_replace_all_caps_features (const GstCaps * caps,
const gchar * feature_name);
GLint gst_gl_internal_format_rgba (GstGLContext * context);
G_END_DECLS