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."
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Point::Extensions::glPointParameterf(GLenum pname, GLfloat param) const
|
||||
{
|
||||
|
||||
@@ -14,19 +14,27 @@
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/GL>
|
||||
#include <osg/PointSprite>
|
||||
#include <osg/Point>
|
||||
#include <osg/State>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/Notify>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user