]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
more cleanups of R_RenderScene (now r_view_ variables exist which are copied from...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 1 Mar 2004 18:56:32 +0000 (18:56 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 1 Mar 2004 18:56:32 +0000 (18:56 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3946 d7cf8633-e32d-0410-b094-e92efae38249

gl_backend.c
gl_rmain.c
r_shadow.c
render.h

index 9f970fe63e4ed91a434ce542d3f688b17478af0a..9b2ad26a74f3c1ba889dc7f08ebb3c4f86b13490 100644 (file)
@@ -635,8 +635,8 @@ void GL_TransformToScreen(const vec4_t in, vec4_t out)
        Matrix4x4_Transform4 (&backend_viewmatrix, in, temp);
        Matrix4x4_Transform4 (&backend_projectmatrix, temp, out);
        iw = 1.0f / out[3];
-       out[0] = r_refdef.x + (out[0] * iw + 1.0f) * r_refdef.width * 0.5f;
-       out[1] = r_refdef.y + (out[1] * iw + 1.0f) * r_refdef.height * 0.5f;
+       out[0] = r_view_x + (out[0] * iw + 1.0f) * r_view_width * 0.5f;
+       out[1] = r_view_y + (out[1] * iw + 1.0f) * r_view_height * 0.5f;
        out[2] = out[2] * iw;
 }
 
index 1389621f65d87b4d52ef041bd1b0396932ee35a2..61aafc21f096f3d5941cf6c2881533aca897c504 100644 (file)
@@ -45,6 +45,13 @@ vec3_t r_viewforward;
 vec3_t r_viewleft;
 vec3_t r_viewright;
 vec3_t r_viewup;
+int r_view_x;
+int r_view_y;
+int r_view_width;
+int r_view_height;
+float r_view_fov_x;
+float r_view_fov_y;
+matrix4x4_t r_view_matrix;
 
 //
 // screen size info
@@ -505,8 +512,8 @@ void R_DrawModels(void)
 
 static void R_SetFrustum(void)
 {
-       // break apart the viewentity matrix into vectors for various purposes
-       Matrix4x4_ToVectors(&r_refdef.viewentitymatrix, r_viewforward, r_viewleft, r_viewup, r_vieworigin);
+       // break apart the view matrix into vectors for various purposes
+       Matrix4x4_ToVectors(&r_view_matrix, r_viewforward, r_viewleft, r_viewup, r_vieworigin);
        VectorNegate(r_viewleft, r_viewright);
 
        // LordHavoc: note to all quake engine coders, the special case for 90
@@ -514,22 +521,22 @@ static void R_SetFrustum(void)
        // disabled as well.
 
        // rotate R_VIEWFORWARD right by FOV_X/2 degrees
-       RotatePointAroundVector( frustum[0].normal, r_viewup, r_viewforward, -(90 - r_refdef.fov_x / 2));
+       RotatePointAroundVector( frustum[0].normal, r_viewup, r_viewforward, -(90 - r_view_fov_x / 2));
        frustum[0].dist = DotProduct (r_vieworigin, frustum[0].normal);
        PlaneClassify(&frustum[0]);
 
        // rotate R_VIEWFORWARD left by FOV_X/2 degrees
-       RotatePointAroundVector( frustum[1].normal, r_viewup, r_viewforward, (90 - r_refdef.fov_x / 2));
+       RotatePointAroundVector( frustum[1].normal, r_viewup, r_viewforward, (90 - r_view_fov_x / 2));
        frustum[1].dist = DotProduct (r_vieworigin, frustum[1].normal);
        PlaneClassify(&frustum[1]);
 
        // rotate R_VIEWFORWARD up by FOV_X/2 degrees
-       RotatePointAroundVector( frustum[2].normal, r_viewleft, r_viewforward, -(90 - r_refdef.fov_y / 2));
+       RotatePointAroundVector( frustum[2].normal, r_viewleft, r_viewforward, -(90 - r_view_fov_y / 2));
        frustum[2].dist = DotProduct (r_vieworigin, frustum[2].normal);
        PlaneClassify(&frustum[2]);
 
        // rotate R_VIEWFORWARD down by FOV_X/2 degrees
-       RotatePointAroundVector( frustum[3].normal, r_viewleft, r_viewforward, (90 - r_refdef.fov_y / 2));
+       RotatePointAroundVector( frustum[3].normal, r_viewleft, r_viewforward, (90 - r_view_fov_y / 2));
        frustum[3].dist = DotProduct (r_vieworigin, frustum[3].normal);
        PlaneClassify(&frustum[3]);
 }
@@ -603,33 +610,32 @@ void R_RenderView(void)
        if (!r_refdef.entities/* || !cl.worldmodel*/)
                return; //Host_Error ("R_RenderView: NULL worldmodel");
        
-       r_refdef.width = bound(0, r_refdef.width, vid.realwidth);
-       r_refdef.height = bound(0, r_refdef.height, vid.realheight);
-       r_refdef.x = bound(0, r_refdef.x, vid.realwidth - r_refdef.width);
-       r_refdef.y = bound(0, r_refdef.y, vid.realheight - r_refdef.height);
-       r_refdef.fov_x = bound(1, r_refdef.fov_x, 170);
-       r_refdef.fov_y = bound(1, r_refdef.fov_y, 170);
-
-       // GL is weird because it's bottom to top, r_refdef.y is top to bottom
-       qglViewport(r_refdef.x, vid.realheight - (r_refdef.y + r_refdef.height), r_refdef.width, r_refdef.height);
-       GL_Scissor(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
+       r_view_width = bound(0, r_refdef.width, vid.realwidth);
+       r_view_height = bound(0, r_refdef.height, vid.realheight);
+       r_view_x = bound(0, r_refdef.x, vid.realwidth - r_refdef.width);
+       r_view_y = bound(0, r_refdef.y, vid.realheight - r_refdef.height);
+       r_view_fov_x = bound(1, r_refdef.fov_x, 170);
+       r_view_fov_y = bound(1, r_refdef.fov_y, 170);
+       r_view_matrix = r_refdef.viewentitymatrix;
+
+       // GL is weird because it's bottom to top, r_view_y is top to bottom
+       qglViewport(r_view_x, vid.realheight - (r_view_y + r_view_height), r_view_width, r_view_height);
+       GL_Scissor(r_view_x, r_view_y, r_view_width, r_view_height);
        GL_ScissorTest(true);
        R_ClearScreen();
 
-       R_SetFrustum();
-       r_farclip = R_FarClip(r_vieworigin, r_viewforward, 768.0f) + 256.0f;
-
-       if (gl_stencil && ((r_shadow_realtime_world.integer && r_shadow_worldshadows.integer) || ((r_shadow_realtime_world.integer || r_shadow_realtime_dlight.integer) && r_shadow_dlightshadows.integer)))
-               GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_refdef.fov_x, r_refdef.fov_y, 1.0f);
-       else
-               GL_SetupView_Mode_Perspective(r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip);
-
-       GL_SetupView_Orientation_FromEntity(&r_refdef.viewentitymatrix);
        R_Mesh_Start();
        R_TimeReport("setup");
 
+       qglDepthFunc(GL_LEQUAL);
+       qglPolygonOffset(0, 0);
+       qglEnable(GL_POLYGON_OFFSET_FILL);
+
        R_RenderScene();
 
+       qglPolygonOffset(0, 0);
+       qglDisable(GL_POLYGON_OFFSET_FILL);
+
        R_BlendView();
        R_TimeReport("blendview");
        
@@ -651,6 +657,16 @@ void R_RenderScene(void)
 
        r_framecount++;
 
+       R_SetFrustum();
+
+       r_farclip = R_FarClip(r_vieworigin, r_viewforward, 768.0f) + 256.0f;
+       if (gl_stencil && ((r_shadow_realtime_world.integer && r_shadow_worldshadows.integer) || ((r_shadow_realtime_world.integer || r_shadow_realtime_dlight.integer) && r_shadow_dlightshadows.integer)))
+               GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_view_fov_x, r_view_fov_y, 1.0f);
+       else
+               GL_SetupView_Mode_Perspective(r_view_fov_x, r_view_fov_y, 1.0f, r_farclip);
+
+       GL_SetupView_Orientation_FromEntity(&r_view_matrix);
+
        R_SkyStartFrame();
 
        if (cl.worldmodel && cl.worldmodel->brush.FatPVS)
@@ -662,10 +678,6 @@ void R_RenderScene(void)
        R_MarkEntities();
        R_TimeReport("markentity");
 
-       qglDepthFunc(GL_LEQUAL);
-       qglPolygonOffset(0, 0);
-       qglEnable(GL_POLYGON_OFFSET_FILL);
-
        R_MeshQueue_BeginScene();
 
        R_Shadow_UpdateWorldLightSelection();
@@ -726,9 +738,6 @@ void R_RenderScene(void)
                R_TimeReport("shadowvolume");
        }
 
-       qglPolygonOffset(0, 0);
-       qglDisable(GL_POLYGON_OFFSET_FILL);
-
        // don't let sound skip if going slow
        if (!intimerefresh && !r_speeds.integer)
                S_ExtraUpdate ();
index 5883fb8e5b1fdc5cc7e06d755875263c74e88b06..a62dfaecb221d3a1794c1b052383651c121fa187 100644 (file)
@@ -872,7 +872,7 @@ void R_Shadow_Stage_Begin(void)
        R_Mesh_State_Texture(&m);
        GL_Color(0, 0, 0, 1);
        qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
-       GL_Scissor(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
+       GL_Scissor(r_view_x, r_view_y, r_view_width, r_view_height);
        r_shadowstage = SHADOWSTAGE_NONE;
 
        c_rt_lights = c_rt_clears = c_rt_scissored = 0;
@@ -987,7 +987,7 @@ void R_Shadow_Stage_End(void)
        //qglDisable(GL_POLYGON_OFFSET_FILL);
        GL_Color(1, 1, 1, 1);
        qglColorMask(1, 1, 1, 1);
-       GL_Scissor(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
+       GL_Scissor(r_view_x, r_view_y, r_view_width, r_view_height);
        qglDepthFunc(GL_LEQUAL);
        qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
        qglDisable(GL_STENCIL_TEST);
@@ -1009,7 +1009,7 @@ int R_Shadow_ScissorForBBox(const float *mins, const float *maxs)
        // (?!?  seems like a driver bug) so abort if gl_stencil is false
        if (!gl_stencil || BoxesOverlap(r_vieworigin, r_vieworigin, mins, maxs))
        {
-               GL_Scissor(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
+               GL_Scissor(r_view_x, r_view_y, r_view_width, r_view_height);
                return false;
        }
        for (i = 0;i < 3;i++)
@@ -1155,10 +1155,10 @@ int R_Shadow_ScissorForBBox(const float *mins, const float *maxs)
        ix2 = x2 + 1.0f;
        iy2 = y2 + 1.0f;
        //Con_Printf("%f %f %f %f\n", x1, y1, x2, y2);
-       if (ix1 < r_refdef.x) ix1 = r_refdef.x;
-       if (iy1 < r_refdef.y) iy1 = r_refdef.y;
-       if (ix2 > r_refdef.x + r_refdef.width) ix2 = r_refdef.x + r_refdef.width;
-       if (iy2 > r_refdef.y + r_refdef.height) iy2 = r_refdef.y + r_refdef.height;
+       if (ix1 < r_view_x) ix1 = r_view_x;
+       if (iy1 < r_view_y) iy1 = r_view_y;
+       if (ix2 > r_view_x + r_view_width) ix2 = r_view_x + r_view_width;
+       if (iy2 > r_view_y + r_view_height) iy2 = r_view_y + r_view_height;
        if (ix2 <= ix1 || iy2 <= iy1)
                return true;
        // set up the scissor rectangle
@@ -2307,7 +2307,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
        if (visiblevolumes)
        {
                qglEnable(GL_CULL_FACE);
-               GL_Scissor(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
+               GL_Scissor(r_view_x, r_view_y, r_view_width, r_view_height);
        }
        else
                R_Shadow_Stage_End();
index 9a28218f1f024e78c07b63fe709121faeb0dbd12..eac7795ea8d88200a7a3f9541380e47e022e0773 100644 (file)
--- a/render.h
+++ b/render.h
@@ -90,11 +90,18 @@ extern      int             c_alias_polys, c_light_polys, c_faces, c_nodes, c_leafs, c_models, c
 //
 // view origin
 //
-extern vec3_t  r_vieworigin;
-extern vec3_t  r_viewforward;
-extern vec3_t  r_viewleft;
-extern vec3_t  r_viewright;
-extern vec3_t  r_viewup;
+extern vec3_t r_vieworigin;
+extern vec3_t r_viewforward;
+extern vec3_t r_viewleft;
+extern vec3_t r_viewright;
+extern vec3_t r_viewup;
+extern int r_view_x;
+extern int r_view_y;
+extern int r_view_width;
+extern int r_view_height;
+extern float r_view_fov_x;
+extern float r_view_fov_y;
+extern matrix4x4_t r_view_matrix;
 
 extern mleaf_t         *r_viewleaf, *r_oldviewleaf;
 extern unsigned short  d_lightstylevalue[256]; // 8.8 fraction of base light value