void gst_gl_effects_sobel (GstGLEffects * effects) { GstGLFilter *filter = GST_GL_FILTER (effects); GstGLShader *shader; shader = gst_gl_effects_get_fragment_shader (effects, "desat0", desaturate_fragment_source_gles2); gst_gl_filter_render_to_target_with_shader (filter, effects->intexture, effects->midtexture[0], shader); shader = gst_gl_effects_get_fragment_shader (effects, "hconv0", sep_sobel_hconv3_fragment_source_gles2); gst_gl_shader_use (shader); gst_gl_shader_set_uniform_1f (shader, "height", GST_VIDEO_INFO_HEIGHT (&filter->out_info)); gst_gl_filter_render_to_target_with_shader (filter, effects->midtexture[0], effects->midtexture[1], shader); shader = gst_gl_effects_get_fragment_shader (effects, "vconv0", sep_sobel_vconv3_fragment_source_gles2); gst_gl_shader_use (shader); gst_gl_shader_set_uniform_1f (shader, "width", GST_VIDEO_INFO_WIDTH (&filter->out_info)); gst_gl_filter_render_to_target_with_shader (filter, effects->midtexture[1], effects->midtexture[0], shader); shader = gst_gl_effects_get_fragment_shader (effects, "len0", sep_sobel_length_fragment_source_gles2); gst_gl_shader_use (shader); gst_gl_shader_set_uniform_1i (shader, "invert", effects->invert); gst_gl_filter_render_to_target_with_shader (filter, effects->midtexture[0], effects->outtexture, shader); }
//opengl scene, params: input texture (not the output filter->texture) static void gst_gl_filter_glass_callback (gpointer stuff) { static gint64 start_time = 0; gfloat rotation; GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (stuff); GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable; gint width = GST_VIDEO_INFO_WIDTH (&filter->out_info); gint height = GST_VIDEO_INFO_HEIGHT (&filter->out_info); guint texture = glass_filter->in_tex; if (start_time == 0) start_time = get_time (); else { gint64 time_left = (glass_filter->timestamp / 1000) - (get_time () - start_time); time_left -= 1000000 / 25; if (time_left > 2000) { GST_LOG ("escape"); return; } } gst_gl_shader_use (glass_filter->passthrough_shader); gst_gl_filter_glass_draw_background_gradient (glass_filter); //Rotation if (start_time != 0) { gint64 time_passed = get_time () - start_time; rotation = sin (time_passed / 1200000.0) * 45.0f; } else { rotation = 0.0f; } gl->Enable (GL_BLEND); gl->BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gst_gl_shader_use (glass_filter->shader); //Reflection gst_gl_filter_glass_draw_video_plane (filter, width, height, texture, 0.0f, 2.0f, 0.3f, 0.0f, TRUE, rotation); //Main video gst_gl_filter_glass_draw_video_plane (filter, width, height, texture, 0.0f, 0.0f, 1.0f, 1.0f, FALSE, rotation); gst_gl_context_clear_shader (GST_GL_BASE_FILTER (filter)->context); gl->Disable (GL_BLEND); }
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); }
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 gboolean _src_shader_fill_bound_fbo (gpointer impl) { struct SrcShader *src = impl; const GstGLFuncs *gl; g_return_val_if_fail (src->base.context, FALSE); g_return_val_if_fail (src->shader, FALSE); gl = src->base.context->gl_vtable; gst_gl_shader_use (src->shader); if (gl->GenVertexArrays) gl->BindVertexArray (src->vao); else _bind_buffer (src); gl->DrawElements (GL_TRIANGLES, src->n_indices, GL_UNSIGNED_SHORT, (gpointer) (gintptr) src->index_offset); if (gl->GenVertexArrays) gl->BindVertexArray (0); else _unbind_buffer (src); gst_gl_context_clear_shader (src->base.context); return TRUE; }
static gboolean blit_tex (gpointer data) { GstGLContext *context = data; const GstGLFuncs *gl = context->gl_vtable; gl->Clear (GL_COLOR_BUFFER_BIT); gst_gl_shader_use (shader); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, gst_gl_memory_get_texture_id (gl_tex)); gst_gl_shader_set_uniform_1i (shader, "s_texture", 0); if (gl->GenVertexArrays) gl->BindVertexArray (vao); _bind_buffer (context); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); if (gl->GenVertexArrays) gl->BindVertexArray (0); _unbind_buffer (context); 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_differencematte_interp (gint width, gint height, guint texture, gpointer stuff) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gst_gl_shader_use (differencematte->shader[3]); glActiveTexture (GL_TEXTURE0); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "blend", 0); glActiveTexture (GL_TEXTURE1); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, differencematte->newbgtexture); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "base", 1); glActiveTexture (GL_TEXTURE2); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, differencematte->midtexture[2]); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "alpha", 2); gst_gl_differencematte_draw_texture (differencematte, texture); }
static void gst_gl_effects_xray_step_three (gint width, gint height, guint texture, gpointer data) { GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLShader *shader; shader = g_hash_table_lookup (effects->shaderstable, "xray2"); if (!shader) { shader = gst_gl_shader_new (); g_hash_table_insert (effects->shaderstable, "xray2", shader); } g_return_if_fail (gst_gl_shader_compile_and_check (shader, vconv7_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gst_gl_shader_use (shader); glActiveTexture (GL_TEXTURE1); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (shader, "tex", 1); gst_gl_shader_set_uniform_1fv (shader, "kernel", 9, gauss_kernel); gst_gl_effects_draw_texture (effects, texture); }
static void gst_gl_differencematte_vblur (gint width, gint height, guint texture, gpointer stuff) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff); gfloat gauss_kernel[9] = { 0.026995f, 0.064759f, 0.120985f, 0.176033f, 0.199471f, 0.176033f, 0.120985f, 0.064759f, 0.026995f }; glMatrixMode (GL_PROJECTION); glLoadIdentity (); gst_gl_shader_use (differencematte->shader[2]); glActiveTexture (GL_TEXTURE0); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (differencematte->shader[2], "tex", 0); gst_gl_shader_set_uniform_1fv (differencematte->shader[2], "kernel", 9, gauss_kernel); gst_gl_shader_set_uniform_1f (differencematte->shader[2], "norm_const", 0.977016f); gst_gl_shader_set_uniform_1f (differencematte->shader[2], "norm_offset", 0.0f); gst_gl_differencematte_draw_texture (differencematte, texture); }
static void draw_render (gpointer data) { GstGLContext *context = data; GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context); const GstGLFuncs *gl = context->gl_vtable; gl->Clear (GL_COLOR_BUFFER_BIT); gst_gl_shader_use (shader); if (gl->GenVertexArrays) gl->BindVertexArray (vao); else _bind_buffer (context); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, tex_id); gst_gl_shader_set_uniform_1i (shader, "s_texture", 0); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); if (gl->GenVertexArrays) gl->BindVertexArray (0); else _unbind_buffer (context); context_class->swap_buffers (context); }
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_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) { GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (filter); gfloat topy; gfloat bottomy; if (reversed) { topy = center_y - 1.0f; bottomy = center_y + 1.0f; } else { topy = center_y + 1.0f; bottomy = center_y - 1.0f; } gst_gl_shader_use (glass_filter->shader); glActiveTextureARB (GL_TEXTURE0_ARB); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (glass_filter->shader, "tex", 0); gst_gl_shader_set_uniform_1f (glass_filter->shader, "width", (gfloat) width); gst_gl_shader_set_uniform_1f (glass_filter->shader, "height", (gfloat) height); glBegin (GL_QUADS); glColor4f (1.0f, 1.0f, 1.0f, start_alpha); glTexCoord2i (0, height); glVertex2f (center_x - 1.6f, topy); glTexCoord2i (width, height); glVertex2f (center_x + 1.6f, topy); glColor4f (1.0, 1.0, 1.0, stop_alpha); glTexCoord2i (width, 0); glVertex2f (center_x + 1.6f, bottomy); glTexCoord2i (0, 0); glVertex2f (center_x - 1.6f, bottomy); glEnd (); gst_gl_shader_use (0); }
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); }
//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); GstGLBuffer *gl_buffer_prev = deinterlace_filter->gl_buffer_prev; glMatrixMode (GL_PROJECTION); glLoadIdentity (); gst_gl_shader_use (deinterlace_filter->shader); glEnable (GL_TEXTURE_RECTANGLE_ARB); if (gl_buffer_prev) { glActiveTexture (GL_TEXTURE1_ARB); gst_gl_shader_set_uniform_1i (deinterlace_filter->shader, "tex_prev", 1); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, gl_buffer_prev->texture); } glActiveTexture (GL_TEXTURE0_ARB); gst_gl_shader_set_uniform_1i (deinterlace_filter->shader, "tex", 0); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); 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_1i (deinterlace_filter->shader, "width", filter->width); gst_gl_shader_set_uniform_1i (deinterlace_filter->shader, "height", filter->height); glBegin (GL_QUADS); glMultiTexCoord2iARB (GL_TEXTURE0_ARB, 0, 0); glMultiTexCoord2iARB (GL_TEXTURE1_ARB, 0, 0); glVertex2i (-1, -1); glMultiTexCoord2iARB (GL_TEXTURE0_ARB, width, 0); glMultiTexCoord2iARB (GL_TEXTURE1_ARB, width, 0); glVertex2i (1, -1); glMultiTexCoord2iARB (GL_TEXTURE0_ARB, width, height); glMultiTexCoord2iARB (GL_TEXTURE1_ARB, width, height); glVertex2i (1, 1); glMultiTexCoord2iARB (GL_TEXTURE0_ARB, 0, height); glMultiTexCoord2iARB (GL_TEXTURE1_ARB, 0, height); glVertex2i (-1, 1); glEnd (); glDisable (GL_TEXTURE_RECTANGLE_ARB); }
static void _update_uniforms (GstGLFilterShader * filtershader) { if (filtershader->new_uniforms && filtershader->uniforms) { gst_gl_shader_use (filtershader->shader); gst_structure_foreach (filtershader->uniforms, (GstStructureForeachFunc) _set_uniform, filtershader->shader); filtershader->new_uniforms = FALSE; } }
static gboolean gst_gl_alpha_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex, GstGLMemory * out_tex) { GstGLAlpha *alpha = GST_GL_ALPHA (filter); GstGLShader *shader; if (!alpha->alpha_shader) _create_shader (alpha); GST_OBJECT_LOCK (alpha); if (alpha->method == ALPHA_METHOD_SET) { shader = alpha->alpha_shader; gst_gl_shader_use (shader); gst_gl_shader_set_uniform_1f (shader, "alpha", alpha->alpha); } else { shader = alpha->chroma_key_shader; gst_gl_shader_use (shader); gst_gl_shader_set_uniform_1f (shader, "cb", alpha->cb); gst_gl_shader_set_uniform_1f (shader, "cr", alpha->cr); gst_gl_shader_set_uniform_1f (shader, "kg", alpha->kg); gst_gl_shader_set_uniform_1f (shader, "accept_angle_tg", alpha->accept_angle_tg); gst_gl_shader_set_uniform_1f (shader, "accept_angle_ctg", alpha->accept_angle_ctg); gst_gl_shader_set_uniform_1f (shader, "one_over_kc", alpha->one_over_kc); gst_gl_shader_set_uniform_1f (shader, "kfgy_scale", alpha->kfgy_scale); gst_gl_shader_set_uniform_1f (shader, "noise_level2", alpha->noise_level2); gst_gl_shader_set_uniform_1f (shader, "smin", 0.5 - alpha->black_sensitivity / 255.0); gst_gl_shader_set_uniform_1f (shader, "smax", 0.5 + alpha->white_sensitivity / 255.0); } GST_OBJECT_UNLOCK (alpha); gst_gl_filter_render_to_target_with_shader (filter, in_tex, out_tex, shader); return TRUE; }
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 gboolean _draw_checker_background (GstGLVideoMixer * video_mixer) { GstGLMixer *mixer = GST_GL_MIXER (video_mixer); const GstGLFuncs *gl = GST_GL_BASE_MIXER (mixer)->context->gl_vtable; gint attr_position_loc = 0; /* *INDENT-OFF* */ gfloat v_vertices[] = { -1.0,-1.0,-1.0f, 1.0,-1.0,-1.0f, 1.0, 1.0,-1.0f, -1.0, 1.0,-1.0f, }; /* *INDENT-ON* */ if (!video_mixer->checker) { if (!gst_gl_context_gen_shader (GST_GL_BASE_MIXER (mixer)->context, checker_v_src, checker_f_src, &video_mixer->checker)) return FALSE; } gst_gl_shader_use (video_mixer->checker); attr_position_loc = gst_gl_shader_get_attribute_location (video_mixer->checker, "a_position"); _init_vbo_indices (video_mixer); if (!video_mixer->checker_vbo) { gl->GenBuffers (1, &video_mixer->checker_vbo); gl->BindBuffer (GL_ARRAY_BUFFER, video_mixer->checker_vbo); gl->BufferData (GL_ARRAY_BUFFER, 4 * 3 * sizeof (GLfloat), v_vertices, GL_STATIC_DRAW); } else { gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, video_mixer->vbo_indices); gl->BindBuffer (GL_ARRAY_BUFFER, video_mixer->checker_vbo); } gl->VertexAttribPointer (attr_position_loc, 3, GL_FLOAT, GL_FALSE, 3 * sizeof (GLfloat), (void *) 0); gl->EnableVertexAttribArray (attr_position_loc); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); gl->DisableVertexAttribArray (attr_position_loc); gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); gl->BindBuffer (GL_ARRAY_BUFFER, 0); return TRUE; }
static void _test_default_shader_gl (GstGLContext * context, gpointer data) { GstGLShader *shader; GError *error = NULL; shader = gst_gl_shader_new_default (context, &error); fail_unless (shader != NULL); fail_unless (error == NULL); gst_gl_shader_use (shader); gst_gl_context_clear_shader (context); gst_object_unref (shader); }
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); }
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); }
void gst_gl_effects_xray_step_five (gint width, gint height, guint texture, gpointer stuff) { GstGLEffects *effects = GST_GL_EFFECTS (stuff); GstGLShader *shader; shader = g_hash_table_lookup (effects->shaderstable, "xray4"); if (!shader) { shader = gst_gl_shader_new (); 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_display_set_error (GST_GL_FILTER (effects)->display, "Failed to initialize multiply shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, GST_GL_DISPLAY_ERR_MSG (GST_GL_FILTER (effects)->display), (NULL)); return; } glMatrixMode (GL_PROJECTION); glLoadIdentity (); gst_gl_shader_use (shader); glActiveTexture (GL_TEXTURE2); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, effects->midtexture[2]); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (shader, "base", 2); glActiveTexture (GL_TEXTURE1); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1f (shader, "alpha", (gfloat) 0.5f); gst_gl_shader_set_uniform_1i (shader, "blend", 1); gst_gl_effects_draw_texture (effects, texture); }
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; }
static void gst_gl_effects_xray_step_two (gint width, gint height, guint texture, gpointer data) { GstGLEffects *effects = GST_GL_EFFECTS (data); GstGLShader *shader; shader = g_hash_table_lookup (effects->shaderstable, "xray1"); if (!shader) { shader = gst_gl_shader_new (); 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_display_set_error (GST_GL_FILTER (effects)->display, "Failed to initialize hconv7 shader"); GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, GST_GL_DISPLAY_ERR_MSG (GST_GL_FILTER (effects)->display), (NULL)); return; } glMatrixMode (GL_PROJECTION); glLoadIdentity (); gst_gl_shader_use (shader); glActiveTexture (GL_TEXTURE1); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glDisable (GL_TEXTURE_RECTANGLE_ARB); gst_gl_shader_set_uniform_1i (shader, "tex", 1); gst_gl_shader_set_uniform_1fv (shader, "kernel", 9, gauss_kernel); gst_gl_effects_draw_texture (effects, texture); }
static void _test_get_attribute_location_gl (GstGLContext * context, gpointer data) { GstGLShader *shader; GError *error = NULL; gint loc; shader = gst_gl_shader_new_default (context, &error); gst_gl_shader_use (shader); loc = gst_gl_shader_get_attribute_location (shader, "a_position"); fail_unless (loc != -1); loc = gst_gl_shader_get_attribute_location (shader, "a_texcoord"); fail_unless (loc != -1); loc = gst_gl_shader_get_attribute_location (shader, "unused_value_1928374"); fail_unless (loc == -1); gst_object_unref (shader); }
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 draw_render (gpointer data) { GstGLContext *context = data; GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context); const GstGLFuncs *gl = context->gl_vtable; const GLfloat vVertices[] = { 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 }; GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; gl->Clear (GL_COLOR_BUFFER_BIT); gst_gl_shader_use (shader); /* Load the vertex position */ gl->VertexAttribPointer (shader_attr_position_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices); /* Load the texture coordinate */ gl->VertexAttribPointer (shader_attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]); gl->EnableVertexAttribArray (shader_attr_position_loc); gl->EnableVertexAttribArray (shader_attr_texture_loc); gl->ActiveTexture (GL_TEXTURE0); gl->BindTexture (GL_TEXTURE_2D, tex_id); gst_gl_shader_set_uniform_1i (shader, "s_texture", 0); gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); context_class->swap_buffers (context); }
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); }