-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
4,657 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "resLoader.h" | ||
#include "api/vulkan/image.h" | ||
#include "tinyktx.h" | ||
#include "tinydds.h" | ||
|
||
#include <fstream> | ||
|
||
namespace | ||
{ | ||
inline bool loadKTXTextureDesc(std::filesystem::path path, aph::vk::ImageCreateInfo* pOutDesc) | ||
{ | ||
if (!std::filesystem::exists(path)) | ||
{ | ||
return false; | ||
} | ||
|
||
std::ifstream file(path); | ||
|
||
file.seekg(std::ios::end); | ||
ssize_t ktxDataSize = file.tellg(); | ||
|
||
if (ktxDataSize > UINT32_MAX) | ||
{ | ||
return false; | ||
} | ||
|
||
file.seekg(0); | ||
|
||
TinyKtx_Callbacks callbacks | ||
{ | ||
[](void* user, char const* msg) { CM_LOG_ERR("%s", msg); }, | ||
[](void* user, size_t size) { return malloc(size); }, | ||
[](void* user, void* memory) { free(memory); }, | ||
[](void* user, void* buffer, size_t byteCount) { | ||
|
||
|
||
return fsReadFromStream((FileStream*)user, buffer, (ssize_t)byteCount); | ||
}, | ||
[](void* user, int64_t offset) { | ||
auto ifs = reinterpret_cast<std::ifstream*>(user); | ||
return ifs->tellg() | ||
}, | ||
[](void *user) { return (int64_t)fsGetStreamSeekPosition((FileStream*)user); } | ||
}; | ||
|
||
TinyKtx_ContextHandle ctx = TinyKtx_CreateContext(&callbacks, &file); | ||
bool headerOkay = TinyKtx_ReadHeader(ctx); | ||
if (!headerOkay) | ||
{ | ||
TinyKtx_DestroyContext(ctx); | ||
return false; | ||
} | ||
|
||
aph::vk::ImageCreateInfo& textureCI = *pOutDesc; | ||
textureCI.extent = { | ||
.width = TinyKtx_Width(ctx), | ||
.height = TinyKtx_Height(ctx), | ||
.depth = std::max(1U, TinyKtx_Depth(ctx)), | ||
}; | ||
textureCI.arrayLayers = std::max(1U, TinyKtx_ArraySlices(ctx)); | ||
textureCI.mipLevels = std::max(1U, TinyKtx_NumberOfMipmaps(ctx)); | ||
textureCI.format = TinyImageFormat_FromTinyKtxFormat(TinyKtx_GetFormat(ctx)); | ||
textureCI.mDescriptors = DESCRIPTOR_TYPE_TEXTURE; | ||
textureCI.mSampleCount = SAMPLE_COUNT_1; | ||
|
||
if (textureCI.format == VK_FORMAT_UNDEFINED) | ||
{ | ||
TinyKtx_DestroyContext(ctx); | ||
return false; | ||
} | ||
|
||
if (TinyKtx_IsCubemap(ctx)) | ||
{ | ||
textureCI.mArraySize *= 6; | ||
textureDesc.mDescriptors |= DESCRIPTOR_TYPE_TEXTURE_CUBE; | ||
} | ||
|
||
TinyKtx_DestroyContext(ctx); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef RES_LOADER_H_ | ||
#define RES_LOADER_H_ | ||
|
||
#include "common/common.h" | ||
|
||
namespace aph | ||
{ | ||
|
||
struct ResourceLoaderCreateInfo | ||
{ | ||
bool isMultiThreads = false; | ||
}; | ||
|
||
enum class ImageContainerType | ||
{ | ||
Dds = 0, | ||
Ktx, | ||
Png, | ||
Jpg, | ||
}; | ||
|
||
struct ImageLoadInfo | ||
{ | ||
std::string path; | ||
ImageContainerType containerType; | ||
}; | ||
|
||
struct BufferLoadInfo | ||
{ | ||
std::string path; | ||
}; | ||
|
||
class ResourceLoader | ||
{ | ||
public: | ||
ResourceLoader(const ResourceLoaderCreateInfo& createInfo) {} | ||
|
||
~ResourceLoader() = default; | ||
|
||
void loadImages(); | ||
void loadBuffers(); | ||
}; | ||
} // namespace aph | ||
|
||
#endif |
Oops, something went wrong.