Fake vertex arrays for text and particles.

Getting gl_vaelements_max -1 to work produced a rather nasty surprise :P
This commit is contained in:
Bill Currie 2011-12-16 20:09:05 +09:00
parent 5cd1f6f5cf
commit 933120d44f
2 changed files with 83 additions and 48 deletions

View file

@ -77,11 +77,12 @@ typedef struct {
byte *draw_chars; // 8*8 graphic characters
int tVAsize;
int *tVAindices;
int tVAcount;
float *textVertices, *tV;
float *textCoords, *tC;
int textUseVA;
int tVAsize;
int *tVAindices;
int tVAcount;
float *textVertices, *tV;
float *textCoords, *tC;
qpic_t *draw_backtile;
@ -146,35 +147,37 @@ Draw_InitText (void)
{
int i;
if (vaelements > 3) {
tVAsize = vaelements - (vaelements % 4);
} else if (vaelements >= 0) {
if (vaelements < 0) {
textUseVA = 0;
tVAsize = 2048;
} else
tVAsize = 0;
if (tVAsize) {
Sys_MaskPrintf (SYS_DEV, "Text: Vertex Array use disabled.\n");
} else {
textUseVA = 1;
if (vaelements > 3)
tVAsize = vaelements - (vaelements % 4);
else
tVAsize = 2048;
Sys_MaskPrintf (SYS_DEV, "Text: %i maximum vertex elements.\n",
tVAsize);
}
if (textVertices)
free (textVertices);
textVertices = calloc (tVAsize, 2 * sizeof (float));
if (textVertices)
free (textVertices);
textVertices = calloc (tVAsize, 2 * sizeof (float));
if (textCoords)
free (textCoords);
textCoords = calloc (tVAsize, 2 * sizeof (float));
if (textCoords)
free (textCoords);
textCoords = calloc (tVAsize, 2 * sizeof (float));
if (textUseVA) {
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 {
Sys_MaskPrintf (SYS_DEV, "Text: Vertex Array use disabled.\n");
}
if (tVAindices)
free (tVAindices);
tVAindices = (int *) calloc (tVAsize, sizeof (int));
for (i = 0; i < tVAsize; i++)
tVAindices[i] = i;
}
VISIBLE qpic_t *
@ -424,7 +427,22 @@ static inline void
flush_text (void)
{
qfglBindTexture (GL_TEXTURE_2D, char_texture);
qfglDrawElements (GL_QUADS, tVAcount, GL_UNSIGNED_INT, tVAindices);
if (textUseVA) {
qfglDrawElements (GL_QUADS, tVAcount, GL_UNSIGNED_INT, tVAindices);
} else {
float *v = textVertices;
float *c = textCoords;
int i;
qfglBegin (GL_QUADS);
for (i = 0; i < tVAcount; i++) {
qfglTexCoord2fv (c);
qfglVertex2fv (v);
c += 2;
v += 2;
}
qfglEnd ();
}
tVAcount = 0;
tV = textVertices;
tC = textCoords;

View file

@ -64,6 +64,7 @@ int ramp1[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 };
int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 };
int ramp3[8] = { 0x6d, 0x6b, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
int partUseVA;
int pVAsize;
int *pVAindices;
varray_t2f_c4ub_v3f_t *particleVertexArray;
@ -153,33 +154,34 @@ R_InitParticles (void)
int i;
if (r_maxparticles && r_init) {
if (vaelements > 3)
pVAsize = min ((unsigned int) (vaelements - (vaelements % 4)),
r_maxparticles * 4);
else if (vaelements >= 0)
if (vaelements) {
partUseVA = 0;
pVAsize = r_maxparticles * 4;
else
pVAsize = 0;
if (pVAsize) {
Sys_MaskPrintf (SYS_DEV,
"Particles: Vertex Array use disabled.\n");
} else {
if (vaelements > 3)
pVAsize = min ((unsigned int) (vaelements - (vaelements % 4)),
r_maxparticles * 4);
else if (vaelements >= 0)
pVAsize = r_maxparticles * 4;
Sys_MaskPrintf (SYS_DEV,
"Particles: %i maximum vertex elements.\n",
pVAsize);
}
if (particleVertexArray)
free (particleVertexArray);
particleVertexArray = (varray_t2f_c4ub_v3f_t *)
calloc (pVAsize, sizeof (varray_t2f_c4ub_v3f_t));
if (particleVertexArray)
free (particleVertexArray);
particleVertexArray = (varray_t2f_c4ub_v3f_t *)
calloc (pVAsize, sizeof (varray_t2f_c4ub_v3f_t));
if (partUseVA)
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, particleVertexArray);
if (pVAindices)
free (pVAindices);
pVAindices = (int *) calloc (pVAsize, sizeof (int));
for (i = 0; i < pVAsize; i++)
pVAindices[i] = i;
} else {
Sys_MaskPrintf (SYS_DEV,
"Particles: Vertex Array use disabled.\n");
}
if (pVAindices)
free (pVAindices);
pVAindices = (int *) calloc (pVAsize, sizeof (int));
for (i = 0; i < pVAsize; i++)
pVAindices[i] = i;
} else {
if (particleVertexArray) {
free (particleVertexArray);
@ -1646,6 +1648,7 @@ R_DrawParticles (void)
VA += 4;
vacount += 4;
if (vacount + 4 > pVAsize) {
// never reached if partUseVA is false
qfglDrawElements (GL_QUADS, vacount, GL_UNSIGNED_INT,
pVAindices);
vacount = 0;
@ -1664,8 +1667,22 @@ R_DrawParticles (void)
activeparticles++;
}
}
if (vacount)
qfglDrawElements (GL_QUADS, vacount, GL_UNSIGNED_INT, pVAindices);
if (vacount) {
if (partUseVA) {
qfglDrawElements (GL_QUADS, vacount, GL_UNSIGNED_INT, pVAindices);
} else {
varray_t2f_c4ub_v3f_t *va = particleVertexArray;
int i;
qfglBegin (GL_QUADS);
for (i = 0; i < vacount; i++, va++) {
qfglTexCoord2fv (va->texcoord);
qfglColor4ubv (va->color);
qfglVertex3fv (va->vertex);
}
qfglEnd ();
}
}
k = 0;
while (maxparticle >= activeparticles) {