wined3d: Add a WINED3DTSS_BUMPENVSCALE stub.
[wine] / dlls / wined3d / state.c
1 /*
2  * Direct3D state management
3  *
4  * Copyright 2006 Stefan Dösinger for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include <stdio.h>
23 #ifdef HAVE_FLOAT_H
24 # include <float.h>
25 #endif
26 #include "wined3d_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
29
30 #define GLINFO_LOCATION ((IWineD3DImpl *)(stateblock->wineD3DDevice->wineD3D))->gl_info
31
32 static void state_nogl(DWORD state, IWineD3DStateBlockImpl *stateblock) {
33     /* Used for states which are not mapped to a gl state as-is, but used somehow different,
34      * e.g as a parameter for drawing, or which are unimplemented in windows d3d
35      */
36     if(STATE_IS_RENDER(state)) {
37         WINED3DRENDERSTATETYPE RenderState = state - STATE_RENDER(0);
38         TRACE("(%s,%d) no direct mapping to gl\n", debug_d3drenderstate(RenderState), stateblock->renderState[RenderState]);
39     } else {
40         /* Shouldn't have an unknown type here */
41         FIXME("%d no direct mapping to gl of state with unknown type\n", state);
42     }
43 }
44
45 static void state_undefined(DWORD state, IWineD3DStateBlockImpl *stateblock) {
46     /* Print a WARN, this allows the stateblock code to loop over all states to generate a display
47      * list without causing confusing terminal output. Deliberately no special debug name here
48      * because its undefined.
49      */
50     WARN("undefined state %d\n", state);
51 }
52
53 static void state_fillmode(DWORD state, IWineD3DStateBlockImpl *stateblock) {
54     D3DFILLMODE Value = stateblock->renderState[WINED3DRS_FILLMODE];
55
56     switch(Value) {
57         case D3DFILL_POINT:
58             glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
59             checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
60             break;
61         case D3DFILL_WIREFRAME:
62             glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
63             checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
64             break;
65         case D3DFILL_SOLID:
66             glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
67             checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
68             break;
69         default:
70             FIXME("Unrecognized WINED3DRS_FILLMODE value %d\n", Value);
71     }
72 }
73
74 static void state_lighting(DWORD state, IWineD3DStateBlockImpl *stateblock) {
75
76     /* TODO: Lighting is only enabled if Vertex normals are passed by the application,
77      * so merge the lighting render state with the vertex declaration once it is available
78      */
79
80     if (stateblock->renderState[WINED3DRS_LIGHTING]) {
81         glEnable(GL_LIGHTING);
82         checkGLcall("glEnable GL_LIGHTING");
83     } else {
84         glDisable(GL_LIGHTING);
85         checkGLcall("glDisable GL_LIGHTING");
86     }
87 }
88
89 static void state_zenable(DWORD state, IWineD3DStateBlockImpl *stateblock) {
90     switch ((WINED3DZBUFFERTYPE) stateblock->renderState[WINED3DRS_ZENABLE]) {
91         case WINED3DZB_FALSE:
92             glDisable(GL_DEPTH_TEST);
93             checkGLcall("glDisable GL_DEPTH_TEST");
94             break;
95         case WINED3DZB_TRUE:
96             glEnable(GL_DEPTH_TEST);
97             checkGLcall("glEnable GL_DEPTH_TEST");
98             break;
99         case WINED3DZB_USEW:
100             glEnable(GL_DEPTH_TEST);
101             checkGLcall("glEnable GL_DEPTH_TEST");
102             FIXME("W buffer is not well handled\n");
103             break;
104         default:
105             FIXME("Unrecognized D3DZBUFFERTYPE value %d\n", stateblock->renderState[WINED3DRS_ZENABLE]);
106     }
107 }
108
109 static void state_cullmode(DWORD state, IWineD3DStateBlockImpl *stateblock) {
110     /* TODO: Put this into the offscreen / onscreen rendering block due to device->render_offscreen */
111
112     /* If we are culling "back faces with clockwise vertices" then
113        set front faces to be counter clockwise and enable culling
114        of back faces                                               */
115     switch ((WINED3DCULL) stateblock->renderState[WINED3DRS_CULLMODE]) {
116         case WINED3DCULL_NONE:
117             glDisable(GL_CULL_FACE);
118             checkGLcall("glDisable GL_CULL_FACE");
119             break;
120         case WINED3DCULL_CW:
121             glEnable(GL_CULL_FACE);
122             checkGLcall("glEnable GL_CULL_FACE");
123             if (stateblock->wineD3DDevice->render_offscreen) {
124                 glFrontFace(GL_CW);
125                 checkGLcall("glFrontFace GL_CW");
126             } else {
127                 glFrontFace(GL_CCW);
128                 checkGLcall("glFrontFace GL_CCW");
129             }
130             glCullFace(GL_BACK);
131             break;
132         case WINED3DCULL_CCW:
133             glEnable(GL_CULL_FACE);
134             checkGLcall("glEnable GL_CULL_FACE");
135             if (stateblock->wineD3DDevice->render_offscreen) {
136                 glFrontFace(GL_CCW);
137                 checkGLcall("glFrontFace GL_CCW");
138             } else {
139                 glFrontFace(GL_CW);
140                 checkGLcall("glFrontFace GL_CW");
141             }
142             glCullFace(GL_BACK);
143             break;
144         default:
145             FIXME("Unrecognized/Unhandled WINED3DCULL value %d\n", stateblock->renderState[WINED3DRS_CULLMODE]);
146     }
147 }
148
149 static void state_shademode(DWORD state, IWineD3DStateBlockImpl *stateblock) {
150     switch ((WINED3DSHADEMODE) stateblock->renderState[WINED3DRS_SHADEMODE]) {
151         case WINED3DSHADE_FLAT:
152             glShadeModel(GL_FLAT);
153             checkGLcall("glShadeModel(GL_FLAT)");
154             break;
155         case WINED3DSHADE_GOURAUD:
156             glShadeModel(GL_SMOOTH);
157             checkGLcall("glShadeModel(GL_SMOOTH)");
158             break;
159         case WINED3DSHADE_PHONG:
160             FIXME("WINED3DSHADE_PHONG isn't supported\n");
161             break;
162         default:
163             FIXME("Unrecognized/Unhandled WINED3DSHADEMODE value %d\n", stateblock->renderState[WINED3DRS_SHADEMODE]);
164     }
165 }
166
167 static void state_ditherenable(DWORD state, IWineD3DStateBlockImpl *stateblock) {
168     if (stateblock->renderState[WINED3DRS_DITHERENABLE]) {
169         glEnable(GL_DITHER);
170         checkGLcall("glEnable GL_DITHER");
171     } else {
172         glDisable(GL_DITHER);
173         checkGLcall("glDisable GL_DITHER");
174     }
175 }
176
177 static void state_zwritenable(DWORD state, IWineD3DStateBlockImpl *stateblock) {
178     /* TODO: Test if in d3d z writing is enabled even if ZENABLE is off. If yes,
179      * this has to be merged with ZENABLE and ZFUNC
180      */
181     if (stateblock->renderState[WINED3DRS_ZWRITEENABLE]) {
182         glDepthMask(1);
183         checkGLcall("glDepthMask(1)");
184     } else {
185         glDepthMask(0);
186         checkGLcall("glDepthMask(0)");
187     }
188 }
189
190 static void state_zfunc(DWORD state, IWineD3DStateBlockImpl *stateblock) {
191     int glParm = CompareFunc(stateblock->renderState[WINED3DRS_ZFUNC]);
192
193     if(glParm) {
194         glDepthFunc(glParm);
195         checkGLcall("glDepthFunc");
196     }
197 }
198
199 static void state_ambient(DWORD state, IWineD3DStateBlockImpl *stateblock) {
200     float col[4];
201     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_AMBIENT], col);
202
203     TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]);
204     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
205     checkGLcall("glLightModel for MODEL_AMBIENT");
206 }
207
208 static void state_blend(DWORD state, IWineD3DStateBlockImpl *stateblock) {
209     int srcBlend = GL_ZERO;
210     int dstBlend = GL_ZERO;
211     float col[4];
212
213     /* GL_LINE_SMOOTH needs GL_BLEND to work, according to the red book, and special blending params */
214     /* TODO: Is enabling blending really affected by the blendfactor??? */
215     if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE]      ||
216         stateblock->renderState[WINED3DRS_EDGEANTIALIAS]         ||
217         stateblock->renderState[WINED3DRS_ANTIALIASEDLINEENABLE] ||
218         stateblock->renderState[WINED3DRS_BLENDFACTOR] != 0xFFFFFFFF) {
219         glEnable(GL_BLEND);
220         checkGLcall("glEnable GL_BLEND");
221     } else {
222         glDisable(GL_BLEND);
223         checkGLcall("glDisable GL_BLEND");
224         /* Nothing more to do - get out */
225         return;
226     };
227
228     switch (stateblock->renderState[WINED3DRS_SRCBLEND]) {
229         case WINED3DBLEND_ZERO               : srcBlend = GL_ZERO;  break;
230         case WINED3DBLEND_ONE                : srcBlend = GL_ONE;  break;
231         case WINED3DBLEND_SRCCOLOR           : srcBlend = GL_SRC_COLOR;  break;
232         case WINED3DBLEND_INVSRCCOLOR        : srcBlend = GL_ONE_MINUS_SRC_COLOR;  break;
233         case WINED3DBLEND_SRCALPHA           : srcBlend = GL_SRC_ALPHA;  break;
234         case WINED3DBLEND_INVSRCALPHA        : srcBlend = GL_ONE_MINUS_SRC_ALPHA;  break;
235         case WINED3DBLEND_DESTALPHA          : srcBlend = GL_DST_ALPHA;  break;
236         case WINED3DBLEND_INVDESTALPHA       : srcBlend = GL_ONE_MINUS_DST_ALPHA;  break;
237         case WINED3DBLEND_DESTCOLOR          : srcBlend = GL_DST_COLOR;  break;
238         case WINED3DBLEND_INVDESTCOLOR       : srcBlend = GL_ONE_MINUS_DST_COLOR;  break;
239         case WINED3DBLEND_SRCALPHASAT        : srcBlend = GL_SRC_ALPHA_SATURATE;  break;
240
241         case WINED3DBLEND_BOTHSRCALPHA       : srcBlend = GL_SRC_ALPHA;
242             dstBlend = GL_SRC_ALPHA;
243             break;
244
245         case WINED3DBLEND_BOTHINVSRCALPHA    : srcBlend = GL_ONE_MINUS_SRC_ALPHA;
246             dstBlend = GL_ONE_MINUS_SRC_ALPHA;
247             break;
248
249         case WINED3DBLEND_BLENDFACTOR        : srcBlend = GL_CONSTANT_COLOR;   break;
250         case WINED3DBLEND_INVBLENDFACTOR     : srcBlend = GL_ONE_MINUS_CONSTANT_COLOR;  break;
251         default:
252             FIXME("Unrecognized src blend value %d\n", stateblock->renderState[WINED3DRS_SRCBLEND]);
253     }
254
255     switch (stateblock->renderState[WINED3DRS_DESTBLEND]) {
256         case WINED3DBLEND_ZERO               : dstBlend = GL_ZERO;  break;
257         case WINED3DBLEND_ONE                : dstBlend = GL_ONE;  break;
258         case WINED3DBLEND_SRCCOLOR           : dstBlend = GL_SRC_COLOR;  break;
259         case WINED3DBLEND_INVSRCCOLOR        : dstBlend = GL_ONE_MINUS_SRC_COLOR;  break;
260         case WINED3DBLEND_SRCALPHA           : dstBlend = GL_SRC_ALPHA;  break;
261         case WINED3DBLEND_INVSRCALPHA        : dstBlend = GL_ONE_MINUS_SRC_ALPHA;  break;
262         case WINED3DBLEND_DESTALPHA          : dstBlend = GL_DST_ALPHA;  break;
263         case WINED3DBLEND_INVDESTALPHA       : dstBlend = GL_ONE_MINUS_DST_ALPHA;  break;
264         case WINED3DBLEND_DESTCOLOR          : dstBlend = GL_DST_COLOR;  break;
265         case WINED3DBLEND_INVDESTCOLOR       : dstBlend = GL_ONE_MINUS_DST_COLOR;  break;
266         case WINED3DBLEND_SRCALPHASAT        : dstBlend = GL_SRC_ALPHA_SATURATE;  break;
267
268         case WINED3DBLEND_BOTHSRCALPHA       : dstBlend = GL_SRC_ALPHA;
269             srcBlend = GL_SRC_ALPHA;
270             break;
271
272         case WINED3DBLEND_BOTHINVSRCALPHA    : dstBlend = GL_ONE_MINUS_SRC_ALPHA;
273             srcBlend = GL_ONE_MINUS_SRC_ALPHA;
274             break;
275
276         case D3DBLEND_BLENDFACTOR        : dstBlend = GL_CONSTANT_COLOR;   break;
277         case D3DBLEND_INVBLENDFACTOR     : dstBlend = GL_ONE_MINUS_CONSTANT_COLOR;  break;
278         default:
279             FIXME("Unrecognized dst blend value %d\n", stateblock->renderState[WINED3DRS_DESTBLEND]);
280     }
281
282     if(stateblock->renderState[WINED3DRS_EDGEANTIALIAS] ||
283        stateblock->renderState[WINED3DRS_ANTIALIASEDLINEENABLE]) {
284         glEnable(GL_LINE_SMOOTH);
285         checkGLcall("glEnable(GL_LINE_SMOOTH)");
286         if(srcBlend != GL_SRC_ALPHA) {
287             FIXME("WINED3DRS_EDGEANTIALIAS enabled, but incompatible src blending param - what to do?\n");
288             srcBlend = GL_SRC_ALPHA;
289         }
290         if(dstBlend != GL_ONE_MINUS_SRC_ALPHA) {
291             FIXME("WINED3DRS_EDGEANTIALIAS enabled, but incompatible dst blending param - what to do?\n");
292             dstBlend = GL_ONE_MINUS_SRC_ALPHA;
293         }
294     } else {
295         glDisable(GL_LINE_SMOOTH);
296         checkGLcall("glDisable(GL_LINE_SMOOTH)");
297     }
298
299     TRACE("glBlendFunc src=%x, dst=%x\n", srcBlend, dstBlend);
300     glBlendFunc(srcBlend, dstBlend);
301     checkGLcall("glBlendFunc");
302
303     /* TODO: Remove when state management done */
304     stateblock->wineD3DDevice->dstBlend = dstBlend;
305     stateblock->wineD3DDevice->srcBlend = srcBlend;
306
307     TRACE("Setting BlendFactor to %d\n", stateblock->renderState[WINED3DRS_BLENDFACTOR]);
308     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_BLENDFACTOR], col);
309     glBlendColor (col[0],col[1],col[2],col[3]);
310     checkGLcall("glBlendColor");
311 }
312
313 static void state_alpha(DWORD state, IWineD3DStateBlockImpl *stateblock) {
314     int glParm = 0;
315     float ref;
316     BOOL enable_ckey = FALSE;
317
318     IWineD3DSurfaceImpl *surf;
319
320     /* Find out if the texture on the first stage has a ckey set
321      * The alpha state func reads the texture settings, even though alpha and texture are not grouped
322      * together. This is to avoid making a huge alpha+texture+texture stage+ckey block due to the hardly
323      * used WINED3DRS_COLORKEYENABLE state(which is d3d <= 3 only). The texture function will call alpha
324      * in case it finds some texture+colorkeyenable combination which needs extra care.
325      */
326     if(stateblock->textures[0]) {
327         surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *)stateblock->textures[0])->surfaces[0];
328         if(surf->CKeyFlags & DDSD_CKSRCBLT) enable_ckey = TRUE;
329     }
330
331     if (stateblock->renderState[WINED3DRS_ALPHATESTENABLE] ||
332         (stateblock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey)) {
333         glEnable(GL_ALPHA_TEST);
334         checkGLcall("glEnable GL_ALPHA_TEST");
335     } else {
336         glDisable(GL_ALPHA_TEST);
337         checkGLcall("glDisable GL_ALPHA_TEST");
338         /* Alpha test is disabled, don't bother setting the params - it will happen on the next
339          * enable call
340          */
341         return;
342     }
343
344     if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey) {
345         glParm = GL_NOTEQUAL;
346         ref = 0.0;
347     } else {
348         ref = ((float) stateblock->renderState[WINED3DRS_ALPHAREF]) / 255.0f;
349         glParm = CompareFunc(stateblock->renderState[WINED3DRS_ALPHAFUNC]);
350     }
351     if(glParm) {
352         stateblock->wineD3DDevice->alphafunc = glParm; /* Remove when state management done */
353         glAlphaFunc(glParm, ref);
354         checkGLcall("glAlphaFunc");
355     }
356     /* TODO: Some texture blending operations seem to affect the alpha test */
357 }
358
359 static void state_clipping(DWORD state, IWineD3DStateBlockImpl *stateblock) {
360     DWORD enable  = 0xFFFFFFFF;
361     DWORD disable = 0x00000000;
362
363     /* TODO: Keep track of previously enabled clipplanes to avoid unneccessary resetting
364      * of already set values
365      */
366
367     /* If enabling / disabling all
368      * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
369      */
370     if (stateblock->renderState[WINED3DRS_CLIPPING]) {
371         enable  = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
372         disable = ~stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
373     } else {
374         disable = 0xffffffff;
375         enable  = 0x00;
376     }
377
378     if (enable & WINED3DCLIPPLANE0)  { glEnable(GL_CLIP_PLANE0);  checkGLcall("glEnable(clip plane 0)"); }
379     if (enable & WINED3DCLIPPLANE1)  { glEnable(GL_CLIP_PLANE1);  checkGLcall("glEnable(clip plane 1)"); }
380     if (enable & WINED3DCLIPPLANE2)  { glEnable(GL_CLIP_PLANE2);  checkGLcall("glEnable(clip plane 2)"); }
381     if (enable & WINED3DCLIPPLANE3)  { glEnable(GL_CLIP_PLANE3);  checkGLcall("glEnable(clip plane 3)"); }
382     if (enable & WINED3DCLIPPLANE4)  { glEnable(GL_CLIP_PLANE4);  checkGLcall("glEnable(clip plane 4)"); }
383     if (enable & WINED3DCLIPPLANE5)  { glEnable(GL_CLIP_PLANE5);  checkGLcall("glEnable(clip plane 5)"); }
384
385     if (disable & WINED3DCLIPPLANE0) { glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)"); }
386     if (disable & WINED3DCLIPPLANE1) { glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)"); }
387     if (disable & WINED3DCLIPPLANE2) { glDisable(GL_CLIP_PLANE2); checkGLcall("glDisable(clip plane 2)"); }
388     if (disable & WINED3DCLIPPLANE3) { glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)"); }
389     if (disable & WINED3DCLIPPLANE4) { glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)"); }
390     if (disable & WINED3DCLIPPLANE5) { glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)"); }
391
392     /** update clipping status */
393     if (enable) {
394         stateblock->clip_status.ClipUnion = 0;
395         stateblock->clip_status.ClipIntersection = 0xFFFFFFFF;
396     } else {
397         stateblock->clip_status.ClipUnion = 0;
398         stateblock->clip_status.ClipIntersection = 0;
399     }
400 }
401
402 static void state_blendop(DWORD state, IWineD3DStateBlockImpl *stateblock) {
403     int glParm = GL_FUNC_ADD;
404
405     if(!GL_SUPPORT(EXT_BLEND_MINMAX)) {
406         WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
407         return;
408     }
409
410     switch ((WINED3DBLENDOP) stateblock->renderState[WINED3DRS_BLENDOP]) {
411         case WINED3DBLENDOP_ADD              : glParm = GL_FUNC_ADD;              break;
412         case WINED3DBLENDOP_SUBTRACT         : glParm = GL_FUNC_SUBTRACT;         break;
413         case WINED3DBLENDOP_REVSUBTRACT      : glParm = GL_FUNC_REVERSE_SUBTRACT; break;
414         case WINED3DBLENDOP_MIN              : glParm = GL_MIN;                   break;
415         case WINED3DBLENDOP_MAX              : glParm = GL_MAX;                   break;
416         default:
417             FIXME("Unrecognized/Unhandled D3DBLENDOP value %d\n", stateblock->renderState[WINED3DRS_BLENDOP]);
418     }
419
420     TRACE("glBlendEquation(%x)\n", glParm);
421     GL_EXTCALL(glBlendEquation(glParm));
422     checkGLcall("glBlendEquation");
423 }
424
425 static void
426 state_specularenable(DWORD state, IWineD3DStateBlockImpl *stateblock) {
427     /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
428      * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
429      * specular color. This is wrong:
430      * Separate specular color means the specular colour is maintained separately, whereas
431      * single color means it is merged in. However in both cases they are being used to
432      * some extent.
433      * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
434      * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
435      * running 1.4 yet!
436      *
437      *
438      * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
439      * Instead, we need to setup the FinalCombiner properly.
440      *
441      * The default setup for the FinalCombiner is:
442      *
443      * <variable>       <input>                             <mapping>               <usage>
444      * GL_VARIABLE_A_NV GL_FOG,                             GL_UNSIGNED_IDENTITY_NV GL_ALPHA
445      * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV   GL_UNSIGNED_IDENTITY_NV GL_RGB
446      * GL_VARIABLE_C_NV GL_FOG                              GL_UNSIGNED_IDENTITY_NV GL_RGB
447      * GL_VARIABLE_D_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
448      * GL_VARIABLE_E_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
449      * GL_VARIABLE_F_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
450      * GL_VARIABLE_G_NV GL_SPARE0_NV                        GL_UNSIGNED_IDENTITY_NV GL_ALPHA
451      *
452      * That's pretty much fine as it is, except for variable B, which needs to take
453      * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
454      * whether WINED3DRS_SPECULARENABLE is enabled or not.
455      */
456
457     TRACE("Setting specular enable state\n");
458     /* TODO: Add to the material setting functions */
459     if (stateblock->renderState[WINED3DRS_SPECULARENABLE]) {
460         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*) &stateblock->material.Specular);
461         checkGLcall("glMaterialfv");
462         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
463             glEnable(GL_COLOR_SUM_EXT);
464         } else {
465             TRACE("Specular colors cannot be enabled in this version of opengl\n");
466         }
467         checkGLcall("glEnable(GL_COLOR_SUM)");
468
469         if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
470             GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
471             checkGLcall("glFinalCombinerInputNV()");
472         }
473     } else {
474         float black[4] = {0.0f, 0.0f, 0.0f, 0.0f};
475
476         /* for the case of enabled lighting: */
477         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
478         checkGLcall("glMaterialfv");
479
480         /* for the case of disabled lighting: */
481         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
482             glDisable(GL_COLOR_SUM_EXT);
483         } else {
484             TRACE("Specular colors cannot be disabled in this version of opengl\n");
485         }
486         checkGLcall("glDisable(GL_COLOR_SUM)");
487
488         if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
489             GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
490             checkGLcall("glFinalCombinerInputNV()");
491         }
492     }
493 }
494
495 static void state_texfactor(DWORD state, IWineD3DStateBlockImpl *stateblock) {
496     unsigned int i;
497
498     /* Note the texture color applies to all textures whereas
499      * GL_TEXTURE_ENV_COLOR applies to active only
500      */
501     float col[4];
502     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
503
504     if (!GL_SUPPORT(NV_REGISTER_COMBINERS)) {
505         /* And now the default texture color as well */
506         for (i = 0; i < GL_LIMITS(texture_stages); i++) {
507             /* Note the WINED3DRS value applies to all textures, but GL has one
508              * per texture, so apply it now ready to be used!
509              */
510             if (GL_SUPPORT(ARB_MULTITEXTURE)) {
511                 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
512                 checkGLcall("glActiveTextureARB");
513             } else if (i>0) {
514                 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
515             }
516
517             glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
518             checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
519         }
520     }
521 }
522
523 static void
524 renderstate_stencil_twosided(IWineD3DStateBlockImpl *stateblock, GLint face, GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass ) {
525 #if 0 /* Don't use OpenGL 2.0 calls for now */
526             if(GL_EXTCALL(glStencilFuncSeparate) && GL_EXTCALL(glStencilOpSeparate)) {
527                 GL_EXTCALL(glStencilFuncSeparate(face, func, ref, mask));
528                 checkGLcall("glStencilFuncSeparate(...)");
529                 GL_EXTCALL(glStencilOpSeparate(face, stencilFail, depthFail, stencilPass));
530                 checkGLcall("glStencilOpSeparate(...)");
531         }
532             else
533 #endif
534     if(GL_SUPPORT(EXT_STENCIL_TWO_SIDE)) {
535         glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
536         checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
537         GL_EXTCALL(glActiveStencilFaceEXT(face));
538         checkGLcall("glActiveStencilFaceEXT(...)");
539         glStencilFunc(func, ref, mask);
540         checkGLcall("glStencilFunc(...)");
541         glStencilOp(stencilFail, depthFail, stencilPass);
542         checkGLcall("glStencilOp(...)");
543     } else if(GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
544         GL_EXTCALL(glStencilFuncSeparateATI(face, func, ref, mask));
545         checkGLcall("glStencilFuncSeparateATI(...)");
546         GL_EXTCALL(glStencilOpSeparateATI(face, stencilFail, depthFail, stencilPass));
547         checkGLcall("glStencilOpSeparateATI(...)");
548     } else {
549         ERR("Separate (two sided) stencil not supported on this version of opengl. Caps weren't honored?\n");
550     }
551 }
552
553 static void
554 state_stencil(DWORD state, IWineD3DStateBlockImpl *stateblock) {
555     DWORD onesided_enable = FALSE;
556     DWORD twosided_enable = FALSE;
557     GLint func = GL_ALWAYS;
558     GLint func_ccw = GL_ALWAYS;
559     GLint ref = 0;
560     GLuint mask = 0;
561     GLint stencilFail = GL_KEEP;
562     GLint depthFail = GL_KEEP;
563     GLint stencilPass = GL_KEEP;
564     GLint stencilFail_ccw = GL_KEEP;
565     GLint depthFail_ccw = GL_KEEP;
566     GLint stencilPass_ccw = GL_KEEP;
567
568     if( stateblock->set.renderState[WINED3DRS_STENCILENABLE] )
569         onesided_enable = stateblock->renderState[WINED3DRS_STENCILENABLE];
570     if( stateblock->set.renderState[WINED3DRS_TWOSIDEDSTENCILMODE] )
571         twosided_enable = stateblock->renderState[WINED3DRS_TWOSIDEDSTENCILMODE];
572     if( stateblock->set.renderState[WINED3DRS_STENCILFUNC] )
573         if( !( func = CompareFunc(stateblock->renderState[WINED3DRS_STENCILFUNC]) ) )
574             func = GL_ALWAYS;
575     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILFUNC] )
576         if( !( func_ccw = CompareFunc(stateblock->renderState[WINED3DRS_CCW_STENCILFUNC]) ) )
577             func = GL_ALWAYS;
578     if( stateblock->set.renderState[WINED3DRS_STENCILREF] )
579         ref = stateblock->renderState[WINED3DRS_STENCILREF];
580     if( stateblock->set.renderState[WINED3DRS_STENCILMASK] )
581         mask = stateblock->renderState[WINED3DRS_STENCILMASK];
582     if( stateblock->set.renderState[WINED3DRS_STENCILFAIL] )
583         stencilFail = StencilOp(stateblock->renderState[WINED3DRS_STENCILFAIL]);
584     if( stateblock->set.renderState[WINED3DRS_STENCILZFAIL] )
585         depthFail = StencilOp(stateblock->renderState[WINED3DRS_STENCILZFAIL]);
586     if( stateblock->set.renderState[WINED3DRS_STENCILPASS] )
587         stencilPass = StencilOp(stateblock->renderState[WINED3DRS_STENCILPASS]);
588     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILFAIL] )
589         stencilFail_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILFAIL]);
590     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILZFAIL] )
591         depthFail_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILZFAIL]);
592     if( stateblock->set.renderState[WINED3DRS_CCW_STENCILPASS] )
593         stencilPass_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILPASS]);
594
595     TRACE("(onesided %d, twosided %d, ref %x, mask %x,  \
596             GL_FRONT: func: %x, fail %x, zfail %x, zpass %x  \
597             GL_BACK: func: %x, fail %x, zfail %x, zpass %x )\n",
598     onesided_enable, twosided_enable, ref, mask,
599     func, stencilFail, depthFail, stencilPass,
600     func_ccw, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
601
602     if (twosided_enable) {
603         renderstate_stencil_twosided(stateblock, GL_FRONT, func, ref, mask, stencilFail, depthFail, stencilPass);
604         renderstate_stencil_twosided(stateblock, GL_BACK, func_ccw, ref, mask, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
605     } else {
606         if (onesided_enable) {
607             glEnable(GL_STENCIL_TEST);
608             checkGLcall("glEnable GL_STENCIL_TEST");
609             glStencilFunc(func, ref, mask);
610             checkGLcall("glStencilFunc(...)");
611             glStencilOp(stencilFail, depthFail, stencilPass);
612             checkGLcall("glStencilOp(...)");
613         } else {
614             glDisable(GL_STENCIL_TEST);
615             checkGLcall("glDisable GL_STENCIL_TEST");
616         }
617     }
618 }
619
620 static void state_stencilwrite(DWORD state, IWineD3DStateBlockImpl *stateblock) {
621     glStencilMask(stateblock->renderState[WINED3DRS_STENCILWRITEMASK]);
622     checkGLcall("glStencilMask");
623 }
624
625 static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock) {
626     /* TODO: Put this into the vertex type block once that is in the state table */
627     BOOL fogenable = stateblock->renderState[WINED3DRS_FOGENABLE];
628     float fogstart, fogend;
629
630     union {
631         DWORD d;
632         float f;
633     } tmpvalue;
634
635     if (!fogenable) {
636         /* No fog? Disable it, and we're done :-) */
637         glDisable(GL_FOG);
638         checkGLcall("glDisable GL_FOG");
639     }
640
641     tmpvalue.d = stateblock->renderState[WINED3DRS_FOGSTART];
642     fogstart = tmpvalue.f;
643     tmpvalue.d = stateblock->renderState[WINED3DRS_FOGEND];
644     fogend = tmpvalue.f;
645
646 #if 0
647     /* Activate when vertex shaders are in the state table */
648     if(stateblock->vertexShader && ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function &&
649        ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->usesFog) {
650         glFogi(GL_FOG_MODE, GL_LINEAR);
651         checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
652         fogstart = 1.0;
653         fogend = 0.0;
654         stateblock->wineD3DDevice->last_was_foggy_shader = TRUE;
655     }
656 #endif
657
658     /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
659      * the system will apply only pixel(=table) fog effects."
660      */
661     /* else */ if(stateblock->renderState[WINED3DRS_FOGTABLEMODE] == D3DFOG_NONE) {
662         glHint(GL_FOG_HINT, GL_FASTEST);
663         checkGLcall("glHint(GL_FOG_HINT, GL_FASTEST)");
664 #if 0
665         stateblock->wineD3DDevice->last_was_foggy_shader = FALSE;
666 #endif
667         switch (stateblock->renderState[WINED3DRS_FOGVERTEXMODE]) {
668             /* Processed vertices have their fog factor stored in the specular value. Fall too the none case.
669              * If we are drawing untransformed vertices atm, d3ddevice_set_ortho will update the fog
670              */
671             case D3DFOG_EXP:  {
672                 if(!stateblock->wineD3DDevice->last_was_rhw) {
673                     glFogi(GL_FOG_MODE, GL_EXP);
674                     checkGLcall("glFogi(GL_FOG_MODE, GL_EXP");
675                     if(GL_SUPPORT(EXT_FOG_COORD)) {
676                         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
677                         checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
678                     }
679                     break;
680                 }
681             }
682             case D3DFOG_EXP2: {
683                 if(!stateblock->wineD3DDevice->last_was_rhw) {
684                     glFogi(GL_FOG_MODE, GL_EXP2);
685                     checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2");
686                     if(GL_SUPPORT(EXT_FOG_COORD)) {
687                         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
688                         checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
689                     }
690                     break;
691                 }
692             }
693             case D3DFOG_LINEAR: {
694                 if(!stateblock->wineD3DDevice->last_was_rhw) {
695                     glFogi(GL_FOG_MODE, GL_LINEAR);
696                     checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR");
697                     if(GL_SUPPORT(EXT_FOG_COORD)) {
698                         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
699                         checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
700                     }
701                     break;
702                 }
703             }
704             case D3DFOG_NONE: {
705                 /* Both are none? According to msdn the alpha channel of the specular
706                  * color contains a fog factor. Set it in drawStridedSlow.
707                  * Same happens with Vertexfog on transformed vertices
708                  */
709                 if(GL_SUPPORT(EXT_FOG_COORD)) {
710                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
711                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)\n");
712                     glFogi(GL_FOG_MODE, GL_LINEAR);
713                     checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
714                     fogstart = 0xff;
715                     fogend = 0x0;
716                 } else {
717                     /* Disable GL fog, handle this in software in drawStridedSlow */
718                     fogenable = FALSE;
719                 }
720                 break;
721             }
722             default: FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %d\n", stateblock->renderState[WINED3DRS_FOGVERTEXMODE]);
723         }
724     } else {
725         glHint(GL_FOG_HINT, GL_NICEST);
726         checkGLcall("glHint(GL_FOG_HINT, GL_NICEST)");
727 #if 0
728         stateblock->wineD3DDevice->last_was_foggy_shader = FALSE;
729 #endif
730         switch (stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
731             case D3DFOG_EXP:
732                 glFogi(GL_FOG_MODE, GL_EXP);
733                 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP");
734                 if(GL_SUPPORT(EXT_FOG_COORD)) {
735                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
736                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
737                 }
738                 break;
739
740             case D3DFOG_EXP2:
741                 glFogi(GL_FOG_MODE, GL_EXP2);
742                 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2");
743                 if(GL_SUPPORT(EXT_FOG_COORD)) {
744                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
745                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
746                 }
747                 break;
748
749             case D3DFOG_LINEAR:
750                 glFogi(GL_FOG_MODE, GL_LINEAR);
751                 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR");
752                 if(GL_SUPPORT(EXT_FOG_COORD)) {
753                     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
754                     checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT");
755                 }
756                 break;
757
758             case D3DFOG_NONE:   /* Won't happen */
759             default:
760                 FIXME("Unexpected WINED3DRS_FOGTABLEMODE %d\n", stateblock->renderState[WINED3DRS_FOGTABLEMODE]);
761         }
762     }
763
764     if(fogenable) {
765         glEnable(GL_FOG);
766         checkGLcall("glEnable GL_FOG");
767
768         glFogfv(GL_FOG_START, &fogstart);
769         checkGLcall("glFogf(GL_FOG_START, fogstart");
770         TRACE("Fog Start == %f\n", fogstart);
771
772         glFogfv(GL_FOG_END, &fogend);
773         checkGLcall("glFogf(GL_FOG_END, fogend");
774         TRACE("Fog End == %f\n", fogend);
775     } else {
776         glDisable(GL_FOG);
777         checkGLcall("glDisable GL_FOG");
778     }
779
780     if (GL_SUPPORT(NV_FOG_DISTANCE)) {
781         glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
782     }
783 }
784
785 static void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock) {
786     float col[4];
787     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_FOGCOLOR], col);
788     /* Set the default alpha blend color */
789     glFogfv(GL_FOG_COLOR, &col[0]);
790     checkGLcall("glFog GL_FOG_COLOR");
791 }
792
793 static void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock) {
794     union {
795         DWORD d;
796         float f;
797     } tmpvalue;
798     tmpvalue.d = stateblock->renderState[WINED3DRS_FOGDENSITY];
799     glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
800     checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
801 }
802
803 /* TODO: Merge with primitive type + init_materials()!! */
804 static void state_colormat(DWORD state, IWineD3DStateBlockImpl *stateblock) {
805     GLenum Parm = GL_AMBIENT_AND_DIFFUSE;
806
807     if (stateblock->renderState[WINED3DRS_COLORVERTEX]) {
808         TRACE("diff %d, amb %d, emis %d, spec %d\n",
809               stateblock->renderState[WINED3DRS_DIFFUSEMATERIALSOURCE],
810               stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE],
811               stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE],
812               stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE]);
813
814         if (stateblock->renderState[WINED3DRS_DIFFUSEMATERIALSOURCE] == D3DMCS_COLOR1) {
815             if (stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE] == D3DMCS_COLOR1) {
816                 Parm = GL_AMBIENT_AND_DIFFUSE;
817             } else {
818                 Parm = GL_DIFFUSE;
819             }
820         } else if (stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE] == D3DMCS_COLOR1) {
821             Parm = GL_AMBIENT;
822         } else if (stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE] == D3DMCS_COLOR1) {
823             Parm = GL_EMISSION;
824         } else if (stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE] == D3DMCS_COLOR1) {
825             Parm = GL_SPECULAR;
826         } else {
827             Parm = -1;
828         }
829
830         if (Parm == -1) {
831             if (stateblock->wineD3DDevice->tracking_color != DISABLED_TRACKING) stateblock->wineD3DDevice->tracking_color = NEEDS_DISABLE;
832         } else {
833             stateblock->wineD3DDevice->tracking_color = NEEDS_TRACKING;
834             stateblock->wineD3DDevice->tracking_parm  = Parm;
835         }
836
837     } else {
838         if (stateblock->wineD3DDevice->tracking_color != DISABLED_TRACKING) stateblock->wineD3DDevice->tracking_color = NEEDS_DISABLE;
839     }
840 }
841
842 static void state_linepattern(DWORD state, IWineD3DStateBlockImpl *stateblock) {
843     union {
844         DWORD                 d;
845         WINED3DLINEPATTERN    lp;
846     } tmppattern;
847     tmppattern.d = stateblock->renderState[WINED3DRS_LINEPATTERN];
848
849     TRACE("Line pattern: repeat %d bits %x\n", tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
850
851     if (tmppattern.lp.wRepeatFactor) {
852         glLineStipple(tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
853         checkGLcall("glLineStipple(repeat, linepattern)");
854         glEnable(GL_LINE_STIPPLE);
855         checkGLcall("glEnable(GL_LINE_STIPPLE);");
856     } else {
857         glDisable(GL_LINE_STIPPLE);
858         checkGLcall("glDisable(GL_LINE_STIPPLE);");
859     }
860 }
861
862 static void state_zbias(DWORD state, IWineD3DStateBlockImpl *stateblock) {
863     union {
864         DWORD d;
865         float f;
866     } tmpvalue;
867
868     if (stateblock->renderState[WINED3DRS_ZBIAS]) {
869         tmpvalue.d = stateblock->renderState[WINED3DRS_ZBIAS];
870         TRACE("ZBias value %f\n", tmpvalue.f);
871         glPolygonOffset(0, -tmpvalue.f);
872         checkGLcall("glPolygonOffset(0, -Value)");
873         glEnable(GL_POLYGON_OFFSET_FILL);
874         checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL);");
875         glEnable(GL_POLYGON_OFFSET_LINE);
876         checkGLcall("glEnable(GL_POLYGON_OFFSET_LINE);");
877         glEnable(GL_POLYGON_OFFSET_POINT);
878         checkGLcall("glEnable(GL_POLYGON_OFFSET_POINT);");
879     } else {
880         glDisable(GL_POLYGON_OFFSET_FILL);
881         checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL);");
882         glDisable(GL_POLYGON_OFFSET_LINE);
883         checkGLcall("glDisable(GL_POLYGON_OFFSET_LINE);");
884         glDisable(GL_POLYGON_OFFSET_POINT);
885         checkGLcall("glDisable(GL_POLYGON_OFFSET_POINT);");
886     }
887 }
888
889
890 static void state_normalize(DWORD state, IWineD3DStateBlockImpl *stateblock) {
891     if (stateblock->renderState[WINED3DRS_NORMALIZENORMALS]) {
892         glEnable(GL_NORMALIZE);
893         checkGLcall("glEnable(GL_NORMALIZE);");
894     } else {
895         glDisable(GL_NORMALIZE);
896         checkGLcall("glDisable(GL_NORMALIZE);");
897     }
898 }
899
900 static void state_psize(DWORD state, IWineD3DStateBlockImpl *stateblock) {
901     union {
902         DWORD d;
903         float f;
904     } tmpvalue;
905
906     /* FIXME: check that pointSize isn't outside glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize ); or -ve */
907     tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE];
908     TRACE("Set point size to %f\n", tmpvalue.f);
909     glPointSize(tmpvalue.f);
910     checkGLcall("glPointSize(...);");
911 }
912
913 static void state_psizemin(DWORD state, IWineD3DStateBlockImpl *stateblock) {
914     union {
915         DWORD d;
916         float f;
917     } tmpvalue;
918
919     if (GL_SUPPORT(EXT_POINT_PARAMETERS)) {
920         tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
921         GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, tmpvalue.f);
922         checkGLcall("glPointParameterfEXT(...);");
923     } else {
924         FIXME("WINED3DRS_POINTSIZE_MIN not supported on this opengl\n");
925     }
926 }
927
928 static void state_psizemax(DWORD state, IWineD3DStateBlockImpl *stateblock) {
929     union {
930         DWORD d;
931         float f;
932     } tmpvalue;
933
934     if (GL_SUPPORT(EXT_POINT_PARAMETERS)) {
935         tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
936         GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, tmpvalue.f);
937         checkGLcall("glPointParameterfEXT(...);");
938     } else {
939         FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl\n");
940     }
941 }
942
943 static void state_pscale(DWORD state, IWineD3DStateBlockImpl *stateblock) {
944     /* TODO: Group this with the viewport */
945     /*
946      * POINTSCALEENABLE controls how point size value is treated. If set to
947      * true, the point size is scaled with respect to height of viewport.
948      * When set to false point size is in pixels.
949      *
950      * http://msdn.microsoft.com/library/en-us/directx9_c/point_sprites.asp
951      */
952
953     /* Default values */
954     GLfloat att[3] = {1.0f, 0.0f, 0.0f};
955
956     /*
957      * Minimum valid point size for OpenGL is 1.0f. For Direct3D it is 0.0f.
958      * This means that OpenGL will clamp really small point sizes to 1.0f.
959      * To correct for this we need to multiply by the scale factor when sizes
960      * are less than 1.0f. scale_factor =  1.0f / point_size.
961      */
962     GLfloat pointSize = *((float*)&stateblock->renderState[WINED3DRS_POINTSIZE]);
963     if(pointSize > 0.0f) {
964         GLfloat scaleFactor;
965
966         if(pointSize < 1.0f) {
967             scaleFactor = pointSize * pointSize;
968         } else {
969             scaleFactor = 1.0f;
970         }
971
972         if(stateblock->renderState[WINED3DRS_POINTSCALEENABLE]) {
973             att[0] = *((float*)&stateblock->renderState[WINED3DRS_POINTSCALE_A]) /
974                     (stateblock->viewport.Height * stateblock->viewport.Height * scaleFactor);
975             att[1] = *((float*)&stateblock->renderState[WINED3DRS_POINTSCALE_B]) /
976                     (stateblock->viewport.Height * stateblock->viewport.Height * scaleFactor);
977             att[2] = *((float*)&stateblock->renderState[WINED3DRS_POINTSCALE_C]) /
978                     (stateblock->viewport.Height * stateblock->viewport.Height * scaleFactor);
979         }
980     }
981
982     if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
983         GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
984         checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...");
985     }
986     else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
987         GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
988         checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...");
989     } else {
990         TRACE("POINT_PARAMETERS not supported in this version of opengl\n");
991     }
992 }
993
994 static void state_colorwrite(DWORD state, IWineD3DStateBlockImpl *stateblock) {
995     DWORD Value = stateblock->renderState[WINED3DRS_COLORWRITEENABLE];
996
997     TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
998         Value & D3DCOLORWRITEENABLE_RED   ? 1 : 0,
999         Value & D3DCOLORWRITEENABLE_GREEN ? 1 : 0,
1000         Value & D3DCOLORWRITEENABLE_BLUE  ? 1 : 0,
1001         Value & D3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1002     glColorMask(Value & D3DCOLORWRITEENABLE_RED   ? GL_TRUE : GL_FALSE,
1003                 Value & D3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1004                 Value & D3DCOLORWRITEENABLE_BLUE  ? GL_TRUE : GL_FALSE,
1005                 Value & D3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1006     checkGLcall("glColorMask(...)");
1007
1008     /* depends on WINED3DRS_COLORWRITEENABLE. */
1009     if(stateblock->renderState[WINED3DRS_COLORWRITEENABLE1] != 0x0000000F ||
1010        stateblock->renderState[WINED3DRS_COLORWRITEENABLE2] != 0x0000000F ||
1011        stateblock->renderState[WINED3DRS_COLORWRITEENABLE3] != 0x0000000F ) {
1012         ERR("(WINED3DRS_COLORWRITEENABLE1/2/3,%d,%d,%d) not yet implemented. Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n",
1013             stateblock->renderState[WINED3DRS_COLORWRITEENABLE1],
1014             stateblock->renderState[WINED3DRS_COLORWRITEENABLE2],
1015             stateblock->renderState[WINED3DRS_COLORWRITEENABLE3]);
1016     }
1017 }
1018
1019 static void state_localviewer(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1020     if(stateblock->renderState[WINED3DRS_LOCALVIEWER]) {
1021         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1022         checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1023     } else {
1024         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1025         checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
1026     }
1027 }
1028
1029 static void state_lastpixel(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1030     if(stateblock->renderState[WINED3DRS_LASTPIXEL]) {
1031         TRACE("Last Pixel Drawing Enabled\n");
1032     } else {
1033         FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1034     }
1035 }
1036
1037 static void state_pointsprite(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1038     /* TODO: NV_POINT_SPRITE */
1039     if (!GL_SUPPORT(ARB_POINT_SPRITE)) {
1040         TRACE("Point sprites not supported\n");
1041         return;
1042     }
1043
1044     /*
1045      * Point sprites are always enabled. Value controls texture coordinate
1046      * replacement mode. Must be set true for point sprites to use
1047      * textures.
1048      */
1049     glEnable(GL_POINT_SPRITE_ARB);
1050     checkGLcall("glEnable(GL_POINT_SPRITE_ARB)");
1051
1052     if (stateblock->renderState[WINED3DRS_POINTSPRITEENABLE]) {
1053         glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, TRUE);
1054         checkGLcall("glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, TRUE)");
1055     } else {
1056         glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, FALSE);
1057         checkGLcall("glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, FALSE)");
1058     }
1059 }
1060
1061 static void state_wrap(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1062     /**
1063      http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/texture/
1064      http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/graphics/programmingguide/FixedFunction/Textures/texturewrapping.asp
1065      http://www.gamedev.net/reference/programming/features/rendererdll3/page2.asp
1066      Descussion that ways to turn on WRAPing to solve an opengl conversion problem.
1067      http://www.flipcode.org/cgi-bin/fcmsg.cgi?thread_show=10248
1068
1069      so far as I can tell, wrapping and texture-coordinate generate go hand in hand,
1070      */
1071     TRACE("Stub\n");
1072     if(stateblock->renderState[WINED3DRS_WRAP0] ||
1073        stateblock->renderState[WINED3DRS_WRAP1] ||
1074        stateblock->renderState[WINED3DRS_WRAP2] ||
1075        stateblock->renderState[WINED3DRS_WRAP3] ||
1076        stateblock->renderState[WINED3DRS_WRAP4] ||
1077        stateblock->renderState[WINED3DRS_WRAP5] ||
1078        stateblock->renderState[WINED3DRS_WRAP6] ||
1079        stateblock->renderState[WINED3DRS_WRAP7] ||
1080        stateblock->renderState[WINED3DRS_WRAP8] ||
1081        stateblock->renderState[WINED3DRS_WRAP9] ||
1082        stateblock->renderState[WINED3DRS_WRAP10] ||
1083        stateblock->renderState[WINED3DRS_WRAP11] ||
1084        stateblock->renderState[WINED3DRS_WRAP12] ||
1085        stateblock->renderState[WINED3DRS_WRAP13] ||
1086        stateblock->renderState[WINED3DRS_WRAP14] ||
1087        stateblock->renderState[WINED3DRS_WRAP15] ) {
1088         ERR("(WINED3DRS_WRAP0) Texture wraping not yet supported\n");
1089     }
1090 }
1091
1092 static void state_multisampleaa(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1093     if( GL_SUPPORT(ARB_MULTISAMPLE) ) {
1094         if(stateblock->renderState[WINED3DRS_MULTISAMPLEANTIALIAS]) {
1095             glEnable(GL_MULTISAMPLE_ARB);
1096             checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1097         } else {
1098             glDisable(GL_MULTISAMPLE_ARB);
1099             checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1100         }
1101     } else {
1102         if(stateblock->renderState[WINED3DRS_MULTISAMPLEANTIALIAS]) {
1103             ERR("Multisample antialiasing not supported by gl\n");
1104         }
1105     }
1106 }
1107
1108 static void state_scissor(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1109     if(stateblock->renderState[WINED3DRS_SCISSORTESTENABLE]) {
1110         glEnable(GL_SCISSOR_TEST);
1111         checkGLcall("glEnable(GL_SCISSOR_TEST)");
1112     } else {
1113         glDisable(GL_SCISSOR_TEST);
1114         checkGLcall("glDisable(GL_SCISSOR_TEST)");
1115     }
1116 }
1117
1118 static void state_depthbias(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1119     union {
1120         DWORD d;
1121         float f;
1122     } tmpvalue;
1123
1124     if(stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS] ||
1125        stateblock->renderState[WINED3DRS_DEPTHBIAS]) {
1126         tmpvalue.d = stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS];
1127         glEnable(GL_POLYGON_OFFSET_FILL);
1128         checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
1129         glPolygonOffset(tmpvalue.f, *((float*)&stateblock->renderState[WINED3DRS_DEPTHBIAS]));
1130         checkGLcall("glPolygonOffset(...)");
1131     } else {
1132         glDisable(GL_POLYGON_OFFSET_FILL);
1133         checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
1134     }
1135 }
1136
1137 static void state_perspective(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1138     if (stateblock->renderState[WINED3DRS_TEXTUREPERSPECTIVE]) {
1139         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1140         checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)");
1141     } else {
1142         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1143         checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)");
1144     }
1145 }
1146
1147 static void state_stippledalpha(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1148     TRACE("Stub\n");
1149     if (stateblock->renderState[WINED3DRS_STIPPLEDALPHA])
1150         ERR(" Stippled Alpha not supported yet.\n");
1151 }
1152
1153 static void state_antialias(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1154     TRACE("Stub\n");
1155     if (stateblock->renderState[WINED3DRS_ANTIALIAS])
1156         ERR(" Antialias not supported yet.\n");
1157 }
1158
1159 static void state_multisampmask(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1160     TRACE("Stub\n");
1161     if (stateblock->renderState[WINED3DRS_MULTISAMPLEMASK] != 0xFFFFFFFF)
1162         ERR("(WINED3DRS_MULTISAMPLEMASK,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_MULTISAMPLEMASK]);
1163 }
1164
1165 static void state_patchedgestyle(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1166     TRACE("Stub\n");
1167     if (stateblock->renderState[WINED3DRS_PATCHEDGESTYLE] != D3DPATCHEDGE_DISCRETE)
1168         ERR("(WINED3DRS_PATCHEDGESTYLE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_PATCHEDGESTYLE]);
1169 }
1170
1171 static void state_patchsegments(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1172     union {
1173         DWORD d;
1174         float f;
1175     } tmpvalue;
1176     tmpvalue.f = 1.0f;
1177
1178     TRACE("Stub\n");
1179     if (stateblock->renderState[WINED3DRS_PATCHSEGMENTS] != tmpvalue.d)
1180         ERR("(WINED3DRS_PATCHSEGMENTS,%d) not yet implemented\n", tmpvalue.d);
1181 }
1182
1183 static void state_positiondegree(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1184     TRACE("Stub\n");
1185     if (stateblock->renderState[WINED3DRS_POSITIONDEGREE] != D3DDEGREE_CUBIC)
1186         ERR("(WINED3DRS_POSITIONDEGREE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_POSITIONDEGREE]);
1187 }
1188
1189 static void state_normaldegree(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1190     TRACE("Stub\n");
1191     if (stateblock->renderState[WINED3DRS_NORMALDEGREE] != D3DDEGREE_LINEAR)
1192         ERR("(WINED3DRS_NORMALDEGREE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_NORMALDEGREE]);
1193 }
1194
1195 static void state_tessellation(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1196     TRACE("Stub\n");
1197     if(stateblock->renderState[WINED3DRS_ENABLEADAPTIVETESSELLATION])
1198         FIXME("(WINED3DRS_ENABLEADAPTIVETESSELLATION,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_ENABLEADAPTIVETESSELLATION]);
1199 }
1200
1201
1202 static void state_srgbwrite(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1203     if(stateblock->renderState[WINED3DRS_SRGBWRITEENABLE])
1204         ERR("Render state WINED3DRS_SRGBWRITEENABLE not yet implemented\n");
1205 }
1206
1207 static void state_seperateblend(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1208     TRACE("Stub\n");
1209     if(stateblock->renderState[WINED3DRS_SEPARATEALPHABLENDENABLE])
1210         FIXME("(WINED3DRS_SEPARATEALPHABLENDENABLE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_SEPARATEALPHABLENDENABLE]);
1211 }
1212
1213 static void state_wrapu(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1214     if(stateblock->renderState[WINED3DRS_WRAPU]) {
1215         FIXME("Render state WINED3DRS_WRAPU not implemented yet\n");
1216     }
1217 }
1218
1219 static void state_wrapv(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1220     if(stateblock->renderState[WINED3DRS_WRAPV]) {
1221         FIXME("Render state WINED3DRS_WRAPV not implemented yet\n");
1222     }
1223 }
1224
1225 static void state_monoenable(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1226     if(stateblock->renderState[WINED3DRS_MONOENABLE]) {
1227         FIXME("Render state WINED3DRS_MONOENABLE not implemented yet\n");
1228     }
1229 }
1230
1231 static void state_rop2(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1232     if(stateblock->renderState[WINED3DRS_ROP2]) {
1233         FIXME("Render state WINED3DRS_ROP2 not implemented yet\n");
1234     }
1235 }
1236
1237 static void state_planemask(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1238     if(stateblock->renderState[WINED3DRS_PLANEMASK]) {
1239         FIXME("Render state WINED3DRS_PLANEMASK not implemented yet\n");
1240     }
1241 }
1242
1243 static void state_subpixel(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1244     if(stateblock->renderState[WINED3DRS_SUBPIXEL]) {
1245         FIXME("Render state WINED3DRS_SUBPIXEL not implemented yet\n");
1246     }
1247 }
1248
1249 static void state_subpixelx(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1250     if(stateblock->renderState[WINED3DRS_SUBPIXELX]) {
1251         FIXME("Render state WINED3DRS_SUBPIXELX not implemented yet\n");
1252     }
1253 }
1254
1255 static void state_stippleenable(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1256     if(stateblock->renderState[WINED3DRS_STIPPLEENABLE]) {
1257         FIXME("Render state WINED3DRS_STIPPLEENABLE not implemented yet\n");
1258     }
1259 }
1260
1261 static void state_bordercolor(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1262     if(stateblock->renderState[WINED3DRS_BORDERCOLOR]) {
1263         FIXME("Render state WINED3DRS_BORDERCOLOR not implemented yet\n");
1264     }
1265 }
1266
1267 static void state_mipmaplodbias(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1268     if(stateblock->renderState[WINED3DRS_MIPMAPLODBIAS]) {
1269         FIXME("Render state WINED3DRS_MIPMAPLODBIAS not implemented yet\n");
1270     }
1271 }
1272
1273 static void state_anisotropy(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1274     if(stateblock->renderState[WINED3DRS_ANISOTROPY]) {
1275         FIXME("Render state WINED3DRS_ANISOTROPY not implemented yet\n");
1276     }
1277 }
1278
1279 static void state_flushbatch(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1280     if(stateblock->renderState[WINED3DRS_FLUSHBATCH]) {
1281         FIXME("Render state WINED3DRS_FLUSHBATCH not implemented yet\n");
1282     }
1283 }
1284
1285 static void state_translucentsi(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1286     if(stateblock->renderState[WINED3DRS_TRANSLUCENTSORTINDEPENDENT]) {
1287         FIXME("Render state WINED3DRS_TRANSLUCENTSORTINDEPENDENT not implemented yet\n");
1288     }
1289 }
1290
1291 static void state_extents(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1292     if(stateblock->renderState[WINED3DRS_EXTENTS]) {
1293         FIXME("Render state WINED3DRS_EXTENTS not implemented yet\n");
1294     }
1295 }
1296
1297 static void state_ckeyblend(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1298     if(stateblock->renderState[WINED3DRS_COLORKEYBLENDENABLE]) {
1299         FIXME("Render state WINED3DRS_COLORKEYBLENDENABLE not implemented yet\n");
1300     }
1301 }
1302
1303 /* Activates the texture dimension according to the bound D3D texture.
1304  * Does not care for the colorop or correct gl texture unit(when using nvrc)
1305  * Requires the caller to activate the correct unit before
1306  */
1307 static void activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock) {
1308     if(stateblock->textures[stage]) {
1309         glDisable(GL_TEXTURE_1D);
1310         checkGLcall("glDisable(GL_TEXTURE_1D)");
1311         switch(stateblock->textureDimensions[stage]) {
1312             case GL_TEXTURE_2D:
1313                 glDisable(GL_TEXTURE_3D);
1314                 checkGLcall("glDisable(GL_TEXTURE_3D)");
1315                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1316                 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1317                 glEnable(GL_TEXTURE_2D);
1318                 checkGLcall("glEnable(GL_TEXTURE_2D)");
1319                 break;
1320             case GL_TEXTURE_3D:
1321                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1322                 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1323                 glDisable(GL_TEXTURE_2D);
1324                 checkGLcall("glDisable(GL_TEXTURE_2D)");
1325                 glEnable(GL_TEXTURE_3D);
1326                 checkGLcall("glEnable(GL_TEXTURE_3D)");
1327                 break;
1328             case GL_TEXTURE_CUBE_MAP_ARB:
1329                 glDisable(GL_TEXTURE_2D);
1330                 checkGLcall("glDisable(GL_TEXTURE_2D)");
1331                 glDisable(GL_TEXTURE_3D);
1332                 checkGLcall("glDisable(GL_TEXTURE_3D)");
1333                 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
1334                 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
1335                 break;
1336         }
1337     } else {
1338         glDisable(GL_TEXTURE_2D);
1339         checkGLcall("glDisable(GL_TEXTURE_2D)");
1340         glDisable(GL_TEXTURE_3D);
1341         checkGLcall("glDisable(GL_TEXTURE_3D)");
1342         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1343         checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1344         glEnable(GL_TEXTURE_1D);
1345         checkGLcall("glEnable(GL_TEXTURE_1D)");
1346         /* Binding textures is done by samplers. A dummy texture will be bound */
1347     }
1348 }
1349
1350 static void tex_colorop(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1351     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1352
1353     TRACE("Setting color op for stage %d\n", stage);
1354
1355     if (stateblock->pixelShader && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE &&
1356         ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
1357         /* Using a pixel shader? Don't care for anything here, the shader applying does it */
1358         return;
1359     }
1360
1361     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1362         /* TODO: register combiners! */
1363         if(stage >= GL_LIMITS(sampler_stages)) {
1364             if(stateblock->textureState[stage][WINED3DTSS_COLOROP] != WINED3DTOP_DISABLE &&
1365               stateblock->textureState[stage][WINED3DTSS_COLOROP] != 0) {
1366                 FIXME("Attempt to enable unsupported stage!\n");
1367             }
1368             return;
1369         }
1370         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stage));
1371         checkGLcall("glActiveTextureARB");
1372     } else if (stage > 0) {
1373         WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1374         return;
1375     }
1376
1377     if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1378         if(stateblock->lowest_disabled_stage > 0) {
1379             glEnable(GL_REGISTER_COMBINERS_NV);
1380             GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, stateblock->lowest_disabled_stage));
1381         } else {
1382             glDisable(GL_REGISTER_COMBINERS_NV);
1383         }
1384     }
1385     if(stage >= stateblock->lowest_disabled_stage) {
1386         TRACE("Stage disabled\n");
1387         /* Disable everything here */
1388         glDisable(GL_TEXTURE_1D);
1389         checkGLcall("glDisable(GL_TEXTURE_1D)");
1390         glDisable(GL_TEXTURE_2D);
1391         checkGLcall("glDisable(GL_TEXTURE_2D)");
1392         glDisable(GL_TEXTURE_3D);
1393         checkGLcall("glDisable(GL_TEXTURE_3D)");
1394         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1395         checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1396         /* All done */
1397         return;
1398     }
1399
1400     activate_dimensions(stage, stateblock);
1401
1402     /* Set the texture combiners */
1403     if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1404         set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
1405                          stateblock->textureState[stage][WINED3DTSS_COLOROP],
1406                          stateblock->textureState[stage][WINED3DTSS_COLORARG1],
1407                          stateblock->textureState[stage][WINED3DTSS_COLORARG2],
1408                          stateblock->textureState[stage][WINED3DTSS_COLORARG0],
1409                          stage);
1410     } else {
1411         set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
1412                     stateblock->textureState[stage][WINED3DTSS_COLOROP],
1413                     stateblock->textureState[stage][WINED3DTSS_COLORARG1],
1414                     stateblock->textureState[stage][WINED3DTSS_COLORARG2],
1415                     stateblock->textureState[stage][WINED3DTSS_COLORARG0]);
1416     }
1417 }
1418
1419 static void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1420     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1421
1422     TRACE("Setting alpha op for stage %d\n", stage);
1423     /* Do not care for enabled / disabled stages, just assign the settigns. colorop disables / enables required stuff */
1424     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1425         /* TODO: register combiners! */
1426         if(stage >= GL_LIMITS(sampler_stages)) {
1427             if(stateblock->textureState[stage][WINED3DTSS_COLOROP] != WINED3DTOP_DISABLE &&
1428               stateblock->textureState[stage][WINED3DTSS_COLOROP] != 0) {
1429                 FIXME("Attempt to enable unsupported stage!\n");
1430             }
1431             return;
1432         }
1433         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stage));
1434         checkGLcall("glActiveTextureARB");
1435     } else if (stage > 0) {
1436         /* We can't do anything here */
1437         WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1438         return;
1439     }
1440
1441     TRACE("Setting alpha op for stage %d\n", stage);
1442     if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1443         set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
1444                          stateblock->textureState[stage][WINED3DTSS_ALPHAOP],
1445                          stateblock->textureState[stage][WINED3DTSS_ALPHAARG1],
1446                          stateblock->textureState[stage][WINED3DTSS_ALPHAARG2],
1447                          stateblock->textureState[stage][WINED3DTSS_ALPHAARG0],
1448                          stage);
1449     } else {
1450         set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage, stateblock->textureState[stage][WINED3DTSS_ALPHAOP],
1451                     stateblock->textureState[stage][WINED3DTSS_ALPHAARG1],
1452                     stateblock->textureState[stage][WINED3DTSS_ALPHAARG2],
1453                     stateblock->textureState[stage][WINED3DTSS_ALPHAARG0]);
1454     }
1455 }
1456
1457 static void tex_coordindex(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1458     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1459
1460     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1461         /* TODO: register combiners! */
1462         if(stage >= GL_LIMITS(sampler_stages)) {
1463             return;
1464         }
1465         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stage));
1466         checkGLcall("glActiveTextureARB");
1467     } else if (stage > 0) {
1468         /* We can't do anything here */
1469         WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1470         return;
1471     }
1472
1473     /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
1474      *
1475      * FIXME: From MSDN: The WINED3DTSS_TCI_* flags are mutually exclusive. If you include
1476      * one flag, you can still specify an index value, which the system uses to
1477      * determine the texture wrapping mode.
1478      * eg. SetTextureStageState( 0, WINED3DTSS_TEXCOORDINDEX, WINED3DTSS_TCI_CAMERASPACEPOSITION | 1 );
1479      * means use the vertex position (camera-space) as the input texture coordinates
1480      * for this texture stage, and the wrap mode set in the WINED3DRS_WRAP1 render
1481      * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up
1482      * to the TEXCOORDINDEX value
1483      */
1484
1485     /*
1486      * Be careful the value of the mask 0xF0000 come from d3d8types.h infos
1487      */
1488     switch (stateblock->textureState[stage][WINED3DTSS_TEXCOORDINDEX] & 0xFFFF0000) {
1489     case WINED3DTSS_TCI_PASSTHRU:
1490         /*Use the specified texture coordinates contained within the vertex format. This value resolves to zero.*/
1491         glDisable(GL_TEXTURE_GEN_S);
1492         glDisable(GL_TEXTURE_GEN_T);
1493         glDisable(GL_TEXTURE_GEN_R);
1494         glDisable(GL_TEXTURE_GEN_Q);
1495         checkGLcall("glDisable(GL_TEXTURE_GEN_S,T,R,Q)");
1496         break;
1497
1498     case WINED3DTSS_TCI_CAMERASPACEPOSITION:
1499         /* CameraSpacePosition means use the vertex position, transformed to camera space,
1500          * as the input texture coordinates for this stage's texture transformation. This
1501          * equates roughly to EYE_LINEAR
1502          */
1503         {
1504             float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
1505             float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
1506             float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
1507             float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
1508             TRACE("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set eye plane\n");
1509
1510             glMatrixMode(GL_MODELVIEW);
1511             glPushMatrix();
1512             glLoadIdentity();
1513             glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
1514             glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
1515             glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
1516             glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
1517             glPopMatrix();
1518
1519             TRACE("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set GL_TEXTURE_GEN_x and GL_x, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR\n");
1520             glEnable(GL_TEXTURE_GEN_S);
1521             checkGLcall("glEnable(GL_TEXTURE_GEN_S);");
1522             glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
1523             checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
1524             glEnable(GL_TEXTURE_GEN_T);
1525             checkGLcall("glEnable(GL_TEXTURE_GEN_T);");
1526             glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
1527             checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
1528             glEnable(GL_TEXTURE_GEN_R);
1529             checkGLcall("glEnable(GL_TEXTURE_GEN_R);");
1530             glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
1531             checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
1532         }
1533         break;
1534
1535     case WINED3DTSS_TCI_CAMERASPACENORMAL:
1536         {
1537             if (GL_SUPPORT(NV_TEXGEN_REFLECTION)) {
1538                 float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
1539                 float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
1540                 float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
1541                 float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
1542                 TRACE("WINED3DTSS_TCI_CAMERASPACENORMAL - Set eye plane\n");
1543
1544                 glMatrixMode(GL_MODELVIEW);
1545                 glPushMatrix();
1546                 glLoadIdentity();
1547                 glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
1548                 glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
1549                 glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
1550                 glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
1551                 glPopMatrix();
1552
1553                 glEnable(GL_TEXTURE_GEN_S);
1554                 checkGLcall("glEnable(GL_TEXTURE_GEN_S);");
1555                 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
1556                 checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
1557                 glEnable(GL_TEXTURE_GEN_T);
1558                 checkGLcall("glEnable(GL_TEXTURE_GEN_T);");
1559                 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
1560                 checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
1561                 glEnable(GL_TEXTURE_GEN_R);
1562                 checkGLcall("glEnable(GL_TEXTURE_GEN_R);");
1563                 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
1564                 checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
1565             }
1566         }
1567         break;
1568
1569     case WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
1570         {
1571             if (GL_SUPPORT(NV_TEXGEN_REFLECTION)) {
1572             float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
1573             float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
1574             float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
1575             float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
1576             TRACE("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set eye plane\n");
1577
1578             glMatrixMode(GL_MODELVIEW);
1579             glPushMatrix();
1580             glLoadIdentity();
1581             glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
1582             glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
1583             glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
1584             glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
1585             glPopMatrix();
1586
1587             glEnable(GL_TEXTURE_GEN_S);
1588             checkGLcall("glEnable(GL_TEXTURE_GEN_S);");
1589             glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
1590             checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
1591             glEnable(GL_TEXTURE_GEN_T);
1592             checkGLcall("glEnable(GL_TEXTURE_GEN_T);");
1593             glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
1594             checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
1595             glEnable(GL_TEXTURE_GEN_R);
1596             checkGLcall("glEnable(GL_TEXTURE_GEN_R);");
1597             glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
1598             checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
1599             }
1600         }
1601         break;
1602
1603     /* Unhandled types: */
1604     default:
1605         /* Todo: */
1606         /* ? disable GL_TEXTURE_GEN_n ? */
1607         glDisable(GL_TEXTURE_GEN_S);
1608         glDisable(GL_TEXTURE_GEN_T);
1609         glDisable(GL_TEXTURE_GEN_R);
1610         glDisable(GL_TEXTURE_GEN_Q);
1611         FIXME("Unhandled WINED3DTSS_TEXCOORDINDEX %x\n", stateblock->textureState[stage][WINED3DTSS_TEXCOORDINDEX]);
1612         break;
1613     }
1614 }
1615
1616 static void tex_bumpenvlscale(DWORD state, IWineD3DStateBlockImpl *stateblock) {
1617     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1618     union {
1619         DWORD d;
1620         float f;
1621     } tmpvalue;
1622
1623     tmpvalue.d = stateblock->textureState[stage][WINED3DTSS_BUMPENVLSCALE];
1624     if(tmpvalue.f != 0.0) {
1625         ERR("WINED3DTSS_BUMPENVLSCALE not supported yet\n");
1626     }
1627 }
1628
1629 const struct StateEntry StateTable[] =
1630 {
1631       /* State name                                         representative,                                     apply function */
1632     { /* 0,  Undefined                              */      0,                                                  state_undefined     },
1633     { /* 1,  WINED3DRS_TEXTUREHANDLE                */      0 /* Handled in ddraw */,                           state_undefined     },
1634     { /* 2,  WINED3DRS_ANTIALIAS                    */      STATE_RENDER(WINED3DRS_ANTIALIAS),                  state_antialias     },
1635     { /* 3,  WINED3DRS_TEXTUREADDRESS               */      0 /* Handled in ddraw */,                           state_undefined     },
1636     { /* 4,  WINED3DRS_TEXTUREPERSPECTIVE           */      STATE_RENDER(WINED3DRS_TEXTUREPERSPECTIVE),         state_perspective   },
1637     { /* 5,  WINED3DRS_WRAPU                        */      STATE_RENDER(WINED3DRS_WRAPU),                      state_wrapu         },
1638     { /* 6,  WINED3DRS_WRAPV                        */      STATE_RENDER(WINED3DRS_WRAPV),                      state_wrapv         },
1639     { /* 7,  WINED3DRS_ZENABLE                      */      STATE_RENDER(WINED3DRS_ZENABLE),                    state_zenable       },
1640     { /* 8,  WINED3DRS_FILLMODE                     */      STATE_RENDER(WINED3DRS_FILLMODE),                   state_fillmode      },
1641     { /* 9,  WINED3DRS_SHADEMODE                    */      STATE_RENDER(WINED3DRS_SHADEMODE),                  state_shademode     },
1642     { /* 10, WINED3DRS_LINEPATTERN                  */      STATE_RENDER(WINED3DRS_LINEPATTERN),                state_linepattern   },
1643     { /* 11, WINED3DRS_MONOENABLE                   */      STATE_RENDER(WINED3DRS_MONOENABLE),                 state_monoenable    },
1644     { /* 12, WINED3DRS_ROP2                         */      STATE_RENDER(WINED3DRS_ROP2),                       state_rop2          },
1645     { /* 13, WINED3DRS_PLANEMASK                    */      STATE_RENDER(WINED3DRS_PLANEMASK),                  state_planemask     },
1646     { /* 14, WINED3DRS_ZWRITEENABLE                 */      STATE_RENDER(WINED3DRS_ZWRITEENABLE),               state_zwritenable   },
1647     { /* 15, WINED3DRS_ALPHATESTENABLE              */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
1648     { /* 16, WINED3DRS_LASTPIXEL                    */      STATE_RENDER(WINED3DRS_LASTPIXEL),                  state_lastpixel     },
1649     { /* 17, WINED3DRS_TEXTUREMAG                   */      0 /* Handled in ddraw */,                           state_undefined     },
1650     { /* 18, WINED3DRS_TEXTUREMIN                   */      0 /* Handled in ddraw */,                           state_undefined     },
1651     { /* 19, WINED3DRS_SRCBLEND                     */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
1652     { /* 20, WINED3DRS_DESTBLEND                    */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
1653     { /* 21, WINED3DRS_TEXTUREMAPBLEND              */      0 /* Handled in ddraw */,                           state_undefined     },
1654     { /* 22, WINED3DRS_CULLMODE                     */      STATE_RENDER(WINED3DRS_CULLMODE),                   state_cullmode      },
1655     { /* 23, WINED3DRS_ZFUNC                        */      STATE_RENDER(WINED3DRS_ZFUNC),                      state_zfunc         },
1656     { /* 24, WINED3DRS_ALPHAREF                     */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
1657     { /* 25, WINED3DRS_ALPHAFUNC                    */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
1658     { /* 26, WINED3DRS_DITHERENABLE                 */      STATE_RENDER(WINED3DRS_DITHERENABLE),               state_ditherenable  },
1659     { /* 27, WINED3DRS_ALPHABLENDENABLE             */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
1660     { /* 28, WINED3DRS_FOGENABLE                    */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
1661     { /* 29, WINED3DRS_SPECULARENABLE               */      STATE_RENDER(WINED3DRS_SPECULARENABLE),             state_specularenable},
1662     { /* 30, WINED3DRS_ZVISIBLE                     */      0 /* Not supported according to the msdn */,        state_nogl          },
1663     { /* 31, WINED3DRS_SUBPIXEL                     */      STATE_RENDER(WINED3DRS_SUBPIXEL),                   state_subpixel      },
1664     { /* 32, WINED3DRS_SUBPIXELX                    */      STATE_RENDER(WINED3DRS_SUBPIXELX),                  state_subpixelx     },
1665     { /* 33, WINED3DRS_STIPPLEDALPHA                */      STATE_RENDER(WINED3DRS_STIPPLEDALPHA),              state_stippledalpha },
1666     { /* 34, WINED3DRS_FOGCOLOR                     */      STATE_RENDER(WINED3DRS_FOGCOLOR),                   state_fogcolor      },
1667     { /* 35, WINED3DRS_FOGTABLEMODE                 */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
1668     { /* 36, WINED3DRS_FOGSTART                     */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
1669     { /* 37, WINED3DRS_FOGEND                       */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
1670     { /* 38, WINED3DRS_FOGDENSITY                   */      STATE_RENDER(WINED3DRS_FOGDENSITY),                 state_fogdensity    },
1671     { /* 39, WINED3DRS_STIPPLEENABLE                */      STATE_RENDER(WINED3DRS_STIPPLEENABLE),              state_stippleenable },
1672     { /* 40, WINED3DRS_EDGEANTIALIAS                */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
1673     { /* 41, WINED3DRS_COLORKEYENABLE               */      STATE_RENDER(WINED3DRS_ALPHATESTENABLE),            state_alpha         },
1674     { /* 42, undefined                              */      0,                                                  state_undefined     },
1675     { /* 43, WINED3DRS_BORDERCOLOR                  */      STATE_RENDER(WINED3DRS_BORDERCOLOR),                state_bordercolor   },
1676     { /* 44, WINED3DRS_TEXTUREADDRESSU              */      0, /* Handled in ddraw */                           state_undefined     },
1677     { /* 45, WINED3DRS_TEXTUREADDRESSV              */      0, /* Handled in ddraw */                           state_undefined     },
1678     { /* 46, WINED3DRS_MIPMAPLODBIAS                */      STATE_RENDER(WINED3DRS_MIPMAPLODBIAS),              state_mipmaplodbias },
1679     { /* 47, WINED3DRS_ZBIAS                        */      STATE_RENDER(WINED3DRS_ZBIAS),                      state_zbias         },
1680     { /* 48, WINED3DRS_RANGEFOGENABLE               */      0,                                                  state_nogl          },
1681     { /* 49, WINED3DRS_ANISOTROPY                   */      STATE_RENDER(WINED3DRS_ANISOTROPY),                 state_anisotropy    },
1682     { /* 50, WINED3DRS_FLUSHBATCH                   */      STATE_RENDER(WINED3DRS_FLUSHBATCH),                 state_flushbatch    },
1683     { /* 51, WINED3DRS_TRANSLUCENTSORTINDEPENDENT   */      STATE_RENDER(WINED3DRS_TRANSLUCENTSORTINDEPENDENT), state_translucentsi },
1684     { /* 52, WINED3DRS_STENCILENABLE                */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1685     { /* 53, WINED3DRS_STENCILFAIL                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1686     { /* 54, WINED3DRS_STENCILZFAIL                 */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1687     { /* 55, WINED3DRS_STENCILPASS                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1688     { /* 56, WINED3DRS_STENCILFUNC                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1689     { /* 57, WINED3DRS_STENCILREF                   */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1690     { /* 58, WINED3DRS_STENCILMASK                  */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1691     { /* 59, WINED3DRS_STENCILWRITEMASK             */      STATE_RENDER(WINED3DRS_STENCILWRITEMASK),           state_stencilwrite  },
1692     { /* 60, WINED3DRS_TEXTUREFACTOR                */      STATE_RENDER(WINED3DRS_TEXTUREFACTOR),              state_texfactor     },
1693     { /* 61, Undefined                              */      0,                                                  state_undefined     },
1694     { /* 62, Undefined                              */      0,                                                  state_undefined     },
1695     { /* 63, Undefined                              */      0,                                                  state_undefined     },
1696     { /* 64, WINED3DRS_STIPPLEPATTERN00             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1697     { /* 65, WINED3DRS_STIPPLEPATTERN01             */      0 /* Obsolete, should he handled by ddraw */,       state_undefined     },
1698     { /* 66, WINED3DRS_STIPPLEPATTERN02             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1699     { /* 67, WINED3DRS_STIPPLEPATTERN03             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1700     { /* 68, WINED3DRS_STIPPLEPATTERN04             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1701     { /* 69, WINED3DRS_STIPPLEPATTERN05             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1702     { /* 70, WINED3DRS_STIPPLEPATTERN06             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1703     { /* 71, WINED3DRS_STIPPLEPATTERN07             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1704     { /* 72, WINED3DRS_STIPPLEPATTERN08             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1705     { /* 73, WINED3DRS_STIPPLEPATTERN09             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1706     { /* 74, WINED3DRS_STIPPLEPATTERN10             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1707     { /* 75, WINED3DRS_STIPPLEPATTERN11             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1708     { /* 76, WINED3DRS_STIPPLEPATTERN12             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1709     { /* 77, WINED3DRS_STIPPLEPATTERN13             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1710     { /* 78, WINED3DRS_STIPPLEPATTERN14             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1711     { /* 79, WINED3DRS_STIPPLEPATTERN15             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1712     { /* 80, WINED3DRS_STIPPLEPATTERN16             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1713     { /* 81, WINED3DRS_STIPPLEPATTERN17             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1714     { /* 82, WINED3DRS_STIPPLEPATTERN18             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1715     { /* 83, WINED3DRS_STIPPLEPATTERN19             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1716     { /* 84, WINED3DRS_STIPPLEPATTERN20             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1717     { /* 85, WINED3DRS_STIPPLEPATTERN21             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1718     { /* 86, WINED3DRS_STIPPLEPATTERN22             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1719     { /* 87, WINED3DRS_STIPPLEPATTERN23             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1720     { /* 88, WINED3DRS_STIPPLEPATTERN24             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1721     { /* 89, WINED3DRS_STIPPLEPATTERN25             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1722     { /* 90, WINED3DRS_STIPPLEPATTERN26             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1723     { /* 91, WINED3DRS_STIPPLEPATTERN27             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1724     { /* 92, WINED3DRS_STIPPLEPATTERN28             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1725     { /* 93, WINED3DRS_STIPPLEPATTERN29             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1726     { /* 94, WINED3DRS_STIPPLEPATTERN30             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1727     { /* 95, WINED3DRS_STIPPLEPATTERN31             */      0 /* Obsolete, should be handled by ddraw */,       state_undefined     },
1728     { /* 96, Undefined                              */      0,                                                  state_undefined     },
1729     { /* 97, Undefined                              */      0,                                                  state_undefined     },
1730     { /* 98, Undefined                              */      0,                                                  state_undefined     },
1731     { /* 99, Undefined                              */      0,                                                  state_undefined     },
1732     { /*100, Undefined                              */      0,                                                  state_undefined     },
1733     { /*101, Undefined                              */      0,                                                  state_undefined     },
1734     { /*102, Undefined                              */      0,                                                  state_undefined     },
1735     { /*103, Undefined                              */      0,                                                  state_undefined     },
1736     { /*104, Undefined                              */      0,                                                  state_undefined     },
1737     { /*105, Undefined                              */      0,                                                  state_undefined     },
1738     { /*106, Undefined                              */      0,                                                  state_undefined     },
1739     { /*107, Undefined                              */      0,                                                  state_undefined     },
1740     { /*108, Undefined                              */      0,                                                  state_undefined     },
1741     { /*109, Undefined                              */      0,                                                  state_undefined     },
1742     { /*110, Undefined                              */      0,                                                  state_undefined     },
1743     { /*111, Undefined                              */      0,                                                  state_undefined     },
1744     { /*112, Undefined                              */      0,                                                  state_undefined     },
1745     { /*113, Undefined                              */      0,                                                  state_undefined     },
1746     { /*114, Undefined                              */      0,                                                  state_undefined     },
1747     { /*115, Undefined                              */      0,                                                  state_undefined     },
1748     { /*116, Undefined                              */      0,                                                  state_undefined     },
1749     { /*117, Undefined                              */      0,                                                  state_undefined     },
1750     { /*118, Undefined                              */      0,                                                  state_undefined     },
1751     { /*119, Undefined                              */      0,                                                  state_undefined     },
1752     { /*120, Undefined                              */      0,                                                  state_undefined     },
1753     { /*121, Undefined                              */      0,                                                  state_undefined     },
1754     { /*122, Undefined                              */      0,                                                  state_undefined     },
1755     { /*123, Undefined                              */      0,                                                  state_undefined     },
1756     { /*124, Undefined                              */      0,                                                  state_undefined     },
1757     { /*125, Undefined                              */      0,                                                  state_undefined     },
1758     { /*126, Undefined                              */      0,                                                  state_undefined     },
1759     { /*127, Undefined                              */      0,                                                  state_undefined     },
1760     /* Big hole ends */
1761     { /*128, WINED3DRS_WRAP0                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1762     { /*129, WINED3DRS_WRAP1                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1763     { /*130, WINED3DRS_WRAP2                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1764     { /*131, WINED3DRS_WRAP3                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1765     { /*132, WINED3DRS_WRAP4                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1766     { /*133, WINED3DRS_WRAP5                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1767     { /*134, WINED3DRS_WRAP6                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1768     { /*135, WINED3DRS_WRAP7                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1769     { /*136, WINED3DRS_CLIPPING                     */      STATE_RENDER(WINED3DRS_CLIPPING),                   state_clipping      },
1770     { /*137, WINED3DRS_LIGHTING                     */      STATE_RENDER(WINED3DRS_LIGHTING) /* Vertex decl! */,state_lighting      },
1771     { /*138, WINED3DRS_EXTENTS                      */      STATE_RENDER(WINED3DRS_EXTENTS),                    state_extents       },
1772     { /*139, WINED3DRS_AMBIENT                      */      STATE_RENDER(WINED3DRS_AMBIENT),                    state_ambient       },
1773     { /*140, WINED3DRS_FOGVERTEXMODE                */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
1774     { /*141, WINED3DRS_COLORVERTEX                  */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
1775     { /*142, WINED3DRS_LOCALVIEWER                  */      STATE_RENDER(WINED3DRS_LOCALVIEWER),                state_localviewer   },
1776     { /*143, WINED3DRS_NORMALIZENORMALS             */      STATE_RENDER(WINED3DRS_NORMALIZENORMALS),           state_normalize     },
1777     { /*144, WINED3DRS_COLORKEYBLENDENABLE          */      STATE_RENDER(WINED3DRS_COLORKEYBLENDENABLE),        state_ckeyblend     },
1778     { /*145, WINED3DRS_DIFFUSEMATERIALSOURCE        */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
1779     { /*146, WINED3DRS_SPECULARMATERIALSOURCE       */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
1780     { /*147, WINED3DRS_AMBIENTMATERIALSOURCE        */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
1781     { /*148, WINED3DRS_EMISSIVEMATERIALSOURCE       */      STATE_RENDER(WINED3DRS_COLORVERTEX),                state_colormat      },
1782     { /*149, Undefined                              */      0,                                                  state_undefined     },
1783     { /*150, Undefined                              */      0,                                                  state_undefined     },
1784     { /*151, WINED3DRS_VERTEXBLEND                  */      0,                                                  state_nogl          },
1785     { /*152, WINED3DRS_CLIPPLANEENABLE              */      STATE_RENDER(WINED3DRS_CLIPPING),                   state_clipping      },
1786     { /*153, WINED3DRS_SOFTWAREVERTEXPROCESSING     */      0,                                                  state_nogl          },
1787     { /*154, WINED3DRS_POINTSIZE                    */      STATE_RENDER(WINED3DRS_POINTSIZE),                  state_psize         },
1788     { /*155, WINED3DRS_POINTSIZE_MIN                */      STATE_RENDER(WINED3DRS_POINTSIZE_MIN),              state_psizemin      },
1789     { /*156, WINED3DRS_POINTSPRITEENABLE            */      STATE_RENDER(WINED3DRS_POINTSPRITEENABLE),          state_pointsprite   },
1790     { /*157, WINED3DRS_POINTSCALEENABLE             */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
1791     { /*158, WINED3DRS_POINTSCALE_A                 */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
1792     { /*159, WINED3DRS_POINTSCALE_B                 */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
1793     { /*160, WINED3DRS_POINTSCALE_C                 */      STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        },
1794     { /*161, WINED3DRS_MULTISAMPLEANTIALIAS         */      STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS),       state_multisampleaa },
1795     { /*162, WINED3DRS_MULTISAMPLEMASK              */      STATE_RENDER(WINED3DRS_MULTISAMPLEMASK),            state_multisampmask },
1796     { /*163, WINED3DRS_PATCHEDGESTYLE               */      STATE_RENDER(WINED3DRS_PATCHEDGESTYLE),             state_patchedgestyle},
1797     { /*164, WINED3DRS_PATCHSEGMENTS                */      STATE_RENDER(WINED3DRS_PATCHSEGMENTS),              state_patchsegments },
1798     { /*165, WINED3DRS_DEBUGMONITORTOKEN            */      STATE_RENDER(WINED3DRS_DEBUGMONITORTOKEN),          state_nogl          },
1799     { /*166, WINED3DRS_POINTSIZE_MAX                */      STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              state_psizemax      },
1800     { /*167, WINED3DRS_INDEXEDVERTEXBLENDENABLE     */      0,                                                  state_nogl          },
1801     { /*168, WINED3DRS_COLORWRITEENABLE             */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
1802     { /*169, Undefined                              */      0,                                                  state_undefined     },
1803     { /*170, WINED3DRS_TWEENFACTOR                  */      0,                                                  state_nogl          },
1804     { /*171, WINED3DRS_BLENDOP                      */      STATE_RENDER(WINED3DRS_BLENDOP),                    state_blendop       },
1805     { /*172, WINED3DRS_POSITIONDEGREE               */      STATE_RENDER(WINED3DRS_POSITIONDEGREE),             state_positiondegree},
1806     { /*173, WINED3DRS_NORMALDEGREE                 */      STATE_RENDER(WINED3DRS_NORMALDEGREE),               state_normaldegree  },
1807       /*172, WINED3DRS_POSITIONORDER                */      /* Value assigned to 2 state names */
1808       /*173, WINED3DRS_NORMALORDER                  */      /* Value assigned to 2 state names */
1809     { /*174, WINED3DRS_SCISSORTESTENABLE            */      STATE_RENDER(WINED3DRS_SCISSORTESTENABLE),          state_scissor       },
1810     { /*175, WINED3DRS_SLOPESCALEDEPTHBIAS          */      STATE_RENDER(WINED3DRS_DEPTHBIAS),                  state_depthbias     },
1811     { /*176, WINED3DRS_ANTIALIASEDLINEENABLE        */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
1812     { /*177, undefined                              */      0,                                                  state_undefined     },
1813     { /*178, WINED3DRS_MINTESSELLATIONLEVEL         */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
1814     { /*179, WINED3DRS_MAXTESSELLATIONLEVEL         */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
1815     { /*180, WINED3DRS_ADAPTIVETESS_X               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
1816     { /*181, WINED3DRS_ADAPTIVETESS_Y               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
1817     { /*182, WINED3DRS_ADAPTIVETESS_Z               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
1818     { /*183, WINED3DRS_ADAPTIVETESS_W               */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
1819     { /*184, WINED3DRS_ENABLEADAPTIVETESSELLATION   */      STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation  },
1820     { /*185, WINED3DRS_TWOSIDEDSTENCILMODE          */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1821     { /*186, WINED3DRS_CCW_STENCILFAIL              */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1822     { /*187, WINED3DRS_CCW_STENCILZFAIL             */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1823     { /*188, WINED3DRS_CCW_STENCILPASS              */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1824     { /*189, WINED3DRS_CCW_STENCILFUNC              */      STATE_RENDER(WINED3DRS_STENCILENABLE),              state_stencil       },
1825     { /*190, WINED3DRS_COLORWRITEENABLE1            */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
1826     { /*191, WINED3DRS_COLORWRITEENABLE2            */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
1827     { /*192, WINED3DRS_COLORWRITEENABLE3            */      STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    },
1828     { /*193, WINED3DRS_BLENDFACTOR                  */      STATE_RENDER(WINED3DRS_ALPHABLENDENABLE),           state_blend         },
1829     { /*194, WINED3DRS_SRGBWRITEENABLE              */      STATE_RENDER(WINED3DRS_SRGBWRITEENABLE),            state_srgbwrite     },
1830     { /*195, WINED3DRS_DEPTHBIAS                    */      STATE_RENDER(WINED3DRS_DEPTHBIAS),                  state_depthbias     },
1831     { /*196, undefined                              */      0,                                                  state_undefined     },
1832     { /*197, undefined                              */      0,                                                  state_undefined     },
1833     { /*198, WINED3DRS_WRAP8                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1834     { /*199, WINED3DRS_WRAP9                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1835     { /*200, WINED3DRS_WRAP10                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1836     { /*201, WINED3DRS_WRAP11                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1837     { /*202, WINED3DRS_WRAP12                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1838     { /*203, WINED3DRS_WRAP13                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1839     { /*204, WINED3DRS_WRAP14                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1840     { /*205, WINED3DRS_WRAP15                       */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
1841     { /*206, WINED3DRS_SEPARATEALPHABLENDENABLE     */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
1842     { /*207, WINED3DRS_SRCBLENDALPHA                */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
1843     { /*208, WINED3DRS_DESTBLENDALPHA               */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
1844     { /*209, WINED3DRS_BLENDOPALPHA                 */      STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE),   state_seperateblend },
1845     /* Texture stage states */
1846     { /*0, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1847     { /*0, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1848     { /*0, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1849     { /*0, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1850     { /*0, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1851     { /*0, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1852     { /*0, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1853     { /*0, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1854     { /*0, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1855     { /*0, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1856     { /*0, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(0, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
1857     { /*0, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1858     { /*0, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1859     { /*0, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1860     { /*0, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1861     { /*0, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1862     { /*0, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1863     { /*0, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1864     { /*0, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1865     { /*0, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1866     { /*0, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1867     { /*0, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
1868     { /*0, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
1869     { /*0, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(0, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
1870     { /*0, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1871     { /*0, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         },
1872     { /*0, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1873     { /*0, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG),        state_undefined     },
1874     { /*0, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1875     { /*0, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1876     { /*0, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1877     { /*0, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(0, WINED3DTSS_CONSTANT),         state_undefined     },
1878
1879     { /*1, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1880     { /*1, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1881     { /*1, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1882     { /*1, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1883     { /*1, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1884     { /*1, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1885     { /*1, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1886     { /*1, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1887     { /*1, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1888     { /*1, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1889     { /*1, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(1, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
1890     { /*1, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1891     { /*1, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1892     { /*1, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1893     { /*1, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1894     { /*1, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1895     { /*1, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1896     { /*1, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1897     { /*1, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1898     { /*1, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1899     { /*1, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1900     { /*1, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
1901     { /*1, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
1902     { /*1, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(1, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
1903     { /*1, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1904     { /*1, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         },
1905     { /*1, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1906     { /*1, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG),        state_undefined     },
1907     { /*1, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1908     { /*1, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1909     { /*1, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1910     { /*1, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(1, WINED3DTSS_CONSTANT),         state_undefined     },
1911
1912     { /*2, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1913     { /*2, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1914     { /*2, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1915     { /*2, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1916     { /*2, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1917     { /*2, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1918     { /*2, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1919     { /*2, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1920     { /*2, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1921     { /*2, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1922     { /*2, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(2, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
1923     { /*2, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1924     { /*2, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1925     { /*2, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1926     { /*2, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1927     { /*2, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1928     { /*2, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1929     { /*2, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1930     { /*2, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1931     { /*2, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1932     { /*2, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1933     { /*2, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
1934     { /*2, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
1935     { /*2, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(2, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
1936     { /*2, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1937     { /*2, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         },
1938     { /*2, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1939     { /*2, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG),        state_undefined     },
1940     { /*2, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1941     { /*2, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1942     { /*2, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1943     { /*2, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(2, WINED3DTSS_CONSTANT),         state_undefined     },
1944
1945     { /*3, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1946     { /*3, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1947     { /*3, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1948     { /*3, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1949     { /*3, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1950     { /*3, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1951     { /*3, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1952     { /*3, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1953     { /*3, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1954     { /*3, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1955     { /*3, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(3, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
1956     { /*3, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1957     { /*3, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1958     { /*3, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1959     { /*3, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1960     { /*3, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1961     { /*3, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1962     { /*3, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1963     { /*3, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1964     { /*3, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1965     { /*3, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1966     { /*3, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
1967     { /*3, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
1968     { /*3, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(3, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
1969     { /*3, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1970     { /*3, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         },
1971     { /*3, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1972     { /*3, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG),        state_undefined     },
1973     { /*3, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1974     { /*3, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1975     { /*3, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1976     { /*3, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(3, WINED3DTSS_CONSTANT),         state_undefined     },
1977
1978     { /*4, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
1979     { /*4, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
1980     { /*4, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
1981     { /*4, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1982     { /*4, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1983     { /*4, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
1984     { /*4, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          state_undefined     },
1985     { /*4, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          state_undefined     },
1986     { /*4, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          state_undefined     },
1987     { /*4, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          state_undefined     },
1988     { /*4, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(4, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
1989     { /*4, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1990     { /*4, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1991     { /*4, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1992     { /*4, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1993     { /*4, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1994     { /*4, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1995     { /*4, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1996     { /*4, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1997     { /*4, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1998     { /*4, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
1999     { /*4, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
2000     { /*4, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
2001     { /*4, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(4, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
2002     { /*4, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2003     { /*4, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         },
2004     { /*4, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2005     { /*4, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG),        state_undefined     },
2006     { /*4, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2007     { /*4, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2008     { /*4, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2009     { /*4, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(4, WINED3DTSS_CONSTANT),         state_undefined     },
2010
2011     { /*5, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2012     { /*5, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2013     { /*5, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2014     { /*5, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2015     { /*5, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2016     { /*5, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2017     { /*5, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2018     { /*5, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2019     { /*5, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2020     { /*5, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2021     { /*5, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(5, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
2022     { /*5, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2023     { /*5, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2024     { /*5, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2025     { /*5, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2026     { /*5, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2027     { /*5, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2028     { /*5, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2029     { /*5, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2030     { /*5, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2031     { /*5, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2032     { /*5, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
2033     { /*5, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
2034     { /*5, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(5, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
2035     { /*5, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2036     { /*5, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         },
2037     { /*5, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2038     { /*5, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG),        state_undefined     },
2039     { /*5, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2040     { /*5, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2041     { /*5, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2042     { /*5, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(5, WINED3DTSS_CONSTANT),         state_undefined     },
2043
2044     { /*6, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2045     { /*6, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2046     { /*6, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2047     { /*6, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2048     { /*6, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2049     { /*6, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2050     { /*6, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2051     { /*6, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2052     { /*6, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2053     { /*6, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2054     { /*6, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(6, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
2055     { /*6, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2056     { /*6, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2057     { /*6, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2058     { /*6, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2059     { /*6, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2060     { /*6, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2061     { /*6, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2062     { /*6, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2063     { /*6, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2064     { /*6, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2065     { /*6, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
2066     { /*6, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
2067     { /*6, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(6, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
2068     { /*6, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2069     { /*6, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         },
2070     { /*6, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2071     { /*6, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG),        state_undefined     },
2072     { /*6, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2073     { /*6, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2074     { /*6, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2075     { /*6, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(6, WINED3DTSS_CONSTANT),         state_undefined     },
2076
2077     { /*7, 01, WINED3DTSS_COLOROP                   */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2078     { /*7, 02, WINED3DTSS_COLORARG1                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2079     { /*7, 03, WINED3DTSS_COLORARG2                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2080     { /*7, 04, WINED3DTSS_ALPHAOP                   */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2081     { /*7, 05, WINED3DTSS_ALPHAARG1                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2082     { /*7, 06, WINED3DTSS_ALPHAARG2                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2083     { /*7, 07, WINED3DTSS_BUMPENVMAT00              */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2084     { /*7, 08, WINED3DTSS_BUMPENVMAT01              */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2085     { /*7, 09, WINED3DTSS_BUMPENVMAT10              */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2086     { /*7, 10, WINED3DTSS_BUMPENVMAT11              */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2087     { /*7, 11, WINED3DTSS_TEXCOORDINDEX             */      STATE_TEXTURESTAGE(7, WINED3DTSS_TEXCOORDINDEX),    tex_coordindex      },
2088     { /*7, 12, WINED3DTSS_ADDRESS                   */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2089     { /*7, 13, WINED3DTSS_ADDRESSU                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2090     { /*7, 14, WINED3DTSS_ADDRESSV                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2091     { /*7, 15, WINED3DTSS_BORDERCOLOR               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2092     { /*7, 16, WINED3DTSS_MAGFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2093     { /*7, 17, WINED3DTSS_MINFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2094     { /*7, 18, WINED3DTSS_MIPFILTER                 */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2095     { /*7, 19, WINED3DTSS_MIPMAPLODBIAS             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2096     { /*7, 20, WINED3DTSS_MAXMIPLEVEL               */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2097     { /*7, 21, WINED3DTSS_MAXANISOTROPY             */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2098     { /*7, 22, WINED3DTSS_BUMPENVLSCALE             */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE),    tex_bumpenvlscale   },
2099     { /*7, 23, WINED3DTSS_BUMPENVLOFFSET            */      STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLOFFSET),   state_undefined     },
2100     { /*7, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS     */      STATE_TEXTURESTAGE(7, WINED3DTSS_TEXTURETRANSFORMFLAGS), state_undefined},
2101     { /*7, 25, WINED3DTSS_ADDRESSW                  */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2102     { /*7, 26, WINED3DTSS_COLORARG0                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         },
2103     { /*7, 27, WINED3DTSS_ALPHAARG0                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         },
2104     { /*7, 28, WINED3DTSS_RESULTARG                 */      STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG),        state_undefined     },
2105     { /*7, 29, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2106     { /*7, 30, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2107     { /*7, 31, undefined                            */      0 /* -> sampler state in ddraw / d3d8 */,           state_undefined     },
2108     { /*7, 32, WINED3DTSS_CONSTANT                  */      STATE_TEXTURESTAGE(7, WINED3DTSS_CONSTANT),         state_undefined     },
2109 };