summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineOpenGL
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-02-26 15:53:37 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-02-26 15:53:37 +0000
commit831f4301977ee119143f9ade931fe1c7fcdb2eae (patch)
tree2b4187a9e8a71617a2dc0c0c7a8e2d4cff59cf03 /Graphics/GraphicsEngineOpenGL
parentBasic math: added convience constructor Vector4(Vector3, float) (diff)
downloadDiligentCore-831f4301977ee119143f9ade931fe1c7fcdb2eae.tar.gz
DiligentCore-831f4301977ee119143f9ade931fe1c7fcdb2eae.zip
Enabled using stencil in the swap chain in GL backend (fixed https://github.com/DiligentGraphics/DiligentCore/issues/65)
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextIOS.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h6
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h9
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h39
-rw-r--r--Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h4
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp100
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp36
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp7
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp7
16 files changed, 145 insertions, 79 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h
index db25be8e..30107937 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h
@@ -33,7 +33,7 @@ namespace Diligent
public:
typedef EGLContext NativeGLContextType;
- GLContext( const struct EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps );
+ GLContext(const struct EngineGLAttribs& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc);
~GLContext();
bool Init( ANativeWindow* window );
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextIOS.h b/Graphics/GraphicsEngineOpenGL/include/GLContextIOS.h
index 4a343545..a71b16ea 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextIOS.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextIOS.h
@@ -30,7 +30,7 @@ namespace Diligent
public:
typedef void* NativeGLContextType; // EAGLContext*
- GLContext(const struct EngineGLAttribs &InitAttribs, struct DeviceCaps &DeviceCaps);
+ GLContext(const struct EngineGLAttribs& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc);
NativeGLContextType GetCurrentNativeGLContext();
};
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h
index 49c5d99a..b17d8827 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h
@@ -30,7 +30,7 @@ namespace Diligent
public:
typedef GLXContext NativeGLContextType;
- GLContext(const struct EngineGLAttribs &InitAttribs, struct DeviceCaps &DeviceCaps);
+ GLContext(const struct EngineGLAttribs& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc);
~GLContext();
void SwapBuffers();
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
index c8aeb055..b67513e2 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
@@ -30,7 +30,7 @@ namespace Diligent
public:
typedef void* NativeGLContextType; // NSOpenGLContext*
- GLContext(const struct EngineGLAttribs &InitAttribs, struct DeviceCaps &DeviceCaps);
+ GLContext(const struct EngineGLAttribs& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc);
NativeGLContextType GetCurrentNativeGLContext();
};
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h
index 7c21a25b..870449b1 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h
@@ -30,14 +30,14 @@ namespace Diligent
public:
typedef HGLRC NativeGLContextType;
- GLContext( const struct EngineGLAttribs &InitAttribs, struct DeviceCaps &DeviceCaps );
+ GLContext(const struct EngineGLAttribs& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc);
~GLContext();
void SwapBuffers();
NativeGLContextType GetCurrentNativeGLContext();
private:
- HGLRC m_Context;
- HDC m_WindowHandleToDeviceContext;
+ HGLRC m_Context = NULL;
+ HDC m_WindowHandleToDeviceContext = NULL;
};
}
diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h
index b34ebeaa..3ed12b56 100644
--- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h
+++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h
@@ -31,9 +31,12 @@ namespace Diligent
class RenderDeviceGLESImpl final : public RenderDeviceGLImpl
{
public:
- RenderDeviceGLESImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs );
-
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+ RenderDeviceGLESImpl( IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ const EngineGLAttribs& InitAttribs,
+ const SwapChainDesc* pSCDesc = nullptr);
+
+ virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface );
virtual bool Invalidate();
diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h
index b0b67c32..bc56c5d8 100644
--- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h
+++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h
@@ -55,41 +55,44 @@ class RenderDeviceGLImpl : public RenderDeviceBase<IGLDeviceBaseInterface>
public:
using TRenderDeviceBase = RenderDeviceBase<IGLDeviceBaseInterface>;
- RenderDeviceGLImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs );
+ RenderDeviceGLImpl(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ const EngineGLAttribs& InitAttribs,
+ const SwapChainDesc* pSCDesc = nullptr);
~RenderDeviceGLImpl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override;
- void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer **ppBufferLayout, bool bIsDeviceInternal);
- virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* BuffData, IBuffer **ppBufferLayout)override final;
+ void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBufferLayout, bool bIsDeviceInternal);
+ virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* BuffData, IBuffer** ppBufferLayout)override final;
- void CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader, bool bIsDeviceInternal );
- virtual void CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader)override final;
+ void CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader** ppShader, bool bIsDeviceInternal );
+ virtual void CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader** ppShader)override final;
- void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture **ppTexture, bool bIsDeviceInternal);
- virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* Data, ITexture **ppTexture)override final;
+ void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture, bool bIsDeviceInternal);
+ virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* Data, ITexture** ppTexture)override final;
- void CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler, bool bIsDeviceInternal);
- virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler)override final;
+ void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler, bool bIsDeviceInternal);
+ virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler)override final;
- void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState, bool bIsDeviceInternal);
- virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState )override final;
+ void CreatePipelineState( const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState, bool bIsDeviceInternal);
+ virtual void CreatePipelineState( const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState )override final;
virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence)override final;
- virtual void CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc &TexDesc, RESOURCE_STATE InitialState, ITexture **ppTexture)override final;
+ virtual void CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc& TexDesc, RESOURCE_STATE InitialState, ITexture** ppTexture)override final;
- virtual void CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc &BuffDesc, RESOURCE_STATE InitialState, IBuffer **ppBuffer)override final;
+ virtual void CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer)override final;
virtual void ReleaseStaleResources(bool ForceRelease = false)override final {}
const GPUInfo& GetGPUInfo(){ return m_GPUInfo; }
FBOCache& GetFBOCache(GLContext::NativeGLContextType Context);
- void OnReleaseTexture(ITexture *pTexture);
+ void OnReleaseTexture(ITexture* pTexture);
VAOCache& GetVAOCache(GLContext::NativeGLContextType Context);
- void OnDestroyPSO(IPipelineState *pPSO);
- void OnDestroyBuffer(IBuffer *pBuffer);
+ void OnDestroyPSO(IPipelineState* pPSO);
+ void OnDestroyBuffer(IBuffer* pBuffer);
size_t GetCommandQueueCount()const { return 1; }
Uint64 GetCommandQueueMask()const { return Uint64{1};}
@@ -121,7 +124,7 @@ protected:
private:
virtual void TestTextureFormat( TEXTURE_FORMAT TexFormat )override final;
- bool CheckExtension(const Char *ExtensionString);
+ bool CheckExtension(const Char* ExtensionString);
void FlagSupportedTexFormats();
void QueryDeviceCaps();
};
diff --git a/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h b/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h
index 89fd0590..9f3b6dd0 100644
--- a/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h
+++ b/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h
@@ -38,11 +38,11 @@ namespace Diligent
/// * On Win32 platform, this is a window handle (HWND)
/// * On Android platform, this is a pointer to the native window (ANativeWindow*)
/// * On Linux, this is the native window (Window)
- void *pNativeWndHandle = nullptr;
+ void* pNativeWndHandle = nullptr;
#if PLATFORM_LINUX
/// For linux platform only, this is the pointer to the display
- void *pDisplay = nullptr;
+ void* pDisplay = nullptr;
#endif
};
}
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp
index 0e0f877e..738ba5c8 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp
@@ -229,7 +229,7 @@ namespace Diligent
return true;
}
- GLContext::GLContext( const EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps ) :
+ GLContext::GLContext(const EngineGLAttribs& InitAttribs, DeviceCaps& DeviceCaps, const struct SwapChainDesc* /*pSCDesc*/) :
display_( EGL_NO_DISPLAY ),
surface_( EGL_NO_SURFACE ),
context_( EGL_NO_CONTEXT ),
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm b/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm
index 5567eb0e..cc96c671 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm
@@ -32,7 +32,7 @@
namespace Diligent
{
- GLContext::GLContext( const EngineGLAttribs &Info, DeviceCaps &DeviceCaps )
+ GLContext::GLContext(const EngineGLAttribs& Info, DeviceCaps& DeviceCaps, const struct SwapChainDesc* /*pSCDesc*/)
{
if (GetCurrentNativeGLContext() == nullptr)
{
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp
index d4f38df3..00fcc65b 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp
@@ -84,7 +84,7 @@ namespace Diligent
LOG_INFO_MESSAGE( MessageSS.str().c_str() );
}
- GLContext::GLContext( const EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps ) :
+ GLContext::GLContext(const EngineGLAttribs& InitAttribs, DeviceCaps& DeviceCaps, const struct SwapChainDesc* /*pSCDesc*/) :
m_Context(0),
m_pNativeWindow(InitAttribs.pNativeWndHandle),
m_pDisplay(InitAttribs.pDisplay)
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm
index 88e2c9c9..bb6e74da 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm
@@ -48,7 +48,7 @@ static void glDrawElementsInstancedBaseVertexBaseInstance_stub(GLenum mode, GLs
namespace Diligent
{
- GLContext::GLContext( const EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps )
+ GLContext::GLContext(const EngineGLAttribs& InitAttribs, DeviceCaps& DeviceCaps, const struct SwapChainDesc* /*pSCDesc*/)
{
if (GetCurrentNativeGLContext() == nullptr)
{
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp
index 88b46b2b..988dbdb8 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp
@@ -27,6 +27,7 @@
#include "DeviceCaps.h"
#include "GLTypeConversions.h"
#include "EngineGLAttribs.h"
+#include "GraphicsAccessories.h"
namespace Diligent
{
@@ -89,7 +90,7 @@ namespace Diligent
LOG_INFO_MESSAGE( MessageSS.str().c_str() );
}
- GLContext::GLContext(const EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps ) :
+ GLContext::GLContext(const EngineGLAttribs& InitAttribs, DeviceCaps& DeviceCaps, const SwapChainDesc* pSCDesc) :
m_Context(0),
m_WindowHandleToDeviceContext(0)
{
@@ -106,10 +107,53 @@ namespace Diligent
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 32;
- pfd.cDepthBits = 32;
- pfd.iLayerType = PFD_MAIN_PLANE;
+ if (pSCDesc != nullptr)
+ {
+ auto ColorFmt = pSCDesc->ColorBufferFormat;
+ if (ColorFmt == TEX_FORMAT_RGBA8_UNORM || ColorFmt == TEX_FORMAT_RGBA8_UNORM_SRGB ||
+ ColorFmt == TEX_FORMAT_BGRA8_UNORM || ColorFmt == TEX_FORMAT_BGRA8_UNORM_SRGB)
+ {
+ pfd.cColorBits = 32;
+ }
+ else
+ {
+ LOG_WARNING_MESSAGE("Unsupported color buffer format ", GetTextureFormatAttribs(ColorFmt).Name, ". "
+ "OpenGL only supports 32-bit UNORM color buffer formats.");
+ pfd.cColorBits = 32;
+ }
+
+ auto DepthFmt = pSCDesc->DepthBufferFormat;
+ switch(DepthFmt)
+ {
+ case TEX_FORMAT_D32_FLOAT_S8X24_UINT:
+ pfd.cDepthBits = 32;
+ pfd.cStencilBits = 8;
+ break;
+ case TEX_FORMAT_D32_FLOAT:
+ pfd.cDepthBits = 32;
+ break;
+
+ case TEX_FORMAT_D24_UNORM_S8_UINT:
+ pfd.cDepthBits = 24;
+ pfd.cStencilBits = 8;
+ break;
+
+ case TEX_FORMAT_D16_UNORM:
+ pfd.cDepthBits = 16;
+ break;
+
+ default:
+ LOG_ERROR_MESSAGE("Unsupported depth buffer format ", GetTextureFormatAttribs(DepthFmt).Name);
+ pfd.cDepthBits = 32;
+ }
+ }
+ else
+ {
+ pfd.cColorBits = 32;
+ pfd.cDepthBits = 32;
+ }
+ pfd.iLayerType = PFD_MAIN_PLANE;
m_WindowHandleToDeviceContext = GetDC( hWnd );
int nPixelFormat = ChoosePixelFormat( m_WindowHandleToDeviceContext, &pfd );
@@ -131,30 +175,40 @@ namespace Diligent
if( GLEW_OK != err )
LOG_ERROR_AND_THROW( "Failed to initialize GLEW" );
- if( wglewIsSupported( "WGL_ARB_create_context" ) == 1 )
+ if (wglewIsSupported( "WGL_ARB_create_context" ) == 1)
{
- MajorVersion = 4;
- MinorVersion = 4;
- // Setup attributes for a new OpenGL rendering context
- int attribs[] =
- {
- WGL_CONTEXT_MAJOR_VERSION_ARB, MajorVersion,
- WGL_CONTEXT_MINOR_VERSION_ARB, MinorVersion,
- WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
- GL_CONTEXT_PROFILE_MASK, GL_CONTEXT_CORE_PROFILE_BIT,
- 0, 0
- };
+ std::pair<int,int> gl_versions[] = {{4,4}, {4,3}, {4,2}};
+ for(size_t i=0; i < _countof(gl_versions) && m_Context == NULL; ++i)
+ {
+ const auto& version = gl_versions[i];
+ MajorVersion = version.first;
+ MinorVersion = version.second;
+ // Setup attributes for a new OpenGL rendering context
+ int attribs[] =
+ {
+ WGL_CONTEXT_MAJOR_VERSION_ARB, MajorVersion,
+ WGL_CONTEXT_MINOR_VERSION_ARB, MinorVersion,
+ WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
+ GL_CONTEXT_PROFILE_MASK, GL_CONTEXT_CORE_PROFILE_BIT,
+ 0, 0
+ };
#ifdef _DEBUG
- attribs[5] |= WGL_CONTEXT_DEBUG_BIT_ARB;
+ attribs[5] |= WGL_CONTEXT_DEBUG_BIT_ARB;
#endif
- // Create new rendering context
- // In order to create new OpenGL rendering context we have to call function wglCreateContextAttribsARB(),
- // which is an OpenGL function and requires OpenGL to be active when it is called.
- // The only way is to create an old context, activate it, and while it is active create a new one.
- // Very inconsistent, but we have to live with it!
- m_Context = wglCreateContextAttribsARB( m_WindowHandleToDeviceContext, 0, attribs );
+ // Create new rendering context
+ // In order to create new OpenGL rendering context we have to call function wglCreateContextAttribsARB(),
+ // which is an OpenGL function and requires OpenGL to be active when it is called.
+ // The only way is to create an old context, activate it, and while it is active create a new one.
+ // Very inconsistent, but we have to live with it!
+ m_Context = wglCreateContextAttribsARB( m_WindowHandleToDeviceContext, 0, attribs );
+ }
+
+ if (m_Context == NULL)
+ {
+ LOG_ERROR_AND_THROW("Failed to initialize OpenGL context.");
+ }
// Delete tempContext
wglMakeCurrent( NULL, NULL );
diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
index 474f914e..601595e0 100644
--- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
@@ -67,17 +67,17 @@ public:
return &TheFactory;
}
- virtual void CreateDeviceAndSwapChainGL(const EngineGLAttribs& CreationAttribs,
- IRenderDevice **ppDevice,
- IDeviceContext **ppImmediateContext,
- const SwapChainDesc& SCDesc,
- ISwapChain **ppSwapChain )override final;
+ virtual void CreateDeviceAndSwapChainGL(const EngineGLAttribs& CreationAttribs,
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppImmediateContext,
+ const SwapChainDesc& SCDesc,
+ ISwapChain** ppSwapChain )override final;
- virtual void CreateHLSL2GLSLConverter(IHLSL2GLSLConverter **ppConverter)override final;
+ virtual void CreateHLSL2GLSLConverter(IHLSL2GLSLConverter** ppConverter)override final;
virtual void AttachToActiveGLContext( const EngineGLAttribs& CreationAttribs,
- IRenderDevice **ppDevice,
- IDeviceContext **ppImmediateContext )override final;
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppImmediateContext )override final;
};
@@ -93,10 +93,10 @@ public:
/// \param [out] ppSwapChain - Address of the memory location where pointer to the new
/// swap chain will be written.
void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineGLAttribs& CreationAttribs,
- IRenderDevice **ppDevice,
- IDeviceContext **ppImmediateContext,
- const SwapChainDesc& SCDesc,
- ISwapChain **ppSwapChain )
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppImmediateContext,
+ const SwapChainDesc& SCDesc,
+ ISwapChain** ppSwapChain)
{
if (CreationAttribs.DebugMessageCallback != nullptr)
SetDebugMessageCallback(CreationAttribs.DebugMessageCallback);
@@ -114,10 +114,10 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineGLAttribs&
SetRawAllocator(CreationAttribs.pRawMemAllocator);
auto &RawMemAllocator = GetRawAllocator();
- RenderDeviceGLImpl *pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, CreationAttribs) );
+ RenderDeviceGLImpl* pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, CreationAttribs, &SCDesc) );
pRenderDeviceOpenGL->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice) );
- DeviceContextGLImpl *pDeviceContextOpenGL( NEW_RC_OBJ(RawMemAllocator, "DeviceContextGLImpl instance", DeviceContextGLImpl)(pRenderDeviceOpenGL, false ) );
+ DeviceContextGLImpl* pDeviceContextOpenGL( NEW_RC_OBJ(RawMemAllocator, "DeviceContextGLImpl instance", DeviceContextGLImpl)(pRenderDeviceOpenGL, false ) );
// We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceOpenGL will
// keep a weak reference to the context
pDeviceContextOpenGL->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppImmediateContext) );
@@ -164,8 +164,8 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineGLAttribs&
/// \param [out] ppImmediateContext - Address of the memory location where pointers to
/// the immediate context will be written.
void EngineFactoryOpenGLImpl::AttachToActiveGLContext( const EngineGLAttribs& CreationAttribs,
- IRenderDevice **ppDevice,
- IDeviceContext **ppImmediateContext )
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppImmediateContext )
{
if (CreationAttribs.DebugMessageCallback != nullptr)
SetDebugMessageCallback(CreationAttribs.DebugMessageCallback);
@@ -182,10 +182,10 @@ void EngineFactoryOpenGLImpl::AttachToActiveGLContext( const EngineGLAttribs& Cr
SetRawAllocator(CreationAttribs.pRawMemAllocator);
auto &RawMemAllocator = GetRawAllocator();
- RenderDeviceGLImpl *pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, CreationAttribs) );
+ RenderDeviceGLImpl* pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, CreationAttribs) );
pRenderDeviceOpenGL->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice) );
- DeviceContextGLImpl *pDeviceContextOpenGL( NEW_RC_OBJ(RawMemAllocator, "DeviceContextGLImpl instance", DeviceContextGLImpl)(pRenderDeviceOpenGL, false ) );
+ DeviceContextGLImpl* pDeviceContextOpenGL( NEW_RC_OBJ(RawMemAllocator, "DeviceContextGLImpl instance", DeviceContextGLImpl)(pRenderDeviceOpenGL, false ) );
// We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceOpenGL will
// keep a weak reference to the context
pDeviceContextOpenGL->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppImmediateContext) );
diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp
index 0446a157..61435151 100644
--- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp
@@ -27,8 +27,11 @@
namespace Diligent
{
- RenderDeviceGLESImpl::RenderDeviceGLESImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs ) :
- RenderDeviceGLImpl( pRefCounters, RawMemAllocator, InitAttribs )
+ RenderDeviceGLESImpl::RenderDeviceGLESImpl(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ const EngineGLAttribs& InitAttribs,
+ const SwapChainDesc* pSCDesc) :
+ RenderDeviceGLImpl(pRefCounters, RawMemAllocator, InitAttribs, pSCDesc)
{
}
diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
index d7f79554..9d630130 100644
--- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
@@ -47,7 +47,10 @@
namespace Diligent
{
-RenderDeviceGLImpl :: RenderDeviceGLImpl(IReferenceCounters *pRefCounters, IMemoryAllocator& RawMemAllocator, const EngineGLAttribs& InitAttribs):
+RenderDeviceGLImpl :: RenderDeviceGLImpl(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ const EngineGLAttribs& InitAttribs,
+ const SwapChainDesc* pSCDesc):
TRenderDeviceBase
{
pRefCounters,
@@ -64,7 +67,7 @@ RenderDeviceGLImpl :: RenderDeviceGLImpl(IReferenceCounters *pRefCounters, IMemo
sizeof(FenceGLImpl)
},
// Device caps must be filled in before the constructor of Pipeline Cache is called!
- m_GLContext(InitAttribs, m_DeviceCaps),
+ m_GLContext(InitAttribs, m_DeviceCaps, pSCDesc),
m_TexRegionRender(this)
{
GLint NumExtensions = 0;