]> git.pld-linux.org Git - packages/Mesa.git/blob - Mesa-git.patch
- rel 4
[packages/Mesa.git] / Mesa-git.patch
1 diff --git a/configs/autoconf.in b/configs/autoconf.in
2 index 83737e3..a7f3c9d 100644
3 --- a/configs/autoconf.in
4 +++ b/configs/autoconf.in
5 @@ -124,7 +124,7 @@ INSTALL_INC_DIR = $(includedir)
6  DRI_DRIVER_INSTALL_DIR = @DRI_DRIVER_INSTALL_DIR@
7  
8  # Where libGL will look for DRI hardware drivers
9 -DRI_DRIVER_SEARCH_DIR = $(DRI_DRIVER_INSTALL_DIR)
10 +DRI_DRIVER_SEARCH_DIR = @DRI_DRIVER_SEARCH_DIR@
11  
12  # Xorg driver install directory (for xorg state-tracker)
13  XORG_DRIVER_INSTALL_DIR = @XORG_DRIVER_INSTALL_DIR@
14 diff --git a/configure.ac b/configure.ac
15 index 7518976..5d11cf8 100644
16 --- a/configure.ac
17 +++ b/configure.ac
18 @@ -230,6 +230,8 @@ else
19          LIB_EXTENSION='dylib' ;;
20      cygwin* )
21          LIB_EXTENSION='dll' ;;
22 +    aix* )
23 +        LIB_EXTENSION='a' ;;
24      * )
25          LIB_EXTENSION='so' ;;
26      esac
27 @@ -647,6 +649,13 @@ AC_ARG_WITH([dri-driverdir],
28      [DRI_DRIVER_INSTALL_DIR="$withval"],
29      [DRI_DRIVER_INSTALL_DIR='${libdir}/dri'])
30  AC_SUBST([DRI_DRIVER_INSTALL_DIR])
31 +dnl Extra search path for DRI drivers
32 +AC_ARG_WITH([dri-searchpath],
33 +    [AS_HELP_STRING([--with-dri-searchpath=DIRS...],
34 +        [semicolon delimited DRI driver search directories @<:@${libdir}/dri@:>@])],
35 +    [DRI_DRIVER_SEARCH_DIR="$withval"],
36 +    [DRI_DRIVER_SEARCH_DIR='${DRI_DRIVER_INSTALL_DIR}'])
37 +AC_SUBST([DRI_DRIVER_SEARCH_DIR])
38  dnl Direct rendering or just indirect rendering
39  AC_ARG_ENABLE([driglx-direct],
40      [AS_HELP_STRING([--disable-driglx-direct],
41 diff --git a/docs/news.html b/docs/news.html
42 index 07ad42e..93da56a 100644
43 --- a/docs/news.html
44 +++ b/docs/news.html
45 @@ -10,6 +10,17 @@
46  
47  <H1>News</H1>
48  
49 +<h2>September 28, 2009</h2>
50 +<p>
51 +<a href="relnotes-7.6.html">Mesa 7.6</a> is released.  This is a new feature
52 +release.  Those especially concerned about stability may want to wait for the
53 +follow-on 7.6.1 bug-fix release.
54 +</p>
55 +<p>
56 +<a href="relnotes-7.5.2.html">Mesa 7.5.2</a> is also released.
57 +This is a stable release fixing bugs since the 7.5.1 release.
58 +</p>
59 +
60  
61  <h2>September 3, 2009</h2>
62  <p>
63 diff --git a/docs/relnotes-7.5.2.html b/docs/relnotes-7.5.2.html
64 index 0832e11..5c395d9 100644
65 --- a/docs/relnotes-7.5.2.html
66 +++ b/docs/relnotes-7.5.2.html
67 @@ -8,7 +8,7 @@
68  
69  <body bgcolor="#eeeeee">
70  
71 -<H1>Mesa 7.5.2 Release Notes, (date tbd)</H1>
72 +<H1>Mesa 7.5.2 Release Notes, 28 September 2009</H1>
73  
74  <p>
75  Mesa 7.5.2 is a bug-fix release fixing issues found since the 7.5.1 release.
76 @@ -31,7 +31,15 @@ for DRI hardware acceleration.
77  
78  <h2>MD5 checksums</h2>
79  <pre>
80 -tbd
81 +43a90191dd9f76cd65dcc1ac91f3be70  MesaLib-7.5.2.tar.gz
82 +94e47a499f1226803869c2e37a6a8e3a  MesaLib-7.5.2.tar.bz2
83 +1ecb822b567ad67a0617361d45206b67  MesaLib-7.5.2.zip
84 +2718fdce7e075911d6147beb8f27104b  MesaDemos-7.5.2.tar.gz
85 +4e0f5ccd58afe21eddcd94327d926e86  MesaDemos-7.5.2.tar.bz2
86 +f621f8c223b278d7c8e49a012d56ca25  MesaDemos-7.5.2.zip
87 +83c16c1d6bcfcc3f97aab5d2fe430b4c  MesaGLUT-7.5.2.tar.gz
88 +e5d03bedae369ea3705783573bb33813  MesaGLUT-7.5.2.tar.bz2
89 +e82ba28e00d653e6f437d32be8ca8481  MesaGLUT-7.5.2.zip
90  </pre>
91  
92  
93 @@ -55,6 +63,5 @@ tbd
94      when using Gallium.
95  </ul>
96  
97 -
98  </body>
99  </html>
100 diff --git a/docs/relnotes-7.6.1.html b/docs/relnotes-7.6.1.html
101 new file mode 100644
102 index 0000000..9ee6bab
103 --- /dev/null
104 +++ b/docs/relnotes-7.6.1.html
105 @@ -0,0 +1,58 @@
106 +<HTML>
107 +
108 +<TITLE>Mesa Release Notes</TITLE>
109 +
110 +<head><link rel="stylesheet" type="text/css" href="mesa.css"></head>
111 +
112 +<BODY>
113 +
114 +<body bgcolor="#eeeeee">
115 +
116 +<H1>Mesa 7.6.1 Release Notes, (date tbd)</H1>
117 +
118 +<p>
119 +Mesa 7.6.1 is a bug-fix release fixing issues since version 7.6.
120 +</p>
121 +<p>
122 +Mesa 7.6.1 implements the OpenGL 2.1 API, but the version reported by
123 +glGetString(GL_VERSION) depends on the particular driver being used.
124 +Some drivers don't support all the features required in OpenGL 2.1.
125 +</p>
126 +<p>
127 +See the <a href="install.html">Compiling/Installing page</a> for prerequisites
128 +for DRI hardware acceleration.
129 +</p>
130 +
131 +
132 +<h2>MD5 checksums</h2>
133 +<pre>
134 +tbd
135 +</pre>
136 +
137 +
138 +<h2>New features</h2>
139 +<ul>
140 +<li>Upgraded GL/glext.h to version 56, GL/glxext.h to version 25,
141 +    GL/wglext.h to version 17
142 +</ul>
143 +
144 +
145 +<h2>Bug fixes</h2>
146 +<ul>
147 +<li>Fixed crash caused by glXCopyContext() and glXDestroyContext(), bug 24217
148 +<li>glXQueryContext(GLX_RENDER_TYPE) returned wrong values (bug 24211)
149 +<li>GLSL sqrt(0) returned unpredictable results
150 +<li>Fixed default texture binding bug when a bound texture was deleted.
151 +<li>r300: Work around an issue with very large fragment programs on R500.
152 +<li>Fake glXQueryDrawable() didn't return good values (bug 24320)
153 +<li>Fixed AUX buffer breakage (bug 24426).
154 +<li>Fixed locale-dependent float parsing bug in GLSL compiler (bug 24531)
155 +<li>Fixed Gallium Cell driver compilation failure.
156 +<li>Fixed glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT) query so that
157 +    it returns the actual compressed format chosen.
158 +<li>Fixed glBitmap bugs in Intel drivers.
159 +<li>Fixed a number of Microsoft Visual Studio compilation problems.
160 +</ul>
161 +
162 +</body>
163 +</html>
164 diff --git a/docs/relnotes.html b/docs/relnotes.html
165 index 560a660..d8cbc79 100644
166 --- a/docs/relnotes.html
167 +++ b/docs/relnotes.html
168 @@ -13,6 +13,7 @@ The release notes summarize what's new or changed in each Mesa release.
169  </p>
170  
171  <UL>
172 +<LI><A HREF="relnotes-7.6.1.html">7.6.1 release notes</A>
173  <LI><A HREF="relnotes-7.6.html">7.6 release notes</A>
174  <LI><A HREF="relnotes-7.5.2.html">7.5.2 release notes</A>
175  <LI><A HREF="relnotes-7.5.1.html">7.5.1 release notes</A>
176 diff --git a/include/GL/gl_mangle.h b/include/GL/gl_mangle.h
177 index 54147f7..59f6149 100644
178 --- a/include/GL/gl_mangle.h
179 +++ b/include/GL/gl_mangle.h
180 @@ -108,12 +108,20 @@
181  #define glBlendColorEXT                MANGLE(BlendColorEXT)
182  #define glBlendColor           MANGLE(BlendColor)
183  #define glBlendEquationEXT             MANGLE(BlendEquationEXT)
184 +#define glBlendEquationi               MANGLE(BlendEquationi)
185 +#define glBlendEquationIndexedAMD              MANGLE(BlendEquationIndexedAMD)
186  #define glBlendEquation                MANGLE(BlendEquation)
187  #define glBlendEquationSeparateATI             MANGLE(BlendEquationSeparateATI)
188  #define glBlendEquationSeparateEXT             MANGLE(BlendEquationSeparateEXT)
189 +#define glBlendEquationSeparatei               MANGLE(BlendEquationSeparatei)
190 +#define glBlendEquationSeparateIndexedAMD              MANGLE(BlendEquationSeparateIndexedAMD)
191  #define glBlendEquationSeparate                MANGLE(BlendEquationSeparate)
192 +#define glBlendFunci           MANGLE(BlendFunci)
193 +#define glBlendFuncIndexedAMD          MANGLE(BlendFuncIndexedAMD)
194  #define glBlendFunc            MANGLE(BlendFunc)
195  #define glBlendFuncSeparateEXT         MANGLE(BlendFuncSeparateEXT)
196 +#define glBlendFuncSeparatei           MANGLE(BlendFuncSeparatei)
197 +#define glBlendFuncSeparateIndexedAMD          MANGLE(BlendFuncSeparateIndexedAMD)
198  #define glBlendFuncSeparateINGR                MANGLE(BlendFuncSeparateINGR)
199  #define glBlendFuncSeparate            MANGLE(BlendFuncSeparate)
200  #define glBlitFramebufferEXT           MANGLE(BlitFramebufferEXT)
201 @@ -148,6 +156,7 @@
202  #define glClientActiveTexture          MANGLE(ClientActiveTexture)
203  #define glClientActiveVertexStreamATI          MANGLE(ClientActiveVertexStreamATI)
204  #define glClientAttribDefaultEXT               MANGLE(ClientAttribDefaultEXT)
205 +#define glClientWaitSync               MANGLE(ClientWaitSync)
206  #define glClipPlane            MANGLE(ClipPlane)
207  #define glColor3b              MANGLE(Color3b)
208  #define glColor3bv             MANGLE(Color3bv)
209 @@ -320,6 +329,7 @@
210  #define glDeleteRenderbuffersEXT               MANGLE(DeleteRenderbuffersEXT)
211  #define glDeleteRenderbuffers          MANGLE(DeleteRenderbuffers)
212  #define glDeleteShader         MANGLE(DeleteShader)
213 +#define glDeleteSync           MANGLE(DeleteSync)
214  #define glDeleteTexturesEXT            MANGLE(DeleteTexturesEXT)
215  #define glDeleteTextures               MANGLE(DeleteTextures)
216  #define glDeleteTransformFeedbacksNV           MANGLE(DeleteTransformFeedbacksNV)
217 @@ -341,6 +351,7 @@
218  #define glDisableIndexedEXT            MANGLE(DisableIndexedEXT)
219  #define glDisable              MANGLE(Disable)
220  #define glDisableVariantClientStateEXT         MANGLE(DisableVariantClientStateEXT)
221 +#define glDisableVertexAttribAPPLE             MANGLE(DisableVertexAttribAPPLE)
222  #define glDisableVertexAttribArrayARB          MANGLE(DisableVertexAttribArrayARB)
223  #define glDisableVertexAttribArray             MANGLE(DisableVertexAttribArray)
224  #define glDrawArraysEXT                MANGLE(DrawArraysEXT)
225 @@ -354,7 +365,9 @@
226  #define glDrawBuffers          MANGLE(DrawBuffers)
227  #define glDrawElementArrayAPPLE                MANGLE(DrawElementArrayAPPLE)
228  #define glDrawElementArrayATI          MANGLE(DrawElementArrayATI)
229 +#define glDrawElementsBaseVertex               MANGLE(DrawElementsBaseVertex)
230  #define glDrawElementsInstancedARB             MANGLE(DrawElementsInstancedARB)
231 +#define glDrawElementsInstancedBaseVertex              MANGLE(DrawElementsInstancedBaseVertex)
232  #define glDrawElementsInstancedEXT             MANGLE(DrawElementsInstancedEXT)
233  #define glDrawElementsInstanced                MANGLE(DrawElementsInstanced)
234  #define glDrawElements         MANGLE(DrawElements)
235 @@ -362,6 +375,7 @@
236  #define glDrawPixels           MANGLE(DrawPixels)
237  #define glDrawRangeElementArrayAPPLE           MANGLE(DrawRangeElementArrayAPPLE)
238  #define glDrawRangeElementArrayATI             MANGLE(DrawRangeElementArrayATI)
239 +#define glDrawRangeElementsBaseVertex          MANGLE(DrawRangeElementsBaseVertex)
240  #define glDrawRangeElementsEXT         MANGLE(DrawRangeElementsEXT)
241  #define glDrawRangeElements            MANGLE(DrawRangeElements)
242  #define glDrawTransformFeedbackNV              MANGLE(DrawTransformFeedbackNV)
243 @@ -378,6 +392,7 @@
244  #define glEnableIndexedEXT             MANGLE(EnableIndexedEXT)
245  #define glEnable               MANGLE(Enable)
246  #define glEnableVariantClientStateEXT          MANGLE(EnableVariantClientStateEXT)
247 +#define glEnableVertexAttribAPPLE              MANGLE(EnableVertexAttribAPPLE)
248  #define glEnableVertexAttribArrayARB           MANGLE(EnableVertexAttribArrayARB)
249  #define glEnableVertexAttribArray              MANGLE(EnableVertexAttribArray)
250  #define glEndConditionalRender         MANGLE(EndConditionalRender)
251 @@ -409,6 +424,7 @@
252  #define glExecuteProgramNV             MANGLE(ExecuteProgramNV)
253  #define glExtractComponentEXT          MANGLE(ExtractComponentEXT)
254  #define glFeedbackBuffer               MANGLE(FeedbackBuffer)
255 +#define glFenceSync            MANGLE(FenceSync)
256  #define glFinalCombinerInputNV         MANGLE(FinalCombinerInputNV)
257  #define glFinishAsyncSGIX              MANGLE(FinishAsyncSGIX)
258  #define glFinishFenceAPPLE             MANGLE(FinishFenceAPPLE)
259 @@ -469,9 +485,11 @@
260  #define glFramebufferTextureEXT                MANGLE(FramebufferTextureEXT)
261  #define glFramebufferTextureFaceARB            MANGLE(FramebufferTextureFaceARB)
262  #define glFramebufferTextureFaceEXT            MANGLE(FramebufferTextureFaceEXT)
263 +#define glFramebufferTextureFace               MANGLE(FramebufferTextureFace)
264  #define glFramebufferTextureLayerARB           MANGLE(FramebufferTextureLayerARB)
265  #define glFramebufferTextureLayerEXT           MANGLE(FramebufferTextureLayerEXT)
266  #define glFramebufferTextureLayer              MANGLE(FramebufferTextureLayer)
267 +#define glFramebufferTexture           MANGLE(FramebufferTexture)
268  #define glFrameTerminatorGREMEDY               MANGLE(FrameTerminatorGREMEDY)
269  #define glFrameZoomSGIX                MANGLE(FrameZoomSGIX)
270  #define glFreeObjectBufferATI          MANGLE(FreeObjectBufferATI)
271 @@ -523,6 +541,7 @@
272  #define glGetBooleanIndexedvEXT                MANGLE(GetBooleanIndexedvEXT)
273  #define glGetBooleani_v                MANGLE(GetBooleani_v)
274  #define glGetBooleanv          MANGLE(GetBooleanv)
275 +#define glGetBufferParameteri64v               MANGLE(GetBufferParameteri64v)
276  #define glGetBufferParameterivARB              MANGLE(GetBufferParameterivARB)
277  #define glGetBufferParameteriv         MANGLE(GetBufferParameteriv)
278  #define glGetBufferPointervARB         MANGLE(GetBufferPointervARB)
279 @@ -586,6 +605,8 @@
280  #define glGetImageTransformParameterivHP               MANGLE(GetImageTransformParameterivHP)
281  #define glGetInfoLogARB                MANGLE(GetInfoLogARB)
282  #define glGetInstrumentsSGIX           MANGLE(GetInstrumentsSGIX)
283 +#define glGetInteger64i_v              MANGLE(GetInteger64i_v)
284 +#define glGetInteger64v                MANGLE(GetInteger64v)
285  #define glGetIntegerIndexedvEXT                MANGLE(GetIntegerIndexedvEXT)
286  #define glGetIntegeri_v                MANGLE(GetIntegeri_v)
287  #define glGetIntegerv          MANGLE(GetIntegerv)
288 @@ -615,6 +636,7 @@
289  #define glGetMinmaxParameterfv         MANGLE(GetMinmaxParameterfv)
290  #define glGetMinmaxParameterivEXT              MANGLE(GetMinmaxParameterivEXT)
291  #define glGetMinmaxParameteriv         MANGLE(GetMinmaxParameteriv)
292 +#define glGetMultisamplefv             MANGLE(GetMultisamplefv)
293  #define glGetMultisamplefvNV           MANGLE(GetMultisamplefvNV)
294  #define glGetMultiTexEnvfvEXT          MANGLE(GetMultiTexEnvfvEXT)
295  #define glGetMultiTexEnvivEXT          MANGLE(GetMultiTexEnvivEXT)
296 @@ -642,6 +664,7 @@
297  #define glGetObjectBufferfvATI         MANGLE(GetObjectBufferfvATI)
298  #define glGetObjectBufferivATI         MANGLE(GetObjectBufferivATI)
299  #define glGetObjectParameterfvARB              MANGLE(GetObjectParameterfvARB)
300 +#define glGetObjectParameterivAPPLE            MANGLE(GetObjectParameterivAPPLE)
301  #define glGetObjectParameterivARB              MANGLE(GetObjectParameterivARB)
302  #define glGetOcclusionQueryivNV                MANGLE(GetOcclusionQueryivNV)
303  #define glGetOcclusionQueryuivNV               MANGLE(GetOcclusionQueryuivNV)
304 @@ -698,6 +721,7 @@
305  #define glGetSharpenTexFuncSGIS                MANGLE(GetSharpenTexFuncSGIS)
306  #define glGetStringi           MANGLE(GetStringi)
307  #define glGetString            MANGLE(GetString)
308 +#define glGetSynciv            MANGLE(GetSynciv)
309  #define glGetTexBumpParameterfvATI             MANGLE(GetTexBumpParameterfvATI)
310  #define glGetTexBumpParameterivATI             MANGLE(GetTexBumpParameterivATI)
311  #define glGetTexEnvfv          MANGLE(GetTexEnvfv)
312 @@ -715,6 +739,7 @@
313  #define glGetTexParameterIuivEXT               MANGLE(GetTexParameterIuivEXT)
314  #define glGetTexParameterIuiv          MANGLE(GetTexParameterIuiv)
315  #define glGetTexParameteriv            MANGLE(GetTexParameteriv)
316 +#define glGetTexParameterPointervAPPLE         MANGLE(GetTexParameterPointervAPPLE)
317  #define glGetTextureImageEXT           MANGLE(GetTextureImageEXT)
318  #define glGetTextureLevelParameterfvEXT                MANGLE(GetTextureLevelParameterfvEXT)
319  #define glGetTextureLevelParameterivEXT                MANGLE(GetTextureLevelParameterivEXT)
320 @@ -825,12 +850,14 @@
321  #define glIsRenderbufferEXT            MANGLE(IsRenderbufferEXT)
322  #define glIsRenderbuffer               MANGLE(IsRenderbuffer)
323  #define glIsShader             MANGLE(IsShader)
324 +#define glIsSync               MANGLE(IsSync)
325  #define glIsTextureEXT         MANGLE(IsTextureEXT)
326  #define glIsTexture            MANGLE(IsTexture)
327  #define glIsTransformFeedbackNV                MANGLE(IsTransformFeedbackNV)
328  #define glIsVariantEnabledEXT          MANGLE(IsVariantEnabledEXT)
329  #define glIsVertexArrayAPPLE           MANGLE(IsVertexArrayAPPLE)
330  #define glIsVertexArray                MANGLE(IsVertexArray)
331 +#define glIsVertexAttribEnabledAPPLE           MANGLE(IsVertexAttribEnabledAPPLE)
332  #define glLightEnviSGIX                MANGLE(LightEnviSGIX)
333  #define glLightf               MANGLE(Lightf)
334  #define glLightfv              MANGLE(Lightfv)
335 @@ -877,6 +904,10 @@
336  #define glMapObjectBufferATI           MANGLE(MapObjectBufferATI)
337  #define glMapParameterfvNV             MANGLE(MapParameterfvNV)
338  #define glMapParameterivNV             MANGLE(MapParameterivNV)
339 +#define glMapVertexAttrib1dAPPLE               MANGLE(MapVertexAttrib1dAPPLE)
340 +#define glMapVertexAttrib1fAPPLE               MANGLE(MapVertexAttrib1fAPPLE)
341 +#define glMapVertexAttrib2dAPPLE               MANGLE(MapVertexAttrib2dAPPLE)
342 +#define glMapVertexAttrib2fAPPLE               MANGLE(MapVertexAttrib2fAPPLE)
343  #define glMaterialf            MANGLE(Materialf)
344  #define glMaterialfv           MANGLE(Materialfv)
345  #define glMateriali            MANGLE(Materiali)
346 @@ -907,9 +938,11 @@
347  #define glMatrixTranslatefEXT          MANGLE(MatrixTranslatefEXT)
348  #define glMinmaxEXT            MANGLE(MinmaxEXT)
349  #define glMinmax               MANGLE(Minmax)
350 +#define glMinSampleShading             MANGLE(MinSampleShading)
351  #define glMultiDrawArraysEXT           MANGLE(MultiDrawArraysEXT)
352  #define glMultiDrawArrays              MANGLE(MultiDrawArrays)
353  #define glMultiDrawElementArrayAPPLE           MANGLE(MultiDrawElementArrayAPPLE)
354 +#define glMultiDrawElementsBaseVertex          MANGLE(MultiDrawElementsBaseVertex)
355  #define glMultiDrawElementsEXT         MANGLE(MultiDrawElementsEXT)
356  #define glMultiDrawElements            MANGLE(MultiDrawElements)
357  #define glMultiDrawRangeElementArrayAPPLE              MANGLE(MultiDrawRangeElementArrayAPPLE)
358 @@ -1072,6 +1105,8 @@
359  #define glNormalStream3ivATI           MANGLE(NormalStream3ivATI)
360  #define glNormalStream3sATI            MANGLE(NormalStream3sATI)
361  #define glNormalStream3svATI           MANGLE(NormalStream3svATI)
362 +#define glObjectPurgeableAPPLE         MANGLE(ObjectPurgeableAPPLE)
363 +#define glObjectUnpurgeableAPPLE               MANGLE(ObjectUnpurgeableAPPLE)
364  #define glOrtho                MANGLE(Ortho)
365  #define glPassTexCoordATI              MANGLE(PassTexCoordATI)
366  #define glPassThrough          MANGLE(PassThrough)
367 @@ -1162,6 +1197,7 @@
368  #define glProgramParameter4fvNV                MANGLE(ProgramParameter4fvNV)
369  #define glProgramParameteriARB         MANGLE(ProgramParameteriARB)
370  #define glProgramParameteriEXT         MANGLE(ProgramParameteriEXT)
371 +#define glProgramParameteri            MANGLE(ProgramParameteri)
372  #define glProgramParameters4dvNV               MANGLE(ProgramParameters4dvNV)
373  #define glProgramParameters4fvNV               MANGLE(ProgramParameters4fvNV)
374  #define glProgramStringARB             MANGLE(ProgramStringARB)
375 @@ -1200,6 +1236,7 @@
376  #define glProgramUniformMatrix4x3fvEXT         MANGLE(ProgramUniformMatrix4x3fvEXT)
377  #define glProgramVertexLimitNV         MANGLE(ProgramVertexLimitNV)
378  #define glProvokingVertexEXT           MANGLE(ProvokingVertexEXT)
379 +#define glProvokingVertex              MANGLE(ProvokingVertex)
380  #define glPushAttrib           MANGLE(PushAttrib)
381  #define glPushClientAttribDefaultEXT           MANGLE(PushClientAttribDefaultEXT)
382  #define glPushClientAttrib             MANGLE(PushClientAttrib)
383 @@ -1283,6 +1320,7 @@
384  #define glSampleCoverage               MANGLE(SampleCoverage)
385  #define glSampleMapATI         MANGLE(SampleMapATI)
386  #define glSampleMaskEXT                MANGLE(SampleMaskEXT)
387 +#define glSampleMaski          MANGLE(SampleMaski)
388  #define glSampleMaskIndexedNV          MANGLE(SampleMaskIndexedNV)
389  #define glSampleMaskSGIS               MANGLE(SampleMaskSGIS)
390  #define glSamplePatternEXT             MANGLE(SamplePatternEXT)
391 @@ -1454,8 +1492,10 @@
392  #define glTexGeniv             MANGLE(TexGeniv)
393  #define glTexImage1D           MANGLE(TexImage1D)
394  #define glTexImage2D           MANGLE(TexImage2D)
395 +#define glTexImage2DMultisample                MANGLE(TexImage2DMultisample)
396  #define glTexImage3DEXT                MANGLE(TexImage3DEXT)
397  #define glTexImage3D           MANGLE(TexImage3D)
398 +#define glTexImage3DMultisample                MANGLE(TexImage3DMultisample)
399  #define glTexImage4DSGIS               MANGLE(TexImage4DSGIS)
400  #define glTexParameterf                MANGLE(TexParameterf)
401  #define glTexParameterfv               MANGLE(TexParameterfv)
402 @@ -1487,6 +1527,7 @@
403  #define glTextureParameterIivEXT               MANGLE(TextureParameterIivEXT)
404  #define glTextureParameterIuivEXT              MANGLE(TextureParameterIuivEXT)
405  #define glTextureParameterivEXT                MANGLE(TextureParameterivEXT)
406 +#define glTextureRangeAPPLE            MANGLE(TextureRangeAPPLE)
407  #define glTextureRenderbufferEXT               MANGLE(TextureRenderbufferEXT)
408  #define glTextureSubImage1DEXT         MANGLE(TextureSubImage1DEXT)
409  #define glTextureSubImage2DEXT         MANGLE(TextureSubImage2DEXT)
410 @@ -1828,6 +1869,7 @@
411  #define glVertexWeighthvNV             MANGLE(VertexWeighthvNV)
412  #define glVertexWeightPointerEXT               MANGLE(VertexWeightPointerEXT)
413  #define glViewport             MANGLE(Viewport)
414 +#define glWaitSync             MANGLE(WaitSync)
415  #define glWeightbvARB          MANGLE(WeightbvARB)
416  #define glWeightdvARB          MANGLE(WeightdvARB)
417  #define glWeightfvARB          MANGLE(WeightfvARB)
418 diff --git a/include/GL/glext.h b/include/GL/glext.h
419 index 24e6c5d..473b22a 100644
420 --- a/include/GL/glext.h
421 +++ b/include/GL/glext.h
422 @@ -29,9 +29,9 @@ extern "C" {
423  */
424  
425  /* Header file version number, required by OpenGL ABI for Linux */
426 -/* glext.h last updated $Date$ */
427 +/* glext.h last updated $Date$ */
428  /* Current version at http://www.opengl.org/registry/ */
429 -#define GL_GLEXT_VERSION 54
430 +#define GL_GLEXT_VERSION 56
431  
432  /* Function declaration macros - to move into glplatform.h */
433  
434 @@ -4236,7 +4236,7 @@ extern "C" {
435  #define GL_LUMINANCE16_SNORM              0x9019
436  #define GL_LUMINANCE16_ALPHA16_SNORM      0x901A
437  #define GL_INTENSITY16_SNORM              0x901B
438 -/* reuse GL_R_SNORM */
439 +/* reuse GL_RED_SNORM */
440  /* reuse GL_RG_SNORM */
441  /* reuse GL_RGB_SNORM */
442  /* reuse GL_RGBA_SNORM */
443 @@ -4311,6 +4311,88 @@ extern "C" {
444  #define GL_UNPACK_ROW_BYTES_APPLE         0x8A16
445  #endif
446  
447 +#ifndef GL_APPLE_rgb_422
448 +#define GL_RGB_422_APPLE                  0x8A1F
449 +/* reuse GL_UNSIGNED_SHORT_8_8_APPLE */
450 +/* reuse GL_UNSIGNED_SHORT_8_8_REV_APPLE */
451 +#endif
452 +
453 +#ifndef GL_NV_video_capture
454 +#define GL_VIDEO_BUFFER_NV                0x9020
455 +#define GL_VIDEO_BUFFER_BINDING_NV        0x9021
456 +#define GL_FIELD_UPPER_NV                 0x9022
457 +#define GL_FIELD_LOWER_NV                 0x9023
458 +#define GL_NUM_VIDEO_CAPTURE_STREAMS_NV   0x9024
459 +#define GL_NEXT_VIDEO_CAPTURE_BUFFER_STATUS_NV 0x9025
460 +#define GL_VIDEO_CAPTURE_TO_422_SUPPORTED_NV 0x9026
461 +#define GL_LAST_VIDEO_CAPTURE_STATUS_NV   0x9027
462 +#define GL_VIDEO_BUFFER_PITCH_NV          0x9028
463 +#define GL_VIDEO_COLOR_CONVERSION_MATRIX_NV 0x9029
464 +#define GL_VIDEO_COLOR_CONVERSION_MAX_NV  0x902A
465 +#define GL_VIDEO_COLOR_CONVERSION_MIN_NV  0x902B
466 +#define GL_VIDEO_COLOR_CONVERSION_OFFSET_NV 0x902C
467 +#define GL_VIDEO_BUFFER_INTERNAL_FORMAT_NV 0x902D
468 +#define GL_PARTIAL_SUCCESS_NV             0x902E
469 +#define GL_SUCCESS_NV                     0x902F
470 +#define GL_FAILURE_NV                     0x9030
471 +#define GL_YCBYCR8_422_NV                 0x9031
472 +#define GL_YCBAYCR8A_4224_NV              0x9032
473 +#define GL_Z6Y10Z6CB10Z6Y10Z6CR10_422_NV  0x9033
474 +#define GL_Z6Y10Z6CB10Z6A10Z6Y10Z6CR10Z6A10_4224_NV 0x9034
475 +#define GL_Z4Y12Z4CB12Z4Y12Z4CR12_422_NV  0x9035
476 +#define GL_Z4Y12Z4CB12Z4A12Z4Y12Z4CR12Z4A12_4224_NV 0x9036
477 +#define GL_Z4Y12Z4CB12Z4CR12_444_NV       0x9037
478 +#define GL_VIDEO_CAPTURE_FRAME_WIDTH_NV   0x9038
479 +#define GL_VIDEO_CAPTURE_FRAME_HEIGHT_NV  0x9039
480 +#define GL_VIDEO_CAPTURE_FIELD_UPPER_HEIGHT_NV 0x903A
481 +#define GL_VIDEO_CAPTURE_FIELD_LOWER_HEIGHT_NV 0x903B
482 +#define GL_VIDEO_CAPTURE_SURFACE_ORIGIN_NV 0x903C
483 +#endif
484 +
485 +#ifndef GL_NV_copy_image
486 +#endif
487 +
488 +#ifndef GL_EXT_separate_shader_objects
489 +#define GL_ACTIVE_PROGRAM_EXT             0x8B8D
490 +#endif
491 +
492 +#ifndef GL_NV_parameter_buffer_object2
493 +#endif
494 +
495 +#ifndef GL_NV_shader_buffer_load
496 +#define GL_BUFFER_GPU_ADDRESS_NV          0x8F1D
497 +#define GL_GPU_ADDRESS_NV                 0x8F34
498 +#define GL_MAX_SHADER_BUFFER_ADDRESS_NV   0x8F35
499 +#endif
500 +
501 +#ifndef GL_NV_vertex_buffer_unified_memory
502 +#define GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV 0x8F1E
503 +#define GL_ELEMENT_ARRAY_UNIFIED_NV       0x8F1F
504 +#define GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV 0x8F20
505 +#define GL_VERTEX_ARRAY_ADDRESS_NV        0x8F21
506 +#define GL_NORMAL_ARRAY_ADDRESS_NV        0x8F22
507 +#define GL_COLOR_ARRAY_ADDRESS_NV         0x8F23
508 +#define GL_INDEX_ARRAY_ADDRESS_NV         0x8F24
509 +#define GL_TEXTURE_COORD_ARRAY_ADDRESS_NV 0x8F25
510 +#define GL_EDGE_FLAG_ARRAY_ADDRESS_NV     0x8F26
511 +#define GL_SECONDARY_COLOR_ARRAY_ADDRESS_NV 0x8F27
512 +#define GL_FOG_COORD_ARRAY_ADDRESS_NV     0x8F28
513 +#define GL_ELEMENT_ARRAY_ADDRESS_NV       0x8F29
514 +#define GL_VERTEX_ATTRIB_ARRAY_LENGTH_NV  0x8F2A
515 +#define GL_VERTEX_ARRAY_LENGTH_NV         0x8F2B
516 +#define GL_NORMAL_ARRAY_LENGTH_NV         0x8F2C
517 +#define GL_COLOR_ARRAY_LENGTH_NV          0x8F2D
518 +#define GL_INDEX_ARRAY_LENGTH_NV          0x8F2E
519 +#define GL_TEXTURE_COORD_ARRAY_LENGTH_NV  0x8F2F
520 +#define GL_EDGE_FLAG_ARRAY_LENGTH_NV      0x8F30
521 +#define GL_SECONDARY_COLOR_ARRAY_LENGTH_NV 0x8F31
522 +#define GL_FOG_COORD_ARRAY_LENGTH_NV      0x8F32
523 +#define GL_ELEMENT_ARRAY_LENGTH_NV        0x8F33
524 +#endif
525 +
526 +#ifndef GL_NV_texture_barrier
527 +#endif
528 +
529  
530  /*************************************************************/
531  
532 @@ -9245,6 +9327,136 @@ typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType,
533  #define GL_APPLE_row_bytes 1
534  #endif
535  
536 +#ifndef GL_APPLE_rgb_422
537 +#define GL_APPLE_rgb_422 1
538 +#endif
539 +
540 +#ifndef GL_NV_video_capture
541 +#define GL_NV_video_capture 1
542 +#ifdef GL_GLEXT_PROTOTYPES
543 +GLAPI void APIENTRY glBeginVideoCaptureNV (GLuint);
544 +GLAPI void APIENTRY glBindVideoCaptureStreamBufferNV (GLuint, GLuint, GLenum, GLintptrARB);
545 +GLAPI void APIENTRY glBindVideoCaptureStreamTextureNV (GLuint, GLuint, GLenum, GLenum, GLuint);
546 +GLAPI void APIENTRY glEndVideoCaptureNV (GLuint);
547 +GLAPI void APIENTRY glGetVideoCaptureivNV (GLuint, GLenum, GLint *);
548 +GLAPI void APIENTRY glGetVideoCaptureStreamivNV (GLuint, GLuint, GLenum, GLint *);
549 +GLAPI void APIENTRY glGetVideoCaptureStreamfvNV (GLuint, GLuint, GLenum, GLfloat *);
550 +GLAPI void APIENTRY glGetVideoCaptureStreamdvNV (GLuint, GLuint, GLenum, GLdouble *);
551 +GLAPI GLenum APIENTRY glVideoCaptureNV (GLuint, GLuint *, GLuint64EXT *);
552 +GLAPI void APIENTRY glVideoCaptureStreamParameterivNV (GLuint, GLuint, GLenum, const GLint *);
553 +GLAPI void APIENTRY glVideoCaptureStreamParameterfvNV (GLuint, GLuint, GLenum, const GLfloat *);
554 +GLAPI void APIENTRY glVideoCaptureStreamParameterdvNV (GLuint, GLuint, GLenum, const GLdouble *);
555 +#endif /* GL_GLEXT_PROTOTYPES */
556 +typedef void (APIENTRYP PFNGLBEGINVIDEOCAPTURENVPROC) (GLuint video_capture_slot);
557 +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMBUFFERNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset);
558 +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMTEXTURENVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture);
559 +typedef void (APIENTRYP PFNGLENDVIDEOCAPTURENVPROC) (GLuint video_capture_slot);
560 +typedef void (APIENTRYP PFNGLGETVIDEOCAPTUREIVNVPROC) (GLuint video_capture_slot, GLenum pname, GLint *params);
561 +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params);
562 +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params);
563 +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params);
564 +typedef GLenum (APIENTRYP PFNGLVIDEOCAPTURENVPROC) (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time);
565 +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params);
566 +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params);
567 +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params);
568 +#endif
569 +
570 +#ifndef GL_NV_copy_image
571 +#define GL_NV_copy_image 1
572 +#ifdef GL_GLEXT_PROTOTYPES
573 +GLAPI void APIENTRY glCopyImageSubDataNV (GLuint, GLenum, GLint, GLint, GLint, GLint, GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei);
574 +#endif /* GL_GLEXT_PROTOTYPES */
575 +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATANVPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
576 +#endif
577 +
578 +#ifndef GL_EXT_separate_shader_objects
579 +#define GL_EXT_separate_shader_objects 1
580 +#ifdef GL_GLEXT_PROTOTYPES
581 +GLAPI void APIENTRY glUseShaderProgramEXT (GLenum, GLuint);
582 +GLAPI void APIENTRY glActiveProgramEXT (GLuint);
583 +GLAPI GLuint APIENTRY glCreateShaderProgramEXT (GLenum, const GLchar *);
584 +#endif /* GL_GLEXT_PROTOTYPES */
585 +typedef void (APIENTRYP PFNGLUSESHADERPROGRAMEXTPROC) (GLenum type, GLuint program);
586 +typedef void (APIENTRYP PFNGLACTIVEPROGRAMEXTPROC) (GLuint program);
587 +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMEXTPROC) (GLenum type, const GLchar *string);
588 +#endif
589 +
590 +#ifndef GL_NV_parameter_buffer_object2
591 +#define GL_NV_parameter_buffer_object2 1
592 +#endif
593 +
594 +#ifndef GL_NV_shader_buffer_load
595 +#define GL_NV_shader_buffer_load 1
596 +#ifdef GL_GLEXT_PROTOTYPES
597 +GLAPI void APIENTRY glMakeBufferResidentNV (GLenum, GLenum);
598 +GLAPI void APIENTRY glMakeBufferNonResidentNV (GLenum);
599 +GLAPI GLboolean APIENTRY glIsBufferResidentNV (GLenum);
600 +GLAPI void APIENTRY glNamedMakeBufferResidentNV (GLuint, GLenum);
601 +GLAPI void APIENTRY glNamedMakeBufferNonResidentNV (GLuint);
602 +GLAPI GLboolean APIENTRY glIsNamedBufferResidentNV (GLuint);
603 +GLAPI void APIENTRY glGetBufferParameterui64vNV (GLenum, GLenum, GLuint64EXT *);
604 +GLAPI void APIENTRY glGetNamedBufferParameterui64vNV (GLuint, GLenum, GLuint64EXT *);
605 +GLAPI void APIENTRY glGetIntegerui64vNV (GLenum, GLuint64EXT *);
606 +GLAPI void APIENTRY glUniformui64NV (GLint, GLuint64EXT);
607 +GLAPI void APIENTRY glUniformui64vNV (GLint, GLsizei, const GLuint64EXT *);
608 +GLAPI void APIENTRY glGetUniformui64vNV (GLuint, GLint, GLuint64EXT *);
609 +GLAPI void APIENTRY glProgramUniformui64NV (GLuint, GLint, GLuint64EXT);
610 +GLAPI void APIENTRY glProgramUniformui64vNV (GLuint, GLint, GLsizei, const GLuint64EXT *);
611 +#endif /* GL_GLEXT_PROTOTYPES */
612 +typedef void (APIENTRYP PFNGLMAKEBUFFERRESIDENTNVPROC) (GLenum target, GLenum access);
613 +typedef void (APIENTRYP PFNGLMAKEBUFFERNONRESIDENTNVPROC) (GLenum target);
614 +typedef GLboolean (APIENTRYP PFNGLISBUFFERRESIDENTNVPROC) (GLenum target);
615 +typedef void (APIENTRYP PFNGLNAMEDMAKEBUFFERRESIDENTNVPROC) (GLuint buffer, GLenum access);
616 +typedef void (APIENTRYP PFNGLNAMEDMAKEBUFFERNONRESIDENTNVPROC) (GLuint buffer);
617 +typedef GLboolean (APIENTRYP PFNGLISNAMEDBUFFERRESIDENTNVPROC) (GLuint buffer);
618 +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERUI64VNVPROC) (GLenum target, GLenum pname, GLuint64EXT *params);
619 +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERUI64VNVPROC) (GLuint buffer, GLenum pname, GLuint64EXT *params);
620 +typedef void (APIENTRYP PFNGLGETINTEGERUI64VNVPROC) (GLenum value, GLuint64EXT *result);
621 +typedef void (APIENTRYP PFNGLUNIFORMUI64NVPROC) (GLint location, GLuint64EXT value);
622 +typedef void (APIENTRYP PFNGLUNIFORMUI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
623 +typedef void (APIENTRYP PFNGLGETUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLuint64EXT *params);
624 +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64NVPROC) (GLuint program, GLint location, GLuint64EXT value);
625 +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
626 +#endif
627 +
628 +#ifndef GL_NV_vertex_buffer_unified_memory
629 +#define GL_NV_vertex_buffer_unified_memory 1
630 +#ifdef GL_GLEXT_PROTOTYPES
631 +GLAPI void APIENTRY glBufferAddressRangeNV (GLenum, GLuint, GLuint64EXT, GLsizeiptr);
632 +GLAPI void APIENTRY glVertexFormatNV (GLint, GLenum, GLsizei);
633 +GLAPI void APIENTRY glNormalFormatNV (GLenum, GLsizei);
634 +GLAPI void APIENTRY glColorFormatNV (GLint, GLenum, GLsizei);
635 +GLAPI void APIENTRY glIndexFormatNV (GLenum, GLsizei);
636 +GLAPI void APIENTRY glTexCoordFormatNV (GLint, GLenum, GLsizei);
637 +GLAPI void APIENTRY glEdgeFlagFormatNV (GLsizei);
638 +GLAPI void APIENTRY glSecondaryColorFormatNV (GLint, GLenum, GLsizei);
639 +GLAPI void APIENTRY glFogCoordFormatNV (GLenum, GLsizei);
640 +GLAPI void APIENTRY glVertexAttribFormatNV (GLuint, GLint, GLenum, GLboolean, GLsizei);
641 +GLAPI void APIENTRY glVertexAttribIFormatNV (GLuint, GLint, GLenum, GLsizei);
642 +GLAPI void APIENTRY glGetIntegerui64i_vNV (GLenum, GLuint, GLuint64EXT *);
643 +#endif /* GL_GLEXT_PROTOTYPES */
644 +typedef void (APIENTRYP PFNGLBUFFERADDRESSRANGENVPROC) (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length);
645 +typedef void (APIENTRYP PFNGLVERTEXFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
646 +typedef void (APIENTRYP PFNGLNORMALFORMATNVPROC) (GLenum type, GLsizei stride);
647 +typedef void (APIENTRYP PFNGLCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
648 +typedef void (APIENTRYP PFNGLINDEXFORMATNVPROC) (GLenum type, GLsizei stride);
649 +typedef void (APIENTRYP PFNGLTEXCOORDFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
650 +typedef void (APIENTRYP PFNGLEDGEFLAGFORMATNVPROC) (GLsizei stride);
651 +typedef void (APIENTRYP PFNGLSECONDARYCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
652 +typedef void (APIENTRYP PFNGLFOGCOORDFORMATNVPROC) (GLenum type, GLsizei stride);
653 +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride);
654 +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride);
655 +typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
656 +#endif
657 +
658 +#ifndef GL_NV_texture_barrier
659 +#define GL_NV_texture_barrier 1
660 +#ifdef GL_GLEXT_PROTOTYPES
661 +GLAPI void APIENTRY glTextureBarrierNV (void);
662 +#endif /* GL_GLEXT_PROTOTYPES */
663 +typedef void (APIENTRYP PFNGLTEXTUREBARRIERNVPROC) (void);
664 +#endif
665 +
666  
667  #ifdef __cplusplus
668  }
669 diff --git a/include/GL/glxext.h b/include/GL/glxext.h
670 index eac09f9..9ac0592 100644
671 --- a/include/GL/glxext.h
672 +++ b/include/GL/glxext.h
673 @@ -48,9 +48,9 @@ extern "C" {
674  /*************************************************************/
675  
676  /* Header file version number, required by OpenGL ABI for Linux */
677 -/* glxext.h last updated 2009/08/03 */
678 +/* glxext.h last updated 2009/10/08 */
679  /* Current version at http://www.opengl.org/registry/ */
680 -#define GLX_GLXEXT_VERSION 23
681 +#define GLX_GLXEXT_VERSION 25
682  
683  #ifndef GLX_VERSION_1_3
684  #define GLX_WINDOW_BIT                     0x00000001
685 @@ -382,6 +382,20 @@ extern "C" {
686  #ifndef GLX_NV_swap_group
687  #endif
688  
689 +#ifndef GLX_NV_video_capture
690 +#define GLX_DEVICE_ID_NV                   0x20CD
691 +#define GLX_UNIQUE_ID_NV                   0x20CE
692 +#define GLX_NUM_VIDEO_CAPTURE_SLOTS_NV     0x20CF
693 +#endif
694 +
695 +#ifndef GLX_EXT_swap_control
696 +#define GLX_SWAP_INTERVAL_EXT              0x20F1
697 +#define GLX_MAX_SWAP_INTERVAL_EXT          0x20F2
698 +#endif
699 +
700 +#ifndef GLX_NV_copy_image
701 +#endif
702 +
703  
704  /*************************************************************/
705  
706 @@ -415,6 +429,14 @@ typedef struct {
707  } GLXBufferClobberEventSGIX;
708  #endif
709  
710 +#ifndef GLX_NV_video_output
711 +typedef unsigned int GLXVideoDeviceNV;
712 +#endif
713 +
714 +#ifndef GLX_NV_video_capture
715 +typedef XID GLXVideoCaptureDeviceNV;
716 +#endif
717 +
718  #ifndef GLEXT_64_TYPES_DEFINED
719  /* This code block is duplicated in glext.h, so must be protected */
720  #define GLEXT_64_TYPES_DEFINED
721 @@ -827,14 +849,80 @@ typedef void ( * PFNGLXRELEASETEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawab
722  
723  #ifndef GLX_NV_present_video
724  #define GLX_NV_present_video 1
725 +#ifdef GLX_GLXEXT_PROTOTYPES
726 +extern unsigned int * glXEnumerateVideoDevicesNV (Display *, int, int *);
727 +extern int glXBindVideoDeviceNV (Display *, unsigned int, unsigned int, const int *);
728 +#endif /* GLX_GLXEXT_PROTOTYPES */
729 +typedef unsigned int * ( * PFNGLXENUMERATEVIDEODEVICESNVPROC) (Display *dpy, int screen, int *nelements);
730 +typedef int ( * PFNGLXBINDVIDEODEVICENVPROC) (Display *dpy, unsigned int video_slot, unsigned int video_device, const int *attrib_list);
731  #endif
732  
733 -#ifndef GLX_NV_video_out
734 -#define GLX_NV_video_out 1
735 +#ifndef GLX_NV_video_output
736 +#define GLX_NV_video_output 1
737 +#ifdef GLX_GLXEXT_PROTOTYPES
738 +extern int glXGetVideoDeviceNV (Display *, int, int, GLXVideoDeviceNV *);
739 +extern int glXReleaseVideoDeviceNV (Display *, int, GLXVideoDeviceNV);
740 +extern int glXBindVideoImageNV (Display *, GLXVideoDeviceNV, GLXPbuffer, int);
741 +extern int glXReleaseVideoImageNV (Display *, GLXPbuffer);
742 +extern int glXSendPbufferToVideoNV (Display *, GLXPbuffer, int, unsigned long *, GLboolean);
743 +extern int glXGetVideoInfoNV (Display *, int, GLXVideoDeviceNV, unsigned long *, unsigned long *);
744 +#endif /* GLX_GLXEXT_PROTOTYPES */
745 +typedef int ( * PFNGLXGETVIDEODEVICENVPROC) (Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV *pVideoDevice);
746 +typedef int ( * PFNGLXRELEASEVIDEODEVICENVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice);
747 +typedef int ( * PFNGLXBINDVIDEOIMAGENVPROC) (Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer pbuf, int iVideoBuffer);
748 +typedef int ( * PFNGLXRELEASEVIDEOIMAGENVPROC) (Display *dpy, GLXPbuffer pbuf);
749 +typedef int ( * PFNGLXSENDPBUFFERTOVIDEONVPROC) (Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned long *pulCounterPbuffer, GLboolean bBlock);
750 +typedef int ( * PFNGLXGETVIDEOINFONVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo);
751  #endif
752  
753  #ifndef GLX_NV_swap_group
754  #define GLX_NV_swap_group 1
755 +#ifdef GLX_GLXEXT_PROTOTYPES
756 +extern Bool glXJoinSwapGroupNV (Display *, GLXDrawable, GLuint);
757 +extern Bool glXBindSwapBarrierNV (Display *, GLuint, GLuint);
758 +extern Bool glXQuerySwapGroupNV (Display *, GLXDrawable, GLuint *, GLuint *);
759 +extern Bool glXQueryMaxSwapGroupsNV (Display *, int, GLuint *, GLuint *);
760 +extern Bool glXQueryFrameCountNV (Display *, int, GLuint *);
761 +extern Bool glXResetFrameCountNV (Display *, int);
762 +#endif /* GLX_GLXEXT_PROTOTYPES */
763 +typedef Bool ( * PFNGLXJOINSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint group);
764 +typedef Bool ( * PFNGLXBINDSWAPBARRIERNVPROC) (Display *dpy, GLuint group, GLuint barrier);
765 +typedef Bool ( * PFNGLXQUERYSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint *group, GLuint *barrier);
766 +typedef Bool ( * PFNGLXQUERYMAXSWAPGROUPSNVPROC) (Display *dpy, int screen, GLuint *maxGroups, GLuint *maxBarriers);
767 +typedef Bool ( * PFNGLXQUERYFRAMECOUNTNVPROC) (Display *dpy, int screen, GLuint *count);
768 +typedef Bool ( * PFNGLXRESETFRAMECOUNTNVPROC) (Display *dpy, int screen);
769 +#endif
770 +
771 +#ifndef GLX_NV_video_capture
772 +#define GLX_NV_video_capture 1
773 +#ifdef GLX_GLXEXT_PROTOTYPES
774 +extern int glXBindVideoCaptureDeviceNV (Display *, unsigned int, GLXVideoCaptureDeviceNV);
775 +extern GLXVideoCaptureDeviceNV * glXEnumerateVideoCaptureDevicesNV (Display *, int, int *);
776 +extern void glXLockVideoCaptureDeviceNV (Display *, GLXVideoCaptureDeviceNV);
777 +extern int glXQueryVideoCaptureDeviceNV (Display *, GLXVideoCaptureDeviceNV, int, int *);
778 +extern void glXReleaseVideoCaptureDeviceNV (Display *, GLXVideoCaptureDeviceNV);
779 +#endif /* GLX_GLXEXT_PROTOTYPES */
780 +typedef int ( * PFNGLXBINDVIDEOCAPTUREDEVICENVPROC) (Display *dpy, unsigned int video_capture_slot, GLXVideoCaptureDeviceNV device);
781 +typedef GLXVideoCaptureDeviceNV * ( * PFNGLXENUMERATEVIDEOCAPTUREDEVICESNVPROC) (Display *dpy, int screen, int *nelements);
782 +typedef void ( * PFNGLXLOCKVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device);
783 +typedef int ( * PFNGLXQUERYVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device, int attribute, int *value);
784 +typedef void ( * PFNGLXRELEASEVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device);
785 +#endif
786 +
787 +#ifndef GLX_EXT_swap_control
788 +#define GLX_EXT_swap_control 1
789 +#ifdef GLX_GLXEXT_PROTOTYPES
790 +extern int glXSwapIntervalEXT (Display *, GLXDrawable, int);
791 +#endif /* GLX_GLXEXT_PROTOTYPES */
792 +typedef int ( * PFNGLXSWAPINTERVALEXTPROC) (Display *dpy, GLXDrawable drawable, int interval);
793 +#endif
794 +
795 +#ifndef GLX_NV_copy_image
796 +#define GLX_NV_copy_image 1
797 +#ifdef GLX_GLXEXT_PROTOTYPES
798 +extern void glXCopyImageSubDataNV (Display *, GLXContext, GLuint, GLenum, GLint, GLint, GLint, GLint, GLXContext, GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei);
799 +#endif /* GLX_GLXEXT_PROTOTYPES */
800 +typedef void ( * PFNGLXCOPYIMAGESUBDATANVPROC) (Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
801  #endif
802  
803  
804 diff --git a/include/GL/wglext.h b/include/GL/wglext.h
805 index 1f096fb..df96fbe 100644
806 --- a/include/GL/wglext.h
807 +++ b/include/GL/wglext.h
808 @@ -48,9 +48,9 @@ extern "C" {
809  /*************************************************************/
810  
811  /* Header file version number */
812 -/* wglext.h last updated 2009/08/03 */
813 +/* wglext.h last updated 2009/09/16 */
814  /* Current version at http://www.opengl.org/registry/ */
815 -#define WGL_WGLEXT_VERSION 15
816 +#define WGL_WGLEXT_VERSION 17
817  
818  #ifndef WGL_ARB_buffer_region
819  #define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
820 @@ -388,6 +388,14 @@ extern "C" {
821  #define WGL_GPU_NUM_SPI_AMD            0x21A8
822  #endif
823  
824 +#ifndef NV_video_capture
825 +#define WGL_UNIQUE_ID_NV               0x20CE
826 +#define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF
827 +#endif
828 +
829 +#ifndef NV_copy_image
830 +#endif
831 +
832  
833  /*************************************************************/
834  
835 @@ -400,7 +408,7 @@ DECLARE_HANDLE(HPBUFFEREXT);
836  #ifndef WGL_NV_present_video
837  DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV);
838  #endif
839 -#ifndef WGL_NV_video_out
840 +#ifndef WGL_NV_video_output
841  DECLARE_HANDLE(HPVIDEODEV);
842  #endif
843  #ifndef WGL_NV_gpu_affinity
844 @@ -415,6 +423,9 @@ typedef struct _GPU_DEVICE {
845      RECT   rcVirtualScreen;
846  } GPU_DEVICE, *PGPU_DEVICE;
847  #endif
848 +#ifndef WGL_NV_video_capture
849 +DECLARE_HANDLE(HVIDEOINPUTDEVICENV);
850 +#endif
851  
852  #ifndef WGL_ARB_buffer_region
853  #define WGL_ARB_buffer_region 1
854 @@ -750,8 +761,8 @@ typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDC, unsigned int uVide
855  typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue);
856  #endif
857  
858 -#ifndef WGL_NV_video_out
859 -#define WGL_NV_video_out 1
860 +#ifndef WGL_NV_video_output
861 +#define WGL_NV_video_output 1
862  #ifdef WGL_WGLEXT_PROTOTYPES
863  extern BOOL WINAPI wglGetVideoDeviceNV (HDC, int, HPVIDEODEV *);
864  extern BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV);
865 @@ -826,6 +837,30 @@ typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void);
866  typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
867  #endif
868  
869 +#ifndef WGL_NV_video_capture
870 +#define WGL_NV_video_capture 1
871 +#ifdef WGL_WGLEXT_PROTOTYPES
872 +extern BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT, HVIDEOINPUTDEVICENV);
873 +extern UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC, HVIDEOINPUTDEVICENV *);
874 +extern BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC, HVIDEOINPUTDEVICENV);
875 +extern BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC, HVIDEOINPUTDEVICENV, int, int *);
876 +extern BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC, HVIDEOINPUTDEVICENV);
877 +#endif /* WGL_WGLEXT_PROTOTYPES */
878 +typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice);
879 +typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList);
880 +typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
881 +typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue);
882 +typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
883 +#endif
884 +
885 +#ifndef WGL_NV_copy_image
886 +#define WGL_NV_copy_image 1
887 +#ifdef WGL_WGLEXT_PROTOTYPES
888 +extern BOOL WINAPI wglCopyImageSubDataNV (HGLRC, GLuint, GLenum, GLint, GLint, GLint, GLint, HGLRC, GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei);
889 +#endif /* WGL_WGLEXT_PROTOTYPES */
890 +typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
891 +#endif
892 +
893  
894  #ifdef __cplusplus
895  }
896 diff --git a/progs/Makefile b/progs/Makefile
897 index c99f4ee..3700707 100644
898 --- a/progs/Makefile
899 +++ b/progs/Makefile
900 @@ -15,18 +15,22 @@ message:
901  
902  
903  subdirs:
904 -       @for dir in $(SUBDIRS) ; do \
905 -               if [ -d $$dir ] ; then \
906 -                       (cd $$dir && $(MAKE)) || exit 1 ; \
907 -               fi \
908 -       done
909 +       @if test -n "$(SUBDIRS)" ; then \
910 +               for dir in $(SUBDIRS) ; do \
911 +                       if [ -d $$dir ] ; then \
912 +                               (cd $$dir && $(MAKE)) || exit 1 ; \
913 +                       fi \
914 +               done \
915 +       fi
916  
917  # Dummy install target
918  install:
919  
920  clean:
921 -       -@for dir in $(SUBDIRS) tests ; do \
922 -               if [ -d $$dir ] ; then \
923 -                       (cd $$dir && $(MAKE) clean) ; \
924 -               fi \
925 -       done
926 +       -@if test -n "$(SUBDIRS)" ; then \
927 +               for dir in $(SUBDIRS) tests ; do \
928 +                       if [ -d $$dir ] ; then \
929 +                               (cd $$dir && $(MAKE) clean) ; \
930 +                       fi \
931 +               done \
932 +       fi
933 diff --git a/progs/glsl/skinning.c b/progs/glsl/skinning.c
934 index 65ba983..2b96f31 100644
935 --- a/progs/glsl/skinning.c
936 +++ b/progs/glsl/skinning.c
937 @@ -16,6 +16,9 @@
938  #include <GL/glut.h>
939  #include "shaderutil.h"
940  
941 +#ifndef M_PI
942 +#define M_PI 3.1415926535
943 +#endif
944  
945  static char *FragProgFile = "skinning.frag";
946  static char *VertProgFile = "skinning.vert";
947 diff --git a/progs/glsl/texaaline.c b/progs/glsl/texaaline.c
948 index 7a5ac40..2e4f932 100644
949 --- a/progs/glsl/texaaline.c
950 +++ b/progs/glsl/texaaline.c
951 @@ -14,6 +14,9 @@
952  #include <GL/glew.h>
953  #include <GL/glut.h>
954  
955 +#ifndef M_PI
956 +#define M_PI 3.1415926535
957 +#endif
958  
959  static GLint WinWidth = 300, WinHeight = 300;
960  static GLint win = 0;
961 diff --git a/progs/glsl/twoside.c b/progs/glsl/twoside.c
962 index a57484f..ce155d6 100644
963 --- a/progs/glsl/twoside.c
964 +++ b/progs/glsl/twoside.c
965 @@ -16,6 +16,9 @@
966  #include <GL/glut.h>
967  #include "shaderutil.h"
968  
969 +#ifndef M_PI
970 +#define M_PI 3.1415926535
971 +#endif
972  
973  static GLint WinWidth = 300, WinHeight = 300;
974  static char *FragProgFile = NULL;
975 diff --git a/progs/tests/blitfb.c b/progs/tests/blitfb.c
976 new file mode 100644
977 index 0000000..18c8380
978 --- /dev/null
979 +++ b/progs/tests/blitfb.c
980 @@ -0,0 +1,259 @@
981 +/**
982 + * Test glFramebufferBlit()
983 + * Brian Paul
984 + * 27 Oct 2009
985 + */
986 +
987 +#include <assert.h>
988 +#include <stdio.h>
989 +#include <stdlib.h>
990 +#include <string.h>
991 +#include <math.h>
992 +#include <GL/glew.h>
993 +#include <GL/glut.h>
994 +
995 +
996 +static int Win;
997 +static int WinWidth = 1100, WinHeight = 600;
998 +
999 +static int SrcWidth = 512, SrcHeight = 512;
1000 +static int DstWidth = 512, DstHeight = 512;
1001 +
1002 +static GLuint SrcFB, DstFB;
1003 +static GLuint SrcTex, DstTex;
1004 +
1005 +#if 0
1006 +static GLenum SrcTexTarget = GL_TEXTURE_2D, SrcTexFace = GL_TEXTURE_2D;
1007 +#else
1008 +static GLenum SrcTexTarget = GL_TEXTURE_CUBE_MAP, SrcTexFace = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
1009 +#endif
1010 +
1011 +static GLenum DstTexTarget = GL_TEXTURE_2D, DstTexFace = GL_TEXTURE_2D;
1012 +
1013 +static GLuint SrcTexLevel = 01, DstTexLevel = 0;
1014 +
1015 +
1016 +static void
1017 +Draw(void)
1018 +{
1019 +   GLboolean rp = GL_FALSE;
1020 +   GLubyte *buf;
1021 +   GLint srcWidth = SrcWidth >> SrcTexLevel;
1022 +   GLint srcHeight = SrcHeight >> SrcTexLevel;
1023 +   GLint dstWidth = DstWidth >> DstTexLevel;
1024 +   GLint dstHeight = DstHeight >> DstTexLevel;
1025 +   GLenum status;
1026 +
1027 +   /* clear window */
1028 +   glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
1029 +   glClearColor(0.5, 0.5, 0.5, 1.0);
1030 +   glClear(GL_COLOR_BUFFER_BIT);
1031 +
1032 +
1033 +   /* clear src buf */
1034 +   glBindFramebufferEXT(GL_FRAMEBUFFER, SrcFB);
1035 +   status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
1036 +   assert(status == GL_FRAMEBUFFER_COMPLETE_EXT);
1037 +   glClearColor(0, 1, 0, 0);
1038 +   glClear(GL_COLOR_BUFFER_BIT);
1039 +
1040 +   /* clear dst buf */
1041 +   glBindFramebufferEXT(GL_FRAMEBUFFER, DstFB);
1042 +   status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
1043 +   assert(status == GL_FRAMEBUFFER_COMPLETE_EXT);
1044 +   glClearColor(1, 0, 0, 0);
1045 +   glClear(GL_COLOR_BUFFER_BIT);
1046 +
1047 +   /* blit src -> dst */
1048 +   glBindFramebufferEXT(GL_READ_FRAMEBUFFER, SrcFB);
1049 +   glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, DstFB);
1050 +   glBlitFramebufferEXT(0, 0, srcWidth, srcHeight,
1051 +                        0, 0, dstWidth, dstHeight,
1052 +                        GL_COLOR_BUFFER_BIT, GL_NEAREST);
1053 +
1054 +#if 01
1055 +   /* read src results */
1056 +   buf = malloc(4 * srcWidth * srcHeight);
1057 +   memset(buf, 0x88, 4 * srcWidth * srcHeight);
1058 +   glBindFramebufferEXT(GL_FRAMEBUFFER, SrcFB);
1059 +   if (rp)
1060 +      glReadPixels(0, 0, srcWidth, srcHeight, GL_RGBA, GL_UNSIGNED_BYTE, buf);
1061 +   else {
1062 +      glBindTexture(SrcTexTarget, SrcTex);
1063 +      glGetTexImage(SrcTexFace, SrcTexLevel, GL_RGBA, GL_UNSIGNED_BYTE, buf);
1064 +   }
1065 +
1066 +   /* draw dst in window */
1067 +   glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
1068 +   glWindowPos2i(0, 0);
1069 +   glDrawPixels(srcWidth, srcHeight, GL_RGBA, GL_UNSIGNED_BYTE, buf);
1070 +
1071 +   printf("Src Pix[0] = %d %d %d %d\n", buf[0], buf[1], buf[2], buf[3]);
1072 +   free(buf);
1073 +#endif
1074 +
1075 +   glFinish();
1076 +
1077 +   /* read dst results */
1078 +   buf = malloc(4 * dstWidth * dstHeight);
1079 +   memset(buf, 0x88, 4 * dstWidth * dstHeight);
1080 +   glBindFramebufferEXT(GL_FRAMEBUFFER, DstFB);
1081 +   if (rp)
1082 +      glReadPixels(0, 0, dstWidth, dstHeight, GL_RGBA, GL_UNSIGNED_BYTE, buf);
1083 +   else {
1084 +      glBindTexture(DstTexTarget, DstTex);
1085 +      glGetTexImage(DstTexFace, DstTexLevel, GL_RGBA, GL_UNSIGNED_BYTE, buf);
1086 +   }
1087 +
1088 +   /* draw dst in window */
1089 +   glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
1090 +   glWindowPos2i(srcWidth + 2, 0);
1091 +   glDrawPixels(dstWidth, dstHeight, GL_RGBA, GL_UNSIGNED_BYTE, buf);
1092 +
1093 +   printf("Dst Pix[0] = %d %d %d %d\n", buf[0], buf[1], buf[2], buf[3]);
1094 +   free(buf);
1095 +
1096 +   glFinish();
1097 +
1098 +   glutSwapBuffers();
1099 +}
1100 +
1101 +
1102 +static void
1103 +Reshape(int width, int height)
1104 +{
1105 +   WinWidth = width;
1106 +   WinHeight = height;
1107 +   glViewport(0, 0, width, height);
1108 +   glMatrixMode(GL_PROJECTION);
1109 +   glLoadIdentity();
1110 +   glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
1111 +   glMatrixMode(GL_MODELVIEW);
1112 +   glLoadIdentity();
1113 +   glTranslatef(0.0, 0.0, -15.0);
1114 +}
1115 +
1116 +
1117 +static void
1118 +Key(unsigned char key, int x, int y)
1119 +{
1120 +   (void) x;
1121 +   (void) y;
1122 +   switch (key) {
1123 +   case 27:
1124 +      glutDestroyWindow(Win);
1125 +      exit(0);
1126 +      break;
1127 +   }
1128 +   glutPostRedisplay();
1129 +}
1130 +
1131 +
1132 +static void
1133 +SpecialKey(int key, int x, int y)
1134 +{
1135 +   (void) x;
1136 +   (void) y;
1137 +   switch (key) {
1138 +   }
1139 +   glutPostRedisplay();
1140 +}
1141 +
1142 +
1143 +static void
1144 +InitFBOs(void)
1145 +{
1146 +   GLuint w, h, lvl;
1147 +
1148 +   /* Src */
1149 +   glGenTextures(1, &SrcTex);
1150 +   glBindTexture(SrcTexTarget, SrcTex);
1151 +   w = SrcWidth;
1152 +   h = SrcHeight;
1153 +   lvl = 0;
1154 +   for (lvl = 0; ; lvl++) {
1155 +      if (SrcTexTarget == GL_TEXTURE_CUBE_MAP) {
1156 +         GLuint f;
1157 +         for (f = 0; f < 6; f++) {
1158 +            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, lvl, GL_RGBA8,
1159 +                         w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1160 +         }
1161 +      }
1162 +      else {
1163 +         /* single face */
1164 +         glTexImage2D(SrcTexFace, lvl, GL_RGBA8, w, h, 0,
1165 +                      GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1166 +      }
1167 +      if (w == 1 && h == 1)
1168 +         break;
1169 +      if (w > 1)
1170 +         w /= 2;
1171 +      if (h > 1)
1172 +         h /= 2;
1173 +   }
1174 +
1175 +   glGenFramebuffersEXT(1, &SrcFB);
1176 +   glBindFramebufferEXT(GL_FRAMEBUFFER, SrcFB);
1177 +   glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
1178 +                             SrcTexFace, SrcTex, SrcTexLevel);
1179 +
1180 +   /* Dst */
1181 +   glGenTextures(1, &DstTex);
1182 +   glBindTexture(DstTexTarget, DstTex);
1183 +   w = DstWidth;
1184 +   h = DstHeight;
1185 +   lvl = 0;
1186 +   for (lvl = 0; ; lvl++) {
1187 +      glTexImage2D(DstTexFace, lvl, GL_RGBA8, w, h, 0,
1188 +                   GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1189 +      if (w == 1 && h == 1)
1190 +         break;
1191 +      if (w > 1)
1192 +         w /= 2;
1193 +      if (h > 1)
1194 +         h /= 2;
1195 +   }
1196 +
1197 +   glGenFramebuffersEXT(1, &DstFB);
1198 +   glBindFramebufferEXT(GL_FRAMEBUFFER, DstFB);
1199 +   glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
1200 +                             DstTexFace, DstTex, DstTexLevel);
1201 +}
1202 +
1203 +
1204 +static void
1205 +Init(void)
1206 +{
1207 +   if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
1208 +      fprintf(stderr, "This test requires GL_EXT_framebuffer_object\n");
1209 +      exit(1);
1210 +   }
1211 +
1212 +   if (!glutExtensionSupported("GL_EXT_framebuffer_blit")) {
1213 +      fprintf(stderr, "This test requires GL_EXT_framebuffer_blit,\n");
1214 +      exit(1);
1215 +   }
1216 +
1217 +   InitFBOs();
1218 +
1219 +   printf("Left rect = src FBO, Right rect = dst FBO.\n");
1220 +   printf("Both should be green.\n");
1221 +}
1222 +
1223 +
1224 +int
1225 +main(int argc, char *argv[])
1226 +{
1227 +   glutInit(&argc, argv);
1228 +   glutInitWindowSize(WinWidth, WinHeight);
1229 +   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
1230 +   Win = glutCreateWindow(argv[0]);
1231 +   glewInit();
1232 +   glutReshapeFunc(Reshape);
1233 +   glutKeyboardFunc(Key);
1234 +   glutSpecialFunc(SpecialKey);
1235 +   glutDisplayFunc(Draw);
1236 +   Init();
1237 +   glutMainLoop();
1238 +   return 0;
1239 +}
1240 diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c
1241 index 34167d3..da87306 100644
1242 --- a/progs/xdemos/glsync.c
1243 +++ b/progs/xdemos/glsync.c
1244 @@ -95,7 +95,7 @@ enum sync_type {
1245  static void usage(char *name)
1246  {
1247         printf("usage: %s [-w <width>] [-h <height>] [-s<sync method>] "
1248 -              "[-vc]\n", name);
1249 +              "[-v]\n", name);
1250         printf("\t-s<sync method>:\n");
1251         printf("\t\tn: none\n");
1252         printf("\t\ts: SGI video sync extension\n");
1253 diff --git a/progs/xdemos/pbdemo.c b/progs/xdemos/pbdemo.c
1254 index 7db0017..2573209 100644
1255 --- a/progs/xdemos/pbdemo.c
1256 +++ b/progs/xdemos/pbdemo.c
1257 @@ -143,7 +143,7 @@ MakePbuffer( Display *dpy, int screen, int width, int height )
1258  
1259        /* Create the pbuffer using first fbConfig in the list that works. */
1260        for (i=0;i<nConfigs;i++) {
1261 -         pBuffer = CreatePbuffer(dpy, screen, fbConfigs[i], width, height, preserve, largest);
1262 +         pBuffer = CreatePbuffer(dpy, screen, fbConfigs[i], width, height, largest, preserve);
1263           if (pBuffer) {
1264              gFBconfig = fbConfigs[i];
1265              gWidth = width;
1266 @@ -210,6 +210,21 @@ Setup(int width, int height)
1267        return 0;
1268     }
1269  
1270 +   /* Test drawable queries */
1271 +   {
1272 +      unsigned int v;
1273 +      glXQueryDrawable( gDpy, gPBuffer, GLX_WIDTH, &v);
1274 +      printf("GLX_WIDTH = %u\n", v);
1275 +      glXQueryDrawable( gDpy, gPBuffer, GLX_HEIGHT, &v);
1276 +      printf("GLX_HEIGHT = %u\n", v);
1277 +      glXQueryDrawable( gDpy, gPBuffer, GLX_PRESERVED_CONTENTS, &v);
1278 +      printf("GLX_PRESERVED_CONTENTS = %u\n", v);
1279 +      glXQueryDrawable( gDpy, gPBuffer, GLX_LARGEST_PBUFFER, &v);
1280 +      printf("GLX_LARGEST_PBUFFER = %u\n", v);
1281 +      glXQueryDrawable( gDpy, gPBuffer, GLX_FBCONFIG_ID, &v);
1282 +      printf("GLX_FBCONFIG_ID = %u\n", v);
1283 +   }
1284 +
1285     /* Get corresponding XVisualInfo */
1286     visInfo = GetVisualFromFBConfig(gDpy, gScreen, gFBconfig);
1287     if (!visInfo) {
1288 diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
1289 index 36c882a..4f13b3e 100644
1290 --- a/src/gallium/auxiliary/cso_cache/cso_context.c
1291 +++ b/src/gallium/auxiliary/cso_cache/cso_context.c
1292 @@ -268,7 +268,7 @@ void cso_release_all( struct cso_context *ctx )
1293  void cso_destroy_context( struct cso_context *ctx )
1294  {
1295     if (ctx) {
1296 -      //cso_release_all( ctx );
1297 +      /*cso_release_all( ctx );*/
1298        FREE( ctx );
1299     }
1300  }
1301 diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
1302 index 44147ae..734c05f 100644
1303 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
1304 +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
1305 @@ -212,17 +212,10 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
1306        struct draw_vertex_shader *vs = draw->vs.vertex_shader;
1307        vs->prepare(vs, draw);
1308     }
1309 -   
1310 -
1311 -   //return TRUE;
1312  }
1313  
1314  
1315  
1316 -
1317 -
1318 -
1319 -
1320  static void fse_run_linear( struct draw_pt_middle_end *middle, 
1321                              unsigned start, 
1322                              unsigned count )
1323 diff --git a/src/gallium/auxiliary/draw/draw_pt_post_vs.c b/src/gallium/auxiliary/draw/draw_pt_post_vs.c
1324 index 00d7197..78953bc 100644
1325 --- a/src/gallium/auxiliary/draw/draw_pt_post_vs.c
1326 +++ b/src/gallium/auxiliary/draw/draw_pt_post_vs.c
1327 @@ -210,7 +210,7 @@ void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
1328          pvs->run = post_vs_viewport;
1329     }
1330     else {
1331 -      //if (opengl) 
1332 +      /* if (opengl) */
1333        pvs->run = post_vs_cliptest_viewport_gl;
1334     }
1335  }
1336 diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache.c b/src/gallium/auxiliary/draw/draw_pt_vcache.c
1337 index 1a0527b..d3f179c 100644
1338 --- a/src/gallium/auxiliary/draw/draw_pt_vcache.c
1339 +++ b/src/gallium/auxiliary/draw/draw_pt_vcache.c
1340 @@ -394,6 +394,7 @@ vcache_check_run( struct draw_pt_front_end *frontend,
1341  
1342           default:
1343              assert(0);
1344 +            FREE(storage);
1345              return;
1346           }
1347        }
1348 @@ -422,6 +423,7 @@ vcache_check_run( struct draw_pt_front_end *frontend,
1349  
1350           default:
1351              assert(0);
1352 +            FREE(storage);
1353              return;
1354           }
1355        }
1356 diff --git a/src/gallium/auxiliary/draw/draw_vs_aos.c b/src/gallium/auxiliary/draw/draw_vs_aos.c
1357 index 62e04a6..645d7cc 100644
1358 --- a/src/gallium/auxiliary/draw/draw_vs_aos.c
1359 +++ b/src/gallium/auxiliary/draw/draw_vs_aos.c
1360 @@ -891,7 +891,7 @@ static void x87_emit_ex2( struct aos_compilation *cp )
1361     struct x86_reg st1 = x86_make_reg(file_x87, 1);
1362     int stack = cp->func->x87_stack;
1363  
1364 -//   set_fpu_round_neg_inf( cp );
1365 +   /* set_fpu_round_neg_inf( cp ); */
1366  
1367     x87_fld(cp->func, st0);      /* a a */
1368     x87_fprndint( cp->func );   /* int(a) a*/
1369 @@ -1759,14 +1759,14 @@ emit_instruction( struct aos_compilation *cp,
1370        return emit_SUB(cp, inst);
1371   
1372     case TGSI_OPCODE_LRP:
1373 -//      return emit_LERP(cp, inst);
1374 +      /*return emit_LERP(cp, inst);*/
1375        return FALSE;
1376  
1377     case TGSI_OPCODE_FRC:
1378        return emit_FRC(cp, inst);
1379  
1380     case TGSI_OPCODE_CLAMP:
1381 -//      return emit_CLAMP(cp, inst);
1382 +      /*return emit_CLAMP(cp, inst);*/
1383        return FALSE;
1384  
1385     case TGSI_OPCODE_FLR:
1386 diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
1387 index 109ac7c..0d30363 100644
1388 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
1389 +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
1390 @@ -584,7 +584,7 @@ fenced_buffer_list_destroy(struct fenced_buffer_list *fenced_list)
1391     }
1392  
1393  #ifdef DEBUG
1394 -   //assert(!fenced_list->numUnfenced);
1395 +   /*assert(!fenced_list->numUnfenced);*/
1396  #endif
1397        
1398     pipe_mutex_unlock(fenced_list->mutex);
1399 diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c
1400 index 8d39b64..266e7ee 100644
1401 --- a/src/gallium/auxiliary/translate/translate_generic.c
1402 +++ b/src/gallium/auxiliary/translate/translate_generic.c
1403 @@ -217,7 +217,7 @@ ATTRIB( R8G8_SNORM,      2, char, FROM_8_SNORM, TO_8_SNORM )
1404  ATTRIB( R8_SNORM,        1, char, FROM_8_SNORM, TO_8_SNORM )
1405  
1406  ATTRIB( A8R8G8B8_UNORM,       4, ubyte, FROM_8_UNORM, TO_8_UNORM )
1407 -//ATTRIB( R8G8B8A8_UNORM,       4, ubyte, FROM_8_UNORM, TO_8_UNORM )
1408 +/*ATTRIB( R8G8B8A8_UNORM,       4, ubyte, FROM_8_UNORM, TO_8_UNORM )*/
1409  
1410  ATTRIB( R32G32B32A32_FIXED,   4, int, FROM_32_FIXED, TO_32_FIXED )
1411  ATTRIB( R32G32B32_FIXED,      3, int, FROM_32_FIXED, TO_32_FIXED )
1412 diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c
1413 index d9f2f8f..f78706f 100644
1414 --- a/src/gallium/auxiliary/util/u_cpu_detect.c
1415 +++ b/src/gallium/auxiliary/util/u_cpu_detect.c
1416 @@ -268,7 +268,7 @@ static void check_os_katmai_support(void)
1417          * and therefore to be safe I'm going to leave this test in here.
1418          */
1419         if (__cpu_detect_caps.hasSSE) {
1420 -               //      test_os_katmai_exception_support();
1421 +           /* test_os_katmai_exception_support(); */
1422         }
1423  
1424         /* Restore the original signal handlers.
1425 diff --git a/src/gallium/auxiliary/util/u_debug_profile.c b/src/gallium/auxiliary/util/u_debug_profile.c
1426 index 6d8b244..d765b50 100644
1427 --- a/src/gallium/auxiliary/util/u_debug_profile.c
1428 +++ b/src/gallium/auxiliary/util/u_debug_profile.c
1429 @@ -254,7 +254,7 @@ debug_profile_start(void)
1430  {
1431     WCHAR *p;
1432  
1433 -   // increment starting from the less significant digit
1434 +   /* increment starting from the less significant digit */
1435     p = &wFileName[14];
1436     while(1) {
1437        if(*p == '9') {
1438 diff --git a/src/gallium/auxiliary/util/u_debug_symbol.c b/src/gallium/auxiliary/util/u_debug_symbol.c
1439 index 811931f..417d0cf 100644
1440 --- a/src/gallium/auxiliary/util/u_debug_symbol.c
1441 +++ b/src/gallium/auxiliary/util/u_debug_symbol.c
1442 @@ -214,7 +214,7 @@ debug_symbol_print_imagehlp(const void *addr)
1443     HANDLE hProcess;
1444     BYTE symbolBuffer[1024];
1445     PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL) symbolBuffer;
1446 -   DWORD dwDisplacement = 0;  // Displacement of the input address, relative to the start of the symbol
1447 +   DWORD dwDisplacement = 0;  /* Displacement of the input address, relative to the start of the symbol */
1448  
1449     hProcess = GetCurrentProcess();
1450  
1451 diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
1452 index 4e3d35f..aa823aa 100644
1453 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c
1454 +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
1455 @@ -1427,6 +1427,7 @@ set_vertex_data(struct gen_mipmap_state *ctx,
1456              rz = -1.0f;
1457              break;
1458           default:
1459 +            rx = ry = rz = 0.0f;
1460              assert(0);
1461           }
1462  
1463 diff --git a/src/gallium/drivers/cell/ppu/cell_gen_fp.c b/src/gallium/drivers/cell/ppu/cell_gen_fp.c
1464 index 312621f..b6b2f88 100644
1465 --- a/src/gallium/drivers/cell/ppu/cell_gen_fp.c
1466 +++ b/src/gallium/drivers/cell/ppu/cell_gen_fp.c
1467 @@ -674,7 +674,7 @@ emit_MAD(struct codegen *gen, const struct tgsi_full_instruction *inst)
1468   * Emit linear interpolate.  See emit_ADD for comments.
1469   */
1470  static boolean
1471 -emit_LERP(struct codegen *gen, const struct tgsi_full_instruction *inst)
1472 +emit_LRP(struct codegen *gen, const struct tgsi_full_instruction *inst)
1473  {
1474     int ch, s1_reg[4], s2_reg[4], s3_reg[4], d_reg[4], tmp_reg[4];
1475  
1476 @@ -1766,7 +1766,7 @@ emit_instruction(struct codegen *gen,
1477        return emit_binop(gen, inst);
1478     case TGSI_OPCODE_MAD:
1479        return emit_MAD(gen, inst);
1480 -   case TGSI_OPCODE_LERP:
1481 +   case TGSI_OPCODE_LRP:
1482        return emit_LRP(gen, inst);
1483     case TGSI_OPCODE_DP3:
1484        return emit_DP3(gen, inst);
1485 diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c
1486 index 86df320..b4650c0 100644
1487 --- a/src/gallium/drivers/softpipe/sp_context.c
1488 +++ b/src/gallium/drivers/softpipe/sp_context.c
1489 @@ -105,12 +105,17 @@ static void softpipe_destroy( struct pipe_context *pipe )
1490        softpipe->quad[i].output->destroy( softpipe->quad[i].output );
1491     }
1492  
1493 -   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
1494 +   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
1495        sp_destroy_tile_cache(softpipe->cbuf_cache[i]);
1496 +      pipe_surface_reference(&softpipe->framebuffer.cbufs[i], NULL);
1497 +   }
1498     sp_destroy_tile_cache(softpipe->zsbuf_cache);
1499 +   pipe_surface_reference(&softpipe->framebuffer.zsbuf, NULL);
1500  
1501 -   for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
1502 +   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
1503        sp_destroy_tile_cache(softpipe->tex_cache[i]);
1504 +      pipe_texture_reference(&softpipe->texture[i], NULL);
1505 +   }
1506  
1507     for (i = 0; i < Elements(softpipe->constants); i++) {
1508        if (softpipe->constants[i].buffer) {
1509 diff --git a/src/gallium/drivers/softpipe/sp_fs_sse.c b/src/gallium/drivers/softpipe/sp_fs_sse.c
1510 index f4fa090..31ccc3b 100644
1511 --- a/src/gallium/drivers/softpipe/sp_fs_sse.c
1512 +++ b/src/gallium/drivers/softpipe/sp_fs_sse.c
1513 @@ -101,7 +101,7 @@ fs_sse_run( const struct sp_fragment_shader *base,
1514                  machine->Consts,
1515                   (const float (*)[4])shader->immediates,
1516                  machine->InterpCoefs
1517 -                //      , &machine->QuadPos
1518 +                /*, &machine->QuadPos*/
1519        );
1520  
1521     return ~(machine->Temps[TGSI_EXEC_TEMP_KILMASK_I].xyzw[TGSI_EXEC_TEMP_KILMASK_C].u[0]);
1522 diff --git a/src/gallium/drivers/softpipe/sp_state_surface.c b/src/gallium/drivers/softpipe/sp_state_surface.c
1523 index 7c06d86..181bff8 100644
1524 --- a/src/gallium/drivers/softpipe/sp_state_surface.c
1525 +++ b/src/gallium/drivers/softpipe/sp_state_surface.c
1526 @@ -56,7 +56,7 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
1527           sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
1528  
1529           /* assign new */
1530 -         sp->framebuffer.cbufs[i] = fb->cbufs[i];
1531 +         pipe_surface_reference(&sp->framebuffer.cbufs[i], fb->cbufs[i]);
1532  
1533           /* update cache */
1534           sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]);
1535 @@ -71,7 +71,7 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
1536        sp_flush_tile_cache(sp, sp->zsbuf_cache);
1537  
1538        /* assign new */
1539 -      sp->framebuffer.zsbuf = fb->zsbuf;
1540 +      pipe_surface_reference(&sp->framebuffer.zsbuf, fb->zsbuf);
1541  
1542        /* update cache */
1543        sp_tile_cache_set_surface(sp->zsbuf_cache, fb->zsbuf);
1544 diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c
1545 index 461cbb9..b2195ec 100644
1546 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c
1547 +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c
1548 @@ -130,6 +130,16 @@ sp_create_tile_cache( struct pipe_screen *screen )
1549           tc->entries[pos].x =
1550           tc->entries[pos].y = -1;
1551        }
1552 +
1553 +      /* XXX this code prevents valgrind warnings about use of uninitialized
1554 +       * memory in programs that don't clear the surface before rendering.
1555 +       * However, it breaks clearing in other situations (such as in
1556 +       * progs/tests/drawbuffers, see bug 24402).
1557 +       */
1558 +#if 0 && TILE_CLEAR_OPTIMIZATION
1559 +      /* set flags to indicate all the tiles are cleared */
1560 +      memset(tc->clear_flags, 255, sizeof(tc->clear_flags));
1561 +#endif
1562     }
1563     return tc;
1564  }
1565 diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c
1566 index d1a98f8..f2881b9 100644
1567 --- a/src/gallium/state_trackers/glx/xlib/glx_api.c
1568 +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c
1569 @@ -850,10 +850,10 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
1570              if (!fbConfig)
1571                 return NULL;
1572              parselist++;
1573 -            if (*parselist == GLX_RGBA_BIT) {
1574 +            if (*parselist & GLX_RGBA_BIT) {
1575                 rgb_flag = GL_TRUE;
1576              }
1577 -            else if (*parselist == GLX_COLOR_INDEX_BIT) {
1578 +            else if (*parselist & GLX_COLOR_INDEX_BIT) {
1579                 rgb_flag = GL_FALSE;
1580              }
1581              else if (*parselist == 0) {
1582 @@ -1309,13 +1309,17 @@ glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1583  
1584  
1585  Bool
1586 -glXQueryExtension( Display *dpy, int *errorb, int *event )
1587 +glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
1588  {
1589 +   int op, ev, err;
1590     /* Mesa's GLX isn't really an X extension but we try to act like one. */
1591 -   (void) dpy;
1592 -   (void) errorb;
1593 -   (void) event;
1594 -   return True;
1595 +   if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err))
1596 +      ev = err = 0;
1597 +   if (errorBase)
1598 +      *errorBase = err;
1599 +   if (eventBase)
1600 +      *eventBase = ev;
1601 +   return True; /* we're faking GLX so always return success */
1602  }
1603  
1604  
1605 @@ -1990,32 +1994,42 @@ glXCreatePbuffer( Display *dpy, GLXFBConfig config,
1606              break;
1607           case GLX_PRESERVED_CONTENTS:
1608              attrib++;
1609 -            preserveContents = *attrib; /* ignored */
1610 +            preserveContents = *attrib;
1611              break;
1612           case GLX_LARGEST_PBUFFER:
1613              attrib++;
1614 -            useLargest = *attrib; /* ignored */
1615 +            useLargest = *attrib;
1616              break;
1617           default:
1618              return 0;
1619        }
1620     }
1621  
1622 -   /* not used at this time */
1623 -   (void) useLargest;
1624 -   (void) preserveContents;
1625 -
1626     if (width == 0 || height == 0)
1627        return 0;
1628  
1629 +   if (width > MAX_WIDTH || height > MAX_HEIGHT) {
1630 +      /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
1631 +       * allocate the largest possible buffer.
1632 +       */
1633 +      if (useLargest) {
1634 +         width = MAX_WIDTH;
1635 +         height = MAX_HEIGHT;
1636 +      }
1637 +   }
1638 +
1639     xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
1640     /* A GLXPbuffer handle must be an X Drawable because that's what
1641      * glXMakeCurrent takes.
1642      */
1643 -   if (xmbuf)
1644 +   if (xmbuf) {
1645 +      xmbuf->largestPbuffer = useLargest;
1646 +      xmbuf->preservedContents = preserveContents;
1647        return (GLXPbuffer) xmbuf->drawable;
1648 -   else
1649 +   }
1650 +   else {
1651        return 0;
1652 +   }
1653  }
1654  
1655  
1656 @@ -2033,22 +2047,26 @@ void
1657  glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
1658                         unsigned int *value )
1659  {
1660 +   GLuint width, height;
1661     XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
1662     if (!xmbuf)
1663        return;
1664  
1665 +   /* make sure buffer's dimensions are up to date */
1666 +   xmesa_get_window_size(dpy, xmbuf, &width, &height);
1667 +
1668     switch (attribute) {
1669        case GLX_WIDTH:
1670 -         *value = xmesa_buffer_width(xmbuf);
1671 +         *value = width;
1672           break;
1673        case GLX_HEIGHT:
1674 -         *value = xmesa_buffer_width(xmbuf);
1675 +         *value = height;
1676           break;
1677        case GLX_PRESERVED_CONTENTS:
1678 -         *value = True;
1679 +         *value = xmbuf->preservedContents;
1680           break;
1681        case GLX_LARGEST_PBUFFER:
1682 -         *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf);
1683 +         *value = xmbuf->largestPbuffer;
1684           break;
1685        case GLX_FBCONFIG_ID:
1686           *value = xmbuf->xm_visual->visinfo->visualid;
1687 @@ -2120,9 +2138,9 @@ glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
1688        break;
1689     case GLX_RENDER_TYPE:
1690        if (xmctx->xm_visual->mesa_visual.rgbMode)
1691 -         *value = GLX_RGBA_BIT;
1692 +         *value = GLX_RGBA_TYPE;
1693        else
1694 -         *value = GLX_COLOR_INDEX_BIT;
1695 +         *value = GLX_COLOR_INDEX_TYPE;
1696        break;
1697     case GLX_SCREEN:
1698        *value = 0;
1699 diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c
1700 index 957002d..c76dfb3 100644
1701 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c
1702 +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c
1703 @@ -228,7 +228,7 @@ get_drawable_size( Display *dpy, Drawable d, uint *width, uint *height )
1704   * \param width  returns width in pixels
1705   * \param height  returns height in pixels
1706   */
1707 -static void
1708 +void
1709  xmesa_get_window_size(Display *dpy, XMesaBuffer b,
1710                        GLuint *width, GLuint *height)
1711  {
1712 diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h
1713 index ce97a3e..d24971c 100644
1714 --- a/src/gallium/state_trackers/glx/xlib/xm_api.h
1715 +++ b/src/gallium/state_trackers/glx/xlib/xm_api.h
1716 @@ -323,6 +323,9 @@ struct xmesa_buffer {
1717     Colormap cmap;              /* the X colormap */
1718     BufferType type;             /* window, pixmap, pbuffer or glxwindow */
1719  
1720 +   GLboolean largestPbuffer;    /**< for pbuffers */
1721 +   GLboolean preservedContents; /**< for pbuffers */
1722 +
1723     XImage *tempImage;
1724     unsigned long selectedEvents;/* for pbuffers only */
1725  
1726 @@ -370,6 +373,10 @@ extern XMesaBuffer
1727  xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis);
1728  
1729  extern void
1730 +xmesa_get_window_size(Display *dpy, XMesaBuffer b,
1731 +                      GLuint *width, GLuint *height);
1732 +
1733 +extern void
1734  xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer);
1735  
1736  extern void
1737 diff --git a/src/glx/x11/dri_glx.c b/src/glx/x11/dri_glx.c
1738 index ab24bd8..4f7acb6 100644
1739 --- a/src/glx/x11/dri_glx.c
1740 +++ b/src/glx/x11/dri_glx.c
1741 @@ -596,8 +596,10 @@ driCreateDrawable(__GLXscreenConfigs * psc,
1742     pdraw->drawable = drawable;
1743     pdraw->psc = psc;
1744  
1745 -   if (!XF86DRICreateDrawable(psc->dpy, psc->scr, drawable, &hwDrawable))
1746 +   if (!XF86DRICreateDrawable(psc->dpy, psc->scr, drawable, &hwDrawable)) {
1747 +      Xfree(pdraw);
1748        return NULL;
1749 +   }
1750  
1751     /* Create a new drawable */
1752     pdraw->driDrawable =
1753 diff --git a/src/glx/x11/glxcmds.c b/src/glx/x11/glxcmds.c
1754 index ea55cc4..c63116b 100644
1755 --- a/src/glx/x11/glxcmds.c
1756 +++ b/src/glx/x11/glxcmds.c
1757 @@ -398,6 +398,10 @@ CreateContext(Display * dpy, XVisualInfo * vis,
1758                 _XError(dpy, &error);
1759                 return None;
1760              }
1761 +            if (renderType == 0) {
1762 +               /* Initialize renderType now */
1763 +               renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE;
1764 +            }
1765           }
1766           else {
1767              mode = fbconfig;
1768 @@ -484,6 +488,8 @@ CreateContext(Display * dpy, XVisualInfo * vis,
1769        gc->imported = GL_TRUE;
1770     }
1771  
1772 +   gc->renderType = renderType;
1773 +
1774     return gc;
1775  }
1776  
1777 @@ -534,6 +540,16 @@ DestroyContext(Display * dpy, GLXContext gc)
1778     imported = gc->imported;
1779     gc->xid = None;
1780  
1781 +   if (gc->currentDpy) {
1782 +      /* This context is bound to some thread.  According to the man page,
1783 +       * we should not actually delete the context until it's unbound.
1784 +       * Note that we set gc->xid = None above.  In MakeContextCurrent()
1785 +       * we check for that and delete the context there.
1786 +       */
1787 +      __glXUnlock();
1788 +      return;
1789 +   }
1790 +
1791  #ifdef GLX_DIRECT_RENDERING
1792     /* Destroy the direct rendering context */
1793     if (gc->driContext) {
1794 @@ -1575,7 +1591,7 @@ GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1795   * This function dynamically determines whether to use the EXT_import_context
1796   * version of the protocol or the GLX 1.3 version of the protocol.
1797   */
1798 -     static int __glXQueryContextInfo(Display * dpy, GLXContext ctx)
1799 +static int __glXQueryContextInfo(Display * dpy, GLXContext ctx)
1800  {
1801     __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1802     xGLXQueryContextReply reply;
1803 @@ -1713,7 +1729,7 @@ GLX_ALIAS(int, glXQueryContextInfoEXT,
1804            (Display * dpy, GLXContext ctx, int attribute, int *value),
1805            (dpy, ctx, attribute, value), glXQueryContext)
1806  
1807 -     PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
1808 +PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
1809  {
1810     return ctx->xid;
1811  }
1812 @@ -2159,18 +2175,19 @@ GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1813            (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
1814            (dpy, config, attribute, value), glXGetFBConfigAttrib)
1815  
1816 -     PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
1817 -                      (Display * dpy, int screen, int *attrib_list,
1818 -                       int *nelements), (dpy, screen, attrib_list, nelements),
1819 -                      glXChooseFBConfig)
1820 +PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
1821 +                 (Display * dpy, int screen, int *attrib_list,
1822 +                  int *nelements), (dpy, screen, attrib_list, nelements),
1823 +                 glXChooseFBConfig)
1824  
1825 -     PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
1826 -                      (Display * dpy, GLXFBConfigSGIX config),
1827 -                      (dpy, config), glXGetVisualFromFBConfig)
1828 +PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
1829 +                 (Display * dpy, GLXFBConfigSGIX config),
1830 +                 (dpy, config), glXGetVisualFromFBConfig)
1831  
1832 -     PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
1833 -                                                       GLXFBConfigSGIX config,
1834 -                                                       Pixmap pixmap)
1835 +PUBLIC GLXPixmap
1836 +glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
1837 +                                 GLXFBConfigSGIX config,
1838 +                                 Pixmap pixmap)
1839  {
1840     xGLXVendorPrivateWithReplyReq *vpreq;
1841     xGLXCreateGLXPixmapWithConfigSGIXReq *req;
1842 diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
1843 index 2741a41..b6c6ef7 100644
1844 --- a/src/mesa/drivers/common/meta.c
1845 +++ b/src/mesa/drivers/common/meta.c
1846 @@ -238,34 +238,10 @@ _mesa_meta_init(GLcontext *ctx)
1847  void
1848  _mesa_meta_free(GLcontext *ctx)
1849  {
1850 -   struct gl_meta_state *meta = ctx->Meta;
1851 -
1852 -   if (_mesa_get_current_context()) {
1853 -      /* if there's no current context, these textures, buffers, etc should
1854 -       * still get freed by _mesa_free_context_data().
1855 -       */
1856 -
1857 -      _mesa_DeleteTextures(1, &meta->TempTex.TexObj);
1858 -
1859 -      /* glBlitFramebuffer */
1860 -      _mesa_DeleteBuffersARB(1, & meta->Blit.VBO);
1861 -      _mesa_DeleteVertexArraysAPPLE(1, &meta->Blit.ArrayObj);
1862 -      _mesa_DeletePrograms(1, &meta->Blit.DepthFP);
1863 -
1864 -      /* glClear */
1865 -      _mesa_DeleteBuffersARB(1, & meta->Clear.VBO);
1866 -      _mesa_DeleteVertexArraysAPPLE(1, &meta->Clear.ArrayObj);
1867 -
1868 -      /* glCopyPixels */
1869 -      _mesa_DeleteBuffersARB(1, & meta->CopyPix.VBO);
1870 -      _mesa_DeleteVertexArraysAPPLE(1, &meta->CopyPix.ArrayObj);
1871 -
1872 -      /* glDrawPixels */
1873 -      _mesa_DeleteVertexArraysAPPLE(1, &meta->DrawPix.ArrayObj);
1874 -      _mesa_DeletePrograms(1, &meta->DrawPix.DepthFP);
1875 -      _mesa_DeletePrograms(1, &meta->DrawPix.StencilFP);
1876 -   }
1877 -
1878 +   /* Note: Any textures, VBOs, etc, that we allocate should get
1879 +    * freed by the normal context destruction code.  But this would be
1880 +    * the place to free other meta data someday.
1881 +    */
1882     _mesa_free(ctx->Meta);
1883     ctx->Meta = NULL;
1884  }
1885 diff --git a/src/mesa/drivers/dri/Makefile b/src/mesa/drivers/dri/Makefile
1886 index 32db097..264648c 100644
1887 --- a/src/mesa/drivers/dri/Makefile
1888 +++ b/src/mesa/drivers/dri/Makefile
1889 @@ -25,7 +25,7 @@ pcedit = sed \
1890         -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \
1891         -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \
1892         -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \
1893 -       -e 's,@DRI_DRIVER_DIR@,$(DRI_DRIVER_SEARCH_DIR),' \
1894 +       -e 's,@DRI_DRIVER_DIR@,$(DRI_DRIVER_INSTALL_DIR),' \
1895         -e 's,@DRI_PC_REQ_PRIV@,$(DRI_PC_REQ_PRIV),'
1896  
1897  dri.pc: dri.pc.in
1898 diff --git a/src/mesa/drivers/dri/i915/i830_texstate.c b/src/mesa/drivers/dri/i915/i830_texstate.c
1899 index 6f998fa..20ff46b 100644
1900 --- a/src/mesa/drivers/dri/i915/i830_texstate.c
1901 +++ b/src/mesa/drivers/dri/i915/i830_texstate.c
1902 @@ -160,11 +160,18 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
1903  
1904        pitch = intelObj->pitchOverride;
1905     } else {
1906 +      GLuint dst_x, dst_y;
1907 +
1908 +      intel_miptree_get_image_offset(intelObj->mt, intelObj->firstLevel, 0, 0,
1909 +                                    &dst_x, &dst_y);
1910 +
1911        dri_bo_reference(intelObj->mt->region->buffer);
1912        i830->state.tex_buffer[unit] = intelObj->mt->region->buffer;
1913 -      i830->state.tex_offset[unit] = intel_miptree_image_offset(intelObj->mt,
1914 -                                                               0, intelObj->
1915 -                                                               firstLevel);
1916 +      /* XXX: This calculation is probably broken for tiled images with
1917 +       * a non-page-aligned offset.
1918 +       */
1919 +      i830->state.tex_offset[unit] = (dst_x + dst_y * intelObj->mt->pitch) *
1920 +        intelObj->mt->cpp;
1921  
1922        format = translate_texture_format(firstImage->TexFormat->MesaFormat,
1923                                         firstImage->InternalFormat);
1924 diff --git a/src/mesa/drivers/dri/i915/i915_texstate.c b/src/mesa/drivers/dri/i915/i915_texstate.c
1925 index 32d4b30..998a04f 100644
1926 --- a/src/mesa/drivers/dri/i915/i915_texstate.c
1927 +++ b/src/mesa/drivers/dri/i915/i915_texstate.c
1928 @@ -171,11 +171,18 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
1929  
1930        pitch = intelObj->pitchOverride;
1931     } else {
1932 +      GLuint dst_x, dst_y;
1933 +
1934 +      intel_miptree_get_image_offset(intelObj->mt, intelObj->firstLevel, 0, 0,
1935 +                                    &dst_x, &dst_y);
1936 +
1937        dri_bo_reference(intelObj->mt->region->buffer);
1938        i915->state.tex_buffer[unit] = intelObj->mt->region->buffer;
1939 -      i915->state.tex_offset[unit] =  intel_miptree_image_offset(intelObj->mt,
1940 -                                                                0, intelObj->
1941 -                                                                firstLevel);
1942 +      /* XXX: This calculation is probably broken for tiled images with
1943 +       * a non-page-aligned offset.
1944 +       */
1945 +      i915->state.tex_offset[unit] = (dst_x + dst_y * intelObj->mt->pitch) *
1946 +        intelObj->mt->cpp;
1947  
1948        format = translate_texture_format(firstImage->TexFormat->MesaFormat, 
1949                                         firstImage->InternalFormat,
1950 diff --git a/src/mesa/drivers/dri/i915/intel_tris.c b/src/mesa/drivers/dri/i915/intel_tris.c
1951 index a905455..bc6b292 100644
1952 --- a/src/mesa/drivers/dri/i915/intel_tris.c
1953 +++ b/src/mesa/drivers/dri/i915/intel_tris.c
1954 @@ -1194,12 +1194,16 @@ getFallbackString(GLuint bit)
1955  
1956  
1957  
1958 +/**
1959 + * Enable/disable a fallback flag.
1960 + * \param bit  one of INTEL_FALLBACK_x flags.
1961 + */
1962  void
1963 -intelFallback(struct intel_context *intel, GLuint bit, GLboolean mode)
1964 +intelFallback(struct intel_context *intel, GLbitfield bit, GLboolean mode)
1965  {
1966     GLcontext *ctx = &intel->ctx;
1967     TNLcontext *tnl = TNL_CONTEXT(ctx);
1968 -   GLuint oldfallback = intel->Fallback;
1969 +   const GLbitfield oldfallback = intel->Fallback;
1970  
1971     if (mode) {
1972        intel->Fallback |= bit;
1973 diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
1974 index a5209ac..da0e091 100644
1975 --- a/src/mesa/drivers/dri/i965/brw_context.h
1976 +++ b/src/mesa/drivers/dri/i965/brw_context.h
1977 @@ -115,7 +115,7 @@
1978   * Handles blending and (presumably) depth and stencil testing.
1979   */
1980  
1981 -#define BRW_FALLBACK_TEXTURE            0x1
1982 +
1983  #define BRW_MAX_CURBE                    (32*16)
1984  
1985  struct brw_context;
1986 @@ -454,7 +454,6 @@ struct brw_context
1987     GLuint primitive;
1988  
1989     GLboolean emit_state_always;
1990 -   GLboolean tmp_fallback;
1991     GLboolean no_batch_wrap;
1992  
1993     struct {
1994 diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c
1995 index 4aa17fa..348c661 100644
1996 --- a/src/mesa/drivers/dri/i965/brw_draw_upload.c
1997 +++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c
1998 @@ -375,7 +375,7 @@ static void brw_prepare_vertices(struct brw_context *brw)
1999      * isn't an issue at this point.
2000      */
2001     if (brw->vb.nr_enabled >= BRW_VEP_MAX) {
2002 -      intel->Fallback = 1;
2003 +      intel->Fallback = GL_TRUE; /* boolean, not bitfield */
2004        return;
2005     }
2006  
2007 @@ -427,7 +427,7 @@ static void brw_prepare_vertices(struct brw_context *brw)
2008             /* Position array not properly enabled:
2009              */
2010              if (input->glarray->StrideB == 0) {
2011 -               intel->Fallback = 1;
2012 +               intel->Fallback = GL_TRUE; /* boolean, not bitfield */
2013                 return;
2014              }
2015  
2016 @@ -539,12 +539,12 @@ static void brw_emit_vertices(struct brw_context *brw)
2017            if (input->stride) {
2018                OUT_RELOC(input->bo,
2019                          I915_GEM_DOMAIN_VERTEX, 0,
2020 -                        input->offset + input->stride * input->count);
2021 +                        input->offset + input->stride * input->count - 1);
2022            } else {
2023                assert(input->count == 1);
2024                OUT_RELOC(input->bo,
2025                          I915_GEM_DOMAIN_VERTEX, 0,
2026 -                        input->offset + input->element_size);
2027 +                        input->offset + input->element_size - 1);
2028            }
2029        } else
2030            OUT_BATCH(input->stride ? input->count : 0);
2031 @@ -726,7 +726,7 @@ static void brw_emit_index_buffer(struct brw_context *brw)
2032                 brw->ib.offset);
2033        OUT_RELOC(brw->ib.bo,
2034                 I915_GEM_DOMAIN_VERTEX, 0,
2035 -               brw->ib.offset + brw->ib.size);
2036 +               brw->ib.offset + brw->ib.size - 1);
2037        OUT_BATCH( 0 );
2038        ADVANCE_BATCH();
2039     }
2040 diff --git a/src/mesa/drivers/dri/i965/brw_fallback.c b/src/mesa/drivers/dri/i965/brw_fallback.c
2041 index d27c6c2..562a178 100644
2042 --- a/src/mesa/drivers/dri/i965/brw_fallback.c
2043 +++ b/src/mesa/drivers/dri/i965/brw_fallback.c
2044 @@ -133,7 +133,11 @@ const struct brw_tracked_state brw_check_fallback = {
2045  
2046  
2047  
2048 -/* Not used:
2049 +/**
2050 + * Called by the INTEL_FALLBACK() macro.
2051 + * NOTE: this is a no-op for the i965 driver.  The brw->intel.Fallback
2052 + * field is treated as a boolean, not a bitmask.  It's only set in a
2053 + * couple of places.
2054   */
2055  void intelFallback( struct intel_context *intel, GLuint bit, GLboolean mode )
2056  {
2057 diff --git a/src/mesa/drivers/dri/i965/brw_state.h b/src/mesa/drivers/dri/i965/brw_state.h
2058 index 5335eac..d639656 100644
2059 --- a/src/mesa/drivers/dri/i965/brw_state.h
2060 +++ b/src/mesa/drivers/dri/i965/brw_state.h
2061 @@ -151,6 +151,7 @@ void brw_state_cache_check_size( struct brw_context *brw );
2062  
2063  void brw_init_caches( struct brw_context *brw );
2064  void brw_destroy_caches( struct brw_context *brw );
2065 +void brw_state_cache_bo_delete(struct brw_cache *cache, dri_bo *bo);
2066  
2067  /***********************************************************************
2068   * brw_state_batch.c
2069 diff --git a/src/mesa/drivers/dri/i965/brw_state_cache.c b/src/mesa/drivers/dri/i965/brw_state_cache.c
2070 index e40d7a0..f8e46aa 100644
2071 --- a/src/mesa/drivers/dri/i965/brw_state_cache.c
2072 +++ b/src/mesa/drivers/dri/i965/brw_state_cache.c
2073 @@ -517,6 +517,55 @@ brw_clear_cache(struct brw_context *brw, struct brw_cache *cache)
2074     brw->state.dirty.cache |= ~0;
2075  }
2076  
2077 +/* Clear all entries from the cache that point to the given bo.
2078 + *
2079 + * This lets us release memory for reuse earlier for known-dead buffers,
2080 + * at the cost of walking the entire hash table.
2081 + */
2082 +void
2083 +brw_state_cache_bo_delete(struct brw_cache *cache, dri_bo *bo)
2084 +{
2085 +   struct brw_cache_item **prev;
2086 +   GLuint i;
2087 +
2088 +   if (INTEL_DEBUG & DEBUG_STATE)
2089 +      _mesa_printf("%s\n", __FUNCTION__);
2090 +
2091 +   for (i = 0; i < cache->size; i++) {
2092 +      for (prev = &cache->items[i]; *prev;) {
2093 +        struct brw_cache_item *c = *prev;
2094 +        int j;
2095 +
2096 +        for (j = 0; j < c->nr_reloc_bufs; j++) {
2097 +           if (c->reloc_bufs[j] == bo)
2098 +              break;
2099 +        }
2100 +
2101 +        if (j != c->nr_reloc_bufs) {
2102 +
2103 +           *prev = c->next;
2104 +
2105 +           for (j = 0; j < c->nr_reloc_bufs; j++)
2106 +              dri_bo_unreference(c->reloc_bufs[j]);
2107 +           dri_bo_unreference(c->bo);
2108 +           free((void *)c->key);
2109 +           free(c);
2110 +           cache->n_items--;
2111 +
2112 +           /* Delete up the tree.  Notably we're trying to get from
2113 +            * a request to delete the surface, to deleting the surface state
2114 +            * object, to deleting the binding table.  We're slack and restart
2115 +            * the deletion process when we do this because the other delete
2116 +            * may kill our *prev.
2117 +            */
2118 +           brw_state_cache_bo_delete(cache, c->bo);
2119 +           prev = &cache->items[i];
2120 +        } else {
2121 +           prev = &(*prev)->next;
2122 +        }
2123 +      }
2124 +   }
2125 +}
2126  
2127  void
2128  brw_state_cache_check_size(struct brw_context *brw)
2129 diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c
2130 index b817b74..ee447af 100644
2131 --- a/src/mesa/drivers/dri/i965/brw_state_upload.c
2132 +++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
2133 @@ -308,7 +308,7 @@ void brw_validate_state( struct brw_context *brw )
2134     if (brw->state.dirty.brw & BRW_NEW_CONTEXT)
2135        brw_clear_batch_cache(brw);
2136  
2137 -   brw->intel.Fallback = 0;
2138 +   brw->intel.Fallback = GL_FALSE; /* boolean, not bitfield */
2139  
2140     /* do prepare stage for all atoms */
2141     for (i = 0; i < Elements(atoms); i++) {
2142 diff --git a/src/mesa/drivers/dri/i965/brw_tex_layout.c b/src/mesa/drivers/dri/i965/brw_tex_layout.c
2143 index 5986cbf..e59e52e 100644
2144 --- a/src/mesa/drivers/dri/i965/brw_tex_layout.c
2145 +++ b/src/mesa/drivers/dri/i965/brw_tex_layout.c
2146 @@ -86,10 +86,10 @@ GLboolean brw_miptree_layout(struct intel_context *intel,
2147            mt->pitch = intel_miptree_pitch_align(intel, mt, tiling, mt->pitch);
2148  
2149            if (mt->compressed) {
2150 -              qpitch = (y_pitch + ALIGN(minify(y_pitch), align_h) + 11 * align_h) / 4 * mt->pitch * mt->cpp;
2151 +              qpitch = (y_pitch + ALIGN(minify(y_pitch), align_h) + 11 * align_h) / 4;
2152                mt->total_height = (y_pitch + ALIGN(minify(y_pitch), align_h) + 11 * align_h) / 4 * 6;
2153            } else {
2154 -              qpitch = (y_pitch + ALIGN(minify(y_pitch), align_h) + 11 * align_h) * mt->pitch * mt->cpp;
2155 +              qpitch = (y_pitch + ALIGN(minify(y_pitch), align_h) + 11 * align_h);
2156                mt->total_height = (y_pitch + ALIGN(minify(y_pitch), align_h) + 11 * align_h) * 6;
2157            }
2158  
2159 @@ -102,7 +102,8 @@ GLboolean brw_miptree_layout(struct intel_context *intel,
2160                                             height, 1);
2161  
2162                for (q = 0; q < nr_images; q++)
2163 -                  intel_miptree_set_image_offset_ex(mt, level, q, x, y, q * qpitch);
2164 +                  intel_miptree_set_image_offset(mt, level, q,
2165 +                                                x, y + q * qpitch);
2166  
2167                if (mt->compressed)
2168                    img_height = MAX2(1, height/4);
2169 diff --git a/src/mesa/drivers/dri/intel/intel_blit.c b/src/mesa/drivers/dri/intel/intel_blit.c
2170 index 0c5be4c..ec4a5b4 100644
2171 --- a/src/mesa/drivers/dri/intel/intel_blit.c
2172 +++ b/src/mesa/drivers/dri/intel/intel_blit.c
2173 @@ -441,6 +441,10 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
2174                    intel_region_buffer(intel, irb->region,
2175                                        all ? INTEL_WRITE_FULL :
2176                                        INTEL_WRITE_PART);
2177 +              int x1 = b.x1 + irb->region->draw_x;
2178 +              int y1 = b.y1 + irb->region->draw_y;
2179 +              int x2 = b.x2 + irb->region->draw_x;
2180 +              int y2 = b.y2 + irb->region->draw_y;
2181  
2182                 GLuint clearVal;
2183                 GLint pitch, cpp;
2184 @@ -449,11 +453,10 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
2185                 pitch = irb->region->pitch;
2186                 cpp = irb->region->cpp;
2187  
2188 -               DBG("%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
2189 +               DBG("%s dst:buf(%p)/%d %d,%d sz:%dx%d\n",
2190                     __FUNCTION__,
2191                     irb->region->buffer, (pitch * cpp),
2192 -                   irb->region->draw_offset,
2193 -                   b.x1, b.y1, b.x2 - b.x1, b.y2 - b.y1);
2194 +                   x1, y1, x2 - x1, y2 - y1);
2195  
2196                BR13 = 0xf0 << 16;
2197                CMD = XY_COLOR_BLT_CMD;
2198 @@ -526,17 +529,17 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
2199                    buf, irb->Base.Name);
2200                  */
2201  
2202 -               assert(b.x1 < b.x2);
2203 -               assert(b.y1 < b.y2);
2204 +               assert(x1 < x2);
2205 +               assert(y1 < y2);
2206  
2207                 BEGIN_BATCH(6, REFERENCES_CLIPRECTS);
2208                 OUT_BATCH(CMD);
2209                 OUT_BATCH(BR13);
2210 -               OUT_BATCH((b.y1 << 16) | b.x1);
2211 -               OUT_BATCH((b.y2 << 16) | b.x2);
2212 +               OUT_BATCH((y1 << 16) | x1);
2213 +               OUT_BATCH((y2 << 16) | x2);
2214                 OUT_RELOC(write_buffer,
2215                          I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
2216 -                         irb->region->draw_offset);
2217 +                         0);
2218                 OUT_BATCH(clearVal);
2219                 ADVANCE_BATCH();
2220                 clearMask &= ~bufBit;    /* turn off bit, for faster loop exit */
2221 diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
2222 index fce42e9..ddb0550 100644
2223 --- a/src/mesa/drivers/dri/intel/intel_context.c
2224 +++ b/src/mesa/drivers/dri/intel/intel_context.c
2225 @@ -839,7 +839,7 @@ intelDestroyContext(__DRIcontextPrivate * driContextPriv)
2226        _vbo_DestroyContext(&intel->ctx);
2227  
2228        _swrast_DestroyContext(&intel->ctx);
2229 -      intel->Fallback = 0;      /* don't call _swrast_Flush later */
2230 +      intel->Fallback = 0x0;      /* don't call _swrast_Flush later */
2231  
2232        intel_batchbuffer_free(intel->batch);
2233        intel->batch = NULL;
2234 @@ -944,10 +944,23 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
2235                   __DRIdrawablePrivate * driReadPriv)
2236  {
2237     __DRIscreenPrivate *psp = driDrawPriv->driScreenPriv;
2238 +   struct intel_context *intel;
2239 +   GET_CURRENT_CONTEXT(curCtx);
2240 +
2241 +   if (driContextPriv)
2242 +      intel = (struct intel_context *) driContextPriv->driverPrivate;
2243 +   else
2244 +      intel = NULL;
2245 +
2246 +   /* According to the glXMakeCurrent() man page: "Pending commands to
2247 +    * the previous context, if any, are flushed before it is released."
2248 +    * But only flush if we're actually changing contexts.
2249 +    */
2250 +   if (intel_context(curCtx) && intel_context(curCtx) != intel) {
2251 +      _mesa_flush(curCtx);
2252 +   }
2253  
2254     if (driContextPriv) {
2255 -      struct intel_context *intel =
2256 -         (struct intel_context *) driContextPriv->driverPrivate;
2257        struct intel_framebuffer *intel_fb =
2258          (struct intel_framebuffer *) driDrawPriv->driverPrivate;
2259        GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate;
2260 @@ -993,41 +1006,35 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
2261  
2262        _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
2263  
2264 -      /* The drawbuffer won't always be updated by _mesa_make_current: 
2265 -       */
2266 -      if (intel->ctx.DrawBuffer == &intel_fb->Base) {
2267 -
2268 -        if (intel->driReadDrawable != driReadPriv)
2269 -           intel->driReadDrawable = driReadPriv;
2270 -
2271 -        if (intel->driDrawable != driDrawPriv) {
2272 -           if (driDrawPriv->swap_interval == (unsigned)-1) {
2273 -              int i;
2274 -
2275 -              driDrawPriv->vblFlags = (intel->intelScreen->irq_active != 0)
2276 -                 ? driGetDefaultVBlankFlags(&intel->optionCache)
2277 -                : VBLANK_FLAG_NO_IRQ;
2278 -
2279 -              /* Prevent error printf if one crtc is disabled, this will
2280 -               * be properly calculated in intelWindowMoved() next.
2281 -               */
2282 -               driDrawPriv->vblFlags = intelFixupVblank(intel, driDrawPriv);
2283 -
2284 -              (*psp->systemTime->getUST) (&intel_fb->swap_ust);
2285 -              driDrawableInitVBlank(driDrawPriv);
2286 -              intel_fb->vbl_waited = driDrawPriv->vblSeq;
2287 -
2288 -              for (i = 0; i < 2; i++) {
2289 -                 if (intel_fb->color_rb[i])
2290 -                    intel_fb->color_rb[i]->vbl_pending = driDrawPriv->vblSeq;
2291 -              }
2292 -           }
2293 -           intel->driDrawable = driDrawPriv;
2294 -           intelWindowMoved(intel);
2295 -        }
2296 +      intel->driReadDrawable = driReadPriv;
2297  
2298 -        intel_draw_buffer(&intel->ctx, &intel_fb->Base);
2299 +      if (intel->driDrawable != driDrawPriv) {
2300 +         if (driDrawPriv->swap_interval == (unsigned)-1) {
2301 +            int i;
2302 +
2303 +            driDrawPriv->vblFlags = (intel->intelScreen->irq_active != 0)
2304 +               ? driGetDefaultVBlankFlags(&intel->optionCache)
2305 +               : VBLANK_FLAG_NO_IRQ;
2306 +
2307 +            /* Prevent error printf if one crtc is disabled, this will
2308 +             * be properly calculated in intelWindowMoved() next.
2309 +             */
2310 +            driDrawPriv->vblFlags = intelFixupVblank(intel, driDrawPriv);
2311 +
2312 +            (*psp->systemTime->getUST) (&intel_fb->swap_ust);
2313 +            driDrawableInitVBlank(driDrawPriv);
2314 +            intel_fb->vbl_waited = driDrawPriv->vblSeq;
2315 +
2316 +            for (i = 0; i < 2; i++) {
2317 +               if (intel_fb->color_rb[i])
2318 +                  intel_fb->color_rb[i]->vbl_pending = driDrawPriv->vblSeq;
2319 +            }
2320 +         }
2321 +         intel->driDrawable = driDrawPriv;
2322 +         intelWindowMoved(intel);
2323        }
2324 +
2325 +      intel_draw_buffer(&intel->ctx, &intel_fb->Base);
2326     }
2327     else {
2328        _mesa_make_current(NULL, NULL, NULL);
2329 diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
2330 index 03e7cf3..d3acf6e 100644
2331 --- a/src/mesa/drivers/dri/intel/intel_context.h
2332 +++ b/src/mesa/drivers/dri/intel/intel_context.h
2333 @@ -61,6 +61,10 @@ typedef void (*intel_line_func) (struct intel_context *, intelVertex *,
2334                                   intelVertex *);
2335  typedef void (*intel_point_func) (struct intel_context *, intelVertex *);
2336  
2337 +/**
2338 + * Bits for intel->Fallback field
2339 + */
2340 +/*@{*/
2341  #define INTEL_FALLBACK_DRAW_BUFFER      0x1
2342  #define INTEL_FALLBACK_READ_BUFFER      0x2
2343  #define INTEL_FALLBACK_DEPTH_BUFFER      0x4
2344 @@ -68,8 +72,10 @@ typedef void (*intel_point_func) (struct intel_context *, intelVertex *);
2345  #define INTEL_FALLBACK_USER             0x10
2346  #define INTEL_FALLBACK_RENDERMODE       0x20
2347  #define INTEL_FALLBACK_TEXTURE          0x40
2348 +#define INTEL_FALLBACK_DRIVER            0x1000  /**< first for drivers */
2349 +/*@}*/
2350  
2351 -extern void intelFallback(struct intel_context *intel, GLuint bit,
2352 +extern void intelFallback(struct intel_context *intel, GLbitfield bit,
2353                            GLboolean mode);
2354  #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
2355  
2356 @@ -171,7 +177,7 @@ struct intel_context
2357     struct dri_metaops meta;
2358  
2359     GLint refcount;
2360 -   GLuint Fallback;
2361 +   GLbitfield Fallback;  /**< mask of INTEL_FALLBACK_x bits */
2362     GLuint NewGLState;
2363  
2364     dri_bufmgr *bufmgr;
2365 diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
2366 index 804c034..a49868b 100644
2367 --- a/src/mesa/drivers/dri/intel/intel_fbo.c
2368 +++ b/src/mesa/drivers/dri/intel/intel_fbo.c
2369 @@ -385,6 +385,7 @@ intel_create_renderbuffer(GLenum intFormat)
2370     default:
2371        _mesa_problem(NULL,
2372                      "Unexpected intFormat in intel_create_renderbuffer");
2373 +      _mesa_free(irb);
2374        return NULL;
2375     }
2376  
2377 @@ -571,7 +572,7 @@ intel_render_texture(GLcontext * ctx,
2378        = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
2379     struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
2380     struct intel_texture_image *intel_image;
2381 -   GLuint imageOffset;
2382 +   GLuint dst_x, dst_y;
2383  
2384     (void) fb;
2385  
2386 @@ -618,18 +619,16 @@ intel_render_texture(GLcontext * ctx,
2387     }
2388  
2389     /* compute offset of the particular 2D image within the texture region */
2390 -   imageOffset = intel_miptree_image_offset(intel_image->mt,
2391 -                                            att->CubeMapFace,
2392 -                                            att->TextureLevel);
2393 -
2394 -   if (att->Texture->Target == GL_TEXTURE_3D) {
2395 -      const GLuint *offsets = intel_miptree_depth_offsets(intel_image->mt,
2396 -                                                          att->TextureLevel);
2397 -      imageOffset += offsets[att->Zoffset];
2398 -   }
2399 -
2400 -   /* store that offset in the region */
2401 -   intel_image->mt->region->draw_offset = imageOffset;
2402 +   intel_miptree_get_image_offset(intel_image->mt,
2403 +                                 att->TextureLevel,
2404 +                                 att->CubeMapFace,
2405 +                                 att->Zoffset,
2406 +                                 &dst_x, &dst_y);
2407 +
2408 +   intel_image->mt->region->draw_offset = (dst_y * intel_image->mt->pitch +
2409 +                                          dst_x) * intel_image->mt->cpp;
2410 +   intel_image->mt->region->draw_x = dst_x;
2411 +   intel_image->mt->region->draw_y = dst_y;
2412  
2413     /* update drawing region, etc */
2414     intel_draw_buffer(ctx, fb);
2415 diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
2416 index c985da5..459e8fb 100644
2417 --- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
2418 +++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
2419 @@ -29,6 +29,9 @@
2420  #include "intel_mipmap_tree.h"
2421  #include "intel_regions.h"
2422  #include "intel_chipset.h"
2423 +#ifndef I915
2424 +#include "brw_state.h"
2425 +#endif
2426  #include "main/enums.h"
2427  
2428  #define FILE_DEBUG_FLAG DEBUG_MIPTREE
2429 @@ -131,8 +134,10 @@ intel_miptree_create(struct intel_context *intel,
2430     /*
2431      * pitch == 0 || height == 0  indicates the null texture
2432      */
2433 -   if (!mt || !mt->pitch || !mt->total_height)
2434 +   if (!mt || !mt->pitch || !mt->total_height) {
2435 +      free(mt);
2436        return NULL;
2437 +   }
2438  
2439     mt->region = intel_region_alloc(intel,
2440                                    tiling,
2441 @@ -269,11 +274,25 @@ intel_miptree_release(struct intel_context *intel,
2442  
2443        DBG("%s deleting %p\n", __FUNCTION__, *mt);
2444  
2445 +#ifndef I915
2446 +      /* Free up cached binding tables holding a reference on our buffer, to
2447 +       * avoid excessive memory consumption.
2448 +       *
2449 +       * This isn't as aggressive as we could be, as we'd like to do
2450 +       * it from any time we free the last ref on a region.  But intel_region.c
2451 +       * is context-agnostic.  Perhaps our constant state cache should be, as
2452 +       * well.
2453 +       */
2454 +      brw_state_cache_bo_delete(&brw_context(&intel->ctx)->surface_cache,
2455 +                               (*mt)->region->buffer);
2456 +#endif
2457 +
2458        intel_region_release(&((*mt)->region));
2459  
2460 -      for (i = 0; i < MAX_TEXTURE_LEVELS; i++)
2461 -         if ((*mt)->level[i].image_offset)
2462 -            free((*mt)->level[i].image_offset);
2463 +      for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
2464 +        free((*mt)->level[i].x_offset);
2465 +        free((*mt)->level[i].y_offset);
2466 +      }
2467  
2468        free(*mt);
2469     }
2470 @@ -334,82 +353,58 @@ intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
2471     mt->level[level].height = h;
2472     mt->level[level].depth = d;
2473     mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp;
2474 +   mt->level[level].level_x = x;
2475 +   mt->level[level].level_y = y;
2476     mt->level[level].nr_images = nr_images;
2477  
2478     DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
2479         level, w, h, d, x, y, mt->level[level].level_offset);
2480  
2481 -   /* Not sure when this would happen, but anyway: 
2482 -    */
2483 -   if (mt->level[level].image_offset) {
2484 -      free(mt->level[level].image_offset);
2485 -      mt->level[level].image_offset = NULL;
2486 -   }
2487 -
2488     assert(nr_images);
2489 +   assert(!mt->level[level].x_offset);
2490  
2491 -   mt->level[level].image_offset = malloc(nr_images * sizeof(GLuint));
2492 -   mt->level[level].image_offset[0] = 0;
2493 +   mt->level[level].x_offset = malloc(nr_images * sizeof(GLuint));
2494 +   mt->level[level].x_offset[0] = mt->level[level].level_x;
2495 +   mt->level[level].y_offset = malloc(nr_images * sizeof(GLuint));
2496 +   mt->level[level].y_offset[0] = mt->level[level].level_y;
2497  }
2498  
2499  
2500  void
2501 -intel_miptree_set_image_offset_ex(struct intel_mipmap_tree *mt,
2502 -                                  GLuint level, GLuint img,
2503 -                                  GLuint x, GLuint y, 
2504 -                                  GLuint offset)
2505 +intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
2506 +                              GLuint level, GLuint img,
2507 +                              GLuint x, GLuint y)
2508  {
2509     if (img == 0 && level == 0)
2510        assert(x == 0 && y == 0);
2511  
2512     assert(img < mt->level[level].nr_images);
2513  
2514 -   mt->level[level].image_offset[img] = (x + y * mt->pitch) * mt->cpp + offset;
2515 +   mt->level[level].x_offset[img] = mt->level[level].level_x + x;
2516 +   mt->level[level].y_offset[img] = mt->level[level].level_y + y;
2517  
2518 -   DBG("%s level %d img %d pos %d,%d image_offset %x\n",
2519 -       __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]);
2520 +   DBG("%s level %d img %d pos %d,%d\n",
2521 +       __FUNCTION__, level, img,
2522 +       mt->level[level].x_offset[img], mt->level[level].y_offset[img]);
2523  }
2524  
2525  void
2526 -intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
2527 -                              GLuint level, GLuint img,
2528 -                              GLuint x, GLuint y)
2529 -{
2530 -    intel_miptree_set_image_offset_ex(mt, level, img, x, y, 0);
2531 -}
2532 -
2533 -
2534 -/* Although we use the image_offset[] array to store relative offsets
2535 - * to cube faces, Mesa doesn't know anything about this and expects
2536 - * each cube face to be treated as a separate image.
2537 - *
2538 - * These functions present that view to mesa:
2539 - */
2540 -const GLuint *
2541 -intel_miptree_depth_offsets(struct intel_mipmap_tree *mt, GLuint level)
2542 -{
2543 -   static const GLuint zero = 0;
2544 -
2545 -   if (mt->target != GL_TEXTURE_3D || mt->level[level].nr_images == 1)
2546 -      return &zero;
2547 -   else
2548 -      return mt->level[level].image_offset;
2549 -}
2550 -
2551 -
2552 -GLuint
2553 -intel_miptree_image_offset(struct intel_mipmap_tree *mt,
2554 -                          GLuint face, GLuint level)
2555 +intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
2556 +                              GLuint level, GLuint face, GLuint depth,
2557 +                              GLuint *x, GLuint *y)
2558  {
2559 -   if (mt->target == GL_TEXTURE_CUBE_MAP_ARB)
2560 -      return (mt->level[level].level_offset +
2561 -             mt->level[level].image_offset[face]);
2562 -   else
2563 -      return mt->level[level].level_offset;
2564 +   if (mt->target == GL_TEXTURE_CUBE_MAP_ARB) {
2565 +      *x = mt->level[level].x_offset[face];
2566 +      *y = mt->level[level].y_offset[face];
2567 +   } else if (mt->target == GL_TEXTURE_3D) {
2568 +      *x = mt->level[level].x_offset[depth];
2569 +      *y = mt->level[level].y_offset[depth];
2570 +   } else {
2571 +      *x = mt->level[level].x_offset[0];
2572 +      *y = mt->level[level].y_offset[0];
2573 +   }
2574  }
2575  
2576 -
2577 -
2578  /**
2579   * Map a teximage in a mipmap tree.
2580   * \param row_stride  returns row stride in bytes
2581 @@ -425,6 +420,7 @@ intel_miptree_image_map(struct intel_context * intel,
2582                          GLuint level,
2583                          GLuint * row_stride, GLuint * image_offsets)
2584  {
2585 +   GLuint x, y;
2586     DBG("%s \n", __FUNCTION__);
2587  
2588     if (row_stride)
2589 @@ -433,17 +429,23 @@ intel_miptree_image_map(struct intel_context * intel,
2590     if (mt->target == GL_TEXTURE_3D) {
2591        int i;
2592  
2593 -      for (i = 0; i < mt->level[level].depth; i++)
2594 -        image_offsets[i] = mt->level[level].image_offset[i] / mt->cpp;
2595 +      for (i = 0; i < mt->level[level].depth; i++) {
2596 +
2597 +        intel_miptree_get_image_offset(mt, level, face, i,
2598 +                                       &x, &y);
2599 +        image_offsets[i] = x + y * mt->pitch;
2600 +      }
2601 +
2602 +      return intel_region_map(intel, mt->region);
2603     } else {
2604        assert(mt->level[level].depth == 1);
2605 -      assert(mt->target == GL_TEXTURE_CUBE_MAP ||
2606 -            mt->level[level].image_offset[0] == 0);
2607 +      intel_miptree_get_image_offset(mt, level, face, 0,
2608 +                                    &x, &y);
2609        image_offsets[0] = 0;
2610 -   }
2611  
2612 -   return (intel_region_map(intel, mt->region) +
2613 -           intel_miptree_image_offset(mt, face, level));
2614 +      return intel_region_map(intel, mt->region) +
2615 +        (x + y * mt->pitch) * mt->cpp;
2616 +   }
2617  }
2618  
2619  void
2620 @@ -468,20 +470,19 @@ intel_miptree_image_data(struct intel_context *intel,
2621                          GLuint src_image_pitch)
2622  {
2623     GLuint depth = dst->level[level].depth;
2624 -   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
2625 -   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
2626     GLuint i;
2627 -   GLuint height = 0;
2628  
2629     DBG("%s: %d/%d\n", __FUNCTION__, face, level);
2630     for (i = 0; i < depth; i++) {
2631 +      GLuint dst_x, dst_y, height;
2632 +
2633 +      intel_miptree_get_image_offset(dst, level, face, i, &dst_x, &dst_y);
2634 +
2635        height = dst->level[level].height;
2636        if(dst->compressed)
2637          height = (height + 3) / 4;
2638        intel_region_data(intel,
2639 -                       dst->region,
2640 -                       dst_offset + dst_depth_offset[i], /* dst_offset */
2641 -                       0, 0,                             /* dstx, dsty */
2642 +                       dst->region, 0, dst_x, dst_y,
2643                         src,
2644                         src_row_pitch,
2645                         0, 0,                             /* source x, y */
2646 @@ -503,10 +504,7 @@ intel_miptree_image_copy(struct intel_context *intel,
2647     GLuint width = src->level[level].width;
2648     GLuint height = src->level[level].height;
2649     GLuint depth = src->level[level].depth;
2650 -   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
2651 -   GLuint src_offset = intel_miptree_image_offset(src, face, level);
2652 -   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
2653 -   const GLuint *src_depth_offset = intel_miptree_depth_offsets(src, level);
2654 +   GLuint src_x, src_y, dst_x, dst_y;
2655     GLuint i;
2656     GLboolean success;
2657  
2658 @@ -519,22 +517,23 @@ intel_miptree_image_copy(struct intel_context *intel,
2659     }
2660  
2661     for (i = 0; i < depth; i++) {
2662 +      intel_miptree_get_image_offset(src, level, face, i, &src_x, &src_y);
2663 +      intel_miptree_get_image_offset(dst, level, face, i, &dst_x, &dst_y);
2664        success = intel_region_copy(intel,
2665 -                                 dst->region, dst_offset + dst_depth_offset[i],
2666 -                                 0, 0,
2667 -                                 src->region, src_offset + src_depth_offset[i],
2668 -                                 0, 0, width, height, GL_COPY);
2669 +                                 dst->region, 0, dst_x, dst_y,
2670 +                                 src->region, 0, src_x, src_y, width, height,
2671 +                                 GL_COPY);
2672        if (!success) {
2673          GLubyte *src_ptr, *dst_ptr;
2674  
2675          src_ptr = intel_region_map(intel, src->region);
2676          dst_ptr = intel_region_map(intel, dst->region);
2677  
2678 -        _mesa_copy_rect(dst_ptr + dst_offset + dst_depth_offset[i],
2679 +        _mesa_copy_rect(dst_ptr + dst->cpp * (dst_x + dst_y * dst->pitch),
2680                          dst->cpp,
2681                          dst->pitch,
2682                          0, 0, width, height,
2683 -                        src_ptr + src_offset + src_depth_offset[i],
2684 +                        src_ptr + src->cpp * (src_x + src_y * src->pitch),
2685                          src->pitch,
2686                          0, 0);
2687          intel_region_unmap(intel, src->region);
2688 diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
2689 index c890b2a..3bce54d 100644
2690 --- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
2691 +++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
2692 @@ -70,6 +70,10 @@ struct intel_mipmap_level
2693      * always zero in that case.
2694      */
2695     GLuint level_offset;
2696 +   /** Offset to this miptree level, used in computing x_offset. */
2697 +   GLuint level_x;
2698 +   /** Offset to this miptree level, used in computing y_offset. */
2699 +   GLuint level_y;
2700     GLuint width;
2701     GLuint height;
2702     /** Depth of the mipmap at this level: 1 for 1D/2D/CUBE, n for 3D. */
2703 @@ -86,7 +90,7 @@ struct intel_mipmap_level
2704      * compute the offsets of depth/cube images within a mipmap level,
2705      * so have to store them as a lookup table.
2706      */
2707 -   GLuint *image_offset;
2708 +   GLuint *x_offset, *y_offset;
2709  };
2710  
2711  struct intel_mipmap_tree
2712 @@ -176,19 +180,10 @@ GLubyte *intel_miptree_image_map(struct intel_context *intel,
2713  void intel_miptree_image_unmap(struct intel_context *intel,
2714                                 struct intel_mipmap_tree *mt);
2715  
2716 -
2717 -/* Return the linear offset of an image relative to the start of the
2718 - * tree:
2719 - */
2720 -GLuint intel_miptree_image_offset(struct intel_mipmap_tree *mt,
2721 -                                  GLuint face, GLuint level);
2722 -
2723 -/* Return pointers to each 2d slice within an image.  Indexed by depth
2724 - * value.
2725 - */
2726 -const GLuint *intel_miptree_depth_offsets(struct intel_mipmap_tree *mt,
2727 -                                          GLuint level);
2728 -
2729 +void
2730 +intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
2731 +                              GLuint level, GLuint face, GLuint depth,
2732 +                              GLuint *x, GLuint *y);
2733  
2734  void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
2735                                    GLuint level,
2736 @@ -196,16 +191,10 @@ void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
2737                                    GLuint x, GLuint y,
2738                                    GLuint w, GLuint h, GLuint d);
2739  
2740 -void intel_miptree_set_image_offset_ex(struct intel_mipmap_tree *mt,
2741 -                                       GLuint level,
2742 -                                       GLuint img, GLuint x, GLuint y,
2743 -                                       GLuint offset);
2744 -
2745  void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
2746                                      GLuint level,
2747                                      GLuint img, GLuint x, GLuint y);
2748  
2749 -
2750  /* Upload an image into a tree
2751   */
2752  void intel_miptree_image_data(struct intel_context *intel,
2753 diff --git a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
2754 index b543a0b..18e6ebd 100644
2755 --- a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
2756 +++ b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
2757 @@ -435,13 +435,14 @@ intel_texture_bitmap(GLcontext * ctx,
2758     }
2759  
2760     /* Save GL state before we start setting up our drawing */
2761 -   _mesa_PushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT |
2762 -                   GL_VIEWPORT_BIT);
2763 +   _mesa_PushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_POLYGON_BIT |
2764 +                    GL_TEXTURE_BIT | GL_VIEWPORT_BIT);
2765     _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT |
2766                           GL_CLIENT_PIXEL_STORE_BIT);
2767     old_active_texture = ctx->Texture.CurrentUnit;
2768  
2769     _mesa_Disable(GL_POLYGON_STIPPLE);
2770 +   _mesa_PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
2771  
2772     /* Upload our bitmap data to an alpha texture */
2773     _mesa_ActiveTextureARB(GL_TEXTURE0_ARB);
2774 @@ -501,8 +502,6 @@ intel_texture_bitmap(GLcontext * ctx,
2775     meta_restore_vertex_program(&intel->meta);
2776  
2777     _mesa_PopClientAttrib();
2778 -   _mesa_Disable(GL_TEXTURE_2D); /* asserted that it was disabled at entry */
2779 -   _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + old_active_texture);
2780     _mesa_PopAttrib();
2781  
2782     _mesa_DeleteTextures(1, &texname);
2783 diff --git a/src/mesa/drivers/dri/intel/intel_pixel_read.c b/src/mesa/drivers/dri/intel/intel_pixel_read.c
2784 index 8713463..e036736 100644
2785 --- a/src/mesa/drivers/dri/intel/intel_pixel_read.c
2786 +++ b/src/mesa/drivers/dri/intel/intel_pixel_read.c
2787 @@ -236,14 +236,14 @@ do_blit_readpixels(GLcontext * ctx,
2788     intelFlush(&intel->ctx);
2789     LOCK_HARDWARE(intel);
2790  
2791 -   if (intel->driDrawable->numClipRects) {
2792 +   if (intel->driReadDrawable->numClipRects) {
2793        GLboolean all = (width * height * src->cpp == dst->Base.Size &&
2794                         x == 0 && dst_offset == 0);
2795  
2796        dri_bo *dst_buffer = intel_bufferobj_buffer(intel, dst,
2797                                                   all ? INTEL_WRITE_FULL :
2798                                                   INTEL_WRITE_PART);
2799 -      __DRIdrawablePrivate *dPriv = intel->driDrawable;
2800 +      __DRIdrawablePrivate *dPriv = intel->driReadDrawable;
2801        int nbox = dPriv->numClipRects;
2802        drm_clip_rect_t *box = dPriv->pClipRects;
2803        drm_clip_rect_t rect;
2804 diff --git a/src/mesa/drivers/dri/intel/intel_regions.h b/src/mesa/drivers/dri/intel/intel_regions.h
2805 index 0d379bd..535fcd7 100644
2806 --- a/src/mesa/drivers/dri/intel/intel_regions.h
2807 +++ b/src/mesa/drivers/dri/intel/intel_regions.h
2808 @@ -62,6 +62,8 @@ struct intel_region
2809     GLuint map_refcount;  /**< Reference count for mapping */
2810  
2811     GLuint draw_offset; /**< Offset of drawing address within the region */
2812 +   GLuint draw_x, draw_y; /**< Offset of drawing within the region */
2813 +
2814     uint32_t tiling; /**< Which tiling mode the region is in */
2815     uint32_t bit_6_swizzle; /**< GEM flag for address swizzling requirement */
2816     drmAddress classic_map; /**< drmMap of the region when not in GEM mode */
2817 diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
2818 index 8df4990..e71366a 100644
2819 --- a/src/mesa/drivers/dri/intel/intel_span.c
2820 +++ b/src/mesa/drivers/dri/intel/intel_span.c
2821 @@ -163,6 +163,9 @@ static uint32_t x_tile_swizzle(struct intel_renderbuffer *irb,
2822         int     x_tile_number, y_tile_number;
2823         int     tile_off, tile_base;
2824         
2825 +        x += irb->region->draw_x;
2826 +        y += irb->region->draw_y;
2827 +
2828         tile_stride = (irb->region->pitch * irb->region->cpp) << 3;
2829  
2830         xbyte = x * irb->region->cpp;
2831 @@ -218,6 +221,9 @@ static uint32_t y_tile_swizzle(struct intel_renderbuffer *irb,
2832         int     x_tile_number, y_tile_number;
2833         int     tile_off, tile_base;
2834         
2835 +        x += irb->region->draw_x;
2836 +        y += irb->region->draw_y;
2837 +
2838         tile_stride = (irb->region->pitch * irb->region->cpp) << 5;
2839  
2840         xbyte = x * irb->region->cpp;
2841 diff --git a/src/mesa/drivers/dri/intel/intel_syncobj.c b/src/mesa/drivers/dri/intel/intel_syncobj.c
2842 index 1286fe9..0d7889d 100644
2843 --- a/src/mesa/drivers/dri/intel/intel_syncobj.c
2844 +++ b/src/mesa/drivers/dri/intel/intel_syncobj.c
2845 @@ -114,7 +114,7 @@ static void intel_check_sync(GLcontext *ctx, struct gl_sync_object *s)
2846  {
2847     struct intel_sync_object *sync = (struct intel_sync_object *)s;
2848  
2849 -   if (sync->bo && drm_intel_bo_busy(sync->bo)) {
2850 +   if (sync->bo && !drm_intel_bo_busy(sync->bo)) {
2851        drm_intel_bo_unreference(sync->bo);
2852        sync->bo = NULL;
2853        s->StatusFlag = 1;
2854 diff --git a/src/mesa/drivers/dri/intel/intel_tex_copy.c b/src/mesa/drivers/dri/intel/intel_tex_copy.c
2855 index 74f7f58..95dee60 100644
2856 --- a/src/mesa/drivers/dri/intel/intel_tex_copy.c
2857 +++ b/src/mesa/drivers/dri/intel/intel_tex_copy.c
2858 @@ -115,27 +115,29 @@ do_copy_texsubimage(struct intel_context *intel,
2859        drm_intel_bo *dst_bo = intel_region_buffer(intel,
2860                                                  intelImage->mt->region,
2861                                                  INTEL_WRITE_PART);
2862 -      GLuint image_offset = intel_miptree_image_offset(intelImage->mt,
2863 -                                                       intelImage->face,
2864 -                                                       intelImage->level);
2865        const GLint orig_x = x;
2866        const GLint orig_y = y;
2867 +      GLuint image_x, image_y;
2868        GLshort src_pitch;
2869  
2870 +      intel_miptree_get_image_offset(intelImage->mt,
2871 +                                    intelImage->level,
2872 +                                    intelImage->face,
2873 +                                    0,
2874 +                                    &image_x, &image_y);
2875        /* Update dst for clipped src.  Need to also clip the source rect. */
2876        dstx += x - orig_x;
2877        dsty += y - orig_y;
2878  
2879        /* Can't blit to tiled buffers with non-tile-aligned offset. */
2880 -      if (intelImage->mt->region->tiling != I915_TILING_NONE &&
2881 -         (image_offset & 4095) != 0) {
2882 +      if (intelImage->mt->region->tiling == I915_TILING_Y) {
2883          UNLOCK_HARDWARE(intel);
2884          return GL_FALSE;
2885        }
2886  
2887        if (ctx->ReadBuffer->Name == 0) {
2888          /* reading from a window, adjust x, y */
2889 -        __DRIdrawablePrivate *dPriv = intel->driDrawable;
2890 +        const __DRIdrawablePrivate *dPriv = intel->driReadDrawable;
2891          y = dPriv->y + (dPriv->h - (y + height));
2892          x += dPriv->x;
2893  
2894 @@ -156,13 +158,14 @@ do_copy_texsubimage(struct intel_context *intel,
2895                              intelImage->mt->cpp,
2896                              src_pitch,
2897                              src->buffer,
2898 -                            0,
2899 +                            src->draw_offset,
2900                              src->tiling,
2901                              intelImage->mt->pitch,
2902                              dst_bo,
2903 -                            image_offset,
2904 +                            0,
2905                              intelImage->mt->region->tiling,
2906 -                            x, y, dstx, dsty, width, height,
2907 +                            x, y, image_x + dstx, image_y + dsty,
2908 +                            width, height,
2909                              GL_COPY)) {
2910          UNLOCK_HARDWARE(intel);
2911          return GL_FALSE;
2912 diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
2913 index c5f5220..2e0945c 100644
2914 --- a/src/mesa/drivers/dri/intel/intel_tex_image.c
2915 +++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
2916 @@ -204,7 +204,7 @@ try_pbo_upload(struct intel_context *intel,
2917  {
2918     struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
2919     GLuint src_offset, src_stride;
2920 -   GLuint dst_offset, dst_stride;
2921 +   GLuint dst_x, dst_y, dst_stride;
2922  
2923     if (unpack->BufferObj->Name == 0 ||
2924         intel->ctx._ImageTransferState ||
2925 @@ -221,9 +221,9 @@ try_pbo_upload(struct intel_context *intel,
2926     else
2927        src_stride = width;
2928  
2929 -   dst_offset = intel_miptree_image_offset(intelImage->mt,
2930 -                                           intelImage->face,
2931 -                                           intelImage->level);
2932 +   intel_miptree_get_image_offset(intelImage->mt, intelImage->level,
2933 +                                 intelImage->face, 0,
2934 +                                 &dst_x, &dst_y);
2935  
2936     dst_stride = intelImage->mt->pitch;
2937  
2938 @@ -239,8 +239,8 @@ try_pbo_upload(struct intel_context *intel,
2939        if (!intelEmitCopyBlit(intel,
2940                              intelImage->mt->cpp,
2941                              src_stride, src_buffer, src_offset, GL_FALSE,
2942 -                            dst_stride, dst_buffer, dst_offset, GL_FALSE,
2943 -                            0, 0, 0, 0, width, height,
2944 +                            dst_stride, dst_buffer, 0, GL_FALSE,
2945 +                            0, 0, dst_x, dst_y, width, height,
2946                              GL_COPY)) {
2947          UNLOCK_HARDWARE(intel);
2948          return GL_FALSE;
2949 @@ -262,7 +262,7 @@ try_pbo_zcopy(struct intel_context *intel,
2950  {
2951     struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
2952     GLuint src_offset, src_stride;
2953 -   GLuint dst_offset, dst_stride;
2954 +   GLuint dst_x, dst_y, dst_stride;
2955  
2956     if (unpack->BufferObj->Name == 0 ||
2957         intel->ctx._ImageTransferState ||
2958 @@ -279,13 +279,14 @@ try_pbo_zcopy(struct intel_context *intel,
2959     else
2960        src_stride = width;
2961  
2962 -   dst_offset = intel_miptree_image_offset(intelImage->mt,
2963 -                                           intelImage->face,
2964 -                                           intelImage->level);
2965 +   intel_miptree_get_image_offset(intelImage->mt, intelImage->level,
2966 +                                 intelImage->face, 0,
2967 +                                 &dst_x, &dst_y);
2968  
2969     dst_stride = intelImage->mt->pitch;
2970  
2971 -   if (src_stride != dst_stride || dst_offset != 0 || src_offset != 0) {
2972 +   if (src_stride != dst_stride || dst_x != 0 || dst_y != 0 ||
2973 +       src_offset != 0) {
2974        DBG("%s: failure 2\n", __FUNCTION__);
2975        return GL_FALSE;
2976     }
2977 diff --git a/src/mesa/drivers/dri/r200/r200_state.c b/src/mesa/drivers/dri/r200/r200_state.c
2978 index 76852e3..d28e96d 100644
2979 --- a/src/mesa/drivers/dri/r200/r200_state.c
2980 +++ b/src/mesa/drivers/dri/r200/r200_state.c
2981 @@ -1578,13 +1578,6 @@ static void r200ClearStencil( GLcontext *ctx, GLint s )
2982   * Window position and viewport transformation
2983   */
2984  
2985 -/*
2986 - * To correctly position primitives:
2987 - */
2988 -#define SUBPIXEL_X 0.125
2989 -#define SUBPIXEL_Y 0.125
2990 -
2991 -
2992  /**
2993   * Called when window size or position changes or viewport or depth range
2994   * state is changed.  We update the hardware viewport state here.
2995 @@ -1609,9 +1602,9 @@ void r200UpdateWindow( GLcontext *ctx )
2996     }
2997  
2998     float_ui32_type sx = { v[MAT_SX] };
2999 -   float_ui32_type tx = { v[MAT_TX] + xoffset + SUBPIXEL_X };
3000 +   float_ui32_type tx = { v[MAT_TX] + xoffset };
3001     float_ui32_type sy = { v[MAT_SY] * y_scale };
3002 -   float_ui32_type ty = { (v[MAT_TY] * y_scale) + y_bias + SUBPIXEL_Y };
3003 +   float_ui32_type ty = { (v[MAT_TY] * y_scale) + y_bias };
3004     float_ui32_type sz = { v[MAT_SZ] * depthScale };
3005     float_ui32_type tz = { v[MAT_TZ] * depthScale };
3006  
3007 @@ -1680,8 +1673,8 @@ void r200UpdateViewportOffset( GLcontext *ctx )
3008     float_ui32_type tx;
3009     float_ui32_type ty;
3010  
3011 -   tx.f = v[MAT_TX] + xoffset + SUBPIXEL_X;
3012 -   ty.f = (- v[MAT_TY]) + yoffset + SUBPIXEL_Y;
3013 +   tx.f = v[MAT_TX] + xoffset;
3014 +   ty.f = (- v[MAT_TY]) + yoffset;
3015  
3016     if ( rmesa->hw.vpt.cmd[VPT_SE_VPORT_XOFFSET] != tx.ui32 ||
3017         rmesa->hw.vpt.cmd[VPT_SE_VPORT_YOFFSET] != ty.ui32 )
3018 diff --git a/src/mesa/drivers/dri/r300/r300_context.c b/src/mesa/drivers/dri/r300/r300_context.c
3019 index 2ea1b82..9df3897 100644
3020 --- a/src/mesa/drivers/dri/r300/r300_context.c
3021 +++ b/src/mesa/drivers/dri/r300/r300_context.c
3022 @@ -374,11 +374,21 @@ static void r300InitConstValues(GLcontext *ctx, radeonScreenPtr screen)
3023         if (screen->chip_family >= CHIP_FAMILY_RV515) {
3024                 ctx->Const.FragmentProgram.MaxNativeTemps = R500_PFS_NUM_TEMP_REGS;
3025                 ctx->Const.FragmentProgram.MaxNativeAttribs = 11;       /* copy i915... */
3026 -               ctx->Const.FragmentProgram.MaxNativeParameters = R500_PFS_NUM_CONST_REGS;
3027 -               ctx->Const.FragmentProgram.MaxNativeAluInstructions = R500_PFS_MAX_INST;
3028 -               ctx->Const.FragmentProgram.MaxNativeTexInstructions = R500_PFS_MAX_INST;
3029 -               ctx->Const.FragmentProgram.MaxNativeInstructions = R500_PFS_MAX_INST;
3030 -               ctx->Const.FragmentProgram.MaxNativeTexIndirections = R500_PFS_MAX_INST;
3031 +
3032 +               /* The hardware limits are higher than this,
3033 +                * but the non-KMS DRM interface artificially limits us
3034 +                * to this many instructions.
3035 +                *
3036 +                * We could of course work around it in the KMS path,
3037 +                * but it would be a mess, so it seems wiser
3038 +                * to leave it as is. Going forward, the Gallium driver
3039 +                * will not be subject to these limitations.
3040 +                */
3041 +               ctx->Const.FragmentProgram.MaxNativeParameters = 255;
3042 +               ctx->Const.FragmentProgram.MaxNativeAluInstructions = 255;
3043 +               ctx->Const.FragmentProgram.MaxNativeTexInstructions = 255;
3044 +               ctx->Const.FragmentProgram.MaxNativeInstructions = 255;
3045 +               ctx->Const.FragmentProgram.MaxNativeTexIndirections = 255;
3046                 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0;
3047         } else {
3048                 ctx->Const.FragmentProgram.MaxNativeTemps = R300_PFS_NUM_TEMP_REGS;
3049 diff --git a/src/mesa/drivers/dri/r300/r300_fragprog_common.c b/src/mesa/drivers/dri/r300/r300_fragprog_common.c
3050 index 0bdc90b..70c9252 100644
3051 --- a/src/mesa/drivers/dri/r300/r300_fragprog_common.c
3052 +++ b/src/mesa/drivers/dri/r300/r300_fragprog_common.c
3053 @@ -239,6 +239,19 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog
3054         rewriteFog(&compiler, fp);
3055  
3056         r3xx_compile_fragment_program(&compiler);
3057 +
3058 +       if (compiler.is_r500) {
3059 +               /* We need to support the non-KMS DRM interface, which
3060 +                * artificially limits the number of instructions and
3061 +                * constants which are available to us.
3062 +                *
3063 +                * See also the comment in r300_context.c where we
3064 +                * set the MAX_NATIVE_xxx values.
3065 +                */
3066 +               if (fp->code.code.r500.inst_end >= 255 || fp->code.constants.Count > 255)
3067 +                       rc_error(&compiler.Base, "Program is too big (upgrade to r300g to avoid this limitation).\n");
3068 +       }
3069 +
3070         fp->error = compiler.Base.Error;
3071  
3072         fp->InputsRead = compiler.Base.Program.InputsRead;
3073 diff --git a/src/mesa/drivers/dri/r300/r300_texstate.c b/src/mesa/drivers/dri/r300/r300_texstate.c
3074 index f030451..65cabcc 100644
3075 --- a/src/mesa/drivers/dri/r300/r300_texstate.c
3076 +++ b/src/mesa/drivers/dri/r300/r300_texstate.c
3077 @@ -225,10 +225,10 @@ static void setup_hardware_state(r300ContextPtr rmesa, radeonTexObj *t)
3078         if (t->image_override && t->bo)
3079                 return;
3080  
3081 -       t->pp_txsize = (((firstImage->Width - 1) << R300_TX_WIDTHMASK_SHIFT)
3082 -                       | ((firstImage->Height - 1) << R300_TX_HEIGHTMASK_SHIFT)
3083 -                       | ((firstImage->DepthLog2) << R300_TX_DEPTHMASK_SHIFT)
3084 -                       | ((t->mt->lastLevel - t->mt->firstLevel) << R300_TX_MAX_MIP_LEVEL_SHIFT));
3085 +       t->pp_txsize = (((R300_TX_WIDTHMASK_MASK & ((firstImage->Width - 1) << R300_TX_WIDTHMASK_SHIFT)))
3086 +                       | ((R300_TX_HEIGHTMASK_MASK & ((firstImage->Height - 1) << R300_TX_HEIGHTMASK_SHIFT)))
3087 +                       | ((R300_TX_DEPTHMASK_MASK & ((firstImage->DepthLog2) << R300_TX_DEPTHMASK_SHIFT)))
3088 +                       | ((R300_TX_MAX_MIP_LEVEL_MASK & ((t->mt->lastLevel - t->mt->firstLevel) << R300_TX_MAX_MIP_LEVEL_SHIFT))));
3089  
3090         t->tile_bits = 0;
3091  
3092 @@ -248,8 +248,12 @@ static void setup_hardware_state(r300ContextPtr rmesa, radeonTexObj *t)
3093         if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) {
3094             if (firstImage->Width > 2048)
3095                 t->pp_txpitch |= R500_TXWIDTH_BIT11;
3096 +            else
3097 +               t->pp_txpitch &= ~R500_TXWIDTH_BIT11;
3098             if (firstImage->Height > 2048)
3099                 t->pp_txpitch |= R500_TXHEIGHT_BIT11;
3100 +            else
3101 +               t->pp_txpitch &= ~R500_TXHEIGHT_BIT11;
3102         }
3103  }
3104  
3105 @@ -479,16 +483,20 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
3106                 break;
3107         }
3108         pitch_val--;
3109 -       t->pp_txsize = ((rb->base.Width - 1) << R300_TX_WIDTHMASK_SHIFT) |
3110 -              ((rb->base.Height - 1) << R300_TX_HEIGHTMASK_SHIFT);
3111 +       t->pp_txsize = (((R300_TX_WIDTHMASK_MASK & ((rb->base.Width - 1) << R300_TX_WIDTHMASK_SHIFT)))
3112 +                       | ((R300_TX_HEIGHTMASK_MASK & ((rb->base.Height - 1) << R300_TX_HEIGHTMASK_SHIFT))));
3113         t->pp_txsize |= R300_TX_SIZE_TXPITCH_EN;
3114         t->pp_txpitch |= pitch_val;
3115  
3116         if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) {
3117             if (rb->base.Width > 2048)
3118                 t->pp_txpitch |= R500_TXWIDTH_BIT11;
3119 +            else
3120 +               t->pp_txpitch &= ~R500_TXWIDTH_BIT11;
3121             if (rb->base.Height > 2048)
3122                 t->pp_txpitch |= R500_TXHEIGHT_BIT11;
3123 +            else
3124 +               t->pp_txpitch &= ~R500_TXHEIGHT_BIT11;
3125         }
3126         t->validated = GL_TRUE;
3127         _mesa_unlock_texture(radeon->glCtx, texObj);
3128 diff --git a/src/mesa/drivers/dri/r300/r300_vertprog.c b/src/mesa/drivers/dri/r300/r300_vertprog.c
3129 index 2f7b67c..ed8b788 100644
3130 --- a/src/mesa/drivers/dri/r300/r300_vertprog.c
3131 +++ b/src/mesa/drivers/dri/r300/r300_vertprog.c
3132 @@ -62,12 +62,6 @@ static int r300VertexProgUpdateParams(GLcontext * ctx, struct r300_vertex_progra
3133                 }
3134         }
3135  
3136 -       if (vp->code.constants.Count * 4 > VSF_MAX_FRAGMENT_LENGTH) {
3137 -               /* Should have checked this earlier... */
3138 -               fprintf(stderr, "%s:Params exhausted\n", __FUNCTION__);
3139 -               _mesa_exit(-1);
3140 -       }
3141 -
3142         for(i = 0; i < vp->code.constants.Count; ++i) {
3143                 const float * src = 0;
3144                 const struct rc_constant * constant = &vp->code.constants.Constants[i];
3145 @@ -281,6 +275,11 @@ static struct r300_vertex_program *build_program(GLcontext *ctx,
3146         }
3147  
3148         r3xx_compile_vertex_program(&compiler);
3149 +
3150 +       if (vp->code.constants.Count > ctx->Const.VertexProgram.MaxParameters) {
3151 +               rc_error(&compiler.Base, "Program exceeds constant buffer size limit\n");
3152 +       }
3153 +
3154         vp->error = compiler.Base.Error;
3155  
3156         vp->Base->Base.InputsRead = vp->code.InputsRead;
3157 @@ -334,7 +333,6 @@ struct r300_vertex_program * r300SelectAndTranslateVertexShader(GLcontext *ctx)
3158  #define bump_vpu_count(ptr, new_count)   do { \
3159                 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr)); \
3160                 int _nc=(new_count)/4; \
3161 -               assert(_nc < 256); \
3162                 if(_nc>_p->vpu.count)_p->vpu.count=_nc; \
3163         } while(0)
3164  
3165 diff --git a/src/mesa/drivers/dri/r600/r600_cmdbuf.c b/src/mesa/drivers/dri/r600/r600_cmdbuf.c
3166 index 3cfe03a..d27a324 100644
3167 --- a/src/mesa/drivers/dri/r600/r600_cmdbuf.c
3168 +++ b/src/mesa/drivers/dri/r600/r600_cmdbuf.c
3169 @@ -254,7 +254,7 @@ static int r600_cs_process_relocs(struct radeon_cs *cs,
3170      relocs = (struct r600_cs_reloc_legacy *)cs->relocs;
3171  restart:
3172      for (i = 0; i < cs->crelocs; i++) {
3173 -            uint32_t soffset, eoffset, asicoffset;
3174 +            uint32_t soffset, eoffset;
3175  
3176              r = radeon_bo_legacy_validate(relocs[i].base.bo,
3177                                           &soffset, &eoffset);
3178 @@ -262,24 +262,12 @@ restart:
3179                     goto restart;
3180              }
3181              if (r) {
3182 -                   fprintf(stderr, "validated %p [0x%08X, 0x%08X]\n",
3183 +                   fprintf(stderr, "invalid bo(%p) [0x%08X, 0x%08X]\n",
3184                             relocs[i].base.bo, soffset, eoffset);
3185                     return r;
3186              }
3187 -            asicoffset = soffset;
3188  
3189             for (j = 0; j < relocs[i].cindices; j++) {
3190 -                   if (asicoffset >= eoffset) {
3191 -                           /*                radeon_bo_debug(relocs[i].base.bo, 12); */
3192 -                           fprintf(stderr, "validated %p [0x%08X, 0x%08X]\n",
3193 -                                   relocs[i].base.bo, soffset, eoffset);
3194 -                           fprintf(stderr, "above end: %p 0x%08X 0x%08X\n",
3195 -                                   relocs[i].base.bo,
3196 -                                   cs->packets[relocs[i].indices[j]],
3197 -                                   eoffset);
3198 -                           exit(0);
3199 -                           return -EINVAL;
3200 -                   }
3201                     /* pkt3 nop header in ib chunk */
3202                     cs->packets[relocs[i].reloc_indices[j]] = 0xC0001000;
3203                     /* reloc index in ib chunk */
3204 @@ -287,7 +275,7 @@ restart:
3205             }
3206  
3207             /* asic offset in reloc chunk */ /* see alex drm r600_nomm_relocate */
3208 -           reloc_chunk[offset_dw] = asicoffset;
3209 +           reloc_chunk[offset_dw] = soffset;
3210             reloc_chunk[offset_dw + 3] = 0;
3211  
3212             offset_dw += 4;
3213 diff --git a/src/mesa/drivers/dri/r600/r600_texstate.c b/src/mesa/drivers/dri/r600/r600_texstate.c
3214 index bcb8d7c..a30703e 100644
3215 --- a/src/mesa/drivers/dri/r600/r600_texstate.c
3216 +++ b/src/mesa/drivers/dri/r600/r600_texstate.c
3217 @@ -721,7 +721,9 @@ void r600SetTexOffset(__DRIcontext * pDRICtx, GLint texname,
3218         struct gl_texture_object *tObj =
3219             _mesa_lookup_texture(rmesa->radeon.glCtx, texname);
3220         radeonTexObjPtr t = radeon_tex_obj(tObj);
3221 -       uint32_t pitch_val, size;
3222 +       int firstlevel = t->mt ? t->mt->firstLevel : 0;
3223 +       const struct gl_texture_image *firstImage;
3224 +       uint32_t pitch_val, size, row_align, bpp;
3225  
3226         if (!tObj)
3227                 return;
3228 @@ -731,7 +733,13 @@ void r600SetTexOffset(__DRIcontext * pDRICtx, GLint texname,
3229         if (!offset)
3230                 return;
3231  
3232 -       size = pitch;//h * w * (depth / 8);
3233 +       bpp = depth / 8;
3234 +       if (bpp == 3) 
3235 +               bpp = 4;
3236 +
3237 +       firstImage = t->base.Image[0][firstlevel];
3238 +       row_align = rmesa->radeon.texture_row_align - 1;
3239 +       size = ((firstImage->Width * bpp + row_align) & ~row_align) * firstImage->Height;
3240         if (t->bo) {
3241                 radeon_bo_unref(t->bo);
3242                 t->bo = NULL;
3243 diff --git a/src/mesa/drivers/dri/r600/r700_assembler.c b/src/mesa/drivers/dri/r600/r700_assembler.c
3244 index 00eda54..6ff08e1 100644
3245 --- a/src/mesa/drivers/dri/r600/r700_assembler.c
3246 +++ b/src/mesa/drivers/dri/r600/r700_assembler.c
3247 @@ -336,7 +336,8 @@ unsigned int r700GetNumOperands(r700_AssemblerBase* pAsm)
3248  
3249      switch (pAsm->D.dst.opcode)
3250      {
3251 -    case SQ_OP2_INST_ADD:                          
3252 +    case SQ_OP2_INST_ADD:
3253 +    case SQ_OP2_INST_KILLGT:
3254      case SQ_OP2_INST_MUL: 
3255      case SQ_OP2_INST_MAX:
3256      case SQ_OP2_INST_MIN:
3257 @@ -354,9 +355,9 @@ unsigned int r700GetNumOperands(r700_AssemblerBase* pAsm)
3258          return 2;  
3259  
3260      case SQ_OP2_INST_MOV: 
3261 +    case SQ_OP2_INST_MOVA_FLOOR:
3262      case SQ_OP2_INST_FRACT:
3263      case SQ_OP2_INST_FLOOR:
3264 -    case SQ_OP2_INST_KILLGT:
3265      case SQ_OP2_INST_EXP_IEEE:
3266      case SQ_OP2_INST_LOG_CLAMPED:
3267      case SQ_OP2_INST_LOG_IEEE:
3268 @@ -1180,8 +1181,10 @@ GLboolean tex_src(r700_AssemblerBase *pAsm)
3269          case PROGRAM_INPUT:
3270              switch (pILInst->SrcReg[0].Index)
3271              {
3272 +                case FRAG_ATTRIB_WPOS:
3273                  case FRAG_ATTRIB_COL0:
3274                  case FRAG_ATTRIB_COL1:
3275 +                case FRAG_ATTRIB_FOGC:
3276                  case FRAG_ATTRIB_TEX0:
3277                  case FRAG_ATTRIB_TEX1:
3278                  case FRAG_ATTRIB_TEX2:
3279 @@ -1194,7 +1197,16 @@ GLboolean tex_src(r700_AssemblerBase *pAsm)
3280                      pAsm->S[0].src.reg   =
3281                          pAsm->uiFP_AttributeMap[pILInst->SrcReg[0].Index];
3282                      pAsm->S[0].src.rtype = SRC_REG_INPUT;
3283 -                break;
3284 +                    break;
3285 +                case FRAG_ATTRIB_FACE:
3286 +                    fprintf(stderr, "FRAG_ATTRIB_FACE unsupported\n");
3287 +                    break;
3288 +                case FRAG_ATTRIB_PNTC:
3289 +                    fprintf(stderr, "FRAG_ATTRIB_PNTC unsupported\n");
3290 +                    break;
3291 +                case FRAG_ATTRIB_VAR0:
3292 +                    fprintf(stderr, "FRAG_ATTRIB_VAR0 unsupported\n");
3293 +                    break;
3294              }
3295          break;
3296          }
3297 @@ -2053,7 +2065,7 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm)
3298          }
3299  
3300          //other bits
3301 -        alu_instruction_ptr->m_Word0.f.index_mode = SQ_INDEX_LOOP;
3302 +        alu_instruction_ptr->m_Word0.f.index_mode = SQ_INDEX_AR_X;
3303  
3304          if(   (is_single_scalar_operation == GL_TRUE) 
3305             || (GL_TRUE == bSplitInst) )
3306 @@ -2387,6 +2399,35 @@ GLboolean assemble_ADD(r700_AssemblerBase *pAsm)
3307      return GL_TRUE;
3308  }
3309  
3310 +GLboolean assemble_ARL(r700_AssemblerBase *pAsm)
3311 +{ /* TODO: ar values dont' persist between clauses */
3312 +    if( GL_FALSE == checkop1(pAsm) )
3313 +    {
3314 +        return GL_FALSE;
3315 +    }
3316 +
3317 +    pAsm->D.dst.opcode = SQ_OP2_INST_MOVA_FLOOR;
3318 +    setaddrmode_PVSDST(&(pAsm->D.dst), ADDR_ABSOLUTE);
3319 +    pAsm->D.dst.rtype = DST_REG_TEMPORARY;
3320 +    pAsm->D.dst.reg = 0;
3321 +    pAsm->D.dst.writex = 0;
3322 +    pAsm->D.dst.writey = 0;
3323 +    pAsm->D.dst.writez = 0;
3324 +    pAsm->D.dst.writew = 0;
3325 +
3326 +    if( GL_FALSE == assemble_src(pAsm, 0, -1) )
3327 +    {
3328 +        return GL_FALSE;
3329 +    }
3330 +
3331 +    if( GL_FALSE == next_ins(pAsm) )
3332 +    {
3333 +        return GL_FALSE;
3334 +    }
3335 +
3336 +    return GL_TRUE;
3337 +}
3338 +
3339  GLboolean assemble_BAD(char *opcode_str) 
3340  {
3341      radeon_error("Not yet implemented instruction (%s)\n", opcode_str);
3342 @@ -2508,7 +2549,7 @@ GLboolean assemble_DOT(r700_AssemblerBase *pAsm)
3343      }
3344      else if(pAsm->pILInst[pAsm->uiCurInst].Opcode == OPCODE_DPH) 
3345      {
3346 -        onecomp_PVSSRC(&(pAsm->S[1].src), 3);
3347 +        onecomp_PVSSRC(&(pAsm->S[0].src), 3);
3348      } 
3349  
3350      if ( GL_FALSE == next_ins(pAsm) ) 
3351 @@ -2617,15 +2658,15 @@ GLboolean assemble_FRC(r700_AssemblerBase *pAsm)
3352   
3353  GLboolean assemble_KIL(r700_AssemblerBase *pAsm)
3354  {
3355 +    /* TODO: doc says KILL has to be last(end) ALU clause */
3356 +    
3357      checkop1(pAsm);
3358  
3359      pAsm->D.dst.opcode = SQ_OP2_INST_KILLGT;  
3360 -  
3361 -    if ( GL_FALSE == assemble_dst(pAsm) )
3362 -    {
3363 -        return GL_FALSE;
3364 -    }
3365  
3366 +    setaddrmode_PVSDST(&(pAsm->D.dst), ADDR_ABSOLUTE);
3367 +    pAsm->D.dst.rtype = DST_REG_TEMPORARY;
3368 +    pAsm->D.dst.reg   = 0;
3369      pAsm->D.dst.writex = 0;
3370      pAsm->D.dst.writey = 0;
3371      pAsm->D.dst.writez = 0;
3372 @@ -2638,20 +2679,11 @@ GLboolean assemble_KIL(r700_AssemblerBase *pAsm)
3373      setswizzle_PVSSRC(&(pAsm->S[0].src), SQ_SEL_0);
3374      noneg_PVSSRC(&(pAsm->S[0].src));
3375  
3376 -    pAsm->S[1].src.rtype = SRC_REG_TEMPORARY;
3377 -
3378 -    if(PROGRAM_TEMPORARY == pAsm->pILInst[pAsm->uiCurInst].DstReg.File)
3379 +    if ( GL_FALSE == assemble_src(pAsm, 0, 1) )
3380      {
3381 -        pAsm->S[1].src.reg = pAsm->pILInst[pAsm->uiCurInst].DstReg.Index + pAsm->starting_temp_register_number;
3382 -    }
3383 -    else
3384 -    {   //PROGRAM_OUTPUT
3385 -        pAsm->S[1].src.reg = pAsm->uiFP_OutputMap[pAsm->pILInst[pAsm->uiCurInst].DstReg.Index];
3386 +        return GL_FALSE;
3387      }
3388    
3389 -    setaddrmode_PVSSRC(&(pAsm->S[1].src), ADDR_ABSOLUTE);
3390 -    noswizzle_PVSSRC(&(pAsm->S[1].src));
3391 -  
3392      if ( GL_FALSE == next_ins(pAsm) )
3393      {
3394          return GL_FALSE;
3395 @@ -2908,6 +2940,7 @@ GLboolean assemble_LIT(r700_AssemblerBase *pAsm)
3396      pAsm->S[0].src.rtype = srcType;
3397      pAsm->S[0].src.reg   = srcReg;
3398      setaddrmode_PVSSRC(&(pAsm->S[0].src), ADDR_ABSOLUTE);
3399 +    swizzleagain_PVSSRC(&(pAsm->S[0].src), SQ_SEL_X, SQ_SEL_X, SQ_SEL_X, SQ_SEL_X);
3400      pAsm->S[1].src.rtype = SRC_REG_TEMPORARY;
3401      pAsm->S[1].src.reg   = tmp;
3402      setaddrmode_PVSSRC(&(pAsm->S[1].src), ADDR_ABSOLUTE);
3403 @@ -3809,8 +3842,7 @@ GLboolean AssembleInstr(GLuint uiNumberInsts,
3404              break;  
3405  
3406          case OPCODE_ARL: 
3407 -            radeon_error("Not yet implemented instruction OPCODE_ARL \n");
3408 -            //if ( GL_FALSE == assemble_BAD("ARL") ) 
3409 +            if ( GL_FALSE == assemble_ARL(pR700AsmCode) ) 
3410                  return GL_FALSE;
3411              break;
3412          case OPCODE_ARR: 
3413 @@ -4155,6 +4187,7 @@ GLboolean Process_Fragment_Exports(r700_AssemblerBase *pR700AsmCode,
3414                                     GLbitfield          OutputsWritten)  
3415  { 
3416      unsigned int unBit;
3417 +    GLuint export_count = 0;
3418  
3419      if(pR700AsmCode->depth_export_register_number >= 0) 
3420      {
3421 @@ -4176,6 +4209,7 @@ GLboolean Process_Fragment_Exports(r700_AssemblerBase *pR700AsmCode,
3422          {
3423              return GL_FALSE;
3424          }
3425 +        export_count++;
3426         }
3427         unBit = 1 << FRAG_RESULT_DEPTH;
3428         if(OutputsWritten & unBit)
3429 @@ -4189,8 +4223,15 @@ GLboolean Process_Fragment_Exports(r700_AssemblerBase *pR700AsmCode,
3430          {
3431              return GL_FALSE;
3432          }
3433 +        export_count++;
3434         }
3435 -
3436 +    /* Need to export something, otherwise we'll hang
3437 +     * results are undefined anyway */
3438 +    if(export_count == 0)
3439 +    {
3440 +        Process_Export(pR700AsmCode, SQ_EXPORT_PIXEL, 0, 1, 0, GL_FALSE);
3441 +    }
3442 +    
3443      if(pR700AsmCode->cf_last_export_ptr != NULL) 
3444      {
3445          pR700AsmCode->cf_last_export_ptr->m_Word1.f.cf_inst        = SQ_CF_INST_EXPORT_DONE;
3446 diff --git a/src/mesa/drivers/dri/r600/r700_assembler.h b/src/mesa/drivers/dri/r600/r700_assembler.h
3447 index 73bb8ba..d639592 100644
3448 --- a/src/mesa/drivers/dri/r600/r700_assembler.h
3449 +++ b/src/mesa/drivers/dri/r600/r700_assembler.h
3450 @@ -461,6 +461,7 @@ GLboolean next_ins(r700_AssemblerBase *pAsm);
3451  GLboolean assemble_math_function(r700_AssemblerBase* pAsm, BITS opcode);
3452  GLboolean assemble_ABS(r700_AssemblerBase *pAsm);
3453  GLboolean assemble_ADD(r700_AssemblerBase *pAsm);
3454 +GLboolean assemble_ARL(r700_AssemblerBase *pAsm);
3455  GLboolean assemble_BAD(char *opcode_str);
3456  GLboolean assemble_CMP(r700_AssemblerBase *pAsm);
3457  GLboolean assemble_COS(r700_AssemblerBase *pAsm);
3458 diff --git a/src/mesa/drivers/dri/r600/r700_fragprog.c b/src/mesa/drivers/dri/r600/r700_fragprog.c
3459 index 78ce3ae..0f549ea 100644
3460 --- a/src/mesa/drivers/dri/r600/r700_fragprog.c
3461 +++ b/src/mesa/drivers/dri/r600/r700_fragprog.c
3462 @@ -135,15 +135,19 @@ GLboolean Find_Instruction_Dependencies_fp(struct r700_fragment_program *fp,
3463  {
3464      GLuint i, j;
3465      GLint * puiTEMPwrites;
3466 +    GLint * puiTEMPreads;
3467      struct prog_instruction * pILInst;
3468      InstDeps         *pInstDeps;
3469      struct prog_instruction * texcoord_DepInst;
3470      GLint              nDepInstID;
3471  
3472      puiTEMPwrites = (GLint*) MALLOC(sizeof(GLuint)*mesa_fp->Base.NumTemporaries);
3473 +    puiTEMPreads = (GLint*) MALLOC(sizeof(GLuint)*mesa_fp->Base.NumTemporaries);
3474 +
3475      for(i=0; i<mesa_fp->Base.NumTemporaries; i++)
3476      {
3477          puiTEMPwrites[i] = -1;
3478 +        puiTEMPreads[i] = -1;
3479      }
3480  
3481      pInstDeps = (InstDeps*)MALLOC(sizeof(InstDeps)*mesa_fp->Base.NumInstructions);
3482 @@ -167,6 +171,11 @@ GLboolean Find_Instruction_Dependencies_fp(struct r700_fragment_program *fp,
3483              {
3484                  //Set dep.
3485                  pInstDeps[i].nSrcDeps[j] = puiTEMPwrites[pILInst->SrcReg[j].Index];
3486 +                //Set first read
3487 +                if(puiTEMPreads[pILInst->SrcReg[j].Index] < 0 )
3488 +                {
3489 +                    puiTEMPreads[pILInst->SrcReg[j].Index] = i;
3490 +                }
3491              }
3492              else
3493              {
3494 @@ -177,8 +186,6 @@ GLboolean Find_Instruction_Dependencies_fp(struct r700_fragment_program *fp,
3495  
3496      fp->r700AsmCode.pInstDeps = pInstDeps;
3497  
3498 -    FREE(puiTEMPwrites);
3499 -
3500      //Find dep for tex inst    
3501      for(i=0; i<mesa_fp->Base.NumInstructions; i++)
3502      {
3503 @@ -203,9 +210,25 @@ GLboolean Find_Instruction_Dependencies_fp(struct r700_fragment_program *fp,
3504                  {   //... other deps?
3505                  }
3506              }
3507 +            // make sure that we dont overwrite src used earlier
3508 +            nDepInstID = puiTEMPreads[pILInst->DstReg.Index];
3509 +            if(nDepInstID < i)
3510 +            {
3511 +                pInstDeps[i].nDstDep = puiTEMPreads[pILInst->DstReg.Index];
3512 +                texcoord_DepInst = &(mesa_fp->Base.Instructions[nDepInstID]);
3513 +                if(GL_TRUE == IsAlu(texcoord_DepInst->Opcode) )
3514 +                {
3515 +                    pInstDeps[nDepInstID].nDstDep = i;
3516 +                }
3517
3518 +            }
3519 +
3520          }
3521         }
3522  
3523 +    FREE(puiTEMPwrites);
3524 +    FREE(puiTEMPreads);
3525 +
3526      return GL_TRUE;
3527  }
3528  
3529 @@ -251,7 +274,15 @@ GLboolean r700TranslateFragmentShader(struct r700_fragment_program *fp,
3530                 number_of_colors_exported--;
3531         }
3532  
3533 -       fp->r700Shader.exportMode = number_of_colors_exported << 1 | z_enabled;
3534 +       /* illegal to set this to 0 */
3535 +       if(number_of_colors_exported || z_enabled)
3536 +       {
3537 +           fp->r700Shader.exportMode = number_of_colors_exported << 1 | z_enabled;
3538 +       }
3539 +       else
3540 +       {
3541 +           fp->r700Shader.exportMode = (1 << 1);
3542 +       }
3543  
3544      fp->translated = GL_TRUE;
3545  
3546 @@ -341,6 +372,11 @@ GLboolean r700SetupFragmentProgram(GLcontext * ctx)
3547          SETbit(r700->SPI_PS_IN_CONTROL_0.u32All, POSITION_ENA_bit);
3548          SETbit(r700->SPI_INPUT_Z.u32All, PROVIDE_Z_TO_SPI_bit);
3549      }
3550 +    else
3551 +    {
3552 +        CLEARbit(r700->SPI_PS_IN_CONTROL_0.u32All, POSITION_ENA_bit);
3553 +        CLEARbit(r700->SPI_INPUT_Z.u32All, PROVIDE_Z_TO_SPI_bit);
3554 +    }
3555  
3556      ui = (unNumOfReg < ui) ? ui : unNumOfReg;
3557  
3558 diff --git a/src/mesa/drivers/dri/r600/r700_oglprog.c b/src/mesa/drivers/dri/r600/r700_oglprog.c
3559 index 5290ef3..0d476fc 100644
3560 --- a/src/mesa/drivers/dri/r600/r700_oglprog.c
3561 +++ b/src/mesa/drivers/dri/r600/r700_oglprog.c
3562 @@ -40,6 +40,24 @@
3563  #include "r700_vertprog.h"
3564  
3565  
3566 +static void freeVertProgCache(GLcontext *ctx, struct r700_vertex_program_cont *cache)
3567 +{
3568 +       struct r700_vertex_program *tmp, *vp = cache->progs;
3569 +
3570 +       while (vp) {
3571 +               tmp = vp->next;
3572 +               /* Release DMA region */
3573 +               r600DeleteShader(ctx, vp->shaderbo);
3574 +               /* Clean up */
3575 +               Clean_Up_Assembler(&(vp->r700AsmCode));
3576 +               Clean_Up_Shader(&(vp->r700Shader));
3577 +               
3578 +               _mesa_reference_vertprog(ctx, &vp->mesa_program, NULL);
3579 +               _mesa_free(vp);
3580 +               vp = tmp;
3581 +       }
3582 +}
3583 +
3584  static struct gl_program *r700NewProgram(GLcontext * ctx, 
3585                                           GLenum target,
3586                                                              GLuint id)
3587 @@ -84,8 +102,7 @@ static struct gl_program *r700NewProgram(GLcontext * ctx,
3588  
3589  static void r700DeleteProgram(GLcontext * ctx, struct gl_program *prog)
3590  {
3591 -    struct r700_vertex_program_cont   * vpc;
3592 -    struct r700_vertex_program *vp, *tmp;
3593 +    struct r700_vertex_program_cont *vpc = (struct r700_vertex_program_cont *)prog;
3594      struct r700_fragment_program * fp;
3595  
3596         radeon_print(RADEON_SHADER, RADEON_VERBOSE,
3597 @@ -95,20 +112,7 @@ static void r700DeleteProgram(GLcontext * ctx, struct gl_program *prog)
3598      {
3599      case GL_VERTEX_STATE_PROGRAM_NV:
3600      case GL_VERTEX_PROGRAM_ARB:            
3601 -        vpc = (struct r700_vertex_program_cont*)prog;
3602 -        vp = vpc->progs;
3603 -       while (vp) {
3604 -               tmp = vp->next;
3605 -               /* Release DMA region */
3606 -        
3607 -               r600DeleteShader(ctx, vp->shaderbo);
3608 -
3609 -               /* Clean up */
3610 -               Clean_Up_Assembler(&(vp->r700AsmCode));
3611 -               Clean_Up_Shader(&(vp->r700Shader));
3612 -               _mesa_free(vp);
3613 -               vp = tmp;
3614 -       }
3615 +           freeVertProgCache(ctx, vpc);
3616             break;
3617      case GL_FRAGMENT_PROGRAM_NV:
3618      case GL_FRAGMENT_PROGRAM_ARB:
3619 @@ -131,7 +135,24 @@ static void r700DeleteProgram(GLcontext * ctx, struct gl_program *prog)
3620  static void
3621  r700ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
3622  {
3623 -
3624 +       struct r700_vertex_program_cont *vpc = (struct r700_vertex_program_cont *)prog;
3625 +       struct r700_fragment_program * fp = (struct r700_fragment_program*)prog;
3626 +
3627 +       switch (target) {
3628 +       case GL_VERTEX_PROGRAM_ARB:
3629 +               freeVertProgCache(ctx, vpc);
3630 +               vpc->progs = NULL;
3631 +               break;
3632 +       case GL_FRAGMENT_PROGRAM_ARB:
3633 +               r600DeleteShader(ctx, fp->shaderbo);
3634 +               Clean_Up_Assembler(&(fp->r700AsmCode));
3635 +               Clean_Up_Shader(&(fp->r700Shader));
3636 +               fp->translated = GL_FALSE;
3637 +               fp->loaded     = GL_FALSE;
3638 +               fp->shaderbo   = NULL;
3639 +               break;
3640 +       }
3641 +               
3642  }
3643  
3644  static GLboolean r700IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
3645 diff --git a/src/mesa/drivers/dri/r600/r700_state.c b/src/mesa/drivers/dri/r600/r700_state.c
3646 index 124469b..244a016 100644
3647 --- a/src/mesa/drivers/dri/r600/r700_state.c
3648 +++ b/src/mesa/drivers/dri/r600/r700_state.c
3649 @@ -467,10 +467,10 @@ static void r700SetBlendState(GLcontext * ctx)
3650                  eqn, COLOR_COMB_FCN_shift, COLOR_COMB_FCN_mask);
3651  
3652         SETfield(blend_reg,
3653 -                blend_factor(ctx->Color.BlendSrcRGB, GL_TRUE),
3654 +                blend_factor(ctx->Color.BlendSrcA, GL_TRUE),
3655                  ALPHA_SRCBLEND_shift, ALPHA_SRCBLEND_mask);
3656         SETfield(blend_reg,
3657 -                blend_factor(ctx->Color.BlendDstRGB, GL_FALSE),
3658 +                blend_factor(ctx->Color.BlendDstA, GL_FALSE),
3659                  ALPHA_DESTBLEND_shift, ALPHA_DESTBLEND_mask);
3660  
3661         switch (ctx->Color.BlendEquationA) {
3662 @@ -745,9 +745,9 @@ static void r700ColorMask(GLcontext * ctx,
3663                              (b ? 4 : 0) |
3664                              (a ? 8 : 0));
3665  
3666 -       if (mask != r700->CB_SHADER_MASK.u32All) {
3667 +       if (mask != r700->CB_TARGET_MASK.u32All) {
3668                 R600_STATECHANGE(context, cb);
3669 -               SETfield(r700->CB_SHADER_MASK.u32All, mask, OUTPUT0_ENABLE_shift, OUTPUT0_ENABLE_mask);
3670 +               SETfield(r700->CB_TARGET_MASK.u32All, mask, TARGET0_ENABLE_shift, TARGET0_ENABLE_mask);
3671         }
3672  }
3673  
3674 @@ -1269,11 +1269,15 @@ void r700SetScissor(context_t *context) //---------------
3675                 return;
3676         }
3677         if (context->radeon.state.scissor.enabled) {
3678 -               /* r600 has exclusive scissors */
3679                 x1 = context->radeon.state.scissor.rect.x1;
3680                 y1 = context->radeon.state.scissor.rect.y1;
3681 -               x2 = context->radeon.state.scissor.rect.x2 + 1;
3682 -               y2 = context->radeon.state.scissor.rect.y2 + 1;
3683 +               x2 = context->radeon.state.scissor.rect.x2;
3684 +               y2 = context->radeon.state.scissor.rect.y2;
3685 +               /* r600 has exclusive BR scissors */
3686 +               if (context->radeon.radeonScreen->kernel_mm) {
3687 +                       x2++;
3688 +                       y2++;
3689 +               }
3690         } else {
3691                 if (context->radeon.radeonScreen->driScreen->dri2.enabled) {
3692                         x1 = 0;
3693 @@ -1754,7 +1758,7 @@ void r700InitState(GLcontext * ctx) //-------------------
3694      r700->CB_CLRCMP_MSK.u32All = 0xFFFFFFFF;
3695  
3696      /* screen/window/view */
3697 -    SETfield(r700->CB_TARGET_MASK.u32All, 0xF, (4 * id), TARGET0_ENABLE_mask);
3698 +    SETfield(r700->CB_SHADER_MASK.u32All, 0xF, (4 * id), OUTPUT0_ENABLE_mask);
3699  
3700      context->radeon.hw.all_dirty = GL_TRUE;
3701  
3702 diff --git a/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c b/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c
3703 index 3e7547d..ce60a2f 100644
3704 --- a/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c
3705 +++ b/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c
3706 @@ -710,6 +710,10 @@ int radeon_bo_legacy_validate(struct radeon_bo *bo,
3707                  bo, bo->size, bo_legacy->map_count);
3708          return -EINVAL;
3709      }
3710 +    if(bo->size == 0) {
3711 +        fprintf(stderr, "bo(%p) has size 0.\n", bo);
3712 +        return -EINVAL;
3713 +    }
3714      if (bo_legacy->static_bo || bo_legacy->validated) {
3715          *soffset = bo_legacy->offset;
3716          *eoffset = bo_legacy->offset + bo->size;
3717 diff --git a/src/mesa/drivers/dri/radeon/radeon_common.c b/src/mesa/drivers/dri/radeon/radeon_common.c
3718 index 9817ff8..8032cbc 100644
3719 --- a/src/mesa/drivers/dri/radeon/radeon_common.c
3720 +++ b/src/mesa/drivers/dri/radeon/radeon_common.c
3721 @@ -229,16 +229,15 @@ void radeonUpdateScissor( GLcontext *ctx )
3722         }
3723         if (!rmesa->radeonScreen->kernel_mm) {
3724            /* Fix scissors for dri 1 */
3725 -
3726            __DRIdrawablePrivate *dPriv = radeon_get_drawable(rmesa);
3727            x1 += dPriv->x;
3728 -          x2 += dPriv->x;
3729 +          x2 += dPriv->x + 1;
3730            min_x += dPriv->x;
3731 -          max_x += dPriv->x;
3732 +          max_x += dPriv->x + 1;
3733            y1 += dPriv->y;
3734 -          y2 += dPriv->y;
3735 +          y2 += dPriv->y + 1;
3736            min_y += dPriv->y;
3737 -          max_y += dPriv->y;
3738 +          max_y += dPriv->y + 1;
3739         }
3740  
3741         rmesa->state.scissor.rect.x1 = CLAMP(x1,  min_x, max_x);
3742 diff --git a/src/mesa/drivers/dri/radeon/radeon_fbo.c b/src/mesa/drivers/dri/radeon/radeon_fbo.c
3743 index d83b166..2012cbc 100644
3744 --- a/src/mesa/drivers/dri/radeon/radeon_fbo.c
3745 +++ b/src/mesa/drivers/dri/radeon/radeon_fbo.c
3746 @@ -445,7 +445,6 @@ restart:
3747                 goto restart;
3748         }
3749         
3750 -       rrb->pitch = texImage->Width * rrb->cpp;
3751         rrb->base.InternalFormat = rrb->base._ActualFormat;
3752         rrb->base.Width = texImage->Width;
3753         rrb->base.Height = texImage->Height;
3754 @@ -555,8 +554,10 @@ radeon_render_texture(GLcontext * ctx,
3755        imageOffset += offsets[att->Zoffset];
3756     }
3757  
3758 -   /* store that offset in the region */
3759 +   /* store that offset in the region, along with the correct pitch for
3760 +    * the image we are rendering to */
3761     rrb->draw_offset = imageOffset;
3762 +   rrb->pitch = radeon_image->mt->levels[att->TextureLevel].rowstride;
3763  
3764     /* update drawing region, etc */
3765     radeon_draw_buffer(ctx, fb);
3766 diff --git a/src/mesa/drivers/windows/gdi/mesa.def b/src/mesa/drivers/windows/gdi/mesa.def
3767 index bd3e5b2..05817fd 100644
3768 --- a/src/mesa/drivers/windows/gdi/mesa.def
3769 +++ b/src/mesa/drivers/windows/gdi/mesa.def
3770 @@ -867,12 +867,6 @@ EXPORTS
3771         _glapi_get_proc_address
3772         _mesa_add_soft_renderbuffers
3773         _mesa_add_renderbuffer
3774 -       _mesa_begin_query
3775 -       _mesa_buffer_data
3776 -       _mesa_buffer_get_subdata
3777 -       _mesa_buffer_map
3778 -       _mesa_buffer_subdata
3779 -       _mesa_buffer_unmap
3780         _mesa_bzero
3781         _mesa_calloc
3782         _mesa_choose_tex_format
3783 @@ -880,9 +874,7 @@ EXPORTS
3784         _mesa_create_framebuffer
3785         _mesa_create_visual
3786         _mesa_delete_array_object
3787 -       _mesa_delete_buffer_object
3788         _mesa_delete_program
3789 -       _mesa_delete_query
3790         _mesa_delete_texture_object
3791         _mesa_destroy_framebuffer
3792         _mesa_destroy_visual
3793 @@ -892,7 +884,6 @@ EXPORTS
3794         _mesa_enable_2_0_extensions
3795         _mesa_enable_2_1_extensions
3796         _mesa_enable_sw_extensions
3797 -       _mesa_end_query
3798         _mesa_error
3799         _mesa_finish_render_texture
3800         _mesa_framebuffer_renderbuffer
3801 @@ -911,10 +902,8 @@ EXPORTS
3802         _mesa_memcpy
3803         _mesa_memset
3804         _mesa_new_array_object
3805 -       _mesa_new_buffer_object
3806         _mesa_new_framebuffer
3807         _mesa_new_program
3808 -       _mesa_new_query_object
3809         _mesa_new_renderbuffer
3810         _mesa_new_soft_renderbuffer
3811         _mesa_new_texture_image
3812 @@ -943,7 +932,6 @@ EXPORTS
3813         _mesa_update_framebuffer_visual
3814         _mesa_use_program
3815         _mesa_Viewport
3816 -       _mesa_wait_query
3817         _swrast_Accum
3818         _swrast_Bitmap
3819         _swrast_BlitFramebuffer
3820 diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c
3821 index 34e0b8b..5c0084f 100644
3822 --- a/src/mesa/drivers/x11/fakeglx.c
3823 +++ b/src/mesa/drivers/x11/fakeglx.c
3824 @@ -1197,10 +1197,10 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
3825              if (!fbConfig)
3826                 return NULL;
3827              parselist++;
3828 -            if (*parselist == GLX_RGBA_BIT) {
3829 +            if (*parselist & GLX_RGBA_BIT) {
3830                 rgb_flag = GL_TRUE;
3831              }
3832 -            else if (*parselist == GLX_COLOR_INDEX_BIT) {
3833 +            else if (*parselist & GLX_COLOR_INDEX_BIT) {
3834                 rgb_flag = GL_FALSE;
3835              }
3836              else if (*parselist == 0) {
3837 @@ -1637,13 +1637,17 @@ Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
3838  
3839  
3840  static Bool
3841 -Fake_glXQueryExtension( Display *dpy, int *errorb, int *event )
3842 +Fake_glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
3843  {
3844 +   int op, ev, err;
3845     /* Mesa's GLX isn't really an X extension but we try to act like one. */
3846 -   (void) dpy;
3847 -   (void) errorb;
3848 -   (void) event;
3849 -   return True;
3850 +   if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err))
3851 +      ev = err = 0;
3852 +   if (errorBase)
3853 +      *errorBase = err;
3854 +   if (eventBase)
3855 +      *eventBase = ev;
3856 +   return True; /* we're faking GLX so always return success */
3857  }
3858  
3859  
3860 @@ -2349,32 +2353,42 @@ Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
3861              break;
3862           case GLX_PRESERVED_CONTENTS:
3863              attrib++;
3864 -            preserveContents = *attrib; /* ignored */
3865 +            preserveContents = *attrib;
3866              break;
3867           case GLX_LARGEST_PBUFFER:
3868              attrib++;
3869 -            useLargest = *attrib; /* ignored */
3870 +            useLargest = *attrib;
3871              break;
3872           default:
3873              return 0;
3874        }
3875     }
3876  
3877 -   /* not used at this time */
3878 -   (void) useLargest;
3879 -   (void) preserveContents;
3880 -
3881     if (width == 0 || height == 0)
3882        return 0;
3883  
3884 +   if (width > MAX_WIDTH || height > MAX_HEIGHT) {
3885 +      /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
3886 +       * allocate the largest possible buffer.
3887 +       */
3888 +      if (useLargest) {
3889 +         width = MAX_WIDTH;
3890 +         height = MAX_HEIGHT;
3891 +      }
3892 +   }
3893 +
3894     xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
3895     /* A GLXPbuffer handle must be an X Drawable because that's what
3896      * glXMakeCurrent takes.
3897      */
3898 -   if (xmbuf)
3899 +   if (xmbuf) {
3900 +      xmbuf->largestPbuffer = useLargest;
3901 +      xmbuf->preservedContents = preserveContents;
3902        return (GLXPbuffer) xmbuf->frontxrb->pixmap;
3903 -   else
3904 +   }
3905 +   else {
3906        return 0;
3907 +   }
3908  }
3909  
3910  
3911 @@ -2396,6 +2410,9 @@ Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
3912     if (!xmbuf)
3913        return;
3914  
3915 +   /* make sure buffer's dimensions are up to date */
3916 +   xmesa_check_and_update_buffer_size(NULL, xmbuf);
3917 +
3918     switch (attribute) {
3919        case GLX_WIDTH:
3920           *value = xmbuf->mesa_buffer.Width;
3921 @@ -2404,10 +2421,10 @@ Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
3922           *value = xmbuf->mesa_buffer.Height;
3923           break;
3924        case GLX_PRESERVED_CONTENTS:
3925 -         *value = True;
3926 +         *value = xmbuf->preservedContents;
3927           break;
3928        case GLX_LARGEST_PBUFFER:
3929 -         *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height;
3930 +         *value = xmbuf->largestPbuffer;
3931           break;
3932        case GLX_FBCONFIG_ID:
3933           *value = xmbuf->xm_visual->visinfo->visualid;
3934 @@ -2477,9 +2494,9 @@ Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
3935        break;
3936     case GLX_RENDER_TYPE:
3937        if (xmctx->xm_visual->mesa_visual.rgbMode)
3938 -         *value = GLX_RGBA_BIT;
3939 +         *value = GLX_RGBA_TYPE;
3940        else
3941 -         *value = GLX_COLOR_INDEX_BIT;
3942 +         *value = GLX_COLOR_INDEX_TYPE;
3943        break;
3944     case GLX_SCREEN:
3945        *value = 0;
3946 @@ -2764,10 +2781,10 @@ Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, un
3947  
3948     switch (attribute) {
3949        case GLX_PRESERVED_CONTENTS_SGIX:
3950 -         *value = True;
3951 +         *value = xmbuf->preservedContents;
3952           break;
3953        case GLX_LARGEST_PBUFFER_SGIX:
3954 -         *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height;
3955 +         *value = xmbuf->largestPbuffer;
3956           break;
3957        case GLX_WIDTH_SGIX:
3958           *value = xmbuf->mesa_buffer.Width;
3959 diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h
3960 index 25db558..3ffd766 100644
3961 --- a/src/mesa/drivers/x11/xmesaP.h
3962 +++ b/src/mesa/drivers/x11/xmesaP.h
3963 @@ -212,6 +212,9 @@ struct xmesa_buffer {
3964     XMesaDisplay *display;
3965     BufferType type;             /* window, pixmap, pbuffer or glxwindow */
3966  
3967 +   GLboolean largestPbuffer;    /**< for pbuffers */
3968 +   GLboolean preservedContents; /**< for pbuffers */
3969 +
3970     struct xmesa_renderbuffer *frontxrb; /* front color renderbuffer */
3971     struct xmesa_renderbuffer *backxrb;  /* back color renderbuffer */
3972  
3973 diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
3974 index f6d4ac4..e844a74 100644
3975 --- a/src/mesa/main/context.c
3976 +++ b/src/mesa/main/context.c
3977 @@ -898,6 +898,7 @@ _mesa_initialize_context(GLcontext *ctx,
3978        _mesa_free_shared_state(ctx, ctx->Shared);
3979        if (ctx->Exec)
3980           _mesa_free(ctx->Exec);
3981 +      return GL_FALSE;
3982     }
3983  #if FEATURE_dispatch
3984     _mesa_init_exec_table(ctx->Exec);
3985 @@ -1543,6 +1544,33 @@ _mesa_record_error(GLcontext *ctx, GLenum error)
3986  
3987  
3988  /**
3989 + * Flush commands and wait for completion.
3990 + */
3991 +void
3992 +_mesa_finish(GLcontext *ctx)
3993 +{
3994 +   FLUSH_CURRENT( ctx, 0 );
3995 +   if (ctx->Driver.Finish) {
3996 +      ctx->Driver.Finish(ctx);
3997 +   }
3998 +}
3999 +
4000 +
4001 +/**
4002 + * Flush commands.
4003 + */
4004 +void
4005 +_mesa_flush(GLcontext *ctx)
4006 +{
4007 +   FLUSH_CURRENT( ctx, 0 );
4008 +   if (ctx->Driver.Flush) {
4009 +      ctx->Driver.Flush(ctx);
4010 +   }
4011 +}
4012 +
4013 +
4014 +
4015 +/**
4016   * Execute glFinish().
4017   *
4018   * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
4019 @@ -1553,10 +1581,7 @@ _mesa_Finish(void)
4020  {
4021     GET_CURRENT_CONTEXT(ctx);
4022     ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
4023 -   FLUSH_CURRENT( ctx, 0 );
4024 -   if (ctx->Driver.Finish) {
4025 -      ctx->Driver.Finish(ctx);
4026 -   }
4027 +   _mesa_finish(ctx);
4028  }
4029  
4030  
4031 @@ -1571,10 +1596,7 @@ _mesa_Flush(void)
4032  {
4033     GET_CURRENT_CONTEXT(ctx);
4034     ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
4035 -   FLUSH_CURRENT( ctx, 0 );
4036 -   if (ctx->Driver.Flush) {
4037 -      ctx->Driver.Flush(ctx);
4038 -   }
4039 +   _mesa_flush(ctx);
4040  }
4041  
4042  
4043 diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
4044 index 5587695..c3be106 100644
4045 --- a/src/mesa/main/context.h
4046 +++ b/src/mesa/main/context.h
4047 @@ -170,6 +170,14 @@ _mesa_valid_to_render(GLcontext *ctx, const char *where);
4048  extern void
4049  _mesa_record_error( GLcontext *ctx, GLenum error );
4050  
4051 +
4052 +extern void
4053 +_mesa_finish(GLcontext *ctx);
4054 +
4055 +extern void
4056 +_mesa_flush(GLcontext *ctx);
4057 +
4058 +
4059  extern void GLAPIENTRY
4060  _mesa_Finish( void );
4061  
4062 diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
4063 index b53c173..41a5b61 100644
4064 --- a/src/mesa/main/dlist.c
4065 +++ b/src/mesa/main/dlist.c
4066 @@ -1956,6 +1956,9 @@ save_Fogiv(GLenum pname, const GLint *params)
4067     case GL_FOG_END:
4068     case GL_FOG_INDEX:
4069        p[0] = (GLfloat) *params;
4070 +      p[1] = 0.0f;
4071 +      p[2] = 0.0f;
4072 +      p[3] = 0.0f;
4073        break;
4074     case GL_FOG_COLOR:
4075        p[0] = INT_TO_FLOAT(params[0]);
4076 @@ -2244,6 +2247,9 @@ save_LightModeliv(GLenum pname, const GLint *params)
4077     case GL_LIGHT_MODEL_TWO_SIDE:
4078     case GL_LIGHT_MODEL_COLOR_CONTROL:
4079        fparam[0] = (GLfloat) params[0];
4080 +      fparam[1] = 0.0F;
4081 +      fparam[2] = 0.0F;
4082 +      fparam[3] = 0.0F;
4083        break;
4084     default:
4085        /* Error will be caught later in gl_LightModelfv */
4086 diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
4087 index 825a230..ed1db0f 100644
4088 --- a/src/mesa/main/fbobject.c
4089 +++ b/src/mesa/main/fbobject.c
4090 @@ -1511,18 +1511,6 @@ framebuffer_texture(GLcontext *ctx, const char *caller, GLenum target,
4091        return;
4092     }
4093  
4094 -   if (texObj && attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
4095 -      /* the texture format must be depth+stencil */
4096 -      const struct gl_texture_image *texImg;
4097 -      texImg = texObj->Image[0][texObj->BaseLevel];
4098 -      if (!texImg || texImg->_BaseFormat != GL_DEPTH_STENCIL) {
4099 -         _mesa_error(ctx, GL_INVALID_OPERATION,
4100 -                     "glFramebufferTexture%sEXT(texture is not"
4101 -                     " DEPTH_STENCIL format)", caller);
4102 -         return;
4103 -      }
4104 -   }
4105 -
4106     FLUSH_CURRENT(ctx, _NEW_BUFFERS);
4107     /* The above doesn't fully flush the drivers in the way that a
4108      * glFlush does, but that is required here:
4109 diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
4110 index 477ed01..604b106 100644
4111 --- a/src/mesa/main/get.c
4112 +++ b/src/mesa/main/get.c
4113 @@ -5580,16 +5580,16 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4114  
4115     switch (pname) {
4116        case GL_ACCUM_RED_BITS:
4117 -         params[0] = ctx->DrawBuffer->Visual.accumRedBits;
4118 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.accumRedBits);
4119           break;
4120        case GL_ACCUM_GREEN_BITS:
4121 -         params[0] = ctx->DrawBuffer->Visual.accumGreenBits;
4122 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.accumGreenBits);
4123           break;
4124        case GL_ACCUM_BLUE_BITS:
4125 -         params[0] = ctx->DrawBuffer->Visual.accumBlueBits;
4126 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.accumBlueBits);
4127           break;
4128        case GL_ACCUM_ALPHA_BITS:
4129 -         params[0] = ctx->DrawBuffer->Visual.accumAlphaBits;
4130 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.accumAlphaBits);
4131           break;
4132        case GL_ACCUM_CLEAR_VALUE:
4133           params[0] = FLOAT_TO_INT64(ctx->Accum.ClearColor[0]);
4134 @@ -5601,7 +5601,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4135           params[0] = IROUND64(ctx->Pixel.AlphaBias);
4136           break;
4137        case GL_ALPHA_BITS:
4138 -         params[0] = ctx->DrawBuffer->Visual.alphaBits;
4139 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.alphaBits);
4140           break;
4141        case GL_ALPHA_SCALE:
4142           params[0] = IROUND64(ctx->Pixel.AlphaScale);
4143 @@ -5616,13 +5616,13 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4144           params[0] = FLOAT_TO_INT64(ctx->Color.AlphaRef);
4145           break;
4146        case GL_ATTRIB_STACK_DEPTH:
4147 -         params[0] = ctx->AttribStackDepth;
4148 +         params[0] = (GLint64)(ctx->AttribStackDepth);
4149           break;
4150        case GL_AUTO_NORMAL:
4151           params[0] = BOOLEAN_TO_INT64(ctx->Eval.AutoNormal);
4152           break;
4153        case GL_AUX_BUFFERS:
4154 -         params[0] = ctx->DrawBuffer->Visual.numAuxBuffers;
4155 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.numAuxBuffers);
4156           break;
4157        case GL_BLEND:
4158           params[0] = BOOLEAN_TO_INT64(ctx->Color.BlendEnabled);
4159 @@ -5661,13 +5661,13 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4160           params[0] = IROUND64(ctx->Pixel.BlueBias);
4161           break;
4162        case GL_BLUE_BITS:
4163 -         params[0] = ctx->DrawBuffer->Visual.blueBits;
4164 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.blueBits);
4165           break;
4166        case GL_BLUE_SCALE:
4167           params[0] = IROUND64(ctx->Pixel.BlueScale);
4168           break;
4169        case GL_CLIENT_ATTRIB_STACK_DEPTH:
4170 -         params[0] = ctx->ClientAttribStackDepth;
4171 +         params[0] = (GLint64)(ctx->ClientAttribStackDepth);
4172           break;
4173        case GL_CLIP_PLANE0:
4174           params[0] = BOOLEAN_TO_INT64((ctx->Transform.ClipPlanesEnabled >> 0) & 1);
4175 @@ -5703,10 +5703,10 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4176           params[0] = ENUM_TO_INT64(ctx->Light.ColorMaterialMode);
4177           break;
4178        case GL_COLOR_WRITEMASK:
4179 -         params[0] = ctx->Color.ColorMask[RCOMP] ? 1 : 0;
4180 -         params[1] = ctx->Color.ColorMask[GCOMP] ? 1 : 0;
4181 -         params[2] = ctx->Color.ColorMask[BCOMP] ? 1 : 0;
4182 -         params[3] = ctx->Color.ColorMask[ACOMP] ? 1 : 0;
4183 +         params[0] = (GLint64)(ctx->Color.ColorMask[RCOMP] ? 1 : 0);
4184 +         params[1] = (GLint64)(ctx->Color.ColorMask[GCOMP] ? 1 : 0);
4185 +         params[2] = (GLint64)(ctx->Color.ColorMask[BCOMP] ? 1 : 0);
4186 +         params[3] = (GLint64)(ctx->Color.ColorMask[ACOMP] ? 1 : 0);
4187           break;
4188        case GL_CULL_FACE:
4189           params[0] = BOOLEAN_TO_INT64(ctx->Polygon.CullFlag);
4190 @@ -5787,7 +5787,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4191           params[0] = IROUND64(ctx->Pixel.DepthBias);
4192           break;
4193        case GL_DEPTH_BITS:
4194 -         params[0] = ctx->DrawBuffer->Visual.depthBits;
4195 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.depthBits);
4196           break;
4197        case GL_DEPTH_CLEAR_VALUE:
4198           params[0] = FLOAT_TO_INT64(((GLfloat) ctx->Depth.Clear));
4199 @@ -5824,7 +5824,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4200           }
4201           break;
4202        case GL_FEEDBACK_BUFFER_SIZE:
4203 -         params[0] = ctx->Feedback.BufferSize;
4204 +         params[0] = (GLint64)(ctx->Feedback.BufferSize);
4205           break;
4206        case GL_FEEDBACK_BUFFER_TYPE:
4207           params[0] = ENUM_TO_INT64(ctx->Feedback.Type);
4208 @@ -5863,28 +5863,28 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4209           params[0] = IROUND64(ctx->Pixel.GreenBias);
4210           break;
4211        case GL_GREEN_BITS:
4212 -         params[0] = ctx->DrawBuffer->Visual.greenBits;
4213 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.greenBits);
4214           break;
4215        case GL_GREEN_SCALE:
4216           params[0] = IROUND64(ctx->Pixel.GreenScale);
4217           break;
4218        case GL_INDEX_BITS:
4219 -         params[0] = ctx->DrawBuffer->Visual.indexBits;
4220 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.indexBits);
4221           break;
4222        case GL_INDEX_CLEAR_VALUE:
4223 -         params[0] = ctx->Color.ClearIndex;
4224 +         params[0] = (GLint64)(ctx->Color.ClearIndex);
4225           break;
4226        case GL_INDEX_MODE:
4227           params[0] = BOOLEAN_TO_INT64(!ctx->DrawBuffer->Visual.rgbMode);
4228           break;
4229        case GL_INDEX_OFFSET:
4230 -         params[0] = ctx->Pixel.IndexOffset;
4231 +         params[0] = (GLint64)(ctx->Pixel.IndexOffset);
4232           break;
4233        case GL_INDEX_SHIFT:
4234 -         params[0] = ctx->Pixel.IndexShift;
4235 +         params[0] = (GLint64)(ctx->Pixel.IndexShift);
4236           break;
4237        case GL_INDEX_WRITEMASK:
4238 -         params[0] = ctx->Color.IndexMask;
4239 +         params[0] = (GLint64)(ctx->Color.IndexMask);
4240           break;
4241        case GL_LIGHT0:
4242           params[0] = BOOLEAN_TO_INT64(ctx->Light.Light[0].Enabled);
4243 @@ -5938,10 +5938,10 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4244           params[0] = BOOLEAN_TO_INT64(ctx->Line.StippleFlag);
4245           break;
4246        case GL_LINE_STIPPLE_PATTERN:
4247 -         params[0] = ctx->Line.StipplePattern;
4248 +         params[0] = (GLint64)(ctx->Line.StipplePattern);
4249           break;
4250        case GL_LINE_STIPPLE_REPEAT:
4251 -         params[0] = ctx->Line.StippleFactor;
4252 +         params[0] = (GLint64)(ctx->Line.StippleFactor);
4253           break;
4254        case GL_LINE_WIDTH:
4255           params[0] = IROUND64(ctx->Line.Width);
4256 @@ -5958,10 +5958,10 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4257           params[1] = IROUND64(ctx->Const.MaxLineWidth);
4258           break;
4259        case GL_LIST_BASE:
4260 -         params[0] = ctx->List.ListBase;
4261 +         params[0] = (GLint64)(ctx->List.ListBase);
4262           break;
4263        case GL_LIST_INDEX:
4264 -         params[0] = (ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0);
4265 +         params[0] = (GLint64)((ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0));
4266           break;
4267        case GL_LIST_MODE:
4268           {
4269 @@ -5992,7 +5992,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4270           params[1] = IROUND64(ctx->Eval.MapGrid1u2);
4271           break;
4272        case GL_MAP1_GRID_SEGMENTS:
4273 -         params[0] = ctx->Eval.MapGrid1un;
4274 +         params[0] = (GLint64)(ctx->Eval.MapGrid1un);
4275           break;
4276        case GL_MAP1_INDEX:
4277           params[0] = BOOLEAN_TO_INT64(ctx->Eval.Map1Index);
4278 @@ -6028,8 +6028,8 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4279           params[3] = IROUND64(ctx->Eval.MapGrid2v2);
4280           break;
4281        case GL_MAP2_GRID_SEGMENTS:
4282 -         params[0] = ctx->Eval.MapGrid2un;
4283 -         params[1] = ctx->Eval.MapGrid2vn;
4284 +         params[0] = (GLint64)(ctx->Eval.MapGrid2un);
4285 +         params[1] = (GLint64)(ctx->Eval.MapGrid2vn);
4286           break;
4287        case GL_MAP2_INDEX:
4288           params[0] = BOOLEAN_TO_INT64(ctx->Eval.Map2Index);
4289 @@ -6065,53 +6065,53 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4290           params[0] = ENUM_TO_INT64(ctx->Transform.MatrixMode);
4291           break;
4292        case GL_MAX_ATTRIB_STACK_DEPTH:
4293 -         params[0] = MAX_ATTRIB_STACK_DEPTH;
4294 +         params[0] = (GLint64)(MAX_ATTRIB_STACK_DEPTH);
4295           break;
4296        case GL_MAX_CLIENT_ATTRIB_STACK_DEPTH:
4297 -         params[0] = MAX_CLIENT_ATTRIB_STACK_DEPTH;
4298 +         params[0] = (GLint64)(MAX_CLIENT_ATTRIB_STACK_DEPTH);
4299           break;
4300        case GL_MAX_CLIP_PLANES:
4301 -         params[0] = ctx->Const.MaxClipPlanes;
4302 +         params[0] = (GLint64)(ctx->Const.MaxClipPlanes);
4303           break;
4304        case GL_MAX_ELEMENTS_VERTICES:
4305 -         params[0] = ctx->Const.MaxArrayLockSize;
4306 +         params[0] = (GLint64)(ctx->Const.MaxArrayLockSize);
4307           break;
4308        case GL_MAX_ELEMENTS_INDICES:
4309 -         params[0] = ctx->Const.MaxArrayLockSize;
4310 +         params[0] = (GLint64)(ctx->Const.MaxArrayLockSize);
4311           break;
4312        case GL_MAX_EVAL_ORDER:
4313 -         params[0] = MAX_EVAL_ORDER;
4314 +         params[0] = (GLint64)(MAX_EVAL_ORDER);
4315           break;
4316        case GL_MAX_LIGHTS:
4317 -         params[0] = ctx->Const.MaxLights;
4318 +         params[0] = (GLint64)(ctx->Const.MaxLights);
4319           break;
4320        case GL_MAX_LIST_NESTING:
4321 -         params[0] = MAX_LIST_NESTING;
4322 +         params[0] = (GLint64)(MAX_LIST_NESTING);
4323           break;
4324        case GL_MAX_MODELVIEW_STACK_DEPTH:
4325 -         params[0] = MAX_MODELVIEW_STACK_DEPTH;
4326 +         params[0] = (GLint64)(MAX_MODELVIEW_STACK_DEPTH);
4327           break;
4328        case GL_MAX_NAME_STACK_DEPTH:
4329 -         params[0] = MAX_NAME_STACK_DEPTH;
4330 +         params[0] = (GLint64)(MAX_NAME_STACK_DEPTH);
4331           break;
4332        case GL_MAX_PIXEL_MAP_TABLE:
4333 -         params[0] = MAX_PIXEL_MAP_TABLE;
4334 +         params[0] = (GLint64)(MAX_PIXEL_MAP_TABLE);
4335           break;
4336        case GL_MAX_PROJECTION_STACK_DEPTH:
4337 -         params[0] = MAX_PROJECTION_STACK_DEPTH;
4338 +         params[0] = (GLint64)(MAX_PROJECTION_STACK_DEPTH);
4339           break;
4340        case GL_MAX_TEXTURE_SIZE:
4341 -         params[0] = 1 << (ctx->Const.MaxTextureLevels - 1);
4342 +         params[0] = (GLint64)(1 << (ctx->Const.MaxTextureLevels - 1));
4343           break;
4344        case GL_MAX_3D_TEXTURE_SIZE:
4345 -         params[0] = 1 << (ctx->Const.Max3DTextureLevels - 1);
4346 +         params[0] = (GLint64)(1 << (ctx->Const.Max3DTextureLevels - 1));
4347           break;
4348        case GL_MAX_TEXTURE_STACK_DEPTH:
4349 -         params[0] = MAX_TEXTURE_STACK_DEPTH;
4350 +         params[0] = (GLint64)(MAX_TEXTURE_STACK_DEPTH);
4351           break;
4352        case GL_MAX_VIEWPORT_DIMS:
4353 -         params[0] = ctx->Const.MaxViewportWidth;
4354 -         params[1] = ctx->Const.MaxViewportHeight;
4355 +         params[0] = (GLint64)(ctx->Const.MaxViewportWidth);
4356 +         params[1] = (GLint64)(ctx->Const.MaxViewportHeight);
4357           break;
4358        case GL_MODELVIEW_MATRIX:
4359           {
4360 @@ -6135,37 +6135,37 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4361           }
4362           break;
4363        case GL_MODELVIEW_STACK_DEPTH:
4364 -         params[0] = ctx->ModelviewMatrixStack.Depth + 1;
4365 +         params[0] = (GLint64)(ctx->ModelviewMatrixStack.Depth + 1);
4366           break;
4367        case GL_NAME_STACK_DEPTH:
4368 -         params[0] = ctx->Select.NameStackDepth;
4369 +         params[0] = (GLint64)(ctx->Select.NameStackDepth);
4370           break;
4371        case GL_NORMALIZE:
4372           params[0] = BOOLEAN_TO_INT64(ctx->Transform.Normalize);
4373           break;
4374        case GL_PACK_ALIGNMENT:
4375 -         params[0] = ctx->Pack.Alignment;
4376 +         params[0] = (GLint64)(ctx->Pack.Alignment);
4377           break;
4378        case GL_PACK_LSB_FIRST:
4379           params[0] = BOOLEAN_TO_INT64(ctx->Pack.LsbFirst);
4380           break;
4381        case GL_PACK_ROW_LENGTH:
4382 -         params[0] = ctx->Pack.RowLength;
4383 +         params[0] = (GLint64)(ctx->Pack.RowLength);
4384           break;
4385        case GL_PACK_SKIP_PIXELS:
4386 -         params[0] = ctx->Pack.SkipPixels;
4387 +         params[0] = (GLint64)(ctx->Pack.SkipPixels);
4388           break;
4389        case GL_PACK_SKIP_ROWS:
4390 -         params[0] = ctx->Pack.SkipRows;
4391 +         params[0] = (GLint64)(ctx->Pack.SkipRows);
4392           break;
4393        case GL_PACK_SWAP_BYTES:
4394           params[0] = BOOLEAN_TO_INT64(ctx->Pack.SwapBytes);
4395           break;
4396        case GL_PACK_SKIP_IMAGES_EXT:
4397 -         params[0] = ctx->Pack.SkipImages;
4398 +         params[0] = (GLint64)(ctx->Pack.SkipImages);
4399           break;
4400        case GL_PACK_IMAGE_HEIGHT_EXT:
4401 -         params[0] = ctx->Pack.ImageHeight;
4402 +         params[0] = (GLint64)(ctx->Pack.ImageHeight);
4403           break;
4404        case GL_PACK_INVERT_MESA:
4405           params[0] = BOOLEAN_TO_INT64(ctx->Pack.Invert);
4406 @@ -6174,34 +6174,34 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4407           params[0] = ENUM_TO_INT64(ctx->Hint.PerspectiveCorrection);
4408           break;
4409        case GL_PIXEL_MAP_A_TO_A_SIZE:
4410 -         params[0] = ctx->PixelMaps.AtoA.Size;
4411 +         params[0] = (GLint64)(ctx->PixelMaps.AtoA.Size);
4412           break;
4413        case GL_PIXEL_MAP_B_TO_B_SIZE:
4414 -         params[0] = ctx->PixelMaps.BtoB.Size;
4415 +         params[0] = (GLint64)(ctx->PixelMaps.BtoB.Size);
4416           break;
4417        case GL_PIXEL_MAP_G_TO_G_SIZE:
4418 -         params[0] = ctx->PixelMaps.GtoG.Size;
4419 +         params[0] = (GLint64)(ctx->PixelMaps.GtoG.Size);
4420           break;
4421        case GL_PIXEL_MAP_I_TO_A_SIZE:
4422 -         params[0] = ctx->PixelMaps.ItoA.Size;
4423 +         params[0] = (GLint64)(ctx->PixelMaps.ItoA.Size);
4424           break;
4425        case GL_PIXEL_MAP_I_TO_B_SIZE:
4426 -         params[0] = ctx->PixelMaps.ItoB.Size;
4427 +         params[0] = (GLint64)(ctx->PixelMaps.ItoB.Size);
4428           break;
4429        case GL_PIXEL_MAP_I_TO_G_SIZE:
4430 -         params[0] = ctx->PixelMaps.ItoG.Size;
4431 +         params[0] = (GLint64)(ctx->PixelMaps.ItoG.Size);
4432           break;
4433        case GL_PIXEL_MAP_I_TO_I_SIZE:
4434 -         params[0] = ctx->PixelMaps.ItoI.Size;
4435 +         params[0] = (GLint64)(ctx->PixelMaps.ItoI.Size);
4436           break;
4437        case GL_PIXEL_MAP_I_TO_R_SIZE:
4438 -         params[0] = ctx->PixelMaps.ItoR.Size;
4439 +         params[0] = (GLint64)(ctx->PixelMaps.ItoR.Size);
4440           break;
4441        case GL_PIXEL_MAP_R_TO_R_SIZE:
4442 -         params[0] = ctx->PixelMaps.RtoR.Size;
4443 +         params[0] = (GLint64)(ctx->PixelMaps.RtoR.Size);
4444           break;
4445        case GL_PIXEL_MAP_S_TO_S_SIZE:
4446 -         params[0] = ctx->PixelMaps.StoS.Size;
4447 +         params[0] = (GLint64)(ctx->PixelMaps.StoS.Size);
4448           break;
4449        case GL_POINT_SIZE:
4450           params[0] = IROUND64(ctx->Point.Size);
4451 @@ -6290,7 +6290,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4452           }
4453           break;
4454        case GL_PROJECTION_STACK_DEPTH:
4455 -         params[0] = ctx->ProjectionMatrixStack.Depth + 1;
4456 +         params[0] = (GLint64)(ctx->ProjectionMatrixStack.Depth + 1);
4457           break;
4458        case GL_READ_BUFFER:
4459           params[0] = ENUM_TO_INT64(ctx->ReadBuffer->ColorReadBuffer);
4460 @@ -6299,7 +6299,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4461           params[0] = IROUND64(ctx->Pixel.RedBias);
4462           break;
4463        case GL_RED_BITS:
4464 -         params[0] = ctx->DrawBuffer->Visual.redBits;
4465 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.redBits);
4466           break;
4467        case GL_RED_SCALE:
4468           params[0] = IROUND64(ctx->Pixel.RedScale);
4469 @@ -6314,16 +6314,16 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4470           params[0] = BOOLEAN_TO_INT64(ctx->DrawBuffer->Visual.rgbMode);
4471           break;
4472        case GL_SCISSOR_BOX:
4473 -         params[0] = ctx->Scissor.X;
4474 -         params[1] = ctx->Scissor.Y;
4475 -         params[2] = ctx->Scissor.Width;
4476 -         params[3] = ctx->Scissor.Height;
4477 +         params[0] = (GLint64)(ctx->Scissor.X);
4478 +         params[1] = (GLint64)(ctx->Scissor.Y);
4479 +         params[2] = (GLint64)(ctx->Scissor.Width);
4480 +         params[3] = (GLint64)(ctx->Scissor.Height);
4481           break;
4482        case GL_SCISSOR_TEST:
4483           params[0] = BOOLEAN_TO_INT64(ctx->Scissor.Enabled);
4484           break;
4485        case GL_SELECTION_BUFFER_SIZE:
4486 -         params[0] = ctx->Select.BufferSize;
4487 +         params[0] = (GLint64)(ctx->Select.BufferSize);
4488           break;
4489        case GL_SHADE_MODEL:
4490           params[0] = ENUM_TO_INT64(ctx->Light.ShadeModel);
4491 @@ -6332,10 +6332,10 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4492           params[0] = BOOLEAN_TO_INT64(ctx->Texture.SharedPalette);
4493           break;
4494        case GL_STENCIL_BITS:
4495 -         params[0] = ctx->DrawBuffer->Visual.stencilBits;
4496 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.stencilBits);
4497           break;
4498        case GL_STENCIL_CLEAR_VALUE:
4499 -         params[0] = ctx->Stencil.Clear;
4500 +         params[0] = (GLint64)(ctx->Stencil.Clear);
4501           break;
4502        case GL_STENCIL_FAIL:
4503           params[0] = ENUM_TO_INT64(ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace]);
4504 @@ -6350,22 +6350,22 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4505           params[0] = ENUM_TO_INT64(ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace]);
4506           break;
4507        case GL_STENCIL_REF:
4508 -         params[0] = ctx->Stencil.Ref[ctx->Stencil.ActiveFace];
4509 +         params[0] = (GLint64)(ctx->Stencil.Ref[ctx->Stencil.ActiveFace]);
4510           break;
4511        case GL_STENCIL_TEST:
4512           params[0] = BOOLEAN_TO_INT64(ctx->Stencil.Enabled);
4513           break;
4514        case GL_STENCIL_VALUE_MASK:
4515 -         params[0] = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
4516 +         params[0] = (GLint64)(ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace]);
4517           break;
4518        case GL_STENCIL_WRITEMASK:
4519 -         params[0] = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
4520 +         params[0] = (GLint64)(ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace]);
4521           break;
4522        case GL_STEREO:
4523           params[0] = BOOLEAN_TO_INT64(ctx->DrawBuffer->Visual.stereoMode);
4524           break;
4525        case GL_SUBPIXEL_BITS:
4526 -         params[0] = ctx->Const.SubPixelBits;
4527 +         params[0] = (GLint64)(ctx->Const.SubPixelBits);
4528           break;
4529        case GL_TEXTURE_1D:
4530           params[0] = BOOLEAN_TO_INT64(_mesa_IsEnabled(GL_TEXTURE_1D));
4531 @@ -6385,21 +6385,21 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4532           params[0] = BOOLEAN_TO_INT64(_mesa_IsEnabled(GL_TEXTURE_2D_ARRAY_EXT));
4533           break;
4534        case GL_TEXTURE_BINDING_1D:
4535 -         params[0] = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_1D_INDEX]->Name;
4536 +         params[0] = (GLint64)(ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_1D_INDEX]->Name);
4537           break;
4538        case GL_TEXTURE_BINDING_2D:
4539 -         params[0] = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_2D_INDEX]->Name;
4540 +         params[0] = (GLint64)(ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_2D_INDEX]->Name);
4541           break;
4542        case GL_TEXTURE_BINDING_3D:
4543 -         params[0] = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_3D_INDEX]->Name;
4544 +         params[0] = (GLint64)(ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_3D_INDEX]->Name);
4545           break;
4546        case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
4547           CHECK_EXT1(MESA_texture_array, "GetInteger64v");
4548 -         params[0] = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_1D_ARRAY_INDEX]->Name;
4549 +         params[0] = (GLint64)(ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_1D_ARRAY_INDEX]->Name);
4550           break;
4551        case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
4552           CHECK_EXT1(MESA_texture_array, "GetInteger64v");
4553 -         params[0] = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_2D_ARRAY_INDEX]->Name;
4554 +         params[0] = (GLint64)(ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_2D_ARRAY_INDEX]->Name);
4555           break;
4556        case GL_TEXTURE_GEN_S:
4557           params[0] = BOOLEAN_TO_INT64(((ctx->Texture.Unit[ctx->Texture.CurrentUnit].TexGenEnabled & S_BIT) ? 1 : 0));
4558 @@ -6435,40 +6435,40 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4559           }
4560           break;
4561        case GL_TEXTURE_STACK_DEPTH:
4562 -         params[0] = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Depth + 1;
4563 +         params[0] = (GLint64)(ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Depth + 1);
4564           break;
4565        case GL_UNPACK_ALIGNMENT:
4566 -         params[0] = ctx->Unpack.Alignment;
4567 +         params[0] = (GLint64)(ctx->Unpack.Alignment);
4568           break;
4569        case GL_UNPACK_LSB_FIRST:
4570           params[0] = BOOLEAN_TO_INT64(ctx->Unpack.LsbFirst);
4571           break;
4572        case GL_UNPACK_ROW_LENGTH:
4573 -         params[0] = ctx->Unpack.RowLength;
4574 +         params[0] = (GLint64)(ctx->Unpack.RowLength);
4575           break;
4576        case GL_UNPACK_SKIP_PIXELS:
4577 -         params[0] = ctx->Unpack.SkipPixels;
4578 +         params[0] = (GLint64)(ctx->Unpack.SkipPixels);
4579           break;
4580        case GL_UNPACK_SKIP_ROWS:
4581 -         params[0] = ctx->Unpack.SkipRows;
4582 +         params[0] = (GLint64)(ctx->Unpack.SkipRows);
4583           break;
4584        case GL_UNPACK_SWAP_BYTES:
4585           params[0] = BOOLEAN_TO_INT64(ctx->Unpack.SwapBytes);
4586           break;
4587        case GL_UNPACK_SKIP_IMAGES_EXT:
4588 -         params[0] = ctx->Unpack.SkipImages;
4589 +         params[0] = (GLint64)(ctx->Unpack.SkipImages);
4590           break;
4591        case GL_UNPACK_IMAGE_HEIGHT_EXT:
4592 -         params[0] = ctx->Unpack.ImageHeight;
4593 +         params[0] = (GLint64)(ctx->Unpack.ImageHeight);
4594           break;
4595        case GL_UNPACK_CLIENT_STORAGE_APPLE:
4596           params[0] = BOOLEAN_TO_INT64(ctx->Unpack.ClientStorage);
4597           break;
4598        case GL_VIEWPORT:
4599 -         params[0] = ctx->Viewport.X;
4600 -         params[1] = ctx->Viewport.Y;
4601 -         params[2] = ctx->Viewport.Width;
4602 -         params[3] = ctx->Viewport.Height;
4603 +         params[0] = (GLint64)(ctx->Viewport.X);
4604 +         params[1] = (GLint64)(ctx->Viewport.Y);
4605 +         params[2] = (GLint64)(ctx->Viewport.Width);
4606 +         params[3] = (GLint64)(ctx->Viewport.Height);
4607           break;
4608        case GL_ZOOM_X:
4609           params[0] = IROUND64(ctx->Pixel.ZoomX);
4610 @@ -6480,16 +6480,16 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4611           params[0] = BOOLEAN_TO_INT64(ctx->Array.ArrayObj->Vertex.Enabled);
4612           break;
4613        case GL_VERTEX_ARRAY_SIZE:
4614 -         params[0] = ctx->Array.ArrayObj->Vertex.Size;
4615 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Vertex.Size);
4616           break;
4617        case GL_VERTEX_ARRAY_TYPE:
4618           params[0] = ENUM_TO_INT64(ctx->Array.ArrayObj->Vertex.Type);
4619           break;
4620        case GL_VERTEX_ARRAY_STRIDE:
4621 -         params[0] = ctx->Array.ArrayObj->Vertex.Stride;
4622 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Vertex.Stride);
4623           break;
4624        case GL_VERTEX_ARRAY_COUNT_EXT:
4625 -         params[0] = 0;
4626 +         params[0] = (GLint64)(0);
4627           break;
4628        case GL_NORMAL_ARRAY:
4629           params[0] = ENUM_TO_INT64(ctx->Array.ArrayObj->Normal.Enabled);
4630 @@ -6498,25 +6498,25 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4631           params[0] = ENUM_TO_INT64(ctx->Array.ArrayObj->Normal.Type);
4632           break;
4633        case GL_NORMAL_ARRAY_STRIDE:
4634 -         params[0] = ctx->Array.ArrayObj->Normal.Stride;
4635 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Normal.Stride);
4636           break;
4637        case GL_NORMAL_ARRAY_COUNT_EXT:
4638 -         params[0] = 0;
4639 +         params[0] = (GLint64)(0);
4640           break;
4641        case GL_COLOR_ARRAY:
4642           params[0] = BOOLEAN_TO_INT64(ctx->Array.ArrayObj->Color.Enabled);
4643           break;
4644        case GL_COLOR_ARRAY_SIZE:
4645 -         params[0] = ctx->Array.ArrayObj->Color.Size;
4646 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Color.Size);
4647           break;
4648        case GL_COLOR_ARRAY_TYPE:
4649           params[0] = ENUM_TO_INT64(ctx->Array.ArrayObj->Color.Type);
4650           break;
4651        case GL_COLOR_ARRAY_STRIDE:
4652 -         params[0] = ctx->Array.ArrayObj->Color.Stride;
4653 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Color.Stride);
4654           break;
4655        case GL_COLOR_ARRAY_COUNT_EXT:
4656 -         params[0] = 0;
4657 +         params[0] = (GLint64)(0);
4658           break;
4659        case GL_INDEX_ARRAY:
4660           params[0] = BOOLEAN_TO_INT64(ctx->Array.ArrayObj->Index.Enabled);
4661 @@ -6525,46 +6525,46 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4662           params[0] = ENUM_TO_INT64(ctx->Array.ArrayObj->Index.Type);
4663           break;
4664        case GL_INDEX_ARRAY_STRIDE:
4665 -         params[0] = ctx->Array.ArrayObj->Index.Stride;
4666 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Index.Stride);
4667           break;
4668        case GL_INDEX_ARRAY_COUNT_EXT:
4669 -         params[0] = 0;
4670 +         params[0] = (GLint64)(0);
4671           break;
4672        case GL_TEXTURE_COORD_ARRAY:
4673           params[0] = BOOLEAN_TO_INT64(ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled);
4674           break;
4675        case GL_TEXTURE_COORD_ARRAY_SIZE:
4676 -         params[0] = ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Size;
4677 +         params[0] = (GLint64)(ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Size);
4678           break;
4679        case GL_TEXTURE_COORD_ARRAY_TYPE:
4680           params[0] = ENUM_TO_INT64(ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Type);
4681           break;
4682        case GL_TEXTURE_COORD_ARRAY_STRIDE:
4683 -         params[0] = ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Stride;
4684 +         params[0] = (GLint64)(ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Stride);
4685           break;
4686        case GL_TEXTURE_COORD_ARRAY_COUNT_EXT:
4687 -         params[0] = 0;
4688 +         params[0] = (GLint64)(0);
4689           break;
4690        case GL_EDGE_FLAG_ARRAY:
4691           params[0] = BOOLEAN_TO_INT64(ctx->Array.ArrayObj->EdgeFlag.Enabled);
4692           break;
4693        case GL_EDGE_FLAG_ARRAY_STRIDE:
4694 -         params[0] = ctx->Array.ArrayObj->EdgeFlag.Stride;
4695 +         params[0] = (GLint64)(ctx->Array.ArrayObj->EdgeFlag.Stride);
4696           break;
4697        case GL_EDGE_FLAG_ARRAY_COUNT_EXT:
4698 -         params[0] = 0;
4699 +         params[0] = (GLint64)(0);
4700           break;
4701        case GL_MAX_TEXTURE_UNITS_ARB:
4702           CHECK_EXT1(ARB_multitexture, "GetInteger64v");
4703 -         params[0] = ctx->Const.MaxTextureUnits;
4704 +         params[0] = (GLint64)(ctx->Const.MaxTextureUnits);
4705           break;
4706        case GL_ACTIVE_TEXTURE_ARB:
4707           CHECK_EXT1(ARB_multitexture, "GetInteger64v");
4708 -         params[0] = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
4709 +         params[0] = (GLint64)(GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit);
4710           break;
4711        case GL_CLIENT_ACTIVE_TEXTURE_ARB:
4712           CHECK_EXT1(ARB_multitexture, "GetInteger64v");
4713 -         params[0] = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
4714 +         params[0] = (GLint64)(GL_TEXTURE0_ARB + ctx->Array.ActiveTexture);
4715           break;
4716        case GL_TEXTURE_CUBE_MAP_ARB:
4717           CHECK_EXT1(ARB_texture_cube_map, "GetInteger64v");
4718 @@ -6572,17 +6572,17 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4719           break;
4720        case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
4721           CHECK_EXT1(ARB_texture_cube_map, "GetInteger64v");
4722 -         params[0] = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_CUBE_INDEX]->Name;
4723 +         params[0] = (GLint64)(ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_CUBE_INDEX]->Name);
4724           break;
4725        case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
4726           CHECK_EXT1(ARB_texture_cube_map, "GetInteger64v");
4727 -         params[0] = (1 << (ctx->Const.MaxCubeTextureLevels - 1));
4728 +         params[0] = (GLint64)((1 << (ctx->Const.MaxCubeTextureLevels - 1)));
4729           break;
4730        case GL_TEXTURE_COMPRESSION_HINT_ARB:
4731 -         params[0] = ctx->Hint.TextureCompression;
4732 +         params[0] = (GLint64)(ctx->Hint.TextureCompression);
4733           break;
4734        case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
4735 -         params[0] = _mesa_get_compressed_formats(ctx, NULL, GL_FALSE);
4736 +         params[0] = (GLint64)(_mesa_get_compressed_formats(ctx, NULL, GL_FALSE));
4737           break;
4738        case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
4739           {
4740 @@ -6595,11 +6595,11 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4741           break;
4742        case GL_ARRAY_ELEMENT_LOCK_FIRST_EXT:
4743           CHECK_EXT1(EXT_compiled_vertex_array, "GetInteger64v");
4744 -         params[0] = ctx->Array.LockFirst;
4745 +         params[0] = (GLint64)(ctx->Array.LockFirst);
4746           break;
4747        case GL_ARRAY_ELEMENT_LOCK_COUNT_EXT:
4748           CHECK_EXT1(EXT_compiled_vertex_array, "GetInteger64v");
4749 -         params[0] = ctx->Array.LockCount;
4750 +         params[0] = (GLint64)(ctx->Array.LockCount);
4751           break;
4752        case GL_TRANSPOSE_COLOR_MATRIX_ARB:
4753           {
4754 @@ -6707,10 +6707,10 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4755           }
4756           break;
4757        case GL_COLOR_MATRIX_STACK_DEPTH_SGI:
4758 -         params[0] = ctx->ColorMatrixStack.Depth + 1;
4759 +         params[0] = (GLint64)(ctx->ColorMatrixStack.Depth + 1);
4760           break;
4761        case GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI:
4762 -         params[0] = MAX_COLOR_STACK_DEPTH;
4763 +         params[0] = (GLint64)(MAX_COLOR_STACK_DEPTH);
4764           break;
4765        case GL_POST_COLOR_MATRIX_RED_SCALE_SGI:
4766           params[0] = IROUND64(ctx->Pixel.PostColorMatrixScale[0]);
4767 @@ -6828,11 +6828,11 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4768           break;
4769        case GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT:
4770           CHECK_EXT1(EXT_secondary_color, "GetInteger64v");
4771 -         params[0] = ctx->Array.ArrayObj->SecondaryColor.Stride;
4772 +         params[0] = (GLint64)(ctx->Array.ArrayObj->SecondaryColor.Stride);
4773           break;
4774        case GL_SECONDARY_COLOR_ARRAY_SIZE_EXT:
4775           CHECK_EXT1(EXT_secondary_color, "GetInteger64v");
4776 -         params[0] = ctx->Array.ArrayObj->SecondaryColor.Size;
4777 +         params[0] = (GLint64)(ctx->Array.ArrayObj->SecondaryColor.Size);
4778           break;
4779        case GL_CURRENT_FOG_COORDINATE_EXT:
4780           CHECK_EXT1(EXT_fog_coord, "GetInteger64v");
4781 @@ -6851,7 +6851,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4782           break;
4783        case GL_FOG_COORDINATE_ARRAY_STRIDE_EXT:
4784           CHECK_EXT1(EXT_fog_coord, "GetInteger64v");
4785 -         params[0] = ctx->Array.ArrayObj->FogCoord.Stride;
4786 +         params[0] = (GLint64)(ctx->Array.ArrayObj->FogCoord.Stride);
4787           break;
4788        case GL_FOG_COORDINATE_SOURCE_EXT:
4789           CHECK_EXT1(EXT_fog_coord, "GetInteger64v");
4790 @@ -6884,10 +6884,10 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4791           params[0] = BOOLEAN_TO_INT64(ctx->Multisample.SampleCoverageInvert);
4792           break;
4793        case GL_SAMPLE_BUFFERS_ARB:
4794 -         params[0] = ctx->DrawBuffer->Visual.sampleBuffers;
4795 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.sampleBuffers);
4796           break;
4797        case GL_SAMPLES_ARB:
4798 -         params[0] = ctx->DrawBuffer->Visual.samples;
4799 +         params[0] = (GLint64)(ctx->DrawBuffer->Visual.samples);
4800           break;
4801        case GL_RASTER_POSITION_UNCLIPPED_IBM:
4802           CHECK_EXT1(IBM_rasterpos_clip, "GetInteger64v");
4803 @@ -6911,7 +6911,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4804           break;
4805        case GL_VERTEX_PROGRAM_BINDING_NV:
4806           CHECK_EXT1(NV_vertex_program, "GetInteger64v");
4807 -         params[0] = (ctx->VertexProgram.Current ? ctx->VertexProgram.Current->Base.Id : 0);
4808 +         params[0] = (GLint64)((ctx->VertexProgram.Current ? ctx->VertexProgram.Current->Base.Id : 0));
4809           break;
4810        case GL_VERTEX_ATTRIB_ARRAY0_NV:
4811           CHECK_EXT1(NV_vertex_program, "GetInteger64v");
4812 @@ -7047,11 +7047,11 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4813           break;
4814        case GL_FRAGMENT_PROGRAM_BINDING_NV:
4815           CHECK_EXT1(NV_fragment_program, "GetInteger64v");
4816 -         params[0] = ctx->FragmentProgram.Current ? ctx->FragmentProgram.Current->Base.Id : 0;
4817 +         params[0] = (GLint64)(ctx->FragmentProgram.Current ? ctx->FragmentProgram.Current->Base.Id : 0);
4818           break;
4819        case GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV:
4820           CHECK_EXT1(NV_fragment_program, "GetInteger64v");
4821 -         params[0] = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
4822 +         params[0] = (GLint64)(MAX_NV_FRAGMENT_PROGRAM_PARAMS);
4823           break;
4824        case GL_TEXTURE_RECTANGLE_NV:
4825           CHECK_EXT1(NV_texture_rectangle, "GetInteger64v");
4826 @@ -7059,11 +7059,11 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4827           break;
4828        case GL_TEXTURE_BINDING_RECTANGLE_NV:
4829           CHECK_EXT1(NV_texture_rectangle, "GetInteger64v");
4830 -         params[0] = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_RECT_INDEX]->Name;
4831 +         params[0] = (GLint64)(ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentTex[TEXTURE_RECT_INDEX]->Name);
4832           break;
4833        case GL_MAX_RECTANGLE_TEXTURE_SIZE_NV:
4834           CHECK_EXT1(NV_texture_rectangle, "GetInteger64v");
4835 -         params[0] = ctx->Const.MaxTextureRectSize;
4836 +         params[0] = (GLint64)(ctx->Const.MaxTextureRectSize);
4837           break;
4838        case GL_STENCIL_TEST_TWO_SIDE_EXT:
4839           CHECK_EXT1(EXT_stencil_two_side, "GetInteger64v");
4840 @@ -7082,42 +7082,42 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4841           params[0] = IROUND64(ctx->Const.MaxSpotExponent);
4842           break;
4843        case GL_ARRAY_BUFFER_BINDING_ARB:
4844 -         params[0] = ctx->Array.ArrayBufferObj->Name;
4845 +         params[0] = (GLint64)(ctx->Array.ArrayBufferObj->Name);
4846           break;
4847        case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
4848 -         params[0] = ctx->Array.ArrayObj->Vertex.BufferObj->Name;
4849 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Vertex.BufferObj->Name);
4850           break;
4851        case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
4852 -         params[0] = ctx->Array.ArrayObj->Normal.BufferObj->Name;
4853 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Normal.BufferObj->Name);
4854           break;
4855        case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
4856 -         params[0] = ctx->Array.ArrayObj->Color.BufferObj->Name;
4857 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Color.BufferObj->Name);
4858           break;
4859        case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
4860 -         params[0] = ctx->Array.ArrayObj->Index.BufferObj->Name;
4861 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Index.BufferObj->Name);
4862           break;
4863        case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
4864 -         params[0] = ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].BufferObj->Name;
4865 +         params[0] = (GLint64)(ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].BufferObj->Name);
4866           break;
4867        case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
4868 -         params[0] = ctx->Array.ArrayObj->EdgeFlag.BufferObj->Name;
4869 +         params[0] = (GLint64)(ctx->Array.ArrayObj->EdgeFlag.BufferObj->Name);
4870           break;
4871        case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
4872 -         params[0] = ctx->Array.ArrayObj->SecondaryColor.BufferObj->Name;
4873 +         params[0] = (GLint64)(ctx->Array.ArrayObj->SecondaryColor.BufferObj->Name);
4874           break;
4875        case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
4876 -         params[0] = ctx->Array.ArrayObj->FogCoord.BufferObj->Name;
4877 +         params[0] = (GLint64)(ctx->Array.ArrayObj->FogCoord.BufferObj->Name);
4878           break;
4879        case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
4880 -         params[0] = ctx->Array.ElementArrayBufferObj->Name;
4881 +         params[0] = (GLint64)(ctx->Array.ElementArrayBufferObj->Name);
4882           break;
4883        case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
4884           CHECK_EXT1(EXT_pixel_buffer_object, "GetInteger64v");
4885 -         params[0] = ctx->Pack.BufferObj->Name;
4886 +         params[0] = (GLint64)(ctx->Pack.BufferObj->Name);
4887           break;
4888        case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
4889           CHECK_EXT1(EXT_pixel_buffer_object, "GetInteger64v");
4890 -         params[0] = ctx->Unpack.BufferObj->Name;
4891 +         params[0] = (GLint64)(ctx->Unpack.BufferObj->Name);
4892           break;
4893        case GL_VERTEX_PROGRAM_ARB:
4894           CHECK_EXT2(ARB_vertex_program, NV_vertex_program, "GetInteger64v");
4895 @@ -7133,11 +7133,11 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4896           break;
4897        case GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB:
4898           CHECK_EXT3(ARB_vertex_program, ARB_fragment_program, NV_vertex_program, "GetInteger64v");
4899 -         params[0] = ctx->Const.MaxProgramMatrixStackDepth;
4900 +         params[0] = (GLint64)(ctx->Const.MaxProgramMatrixStackDepth);
4901           break;
4902        case GL_MAX_PROGRAM_MATRICES_ARB:
4903           CHECK_EXT3(ARB_vertex_program, ARB_fragment_program, NV_vertex_program, "GetInteger64v");
4904 -         params[0] = ctx->Const.MaxProgramMatrices;
4905 +         params[0] = (GLint64)(ctx->Const.MaxProgramMatrices);
4906           break;
4907        case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
4908           CHECK_EXT3(ARB_vertex_program, ARB_fragment_program, NV_vertex_program, "GetInteger64v");
4909 @@ -7189,11 +7189,11 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4910           break;
4911        case GL_MAX_VERTEX_ATTRIBS_ARB:
4912           CHECK_EXT1(ARB_vertex_program, "GetInteger64v");
4913 -         params[0] = ctx->Const.VertexProgram.MaxAttribs;
4914 +         params[0] = (GLint64)(ctx->Const.VertexProgram.MaxAttribs);
4915           break;
4916        case GL_PROGRAM_ERROR_POSITION_ARB:
4917           CHECK_EXT4(NV_vertex_program, ARB_vertex_program, NV_fragment_program, ARB_fragment_program, "GetInteger64v");
4918 -         params[0] = ctx->Program.ErrorPos;
4919 +         params[0] = (GLint64)(ctx->Program.ErrorPos);
4920           break;
4921        case GL_FRAGMENT_PROGRAM_ARB:
4922           CHECK_EXT1(ARB_fragment_program, "GetInteger64v");
4923 @@ -7201,11 +7201,11 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4924           break;
4925        case GL_MAX_TEXTURE_COORDS_ARB:
4926           CHECK_EXT2(ARB_fragment_program, NV_fragment_program, "GetInteger64v");
4927 -         params[0] = ctx->Const.MaxTextureCoordUnits;
4928 +         params[0] = (GLint64)(ctx->Const.MaxTextureCoordUnits);
4929           break;
4930        case GL_MAX_TEXTURE_IMAGE_UNITS_ARB:
4931           CHECK_EXT2(ARB_fragment_program, NV_fragment_program, "GetInteger64v");
4932 -         params[0] = ctx->Const.MaxTextureImageUnits;
4933 +         params[0] = (GLint64)(ctx->Const.MaxTextureImageUnits);
4934           break;
4935        case GL_DEPTH_BOUNDS_TEST_EXT:
4936           CHECK_EXT1(EXT_depth_bounds_test, "GetInteger64v");
4937 @@ -7217,7 +7217,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4938           params[1] = IROUND64(ctx->Depth.BoundsMax);
4939           break;
4940        case GL_MAX_DRAW_BUFFERS_ARB:
4941 -         params[0] = ctx->Const.MaxDrawBuffers;
4942 +         params[0] = (GLint64)(ctx->Const.MaxDrawBuffers);
4943           break;
4944        case GL_DRAW_BUFFER0_ARB:
4945           params[0] = ENUM_TO_INT64(ctx->DrawBuffer->ColorDrawBuffer[0]);
4946 @@ -7257,31 +7257,31 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4947           break;
4948        case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
4949           CHECK_EXT1(OES_read_format, "GetInteger64v");
4950 -         params[0] = ctx->Const.ColorReadType;
4951 +         params[0] = (GLint64)(ctx->Const.ColorReadType);
4952           break;
4953        case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
4954           CHECK_EXT1(OES_read_format, "GetInteger64v");
4955 -         params[0] = ctx->Const.ColorReadFormat;
4956 +         params[0] = (GLint64)(ctx->Const.ColorReadFormat);
4957           break;
4958        case GL_NUM_FRAGMENT_REGISTERS_ATI:
4959           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4960 -         params[0] = 6;
4961 +         params[0] = (GLint64)(6);
4962           break;
4963        case GL_NUM_FRAGMENT_CONSTANTS_ATI:
4964           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4965 -         params[0] = 8;
4966 +         params[0] = (GLint64)(8);
4967           break;
4968        case GL_NUM_PASSES_ATI:
4969           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4970 -         params[0] = 2;
4971 +         params[0] = (GLint64)(2);
4972           break;
4973        case GL_NUM_INSTRUCTIONS_PER_PASS_ATI:
4974           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4975 -         params[0] = 8;
4976 +         params[0] = (GLint64)(8);
4977           break;
4978        case GL_NUM_INSTRUCTIONS_TOTAL_ATI:
4979           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4980 -         params[0] = 16;
4981 +         params[0] = (GLint64)(16);
4982           break;
4983        case GL_COLOR_ALPHA_PAIRING_ATI:
4984           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4985 @@ -7289,23 +7289,23 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
4986           break;
4987        case GL_NUM_LOOPBACK_COMPONENTS_ATI:
4988           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4989 -         params[0] = 3;
4990 +         params[0] = (GLint64)(3);
4991           break;
4992        case GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI:
4993           CHECK_EXT1(ATI_fragment_shader, "GetInteger64v");
4994 -         params[0] = 3;
4995 +         params[0] = (GLint64)(3);
4996           break;
4997        case GL_STENCIL_BACK_FUNC:
4998           params[0] = ENUM_TO_INT64(ctx->Stencil.Function[1]);
4999           break;
5000        case GL_STENCIL_BACK_VALUE_MASK:
5001 -         params[0] = ctx->Stencil.ValueMask[1];
5002 +         params[0] = (GLint64)(ctx->Stencil.ValueMask[1]);
5003           break;
5004        case GL_STENCIL_BACK_WRITEMASK:
5005 -         params[0] = ctx->Stencil.WriteMask[1];
5006 +         params[0] = (GLint64)(ctx->Stencil.WriteMask[1]);
5007           break;
5008        case GL_STENCIL_BACK_REF:
5009 -         params[0] = ctx->Stencil.Ref[1];
5010 +         params[0] = (GLint64)(ctx->Stencil.Ref[1]);
5011           break;
5012        case GL_STENCIL_BACK_FAIL:
5013           params[0] = ENUM_TO_INT64(ctx->Stencil.FailFunc[1]);
5014 @@ -7318,23 +7318,23 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
5015           break;
5016        case GL_FRAMEBUFFER_BINDING_EXT:
5017           CHECK_EXT1(EXT_framebuffer_object, "GetInteger64v");
5018 -         params[0] = ctx->DrawBuffer->Name;
5019 +         params[0] = (GLint64)(ctx->DrawBuffer->Name);
5020           break;
5021        case GL_RENDERBUFFER_BINDING_EXT:
5022           CHECK_EXT1(EXT_framebuffer_object, "GetInteger64v");
5023 -         params[0] = ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
5024 +         params[0] = (GLint64)(ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0);
5025           break;
5026        case GL_MAX_COLOR_ATTACHMENTS_EXT:
5027           CHECK_EXT1(EXT_framebuffer_object, "GetInteger64v");
5028 -         params[0] = ctx->Const.MaxColorAttachments;
5029 +         params[0] = (GLint64)(ctx->Const.MaxColorAttachments);
5030           break;
5031        case GL_MAX_RENDERBUFFER_SIZE_EXT:
5032           CHECK_EXT1(EXT_framebuffer_object, "GetInteger64v");
5033 -         params[0] = ctx->Const.MaxRenderbufferSize;
5034 +         params[0] = (GLint64)(ctx->Const.MaxRenderbufferSize);
5035           break;
5036        case GL_READ_FRAMEBUFFER_BINDING_EXT:
5037           CHECK_EXT1(EXT_framebuffer_blit, "GetInteger64v");
5038 -         params[0] = ctx->ReadBuffer->Name;
5039 +         params[0] = (GLint64)(ctx->ReadBuffer->Name);
5040           break;
5041        case GL_PROVOKING_VERTEX_EXT:
5042           CHECK_EXT1(EXT_provoking_vertex, "GetInteger64v");
5043 @@ -7346,7 +7346,7 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
5044           break;
5045        case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB:
5046           CHECK_EXT1(ARB_fragment_shader, "GetInteger64v");
5047 -         params[0] = ctx->Const.FragmentProgram.MaxUniformComponents;
5048 +         params[0] = (GLint64)(ctx->Const.FragmentProgram.MaxUniformComponents);
5049           break;
5050        case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB:
5051           CHECK_EXT1(ARB_fragment_shader, "GetInteger64v");
5052 @@ -7354,31 +7354,31 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
5053           break;
5054        case GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB:
5055           CHECK_EXT1(ARB_vertex_shader, "GetInteger64v");
5056 -         params[0] = ctx->Const.VertexProgram.MaxUniformComponents;
5057 +         params[0] = (GLint64)(ctx->Const.VertexProgram.MaxUniformComponents);
5058           break;
5059        case GL_MAX_VARYING_FLOATS_ARB:
5060           CHECK_EXT1(ARB_vertex_shader, "GetInteger64v");
5061 -         params[0] = ctx->Const.MaxVarying * 4;
5062 +         params[0] = (GLint64)(ctx->Const.MaxVarying * 4);
5063           break;
5064        case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB:
5065           CHECK_EXT1(ARB_vertex_shader, "GetInteger64v");
5066 -         params[0] = ctx->Const.MaxVertexTextureImageUnits;
5067 +         params[0] = (GLint64)(ctx->Const.MaxVertexTextureImageUnits);
5068           break;
5069        case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB:
5070           CHECK_EXT1(ARB_vertex_shader, "GetInteger64v");
5071 -         params[0] = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
5072 +         params[0] = (GLint64)(MAX_COMBINED_TEXTURE_IMAGE_UNITS);
5073           break;
5074        case GL_CURRENT_PROGRAM:
5075           CHECK_EXT1(ARB_shader_objects, "GetInteger64v");
5076 -         params[0] = ctx->Shader.CurrentProgram ? ctx->Shader.CurrentProgram->Name : 0;
5077 +         params[0] = (GLint64)(ctx->Shader.CurrentProgram ? ctx->Shader.CurrentProgram->Name : 0);
5078           break;
5079        case GL_MAX_SAMPLES:
5080           CHECK_EXT1(ARB_framebuffer_object, "GetInteger64v");
5081 -         params[0] = ctx->Const.MaxSamples;
5082 +         params[0] = (GLint64)(ctx->Const.MaxSamples);
5083           break;
5084        case GL_VERTEX_ARRAY_BINDING_APPLE:
5085           CHECK_EXT1(APPLE_vertex_array_object, "GetInteger64v");
5086 -         params[0] = ctx->Array.ArrayObj->Name;
5087 +         params[0] = (GLint64)(ctx->Array.ArrayObj->Name);
5088           break;
5089        case GL_TEXTURE_CUBE_MAP_SEAMLESS:
5090           CHECK_EXT1(ARB_seamless_cube_map, "GetInteger64v");
5091 diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
5092 index baecbab..139e56a 100644
5093 --- a/src/mesa/main/image.c
5094 +++ b/src/mesa/main/image.c
5095 @@ -5511,7 +5511,7 @@ _mesa_clip_drawpixels(const GLcontext *ctx,
5096     }
5097  
5098     if (*height <= 0)
5099 -      return GL_TRUE;
5100 +      return GL_FALSE;
5101  
5102     return GL_TRUE;
5103  }
5104 @@ -5564,7 +5564,7 @@ _mesa_clip_readpixels(const GLcontext *ctx,
5105        *height -= (*srcY + *height - buffer->Height);
5106  
5107     if (*height <= 0)
5108 -      return GL_TRUE;
5109 +      return GL_FALSE;
5110  
5111     return GL_TRUE;
5112  }
5113 diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
5114 index 6ffaddc..91d8d15 100644
5115 --- a/src/mesa/main/imports.c
5116 +++ b/src/mesa/main/imports.c
5117 @@ -48,6 +48,13 @@
5118  #include "context.h"
5119  #include "version.h"
5120  
5121 +#ifdef _GNU_SOURCE
5122 +#include <locale.h>
5123 +#ifdef __APPLE__
5124 +#include <xlocale.h>
5125 +#endif
5126 +#endif
5127 +
5128  
5129  #define MAXSTRING 4000  /* for vsnprintf() */
5130  
5131 @@ -908,7 +915,15 @@ _mesa_atoi(const char *s)
5132  double
5133  _mesa_strtod( const char *s, char **end )
5134  {
5135 +#ifdef _GNU_SOURCE
5136 +   static locale_t loc = NULL;
5137 +   if (!loc) {
5138 +      loc = newlocale(LC_CTYPE_MASK, "C", NULL);
5139 +   }
5140 +   return strtod_l(s, end, loc);
5141 +#else
5142     return strtod(s, end);
5143 +#endif
5144  }
5145  
5146  /** Compute simple checksum/hash for a string */
5147 @@ -919,9 +934,9 @@ _mesa_str_checksum(const char *str)
5148     unsigned int sum, i;
5149     const char *c;
5150     sum = i = 1;
5151 -   for (c = str; *c; c++)
5152 +   for (c = str; *c; c++, i++)
5153        sum += *c * (i % 100);
5154 -   return sum;
5155 +   return sum + i;
5156  }
5157  
5158  
5159 diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
5160 index 3dca09d..c3928fa 100644
5161 --- a/src/mesa/main/mipmap.c
5162 +++ b/src/mesa/main/mipmap.c
5163 @@ -1501,8 +1501,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
5164     GLuint comps;
5165  
5166     ASSERT(texObj);
5167 -   /* XXX choose cube map face here??? */
5168 -   srcImage = texObj->Image[0][texObj->BaseLevel];
5169 +   srcImage = _mesa_select_tex_image(ctx, texObj, target, texObj->BaseLevel);
5170     ASSERT(srcImage);
5171  
5172     maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
5173 @@ -1510,7 +1509,9 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
5174  
5175     /* Find convertFormat - the format that do_row() will process */
5176     if (srcImage->IsCompressed) {
5177 -      /* setup for compressed textures */
5178 +      /* setup for compressed textures - need to allocate temporary
5179 +       * image buffers to hold uncompressed images.
5180 +       */
5181        GLuint row;
5182        GLint  components, size;
5183        GLchan *dst;
5184 @@ -1587,11 +1588,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
5185                                           &dstWidth, &dstHeight, &dstDepth);
5186        if (!nextLevel) {
5187           /* all done */
5188 -         if (srcImage->IsCompressed) {
5189 -            _mesa_free((void *) srcData);
5190 -            _mesa_free(dstData);
5191 -         }
5192 -         return;
5193 +         break;
5194        }
5195  
5196        /* get dest gl_texture_image */
5197 @@ -1682,6 +1679,12 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
5198        }
5199  
5200     } /* loop over mipmap levels */
5201 +
5202 +   if (srcImage->IsCompressed) {
5203 +      /* free uncompressed image buffers */
5204 +      _mesa_free((void *) srcData);
5205 +      _mesa_free(dstData);
5206 +   }
5207  }
5208  
5209  
5210 diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
5211 index 38be826..5bef7c8 100644
5212 --- a/src/mesa/main/renderbuffer.c
5213 +++ b/src/mesa/main/renderbuffer.c
5214 @@ -1955,7 +1955,7 @@ _mesa_add_aux_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb,
5215        return GL_FALSE;
5216     }
5217  
5218 -   assert(numBuffers < MAX_AUX_BUFFERS);
5219 +   assert(numBuffers <= MAX_AUX_BUFFERS);
5220  
5221     for (i = 0; i < numBuffers; i++) {
5222        struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, 0);
5223 diff --git a/src/mesa/main/syncobj.c b/src/mesa/main/syncobj.c
5224 index 64f923f..ac3f9eb 100644
5225 --- a/src/mesa/main/syncobj.c
5226 +++ b/src/mesa/main/syncobj.c
5227 @@ -190,7 +190,7 @@ _mesa_unref_sync_object(GLcontext *ctx, struct gl_sync_object *syncObj)
5228  }
5229  
5230  
5231 -GLboolean
5232 +GLboolean GLAPIENTRY
5233  _mesa_IsSync(GLsync sync)
5234  {
5235     GET_CURRENT_CONTEXT(ctx);
5236 @@ -201,7 +201,7 @@ _mesa_IsSync(GLsync sync)
5237  }
5238  
5239  
5240 -void
5241 +void GLAPIENTRY
5242  _mesa_DeleteSync(GLsync sync)
5243  {
5244     GET_CURRENT_CONTEXT(ctx);
5245 @@ -231,7 +231,7 @@ _mesa_DeleteSync(GLsync sync)
5246  }
5247  
5248  
5249 -GLsync
5250 +GLsync GLAPIENTRY
5251  _mesa_FenceSync(GLenum condition, GLbitfield flags)
5252  {
5253     GET_CURRENT_CONTEXT(ctx);
5254 @@ -278,7 +278,7 @@ _mesa_FenceSync(GLenum condition, GLbitfield flags)
5255  }
5256  
5257  
5258 -GLenum
5259 +GLenum GLAPIENTRY
5260  _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5261  {
5262     GET_CURRENT_CONTEXT(ctx);
5263 @@ -319,7 +319,7 @@ _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5264  }
5265  
5266  
5267 -void
5268 +void GLAPIENTRY
5269  _mesa_WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5270  {
5271     GET_CURRENT_CONTEXT(ctx);
5272 @@ -348,7 +348,7 @@ _mesa_WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5273  }
5274  
5275  
5276 -void
5277 +void GLAPIENTRY
5278  _mesa_GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length,
5279                 GLint *values)
5280  {
5281 diff --git a/src/mesa/main/syncobj.h b/src/mesa/main/syncobj.h
5282 index fc160af..f23fa28 100644
5283 --- a/src/mesa/main/syncobj.h
5284 +++ b/src/mesa/main/syncobj.h
5285 @@ -48,22 +48,22 @@ _mesa_ref_sync_object(GLcontext *ctx, struct gl_sync_object *syncObj);
5286  extern void
5287  _mesa_unref_sync_object(GLcontext *ctx, struct gl_sync_object *syncObj);
5288  
5289 -extern GLboolean
5290 +extern GLboolean GLAPIENTRY
5291  _mesa_IsSync(GLsync sync);
5292  
5293 -extern void
5294 +extern void GLAPIENTRY
5295  _mesa_DeleteSync(GLsync sync);
5296  
5297 -extern GLsync
5298 +extern GLsync GLAPIENTRY
5299  _mesa_FenceSync(GLenum condition, GLbitfield flags);
5300  
5301 -extern GLenum
5302 +extern GLenum GLAPIENTRY
5303  _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
5304  
5305 -extern void
5306 +extern void GLAPIENTRY
5307  _mesa_WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
5308  
5309 -extern void
5310 +extern void GLAPIENTRY
5311  _mesa_GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length,
5312                 GLint *values);
5313  
5314 diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
5315 index c1b8c76..2cda4dd 100644
5316 --- a/src/mesa/main/texcompress.c
5317 +++ b/src/mesa/main/texcompress.c
5318 @@ -360,3 +360,53 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
5319  
5320     return addr;
5321  }
5322 +
5323 +
5324 +/**
5325 + * Given a compressed MESA_FORMAT_x value, return the corresponding
5326 + * GLenum for that format.
5327 + * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT)
5328 + * which must return the specific texture format used when the user might
5329 + * have originally specified a generic compressed format in their
5330 + * glTexImage2D() call.
5331 + * For non-compressed textures, we always return the user-specified
5332 + * internal format unchanged.
5333 + */
5334 +GLenum
5335 +_mesa_compressed_format_to_glenum(GLcontext *ctx, GLuint mesaFormat)
5336 +{
5337 +   switch (mesaFormat) {
5338 +#if FEATURE_texture_fxt1
5339 +   case MESA_FORMAT_RGB_FXT1:
5340 +      return GL_COMPRESSED_RGB_FXT1_3DFX;
5341 +   case MESA_FORMAT_RGBA_FXT1:
5342 +      return GL_COMPRESSED_RGBA_FXT1_3DFX;
5343 +#endif
5344 +#if FEATURE_texture_s3tc
5345 +   case MESA_FORMAT_RGB_DXT1:
5346 +      return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
5347 +   case MESA_FORMAT_RGBA_DXT1:
5348 +      return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
5349 +   case MESA_FORMAT_RGBA_DXT3:
5350 +      return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
5351 +   case MESA_FORMAT_RGBA_DXT5:
5352 +      return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
5353 +#if FEATURE_EXT_texture_sRGB
5354 +   case MESA_FORMAT_SRGB_DXT1:
5355 +      return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
5356 +   case MESA_FORMAT_SRGBA_DXT1:
5357 +      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
5358 +   case MESA_FORMAT_SRGBA_DXT3:
5359 +      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
5360 +   case MESA_FORMAT_SRGBA_DXT5:
5361 +      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
5362 +#endif
5363 +#endif
5364 +   default:
5365 +      _mesa_problem(ctx, "Unexpected mesa texture format in"
5366 +                    " _mesa_compressed_format_to_glenum()");
5367 +      return 0;
5368 +   }
5369 +}
5370 +
5371 +
5372 diff --git a/src/mesa/main/texcompress.h b/src/mesa/main/texcompress.h
5373 index 44f3338..0f1a38f 100644
5374 --- a/src/mesa/main/texcompress.h
5375 +++ b/src/mesa/main/texcompress.h
5376 @@ -52,6 +52,10 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
5377                                 GLsizei width, const GLubyte *image);
5378  
5379  
5380 +extern GLenum
5381 +_mesa_compressed_format_to_glenum(GLcontext *ctx, GLuint mesaFormat);
5382 +
5383 +
5384  extern void
5385  _mesa_init_texture_s3tc( GLcontext *ctx );
5386  
5387 diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
5388 index c709004..9d5534e 100644
5389 --- a/src/mesa/main/texformat.c
5390 +++ b/src/mesa/main/texformat.c
5391 @@ -1590,25 +1590,25 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
5392        case GL_COMPRESSED_INTENSITY_ARB:
5393           return &_mesa_texformat_intensity;
5394        case GL_COMPRESSED_RGB_ARB:
5395 -#if FEATURE_texture_fxt1
5396 -         if (ctx->Extensions.TDFX_texture_compression_FXT1)
5397 -            return &_mesa_texformat_rgb_fxt1;
5398 -#endif
5399  #if FEATURE_texture_s3tc
5400           if (ctx->Extensions.EXT_texture_compression_s3tc ||
5401               ctx->Extensions.S3_s3tc)
5402              return &_mesa_texformat_rgb_dxt1;
5403  #endif
5404 -         return &_mesa_texformat_rgb;
5405 -      case GL_COMPRESSED_RGBA_ARB:
5406  #if FEATURE_texture_fxt1
5407           if (ctx->Extensions.TDFX_texture_compression_FXT1)
5408 -            return &_mesa_texformat_rgba_fxt1;
5409 +            return &_mesa_texformat_rgb_fxt1;
5410  #endif
5411 +         return &_mesa_texformat_rgb;
5412 +      case GL_COMPRESSED_RGBA_ARB:
5413  #if FEATURE_texture_s3tc
5414           if (ctx->Extensions.EXT_texture_compression_s3tc ||
5415               ctx->Extensions.S3_s3tc)
5416 -            return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1, see spec */
5417 +            return &_mesa_texformat_rgba_dxt5; /* Not rgba_dxt1, see spec */
5418 +#endif
5419 +#if FEATURE_texture_fxt1
5420 +         if (ctx->Extensions.TDFX_texture_compression_FXT1)
5421 +            return &_mesa_texformat_rgba_fxt1;
5422  #endif
5423           return &_mesa_texformat_rgba;
5424        default:
5425 diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
5426 index d09c439..da55ac8 100644
5427 --- a/src/mesa/main/texobj.c
5428 +++ b/src/mesa/main/texobj.c
5429 @@ -863,7 +863,7 @@ unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj)
5430        for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
5431           if (texObj == unit->CurrentTex[tex]) {
5432              _mesa_reference_texobj(&unit->CurrentTex[tex],
5433 -                                   ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]);
5434 +                                   ctx->Shared->DefaultTex[tex]);
5435              ASSERT(unit->CurrentTex[tex]);
5436              break;
5437           }
5438 diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
5439 index b2fbe22..9d1fdd0 100644
5440 --- a/src/mesa/main/texparam.c
5441 +++ b/src/mesa/main/texparam.c
5442 @@ -776,7 +776,15 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
5443           *params = img->Depth;
5444           break;
5445        case GL_TEXTURE_INTERNAL_FORMAT:
5446 -         *params = img->InternalFormat;
5447 +         if (img->IsCompressed) {
5448 +            /* need to return the actual compressed format */
5449 +            *params = _mesa_compressed_format_to_glenum(ctx,
5450 +                                          img->TexFormat->MesaFormat);
5451 +         }
5452 +         else {
5453 +            /* return the user's requested internal format */
5454 +            *params = img->InternalFormat;
5455 +         }
5456           break;
5457        case GL_TEXTURE_BORDER:
5458           *params = img->Border;
5459 diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
5460 index 861c5f3..8292d43 100644
5461 --- a/src/mesa/main/texstate.c
5462 +++ b/src/mesa/main/texstate.c
5463 @@ -99,16 +99,22 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst )
5464        dst->Texture.Unit[u].BumpTarget = src->Texture.Unit[u].BumpTarget;
5465        COPY_4V(dst->Texture.Unit[u].RotMatrix, src->Texture.Unit[u].RotMatrix);
5466  
5467 +      /*
5468 +       * XXX strictly speaking, we should compare texture names/ids and
5469 +       * bind textures in the dest context according to id.  For now, only
5470 +       * copy bindings if the contexts share the same pool of textures to
5471 +       * avoid refcounting bugs.
5472 +       */
5473 +      if (dst->Shared == src->Shared) {
5474 +         /* copy texture object bindings, not contents of texture objects */
5475 +         _mesa_lock_context_textures(dst);
5476  
5477 -      /* copy texture object bindings, not contents of texture objects */
5478 -      _mesa_lock_context_textures(dst);
5479 -
5480 -      for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
5481 -         _mesa_reference_texobj(&dst->Texture.Unit[u].CurrentTex[tex],
5482 -                                src->Texture.Unit[u].CurrentTex[tex]);
5483 +         for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
5484 +            _mesa_reference_texobj(&dst->Texture.Unit[u].CurrentTex[tex],
5485 +                                   src->Texture.Unit[u].CurrentTex[tex]);
5486 +         }
5487 +         _mesa_unlock_context_textures(dst);
5488        }
5489 -
5490 -      _mesa_unlock_context_textures(dst);
5491     }
5492  }
5493  
5494 diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
5495 index a22db62..d323795 100644
5496 --- a/src/mesa/main/texstore.c
5497 +++ b/src/mesa/main/texstore.c
5498 @@ -589,8 +589,12 @@ _mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
5499     /* unpack and transfer the source image */
5500     tempImage = (GLchan *) _mesa_malloc(srcWidth * srcHeight * srcDepth
5501                                         * components * sizeof(GLchan));
5502 -   if (!tempImage)
5503 +   if (!tempImage) {
5504 +      if (freeSrcImage) {
5505 +         _mesa_free((void *) srcAddr);
5506 +      }
5507        return NULL;
5508 +   }
5509  
5510     dst = tempImage;
5511     for (img = 0; img < srcDepth; img++) {
5512 diff --git a/src/mesa/shader/hash_table.c b/src/mesa/shader/hash_table.c
5513 index 881179f..e89a256 100644
5514 --- a/src/mesa/shader/hash_table.c
5515 +++ b/src/mesa/shader/hash_table.c
5516 @@ -27,10 +27,6 @@
5517   *
5518   * \author Ian Romanick <ian.d.romanick@intel.com>
5519   */
5520 -#include <stdlib.h>
5521 -#include <string.h>
5522 -
5523 -#include <assert.h>
5524  
5525  #include "main/imports.h"
5526  #include "main/simple_list.h"
5527 diff --git a/src/mesa/shader/lex.yy.c b/src/mesa/shader/lex.yy.c
5528 index 709426f..728c2dc 100644
5529 --- a/src/mesa/shader/lex.yy.c
5530 +++ b/src/mesa/shader/lex.yy.c
5531 @@ -53,7 +53,6 @@ typedef int flex_int32_t;
5532  typedef unsigned char flex_uint8_t; 
5533  typedef unsigned short int flex_uint16_t;
5534  typedef unsigned int flex_uint32_t;
5535 -#endif /* ! C99 */
5536  
5537  /* Limits of integral types. */
5538  #ifndef INT8_MIN
5539 @@ -84,6 +83,8 @@ typedef unsigned int flex_uint32_t;
5540  #define UINT32_MAX             (4294967295U)
5541  #endif
5542  
5543 +#endif /* ! C99 */
5544 +
5545  #endif /* ! FLEXINT_H */
5546  
5547  #ifdef __cplusplus
5548 @@ -157,7 +158,15 @@ typedef void* yyscan_t;
5549  
5550  /* Size of default input buffer. */
5551  #ifndef YY_BUF_SIZE
5552 +#ifdef __ia64__
5553 +/* On IA-64, the buffer size is 16k, not 8k.
5554 + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
5555 + * Ditto for the __ia64__ case accordingly.
5556 + */
5557 +#define YY_BUF_SIZE 32768
5558 +#else
5559  #define YY_BUF_SIZE 16384
5560 +#endif /* __ia64__ */
5561  #endif
5562  
5563  /* The state buf must be large enough to hold one state per character in the main buffer.
5564 @@ -900,6 +909,7 @@ static yyconst flex_int16_t yy_chk[1023] =
5565   * DEALINGS IN THE SOFTWARE.
5566   */
5567  #include "main/glheader.h"
5568 +#include "main/imports.h"
5569  #include "prog_instruction.h"
5570  #include "prog_statevars.h"
5571  
5572 @@ -917,7 +927,7 @@ static yyconst flex_int16_t yy_chk[1023] =
5573        if (condition) {                                 \
5574          return token;                                  \
5575        } else {                                         \
5576 -        yylval->string = strdup(yytext);               \
5577 +        yylval->string = return_string(yyextra, yytext);       \
5578          return IDENTIFIER;                             \
5579        }                                                        \
5580     } while (0)
5581 @@ -940,7 +950,7 @@ static yyconst flex_int16_t yy_chk[1023] =
5582          yylval->temp_inst.SaturateMode = SATURATE_ ## sat; \
5583          return token;                                  \
5584        } else {                                         \
5585 -        yylval->string = strdup(yytext);               \
5586 +        yylval->string = return_string(yyextra, yytext);               \
5587          return IDENTIFIER;                             \
5588        }                                                        \
5589     } while (0)
5590 @@ -948,6 +958,45 @@ static yyconst flex_int16_t yy_chk[1023] =
5591  #define SWIZZLE_INVAL  MAKE_SWIZZLE4(SWIZZLE_NIL, SWIZZLE_NIL, \
5592                                      SWIZZLE_NIL, SWIZZLE_NIL)
5593  
5594 +/**
5595 + * Send a string to the parser using asm_parser_state::string_dumpster
5596 + *
5597 + * Sends a string to the parser using asm_parser_state::string_dumpster as a
5598 + * temporary storage buffer.  Data previously stored in
5599 + * asm_parser_state::string_dumpster will be lost.  If
5600 + * asm_parser_state::string_dumpster is not large enough to hold the new
5601 + * string, the buffer size will be increased.  The buffer size is \b never
5602 + * decreased.
5603 + *
5604 + * \param state   Assembler parser state tracking
5605 + * \param str     String to be passed to the parser
5606 + *
5607 + * \return
5608 + * A pointer to asm_parser_state::string_dumpster on success or \c NULL on
5609 + * failure.  Currently the only failure case is \c ENOMEM.
5610 + */
5611 +static char *
5612 +return_string(struct asm_parser_state *state, const char *str)
5613 +{
5614 +   const size_t len = strlen(str);
5615 +
5616 +   if (len >= state->dumpster_size) {
5617 +      char *const dumpster = _mesa_realloc(state->string_dumpster,
5618 +                                          state->dumpster_size,
5619 +                                          len + 1);
5620 +      if (dumpster == NULL) {
5621 +        return NULL;
5622 +      }
5623 +
5624 +      state->string_dumpster = dumpster;
5625 +      state->dumpster_size = len + 1;
5626 +   }
5627 +
5628 +   memcpy(state->string_dumpster, str, len + 1);
5629 +   return state->string_dumpster;
5630 +}
5631 +
5632 +
5633  static unsigned
5634  mask_from_char(char c)
5635  {
5636 @@ -1003,7 +1052,7 @@ swiz_from_char(char c)
5637     } while(0);
5638  
5639  #define YY_EXTRA_TYPE struct asm_parser_state *
5640 -#line 1007 "lex.yy.c"
5641 +#line 1056 "lex.yy.c"
5642  
5643  #define INITIAL 0
5644  
5645 @@ -1140,7 +1189,12 @@ static int input (yyscan_t yyscanner );
5646  
5647  /* Amount of stuff to slurp up with each read. */
5648  #ifndef YY_READ_BUF_SIZE
5649 +#ifdef __ia64__
5650 +/* On IA-64, the buffer size is 16k, not 8k */
5651 +#define YY_READ_BUF_SIZE 16384
5652 +#else
5653  #define YY_READ_BUF_SIZE 8192
5654 +#endif /* __ia64__ */
5655  #endif
5656  
5657  /* Copy whatever the last rule matched to the standard output. */
5658 @@ -1148,7 +1202,7 @@ static int input (yyscan_t yyscanner );
5659  /* This used to be an fputs(), but since the string might contain NUL's,
5660   * we now use fwrite().
5661   */
5662 -#define ECHO fwrite( yytext, yyleng, 1, yyout )
5663 +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
5664  #endif
5665  
5666  /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
5667 @@ -1159,7 +1213,7 @@ static int input (yyscan_t yyscanner );
5668         if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
5669                 { \
5670                 int c = '*'; \
5671 -               unsigned n; \
5672 +               size_t n; \
5673                 for ( n = 0; n < max_size && \
5674                              (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
5675                         buf[n] = (char) c; \
5676 @@ -1244,10 +1298,10 @@ YY_DECL
5677         register int yy_act;
5678      struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5679  
5680 -#line 136 "program_lexer.l"
5681 +#line 176 "program_lexer.l"
5682  
5683  
5684 -#line 1251 "lex.yy.c"
5685 +#line 1305 "lex.yy.c"
5686  
5687      yylval = yylval_param;
5688  
5689 @@ -1336,17 +1390,17 @@ do_action:      /* This label is used only to access EOF actions. */
5690  
5691  case 1:
5692  YY_RULE_SETUP
5693 -#line 138 "program_lexer.l"
5694 +#line 178 "program_lexer.l"
5695  { return ARBvp_10; }
5696         YY_BREAK
5697  case 2:
5698  YY_RULE_SETUP
5699 -#line 139 "program_lexer.l"
5700 +#line 179 "program_lexer.l"
5701  { return ARBfp_10; }
5702         YY_BREAK
5703  case 3:
5704  YY_RULE_SETUP
5705 -#line 140 "program_lexer.l"
5706 +#line 180 "program_lexer.l"
5707  {
5708     yylval->integer = at_address;
5709     return_token_or_IDENTIFIER(require_ARB_vp, ADDRESS);
5710 @@ -1354,760 +1408,760 @@ YY_RULE_SETUP
5711         YY_BREAK
5712  case 4:
5713  YY_RULE_SETUP
5714 -#line 144 "program_lexer.l"
5715 +#line 184 "program_lexer.l"
5716  { return ALIAS; }
5717         YY_BREAK
5718  case 5:
5719  YY_RULE_SETUP
5720 -#line 145 "program_lexer.l"
5721 +#line 185 "program_lexer.l"
5722  { return ATTRIB; }
5723         YY_BREAK
5724  case 6:
5725  YY_RULE_SETUP
5726 -#line 146 "program_lexer.l"
5727 +#line 186 "program_lexer.l"
5728  { return END; }
5729         YY_BREAK
5730  case 7:
5731  YY_RULE_SETUP
5732 -#line 147 "program_lexer.l"
5733 +#line 187 "program_lexer.l"
5734  { return OPTION; }
5735         YY_BREAK
5736  case 8:
5737  YY_RULE_SETUP
5738 -#line 148 "program_lexer.l"
5739 +#line 188 "program_lexer.l"
5740  { return OUTPUT; }
5741         YY_BREAK
5742  case 9:
5743  YY_RULE_SETUP
5744 -#line 149 "program_lexer.l"
5745 +#line 189 "program_lexer.l"
5746  { return PARAM; }
5747         YY_BREAK
5748  case 10:
5749  YY_RULE_SETUP
5750 -#line 150 "program_lexer.l"
5751 +#line 190 "program_lexer.l"
5752  { yylval->integer = at_temp; return TEMP; }
5753         YY_BREAK
5754  case 11:
5755  YY_RULE_SETUP
5756 -#line 152 "program_lexer.l"
5757 +#line 192 "program_lexer.l"
5758  { return_opcode(             1, VECTOR_OP, ABS, OFF); }
5759         YY_BREAK
5760  case 12:
5761  YY_RULE_SETUP
5762 -#line 153 "program_lexer.l"
5763 +#line 193 "program_lexer.l"
5764  { return_opcode(require_ARB_fp, VECTOR_OP, ABS, ZERO_ONE); }
5765         YY_BREAK
5766  case 13:
5767  YY_RULE_SETUP
5768 -#line 154 "program_lexer.l"
5769 +#line 194 "program_lexer.l"
5770  { return_opcode(             1, BIN_OP, ADD, OFF); }
5771         YY_BREAK
5772  case 14:
5773  YY_RULE_SETUP
5774 -#line 155 "program_lexer.l"
5775 +#line 195 "program_lexer.l"
5776  { return_opcode(require_ARB_fp, BIN_OP, ADD, ZERO_ONE); }
5777         YY_BREAK
5778  case 15:
5779  YY_RULE_SETUP
5780 -#line 156 "program_lexer.l"
5781 +#line 196 "program_lexer.l"
5782  { return_opcode(require_ARB_vp, ARL, ARL, OFF); }
5783         YY_BREAK
5784  case 16:
5785  YY_RULE_SETUP
5786 -#line 158 "program_lexer.l"
5787 +#line 198 "program_lexer.l"
5788  { return_opcode(require_ARB_fp, TRI_OP, CMP, OFF); }
5789         YY_BREAK
5790  case 17:
5791  YY_RULE_SETUP
5792 -#line 159 "program_lexer.l"
5793 +#line 199 "program_lexer.l"
5794  { return_opcode(require_ARB_fp, TRI_OP, CMP, ZERO_ONE); }
5795         YY_BREAK
5796  case 18:
5797  YY_RULE_SETUP
5798 -#line 160 "program_lexer.l"
5799 +#line 200 "program_lexer.l"
5800  { return_opcode(require_ARB_fp, SCALAR_OP, COS, OFF); }
5801         YY_BREAK
5802  case 19:
5803  YY_RULE_SETUP
5804 -#line 161 "program_lexer.l"
5805 +#line 201 "program_lexer.l"
5806  { return_opcode(require_ARB_fp, SCALAR_OP, COS, ZERO_ONE); }
5807         YY_BREAK
5808  case 20:
5809  YY_RULE_SETUP
5810 -#line 163 "program_lexer.l"
5811 +#line 203 "program_lexer.l"
5812  { return_opcode(             1, BIN_OP, DP3, OFF); }
5813         YY_BREAK
5814  case 21:
5815  YY_RULE_SETUP
5816 -#line 164 "program_lexer.l"
5817 +#line 204 "program_lexer.l"
5818  { return_opcode(require_ARB_fp, BIN_OP, DP3, ZERO_ONE); }
5819         YY_BREAK
5820  case 22:
5821  YY_RULE_SETUP
5822 -#line 165 "program_lexer.l"
5823 +#line 205 "program_lexer.l"
5824  { return_opcode(             1, BIN_OP, DP4, OFF); }
5825         YY_BREAK
5826  case 23:
5827  YY_RULE_SETUP
5828 -#line 166 "program_lexer.l"
5829 +#line 206 "program_lexer.l"
5830  { return_opcode(require_ARB_fp, BIN_OP, DP4, ZERO_ONE); }
5831         YY_BREAK
5832  case 24:
5833  YY_RULE_SETUP
5834 -#line 167 "program_lexer.l"
5835 +#line 207 "program_lexer.l"
5836  { return_opcode(             1, BIN_OP, DPH, OFF); }
5837         YY_BREAK
5838  case 25:
5839  YY_RULE_SETUP
5840 -#line 168 "program_lexer.l"
5841 +#line 208 "program_lexer.l"
5842  { return_opcode(require_ARB_fp, BIN_OP, DPH, ZERO_ONE); }
5843         YY_BREAK
5844  case 26:
5845  YY_RULE_SETUP
5846 -#line 169 "program_lexer.l"
5847 +#line 209 "program_lexer.l"
5848  { return_opcode(             1, BIN_OP, DST, OFF); }
5849         YY_BREAK
5850  case 27:
5851  YY_RULE_SETUP
5852 -#line 170 "program_lexer.l"
5853 +#line 210 "program_lexer.l"
5854  { return_opcode(require_ARB_fp, BIN_OP, DST, ZERO_ONE); }
5855         YY_BREAK
5856  case 28:
5857  YY_RULE_SETUP
5858 -#line 172 "program_lexer.l"
5859 +#line 212 "program_lexer.l"
5860  { return_opcode(             1, SCALAR_OP, EX2, OFF); }
5861         YY_BREAK
5862  case 29:
5863  YY_RULE_SETUP
5864 -#line 173 "program_lexer.l"
5865 +#line 213 "program_lexer.l"
5866  { return_opcode(require_ARB_fp, SCALAR_OP, EX2, ZERO_ONE); }
5867         YY_BREAK
5868  case 30:
5869  YY_RULE_SETUP
5870 -#line 174 "program_lexer.l"
5871 +#line 214 "program_lexer.l"
5872  { return_opcode(require_ARB_vp, SCALAR_OP, EXP, OFF); }
5873         YY_BREAK
5874  case 31:
5875  YY_RULE_SETUP
5876 -#line 176 "program_lexer.l"
5877 +#line 216 "program_lexer.l"
5878  { return_opcode(             1, VECTOR_OP, FLR, OFF); }
5879         YY_BREAK
5880  case 32:
5881  YY_RULE_SETUP
5882 -#line 177 "program_lexer.l"
5883 +#line 217 "program_lexer.l"
5884  { return_opcode(require_ARB_fp, VECTOR_OP, FLR, ZERO_ONE); }
5885         YY_BREAK
5886  case 33:
5887  YY_RULE_SETUP
5888 -#line 178 "program_lexer.l"
5889 +#line 218 "program_lexer.l"
5890  { return_opcode(             1, VECTOR_OP, FRC, OFF); }
5891         YY_BREAK
5892  case 34:
5893  YY_RULE_SETUP
5894 -#line 179 "program_lexer.l"
5895 +#line 219 "program_lexer.l"
5896  { return_opcode(require_ARB_fp, VECTOR_OP, FRC, ZERO_ONE); }
5897         YY_BREAK
5898  case 35:
5899  YY_RULE_SETUP
5900 -#line 181 "program_lexer.l"
5901 +#line 221 "program_lexer.l"
5902  { return_opcode(require_ARB_fp, KIL, KIL, OFF); }
5903         YY_BREAK
5904  case 36:
5905  YY_RULE_SETUP
5906 -#line 183 "program_lexer.l"
5907 +#line 223 "program_lexer.l"
5908  { return_opcode(             1, VECTOR_OP, LIT, OFF); }
5909         YY_BREAK
5910  case 37:
5911  YY_RULE_SETUP
5912 -#line 184 "program_lexer.l"
5913 +#line 224 "program_lexer.l"
5914  { return_opcode(require_ARB_fp, VECTOR_OP, LIT, ZERO_ONE); }
5915         YY_BREAK
5916  case 38:
5917  YY_RULE_SETUP
5918 -#line 185 "program_lexer.l"
5919 +#line 225 "program_lexer.l"
5920  { return_opcode(             1, SCALAR_OP, LG2, OFF); }
5921         YY_BREAK
5922  case 39:
5923  YY_RULE_SETUP
5924 -#line 186 "program_lexer.l"
5925 +#line 226 "program_lexer.l"
5926  { return_opcode(require_ARB_fp, SCALAR_OP, LG2, ZERO_ONE); }
5927         YY_BREAK
5928  case 40:
5929  YY_RULE_SETUP
5930 -#line 187 "program_lexer.l"
5931 +#line 227 "program_lexer.l"
5932  { return_opcode(require_ARB_vp, SCALAR_OP, LOG, OFF); }
5933         YY_BREAK
5934  case 41:
5935  YY_RULE_SETUP
5936 -#line 188 "program_lexer.l"
5937 +#line 228 "program_lexer.l"
5938  { return_opcode(require_ARB_fp, TRI_OP, LRP, OFF); }
5939         YY_BREAK
5940  case 42:
5941  YY_RULE_SETUP
5942 -#line 189 "program_lexer.l"
5943 +#line 229 "program_lexer.l"
5944  { return_opcode(require_ARB_fp, TRI_OP, LRP, ZERO_ONE); }
5945         YY_BREAK
5946  case 43:
5947  YY_RULE_SETUP
5948 -#line 191 "program_lexer.l"
5949 +#line 231 "program_lexer.l"
5950  { return_opcode(             1, TRI_OP, MAD, OFF); }
5951         YY_BREAK
5952  case 44:
5953  YY_RULE_SETUP
5954 -#line 192 "program_lexer.l"
5955 +#line 232 "program_lexer.l"
5956  { return_opcode(require_ARB_fp, TRI_OP, MAD, ZERO_ONE); }
5957         YY_BREAK
5958  case 45:
5959  YY_RULE_SETUP
5960 -#line 193 "program_lexer.l"
5961 +#line 233 "program_lexer.l"
5962  { return_opcode(             1, BIN_OP, MAX, OFF); }
5963         YY_BREAK
5964  case 46:
5965  YY_RULE_SETUP
5966 -#line 194 "program_lexer.l"
5967 +#line 234 "program_lexer.l"
5968  { return_opcode(require_ARB_fp, BIN_OP, MAX, ZERO_ONE); }
5969         YY_BREAK
5970  case 47:
5971  YY_RULE_SETUP
5972 -#line 195 "program_lexer.l"
5973 +#line 235 "program_lexer.l"
5974  { return_opcode(             1, BIN_OP, MIN, OFF); }
5975         YY_BREAK
5976  case 48:
5977  YY_RULE_SETUP
5978 -#line 196 "program_lexer.l"
5979 +#line 236 "program_lexer.l"
5980  { return_opcode(require_ARB_fp, BIN_OP, MIN, ZERO_ONE); }
5981         YY_BREAK
5982  case 49:
5983  YY_RULE_SETUP
5984 -#line 197 "program_lexer.l"
5985 +#line 237 "program_lexer.l"
5986  { return_opcode(             1, VECTOR_OP, MOV, OFF); }
5987         YY_BREAK
5988  case 50:
5989  YY_RULE_SETUP
5990 -#line 198 "program_lexer.l"
5991 +#line 238 "program_lexer.l"
5992  { return_opcode(require_ARB_fp, VECTOR_OP, MOV, ZERO_ONE); }
5993         YY_BREAK
5994  case 51:
5995  YY_RULE_SETUP
5996 -#line 199 "program_lexer.l"
5997 +#line 239 "program_lexer.l"
5998  { return_opcode(             1, BIN_OP, MUL, OFF); }
5999         YY_BREAK
6000  case 52:
6001  YY_RULE_SETUP
6002 -#line 200 "program_lexer.l"
6003 +#line 240 "program_lexer.l"
6004  { return_opcode(require_ARB_fp, BIN_OP, MUL, ZERO_ONE); }
6005         YY_BREAK
6006  case 53:
6007  YY_RULE_SETUP
6008 -#line 202 "program_lexer.l"
6009 +#line 242 "program_lexer.l"
6010  { return_opcode(             1, BINSC_OP, POW, OFF); }
6011         YY_BREAK
6012  case 54:
6013  YY_RULE_SETUP
6014 -#line 203 "program_lexer.l"
6015 +#line 243 "program_lexer.l"
6016  { return_opcode(require_ARB_fp, BINSC_OP, POW, ZERO_ONE); }
6017         YY_BREAK
6018  case 55:
6019  YY_RULE_SETUP
6020 -#line 205 "program_lexer.l"
6021 +#line 245 "program_lexer.l"
6022  { return_opcode(             1, SCALAR_OP, RCP, OFF); }
6023         YY_BREAK
6024  case 56:
6025  YY_RULE_SETUP
6026 -#line 206 "program_lexer.l"
6027 +#line 246 "program_lexer.l"
6028  { return_opcode(require_ARB_fp, SCALAR_OP, RCP, ZERO_ONE); }
6029         YY_BREAK
6030  case 57:
6031  YY_RULE_SETUP
6032 -#line 207 "program_lexer.l"
6033 +#line 247 "program_lexer.l"
6034  { return_opcode(             1, SCALAR_OP, RSQ, OFF); }
6035         YY_BREAK
6036  case 58:
6037  YY_RULE_SETUP
6038 -#line 208 "program_lexer.l"
6039 +#line 248 "program_lexer.l"
6040  { return_opcode(require_ARB_fp, SCALAR_OP, RSQ, ZERO_ONE); }
6041         YY_BREAK
6042  case 59:
6043  YY_RULE_SETUP
6044 -#line 210 "program_lexer.l"
6045 +#line 250 "program_lexer.l"
6046  { return_opcode(require_ARB_fp, SCALAR_OP, SCS, OFF); }
6047         YY_BREAK
6048  case 60:
6049  YY_RULE_SETUP
6050 -#line 211 "program_lexer.l"
6051 +#line 251 "program_lexer.l"
6052  { return_opcode(require_ARB_fp, SCALAR_OP, SCS, ZERO_ONE); }
6053         YY_BREAK
6054  case 61:
6055  YY_RULE_SETUP
6056 -#line 212 "program_lexer.l"
6057 +#line 252 "program_lexer.l"
6058  { return_opcode(             1, BIN_OP, SGE, OFF); }
6059         YY_BREAK
6060  case 62:
6061  YY_RULE_SETUP
6062 -#line 213 "program_lexer.l"
6063 +#line 253 "program_lexer.l"
6064  { return_opcode(require_ARB_fp, BIN_OP, SGE, ZERO_ONE); }
6065         YY_BREAK
6066  case 63:
6067  YY_RULE_SETUP
6068 -#line 214 "program_lexer.l"
6069 +#line 254 "program_lexer.l"
6070  { return_opcode(require_ARB_fp, SCALAR_OP, SIN, OFF); }
6071         YY_BREAK
6072  case 64:
6073  YY_RULE_SETUP
6074 -#line 215 "program_lexer.l"
6075 +#line 255 "program_lexer.l"
6076  { return_opcode(require_ARB_fp, SCALAR_OP, SIN, ZERO_ONE); }
6077         YY_BREAK
6078  case 65:
6079  YY_RULE_SETUP
6080 -#line 216 "program_lexer.l"
6081 +#line 256 "program_lexer.l"
6082  { return_opcode(             1, BIN_OP, SLT, OFF); }
6083         YY_BREAK
6084  case 66:
6085  YY_RULE_SETUP
6086 -#line 217 "program_lexer.l"
6087 +#line 257 "program_lexer.l"
6088  { return_opcode(require_ARB_fp, BIN_OP, SLT, ZERO_ONE); }
6089         YY_BREAK
6090  case 67:
6091  YY_RULE_SETUP
6092 -#line 218 "program_lexer.l"
6093 +#line 258 "program_lexer.l"
6094  { return_opcode(             1, BIN_OP, SUB, OFF); }
6095         YY_BREAK
6096  case 68:
6097  YY_RULE_SETUP
6098 -#line 219 "program_lexer.l"
6099 +#line 259 "program_lexer.l"
6100  { return_opcode(require_ARB_fp, BIN_OP, SUB, ZERO_ONE); }
6101         YY_BREAK
6102  case 69:
6103  YY_RULE_SETUP
6104 -#line 220 "program_lexer.l"
6105 +#line 260 "program_lexer.l"
6106  { return_opcode(             1, SWZ, SWZ, OFF); }
6107         YY_BREAK
6108  case 70:
6109  YY_RULE_SETUP
6110 -#line 221 "program_lexer.l"
6111 +#line 261 "program_lexer.l"
6112  { return_opcode(require_ARB_fp, SWZ, SWZ, ZERO_ONE); }
6113         YY_BREAK
6114  case 71:
6115  YY_RULE_SETUP
6116 -#line 223 "program_lexer.l"
6117 +#line 263 "program_lexer.l"
6118  { return_opcode(require_ARB_fp, SAMPLE_OP, TEX, OFF); }
6119         YY_BREAK
6120  case 72:
6121  YY_RULE_SETUP
6122 -#line 224 "program_lexer.l"
6123 +#line 264 "program_lexer.l"
6124  { return_opcode(require_ARB_fp, SAMPLE_OP, TEX, ZERO_ONE); }
6125         YY_BREAK
6126  case 73:
6127  YY_RULE_SETUP
6128 -#line 225 "program_lexer.l"
6129 +#line 265 "program_lexer.l"
6130  { return_opcode(require_ARB_fp, SAMPLE_OP, TXB, OFF); }
6131         YY_BREAK
6132  case 74:
6133  YY_RULE_SETUP
6134 -#line 226 "program_lexer.l"
6135 +#line 266 "program_lexer.l"
6136  { return_opcode(require_ARB_fp, SAMPLE_OP, TXB, ZERO_ONE); }
6137         YY_BREAK
6138  case 75:
6139  YY_RULE_SETUP
6140 -#line 227 "program_lexer.l"
6141 +#line 267 "program_lexer.l"
6142  { return_opcode(require_ARB_fp, SAMPLE_OP, TXP, OFF); }
6143         YY_BREAK
6144  case 76:
6145  YY_RULE_SETUP
6146 -#line 228 "program_lexer.l"
6147 +#line 268 "program_lexer.l"
6148  { return_opcode(require_ARB_fp, SAMPLE_OP, TXP, ZERO_ONE); }
6149         YY_BREAK
6150  case 77:
6151  YY_RULE_SETUP
6152 -#line 230 "program_lexer.l"
6153 +#line 270 "program_lexer.l"
6154  { return_opcode(             1, BIN_OP, XPD, OFF); }
6155         YY_BREAK
6156  case 78:
6157  YY_RULE_SETUP
6158 -#line 231 "program_lexer.l"
6159 +#line 271 "program_lexer.l"
6160  { return_opcode(require_ARB_fp, BIN_OP, XPD, ZERO_ONE); }
6161         YY_BREAK
6162  case 79:
6163  YY_RULE_SETUP
6164 -#line 233 "program_lexer.l"
6165 +#line 273 "program_lexer.l"
6166  { return_token_or_IDENTIFIER(require_ARB_vp, VERTEX); }
6167         YY_BREAK
6168  case 80:
6169  YY_RULE_SETUP
6170 -#line 234 "program_lexer.l"
6171 +#line 274 "program_lexer.l"
6172  { return_token_or_IDENTIFIER(require_ARB_fp, FRAGMENT); }
6173         YY_BREAK
6174  case 81:
6175  YY_RULE_SETUP
6176 -#line 235 "program_lexer.l"
6177 +#line 275 "program_lexer.l"
6178  { return PROGRAM; }
6179         YY_BREAK
6180  case 82:
6181  YY_RULE_SETUP
6182 -#line 236 "program_lexer.l"
6183 +#line 276 "program_lexer.l"
6184  { return STATE; }
6185         YY_BREAK
6186  case 83:
6187  YY_RULE_SETUP
6188 -#line 237 "program_lexer.l"
6189 +#line 277 "program_lexer.l"
6190  { return RESULT; }
6191         YY_BREAK
6192  case 84:
6193  YY_RULE_SETUP
6194 -#line 239 "program_lexer.l"
6195 +#line 279 "program_lexer.l"
6196  { return AMBIENT; }
6197         YY_BREAK
6198  case 85:
6199  YY_RULE_SETUP
6200 -#line 240 "program_lexer.l"
6201 +#line 280 "program_lexer.l"
6202  { return ATTENUATION; }
6203         YY_BREAK
6204  case 86:
6205  YY_RULE_SETUP
6206 -#line 241 "program_lexer.l"
6207 +#line 281 "program_lexer.l"
6208  { return BACK; }
6209         YY_BREAK
6210  case 87:
6211  YY_RULE_SETUP
6212 -#line 242 "program_lexer.l"
6213 +#line 282 "program_lexer.l"
6214  { return_token_or_DOT(require_ARB_vp, CLIP); }
6215         YY_BREAK
6216  case 88:
6217  YY_RULE_SETUP
6218 -#line 243 "program_lexer.l"
6219 +#line 283 "program_lexer.l"
6220  { return COLOR; }
6221         YY_BREAK
6222  case 89:
6223  YY_RULE_SETUP
6224 -#line 244 "program_lexer.l"
6225 +#line 284 "program_lexer.l"
6226  { return_token_or_DOT(require_ARB_fp, DEPTH); }
6227         YY_BREAK
6228  case 90:
6229  YY_RULE_SETUP
6230 -#line 245 "program_lexer.l"
6231 +#line 285 "program_lexer.l"
6232  { return DIFFUSE; }
6233         YY_BREAK
6234  case 91:
6235  YY_RULE_SETUP
6236 -#line 246 "program_lexer.l"
6237 +#line 286 "program_lexer.l"
6238  { return DIRECTION; }
6239         YY_BREAK
6240  case 92:
6241  YY_RULE_SETUP
6242 -#line 247 "program_lexer.l"
6243 +#line 287 "program_lexer.l"
6244  { return EMISSION; }
6245         YY_BREAK
6246  case 93:
6247  YY_RULE_SETUP
6248 -#line 248 "program_lexer.l"
6249 +#line 288 "program_lexer.l"
6250  { return ENV; }
6251         YY_BREAK
6252  case 94:
6253  YY_RULE_SETUP
6254 -#line 249 "program_lexer.l"
6255 +#line 289 "program_lexer.l"
6256  { return EYE; }
6257         YY_BREAK
6258  case 95:
6259  YY_RULE_SETUP
6260 -#line 250 "program_lexer.l"
6261 +#line 290 "program_lexer.l"
6262  { return FOGCOORD; }
6263         YY_BREAK
6264  case 96:
6265  YY_RULE_SETUP
6266 -#line 251 "program_lexer.l"
6267 +#line 291 "program_lexer.l"
6268  { return FOG; }
6269         YY_BREAK
6270  case 97:
6271  YY_RULE_SETUP
6272 -#line 252 "program_lexer.l"
6273 +#line 292 "program_lexer.l"
6274  { return FRONT; }
6275         YY_BREAK
6276  case 98:
6277  YY_RULE_SETUP
6278 -#line 253 "program_lexer.l"
6279 +#line 293 "program_lexer.l"
6280  { return HALF; }
6281         YY_BREAK
6282  case 99:
6283  YY_RULE_SETUP
6284 -#line 254 "program_lexer.l"
6285 +#line 294 "program_lexer.l"
6286  { return INVERSE; }
6287         YY_BREAK
6288  case 100:
6289  YY_RULE_SETUP
6290 -#line 255 "program_lexer.l"
6291 +#line 295 "program_lexer.l"
6292  { return INVTRANS; }
6293         YY_BREAK
6294  case 101:
6295  YY_RULE_SETUP
6296 -#line 256 "program_lexer.l"
6297 +#line 296 "program_lexer.l"
6298  { return LIGHT; }
6299         YY_BREAK
6300  case 102:
6301  YY_RULE_SETUP
6302 -#line 257 "program_lexer.l"
6303 +#line 297 "program_lexer.l"
6304  { return LIGHTMODEL; }
6305         YY_BREAK
6306  case 103:
6307  YY_RULE_SETUP
6308 -#line 258 "program_lexer.l"
6309 +#line 298 "program_lexer.l"
6310  { return LIGHTPROD; }
6311         YY_BREAK
6312  case 104:
6313  YY_RULE_SETUP
6314 -#line 259 "program_lexer.l"
6315 +#line 299 "program_lexer.l"
6316  { return LOCAL; }
6317         YY_BREAK
6318  case 105:
6319  YY_RULE_SETUP
6320 -#line 260 "program_lexer.l"
6321 +#line 300 "program_lexer.l"
6322  { return MATERIAL; }
6323         YY_BREAK
6324  case 106:
6325  YY_RULE_SETUP
6326 -#line 261 "program_lexer.l"
6327 +#line 301 "program_lexer.l"
6328  { return MAT_PROGRAM; }
6329         YY_BREAK
6330  case 107:
6331  YY_RULE_SETUP
6332 -#line 262 "program_lexer.l"
6333 +#line 302 "program_lexer.l"
6334  { return MATRIX; }
6335         YY_BREAK
6336  case 108:
6337  YY_RULE_SETUP
6338 -#line 263 "program_lexer.l"
6339 +#line 303 "program_lexer.l"
6340  { return_token_or_DOT(require_ARB_vp, MATRIXINDEX); }
6341         YY_BREAK
6342  case 109:
6343  YY_RULE_SETUP
6344 -#line 264 "program_lexer.l"
6345 +#line 304 "program_lexer.l"
6346  { return MODELVIEW; }
6347         YY_BREAK
6348  case 110:
6349  YY_RULE_SETUP
6350 -#line 265 "program_lexer.l"
6351 +#line 305 "program_lexer.l"
6352  { return MVP; }
6353         YY_BREAK
6354  case 111:
6355  YY_RULE_SETUP
6356 -#line 266 "program_lexer.l"
6357 +#line 306 "program_lexer.l"
6358  { return_token_or_DOT(require_ARB_vp, NORMAL); }
6359         YY_BREAK
6360  case 112:
6361  YY_RULE_SETUP
6362 -#line 267 "program_lexer.l"
6363 +#line 307 "program_lexer.l"
6364  { return OBJECT; }
6365         YY_BREAK
6366  case 113:
6367  YY_RULE_SETUP
6368 -#line 268 "program_lexer.l"
6369 +#line 308 "program_lexer.l"
6370  { return PALETTE; }
6371         YY_BREAK
6372  case 114:
6373  YY_RULE_SETUP
6374 -#line 269 "program_lexer.l"
6375 +#line 309 "program_lexer.l"
6376  { return PARAMS; }
6377         YY_BREAK
6378  case 115:
6379  YY_RULE_SETUP
6380 -#line 270 "program_lexer.l"
6381 +#line 310 "program_lexer.l"
6382  { return PLANE; }
6383         YY_BREAK
6384  case 116:
6385  YY_RULE_SETUP
6386 -#line 271 "program_lexer.l"
6387 +#line 311 "program_lexer.l"
6388  { return_token_or_DOT(require_ARB_vp, POINT_TOK); }
6389         YY_BREAK
6390  case 117:
6391  YY_RULE_SETUP
6392 -#line 272 "program_lexer.l"
6393 +#line 312 "program_lexer.l"
6394  { return_token_or_DOT(require_ARB_vp, POINTSIZE); }
6395         YY_BREAK
6396  case 118:
6397  YY_RULE_SETUP
6398 -#line 273 "program_lexer.l"
6399 +#line 313 "program_lexer.l"
6400  { return POSITION; }
6401         YY_BREAK
6402  case 119:
6403  YY_RULE_SETUP
6404 -#line 274 "program_lexer.l"
6405 +#line 314 "program_lexer.l"
6406  { return PRIMARY; }
6407         YY_BREAK
6408  case 120:
6409  YY_RULE_SETUP
6410 -#line 275 "program_lexer.l"
6411 +#line 315 "program_lexer.l"
6412  { return PROJECTION; }
6413         YY_BREAK
6414  case 121:
6415  YY_RULE_SETUP
6416 -#line 276 "program_lexer.l"
6417 +#line 316 "program_lexer.l"
6418  { return_token_or_DOT(require_ARB_fp, RANGE); }
6419         YY_BREAK
6420  case 122:
6421  YY_RULE_SETUP
6422 -#line 277 "program_lexer.l"
6423 +#line 317 "program_lexer.l"
6424  { return ROW; }
6425         YY_BREAK
6426  case 123:
6427  YY_RULE_SETUP
6428 -#line 278 "program_lexer.l"
6429 +#line 318 "program_lexer.l"
6430  { return SCENECOLOR; }
6431         YY_BREAK
6432  case 124:
6433  YY_RULE_SETUP
6434 -#line 279 "program_lexer.l"
6435 +#line 319 "program_lexer.l"
6436  { return SECONDARY; }
6437         YY_BREAK
6438  case 125:
6439  YY_RULE_SETUP
6440 -#line 280 "program_lexer.l"
6441 +#line 320 "program_lexer.l"
6442  { return SHININESS; }
6443         YY_BREAK
6444  case 126:
6445  YY_RULE_SETUP
6446 -#line 281 "program_lexer.l"
6447 +#line 321 "program_lexer.l"
6448  { return_token_or_DOT(require_ARB_vp, SIZE_TOK); }
6449         YY_BREAK
6450  case 127:
6451  YY_RULE_SETUP
6452 -#line 282 "program_lexer.l"
6453 +#line 322 "program_lexer.l"
6454  { return SPECULAR; }
6455         YY_BREAK
6456  case 128:
6457  YY_RULE_SETUP
6458 -#line 283 "program_lexer.l"
6459 +#line 323 "program_lexer.l"
6460  { return SPOT; }
6461         YY_BREAK
6462  case 129:
6463  YY_RULE_SETUP
6464 -#line 284 "program_lexer.l"
6465 +#line 324 "program_lexer.l"
6466  { return TEXCOORD; }
6467         YY_BREAK
6468  case 130:
6469  YY_RULE_SETUP
6470 -#line 285 "program_lexer.l"
6471 +#line 325 "program_lexer.l"
6472  { return_token_or_DOT(require_ARB_fp, TEXENV); }
6473         YY_BREAK
6474  case 131:
6475  YY_RULE_SETUP
6476 -#line 286 "program_lexer.l"
6477 +#line 326 "program_lexer.l"
6478  { return_token_or_DOT(require_ARB_vp, TEXGEN); }
6479         YY_BREAK
6480  case 132:
6481  YY_RULE_SETUP
6482 -#line 287 "program_lexer.l"
6483 +#line 327 "program_lexer.l"
6484  { return_token_or_DOT(require_ARB_vp, TEXGEN_Q); }
6485         YY_BREAK
6486  case 133:
6487  YY_RULE_SETUP
6488 -#line 288 "program_lexer.l"
6489 +#line 328 "program_lexer.l"
6490  { return_token_or_DOT(require_ARB_vp, TEXGEN_S); }
6491         YY_BREAK
6492  case 134:
6493  YY_RULE_SETUP
6494 -#line 289 "program_lexer.l"
6495 +#line 329 "program_lexer.l"
6496  { return_token_or_DOT(require_ARB_vp, TEXGEN_T); }
6497         YY_BREAK
6498  case 135:
6499  YY_RULE_SETUP
6500 -#line 290 "program_lexer.l"
6501 +#line 330 "program_lexer.l"
6502  { return TEXTURE; }
6503         YY_BREAK
6504  case 136:
6505  YY_RULE_SETUP
6506 -#line 291 "program_lexer.l"
6507 +#line 331 "program_lexer.l"
6508  { return TRANSPOSE; }
6509         YY_BREAK
6510  case 137:
6511  YY_RULE_SETUP
6512 -#line 292 "program_lexer.l"
6513 +#line 332 "program_lexer.l"
6514  { return_token_or_DOT(require_ARB_vp, VTXATTRIB); }
6515         YY_BREAK
6516  case 138:
6517  YY_RULE_SETUP
6518 -#line 293 "program_lexer.l"
6519 +#line 333 "program_lexer.l"
6520  { return_token_or_DOT(require_ARB_vp, WEIGHT); }
6521         YY_BREAK
6522  case 139:
6523  YY_RULE_SETUP
6524 -#line 295 "program_lexer.l"
6525 +#line 335 "program_lexer.l"
6526  { return_token_or_IDENTIFIER(require_ARB_fp, TEXTURE_UNIT); }
6527         YY_BREAK
6528  case 140:
6529  YY_RULE_SETUP
6530 -#line 296 "program_lexer.l"
6531 +#line 336 "program_lexer.l"
6532  { return_token_or_IDENTIFIER(require_ARB_fp, TEX_1D); }
6533         YY_BREAK
6534  case 141:
6535  YY_RULE_SETUP
6536 -#line 297 "program_lexer.l"
6537 +#line 337 "program_lexer.l"
6538  { return_token_or_IDENTIFIER(require_ARB_fp, TEX_2D); }
6539         YY_BREAK
6540  case 142:
6541  YY_RULE_SETUP
6542 -#line 298 "program_lexer.l"
6543 +#line 338 "program_lexer.l"
6544  { return_token_or_IDENTIFIER(require_ARB_fp, TEX_3D); }
6545         YY_BREAK
6546  case 143:
6547  YY_RULE_SETUP
6548 -#line 299 "program_lexer.l"
6549 +#line 339 "program_lexer.l"
6550  { return_token_or_IDENTIFIER(require_ARB_fp, TEX_CUBE); }
6551         YY_BREAK
6552  case 144:
6553  YY_RULE_SETUP
6554 -#line 300 "program_lexer.l"
6555 +#line 340 "program_lexer.l"
6556  { return_token_or_IDENTIFIER(require_ARB_fp && require_rect, TEX_RECT); }
6557         YY_BREAK
6558  case 145:
6559  YY_RULE_SETUP
6560 -#line 301 "program_lexer.l"
6561 +#line 341 "program_lexer.l"
6562  { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow, TEX_SHADOW1D); }
6563         YY_BREAK
6564  case 146:
6565  YY_RULE_SETUP
6566 -#line 302 "program_lexer.l"
6567 +#line 342 "program_lexer.l"
6568  { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow, TEX_SHADOW2D); }
6569         YY_BREAK
6570  case 147:
6571  YY_RULE_SETUP
6572 -#line 303 "program_lexer.l"
6573 +#line 343 "program_lexer.l"
6574  { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_rect, TEX_SHADOWRECT); }
6575         YY_BREAK
6576  case 148:
6577  YY_RULE_SETUP
6578 -#line 304 "program_lexer.l"
6579 +#line 344 "program_lexer.l"
6580  { return_token_or_IDENTIFIER(require_ARB_fp && require_texarray, TEX_ARRAY1D); }
6581         YY_BREAK
6582  case 149:
6583  YY_RULE_SETUP
6584 -#line 305 "program_lexer.l"
6585 +#line 345 "program_lexer.l"
6586  { return_token_or_IDENTIFIER(require_ARB_fp && require_texarray, TEX_ARRAY2D); }
6587         YY_BREAK
6588  case 150:
6589  YY_RULE_SETUP
6590 -#line 306 "program_lexer.l"
6591 +#line 346 "program_lexer.l"
6592  { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_texarray, TEX_ARRAYSHADOW1D); }
6593         YY_BREAK
6594  case 151:
6595  YY_RULE_SETUP
6596 -#line 307 "program_lexer.l"
6597 +#line 347 "program_lexer.l"
6598  { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_texarray, TEX_ARRAYSHADOW2D); }
6599         YY_BREAK
6600  case 152:
6601  YY_RULE_SETUP
6602 -#line 309 "program_lexer.l"
6603 +#line 349 "program_lexer.l"
6604  {
6605 -   yylval->string = strdup(yytext);
6606 +   yylval->string = return_string(yyextra, yytext);
6607     return IDENTIFIER;
6608  }
6609         YY_BREAK
6610  case 153:
6611  YY_RULE_SETUP
6612 -#line 314 "program_lexer.l"
6613 +#line 354 "program_lexer.l"
6614  { return DOT_DOT; }
6615         YY_BREAK
6616  case 154:
6617  YY_RULE_SETUP
6618 -#line 316 "program_lexer.l"
6619 +#line 356 "program_lexer.l"
6620  {
6621     yylval->integer = strtol(yytext, NULL, 10);
6622     return INTEGER;
6623 @@ -2115,9 +2169,9 @@ YY_RULE_SETUP
6624         YY_BREAK
6625  case 155:
6626  YY_RULE_SETUP
6627 -#line 320 "program_lexer.l"
6628 +#line 360 "program_lexer.l"
6629  {
6630 -   yylval->real = strtod(yytext, NULL);
6631 +   yylval->real = _mesa_strtod(yytext, NULL);
6632     return REAL;
6633  }
6634         YY_BREAK
6635 @@ -2127,31 +2181,31 @@ case 156:
6636  yyg->yy_c_buf_p = yy_cp -= 1;
6637  YY_DO_BEFORE_ACTION; /* set up yytext again */
6638  YY_RULE_SETUP
6639 -#line 324 "program_lexer.l"
6640 +#line 364 "program_lexer.l"
6641  {
6642 -   yylval->real = strtod(yytext, NULL);
6643 +   yylval->real = _mesa_strtod(yytext, NULL);
6644     return REAL;
6645  }
6646         YY_BREAK
6647  case 157:
6648  YY_RULE_SETUP
6649 -#line 328 "program_lexer.l"
6650 +#line 368 "program_lexer.l"
6651  {
6652 -   yylval->real = strtod(yytext, NULL);
6653 +   yylval->real = _mesa_strtod(yytext, NULL);
6654     return REAL;
6655  }
6656         YY_BREAK
6657  case 158:
6658  YY_RULE_SETUP
6659 -#line 332 "program_lexer.l"
6660 +#line 372 "program_lexer.l"
6661  {
6662 -   yylval->real = strtod(yytext, NULL);
6663 +   yylval->real = _mesa_strtod(yytext, NULL);
6664     return REAL;
6665  }
6666         YY_BREAK
6667  case 159:
6668  YY_RULE_SETUP
6669 -#line 337 "program_lexer.l"
6670 +#line 377 "program_lexer.l"
6671  {
6672     yylval->swiz_mask.swizzle = SWIZZLE_NOOP;
6673     yylval->swiz_mask.mask = WRITEMASK_XYZW;
6674 @@ -2160,7 +2214,7 @@ YY_RULE_SETUP
6675         YY_BREAK
6676  case 160:
6677  YY_RULE_SETUP
6678 -#line 343 "program_lexer.l"
6679 +#line 383 "program_lexer.l"
6680  {
6681     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6682     yylval->swiz_mask.mask = WRITEMASK_XY
6683 @@ -2170,7 +2224,7 @@ YY_RULE_SETUP
6684         YY_BREAK
6685  case 161:
6686  YY_RULE_SETUP
6687 -#line 349 "program_lexer.l"
6688 +#line 389 "program_lexer.l"
6689  {
6690     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6691     yylval->swiz_mask.mask = WRITEMASK_XZW;
6692 @@ -2179,7 +2233,7 @@ YY_RULE_SETUP
6693         YY_BREAK
6694  case 162:
6695  YY_RULE_SETUP
6696 -#line 354 "program_lexer.l"
6697 +#line 394 "program_lexer.l"
6698  {
6699     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6700     yylval->swiz_mask.mask = WRITEMASK_YZW;
6701 @@ -2188,7 +2242,7 @@ YY_RULE_SETUP
6702         YY_BREAK
6703  case 163:
6704  YY_RULE_SETUP
6705 -#line 360 "program_lexer.l"
6706 +#line 400 "program_lexer.l"
6707  {
6708     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6709     yylval->swiz_mask.mask = WRITEMASK_X
6710 @@ -2198,7 +2252,7 @@ YY_RULE_SETUP
6711         YY_BREAK
6712  case 164:
6713  YY_RULE_SETUP
6714 -#line 366 "program_lexer.l"
6715 +#line 406 "program_lexer.l"
6716  {
6717     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6718     yylval->swiz_mask.mask = WRITEMASK_Y
6719 @@ -2208,7 +2262,7 @@ YY_RULE_SETUP
6720         YY_BREAK
6721  case 165:
6722  YY_RULE_SETUP
6723 -#line 372 "program_lexer.l"
6724 +#line 412 "program_lexer.l"
6725  {
6726     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6727     yylval->swiz_mask.mask = WRITEMASK_ZW;
6728 @@ -2217,7 +2271,7 @@ YY_RULE_SETUP
6729         YY_BREAK
6730  case 166:
6731  YY_RULE_SETUP
6732 -#line 378 "program_lexer.l"
6733 +#line 418 "program_lexer.l"
6734  {
6735     const unsigned s = swiz_from_char(yytext[1]);
6736     yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(s, s, s, s);
6737 @@ -2227,7 +2281,7 @@ YY_RULE_SETUP
6738         YY_BREAK
6739  case 167:
6740  YY_RULE_SETUP
6741 -#line 385 "program_lexer.l"
6742 +#line 425 "program_lexer.l"
6743  {
6744     yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(swiz_from_char(yytext[1]),
6745                                             swiz_from_char(yytext[2]),
6746 @@ -2239,7 +2293,7 @@ YY_RULE_SETUP
6747         YY_BREAK
6748  case 168:
6749  YY_RULE_SETUP
6750 -#line 394 "program_lexer.l"
6751 +#line 434 "program_lexer.l"
6752  {
6753     yylval->swiz_mask.swizzle = SWIZZLE_NOOP;
6754     yylval->swiz_mask.mask = WRITEMASK_XYZW;
6755 @@ -2248,7 +2302,7 @@ YY_RULE_SETUP
6756         YY_BREAK
6757  case 169:
6758  YY_RULE_SETUP
6759 -#line 400 "program_lexer.l"
6760 +#line 440 "program_lexer.l"
6761  {
6762     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6763     yylval->swiz_mask.mask = WRITEMASK_XY
6764 @@ -2258,7 +2312,7 @@ YY_RULE_SETUP
6765         YY_BREAK
6766  case 170:
6767  YY_RULE_SETUP
6768 -#line 406 "program_lexer.l"
6769 +#line 446 "program_lexer.l"
6770  {
6771     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6772     yylval->swiz_mask.mask = WRITEMASK_XZW;
6773 @@ -2267,7 +2321,7 @@ YY_RULE_SETUP
6774         YY_BREAK
6775  case 171:
6776  YY_RULE_SETUP
6777 -#line 411 "program_lexer.l"
6778 +#line 451 "program_lexer.l"
6779  {
6780     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6781     yylval->swiz_mask.mask = WRITEMASK_YZW;
6782 @@ -2276,7 +2330,7 @@ YY_RULE_SETUP
6783         YY_BREAK
6784  case 172:
6785  YY_RULE_SETUP
6786 -#line 417 "program_lexer.l"
6787 +#line 457 "program_lexer.l"
6788  {
6789     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6790     yylval->swiz_mask.mask = WRITEMASK_X
6791 @@ -2286,7 +2340,7 @@ YY_RULE_SETUP
6792         YY_BREAK
6793  case 173:
6794  YY_RULE_SETUP
6795 -#line 423 "program_lexer.l"
6796 +#line 463 "program_lexer.l"
6797  {
6798     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6799     yylval->swiz_mask.mask = WRITEMASK_Y
6800 @@ -2296,7 +2350,7 @@ YY_RULE_SETUP
6801         YY_BREAK
6802  case 174:
6803  YY_RULE_SETUP
6804 -#line 429 "program_lexer.l"
6805 +#line 469 "program_lexer.l"
6806  {
6807     yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
6808     yylval->swiz_mask.mask = WRITEMASK_ZW;
6809 @@ -2305,7 +2359,7 @@ YY_RULE_SETUP
6810         YY_BREAK
6811  case 175:
6812  YY_RULE_SETUP
6813 -#line 435 "program_lexer.l"
6814 +#line 475 "program_lexer.l"
6815  {
6816     const unsigned s = swiz_from_char(yytext[1]);
6817     yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(s, s, s, s);
6818 @@ -2315,7 +2369,7 @@ YY_RULE_SETUP
6819         YY_BREAK
6820  case 176:
6821  YY_RULE_SETUP
6822 -#line 443 "program_lexer.l"
6823 +#line 483 "program_lexer.l"
6824  {
6825     if (require_ARB_vp) {
6826        return TEXGEN_R;
6827 @@ -2329,7 +2383,7 @@ YY_RULE_SETUP
6828         YY_BREAK
6829  case 177:
6830  YY_RULE_SETUP
6831 -#line 454 "program_lexer.l"
6832 +#line 494 "program_lexer.l"
6833  {
6834     yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(swiz_from_char(yytext[1]),
6835                                             swiz_from_char(yytext[2]),
6836 @@ -2341,13 +2395,13 @@ YY_RULE_SETUP
6837         YY_BREAK
6838  case 178:
6839  YY_RULE_SETUP
6840 -#line 463 "program_lexer.l"
6841 +#line 503 "program_lexer.l"
6842  { return DOT; }
6843         YY_BREAK
6844  case 179:
6845  /* rule 179 can match eol */
6846  YY_RULE_SETUP
6847 -#line 465 "program_lexer.l"
6848 +#line 505 "program_lexer.l"
6849  {
6850     yylloc->first_line++;
6851     yylloc->first_column = 1;
6852 @@ -2358,7 +2412,7 @@ YY_RULE_SETUP
6853         YY_BREAK
6854  case 180:
6855  YY_RULE_SETUP
6856 -#line 472 "program_lexer.l"
6857 +#line 512 "program_lexer.l"
6858  /* eat whitespace */ ;
6859         YY_BREAK
6860  case 181:
6861 @@ -2366,20 +2420,20 @@ case 181:
6862  yyg->yy_c_buf_p = yy_cp -= 1;
6863  YY_DO_BEFORE_ACTION; /* set up yytext again */
6864  YY_RULE_SETUP
6865 -#line 473 "program_lexer.l"
6866 +#line 513 "program_lexer.l"
6867  /* eat comments */ ;
6868         YY_BREAK
6869  case 182:
6870  YY_RULE_SETUP
6871 -#line 474 "program_lexer.l"
6872 +#line 514 "program_lexer.l"
6873  { return yytext[0]; }
6874         YY_BREAK
6875  case 183:
6876  YY_RULE_SETUP
6877 -#line 475 "program_lexer.l"
6878 +#line 515 "program_lexer.l"
6879  ECHO;
6880         YY_BREAK
6881 -#line 2383 "lex.yy.c"
6882 +#line 2437 "lex.yy.c"
6883  case YY_STATE_EOF(INITIAL):
6884         yyterminate();
6885  
6886 @@ -3147,8 +3201,8 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
6887  
6888  /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
6889   * scan from a @e copy of @a bytes.
6890 - * @param bytes the byte buffer to scan
6891 - * @param len the number of bytes in the buffer pointed to by @a bytes.
6892 + * @param yybytes the byte buffer to scan
6893 + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
6894   * @param yyscanner The scanner object.
6895   * @return the newly allocated buffer state object.
6896   */
6897 @@ -3554,7 +3608,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
6898  
6899  #define YYTABLES_NAME "yytables"
6900  
6901 -#line 475 "program_lexer.l"
6902 +#line 515 "program_lexer.l"
6903  
6904  
6905  
6906 diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
6907 index 69b81e7..192d39a 100644
6908 --- a/src/mesa/shader/prog_execute.c
6909 +++ b/src/mesa/shader/prog_execute.c
6910 @@ -939,7 +939,7 @@ _mesa_execute_program(GLcontext * ctx,
6911             /* The fast LOG2 macro doesn't meet the precision requirements.
6912              */
6913              if (a[0] == 0.0F) {
6914 -               val = 0.0F;
6915 +               val = -FLT_MAX;
6916              }
6917              else {
6918                 val = log(a[0]) * 1.442695F;
6919 diff --git a/src/mesa/shader/prog_optimize.c b/src/mesa/shader/prog_optimize.c
6920 index be90310..9d93748 100644
6921 --- a/src/mesa/shader/prog_optimize.c
6922 +++ b/src/mesa/shader/prog_optimize.c
6923 @@ -217,6 +217,7 @@ _mesa_remove_dead_code(struct gl_program *prog)
6924              if (inst->SrcReg[j].RelAddr) {
6925                 if (dbg)
6926                    _mesa_printf("abort remove dead code (indirect temp)\n");
6927 +               _mesa_free(removeInst);
6928                 return;
6929              }
6930  
6931 @@ -232,6 +233,7 @@ _mesa_remove_dead_code(struct gl_program *prog)
6932           if (inst->DstReg.RelAddr) {
6933              if (dbg)
6934                 _mesa_printf("abort remove dead code (indirect temp)\n");
6935 +            _mesa_free(removeInst);
6936              return;
6937           }
6938  
6939 @@ -422,6 +424,8 @@ _mesa_remove_extra_moves(struct gl_program *prog)
6940     /* now remove the instructions which aren't needed */
6941     rem = remove_instructions(prog, removeInst);
6942  
6943 +   _mesa_free(removeInst);
6944 +
6945     if (dbg) {
6946        _mesa_printf("Optimize: End remove extra moves.  %u instructions removed\n", rem);
6947        /*_mesa_print_program(prog);*/
6948 diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h
6949 index d1fcf47..699cb0c 100644
6950 --- a/src/mesa/shader/prog_parameter.h
6951 +++ b/src/mesa/shader/prog_parameter.h
6952 @@ -56,7 +56,13 @@ struct gl_program_parameter
6953     const char *Name;        /**< Null-terminated string */
6954     gl_register_file Type;   /**< PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */
6955     GLenum DataType;         /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
6956 -   GLuint Size;             /**< Number of components (1..4) */
6957 +   /**
6958 +    * Number of components (1..4), or more.
6959 +    * If the number of components is greater than 4,
6960 +    * this parameter is part of a larger uniform like a GLSL matrix or array.
6961 +    * The next program parameter's Size will be Size-4 of this parameter.
6962 +    */
6963 +   GLuint Size;
6964     GLboolean Used;          /**< Helper flag for GLSL uniform tracking */
6965     GLboolean Initialized;   /**< Has the ParameterValue[] been set? */
6966     GLbitfield Flags;        /**< Bitmask of PROG_PARAM_*_BIT */
6967 diff --git a/src/mesa/shader/program_lexer.l b/src/mesa/shader/program_lexer.l
6968 index d240217..6c4fad3 100644
6969 --- a/src/mesa/shader/program_lexer.l
6970 +++ b/src/mesa/shader/program_lexer.l
6971 @@ -22,6 +22,7 @@
6972   * DEALINGS IN THE SOFTWARE.
6973   */
6974  #include "main/glheader.h"
6975 +#include "main/imports.h"
6976  #include "prog_instruction.h"
6977  #include "prog_statevars.h"
6978  
6979 @@ -39,7 +40,7 @@
6980        if (condition) {                                 \
6981          return token;                                  \
6982        } else {                                         \
6983 -        yylval->string = strdup(yytext);               \
6984 +        yylval->string = return_string(yyextra, yytext);       \
6985          return IDENTIFIER;                             \
6986        }                                                        \
6987     } while (0)
6988 @@ -62,7 +63,7 @@
6989          yylval->temp_inst.SaturateMode = SATURATE_ ## sat; \
6990          return token;                                  \
6991        } else {                                         \
6992 -        yylval->string = strdup(yytext);               \
6993 +        yylval->string = return_string(yyextra, yytext);               \
6994          return IDENTIFIER;                             \
6995        }                                                        \
6996     } while (0)
6997 @@ -70,6 +71,45 @@
6998  #define SWIZZLE_INVAL  MAKE_SWIZZLE4(SWIZZLE_NIL, SWIZZLE_NIL, \
6999                                      SWIZZLE_NIL, SWIZZLE_NIL)
7000  
7001 +/**
7002 + * Send a string to the parser using asm_parser_state::string_dumpster
7003 + *
7004 + * Sends a string to the parser using asm_parser_state::string_dumpster as a
7005 + * temporary storage buffer.  Data previously stored in
7006 + * asm_parser_state::string_dumpster will be lost.  If
7007 + * asm_parser_state::string_dumpster is not large enough to hold the new
7008 + * string, the buffer size will be increased.  The buffer size is \b never
7009 + * decreased.
7010 + *
7011 + * \param state   Assembler parser state tracking
7012 + * \param str     String to be passed to the parser
7013 + *
7014 + * \return
7015 + * A pointer to asm_parser_state::string_dumpster on success or \c NULL on
7016 + * failure.  Currently the only failure case is \c ENOMEM.
7017 + */
7018 +static char *
7019 +return_string(struct asm_parser_state *state, const char *str)
7020 +{
7021 +   const size_t len = strlen(str);
7022 +
7023 +   if (len >= state->dumpster_size) {
7024 +      char *const dumpster = _mesa_realloc(state->string_dumpster,
7025 +                                          state->dumpster_size,
7026 +                                          len + 1);
7027 +      if (dumpster == NULL) {
7028 +        return NULL;
7029 +      }
7030 +
7031 +      state->string_dumpster = dumpster;
7032 +      state->dumpster_size = len + 1;
7033 +   }
7034 +
7035 +   memcpy(state->string_dumpster, str, len + 1);
7036 +   return state->string_dumpster;
7037 +}
7038 +
7039 +
7040  static unsigned
7041  mask_from_char(char c)
7042  {
7043 @@ -307,7 +347,7 @@ ARRAYSHADOW1D             { return_token_or_IDENTIFIER(require_ARB_fp && require
7044  ARRAYSHADOW2D             { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_texarray, TEX_ARRAYSHADOW2D); }
7045  
7046  [_a-zA-Z$][_a-zA-Z0-9$]*  {
7047 -   yylval->string = strdup(yytext);
7048 +   yylval->string = return_string(yyextra, yytext);
7049     return IDENTIFIER;
7050  }
7051  
7052 @@ -318,19 +358,19 @@ ARRAYSHADOW2D             { return_token_or_IDENTIFIER(require_ARB_fp && require
7053     return INTEGER;
7054  }
7055  {num}?{frac}{exp}?        {
7056 -   yylval->real = strtod(yytext, NULL);
7057 +   yylval->real = _mesa_strtod(yytext, NULL);
7058     return REAL;
7059  }
7060  {num}"."/[^.]             {
7061 -   yylval->real = strtod(yytext, NULL);
7062 +   yylval->real = _mesa_strtod(yytext, NULL);
7063     return REAL;
7064  }
7065  {num}{exp}                {
7066 -   yylval->real = strtod(yytext, NULL);
7067 +   yylval->real = _mesa_strtod(yytext, NULL);
7068     return REAL;
7069  }
7070  {num}"."{exp}             {
7071 -   yylval->real = strtod(yytext, NULL);
7072 +   yylval->real = _mesa_strtod(yytext, NULL);
7073     return REAL;
7074  }
7075  
7076 diff --git a/src/mesa/shader/program_parse.tab.c b/src/mesa/shader/program_parse.tab.c
7077 index 9f2d4de..261b605 100644
7078 --- a/src/mesa/shader/program_parse.tab.c
7079 +++ b/src/mesa/shader/program_parse.tab.c
7080 @@ -3109,7 +3109,7 @@ yyreduce:
7081  /* Line 1455 of yacc.c  */
7082  #line 1041 "program_parse.y"
7083      {
7084 -          if (((yyvsp[(1) - (1)].integer) < 1) || ((unsigned) (yyvsp[(1) - (1)].integer) >= state->limits->MaxParameters)) {
7085 +          if (((yyvsp[(1) - (1)].integer) < 1) || ((unsigned) (yyvsp[(1) - (1)].integer) > state->limits->MaxParameters)) {
7086               yyerror(& (yylsp[(1) - (1)]), state, "invalid parameter array size");
7087               YYERROR;
7088            } else {
7089 @@ -4565,7 +4565,7 @@ yyreduce:
7090                       "undefined variable binding in ALIAS statement");
7091               YYERROR;
7092            } else {
7093 -             _mesa_symbol_table_add_symbol(state->st, 0, (yyvsp[(2) - (4)].string), target);
7094 +             _mesa_symbol_table_add_symbol(state->st, 0, strdup((yyvsp[(2) - (4)].string)), target);
7095            }
7096         ;}
7097      break;
7098 @@ -4896,10 +4896,14 @@ declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
7099     if (exist != NULL) {
7100        yyerror(locp, state, "redeclared identifier");
7101     } else {
7102 -      s = calloc(1, sizeof(struct asm_symbol));
7103 -      s->name = name;
7104 +      const size_t name_len = strlen(name);
7105 +
7106 +      s = calloc(1, sizeof(struct asm_symbol) + name_len + 1);
7107 +      s->name = (char *)(s + 1);
7108        s->type = t;
7109  
7110 +      memcpy((char *) s->name, name, name_len + 1);
7111 +
7112        switch (t) {
7113        case at_temp:
7114          if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
7115 @@ -5147,6 +5151,11 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
7116     _mesa_memcpy (strz, str, len);
7117     strz[len] = '\0';
7118  
7119 +   if (state->prog->String != NULL) {
7120 +      _mesa_free(state->prog->String);
7121 +      state->prog->String = NULL;
7122 +   }
7123 +
7124     state->prog->String = strz;
7125  
7126     state->st = _mesa_symbol_table_ctor();
7127 @@ -5236,7 +5245,6 @@ error:
7128     for (sym = state->sym; sym != NULL; sym = temp) {
7129        temp = sym->next;
7130  
7131 -      _mesa_free((void *) sym->name);
7132        _mesa_free(sym);
7133     }
7134     state->sym = NULL;
7135 @@ -5244,6 +5252,11 @@ error:
7136     _mesa_symbol_table_dtor(state->st);
7137     state->st = NULL;
7138  
7139 +   if (state->string_dumpster != NULL) {
7140 +      _mesa_free(state->string_dumpster);
7141 +      state->dumpster_size = 0;
7142 +   }
7143 +
7144     return result;
7145  }
7146  
7147 diff --git a/src/mesa/shader/program_parse.y b/src/mesa/shader/program_parse.y
7148 index 06c1915..a23625d 100644
7149 --- a/src/mesa/shader/program_parse.y
7150 +++ b/src/mesa/shader/program_parse.y
7151 @@ -1039,7 +1039,7 @@ optArraySize:
7152         }
7153         | INTEGER
7154          {
7155 -          if (($1 < 1) || ((unsigned) $1 >= state->limits->MaxParameters)) {
7156 +          if (($1 < 1) || ((unsigned) $1 > state->limits->MaxParameters)) {
7157               yyerror(& @1, state, "invalid parameter array size");
7158               YYERROR;
7159            } else {
7160 @@ -1919,7 +1919,7 @@ ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
7161                       "undefined variable binding in ALIAS statement");
7162               YYERROR;
7163            } else {
7164 -             _mesa_symbol_table_add_symbol(state->st, 0, $2, target);
7165 +             _mesa_symbol_table_add_symbol(state->st, 0, strdup($2), target);
7166            }
7167         }
7168         ;
7169 @@ -2027,10 +2027,14 @@ declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
7170     if (exist != NULL) {
7171        yyerror(locp, state, "redeclared identifier");
7172     } else {
7173 -      s = calloc(1, sizeof(struct asm_symbol));
7174 -      s->name = name;
7175 +      const size_t name_len = strlen(name);
7176 +
7177 +      s = calloc(1, sizeof(struct asm_symbol) + name_len + 1);
7178 +      s->name = (char *)(s + 1);
7179        s->type = t;
7180  
7181 +      memcpy((char *) s->name, name, name_len + 1);
7182 +
7183        switch (t) {
7184        case at_temp:
7185          if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
7186 @@ -2278,6 +2282,11 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
7187     _mesa_memcpy (strz, str, len);
7188     strz[len] = '\0';
7189  
7190 +   if (state->prog->String != NULL) {
7191 +      _mesa_free(state->prog->String);
7192 +      state->prog->String = NULL;
7193 +   }
7194 +
7195     state->prog->String = strz;
7196  
7197     state->st = _mesa_symbol_table_ctor();
7198 @@ -2367,7 +2376,6 @@ error:
7199     for (sym = state->sym; sym != NULL; sym = temp) {
7200        temp = sym->next;
7201  
7202 -      _mesa_free((void *) sym->name);
7203        _mesa_free(sym);
7204     }
7205     state->sym = NULL;
7206 @@ -2375,5 +2383,10 @@ error:
7207     _mesa_symbol_table_dtor(state->st);
7208     state->st = NULL;
7209  
7210 +   if (state->string_dumpster != NULL) {
7211 +      _mesa_free(state->string_dumpster);
7212 +      state->dumpster_size = 0;
7213 +   }
7214 +
7215     return result;
7216  }
7217 diff --git a/src/mesa/shader/program_parser.h b/src/mesa/shader/program_parser.h
7218 index fa47d84..8d8b4d8 100644
7219 --- a/src/mesa/shader/program_parser.h
7220 +++ b/src/mesa/shader/program_parser.h
7221 @@ -38,6 +38,13 @@ enum asm_type {
7222     at_output,
7223  };
7224  
7225 +/**
7226 + * \note
7227 + * Objects of this type are allocated as the object plus the name of the
7228 + * symbol.  That is, malloc(sizeof(struct asm_symbol) + strlen(name) + 1).
7229 + * Alternately, asm_symbol::name could be moved to the bottom of the structure
7230 + * and declared as 'char name[0];'.
7231 + */
7232  struct asm_symbol {
7233     struct asm_symbol *next;    /**< List linkage for freeing. */
7234     const char *name;
7235 @@ -158,6 +165,15 @@ struct asm_parser_state {
7236  
7237  
7238     /**
7239 +    * Buffer to hold strings transfered from the lexer to the parser
7240 +    */
7241 +   /*@{*/
7242 +   char *string_dumpster;      /**< String data transfered. */
7243 +   size_t dumpster_size;       /**< Total size, in bytes, of the buffer. */
7244 +   /*@}*/
7245 +
7246 +
7247 +   /**
7248      * Selected limits copied from gl_constants
7249      *
7250      * These are limits from the GL context, but various bits in the program
7251 diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
7252 index 178b7d0..b282d7a 100644
7253 --- a/src/mesa/shader/shader_api.c
7254 +++ b/src/mesa/shader/shader_api.c
7255 @@ -1702,8 +1702,8 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program,
7256           /* we'll ignore extra data below */
7257        }
7258        else {
7259 -         /* non-array: count must be one */
7260 -         if (count != 1) {
7261 +         /* non-array: count must be at most one; count == 0 is handled by the loop below */
7262 +         if (count > 1) {
7263              _mesa_error(ctx, GL_INVALID_OPERATION,
7264                          "glUniform(uniform is not an array)");
7265              return;
7266 @@ -1880,20 +1880,27 @@ set_program_uniform_matrix(GLcontext *ctx, struct gl_program *program,
7267                             GLboolean transpose, const GLfloat *values)
7268  {
7269     GLuint mat, row, col;
7270 -   GLuint dst = index + offset, src = 0;
7271 +   GLuint src = 0;
7272 +   const struct gl_program_parameter * param = &program->Parameters->Parameters[index];
7273 +   const GLint slots = (param->Size + 3) / 4;
7274 +   const GLint typeSize = sizeof_glsl_type(param->DataType);
7275     GLint nr, nc;
7276  
7277     /* check that the number of rows, columns is correct */
7278 -   get_matrix_dims(program->Parameters->Parameters[index].DataType, &nr, &nc);
7279 +   get_matrix_dims(param->DataType, &nr, &nc);
7280     if (rows != nr || cols != nc) {
7281        _mesa_error(ctx, GL_INVALID_OPERATION,
7282                    "glUniformMatrix(matrix size mismatch)");
7283        return;
7284     }
7285  
7286 -   if (index + offset > program->Parameters->Size) {
7287 -      /* out of bounds! */
7288 -      return;
7289 +   if (param->Size <= typeSize) {
7290 +      /* non-array: count must be at most one; count == 0 is handled by the loop below */
7291 +      if (count > 1) {
7292 +         _mesa_error(ctx, GL_INVALID_OPERATION,
7293 +                     "glUniformMatrix(uniform is not an array)");
7294 +         return;
7295 +      }
7296     }
7297  
7298     /*
7299 @@ -1907,7 +1914,12 @@ set_program_uniform_matrix(GLcontext *ctx, struct gl_program *program,
7300  
7301        /* each matrix: */
7302        for (col = 0; col < cols; col++) {
7303 -         GLfloat *v = program->Parameters->ParameterValues[dst];
7304 +         GLfloat *v;
7305 +         if (offset >= slots) {
7306 +            /* Ignore writes beyond the end of (the used part of) an array */
7307 +            return;
7308 +         }
7309 +         v = program->Parameters->ParameterValues[index + offset];
7310           for (row = 0; row < rows; row++) {
7311              if (transpose) {
7312                 v[row] = values[src + row * cols + col];
7313 @@ -1916,7 +1928,8 @@ set_program_uniform_matrix(GLcontext *ctx, struct gl_program *program,
7314                 v[row] = values[src + col * rows + row];
7315              }
7316           }
7317 -         dst++;
7318 +
7319 +         offset++;
7320        }
7321  
7322        src += rows * cols;  /* next matrix */
7323 diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc
7324 index 9764fc2..56de47e 100644
7325 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc
7326 +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc
7327 @@ -602,42 +602,50 @@ vec4 exp2(const vec4 a)
7328  
7329  float sqrt(const float x)
7330  {
7331 +   const float nx = -x;
7332     float r;
7333     __asm float_rsq r, x;
7334 -   __asm float_rcp __retVal, r;
7335 -}
7336 -
7337 -vec2 sqrt(const vec2 v)
7338 -{
7339 -   float r;
7340 -   __asm float_rsq r, v.x;
7341 -   __asm float_rcp __retVal.x, r;
7342 -   __asm float_rsq r, v.y;
7343 -   __asm float_rcp __retVal.y, r;
7344 -}
7345 -
7346 -vec3 sqrt(const vec3 v)
7347 -{
7348 -   float r;
7349 -   __asm float_rsq r, v.x;
7350 -   __asm float_rcp __retVal.x, r;
7351 -   __asm float_rsq r, v.y;
7352 -   __asm float_rcp __retVal.y, r;
7353 -   __asm float_rsq r, v.z;
7354 -   __asm float_rcp __retVal.z, r;
7355 -}
7356 -
7357 -vec4 sqrt(const vec4 v)
7358 -{
7359 -   float r;
7360 -   __asm float_rsq r, v.x;
7361 -   __asm float_rcp __retVal.x, r;
7362 -   __asm float_rsq r, v.y;
7363 -   __asm float_rcp __retVal.y, r;
7364 -   __asm float_rsq r, v.z;
7365 -   __asm float_rcp __retVal.z, r;
7366 -   __asm float_rsq r, v.w;
7367 -   __asm float_rcp __retVal.w, r;
7368 +   __asm float_rcp r, r;
7369 +   __asm vec4_cmp __retVal, nx, r, 0.0;
7370 +}
7371 +
7372 +vec2 sqrt(const vec2 x)
7373 +{
7374 +   const vec2 nx = -x, zero = vec2(0.0);
7375 +   vec2 r;
7376 +   __asm float_rsq r.x, x.x;
7377 +   __asm float_rsq r.y, x.y;
7378 +   __asm float_rcp r.x, r.x;
7379 +   __asm float_rcp r.y, r.y;
7380 +   __asm vec4_cmp __retVal, nx, r, zero;
7381 +}
7382 +
7383 +vec3 sqrt(const vec3 x)
7384 +{
7385 +   const vec3 nx = -x, zero = vec3(0.0);
7386 +   vec3 r;
7387 +   __asm float_rsq r.x, x.x;
7388 +   __asm float_rsq r.y, x.y;
7389 +   __asm float_rsq r.z, x.z;
7390 +   __asm float_rcp r.x, r.x;
7391 +   __asm float_rcp r.y, r.y;
7392 +   __asm float_rcp r.z, r.z;
7393 +   __asm vec4_cmp __retVal, nx, r, zero;
7394 +}
7395 +
7396 +vec4 sqrt(const vec4 x)
7397 +{
7398 +   const vec4 nx = -x, zero = vec4(0.0);
7399 +   vec4 r;
7400 +   __asm float_rsq r.x, x.x;
7401 +   __asm float_rsq r.y, x.y;
7402 +   __asm float_rsq r.z, x.z;
7403 +   __asm float_rsq r.w, x.w;
7404 +   __asm float_rcp r.x, r.x;
7405 +   __asm float_rcp r.y, r.y;
7406 +   __asm float_rcp r.z, r.z;
7407 +   __asm float_rcp r.w, r.w;
7408 +   __asm vec4_cmp __retVal, nx, r, zero;
7409  }
7410  
7411  
7412 diff --git a/src/mesa/shader/slang/library/slang_common_builtin_gc.h b/src/mesa/shader/slang/library/slang_common_builtin_gc.h
7413 index 78a7b83..3c3666e 100644
7414 --- a/src/mesa/shader/slang/library/slang_common_builtin_gc.h
7415 +++ b/src/mesa/shader/slang/library/slang_common_builtin_gc.h
7416 @@ -307,55 +307,63 @@
7417  0,0,18,97,0,59,121,0,0,0,4,102,108,111,97,116,95,101,120,112,50,0,18,95,95,114,101,116,86,97,108,0,
7418  59,122,0,0,18,97,0,59,122,0,0,0,4,102,108,111,97,116,95,101,120,112,50,0,18,95,95,114,101,116,86,
7419  97,108,0,59,119,0,0,18,97,0,59,119,0,0,0,0,1,90,95,0,0,9,0,0,115,113,114,116,0,1,1,0,0,9,0,120,0,0,
7420 -0,1,3,2,90,95,0,0,9,0,1,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,0,18,120,0,0,0,4,
7421 -102,108,111,97,116,95,114,99,112,0,18,95,95,114,101,116,86,97,108,0,0,18,114,0,0,0,0,1,90,95,0,0,
7422 -10,0,0,115,113,114,116,0,1,1,0,0,10,0,118,0,0,0,1,3,2,90,95,0,0,9,0,1,114,0,0,0,4,102,108,111,97,
7423 -116,95,114,115,113,0,18,114,0,0,18,118,0,59,120,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,95,
7424 -95,114,101,116,86,97,108,0,59,120,0,0,18,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,
7425 -0,18,118,0,59,121,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,95,95,114,101,116,86,97,108,0,59,
7426 -121,0,0,18,114,0,0,0,0,1,90,95,0,0,11,0,0,115,113,114,116,0,1,1,0,0,11,0,118,0,0,0,1,3,2,90,95,0,0,
7427 -9,0,1,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,0,18,118,0,59,120,0,0,0,4,102,108,
7428 -111,97,116,95,114,99,112,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,114,0,0,0,4,102,108,111,
7429 -97,116,95,114,115,113,0,18,114,0,0,18,118,0,59,121,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,
7430 -95,95,114,101,116,86,97,108,0,59,121,0,0,18,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,
7431 -0,0,18,118,0,59,122,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,95,95,114,101,116,86,97,108,0,59,
7432 -122,0,0,18,114,0,0,0,0,1,90,95,0,0,12,0,0,115,113,114,116,0,1,1,0,0,12,0,118,0,0,0,1,3,2,90,95,0,0,
7433 -9,0,1,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,0,18,118,0,59,120,0,0,0,4,102,108,
7434 -111,97,116,95,114,99,112,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,114,0,0,0,4,102,108,111,
7435 -97,116,95,114,115,113,0,18,114,0,0,18,118,0,59,121,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,
7436 -95,95,114,101,116,86,97,108,0,59,121,0,0,18,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,
7437 -0,0,18,118,0,59,122,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,95,95,114,101,116,86,97,108,0,59,
7438 -122,0,0,18,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,0,18,118,0,59,119,0,0,0,4,102,
7439 -108,111,97,116,95,114,99,112,0,18,95,95,114,101,116,86,97,108,0,59,119,0,0,18,114,0,0,0,0,1,90,95,
7440 -0,0,9,0,0,105,110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,9,0,120,0,0,0,1,4,102,108,111,97,
7441 -116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,120,0,0,0,0,1,90,95,0,0,10,0,0,
7442 -105,110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,10,0,118,0,0,0,1,4,102,108,111,97,116,95,114,
7443 -115,113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,118,0,59,120,0,0,0,4,102,108,111,97,116,
7444 -95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,121,0,0,18,118,0,59,121,0,0,0,0,1,90,95,0,0,
7445 -11,0,0,105,110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,11,0,118,0,0,0,1,4,102,108,111,97,116,
7446 -95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,118,0,59,120,0,0,0,4,102,108,111,
7447 -97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,121,0,0,18,118,0,59,121,0,0,0,4,102,
7448 -108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,122,0,0,18,118,0,59,122,0,0,0,
7449 -0,1,90,95,0,0,12,0,0,105,110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,12,0,118,0,0,0,1,4,102,
7450 -108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,118,0,59,120,0,0,0,
7451 -4,102,108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,121,0,0,18,118,0,59,121,
7452 -0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,122,0,0,18,118,0,
7453 -59,122,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,119,0,0,18,
7454 -118,0,59,119,0,0,0,0,1,90,95,0,0,9,0,0,110,111,114,109,97,108,105,122,101,0,1,1,0,0,9,0,120,0,0,0,
7455 -1,9,18,95,95,114,101,116,86,97,108,0,17,49,0,48,0,0,20,0,0,1,90,95,0,0,10,0,0,110,111,114,109,97,
7456 -108,105,122,101,0,1,1,0,0,10,0,118,0,0,0,1,3,2,90,95,1,0,9,0,1,115,0,2,58,105,110,118,101,114,115,
7457 -101,115,113,114,116,0,0,58,100,111,116,0,0,18,118,0,0,18,118,0,0,0,0,0,0,0,4,118,101,99,52,95,109,
7458 -117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59,120,121,0,0,18,118,0,0,18,115,0,
7459 -0,0,0,1,90,95,0,0,11,0,0,110,111,114,109,97,108,105,122,101,0,1,1,0,0,11,0,118,0,0,0,1,3,2,90,95,0,
7460 -0,9,0,1,116,109,112,0,0,0,4,118,101,99,51,95,100,111,116,0,18,116,109,112,0,0,18,118,0,0,18,118,0,
7461 -0,0,4,102,108,111,97,116,95,114,115,113,0,18,116,109,112,0,0,18,116,109,112,0,0,0,4,118,101,99,52,
7462 -95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59,120,121,122,0,0,18,118,0,
7463 -0,18,116,109,112,0,0,0,0,1,90,95,0,0,12,0,0,110,111,114,109,97,108,105,122,101,0,1,1,0,0,12,0,118,
7464 -0,0,0,1,3,2,90,95,0,0,9,0,1,116,109,112,0,0,0,4,118,101,99,52,95,100,111,116,0,18,116,109,112,0,0,
7465 -18,118,0,0,18,118,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,116,109,112,0,0,18,116,109,112,0,
7466 -0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59,120,
7467 -121,122,0,0,18,118,0,0,18,116,109,112,0,0,0,0,1,90,95,0,0,9,0,0,97,98,115,0,1,1,0,0,9,0,97,0,0,0,1,
7468 -4,118,101,99,52,95,97,98,115,0,18,95,95,114,101,116,86,97,108,0,0,18,97,0,0,0,0,1,90,95,0,0,10,0,0,
7469 +0,1,3,2,90,95,1,0,9,0,1,110,120,0,2,18,120,0,54,0,0,3,2,90,95,0,0,9,0,1,114,0,0,0,4,102,108,111,97,
7470 +116,95,114,115,113,0,18,114,0,0,18,120,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,114,0,0,18,
7471 +114,0,0,0,4,118,101,99,52,95,99,109,112,0,18,95,95,114,101,116,86,97,108,0,0,18,110,120,0,0,18,114,
7472 +0,0,17,48,0,48,0,0,0,0,0,1,90,95,0,0,10,0,0,115,113,114,116,0,1,1,0,0,10,0,120,0,0,0,1,3,2,90,95,1,
7473 +0,10,0,1,110,120,0,2,18,120,0,54,0,1,1,122,101,114,111,0,2,58,118,101,99,50,0,0,17,48,0,48,0,0,0,0,
7474 +0,0,3,2,90,95,0,0,10,0,1,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,59,120,0,0,18,
7475 +120,0,59,120,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,59,121,0,0,18,120,0,59,121,0,0,0,
7476 +4,102,108,111,97,116,95,114,99,112,0,18,114,0,59,120,0,0,18,114,0,59,120,0,0,0,4,102,108,111,97,
7477 +116,95,114,99,112,0,18,114,0,59,121,0,0,18,114,0,59,121,0,0,0,4,118,101,99,52,95,99,109,112,0,18,
7478 +95,95,114,101,116,86,97,108,0,0,18,110,120,0,0,18,114,0,0,18,122,101,114,111,0,0,0,0,1,90,95,0,0,
7479 +11,0,0,115,113,114,116,0,1,1,0,0,11,0,120,0,0,0,1,3,2,90,95,1,0,11,0,1,110,120,0,2,18,120,0,54,0,1,
7480 +1,122,101,114,111,0,2,58,118,101,99,51,0,0,17,48,0,48,0,0,0,0,0,0,3,2,90,95,0,0,11,0,1,114,0,0,0,4,
7481 +102,108,111,97,116,95,114,115,113,0,18,114,0,59,120,0,0,18,120,0,59,120,0,0,0,4,102,108,111,97,116,
7482 +95,114,115,113,0,18,114,0,59,121,0,0,18,120,0,59,121,0,0,0,4,102,108,111,97,116,95,114,115,113,0,
7483 +18,114,0,59,122,0,0,18,120,0,59,122,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,114,0,59,120,0,0,
7484 +18,114,0,59,120,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,114,0,59,121,0,0,18,114,0,59,121,0,0,
7485 +0,4,102,108,111,97,116,95,114,99,112,0,18,114,0,59,122,0,0,18,114,0,59,122,0,0,0,4,118,101,99,52,
7486 +95,99,109,112,0,18,95,95,114,101,116,86,97,108,0,0,18,110,120,0,0,18,114,0,0,18,122,101,114,111,0,
7487 +0,0,0,1,90,95,0,0,12,0,0,115,113,114,116,0,1,1,0,0,12,0,120,0,0,0,1,3,2,90,95,1,0,12,0,1,110,120,0,
7488 +2,18,120,0,54,0,1,1,122,101,114,111,0,2,58,118,101,99,52,0,0,17,48,0,48,0,0,0,0,0,0,3,2,90,95,0,0,
7489 +12,0,1,114,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,114,0,59,120,0,0,18,120,0,59,120,0,0,0,4,
7490 +102,108,111,97,116,95,114,115,113,0,18,114,0,59,121,0,0,18,120,0,59,121,0,0,0,4,102,108,111,97,116,
7491 +95,114,115,113,0,18,114,0,59,122,0,0,18,120,0,59,122,0,0,0,4,102,108,111,97,116,95,114,115,113,0,
7492 +18,114,0,59,119,0,0,18,120,0,59,119,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,114,0,59,120,0,0,
7493 +18,114,0,59,120,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,114,0,59,121,0,0,18,114,0,59,121,0,0,
7494 +0,4,102,108,111,97,116,95,114,99,112,0,18,114,0,59,122,0,0,18,114,0,59,122,0,0,0,4,102,108,111,97,
7495 +116,95,114,99,112,0,18,114,0,59,119,0,0,18,114,0,59,119,0,0,0,4,118,101,99,52,95,99,109,112,0,18,
7496 +95,95,114,101,116,86,97,108,0,0,18,110,120,0,0,18,114,0,0,18,122,101,114,111,0,0,0,0,1,90,95,0,0,9,
7497 +0,0,105,110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,9,0,120,0,0,0,1,4,102,108,111,97,116,95,
7498 +114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,120,0,0,0,0,1,90,95,0,0,10,0,0,105,
7499 +110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,10,0,118,0,0,0,1,4,102,108,111,97,116,95,114,115,
7500 +113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,118,0,59,120,0,0,0,4,102,108,111,97,116,95,
7501 +114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,121,0,0,18,118,0,59,121,0,0,0,0,1,90,95,0,0,11,0,
7502 +0,105,110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,11,0,118,0,0,0,1,4,102,108,111,97,116,95,
7503 +114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,118,0,59,120,0,0,0,4,102,108,111,97,
7504 +116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,121,0,0,18,118,0,59,121,0,0,0,4,102,108,
7505 +111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,122,0,0,18,118,0,59,122,0,0,0,0,1,
7506 +90,95,0,0,12,0,0,105,110,118,101,114,115,101,115,113,114,116,0,1,1,0,0,12,0,118,0,0,0,1,4,102,108,
7507 +111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,118,0,59,120,0,0,0,4,
7508 +102,108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,121,0,0,18,118,0,59,121,0,
7509 +0,0,4,102,108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,122,0,0,18,118,0,59,
7510 +122,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,95,95,114,101,116,86,97,108,0,59,119,0,0,18,118,
7511 +0,59,119,0,0,0,0,1,90,95,0,0,9,0,0,110,111,114,109,97,108,105,122,101,0,1,1,0,0,9,0,120,0,0,0,1,9,
7512 +18,95,95,114,101,116,86,97,108,0,17,49,0,48,0,0,20,0,0,1,90,95,0,0,10,0,0,110,111,114,109,97,108,
7513 +105,122,101,0,1,1,0,0,10,0,118,0,0,0,1,3,2,90,95,1,0,9,0,1,115,0,2,58,105,110,118,101,114,115,101,
7514 +115,113,114,116,0,0,58,100,111,116,0,0,18,118,0,0,18,118,0,0,0,0,0,0,0,4,118,101,99,52,95,109,117,
7515 +108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59,120,121,0,0,18,118,0,0,18,115,0,0,0,
7516 +0,1,90,95,0,0,11,0,0,110,111,114,109,97,108,105,122,101,0,1,1,0,0,11,0,118,0,0,0,1,3,2,90,95,0,0,9,
7517 +0,1,116,109,112,0,0,0,4,118,101,99,51,95,100,111,116,0,18,116,109,112,0,0,18,118,0,0,18,118,0,0,0,
7518 +4,102,108,111,97,116,95,114,115,113,0,18,116,109,112,0,0,18,116,109,112,0,0,0,4,118,101,99,52,95,
7519 +109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59,120,121,122,0,0,18,118,0,0,
7520 +18,116,109,112,0,0,0,0,1,90,95,0,0,12,0,0,110,111,114,109,97,108,105,122,101,0,1,1,0,0,12,0,118,0,
7521 +0,0,1,3,2,90,95,0,0,9,0,1,116,109,112,0,0,0,4,118,101,99,52,95,100,111,116,0,18,116,109,112,0,0,18,
7522 +118,0,0,18,118,0,0,0,4,102,108,111,97,116,95,114,115,113,0,18,116,109,112,0,0,18,116,109,112,0,0,0,
7523 +4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59,120,121,
7524 +122,0,0,18,118,0,0,18,116,109,112,0,0,0,0,1,90,95,0,0,9,0,0,97,98,115,0,1,1,0,0,9,0,97,0,0,0,1,4,
7525 +118,101,99,52,95,97,98,115,0,18,95,95,114,101,116,86,97,108,0,0,18,97,0,0,0,0,1,90,95,0,0,10,0,0,
7526  97,98,115,0,1,1,0,0,10,0,97,0,0,0,1,4,118,101,99,52,95,97,98,115,0,18,95,95,114,101,116,86,97,108,
7527  0,59,120,121,0,0,18,97,0,0,0,0,1,90,95,0,0,11,0,0,97,98,115,0,1,1,0,0,11,0,97,0,0,0,1,4,118,101,99,
7528  52,95,97,98,115,0,18,95,95,114,101,116,86,97,108,0,59,120,121,122,0,0,18,97,0,0,0,0,1,90,95,0,0,12,
7529 diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
7530 index 703af9f..344dfdc 100644
7531 --- a/src/mesa/shader/slang/slang_codegen.c
7532 +++ b/src/mesa/shader/slang/slang_codegen.c
7533 @@ -422,6 +422,7 @@ static slang_asm_info AsmInfo[] = {
7534     { "vec4_lrp", IR_LRP, 1, 3 },
7535     { "vec4_min", IR_MIN, 1, 2 },
7536     { "vec4_max", IR_MAX, 1, 2 },
7537 +   { "vec4_cmp", IR_CMP, 1, 3 },
7538     { "vec4_clamp", IR_CLAMP, 1, 3 },
7539     { "vec4_seq", IR_SEQUAL, 1, 2 },
7540     { "vec4_sne", IR_SNEQUAL, 1, 2 },
7541 diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
7542 index 3f455e0..3af301e 100644
7543 --- a/src/mesa/shader/slang/slang_emit.c
7544 +++ b/src/mesa/shader/slang/slang_emit.c
7545 @@ -2287,6 +2287,7 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n)
7546     case IR_POW:
7547     /* trinary operators */
7548     case IR_LRP:
7549 +   case IR_CMP:
7550        return emit_arith(emitInfo, n);
7551  
7552     case IR_EQUAL:
7553 diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c
7554 index 1c7f747..6260350 100644
7555 --- a/src/mesa/shader/slang/slang_ir.c
7556 +++ b/src/mesa/shader/slang/slang_ir.c
7557 @@ -80,6 +80,7 @@ static const slang_ir_info IrInfo[] = {
7558     { IR_NOISE4, "IR_NOISE4", OPCODE_NOISE4, 1, 1 },
7559  
7560     /* other */
7561 +   { IR_CMP, "IR_CMP", OPCODE_CMP, 4, 3 },  /* compare/select */
7562     { IR_SEQ, "IR_SEQ", OPCODE_NOP, 0, 0 },
7563     { IR_SCOPE, "IR_SCOPE", OPCODE_NOP, 0, 0 },
7564     { IR_LABEL, "IR_LABEL", OPCODE_NOP, 0, 0 },
7565 diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
7566 index e796693..166b4e8 100644
7567 --- a/src/mesa/shader/slang/slang_ir.h
7568 +++ b/src/mesa/shader/slang/slang_ir.h
7569 @@ -91,6 +91,7 @@ typedef enum
7570     IR_CLAMP,
7571     IR_MIN,
7572     IR_MAX,
7573 +   IR_CMP,     /* = (op0 < 0) ? op1 : op2 */
7574     IR_SEQUAL,  /* Set if args are equal (vector) */
7575     IR_SNEQUAL, /* Set if args are not equal (vector) */
7576     IR_SGE,     /* Set if greater or equal (vector) */
7577 diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
7578 index 8f2b40d..144c126 100644
7579 --- a/src/mesa/shader/slang/slang_link.c
7580 +++ b/src/mesa/shader/slang/slang_link.c
7581 @@ -104,7 +104,7 @@ link_varying_vars(GLcontext *ctx,
7582     GLuint *map, i, firstVarying, newFile;
7583     GLbitfield *inOutFlags;
7584  
7585 -   map = (GLuint *) malloc(prog->Varying->NumParameters * sizeof(GLuint));
7586 +   map = (GLuint *) _mesa_malloc(prog->Varying->NumParameters * sizeof(GLuint));
7587     if (!map)
7588        return GL_FALSE;
7589  
7590 @@ -135,6 +135,7 @@ link_varying_vars(GLcontext *ctx,
7591              &shProg->Varying->Parameters[j];
7592           if (var->Size != v->Size) {
7593              link_error(shProg, "mismatched varying variable types");
7594 +            _mesa_free(map);
7595              return GL_FALSE;
7596           }
7597           if (!bits_agree(var->Flags, v->Flags, PROG_PARAM_BIT_CENTROID)) {
7598 @@ -142,6 +143,7 @@ link_varying_vars(GLcontext *ctx,
7599              _mesa_snprintf(msg, sizeof(msg),
7600                             "centroid modifier mismatch for '%s'", var->Name);
7601              link_error(shProg, msg);
7602 +            _mesa_free(map);
7603              return GL_FALSE;
7604           }
7605           if (!bits_agree(var->Flags, v->Flags, PROG_PARAM_BIT_INVARIANT)) {
7606 @@ -149,6 +151,7 @@ link_varying_vars(GLcontext *ctx,
7607              _mesa_snprintf(msg, sizeof(msg),
7608                             "invariant modifier mismatch for '%s'", var->Name);
7609              link_error(shProg, msg);
7610 +            _mesa_free(map);
7611              return GL_FALSE;
7612           }
7613        }
7614 @@ -160,6 +163,7 @@ link_varying_vars(GLcontext *ctx,
7615  
7616        if (shProg->Varying->NumParameters > ctx->Const.MaxVarying) {
7617           link_error(shProg, "Too many varying variables");
7618 +         _mesa_free(map);
7619           return GL_FALSE;
7620        }
7621  
7622 @@ -199,7 +203,7 @@ link_varying_vars(GLcontext *ctx,
7623        }
7624     }
7625  
7626 -   free(map);
7627 +   _mesa_free(map);
7628  
7629     /* these will get recomputed before linking is completed */
7630     prog->InputsRead = 0x0;
7631 @@ -670,6 +674,7 @@ get_main_shader(GLcontext *ctx,
7632            !shader->Main ||
7633            shader->UnresolvedRefs) {
7634           link_error(shProg, "Unresolved symbols");
7635 +         _mesa_free_shader(ctx, shader);
7636           return NULL;
7637        }
7638     }
7639 diff --git a/src/mesa/shader/symbol_table.c b/src/mesa/shader/symbol_table.c
7640 index 7a9aa7b..1f6d9b8 100644
7641 --- a/src/mesa/shader/symbol_table.c
7642 +++ b/src/mesa/shader/symbol_table.c
7643 @@ -20,12 +20,8 @@
7644   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
7645   * DEALINGS IN THE SOFTWARE.
7646   */
7647 -#include <stdlib.h>
7648 -#include <stdio.h>
7649 -#include <string.h>
7650 -#include <errno.h>
7651 -#include <assert.h>
7652  
7653 +#include "main/imports.h"
7654  #include "symbol_table.h"
7655  #include "hash_table.h"
7656  
7657 @@ -73,6 +69,9 @@ struct symbol {
7658  /**
7659   */
7660  struct symbol_header {
7661 +    /** Linkage in list of all headers in a given symbol table. */
7662 +    struct symbol_header *next;
7663 +
7664      /** Symbol name. */
7665      const char *name;
7666  
7667 @@ -102,6 +101,9 @@ struct _mesa_symbol_table {
7668  
7669      /** Top of scope stack. */
7670      struct scope_level *current_scope;
7671 +
7672 +    /** List of all symbol headers in the table. */
7673 +    struct symbol_header *hdr;
7674  };
7675  
7676  
7677 @@ -301,6 +303,8 @@ _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *table,
7678          hdr->name = name;
7679  
7680          hash_table_insert(table->ht, hdr, name);
7681 +       hdr->next = table->hdr;
7682 +       table->hdr = hdr;
7683      }
7684  
7685      check_symbol_table(table);
7686 @@ -341,10 +345,18 @@ _mesa_symbol_table_ctor(void)
7687  void
7688  _mesa_symbol_table_dtor(struct _mesa_symbol_table *table)
7689  {
7690 +   struct symbol_header *hdr;
7691 +   struct symbol_header *next;
7692 +
7693     while (table->current_scope != NULL) {
7694        _mesa_symbol_table_pop_scope(table);
7695     }
7696  
7697 +   for (hdr = table->hdr; hdr != NULL; hdr = next) {
7698 +       next = hdr->next;
7699 +       _mesa_free(hdr);
7700 +   }
7701 +
7702     hash_table_dtor(table->ht);
7703     free(table);
7704  }
7705 diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
7706 index a9cafbf..2a227a7 100644
7707 --- a/src/mesa/state_tracker/st_cb_drawpixels.c
7708 +++ b/src/mesa/state_tracker/st_cb_drawpixels.c
7709 @@ -598,15 +598,15 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
7710  
7711     /* viewport state: viewport matching window dims */
7712     {
7713 -      const float width = (float) ctx->DrawBuffer->Width;
7714 -      const float height = (float) ctx->DrawBuffer->Height;
7715 +      const float w = (float) ctx->DrawBuffer->Width;
7716 +      const float h = (float) ctx->DrawBuffer->Height;
7717        struct pipe_viewport_state vp;
7718 -      vp.scale[0] =  0.5f * width;
7719 -      vp.scale[1] = -0.5f * height;
7720 +      vp.scale[0] =  0.5f * w;
7721 +      vp.scale[1] = -0.5f * h;
7722        vp.scale[2] = 1.0f;
7723        vp.scale[3] = 1.0f;
7724 -      vp.translate[0] = 0.5f * width;
7725 -      vp.translate[1] = 0.5f * height;
7726 +      vp.translate[0] = 0.5f * w;
7727 +      vp.translate[1] = 0.5f * h;
7728        vp.translate[2] = 0.0f;
7729        vp.translate[3] = 0.0f;
7730        cso_set_viewport(cso, &vp);
7731 @@ -661,6 +661,15 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
7732     const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
7733     GLint skipPixels;
7734     ubyte *stmap;
7735 +   struct gl_pixelstore_attrib clippedUnpack = *unpack;
7736 +
7737 +   if (!zoom) {
7738 +      if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,
7739 +                                 &clippedUnpack)) {
7740 +         /* totally clipped */
7741 +         return;
7742 +      }
7743 +   }
7744  
7745     strb = st_renderbuffer(ctx->DrawBuffer->
7746                            Attachment[BUFFER_STENCIL].Renderbuffer);
7747 @@ -681,7 +690,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
7748  
7749     stmap = screen->transfer_map(screen, pt);
7750  
7751 -   pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
7752 +   pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels);
7753     assert(pixels);
7754  
7755     /* if width > MAX_WIDTH, have to process image in chunks */
7756 @@ -694,17 +703,18 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
7757           GLubyte sValues[MAX_WIDTH];
7758           GLuint zValues[MAX_WIDTH];
7759           GLenum destType = GL_UNSIGNED_BYTE;
7760 -         const GLvoid *source = _mesa_image_address2d(unpack, pixels,
7761 +         const GLvoid *source = _mesa_image_address2d(&clippedUnpack, pixels,
7762                                                        width, height,
7763                                                        format, type,
7764                                                        row, skipPixels);
7765           _mesa_unpack_stencil_span(ctx, spanWidth, destType, sValues,
7766 -                                   type, source, unpack,
7767 +                                   type, source, &clippedUnpack,
7768                                     ctx->_ImageTransferState);
7769  
7770           if (format == GL_DEPTH_STENCIL) {
7771              _mesa_unpack_depth_span(ctx, spanWidth, GL_UNSIGNED_INT, zValues,
7772 -                                    (1 << 24) - 1, type, source, unpack);
7773 +                                    (1 << 24) - 1, type, source,
7774 +                                    &clippedUnpack);
7775           }
7776  
7777           if (zoom) {
7778 @@ -775,7 +785,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
7779        skipPixels += spanWidth;
7780     }
7781  
7782 -   _mesa_unmap_pbo_source(ctx, unpack);
7783 +   _mesa_unmap_pbo_source(ctx, &clippedUnpack);
7784  
7785     /* unmap the stencil buffer */
7786     screen->transfer_unmap(screen, pt);
7787 diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
7788 index fe0a121..e8399de 100644
7789 --- a/src/mesa/state_tracker/st_cb_fbo.c
7790 +++ b/src/mesa/state_tracker/st_cb_fbo.c
7791 @@ -165,12 +165,12 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
7792                                                       strb->texture,
7793                                                       0, 0, 0,
7794                                                       surface_usage );
7795 -
7796 -      assert(strb->surface->texture);
7797 -      assert(strb->surface->format);
7798 -      assert(strb->surface->width == width);
7799 -      assert(strb->surface->height == height);
7800 -
7801 +      if (strb->surface) {
7802 +         assert(strb->surface->texture);
7803 +         assert(strb->surface->format);
7804 +         assert(strb->surface->width == width);
7805 +         assert(strb->surface->height == height);
7806 +      }
7807  
7808        return strb->surface != NULL;
7809     }
7810 @@ -298,6 +298,7 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
7811     default:
7812        _mesa_problem(NULL,
7813                     "Unexpected format in st_new_renderbuffer_fb");
7814 +      _mesa_free(strb);
7815        return NULL;
7816     }
7817  
7818 diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
7819 index b13e377..f45b3e6 100644
7820 --- a/src/mesa/state_tracker/st_cb_texture.c
7821 +++ b/src/mesa/state_tracker/st_cb_texture.c
7822 @@ -1313,7 +1313,8 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
7823                                                srcX, srcY,
7824                                                width, height);
7825  
7826 -   if (baseFormat == GL_DEPTH_COMPONENT &&
7827 +   if ((baseFormat == GL_DEPTH_COMPONENT ||
7828 +        baseFormat == GL_DEPTH_STENCIL) &&
7829         pf_is_depth_and_stencil(stImage->pt->format))
7830        transfer_usage = PIPE_TRANSFER_READ_WRITE;
7831     else
7832 @@ -1326,7 +1327,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
7833                                    destX, destY, width, height);
7834  
7835     if (baseFormat == GL_DEPTH_COMPONENT ||
7836 -       baseFormat == GL_DEPTH24_STENCIL8) {
7837 +       baseFormat == GL_DEPTH_STENCIL) {
7838        const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
7839                                       ctx->Pixel.DepthBias != 0.0F);
7840        GLint row, yStep;
7841 @@ -1453,7 +1454,7 @@ st_copy_texsubimage(GLcontext *ctx,
7842     struct gl_texture_image *texImage =
7843        _mesa_select_tex_image(ctx, texObj, target, level);
7844     struct st_texture_image *stImage = st_texture_image(texImage);
7845 -   const GLenum texBaseFormat = texImage->InternalFormat;
7846 +   const GLenum texBaseFormat = texImage->_BaseFormat;
7847     struct gl_framebuffer *fb = ctx->ReadBuffer;
7848     struct st_renderbuffer *strb;
7849     struct pipe_context *pipe = ctx->st->pipe;
7850 @@ -1474,12 +1475,9 @@ st_copy_texsubimage(GLcontext *ctx,
7851  
7852     /* determine if copying depth or color data */
7853     if (texBaseFormat == GL_DEPTH_COMPONENT ||
7854 -       texBaseFormat == GL_DEPTH24_STENCIL8) {
7855 +       texBaseFormat == GL_DEPTH_STENCIL) {
7856        strb = st_renderbuffer(fb->_DepthBuffer);
7857     }
7858 -   else if (texBaseFormat == GL_DEPTH_STENCIL_EXT) {
7859 -      strb = st_renderbuffer(fb->_StencilBuffer);
7860 -   }
7861     else {
7862        /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
7863        strb = st_renderbuffer(fb->_ColorReadBuffer);
7864 @@ -1562,6 +1560,8 @@ st_copy_texsubimage(GLcontext *ctx,
7865           use_fallback = GL_FALSE;
7866        }
7867        else if (format_writemask &&
7868 +               texBaseFormat != GL_DEPTH_COMPONENT &&
7869 +               texBaseFormat != GL_DEPTH_STENCIL &&
7870                 screen->is_format_supported(screen, src_format,
7871                                             PIPE_TEXTURE_2D, 
7872                                             PIPE_TEXTURE_USAGE_SAMPLER,
7873 @@ -1775,7 +1775,11 @@ st_finalize_texture(GLcontext *ctx,
7874         * incomplete.  In that case, we'll have set stObj->lastLevel before
7875         * we get here.
7876         */
7877 -      stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel;
7878 +      if (stObj->base.MinFilter == GL_LINEAR ||
7879 +          stObj->base.MinFilter == GL_NEAREST)
7880 +         stObj->lastLevel = stObj->base.BaseLevel;
7881 +      else
7882 +         stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel;
7883     }
7884  
7885     firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
7886 diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c
7887 index 5c0d335..a5d1ae3 100644
7888 --- a/src/mesa/state_tracker/st_framebuffer.c
7889 +++ b/src/mesa/state_tracker/st_framebuffer.c
7890 @@ -52,6 +52,7 @@ st_create_framebuffer( const __GLcontextModes *visual,
7891     struct st_framebuffer *stfb = ST_CALLOC_STRUCT(st_framebuffer);
7892     if (stfb) {
7893        int samples = st_get_msaa();
7894 +      int i;
7895  
7896        if (visual->sampleBuffers)
7897           samples = visual->samples;
7898 @@ -119,6 +120,12 @@ st_create_framebuffer( const __GLcontextModes *visual,
7899           _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb);
7900        }
7901  
7902 +      for (i = 0; i < visual->numAuxBuffers; i++) {
7903 +         struct gl_renderbuffer *aux
7904 +            = st_new_renderbuffer_fb(colorFormat, 0, FALSE);
7905 +         _mesa_add_renderbuffer(&stfb->Base, BUFFER_AUX0 + i, aux);
7906 +      }
7907 +
7908        stfb->Base.Initialized = GL_TRUE;
7909        stfb->InitWidth = width;
7910        stfb->InitHeight = height;
7911 diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
7912 index 26e23f0..7086cae 100644
7913 --- a/src/mesa/swrast/s_depth.c
7914 +++ b/src/mesa/swrast/s_depth.c
7915 @@ -1211,6 +1211,7 @@ _swrast_read_depth_span_float( GLcontext *ctx, struct gl_renderbuffer *rb,
7916     if (!rb) {
7917        /* really only doing this to prevent FP exceptions later */
7918        _mesa_bzero(depth, n * sizeof(GLfloat));
7919 +      return;
7920     }
7921  
7922     ASSERT(rb->_BaseFormat == GL_DEPTH_COMPONENT);
7923 @@ -1273,7 +1274,8 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
7924  {
7925     if (!rb) {
7926        /* really only doing this to prevent FP exceptions later */
7927 -      _mesa_bzero(depth, n * sizeof(GLfloat));
7928 +      _mesa_bzero(depth, n * sizeof(GLuint));
7929 +      return;
7930     }
7931  
7932     ASSERT(rb->_BaseFormat == GL_DEPTH_COMPONENT);
7933
This page took 0.895367 seconds and 4 git commands to generate.