Skip to content

Commit 858546c

Browse files
IDataBlob: added template versions of GetDataPtr and GetConstDataPtr methods
1 parent 656c769 commit 858546c

File tree

8 files changed

+23
-9
lines changed

8 files changed

+23
-9
lines changed

Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool ShaderGLImpl::GetCompileStatus(IDataBlob** ppCompilerOutput, bool ThrowOnEr
321321
// InfoLogLen accounts for null terminator
322322
auto pOutputDataBlob = DataBlobImpl::Create(InfoLogLen + m_GLSLSourceString.length() + 1);
323323

324-
char* DataPtr = static_cast<char*>(pOutputDataBlob->GetDataPtr());
324+
char* DataPtr = pOutputDataBlob->GetDataPtr<char>();
325325
if (!InfoLog.empty())
326326
{
327327
// Copy info log including null terminator

Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,8 @@ void HLSL2GLSLConverterImpl::ConversionStream::InsertIncludes(String& GLSLSource
798798
pIncludeDataStream->ReadBlob(pIncludeData);
799799

800800
// Get include text
801-
auto IncludeText = reinterpret_cast<const Char*>(pIncludeData->GetDataPtr());
802-
size_t NumSymbols = pIncludeData->GetSize();
801+
const Char* IncludeText = pIncludeData->GetConstDataPtr<Char>();
802+
size_t NumSymbols = pIncludeData->GetSize();
803803

804804
// Insert the text into source
805805
GLSLSource.insert(IncludeStartPos - GLSLSource.begin(), IncludeText, NumSymbols);

Graphics/ShaderTools/include/HLSLUtils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void HandleHLSLCompilerResult(bool CompilationSucceeded,
5959
const auto ShaderSourceLen = ShaderSource.length();
6060
auto pOutputLogBlob = DataBlobImpl::Create(ShaderSourceLen + 1 + CompilerMsgLen + 1);
6161

62-
auto* log = static_cast<char*>(pOutputLogBlob->GetDataPtr());
62+
char* log = pOutputLogBlob->GetDataPtr<char>();
6363

6464
if (CompilerMsg != nullptr)
6565
memcpy(log, CompilerMsg, CompilerMsgLen);

Graphics/ShaderTools/src/GLSLangUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void LogCompilerError(const char* DebugOutputMessage,
247247
if (ppCompilerOutput != nullptr)
248248
{
249249
auto pOutputDataBlob = DataBlobImpl::Create(SourceCodeLen + 1 + ErrorLog.length() + 1);
250-
char* DataPtr = reinterpret_cast<char*>(pOutputDataBlob->GetDataPtr());
250+
char* DataPtr = pOutputDataBlob->GetDataPtr<char>();
251251
memcpy(DataPtr, ErrorLog.data(), ErrorLog.length() + 1);
252252
memcpy(DataPtr + ErrorLog.length() + 1, ShaderSource, SourceCodeLen + 1);
253253
pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ppCompilerOutput));
@@ -321,7 +321,7 @@ class IncluderImpl : public ::glslang::TShader::Includer
321321
auto* pNewInclude =
322322
new IncludeResult{
323323
headerName,
324-
reinterpret_cast<const char*>(pFileData->GetDataPtr()),
324+
pFileData->GetConstDataPtr<char>(),
325325
pFileData->GetSize(),
326326
nullptr};
327327

Graphics/ShaderTools/src/ShaderToolsCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ ShaderSourceFileData ReadShaderSourceFile(const char* Sourc
244244

245245
SourceData.pFileData = DataBlobImpl::Create();
246246
pSourceStream->ReadBlob(SourceData.pFileData);
247-
SourceData.Source = reinterpret_cast<char*>(SourceData.pFileData->GetDataPtr());
247+
SourceData.Source = SourceData.pFileData->GetConstDataPtr<char>();
248248
SourceData.SourceLength = StaticCast<Uint32>(SourceData.pFileData->GetSize());
249249
}
250250
else

Graphics/ShaderTools/src/WGSLShaderResources.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ WGSLShaderResources::WGSLShaderResources(IMemoryAllocator& Allocator,
761761
{
762762
RefCntAutoPtr<DataBlobImpl> pOutputDataBlob = DataBlobImpl::Create(WGSL.length() + 1 + Diagnostics.length() + 1);
763763

764-
char* DataPtr = reinterpret_cast<char*>(pOutputDataBlob->GetDataPtr());
764+
char* DataPtr = pOutputDataBlob->GetDataPtr<char>();
765765
memcpy(DataPtr, Diagnostics.data(), Diagnostics.length() + 1);
766766
memcpy(DataPtr + Diagnostics.length() + 1, WGSL.data(), WGSL.length() + 1);
767767
pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ppTintOutput));

Primitives/interface/DataBlob.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ DILIGENT_BEGIN_INTERFACE(IDataBlob, IObject)
6565
/// Returns const pointer to the internal data buffer
6666
VIRTUAL const void* METHOD(GetConstDataPtr)(THIS_
6767
size_t Offset DEFAULT_VALUE(0)) CONST PURE;
68+
69+
#if DILIGENT_CPP_INTERFACE
70+
template <typename T>
71+
T* GetDataPtr(size_t Offset = 0)
72+
{
73+
return static_cast<T*>(GetDataPtr(Offset));
74+
}
75+
76+
template <typename T>
77+
const T* GetConstDataPtr(size_t Offset = 0) const
78+
{
79+
return static_cast<const T*>(GetConstDataPtr(Offset));
80+
}
81+
#endif
6882
};
6983
DILIGENT_END_INTERFACE
7084

Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void TestBrokenShader(const char* Source,
126126
ASSERT_NE(pErrors, nullptr);
127127
}
128128
ASSERT_NE(pErrors, nullptr);
129-
const char* Msg = reinterpret_cast<const char*>(pErrors->GetDataPtr());
129+
const char* Msg = pErrors->GetConstDataPtr<char>();
130130
LOG_INFO_MESSAGE("Compiler output:\n", Msg);
131131
}
132132

0 commit comments

Comments
 (0)