#include "quakedef.h"
-//cvar_t gl_mesh_maxtriangles = {0, "gl_mesh_maxtriangles", "21760"};
cvar_t gl_mesh_maxtriangles = {0, "gl_mesh_maxtriangles", "1024"};
-//cvar_t gl_mesh_batchtriangles = {0, "gl_mesh_batchtriangles", "1024"};
-cvar_t gl_mesh_batchtriangles = {0, "gl_mesh_batchtriangles", "0"};
cvar_t gl_mesh_transtriangles = {0, "gl_mesh_transtriangles", "16384"};
-cvar_t gl_mesh_floatcolors = {0, "gl_mesh_floatcolors", "0"};
+cvar_t gl_mesh_floatcolors = {0, "gl_mesh_floatcolors", "1"};
cvar_t gl_mesh_drawmode = {CVAR_SAVE, "gl_mesh_drawmode", "3"};
cvar_t r_render = {0, "r_render", "1"};
cvar_t gl_dither = {CVAR_SAVE, "gl_dither", "1"}; // whether or not to use dithering
cvar_t gl_lockarrays = {0, "gl_lockarrays", "1"};
+// this is used to increase gl_mesh_maxtriangles automatically if a mesh was
+// too large for the buffers in the previous frame
+int overflowedverts = 0;
+// increase transtriangles automatically too
+int overflowedtransverts = 0;
+
+int gl_maxdrawrangeelementsvertices;
+int gl_maxdrawrangeelementsindices;
+
#ifdef DEBUGGL
int errornumber = 0;
}
#endif
-float r_farclip, r_newfarclip;
-
-int polyindexarray[768];
+float r_mesh_farclip;
static float viewdist;
+// sign bits (true if negative) for vpn[] entries, so quick integer compares can be used instead of float compares
+static int vpnbit0, vpnbit1, vpnbit2;
int c_meshs, c_meshtris, c_transmeshs, c_transtris;
-int lightscalebit;
-float lightscale;
-float overbrightscale;
+int lightscalebit;
+float lightscale;
+float overbrightscale;
void SCR_ScreenShot_f (void);
static int max_meshs;
static int max_transmeshs;
-static int max_batch;
static int max_verts; // always max_meshs * 3
static int max_transverts; // always max_transmeshs * 3
#define TRANSDEPTHRES 4096
}
buf_texcoord_t;
-static float meshfarclip;
static int currentmesh, currenttriangle, currentvertex, backendunits, backendactive, transranout;
static buf_mesh_t *buf_mesh;
static buf_tri_t *buf_tri;
{
int i;
+ qglGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &gl_maxdrawrangeelementsvertices);
+ qglGetIntegerv(GL_MAX_ELEMENTS_INDICES, &gl_maxdrawrangeelementsindices);
+
+ Con_Printf("OpenGL Backend started with gl_mesh_maxtriangles %i, gl_mesh_transtriangles %i\n", gl_mesh_maxtriangles.integer, gl_mesh_transtriangles.integer);
+ if (qglDrawRangeElements != NULL)
+ Con_Printf("glDrawRangeElements detected (max vertices %i, max indices %i)\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
+ if (strstr(gl_renderer, "3Dfx"))
+ {
+ Con_Printf("3Dfx driver detected, forcing gl_mesh_floatcolors to 0 to prevent crashs\n");
+ Cvar_SetValueQuick(&gl_mesh_floatcolors, 0);
+ }
+ Con_Printf("\n");
+
max_verts = max_meshs * 3;
max_transverts = max_transmeshs * 3;
static void gl_backend_shutdown(void)
{
+ Con_Printf("OpenGL Backend shutting down\n");
+
if (resizingbuffers)
Mem_EmptyPool(gl_backend_mempool);
else
static void gl_backend_bufferchanges(int init)
{
+ if (overflowedverts > gl_mesh_maxtriangles.integer * 3)
+ Cvar_SetValueQuick(&gl_mesh_maxtriangles, (int) ((overflowedverts + 2) / 3));
+ overflowedverts = 0;
+
+ if (overflowedtransverts > gl_mesh_transtriangles.integer * 3)
+ Cvar_SetValueQuick(&gl_mesh_transtriangles, (int) ((overflowedtransverts + 2) / 3));
+ overflowedtransverts = 0;
+
+ if (gl_mesh_drawmode.integer < 0)
+ Cvar_SetValueQuick(&gl_mesh_drawmode, 0);
+ if (gl_mesh_drawmode.integer > 3)
+ Cvar_SetValueQuick(&gl_mesh_drawmode, 3);
+
+ if (gl_mesh_drawmode.integer >= 3 && qglDrawRangeElements == NULL)
+ {
+ // change drawmode 3 to 2 if 3 won't work at all
+ Cvar_SetValueQuick(&gl_mesh_drawmode, 2);
+ }
+
// 21760 is (65536 / 3) rounded off to a multiple of 128
- if (gl_mesh_maxtriangles.integer < 256)
- Cvar_SetValueQuick(&gl_mesh_maxtriangles, 256);
+ if (gl_mesh_maxtriangles.integer < 1024)
+ Cvar_SetValueQuick(&gl_mesh_maxtriangles, 1024);
if (gl_mesh_maxtriangles.integer > 21760)
Cvar_SetValueQuick(&gl_mesh_maxtriangles, 21760);
- if (gl_mesh_transtriangles.integer < 256)
- Cvar_SetValueQuick(&gl_mesh_transtriangles, 256);
+ if (gl_mesh_transtriangles.integer < 1024)
+ Cvar_SetValueQuick(&gl_mesh_transtriangles, 1024);
if (gl_mesh_transtriangles.integer > 65536)
Cvar_SetValueQuick(&gl_mesh_transtriangles, 65536);
- if (gl_mesh_batchtriangles.integer < 0)
- Cvar_SetValueQuick(&gl_mesh_batchtriangles, 0);
- if (gl_mesh_batchtriangles.integer > gl_mesh_maxtriangles.integer)
- Cvar_SetValueQuick(&gl_mesh_batchtriangles, gl_mesh_maxtriangles.integer);
-
- max_batch = gl_mesh_batchtriangles.integer;
-
if (max_meshs != gl_mesh_maxtriangles.integer || max_transmeshs != gl_mesh_transtriangles.integer)
{
max_meshs = gl_mesh_maxtriangles.integer;
static void gl_backend_newmap(void)
{
- r_farclip = r_newfarclip = 2048.0f;
}
void gl_backend_init(void)
{
- int i;
-
Cvar_RegisterVariable(&r_render);
Cvar_RegisterVariable(&gl_dither);
Cvar_RegisterVariable(&gl_lockarrays);
Cvar_RegisterVariable(&gl_mesh_maxtriangles);
Cvar_RegisterVariable(&gl_mesh_transtriangles);
- Cvar_RegisterVariable(&gl_mesh_batchtriangles);
Cvar_RegisterVariable(&gl_mesh_floatcolors);
Cvar_RegisterVariable(&gl_mesh_drawmode);
R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap);
gl_backend_bufferchanges(true);
- for (i = 0;i < 256;i++)
- {
- polyindexarray[i*3+0] = 0;
- polyindexarray[i*3+1] = i + 1;
- polyindexarray[i*3+2] = i + 2;
- }
}
int arraylocked = false;
void GL_LockArray(int first, int count)
{
- if (!arraylocked && gl_supportslockarrays && gl_lockarrays.integer && gl_mesh_drawmode.integer != 0)
+ if (!arraylocked && gl_supportslockarrays && gl_lockarrays.integer && gl_mesh_drawmode.integer > 0)
{
qglLockArraysEXT(first, count);
CHECKGLERROR
}
}
-//static float gldepthmin, gldepthmax;
-
/*
=============
GL_SetupFrame
double xmax, ymax;
double fovx, fovy, zNear, zFar, aspect;
- // update farclip based on previous frame
- r_farclip = r_newfarclip;
-
if (!r_render.integer)
return;
-// qglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: moved to SCR_UpdateScreen
-// gldepthmin = 0;
-// gldepthmax = 1;
qglDepthFunc (GL_LEQUAL);CHECKGLERROR
-// qglDepthRange (gldepthmin, gldepthmax);CHECKGLERROR
-
// set up viewpoint
qglMatrixMode(GL_PROJECTION);CHECKGLERROR
qglLoadIdentity ();CHECKGLERROR
// depth range
zNear = 1.0;
- zFar = r_farclip;
+ zFar = r_mesh_farclip;
// fov angles
fovx = r_refdef.fov_x;
// set view pyramid
qglFrustum(-xmax, xmax, -ymax, ymax, zNear, zFar);CHECKGLERROR
-// qglCullFace(GL_FRONT);CHECKGLERROR
-
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
qglLoadIdentity ();CHECKGLERROR
qglRotatef (-r_refdef.viewangles[1], 0, 0, 1);CHECKGLERROR
// camera location
qglTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);CHECKGLERROR
-
-// qglGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
-
- //
- // set drawing parms
- //
-// if (gl_cull.integer)
-// {
-// qglEnable(GL_CULL_FACE);CHECKGLERROR
-// }
-// else
-// {
-// qglDisable(GL_CULL_FACE);CHECKGLERROR
-// }
-
-// qglEnable(GL_BLEND);CHECKGLERROR
-// qglEnable(GL_DEPTH_TEST);CHECKGLERROR
-// qglDepthMask(1);CHECKGLERROR
}
-static int mesh_blendfunc1;
-static int mesh_blendfunc2;
-static int mesh_blend;
-static GLboolean mesh_depthmask;
-static int mesh_depthtest;
-static int mesh_unit;
-static int mesh_clientunit;
-static int mesh_texture[MAX_TEXTUREUNITS];
-static float mesh_texturergbscale[MAX_TEXTUREUNITS];
+static struct
+{
+ int blendfunc1;
+ int blendfunc2;
+ int blend;
+ GLboolean depthmask;
+ int depthtest;
+ int unit;
+ int clientunit;
+ int texture[MAX_TEXTUREUNITS];
+ float texturergbscale[MAX_TEXTUREUNITS];
+}
+gl_state;
void GL_SetupTextureState(void)
{
{
for (i = 0;i < backendunits;i++)
{
- qglActiveTexture(GL_TEXTURE0_ARB + (mesh_unit = i));CHECKGLERROR
- qglBindTexture(GL_TEXTURE_2D, mesh_texture[i]);CHECKGLERROR
+ qglActiveTexture(GL_TEXTURE0_ARB + (gl_state.unit = i));CHECKGLERROR
+ qglBindTexture(GL_TEXTURE_2D, gl_state.texture[i]);CHECKGLERROR
if (gl_combine.integer)
{
qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);CHECKGLERROR
qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);CHECKGLERROR
qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);CHECKGLERROR
qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, GL_SRC_ALPHA);CHECKGLERROR
- qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, mesh_texturergbscale[i]);CHECKGLERROR
+ qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, gl_state.texturergbscale[i]);CHECKGLERROR
qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);CHECKGLERROR
}
else
{
qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);CHECKGLERROR
}
- if (mesh_texture[i])
+ if (gl_state.texture[i])
{
qglEnable(GL_TEXTURE_2D);CHECKGLERROR
}
{
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
}
- if (gl_mesh_drawmode.integer != 0)
+ if (gl_mesh_drawmode.integer > 0)
{
- qglClientActiveTexture(GL_TEXTURE0_ARB + (mesh_clientunit = i));CHECKGLERROR
+ qglClientActiveTexture(GL_TEXTURE0_ARB + (gl_state.clientunit = i));CHECKGLERROR
qglTexCoordPointer(2, GL_FLOAT, sizeof(buf_texcoord_t), buf_texcoord[i]);CHECKGLERROR
- if (mesh_texture[i])
+ if (gl_state.texture[i])
{
qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
}
else
{
- qglBindTexture(GL_TEXTURE_2D, mesh_texture[0]);CHECKGLERROR
+ qglBindTexture(GL_TEXTURE_2D, gl_state.texture[0]);CHECKGLERROR
qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);CHECKGLERROR
- if (mesh_texture[0])
+ if (gl_state.texture[0])
{
qglEnable(GL_TEXTURE_2D);CHECKGLERROR
}
{
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
}
- if (gl_mesh_drawmode.integer != 0)
+ if (gl_mesh_drawmode.integer > 0)
{
qglTexCoordPointer(2, GL_FLOAT, sizeof(buf_texcoord_t), buf_texcoord[0]);CHECKGLERROR
- if (mesh_texture[0])
+ if (gl_state.texture[0])
{
qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
// called at beginning of frame
int usedarrays;
-void R_Mesh_Start(void)
+void R_Mesh_Start(float farclip)
{
int i;
if (!backendactive)
currenttransmesh = 0;
currenttranstriangle = 0;
currenttransvertex = 0;
- meshfarclip = 0;
transranout = false;
+ r_mesh_farclip = farclip;
viewdist = DotProduct(r_origin, vpn);
+ vpnbit0 = vpn[0] < 0;
+ vpnbit1 = vpn[1] < 0;
+ vpnbit2 = vpn[2] < 0;
c_meshs = 0;
c_meshtris = 0;
GL_SetupFrame();
- mesh_unit = 0;
- mesh_clientunit = 0;
+ gl_state.unit = 0;
+ gl_state.clientunit = 0;
for (i = 0;i < backendunits;i++)
{
- mesh_texture[i] = 0;
- mesh_texturergbscale[i] = 1;
+ gl_state.texture[i] = 0;
+ gl_state.texturergbscale[i] = 1;
}
qglEnable(GL_CULL_FACE);CHECKGLERROR
qglCullFace(GL_FRONT);CHECKGLERROR
- mesh_depthtest = true;
+ gl_state.depthtest = true;
qglEnable(GL_DEPTH_TEST);CHECKGLERROR
- mesh_blendfunc1 = GL_ONE;
- mesh_blendfunc2 = GL_ZERO;
- qglBlendFunc(mesh_blendfunc1, mesh_blendfunc2);CHECKGLERROR
+ gl_state.blendfunc1 = GL_ONE;
+ gl_state.blendfunc2 = GL_ZERO;
+ qglBlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);CHECKGLERROR
- mesh_blend = 0;
+ gl_state.blend = 0;
qglDisable(GL_BLEND);CHECKGLERROR
- mesh_depthmask = GL_TRUE;
- qglDepthMask(mesh_depthmask);CHECKGLERROR
+ gl_state.depthmask = GL_TRUE;
+ qglDepthMask(gl_state.depthmask);CHECKGLERROR
usedarrays = false;
- if (gl_mesh_drawmode.integer != 0)
+ if (gl_mesh_drawmode.integer > 0)
{
usedarrays = true;
qglVertexPointer(3, GL_FLOAT, sizeof(buf_vertex_t), &buf_vertex[0].v[0]);CHECKGLERROR
int gl_backend_rebindtextures;
-void GL_UpdateFarclip(void)
-{
- int i;
- float farclip;
-
- // push out farclip based on vertices
- // FIXME: wouldn't this be slow when using matrix transforms?
- for (i = 0;i < currentvertex;i++)
- {
- farclip = DotProduct(buf_vertex[i].v, vpn);
- if (meshfarclip < farclip)
- meshfarclip = farclip;
- }
-
- farclip = meshfarclip + 256.0f - viewdist; // + 256 just to be safe
-
- // push out farclip for next frame
- if (farclip > r_newfarclip)
- r_newfarclip = ceil((farclip + 255) / 256) * 256 + 256;
-}
-
void GL_ConvertColorsFloatToByte(void)
{
- int i, k, *icolor;
- float *fcolor;
+ int i, k, total;
+ // LordHavoc: to avoid problems with aliasing (treating memory as two
+ // different types - exactly what this is doing), these must be volatile
+ // (or a union)
+ volatile int *icolor;
+ volatile float *fcolor;
qbyte *bcolor;
+ total = currentvertex * 4;
+
// shift float to have 8bit fraction at base of number
- for (i = 0, fcolor = &buf_fcolor->c[0];i < currentvertex;i++)
+ fcolor = &buf_fcolor->c[0];
+ for (i = 0;i < total;)
{
- *fcolor++ += 32768.0f;
- *fcolor++ += 32768.0f;
- *fcolor++ += 32768.0f;
- *fcolor++ += 32768.0f;
+ fcolor[i ] += 32768.0f;
+ fcolor[i + 1] += 32768.0f;
+ fcolor[i + 2] += 32768.0f;
+ fcolor[i + 3] += 32768.0f;
+ i += 4;
}
+
// then read as integer and kill float bits...
- for (i = 0, icolor = (int *)&buf_fcolor->c[0], bcolor = &buf_bcolor->c[0];i < currentvertex;i++)
+ icolor = (int *)&buf_fcolor->c[0];
+ bcolor = &buf_bcolor->c[0];
+ for (i = 0;i < total;)
{
- k = (*icolor++) & 0x7FFFFF;*bcolor++ = k > 255 ? 255 : k;
- k = (*icolor++) & 0x7FFFFF;*bcolor++ = k > 255 ? 255 : k;
- k = (*icolor++) & 0x7FFFFF;*bcolor++ = k > 255 ? 255 : k;
- k = (*icolor++) & 0x7FFFFF;*bcolor++ = k > 255 ? 255 : k;
+ k = icolor[i ] & 0x7FFFFF;if (k > 255) k = 255;bcolor[i ] = (qbyte) k;
+ k = icolor[i + 1] & 0x7FFFFF;if (k > 255) k = 255;bcolor[i + 1] = (qbyte) k;
+ k = icolor[i + 2] & 0x7FFFFF;if (k > 255) k = 255;bcolor[i + 2] = (qbyte) k;
+ k = icolor[i + 3] & 0x7FFFFF;if (k > 255) k = 255;bcolor[i + 3] = (qbyte) k;
+ i += 4;
}
}
{
for (i = 0;i < backendunits;i++)
{
- if (mesh_texture[i] != mesh->textures[i])
+ if (gl_state.texture[i] != mesh->textures[i])
{
- if (mesh_unit != i)
+ if (gl_state.unit != i)
{
- qglActiveTexture(GL_TEXTURE0_ARB + (mesh_unit = i));CHECKGLERROR
+ qglActiveTexture(GL_TEXTURE0_ARB + (gl_state.unit = i));CHECKGLERROR
}
- if (mesh_texture[i] == 0)
+ if (gl_state.texture[i] == 0)
{
qglEnable(GL_TEXTURE_2D);CHECKGLERROR
// have to disable texcoord array on disabled texture
// units due to NVIDIA driver bug with
// compiled_vertex_array
- if (mesh_clientunit != i)
+ if (gl_state.clientunit != i)
{
- qglClientActiveTexture(GL_TEXTURE0_ARB + (mesh_clientunit = i));CHECKGLERROR
+ qglClientActiveTexture(GL_TEXTURE0_ARB + (gl_state.clientunit = i));CHECKGLERROR
}
qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
- qglBindTexture(GL_TEXTURE_2D, (mesh_texture[i] = mesh->textures[i]));CHECKGLERROR
- if (mesh_texture[i] == 0)
+ qglBindTexture(GL_TEXTURE_2D, (gl_state.texture[i] = mesh->textures[i]));CHECKGLERROR
+ if (gl_state.texture[i] == 0)
{
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
// have to disable texcoord array on disabled texture
// units due to NVIDIA driver bug with
// compiled_vertex_array
- if (mesh_clientunit != i)
+ if (gl_state.clientunit != i)
{
- qglClientActiveTexture(GL_TEXTURE0_ARB + (mesh_clientunit = i));CHECKGLERROR
+ qglClientActiveTexture(GL_TEXTURE0_ARB + (gl_state.clientunit = i));CHECKGLERROR
}
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
}
- if (mesh_texturergbscale[i] != mesh->texturergbscale[i])
+ if (gl_state.texturergbscale[i] != mesh->texturergbscale[i])
{
- if (mesh_unit != i)
+ if (gl_state.unit != i)
{
- qglActiveTexture(GL_TEXTURE0_ARB + (mesh_unit = i));CHECKGLERROR
+ qglActiveTexture(GL_TEXTURE0_ARB + (gl_state.unit = i));CHECKGLERROR
}
- qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (mesh_texturergbscale[i] = mesh->texturergbscale[i]));CHECKGLERROR
+ qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (gl_state.texturergbscale[i] = mesh->texturergbscale[i]));CHECKGLERROR
}
}
}
else
{
- if (mesh_texture[0] != mesh->textures[0])
+ if (gl_state.texture[0] != mesh->textures[0])
{
- if (mesh_texture[0] == 0)
+ if (gl_state.texture[0] == 0)
{
qglEnable(GL_TEXTURE_2D);CHECKGLERROR
qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
- qglBindTexture(GL_TEXTURE_2D, (mesh_texture[0] = mesh->textures[0]));CHECKGLERROR
- if (mesh_texture[0] == 0)
+ qglBindTexture(GL_TEXTURE_2D, (gl_state.texture[0] = mesh->textures[0]));CHECKGLERROR
+ if (gl_state.texture[0] == 0)
{
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
}
}
- if (mesh_blendfunc1 != mesh->blendfunc1 || mesh_blendfunc2 != mesh->blendfunc2)
+ if (gl_state.blendfunc1 != mesh->blendfunc1 || gl_state.blendfunc2 != mesh->blendfunc2)
{
- qglBlendFunc(mesh_blendfunc1 = mesh->blendfunc1, mesh_blendfunc2 = mesh->blendfunc2);CHECKGLERROR
- if (mesh_blendfunc2 == GL_ZERO)
+ qglBlendFunc(gl_state.blendfunc1 = mesh->blendfunc1, gl_state.blendfunc2 = mesh->blendfunc2);CHECKGLERROR
+ if (gl_state.blendfunc2 == GL_ZERO)
{
- if (mesh_blendfunc1 == GL_ONE)
+ if (gl_state.blendfunc1 == GL_ONE)
{
- if (mesh_blend)
+ if (gl_state.blend)
{
- mesh_blend = 0;
+ gl_state.blend = 0;
qglDisable(GL_BLEND);CHECKGLERROR
}
}
else
{
- if (!mesh_blend)
+ if (!gl_state.blend)
{
- mesh_blend = 1;
+ gl_state.blend = 1;
qglEnable(GL_BLEND);CHECKGLERROR
}
}
}
else
{
- if (!mesh_blend)
+ if (!gl_state.blend)
{
- mesh_blend = 1;
+ gl_state.blend = 1;
qglEnable(GL_BLEND);CHECKGLERROR
}
}
}
- if (mesh_depthtest != mesh->depthtest)
+ if (gl_state.depthtest != mesh->depthtest)
{
- mesh_depthtest = mesh->depthtest;
- if (mesh_depthtest)
+ gl_state.depthtest = mesh->depthtest;
+ if (gl_state.depthtest)
qglEnable(GL_DEPTH_TEST);
else
qglDisable(GL_DEPTH_TEST);
}
- if (mesh_depthmask != mesh->depthmask)
+ if (gl_state.depthmask != mesh->depthmask)
{
- qglDepthMask(mesh_depthmask = mesh->depthmask);CHECKGLERROR
+ qglDepthMask(gl_state.depthmask = mesh->depthmask);CHECKGLERROR
}
}
void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *index)
{
unsigned int i, j, in;
- if (gl_mesh_drawmode.integer == 3 && qglDrawRangeElements == NULL)
- Cvar_SetValueQuick(&gl_mesh_drawmode, 2);
-
- if (gl_mesh_drawmode.integer == 3)
+ if (gl_mesh_drawmode.integer >= 3/* && (endvert - firstvert) <= gl_maxdrawrangeelementsvertices && (indexcount) <= gl_maxdrawrangeelementsindices*/)
{
// GL 1.2 or GL 1.1 with extension
qglDrawRangeElements(GL_TRIANGLES, firstvert, endvert, indexcount, GL_UNSIGNED_INT, index);
}
- else if (gl_mesh_drawmode.integer == 2)
+ else if (gl_mesh_drawmode.integer >= 2)
{
// GL 1.1
qglDrawElements(GL_TRIANGLES, indexcount, GL_UNSIGNED_INT, index);
}
- else if (gl_mesh_drawmode.integer == 1)
+ else if (gl_mesh_drawmode.integer >= 1)
{
// GL 1.1
// feed it manually using glArrayElement
{
// GL 1.1 but not using vertex arrays - 3dfx glquake minigl driver
// feed it manually
- if (gl_mesh_drawmode.integer != 0)
- Cvar_SetValueQuick(&gl_mesh_drawmode, 0);
qglBegin(GL_TRIANGLES);
- if (r_multitexture.integer)
+ if (gl_state.texture[1]) // if the mesh uses multiple textures
{
// the minigl doesn't have this (because it does not have ARB_multitexture)
for (i = 0;i < indexcount;i++)
in = index[i];
qglColor4ub(buf_bcolor[in].c[0], buf_bcolor[in].c[1], buf_bcolor[in].c[2], buf_bcolor[in].c[3]);
for (j = 0;j < backendunits;j++)
- if (mesh_texture[j])
+ if (gl_state.texture[j])
qglMultiTexCoord2f(GL_TEXTURE0_ARB + j, buf_texcoord[j][in].t[0], buf_texcoord[j][in].t[1]);
qglVertex3f(buf_vertex[in].v[0], buf_vertex[in].v[1], buf_vertex[in].v[2]);
}
{
in = index[i];
qglColor4ub(buf_bcolor[in].c[0], buf_bcolor[in].c[1], buf_bcolor[in].c[2], buf_bcolor[in].c[3]);
- if (mesh_texture[0])
+ if (gl_state.texture[0])
qglTexCoord2f(buf_texcoord[0][in].t[0], buf_texcoord[0][in].t[1]);
qglVertex3f(buf_vertex[in].v[0], buf_vertex[in].v[1], buf_vertex[in].v[2]);
}
}
qglEnd();
}
- /*
- if (qglDrawRangeElements)
- qglDrawRangeElements(GL_TRIANGLES, firstvert, endvert, indexcount, index);
- else
- {
- }
- #ifdef WIN32
- // FIXME: dynamic link to GL so we can get DrawRangeElements on WIN32
- qglDrawElements(GL_TRIANGLES, indexcount, GL_UNSIGNED_INT, index);CHECKGLERROR
- #else
- qglDrawRangeElements(GL_TRIANGLES, firstvert, firstvert + mesh->verts, indexcount, GL_UNSIGNED_INT, index);CHECKGLERROR
- #endif
- */
}
// renders mesh buffers, called to flush buffers when full
void R_Mesh_Render(void)
{
- int i;
int k;
- int indexcount;
- int firstvert;
buf_mesh_t *mesh;
- unsigned int *index;
if (!backendactive)
Sys_Error("R_Mesh_Render: called when backend is not active\n");
if (!currentmesh)
return;
- CHECKGLERROR
+ if (!r_render.integer)
+ {
+ currentmesh = 0;
+ currenttriangle = 0;
+ currentvertex = 0;
+ return;
+ }
- GL_UpdateFarclip();
+ CHECKGLERROR
- if (!gl_mesh_floatcolors.integer || gl_mesh_drawmode.integer == 0)
+ // drawmode 0 always uses byte colors
+ if (!gl_mesh_floatcolors.integer || gl_mesh_drawmode.integer <= 0)
GL_ConvertColorsFloatToByte();
- // lock the arrays now that they will have no further modifications
- //GL_LockArray(0, currentvertex);CHECKGLERROR
if (gl_backend_rebindtextures)
{
gl_backend_rebindtextures = false;
for (k = 1, mesh = buf_mesh + k;k < currentmesh;k++, mesh++)
{
GL_MeshState(mesh);
-
- firstvert = mesh->firstvert;
- indexcount = mesh->triangles * 3;
- index = (unsigned int *)&buf_tri[mesh->firsttriangle].index[0];
-
- // if not using batching, skip the index adjustment
- if (firstvert != 0)
- for (i = 0;i < indexcount;i++)
- index[i] += firstvert;
-
- GL_DrawRangeElements(firstvert, firstvert + mesh->verts, indexcount, index);CHECKGLERROR
+ GL_DrawRangeElements(mesh->firstvert, mesh->firstvert + mesh->verts, mesh->triangles * 3, buf_tri[mesh->firsttriangle].index);CHECKGLERROR
}
}
{
int i;
// flush any queued meshs
- R_Mesh_Render();
+ if (currentmesh)
+ R_Mesh_Render();
if (backendunits > 1)
{
void R_Mesh_ClearDepth(void)
{
- R_Mesh_AddTransparent();
+ if (currenttransmesh)
+ R_Mesh_AddTransparent();
+ if (currentmesh)
+ R_Mesh_Render();
R_Mesh_Finish();
qglClear(GL_DEPTH_BUFFER_BIT);
- R_Mesh_Start();
+ R_Mesh_Start(r_mesh_farclip);
}
void R_Mesh_AddTransparent(void)
}
// map farclip to 0-4095 list range
- centerscaler = (TRANSDEPTHRES / r_farclip) * (1.0f / 3.0f);
+ centerscaler = (TRANSDEPTHRES / r_mesh_farclip) * (1.0f / 3.0f);
viewdistcompare = viewdist + 4.0f;
memset(buf_sorttranstri_list, 0, TRANSDEPTHRES * sizeof(buf_transtri_t *));
}
}
+ R_Mesh_Render();
for (;transmesh;transmesh = transmesh->chain)
{
- if (currentmesh >= max_meshs || currenttriangle + transmesh->triangles > max_batch || currenttriangle + transmesh->triangles > 1024 || currentvertex + transmesh->verts > max_verts)
- R_Mesh_Render();
-
mesh = &buf_mesh[currentmesh++];
*mesh = *transmesh; // copy mesh properties
currenttriangle++;
}
mesh->triangles = currenttriangle - mesh->firsttriangle;
+ R_Mesh_Render();
}
currenttransmesh = 0;
currenttransvertex = 0;
}
-void R_Mesh_Draw(const rmeshinfo_t *m)
-{
- // these are static because gcc runs out of virtual registers otherwise
- static int i, j, overbright, *index;
- static float *in, scaler;
- static float cr, cg, cb, ca;
- static buf_mesh_t *mesh;
- static buf_vertex_t *vert;
- static buf_fcolor_t *fcolor;
- static buf_texcoord_t *texcoord[MAX_TEXTUREUNITS];
-
- if (!backendactive)
- Sys_Error("R_Mesh_Draw: called when backend is not active\n");
-
- if (m->index == NULL
- || !m->numtriangles
- || m->vertex == NULL
- || !m->numverts)
- Host_Error("R_Mesh_Draw: no triangles or verts\n");
-
- // ignore meaningless alpha meshs
- if (!m->depthwrite && m->blendfunc1 == GL_SRC_ALPHA && (m->blendfunc2 == GL_ONE || m->blendfunc2 == GL_ONE_MINUS_SRC_ALPHA))
- {
- if (m->color)
- {
- for (i = 0, in = m->color + 3;i < m->numverts;i++, (int)in += m->colorstep)
- if (*in >= 0.01f)
- break;
- if (i == m->numverts)
- return;
- }
- else if (m->ca < 0.01f)
- return;
- }
-
- if (!backendactive)
- Sys_Error("R_Mesh_Draw: called when backend is not active\n");
-
-#ifdef DEBUGGL
- for (i = 0;i < m->numtriangles * 3;i++)
- if ((unsigned int) m->index[i] >= (unsigned int) m->numverts)
- Host_Error("R_Mesh_Draw: invalid index (%i of %i verts)\n", m->index, m->numverts);
-#endif
-
- // FIXME: we can work around this by falling back on non-array renderer if buffers are too big
- if (m->numtriangles > 1024 || m->numverts > 3072)
- {
- Con_Printf("R_Mesh_Draw: mesh too big for 3DFX drivers, rejected\n");
- return;
- }
-
- if (m->numtriangles > max_meshs || m->numverts > max_verts)
- {
- Con_Printf("R_Mesh_Draw: mesh too big for current gl_mesh_maxtriangles setting, rejected\n");
- return;
- }
-
-
- if (m->transparent)
- {
- if (currenttransmesh >= max_transmeshs || (currenttranstriangle + m->numtriangles) > max_transmeshs || (currenttransvertex + m->numverts) > max_transverts)
- {
- if (!transranout)
- {
- Con_Printf("R_Mesh_Draw: ran out of room for transparent meshs\n");
- transranout = true;
- }
- return;
- }
-
- c_transmeshs++;
- c_transtris += m->numtriangles;
- vert = &buf_transvertex[currenttransvertex];
- fcolor = &buf_transfcolor[currenttransvertex];
- for (i = 0;i < backendunits;i++)
- texcoord[i] = &buf_transtexcoord[i][currenttransvertex];
-
- // transmesh is only for storage of transparent meshs until they
- // are inserted into the main mesh array
- mesh = &buf_transmesh[currenttransmesh++];
- mesh->firsttriangle = currenttranstriangle;
- mesh->firstvert = currenttransvertex;
- index = &buf_transtri[currenttranstriangle].index[0];
-
- currenttranstriangle += m->numtriangles;
- currenttransvertex += m->numverts;
- }
- else
- {
- if (currentmesh >= max_meshs || (currenttriangle + m->numtriangles) > max_batch || (currentvertex + m->numverts) > max_verts)
- R_Mesh_Render();
-
- c_meshs++;
- c_meshtris += m->numtriangles;
- vert = &buf_vertex[currentvertex];
- fcolor = &buf_fcolor[currentvertex];
- for (i = 0;i < backendunits;i++)
- texcoord[i] = &buf_texcoord[i][currentvertex];
-
- // opaque meshs are rendered directly
- mesh = &buf_mesh[currentmesh++];
- mesh->firsttriangle = currenttriangle;
- mesh->firstvert = currentvertex;
- index = &buf_tri[currenttriangle].index[0];
-
- currenttriangle += m->numtriangles;
- currentvertex += m->numverts;
- }
-
- // code shared for transparent and opaque meshs
- memcpy(index, m->index, sizeof(int[3]) * m->numtriangles);
- mesh->blendfunc1 = m->blendfunc1;
- mesh->blendfunc2 = m->blendfunc2;
- mesh->depthmask = (m->blendfunc2 == GL_ZERO || m->depthwrite);
- mesh->depthtest = !m->depthdisable;
- mesh->triangles = m->numtriangles;
- mesh->verts = m->numverts;
-
- overbright = false;
- scaler = 1;
- if (m->blendfunc2 == GL_SRC_COLOR)
- {
- if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
- scaler *= 0.5f;
- }
- else
- {
- if (m->tex[0])
- {
- overbright = gl_combine.integer;
- if (overbright)
- scaler *= 0.25f;
- }
- scaler *= overbrightscale;
- }
-
-
- j = -1;
- for (i = 0;i < backendunits;i++)
- {
- if ((mesh->textures[i] = m->tex[i]))
- j = i;
- mesh->texturergbscale[i] = m->texrgbscale[i];
- if (mesh->texturergbscale[i] != 1 && mesh->texturergbscale[i] != 2 && mesh->texturergbscale[i] != 4)
- mesh->texturergbscale[i] = 1;
- }
- if (overbright && j >= 0)
- mesh->texturergbscale[j] = 4;
-
- if (m->vertexstep != sizeof(buf_vertex_t))
- {
- for (i = 0, in = m->vertex;i < m->numverts;i++, (int)in += m->vertexstep)
- {
- vert[i].v[0] = in[0];
- vert[i].v[1] = in[1];
- vert[i].v[2] = in[2];
- }
- }
- else
- memcpy(vert, m->vertex, m->numverts * sizeof(buf_vertex_t));
-
- if (m->color)
- {
- for (i = 0, in = m->color;i < m->numverts;i++, (int)in += m->colorstep)
- {
- fcolor[i].c[0] = in[0] * scaler;
- fcolor[i].c[1] = in[1] * scaler;
- fcolor[i].c[2] = in[2] * scaler;
- fcolor[i].c[3] = in[3];
- }
- }
- else
- {
- cr = m->cr * scaler;
- cg = m->cg * scaler;
- cb = m->cb * scaler;
- ca = m->ca;
- for (i = 0;i < m->numverts;i++)
- {
- fcolor[i].c[0] = cr;
- fcolor[i].c[1] = cg;
- fcolor[i].c[2] = cb;
- fcolor[i].c[3] = ca;
- }
- }
-
- for (j = 0;j < MAX_TEXTUREUNITS && m->tex[j];j++)
- {
- if (j >= backendunits)
- Sys_Error("R_Mesh_Draw: texture %i supplied when there are only %i texture units\n", j + 1, backendunits);
- if (m->texcoordstep[j] != sizeof(buf_texcoord_t))
- {
- for (i = 0, in = m->texcoords[j];i < m->numverts;i++, (int)in += m->texcoordstep[j])
- {
- texcoord[j][i].t[0] = in[0];
- texcoord[j][i].t[1] = in[1];
- }
- }
- else
- memcpy(&texcoord[j][0].t[0], m->texcoords[j], m->numverts * sizeof(buf_texcoord_t));
- }
- #if 0
- for (;j < backendunits;j++)
- memset(&texcoord[j][0].t[0], 0, m->numverts * sizeof(buf_texcoord_t));
- #endif
-}
-
-void R_Mesh_Draw_NativeOnly(const rmeshinfo_t *m)
-{
- // these are static because gcc runs out of virtual registers otherwise
- static int i, j, overbright, *index;
- static float *in, scaler;
- static buf_mesh_t *mesh;
- static buf_vertex_t *vert;
- static buf_fcolor_t *fcolor;
- static buf_texcoord_t *texcoord[MAX_TEXTUREUNITS];
-
- if (!backendactive)
- Sys_Error("R_Mesh_Draw: called when backend is not active\n");
-
- if (m->index == NULL
- || !m->numtriangles
- || m->vertex == NULL
- || !m->numverts)
- Host_Error("R_Mesh_Draw: no triangles or verts\n");
-
- // ignore meaningless alpha meshs
- if (!m->depthwrite && m->blendfunc1 == GL_SRC_ALPHA && (m->blendfunc2 == GL_ONE || m->blendfunc2 == GL_ONE_MINUS_SRC_ALPHA))
- {
- if (m->color)
- {
- for (i = 0, in = m->color + 3;i < m->numverts;i++, (int)in += m->colorstep)
- if (*in >= 0.01f)
- break;
- if (i == m->numverts)
- return;
- }
- else if (m->ca < 0.01f)
- return;
- }
-
- // FIXME: we can work around this by falling back on non-array renderer if buffers are too big
- if (m->numtriangles > 1024 || m->numverts > 3072)
- {
- Con_Printf("R_Mesh_Draw_NativeOnly: mesh too big for 3DFX drivers, rejected\n");
- return;
- }
-
- if (m->numtriangles > max_meshs || m->numverts > max_verts)
- {
- Con_Printf("R_Mesh_Draw_NativeOnly: mesh too big for current gl_mesh_maxtriangles setting, rejected\n");
- return;
- }
-
-
- if (m->transparent)
- {
- if (currenttransmesh >= max_transmeshs || (currenttranstriangle + m->numtriangles) > max_transmeshs || (currenttransvertex + m->numverts) > max_transverts)
- {
- if (!transranout)
- {
- Con_Printf("R_Mesh_Draw_NativeOnly: ran out of room for transparent meshs\n");
- transranout = true;
- }
- return;
- }
-
- c_transmeshs++;
- c_transtris += m->numtriangles;
- vert = &buf_transvertex[currenttransvertex];
- fcolor = &buf_transfcolor[currenttransvertex];
- for (i = 0;i < backendunits;i++)
- texcoord[i] = &buf_transtexcoord[i][currenttransvertex];
-
- // transmesh is only for storage of transparent meshs until they
- // are inserted into the main mesh array
- mesh = &buf_transmesh[currenttransmesh++];
- mesh->firsttriangle = currenttranstriangle;
- mesh->firstvert = currenttransvertex;
- index = &buf_transtri[currenttranstriangle].index[0];
- currenttranstriangle += m->numtriangles;
- currenttransvertex += m->numverts;
- }
- else
- {
- if (currentmesh >= max_meshs || (currenttriangle + m->numtriangles) > max_batch || (currentvertex + m->numverts) > max_verts)
- R_Mesh_Render();
-
- c_meshs++;
- c_meshtris += m->numtriangles;
- vert = &buf_vertex[currentvertex];
- fcolor = &buf_fcolor[currentvertex];
- for (i = 0;i < backendunits;i++)
- texcoord[i] = &buf_texcoord[i][currentvertex];
-
- // opaque meshs are rendered directly
- mesh = &buf_mesh[currentmesh++];
- mesh->firsttriangle = currenttriangle;
- mesh->firstvert = currentvertex;
- index = &buf_tri[currenttriangle].index[0];
- currenttriangle += m->numtriangles;
- currentvertex += m->numverts;
- }
-
- // code shared for transparent and opaque meshs
- memcpy(index, m->index, sizeof(int[3]) * m->numtriangles);
- mesh->blendfunc1 = m->blendfunc1;
- mesh->blendfunc2 = m->blendfunc2;
- mesh->depthmask = (m->blendfunc2 == GL_ZERO || m->depthwrite);
- mesh->depthtest = !m->depthdisable;
- mesh->triangles = m->numtriangles;
- mesh->verts = m->numverts;
-
- overbright = false;
- scaler = 1;
- if (m->blendfunc2 == GL_SRC_COLOR)
- {
- if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
- scaler *= 0.5f;
- }
- else
- {
- if (m->tex[0])
- {
- overbright = gl_combine.integer;
- if (overbright)
- scaler *= 0.25f;
- }
- scaler *= overbrightscale;
- }
-
- j = -1;
- for (i = 0;i < backendunits;i++)
- {
- if ((mesh->textures[i] = m->tex[i]))
- j = i;
- mesh->texturergbscale[i] = m->texrgbscale[i];
- if (mesh->texturergbscale[i] != 1 && mesh->texturergbscale[i] != 2 && mesh->texturergbscale[i] != 4)
- mesh->texturergbscale[i] = 1;
- }
- if (overbright && j >= 0)
- mesh->texturergbscale[j] = 4;
-
- if (m->vertexstep != sizeof(buf_vertex_t))
- Host_Error("R_Mesh_Draw_NativeOnly: unsupported vertexstep\n");
- if (m->colorstep != sizeof(buf_fcolor_t))
- Host_Error("R_Mesh_Draw_NativeOnly: unsupported colorstep\n");
- if (m->color == NULL)
- Host_Error("R_Mesh_Draw_NativeOnly: must provide color array\n");
- for (j = 0;j < MAX_TEXTUREUNITS && m->tex[j];j++)
- {
- if (j >= backendunits)
- Sys_Error("R_Mesh_Draw_NativeOnly: texture %i supplied when there are only %i texture units\n", j + 1, backendunits);
- if (m->texcoordstep[j] != sizeof(buf_texcoord_t))
- Host_Error("R_Mesh_Draw_NativeOnly: unsupported texcoordstep\n");
- }
-
- memcpy(vert, m->vertex, m->numverts * sizeof(buf_vertex_t));
- for (j = 0;j < MAX_TEXTUREUNITS && m->tex[j];j++)
- memcpy(&texcoord[j][0].t[0], m->texcoords[j], m->numverts * sizeof(buf_texcoord_t));
- #if 0
- for (;j < backendunits;j++)
- memset(&texcoord[j][0].t[0], 0, m->numverts * sizeof(buf_texcoord_t));
- #endif
-
- memcpy(fcolor, m->color, m->numverts * sizeof(buf_fcolor_t));
-
- // do this as a second step because memcpy preloaded the cache, which we can't easily do
- if (scaler != 1)
- {
- for (i = 0;i < m->numverts;i++)
- {
- fcolor[i].c[0] *= scaler;
- fcolor[i].c[1] *= scaler;
- fcolor[i].c[2] *= scaler;
- }
- }
-}
-
// allocates space in geometry buffers, and fills in pointers to the buffers in passsed struct
// (this is used for very high speed rendering, no copying)
-int R_Mesh_Draw_GetBuffer(rmeshbufferinfo_t *m)
+int R_Mesh_Draw_GetBuffer(rmeshbufferinfo_t *m, int wantoverbright)
{
// these are static because gcc runs out of virtual registers otherwise
int i, j, overbright;
buf_mesh_t *mesh;
if (!backendactive)
- Sys_Error("R_Mesh_Draw: called when backend is not active\n");
+ Sys_Error("R_Mesh_Draw_GetBuffer: called when backend is not active\n");
if (!m->numtriangles
|| !m->numverts)
- Host_Error("R_Mesh_Draw: no triangles or verts\n");
+ Host_Error("R_Mesh_Draw_GetBuffer: no triangles or verts\n");
+ // LordHavoc: removed this error condition because with floatcolors 0,
+ // the 3DFX driver works with very large meshs
// FIXME: we can work around this by falling back on non-array renderer if buffers are too big
- if (m->numtriangles > 1024 || m->numverts > 3072)
- {
- Con_Printf("R_Mesh_Draw_GetBuffer: mesh too big for 3DFX drivers, rejected\n");
- return false;
- }
+ //if (m->numtriangles > 1024 || m->numverts > 3072)
+ //{
+ // Con_Printf("R_Mesh_Draw_GetBuffer: mesh too big for 3DFX drivers, rejected\n");
+ // return false;
+ //}
+
+ i = max(m->numtriangles * 3, m->numverts);
+ if (overflowedverts < i)
+ overflowedverts = i;
if (m->numtriangles > max_meshs || m->numverts > max_verts)
{
- Con_Printf("R_Mesh_Draw_GetBuffer: mesh too big for current gl_mesh_maxtriangles setting, rejected\n");
+ Con_Printf("R_Mesh_Draw_GetBuffer: mesh too big for current gl_mesh_maxtriangles setting, increasing limits\n");
return false;
}
-
if (m->transparent)
{
+ overflowedtransverts += max(m->numtriangles * 3, m->numverts);
if (currenttransmesh >= max_transmeshs || (currenttranstriangle + m->numtriangles) > max_transmeshs || (currenttransvertex + m->numverts) > max_transverts)
{
if (!transranout)
{
- Con_Printf("R_Mesh_Draw: ran out of room for transparent meshs\n");
+ Con_Printf("R_Mesh_Draw_GetBuffer: ran out of room for transparent meshs\n");
transranout = true;
}
return false;
}
else
{
- if (currentmesh >= max_meshs || (currenttriangle + m->numtriangles) > max_batch || (currentvertex + m->numverts) > max_verts)
+ if (currentmesh)
+ {
R_Mesh_Render();
+ Con_Printf("mesh queue not empty, flushing.\n");
+ }
c_meshs++;
c_meshtris += m->numtriangles;
overbright = false;
scaler = 1;
- if (m->blendfunc2 == GL_SRC_COLOR)
+ if (m->blendfunc1 == GL_DST_COLOR)
{
- if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
+ // check if it is a 2x modulate with framebuffer
+ if (m->blendfunc2 == GL_SRC_COLOR)
scaler *= 0.5f;
}
- else
+ else if (m->blendfunc2 != GL_SRC_COLOR)
{
if (m->tex[0])
{
- overbright = gl_combine.integer;
+ overbright = wantoverbright && gl_combine.integer;
if (overbright)
scaler *= 0.25f;
}
return true;
}
-void R_Mesh_DrawPolygon(rmeshinfo_t *m, int numverts)
-{
- m->index = polyindexarray;
- m->numverts = numverts;
- m->numtriangles = numverts - 2;
- if (m->numtriangles < 1)
- {
- Con_Printf("R_Mesh_DrawPolygon: invalid vertex count\n");
- return;
- }
- if (m->numtriangles >= 256)
- {
- Con_Printf("R_Mesh_DrawPolygon: only up to 256 triangles (258 verts) supported\n");
- return;
- }
- R_Mesh_Draw(m);
-}
-
/*
==============================================================================
*/
void SCR_UpdateScreen (void)
{
- //Mem_CheckSentinelsGlobal();
- //R_TimeReport("memtest");
-
VID_Finish ();
R_TimeReport("finish");
- if (gl_combine.integer && !gl_combine_extension)
- Cvar_SetValue("gl_combine", 0);
+ if (r_textureunits.integer > gl_textureunits)
+ Cvar_SetValueQuick(&r_textureunits, gl_textureunits);
+ if (r_textureunits.integer < 1)
+ Cvar_SetValueQuick(&r_textureunits, 1);
+
+ if (gl_combine.integer && (!gl_combine_extension || r_textureunits.integer < 2))
+ Cvar_SetValueQuick(&gl_combine, 0);
+ // lighting scale
+ overbrightscale = 1.0f / (float) (1 << v_overbrightbits.integer);
+
+ // lightmaps only
lightscalebit = v_overbrightbits.integer;
- if (gl_combine.integer && r_multitexture.integer)
+ if (gl_combine.integer && r_textureunits.integer > 1)
lightscalebit += 2;
-
lightscale = 1.0f / (float) (1 << lightscalebit);
- overbrightscale = 1.0f / (float) (1 << v_overbrightbits.integer);
R_TimeReport("setup");
// (this doesn't wait for the commands themselves to complete)
qglFlush();
}
+