root/OpenSceneGraph/trunk/src/osg/Point.cpp @ 13041

Revision 13041, 6.2 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osg/GLExtensions>
15#include <osg/GL>
16#include <osg/State>
17#include <osg/Point>
18#include <osg/Notify>
19
20using namespace osg;
21
22// ARB, EXT and SGIS versions use same values as OpenGL version 1.4.
23#ifndef GL_VERSION_1_4
24define GL_POINT_SIZE_MIN                   0x8126
25define GL_POINT_SIZE_MAX                   0x8127
26define GL_POINT_FADE_THRESHOLD_SIZE        0x8128
27define GL_POINT_DISTANCE_ATTENUATION       0x8129
28#endif
29
30Point::Point()
31{
32    _size = 1.0f;                               // TODO find proper default
33    _fadeThresholdSize = 1.0f;                  // TODO find proper default
34    _distanceAttenuation = Vec3(1, 0.0, 0.0);   // TODO find proper default
35
36    _minSize = 0.0;
37    _maxSize = 100.0;//depends on mulitsampling ... some default necessary
38}
39
40Point::Point(float size)
41{
42    _size = size;
43    _fadeThresholdSize = 1.0f;                  // TODO find proper default
44    _distanceAttenuation = Vec3(1, 0.0, 0.0);   // TODO find proper default
45
46    _minSize = 0.0;
47    _maxSize = 100.0;//depends on mulitsampling ... some default necessary
48}
49
50Point::~Point()
51{
52}
53
54
55void Point::setSize( float size )
56{
57    _size = size;
58}
59
60
61void Point::setFadeThresholdSize(float fadeThresholdSize)
62{
63    _fadeThresholdSize = fadeThresholdSize;
64}
65
66
67void Point::setDistanceAttenuation(const Vec3& distanceAttenuation)
68{
69    _distanceAttenuation = distanceAttenuation;
70}
71
72void Point::setMinSize(float minSize)
73{
74    _minSize = minSize;
75}
76
77void Point::setMaxSize(float maxSize)
78{
79    _maxSize = maxSize;
80}
81
82void Point::apply(State& state) const
83{
84#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
85    glPointSize(_size);
86
87    const unsigned int contextID = state.getContextID();
88    const Extensions* extensions = getExtensions(contextID,true);
89
90    if (!extensions->isPointParametersSupported())
91        return;
92
93    extensions->glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, (const GLfloat*)&_distanceAttenuation);
94    extensions->glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, _fadeThresholdSize);
95    extensions->glPointParameterf(GL_POINT_SIZE_MIN, _minSize);
96    extensions->glPointParameterf(GL_POINT_SIZE_MAX, _maxSize);
97#else
98    OSG_NOTICE<<"Warning: Point::apply(State&) - not supported."<<std::endl;
99#endif
100}
101
102
103typedef buffered_value< ref_ptr<Point::Extensions> > BufferedExtensions;
104static BufferedExtensions s_extensions;
105
106Point::Extensions* Point::getExtensions(unsigned int contextID,bool createIfNotInitalized)
107{
108    if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);
109    return s_extensions[contextID].get();
110}
111
112void Point::setExtensions(unsigned int contextID,Extensions* extensions)
113{
114    s_extensions[contextID] = extensions;
115}
116
117Point::Extensions::Extensions(unsigned int contextID)
118{
119    setupGLExtensions(contextID);
120}
121
122Point::Extensions::Extensions(const Extensions& rhs):
123    Referenced()
124{
125    _isPointParametersSupported = rhs._isPointParametersSupported;
126    _isPointSpriteCoordOriginSupported = rhs._isPointSpriteCoordOriginSupported;
127    _glPointParameteri = rhs._glPointParameteri;
128    _glPointParameterf = rhs._glPointParameterf;
129    _glPointParameterfv = rhs._glPointParameterfv;
130}
131
132void Point::Extensions::lowestCommonDenominator(const Extensions& rhs)
133{
134    if (!rhs._isPointParametersSupported)  _isPointParametersSupported = false;
135    if (!rhs._isPointSpriteCoordOriginSupported)  _isPointSpriteCoordOriginSupported = false;
136    if (!rhs._glPointParameteri)           _glPointParameteri = 0;
137    if (!rhs._glPointParameterf)           _glPointParameterf = 0;
138    if (!rhs._glPointParameterfv)          _glPointParameterfv = 0;
139}
140
141void Point::Extensions::setupGLExtensions(unsigned int contextID)
142{
143    _isPointParametersSupported = OSG_GL3_FEATURES ||
144                                  strncmp((const char*)glGetString(GL_VERSION),"1.4",3)>=0 ||
145                                  isGLExtensionSupported(contextID,"GL_ARB_point_parameters") ||
146                                  isGLExtensionSupported(contextID,"GL_EXT_point_parameters") ||
147                                  isGLExtensionSupported(contextID,"GL_SGIS_point_parameters");
148
149    _isPointSpriteCoordOriginSupported = OSG_GL3_FEATURES || strncmp((const char*)glGetString(GL_VERSION),"2.0",3)>=0;
150
151    setGLExtensionFuncPtr(_glPointParameteri, "glPointParameteri", "glPointParameteriARB");
152    if (!_glPointParameteri) setGLExtensionFuncPtr(_glPointParameteri, "glPointParameteriEXT", "glPointParameteriSGIS");
153
154    setGLExtensionFuncPtr(_glPointParameterf, "glPointParameterf", "glPointParameterfARB");
155    if (!_glPointParameterf) setGLExtensionFuncPtr(_glPointParameterf, "glPointParameterfEXT", "glPointParameterfSGIS");
156
157    setGLExtensionFuncPtr(_glPointParameterfv, "glPointParameterfv", "glPointParameterfvARB");
158    if (!_glPointParameterfv) setGLExtensionFuncPtr(_glPointParameterfv, "glPointParameterfvEXT", "glPointParameterfvSGIS");
159}
160
161void Point::Extensions::glPointParameteri(GLenum pname, GLint param) const
162{
163    if (_glPointParameteri)
164    {
165        _glPointParameteri(pname, param);
166    }
167    else
168    {
169        OSG_WARN<<"Error: glPointParameteri not supported by OpenGL driver"<<std::endl;
170    }
171}
172
173void Point::Extensions::glPointParameterf(GLenum pname, GLfloat param) const
174{
175    if (_glPointParameterf)
176    {
177        _glPointParameterf(pname, param);
178    }
179    else
180    {
181        OSG_WARN<<"Error: glPointParameterf not supported by OpenGL driver"<<std::endl;
182    }
183}
184
185void Point::Extensions::glPointParameterfv(GLenum pname, const GLfloat *params) const
186{
187    if (_glPointParameterfv)
188    {
189        _glPointParameterfv(pname, params);
190    }
191    else
192    {
193        OSG_WARN<<"Error: glPointParameterfv not supported by OpenGL driver"<<std::endl;
194    }
195}
Note: See TracBrowser for help on using the browser.