root/OpenSceneGraph/trunk/src/osg/PointSprite.cpp @ 13041

Revision 13041, 2.8 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
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
22using namespace osg;
23
24PointSprite::PointSprite()
25    : _coordOriginMode(UPPER_LEFT)
26{
27}
28
29PointSprite::~PointSprite()
30{
31}
32
33int PointSprite::compare(const StateAttribute& sa) const
34{
35    COMPARE_StateAttribute_Types(PointSprite,sa)
36
37    COMPARE_StateAttribute_Parameter(_coordOriginMode)
38
39    return 0; // passed all the above comparison macros, must be equal.
40}
41
42
43bool 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
52void 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
71struct IntializedSupportedPair
72{
73    IntializedSupportedPair():
74        initialized(false),
75        supported(false) {}
76
77    bool initialized;
78    bool supported;
79};
80
81typedef osg::buffered_object< IntializedSupportedPair > BufferedExtensions;
82static BufferedExtensions s_extensions;
83
84bool 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}
Note: See TracBrowser for help on using the browser.