Skip to content

Commit eeae3cc

Browse files
committed
WIP
1 parent 0af3eb8 commit eeae3cc

File tree

7 files changed

+35
-23
lines changed

7 files changed

+35
-23
lines changed

editor/app.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
334334
plRendererSettings tRenderSettings = {
335335
.ptDevice = ptAppData->ptDevice,
336336
.ptSwap = gptStarter->get_swapchain(),
337-
.uMaxTextureResolution = 1024,
337+
.uMaxTextureResolution = 1024 * 4,
338338
};
339339
gptRenderer->initialize(tRenderSettings);
340340

@@ -474,9 +474,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
474474
gptRenderer->load_skybox_from_panorama(ptAppData->ptScene, "/environments/helipad.hdr", 1024);
475475

476476
plModelLoaderData tLoaderData0 = {0};
477-
gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "/models/gltf/humanoid/model.gltf", NULL, &tLoaderData0);
477+
// gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "/models/gltf/humanoid/model.gltf", NULL, &tLoaderData0);
478478
// gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "/models/gltf/humanoid/floor.gltf", NULL, &tLoaderData0);
479-
gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "/gltf/Sponza/glTF/Sponza.gltf", NULL, &tLoaderData0);
479+
// gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "/gltf/Sponza/glTF/Sponza.gltf", NULL, &tLoaderData0);
480+
gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "C:/Users/Jonathan Hoffstadt/Documents/Models/BistroExteriorGltf/bistro_exterior.gltf", NULL, &tLoaderData0);
480481
// gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "/models/gltf/sort.gltf", NULL, &tLoaderData0);
481482
// plMat4 tRotation = pl_mat4_rotate_xyz(-PL_PI_2, 0.0f, 1.0f, 0.0f);
482483
// gptModelLoader->load_gltf(ptAppData->ptComponentLibrary, "/gltf/CarConcept/glTF/CarConcept.gltf", &tRotation, &tLoaderData0);

extensions/pl_dxt_ext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Index of this file:
2626
* 1 channel -> PL_FORMAT_BC4_*
2727
* 2 channel -> PL_FORMAT_BC5_*
2828
* 3 channel -> PL_FORMAT_BC1_*
29-
* 4 channel -> PL_FORMAT_BC2_*
29+
* 4 channel -> PL_FORMAT_BC3_*
3030
*/
3131

3232
//-----------------------------------------------------------------------------

extensions/pl_graphics_ext.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ pl__format_stride(plFormat tFormat)
433433
case PL_FORMAT_EAC_R11G11_UNORM:
434434
case PL_FORMAT_EAC_R11G11_SNORM:
435435
return 64 / (4 * 8);
436-
437-
case PL_FORMAT_BC2_SRGB:
436+
438437
case PL_FORMAT_BC2_UNORM:
438+
case PL_FORMAT_BC2_SRGB:
439439
case PL_FORMAT_BC3_UNORM:
440440
case PL_FORMAT_BC3_SRGB:
441441
case PL_FORMAT_BC5_UNORM:

extensions/pl_graphics_metal.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,19 @@
873873
tDesc.pcDebugName = "unnamed texture";
874874

875875
if(tDesc.uMips == 0)
876-
tDesc.uMips = (uint32_t)floorf(log2f((float)pl_maxi((int)tDesc.tDimensions.x, (int)tDesc.tDimensions.y))) + 1u;
876+
tDesc.uMips = (uint32_t)floorf(log2f((float)pl_maxi((int)tDesc.tDimensions.x, (int)tDesc.tDimensions.y))) + 1;
877+
878+
for(uint32_t uMipLevel = 1; uMipLevel < tDesc.uMips; uMipLevel++)
879+
{
880+
int iCurrentWidth = (int)tDesc.tDimensions.x / ((1 << (int)uMipLevel));
881+
int iCurrentHeight = (int)tDesc.tDimensions.y / ((1 << (int)uMipLevel));
882+
883+
if(iCurrentHeight < 4 || iCurrentWidth < 4)
884+
{
885+
tDesc.uMips = uMipLevel;
886+
break;
887+
}
888+
}
877889

878890
ptTexture->tDesc = tDesc,
879891
ptTexture->tView = (plTextureViewDesc){

extensions/pl_model_loader_ext.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ pl__load_gltf_texture(const char* pcPath, plTextureSlot tSlot, const cgltf_textu
424424

425425
pl_str_get_file_name_only(ptTexture->texture->image->mime_type, pcNext, 4);
426426
strcpy(ptMaterial->atTextureMaps[tSlot].acName, acResourceName);
427-
ptMaterial->atTextureMaps[tSlot].tResource = gptResource->load_ex(acResourceName, 0, (uint8_t*)pucActualBuffer, ptTexture->texture->image->buffer_view->size, pcPath, 0);
427+
ptMaterial->atTextureMaps[tSlot].tResource = gptResource->load_ex(acResourceName, PL_RESOURCE_LOAD_FLAG_BLOCK_COMPRESSED, (uint8_t*)pucActualBuffer, ptTexture->texture->image->buffer_view->size, pcPath, 0);
428428
}
429429
else if(strncmp(ptTexture->texture->image->uri, "data:", 5) == 0)
430430
{
@@ -457,7 +457,8 @@ pl__load_gltf_texture(const char* pcPath, plTextureSlot tSlot, const cgltf_textu
457457
char acFilepath[2048] = {0};
458458
strcpy(acFilepath, pcDirectory);
459459
pl_str_concatenate(acFilepath, ptMaterial->atTextureMaps[tSlot].acName, acFilepath, 2048);
460-
ptMaterial->atTextureMaps[tSlot].tResource = gptResource->load(acFilepath, 0);
460+
// ptMaterial->atTextureMaps[tSlot].tResource = gptResource->load(acFilepath, PL_RESOURCE_LOAD_FLAG_BLOCK_COMPRESSED);
461+
ptMaterial->atTextureMaps[tSlot].tResource = gptResource->load(acFilepath, PL_RESOURCE_LOAD_FLAG_BLOCK_COMPRESSED);
461462
}
462463
}
463464

extensions/pl_resource_ext.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
382382

383383
bool bResizeNeeded = false;
384384
bool bGenerateMips = true;
385-
bool bAttemptCompression = true;
386385
plImageInfo tImageInfo = {0};
387386
size_t szStagingOffset = 0;
388387
if(gptImage->get_info((unsigned char*)puFileData, (int)szFileByteSize, &tImageInfo))
@@ -488,7 +487,7 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
488487

489488
tResource.tTexture = gptGfx->create_texture(ptDevice, &tTextureDesc, &ptTexture);
490489
}
491-
else if(bAttemptCompression)
490+
else if(tFlags & PL_RESOURCE_LOAD_FLAG_BLOCK_COMPRESSED)
492491
{
493492
unsigned char* puRawBytes = gptImage->load((unsigned char*)puFileData, (int)szFileByteSize, &iTextureWidth, &iTextureHeight, &iTextureChannels, 4);
494493

@@ -503,7 +502,7 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
503502
// create texture
504503
const plTextureDesc tTextureDesc = {
505504
.tDimensions = {(float)tImageInfo.iWidth, (float)tImageInfo.iHeight, 1},
506-
.tFormat = PL_FORMAT_BC2_UNORM,
505+
.tFormat = PL_FORMAT_BC3_UNORM,
507506
.uLayers = 1,
508507
.uMips = 0,
509508
.tType = PL_TEXTURE_TYPE_2D,
@@ -548,9 +547,6 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
548547
pl__resource_create_staging_buffer(szRequiredStagingSize);
549548
}
550549

551-
552-
553-
554550
plBuffer* ptStagingBuffer = gptGfx->get_buffer(ptDevice, gptResourceManager->tStagingBuffer.tStagingBufferHandle);
555551

556552
gptDxt->compress(&tDxtInfoOriginal, (uint8_t*)&ptStagingBuffer->tMemoryAllocation.pHostMapped[szStagingOffset], &szRequiredStagingSize);
@@ -562,8 +558,6 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
562558
auWorkingBuffer[1] = puRawBytes;
563559
memset(auWorkingBuffer[0], 0, szMaxBufferSize);
564560

565-
566-
567561
const plBufferImageCopy tBufferImageCopy0 = {
568562
.uImageWidth = (uint32_t)tImageInfo.iWidth,
569563
.uImageHeight = (uint32_t)tImageInfo.iHeight,
@@ -615,7 +609,6 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
615609
uint8_t uBlue = (ptPixel0[2] + ptPixel1[2] + ptPixel2[2] + ptPixel3[2]) / 4;
616610
uint8_t uAlpha = (ptPixel0[3] + ptPixel1[3] + ptPixel2[3] + ptPixel3[3]) / 4;
617611

618-
619612
puDstBuffer[j * iCurrentWidth * 4 + i * 4 + 0] = uRed;
620613
puDstBuffer[j * iCurrentWidth * 4 + i * 4 + 1] = uGreen;
621614
puDstBuffer[j * iCurrentWidth * 4 + i * 4 + 2] = uBlue;
@@ -647,7 +640,11 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
647640
.uMipLevel = uMipLevel
648641
};
649642

650-
gptGfx->copy_buffer_to_texture(ptBlitEncoder, gptResourceManager->tStagingBuffer.tStagingBufferHandle, tResource.tTexture, 1, &tBufferImageCopy);
643+
gptGfx->copy_buffer_to_texture(ptBlitEncoder,
644+
gptResourceManager->tStagingBuffer.tStagingBufferHandle,
645+
tResource.tTexture,
646+
1,
647+
&tBufferImageCopy);
651648
szStagingOffset += szCurrentSize;
652649
}
653650

@@ -702,7 +699,7 @@ pl_resource_load_ex(const char* pcName, plResourceLoadFlags tFlags, uint8_t* puO
702699
tResource.tTexture = gptGfx->create_texture(ptDevice, &tTextureDesc, &ptTexture);
703700
}
704701

705-
if(!bAttemptCompression)
702+
if(!(tFlags & PL_RESOURCE_LOAD_FLAG_BLOCK_COMPRESSED))
706703
{
707704

708705
// choose allocator

extensions/pl_resource_ext.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Index of this file:
4545
// [SECTION] apis
4646
//-----------------------------------------------------------------------------
4747

48-
#define plResourceI_version {0, 2, 2}
48+
#define plResourceI_version {0, 3, 0}
4949

5050
//-----------------------------------------------------------------------------
5151
// [SECTION] includes
@@ -113,8 +113,9 @@ typedef struct _plResourceI
113113

114114
enum _plResourceLoadFlags
115115
{
116-
PL_RESOURCE_LOAD_FLAG_NONE,
117-
PL_RESOURCE_LOAD_FLAG_RETAIN_FILE_DATA
116+
PL_RESOURCE_LOAD_FLAG_NONE = 0,
117+
PL_RESOURCE_LOAD_FLAG_RETAIN_FILE_DATA = 1 << 0,
118+
PL_RESOURCE_LOAD_FLAG_BLOCK_COMPRESSED = 1 << 1,
118119
};
119120

120121
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)