In Game:
![Image](http://s10.postimg.org/fl47keqd5/Untitled.png)
Source Texture:
![Image](http://s9.postimg.org/5jfhcy2ij/covi_pattern.png)
Code: Select all
// Color 255 is transparent black.
// This is a bit of a dirty hack.
d_8to24table[255] = 0;
Code: Select all
/*
================
GL_LoadPalTex
================
*/
int GL_LoadPalTex (const char *identifier, int width, int height, const byte *data, qboolean stretch_to_power_of_two, int filter, int mipmap_level, byte *palette, int paltype)
{
int texture_index = -1;
tex_scale_down = r_tex_scale_down.value == qtrue;
// See if the texture is already present.
if (identifier[0])
{
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == true)
{
const gltexture_t& texture = gltextures[i];
if (!strcmp (identifier, texture.identifier))
{
return i;
}
}
}
}
// Out of textures?
if (numgltextures == MAX_GLTEXTURES)
{
Sys_Error("Out of OpenGL textures");
}
// Use the next available texture.
numgltextures++;
texture_index = numgltextures;
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == false)
{
texture_index = i;
break;
}
}
gltexture_t& texture = gltextures[texture_index];
gltextures_used[texture_index] = true;
// Fill in the source data.
strcpy(texture.identifier, identifier);
texture.original_width = width;
texture.original_height = height;
texture.stretch_to_power_of_two = stretch_to_power_of_two != qfalse;
// Fill in the texture description.
texture.format = GU_PSM_T8;
texture.filter = filter;
texture.mipmaps = mipmap_level;
texture.swizzle = GU_TRUE;
texture.bpp = 1;
// Upload the Palette
if((paltype == PAL_RGB && palette) ||
(paltype == PAL_RGBA && palette) ||
(paltype == PAL_Q2 && palette == NULL) ||
(paltype == PAL_H2 && palette == NULL) )
{
#ifndef STATIC_PAL
if(paltype == PAL_Q2)
{
texture.palette = d_8to24tableQ2; //hard coded palette
}
else if(paltype == PAL_H2)
{
texture.palette = d_8to24tableH2; //hard coded palette
}
else
{
texture.palette = static_cast<ScePspRGBA8888*>(memalign(16, sizeof(ScePspRGBA8888) * 256));
if(!texture.palette)
{
Sys_Error("Out of RAM for palettes.");
}
#endif
if(paltype == PAL_RGBA)
{
// Convert the palette to PSP format.
for (ScePspRGBA8888* color = &texture.palette[0]; color < &texture.palette[256]; ++color)
{
const unsigned int r = gammatable[*palette++];
const unsigned int g = gammatable[*palette++];
const unsigned int b = gammatable[*palette++];
const unsigned int a = gammatable[*palette++];
*color = GU_RGBA(r, g, b, a);
}
}
else if(paltype == PAL_RGB)
{
// Convert the palette to PSP format.
for (ScePspRGBA8888* color = &texture.palette[0]; color < &texture.palette[256]; ++color)
{
const unsigned int r = gammatable[*palette++];
const unsigned int g = gammatable[*palette++];
const unsigned int b = gammatable[*palette++];
*color = GU_RGBA(r, g, b, 0xff);
}
}
#ifndef STATIC_PAL
}
#endif
texture.palette[255] = 0; //alpha color
texture.palette_active = qtrue;
}
else
{
Sys_Error("GL_LoadPalTex: Unknow palette type");
}
if (tex_scale_down == true && texture.stretch_to_power_of_two == true)
{
texture.width = std::max(round_down(width), 32U);
texture.height = std::max(round_down(height),32U);
}
else
{
texture.width = std::max(round_up(width), 32U);
texture.height = std::max(round_up(height),32U);
}
for (int i=0; i <= mipmap_level;i++)
{
int div = (int) powf(2,i);
if ((texture.width / div) > 16 && (texture.height / div) > 16 )
{
texture.mipmaps = i;
}
}
// Do we really need to resize the texture?
if (texture.stretch_to_power_of_two)
{
// Not if the size hasn't changed.
texture.stretch_to_power_of_two = (texture.width != width) || (texture.height != height);
}
Con_DPrintf("Loading TEX_PAL: %s [%dx%d](%0.2f KB)\n",texture.identifier,texture.width,texture.height, (float) ((texture.width*texture.height)/1024) + 256);
// Allocate the RAM.
std::size_t buffer_size = texture.width * texture.height;
if (texture.mipmaps > 0)
{
int size_incr = buffer_size/4;
for (int i= 1;i <= texture.mipmaps;i++)
{
buffer_size += size_incr;
size_incr = size_incr/4;
}
}
texture.ram = static_cast<texel*>(memalign(16, buffer_size));
if (!texture.ram)
{
Sys_Error("Out of RAM for textures.");
}
// Allocate the VRAM.
texture.vram = static_cast<texel*>(valloc(buffer_size));
// Upload the texture.
GL_Upload8(texture_index, data, width, height);
if (texture.vram && texture.ram)
{
free(texture.ram);
texture.ram = NULL;
}
// Done.
return texture_index;
}
Code: Select all
texture.palette[255] = texture.palette[255];
Code: Select all
if (!Q_strncmp(texture.identifier, "{",1))
texture.palette[255] = 0; //alpha color
else
texture.palette[255] = texture.palette[255];
I could try to look into it, but im sure thats out of my league (currently). I knew enough basic C to get by and hardly anything about PSPGUdrm_wayne wrote: you can also try to upload all 8bpp paltextures to the PSPGU with the built-in DXT compressor,
this will save alot of ram.