- save r_viewpoint as a whole when processing portals.

This commit is contained in:
Christoph Oelckers 2018-06-19 17:55:42 +02:00
parent 753cd0aede
commit 87dfa34f1f
8 changed files with 16 additions and 34 deletions

View file

@ -90,7 +90,6 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
mMirrorCount = 0;
mPlaneMirrorCount = 0;
mAngles = FRotator(0.f, 0.f, 0.f);
mViewVector = FVector2(0,0);
mVBO = nullptr;
mSkyVBO = nullptr;
mShaderManager = nullptr;

View file

@ -129,7 +129,6 @@ public:
FShadowMap mShadowMap;
FRotator mAngles;
FVector2 mViewVector;
FFlatVertexBuffer *mVBO;
FSkyVertexBuffer *mSkyVBO;

View file

@ -266,13 +266,8 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo **pDi)
}
// save viewpoint
savedViewPos = r_viewpoint.Pos;
savedViewActorPos = r_viewpoint.ActorPos;
savedshowviewer = r_viewpoint.showviewer;
savedAngles = r_viewpoint.Angles;
savedviewpoint = r_viewpoint;
savedviewactor=GLRenderer->mViewActor;
savedviewpath[0] = r_viewpoint.Path[0];
savedviewpath[1] = r_viewpoint.Path[1];
savedvisibility = r_viewpoint.camera ? r_viewpoint.camera->renderflags & RF_MAYBEINVISIBLE : ActorRenderFlags::FromInt(0);
@ -286,7 +281,8 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo **pDi)
inline void GLPortal::ClearClipper(FDrawInfo *di)
{
DAngle angleOffset = deltaangle(savedAngles.Yaw, r_viewpoint.Angles.Yaw);
FRenderViewpoint &oldvp = savedviewpoint;
DAngle angleOffset = deltaangle(oldvp.Angles.Yaw, r_viewpoint.Angles.Yaw);
di->mClipper->Clear();
@ -294,8 +290,8 @@ inline void GLPortal::ClearClipper(FDrawInfo *di)
di->mClipper->SafeAddClipRange(0,0xffffffff);
for (unsigned int i = 0; i < lines.Size(); i++)
{
DAngle startAngle = (DVector2(lines[i].glseg.x2, lines[i].glseg.y2) - savedViewPos).Angle() + angleOffset;
DAngle endAngle = (DVector2(lines[i].glseg.x1, lines[i].glseg.y1) - savedViewPos).Angle() + angleOffset;
DAngle startAngle = (DVector2(lines[i].glseg.x2, lines[i].glseg.y2) - oldvp.Pos).Angle() + angleOffset;
DAngle endAngle = (DVector2(lines[i].glseg.x1, lines[i].glseg.y1) - oldvp.Pos).Angle() + angleOffset;
if (deltaangle(endAngle, startAngle) < 0)
{
@ -329,12 +325,7 @@ void GLPortal::End(bool usestencil)
if (needdepth) FDrawInfo::EndDrawInfo();
// Restore the old view
r_viewpoint.Path[0] = savedviewpath[0];
r_viewpoint.Path[1] = savedviewpath[1];
r_viewpoint.Pos = savedViewPos;
r_viewpoint.showviewer = savedshowviewer;
r_viewpoint.ActorPos = savedViewActorPos;
r_viewpoint.Angles = savedAngles;
r_viewpoint = savedviewpoint;
GLRenderer->mViewActor=savedviewactor;
if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags = (r_viewpoint.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility;
drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
@ -389,10 +380,7 @@ void GLPortal::End(bool usestencil)
glDepthMask(true);
}
// Restore the old view
r_viewpoint.showviewer = savedshowviewer;
r_viewpoint.ActorPos = savedViewActorPos;
r_viewpoint.Pos = savedViewPos;
r_viewpoint.Angles = savedAngles;
r_viewpoint = savedviewpoint;
GLRenderer->mViewActor=savedviewactor;
if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags |= savedvisibility;
drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));

View file

@ -37,6 +37,7 @@
#define __GL_PORTAL_H
#include "tarray.h"
#include "r_utility.h"
#include "actor.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/scene/gl_drawinfo.h"
@ -69,13 +70,9 @@ public:
private:
void DrawPortalStencil();
DVector3 savedviewpath[2];
DVector3 savedViewPos;
DVector3 savedViewActorPos;
DRotator savedAngles;
bool savedshowviewer;
AActor * savedviewactor;
ActorRenderFlags savedvisibility;
FRenderViewpoint savedviewpoint;
GLPortal *PrevPortal;
TArray<unsigned int> mPrimIndices;

View file

@ -151,8 +151,8 @@ void GLSceneDrawer::SetViewAngle(DAngle viewangle)
FRenderViewpoint &vp = r_viewpoint;
GLRenderer->mAngles.Yaw = float(270.0-viewangle.Degrees);
DVector2 v = vp.Angles.Yaw.ToVector();
GLRenderer->mViewVector.X = v.X;
GLRenderer->mViewVector.Y = v.Y;
vp.ViewVector.X = v.X;
vp.ViewVector.Y = v.Y;
vp.SetViewAngle(r_viewwindow);
}
@ -236,7 +236,6 @@ void GLSceneDrawer::CreateScene(FDrawInfo *di)
validcount++; // used for processing sidedefs only once by the renderer.
di->mAngles = GLRenderer->mAngles;
di->mViewVector = GLRenderer->mViewVector;
di->mViewActor = GLRenderer->mViewActor;
di->mShadowMap = &GLRenderer->mShadowMap;

View file

@ -84,7 +84,6 @@ struct HWDrawInfo
std::atomic<int> spriteindex;
IPortal *mClipPortal;
FRotator mAngles;
FVector2 mViewVector;
AActor *mViewActor;
IShadowMap *mShadowMap;
Clipper *mClipper;

View file

@ -597,8 +597,8 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
switch (spritetype)
{
case RF_FACESPRITE:
viewvecX = di->mViewVector.X;
viewvecY = di->mViewVector.Y;
viewvecX = vp.ViewVector.X;
viewvecY = vp.ViewVector.Y;
x1 = x - viewvecY*leftfac;
x2 = x - viewvecY*rightfac;
@ -946,8 +946,8 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t *
else factor = 1 / 7.f;
float scalefac=particle->size * factor;
float viewvecX = di->mViewVector.X;
float viewvecY = di->mViewVector.Y;
float viewvecX = vp.ViewVector.X;
float viewvecY = vp.ViewVector.Y;
x1=x+viewvecY*scalefac;
x2=x-viewvecY*scalefac;

View file

@ -21,6 +21,7 @@ struct FRenderViewpoint
DVector3 Pos; // Camera position
DVector3 ActorPos; // Camera actor's position
DRotator Angles; // Camera angles
DVector2 ViewVector; // HWR only: direction the camera is facing.
DVector3 Path[2]; // View path for portal calculations
double Cos; // cos(Angles.Yaw)