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