typedef struct buf_mesh_s
{
- //struct buf_mesh_s *next;
int depthmask;
int depthtest;
int blendfunc1, blendfunc2;
int firsttriangle;
int triangles;
int firstvert;
- int lastvert;
+ int verts;
struct buf_mesh_s *chain;
struct buf_transtri_s *transchain;
- //struct buf_transtri_s **transchainpointer;
}
buf_mesh_t;
buf_texcoord_t;
static float meshfarclip;
-static int currentmesh, currenttriangle, currentvertex, backendunits, backendactive, meshmerge, transranout;
+static int currentmesh, currenttriangle, currentvertex, backendunits, backendactive, transranout;
static buf_mesh_t *buf_mesh;
static buf_tri_t *buf_tri;
static buf_vertex_t *buf_vertex;
static int currenttransmesh, currenttransvertex, currenttranstriangle;
static buf_mesh_t *buf_transmesh;
-static buf_transtri_t *buf_transtri;
-static buf_transtri_t **buf_transtri_list;
+static buf_transtri_t *buf_sorttranstri;
+static buf_transtri_t **buf_sorttranstri_list;
+static buf_tri_t *buf_transtri;
static buf_vertex_t *buf_transvertex;
static buf_fcolor_t *buf_transfcolor;
static buf_texcoord_t *buf_transtexcoord[MAX_TEXTUREUNITS];
BACKENDALLOC(buf_bcolor, max_verts, buf_bcolor_t)
BACKENDALLOC(buf_transmesh, max_meshs, buf_mesh_t)
- BACKENDALLOC(buf_transtri, max_meshs, buf_transtri_t)
- BACKENDALLOC(buf_transtri_list, TRANSDEPTHRES, buf_transtri_t *)
+ BACKENDALLOC(buf_sorttranstri, max_meshs, buf_transtri_t)
+ BACKENDALLOC(buf_sorttranstri_list, TRANSDEPTHRES, buf_transtri_t *)
+ BACKENDALLOC(buf_transtri, max_meshs, buf_tri_t)
BACKENDALLOC(buf_transvertex, max_verts, buf_vertex_t)
BACKENDALLOC(buf_transfcolor, max_verts, buf_fcolor_t)
static void gl_backend_shutdown(void)
{
- //int i;
- /*
-#define BACKENDFREE(var)\
- if (var)\
- {\
- Mem_Free(var);\
- var = NULL;\
- }
- */
- /*
-#define BACKENDFREE(var) var = NULL;
-
- BACKENDFREE(buf_mesh)
- BACKENDFREE(buf_tri)
- BACKENDFREE(buf_vertex)
- BACKENDFREE(buf_fcolor)
- BACKENDFREE(buf_bcolor)
-
- BACKENDFREE(buf_transmesh)
- BACKENDFREE(buf_transtri)
- BACKENDFREE(buf_transtri_list)
- BACKENDFREE(buf_transvertex)
- BACKENDFREE(buf_transfcolor)
-
- for (i = 0;i < MAX_TEXTUREUNITS;i++)
- {
- BACKENDFREE(buf_texcoord[i])
- BACKENDFREE(buf_transtexcoord[i])
- }
- */
-
if (resizingbuffers)
Mem_EmptyPool(gl_backend_mempool);
else
// y is weird beause OpenGL is bottom to top, we use top to bottom
glViewport(r_refdef.x, vid.realheight - (r_refdef.y + r_refdef.height), r_refdef.width, r_refdef.height);
// yfov = 2*atan((float)r_refdef.height/r_refdef.width)*180/M_PI;
- MYgluPerspective (r_refdef.fov_x, r_refdef.fov_y, r_refdef.width/r_refdef.height, 4, r_farclip);
+ MYgluPerspective (r_refdef.fov_x, r_refdef.fov_y, r_refdef.width/r_refdef.height, 4.0 / 3.0, r_farclip);
glCullFace(GL_FRONT);
currenttranstriangle = 0;
currenttransvertex = 0;
meshfarclip = 0;
- meshmerge = gl_mesh_merge.integer;
transranout = false;
viewdist = DotProduct(r_origin, vpn);
// renders mesh buffers, called to flush buffers when full
void R_Mesh_Render(void)
{
- int i, k, blendfunc1, blendfunc2, blend, depthmask, depthtest, unit = 0, clientunit = 0, firsttriangle, triangles, firstvert, lastvert, texture[MAX_TEXTUREUNITS];
+ int i, k, blendfunc1, blendfunc2, blend, depthmask, depthtest, unit = 0, clientunit = 0, firsttriangle, endtriangle, indexcount, firstvert, endvert, texture[MAX_TEXTUREUNITS];
float farclip, texturergbscale[MAX_TEXTUREUNITS];
buf_mesh_t *mesh;
unsigned int *index;
glDepthMask((GLboolean) depthmask);
CHECKGLERROR
- glVertexPointer(3, GL_FLOAT, sizeof(buf_vertex_t), buf_vertex);
+ glVertexPointer(3, GL_FLOAT, sizeof(buf_vertex_t), &buf_vertex[0].v[0]);
CHECKGLERROR
glEnableClientState(GL_VERTEX_ARRAY);
CHECKGLERROR
if (gl_mesh_floatcolors.integer)
{
- glColorPointer(4, GL_FLOAT, sizeof(buf_fcolor_t), buf_fcolor);
+ glColorPointer(4, GL_FLOAT, sizeof(buf_fcolor_t), &buf_fcolor[0].c[0]);
CHECKGLERROR
}
else
k = (*icolor++) & 0x7FFFFF;*bcolor++ = k > 255 ? 255 : k;
k = (*icolor++) & 0x7FFFFF;*bcolor++ = k > 255 ? 255 : k;
}
- glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(buf_bcolor_t), buf_bcolor);
+ glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(buf_bcolor_t), &buf_bcolor[0].c[0]);
CHECKGLERROR
}
glEnableClientState(GL_COLOR_ARRAY);
}
firsttriangle = mesh->firsttriangle;
- triangles = mesh->triangles;
firstvert = mesh->firstvert;
- lastvert = mesh->lastvert;
- mesh = &buf_mesh[++k];
+ endtriangle = firsttriangle + mesh->triangles;
+ endvert = firstvert + mesh->verts;
- if (meshmerge)
+ mesh = &buf_mesh[++k];
+ if (gl_mesh_merge.integer)
{
#if MAX_TEXTUREUNITS != 4
#error update this code
#endif
while (k < currentmesh
+ && mesh->firsttriangle == endtriangle
+ && mesh->firstvert == endvert
+ && mesh->depthmask == depthmask
+ && mesh->depthtest == depthtest
&& mesh->blendfunc1 == blendfunc1
&& mesh->blendfunc2 == blendfunc2
- && mesh->depthtest == depthtest
- && mesh->depthmask == depthmask
&& mesh->textures[0] == texture[0]
&& mesh->textures[1] == texture[1]
&& mesh->textures[2] == texture[2]
&& mesh->texturergbscale[2] == texturergbscale[2]
&& mesh->texturergbscale[3] == texturergbscale[3])
{
- triangles += mesh->triangles;
- if (firstvert > mesh->firstvert)
- firstvert = mesh->firstvert;
- if (lastvert < mesh->lastvert)
- lastvert = mesh->lastvert;
+ endtriangle += mesh->triangles;
+ endvert += mesh->verts;
mesh = &buf_mesh[++k];
}
}
+ indexcount = (endtriangle - firsttriangle) * 3;
index = (unsigned int *)&buf_tri[firsttriangle].index[0];
- for (i = 0;i < triangles * 3;i++)
+ for (i = 0;i < indexcount;i++)
index[i] += firstvert;
#ifdef WIN32
// FIXME: dynamic link to GL so we can get DrawRangeElements on WIN32
- glDrawElements(GL_TRIANGLES, triangles * 3, GL_UNSIGNED_INT, index);
+ glDrawElements(GL_TRIANGLES, indexcount, GL_UNSIGNED_INT, index);
#else
- glDrawRangeElements(GL_TRIANGLES, firstvert, lastvert + 1, triangles * 3, GL_UNSIGNED_INT, index);
+ glDrawRangeElements(GL_TRIANGLES, firstvert, endvert, indexcount, GL_UNSIGNED_INT, index);
#endif
CHECKGLERROR
}
void R_Mesh_AddTransparent(void)
{
- int i, j, k;
+ int i, j, k, *index;
float viewdistcompare, centerscaler, dist1, dist2, dist3, center, maxdist;
buf_vertex_t *vert1, *vert2, *vert3;
buf_transtri_t *tri;
if (!currenttransmesh)
return;
- /*
// convert index data to transtris for sorting
- for (i = 0;i < currenttransmesh;i++)
+ for (j = 0;j < currenttransmesh;j++)
{
- mesh = buf_transmesh + i;
- j = mesh->firstvert;
- index = mesh->index;
- for (i = 0;i < mesh->numtriangles;i++)
+ mesh = buf_transmesh + j;
+ k = mesh->firsttriangle;
+ index = &buf_transtri[k].index[0];
+ for (i = 0;i < mesh->triangles;i++)
{
- tri = &buf_transtri[currenttranstriangle++];
+ tri = &buf_sorttranstri[k++];
tri->mesh = mesh;
- tri->index[0] = *index++ + j;
- tri->index[1] = *index++ + j;
- tri->index[2] = *index++ + j;
+ tri->index[0] = *index++;
+ tri->index[1] = *index++;
+ tri->index[2] = *index++;
}
}
- */
// map farclip to 0-4095 list range
centerscaler = (TRANSDEPTHRES / r_farclip) * (1.0f / 3.0f);
viewdistcompare = viewdist + 4.0f;
- memset(buf_transtri_list, 0, TRANSDEPTHRES * sizeof(buf_transtri_t *));
+ memset(buf_sorttranstri_list, 0, TRANSDEPTHRES * sizeof(buf_transtri_t *));
k = 0;
for (j = 0;j < currenttranstriangle;j++)
{
- tri = &buf_transtri[j];
+ tri = &buf_sorttranstri[j];
i = tri->mesh->firstvert;
vert1 = &buf_transvertex[tri->index[0] + i];
i = *((long *)¢er) & 0x7FFFFF;
i = min(i, (TRANSDEPTHRES - 1));
#endif
- tri->next = buf_transtri_list[i];
- buf_transtri_list[i] = tri;
+ tri->next = buf_sorttranstri_list[i];
+ buf_sorttranstri_list[i] = tri;
k++;
}
- if (currentmesh + k > max_meshs || currenttriangle + k > max_batch || currentvertex + currenttransvertex > max_verts)
- R_Mesh_Render();
-
for (i = 0;i < currenttransmesh;i++)
buf_transmesh[i].transchain = NULL;
transmesh = NULL;
for (j = 0;j < TRANSDEPTHRES;j++)
{
- if ((tri = buf_transtri_list[j]))
+ if ((tri = buf_sorttranstri_list[j]))
{
for (;tri;tri = tri->next)
{
for (;transmesh;transmesh = transmesh->chain)
{
- int numverts = transmesh->lastvert - transmesh->firstvert + 1;
- //if (currentmesh >= max_meshs || currenttriangle + transmesh->triangles > max_batch || currentvertex + numverts > max_verts)
- // R_Mesh_Render();
-
- memcpy(&buf_vertex[currentvertex], &buf_transvertex[transmesh->firstvert], numverts * sizeof(buf_vertex_t));
- memcpy(&buf_fcolor[currentvertex], &buf_transfcolor[transmesh->firstvert], numverts * sizeof(buf_fcolor_t));
- for (i = 0;i < backendunits && transmesh->textures[i];i++)
- memcpy(&buf_texcoord[i][currentvertex], &buf_transtexcoord[i][transmesh->firstvert], numverts * sizeof(buf_texcoord_t));
+ if (currentmesh >= max_meshs || currenttriangle + transmesh->triangles > max_batch || currentvertex + transmesh->verts > max_verts)
+ R_Mesh_Render();
mesh = &buf_mesh[currentmesh++];
*mesh = *transmesh; // copy mesh properties
+
mesh->firstvert = currentvertex;
- mesh->lastvert = currentvertex + numverts - 1;
- currentvertex += numverts;
+ memcpy(&buf_vertex[currentvertex], &buf_transvertex[transmesh->firstvert], transmesh->verts * sizeof(buf_vertex_t));
+ memcpy(&buf_fcolor[currentvertex], &buf_transfcolor[transmesh->firstvert], transmesh->verts * sizeof(buf_fcolor_t));
+ for (i = 0;i < backendunits && transmesh->textures[i];i++)
+ memcpy(&buf_texcoord[i][currentvertex], &buf_transtexcoord[i][transmesh->firstvert], transmesh->verts * sizeof(buf_texcoord_t));
+ currentvertex += mesh->verts;
+
mesh->firsttriangle = currenttriangle;
for (tri = transmesh->transchain;tri;tri = tri->meshsortchain)
{
void R_Mesh_Draw(const rmeshinfo_t *m)
{
// these are static because gcc runs out of virtual registers otherwise
- static int i, j, *index, overbright;
+ static int i, j, overbright, *index;
static float *in, scaler;
static float cr, cg, cb, ca;
static buf_mesh_t *mesh;
static buf_vertex_t *vert;
static buf_fcolor_t *fcolor;
static buf_texcoord_t *texcoord[MAX_TEXTUREUNITS];
- static buf_transtri_t *tri;
if (!backendactive)
Sys_Error("R_Mesh_Draw: called when backend is not active\n");
if (!backendactive)
Sys_Error("R_Mesh_Draw: called when backend is not active\n");
- scaler = 1;
- if (m->blendfunc2 == GL_SRC_COLOR)
- {
- if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
- scaler *= 0.5f;
- }
- else
- {
- if (m->tex[0])
- {
- overbright = gl_combine.integer;
- if (overbright)
- scaler *= 0.25f;
- }
- scaler *= overbrightscale;
- }
+#ifdef DEBUGGL
+ for (i = 0;i < m->numtriangles * 3;i++)
+ if ((unsigned int) m->index[i] >= (unsigned int) m->numverts)
+ Host_Error("R_Mesh_Draw: invalid index (%i of %i verts)\n", m->index, m->numverts);
+#endif
if (m->transparent)
{
// transmesh is only for storage of transparent meshs until they
// are inserted into the main mesh array
mesh = &buf_transmesh[currenttransmesh++];
-
- // transparent meshs are broken up into individual triangles which can
- // be sorted by depth
- index = m->index;
- for (i = 0;i < m->numtriangles;i++)
- {
- tri = &buf_transtri[currenttranstriangle++];
- tri->mesh = mesh;
- tri->index[0] = *index++;
- tri->index[1] = *index++;
- tri->index[2] = *index++;
- }
-
+ mesh->firsttriangle = currenttranstriangle;
mesh->firstvert = currenttransvertex;
- mesh->lastvert = currenttransvertex + m->numverts - 1;
+ index = &buf_transtri[currenttranstriangle].index[0];
+
+ currenttranstriangle += m->numtriangles;
currenttransvertex += m->numverts;
}
else
for (i = 0;i < backendunits;i++)
texcoord[i] = &buf_texcoord[i][currentvertex];
- mesh = &buf_mesh[currentmesh++];
// opaque meshs are rendered directly
+ mesh = &buf_mesh[currentmesh++];
mesh->firsttriangle = currenttriangle;
- memcpy(&buf_tri[currenttriangle].index[0], m->index, sizeof(float[3]) * m->numtriangles);
- currenttriangle += m->numtriangles;
-
mesh->firstvert = currentvertex;
- mesh->lastvert = currentvertex + m->numverts - 1;
+ index = &buf_tri[currenttriangle].index[0];
+
+ currenttriangle += m->numtriangles;
currentvertex += m->numverts;
}
// code shared for transparent and opaque meshs
+ memcpy(index, m->index, sizeof(int[3]) * m->numtriangles);
mesh->blendfunc1 = m->blendfunc1;
mesh->blendfunc2 = m->blendfunc2;
mesh->depthmask = (m->blendfunc2 == GL_ZERO || m->depthwrite);
mesh->depthtest = !m->depthdisable;
mesh->triangles = m->numtriangles;
+ mesh->verts = m->numverts;
+
+ overbright = false;
+ scaler = 1;
+ if (m->blendfunc2 == GL_SRC_COLOR)
+ {
+ if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
+ scaler *= 0.5f;
+ }
+ else
+ {
+ if (m->tex[0])
+ {
+ overbright = gl_combine.integer;
+ if (overbright)
+ scaler *= 0.25f;
+ }
+ scaler *= overbrightscale;
+ }
+
+
j = -1;
for (i = 0;i < backendunits;i++)
{
for (;j < backendunits;j++)
memset(&texcoord[j][0].t[0], 0, m->numverts * sizeof(buf_texcoord_t));
#endif
-
- if (currenttriangle >= max_batch)
- R_Mesh_Render();
}
void R_Mesh_Draw_NativeOnly(const rmeshinfo_t *m)
{
// these are static because gcc runs out of virtual registers otherwise
- static int i, j, *index, overbright;
+ static int i, j, overbright, *index;
static float *in, scaler;
static buf_mesh_t *mesh;
static buf_vertex_t *vert;
static buf_fcolor_t *fcolor;
static buf_texcoord_t *texcoord[MAX_TEXTUREUNITS];
- static buf_transtri_t *tri;
if (!backendactive)
Sys_Error("R_Mesh_Draw: called when backend is not active\n");
return;
}
- scaler = 1;
- if (m->blendfunc2 == GL_SRC_COLOR)
- {
- if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
- scaler *= 0.5f;
- }
- else
- {
- if (m->tex[0])
- {
- overbright = gl_combine.integer;
- if (overbright)
- scaler *= 0.25f;
- }
- scaler *= overbrightscale;
- }
-
if (m->transparent)
{
if (currenttransmesh >= max_meshs || (currenttranstriangle + m->numtriangles) > max_meshs || (currenttransvertex + m->numverts) > max_verts)
// transmesh is only for storage of transparent meshs until they
// are inserted into the main mesh array
mesh = &buf_transmesh[currenttransmesh++];
-
- // transparent meshs are broken up into individual triangles which can
- // be sorted by depth
- index = m->index;
- for (i = 0;i < m->numtriangles;i++)
- {
- tri = &buf_transtri[currenttranstriangle++];
- tri->mesh = mesh;
- tri->index[0] = *index++;
- tri->index[1] = *index++;
- tri->index[2] = *index++;
- }
-
+ mesh->firsttriangle = currenttranstriangle;
mesh->firstvert = currenttransvertex;
- mesh->lastvert = currenttransvertex + m->numverts - 1;
+ index = &buf_transtri[currenttranstriangle].index[0];
+ currenttranstriangle += m->numtriangles;
currenttransvertex += m->numverts;
}
else
for (i = 0;i < backendunits;i++)
texcoord[i] = &buf_texcoord[i][currentvertex];
- mesh = &buf_mesh[currentmesh++];
// opaque meshs are rendered directly
+ mesh = &buf_mesh[currentmesh++];
mesh->firsttriangle = currenttriangle;
- memcpy(&buf_tri[currenttriangle].index[0], m->index, sizeof(float[3]) * m->numtriangles);
- currenttriangle += m->numtriangles;
-
mesh->firstvert = currentvertex;
- mesh->lastvert = currentvertex + m->numverts - 1;
+ index = &buf_tri[currenttriangle].index[0];
+ currenttriangle += m->numtriangles;
currentvertex += m->numverts;
}
// code shared for transparent and opaque meshs
+ memcpy(index, m->index, sizeof(int[3]) * m->numtriangles);
mesh->blendfunc1 = m->blendfunc1;
mesh->blendfunc2 = m->blendfunc2;
mesh->depthmask = (m->blendfunc2 == GL_ZERO || m->depthwrite);
mesh->depthtest = !m->depthdisable;
mesh->triangles = m->numtriangles;
+ mesh->verts = m->numverts;
+
+ overbright = false;
+ scaler = 1;
+ if (m->blendfunc2 == GL_SRC_COLOR)
+ {
+ if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
+ scaler *= 0.5f;
+ }
+ else
+ {
+ if (m->tex[0])
+ {
+ overbright = gl_combine.integer;
+ if (overbright)
+ scaler *= 0.25f;
+ }
+ scaler *= overbrightscale;
+ }
+
j = -1;
for (i = 0;i < backendunits;i++)
{
fcolor[i].c[2] *= scaler;
}
}
-
- if (currenttriangle >= max_batch)
- R_Mesh_Render();
}
-/*
-void R_Mesh_Draw_GetBuffer(volatile rmeshinfo_t *m)
+// allocates space in geometry buffers, and fills in pointers to the buffers in passsed struct
+// (this is used for very high speed rendering, no copying)
+int R_Mesh_Draw_GetBuffer(rmeshbufferinfo_t *m)
{
// these are static because gcc runs out of virtual registers otherwise
- static int i, j, *index, overbright;
- static float *in, scaler;
- static buf_transtri_t *tri;
+ int i, j, overbright;
+ float scaler;
+ buf_mesh_t *mesh;
if (!backendactive)
Sys_Error("R_Mesh_Draw: called when backend is not active\n");
|| !m->numverts)
Host_Error("R_Mesh_Draw: no triangles or verts\n");
- scaler = 1;
- if (m->blendfunc2 == GL_SRC_COLOR)
- {
- if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
- scaler *= 0.5f;
- }
- else
- {
- if (m->tex[0])
- {
- overbright = gl_combine.integer;
- if (overbright)
- scaler *= 0.25f;
- }
- scaler *= overbrightscale;
- }
-
if (m->transparent)
{
if (currenttransmesh >= max_meshs || (currenttranstriangle + m->numtriangles) > max_meshs || (currenttransvertex + m->numverts) > max_verts)
Con_Printf("R_Mesh_Draw: ran out of room for transparent meshs\n");
transranout = true;
}
- return;
+ return false;
}
c_transmeshs++;
c_transtris += m->numtriangles;
+ m->index = &buf_transtri[currenttranstriangle].index[0];
m->vertex = &buf_transvertex[currenttransvertex].v[0];
m->color = &buf_transfcolor[currenttransvertex].c[0];
for (i = 0;i < backendunits;i++)
- m->texcoords[i] = &buf_transtexcoord[i][currenttransvertex].tc[0];
+ m->texcoords[i] = &buf_transtexcoord[i][currenttransvertex].t[0];
// transmesh is only for storage of transparent meshs until they
// are inserted into the main mesh array
mesh = &buf_transmesh[currenttransmesh++];
-
- // transparent meshs are broken up into individual triangles which can
- // be sorted by depth
- index = m->index;
- for (i = 0;i < m->numtriangles;i++)
- {
- tri = &buf_transtri[currenttranstriangle++];
- tri->mesh = mesh;
- tri->index[0] = *index++;
- tri->index[1] = *index++;
- tri->index[2] = *index++;
- }
-
+ mesh->firsttriangle = currenttranstriangle;
mesh->firstvert = currenttransvertex;
- mesh->lastvert = currenttransvertex + m->numverts - 1;
+ currenttranstriangle += m->numtriangles;
currenttransvertex += m->numverts;
}
else
{
if (m->numtriangles > max_meshs || m->numverts > max_verts)
{
- Con_Printf("R_Mesh_Draw_NativeOnly: mesh too big for buffers\n");
- return;
+ Con_Printf("R_Mesh_Draw_GetBuffer: mesh too big for buffers\n");
+ return false;
}
if (currentmesh >= max_meshs || (currenttriangle + m->numtriangles) > max_batch || (currentvertex + m->numverts) > max_verts)
c_meshs++;
c_meshtris += m->numtriangles;
- vert = &buf_vertex[currentvertex];
- fcolor = &buf_fcolor[currentvertex];
+ m->index = &buf_tri[currenttriangle].index[0];
+ m->vertex = &buf_vertex[currentvertex].v[0];
+ m->color = &buf_fcolor[currentvertex].c[0];
for (i = 0;i < backendunits;i++)
- texcoord[i] = &buf_texcoord[i][currentvertex];
+ m->texcoords[i] = &buf_texcoord[i][currentvertex].t[0];
- mesh = &buf_mesh[currentmesh++];
// opaque meshs are rendered directly
+ mesh = &buf_mesh[currentmesh++];
mesh->firsttriangle = currenttriangle;
- memcpy(&buf_tri[currenttriangle].index[0], m->index, sizeof(float[3]) * m->numtriangles);
- currenttriangle += m->numtriangles;
-
mesh->firstvert = currentvertex;
- mesh->lastvert = currentvertex + m->numverts - 1;
+ currenttriangle += m->numtriangles;
currentvertex += m->numverts;
}
mesh->depthmask = (m->blendfunc2 == GL_ZERO || m->depthwrite);
mesh->depthtest = !m->depthdisable;
mesh->triangles = m->numtriangles;
+ mesh->verts = m->numverts;
+
+ overbright = false;
+ scaler = 1;
+ if (m->blendfunc2 == GL_SRC_COLOR)
+ {
+ if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
+ scaler *= 0.5f;
+ }
+ else
+ {
+ if (m->tex[0])
+ {
+ overbright = gl_combine.integer;
+ if (overbright)
+ scaler *= 0.25f;
+ }
+ scaler *= overbrightscale;
+ }
+ m->colorscale = scaler;
+
j = -1;
- for (i = 0;i < backendunits;i++)
+ for (i = 0;i < MAX_TEXTUREUNITS;i++)
{
if ((mesh->textures[i] = m->tex[i]))
+ {
j = i;
+ if (i >= backendunits)
+ Sys_Error("R_Mesh_Draw_GetBuffer: texture %i supplied when there are only %i texture units\n", j + 1, backendunits);
+ }
mesh->texturergbscale[i] = m->texrgbscale[i];
if (mesh->texturergbscale[i] != 1 && mesh->texturergbscale[i] != 2 && mesh->texturergbscale[i] != 4)
mesh->texturergbscale[i] = 1;
if (overbright && j >= 0)
mesh->texturergbscale[j] = 4;
- if (m->vertexstep != sizeof(buf_vertex_t))
- Host_Error("R_Mesh_Draw_NativeOnly: unsupported vertexstep\n");
- if (m->colorstep != sizeof(buf_fcolor_t))
- Host_Error("R_Mesh_Draw_NativeOnly: unsupported colorstep\n");
- if (m->color == NULL)
- Host_Error("R_Mesh_Draw_NativeOnly: must provide color array\n");
- for (j = 0;j < MAX_TEXTUREUNITS && m->tex[j];j++)
- {
- if (j >= backendunits)
- Sys_Error("R_Mesh_Draw_NativeOnly: texture %i supplied when there are only %i texture units\n", j + 1, backendunits);
- if (m->texcoordstep[j] != sizeof(buf_texcoord_t))
- Host_Error("R_Mesh_Draw_NativeOnly: unsupported texcoordstep\n");
- }
-
- memcpy(vert, m->vertex, m->numverts * sizeof(buf_vertex_t));
- for (j = 0;j < MAX_TEXTUREUNITS && m->tex[j];j++)
- memcpy(&texcoord[j][0].t[0], m->texcoords[j], m->numverts * sizeof(buf_texcoord_t));
- #if 0
- for (;j < backendunits;j++)
- memset(&texcoord[j][0].t[0], 0, m->numverts * sizeof(buf_texcoord_t));
- #endif
-
- memcpy(fcolor, m->color, m->numverts * sizeof(buf_fcolor_t));
-
- // do this as a second step because memcpy preloaded the cache, which we can't easily do
- if (scaler != 1)
- {
- for (i = 0;i < m->numverts;i++)
- {
- fcolor[i].c[0] *= scaler;
- fcolor[i].c[1] *= scaler;
- fcolor[i].c[2] *= scaler;
- }
- }
-
- if (currenttriangle >= max_batch)
- R_Mesh_Render();
+ return true;
}
-*/
void R_Mesh_DrawPolygon(rmeshinfo_t *m, int numverts)
{
R_Mesh_Draw(m);
}
-// LordHavoc: this thing is evil, but necessary because decals account for so much overhead
-void R_Mesh_DrawDecal(const rmeshinfo_t *m)
-{
- // these are static because gcc runs out of virtual registers otherwise
- static int i, *index, overbright;
- static float scaler;
- static float cr, cg, cb, ca;
- static buf_mesh_t *mesh;
- static buf_vertex_t *vert;
- static buf_fcolor_t *fcolor;
- static buf_texcoord_t *texcoord;
- static buf_transtri_t *tri;
-
- if (!backendactive)
- Sys_Error("R_Mesh_Draw: called when backend is not active\n");
-
- scaler = 1;
- if (m->tex[0])
- {
- overbright = gl_combine.integer;
- if (overbright)
- scaler *= 0.25f;
- }
- scaler *= overbrightscale;
-
- if (m->transparent)
- {
- if (currenttransmesh >= max_meshs || (currenttranstriangle + 2) > max_meshs || (currenttransvertex + 4) > max_verts)
- {
- if (!transranout)
- {
- Con_Printf("R_Mesh_Draw: ran out of room for transparent meshs\n");
- transranout = true;
- }
- return;
- }
-
- c_transmeshs++;
- c_transtris += 2;
- vert = &buf_transvertex[currenttransvertex];
- fcolor = &buf_transfcolor[currenttransvertex];
- texcoord = &buf_transtexcoord[0][currenttransvertex];
-
- // transmesh is only for storage of transparent meshs until they
- // are inserted into the main mesh array
- mesh = &buf_transmesh[currenttransmesh++];
- mesh->blendfunc1 = m->blendfunc1;
- mesh->blendfunc2 = m->blendfunc2;
- mesh->depthmask = false;
- mesh->depthtest = true;
- mesh->triangles = 2;
- mesh->textures[0] = m->tex[0];
- mesh->texturergbscale[0] = overbright ? 4 : 1;
- for (i = 1;i < backendunits;i++)
- {
- mesh->textures[i] = 0;
- mesh->texturergbscale[i] = 1;
- }
- mesh->chain = NULL;
-
- // transparent meshs are broken up into individual triangles which can
- // be sorted by depth
- index = m->index;
- tri = &buf_transtri[currenttranstriangle++];
- tri->mesh = mesh;
- tri->index[0] = 0;
- tri->index[1] = 1;
- tri->index[2] = 2;
- tri = &buf_transtri[currenttranstriangle++];
- tri->mesh = mesh;
- tri->index[0] = 0;
- tri->index[1] = 2;
- tri->index[2] = 3;
-
- mesh->firstvert = currenttransvertex;
- mesh->lastvert = currenttransvertex + 3;
- currenttransvertex += 4;
- }
- else
- {
- if (2 > max_meshs || 4 > max_verts)
- {
- Con_Printf("R_Mesh_Draw: mesh too big for buffers\n");
- return;
- }
-
- if (currentmesh >= max_meshs || (currenttriangle + 2) > max_batch || (currentvertex + 4) > max_verts)
- R_Mesh_Render();
-
- c_meshs++;
- c_meshtris += 2;
- vert = &buf_vertex[currentvertex];
- fcolor = &buf_fcolor[currentvertex];
- texcoord = &buf_texcoord[0][currentvertex];
-
- mesh = &buf_mesh[currentmesh++];
- mesh->blendfunc1 = m->blendfunc1;
- mesh->blendfunc2 = m->blendfunc2;
- mesh->depthmask = false;
- mesh->depthtest = !m->depthdisable;
- mesh->firsttriangle = currenttriangle;
- mesh->triangles = 2;
- mesh->textures[0] = m->tex[0];
- mesh->texturergbscale[0] = overbright ? 4 : 1;
- for (i = 1;i < backendunits;i++)
- {
- mesh->textures[i] = 0;
- mesh->texturergbscale[i] = 1;
- }
-
- // opaque meshs are rendered directly
- index = &buf_tri[currenttriangle].index[0];
- index[0] = 0;
- index[1] = 1;
- index[2] = 2;
- index[3] = 0;
- index[4] = 2;
- index[5] = 3;
- mesh->firstvert = currentvertex;
- mesh->lastvert = currentvertex + 3;
- currenttriangle += 2;
- currentvertex += 4;
- }
-
- // buf_vertex_t must match the size of the decal vertex array (or vice versa)
- memcpy(vert, m->vertex, 4 * sizeof(buf_vertex_t));
-
- cr = m->cr * scaler;
- cg = m->cg * scaler;
- cb = m->cb * scaler;
- ca = m->ca;
- fcolor[0].c[0] = cr;
- fcolor[0].c[1] = cg;
- fcolor[0].c[2] = cb;
- fcolor[0].c[3] = ca;
- fcolor[1].c[0] = cr;
- fcolor[1].c[1] = cg;
- fcolor[1].c[2] = cb;
- fcolor[1].c[3] = ca;
- fcolor[2].c[0] = cr;
- fcolor[2].c[1] = cg;
- fcolor[2].c[2] = cb;
- fcolor[2].c[3] = ca;
- fcolor[3].c[0] = cr;
- fcolor[3].c[1] = cg;
- fcolor[3].c[2] = cb;
- fcolor[3].c[3] = ca;
-
- // buf_texcoord_t must be the same size as the decal texcoord array (or vice versa)
- memcpy(&texcoord[0].t[0], m->texcoords[0], 4 * sizeof(buf_texcoord_t));
-
- if (currenttriangle >= max_batch)
- R_Mesh_Render();
-}
-
/*
==============================================================================