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