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
00049 #ifndef GL_NV_multisample_filter_hint
00050 # define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534
00051 #endif
00052
00053 #ifndef GL_VERSION_1_3
00054 # define GL_MULTISAMPLE 0x809D
00055 # define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
00056 # define GL_SAMPLE_ALPHA_TO_ONE 0x809F
00057 # define GL_SAMPLE_COVERAGE 0x80A0
00058 # define GL_SAMPLE_BUFFERS 0x80A8
00059 # define GL_SAMPLES 0x80A9
00060 # define GL_SAMPLE_COVERAGE_VALUE 0x80AA
00061 # define GL_SAMPLE_COVERAGE_INVERT 0x80AB
00062 # define GL_MULTISAMPLE_BIT 0x20000000
00063 #endif
00064
00065 OSG_USING_NAMESPACE
00066
00067
00073 RenderOptions::RenderOptions(void) :
00074 Inherited(),
00075 _changed(0),
00076 _last_changed(0),
00077 _gl_version(0.0f),
00078 _polygon_mode(GL_FILL),
00079 _backface_culling(false),
00080 _two_sided_lighting(false),
00081 _spec_tex_lighting(false)
00082 {
00083 }
00084
00090 RenderOptions::RenderOptions(const RenderOptions &source) :
00091 Inherited(source),
00092 _changed(source._changed),
00093 _last_changed(source._last_changed),
00094 _gl_version(source._gl_version),
00095 _polygon_mode(source._polygon_mode),
00096 _backface_culling(source._backface_culling),
00097 _two_sided_lighting(source._two_sided_lighting),
00098 _spec_tex_lighting(source._spec_tex_lighting)
00099 {
00100 }
00101
00107 RenderOptions::~RenderOptions(void)
00108 {
00109 }
00110
00116 void RenderOptions::initMethod (void)
00117 {
00118 }
00119
00125 void RenderOptions::changed(BitVector whichField, UInt32 origin)
00126 {
00127 _changed |= whichField;
00128 Inherited::changed(whichField, origin);
00129 }
00130
00131 void RenderOptions::setWireframe( bool value )
00132 {
00133 if(value)
00134 setPolygonMode(GL_LINE);
00135 else
00136 setPolygonMode(GL_FILL);
00137 }
00138
00139 bool RenderOptions::getWireframe( void )
00140 {
00141 return getPolygonMode() == GL_LINE;
00142 }
00143
00144 BitVector RenderOptions::getChanged( void )
00145 {
00146 return _changed;
00147 }
00148
00149 BitVector RenderOptions::getLastChanged( void )
00150 {
00151 return _last_changed;
00152 }
00153
00154 void RenderOptions::activateOptions(RenderAction *action)
00155 {
00156 if(_gl_version == 0.0f)
00157 {
00158
00159 std::string vstr =
00160 reinterpret_cast<const char *>(glGetString(GL_VERSION));
00161
00162
00163 vstr = vstr.substr(0, 3);
00164 _gl_version = atof(vstr.c_str());
00165 }
00166
00167 if(_changed & PolygonModeFieldMask)
00168 _polygon_mode = getPolygonMode();
00169
00170 if(_changed & BackfaceCullingFieldMask)
00171 _backface_culling = getBackfaceCulling();
00172
00173 if(_changed & CorrectTwoSidedLightingFieldMask)
00174 action->setCorrectTwoSidedLighting(getCorrectTwoSidedLighting());
00175
00176 if(_changed & TwoSidedLightingFieldMask)
00177 _two_sided_lighting = getTwoSidedLighting();
00178
00179 if(_changed & SortTransFieldMask)
00180 action->setSortTrans(getSortTrans());
00181
00182 if(_changed & ZWriteTransFieldMask)
00183 action->setZWriteTrans(getZWriteTrans());
00184
00185 if(_changed & LocalLightsFieldMask)
00186 action->setLocalLights(getLocalLights());
00187
00188 if(_changed & SpecTexLightingFieldMask)
00189 _spec_tex_lighting = getSpecTexLighting();
00190
00191 if(_changed & OcclusionCullingFieldMask)
00192 action->setOcclusionCulling(getOcclusionCulling());
00193
00194 if(_changed & OcclusionCullingModeFieldMask)
00195 action->setOcclusionCullingMode(getOcclusionCullingMode());
00196
00197 if(_changed & OcclusionCullingPixelsFieldMask)
00198 action->setOcclusionCullingPixels(getOcclusionCullingPixels());
00199
00200 if(_changed & SmallFeatureCullingFieldMask)
00201 action->setSmallFeatureCulling(getSmallFeatureCulling());
00202
00203 if(_changed & SmallFeaturePixelsFieldMask)
00204 action->setSmallFeaturePixels(getSmallFeaturePixels());
00205
00206 if(_changed & SmallFeatureThresholdFieldMask)
00207 action->setSmallFeatureThreshold(getSmallFeatureThreshold());
00208
00209 if(_changed & FrustumCullingFieldMask)
00210 action->setFrustumCulling(getFrustumCulling());
00211
00212 if(_changed & DepthOnlyPassFieldMask)
00213 action->setDepthOnlyPass(getDepthOnlyPass());
00214
00215
00216 glPolygonMode(GL_FRONT_AND_BACK, _polygon_mode);
00217
00218 if(_backface_culling)
00219 {
00220 glEnable(GL_CULL_FACE);
00221 glCullFace(GL_BACK);
00222 }
00223 else
00224 {
00225 glDisable(GL_CULL_FACE);
00226 glCullFace(GL_BACK);
00227 }
00228
00229
00230 if ((getMultiSample() > 1) && (getMultiSampleFilterMode()))
00231 {
00232 GLint bufs = 0, samples = 0;
00233 glGetIntegerv (GL_SAMPLE_BUFFERS, &bufs);
00234 glGetIntegerv (GL_SAMPLES, &samples);
00235
00236 if (bufs > 1 || (samples != getMultiSample()))
00237 {
00238 static bool firstTime = true;
00239 if (firstTime)
00240 {
00241 FWARNING (( "Invalid multi-sample window setting: %d/%d\n",
00242 bufs, samples ));
00243 firstTime = false;
00244 }
00245 }
00246
00247 glEnable ( GL_MULTISAMPLE );
00248 glHint ( GL_MULTISAMPLE_FILTER_HINT_NV,
00249 getMultiSampleFilterMode () );
00250 }
00251 else
00252 glDisable ( GL_MULTISAMPLE );
00253
00254 if(_two_sided_lighting)
00255 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00256 else
00257 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
00258
00259 if(_gl_version >= 1.2f)
00260 {
00261 if(_spec_tex_lighting)
00262 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
00263 else
00264 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
00265 }
00266
00267 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, getLightModelAmbient().getValuesRGBA());
00268
00269 if ( getFogMode() ) {
00270 glEnable(GL_FOG);
00271 glFogi(GL_FOG_MODE, getFogMode());
00272 glFogf(GL_FOG_DENSITY, getFogDensity());
00273 glFogf(GL_FOG_START, getFogRange().x());
00274 glFogf(GL_FOG_END, getFogRange().y());
00275 glFogfv(GL_FOG_COLOR, getFogColor().getValuesRGBA());
00276 }
00277 else {
00278 glDisable(GL_FOG);
00279 }
00280
00281 _last_changed = _changed;
00282 _changed = 0;
00283 }