]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
bmodel shadow volumes
[xonotic/darkplaces.git] / gl_rmain.c
index 5552b0cb0140034245e448b2e14ef2e81c61b5d0..184af30762a74bfc542b9030c7d46d5521a99612 100644 (file)
@@ -51,6 +51,7 @@ unsigned short d_lightstylevalue[256];
 
 cvar_t r_drawentities = {0, "r_drawentities","1"};
 cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
+cvar_t r_shadows = {CVAR_SAVE, "r_shadows", "1"};
 cvar_t r_speeds = {0, "r_speeds","0"};
 cvar_t r_fullbright = {0, "r_fullbright","0"};
 cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
@@ -218,6 +219,7 @@ void GL_Main_Init(void)
        Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
        Cvar_RegisterVariable (&r_drawentities);
        Cvar_RegisterVariable (&r_drawviewmodel);
+       Cvar_RegisterVariable (&r_shadows);
        Cvar_RegisterVariable (&r_speeds);
        Cvar_RegisterVariable (&r_fullbrights);
        Cvar_RegisterVariable (&r_wateralpha);
@@ -280,6 +282,7 @@ extern void R_Textures_Init(void);
 extern void Mod_RenderInit(void);
 extern void GL_Draw_Init(void);
 extern void GL_Main_Init(void);
+extern void R_Shadow_Init(void);
 extern void GL_Models_Init(void);
 extern void R_Sky_Init(void);
 extern void GL_Surf_Init(void);
@@ -293,13 +296,13 @@ extern void Sbar_Init(void);
 
 void Render_Init(void)
 {
-       R_Modules_Shutdown();
        R_Textures_Init();
        Mod_RenderInit();
        gl_backend_init();
        R_MeshQueue_Init();
        GL_Draw_Init();
        GL_Main_Init();
+       R_Shadow_Init();
        GL_Models_Init();
        R_Sky_Init();
        GL_Surf_Init();
@@ -309,7 +312,6 @@ void Render_Init(void)
        R_Explosion_Init();
        ui_init();
        Sbar_Init();
-       R_Modules_Start();
 }
 
 /*
@@ -324,9 +326,6 @@ void GL_Init (void)
 
        // LordHavoc: report supported extensions
        Con_Printf ("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
-
-       qglCullFace(GL_FRONT);
-       qglEnable(GL_TEXTURE_2D);
 }
 
 int R_CullBox(const vec3_t emins, const vec3_t emaxs)
@@ -461,9 +460,6 @@ static void R_MarkEntities (void)
                        VectorAdd(ent->angles, r_refdef.viewangles, ent->angles);
                }
 
-               if (R_CullBox(ent->mins, ent->maxs))
-                       continue;
-
                ent->visframe = r_framecount;
                VectorCopy(ent->angles, v);
                if (!ent->model || ent->model->type != mod_brush)
@@ -472,6 +468,8 @@ static void R_MarkEntities (void)
                Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
                R_LerpAnimation(ent);
                R_UpdateEntLights(ent);
+               if (R_CullBox(ent->mins, ent->maxs))
+                       continue;
                R_FarClip_Box(ent->mins, ent->maxs);
        }
 }
@@ -546,6 +544,25 @@ void R_DrawModels (void)
        }
 }
 
+void R_DrawFakeShadows (void)
+{
+       int i;
+       entity_render_t *ent;
+
+       if (!r_drawentities.integer)
+               return;
+
+       ent = &cl_entities[0].render;
+       if (ent->model && ent->model->DrawFakeShadow)
+               ent->model->DrawFakeShadow(ent);
+       for (i = 0;i < r_refdef.numentities;i++)
+       {
+               ent = r_refdef.entities[i];
+               if (ent->model && ent->model->DrawFakeShadow)
+                       ent->model->DrawFakeShadow(ent);
+       }
+}
+
 static void R_SetFrustum (void)
 {
        int i;
@@ -612,10 +629,6 @@ static void R_BlendView(void)
        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;
@@ -627,6 +640,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;
+       GL_Color(r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
        R_Mesh_Draw(3, 1, polygonelements);
 }
 
@@ -665,7 +679,7 @@ void R_RenderView (void)
        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);
+       qglDepthFunc(GL_LEQUAL);
        
        R_Mesh_Start();
        R_MeshQueue_BeginScene();
@@ -704,6 +718,11 @@ void R_RenderView (void)
 
        R_MeshQueue_Render();
        R_MeshQueue_EndScene();
+       if (r_shadows.integer)
+       {
+               R_DrawFakeShadows();
+               R_TimeReport("fakeshadows");
+       }
        R_Mesh_Finish();
        R_TimeReport("meshfinish");
 }
@@ -727,10 +746,7 @@ 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 * 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;
+       R_FillColors(varray_color, 8, cr * r_colorscale, cg * r_colorscale, cb * r_colorscale, ca);
        if (fogenabled)
        {
                for (i = 0, v = varray_vertex, c = varray_color;i < 8;i++, v += 4, c += 4)
@@ -744,6 +760,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
                        c[2] = c[2] * f1 + fogcolor[2] * f2;
                }
        }
+       GL_UseColorArray();
        R_Mesh_Draw(8, 12);
 }
 */
@@ -787,12 +804,12 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2)
        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;
+       varray_color[ 0] = 0.00f * r_colorscale;varray_color[ 1] = 0.00f * r_colorscale;varray_color[ 2] = 0.50f * r_colorscale;varray_color[ 3] = ent->alpha;
+       varray_color[ 4] = 0.00f * r_colorscale;varray_color[ 5] = 0.00f * r_colorscale;varray_color[ 6] = 0.50f * r_colorscale;varray_color[ 7] = ent->alpha;
+       varray_color[ 8] = 0.00f * r_colorscale;varray_color[ 9] = 0.50f * r_colorscale;varray_color[10] = 0.00f * r_colorscale;varray_color[11] = ent->alpha;
+       varray_color[12] = 0.00f * r_colorscale;varray_color[13] = 0.50f * r_colorscale;varray_color[14] = 0.00f * r_colorscale;varray_color[15] = ent->alpha;
+       varray_color[16] = 0.50f * r_colorscale;varray_color[17] = 0.00f * r_colorscale;varray_color[18] = 0.00f * r_colorscale;varray_color[19] = ent->alpha;
+       varray_color[20] = 0.50f * r_colorscale;varray_color[21] = 0.00f * r_colorscale;varray_color[22] = 0.00f * r_colorscale;varray_color[23] = ent->alpha;
        if (fogenabled)
        {
                VectorSubtract(ent->origin, r_origin, diff);
@@ -814,6 +831,7 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2)
                        c[2] *= r_colorscale;
                }
        }
+       GL_UseColorArray();
        R_Mesh_Draw(6, 8, element);
 }