OpenSceneGraph/src/osg/Point.cpp

108 lines
3.1 KiB
C++
Raw Normal View History

2001-01-11 00:32:10 +08:00
// Ideas and code borrowed from GLUT pointburst demo
// written by Mark J. Kilgard
2001-01-11 00:32:10 +08:00
#include <osg/GLExtensions>
#include <osg/GL>
#include <osg/Point>
#include <osg/Notify>
2001-01-11 00:32:10 +08:00
using namespace osg;
// 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
# define GL_EXT_point_parameters 1
2001-01-11 00:32:10 +08:00
#endif
#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
PFNGLPOINTPARAMETERFEXTPROC s_PointParameterfEXT = NULL;
PFNGLPOINTPARAMETERFVEXTPROC s_PointParameterfvEXT = NULL;
2001-01-11 00:32:10 +08:00
Point::Point()
2001-01-11 00:32:10 +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
}
Point::~Point()
2001-01-11 00:32:10 +08:00
{
}
void Point::init_GL_EXT()
{
if (isGLExtensionSupported("GL_EXT_point_parameters"))
2001-01-11 00:32:10 +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
}
}
void Point::setSize( float size )
2001-01-11 00:32:10 +08:00
{
_size = size;
}
void Point::setFadeThresholdSize(float fadeThresholdSize)
2001-01-11 00:32:10 +08:00
{
_fadeThresholdSize = fadeThresholdSize;
}
2001-01-11 00:32:10 +08:00
void Point::setDistanceAttenuation(const Vec3& distanceAttenuation)
{
_distanceAttenuation = distanceAttenuation;
}
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();
}
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
}