static void gst_gl_differencematte_interp (gint width, gint height, guint texture, gpointer stuff) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff); GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gst_gl_shader_use (differencematte->shader[3]); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "blend", 0); gl->ActiveTexture (GL_TEXTURE1); gl->BindTexture (GL_TEXTURE_2D, differencematte->newbgtexture); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "base", 1); gl->ActiveTexture (GL_TEXTURE2); gl->BindTexture (GL_TEXTURE_2D, differencematte->midtexture[2]); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "alpha", 2); gst_gl_filter_draw_texture (filter, texture, width, height); }
static void gst_gl_differencematte_diff (gint width, gint height, guint texture, gpointer stuff) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff); GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); gst_gl_shader_use (differencematte->shader[0]); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (differencematte->shader[0], "current", 0); gl->ActiveTexture (GL_TEXTURE1); gl->BindTexture (GL_TEXTURE_2D, differencematte->savedbgtexture); gst_gl_shader_set_uniform_1i (differencematte->shader[0], "saved", 1); gst_gl_filter_draw_texture (filter, texture, width, height); }
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 gboolean gst_gl_deinterlace_greedyh_callback (GstGLFilter * filter, GstGLMemory * in_tex, gpointer user_data) { GstGLShader *shader; GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter); GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; GstGLFuncs *gl = context->gl_vtable; shader = gst_gl_deinterlace_get_fragment_shader (filter, "greedhy", greedyh_fragment_source); if (!shader) return FALSE; #if GST_GL_HAVE_OPENGL if (USING_OPENGL (context)) { gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); } #endif gst_gl_shader_use (shader); if (G_LIKELY (deinterlace_filter->prev_tex != NULL)) { gl->ActiveTexture (GL_TEXTURE1); gst_gl_shader_set_uniform_1i (shader, "tex_prev", 1); gl->BindTexture (GL_TEXTURE_2D, gst_gl_memory_get_texture_id (deinterlace_filter->prev_tex)); } gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, gst_gl_memory_get_texture_id (in_tex)); gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1f (shader, "max_comb", 5.0f / 255.0f); gst_gl_shader_set_uniform_1f (shader, "motion_threshold", 25.0f / 255.0f); gst_gl_shader_set_uniform_1f (shader, "motion_sense", 30.0f / 255.0f); gst_gl_shader_set_uniform_1f (shader, "width", GST_VIDEO_INFO_WIDTH (&filter->out_info)); gst_gl_shader_set_uniform_1f (shader, "height", GST_VIDEO_INFO_HEIGHT (&filter->out_info)); gst_gl_filter_draw_fullscreen_quad (filter); /* we keep the previous buffer around so this is safe */ deinterlace_filter->prev_tex = in_tex; return TRUE; }
static void gst_gl_effects_sobel_callback_vconv (gint width, gint height, guint texture, gpointer data) { GstGLShader *shader = NULL; GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLFilter *filter = GST_GL_FILTER (effects); if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "vconv0", sep_sobel_vconv3_fragment_source_gles2, sep_sobel_vconv3_fragment_source_opengl))) { GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; #if GST_GL_HAVE_OPENGL if (USING_OPENGL (GST_GL_BASE_FILTER (filter)->context)) { gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); } #endif gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1f (shader, "height", height); gst_gl_filter_draw_texture (filter, texture, width, height); } }
static void gst_gl_effects_twirl_callback (gint width, gint height, guint texture, gpointer data) { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLFilter *filter = GST_GL_FILTER (effects); GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; GstGLFuncs *gl = context->gl_vtable; shader = gst_gl_effects_get_fragment_shader (effects, "twirl", twirl_fragment_source_gles2); if (!shader) return; #if GST_GL_HAVE_OPENGL if (USING_OPENGL (context)) { gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); } #endif gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_filter_draw_texture (filter, texture, width, height); }
void gst_gl_effects_xray_step_five (gint width, gint height, guint texture, gpointer data) { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLFilter *filter = GST_GL_FILTER (effects); GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray4"); if (!shader) { shader = gst_gl_shader_new (context); g_hash_table_insert (effects->shaderstable, "xray4", shader); } if (!gst_gl_shader_compile_and_check (shader, multiply_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) { gst_gl_context_set_error (context, "Failed to initialize multiply shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); return; } gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE2); gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, effects->midtexture[2]); gl->Disable (GL_TEXTURE_2D); gst_gl_shader_set_uniform_1i (shader, "base", 2); gl->ActiveTexture (GL_TEXTURE1); gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); gl->Disable (GL_TEXTURE_2D); gst_gl_shader_set_uniform_1f (shader, "alpha", (gfloat) 0.5f); gst_gl_shader_set_uniform_1i (shader, "blend", 1); gst_gl_filter_draw_texture (filter, texture, width, height); }
void gst_3d_scene_clear_state (Gst3DScene * self) { GstGLFuncs *gl = self->context->gl_vtable; gl->BindVertexArray (0); gl->BindTexture (GL_TEXTURE_2D, 0); gst_gl_context_clear_shader (self->context); }
static void gst_gl_effects_squeeze_callback (gint width, gint height, guint texture, gpointer data) { GstGLShader *shader; GstGLFilter *filter = GST_GL_FILTER (data); GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "squeeze0"); if (!shader) { shader = gst_gl_shader_new (context); g_hash_table_insert (effects->shaderstable, (gchar *) "squeeze0", shader); if (USING_GLES2 (context) || USING_OPENGL3 (context)) { if (!gst_gl_shader_compile_with_default_v_and_check (shader, squeeze_fragment_source_gles2, &filter->draw_attr_position_loc, &filter->draw_attr_texture_loc)) { /* gst gl context error is already set */ GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("Failed to initialize squeeze shader, %s", gst_gl_context_get_error ()), (NULL)); return; } } #if GST_GL_HAVE_OPENGL if (USING_OPENGL (context)) { if (!gst_gl_shader_compile_and_check (shader, squeeze_fragment_source_opengl, GST_GL_SHADER_FRAGMENT_SOURCE)) { gst_gl_context_set_error (context, "Failed to initialize squeeze shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); return; } } #endif } #if GST_GL_HAVE_OPENGL if (USING_OPENGL (context)) { gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); } #endif gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE0); if (USING_OPENGL (context)) gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_filter_draw_texture (filter, texture, width, height); }
static void gst_gl_filter_glass_draw_video_plane (GstGLFilter * filter, gint width, gint height, guint texture, gfloat center_x, gfloat center_y, gfloat start_alpha, gfloat stop_alpha, gboolean reversed, gfloat rotation) { GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (filter); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gfloat topy = reversed ? center_y - 1.0f : center_y + 1.0f; gfloat bottomy = reversed ? center_y + 1.0f : center_y - 1.0f; /* *INDENT-OFF* */ gfloat mesh[] = { /*| Vertex |TexCoord0| Colour |*/ center_x-1.6, topy, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, start_alpha, center_x+1.6, topy, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, start_alpha, center_x+1.6, bottomy, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, stop_alpha, center_x-1.6, bottomy, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, stop_alpha, }; /* *INDENT-ON* */ GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (glass_filter->shader, "tex", 0); gst_gl_shader_set_uniform_1f (glass_filter->shader, "yrot", rotation); gst_gl_shader_set_uniform_1f (glass_filter->shader, "aspect", (gfloat) width / (gfloat) height); gl->ClientActiveTexture (GL_TEXTURE0); gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); gl->EnableClientState (GL_VERTEX_ARRAY); gl->EnableClientState (GL_COLOR_ARRAY); gl->VertexPointer (3, GL_FLOAT, 9 * sizeof (gfloat), mesh); gl->TexCoordPointer (2, GL_FLOAT, 9 * sizeof (gfloat), &mesh[3]); gl->ColorPointer (4, GL_FLOAT, 9 * sizeof (gfloat), &mesh[5]); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); gl->DisableClientState (GL_VERTEX_ARRAY); gl->DisableClientState (GL_COLOR_ARRAY); }
static void gst_gl_differencematte_identity (gint width, gint height, guint texture, gpointer stuff) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff); GstGLFilter *filter = GST_GL_FILTER (differencematte); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gst_gl_shader_use (differencematte->identity_shader); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (differencematte->identity_shader, "tex", 0); gst_gl_filter_draw_texture (filter, texture, width, height); }
static void gst_gl_effects_xray_step_two (gint width, gint height, guint texture, gpointer data) { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLFilter *filter = GST_GL_FILTER (effects); GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray1"); if (!shader) { shader = gst_gl_shader_new (context); g_hash_table_insert (effects->shaderstable, "xray1", shader); } if (!kernel_ready) { fill_gaussian_kernel (gauss_kernel, 7, 1.5); kernel_ready = TRUE; } if (!gst_gl_shader_compile_and_check (shader, hconv7_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) { gst_gl_context_set_error (context, "Failed to initialize hconv7 shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); return; } gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE1); gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); gl->Disable (GL_TEXTURE_2D); gst_gl_shader_set_uniform_1i (shader, "tex", 1); gst_gl_shader_set_uniform_1fv (shader, "kernel", 9, gauss_kernel); gst_gl_shader_set_uniform_1f (shader, "width", width); gst_gl_filter_draw_texture (filter, texture, width, height); }
static gboolean _2d_texture_renderer_init (GstAmc2DTextureRenderer * renderer) { GstGLFuncs *gl; gboolean res; gl = renderer->context->gl_vtable; if (renderer->initialized) return TRUE; if (!gl->CreateProgramObject && !gl->CreateProgram) { gst_gl_context_set_error (renderer->context, "Cannot perform conversion without OpenGL shaders"); return FALSE; } _gen_oes_texture (renderer->context, &renderer->oes_tex_id); res = gst_gl_context_gen_shader (renderer->context, vert_COPY_OES, frag_COPY_OES, &renderer->shader); if (!res) return FALSE; renderer->shader_attr_position_loc = gst_gl_shader_get_attribute_location (renderer->shader, "a_position"); renderer->shader_attr_texture_loc = gst_gl_shader_get_attribute_location (renderer->shader, "a_texcoord"); gst_gl_shader_use (renderer->shader); gst_gl_shader_set_uniform_1i (renderer->shader, "u_tex", 0); gst_gl_context_clear_shader (renderer->context); if (!_2d_texture_renderer_init_fbo (renderer)) return FALSE; gl->BindTexture (GL_TEXTURE_2D, 0); renderer->initialized = TRUE; return TRUE; }
/* init resources that need a gl context */ static void gst_gl_effects_init_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->GenTextures (1, &effects->midtexture[i]); gl->BindTexture (GL_TEXTURE_2D, effects->midtexture[i]); 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 gst_gl_effects_xray_sobel_length (gint width, gint height, guint texture, gpointer data) { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLFilter *filter = GST_GL_FILTER (effects); GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray_sob_len"); if (!shader) { shader = gst_gl_shader_new (context); g_hash_table_insert (effects->shaderstable, (gchar *) "xray_sob_len", shader); } if (!gst_gl_shader_compile_and_check (shader, sep_sobel_length_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) { gst_gl_context_set_error (context, "Failed to initialize seobel length shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); return; } gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE1); gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); gl->Disable (GL_TEXTURE_2D); gst_gl_shader_set_uniform_1i (shader, "tex", 1); gst_gl_shader_set_uniform_1i (shader, "invert", TRUE); gst_gl_filter_draw_texture (filter, texture, width, height); }
static void gst_gl_effects_square_callback (gint width, gint height, guint texture, gpointer data) { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLFilter *filter = GST_GL_FILTER (effects); GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "square0"); if (!shader) { shader = gst_gl_shader_new (context); g_hash_table_insert (effects->shaderstable, "square0", shader); } if (!gst_gl_shader_compile_and_check (shader, square_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) { gst_gl_context_set_error (context, "Failed to initialize square shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); return; } gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE0); gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f); gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f); gst_gl_filter_draw_texture (filter, texture, width, height); }
static void gst_gl_differencematte_vblur (gint width, gint height, guint texture, gpointer stuff) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff); GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gst_gl_shader_use (differencematte->shader[2]); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (differencematte->shader[2], "tex", 0); gst_gl_shader_set_uniform_1fv (differencematte->shader[2], "kernel", 7, differencematte->kernel); gst_gl_shader_set_uniform_1f (differencematte->shader[2], "gauss_height", height); gst_gl_filter_draw_texture (filter, texture, width, height); }
static gboolean gst_gl_filtershader_hcallback (GstGLFilter * filter, GstGLMemory * in_tex, gpointer stuff) { GstGLFilterShader *filtershader = GST_GL_FILTERSHADER (filter); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; GstGLShader *shader; if (!(shader = _maybe_recompile_shader (filtershader))) return FALSE; gl->ClearColor (0.0, 0.0, 0.0, 1.0); gl->Clear (GL_COLOR_BUFFER_BIT); gst_gl_shader_use (shader); /* FIXME: propertise these */ gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1f (shader, "width", GST_VIDEO_INFO_WIDTH (&filter->out_info)); gst_gl_shader_set_uniform_1f (shader, "height", GST_VIDEO_INFO_HEIGHT (&filter->out_info)); gst_gl_shader_set_uniform_1f (shader, "time", filtershader->time); /* FIXME: propertise these */ filter->draw_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); filter->draw_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texcoord"); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, gst_gl_memory_get_texture_id (in_tex)); gst_gl_filter_draw_fullscreen_quad (filter); gst_object_unref (shader); return TRUE; }
static void gst_gl_filtershader_hcallback (gint width, gint height, guint texture, gpointer stuff) { GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFilterShader *filtershader = GST_GL_FILTERSHADER (filter); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; GstGLShader *shader; if (!(shader = _maybe_recompile_shader (filtershader))) return; gl->ClearColor (0.0, 0.0, 0.0, 1.0); gl->Clear (GL_COLOR_BUFFER_BIT); gst_gl_shader_use (shader); /* FIXME: propertise these */ gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1f (shader, "width", width); gst_gl_shader_set_uniform_1f (shader, "height", height); gst_gl_shader_set_uniform_1f (shader, "time", filtershader->time); /* FIXME: propertise these */ filter->draw_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); filter->draw_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texcoord"); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_filter_draw_texture (filter, texture, width, height); gst_object_unref (shader); }
static void _draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff) { GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFuncs *gl = filter->context->gl_vtable; #if GST_GL_HAVE_OPENGL if (gst_gl_context_get_gl_api (filter->context) & GST_GL_API_OPENGL) { gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); } #endif gst_gl_shader_use (filter->default_shader); gl->ActiveTexture (GL_TEXTURE1); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (filter->default_shader, "tex", 1); gst_gl_shader_set_uniform_1f (filter->default_shader, "width", width); gst_gl_shader_set_uniform_1f (filter->default_shader, "height", height); gst_gl_filter_draw_texture (filter, texture, width, height); }
/* opengl scene, params: input texture (not the output mixer->texture) */ static void gst_gl_video_mixer_callback (gpointer stuff) { GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (stuff); GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (stuff); GstGLMixer *mixer = GST_GL_MIXER (video_mixer); GstGLFuncs *gl = GST_GL_BASE_MIXER (mixer)->context->gl_vtable; GLint attr_position_loc = 0; GLint attr_texture_loc = 0; guint out_width, out_height; guint count = 0; out_width = GST_VIDEO_INFO_WIDTH (&vagg->info); out_height = GST_VIDEO_INFO_HEIGHT (&vagg->info); gst_gl_context_clear_shader (GST_GL_BASE_MIXER (mixer)->context); gl->BindTexture (GL_TEXTURE_2D, 0); gl->Disable (GL_DEPTH_TEST); gl->Disable (GL_CULL_FACE); if (gl->GenVertexArrays) { if (!video_mixer->vao) gl->GenVertexArrays (1, &video_mixer->vao); gl->BindVertexArray (video_mixer->vao); } if (!_draw_background (video_mixer)) return; gst_gl_shader_use (video_mixer->shader); attr_position_loc = gst_gl_shader_get_attribute_location (video_mixer->shader, "a_position"); attr_texture_loc = gst_gl_shader_get_attribute_location (video_mixer->shader, "a_texCoord"); gl->Enable (GL_BLEND); while (count < video_mixer->input_frames->len) { GstGLMixerFrameData *frame; GstGLVideoMixerPad *pad; GstVideoInfo *v_info; guint in_tex; guint in_width, in_height; /* *INDENT-OFF* */ gfloat v_vertices[] = { -1.0,-1.0,-1.0f, 0.0f, 0.0f, 1.0,-1.0,-1.0f, 1.0f, 0.0f, 1.0, 1.0,-1.0f, 1.0f, 1.0f, -1.0, 1.0,-1.0f, 0.0f, 1.0f, }; /* *INDENT-ON* */ frame = g_ptr_array_index (video_mixer->input_frames, count); if (!frame) { GST_DEBUG ("skipping texture, null frame"); count++; continue; } pad = (GstGLVideoMixerPad *) frame->pad; v_info = &GST_VIDEO_AGGREGATOR_PAD (pad)->info; in_width = GST_VIDEO_INFO_WIDTH (v_info); in_height = GST_VIDEO_INFO_HEIGHT (v_info); if (!frame->texture || in_width <= 0 || in_height <= 0 || pad->alpha == 0.0f) { GST_DEBUG ("skipping texture:%u frame:%p width:%u height:%u alpha:%f", frame->texture, frame, in_width, in_height, pad->alpha); count++; continue; } in_tex = frame->texture; _init_vbo_indices (video_mixer); if (pad->geometry_change || !pad->vertex_buffer) { gint pad_width, pad_height; gfloat w, h; _mixer_pad_get_output_size (video_mixer, pad, &pad_width, &pad_height); w = ((gfloat) pad_width / (gfloat) out_width); h = ((gfloat) pad_height / (gfloat) out_height); /* top-left */ v_vertices[0] = v_vertices[15] = 2.0f * (gfloat) pad->xpos / (gfloat) out_width - 1.0f; /* bottom-left */ v_vertices[1] = v_vertices[6] = 2.0f * (gfloat) pad->ypos / (gfloat) out_height - 1.0f; /* top-right */ v_vertices[5] = v_vertices[10] = v_vertices[0] + 2.0f * w; /* bottom-right */ v_vertices[11] = v_vertices[16] = v_vertices[1] + 2.0f * h; GST_TRACE ("processing texture:%u dimensions:%ux%u, at %f,%f %fx%f with " "alpha:%f", in_tex, in_width, in_height, v_vertices[0], v_vertices[1], v_vertices[5], v_vertices[11], pad->alpha); if (!pad->vertex_buffer) gl->GenBuffers (1, &pad->vertex_buffer); gl->BindBuffer (GL_ARRAY_BUFFER, pad->vertex_buffer); gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), v_vertices, GL_STATIC_DRAW); pad->geometry_change = FALSE; } else { gl->BindBuffer (GL_ARRAY_BUFFER, pad->vertex_buffer); } gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, video_mixer->vbo_indices); gl->BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl->BlendEquation (GL_FUNC_ADD); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, in_tex); gst_gl_shader_set_uniform_1i (video_mixer->shader, "texture", 0); gst_gl_shader_set_uniform_1f (video_mixer->shader, "alpha", pad->alpha); gl->EnableVertexAttribArray (attr_position_loc); gl->EnableVertexAttribArray (attr_texture_loc); gl->VertexAttribPointer (attr_position_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), (void *) 0); gl->VertexAttribPointer (attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), (void *) (3 * sizeof (GLfloat))); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); ++count; } gl->DisableVertexAttribArray (attr_position_loc); gl->DisableVertexAttribArray (attr_texture_loc); if (gl->GenVertexArrays) gl->BindVertexArray (0); gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); gl->BindBuffer (GL_ARRAY_BUFFER, 0); gl->BindTexture (GL_TEXTURE_2D, 0); gl->Disable (GL_BLEND); gst_gl_context_clear_shader (GST_GL_BASE_MIXER (mixer)->context); }
/* opengl scene, params: input texture (not the output mixer->texture) */ static gboolean gst_gl_mosaic_callback (gpointer stuff) { GstGLMosaic *mosaic = GST_GL_MOSAIC (stuff); GstGLMixer *mixer = GST_GL_MIXER (mosaic); GstGLFuncs *gl = GST_GL_BASE_MIXER (mixer)->context->gl_vtable; GList *walk; static GLfloat xrot = 0; static GLfloat yrot = 0; static GLfloat zrot = 0; GLint attr_position_loc = 0; GLint attr_texture_loc = 0; const GLfloat matrix[] = { 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; const GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; guint count = 0; gst_gl_context_clear_shader (GST_GL_BASE_MIXER (mixer)->context); gl->BindTexture (GL_TEXTURE_2D, 0); gl->Enable (GL_DEPTH_TEST); gl->ClearColor (0.0, 0.0, 0.0, 0.0); gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gst_gl_shader_use (mosaic->shader); attr_position_loc = gst_gl_shader_get_attribute_location (mosaic->shader, "a_position"); attr_texture_loc = gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord"); GST_OBJECT_LOCK (mosaic); walk = GST_ELEMENT (mosaic)->sinkpads; while (walk) { GstGLMixerPad *pad = walk->data; /* *INDENT-OFF* */ gfloat v_vertices[] = { /* front face */ 1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, -1.0f,-1.0f,-1.0f, 0.0f, 1.0f, -1.0f, 1.0f,-1.0f, 0.0f, 0.0f, /* right face */ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f,-1.0f, 0.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, /* left face */ -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f,-1.0f, 1.0f, 1.0f, -1.0f,-1.0f,-1.0f, 0.0f, 1.0f, -1.0f,-1.0f, 1.0f, 0.0f, 0.0f, /* top face */ 1.0f,-1.0f, 1.0f, 1.0f, 0.0f, -1.0f,-1.0f, 1.0f, 0.0f, 0.0f, -1.0f,-1.0f,-1.0f, 0.0f, 1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, /* bottom face */ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, /* back face */ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f }; /* *INDENT-ON* */ guint in_tex; guint width, height; in_tex = pad->current_texture; width = GST_VIDEO_INFO_WIDTH (&GST_VIDEO_AGGREGATOR_PAD (pad)->info); height = GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_AGGREGATOR_PAD (pad)->info); if (!in_tex || width <= 0 || height <= 0) { GST_DEBUG ("skipping texture:%u pad:%p width:%u height %u", in_tex, pad, width, height); count++; walk = g_list_next (walk); continue; } GST_TRACE ("processing texture:%u dimensions:%ux%u", in_tex, width, height); gl->VertexAttribPointer (attr_position_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count]); gl->VertexAttribPointer (attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count + 3]); gl->EnableVertexAttribArray (attr_position_loc); gl->EnableVertexAttribArray (attr_texture_loc); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, in_tex); gst_gl_shader_set_uniform_1i (mosaic->shader, "s_texture", 0); gst_gl_shader_set_uniform_1f (mosaic->shader, "xrot_degree", xrot); gst_gl_shader_set_uniform_1f (mosaic->shader, "yrot_degree", yrot); gst_gl_shader_set_uniform_1f (mosaic->shader, "zrot_degree", zrot); gst_gl_shader_set_uniform_matrix_4fv (mosaic->shader, "u_matrix", 1, GL_FALSE, matrix); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); ++count; walk = g_list_next (walk); } GST_OBJECT_UNLOCK (mosaic); gl->DisableVertexAttribArray (attr_position_loc); gl->DisableVertexAttribArray (attr_texture_loc); gl->BindTexture (GL_TEXTURE_2D, 0); gl->Disable (GL_DEPTH_TEST); gst_gl_context_clear_shader (GST_GL_BASE_MIXER (mixer)->context); xrot += 0.6f; yrot += 0.4f; zrot += 0.8f; return TRUE; }
static void _callback_gles2 (gint width, gint height, guint texture, gpointer stuff) { GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter); GstGLFuncs *gl = filter->context->gl_vtable; static GLfloat xrot = 0; static GLfloat yrot = 0; static GLfloat zrot = 0; /* *INDENT-OFF* */ const GLfloat v_vertices[] = { /*| Vertex | TexCoord |*/ /* front face */ 1.0, 1.0, -1.0, 1.0, 0.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 0.0, 1.0, -1.0, 1.0, -1.0, 0.0, 0.0, /* back face */ 1.0, 1.0, 1.0, 1.0, 0.0, -1.0, 1.0, 1.0, 0.0, 0.0, -1.0, -1.0, 1.0, 0.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, /* right face */ 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, /* left face */ -1.0, 1.0, 1.0, 1.0, 0.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 0.0, 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, /* top face */ 1.0, -1.0, 1.0, 1.0, 0.0, -1.0, -1.0, 1.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, /* bottom face */ 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 0.0, 1.0, -1.0, 1.0, 1.0, 0.0, 0.0 }; /* *INDENT-ON* */ GLushort indices[] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }; GLint attr_position_loc = 0; GLint attr_texture_loc = 0; const GLfloat matrix[] = { 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; gl->Enable (GL_DEPTH_TEST); gl->ClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0); gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gst_gl_shader_use (cube_filter->shader); attr_position_loc = gst_gl_shader_get_attribute_location (cube_filter->shader, "a_position"); attr_texture_loc = gst_gl_shader_get_attribute_location (cube_filter->shader, "a_texCoord"); /* Load the vertex position */ gl->VertexAttribPointer (attr_position_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), v_vertices); /* Load the texture coordinate */ gl->VertexAttribPointer (attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[3]); gl->EnableVertexAttribArray (attr_position_loc); gl->EnableVertexAttribArray (attr_texture_loc); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (cube_filter->shader, "s_texture", 0); gst_gl_shader_set_uniform_1f (cube_filter->shader, "xrot_degree", xrot); gst_gl_shader_set_uniform_1f (cube_filter->shader, "yrot_degree", yrot); gst_gl_shader_set_uniform_1f (cube_filter->shader, "zrot_degree", zrot); gst_gl_shader_set_uniform_matrix_4fv (cube_filter->shader, "u_matrix", 1, GL_FALSE, matrix); gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices); gl->DisableVertexAttribArray (attr_position_loc); gl->DisableVertexAttribArray (attr_texture_loc); gl->Disable (GL_DEPTH_TEST); xrot += 0.3f; yrot += 0.2f; zrot += 0.4f; }
static void _callback_opengl (gint width, gint height, guint texture, gpointer stuff) { GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (stuff); GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFuncs *gl = filter->context->gl_vtable; static GLfloat xrot = 0; static GLfloat yrot = 0; static GLfloat zrot = 0; /* *INDENT-OFF* */ const GLfloat v_vertices[] = { /*| Vertex | TexCoord |*/ /* front face */ 1.0, 1.0, -1.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0, 0.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 0.0, 1.0, /* back face */ -1.0, 1.0, 1.0, 0.0, 0.0, -1.0, -1.0, 1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, /* right face */ -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, -1.0, -1.0, 1.0, 0.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 0.0, 1.0, /* left face */ 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, -1.0, 1.0, 1.0, 0.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, /* top face */ 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, -1.0, 1.0, 0.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 0.0, 1.0, /* bottom face */ 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0, 0.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 0.0, 1.0, }; /* *INDENT-ON* */ GLushort indices[] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }; gl->Enable (GL_DEPTH_TEST); gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); gl->ClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0); gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl->MatrixMode (GL_PROJECTION); gluLookAt (0.0, 0.0, -6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); gl->MatrixMode (GL_MODELVIEW); gl->LoadIdentity (); // gl->Translatef (0.0f, 0.0f, -5.0f); gl->Rotatef (xrot, 1.0f, 0.0f, 0.0f); gl->Rotatef (yrot, 0.0f, 1.0f, 0.0f); gl->Rotatef (zrot, 0.0f, 0.0f, 1.0f); gl->ClientActiveTexture (GL_TEXTURE0); gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); gl->EnableClientState (GL_VERTEX_ARRAY); gl->VertexPointer (3, GL_FLOAT, 5 * sizeof (float), v_vertices); gl->TexCoordPointer (2, GL_FLOAT, 5 * sizeof (float), &v_vertices[3]); gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices); gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); gl->DisableClientState (GL_VERTEX_ARRAY); gl->Disable (GL_DEPTH_TEST); xrot += 0.3f; yrot += 0.2f; zrot += 0.4f; }
void gst_gl_effects_luma_to_curve (GstGLEffects * effects, GstGLEffectsCurve curve, gint curve_index, gint width, gint height, GLuint texture) { GstGLShader *shader; GstGLFilter *filter = GST_GL_FILTER (effects); GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "lumamap0"); if (!shader) { shader = gst_gl_shader_new (context); g_hash_table_insert (effects->shaderstable, "lumamap0", shader); } if (!gst_gl_shader_compile_and_check (shader, luma_to_curve_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) { gst_gl_context_set_error (context, "Failed to initialize luma to curve shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); return; } gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); gst_gl_shader_use (shader); if (effects->curve[curve_index] == 0) { /* this parameters are needed to have a right, predictable, mapping */ gl->GenTextures (1, &effects->curve[curve_index]); gl->Enable (GL_TEXTURE_1D); gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]); gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP); gl->TexImage1D (GL_TEXTURE_1D, 0, curve.bytes_per_pixel, curve.width, 0, GL_RGB, GL_UNSIGNED_BYTE, curve.pixel_data); gl->Disable (GL_TEXTURE_1D); } gl->ActiveTexture (GL_TEXTURE2); gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); gst_gl_shader_set_uniform_1i (shader, "tex", 2); gl->Disable (GL_TEXTURE_2D); gl->ActiveTexture (GL_TEXTURE1); gl->Enable (GL_TEXTURE_1D); gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]); gst_gl_shader_set_uniform_1i (shader, "curve", 1); gl->Disable (GL_TEXTURE_1D); gst_gl_filter_draw_texture (filter, texture, width, height); }
static gboolean _2d_texture_renderer_draw (GstAmc2DTextureRenderer * renderer) { GstGLFuncs *gl; guint out_width, out_height; GLint viewport_dim[4]; /* *INDENT-OFF* */ const GLfloat vertices[] = { 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 }; /* *INDENT-ON* */ GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; GLenum multipleRT[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; gl = renderer->context->gl_vtable; out_width = GST_VIDEO_INFO_WIDTH (&renderer->info); out_height = GST_VIDEO_INFO_HEIGHT (&renderer->info); gl->BindFramebuffer (GL_FRAMEBUFFER, renderer->fbo); /* attach the texture to the FBO to rendererer to */ gl->BindTexture (GL_TEXTURE_2D, renderer->tex_id); gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderer->tex_id, 0); if (gl->DrawBuffers) gl->DrawBuffers (1, multipleRT); else if (gl->DrawBuffer) gl->DrawBuffer (GL_COLOR_ATTACHMENT0); gl->GetIntegerv (GL_VIEWPORT, viewport_dim); gl->Viewport (0, 0, out_width, out_height); gl->ClearColor (0.0, 0.0, 0.0, 0.0); gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gst_gl_shader_use (renderer->shader); gst_gl_shader_set_uniform_matrix_4fv (renderer->shader, "u_transformation", 1, FALSE, renderer->transformation_matrix); gl->VertexAttribPointer (renderer->shader_attr_position_loc, 4, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vertices); gl->VertexAttribPointer (renderer->shader_attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vertices[3]); gl->EnableVertexAttribArray (renderer->shader_attr_position_loc); gl->EnableVertexAttribArray (renderer->shader_attr_texture_loc); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_EXTERNAL_OES, renderer->oes_tex_id); gl->TexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl->TexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gl->TexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl->TexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); gl->DisableVertexAttribArray (renderer->shader_attr_position_loc); gl->DisableVertexAttribArray (renderer->shader_attr_texture_loc); if (gl->DrawBuffer) gl->DrawBuffer (GL_NONE); /* we are done with the shader */ gst_gl_context_clear_shader (renderer->context); gl->Viewport (viewport_dim[0], viewport_dim[1], viewport_dim[2], viewport_dim[3]); gst_gl_context_check_framebuffer_status (renderer->context); gl->BindFramebuffer (GL_FRAMEBUFFER, 0); return TRUE; }
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; }
static void gst_gl_transformation_callback (gpointer stuff) { GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLTransformation *transformation = GST_GL_TRANSFORMATION (filter); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; GLfloat temp_matrix[16]; gst_gl_context_clear_shader (GST_GL_BASE_FILTER (filter)->context); gl->BindTexture (GL_TEXTURE_2D, 0); gl->ClearColor (0.f, 0.f, 0.f, 1.f); gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gst_gl_shader_use (transformation->shader); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, transformation->in_tex); gst_gl_shader_set_uniform_1i (transformation->shader, "texture", 0); graphene_matrix_to_float (&transformation->mvp_matrix, temp_matrix); gst_gl_shader_set_uniform_matrix_4fv (transformation->shader, "mvp", 1, GL_FALSE, temp_matrix); if (!transformation->vertex_buffer) { transformation->attr_position = gst_gl_shader_get_attribute_location (transformation->shader, "position"); transformation->attr_texture = gst_gl_shader_get_attribute_location (transformation->shader, "uv"); if (gl->GenVertexArrays) { gl->GenVertexArrays (1, &transformation->vao); gl->BindVertexArray (transformation->vao); } gl->GenBuffers (1, &transformation->vertex_buffer); gl->GenBuffers (1, &transformation->vbo_indices); gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, transformation->vbo_indices); gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices, GL_STATIC_DRAW); transformation->caps_change = TRUE; } if (gl->GenVertexArrays) gl->BindVertexArray (transformation->vao); if (transformation->caps_change) { _upload_vertices (transformation); _bind_buffer (transformation); if (gl->GenVertexArrays) { gl->BindVertexArray (0); gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); gl->BindBuffer (GL_ARRAY_BUFFER, 0); } } else if (!gl->GenVertexArrays) { _bind_buffer (transformation); } gl->DrawElements (GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, indices); if (gl->GenVertexArrays) gl->BindVertexArray (0); else _unbind_buffer (transformation); gst_gl_context_clear_shader (GST_GL_BASE_FILTER (filter)->context); transformation->caps_change = FALSE; }
//opengl scene, params: input texture (not the output filter->texture) static void gst_gl_deinterlace_callback (gint width, gint height, guint texture, gpointer stuff) { GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (stuff); GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; guint temp; GLfloat verts[] = { -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0 }; GLfloat texcoords0[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; GLfloat texcoords1[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; gl->MatrixMode (GL_PROJECTION); gl->LoadIdentity (); gst_gl_shader_use (deinterlace_filter->shader); if (G_UNLIKELY (deinterlace_filter->prev_tex == 0)) { gst_gl_context_gen_texture (GST_GL_BASE_FILTER (filter)->context, &deinterlace_filter->prev_tex, GST_VIDEO_INFO_FORMAT (&filter->out_info), GST_VIDEO_INFO_WIDTH (&filter->out_info), GST_VIDEO_INFO_HEIGHT (&filter->out_info)); } else { gl->ActiveTexture (GL_TEXTURE1); gst_gl_shader_set_uniform_1i (deinterlace_filter->shader, "tex_prev", 1); gl->BindTexture (GL_TEXTURE_2D, deinterlace_filter->prev_tex); } gl->ActiveTexture (GL_TEXTURE0); gst_gl_shader_set_uniform_1i (deinterlace_filter->shader, "tex", 0); gst_gl_shader_set_uniform_1f (deinterlace_filter->shader, "max_comb", 5.0f / 255.0f); gst_gl_shader_set_uniform_1f (deinterlace_filter->shader, "motion_threshold", 25.0f / 255.0f); gst_gl_shader_set_uniform_1f (deinterlace_filter->shader, "motion_sense", 30.0f / 255.0f); gst_gl_shader_set_uniform_1f (deinterlace_filter->shader, "width", GST_VIDEO_INFO_WIDTH (&filter->out_info)); gst_gl_shader_set_uniform_1f (deinterlace_filter->shader, "height", GST_VIDEO_INFO_HEIGHT (&filter->out_info)); gl->ClientActiveTexture (GL_TEXTURE0); gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); gl->EnableClientState (GL_VERTEX_ARRAY); gl->VertexPointer (2, GL_FLOAT, 0, &verts); gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords0); gl->ClientActiveTexture (GL_TEXTURE1); gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords1); gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4); gl->DisableClientState (GL_VERTEX_ARRAY); gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); gl->ClientActiveTexture (GL_TEXTURE0); gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); if (texture == filter->in_tex_id) { temp = filter->in_tex_id; filter->in_tex_id = deinterlace_filter->prev_tex; deinterlace_filter->prev_tex = temp; } else { deinterlace_filter->prev_tex = texture; } }
//opengl scene, params: input texture (not the output filter->texture) static void gst_gl_bumper_callback (gint width, gint height, guint texture, gpointer stuff) { static GLfloat xrot = 0; static GLfloat yrot = 0; static GLfloat zrot = 0; GstGLFuncs *gl; GstGLBumper *bumper = GST_GL_BUMPER (stuff); GstGLContext *context = GST_GL_FILTER (bumper)->context; GLint locTangent = 0; //choose the lights GLfloat light_direction0[] = { 1.0, 0.0, -1.0, 0.0 }; // light goes along -x GLfloat light_direction1[] = { -1.0, 0.0, -1.0, 0.0 }; // light goes along x GLfloat light_diffuse0[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_diffuse1[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; /* *INDENT-OFF* */ MeshData mesh[] = { /* | Vertex | Normal |TexCoord0|TexCoord1| VertexAttrib | */ /*F*/ { 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, /*r*/ { 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0}, /*o*/ {-1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0}, {-1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, /*R*/ {-1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, /*i*/ {-1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0}, /*g*/ {-1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0}, {-1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, /*B*/ {-1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, /*a*/ {-1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0}, /*c*/ { 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0}, { 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, /*L*/ { 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, /*e*/ { 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0}, /*f*/ { 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0}, { 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, /*T*/ { 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, /*o*/ { 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, /*p*/ {-1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0}, {-1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, /*B*/ { 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}, /*o*/ { 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0}, /*t*/ {-1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -1.0}, {-1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0}, }; GLushort indices[] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }; /* *INDENT-ON* */ gl = GST_GL_FILTER (bumper)->context->gl_vtable; //eye point gl->MatrixMode (GL_PROJECTION); gluLookAt (0.0, 0.0, -6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); gl->MatrixMode (GL_MODELVIEW); //scene conf gl->Enable (GL_DEPTH_TEST); gl->DepthFunc (GL_LEQUAL); gl->Hint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); gl->ShadeModel (GL_SMOOTH); //set the lights gl->Lightfv (GL_LIGHT0, GL_POSITION, light_direction0); gl->Lightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse0); gl->Lightfv (GL_LIGHT1, GL_POSITION, light_direction1); gl->Lightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse1); gl->Materialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse); gl->ColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); gl->Enable (GL_COLOR_MATERIAL); gl->Enable (GL_LIGHTING); gl->Enable (GL_LIGHT0); gl->Enable (GL_LIGHT1); //configure shader gst_gl_shader_use (bumper->shader); locTangent = gst_gl_shader_get_attribute_location (bumper->shader, "aTangent"); //set the normal map gl->ActiveTexture (GL_TEXTURE1); gst_gl_shader_set_uniform_1i (bumper->shader, "texture1", 1); gl->BindTexture (GL_TEXTURE_2D, bumper->bumpmap); //set the video texture gl->ActiveTexture (GL_TEXTURE0); gst_gl_shader_set_uniform_1i (bumper->shader, "texture0", 0); gl->BindTexture (GL_TEXTURE_2D, texture); gl->Rotatef (xrot, 1.0f, 0.0f, 0.0f); gl->Rotatef (yrot, 0.0f, 1.0f, 0.0f); gl->Rotatef (zrot, 0.0f, 0.0f, 1.0f); gl->EnableVertexAttribArray (locTangent); gl->ClientActiveTexture (GL_TEXTURE0); gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); gl->EnableClientState (GL_VERTEX_ARRAY); gl->EnableClientState (GL_NORMAL_ARRAY); gl->VertexAttribPointer (locTangent, 3, GL_FLOAT, 0, sizeof (MeshData), &mesh[0].va0); gl->VertexPointer (3, GL_FLOAT, sizeof (MeshData), &mesh[0].x); gl->NormalPointer (GL_FLOAT, sizeof (MeshData), &mesh[0].nx); gl->TexCoordPointer (2, GL_FLOAT, sizeof (MeshData), &mesh[0].s0); gl->ClientActiveTexture (GL_TEXTURE1); gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); gl->TexCoordPointer (2, GL_FLOAT, sizeof (MeshData), &mesh[0].s1); gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices); gl->DisableClientState (GL_VERTEX_ARRAY); gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); gl->DisableClientState (GL_NORMAL_ARRAY); gl->ClientActiveTexture (GL_TEXTURE0); gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); gl->DisableVertexAttribArray (locTangent); gst_gl_context_clear_shader (context); gl->Disable (GL_LIGHT0); gl->Disable (GL_LIGHT1); gl->Disable (GL_LIGHTING); gl->Disable (GL_COLOR_MATERIAL); xrot += 1.0f; yrot += 0.9f; zrot += 0.6f; }