This commit is contained in:
nashmuhandes 2016-08-01 11:28:16 +08:00
commit 624a2da175
9 changed files with 93 additions and 100 deletions

View file

@ -105,6 +105,16 @@ public:
if (pcount) *pcount = count; if (pcount) *pcount = count;
} }
void RenderScreenQuad(float maxU = 1.0f, float maxV = 1.0f)
{
FFlatVertex *ptr = GetBuffer();
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
ptr->Set(-1.0f, 1.0f, 0, 0.0f, maxV); ptr++;
ptr->Set(1.0f, -1.0f, 0, maxU, 0.0f); ptr++;
ptr->Set(1.0f, 1.0f, 0, maxU, maxV); ptr++;
RenderCurrent(ptr, GL_TRIANGLE_STRIP);
}
#endif #endif
void Reset() void Reset()
{ {

View file

@ -145,14 +145,7 @@ void FGLRenderer::BloomScene()
mBloomExtractShader->Bind(); mBloomExtractShader->Bind();
mBloomExtractShader->SceneTexture.Set(0); mBloomExtractShader->SceneTexture.Set(0);
mBloomExtractShader->Exposure.Set(mCameraExposure); mBloomExtractShader->Exposure.Set(mCameraExposure);
{ mVBO->RenderScreenQuad();
FFlatVertex *ptr = mVBO->GetBuffer();
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
ptr->Set(-1.0f, 1.0f, 0, 0.0f, 1.0f); ptr++;
ptr->Set(1.0f, -1.0f, 0, 1.0f, 0.0f); ptr++;
ptr->Set(1.0f, 1.0f, 0, 1.0f, 1.0f); ptr++;
mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -183,14 +176,7 @@ void FGLRenderer::BloomScene()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
mBloomCombineShader->Bind(); mBloomCombineShader->Bind();
mBloomCombineShader->BloomTexture.Set(0); mBloomCombineShader->BloomTexture.Set(0);
{ mVBO->RenderScreenQuad();
FFlatVertex *ptr = mVBO->GetBuffer();
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
ptr->Set(-1.0f, 1.0f, 0, 0.0f, 1.0f); ptr++;
ptr->Set(1.0f, -1.0f, 0, 1.0f, 0.0f); ptr++;
ptr->Set(1.0f, 1.0f, 0, 1.0f, 1.0f); ptr++;
mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
}
} }
mBlurShader->BlurHorizontal(mVBO, blurAmount, sampleCount, level0.VTexture, level0.HFramebuffer, level0.Width, level0.Height); mBlurShader->BlurHorizontal(mVBO, blurAmount, sampleCount, level0.VTexture, level0.HFramebuffer, level0.Width, level0.Height);
@ -198,7 +184,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);
@ -208,14 +194,7 @@ void FGLRenderer::BloomScene()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
mBloomCombineShader->Bind(); mBloomCombineShader->Bind();
mBloomCombineShader->BloomTexture.Set(0); mBloomCombineShader->BloomTexture.Set(0);
{ mVBO->RenderScreenQuad();
FFlatVertex *ptr = mVBO->GetBuffer();
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
ptr->Set(-1.0f, 1.0f, 0, 0.0f, 1.0f); ptr++;
ptr->Set(1.0f, -1.0f, 0, 1.0f, 0.0f); ptr++;
ptr->Set(1.0f, 1.0f, 0, 1.0f, 1.0f); ptr++;
mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
}
if (blendEnabled) if (blendEnabled)
glEnable(GL_BLEND); glEnable(GL_BLEND);
@ -263,13 +242,7 @@ void FGLRenderer::TonemapScene()
mTonemapShader->Bind(); mTonemapShader->Bind();
mTonemapShader->SceneTexture.Set(0); mTonemapShader->SceneTexture.Set(0);
mTonemapShader->Exposure.Set(mCameraExposure); mTonemapShader->Exposure.Set(mCameraExposure);
mVBO->RenderScreenQuad();
FFlatVertex *ptr = mVBO->GetBuffer();
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
ptr->Set(-1.0f, 1.0f, 0, 0.0f, 1.0f); ptr++;
ptr->Set(1.0f, -1.0f, 0, 1.0f, 0.0f); ptr++;
ptr->Set(1.0f, 1.0f, 0, 1.0f, 1.0f); ptr++;
mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
if (blendEnabled) if (blendEnabled)
glEnable(GL_BLEND); glEnable(GL_BLEND);
@ -287,7 +260,7 @@ void FGLRenderer::TonemapScene()
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FGLRenderer::Flush() void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
{ {
if (FGLRenderBuffers::IsEnabled()) if (FGLRenderBuffers::IsEnabled())
{ {
@ -311,16 +284,26 @@ void FGLRenderer::Flush()
mBuffers->BindOutputFB(); mBuffers->BindOutputFB();
int x, y, width, height;
if (bounds)
{
x = bounds->left;
y = bounds->top;
width = bounds->width;
height = bounds->height;
}
else
{
// Calculate letterbox // Calculate letterbox
int clientWidth = framebuffer->GetClientWidth(); int clientWidth = framebuffer->GetClientWidth();
int clientHeight = framebuffer->GetClientHeight(); int clientHeight = framebuffer->GetClientHeight();
float scaleX = clientWidth / (float)mOutputViewport.width; float scaleX = clientWidth / (float)mScreenViewport.width;
float scaleY = clientHeight / (float)mOutputViewport.height; float scaleY = clientHeight / (float)mScreenViewport.height;
float scale = MIN(scaleX, scaleY); float scale = MIN(scaleX, scaleY);
int width = (int)round(mOutputViewport.width * scale); width = (int)round(mScreenViewport.width * scale);
int height = (int)round(mOutputViewport.height * scale); height = (int)round(mScreenViewport.height * scale);
int x = (clientWidth - width) / 2; x = (clientWidth - width) / 2;
int y = (clientHeight - height) / 2; y = (clientHeight - height) / 2;
// Black bars around the box: // Black bars around the box:
glViewport(0, 0, clientWidth, clientHeight); glViewport(0, 0, clientWidth, clientHeight);
@ -346,6 +329,7 @@ void FGLRenderer::Flush()
glScissor(x + width, y, clientWidth - x - width, height); glScissor(x + width, y, clientWidth - x - width, height);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
}
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
// Present what was rendered: // Present what was rendered:
@ -354,7 +338,7 @@ void FGLRenderer::Flush()
mPresentShader->Bind(); mPresentShader->Bind();
mPresentShader->InputTexture.Set(0); mPresentShader->InputTexture.Set(0);
if (framebuffer->IsHWGammaActive()) if (!applyGamma || framebuffer->IsHWGammaActive())
{ {
mPresentShader->Gamma.Set(1.0f); mPresentShader->Gamma.Set(1.0f);
mPresentShader->Contrast.Set(1.0f); mPresentShader->Contrast.Set(1.0f);
@ -367,13 +351,7 @@ void FGLRenderer::Flush()
mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f)); mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
} }
mBuffers->BindHudTexture(0); mBuffers->BindHudTexture(0);
mVBO->RenderScreenQuad(width / (float)mBuffers->GetWidth(), height / (float)mBuffers->GetHeight());
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
ptr->Set(-1.0f, 1.0f, 0, 0.0f, 1.0f); ptr++;
ptr->Set(1.0f, -1.0f, 0, 1.0f, 0.0f); ptr++;
ptr->Set(1.0f, 1.0f, 0, 1.0f, 1.0f); ptr++;
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
if (blendEnabled) if (blendEnabled)
glEnable(GL_BLEND); glEnable(GL_BLEND);

View file

@ -34,6 +34,9 @@ public:
static bool IsEnabled(); static bool IsEnabled();
int GetWidth() const { return mWidth; }
int GetHeight() const { return mHeight; }
private: private:
void ClearScene(); void ClearScene();
void ClearHud(); void ClearHud();

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;
@ -117,7 +118,7 @@ public:
angle_t FrustumAngle(); angle_t FrustumAngle();
void SetViewArea(); void SetViewArea();
void SetOutputViewport(GL_IRECT *bounds); void SetOutputViewport(GL_IRECT *bounds);
void Set3DViewport(bool toscreen); void Set3DViewport(bool mainview);
void Reset3DViewport(); void Reset3DViewport();
sector_t *RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); sector_t *RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen);
void RenderView(player_t *player); void RenderView(player_t *player);
@ -159,7 +160,8 @@ public:
void EndDrawScene(sector_t * viewsector); void EndDrawScene(sector_t * viewsector);
void BloomScene(); void BloomScene();
void TonemapScene(); void TonemapScene();
void Flush(); void CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma);
void Flush() { CopyToBackbuffer(nullptr, true); }
void SetProjection(float fov, float ratio, float fovratio); void SetProjection(float fov, float ratio, float fovratio);
void SetProjection(VSMatrix matrix); // raw matrix input from stereo 3d modes void SetProjection(VSMatrix matrix); // raw matrix input from stereo 3d modes

View file

@ -157,9 +157,6 @@ void FGLRenderer::SetViewArea()
void FGLRenderer::Reset3DViewport() void FGLRenderer::Reset3DViewport()
{ {
if (FGLRenderBuffers::IsEnabled())
glViewport(0, 0, mOutputViewport.width, mOutputViewport.height);
else
glViewport(mOutputViewport.left, mOutputViewport.top, mOutputViewport.width, mOutputViewport.height); glViewport(mOutputViewport.left, mOutputViewport.top, mOutputViewport.width, mOutputViewport.height);
} }
@ -169,21 +166,17 @@ void FGLRenderer::Reset3DViewport()
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FGLRenderer::Set3DViewport(bool toscreen) void FGLRenderer::Set3DViewport(bool mainview)
{ {
const auto &bounds = mOutputViewportLB; if (mainview && 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
{ const auto &bounds = mOutputViewportLB;
glViewport(bounds.left, bounds.top, bounds.width, bounds.height); glViewport(bounds.left, bounds.top, bounds.width, bounds.height);
glScissor(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);
@ -847,7 +840,7 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo
eye->SetUp(); eye->SetUp();
// TODO: stereo specific viewport - needed when implementing side-by-side modes etc. // TODO: stereo specific viewport - needed when implementing side-by-side modes etc.
SetOutputViewport(bounds); SetOutputViewport(bounds);
Set3DViewport(toscreen); Set3DViewport(mainview);
mDrawingScene2D = true; mDrawingScene2D = true;
mCurrentFoV = fov; mCurrentFoV = fov;
// Stereo mode specific perspective projection // Stereo mode specific perspective projection
@ -865,8 +858,8 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo
clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs() + a1, ViewAngle.BAMs() - a1); clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs() + a1, ViewAngle.BAMs() - a1);
ProcessScene(toscreen); ProcessScene(toscreen);
if (mainview) EndDrawScene(retval); // do not call this for camera textures. if (mainview && toscreen) EndDrawScene(retval); // do not call this for camera textures.
if (toscreen) if (mainview)
{ {
if (FGLRenderBuffers::IsEnabled()) mBuffers->BlitSceneToTexture(); if (FGLRenderBuffers::IsEnabled()) mBuffers->BlitSceneToTexture();
BloomScene(); BloomScene();
@ -983,6 +976,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FILE *file, int width, int hei
gl_RenderState.SetSoftLightLevel(-1); gl_RenderState.SetSoftLightLevel(-1);
screen->Begin2D(false); screen->Begin2D(false);
DrawBlend(viewsector); DrawBlend(viewsector);
CopyToBackbuffer(&bounds, false);
glFlush(); glFlush();
byte * scr = (byte *)M_Malloc(width * height * 3); byte * scr = (byte *)M_Malloc(width * height * 3);

View file

@ -58,6 +58,7 @@ void FPresentShader::Bind()
mShader.SetFragDataLocation(0, "FragColor"); mShader.SetFragDataLocation(0, "FragColor");
mShader.Link("shaders/glsl/present"); mShader.Link("shaders/glsl/present");
mShader.SetAttribLocation(0, "PositionInProjection"); mShader.SetAttribLocation(0, "PositionInProjection");
mShader.SetAttribLocation(1, "UV");
InputTexture.Init(mShader, "InputTexture"); InputTexture.Init(mShader, "InputTexture");
Gamma.Init(mShader, "Gamma"); Gamma.Init(mShader, "Gamma");
Contrast.Init(mShader, "Contrast"); Contrast.Init(mShader, "Contrast");

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);

View file

@ -1,9 +1,10 @@
in vec4 PositionInProjection; in vec4 PositionInProjection;
in vec2 UV;
out vec2 TexCoord; out vec2 TexCoord;
void main() void main()
{ {
gl_Position = PositionInProjection; gl_Position = PositionInProjection;
TexCoord = PositionInProjection.xy * 0.5 + 0.5; TexCoord = UV;
} }