Commit 1e9f7b63 authored by Matthew Waters's avatar Matthew Waters 🐨 Committed by Tim-Philipp Müller

gl: consolidate internal_rgba_format into glmemory

Expose some useful value format conversion functions available in
GstGLMemory.
parent f8ebadab
......@@ -273,7 +273,9 @@ static void
gst_gl_effects_init_gl_resources (GstGLFilter * filter)
{
GstGLEffects *effects = GST_GL_EFFECTS (filter);
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
guint internal_format;
gint i = 0;
for (i = 0; i < NEEDED_TEXTURES; i++) {
......@@ -285,8 +287,10 @@ 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,
gst_gl_internal_format_rgba (GST_GL_BASE_FILTER (filter)->context),
internal_format =
gst_gl_sized_gl_format_from_gl_format_type (context, GL_RGBA,
GL_UNSIGNED_BYTE);
gl->TexImage2D (GL_TEXTURE_2D, 0, internal_format,
GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info), 0, GL_RGBA, GL_UNSIGNED_BYTE,
NULL);
......
......@@ -93,8 +93,13 @@ static void gst_gl_filtershader_hcallback (gint width, gint height,
static void
gst_gl_filtershader_init_resources (GstGLFilter * filter)
{
glTexImage2D (GL_TEXTURE_2D, 0,
gst_gl_internal_format_rgba (GST_GL_BASE_FILTER (filter)->context),
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
guint internal_format;
internal_format =
gst_gl_sized_gl_format_from_gl_format_type (context, GL_RGBA,
GL_UNSIGNED_BYTE);
glTexImage2D (GL_TEXTURE_2D, 0, internal_format,
GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info), 0, GL_RGBA, GL_UNSIGNED_BYTE,
NULL);
......
......@@ -1432,6 +1432,7 @@ _init_convert_fbo (GstGLColorConvert * convert)
GstGLFuncs *gl;
guint out_width, out_height;
GLuint fake_texture = 0; /* a FBO must hava texture to init */
GLenum internal_format;
gl = convert->context->gl_vtable;
......@@ -1466,8 +1467,10 @@ _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,
gst_gl_internal_format_rgba (convert->context), out_width, out_height, 0,
internal_format =
gst_gl_sized_gl_format_from_gl_format_type (convert->context, GL_RGBA,
GL_UNSIGNED_BYTE);
gl->TexImage2D (GL_TEXTURE_2D, 0, internal_format, 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);
......
......@@ -90,6 +90,7 @@ gst_gl_framebuffer_generate (GstGLFramebuffer * frame, gint width, gint height,
{
GLuint fake_texture = 0;
const GstGLFuncs *gl;
GLenum internal_format;
g_return_val_if_fail (GST_IS_GL_FRAMEBUFFER (frame), FALSE);
g_return_val_if_fail (fbo != NULL && depth != NULL, FALSE);
......@@ -125,8 +126,10 @@ 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,
gst_gl_internal_format_rgba (frame->context), width, height, 0, GL_RGBA,
internal_format =
gst_gl_sized_gl_format_from_gl_format_type (frame->context, GL_RGBA,
GL_UNSIGNED_BYTE);
gl->TexImage2D (GL_TEXTURE_2D, 0, internal_format, 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);
......
......@@ -180,8 +180,21 @@ _gl_format_type_n_bytes (guint format, guint type)
_gl_type_n_bytes (type);
}
static inline GLenum
_gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format)
static inline guint
_gl_texture_type_n_bytes (GstVideoGLTextureType tex_format)
{
guint format, type;
format = gst_gl_format_from_gl_texture_type (tex_format);
type = GL_UNSIGNED_BYTE;
if (tex_format == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
type = GL_UNSIGNED_SHORT_5_6_5;
return _gl_format_type_n_bytes (format, type);
}
guint
gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format)
{
switch (tex_format) {
case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA:
......@@ -202,19 +215,6 @@ _gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format)
}
}
static inline guint
_gl_texture_type_n_bytes (GstVideoGLTextureType tex_format)
{
guint format, type;
format = _gst_gl_format_from_gl_texture_type (tex_format);
type = GL_UNSIGNED_BYTE;
if (tex_format == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
type = GL_UNSIGNED_SHORT_5_6_5;
return _gl_format_type_n_bytes (format, type);
}
GstVideoGLTextureType
gst_gl_texture_type_from_format (GstGLContext * context,
GstVideoFormat v_format, guint plane)
......@@ -292,9 +292,9 @@ gst_gl_texture_type_from_format (GstGLContext * context,
return GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
}
static inline GLenum
_sized_gl_format_from_gl_format_type (GstGLContext * context, GLenum format,
GLenum type)
guint
gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
guint format, guint type)
{
gboolean ext_texture_rg =
gst_gl_context_check_feature (context, "GL_EXT_texture_rg");
......@@ -303,7 +303,8 @@ _sized_gl_format_from_gl_format_type (GstGLContext * context, GLenum format,
case GL_RGBA:
switch (type) {
case GL_UNSIGNED_BYTE:
return gst_gl_internal_format_rgba (context);
return USING_GLES2 (context)
&& !USING_GLES3 (context) ? GL_RGBA : GL_RGBA8;
break;
}
break;
......@@ -395,7 +396,7 @@ _generate_texture (GstGLContext * context, GenTexture * data)
data->gl_format, data->gl_type, data->width, data->height);
internal_format =
_sized_gl_format_from_gl_format_type (context, data->gl_format,
gst_gl_sized_gl_format_from_gl_format_type (context, data->gl_format,
data->gl_type);
gl->GenTextures (1, &data->result);
......@@ -449,7 +450,7 @@ _upload_memory (GstGLContext * context, GstGLMemory * gl_mem)
if (gl_mem->tex_type == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
gl_type = GL_UNSIGNED_SHORT_5_6_5;
gl_format = _gst_gl_format_from_gl_texture_type (gl_mem->tex_type);
gl_format = gst_gl_format_from_gl_texture_type (gl_mem->tex_type);
gl_target = gl_mem->tex_target;
if (USING_OPENGL (context) || USING_GLES3 (context)
......@@ -595,7 +596,7 @@ _transfer_download (GstGLContext * context, GstGLMemory * gl_mem)
size = gst_gl_get_plane_data_size (&gl_mem->info, &gl_mem->valign,
gl_mem->plane);
plane_start = _find_plane_frame_start (gl_mem);
format = _gst_gl_format_from_gl_texture_type (gl_mem->tex_type);
format = gst_gl_format_from_gl_texture_type (gl_mem->tex_type);
type = GL_UNSIGNED_BYTE;
if (gl_mem->tex_type == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
type = GL_UNSIGNED_SHORT_5_6_5;
......@@ -634,7 +635,7 @@ _download_memory (GstGLContext * context, GstGLMemory * gl_mem)
GLuint fboId;
gl = context->gl_vtable;
format = _gst_gl_format_from_gl_texture_type (gl_mem->tex_type);
format = gst_gl_format_from_gl_texture_type (gl_mem->tex_type);
type = GL_UNSIGNED_BYTE;
if (gl_mem->tex_type == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
type = GL_UNSIGNED_SHORT_5_6_5;
......@@ -772,7 +773,7 @@ _gl_mem_new (GstAllocator * allocator, GstMemory * parent,
data.width = mem->tex_width;
data.height = GL_MEM_HEIGHT (mem);
data.gl_format = _gst_gl_format_from_gl_texture_type (mem->tex_type);
data.gl_format = gst_gl_format_from_gl_texture_type (mem->tex_type);
data.gl_type = GL_UNSIGNED_BYTE;
data.gl_target = mem->tex_target;
if (mem->tex_type == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
......@@ -920,11 +921,11 @@ _gl_mem_copy_thread (GstGLContext * context, gpointer data)
out_stride = copy_params->out_stride;
gl = src->context->gl_vtable;
out_gl_format = _gst_gl_format_from_gl_texture_type (copy_params->out_format);
out_gl_format = gst_gl_format_from_gl_texture_type (copy_params->out_format);
out_gl_type = GL_UNSIGNED_BYTE;
if (copy_params->out_format == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
out_gl_type = GL_UNSIGNED_SHORT_5_6_5;
in_gl_format = _gst_gl_format_from_gl_texture_type (src->tex_type);
in_gl_format = gst_gl_format_from_gl_texture_type (src->tex_type);
in_gl_type = GL_UNSIGNED_BYTE;
if (src->tex_type == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
in_gl_type = GL_UNSIGNED_SHORT_5_6_5;
......
......@@ -182,7 +182,13 @@ gboolean gst_gl_memory_setup_wrapped (GstGLContext * context, GstVideoInfo
gint gst_gl_memory_get_texture_width (GstGLMemory * gl_mem);
gint gst_gl_memory_get_texture_height (GstGLMemory * gl_mem);
GstVideoGLTextureType gst_gl_texture_type_from_format (GstGLContext *context, GstVideoFormat v_format, guint plane);
GstVideoGLTextureType gst_gl_texture_type_from_format (GstGLContext *context,
GstVideoFormat v_format,
guint plane);
guint gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format);
guint gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
guint format,
guint type);
void gst_gl_memory_download_transfer (GstGLMemory * gl_mem);
......
......@@ -108,6 +108,7 @@ static void
_gen_texture (GstGLContext * context, GenTexture * data)
{
const GstGLFuncs *gl = context->gl_vtable;
GLenum internal_format;
GST_TRACE ("Generating texture format:%u dimensions:%ux%u", data->format,
data->width, data->height);
......@@ -115,8 +116,11 @@ _gen_texture (GstGLContext * context, GenTexture * data)
gl->GenTextures (1, &data->result);
gl->BindTexture (GL_TEXTURE_2D, data->result);
internal_format =
gst_gl_sized_gl_format_from_gl_format_type (context, GL_RGBA,
GL_UNSIGNED_BYTE);
if (data->width > 0 && data->height > 0)
gl->TexImage2D (GL_TEXTURE_2D, 0, gst_gl_internal_format_rgba (context),
gl->TexImage2D (GL_TEXTURE_2D, 0, internal_format,
data->width, data->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
......@@ -127,6 +131,7 @@ _gen_texture (GstGLContext * context, GenTexture * data)
GST_LOG ("generated texture id:%d", data->result);
}
/* deprecated. replaced by GstGLMemory */
void
gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height)
......@@ -145,6 +150,7 @@ _del_texture (GstGLContext * context, guint * texture)
context->gl_vtable->DeleteTextures (1, texture);
}
/* deprecated. replaced by GstGLMemory */
void
gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture)
{
......@@ -163,6 +169,8 @@ static void
_gen_texture_full (GstGLContext * context, GenTextureFull * data)
{
const GstGLFuncs *gl = context->gl_vtable;
GstVideoGLTextureType tex_type;
GstVideoFormat v_format;
GLint glinternalformat = 0;
GLenum glformat = 0;
GLenum gltype = 0;
......@@ -170,60 +178,14 @@ _gen_texture_full (GstGLContext * context, GenTextureFull * data)
gl->GenTextures (1, &data->result);
gl->BindTexture (GL_TEXTURE_2D, data->result);
switch (GST_VIDEO_INFO_FORMAT (data->info)) {
case GST_VIDEO_FORMAT_RGB:
case GST_VIDEO_FORMAT_BGR:
{
glinternalformat = GL_RGB8;
glformat = GL_RGB;
gltype = GL_UNSIGNED_BYTE;
break;
}
case GST_VIDEO_FORMAT_RGB16:
{
glinternalformat = GL_RGB16;
glformat = GL_RGB;
gltype = GL_UNSIGNED_SHORT_5_6_5;
break;
}
case GST_VIDEO_FORMAT_RGBA:
case GST_VIDEO_FORMAT_BGRA:
case GST_VIDEO_FORMAT_ARGB:
case GST_VIDEO_FORMAT_ABGR:
case GST_VIDEO_FORMAT_RGBx:
case GST_VIDEO_FORMAT_BGRx:
case GST_VIDEO_FORMAT_xRGB:
case GST_VIDEO_FORMAT_xBGR:
case GST_VIDEO_FORMAT_AYUV:
{
glinternalformat = gst_gl_internal_format_rgba (context);
glformat = GL_RGBA;
gltype = GL_UNSIGNED_BYTE;
break;
}
case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_NV21:
{
glinternalformat = GL_LUMINANCE;
glformat = data->comp == 0 ? GL_LUMINANCE : GL_LUMINANCE_ALPHA;
gltype = GL_UNSIGNED_BYTE;
break;
}
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
case GST_VIDEO_FORMAT_Y444:
case GST_VIDEO_FORMAT_Y42B:
case GST_VIDEO_FORMAT_Y41B:
{
glformat = GL_LUMINANCE;
gltype = GL_UNSIGNED_BYTE;
break;
}
default:
GST_WARNING ("unsupported %s",
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (data->info)));
break;
}
v_format = GST_VIDEO_INFO_FORMAT (data->info);
tex_type = gst_gl_texture_type_from_format (context, v_format, data->comp);
glformat = gst_gl_format_from_gl_texture_type (tex_type);
gltype = GL_UNSIGNED_BYTE;
if (v_format == GST_VIDEO_FORMAT_RGB16)
gltype = GL_UNSIGNED_SHORT_5_6_5;
glinternalformat = gst_gl_sized_gl_format_from_gl_format_type (context,
glformat, gltype);
gl->TexImage2D (GL_TEXTURE_2D, 0, glinternalformat,
GST_VIDEO_INFO_COMP_WIDTH (data->info, data->comp),
......@@ -236,6 +198,7 @@ _gen_texture_full (GstGLContext * context, GenTextureFull * data)
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
/* deprecated. replaced by GstGLMemory */
void
gst_gl_generate_texture_full (GstGLContext * context, const GstVideoInfo * info,
const guint comp, gint stride[], gsize offset[], gsize size[],
......@@ -969,15 +932,3 @@ 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
}
......@@ -67,10 +67,13 @@ typedef void (*GLCB) (gint, gint, guint, gpointer stuff);
*/
typedef void (*GLCB_V2) (gpointer stuff);
/* deprecated. replaced by GstGLMemory */
void gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height);
/* deprecated. replaced by GstGLMemory */
void gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture);
/* deprecated. replaced by GstGLMemory */
void gst_gl_generate_texture_full (GstGLContext * context, const GstVideoInfo * info,
const guint comp, gint stride[], gsize offset[], gsize size[], GLuint * pTexture);
......@@ -105,7 +108,6 @@ 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment