Skip to content

Commit a70f2f6

Browse files
committed
more
GL updated to use the latest version supported minimum 3.3 gl updated to double buffered window dx prev buffer saved and accessed through resolve or getPrevBackBuffer
1 parent e7c44e5 commit a70f2f6

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

Engine/source/gfx/D3D11/gfxD3D11Target.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ GFXD3D11WindowTarget::GFXD3D11WindowTarget()
324324
mDepthStencilView = NULL;
325325
mDepthStencil = NULL;
326326
mBackBufferView = NULL;
327+
mPrevBackBuffer = NULL;
327328
mSwapChain = NULL;
328329
dMemset(&mPresentationParams, 0, sizeof(mPresentationParams));
329330
mSecondaryWindow = false;
@@ -335,6 +336,7 @@ GFXD3D11WindowTarget::~GFXD3D11WindowTarget()
335336
SAFE_RELEASE(mDepthStencil);
336337
SAFE_RELEASE(mBackBufferView);
337338
SAFE_RELEASE(mBackBuffer);
339+
SAFE_RELEASE(mPrevBackBuffer);
338340
SAFE_RELEASE(mSwapChain);
339341
}
340342

@@ -383,6 +385,7 @@ bool GFXD3D11WindowTarget::present()
383385
AssertFatal(false, "DXGI_ERROR_INVALID_CALL");
384386
}
385387
// if swap chain flip this needs to be called right after present as it unbinds the backbuffer.
388+
setBackBuffer();
386389
activate();
387390
return (hr == S_OK);
388391
}
@@ -554,10 +557,12 @@ void GFXD3D11WindowTarget::resurrect()
554557

555558
void GFXD3D11WindowTarget::setBackBuffer()
556559
{
557-
SAFE_RELEASE(mBackBuffer);
560+
// dx automatically handles the backbuffer swaps, 0 is always the previous backbuffer.
558561
HRESULT hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBuffer);
559562
if (FAILED(hr))
560563
AssertFatal(false, "GFXD3D11WindowTarget::setBackBuffer - Failed to retrieve backbuffer.");
564+
565+
mPrevBackBuffer = mBackBuffer;
561566
}
562567

563568
void GFXD3D11WindowTarget::activate()
@@ -589,7 +594,7 @@ void GFXD3D11WindowTarget::resolveTo(GFXTextureObject *tex)
589594
D3D11_TEXTURE2D_DESC desc;
590595
ID3D11Texture2D* surf = ((GFXD3D11TextureObject*)(tex))->get2DTex();
591596
surf->GetDesc(&desc);
592-
D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, mBackBuffer, 0, desc.Format);
597+
D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, mPrevBackBuffer, 0, desc.Format);
593598
}
594599

595600
IDXGISwapChain* GFXD3D11WindowTarget::getSwapChain()
@@ -604,6 +609,12 @@ ID3D11Texture2D* GFXD3D11WindowTarget::getBackBuffer()
604609
return mBackBuffer;
605610
}
606611

612+
ID3D11Texture2D* GFXD3D11WindowTarget::getPrevBackBuffer()
613+
{
614+
mPrevBackBuffer->AddRef();
615+
return mPrevBackBuffer;
616+
}
617+
607618
ID3D11Texture2D* GFXD3D11WindowTarget::getDepthStencil()
608619
{
609620
mDepthStencil->AddRef();

Engine/source/gfx/D3D11/gfxD3D11Target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class GFXD3D11WindowTarget : public GFXWindowTarget
7777

7878
/// Our backbuffer
7979
ID3D11Texture2D* mBackBuffer;
80+
ID3D11Texture2D* mPrevBackBuffer;
8081
ID3D11Texture2D* mDepthStencil;
8182
ID3D11RenderTargetView* mBackBufferView;
8283
ID3D11DepthStencilView* mDepthStencilView;
@@ -116,6 +117,7 @@ class GFXD3D11WindowTarget : public GFXWindowTarget
116117
// These are all reference counted and must be released by whomever uses the get* function
117118
IDXGISwapChain* getSwapChain();
118119
ID3D11Texture2D* getBackBuffer();
120+
ID3D11Texture2D* getPrevBackBuffer();
119121
ID3D11Texture2D* getDepthStencil();
120122
ID3D11RenderTargetView* getBackBufferView();
121123
ID3D11DepthStencilView* getDepthStencilView();

Engine/source/gfx/gl/gfxGLWindowTarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ inline void GFXGLWindowTarget::_setupAttachments()
121121
glEnable(GL_FRAMEBUFFER_SRGB);
122122
GFXGL->getOpenglCache()->setCacheBinded(GL_FRAMEBUFFER, mBackBufferFBO);
123123
const Point2I dstSize = getSize();
124-
mBackBufferColorTex.set(dstSize.x, dstSize.y, getFormat(), &GFXRenderTargetSRGBProfile, "backBuffer");
124+
mBackBufferColorTex.set(dstSize.x, dstSize.y, getFormat(), &GFXRenderTargetSRGBProfile, "backBuffer_color");
125125
GFXGLTextureObject *color = static_cast<GFXGLTextureObject*>(mBackBufferColorTex.getPointer());
126126
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color->getHandle(), 0);
127-
mBackBufferDepthTex.set(dstSize.x, dstSize.y, GFXFormatD24S8, &BackBufferDepthProfile, "backBuffer");
127+
mBackBufferDepthTex.set(dstSize.x, dstSize.y, GFXFormatD24S8, &BackBufferDepthProfile, "backBuffer_depth");
128128
GFXGLTextureObject *depth = static_cast<GFXGLTextureObject*>(mBackBufferDepthTex.getPointer());
129129
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depth->getHandle(), 0);
130130
}

Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ void GFXGLDevice::enumerateAdapters( Vector<GFXAdapter*> &adapterList )
103103
}
104104

105105
SDL_ClearError();
106-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
107-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
108106
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
109107
SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
110108

@@ -140,6 +138,9 @@ void GFXGLDevice::enumerateAdapters( Vector<GFXAdapter*> &adapterList )
140138
return;
141139
}
142140

141+
// Set our sdl attribute to use this version.
142+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
143+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
143144
//check for required extensions
144145
if (!gglHasExtension(ARB_texture_cube_map_array))
145146
{

Engine/source/platformSDL/sdlPlatformGL.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ namespace PlatformGL
1313

1414
void init()
1515
{
16-
const U32 majorOGL = 3;
17-
const U32 minorOGL = 3;
1816
U32 debugFlag = 0;
1917
#ifdef TORQUE_DEBUG
2018
debugFlag |= SDL_GL_CONTEXT_DEBUG_FLAG;
2119
#endif
22-
23-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorOGL);
24-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorOGL);
2520
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
2621
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag);
2722
SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
23+
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Enable double buffering
24+
// Make sure the visual is accelerated
25+
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
2826
#ifdef TORQUE_GL_SOFTWARE
2927
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 0);
3028
#endif
@@ -50,6 +48,10 @@ namespace PlatformGL
5048
Con::printf( err );
5149
AssertFatal(0, err );
5250
}
51+
int majorOGL = 0;
52+
int minorOGL = 0;
53+
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorOGL);
54+
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorOGL);
5355

5456
return ctx;
5557
}

0 commit comments

Comments
 (0)