Skip to content

Commit dea4627

Browse files
Use template versions of IDataBlob::GetDataPtr and IDataBlob::GetConstDataPtr methods
1 parent 3180aff commit dea4627

File tree

11 files changed

+31
-34
lines changed

11 files changed

+31
-34
lines changed

AssetLoader/interface/DXSDKMeshLoader.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -331,7 +331,7 @@ class DXSDKMesh
331331
virtual ~DXSDKMesh();
332332

333333
bool Create(const Char* szFileName);
334-
bool Create(Uint8* pData, Uint32 DataUint8s);
334+
bool Create(const Uint8* pData, Uint32 DataUint8s);
335335
void LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* pDevice, IDeviceContext* pDeviceCtx);
336336
void Destroy();
337337

@@ -400,8 +400,7 @@ class DXSDKMesh
400400
protected:
401401
bool CreateFromFile(const char* szFileName);
402402

403-
bool CreateFromMemory(Uint8* pData,
404-
Uint32 DataUint8s);
403+
bool CreateFromMemory(const Uint8* pData, Uint32 DataUint8s);
405404

406405
void ComputeBoundingBoxes();
407406

AssetLoader/src/DXSDKMeshLoader.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -56,8 +56,7 @@ bool DXSDKMesh::CreateFromFile(const char* szFileName)
5656

5757
File.Close();
5858

59-
auto res = CreateFromMemory(reinterpret_cast<Uint8*>(pFileData->GetDataPtr()),
60-
static_cast<Uint32>(pFileData->GetSize()));
59+
auto res = CreateFromMemory(pFileData->GetConstDataPtr<Uint8>(), static_cast<Uint32>(pFileData->GetSize()));
6160

6261
return res;
6362
}
@@ -103,8 +102,7 @@ void DXSDKMesh::ComputeBoundingBoxes()
103102
}
104103
}
105104

106-
bool DXSDKMesh::CreateFromMemory(Uint8* pData,
107-
Uint32 DataUint8s)
105+
bool DXSDKMesh::CreateFromMemory(const Uint8* pData, Uint32 DataUint8s)
108106
{
109107
m_StaticMeshData.resize(DataUint8s);
110108
memcpy(m_StaticMeshData.data(), pData, DataUint8s);
@@ -281,7 +279,7 @@ bool DXSDKMesh::Create(const Char* szFileName)
281279
}
282280

283281
//--------------------------------------------------------------------------------------
284-
bool DXSDKMesh::Create(Uint8* pData, Uint32 DataUint8s)
282+
bool DXSDKMesh::Create(const Uint8* pData, Uint32 DataUint8s)
285283
{
286284
return CreateFromMemory(pData, DataUint8s);
287285
}

HLSL2GLSLConverter/src/HLSL2GLSLConverterApp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int HLSL2GLSLConverterApp::Convert(IRenderDevice* pDevice)
164164
}
165165
auto pHLSLSourceBlob = DataBlobImpl::Create();
166166
pInputFileStream->ReadBlob(pHLSLSourceBlob);
167-
auto* HLSLSource = reinterpret_cast<char*>(pHLSLSourceBlob->GetDataPtr());
167+
char* HLSLSource = pHLSLSourceBlob->GetDataPtr<char>();
168168
auto SourceLen = static_cast<Int32>(pHLSLSourceBlob->GetSize());
169169

170170
RefCntAutoPtr<IHLSL2GLSLConverter> pConverter;
@@ -208,7 +208,7 @@ int HLSL2GLSLConverterApp::Convert(IRenderDevice* pDevice)
208208
ShaderCreateInfo ShaderCI;
209209
ShaderCI.EntryPoint = m_EntryPoint.c_str();
210210
ShaderCI.Desc = {"Test shader", m_ShaderType, true};
211-
ShaderCI.Source = reinterpret_cast<const char*>(pGLSLSourceBlob->GetConstDataPtr());
211+
ShaderCI.Source = pGLSLSourceBlob->GetConstDataPtr<char>();
212212
ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_GLSL;
213213
RefCntAutoPtr<IShader> pTestShader;
214214
pDevice->CreateShader(ShaderCI, &pTestShader);
@@ -222,7 +222,7 @@ int HLSL2GLSLConverterApp::Convert(IRenderDevice* pDevice)
222222

223223
if (m_PrintConvertedSource)
224224
{
225-
LOG_INFO_MESSAGE("Converted GLSL:\n", reinterpret_cast<const char*>(pGLSLSourceBlob->GetConstDataPtr()));
225+
LOG_INFO_MESSAGE("Converted GLSL:\n", pGLSLSourceBlob->GetConstDataPtr<char>());
226226
}
227227

228228
return 0;

RenderStateNotation/src/RenderStateNotationParserImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -302,7 +302,7 @@ Bool RenderStateNotationParserImpl::ParseFileInternal(const Char*
302302
auto pFileData = DataBlobImpl::Create();
303303
pFileStream->ReadBlob(pFileData);
304304

305-
if (!ParseStringInternal(static_cast<const char*>(pFileData->GetConstDataPtr()), StaticCast<Uint32>(pFileData->GetSize()), pStreamFactory))
305+
if (!ParseStringInternal(pFileData->GetConstDataPtr<char>(), StaticCast<Uint32>(pFileData->GetSize()), pStreamFactory))
306306
LOG_ERROR_AND_THROW("Failed to parse file: '", FilePath, "'.");
307307
}
308308

RenderStatePackager/src/ParsingEnvironment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@ bool ParsingEnvironment::Initialize()
9494
auto pFileData = DataBlobImpl::Create(0);
9595
File->Read(pFileData);
9696

97-
ParseRSNDeviceCreateInfo(static_cast<const char*>(pFileData->GetConstDataPtr()), StaticCast<Uint32>(pFileData->GetSize()), DeviceCI, Allocator);
97+
ParseRSNDeviceCreateInfo(pFileData->GetConstDataPtr<char>(), StaticCast<Uint32>(pFileData->GetSize()), DeviceCI, Allocator);
9898
}
9999

100100
auto ConstructString = [](std::vector<std::string> const& Paths) {

Tests/DiligentToolsTest/include/DRSNLoader.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ inline nlohmann::json LoadDRSNFromFile(const Char* FilePath)
6060

6161
auto pFileData = DataBlobImpl::Create();
6262
File->Read(pFileData);
63-
Json = nlohmann::json::parse(String{reinterpret_cast<const char*>(pFileData->GetConstDataPtr()), pFileData->GetSize()});
63+
Json = nlohmann::json::parse(String{pFileData->GetConstDataPtr<char>(), pFileData->GetSize()});
6464
}
6565
catch (std::runtime_error& err)
6666
{

Tests/DiligentToolsTest/src/JPEGCodecTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -72,7 +72,7 @@ TEST(Tools_TextureLoader, JPEGCodec)
7272
ASSERT_EQ(DecodedImgDesc.NumComponents, NumComponents);
7373
ASSERT_EQ(DecodedImgDesc.ComponentType, VT_UINT8);
7474

75-
const Uint8* pTestPixels = reinterpret_cast<const Uint8*>(pDecodedPixelsBlob->GetDataPtr());
75+
const Uint8* pTestPixels = pDecodedPixelsBlob->GetConstDataPtr<Uint8>();
7676
for (Uint32 y = 0; y < TestImgHeight; ++y)
7777
{
7878
for (Uint32 x = 0; x < TestImgWidth; ++x)

Tests/DiligentToolsTest/src/PNGCodecTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -80,7 +80,7 @@ TEST(Tools_TextureLoader, PNGCodec)
8080
ASSERT_EQ(DecodedImgDesc.NumComponents, NumComponents);
8181
ASSERT_EQ(DecodedImgDesc.ComponentType, VT_UINT8);
8282

83-
const Uint8* pTestPixels = reinterpret_cast<const Uint8*>(pDecodedPixelsBlob->GetDataPtr());
83+
const Uint8* pTestPixels = pDecodedPixelsBlob->GetConstDataPtr<Uint8>();
8484
for (Uint32 y = 0; y < TestImgHeight; ++y)
8585
{
8686
for (Uint32 x = 0; x < TestImgWidth; ++x)

TextureLoader/src/Image.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void Image::LoadTiffFile(IDataBlob* pFileData, const ImageLoadInfo& LoadInfo)
231231
if (PlanarConfig == PLANARCONFIG_CONTIG || m_Desc.NumComponents == 1)
232232
{
233233
VERIFY_EXPR(m_Desc.RowStride >= ScanlineSize);
234-
auto* pDataPtr = reinterpret_cast<Uint8*>(m_pData->GetDataPtr());
234+
Uint8* pDataPtr = m_pData->GetDataPtr<Uint8>();
235235
for (Uint32 row = 0; row < m_Desc.Height; row++, pDataPtr += m_Desc.RowStride)
236236
{
237237
TIFFReadScanline(TiffFile, pDataPtr, row);
@@ -244,7 +244,7 @@ void Image::LoadTiffFile(IDataBlob* pFileData, const ImageLoadInfo& LoadInfo)
244244
{
245245
for (Uint16 comp = 0; comp < m_Desc.NumComponents; ++comp)
246246
{
247-
auto* const pDstRow = reinterpret_cast<Uint8*>(m_pData->GetDataPtr()) + m_Desc.RowStride * row + comp;
247+
Uint8* const pDstRow = m_pData->GetDataPtr<Uint8>() + m_Desc.RowStride * row + comp;
248248

249249
TIFFReadScanline(TiffFile, ScanlineData.data(), row, comp);
250250

@@ -286,7 +286,7 @@ void Image::LoadTiffFile(IDataBlob* pFileData, const ImageLoadInfo& LoadInfo)
286286
static bool LoadHDRFile(IDataBlob* pSrcHdrBits, IDataBlob* pDstPixels, ImageDesc* pDstImgDesc)
287287
{
288288
Int32 Width = 0, Height = 0, NumComponents = 0;
289-
float* pFloatData = stbi_loadf_from_memory(static_cast<const Uint8*>(pSrcHdrBits->GetConstDataPtr()), static_cast<Int32>(pSrcHdrBits->GetSize()), &Width, &Height, &NumComponents, 0);
289+
float* pFloatData = stbi_loadf_from_memory(pSrcHdrBits->GetConstDataPtr<stbi_uc>(), static_cast<Int32>(pSrcHdrBits->GetSize()), &Width, &Height, &NumComponents, 0);
290290
if (pFloatData == nullptr)
291291
{
292292
LOG_ERROR_MESSAGE("Failed to load HDR image from memory. STB supports only 32-bit rle rgbe textures");
@@ -308,7 +308,7 @@ static bool LoadHDRFile(IDataBlob* pSrcHdrBits, IDataBlob* pDstPixels, ImageDesc
308308
static bool LoadTGAFile(IDataBlob* pSrcTgaBits, IDataBlob* pDstPixels, ImageDesc* pDstImgDesc)
309309
{
310310
Int32 Width = 0, Height = 0, NumComponents = 0;
311-
Uint8* pFloatData = stbi_load_from_memory(static_cast<const Uint8*>(pSrcTgaBits->GetConstDataPtr()), static_cast<Int32>(pSrcTgaBits->GetSize()), &Width, &Height, &NumComponents, 0);
311+
Uint8* pFloatData = stbi_load_from_memory(pSrcTgaBits->GetConstDataPtr<stbi_uc>(), static_cast<Int32>(pSrcTgaBits->GetSize()), &Width, &Height, &NumComponents, 0);
312312
if (pFloatData == nullptr)
313313
{
314314
LOG_ERROR_MESSAGE("Failed to load TGA image from memory");
@@ -657,7 +657,7 @@ IMAGE_FILE_FORMAT CreateImageFromFile(const Char* FilePath,
657657
auto pFileData = DataBlobImpl::Create();
658658
pFileStream->ReadBlob(pFileData);
659659

660-
ImgFileFormat = Image::GetFileFormat(static_cast<const Uint8*>(pFileData->GetDataPtr()), pFileData->GetSize(), FilePath);
660+
ImgFileFormat = Image::GetFileFormat(pFileData->GetConstDataPtr<Uint8>(), pFileData->GetSize(), FilePath);
661661
if (ImgFileFormat == IMAGE_FILE_FORMAT_UNKNOWN)
662662
{
663663
LOG_ERROR_AND_THROW("Unable to derive image format for file '", FilePath, "\".");

TextureLoader/src/SGILoader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ bool LoadSGI(IDataBlob* pSGIData,
6363
ImageDesc* pDstImgDesc)
6464
{
6565
VERIFY_EXPR(pSGIData != nullptr && pDstPixels != nullptr && pDstImgDesc != nullptr);
66-
const auto* pDataStart = reinterpret_cast<const Uint8*>(pSGIData->GetConstDataPtr());
67-
const auto Size = pSGIData->GetSize();
68-
const auto* pDataEnd = pDataStart + Size;
69-
const auto* pSrcPtr = pDataStart;
66+
const Uint8* pDataStart = pSGIData->GetConstDataPtr<Uint8>();
67+
const size_t Size = pSGIData->GetSize();
68+
const Uint8* pDataEnd = pDataStart + Size;
69+
const Uint8* pSrcPtr = pDataStart;
7070

7171
if (Size < sizeof(SGIHeader))
7272
{
@@ -113,7 +113,7 @@ bool LoadSGI(IDataBlob* pSGIData,
113113

114114
pDstImgDesc->RowStride = Width * NumChannels * BytesPerChannel;
115115
pDstPixels->Resize(size_t{Height} * pDstImgDesc->RowStride);
116-
auto* pDstPtr = reinterpret_cast<Uint8*>(pDstPixels->GetDataPtr());
116+
Uint8* pDstPtr = pDstPixels->GetDataPtr<Uint8>();
117117

118118
if (Header.Compression == 0)
119119
{

0 commit comments

Comments
 (0)