Developer Documentation
Renderer.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#include <ACG/GL/acg_glew.hh>
43#include "Renderer.hh"
44
45#include <cstdio>
46#include <iostream>
47#include <cstdlib>
48
49#include <QSurfaceFormat>
50
51#include <ACG/GL/gl.hh>
52
53#include <OpenFlipper/common/ViewObjectMarker.hh>
54#include <ACG/Utils/Profile.hh>
55
56#include <ACG/Scenegraph/StencilRefNode.hh>
57
58using namespace ACG;
59
60// =================================================
61
62Renderer::Renderer()
63{
64}
65
66
67Renderer::~Renderer()
68{
69}
70
71
72void Renderer::initializePlugin()
73{
74}
75
76
77void Renderer::render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties)
78{
80
81 if (root) {
82 ViewObjectMarker *oM = _properties.objectMarker();
83 GLuint refBits = 0;
84 QSet<GLuint> references;
85
86 if (oM)
87 {
88 ACG::GLState::enable(GL_STENCIL_TEST);
89 glClearStencil(0);
90 glClear(GL_STENCIL_BUFFER_BIT);
91 glStencilOp (GL_KEEP, GL_KEEP, GL_ZERO);
92 glStencilFunc (GL_ALWAYS, 0, ~0);
93
95 o_it != PluginFunctions::objectsEnd(); ++o_it)
96 {
97 bool ok;
98 GLuint ref;
99
100 ok = oM->stencilRefForObject(*o_it, ref);
101
102 if (ok)
103 {
104 o_it->stencilRefNode ()->setReference (ref);
105 o_it->stencilRefNode ()->show ();
106 refBits |= ref;
107 references << ref;
108 }
109 else
110 o_it->stencilRefNode ()->hide ();
111 }
112 }
113
114 ACG::SceneGraph::DrawAction action( _properties.drawMode(), *_glState , false);
115 ACG::SceneGraph::traverse_multipass(root, action, *_glState, _properties.drawMode() );
116
117 // Second pass for blending
118 ACG::SceneGraph::DrawAction action1(_properties.drawMode(), *_glState, true);
119 ACG::SceneGraph::traverse_multipass(root, action1, *_glState, _properties.drawMode());
120
121 if (oM)
122 {
123 if (oM->type() == ViewObjectMarker::PerBit)
124 {
125 references.clear ();
126 for (unsigned int i = 0; i < sizeof (GLuint) * 8; i++)
127 if (refBits & (1 << i))
128 references << (1 << i);
129 }
130
131 glPushAttrib(GL_ALL_ATTRIB_BITS);
132
133 ACG::GLState::enable(GL_BLEND);
134 ACG::GLState::disable(GL_DEPTH_TEST);
135 ACG::GLState::disable(GL_LIGHTING);
136 ACG::GLState::disable(GL_DITHER);
137
138 int vp_l, vp_b, vp_w, vp_h;
139 _glState->get_viewport (vp_l, vp_b, vp_w, vp_h);
140
141 glMatrixMode(GL_PROJECTION);
142 glPushMatrix ();
143 glLoadIdentity();
144 glOrtho(0, vp_w, vp_h, 0, 0, 1.0);
145 glMatrixMode(GL_MODELVIEW);
146 glPushMatrix ();
147 glLoadIdentity();
148
149 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
150
151 foreach (unsigned int ref, references)
152 {
153 bool ok;
154 GLenum sfactor;
155 GLenum dfactor;
156 ACG::Vec4f color;
157 unsigned int mask = ~0;
158
159 if (oM->type() == ViewObjectMarker::PerBit)
160 {
161 ok = oM->blendForStencilRefBit (ref, sfactor, dfactor, color);
162 mask = ref;
163 }
164 else
165 ok = oM->blendForStencilRefNumber (ref, sfactor, dfactor, color);
166
167 if (!ok)
168 continue;
169
170 glStencilFunc (GL_EQUAL, ref, mask);
171
172 ACG::GLState::blendFunc (sfactor, dfactor);
173 glColor4f (color[0], color [1], color [2], color[3]);
174
175 glBegin (GL_QUADS);
176 glVertex2i(0, 0);
177 glVertex2i(0, vp_h);
178 glVertex2i(vp_w, vp_h);
179 glVertex2i(vp_w, 0);
180 glEnd ();
181
182 }
183
184 glMatrixMode(GL_PROJECTION);
185 glPopMatrix ();
186 glMatrixMode(GL_MODELVIEW);
187 glPopMatrix ();
188
189 glPopAttrib ();
190 ACG::GLState::disable (GL_STENCIL_TEST);
191 }
192
193
194 }
195}
196
197QString Renderer::checkOpenGL()
198{
200 return QString("Classic Rendering-plugin is not available for OpenGL core contexts.");
201 // Get version and check
202 if ( !ACG::Profile::isCompatibilityProfile() )
203 return QString("This plugin requires an OpenGL compatibility context to work.");
204
205 // This renderer plugin should run on almost any old style hardware
206 return QString("");
207
208}
209
210
211
212
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
Definition: GLState.cc:1507
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Definition: GLState.hh:307
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
Definition: GLState.cc:1527
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
Definition: GLState.hh:841
virtual bool blendForStencilRefBit(GLuint _refbit, GLenum &_src, GLenum &_dst, ACG::Vec4f &_color)
virtual bool blendForStencilRefNumber(GLuint _reference, GLenum &_src, GLenum &_dst, ACG::Vec4f &_color)
@ PerBit
Mark per returned reference bits.
virtual bool stencilRefForObject(BaseObjectData *_obj, GLuint &_reference)=0
void objectMarker(ViewObjectMarker *_marker)
set object marker for viewer
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
Definition: SceneGraph.hh:254
Namespace providing different geometric functions concerning angles.
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
Definition: gl.cc:166
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
const QStringList ALL_OBJECTS
Iterable object range.