We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4314

Summary: Getting Display Handle
Product: SDL Reporter: Martin Gerhardy <martin.gerhardy>
Component: videoAssignee: Martin Gerhardy <martin.gerhardy>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: Small testcase (not written by me) for the CL/GL sharing

Description Martin Gerhardy 2018-10-14 09:13:15 UTC
I'm having trouble setting up the OpenCL OpenGL sharing context. When doing the init of the OpenCL context, you have to specify the display and the context handle. The context should not be a problem - we could just use SDL_GL_GetCurrentContext (which hopefully directly maps to glXGetCurrentContext or eglGetCurrentContext) - but OpenCL also needs to get the display handle and here it gets ... tricky. For windows this is wglGetCurrentDC and for linux it is glXGetCurrentDisplay - or eglGetCurrentDisplay if you are using EGL. To be honest, I don't know a way to check at runtime whether my context is egl or glx/wgl - I could only check this at compile time afair.

Therefore it would be nice if we could also get something similar as SDL_GL_GetCurrentContext for the display. E.g. SDL_GL_GetCurrentDisplay(SDLWindow* window)
Comment 1 Martin Gerhardy 2018-10-14 09:16:37 UTC
Created attachment 3373 [details]
Small testcase (not written by me) for the CL/GL sharing

Attached a small glx example where the CL sharing works with glfw and glx

And this is the OpenCL extension I'm talking about:
https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/cl_khr_gl_sharing.html
Comment 2 Martin Gerhardy 2018-10-14 09:46:39 UTC
And the last thing - We also need to know which type of handle it is. Is it glx, egl, wgl, ...? this is due to the fact that OpenCL must know this, too. 


https://github.com/mgerhardy/engine/blob/master/src/modules/computevideo/cl/CLComputeVideo.cpp

CL_WGL_HDC_KHR
CL_GLX_DISPLAY_KHR
CL_EGL_DISPLAY_KHR

CL_CGL_SHAREGROUP_KHR for CGL is quite easy I suppose.
CL_GL_CONTEXT_KHR is for the gl context.
Comment 3 Sam Lantinga 2018-11-03 00:13:02 UTC
Would you like to propose an API change for this?
Comment 4 Martin Gerhardy 2018-11-08 07:54:33 UTC
What do you think about this?

/**
 *  \brief Get the display of the given window
 *
 *  \param window   Window from which the display should be queried
 */
extern DECLSPEC SDL_GLDisplay SDLCALL SDL_GL_GetDisplay(SDL_Window * window);

If nobody votes against this, I would implement it.
Comment 5 Sam Lantinga 2018-11-13 00:39:47 UTC
That sounds reasonable. Let's call it SDL_GL_GetCurrentDisplay() to match the naming from the platform extensions.

Thanks!