/* Called in the gl thread */ static void gst_glimage_sink_thread_init_redisplay (GstGLImageSink * gl_sink) { GError *error = NULL; gl_sink->redisplay_shader = gst_gl_shader_new (gl_sink->context); gst_gl_shader_set_vertex_source (gl_sink->redisplay_shader, redisplay_vertex_shader_str_gles2); gst_gl_shader_set_fragment_source (gl_sink->redisplay_shader, redisplay_fragment_shader_str_gles2); gst_gl_shader_compile (gl_sink->redisplay_shader, &error); if (error) { gst_gl_context_set_error (gl_sink->context, "%s", error->message); g_error_free (error); error = NULL; gst_gl_context_clear_shader (gl_sink->context); } else { gl_sink->redisplay_attr_position_loc = gst_gl_shader_get_attribute_location (gl_sink->redisplay_shader, "a_position"); gl_sink->redisplay_attr_texture_loc = gst_gl_shader_get_attribute_location (gl_sink->redisplay_shader, "a_texCoord"); } }
static void _bind_buffer (GstGLFilterCube * cube_filter) { const GstGLFuncs *gl = GST_GL_BASE_FILTER (cube_filter)->context->gl_vtable; gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, cube_filter->vbo_indices); gl->BindBuffer (GL_ARRAY_BUFFER, cube_filter->vertex_buffer); cube_filter->attr_position = gst_gl_shader_get_attribute_location (cube_filter->shader, "a_position"); cube_filter->attr_texture = gst_gl_shader_get_attribute_location (cube_filter->shader, "a_texcoord"); /* Load the vertex position */ gl->VertexAttribPointer (cube_filter->attr_position, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), (void *) 0); /* Load the texture coordinate */ gl->VertexAttribPointer (cube_filter->attr_texture, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), (void *) (3 * sizeof (GLfloat))); gl->EnableVertexAttribArray (cube_filter->attr_position); gl->EnableVertexAttribArray (cube_filter->attr_texture); }
static void init (gpointer data) { GstGLContext *context = data; /* has to be called in the thread that is going to use the framebuffer */ fbo = gst_gl_framebuffer_new (context); gst_gl_framebuffer_generate (fbo, 320, 240, &fbo_id, &rbo); fail_if (fbo == NULL || fbo_id == 0, "failed to create framebuffer object"); gst_gl_context_gen_texture (context, &tex, GST_VIDEO_FORMAT_RGBA, 320, 240); fail_if (tex == 0, "failed to create texture"); #if GST_GL_HAVE_GLES2 if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) { shader = gst_gl_shader_new (context); fail_if (shader == NULL, "failed to create shader object"); gst_gl_shader_set_vertex_source (shader, vertex_shader_str_gles2); gst_gl_shader_set_fragment_source (shader, fragment_shader_str_gles2); error = NULL; gst_gl_shader_compile (shader, &error); fail_if (error != NULL, "Error compiling shader %s\n", error ? error->message : "Unknown Error"); shader_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); shader_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texCoord"); } #endif }
static void gst_gl_overlay_compositor_init_gl (GstGLContext * context, gpointer compositor_pointer) { GstGLOverlayCompositor *compositor = (GstGLOverlayCompositor *) compositor_pointer; GError *error = NULL; if (!(compositor->shader = gst_gl_shader_new_link_with_stages (context, &error, gst_glsl_stage_new_default_vertex (context), gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, fragment_shader), NULL))) { GST_ERROR_OBJECT (compositor, "could not initialize shader: %s", error->message); return; } compositor->position_attrib = gst_gl_shader_get_attribute_location (compositor->shader, "a_position"); compositor->texcoord_attrib = gst_gl_shader_get_attribute_location (compositor->shader, "a_texcoord"); }
static GstGLShader * gst_gl_deinterlace_get_fragment_shader (GstGLFilter * filter, const gchar * shader_name, const gchar * shader_source) { GstGLShader *shader = NULL; GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter); GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; shader = g_hash_table_lookup (deinterlace_filter->shaderstable, shader_name); if (!shader) { GError *error = NULL; if (!(shader = gst_gl_shader_new_link_with_stages (context, &error, gst_glsl_stage_new_default_vertex (context), gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, shader_source), NULL))) { GST_ELEMENT_ERROR (deinterlace_filter, RESOURCE, NOT_FOUND, ("Failed to initialize %s shader", shader_name), (NULL)); } 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"); } g_hash_table_insert (deinterlace_filter->shaderstable, (gchar *) shader_name, shader); return shader; }
static void init (gpointer data) { GError *error = NULL; shader = gst_gl_shader_new_default (context, &error); fail_if (shader == NULL, "failed to create shader object %s", error->message); shader_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); shader_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texCoord"); }
static void _bind_buffer (struct SrcShader *src) { GstGLContext *context = src->base.context; const GstGLFuncs *gl = context->gl_vtable; gint i; gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, src->vbo_indices); gl->BindBuffer (GL_ARRAY_BUFFER, src->vbo); /* Load the vertex position */ for (i = 0; i < src->n_attributes; i++) { struct attribute *attr = &src->attributes[i]; if (attr->location == -1) attr->location = gst_gl_shader_get_attribute_location (src->shader, attr->name); gl->VertexAttribPointer (attr->location, attr->n_elements, attr->element_type, GL_FALSE, attr->stride, (void *) (gintptr) attr->offset); gl->EnableVertexAttribArray (attr->location); } }
static gboolean _create_shader (GstGLAlpha * alpha) { GstGLBaseFilter *base_filter = GST_GL_BASE_FILTER (alpha); GstGLFilter *filter = GST_GL_FILTER (alpha); GError *error = NULL; if (alpha->alpha_shader) gst_object_unref (alpha->alpha_shader); if (!(alpha->alpha_shader = gst_gl_shader_new_link_with_stages (base_filter->context, &error, gst_glsl_stage_new_default_vertex (base_filter->context), gst_glsl_stage_new_with_string (base_filter->context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, alpha_frag), NULL))) { GST_ELEMENT_ERROR (alpha, RESOURCE, NOT_FOUND, ("%s", "Failed to initialize alpha shader"), ("%s", error ? error->message : "Unknown error")); return FALSE; } if (alpha->chroma_key_shader) gst_object_unref (alpha->chroma_key_shader); if (!(alpha->chroma_key_shader = gst_gl_shader_new_link_with_stages (base_filter->context, &error, gst_glsl_stage_new_default_vertex (base_filter->context), gst_glsl_stage_new_with_string (base_filter->context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, chroma_key_frag), NULL))) { GST_ELEMENT_ERROR (alpha, RESOURCE, NOT_FOUND, ("%s", "Failed to initialize chroma key shader"), ("%s", error ? error->message : "Unknown error")); return FALSE; } filter->draw_attr_position_loc = gst_gl_shader_get_attribute_location (alpha->alpha_shader, "a_position"); filter->draw_attr_texture_loc = gst_gl_shader_get_attribute_location (alpha->alpha_shader, "a_texcoord"); return TRUE; }
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 _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 init (gpointer data) { GstGLContext *context = data; GError *error = NULL; GstVideoInfo v_info; GstGLMemoryAllocator *allocator; GstGLVideoAllocationParams *params; gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, 320, 240); allocator = gst_gl_memory_allocator_get_default (context); params = gst_gl_video_allocation_params_new (context, NULL, &v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, GST_GL_RGBA); /* has to be called in the thread that is going to use the framebuffer */ fbo = gst_gl_framebuffer_new_with_default_depth (context, 320, 240); fail_if (fbo == NULL, "failed to create framebuffer object"); gl_tex = (GstGLMemory *) gst_gl_base_memory_alloc ((GstGLBaseMemoryAllocator *) allocator, (GstGLAllocationParams *) params); gl_tex2 = (GstGLMemory *) gst_gl_base_memory_alloc ((GstGLBaseMemoryAllocator *) allocator, (GstGLAllocationParams *) params); gst_object_unref (allocator); gst_gl_allocation_params_free ((GstGLAllocationParams *) params); fail_if (gl_tex == NULL, "failed to create texture"); shader = gst_gl_shader_new_default (context, &error); fail_if (shader == NULL, "failed to create shader object: %s", error->message); shader_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); shader_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texcoord"); }
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 init (gpointer data) { const GstGLFuncs *gl = context->gl_vtable; GError *error = NULL; shader = gst_gl_shader_new_default (context, &error); fail_if (shader == NULL, "failed to create shader object %s", error->message); shader_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); shader_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texcoord"); if (!vbo) { if (gl->GenVertexArrays) { gl->GenVertexArrays (1, &vao); gl->BindVertexArray (vao); } gl->GenBuffers (1, &vbo); gl->BindBuffer (GL_ARRAY_BUFFER, vbo); gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices, GL_STATIC_DRAW); gl->GenBuffers (1, &vbo_indices); gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, vbo_indices); gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices, GL_STATIC_DRAW); if (gl->GenVertexArrays) { _bind_buffer (context); gl->BindVertexArray (0); } gl->BindBuffer (GL_ARRAY_BUFFER, 0); gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); } }
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 init (gpointer data) { #if GST_GL_HAVE_GLES2 if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) { shader = gst_gl_shader_new (context); fail_if (shader == NULL, "failed to create shader object"); gst_gl_shader_set_vertex_source (shader, vertex_shader_str_gles2); gst_gl_shader_set_fragment_source (shader, fragment_shader_str_gles2); error = NULL; gst_gl_shader_compile (shader, &error); fail_if (error != NULL, "Error compiling shader %s\n", error ? error->message : "Unknown Error"); shader_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); shader_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texCoord"); } #endif }
static gboolean gst_gl_colorscale_gl_start (GstGLBaseFilter * base_filter) { GstGLColorscale *colorscale = GST_GL_COLORSCALE (base_filter); GstGLFilter *filter = GST_GL_FILTER (base_filter); GstGLShader *shader; GError *error = NULL; if (!(shader = gst_gl_shader_new_default (base_filter->context, &error))) { GST_ERROR_OBJECT (colorscale, "Failed to initialize shader: %s", error->message); gst_object_unref (shader); return FALSE; } 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"); colorscale->shader = shader; return GST_GL_BASE_FILTER_CLASS (parent_class)->gl_start (base_filter); }
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 _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; }
/* 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); }
static void gst_gl_transformation_callback (gpointer stuff) { GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLTransformation *transformation = GST_GL_TRANSFORMATION (filter); GstGLFuncs *gl = filter->context->gl_vtable; /* *INDENT-OFF* */ const GLfloat positions[] = { -transformation->aspect, 1.0, 0.0, 1.0, transformation->aspect, 1.0, 0.0, 1.0, transformation->aspect, -1.0, 0.0, 1.0, -transformation->aspect, -1.0, 0.0, 1.0, }; const GLfloat texture_coordinates[] = { 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, }; /* *INDENT-ON* */ GLushort indices[] = { 0, 1, 2, 3, 0 }; GLfloat temp_matrix[16]; GLint attr_position_loc = 0; GLint attr_texture_loc = 0; gst_gl_context_clear_shader (filter->context); gl->BindTexture (GL_TEXTURE_2D, 0); gl->ClearColor (0.f, 0.f, 0.f, 0.f); gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gst_gl_shader_use (transformation->shader); attr_position_loc = gst_gl_shader_get_attribute_location (transformation->shader, "position"); attr_texture_loc = gst_gl_shader_get_attribute_location (transformation->shader, "uv"); /* Load the vertex position */ gl->VertexAttribPointer (attr_position_loc, 4, GL_FLOAT, GL_FALSE, 0, positions); /* Load the texture coordinate */ gl->VertexAttribPointer (attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 0, texture_coordinates); gl->EnableVertexAttribArray (attr_position_loc); gl->EnableVertexAttribArray (attr_texture_loc); 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); gl->DrawElements (GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, indices); gl->DisableVertexAttribArray (attr_position_loc); gl->DisableVertexAttribArray (attr_texture_loc); gst_gl_context_clear_shader (filter->context); }
//opengl scene, params: input texture (not the output filter->texture) static void gst_gl_filter_cube_callback (gint width, gint height, guint texture, gpointer stuff) { GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (stuff); static GLfloat xrot = 0; static GLfloat yrot = 0; static GLfloat zrot = 0; #ifndef OPENGL_ES2 glEnable (GL_DEPTH_TEST); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef (0.0f, 0.0f, -5.0f); glRotatef (xrot, 1.0f, 0.0f, 0.0f); glRotatef (yrot, 0.0f, 1.0f, 0.0f); glRotatef (zrot, 0.0f, 0.0f, 1.0f); glBegin (GL_QUADS); // Front Face glTexCoord2f ((gfloat) width, 0.0f); glVertex3f (-1.0f, -1.0f, 1.0f); glTexCoord2f (0.0f, 0.0f); glVertex3f (1.0f, -1.0f, 1.0f); glTexCoord2f (0.0f, (gfloat) height); glVertex3f (1.0f, 1.0f, 1.0f); glTexCoord2f ((gfloat) width, (gfloat) height); glVertex3f (-1.0f, 1.0f, 1.0f); // Back Face glTexCoord2f (0.0f, 0.0f); glVertex3f (-1.0f, -1.0f, -1.0f); glTexCoord2f (0.0f, (gfloat) height); glVertex3f (-1.0f, 1.0f, -1.0f); glTexCoord2f ((gfloat) width, (gfloat) height); glVertex3f (1.0f, 1.0f, -1.0f); glTexCoord2f ((gfloat) width, 0.0f); glVertex3f (1.0f, -1.0f, -1.0f); // Top Face glTexCoord2f ((gfloat) width, (gfloat) height); glVertex3f (-1.0f, 1.0f, -1.0f); glTexCoord2f ((gfloat) width, 0.0f); glVertex3f (-1.0f, 1.0f, 1.0f); glTexCoord2f (0.0f, 0.0f); glVertex3f (1.0f, 1.0f, 1.0f); glTexCoord2f (0.0f, (gfloat) height); glVertex3f (1.0f, 1.0f, -1.0f); // Bottom Face glTexCoord2f ((gfloat) width, 0.0f); glVertex3f (-1.0f, -1.0f, -1.0f); glTexCoord2f (0.0f, 0.0f); glVertex3f (1.0f, -1.0f, -1.0f); glTexCoord2f (0.0f, (gfloat) height); glVertex3f (1.0f, -1.0f, 1.0f); glTexCoord2f ((gfloat) width, (gfloat) height); glVertex3f (-1.0f, -1.0f, 1.0f); // Right face glTexCoord2f (0.0f, 0.0f); glVertex3f (1.0f, -1.0f, -1.0f); glTexCoord2f (0.0f, (gfloat) height); glVertex3f (1.0f, 1.0f, -1.0f); glTexCoord2f ((gfloat) width, (gfloat) height); glVertex3f (1.0f, 1.0f, 1.0f); glTexCoord2f ((gfloat) width, 0.0f); glVertex3f (1.0f, -1.0f, 1.0f); // Left Face glTexCoord2f ((gfloat) width, 0.0f); glVertex3f (-1.0f, -1.0f, -1.0f); glTexCoord2f (0.0f, 0.0f); glVertex3f (-1.0f, -1.0f, 1.0f); glTexCoord2f (0.0f, (gfloat) height); glVertex3f (-1.0f, 1.0f, 1.0f); glTexCoord2f ((gfloat) width, (gfloat) height); glVertex3f (-1.0f, 1.0f, -1.0f); glEnd (); #else const GLfloat 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, //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, //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 }; 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 }; glEnable (GL_DEPTH_TEST); glClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0); glClear (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 glVertexAttribPointer (attr_position_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), v_vertices); //Load the texture coordinate glVertexAttribPointer (attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[3]); glEnableVertexAttribArray (attr_position_loc); glEnableVertexAttribArray (attr_texture_loc); glActiveTexture (GL_TEXTURE0); glBindTexture (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); glDrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices); glDisableVertexAttribArray (attr_position_loc); glDisableVertexAttribArray (attr_texture_loc); #endif glDisable (GL_DEPTH_TEST); xrot += 0.3f; yrot += 0.2f; zrot += 0.4f; }
/* Called in the gl thread */ static gboolean _init_convert (GstGLColorConvert * convert) { GstGLFuncs *gl; gboolean res; struct ConvertInfo *info = &convert->priv->convert_info; gint i; gl = convert->context->gl_vtable; if (convert->initted) return TRUE; GST_INFO ("Initializing color conversion from %s to %s", gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&convert->in_info)), gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&convert->out_info))); if (!gl->CreateProgramObject && !gl->CreateProgram) { gst_gl_context_set_error (convert->context, "Cannot perform color conversion without OpenGL shaders"); goto error; } if (GST_VIDEO_INFO_IS_RGB (&convert->in_info)) { if (GST_VIDEO_INFO_IS_RGB (&convert->out_info)) { _RGB_to_RGB (convert); } } if (GST_VIDEO_INFO_IS_YUV (&convert->in_info)) { if (GST_VIDEO_INFO_IS_RGB (&convert->out_info)) { _YUV_to_RGB (convert); } } if (GST_VIDEO_INFO_IS_RGB (&convert->in_info)) { if (GST_VIDEO_INFO_IS_YUV (&convert->out_info)) { _RGB_to_YUV (convert); } } if (GST_VIDEO_INFO_IS_RGB (&convert->in_info)) { if (GST_VIDEO_INFO_IS_GRAY (&convert->out_info)) { _RGB_to_GRAY (convert); } } if (GST_VIDEO_INFO_IS_GRAY (&convert->in_info)) { if (GST_VIDEO_INFO_IS_RGB (&convert->out_info)) { _GRAY_to_RGB (convert); } } if (!info->frag_prog || info->in_n_textures == 0 || info->out_n_textures == 0) goto unhandled_format; /* multiple draw targets not supported on GLES2...yet */ if (info->out_n_textures > 1 && (!gl->DrawBuffers || USING_GLES2 (convert->context))) { g_free (info->frag_prog); GST_ERROR ("Conversion requires output to multiple draw buffers"); goto incompatible_api; } /* Requires reading from a RG/LA framebuffer... */ if (USING_GLES2 (convert->context) && (GST_VIDEO_INFO_FORMAT (&convert->out_info) == GST_VIDEO_FORMAT_YUY2 || GST_VIDEO_INFO_FORMAT (&convert->out_info) == GST_VIDEO_FORMAT_UYVY)) { g_free (info->frag_prog); GST_ERROR ("Conversion requires reading with an unsupported format"); goto incompatible_api; } res = gst_gl_context_gen_shader (convert->context, text_vertex_shader, info->frag_prog, &convert->shader); g_free (info->frag_prog); if (!res) goto error; convert->shader_attr_position_loc = gst_gl_shader_get_attribute_location (convert->shader, "a_position"); convert->shader_attr_texture_loc = gst_gl_shader_get_attribute_location (convert->shader, "a_texcoord"); gst_gl_shader_use (convert->shader); if (info->cms_offset && info->cms_coeff1 && info->cms_coeff2 && info->cms_coeff3) { gst_gl_shader_set_uniform_3fv (convert->shader, "offset", 1, info->cms_offset); gst_gl_shader_set_uniform_3fv (convert->shader, "coeff1", 1, info->cms_coeff1); gst_gl_shader_set_uniform_3fv (convert->shader, "coeff2", 1, info->cms_coeff2); gst_gl_shader_set_uniform_3fv (convert->shader, "coeff3", 1, info->cms_coeff3); } for (i = info->in_n_textures; i >= 0; i--) { if (info->shader_tex_names[i]) gst_gl_shader_set_uniform_1i (convert->shader, info->shader_tex_names[i], i); } gst_gl_shader_set_uniform_1f (convert->shader, "width", GST_VIDEO_INFO_WIDTH (&convert->in_info)); gst_gl_shader_set_uniform_1f (convert->shader, "height", GST_VIDEO_INFO_HEIGHT (&convert->in_info)); if (info->chroma_sampling[0] > 0.0f && info->chroma_sampling[1] > 0.0f) { gst_gl_shader_set_uniform_2fv (convert->shader, "chroma_sampling", 1, info->chroma_sampling); } gst_gl_context_clear_shader (convert->context); if (!_init_convert_fbo (convert)) { goto error; } gl->BindTexture (GL_TEXTURE_2D, 0); convert->initted = TRUE; return TRUE; unhandled_format: gst_gl_context_set_error (convert->context, "Don't know how to convert from %s to %s", gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&convert->in_info)), gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&convert->out_info))); error: return FALSE; incompatible_api: { gst_gl_context_set_error (convert->context, "Converting from %s to %s requires " "functionality that the current OpenGL setup does not support", gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&convert->in_info)), gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&convert->out_info))); return FALSE; } }
/* 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 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 mixer->texture) static void gst_gl_mosaic_callback (gpointer stuff) { GstGLMosaic *mosaic = GST_GL_MOSAIC (stuff); 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; gboolean do_next = TRUE; gst_gl_shader_use (NULL); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0); glDisable (GL_TEXTURE_RECTANGLE_ARB); glEnable (GL_DEPTH_TEST); glClearColor (0.0, 0.0, 0.0, 0.0); glClear (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"); while (do_next && count < mosaic->input_gl_buffers->len && count < 6) { GstGLBuffer *gl_in_buffer = g_ptr_array_index (mosaic->input_gl_buffers, count); if (gl_in_buffer && gl_in_buffer->texture) { GLuint texture = gl_in_buffer->texture; GLfloat width = (GLfloat) gl_in_buffer->width; GLfloat height = (GLfloat) gl_in_buffer->height; const GLfloat v_vertices[] = { //front face 1.0f, 1.0f, -1.0f, width, 0.0f, 1.0f, -1.0f, -1.0f, width, height, -1.0f, -1.0f, -1.0f, 0.0f, height, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, //right face 1.0f, 1.0f, 1.0f, width, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, height, 1.0f, 1.0f, -1.0f, width, height, //left face -1.0f, 1.0f, 1.0f, width, 0.0f, -1.0f, 1.0f, -1.0f, width, height, -1.0f, -1.0f, -1.0f, 0.0f, height, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, //top face 1.0f, -1.0f, 1.0f, width, 0.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, -1.0f, -1.0f, -1.0f, 0.0f, height, 1.0f, -1.0f, -1.0f, width, height, //bottom face 1.0f, 1.0f, 1.0f, width, 0.0f, 1.0f, 1.0f, -1.0f, width, height, -1.0f, 1.0f, -1.0f, 0.0f, height, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, //back face 1.0f, 1.0f, 1.0f, width, 0.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f, -1.0f, 1.0f, 0.0f, height, 1.0f, -1.0f, 1.0f, width, height }; glVertexAttribPointerARB (attr_position_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count]); glVertexAttribPointerARB (attr_texture_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count + 3]); glEnableVertexAttribArrayARB (attr_position_loc); glEnableVertexAttribArrayARB (attr_texture_loc); glActiveTextureARB (GL_TEXTURE0_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); 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); glDrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); ++count; } else { do_next = FALSE; } } glDisableVertexAttribArrayARB (attr_position_loc); glDisableVertexAttribArrayARB (attr_texture_loc); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0); glDisable (GL_DEPTH_TEST); gst_gl_shader_use (NULL); xrot += 0.6f; yrot += 0.4f; zrot += 0.8f; }
void gst_gl_test_src_shader (GstGLTestSrc * v, GstBuffer * buffer, int w, int h) { GstGLFuncs *gl = v->context->gl_vtable; /* *INDENT-OFF* */ const GLfloat positions[] = { -1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, -1.0, 0.0, 1.0, -1.0, -1.0, 0.0, 1.0, }; const GLfloat identitiy_matrix[] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, }; const GLfloat uvs[] = { 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, }; /* *INDENT-ON* */ GLushort indices[] = { 0, 1, 2, 3, 0 }; GLint attr_position_loc = 0; GLint attr_uv_loc = 0; if (gst_gl_context_get_gl_api (v->context)) { gst_gl_context_clear_shader (v->context); gl->BindTexture (GL_TEXTURE_2D, 0); gl->Disable (GL_TEXTURE_2D); gst_gl_shader_use (v->shader); attr_position_loc = gst_gl_shader_get_attribute_location (v->shader, "position"); attr_uv_loc = gst_gl_shader_get_attribute_location (v->shader, "uv"); /* Load the vertex position */ gl->VertexAttribPointer (attr_position_loc, 4, GL_FLOAT, GL_FALSE, 0, positions); /* Load the texture coordinate */ gl->VertexAttribPointer (attr_uv_loc, 2, GL_FLOAT, GL_FALSE, 0, uvs); gl->EnableVertexAttribArray (attr_position_loc); gl->EnableVertexAttribArray (attr_uv_loc); gst_gl_shader_set_uniform_matrix_4fv (v->shader, "mvp", 1, GL_FALSE, identitiy_matrix); gst_gl_shader_set_uniform_1f (v->shader, "time", (gfloat) v->running_time / GST_SECOND); gst_gl_shader_set_uniform_1f (v->shader, "aspect_ratio", (gfloat) w / (gfloat) h); gl->DrawElements (GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, indices); gl->DisableVertexAttribArray (attr_position_loc); gl->DisableVertexAttribArray (attr_uv_loc); gst_gl_context_clear_shader (v->context); } }
//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; GstGLBumper *bumper = GST_GL_BUMPER (stuff); 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 }; //eye point glMatrixMode (GL_PROJECTION); gluLookAt (0.0, 0.0, -6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glMatrixMode (GL_MODELVIEW); //scene conf glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL); glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glShadeModel (GL_SMOOTH); //set the lights glLightfv (GL_LIGHT0, GL_POSITION, light_direction0); glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse0); glLightfv (GL_LIGHT1, GL_POSITION, light_direction1); glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse1); glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_LIGHT1); //configure shader gst_gl_shader_use (bumper->shader); locTangent = gst_gl_shader_get_attribute_location (bumper->shader, "aTangent"); //set the normal map glActiveTextureARB (GL_TEXTURE1_ARB); gst_gl_shader_set_uniform_1i (bumper->shader, "texture1", 1); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, bumper->bumpmap); //set the video texture glActiveTextureARB (GL_TEXTURE0_ARB); gst_gl_shader_set_uniform_1i (bumper->shader, "texture0", 0); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); //glTranslatef(2.0f, 2.0f, 5.0f); glRotatef (xrot, 1.0f, 0.0f, 0.0f); glRotatef (yrot, 0.0f, 1.0f, 0.0f); glRotatef (zrot, 0.0f, 0.0f, 1.0f); //Cube glBegin (GL_QUADS); // front face glNormal3d (0.0, 0.0, -1.0); glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3d (1.0, 1.0, -1.0); // B glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height); glVertex3d (1.0, -1.0, -1.0); // A glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height); glVertex3d (-1.0, -1.0, -1.0); // D glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0); glVertex3d (-1.0, 1.0, -1.0); // C // right face glNormal3d (-1.0, 0.0, 0.0); glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3d (-1.0, 1.0, -1.0); // C glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height); glVertex3d (-1.0, -1.0, -1.0); // D glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height); glVertex3d (-1.0, -1.0, 1.0); // H glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0); glVertex3d (-1.0, 1.0, 1.0); // G // back face glNormal3d (0.0, 0.0, 1.0); glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3d (-1.0, 1.0, 1.0); // G glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height); glVertex3d (-1.0, -1.0, 1.0); // H glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height); glVertex3d (1.0, -1.0, 1.0); // E glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0); glVertex3d (1.0, 1.0, 1.0); // F // left face glNormal3d (1.0, 0.0, 0.0); glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3d (1.0, 1.0, 1.0); // F glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height); glVertex3d (1.0, -1.0, 1.0); // E glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height); glVertex3d (1.0, -1.0, -1.0); // A glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0); glVertex3d (1.0, 1.0, -1.0); // B // top face glNormal3d (0.0, 1.0, 0.0); glVertexAttrib3dARB (locTangent, 0.0, 0.0, 1.0); glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3d (1.0, 1.0, 1.0); // F glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height); glVertex3d (1.0, 1.0, -1.0); // B glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height); glVertex3d (-1.0, 1.0, -1.0); // C glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0); glVertex3d (-1.0, 1.0, 1.0); // G // bottom face glNormal3d (0.0, -1.0, 0.0); glVertexAttrib3dARB (locTangent, 0.0, 0.0, -1.0); glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3d (1.0, -1.0, -1.0); // A glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height); glVertex3d (1.0, -1.0, 1.0); // E glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height); glVertex3d (-1.0, -1.0, 1.0); // H glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0); glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0); glVertex3d (-1.0, -1.0, -1.0); // D glEnd (); glUseProgram (0); glDisable (GL_LIGHT0); glDisable (GL_LIGHT1); glDisable (GL_LIGHTING); glDisable (GL_COLOR_MATERIAL); xrot += 1.0f; yrot += 0.9f; zrot += 1.1f; }
/* init resources that need a gl context */ static void gst_gl_differencematte_init_gl_resources (GstGLFilter * filter) { GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter); GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; const GstGLFuncs *gl = context->gl_vtable; GError *error = NULL; gint i; for (i = 0; i < 4; i++) { gl->GenTextures (1, &differencematte->midtexture[i]); gl->BindTexture (GL_TEXTURE_2D, differencematte->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); } if (!(differencematte->identity_shader = gst_gl_shader_new_default (context, &error))) { GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s", "Failed to compile identity shader"), ("%s", error->message)); return; } if (!(differencematte->shader[0] = gst_gl_shader_new_link_with_stages (context, &error, gst_glsl_stage_new_default_vertex (context), gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, difference_fragment_source), NULL))) { GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s", "Failed to compile difference shader"), ("%s", error->message)); return; } if (!(differencematte->shader[1] = gst_gl_shader_new_link_with_stages (context, &error, gst_glsl_stage_new_default_vertex (context), gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, hconv7_fragment_source_gles2), NULL))) { GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s", "Failed to compile convolution shader"), ("%s", error->message)); return; } if (!(differencematte->shader[2] = gst_gl_shader_new_link_with_stages (context, &error, gst_glsl_stage_new_default_vertex (context), gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, vconv7_fragment_source_gles2), NULL))) { GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s", "Failed to compile convolution shader"), ("%s", error->message)); return; } if (!(differencematte->shader[3] = gst_gl_shader_new_link_with_stages (context, &error, gst_glsl_stage_new_default_vertex (context), gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE, GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, texture_interp_fragment_source), NULL))) { GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s", "Failed to compile interpolation shader"), ("%s", error->message)); return; } /* FIXME: this should really be per shader */ filter->draw_attr_position_loc = gst_gl_shader_get_attribute_location (differencematte->shader[2], "a_position"); filter->draw_attr_texture_loc = gst_gl_shader_get_attribute_location (differencematte->shader[2], "a_texcoord"); }
//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; }