Convert the colormap to a 2D palette.

This skips one level of indirection in the alias model and brush shaders.
Hopefully, this will improve performance on my eeepc.
This commit is contained in:
Bill Currie 2012-01-14 21:42:42 +09:00
parent 928dd92276
commit c884ef5f80
5 changed files with 29 additions and 37 deletions

View file

@ -73,7 +73,6 @@ static struct {
shaderparam_t normalb; shaderparam_t normalb;
shaderparam_t vertexa; shaderparam_t vertexa;
shaderparam_t vertexb; shaderparam_t vertexb;
shaderparam_t palette;
shaderparam_t colormap; shaderparam_t colormap;
shaderparam_t skin; shaderparam_t skin;
shaderparam_t ambient; shaderparam_t ambient;
@ -93,7 +92,6 @@ static struct {
{"vnormalb", 0}, {"vnormalb", 0},
{"vertexa", 0}, {"vertexa", 0},
{"vertexb", 0}, {"vertexb", 0},
{"palette", 1},
{"colormap", 1}, {"colormap", 1},
{"skin", 1}, {"skin", 1},
{"ambient", 1}, {"ambient", 1},
@ -125,7 +123,6 @@ R_InitAlias (void)
GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.normalb); GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.normalb);
GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.vertexa); GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.vertexa);
GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.vertexb); GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.vertexb);
GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.palette);
GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.colormap); GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.colormap);
GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.skin); GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.skin);
GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.ambient); GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.ambient);
@ -291,11 +288,6 @@ R_AliasBegin (void)
qfglEnable (GL_TEXTURE_2D); qfglEnable (GL_TEXTURE_2D);
qfglBindTexture (GL_TEXTURE_2D, glsl_colormap); qfglBindTexture (GL_TEXTURE_2D, glsl_colormap);
qfglUniform1i (quake_mdl.palette.location, 2);
qfglActiveTexture (GL_TEXTURE0 + 2);
qfglEnable (GL_TEXTURE_2D);
qfglBindTexture (GL_TEXTURE_2D, glsl_palette);
qfglUniform1i (quake_mdl.skin.location, 0); qfglUniform1i (quake_mdl.skin.location, 0);
qfglActiveTexture (GL_TEXTURE0 + 0); qfglActiveTexture (GL_TEXTURE0 + 0);
qfglEnable (GL_TEXTURE_2D); qfglEnable (GL_TEXTURE_2D);
@ -318,6 +310,4 @@ R_AliasEnd (void)
qfglDisable (GL_TEXTURE_2D); qfglDisable (GL_TEXTURE_2D);
qfglActiveTexture (GL_TEXTURE0 + 1); qfglActiveTexture (GL_TEXTURE0 + 1);
qfglDisable (GL_TEXTURE_2D); qfglDisable (GL_TEXTURE_2D);
qfglActiveTexture (GL_TEXTURE0 + 2);
qfglDisable (GL_TEXTURE_2D);
} }

View file

@ -129,7 +129,6 @@ static struct {
shaderparam_t mvp_matrix; shaderparam_t mvp_matrix;
shaderparam_t tlst; shaderparam_t tlst;
shaderparam_t vertex; shaderparam_t vertex;
shaderparam_t palette;
shaderparam_t colormap; shaderparam_t colormap;
shaderparam_t texture; shaderparam_t texture;
shaderparam_t lightmap; shaderparam_t lightmap;
@ -138,7 +137,6 @@ static struct {
{"mvp_mat", 1}, {"mvp_mat", 1},
{"tlst", 0}, {"tlst", 0},
{"vertex", 0}, {"vertex", 0},
{"palette", 1},
{"colormap", 1}, {"colormap", 1},
{"texture", 1}, {"texture", 1},
{"lightmap", 1}, {"lightmap", 1},
@ -797,11 +795,6 @@ bsp_begin (void)
qfglEnable (GL_TEXTURE_2D); qfglEnable (GL_TEXTURE_2D);
qfglBindTexture (GL_TEXTURE_2D, glsl_colormap); qfglBindTexture (GL_TEXTURE_2D, glsl_colormap);
qfglUniform1i (quake_bsp.palette.location, 3);
qfglActiveTexture (GL_TEXTURE0 + 3);
qfglEnable (GL_TEXTURE_2D);
qfglBindTexture (GL_TEXTURE_2D, glsl_palette);
qfglUniform1i (quake_bsp.lightmap.location, 1); qfglUniform1i (quake_bsp.lightmap.location, 1);
qfglActiveTexture (GL_TEXTURE0 + 1); qfglActiveTexture (GL_TEXTURE0 + 1);
qfglEnable (GL_TEXTURE_2D); qfglEnable (GL_TEXTURE_2D);
@ -826,8 +819,6 @@ bsp_end (void)
qfglDisable (GL_TEXTURE_2D); qfglDisable (GL_TEXTURE_2D);
qfglActiveTexture (GL_TEXTURE0 + 2); qfglActiveTexture (GL_TEXTURE0 + 2);
qfglDisable (GL_TEXTURE_2D); qfglDisable (GL_TEXTURE_2D);
qfglActiveTexture (GL_TEXTURE0 + 3);
qfglDisable (GL_TEXTURE_2D);
qfglBindBuffer (GL_ARRAY_BUFFER, 0); qfglBindBuffer (GL_ARRAY_BUFFER, 0);
} }
@ -1158,7 +1149,6 @@ R_InitBsp (void)
GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.mvp_matrix); GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.mvp_matrix);
GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.tlst); GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.tlst);
GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.vertex); GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.vertex);
GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.palette);
GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.colormap); GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.colormap);
GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.texture); GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.texture);
GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.lightmap); GL_ResolveShaderParam (quake_bsp.program, &quake_bsp.lightmap);

View file

@ -1,4 +1,3 @@
uniform sampler2D palette;
uniform sampler2D colormap; uniform sampler2D colormap;
uniform sampler2D texture; uniform sampler2D texture;
uniform sampler2D lightmap; uniform sampler2D lightmap;
@ -13,6 +12,5 @@ main (void)
float light = texture2D (lightmap, lst).r; float light = texture2D (lightmap, lst).r;
float col; float col;
col = texture2D (colormap, vec2 (pix, light * 4.0)).r; gl_FragColor = texture2D (colormap, vec2 (pix, light * 4.0));
gl_FragColor = texture2D (palette, vec2 (col, 0.0));
} }

View file

@ -1,4 +1,3 @@
uniform sampler2D palette;
uniform sampler2D colormap; uniform sampler2D colormap;
uniform sampler2D skin; uniform sampler2D skin;
uniform float ambient; uniform float ambient;
@ -20,6 +19,5 @@ main (void)
d = min (d, 0.0); d = min (d, 0.0);
light = 255.0 - light; light = 255.0 - light;
light += d * shadelight; light += d * shadelight;
col = texture2D (colormap, vec2 (pix, light / 255.0)).r; gl_FragColor = texture2D (colormap, vec2 (pix, light / 255.0));
gl_FragColor = texture2D (palette, vec2 (col, 0.0));
} }

View file

@ -74,7 +74,7 @@ GL_Common_Init_Cvars (void)
void void
VID_SetPalette (unsigned char *palette) VID_SetPalette (unsigned char *palette)
{ {
byte *pal, *ip, *op; byte *pal, *col, *ip, *op;
unsigned int r, g, b, v; unsigned int r, g, b, v;
unsigned short i; unsigned short i;
unsigned int *table; unsigned int *table;
@ -99,15 +99,37 @@ VID_SetPalette (unsigned char *palette)
} }
d_8to24table[255] = 0; // 255 is transparent d_8to24table[255] = 0; // 255 is transparent
Sys_MaskPrintf (SYS_VID, "Converting palette to RGBA texture\n"); Sys_MaskPrintf (SYS_VID, "Converting palette/colormap to RGBA textures\n");
pal = malloc (256 * 4); pal = malloc (256 * VID_GRADES * 4);
for (i = 0, ip = palette, op = pal; i < 255; i++) { for (i = 0, col = vid.colormap8, op = pal; i < 256 * VID_GRADES; i++) {
ip = palette + *col++ * 3;
*op++ = *ip++;
*op++ = *ip++;
*op++ = *ip++;
*op++ = 255; // alpha = 1
}
for (i = 0; i < VID_GRADES; i++)
pal[i * 256 * 4 + 255 + 3] = 0;
if (!glsl_colormap) {
GLuint tex;
qfglGenTextures (1, &tex);
glsl_colormap = tex;
}
qfglBindTexture (GL_TEXTURE_2D, glsl_colormap);
qfglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, VID_GRADES, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pal);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
for (i = 0, ip = palette, op = pal; i < 256; i++) {
*op++ = *ip++; *op++ = *ip++;
*op++ = *ip++; *op++ = *ip++;
*op++ = *ip++; *op++ = *ip++;
*op++ = 255; // alpha = 1 *op++ = 255; // alpha = 1
} }
QuatZero (op); // color 255 = transparent (alpha = 0)
if (!glsl_palette) { if (!glsl_palette) {
GLuint tex; GLuint tex;
@ -121,13 +143,7 @@ VID_SetPalette (unsigned char *palette)
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
qfglGenerateMipmap (GL_TEXTURE_2D);
free (pal); free (pal);
if (glsl_colormap)
GL_ReleaseTexture (glsl_colormap);
glsl_colormap = GL_LoadQuakeTexture ("colormap", 256, VID_GRADES,
vid.colormap8);
} }
void void