mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-02 00:32:45 +03:00
feat(texture): implement TextureCacheCreateTexture
This commit is contained in:
parent
421accf989
commit
fdc24b9bed
@ -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) {
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user