Fix incorrect viewport location when not using fullscreen HUD

This commit is contained in:
Magnus Norddahl 2016-07-31 13:23:49 +02:00
parent d3457f4508
commit a6354c74cf
5 changed files with 17 additions and 19 deletions

View file

@ -198,7 +198,7 @@ void FGLRenderer::BloomScene()
// Add bloom back to scene texture: // Add bloom back to scene texture:
mBuffers->BindSceneTextureFB(); mBuffers->BindSceneTextureFB();
glViewport(0, 0, mOutputViewport.width, mOutputViewport.height); glViewport(mOutputViewport.left, mOutputViewport.top, mOutputViewport.width, mOutputViewport.height);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD); glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE); glBlendFunc(GL_ONE, GL_ONE);

View file

@ -185,6 +185,7 @@ void FGLRenderer::SetOutputViewport(GL_IRECT *bounds)
{ {
mOutputViewport = *bounds; mOutputViewport = *bounds;
mOutputViewportLB = *bounds; mOutputViewportLB = *bounds;
mScreenViewport = *bounds;
return; return;
} }
@ -209,6 +210,12 @@ void FGLRenderer::SetOutputViewport(GL_IRECT *bounds)
int vw = viewwidth; int vw = viewwidth;
int vh = viewheight; int vh = viewheight;
// The entire renderable area, including the 2D HUD
mScreenViewport.left = 0;
mScreenViewport.top = 0;
mScreenViewport.width = framebuffer->GetWidth();
mScreenViewport.height = framebuffer->GetHeight();
// Letterboxed viewport for the main scene // Letterboxed viewport for the main scene
mOutputViewportLB.left = viewwindowx; mOutputViewportLB.left = viewwindowx;
mOutputViewportLB.top = trueheight - bars - (height + viewwindowy - ((height - vh) / 2)); mOutputViewportLB.top = trueheight - bars - (height + viewwindowy - ((height - vh) / 2));
@ -242,12 +249,8 @@ void FGLRenderer::Begin2D()
mBuffers->BindSceneFB(); mBuffers->BindSceneFB();
else else
mBuffers->BindHudFB(); mBuffers->BindHudFB();
glViewport(0, 0, mOutputViewport.width, mOutputViewport.height);
}
else
{
glViewport(mOutputViewport.left, mOutputViewport.top, mOutputViewport.width, mOutputViewport.height);
} }
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
gl_RenderState.EnableFog(false); gl_RenderState.EnableFog(false);
gl_RenderState.Set2DMode(true); gl_RenderState.Set2DMode(true);

View file

@ -106,6 +106,7 @@ public:
FSkyVertexBuffer *mSkyVBO; FSkyVertexBuffer *mSkyVBO;
FLightBuffer *mLights; FLightBuffer *mLights;
GL_IRECT mScreenViewport;
GL_IRECT mOutputViewportLB; GL_IRECT mOutputViewportLB;
GL_IRECT mOutputViewport; GL_IRECT mOutputViewport;
bool mDrawingScene2D = false; bool mDrawingScene2D = false;

View file

@ -157,10 +157,7 @@ void FGLRenderer::SetViewArea()
void FGLRenderer::Reset3DViewport() void FGLRenderer::Reset3DViewport()
{ {
if (FGLRenderBuffers::IsEnabled()) glViewport(mOutputViewport.left, mOutputViewport.top, mOutputViewport.width, mOutputViewport.height);
glViewport(0, 0, mOutputViewport.width, mOutputViewport.height);
else
glViewport(mOutputViewport.left, mOutputViewport.top, mOutputViewport.width, mOutputViewport.height);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -171,20 +168,16 @@ void FGLRenderer::Reset3DViewport()
void FGLRenderer::Set3DViewport(bool toscreen) void FGLRenderer::Set3DViewport(bool toscreen)
{ {
const auto &bounds = mOutputViewportLB;
if (toscreen && FGLRenderBuffers::IsEnabled()) if (toscreen && FGLRenderBuffers::IsEnabled())
{ {
mBuffers->Setup(mOutputViewport.width, mOutputViewport.height); mBuffers->Setup(mOutputViewport.width, mOutputViewport.height);
mBuffers->BindSceneFB(); mBuffers->BindSceneFB();
glViewport(0, 0, bounds.width, bounds.height);
glScissor(0, 0, bounds.width, bounds.height);
}
else
{
glViewport(bounds.left, bounds.top, bounds.width, bounds.height);
glScissor(bounds.left, bounds.top, bounds.width, bounds.height);
} }
const auto &bounds = mOutputViewportLB;
glViewport(bounds.left, bounds.top, bounds.width, bounds.height);
glScissor(bounds.left, bounds.top, bounds.width, bounds.height);
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
#ifdef _DEBUG #ifdef _DEBUG

View file

@ -233,7 +233,8 @@ bool OpenGLFrameBuffer::WipeDo(int ticks)
if (FGLRenderBuffers::IsEnabled()) if (FGLRenderBuffers::IsEnabled())
{ {
GLRenderer->mBuffers->BindHudFB(); GLRenderer->mBuffers->BindHudFB();
glViewport(0, 0, GLRenderer->mOutputViewport.width, GLRenderer->mOutputViewport.height); const auto &bounds = GLRenderer->mScreenViewport;
glViewport(bounds.left, bounds.top, bounds.width, bounds.height);
} }
bool done = ScreenWipe->Run(ticks, this); bool done = ScreenWipe->Run(ticks, this);