diff --git a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp index 6e937bc34f..23c90546ce 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp @@ -234,17 +234,17 @@ DXGI_SWAP_CHAIN_DESC GFXD3D11Device::setupPresentParams(const GFXVideoMode &mode mMultisampleDesc = sampleDesc; - d3dpp.BufferCount = smEnableVSync ? 2 : 1; // triple buffering when vsync is on. + d3dpp.BufferCount = smEnableVSync ? 3 : 2; // triple buffering in vsync, double buffered non vsync. d3dpp.BufferDesc.Width = mode.resolution.x; d3dpp.BufferDesc.Height = mode.resolution.y; - d3dpp.BufferDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8_SRGB]; + d3dpp.BufferDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8]; d3dpp.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; d3dpp.OutputWindow = hwnd; d3dpp.SampleDesc = sampleDesc; d3dpp.Windowed = !mode.fullScreen; d3dpp.BufferDesc.RefreshRate.Numerator = mode.refreshRate; d3dpp.BufferDesc.RefreshRate.Denominator = 1; - d3dpp.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + d3dpp.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; if (mode.fullScreen) { diff --git a/Engine/source/gfx/D3D11/gfxD3D11Target.cpp b/Engine/source/gfx/D3D11/gfxD3D11Target.cpp index 88e91156d5..2f8aa35e1b 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Target.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Target.cpp @@ -324,6 +324,7 @@ GFXD3D11WindowTarget::GFXD3D11WindowTarget() mDepthStencilView = NULL; mDepthStencil = NULL; mBackBufferView = NULL; + mPrevBackBuffer = NULL; mSwapChain = NULL; dMemset(&mPresentationParams, 0, sizeof(mPresentationParams)); mSecondaryWindow = false; @@ -332,9 +333,10 @@ GFXD3D11WindowTarget::GFXD3D11WindowTarget() GFXD3D11WindowTarget::~GFXD3D11WindowTarget() { SAFE_RELEASE(mDepthStencilView) - SAFE_RELEASE(mDepthStencil); + SAFE_RELEASE(mDepthStencil); SAFE_RELEASE(mBackBufferView); SAFE_RELEASE(mBackBuffer); + SAFE_RELEASE(mPrevBackBuffer); SAFE_RELEASE(mSwapChain); } @@ -382,7 +384,9 @@ bool GFXD3D11WindowTarget::present() else if (result == DXGI_ERROR_INVALID_CALL) AssertFatal(false, "DXGI_ERROR_INVALID_CALL"); } - + // if swap chain flip this needs to be called right after present as it unbinds the backbuffer. + setBackBuffer(); + activate(); return (hr == S_OK); } @@ -553,8 +557,12 @@ void GFXD3D11WindowTarget::resurrect() void GFXD3D11WindowTarget::setBackBuffer() { - if (!mBackBuffer) - mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)& mBackBuffer); + // dx automatically handles the backbuffer swaps, 0 is always the previous backbuffer. + HRESULT hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBuffer); + if (FAILED(hr)) + AssertFatal(false, "GFXD3D11WindowTarget::setBackBuffer - Failed to retrieve backbuffer."); + + mPrevBackBuffer = mBackBuffer; } void GFXD3D11WindowTarget::activate() @@ -586,7 +594,7 @@ void GFXD3D11WindowTarget::resolveTo(GFXTextureObject *tex) D3D11_TEXTURE2D_DESC desc; ID3D11Texture2D* surf = ((GFXD3D11TextureObject*)(tex))->get2DTex(); surf->GetDesc(&desc); - D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, mBackBuffer, 0, desc.Format); + D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, mPrevBackBuffer, 0, desc.Format); } IDXGISwapChain* GFXD3D11WindowTarget::getSwapChain() @@ -601,6 +609,12 @@ ID3D11Texture2D* GFXD3D11WindowTarget::getBackBuffer() return mBackBuffer; } +ID3D11Texture2D* GFXD3D11WindowTarget::getPrevBackBuffer() +{ + mPrevBackBuffer->AddRef(); + return mPrevBackBuffer; +} + ID3D11Texture2D* GFXD3D11WindowTarget::getDepthStencil() { mDepthStencil->AddRef(); diff --git a/Engine/source/gfx/D3D11/gfxD3D11Target.h b/Engine/source/gfx/D3D11/gfxD3D11Target.h index 1173a4ee40..efbf944a40 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Target.h +++ b/Engine/source/gfx/D3D11/gfxD3D11Target.h @@ -77,6 +77,7 @@ class GFXD3D11WindowTarget : public GFXWindowTarget /// Our backbuffer ID3D11Texture2D* mBackBuffer; + ID3D11Texture2D* mPrevBackBuffer; ID3D11Texture2D* mDepthStencil; ID3D11RenderTargetView* mBackBufferView; ID3D11DepthStencilView* mDepthStencilView; @@ -116,6 +117,7 @@ class GFXD3D11WindowTarget : public GFXWindowTarget // These are all reference counted and must be released by whomever uses the get* function IDXGISwapChain* getSwapChain(); ID3D11Texture2D* getBackBuffer(); + ID3D11Texture2D* getPrevBackBuffer(); ID3D11Texture2D* getDepthStencil(); ID3D11RenderTargetView* getBackBufferView(); ID3D11DepthStencilView* getDepthStencilView(); diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp index 0d846fc7ea..54043abd73 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp @@ -121,10 +121,10 @@ inline void GFXGLWindowTarget::_setupAttachments() glEnable(GL_FRAMEBUFFER_SRGB); GFXGL->getOpenglCache()->setCacheBinded(GL_FRAMEBUFFER, mBackBufferFBO); const Point2I dstSize = getSize(); - mBackBufferColorTex.set(dstSize.x, dstSize.y, getFormat(), &GFXRenderTargetSRGBProfile, "backBuffer"); + mBackBufferColorTex.set(dstSize.x, dstSize.y, getFormat(), &GFXRenderTargetSRGBProfile, "backBuffer_color"); GFXGLTextureObject *color = static_cast(mBackBufferColorTex.getPointer()); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color->getHandle(), 0); - mBackBufferDepthTex.set(dstSize.x, dstSize.y, GFXFormatD24S8, &BackBufferDepthProfile, "backBuffer"); + mBackBufferDepthTex.set(dstSize.x, dstSize.y, GFXFormatD24S8, &BackBufferDepthProfile, "backBuffer_depth"); GFXGLTextureObject *depth = static_cast(mBackBufferDepthTex.getPointer()); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depth->getHandle(), 0); } diff --git a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp index b886094c7d..68358f061e 100644 --- a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp +++ b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp @@ -103,8 +103,6 @@ void GFXGLDevice::enumerateAdapters( Vector &adapterList ) } SDL_ClearError(); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); @@ -139,7 +137,11 @@ void GFXGLDevice::enumerateAdapters( Vector &adapterList ) { return; } + Con::printf("OpenGL Version: %d.%d", major, minor); + // Set our sdl attribute to use this version. + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor); //check for required extensions if (!gglHasExtension(ARB_texture_cube_map_array)) { @@ -168,7 +170,26 @@ void GFXGLDevice::enumerateAdapters( Vector &adapterList ) dStrcpy(toAdd->mName, "OpenGL", GFXAdapter::MaxAdapterNameLen); toAdd->mType = OpenGL; - toAdd->mShaderModel = 0.f; + F32 shaderModel = 3.3; + if (major == 4) + { + if (minor == 0) + shaderModel = 4.00f; // GLSL 4.00 + else if (minor == 1) + shaderModel = 4.10f; // GLSL 4.10 + else if (minor == 2) + shaderModel = 4.20f; // GLSL 4.20 + else if (minor == 3) + shaderModel = 4.30f; // GLSL 4.30 + else if (minor == 4) + shaderModel = 4.40f; // GLSL 4.40 + else if (minor == 5) + shaderModel = 4.50f; // GLSL 4.50 + else if (minor == 6) + shaderModel = 4.60f; // GLSL 4.60 + } + + toAdd->mShaderModel = shaderModel; toAdd->mCreateDeviceInstanceDelegate = mCreateDeviceInstance; // Enumerate all available resolutions: diff --git a/Engine/source/platformSDL/sdlPlatformGL.cpp b/Engine/source/platformSDL/sdlPlatformGL.cpp index fd55727b82..1f2c9fbb84 100644 --- a/Engine/source/platformSDL/sdlPlatformGL.cpp +++ b/Engine/source/platformSDL/sdlPlatformGL.cpp @@ -13,18 +13,16 @@ namespace PlatformGL void init() { - const U32 majorOGL = 3; - const U32 minorOGL = 3; U32 debugFlag = 0; #ifdef TORQUE_DEBUG debugFlag |= SDL_GL_CONTEXT_DEBUG_FLAG; #endif - - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorOGL); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorOGL); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag); SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Enable double buffering + // Make sure the visual is accelerated + SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); #ifdef TORQUE_GL_SOFTWARE SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 0); #endif @@ -50,6 +48,10 @@ namespace PlatformGL Con::printf( err ); AssertFatal(0, err ); } + int majorOGL = 0; + int minorOGL = 0; + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorOGL); + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorOGL); return ctx; }