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