diff --git a/data/dynos_gfx_load.cpp b/data/dynos_gfx_load.cpp index e5505cc4..ccb5ca14 100644 --- a/data/dynos_gfx_load.cpp +++ b/data/dynos_gfx_load.cpp @@ -1,5 +1,7 @@ #include "dynos.cpp.h" +extern void ModelTextureAdd(char* id, char* data, int w, int h); + // // Pointers // @@ -104,6 +106,7 @@ static void LoadTextureData(FILE *aFile, GfxData *aGfxData) { _Node->mData->mRawFormat = G_IM_FMT_RGBA; _Node->mData->mRawSize = G_IM_SIZ_32b; _Node->mData->mRawData = Array(_RawData, _RawData + (_Node->mData->mRawWidth * _Node->mData->mRawHeight * 4)); + ModelTextureAdd((std::string("gfx/") + _Node->mName.begin()).data(), (char*)_RawData, _Node->mData->mRawWidth, _Node->mData->mRawHeight); free(_RawData); } else { // Probably a palette _Node->mData->mRawData = Array(); diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 7d232fef..bae0596d 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -513,6 +513,14 @@ static void import_texture_ci8(int tile) { void load_texture(const char *fullpath) { int w, h; uint64_t imgsize = 0; + + + extern char* ModelTextureGet(char* id, int* w, int* h); + char* model_data = ModelTextureGet(fullpath, &w, &h); + if (model_data) { + gfx_rapi->upload_texture(model_data, w, h); + return; + } u8 *imgdata = fs_load_file(fullpath, &imgsize); if (imgdata) { diff --git a/src/saturn/saturn_models.cpp b/src/saturn/saturn_models.cpp index f54a31fe..cfcc5e69 100644 --- a/src/saturn/saturn_models.cpp +++ b/src/saturn/saturn_models.cpp @@ -164,4 +164,50 @@ Model LoadModelData(std::string folderPath) { } } return model; +} + +struct ModelTexture { + struct ModelTexture* next; + char* id; + char* data; + int w, h; +}; +struct ModelTexture* gModelTextureList; + +void ModelTextureAdd(char* id, char* data, int w, int h) { + struct ModelTexture* curr = gModelTextureList; + while (curr) { + if (strcmp(curr->id, id) == 0) return; + curr = curr->next; + } + struct ModelTexture* tex = (struct ModelTexture*)malloc(sizeof(struct ModelTexture)); + int texid_len = strlen(id) + 1; + char* texid = (char*)malloc(texid_len); + char* texdata = (char*)malloc(w * h * 4); + memcpy(texid, id, texid_len); + memcpy(texdata, data, w * h * 4); + tex->w = w; + tex->h = h; + tex->id = texid; + tex->data = texdata; + tex->next = nullptr; + if (gModelTextureList) { + struct ModelTexture* prev = gModelTextureList; + while (prev->next) prev = prev->next; + prev->next = tex; + } + else gModelTextureList = tex; +} + +extern "C" char* ModelTextureGet(char* id, int* w, int* h) { + struct ModelTexture* curr = gModelTextureList; + while (curr) { + if (strcmp(curr->id, id) == 0) { + *w = curr->w; + *h = curr->h; + return curr->data; + } + curr = curr->next; + } + return nullptr; } \ No newline at end of file