mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-26 00:38:55 +05:30
detour-implementation of texture unpacking
This commit is contained in:
parent
1b06741be4
commit
c812696612
@ -52,7 +52,7 @@ unsigned int gettexturebatch(
|
|||||||
const char*,
|
const char*,
|
||||||
unsigned int);
|
unsigned int);
|
||||||
|
|
||||||
void gettextures(struct Texture **,
|
void gettextures(unsigned int*,
|
||||||
struct TexturePack*,
|
struct TexturePack*,
|
||||||
struct TextureBatch**,
|
struct TextureBatch**,
|
||||||
struct TextureBatchDescriptor**);
|
struct TextureBatchDescriptor**);
|
||||||
|
@ -79,7 +79,7 @@ unsigned int gettexturebatch(
|
|||||||
return totaltextures;
|
return totaltextures;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gettextures(struct Texture **t,
|
void gettextures(unsigned int *t,
|
||||||
struct TexturePack *tp,
|
struct TexturePack *tp,
|
||||||
struct TextureBatch **tb,
|
struct TextureBatch **tb,
|
||||||
struct TextureBatchDescriptor **bds) {
|
struct TextureBatchDescriptor **bds) {
|
||||||
@ -87,11 +87,11 @@ void gettextures(struct Texture **t,
|
|||||||
unsigned int j;
|
unsigned int j;
|
||||||
// k is access to index of textures.
|
// k is access to index of textures.
|
||||||
unsigned int k = 0;
|
unsigned int k = 0;
|
||||||
unsigned int offset = 0;
|
unsigned int offset = tp -> firstBatchOffset;
|
||||||
for (i = 0; i < tp -> batchNumber; i++) {
|
for (i = 0; i < tp -> batchNumber; i++) {
|
||||||
for (j = 0; j < bds[i] -> texNumber; j++) {
|
for (j = 0; j < bds[i] -> texNumber; j++) {
|
||||||
printf("texture offsets %x\n", offset + tp -> firstBatchOffset);
|
printf("texture offsets %x\n", offset);
|
||||||
t[k] = (struct Texture*)tb + offset;
|
t[k] = offset;
|
||||||
offset += bds[i] -> textureSize;
|
offset += bds[i] -> textureSize;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
17
test/main.c
17
test/main.c
@ -110,7 +110,7 @@ bool unpackpld (const char *filedata,
|
|||||||
|
|
||||||
void write(const char *filename,
|
void write(const char *filename,
|
||||||
unsigned int id,
|
unsigned int id,
|
||||||
struct Texture *t,
|
const char* t,
|
||||||
unsigned int size) {
|
unsigned int size) {
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -120,6 +120,10 @@ void write(const char *filename,
|
|||||||
if (out != NULL) {
|
if (out != NULL) {
|
||||||
written = fwrite(t, sizeof(unsigned char), size, out);
|
written = fwrite(t, sizeof(unsigned char), size, out);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
/* unsigned int i;
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
printf("w %u \n", *(t + i));
|
||||||
|
} */
|
||||||
if (written == 0) {
|
if (written == 0) {
|
||||||
perror("texture write error");
|
perror("texture write error");
|
||||||
}
|
}
|
||||||
@ -140,10 +144,9 @@ void unpacktextures(const char *filedata,
|
|||||||
descripts,
|
descripts,
|
||||||
filedata,
|
filedata,
|
||||||
filesize);
|
filesize);
|
||||||
struct Texture **textures = NULL;
|
unsigned int *tloc = (unsigned int*)
|
||||||
textures = (struct Texture**)
|
malloc(sizeof(unsigned int) * texturecount);
|
||||||
malloc(sizeof(struct Texture**) * texturecount);
|
gettextures(tloc, tp, batches, descripts);
|
||||||
gettextures(textures, tp, batches, descripts);
|
|
||||||
// add 3 to buffer for digits, & 4 for file extension
|
// add 3 to buffer for digits, & 4 for file extension
|
||||||
char *fmt = (char*)malloc(strlen(filename) + 3 + 4);
|
char *fmt = (char*)malloc(strlen(filename) + 3 + 4);
|
||||||
unsigned int texsize = 0;
|
unsigned int texsize = 0;
|
||||||
@ -151,10 +154,10 @@ void unpacktextures(const char *filedata,
|
|||||||
for (i = 0; i < texturecount; i++) {
|
for (i = 0; i < texturecount; i++) {
|
||||||
texsize = descripts[i/(tp -> batchNumber)] -> textureSize;
|
texsize = descripts[i/(tp -> batchNumber)] -> textureSize;
|
||||||
sprintf(fmt, "test_%d.dds", i);
|
sprintf(fmt, "test_%d.dds", i);
|
||||||
write(fmt, i, textures[i], texsize);
|
write(fmt, i, filedata + tloc[i], texsize);
|
||||||
}
|
}
|
||||||
free(fmt);
|
free(fmt);
|
||||||
free(textures);
|
free(tloc);
|
||||||
free(descripts);
|
free(descripts);
|
||||||
free(batches);
|
free(batches);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user