diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp index 3752a0760..1595f1045 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp @@ -321,7 +321,7 @@ bool ShaderGLImpl::GetCompileStatus(IDataBlob** ppCompilerOutput, bool ThrowOnEr // InfoLogLen accounts for null terminator auto pOutputDataBlob = DataBlobImpl::Create(InfoLogLen + m_GLSLSourceString.length() + 1); - char* DataPtr = static_cast(pOutputDataBlob->GetDataPtr()); + char* DataPtr = pOutputDataBlob->GetDataPtr(); if (!InfoLog.empty()) { // Copy info log including null terminator diff --git a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp index 9d3395d31..58168dc29 100644 --- a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp +++ b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp @@ -798,8 +798,8 @@ void HLSL2GLSLConverterImpl::ConversionStream::InsertIncludes(String& GLSLSource pIncludeDataStream->ReadBlob(pIncludeData); // Get include text - auto IncludeText = reinterpret_cast(pIncludeData->GetDataPtr()); - size_t NumSymbols = pIncludeData->GetSize(); + const Char* IncludeText = pIncludeData->GetConstDataPtr(); + size_t NumSymbols = pIncludeData->GetSize(); // Insert the text into source GLSLSource.insert(IncludeStartPos - GLSLSource.begin(), IncludeText, NumSymbols); diff --git a/Graphics/ShaderTools/include/HLSLUtils.hpp b/Graphics/ShaderTools/include/HLSLUtils.hpp index 20e40866c..1e66cb559 100644 --- a/Graphics/ShaderTools/include/HLSLUtils.hpp +++ b/Graphics/ShaderTools/include/HLSLUtils.hpp @@ -59,7 +59,7 @@ void HandleHLSLCompilerResult(bool CompilationSucceeded, const auto ShaderSourceLen = ShaderSource.length(); auto pOutputLogBlob = DataBlobImpl::Create(ShaderSourceLen + 1 + CompilerMsgLen + 1); - auto* log = static_cast(pOutputLogBlob->GetDataPtr()); + char* log = pOutputLogBlob->GetDataPtr(); if (CompilerMsg != nullptr) memcpy(log, CompilerMsg, CompilerMsgLen); diff --git a/Graphics/ShaderTools/src/GLSLangUtils.cpp b/Graphics/ShaderTools/src/GLSLangUtils.cpp index bb0edeb25..776ad4a2e 100644 --- a/Graphics/ShaderTools/src/GLSLangUtils.cpp +++ b/Graphics/ShaderTools/src/GLSLangUtils.cpp @@ -247,7 +247,7 @@ void LogCompilerError(const char* DebugOutputMessage, if (ppCompilerOutput != nullptr) { auto pOutputDataBlob = DataBlobImpl::Create(SourceCodeLen + 1 + ErrorLog.length() + 1); - char* DataPtr = reinterpret_cast(pOutputDataBlob->GetDataPtr()); + char* DataPtr = pOutputDataBlob->GetDataPtr(); memcpy(DataPtr, ErrorLog.data(), ErrorLog.length() + 1); memcpy(DataPtr + ErrorLog.length() + 1, ShaderSource, SourceCodeLen + 1); pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast(ppCompilerOutput)); @@ -321,7 +321,7 @@ class IncluderImpl : public ::glslang::TShader::Includer auto* pNewInclude = new IncludeResult{ headerName, - reinterpret_cast(pFileData->GetDataPtr()), + pFileData->GetConstDataPtr(), pFileData->GetSize(), nullptr}; diff --git a/Graphics/ShaderTools/src/ShaderToolsCommon.cpp b/Graphics/ShaderTools/src/ShaderToolsCommon.cpp index 08b4b33f8..b00151c12 100644 --- a/Graphics/ShaderTools/src/ShaderToolsCommon.cpp +++ b/Graphics/ShaderTools/src/ShaderToolsCommon.cpp @@ -244,7 +244,7 @@ ShaderSourceFileData ReadShaderSourceFile(const char* Sourc SourceData.pFileData = DataBlobImpl::Create(); pSourceStream->ReadBlob(SourceData.pFileData); - SourceData.Source = reinterpret_cast(SourceData.pFileData->GetDataPtr()); + SourceData.Source = SourceData.pFileData->GetConstDataPtr(); SourceData.SourceLength = StaticCast(SourceData.pFileData->GetSize()); } else diff --git a/Graphics/ShaderTools/src/WGSLShaderResources.cpp b/Graphics/ShaderTools/src/WGSLShaderResources.cpp index 212ff149c..a701931e9 100644 --- a/Graphics/ShaderTools/src/WGSLShaderResources.cpp +++ b/Graphics/ShaderTools/src/WGSLShaderResources.cpp @@ -761,7 +761,7 @@ WGSLShaderResources::WGSLShaderResources(IMemoryAllocator& Allocator, { RefCntAutoPtr pOutputDataBlob = DataBlobImpl::Create(WGSL.length() + 1 + Diagnostics.length() + 1); - char* DataPtr = reinterpret_cast(pOutputDataBlob->GetDataPtr()); + char* DataPtr = pOutputDataBlob->GetDataPtr(); memcpy(DataPtr, Diagnostics.data(), Diagnostics.length() + 1); memcpy(DataPtr + Diagnostics.length() + 1, WGSL.data(), WGSL.length() + 1); pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast(ppTintOutput)); diff --git a/Primitives/interface/DataBlob.h b/Primitives/interface/DataBlob.h index 0ddbb2feb..301a51f59 100644 --- a/Primitives/interface/DataBlob.h +++ b/Primitives/interface/DataBlob.h @@ -65,6 +65,20 @@ DILIGENT_BEGIN_INTERFACE(IDataBlob, IObject) /// Returns const pointer to the internal data buffer VIRTUAL const void* METHOD(GetConstDataPtr)(THIS_ size_t Offset DEFAULT_VALUE(0)) CONST PURE; + +#if DILIGENT_CPP_INTERFACE + template + T* GetDataPtr(size_t Offset = 0) + { + return static_cast(GetDataPtr(Offset)); + } + + template + const T* GetConstDataPtr(size_t Offset = 0) const + { + return static_cast(GetConstDataPtr(Offset)); + } +#endif }; DILIGENT_END_INTERFACE diff --git a/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp b/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp index 3cd697f3c..a9c598467 100644 --- a/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp +++ b/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp @@ -126,7 +126,7 @@ void TestBrokenShader(const char* Source, ASSERT_NE(pErrors, nullptr); } ASSERT_NE(pErrors, nullptr); - const char* Msg = reinterpret_cast(pErrors->GetDataPtr()); + const char* Msg = pErrors->GetConstDataPtr(); LOG_INFO_MESSAGE("Compiler output:\n", Msg); }