]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
colors for DrawQ_Mesh are now float rather than byte, and vertices are padded to...
[xonotic/darkplaces.git] / gl_rmain.c
index b16a2bda9d66f3d0f51518fa74c030e928e3b219..0b21178968aac487bc607e33519b039d29a1e428 100644 (file)
@@ -26,6 +26,8 @@ int r_framecount;
 
 mplane_t frustum[4];
 
+matrix4x4_t r_identitymatrix;
+
 int c_alias_polys, c_light_polys, c_faces, c_nodes, c_leafs, c_models, c_bmodels, c_sprites, c_particles, c_dlights;
 
 // true during envmap command capture
@@ -121,8 +123,6 @@ static void R_TimeRefresh_f (void)
        Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
 }
 
-extern cvar_t r_drawportals;
-
 vec3_t fogcolor;
 vec_t fogdensity;
 float fog_density, fog_red, fog_green, fog_blue;
@@ -212,6 +212,7 @@ void gl_main_newmap(void)
 
 void GL_Main_Init(void)
 {
+       Matrix4x4_CreateIdentity(&r_identitymatrix);
 // FIXME: move this to client?
        FOG_registercvars();
        Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
@@ -326,6 +327,100 @@ void GL_Init (void)
        qglEnable(GL_TEXTURE_2D);
 }
 
+int R_CullBox(const vec3_t emins, const vec3_t emaxs)
+{
+       int i;
+       mplane_t *p;
+       for (i = 0;i < 4;i++)
+       {
+               p = frustum + i;
+               switch(p->signbits)
+               {
+               default:
+               case 0:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return true;
+                       break;
+               case 1:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return true;
+                       break;
+               case 2:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return true;
+                       break;
+               case 3:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return true;
+                       break;
+               case 4:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2] < p->dist)
+                               return true;
+                       break;
+               case 5:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2] < p->dist)
+                               return true;
+                       break;
+               case 6:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2] < p->dist)
+                               return true;
+                       break;
+               case 7:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2] < p->dist)
+                               return true;
+                       break;
+               }
+       }
+       return false;
+}
+
+int R_NotCulledBox(const vec3_t emins, const vec3_t emaxs)
+{
+       int i;
+       mplane_t *p;
+       for (i = 0;i < 4;i++)
+       {
+               p = frustum + i;
+               switch(p->signbits)
+               {
+               default:
+               case 0:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return false;
+                       break;
+               case 1:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return false;
+                       break;
+               case 2:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return false;
+                       break;
+               case 3:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2] < p->dist)
+                               return false;
+                       break;
+               case 4:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2] < p->dist)
+                               return false;
+                       break;
+               case 5:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2] < p->dist)
+                               return false;
+                       break;
+               case 6:
+                       if (p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2] < p->dist)
+                               return false;
+                       break;
+               case 7:
+                       if (p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2] < p->dist)
+                               return false;
+                       break;
+               }
+       }
+       return true;
+}
+
 
 //==================================================================================
 
@@ -401,6 +496,28 @@ int R_DrawBrushModelsSky (void)
        return sky;
 }
 
+/*
+=============
+R_DrawViewModel
+=============
+*/
+void R_DrawViewModel (void)
+{
+       entity_render_t *ent;
+
+       // FIXME: move these checks to client
+       if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
+               return;
+
+       ent = &cl.viewent.render;
+       Mod_CheckLoaded(ent->model);
+       R_LerpAnimation(ent);
+       Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], -ent->angles[0], ent->angles[1], ent->angles[2], ent->scale);
+       Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
+       R_UpdateEntLights(ent);
+       ent->model->Draw(ent);
+}
+
 void R_DrawNoModel(entity_render_t *ent);
 void R_DrawModels (void)
 {
@@ -410,6 +527,7 @@ void R_DrawModels (void)
        if (!r_drawentities.integer)
                return;
 
+       R_DrawViewModel();
        for (i = 0;i < r_refdef.numentities;i++)
        {
                ent = r_refdef.entities[i];
@@ -426,28 +544,6 @@ void R_DrawModels (void)
        }
 }
 
-/*
-=============
-R_DrawViewModel
-=============
-*/
-void R_DrawViewModel (void)
-{
-       entity_render_t *ent;
-
-       // FIXME: move these checks to client
-       if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
-               return;
-
-       ent = &cl.viewent.render;
-       Mod_CheckLoaded(ent->model);
-       R_LerpAnimation(ent);
-       Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], -ent->angles[0], ent->angles[1], ent->angles[2], ent->scale);
-       Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
-       R_UpdateEntLights(ent);
-       ent->model->Draw(ent);
-}
-
 static void R_SetFrustum (void)
 {
        int i;
@@ -501,7 +597,7 @@ static void R_SetupFrame (void)
 
 static void R_BlendView(void)
 {
-       rmeshbufferinfo_t m;
+       rmeshstate_t m;
        float r;
 
        if (r_refdef.viewblend[3] < 0.01f)
@@ -511,31 +607,25 @@ static void R_BlendView(void)
        m.blendfunc1 = GL_SRC_ALPHA;
        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
        m.depthdisable = true; // magic
-       m.numtriangles = 1;
-       m.numverts = 3;
-       Matrix4x4_CreateIdentity(&m.matrix);
-       if (R_Mesh_Draw_GetBuffer(&m, false))
-       {
-               m.index[0] = 0;
-               m.index[1] = 1;
-               m.index[2] = 2;
-               m.color[0] = m.color[4] = m.color[8] = r_refdef.viewblend[0];
-               m.color[1] = m.color[5] = m.color[9] = r_refdef.viewblend[1];
-               m.color[2] = m.color[6] = m.color[10] = r_refdef.viewblend[2];
-               m.color[3] = m.color[7] = m.color[11] = r_refdef.viewblend[3];
-               r = 64000;
-               m.vertex[0] = r_origin[0] + vpn[0] * 1.5 - vright[0] * r - vup[0] * r;
-               m.vertex[1] = r_origin[1] + vpn[1] * 1.5 - vright[1] * r - vup[1] * r;
-               m.vertex[2] = r_origin[2] + vpn[2] * 1.5 - vright[2] * r - vup[2] * r;
-               r *= 3;
-               m.vertex[4] = m.vertex[0] + vup[0] * r;
-               m.vertex[5] = m.vertex[1] + vup[1] * r;
-               m.vertex[6] = m.vertex[2] + vup[2] * r;
-               m.vertex[8] = m.vertex[0] + vright[0] * r;
-               m.vertex[9] = m.vertex[1] + vright[1] * r;
-               m.vertex[10] = m.vertex[2] + vright[2] * r;
-               R_Mesh_Render();
-       }
+       R_Mesh_Matrix(&r_identitymatrix);
+       R_Mesh_State(&m);
+
+       varray_color[0] = varray_color[4] = varray_color[8] = r_refdef.viewblend[0];
+       varray_color[1] = varray_color[5] = varray_color[9] = r_refdef.viewblend[1];
+       varray_color[2] = varray_color[6] = varray_color[10] = r_refdef.viewblend[2];
+       varray_color[3] = varray_color[7] = varray_color[11] = r_refdef.viewblend[3];
+       r = 64000;
+       varray_vertex[0] = r_origin[0] + vpn[0] * 1.5 - vright[0] * r - vup[0] * r;
+       varray_vertex[1] = r_origin[1] + vpn[1] * 1.5 - vright[1] * r - vup[1] * r;
+       varray_vertex[2] = r_origin[2] + vpn[2] * 1.5 - vright[2] * r - vup[2] * r;
+       r *= 3;
+       varray_vertex[4] = varray_vertex[0] + vup[0] * r;
+       varray_vertex[5] = varray_vertex[1] + vup[1] * r;
+       varray_vertex[6] = varray_vertex[2] + vup[2] * r;
+       varray_vertex[8] = varray_vertex[0] + vright[0] * r;
+       varray_vertex[9] = varray_vertex[1] + vright[1] * r;
+       varray_vertex[10] = varray_vertex[2] + vright[2] * r;
+       R_Mesh_Draw(3, 1, polygonelements);
 }
 
 /*
@@ -570,41 +660,25 @@ void R_RenderView (void)
        r_farclip = R_FarClip_Finish() + 256.0f;
        R_TimeReport("markentity");
 
-       R_Mesh_Start(r_farclip);
+       GL_SetupView_ViewPort(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
+       GL_SetupView_Mode_Perspective((double) r_refdef.height / r_refdef.width, r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip);
+       GL_SetupView_Orientation_FromEntity (r_refdef.vieworg, r_refdef.viewangles);
+       GL_DepthFunc(GL_LEQUAL);
+       
+       R_Mesh_Start();
        R_MeshQueue_BeginScene();
 
        if (R_DrawBrushModelsSky())
                R_TimeReport("bmodelsky");
 
-       if (world->model)
-       {
-               R_DrawWorld(world);
-               R_TimeReport("worldnode");
-
-               R_SurfMarkLights(world);
-               R_TimeReport("marklights");
-
-               R_PrepareSurfaces(world);
-               R_TimeReport("surfprep");
-
-               R_DrawSurfaces(world, SHADERSTAGE_SKY);
-               R_DrawSurfaces(world, SHADERSTAGE_NORMAL);
-               R_TimeReport("surfdraw");
-
-               if (r_drawportals.integer)
-               {
-                       R_DrawPortals(world);
-                       R_TimeReport("portals");
-               }
-       }
+       // must occur early because it can draw sky
+       R_DrawWorld(world);
+       R_TimeReport("world");
 
        // don't let sound skip if going slow
        if (!intimerefresh && !r_speeds.integer)
                S_ExtraUpdate ();
 
-       R_DrawViewModel();
-       R_TimeReport("viewmodel");
-
        R_DrawModels();
        R_TimeReport("models");
 
@@ -615,7 +689,7 @@ void R_RenderView (void)
        R_TimeReport("explosions");
 
        R_MeshQueue_RenderTransparent();
-       R_TimeReport("addtrans");
+       R_TimeReport("drawtrans");
 
        R_DrawCoronas();
        R_TimeReport("coronas");
@@ -632,53 +706,52 @@ void R_RenderView (void)
        R_TimeReport("meshfinish");
 }
 
+/*
 void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, float ca)
 {
        int i;
        float *v, *c, f1, f2, diff[3];
-       rmeshbufferinfo_t m;
-       m.numtriangles = 12;
-       m.numverts = 8;
+       rmeshstate_t m;
        m.blendfunc1 = GL_SRC_ALPHA;
        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       Matrix4x4_CreateIdentity(&m.matrix);
-       if (R_Mesh_Draw_GetBuffer(&m, false))
+       R_Mesh_Matrix(&r_identitymatrix);
+       R_Mesh_State(&m);
+
+       varray_vertex[ 0] = mins[0];varray_vertex[ 1] = mins[1];varray_vertex[ 2] = mins[2];
+       varray_vertex[ 4] = maxs[0];varray_vertex[ 5] = mins[1];varray_vertex[ 6] = mins[2];
+       varray_vertex[ 8] = mins[0];varray_vertex[ 9] = maxs[1];varray_vertex[10] = mins[2];
+       varray_vertex[12] = maxs[0];varray_vertex[13] = maxs[1];varray_vertex[14] = mins[2];
+       varray_vertex[16] = mins[0];varray_vertex[17] = mins[1];varray_vertex[18] = maxs[2];
+       varray_vertex[20] = maxs[0];varray_vertex[21] = mins[1];varray_vertex[22] = maxs[2];
+       varray_vertex[24] = mins[0];varray_vertex[25] = maxs[1];varray_vertex[26] = maxs[2];
+       varray_vertex[28] = maxs[0];varray_vertex[29] = maxs[1];varray_vertex[30] = maxs[2];
+       varray_color[ 0] = varray_color[ 4] = varray_color[ 8] = varray_color[12] = varray_color[16] = varray_color[20] = varray_color[24] = varray_color[28] = cr * r_colorscale;
+       varray_color[ 1] = varray_color[ 5] = varray_color[ 9] = varray_color[13] = varray_color[17] = varray_color[21] = varray_color[25] = varray_color[29] = cg * r_colorscale;
+       varray_color[ 2] = varray_color[ 6] = varray_color[10] = varray_color[14] = varray_color[18] = varray_color[22] = varray_color[26] = varray_color[30] = cb * r_colorscale;
+       varray_color[ 3] = varray_color[ 7] = varray_color[11] = varray_color[15] = varray_color[19] = varray_color[23] = varray_color[27] = varray_color[31] = ca;
+       if (fogenabled)
        {
-               m.vertex[ 0] = mins[0];m.vertex[ 1] = mins[1];m.vertex[ 2] = mins[2];
-               m.vertex[ 4] = maxs[0];m.vertex[ 5] = mins[1];m.vertex[ 6] = mins[2];
-               m.vertex[ 8] = mins[0];m.vertex[ 9] = maxs[1];m.vertex[10] = mins[2];
-               m.vertex[12] = maxs[0];m.vertex[13] = maxs[1];m.vertex[14] = mins[2];
-               m.vertex[16] = mins[0];m.vertex[17] = mins[1];m.vertex[18] = maxs[2];
-               m.vertex[20] = maxs[0];m.vertex[21] = mins[1];m.vertex[22] = maxs[2];
-               m.vertex[24] = mins[0];m.vertex[25] = maxs[1];m.vertex[26] = maxs[2];
-               m.vertex[28] = maxs[0];m.vertex[29] = maxs[1];m.vertex[30] = maxs[2];
-               m.color[ 0] = m.color[ 4] = m.color[ 8] = m.color[12] = m.color[16] = m.color[20] = m.color[24] = m.color[28] = cr * m.colorscale;
-               m.color[ 1] = m.color[ 5] = m.color[ 9] = m.color[13] = m.color[17] = m.color[21] = m.color[25] = m.color[29] = cg * m.colorscale;
-               m.color[ 2] = m.color[ 6] = m.color[10] = m.color[14] = m.color[18] = m.color[22] = m.color[26] = m.color[30] = cb * m.colorscale;
-               m.color[ 3] = m.color[ 7] = m.color[11] = m.color[15] = m.color[19] = m.color[23] = m.color[27] = m.color[31] = ca;
-               if (fogenabled)
+               for (i = 0, v = varray_vertex, c = varray_color;i < 8;i++, v += 4, c += 4)
                {
-                       for (i = 0, v = m.vertex, c = m.color;i < m.numverts;i++, v += 4, c += 4)
-                       {
-                               VectorSubtract(v, r_origin, diff);
-                               f2 = exp(fogdensity/DotProduct(diff, diff));
-                               f1 = 1 - f2;
-                               f2 *= m.colorscale;
-                               c[0] = c[0] * f1 + fogcolor[0] * f2;
-                               c[1] = c[1] * f1 + fogcolor[1] * f2;
-                               c[2] = c[2] * f1 + fogcolor[2] * f2;
-                       }
+                       VectorSubtract(v, r_origin, diff);
+                       f2 = exp(fogdensity/DotProduct(diff, diff));
+                       f1 = 1 - f2;
+                       f2 *= r_colorscale;
+                       c[0] = c[0] * f1 + fogcolor[0] * f2;
+                       c[1] = c[1] * f1 + fogcolor[1] * f2;
+                       c[2] = c[2] * f1 + fogcolor[2] * f2;
                }
-               R_Mesh_Render();
        }
+       R_Mesh_Draw(8, 12);
 }
+*/
 
 void R_DrawNoModelCallback(const void *calldata1, int calldata2)
 {
        const entity_render_t *ent = calldata1;
-       int i;
+       int i, element[24];
        float f1, f2, *c, diff[3];
-       rmeshbufferinfo_t m;
+       rmeshstate_t m;
        memset(&m, 0, sizeof(m));
        if (ent->flags & EF_ADDITIVE)
        {
@@ -695,54 +768,51 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2)
                m.blendfunc1 = GL_ONE;
                m.blendfunc2 = GL_ZERO;
        }
-       m.numtriangles = 8;
-       m.numverts = 6;
-       m.matrix = ent->matrix;
-       if (R_Mesh_Draw_GetBuffer(&m, false))
+       R_Mesh_Matrix(&ent->matrix);
+       R_Mesh_State(&m);
+
+       element[ 0] = 5;element[ 1] = 2;element[ 2] = 0;
+       element[ 3] = 5;element[ 4] = 1;element[ 5] = 2;
+       element[ 6] = 5;element[ 7] = 0;element[ 8] = 3;
+       element[ 9] = 5;element[10] = 3;element[11] = 1;
+       element[12] = 0;element[13] = 2;element[14] = 4;
+       element[15] = 2;element[16] = 1;element[17] = 4;
+       element[18] = 3;element[19] = 0;element[20] = 4;
+       element[21] = 1;element[22] = 3;element[23] = 4;
+       varray_vertex[ 0] = -16;varray_vertex[ 1] =   0;varray_vertex[ 2] =   0;
+       varray_vertex[ 4] =  16;varray_vertex[ 5] =   0;varray_vertex[ 6] =   0;
+       varray_vertex[ 8] =   0;varray_vertex[ 9] = -16;varray_vertex[10] =   0;
+       varray_vertex[12] =   0;varray_vertex[13] =  16;varray_vertex[14] =   0;
+       varray_vertex[16] =   0;varray_vertex[17] =   0;varray_vertex[18] = -16;
+       varray_vertex[20] =   0;varray_vertex[21] =   0;varray_vertex[22] =  16;
+       varray_color[ 0] = 0.00f;varray_color[ 1] = 0.00f;varray_color[ 2] = 0.50f;varray_color[ 3] = ent->alpha;
+       varray_color[ 4] = 0.00f;varray_color[ 5] = 0.00f;varray_color[ 6] = 0.50f;varray_color[ 7] = ent->alpha;
+       varray_color[ 8] = 0.00f;varray_color[ 9] = 0.50f;varray_color[10] = 0.00f;varray_color[11] = ent->alpha;
+       varray_color[12] = 0.00f;varray_color[13] = 0.50f;varray_color[14] = 0.00f;varray_color[15] = ent->alpha;
+       varray_color[16] = 0.50f;varray_color[17] = 0.00f;varray_color[18] = 0.00f;varray_color[19] = ent->alpha;
+       varray_color[20] = 0.50f;varray_color[21] = 0.00f;varray_color[22] = 0.00f;varray_color[23] = ent->alpha;
+       if (fogenabled)
        {
-               m.index[ 0] = 5;m.index[ 1] = 2;m.index[ 2] = 0;
-               m.index[ 3] = 5;m.index[ 4] = 1;m.index[ 5] = 2;
-               m.index[ 6] = 5;m.index[ 7] = 0;m.index[ 8] = 3;
-               m.index[ 9] = 5;m.index[10] = 3;m.index[11] = 1;
-               m.index[12] = 0;m.index[13] = 2;m.index[14] = 4;
-               m.index[15] = 2;m.index[16] = 1;m.index[17] = 4;
-               m.index[18] = 3;m.index[19] = 0;m.index[20] = 4;
-               m.index[21] = 1;m.index[22] = 3;m.index[23] = 4;
-               m.vertex[ 0] = -16;m.vertex[ 1] =   0;m.vertex[ 2] =   0;
-               m.vertex[ 4] =  16;m.vertex[ 5] =   0;m.vertex[ 6] =   0;
-               m.vertex[ 8] =   0;m.vertex[ 9] = -16;m.vertex[10] =   0;
-               m.vertex[12] =   0;m.vertex[13] =  16;m.vertex[14] =   0;
-               m.vertex[16] =   0;m.vertex[17] =   0;m.vertex[18] = -16;
-               m.vertex[20] =   0;m.vertex[21] =   0;m.vertex[22] =  16;
-               m.color[ 0] = 0.00f;m.color[ 1] = 0.00f;m.color[ 2] = 0.50f;m.color[ 3] = ent->alpha;
-               m.color[ 4] = 0.00f;m.color[ 5] = 0.00f;m.color[ 6] = 0.50f;m.color[ 7] = ent->alpha;
-               m.color[ 8] = 0.00f;m.color[ 9] = 0.50f;m.color[10] = 0.00f;m.color[11] = ent->alpha;
-               m.color[12] = 0.00f;m.color[13] = 0.50f;m.color[14] = 0.00f;m.color[15] = ent->alpha;
-               m.color[16] = 0.50f;m.color[17] = 0.00f;m.color[18] = 0.00f;m.color[19] = ent->alpha;
-               m.color[20] = 0.50f;m.color[21] = 0.00f;m.color[22] = 0.00f;m.color[23] = ent->alpha;
-               if (fogenabled)
+               VectorSubtract(ent->origin, r_origin, diff);
+               f2 = exp(fogdensity/DotProduct(diff, diff));
+               f1 = 1 - f2;
+               for (i = 0, c = varray_color;i < 6;i++, c += 4)
                {
-                       VectorSubtract(ent->origin, r_origin, diff);
-                       f2 = exp(fogdensity/DotProduct(diff, diff));
-                       f1 = 1 - f2;
-                       for (i = 0, c = m.color;i < m.numverts;i++, c += 4)
-                       {
-                               c[0] = (c[0] * f1 + fogcolor[0] * f2) * m.colorscale;
-                               c[1] = (c[1] * f1 + fogcolor[1] * f2) * m.colorscale;
-                               c[2] = (c[2] * f1 + fogcolor[2] * f2) * m.colorscale;
-                       }
+                       c[0] = (c[0] * f1 + fogcolor[0] * f2) * r_colorscale;
+                       c[1] = (c[1] * f1 + fogcolor[1] * f2) * r_colorscale;
+                       c[2] = (c[2] * f1 + fogcolor[2] * f2) * r_colorscale;
                }
-               else
+       }
+       else
+       {
+               for (i = 0, c = varray_color;i < 6;i++, c += 4)
                {
-                       for (i = 0, c = m.color;i < m.numverts;i++, c += 4)
-                       {
-                               c[0] *= m.colorscale;
-                               c[1] *= m.colorscale;
-                               c[2] *= m.colorscale;
-                       }
+                       c[0] *= r_colorscale;
+                       c[1] *= r_colorscale;
+                       c[2] *= r_colorscale;
                }
-               R_Mesh_Render();
        }
+       R_Mesh_Draw(6, 8, element);
 }
 
 void R_DrawNoModel(entity_render_t *ent)