@@ -47,6 +47,59 @@ Index of this file:
47
47
// [SECTION] structs
48
48
//-----------------------------------------------------------------------------
49
49
50
+ typedef int DXGI_FORMAT ;
51
+ typedef int D3D10_RESOURCE_DIMENSION ;
52
+
53
+ typedef struct _plDssPixelFormat
54
+ {
55
+ uint32_t uSize ;
56
+ uint32_t uFlags ;
57
+ uint32_t uFourCC ;
58
+ uint32_t uRGBBitCount ;
59
+ uint32_t uRBitMask ;
60
+ uint32_t uGBitMask ;
61
+ uint32_t uBBitMask ;
62
+ uint32_t uABitMask ;
63
+ } plDssPixelFormat ;
64
+
65
+ typedef struct _plDdsInternalHeader
66
+ {
67
+ uint32_t uSize ;
68
+ uint32_t uFlags ;
69
+ uint32_t uHeight ;
70
+ uint32_t uWidth ;
71
+ uint32_t uPitchOrLinearSize ;
72
+ uint32_t uDepth ;
73
+ uint32_t uMipMapCount ;
74
+ uint32_t auReserved1 [11 ];
75
+ plDssPixelFormat ddspf ;
76
+ uint32_t uCaps ;
77
+ uint32_t uCaps2 ;
78
+ uint32_t uCaps3 ;
79
+ uint32_t uCaps4 ;
80
+ uint32_t uReserved2 ;
81
+ } plDdsInternalHeader ;
82
+
83
+ typedef struct _plDdsHeaderDxt10
84
+ {
85
+ DXGI_FORMAT tDxgiFormat ;
86
+ D3D10_RESOURCE_DIMENSION tResourceDimension ;
87
+ uint32_t uMiscFlag ;
88
+ uint32_t uArraySize ;
89
+ uint32_t uMiscFlags2 ;
90
+ } plDdsHeaderDxt10 ;
91
+
92
+ typedef struct _plDdsHeader
93
+ {
94
+ uint32_t uMagic ;
95
+ plDdsInternalHeader tHeader ;
96
+ plDdsHeaderDxt10 tHeader10 ;
97
+ } plDdsHeader ;
98
+
99
+ //-----------------------------------------------------------------------------
100
+ // [SECTION] public api
101
+ //-----------------------------------------------------------------------------
102
+
50
103
typedef struct _plAppData
51
104
{
52
105
// window
@@ -254,7 +307,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
254
307
// create vertex buffer
255
308
const plBufferDesc tStagingBufferDesc = {
256
309
.tUsage = PL_BUFFER_USAGE_STAGING ,
257
- .szByteSize = 1280000 ,
310
+ .szByteSize = 1280000 * 2 ,
258
311
.pcDebugName = "staging buffer"
259
312
};
260
313
ptAppData -> tStagingBuffer = gptGfx -> create_buffer (ptDevice , & tStagingBufferDesc , NULL );
@@ -284,24 +337,26 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
284
337
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~textures~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285
338
286
339
// load image file from disk
287
- size_t szImageFileSize = gptVfs -> get_file_size_str ("/assets/textures/SpriteMapExample.png " );
288
- plVfsFileHandle tSpriteSheet = gptVfs -> open_file ("/assets/textures/SpriteMapExample.png " , PL_VFS_FILE_MODE_READ );
340
+ size_t szImageFileSize = gptVfs -> get_file_size_str ("/assets/textures/sprite.dds " );
341
+ plVfsFileHandle tSpriteSheet = gptVfs -> open_file ("/assets/textures/sprite.dds " , PL_VFS_FILE_MODE_READ );
289
342
gptVfs -> read_file (tSpriteSheet , NULL , & szImageFileSize );
290
343
unsigned char * pucBuffer = malloc (szImageFileSize );
291
344
gptVfs -> read_file (tSpriteSheet , pucBuffer , & szImageFileSize );
292
345
gptVfs -> close_file (tSpriteSheet );
293
346
347
+ plDdsHeader * ptHeader = (plDdsHeader * )pucBuffer ;
348
+
294
349
// load actual data from file data
295
- int iImageWidth = 0 ;
296
- int iImageHeight = 0 ;
297
- int _unused ;
298
- unsigned char * pucImageData = gptImage -> load (pucBuffer , (int )szImageFileSize , & iImageWidth , & iImageHeight , & _unused , 4 );
299
- free (pucBuffer );
350
+ // int iImageWidth = 0;
351
+ // int iImageHeight = 0;
352
+ // int _unused;
353
+ // unsigned char* pucImageData = gptImage->load(pucBuffer, (int)szImageFileSize, &iImageWidth, &iImageHeight, &_unused, 4);
354
+ // free(pucBuffer);
300
355
301
356
// create texture
302
357
const plTextureDesc tTextureDesc = {
303
- .tDimensions = { (float )iImageWidth , (float )iImageHeight , 1 },
304
- .tFormat = PL_FORMAT_R8G8B8A8_UNORM ,
358
+ .tDimensions = { (float )ptHeader -> tHeader . uWidth , (float )ptHeader -> tHeader . uHeight , 1 },
359
+ .tFormat = PL_FORMAT_BC2_UNORM ,
305
360
.uLayers = 1 ,
306
361
.uMips = 1 ,
307
362
.tType = PL_TEXTURE_TYPE_2D ,
@@ -327,11 +382,20 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
327
382
gptGfx -> set_texture_usage (ptEncoder , ptAppData -> tTexture , PL_TEXTURE_USAGE_SAMPLED , 0 );
328
383
329
384
// copy memory to mapped staging buffer
330
- memcpy (& ptStagingBuffer -> tMemoryAllocation .pHostMapped [2048 ], pucImageData , iImageWidth * iImageHeight * 4 );
385
+ // memcpy(&ptStagingBuffer->tMemoryAllocation.pHostMapped[2048], &pucBuffer[sizeof(plDdsHeader)], ptHeader->tHeader.uWidth * ptHeader->tHeader.uHeight * 4);
386
+
387
+ size_t uPitch = pl_max ( 1 , ((ptHeader -> tHeader .uWidth + 3 )/4 ) ) * 4 ;
388
+ // size_t uPitch = (ptHeader->tHeader.uWidth + 4 - 1) / 4;
389
+ // uPitch = uPitch * 128 / 8;
390
+
391
+ for (uint32_t i = 0 ; i < ptHeader -> tHeader .uHeight ; i ++ )
392
+ {
393
+ memcpy (& ptStagingBuffer -> tMemoryAllocation .pHostMapped [2048 + i * uPitch ], & pucBuffer [sizeof (plDdsHeader ) + i * uPitch ], uPitch );
394
+ }
331
395
332
396
const plBufferImageCopy tBufferImageCopy = {
333
- .uImageWidth = ( uint32_t ) iImageWidth ,
334
- .uImageHeight = ( uint32_t ) iImageHeight ,
397
+ .uImageWidth = ptHeader -> tHeader . uWidth ,
398
+ .uImageHeight = ptHeader -> tHeader . uHeight ,
335
399
.uImageDepth = 1 ,
336
400
.uLayerCount = 1 ,
337
401
.szBufferOffset = 2048
@@ -342,7 +406,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
342
406
gptStarter -> return_blit_encoder (ptEncoder );
343
407
344
408
// free image data
345
- gptImage -> free (pucImageData );
409
+ // gptImage->free(pucImageData);
346
410
347
411
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~samplers~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
348
412
0 commit comments