I think so but I’m not at all confident that it’s working correctly. I’m not good enough at OpenGL to figure out what’s working and what isn’t and it’s made harder due to it running on a Quest 3 headset and any debugging tools seem to be lacking or non existent on Linux.
static gboolean
sync_bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_NEED_CONTEXT:
{
const gchar *context_type;
GstContext *context = NULL;
gst_message_parse_context_type (msg, &context_type);
Logger::logFormat("Got need context %s", context_type);
if (g_strcmp0 (context_type, "gst.gl.app_context") == 0) {
GstGLContext *gl_context = sharedContext;
GstStructure *s;
Logger::log("Setting context...");
context = gst_context_new ("gst.gl.app_context", TRUE);
Logger::log("Made new context");
s = gst_context_writable_structure (context);
Logger::log("Made writable context");
gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, gl_context, NULL);
Logger::log("Set GL context");
gst_element_set_context (GST_ELEMENT (msg->src), context);
Logger::log("Set context");
}
if (context) {
gst_context_unref (context);
}
break;
}
default:
break;
}
return FALSE;
}
I create and activate the context and such in a different function
void GLInit() {
g_unityDisplay = eglGetCurrentDisplay();
g_unityContext = eglGetCurrentContext();
Logger::logFormat("Unity context %p", g_unityContext);
Logger::logFormat("Unity display %p", g_unityDisplay);
GstGLDisplayEGL *display = gst_gl_display_egl_new_with_egl_display(g_unityDisplay);
sharedContext = gst_gl_context_new_wrapped(
GST_GL_DISPLAY_CAST(display),
(guintptr)g_unityContext,
GST_GL_PLATFORM_EGL,
GST_GL_API_GLES2
);
gst_gl_context_activate(sharedContext, TRUE);
GError *error;
if (!gst_gl_context_fill_info (sharedContext, &error)) {
Logger::log("Failed to retrieve context info");
gst_gl_context_activate (sharedContext, FALSE);
return;
}
gst_gl_context_activate (sharedContext, FALSE);
Logger::log("GL has been init successfully.");
}
I have another thread going at Shared context failing to fill info - #3 by bluewave41 relating to my Unity context sharing struggles. I can’t find any good examples of this that work correctly.