examples/sdlshare: Activate and initialize our wrapped GL context

This allows us to e.g. use the GL functions vtable on it later.
This commit is contained in:
Sebastian Dröge 2019-03-13 08:20:57 +01:00
parent 9000bc86df
commit 0bcba6a3ec
2 changed files with 25 additions and 13 deletions

View file

@ -302,8 +302,8 @@ main (int argc, char **argv)
GstPipeline *pipeline = NULL;
GstBus *bus = NULL;
GstElement *appsink = NULL;
GstState state;
const gchar *platform;
GError *err = NULL;
/* Initialize SDL for video output */
if (SDL_Init (SDL_INIT_VIDEO) < 0) {
@ -350,12 +350,22 @@ main (int argc, char **argv)
sdl_gl_display =
(GstGLDisplay *) gst_gl_display_x11_new_with_display (sdl_display);
#endif
SDL_GL_MakeCurrent (sdl_window, NULL);
sdl_context =
gst_gl_context_new_wrapped (sdl_gl_display, (guintptr) gl_context,
gst_gl_platform_from_string (platform), GST_GL_API_OPENGL);
gst_gl_context_activate (sdl_context, TRUE);
if (!gst_gl_context_fill_info (sdl_context, &err)) {
fprintf (stderr, "Failed to fill in wrapped GStreamer context: %s\n",
err->message);
g_clear_error (&err);
SDL_Quit ();
return -1;
}
SDL_GL_MakeCurrent (sdl_window, NULL);
pipeline =
GST_PIPELINE (gst_parse_launch
("videotestsrc ! glupload ! gleffects effect=5 ! "
@ -367,16 +377,6 @@ main (int argc, char **argv)
gst_bus_enable_sync_message_emission (bus);
g_signal_connect (bus, "sync-message", G_CALLBACK (sync_bus_call), NULL);
/* NULL to PAUSED state pipeline to make sure the gst opengl context is created and
* shared with the sdl one */
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
state = GST_STATE_PAUSED;
if (gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) {
g_debug ("failed to pause pipeline\n");
return -1;
}
queue_input_buf = g_async_queue_new ();
queue_output_buf = g_async_queue_new ();
@ -395,6 +395,7 @@ main (int argc, char **argv)
gst_object_unref (bus);
gst_gl_context_activate (sdl_context, FALSE);
gst_object_unref (sdl_context);
gst_object_unref (sdl_gl_display);

View file

@ -304,6 +304,7 @@ main (int argc, char **argv)
GstBus *bus = NULL;
GstElement *glimagesink = NULL;
const gchar *platform;
GError *err = NULL;
/* Initialize SDL for video output */
if (SDL_Init (SDL_INIT_VIDEO) < 0) {
@ -353,12 +354,21 @@ main (int argc, char **argv)
sdl_gl_display =
(GstGLDisplay *) gst_gl_display_x11_new_with_display (sdl_display);
#endif
SDL_GL_MakeCurrent (sdl_window, NULL);
sdl_context =
gst_gl_context_new_wrapped (sdl_gl_display, (guintptr) gl_context,
gst_gl_platform_from_string (platform), GST_GL_API_OPENGL);
gst_gl_context_activate (sdl_context, TRUE);
if (!gst_gl_context_fill_info (sdl_context, &err)) {
fprintf (stderr, "Failed to fill in wrapped GStreamer context: %s\n",
err->message);
g_clear_error (&err);
SDL_Quit ();
return -1;
}
pipeline =
GST_PIPELINE (gst_parse_launch
("videotestsrc ! video/x-raw, width=320, height=240, framerate=(fraction)30/1 ! "
@ -393,6 +403,7 @@ main (int argc, char **argv)
gst_bus_remove_signal_watch (bus);
gst_object_unref (bus);
gst_gl_context_activate (sdl_context, FALSE);
gst_object_unref (sdl_context);
gst_object_unref (sdl_gl_display);