| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/GLExtensions> |
|---|
| 14 | #include <osg/Multisample> |
|---|
| 15 | #include <osg/State> |
|---|
| 16 | #include <osg/Notify> |
|---|
| 17 | #include <osg/buffered_value> |
|---|
| 18 | |
|---|
| 19 | using namespace osg; |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | Multisample::Multisample() : _mode(DONT_CARE) |
|---|
| 23 | { |
|---|
| 24 | _coverage = 1; |
|---|
| 25 | _invert = false; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | Multisample::~Multisample() |
|---|
| 29 | { |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | void Multisample::apply(State& state) const |
|---|
| 33 | { |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | const unsigned int contextID = state.getContextID(); |
|---|
| 37 | |
|---|
| 38 | const Extensions* extensions = getExtensions(contextID,true); |
|---|
| 39 | |
|---|
| 40 | if (!extensions->isMultisampleSupported()) |
|---|
| 41 | { |
|---|
| 42 | OSG_WARN<<"Warning: Multisample::apply(..) failed, Multisample is not support by OpenGL driver."<<std::endl; |
|---|
| 43 | return; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | if(extensions->isMultisampleFilterHintSupported()) |
|---|
| 47 | glHint(GL_MULTISAMPLE_FILTER_HINT_NV, _mode); |
|---|
| 48 | extensions->glSampleCoverage(_coverage, _invert); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | typedef buffered_value< ref_ptr<Multisample::Extensions> > BufferedExtensions; |
|---|
| 56 | static BufferedExtensions s_extensions; |
|---|
| 57 | |
|---|
| 58 | Multisample::Extensions* Multisample::getExtensions(unsigned int contextID,bool createIfNotInitalized) |
|---|
| 59 | { |
|---|
| 60 | if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); |
|---|
| 61 | return s_extensions[contextID].get(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void Multisample::setExtensions(unsigned int contextID,Extensions* extensions) |
|---|
| 65 | { |
|---|
| 66 | s_extensions[contextID] = extensions; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | Multisample::Extensions::Extensions(unsigned int contextID) |
|---|
| 71 | { |
|---|
| 72 | setupGLExtensions(contextID); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | Multisample::Extensions::Extensions(const Extensions& rhs): |
|---|
| 76 | Referenced() |
|---|
| 77 | { |
|---|
| 78 | _isMultisampleSupported = rhs._isMultisampleSupported; |
|---|
| 79 | _isMultisampleFilterHintSupported = rhs._isMultisampleFilterHintSupported; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void Multisample::Extensions::lowestCommonDenominator(const Extensions& rhs) |
|---|
| 83 | { |
|---|
| 84 | if (!rhs._isMultisampleSupported) _isMultisampleSupported = false; |
|---|
| 85 | if (!rhs._isMultisampleFilterHintSupported) _isMultisampleFilterHintSupported = false; |
|---|
| 86 | if (!rhs._glSampleCoverage) _glSampleCoverage = 0; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | void Multisample::Extensions::setupGLExtensions(unsigned int contextID) |
|---|
| 90 | { |
|---|
| 91 | _isMultisampleSupported = OSG_GLES2_FEATURES || OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_ARB_multisample"); |
|---|
| 92 | _isMultisampleFilterHintSupported = isGLExtensionSupported(contextID,"GL_NV_multisample_filter_hint"); |
|---|
| 93 | |
|---|
| 94 | setGLExtensionFuncPtr(_glSampleCoverage, "glSampleCoverageARB"); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | void Multisample::Extensions::glSampleCoverage(GLclampf value, GLboolean invert) const |
|---|
| 98 | { |
|---|
| 99 | if (_glSampleCoverage) |
|---|
| 100 | { |
|---|
| 101 | _glSampleCoverage(value, invert); |
|---|
| 102 | } |
|---|
| 103 | else |
|---|
| 104 | { |
|---|
| 105 | OSG_WARN<<"Error: glSampleCoverage not supported by OpenGL driver"<<std::endl; |
|---|
| 106 | } |
|---|
| 107 | } |
|---|