cvar_t gl_mesh_maxtriangles = {0, "gl_mesh_maxtriangles", "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"};
}
#endif
-float r_farclip, r_newfarclip;
+float r_mesh_farclip;
int polyindexarray[768];
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);
}
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;
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", gl_mesh_maxtriangles.integer, gl_mesh_transtriangles.integer);
+ 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(", with glDrawRangeElements (max vertices %i, max indices %i)\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
+ 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;
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 < 1)
+ Cvar_SetValueQuick(&gl_mesh_batchtriangles, 1);
if (gl_mesh_batchtriangles.integer > gl_mesh_maxtriangles.integer)
Cvar_SetValueQuick(&gl_mesh_batchtriangles, gl_mesh_maxtriangles.integer);
static void gl_backend_newmap(void)
{
- r_farclip = r_newfarclip = 2048.0f;
}
void gl_backend_init(void)
double xmax, ymax;
double fovx, fovy, zNear, zFar, aspect;
- // update farclip based on previous frame
- r_farclip = r_newfarclip;
-
if (!r_render.integer)
return;
// depth range
zNear = 1.0;
- zFar = r_farclip;
+ zFar = r_mesh_farclip;
// fov angles
fovx = r_refdef.fov_x;
// 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;
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, total;
// GL 1.1 but not using vertex arrays - 3dfx glquake minigl driver
// feed it manually
qglBegin(GL_TRIANGLES);
- if (r_multitexture.integer)
+ if (mesh_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++)
CHECKGLERROR
- GL_UpdateFarclip();
-
// drawmode 0 always uses byte colors
if (!gl_mesh_floatcolors.integer || gl_mesh_drawmode.integer <= 0)
GL_ConvertColorsFloatToByte();
{
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 *));
// 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;
{
if (m->tex[0])
{
- overbright = gl_combine.integer;
+ overbright = wantoverbright && gl_combine.integer;
if (overbright)
scaler *= 0.25f;
}
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");