| 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_MULTISAMPLE |
|---|
| 15 | #define OSG_MULTISAMPLE 1 |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #include <osg/GL> |
|---|
| 19 | #include <osg/StateAttribute> |
|---|
| 20 | #include <osg/ref_ptr> |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #ifndef GL_ARB_multisample |
|---|
| 24 | #define GL_MULTISAMPLE_ARB 0x809D |
|---|
| 25 | #define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E |
|---|
| 26 | #define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F |
|---|
| 27 | #define GL_SAMPLE_COVERAGE_ARB 0x80A0 |
|---|
| 28 | #define GL_SAMPLE_BUFFERS_ARB 0x80A8 |
|---|
| 29 | #define GL_SAMPLES_ARB 0x80A9 |
|---|
| 30 | #define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA |
|---|
| 31 | #define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB |
|---|
| 32 | #define GL_MULTISAMPLE_BIT_ARB 0x20000000 |
|---|
| 33 | #endif |
|---|
| 34 | #ifndef GL_NV_multisample_filter_hint |
|---|
| 35 | #define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 |
|---|
| 36 | #endif |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | namespace osg { |
|---|
| 40 | |
|---|
| 41 | /** Multisample - encapsulates the OpenGL Multisample state.*/ |
|---|
| 42 | class OSG_EXPORT Multisample : public StateAttribute |
|---|
| 43 | { |
|---|
| 44 | public : |
|---|
| 45 | |
|---|
| 46 | enum Mode |
|---|
| 47 | { |
|---|
| 48 | FASTEST = GL_FASTEST, |
|---|
| 49 | NICEST = GL_NICEST, |
|---|
| 50 | DONT_CARE = GL_DONT_CARE |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | Multisample(); |
|---|
| 54 | |
|---|
| 55 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
|---|
| 56 | Multisample(const Multisample& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 57 | StateAttribute(trans,copyop), |
|---|
| 58 | _coverage(trans._coverage), |
|---|
| 59 | _invert(trans._invert), |
|---|
| 60 | _mode(trans._mode) {} |
|---|
| 61 | |
|---|
| 62 | META_StateAttribute(osg, Multisample,MULTISAMPLE); |
|---|
| 63 | |
|---|
| 64 | /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ |
|---|
| 65 | virtual int compare(const StateAttribute& sa) const |
|---|
| 66 | { |
|---|
| 67 | // check the types are equal and then create the rhs variable |
|---|
| 68 | // used by the COMPARE_StateAttribute_Parameter macros below. |
|---|
| 69 | COMPARE_StateAttribute_Types(Multisample,sa) |
|---|
| 70 | |
|---|
| 71 | // compare each parameter in turn against the rhs. |
|---|
| 72 | COMPARE_StateAttribute_Parameter(_coverage) |
|---|
| 73 | COMPARE_StateAttribute_Parameter(_invert) |
|---|
| 74 | COMPARE_StateAttribute_Parameter(_mode) |
|---|
| 75 | |
|---|
| 76 | return 0; // passed all the above comparison macros, must be equal. |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | void setSampleCoverage(float coverage, bool invert) |
|---|
| 80 | { |
|---|
| 81 | _coverage = coverage; |
|---|
| 82 | _invert = invert; |
|---|
| 83 | } |
|---|
| 84 | inline void setCoverage(float coverage) { _coverage=coverage; } |
|---|
| 85 | inline float getCoverage() const { return _coverage; } |
|---|
| 86 | |
|---|
| 87 | inline void setInvert(bool invert) { _invert=invert; } |
|---|
| 88 | inline bool getInvert() const { return _invert; } |
|---|
| 89 | |
|---|
| 90 | inline void setHint(Mode mode) { _mode = mode; } |
|---|
| 91 | inline Mode getHint() const { return _mode; } |
|---|
| 92 | |
|---|
| 93 | virtual void apply(State& state) const; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | /** Extensions class which encapsulates the querying of extensions and |
|---|
| 97 | * associated function pointers, and provide convenience wrappers to |
|---|
| 98 | * check for the extensions or use the associated functions.*/ |
|---|
| 99 | class OSG_EXPORT Extensions : public osg::Referenced |
|---|
| 100 | { |
|---|
| 101 | public: |
|---|
| 102 | Extensions(unsigned int contextID); |
|---|
| 103 | |
|---|
| 104 | Extensions(const Extensions& rhs); |
|---|
| 105 | |
|---|
| 106 | void lowestCommonDenominator(const Extensions& rhs); |
|---|
| 107 | |
|---|
| 108 | void setupGLExtensions(unsigned int contextID); |
|---|
| 109 | |
|---|
| 110 | void setMultisampleSupported(bool flag) { _isMultisampleSupported=flag; } |
|---|
| 111 | void setMultisampleFilterHintSupported(bool flag) { _isMultisampleFilterHintSupported=flag; } |
|---|
| 112 | bool isMultisampleSupported() const { return _isMultisampleSupported; } |
|---|
| 113 | bool isMultisampleFilterHintSupported() const { return _isMultisampleFilterHintSupported; } |
|---|
| 114 | |
|---|
| 115 | void glSampleCoverage(GLclampf value, GLboolean invert) const; |
|---|
| 116 | |
|---|
| 117 | protected: |
|---|
| 118 | |
|---|
| 119 | ~Extensions() {} |
|---|
| 120 | |
|---|
| 121 | bool _isMultisampleSupported; |
|---|
| 122 | bool _isMultisampleFilterHintSupported; |
|---|
| 123 | |
|---|
| 124 | typedef void (GL_APIENTRY * GLSampleCoverageProc) (GLclampf value, GLboolean invert); |
|---|
| 125 | GLSampleCoverageProc _glSampleCoverage; |
|---|
| 126 | |
|---|
| 127 | }; |
|---|
| 128 | |
|---|
| 129 | /** Function to call to get the extension of a specified context. |
|---|
| 130 | * If the Extension object for that context has not yet been created |
|---|
| 131 | * and the 'createIfNotInitalized' flag been set to false then returns NULL. |
|---|
| 132 | * If 'createIfNotInitalized' is true then the Extensions object is |
|---|
| 133 | * automatically created. However, in this case the extension object will |
|---|
| 134 | * only be created with the graphics context associated with ContextID..*/ |
|---|
| 135 | static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized); |
|---|
| 136 | |
|---|
| 137 | /** setExtensions allows users to override the extensions across graphics contexts. |
|---|
| 138 | * Typically used when you have different extensions supported across graphics pipes |
|---|
| 139 | * but need to ensure that they all use the same low common denominator extensions.*/ |
|---|
| 140 | static void setExtensions(unsigned int contextID,Extensions* extensions); |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | protected : |
|---|
| 145 | |
|---|
| 146 | virtual ~Multisample(); |
|---|
| 147 | |
|---|
| 148 | float _coverage; |
|---|
| 149 | bool _invert; |
|---|
| 150 | Mode _mode; |
|---|
| 151 | }; |
|---|
| 152 | |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | #endif |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|