mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
OpenGL multiple canvas support
This commit is contained in:
parent
efab1299ca
commit
08c0195cba
4 changed files with 60 additions and 28 deletions
|
|
@ -37,7 +37,7 @@ GFX_ImplementTextureProfile( BackBufferDepthProfile,
|
||||||
|
|
||||||
GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d)
|
GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d)
|
||||||
: GFXWindowTarget(win), mDevice(d), mContext(NULL), mFullscreenContext(NULL)
|
: GFXWindowTarget(win), mDevice(d), mContext(NULL), mFullscreenContext(NULL)
|
||||||
, mCopyFBO(0), mBackBufferFBO(0)
|
, mCopyFBO(0), mBackBufferFBO(0), mSecondaryWindow(false)
|
||||||
{
|
{
|
||||||
win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal);
|
win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal);
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +52,14 @@ GFXGLWindowTarget::~GFXGLWindowTarget()
|
||||||
|
|
||||||
void GFXGLWindowTarget::resetMode()
|
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();
|
_teardownCurrentMode();
|
||||||
_setupNewMode();
|
_setupNewMode();
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ public:
|
||||||
virtual void resolveTo(GFXTextureObject* obj);
|
virtual void resolveTo(GFXTextureObject* obj);
|
||||||
|
|
||||||
void _onAppSignal(WindowId wnd, S32 event);
|
void _onAppSignal(WindowId wnd, S32 event);
|
||||||
|
|
||||||
|
// create pixel format for the window
|
||||||
|
void createPixelFormat();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class GFXGLDevice;
|
friend class GFXGLDevice;
|
||||||
|
|
@ -58,6 +61,8 @@ private:
|
||||||
GFXTexHandle mBackBufferColorTex, mBackBufferDepthTex;
|
GFXTexHandle mBackBufferColorTex, mBackBufferDepthTex;
|
||||||
Point2I size;
|
Point2I size;
|
||||||
GFXDevice* mDevice;
|
GFXDevice* mDevice;
|
||||||
|
/// Is this a secondary window
|
||||||
|
bool mSecondaryWindow;
|
||||||
void* mContext;
|
void* mContext;
|
||||||
void* mFullscreenContext;
|
void* mFullscreenContext;
|
||||||
void _teardownCurrentMode();
|
void _teardownCurrentMode();
|
||||||
|
|
@ -66,6 +71,7 @@ private:
|
||||||
void _WindowPresent();
|
void _WindowPresent();
|
||||||
//set this windows context to be current
|
//set this windows context to be current
|
||||||
void _makeContextCurrent();
|
void _makeContextCurrent();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -191,19 +191,21 @@ U32 GFXGLDevice::getTotalVideoMemory()
|
||||||
|
|
||||||
GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window )
|
GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window )
|
||||||
{
|
{
|
||||||
AssertFatal(!mContext, "This GFXGLDevice is already assigned to a window");
|
GFXGLWindowTarget* ggwt = new GFXGLWindowTarget(window, this);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
GFXFence* GFXGLDevice::_createPlatformSpecificFence()
|
||||||
|
|
|
||||||
|
|
@ -255,14 +255,6 @@ void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window )
|
||||||
HDC hdcGL = GetDC( hwnd );
|
HDC hdcGL = GetDC( hwnd );
|
||||||
AssertFatal( hdcGL != NULL, "Failed to create device context" );
|
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_MAJOR = 3;
|
||||||
int OGL_MINOR = 2;
|
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);
|
GFXGLWindowTarget *ggwt = new GFXGLWindowTarget(window, this);
|
||||||
ggwt->registerResourceWithDevice(this);
|
ggwt->registerResourceWithDevice(this);
|
||||||
|
ggwt->createPixelFormat();
|
||||||
|
|
||||||
|
//first window
|
||||||
|
if (!mContext)
|
||||||
|
{
|
||||||
|
init(window->getVideoMode(), window);
|
||||||
|
ggwt->mSecondaryWindow = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ggwt->mSecondaryWindow = true;
|
||||||
|
|
||||||
ggwt->mContext = mContext;
|
ggwt->mContext = mContext;
|
||||||
AssertFatal(ggwt->mContext, "GFXGLDevice::allocWindowTarget - failed to allocate window target!");
|
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()
|
void GFXGLWindowTarget::_makeContextCurrent()
|
||||||
{
|
{
|
||||||
HWND hwnd = GETHWND(getWindow());
|
HWND hwnd = GETHWND(getWindow());
|
||||||
HDC hdc = GetDC(hwnd);
|
HDC hdc = GetDC(hwnd);
|
||||||
|
|
||||||
if (!wglMakeCurrent(hdc, (HGLRC)mContext))
|
if (!wglMakeCurrent(hdc, (HGLRC)mContext))
|
||||||
{
|
{
|
||||||
//HRESULT if needed for debug
|
//HRESULT if needed for debug
|
||||||
//HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
|
//HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
|
||||||
AssertFatal(false, "GFXGLWindowTarget::_makeContextCurrent() - cannot make our context current.");
|
AssertFatal(false, "GFXGLWindowTarget::_makeContextCurrent() - cannot make our context current.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue