2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/GLExtensions>
|
2002-08-25 03:39:39 +08:00
|
|
|
#include <osg/GL>
|
2005-04-20 20:32:43 +08:00
|
|
|
#include <osg/State>
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/Point>
|
|
|
|
#include <osg/Notify>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2005-04-20 20:32:43 +08:00
|
|
|
// ARB, EXT and SGIS versions use same values as OpenGL version 1.4.
|
|
|
|
#ifndef GL_VERSION_1_4
|
|
|
|
# define GL_POINT_SIZE_MIN 0x8126
|
|
|
|
# define GL_POINT_SIZE_MAX 0x8127
|
|
|
|
# define GL_POINT_FADE_THRESHOLD_SIZE 0x8128
|
|
|
|
# define GL_POINT_DISTANCE_ATTENUATION 0x8129
|
2001-01-11 00:32:10 +08:00
|
|
|
#endif
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
Point::Point()
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
_size = 1.0f; // TODO find proper default
|
|
|
|
_fadeThresholdSize = 1.0f; // TODO find proper default
|
|
|
|
// TODO find proper default
|
2003-06-24 23:40:09 +08:00
|
|
|
_distanceAttenuation = Vec3(1, 0.0, 0.0);
|
|
|
|
|
|
|
|
_minSize = 0.0;
|
|
|
|
_maxSize = 100.0;//depends on mulitsampling ... some default necessary
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
Point::~Point()
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-08 13:41:19 +08:00
|
|
|
void Point::setSize( float size )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
_size = size;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-10-08 16:39:42 +08:00
|
|
|
void Point::setFadeThresholdSize(float fadeThresholdSize)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
_fadeThresholdSize = fadeThresholdSize;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
void Point::setDistanceAttenuation(const Vec3& distanceAttenuation)
|
|
|
|
{
|
|
|
|
_distanceAttenuation = distanceAttenuation;
|
|
|
|
}
|
|
|
|
|
2003-06-24 23:40:09 +08:00
|
|
|
void Point::setMinSize(float minSize)
|
|
|
|
{
|
|
|
|
_minSize = minSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Point::setMaxSize(float maxSize)
|
|
|
|
{
|
|
|
|
_maxSize = maxSize;
|
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2005-04-20 20:32:43 +08:00
|
|
|
void Point::apply(State& state) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
glPointSize(_size);
|
|
|
|
|
2005-04-20 20:32:43 +08:00
|
|
|
const unsigned int contextID = state.getContextID();
|
|
|
|
const Extensions* extensions = getExtensions(contextID,true);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-04-20 20:32:43 +08:00
|
|
|
if (!extensions->isPointParametersSupported())
|
|
|
|
return;
|
|
|
|
|
|
|
|
extensions->glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, (const GLfloat*)&_distanceAttenuation);
|
|
|
|
extensions->glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, _fadeThresholdSize);
|
|
|
|
extensions->glPointParameterf(GL_POINT_SIZE_MIN, _minSize);
|
|
|
|
extensions->glPointParameterf(GL_POINT_SIZE_MAX, _maxSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef buffered_value< ref_ptr<Point::Extensions> > BufferedExtensions;
|
|
|
|
static BufferedExtensions s_extensions;
|
|
|
|
|
|
|
|
Point::Extensions* Point::getExtensions(unsigned int contextID,bool createIfNotInitalized)
|
|
|
|
{
|
2005-04-26 21:15:27 +08:00
|
|
|
if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);
|
2005-04-20 20:32:43 +08:00
|
|
|
return s_extensions[contextID].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Point::setExtensions(unsigned int contextID,Extensions* extensions)
|
|
|
|
{
|
|
|
|
s_extensions[contextID] = extensions;
|
|
|
|
}
|
|
|
|
|
2005-04-26 21:15:27 +08:00
|
|
|
Point::Extensions::Extensions(unsigned int contextID)
|
2005-04-20 20:32:43 +08:00
|
|
|
{
|
2007-06-28 04:36:16 +08:00
|
|
|
setupGLExtensions(contextID);
|
2005-04-20 20:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Point::Extensions::Extensions(const Extensions& rhs):
|
|
|
|
Referenced()
|
|
|
|
{
|
|
|
|
_isPointParametersSupported = rhs._isPointParametersSupported;
|
2007-06-30 01:01:37 +08:00
|
|
|
_isPointSpriteCoordOriginSupported = rhs._isPointSpriteCoordOriginSupported;
|
|
|
|
_glPointParameteri = rhs._glPointParameteri;
|
|
|
|
_glPointParameterf = rhs._glPointParameterf;
|
|
|
|
_glPointParameterfv = rhs._glPointParameterfv;
|
2005-04-20 20:32:43 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-04-20 20:32:43 +08:00
|
|
|
void Point::Extensions::lowestCommonDenominator(const Extensions& rhs)
|
|
|
|
{
|
|
|
|
if (!rhs._isPointParametersSupported) _isPointParametersSupported = false;
|
2007-06-30 01:01:37 +08:00
|
|
|
if (!rhs._isPointSpriteCoordOriginSupported) _isPointSpriteCoordOriginSupported = false;
|
2006-11-14 20:29:54 +08:00
|
|
|
if (!rhs._glPointParameteri) _glPointParameteri = 0;
|
2005-04-20 20:32:43 +08:00
|
|
|
if (!rhs._glPointParameterf) _glPointParameterf = 0;
|
|
|
|
if (!rhs._glPointParameterfv) _glPointParameterfv = 0;
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2007-06-28 04:36:16 +08:00
|
|
|
void Point::Extensions::setupGLExtensions(unsigned int contextID)
|
2005-04-20 20:32:43 +08:00
|
|
|
{
|
|
|
|
_isPointParametersSupported = strncmp((const char*)glGetString(GL_VERSION),"1.4",3)>=0 ||
|
2005-04-26 21:15:27 +08:00
|
|
|
isGLExtensionSupported(contextID,"GL_ARB_point_parameters") ||
|
|
|
|
isGLExtensionSupported(contextID,"GL_EXT_point_parameters") ||
|
|
|
|
isGLExtensionSupported(contextID,"GL_SGIS_point_parameters");
|
2006-11-14 20:29:54 +08:00
|
|
|
|
2007-06-30 01:01:37 +08:00
|
|
|
_isPointSpriteCoordOriginSupported = strncmp((const char*)glGetString(GL_VERSION),"2.0",3)>=0;
|
|
|
|
|
2007-09-10 23:19:23 +08:00
|
|
|
setGLExtensionFuncPtr(_glPointParameteri, "glPointParameteri", "glPointParameteriARB");
|
|
|
|
if (!_glPointParameteri) setGLExtensionFuncPtr(_glPointParameteri, "glPointParameteriEXT", "glPointParameteriSGIS");
|
2006-11-14 20:29:54 +08:00
|
|
|
|
2007-09-10 23:19:23 +08:00
|
|
|
setGLExtensionFuncPtr(_glPointParameterf, "glPointParameterf", "glPointParameterfARB");
|
|
|
|
if (!_glPointParameterf) setGLExtensionFuncPtr(_glPointParameterf, "glPointParameterfEXT", "glPointParameterfSGIS");
|
2005-04-20 20:32:43 +08:00
|
|
|
|
2007-09-10 23:19:23 +08:00
|
|
|
setGLExtensionFuncPtr(_glPointParameterfv, "glPointParameterfv", "glPointParameterfvARB");
|
|
|
|
if (!_glPointParameterfv) setGLExtensionFuncPtr(_glPointParameterfv, "glPointParameterfvEXT", "glPointParameterfvSGIS");
|
2005-04-20 20:32:43 +08:00
|
|
|
}
|
|
|
|
|
2006-11-14 20:29:54 +08:00
|
|
|
void Point::Extensions::glPointParameteri(GLenum pname, GLint param) const
|
|
|
|
{
|
|
|
|
if (_glPointParameteri)
|
|
|
|
{
|
2007-09-10 23:19:23 +08:00
|
|
|
_glPointParameteri(pname, param);
|
2006-11-14 20:29:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glPointParameteri not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
2005-04-20 20:32:43 +08:00
|
|
|
|
|
|
|
void Point::Extensions::glPointParameterf(GLenum pname, GLfloat param) const
|
|
|
|
{
|
|
|
|
if (_glPointParameterf)
|
2003-06-24 23:40:09 +08:00
|
|
|
{
|
2007-09-10 23:19:23 +08:00
|
|
|
_glPointParameterf(pname, param);
|
2005-04-20 20:32:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glPointParameterf not supported by OpenGL driver"<<std::endl;
|
2003-06-24 23:40:09 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2005-04-20 20:32:43 +08:00
|
|
|
void Point::Extensions::glPointParameterfv(GLenum pname, const GLfloat *params) const
|
|
|
|
{
|
|
|
|
if (_glPointParameterfv)
|
|
|
|
{
|
2007-09-10 23:19:23 +08:00
|
|
|
_glPointParameterfv(pname, params);
|
2005-04-20 20:32:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glPointParameterfv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|