Skip to content

Commit

Permalink
Fixed error when setting independent blend states on GLES devices tha…
Browse files Browse the repository at this point in the history
…t only support 4 render targets.
  • Loading branch information
TheMostDiligent committed Feb 19, 2018
1 parent 3576377 commit af77e4f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
14 changes: 9 additions & 5 deletions Graphics/GraphicsEngineOpenGL/include/GLContextState.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ class GLContextState
void SetCurrentGLContext(GLContext::NativeGLContextType Context) { m_CurrentGLContext = Context; }
GLContext::NativeGLContextType GetCurrentGLContext()const { return m_CurrentGLContext; }

struct ContextCaps
{
bool bFillModeSelectionSupported = True;
GLint m_iMaxCombinedTexUnits = 0;
GLint m_iMaxDrawBuffers = 0;
};
const ContextCaps& GetContextCaps(){return m_Caps;}

private:
// It is unsafe to use GL handle to keep track of bound objects
// When an object is released, GL is free to reuse its handle for
Expand Down Expand Up @@ -195,11 +203,7 @@ class GLContextState
EnableStateHelper ScissorTestEnable;
}m_RSState;

struct ContextCaps
{
bool bFillModeSelectionSupported = True;
GLint m_iMaxCombinedTexUnits = 0;
}m_Caps;
ContextCaps m_Caps;

Uint32 m_ColorWriteMasks[MaxRenderTargets] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
EnableStateHelper m_bIndependentWriteMasks;
Expand Down
6 changes: 5 additions & 1 deletion Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,12 @@ namespace Diligent

Uint32 NumRenderTargets = m_NumBoundRenderTargets;
VERIFY(NumRenderTargets < MaxRenderTargets, "Too many render targets (", NumRenderTargets, ") are being set");

NumRenderTargets = std::min(NumRenderTargets, MaxRenderTargets);

const auto& CtxCaps = m_ContextState.GetContextCaps();
VERIFY(NumRenderTargets < CtxCaps.m_iMaxDrawBuffers, "This device only supports ", CtxCaps.m_iMaxDrawBuffers, " draw buffers, but ", NumRenderTargets, " are being set");
NumRenderTargets = std::min(NumRenderTargets, static_cast<Uint32>(CtxCaps.m_iMaxDrawBuffers));

ITextureView *pBoundRTVs[MaxRenderTargets] = {};
for (Uint32 rt = 0; rt < NumRenderTargets; ++rt)
pBoundRTVs[rt] = m_pBoundRenderTargets[rt];
Expand Down
24 changes: 22 additions & 2 deletions Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ namespace Diligent
glGetIntegerv( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_Caps.m_iMaxCombinedTexUnits );
CHECK_GL_ERROR( "Failed to get max combined tex image units count" );
VERIFY_EXPR(m_Caps.m_iMaxCombinedTexUnits > 0);

m_Caps.m_iMaxDrawBuffers = 0;
glGetIntegerv( GL_MAX_DRAW_BUFFERS, &m_Caps.m_iMaxDrawBuffers );
CHECK_GL_ERROR( "Failed to get max draw buffers count" );
VERIFY_EXPR(m_Caps.m_iMaxDrawBuffers > 0);
}

m_BoundTextures.reserve( m_Caps.m_iMaxCombinedTexUnits );
Expand Down Expand Up @@ -577,8 +582,15 @@ namespace Diligent
const auto& RT = BSDsc.RenderTargets[i];
if( RT.BlendEnable )
bEnableBlend = true;

SetColorWriteMask(i, RT.RenderTargetWriteMask, True);

if(i < m_Caps.m_iMaxDrawBuffers)
{
SetColorWriteMask(i, RT.RenderTargetWriteMask, True);
}
else
{
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");
}
}
}
else
Expand Down Expand Up @@ -610,6 +622,14 @@ namespace Diligent
for( int i = 0; i < BSDsc.MaxRenderTargets; ++i )
{
const auto& RT = BSDsc.RenderTargets[i];

if(i >= m_Caps.m_iMaxDrawBuffers)
{
if( RT.BlendEnable )
LOG_ERROR_MESSAGE("Blend is enabled for render target ", i, " but this device only supports ", m_Caps.m_iMaxDrawBuffers, " draw buffers");
continue;
}

if( RT.BlendEnable )
{
glEnablei( GL_BLEND, i );
Expand Down

0 comments on commit af77e4f

Please sign in to comment.