mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +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*,
|
const char*,
|
||||||
unsigned int);
|
unsigned int);
|
||||||
|
|
||||||
void gettexturebatch(struct TextureBatch**,
|
unsigned int gettexturebatch(
|
||||||
|
struct TextureBatch**,
|
||||||
|
struct TextureBatchDescriptor**,
|
||||||
const char*,
|
const char*,
|
||||||
unsigned int);
|
unsigned int);
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,23 +56,30 @@ void gettbd (struct TextureBatchDescriptor **descriptors,
|
|||||||
return;
|
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,
|
const char *filedata,
|
||||||
unsigned int filesize) {
|
unsigned int filesize) {
|
||||||
struct TexturePack *tp = (struct TexturePack*)filedata;
|
struct TexturePack *tp = (struct TexturePack*)filedata;
|
||||||
struct TextureBatchDescriptor **bds = NULL;
|
// struct TextureBatchDescriptor **bds = NULL;
|
||||||
bds = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
// bds = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
||||||
gettbd(bds, filedata, filesize);
|
// gettbd(bds, filedata, filesize);
|
||||||
unsigned int offset = tp -> firstBatchOffset;
|
unsigned int offset = tp -> firstBatchOffset;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
|
unsigned int totaltextures = 0;
|
||||||
// TextureBatch shares a starting address with the first texture
|
// TextureBatch shares a starting address with the first texture
|
||||||
// and shares the ending address with the last texture.
|
// and shares the ending address with the last texture.
|
||||||
for (i = 0; i < tp -> batchNumber; i++) {
|
for (i = 0; i < tp -> batchNumber; i++) {
|
||||||
printf("%x \n", offset);
|
printf("%x \n", offset);
|
||||||
tb[i] = (struct TextureBatch*)filedata + offset;
|
tb[i] = (struct TextureBatch*)filedata + offset;
|
||||||
// the next texture batch is TextureSize * number of textures away.
|
// 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);
|
free(bds);
|
||||||
return;
|
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) {
|
int main(int argc, char ** argv) {
|
||||||
char *f = argv[1];
|
char *f = argv[1];
|
||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
char *buffer = loadfile(f, &bufsize);
|
char *buffer = loadfile(f, &bufsize);
|
||||||
// unpackpld(buffer, bufsize, f);
|
// unpackpld(buffer, bufsize, f);
|
||||||
// unpacktextures(buffer, bufsize);
|
// unpacktextures(buffer, bufsize);
|
||||||
struct TexturePack *tp = (struct TexturePack*)buffer;
|
unpacktextures(buffer, bufsize);
|
||||||
struct TextureBatch **batches = NULL;
|
|
||||||
batches = (struct TextureBatch**)malloc(tp -> batchNumber);
|
|
||||||
gettexturebatch(batches, buffer, bufsize);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user