Unpack textures has correct offsets for textures

This commit is contained in:
_
2018-04-04 21:49:32 -07:00
parent cff2209971
commit 24d4f920dc
3 changed files with 57 additions and 11 deletions

View File

@@ -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;
}