| 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 | #ifndef OSG_BLENDCOLOR |
|---|
| 15 | #define OSG_BLENDCOLOR 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/GL> |
|---|
| 18 | #include <osg/StateAttribute> |
|---|
| 19 | #include <osg/ref_ptr> |
|---|
| 20 | #include <osg/Vec4> |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | namespace osg { |
|---|
| 25 | |
|---|
| 26 | /** Encapsulates OpenGL blend/transparency state. */ |
|---|
| 27 | class OSG_EXPORT BlendColor : public StateAttribute |
|---|
| 28 | { |
|---|
| 29 | public : |
|---|
| 30 | |
|---|
| 31 | BlendColor(); |
|---|
| 32 | |
|---|
| 33 | BlendColor(const osg::Vec4& constantColor); |
|---|
| 34 | |
|---|
| 35 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
|---|
| 36 | BlendColor(const BlendColor& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 37 | StateAttribute(trans,copyop), |
|---|
| 38 | _constantColor(trans._constantColor) {} |
|---|
| 39 | |
|---|
| 40 | META_StateAttribute(osg, BlendColor,BLENDCOLOR); |
|---|
| 41 | |
|---|
| 42 | /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ |
|---|
| 43 | virtual int compare(const StateAttribute& sa) const |
|---|
| 44 | { |
|---|
| 45 | // Check for equal types, then create the rhs variable |
|---|
| 46 | // used by the COMPARE_StateAttribute_Parameter macros below. |
|---|
| 47 | COMPARE_StateAttribute_Types(BlendColor,sa) |
|---|
| 48 | |
|---|
| 49 | // Compare each parameter in turn against the rhs. |
|---|
| 50 | COMPARE_StateAttribute_Parameter(_constantColor) |
|---|
| 51 | |
|---|
| 52 | return 0; // Passed all the above comparison macros, so must be equal. |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const |
|---|
| 56 | { |
|---|
| 57 | usage.usesMode(GL_BLEND); |
|---|
| 58 | return true; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | void setConstantColor(const osg::Vec4& color) { _constantColor = color; } |
|---|
| 62 | |
|---|
| 63 | inline osg::Vec4& getConstantColor() { return _constantColor; } |
|---|
| 64 | |
|---|
| 65 | inline const osg::Vec4& getConstantColor() const { return _constantColor; } |
|---|
| 66 | |
|---|
| 67 | virtual void apply(State& state) const; |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | /** Encapsulates queries of extension availability, obtains extension |
|---|
| 73 | * function pointers, and provides convenience wrappers for |
|---|
| 74 | * calling extension functions. */ |
|---|
| 75 | class OSG_EXPORT Extensions : public osg::Referenced |
|---|
| 76 | { |
|---|
| 77 | public: |
|---|
| 78 | Extensions(unsigned int contextID); |
|---|
| 79 | |
|---|
| 80 | Extensions(const Extensions& rhs); |
|---|
| 81 | |
|---|
| 82 | void lowestCommonDenominator(const Extensions& rhs); |
|---|
| 83 | |
|---|
| 84 | void setupGLExtensions(unsigned int contextID); |
|---|
| 85 | |
|---|
| 86 | void setBlendColorSupported(bool flag) { _isBlendColorSupported=flag; } |
|---|
| 87 | bool isBlendColorSupported() const { return _isBlendColorSupported; } |
|---|
| 88 | |
|---|
| 89 | void glBlendColor(GLclampf red , GLclampf green , GLclampf blue , GLclampf alpha) const; |
|---|
| 90 | |
|---|
| 91 | protected: |
|---|
| 92 | |
|---|
| 93 | ~Extensions() {} |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | typedef void (GL_APIENTRY * GLBlendColorProc) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); |
|---|
| 97 | bool _isBlendColorSupported; |
|---|
| 98 | GLBlendColorProc _glBlendColor; |
|---|
| 99 | |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | /** Returns the Extensions object for the given context. |
|---|
| 103 | * If createIfNotInitalized is true and the Extensions object doesn't |
|---|
| 104 | * exist, getExtensions() creates it on the given context. |
|---|
| 105 | * Returns NULL if createIfNotInitalized is false and the Extensions |
|---|
| 106 | * object doesn't exist. */ |
|---|
| 107 | static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized); |
|---|
| 108 | |
|---|
| 109 | /** setExtensions() allows users to override the extensions across graphics contexts. |
|---|
| 110 | * Typically used when you have different extensions supported across graphics pipes, |
|---|
| 111 | * but need to ensure that they all use the same low common denominator extensions. */ |
|---|
| 112 | static void setExtensions(unsigned int contextID,Extensions* extensions); |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | protected : |
|---|
| 117 | |
|---|
| 118 | virtual ~BlendColor(); |
|---|
| 119 | |
|---|
| 120 | osg::Vec4 _constantColor; |
|---|
| 121 | }; |
|---|
| 122 | |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | #endif |
|---|