2001-01-11 00:32:10 +08:00
|
|
|
// Ideas and code borrowed from GLUT pointburst demo
|
2001-09-20 05:08:56 +08:00
|
|
|
// written by Mark J. Kilgard
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/GL>
|
|
|
|
#include <osg/GLExtensions>
|
|
|
|
#include <osg/Point>
|
|
|
|
#include <osg/Notify>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// if extensions not defined by gl.h (or via glext.h) define them
|
|
|
|
// ourselves and allow the extensions to detectd at runtine using
|
|
|
|
// osg::isGLExtensionSupported().
|
2001-01-11 00:32:10 +08:00
|
|
|
#if defined(GL_SGIS_point_parameters) && !defined(GL_EXT_point_parameters)
|
|
|
|
/* Use the EXT point parameters interface for the SGIS implementation. */
|
|
|
|
# define GL_POINT_SIZE_MIN_EXT GL_POINT_SIZE_MIN_SGIS
|
|
|
|
# define GL_POINT_SIZE_MAX_EXT GL_POINT_SIZE_MAX_SGIS
|
|
|
|
# define GL_POINT_FADE_THRESHOLD_SIZE_EXT GL_POINT_FADE_THRESHOLD_SIZE_SGIS
|
|
|
|
# define GL_DISTANCE_ATTENUATION_EXT GL_DISTANCE_ATTENUATION_SGIS
|
|
|
|
# define GL_EXT_point_parameters 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(GL_EXT_point_parameters)
|
|
|
|
# define GL_POINT_SIZE_MIN_EXT 0x8126
|
|
|
|
# define GL_POINT_SIZE_MAX_EXT 0x8127
|
|
|
|
# define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128
|
|
|
|
# define GL_DISTANCE_ATTENUATION_EXT 0x8129
|
2001-09-20 05:08:56 +08:00
|
|
|
# define GL_EXT_point_parameters 1
|
2001-01-11 00:32:10 +08:00
|
|
|
#endif
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
#ifndef PFNGLPOINTPARAMETERFEXTPROC
|
|
|
|
typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param);
|
|
|
|
#endif
|
|
|
|
#ifndef PFNGLPOINTPARAMETERFVEXTPROC
|
|
|
|
typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params);
|
2001-01-11 00:32:10 +08:00
|
|
|
#endif
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
PFNGLPOINTPARAMETERFEXTPROC s_PointParameterfEXT = NULL;
|
|
|
|
PFNGLPOINTPARAMETERFVEXTPROC s_PointParameterfvEXT = NULL;
|
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
|
|
|
{
|
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
|
|
|
|
_distanceAttenuation = Vec3(0.0f, 1.0f/5.f, 0.0f);
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Point::init_GL_EXT()
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (isGLExtensionSupported("GL_EXT_point_parameters"))
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
s_PointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
|
|
|
|
getGLExtensionFuncPtr("glPointParameterfEXT");
|
|
|
|
s_PointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
|
|
|
|
getGLExtensionFuncPtr("glPointParameterfvEXT");
|
|
|
|
}
|
|
|
|
else if (isGLExtensionSupported("GL_SGIS_point_parameters"))
|
|
|
|
{
|
|
|
|
s_PointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
|
|
|
|
getGLExtensionFuncPtr("glPointParameterfSGIS");
|
|
|
|
s_PointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
|
|
|
|
getGLExtensionFuncPtr("glPointParameterfvSGIS");
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void Point::setSize( const float size )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
_size = size;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
void Point::setFadeThresholdSize(const 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;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
void Point::apply(State&) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
glPointSize(_size);
|
|
|
|
|
|
|
|
static bool s_gl_ext_init=false;
|
|
|
|
|
|
|
|
if (!s_gl_ext_init)
|
|
|
|
{
|
|
|
|
s_gl_ext_init = true;
|
|
|
|
init_GL_EXT();
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
if (s_PointParameterfvEXT) s_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, (const GLfloat*)&_distanceAttenuation);
|
|
|
|
if (s_PointParameterfEXT) s_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, _fadeThresholdSize);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|