mirror of
https://github.com/Llennpie/Saturn.git
synced 2025-01-22 07:32:02 -05:00
le textures
This commit is contained in:
parent
2c7b4775d2
commit
89419ec718
3 changed files with 57 additions and 0 deletions
|
@ -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<u8>(_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<u8>();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue