fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Base / OSGRenderOptions.cpp
blob8c4698bf50042a6b41396c7fb0ce896eff85a3a1
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
43 #include "OSGGLEXT.h"
45 #include "OSGRenderOptions.h"
46 #include "OSGRenderActionBase.h"
48 OSG_USING_NAMESPACE
50 // Documentation for this class is emited in the
51 // OSGRenderOptionsBase.cpp file.
52 // To modify it, please change the .fcd file (OSGRenderOptions.fcd) and
53 // regenerate the base file.
55 /*!
58 RenderOptions::RenderOptions(void) :
59 Inherited(),
60 _changed(0),
61 _last_changed(0),
62 _gl_version(0.0f),
63 _polygon_mode(GL_FILL),
64 _backface_culling(false),
65 _two_sided_lighting(false),
66 _spec_tex_lighting(false)
70 /*!
72 RenderOptions::RenderOptions(const RenderOptions &source) :
73 Inherited(source),
74 _changed(source._changed),
75 _last_changed(source._last_changed),
76 _gl_version(source._gl_version),
77 _polygon_mode(source._polygon_mode),
78 _backface_culling(source._backface_culling),
79 _two_sided_lighting(source._two_sided_lighting),
80 _spec_tex_lighting(source._spec_tex_lighting)
84 /*!
86 RenderOptions::~RenderOptions(void)
90 /*!
92 void RenderOptions::initMethod(InitPhase ePhase)
94 Inherited::initMethod(ePhase);
97 /*!
99 void RenderOptions::changed(ConstFieldMaskArg whichField,
100 UInt32 origin,
101 BitVector details)
103 _changed |= whichField;
105 Inherited::changed(whichField, origin, details);
108 void RenderOptions::setWireframe(bool value)
110 #ifndef OSG_OGL_ES2
111 if(value)
113 setPolygonMode(GL_LINE);
115 else
117 setPolygonMode(GL_FILL);
119 #endif
122 bool RenderOptions::getWireframe(void)
124 #ifndef OSG_OGL_ES2
125 return getPolygonMode() == GL_LINE;
126 #else
127 return false;
128 #endif
131 BitVector RenderOptions::getChanged(void)
133 return _changed;
136 BitVector RenderOptions::getLastChanged(void)
138 return _last_changed;
141 void RenderOptions::activate(RenderActionBase *pAction)
143 if(pAction == NULL)
144 return;
147 fprintf(stderr, "ac:pro : %016llx\n",
148 this->getRenderProperties());
150 pAction->addRenderProperties(this->getRenderProperties());
151 pAction->setUseGLFinish (this->getUseGLFinish ());
154 void RenderOptions::deactivate(RenderActionBase *pAction)
156 if(pAction == NULL)
157 return;
159 pAction->subRenderProperties(this->getRenderProperties());
160 pAction->setUseGLFinish (false );
164 #ifdef OSG_OLD_RENDER_ACTION
165 void RenderOptions::activateOptions(RenderAction *action)
167 if(_gl_version == 0.0f)
169 // detect OpenGL version.
170 std::string vstr = (const char *) glGetString(GL_VERSION);
171 // remove last .x
172 vstr = vstr.substr(0, 3);
173 _gl_version = atof(vstr.c_str());
176 if(_changed & PolygonModeFieldMask)
177 _polygon_mode = getPolygonMode();
179 if(_changed & BackfaceCullingFieldMask)
180 _backface_culling = getBackfaceCulling();
182 if(_changed & CorrectTwoSidedLightingFieldMask)
183 action->setCorrectTwoSidedLighting(getCorrectTwoSidedLighting());
185 if(_changed & TwoSidedLightingFieldMask)
186 _two_sided_lighting = getTwoSidedLighting();
188 if(_changed & SortTransFieldMask)
189 action->setSortTrans(getSortTrans());
191 if(_changed & ZWriteTransFieldMask)
192 action->setZWriteTrans(getZWriteTrans());
194 if(_changed & LocalLightsFieldMask)
195 action->setLocalLights(getLocalLights());
197 if(_changed & SpecTexLightingFieldMask)
198 _spec_tex_lighting = getSpecTexLighting();
200 if(_changed & OcclusionCullingFieldMask)
201 action->setOcclusionCulling(getOcclusionCulling());
203 if(_changed & OcclusionCullingModeFieldMask)
204 action->setOcclusionCullingMode(getOcclusionCullingMode());
206 if(_changed & OcclusionCullingPixelsFieldMask)
207 action->setOcclusionCullingPixels(getOcclusionCullingPixels());
209 if(_changed & SmallFeatureCullingFieldMask)
210 action->setSmallFeatureCulling(getSmallFeatureCulling());
212 if(_changed & SmallFeaturePixelsFieldMask)
213 action->setSmallFeaturePixels(getSmallFeaturePixels());
215 if(_changed & SmallFeatureThresholdFieldMask)
216 action->setSmallFeatureThreshold(getSmallFeatureThreshold());
218 if(_changed & FrustumCullingFieldMask)
219 action->setFrustumCulling(getFrustumCulling());
221 if(_changed & DepthOnlyPassFieldMask)
222 action->setDepthOnlyPass(getDepthOnlyPass());
224 // we update the gl stuff each frame.
225 glPolygonMode(GL_FRONT_AND_BACK, _polygon_mode);
227 if(_backface_culling)
229 glEnable(GL_CULL_FACE);
230 glCullFace(GL_BACK);
232 else
234 glDisable(GL_CULL_FACE);
235 glCullFace(GL_BACK);
238 if(_two_sided_lighting)
239 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
240 else
241 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
243 if(_gl_version >= 1.2f)
245 if(_spec_tex_lighting)
247 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,
248 GL_SEPARATE_SPECULAR_COLOR);
250 else
252 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,
253 GL_SINGLE_COLOR);
257 glLightModelfv(GL_LIGHT_MODEL_AMBIENT,
258 getLightModelAmbient().getValuesRGBA());
260 if ( getFogMode() )
262 glEnable(GL_FOG);
263 glFogi(GL_FOG_MODE, getFogMode());
264 glFogf(GL_FOG_DENSITY, getFogDensity());
265 glFogf(GL_FOG_START, getFogRange().x());
266 glFogf(GL_FOG_END, getFogRange().y());
267 glFogfv(GL_FOG_COLOR, getFogColor().getValuesRGBA());
269 else
271 glDisable(GL_FOG);
274 _last_changed = _changed;
275 _changed = 0;
277 #endif