diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-02-20 06:33:03 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-02-20 06:33:03 +0000 |
| commit | baa883fe0e18431ffede146201e911bc6da7469e (patch) | |
| tree | 352da89a73053d18b3a9fc9cc7ff990f5f81f16e /Graphics/GraphicsEngineOpenGL | |
| parent | HLSL2GLSLConverter: added option to not use layout location qualifiers on sha... (diff) | |
| download | DiligentCore-baa883fe0e18431ffede146201e911bc6da7469e.tar.gz DiligentCore-baa883fe0e18431ffede146201e911bc6da7469e.zip | |
Updated supported texture format tests in GL backend
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index b681708f..c4d2cbb0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -464,8 +464,8 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats() bool bGL43OrAbove = DeviceCaps.DevType == DeviceType::OpenGL && (DeviceCaps.MajorVersion >= 5 || (DeviceCaps.MajorVersion == 4 && DeviceCaps.MinorVersion >= 3) ); - const int TestTextureDim = 32; - const int MaxTexelSize = 16; + constexpr int TestTextureDim = 8; + constexpr int MaxTexelSize = 16; std::vector<Uint8> ZeroData(TestTextureDim * TestTextureDim * MaxTexelSize); // Go through all formats and try to create small 2D texture to check if the format is supported @@ -493,28 +493,52 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats() #endif // Check that the format is indeed supported - if( FmtInfo->Supported ) + if (FmtInfo->Supported) { GLObjectWrappers::GLTextureObj TestGLTex( true ); - // Immediate context is not created yet, so use raw GL functions + // Immediate context has not been created yet, so use raw GL functions glBindTexture( GL_TEXTURE_2D, TestGLTex ); CHECK_GL_ERROR( "Failed to bind texture" ); glTexStorage2D( GL_TEXTURE_2D, 1, GLFmt, TestTextureDim, TestTextureDim ); - CHECK_GL_ERROR( "Failed to allocate storage for the test texture. Test format: ", FmtInfo->Name); - - // It turned out it is not enough to only allocate texture storage - // For some reason glTexStorage2D() may succeed, but upload operation - // will later fail. So we need to additionally try to upload some - // data to the texture - const auto& TransferAttribs = GetNativePixelTransferAttribs( FmtInfo->Format ); - if( FmtInfo->ComponentType != COMPONENT_TYPE_COMPRESSED ) + if (glGetError() == GL_NO_ERROR) + { + // It turned out it is not enough to only allocate texture storage + // For some reason glTexStorage2D() may succeed, but upload operation + // will later fail. So we need to additionally try to upload some + // data to the texture + const auto& TransferAttribs = GetNativePixelTransferAttribs(FmtInfo->Format); + if (TransferAttribs.IsCompressed) + { + const auto& FmtAttribs = GetTextureFormatAttribs(FmtInfo->Format); + static_assert( (TestTextureDim & (TestTextureDim-1)) == 0, "Test texture dim must be power of two!"); + auto BlockBytesInRow = (TestTextureDim/int{FmtAttribs.BlockWidth}) * int{FmtAttribs.ComponentSize}; + glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, // mip level + 0, 0, TestTextureDim, TestTextureDim, + GLFmt, + (TestTextureDim/int{FmtAttribs.BlockHeight}) * BlockBytesInRow, + ZeroData.data() ); + } + else + { + glTexSubImage2D( GL_TEXTURE_2D, 0, // mip level + 0, 0, TestTextureDim, TestTextureDim, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + ZeroData.data() ); + } + + if (glGetError() != GL_NO_ERROR) + { + LOG_WARNING_MESSAGE("Failed to upload data to a test ", TestTextureDim, "x", TestTextureDim, " ", FmtInfo->Name, " texture. " + "This likely indicates that the format is not supported despite being reported so by the device."); + FmtInfo->Supported = false; + } + } + else { - glTexSubImage2D( GL_TEXTURE_2D, 0, // mip level - 0, 0, TestTextureDim, TestTextureDim, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - ZeroData.data() ); + LOG_WARNING_MESSAGE( "Failed to allocate storage for a test ", TestTextureDim, "x", TestTextureDim, " ", FmtInfo->Name, " texture. " + "This likely indicates that the format is not supported despite being reported so by the device."); + FmtInfo->Supported = false; } - CHECK_GL_ERROR( "Failed to upload data to the test texture. Test format: ", FmtInfo->Name); glBindTexture( GL_TEXTURE_2D, 0 ); } } |
