From e4d7d9de8ba7c4c0bca570b61adffb4419656c42 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 12 Mar 2017 12:03:54 +0100 Subject: [PATCH 1/3] - moved several more functions from FGLRenderer to GLSceneDrawer. --- src/gl/compatibility/gl_20.cpp | 5 +- src/gl/renderer/gl_renderer.h | 13 ------ src/gl/scene/gl_portal.cpp | 30 ++++++------ src/gl/scene/gl_scene.cpp | 83 +++++++++++++++------------------- src/gl/scene/gl_scenedrawer.h | 27 +++++++++-- src/gl/scene/gl_skydome.cpp | 3 +- 6 files changed, 81 insertions(+), 80 deletions(-) diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 66a7bc5f9a..917963e485 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -47,6 +47,7 @@ #include "gl/system/gl_cvars.h" #include "gl/renderer/gl_renderstate.h" #include "gl/scene/gl_drawinfo.h" +#include "gl/scene/gl_scenedrawer.h" #include "gl/data/gl_vertexbuffer.h" @@ -756,7 +757,7 @@ void GLWall::RenderLightsCompat(int pass) // //========================================================================== -void FGLRenderer::RenderMultipassStuff() +void GLSceneDrawer::RenderMultipassStuff() { // First pass: empty background with sector light only @@ -790,7 +791,7 @@ void FGLRenderer::RenderMultipassStuff() // second pass: draw lights glDepthMask(false); - if (mLightCount && !gl_fixedcolormap) + if (GLRenderer->mLightCount && !gl_fixedcolormap) { if (gl_SetupLightTexture()) { diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 4d88832055..4406b2d99e 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -158,21 +158,12 @@ class FGLRenderer int ScreenToWindowX(int x); int ScreenToWindowY(int y); - angle_t FrustumAngle(); - void SetViewArea(); - void Set3DViewport(bool mainview); void Reset3DViewport(); sector_t *RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void RenderView(player_t *player); - void SetViewAngle(DAngle viewangle); - void SetupView(float viewx, float viewy, float viewz, DAngle viewangle, bool mirror, bool planemirror); void Initialize(int width, int height); - void RenderMultipassStuff(); - void RenderScene(int recursion); - void RenderTranslucent(); - void DrawScene(int drawmode); void DrawBlend(sector_t * viewsector); void DrawPSprite (player_t * player,DPSprite *psp,float sx, float sy, bool hudModelStep, int OverrideShader, bool alphatexture); @@ -208,10 +199,6 @@ class FGLRenderer void DrawPresentTexture(const GL_IRECT &box, bool applyGamma); void Flush(); - void SetProjection(float fov, float ratio, float fovratio); - void SetProjection(VSMatrix matrix); // raw matrix input from stereo 3d modes - void SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror); - void ProcessScene(bool toscreen = false); bool StartOffscreen(); void EndOffscreen(); diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index ebfad3d4d6..1f8f521edd 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -328,7 +328,7 @@ inline void GLPortal::ClearClipper() } // and finally clip it to the visible area - angle_t a1 = GLRenderer->FrustumAngle(); + angle_t a1 = drawer->FrustumAngle(); if (a1 < ANGLE_180) drawer->clipper.SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs() + a1, r_viewpoint.Angles.Yaw.BAMs() - a1); // lock the parts that have just been clipped out. @@ -363,7 +363,7 @@ void GLPortal::End(bool usestencil) GLRenderer->mViewActor=savedviewactor; in_area=savedviewarea; if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags = (r_viewpoint.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; - GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); { ScopedColorMask colorMask(0, 0, 0, 0); // glColorMask(0, 0, 0, 0); // no graphics @@ -422,7 +422,7 @@ void GLPortal::End(bool usestencil) GLRenderer->mViewActor=savedviewactor; in_area=savedviewarea; if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags |= savedvisibility; - GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); // This draws a valid z-buffer into the stencil's contents to ensure it // doesn't get overwritten by the level's geometry. @@ -648,8 +648,8 @@ void GLSkyboxPortal::DrawContents() GLRenderer->mViewActor = origin; inskybox = true; - GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); - GLRenderer->SetViewArea(); + drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + drawer->SetViewArea(); ClearClipper(); int mapsection = R_PointInSubsector(r_viewpoint.Pos)->mapsection; @@ -657,7 +657,7 @@ void GLSkyboxPortal::DrawContents() SaveMapSection(); currentmapsection[mapsection >> 3] |= 1 << (mapsection & 7); - GLRenderer->DrawScene(DM_SKYPORTAL); + drawer->DrawScene(DM_SKYPORTAL); portal->mFlags &= ~PORTSF_INSKYBOX; inskybox = false; gl_RenderState.SetDepthClamp(oldclamp); @@ -744,7 +744,7 @@ void GLSectorStackPortal::DrawContents() // avoid recursions! if (origin->plane != -1) instack[origin->plane]++; - GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); SaveMapSection(); SetupCoverage(); ClearClipper(); @@ -758,7 +758,7 @@ void GLSectorStackPortal::DrawContents() drawer->clipper.SetBlocked(true); } - GLRenderer->DrawScene(DM_PORTAL); + drawer->DrawScene(DM_PORTAL); RestoreMapSection(); if (origin->plane != -1) instack[origin->plane]--; @@ -801,11 +801,11 @@ void GLPlaneMirrorPortal::DrawContents() PlaneMirrorMode = origin->fC() < 0 ? -1 : 1; PlaneMirrorFlag++; - GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); ClearClipper(); gl_RenderState.SetClipHeight(planez, PlaneMirrorMode < 0 ? -1.f : 1.f); - GLRenderer->DrawScene(DM_PORTAL); + drawer->DrawScene(DM_PORTAL); gl_RenderState.SetClipHeight(0.f, 0.f); PlaneMirrorFlag--; PlaneMirrorMode = old_pm; @@ -967,11 +967,11 @@ void GLMirrorPortal::DrawContents() GLRenderer->mViewActor = NULL; MirrorFlag++; - GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); drawer->clipper.Clear(); - angle_t af = GLRenderer->FrustumAngle(); + angle_t af = drawer->FrustumAngle(); if (afclipper.SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs()+af, r_viewpoint.Angles.Yaw.BAMs()-af); angle_t a2 = linedef->v1->GetClipAngle(); @@ -980,7 +980,7 @@ void GLMirrorPortal::DrawContents() gl_RenderState.SetClipLine(linedef); gl_RenderState.EnableClipLine(true); - GLRenderer->DrawScene(DM_PORTAL); + drawer->DrawScene(DM_PORTAL); gl_RenderState.EnableClipLine(false); MirrorFlag--; @@ -1049,12 +1049,12 @@ void GLLineToLinePortal::DrawContents() } GLRenderer->mViewActor = nullptr; - GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); ClearClipper(); gl_RenderState.SetClipLine(glport->lines[0]->mDestination); gl_RenderState.EnableClipLine(true); - GLRenderer->DrawScene(DM_PORTAL); + drawer->DrawScene(DM_PORTAL); gl_RenderState.EnableClipLine(false); RestoreMapSection(); } diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 619f71cf4c..0b704ad795 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -100,18 +100,18 @@ void gl_ParseDefs(); // R_FrustumAngle // //----------------------------------------------------------------------------- -angle_t FGLRenderer::FrustumAngle() +angle_t GLSceneDrawer::FrustumAngle() { - float tilt= fabs(mAngles.Pitch.Degrees); + float tilt = fabs(GLRenderer->mAngles.Pitch.Degrees); // If the pitch is larger than this you can look all around at a FOV of 90° - if (tilt>46.0f) return 0xffffffff; + if (tilt > 46.0f) return 0xffffffff; // ok, this is a gross hack that barely works... // but at least it doesn't overestimate too much... - double floatangle=2.0+(45.0+((tilt/1.9)))*mCurrentFoV*48.0/AspectMultiplier(r_viewwindow.WidescreenRatio)/90.0; + double floatangle = 2.0 + (45.0 + ((tilt / 1.9)))*GLRenderer->mCurrentFoV*48.0 / AspectMultiplier(r_viewwindow.WidescreenRatio) / 90.0; angle_t a1 = DAngle(floatangle).BAMs(); - if (a1>=ANGLE_180) return 0xffffffff; + if (a1 >= ANGLE_180) return 0xffffffff; return a1; } @@ -120,7 +120,7 @@ angle_t FGLRenderer::FrustumAngle() // Sets the area the camera is in // //----------------------------------------------------------------------------- -void FGLRenderer::SetViewArea() +void GLSceneDrawer::SetViewArea() { // The render_sector is better suited to represent the current position in GL r_viewpoint.sector = R_PointInSubsector(r_viewpoint.Pos)->render_sector; @@ -155,12 +155,12 @@ void FGLRenderer::Reset3DViewport() // //----------------------------------------------------------------------------- -void FGLRenderer::Set3DViewport(bool mainview) +void GLSceneDrawer::Set3DViewport(bool mainview) { - if (mainview && mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height)) + if (mainview && GLRenderer->mBuffers->Setup(GLRenderer->mScreenViewport.width, GLRenderer->mScreenViewport.height, GLRenderer->mSceneViewport.width, GLRenderer->mSceneViewport.height)) { bool useSSAO = (gl_ssao != 0); - mBuffers->BindSceneFB(useSSAO); + GLRenderer->mBuffers->BindSceneFB(useSSAO); gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); gl_RenderState.Apply(); @@ -170,10 +170,10 @@ void FGLRenderer::Set3DViewport(bool mainview) // This is faster on newer hardware because it allows the GPU to skip // reading from slower memory where the full buffers are stored. glDisable(GL_SCISSOR_TEST); - glClearColor(mSceneClearColor[0], mSceneClearColor[1], mSceneClearColor[2], 1.0f); + glClearColor(GLRenderer->mSceneClearColor[0], GLRenderer->mSceneClearColor[1], GLRenderer->mSceneClearColor[2], 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - const auto &bounds = mSceneViewport; + const auto &bounds = GLRenderer->mSceneViewport; glViewport(bounds.left, bounds.top, bounds.width, bounds.height); glScissor(bounds.left, bounds.top, bounds.width, bounds.height); @@ -192,12 +192,12 @@ void FGLRenderer::Set3DViewport(bool mainview) // //----------------------------------------------------------------------------- -void FGLRenderer::SetViewAngle(DAngle viewangle) +void GLSceneDrawer::SetViewAngle(DAngle viewangle) { - mAngles.Yaw = float(270.0-viewangle.Degrees); + GLRenderer->mAngles.Yaw = float(270.0-viewangle.Degrees); DVector2 v = r_viewpoint.Angles.Yaw.ToVector(); - mViewVector.X = v.X; - mViewVector.Y = v.Y; + GLRenderer->mViewVector.X = v.X; + GLRenderer->mViewVector.Y = v.Y; R_SetViewAngle(r_viewpoint, r_viewwindow); } @@ -210,15 +210,7 @@ void FGLRenderer::SetViewAngle(DAngle viewangle) // //----------------------------------------------------------------------------- -void FGLRenderer::SetProjection(float fov, float ratio, float fovratio) -{ - - float fovy = 2 * RAD2DEG(atan(tan(DEG2RAD(fov) / 2) / fovratio)); - gl_RenderState.mProjectionMatrix.perspective(fovy, ratio, GetZNear(), GetZFar()); -} - -// raw matrix input from stereo 3d modes -void FGLRenderer::SetProjection(VSMatrix matrix) +void GLSceneDrawer::SetProjection(VSMatrix matrix) { gl_RenderState.mProjectionMatrix.loadIdentity(); gl_RenderState.mProjectionMatrix.multMatrix(matrix); @@ -230,7 +222,7 @@ void FGLRenderer::SetProjection(VSMatrix matrix) // //----------------------------------------------------------------------------- -void FGLRenderer::SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror) +void GLSceneDrawer::SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror) { float mult = mirror? -1:1; float planemult = planemirror? -glset.pixelstretch : glset.pixelstretch; @@ -250,7 +242,7 @@ void FGLRenderer::SetViewMatrix(float vx, float vy, float vz, bool mirror, bool // Setup the view rotation matrix for the given viewpoint // //----------------------------------------------------------------------------- -void FGLRenderer::SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror) +void GLSceneDrawer::SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror) { SetViewAngle(va); SetViewMatrix(vx, vy, vz, mirror, planemirror); @@ -267,9 +259,8 @@ void FGLRenderer::SetupView(float vx, float vy, float vz, DAngle va, bool mirror void GLSceneDrawer::CreateScene() { - angle_t a1 = GLRenderer->FrustumAngle(); + angle_t a1 = FrustumAngle(); InitClipper(r_viewpoint.Angles.Yaw.BAMs() + a1, r_viewpoint.Angles.Yaw.BAMs() - a1); - GLPortal::drawer = this; // reset the portal manager GLPortal::StartFrame(); @@ -306,7 +297,7 @@ void GLSceneDrawer::CreateScene() // //----------------------------------------------------------------------------- -void FGLRenderer::RenderScene(int recursion) +void GLSceneDrawer::RenderScene(int recursion) { RenderAll.Clock(); @@ -329,7 +320,7 @@ void FGLRenderer::RenderScene(int recursion) // if we don't have a persistently mapped buffer, we have to process all the dynamic lights up front, // so that we don't have to do repeated map/unmap calls on the buffer. - bool haslights = mLightCount > 0 && gl_fixedcolormap == CM_DEFAULT && gl_lights; + bool haslights = GLRenderer->mLightCount > 0 && gl_fixedcolormap == CM_DEFAULT && gl_lights; if (gl.lightmethod == LM_DEFERRED && haslights) { GLRenderer->mLights->Begin(); @@ -358,7 +349,7 @@ void FGLRenderer::RenderScene(int recursion) { pass = GLPASS_ALL; } - else + else // GL 2.x legacy mode { // process everything that needs to handle textured dynamic lights. if (haslights) RenderMultipassStuff(); @@ -445,7 +436,7 @@ void FGLRenderer::RenderScene(int recursion) // //----------------------------------------------------------------------------- -void FGLRenderer::RenderTranslucent() +void GLSceneDrawer::RenderTranslucent() { RenderAll.Clock(); @@ -477,7 +468,7 @@ void FGLRenderer::RenderTranslucent() // //----------------------------------------------------------------------------- -void FGLRenderer::DrawScene(int drawmode) +void GLSceneDrawer::DrawScene(int drawmode) { static int recursion=0; static int ssao_portals_available = 0; @@ -498,17 +489,15 @@ void FGLRenderer::DrawScene(int drawmode) ssao_portals_available--; } - GLSceneDrawer drawer; - if (r_viewpoint.camera != nullptr) { ActorRenderFlags savedflags = r_viewpoint.camera->renderflags; - drawer.CreateScene(); + CreateScene(); r_viewpoint.camera->renderflags = savedflags; } else { - drawer.CreateScene(); + CreateScene(); } GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place. @@ -517,8 +506,8 @@ void FGLRenderer::DrawScene(int drawmode) if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS) { gl_RenderState.EnableDrawBuffers(1); - AmbientOccludeScene(); - mBuffers->BindSceneFB(true); + GLRenderer->AmbientOccludeScene(); + GLRenderer->mBuffers->BindSceneFB(true); gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); gl_RenderState.Apply(); gl_RenderState.ApplyMatrices(); @@ -732,7 +721,7 @@ void FGLRenderer::EndDrawScene(sector_t * viewsector) // //----------------------------------------------------------------------------- -void FGLRenderer::ProcessScene(bool toscreen) +void GLSceneDrawer::ProcessScene(bool toscreen) { FDrawInfo::StartDrawInfo(); iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; @@ -800,12 +789,14 @@ void FGLRenderer::SetFixedColormap (player_t *player) sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) { + GLSceneDrawer drawer; + sector_t * lviewsector; mSceneClearColor[0] = 0.0f; mSceneClearColor[1] = 0.0f; mSceneClearColor[2] = 0.0f; R_SetupFrame (r_viewpoint, r_viewwindow, camera); - SetViewArea(); + drawer.SetViewArea(); // We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1. double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); @@ -844,20 +835,20 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo const s3d::EyePose * eye = stereo3dMode.getEyePose(eye_ix); eye->SetUp(); SetOutputViewport(bounds); - Set3DViewport(mainview); + drawer.Set3DViewport(mainview); mDrawingScene2D = true; mCurrentFoV = fov; // Stereo mode specific perspective projection - SetProjection( eye->GetProjection(fov, ratio, fovratio) ); + drawer.SetProjection( eye->GetProjection(fov, ratio, fovratio) ); // SetProjection(fov, ratio, fovratio); // switch to perspective mode and set up clipper - SetViewAngle(r_viewpoint.Angles.Yaw); + drawer.SetViewAngle(r_viewpoint.Angles.Yaw); // Stereo mode specific viewpoint adjustment - temporarily shifts global ViewPos eye->GetViewShift(GLRenderer->mAngles.Yaw.Degrees, viewShift); s3d::ScopedViewShifter viewShifter(viewShift); - SetViewMatrix(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, false, false); + drawer.SetViewMatrix(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, false, false); gl_RenderState.ApplyMatrices(); - ProcessScene(toscreen); + drawer.ProcessScene(toscreen); if (mainview && toscreen) EndDrawScene(lviewsector); // do not call this for camera textures. if (mainview && FGLRenderBuffers::IsEnabled()) { diff --git a/src/gl/scene/gl_scenedrawer.h b/src/gl/scene/gl_scenedrawer.h index eb40ecb351..375a8bdc18 100644 --- a/src/gl/scene/gl_scenedrawer.h +++ b/src/gl/scene/gl_scenedrawer.h @@ -3,6 +3,7 @@ #include "r_defs.h" #include "m_fixed.h" #include "gl_clipper.h" +#include "gl_portal.h" class GLSceneDrawer { @@ -10,7 +11,9 @@ class GLSceneDrawer subsector_t *currentsubsector; // used by the line processing code. sector_t *currentsector; - + + void RenderMultipassStuff(); + void UnclipSubsector(subsector_t *sub); void AddLine (seg_t *seg, bool portalclip); void PolySubsector(subsector_t * sub); @@ -22,10 +25,28 @@ class GLSceneDrawer void DoSubsector(subsector_t * sub); void RenderBSPNode(void *node); + void RenderScene(int recursion); + void RenderTranslucent(); + + void CreateScene(); + public: + GLSceneDrawer() + { + GLPortal::drawer = this; + } + Clipper clipper; - - void CreateScene(); + + angle_t FrustumAngle(); + void SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror); + void SetViewArea(); + void SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror); + void SetViewAngle(DAngle viewangle); + void SetProjection(VSMatrix matrix); + void Set3DViewport(bool mainview); + void DrawScene(int drawmode); + void ProcessScene(bool toscreen = false); void InitClipper(angle_t a1, angle_t a2) { diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index a988bdfec9..ea19c8ca38 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -68,6 +68,7 @@ #include "gl/renderer/gl_lightdata.h" #include "gl/renderer/gl_renderstate.h" #include "gl/scene/gl_drawinfo.h" +#include "gl/scene/gl_scenedrawer.h" #include "gl/scene/gl_portal.h" #include "gl/shaders/gl_shader.h" #include "gl/textures/gl_bitmap.h" @@ -519,7 +520,7 @@ void GLSkyPortal::DrawContents() bool oldClamp = gl_RenderState.SetDepthClamp(true); gl_MatrixStack.Push(gl_RenderState.mViewMatrix); - GLRenderer->SetupView(0, 0, 0, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + drawer->SetupView(0, 0, 0, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO); if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox) From e7330cfa0321c82ebc5f241ad4f3a08cf2c1da95 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 12 Mar 2017 12:51:26 +0100 Subject: [PATCH 2/3] - all main functions in gl_scene.cpp now belong to the new GLSceneDrawer class. --- src/gl/renderer/gl_renderer.h | 8 --- src/gl/scene/gl_scene.cpp | 98 +++++++++++++++++------------------ src/gl/scene/gl_scenedrawer.h | 8 +++ 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 4406b2d99e..0619da0c65 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -158,13 +158,8 @@ class FGLRenderer int ScreenToWindowX(int x); int ScreenToWindowY(int y); - void Reset3DViewport(); - sector_t *RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); - void RenderView(player_t *player); - void Initialize(int width, int height); - void DrawBlend(sector_t * viewsector); void DrawPSprite (player_t * player,DPSprite *psp,float sx, float sy, bool hudModelStep, int OverrideShader, bool alphatexture); void DrawPlayerSprites(sector_t * viewsector, bool hudModelStep); @@ -182,9 +177,6 @@ class FGLRenderer void SetupLevel(); void RenderScreenQuad(); - void SetFixedColormap (player_t *player); - void WriteSavePic (player_t *player, FileWriter *file, int width, int height); - void EndDrawScene(sector_t * viewsector); void PostProcessScene(); void AmbientOccludeScene(); void UpdateCameraExposure(); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 0b704ad795..48dac4391e 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -144,9 +144,9 @@ void GLSceneDrawer::SetViewArea() // //----------------------------------------------------------------------------- -void FGLRenderer::Reset3DViewport() +void GLSceneDrawer::Reset3DViewport() { - glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); + glViewport(GLRenderer->mScreenViewport.left, GLRenderer->mScreenViewport.top, GLRenderer->mScreenViewport.width, GLRenderer->mScreenViewport.height); } //----------------------------------------------------------------------------- @@ -536,7 +536,7 @@ void gl_FillScreen() // Draws a blend over the entire view // //========================================================================== -void FGLRenderer::DrawBlend(sector_t * viewsector) +void GLSceneDrawer::DrawBlend(sector_t * viewsector) { float blend[4]={0,0,0,0}; PalEntry blendv=0; @@ -597,7 +597,7 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) if (blendv.a == 255) { // The calculated average is too dark so brighten it according to the palettes's overall brightness - int maxcol = MAX(MAX(framebuffer->palette_brightness, blendv.r), MAX(blendv.g, blendv.b)); + int maxcol = MAX(MAX(GLRenderer->framebuffer->palette_brightness, blendv.r), MAX(blendv.g, blendv.b)); blendv.r = blendv.r * 255 / maxcol; blendv.g = blendv.g * 255 / maxcol; blendv.b = blendv.b * 255 / maxcol; @@ -668,7 +668,7 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) //----------------------------------------------------------------------------- -void FGLRenderer::EndDrawScene(sector_t * viewsector) +void GLSceneDrawer::EndDrawScene(sector_t * viewsector) { gl_RenderState.EnableFog(false); @@ -680,19 +680,19 @@ void FGLRenderer::EndDrawScene(sector_t * viewsector) { // [BB] The HUD model should be drawn over everything else already drawn. glClear(GL_DEPTH_BUFFER_BIT); - DrawPlayerSprites (viewsector, true); + GLRenderer->DrawPlayerSprites (viewsector, true); } glDisable(GL_STENCIL_TEST); - framebuffer->Begin2D(false); + GLRenderer->framebuffer->Begin2D(false); Reset3DViewport(); // [BB] Only draw the sprites if we didn't render a HUD model before. if ( renderHUDModel == false ) { - DrawPlayerSprites (viewsector, false); + GLRenderer->DrawPlayerSprites (viewsector, false); } if (gl.legacyMode) { @@ -701,7 +701,7 @@ void FGLRenderer::EndDrawScene(sector_t * viewsector) gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetSoftLightLevel(-1); - DrawTargeterSprites(); + GLRenderer->DrawTargeterSprites(); if (!FGLRenderBuffers::IsEnabled()) { DrawBlend(viewsector); @@ -741,7 +741,7 @@ void GLSceneDrawer::ProcessScene(bool toscreen) // //----------------------------------------------------------------------------- -void FGLRenderer::SetFixedColormap (player_t *player) +void GLSceneDrawer::SetFixedColormap (player_t *player) { gl_fixedcolormap=CM_DEFAULT; @@ -787,16 +787,14 @@ void FGLRenderer::SetFixedColormap (player_t *player) // //----------------------------------------------------------------------------- -sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) +sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) { - GLSceneDrawer drawer; - sector_t * lviewsector; - mSceneClearColor[0] = 0.0f; - mSceneClearColor[1] = 0.0f; - mSceneClearColor[2] = 0.0f; + GLRenderer->mSceneClearColor[0] = 0.0f; + GLRenderer->mSceneClearColor[1] = 0.0f; + GLRenderer->mSceneClearColor[2] = 0.0f; R_SetupFrame (r_viewpoint, r_viewwindow, camera); - drawer.SetViewArea(); + SetViewArea(); // We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1. double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); @@ -804,23 +802,23 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); - mAngles.Pitch = (float)RAD2DEG(asin(angy / alen)); - mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; + GLRenderer->mAngles.Pitch = (float)RAD2DEG(asin(angy / alen)); + GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; // Scroll the sky - mSky1Pos = (float)fmod(gl_frameMS * level.skyspeed1, 1024.f) * 90.f/256.f; - mSky2Pos = (float)fmod(gl_frameMS * level.skyspeed2, 1024.f) * 90.f/256.f; + GLRenderer->mSky1Pos = (float)fmod(gl_frameMS * level.skyspeed1, 1024.f) * 90.f/256.f; + GLRenderer->mSky2Pos = (float)fmod(gl_frameMS * level.skyspeed2, 1024.f) * 90.f/256.f; if (camera->player && camera->player-players==consoleplayer && ((camera->player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && camera==camera->player->mo) { - mViewActor=NULL; + GLRenderer->mViewActor=NULL; } else { - mViewActor=camera; + GLRenderer->mViewActor=camera; } // 'viewsector' will not survive the rendering so it cannot be used anymore below. @@ -834,42 +832,42 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo { const s3d::EyePose * eye = stereo3dMode.getEyePose(eye_ix); eye->SetUp(); - SetOutputViewport(bounds); - drawer.Set3DViewport(mainview); - mDrawingScene2D = true; - mCurrentFoV = fov; + GLRenderer->SetOutputViewport(bounds); + Set3DViewport(mainview); + GLRenderer->mDrawingScene2D = true; + GLRenderer->mCurrentFoV = fov; // Stereo mode specific perspective projection - drawer.SetProjection( eye->GetProjection(fov, ratio, fovratio) ); + SetProjection( eye->GetProjection(fov, ratio, fovratio) ); // SetProjection(fov, ratio, fovratio); // switch to perspective mode and set up clipper - drawer.SetViewAngle(r_viewpoint.Angles.Yaw); + SetViewAngle(r_viewpoint.Angles.Yaw); // Stereo mode specific viewpoint adjustment - temporarily shifts global ViewPos eye->GetViewShift(GLRenderer->mAngles.Yaw.Degrees, viewShift); s3d::ScopedViewShifter viewShifter(viewShift); - drawer.SetViewMatrix(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, false, false); + SetViewMatrix(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, false, false); gl_RenderState.ApplyMatrices(); - drawer.ProcessScene(toscreen); + ProcessScene(toscreen); if (mainview && toscreen) EndDrawScene(lviewsector); // do not call this for camera textures. if (mainview && FGLRenderBuffers::IsEnabled()) { - PostProcessScene(); + GLRenderer->PostProcessScene(); // This should be done after postprocessing, not before. - mBuffers->BindCurrentFB(); - glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); + GLRenderer->mBuffers->BindCurrentFB(); + glViewport(GLRenderer->mScreenViewport.left, GLRenderer->mScreenViewport.top, GLRenderer->mScreenViewport.width, GLRenderer->mScreenViewport.height); if (!toscreen) { gl_RenderState.mViewMatrix.loadIdentity(); - gl_RenderState.mProjectionMatrix.ortho(mScreenViewport.left, mScreenViewport.width, mScreenViewport.height, mScreenViewport.top, -1.0f, 1.0f); + gl_RenderState.mProjectionMatrix.ortho(GLRenderer->mScreenViewport.left, GLRenderer->mScreenViewport.width, GLRenderer->mScreenViewport.height, GLRenderer->mScreenViewport.top, -1.0f, 1.0f); gl_RenderState.ApplyMatrices(); } DrawBlend(lviewsector); } - mDrawingScene2D = false; + GLRenderer->mDrawingScene2D = false; if (!stereo3dMode.IsMono() && FGLRenderBuffers::IsEnabled()) - mBuffers->BlitToEyeTexture(eye_ix); + GLRenderer->mBuffers->BlitToEyeTexture(eye_ix); eye->TearDown(); } stereo3dMode.TearDown(); @@ -885,12 +883,12 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo // //----------------------------------------------------------------------------- -void FGLRenderer::RenderView (player_t* player) +void GLSceneDrawer::RenderView (player_t* player) { checkBenchActive(); - gl_RenderState.SetVertexBuffer(mVBO); + gl_RenderState.SetVertexBuffer(GLRenderer->mVBO); GLRenderer->mVBO->Reset(); // reset statistics counters @@ -943,7 +941,7 @@ void FGLRenderer::RenderView (player_t* player) // //=========================================================================== -void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) +void GLSceneDrawer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { GL_IRECT bounds; @@ -953,7 +951,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i bounds.height=height; glFlush(); SetFixedColormap(player); - gl_RenderState.SetVertexBuffer(mVBO); + gl_RenderState.SetVertexBuffer(GLRenderer->mVBO); GLRenderer->mVBO->Reset(); if (!gl.legacyMode) GLRenderer->mLights->Clear(); @@ -961,7 +959,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i TThinkerIterator it(STAT_DLIGHT); GLRenderer->mLightCount = ((it.Next()) != NULL); - sector_t *viewsector = RenderViewpoint(players[consoleplayer].camera, &bounds, + sector_t *viewsector = RenderViewpoint(players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); glDisable(GL_STENCIL_TEST); gl_RenderState.SetFixedColormap(CM_DEFAULT); @@ -971,7 +969,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i { DrawBlend(viewsector); } - CopyToBackbuffer(&bounds, false); + GLRenderer->CopyToBackbuffer(&bounds, false); glFlush(); uint8_t * scr = (uint8_t *)M_Malloc(width * height * 3); @@ -1104,7 +1102,8 @@ void FGLInterface::SetClearColor(int color) void FGLInterface::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { - GLRenderer->WriteSavePic(player, file, width, height); + GLSceneDrawer drawer; + drawer.WriteSavePic(player, file, width, height); } //=========================================================================== @@ -1115,7 +1114,8 @@ void FGLInterface::WriteSavePic (player_t *player, FileWriter *file, int width, void FGLInterface::RenderView(player_t *player) { - GLRenderer->RenderView(player); + GLSceneDrawer drawer; + drawer.RenderView(player); } //=========================================================================== @@ -1145,9 +1145,6 @@ void FGLInterface::RenderTextureView (FCanvasTexture *tex, AActor *Viewpoint, in int width = gltex->TextureWidth(); int height = gltex->TextureHeight(); - gl_fixedcolormap=CM_DEFAULT; - gl_RenderState.SetFixedColormap(CM_DEFAULT); - if (gl.legacyMode) { // In legacy mode, fail if the requested texture is too large. @@ -1165,7 +1162,10 @@ void FGLInterface::RenderTextureView (FCanvasTexture *tex, AActor *Viewpoint, in bounds.width=FHardwareTexture::GetTexDimension(gltex->GetWidth()); bounds.height=FHardwareTexture::GetTexDimension(gltex->GetHeight()); - GLRenderer->RenderViewpoint(Viewpoint, &bounds, FOV, (float)width/height, (float)width/height, false, false); + GLSceneDrawer drawer; + gl_fixedcolormap = CM_DEFAULT; + gl_RenderState.SetFixedColormap(CM_DEFAULT); + drawer.RenderViewpoint(Viewpoint, &bounds, FOV, (float)width/height, (float)width/height, false, false); if (gl.legacyMode) { diff --git a/src/gl/scene/gl_scenedrawer.h b/src/gl/scene/gl_scenedrawer.h index 375a8bdc18..fda91e6866 100644 --- a/src/gl/scene/gl_scenedrawer.h +++ b/src/gl/scene/gl_scenedrawer.h @@ -45,8 +45,16 @@ class GLSceneDrawer void SetViewAngle(DAngle viewangle); void SetProjection(VSMatrix matrix); void Set3DViewport(bool mainview); + void Reset3DViewport(); + void SetFixedColormap(player_t *player); void DrawScene(int drawmode); void ProcessScene(bool toscreen = false); + void DrawBlend(sector_t * viewsector); + void EndDrawScene(sector_t * viewsector); + + sector_t *RenderViewpoint(AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); + void RenderView(player_t *player); + void WriteSavePic(player_t *player, FileWriter *file, int width, int height); void InitClipper(angle_t a1, angle_t a2) { From b398c7458cfeb90f2ad2719160d59b7bdaac56da Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 11 Mar 2017 14:58:33 +0200 Subject: [PATCH 3/3] Do not draw crosshair on automap with alternative HUD enabled --- src/d_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index a706bb5384..65ae2186ad 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -808,7 +808,7 @@ void D_Display () { StatusBar->DrawBottomStuff (HUD_AltHud); if (DrawFSHUD || automapactive) DrawHUD(); - if (players[consoleplayer].camera && players[consoleplayer].camera->player) + if (players[consoleplayer].camera && players[consoleplayer].camera->player && !automapactive) { StatusBar->DrawCrosshair(); }