| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osg/GLExtensions> |
|---|
| 15 | #include <osg/GL> |
|---|
| 16 | #include <osg/PointSprite> |
|---|
| 17 | #include <osg/Point> |
|---|
| 18 | #include <osg/State> |
|---|
| 19 | #include <osg/buffered_value> |
|---|
| 20 | #include <osg/Notify> |
|---|
| 21 | |
|---|
| 22 | using namespace osg; |
|---|
| 23 | |
|---|
| 24 | PointSprite::PointSprite() |
|---|
| 25 | : _coordOriginMode(UPPER_LEFT) |
|---|
| 26 | { |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | PointSprite::~PointSprite() |
|---|
| 30 | { |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | int PointSprite::compare(const StateAttribute& sa) const |
|---|
| 34 | { |
|---|
| 35 | COMPARE_StateAttribute_Types(PointSprite,sa) |
|---|
| 36 | |
|---|
| 37 | COMPARE_StateAttribute_Parameter(_coordOriginMode) |
|---|
| 38 | |
|---|
| 39 | return 0; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | bool PointSprite::checkValidityOfAssociatedModes(osg::State& state) const |
|---|
| 44 | { |
|---|
| 45 | |
|---|
| 46 | bool modeValid = isPointSpriteSupported(state.getContextID()); |
|---|
| 47 | state.setModeValidity(GL_POINT_SPRITE_ARB, modeValid); |
|---|
| 48 | |
|---|
| 49 | return modeValid; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | void PointSprite::apply(osg::State& state) const |
|---|
| 53 | { |
|---|
| 54 | #if defined( OSG_GL3_AVAILABLE ) |
|---|
| 55 | const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true); |
|---|
| 56 | extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode); |
|---|
| 57 | #elif defined( OSG_GL_FIXED_FUNCTION_AVAILABLE ) |
|---|
| 58 | if(!isPointSpriteSupported(state.getContextID())) return; |
|---|
| 59 | |
|---|
| 60 | glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, 1); |
|---|
| 61 | |
|---|
| 62 | const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true); |
|---|
| 63 | |
|---|
| 64 | if (extensions->isPointSpriteCoordOriginSupported()) |
|---|
| 65 | extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode); |
|---|
| 66 | #else |
|---|
| 67 | OSG_NOTICE<<"Warning: PointSprite::apply(State&) - not supported."<<std::endl; |
|---|
| 68 | #endif |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | struct IntializedSupportedPair |
|---|
| 72 | { |
|---|
| 73 | IntializedSupportedPair(): |
|---|
| 74 | initialized(false), |
|---|
| 75 | supported(false) {} |
|---|
| 76 | |
|---|
| 77 | bool initialized; |
|---|
| 78 | bool supported; |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | typedef osg::buffered_object< IntializedSupportedPair > BufferedExtensions; |
|---|
| 82 | static BufferedExtensions s_extensions; |
|---|
| 83 | |
|---|
| 84 | bool PointSprite::isPointSpriteSupported(unsigned int contextID) |
|---|
| 85 | { |
|---|
| 86 | if (!s_extensions[contextID].initialized) |
|---|
| 87 | { |
|---|
| 88 | s_extensions[contextID].initialized = true; |
|---|
| 89 | s_extensions[contextID].supported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID, "GL_ARB_point_sprite") || isGLExtensionSupported(contextID, "GL_NV_point_sprite"); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | return s_extensions[contextID].supported; |
|---|
| 93 | } |
|---|