1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 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 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
49 #include "OSGGLFuncProtos.h"
51 #include "OSGWindow.h"
52 #include "OSGDrawEnv.h"
54 #include "OSGPointChunk.h"
55 #include "OSGConceptPropertyChecks.h"
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 /***************************************************************************\
66 \***************************************************************************/
69 StateChunkClass
PointChunk::_class("Point", 1, 50);
71 StateChunkClass
PointChunk::_class("Point", 1, 110);
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 /***************************************************************************\
82 \***************************************************************************/
84 void PointChunk::initMethod(InitPhase ePhase
)
86 Inherited::initMethod(ePhase
);
88 if(ePhase
== TypeObject::SystemPost
)
91 Window::registerExtension("GL_ARB_point_parameters");
93 Window::registerExtension("GL_ARB_point_sprite");
95 Window::registerExtension("GL_NV_point_sprite");
96 _funcIdPointParameterf
=
97 Window::registerFunction (
98 OSG_DLSYM_UNDERSCORE
"glPointParameterfARB",
100 _funcIdPointParameterfv
=
101 Window::registerFunction (
102 OSG_DLSYM_UNDERSCORE
"glPointParameterfvARB",
103 _extPointParameters
);
107 /***************************************************************************\
109 \***************************************************************************/
111 /*-------------------------------------------------------------------------*\
113 \*-------------------------------------------------------------------------*/
115 /*----------------------- constructors & destructors ----------------------*/
117 PointChunk::PointChunk(void) :
122 PointChunk::PointChunk(const PointChunk
&source
) :
127 PointChunk::~PointChunk(void)
131 /*------------------------- Chunk Class Access ---------------------------*/
133 const StateChunkClass
*PointChunk::getClass(void) const
138 /*----------------------------- class specific ----------------------------*/
140 void PointChunk::changed(ConstFieldMaskArg whichField
,
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
)
159 glPointSize(getSize());
162 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
164 glEnable(GL_POINT_SMOOTH
);
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
,
182 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
183 OSGGETGLFUNCBYID_GL3( glPointParameterfv
,
184 osgGlPointParameterfv
,
185 _funcIdPointParameterfv
,
188 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB
, getMinSize());
189 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB
, getMaxSize());
191 osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB
,
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
);
206 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
207 #if GL_ARB_point_sprite
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
,
220 osgGlPointParameterf(GL_POINT_SPRITE_R_MODE_NV
,
225 glEnable(GL_POINT_SPRITE_ARB
);
231 #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
236 void PointChunk::changeFrom(DrawEnv
*pEnv
,
237 StateChunk
*old_chunk
,
240 PointChunk
*old
= dynamic_cast<PointChunk
*>(old_chunk
);
243 if(getSize() != old
->getSize())
244 glPointSize(getSize());
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
);
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
,
273 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
274 OSGGETGLFUNCBYID_GL3( glPointParameterfv
,
275 osgGlPointParameterfv
,
276 _funcIdPointParameterfv
,
279 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB
, getMinSize());
280 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB
, getMaxSize());
282 osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB
,
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
);
295 else if(old
->getMinSize() >= 0.f
)
297 if(pEnv
->getWindow()->hasExtOrVersion(_extPointParameters
, 0x0104))
299 OSGGETGLFUNCBYID_GL3( glPointParameterf
,
300 osgGlPointParameterf
,
301 _funcIdPointParameterf
,
303 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
304 OSGGETGLFUNCBYID_GL3( glPointParameterfv
,
305 osgGlPointParameterfv
,
306 _funcIdPointParameterfv
,
309 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB
, 0);
310 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB
, 1e10
);
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
);
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
,
337 osgGlPointParameterf(GL_POINT_SPRITE_R_MODE_NV
,
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
);
357 #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
362 void PointChunk::deactivate(DrawEnv
*pEnv
, UInt32
)
369 Window
*pWin
= pEnv
->getWindow();
371 osgSinkUnusedWarning(pWin
);
373 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
375 glDisable(GL_POINT_SMOOTH
);
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
,
387 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
388 OSGGETGLFUNCBYID_GL3( glPointParameterfv
,
389 osgGlPointParameterfv
,
390 _funcIdPointParameterfv
,
393 osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB
, 0);
394 osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB
, 1e10
);
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
);
408 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
409 #if GL_ARB_point_sprite
412 if(pEnv
->getWindow()->hasExtOrVersion(_extPointSpriteARB
, 0x0200))
414 glDisable(GL_POINT_SPRITE_ARB
);
421 #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
426 /*-------------------------- Comparison -----------------------------------*/
428 bool PointChunk::isTransparent(void) const
430 return getMinSize() >= 0.f
;
433 Real32
PointChunk::switchCost(StateChunk
*)
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
);
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() )
470 bool PointChunk::operator != (const StateChunk
&other
) const
472 return ! (*this == other
);