diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp index 682c0f7c8..4acf5fef6 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp @@ -37,7 +37,7 @@ GFX_ImplementTextureProfile( BackBufferDepthProfile, GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d) : GFXWindowTarget(win), mDevice(d), mContext(NULL), mFullscreenContext(NULL) - , mCopyFBO(0), mBackBufferFBO(0) + , mCopyFBO(0), mBackBufferFBO(0), mSecondaryWindow(false) { win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal); } @@ -52,7 +52,14 @@ GFXGLWindowTarget::~GFXGLWindowTarget() void GFXGLWindowTarget::resetMode() { - if(mWindow->getVideoMode().fullScreen != mWindow->isFullscreen()) + // Do some validation... + bool fullscreen = mWindow->getVideoMode().fullScreen; + if (fullscreen && mSecondaryWindow) + { + AssertFatal(false, "GFXGLWindowTarget::resetMode - Cannot go fullscreen with secondary window!"); + } + + if(fullscreen != mWindow->isFullscreen()) { _teardownCurrentMode(); _setupNewMode(); diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.h b/Engine/source/gfx/gl/gfxGLWindowTarget.h index 6da33dcfb..10f1f0cc8 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.h +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.h @@ -50,6 +50,9 @@ public: virtual void resolveTo(GFXTextureObject* obj); void _onAppSignal(WindowId wnd, S32 event); + + // create pixel format for the window + void createPixelFormat(); private: friend class GFXGLDevice; @@ -58,6 +61,8 @@ private: GFXTexHandle mBackBufferColorTex, mBackBufferDepthTex; Point2I size; GFXDevice* mDevice; + /// Is this a secondary window + bool mSecondaryWindow; void* mContext; void* mFullscreenContext; void _teardownCurrentMode(); @@ -66,6 +71,7 @@ private: void _WindowPresent(); //set this windows context to be current void _makeContextCurrent(); + }; #endif diff --git a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp index 43b3ab04e..9eaf0c68d 100644 --- a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp +++ b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp @@ -191,19 +191,21 @@ U32 GFXGLDevice::getTotalVideoMemory() GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window ) { - AssertFatal(!mContext, "This GFXGLDevice is already assigned to a window"); - - GFXGLWindowTarget* ggwt = 0; - if( !mContext ) - { - // no context, init the device now - init(window->getVideoMode(), window); - ggwt = new GFXGLWindowTarget(window, this); - ggwt->registerResourceWithDevice(this); - ggwt->mContext = mContext; - } + GFXGLWindowTarget* ggwt = new GFXGLWindowTarget(window, this); - return ggwt; + //first window + if (!mContext) + { + init(window->getVideoMode(), window); + ggwt->mSecondaryWindow = false; + } + else + ggwt->mSecondaryWindow = true; + + ggwt->registerResourceWithDevice(this); + ggwt->mContext = mContext; + + return ggwt; } GFXFence* GFXGLDevice::_createPlatformSpecificFence() diff --git a/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp b/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp index 4a0217e1f..1b88f2dc9 100644 --- a/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp +++ b/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp @@ -255,14 +255,6 @@ void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window ) HDC hdcGL = GetDC( hwnd ); AssertFatal( hdcGL != NULL, "Failed to create device context" ); - // Create pixel format descriptor... - PIXELFORMATDESCRIPTOR pfd; - CreatePixelFormat( &pfd, 32, 0, 0, false ); // 32 bit color... We do not need depth or stencil, OpenGL renders into a FBO and then copy the image to window - if( !SetPixelFormat( hdcGL, ChoosePixelFormat( hdcGL, &pfd ), &pfd ) ) - { - AssertFatal( false, "GFXGLDevice::init - cannot get the one and only pixel format we check for." ); - } - int OGL_MAJOR = 3; int OGL_MINOR = 2; @@ -330,13 +322,21 @@ U32 GFXGLDevice::getTotalVideoMemory() //------------------------------------------------------------------------------ -GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window ) +GFXWindowTarget *GFXGLDevice::allocWindowTarget(PlatformWindow *window) { - AssertFatal(!mContext, ""); - - init(window->getVideoMode(), window); GFXGLWindowTarget *ggwt = new GFXGLWindowTarget(window, this); ggwt->registerResourceWithDevice(this); + ggwt->createPixelFormat(); + + //first window + if (!mContext) + { + init(window->getVideoMode(), window); + ggwt->mSecondaryWindow = false; + } + else + ggwt->mSecondaryWindow = true; + ggwt->mContext = mContext; AssertFatal(ggwt->mContext, "GFXGLDevice::allocWindowTarget - failed to allocate window target!"); @@ -364,15 +364,32 @@ void GFXGLWindowTarget::_setupNewMode() { } +void GFXGLWindowTarget::createPixelFormat() +{ + HWND hwnd = GETHWND(mWindow); + // Create a device context + HDC hdcGL = GetDC(hwnd); + AssertFatal(hdcGL != NULL, "GFXGLWindowTarget::createPixelFormat() - Failed to create device context"); + + // Create pixel format descriptor... + PIXELFORMATDESCRIPTOR pfd; + CreatePixelFormat(&pfd, 32, 0, 0, false); // 32 bit color... We do not need depth or stencil, OpenGL renders into a FBO and then copy the image to window + if (!SetPixelFormat(hdcGL, ChoosePixelFormat(hdcGL, &pfd), &pfd)) + { + AssertFatal(false, "GFXGLWindowTarget::createPixelFormat() - cannot get the one and only pixel format we check for."); + } +} + void GFXGLWindowTarget::_makeContextCurrent() { HWND hwnd = GETHWND(getWindow()); HDC hdc = GetDC(hwnd); + if (!wglMakeCurrent(hdc, (HGLRC)mContext)) { //HRESULT if needed for debug //HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); AssertFatal(false, "GFXGLWindowTarget::_makeContextCurrent() - cannot make our context current."); } - -} + +} \ No newline at end of file