Package: gem / 1:0.93.3-7

sanitize-glstack.patch Patch series | download
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
Author: IOhannes m zmoelnig <zmoelnig@umlautO.umlaeute.mur.at>
Description: check whether querying the matrix depths is really possible
and if not, stop throwing an error for each render-cycle;
this has been backported from upstream's HEAD
Forwarded: not-needed

--- gem.orig/src/Gem/GLStack.cpp
+++ gem/src/Gem/GLStack.cpp
@@ -25,6 +25,8 @@
 /* need GLUtil for glReportError */ 
 #include "Gem/GemGL.h"
 #include "Utils/GLUtil.h"
+#include <map>
+
 #define GLDEBUG if(glReportError())::startpost("glError @ %s:%d[%s] ", __FILE__, __LINE__, __FUNCTION__), ::post
 
 using namespace gem;
@@ -46,76 +48,39 @@
 };
 };
 
-static GLenum id2maxdepth(enum GLStack::GemStackId id) {
-  GLenum result=0;
-  switch(id) {
-  case GLStack::MODELVIEW:
-    result=GL_MAX_MODELVIEW_STACK_DEPTH; 
-    break;
-  case GLStack::PROJECTION: 
-    result=GL_MAX_PROJECTION_STACK_DEPTH; 
-    break;
-  case GLStack::TEXTURE: 
-    result=GL_MAX_TEXTURE_STACK_DEPTH; 
-    break;
-  case GLStack::COLOR: 
-    result=GL_MAX_COLOR_MATRIX_STACK_DEPTH; 
-    break;
-  default:
-    //    ::error("GLStack: illegal stack matrix: %d");
-    break;
-  }
-  return result;
-}
-
-
-static GLenum id2depth(enum GLStack::GemStackId id) {
-  GLenum result=0;
-  switch(id) {
-  case GLStack::MODELVIEW:
-    result=GL_MODELVIEW_STACK_DEPTH; 
-    break;
-  case GLStack::PROJECTION: 
-    result=GL_PROJECTION_STACK_DEPTH; 
-    break;
-  case GLStack::TEXTURE: 
-    result=GL_TEXTURE_STACK_DEPTH; 
-    break;
-  case GLStack::COLOR: 
-    result=GL_COLOR_MATRIX_STACK_DEPTH; 
-    break;
-  default:
-    //    ::error("GLStack: illegal stack matrix: %d");
-    break;
-  }
-  return result;
-}
-
-
-static GLenum id2mode(enum GLStack::GemStackId id) {
-  GLenum result=0;
-  switch(id) {
-  case GLStack::MODELVIEW:
-    result=GL_MODELVIEW; 
-    break;
-  case GLStack::PROJECTION: 
-    result=GL_PROJECTION; 
-    break;
-  case GLStack::TEXTURE: 
-    result=GL_TEXTURE; 
-    break;
-  case GLStack::COLOR: 
-    result=GL_COLOR; 
-    break;
-  default:
-    //    ::error("GLStack: illegal stack matrix: %d");
-    break;
-  }
-  return result;
+namespace {
+  static std::map<enum GLStack::GemStackId, GLenum>s_id2mode;
+  static std::map<enum GLStack::GemStackId, GLenum>s_id2depth;
+  static std::map<enum GLStack::GemStackId, GLenum>s_id2maxdepth;
+  static std::map<enum GLStack::GemStackId, bool>s_id2init;
 }
 
 
 GLStack:: GLStack(bool haveValidContext) : data(new Data()) {
+  static bool firsttime=true;
+  if(firsttime) {
+    s_id2mode[MODELVIEW] =GL_MODELVIEW;
+    s_id2mode[PROJECTION]=GL_PROJECTION;
+    s_id2mode[TEXTURE]   =GL_TEXTURE;
+    s_id2mode[COLOR]     =GL_COLOR;
+
+    s_id2depth[MODELVIEW] =GL_MODELVIEW_STACK_DEPTH;
+    s_id2depth[PROJECTION]=GL_PROJECTION_STACK_DEPTH;
+    s_id2depth[TEXTURE]   =GL_TEXTURE_STACK_DEPTH;
+    s_id2depth[COLOR]     =GL_COLOR_MATRIX_STACK_DEPTH;
+
+    s_id2maxdepth[MODELVIEW] =GL_MAX_MODELVIEW_STACK_DEPTH;
+    s_id2maxdepth[PROJECTION]=GL_MAX_PROJECTION_STACK_DEPTH;
+    s_id2maxdepth[TEXTURE]   =GL_MAX_TEXTURE_STACK_DEPTH;
+    s_id2maxdepth[COLOR]     =GL_MAX_COLOR_MATRIX_STACK_DEPTH;
+
+    s_id2init[MODELVIEW] =false;
+    s_id2init[PROJECTION]=false;
+    s_id2init[TEXTURE]   =false;
+    s_id2init[COLOR]     =false;
+  }
+  firsttime=false;
+
   if(haveValidContext) {
     reset();
   }
@@ -129,7 +94,7 @@
   // changing the texunit (e.g. in [pix_texture]) makes the 
   // local depthcounter a useless, and we get a lot of 
   // stack under/overflows
-#endif  
+#endif
 
 
 /** push the given matrix to the stack if the maximum has not been reached 
@@ -137,7 +102,7 @@
  * NOTE: needs valid openGL context
  */
 bool GLStack::push(enum GemStackId id) {
-  GLenum mode=id2mode(id);
+  GLenum mode=s_id2mode[id];
   if(!mode)return false;
   if(data->stackDepth[id]<data->maxDepth[id]) {
     glMatrixMode(mode);
@@ -163,7 +128,7 @@
  * NOTE: needs valid openGL context
  */
 bool GLStack::pop(enum GemStackId id) {
-  GLenum mode=id2mode(id);
+  GLenum mode=s_id2mode[id];
   if(!mode)return false;
 
   data->stackDepth[id]--;
@@ -197,14 +162,30 @@
  * NOTE: needs valid openGL context
  */
 int GLStack::reset(enum GemStackId id) {
-  GLenum maxdepth=id2maxdepth(id);
-  GLenum depth=id2depth(id);
+  bool firsttime=!(s_id2init[id]);
+  if(firsttime) {
+    s_id2init[id]=true;
+
+    if(COLOR == id && !GLEW_ARB_imaging) {
+      s_id2maxdepth[id]=0;
+      s_id2depth[id]=0;
+    }
+    glReportError(); // clear any errors so far
+  }
+
+
+  GLenum maxdepth=s_id2maxdepth[id];
+  GLenum depth=s_id2depth[id];
 
   if(maxdepth && depth) {
-    if(COLOR != id || GLEW_ARB_imaging) {
-      glGetIntegerv(maxdepth, data->maxDepth+id);
-      glGetIntegerv(depth, data->stackDepth+id);
-    }
+    /* hmm, some ati-cards (with fglrx) report GLEW_ARB_imaging support but fail the 'depth' test for COLOR */
+
+    glGetIntegerv(maxdepth, data->maxDepth+id);
+    if(firsttime && glReportError())s_id2maxdepth[id]=0;
+
+    glGetIntegerv(depth, data->stackDepth+id);
+    if(firsttime && glReportError())s_id2depth[id]=0;
+
     data->orgDepth[id]=data->stackDepth[id];
     return data->stackDepth[id];
   }