diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 55009e2ce..3a3f6b328 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -468,8 +468,8 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); HWViewpointUniforms matrices; + matrices.SetDefaults(); matrices.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f); - matrices.mViewMatrix.loadIdentity(); matrices.CalcDependencies(); GLRenderer->mShaderManager->ApplyMatrices(&matrices, NORMAL_PASS); diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 0d891efc8..c830499fd 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -96,7 +96,6 @@ void FRenderState::Reset() mInterpolationFactor = 0.0f; mColor.Set(1.0f, 1.0f, 1.0f, 1.0f); - mCameraPos.Set(0.0f, 0.0f, 0.0f, 0.0f); mGlowTop.Set(0.0f, 0.0f, 0.0f, 0.0f); mGlowBottom.Set(0.0f, 0.0f, 0.0f, 0.0f); mGlowTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); @@ -163,7 +162,6 @@ bool FRenderState::ApplyShader() activeShader->muPalLightLevels.Set(static_cast(gl_bandedswlight) | (static_cast(gl_fogmode) << 8)); activeShader->muGlobVis.Set(GLRenderer->mGlobVis / 32.0f); activeShader->muTextureMode.Set(mTextureMode == TM_MODULATE && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode); - activeShader->muCameraPos.Set(mCameraPos.vec); activeShader->muLightParms.Set(mLightParms); activeShader->muFogColor.Set(mFogColor); activeShader->muObjectColor.Set(mObjectColor); @@ -176,7 +174,6 @@ bool FRenderState::ApplyShader() activeShader->muAlphaThreshold.Set(mAlphaThreshold); activeShader->muLightIndex.Set(-1); activeShader->muClipSplit.Set(mClipSplit); - activeShader->muViewHeight.Set(viewheight); activeShader->muSpecularMaterial.Set(mGlossiness, mSpecularLevel); if (mGlowEnabled) diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 21d0f2265..257ef56a8 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -103,7 +103,6 @@ class FRenderState FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer; FStateVec4 mNormal; FStateVec4 mColor; - FStateVec4 mCameraPos; FStateVec4 mGlowTop, mGlowBottom; FStateVec4 mGlowTopPlane, mGlowBottomPlane; FStateVec4 mSplitTopPlane, mSplitBottomPlane; @@ -344,11 +343,6 @@ public: mTextureMatrixEnabled = on; } - void SetCameraPos(float x, float y, float z) - { - mCameraPos.Set(x, z, y, 0); - } - void SetGlowParams(float *t, float *b) { mGlowTop.Set(t[0], t[1], t[2], t[3]); diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index da5c5fa38..c123007ed 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -44,6 +44,17 @@ #include "gl/renderer/gl_quaddrawer.h" #include "gl/dynlights/gl_lightbuffer.h" +class FDrawInfoList +{ +public: + TDeletingArray mList; + + + FDrawInfo * GetNew(); + void Release(FDrawInfo *); +}; + + static FDrawInfo * gl_drawinfo; FDrawInfoList di_list; @@ -228,11 +239,10 @@ void FDrawInfo::StartScene() //========================================================================== FDrawInfo *FDrawInfo::EndDrawInfo() { - FDrawInfo * di = gl_drawinfo; - - for(int i=0;idrawlists[i].Reset(); - gl_drawinfo=di->next; - di_list.Release(di); + assert(this == gl_drawinfo); + for(int i=0;i mList; - -public: - - FDrawInfo *GetNew(); - void Release(FDrawInfo *); -}; - void gl_SetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblending); diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index d516e37ee..1c3b7c3b1 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -158,7 +158,6 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn rendered_portals++; Clocker c(PortalAll); - *pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint, &outer_di->VPUniforms); if (usestencil) { if (!gl_portals) @@ -254,6 +253,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn glDisable(GL_DEPTH_TEST); } } + *pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint, &outer_di->VPUniforms); // save viewpoint savedvisibility = outer_di->Viewpoint.camera ? outer_di->Viewpoint.camera->renderflags & RF_MAYBEINVISIBLE : ActorRenderFlags::FromInt(0); @@ -316,7 +316,7 @@ void GLPortal::End(FDrawInfo *di, bool usestencil) // Restore the old view if (vp.camera != nullptr) vp.camera->renderflags = (vp.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; - di->SetupView(vp, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); { ScopedColorMask colorMask(0, 0, 0, 0); // glColorMask(0, 0, 0, 0); // no graphics @@ -370,7 +370,7 @@ void GLPortal::End(FDrawInfo *di, bool usestencil) // Restore the old view if (vp.camera != nullptr) vp.camera->renderflags = (vp.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; - di->SetupView(vp, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.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. @@ -577,7 +577,7 @@ void GLSkyboxPortal::DrawContents(FDrawInfo *di) vp.ViewActor = origin; inskybox = true; - di->SetupView(vp, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); di->SetViewArea(); ClearClipper(di); @@ -684,7 +684,7 @@ void GLSectorStackPortal::DrawContents(FDrawInfo *di) // avoid recursions! if (origin->plane != -1) screen->instack[origin->plane]++; - di->SetupView(vp, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); SetupCoverage(di); ClearClipper(di); @@ -740,7 +740,7 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di) PlaneMirrorMode = origin->fC() < 0 ? -1 : 1; PlaneMirrorFlag++; - di->SetupView(vp, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); ClearClipper(di); di->UpdateCurrentMapSection(); @@ -911,7 +911,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di) vp.ViewActor = nullptr; MirrorFlag++; - di->SetupView(vp, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); di->mClipper->Clear(); @@ -988,7 +988,7 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di) } vp.ViewActor = nullptr; - di->SetupView(vp, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); ClearClipper(di); gl_RenderState.SetClipLine(glport->lines[0]->mDestination); @@ -1104,7 +1104,7 @@ void GLHorizonPortal::DrawContents(FDrawInfo *di) ClearScreen(di); return; } - gl_RenderState.SetCameraPos(vp.Pos.X, vp.Pos.Y, vp.Pos.Z); + di->SetCameraPos(vp.Pos); if (gltexture && gltexture->tex->isFullbright()) diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 10c67c809..86cb361fb 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -104,10 +104,12 @@ void FDrawInfo::SetViewMatrix(const FRotator &angles, float vx, float vy, float // Setup the view rotation matrix for the given viewpoint // //----------------------------------------------------------------------------- -void FDrawInfo::SetupView(FRenderViewpoint &vp, float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror) +void FDrawInfo::SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror) { + auto &vp = Viewpoint; vp.SetViewAngle(r_viewwindow); SetViewMatrix(vp.HWAngles, vx, vy, vz, mirror, planemirror); + SetCameraPos(vp.Pos); ApplyVPUniforms(); } @@ -182,8 +184,6 @@ void FDrawInfo::RenderScene(int recursion) glDepthMask(true); if (!gl_no_skyclear) GLPortal::RenderFirstSkyPortal(recursion, this); - gl_RenderState.SetCameraPos(vp.Pos.X, vp.Pos.Y, vp.Pos.Z); - gl_RenderState.EnableFog(true); gl_RenderState.BlendFunc(GL_ONE,GL_ZERO); @@ -287,12 +287,8 @@ void FDrawInfo::RenderScene(int recursion) void FDrawInfo::RenderTranslucent() { - const auto &vp = Viewpoint; - RenderAll.Clock(); - gl_RenderState.SetCameraPos(vp.Pos.X, vp.Pos.Y, vp.Pos.Z); - // final pass: translucent stuff gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index 1ca523705..52db58670 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -230,7 +230,7 @@ void GLSkyPortal::DrawContents(FDrawInfo *di) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); bool oldClamp = gl_RenderState.SetDepthClamp(true); - di->SetupView(vp, 0, 0, 0, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + di->SetupView(0, 0, 0, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO); if (origin->texture[0] && origin->texture[0]->tex->bSkybox) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index f50fb595a..d1ba1f8a6 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -311,7 +311,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muPalLightLevels.Init(hShader, "uPalLightLevels"); muGlobVis.Init(hShader, "uGlobVis"); muTextureMode.Init(hShader, "uTextureMode"); - muCameraPos.Init(hShader, "uCameraPos"); muLightParms.Init(hShader, "uLightAttr"); muClipSplit.Init(hShader, "uClipSplit"); muLightIndex.Init(hShader, "uLightIndex"); @@ -331,7 +330,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muClipHeightDirection.Init(hShader, "uClipHeightDirection"); muAlphaThreshold.Init(hShader, "uAlphaThreshold"); muSpecularMaterial.Init(hShader, "uSpecularMaterial"); - muViewHeight.Init(hShader, "uViewHeight"); muTimer.Init(hShader, "timer"); lights_index = glGetUniformLocation(hShader, "lights"); @@ -345,6 +343,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * normalviewmatrix_index = glGetUniformLocation(hShader, "NormalViewMatrix"); normalmodelmatrix_index = glGetUniformLocation(hShader, "NormalModelMatrix"); quadmode_index = glGetUniformLocation(hShader, "uQuadMode"); + viewheight_index = glGetUniformLocation(hShader, "uViewHeight"); + camerapos_index = glGetUniformLocation(hShader, "uCameraPos"); if (!(gl.flags & RFL_SHADER_STORAGE_BUFFER)) { @@ -441,6 +441,9 @@ void FShader::ApplyMatrices(HWViewpointUniforms *u) glUniformMatrix4fv(projectionmatrix_index, 1, false, u->mProjectionMatrix.get()); glUniformMatrix4fv(viewmatrix_index, 1, false, u->mViewMatrix.get()); glUniformMatrix4fv(normalviewmatrix_index, 1, false, u->mNormalViewMatrix.get()); + + glUniform4fv(camerapos_index, 1, &u->mCameraPos[0]); + glUniform1i(viewheight_index, u->mViewHeight); } //========================================================================== diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 10503f527..26d66fe28 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -246,7 +246,6 @@ class FShader FBufferedUniform1i muPalLightLevels; FBufferedUniform1f muGlobVis; FBufferedUniform1i muTextureMode; - FBufferedUniform4f muCameraPos; FBufferedUniform4f muLightParms; FBufferedUniform2f muClipSplit; FBufferedUniform1i muLightIndex; @@ -265,17 +264,20 @@ class FShader FBufferedUniform1f muClipHeight; FBufferedUniform1f muClipHeightDirection; FBufferedUniform1f muAlphaThreshold; - FBufferedUniform1i muViewHeight; FBufferedUniform2f muSpecularMaterial; FBufferedUniform1f muTimer; int lights_index; - int projectionmatrix_index; - int viewmatrix_index; - int normalviewmatrix_index; int modelmatrix_index; int normalmodelmatrix_index; int texturematrix_index; + + int projectionmatrix_index; + int viewmatrix_index; + int normalviewmatrix_index; + int viewheight_index; + int camerapos_index; + public: int vertexmatrix_index; int texcoordmatrix_index; diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 11c3c8e5f..f62c12a62 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -1,6 +1,7 @@ #pragma once #include +#include "vectors.h" #include "r_defs.h" #include "r_utility.h" #include "hw_viewpointuniforms.h" @@ -151,6 +152,12 @@ private: void RenderThings(subsector_t * sub, sector_t * sector); void DoSubsector(subsector_t * sub); public: + + void SetCameraPos(const DVector3 &pos) + { + VPUniforms.mCameraPos = { (float)pos.X, (float)pos.Z, (float)pos.Y, 0.f }; + } + void RenderBSPNode(void *node); void ClearBuffers(); diff --git a/src/hwrenderer/scene/hw_viewpointuniforms.h b/src/hwrenderer/scene/hw_viewpointuniforms.h index 1fdbcc4d1..7dc76317e 100644 --- a/src/hwrenderer/scene/hw_viewpointuniforms.h +++ b/src/hwrenderer/scene/hw_viewpointuniforms.h @@ -1,13 +1,17 @@ #pragma once #include "r_data/matrix.h" +#include "r_utility.h" struct HWViewpointUniforms { - VSMatrix mProjectionMatrix; - VSMatrix mViewMatrix; - VSMatrix mNormalViewMatrix; + VSMatrix mProjectionMatrix; + VSMatrix mViewMatrix; + VSMatrix mNormalViewMatrix; + FVector4 mCameraPos; + FVector4 mClipLine; + int mViewHeight; void CalcDependencies() { mNormalViewMatrix.computeNormalMatrix(mViewMatrix); @@ -18,6 +22,7 @@ struct HWViewpointUniforms mProjectionMatrix.loadIdentity(); mViewMatrix.loadIdentity(); mNormalViewMatrix.loadIdentity(); + mViewHeight = viewheight; } };