Skip to content

Commit

Permalink
tImageKTX now uses CreateFromNamedFile instead of CreateFromMemory if…
Browse files Browse the repository at this point in the history
… the file load call is used.
  • Loading branch information
bluescan committed Jun 29, 2024
1 parent ff7a2d5 commit a356345
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Modules/Image/Inc/Image/tImageKTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <Image/tPixelFormat.h>
#include <Image/tLayer.h>
#include <Image/tBaseImage.h>
struct ktxTexture;
namespace tImage
{

Expand Down Expand Up @@ -212,6 +213,7 @@ class tImageKTX : public tBaseImage
tString Filename;

private:
bool LoadFromTexture(ktxTexture* texture, const LoadParams& paramsIn);
void SetStateBit(StateBit state) { States |= 1 << int(state); }

// The states are bits in this States member.
Expand Down
25 changes: 23 additions & 2 deletions Modules/Image/Src/tImageKTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,19 +754,30 @@ bool tImageKTX::Load(const tString& ktxFile, const LoadParams& loadParams)
return false;
}

#if 0
int ktxSizeBytes = 0;
uint8* ktxData = (uint8*)tSystem::tLoadFile(ktxFile, 0, &ktxSizeBytes);
bool success = Load(ktxData, ktxSizeBytes, loadParams);
delete[] ktxData;

return success;
#endif

ktx_error_code_e result = KTX_SUCCESS;
ktxTexture* texture = nullptr;
result = ktxTexture_CreateFromNamedFile(ktxFile.Chr(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &texture);
if (!texture || (result != KTX_SUCCESS))
{
SetStateBit(StateBit::Fatal_CouldNotParseFile);
return false;
}

return LoadFromTexture(texture, loadParams);
}


bool tImageKTX::Load(const uint8* ktxData, int ktxSizeBytes, const LoadParams& paramsIn)
{
Clear();
LoadParams params(paramsIn);

ktx_error_code_e result = KTX_SUCCESS;
ktxTexture* texture = nullptr;
Expand All @@ -777,6 +788,16 @@ bool tImageKTX::Load(const uint8* ktxData, int ktxSizeBytes, const LoadParams& p
return false;
}

return LoadFromTexture(texture, paramsIn);
}


bool tImageKTX::LoadFromTexture(ktxTexture* texture, const LoadParams& paramsIn)
{
tAssert(texture);
LoadParams params(paramsIn);
ktx_error_code_e result = KTX_SUCCESS;

NumImages = texture->numFaces; // Number of faces. 1 or 6 for cubemaps.
int numLayers = texture->numLayers; // Number of array layers. I believe this will be > 1 for 3D textures that are made of an array of layers.
NumMipmapLayers = texture->numLevels; // Mipmap levels.
Expand Down

0 comments on commit a356345

Please sign in to comment.