mirror of
https://github.com/nzp-team/dquakeplus.git
synced 2025-01-19 06:10:52 +00:00
Stop storing palette data for WAD3 and PCX textures
This commit is contained in:
parent
b30f349572
commit
f5b90862ca
5 changed files with 170 additions and 114 deletions
|
@ -610,6 +610,74 @@ void Host_ServerFrame (void)
|
|||
SV_SendClientMessages ();
|
||||
}
|
||||
|
||||
int extshit()
|
||||
{
|
||||
u32 size, sizeblock;
|
||||
u8 *ram;
|
||||
// Init variables
|
||||
size = 0;
|
||||
sizeblock = (1024 * 1024);
|
||||
// Check loop
|
||||
while (sizeblock)
|
||||
{
|
||||
// Increment size
|
||||
size += sizeblock;
|
||||
// Allocate ram
|
||||
ram = (u8*)malloc(size);
|
||||
// Check allocate
|
||||
if (!(ram))
|
||||
{
|
||||
// Restore old size
|
||||
size -= sizeblock;
|
||||
// Size block / 2
|
||||
sizeblock >>= 1;
|
||||
}
|
||||
else
|
||||
free(ram);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int freememory()
|
||||
{
|
||||
u8 **ram, **temp;
|
||||
u32 size, count, x;
|
||||
// Init variables
|
||||
ram = NULL;
|
||||
size = 0;
|
||||
count = 0;
|
||||
// Check loop
|
||||
for (;;)
|
||||
{
|
||||
// Check size entries
|
||||
if (!(count % 10))
|
||||
{
|
||||
// Allocate more entries if needed
|
||||
temp = (u8**)realloc(ram,sizeof(u8*) * (count + 10));
|
||||
if (!(temp)) break;
|
||||
// Update entries and size (size contains also size of entries)
|
||||
ram = temp;
|
||||
size += (sizeof(u8 *) * 10);
|
||||
}
|
||||
// Find max lineare size available
|
||||
x = extshit();
|
||||
if (!(x)) break;
|
||||
// Allocate ram
|
||||
ram[count] = (u8*)malloc(x);
|
||||
if (!(ram[count])) break;
|
||||
// Update variables
|
||||
size += x;
|
||||
count++;
|
||||
}
|
||||
// Free ram
|
||||
if (ram)
|
||||
{
|
||||
for (x=0;x<count;x++) free(ram[x]);
|
||||
free(ram);
|
||||
}
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
|
@ -714,11 +782,15 @@ void _Host_Frame (float time)
|
|||
pass1+pass2+pass3, pass1, pass2, pass3);
|
||||
}
|
||||
|
||||
//Con_Printf ("%dkB free \n", freememory()/1024);
|
||||
|
||||
//frame speed counter
|
||||
fps_count++;//muff
|
||||
host_framecount++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Host_Frame (float time)
|
||||
{
|
||||
double time1, time2;
|
||||
|
|
|
@ -282,24 +282,23 @@ namespace quake
|
|||
__asm__ (
|
||||
".set push\n" // save assembler option
|
||||
".set noreorder\n" // suppress reordering
|
||||
"move $8, %1\n" // $8 = &vertices[0]
|
||||
"move $9, %2\n" // $9 = vertex_count
|
||||
"li $10, 20\n" // $10 = 20( sizeof(glvert_t) )
|
||||
"mul $10, $10, $9\n" // $10 = $10 * $9
|
||||
"addu $10, $10, $8\n" // $10 = $10 + $8
|
||||
"move $8, %1\n" // $8 = &v[0]
|
||||
"move $9, %2\n" // $9 = vc
|
||||
"li $10, 20\n" // $10 = 20( sizeof( gu_vert_t ) )
|
||||
"mul $10, $10, $9\n" // $10 = $10 * $9
|
||||
"addu $10, $10, $8\n" // $10 = $10 + $8
|
||||
"addiu %0, $0, 1\n" // res = 1
|
||||
"vzero.q C600\n" // C600 = [0.0f, 0.0f, 0.0f. 0.0f]
|
||||
"0:\n" // loop
|
||||
"ulv.q C610, 8($8)\n" // Load vertex into register skip tex cord 8 byte
|
||||
"vone.s S613\n" // Now set the 4th entry to be 1 as that is just random
|
||||
"vdot.q S620, C700, C610\n" // S620 = v[i] * frustrum[0]
|
||||
"vdot.q S621, C710, C610\n" // S621 = v[i] * frustrum[1]
|
||||
"vdot.q S622, C720, C610\n" // S622 = v[i] * frustrum[2]
|
||||
"vdot.q S623, C730, C610\n" // S623 = v[i] * frustrum[3]
|
||||
"vzero.q C610\n" // C610 = [0.0f, 0.0f, 0.0f. 0.0f]
|
||||
"addiu %0, $0, 1\n" // res = 1
|
||||
"vcmp.q LT, C620, C610\n" // S620 < 0.0f || S621 < 0.0f || S622 < 0.0f || S623 < 0.0f
|
||||
"lv.s S610, 8($8)\n" // S610 = v[i].xyz[0]
|
||||
"lv.s S611, 12($8)\n" // S611 = v[i].xyz[1]
|
||||
"lv.s S612, 16($8)\n" // S612 = v[i].xyz[2]
|
||||
"vhtfm4.q C620, M700, C610\n" // C620 = frustrum * v[i].xyz
|
||||
"vcmp.q LT, C620, C600\n" // S620 < 0.0f || S621 < 0.0f || S622 < 0.0f || S623 < 0.0f
|
||||
"bvt 4, 1f\n" // if ( CC[4] == 1 ) jump to exit
|
||||
"addiu $8, $8, 20\n" // $8 = $8 + 20( sizeof(glvert_t) )
|
||||
"bne $10, $8, 0b\n" // if ( $9 != 0 ) jump to loop
|
||||
"addiu $8, $8, 20\n" // $8 = $8 + 20( sizeof( gu_vert_t ) ) ( delay slot )
|
||||
"bne $10, $8, 0b\n" // if ( $10 != $8 ) jump to loop
|
||||
"nop\n" // ( delay slot )
|
||||
"move %0, $0\n" // res = 0
|
||||
"1:\n" // exit
|
||||
".set pop\n" // Restore assembler option
|
||||
|
|
|
@ -2498,19 +2498,23 @@ void GL_UploadDXT(int texture_index, const byte *data, int width, int height)
|
|||
}
|
||||
}
|
||||
|
||||
tx_compress_dxtn(texture.bpp, texture.width, texture.height,(const unsigned char *)&unswizzled[0], texture.format, (unsigned char *)texture.ram);
|
||||
if (texture.vram) {
|
||||
tx_compress_dxtn(texture.bpp, texture.width, texture.height,(const unsigned char *)&unswizzled[0], texture.format, (unsigned char *)texture.vram);
|
||||
} else {
|
||||
tx_compress_dxtn(texture.bpp, texture.width, texture.height,(const unsigned char *)&unswizzled[0], texture.format, (unsigned char *)texture.ram);
|
||||
}
|
||||
|
||||
Hunk_FreeToLowMark (start);
|
||||
|
||||
// Copy to VRAM?
|
||||
if (texture.vram)
|
||||
{
|
||||
// Copy.
|
||||
memcpy(texture.vram, texture.ram, buffer_sizedst);
|
||||
// Flush the data cache.
|
||||
sceKernelDcacheWritebackRange(texture.vram, buffer_sizedst);
|
||||
} else {
|
||||
// Flush the data cache.
|
||||
sceKernelDcacheWritebackRange(texture.ram, buffer_sizedst);
|
||||
}
|
||||
// Flush the data cache.
|
||||
sceKernelDcacheWritebackRange(texture.ram, buffer_sizedst);
|
||||
}
|
||||
|
||||
static std::size_t round_up(std::size_t size)
|
||||
|
@ -3310,6 +3314,7 @@ int GL_LoadImages (const char *identifier, int width, int height, const byte *da
|
|||
|
||||
// Allocate the VRAM.
|
||||
texture.vram = static_cast<texel*>(valloc(buffer_size));
|
||||
|
||||
// Upload the texture.
|
||||
switch(texture.format)
|
||||
{
|
||||
|
@ -3328,11 +3333,14 @@ int GL_LoadImages (const char *identifier, int width, int height, const byte *da
|
|||
GL_UploadDXT(texture_index, data, width, height);
|
||||
break;
|
||||
}
|
||||
|
||||
//FIXME: this isn't completely clearing out the normal ram stuff :s
|
||||
if (texture.vram && texture.ram)
|
||||
{
|
||||
free(texture.ram);
|
||||
texture.ram = NULL;
|
||||
}
|
||||
|
||||
// Done.
|
||||
return texture_index;
|
||||
}
|
||||
|
|
|
@ -189,83 +189,68 @@ typedef struct
|
|||
unsigned char data; // unbounded
|
||||
} pcx_t;
|
||||
|
||||
byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
|
||||
{
|
||||
pcx_t *pcx, pcxbuf;
|
||||
byte palette[768];
|
||||
byte *pix, *image_rgba;
|
||||
int x, y;
|
||||
int dataByte, runLength;
|
||||
int count;
|
||||
byte* LoadPCX(FILE* f, int matchwidth, int matchheight) {
|
||||
pcx_t pcxbuf;
|
||||
fread(&pcxbuf, 1, sizeof(pcxbuf), f);
|
||||
|
||||
//
|
||||
// parse the PCX file
|
||||
//
|
||||
fread (&pcxbuf, 1, sizeof(pcxbuf), f);
|
||||
pcx_t* pcx = &pcxbuf;
|
||||
|
||||
pcx = &pcxbuf;
|
||||
if (pcx->manufacturer != 0x0a || pcx->version != 5 || pcx->encoding != 1 ||
|
||||
pcx->bits_per_pixel != 8 || pcx->xmax >= 320 || pcx->ymax >= 256) {
|
||||
Con_Printf("Bad pcx file\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (pcx->manufacturer != 0x0a
|
||||
|| pcx->version != 5
|
||||
|| pcx->encoding != 1
|
||||
|| pcx->bits_per_pixel != 8
|
||||
|| pcx->xmax >= 320
|
||||
|| pcx->ymax >= 256)
|
||||
{
|
||||
Con_Printf ("Bad pcx file\n");
|
||||
return NULL;
|
||||
}
|
||||
if (matchwidth && (pcx->xmax + 1) != matchwidth) {
|
||||
fclose(f);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (matchwidth && (pcx->xmax+1) != matchwidth)
|
||||
{
|
||||
fclose (f);
|
||||
return NULL;
|
||||
}
|
||||
if (matchheight && (pcx->ymax + 1) != matchheight) {
|
||||
fclose(f);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (matchheight && (pcx->ymax+1) != matchheight)
|
||||
{
|
||||
fclose (f);
|
||||
return NULL;
|
||||
}
|
||||
fseek(f, -768, SEEK_END);
|
||||
byte palette[768];
|
||||
fread(palette, 1, 768, f);
|
||||
|
||||
// seek to palette
|
||||
fseek (f, -768, SEEK_END);
|
||||
fread (palette, 1, 768, f);
|
||||
fseek(f, sizeof(pcxbuf) - 4, SEEK_SET);
|
||||
|
||||
fseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
|
||||
int count = (pcx->xmax + 1) * (pcx->ymax + 1);
|
||||
byte* image_rgba = static_cast<byte*>(Q_malloc(4 * count));
|
||||
|
||||
count = (pcx->xmax+1) * (pcx->ymax+1);
|
||||
byte* pix = image_rgba;
|
||||
for (int y = 0; y <= pcx->ymax; y++) {
|
||||
for (int x = 0; x <= pcx->xmax;) {
|
||||
int dataByte = fgetc(f);
|
||||
|
||||
image_rgba = static_cast<byte*>(Q_malloc( count ));
|
||||
int runLength = 1;
|
||||
if ((dataByte & 0xC0) == 0xC0) {
|
||||
runLength = dataByte & 0x3F;
|
||||
dataByte = fgetc(f);
|
||||
}
|
||||
|
||||
for (y=0 ; y<=pcx->ymax ; y++)
|
||||
{
|
||||
pix = image_rgba + y * (pcx->xmax+1);
|
||||
for (x=0 ; x<=pcx->xmax ; ) // muff - fixed - was referencing ymax
|
||||
{
|
||||
dataByte = fgetc(f);
|
||||
while (runLength-- > 0) {
|
||||
byte* color = palette + dataByte * 3;
|
||||
pix[0] = color[0];
|
||||
pix[1] = color[1];
|
||||
pix[2] = color[2];
|
||||
pix[3] = 0xFF; // set alpha to 255
|
||||
pix += 4;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((dataByte & 0xC0) == 0xC0)
|
||||
{
|
||||
runLength = dataByte & 0x3F;
|
||||
dataByte = fgetc(f);
|
||||
}
|
||||
else
|
||||
runLength = 1;
|
||||
image_width = pcx->xmax + 1;
|
||||
image_height = pcx->ymax + 1;
|
||||
//memcpy_vfpu(image_palette, palette, sizeof(palette));
|
||||
//image_palette_type = PAL_RGB;
|
||||
|
||||
while(runLength-- > 0)
|
||||
pix[x++] = dataByte;
|
||||
}
|
||||
}
|
||||
image_width = pcx->xmax+1;
|
||||
image_height = pcx->ymax+1;
|
||||
fclose(f);
|
||||
|
||||
memcpy_vfpu(image_palette, palette, sizeof(palette));
|
||||
image_palette_type = PAL_RGB;
|
||||
|
||||
fclose (f);
|
||||
|
||||
return image_rgba;
|
||||
return image_rgba;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -156,42 +156,34 @@ loaded:
|
|||
//converts paletted to rgba
|
||||
int ConvertWad3ToRGBA(miptex_t *tex)
|
||||
{
|
||||
byte *in, *data, *pal;
|
||||
int i, p, image_size;
|
||||
// Check that texture has data
|
||||
if (!tex->offsets[0]) {
|
||||
Sys_Error("ConvertWad3ToRGBA: tex->offsets[0] == 0");
|
||||
}
|
||||
|
||||
if (!tex->offsets[0])
|
||||
Sys_Error("ConvertWad3ToRGBA: tex->offsets[0] == 0");
|
||||
// Get pointers to WAD3 data and palette
|
||||
byte* wadData = ((byte*)tex) + tex->offsets[0];
|
||||
byte* palette = ((byte*)tex) + tex->offsets[3] + (tex->width>>3)*(tex->height>>3) + 2;
|
||||
//byte* palette = wadData + tex->offsets[MIPLEVELS]; // Palette starts 2 bytes after the last mipmap
|
||||
|
||||
image_size = tex->width * tex->height;
|
||||
// Allocate buffer for RGBA data
|
||||
int imageSize = tex->width * tex->height;
|
||||
byte* rgbaData = (byte*)Q_malloc(imageSize * 4);
|
||||
|
||||
in = (byte *) ((byte *) tex + tex->offsets[0]);
|
||||
pal = in + ((image_size * 85) >> 6) + 2;
|
||||
// Convert WAD3 data to RGBA format
|
||||
for (int i = 0; i < imageSize; i++) {
|
||||
byte colorIndex = wadData[i];
|
||||
rgbaData[i * 4] = palette[colorIndex * 3 + 0];
|
||||
rgbaData[i * 4 + 1] = palette[colorIndex * 3 + 1];
|
||||
rgbaData[i * 4 + 2] = palette[colorIndex * 3 + 2];
|
||||
rgbaData[i * 4 + 3] = 255; // Set alpha to opaque
|
||||
}
|
||||
|
||||
int index = GL_LoadImages(tex->name, tex->width, tex->height, rgbaData, qtrue, GU_LINEAR, 0, 4);
|
||||
|
||||
data = (byte*)Q_malloc(image_size);
|
||||
for (i = 0; i < image_size; i++)
|
||||
{
|
||||
p = *in++;
|
||||
/*
|
||||
if (tex->name[0] == '{' && p == 255)
|
||||
data[i] = 0;
|
||||
else
|
||||
*/
|
||||
data[i] = p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int level = 0;
|
||||
if (r_mipmaps.value > 0)
|
||||
level = 3;
|
||||
|
||||
int index = GL_LoadPalTex (tex->name, tex->width, tex->height, (const byte*)data, qtrue, GU_LINEAR, level, (byte *)pal, PAL_RGB);
|
||||
|
||||
free(data);
|
||||
free(rgbaData);
|
||||
|
||||
return index;
|
||||
|
||||
}
|
||||
|
||||
int WAD3_LoadTexture(miptex_t *mt)
|
||||
|
|
Loading…
Reference in a new issue