Developer Documentation
Loading...
Searching...
No Matches
PostProcessorAnaglyphPlugin.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43#include "PostProcessorAnaglyphPlugin.hh"
44
45#include <ACG/GL/ScreenQuad.hh>
46#include <ACG/GL/ShaderCache.hh>
47
50
51
52PostProcessorAnaglyphPlugin::PostProcessorAnaglyphPlugin()
53{
54}
55
56PostProcessorAnaglyphPlugin::~PostProcessorAnaglyphPlugin()
57{
58}
59
60QString PostProcessorAnaglyphPlugin::checkOpenGL() {
61 if (!ACG::openGLVersion(3, 0))
62 return QString("Insufficient OpenGL Version! OpenGL 3.0 or higher required");
63
64 return QString("");
65}
66
67
68
69QString PostProcessorAnaglyphPlugin::postProcessorName() {
70 return QString("AnaglyphStereo");
71}
72
73
74void PostProcessorAnaglyphPlugin::postProcess(ACG::GLState* _glstate, const std::vector<const PostProcessorInput*>& _input, const PostProcessorOutput& _output) {
75
76 if (_input.size() != 2) {
77 std::cerr << "PostProcessorAnaglyphPlugin: two input images required!" << std::endl;
78 return;
79 }
80
81 // ======================================================================================================
82 // Fetch shader from cache
83 // ======================================================================================================
84
85 QStringList macros;
86
87 if (OpenFlipper::Options::stereoMode () == OpenFlipper::Options::AnaglyphCustom)
88 macros.push_back("#define ANAGLYPH_CUSTOM");
89
90 GLSL::Program* shader = ACG::ShaderCache::getInstance()->getProgram("ScreenQuad/screenquad.glsl", "AnaglyphStereo/anaglyph.glsl", &macros);
91
92 // ======================================================================================================
93 // Bind input texture
94 // ======================================================================================================
95
96 _input[1]->bindColorTex(1);
97 _input[0]->bindColorTex(0);
98
99 // ======================================================================================================
100 // Bind output FBO
101 // ======================================================================================================
102
103 _output.bind();
104
105 // ======================================================================================================
106 // Setup render states
107 // ======================================================================================================
108
109 glDepthMask(1);
110 glColorMask(1,1,1,1);
111
112 glDisable(GL_DEPTH_TEST);
113 glDisable(GL_BLEND);
114
115 // ======================================================================================================
116 // Setup shader
117 // ======================================================================================================
118
119 shader->use();
120 shader->setUniform("SceneLeft", 0);
121 shader->setUniform("SceneRight", 1);
122
123 if (OpenFlipper::Options::stereoMode () == OpenFlipper::Options::AnaglyphCustom)
124 {
125 // column major
126 std::vector<float> le = OpenFlipper::Options::anaglyphLeftEyeColorMatrix();
127 std::vector<float> re = OpenFlipper::Options::anaglyphRightEyeColorMatrix();
128
129 ACG::GLMatrixf ml, mr;
130
131 for (int r = 0; r < 3; ++r)
132 {
133 for (int c = 0; c < 3; ++c)
134 {
135 ml(r,c) = le[c*3 + r];
136 mr(r,c) = re[c*3 + r];
137 }
138 }
139
140 shader->setUniformMat3("EyeColMatrixLeft", ml);
141 shader->setUniformMat3("EyeColMatrixRight", mr);
142 }
143
144 // ======================================================================================================
145 // Execute
146 // ======================================================================================================
147
148 ACG::ScreenQuad::draw(shader);
149
150
151 shader->disable();
152}
153
154
155
static void draw(GLSL::Program *_prog=0)
Draw the screen quad.
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
GLSL program class.
void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed=false)
Set 3x3fMatrix uniform to specified value.
void disable()
Resets to standard rendering pipeline.
void use()
Enables the program object for using.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
bool openGLVersion(const int _major, const int _minor, bool _verbose)
Definition gl.cc:129