File: prevent_immutability.patch

package info (click to toggle)
openscenegraph 3.6.5%2Bdfsg1-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,100 kB
  • sloc: cpp: 392,065; ansic: 21,495; java: 1,020; yacc: 548; makefile: 431; objc: 406; xml: 155; lex: 151; javascript: 34
file content (203 lines) | stat: -rw-r--r-- 10,016 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
From: Julien Valentin <mp3butcher@hotmail.com>
Date: Wed, 25 Mar 2020 23:00:24 +0100
Subject: [PATCH] prevent immutability resetting when textureobject is taken
 from orphans

---
 src/osg/Texture1D.cpp            | 10 +++++++---
 src/osg/Texture2D.cpp            |  8 ++++++--
 src/osg/Texture2DArray.cpp       |  6 ++++--
 src/osg/Texture2DMultisample.cpp |  7 +++++--
 src/osg/Texture3D.cpp            |  7 +++++--
 src/osg/TextureCubeMap.cpp       |  6 +++++-
 src/osg/TextureRectangle.cpp     |  7 +++++--
 7 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp
index d24a77a..23e6f4a 100644
--- a/src/osg/Texture1D.cpp
+++ b/src/osg/Texture1D.cpp
@@ -238,13 +238,15 @@ void Texture1D::apply(State& state) const
             textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, 1, 1, 0);
             textureObject->bind();
             applyTexParameters(GL_TEXTURE_1D, state);
-
-            extensions->glTexStorage1D( GL_TEXTURE_1D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth);
+            if(!textureObject->_allocated)
+            {
+                extensions->glTexStorage1D( GL_TEXTURE_1D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth);
+            }
         }
         else
         {
             GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat;
-            textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, internalFormat, _textureWidth, 1, 1, 0);
+            textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, internalFormat, _textureWidth, 1, 1, _borderWidth);
             textureObject->bind();
             applyTexParameters(GL_TEXTURE_1D, state);
 
@@ -260,6 +262,8 @@ void Texture1D::apply(State& state) const
             _readPBuffer->bindPBufferToTexture(GL_FRONT);
         }
 
+        textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat: _internalFormat, _textureWidth, 1, 1, _borderWidth);
+
     }
     else
     {
diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp
index 2aac8b2..f256793 100644
--- a/src/osg/Texture2D.cpp
+++ b/src/osg/Texture2D.cpp
@@ -306,8 +306,11 @@ void Texture2D::apply(State& state) const
              textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
              textureObject->bind();
              applyTexParameters(GL_TEXTURE_2D, state);
-             extensions->glTexStorage2D( GL_TEXTURE_2D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat,
-                      _textureWidth, _textureHeight);
+             if(!textureObject->_allocated)
+             {
+                 extensions->glTexStorage2D( GL_TEXTURE_2D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat,
+                          _textureWidth, _textureHeight);
+             }
          }
          else
          {
@@ -327,6 +330,7 @@ void Texture2D::apply(State& state) const
             _readPBuffer->bindPBufferToTexture(GL_FRONT);
         }
 
+        textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat: _internalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
     }
     else
     {
diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp
index 8edfe2c..bc267f0 100644
--- a/src/osg/Texture2DArray.cpp
+++ b/src/osg/Texture2DArray.cpp
@@ -353,7 +353,7 @@ void Texture2DArray::apply(State& state) const
         applyTexParameters(GL_TEXTURE_2D_ARRAY, state);
 
         // First we need to allocate the texture memory
-        if(texStorageSizedInternalFormat!=0)
+        if(texStorageSizedInternalFormat!=0 && !textureObject->_allocated)
         {
             extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, textureDepth);
         }
@@ -452,7 +452,7 @@ void Texture2DArray::apply(State& state) const
 
         applyTexParameters(GL_TEXTURE_2D_ARRAY,state);
 
-        if (texStorageSizedInternalFormat!=0)
+        if (texStorageSizedInternalFormat!=0 && !textureObject->_allocated)
         {
             extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
         }
@@ -463,6 +463,8 @@ void Texture2DArray::apply(State& state) const
                      _sourceFormat ? _sourceFormat : _internalFormat,
                      _sourceType ? _sourceType : GL_UNSIGNED_BYTE,
                      0);
+
+        textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, _textureWidth, _textureHeight, _textureDepth, 0);
     }
 
     // nothing before, so just unbind the texture target
diff --git a/src/osg/Texture2DMultisample.cpp b/src/osg/Texture2DMultisample.cpp
index 94e5b53..5961f3a 100644
--- a/src/osg/Texture2DMultisample.cpp
+++ b/src/osg/Texture2DMultisample.cpp
@@ -108,8 +108,10 @@ void Texture2DMultisample::apply(State& state) const
         {
             textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0);
             textureObject->bind();
-
-            extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations);
+            if(!textureObject->_allocated)
+            {
+                extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations);
+            }
         }
         else
         {
@@ -123,6 +125,7 @@ void Texture2DMultisample::apply(State& state) const
                                              _textureHeight,
                                              _fixedsamplelocations );
         }
+        textureObject->setAllocated(1, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat: _internalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
 
     }
     else
diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp
index 74fe713..ee97e69 100644
--- a/src/osg/Texture3D.cpp
+++ b/src/osg/Texture3D.cpp
@@ -322,8 +322,10 @@ void Texture3D::apply(State& state) const
             textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_3D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth,0);
             textureObject->bind();
             applyTexParameters(GL_TEXTURE_3D, state);
-
-            extensions->glTexStorage3D( GL_TEXTURE_3D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
+            if(!textureObject->_allocated)
+            {
+                extensions->glTexStorage3D( GL_TEXTURE_3D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
+            }
         }
         else
         {
@@ -345,6 +347,7 @@ void Texture3D::apply(State& state) const
             _readPBuffer->bindPBufferToTexture(GL_FRONT);
         }
 
+        textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat : _internalFormat, _textureWidth, _textureHeight, _textureDepth, _borderWidth);
     }
     else
     {
diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp
index ba61ba9..a2807ce 100644
--- a/src/osg/TextureCubeMap.cpp
+++ b/src/osg/TextureCubeMap.cpp
@@ -353,7 +353,10 @@ void TextureCubeMap::apply(State& state) const
 
         if(texStorageSizedInternalFormat!=0)
         {
-            extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight);
+            if(!textureObject->_allocated)
+            {
+                extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight);
+            }
 
         }
         else
@@ -367,6 +370,7 @@ void TextureCubeMap::apply(State& state) const
                              0);
             }
 
+        textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat : _internalFormat, _textureWidth, _textureHeight, 1, 0);
     }
     else
     {
diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp
index 47d81d7..c79d667 100644
--- a/src/osg/TextureRectangle.cpp
+++ b/src/osg/TextureRectangle.cpp
@@ -281,8 +281,10 @@ void TextureRectangle::apply(State& state) const
             textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_RECTANGLE, 0, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0);
             textureObject->bind();
             applyTexParameters(GL_TEXTURE_RECTANGLE, state);
-
-            extensions->glTexStorage2D( GL_TEXTURE_RECTANGLE, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight);
+            if(!textureObject->_allocated)
+            {
+                extensions->glTexStorage2D( GL_TEXTURE_RECTANGLE, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight);
+            }
         }
         else
         {
@@ -303,6 +305,7 @@ void TextureRectangle::apply(State& state) const
             _readPBuffer->bindPBufferToTexture(GL_FRONT);
         }
 
+        textureObject->setAllocated(0, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat : _internalFormat, _textureWidth, _textureHeight, 1, 0);
     }
     else
     {