From de136f749e48d977b1aac2481cc062d23974afa2 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 1 Mar 2004 18:56:32 +0000 Subject: [PATCH] more cleanups of R_RenderScene (now r_view_ variables exist which are copied from the r_refdef fields each frame, these variables can easily be reconfigured for texture renders for mirrors or whatever) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3946 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_backend.c | 4 +-- gl_rmain.c | 73 +++++++++++++++++++++++++++++----------------------- r_shadow.c | 16 ++++++------ render.h | 17 ++++++++---- 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/gl_backend.c b/gl_backend.c index 9f970fe6..9b2ad26a 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -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; } diff --git a/gl_rmain.c b/gl_rmain.c index 1389621f..61aafc21 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -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 (); diff --git a/r_shadow.c b/r_shadow.c index 5883fb8e..a62dfaec 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -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(); diff --git a/render.h b/render.h index 9a28218f..eac7795e 100644 --- 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 -- 2.39.2