gl_draw.c: gl_lightmode now uses a callback.

gl_dyn_part.c:
  Now uses a (non-locked) vertex array to reduce GL calls.
  Gives a slight speed gain, I'll optimize it a bit more soon.
gl_rlight.c:
  Fixed much of the dlightframecount issues.
  (This gives cleaner code and a speed up.)
gl_rmain.c: A slight reorg of the dlight call order.
gl_rmisc.c: Enable some of the vertex arrays. (vertex, texcoord, color.)
gl_rsurf.c:
  Reworked R_BuildLightMap, smaller now code wise, also more optimized,
  and it builds a 0-2 lightmap in more cases now.

  Playing with GL_UploadLightmap.

  For non-lighthalf non-mtex lightmaps use a 0-2 range.
  (Makes gl_lightmode look a /lot/ better.)

gl_screen.c: More stuff with the gl_lightmode callback.
r_view.c: R_PushDlights is called elsewhere now.
sw_rmain.c:
  Moved the R_PushDlights call.
  Also killed the unused PASSAGES define.
This commit is contained in:
Zephaniah E. Hull 2001-04-06 02:57:26 +00:00
parent 9ea0605558
commit b7ee9ba07d
10 changed files with 141 additions and 161 deletions

View file

@ -68,9 +68,6 @@ typedef struct entity_s
struct efrag_s *efrag; // linked list of efrags (FIXME)
int visframe; // last frame this entity was found in an active leaf, only used for static objects
int dlightframe; // dynamic lighting
int dlightbits;
float colormod[3]; // color tint for model
float alpha; // opacity (alpha) of the model
float scale; // size scaler of the model

View file

@ -251,6 +251,19 @@ Draw_TextBox (int x, int y, int width, int lines)
extern void glrmain_init (void);
extern void glrsurf_init (void);
extern void GL_TextureMode_f (void);
extern void R_ForceLightUpdate (void);
void
gl_lightmode_callback (cvar_t *cvar)
{
if (cvar->int_val) {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 128;
} else {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 255;
}
R_ForceLightUpdate ();
}
void
Draw_Init (void)
@ -266,14 +279,7 @@ Draw_Init (void)
Cvar_Set (gl_lightmode, "0");
}
lighthalf = gl_lightmode->int_val != 0; // to avoid re-rendering all
// lightmaps on first frame
if (lighthalf) {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 128;
} else {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 255;
}
gl_lightmode_callback(gl_lightmode);
Cmd_AddCommand ("gl_texturemode", &GL_TextureMode_f, "Texture mipmap quality.");
@ -305,12 +311,12 @@ Draw_Init (void)
glrsurf_init ();
}
void
Draw_Init_Cvars (void)
{
gl_lightmode = Cvar_Get ("gl_lightmode", "1", CVAR_ARCHIVE, 0,
"Lighting mode (0 = GLQuake style, 1 = new style)");
gl_lightmode = Cvar_Get ("gl_lightmode", "1", CVAR_ARCHIVE,
gl_lightmode_callback,
"Lighting mode (0 = GLQuake style, 1 = new style)");
gl_max_size = Cvar_Get ("gl_max_size", "1024", CVAR_NONE, 0, "Texture dimension");
gl_picmip = Cvar_Get ("gl_picmip", "0", CVAR_NONE, 0, "Dimensions of displayed textures. 0 is normal, 1 is half, 2 is 1/4");
gl_constretch = Cvar_Get ("gl_constretch", "0", CVAR_ARCHIVE, 0,

View file

@ -66,9 +66,15 @@ typedef struct particle_s {
ptype_t type;
} particle_t;
typedef struct varray_s {
float texcoord[2];
unsigned char color[4];
float vertex[3];
} varray_t;
static particle_t *particles, **freeparticles;
static short r_numparticles, numparticles;
//static varray_t *vertex_array;
extern qboolean lighthalf;
@ -148,11 +154,13 @@ R_MaxParticlesCheck (cvar_t *var)
// and the compiler doesn't know when we do bad things with them.
free (particles);
free (freeparticles);
//free (vertex_array);
particles = (particle_t *)
calloc (r_numparticles, sizeof (particle_t));
freeparticles = (particle_t **)
calloc (r_numparticles, sizeof (particle_t*));
//vertex_array = (float *) calloc(r_numparticles, sizeof (varray_t));
R_ClearParticles();
}
@ -558,11 +566,21 @@ R_DrawParticles (void)
vec3_t up, right;
float scale;
particle_t *part;
int activeparticles, maxparticle, j, k;
int activeparticles, maxparticle, j, k, vnum;
varray_t vertex_array[4];
// LordHavoc: particles should not affect zbuffer
glDepthMask (GL_FALSE);
glInterleavedArrays (GL_T2F_C4UB_V3F, 0, (void *) &(vertex_array[0]));
vertex_array[0].texcoord[0] = 0; vertex_array[0].texcoord[1] = 1;
vertex_array[1].texcoord[0] = 0; vertex_array[1].texcoord[1] = 0;
vertex_array[2].texcoord[0] = 1; vertex_array[2].texcoord[1] = 0;
vertex_array[3].texcoord[0] = 1; vertex_array[3].texcoord[1] = 1;
vnum = 0;
VectorScale (vup, 1.5, up);
VectorScale (vright, 1.5, right);
@ -592,38 +610,51 @@ R_DrawParticles (void)
at = (byte *) & d_8to24table[(byte) part->color];
alpha = part->alpha;
if (lighthalf)
glColor4ub ((byte) ((int) at[0] >> 1),
(byte) ((int) at[1] >> 1),
(byte) ((int) at[2] >> 1), alpha);
else
glColor4ub (at[0], at[1], at[2], alpha);
if (lighthalf) {
vertex_array[0].color[0] = (byte) ((int) at[0] >> 1);
vertex_array[0].color[1] = (byte) ((int) at[1] >> 1);
vertex_array[0].color[2] = (byte) ((int) at[2] >> 1);
} else {
VectorCopy(at, vertex_array[0].color);
}
vertex_array[0].color[3] = alpha;
memcpy(vertex_array[1].color, vertex_array[0].color, 4);
memcpy(vertex_array[2].color, vertex_array[0].color, 4);
memcpy(vertex_array[3].color, vertex_array[0].color, 4);
scale = part->scale;
vertex_array[0].vertex[0] =
(part->org[0] + ((up[0] + right[0]) * scale));
vertex_array[0].vertex[1] =
(part->org[1] + ((up[1] + right[1]) * scale));
vertex_array[0].vertex[2] =
(part->org[2] + ((up[2] + right[2]) * scale));
vertex_array[1].vertex[0] =
(part->org[0] + (up[0] * -scale) + (right[0] * scale));
vertex_array[1].vertex[1] =
(part->org[1] + (up[1] * -scale) + (right[1] * scale));
vertex_array[1].vertex[2] =
(part->org[2] + (up[2] * -scale) + (right[2] * scale));
vertex_array[2].vertex[0] =
(part->org[0] + ((up[0] + right[0]) * -scale));
vertex_array[2].vertex[1] =
(part->org[1] + ((up[1] + right[1]) * -scale));
vertex_array[2].vertex[2] =
(part->org[2] + ((up[2] + right[2]) * -scale));
vertex_array[3].vertex[0] =
(part->org[0] + (up[0] * scale) + (right[0] * -scale));
vertex_array[3].vertex[1] =
(part->org[1] + (up[1] * scale) + (right[1] * -scale));
vertex_array[3].vertex[2] =
(part->org[2] + (up[2] * scale) + (right[2] * -scale));
glBindTexture (GL_TEXTURE_2D, part->tex);
glBegin (GL_QUADS);
glTexCoord2f (0, 1);
glVertex3f ((part->org[0] + ((up[0] + right[0]) * scale)),
(part->org[1] + ((up[1] + right[1]) * scale)),
(part->org[2] + ((up[2] + right[2]) * scale)));
glTexCoord2f (0, 0);
glVertex3f ((part->org[0] + (up[0] * -scale) + (right[0] * scale)),
(part->org[1] + (up[1] * -scale) + (right[1] * scale)),
(part->org[2] + (up[2] * -scale) + (right[2] * scale)));
glTexCoord2f (1, 0);
glVertex3f ((part->org[0] + ((up[0] + right[0]) * -scale)),
(part->org[1] + ((up[1] + right[1]) * -scale)),
(part->org[2] + ((up[2] + right[2]) * -scale)));
glTexCoord2f (1, 1);
glVertex3f ((part->org[0] + (up[0] * scale) + (right[0] * -scale)),
(part->org[1] + (up[1] * scale) + (right[1] * -scale)),
(part->org[2] + (up[2] * scale) + (right[2] * -scale)));
glEnd ();
glDrawArrays (GL_QUADS, 0, 4);
}
for (i = 0; i < 3; i++)

View file

@ -41,10 +41,6 @@
#include "glquake.h"
int r_dlightframecount;
extern qboolean lighthalf;
/*
R_AnimateLight
*/
@ -168,8 +164,6 @@ R_RenderDlights (void)
if (!gl_dlight_polyblend->int_val)
return;
r_dlightframecount = r_framecount + 1; // because the count hasn't
// advanced yet for this frame
glDepthMask (GL_FALSE);
glDisable (GL_TEXTURE_2D);
glBlendFunc (GL_ONE, GL_ONE);
@ -264,13 +258,12 @@ R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, mnode_t *node)
t = l - t;
// compare to minimum light
if ((s * s + t * t + dist * dist) < maxdist) {
if (surf->dlightframe != r_dlightframecount) // not dynamic
// until now
{
if (surf->dlightframe != r_framecount) {
surf->dlightframe = r_framecount;
surf->dlightbits = bit;
surf->dlightframe = r_dlightframecount;
} else // already dynamic
} else {
surf->dlightbits |= bit;
}
}
}
@ -282,10 +275,9 @@ R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, mnode_t *node)
R_MarkLights (lightorigin, light, bit, node->children[1]);
}
/*
R_PushDlights
*/
R_PushDlights
*/
void
R_PushDlights (vec3_t entorigin)
{
@ -296,8 +288,6 @@ R_PushDlights (vec3_t entorigin)
if (!gl_dlight_lightmap->int_val)
return;
r_dlightframecount = r_framecount + 1; // because the count hasn't
// advanced yet for this frame
l = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, l++) {

View file

@ -1205,6 +1205,8 @@ R_RenderView (void)
R_SetupGL ();
R_PushDlights (vec3_origin);
R_MarkLeaves (); // done here so we know if we're in
// water

View file

@ -201,6 +201,10 @@ R_Init (void)
texture_extension_number += MAX_CLIENTS;
player_fb_textures = texture_extension_number;
texture_extension_number += MAX_CACHED_SKINS;
glEnableClientState (GL_COLOR_ARRAY);
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
}
void

View file

@ -94,7 +94,7 @@ glrsurf_init (void)
memset (&lightmaps, 0, sizeof (lightmaps));
}
void
static void
R_RecursiveLightUpdate (mnode_t *node)
{
int c;
@ -220,8 +220,7 @@ void
R_BuildLightMap (msurface_t *surf, byte * dest, int stride)
{
int smax, tmax;
int t;
int i, j, size;
int i, j, size, shift;
byte *lightmap;
unsigned int scale;
int maps;
@ -265,85 +264,46 @@ R_BuildLightMap (msurface_t *surf, byte * dest, int stride)
// bound and shift
stride -= smax * lightmap_bytes;
bl = blocklights;
if (gl_mtex_active && !lighthalf) {
shift = 7; // 0-1 lightmap range.
} else {
shift = 8; // 0-2 lightmap range.
}
switch (lightmap_bytes) {
case 4:
if (lighthalf) {
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
t = (int) *bl++ >> 8;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 8;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 8;
*dest++ = bound (0, t, 255);
*dest++ = 255;
}
}
} else {
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
t = (int) *bl++ >> 7;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 7;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 7;
*dest++ = bound (0, t, 255);
*dest++ = 255;
}
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
dest[0] = bound(0, bl[0] >> shift, 255);
dest[1] = bound(0, bl[1] >> shift, 255);
dest[2] = bound(0, bl[2] >> shift, 255);
dest[3] = 255;
dest += 4;
bl += 3;
}
}
break;
case 3:
if (lighthalf) {
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
t = (int) *bl++ >> 8;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 8;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 8;
*dest++ = bound (0, t, 255);
}
}
} else {
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
t = (int) *bl++ >> 7;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 7;
*dest++ = bound (0, t, 255);
t = (int) *bl++ >> 7;
*dest++ = bound (0, t, 255);
}
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
dest[0] = bound(0, bl[0] >> shift, 255);
dest[1] = bound(0, bl[1] >> shift, 255);
dest[2] = bound(0, bl[2] >> shift, 255);
dest += 3;
bl += 3;
}
}
break;
case 1:
if (lighthalf) {
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
t = (int) *bl++ >> 8;
t2 = bound (0, t, 255);
t = (int) *bl++ >> 8;
t2 += bound (0, t, 255);
t = (int) *bl++ >> 8;
t2 += bound (0, t, 255);
t2 *= (1.0 / 3.0);
*dest++ = t2;
}
}
} else {
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
t = (int) *bl++ >> 7;
t2 = bound (0, t, 255);
t = (int) *bl++ >> 7;
t2 += bound (0, t, 255);
t = (int) *bl++ >> 7;
t2 += bound (0, t, 255);
t2 *= (1.0 / 3.0);
*dest++ = t2;
}
for (i = 0; i < tmax; i++, dest += stride) {
for (j = 0; j < smax; j++) {
t2 = bound (0, bl[0] >> shift, 255);
t2 += bound (0, bl[1] >> shift, 255);
t2 += bound (0, bl[2] >> shift, 255);
t2 *= (1.0 / 3.0);
*dest++ = t2;
bl += 3;
}
}
break;
@ -399,9 +359,14 @@ QF_glMultiTexCoord2fARB qglMultiTexCoord2f = NULL;
void
GL_UploadLightmap (int i, int x, int y, int w, int h)
{
/*
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, y, BLOCK_WIDTH, h, gl_lightmap_format,
GL_UNSIGNED_BYTE,
lightmaps[i] + (y * BLOCK_WIDTH) * lightmap_bytes);
*/
glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, BLOCK_WIDTH,
BLOCK_HEIGHT, 0, gl_lightmap_format,
GL_UNSIGNED_BYTE, lightmaps[i]);
}
/*
@ -440,9 +405,7 @@ R_DrawMultitexturePoly (msurface_t *s)
if (d_lightstylevalue[s->styles[maps]] != s->cached_light[maps])
goto dynamic;
if (s->dlightframe == r_framecount // dynamic this frame
|| s->cached_dlight) // dynamic previously
{
if ((s->dlightframe = r_framecount) || s->cached_dlight) {
dynamic:
R_BuildLightMap (s,
lightmaps[s->lightmaptexturenum] +
@ -487,7 +450,11 @@ R_BlendLightmaps (void)
glDepthMask (GL_FALSE); // don't bother writing Z
glBlendFunc (GL_ZERO, GL_SRC_COLOR);
if (lighthalf)
glBlendFunc (GL_ZERO, GL_SRC_COLOR);
else
glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR);
glColor3f (1, 1, 1);
for (i = 0; i < MAX_LIGHTMAPS; i++) {
@ -590,9 +557,7 @@ R_RenderBrushPoly (msurface_t *fa)
if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps])
goto dynamic;
if (fa->dlightframe == r_framecount // dynamic this frame
|| fa->cached_dlight) // dynamic previously
{
if ((fa->dlightframe == r_framecount) || fa->cached_dlight) {
dynamic:
if (r_dynamic->int_val) {
lightmap_modified[fa->lightmaptexturenum] = true;

View file

@ -976,15 +976,6 @@ SCR_UpdateScreen (void)
// do 3D refresh drawing, and then update the screen
if (lighthalf != gl_lightmode->int_val) {
lighthalf = gl_lightmode->int_val;
if (lighthalf)
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 128;
else
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 255;
R_ForceLightUpdate ();
}
SCR_SetUpToDrawConsole ();
V_RenderView ();
@ -1024,12 +1015,14 @@ SCR_UpdateScreen (void)
glDisable (GL_TEXTURE_2D);
Cvar_SetValue (brightness, bound (1, brightness->value, 5));
if (lighthalf) // LordHavoc: render was done at half
//
// brightness
if (lighthalf) { // LordHavoc: render was done at half
// brightness
f = brightness->value * 2;
else
} else {
Cvar_SetValue (brightness, bound (1, brightness->value, 5));
f = brightness->value;
}
if (f >= 1.002) { // Make sure we don't get bit by
// roundoff errors
glBlendFunc (GL_DST_COLOR, GL_ONE);

View file

@ -719,8 +719,6 @@ V_RenderView (void)
V_CalcRefdef ();
}
R_PushDlights (vec3_origin);
R_RenderView ();
}

View file

@ -52,7 +52,6 @@
#include "QF/sys.h"
#include "view.h"
//define PASSAGES
void *colormap;
vec3_t viewlightvec;
@ -178,9 +177,6 @@ cvar_t *gl_sky_divide;
extern cvar_t *scr_fov;
void CreatePassages (void);
void SetVisibilityByPassages (void);
void R_NetGraph (void);
void R_ZGraph (void);
@ -1005,14 +1001,12 @@ R_RenderView_ (void)
if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val)
r_time1 = Sys_DoubleTime ();
R_PushDlights (vec3_origin);
R_SetupFrame ();
#ifdef PASSAGES
SetVisibilityByPassages ();
#else
R_MarkLeaves (); // done here so we know if we're in
// water
#endif
// make FDIV fast. This reduces timing precision after we've been running for a
// while, so we don't do it globally. This also sets chop mode, and we do it