quartz: Use proper alloc/free functions for COM objects.
[wine] / dlls / wined3d / state.c
1 /*
2  * Direct3D state management
3  *
4  * Copyright 2002 Lionel Ulmer
5  * Copyright 2002-2005 Jason Edmeades
6  * Copyright 2003-2004 Raphael Junqueira
7  * Copyright 2004 Christian Costa
8  * Copyright 2005 Oliver Stieber
9  * Copyright 2006 Henri Verbeet
10  * Copyright 2006-2007 Stefan Dösinger for CodeWeavers
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26
27 #include "config.h"
28 #include <stdio.h>
29 #ifdef HAVE_FLOAT_H
30 # include <float.h>
31 #endif
32 #include "wined3d_private.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
35 WINE_DECLARE_DEBUG_CHANNEL(d3d_shader);
36
37 #define GLINFO_LOCATION ((IWineD3DImpl *)(stateblock->wineD3DDevice->wineD3D))->gl_info
38
39 static void state_nogl(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
40     /* Used for states which are not mapped to a gl state as-is, but used somehow different,
41      * e.g as a parameter for drawing, or which are unimplemented in windows d3d
42      */
43     if(STATE_IS_RENDER(state)) {
44         WINED3DRENDERSTATETYPE RenderState = state - STATE_RENDER(0);
45         TRACE("(%s,%d) no direct mapping to gl\n", debug_d3drenderstate(RenderState), stateblock->renderState[RenderState]);
46     } else {
47         /* Shouldn't have an unknown type here */
48         FIXME("%d no direct mapping to gl of state with unknown type\n", state);
49     }
50 }
51
52 static void state_undefined(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
53     /* Print a WARN, this allows the stateblock code to loop over all states to generate a display
54      * list without causing confusing terminal output. Deliberately no special debug name here
55      * because its undefined.
56      */
57     WARN("undefined state %d\n", state);
58 }
59
60 static void state_fillmode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
61     WINED3DFILLMODE Value = stateblock->renderState[WINED3DRS_FILLMODE];
62
63     switch(Value) {
64         case WINED3DFILL_POINT:
65             glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
66             checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
67             break;
68         case WINED3DFILL_WIREFRAME:
69             glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
70             checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
71             break;
72         case WINED3DFILL_SOLID:
73             glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
74             checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
75             break;
76         default:
77             FIXME("Unrecognized WINED3DRS_FILLMODE value %d\n", Value);
78     }
79 }
80
81 static void state_lighting(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
82     BOOL transformed;
83
84     /* Lighting is not enabled if transformed vertices are drawn
85      * but lighting does not affect the stream sources, so it is not grouped for performance reasons.
86      * This state reads the decoded vertex decl, so if it is dirty don't do anything. The
87      * vertex declaration appplying function calls this function for updating
88      */
89
90     if(isStateDirty(context, STATE_VDECL)) {
91         return;
92     }
93
94     transformed = ((stateblock->wineD3DDevice->strided_streams.u.s.position.lpData != NULL ||
95                     stateblock->wineD3DDevice->strided_streams.u.s.position.VBO != 0) &&
96                     stateblock->wineD3DDevice->strided_streams.u.s.position_transformed) ? TRUE : FALSE;
97
98     if (stateblock->renderState[WINED3DRS_LIGHTING] && !transformed) {
99         glEnable(GL_LIGHTING);
100         checkGLcall("glEnable GL_LIGHTING");
101     } else {
102         glDisable(GL_LIGHTING);
103         checkGLcall("glDisable GL_LIGHTING");
104     }
105 }
106
107 static void state_zenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
108     /* No z test without depth stencil buffers */
109     if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) {
110         glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */
111         checkGLcall("glDisable GL_DEPTH_TEST");
112         return;
113     }
114
115     switch ((WINED3DZBUFFERTYPE) stateblock->renderState[WINED3DRS_ZENABLE]) {
116         case WINED3DZB_FALSE:
117             glDisable(GL_DEPTH_TEST);
118             checkGLcall("glDisable GL_DEPTH_TEST");
119             break;
120         case WINED3DZB_TRUE:
121             glEnable(GL_DEPTH_TEST);
122             checkGLcall("glEnable GL_DEPTH_TEST");
123             break;
124         case WINED3DZB_USEW:
125             glEnable(GL_DEPTH_TEST);
126             checkGLcall("glEnable GL_DEPTH_TEST");
127             FIXME("W buffer is not well handled\n");
128             break;
129         default:
130             FIXME("Unrecognized D3DZBUFFERTYPE value %d\n", stateblock->renderState[WINED3DRS_ZENABLE]);
131     }
132 }
133
134 static void state_cullmode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
135     /* TODO: Put this into the offscreen / onscreen rendering block due to device->render_offscreen */
136
137     /* If we are culling "back faces with clockwise vertices" then
138        set front faces to be counter clockwise and enable culling
139        of back faces                                               */
140     switch ((WINED3DCULL) stateblock->renderState[WINED3DRS_CULLMODE]) {
141         case WINED3DCULL_NONE:
142             glDisable(GL_CULL_FACE);
143             checkGLcall("glDisable GL_CULL_FACE");
144             break;
145         case WINED3DCULL_CW:
146             glEnable(GL_CULL_FACE);
147             checkGLcall("glEnable GL_CULL_FACE");
148             if (stateblock->wineD3DDevice->render_offscreen) {
149                 glFrontFace(GL_CW);
150                 checkGLcall("glFrontFace GL_CW");
151             } else {
152                 glFrontFace(GL_CCW);
153                 checkGLcall("glFrontFace GL_CCW");
154             }
155             glCullFace(GL_BACK);
156             break;
157         case WINED3DCULL_CCW:
158             glEnable(GL_CULL_FACE);
159             checkGLcall("glEnable GL_CULL_FACE");
160             if (stateblock->wineD3DDevice->render_offscreen) {
161                 glFrontFace(GL_CCW);
162                 checkGLcall("glFrontFace GL_CCW");
163             } else {
164                 glFrontFace(GL_CW);
165                 checkGLcall("glFrontFace GL_CW");
166             }
167             glCullFace(GL_BACK);
168             break;
169         default:
170             FIXME("Unrecognized/Unhandled WINED3DCULL value %d\n", stateblock->renderState[WINED3DRS_CULLMODE]);
171     }
172 }
173
174 static void state_shademode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
175     switch ((WINED3DSHADEMODE) stateblock->renderState[WINED3DRS_SHADEMODE]) {
176         case WINED3DSHADE_FLAT:
177             glShadeModel(GL_FLAT);
178             checkGLcall("glShadeModel(GL_FLAT)");
179             break;
180         case WINED3DSHADE_GOURAUD:
181             glShadeModel(GL_SMOOTH);
182             checkGLcall("glShadeModel(GL_SMOOTH)");
183             break;
184         case WINED3DSHADE_PHONG:
185             FIXME("WINED3DSHADE_PHONG isn't supported\n");
186             break;
187         default:
188             FIXME("Unrecognized/Unhandled WINED3DSHADEMODE value %d\n", stateblock->renderState[WINED3DRS_SHADEMODE]);
189     }
190 }
191
192 static void state_ditherenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
193     if (stateblock->renderState[WINED3DRS_DITHERENABLE]) {
194         glEnable(GL_DITHER);
195         checkGLcall("glEnable GL_DITHER");
196     } else {
197         glDisable(GL_DITHER);
198         checkGLcall("glDisable GL_DITHER");
199     }
200 }
201
202 static void state_zwritenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
203     /* TODO: Test if in d3d z writing is enabled even if ZENABLE is off. If yes,
204      * this has to be merged with ZENABLE and ZFUNC
205      */
206     if (stateblock->renderState[WINED3DRS_ZWRITEENABLE]) {
207         glDepthMask(1);
208         checkGLcall("glDepthMask(1)");
209     } else {
210         glDepthMask(0);
211         checkGLcall("glDepthMask(0)");
212     }
213 }
214
215 static void state_zfunc(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
216     int glParm = CompareFunc(stateblock->renderState[WINED3DRS_ZFUNC]);
217
218     if(glParm) {
219         glDepthFunc(glParm);
220         checkGLcall("glDepthFunc");
221     }
222 }
223
224 static void state_ambient(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
225     float col[4];
226     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_AMBIENT], col);
227
228     TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]);
229     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
230     checkGLcall("glLightModel for MODEL_AMBIENT");
231 }
232
233 static void state_blend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
234     int srcBlend = GL_ZERO;
235     int dstBlend = GL_ZERO;
236
237     /* GL_LINE_SMOOTH needs GL_BLEND to work, according to the red book, and special blending params */
238     if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE]      ||
239         stateblock->renderState[WINED3DRS_EDGEANTIALIAS]         ||
240         stateblock->renderState[WINED3DRS_ANTIALIASEDLINEENABLE]) {
241         glEnable(GL_BLEND);
242         checkGLcall("glEnable GL_BLEND");
243     } else {
244         glDisable(GL_BLEND);
245         checkGLcall("glDisable GL_BLEND");
246         /* Nothing more to do - get out */
247         return;
248     };
249
250     switch (stateblock->renderState[WINED3DRS_SRCBLEND]) {
251         case WINED3DBLEND_ZERO               : srcBlend = GL_ZERO;  break;
252         case WINED3DBLEND_ONE                : srcBlend = GL_ONE;  break;
253         case WINED3DBLEND_SRCCOLOR           : srcBlend = GL_SRC_COLOR;  break;
254         case WINED3DBLEND_INVSRCCOLOR        : srcBlend = GL_ONE_MINUS_SRC_COLOR;  break;
255         case WINED3DBLEND_SRCALPHA           : srcBlend = GL_SRC_ALPHA;  break;
256         case WINED3DBLEND_INVSRCALPHA        : srcBlend = GL_ONE_MINUS_SRC_ALPHA;  break;
257         case WINED3DBLEND_DESTALPHA          : srcBlend = GL_DST_ALPHA;  break;
258         case WINED3DBLEND_INVDESTALPHA       : srcBlend = GL_ONE_MINUS_DST_ALPHA;  break;
259         case WINED3DBLEND_DESTCOLOR          : srcBlend = GL_DST_COLOR;  break;
260         case WINED3DBLEND_INVDESTCOLOR       : srcBlend = GL_ONE_MINUS_DST_COLOR;  break;
261         case WINED3DBLEND_SRCALPHASAT        : srcBlend = GL_SRC_ALPHA_SATURATE;  break;
262
263         case WINED3DBLEND_BOTHSRCALPHA       : srcBlend = GL_SRC_ALPHA;
264             dstBlend = GL_SRC_ALPHA;
265             break;
266
267         case WINED3DBLEND_BOTHINVSRCALPHA    : srcBlend = GL_ONE_MINUS_SRC_ALPHA;
268             dstBlend = GL_ONE_MINUS_SRC_ALPHA;
269             break;
270
271         case WINED3DBLEND_BLENDFACTOR        : srcBlend = GL_CONSTANT_COLOR;   break;
272         case WINED3DBLEND_INVBLENDFACTOR     : srcBlend = GL_ONE_MINUS_CONSTANT_COLOR;  break;
273         default:
274             FIXME("Unrecognized src blend value %d\n", stateblock->renderState[WINED3DRS_SRCBLEND]);
275     }
276
277     switch (stateblock->renderState[WINED3DRS_DESTBLEND]) {
278         case WINED3DBLEND_ZERO               : dstBlend = GL_ZERO;  break;
279         case WINED3DBLEND_ONE                : dstBlend = GL_ONE;  break;
280         case WINED3DBLEND_SRCCOLOR           : dstBlend = GL_SRC_COLOR;  break;
281         case WINED3DBLEND_INVSRCCOLOR        : dstBlend = GL_ONE_MINUS_SRC_COLOR;  break;
282         case WINED3DBLEND_SRCALPHA           : dstBlend = GL_SRC_ALPHA;  break;
283         case WINED3DBLEND_INVSRCALPHA        : dstBlend = GL_ONE_MINUS_SRC_ALPHA;  break;
284         case WINED3DBLEND_DESTALPHA          : dstBlend = GL_DST_ALPHA;  break;
285         case WINED3DBLEND_INVDESTALPHA       : dstBlend = GL_ONE_MINUS_DST_ALPHA;  break;
286         case WINED3DBLEND_DESTCOLOR          : dstBlend = GL_DST_COLOR;  break;
287         case WINED3DBLEND_INVDESTCOLOR       : dstBlend = GL_ONE_MINUS_DST_COLOR;  break;
288         case WINED3DBLEND_SRCALPHASAT        : dstBlend = GL_SRC_ALPHA_SATURATE;  break;
289
290         case WINED3DBLEND_BOTHSRCALPHA       : dstBlend = GL_SRC_ALPHA;
291             srcBlend = GL_SRC_ALPHA;
292             break;
293
294         case WINED3DBLEND_BOTHINVSRCALPHA    : dstBlend = GL_ONE_MINUS_SRC_ALPHA;
295             srcBlend = GL_ONE_MINUS_SRC_ALPHA;
296             break;
297
298         case WINED3DBLEND_BLENDFACTOR        : dstBlend = GL_CONSTANT_COLOR;   break;
299         case WINED3DBLEND_INVBLENDFACTOR     : dstBlend = GL_ONE_MINUS_CONSTANT_COLOR;  break;
300         default:
301             FIXME("Unrecognized dst blend value %d\n", stateblock->renderState[WINED3DRS_DESTBLEND]);
302     }
303
304     if(stateblock->renderState[WINED3DRS_EDGEANTIALIAS] ||
305        stateblock->renderState[WINED3DRS_ANTIALIASEDLINEENABLE]) {
306         glEnable(GL_LINE_SMOOTH);
307         checkGLcall("glEnable(GL_LINE_SMOOTH)");
308         if(srcBlend != GL_SRC_ALPHA) {
309             FIXME("WINED3DRS_EDGEANTIALIAS enabled, but incompatible src blending param - what to do?\n");
310             srcBlend = GL_SRC_ALPHA;
311         }
312         if(dstBlend != GL_ONE_MINUS_SRC_ALPHA) {
313             FIXME("WINED3DRS_EDGEANTIALIAS enabled, but incompatible dst blending param - what to do?\n");
314             dstBlend = GL_ONE_MINUS_SRC_ALPHA;
315         }
316     } else {
317         glDisable(GL_LINE_SMOOTH);
318         checkGLcall("glDisable(GL_LINE_SMOOTH)");
319     }
320
321     TRACE("glBlendFunc src=%x, dst=%x\n", srcBlend, dstBlend);
322     glBlendFunc(srcBlend, dstBlend);
323     checkGLcall("glBlendFunc");
324 }
325
326 static void state_blendfactor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
327     float col[4];
328
329     TRACE("Setting BlendFactor to %d\n", stateblock->renderState[WINED3DRS_BLENDFACTOR]);
330     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_BLENDFACTOR], col);
331     glBlendColor (col[0],col[1],col[2],col[3]);
332     checkGLcall("glBlendColor");
333 }
334
335 static void state_alpha(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
336     int glParm = 0;
337     float ref;
338     BOOL enable_ckey = FALSE;
339
340     IWineD3DSurfaceImpl *surf;
341
342     /* Find out if the texture on the first stage has a ckey set
343      * The alpha state func reads the texture settings, even though alpha and texture are not grouped
344      * together. This is to avoid making a huge alpha+texture+texture stage+ckey block due to the hardly
345      * used WINED3DRS_COLORKEYENABLE state(which is d3d <= 3 only). The texture function will call alpha
346      * in case it finds some texture+colorkeyenable combination which needs extra care.
347      */
348     if(stateblock->textures[0] && stateblock->textureDimensions[0] == GL_TEXTURE_2D) {
349         surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *)stateblock->textures[0])->surfaces[0];
350
351         if(surf->CKeyFlags & DDSD_CKSRCBLT) {
352             const PixelFormatDesc *fmt = getFormatDescEntry(surf->resource.format);
353             /* The surface conversion does not do color keying conversion for surfaces that have an alpha
354              * channel on their own. Likewise, the alpha test shouldn't be set up for color keying if the
355              * surface has alpha bits
356              */
357             if(fmt->alphaMask == 0x00000000) {
358                 enable_ckey = TRUE;
359             }
360         }
361     }
362
363     if(enable_ckey || context->last_was_ckey) {
364         StateTable[STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP)].apply(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context);
365     }
366     context->last_was_ckey = enable_ckey;
367
368     if (stateblock->renderState[WINED3DRS_ALPHATESTENABLE] ||
369         (stateblock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey)) {
370         glEnable(GL_ALPHA_TEST);
371         checkGLcall("glEnable GL_ALPHA_TEST");
372     } else {
373         glDisable(GL_ALPHA_TEST);
374         checkGLcall("glDisable GL_ALPHA_TEST");
375         /* Alpha test is disabled, don't bother setting the params - it will happen on the next
376          * enable call
377          */
378         return;
379     }
380
381     if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey) {
382         glParm = GL_NOTEQUAL;
383         ref = 0.0;
384     } else {
385         ref = ((float) stateblock->renderState[WINED3DRS_ALPHAREF]) / 255.0f;
386         glParm = CompareFunc(stateblock->renderState[WINED3DRS_ALPHAFUNC]);
387     }
388     if(glParm) {
389         glAlphaFunc(glParm, ref);
390         checkGLcall("glAlphaFunc");
391     }
392 }
393
394 static void state_clipping(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
395     DWORD enable  = 0xFFFFFFFF;
396     DWORD disable = 0x00000000;
397
398     if(stateblock->vertexShader) {
399         /* The spec says that opengl clipping planes are disabled when using shaders. Direct3D planes aren't,
400          * so that is an issue. The MacOS ATI driver keeps clipping planes activated with shaders in some
401          * contitions I got sick of tracking down. The shader state handler disables all clip planes because
402          * of that - don't do anything here and keep them disabled
403          */
404         if(stateblock->renderState[WINED3DRS_CLIPPLANEENABLE]) {
405             static BOOL warned = FALSE;
406             if(!warned) {
407                 FIXME("Clipping not supported with vertex shaders\n");
408                 warned = TRUE;
409             }
410         }
411         return;
412     }
413
414     /* TODO: Keep track of previously enabled clipplanes to avoid unneccessary resetting
415      * of already set values
416      */
417
418     /* If enabling / disabling all
419      * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
420      */
421     if (stateblock->renderState[WINED3DRS_CLIPPING]) {
422         enable  = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
423         disable = ~stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
424     } else {
425         disable = 0xffffffff;
426         enable  = 0x00;
427     }
428
429     if (enable & WINED3DCLIPPLANE0)  { glEnable(GL_CLIP_PLANE0);  checkGLcall("glEnable(clip plane 0)"); }
430     if (enable & WINED3DCLIPPLANE1)  { glEnable(GL_CLIP_PLANE1);  checkGLcall("glEnable(clip plane 1)"); }
431     if (enable & WINED3DCLIPPLANE2)  { glEnable(GL_CLIP_PLANE2);  checkGLcall("glEnable(clip plane 2)"); }
432     if (enable & WINED3DCLIPPLANE3)  { glEnable(GL_CLIP_PLANE3);  checkGLcall("glEnable(clip plane 3)"); }
433     if (enable & WINED3DCLIPPLANE4)  { glEnable(GL_CLIP_PLANE4);  checkGLcall("glEnable(clip plane 4)"); }
434     if (enable & WINED3DCLIPPLANE5)  { glEnable(GL_CLIP_PLANE5);  checkGLcall("glEnable(clip plane 5)"); }
435
436     if (disable & WINED3DCLIPPLANE0) { glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)"); }
437     if (disable & WINED3DCLIPPLANE1) { glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)"); }
438     if (disable & WINED3DCLIPPLANE2) { glDisable(GL_CLIP_PLANE2); checkGLcall("glDisable(clip plane 2)"); }
439     if (disable & WINED3DCLIPPLANE3) { glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)"); }
440     if (disable & WINED3DCLIPPLANE4) { glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)"); }
441     if (disable & WINED3DCLIPPLANE5) { glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)"); }
442
443     /** update clipping status */
444     if (enable) {
445         stateblock->clip_status.ClipUnion = 0;
446         stateblock->clip_status.ClipIntersection = 0xFFFFFFFF;
447     } else {
448         stateblock->clip_status.ClipUnion = 0;
449         stateblock->clip_status.ClipIntersection = 0;
450     }
451 }
452
453 static void state_blendop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
454     int glParm = GL_FUNC_ADD;
455
456     if(!GL_SUPPORT(EXT_BLEND_MINMAX)) {
457         WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
458         return;
459     }
460
461     switch ((WINED3DBLENDOP) stateblock->renderState[WINED3DRS_BLENDOP]) {
462         case WINED3DBLENDOP_ADD              : glParm = GL_FUNC_ADD;              break;
463         case WINED3DBLENDOP_SUBTRACT         : glParm = GL_FUNC_SUBTRACT;         break;
464         case WINED3DBLENDOP_REVSUBTRACT      : glParm = GL_FUNC_REVERSE_SUBTRACT; break;
465         case WINED3DBLENDOP_MIN              : glParm = GL_MIN;                   break;
466         case WINED3DBLENDOP_MAX              : glParm = GL_MAX;                   break;
467         default:
468             FIXME("Unrecognized/Unhandled D3DBLENDOP value %d\n", stateblock->renderState[WINED3DRS_BLENDOP]);
469     }
470
471     TRACE("glBlendEquation(%x)\n", glParm);
472     GL_EXTCALL(glBlendEquation(glParm));
473     checkGLcall("glBlendEquation");
474 }
475
476 static void
477 state_specularenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
478     /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
479      * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
480      * specular color. This is wrong:
481      * Separate specular color means the specular colour is maintained separately, whereas
482      * single color means it is merged in. However in both cases they are being used to
483      * some extent.
484      * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
485      * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
486      * running 1.4 yet!
487      *
488      *
489      * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
490      * Instead, we need to setup the FinalCombiner properly.
491      *
492      * The default setup for the FinalCombiner is:
493      *
494      * <variable>       <input>                             <mapping>               <usage>
495      * GL_VARIABLE_A_NV GL_FOG,                             GL_UNSIGNED_IDENTITY_NV GL_ALPHA
496      * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV   GL_UNSIGNED_IDENTITY_NV GL_RGB
497      * GL_VARIABLE_C_NV GL_FOG                              GL_UNSIGNED_IDENTITY_NV GL_RGB
498      * GL_VARIABLE_D_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
499      * GL_VARIABLE_E_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
500      * GL_VARIABLE_F_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
501      * GL_VARIABLE_G_NV GL_SPARE0_NV                        GL_UNSIGNED_IDENTITY_NV GL_ALPHA
502      *
503      * That's pretty much fine as it is, except for variable B, which needs to take
504      * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
505      * whether WINED3DRS_SPECULARENABLE is enabled or not.
506      */
507
508     TRACE("Setting specular enable state\n");
509     /* TODO: Add to the material setting functions */
510     if (stateblock->renderState[WINED3DRS_SPECULARENABLE]) {
511         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*) &stateblock->material.Specular);
512         checkGLcall("glMaterialfv");
513         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
514             glEnable(GL_COLOR_SUM_EXT);
515         } else {
516             TRACE("Specular colors cannot be enabled in this version of opengl\n");
517         }
518         checkGLcall("glEnable(GL_COLOR_SUM)");
519
520         if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
521             GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
522             checkGLcall("glFinalCombinerInputNV()");
523         }
524     } else {
525         float black[4] = {0.0f, 0.0f, 0.0f, 0.0f};
526
527         /* for the case of enabled lighting: */
528         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
529         checkGLcall("glMaterialfv");
530
531         /* for the case of disabled lighting: */
532         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
533             glDisable(GL_COLOR_SUM_EXT);
534         } else {
535             TRACE("Specular colors cannot be disabled in this version of opengl\n");
536         }
537         checkGLcall("glDisable(GL_COLOR_SUM)");
538
539         if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
540             GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
541             checkGLcall("glFinalCombinerInputNV()");
542         }
543     }
544 }
545
546 static void state_texfactor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
547     unsigned int i;
548
549     /* Note the texture color applies to all textures whereas
550      * GL_TEXTURE_ENV_COLOR applies to active only
551      */
552     float col[4];
553     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
554
555     if (!GL_SUPPORT(NV_REGISTER_COMBINERS)) {
556         /* And now the default texture color as well */
557         for (i = 0; i < GL_LIMITS(texture_stages); i++) {
558             /* Note the WINED3DRS value applies to all textures, but GL has one
559              * per texture, so apply it now ready to be used!
560              */
561             if (GL_SUPPORT(ARB_MULTITEXTURE)) {
562                 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
563                 checkGLcall("glActiveTextureARB");
564             } else if (i>0) {
565                 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
566             }
567
568             glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
569             checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
570         }
571     } else {
572         GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
573     }
574 }
575
576 static void
577 renderstate_stencil_twosided(IWineD3DStateBlockImpl *stateblock, GLint face, GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass ) {
578 #if 0 /* Don't use OpenGL 2.0 calls for now */
579             if(GL_EXTCALL(glStencilFuncSeparate) && GL_EXTCALL(glStencilOpSeparate)) {
580                 GL_EXTCALL(glStencilFuncSeparate(face, func, ref, mask));
581                 checkGLcall("glStencilFuncSeparate(...)");
582                 GL_EXTCALL(glStencilOpSeparate(face, stencilFail, depthFail, stencilPass));
583                 checkGLcall("glStencilOpSeparate(...)");
584         }
585             else
586 #endif
587     if(GL_SUPPORT(EXT_STENCIL_TWO_SIDE)) {
588         glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
589         checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
590         GL_EXTCALL(glActiveStencilFaceEXT(face));
591         checkGLcall("glActiveStencilFaceEXT(...)");
592         glStencilFunc(func, ref, mask);
593         checkGLcall("glStencilFunc(...)");
594         glStencilOp(stencilFail, depthFail, stencilPass);
595         checkGLcall("glStencilOp(...)");
596     } else if(GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
597         GL_EXTCALL(glStencilFuncSeparateATI(face, func, ref, mask));
598         checkGLcall("glStencilFuncSeparateATI(...)");
599         GL_EXTCALL(glStencilOpSeparateATI(face, stencilFail, depthFail, stencilPass));
600         checkGLcall("glStencilOpSeparateATI(...)");
601     } else {
602         ERR("Separate (two sided) stencil not supported on this version of opengl. Caps weren't honored?\n");
603     }
604 }
605
606 static void
607 state_stencil(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
608     DWORD onesided_enable = FALSE;
609     DWORD twosided_enable = FALSE;
610     GLint func = GL_ALWAYS;
611     GLint func_ccw = GL_ALWAYS;
612     GLint ref = 0;
613     GLuint mask = 0;
614     GLint stencilFail = GL_KEEP;
615     GLint depthFail = GL_KEEP;
616     GLint stencilPass = GL_KEEP;
617     GLint stencilFail_ccw = GL_KEEP;
618     GLint depthFail_ccw = GL_KEEP;
619     GLint stencilPass_ccw = GL_KEEP;
620
621     /* No stencil test without a stencil buffer */
622     if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) {
623         glDisable(GL_STENCIL_TEST);
624         checkGLcall("glDisable GL_STENCIL_TEST");
625         return;
626     }
627
628     if( stateblock->set.renderState[WINED3DRS_STENCILENABLE] )
629         onesided_enable = stateblock->renderState[WINED3DRS_STENCILENABLE];
630     if( stateblock->set.renderState[WINED3DRS_TWOSIDEDSTENCILMODE] )
631         twosided_enable = stateblock->renderState[WINED3DRS_TWOSIDEDSTENCILMODE];
632     if( stateblock->set.renderState[WINED3DRS_STENCILFUNC] )
633         if( !( func = CompareFunc(stateblock->renderState[WINED3DRS_STENCILFUNC]) ) )
634             func = GL_ALWAYS;
635     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILFUNC] )
636         if( !( func_ccw = CompareFunc(stateblock->renderState[WINED3DRS_CCW_STENCILFUNC]) ) )
637             func = GL_ALWAYS;
638     if( stateblock->set.renderState[WINED3DRS_STENCILREF] )
639         ref = stateblock->renderState[WINED3DRS_STENCILREF];
640     if( stateblock->set.renderState[WINED3DRS_STENCILMASK] )
641         mask = stateblock->renderState[WINED3DRS_STENCILMASK];
642     if( stateblock->set.renderState[WINED3DRS_STENCILFAIL] )
643         stencilFail = StencilOp(stateblock->renderState[WINED3DRS_STENCILFAIL]);
644     if( stateblock->set.renderState[WINED3DRS_STENCILZFAIL] )
645         depthFail = StencilOp(stateblock->renderState[WINED3DRS_STENCILZFAIL]);
646     if( stateblock->set.renderState[WINED3DRS_STENCILPASS] )
647         stencilPass = StencilOp(stateblock->renderState[WINED3DRS_STENCILPASS]);
648     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILFAIL] )
649         stencilFail_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILFAIL]);
650     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILZFAIL] )
651         depthFail_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILZFAIL]);
652     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILPASS] )
653         stencilPass_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILPASS]);
654
655     TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
656           "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
657           "GL_BACK: func: %x, fail %x, zfail %x, zpass %x )\n",
658     onesided_enable, twosided_enable, ref, mask,
659     func, stencilFail, depthFail, stencilPass,
660     func_ccw, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
661
662     if (twosided_enable) {
663         renderstate_stencil_twosided(stateblock, GL_FRONT, func, ref, mask, stencilFail, depthFail, stencilPass);
664         renderstate_stencil_twosided(stateblock, GL_BACK, func_ccw, ref, mask, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
665     } else {
666         if (onesided_enable) {
667             glEnable(GL_STENCIL_TEST);
668             checkGLcall("glEnable GL_STENCIL_TEST");
669             glStencilFunc(func, ref, mask);
670             checkGLcall("glStencilFunc(...)");
671             glStencilOp(stencilFail, depthFail, stencilPass);
672             checkGLcall("glStencilOp(...)");
673         } else {
674             glDisable(GL_STENCIL_TEST);
675             checkGLcall("glDisable GL_STENCIL_TEST");
676         }
677     }
678 }
679
680 static void state_stencilwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
681     if(stateblock->wineD3DDevice->stencilBufferTarget) {
682         glStencilMask(stateblock->renderState[WINED3DRS_STENCILWRITEMASK]);
683     } else {
684         glStencilMask(0);
685     }
686     checkGLcall("glStencilMask");
687 }
688
689 static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
690     /* TODO: Put this into the vertex type block once that is in the state table */
691     BOOL fogenable = stateblock->renderState[WINED3DRS_FOGENABLE];
692     float fogstart, fogend;
693
694     union {
695         DWORD d;
696         float f;
697     } tmpvalue;
698
699     if (!fogenable) {
700         /* No fog? Disable it, and we're done :-) */
701         glDisable(GL_FOG);
702         checkGLcall("glDisable GL_FOG");
703         return;
704     }
705
706     tmpvalue.d = stateblock->renderState[WINED3DRS_FOGSTART];
707     fogstart = tmpvalue.f;
708     tmpvalue.d = stateblock->renderState[WINED3DRS_FOGEND];
709     fogend = tmpvalue.f;
710
711     /* Activate when vertex shaders are in the state table */
712     if(stateblock->vertexShader && ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function &&
713        ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->usesFog) {
714         glFogi(GL_FOG_MODE, GL_LINEAR);
715         checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
716         if (stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) {
717             fogstart = 1.0;
718             fogend = 0.0;
719         }
720         context->last_was_foggy_shader = TRUE;
721     }
722     /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
723      * the system will apply only pixel(=table) fog effects."
724      */
725     else if(stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) {
726         glHint(GL_FOG_HINT, GL_FASTEST);
727         checkGLcall("glHint(GL_FOG_HINT, GL_FASTEST)");
728         context->last_was_foggy_shader = FALSE;
729
730         switch (stateblock->renderState[WINED3DRS_FOGVERTEXMODE]) {
731             /* Processed vertices have their fog factor stored in the specular value. Fall too the none case.
732              * If we are drawing untransformed vertices atm, d3ddevice_set_ortho will update the fog
733              */
734             case WINED3DFOG_EXP:  {
735                 if(!context->last_was_rhw) {
736                     glFogi(GL_FOG_MODE, GL_EXP);
737                     checkGLcall("glFogi(GL_FOG_MODE, GL_EXP");
738                     if(GL_SUPPORT(EXT_FOG_COORD)) {
739                         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
740                         checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
741                     }
742                     break;
743                 }
744             }
745             case WINED3DFOG_EXP2: {
746                 if(!context->last_was_rhw) {
747                     glFogi(GL_FOG_MODE, GL_EXP2);
748                     checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2");
749                     if(GL_SUPPORT(EXT_FOG_COORD)) {
750                         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
751                         checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
752                     }
753                     break;
754                 }
755             }
756             case WINED3DFOG_LINEAR: {
757                 if(!context->last_was_rhw) {
758                     glFogi(GL_FOG_MODE, GL_LINEAR);
759                     checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR");
760                     if(GL_SUPPORT(EXT_FOG_COORD)) {
761                         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
762                         checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
763                     }
764                     break;
765                 }
766             }
767             case WINED3DFOG_NONE: {
768                 /* Both are none? According to msdn the alpha channel of the specular
769                  * color contains a fog factor. Set it in drawStridedSlow.
770                  * Same happens with Vertexfog on transformed vertices
771                  */
772                 if(GL_SUPPORT(EXT_FOG_COORD)) {
773                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
774                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)\n");
775                     glFogi(GL_FOG_MODE, GL_LINEAR);
776                     checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
777                     fogstart = 0xff;
778                     fogend = 0x0;
779                 } else {
780                     /* Disable GL fog, handle this in software in drawStridedSlow */
781                     fogenable = FALSE;
782                 }
783                 break;
784             }
785             default: FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %d\n", stateblock->renderState[WINED3DRS_FOGVERTEXMODE]);
786         }
787     } else {
788         glHint(GL_FOG_HINT, GL_NICEST);
789         checkGLcall("glHint(GL_FOG_HINT, GL_NICEST)");
790         context->last_was_foggy_shader = FALSE;
791
792         switch (stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
793             case WINED3DFOG_EXP:
794                 glFogi(GL_FOG_MODE, GL_EXP);
795                 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP");
796                 if(GL_SUPPORT(EXT_FOG_COORD)) {
797                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
798                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
799                 }
800                 break;
801
802             case WINED3DFOG_EXP2:
803                 glFogi(GL_FOG_MODE, GL_EXP2);
804                 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2");
805                 if(GL_SUPPORT(EXT_FOG_COORD)) {
806                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
807                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
808                 }
809                 break;
810
811             case WINED3DFOG_LINEAR:
812                 glFogi(GL_FOG_MODE, GL_LINEAR);
813                 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR");
814                 if(GL_SUPPORT(EXT_FOG_COORD)) {
815                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
816                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
817                 }
818                 break;
819
820             case WINED3DFOG_NONE:   /* Won't happen */
821             default:
822                 FIXME("Unexpected WINED3DRS_FOGTABLEMODE %d\n", stateblock->renderState[WINED3DRS_FOGTABLEMODE]);
823         }
824     }
825
826     if(fogenable) {
827         glEnable(GL_FOG);
828         checkGLcall("glEnable GL_FOG");
829
830         glFogfv(GL_FOG_START, &fogstart);
831         checkGLcall("glFogf(GL_FOG_START, fogstart");
832         TRACE("Fog Start == %f\n", fogstart);
833
834         glFogfv(GL_FOG_END, &fogend);
835         checkGLcall("glFogf(GL_FOG_END, fogend");
836         TRACE("Fog End == %f\n", fogend);
837     } else {
838         glDisable(GL_FOG);
839         checkGLcall("glDisable GL_FOG");
840     }
841
842     if (GL_SUPPORT(NV_FOG_DISTANCE)) {
843         glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
844     }
845 }
846
847 static void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
848     float col[4];
849     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_FOGCOLOR], col);
850     /* Set the default alpha blend color */
851     glFogfv(GL_FOG_COLOR, &col[0]);
852     checkGLcall("glFog GL_FOG_COLOR");
853 }
854
855 static void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
856     union {
857         DWORD d;
858         float f;
859     } tmpvalue;
860     tmpvalue.d = stateblock->renderState[WINED3DRS_FOGDENSITY];
861     glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
862     checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
863 }
864
865 /* TODO: Merge with primitive type + init_materials()!! */
866 static void state_colormat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
867     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)stateblock->wineD3DDevice;
868     GLenum Parm = 0;
869     WineDirect3DStridedData *diffuse = &device->strided_streams.u.s.diffuse;
870     BOOL isDiffuseSupplied;
871
872     /* Depends on the decoded vertex declaration to read the existence of diffuse data.
873      * The vertex declaration will call this function if the fixed function pipeline is used.
874      */
875
876     if(isStateDirty(context, STATE_VDECL)) {
877         return;
878     }
879
880     isDiffuseSupplied = diffuse->lpData || diffuse->VBO;
881
882     if (isDiffuseSupplied && stateblock->renderState[WINED3DRS_COLORVERTEX]) {
883         TRACE("diff %d, amb %d, emis %d, spec %d\n",
884               stateblock->renderState[WINED3DRS_DIFFUSEMATERIALSOURCE],
885               stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE],
886               stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE],
887               stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE]);
888
889         if (stateblock->renderState[WINED3DRS_DIFFUSEMATERIALSOURCE] == WINED3DMCS_COLOR1) {
890             if (stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1) {
891                 Parm = GL_AMBIENT_AND_DIFFUSE;
892             } else {
893                 Parm = GL_DIFFUSE;
894             }
895         } else if (stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1) {
896             Parm = GL_AMBIENT;
897         } else if (stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1) {
898             Parm = GL_EMISSION;
899         } else if (stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) {
900             Parm = GL_SPECULAR;
901         }
902     }
903
904     /* Nothing changed, return. */
905     if (Parm == context->tracking_parm) return;
906
907     if(!Parm) {
908         glDisable(GL_COLOR_MATERIAL);
909         checkGLcall("glDisable GL_COLOR_MATERIAL");
910     } else {
911         glColorMaterial(GL_FRONT_AND_BACK, Parm);
912         checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
913         glEnable(GL_COLOR_MATERIAL);
914         checkGLcall("glEnable(GL_COLOR_MATERIAL)");
915     }
916
917     /* Apparently calls to glMaterialfv are ignored for properties we're
918      * tracking with glColorMaterial, so apply those here. */
919     switch (context->tracking_parm) {
920         case GL_AMBIENT_AND_DIFFUSE:
921             glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*)&device->updateStateBlock->material.Ambient);
922             glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float*)&device->updateStateBlock->material.Diffuse);
923             checkGLcall("glMaterialfv");
924             break;
925
926         case GL_DIFFUSE:
927             glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float*)&device->updateStateBlock->material.Diffuse);
928             checkGLcall("glMaterialfv");
929             break;
930
931         case GL_AMBIENT:
932             glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*)&device->updateStateBlock->material.Ambient);
933             checkGLcall("glMaterialfv");
934             break;
935
936         case GL_EMISSION:
937             glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float*)&device->updateStateBlock->material.Emissive);
938             checkGLcall("glMaterialfv");
939             break;
940
941         case GL_SPECULAR:
942             /* Only change material color if specular is enabled, otherwise it is set to black */
943             if (device->stateBlock->renderState[WINED3DRS_SPECULARENABLE]) {
944                 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*)&device->updateStateBlock->material.Specular);
945                 checkGLcall("glMaterialfv");
946             } else {
947                 float black[4] = {0.0f, 0.0f, 0.0f, 0.0f};
948                 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
949                 checkGLcall("glMaterialfv");
950             }
951             break;
952     }
953
954     context->tracking_parm = Parm;
955 }
956
957 static void state_linepattern(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
958     union {
959         DWORD                 d;
960         WINED3DLINEPATTERN    lp;
961     } tmppattern;
962     tmppattern.d = stateblock->renderState[WINED3DRS_LINEPATTERN];
963
964     TRACE("Line pattern: repeat %d bits %x\n", tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
965
966     if (tmppattern.lp.wRepeatFactor) {
967         glLineStipple(tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
968         checkGLcall("glLineStipple(repeat, linepattern)");
969         glEnable(GL_LINE_STIPPLE);
970         checkGLcall("glEnable(GL_LINE_STIPPLE);");
971     } else {
972         glDisable(GL_LINE_STIPPLE);
973         checkGLcall("glDisable(GL_LINE_STIPPLE);");
974     }
975 }
976
977 static void state_zbias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
978     union {
979         DWORD d;
980         float f;
981     } tmpvalue;
982
983     if (stateblock->renderState[WINED3DRS_ZBIAS]) {
984         tmpvalue.d = stateblock->renderState[WINED3DRS_ZBIAS];
985         TRACE("ZBias value %f\n", tmpvalue.f);
986         glPolygonOffset(0, -tmpvalue.f);
987         checkGLcall("glPolygonOffset(0, -Value)");
988         glEnable(GL_POLYGON_OFFSET_FILL);
989         checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL);");
990         glEnable(GL_POLYGON_OFFSET_LINE);
991         checkGLcall("glEnable(GL_POLYGON_OFFSET_LINE);");
992         glEnable(GL_POLYGON_OFFSET_POINT);
993         checkGLcall("glEnable(GL_POLYGON_OFFSET_POINT);");
994     } else {
995         glDisable(GL_POLYGON_OFFSET_FILL);
996         checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL);");
997         glDisable(GL_POLYGON_OFFSET_LINE);
998         checkGLcall("glDisable(GL_POLYGON_OFFSET_LINE);");
999         glDisable(GL_POLYGON_OFFSET_POINT);
1000         checkGLcall("glDisable(GL_POLYGON_OFFSET_POINT);");
1001     }
1002 }
1003
1004
1005 static void state_normalize(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1006     if (stateblock->renderState[WINED3DRS_NORMALIZENORMALS]) {
1007         glEnable(GL_NORMALIZE);
1008         checkGLcall("glEnable(GL_NORMALIZE);");
1009     } else {
1010         glDisable(GL_NORMALIZE);
1011         checkGLcall("glDisable(GL_NORMALIZE);");
1012     }
1013 }
1014
1015 static void state_psize(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1016     union {
1017         DWORD d;
1018         float f;
1019     } tmpvalue;
1020
1021     /* FIXME: check that pointSize isn't outside glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize ); or -ve */
1022     tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE];
1023     TRACE("Set point size to %f\n", tmpvalue.f);
1024     glPointSize(tmpvalue.f);
1025     checkGLcall("glPointSize(...);");
1026 }
1027
1028 static void state_psizemin(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1029     union {
1030         DWORD d;
1031         float f;
1032     } tmpvalue;
1033
1034     tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
1035     if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
1036         GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, tmpvalue.f);
1037         checkGLcall("glPointParameterfARB(...");
1038     }
1039     else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
1040         GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, tmpvalue.f);
1041         checkGLcall("glPointParameterfEXT(...);");
1042     } else if(tmpvalue.f != 1.0) {
1043         FIXME("WINED3DRS_POINTSIZE_MIN not supported on this opengl, value is %f\n", tmpvalue.f);
1044     }
1045 }
1046
1047 static void state_psizemax(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1048     union {
1049         DWORD d;
1050         float f;
1051     } tmpvalue;
1052
1053     tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
1054     if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
1055         GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, tmpvalue.f);
1056         checkGLcall("glPointParameterfARB(...");
1057     }
1058     else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
1059         GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, tmpvalue.f);
1060         checkGLcall("glPointParameterfEXT(...);");
1061     } else if(tmpvalue.f != 64.0) {
1062         FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f);
1063     }
1064 }
1065
1066 static void state_pscale(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1067     /* TODO: Group this with the viewport */
1068     /*
1069      * POINTSCALEENABLE controls how point size value is treated. If set to
1070      * true, the point size is scaled with respect to height of viewport.
1071      * When set to false point size is in pixels.
1072      *
1073      * http://msdn.microsoft.com/library/en-us/directx9_c/point_sprites.asp
1074      */
1075
1076     /* Default values */
1077     GLfloat att[3] = {1.0f, 0.0f, 0.0f};
1078
1079     /*
1080      * Minimum valid point size for OpenGL is 1.0f. For Direct3D it is 0.0f.
1081      * This means that OpenGL will clamp really small point sizes to 1.0f.
1082      * To correct for this we need to multiply by the scale factor when sizes
1083      * are less than 1.0f. scale_factor =  1.0f / point_size.
1084      */
1085     GLfloat pointSize = *((float*)&stateblock->renderState[WINED3DRS_POINTSIZE]);
1086     if(pointSize > 0.0f) {
1087         GLfloat scaleFactor;
1088
1089         if(pointSize < 1.0f) {
1090             scaleFactor = pointSize * pointSize;
1091         } else {
1092             scaleFactor = 1.0f;
1093         }
1094
1095         if(stateblock->renderState[WINED3DRS_POINTSCALEENABLE]) {
1096             att[0] = *((float*)&stateblock->renderState[WINED3DRS_POINTSCALE_A]) /
1097                     (stateblock->viewport.Height * stateblock->viewport.Height * scaleFactor);
1098             att[1] = *((float*)&stateblock->renderState[WINED3DRS_POINTSCALE_B]) /
1099                     (stateblock->viewport.Height * stateblock->viewport.Height * scaleFactor);
1100             att[2] = *((float*)&stateblock->renderState[WINED3DRS_POINTSCALE_C]) /
1101                     (stateblock->viewport.Height * stateblock->viewport.Height * scaleFactor);
1102         }
1103     }
1104
1105     if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
1106         GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
1107         checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...");
1108     }
1109     else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
1110         GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
1111         checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...");
1112     } else {
1113         TRACE("POINT_PARAMETERS not supported in this version of opengl\n");
1114     }
1115 }
1116
1117 static void state_colorwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1118     DWORD Value = stateblock->renderState[WINED3DRS_COLORWRITEENABLE];
1119
1120     TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
1121         Value & WINED3DCOLORWRITEENABLE_RED   ? 1 : 0,
1122         Value & WINED3DCOLORWRITEENABLE_GREEN ? 1 : 0,
1123         Value & WINED3DCOLORWRITEENABLE_BLUE  ? 1 : 0,
1124         Value & WINED3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1125     glColorMask(Value & WINED3DCOLORWRITEENABLE_RED   ? GL_TRUE : GL_FALSE,
1126                 Value & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1127                 Value & WINED3DCOLORWRITEENABLE_BLUE  ? GL_TRUE : GL_FALSE,
1128                 Value & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1129     checkGLcall("glColorMask(...)");
1130
1131     /* depends on WINED3DRS_COLORWRITEENABLE. */
1132     if(stateblock->renderState[WINED3DRS_COLORWRITEENABLE1] != 0x0000000F ||
1133        stateblock->renderState[WINED3DRS_COLORWRITEENABLE2] != 0x0000000F ||
1134        stateblock->renderState[WINED3DRS_COLORWRITEENABLE3] != 0x0000000F ) {
1135         ERR("(WINED3DRS_COLORWRITEENABLE1/2/3,%d,%d,%d) not yet implemented. Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n",
1136             stateblock->renderState[WINED3DRS_COLORWRITEENABLE1],
1137             stateblock->renderState[WINED3DRS_COLORWRITEENABLE2],
1138             stateblock->renderState[WINED3DRS_COLORWRITEENABLE3]);
1139     }
1140 }
1141
1142 static void state_localviewer(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1143     if(stateblock->renderState[WINED3DRS_LOCALVIEWER]) {
1144         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1145         checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1146     } else {
1147         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1148         checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
1149     }
1150 }
1151
1152 static void state_lastpixel(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1153     if(stateblock->renderState[WINED3DRS_LASTPIXEL]) {
1154         TRACE("Last Pixel Drawing Enabled\n");
1155     } else {
1156         FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1157     }
1158 }
1159
1160 static void state_pointsprite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1161     unsigned int i;
1162     int val;
1163
1164     /* TODO: NV_POINT_SPRITE */
1165     if (!GL_SUPPORT(ARB_POINT_SPRITE)) {
1166         TRACE("Point sprites not supported\n");
1167         return;
1168     }
1169
1170     if (stateblock->renderState[WINED3DRS_POINTSPRITEENABLE]) {
1171         val = GL_TRUE;
1172     } else {
1173         val = GL_FALSE;
1174     }
1175
1176     for (i = 0; i < GL_LIMITS(texture_stages); i++) {
1177         /* Note the WINED3DRS value applies to all textures, but GL has one
1178          * per texture, so apply it now ready to be used!
1179          */
1180         if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1181             GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
1182             checkGLcall("glActiveTextureARB");
1183         } else if (i==1) {
1184             FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1185             break;
1186         }
1187
1188         glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, val);
1189         checkGLcall((val?"glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)":
1190                          "glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE)"));
1191     }
1192 }
1193
1194 static void state_wrap(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1195     /**
1196      http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/texture/
1197      http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/graphics/programmingguide/FixedFunction/Textures/texturewrapping.asp
1198      http://www.gamedev.net/reference/programming/features/rendererdll3/page2.asp
1199      Descussion that ways to turn on WRAPing to solve an opengl conversion problem.
1200      http://www.flipcode.org/cgi-bin/fcmsg.cgi?thread_show=10248
1201
1202      so far as I can tell, wrapping and texture-coordinate generate go hand in hand,
1203      */
1204     TRACE("Stub\n");
1205     if(stateblock->renderState[WINED3DRS_WRAP0] ||
1206        stateblock->renderState[WINED3DRS_WRAP1] ||
1207        stateblock->renderState[WINED3DRS_WRAP2] ||
1208        stateblock->renderState[WINED3DRS_WRAP3] ||
1209        stateblock->renderState[WINED3DRS_WRAP4] ||
1210        stateblock->renderState[WINED3DRS_WRAP5] ||
1211        stateblock->renderState[WINED3DRS_WRAP6] ||
1212        stateblock->renderState[WINED3DRS_WRAP7] ||
1213        stateblock->renderState[WINED3DRS_WRAP8] ||
1214        stateblock->renderState[WINED3DRS_WRAP9] ||
1215        stateblock->renderState[WINED3DRS_WRAP10] ||
1216        stateblock->renderState[WINED3DRS_WRAP11] ||
1217        stateblock->renderState[WINED3DRS_WRAP12] ||
1218        stateblock->renderState[WINED3DRS_WRAP13] ||
1219        stateblock->renderState[WINED3DRS_WRAP14] ||
1220        stateblock->renderState[WINED3DRS_WRAP15] ) {
1221         ERR("(WINED3DRS_WRAP0) Texture wraping not yet supported\n");
1222     }
1223 }
1224
1225 static void state_multisampleaa(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1226     if( GL_SUPPORT(ARB_MULTISAMPLE) ) {
1227         if(stateblock->renderState[WINED3DRS_MULTISAMPLEANTIALIAS]) {
1228             glEnable(GL_MULTISAMPLE_ARB);
1229             checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1230         } else {
1231             glDisable(GL_MULTISAMPLE_ARB);
1232             checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1233         }
1234     } else {
1235         if(stateblock->renderState[WINED3DRS_MULTISAMPLEANTIALIAS]) {
1236             ERR("Multisample antialiasing not supported by gl\n");
1237         }
1238     }
1239 }
1240
1241 static void state_scissor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1242     if(stateblock->renderState[WINED3DRS_SCISSORTESTENABLE]) {
1243         glEnable(GL_SCISSOR_TEST);
1244         checkGLcall("glEnable(GL_SCISSOR_TEST)");
1245     } else {
1246         glDisable(GL_SCISSOR_TEST);
1247         checkGLcall("glDisable(GL_SCISSOR_TEST)");
1248     }
1249 }
1250
1251 static void state_depthbias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1252     union {
1253         DWORD d;
1254         float f;
1255     } tmpvalue;
1256
1257     if(stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS] ||
1258        stateblock->renderState[WINED3DRS_DEPTHBIAS]) {
1259         tmpvalue.d = stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS];
1260         glEnable(GL_POLYGON_OFFSET_FILL);
1261         checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
1262         glPolygonOffset(tmpvalue.f, *((float*)&stateblock->renderState[WINED3DRS_DEPTHBIAS]));
1263         checkGLcall("glPolygonOffset(...)");
1264     } else {
1265         glDisable(GL_POLYGON_OFFSET_FILL);
1266         checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
1267     }
1268 }
1269
1270 static void state_perspective(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1271     if (stateblock->renderState[WINED3DRS_TEXTUREPERSPECTIVE]) {
1272         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1273         checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)");
1274     } else {
1275         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1276         checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)");
1277     }
1278 }
1279
1280 static void state_stippledalpha(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1281     TRACE("Stub\n");
1282     if (stateblock->renderState[WINED3DRS_STIPPLEDALPHA])
1283         ERR(" Stippled Alpha not supported yet.\n");
1284 }
1285
1286 static void state_antialias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1287     TRACE("Stub\n");
1288     if (stateblock->renderState[WINED3DRS_ANTIALIAS])
1289         ERR(" Antialias not supported yet.\n");
1290 }
1291
1292 static void state_multisampmask(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1293     TRACE("Stub\n");
1294     if (stateblock->renderState[WINED3DRS_MULTISAMPLEMASK] != 0xFFFFFFFF)
1295         ERR("(WINED3DRS_MULTISAMPLEMASK,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_MULTISAMPLEMASK]);
1296 }
1297
1298 static void state_patchedgestyle(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1299     TRACE("Stub\n");
1300     if (stateblock->renderState[WINED3DRS_PATCHEDGESTYLE] != WINED3DPATCHEDGE_DISCRETE)
1301         ERR("(WINED3DRS_PATCHEDGESTYLE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_PATCHEDGESTYLE]);
1302 }
1303
1304 static void state_patchsegments(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1305     union {
1306         DWORD d;
1307         float f;
1308     } tmpvalue;
1309     tmpvalue.f = 1.0f;
1310
1311     TRACE("Stub\n");
1312     if (stateblock->renderState[WINED3DRS_PATCHSEGMENTS] != tmpvalue.d)
1313         ERR("(WINED3DRS_PATCHSEGMENTS,%d) not yet implemented\n", tmpvalue.d);
1314 }
1315
1316 static void state_positiondegree(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1317     TRACE("Stub\n");
1318     if (stateblock->renderState[WINED3DRS_POSITIONDEGREE] != WINED3DDEGREE_CUBIC)
1319         ERR("(WINED3DRS_POSITIONDEGREE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_POSITIONDEGREE]);
1320 }
1321
1322 static void state_normaldegree(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1323     TRACE("Stub\n");
1324     if (stateblock->renderState[WINED3DRS_NORMALDEGREE] != WINED3DDEGREE_LINEAR)
1325         ERR("(WINED3DRS_NORMALDEGREE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_NORMALDEGREE]);
1326 }
1327
1328 static void state_tessellation(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1329     TRACE("Stub\n");
1330     if(stateblock->renderState[WINED3DRS_ENABLEADAPTIVETESSELLATION])
1331         FIXME("(WINED3DRS_ENABLEADAPTIVETESSELLATION,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_ENABLEADAPTIVETESSELLATION]);
1332 }
1333
1334
1335 static void state_srgbwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1336     if(stateblock->renderState[WINED3DRS_SRGBWRITEENABLE])
1337         ERR("Render state WINED3DRS_SRGBWRITEENABLE not yet implemented\n");
1338 }
1339
1340 static void state_seperateblend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1341     TRACE("Stub\n");
1342     if(stateblock->renderState[WINED3DRS_SEPARATEALPHABLENDENABLE])
1343         FIXME("(WINED3DRS_SEPARATEALPHABLENDENABLE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_SEPARATEALPHABLENDENABLE]);
1344 }
1345
1346 static void state_wrapu(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1347     if(stateblock->renderState[WINED3DRS_WRAPU]) {
1348         FIXME("Render state WINED3DRS_WRAPU not implemented yet\n");
1349     }
1350 }
1351
1352 static void state_wrapv(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1353     if(stateblock->renderState[WINED3DRS_WRAPV]) {
1354         FIXME("Render state WINED3DRS_WRAPV not implemented yet\n");
1355     }
1356 }
1357
1358 static void state_monoenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1359     if(stateblock->renderState[WINED3DRS_MONOENABLE]) {
1360         FIXME("Render state WINED3DRS_MONOENABLE not implemented yet\n");
1361     }
1362 }
1363
1364 static void state_rop2(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1365     if(stateblock->renderState[WINED3DRS_ROP2]) {
1366         FIXME("Render state WINED3DRS_ROP2 not implemented yet\n");
1367     }
1368 }
1369
1370 static void state_planemask(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1371     if(stateblock->renderState[WINED3DRS_PLANEMASK]) {
1372         FIXME("Render state WINED3DRS_PLANEMASK not implemented yet\n");
1373     }
1374 }
1375
1376 static void state_subpixel(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1377     if(stateblock->renderState[WINED3DRS_SUBPIXEL]) {
1378         FIXME("Render state WINED3DRS_SUBPIXEL not implemented yet\n");
1379     }
1380 }
1381
1382 static void state_subpixelx(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1383     if(stateblock->renderState[WINED3DRS_SUBPIXELX]) {
1384         FIXME("Render state WINED3DRS_SUBPIXELX not implemented yet\n");
1385     }
1386 }
1387
1388 static void state_stippleenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1389     if(stateblock->renderState[WINED3DRS_STIPPLEENABLE]) {
1390         FIXME("Render state WINED3DRS_STIPPLEENABLE not implemented yet\n");
1391     }
1392 }
1393
1394 static void state_bordercolor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1395     if(stateblock->renderState[WINED3DRS_BORDERCOLOR]) {
1396         FIXME("Render state WINED3DRS_BORDERCOLOR not implemented yet\n");
1397     }
1398 }
1399
1400 static void state_mipmaplodbias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1401     if(stateblock->renderState[WINED3DRS_MIPMAPLODBIAS]) {
1402         FIXME("Render state WINED3DRS_MIPMAPLODBIAS not implemented yet\n");
1403     }
1404 }
1405
1406 static void state_anisotropy(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1407     if(stateblock->renderState[WINED3DRS_ANISOTROPY]) {
1408         FIXME("Render state WINED3DRS_ANISOTROPY not implemented yet\n");
1409     }
1410 }
1411
1412 static void state_flushbatch(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1413     if(stateblock->renderState[WINED3DRS_FLUSHBATCH]) {
1414         FIXME("Render state WINED3DRS_FLUSHBATCH not implemented yet\n");
1415     }
1416 }
1417
1418 static void state_translucentsi(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1419     if(stateblock->renderState[WINED3DRS_TRANSLUCENTSORTINDEPENDENT]) {
1420         FIXME("Render state WINED3DRS_TRANSLUCENTSORTINDEPENDENT not implemented yet\n");
1421     }
1422 }
1423
1424 static void state_extents(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1425     if(stateblock->renderState[WINED3DRS_EXTENTS]) {
1426         FIXME("Render state WINED3DRS_EXTENTS not implemented yet\n");
1427     }
1428 }
1429
1430 static void state_ckeyblend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1431     if(stateblock->renderState[WINED3DRS_COLORKEYBLENDENABLE]) {
1432         FIXME("Render state WINED3DRS_COLORKEYBLENDENABLE not implemented yet\n");
1433     }
1434 }
1435
1436 /* Activates the texture dimension according to the bound D3D texture.
1437  * Does not care for the colorop or correct gl texture unit(when using nvrc)
1438  * Requires the caller to activate the correct unit before
1439  */
1440 static void activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock) {
1441     if(stateblock->textures[stage]) {
1442         glDisable(GL_TEXTURE_1D);
1443         checkGLcall("glDisable(GL_TEXTURE_1D)");
1444         switch(stateblock->textureDimensions[stage]) {
1445             case GL_TEXTURE_2D:
1446                 glDisable(GL_TEXTURE_3D);
1447                 checkGLcall("glDisable(GL_TEXTURE_3D)");
1448                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1449                 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1450                 glEnable(GL_TEXTURE_2D);
1451                 checkGLcall("glEnable(GL_TEXTURE_2D)");
1452                 break;
1453             case GL_TEXTURE_3D:
1454                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1455                 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1456                 glDisable(GL_TEXTURE_2D);
1457                 checkGLcall("glDisable(GL_TEXTURE_2D)");
1458                 glEnable(GL_TEXTURE_3D);
1459                 checkGLcall("glEnable(GL_TEXTURE_3D)");
1460                 break;
1461             case GL_TEXTURE_CUBE_MAP_ARB:
1462                 glDisable(GL_TEXTURE_2D);
1463                 checkGLcall("glDisable(GL_TEXTURE_2D)");
1464                 glDisable(GL_TEXTURE_3D);
1465                 checkGLcall("glDisable(GL_TEXTURE_3D)");
1466                 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
1467                 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
1468                 break;
1469         }
1470     } else {
1471         glDisable(GL_TEXTURE_2D);
1472         checkGLcall("glDisable(GL_TEXTURE_2D)");
1473         glDisable(GL_TEXTURE_3D);
1474         checkGLcall("glDisable(GL_TEXTURE_3D)");
1475         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1476         checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1477         glEnable(GL_TEXTURE_1D);
1478         checkGLcall("glEnable(GL_TEXTURE_1D)");
1479         /* Binding textures is done by samplers. A dummy texture will be bound */
1480     }
1481 }
1482
1483 static void tex_colorop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1484     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1485     DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
1486
1487     TRACE("Setting color op for stage %d\n", stage);
1488
1489     if (stateblock->pixelShader && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE &&
1490         ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
1491         /* Using a pixel shader? Don't care for anything here, the shader applying does it */
1492         return;
1493     }
1494
1495     if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
1496
1497     if (mapped_stage != -1) {
1498         if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1499             if (mapped_stage >= GL_LIMITS(sampler_stages)) {
1500                 if (stateblock->textureState[stage][WINED3DTSS_COLOROP] != WINED3DTOP_DISABLE &&
1501                         stateblock->textureState[stage][WINED3DTSS_COLOROP] != 0) {
1502                     FIXME("Attempt to enable unsupported stage!\n");
1503                 }
1504                 return;
1505             }
1506             GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
1507             checkGLcall("glActiveTextureARB");
1508         } else if (stage > 0) {
1509             WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1510             return;
1511         }
1512     }
1513
1514     if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1515         if(stateblock->lowest_disabled_stage > 0) {
1516             glEnable(GL_REGISTER_COMBINERS_NV);
1517             GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, stateblock->lowest_disabled_stage));
1518         } else {
1519             glDisable(GL_REGISTER_COMBINERS_NV);
1520         }
1521     }
1522     if(stage >= stateblock->lowest_disabled_stage) {
1523         TRACE("Stage disabled\n");
1524         if (mapped_stage != -1) {
1525             /* Disable everything here */
1526             glDisable(GL_TEXTURE_1D);
1527             checkGLcall("glDisable(GL_TEXTURE_1D)");
1528             glDisable(GL_TEXTURE_2D);
1529             checkGLcall("glDisable(GL_TEXTURE_2D)");
1530             glDisable(GL_TEXTURE_3D);
1531             checkGLcall("glDisable(GL_TEXTURE_3D)");
1532             glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1533             checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1534         }
1535         /* All done */
1536         return;
1537     }
1538
1539     /* The sampler will also activate the correct texture dimensions, so no need to do it here
1540      * if the sampler for this stage is dirty
1541      */
1542     if(!isStateDirty(context, STATE_SAMPLER(stage))) {
1543         if (mapped_stage != -1) activate_dimensions(stage, stateblock);
1544     }
1545
1546     /* Set the texture combiners */
1547     if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1548         set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
1549                          stateblock->textureState[stage][WINED3DTSS_COLOROP],
1550                          stateblock->textureState[stage][WINED3DTSS_COLORARG1],
1551                          stateblock->textureState[stage][WINED3DTSS_COLORARG2],
1552                          stateblock->textureState[stage][WINED3DTSS_COLORARG0],
1553                          mapped_stage);
1554     } else {
1555         set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
1556                     stateblock->textureState[stage][WINED3DTSS_COLOROP],
1557                     stateblock->textureState[stage][WINED3DTSS_COLORARG1],
1558                     stateblock->textureState[stage][WINED3DTSS_COLORARG2],
1559                     stateblock->textureState[stage][WINED3DTSS_COLORARG0]);
1560     }
1561 }
1562
1563 static void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1564     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1565     DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
1566     DWORD op, arg1, arg2, arg0;
1567
1568     TRACE("Setting alpha op for stage %d\n", stage);
1569     /* Do not care for enabled / disabled stages, just assign the settigns. colorop disables / enables required stuff */
1570     if (mapped_stage != -1) {
1571         if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1572             if (stage >= GL_LIMITS(sampler_stages)) {
1573                 if (stateblock->textureState[stage][WINED3DTSS_COLOROP] != WINED3DTOP_DISABLE &&
1574                         stateblock->textureState[stage][WINED3DTSS_COLOROP] != 0) {
1575                     FIXME("Attempt to enable unsupported stage!\n");
1576                 }
1577                 return;
1578             }
1579             GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
1580             checkGLcall("glActiveTextureARB");
1581         } else if (stage > 0) {
1582             /* We can't do anything here */
1583             WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1584             return;
1585         }
1586     }
1587
1588     op = stateblock->textureState[stage][WINED3DTSS_ALPHAOP];
1589     arg1 = stateblock->textureState[stage][WINED3DTSS_ALPHAARG1];
1590     arg2 = stateblock->textureState[stage][WINED3DTSS_ALPHAARG2];
1591     arg0 = stateblock->textureState[stage][WINED3DTSS_ALPHAARG0];
1592
1593     if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && stage == 0 &&
1594        stateblock->textures[0] && stateblock->textureDimensions[0] == GL_TEXTURE_2D) {
1595         IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *) stateblock->textures[0])->surfaces[0];
1596
1597         if(surf->CKeyFlags & DDSD_CKSRCBLT &&
1598            getFormatDescEntry(surf->resource.format)->alphaMask == 0x00000000) {
1599
1600             /* Color keying needs to pass alpha values from the texture through to have the alpha test work properly.
1601              * On the other hand applications can still use texture combiners apparently. This code takes care that apps
1602              * cannot remove the texture's alpha channel entirely.
1603              *
1604              * The fixup is required for Prince of Persia 3D(prison bars), while Moto racer 2 requires D3DTOP_MODULATE to work
1605              * on color keyed surfaces.
1606              *
1607              * What to do with multitexturing? So far no app has been found that uses color keying with multitexturing
1608              */
1609             if(op == WINED3DTOP_DISABLE) op = WINED3DTOP_SELECTARG1;
1610             if(op == WINED3DTOP_SELECTARG1) arg1 = WINED3DTA_TEXTURE;
1611             else if(op == WINED3DTOP_SELECTARG2) arg2 = WINED3DTA_TEXTURE;
1612         }
1613     }
1614
1615     TRACE("Setting alpha op for stage %d\n", stage);
1616     if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1617         set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
1618                          op, arg1, arg2, arg0,
1619                          mapped_stage);
1620     } else {
1621         set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
1622                     op, arg1, arg2, arg0);
1623     }
1624 }
1625
1626 static void transform_texture(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1627     DWORD texUnit = state - STATE_TRANSFORM(WINED3DTS_TEXTURE0);
1628
1629     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1630         if(texUnit >= GL_LIMITS(sampler_stages)) {
1631             return;
1632         }
1633         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stateblock->wineD3DDevice->texUnitMap[texUnit]));
1634         checkGLcall("glActiveTextureARB");
1635     } else if (texUnit > 0) {
1636         /* We can't do anything here */
1637         WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1638         return;
1639     }
1640
1641     set_texture_matrix((float *)&stateblock->transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0],
1642                         stateblock->textureState[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS],
1643                         (stateblock->textureState[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xFFFF0000) != WINED3DTSS_TCI_PASSTHRU);
1644
1645 }
1646
1647 static void loadVertexData(IWineD3DStateBlockImpl *stateblock, WineDirect3DVertexStridedData *sd);
1648
1649 static void tex_coordindex(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1650     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1651     DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
1652
1653     if (mapped_stage == -1) {
1654         TRACE("No texture unit mapped to stage %d. Skipping texture coordinates.\n", stage);
1655         return;
1656     }
1657
1658     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1659         if(stage >= GL_LIMITS(sampler_stages)) {
1660             return;
1661         }
1662         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
1663         checkGLcall("glActiveTextureARB");
1664     } else if (stage > 0) {
1665         /* We can't do anything here */
1666         WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1667         return;
1668     }
1669
1670     /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
1671      *
1672      * FIXME: From MSDN: The WINED3DTSS_TCI_* flags are mutually exclusive. If you include
1673      * one flag, you can still specify an index value, which the system uses to
1674      * determine the texture wrapping mode.
1675      * eg. SetTextureStageState( 0, WINED3DTSS_TEXCOORDINDEX, WINED3DTSS_TCI_CAMERASPACEPOSITION | 1 );
1676      * means use the vertex position (camera-space) as the input texture coordinates
1677      * for this texture stage, and the wrap mode set in the WINED3DRS_WRAP1 render
1678      * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up
1679      * to the TEXCOORDINDEX value
1680      */
1681
1682     /*
1683      * Be careful the value of the mask 0xF0000 come from d3d8types.h infos
1684      */
1685     switch (stateblock->textureState[stage][WINED3DTSS_TEXCOORDINDEX] & 0xFFFF0000) {
1686     case WINED3DTSS_TCI_PASSTHRU:
1687         /*Use the specified texture coordinates contained within the vertex format. This value resolves to zero.*/
1688         glDisable(GL_TEXTURE_GEN_S);
1689         glDisable(GL_TEXTURE_GEN_T);
1690         glDisable(GL_TEXTURE_GEN_R);
1691         glDisable(GL_TEXTURE_GEN_Q);
1692         checkGLcall("glDisable(GL_TEXTURE_GEN_S,T,R,Q)");
1693         break;
1694
1695     case WINED3DTSS_TCI_CAMERASPACEPOSITION:
1696         /* CameraSpacePosition means use the vertex position, transformed to camera space,
1697          * as the input texture coordinates for this stage's texture transformation. This
1698          * equates roughly to EYE_LINEAR
1699          */
1700         {
1701             float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
1702             float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
1703             float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
1704             float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
1705             TRACE("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set eye plane\n");
1706
1707             glMatrixMode(GL_MODELVIEW);
1708             glPushMatrix();
1709             glLoadIdentity();
1710             glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
1711             glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
1712             glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
1713             glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
1714             glPopMatrix();
1715
1716             TRACE("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set GL_TEXTURE_GEN_x and GL_x, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR\n");
1717             glEnable(GL_TEXTURE_GEN_S);
1718             checkGLcall("glEnable(GL_TEXTURE_GEN_S);");
1719             glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
1720             checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
1721             glEnable(GL_TEXTURE_GEN_T);
1722             checkGLcall("glEnable(GL_TEXTURE_GEN_T);");
1723             glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
1724             checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
1725             glEnable(GL_TEXTURE_GEN_R);
1726             checkGLcall("glEnable(GL_TEXTURE_GEN_R);");
1727             glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
1728             checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
1729         }
1730         break;
1731
1732     case WINED3DTSS_TCI_CAMERASPACENORMAL:
1733         {
1734             if (GL_SUPPORT(NV_TEXGEN_REFLECTION)) {
1735                 float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
1736                 float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
1737                 float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
1738                 float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
1739                 TRACE("WINED3DTSS_TCI_CAMERASPACENORMAL - Set eye plane\n");
1740
1741                 glMatrixMode(GL_MODELVIEW);
1742                 glPushMatrix();
1743                 glLoadIdentity();
1744                 glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
1745                 glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
1746                 glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
1747                 glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
1748                 glPopMatrix();
1749
1750                 glEnable(GL_TEXTURE_GEN_S);
1751                 checkGLcall("glEnable(GL_TEXTURE_GEN_S);");
1752                 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
1753                 checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
1754                 glEnable(GL_TEXTURE_GEN_T);
1755                 checkGLcall("glEnable(GL_TEXTURE_GEN_T);");
1756                 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
1757                 checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
1758                 glEnable(GL_TEXTURE_GEN_R);
1759                 checkGLcall("glEnable(GL_TEXTURE_GEN_R);");
1760                 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
1761                 checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
1762             }
1763         }
1764         break;
1765
1766     case WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
1767         {
1768             if (GL_SUPPORT(NV_TEXGEN_REFLECTION)) {
1769             float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
1770             float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
1771             float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
1772             float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
1773             TRACE("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set eye plane\n");
1774
1775             glMatrixMode(GL_MODELVIEW);
1776             glPushMatrix();
1777             glLoadIdentity();
1778             glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
1779             glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
1780             glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
1781             glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
1782             glPopMatrix();
1783
1784             glEnable(GL_TEXTURE_GEN_S);
1785             checkGLcall("glEnable(GL_TEXTURE_GEN_S);");
1786             glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
1787             checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
1788             glEnable(GL_TEXTURE_GEN_T);
1789             checkGLcall("glEnable(GL_TEXTURE_GEN_T);");
1790             glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
1791             checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
1792             glEnable(GL_TEXTURE_GEN_R);
1793             checkGLcall("glEnable(GL_TEXTURE_GEN_R);");
1794             glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
1795             checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
1796             }
1797         }
1798         break;
1799
1800     /* Unhandled types: */
1801     default:
1802         /* Todo: */
1803         /* ? disable GL_TEXTURE_GEN_n ? */
1804         glDisable(GL_TEXTURE_GEN_S);
1805         glDisable(GL_TEXTURE_GEN_T);
1806         glDisable(GL_TEXTURE_GEN_R);
1807         glDisable(GL_TEXTURE_GEN_Q);
1808         FIXME("Unhandled WINED3DTSS_TEXCOORDINDEX %x\n", stateblock->textureState[stage][WINED3DTSS_TEXCOORDINDEX]);
1809         break;
1810     }
1811
1812     /* Update the texture matrix */
1813     if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + stage))) {
1814         transform_texture(STATE_TRANSFORM(WINED3DTS_TEXTURE0 + stage), stateblock, context);
1815     }
1816
1817     if(!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded) {
1818         /* Reload the arrays if we are using fixed function arrays to reflect the selected coord input
1819          * source. Call loadVertexData directly because there is no need to reparse the vertex declaration
1820          * and do all the things linked to it
1821          * TODO: Tidy that up to reload only the arrays of the changed unit
1822          */
1823         loadVertexData(stateblock, &stateblock->wineD3DDevice->strided_streams);
1824     }
1825 }
1826
1827 static void tex_bumpenvlscale(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1828     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1829     union {
1830         DWORD d;
1831         float f;
1832     } tmpvalue;
1833
1834     tmpvalue.d = stateblock->textureState[stage][WINED3DTSS_BUMPENVLSCALE];
1835     if(tmpvalue.f != 0.0) {
1836         ERR("WINED3DTSS_BUMPENVLSCALE not supported yet\n");
1837     }
1838 }
1839
1840 static void tex_bumpenvloffset(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1841     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1842     union {
1843         DWORD d;
1844         float f;
1845     } tmpvalue;
1846
1847     tmpvalue.d = stateblock->textureState[stage][WINED3DTSS_BUMPENVLOFFSET];
1848     if(tmpvalue.f != 0.0) {
1849         ERR("WINED3DTSS_BUMPENVLOFFSET not supported yet\n");
1850     }
1851 }
1852
1853 static void tex_resultarg(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1854     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1855
1856     if(stage >= GL_LIMITS(texture_stages)) {
1857         return;
1858     }
1859
1860     if(stateblock->textureState[stage][WINED3DTSS_RESULTARG] != WINED3DTA_CURRENT) {
1861         ERR("WINED3DTSS_RESULTARG not supported yet\n");
1862     }
1863 }
1864
1865 static void sampler(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1866     DWORD sampler = state - STATE_SAMPLER(0);
1867     DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
1868     union {
1869         float f;
1870         DWORD d;
1871     } tmpvalue;
1872
1873     TRACE("Sampler: %d\n", sampler);
1874     /* Enabling and disabling texture dimensions is done by texture stage state / pixel shader setup, this function
1875      * only has to bind textures and set the per texture states
1876      */
1877
1878     if (mapped_stage == -1) {
1879         TRACE("No sampler mapped to stage %d. Returning.\n", sampler);
1880         return;
1881     }
1882
1883     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1884         if(sampler >= GL_LIMITS(sampler_stages)) {
1885             return;
1886         }
1887         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
1888         checkGLcall("glActiveTextureARB");
1889     } else if (sampler > 0) {
1890         /* We can't do anything here */
1891         WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1892         return;
1893     }
1894
1895     if(stateblock->textures[sampler]) {
1896         BOOL texIsPow2 = FALSE;
1897
1898         /* The fixed function np2 texture emulation uses the texture matrix to fix up the coordinates
1899          * IWineD3DBaseTexture::ApplyStateChanges multiplies the set matrix with a fixup matrix. Before the
1900          * scaling is reapplied or removed, the texture matrix has to be reapplied
1901          */
1902         if(!GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) && sampler < MAX_TEXTURES) {
1903             if(stateblock->textureDimensions[sampler] == GL_TEXTURE_2D) {
1904                 if(((IWineD3DTextureImpl *) stateblock->textures[sampler])->pow2scalingFactorX != 1.0 ||
1905                    ((IWineD3DTextureImpl *) stateblock->textures[sampler])->pow2scalingFactorY != 1.0 ) {
1906                     texIsPow2 = TRUE;
1907                 }
1908             } else if(stateblock->textureDimensions[sampler] == GL_TEXTURE_CUBE_MAP_ARB) {
1909                 if(((IWineD3DCubeTextureImpl *) stateblock->textures[sampler])->pow2scalingFactor != 1.0) {
1910                     texIsPow2 = TRUE;
1911                 }
1912             }
1913
1914             if(texIsPow2 || context->lastWasPow2Texture[sampler]) {
1915                 transform_texture(STATE_TRANSFORM(WINED3DTS_TEXTURE0 + stateblock->wineD3DDevice->texUnitMap[sampler]), stateblock, context);
1916                 context->lastWasPow2Texture[sampler] = texIsPow2;
1917             }
1918         }
1919
1920         IWineD3DBaseTexture_PreLoad((IWineD3DBaseTexture *) stateblock->textures[sampler]);
1921         IWineD3DBaseTexture_ApplyStateChanges(stateblock->textures[sampler], stateblock->textureState[sampler], stateblock->samplerState[sampler]);
1922
1923         if (GL_SUPPORT(EXT_TEXTURE_LOD_BIAS)) {
1924             tmpvalue.d = stateblock->samplerState[sampler][WINED3DSAMP_MIPMAPLODBIAS];
1925             glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
1926                       GL_TEXTURE_LOD_BIAS_EXT,
1927                       tmpvalue.f);
1928             checkGLcall("glTexEnvi GL_TEXTURE_LOD_BIAS_EXT ...");
1929         }
1930
1931         if (stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE && stateblock->pixelShader &&
1932             ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
1933             /* Using a pixel shader? Verify the sampler types */
1934
1935             /* Make sure that the texture dimensions are enabled. I don't have to disable the other
1936              * dimensions because the shader knows from which texture type to sample from. For the sake of
1937              * debugging all dimensions could be enabled and a texture with some ugly pink bound to the unused
1938              * dimensions. This should make wrong sampling sources visible :-)
1939              */
1940             glEnable(stateblock->textureDimensions[sampler]);
1941             checkGLcall("glEnable(stateblock->textureDimensions[sampler])");
1942         } else if(sampler < stateblock->lowest_disabled_stage) {
1943             if(!isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) {
1944                 activate_dimensions(sampler, stateblock);
1945             }
1946
1947             if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && sampler == 0) {
1948                 /* If color keying is enabled update the alpha test, it depends on the existence
1949                  * of a color key in stage 0
1950                  */
1951                 state_alpha(WINED3DRS_COLORKEYENABLE, stateblock, context);
1952             }
1953         }
1954     } else if(sampler < GL_LIMITS(texture_stages)) {
1955         if(sampler < stateblock->lowest_disabled_stage) {
1956             /* TODO: What should I do with pixel shaders here ??? */
1957             if(!isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) {
1958                 activate_dimensions(sampler, stateblock);
1959             }
1960         } /* Otherwise tex_colorop disables the stage */
1961         glBindTexture(GL_TEXTURE_1D, stateblock->wineD3DDevice->dummyTextureName[sampler]);
1962         checkGLcall("glBindTexture(GL_TEXTURE_1D, stateblock->wineD3DDevice->dummyTextureName[sampler])");
1963     }
1964 }
1965
1966 static void shaderconstant(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1967     IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
1968
1969     /* Vertex and pixel shader states will call a shader upload, don't do anything as long one of them
1970      * has an update pending
1971      */
1972     if(isStateDirty(context, STATE_VDECL) ||
1973        isStateDirty(context, STATE_PIXELSHADER)) {
1974        return;
1975     }
1976     
1977     device->shader_backend->shader_load_constants((IWineD3DDevice *) device,
1978         stateblock->pixelShader && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function,
1979         stateblock->vertexShader && ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function);
1980 }
1981
1982 static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1983     BOOL use_ps = stateblock->pixelShader && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function != NULL;
1984     BOOL use_vs = stateblock->vertexShader && ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function != NULL;
1985     int i;
1986
1987     if (use_ps) {
1988         if(!context->last_was_pshader) {
1989             /* Former draw without a pixel shader, some samplers
1990              * may be disabled because of WINED3DTSS_COLOROP = WINED3DTOP_DISABLE
1991              * make sure to enable them
1992              */
1993             for(i=0; i < MAX_SAMPLERS; i++) {
1994                 if(!isStateDirty(context, STATE_SAMPLER(i))) {
1995                     sampler(STATE_SAMPLER(i), stateblock, context);
1996                 }
1997             }
1998         } else {
1999            /* Otherwise all samplers were activated by the code above in earlier draws, or by sampler()
2000             * if a different texture was bound. I don't have to do anything.
2001             */
2002         }
2003
2004         /* Compile and bind the shader */
2005         IWineD3DPixelShader_CompileShader(stateblock->pixelShader);
2006     } else {
2007         /* Disabled the pixel shader - color ops weren't applied
2008          * while it was enabled, so re-apply them.
2009          */
2010         for(i=0; i < MAX_TEXTURES; i++) {
2011             if(!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP))) {
2012                 tex_colorop(STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP), stateblock, context);
2013             }
2014         }
2015     }
2016
2017     if(!isStateDirty(context, StateTable[STATE_VSHADER].representative)) {
2018         stateblock->wineD3DDevice->shader_backend->shader_select((IWineD3DDevice *)stateblock->wineD3DDevice, use_ps, use_vs);
2019
2020         if(!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (use_vs || use_ps)) {
2021             shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock, context);
2022         }
2023     }
2024
2025     context->last_was_pshader = use_ps;
2026 }
2027
2028 static void tex_bumpenvmat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2029     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
2030
2031     if(stateblock->pixelShader && stage != 0 &&
2032        ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->needsbumpmat == stage) {
2033         /* The pixel shader has to know the bump env matrix. Do a constants update if it isn't scheduled
2034          * anyway
2035          */
2036         if(!isStateDirty(context, STATE_PIXELSHADERCONSTANT) &&
2037            !isStateDirty(context, STATE_PIXELSHADER)) {
2038             shaderconstant(STATE_PIXELSHADERCONSTANT, stateblock, context);
2039         }
2040     }
2041 }
2042
2043 static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2044     /* This function is called by transform_view below if the view matrix was changed too
2045      *
2046      * Deliberately no check if the vertex declaration is dirty because the vdecl state
2047      * does not always update the world matrix, only on a switch between transformed
2048      * and untrannsformed draws. It *may* happen that the world matrix is set 2 times during one
2049      * draw, but that should be rather rare and cheaper in total.
2050      */
2051     glMatrixMode(GL_MODELVIEW);
2052     checkGLcall("glMatrixMode");
2053
2054     if(context->last_was_rhw) {
2055         glLoadIdentity();
2056         checkGLcall("glLoadIdentity()");
2057     } else {
2058         /* In the general case, the view matrix is the identity matrix */
2059         if (stateblock->wineD3DDevice->view_ident) {
2060             glLoadMatrixf((float *) &stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
2061             checkGLcall("glLoadMatrixf");
2062         } else {
2063             glLoadMatrixf((float *) &stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
2064             checkGLcall("glLoadMatrixf");
2065             glMultMatrixf((float *) &stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
2066             checkGLcall("glMultMatrixf");
2067         }
2068     }
2069 }
2070
2071 static void clipplane(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2072     UINT index = state - STATE_CLIPPLANE(0);
2073
2074     if(isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW)) || index >= GL_LIMITS(clipplanes)) {
2075         return;
2076     }
2077
2078     /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */
2079     glMatrixMode(GL_MODELVIEW);
2080     glPushMatrix();
2081     glLoadMatrixf((float *) &stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
2082
2083     TRACE("Clipplane [%f,%f,%f,%f]\n",
2084           stateblock->clipplane[index][0],
2085           stateblock->clipplane[index][1],
2086           stateblock->clipplane[index][2],
2087           stateblock->clipplane[index][3]);
2088     glClipPlane(GL_CLIP_PLANE0 + index, stateblock->clipplane[index]);
2089     checkGLcall("glClipPlane");
2090
2091     glPopMatrix();
2092 }
2093
2094 static void transform_view(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2095     unsigned int k;
2096
2097     /* If we are changing the View matrix, reset the light and clipping planes to the new view
2098      * NOTE: We have to reset the positions even if the light/plane is not currently
2099      *       enabled, since the call to enable it will not reset the position.
2100      * NOTE2: Apparently texture transforms do NOT need reapplying
2101      */
2102
2103     PLIGHTINFOEL *light = NULL;
2104
2105     glMatrixMode(GL_MODELVIEW);
2106     checkGLcall("glMatrixMode(GL_MODELVIEW)");
2107     glLoadMatrixf((float *)(float *) &stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
2108     checkGLcall("glLoadMatrixf(...)");
2109
2110     /* Reset lights. TODO: Call light apply func */
2111     for(k = 0; k < stateblock->wineD3DDevice->maxConcurrentLights; k++) {
2112         light = stateblock->activeLights[k];
2113         if(!light) continue;
2114         glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, light->lightPosn);
2115         checkGLcall("glLightfv posn");
2116         glLightfv(GL_LIGHT0 + light->glIndex, GL_SPOT_DIRECTION, light->lightDirn);
2117         checkGLcall("glLightfv dirn");
2118     }
2119
2120     /* Reset Clipping Planes  */
2121     for (k = 0; k < GL_LIMITS(clipplanes); k++) {
2122         if(!isStateDirty(context, STATE_CLIPPLANE(k))) {
2123             clipplane(STATE_CLIPPLANE(k), stateblock, context);
2124         }
2125     }
2126
2127     if(context->last_was_rhw) {
2128         glLoadIdentity();
2129         checkGLcall("glLoadIdentity()");
2130         /* No need to update the world matrix, the identity is fine */
2131         return;
2132     }
2133
2134     /* Call the world matrix state, this will apply the combined WORLD + VIEW matrix
2135      * No need to do it here if the state is scheduled for update.
2136      */
2137     if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)))) {
2138         transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context);
2139     }
2140 }
2141
2142 static void transform_worldex(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2143     WARN("World matrix 1 - 255 not supported yet\n");
2144 }
2145
2146 static const GLfloat invymat[16] = {
2147     1.0f, 0.0f, 0.0f, 0.0f,
2148     0.0f, -1.0f, 0.0f, 0.0f,
2149     0.0f, 0.0f, 1.0f, 0.0f,
2150     0.0f, 0.0f, 0.0f, 1.0f};
2151
2152 static void transform_projection(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2153     glMatrixMode(GL_PROJECTION);
2154     checkGLcall("glMatrixMode(GL_PROJECTION)");
2155     glLoadIdentity();
2156     checkGLcall("glLoadIdentity");
2157
2158     if(context->last_was_rhw) {
2159         double X, Y, height, width, minZ, maxZ;
2160
2161         X      = stateblock->viewport.X;
2162         Y      = stateblock->viewport.Y;
2163         height = stateblock->viewport.Height;
2164         width  = stateblock->viewport.Width;
2165         minZ   = stateblock->viewport.MinZ;
2166         maxZ   = stateblock->viewport.MaxZ;
2167
2168         if(!stateblock->wineD3DDevice->untransformed) {
2169             /* Transformed vertices are supposed to bypass the whole transform pipeline including
2170              * frustum clipping. This can't be done in opengl, so this code adjusts the Z range to
2171              * suppress depth clipping. This can be done because it is an orthogonal projection and
2172              * the Z coordinate does not affect the size of the primitives
2173              */
2174             TRACE("Calling glOrtho with %f, %f, %f, %f\n", width, height, -minZ, -maxZ);
2175             if(stateblock->wineD3DDevice->render_offscreen) {
2176                 glOrtho(X, X + width, -Y, -Y - height, -minZ, -maxZ);
2177             } else {
2178                 glOrtho(X, X + width, Y + height, Y, -minZ, -maxZ);
2179             }
2180         } else {
2181             /* If the app mixes transformed and untransformed primitives we can't use the coordinate system
2182              * trick above because this would mess up transformed and untransformed Z order. Pass the z position
2183              * unmodified to opengl.
2184              *
2185              * If the app depends on mixed types and disabled clipping we're out of luck without a pipeline
2186              * replacement shader.
2187              */
2188             TRACE("Calling glOrtho with %f, %f, %f, %f\n", width, height, 1.0, -1.0);
2189             if(stateblock->wineD3DDevice->render_offscreen) {
2190                 glOrtho(X, X + width, -Y, -Y - height, 1.0, -1.0);
2191             } else {
2192                 glOrtho(X, X + width, Y + height, Y, 1.0, -1.0);
2193             }
2194         }
2195         checkGLcall("glOrtho");
2196
2197         /* Window Coord 0 is the middle of the first pixel, so translate by 3/8 pixels */
2198         glTranslatef(0.375, 0.375, 0);
2199         checkGLcall("glTranslatef(0.375, 0.375, 0)");
2200         /* D3D texture coordinates are flipped compared to OpenGL ones, so
2201          * render everything upside down when rendering offscreen. */
2202         if (stateblock->wineD3DDevice->render_offscreen) {
2203             glMultMatrixf(invymat);
2204             checkGLcall("glMultMatrixf(invymat)");
2205         }
2206     } else {
2207         /* The rule is that the window coordinate 0 does not correspond to the
2208             beginning of the first pixel, but the center of the first pixel.
2209             As a consequence if you want to correctly draw one line exactly from
2210             the left to the right end of the viewport (with all matrices set to
2211             be identity), the x coords of both ends of the line would be not
2212             -1 and 1 respectively but (-1-1/viewport_widh) and (1-1/viewport_width)
2213             instead.                                                               */
2214         glTranslatef(0.9 / stateblock->viewport.Width, -0.9 / stateblock->viewport.Height, 0);
2215         checkGLcall("glTranslatef (0.9 / width, -0.9 / height, 0)");
2216
2217         /* D3D texture coordinates are flipped compared to OpenGL ones, so
2218             * render everything upside down when rendering offscreen. */
2219         if (stateblock->wineD3DDevice->render_offscreen) {
2220             glMultMatrixf(invymat);
2221             checkGLcall("glMultMatrixf(invymat)");
2222         }
2223         glMultMatrixf((float *) &stateblock->transforms[WINED3DTS_PROJECTION].u.m[0][0]);
2224         checkGLcall("glLoadMatrixf");
2225     }
2226 }
2227
2228 /* This should match any arrays loaded in loadVertexData.
2229  * stateblock impl is required for GL_SUPPORT
2230  * TODO: Only load / unload arrays if we have to.
2231  */
2232 static inline void unloadVertexData(IWineD3DStateBlockImpl *stateblock) {
2233     int texture_idx;
2234
2235     glDisableClientState(GL_VERTEX_ARRAY);
2236     glDisableClientState(GL_NORMAL_ARRAY);
2237     glDisableClientState(GL_COLOR_ARRAY);
2238     if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
2239         glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
2240     }
2241     for (texture_idx = 0; texture_idx < GL_LIMITS(textures); ++texture_idx) {
2242         GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx));
2243         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2244     }
2245 }
2246
2247 /* This should match any arrays loaded in loadNumberedArrays
2248  * TODO: Only load / unload arrays if we have to.
2249  */
2250 static inline void unloadNumberedArrays(IWineD3DStateBlockImpl *stateblock) {
2251     /* disable any attribs (this is the same for both GLSL and ARB modes) */
2252     GLint maxAttribs;
2253     int i;
2254
2255     /* Leave all the attribs disabled */
2256     glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &maxAttribs);
2257     /* MESA does not support it right not */
2258     if (glGetError() != GL_NO_ERROR)
2259         maxAttribs = 16;
2260     for (i = 0; i < maxAttribs; ++i) {
2261         GL_EXTCALL(glDisableVertexAttribArrayARB(i));
2262         checkGLcall("glDisableVertexAttribArrayARB(reg);");
2263     }
2264 }
2265
2266 static inline void loadNumberedArrays(IWineD3DStateBlockImpl *stateblock, WineDirect3DVertexStridedData *strided) {
2267     GLint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? -1 : 0;
2268     int i;
2269     UINT *offset = stateblock->streamOffset;
2270
2271     /* Default to no instancing */
2272     stateblock->wineD3DDevice->instancedDraw = FALSE;
2273
2274     for (i = 0; i < MAX_ATTRIBS; i++) {
2275
2276         if (!strided->u.input[i].lpData && !strided->u.input[i].VBO)
2277             continue;
2278
2279         /* Do not load instance data. It will be specified using glTexCoord by drawprim */
2280         if(stateblock->streamFlags[strided->u.input[i].streamNo] & WINED3DSTREAMSOURCE_INSTANCEDATA) {
2281             GL_EXTCALL(glDisableVertexAttribArrayARB(i));
2282             stateblock->wineD3DDevice->instancedDraw = TRUE;
2283             continue;
2284         }
2285
2286         TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, strided->u.input[i].VBO);
2287
2288         if(strided->u.input[i].dwStride) {
2289             if(curVBO != strided->u.input[i].VBO) {
2290                 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, strided->u.input[i].VBO));
2291                 checkGLcall("glBindBufferARB");
2292                 curVBO = strided->u.input[i].VBO;
2293             }
2294             GL_EXTCALL(glVertexAttribPointerARB(i,
2295                             WINED3D_ATR_SIZE(strided->u.input[i].dwType),
2296                             WINED3D_ATR_GLTYPE(strided->u.input[i].dwType),
2297                             WINED3D_ATR_NORMALIZED(strided->u.input[i].dwType),
2298                             strided->u.input[i].dwStride,
2299                             strided->u.input[i].lpData + stateblock->loadBaseVertexIndex * strided->u.input[i].dwStride + offset[strided->u.input[i].streamNo]) );
2300             GL_EXTCALL(glEnableVertexAttribArrayARB(i));
2301         } else {
2302             /* Stride = 0 means always the same values. glVertexAttribPointerARB doesn't do that. Instead disable the pointer and
2303              * set up the attribute statically. But we have to figure out the system memory address.
2304              */
2305             BYTE *ptr = strided->u.input[i].lpData + offset[strided->u.input[i].streamNo];
2306             if(strided->u.input[i].VBO) {
2307                 IWineD3DVertexBufferImpl *vb = (IWineD3DVertexBufferImpl *) stateblock->streamSource[strided->u.input[i].streamNo];
2308                 ptr += (long) vb->resource.allocatedMemory;
2309             }
2310             GL_EXTCALL(glDisableVertexAttribArrayARB(i));
2311
2312             switch(strided->u.input[i].dwType) {
2313                 case WINED3DDECLTYPE_FLOAT1:
2314                     GL_EXTCALL(glVertexAttrib1fvARB(i, (float *) ptr));
2315                     break;
2316                 case WINED3DDECLTYPE_FLOAT2:
2317                     GL_EXTCALL(glVertexAttrib2fvARB(i, (float *) ptr));
2318                     break;
2319                 case WINED3DDECLTYPE_FLOAT3:
2320                     GL_EXTCALL(glVertexAttrib3fvARB(i, (float *) ptr));
2321                     break;
2322                 case WINED3DDECLTYPE_FLOAT4:
2323                     GL_EXTCALL(glVertexAttrib4fvARB(i, (float *) ptr));
2324                     break;
2325
2326                 case WINED3DDECLTYPE_UBYTE4:
2327                     GL_EXTCALL(glVertexAttrib4NubvARB(i, ptr));
2328                     break;
2329                 case WINED3DDECLTYPE_UBYTE4N:
2330                 case WINED3DDECLTYPE_D3DCOLOR:
2331                     GL_EXTCALL(glVertexAttrib4NubvARB(i, ptr));
2332                     break;
2333
2334                 case WINED3DDECLTYPE_SHORT2:
2335                     GL_EXTCALL(glVertexAttrib4svARB(i, (GLshort *) ptr));
2336                     break;
2337                 case WINED3DDECLTYPE_SHORT4:
2338                     GL_EXTCALL(glVertexAttrib4svARB(i, (GLshort *) ptr));
2339                     break;
2340
2341                 case WINED3DDECLTYPE_SHORT2N:
2342                 {
2343                     GLshort s[4] = {((short *) ptr)[0], ((short *) ptr)[1], 0, 1};
2344                     GL_EXTCALL(glVertexAttrib4NsvARB(i, s));
2345                     break;
2346                 }
2347                 case WINED3DDECLTYPE_USHORT2N:
2348                 {
2349                     GLushort s[4] = {((unsigned short *) ptr)[0], ((unsigned short *) ptr)[1], 0, 1};
2350                     GL_EXTCALL(glVertexAttrib4NusvARB(i, s));
2351                     break;
2352                 }
2353                 case WINED3DDECLTYPE_SHORT4N:
2354                     GL_EXTCALL(glVertexAttrib4NsvARB(i, (GLshort *) ptr));
2355                     break;
2356                 case WINED3DDECLTYPE_USHORT4N:
2357                     GL_EXTCALL(glVertexAttrib4NusvARB(i, (GLushort *) ptr));
2358                     break;
2359
2360                 case WINED3DDECLTYPE_UDEC3:
2361                     FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
2362                     /*glVertexAttrib3usvARB(i, (GLushort *) ptr); Does not exist */
2363                     break;
2364                 case WINED3DDECLTYPE_DEC3N:
2365                     FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
2366                     /*glVertexAttrib3NusvARB(i, (GLushort *) ptr); Does not exist */
2367                     break;
2368
2369                 case WINED3DDECLTYPE_FLOAT16_2:
2370                     /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
2371                      * byte float according to the IEEE standard
2372                      */
2373                     FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_2\n");
2374                     break;
2375                 case WINED3DDECLTYPE_FLOAT16_4:
2376                     FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_4\n");
2377                     break;
2378
2379                 case WINED3DDECLTYPE_UNUSED:
2380                 default:
2381                     ERR("Unexpected declaration in stride 0 attributes\n");
2382                     break;
2383
2384             }
2385         }
2386     }
2387 }
2388
2389 /* Used from 2 different functions, and too big to justify making it inlined */
2390 static void loadVertexData(IWineD3DStateBlockImpl *stateblock, WineDirect3DVertexStridedData *sd) {
2391     unsigned int textureNo   = 0;
2392     unsigned int texture_idx = 0;
2393     UINT *offset = stateblock->streamOffset;
2394     GLint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? -1 : 0;
2395
2396     TRACE("Using fast vertex array code\n");
2397
2398     /* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */
2399     stateblock->wineD3DDevice->instancedDraw = FALSE;
2400
2401     /* Blend Data ---------------------------------------------- */
2402     if( (sd->u.s.blendWeights.lpData) || (sd->u.s.blendWeights.VBO) ||
2403         (sd->u.s.blendMatrixIndices.lpData) || (sd->u.s.blendMatrixIndices.VBO) ) {
2404
2405
2406         if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
2407
2408 #if 1
2409             glEnableClientState(GL_WEIGHT_ARRAY_ARB);
2410             checkGLcall("glEnableClientState(GL_WEIGHT_ARRAY_ARB)");
2411 #endif
2412
2413             TRACE("Blend %d %p %d\n", WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType),
2414                 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride, sd->u.s.blendWeights.dwStride + offset[sd->u.s.blendWeights.streamNo]);
2415             /* FIXME("TODO\n");*/
2416             /* Note dwType == float3 or float4 == 2 or 3 */
2417
2418 #if 0
2419             /* with this on, the normals appear to be being modified,
2420                but the vertices aren't being translated as they should be
2421                Maybe the world matrix aren't being setup properly? */
2422             glVertexBlendARB(WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType) + 1);
2423 #endif
2424
2425
2426             VTRACE(("glWeightPointerARB(%d, GL_FLOAT, %d, %p)\n",
2427                 WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType) ,
2428                 sd->u.s.blendWeights.dwStride,
2429                 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride + offset[sd->u.s.blendWeights.streamNo]));
2430
2431             if(curVBO != sd->u.s.blendWeights.VBO) {
2432                 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.blendWeights.VBO));
2433                 checkGLcall("glBindBufferARB");
2434                 curVBO = sd->u.s.blendWeights.VBO;
2435             }
2436
2437             GL_EXTCALL(glWeightPointerARB)(
2438                 WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType),
2439                 WINED3D_ATR_GLTYPE(sd->u.s.blendWeights.dwType),
2440                 sd->u.s.blendWeights.dwStride,
2441                 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride + offset[sd->u.s.blendWeights.streamNo]);
2442
2443             checkGLcall("glWeightPointerARB");
2444
2445             if((sd->u.s.blendMatrixIndices.lpData) || (sd->u.s.blendMatrixIndices.VBO)){
2446                 static BOOL showfixme = TRUE;
2447                 if(showfixme){
2448                     FIXME("blendMatrixIndices support\n");
2449                     showfixme = FALSE;
2450                 }
2451             }
2452
2453         } else if (GL_SUPPORT(EXT_VERTEX_WEIGHTING)) {
2454             /* FIXME("TODO\n");*/
2455 #if 0
2456
2457             GL_EXTCALL(glVertexWeightPointerEXT)(
2458                 WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType),
2459                 WINED3D_ATR_GLTYPE(sd->u.s.blendWeights.dwType),
2460                 sd->u.s.blendWeights.dwStride,
2461                 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride);
2462             checkGLcall("glVertexWeightPointerEXT(numBlends, ...)");
2463             glEnableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT);
2464             checkGLcall("glEnableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT)");
2465 #endif
2466
2467         } else {
2468             /* TODO: support blends in drawStridedSlow
2469              * No need to write a FIXME here, this is done after the general vertex decl decoding
2470              */
2471             WARN("unsupported blending in openGl\n");
2472         }
2473     } else {
2474         if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
2475 #if 0    /* TODO: Vertex blending */
2476             glDisable(GL_VERTEX_BLEND_ARB);
2477 #endif
2478             TRACE("ARB_VERTEX_BLEND\n");
2479         } else if (GL_SUPPORT(EXT_VERTEX_WEIGHTING)) {
2480             TRACE(" EXT_VERTEX_WEIGHTING\n");
2481             glDisableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT);
2482             checkGLcall("glDisableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT)");
2483
2484         }
2485     }
2486
2487 #if 0 /* FOG  ----------------------------------------------*/
2488     if (sd->u.s.fog.lpData || sd->u.s.fog.VBO) {
2489         /* TODO: fog*/
2490     if (GL_SUPPORT(EXT_FOG_COORD) {
2491              glEnableClientState(GL_FOG_COORDINATE_EXT);
2492             (GL_EXTCALL)(FogCoordPointerEXT)(
2493                 WINED3D_ATR_GLTYPE(sd->u.s.fog.dwType),
2494                 sd->u.s.fog.dwStride,
2495                 sd->u.s.fog.lpData + stateblock->loadBaseVertexIndex * sd->u.s.fog.dwStride);
2496         } else {
2497             /* don't bother falling back to 'slow' as we don't support software FOG yet. */
2498             /* FIXME: fixme once */
2499             TRACE("Hardware support for FOG is not avaiable, FOG disabled.\n");
2500         }
2501     } else {
2502         if (GL_SUPPRT(EXT_FOR_COORD) {
2503              /* make sure fog is disabled */
2504              glDisableClientState(GL_FOG_COORDINATE_EXT);
2505         }
2506     }
2507 #endif
2508
2509 #if 0 /* tangents  ----------------------------------------------*/
2510     if (sd->u.s.tangent.lpData || sd->u.s.tangent.VBO ||
2511         sd->u.s.binormal.lpData || sd->u.s.binormal.VBO) {
2512         /* TODO: tangents*/
2513         if (GL_SUPPORT(EXT_COORDINATE_FRAME) {
2514             if (sd->u.s.tangent.lpData || sd->u.s.tangent.VBO) {
2515                 glEnable(GL_TANGENT_ARRAY_EXT);
2516                 (GL_EXTCALL)(TangentPointerEXT)(
2517                     WINED3D_ATR_GLTYPE(sd->u.s.tangent.dwType),
2518                     sd->u.s.tangent.dwStride,
2519                     sd->u.s.tangent.lpData + stateblock->loadBaseVertexIndex * sd->u.s.tangent.dwStride);
2520             } else {
2521                     glDisable(GL_TANGENT_ARRAY_EXT);
2522             }
2523             if (sd->u.s.binormal.lpData || sd->u.s.binormal.VBO) {
2524                     glEnable(GL_BINORMAL_ARRAY_EXT);
2525                     (GL_EXTCALL)(BinormalPointerEXT)(
2526                         WINED3D_ATR_GLTYPE(sd->u.s.binormal.dwType),
2527                         sd->u.s.binormal.dwStride,
2528                         sd->u.s.binormal.lpData + stateblock->loadBaseVertexIndex * sd->u.s.binormal.dwStride);
2529             } else{
2530                     glDisable(GL_BINORMAL_ARRAY_EXT);
2531             }
2532
2533         } else {
2534             /* don't bother falling back to 'slow' as we don't support software tangents and binormals yet . */
2535             /* FIXME: fixme once */
2536             TRACE("Hardware support for tangents and binormals is not avaiable, tangents and binormals disabled.\n");
2537         }
2538     } else {
2539         if (GL_SUPPORT(EXT_COORDINATE_FRAME) {
2540              /* make sure fog is disabled */
2541              glDisable(GL_TANGENT_ARRAY_EXT);
2542              glDisable(GL_BINORMAL_ARRAY_EXT);
2543         }
2544     }
2545 #endif
2546
2547     /* Point Size ----------------------------------------------*/
2548     if (sd->u.s.pSize.lpData || sd->u.s.pSize.VBO) {
2549
2550         /* no such functionality in the fixed function GL pipeline */
2551         TRACE("Cannot change ptSize here in openGl\n");
2552         /* TODO: Implement this function in using shaders if they are available */
2553
2554     }
2555
2556     /* Vertex Pointers -----------------------------------------*/
2557     if (sd->u.s.position.lpData != NULL || sd->u.s.position.VBO != 0) {
2558         /* Note dwType == float3 or float4 == 2 or 3 */
2559         VTRACE(("glVertexPointer(%d, GL_FLOAT, %d, %p)\n",
2560                 sd->u.s.position.dwStride,
2561                 sd->u.s.position.dwType + 1,
2562                 sd->u.s.position.lpData));
2563
2564         if(curVBO != sd->u.s.position.VBO) {
2565             GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.position.VBO));
2566             checkGLcall("glBindBufferARB");
2567             curVBO = sd->u.s.position.VBO;
2568         }
2569
2570         /* min(WINED3D_ATR_SIZE(position),3) to Disable RHW mode as 'w' coord
2571            handling for rhw mode should not impact screen position whereas in GL it does.
2572            This may  result in very slightly distored textures in rhw mode, but
2573            a very minimal different. There's always the other option of
2574            fixing the view matrix to prevent w from having any effect
2575
2576            This only applies to user pointer sources, in VBOs the vertices are fixed up
2577          */
2578         if(sd->u.s.position.VBO == 0) {
2579             glVertexPointer(3 /* min(WINED3D_ATR_SIZE(sd->u.s.position.dwType),3) */,
2580                 WINED3D_ATR_GLTYPE(sd->u.s.position.dwType),
2581                 sd->u.s.position.dwStride, sd->u.s.position.lpData + stateblock->loadBaseVertexIndex * sd->u.s.position.dwStride + offset[sd->u.s.position.streamNo]);
2582         } else {
2583             glVertexPointer(
2584                 WINED3D_ATR_SIZE(sd->u.s.position.dwType),
2585                 WINED3D_ATR_GLTYPE(sd->u.s.position.dwType),
2586                 sd->u.s.position.dwStride, sd->u.s.position.lpData + stateblock->loadBaseVertexIndex * sd->u.s.position.dwStride + offset[sd->u.s.position.streamNo]);
2587         }
2588         checkGLcall("glVertexPointer(...)");
2589         glEnableClientState(GL_VERTEX_ARRAY);
2590         checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)");
2591
2592     } else {
2593         glDisableClientState(GL_VERTEX_ARRAY);
2594         checkGLcall("glDisableClientState(GL_VERTEX_ARRAY)");
2595     }
2596
2597     /* Normals -------------------------------------------------*/
2598     if (sd->u.s.normal.lpData || sd->u.s.normal.VBO) {
2599         /* Note dwType == float3 or float4 == 2 or 3 */
2600         VTRACE(("glNormalPointer(GL_FLOAT, %d, %p)\n",
2601                 sd->u.s.normal.dwStride,
2602                 sd->u.s.normal.lpData));
2603         if(curVBO != sd->u.s.normal.VBO) {
2604             GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.normal.VBO));
2605             checkGLcall("glBindBufferARB");
2606             curVBO = sd->u.s.normal.VBO;
2607         }
2608         glNormalPointer(
2609             WINED3D_ATR_GLTYPE(sd->u.s.normal.dwType),
2610             sd->u.s.normal.dwStride,
2611             sd->u.s.normal.lpData + stateblock->loadBaseVertexIndex * sd->u.s.normal.dwStride + offset[sd->u.s.normal.streamNo]);
2612         checkGLcall("glNormalPointer(...)");
2613         glEnableClientState(GL_NORMAL_ARRAY);
2614         checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
2615
2616     } else {
2617         glDisableClientState(GL_NORMAL_ARRAY);
2618         checkGLcall("glDisableClientState(GL_NORMAL_ARRAY)");
2619         glNormal3f(0, 0, 1);
2620         checkGLcall("glNormal3f(0, 0, 1)");
2621     }
2622
2623     /* Diffuse Colour --------------------------------------------*/
2624     /*  WARNING: Data here MUST be in RGBA format, so cannot      */
2625     /*     go directly into fast mode from app pgm, because       */
2626     /*     directx requires data in BGRA format.                  */
2627     /* currently fixupVertices swizels the format, but this isn't */
2628     /* very practical when using VBOS                             */
2629     /* NOTE: Unless we write a vertex shader to swizel the colour */
2630     /* , or the user doesn't care and wants the speed advantage   */
2631
2632     if (sd->u.s.diffuse.lpData || sd->u.s.diffuse.VBO) {
2633         /* Note dwType == float3 or float4 == 2 or 3 */
2634         VTRACE(("glColorPointer(4, GL_UNSIGNED_BYTE, %d, %p)\n",
2635                 sd->u.s.diffuse.dwStride,
2636                 sd->u.s.diffuse.lpData));
2637
2638         if(curVBO != sd->u.s.diffuse.VBO) {
2639             GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.diffuse.VBO));
2640             checkGLcall("glBindBufferARB");
2641             curVBO = sd->u.s.diffuse.VBO;
2642         }
2643         glColorPointer(4, GL_UNSIGNED_BYTE,
2644                        sd->u.s.diffuse.dwStride,
2645                        sd->u.s.diffuse.lpData + stateblock->loadBaseVertexIndex * sd->u.s.diffuse.dwStride + offset[sd->u.s.diffuse.streamNo]);
2646         checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
2647         glEnableClientState(GL_COLOR_ARRAY);
2648         checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");
2649
2650     } else {
2651         glDisableClientState(GL_COLOR_ARRAY);
2652         checkGLcall("glDisableClientState(GL_COLOR_ARRAY)");
2653         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
2654         checkGLcall("glColor4f(1, 1, 1, 1)");
2655     }
2656
2657     /* Specular Colour ------------------------------------------*/
2658     if (sd->u.s.specular.lpData || sd->u.s.specular.VBO) {
2659         TRACE("setting specular colour\n");
2660         /* Note dwType == float3 or float4 == 2 or 3 */
2661         VTRACE(("glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, %d, %p)\n",
2662                 sd->u.s.specular.dwStride,
2663                 sd->u.s.specular.lpData));
2664         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
2665             if(curVBO != sd->u.s.specular.VBO) {
2666                 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.specular.VBO));
2667                 checkGLcall("glBindBufferARB");
2668                 curVBO = sd->u.s.specular.VBO;
2669             }
2670             GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE,
2671                                                    sd->u.s.specular.dwStride,
2672                                                    sd->u.s.specular.lpData + stateblock->loadBaseVertexIndex * sd->u.s.specular.dwStride + offset[sd->u.s.specular.streamNo]);
2673             vcheckGLcall("glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, ...)");
2674             glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
2675             vcheckGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
2676         } else {
2677
2678         /* Missing specular color is not critical, no warnings */
2679         VTRACE(("Specular colour is not supported in this GL implementation\n"));
2680         }
2681
2682     } else {
2683         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
2684
2685             glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
2686             checkGLcall("glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
2687             GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
2688             checkGLcall("glSecondaryColor3fEXT(0, 0, 0)");
2689         } else {
2690
2691             /* Missing specular color is not critical, no warnings */
2692             VTRACE(("Specular colour is not supported in this GL implementation\n"));
2693         }
2694     }
2695
2696     /* Texture coords -------------------------------------------*/
2697
2698     for (textureNo = 0, texture_idx = 0; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
2699         /* The code below uses glClientActiveTexture and glMultiTexCoord* which are all part of the GL_ARB_multitexture extension. */
2700         /* Abort if we don't support the extension. */
2701         if (!GL_SUPPORT(ARB_MULTITEXTURE)) {
2702             FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
2703             continue;
2704         }
2705
2706         if (/*!GL_SUPPORT(NV_REGISTER_COMBINERS) || stateblock->textures[textureNo]*/ TRUE) {
2707             /* Select the correct texture stage */
2708             GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx));
2709         }
2710
2711         if (stateblock->textures[textureNo] != NULL) {
2712             int coordIdx = stateblock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX];
2713
2714             if (coordIdx >= MAX_TEXTURES) {
2715                 VTRACE(("tex: %d - Skip tex coords, as being system generated\n", textureNo));
2716                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2717                 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, 0, 0, 0, 1));
2718
2719             } else if (sd->u.s.texCoords[coordIdx].lpData == NULL && sd->u.s.texCoords[coordIdx].VBO == 0) {
2720                 VTRACE(("Bound texture but no texture coordinates supplied, so skipping\n"));
2721                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2722                 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, 0, 0, 0, 1));
2723
2724             } else {
2725                 TRACE("Setting up texture %u, idx %d, cordindx %u, data %p\n",
2726                       textureNo, texture_idx, coordIdx, sd->u.s.texCoords[coordIdx].lpData);
2727                 if(curVBO != sd->u.s.texCoords[coordIdx].VBO) {
2728                     GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.texCoords[coordIdx].VBO));
2729                     checkGLcall("glBindBufferARB");
2730                     curVBO = sd->u.s.texCoords[coordIdx].VBO;
2731                 }
2732                 /* The coords to supply depend completely on the fvf / vertex shader */
2733                 glTexCoordPointer(
2734                     WINED3D_ATR_SIZE(sd->u.s.texCoords[coordIdx].dwType),
2735                     WINED3D_ATR_GLTYPE(sd->u.s.texCoords[coordIdx].dwType),
2736                     sd->u.s.texCoords[coordIdx].dwStride,
2737                     sd->u.s.texCoords[coordIdx].lpData + stateblock->loadBaseVertexIndex * sd->u.s.texCoords[coordIdx].dwStride + offset[sd->u.s.texCoords[coordIdx].streamNo]);
2738                 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2739             }
2740         } else if (!GL_SUPPORT(NV_REGISTER_COMBINERS)) {
2741             glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2742             GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1));
2743         }
2744         if (/*!GL_SUPPORT(NV_REGISTER_COMBINERS) || stateblock->textures[textureNo]*/ TRUE) ++texture_idx;
2745     }
2746     if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
2747         for (textureNo = texture_idx; textureNo < GL_LIMITS(textures); ++textureNo) {
2748             GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo));
2749             glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2750             GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1));
2751         }
2752     }
2753 }
2754
2755 inline void drawPrimitiveTraceDataLocations(
2756     WineDirect3DVertexStridedData *dataLocations) {
2757
2758     /* Dump out what parts we have supplied */
2759     TRACE("Strided Data:\n");
2760     TRACE_STRIDED((dataLocations), position);
2761     TRACE_STRIDED((dataLocations), blendWeights);
2762     TRACE_STRIDED((dataLocations), blendMatrixIndices);
2763     TRACE_STRIDED((dataLocations), normal);
2764     TRACE_STRIDED((dataLocations), pSize);
2765     TRACE_STRIDED((dataLocations), diffuse);
2766     TRACE_STRIDED((dataLocations), specular);
2767     TRACE_STRIDED((dataLocations), texCoords[0]);
2768     TRACE_STRIDED((dataLocations), texCoords[1]);
2769     TRACE_STRIDED((dataLocations), texCoords[2]);
2770     TRACE_STRIDED((dataLocations), texCoords[3]);
2771     TRACE_STRIDED((dataLocations), texCoords[4]);
2772     TRACE_STRIDED((dataLocations), texCoords[5]);
2773     TRACE_STRIDED((dataLocations), texCoords[6]);
2774     TRACE_STRIDED((dataLocations), texCoords[7]);
2775     TRACE_STRIDED((dataLocations), position2);
2776     TRACE_STRIDED((dataLocations), normal2);
2777     TRACE_STRIDED((dataLocations), tangent);
2778     TRACE_STRIDED((dataLocations), binormal);
2779     TRACE_STRIDED((dataLocations), tessFactor);
2780     TRACE_STRIDED((dataLocations), fog);
2781     TRACE_STRIDED((dataLocations), depth);
2782     TRACE_STRIDED((dataLocations), sample);
2783
2784     return;
2785 }
2786
2787 /* Helper for vertexdeclaration() */
2788 static inline void handleStreams(IWineD3DStateBlockImpl *stateblock, BOOL useVertexShaderFunction, WineD3DContext *context) {
2789     IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
2790     BOOL fixup = FALSE;
2791     WineDirect3DVertexStridedData *dataLocations = &device->strided_streams;
2792
2793     if(device->up_strided) {
2794         /* Note: this is a ddraw fixed-function code path */
2795         TRACE("================ Strided Input ===================\n");
2796         memcpy(dataLocations, device->up_strided, sizeof(*dataLocations));
2797
2798         if(TRACE_ON(d3d)) {
2799             drawPrimitiveTraceDataLocations(dataLocations);
2800         }
2801     } else if (stateblock->vertexDecl || stateblock->vertexShader) {
2802         /* Note: This is a fixed function or shader codepath.
2803          * This means it must handle both types of strided data.
2804          * Shaders must go through here to zero the strided data, even if they
2805          * don't set any declaration at all
2806          */
2807         TRACE("================ Vertex Declaration  ===================\n");
2808         memset(dataLocations, 0, sizeof(*dataLocations));
2809
2810         if (stateblock->vertexDecl) {
2811             primitiveDeclarationConvertToStridedData((IWineD3DDevice *) device, useVertexShaderFunction,
2812                 dataLocations, &fixup);
2813         }
2814     } else {
2815         /* Note: This codepath is not reachable from d3d9 (see fvf->decl9 conversion)
2816          * It is reachable through d3d8, but only for fixed-function.
2817          * It will not work properly for shaders.
2818          */
2819         TRACE("================ FVF ===================\n");
2820         memset(dataLocations, 0, sizeof(*dataLocations));
2821         primitiveConvertToStridedData((IWineD3DDevice *) device, dataLocations, &fixup);
2822         if(TRACE_ON(d3d)) {
2823             drawPrimitiveTraceDataLocations(dataLocations);
2824         }
2825      }
2826
2827     /* Unload the old arrays before loading the new ones to get old junk out */
2828     if(context->numberedArraysLoaded) {
2829         unloadNumberedArrays(stateblock);
2830         context->numberedArraysLoaded = FALSE;
2831     }
2832     if(context->namedArraysLoaded) {
2833         unloadVertexData(stateblock);
2834         context->namedArraysLoaded = FALSE;
2835     }
2836
2837     if(useVertexShaderFunction) {
2838         TRACE("Loading numbered arrays\n");
2839         loadNumberedArrays(stateblock, dataLocations);
2840         device->useDrawStridedSlow = FALSE;
2841         context->numberedArraysLoaded = TRUE;
2842     } else if (fixup ||
2843                (dataLocations->u.s.pSize.lpData == NULL &&
2844                 dataLocations->u.s.diffuse.lpData == NULL &&
2845                 dataLocations->u.s.specular.lpData == NULL)) {
2846         /* Load the vertex data using named arrays */
2847         TRACE("Loading vertex data\n");
2848         loadVertexData(stateblock, dataLocations);
2849         device->useDrawStridedSlow = FALSE;
2850         context->namedArraysLoaded = TRUE;
2851     } else {
2852         TRACE("Not loading vertex data\n");
2853         device->useDrawStridedSlow = TRUE;
2854     }
2855
2856 /* Generate some fixme's if unsupported functionality is being used */
2857 #define BUFFER_OR_DATA(_attribute) dataLocations->u.s._attribute.lpData
2858     /* TODO: Either support missing functionality in fixupVertices or by creating a shader to replace the pipeline. */
2859     if (!useVertexShaderFunction &&
2860         stateblock->renderState[WINED3DRS_VERTEXBLEND] &&
2861         (BUFFER_OR_DATA(blendMatrixIndices) || BUFFER_OR_DATA(blendWeights))) {
2862         FIXME("Vertex Blending is not implemented yet %p %p\n",dataLocations->u.s.blendWeights.lpData,dataLocations->u.s.blendWeights.lpData);
2863         /* TODO: Implement it using GL_ARB_vertex_blend or software emulation in drawStridedSlow */
2864     }
2865     if (!useVertexShaderFunction && (BUFFER_OR_DATA(position2) || BUFFER_OR_DATA(normal2))) {
2866         FIXME("Tweening is only valid with vertex shaders\n");
2867     }
2868     if (!useVertexShaderFunction && (BUFFER_OR_DATA(tangent) || BUFFER_OR_DATA(binormal))) {
2869         FIXME("Tangent and binormal bump mapping is only valid with vertex shaders\n");
2870     }
2871     if (!useVertexShaderFunction && (BUFFER_OR_DATA(tessFactor) || BUFFER_OR_DATA(fog) || BUFFER_OR_DATA(depth) || BUFFER_OR_DATA(sample))) {
2872         FIXME("Extended attributes are only valid with vertex shaders\n");
2873     }
2874 #undef BUFFER_OR_DATA
2875 }
2876
2877 static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2878     BOOL useVertexShaderFunction = FALSE, updateFog = FALSE;
2879     BOOL usePixelShaderFunction = stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE && stateblock->pixelShader
2880             && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function;
2881     BOOL transformed;
2882     /* Some stuff is in the device until we have per context tracking */
2883     IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
2884     BOOL wasrhw = context->last_was_rhw;
2885
2886     /* Shaders can be implemented using ARB_PROGRAM, GLSL, or software -
2887      * here simply check whether a shader was set, or the user disabled shaders
2888      */
2889     if (device->vs_selected_mode != SHADER_NONE && stateblock->vertexShader &&
2890        ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function != NULL) {
2891         useVertexShaderFunction = TRUE;
2892
2893         if(((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->usesFog != context->last_was_foggy_shader) {
2894             updateFog = TRUE;
2895         }
2896     } else if(context->last_was_foggy_shader) {
2897         updateFog = TRUE;
2898     }
2899
2900     handleStreams(stateblock, useVertexShaderFunction, context);
2901
2902     /* Do I have to use ? TRUE : FALSE ? Or can I rely on 15==15 being equal to TRUE(=1)? */
2903     transformed = ((device->strided_streams.u.s.position.lpData != NULL ||
2904                     device->strided_streams.u.s.position.VBO != 0) &&
2905                     device->strided_streams.u.s.position_transformed) ? TRUE : FALSE;
2906
2907     if(transformed != context->last_was_rhw && !useVertexShaderFunction) {
2908         updateFog = TRUE;
2909     }
2910
2911     /* Reapply lighting if it is not scheduled for reapplication already */
2912     if(!isStateDirty(context, STATE_RENDER(WINED3DRS_LIGHTING))) {
2913         state_lighting(STATE_RENDER(WINED3DRS_LIGHTING), stateblock, context);
2914     }
2915
2916     if (!useVertexShaderFunction && transformed) {
2917         context->last_was_rhw = TRUE;
2918     } else {
2919
2920         /* Untransformed, so relies on the view and projection matrices */
2921         context->last_was_rhw = FALSE;
2922         /* This turns off the Z scale trick to 'disable' viewport frustum clipping in rhw mode*/
2923         device->untransformed = TRUE;
2924
2925         /* Todo for sw shaders: Vertex Shader output is already transformed, so set up identity matrices
2926          * Not needed as long as only hw shaders are supported
2927          */
2928
2929         /* This sets the shader output position correction constants.
2930          * TODO: Move to the viewport state
2931          */
2932         if (useVertexShaderFunction) {
2933             device->posFixup[1] = device->render_offscreen ? -1.0 : 1.0;
2934         }
2935     }
2936
2937     /* Don't have to apply the matrices when vertex shaders are used. When vshaders are turned
2938      * off this function will be called again anyway to make sure they're properly set
2939      */
2940     if(!useVertexShaderFunction) {
2941         /* TODO: Move this mainly to the viewport state and only apply when the vp has changed
2942          * or transformed / untransformed was switched
2943          */
2944        if(wasrhw != context->last_was_rhw &&
2945           !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION)) &&
2946           !isStateDirty(context, STATE_VIEWPORT)) {
2947             transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context);
2948         }
2949         /* World matrix needs reapplication here only if we're switching between rhw and non-rhw
2950          * mode.
2951          *
2952          * If a vertex shader is used, the world matrix changed and then vertex shader unbound
2953          * this check will fail and the matrix not applied again. This is OK because a simple
2954          * world matrix change reapplies the matrix - These checks here are only to satisfy the
2955          * needs of the vertex declaration.
2956          *
2957          * World and view matrix go into the same gl matrix, so only apply them when neither is
2958          * dirty
2959          */
2960         if(transformed != wasrhw &&
2961            !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0))) &&
2962            !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW))) {
2963             transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context);
2964         }
2965
2966         if(!isStateDirty(context, STATE_RENDER(WINED3DRS_COLORVERTEX))) {
2967             state_colormat(STATE_RENDER(WINED3DRS_COLORVERTEX), stateblock, context);
2968         }
2969
2970         if(context->last_was_vshader && !isStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPLANEENABLE))) {
2971             state_clipping(STATE_RENDER(WINED3DRS_CLIPPLANEENABLE), stateblock, context);
2972         }
2973     } else {
2974         /* We compile the shader here because we need the vertex declaration
2975          * in order to determine if we need to do any swizzling for D3DCOLOR
2976          * registers. If the shader is already compiled this call will do nothing. */
2977         IWineD3DVertexShader_CompileShader(stateblock->vertexShader);
2978
2979         if(!context->last_was_vshader) {
2980             int i;
2981             static BOOL warned = FALSE;
2982             /* Disable all clip planes to get defined results on all drivers. See comment in the
2983              * state_clipping state handler
2984              */
2985             for(i = 0; i < GL_LIMITS(clipplanes); i++) {
2986                 glDisable(GL_CLIP_PLANE0 + i);
2987                 checkGLcall("glDisable(GL_CLIP_PLANE0 + i)");
2988             }
2989
2990             if(!warned && stateblock->renderState[WINED3DRS_CLIPPLANEENABLE]) {
2991                 FIXME("Clipping not supported with vertex shaders\n");
2992                 warned = TRUE;
2993             }
2994         }
2995     }
2996
2997     /* Vertex and pixel shaders are applied together for now, so let the last dirty state do the
2998      * application
2999      */
3000     if (!isStateDirty(context, STATE_PIXELSHADER)) {
3001         device->shader_backend->shader_select((IWineD3DDevice *)device, usePixelShaderFunction, useVertexShaderFunction);
3002
3003         if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (useVertexShaderFunction || usePixelShaderFunction)) {
3004             shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock, context);
3005         }
3006     }
3007
3008     context->last_was_vshader = useVertexShaderFunction;
3009
3010     if(updateFog) {
3011         state_fog(STATE_RENDER(WINED3DRS_FOGENABLE), stateblock, context);
3012     }
3013 }
3014
3015 static void viewport(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3016     glDepthRange(stateblock->viewport.MinZ, stateblock->viewport.MaxZ);
3017     checkGLcall("glDepthRange");
3018     /* Note: GL requires lower left, DirectX supplies upper left. This is reversed when using offscreen rendering
3019      */
3020     if(stateblock->wineD3DDevice->render_offscreen) {
3021         glViewport(stateblock->viewport.X,
3022                    stateblock->viewport.Y,
3023                    stateblock->viewport.Width, stateblock->viewport.Height);
3024     } else {
3025         glViewport(stateblock->viewport.X,
3026                    (((IWineD3DSurfaceImpl *)stateblock->wineD3DDevice->render_targets[0])->currentDesc.Height - (stateblock->viewport.Y + stateblock->viewport.Height)),
3027                    stateblock->viewport.Width, stateblock->viewport.Height);
3028     }
3029
3030     checkGLcall("glViewport");
3031
3032     stateblock->wineD3DDevice->posFixup[2] = 0.9 / stateblock->viewport.Width;
3033     stateblock->wineD3DDevice->posFixup[3] = -0.9 / stateblock->viewport.Height;
3034     if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
3035         transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context);
3036     }
3037
3038 }
3039
3040 static void light(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3041     UINT Index = state - STATE_ACTIVELIGHT(0);
3042     PLIGHTINFOEL *lightInfo = stateblock->activeLights[Index];
3043
3044     if(!lightInfo) {
3045         glDisable(GL_LIGHT0 + Index);
3046         checkGLcall("glDisable(GL_LIGHT0 + Index)");
3047     } else {
3048         float quad_att;
3049         float colRGBA[] = {0.0, 0.0, 0.0, 0.0};
3050
3051         /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
3052         glMatrixMode(GL_MODELVIEW);
3053         glPushMatrix();
3054         glLoadMatrixf((float *)&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
3055
3056         /* Diffuse: */
3057         colRGBA[0] = lightInfo->OriginalParms.Diffuse.r;
3058         colRGBA[1] = lightInfo->OriginalParms.Diffuse.g;
3059         colRGBA[2] = lightInfo->OriginalParms.Diffuse.b;
3060         colRGBA[3] = lightInfo->OriginalParms.Diffuse.a;
3061         glLightfv(GL_LIGHT0 + Index, GL_DIFFUSE, colRGBA);
3062         checkGLcall("glLightfv");
3063
3064         /* Specular */
3065         colRGBA[0] = lightInfo->OriginalParms.Specular.r;
3066         colRGBA[1] = lightInfo->OriginalParms.Specular.g;
3067         colRGBA[2] = lightInfo->OriginalParms.Specular.b;
3068         colRGBA[3] = lightInfo->OriginalParms.Specular.a;
3069         glLightfv(GL_LIGHT0 + Index, GL_SPECULAR, colRGBA);
3070         checkGLcall("glLightfv");
3071
3072         /* Ambient */
3073         colRGBA[0] = lightInfo->OriginalParms.Ambient.r;
3074         colRGBA[1] = lightInfo->OriginalParms.Ambient.g;
3075         colRGBA[2] = lightInfo->OriginalParms.Ambient.b;
3076         colRGBA[3] = lightInfo->OriginalParms.Ambient.a;
3077         glLightfv(GL_LIGHT0 + Index, GL_AMBIENT, colRGBA);
3078         checkGLcall("glLightfv");
3079
3080         if ((lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range) >= FLT_MIN) {
3081             quad_att = 1.4/(lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range);
3082         } else {
3083             quad_att = 0; /*  0 or  MAX?  (0 seems to be ok) */
3084         }
3085
3086         /* Do not assign attenuation values for lights that do not use them. D3D apps are free to pass any junk,
3087          * but gl drivers use them and may crash due to bad Attenuation values. Need for Speed most wanted sets
3088          * Attenuation0 to NaN and crashes in the gl lib
3089          */
3090
3091         switch (lightInfo->OriginalParms.Type) {
3092             case WINED3DLIGHT_POINT:
3093                 /* Position */
3094                 glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]);
3095                 checkGLcall("glLightfv");
3096                 glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
3097                 checkGLcall("glLightf");
3098                 /* Attenuation - Are these right? guessing... */
3099                 glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,  lightInfo->OriginalParms.Attenuation0);
3100                 checkGLcall("glLightf");
3101                 glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,    lightInfo->OriginalParms.Attenuation1);
3102                 checkGLcall("glLightf");
3103                 if (quad_att < lightInfo->OriginalParms.Attenuation2) quad_att = lightInfo->OriginalParms.Attenuation2;
3104                 glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
3105                 checkGLcall("glLightf");
3106                 /* FIXME: Range */
3107                 break;
3108
3109             case WINED3DLIGHT_SPOT:
3110                 /* Position */
3111                 glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]);
3112                 checkGLcall("glLightfv");
3113                 /* Direction */
3114                 glLightfv(GL_LIGHT0 + Index, GL_SPOT_DIRECTION, &lightInfo->lightDirn[0]);
3115                 checkGLcall("glLightfv");
3116                 glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, lightInfo->exponent);
3117                 checkGLcall("glLightf");
3118                 glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
3119                 checkGLcall("glLightf");
3120                 /* Attenuation - Are these right? guessing... */
3121                 glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,  lightInfo->OriginalParms.Attenuation0);
3122                 checkGLcall("glLightf");
3123                 glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,    lightInfo->OriginalParms.Attenuation1);
3124                 checkGLcall("glLightf");
3125                 if (quad_att < lightInfo->OriginalParms.Attenuation2) quad_att = lightInfo->OriginalParms.Attenuation2;
3126                 glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
3127                 checkGLcall("glLightf");
3128                 /* FIXME: Range */
3129                 break;
3130
3131             case WINED3DLIGHT_DIRECTIONAL:
3132                 /* Direction */
3133                 glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]); /* Note gl uses w position of 0 for direction! */
3134                 checkGLcall("glLightfv");
3135                 glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
3136                 checkGLcall("glLightf");
3137                 glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, 0.0f);
3138                 checkGLcall("glLightf");
3139                 break;
3140
3141             default:
3142                 FIXME("Unrecognized light type %d\n", lightInfo->OriginalParms.Type);
3143         }
3144
3145         /* Restore the modelview matrix */
3146         glPopMatrix();
3147
3148         glEnable(GL_LIGHT0 + Index);
3149         checkGLcall("glEnable(GL_LIGHT0 + Index)");
3150     }
3151
3152     return;
3153 }
3154
3155 static void scissorrect(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3156     IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) stateblock->wineD3DDevice->swapchains[0];
3157     RECT *pRect = &stateblock->scissorRect;
3158     RECT windowRect;
3159     UINT winHeight;
3160
3161     GetClientRect(swapchain->win_handle, &windowRect);
3162     /* Warning: glScissor uses window coordinates, not viewport coordinates, so our viewport correction does not apply
3163      * Warning2: Even in windowed mode the coords are relative to the window, not the screen
3164      */
3165     winHeight = windowRect.bottom - windowRect.top;
3166     TRACE("(%p) Setting new Scissor Rect to %d:%d-%d:%d\n", stateblock->wineD3DDevice, pRect->left, pRect->bottom - winHeight,
3167           pRect->right - pRect->left, pRect->bottom - pRect->top);
3168     glScissor(pRect->left, winHeight - pRect->bottom, pRect->right - pRect->left, pRect->bottom - pRect->top);
3169     checkGLcall("glScissor");
3170 }
3171
3172 static void indexbuffer(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3173     if(GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT)) {
3174         if(stateblock->streamIsUP || stateblock->pIndexData == NULL ) {
3175             GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
3176         } else {
3177             IWineD3DIndexBufferImpl *ib = (IWineD3DIndexBufferImpl *) stateblock->pIndexData;
3178             GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib->vbo));
3179         }
3180     }
3181 }
3182
3183 const struct StateEntry StateTable[] =
3184 {
3185       /* State name                                         representative,                                     apply function */
3186     { /* 0,  Undefined                              */      0,                                                  state_undefined     },
3187     { /* 1,  WINED3DRS_TEXTUREHANDLE                */      0 /* Handled in ddraw */,                           state_undefined     },
3188     { /* 2,  WINED3DRS_ANTIALIAS                    */      STATE_RENDER(WINED3DRS_ANTIALIAS),                  state_antialias     },
3189     { /* 3,  WINED3DRS_TEXTUREADDRESS               */      0 /* Handled in ddraw */,                           state_undefined     },
3190     { /* 4,  WINED3DRS_TEXTUREPERSPECTIVE           */      STATE_RENDER(WINED3DRS_TEXTUREPERSPECTIVE),         state_perspective   },
3191     { /* 5,  WINED3DRS_WRAPU                        */      STATE_RENDER(WINED3DRS_WRAPU),                      state_wrapu         },
3192     { /* 6,  WINED3DRS_WRAPV                        */      STATE_RENDER(WINED3DRS_WRAPV),                      state_wrapv         },
3193     { /* 7,  WINED3DRS_ZENABLE                      */      STATE_RENDER(WINED3DRS_ZENABLE),                    state_zenable       },
3194     { /* 8,  WINED3DRS_FILLMODE                     */      STATE_RENDER(WINED3DRS_FILLMODE),                   state_fillmode      },
3195     { /* 9,  WINED3DRS_SHADEMODE                    */      STATE_RENDER(WINED3DRS_SHADEMODE),                  state_shademode     },
3196     { /* 10, WINED3DRS_LINEPATTERN                  */      STATE_RENDER(WINED3DRS_LINEPATTERN),                state_linepattern   },
3197     { /* 11, WINED3DRS_MONOENABLE                   */      STATE_RENDER(WINED3DRS_MONOENABLE),                 state_monoenable    },
3198     { /* 12, WINED3DRS_ROP2                         */      STATE_RENDER(WINED3DRS_ROP2),                       state_rop2          },
3199     { /* 13, WINED3DRS_PLANEMASK                    */      STATE_RENDER(WINED3DRS_PLANEMASK),                  state_planemask     },
3200     { /* 14, WINED3DRS_ZWRITEENABLE                 */      STATE_RENDER(WINED3DRS_ZWRITEENABLE),               state_zwritenable   },
3201     { /* 15, WINED3DRS_ALPHATESTENABLE              */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
3202     { /* 16, WINED3DRS_LASTPIXEL                    */      STATE_RENDER(WINED3DRS_LASTPIXEL),                  state_lastpixel     },
3203     { /* 17, WINED3DRS_TEXTUREMAG                   */      0 /* Handled in ddraw */,                           state_undefined     },
3204     { /* 18, WINED3DRS_TEXTUREMIN                   */      0 /* Handled in ddraw */,                           state_undefined     },
3205     { /* 19, WINED3DRS_SRCBLEND                     */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
3206     { /* 20, WINED3DRS_DESTBLEND                    */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
3207     { /* 21, WINED3DRS_TEXTUREMAPBLEND              */      0 /* Handled in ddraw */,                           state_undefined     },
3208     { /* 22, WINED3DRS_CULLMODE                     */      STATE_RENDER(WINED3DRS_CULLMODE),                   state_cullmode      },
3209     { /* 23, WINED3DRS_ZFUNC                        */      STATE_RENDER(WINED3DRS_ZFUNC),                      state_zfunc         },
3210     { /* 24, WINED3DRS_ALPHAREF                     */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
3211     { /* 25, WINED3DRS_ALPHAFUNC                    */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
3212     { /* 26, WINED3DRS_DITHERENABLE                 */      STATE_RENDER(WINED3DRS_DITHERENABLE),               state_ditherenable  },
3213     { /* 27, WINED3DRS_ALPHABLENDENABLE             */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
3214     { /* 28, WINED3DRS_FOGENABLE                    */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
3215     { /* 29, WINED3DRS_SPECULARENABLE               */      STATE_RENDER(WINED3DRS_SPECULARENABLE),             state_specularenable},
3216     { /* 30, WINED3DRS_ZVISIBLE                     */      0 /* Not supported according to the msdn */,        state_nogl          },
3217     { /* 31, WINED3DRS_SUBPIXEL                     */      STATE_RENDER(WINED3DRS_SUBPIXEL),                   state_subpixel      },
3218     { /* 32, WINED3DRS_SUBPIXELX                    */      STATE_RENDER(WINED3DRS_SUBPIXELX),                  state_subpixelx     },
3219     { /* 33, WINED3DRS_STIPPLEDALPHA                */      STATE_RENDER(WINED3DRS_STIPPLEDALPHA),              state_stippledalpha },
3220     { /* 34, WINED3DRS_FOGCOLOR                     */      STATE_RENDER(WINED3DRS_FOGCOLOR),                   state_fogcolor      },
3221     { /* 35, WINED3DRS_FOGTABLEMODE                 */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
3222     { /* 36, WINED3DRS_FOGSTART                     */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
3223     { /* 37, WINED3DRS_FOGEND                       */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
3224     { /* 38, WINED3DRS_FOGDENSITY                   */      STATE_RENDER(WINED3DRS_FOGDENSITY),                 state_fogdensity    },
3225     { /* 39, WINED3DRS_STIPPLEENABLE                */      STATE_RENDER(WINED3DRS_STIPPLEENABLE),              state_stippleenable },
3226     { /* 40, WINED3DRS_EDGEANTIALIAS                */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
3227     { /* 41, WINED3DRS_COLORKEYENABLE               */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
3228     { /* 42, undefined                              */      0,                                                  state_undefined     },
3229     { /* 43, WINED3DRS_BORDERCOLOR                  */      STATE_RENDER(WINED3DRS_BORDERCOLOR),                state_bordercolor   },
3230     { /* 44, WINED3DRS_TEXTUREADDRESSU              */      0, /* Handled in ddraw */                           state_undefined     },
3231     { /* 45, WINED3DRS_TEXTUREADDRESSV              */      0, /* Handled in ddraw */                           state_undefined     },
3232     { /* 46, WINED3DRS_MIPMAPLODBIAS                */      STATE_RENDER(WINED3DRS_MIPMAPLODBIAS),              state_mipmaplodbias },
3233     { /* 47, WINED3DRS_ZBIAS                        */      STATE_RENDER(WINED3DRS_ZBIAS),                      state_zbias         },
3234     { /* 48, WINED3DRS_RANGEFOGENABLE               */      0,                                                  state_nogl          },
3235     { /* 49, WINED3DRS_ANISOTROPY                   */      STATE_RENDER(WINED3DRS_ANISOTROPY),                 state_anisotropy    },
3236     { /* 50, WINED3DRS_FLUSHBATCH                   */      STATE_RENDER(WINED3DRS_FLUSHBATCH),                 state_flushbatch    },
3237     { /* 51, WINED3DRS_TRANSLUCENTSORTINDEPENDENT   */      STATE_RENDER(WINED3DRS_TRANSLUCENTSORTINDEPENDENT), state_translucentsi },
3238     { /* 52, WINED3DRS_STENCILENABLE                */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3239     { /* 53, WINED3DRS_STENCILFAIL                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3240     { /* 54, WINED3DRS_STENCILZFAIL                 */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3241     { /* 55, WINED3DRS_STENCILPASS                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3242     { /* 56, WINED3DRS_STENCILFUNC                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3243     { /* 57, WINED3DRS_STENCILREF                   */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3244     { /* 58, WINED3DRS_STENCILMASK                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3245     { /* 59, WINED3DRS_STENCILWRITEMASK             */      STATE_RENDER(WINED3DRS_STENCILWRITEMASK),           state_stencilwrite  },
3246     { /* 60, WINED3DRS_TEXTUREFACTOR                */      STATE_RENDER(WINED3DRS_TEXTUREFACTOR),              state_texfactor     },
3247     { /* 61, Undefined                              */      0,                                                  state_undefined     },
3248     { /* 62, Undefined                              */      0,                                                  state_undefined     },
3249     { /* 63, Undefined                              */      0,                                                  state_undefined     },
3250     { /* 64, WINED3DRS_STIPPLEPATTERN00             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3251     { /* 65, WINED3DRS_STIPPLEPATTERN01             */      0 /* Obsolete, should he handled by ddraw */,       state_undefined     },
3252     { /* 66, WINED3DRS_STIPPLEPATTERN02             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3253     { /* 67, WINED3DRS_STIPPLEPATTERN03             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3254     { /* 68, WINED3DRS_STIPPLEPATTERN04             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3255     { /* 69, WINED3DRS_STIPPLEPATTERN05             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3256     { /* 70, WINED3DRS_STIPPLEPATTERN06             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3257     { /* 71, WINED3DRS_STIPPLEPATTERN07             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3258     { /* 72, WINED3DRS_STIPPLEPATTERN08             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3259     { /* 73, WINED3DRS_STIPPLEPATTERN09             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3260     { /* 74, WINED3DRS_STIPPLEPATTERN10             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3261     { /* 75, WINED3DRS_STIPPLEPATTERN11             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3262     { /* 76, WINED3DRS_STIPPLEPATTERN12             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3263     { /* 77, WINED3DRS_STIPPLEPATTERN13             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3264     { /* 78, WINED3DRS_STIPPLEPATTERN14             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3265     { /* 79, WINED3DRS_STIPPLEPATTERN15             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3266     { /* 80, WINED3DRS_STIPPLEPATTERN16             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3267     { /* 81, WINED3DRS_STIPPLEPATTERN17             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3268     { /* 82, WINED3DRS_STIPPLEPATTERN18             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3269     { /* 83, WINED3DRS_STIPPLEPATTERN19             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3270     { /* 84, WINED3DRS_STIPPLEPATTERN20             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3271     { /* 85, WINED3DRS_STIPPLEPATTERN21             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3272     { /* 86, WINED3DRS_STIPPLEPATTERN22             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3273     { /* 87, WINED3DRS_STIPPLEPATTERN23             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3274     { /* 88, WINED3DRS_STIPPLEPATTERN24             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3275     { /* 89, WINED3DRS_STIPPLEPATTERN25             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3276     { /* 90, WINED3DRS_STIPPLEPATTERN26             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3277     { /* 91, WINED3DRS_STIPPLEPATTERN27             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3278     { /* 92, WINED3DRS_STIPPLEPATTERN28             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3279     { /* 93, WINED3DRS_STIPPLEPATTERN29             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3280     { /* 94, WINED3DRS_STIPPLEPATTERN30             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3281     { /* 95, WINED3DRS_STIPPLEPATTERN31             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
3282     { /* 96, Undefined                              */      0,                                                  state_undefined     },
3283     { /* 97, Undefined                              */      0,                                                  state_undefined     },
3284     { /* 98, Undefined                              */      0,                                                  state_undefined     },
3285     { /* 99, Undefined                              */      0,                                                  state_undefined     },
3286     { /*100, Undefined                              */      0,                                                  state_undefined     },
3287     { /*101, Undefined                              */      0,                                                  state_undefined     },
3288     { /*102, Undefined                              */      0,                                                  state_undefined     },
3289     { /*103, Undefined                              */      0,                                                  state_undefined     },
3290     { /*104, Undefined                              */      0,                                                  state_undefined     },
3291     { /*105, Undefined                              */      0,                                                  state_undefined     },
3292     { /*106, Undefined                              */      0,                                                  state_undefined     },
3293     { /*107, Undefined                              */      0,                                                  state_undefined     },
3294     { /*108, Undefined                              */      0,                                                  state_undefined     },
3295     { /*109, Undefined                              */      0,                                                  state_undefined     },
3296     { /*110, Undefined                              */      0,                                                  state_undefined     },
3297     { /*111, Undefined                              */      0,                                                  state_undefined     },
3298     { /*112, Undefined                              */      0,                                                  state_undefined     },
3299     { /*113, Undefined                              */      0,                                                  state_undefined     },
3300     { /*114, Undefined                              */      0,                                                  state_undefined     },
3301     { /*115, Undefined                              */      0,                                                  state_undefined     },
3302     { /*116, Undefined                              */      0,                                                  state_undefined     },
3303     { /*117, Undefined                              */      0,                                                  state_undefined     },
3304     { /*118, Undefined                              */      0,                                                  state_undefined     },
3305     { /*119, Undefined                              */      0,                                                  state_undefined     },
3306     { /*120, Undefined                              */      0,                                                  state_undefined     },
3307     { /*121, Undefined                              */      0,                                                  state_undefined     },
3308     { /*122, Undefined                              */      0,                                                  state_undefined     },
3309     { /*123, Undefined                              */      0,                                                  state_undefined     },
3310     { /*124, Undefined                              */      0,                                                  state_undefined     },
3311     { /*125, Undefined                              */      0,                                                  state_undefined     },
3312     { /*126, Undefined                              */      0,                                                  state_undefined     },
3313     { /*127, Undefined                              */      0,                                                  state_undefined     },
3314     /* Big hole ends */
3315     { /*128, WINED3DRS_WRAP0                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3316     { /*129, WINED3DRS_WRAP1                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3317     { /*130, WINED3DRS_WRAP2                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3318     { /*131, WINED3DRS_WRAP3                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3319     { /*132, WINED3DRS_WRAP4                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3320     { /*133, WINED3DRS_WRAP5                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3321     { /*134, WINED3DRS_WRAP6                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3322     { /*135, WINED3DRS_WRAP7                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3323     { /*136, WINED3DRS_CLIPPING                     */      STATE_RENDER(WINED3DRS_CLIPPING),                   state_clipping      },
3324     { /*137, WINED3DRS_LIGHTING                     */      STATE_RENDER(WINED3DRS_LIGHTING),                   state_lighting      },
3325     { /*138, WINED3DRS_EXTENTS                      */      STATE_RENDER(WINED3DRS_EXTENTS),                    state_extents       },
3326     { /*139, WINED3DRS_AMBIENT                      */      STATE_RENDER(WINED3DRS_AMBIENT),                    state_ambient       },
3327     { /*140, WINED3DRS_FOGVERTEXMODE                */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
3328     { /*141, WINED3DRS_COLORVERTEX                  */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
3329     { /*142, WINED3DRS_LOCALVIEWER                  */      STATE_RENDER(WINED3DRS_LOCALVIEWER),                state_localviewer   },
3330     { /*143, WINED3DRS_NORMALIZENORMALS             */      STATE_RENDER(WINED3DRS_NORMALIZENORMALS),           state_normalize     },
3331     { /*144, WINED3DRS_COLORKEYBLENDENABLE          */      STATE_RENDER(WINED3DRS_COLORKEYBLENDENABLE),        state_ckeyblend     },
3332     { /*145, WINED3DRS_DIFFUSEMATERIALSOURCE        */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
3333     { /*146, WINED3DRS_SPECULARMATERIALSOURCE       */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
3334     { /*147, WINED3DRS_AMBIENTMATERIALSOURCE        */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
3335     { /*148, WINED3DRS_EMISSIVEMATERIALSOURCE       */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
3336     { /*149, Undefined                              */      0,                                                  state_undefined     },
3337     { /*150, Undefined                              */      0,                                                  state_undefined     },
3338     { /*151, WINED3DRS_VERTEXBLEND                  */      0,                                                  state_nogl          },
3339     { /*152, WINED3DRS_CLIPPLANEENABLE              */      STATE_RENDER(WINED3DRS_CLIPPING),                   state_clipping      },
3340     { /*153, WINED3DRS_SOFTWAREVERTEXPROCESSING     */      0,                                                  state_nogl          },
3341     { /*154, WINED3DRS_POINTSIZE                    */      STATE_RENDER(WINED3DRS_POINTSIZE),                  state_psize         },
3342     { /*155, WINED3DRS_POINTSIZE_MIN                */      STATE_RENDER(WINED3DRS_POINTSIZE_MIN),              state_psizemin      },
3343     { /*156, WINED3DRS_POINTSPRITEENABLE            */      STATE_RENDER(WINED3DRS_POINTSPRITEENABLE),          state_pointsprite   },
3344     { /*157, WINED3DRS_POINTSCALEENABLE             */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
3345     { /*158, WINED3DRS_POINTSCALE_A                 */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
3346     { /*159, WINED3DRS_POINTSCALE_B                 */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
3347     { /*160, WINED3DRS_POINTSCALE_C                 */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
3348     { /*161, WINED3DRS_MULTISAMPLEANTIALIAS         */      STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS),       state_multisampleaa },
3349     { /*162, WINED3DRS_MULTISAMPLEMASK              */      STATE_RENDER(WINED3DRS_MULTISAMPLEMASK),            state_multisampmask },
3350     { /*163, WINED3DRS_PATCHEDGESTYLE               */      STATE_RENDER(WINED3DRS_PATCHEDGESTYLE),             state_patchedgestyle},
3351     { /*164, WINED3DRS_PATCHSEGMENTS                */      STATE_RENDER(WINED3DRS_PATCHSEGMENTS),              state_patchsegments },
3352     { /*165, WINED3DRS_DEBUGMONITORTOKEN            */      STATE_RENDER(WINED3DRS_DEBUGMONITORTOKEN),          state_nogl          },
3353     { /*166, WINED3DRS_POINTSIZE_MAX                */      STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              state_psizemax      },
3354     { /*167, WINED3DRS_INDEXEDVERTEXBLENDENABLE     */      0,                                                  state_nogl          },
3355     { /*168, WINED3DRS_COLORWRITEENABLE             */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
3356     { /*169, Undefined                              */      0,                                                  state_undefined     },
3357     { /*170, WINED3DRS_TWEENFACTOR                  */      0,                                                  state_nogl          },
3358     { /*171, WINED3DRS_BLENDOP                      */      STATE_RENDER(WINED3DRS_BLENDOP),                    state_blendop       },
3359     { /*172, WINED3DRS_POSITIONDEGREE               */      STATE_RENDER(WINED3DRS_POSITIONDEGREE),             state_positiondegree},
3360     { /*173, WINED3DRS_NORMALDEGREE                 */      STATE_RENDER(WINED3DRS_NORMALDEGREE),               state_normaldegree  },
3361       /*172, WINED3DRS_POSITIONORDER                */      /* Value assigned to 2 state names */
3362       /*173, WINED3DRS_NORMALORDER                  */      /* Value assigned to 2 state names */
3363     { /*174, WINED3DRS_SCISSORTESTENABLE            */      STATE_RENDER(WINED3DRS_SCISSORTESTENABLE),          state_scissor       },
3364     { /*175, WINED3DRS_SLOPESCALEDEPTHBIAS          */      STATE_RENDER(WINED3DRS_DEPTHBIAS),                  state_depthbias     },
3365     { /*176, WINED3DRS_ANTIALIASEDLINEENABLE        */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
3366     { /*177, undefined                              */      0,                                                  state_undefined     },
3367     { /*178, WINED3DRS_MINTESSELLATIONLEVEL         */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
3368     { /*179, WINED3DRS_MAXTESSELLATIONLEVEL         */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
3369     { /*180, WINED3DRS_ADAPTIVETESS_X               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
3370     { /*181, WINED3DRS_ADAPTIVETESS_Y               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
3371     { /*182, WINED3DRS_ADAPTIVETESS_Z               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
3372     { /*183, WINED3DRS_ADAPTIVETESS_W               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
3373     { /*184, WINED3DRS_ENABLEADAPTIVETESSELLATION   */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
3374     { /*185, WINED3DRS_TWOSIDEDSTENCILMODE          */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3375     { /*186, WINED3DRS_CCW_STENCILFAIL              */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3376     { /*187, WINED3DRS_CCW_STENCILZFAIL             */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3377     { /*188, WINED3DRS_CCW_STENCILPASS              */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3378     { /*189, WINED3DRS_CCW_STENCILFUNC              */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
3379     { /*190, WINED3DRS_COLORWRITEENABLE1            */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
3380     { /*191, WINED3DRS_COLORWRITEENABLE2            */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
3381     { /*192, WINED3DRS_COLORWRITEENABLE3            */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
3382     { /*193, WINED3DRS_BLENDFACTOR                  */      STATE_RENDER(WINED3DRS_BLENDFACTOR),                state_blendfactor   },
3383     { /*194, WINED3DRS_SRGBWRITEENABLE              */      STATE_RENDER(WINED3DRS_SRGBWRITEENABLE),            state_srgbwrite     },
3384     { /*195, WINED3DRS_DEPTHBIAS                    */      STATE_RENDER(WINED3DRS_DEPTHBIAS),                  state_depthbias     },
3385     { /*196, undefined                              */      0,                                                  state_undefined     },
3386     { /*197, undefined                              */      0,                                                  state_undefined     },
3387     { /*198, WINED3DRS_WRAP8                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3388     { /*199, WINED3DRS_WRAP9                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3389     { /*200, WINED3DRS_WRAP10                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3390     { /*201, WINED3DRS_WRAP11                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3391     { /*202, WINED3DRS_WRAP12                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3392     { /*203, WINED3DRS_WRAP13                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3393     { /*204, WINED3DRS_WRAP14                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3394     { /*205, WINED3DRS_WRAP15                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
3395     { /*206, WINED3DRS_SEPARATEALPHABLENDENABLE     */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
3396     { /*207, WINED3DRS_SRCBLENDALPHA                */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
3397     { /*208, WINED3DRS_DESTBLENDALPHA               */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
3398     { /*209, WINED3DRS_BLENDOPALPHA                 */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
3399     /* Texture stage states */
3400     { /*0, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
3401     { /*0, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
3402     { /*0, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
3403     { /*0, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3404     { /*0, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3405     { /*0, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3406     { /*0, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3407     { /*0, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3408     { /*0, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3409     { /*0, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3410     { /*0, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(0, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3411     { /*0, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3412     { /*0, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3413     { /*0, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3414     { /*0, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3415     { /*0, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3416     { /*0, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3417     { /*0, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3418     { /*0, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3419     { /*0, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3420     { /*0, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3421     { /*0, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3422     { /*0, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3423     { /*0, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE0),                transform_texture   },
3424     { /*0, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3425     { /*0, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
3426     { /*0, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3427     { /*0, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG),        tex_resultarg       },
3428     { /*0, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3429     { /*0, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3430     { /*0, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3431     { /*0, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3432
3433     { /*1, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
3434     { /*1, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
3435     { /*1, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
3436     { /*1, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3437     { /*1, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3438     { /*1, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3439     { /*1, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3440     { /*1, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3441     { /*1, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3442     { /*1, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3443     { /*1, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(1, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3444     { /*1, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3445     { /*1, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3446     { /*1, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3447     { /*1, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3448     { /*1, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3449     { /*1, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3450     { /*1, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3451     { /*1, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3452     { /*1, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3453     { /*1, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3454     { /*1, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3455     { /*1, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3456     { /*1, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE1),                transform_texture   },
3457     { /*1, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3458     { /*1, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
3459     { /*1, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3460     { /*1, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG),        tex_resultarg       },
3461     { /*1, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3462     { /*1, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3463     { /*1, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3464     { /*1, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3465
3466     { /*2, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
3467     { /*2, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
3468     { /*2, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
3469     { /*2, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3470     { /*2, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3471     { /*2, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3472     { /*2, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3473     { /*2, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3474     { /*2, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3475     { /*2, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3476     { /*2, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(2, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3477     { /*2, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3478     { /*2, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3479     { /*2, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3480     { /*2, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3481     { /*2, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3482     { /*2, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3483     { /*2, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3484     { /*2, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3485     { /*2, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3486     { /*2, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3487     { /*2, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3488     { /*2, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3489     { /*2, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE2),                transform_texture   },
3490     { /*2, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3491     { /*2, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
3492     { /*2, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3493     { /*2, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG),        tex_resultarg       },
3494     { /*2, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3495     { /*2, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3496     { /*2, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3497     { /*2, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3498
3499     { /*3, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
3500     { /*3, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
3501     { /*3, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
3502     { /*3, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3503     { /*3, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3504     { /*3, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3505     { /*3, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3506     { /*3, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3507     { /*3, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3508     { /*3, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3509     { /*3, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(3, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3510     { /*3, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3511     { /*3, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3512     { /*3, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3513     { /*3, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3514     { /*3, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3515     { /*3, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3516     { /*3, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3517     { /*3, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3518     { /*3, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3519     { /*3, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3520     { /*3, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3521     { /*3, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3522     { /*3, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE3),                transform_texture   },
3523     { /*3, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3524     { /*3, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
3525     { /*3, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3526     { /*3, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG),        tex_resultarg       },
3527     { /*3, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3528     { /*3, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3529     { /*3, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3530     { /*3, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3531
3532     { /*4, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
3533     { /*4, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
3534     { /*4, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
3535     { /*4, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3536     { /*4, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3537     { /*4, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3538     { /*4, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3539     { /*4, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3540     { /*4, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3541     { /*4, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3542     { /*4, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(4, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3543     { /*4, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3544     { /*4, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3545     { /*4, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3546     { /*4, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3547     { /*4, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3548     { /*4, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3549     { /*4, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3550     { /*4, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3551     { /*4, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3552     { /*4, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3553     { /*4, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3554     { /*4, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3555     { /*4, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE4),                transform_texture   },
3556     { /*4, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3557     { /*4, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
3558     { /*4, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3559     { /*4, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG),        tex_resultarg       },
3560     { /*4, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3561     { /*4, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3562     { /*4, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3563     { /*4, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3564
3565     { /*5, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
3566     { /*5, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
3567     { /*5, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
3568     { /*5, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3569     { /*5, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3570     { /*5, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3571     { /*5, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3572     { /*5, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3573     { /*5, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3574     { /*5, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3575     { /*5, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(5, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3576     { /*5, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3577     { /*5, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3578     { /*5, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3579     { /*5, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3580     { /*5, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3581     { /*5, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3582     { /*5, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3583     { /*5, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3584     { /*5, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3585     { /*5, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3586     { /*5, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3587     { /*5, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3588     { /*5, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE5),                transform_texture   },
3589     { /*5, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3590     { /*5, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
3591     { /*5, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3592     { /*5, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG),        tex_resultarg       },
3593     { /*5, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3594     { /*5, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3595     { /*5, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3596     { /*5, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3597
3598     { /*6, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
3599     { /*6, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
3600     { /*6, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
3601     { /*6, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3602     { /*6, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3603     { /*6, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3604     { /*6, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3605     { /*6, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3606     { /*6, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3607     { /*6, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3608     { /*6, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(6, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3609     { /*6, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3610     { /*6, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3611     { /*6, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3612     { /*6, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3613     { /*6, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3614     { /*6, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3615     { /*6, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3616     { /*6, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3617     { /*6, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3618     { /*6, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3619     { /*6, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3620     { /*6, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3621     { /*6, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE6),                transform_texture   },
3622     { /*6, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3623     { /*6, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
3624     { /*6, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3625     { /*6, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG),        tex_resultarg       },
3626     { /*6, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3627     { /*6, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3628     { /*6, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3629     { /*6, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3630
3631     { /*7, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
3632     { /*7, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
3633     { /*7, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
3634     { /*7, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3635     { /*7, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3636     { /*7, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3637     { /*7, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3638     { /*7, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3639     { /*7, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3640     { /*7, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      },
3641     { /*7, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(7, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
3642     { /*7, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3643     { /*7, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3644     { /*7, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3645     { /*7, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3646     { /*7, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3647     { /*7, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3648     { /*7, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3649     { /*7, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3650     { /*7, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3651     { /*7, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3652     { /*7, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
3653     { /*7, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLOFFSET),   tex_bumpenvloffset  },
3654     { /*7, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TRANSFORM(WINED3DTS_TEXTURE7),                transform_texture   },
3655     { /*7, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3656     { /*7, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
3657     { /*7, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
3658     { /*7, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG),        tex_resultarg       },
3659     { /*7, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3660     { /*7, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3661     { /*7, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
3662     { /*7, 32, WINED3DTSS_CONSTANT                  */      0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl          },
3663     /* Sampler states */
3664     { /* 0, Sampler 0                               */      STATE_SAMPLER(0),                                   sampler             },
3665     { /* 1, Sampler 1                               */      STATE_SAMPLER(1),                                   sampler             },
3666     { /* 2, Sampler 2                               */      STATE_SAMPLER(2),                                   sampler             },
3667     { /* 3, Sampler 3                               */      STATE_SAMPLER(3),                                   sampler             },
3668     { /* 4, Sampler 3                               */      STATE_SAMPLER(4),                                   sampler             },
3669     { /* 5, Sampler 5                               */      STATE_SAMPLER(5),                                   sampler             },
3670     { /* 6, Sampler 6                               */      STATE_SAMPLER(6),                                   sampler             },
3671     { /* 7, Sampler 7                               */      STATE_SAMPLER(7),                                   sampler             },
3672     { /* 8, Sampler 8                               */      STATE_SAMPLER(8),                                   sampler             },
3673     { /* 9, Sampler 9                               */      STATE_SAMPLER(9),                                   sampler             },
3674     { /*10, Sampler 10                              */      STATE_SAMPLER(10),                                  sampler             },
3675     { /*11, Sampler 11                              */      STATE_SAMPLER(11),                                  sampler             },
3676     { /*12, Sampler 12                              */      STATE_SAMPLER(12),                                  sampler             },
3677     { /*13, Sampler 13                              */      STATE_SAMPLER(13),                                  sampler             },
3678     { /*14, Sampler 14                              */      STATE_SAMPLER(14),                                  sampler             },
3679     { /*15, Sampler 15                              */      STATE_SAMPLER(15),                                  sampler             },
3680     /* Pixel shader */
3681     { /*  , Pixel Shader                            */      STATE_PIXELSHADER,                                  pixelshader         },
3682       /* Transform states follow                    */
3683     { /*  1, undefined                              */      0,                                                  state_undefined     },
3684     { /*  2, WINED3DTS_VIEW                         */      STATE_TRANSFORM(WINED3DTS_VIEW),                    transform_view      },
3685     { /*  3, WINED3DTS_PROJECTION                   */      STATE_TRANSFORM(WINED3DTS_PROJECTION),              transform_projection},
3686     { /*  4, undefined                              */      0,                                                  state_undefined     },
3687     { /*  5, undefined                              */      0,                                                  state_undefined     },
3688     { /*  6, undefined                              */      0,                                                  state_undefined     },
3689     { /*  7, undefined                              */      0,                                                  state_undefined     },
3690     { /*  8, undefined                              */      0,                                                  state_undefined     },
3691     { /*  9, undefined                              */      0,                                                  state_undefined     },
3692     { /* 10, undefined                              */      0,                                                  state_undefined     },
3693     { /* 11, undefined                              */      0,                                                  state_undefined     },
3694     { /* 12, undefined                              */      0,                                                  state_undefined     },
3695     { /* 13, undefined                              */      0,                                                  state_undefined     },
3696     { /* 14, undefined                              */      0,                                                  state_undefined     },
3697     { /* 15, undefined                              */      0,                                                  state_undefined     },
3698     { /* 16, WINED3DTS_TEXTURE0                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE0),                transform_texture   },
3699     { /* 17, WINED3DTS_TEXTURE1                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE1),                transform_texture   },
3700     { /* 18, WINED3DTS_TEXTURE2                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE2),                transform_texture   },
3701     { /* 19, WINED3DTS_TEXTURE3                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE3),                transform_texture   },
3702     { /* 20, WINED3DTS_TEXTURE4                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE4),                transform_texture   },
3703     { /* 21, WINED3DTS_TEXTURE5                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE5),                transform_texture   },
3704     { /* 22, WINED3DTS_TEXTURE6                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE6),                transform_texture   },
3705     { /* 23, WINED3DTS_TEXTURE7                     */      STATE_TRANSFORM(WINED3DTS_TEXTURE7),                transform_texture   },
3706       /* A huge gap between TEXTURE7 and WORLDMATRIX(0) :-( But entries are needed to catch then if a broken app sets them */
3707     { /* 24, undefined                              */      0,                                                  state_undefined     },
3708     { /* 25, undefined                              */      0,                                                  state_undefined     },
3709     { /* 26, undefined                              */      0,                                                  state_undefined     },
3710     { /* 27, undefined                              */      0,                                                  state_undefined     },
3711     { /* 28, undefined                              */      0,                                                  state_undefined     },
3712     { /* 29, undefined                              */      0,                                                  state_undefined     },
3713     { /* 30, undefined                              */      0,                                                  state_undefined     },
3714     { /* 31, undefined                              */      0,                                                  state_undefined     },
3715     { /* 32, undefined                              */      0,                                                  state_undefined     },
3716     { /* 33, undefined                              */      0,                                                  state_undefined     },
3717     { /* 34, undefined                              */      0,                                                  state_undefined     },
3718     { /* 35, undefined                              */      0,                                                  state_undefined     },
3719     { /* 36, undefined                              */      0,                                                  state_undefined     },
3720     { /* 37, undefined                              */      0,                                                  state_undefined     },
3721     { /* 38, undefined                              */      0,                                                  state_undefined     },
3722     { /* 39, undefined                              */      0,                                                  state_undefined     },
3723     { /* 40, undefined                              */      0,                                                  state_undefined     },
3724     { /* 41, undefined                              */      0,                                                  state_undefined     },
3725     { /* 42, undefined                              */      0,                                                  state_undefined     },
3726     { /* 43, undefined                              */      0,                                                  state_undefined     },
3727     { /* 44, undefined                              */      0,                                                  state_undefined     },
3728     { /* 45, undefined                              */      0,                                                  state_undefined     },
3729     { /* 46, undefined                              */      0,                                                  state_undefined     },
3730     { /* 47, undefined                              */      0,                                                  state_undefined     },
3731     { /* 48, undefined                              */      0,                                                  state_undefined     },
3732     { /* 49, undefined                              */      0,                                                  state_undefined     },
3733     { /* 50, undefined                              */      0,                                                  state_undefined     },
3734     { /* 51, undefined                              */      0,                                                  state_undefined     },
3735     { /* 52, undefined                              */      0,                                                  state_undefined     },
3736     { /* 53, undefined                              */      0,                                                  state_undefined     },
3737     { /* 54, undefined                              */      0,                                                  state_undefined     },
3738     { /* 55, undefined                              */      0,                                                  state_undefined     },
3739     { /* 56, undefined                              */      0,                                                  state_undefined     },
3740     { /* 57, undefined                              */      0,                                                  state_undefined     },
3741     { /* 58, undefined                              */      0,                                                  state_undefined     },
3742     { /* 59, undefined                              */      0,                                                  state_undefined     },
3743     { /* 60, undefined                              */      0,                                                  state_undefined     },
3744     { /* 61, undefined                              */      0,                                                  state_undefined     },
3745     { /* 62, undefined                              */      0,                                                  state_undefined     },
3746     { /* 63, undefined                              */      0,                                                  state_undefined     },
3747     { /* 64, undefined                              */      0,                                                  state_undefined     },
3748     { /* 65, undefined                              */      0,                                                  state_undefined     },
3749     { /* 66, undefined                              */      0,                                                  state_undefined     },
3750     { /* 67, undefined                              */      0,                                                  state_undefined     },
3751     { /* 68, undefined                              */      0,                                                  state_undefined     },
3752     { /* 69, undefined                              */      0,                                                  state_undefined     },
3753     { /* 70, undefined                              */      0,                                                  state_undefined     },
3754     { /* 71, undefined                              */      0,                                                  state_undefined     },
3755     { /* 72, undefined                              */      0,                                                  state_undefined     },
3756     { /* 73, undefined                              */      0,                                                  state_undefined     },
3757     { /* 74, undefined                              */      0,                                                  state_undefined     },
3758     { /* 75, undefined                              */      0,                                                  state_undefined     },
3759     { /* 76, undefined                              */      0,                                                  state_undefined     },
3760     { /* 77, undefined                              */      0,                                                  state_undefined     },
3761     { /* 78, undefined                              */      0,                                                  state_undefined     },
3762     { /* 79, undefined                              */      0,                                                  state_undefined     },
3763     { /* 80, undefined                              */      0,                                                  state_undefined     },
3764     { /* 81, undefined                              */      0,                                                  state_undefined     },
3765     { /* 82, undefined                              */      0,                                                  state_undefined     },
3766     { /* 83, undefined                              */      0,                                                  state_undefined     },
3767     { /* 84, undefined                              */      0,                                                  state_undefined     },
3768     { /* 85, undefined                              */      0,                                                  state_undefined     },
3769     { /* 86, undefined                              */      0,                                                  state_undefined     },
3770     { /* 87, undefined                              */      0,                                                  state_undefined     },
3771     { /* 88, undefined                              */      0,                                                  state_undefined     },
3772     { /* 89, undefined                              */      0,                                                  state_undefined     },
3773     { /* 90, undefined                              */      0,                                                  state_undefined     },
3774     { /* 91, undefined                              */      0,                                                  state_undefined     },
3775     { /* 92, undefined                              */      0,                                                  state_undefined     },
3776     { /* 93, undefined                              */      0,                                                  state_undefined     },
3777     { /* 94, undefined                              */      0,                                                  state_undefined     },
3778     { /* 95, undefined                              */      0,                                                  state_undefined     },
3779     { /* 96, undefined                              */      0,                                                  state_undefined     },
3780     { /* 97, undefined                              */      0,                                                  state_undefined     },
3781     { /* 98, undefined                              */      0,                                                  state_undefined     },
3782     { /* 99, undefined                              */      0,                                                  state_undefined     },
3783     { /*100, undefined                              */      0,                                                  state_undefined     },
3784     { /*101, undefined                              */      0,                                                  state_undefined     },
3785     { /*102, undefined                              */      0,                                                  state_undefined     },
3786     { /*103, undefined                              */      0,                                                  state_undefined     },
3787     { /*104, undefined                              */      0,                                                  state_undefined     },
3788     { /*105, undefined                              */      0,                                                  state_undefined     },
3789     { /*106, undefined                              */      0,                                                  state_undefined     },
3790     { /*107, undefined                              */      0,                                                  state_undefined     },
3791     { /*108, undefined                              */      0,                                                  state_undefined     },
3792     { /*109, undefined                              */      0,                                                  state_undefined     },
3793     { /*110, undefined                              */      0,                                                  state_undefined     },
3794     { /*111, undefined                              */      0,                                                  state_undefined     },
3795     { /*112, undefined                              */      0,                                                  state_undefined     },
3796     { /*113, undefined                              */      0,                                                  state_undefined     },
3797     { /*114, undefined                              */      0,                                                  state_undefined     },
3798     { /*115, undefined                              */      0,                                                  state_undefined     },
3799     { /*116, undefined                              */      0,                                                  state_undefined     },
3800     { /*117, undefined                              */      0,                                                  state_undefined     },
3801     { /*118, undefined                              */      0,                                                  state_undefined     },
3802     { /*119, undefined                              */      0,                                                  state_undefined     },
3803     { /*120, undefined                              */      0,                                                  state_undefined     },
3804     { /*121, undefined                              */      0,                                                  state_undefined     },
3805     { /*122, undefined                              */      0,                                                  state_undefined     },
3806     { /*123, undefined                              */      0,                                                  state_undefined     },
3807     { /*124, undefined                              */      0,                                                  state_undefined     },
3808     { /*125, undefined                              */      0,                                                  state_undefined     },
3809     { /*126, undefined                              */      0,                                                  state_undefined     },
3810     { /*127, undefined                              */      0,                                                  state_undefined     },
3811     { /*128, undefined                              */      0,                                                  state_undefined     },
3812     { /*129, undefined                              */      0,                                                  state_undefined     },
3813     { /*130, undefined                              */      0,                                                  state_undefined     },
3814     { /*131, undefined                              */      0,                                                  state_undefined     },
3815     { /*132, undefined                              */      0,                                                  state_undefined     },
3816     { /*133, undefined                              */      0,                                                  state_undefined     },
3817     { /*134, undefined                              */      0,                                                  state_undefined     },
3818     { /*135, undefined                              */      0,                                                  state_undefined     },
3819     { /*136, undefined                              */      0,                                                  state_undefined     },
3820     { /*137, undefined                              */      0,                                                  state_undefined     },
3821     { /*138, undefined                              */      0,                                                  state_undefined     },
3822     { /*139, undefined                              */      0,                                                  state_undefined     },
3823     { /*140, undefined                              */      0,                                                  state_undefined     },
3824     { /*141, undefined                              */      0,                                                  state_undefined     },
3825     { /*142, undefined                              */      0,                                                  state_undefined     },
3826     { /*143, undefined                              */      0,                                                  state_undefined     },
3827     { /*144, undefined                              */      0,                                                  state_undefined     },
3828     { /*145, undefined                              */      0,                                                  state_undefined     },
3829     { /*146, undefined                              */      0,                                                  state_undefined     },
3830     { /*147, undefined                              */      0,                                                  state_undefined     },
3831     { /*148, undefined                              */      0,                                                  state_undefined     },
3832     { /*149, undefined                              */      0,                                                  state_undefined     },
3833     { /*150, undefined                              */      0,                                                  state_undefined     },
3834     { /*151, undefined                              */      0,                                                  state_undefined     },
3835     { /*152, undefined                              */      0,                                                  state_undefined     },
3836     { /*153, undefined                              */      0,                                                  state_undefined     },
3837     { /*154, undefined                              */      0,                                                  state_undefined     },
3838     { /*155, undefined                              */      0,                                                  state_undefined     },
3839     { /*156, undefined                              */      0,                                                  state_undefined     },
3840     { /*157, undefined                              */      0,                                                  state_undefined     },
3841     { /*158, undefined                              */      0,                                                  state_undefined     },
3842     { /*159, undefined                              */      0,                                                  state_undefined     },
3843     { /*160, undefined                              */      0,                                                  state_undefined     },
3844     { /*161, undefined                              */      0,                                                  state_undefined     },
3845     { /*162, undefined                              */      0,                                                  state_undefined     },
3846     { /*163, undefined                              */      0,                                                  state_undefined     },
3847     { /*164, undefined                              */      0,                                                  state_undefined     },
3848     { /*165, undefined                              */      0,                                                  state_undefined     },
3849     { /*166, undefined                              */      0,                                                  state_undefined     },
3850     { /*167, undefined                              */      0,                                                  state_undefined     },
3851     { /*168, undefined                              */      0,                                                  state_undefined     },
3852     { /*169, undefined                              */      0,                                                  state_undefined     },
3853     { /*170, undefined                              */      0,                                                  state_undefined     },
3854     { /*171, undefined                              */      0,                                                  state_undefined     },
3855     { /*172, undefined                              */      0,                                                  state_undefined     },
3856     { /*173, undefined                              */      0,                                                  state_undefined     },
3857     { /*174, undefined                              */      0,                                                  state_undefined     },
3858     { /*175, undefined                              */      0,                                                  state_undefined     },
3859     { /*176, undefined                              */      0,                                                  state_undefined     },
3860     { /*177, undefined                              */      0,                                                  state_undefined     },
3861     { /*178, undefined                              */      0,                                                  state_undefined     },
3862     { /*179, undefined                              */      0,                                                  state_undefined     },
3863     { /*180, undefined                              */      0,                                                  state_undefined     },
3864     { /*181, undefined                              */      0,                                                  state_undefined     },
3865     { /*182, undefined                              */      0,                                                  state_undefined     },
3866     { /*183, undefined                              */      0,                                                  state_undefined     },
3867     { /*184, undefined                              */      0,                                                  state_undefined     },
3868     { /*185, undefined                              */      0,                                                  state_undefined     },
3869     { /*186, undefined                              */      0,                                                  state_undefined     },
3870     { /*187, undefined                              */      0,                                                  state_undefined     },
3871     { /*188, undefined                              */      0,                                                  state_undefined     },
3872     { /*189, undefined                              */      0,                                                  state_undefined     },
3873     { /*190, undefined                              */      0,                                                  state_undefined     },
3874     { /*191, undefined                              */      0,                                                  state_undefined     },
3875     { /*192, undefined                              */      0,                                                  state_undefined     },
3876     { /*193, undefined                              */      0,                                                  state_undefined     },
3877     { /*194, undefined                              */      0,                                                  state_undefined     },
3878     { /*195, undefined                              */      0,                                                  state_undefined     },
3879     { /*196, undefined                              */      0,                                                  state_undefined     },
3880     { /*197, undefined                              */      0,                                                  state_undefined     },
3881     { /*198, undefined                              */      0,                                                  state_undefined     },
3882     { /*199, undefined                              */      0,                                                  state_undefined     },
3883     { /*200, undefined                              */      0,                                                  state_undefined     },
3884     { /*201, undefined                              */      0,                                                  state_undefined     },
3885     { /*202, undefined                              */      0,                                                  state_undefined     },
3886     { /*203, undefined                              */      0,                                                  state_undefined     },
3887     { /*204, undefined                              */      0,                                                  state_undefined     },
3888     { /*205, undefined                              */      0,                                                  state_undefined     },
3889     { /*206, undefined                              */      0,                                                  state_undefined     },
3890     { /*207, undefined                              */      0,                                                  state_undefined     },
3891     { /*208, undefined                              */      0,                                                  state_undefined     },
3892     { /*209, undefined                              */      0,                                                  state_undefined     },
3893     { /*210, undefined                              */      0,                                                  state_undefined     },
3894     { /*211, undefined                              */      0,                                                  state_undefined     },
3895     { /*212, undefined                              */      0,                                                  state_undefined     },
3896     { /*213, undefined                              */      0,                                                  state_undefined     },
3897     { /*214, undefined                              */      0,                                                  state_undefined     },
3898     { /*215, undefined                              */      0,                                                  state_undefined     },
3899     { /*216, undefined                              */      0,                                                  state_undefined     },
3900     { /*217, undefined                              */      0,                                                  state_undefined     },
3901     { /*218, undefined                              */      0,                                                  state_undefined     },
3902     { /*219, undefined                              */      0,                                                  state_undefined     },
3903     { /*220, undefined                              */      0,                                                  state_undefined     },
3904     { /*221, undefined                              */      0,                                                  state_undefined     },
3905     { /*222, undefined                              */      0,                                                  state_undefined     },
3906     { /*223, undefined                              */      0,                                                  state_undefined     },
3907     { /*224, undefined                              */      0,                                                  state_undefined     },
3908     { /*225, undefined                              */      0,                                                  state_undefined     },
3909     { /*226, undefined                              */      0,                                                  state_undefined     },
3910     { /*227, undefined                              */      0,                                                  state_undefined     },
3911     { /*228, undefined                              */      0,                                                  state_undefined     },
3912     { /*229, undefined                              */      0,                                                  state_undefined     },
3913     { /*230, undefined                              */      0,                                                  state_undefined     },
3914     { /*231, undefined                              */      0,                                                  state_undefined     },
3915     { /*232, undefined                              */      0,                                                  state_undefined     },
3916     { /*233, undefined                              */      0,                                                  state_undefined     },
3917     { /*234, undefined                              */      0,                                                  state_undefined     },
3918     { /*235, undefined                              */      0,                                                  state_undefined     },
3919     { /*236, undefined                              */      0,                                                  state_undefined     },
3920     { /*237, undefined                              */      0,                                                  state_undefined     },
3921     { /*238, undefined                              */      0,                                                  state_undefined     },
3922     { /*239, undefined                              */      0,                                                  state_undefined     },
3923     { /*240, undefined                              */      0,                                                  state_undefined     },
3924     { /*241, undefined                              */      0,                                                  state_undefined     },
3925     { /*242, undefined                              */      0,                                                  state_undefined     },
3926     { /*243, undefined                              */      0,                                                  state_undefined     },
3927     { /*244, undefined                              */      0,                                                  state_undefined     },
3928     { /*245, undefined                              */      0,                                                  state_undefined     },
3929     { /*246, undefined                              */      0,                                                  state_undefined     },
3930     { /*247, undefined                              */      0,                                                  state_undefined     },
3931     { /*248, undefined                              */      0,                                                  state_undefined     },
3932     { /*249, undefined                              */      0,                                                  state_undefined     },
3933     { /*250, undefined                              */      0,                                                  state_undefined     },
3934     { /*251, undefined                              */      0,                                                  state_undefined     },
3935     { /*252, undefined                              */      0,                                                  state_undefined     },
3936     { /*253, undefined                              */      0,                                                  state_undefined     },
3937     { /*254, undefined                              */      0,                                                  state_undefined     },
3938     { /*255, undefined                              */      0,                                                  state_undefined     },
3939       /* End huge gap */
3940     { /*256, WINED3DTS_WORLDMATRIX(0)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)),          transform_world     },
3941     { /*257, WINED3DTS_WORLDMATRIX(1)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(1)),          transform_worldex   },
3942     { /*258, WINED3DTS_WORLDMATRIX(2)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(2)),          transform_worldex   },
3943     { /*259, WINED3DTS_WORLDMATRIX(3)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(3)),          transform_worldex   },
3944     { /*260, WINED3DTS_WORLDMATRIX(4)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(4)),          transform_worldex   },
3945     { /*261, WINED3DTS_WORLDMATRIX(5)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(5)),          transform_worldex   },
3946     { /*262, WINED3DTS_WORLDMATRIX(6)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(6)),          transform_worldex   },
3947     { /*263, WINED3DTS_WORLDMATRIX(7)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(7)),          transform_worldex   },
3948     { /*264, WINED3DTS_WORLDMATRIX(8)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(8)),          transform_worldex   },
3949     { /*265, WINED3DTS_WORLDMATRIX(9)               */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(9)),          transform_worldex   },
3950     { /*266, WINED3DTS_WORLDMATRIX(10)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(10)),         transform_worldex   },
3951     { /*267, WINED3DTS_WORLDMATRIX(11)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(11)),         transform_worldex   },
3952     { /*268, WINED3DTS_WORLDMATRIX(12)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(12)),         transform_worldex   },
3953     { /*269, WINED3DTS_WORLDMATRIX(13)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(13)),         transform_worldex   },
3954     { /*270, WINED3DTS_WORLDMATRIX(14)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(14)),         transform_worldex   },
3955     { /*271, WINED3DTS_WORLDMATRIX(15)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(15)),         transform_worldex   },
3956     { /*272, WINED3DTS_WORLDMATRIX(16)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(16)),         transform_worldex   },
3957     { /*273, WINED3DTS_WORLDMATRIX(17)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(17)),         transform_worldex   },
3958     { /*274, WINED3DTS_WORLDMATRIX(18)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(18)),         transform_worldex   },
3959     { /*275, WINED3DTS_WORLDMATRIX(19)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(19)),         transform_worldex   },
3960     { /*276, WINED3DTS_WORLDMATRIX(20)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(20)),         transform_worldex   },
3961     { /*277, WINED3DTS_WORLDMATRIX(21)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(21)),         transform_worldex   },
3962     { /*278, WINED3DTS_WORLDMATRIX(22)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(22)),         transform_worldex   },
3963     { /*279, WINED3DTS_WORLDMATRIX(23)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(23)),         transform_worldex   },
3964     { /*280, WINED3DTS_WORLDMATRIX(24)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(24)),         transform_worldex   },
3965     { /*281, WINED3DTS_WORLDMATRIX(25)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(25)),         transform_worldex   },
3966     { /*282, WINED3DTS_WORLDMATRIX(26)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(26)),         transform_worldex   },
3967     { /*283, WINED3DTS_WORLDMATRIX(27)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(27)),         transform_worldex   },
3968     { /*284, WINED3DTS_WORLDMATRIX(28)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(28)),         transform_worldex   },
3969     { /*285, WINED3DTS_WORLDMATRIX(29)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(29)),         transform_worldex   },
3970     { /*286, WINED3DTS_WORLDMATRIX(30)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(30)),         transform_worldex   },
3971     { /*287, WINED3DTS_WORLDMATRIX(31)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(31)),         transform_worldex   },
3972     { /*288, WINED3DTS_WORLDMATRIX(32)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(32)),         transform_worldex   },
3973     { /*289, WINED3DTS_WORLDMATRIX(33)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(33)),         transform_worldex   },
3974     { /*290, WINED3DTS_WORLDMATRIX(34)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(34)),         transform_worldex   },
3975     { /*291, WINED3DTS_WORLDMATRIX(35)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(35)),         transform_worldex   },
3976     { /*292, WINED3DTS_WORLDMATRIX(36)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(36)),         transform_worldex   },
3977     { /*293, WINED3DTS_WORLDMATRIX(37)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(37)),         transform_worldex   },
3978     { /*294, WINED3DTS_WORLDMATRIX(38)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(38)),         transform_worldex   },
3979     { /*295, WINED3DTS_WORLDMATRIX(39)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(39)),         transform_worldex   },
3980     { /*296, WINED3DTS_WORLDMATRIX(40)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(40)),         transform_worldex   },
3981     { /*297, WINED3DTS_WORLDMATRIX(41)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(41)),         transform_worldex   },
3982     { /*298, WINED3DTS_WORLDMATRIX(42)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(42)),         transform_worldex   },
3983     { /*299, WINED3DTS_WORLDMATRIX(43)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(43)),         transform_worldex   },
3984     { /*300, WINED3DTS_WORLDMATRIX(44)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(44)),         transform_worldex   },
3985     { /*301, WINED3DTS_WORLDMATRIX(45)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(45)),         transform_worldex   },
3986     { /*302, WINED3DTS_WORLDMATRIX(46)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(46)),         transform_worldex   },
3987     { /*303, WINED3DTS_WORLDMATRIX(47)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(47)),         transform_worldex   },
3988     { /*304, WINED3DTS_WORLDMATRIX(48)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(48)),         transform_worldex   },
3989     { /*305, WINED3DTS_WORLDMATRIX(49)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(49)),         transform_worldex   },
3990     { /*306, WINED3DTS_WORLDMATRIX(50)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(50)),         transform_worldex   },
3991     { /*307, WINED3DTS_WORLDMATRIX(51)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(51)),         transform_worldex   },
3992     { /*308, WINED3DTS_WORLDMATRIX(52)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(52)),         transform_worldex   },
3993     { /*309, WINED3DTS_WORLDMATRIX(53)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(53)),         transform_worldex   },
3994     { /*310, WINED3DTS_WORLDMATRIX(54)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(54)),         transform_worldex   },
3995     { /*311, WINED3DTS_WORLDMATRIX(55)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(55)),         transform_worldex   },
3996     { /*312, WINED3DTS_WORLDMATRIX(56)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(56)),         transform_worldex   },
3997     { /*313, WINED3DTS_WORLDMATRIX(57)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(57)),         transform_worldex   },
3998     { /*314, WINED3DTS_WORLDMATRIX(58)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(58)),         transform_worldex   },
3999     { /*315, WINED3DTS_WORLDMATRIX(59)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(59)),         transform_worldex   },
4000     { /*316, WINED3DTS_WORLDMATRIX(60)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(60)),         transform_worldex   },
4001     { /*317, WINED3DTS_WORLDMATRIX(61)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(61)),         transform_worldex   },
4002     { /*318, WINED3DTS_WORLDMATRIX(62)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(62)),         transform_worldex   },
4003     { /*319, WINED3DTS_WORLDMATRIX(63)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(63)),         transform_worldex   },
4004     { /*320, WINED3DTS_WORLDMATRIX(64)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(64)),         transform_worldex   },
4005     { /*321, WINED3DTS_WORLDMATRIX(65)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(65)),         transform_worldex   },
4006     { /*322, WINED3DTS_WORLDMATRIX(66)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(66)),         transform_worldex   },
4007     { /*323, WINED3DTS_WORLDMATRIX(67)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(67)),         transform_worldex   },
4008     { /*324, WINED3DTS_WORLDMATRIX(68)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(68)),         transform_worldex   },
4009     { /*325, WINED3DTS_WORLDMATRIX(68)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(69)),         transform_worldex   },
4010     { /*326, WINED3DTS_WORLDMATRIX(70)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(70)),         transform_worldex   },
4011     { /*327, WINED3DTS_WORLDMATRIX(71)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(71)),         transform_worldex   },
4012     { /*328, WINED3DTS_WORLDMATRIX(72)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(72)),         transform_worldex   },
4013     { /*329, WINED3DTS_WORLDMATRIX(73)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(73)),         transform_worldex   },
4014     { /*330, WINED3DTS_WORLDMATRIX(74)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(74)),         transform_worldex   },
4015     { /*331, WINED3DTS_WORLDMATRIX(75)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(75)),         transform_worldex   },
4016     { /*332, WINED3DTS_WORLDMATRIX(76)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(76)),         transform_worldex   },
4017     { /*333, WINED3DTS_WORLDMATRIX(77)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(77)),         transform_worldex   },
4018     { /*334, WINED3DTS_WORLDMATRIX(78)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(78)),         transform_worldex   },
4019     { /*335, WINED3DTS_WORLDMATRIX(79)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(79)),         transform_worldex   },
4020     { /*336, WINED3DTS_WORLDMATRIX(80)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(80)),         transform_worldex   },
4021     { /*337, WINED3DTS_WORLDMATRIX(81)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(81)),         transform_worldex   },
4022     { /*338, WINED3DTS_WORLDMATRIX(82)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(82)),         transform_worldex   },
4023     { /*339, WINED3DTS_WORLDMATRIX(83)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(83)),         transform_worldex   },
4024     { /*340, WINED3DTS_WORLDMATRIX(84)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(84)),         transform_worldex   },
4025     { /*341, WINED3DTS_WORLDMATRIX(85)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(85)),         transform_worldex   },
4026     { /*341, WINED3DTS_WORLDMATRIX(86)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(86)),         transform_worldex   },
4027     { /*343, WINED3DTS_WORLDMATRIX(87)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(87)),         transform_worldex   },
4028     { /*344, WINED3DTS_WORLDMATRIX(88)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(88)),         transform_worldex   },
4029     { /*345, WINED3DTS_WORLDMATRIX(89)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(89)),         transform_worldex   },
4030     { /*346, WINED3DTS_WORLDMATRIX(90)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(90)),         transform_worldex   },
4031     { /*347, WINED3DTS_WORLDMATRIX(91)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(91)),         transform_worldex   },
4032     { /*348, WINED3DTS_WORLDMATRIX(92)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(92)),         transform_worldex   },
4033     { /*349, WINED3DTS_WORLDMATRIX(93)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(93)),         transform_worldex   },
4034     { /*350, WINED3DTS_WORLDMATRIX(94)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(94)),         transform_worldex   },
4035     { /*351, WINED3DTS_WORLDMATRIX(95)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(95)),         transform_worldex   },
4036     { /*352, WINED3DTS_WORLDMATRIX(96)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(96)),         transform_worldex   },
4037     { /*353, WINED3DTS_WORLDMATRIX(97)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(97)),         transform_worldex   },
4038     { /*354, WINED3DTS_WORLDMATRIX(98)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(98)),         transform_worldex   },
4039     { /*355, WINED3DTS_WORLDMATRIX(99)              */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(99)),         transform_worldex   },
4040     { /*356, WINED3DTS_WORLDMATRIX(100)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(100)),        transform_worldex   },
4041     { /*357, WINED3DTS_WORLDMATRIX(101)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(101)),        transform_worldex   },
4042     { /*358, WINED3DTS_WORLDMATRIX(102)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(102)),        transform_worldex   },
4043     { /*359, WINED3DTS_WORLDMATRIX(103)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(103)),        transform_worldex   },
4044     { /*360, WINED3DTS_WORLDMATRIX(104)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(104)),        transform_worldex   },
4045     { /*361, WINED3DTS_WORLDMATRIX(105)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(105)),        transform_worldex   },
4046     { /*362, WINED3DTS_WORLDMATRIX(106)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(106)),        transform_worldex   },
4047     { /*363, WINED3DTS_WORLDMATRIX(107)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(107)),        transform_worldex   },
4048     { /*364, WINED3DTS_WORLDMATRIX(108)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(108)),        transform_worldex   },
4049     { /*365, WINED3DTS_WORLDMATRIX(109)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(109)),        transform_worldex   },
4050     { /*366, WINED3DTS_WORLDMATRIX(110)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(110)),        transform_worldex   },
4051     { /*367, WINED3DTS_WORLDMATRIX(111)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(111)),        transform_worldex   },
4052     { /*368, WINED3DTS_WORLDMATRIX(112)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(112)),        transform_worldex   },
4053     { /*369, WINED3DTS_WORLDMATRIX(113)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(113)),        transform_worldex   },
4054     { /*370, WINED3DTS_WORLDMATRIX(114)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(114)),        transform_worldex   },
4055     { /*371, WINED3DTS_WORLDMATRIX(115)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(115)),        transform_worldex   },
4056     { /*372, WINED3DTS_WORLDMATRIX(116)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(116)),        transform_worldex   },
4057     { /*373, WINED3DTS_WORLDMATRIX(117)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(117)),        transform_worldex   },
4058     { /*374, WINED3DTS_WORLDMATRIX(118)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(118)),        transform_worldex   },
4059     { /*375, WINED3DTS_WORLDMATRIX(119)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(119)),        transform_worldex   },
4060     { /*376, WINED3DTS_WORLDMATRIX(120)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(120)),        transform_worldex   },
4061     { /*377, WINED3DTS_WORLDMATRIX(121)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(121)),        transform_worldex   },
4062     { /*378, WINED3DTS_WORLDMATRIX(122)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(122)),        transform_worldex   },
4063     { /*379, WINED3DTS_WORLDMATRIX(123)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(123)),        transform_worldex   },
4064     { /*380, WINED3DTS_WORLDMATRIX(124)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(124)),        transform_worldex   },
4065     { /*381, WINED3DTS_WORLDMATRIX(125)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(125)),        transform_worldex   },
4066     { /*382, WINED3DTS_WORLDMATRIX(126)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(126)),        transform_worldex   },
4067     { /*383, WINED3DTS_WORLDMATRIX(127)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(127)),        transform_worldex   },
4068     { /*384, WINED3DTS_WORLDMATRIX(128)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(128)),        transform_worldex   },
4069     { /*385, WINED3DTS_WORLDMATRIX(129)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(129)),        transform_worldex   },
4070     { /*386, WINED3DTS_WORLDMATRIX(130)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(130)),        transform_worldex   },
4071     { /*387, WINED3DTS_WORLDMATRIX(131)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(131)),        transform_worldex   },
4072     { /*388, WINED3DTS_WORLDMATRIX(132)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(132)),        transform_worldex   },
4073     { /*389, WINED3DTS_WORLDMATRIX(133)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(133)),        transform_worldex   },
4074     { /*390, WINED3DTS_WORLDMATRIX(134)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(134)),        transform_worldex   },
4075     { /*391, WINED3DTS_WORLDMATRIX(135)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(135)),        transform_worldex   },
4076     { /*392, WINED3DTS_WORLDMATRIX(136)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(136)),        transform_worldex   },
4077     { /*393, WINED3DTS_WORLDMATRIX(137)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(137)),        transform_worldex   },
4078     { /*394, WINED3DTS_WORLDMATRIX(138)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(138)),        transform_worldex   },
4079     { /*395, WINED3DTS_WORLDMATRIX(139)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(139)),        transform_worldex   },
4080     { /*396, WINED3DTS_WORLDMATRIX(140)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(140)),        transform_worldex   },
4081     { /*397, WINED3DTS_WORLDMATRIX(141)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(141)),        transform_worldex   },
4082     { /*398, WINED3DTS_WORLDMATRIX(142)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(142)),        transform_worldex   },
4083     { /*399, WINED3DTS_WORLDMATRIX(143)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(143)),        transform_worldex   },
4084     { /*400, WINED3DTS_WORLDMATRIX(144)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(144)),        transform_worldex   },
4085     { /*401, WINED3DTS_WORLDMATRIX(145)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(145)),        transform_worldex   },
4086     { /*402, WINED3DTS_WORLDMATRIX(146)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(146)),        transform_worldex   },
4087     { /*403, WINED3DTS_WORLDMATRIX(147)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(147)),        transform_worldex   },
4088     { /*404, WINED3DTS_WORLDMATRIX(148)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(148)),        transform_worldex   },
4089     { /*405, WINED3DTS_WORLDMATRIX(149)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(149)),        transform_worldex   },
4090     { /*406, WINED3DTS_WORLDMATRIX(150)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(150)),        transform_worldex   },
4091     { /*407, WINED3DTS_WORLDMATRIX(151)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(151)),        transform_worldex   },
4092     { /*408, WINED3DTS_WORLDMATRIX(152)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(152)),        transform_worldex   },
4093     { /*409, WINED3DTS_WORLDMATRIX(153)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(153)),        transform_worldex   },
4094     { /*410, WINED3DTS_WORLDMATRIX(154)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(154)),        transform_worldex   },
4095     { /*411, WINED3DTS_WORLDMATRIX(155)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(155)),        transform_worldex   },
4096     { /*412, WINED3DTS_WORLDMATRIX(156)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(156)),        transform_worldex   },
4097     { /*413, WINED3DTS_WORLDMATRIX(157)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(157)),        transform_worldex   },
4098     { /*414, WINED3DTS_WORLDMATRIX(158)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(158)),        transform_worldex   },
4099     { /*415, WINED3DTS_WORLDMATRIX(159)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(159)),        transform_worldex   },
4100     { /*416, WINED3DTS_WORLDMATRIX(160)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(160)),        transform_worldex   },
4101     { /*417, WINED3DTS_WORLDMATRIX(161)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(161)),        transform_worldex   },
4102     { /*418, WINED3DTS_WORLDMATRIX(162)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(162)),        transform_worldex   },
4103     { /*419, WINED3DTS_WORLDMATRIX(163)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(163)),        transform_worldex   },
4104     { /*420, WINED3DTS_WORLDMATRIX(164)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(164)),        transform_worldex   },
4105     { /*421, WINED3DTS_WORLDMATRIX(165)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(165)),        transform_worldex   },
4106     { /*422, WINED3DTS_WORLDMATRIX(166)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(166)),        transform_worldex   },
4107     { /*423, WINED3DTS_WORLDMATRIX(167)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(167)),        transform_worldex   },
4108     { /*424, WINED3DTS_WORLDMATRIX(168)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(168)),        transform_worldex   },
4109     { /*425, WINED3DTS_WORLDMATRIX(168)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(169)),        transform_worldex   },
4110     { /*426, WINED3DTS_WORLDMATRIX(170)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(170)),        transform_worldex   },
4111     { /*427, WINED3DTS_WORLDMATRIX(171)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(171)),        transform_worldex   },
4112     { /*428, WINED3DTS_WORLDMATRIX(172)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(172)),        transform_worldex   },
4113     { /*429, WINED3DTS_WORLDMATRIX(173)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(173)),        transform_worldex   },
4114     { /*430, WINED3DTS_WORLDMATRIX(174)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(174)),        transform_worldex   },
4115     { /*431, WINED3DTS_WORLDMATRIX(175)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(175)),        transform_worldex   },
4116     { /*432, WINED3DTS_WORLDMATRIX(176)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(176)),        transform_worldex   },
4117     { /*433, WINED3DTS_WORLDMATRIX(177)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(177)),        transform_worldex   },
4118     { /*434, WINED3DTS_WORLDMATRIX(178)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(178)),        transform_worldex   },
4119     { /*435, WINED3DTS_WORLDMATRIX(179)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(179)),        transform_worldex   },
4120     { /*436, WINED3DTS_WORLDMATRIX(180)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(180)),        transform_worldex   },
4121     { /*437, WINED3DTS_WORLDMATRIX(181)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(181)),        transform_worldex   },
4122     { /*438, WINED3DTS_WORLDMATRIX(182)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(182)),        transform_worldex   },
4123     { /*439, WINED3DTS_WORLDMATRIX(183)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(183)),        transform_worldex   },
4124     { /*440, WINED3DTS_WORLDMATRIX(184)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(184)),        transform_worldex   },
4125     { /*441, WINED3DTS_WORLDMATRIX(185)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(185)),        transform_worldex   },
4126     { /*441, WINED3DTS_WORLDMATRIX(186)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(186)),        transform_worldex   },
4127     { /*443, WINED3DTS_WORLDMATRIX(187)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(187)),        transform_worldex   },
4128     { /*444, WINED3DTS_WORLDMATRIX(188)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(188)),        transform_worldex   },
4129     { /*445, WINED3DTS_WORLDMATRIX(189)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(189)),        transform_worldex   },
4130     { /*446, WINED3DTS_WORLDMATRIX(190)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(190)),        transform_worldex   },
4131     { /*447, WINED3DTS_WORLDMATRIX(191)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(191)),        transform_worldex   },
4132     { /*448, WINED3DTS_WORLDMATRIX(192)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(192)),        transform_worldex   },
4133     { /*449, WINED3DTS_WORLDMATRIX(193)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(193)),        transform_worldex   },
4134     { /*450, WINED3DTS_WORLDMATRIX(194)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(194)),        transform_worldex   },
4135     { /*451, WINED3DTS_WORLDMATRIX(195)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(195)),        transform_worldex   },
4136     { /*452, WINED3DTS_WORLDMATRIX(196)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(196)),        transform_worldex   },
4137     { /*453, WINED3DTS_WORLDMATRIX(197)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(197)),        transform_worldex   },
4138     { /*454, WINED3DTS_WORLDMATRIX(198)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(198)),        transform_worldex   },
4139     { /*455, WINED3DTS_WORLDMATRIX(199)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(199)),        transform_worldex   },
4140     { /*356, WINED3DTS_WORLDMATRIX(200)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(200)),        transform_worldex   },
4141     { /*457, WINED3DTS_WORLDMATRIX(201)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(201)),        transform_worldex   },
4142     { /*458, WINED3DTS_WORLDMATRIX(202)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(202)),        transform_worldex   },
4143     { /*459, WINED3DTS_WORLDMATRIX(203)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(203)),        transform_worldex   },
4144     { /*460, WINED3DTS_WORLDMATRIX(204)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(204)),        transform_worldex   },
4145     { /*461, WINED3DTS_WORLDMATRIX(205)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(205)),        transform_worldex   },
4146     { /*462, WINED3DTS_WORLDMATRIX(206)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(206)),        transform_worldex   },
4147     { /*463, WINED3DTS_WORLDMATRIX(207)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(207)),        transform_worldex   },
4148     { /*464, WINED3DTS_WORLDMATRIX(208)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(208)),        transform_worldex   },
4149     { /*465, WINED3DTS_WORLDMATRIX(209)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(209)),        transform_worldex   },
4150     { /*466, WINED3DTS_WORLDMATRIX(210)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(210)),        transform_worldex   },
4151     { /*467, WINED3DTS_WORLDMATRIX(211)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(211)),        transform_worldex   },
4152     { /*468, WINED3DTS_WORLDMATRIX(212)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(212)),        transform_worldex   },
4153     { /*469, WINED3DTS_WORLDMATRIX(213)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(213)),        transform_worldex   },
4154     { /*470, WINED3DTS_WORLDMATRIX(214)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(214)),        transform_worldex   },
4155     { /*471, WINED3DTS_WORLDMATRIX(215)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(215)),        transform_worldex   },
4156     { /*472, WINED3DTS_WORLDMATRIX(216)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(216)),        transform_worldex   },
4157     { /*473, WINED3DTS_WORLDMATRIX(217)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(217)),        transform_worldex   },
4158     { /*474, WINED3DTS_WORLDMATRIX(218)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(218)),        transform_worldex   },
4159     { /*475, WINED3DTS_WORLDMATRIX(219)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(219)),        transform_worldex   },
4160     { /*476, WINED3DTS_WORLDMATRIX(220)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(220)),        transform_worldex   },
4161     { /*477, WINED3DTS_WORLDMATRIX(221)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(221)),        transform_worldex   },
4162     { /*478, WINED3DTS_WORLDMATRIX(222)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(222)),        transform_worldex   },
4163     { /*479, WINED3DTS_WORLDMATRIX(223)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(223)),        transform_worldex   },
4164     { /*480, WINED3DTS_WORLDMATRIX(224)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(224)),        transform_worldex   },
4165     { /*481, WINED3DTS_WORLDMATRIX(225)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(225)),        transform_worldex   },
4166     { /*482, WINED3DTS_WORLDMATRIX(226)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(226)),        transform_worldex   },
4167     { /*483, WINED3DTS_WORLDMATRIX(227)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(227)),        transform_worldex   },
4168     { /*484, WINED3DTS_WORLDMATRIX(228)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(228)),        transform_worldex   },
4169     { /*485, WINED3DTS_WORLDMATRIX(229)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(229)),        transform_worldex   },
4170     { /*486, WINED3DTS_WORLDMATRIX(230)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(230)),        transform_worldex   },
4171     { /*487, WINED3DTS_WORLDMATRIX(231)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(231)),        transform_worldex   },
4172     { /*488, WINED3DTS_WORLDMATRIX(232)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(232)),        transform_worldex   },
4173     { /*489, WINED3DTS_WORLDMATRIX(233)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(233)),        transform_worldex   },
4174     { /*490, WINED3DTS_WORLDMATRIX(234)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(234)),        transform_worldex   },
4175     { /*491, WINED3DTS_WORLDMATRIX(235)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(235)),        transform_worldex   },
4176     { /*492, WINED3DTS_WORLDMATRIX(236)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(236)),        transform_worldex   },
4177     { /*493, WINED3DTS_WORLDMATRIX(237)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(237)),        transform_worldex   },
4178     { /*494, WINED3DTS_WORLDMATRIX(238)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(238)),        transform_worldex   },
4179     { /*495, WINED3DTS_WORLDMATRIX(239)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(239)),        transform_worldex   },
4180     { /*496, WINED3DTS_WORLDMATRIX(240)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(240)),        transform_worldex   },
4181     { /*497, WINED3DTS_WORLDMATRIX(241)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(241)),        transform_worldex   },
4182     { /*498, WINED3DTS_WORLDMATRIX(242)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(242)),        transform_worldex   },
4183     { /*499, WINED3DTS_WORLDMATRIX(243)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(243)),        transform_worldex   },
4184     { /*500, WINED3DTS_WORLDMATRIX(244)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(244)),        transform_worldex   },
4185     { /*501, WINED3DTS_WORLDMATRIX(245)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(245)),        transform_worldex   },
4186     { /*502, WINED3DTS_WORLDMATRIX(246)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(246)),        transform_worldex   },
4187     { /*503, WINED3DTS_WORLDMATRIX(247)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(247)),        transform_worldex   },
4188     { /*504, WINED3DTS_WORLDMATRIX(248)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(248)),        transform_worldex   },
4189     { /*505, WINED3DTS_WORLDMATRIX(249)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(249)),        transform_worldex   },
4190     { /*506, WINED3DTS_WORLDMATRIX(250)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(250)),        transform_worldex   },
4191     { /*507, WINED3DTS_WORLDMATRIX(251)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(251)),        transform_worldex   },
4192     { /*508, WINED3DTS_WORLDMATRIX(252)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(252)),        transform_worldex   },
4193     { /*509, WINED3DTS_WORLDMATRIX(253)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(253)),        transform_worldex   },
4194     { /*510, WINED3DTS_WORLDMATRIX(254)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(254)),        transform_worldex   },
4195     { /*511, WINED3DTS_WORLDMATRIX(255)             */      STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)),        transform_worldex   },
4196       /* Various Vertex states follow */
4197     { /*   , STATE_STREAMSRC                        */      STATE_VDECL,                                        vertexdeclaration   },
4198     { /*   , STATE_INDEXBUFFER                      */      STATE_INDEXBUFFER,                                  indexbuffer         },
4199     { /*   , STATE_VDECL                            */      STATE_VDECL,                                        vertexdeclaration   },
4200     { /*   , STATE_VSHADER                          */      STATE_VDECL,                                        vertexdeclaration   },
4201     { /*   , STATE_VIEWPORT                         */      STATE_VIEWPORT,                                     viewport            },
4202     { /*   , STATE_VERTEXSHADERCONSTANT             */      STATE_VERTEXSHADERCONSTANT,                         shaderconstant      },
4203     { /*   , STATE_PIXELSHADERCONSTANT              */      STATE_VERTEXSHADERCONSTANT,                         shaderconstant      },
4204       /* Lights */
4205     { /*   , STATE_ACTIVELIGHT(0)                   */      STATE_ACTIVELIGHT(0),                               light               },
4206     { /*   , STATE_ACTIVELIGHT(1)                   */      STATE_ACTIVELIGHT(1),                               light               },
4207     { /*   , STATE_ACTIVELIGHT(2)                   */      STATE_ACTIVELIGHT(2),                               light               },
4208     { /*   , STATE_ACTIVELIGHT(3)                   */      STATE_ACTIVELIGHT(3),                               light               },
4209     { /*   , STATE_ACTIVELIGHT(4)                   */      STATE_ACTIVELIGHT(4),                               light               },
4210     { /*   , STATE_ACTIVELIGHT(5)                   */      STATE_ACTIVELIGHT(5),                               light               },
4211     { /*   , STATE_ACTIVELIGHT(6)                   */      STATE_ACTIVELIGHT(6),                               light               },
4212     { /*   , STATE_ACTIVELIGHT(7)                   */      STATE_ACTIVELIGHT(7),                               light               },
4213
4214     { /* Scissor rect                               */      STATE_SCISSORRECT,                                  scissorrect         },
4215       /* Clip planes */
4216     { /* STATE_CLIPPLANE(0)                         */      STATE_CLIPPLANE(0),                                 clipplane           },
4217     { /* STATE_CLIPPLANE(1)                         */      STATE_CLIPPLANE(1),                                 clipplane           },
4218     { /* STATE_CLIPPLANE(2)                         */      STATE_CLIPPLANE(2),                                 clipplane           },
4219     { /* STATE_CLIPPLANE(3)                         */      STATE_CLIPPLANE(3),                                 clipplane           },
4220     { /* STATE_CLIPPLANE(4)                         */      STATE_CLIPPLANE(4),                                 clipplane           },
4221     { /* STATE_CLIPPLANE(5)                         */      STATE_CLIPPLANE(5),                                 clipplane           },
4222     { /* STATE_CLIPPLANE(6)                         */      STATE_CLIPPLANE(6),                                 clipplane           },
4223     { /* STATE_CLIPPLANE(7)                         */      STATE_CLIPPLANE(7),                                 clipplane           },
4224     { /* STATE_CLIPPLANE(8)                         */      STATE_CLIPPLANE(8),                                 clipplane           },
4225     { /* STATE_CLIPPLANE(9)                         */      STATE_CLIPPLANE(9),                                 clipplane           },
4226     { /* STATE_CLIPPLANE(10)                        */      STATE_CLIPPLANE(10),                                clipplane           },
4227     { /* STATE_CLIPPLANE(11)                        */      STATE_CLIPPLANE(11),                                clipplane           },
4228     { /* STATE_CLIPPLANE(12)                        */      STATE_CLIPPLANE(12),                                clipplane           },
4229     { /* STATE_CLIPPLANE(13)                        */      STATE_CLIPPLANE(13),                                clipplane           },
4230     { /* STATE_CLIPPLANE(14)                        */      STATE_CLIPPLANE(14),                                clipplane           },
4231     { /* STATE_CLIPPLANE(15)                        */      STATE_CLIPPLANE(15),                                clipplane           },
4232     { /* STATE_CLIPPLANE(16)                        */      STATE_CLIPPLANE(16),                                clipplane           },
4233     { /* STATE_CLIPPLANE(17)                        */      STATE_CLIPPLANE(17),                                clipplane           },
4234     { /* STATE_CLIPPLANE(18)                        */      STATE_CLIPPLANE(18),                                clipplane           },
4235     { /* STATE_CLIPPLANE(19)                        */      STATE_CLIPPLANE(19),                                clipplane           },
4236     { /* STATE_CLIPPLANE(20)                        */      STATE_CLIPPLANE(20),                                clipplane           },
4237     { /* STATE_CLIPPLANE(21)                        */      STATE_CLIPPLANE(21),                                clipplane           },
4238     { /* STATE_CLIPPLANE(22)                        */      STATE_CLIPPLANE(22),                                clipplane           },
4239     { /* STATE_CLIPPLANE(23)                        */      STATE_CLIPPLANE(23),                                clipplane           },
4240     { /* STATE_CLIPPLANE(24)                        */      STATE_CLIPPLANE(24),                                clipplane           },
4241     { /* STATE_CLIPPLANE(25)                        */      STATE_CLIPPLANE(25),                                clipplane           },
4242     { /* STATE_CLIPPLANE(26)                        */      STATE_CLIPPLANE(26),                                clipplane           },
4243     { /* STATE_CLIPPLANE(27)                        */      STATE_CLIPPLANE(27),                                clipplane           },
4244     { /* STATE_CLIPPLANE(28)                        */      STATE_CLIPPLANE(28),                                clipplane           },
4245     { /* STATE_CLIPPLANE(29)                        */      STATE_CLIPPLANE(29),                                clipplane           },
4246     { /* STATE_CLIPPLANE(30)                        */      STATE_CLIPPLANE(30),                                clipplane           },
4247     { /* STATE_CLIPPLANE(31)                        */      STATE_CLIPPLANE(31),                                clipplane           },
4248 };