2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 void R_InitTextures (void)
36 // create a simple checkerboard texture for the default
37 r_notexture_mip = Hunk_AllocName (sizeof(texture_t) + 16*16+8*8+4*4+2*2, "notexture");
39 r_notexture_mip->width = r_notexture_mip->height = 16;
40 r_notexture_mip->offsets[0] = sizeof(texture_t);
41 r_notexture_mip->offsets[1] = r_notexture_mip->offsets[0] + 16*16;
42 r_notexture_mip->offsets[2] = r_notexture_mip->offsets[1] + 8*8;
43 r_notexture_mip->offsets[3] = r_notexture_mip->offsets[2] + 4*4;
44 r_notexture_mip->transparent = FALSE;
48 dest = (byte *)r_notexture_mip + r_notexture_mip->offsets[m];
49 for (y=0 ; y< (16>>m) ; y++)
50 for (x=0 ; x< (16>>m) ; x++)
52 if ( (y< (8>>m) ) ^ (x< (8>>m) ) )
64 Grab six views for environment mapping tests
67 void R_Envmap_f (void)
69 byte buffer[256*256*4];
71 glDrawBuffer (GL_FRONT);
72 glReadBuffer (GL_FRONT);
77 r_refdef.vrect.width = 256;
78 r_refdef.vrect.height = 256;
80 r_refdef.viewangles[0] = 0;
81 r_refdef.viewangles[1] = 0;
82 r_refdef.viewangles[2] = 0;
83 GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
85 glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
86 COM_WriteFile ("env0.rgb", buffer, sizeof(buffer));
88 r_refdef.viewangles[1] = 90;
89 GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
91 glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
92 COM_WriteFile ("env1.rgb", buffer, sizeof(buffer));
94 r_refdef.viewangles[1] = 180;
95 GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
97 glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
98 COM_WriteFile ("env2.rgb", buffer, sizeof(buffer));
100 r_refdef.viewangles[1] = 270;
101 GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
103 glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
104 COM_WriteFile ("env3.rgb", buffer, sizeof(buffer));
106 r_refdef.viewangles[0] = -90;
107 r_refdef.viewangles[1] = 0;
108 GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
110 glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
111 COM_WriteFile ("env4.rgb", buffer, sizeof(buffer));
113 r_refdef.viewangles[0] = 90;
114 r_refdef.viewangles[1] = 0;
115 GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
117 glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
118 COM_WriteFile ("env5.rgb", buffer, sizeof(buffer));
121 glDrawBuffer (GL_BACK);
122 glReadBuffer (GL_BACK);
126 void R_InitParticles (void);
135 // extern cvar_t gl_finish;
137 Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
138 Cmd_AddCommand ("envmap", R_Envmap_f);
139 Cmd_AddCommand ("pointfile", R_ReadPointFile_f);
141 // Cvar_RegisterVariable (&r_norefresh);
142 // Cvar_RegisterVariable (&r_lightmap);
143 Cvar_RegisterVariable (&r_drawentities);
144 Cvar_RegisterVariable (&r_drawviewmodel);
145 Cvar_RegisterVariable (&r_shadows);
146 Cvar_RegisterVariable (&r_wateralpha);
147 Cvar_RegisterVariable (&r_dynamic);
148 Cvar_RegisterVariable (&r_novis);
149 Cvar_RegisterVariable (&r_speeds);
150 Cvar_RegisterVariable (&r_waterripple); // LordHavoc: added waterripple
152 // Cvar_RegisterVariable (&gl_cull);
153 // Cvar_RegisterVariable (&gl_affinemodels);
154 // Cvar_RegisterVariable (&gl_polyblend);
155 // Cvar_RegisterVariable (&gl_flashblend);
156 Cvar_RegisterVariable (&gl_playermip);
157 // Cvar_RegisterVariable (&gl_nocolors);
159 // Cvar_RegisterVariable (&gl_keeptjunctions);
160 // Cvar_RegisterVariable (&gl_reporttjunctions);
164 playertextures = texture_extension_number;
165 texture_extension_number += 64; // LordHavoc: increased number of players from 16 to 64
168 qboolean VID_Is8bit(void);
169 void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboolean alpha);
173 R_TranslatePlayerSkin
175 Translates a skin texture by the per-player color lookup
178 void R_TranslatePlayerSkin (int playernum)
182 unsigned translate32[256];
185 aliashdr_t *paliashdr;
187 unsigned pixels[512*256], *out;
188 unsigned scaled_width, scaled_height;
189 int inwidth, inheight;
191 unsigned frac, fracstep;
193 top = cl.scores[playernum].colors & 0xf0;
194 bottom = (cl.scores[playernum].colors &15)<<4;
196 for (i=0 ; i<256 ; i++)
199 for (i=0 ; i<16 ; i++)
201 // LordHavoc: corrected color ranges
202 if (top < 128 || (top >= 224 && top < 240)) // the artists made some backwards ranges. sigh.
203 translate[TOP_RANGE+i] = top+i;
205 translate[TOP_RANGE+i] = top+15-i;
207 // LordHavoc: corrected color ranges
208 if (bottom < 128 || (bottom >= 224 && bottom < 240))
209 translate[BOTTOM_RANGE+i] = bottom+i;
211 translate[BOTTOM_RANGE+i] = bottom+15-i;
215 // locate the original skin pixels
217 currententity = &cl_entities[1+playernum];
218 model = currententity->model;
220 return; // player doesn't have a model yet
221 if (model->type != mod_alias)
222 return; // only translate skins on alias models
224 paliashdr = (aliashdr_t *)Mod_Extradata (model);
225 s = paliashdr->skinwidth * paliashdr->skinheight;
226 if (currententity->skinnum < 0 || currententity->skinnum >= paliashdr->numskins)
228 Con_Printf("(%d): Invalid player skin #%d\n", playernum, currententity->skinnum);
229 original = (byte *)paliashdr + paliashdr->texels[0];
232 original = (byte *)paliashdr + paliashdr->texels[currententity->skinnum];
234 Sys_Error ("R_TranslateSkin: s&3");
236 inwidth = paliashdr->skinwidth;
237 inheight = paliashdr->skinheight;
239 // because this happens during gameplay, do it fast
240 // instead of sending it through gl_upload 8
241 glBindTexture(GL_TEXTURE_2D, playertextures + playernum);
244 byte translated[320*200];
246 for (i=0 ; i<s ; i+=4)
248 translated[i] = translate[original[i]];
249 translated[i+1] = translate[original[i+1]];
250 translated[i+2] = translate[original[i+2]];
251 translated[i+3] = translate[original[i+3]];
255 // don't mipmap these, because it takes too long
256 GL_Upload8 (translated, paliashdr->skinwidth, paliashdr->skinheight, false, false, true);
258 scaled_width = gl_max_size.value < 512 ? gl_max_size.value : 512;
259 scaled_height = gl_max_size.value < 256 ? gl_max_size.value : 256;
261 // allow users to crunch sizes down even more if they want
262 scaled_width >>= (int)gl_playermip.value;
263 scaled_height >>= (int)gl_playermip.value;
266 { // 8bit texture upload
269 out2 = (byte *)pixels;
270 memset(pixels, 0, sizeof(pixels));
271 fracstep = inwidth*0x10000/scaled_width;
272 for (i=0 ; i<scaled_height ; i++, out2 += scaled_width)
274 inrow = original + inwidth*(i*inheight/scaled_height);
275 frac = fracstep >> 1;
276 for (j=0 ; j<scaled_width ; j+=4)
278 out2[j] = translate[inrow[frac>>16]];
280 out2[j+1] = translate[inrow[frac>>16]];
282 out2[j+2] = translate[inrow[frac>>16]];
284 out2[j+3] = translate[inrow[frac>>16]];
289 GL_Upload8_EXT ((byte *)pixels, scaled_width, scaled_height, false, false);
293 for (i=0 ; i<256 ; i++)
294 translate32[i] = d_8to24table[translate[i]];
297 fracstep = inwidth*0x10000/scaled_width;
298 for (i=0 ; i<scaled_height ; i++, out += scaled_width)
300 inrow = original + inwidth*(i*inheight/scaled_height);
301 frac = fracstep >> 1;
302 for (j=0 ; j<scaled_width ; j+=4)
304 out[j] = translate32[inrow[frac>>16]];
306 out[j+1] = translate32[inrow[frac>>16]];
308 out[j+2] = translate32[inrow[frac>>16]];
310 out[j+3] = translate32[inrow[frac>>16]];
314 glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
316 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
317 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
318 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
323 void R_ClearParticles (void);
324 void GL_BuildLightmaps (void);
331 void SHOWLMP_clear();
336 for (i=0 ; i<256 ; i++)
337 d_lightstylevalue[i] = 264; // normal light value
339 memset (&r_worldentity, 0, sizeof(r_worldentity));
340 r_worldentity.model = cl.worldmodel;
341 currententity = &r_worldentity;
343 // clear out efrags in case the level hasn't been reloaded
344 // FIXME: is this one short?
345 for (i=0 ; i<cl.worldmodel->numleafs ; i++)
346 cl.worldmodel->leafs[i].efrags = NULL;
351 GL_BuildLightmaps ();
353 // identify sky texture
355 for (i=0 ; i<cl.worldmodel->numtextures ; i++)
357 if (!cl.worldmodel->textures[i])
359 if (!strncmp(cl.worldmodel->textures[i]->name,"sky",3) )
361 cl.worldmodel->textures[i]->texturechain = NULL;
371 For program optimization
374 void R_TimeRefresh_f (void)
377 float start, stop, time;
379 start = Sys_FloatTime ();
380 for (i=0 ; i<128 ; i++)
382 r_refdef.viewangles[1] = i/128.0*360.0;
386 stop = Sys_FloatTime ();
388 Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
391 void D_FlushCaches (void)