| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #include <osg/GLExtensions> |
|---|
| 18 | #include <osg/Texture2DMultisample> |
|---|
| 19 | #include <osg/State> |
|---|
| 20 | #include <osg/Notify> |
|---|
| 21 | |
|---|
| 22 | using namespace osg; |
|---|
| 23 | |
|---|
| 24 | Texture2DMultisample::Texture2DMultisample(): |
|---|
| 25 | _textureWidth(0), |
|---|
| 26 | _textureHeight(0), |
|---|
| 27 | _numSamples(1), |
|---|
| 28 | _fixedsamplelocations(GL_FALSE) |
|---|
| 29 | { |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | Texture2DMultisample::Texture2DMultisample(GLsizei numSamples, GLboolean fixedsamplelocations): |
|---|
| 33 | _textureWidth(0), |
|---|
| 34 | _textureHeight(0), |
|---|
| 35 | _numSamples(numSamples), |
|---|
| 36 | _fixedsamplelocations(fixedsamplelocations) |
|---|
| 37 | { |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | Texture2DMultisample::Texture2DMultisample(const Texture2DMultisample& text,const CopyOp& copyop): |
|---|
| 41 | Texture(text,copyop), |
|---|
| 42 | _textureWidth(text._textureWidth), |
|---|
| 43 | _textureHeight(text._textureHeight), |
|---|
| 44 | _numSamples(text._numSamples), |
|---|
| 45 | _fixedsamplelocations(text._fixedsamplelocations) |
|---|
| 46 | { |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | Texture2DMultisample::~Texture2DMultisample() |
|---|
| 50 | { |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | int Texture2DMultisample::compare(const StateAttribute& sa) const |
|---|
| 54 | { |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | COMPARE_StateAttribute_Types(Texture2DMultisample,sa) |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | int result = compareTexture(rhs); |
|---|
| 61 | if (result!=0) return result; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | if (_textureWidth != 0 && rhs._textureWidth != 0) |
|---|
| 65 | { |
|---|
| 66 | COMPARE_StateAttribute_Parameter(_textureWidth) |
|---|
| 67 | } |
|---|
| 68 | if (_textureHeight != 0 && rhs._textureHeight != 0) |
|---|
| 69 | { |
|---|
| 70 | COMPARE_StateAttribute_Parameter(_textureHeight) |
|---|
| 71 | } |
|---|
| 72 | if (_numSamples != 0 && rhs._numSamples != 0) |
|---|
| 73 | { |
|---|
| 74 | COMPARE_StateAttribute_Parameter(_numSamples) |
|---|
| 75 | } |
|---|
| 76 | if (_fixedsamplelocations != 0 && rhs._fixedsamplelocations != 0) |
|---|
| 77 | { |
|---|
| 78 | COMPARE_StateAttribute_Parameter(_fixedsamplelocations) |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | return 0; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | void Texture2DMultisample::apply(State& state) const |
|---|
| 86 | { |
|---|
| 87 | |
|---|
| 88 | const unsigned int contextID = state.getContextID(); |
|---|
| 89 | const Extensions* extensions = getExtensions(contextID,true); |
|---|
| 90 | if (!extensions->isTextureMultisampledSupported()) |
|---|
| 91 | { |
|---|
| 92 | OSG_INFO<<"Texture2DMultisample not supoorted."<<std::endl; |
|---|
| 93 | return; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID).get(); |
|---|
| 97 | ElapsedTime elapsedTime(&(tom->getApplyTime())); |
|---|
| 98 | tom->getNumberApplied()++; |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | TextureObject* textureObject = getTextureObject(contextID); |
|---|
| 102 | |
|---|
| 103 | if (textureObject) |
|---|
| 104 | { |
|---|
| 105 | textureObject->bind(); |
|---|
| 106 | } |
|---|
| 107 | else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_numSamples!=0) ) |
|---|
| 108 | { |
|---|
| 109 | _textureObjectBuffer[contextID] = textureObject = |
|---|
| 110 | generateTextureObject( this, |
|---|
| 111 | contextID, |
|---|
| 112 | getTextureTarget(), |
|---|
| 113 | 1, |
|---|
| 114 | _internalFormat, |
|---|
| 115 | _textureWidth, |
|---|
| 116 | _textureHeight, |
|---|
| 117 | 1, |
|---|
| 118 | _borderWidth); |
|---|
| 119 | |
|---|
| 120 | textureObject->bind(); |
|---|
| 121 | |
|---|
| 122 | extensions->glTexImage2DMultisample( getTextureTarget(), |
|---|
| 123 | _numSamples, |
|---|
| 124 | _internalFormat, |
|---|
| 125 | _textureWidth, |
|---|
| 126 | _textureHeight, |
|---|
| 127 | _fixedsamplelocations ); |
|---|
| 128 | |
|---|
| 129 | } |
|---|
| 130 | else |
|---|
| 131 | { |
|---|
| 132 | glBindTexture( getTextureTarget(), 0 ); |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | void Texture2DMultisample::computeInternalFormat() const |
|---|
| 137 | { |
|---|
| 138 | computeInternalFormatType(); |
|---|
| 139 | } |
|---|