1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
45 #include "OSGRenderOptions.h"
46 #include "OSGRenderActionBase.h"
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.
58 RenderOptions::RenderOptions(void) :
63 _polygon_mode(GL_FILL
),
64 _backface_culling(false),
65 _two_sided_lighting(false),
66 _spec_tex_lighting(false)
72 RenderOptions::RenderOptions(const RenderOptions
&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
)
86 RenderOptions::~RenderOptions(void)
92 void RenderOptions::initMethod(InitPhase ePhase
)
94 Inherited::initMethod(ePhase
);
99 void RenderOptions::changed(ConstFieldMaskArg whichField
,
103 _changed
|= whichField
;
105 Inherited::changed(whichField
, origin
, details
);
108 void RenderOptions::setWireframe(bool value
)
113 setPolygonMode(GL_LINE
);
117 setPolygonMode(GL_FILL
);
122 bool RenderOptions::getWireframe(void)
125 return getPolygonMode() == GL_LINE
;
131 BitVector
RenderOptions::getChanged(void)
136 BitVector
RenderOptions::getLastChanged(void)
138 return _last_changed
;
141 void RenderOptions::activate(RenderActionBase
*pAction
)
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
)
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
);
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
);
234 glDisable(GL_CULL_FACE
);
238 if(_two_sided_lighting
)
239 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE
, GL_TRUE
);
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
);
252 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL
,
257 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
,
258 getLightModelAmbient().getValuesRGBA());
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());
274 _last_changed
= _changed
;