get HDC device context for OpenGL/OpenCL shared context
I'm following this guide for OpenGL/OpenCL interop: Intel CL/GL interop tutorial
It says there I can use the function clGetGLContextInfoKHR to find the device currently associated with my OpenGL context. The function requires a list of parameters containing the OpenCL platform, the OpenGL context, and the device context (HDC) used to create the OpenGL context.
After googling it, I found thread that gives a method to get the HDC for an SDL window: thread They suggest using this code:
#ifdef _WIN32
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if ( SDL_GetWMInfo(&info) < 0 )
fail();
hwnd = info.window;
#endif
First off, it looks like it only works for Win32. Will it work for 64-bit Windows? And is there a way to do the same thing on Linux/OSX?
Second, when I compile it with MinGW-w64, I get an error "unknown type name 'SDL_SysWMinfo'". SDL_SysWMinfo can be found in the official docs, and I have the latest SDL version, so it should work. I'm guessing that type definition isn't in my SDL.h header file- is there another header file I need?
The most portable and framework agnostic method is to use the platform specific WSI functions to query the drawable and OpenGL context. Using a few typedefs you can make portable wrappers which you can then use to query the context and drawable.
#if defined(_WIN32)
typedef HGLRC GLContext;
typedef HDC GLDrawable;
typedef HWND GLWindow;
GLContext getCurrentGLContext(void) { return wglGetCurrentContext(); }
GLDrawable getCurrentGLDrawable(void) { return wglGetCurrentDC(); }
GLWindow getCurrentGLWindow(void) { return WindowFromDC(wglGetCurrentDC()); }
#elif defined(__unix__)
/* FIXME: consider Wayland or a EGL environment */
typedef GLXContext GLContext;
typedef GLXDrawable GLDrawable;
typedef Window GLWindow;
GLContext getCurrentGLContext(void) { return glXGetCurrentContext(); }
GLDrawable getCurrentGLDrawable(void) { return glXGetCurrentDrawable(); }
GLWindow getCurrentGLWindow(void) { return glXGetCurrentDrawable(); }
#elif __APPLE__
/* FIXME: Implement this for MacOS X
#endif
Use them while the SDL window is current, so that the OpenGL context is active and query it using those wrappers. You may notice that in the GLX version getCurrentGLDrawable and getCurrentGLWindow return the same thing. That is, because X11 makes no distinction between windows and drawables.
链接地址: http://www.djcxy.com/p/38462.html