14
14
#include " Constants.h"
15
15
#include " Context.h"
16
16
#include " render/renderer/buffer/Buffer.h"
17
+ #include " resources/PackFileData.h"
17
18
#include " resources/ResourceSystem.h"
18
19
#include " resources/Texture2DData.h"
19
20
#include " utils/Descriptor.h"
@@ -93,14 +94,21 @@ Texture2D& Texture2D::operator=(Texture2D&& other)
93
94
void Texture2D::LoadFromFile (const char * filePath)
94
95
{
95
96
PackFile* packFile = ResourceSystem::GetInstance ().GetPackFile ();
96
- std::shared_ptr<Texture2DData> texture2dData = packFile->FindData <Texture2DData>(filePath);
97
- uint64_t imageSize = texture2dData->GetImageSize ();
98
- const uint8_t * pixelPtr = texture2dData->GetPixels ();
97
+ std::shared_ptr<PackFileData> texture2dDataBuffer = packFile->FindData <PackFileData>(filePath);
98
+
99
+ BinarySerialisation::Buffer buffer;
100
+ uint8_t * data = reinterpret_cast <uint8_t *>(texture2dDataBuffer->data );
101
+ size_t dataSize = texture2dDataBuffer->dataSize ;
102
+ buffer.data .assign (data, dataSize);
103
+
104
+ // TODO - Fold into resource system
105
+ Texture2DData texture2dData;
106
+ texture2dData.serialise (buffer, BinarySerialisation::DESERIALISE);
99
107
100
108
Buffer::Buffer stagingBuffer;
101
109
defer ([&stagingBuffer] { Buffer::DestroyBuffer (stagingBuffer); });
102
110
103
- Buffer::CreateBuffer (imageSize ,
111
+ Buffer::CreateBuffer (texture2dData. GetImageSize () ,
104
112
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
105
113
// specifies that data is accessible on the CPU.
106
114
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
@@ -109,13 +117,13 @@ void Texture2D::LoadFromFile(const char* filePath)
109
117
OUT stagingBuffer.buffer ,
110
118
OUT stagingBuffer.bufferMemory );
111
119
112
- Buffer::CopyData (stagingBuffer, imageSize, pixelPtr );
120
+ Buffer::CopyData (stagingBuffer, texture2dData. GetImageSize (), texture2dData. pixels . data () );
113
121
114
- extent = {static_cast <uint32_t >(texture2dData-> texWidth ),
115
- static_cast <uint32_t >(texture2dData-> texHeight )};
122
+ extent = {static_cast <uint32_t >(texture2dData. texWidth ),
123
+ static_cast <uint32_t >(texture2dData. texHeight )};
116
124
117
- Utils::Extent3D imageExtent {static_cast <uint32_t >(texture2dData-> texWidth ),
118
- static_cast <uint32_t >(texture2dData-> texHeight ),
125
+ Utils::Extent3D imageExtent {static_cast <uint32_t >(texture2dData. texWidth ),
126
+ static_cast <uint32_t >(texture2dData. texHeight ),
119
127
1 };
120
128
image = Image ({Utils::RGBASRGB, imageExtent, Vulkan::Utils::USAGE_TEXTURE, 1 , 1 });
121
129
0 commit comments