MaskAnaglyph present mode

This commit is contained in:
Magnus Norddahl 2016-09-08 19:02:13 +02:00 committed by Christoph Oelckers
parent ccbe5160b0
commit 8b7267cf87
4 changed files with 56 additions and 37 deletions

View file

@ -397,6 +397,8 @@ void FGLRenderer::Flush()
{ {
FGLDebug::PushGroup("Eye2D"); FGLDebug::PushGroup("Eye2D");
mBuffers->BindEyeFB(eye_ix); mBuffers->BindEyeFB(eye_ix);
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
glScissor(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
m2DDrawer->Draw(); m2DDrawer->Draw();
FGLDebug::PopGroup(); FGLDebug::PopGroup();
} }
@ -437,28 +439,8 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
box = mOutputLetterbox; box = mOutputLetterbox;
} }
// Present what was rendered:
glViewport(box.left, box.top, box.width, box.height);
mPresentShader->Bind();
mPresentShader->InputTexture.Set(0);
if (!applyGamma || framebuffer->IsHWGammaActive())
{
mPresentShader->InvGamma.Set(1.0f);
mPresentShader->Contrast.Set(1.0f);
mPresentShader->Brightness.Set(0.0f);
}
else
{
mPresentShader->InvGamma.Set(1.0f / clamp<float>(Gamma, 0.1f, 4.f));
mPresentShader->Contrast.Set(clamp<float>(vid_contrast, 0.1f, 3.f));
mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
}
mPresentShader->Scale.Set(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight());
mBuffers->BindCurrentTexture(0); mBuffers->BindCurrentTexture(0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawPresentTexture(box, applyGamma);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
RenderScreenQuad();
} }
else if (!bounds) else if (!bounds)
{ {
@ -468,6 +450,32 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
FGLDebug::PopGroup(); FGLDebug::PopGroup();
} }
void FGLRenderer::DrawPresentTexture(const GL_IRECT &box, bool applyGamma)
{
glViewport(box.left, box.top, box.width, box.height);
glActiveTexture(GL_TEXTURE0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
mPresentShader->Bind();
mPresentShader->InputTexture.Set(0);
if (!applyGamma || framebuffer->IsHWGammaActive())
{
mPresentShader->InvGamma.Set(1.0f);
mPresentShader->Contrast.Set(1.0f);
mPresentShader->Brightness.Set(0.0f);
}
else
{
mPresentShader->InvGamma.Set(1.0f / clamp<float>(Gamma, 0.1f, 4.f));
mPresentShader->Contrast.Set(clamp<float>(vid_contrast, 0.1f, 3.f));
mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
}
mPresentShader->Scale.Set(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight());
RenderScreenQuad();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Fills the black bars around the screen letterbox // Fills the black bars around the screen letterbox

View file

@ -173,6 +173,7 @@ public:
void ClearTonemapPalette(); void ClearTonemapPalette();
void LensDistortScene(); void LensDistortScene();
void CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma); void CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma);
void DrawPresentTexture(const GL_IRECT &box, bool applyGamma);
void Flush(); void Flush();
void SetProjection(float fov, float ratio, float fovratio); void SetProjection(float fov, float ratio, float fovratio);

View file

@ -34,6 +34,8 @@
*/ */
#include "gl_anaglyph.h" #include "gl_anaglyph.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderbuffers.h"
namespace s3d { namespace s3d {
@ -44,6 +46,25 @@ MaskAnaglyph::MaskAnaglyph(const ColorMask& leftColorMask, double ipdMeters)
eye_ptrs.Push(&rightEye); eye_ptrs.Push(&rightEye);
} }
void MaskAnaglyph::Present() const
{
GLRenderer->mBuffers->BindOutputFB();
GLRenderer->ClearBorders();
gl_RenderState.SetColorMask(leftEye.GetColorMask().r, leftEye.GetColorMask().g, leftEye.GetColorMask().b, true);
gl_RenderState.ApplyColorMask();
GLRenderer->mBuffers->BindEyeTexture(0, 0);
GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true);
gl_RenderState.SetColorMask(rightEye.GetColorMask().r, rightEye.GetColorMask().g, rightEye.GetColorMask().b, true);
gl_RenderState.ApplyColorMask();
GLRenderer->mBuffers->BindEyeTexture(1, 0);
GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true);
gl_RenderState.ResetColorMask();
gl_RenderState.ApplyColorMask();
}
/* static */ /* static */
const GreenMagenta& GreenMagenta::getInstance(float ipd) const GreenMagenta& GreenMagenta::getInstance(float ipd)

View file

@ -61,14 +61,8 @@ class AnaglyphLeftPose : public LeftEyePose
{ {
public: public:
AnaglyphLeftPose(const ColorMask& colorMask, float ipd) : LeftEyePose(ipd), colorMask(colorMask) {} AnaglyphLeftPose(const ColorMask& colorMask, float ipd) : LeftEyePose(ipd), colorMask(colorMask) {}
virtual void SetUp() const { ColorMask GetColorMask() const { return colorMask; }
gl_RenderState.SetColorMask(colorMask.r, colorMask.g, colorMask.b, true);
gl_RenderState.ApplyColorMask();
}
virtual void TearDown() const {
gl_RenderState.ResetColorMask();
gl_RenderState.ApplyColorMask();
}
private: private:
ColorMask colorMask; ColorMask colorMask;
}; };
@ -77,14 +71,8 @@ class AnaglyphRightPose : public RightEyePose
{ {
public: public:
AnaglyphRightPose(const ColorMask& colorMask, float ipd) : RightEyePose(ipd), colorMask(colorMask) {} AnaglyphRightPose(const ColorMask& colorMask, float ipd) : RightEyePose(ipd), colorMask(colorMask) {}
virtual void SetUp() const { ColorMask GetColorMask() const { return colorMask; }
gl_RenderState.SetColorMask(colorMask.r, colorMask.g, colorMask.b, true);
gl_RenderState.ApplyColorMask();
}
virtual void TearDown() const {
gl_RenderState.ResetColorMask();
gl_RenderState.ApplyColorMask();
}
private: private:
ColorMask colorMask; ColorMask colorMask;
}; };
@ -93,6 +81,7 @@ class MaskAnaglyph : public Stereo3DMode
{ {
public: public:
MaskAnaglyph(const ColorMask& leftColorMask, double ipdMeters); MaskAnaglyph(const ColorMask& leftColorMask, double ipdMeters);
void Present() const override;
private: private:
AnaglyphLeftPose leftEye; AnaglyphLeftPose leftEye;
AnaglyphRightPose rightEye; AnaglyphRightPose rightEye;