mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Use vertex arrays for text. Another 1-3% speedup.
This commit is contained in:
parent
71c9cdcc08
commit
10d7d17fcc
6 changed files with 189 additions and 70 deletions
|
@ -31,9 +31,11 @@
|
|||
|
||||
#include "QF/wad.h"
|
||||
|
||||
extern byte *draw_chars;
|
||||
extern qpic_t *draw_disc; // also used on sbar
|
||||
|
||||
void Draw_Init (void);
|
||||
void Draw_InitText (void);
|
||||
void Draw_Init_Cvars (void);
|
||||
void Draw_Character (int x, int y, unsigned int num);
|
||||
void Draw_Pic (int x, int y, qpic_t *pic);
|
||||
|
@ -54,7 +56,6 @@ qpic_t *Draw_PicFromWad (const char *name);
|
|||
qpic_t *Draw_CachePic (const char *path, qboolean alpha);
|
||||
|
||||
void GL_Set2D (void);
|
||||
|
||||
extern byte *draw_chars;
|
||||
void GL_FlushText (void);
|
||||
|
||||
#endif // _DRAW_H
|
||||
|
|
|
@ -39,12 +39,6 @@
|
|||
|
||||
#include "QF/GL/types.h"
|
||||
|
||||
typedef struct varray_t2f_c4ub_v2f_s {
|
||||
GLfloat texcoord[2];
|
||||
GLubyte color[4];
|
||||
GLfloat vertex[2];
|
||||
} varray_t2f_c4ub_v2f_t;
|
||||
|
||||
typedef struct varray_t2f_c4ub_v3f_s {
|
||||
GLfloat texcoord[2];
|
||||
GLubyte color[4];
|
||||
|
@ -58,14 +52,16 @@ typedef struct varray_t2f_c4f_n3f_v3f_s {
|
|||
GLfloat vertex[3];
|
||||
} varray_t2f_c4f_n3f_v3f_t;
|
||||
|
||||
//#define MAX_VARRAY_VERTS 10000
|
||||
|
||||
extern int vaelements;
|
||||
|
||||
//extern varray_t2f_c4f_n3f_v3f_t *modelVertexArray
|
||||
//extern int mVAsize;
|
||||
|
||||
extern varray_t2f_c4ub_v3f_t *particleVertexArray;
|
||||
extern int pVAsize;
|
||||
|
||||
//extern varray_t2f_c4ub_v3f_t *modelVertexArray
|
||||
//extern varray_t2f_v2f_t *textVertexArray;
|
||||
extern float *textCoords;
|
||||
extern float *textVertices;
|
||||
extern int tVAsize;
|
||||
|
||||
#endif // __qf_varrays_h
|
||||
|
|
|
@ -64,8 +64,15 @@ static const char rcsid[] =
|
|||
#include "r_cvar.h"
|
||||
#include "r_shared.h"
|
||||
#include "sbar.h"
|
||||
#include "varrays.h"
|
||||
|
||||
byte *draw_chars; // 8*8 graphic characters
|
||||
byte *draw_chars; // 8*8 graphic characters
|
||||
|
||||
int tVAsize;
|
||||
int *tVAindices;
|
||||
unsigned int tVAcount;
|
||||
float *textVertices, *tV;
|
||||
float *textCoords, *tC;
|
||||
|
||||
qpic_t *draw_backtile;
|
||||
|
||||
|
@ -103,6 +110,50 @@ static int numcachepics;
|
|||
|
||||
static byte menuplyr_pixels[4096];
|
||||
|
||||
|
||||
void
|
||||
Draw_InitText (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (r_init) {
|
||||
if (vaelements > 3)
|
||||
tVAsize = vaelements - (vaelements %4);
|
||||
else
|
||||
tVAsize = 2048;
|
||||
Con_Printf ("Text: %i maximum vertex elements.\n", tVAsize);
|
||||
|
||||
if (textVertices)
|
||||
free (textVertices);
|
||||
textVertices = calloc (tVAsize, 2 * sizeof (float));
|
||||
|
||||
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 {
|
||||
if (textVertices) {
|
||||
free (textVertices);
|
||||
textVertices = 0;
|
||||
}
|
||||
if (textCoords) {
|
||||
free (textCoords);
|
||||
textCoords = 0;
|
||||
}
|
||||
if (tVAindices) {
|
||||
free (tVAindices);
|
||||
tVAindices = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qpic_t *
|
||||
Draw_PicFromWad (const char *name)
|
||||
{
|
||||
|
@ -323,7 +374,6 @@ Draw_Character (int x, int y, unsigned int num)
|
|||
|
||||
if (num == 32)
|
||||
return; // space
|
||||
|
||||
if (y <= -8)
|
||||
return; // totally off screen
|
||||
|
||||
|
@ -332,18 +382,30 @@ Draw_Character (int x, int y, unsigned int num)
|
|||
frow = (num >> 4) * CELL_SIZE;
|
||||
fcol = (num & 15) * CELL_SIZE;
|
||||
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
|
||||
qfglBegin (GL_QUADS);
|
||||
qfglTexCoord2f (fcol, frow);
|
||||
qfglVertex2f (x, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow);
|
||||
qfglVertex2f (x + 8, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow + CELL_SIZE);
|
||||
qfglVertex2f (x + 8, y + 8);
|
||||
qfglTexCoord2f (fcol, frow + CELL_SIZE);
|
||||
qfglVertex2f (x, y + 8);
|
||||
qfglEnd ();
|
||||
*tC++ = fcol;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*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;
|
||||
tVAcount += 4;
|
||||
if (tVAcount + 4 > tVAsize) {
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglDrawElements (GL_QUADS, tVAcount, GL_UNSIGNED_INT, tVAindices);
|
||||
tVAcount = 0;
|
||||
tV = textVertices;
|
||||
tC = textCoords;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -357,28 +419,40 @@ Draw_String (int x, int y, const char *str)
|
|||
if (y <= -8)
|
||||
return; // totally off screen
|
||||
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglBegin (GL_QUADS);
|
||||
|
||||
while (*str) {
|
||||
if ((num = *str++) != 32) // Don't render spaces
|
||||
{
|
||||
frow = (num >> 4) * CELL_SIZE;
|
||||
fcol = (num & 15) * CELL_SIZE;
|
||||
|
||||
qfglTexCoord2f (fcol, frow);
|
||||
qfglVertex2f (x, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow);
|
||||
qfglVertex2f (x + 8, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow + CELL_SIZE);
|
||||
qfglVertex2f (x + 8, y + 8);
|
||||
qfglTexCoord2f (fcol, frow + CELL_SIZE);
|
||||
qfglVertex2f (x, y + 8);
|
||||
*tC++ = fcol;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*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;
|
||||
tVAcount += 4;
|
||||
if (tVAcount + 4 > tVAsize) {
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglDrawElements (GL_QUADS, tVAcount, GL_UNSIGNED_INT,
|
||||
tVAindices);
|
||||
tVAcount = 0;
|
||||
tV = textVertices;
|
||||
tC = textCoords;
|
||||
}
|
||||
}
|
||||
x += 8;
|
||||
}
|
||||
|
||||
qfglEnd ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -392,26 +466,39 @@ Draw_nString (int x, int y, const char *str, int count)
|
|||
if (y <= -8)
|
||||
return; // totally off screen
|
||||
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglBegin (GL_QUADS);
|
||||
|
||||
while (count-- && *str) {
|
||||
if ((num = *str++) != 32) { // Don't render spaces
|
||||
frow = (num >> 4) * CELL_SIZE;
|
||||
fcol = (num & 15) * CELL_SIZE;
|
||||
|
||||
qfglTexCoord2f (fcol, frow);
|
||||
qfglVertex2f (x, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow);
|
||||
qfglVertex2f (x + 8, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow + CELL_SIZE);
|
||||
qfglVertex2f (x + 8, y + 8);
|
||||
qfglTexCoord2f (fcol, frow + CELL_SIZE);
|
||||
qfglVertex2f (x, y + 8);
|
||||
*tC++ = fcol;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*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;
|
||||
tVAcount += 4;
|
||||
if (tVAcount + 4 > tVAsize) {
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglDrawElements (GL_QUADS, tVAcount, GL_UNSIGNED_INT,
|
||||
tVAindices);
|
||||
tVAcount = 0;
|
||||
tV = textVertices;
|
||||
tC = textCoords;
|
||||
}
|
||||
}
|
||||
x += 8;
|
||||
}
|
||||
qfglEnd ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -425,28 +512,40 @@ Draw_AltString (int x, int y, const char *str)
|
|||
if (y <= -8)
|
||||
return; // totally off screen
|
||||
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglBegin (GL_QUADS);
|
||||
|
||||
while (*str) {
|
||||
if ((num = *str++ | 0x80) != (0x80 | 32)) // Don't render spaces
|
||||
{
|
||||
frow = (num >> 4) * CELL_SIZE;
|
||||
fcol = (num & 15) * CELL_SIZE;
|
||||
|
||||
qfglTexCoord2f (fcol, frow);
|
||||
qfglVertex2f (x, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow);
|
||||
qfglVertex2f (x + 8, y);
|
||||
qfglTexCoord2f (fcol + CELL_SIZE, frow + CELL_SIZE);
|
||||
qfglVertex2f (x + 8, y + 8);
|
||||
qfglTexCoord2f (fcol, frow + CELL_SIZE);
|
||||
qfglVertex2f (x, y + 8);
|
||||
*tC++ = fcol;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*tC++ = frow;
|
||||
*tC++ = fcol + CELL_SIZE;
|
||||
*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;
|
||||
tVAcount += 4;
|
||||
if (tVAcount + 4 > tVAsize) {
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglDrawElements (GL_QUADS, tVAcount, GL_UNSIGNED_INT,
|
||||
tVAindices);
|
||||
tVAcount = 0;
|
||||
tV = textVertices;
|
||||
tC = textCoords;
|
||||
}
|
||||
}
|
||||
x += 8;
|
||||
}
|
||||
|
||||
qfglEnd ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -601,6 +700,8 @@ Draw_ConsoleBackground (int lines)
|
|||
glpic_t *gl;
|
||||
qpic_t *conback;
|
||||
|
||||
GL_FlushText (); // Flush text that should be rendered before the console
|
||||
|
||||
// This can be a CachePic now, just like in software
|
||||
conback = Draw_CachePic ("gfx/conback.lmp", false);
|
||||
gl = (glpic_t *) conback->data;
|
||||
|
@ -777,4 +878,25 @@ GL_Set2D (void)
|
|||
qfglDisable (GL_CULL_FACE);
|
||||
|
||||
qfglColor3ubv (color_white);
|
||||
|
||||
qfglEnableClientState (GL_VERTEX_ARRAY);
|
||||
qfglVertexPointer (2, GL_FLOAT, 0, textVertices);
|
||||
qfglEnableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||
qfglTexCoordPointer (2, GL_FLOAT, 0, textCoords);
|
||||
qfglDisableClientState (GL_COLOR_ARRAY);
|
||||
tVAcount = 0;
|
||||
tV = textVertices;
|
||||
tC = textCoords;
|
||||
}
|
||||
|
||||
void
|
||||
GL_FlushText (void)
|
||||
{
|
||||
if (tVAcount) {
|
||||
qfglBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
qfglDrawElements (GL_QUADS, tVAcount, GL_UNSIGNED_INT, tVAindices);
|
||||
tVAcount = 0;
|
||||
tV = textVertices;
|
||||
tC = textCoords;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ R_InitParticles (void)
|
|||
pVAsize = min (vaelements - (vaelements % 4), r_maxparticles * 4);
|
||||
else
|
||||
pVAsize = r_maxparticles * 4;
|
||||
Con_Printf ("%i maximum vertex elements.\n", pVAsize);
|
||||
Con_Printf ("Particles: %i maximum vertex elements.\n", pVAsize);
|
||||
|
||||
if (particleVertexArray)
|
||||
free (particleVertexArray);
|
||||
|
@ -1281,9 +1281,10 @@ R_DrawParticles (void)
|
|||
if (!r_particles->int_val)
|
||||
return;
|
||||
|
||||
qfglBindTexture (GL_TEXTURE_2D, part_tex);
|
||||
// LordHavoc: particles should not affect zbuffer
|
||||
qfglDepthMask (GL_FALSE);
|
||||
qfglBindTexture (GL_TEXTURE_2D, part_tex);
|
||||
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, particleVertexArray);
|
||||
|
||||
grav = (fast_grav = r_frametime * 800.0) * 0.05;
|
||||
time_125 = r_frametime * 0.125;
|
||||
|
|
|
@ -42,6 +42,7 @@ static const char rcsid[] =
|
|||
#include "QF/cmd.h"
|
||||
#include "QF/console.h"
|
||||
#include "QF/cvar.h"
|
||||
#include "QF/draw.h"
|
||||
#include "QF/render.h"
|
||||
#include "QF/skin.h"
|
||||
#include "QF/sys.h"
|
||||
|
@ -161,10 +162,7 @@ R_Init (void)
|
|||
|
||||
r_init = 1;
|
||||
R_InitParticles ();
|
||||
|
||||
qfglEnableClientState (GL_COLOR_ARRAY);
|
||||
qfglEnableClientState (GL_VERTEX_ARRAY);
|
||||
qfglEnableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||
Draw_InitText ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -856,5 +856,6 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
|
|||
c_alias_polys);
|
||||
}
|
||||
|
||||
GL_FlushText ();
|
||||
qfglFlush ();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue