feat(texture): implement TextureCacheCreateTexture

This commit is contained in:
fallenoak 2025-10-18 09:44:02 -05:00
parent 421accf989
commit fdc24b9bed
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 47 additions and 2 deletions

View File

@ -1,7 +1,50 @@
#include "component/Texture.hpp" #include "component/Texture.hpp"
#include <common/ObjectAlloc.hpp>
TSHashTable<CACHEENTRY, HASHKEY_NONE> s_cacheTable;
HASHKEY_NONE s_cacheKey;
uint32_t* s_entryHeap;
void CACHEENTRY::AddRef() {
this->m_refCount++;
}
CACHEENTRY* TextureCacheAllocEntry() {
if (!s_entryHeap) {
auto heapId = static_cast<uint32_t*>(SMemAlloc(sizeof(uint32_t), __FILE__, __LINE__, 0));
*heapId = ObjectAllocAddHeap(sizeof(CACHEENTRY), 1024, "TCACHEENTRY", true);
s_entryHeap = heapId;
}
uint32_t memHandle;
void* mem;
if (!ObjectAlloc(*s_entryHeap, &memHandle, &mem, false)) {
return nullptr;
}
auto entry = new (mem) CACHEENTRY();
entry->m_memHandle = memHandle;
return entry;
}
CACHEENTRY* TextureCacheCreateTexture(const char* fileName) { CACHEENTRY* TextureCacheCreateTexture(const char* fileName) {
// TODO auto hashval = SStrHash(fileName);
auto texture = s_cacheTable.Ptr(hashval, s_cacheKey);
if (!texture) {
texture = TextureCacheAllocEntry();
s_cacheTable.Insert(texture, hashval, s_cacheKey);
SStrCopy(texture->m_fileName, fileName, sizeof(texture->m_fileName));
}
texture->AddRef();
return texture;
} }
void TextureCacheDestroyTexture(void* texture) { void TextureCacheDestroyTexture(void* texture) {

View File

@ -11,8 +11,10 @@ class CACHEENTRY : public TSHashObject<CACHEENTRY, HASHKEY_NONE> {
CAsyncObject* m_asyncObject = nullptr; CAsyncObject* m_asyncObject = nullptr;
char m_fileName[128]; char m_fileName[128];
uint32_t m_refCount = 0; uint32_t m_refCount = 0;
void* m_memHandle = nullptr; uint32_t m_memHandle = 0;
// Member functions
void AddRef();
}; };
CACHEENTRY* TextureCacheCreateTexture(const char* fileName); CACHEENTRY* TextureCacheCreateTexture(const char* fileName);