Prevent bad gl_max_size settings from causing buggy drivers to freak out.

This commit is contained in:
Ragnvald Maartmann-Moe IV 2003-03-24 20:21:24 +00:00
parent eb5f2137b4
commit 6c7701a38b
3 changed files with 67 additions and 39 deletions

View File

@ -129,8 +129,12 @@ Draw_InitText (void)
if (r_init) { if (r_init) {
if (vaelements > 3) if (vaelements > 3)
tVAsize = vaelements - (vaelements % 4); tVAsize = vaelements - (vaelements % 4);
else else if (vaelements >= 0)
tVAsize = 2048; tVAsize = 2048;
else
tVAsize = 0;
if (tVAsize) {
Con_Printf ("Text: %i maximum vertex elements.\n", tVAsize); Con_Printf ("Text: %i maximum vertex elements.\n", tVAsize);
if (textVertices) if (textVertices)
@ -148,6 +152,9 @@ Draw_InitText (void)
tVAindices = (int *) calloc (tVAsize, sizeof (int)); tVAindices = (int *) calloc (tVAsize, sizeof (int));
for (i = 0; i < tVAsize; i++) for (i = 0; i < tVAsize; i++)
tVAindices[i] = i; tVAindices[i] = i;
} else {
Con_Printf ("Text: Vertex Array use disabled.\n");
}
} else { } else {
if (textVertices) { if (textVertices) {
free (textVertices); free (textVertices);
@ -332,11 +339,6 @@ void
Draw_Init (void) Draw_Init (void)
{ {
int i; int i;
GLint texSize;
// Some cards have a texture size limit.
qfglGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
Cvar_Set (gl_max_size, va("%d", texSize));
Cmd_AddCommand ("gl_texturemode", &GL_TextureMode_f, Cmd_AddCommand ("gl_texturemode", &GL_TextureMode_f,
"Texture mipmap quality."); "Texture mipmap quality.");
@ -381,13 +383,21 @@ flush_text (void)
} }
static inline void static inline void
queue_character (int x, int y, int num) queue_character (float x, float y, int num)
{ {
float frow, fcol; float frow, fcol;
frow = (num >> 4) * CELL_SIZE; frow = (num >> 4) * CELL_SIZE;
fcol = (num & 15) * CELL_SIZE; fcol = (num & 15) * CELL_SIZE;
*tV++ = x;
*tV++ = y;
*tV++ = x + 8.0;
*tV++ = y;
*tV++ = x + 8.0;
*tV++ = y + 8.0;
*tV++ = x;
*tV++ = y + 8.0;
*tC++ = fcol; *tC++ = fcol;
*tC++ = frow; *tC++ = frow;
*tC++ = fcol + CELL_SIZE; *tC++ = fcol + CELL_SIZE;
@ -396,14 +406,6 @@ queue_character (int x, int y, int num)
*tC++ = frow + CELL_SIZE; *tC++ = frow + CELL_SIZE;
*tC++ = fcol; *tC++ = fcol;
*tC++ = frow + CELL_SIZE; *tC++ = frow + CELL_SIZE;
*tV++ = x;
*tV++ = y;
*tV++ = x + 8;
*tV++ = y;
*tV++ = x + 8;
*tV++ = y + 8;
*tV++ = x;
*tV++ = y + 8;
} }
static inline void static inline void
@ -431,7 +433,7 @@ Draw_Character (int x, int y, unsigned int num)
num &= 255; num &= 255;
queue_character (x, y, num); queue_character ((float) x, (float) y, num);
tVA_increment (); tVA_increment ();
} }
@ -439,18 +441,22 @@ void
Draw_String (int x, int y, const char *str) Draw_String (int x, int y, const char *str)
{ {
unsigned char num; unsigned char num;
float x1, y1;
if (!str || !str[0]) if (!str || !str[0])
return; return;
if (y <= -8) if (y <= -8)
return; // totally off screen return; // totally off screen
x1 = (float) x;
y1 = (float) y;
while (*str) { while (*str) {
if ((num = *str++) != 32) { // Don't render spaces if ((num = *str++) != 32) { // Don't render spaces
queue_character (x, y, num); queue_character (x1, y1, num);
tVA_increment (); tVA_increment ();
} }
x += 8; x1 += 8.0;
} }
} }
@ -458,18 +464,22 @@ void
Draw_nString (int x, int y, const char *str, int count) Draw_nString (int x, int y, const char *str, int count)
{ {
unsigned char num; unsigned char num;
float x1, y1;
if (!str || !str[0]) if (!str || !str[0])
return; return;
if (y <= -8) if (y <= -8)
return; // totally off screen return; // totally off screen
x1 = (float) x;
y1 = (float) y;
while (count-- && *str) { while (count-- && *str) {
if ((num = *str++) != 32) { // Don't render spaces if ((num = *str++) != 32) { // Don't render spaces
queue_character (x, y, num); queue_character (x1, y1, num);
tVA_increment (); tVA_increment ();
} }
x += 8; x1 += 8.0;
} }
} }
@ -477,19 +487,23 @@ void
Draw_AltString (int x, int y, const char *str) Draw_AltString (int x, int y, const char *str)
{ {
unsigned char num; unsigned char num;
float x1, y1;
if (!str || !str[0]) if (!str || !str[0])
return; return;
if (y <= -8) if (y <= -8)
return; // totally off screen return; // totally off screen
x1 = (float) x;
y1 = (float) y;
while (*str) { while (*str) {
if ((num = *str++ | 0x80) != (0x80 | 32)) // Don't render spaces if ((num = *str++ | 0x80) != (0x80 | 32)) // Don't render spaces
{ {
queue_character (x, y, num); queue_character (x1, y1, num);
tVA_increment (); tVA_increment ();
} }
x += 8; x1 += 8.0;
} }
} }

View File

@ -70,7 +70,6 @@ cvar_t *gl_keeptjunctions;
cvar_t *gl_lerp_anim; cvar_t *gl_lerp_anim;
cvar_t *gl_lightmap_align; cvar_t *gl_lightmap_align;
cvar_t *gl_lightmap_subimage; cvar_t *gl_lightmap_subimage;
cvar_t *gl_max_size;
cvar_t *gl_nocolors; cvar_t *gl_nocolors;
cvar_t *gl_particle_mip; cvar_t *gl_particle_mip;
cvar_t *gl_particle_size; cvar_t *gl_particle_size;
@ -145,6 +144,7 @@ int r_viewsize;
float cl_wateralpha; float cl_wateralpha;
static void static void
r_particles_f (cvar_t *var) r_particles_f (cvar_t *var)
{ {
@ -288,8 +288,6 @@ R_Init_Cvars (void)
"around the area changed. 1 updates " "around the area changed. 1 updates "
"every line that changed. 0 updates the " "every line that changed. 0 updates the "
"entire lightmap."); "entire lightmap.");
gl_max_size = Cvar_Get ("gl_max_size", "1024", CVAR_NONE, NULL,
"Texture dimension");
gl_nocolors = Cvar_Get ("gl_nocolors", "0", CVAR_NONE, NULL, gl_nocolors = Cvar_Get ("gl_nocolors", "0", CVAR_NONE, NULL,
"Set to 1, turns off all player colors"); "Set to 1, turns off all player colors");
gl_particle_mip = Cvar_Get ("gl_particle_mip", "0", CVAR_NONE, NULL, gl_particle_mip = Cvar_Get ("gl_particle_mip", "0", CVAR_NONE, NULL,

View File

@ -93,6 +93,7 @@ qboolean is8bit = false;
qboolean gl_feature_mach64 = false; qboolean gl_feature_mach64 = false;
cvar_t *gl_max_size;
cvar_t *gl_multitexture; cvar_t *gl_multitexture;
cvar_t *gl_vaelements_max; cvar_t *gl_vaelements_max;
cvar_t *gl_screenshot_byte_swap; cvar_t *gl_screenshot_byte_swap;
@ -100,6 +101,19 @@ cvar_t *vid_mode;
cvar_t *vid_use8bit; cvar_t *vid_use8bit;
static void
gl_max_size_f (cvar_t *var)
{
GLint texSize;
// Check driver's max texture size
qfglGetIntegerv (GL_MAX_TEXTURE_SIZE, &texSize);
if (var->int_val < 1)
Cvar_SetValue (var, texSize);
else
Cvar_SetValue (var, bound (1, var->int_val, texSize));
}
static void static void
gl_multitexture_f (cvar_t *var) gl_multitexture_f (cvar_t *var)
{ {
@ -124,6 +138,8 @@ GL_Common_Init_Cvars (void)
"Limit the vertex array size for buggy " "Limit the vertex array size for buggy "
"drivers. 0 (default) uses driver provided " "drivers. 0 (default) uses driver provided "
"limit, -1 disables use of vertex arrays."); "limit, -1 disables use of vertex arrays.");
gl_max_size = Cvar_Get ("gl_max_size", "0", CVAR_NONE, gl_max_size_f,
"Texture dimension");
gl_multitexture = Cvar_Get ("gl_multitexture", "0", CVAR_ARCHIVE, gl_multitexture = Cvar_Get ("gl_multitexture", "0", CVAR_ARCHIVE,
gl_multitexture_f, "Use multitexture when " gl_multitexture_f, "Use multitexture when "
"available."); "available.");