changed: gcc8 base update
[opensg.git] / Source / System / State / OpenGL / OSGPointChunk.cpp
blob16470ef9714b4388b9a33353e6069da6339639df
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGLEXT.h"
49 #include "OSGGLFuncProtos.h"
51 #include "OSGWindow.h"
52 #include "OSGDrawEnv.h"
54 #include "OSGPointChunk.h"
55 #include "OSGConceptPropertyChecks.h"
57 OSG_USING_NAMESPACE
59 // Documentation for this class is emited in the
60 // OSGPointChunkBase.cpp file.
61 // To modify it, please change the .fcd file (OSGPointChunk.fcd) and
62 // regenerate the base file.
64 /***************************************************************************\
65 * Class variables *
66 \***************************************************************************/
68 #ifndef OSG_OGL_ES2
69 StateChunkClass PointChunk::_class("Point", 1, 50);
70 #else
71 StateChunkClass PointChunk::_class("Point", 1, 110);
72 #endif
74 UInt32 PointChunk::_extPointParameters = Window::invalidExtensionID;
75 UInt32 PointChunk::_extPointSpriteARB = Window::invalidExtensionID;
76 UInt32 PointChunk::_extPointSpriteNV = Window::invalidExtensionID;
77 UInt32 PointChunk::_funcIdPointParameterf = Window::invalidFunctionID;
78 UInt32 PointChunk::_funcIdPointParameterfv = Window::invalidFunctionID;
80 /***************************************************************************\
81 * Class methods *
82 \***************************************************************************/
84 void PointChunk::initMethod(InitPhase ePhase)
86 Inherited::initMethod(ePhase);
88 if(ePhase == TypeObject::SystemPost)
90 _extPointParameters =
91 Window::registerExtension("GL_ARB_point_parameters");
92 _extPointSpriteARB =
93 Window::registerExtension("GL_ARB_point_sprite");
94 _extPointSpriteNV =
95 Window::registerExtension("GL_NV_point_sprite");
96 _funcIdPointParameterf =
97 Window::registerFunction (
98 OSG_DLSYM_UNDERSCORE"glPointParameterfARB",
99 _extPointParameters);
100 _funcIdPointParameterfv =
101 Window::registerFunction (
102 OSG_DLSYM_UNDERSCORE"glPointParameterfvARB",
103 _extPointParameters);
107 /***************************************************************************\
108 * Instance methods *
109 \***************************************************************************/
111 /*-------------------------------------------------------------------------*\
112 - private -
113 \*-------------------------------------------------------------------------*/
115 /*----------------------- constructors & destructors ----------------------*/
117 PointChunk::PointChunk(void) :
118 Inherited()
122 PointChunk::PointChunk(const PointChunk &source) :
123 Inherited(source)
127 PointChunk::~PointChunk(void)
131 /*------------------------- Chunk Class Access ---------------------------*/
133 const StateChunkClass *PointChunk::getClass(void) const
135 return &_class;
138 /*----------------------------- class specific ----------------------------*/
140 void PointChunk::changed(ConstFieldMaskArg whichField,
141 UInt32 origin,
142 BitVector details)
144 Inherited::changed(whichField, origin, details);
147 void PointChunk::dump( UInt32 ,
148 const BitVector ) const
150 SLOG << "Dump PointChunk NI" << std::endl;
153 /*------------------------------ State ------------------------------------*/
155 void PointChunk::activate(DrawEnv *pEnv, UInt32)
157 #ifndef OSG_OGL_ES2
158 if(getSize() != 1.f)
159 glPointSize(getSize());
160 #endif
162 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
163 if(getSmooth())
164 glEnable(GL_POINT_SMOOTH);
165 #endif
167 pEnv->incNumChunkChanges();
169 Window *pWin = pEnv->getWindow();
171 osgSinkUnusedWarning(pWin);
173 #if GL_ARB_point_parameters
174 if(getMinSize() >= 0.f)
176 if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
178 OSGGETGLFUNCBYID_GL3( glPointParameterf,
179 osgGlPointParameterf,
180 _funcIdPointParameterf,
181 pWin);
182 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
183 OSGGETGLFUNCBYID_GL3( glPointParameterfv,
184 osgGlPointParameterfv,
185 _funcIdPointParameterfv,
186 pWin);
188 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, getMinSize());
189 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, getMaxSize());
190 #endif
191 osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB,
192 getFadeThreshold());
194 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
195 GLfloat att[3] = { getConstantAttenuation (),
196 getLinearAttenuation (),
197 getQuadraticAttenuation() };
199 osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
200 #endif
204 #endif
206 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
207 #if GL_ARB_point_sprite
208 if(getSprite())
210 if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
212 #if GL_NV_point_sprite
213 if(pEnv->getWindow()->hasExtension(_extPointSpriteNV))
215 OSGGETGLFUNCBYID_GL3( glPointParameterf,
216 osgGlPointParameterf,
217 _funcIdPointParameterf,
218 pWin);
220 osgGlPointParameterf(GL_POINT_SPRITE_R_MODE_NV,
221 Real32(getRMode()));
223 #endif
225 glEnable(GL_POINT_SPRITE_ARB);
229 #endif
230 #endif
231 #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
232 pEnv;
233 #endif
236 void PointChunk::changeFrom(DrawEnv *pEnv,
237 StateChunk *old_chunk,
238 UInt32 )
240 PointChunk *old = dynamic_cast<PointChunk *>(old_chunk);
242 #ifndef OSG_OGL_ES2
243 if(getSize() != old->getSize())
244 glPointSize(getSize());
245 #endif
247 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
248 if(getSmooth() && !old->getSmooth())
250 glEnable(GL_POINT_SMOOTH);
252 else if(!getSmooth() && old->getSmooth())
254 glDisable(GL_POINT_SMOOTH);
256 #endif
258 pEnv->incNumChunkChanges();
260 Window *pWin = pEnv->getWindow();
262 osgSinkUnusedWarning(pWin);
264 #if GL_ARB_point_parameters
265 if(getMinSize() >= 0.f)
267 if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
269 OSGGETGLFUNCBYID_GL3( glPointParameterf,
270 osgGlPointParameterf,
271 _funcIdPointParameterf,
272 pWin);
273 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
274 OSGGETGLFUNCBYID_GL3( glPointParameterfv,
275 osgGlPointParameterfv,
276 _funcIdPointParameterfv,
277 pWin);
279 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, getMinSize());
280 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, getMaxSize());
281 #endif
282 osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB,
283 getFadeThreshold());
285 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
286 GLfloat att[3] = { getConstantAttenuation (),
287 getLinearAttenuation (),
288 getQuadraticAttenuation() };
290 osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
291 #endif
295 else if(old->getMinSize() >= 0.f)
297 if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
299 OSGGETGLFUNCBYID_GL3( glPointParameterf,
300 osgGlPointParameterf,
301 _funcIdPointParameterf,
302 pWin);
303 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
304 OSGGETGLFUNCBYID_GL3( glPointParameterfv,
305 osgGlPointParameterfv,
306 _funcIdPointParameterfv,
307 pWin);
309 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0);
310 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10);
311 #endif
312 osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1);
314 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
315 GLfloat att[3] = { 1, 0, 0 };
317 osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
318 #endif
321 #endif
323 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
324 #if GL_ARB_point_sprite
325 if(getSprite() && !old->getSprite())
327 if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
329 #if GL_NV_point_sprite
330 if(pEnv->getWindow()->hasExtension(_extPointSpriteNV))
332 OSGGETGLFUNCBYID_GL3( glPointParameterf,
333 osgGlPointParameterf,
334 _funcIdPointParameterf,
335 pWin);
337 osgGlPointParameterf(GL_POINT_SPRITE_R_MODE_NV,
338 Real32(getRMode()));
340 #endif
342 glEnable(GL_POINT_SPRITE_ARB);
346 else if(!getSprite() && old->getSprite())
348 if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
350 glDisable(GL_POINT_SPRITE_ARB);
354 #endif
355 #endif
357 #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
358 pEnv;
359 #endif
362 void PointChunk::deactivate(DrawEnv *pEnv, UInt32)
364 #ifndef OSG_OGL_ES2
365 if(getSize() != 1.f)
366 glPointSize(1.f);
367 #endif
369 Window *pWin = pEnv->getWindow();
371 osgSinkUnusedWarning(pWin);
373 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
374 if(getSmooth())
375 glDisable(GL_POINT_SMOOTH);
376 #endif
378 #if GL_ARB_point_parameters
379 if(getMinSize() >= 0.f)
381 if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
383 OSGGETGLFUNCBYID_GL3( glPointParameterf,
384 osgGlPointParameterf,
385 _funcIdPointParameterf,
386 pWin);
387 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
388 OSGGETGLFUNCBYID_GL3( glPointParameterfv,
389 osgGlPointParameterfv,
390 _funcIdPointParameterfv,
391 pWin);
393 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0);
394 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10);
395 #endif
396 osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1);
398 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
399 GLfloat att[3] = { 1, 0, 0 };
401 osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
402 #endif
406 #endif
408 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
409 #if GL_ARB_point_sprite
410 if(getSprite())
412 if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
414 glDisable(GL_POINT_SPRITE_ARB);
418 #endif
419 #endif
421 #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
422 pEnv;
423 #endif
426 /*-------------------------- Comparison -----------------------------------*/
428 bool PointChunk::isTransparent(void) const
430 return getMinSize() >= 0.f;
433 Real32 PointChunk::switchCost(StateChunk *)
435 return 0;
438 bool PointChunk::operator < (const StateChunk &other) const
440 return this < &other;
443 bool PointChunk::operator == (const StateChunk &other) const
445 PointChunk const *tother = dynamic_cast<PointChunk const*>(&other);
447 if(!tother)
448 return false;
450 if(tother == this)
451 return true;
453 if(getSize() != tother->getSize() ||
454 getSmooth() != tother->getSmooth() ||
455 getMinSize() != tother->getMinSize() ||
456 getMaxSize() != tother->getMaxSize() ||
457 getConstantAttenuation() != tother->getConstantAttenuation() ||
458 getLinearAttenuation() != tother->getLinearAttenuation() ||
459 getQuadraticAttenuation() != tother->getQuadraticAttenuation() ||
460 getFadeThreshold() != tother->getFadeThreshold() ||
461 getSprite() != tother->getSprite() ||
462 getRMode() != tother->getRMode() )
464 return false;
467 return true;
470 bool PointChunk::operator != (const StateChunk &other) const
472 return ! (*this == other);