// this is used to increase gl_mesh_maxtriangles automatically if a mesh was
// too large for the buffers in the previous frame
-int overflowedmeshtris = 0;
+int overflowedverts = 0;
+// increase transtriangles automatically too
+int overflowedtransverts = 0;
int gl_maxdrawrangeelementsvertices;
int gl_maxdrawrangeelementsindices;
{
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", 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("\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 (overflowedmeshtris > gl_mesh_maxtriangles.integer)
- Cvar_SetValueQuick(&gl_mesh_maxtriangles, overflowedmeshtris);
- overflowedmeshtris = 0;
+ 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)
+ if (gl_mesh_drawmode.integer >= 3 && qglDrawRangeElements == NULL)
{
- if (qglDrawRangeElements != NULL && gl_maxdrawrangeelementsindices >= 3072 && gl_maxdrawrangeelementsvertices >= 3072)
- {
- // make sure we don't exceed the DrawRangeElements limits
- if (gl_mesh_maxtriangles.integer * 3 > gl_maxdrawrangeelementsindices)
- Cvar_SetValueQuick(&gl_mesh_maxtriangles, (int) (gl_maxdrawrangeelementsindices / 3));
- if (gl_mesh_maxtriangles.integer * 3 > gl_maxdrawrangeelementsvertices)
- Cvar_SetValueQuick(&gl_mesh_maxtriangles, (int) (gl_maxdrawrangeelementsvertices / 3));
- }
- else
- {
- // change drawmode 3 to 2 if 3 won't work
- Cvar_SetValueQuick(&gl_mesh_drawmode, 2);
- }
+ // 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
void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *index)
{
unsigned int i, j, in;
- 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);
// return;
//}
+ 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: mesh too big for current gl_mesh_maxtriangles setting, increasing limits\n");
- if (m->numtriangles > overflowedmeshtris)
- overflowedmeshtris = m->numtriangles;
- if (((m->numverts + 2) / 3) > overflowedmeshtris)
- overflowedmeshtris = (m->numverts + 2) / 3;
return;
}
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)
// return;
//}
+ 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_NativeOnly: mesh too big for current gl_mesh_maxtriangles setting, increasing limits\n");
- if (m->numtriangles > overflowedmeshtris)
- overflowedmeshtris = m->numtriangles;
- if (((m->numverts + 2) / 3) > overflowedmeshtris)
- overflowedmeshtris = (m->numverts + 2) / 3;
return;
}
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)
// 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, increasing limits\n");
- if (m->numtriangles > overflowedmeshtris)
- overflowedmeshtris = m->numtriangles;
- if (((m->numverts + 2) / 3) > overflowedmeshtris)
- overflowedmeshtris = (m->numverts + 2) / 3;
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)
}
extern cvar_t gl_mesh_drawmode;
+extern int gl_maxdrawrangeelementsvertices;
+extern int gl_maxdrawrangeelementsindices;
+
void R_DrawQueue(void)
{
int pos, num, chartexnum, overbright;
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 || gl_maxdrawrangeelementsindices < 3072 || gl_maxdrawrangeelementsvertices < 3072))
+ if (gl_mesh_drawmode.integer >= 3 && qglDrawRangeElements == NULL)
Cvar_SetValueQuick(&gl_mesh_drawmode, 2);
if (gl_mesh_drawmode.integer > 0)
qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR
}
- if (gl_mesh_drawmode.integer >= 3)
+ if (gl_mesh_drawmode.integer >= 3/* && (mesh->numvertices) <= gl_maxdrawrangeelementsvertices && (mesh->numindices) <= gl_maxdrawrangeelementsindices*/)
{
// GL 1.2 or GL 1.1 with extension
GL_LockArray(0, mesh->numvertices);
// LordHavoc: GL_EXT_compiled_vertex_array support
int gl_supportslockarrays = false;
-int gl_maxdrawrangeelementsvertices;
-int gl_maxdrawrangeelementsindices;
-
cvar_t vid_mode = {0, "vid_mode", "0"};
cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
cvar_t vid_fullscreen = {0, "vid_fullscreen", "1"};
if (!gl_checkextension("OpenGL 1.1.0", opengl110funcs, NULL, false))
Sys_Error("OpenGL 1.1.0 functions not found\n");
- if (gl_checkextension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true)
- || gl_checkextension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", true))
- {
- qglGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &gl_maxdrawrangeelementsvertices);
- qglGetIntegerv(GL_MAX_ELEMENTS_INDICES, &gl_maxdrawrangeelementsindices);
-
- if (gl_maxdrawrangeelementsvertices < 1 || gl_maxdrawrangeelementsindices < 1)
- {
- Con_Printf("invalid GL_MAX_ELEMENTS_VERTICES (%i) and/or GL_MAX_ELEMENTS_INDICES (%i)\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
- qglDrawRangeElements = qglDrawRangeElementsEXT = NULL;
- }
- }
+ if (!gl_checkextension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
+ gl_checkextension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", true);
if (gl_checkextension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
{