From 7cb1bcbd7d070033d9d820e41bd387caf42d0d28 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 14 Nov 2006 12:29:54 +0000 Subject: [PATCH] From Farshid Lashkari, "This patch adds a CoordOriginMode to the osg::PointSprite attribute. The mode needs to be changed to LOWER_LEFT when rendering point sprites to pbuffers or FBOs, otherwise the points will be transformed on the CPU." --- include/osg/Point | 2 ++ include/osg/PointSprite | 22 ++++++++++++++++++---- src/osg/Point.cpp | 18 +++++++++++++++++- src/osg/PointSprite.cpp | 23 ++++++++++++++++++----- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/include/osg/Point b/include/osg/Point index e3b2f6966..a0b8a21af 100644 --- a/include/osg/Point +++ b/include/osg/Point @@ -94,6 +94,7 @@ class OSG_EXPORT Point : public StateAttribute void setPointParametersSupported(bool flag) { _isPointParametersSupported=flag; } bool isPointParametersSupported() const { return _isPointParametersSupported; } + void glPointParameteri(GLenum pname, GLint param) const; void glPointParameterf(GLenum pname, GLfloat param) const; void glPointParameterfv(GLenum pname, const GLfloat *params) const; @@ -103,6 +104,7 @@ class OSG_EXPORT Point : public StateAttribute bool _isPointParametersSupported; + void* _glPointParameteri; void* _glPointParameterf; void* _glPointParameterfv; diff --git a/include/osg/PointSprite b/include/osg/PointSprite index 09054e384..e99977f12 100644 --- a/include/osg/PointSprite +++ b/include/osg/PointSprite @@ -20,6 +20,9 @@ #ifndef GL_ARB_point_sprite #define GL_POINT_SPRITE_ARB 0x8861 #define GL_COORD_REPLACE_ARB 0x8862 +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 #endif namespace osg { @@ -28,11 +31,12 @@ namespace osg { class OSG_EXPORT PointSprite : public osg::StateAttribute { public: - PointSprite() {} + PointSprite(); /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ - PointSprite(const PointSprite& texenv,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - StateAttribute(texenv,copyop) {} + PointSprite(const PointSprite& ps,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + StateAttribute(ps,copyop), + _coordOriginMode(ps._coordOriginMode) {} META_StateAttribute(osg, PointSprite, POINTSPRITE); @@ -53,9 +57,19 @@ public: virtual void apply(osg::State& state) const; static bool isPointSpriteSupported(unsigned int context); + + enum CoordOriginMode { + UPPER_LEFT = GL_UPPER_LEFT, + LOWER_LEFT = GL_LOWER_LEFT + }; + + inline void setCoordOriginMode(CoordOriginMode mode) { _coordOriginMode = mode; } + inline CoordOriginMode getCoordOriginMode() const { return _coordOriginMode; } protected: - virtual ~PointSprite( void ) {} + virtual ~PointSprite(); + + CoordOriginMode _coordOriginMode; }; } diff --git a/src/osg/Point.cpp b/src/osg/Point.cpp index 2b87a2edd..181f1c7cb 100644 --- a/src/osg/Point.cpp +++ b/src/osg/Point.cpp @@ -116,6 +116,7 @@ Point::Extensions::Extensions(const Extensions& rhs): void Point::Extensions::lowestCommonDenominator(const Extensions& rhs) { if (!rhs._isPointParametersSupported) _isPointParametersSupported = false; + if (!rhs._glPointParameteri) _glPointParameteri = 0; if (!rhs._glPointParameterf) _glPointParameterf = 0; if (!rhs._glPointParameterfv) _glPointParameterfv = 0; } @@ -126,7 +127,10 @@ void Point::Extensions::setupGLExtenions(unsigned int contextID) isGLExtensionSupported(contextID,"GL_ARB_point_parameters") || isGLExtensionSupported(contextID,"GL_EXT_point_parameters") || isGLExtensionSupported(contextID,"GL_SGIS_point_parameters"); - + + _glPointParameteri = getGLExtensionFuncPtr("glPointParameteri", "glPointParameteriARB"); + if (!_glPointParameteri) _glPointParameteri = getGLExtensionFuncPtr("glPointParameteriEXT", "glPointParameteriSGIS"); + _glPointParameterf = getGLExtensionFuncPtr("glPointParameterf", "glPointParameterfARB"); if (!_glPointParameterf) _glPointParameterf = getGLExtensionFuncPtr("glPointParameterfEXT", "glPointParameterfSGIS"); @@ -134,6 +138,18 @@ void Point::Extensions::setupGLExtenions(unsigned int contextID) if (!_glPointParameterfv) _glPointParameterfv = getGLExtensionFuncPtr("glPointParameterfvEXT", "glPointParameterfvSGIS"); } +void Point::Extensions::glPointParameteri(GLenum pname, GLint param) const +{ + if (_glPointParameteri) + { + typedef void (APIENTRY * GLPointParameteriProc) (GLenum pname, GLint param); + ((GLPointParameteriProc)_glPointParameteri)(pname, param); + } + else + { + notify(WARN)<<"Error: glPointParameteri not supported by OpenGL driver"< #include #include +#include #include #include #include using namespace osg; +PointSprite::PointSprite() + : _coordOriginMode(UPPER_LEFT) +{ +} + +PointSprite::~PointSprite() +{ +} + int PointSprite::compare(const StateAttribute& sa) const { - if (this==&sa) return 0;\ - const std::type_info* type_lhs = &typeid(*this);\ - const std::type_info* type_rhs = &typeid(sa);\ - if (type_lhs->before(*type_rhs)) return -1;\ - if (*type_lhs != *type_rhs) return 1;\ + COMPARE_StateAttribute_Types(PointSprite,sa) + + COMPARE_StateAttribute_Parameter(_coordOriginMode) return 0; // passed all the above comparison macro's, must be equal. } @@ -46,6 +54,11 @@ void PointSprite::apply(osg::State& state) const if(!isPointSpriteSupported(state.getContextID())) return; glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, 1); + + const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true); + + if (extensions->isPointParametersSupported()) + extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode); } struct IntializedSupportedPair