static GUBGraphicContext *gub_create_graphic_context_egl(GstPipeline *pipeline, float crop_left, float crop_top, float crop_right, float crop_bottom) { static const GLfloat vVertices[] = { -1.f, -1.f, 0.f, 0.f, -1.f, 1.f, 0.f, 1.f, 1.f, -1.f, 1.f, 0.f, 1.f, 1.f, 1.f, 1.f }; guintptr raw_context; GstStructure *s; GstGLDisplay *display; GstGLContext *gl_context; GUBGraphicContextEGL *gcontext; raw_context = gst_gl_context_get_current_gl_context(GST_GL_PLATFORM_EGL); if (!raw_context) { gub_log("Could not retrieve current EGL context"); return NULL; } display = (GstGLDisplay *)gst_gl_display_egl_new(); gl_context = gst_gl_context_new_wrapped(display, raw_context, GST_GL_PLATFORM_EGL, GST_GL_API_GLES2); gub_log("Current GL context is %p (GSTGL Platform %s GSTGL API %s)", raw_context, gst_gl_platform_to_string(gst_gl_context_get_gl_platform(gl_context)), gst_gl_api_to_string(gst_gl_context_get_gl_api(gl_context))); gub_log("VENDOR: %s", glGetString(GL_VENDOR)); gub_log("RENDERER: %s", glGetString(GL_RENDERER)); gub_log("VERSION: %s", glGetString(GL_VERSION)); gub_log("GLSL VERSION: %s", glGetString(GL_SHADING_LANGUAGE_VERSION)); gcontext = (GUBGraphicContextEGL *)malloc(sizeof(GUBGraphicContextEGL)); gcontext->gl = gl_context; gcontext->display = display; gcontext->crop_left = crop_left; gcontext->crop_top = crop_top; gcontext->crop_right = crop_right; gcontext->crop_bottom = crop_bottom; glGenFramebuffers(1, &gcontext->fbo); if (gl_context->gl_vtable->GenVertexArrays) gl_context->gl_vtable->GenVertexArrays(1, &gcontext->vao); if (gcontext->gl->gl_vtable->BindVertexArray) gcontext->gl->gl_vtable->BindVertexArray(gcontext->vao); glGenBuffers(1, &gcontext->vbo); glBindBuffer(GL_ARRAY_BUFFER, gcontext->vbo); glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(GLfloat), vVertices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); gcontext->po = gub_create_program(); gcontext->samplerLoc = glGetUniformLocation(gcontext->po, "sTexture"); return gcontext; }
/** * gst_gl_display_new: * * Returns: (transfer full): a new #GstGLDisplay * * Since: 1.4 */ GstGLDisplay * gst_gl_display_new (void) { GstGLDisplay *display = NULL; const gchar *user_choice, *platform_choice; static volatile gsize _init = 0; if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0, "gldisplay element"); g_once_init_leave (&_init, 1); } user_choice = g_getenv ("GST_GL_WINDOW"); platform_choice = g_getenv ("GST_GL_PLATFORM"); GST_INFO ("creating a display, user choice:%s (platform: %s)", GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice)); #if GST_GL_HAVE_WINDOW_COCOA if (!display && (!user_choice || g_strstr_len (user_choice, 5, "cocoa"))) { display = GST_GL_DISPLAY (gst_gl_display_cocoa_new ()); if (!display) return NULL; } #endif #if GST_GL_HAVE_WINDOW_X11 if (!display && (!user_choice || g_strstr_len (user_choice, 3, "x11"))) display = GST_GL_DISPLAY (gst_gl_display_x11_new (NULL)); #endif #if GST_GL_HAVE_WINDOW_WAYLAND if (!display && (!user_choice || g_strstr_len (user_choice, 7, "wayland"))) display = GST_GL_DISPLAY (gst_gl_display_wayland_new (NULL)); #endif #if GST_GL_HAVE_PLATFORM_EGL if (!display && (!platform_choice || g_strstr_len (platform_choice, 3, "egl"))) display = GST_GL_DISPLAY (gst_gl_display_egl_new ()); #endif if (!display) { /* subclass returned a NULL window */ GST_WARNING ("Could not create display. user specified %s " "(platform: %s), creating dummy", GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice)); return g_object_new (GST_TYPE_GL_DISPLAY, NULL); } return display; }