Skip to content

Commit 98064f9

Browse files
committed
Add GL_ARB_stencil_texturing capability checking, and FormatInfo.Supported checking.
1 parent 9e3dcad commit 98064f9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,13 +1138,16 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats()
11381138
{
11391139
const RenderDeviceInfo& DeviceInfo = GetDeviceInfo();
11401140
const bool bDekstopGL = DeviceInfo.Type == RENDER_DEVICE_TYPE_GL;
1141+
const bool bGL430OrAbove = DeviceInfo.Type == RENDER_DEVICE_TYPE_GL && DeviceInfo.APIVersion >= Version{4, 3};
11411142
const bool bGLES30OrAbove = DeviceInfo.Type == RENDER_DEVICE_TYPE_GLES && DeviceInfo.APIVersion >= Version{3, 0};
1143+
const bool bGLES31OrAbove = DeviceInfo.Type == RENDER_DEVICE_TYPE_GLES && DeviceInfo.APIVersion >= Version{3, 1};
11421144

11431145
const bool bRGTC = CheckExtension("GL_EXT_texture_compression_rgtc") || CheckExtension("GL_ARB_texture_compression_rgtc");
11441146
const bool bBPTC = CheckExtension("GL_EXT_texture_compression_bptc") || CheckExtension("GL_ARB_texture_compression_bptc");
11451147
const bool bS3TC = CheckExtension("GL_EXT_texture_compression_s3tc") || CheckExtension("GL_WEBGL_compressed_texture_s3tc");
11461148
const bool bTexNorm16 = bDekstopGL || CheckExtension("GL_EXT_texture_norm16"); // Only for ES3.1+
11471149
const bool bTexSwizzle = bDekstopGL || bGLES30OrAbove || CheckExtension("GL_ARB_texture_swizzle");
1150+
const bool bStencilTex = bGL430OrAbove || bGLES31OrAbove || CheckExtension("GL_ARB_stencil_texturing");
11481151

11491152
#if PLATFORM_WEB
11501153
const bool bETC2 = CheckExtension("GL_WEBGL_compressed_texture_etc");
@@ -1253,7 +1256,7 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats()
12531256
FlagFormat(TEX_FORMAT_R32G8X24_TYPELESS, true );
12541257
FlagFormat(TEX_FORMAT_D32_FLOAT_S8X24_UINT, true, BIND_DEPTH_STENCIL );
12551258
FlagFormat(TEX_FORMAT_R32_FLOAT_X8X24_TYPELESS, true, TexBindFlags, bDekstopGL);
1256-
FlagFormat(TEX_FORMAT_X32_TYPELESS_G8X24_UINT, true, BIND_SHADER_RESOURCE, false);
1259+
FlagFormat(TEX_FORMAT_X32_TYPELESS_G8X24_UINT, bStencilTex, BIND_SHADER_RESOURCE, false);
12571260
FlagFormat(TEX_FORMAT_RGB10A2_TYPELESS, true );
12581261
FlagFormat(TEX_FORMAT_RGB10A2_UNORM, true, BindSrvRtvUav, true);
12591262
FlagFormat(TEX_FORMAT_RGB10A2_UINT, true, BindSrvRtvUav );
@@ -1278,7 +1281,7 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats()
12781281
FlagFormat(TEX_FORMAT_R24G8_TYPELESS, true );
12791282
FlagFormat(TEX_FORMAT_D24_UNORM_S8_UINT, true, BIND_DEPTH_STENCIL );
12801283
FlagFormat(TEX_FORMAT_R24_UNORM_X8_TYPELESS, true, TexBindFlags, true);
1281-
FlagFormat(TEX_FORMAT_X24_TYPELESS_G8_UINT, true, BIND_SHADER_RESOURCE, false);
1284+
FlagFormat(TEX_FORMAT_X24_TYPELESS_G8_UINT, bStencilTex, BIND_SHADER_RESOURCE, false);
12821285
FlagFormat(TEX_FORMAT_RG8_TYPELESS, true );
12831286
FlagFormat(TEX_FORMAT_RG8_UNORM, true, U8BindFlags, true);
12841287
FlagFormat(TEX_FORMAT_RG8_UINT, true, UI8BindFlags );

Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,21 +490,25 @@ void TextureBaseGL::CreateViewInternal(const TextureViewDesc& OrigViewDesc, ITex
490490
LOG_ERROR_AND_THROW("glTextureView is not supported");
491491

492492
glTextureView(pViewOGL->GetHandle(), GLViewTarget, m_GlTexture, GLViewFormat, ViewDesc.MostDetailedMip, ViewDesc.NumMipLevels, ViewDesc.FirstArraySlice, NumLayers);
493-
494493
DEV_CHECK_GL_ERROR_AND_THROW("Failed to create texture view");
495494
pViewOGL->SetBindTarget(GLViewTarget);
496495

497-
if(ViewDesc.Format == TEX_FORMAT_X24_TYPELESS_G8_UINT || ViewDesc.Format == TEX_FORMAT_X32_TYPELESS_G8X24_UINT)
496+
if (ViewDesc.Format == TEX_FORMAT_X24_TYPELESS_G8_UINT || ViewDesc.Format == TEX_FORMAT_X32_TYPELESS_G8X24_UINT)
498497
{
499-
RefCntAutoPtr<DeviceContextGLImpl> pDeviceContext = pDeviceGLImpl->GetImmediateContext(0);
500-
VERIFY(pDeviceContext, "Immediate device context has been destroyed");
501-
GLContextState& GLState = pDeviceContext->GetContextState();
498+
const auto &FormatInfo = pDeviceGLImpl->GetTextureFormatInfo(ViewDesc.Format);
502499

503-
GLState.BindTexture(-1, GLViewTarget, pViewOGL->GetHandle());
500+
if (FormatInfo.Supported)
501+
{
502+
RefCntAutoPtr<DeviceContextGLImpl> pDeviceContext = pDeviceGLImpl->GetImmediateContext(0);
503+
VERIFY(pDeviceContext, "Immediate device context has been destroyed");
504+
GLContextState& GLState = pDeviceContext->GetContextState();
504505

505-
glTexParameteri(GLViewTarget, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX);
506+
GLState.BindTexture(-1, GLViewTarget, pViewOGL->GetHandle());
506507

507-
GLState.BindTexture(-1, GLViewTarget, GLObjectWrappers::GLTextureObj::Null());
508+
glTexParameteri(GLViewTarget, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX);
509+
510+
GLState.BindTexture(-1, GLViewTarget, GLObjectWrappers::GLTextureObj::Null());
511+
}
508512
}
509513

510514
if (!IsIdentityComponentMapping(ViewDesc.Swizzle))
@@ -522,7 +526,6 @@ void TextureBaseGL::CreateViewInternal(const TextureViewDesc& OrigViewDesc, ITex
522526
DEV_CHECK_GL_ERROR("Failed to set GL_TEXTURE_SWIZZLE_B texture parameter");
523527
glTexParameteri(GLViewTarget, GL_TEXTURE_SWIZZLE_A, TextureComponentSwizzleToGLTextureSwizzle(ViewDesc.Swizzle.A, GL_ALPHA));
524528
DEV_CHECK_GL_ERROR("Failed to set GL_TEXTURE_SWIZZLE_A texture parameter");
525-
526529
GLState.BindTexture(-1, GLViewTarget, GLObjectWrappers::GLTextureObj::Null());
527530
}
528531
}

0 commit comments

Comments
 (0)