Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * *
44 * $Revision: 19248 $ *
45 * $LastChangedBy: moebius $ *
46 * $Date: 2014-07-21 14:27:08 +0200 (Mon, 21 Jul 2014) $ *
47 * *
48 \*===========================================================================*/
49 
50 #include "PostProcessorAnaglyphPlugin.hh"
51 
52 #include <ACG/GL/ScreenQuad.hh>
53 #include <ACG/GL/ShaderCache.hh>
54 
57 
58 
59 PostProcessorAnaglyphPlugin::PostProcessorAnaglyphPlugin()
60 {
61 }
62 
63 PostProcessorAnaglyphPlugin::~PostProcessorAnaglyphPlugin()
64 {
65 }
66 
67 QString PostProcessorAnaglyphPlugin::checkOpenGL() {
68  if (!ACG::openGLVersion(3, 0))
69  return QString("Insufficient OpenGL Version! OpenGL 3.0 or higher required");
70 
71  return QString("");
72 }
73 
74 
75 
76 QString PostProcessorAnaglyphPlugin::postProcessorName() {
77  return QString("AnaglyphStereo");
78 }
79 
80 
81 void PostProcessorAnaglyphPlugin::postProcess(ACG::GLState* _glstate, const std::vector<const PostProcessorInput*>& _input, const PostProcessorOutput& _output) {
82 
83  if (_input.size() != 2) {
84  std::cerr << "PostProcessorAnaglyphPlugin: two input images required!" << std::endl;
85  return;
86  }
87 
88  // ======================================================================================================
89  // Fetch shader from cache
90  // ======================================================================================================
91 
92  QStringList macros;
93 
94  if (OpenFlipper::Options::stereoMode () == OpenFlipper::Options::AnaglyphCustom)
95  macros.push_back("#define ANAGLYPH_CUSTOM");
96 
97  GLSL::Program* shader = ACG::ShaderCache::getInstance()->getProgram("ScreenQuad/screenquad.glsl", "AnaglyphStereo/anaglyph.glsl", &macros);
98 
99  // ======================================================================================================
100  // Bind input texture
101  // ======================================================================================================
102 
103  _input[1]->bindColorTex(1);
104  _input[0]->bindColorTex(0);
105 
106  // ======================================================================================================
107  // Bind output FBO
108  // ======================================================================================================
109 
110  _output.bind();
111 
112  // ======================================================================================================
113  // Setup render states
114  // ======================================================================================================
115 
116  glDepthMask(1);
117  glColorMask(1,1,1,1);
118 
119  glDisable(GL_DEPTH_TEST);
120  glDisable(GL_BLEND);
121 
122  // ======================================================================================================
123  // Setup shader
124  // ======================================================================================================
125 
126  shader->use();
127  shader->setUniform("SceneLeft", 0);
128  shader->setUniform("SceneRight", 1);
129 
130  if (OpenFlipper::Options::stereoMode () == OpenFlipper::Options::AnaglyphCustom)
131  {
132  // column major
133  std::vector<float> le = OpenFlipper::Options::anaglyphLeftEyeColorMatrix();
134  std::vector<float> re = OpenFlipper::Options::anaglyphRightEyeColorMatrix();
135 
136  ACG::GLMatrixf ml, mr;
137 
138  for (int r = 0; r < 3; ++r)
139  {
140  for (int c = 0; c < 3; ++c)
141  {
142  ml(r,c) = le[c*3 + r];
143  mr(r,c) = re[c*3 + r];
144  }
145  }
146 
147  shader->setUniformMat3("EyeColMatrixLeft", ml);
148  shader->setUniformMat3("EyeColMatrixRight", mr);
149  }
150 
151  // ======================================================================================================
152  // Execute
153  // ======================================================================================================
154 
155  ACG::ScreenQuad::draw(shader);
156 
157 
158  shader->disable();
159 }
160 
161 
162 #if QT_VERSION < 0x050000
163  Q_EXPORT_PLUGIN2( postprocessoranaglyphstereoplugin , PostProcessorAnaglyphPlugin );
164 #endif
165 
static void draw(GLSL::Program *_prog=0)
Draw the screen quad.
Definition: ScreenQuad.cc:147
bool openGLVersion(const int _major, const int _minor)
Definition: gl.cc:95
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
Definition: ShaderCache.cc:108
void use()
Enables the program object for using.
Definition: GLSLShader.cc:351
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
Definition: ShaderCache.cc:90
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
Definition: GLSLShader.cc:391
GLSL program class.
Definition: GLSLShader.hh:217
void disable()
Resets to standard rendering pipeline.
Definition: GLSLShader.cc:361
void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed=false)
Set 3x3fMatrix uniform to specified value.
Definition: GLSLShader.cc:669