/* free resources that need a gl context */ static void gst_gl_differencematte_reset_gl_resources (GstGLFilter * filter) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gint i; gl->DeleteTextures (1, &differencematte->savedbgtexture); gl->DeleteTextures (1, &differencematte->newbgtexture); for (i = 0; i < 4; i++) { if (differencematte->identity_shader) { gst_object_unref (differencematte->identity_shader); differencematte->identity_shader = NULL; } if (differencematte->shader[i]) { gst_object_unref (differencematte->shader[i]); differencematte->shader[i] = NULL; } if (differencematte->midtexture[i]) { gl->DeleteTextures (1, &differencematte->midtexture[i]); differencematte->midtexture[i] = 0; } } differencematte->location = NULL; differencematte->pixbuf = NULL; differencematte->savedbgtexture = 0; differencematte->newbgtexture = 0; differencematte->bg_has_changed = FALSE; }
/* free resources that need a gl context */ static void gst_gl_effects_reset_gl_resources (GstGLFilter * filter) { GstGLEffects *effects = GST_GL_EFFECTS (filter); GstGLFuncs *gl = filter->context->gl_vtable; gint i = 0; for (i = 0; i < NEEDED_TEXTURES; i++) { gl->DeleteTextures (1, &effects->midtexture[i]); effects->midtexture[i] = 0; } for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) { gl->DeleteTextures (1, &effects->curve[i]); effects->curve[i] = 0; } }
static void init_pixbuf_texture (GstGLContext * context, gpointer data) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (data); GstGLFilter *filter = GST_GL_FILTER (data); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gl->DeleteTextures (1, &differencematte->newbgtexture); gl->GenTextures (1, &differencematte->newbgtexture); gl->BindTexture (GL_TEXTURE_2D, differencematte->newbgtexture); gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, (gint) differencematte->pbuf_width, (gint) differencematte->pbuf_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, differencematte->pixbuf); 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); gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (differencematte->savedbgtexture == 0) { gl->GenTextures (1, &differencematte->savedbgtexture); gl->BindTexture (GL_TEXTURE_2D, differencematte->savedbgtexture); gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, GST_VIDEO_INFO_WIDTH (&filter->out_info), 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); gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } }
static void deinit (gpointer data) { GstGLContext *context = data; GstGLFuncs *gl = context->gl_vtable; gl->DeleteTextures (1, &tex);; gst_object_unref (fbo); #if GST_GL_HAVE_GLES2 if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) gst_object_unref (shader); #endif }
static gboolean _2d_texture_renderer_init_fbo (GstAmc2DTextureRenderer * renderer) { GstGLFuncs *gl; GLuint fake_texture = 0; guint out_width, out_height; out_width = GST_VIDEO_INFO_WIDTH (&renderer->info); out_height = GST_VIDEO_INFO_HEIGHT (&renderer->info); gl = renderer->context->gl_vtable; if (!gl->GenFramebuffers) { /* turn off the pipeline because Frame buffer object is a not present */ gst_gl_context_set_error (renderer->context, "Context, EXT_framebuffer_object supported: no"); return FALSE; } GST_INFO ("Context, EXT_framebuffer_object supported: yes"); /* setup FBO */ gl->GenFramebuffers (1, &renderer->fbo); gl->BindFramebuffer (GL_FRAMEBUFFER, renderer->fbo); /* setup the render buffer for depth */ gl->GenRenderbuffers (1, &renderer->depth_buffer); gl->BindRenderbuffer (GL_RENDERBUFFER, renderer->depth_buffer); gl->RenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, out_width, out_height); /* a fake texture is attached to the render 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->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); gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); /* attach the texture to the FBO to renderer to */ gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fake_texture, 0); /* attach the depth render buffer to the FBO */ gl->FramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderer->depth_buffer); if (!gst_gl_context_check_framebuffer_status (renderer->context)) { gst_gl_context_set_error (renderer->context, "GL framebuffer status incomplete"); return FALSE; } /* unbind the FBO */ gl->BindFramebuffer (GL_FRAMEBUFFER, 0); gl->DeleteTextures (1, &fake_texture); return TRUE; }