Skip to content

Commit af77e4f

Browse files
Fixed error when setting independent blend states on GLES devices that only support 4 render targets.
1 parent 3576377 commit af77e4f

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

Graphics/GraphicsEngineOpenGL/include/GLContextState.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ class GLContextState
7777
void SetCurrentGLContext(GLContext::NativeGLContextType Context) { m_CurrentGLContext = Context; }
7878
GLContext::NativeGLContextType GetCurrentGLContext()const { return m_CurrentGLContext; }
7979

80+
struct ContextCaps
81+
{
82+
bool bFillModeSelectionSupported = True;
83+
GLint m_iMaxCombinedTexUnits = 0;
84+
GLint m_iMaxDrawBuffers = 0;
85+
};
86+
const ContextCaps& GetContextCaps(){return m_Caps;}
87+
8088
private:
8189
// It is unsafe to use GL handle to keep track of bound objects
8290
// When an object is released, GL is free to reuse its handle for
@@ -195,11 +203,7 @@ class GLContextState
195203
EnableStateHelper ScissorTestEnable;
196204
}m_RSState;
197205

198-
struct ContextCaps
199-
{
200-
bool bFillModeSelectionSupported = True;
201-
GLint m_iMaxCombinedTexUnits = 0;
202-
}m_Caps;
206+
ContextCaps m_Caps;
203207

204208
Uint32 m_ColorWriteMasks[MaxRenderTargets] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
205209
EnableStateHelper m_bIndependentWriteMasks;

Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,12 @@ namespace Diligent
301301

302302
Uint32 NumRenderTargets = m_NumBoundRenderTargets;
303303
VERIFY(NumRenderTargets < MaxRenderTargets, "Too many render targets (", NumRenderTargets, ") are being set");
304-
305304
NumRenderTargets = std::min(NumRenderTargets, MaxRenderTargets);
305+
306+
const auto& CtxCaps = m_ContextState.GetContextCaps();
307+
VERIFY(NumRenderTargets < CtxCaps.m_iMaxDrawBuffers, "This device only supports ", CtxCaps.m_iMaxDrawBuffers, " draw buffers, but ", NumRenderTargets, " are being set");
308+
NumRenderTargets = std::min(NumRenderTargets, static_cast<Uint32>(CtxCaps.m_iMaxDrawBuffers));
309+
306310
ITextureView *pBoundRTVs[MaxRenderTargets] = {};
307311
for (Uint32 rt = 0; rt < NumRenderTargets; ++rt)
308312
pBoundRTVs[rt] = m_pBoundRenderTargets[rt];

Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ namespace Diligent
4646
glGetIntegerv( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_Caps.m_iMaxCombinedTexUnits );
4747
CHECK_GL_ERROR( "Failed to get max combined tex image units count" );
4848
VERIFY_EXPR(m_Caps.m_iMaxCombinedTexUnits > 0);
49+
50+
m_Caps.m_iMaxDrawBuffers = 0;
51+
glGetIntegerv( GL_MAX_DRAW_BUFFERS, &m_Caps.m_iMaxDrawBuffers );
52+
CHECK_GL_ERROR( "Failed to get max draw buffers count" );
53+
VERIFY_EXPR(m_Caps.m_iMaxDrawBuffers > 0);
4954
}
5055

5156
m_BoundTextures.reserve( m_Caps.m_iMaxCombinedTexUnits );
@@ -577,8 +582,15 @@ namespace Diligent
577582
const auto& RT = BSDsc.RenderTargets[i];
578583
if( RT.BlendEnable )
579584
bEnableBlend = true;
580-
581-
SetColorWriteMask(i, RT.RenderTargetWriteMask, True);
585+
586+
if(i < m_Caps.m_iMaxDrawBuffers)
587+
{
588+
SetColorWriteMask(i, RT.RenderTargetWriteMask, True);
589+
}
590+
else
591+
{
592+
VERIFY(RT.RenderTargetWriteMask == RenderTargetBlendDesc().RenderTargetWriteMask, "Render target write mask is specified for buffer ", i, " but this device only supports ", m_Caps.m_iMaxDrawBuffers, " draw buffers");
593+
}
582594
}
583595
}
584596
else
@@ -610,6 +622,14 @@ namespace Diligent
610622
for( int i = 0; i < BSDsc.MaxRenderTargets; ++i )
611623
{
612624
const auto& RT = BSDsc.RenderTargets[i];
625+
626+
if(i >= m_Caps.m_iMaxDrawBuffers)
627+
{
628+
if( RT.BlendEnable )
629+
LOG_ERROR_MESSAGE("Blend is enabled for render target ", i, " but this device only supports ", m_Caps.m_iMaxDrawBuffers, " draw buffers");
630+
continue;
631+
}
632+
613633
if( RT.BlendEnable )
614634
{
615635
glEnablei( GL_BLEND, i );

0 commit comments

Comments
 (0)