From 9230a20f18a22d7880813dd045854e02e57dcee2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 13 Jul 2014 17:15:17 +0200 Subject: [PATCH] - added some checks to the wall rendering code that will allow to disable the clip planes in many cases, even when a plane mirror portal is active. This also solves the precision issue with using world coordinates for clip checks. --- src/gl/scene/gl_portal.cpp | 5 ++--- src/gl/scene/gl_walls_draw.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 28b9a12828..c0fee33859 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -794,9 +794,8 @@ void GLPlaneMirrorPortal::DrawContents() validcount++; float f = FIXED2FLOAT(planez); - // the coordinate fudging is needed because for some reason this is nowhere near precise and leaves gaps. Strange... - if (PlaneMirrorMode < 0) gl_RenderState.SetClipHeightTop(f+0.3f); // ceiling mirror: clip everytihng with a z lower than the portal's ceiling - else gl_RenderState.SetClipHeightBottom(f-0.3f); // floor mirror: clip everything with a z higher than the portal's floor + if (PlaneMirrorMode < 0) gl_RenderState.SetClipHeightTop(f); // ceiling mirror: clip everytihng with a z lower than the portal's ceiling + else gl_RenderState.SetClipHeightBottom(f); // floor mirror: clip everything with a z higher than the portal's floor PlaneMirrorFlag++; GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 8e3a4b955a..aabec775e4 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -225,7 +225,7 @@ void GLWall::SetupLights() void GLWall::RenderWall(int textured, ADynamicLight * light, unsigned int *store) { - texcoord tcs[4]; + static texcoord tcs[4]; // making this variable static saves us a relatively costly stack integrity check. bool split = (gl_seamless && !(textured&RWF_NOSPLIT) && seg->sidedef != NULL && !(seg->sidedef->Flags & WALLF_POLYOBJ)); if (!light) @@ -249,7 +249,14 @@ void GLWall::RenderWall(int textured, ADynamicLight * light, unsigned int *store if (!(textured & RWF_NORENDER)) { + // disable the clip plane if it isn't needed (which can be determined by a simple check.) + float ct = gl_RenderState.GetClipHeightTop(); + float cb = gl_RenderState.GetClipHeightBottom(); + if (ztop[0] <= ct && ztop[1] <= ct) gl_RenderState.SetClipHeightTop(65536.f); + if (zbottom[0] >= cb && zbottom[1] >= cb) gl_RenderState.SetClipHeightBottom(-65536.f); gl_RenderState.Apply(); + gl_RenderState.SetClipHeightTop(ct); + gl_RenderState.SetClipHeightBottom(cb); } // the rest of the code is identical for textured rendering and lights