SDL-mirror/src/video/windows
Sam Lantinga a09aac7720 Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
The reasoning behind this change is that source2 in -tools mode has a single OpenGL context that is used with multiple different windows.  Some of those windows are created outside the engine (i.e. with Qt) and therefore we need to use SDL_CreateWindowFrom() to get an SDL_Window for those.  The requirement for sharing an OpenGL context across multiple different windows is that each window has the same pixel format.  To facilitate this, I now set SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT for the main window before calling SDL_CreateWindowFrom().  When I do this, SDL_CreateWindowFrom() will:

1. Set the pixel format of the returned window to the same pixel format as this SDL_Window passed in with the hint
2. The flag SDL_WINDOW_OPENGL will be set on the new window so it can be used for OpenGL rendering.

I only currently implemented this for Win32/WGL so implementing it for other platforms (i.e. X11) remains a TODO.

CR: SamL

Some pseudocode that shows how this is used in Source2:

HWND hExternalHwnd; // HWND that was established outside of SDL

// Create main window (happens inside platwindow.cpp)
SDL_Window *mainWindow = SDL_CreateWindow( , SDL_WINDOW_OPENGL .. );
// Create GL context, happens inside rendersystemgl
SDL_GLContext onlyContext = SDL_GL_CreateContext( mainWindow );

// Now I need to create another window from hEternalHwnd for my swap chain that will have the same pixel format as mainWindow, so set the hint
SDL_SetHint( SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT, CFmtStr( %p, mainWindow) );

// Create the secondary window.  This returned window will have SDL_WINDOW_OPENGL set and share a pixel format with mainWindow from the hint
SDL_Window *secondaryWindow = SDL_CreateWindowFrom( hExternalHwnd );

// To render to the main window:
SDL_GL_MakeCurrent( mainWindow, onlyContext );
// Do some rendering to main window

// To render to the secondary window:
SDL_GLMakeCurrent( secondaryWindow, onlyContext );
// Do some rendering to secondary window
2014-01-30 12:30:40 -08:00
..
SDL_msctf.h Fixed line endings - in Mercurial they're \n 2011-02-10 14:36:09 -08:00
SDL_vkeys.h File style cleanup for the SDL 2.0 release 2013-05-18 14:17:52 -07:00
SDL_windowsclipboard.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsclipboard.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsevents.c Document Michael's changes adding TranslateMessage() back to the SDL message loop. 2014-01-30 12:27:24 -08:00
SDL_windowsevents.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsframebuffer.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsframebuffer.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowskeyboard.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowskeyboard.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsmessagebox.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsmessagebox.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsmodes.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsmodes.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsmouse.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsmouse.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsopengl.c Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()). 2014-01-30 12:30:40 -08:00
SDL_windowsopengl.h Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()). 2014-01-30 12:30:40 -08:00
SDL_windowsopengles.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsopengles.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsshape.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsshape.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsvideo.c Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowsvideo.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
SDL_windowswindow.c Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()). 2014-01-30 12:30:40 -08:00
SDL_windowswindow.h Make internal SDL sources include SDL_internal.h instead of SDL_config.h 2013-11-24 23:56:17 -05:00
wmmsg.h File style cleanup for the SDL 2.0 release 2013-05-18 14:17:52 -07:00