From 6c7701a38bfb042e650fb6bc75c84997dc6d7f88 Mon Sep 17 00:00:00 2001 From: Ragnvald Maartmann-Moe IV Date: Mon, 24 Mar 2003 20:21:24 +0000 Subject: [PATCH] Prevent bad gl_max_size settings from causing buggy drivers to freak out. --- libs/video/renderer/gl/gl_draw.c | 86 +++++++++++++++++------------- libs/video/renderer/r_cvar.c | 4 +- libs/video/targets/vid_common_gl.c | 16 ++++++ 3 files changed, 67 insertions(+), 39 deletions(-) diff --git a/libs/video/renderer/gl/gl_draw.c b/libs/video/renderer/gl/gl_draw.c index dec46449e..8d4957a39 100644 --- a/libs/video/renderer/gl/gl_draw.c +++ b/libs/video/renderer/gl/gl_draw.c @@ -129,25 +129,32 @@ Draw_InitText (void) if (r_init) { if (vaelements > 3) tVAsize = vaelements - (vaelements % 4); - else + else if (vaelements >= 0) tVAsize = 2048; - Con_Printf ("Text: %i maximum vertex elements.\n", tVAsize); + else + tVAsize = 0; - if (textVertices) - free (textVertices); - textVertices = calloc (tVAsize, 2 * sizeof (float)); + if (tVAsize) { + Con_Printf ("Text: %i maximum vertex elements.\n", tVAsize); - if (textCoords) - free (textCoords); - textCoords = calloc (tVAsize, 2 * sizeof (float)); + if (textVertices) + free (textVertices); + textVertices = calloc (tVAsize, 2 * sizeof (float)); - qfglTexCoordPointer (2, GL_FLOAT, 0, textCoords); - qfglVertexPointer (2, GL_FLOAT, 0, textVertices); - if (tVAindices) - free (tVAindices); - tVAindices = (int *) calloc (tVAsize, sizeof (int)); - for (i = 0; i < tVAsize; i++) - tVAindices[i] = i; + if (textCoords) + free (textCoords); + textCoords = calloc (tVAsize, 2 * sizeof (float)); + + qfglTexCoordPointer (2, GL_FLOAT, 0, textCoords); + qfglVertexPointer (2, GL_FLOAT, 0, textVertices); + if (tVAindices) + free (tVAindices); + tVAindices = (int *) calloc (tVAsize, sizeof (int)); + for (i = 0; i < tVAsize; i++) + tVAindices[i] = i; + } else { + Con_Printf ("Text: Vertex Array use disabled.\n"); + } } else { if (textVertices) { free (textVertices); @@ -332,11 +339,6 @@ void Draw_Init (void) { 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, "Texture mipmap quality."); @@ -381,13 +383,21 @@ flush_text (void) } static inline void -queue_character (int x, int y, int num) +queue_character (float x, float y, int num) { float frow, fcol; frow = (num >> 4) * 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++ = frow; *tC++ = fcol + CELL_SIZE; @@ -396,14 +406,6 @@ queue_character (int x, int y, int num) *tC++ = frow + CELL_SIZE; *tC++ = fcol; *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 @@ -431,7 +433,7 @@ Draw_Character (int x, int y, unsigned int num) num &= 255; - queue_character (x, y, num); + queue_character ((float) x, (float) y, num); tVA_increment (); } @@ -439,18 +441,22 @@ void Draw_String (int x, int y, const char *str) { unsigned char num; + float x1, y1; if (!str || !str[0]) return; if (y <= -8) return; // totally off screen + x1 = (float) x; + y1 = (float) y; + while (*str) { if ((num = *str++) != 32) { // Don't render spaces - queue_character (x, y, num); + queue_character (x1, y1, num); tVA_increment (); } - x += 8; + x1 += 8.0; } } @@ -458,18 +464,22 @@ void Draw_nString (int x, int y, const char *str, int count) { unsigned char num; + float x1, y1; if (!str || !str[0]) return; if (y <= -8) return; // totally off screen + x1 = (float) x; + y1 = (float) y; + while (count-- && *str) { if ((num = *str++) != 32) { // Don't render spaces - queue_character (x, y, num); + queue_character (x1, y1, num); tVA_increment (); } - x += 8; + x1 += 8.0; } } @@ -477,19 +487,23 @@ void Draw_AltString (int x, int y, const char *str) { unsigned char num; + float x1, y1; if (!str || !str[0]) return; if (y <= -8) return; // totally off screen + x1 = (float) x; + y1 = (float) y; + while (*str) { if ((num = *str++ | 0x80) != (0x80 | 32)) // Don't render spaces { - queue_character (x, y, num); + queue_character (x1, y1, num); tVA_increment (); } - x += 8; + x1 += 8.0; } } diff --git a/libs/video/renderer/r_cvar.c b/libs/video/renderer/r_cvar.c index 0e231efba..64b3e285e 100644 --- a/libs/video/renderer/r_cvar.c +++ b/libs/video/renderer/r_cvar.c @@ -70,7 +70,6 @@ cvar_t *gl_keeptjunctions; cvar_t *gl_lerp_anim; cvar_t *gl_lightmap_align; cvar_t *gl_lightmap_subimage; -cvar_t *gl_max_size; cvar_t *gl_nocolors; cvar_t *gl_particle_mip; cvar_t *gl_particle_size; @@ -145,6 +144,7 @@ int r_viewsize; float cl_wateralpha; + static void r_particles_f (cvar_t *var) { @@ -288,8 +288,6 @@ R_Init_Cvars (void) "around the area changed. 1 updates " "every line that changed. 0 updates the " "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, "Set to 1, turns off all player colors"); gl_particle_mip = Cvar_Get ("gl_particle_mip", "0", CVAR_NONE, NULL, diff --git a/libs/video/targets/vid_common_gl.c b/libs/video/targets/vid_common_gl.c index 166d7bb9e..09d3ebc56 100644 --- a/libs/video/targets/vid_common_gl.c +++ b/libs/video/targets/vid_common_gl.c @@ -93,6 +93,7 @@ qboolean is8bit = false; qboolean gl_feature_mach64 = false; +cvar_t *gl_max_size; cvar_t *gl_multitexture; cvar_t *gl_vaelements_max; cvar_t *gl_screenshot_byte_swap; @@ -100,6 +101,19 @@ cvar_t *vid_mode; 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 gl_multitexture_f (cvar_t *var) { @@ -124,6 +138,8 @@ GL_Common_Init_Cvars (void) "Limit the vertex array size for buggy " "drivers. 0 (default) uses driver provided " "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_f, "Use multitexture when " "available.");