mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 12:32:34 +00:00
- move view and projection matrices to DrawInfo.
This commit is contained in:
parent
b106f72741
commit
1967165633
27 changed files with 80 additions and 94 deletions
|
@ -50,7 +50,7 @@ CVAR(Bool, gl_light_models, true, CVAR_ARCHIVE)
|
||||||
VSMatrix FGLModelRenderer::GetViewToWorldMatrix()
|
VSMatrix FGLModelRenderer::GetViewToWorldMatrix()
|
||||||
{
|
{
|
||||||
VSMatrix objectToWorldMatrix;
|
VSMatrix objectToWorldMatrix;
|
||||||
gl_RenderState.mViewMatrix.inverseMatrix(objectToWorldMatrix);
|
di->VPUniforms.mViewMatrix.inverseMatrix(objectToWorldMatrix);
|
||||||
return objectToWorldMatrix;
|
return objectToWorldMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,14 @@
|
||||||
#include "r_data/models/models.h"
|
#include "r_data/models/models.h"
|
||||||
|
|
||||||
class GLSprite;
|
class GLSprite;
|
||||||
|
struct FDrawInfo;
|
||||||
|
|
||||||
class FGLModelRenderer : public FModelRenderer
|
class FGLModelRenderer : public FModelRenderer
|
||||||
{
|
{
|
||||||
int modellightindex = -1;
|
int modellightindex = -1;
|
||||||
|
FDrawInfo *di;
|
||||||
public:
|
public:
|
||||||
FGLModelRenderer(int mli) : modellightindex(mli)
|
FGLModelRenderer(FDrawInfo *d, int mli) : modellightindex(mli), di(d)
|
||||||
{}
|
{}
|
||||||
ModelRendererType GetType() const override { return GLModelRendererType; }
|
ModelRendererType GetType() const override { return GLModelRendererType; }
|
||||||
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
|
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define __GL_LIGHTDATA
|
#define __GL_LIGHTDATA
|
||||||
|
|
||||||
#include "v_palette.h"
|
#include "v_palette.h"
|
||||||
#include "p_3dfloors.h"
|
#include "r_defs.h"
|
||||||
#include "r_data/renderstyle.h"
|
#include "r_data/renderstyle.h"
|
||||||
#include "hwrenderer/utility/hw_lighting.h"
|
#include "hwrenderer/utility/hw_lighting.h"
|
||||||
#include "r_data/colormaps.h"
|
#include "r_data/colormaps.h"
|
||||||
|
|
|
@ -81,7 +81,7 @@ void FGLRenderer::PostProcessScene(int fixedcm, const std::function<void()> &aft
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void FGLRenderer::AmbientOccludeScene()
|
void FGLRenderer::AmbientOccludeScene(float m5)
|
||||||
{
|
{
|
||||||
FGLDebug::PushGroup("AmbientOccludeScene");
|
FGLDebug::PushGroup("AmbientOccludeScene");
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
float aoStrength = gl_ssao_strength;
|
float aoStrength = gl_ssao_strength;
|
||||||
|
|
||||||
//float tanHalfFovy = tan(fovy * (M_PI / 360.0f));
|
//float tanHalfFovy = tan(fovy * (M_PI / 360.0f));
|
||||||
float tanHalfFovy = 1.0f / gl_RenderState.mProjectionMatrix.get()[5];
|
float tanHalfFovy = 1.0f / m5;
|
||||||
float invFocalLenX = tanHalfFovy * (mBuffers->GetSceneWidth() / (float)mBuffers->GetSceneHeight());
|
float invFocalLenX = tanHalfFovy * (mBuffers->GetSceneWidth() / (float)mBuffers->GetSceneHeight());
|
||||||
float invFocalLenY = tanHalfFovy;
|
float invFocalLenY = tanHalfFovy;
|
||||||
float nDotVBias = clamp(bias, 0.0f, 1.0f);
|
float nDotVBias = clamp(bias, 0.0f, 1.0f);
|
||||||
|
|
|
@ -467,9 +467,11 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
||||||
const auto &mScreenViewport = screen->mScreenViewport;
|
const auto &mScreenViewport = screen->mScreenViewport;
|
||||||
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
|
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
|
||||||
|
|
||||||
gl_RenderState.mViewMatrix.loadIdentity();
|
HWViewpointUniforms matrices;
|
||||||
gl_RenderState.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f);
|
matrices.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f);
|
||||||
gl_RenderState.ApplyMatrices();
|
matrices.mViewMatrix.loadIdentity();
|
||||||
|
matrices.CalcDependencies();
|
||||||
|
GLRenderer->mShaderManager->ApplyMatrices(&matrices.mProjectionMatrix, &matrices.mViewMatrix, &matrices.mNormalViewMatrix, NORMAL_PASS);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ public:
|
||||||
|
|
||||||
void RenderScreenQuad();
|
void RenderScreenQuad();
|
||||||
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D);
|
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D);
|
||||||
void AmbientOccludeScene();
|
void AmbientOccludeScene(float m5);
|
||||||
void UpdateCameraExposure();
|
void UpdateCameraExposure();
|
||||||
void BloomScene(int fixedcm);
|
void BloomScene(int fixedcm);
|
||||||
void TonemapScene();
|
void TonemapScene();
|
||||||
|
|
|
@ -107,8 +107,6 @@ void FRenderState::Reset()
|
||||||
mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f);
|
mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
mEffectState = 0;
|
mEffectState = 0;
|
||||||
activeShader = nullptr;
|
activeShader = nullptr;
|
||||||
mProjectionMatrix.loadIdentity();
|
|
||||||
mViewMatrix.loadIdentity();
|
|
||||||
mModelMatrix.loadIdentity();
|
mModelMatrix.loadIdentity();
|
||||||
mTextureMatrix.loadIdentity();
|
mTextureMatrix.loadIdentity();
|
||||||
mPassType = NORMAL_PASS;
|
mPassType = NORMAL_PASS;
|
||||||
|
@ -304,17 +302,6 @@ void FRenderState::ApplyColorMask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FRenderState::ApplyMatrices()
|
|
||||||
{
|
|
||||||
if (GLRenderer->mShaderManager != NULL)
|
|
||||||
{
|
|
||||||
VSMatrix norm;
|
|
||||||
norm.computeNormalMatrix(mViewMatrix);
|
|
||||||
|
|
||||||
GLRenderer->mShaderManager->ApplyMatrices(&mProjectionMatrix, &mViewMatrix, &norm, mPassType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FRenderState::ApplyLightIndex(int index)
|
void FRenderState::ApplyLightIndex(int index)
|
||||||
{
|
{
|
||||||
if (index > -1 && GLRenderer->mLights->GetBufferType() == GL_UNIFORM_BUFFER)
|
if (index > -1 && GLRenderer->mLights->GetBufferType() == GL_UNIFORM_BUFFER)
|
||||||
|
|
|
@ -131,11 +131,8 @@ class FRenderState
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VSMatrix mProjectionMatrix;
|
|
||||||
VSMatrix mViewMatrix;
|
|
||||||
VSMatrix mModelMatrix;
|
VSMatrix mModelMatrix;
|
||||||
VSMatrix mTextureMatrix;
|
VSMatrix mTextureMatrix;
|
||||||
VSMatrix mNormalViewMatrix;
|
|
||||||
|
|
||||||
FRenderState()
|
FRenderState()
|
||||||
{
|
{
|
||||||
|
@ -162,7 +159,6 @@ public:
|
||||||
|
|
||||||
void Apply();
|
void Apply();
|
||||||
void ApplyColorMask();
|
void ApplyColorMask();
|
||||||
void ApplyMatrices();
|
|
||||||
void ApplyLightIndex(int index);
|
void ApplyLightIndex(int index);
|
||||||
|
|
||||||
void SetVertexBuffer(FVertexBuffer *vb)
|
void SetVertexBuffer(FVertexBuffer *vb)
|
||||||
|
|
|
@ -190,12 +190,14 @@ FDrawInfo::~FDrawInfo()
|
||||||
// OpenGL has no use for multiple clippers so use the same one for all DrawInfos.
|
// OpenGL has no use for multiple clippers so use the same one for all DrawInfos.
|
||||||
static Clipper staticClipper;
|
static Clipper staticClipper;
|
||||||
|
|
||||||
FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp)
|
FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms)
|
||||||
{
|
{
|
||||||
FDrawInfo *di=di_list.GetNew();
|
FDrawInfo *di=di_list.GetNew();
|
||||||
di->mVBO = GLRenderer->mVBO;
|
di->mVBO = GLRenderer->mVBO;
|
||||||
di->mClipper = &staticClipper;
|
di->mClipper = &staticClipper;
|
||||||
di->Viewpoint = parentvp;
|
di->Viewpoint = parentvp;
|
||||||
|
if (uniforms) di->VPUniforms = *uniforms;
|
||||||
|
else di->VPUniforms.SetDefaults();
|
||||||
di->mClipper->SetViewpoint(di->Viewpoint);
|
di->mClipper->SetViewpoint(di->Viewpoint);
|
||||||
staticClipper.Clear();
|
staticClipper.Clear();
|
||||||
di->StartScene();
|
di->StartScene();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "gl/renderer/gl_lightdata.h"
|
#include "gl/renderer/gl_lightdata.h"
|
||||||
#include "hwrenderer/scene/hw_drawlist.h"
|
#include "hwrenderer/scene/hw_drawlist.h"
|
||||||
#include "hwrenderer/scene/hw_weapon.h"
|
#include "hwrenderer/scene/hw_weapon.h"
|
||||||
|
#include "hwrenderer/scene/hw_viewpointuniforms.h"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable:4244)
|
#pragma warning(disable:4244)
|
||||||
|
@ -42,6 +43,8 @@ struct FDrawInfo : public HWDrawInfo
|
||||||
FDrawInfo();
|
FDrawInfo();
|
||||||
~FDrawInfo();
|
~FDrawInfo();
|
||||||
|
|
||||||
|
void ApplyVPUniforms() override;
|
||||||
|
|
||||||
void AddWall(GLWall *wall) override;
|
void AddWall(GLWall *wall) override;
|
||||||
void AddMirrorSurface(GLWall *w) override;
|
void AddMirrorSurface(GLWall *w) override;
|
||||||
GLDecal *AddDecal(bool onmirror) override;
|
GLDecal *AddDecal(bool onmirror) override;
|
||||||
|
@ -110,12 +113,11 @@ struct FDrawInfo : public HWDrawInfo
|
||||||
void DrawEndScene2D(sector_t * viewsector);
|
void DrawEndScene2D(sector_t * viewsector);
|
||||||
|
|
||||||
// These should go into hwrenderer later.
|
// These should go into hwrenderer later.
|
||||||
void SetProjection(VSMatrix matrix);
|
|
||||||
void SetViewMatrix(const FRotator &angles, float vx, float vy, float vz, bool mirror, bool planemirror);
|
void SetViewMatrix(const FRotator &angles, float vx, float vy, float vz, bool mirror, bool planemirror);
|
||||||
void SetupView(FRenderViewpoint &vp, float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror);
|
void SetupView(FRenderViewpoint &vp, float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror);
|
||||||
|
|
||||||
|
|
||||||
static FDrawInfo *StartDrawInfo(FRenderViewpoint &parentvp);
|
static FDrawInfo *StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms);
|
||||||
FDrawInfo *EndDrawInfo();
|
FDrawInfo *EndDrawInfo();
|
||||||
|
|
||||||
gl_subsectorrendernode * GetOtherFloorPlanes(unsigned int sector)
|
gl_subsectorrendernode * GetOtherFloorPlanes(unsigned int sector)
|
||||||
|
|
|
@ -93,15 +93,13 @@ void GLPortal::BeginScene()
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
void GLPortal::ClearScreen()
|
void GLPortal::ClearScreen(FDrawInfo *di)
|
||||||
{
|
{
|
||||||
bool multi = !!glIsEnabled(GL_MULTISAMPLE);
|
bool multi = !!glIsEnabled(GL_MULTISAMPLE);
|
||||||
gl_MatrixStack.Push(gl_RenderState.mViewMatrix);
|
|
||||||
gl_MatrixStack.Push(gl_RenderState.mProjectionMatrix);
|
|
||||||
|
|
||||||
gl_RenderState.mViewMatrix.loadIdentity();
|
di->VPUniforms.mViewMatrix.loadIdentity();
|
||||||
gl_RenderState.mProjectionMatrix.ortho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1.0f, 1.0f);
|
di->VPUniforms.mProjectionMatrix.ortho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1.0f, 1.0f);
|
||||||
gl_RenderState.ApplyMatrices();
|
di->ApplyVPUniforms();
|
||||||
gl_RenderState.SetColor(0, 0, 0);
|
gl_RenderState.SetColor(0, 0, 0);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
|
||||||
|
@ -111,9 +109,6 @@ void GLPortal::ClearScreen()
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::FULLSCREEN_INDEX, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::FULLSCREEN_INDEX, 4);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
gl_MatrixStack.Pop(gl_RenderState.mProjectionMatrix);
|
|
||||||
gl_MatrixStack.Pop(gl_RenderState.mViewMatrix);
|
|
||||||
gl_RenderState.ApplyMatrices();
|
|
||||||
if (multi) glEnable(GL_MULTISAMPLE);
|
if (multi) glEnable(GL_MULTISAMPLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +157,8 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
|
||||||
*pDi = nullptr;
|
*pDi = nullptr;
|
||||||
rendered_portals++;
|
rendered_portals++;
|
||||||
Clocker c(PortalAll);
|
Clocker c(PortalAll);
|
||||||
|
|
||||||
|
*pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint, &outer_di->VPUniforms);
|
||||||
if (usestencil)
|
if (usestencil)
|
||||||
{
|
{
|
||||||
if (!gl_portals)
|
if (!gl_portals)
|
||||||
|
@ -226,7 +223,6 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -244,7 +240,6 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
|
||||||
gl_RenderState.SetEffect(EFF_NONE);
|
gl_RenderState.SetEffect(EFF_NONE);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDepthMask(false); // don't write to Z-buffer!
|
glDepthMask(false); // don't write to Z-buffer!
|
||||||
*pDi = outer_di;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recursion++;
|
recursion++;
|
||||||
|
@ -253,15 +248,10 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (NeedDepthBuffer())
|
if (!NeedDepthBuffer())
|
||||||
{
|
|
||||||
*pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
glDepthMask(false);
|
glDepthMask(false);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
*pDi = outer_di;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,9 +308,10 @@ void GLPortal::End(FDrawInfo *di, bool usestencil)
|
||||||
if (PrevPortal != nullptr) PrevPortal->PopState();
|
if (PrevPortal != nullptr) PrevPortal->PopState();
|
||||||
GLRenderer->mCurrentPortal = PrevPortal;
|
GLRenderer->mCurrentPortal = PrevPortal;
|
||||||
|
|
||||||
|
di = di->EndDrawInfo();
|
||||||
|
di->ApplyVPUniforms();
|
||||||
if (usestencil)
|
if (usestencil)
|
||||||
{
|
{
|
||||||
if (needdepth) di = di->EndDrawInfo();
|
|
||||||
auto &vp = di->Viewpoint;
|
auto &vp = di->Viewpoint;
|
||||||
|
|
||||||
// Restore the old view
|
// Restore the old view
|
||||||
|
@ -368,7 +359,6 @@ void GLPortal::End(FDrawInfo *di, bool usestencil)
|
||||||
{
|
{
|
||||||
if (needdepth)
|
if (needdepth)
|
||||||
{
|
{
|
||||||
di = di->EndDrawInfo();
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -561,7 +551,7 @@ void GLSkyboxPortal::DrawContents(FDrawInfo *di)
|
||||||
|
|
||||||
if (skyboxrecursion >= 3)
|
if (skyboxrecursion >= 3)
|
||||||
{
|
{
|
||||||
ClearScreen();
|
ClearScreen(di);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto &vp = di->Viewpoint;
|
auto &vp = di->Viewpoint;
|
||||||
|
@ -732,7 +722,7 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di)
|
||||||
{
|
{
|
||||||
if (renderdepth > r_mirror_recursions)
|
if (renderdepth > r_mirror_recursions)
|
||||||
{
|
{
|
||||||
ClearScreen();
|
ClearScreen(di);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// A plane mirror needs to flip the portal exclusion logic because inside the mirror, up is down and down is up.
|
// A plane mirror needs to flip the portal exclusion logic because inside the mirror, up is down and down is up.
|
||||||
|
@ -856,7 +846,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
|
||||||
{
|
{
|
||||||
if (renderdepth>r_mirror_recursions)
|
if (renderdepth>r_mirror_recursions)
|
||||||
{
|
{
|
||||||
ClearScreen();
|
ClearScreen(di);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -958,7 +948,7 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di)
|
||||||
// TODO: Handle recursion more intelligently
|
// TODO: Handle recursion more intelligently
|
||||||
if (renderdepth>r_mirror_recursions)
|
if (renderdepth>r_mirror_recursions)
|
||||||
{
|
{
|
||||||
ClearScreen();
|
ClearScreen(di);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto &vp = di->Viewpoint;
|
auto &vp = di->Viewpoint;
|
||||||
|
@ -1111,7 +1101,7 @@ void GLHorizonPortal::DrawContents(FDrawInfo *di)
|
||||||
gltexture=FMaterial::ValidateTexture(sp->texture, false, true);
|
gltexture=FMaterial::ValidateTexture(sp->texture, false, true);
|
||||||
if (!gltexture)
|
if (!gltexture)
|
||||||
{
|
{
|
||||||
ClearScreen();
|
ClearScreen(di);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gl_RenderState.SetCameraPos(vp.Pos.X, vp.Pos.Y, vp.Pos.Z);
|
gl_RenderState.SetCameraPos(vp.Pos.X, vp.Pos.Y, vp.Pos.Z);
|
||||||
|
|
|
@ -88,7 +88,7 @@ protected:
|
||||||
virtual bool IsSky() { return false; }
|
virtual bool IsSky() { return false; }
|
||||||
virtual bool NeedCap() { return true; }
|
virtual bool NeedCap() { return true; }
|
||||||
virtual bool NeedDepthBuffer() { return true; }
|
virtual bool NeedDepthBuffer() { return true; }
|
||||||
void ClearScreen();
|
void ClearScreen(FDrawInfo *di);
|
||||||
virtual const char *GetName() = 0;
|
virtual const char *GetName() = 0;
|
||||||
virtual void PushState() {}
|
virtual void PushState() {}
|
||||||
virtual void PopState() {}
|
virtual void PopState() {}
|
||||||
|
|
|
@ -71,17 +71,11 @@ EXTERN_CVAR (Bool, r_deathcamera)
|
||||||
EXTERN_CVAR (Float, r_visibility)
|
EXTERN_CVAR (Float, r_visibility)
|
||||||
EXTERN_CVAR (Bool, r_drawvoxels)
|
EXTERN_CVAR (Bool, r_drawvoxels)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// SetProjection
|
|
||||||
// sets projection matrix
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void FDrawInfo::SetProjection(VSMatrix matrix)
|
void FDrawInfo::ApplyVPUniforms()
|
||||||
{
|
{
|
||||||
gl_RenderState.mProjectionMatrix.loadIdentity();
|
VPUniforms.CalcDependencies();
|
||||||
gl_RenderState.mProjectionMatrix.multMatrix(matrix);
|
GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms.mProjectionMatrix, &VPUniforms.mViewMatrix, &VPUniforms.mNormalViewMatrix, NORMAL_PASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -95,12 +89,12 @@ void FDrawInfo::SetViewMatrix(const FRotator &angles, float vx, float vy, float
|
||||||
float mult = mirror? -1:1;
|
float mult = mirror? -1:1;
|
||||||
float planemult = planemirror? -level.info->pixelstretch : level.info->pixelstretch;
|
float planemult = planemirror? -level.info->pixelstretch : level.info->pixelstretch;
|
||||||
|
|
||||||
gl_RenderState.mViewMatrix.loadIdentity();
|
VPUniforms.mViewMatrix.loadIdentity();
|
||||||
gl_RenderState.mViewMatrix.rotate(angles.Roll.Degrees, 0.0f, 0.0f, 1.0f);
|
VPUniforms.mViewMatrix.rotate(angles.Roll.Degrees, 0.0f, 0.0f, 1.0f);
|
||||||
gl_RenderState.mViewMatrix.rotate(angles.Pitch.Degrees, 1.0f, 0.0f, 0.0f);
|
VPUniforms.mViewMatrix.rotate(angles.Pitch.Degrees, 1.0f, 0.0f, 0.0f);
|
||||||
gl_RenderState.mViewMatrix.rotate(angles.Yaw.Degrees, 0.0f, mult, 0.0f);
|
VPUniforms.mViewMatrix.rotate(angles.Yaw.Degrees, 0.0f, mult, 0.0f);
|
||||||
gl_RenderState.mViewMatrix.translate(vx * mult, -vz * planemult , -vy);
|
VPUniforms.mViewMatrix.translate(vx * mult, -vz * planemult , -vy);
|
||||||
gl_RenderState.mViewMatrix.scale(-mult, planemult, 1);
|
VPUniforms.mViewMatrix.scale(-mult, planemult, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +108,7 @@ void FDrawInfo::SetupView(FRenderViewpoint &vp, float vx, float vy, float vz, DA
|
||||||
{
|
{
|
||||||
vp.SetViewAngle(r_viewwindow);
|
vp.SetViewAngle(r_viewwindow);
|
||||||
SetViewMatrix(vp.HWAngles, vx, vy, vz, mirror, planemirror);
|
SetViewMatrix(vp.HWAngles, vx, vy, vz, mirror, planemirror);
|
||||||
gl_RenderState.ApplyMatrices();
|
ApplyVPUniforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -364,11 +358,11 @@ void FDrawInfo::DrawScene(int drawmode)
|
||||||
if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS)
|
if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS)
|
||||||
{
|
{
|
||||||
gl_RenderState.EnableDrawBuffers(1);
|
gl_RenderState.EnableDrawBuffers(1);
|
||||||
GLRenderer->AmbientOccludeScene();
|
GLRenderer->AmbientOccludeScene(VPUniforms.mProjectionMatrix.get()[5]);
|
||||||
GLRenderer->mBuffers->BindSceneFB(true);
|
GLRenderer->mBuffers->BindSceneFB(true);
|
||||||
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
gl_RenderState.ApplyMatrices();
|
ApplyVPUniforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle all portals after rendering the opaque objects but before
|
// Handle all portals after rendering the opaque objects but before
|
||||||
|
@ -414,9 +408,9 @@ void FDrawInfo::DrawEndScene2D(sector_t * viewsector)
|
||||||
const bool renderHUDModel = IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player);
|
const bool renderHUDModel = IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player);
|
||||||
|
|
||||||
// This should be removed once all 2D stuff is really done through the 2D interface.
|
// This should be removed once all 2D stuff is really done through the 2D interface.
|
||||||
gl_RenderState.mViewMatrix.loadIdentity();
|
VPUniforms.mViewMatrix.loadIdentity();
|
||||||
gl_RenderState.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f);
|
VPUniforms.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f);
|
||||||
gl_RenderState.ApplyMatrices();
|
ApplyVPUniforms();
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_MULTISAMPLE);
|
glDisable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
|
@ -510,20 +504,20 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came
|
||||||
screen->SetViewportRects(bounds);
|
screen->SetViewportRects(bounds);
|
||||||
Set3DViewport(mainview);
|
Set3DViewport(mainview);
|
||||||
|
|
||||||
FDrawInfo *di = FDrawInfo::StartDrawInfo(mainvp);
|
FDrawInfo *di = FDrawInfo::StartDrawInfo(mainvp, nullptr);
|
||||||
auto vp = di->Viewpoint;
|
auto vp = di->Viewpoint;
|
||||||
di->SetViewArea();
|
di->SetViewArea();
|
||||||
auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr);
|
auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr);
|
||||||
di->Viewpoint.FieldOfView = fov; // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint)
|
di->Viewpoint.FieldOfView = fov; // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint)
|
||||||
|
|
||||||
// Stereo mode specific perspective projection
|
// Stereo mode specific perspective projection
|
||||||
di->SetProjection( eye->GetProjection(fov, ratio, fovratio) );
|
di->VPUniforms.mProjectionMatrix = eye->GetProjection(fov, ratio, fovratio);
|
||||||
vp.SetViewAngle(r_viewwindow);
|
vp.SetViewAngle(r_viewwindow);
|
||||||
// Stereo mode specific viewpoint adjustment - temporarily shifts global ViewPos
|
// Stereo mode specific viewpoint adjustment - temporarily shifts global ViewPos
|
||||||
eye->GetViewShift(vp.HWAngles.Yaw.Degrees, viewShift);
|
eye->GetViewShift(vp.HWAngles.Yaw.Degrees, viewShift);
|
||||||
ScopedViewShifter viewShifter(vp.Pos, viewShift);
|
ScopedViewShifter viewShifter(vp.Pos, viewShift);
|
||||||
di->SetViewMatrix(vp.HWAngles, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false);
|
di->SetViewMatrix(vp.HWAngles, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false);
|
||||||
gl_RenderState.ApplyMatrices();
|
di->ApplyVPUniforms();
|
||||||
|
|
||||||
di->ProcessScene(toscreen);
|
di->ProcessScene(toscreen);
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,6 @@ void GLSkyPortal::DrawContents(FDrawInfo *di)
|
||||||
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
bool oldClamp = gl_RenderState.SetDepthClamp(true);
|
bool oldClamp = gl_RenderState.SetDepthClamp(true);
|
||||||
|
|
||||||
gl_MatrixStack.Push(gl_RenderState.mViewMatrix);
|
|
||||||
di->SetupView(vp, 0, 0, 0, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
|
di->SetupView(vp, 0, 0, 0, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
|
||||||
|
|
||||||
gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO);
|
gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO);
|
||||||
|
@ -270,8 +269,7 @@ void GLSkyPortal::DrawContents(FDrawInfo *di)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
||||||
gl_MatrixStack.Pop(gl_RenderState.mViewMatrix);
|
di->ApplyVPUniforms();
|
||||||
gl_RenderState.ApplyMatrices();
|
|
||||||
::level.lightmode = oldlightmode;
|
::level.lightmode = oldlightmode;
|
||||||
gl_RenderState.SetDepthClamp(oldClamp);
|
gl_RenderState.SetDepthClamp(oldClamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FGLModelRenderer renderer(sprite->dynlightindex);
|
FGLModelRenderer renderer(this, sprite->dynlightindex);
|
||||||
renderer.RenderModel(sprite->x, sprite->y, sprite->z, sprite->modelframe, sprite->actor, vp.TicFrac);
|
renderer.RenderModel(sprite->x, sprite->y, sprite->z, sprite->modelframe, sprite->actor, vp.TicFrac);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,6 @@ void FDrawInfo::RenderMirrorSurface(GLWall *wall)
|
||||||
|
|
||||||
// we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is.
|
// we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is.
|
||||||
gl_RenderState.EnableTextureMatrix(true);
|
gl_RenderState.EnableTextureMatrix(true);
|
||||||
gl_RenderState.mTextureMatrix.computeNormalMatrix(gl_RenderState.mViewMatrix);
|
|
||||||
|
|
||||||
// Use sphere mapping for this
|
// Use sphere mapping for this
|
||||||
gl_RenderState.SetEffect(EFF_SPHEREMAP);
|
gl_RenderState.SetEffect(EFF_SPHEREMAP);
|
||||||
|
|
|
@ -65,7 +65,7 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds)
|
||||||
if (huds->mframe)
|
if (huds->mframe)
|
||||||
{
|
{
|
||||||
gl_RenderState.AlphaFunc(GL_GEQUAL, 0);
|
gl_RenderState.AlphaFunc(GL_GEQUAL, 0);
|
||||||
FGLModelRenderer renderer(huds->lightindex);
|
FGLModelRenderer renderer(this, huds->lightindex);
|
||||||
renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my);
|
renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -91,7 +91,7 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds)
|
||||||
|
|
||||||
void FDrawInfo::DrawPlayerSprites(bool hudModelStep)
|
void FDrawInfo::DrawPlayerSprites(bool hudModelStep)
|
||||||
{
|
{
|
||||||
s3d::Stereo3DMode::getCurrentMode().AdjustPlayerSprites();
|
s3d::Stereo3DMode::getCurrentMode().AdjustPlayerSprites(this);
|
||||||
|
|
||||||
int oldlightmode = level.lightmode;
|
int oldlightmode = level.lightmode;
|
||||||
if (!hudModelStep && level.lightmode == 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that.
|
if (!hudModelStep && level.lightmode == 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that.
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "gl/scene/gl_drawinfo.h"
|
||||||
#include "gl_sidebyside3d.h"
|
#include "gl_sidebyside3d.h"
|
||||||
#include "gl/renderer/gl_renderbuffers.h"
|
#include "gl/renderer/gl_renderbuffers.h"
|
||||||
|
|
||||||
|
@ -98,13 +99,13 @@ SideBySideFull::SideBySideFull(double ipdMeters)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */
|
/* virtual */
|
||||||
void SideBySideFull::AdjustPlayerSprites() const /* override */
|
void SideBySideFull::AdjustPlayerSprites(FDrawInfo *di) const /* override */
|
||||||
{
|
{
|
||||||
// Show weapon at double width, so it would appear normal width after rescaling
|
// Show weapon at double width, so it would appear normal width after rescaling
|
||||||
int w = screen->mScreenViewport.width;
|
int w = screen->mScreenViewport.width;
|
||||||
int h = screen->mScreenViewport.height;
|
int h = screen->mScreenViewport.height;
|
||||||
gl_RenderState.mProjectionMatrix.ortho(w/2, w + w/2, h, 0, -1.0f, 1.0f);
|
di->VPUniforms.mProjectionMatrix.ortho(w/2, w + w/2, h, 0, -1.0f, 1.0f);
|
||||||
gl_RenderState.ApplyMatrices();
|
di->ApplyVPUniforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
|
@ -82,7 +82,7 @@ class SideBySideFull : public SideBySideBase
|
||||||
public:
|
public:
|
||||||
static const SideBySideFull& getInstance(float ipd);
|
static const SideBySideFull& getInstance(float ipd);
|
||||||
SideBySideFull(double ipdMeters);
|
SideBySideFull(double ipdMeters);
|
||||||
virtual void AdjustPlayerSprites() const override;
|
virtual void AdjustPlayerSprites(FDrawInfo *di) const override;
|
||||||
private:
|
private:
|
||||||
SBSFLeftEyePose leftEye;
|
SBSFLeftEyePose leftEye;
|
||||||
SBSFRightEyePose rightEye;
|
SBSFRightEyePose rightEye;
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
|
|
||||||
virtual bool IsMono() const { return false; }
|
virtual bool IsMono() const { return false; }
|
||||||
virtual void AdjustViewports() const {};
|
virtual void AdjustViewports() const {};
|
||||||
virtual void AdjustPlayerSprites() const {};
|
virtual void AdjustPlayerSprites(FDrawInfo *di) const {};
|
||||||
virtual void Present() const = 0;
|
virtual void Present() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -342,7 +342,7 @@ IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(FTexture *tex)
|
||||||
|
|
||||||
FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
|
FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
|
||||||
{
|
{
|
||||||
return new FGLModelRenderer(mli);
|
return new FGLModelRenderer(nullptr, mli);
|
||||||
}
|
}
|
||||||
|
|
||||||
IUniformBuffer *OpenGLFrameBuffer::CreateUniformBuffer(size_t size, bool staticuse)
|
IUniformBuffer *OpenGLFrameBuffer::CreateUniformBuffer(size_t size, bool staticuse)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include "r_defs.h"
|
#include "r_defs.h"
|
||||||
#include "r_utility.h"
|
#include "r_utility.h"
|
||||||
|
#include "hw_viewpointuniforms.h"
|
||||||
|
|
||||||
|
|
||||||
struct FSectorPortalGroup;
|
struct FSectorPortalGroup;
|
||||||
|
@ -19,6 +20,7 @@ struct HUDSprite;
|
||||||
class Clipper;
|
class Clipper;
|
||||||
class IPortal;
|
class IPortal;
|
||||||
class FFlatVertexGenerator;
|
class FFlatVertexGenerator;
|
||||||
|
class IRenderQueue;
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -99,6 +101,7 @@ struct HWDrawInfo
|
||||||
IShadowMap *mShadowMap;
|
IShadowMap *mShadowMap;
|
||||||
Clipper *mClipper;
|
Clipper *mClipper;
|
||||||
FRenderViewpoint Viewpoint;
|
FRenderViewpoint Viewpoint;
|
||||||
|
HWViewpointUniforms VPUniforms; // per-viewpoint uniform state
|
||||||
|
|
||||||
TArray<MissingTextureInfo> MissingUpperTextures;
|
TArray<MissingTextureInfo> MissingUpperTextures;
|
||||||
TArray<MissingTextureInfo> MissingLowerTextures;
|
TArray<MissingTextureInfo> MissingLowerTextures;
|
||||||
|
@ -207,6 +210,7 @@ public:
|
||||||
virtual void AddHUDSprite(HUDSprite *huds) = 0;
|
virtual void AddHUDSprite(HUDSprite *huds) = 0;
|
||||||
|
|
||||||
virtual int UploadLights(FDynLightData &data) = 0;
|
virtual int UploadLights(FDynLightData &data) = 0;
|
||||||
|
virtual void ApplyVPUniforms() = 0;
|
||||||
|
|
||||||
virtual GLDecal *AddDecal(bool onmirror) = 0;
|
virtual GLDecal *AddDecal(bool onmirror) = 0;
|
||||||
virtual std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count) = 0;
|
virtual std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count) = 0;
|
||||||
|
|
|
@ -12,4 +12,12 @@ struct HWViewpointUniforms
|
||||||
{
|
{
|
||||||
mNormalViewMatrix.computeNormalMatrix(mViewMatrix);
|
mNormalViewMatrix.computeNormalMatrix(mViewMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetDefaults()
|
||||||
|
{
|
||||||
|
mProjectionMatrix.loadIdentity();
|
||||||
|
mViewMatrix.loadIdentity();
|
||||||
|
mNormalViewMatrix.loadIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@ class AActor;
|
||||||
enum area_t : int;
|
enum area_t : int;
|
||||||
struct FSpriteModelFrame;
|
struct FSpriteModelFrame;
|
||||||
struct HWDrawInfo;
|
struct HWDrawInfo;
|
||||||
|
class FMaterial;
|
||||||
|
|
||||||
|
|
||||||
struct WeaponPosition
|
struct WeaponPosition
|
||||||
|
|
|
@ -1032,7 +1032,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
|
||||||
double alen = sqrt(angx*angx + angy*angy);
|
double alen = sqrt(angx*angx + angy*angy);
|
||||||
viewpoint.HWAngles.Pitch = RAD2DEG((float)asin(angy / alen));
|
viewpoint.HWAngles.Pitch = RAD2DEG((float)asin(angy / alen));
|
||||||
|
|
||||||
viewpoint.HWAngles.Roll.Degrees = viewpoint.Angles.Roll.Degrees; // copied for convenience.
|
viewpoint.HWAngles.Roll.Degrees = (float)viewpoint.Angles.Roll.Degrees; // copied for convenience.
|
||||||
|
|
||||||
// ViewActor only gets set, if the camera actor should not be rendered
|
// ViewActor only gets set, if the camera actor should not be rendered
|
||||||
if (actor->player && actor->player - players == consoleplayer &&
|
if (actor->player && actor->player - players == consoleplayer &&
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "p_3dfloors.h"
|
#include "r_defs.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
EXTERN_CVAR(Int, r_3dfloors);
|
EXTERN_CVAR(Int, r_3dfloors);
|
||||||
|
|
|
@ -68,7 +68,7 @@ void main()
|
||||||
|
|
||||||
#ifdef SPHEREMAP
|
#ifdef SPHEREMAP
|
||||||
vec3 u = normalize(eyeCoordPos.xyz);
|
vec3 u = normalize(eyeCoordPos.xyz);
|
||||||
vec4 n = normalize(TextureMatrix * vec4(parmTexCoord.x, 0.0, parmTexCoord.y, 0.0)); // use texture matrix and coordinates for our normal. Since this is only used on walls, the normal's y coordinate is always 0.
|
vec4 n = normalize(NormalViewMatrix * vec4(parmTexCoord.x, 0.0, parmTexCoord.y, 0.0));
|
||||||
vec3 r = reflect(u, n.xyz);
|
vec3 r = reflect(u, n.xyz);
|
||||||
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
|
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
|
||||||
vec2 sst = vec2(r.x/m + 0.5, r.y/m + 0.5);
|
vec2 sst = vec2(r.x/m + 0.5, r.y/m + 0.5);
|
||||||
|
|
Loading…
Reference in a new issue