R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
}
-extern cvar_t gl_mesh_drawrangeelements;
-extern int gl_maxdrawrangeelementsvertices;
-extern int gl_maxdrawrangeelementsindices;
-
-#if 0
+int quadelements[768];
void R_DrawQueue(void)
{
- int pos, num, chartexnum, overbright;
- float x, y, w, h, s, t, u, v;
+ int pos, num, chartexnum, overbright, texnum, additive, batch;
+ float x, y, w, h, s, t, u, v, cr, cg, cb, ca, *av, *at, *ac;
cachepic_t *pic;
drawqueue_t *dq;
char *str, *currentpic;
int batchcount;
unsigned int color;
drawqueuemesh_t *mesh;
+ rmeshstate_t m;
if (!r_render.integer)
return;
+ if (!quadelements[1])
+ {
+ // elements for rendering a series of quads as triangles
+ for (batch = 0, pos = 0, num = 0;batch < 128;batch++, num += 4)
+ {
+ quadelements[pos++] = num;
+ quadelements[pos++] = num + 1;
+ quadelements[pos++] = num + 2;
+ quadelements[pos++] = num;
+ quadelements[pos++] = num + 2;
+ quadelements[pos++] = num + 3;
+ }
+ }
GL_SetupView_ViewPort(vid.realx, vid.realy, vid.realwidth, vid.realheight);
GL_SetupView_Mode_Ortho(0, 0, vid.conwidth, vid.conheight, -10, 100);
- GL_SetupView_Orientation_Identity();
GL_DepthFunc(GL_LEQUAL);
R_Mesh_Start();
+ R_Mesh_Matrix(&r_identitymatrix);
+ memset(&m, 0, sizeof(m));
chartexnum = R_GetTexture(char_texture);
+ m.tex[0] = chartexnum;
+ R_Mesh_TextureState(&m);
currentpic = "";
pic = NULL;
y = dq->y;
w = dq->scalex;
h = dq->scaley;
-
+
switch(dq->command)
{
case DRAWQUEUE_PIC:
str = (char *)(dq + 1);
if (strcmp(str, currentpic))
{
- if (batch)
- {
- batch = false;
- qglEnd();
- }
currentpic = str;
pic = Draw_CachePic(str);
- qglBindTexture(GL_TEXTURE_2D, R_GetTexture(pic->tex));
+ m.tex[0] = R_GetTexture(pic->tex);
+ R_Mesh_TextureState(&m);
}
if (*str)
{
varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = cg;
varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = cb;
varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = ca;
- varray_texcoord[0] = 0;varray_texcoord[1] = 0;
- varray_texcoord[2] = 1;varray_texcoord[3] = 0;
- varray_texcoord[4] = 1;varray_texcoord[5] = 1;
- varray_texcoord[6] = 0;varray_texcoord[7] = 1;
- varray_vertex[ 0] = x ;varray_vertex[ 1] = y ;varray_vertex[ 2] = 0;
- varray_vertex[ 4] = x+w;varray_vertex[ 5] = y ;varray_vertex[ 6] = 0;
- varray_vertex[ 8] = x+w;varray_vertex[ 9] = y+h;varray_vertex[10] = 0;
- varray_vertex[12] = x ;varray_vertex[13] = y+h;varray_vertex[14] = 0;
- R_Mesh_Draw(4, 2, polygonelements);
+ varray_texcoord[0][0] = 0;varray_texcoord[0][1] = 0;
+ varray_texcoord[0][2] = 1;varray_texcoord[0][3] = 0;
+ varray_texcoord[0][4] = 1;varray_texcoord[0][5] = 1;
+ varray_texcoord[0][6] = 0;varray_texcoord[0][7] = 1;
+ varray_vertex[ 0] = x ;varray_vertex[ 1] = y ;varray_vertex[ 2] = 10;
+ varray_vertex[ 4] = x+w;varray_vertex[ 5] = y ;varray_vertex[ 6] = 10;
+ varray_vertex[ 8] = x+w;varray_vertex[ 9] = y+h;varray_vertex[10] = 10;
+ varray_vertex[12] = x ;varray_vertex[13] = y+h;varray_vertex[14] = 10;
+ R_Mesh_Draw(4, 2, quadelements);
break;
case DRAWQUEUE_STRING:
str = (char *)(dq + 1);
if (strcmp("gfx/conchars", currentpic))
{
- if (batch)
- {
- batch = false;
- qglEnd();
- }
currentpic = "gfx/conchars";
- qglBindTexture(GL_TEXTURE_2D, chartexnum);
+ m.tex[0] = chartexnum;
+ R_Mesh_TextureState(&m);
}
batchcount = 0;
ac = varray_color;
- at = varray_texcoord;
+ at = varray_texcoord[0];
av = varray_vertex;
while ((num = *str++) && x < vid.conwidth)
{
at[2] = s+u;at[3] = t ;
at[4] = s+u;at[5] = t+v;
at[6] = s ;at[7] = t+v;
- av[0] = x ;av[1] = y ;av[2] = 0;
- av[4] = x+w;av[1] = y ;av[2] = 0;
- av[8] = x+w;av[1] = y+h;av[2] = 0;
- av[0] = x ;av[1] = y+h;av[2] = 0;
+ av[ 0] = x ;av[ 1] = y ;av[ 2] = 10;
+ av[ 4] = x+w;av[ 5] = y ;av[ 6] = 10;
+ av[ 8] = x+w;av[ 9] = y+h;av[10] = 10;
+ av[12] = x ;av[13] = y+h;av[14] = 10;
ac += 16;
at += 8;
av += 16;
batchcount++;
if (batchcount >= 128)
{
- R_Mesh_Draw(batchcount * 4, batchcount * 2, polygonelements);
+ R_Mesh_Draw(batchcount * 4, batchcount * 2, quadelements);
batchcount = 0;
ac = varray_color;
- at = varray_texcoord;
+ at = varray_texcoord[0];
av = varray_vertex;
}
}
x += w;
}
- R_Mesh_Draw(batchcount * 4, batchcount * 2, polygonelements);
+ if (batchcount > 0)
+ R_Mesh_Draw(batchcount * 4, batchcount * 2, quadelements);
break;
case DRAWQUEUE_MESH:
mesh = (void *)(dq + 1);
m.tex[0] = R_GetTexture(mesh->texture);
+ R_Mesh_TextureState(&m);
R_Mesh_ResizeCheck(mesh->numvertices);
memcpy(varray_vertex, mesh->vertices, sizeof(float[4]) * mesh->numvertices);
- memcpy(varray_texcoord, mesh->texcoords, sizeof(float[2]) * mesh->numvertices);
+ memcpy(varray_texcoord[0], mesh->texcoords, sizeof(float[2]) * mesh->numvertices);
memcpy(varray_color, mesh->colors, sizeof(float[4]) * mesh->numvertices);
- R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->indices);
+ R_Mesh_Draw(mesh->numvertices, mesh->numtriangles, mesh->indices);
currentpic = "\0";
break;
}
if (!v_hwgamma.integer)
{
+ // we use one big triangle for all the screen blends
+ varray_texcoord[0][0] = 0;varray_texcoord[0][1] = 0;
+ varray_texcoord[0][2] = 0;varray_texcoord[0][3] = 0;
+ varray_texcoord[0][4] = 0;varray_texcoord[0][5] = 0;
+ varray_vertex[0] = -5000;varray_vertex[1] = -5000;varray_vertex[2] = 10;
+ varray_vertex[4] = 10000;varray_vertex[1] = -5000;varray_vertex[2] = 10;
+ varray_vertex[8] = -5000;varray_vertex[1] = 10000;varray_vertex[2] = 10;
+ // alpha is 1 for all these
+ varray_color[3] = varray_color[7] = varray_color[11] = 1;
+ // all the blends ignore depth
+ m.depthdisable = true;
t = v_contrast.value * (float) (1 << v_overbrightbits.integer);
if (t >= 1.01f)
{
m.blendfunc1 = GL_DST_COLOR;
m.blendfunc2 = GL_ONE;
- m.depthdisable = true;
R_Mesh_State(&m);
while (t >= 1.01f)
{
cr = t - 1.0f;
if (cr > 1.0f)
cr = 1.0f;
- varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = cr;
- varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = cr;
- varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = cr;
- varray_texcoord[0] = 0;varray_texcoord[1] = 0;
- varray_texcoord[2] = 0;varray_texcoord[3] = 0;
- varray_texcoord[4] = 0;varray_texcoord[5] = 0;
- varray_vertex[0] = -5000;varray_vertex[1] = -5000;varray_vertex[2] = 0;
- varray_vertex[4] = 10000;varray_vertex[1] = -5000;varray_vertex[2] = 0;
- varray_vertex[8] = -5000;varray_vertex[1] = 10000;varray_vertex[2] = 0;
+ varray_color[0] = varray_color[4] = varray_color[ 8] = cr;
+ varray_color[1] = varray_color[5] = varray_color[ 9] = cr;
+ varray_color[2] = varray_color[6] = varray_color[10] = cr;
R_Mesh_Draw(3, 1, polygonelements);
t *= 0.5;
}
}
else if (t <= 0.99f)
{
- qglBlendFunc(GL_ZERO, GL_SRC_COLOR);
- CHECKGLERROR
- qglBegin(GL_TRIANGLES);
- num = (int) (t * 255.0f);
- qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
- qglVertex2f (-5000, -5000);
- qglVertex2f (10000, -5000);
- qglVertex2f (-5000, 10000);
- qglEnd();
- CHECKGLERROR
- }
- if (v_brightness.value >= 0.01f)
- {
- qglBlendFunc (GL_ONE, GL_ONE);
- CHECKGLERROR
- num = (int) (v_brightness.value * 255.0f);
- qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
- CHECKGLERROR
- qglBegin (GL_TRIANGLES);
- qglVertex2f (-5000, -5000);
- qglVertex2f (10000, -5000);
- qglVertex2f (-5000, 10000);
- qglEnd ();
- CHECKGLERROR
- }
- qglEnable(GL_TEXTURE_2D);
- CHECKGLERROR
- }
-
- qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- CHECKGLERROR
- qglEnable (GL_CULL_FACE);
- CHECKGLERROR
- qglEnable (GL_DEPTH_TEST);
- CHECKGLERROR
- qglDisable (GL_BLEND);
- CHECKGLERROR
- qglColor4ub (255, 255, 255, 255);
- CHECKGLERROR
-}
-#else
-void R_DrawQueue(void)
-{
- int pos, num, chartexnum, overbright;
- float x, y, w, h, s, t, u, v;
- cachepic_t *pic;
- drawqueue_t *dq;
- char *str, *currentpic;
- int batch, batchcount, additive;
- unsigned int color;
- drawqueuemesh_t *mesh;
-
- if (!r_render.integer)
- return;
-
- qglMatrixMode(GL_PROJECTION);
- qglLoadIdentity();
- qglOrtho(0, vid.conwidth, vid.conheight, 0, -99999, 99999);
-
- qglMatrixMode(GL_MODELVIEW);
- qglLoadIdentity();
-
- qglDisable(GL_DEPTH_TEST);
- qglDisable(GL_CULL_FACE);
- qglEnable(GL_BLEND);
- qglEnable(GL_TEXTURE_2D);
- qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- chartexnum = R_GetTexture(char_texture);
-
- additive = false;
- qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- currentpic = "";
- pic = NULL;
- qglBindTexture(GL_TEXTURE_2D, 0);
- color = 0;
- qglColor4ub(0,0,0,0);
-
- overbright = v_overbrightbits.integer;
- batch = false;
- batchcount = 0;
- for (pos = 0;pos < r_refdef.drawqueuesize;pos += ((drawqueue_t *)(r_refdef.drawqueue + pos))->size)
- {
- dq = (drawqueue_t *)(r_refdef.drawqueue + pos);
- if (dq->flags & DRAWFLAG_ADDITIVE)
- {
- if (!additive)
- {
- if (batch)
- {
- batch = false;
- qglEnd();
- }
- additive = true;
- qglBlendFunc(GL_SRC_ALPHA, GL_ONE);
- }
- }
- else
- {
- if (additive)
- {
- if (batch)
- {
- batch = false;
- qglEnd();
- }
- additive = false;
- qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- }
- if (color != dq->color)
- {
- color = dq->color;
- qglColor4ub((qbyte)(((color >> 24) & 0xFF) >> overbright), (qbyte)(((color >> 16) & 0xFF) >> overbright), (qbyte)(((color >> 8) & 0xFF) >> overbright), (qbyte)(color & 0xFF));
- }
- if (batch && batchcount > 128)
- {
- batch = false;
- qglEnd();
- }
- x = dq->x;
- y = dq->y;
- w = dq->scalex;
- h = dq->scaley;
- switch(dq->command)
- {
- case DRAWQUEUE_PIC:
- str = (char *)(dq + 1);
- if (*str)
- {
- if (strcmp(str, currentpic))
- {
- if (batch)
- {
- batch = false;
- qglEnd();
- }
- currentpic = str;
- pic = Draw_CachePic(str);
- qglBindTexture(GL_TEXTURE_2D, R_GetTexture(pic->tex));
- }
- if (w == 0)
- w = pic->width;
- if (h == 0)
- h = pic->height;
- if (!batch)
- {
- batch = true;
- qglBegin(GL_TRIANGLES);
- batchcount = 0;
- }
- qglTexCoord2f (0, 0);qglVertex2f (x , y );
- qglTexCoord2f (1, 0);qglVertex2f (x+w, y );
- qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
- qglTexCoord2f (0, 0);qglVertex2f (x , y );
- qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
- qglTexCoord2f (0, 1);qglVertex2f (x , y+h);
- batchcount++;
- }
- else
- {
- if (currentpic[0])
- {
- if (batch)
- {
- batch = false;
- qglEnd();
- }
- currentpic = "";
- qglBindTexture(GL_TEXTURE_2D, 0);
- }
- if (!batch)
- {
- batch = true;
- qglBegin(GL_TRIANGLES);
- batchcount = 0;
- }
- qglTexCoord2f (0, 0);qglVertex2f (x , y );
- qglTexCoord2f (1, 0);qglVertex2f (x+w, y );
- qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
- qglTexCoord2f (0, 0);qglVertex2f (x , y );
- qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
- qglTexCoord2f (0, 1);qglVertex2f (x , y+h);
- batchcount++;
- }
- break;
- case DRAWQUEUE_STRING:
- str = (char *)(dq + 1);
- if (strcmp("gfx/conchars", currentpic))
- {
- if (batch)
- {
- batch = false;
- qglEnd();
- }
- currentpic = "gfx/conchars";
- qglBindTexture(GL_TEXTURE_2D, chartexnum);
- }
- if (!batch)
- {
- batch = true;
- qglBegin(GL_TRIANGLES);
- batchcount = 0;
- }
- while ((num = *str++) && x < vid.conwidth)
- {
- if (num != ' ')
- {
- s = (num & 15)*0.0625f + (0.5f / 256.0f);
- t = (num >> 4)*0.0625f + (0.5f / 256.0f);
- u = 0.0625f - (1.0f / 256.0f);
- v = 0.0625f - (1.0f / 256.0f);
- qglTexCoord2f (s , t );qglVertex2f (x , y );
- qglTexCoord2f (s+u, t );qglVertex2f (x+w, y );
- qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
- qglTexCoord2f (s , t );qglVertex2f (x , y );
- qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
- qglTexCoord2f (s , t+v);qglVertex2f (x , y+h);
- batchcount++;
- }
- x += w;
- }
- break;
- case DRAWQUEUE_MESH:
- if (batch)
- {
- batch = false;
- qglEnd();
- }
-
- mesh = (void *)(dq + 1);
- qglBindTexture(GL_TEXTURE_2D, R_GetTexture(mesh->texture));
- qglVertexPointer(3, GL_FLOAT, sizeof(float[4]), mesh->vertices);CHECKGLERROR
- qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), mesh->texcoords);CHECKGLERROR
- qglColorPointer(4, GL_FLOAT, sizeof(float[4]), mesh->colors);CHECKGLERROR
- qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
- qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
- qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR
- GL_DrawRangeElements(0, mesh->numvertices, mesh->numindices, mesh->indices);
- qglDisableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
- qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
- qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR
-
- // restore color, since it got trashed by using color array
- qglColor4ub((qbyte)(((color >> 24) & 0xFF) >> overbright), (qbyte)(((color >> 16) & 0xFF) >> overbright), (qbyte)(((color >> 8) & 0xFF) >> overbright), (qbyte)(color & 0xFF));
- CHECKGLERROR
- currentpic = "\0";
- break;
- }
- }
- if (batch)
- qglEnd();
- CHECKGLERROR
-
- if (!v_hwgamma.integer)
- {
- qglDisable(GL_TEXTURE_2D);
- CHECKGLERROR
- t = v_contrast.value * (float) (1 << v_overbrightbits.integer);
- if (t >= 1.01f)
- {
- qglBlendFunc (GL_DST_COLOR, GL_ONE);
- CHECKGLERROR
- qglBegin (GL_TRIANGLES);
- while (t >= 1.01f)
- {
- num = (int) ((t - 1.0f) * 255.0f);
- if (num > 255)
- num = 255;
- qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
- qglVertex2f (-5000, -5000);
- qglVertex2f (10000, -5000);
- qglVertex2f (-5000, 10000);
- t *= 0.5;
- }
- qglEnd ();
- CHECKGLERROR
- }
- else if (t <= 0.99f)
- {
- qglBlendFunc(GL_ZERO, GL_SRC_COLOR);
- CHECKGLERROR
- qglBegin(GL_TRIANGLES);
- num = (int) (t * 255.0f);
- qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
- qglVertex2f (-5000, -5000);
- qglVertex2f (10000, -5000);
- qglVertex2f (-5000, 10000);
- qglEnd();
- CHECKGLERROR
+ m.blendfunc1 = GL_ZERO;
+ m.blendfunc2 = GL_SRC_COLOR;
+ R_Mesh_State(&m);
+ varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = t;
+ varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = t;
+ varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = t;
+ R_Mesh_Draw(3, 1, polygonelements);
}
if (v_brightness.value >= 0.01f)
{
- qglBlendFunc (GL_ONE, GL_ONE);
- CHECKGLERROR
- num = (int) (v_brightness.value * 255.0f);
- qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
- CHECKGLERROR
- qglBegin (GL_TRIANGLES);
- qglVertex2f (-5000, -5000);
- qglVertex2f (10000, -5000);
- qglVertex2f (-5000, 10000);
- qglEnd ();
- CHECKGLERROR
+ m.blendfunc1 = GL_ONE;
+ m.blendfunc2 = GL_ONE;
+ R_Mesh_State(&m);
+ varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = v_brightness.value;
+ varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = v_brightness.value;
+ varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = v_brightness.value;
+ R_Mesh_Draw(3, 1, polygonelements);
}
- qglEnable(GL_TEXTURE_2D);
- CHECKGLERROR
}
-
- qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- CHECKGLERROR
- qglEnable (GL_CULL_FACE);
- CHECKGLERROR
- qglEnable (GL_DEPTH_TEST);
- CHECKGLERROR
- qglDisable (GL_BLEND);
- CHECKGLERROR
- qglColor4ub (255, 255, 255, 255);
- CHECKGLERROR
+ R_Mesh_Finish();
}
-#endif