From 63dc3949139586fe5b7d71dc0800ff2adb01c4af Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 8 Sep 2016 21:15:00 +0200 Subject: [PATCH] Present function for left, right and quad-buffered stereo3d --- src/gl/stereo3d/gl_quadstereo.cpp | 31 ++++++++++++++++++++++++- src/gl/stereo3d/gl_quadstereo.h | 18 ++------------ src/gl/stereo3d/gl_stereo3d.cpp | 23 ------------------ src/gl/stereo3d/gl_stereo3d.h | 3 ++- src/gl/stereo3d/gl_stereo_leftright.cpp | 18 ++++++++++++++ src/gl/stereo3d/gl_stereo_leftright.h | 2 ++ 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/gl/stereo3d/gl_quadstereo.cpp b/src/gl/stereo3d/gl_quadstereo.cpp index 63bbbedc1a..cd689d3b53 100644 --- a/src/gl/stereo3d/gl_quadstereo.cpp +++ b/src/gl/stereo3d/gl_quadstereo.cpp @@ -34,6 +34,8 @@ */ #include "gl_quadstereo.h" +#include "gl/renderer/gl_renderer.h" +#include "gl/renderer/gl_renderbuffers.h" namespace s3d { @@ -46,7 +48,7 @@ QuadStereo::QuadStereo(double ipdMeters) GLboolean supportsStereo, supportsBuffered; glGetBooleanv(GL_STEREO, &supportsStereo); glGetBooleanv(GL_DOUBLEBUFFER, &supportsBuffered); - bool bQuadStereoSupported = supportsStereo && supportsBuffered; + bQuadStereoSupported = supportsStereo && supportsBuffered; leftEye.bQuadStereoSupported = bQuadStereoSupported; rightEye.bQuadStereoSupported = bQuadStereoSupported; @@ -57,6 +59,33 @@ QuadStereo::QuadStereo(double ipdMeters) } } +void QuadStereo::Present() const +{ + if (bQuadStereoSupported) + { + GLRenderer->mBuffers->BindOutputFB(); + + glDrawBuffer(GL_BACK_LEFT); + GLRenderer->ClearBorders(); + GLRenderer->mBuffers->BindEyeTexture(0, 0); + GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true); + + glDrawBuffer(GL_BACK_RIGHT); + GLRenderer->ClearBorders(); + GLRenderer->mBuffers->BindEyeTexture(1, 0); + GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true); + + glDrawBuffer(GL_BACK); + } + else + { + GLRenderer->mBuffers->BindOutputFB(); + GLRenderer->ClearBorders(); + GLRenderer->mBuffers->BindEyeTexture(1, 0); + GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true); + } +} + /* static */ const QuadStereo& QuadStereo::getInstance(float ipd) { diff --git a/src/gl/stereo3d/gl_quadstereo.h b/src/gl/stereo3d/gl_quadstereo.h index f27fb78f89..d9aa4f4354 100644 --- a/src/gl/stereo3d/gl_quadstereo.h +++ b/src/gl/stereo3d/gl_quadstereo.h @@ -47,14 +47,6 @@ class QuadStereoLeftPose : public LeftEyePose { public: QuadStereoLeftPose(float ipd) : LeftEyePose(ipd), bQuadStereoSupported(false) {} - virtual void SetUp() const { - if (bQuadStereoSupported) - glDrawBuffer(GL_BACK_LEFT); - } - virtual void TearDown() const { - if (bQuadStereoSupported) - glDrawBuffer(GL_BACK); - } bool bQuadStereoSupported; }; @@ -62,14 +54,6 @@ class QuadStereoRightPose : public RightEyePose { public: QuadStereoRightPose(float ipd) : RightEyePose(ipd), bQuadStereoSupported(false){} - virtual void SetUp() const { - if (bQuadStereoSupported) - glDrawBuffer(GL_BACK_RIGHT); - } - virtual void TearDown() const { - if (bQuadStereoSupported) - glDrawBuffer(GL_BACK); - } bool bQuadStereoSupported; }; @@ -84,10 +68,12 @@ class QuadStereo : public Stereo3DMode { public: QuadStereo(double ipdMeters); + void Present() const override; static const QuadStereo& getInstance(float ipd); private: QuadStereoLeftPose leftEye; QuadStereoRightPose rightEye; + bool bQuadStereoSupported; }; diff --git a/src/gl/stereo3d/gl_stereo3d.cpp b/src/gl/stereo3d/gl_stereo3d.cpp index e1c4f63068..d686a4a43e 100644 --- a/src/gl/stereo3d/gl_stereo3d.cpp +++ b/src/gl/stereo3d/gl_stereo3d.cpp @@ -36,7 +36,6 @@ #include "gl/system/gl_system.h" #include "gl/stereo3d/gl_stereo3d.h" #include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_renderbuffers.h" #include "vectors.h" // RAD2DEG #include "doomtype.h" // M_PI @@ -80,28 +79,6 @@ Stereo3DMode::~Stereo3DMode() { } -void Stereo3DMode::Present() const -{ - // Example copying eye textures to the back buffer: - - // The letterbox for the output destination. - // If stereo modes needs different dimensions then that needs to be added to FGLRenderer::SetOutputViewport. - const auto &box = GLRenderer->mOutputLetterbox; - - GLRenderer->mBuffers->BindOutputFB(); - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - for (int eye_ix = 0; eye_ix < eye_count(); ++eye_ix) - { - GLRenderer->mBuffers->BindEyeFB(eye_ix, true); - int width = GLRenderer->mBuffers->GetWidth(); - int height = GLRenderer->mBuffers->GetHeight(); - glBlitFramebuffer(0, 0, width, height, box.left + eye_ix * box.width / eye_count(), box.top, box.left + (eye_ix + 1) * box.width / eye_count(), box.height, GL_COLOR_BUFFER_BIT, GL_LINEAR); - } - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); -} - // Avoid static initialization order fiasco by declaring first Mode type (Mono) here in the // same source file as Stereo3DMode::getCurrentMode() // https://isocpp.org/wiki/faq/ctors#static-init-order diff --git a/src/gl/stereo3d/gl_stereo3d.h b/src/gl/stereo3d/gl_stereo3d.h index 3cac6b79d5..2cb9417d28 100644 --- a/src/gl/stereo3d/gl_stereo3d.h +++ b/src/gl/stereo3d/gl_stereo3d.h @@ -86,7 +86,7 @@ public: virtual void TearDown() const {}; virtual bool IsMono() const { return false; } - virtual void Present() const; + virtual void Present() const = 0; protected: TArray eye_ptrs; @@ -106,6 +106,7 @@ public: static const MonoView& getInstance(); bool IsMono() const override { return true; } + void Present() const override { } protected: MonoView() { eye_ptrs.Push(¢ralEye); } diff --git a/src/gl/stereo3d/gl_stereo_leftright.cpp b/src/gl/stereo3d/gl_stereo_leftright.cpp index 354185792b..8605c9b535 100644 --- a/src/gl/stereo3d/gl_stereo_leftright.cpp +++ b/src/gl/stereo3d/gl_stereo_leftright.cpp @@ -37,7 +37,10 @@ #include "vectors.h" // RAD2DEG #include "doomtype.h" // M_PI #include "gl/system/gl_cvars.h" +#include "gl/system/gl_system.h" +#include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_renderer.h" +#include "gl/renderer/gl_renderbuffers.h" #include EXTERN_CVAR(Float, vr_screendist) @@ -89,6 +92,13 @@ const LeftEyeView& LeftEyeView::getInstance(float ipd) return instance; } +void LeftEyeView::Present() const +{ + GLRenderer->mBuffers->BindOutputFB(); + GLRenderer->ClearBorders(); + GLRenderer->mBuffers->BindEyeTexture(0, 0); + GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true); +} /* static */ const RightEyeView& RightEyeView::getInstance(float ipd) @@ -98,5 +108,13 @@ const RightEyeView& RightEyeView::getInstance(float ipd) return instance; } +void RightEyeView::Present() const +{ + GLRenderer->mBuffers->BindOutputFB(); + GLRenderer->ClearBorders(); + GLRenderer->mBuffers->BindEyeTexture(0, 0); + GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true); +} + } /* namespace s3d */ diff --git a/src/gl/stereo3d/gl_stereo_leftright.h b/src/gl/stereo3d/gl_stereo_leftright.h index de13a32cb8..2508466514 100644 --- a/src/gl/stereo3d/gl_stereo_leftright.h +++ b/src/gl/stereo3d/gl_stereo_leftright.h @@ -83,6 +83,7 @@ public: LeftEyeView(float ipd) : eye(ipd) { eye_ptrs.Push(&eye); } float getIpd() const { return eye.getIpd(); } void setIpd(float ipd) { eye.setIpd(ipd); } + void Present() const override; protected: LeftEyePose eye; }; @@ -96,6 +97,7 @@ public: RightEyeView(float ipd) : eye(ipd) { eye_ptrs.Push(&eye); } float getIpd() const { return eye.getIpd(); } void setIpd(float ipd) { eye.setIpd(ipd); } + void Present() const override; protected: RightEyePose eye; };