glmemory: expose gst_gl_memory_texsubimage

Removes extremely similar code from glmemorypbo.
This commit is contained in:
Matthew Waters 2016-01-07 18:47:37 +11:00 committed by Tim-Philipp Müller
parent 1b49603d78
commit 5ba0ab3da9
3 changed files with 10 additions and 33 deletions

View file

@ -443,6 +443,12 @@ _gl_tex_map_cpu_access (GstGLMemory * gl_mem, GstMapInfo * info, gsize size)
static void static void
_upload_cpu_write (GstGLMemory * gl_mem, GstMapInfo * info, gsize maxsize) _upload_cpu_write (GstGLMemory * gl_mem, GstMapInfo * info, gsize maxsize)
{
gst_gl_memory_texsubimage (gl_mem, gl_mem->mem.data);
}
void
gst_gl_memory_texsubimage (GstGLMemory * gl_mem, gpointer read_pointer)
{ {
GstGLContext *context = gl_mem->mem.context; GstGLContext *context = gl_mem->mem.context;
const GstGLFuncs *gl; const GstGLFuncs *gl;
@ -477,7 +483,7 @@ _upload_cpu_write (GstGLMemory * gl_mem, GstMapInfo * info, gsize maxsize)
gst_gl_get_plane_start (&gl_mem->info, &gl_mem->valign, gst_gl_get_plane_start (&gl_mem->info, &gl_mem->valign,
gl_mem->plane) + gl_mem->mem.mem.offset; gl_mem->plane) + gl_mem->mem.mem.offset;
data = (gpointer) ((gintptr) plane_start + (gintptr) gl_mem->mem.data); data = (gpointer) ((gintptr) plane_start + (gintptr) read_pointer);
gl->BindTexture (gl_target, gl_mem->tex_id); gl->BindTexture (gl_target, gl_mem->tex_id);
gl->TexSubImage2D (gl_target, 0, 0, 0, gl_mem->tex_width, gl->TexSubImage2D (gl_target, 0, 0, 0, gl_mem->tex_width,

View file

@ -204,6 +204,8 @@ gboolean gst_gl_memory_copy_teximage (GstGLMemory * src,
gboolean gst_gl_memory_read_pixels (GstGLMemory * gl_mem, gboolean gst_gl_memory_read_pixels (GstGLMemory * gl_mem,
gpointer read_pointer); gpointer read_pointer);
void gst_gl_memory_texsubimage (GstGLMemory * gl_mem,
gpointer read_pointer);
/* accessors */ /* accessors */
gint gst_gl_memory_get_texture_width (GstGLMemory * gl_mem); gint gst_gl_memory_get_texture_width (GstGLMemory * gl_mem);

View file

@ -136,9 +136,7 @@ _upload_pbo_memory (GstGLMemoryPBO * gl_mem, GstMapInfo * info,
{ {
GstGLContext *context = gl_mem->mem.mem.context; GstGLContext *context = gl_mem->mem.mem.context;
const GstGLFuncs *gl; const GstGLFuncs *gl;
guint gl_format, gl_type, gl_target;
guint pbo_id; guint pbo_id;
gsize plane_start;
if (!GST_MEMORY_FLAG_IS_SET (gl_mem, GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD)) if (!GST_MEMORY_FLAG_IS_SET (gl_mem, GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD))
return; return;
@ -148,42 +146,13 @@ _upload_pbo_memory (GstGLMemoryPBO * gl_mem, GstMapInfo * info,
gl = context->gl_vtable; gl = context->gl_vtable;
pbo_id = *(guint *) pbo_info->data; pbo_id = *(guint *) pbo_info->data;
gl_type = GL_UNSIGNED_BYTE;
if (gl_mem->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->mem.tex_type);
gl_target = gst_gl_texture_target_to_gl (gl_mem->mem.tex_target);
if (USING_OPENGL (context) || USING_GLES3 (context)
|| USING_OPENGL3 (context)) {
gl->PixelStorei (GL_UNPACK_ROW_LENGTH, gl_mem->mem.unpack_length);
} else if (USING_GLES2 (context)) {
gl->PixelStorei (GL_UNPACK_ALIGNMENT, gl_mem->mem.unpack_length);
}
GST_CAT_LOG (GST_CAT_GL_MEMORY, "upload for texture id:%u, with pbo %u %ux%u", GST_CAT_LOG (GST_CAT_GL_MEMORY, "upload for texture id:%u, with pbo %u %ux%u",
gl_mem->mem.tex_id, pbo_id, gl_mem->mem.tex_width, gl_mem->mem.tex_id, pbo_id, gl_mem->mem.tex_width,
GL_MEM_HEIGHT (gl_mem)); GL_MEM_HEIGHT (gl_mem));
/* find the start of the plane data including padding */
plane_start =
gst_gl_get_plane_start (&gl_mem->mem.info, &gl_mem->mem.valign,
gl_mem->mem.plane) + GST_MEMORY_CAST (gl_mem)->offset;
gl->BindBuffer (GL_PIXEL_UNPACK_BUFFER, pbo_id); gl->BindBuffer (GL_PIXEL_UNPACK_BUFFER, pbo_id);
gl->BindTexture (gl_target, gl_mem->mem.tex_id); gst_gl_memory_texsubimage (GST_GL_MEMORY_CAST (gl_mem), NULL);
gl->TexSubImage2D (gl_target, 0, 0, 0, gl_mem->mem.tex_width,
GL_MEM_HEIGHT (gl_mem), gl_format, gl_type, (void *) plane_start);
gl->BindBuffer (GL_PIXEL_UNPACK_BUFFER, 0); gl->BindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
gl->BindTexture (gl_target, 0);
/* Reset to default values */
if (USING_OPENGL (context) || USING_GLES3 (context)) {
gl->PixelStorei (GL_UNPACK_ROW_LENGTH, 0);
} else if (USING_GLES2 (context)) {
gl->PixelStorei (GL_UNPACK_ALIGNMENT, 4);
}
} }
static guint static guint