00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041
00042 #include <OSGConfig.h>
00043 #include <OSGGLEXT.h>
00044
00045 #include "OSGRenderOptions.h"
00046 #include "OSGRenderAction.h"
00047
00048 OSG_USING_NAMESPACE
00049
00050
00056 RenderOptions::RenderOptions(void) :
00057 Inherited(),
00058 _changed(0),
00059 _last_changed(0),
00060 _gl_version(0.0f),
00061 _polygon_mode(GL_FILL),
00062 _backface_culling(false),
00063 _two_sided_lighting(false),
00064 _spec_tex_lighting(false)
00065 {
00066 }
00067
00073 RenderOptions::RenderOptions(const RenderOptions &source) :
00074 Inherited(source),
00075 _changed(source._changed),
00076 _last_changed(source._last_changed),
00077 _gl_version(source._gl_version),
00078 _polygon_mode(source._polygon_mode),
00079 _backface_culling(source._backface_culling),
00080 _two_sided_lighting(source._two_sided_lighting),
00081 _spec_tex_lighting(source._spec_tex_lighting)
00082 {
00083 }
00084
00090 RenderOptions::~RenderOptions(void)
00091 {
00092 }
00093
00099 void RenderOptions::initMethod (void)
00100 {
00101 }
00102
00108 void RenderOptions::changed(BitVector whichField, UInt32 origin)
00109 {
00110 _changed |= whichField;
00111 Inherited::changed(whichField, origin);
00112 }
00113
00114 void RenderOptions::setWireframe( bool value )
00115 {
00116 if(value)
00117 setPolygonMode(GL_LINE);
00118 else
00119 setPolygonMode(GL_FILL);
00120 }
00121
00122 bool RenderOptions::getWireframe( void )
00123 {
00124 return getPolygonMode() == GL_LINE;
00125 }
00126
00127 BitVector RenderOptions::getChanged( void )
00128 {
00129 return _changed;
00130 }
00131
00132 BitVector RenderOptions::getLastChanged( void )
00133 {
00134 return _last_changed;
00135 }
00136
00137 void RenderOptions::activateOptions(RenderAction *action)
00138 {
00139 if(_gl_version == 0.0f)
00140 {
00141
00142 std::string vstr = (const char *) glGetString(GL_VERSION);
00143
00144 vstr = vstr.substr(0, 3);
00145 _gl_version = atof(vstr.c_str());
00146 }
00147
00148 if(_changed & PolygonModeFieldMask)
00149 _polygon_mode = getPolygonMode();
00150
00151 if(_changed & BackfaceCullingFieldMask)
00152 _backface_culling = getBackfaceCulling();
00153
00154 if(_changed & CorrectTwoSidedLightingFieldMask)
00155 action->setCorrectTwoSidedLighting(getCorrectTwoSidedLighting());
00156
00157 if(_changed & TwoSidedLightingFieldMask)
00158 _two_sided_lighting = getTwoSidedLighting();
00159
00160 if(_changed & SortTransFieldMask)
00161 action->setSortTrans(getSortTrans());
00162
00163 if(_changed & ZWriteTransFieldMask)
00164 action->setZWriteTrans(getZWriteTrans());
00165
00166 if(_changed & LocalLightsFieldMask)
00167 action->setLocalLights(getLocalLights());
00168
00169 if(_changed & SpecTexLightingFieldMask)
00170 _spec_tex_lighting = getSpecTexLighting();
00171
00172 if(_changed & OcclusionCullingFieldMask)
00173 action->setOcclusionCulling(getOcclusionCulling());
00174
00175 if(_changed & OcclusionCullingModeFieldMask)
00176 action->setOcclusionCullingMode(getOcclusionCullingMode());
00177
00178 if(_changed & OcclusionCullingPixelsFieldMask)
00179 action->setOcclusionCullingPixels(getOcclusionCullingPixels());
00180
00181 if(_changed & SmallFeatureCullingFieldMask)
00182 action->setSmallFeatureCulling(getSmallFeatureCulling());
00183
00184 if(_changed & SmallFeaturePixelsFieldMask)
00185 action->setSmallFeaturePixels(getSmallFeaturePixels());
00186
00187 if(_changed & SmallFeatureThresholdFieldMask)
00188 action->setSmallFeatureThreshold(getSmallFeatureThreshold());
00189
00190 if(_changed & FrustumCullingFieldMask)
00191 action->setFrustumCulling(getFrustumCulling());
00192
00193
00194 glPolygonMode(GL_FRONT_AND_BACK, _polygon_mode);
00195
00196 if(_backface_culling)
00197 {
00198 glEnable(GL_CULL_FACE);
00199 glCullFace(GL_BACK);
00200 }
00201 else
00202 {
00203 glDisable(GL_CULL_FACE);
00204 glCullFace(GL_BACK);
00205 }
00206
00207 if(_two_sided_lighting)
00208 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00209 else
00210 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
00211
00212 if(_gl_version >= 1.2f)
00213 {
00214 if(_spec_tex_lighting)
00215 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
00216 else
00217 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
00218 }
00219
00220 _last_changed = _changed;
00221 _changed = 0;
00222 }