mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-25 16:28:57 +05:30
Unpack textures has correct offsets for textures
This commit is contained in:
parent
cff2209971
commit
24d4f920dc
@ -46,7 +46,9 @@ void gettbd(struct TextureBatchDescriptor**,
|
||||
const char*,
|
||||
unsigned int);
|
||||
|
||||
void gettexturebatch(struct TextureBatch**,
|
||||
unsigned int gettexturebatch(
|
||||
struct TextureBatch**,
|
||||
struct TextureBatchDescriptor**,
|
||||
const char*,
|
||||
unsigned int);
|
||||
#endif
|
||||
|
@ -56,23 +56,30 @@ void gettbd (struct TextureBatchDescriptor **descriptors,
|
||||
return;
|
||||
}
|
||||
|
||||
void gettexturebatch(struct TextureBatch **tb,
|
||||
// returns total count of textures in the file.
|
||||
unsigned int gettexturebatch(
|
||||
struct TextureBatch **tb,
|
||||
struct TextureBatchDescriptor **bds,
|
||||
const char *filedata,
|
||||
unsigned int filesize) {
|
||||
struct TexturePack *tp = (struct TexturePack*)filedata;
|
||||
struct TextureBatchDescriptor **bds = NULL;
|
||||
bds = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
||||
gettbd(bds, filedata, filesize);
|
||||
// struct TextureBatchDescriptor **bds = NULL;
|
||||
// bds = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
||||
// gettbd(bds, filedata, filesize);
|
||||
unsigned int offset = tp -> firstBatchOffset;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int totaltextures = 0;
|
||||
// TextureBatch shares a starting address with the first texture
|
||||
// and shares the ending address with the last texture.
|
||||
for (i = 0; i < tp -> batchNumber; i++) {
|
||||
printf("%x \n", offset);
|
||||
tb[i] = (struct TextureBatch*)filedata + offset;
|
||||
// the next texture batch is TextureSize * number of textures away.
|
||||
offset += bds[i] -> textureSize * (bds[i] -> texNumber);
|
||||
offset += bds[i] -> textureSize * (bds[i] -> texNumber);
|
||||
totaltextures += bds[i] -> texNumber;
|
||||
}
|
||||
free(bds);
|
||||
// free(bds);
|
||||
return totaltextures;
|
||||
}
|
||||
|
||||
|
45
test/main.c
45
test/main.c
@ -102,18 +102,55 @@ bool unpackpld (const char *filedata,
|
||||
}
|
||||
free(bds);
|
||||
return;
|
||||
|
||||
const char *fmt = (const char*)malloc(strlen(filename) + 3 + 3);
|
||||
strcat(fmt, filename);
|
||||
strcat(fmt, "%d.dds");
|
||||
} */
|
||||
|
||||
void unpacktextures(const char *filedata,
|
||||
unsigned int filesize) {
|
||||
struct TexturePack *tp = (struct TexturePack*)filedata;
|
||||
|
||||
struct TextureBatch **batches = NULL;
|
||||
batches = (struct TextureBatch**)malloc(tp -> batchNumber);
|
||||
|
||||
struct TextureBatchDescriptor **descripts = NULL;
|
||||
descripts = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
||||
gettbd(descripts, filedata, filesize);
|
||||
// array of pointers - texture data exists in memory in filedata.
|
||||
unsigned int texturecount = gettexturebatch(batches,
|
||||
descripts,
|
||||
filedata,
|
||||
filesize);
|
||||
struct Texture **textures = NULL;
|
||||
textures = (struct Texture**)malloc(texturecount);
|
||||
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
// k is access to index of textures.
|
||||
unsigned int k = 0;
|
||||
unsigned int offset = 0;
|
||||
for (i = 0; i < tp -> batchNumber; i++) {
|
||||
for (j = 0; j < descripts[i] -> texNumber; j++) {
|
||||
printf("texture offsets %x\n", offset + tp -> firstBatchOffset);
|
||||
textures[k] = (struct Texture*)batches + offset;
|
||||
offset += descripts[i] -> textureSize;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
free(textures);
|
||||
free(descripts);
|
||||
free(batches);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
// unpackpld(buffer, bufsize, f);
|
||||
// unpacktextures(buffer, bufsize);
|
||||
struct TexturePack *tp = (struct TexturePack*)buffer;
|
||||
struct TextureBatch **batches = NULL;
|
||||
batches = (struct TextureBatch**)malloc(tp -> batchNumber);
|
||||
gettexturebatch(batches, buffer, bufsize);
|
||||
unpacktextures(buffer, bufsize);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user