]> 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 de052f0f93ed9a8be8f2d0404e297f1177ec7b68..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
@@ -210,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);
@@ -324,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;
+}
+
 
 //==================================================================================
 
@@ -509,14 +606,10 @@ static void R_BlendView(void)
        memset(&m, 0, sizeof(m));
        m.blendfunc1 = GL_SRC_ALPHA;
        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       m.wantoverbright = false;
        m.depthdisable = true; // magic
-       Matrix4x4_CreateIdentity(&m.matrix);
+       R_Mesh_Matrix(&r_identitymatrix);
        R_Mesh_State(&m);
 
-       varray_element[0] = 0;
-       varray_element[1] = 1;
-       varray_element[2] = 2;
        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];
@@ -532,7 +625,7 @@ static void R_BlendView(void)
        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);
+       R_Mesh_Draw(3, 1, polygonelements);
 }
 
 /*
@@ -567,7 +660,12 @@ 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())
@@ -616,11 +714,9 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
        rmeshstate_t m;
        m.blendfunc1 = GL_SRC_ALPHA;
        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       m.wantoverbright = false;
-       Matrix4x4_CreateIdentity(&m.matrix);
+       R_Mesh_Matrix(&r_identitymatrix);
        R_Mesh_State(&m);
 
-       varray_element
        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];
@@ -629,9 +725,9 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
        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 * mesh_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 * mesh_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 * mesh_colorscale;
+       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)
        {
@@ -640,7 +736,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
                        VectorSubtract(v, r_origin, diff);
                        f2 = exp(fogdensity/DotProduct(diff, diff));
                        f1 = 1 - f2;
-                       f2 *= mesh_colorscale;
+                       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;
@@ -653,7 +749,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
 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];
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -672,18 +768,17 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2)
                m.blendfunc1 = GL_ONE;
                m.blendfunc2 = GL_ZERO;
        }
-       m.wantoverbright = false;
-       m.matrix = ent->matrix;
+       R_Mesh_Matrix(&ent->matrix);
        R_Mesh_State(&m);
 
-       varray_element[ 0] = 5;varray_element[ 1] = 2;varray_element[ 2] = 0;
-       varray_element[ 3] = 5;varray_element[ 4] = 1;varray_element[ 5] = 2;
-       varray_element[ 6] = 5;varray_element[ 7] = 0;varray_element[ 8] = 3;
-       varray_element[ 9] = 5;varray_element[10] = 3;varray_element[11] = 1;
-       varray_element[12] = 0;varray_element[13] = 2;varray_element[14] = 4;
-       varray_element[15] = 2;varray_element[16] = 1;varray_element[17] = 4;
-       varray_element[18] = 3;varray_element[19] = 0;varray_element[20] = 4;
-       varray_element[21] = 1;varray_element[22] = 3;varray_element[23] = 4;
+       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;
@@ -703,21 +798,21 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2)
                f1 = 1 - f2;
                for (i = 0, c = varray_color;i < 6;i++, c += 4)
                {
-                       c[0] = (c[0] * f1 + fogcolor[0] * f2) * mesh_colorscale;
-                       c[1] = (c[1] * f1 + fogcolor[1] * f2) * mesh_colorscale;
-                       c[2] = (c[2] * f1 + fogcolor[2] * f2) * mesh_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
        {
                for (i = 0, c = varray_color;i < 6;i++, c += 4)
                {
-                       c[0] *= mesh_colorscale;
-                       c[1] *= mesh_colorscale;
-                       c[2] *= mesh_colorscale;
+                       c[0] *= r_colorscale;
+                       c[1] *= r_colorscale;
+                       c[2] *= r_colorscale;
                }
        }
-       R_Mesh_Draw(6, 8);
+       R_Mesh_Draw(6, 8, element);
 }
 
 void R_DrawNoModel(entity_render_t *ent)