msi: Read the disk prompt source list property from the user-unmanaged context.
[wine.git] / dlls / wined3d / state.c
blob8f5060f035e7d0ed0bec71e51390ed0ed01a0e2e
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_blendop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
41 static void state_nogl(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
42 /* Used for states which are not mapped to a gl state as-is, but used somehow different,
43 * e.g as a parameter for drawing, or which are unimplemented in windows d3d
45 if(STATE_IS_RENDER(state)) {
46 WINED3DRENDERSTATETYPE RenderState = state - STATE_RENDER(0);
47 TRACE("(%s,%d) no direct mapping to gl\n", debug_d3drenderstate(RenderState), stateblock->renderState[RenderState]);
48 } else {
49 /* Shouldn't have an unknown type here */
50 FIXME("%d no direct mapping to gl of state with unknown type\n", state);
54 static void state_undefined(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
55 /* Print a WARN, this allows the stateblock code to loop over all states to generate a display
56 * list without causing confusing terminal output. Deliberately no special debug name here
57 * because its undefined.
59 WARN("undefined state %d\n", state);
62 static void state_fillmode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
63 WINED3DFILLMODE Value = stateblock->renderState[WINED3DRS_FILLMODE];
65 switch(Value) {
66 case WINED3DFILL_POINT:
67 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
68 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
69 break;
70 case WINED3DFILL_WIREFRAME:
71 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
72 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
73 break;
74 case WINED3DFILL_SOLID:
75 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
76 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
77 break;
78 default:
79 FIXME("Unrecognized WINED3DRS_FILLMODE value %d\n", Value);
83 static void state_lighting(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
84 BOOL transformed;
86 /* Lighting is not enabled if transformed vertices are drawn
87 * but lighting does not affect the stream sources, so it is not grouped for performance reasons.
88 * This state reads the decoded vertex declaration, so if it is dirty don't do anything. The
89 * vertex declaration applying function calls this function for updating
92 if(isStateDirty(context, STATE_VDECL)) {
93 return;
96 transformed = ((stateblock->wineD3DDevice->strided_streams.u.s.position.lpData != NULL ||
97 stateblock->wineD3DDevice->strided_streams.u.s.position.VBO != 0) &&
98 stateblock->wineD3DDevice->strided_streams.u.s.position_transformed) ? TRUE : FALSE;
100 if (stateblock->renderState[WINED3DRS_LIGHTING] && !transformed) {
101 glEnable(GL_LIGHTING);
102 checkGLcall("glEnable GL_LIGHTING");
103 } else {
104 glDisable(GL_LIGHTING);
105 checkGLcall("glDisable GL_LIGHTING");
109 static void state_zenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
110 /* No z test without depth stencil buffers */
111 if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) {
112 TRACE("No Z buffer - disabling depth test\n");
113 glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */
114 checkGLcall("glDisable GL_DEPTH_TEST");
115 return;
118 switch ((WINED3DZBUFFERTYPE) stateblock->renderState[WINED3DRS_ZENABLE]) {
119 case WINED3DZB_FALSE:
120 glDisable(GL_DEPTH_TEST);
121 checkGLcall("glDisable GL_DEPTH_TEST");
122 break;
123 case WINED3DZB_TRUE:
124 glEnable(GL_DEPTH_TEST);
125 checkGLcall("glEnable GL_DEPTH_TEST");
126 break;
127 case WINED3DZB_USEW:
128 glEnable(GL_DEPTH_TEST);
129 checkGLcall("glEnable GL_DEPTH_TEST");
130 FIXME("W buffer is not well handled\n");
131 break;
132 default:
133 FIXME("Unrecognized D3DZBUFFERTYPE value %d\n", stateblock->renderState[WINED3DRS_ZENABLE]);
137 static void state_cullmode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
138 /* glFrontFace() is set in context.c at context init and on an offscreen / onscreen rendering
139 * switch
141 switch ((WINED3DCULL) stateblock->renderState[WINED3DRS_CULLMODE]) {
142 case WINED3DCULL_NONE:
143 glDisable(GL_CULL_FACE);
144 checkGLcall("glDisable GL_CULL_FACE");
145 break;
146 case WINED3DCULL_CW:
147 glEnable(GL_CULL_FACE);
148 checkGLcall("glEnable GL_CULL_FACE");
149 glCullFace(GL_FRONT);
150 checkGLcall("glCullFace(GL_FRONT)");
151 break;
152 case WINED3DCULL_CCW:
153 glEnable(GL_CULL_FACE);
154 checkGLcall("glEnable GL_CULL_FACE");
155 glCullFace(GL_BACK);
156 checkGLcall("glCullFace(GL_BACK)");
157 break;
158 default:
159 FIXME("Unrecognized/Unhandled WINED3DCULL value %d\n", stateblock->renderState[WINED3DRS_CULLMODE]);
163 static void state_shademode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
164 switch ((WINED3DSHADEMODE) stateblock->renderState[WINED3DRS_SHADEMODE]) {
165 case WINED3DSHADE_FLAT:
166 glShadeModel(GL_FLAT);
167 checkGLcall("glShadeModel(GL_FLAT)");
168 break;
169 case WINED3DSHADE_GOURAUD:
170 glShadeModel(GL_SMOOTH);
171 checkGLcall("glShadeModel(GL_SMOOTH)");
172 break;
173 case WINED3DSHADE_PHONG:
174 FIXME("WINED3DSHADE_PHONG isn't supported\n");
175 break;
176 default:
177 FIXME("Unrecognized/Unhandled WINED3DSHADEMODE value %d\n", stateblock->renderState[WINED3DRS_SHADEMODE]);
181 static void state_ditherenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
182 if (stateblock->renderState[WINED3DRS_DITHERENABLE]) {
183 glEnable(GL_DITHER);
184 checkGLcall("glEnable GL_DITHER");
185 } else {
186 glDisable(GL_DITHER);
187 checkGLcall("glDisable GL_DITHER");
191 static void state_zwritenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
192 /* TODO: Test if in d3d z writing is enabled even if ZENABLE is off. If yes,
193 * this has to be merged with ZENABLE and ZFUNC
195 if (stateblock->renderState[WINED3DRS_ZWRITEENABLE]) {
196 glDepthMask(1);
197 checkGLcall("glDepthMask(1)");
198 } else {
199 glDepthMask(0);
200 checkGLcall("glDepthMask(0)");
204 static void state_zfunc(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
205 int glParm = CompareFunc(stateblock->renderState[WINED3DRS_ZFUNC]);
207 if(glParm) {
208 if(glParm == GL_EQUAL || glParm == GL_NOTEQUAL) {
209 static BOOL once = FALSE;
210 /* There are a few issues with this: First, our inability to
211 * select a proper Z depth, most of the time we're stuck with
212 * D24S8, even if the app selects D32 or D16. There seem to be
213 * some other precision problems which have to be debugged to
214 * make NOTEQUAL and EQUAL work properly
216 if(!once) {
217 once = TRUE;
218 FIXME("D3DCMP_NOTEQUAL and D3DCMP_EQUAL do not work correctly yet\n");
222 glDepthFunc(glParm);
223 checkGLcall("glDepthFunc");
227 static void state_ambient(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
228 float col[4];
229 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_AMBIENT], col);
231 TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]);
232 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
233 checkGLcall("glLightModel for MODEL_AMBIENT");
236 static void state_blend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
237 int srcBlend = GL_ZERO;
238 int dstBlend = GL_ZERO;
239 const StaticPixelFormatDesc *rtFormat;
240 IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *) stateblock->wineD3DDevice->render_targets[0];
242 /* GL_LINE_SMOOTH needs GL_BLEND to work, according to the red book, and special blending params */
243 if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE] ||
244 stateblock->renderState[WINED3DRS_EDGEANTIALIAS] ||
245 stateblock->renderState[WINED3DRS_ANTIALIASEDLINEENABLE]) {
246 glEnable(GL_BLEND);
247 checkGLcall("glEnable GL_BLEND");
248 } else {
249 glDisable(GL_BLEND);
250 checkGLcall("glDisable GL_BLEND");
251 /* Nothing more to do - get out */
252 return;
255 switch (stateblock->renderState[WINED3DRS_DESTBLEND]) {
256 case WINED3DBLEND_ZERO : dstBlend = GL_ZERO; break;
257 case WINED3DBLEND_ONE : dstBlend = GL_ONE; break;
258 case WINED3DBLEND_SRCCOLOR : dstBlend = GL_SRC_COLOR; break;
259 case WINED3DBLEND_INVSRCCOLOR : dstBlend = GL_ONE_MINUS_SRC_COLOR; break;
260 case WINED3DBLEND_SRCALPHA : dstBlend = GL_SRC_ALPHA; break;
261 case WINED3DBLEND_INVSRCALPHA : dstBlend = GL_ONE_MINUS_SRC_ALPHA; break;
262 case WINED3DBLEND_DESTCOLOR : dstBlend = GL_DST_COLOR; break;
263 case WINED3DBLEND_INVDESTCOLOR : dstBlend = GL_ONE_MINUS_DST_COLOR; break;
265 /* To compensate the lack of format switching with backbuffer offscreen rendering,
266 * and with onscreen rendering, we modify the alpha test parameters for (INV)DESTALPHA
267 * if the render target doesn't support alpha blending. A nonexistent alpha channel
268 * returns 1.0, so D3DBLEND_DESTALPHA is GL_ONE, and D3DBLEND_INVDESTALPHA is GL_ZERO
270 case WINED3DBLEND_DESTALPHA :
271 rtFormat = getFormatDescEntry(target->resource.format, NULL, NULL);
272 dstBlend = rtFormat->alphaMask ? GL_DST_ALPHA : GL_ONE;
273 break;
274 case WINED3DBLEND_INVDESTALPHA :
275 rtFormat = getFormatDescEntry(target->resource.format, NULL, NULL);
276 dstBlend = rtFormat->alphaMask ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO;
277 break;
279 case WINED3DBLEND_SRCALPHASAT :
280 dstBlend = GL_SRC_ALPHA_SATURATE;
281 WARN("Application uses SRCALPHASAT as dest blend factor, expect problems\n");
282 break;
284 /* WINED3DBLEND_BOTHSRCALPHA and WINED3DBLEND_BOTHINVSRCALPHA are legacy source blending
285 * values which are still valid up to d3d9. They should not occur as dest blend values
287 case WINED3DBLEND_BOTHSRCALPHA : dstBlend = GL_SRC_ALPHA;
288 srcBlend = GL_SRC_ALPHA;
289 FIXME("WINED3DRS_DESTBLEND = WINED3DBLEND_BOTHSRCALPHA, what to do?\n");
290 break;
292 case WINED3DBLEND_BOTHINVSRCALPHA : dstBlend = GL_ONE_MINUS_SRC_ALPHA;
293 srcBlend = GL_ONE_MINUS_SRC_ALPHA;
294 FIXME("WINED3DRS_DESTBLEND = WINED3DBLEND_BOTHINVSRCALPHA, what to do?\n");
295 break;
297 case WINED3DBLEND_BLENDFACTOR : dstBlend = GL_CONSTANT_COLOR; break;
298 case WINED3DBLEND_INVBLENDFACTOR : dstBlend = GL_ONE_MINUS_CONSTANT_COLOR; break;
299 default:
300 FIXME("Unrecognized dst blend value %d\n", stateblock->renderState[WINED3DRS_DESTBLEND]);
303 switch (stateblock->renderState[WINED3DRS_SRCBLEND]) {
304 case WINED3DBLEND_ZERO : srcBlend = GL_ZERO; break;
305 case WINED3DBLEND_ONE : srcBlend = GL_ONE; break;
306 case WINED3DBLEND_SRCCOLOR : srcBlend = GL_SRC_COLOR; break;
307 case WINED3DBLEND_INVSRCCOLOR : srcBlend = GL_ONE_MINUS_SRC_COLOR; break;
308 case WINED3DBLEND_SRCALPHA : srcBlend = GL_SRC_ALPHA; break;
309 case WINED3DBLEND_INVSRCALPHA : srcBlend = GL_ONE_MINUS_SRC_ALPHA; break;
310 case WINED3DBLEND_DESTCOLOR : srcBlend = GL_DST_COLOR; break;
311 case WINED3DBLEND_INVDESTCOLOR : srcBlend = GL_ONE_MINUS_DST_COLOR; break;
312 case WINED3DBLEND_SRCALPHASAT : srcBlend = GL_SRC_ALPHA_SATURATE; break;
314 case WINED3DBLEND_DESTALPHA :
315 rtFormat = getFormatDescEntry(target->resource.format, NULL, NULL);
316 srcBlend = rtFormat->alphaMask ? GL_DST_ALPHA : GL_ONE;
317 break;
318 case WINED3DBLEND_INVDESTALPHA :
319 rtFormat = getFormatDescEntry(target->resource.format, NULL, NULL);
320 srcBlend = rtFormat->alphaMask ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO;
321 break;
323 case WINED3DBLEND_BOTHSRCALPHA : srcBlend = GL_SRC_ALPHA;
324 dstBlend = GL_ONE_MINUS_SRC_ALPHA;
325 break;
327 case WINED3DBLEND_BOTHINVSRCALPHA : srcBlend = GL_ONE_MINUS_SRC_ALPHA;
328 dstBlend = GL_SRC_ALPHA;
329 break;
331 case WINED3DBLEND_BLENDFACTOR : srcBlend = GL_CONSTANT_COLOR; break;
332 case WINED3DBLEND_INVBLENDFACTOR : srcBlend = GL_ONE_MINUS_CONSTANT_COLOR; break;
333 default:
334 FIXME("Unrecognized src blend value %d\n", stateblock->renderState[WINED3DRS_SRCBLEND]);
337 if(stateblock->renderState[WINED3DRS_EDGEANTIALIAS] ||
338 stateblock->renderState[WINED3DRS_ANTIALIASEDLINEENABLE]) {
339 glEnable(GL_LINE_SMOOTH);
340 checkGLcall("glEnable(GL_LINE_SMOOTH)");
341 if(srcBlend != GL_SRC_ALPHA) {
342 WARN("WINED3DRS_EDGEANTIALIAS enabled, but unexpected src blending param\n");
344 if(dstBlend != GL_ONE_MINUS_SRC_ALPHA && dstBlend != GL_ONE) {
345 WARN("WINED3DRS_EDGEANTIALIAS enabled, but unexpected dst blending param\n");
347 } else {
348 glDisable(GL_LINE_SMOOTH);
349 checkGLcall("glDisable(GL_LINE_SMOOTH)");
352 /* Re-apply BLENDOP(ALPHA) because of a possible SEPARATEALPHABLENDENABLE change */
353 if(!isStateDirty(context, STATE_RENDER(WINED3DRS_BLENDOP))) {
354 state_blendop(STATE_RENDER(WINED3DRS_BLENDOPALPHA), stateblock, context);
357 if(stateblock->renderState[WINED3DRS_SEPARATEALPHABLENDENABLE]) {
358 int srcBlendAlpha = GL_ZERO;
359 int dstBlendAlpha = GL_ZERO;
361 /* Separate alpha blending requires GL_EXT_blend_function_separate, so make sure it is around */
362 if(!GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE)) {
363 WARN("Unsupported in local OpenGL implementation: glBlendFuncSeparateEXT\n");
364 return;
367 switch (stateblock->renderState[WINED3DRS_DESTBLENDALPHA]) {
368 case WINED3DBLEND_ZERO : dstBlendAlpha = GL_ZERO; break;
369 case WINED3DBLEND_ONE : dstBlendAlpha = GL_ONE; break;
370 case WINED3DBLEND_SRCCOLOR : dstBlendAlpha = GL_SRC_COLOR; break;
371 case WINED3DBLEND_INVSRCCOLOR : dstBlendAlpha = GL_ONE_MINUS_SRC_COLOR; break;
372 case WINED3DBLEND_SRCALPHA : dstBlendAlpha = GL_SRC_ALPHA; break;
373 case WINED3DBLEND_INVSRCALPHA : dstBlendAlpha = GL_ONE_MINUS_SRC_ALPHA; break;
374 case WINED3DBLEND_DESTCOLOR : dstBlendAlpha = GL_DST_COLOR; break;
375 case WINED3DBLEND_INVDESTCOLOR : dstBlendAlpha = GL_ONE_MINUS_DST_COLOR; break;
376 case WINED3DBLEND_DESTALPHA : dstBlendAlpha = GL_DST_ALPHA; break;
377 case WINED3DBLEND_INVDESTALPHA : dstBlendAlpha = GL_DST_ALPHA; break;
378 case WINED3DBLEND_SRCALPHASAT :
379 dstBlend = GL_SRC_ALPHA_SATURATE;
380 WARN("Application uses SRCALPHASAT as dest blend factor, expect problems\n");
381 break;
382 /* WINED3DBLEND_BOTHSRCALPHA and WINED3DBLEND_BOTHINVSRCALPHA are legacy source blending
383 * values which are still valid up to d3d9. They should not occur as dest blend values
385 case WINED3DBLEND_BOTHSRCALPHA :
386 dstBlendAlpha = GL_SRC_ALPHA;
387 srcBlendAlpha = GL_SRC_ALPHA;
388 FIXME("WINED3DRS_DESTBLENDALPHA = WINED3DBLEND_BOTHSRCALPHA, what to do?\n");
389 break;
390 case WINED3DBLEND_BOTHINVSRCALPHA :
391 dstBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
392 srcBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
393 FIXME("WINED3DRS_DESTBLENDALPHA = WINED3DBLEND_BOTHINVSRCALPHA, what to do?\n");
394 break;
395 case WINED3DBLEND_BLENDFACTOR : dstBlendAlpha = GL_CONSTANT_COLOR; break;
396 case WINED3DBLEND_INVBLENDFACTOR : dstBlendAlpha = GL_ONE_MINUS_CONSTANT_COLOR; break;
397 default:
398 FIXME("Unrecognized dst blend alpha value %d\n", stateblock->renderState[WINED3DRS_DESTBLENDALPHA]);
401 switch (stateblock->renderState[WINED3DRS_SRCBLENDALPHA]) {
402 case WINED3DBLEND_ZERO : srcBlendAlpha = GL_ZERO; break;
403 case WINED3DBLEND_ONE : srcBlendAlpha = GL_ONE; break;
404 case WINED3DBLEND_SRCCOLOR : srcBlendAlpha = GL_SRC_COLOR; break;
405 case WINED3DBLEND_INVSRCCOLOR : srcBlendAlpha = GL_ONE_MINUS_SRC_COLOR; break;
406 case WINED3DBLEND_SRCALPHA : srcBlendAlpha = GL_SRC_ALPHA; break;
407 case WINED3DBLEND_INVSRCALPHA : srcBlendAlpha = GL_ONE_MINUS_SRC_ALPHA; break;
408 case WINED3DBLEND_DESTCOLOR : srcBlendAlpha = GL_DST_COLOR; break;
409 case WINED3DBLEND_INVDESTCOLOR : srcBlendAlpha = GL_ONE_MINUS_DST_COLOR; break;
410 case WINED3DBLEND_SRCALPHASAT : srcBlendAlpha = GL_SRC_ALPHA_SATURATE; break;
411 case WINED3DBLEND_DESTALPHA : srcBlendAlpha = GL_DST_ALPHA; break;
412 case WINED3DBLEND_INVDESTALPHA : srcBlendAlpha = GL_DST_ALPHA; break;
413 case WINED3DBLEND_BOTHSRCALPHA :
414 srcBlendAlpha = GL_SRC_ALPHA;
415 dstBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
416 break;
417 case WINED3DBLEND_BOTHINVSRCALPHA :
418 srcBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
419 dstBlendAlpha = GL_SRC_ALPHA;
420 break;
421 case WINED3DBLEND_BLENDFACTOR : srcBlendAlpha = GL_CONSTANT_COLOR; break;
422 case WINED3DBLEND_INVBLENDFACTOR : srcBlendAlpha = GL_ONE_MINUS_CONSTANT_COLOR; break;
423 default:
424 FIXME("Unrecognized src blend alpha value %d\n", stateblock->renderState[WINED3DRS_SRCBLENDALPHA]);
427 GL_EXTCALL(glBlendFuncSeparateEXT(srcBlend, dstBlend, srcBlendAlpha, dstBlendAlpha));
428 checkGLcall("glBlendFuncSeparateEXT");
429 } else {
430 TRACE("glBlendFunc src=%x, dst=%x\n", srcBlend, dstBlend);
431 glBlendFunc(srcBlend, dstBlend);
432 checkGLcall("glBlendFunc");
435 /* colorkey fixup for stage 0 alphaop depends on WINED3DRS_ALPHABLENDENABLE state,
436 so it may need updating */
437 if (stateblock->renderState[WINED3DRS_COLORKEYENABLE]) {
438 StateTable[STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP)].apply(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context);
442 static void state_blendfactor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
443 float col[4];
445 if(!GL_SUPPORT(EXT_BLEND_COLOR)) {
446 WARN("Unsupported in local OpenGL implementation: glBlendColorEXT\n");
447 return;
450 TRACE("Setting BlendFactor to %d\n", stateblock->renderState[WINED3DRS_BLENDFACTOR]);
451 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_BLENDFACTOR], col);
452 GL_EXTCALL(glBlendColorEXT (col[0],col[1],col[2],col[3]));
453 checkGLcall("glBlendColor");
456 static void state_alpha(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
457 int glParm = 0;
458 float ref;
459 BOOL enable_ckey = FALSE;
461 IWineD3DSurfaceImpl *surf;
463 /* Find out if the texture on the first stage has a ckey set
464 * The alpha state func reads the texture settings, even though alpha and texture are not grouped
465 * together. This is to avoid making a huge alpha+texture+texture stage+ckey block due to the hardly
466 * used WINED3DRS_COLORKEYENABLE state(which is d3d <= 3 only). The texture function will call alpha
467 * in case it finds some texture+colorkeyenable combination which needs extra care.
469 if(stateblock->textures[0] && (
470 stateblock->textureDimensions[0] == GL_TEXTURE_2D ||
471 stateblock->textureDimensions[0] == GL_TEXTURE_RECTANGLE_ARB)) {
472 surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *)stateblock->textures[0])->surfaces[0];
474 if(surf->CKeyFlags & WINEDDSD_CKSRCBLT) {
475 const StaticPixelFormatDesc *fmt = getFormatDescEntry(surf->resource.format, NULL, NULL);
476 /* The surface conversion does not do color keying conversion for surfaces that have an alpha
477 * channel on their own. Likewise, the alpha test shouldn't be set up for color keying if the
478 * surface has alpha bits
480 if(fmt->alphaMask == 0x00000000) {
481 enable_ckey = TRUE;
486 if(enable_ckey || context->last_was_ckey) {
487 StateTable[STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP)].apply(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context);
489 context->last_was_ckey = enable_ckey;
491 if (stateblock->renderState[WINED3DRS_ALPHATESTENABLE] ||
492 (stateblock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey)) {
493 glEnable(GL_ALPHA_TEST);
494 checkGLcall("glEnable GL_ALPHA_TEST");
495 } else {
496 glDisable(GL_ALPHA_TEST);
497 checkGLcall("glDisable GL_ALPHA_TEST");
498 /* Alpha test is disabled, don't bother setting the params - it will happen on the next
499 * enable call
501 return;
504 if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey) {
505 glParm = GL_NOTEQUAL;
506 ref = 0.0;
507 } else {
508 ref = ((float) stateblock->renderState[WINED3DRS_ALPHAREF]) / 255.0f;
509 glParm = CompareFunc(stateblock->renderState[WINED3DRS_ALPHAFUNC]);
511 if(glParm) {
512 glAlphaFunc(glParm, ref);
513 checkGLcall("glAlphaFunc");
517 static void state_clipping(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
518 DWORD enable = 0xFFFFFFFF;
519 DWORD disable = 0x00000000;
521 if (use_vs(stateblock->wineD3DDevice)) {
522 /* The spec says that opengl clipping planes are disabled when using shaders. Direct3D planes aren't,
523 * so that is an issue. The MacOS ATI driver keeps clipping planes activated with shaders in some
524 * conditions I got sick of tracking down. The shader state handler disables all clip planes because
525 * of that - don't do anything here and keep them disabled
527 if(stateblock->renderState[WINED3DRS_CLIPPLANEENABLE]) {
528 static BOOL warned = FALSE;
529 if(!warned) {
530 FIXME("Clipping not supported with vertex shaders\n");
531 warned = TRUE;
534 return;
537 /* TODO: Keep track of previously enabled clipplanes to avoid unnecessary resetting
538 * of already set values
541 /* If enabling / disabling all
542 * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
544 if (stateblock->renderState[WINED3DRS_CLIPPING]) {
545 enable = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
546 disable = ~stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
547 if(GL_SUPPORT(NV_DEPTH_CLAMP)) {
548 glDisable(GL_DEPTH_CLAMP_NV);
549 checkGLcall("glDisable(GL_DEPTH_CLAMP_NV)");
551 } else {
552 disable = 0xffffffff;
553 enable = 0x00;
554 if(GL_SUPPORT(NV_DEPTH_CLAMP)) {
555 glEnable(GL_DEPTH_CLAMP_NV);
556 checkGLcall("glEnable(GL_DEPTH_CLAMP_NV)");
560 if (enable & WINED3DCLIPPLANE0) { glEnable(GL_CLIP_PLANE0); checkGLcall("glEnable(clip plane 0)"); }
561 if (enable & WINED3DCLIPPLANE1) { glEnable(GL_CLIP_PLANE1); checkGLcall("glEnable(clip plane 1)"); }
562 if (enable & WINED3DCLIPPLANE2) { glEnable(GL_CLIP_PLANE2); checkGLcall("glEnable(clip plane 2)"); }
563 if (enable & WINED3DCLIPPLANE3) { glEnable(GL_CLIP_PLANE3); checkGLcall("glEnable(clip plane 3)"); }
564 if (enable & WINED3DCLIPPLANE4) { glEnable(GL_CLIP_PLANE4); checkGLcall("glEnable(clip plane 4)"); }
565 if (enable & WINED3DCLIPPLANE5) { glEnable(GL_CLIP_PLANE5); checkGLcall("glEnable(clip plane 5)"); }
567 if (disable & WINED3DCLIPPLANE0) { glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)"); }
568 if (disable & WINED3DCLIPPLANE1) { glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)"); }
569 if (disable & WINED3DCLIPPLANE2) { glDisable(GL_CLIP_PLANE2); checkGLcall("glDisable(clip plane 2)"); }
570 if (disable & WINED3DCLIPPLANE3) { glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)"); }
571 if (disable & WINED3DCLIPPLANE4) { glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)"); }
572 if (disable & WINED3DCLIPPLANE5) { glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)"); }
574 /** update clipping status */
575 if (enable) {
576 stateblock->clip_status.ClipUnion = 0;
577 stateblock->clip_status.ClipIntersection = 0xFFFFFFFF;
578 } else {
579 stateblock->clip_status.ClipUnion = 0;
580 stateblock->clip_status.ClipIntersection = 0;
584 static void state_blendop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
585 int blendEquation = GL_FUNC_ADD;
586 int blendEquationAlpha = GL_FUNC_ADD;
588 if(!GL_SUPPORT(EXT_BLEND_MINMAX)) {
589 WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
590 return;
593 /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */
594 if(stateblock->renderState[WINED3DRS_BLENDOPALPHA] && !GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE)) {
595 WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparateEXT\n");
596 return;
599 switch ((WINED3DBLENDOP) stateblock->renderState[WINED3DRS_BLENDOP]) {
600 case WINED3DBLENDOP_ADD : blendEquation = GL_FUNC_ADD; break;
601 case WINED3DBLENDOP_SUBTRACT : blendEquation = GL_FUNC_SUBTRACT; break;
602 case WINED3DBLENDOP_REVSUBTRACT : blendEquation = GL_FUNC_REVERSE_SUBTRACT; break;
603 case WINED3DBLENDOP_MIN : blendEquation = GL_MIN; break;
604 case WINED3DBLENDOP_MAX : blendEquation = GL_MAX; break;
605 default:
606 FIXME("Unrecognized/Unhandled D3DBLENDOP value %d\n", stateblock->renderState[WINED3DRS_BLENDOP]);
609 switch ((WINED3DBLENDOP) stateblock->renderState[WINED3DRS_BLENDOPALPHA]) {
610 case WINED3DBLENDOP_ADD : blendEquationAlpha = GL_FUNC_ADD; break;
611 case WINED3DBLENDOP_SUBTRACT : blendEquationAlpha = GL_FUNC_SUBTRACT; break;
612 case WINED3DBLENDOP_REVSUBTRACT : blendEquationAlpha = GL_FUNC_REVERSE_SUBTRACT; break;
613 case WINED3DBLENDOP_MIN : blendEquationAlpha = GL_MIN; break;
614 case WINED3DBLENDOP_MAX : blendEquationAlpha = GL_MAX; break;
615 default:
616 FIXME("Unrecognized/Unhandled D3DBLENDOP value %d\n", stateblock->renderState[WINED3DRS_BLENDOPALPHA]);
619 if(stateblock->renderState[WINED3DRS_SEPARATEALPHABLENDENABLE]) {
620 TRACE("glBlendEquationSeparateEXT(%x, %x)\n", blendEquation, blendEquationAlpha);
621 GL_EXTCALL(glBlendEquationSeparateEXT(blendEquation, blendEquationAlpha));
622 checkGLcall("glBlendEquationSeparateEXT");
623 } else {
624 TRACE("glBlendEquation(%x)\n", blendEquation);
625 GL_EXTCALL(glBlendEquationEXT(blendEquation));
626 checkGLcall("glBlendEquation");
630 static void
631 state_specularenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
632 /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
633 * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
634 * specular color. This is wrong:
635 * Separate specular color means the specular colour is maintained separately, whereas
636 * single color means it is merged in. However in both cases they are being used to
637 * some extent.
638 * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
639 * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
640 * running 1.4 yet!
643 * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
644 * Instead, we need to setup the FinalCombiner properly.
646 * The default setup for the FinalCombiner is:
648 * <variable> <input> <mapping> <usage>
649 * GL_VARIABLE_A_NV GL_FOG, GL_UNSIGNED_IDENTITY_NV GL_ALPHA
650 * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV GL_UNSIGNED_IDENTITY_NV GL_RGB
651 * GL_VARIABLE_C_NV GL_FOG GL_UNSIGNED_IDENTITY_NV GL_RGB
652 * GL_VARIABLE_D_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
653 * GL_VARIABLE_E_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
654 * GL_VARIABLE_F_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
655 * GL_VARIABLE_G_NV GL_SPARE0_NV GL_UNSIGNED_IDENTITY_NV GL_ALPHA
657 * That's pretty much fine as it is, except for variable B, which needs to take
658 * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
659 * whether WINED3DRS_SPECULARENABLE is enabled or not.
662 TRACE("Setting specular enable state and materials\n");
663 if (stateblock->renderState[WINED3DRS_SPECULARENABLE]) {
664 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*) &stateblock->material.Specular);
665 checkGLcall("glMaterialfv");
667 if(stateblock->material.Power > 128.0) {
668 /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0
669 * and 128.0, although in d3d neither -1 nor 129 produce an error. For values > 128 clamp
670 * them, since 128 results in a hardly visible specular highlight, so it should be safe to
671 * to clamp to 128
673 WARN("Material power > 128\n");
674 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 128.0);
675 } else {
676 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, stateblock->material.Power);
678 checkGLcall("glMaterialf(GL_SHININESS)");
680 if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
681 glEnable(GL_COLOR_SUM_EXT);
682 } else {
683 TRACE("Specular colors cannot be enabled in this version of opengl\n");
685 checkGLcall("glEnable(GL_COLOR_SUM)");
687 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
688 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
689 checkGLcall("glFinalCombinerInputNV()");
691 } else {
692 float black[4] = {0.0f, 0.0f, 0.0f, 0.0f};
694 /* for the case of enabled lighting: */
695 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
696 checkGLcall("glMaterialfv");
698 /* for the case of disabled lighting: */
699 if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
700 glDisable(GL_COLOR_SUM_EXT);
701 } else {
702 TRACE("Specular colors cannot be disabled in this version of opengl\n");
704 checkGLcall("glDisable(GL_COLOR_SUM)");
706 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
707 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
708 checkGLcall("glFinalCombinerInputNV()");
712 TRACE("(%p) : Diffuse (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Diffuse.r, stateblock->material.Diffuse.g,
713 stateblock->material.Diffuse.b, stateblock->material.Diffuse.a);
714 TRACE("(%p) : Ambient (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Ambient.r, stateblock->material.Ambient.g,
715 stateblock->material.Ambient.b, stateblock->material.Ambient.a);
716 TRACE("(%p) : Specular (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Specular.r, stateblock->material.Specular.g,
717 stateblock->material.Specular.b, stateblock->material.Specular.a);
718 TRACE("(%p) : Emissive (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Emissive.r, stateblock->material.Emissive.g,
719 stateblock->material.Emissive.b, stateblock->material.Emissive.a);
721 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*) &stateblock->material.Ambient);
722 checkGLcall("glMaterialfv(GL_AMBIENT)");
723 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float*) &stateblock->material.Diffuse);
724 checkGLcall("glMaterialfv(GL_DIFFUSE)");
725 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float*) &stateblock->material.Emissive);
726 checkGLcall("glMaterialfv(GL_EMISSION)");
729 static void state_texfactor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
730 unsigned int i;
732 /* Note the texture color applies to all textures whereas
733 * GL_TEXTURE_ENV_COLOR applies to active only
735 float col[4];
736 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
738 if (!GL_SUPPORT(NV_REGISTER_COMBINERS)) {
739 /* And now the default texture color as well */
740 for (i = 0; i < GL_LIMITS(texture_stages); i++) {
741 /* Note the WINED3DRS value applies to all textures, but GL has one
742 * per texture, so apply it now ready to be used!
744 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
745 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
746 checkGLcall("glActiveTextureARB");
747 } else if (i>0) {
748 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
751 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
752 checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
754 } else {
755 GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
759 static void
760 renderstate_stencil_twosided(IWineD3DStateBlockImpl *stateblock, GLint face, GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass ) {
761 #if 0 /* Don't use OpenGL 2.0 calls for now */
762 if(GL_EXTCALL(glStencilFuncSeparate) && GL_EXTCALL(glStencilOpSeparate)) {
763 GL_EXTCALL(glStencilFuncSeparate(face, func, ref, mask));
764 checkGLcall("glStencilFuncSeparate(...)");
765 GL_EXTCALL(glStencilOpSeparate(face, stencilFail, depthFail, stencilPass));
766 checkGLcall("glStencilOpSeparate(...)");
768 else
769 #endif
770 if(GL_SUPPORT(EXT_STENCIL_TWO_SIDE)) {
771 glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
772 checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
773 GL_EXTCALL(glActiveStencilFaceEXT(face));
774 checkGLcall("glActiveStencilFaceEXT(...)");
775 glStencilFunc(func, ref, mask);
776 checkGLcall("glStencilFunc(...)");
777 glStencilOp(stencilFail, depthFail, stencilPass);
778 checkGLcall("glStencilOp(...)");
779 } else if(GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
780 GL_EXTCALL(glStencilFuncSeparateATI(face, func, ref, mask));
781 checkGLcall("glStencilFuncSeparateATI(...)");
782 GL_EXTCALL(glStencilOpSeparateATI(face, stencilFail, depthFail, stencilPass));
783 checkGLcall("glStencilOpSeparateATI(...)");
784 } else {
785 ERR("Separate (two sided) stencil not supported on this version of opengl. Caps weren't honored?\n");
789 static void
790 state_stencil(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
791 DWORD onesided_enable = FALSE;
792 DWORD twosided_enable = FALSE;
793 GLint func = GL_ALWAYS;
794 GLint func_ccw = GL_ALWAYS;
795 GLint ref = 0;
796 GLuint mask = 0;
797 GLint stencilFail = GL_KEEP;
798 GLint depthFail = GL_KEEP;
799 GLint stencilPass = GL_KEEP;
800 GLint stencilFail_ccw = GL_KEEP;
801 GLint depthFail_ccw = GL_KEEP;
802 GLint stencilPass_ccw = GL_KEEP;
804 /* No stencil test without a stencil buffer */
805 if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) {
806 glDisable(GL_STENCIL_TEST);
807 checkGLcall("glDisable GL_STENCIL_TEST");
808 return;
811 onesided_enable = stateblock->renderState[WINED3DRS_STENCILENABLE];
812 twosided_enable = stateblock->renderState[WINED3DRS_TWOSIDEDSTENCILMODE];
813 if( !( func = CompareFunc(stateblock->renderState[WINED3DRS_STENCILFUNC]) ) )
814 func = GL_ALWAYS;
815 if( !( func_ccw = CompareFunc(stateblock->renderState[WINED3DRS_CCW_STENCILFUNC]) ) )
816 func_ccw = GL_ALWAYS;
817 ref = stateblock->renderState[WINED3DRS_STENCILREF];
818 mask = stateblock->renderState[WINED3DRS_STENCILMASK];
819 stencilFail = StencilOp(stateblock->renderState[WINED3DRS_STENCILFAIL]);
820 depthFail = StencilOp(stateblock->renderState[WINED3DRS_STENCILZFAIL]);
821 stencilPass = StencilOp(stateblock->renderState[WINED3DRS_STENCILPASS]);
822 stencilFail_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILFAIL]);
823 depthFail_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILZFAIL]);
824 stencilPass_ccw = StencilOp(stateblock->renderState[WINED3DRS_CCW_STENCILPASS]);
826 TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
827 "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
828 "GL_BACK: func: %x, fail %x, zfail %x, zpass %x )\n",
829 onesided_enable, twosided_enable, ref, mask,
830 func, stencilFail, depthFail, stencilPass,
831 func_ccw, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
833 if (twosided_enable && onesided_enable) {
834 glEnable(GL_STENCIL_TEST);
835 checkGLcall("glEnable GL_STENCIL_TEST");
837 /* Apply back first, then front. This function calls glActiveStencilFaceEXT,
838 * which has an effect on the code below too. If we apply the front face
839 * afterwards, we are sure that the active stencil face is set to front,
840 * and other stencil functions which do not use two sided stencil do not have
841 * to set it back
843 renderstate_stencil_twosided(stateblock, GL_BACK, func_ccw, ref, mask, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
844 renderstate_stencil_twosided(stateblock, GL_FRONT, func, ref, mask, stencilFail, depthFail, stencilPass);
845 } else if(onesided_enable) {
846 if(GL_SUPPORT(EXT_STENCIL_TWO_SIDE)) {
847 glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
848 checkGLcall("glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
851 glEnable(GL_STENCIL_TEST);
852 checkGLcall("glEnable GL_STENCIL_TEST");
853 glStencilFunc(func, ref, mask);
854 checkGLcall("glStencilFunc(...)");
855 glStencilOp(stencilFail, depthFail, stencilPass);
856 checkGLcall("glStencilOp(...)");
857 } else {
858 glDisable(GL_STENCIL_TEST);
859 checkGLcall("glDisable GL_STENCIL_TEST");
863 static void state_stencilwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
864 DWORD mask;
866 if(stateblock->wineD3DDevice->stencilBufferTarget) {
867 mask = stateblock->renderState[WINED3DRS_STENCILWRITEMASK];
868 } else {
869 mask = 0;
872 if(GL_SUPPORT(EXT_STENCIL_TWO_SIDE)) {
873 GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
874 checkGLcall("glActiveStencilFaceEXT(GL_BACK)");
875 glStencilMask(mask);
876 checkGLcall("glStencilMask");
877 GL_EXTCALL(glActiveStencilFaceEXT(GL_FRONT));
878 checkGLcall("glActiveStencilFaceEXT(GL_FRONT)");
879 glStencilMask(mask);
880 } else {
881 glStencilMask(mask);
883 checkGLcall("glStencilMask");
886 static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
887 /* TODO: Put this into the vertex type block once that is in the state table */
888 BOOL fogenable = stateblock->renderState[WINED3DRS_FOGENABLE];
889 BOOL is_ps3 = use_ps(stateblock->wineD3DDevice)
890 && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.hex_version >= WINED3DPS_VERSION(3,0);
891 float fogstart, fogend;
893 union {
894 DWORD d;
895 float f;
896 } tmpvalue;
898 if (!fogenable) {
899 /* No fog? Disable it, and we're done :-) */
900 glDisable(GL_FOG);
901 checkGLcall("glDisable GL_FOG");
902 if( use_ps(stateblock->wineD3DDevice)
903 && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.hex_version < WINED3DPS_VERSION(3,0) ) {
904 /* disable fog in the pixel shader
905 * NOTE: For pixel shader, GL_FOG_START and GL_FOG_END don't hold fog start s and end e but
906 * -1/(e-s) and e/(e-s) respectively.
908 glFogf(GL_FOG_START, 0.0f);
909 checkGLcall("glFogf(GL_FOG_START, fogstart)");
910 glFogf(GL_FOG_END, 1.0f);
911 checkGLcall("glFogf(GL_FOG_END, fogend)");
913 return;
916 tmpvalue.d = stateblock->renderState[WINED3DRS_FOGSTART];
917 fogstart = tmpvalue.f;
918 tmpvalue.d = stateblock->renderState[WINED3DRS_FOGEND];
919 fogend = tmpvalue.f;
921 /* Fog Rules:
923 * With fixed function vertex processing, Direct3D knows 2 different fog input sources.
924 * It can use the Z value of the vertex, or the alpha component of the specular color.
925 * This depends on the fog vertex, fog table and the vertex declaration. If the Z value
926 * is used, fogstart, fogend and the equation type are used, otherwise linear fog with
927 * start = 255, end = 0 is used. Obviously the msdn is not very clear on that.
929 * FOGTABLEMODE != NONE:
930 * The Z value is used, with the equation specified, no matter what vertex type.
932 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, untransformed:
933 * Per vertex fog is calculated using the specified fog equation and the parameters
935 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, transformed, OR
936 * FOGTABLEMODE == NONE, FOGVERTEXMODE == NONE, untransformed:
937 * Linear fog with start = 255.0, end = 0.0, input comes from the specular color
940 * Rules for vertex fog with shaders:
942 * When mixing fixed function functionality with the programmable pipeline, D3D expects
943 * the fog computation to happen during transformation while openGL expects it to happen
944 * during rasterization. Also, prior to pixel shader 3.0 D3D handles fog blending after
945 * the pixel shader while openGL always expects the pixel shader to handle the blending.
946 * To solve this problem, WineD3D does:
947 * 1) implement a linear fog equation and fog blending at the end of every pre 3.0 pixel
948 * shader,
949 * and 2) disables the fog computation (in either the fixed function or programmable
950 * rasterizer) if using a vertex program.
953 * If a fogtablemode and a fogvertexmode are specified, table fog is applied (with or
954 * without shaders).
957 if( is_ps3 ) {
958 if( !use_vs(stateblock->wineD3DDevice)
959 && stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE ) {
960 FIXME("Implement vertex fog for pixel shader >= 3.0 and fixed function pipeline\n");
964 if (use_vs(stateblock->wineD3DDevice)
965 && ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.reg_maps.fog) {
966 if( stateblock->renderState[WINED3DRS_FOGTABLEMODE] != WINED3DFOG_NONE ) {
967 if(!is_ps3) FIXME("Implement table fog for foggy vertex shader\n");
968 /* Disable fog */
969 fogenable = FALSE;
970 } else {
971 /* Set fog computation in the rasterizer to pass through the value (just blend it) */
972 glFogi(GL_FOG_MODE, GL_LINEAR);
973 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
974 fogstart = 1.0;
975 fogend = 0.0;
978 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
979 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
980 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
981 context->fog_coord = FALSE;
983 context->last_was_foggy_shader = TRUE;
985 else if( use_ps(stateblock->wineD3DDevice) ) {
986 /* NOTE: For pixel shader, GL_FOG_START and GL_FOG_END don't hold fog start s and end e but
987 * -1/(e-s) and e/(e-s) respectively to simplify fog computation in the shader.
989 WINED3DFOGMODE mode;
990 context->last_was_foggy_shader = FALSE;
992 /* If both fogmodes are set use the table fog mode */
993 if(stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE)
994 mode = stateblock->renderState[WINED3DRS_FOGVERTEXMODE];
995 else
996 mode = stateblock->renderState[WINED3DRS_FOGTABLEMODE];
998 switch (mode) {
999 case WINED3DFOG_EXP:
1000 case WINED3DFOG_EXP2:
1001 if(!is_ps3) FIXME("Implement non linear fog for pixel shader < 3.0\n");
1002 /* Disable fog */
1003 fogenable = FALSE;
1004 break;
1006 case WINED3DFOG_LINEAR:
1007 fogstart = -1.0f/(fogend-fogstart);
1008 fogend *= -fogstart;
1009 break;
1011 case WINED3DFOG_NONE:
1012 if(!is_ps3) FIXME("Implement software vertex fog for pixel shader < 3.0\n");
1013 /* Disable fog */
1014 fogenable = FALSE;
1015 break;
1016 default: FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %d\n", stateblock->renderState[WINED3DRS_FOGVERTEXMODE]);
1019 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
1020 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1021 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1022 context->fog_coord = FALSE;
1025 /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
1026 * the system will apply only pixel(=table) fog effects."
1028 else if(stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) {
1029 glHint(GL_FOG_HINT, GL_FASTEST);
1030 checkGLcall("glHint(GL_FOG_HINT, GL_FASTEST)");
1031 context->last_was_foggy_shader = FALSE;
1033 switch (stateblock->renderState[WINED3DRS_FOGVERTEXMODE]) {
1034 /* If processed vertices are used, fall through to the NONE case */
1035 case WINED3DFOG_EXP: {
1036 if(!context->last_was_rhw) {
1037 glFogi(GL_FOG_MODE, GL_EXP);
1038 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1039 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
1040 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1041 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1042 context->fog_coord = FALSE;
1044 break;
1047 case WINED3DFOG_EXP2: {
1048 if(!context->last_was_rhw) {
1049 glFogi(GL_FOG_MODE, GL_EXP2);
1050 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1051 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
1052 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1053 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1054 context->fog_coord = FALSE;
1056 break;
1059 case WINED3DFOG_LINEAR: {
1060 if(!context->last_was_rhw) {
1061 glFogi(GL_FOG_MODE, GL_LINEAR);
1062 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1063 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
1064 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1065 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1066 context->fog_coord = FALSE;
1068 break;
1071 case WINED3DFOG_NONE: {
1072 /* Both are none? According to msdn the alpha channel of the specular
1073 * color contains a fog factor. Set it in drawStridedSlow.
1074 * Same happens with Vertexfog on transformed vertices
1076 if(GL_SUPPORT(EXT_FOG_COORD)) {
1077 if(context->fog_coord == FALSE) {
1078 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
1079 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)");
1080 context->fog_coord = TRUE;
1082 glFogi(GL_FOG_MODE, GL_LINEAR);
1083 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1084 fogstart = 0xff;
1085 fogend = 0x0;
1086 } else {
1087 /* Disable GL fog, handle this in software in drawStridedSlow */
1088 fogenable = FALSE;
1090 break;
1092 default: FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %d\n", stateblock->renderState[WINED3DRS_FOGVERTEXMODE]);
1094 } else {
1095 glHint(GL_FOG_HINT, GL_NICEST);
1096 checkGLcall("glHint(GL_FOG_HINT, GL_NICEST)");
1097 context->last_was_foggy_shader = FALSE;
1099 switch (stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
1100 case WINED3DFOG_EXP:
1101 glFogi(GL_FOG_MODE, GL_EXP);
1102 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1103 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
1104 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1105 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1106 context->fog_coord = FALSE;
1108 break;
1110 case WINED3DFOG_EXP2:
1111 glFogi(GL_FOG_MODE, GL_EXP2);
1112 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1113 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
1114 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1115 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1116 context->fog_coord = FALSE;
1118 break;
1120 case WINED3DFOG_LINEAR:
1121 glFogi(GL_FOG_MODE, GL_LINEAR);
1122 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1123 if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) {
1124 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1125 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1126 context->fog_coord = FALSE;
1128 break;
1130 case WINED3DFOG_NONE: /* Won't happen */
1131 default:
1132 FIXME("Unexpected WINED3DRS_FOGTABLEMODE %d\n", stateblock->renderState[WINED3DRS_FOGTABLEMODE]);
1136 if(fogenable) {
1137 glEnable(GL_FOG);
1138 checkGLcall("glEnable GL_FOG");
1140 if(fogstart != fogend)
1142 glFogfv(GL_FOG_START, &fogstart);
1143 checkGLcall("glFogf(GL_FOG_START, fogstart)");
1144 TRACE("Fog Start == %f\n", fogstart);
1146 glFogfv(GL_FOG_END, &fogend);
1147 checkGLcall("glFogf(GL_FOG_END, fogend)");
1148 TRACE("Fog End == %f\n", fogend);
1150 else
1152 glFogf(GL_FOG_START, -1.0 / 0.0);
1153 checkGLcall("glFogf(GL_FOG_START, fogstart)");
1154 TRACE("Fog Start == %f\n", fogstart);
1156 glFogf(GL_FOG_END, 0.0);
1157 checkGLcall("glFogf(GL_FOG_END, fogend)");
1158 TRACE("Fog End == %f\n", fogend);
1160 } else {
1161 glDisable(GL_FOG);
1162 checkGLcall("glDisable GL_FOG");
1163 if( use_ps(stateblock->wineD3DDevice) ) {
1164 /* disable fog in the pixel shader
1165 * NOTE: For pixel shader, GL_FOG_START and GL_FOG_END don't hold fog start s and end e but
1166 * -1/(e-s) and e/(e-s) respectively.
1168 glFogf(GL_FOG_START, 0.0f);
1169 checkGLcall("glFogf(GL_FOG_START, fogstart)");
1170 glFogf(GL_FOG_END, 1.0f);
1171 checkGLcall("glFogf(GL_FOG_END, fogend)");
1176 static void state_rangefog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1177 if(stateblock->renderState[WINED3DRS_RANGEFOGENABLE]) {
1178 if (GL_SUPPORT(NV_FOG_DISTANCE)) {
1179 glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
1180 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)");
1181 } else {
1182 WARN("Range fog enabled, but not supported by this opengl implementation\n");
1184 } else {
1185 if (GL_SUPPORT(NV_FOG_DISTANCE)) {
1186 glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
1187 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
1192 static void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1193 float col[4];
1194 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_FOGCOLOR], col);
1195 glFogfv(GL_FOG_COLOR, &col[0]);
1196 checkGLcall("glFog GL_FOG_COLOR");
1199 static void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1200 union {
1201 DWORD d;
1202 float f;
1203 } tmpvalue;
1204 tmpvalue.d = stateblock->renderState[WINED3DRS_FOGDENSITY];
1205 glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
1206 checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
1209 /* TODO: Merge with primitive type + init_materials()!! */
1210 static void state_colormat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1211 IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
1212 GLenum Parm = 0;
1213 WineDirect3DStridedData *diffuse = &device->strided_streams.u.s.diffuse;
1214 BOOL isDiffuseSupplied;
1216 /* Depends on the decoded vertex declaration to read the existence of diffuse data.
1217 * The vertex declaration will call this function if the fixed function pipeline is used.
1220 if(isStateDirty(context, STATE_VDECL)) {
1221 return;
1224 isDiffuseSupplied = diffuse->lpData || diffuse->VBO;
1226 context->num_untracked_materials = 0;
1227 if (isDiffuseSupplied && stateblock->renderState[WINED3DRS_COLORVERTEX]) {
1228 TRACE("diff %d, amb %d, emis %d, spec %d\n",
1229 stateblock->renderState[WINED3DRS_DIFFUSEMATERIALSOURCE],
1230 stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE],
1231 stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE],
1232 stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE]);
1234 if (stateblock->renderState[WINED3DRS_DIFFUSEMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1235 if (stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1236 Parm = GL_AMBIENT_AND_DIFFUSE;
1237 } else {
1238 Parm = GL_DIFFUSE;
1240 if(stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1241 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1242 context->num_untracked_materials++;
1244 if(stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1245 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1246 context->num_untracked_materials++;
1248 } else if (stateblock->renderState[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1249 Parm = GL_AMBIENT;
1250 if(stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1251 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1252 context->num_untracked_materials++;
1254 if(stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1255 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1256 context->num_untracked_materials++;
1258 } else if (stateblock->renderState[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1259 Parm = GL_EMISSION;
1260 if(stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1261 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1262 context->num_untracked_materials++;
1264 } else if (stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) {
1265 Parm = GL_SPECULAR;
1269 /* Nothing changed, return. */
1270 if (Parm == context->tracking_parm) return;
1272 if(!Parm) {
1273 glDisable(GL_COLOR_MATERIAL);
1274 checkGLcall("glDisable GL_COLOR_MATERIAL");
1275 } else {
1276 glColorMaterial(GL_FRONT_AND_BACK, Parm);
1277 checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
1278 glEnable(GL_COLOR_MATERIAL);
1279 checkGLcall("glEnable(GL_COLOR_MATERIAL)");
1282 /* Apparently calls to glMaterialfv are ignored for properties we're
1283 * tracking with glColorMaterial, so apply those here. */
1284 switch (context->tracking_parm) {
1285 case GL_AMBIENT_AND_DIFFUSE:
1286 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*)&device->updateStateBlock->material.Ambient);
1287 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float*)&device->updateStateBlock->material.Diffuse);
1288 checkGLcall("glMaterialfv");
1289 break;
1291 case GL_DIFFUSE:
1292 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float*)&device->updateStateBlock->material.Diffuse);
1293 checkGLcall("glMaterialfv");
1294 break;
1296 case GL_AMBIENT:
1297 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*)&device->updateStateBlock->material.Ambient);
1298 checkGLcall("glMaterialfv");
1299 break;
1301 case GL_EMISSION:
1302 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float*)&device->updateStateBlock->material.Emissive);
1303 checkGLcall("glMaterialfv");
1304 break;
1306 case GL_SPECULAR:
1307 /* Only change material color if specular is enabled, otherwise it is set to black */
1308 if (device->stateBlock->renderState[WINED3DRS_SPECULARENABLE]) {
1309 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*)&device->updateStateBlock->material.Specular);
1310 checkGLcall("glMaterialfv");
1311 } else {
1312 float black[4] = {0.0f, 0.0f, 0.0f, 0.0f};
1313 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
1314 checkGLcall("glMaterialfv");
1316 break;
1319 context->tracking_parm = Parm;
1322 static void state_linepattern(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1323 union {
1324 DWORD d;
1325 WINED3DLINEPATTERN lp;
1326 } tmppattern;
1327 tmppattern.d = stateblock->renderState[WINED3DRS_LINEPATTERN];
1329 TRACE("Line pattern: repeat %d bits %x\n", tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
1331 if (tmppattern.lp.wRepeatFactor) {
1332 glLineStipple(tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
1333 checkGLcall("glLineStipple(repeat, linepattern)");
1334 glEnable(GL_LINE_STIPPLE);
1335 checkGLcall("glEnable(GL_LINE_STIPPLE);");
1336 } else {
1337 glDisable(GL_LINE_STIPPLE);
1338 checkGLcall("glDisable(GL_LINE_STIPPLE);");
1342 static void state_zbias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1343 union {
1344 DWORD d;
1345 float f;
1346 } tmpvalue;
1348 if (stateblock->renderState[WINED3DRS_ZBIAS]) {
1349 tmpvalue.d = stateblock->renderState[WINED3DRS_ZBIAS];
1350 TRACE("ZBias value %f\n", tmpvalue.f);
1351 glPolygonOffset(0, -tmpvalue.f);
1352 checkGLcall("glPolygonOffset(0, -Value)");
1353 glEnable(GL_POLYGON_OFFSET_FILL);
1354 checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL);");
1355 glEnable(GL_POLYGON_OFFSET_LINE);
1356 checkGLcall("glEnable(GL_POLYGON_OFFSET_LINE);");
1357 glEnable(GL_POLYGON_OFFSET_POINT);
1358 checkGLcall("glEnable(GL_POLYGON_OFFSET_POINT);");
1359 } else {
1360 glDisable(GL_POLYGON_OFFSET_FILL);
1361 checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL);");
1362 glDisable(GL_POLYGON_OFFSET_LINE);
1363 checkGLcall("glDisable(GL_POLYGON_OFFSET_LINE);");
1364 glDisable(GL_POLYGON_OFFSET_POINT);
1365 checkGLcall("glDisable(GL_POLYGON_OFFSET_POINT);");
1370 static void state_normalize(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1371 if(isStateDirty(context, STATE_VDECL)) {
1372 return;
1374 /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor
1375 * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division
1376 * by zero and is not properly defined in opengl, so avoid it
1378 if (stateblock->renderState[WINED3DRS_NORMALIZENORMALS] && (
1379 stateblock->wineD3DDevice->strided_streams.u.s.normal.lpData ||
1380 stateblock->wineD3DDevice->strided_streams.u.s.normal.VBO)) {
1381 glEnable(GL_NORMALIZE);
1382 checkGLcall("glEnable(GL_NORMALIZE);");
1383 } else {
1384 glDisable(GL_NORMALIZE);
1385 checkGLcall("glDisable(GL_NORMALIZE);");
1389 static void state_psizemin(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1390 union {
1391 DWORD d;
1392 float f;
1393 } tmpvalue;
1395 tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
1396 if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
1397 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, tmpvalue.f);
1398 checkGLcall("glPointParameterfARB(...)");
1400 else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
1401 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, tmpvalue.f);
1402 checkGLcall("glPointParameterfEXT(...)");
1403 } else if(tmpvalue.f != 1.0) {
1404 FIXME("WINED3DRS_POINTSIZE_MIN not supported on this opengl, value is %f\n", tmpvalue.f);
1408 static void state_psizemax(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1409 union {
1410 DWORD d;
1411 float f;
1412 } tmpvalue;
1414 tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
1415 if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
1416 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, tmpvalue.f);
1417 checkGLcall("glPointParameterfARB(...)");
1419 else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
1420 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, tmpvalue.f);
1421 checkGLcall("glPointParameterfEXT(...)");
1422 } else if(tmpvalue.f != 64.0) {
1423 FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f);
1427 static void state_pscale(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1428 /* TODO: Group this with the viewport */
1430 * POINTSCALEENABLE controls how point size value is treated. If set to
1431 * true, the point size is scaled with respect to height of viewport.
1432 * When set to false point size is in pixels.
1434 * http://msdn.microsoft.com/library/en-us/directx9_c/point_sprites.asp
1437 /* Default values */
1438 GLfloat att[3] = {1.0f, 0.0f, 0.0f};
1439 union {
1440 DWORD d;
1441 float f;
1442 } pointSize, A, B, C;
1444 pointSize.d = stateblock->renderState[WINED3DRS_POINTSIZE];
1445 A.d = stateblock->renderState[WINED3DRS_POINTSCALE_A];
1446 B.d = stateblock->renderState[WINED3DRS_POINTSCALE_B];
1447 C.d = stateblock->renderState[WINED3DRS_POINTSCALE_C];
1449 if(stateblock->renderState[WINED3DRS_POINTSCALEENABLE]) {
1450 GLfloat scaleFactor;
1451 float h = stateblock->viewport.Height;
1453 if(pointSize.f < GL_LIMITS(pointsizemin)) {
1455 * Minimum valid point size for OpenGL is driver specific. For Direct3D it is
1456 * 0.0f. This means that OpenGL will clamp really small point sizes to the
1457 * driver minimum. To correct for this we need to multiply by the scale factor when sizes
1458 * are less than 1.0f. scale_factor = 1.0f / point_size.
1460 scaleFactor = pointSize.f / GL_LIMITS(pointsizemin);
1461 /* Clamp the point size, don't rely on the driver to do it. MacOS says min point size
1462 * is 1.0, but then accepts points below that and draws too small points
1464 pointSize.f = GL_LIMITS(pointsizemin);
1465 } else if(pointSize.f > GL_LIMITS(pointsize)) {
1466 /* gl already scales the input to glPointSize,
1467 * d3d scales the result after the point size scale.
1468 * If the point size is bigger than the max size, use the
1469 * scaling to scale it bigger, and set the gl point size to max
1471 scaleFactor = pointSize.f / GL_LIMITS(pointsize);
1472 TRACE("scale: %f\n", scaleFactor);
1473 pointSize.f = GL_LIMITS(pointsize);
1474 } else {
1475 scaleFactor = 1.0f;
1477 scaleFactor = pow(h * scaleFactor, 2);
1479 att[0] = A.f / scaleFactor;
1480 att[1] = B.f / scaleFactor;
1481 att[2] = C.f / scaleFactor;
1484 if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
1485 GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
1486 checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...)");
1488 else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
1489 GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
1490 checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)");
1491 } else if(stateblock->renderState[WINED3DRS_POINTSCALEENABLE]) {
1492 WARN("POINT_PARAMETERS not supported in this version of opengl\n");
1495 glPointSize(pointSize.f);
1496 checkGLcall("glPointSize(...);");
1499 static void state_colorwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1500 DWORD Value = stateblock->renderState[WINED3DRS_COLORWRITEENABLE];
1502 TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
1503 Value & WINED3DCOLORWRITEENABLE_RED ? 1 : 0,
1504 Value & WINED3DCOLORWRITEENABLE_GREEN ? 1 : 0,
1505 Value & WINED3DCOLORWRITEENABLE_BLUE ? 1 : 0,
1506 Value & WINED3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1507 glColorMask(Value & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1508 Value & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1509 Value & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1510 Value & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1511 checkGLcall("glColorMask(...)");
1513 /* depends on WINED3DRS_COLORWRITEENABLE. */
1514 if(stateblock->renderState[WINED3DRS_COLORWRITEENABLE1] != 0x0000000F ||
1515 stateblock->renderState[WINED3DRS_COLORWRITEENABLE2] != 0x0000000F ||
1516 stateblock->renderState[WINED3DRS_COLORWRITEENABLE3] != 0x0000000F ) {
1517 ERR("(WINED3DRS_COLORWRITEENABLE1/2/3,%d,%d,%d) not yet implemented. Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n",
1518 stateblock->renderState[WINED3DRS_COLORWRITEENABLE1],
1519 stateblock->renderState[WINED3DRS_COLORWRITEENABLE2],
1520 stateblock->renderState[WINED3DRS_COLORWRITEENABLE3]);
1524 static void state_localviewer(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1525 if(stateblock->renderState[WINED3DRS_LOCALVIEWER]) {
1526 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1527 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1528 } else {
1529 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1530 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
1534 static void state_lastpixel(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1535 if(stateblock->renderState[WINED3DRS_LASTPIXEL]) {
1536 TRACE("Last Pixel Drawing Enabled\n");
1537 } else {
1538 static BOOL first = TRUE;
1539 if(first) {
1540 FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1541 first = FALSE;
1542 } else {
1543 TRACE("Last Pixel Drawing Disabled, not handled yet\n");
1548 static void state_pointsprite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1549 /* TODO: NV_POINT_SPRITE */
1550 if (!GL_SUPPORT(ARB_POINT_SPRITE)) {
1551 TRACE("Point sprites not supported\n");
1552 return;
1555 if (stateblock->renderState[WINED3DRS_POINTSPRITEENABLE]) {
1556 glEnable(GL_POINT_SPRITE_ARB);
1557 checkGLcall("glEnable(GL_POINT_SPRITE_ARB)");
1558 } else {
1559 glDisable(GL_POINT_SPRITE_ARB);
1560 checkGLcall("glDisable(GL_POINT_SPRITE_ARB)");
1564 static void state_wrap(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1566 http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/texture/
1567 http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/graphics/programmingguide/FixedFunction/Textures/texturewrapping.asp
1568 http://www.gamedev.net/reference/programming/features/rendererdll3/page2.asp
1569 Discussion on the ways to turn on WRAPing to solve an OpenGL conversion problem.
1570 http://www.flipcode.org/cgi-bin/fcmsg.cgi?thread_show=10248
1572 so far as I can tell, wrapping and texture-coordinate generate go hand in hand,
1574 TRACE("Stub\n");
1575 if(stateblock->renderState[WINED3DRS_WRAP0] ||
1576 stateblock->renderState[WINED3DRS_WRAP1] ||
1577 stateblock->renderState[WINED3DRS_WRAP2] ||
1578 stateblock->renderState[WINED3DRS_WRAP3] ||
1579 stateblock->renderState[WINED3DRS_WRAP4] ||
1580 stateblock->renderState[WINED3DRS_WRAP5] ||
1581 stateblock->renderState[WINED3DRS_WRAP6] ||
1582 stateblock->renderState[WINED3DRS_WRAP7] ||
1583 stateblock->renderState[WINED3DRS_WRAP8] ||
1584 stateblock->renderState[WINED3DRS_WRAP9] ||
1585 stateblock->renderState[WINED3DRS_WRAP10] ||
1586 stateblock->renderState[WINED3DRS_WRAP11] ||
1587 stateblock->renderState[WINED3DRS_WRAP12] ||
1588 stateblock->renderState[WINED3DRS_WRAP13] ||
1589 stateblock->renderState[WINED3DRS_WRAP14] ||
1590 stateblock->renderState[WINED3DRS_WRAP15] ) {
1591 FIXME("(WINED3DRS_WRAP0) Texture wraping not yet supported\n");
1595 static void state_multisampleaa(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1596 if( GL_SUPPORT(ARB_MULTISAMPLE) ) {
1597 if(stateblock->renderState[WINED3DRS_MULTISAMPLEANTIALIAS]) {
1598 glEnable(GL_MULTISAMPLE_ARB);
1599 checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1600 } else {
1601 glDisable(GL_MULTISAMPLE_ARB);
1602 checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1604 } else {
1605 if(stateblock->renderState[WINED3DRS_MULTISAMPLEANTIALIAS]) {
1606 WARN("Multisample antialiasing not supported by gl\n");
1611 static void state_scissor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1612 if(stateblock->renderState[WINED3DRS_SCISSORTESTENABLE]) {
1613 glEnable(GL_SCISSOR_TEST);
1614 checkGLcall("glEnable(GL_SCISSOR_TEST)");
1615 } else {
1616 glDisable(GL_SCISSOR_TEST);
1617 checkGLcall("glDisable(GL_SCISSOR_TEST)");
1621 static void state_depthbias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1622 union {
1623 DWORD d;
1624 float f;
1625 } tmpvalue;
1627 if(stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS] ||
1628 stateblock->renderState[WINED3DRS_DEPTHBIAS]) {
1629 tmpvalue.d = stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS];
1630 glEnable(GL_POLYGON_OFFSET_FILL);
1631 checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
1632 glPolygonOffset(tmpvalue.f, *((float*)&stateblock->renderState[WINED3DRS_DEPTHBIAS]));
1633 checkGLcall("glPolygonOffset(...)");
1634 } else {
1635 glDisable(GL_POLYGON_OFFSET_FILL);
1636 checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
1640 static void state_perspective(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1641 if (stateblock->renderState[WINED3DRS_TEXTUREPERSPECTIVE]) {
1642 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1643 checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)");
1644 } else {
1645 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1646 checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)");
1650 static void state_stippledalpha(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1651 TRACE("Stub\n");
1652 if (stateblock->renderState[WINED3DRS_STIPPLEDALPHA])
1653 FIXME(" Stippled Alpha not supported yet.\n");
1656 static void state_antialias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1657 TRACE("Stub\n");
1658 if (stateblock->renderState[WINED3DRS_ANTIALIAS])
1659 FIXME(" Antialias not supported yet.\n");
1662 static void state_multisampmask(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1663 TRACE("Stub\n");
1664 if (stateblock->renderState[WINED3DRS_MULTISAMPLEMASK] != 0xFFFFFFFF)
1665 FIXME("(WINED3DRS_MULTISAMPLEMASK,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_MULTISAMPLEMASK]);
1668 static void state_patchedgestyle(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1669 TRACE("Stub\n");
1670 if (stateblock->renderState[WINED3DRS_PATCHEDGESTYLE] != WINED3DPATCHEDGE_DISCRETE)
1671 FIXME("(WINED3DRS_PATCHEDGESTYLE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_PATCHEDGESTYLE]);
1674 static void state_patchsegments(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1675 union {
1676 DWORD d;
1677 float f;
1678 } tmpvalue;
1679 tmpvalue.f = 1.0f;
1681 TRACE("Stub\n");
1682 if (stateblock->renderState[WINED3DRS_PATCHSEGMENTS] != tmpvalue.d)
1684 static BOOL displayed = FALSE;
1686 tmpvalue.d = stateblock->renderState[WINED3DRS_PATCHSEGMENTS];
1687 if(!displayed)
1688 FIXME("(WINED3DRS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f);
1690 displayed = TRUE;
1694 static void state_positiondegree(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1695 TRACE("Stub\n");
1696 if (stateblock->renderState[WINED3DRS_POSITIONDEGREE] != WINED3DDEGREE_CUBIC)
1697 FIXME("(WINED3DRS_POSITIONDEGREE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_POSITIONDEGREE]);
1700 static void state_normaldegree(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1701 TRACE("Stub\n");
1702 if (stateblock->renderState[WINED3DRS_NORMALDEGREE] != WINED3DDEGREE_LINEAR)
1703 FIXME("(WINED3DRS_NORMALDEGREE,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_NORMALDEGREE]);
1706 static void state_tessellation(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1707 TRACE("Stub\n");
1708 if(stateblock->renderState[WINED3DRS_ENABLEADAPTIVETESSELLATION])
1709 FIXME("(WINED3DRS_ENABLEADAPTIVETESSELLATION,%d) not yet implemented\n", stateblock->renderState[WINED3DRS_ENABLEADAPTIVETESSELLATION]);
1712 static void state_wrapu(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1713 if(stateblock->renderState[WINED3DRS_WRAPU]) {
1714 FIXME("Render state WINED3DRS_WRAPU not implemented yet\n");
1718 static void state_wrapv(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1719 if(stateblock->renderState[WINED3DRS_WRAPV]) {
1720 FIXME("Render state WINED3DRS_WRAPV not implemented yet\n");
1724 static void state_monoenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1725 if(stateblock->renderState[WINED3DRS_MONOENABLE]) {
1726 FIXME("Render state WINED3DRS_MONOENABLE not implemented yet\n");
1730 static void state_rop2(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1731 if(stateblock->renderState[WINED3DRS_ROP2]) {
1732 FIXME("Render state WINED3DRS_ROP2 not implemented yet\n");
1736 static void state_planemask(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1737 if(stateblock->renderState[WINED3DRS_PLANEMASK]) {
1738 FIXME("Render state WINED3DRS_PLANEMASK not implemented yet\n");
1742 static void state_subpixel(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1743 if(stateblock->renderState[WINED3DRS_SUBPIXEL]) {
1744 FIXME("Render state WINED3DRS_SUBPIXEL not implemented yet\n");
1748 static void state_subpixelx(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1749 if(stateblock->renderState[WINED3DRS_SUBPIXELX]) {
1750 FIXME("Render state WINED3DRS_SUBPIXELX not implemented yet\n");
1754 static void state_stippleenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1755 if(stateblock->renderState[WINED3DRS_STIPPLEENABLE]) {
1756 FIXME("Render state WINED3DRS_STIPPLEENABLE not implemented yet\n");
1760 static void state_bordercolor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1761 if(stateblock->renderState[WINED3DRS_BORDERCOLOR]) {
1762 FIXME("Render state WINED3DRS_BORDERCOLOR not implemented yet\n");
1766 static void state_mipmaplodbias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1767 if(stateblock->renderState[WINED3DRS_MIPMAPLODBIAS]) {
1768 FIXME("Render state WINED3DRS_MIPMAPLODBIAS not implemented yet\n");
1772 static void state_anisotropy(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1773 if(stateblock->renderState[WINED3DRS_ANISOTROPY]) {
1774 FIXME("Render state WINED3DRS_ANISOTROPY not implemented yet\n");
1778 static void state_flushbatch(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1779 if(stateblock->renderState[WINED3DRS_FLUSHBATCH]) {
1780 FIXME("Render state WINED3DRS_FLUSHBATCH not implemented yet\n");
1784 static void state_translucentsi(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1785 if(stateblock->renderState[WINED3DRS_TRANSLUCENTSORTINDEPENDENT]) {
1786 FIXME("Render state WINED3DRS_TRANSLUCENTSORTINDEPENDENT not implemented yet\n");
1790 static void state_extents(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1791 if(stateblock->renderState[WINED3DRS_EXTENTS]) {
1792 FIXME("Render state WINED3DRS_EXTENTS not implemented yet\n");
1796 static void state_ckeyblend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1797 if(stateblock->renderState[WINED3DRS_COLORKEYBLENDENABLE]) {
1798 FIXME("Render state WINED3DRS_COLORKEYBLENDENABLE not implemented yet\n");
1802 /* Activates the texture dimension according to the bound D3D texture.
1803 * Does not care for the colorop or correct gl texture unit(when using nvrc)
1804 * Requires the caller to activate the correct unit before
1806 static void activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1807 BOOL bumpmap = FALSE;
1809 if(stage > 0 && (stateblock->textureState[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE ||
1810 stateblock->textureState[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP)) {
1811 bumpmap = TRUE;
1812 context->texShaderBumpMap |= (1 << stage);
1813 } else {
1814 context->texShaderBumpMap &= ~(1 << stage);
1817 if(stateblock->textures[stage]) {
1818 switch(stateblock->textureDimensions[stage]) {
1819 case GL_TEXTURE_2D:
1820 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1821 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_2D);
1822 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
1823 } else {
1824 glDisable(GL_TEXTURE_3D);
1825 checkGLcall("glDisable(GL_TEXTURE_3D)");
1826 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1827 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1828 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1830 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
1831 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1832 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
1834 glEnable(GL_TEXTURE_2D);
1835 checkGLcall("glEnable(GL_TEXTURE_2D)");
1837 break;
1838 case GL_TEXTURE_RECTANGLE_ARB:
1839 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1840 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_RECTANGLE_ARB);
1841 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
1842 } else {
1843 glDisable(GL_TEXTURE_2D);
1844 checkGLcall("glDisable(GL_TEXTURE_2D)");
1845 glDisable(GL_TEXTURE_3D);
1846 checkGLcall("glDisable(GL_TEXTURE_3D)");
1847 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1848 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1849 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1851 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1852 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
1854 break;
1855 case GL_TEXTURE_3D:
1856 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1857 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
1858 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D)");
1859 } else {
1860 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1861 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1862 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1864 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
1865 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1866 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
1868 glDisable(GL_TEXTURE_2D);
1869 checkGLcall("glDisable(GL_TEXTURE_2D)");
1870 glEnable(GL_TEXTURE_3D);
1871 checkGLcall("glEnable(GL_TEXTURE_3D)");
1873 break;
1874 case GL_TEXTURE_CUBE_MAP_ARB:
1875 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1876 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB);
1877 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB)");
1878 } else {
1879 glDisable(GL_TEXTURE_2D);
1880 checkGLcall("glDisable(GL_TEXTURE_2D)");
1881 glDisable(GL_TEXTURE_3D);
1882 checkGLcall("glDisable(GL_TEXTURE_3D)");
1883 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
1884 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1885 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
1887 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
1888 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
1890 break;
1892 } else {
1893 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1894 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
1895 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE)");
1896 } else {
1897 glEnable(GL_TEXTURE_2D);
1898 checkGLcall("glEnable(GL_TEXTURE_2D)");
1899 glDisable(GL_TEXTURE_3D);
1900 checkGLcall("glDisable(GL_TEXTURE_3D)");
1901 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1902 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1903 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1905 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
1906 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1907 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
1909 /* Binding textures is done by samplers. A dummy texture will be bound */
1914 static void tex_colorop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
1915 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
1916 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
1917 BOOL tex_used = stateblock->wineD3DDevice->fixed_function_usage_map[stage];
1919 TRACE("Setting color op for stage %d\n", stage);
1921 if (stateblock->pixelShader && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE &&
1922 ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
1923 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
1924 return;
1927 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
1929 if (mapped_stage != -1) {
1930 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1931 if (tex_used && mapped_stage >= GL_LIMITS(textures)) {
1932 FIXME("Attempt to enable unsupported stage!\n");
1933 return;
1935 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
1936 checkGLcall("glActiveTextureARB");
1937 } else if (stage > 0) {
1938 WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1939 return;
1943 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1944 if(stateblock->lowest_disabled_stage > 0) {
1945 glEnable(GL_REGISTER_COMBINERS_NV);
1946 GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, stateblock->lowest_disabled_stage));
1947 } else {
1948 glDisable(GL_REGISTER_COMBINERS_NV);
1951 if(stage >= stateblock->lowest_disabled_stage) {
1952 TRACE("Stage disabled\n");
1953 if (mapped_stage != -1) {
1954 /* Disable everything here */
1955 glDisable(GL_TEXTURE_2D);
1956 checkGLcall("glDisable(GL_TEXTURE_2D)");
1957 glDisable(GL_TEXTURE_3D);
1958 checkGLcall("glDisable(GL_TEXTURE_3D)");
1959 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1960 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
1961 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
1963 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
1964 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1965 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
1967 if(GL_SUPPORT(NV_TEXTURE_SHADER2) && mapped_stage < GL_LIMITS(textures)) {
1968 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
1971 /* All done */
1972 return;
1975 /* The sampler will also activate the correct texture dimensions, so no need to do it here
1976 * if the sampler for this stage is dirty
1978 if(!isStateDirty(context, STATE_SAMPLER(stage))) {
1979 if (tex_used) activate_dimensions(stage, stateblock, context);
1982 /* Set the texture combiners */
1983 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
1984 set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
1985 stateblock->textureState[stage][WINED3DTSS_COLOROP],
1986 stateblock->textureState[stage][WINED3DTSS_COLORARG1],
1987 stateblock->textureState[stage][WINED3DTSS_COLORARG2],
1988 stateblock->textureState[stage][WINED3DTSS_COLORARG0],
1989 mapped_stage);
1991 /* In register combiners bump mapping is done in the stage AFTER the one that has the bump map operation set,
1992 * thus the texture shader may have to be updated
1994 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1995 BOOL usesBump = (stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE ||
1996 stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP) ? TRUE : FALSE;
1997 BOOL usedBump = (context->texShaderBumpMap & 1 << (stage + 1)) ? TRUE : FALSE;
1998 if(usesBump != usedBump) {
1999 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage + 1));
2000 checkGLcall("glActiveTextureARB");
2001 activate_dimensions(stage + 1, stateblock, context);
2002 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
2003 checkGLcall("glActiveTextureARB");
2006 } else {
2007 set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
2008 stateblock->textureState[stage][WINED3DTSS_COLOROP],
2009 stateblock->textureState[stage][WINED3DTSS_COLORARG1],
2010 stateblock->textureState[stage][WINED3DTSS_COLORARG2],
2011 stateblock->textureState[stage][WINED3DTSS_COLORARG0]);
2015 static void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2016 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
2017 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
2018 BOOL tex_used = stateblock->wineD3DDevice->fixed_function_usage_map[stage];
2019 DWORD op, arg1, arg2, arg0;
2021 TRACE("Setting alpha op for stage %d\n", stage);
2022 /* Do not care for enabled / disabled stages, just assign the settings. colorop disables / enables required stuff */
2023 if (mapped_stage != -1) {
2024 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
2025 if (tex_used && mapped_stage >= GL_LIMITS(textures)) {
2026 FIXME("Attempt to enable unsupported stage!\n");
2027 return;
2029 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
2030 checkGLcall("glActiveTextureARB");
2031 } else if (stage > 0) {
2032 /* We can't do anything here */
2033 WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
2034 return;
2038 op = stateblock->textureState[stage][WINED3DTSS_ALPHAOP];
2039 arg1 = stateblock->textureState[stage][WINED3DTSS_ALPHAARG1];
2040 arg2 = stateblock->textureState[stage][WINED3DTSS_ALPHAARG2];
2041 arg0 = stateblock->textureState[stage][WINED3DTSS_ALPHAARG0];
2043 if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && stage == 0 &&
2044 stateblock->textures[0] &&
2045 (stateblock->textureDimensions[0] == GL_TEXTURE_2D || stateblock->textureDimensions[0] == GL_TEXTURE_RECTANGLE_ARB)) {
2046 IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *) stateblock->textures[0])->surfaces[0];
2048 if(surf->CKeyFlags & WINEDDSD_CKSRCBLT &&
2049 getFormatDescEntry(surf->resource.format, NULL, NULL)->alphaMask == 0x00000000) {
2051 /* Color keying needs to pass alpha values from the texture through to have the alpha test work properly.
2052 * On the other hand applications can still use texture combiners apparently. This code takes care that apps
2053 * cannot remove the texture's alpha channel entirely.
2055 * The fixup is required for Prince of Persia 3D(prison bars), while Moto racer 2 requires D3DTOP_MODULATE to work
2056 * on color keyed surfaces. Aliens vs Predator 1 uses color keyed textures and alpha component of diffuse color to
2057 * draw things like translucent text and perform other blending effects.
2059 * Aliens vs Predator 1 relies on diffuse alpha having an effect, so it cannot be ignored. To provide the
2060 * behavior expected by the game, while emulating the colorkey, diffuse alpha must be modulated with texture alpha.
2061 * OTOH, Moto racer 2 at some points sets alphaop/alphaarg to SELECTARG/CURRENT, yet puts garbage in diffuse alpha
2062 * (zeroes). This works on native, because the game disables alpha test and alpha blending. Alpha test is overwritten by
2063 * wine's for purposes of color-keying though, so this will lead to missing geometry if texture alpha is modulated
2064 * (pixels fail alpha test). To get around this, ALPHABLENDENABLE state is checked: if the app enables alpha blending,
2065 * it can be expected to provide meaningful values in diffuse alpha, so it should be modulated with texture alpha;
2066 * otherwise, selecting diffuse alpha is ignored in favour of texture alpha.
2068 * What to do with multitexturing? So far no app has been found that uses color keying with multitexturing
2070 if(op == WINED3DTOP_DISABLE) {
2071 arg1 = WINED3DTA_TEXTURE;
2072 op = WINED3DTOP_SELECTARG1;
2074 else if(op == WINED3DTOP_SELECTARG1 && arg1 != WINED3DTA_TEXTURE) {
2075 if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE]) {
2076 arg2 = WINED3DTA_TEXTURE;
2077 op = WINED3DTOP_MODULATE;
2079 else arg1 = WINED3DTA_TEXTURE;
2081 else if(op == WINED3DTOP_SELECTARG2 && arg2 != WINED3DTA_TEXTURE) {
2082 if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE]) {
2083 arg1 = WINED3DTA_TEXTURE;
2084 op = WINED3DTOP_MODULATE;
2086 else arg2 = WINED3DTA_TEXTURE;
2091 TRACE("Setting alpha op for stage %d\n", stage);
2092 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
2093 set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
2094 op, arg1, arg2, arg0,
2095 mapped_stage);
2096 } else {
2097 set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
2098 op, arg1, arg2, arg0);
2102 static void transform_texture(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2103 DWORD texUnit = state - STATE_TRANSFORM(WINED3DTS_TEXTURE0);
2104 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[texUnit];
2105 BOOL generated;
2107 /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
2108 if(use_vs(stateblock->wineD3DDevice) ||
2109 isStateDirty(context, STATE_VDECL)) {
2110 TRACE("Using a vertex shader, or stream sources not sorted out yet, skipping\n");
2111 return;
2114 if (mapped_stage == -1) return;
2116 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
2117 if(mapped_stage >= GL_LIMITS(textures)) {
2118 return;
2120 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
2121 checkGLcall("glActiveTextureARB");
2122 } else if (mapped_stage > 0) {
2123 /* We can't do anything here */
2124 WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
2125 return;
2127 generated = (stateblock->textureState[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xFFFF0000) != WINED3DTSS_TCI_PASSTHRU;
2129 set_texture_matrix(&stateblock->transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0],
2130 stateblock->textureState[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS],
2131 generated,
2132 context->last_was_rhw,
2133 stateblock->wineD3DDevice->strided_streams.u.s.texCoords[texUnit].dwStride ?
2134 stateblock->wineD3DDevice->strided_streams.u.s.texCoords[texUnit].dwType:
2135 WINED3DDECLTYPE_UNUSED);
2137 /* The sampler applying function calls us if this changes */
2138 if(context->lastWasPow2Texture[texUnit] && stateblock->textures[texUnit]) {
2139 if(generated) {
2140 FIXME("Non-power2 texture being used with generated texture coords\n");
2142 TRACE("Non power two matrix multiply fixup\n");
2143 glMultMatrixf(((IWineD3DTextureImpl *) stateblock->textures[texUnit])->baseTexture.pow2Matrix);
2147 static void unloadTexCoords(IWineD3DStateBlockImpl *stateblock) {
2148 int texture_idx;
2150 for (texture_idx = 0; texture_idx < GL_LIMITS(texture_stages); ++texture_idx) {
2151 GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx));
2152 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2156 static void loadTexCoords(IWineD3DStateBlockImpl *stateblock, WineDirect3DVertexStridedData *sd, GLint *curVBO) {
2157 UINT *offset = stateblock->streamOffset;
2158 unsigned int mapped_stage = 0;
2159 unsigned int textureNo = 0;
2161 /* The code below uses glClientActiveTexture and glMultiTexCoord* which are all part of the GL_ARB_multitexture extension. */
2162 /* Abort if we don't support the extension. */
2163 if (!GL_SUPPORT(ARB_MULTITEXTURE)) {
2164 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
2165 return;
2168 for (textureNo = 0; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
2169 int coordIdx = stateblock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX];
2171 mapped_stage = stateblock->wineD3DDevice->texUnitMap[textureNo];
2172 if (mapped_stage == -1) continue;
2174 if (coordIdx < MAX_TEXTURES && (sd->u.s.texCoords[coordIdx].lpData || sd->u.s.texCoords[coordIdx].VBO)) {
2175 TRACE("Setting up texture %u, idx %d, cordindx %u, data %p\n",
2176 textureNo, mapped_stage, coordIdx, sd->u.s.texCoords[coordIdx].lpData);
2178 if (*curVBO != sd->u.s.texCoords[coordIdx].VBO) {
2179 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.texCoords[coordIdx].VBO));
2180 checkGLcall("glBindBufferARB");
2181 *curVBO = sd->u.s.texCoords[coordIdx].VBO;
2184 GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
2185 checkGLcall("glClientActiveTextureARB");
2187 /* The coords to supply depend completely on the fvf / vertex shader */
2188 glTexCoordPointer(
2189 WINED3D_ATR_SIZE(sd->u.s.texCoords[coordIdx].dwType),
2190 WINED3D_ATR_GLTYPE(sd->u.s.texCoords[coordIdx].dwType),
2191 sd->u.s.texCoords[coordIdx].dwStride,
2192 sd->u.s.texCoords[coordIdx].lpData + stateblock->loadBaseVertexIndex * sd->u.s.texCoords[coordIdx].dwStride + offset[sd->u.s.texCoords[coordIdx].streamNo]);
2193 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2194 } else {
2195 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + mapped_stage, 0, 0, 0, 1));
2198 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
2199 /* The number of the mapped stages increases monotonically, so it's fine to use the last used one */
2200 for (textureNo = mapped_stage + 1; textureNo < GL_LIMITS(textures); ++textureNo) {
2201 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1));
2206 static void tex_coordindex(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2207 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
2208 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
2210 if (mapped_stage == -1) {
2211 TRACE("No texture unit mapped to stage %d. Skipping texture coordinates.\n", stage);
2212 return;
2215 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
2216 if(mapped_stage >= GL_LIMITS(fragment_samplers)) {
2217 return;
2219 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
2220 checkGLcall("glActiveTextureARB");
2221 } else if (stage > 0) {
2222 /* We can't do anything here */
2223 WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
2224 return;
2227 /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
2229 * FIXME: From MSDN: The WINED3DTSS_TCI_* flags are mutually exclusive. If you include
2230 * one flag, you can still specify an index value, which the system uses to
2231 * determine the texture wrapping mode.
2232 * eg. SetTextureStageState( 0, WINED3DTSS_TEXCOORDINDEX, WINED3DTSS_TCI_CAMERASPACEPOSITION | 1 );
2233 * means use the vertex position (camera-space) as the input texture coordinates
2234 * for this texture stage, and the wrap mode set in the WINED3DRS_WRAP1 render
2235 * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up
2236 * to the TEXCOORDINDEX value
2240 * Be careful the value of the mask 0xF0000 come from d3d8types.h infos
2242 switch (stateblock->textureState[stage][WINED3DTSS_TEXCOORDINDEX] & 0xFFFF0000) {
2243 case WINED3DTSS_TCI_PASSTHRU:
2244 /*Use the specified texture coordinates contained within the vertex format. This value resolves to zero.*/
2245 glDisable(GL_TEXTURE_GEN_S);
2246 glDisable(GL_TEXTURE_GEN_T);
2247 glDisable(GL_TEXTURE_GEN_R);
2248 glDisable(GL_TEXTURE_GEN_Q);
2249 checkGLcall("glDisable(GL_TEXTURE_GEN_S,T,R,Q)");
2250 break;
2252 case WINED3DTSS_TCI_CAMERASPACEPOSITION:
2253 /* CameraSpacePosition means use the vertex position, transformed to camera space,
2254 * as the input texture coordinates for this stage's texture transformation. This
2255 * equates roughly to EYE_LINEAR
2258 float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
2259 float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
2260 float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
2261 float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
2262 TRACE("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set eye plane\n");
2264 glMatrixMode(GL_MODELVIEW);
2265 glPushMatrix();
2266 glLoadIdentity();
2267 glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
2268 glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
2269 glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
2270 glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
2271 glPopMatrix();
2273 TRACE("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set GL_TEXTURE_GEN_x and GL_x, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR\n");
2274 glEnable(GL_TEXTURE_GEN_S);
2275 checkGLcall("glEnable(GL_TEXTURE_GEN_S)");
2276 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
2277 checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
2278 glEnable(GL_TEXTURE_GEN_T);
2279 checkGLcall("glEnable(GL_TEXTURE_GEN_T)");
2280 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
2281 checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
2282 glEnable(GL_TEXTURE_GEN_R);
2283 checkGLcall("glEnable(GL_TEXTURE_GEN_R)");
2284 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
2285 checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)");
2287 break;
2289 case WINED3DTSS_TCI_CAMERASPACENORMAL:
2291 if (GL_SUPPORT(NV_TEXGEN_REFLECTION)) {
2292 float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
2293 float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
2294 float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
2295 float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
2296 TRACE("WINED3DTSS_TCI_CAMERASPACENORMAL - Set eye plane\n");
2298 glMatrixMode(GL_MODELVIEW);
2299 glPushMatrix();
2300 glLoadIdentity();
2301 glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
2302 glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
2303 glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
2304 glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
2305 glPopMatrix();
2307 glEnable(GL_TEXTURE_GEN_S);
2308 checkGLcall("glEnable(GL_TEXTURE_GEN_S)");
2309 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
2310 checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
2311 glEnable(GL_TEXTURE_GEN_T);
2312 checkGLcall("glEnable(GL_TEXTURE_GEN_T)");
2313 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
2314 checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
2315 glEnable(GL_TEXTURE_GEN_R);
2316 checkGLcall("glEnable(GL_TEXTURE_GEN_R)");
2317 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
2318 checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV)");
2321 break;
2323 case WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
2325 if (GL_SUPPORT(NV_TEXGEN_REFLECTION)) {
2326 float s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
2327 float t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
2328 float r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
2329 float q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
2330 TRACE("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set eye plane\n");
2332 glMatrixMode(GL_MODELVIEW);
2333 glPushMatrix();
2334 glLoadIdentity();
2335 glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
2336 glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
2337 glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
2338 glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
2339 glPopMatrix();
2341 glEnable(GL_TEXTURE_GEN_S);
2342 checkGLcall("glEnable(GL_TEXTURE_GEN_S)");
2343 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
2344 checkGLcall("glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
2345 glEnable(GL_TEXTURE_GEN_T);
2346 checkGLcall("glEnable(GL_TEXTURE_GEN_T)");
2347 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
2348 checkGLcall("glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
2349 glEnable(GL_TEXTURE_GEN_R);
2350 checkGLcall("glEnable(GL_TEXTURE_GEN_R)");
2351 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
2352 checkGLcall("glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV)");
2355 break;
2357 /* Unhandled types: */
2358 default:
2359 /* Todo: */
2360 /* ? disable GL_TEXTURE_GEN_n ? */
2361 glDisable(GL_TEXTURE_GEN_S);
2362 glDisable(GL_TEXTURE_GEN_T);
2363 glDisable(GL_TEXTURE_GEN_R);
2364 glDisable(GL_TEXTURE_GEN_Q);
2365 FIXME("Unhandled WINED3DTSS_TEXCOORDINDEX %x\n", stateblock->textureState[stage][WINED3DTSS_TEXCOORDINDEX]);
2366 break;
2369 /* Update the texture matrix */
2370 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + stage))) {
2371 transform_texture(STATE_TRANSFORM(WINED3DTS_TEXTURE0 + stage), stateblock, context);
2374 if(!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded) {
2375 /* Reload the arrays if we are using fixed function arrays to reflect the selected coord input
2376 * source. Call loadTexCoords directly because there is no need to reparse the vertex declaration
2377 * and do all the things linked to it
2378 * TODO: Tidy that up to reload only the arrays of the changed unit
2380 GLint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? -1 : 0;
2382 unloadTexCoords(stateblock);
2383 loadTexCoords(stateblock, &stateblock->wineD3DDevice->strided_streams, &curVBO);
2387 static void shaderconstant(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2388 IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
2390 /* Vertex and pixel shader states will call a shader upload, don't do anything as long one of them
2391 * has an update pending
2393 if(isStateDirty(context, STATE_VDECL) ||
2394 isStateDirty(context, STATE_PIXELSHADER)) {
2395 return;
2398 device->shader_backend->shader_load_constants((IWineD3DDevice *) device, use_ps(device), use_vs(device));
2401 static void tex_bumpenvlscale(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2402 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
2403 union {
2404 DWORD d;
2405 float f;
2406 } tmpvalue;
2408 if(stateblock->pixelShader && stage != 0 &&
2409 ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->baseShader.reg_maps.luminanceparams == stage) {
2410 /* The pixel shader has to know the luminance scale. Do a constants update if it
2411 * isn't scheduled anyway
2413 if(!isStateDirty(context, STATE_PIXELSHADERCONSTANT) &&
2414 !isStateDirty(context, STATE_PIXELSHADER)) {
2415 shaderconstant(STATE_PIXELSHADERCONSTANT, stateblock, context);
2419 tmpvalue.d = stateblock->textureState[stage][WINED3DTSS_BUMPENVLSCALE];
2420 if(tmpvalue.f != 0.0) {
2421 FIXME("WINED3DTSS_BUMPENVLSCALE not supported yet\n");
2425 static void tex_bumpenvloffset(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2426 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
2427 union {
2428 DWORD d;
2429 float f;
2430 } tmpvalue;
2432 if(stateblock->pixelShader && stage != 0 &&
2433 ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->baseShader.reg_maps.luminanceparams == stage) {
2434 /* The pixel shader has to know the luminance offset. Do a constants update if it
2435 * isn't scheduled anyway
2437 if(!isStateDirty(context, STATE_PIXELSHADERCONSTANT) &&
2438 !isStateDirty(context, STATE_PIXELSHADER)) {
2439 shaderconstant(STATE_PIXELSHADERCONSTANT, stateblock, context);
2443 tmpvalue.d = stateblock->textureState[stage][WINED3DTSS_BUMPENVLOFFSET];
2444 if(tmpvalue.f != 0.0) {
2445 FIXME("WINED3DTSS_BUMPENVLOFFSET not supported yet\n");
2449 static void tex_resultarg(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2450 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
2452 if(stage >= GL_LIMITS(texture_stages)) {
2453 return;
2456 if(stateblock->textureState[stage][WINED3DTSS_RESULTARG] != WINED3DTA_CURRENT) {
2457 FIXME("WINED3DTSS_RESULTARG not supported yet\n");
2461 static void sampler(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2462 DWORD sampler = state - STATE_SAMPLER(0);
2463 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
2464 union {
2465 float f;
2466 DWORD d;
2467 } tmpvalue;
2469 TRACE("Sampler: %d\n", sampler);
2470 /* Enabling and disabling texture dimensions is done by texture stage state / pixel shader setup, this function
2471 * only has to bind textures and set the per texture states
2474 if (mapped_stage == -1) {
2475 TRACE("No sampler mapped to stage %d. Returning.\n", sampler);
2476 return;
2479 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
2480 if (mapped_stage >= GL_LIMITS(combined_samplers)) {
2481 return;
2483 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
2484 checkGLcall("glActiveTextureARB");
2485 } else if (sampler > 0) {
2486 /* We can't do anything here */
2487 WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
2488 return;
2491 if(stateblock->textures[sampler]) {
2492 BOOL texIsPow2 = FALSE;
2494 /* The fixed function np2 texture emulation uses the texture matrix to fix up the coordinates
2495 * IWineD3DBaseTexture::ApplyStateChanges multiplies the set matrix with a fixup matrix. Before the
2496 * scaling is reapplied or removed, the texture matrix has to be reapplied
2498 if(!GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) && sampler < MAX_TEXTURES) {
2499 if(stateblock->textureDimensions[sampler] == GL_TEXTURE_2D ||
2500 stateblock->textureDimensions[sampler] == GL_TEXTURE_RECTANGLE_ARB) {
2501 if(((IWineD3DTextureImpl *) stateblock->textures[sampler])->baseTexture.pow2Matrix[0] != 1.0 ||
2502 ((IWineD3DTextureImpl *) stateblock->textures[sampler])->baseTexture.pow2Matrix[5] != 1.0 ) {
2503 texIsPow2 = TRUE;
2505 } else if(stateblock->textureDimensions[sampler] == GL_TEXTURE_CUBE_MAP_ARB) {
2506 if(((IWineD3DCubeTextureImpl *) stateblock->textures[sampler])->baseTexture.pow2Matrix[0] != 1.0) {
2507 texIsPow2 = TRUE;
2511 if(texIsPow2 || context->lastWasPow2Texture[sampler]) {
2512 context->lastWasPow2Texture[sampler] = texIsPow2;
2513 transform_texture(STATE_TRANSFORM(WINED3DTS_TEXTURE0 + stateblock->wineD3DDevice->texUnitMap[sampler]), stateblock, context);
2517 IWineD3DBaseTexture_PreLoad(stateblock->textures[sampler]);
2518 IWineD3DBaseTexture_ApplyStateChanges(stateblock->textures[sampler], stateblock->textureState[sampler], stateblock->samplerState[sampler]);
2520 if (GL_SUPPORT(EXT_TEXTURE_LOD_BIAS)) {
2521 tmpvalue.d = stateblock->samplerState[sampler][WINED3DSAMP_MIPMAPLODBIAS];
2522 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
2523 GL_TEXTURE_LOD_BIAS_EXT,
2524 tmpvalue.f);
2525 checkGLcall("glTexEnvi(GL_TEXTURE_LOD_BIAS_EXT, ...)");
2528 if (stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE && stateblock->pixelShader &&
2529 ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
2530 /* Using a pixel shader? Verify the sampler types */
2532 /* Make sure that the texture dimensions are enabled. I don't have to disable the other
2533 * dimensions because the shader knows from which texture type to sample from. For the sake of
2534 * debugging all dimensions could be enabled and a texture with some ugly pink bound to the unused
2535 * dimensions. This should make wrong sampling sources visible :-)
2537 glEnable(stateblock->textureDimensions[sampler]);
2538 checkGLcall("glEnable(stateblock->textureDimensions[sampler])");
2539 } else if(sampler < stateblock->lowest_disabled_stage) {
2540 if(!isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) {
2541 activate_dimensions(sampler, stateblock, context);
2544 if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && sampler == 0) {
2545 /* If color keying is enabled update the alpha test, it depends on the existence
2546 * of a color key in stage 0
2548 state_alpha(WINED3DRS_COLORKEYENABLE, stateblock, context);
2551 } else if(mapped_stage < GL_LIMITS(textures)) {
2552 if(sampler < stateblock->lowest_disabled_stage) {
2553 /* TODO: What should I do with pixel shaders here ??? */
2554 if(!isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) {
2555 activate_dimensions(sampler, stateblock, context);
2558 if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && sampler == 0) {
2559 /* If color keying is enabled update the alpha test, it depends on the existence
2560 * of a color key in stage 0
2562 state_alpha(WINED3DRS_COLORKEYENABLE, stateblock, context);
2564 } /* Otherwise tex_colorop disables the stage */
2565 glBindTexture(GL_TEXTURE_2D, stateblock->wineD3DDevice->dummyTextureName[sampler]);
2566 checkGLcall("glBindTexture(GL_TEXTURE_2D, stateblock->wineD3DDevice->dummyTextureName[sampler])");
2570 static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2571 IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
2572 BOOL use_pshader = use_ps(device);
2573 BOOL use_vshader = use_vs(device);
2574 BOOL update_fog = FALSE;
2575 int i;
2577 if (use_pshader) {
2578 if(!context->last_was_pshader) {
2579 /* Former draw without a pixel shader, some samplers
2580 * may be disabled because of WINED3DTSS_COLOROP = WINED3DTOP_DISABLE
2581 * make sure to enable them
2583 for(i=0; i < MAX_FRAGMENT_SAMPLERS; i++) {
2584 if(!isStateDirty(context, STATE_SAMPLER(i))) {
2585 sampler(STATE_SAMPLER(i), stateblock, context);
2588 update_fog = TRUE;
2589 } else {
2590 /* Otherwise all samplers were activated by the code above in earlier draws, or by sampler()
2591 * if a different texture was bound. I don't have to do anything.
2595 /* Compile and bind the shader */
2596 IWineD3DPixelShader_CompileShader(stateblock->pixelShader);
2597 } else {
2598 /* Disabled the pixel shader - color ops weren't applied
2599 * while it was enabled, so re-apply them.
2601 for(i=0; i < MAX_TEXTURES; i++) {
2602 if(!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP))) {
2603 tex_colorop(STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP), stateblock, context);
2606 if(context->last_was_pshader)
2607 update_fog = TRUE;
2610 if(!isStateDirty(context, StateTable[STATE_VSHADER].representative)) {
2611 device->shader_backend->shader_select((IWineD3DDevice *)stateblock->wineD3DDevice, use_pshader, use_vshader);
2613 if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (use_vshader || use_pshader)) {
2614 shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock, context);
2618 if(update_fog)
2619 state_fog(state, stateblock, context);
2621 context->last_was_pshader = use_pshader;
2624 static void tex_bumpenvmat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2625 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
2626 float mat[2][2];
2628 if(stateblock->pixelShader && stage != 0 &&
2629 ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->needsbumpmat == stage) {
2630 /* The pixel shader has to know the bump env matrix. Do a constants update if it isn't scheduled
2631 * anyway
2633 if(!isStateDirty(context, STATE_PIXELSHADERCONSTANT) &&
2634 !isStateDirty(context, STATE_PIXELSHADER)) {
2635 shaderconstant(STATE_PIXELSHADERCONSTANT, stateblock, context);
2639 if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
2640 if(stage >= GL_LIMITS(texture_stages)) {
2641 WARN("Bump env matrix of unsupported stage set\n");
2642 } else if(GL_SUPPORT(ARB_MULTITEXTURE)) {
2643 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stage));
2644 checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stage))");
2646 mat[0][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT00]);
2647 mat[1][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT01]);
2648 mat[0][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT10]);
2649 mat[1][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT11]);
2650 GL_EXTCALL(glTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI, (float *) mat));
2651 checkGLcall("glTexBumpParameterfvATI");
2652 } else if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
2653 /* Direct3D sets the matrix in the stage reading the perturbation map. The result is used to
2654 * offset the destination stage(always stage + 1 in d3d). In GL_NV_texture_shader, the bump
2655 * map offseting is done in the stage reading the bump mapped texture, and the perturbation
2656 * map is read from a specified source stage(always stage - 1 for d3d). Thus set the matrix
2657 * for stage + 1. Keep the nvrc tex unit mapping in mind too
2659 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage + 1];
2661 if(mapped_stage < GL_LIMITS(textures)) {
2662 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
2663 checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage))");
2665 /* We can't just pass a pointer to the stateblock to GL due to the different matrix
2666 * format(column major vs row major)
2668 mat[0][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT00]);
2669 mat[1][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT01]);
2670 mat[0][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT10]);
2671 mat[1][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT11]);
2672 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *) mat);
2673 checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)");
2678 static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2679 /* This function is called by transform_view below if the view matrix was changed too
2681 * Deliberately no check if the vertex declaration is dirty because the vdecl state
2682 * does not always update the world matrix, only on a switch between transformed
2683 * and untransformed draws. It *may* happen that the world matrix is set 2 times during one
2684 * draw, but that should be rather rare and cheaper in total.
2686 glMatrixMode(GL_MODELVIEW);
2687 checkGLcall("glMatrixMode");
2689 if(context->last_was_rhw) {
2690 glLoadIdentity();
2691 checkGLcall("glLoadIdentity()");
2692 } else {
2693 /* In the general case, the view matrix is the identity matrix */
2694 if (stateblock->wineD3DDevice->view_ident) {
2695 glLoadMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
2696 checkGLcall("glLoadMatrixf");
2697 } else {
2698 glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
2699 checkGLcall("glLoadMatrixf");
2700 glMultMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
2701 checkGLcall("glMultMatrixf");
2706 static void clipplane(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2707 UINT index = state - STATE_CLIPPLANE(0);
2709 if(isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW)) || index >= GL_LIMITS(clipplanes)) {
2710 return;
2713 /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */
2714 glMatrixMode(GL_MODELVIEW);
2715 glPushMatrix();
2716 glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
2718 TRACE("Clipplane [%f,%f,%f,%f]\n",
2719 stateblock->clipplane[index][0],
2720 stateblock->clipplane[index][1],
2721 stateblock->clipplane[index][2],
2722 stateblock->clipplane[index][3]);
2723 glClipPlane(GL_CLIP_PLANE0 + index, stateblock->clipplane[index]);
2724 checkGLcall("glClipPlane");
2726 glPopMatrix();
2729 static void transform_worldex(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2730 UINT matrix = state - STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0));
2731 GLenum glMat;
2732 TRACE("Setting world matrix %d\n", matrix);
2734 if(matrix >= GL_LIMITS(blends)) {
2735 WARN("Unsupported blend matrix set\n");
2736 return;
2737 } else if(isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW))) {
2738 return;
2741 /* GL_MODELVIEW0_ARB: 0x1700
2742 * GL_MODELVIEW1_ARB: 0x0x850a
2743 * GL_MODELVIEW2_ARB: 0x8722
2744 * GL_MODELVIEW3_ARB: 0x8723
2745 * etc
2746 * GL_MODELVIEW31_ARB: 0x873F
2748 if(matrix == 1) glMat = GL_MODELVIEW1_ARB;
2749 else glMat = GL_MODELVIEW2_ARB - 2 + matrix;
2751 glMatrixMode(glMat);
2752 checkGLcall("glMatrixMode(glMat)");
2754 /* World matrix 0 is multiplied with the view matrix because d3d uses 3 matrices while gl uses only 2. To avoid
2755 * weighting the view matrix incorrectly it has to be multiplied into every gl modelview matrix
2757 if(stateblock->wineD3DDevice->view_ident) {
2758 glLoadMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]);
2759 checkGLcall("glLoadMatrixf")
2760 } else {
2761 glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
2762 checkGLcall("glLoadMatrixf")
2763 glMultMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]);
2764 checkGLcall("glMultMatrixf")
2768 static void state_vertexblend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2769 WINED3DVERTEXBLENDFLAGS val = stateblock->renderState[WINED3DRS_VERTEXBLEND];
2771 switch(val) {
2772 case WINED3DVBF_1WEIGHTS:
2773 case WINED3DVBF_2WEIGHTS:
2774 case WINED3DVBF_3WEIGHTS:
2775 if(GL_SUPPORT(ARB_VERTEX_BLEND)) {
2776 glEnable(GL_VERTEX_BLEND_ARB);
2777 checkGLcall("glEnable(GL_VERTEX_BLEND_ARB)");
2779 /* D3D adds one more matrix which has weight (1 - sum(weights)). This is enabled at context
2780 * creation with enabling GL_WEIGHT_SUM_UNITY_ARB.
2782 GL_EXTCALL(glVertexBlendARB(stateblock->renderState[WINED3DRS_VERTEXBLEND] + 1));
2784 if(!stateblock->wineD3DDevice->vertexBlendUsed) {
2785 int i;
2786 for(i = 1; i < GL_LIMITS(blends); i++) {
2787 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(i)))) {
2788 transform_worldex(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(i)), stateblock, context);
2791 stateblock->wineD3DDevice->vertexBlendUsed = TRUE;
2793 } else {
2794 static BOOL once = FALSE;
2795 if(!once) {
2796 once = TRUE;
2797 /* TODO: Implement vertex blending in drawStridedSlow */
2798 FIXME("Vertex blending enabled, but not supported by hardware\n");
2801 break;
2803 case WINED3DVBF_DISABLE:
2804 case WINED3DVBF_0WEIGHTS: /* for Indexed vertex blending - not supported */
2805 if(GL_SUPPORT(ARB_VERTEX_BLEND)) {
2806 glDisable(GL_VERTEX_BLEND_ARB);
2807 checkGLcall("glDisable(GL_VERTEX_BLEND_ARB)");
2808 } else {
2809 TRACE("Vertex blending disabled\n");
2811 break;
2813 case WINED3DVBF_TWEENING:
2814 /* Just set the vertex weight for weight 0, enable vertex blending and hope the app doesn't have
2815 * vertex weights in the vertices?
2816 * For now we don't report that as supported, so a warn should suffice
2818 WARN("Tweening not supported yet\n");
2819 break;
2823 static void transform_view(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2824 unsigned int k;
2826 /* If we are changing the View matrix, reset the light and clipping planes to the new view
2827 * NOTE: We have to reset the positions even if the light/plane is not currently
2828 * enabled, since the call to enable it will not reset the position.
2829 * NOTE2: Apparently texture transforms do NOT need reapplying
2832 PLIGHTINFOEL *light = NULL;
2834 glMatrixMode(GL_MODELVIEW);
2835 checkGLcall("glMatrixMode(GL_MODELVIEW)");
2836 glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
2837 checkGLcall("glLoadMatrixf(...)");
2839 /* Reset lights. TODO: Call light apply func */
2840 for(k = 0; k < stateblock->wineD3DDevice->maxConcurrentLights; k++) {
2841 light = stateblock->activeLights[k];
2842 if(!light) continue;
2843 glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, light->lightPosn);
2844 checkGLcall("glLightfv posn");
2845 glLightfv(GL_LIGHT0 + light->glIndex, GL_SPOT_DIRECTION, light->lightDirn);
2846 checkGLcall("glLightfv dirn");
2849 /* Reset Clipping Planes */
2850 for (k = 0; k < GL_LIMITS(clipplanes); k++) {
2851 if(!isStateDirty(context, STATE_CLIPPLANE(k))) {
2852 clipplane(STATE_CLIPPLANE(k), stateblock, context);
2856 if(context->last_was_rhw) {
2857 glLoadIdentity();
2858 checkGLcall("glLoadIdentity()");
2859 /* No need to update the world matrix, the identity is fine */
2860 return;
2863 /* Call the world matrix state, this will apply the combined WORLD + VIEW matrix
2864 * No need to do it here if the state is scheduled for update.
2866 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)))) {
2867 transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context);
2870 /* Avoid looping over a number of matrices if the app never used the functionality */
2871 if(stateblock->wineD3DDevice->vertexBlendUsed) {
2872 for(k = 1; k < GL_LIMITS(blends); k++) {
2873 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(k)))) {
2874 transform_worldex(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(k)), stateblock, context);
2880 static void transform_projection(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2881 glMatrixMode(GL_PROJECTION);
2882 checkGLcall("glMatrixMode(GL_PROJECTION)");
2883 glLoadIdentity();
2884 checkGLcall("glLoadIdentity");
2886 if(context->last_was_rhw) {
2887 double X, Y, height, width, minZ, maxZ;
2889 X = stateblock->viewport.X;
2890 Y = stateblock->viewport.Y;
2891 height = stateblock->viewport.Height;
2892 width = stateblock->viewport.Width;
2893 minZ = stateblock->viewport.MinZ;
2894 maxZ = stateblock->viewport.MaxZ;
2896 if(!stateblock->wineD3DDevice->untransformed) {
2897 /* Transformed vertices are supposed to bypass the whole transform pipeline including
2898 * frustum clipping. This can't be done in opengl, so this code adjusts the Z range to
2899 * suppress depth clipping. This can be done because it is an orthogonal projection and
2900 * the Z coordinate does not affect the size of the primitives. Half Life 1 and Prince of
2901 * Persia 3D need this.
2903 * Note that using minZ and maxZ here doesn't entirely fix the problem, since view frustum
2904 * clipping is still enabled, but it seems to fix it for all apps tested so far. A minor
2905 * problem can be witnessed in half-life 1 engine based games, the weapon is clipped close
2906 * to the viewer.
2908 * Also note that this breaks z comparison against z values filled in with clear,
2909 * but no app depending on that and disabled clipping has been found yet. Comparing
2910 * primitives against themselves works, so the Z buffer is still intact for normal hidden
2911 * surface removal.
2913 * We could disable clipping entirely by setting the near to infinity and far to -infinity,
2914 * but this would break Z buffer operation. Raising the range to something less than
2915 * infinity would help a bit at the cost of Z precision, but it wouldn't eliminate the
2916 * problem either.
2918 TRACE("Calling glOrtho with %f, %f, %f, %f\n", width, height, -minZ, -maxZ);
2919 if(stateblock->wineD3DDevice->render_offscreen) {
2920 glOrtho(X, X + width, -Y, -Y - height, -minZ, -maxZ);
2921 } else {
2922 glOrtho(X, X + width, Y + height, Y, -minZ, -maxZ);
2924 } else {
2925 /* If the app mixes transformed and untransformed primitives we can't use the coordinate system
2926 * trick above because this would mess up transformed and untransformed Z order. Pass the z position
2927 * unmodified to opengl.
2929 * If the app depends on mixed types and disabled clipping we're out of luck without a pipeline
2930 * replacement shader.
2932 TRACE("Calling glOrtho with %f, %f, %f, %f\n", width, height, 1.0, -1.0);
2933 if(stateblock->wineD3DDevice->render_offscreen) {
2934 glOrtho(X, X + width, -Y, -Y - height, 0.0, -1.0);
2935 } else {
2936 glOrtho(X, X + width, Y + height, Y, 0.0, -1.0);
2939 checkGLcall("glOrtho");
2941 /* Window Coord 0 is the middle of the first pixel, so translate by 1/2 pixels */
2942 glTranslatef(0.5, 0.5, 0);
2943 checkGLcall("glTranslatef(0.5, 0.5, 0)");
2944 /* D3D texture coordinates are flipped compared to OpenGL ones, so
2945 * render everything upside down when rendering offscreen. */
2946 if (stateblock->wineD3DDevice->render_offscreen) {
2947 glScalef(1.0, -1.0, 1.0);
2948 checkGLcall("glScalef");
2950 } else {
2951 /* The rule is that the window coordinate 0 does not correspond to the
2952 beginning of the first pixel, but the center of the first pixel.
2953 As a consequence if you want to correctly draw one line exactly from
2954 the left to the right end of the viewport (with all matrices set to
2955 be identity), the x coords of both ends of the line would be not
2956 -1 and 1 respectively but (-1-1/viewport_widh) and (1-1/viewport_width)
2957 instead.
2959 1.0 / Width is used because the coord range goes from -1.0 to 1.0, then we
2960 divide by the Width/Height, so we need the half range(1.0) to translate by
2961 half a pixel.
2963 The other fun is that d3d's output z range after the transformation is [0;1],
2964 but opengl's is [-1;1]. Since the z buffer is in range [0;1] for both, gl
2965 scales [-1;1] to [0;1]. This would mean that we end up in [0.5;1] and loose a lot
2966 of Z buffer precision and the clear values do not match in the z test. Thus scale
2967 [0;1] to [-1;1], so when gl undoes that we utilize the full z range
2969 glTranslatef(1.0 / stateblock->viewport.Width, -1.0/ stateblock->viewport.Height, -1.0);
2970 checkGLcall("glTranslatef (1.0 / width, -1.0 / height, -1.0)");
2971 if (stateblock->wineD3DDevice->render_offscreen) {
2972 /* D3D texture coordinates are flipped compared to OpenGL ones, so
2973 * render everything upside down when rendering offscreen. */
2974 glScalef(1.0, -1.0, 2.0);
2975 } else {
2976 glScalef(1.0, 1.0, 2.0);
2978 checkGLcall("glScalef");
2980 glMultMatrixf(&stateblock->transforms[WINED3DTS_PROJECTION].u.m[0][0]);
2981 checkGLcall("glLoadMatrixf");
2985 /* This should match any arrays loaded in loadVertexData.
2986 * stateblock impl is required for GL_SUPPORT
2987 * TODO: Only load / unload arrays if we have to.
2989 static inline void unloadVertexData(IWineD3DStateBlockImpl *stateblock) {
2990 glDisableClientState(GL_VERTEX_ARRAY);
2991 glDisableClientState(GL_NORMAL_ARRAY);
2992 glDisableClientState(GL_COLOR_ARRAY);
2993 if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
2994 glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
2996 if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
2997 glDisableClientState(GL_WEIGHT_ARRAY_ARB);
2998 } else if (GL_SUPPORT(EXT_VERTEX_WEIGHTING)) {
2999 glDisableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT);
3001 unloadTexCoords(stateblock);
3004 /* This should match any arrays loaded in loadNumberedArrays
3005 * TODO: Only load / unload arrays if we have to.
3007 static inline void unloadNumberedArrays(IWineD3DStateBlockImpl *stateblock) {
3008 /* disable any attribs (this is the same for both GLSL and ARB modes) */
3009 GLint maxAttribs;
3010 int i;
3012 /* Leave all the attribs disabled */
3013 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &maxAttribs);
3014 /* MESA does not support it right not */
3015 if (glGetError() != GL_NO_ERROR)
3016 maxAttribs = 16;
3017 for (i = 0; i < maxAttribs; ++i) {
3018 GL_EXTCALL(glDisableVertexAttribArrayARB(i));
3019 checkGLcall("glDisableVertexAttribArrayARB(reg)");
3023 static inline void loadNumberedArrays(IWineD3DStateBlockImpl *stateblock, WineDirect3DVertexStridedData *strided) {
3024 GLint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? -1 : 0;
3025 int i;
3026 UINT *offset = stateblock->streamOffset;
3027 IWineD3DVertexBufferImpl *vb;
3028 DWORD_PTR shift_index;
3030 /* Default to no instancing */
3031 stateblock->wineD3DDevice->instancedDraw = FALSE;
3033 for (i = 0; i < MAX_ATTRIBS; i++) {
3035 if (!strided->u.input[i].lpData && !strided->u.input[i].VBO)
3036 continue;
3038 /* Do not load instance data. It will be specified using glTexCoord by drawprim */
3039 if(stateblock->streamFlags[strided->u.input[i].streamNo] & WINED3DSTREAMSOURCE_INSTANCEDATA) {
3040 GL_EXTCALL(glDisableVertexAttribArrayARB(i));
3041 stateblock->wineD3DDevice->instancedDraw = TRUE;
3042 continue;
3045 TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, strided->u.input[i].VBO);
3047 if(strided->u.input[i].dwStride) {
3048 if(curVBO != strided->u.input[i].VBO) {
3049 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, strided->u.input[i].VBO));
3050 checkGLcall("glBindBufferARB");
3051 curVBO = strided->u.input[i].VBO;
3053 vb = (IWineD3DVertexBufferImpl *) stateblock->streamSource[strided->u.input[i].streamNo];
3054 /* Use the VBO to find out if a vertex buffer exists, not the vb pointer. vb can point to a
3055 * user pointer data blob. In that case curVBO will be 0. If there is a vertex buffer but no
3056 * vbo we won't be load converted attributes anyway
3058 if(curVBO && vb->conv_shift) {
3059 TRACE("Loading attribute from shifted buffer\n");
3060 TRACE("Attrib %d has original stride %d, new stride %d\n", i, strided->u.input[i].dwStride, vb->conv_stride);
3061 TRACE("Original offset %p, additional offset 0x%08x\n",strided->u.input[i].lpData, vb->conv_shift[(DWORD_PTR) strided->u.input[i].lpData]);
3062 TRACE("Opengl type %x\n", WINED3D_ATR_GLTYPE(strided->u.input[i].dwType));
3063 shift_index = ((DWORD_PTR) strided->u.input[i].lpData + offset[strided->u.input[i].streamNo]);
3064 shift_index = shift_index % strided->u.input[i].dwStride;
3065 GL_EXTCALL(glVertexAttribPointerARB(i,
3066 WINED3D_ATR_SIZE(strided->u.input[i].dwType),
3067 WINED3D_ATR_GLTYPE(strided->u.input[i].dwType),
3068 WINED3D_ATR_NORMALIZED(strided->u.input[i].dwType),
3069 vb->conv_stride,
3071 strided->u.input[i].lpData + vb->conv_shift[shift_index] +
3072 stateblock->loadBaseVertexIndex * strided->u.input[i].dwStride +
3073 offset[strided->u.input[i].streamNo]));
3075 } else {
3076 GL_EXTCALL(glVertexAttribPointerARB(i,
3077 WINED3D_ATR_SIZE(strided->u.input[i].dwType),
3078 WINED3D_ATR_GLTYPE(strided->u.input[i].dwType),
3079 WINED3D_ATR_NORMALIZED(strided->u.input[i].dwType),
3080 strided->u.input[i].dwStride,
3082 strided->u.input[i].lpData +
3083 stateblock->loadBaseVertexIndex * strided->u.input[i].dwStride +
3084 offset[strided->u.input[i].streamNo]) );
3086 GL_EXTCALL(glEnableVertexAttribArrayARB(i));
3087 } else {
3088 /* Stride = 0 means always the same values. glVertexAttribPointerARB doesn't do that. Instead disable the pointer and
3089 * set up the attribute statically. But we have to figure out the system memory address.
3091 BYTE *ptr = strided->u.input[i].lpData + offset[strided->u.input[i].streamNo];
3092 if(strided->u.input[i].VBO) {
3093 vb = (IWineD3DVertexBufferImpl *) stateblock->streamSource[strided->u.input[i].streamNo];
3094 ptr += (long) vb->resource.allocatedMemory;
3096 GL_EXTCALL(glDisableVertexAttribArrayARB(i));
3098 switch(strided->u.input[i].dwType) {
3099 case WINED3DDECLTYPE_FLOAT1:
3100 GL_EXTCALL(glVertexAttrib1fvARB(i, (float *) ptr));
3101 break;
3102 case WINED3DDECLTYPE_FLOAT2:
3103 GL_EXTCALL(glVertexAttrib2fvARB(i, (float *) ptr));
3104 break;
3105 case WINED3DDECLTYPE_FLOAT3:
3106 GL_EXTCALL(glVertexAttrib3fvARB(i, (float *) ptr));
3107 break;
3108 case WINED3DDECLTYPE_FLOAT4:
3109 GL_EXTCALL(glVertexAttrib4fvARB(i, (float *) ptr));
3110 break;
3112 case WINED3DDECLTYPE_UBYTE4:
3113 GL_EXTCALL(glVertexAttrib4NubvARB(i, ptr));
3114 break;
3115 case WINED3DDECLTYPE_UBYTE4N:
3116 case WINED3DDECLTYPE_D3DCOLOR:
3117 GL_EXTCALL(glVertexAttrib4NubvARB(i, ptr));
3118 break;
3120 case WINED3DDECLTYPE_SHORT2:
3121 GL_EXTCALL(glVertexAttrib4svARB(i, (GLshort *) ptr));
3122 break;
3123 case WINED3DDECLTYPE_SHORT4:
3124 GL_EXTCALL(glVertexAttrib4svARB(i, (GLshort *) ptr));
3125 break;
3127 case WINED3DDECLTYPE_SHORT2N:
3129 GLshort s[4] = {((short *) ptr)[0], ((short *) ptr)[1], 0, 1};
3130 GL_EXTCALL(glVertexAttrib4NsvARB(i, s));
3131 break;
3133 case WINED3DDECLTYPE_USHORT2N:
3135 GLushort s[4] = {((unsigned short *) ptr)[0], ((unsigned short *) ptr)[1], 0, 1};
3136 GL_EXTCALL(glVertexAttrib4NusvARB(i, s));
3137 break;
3139 case WINED3DDECLTYPE_SHORT4N:
3140 GL_EXTCALL(glVertexAttrib4NsvARB(i, (GLshort *) ptr));
3141 break;
3142 case WINED3DDECLTYPE_USHORT4N:
3143 GL_EXTCALL(glVertexAttrib4NusvARB(i, (GLushort *) ptr));
3144 break;
3146 case WINED3DDECLTYPE_UDEC3:
3147 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
3148 /*glVertexAttrib3usvARB(i, (GLushort *) ptr); Does not exist */
3149 break;
3150 case WINED3DDECLTYPE_DEC3N:
3151 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
3152 /*glVertexAttrib3NusvARB(i, (GLushort *) ptr); Does not exist */
3153 break;
3155 case WINED3DDECLTYPE_FLOAT16_2:
3156 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
3157 * byte float according to the IEEE standard
3159 FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_2\n");
3160 break;
3161 case WINED3DDECLTYPE_FLOAT16_4:
3162 FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_4\n");
3163 break;
3165 case WINED3DDECLTYPE_UNUSED:
3166 default:
3167 ERR("Unexpected declaration in stride 0 attributes\n");
3168 break;
3173 checkGLcall("Loading numbered arrays");
3176 /* Used from 2 different functions, and too big to justify making it inlined */
3177 static void loadVertexData(IWineD3DStateBlockImpl *stateblock, WineDirect3DVertexStridedData *sd) {
3178 UINT *offset = stateblock->streamOffset;
3179 GLint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? -1 : 0;
3181 TRACE("Using fast vertex array code\n");
3183 /* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */
3184 stateblock->wineD3DDevice->instancedDraw = FALSE;
3186 /* Blend Data ---------------------------------------------- */
3187 if( (sd->u.s.blendWeights.lpData) || (sd->u.s.blendWeights.VBO) ||
3188 (sd->u.s.blendMatrixIndices.lpData) || (sd->u.s.blendMatrixIndices.VBO) ) {
3190 if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
3191 TRACE("Blend %d %p %d\n", WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType),
3192 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride, sd->u.s.blendWeights.dwStride + offset[sd->u.s.blendWeights.streamNo]);
3194 glEnableClientState(GL_WEIGHT_ARRAY_ARB);
3195 checkGLcall("glEnableClientState(GL_WEIGHT_ARRAY_ARB)");
3197 GL_EXTCALL(glVertexBlendARB(WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType) + 1));
3199 VTRACE(("glWeightPointerARB(%d, GL_FLOAT, %d, %p)\n",
3200 WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType) ,
3201 sd->u.s.blendWeights.dwStride,
3202 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride + offset[sd->u.s.blendWeights.streamNo]));
3204 if(curVBO != sd->u.s.blendWeights.VBO) {
3205 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.blendWeights.VBO));
3206 checkGLcall("glBindBufferARB");
3207 curVBO = sd->u.s.blendWeights.VBO;
3210 GL_EXTCALL(glWeightPointerARB)(
3211 WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType),
3212 WINED3D_ATR_GLTYPE(sd->u.s.blendWeights.dwType),
3213 sd->u.s.blendWeights.dwStride,
3214 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride + offset[sd->u.s.blendWeights.streamNo]);
3216 checkGLcall("glWeightPointerARB");
3218 if((sd->u.s.blendMatrixIndices.lpData) || (sd->u.s.blendMatrixIndices.VBO)){
3219 static BOOL showfixme = TRUE;
3220 if(showfixme){
3221 FIXME("blendMatrixIndices support\n");
3222 showfixme = FALSE;
3225 } else if (GL_SUPPORT(EXT_VERTEX_WEIGHTING)) {
3226 /* FIXME("TODO\n");*/
3227 #if 0
3229 GL_EXTCALL(glVertexWeightPointerEXT)(
3230 WINED3D_ATR_SIZE(sd->u.s.blendWeights.dwType),
3231 WINED3D_ATR_GLTYPE(sd->u.s.blendWeights.dwType),
3232 sd->u.s.blendWeights.dwStride,
3233 sd->u.s.blendWeights.lpData + stateblock->loadBaseVertexIndex * sd->u.s.blendWeights.dwStride);
3234 checkGLcall("glVertexWeightPointerEXT(numBlends, ...)");
3235 glEnableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT);
3236 checkGLcall("glEnableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT)");
3237 #endif
3239 } else {
3240 /* TODO: support blends in drawStridedSlow
3241 * No need to write a FIXME here, this is done after the general vertex decl decoding
3243 WARN("unsupported blending in openGl\n");
3245 } else {
3246 if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
3247 static const GLbyte one = 1;
3248 GL_EXTCALL(glWeightbvARB(1, &one));
3249 checkGLcall("glWeightivARB(GL_LIMITS(blends), weights)");
3253 #if 0 /* FOG ----------------------------------------------*/
3254 if (sd->u.s.fog.lpData || sd->u.s.fog.VBO) {
3255 /* TODO: fog*/
3256 if (GL_SUPPORT(EXT_FOG_COORD) {
3257 glEnableClientState(GL_FOG_COORDINATE_EXT);
3258 (GL_EXTCALL)(FogCoordPointerEXT)(
3259 WINED3D_ATR_GLTYPE(sd->u.s.fog.dwType),
3260 sd->u.s.fog.dwStride,
3261 sd->u.s.fog.lpData + stateblock->loadBaseVertexIndex * sd->u.s.fog.dwStride);
3262 } else {
3263 /* don't bother falling back to 'slow' as we don't support software FOG yet. */
3264 /* FIXME: fixme once */
3265 TRACE("Hardware support for FOG is not avaiable, FOG disabled.\n");
3267 } else {
3268 if (GL_SUPPRT(EXT_FOR_COORD) {
3269 /* make sure fog is disabled */
3270 glDisableClientState(GL_FOG_COORDINATE_EXT);
3273 #endif
3275 #if 0 /* tangents ----------------------------------------------*/
3276 if (sd->u.s.tangent.lpData || sd->u.s.tangent.VBO ||
3277 sd->u.s.binormal.lpData || sd->u.s.binormal.VBO) {
3278 /* TODO: tangents*/
3279 if (GL_SUPPORT(EXT_COORDINATE_FRAME) {
3280 if (sd->u.s.tangent.lpData || sd->u.s.tangent.VBO) {
3281 glEnable(GL_TANGENT_ARRAY_EXT);
3282 (GL_EXTCALL)(TangentPointerEXT)(
3283 WINED3D_ATR_GLTYPE(sd->u.s.tangent.dwType),
3284 sd->u.s.tangent.dwStride,
3285 sd->u.s.tangent.lpData + stateblock->loadBaseVertexIndex * sd->u.s.tangent.dwStride);
3286 } else {
3287 glDisable(GL_TANGENT_ARRAY_EXT);
3289 if (sd->u.s.binormal.lpData || sd->u.s.binormal.VBO) {
3290 glEnable(GL_BINORMAL_ARRAY_EXT);
3291 (GL_EXTCALL)(BinormalPointerEXT)(
3292 WINED3D_ATR_GLTYPE(sd->u.s.binormal.dwType),
3293 sd->u.s.binormal.dwStride,
3294 sd->u.s.binormal.lpData + stateblock->loadBaseVertexIndex * sd->u.s.binormal.dwStride);
3295 } else{
3296 glDisable(GL_BINORMAL_ARRAY_EXT);
3299 } else {
3300 /* don't bother falling back to 'slow' as we don't support software tangents and binormals yet . */
3301 /* FIXME: fixme once */
3302 TRACE("Hardware support for tangents and binormals is not avaiable, tangents and binormals disabled.\n");
3304 } else {
3305 if (GL_SUPPORT(EXT_COORDINATE_FRAME) {
3306 /* make sure fog is disabled */
3307 glDisable(GL_TANGENT_ARRAY_EXT);
3308 glDisable(GL_BINORMAL_ARRAY_EXT);
3311 #endif
3313 /* Point Size ----------------------------------------------*/
3314 if (sd->u.s.pSize.lpData || sd->u.s.pSize.VBO) {
3316 /* no such functionality in the fixed function GL pipeline */
3317 TRACE("Cannot change ptSize here in openGl\n");
3318 /* TODO: Implement this function in using shaders if they are available */
3322 /* Vertex Pointers -----------------------------------------*/
3323 if (sd->u.s.position.lpData != NULL || sd->u.s.position.VBO != 0) {
3324 /* Note dwType == float3 or float4 == 2 or 3 */
3325 VTRACE(("glVertexPointer(%d, GL_FLOAT, %d, %p)\n",
3326 sd->u.s.position.dwStride,
3327 sd->u.s.position.dwType + 1,
3328 sd->u.s.position.lpData));
3330 if(curVBO != sd->u.s.position.VBO) {
3331 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.position.VBO));
3332 checkGLcall("glBindBufferARB");
3333 curVBO = sd->u.s.position.VBO;
3336 /* min(WINED3D_ATR_SIZE(position),3) to Disable RHW mode as 'w' coord
3337 handling for rhw mode should not impact screen position whereas in GL it does.
3338 This may result in very slightly distorted textures in rhw mode.
3339 There's always the other option of fixing the view matrix to
3340 prevent w from having any effect.
3342 This only applies to user pointer sources, in VBOs the vertices are fixed up
3344 if(sd->u.s.position.VBO == 0) {
3345 glVertexPointer(3 /* min(WINED3D_ATR_SIZE(sd->u.s.position.dwType),3) */,
3346 WINED3D_ATR_GLTYPE(sd->u.s.position.dwType),
3347 sd->u.s.position.dwStride, sd->u.s.position.lpData + stateblock->loadBaseVertexIndex * sd->u.s.position.dwStride + offset[sd->u.s.position.streamNo]);
3348 } else {
3349 glVertexPointer(
3350 WINED3D_ATR_SIZE(sd->u.s.position.dwType),
3351 WINED3D_ATR_GLTYPE(sd->u.s.position.dwType),
3352 sd->u.s.position.dwStride, sd->u.s.position.lpData + stateblock->loadBaseVertexIndex * sd->u.s.position.dwStride + offset[sd->u.s.position.streamNo]);
3354 checkGLcall("glVertexPointer(...)");
3355 glEnableClientState(GL_VERTEX_ARRAY);
3356 checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)");
3359 /* Normals -------------------------------------------------*/
3360 if (sd->u.s.normal.lpData || sd->u.s.normal.VBO) {
3361 /* Note dwType == float3 or float4 == 2 or 3 */
3362 VTRACE(("glNormalPointer(GL_FLOAT, %d, %p)\n",
3363 sd->u.s.normal.dwStride,
3364 sd->u.s.normal.lpData));
3365 if(curVBO != sd->u.s.normal.VBO) {
3366 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.normal.VBO));
3367 checkGLcall("glBindBufferARB");
3368 curVBO = sd->u.s.normal.VBO;
3370 glNormalPointer(
3371 WINED3D_ATR_GLTYPE(sd->u.s.normal.dwType),
3372 sd->u.s.normal.dwStride,
3373 sd->u.s.normal.lpData + stateblock->loadBaseVertexIndex * sd->u.s.normal.dwStride + offset[sd->u.s.normal.streamNo]);
3374 checkGLcall("glNormalPointer(...)");
3375 glEnableClientState(GL_NORMAL_ARRAY);
3376 checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
3378 } else {
3379 glNormal3f(0, 0, 0);
3380 checkGLcall("glNormal3f(0, 0, 0)");
3383 /* Diffuse Colour --------------------------------------------*/
3384 /* WARNING: Data here MUST be in RGBA format, so cannot */
3385 /* go directly into fast mode from app pgm, because */
3386 /* directx requires data in BGRA format. */
3387 /* currently fixupVertices swizzles the format, but this isn't*/
3388 /* very practical when using VBOS */
3389 /* NOTE: Unless we write a vertex shader to swizzle the colour*/
3390 /* , or the user doesn't care and wants the speed advantage */
3392 if (sd->u.s.diffuse.lpData || sd->u.s.diffuse.VBO) {
3393 /* Note dwType == float3 or float4 == 2 or 3 */
3394 VTRACE(("glColorPointer(4, GL_UNSIGNED_BYTE, %d, %p)\n",
3395 sd->u.s.diffuse.dwStride,
3396 sd->u.s.diffuse.lpData));
3398 if(curVBO != sd->u.s.diffuse.VBO) {
3399 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.diffuse.VBO));
3400 checkGLcall("glBindBufferARB");
3401 curVBO = sd->u.s.diffuse.VBO;
3404 glColorPointer(WINED3D_ATR_SIZE(sd->u.s.diffuse.dwType),
3405 WINED3D_ATR_GLTYPE(sd->u.s.diffuse.dwType),
3406 sd->u.s.diffuse.dwStride,
3407 sd->u.s.diffuse.lpData + stateblock->loadBaseVertexIndex * sd->u.s.diffuse.dwStride + offset[sd->u.s.diffuse.streamNo]);
3408 checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
3409 glEnableClientState(GL_COLOR_ARRAY);
3410 checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");
3412 } else {
3413 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
3414 checkGLcall("glColor4f(1, 1, 1, 1)");
3417 /* Specular Colour ------------------------------------------*/
3418 if (sd->u.s.specular.lpData || sd->u.s.specular.VBO) {
3419 TRACE("setting specular colour\n");
3420 /* Note dwType == float3 or float4 == 2 or 3 */
3421 VTRACE(("glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, %d, %p)\n",
3422 sd->u.s.specular.dwStride,
3423 sd->u.s.specular.lpData));
3424 if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3425 if(curVBO != sd->u.s.specular.VBO) {
3426 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, sd->u.s.specular.VBO));
3427 checkGLcall("glBindBufferARB");
3428 curVBO = sd->u.s.specular.VBO;
3430 GL_EXTCALL(glSecondaryColorPointerEXT)(WINED3D_ATR_SIZE(sd->u.s.specular.dwType),
3431 WINED3D_ATR_GLTYPE(sd->u.s.specular.dwType),
3432 sd->u.s.specular.dwStride,
3433 sd->u.s.specular.lpData + stateblock->loadBaseVertexIndex * sd->u.s.specular.dwStride + offset[sd->u.s.specular.streamNo]);
3434 vcheckGLcall("glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, ...)");
3435 glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
3436 vcheckGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
3437 } else {
3439 /* Missing specular color is not critical, no warnings */
3440 VTRACE(("Specular colour is not supported in this GL implementation\n"));
3443 } else {
3444 if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3445 GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
3446 checkGLcall("glSecondaryColor3fEXT(0, 0, 0)");
3447 } else {
3449 /* Missing specular color is not critical, no warnings */
3450 VTRACE(("Specular colour is not supported in this GL implementation\n"));
3454 /* Texture coords -------------------------------------------*/
3455 loadTexCoords(stateblock, sd, &curVBO);
3458 static inline void drawPrimitiveTraceDataLocations(
3459 WineDirect3DVertexStridedData *dataLocations) {
3461 /* Dump out what parts we have supplied */
3462 TRACE("Strided Data:\n");
3463 TRACE_STRIDED((dataLocations), position);
3464 TRACE_STRIDED((dataLocations), blendWeights);
3465 TRACE_STRIDED((dataLocations), blendMatrixIndices);
3466 TRACE_STRIDED((dataLocations), normal);
3467 TRACE_STRIDED((dataLocations), pSize);
3468 TRACE_STRIDED((dataLocations), diffuse);
3469 TRACE_STRIDED((dataLocations), specular);
3470 TRACE_STRIDED((dataLocations), texCoords[0]);
3471 TRACE_STRIDED((dataLocations), texCoords[1]);
3472 TRACE_STRIDED((dataLocations), texCoords[2]);
3473 TRACE_STRIDED((dataLocations), texCoords[3]);
3474 TRACE_STRIDED((dataLocations), texCoords[4]);
3475 TRACE_STRIDED((dataLocations), texCoords[5]);
3476 TRACE_STRIDED((dataLocations), texCoords[6]);
3477 TRACE_STRIDED((dataLocations), texCoords[7]);
3478 TRACE_STRIDED((dataLocations), position2);
3479 TRACE_STRIDED((dataLocations), normal2);
3480 TRACE_STRIDED((dataLocations), tangent);
3481 TRACE_STRIDED((dataLocations), binormal);
3482 TRACE_STRIDED((dataLocations), tessFactor);
3483 TRACE_STRIDED((dataLocations), fog);
3484 TRACE_STRIDED((dataLocations), depth);
3485 TRACE_STRIDED((dataLocations), sample);
3487 return;
3490 /* Helper for vertexdeclaration() */
3491 static inline void handleStreams(IWineD3DStateBlockImpl *stateblock, BOOL useVertexShaderFunction, WineD3DContext *context) {
3492 IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
3493 BOOL fixup = FALSE;
3494 WineDirect3DVertexStridedData *dataLocations = &device->strided_streams;
3496 if(device->up_strided) {
3497 /* Note: this is a ddraw fixed-function code path */
3498 TRACE("================ Strided Input ===================\n");
3499 memcpy(dataLocations, device->up_strided, sizeof(*dataLocations));
3501 if(TRACE_ON(d3d)) {
3502 drawPrimitiveTraceDataLocations(dataLocations);
3504 } else {
3505 /* Note: This is a fixed function or shader codepath.
3506 * This means it must handle both types of strided data.
3507 * Shaders must go through here to zero the strided data, even if they
3508 * don't set any declaration at all
3510 TRACE("================ Vertex Declaration ===================\n");
3511 memset(dataLocations, 0, sizeof(*dataLocations));
3512 primitiveDeclarationConvertToStridedData((IWineD3DDevice *) device,
3513 useVertexShaderFunction, dataLocations, &fixup);
3516 if (dataLocations->u.s.position_transformed) {
3517 useVertexShaderFunction = FALSE;
3520 /* Unload the old arrays before loading the new ones to get old junk out */
3521 if(context->numberedArraysLoaded) {
3522 unloadNumberedArrays(stateblock);
3523 context->numberedArraysLoaded = FALSE;
3525 if(context->namedArraysLoaded) {
3526 unloadVertexData(stateblock);
3527 context->namedArraysLoaded = FALSE;
3530 if(useVertexShaderFunction) {
3531 if(((IWineD3DVertexDeclarationImpl *) stateblock->vertexDecl)->half_float_conv_needed && !fixup) {
3532 TRACE("Using drawStridedSlow with vertex shaders for FLOAT16 conversion\n");
3533 device->useDrawStridedSlow = TRUE;
3534 context->numberedArraysLoaded = FALSE;
3535 } else {
3536 TRACE("Loading numbered arrays\n");
3537 loadNumberedArrays(stateblock, dataLocations);
3538 device->useDrawStridedSlow = FALSE;
3539 context->numberedArraysLoaded = TRUE;
3541 } else if (fixup ||
3542 (dataLocations->u.s.pSize.lpData == NULL &&
3543 dataLocations->u.s.diffuse.lpData == NULL &&
3544 dataLocations->u.s.specular.lpData == NULL)) {
3545 /* Load the vertex data using named arrays */
3546 TRACE("Loading vertex data\n");
3547 loadVertexData(stateblock, dataLocations);
3548 device->useDrawStridedSlow = FALSE;
3549 context->namedArraysLoaded = TRUE;
3550 } else {
3551 TRACE("Not loading vertex data\n");
3552 device->useDrawStridedSlow = TRUE;
3555 /* Generate some fixme's if unsupported functionality is being used */
3556 #define BUFFER_OR_DATA(_attribute) dataLocations->u.s._attribute.lpData
3557 /* TODO: Either support missing functionality in fixupVertices or by creating a shader to replace the pipeline. */
3558 if (!useVertexShaderFunction && (BUFFER_OR_DATA(position2) || BUFFER_OR_DATA(normal2))) {
3559 FIXME("Tweening is only valid with vertex shaders\n");
3561 if (!useVertexShaderFunction && (BUFFER_OR_DATA(tangent) || BUFFER_OR_DATA(binormal))) {
3562 FIXME("Tangent and binormal bump mapping is only valid with vertex shaders\n");
3564 if (!useVertexShaderFunction && (BUFFER_OR_DATA(tessFactor) || BUFFER_OR_DATA(fog) || BUFFER_OR_DATA(depth) || BUFFER_OR_DATA(sample))) {
3565 FIXME("Extended attributes are only valid with vertex shaders\n");
3567 #undef BUFFER_OR_DATA
3570 static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3571 BOOL useVertexShaderFunction = FALSE, updateFog = FALSE;
3572 BOOL usePixelShaderFunction = stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE && stateblock->pixelShader
3573 && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function;
3574 BOOL transformed;
3575 /* Some stuff is in the device until we have per context tracking */
3576 IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
3577 BOOL wasrhw = context->last_was_rhw;
3579 /* Shaders can be implemented using ARB_PROGRAM, GLSL, or software -
3580 * here simply check whether a shader was set, or the user disabled shaders
3582 if (device->vs_selected_mode != SHADER_NONE && stateblock->vertexShader &&
3583 ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function != NULL) {
3584 useVertexShaderFunction = TRUE;
3586 if(((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.reg_maps.fog != context->last_was_foggy_shader) {
3587 updateFog = TRUE;
3589 } else if(context->last_was_foggy_shader) {
3590 updateFog = TRUE;
3593 handleStreams(stateblock, useVertexShaderFunction, context);
3595 transformed = device->strided_streams.u.s.position_transformed;
3596 if (transformed) useVertexShaderFunction = FALSE;
3598 if(transformed != context->last_was_rhw && !useVertexShaderFunction) {
3599 updateFog = TRUE;
3602 /* Reapply lighting if it is not scheduled for reapplication already */
3603 if(!isStateDirty(context, STATE_RENDER(WINED3DRS_LIGHTING))) {
3604 state_lighting(STATE_RENDER(WINED3DRS_LIGHTING), stateblock, context);
3607 if (transformed) {
3608 context->last_was_rhw = TRUE;
3609 } else {
3611 /* Untransformed, so relies on the view and projection matrices */
3612 context->last_was_rhw = FALSE;
3613 /* This turns off the Z scale trick to 'disable' viewport frustum clipping in rhw mode*/
3614 device->untransformed = TRUE;
3616 /* Todo for sw shaders: Vertex Shader output is already transformed, so set up identity matrices
3617 * Not needed as long as only hw shaders are supported
3620 /* This sets the shader output position correction constants.
3621 * TODO: Move to the viewport state
3623 if (useVertexShaderFunction) {
3624 device->posFixup[1] = device->render_offscreen ? -1.0 : 1.0;
3625 device->posFixup[3] = -device->posFixup[1] / stateblock->viewport.Height;
3629 /* Don't have to apply the matrices when vertex shaders are used. When vshaders are turned
3630 * off this function will be called again anyway to make sure they're properly set
3632 if(!useVertexShaderFunction) {
3633 /* TODO: Move this mainly to the viewport state and only apply when the vp has changed
3634 * or transformed / untransformed was switched
3636 if(wasrhw != context->last_was_rhw &&
3637 !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION)) &&
3638 !isStateDirty(context, STATE_VIEWPORT)) {
3639 transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context);
3641 /* World matrix needs reapplication here only if we're switching between rhw and non-rhw
3642 * mode.
3644 * If a vertex shader is used, the world matrix changed and then vertex shader unbound
3645 * this check will fail and the matrix not applied again. This is OK because a simple
3646 * world matrix change reapplies the matrix - These checks here are only to satisfy the
3647 * needs of the vertex declaration.
3649 * World and view matrix go into the same gl matrix, so only apply them when neither is
3650 * dirty
3652 if(transformed != wasrhw &&
3653 !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0))) &&
3654 !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW))) {
3655 transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context);
3658 if(!isStateDirty(context, STATE_RENDER(WINED3DRS_COLORVERTEX))) {
3659 state_colormat(STATE_RENDER(WINED3DRS_COLORVERTEX), stateblock, context);
3662 if(context->last_was_vshader && !isStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPLANEENABLE))) {
3663 state_clipping(STATE_RENDER(WINED3DRS_CLIPPLANEENABLE), stateblock, context);
3665 if(!isStateDirty(context, STATE_RENDER(WINED3DRS_NORMALIZENORMALS))) {
3666 state_normalize(STATE_RENDER(WINED3DRS_NORMALIZENORMALS), stateblock, context);
3668 } else {
3669 /* We compile the shader here because we need the vertex declaration
3670 * in order to determine if we need to do any swizzling for D3DCOLOR
3671 * registers. If the shader is already compiled this call will do nothing. */
3672 IWineD3DVertexShader_CompileShader(stateblock->vertexShader);
3674 if(!context->last_was_vshader) {
3675 int i;
3676 static BOOL warned = FALSE;
3677 /* Disable all clip planes to get defined results on all drivers. See comment in the
3678 * state_clipping state handler
3680 for(i = 0; i < GL_LIMITS(clipplanes); i++) {
3681 glDisable(GL_CLIP_PLANE0 + i);
3682 checkGLcall("glDisable(GL_CLIP_PLANE0 + i)");
3685 if(!warned && stateblock->renderState[WINED3DRS_CLIPPLANEENABLE]) {
3686 FIXME("Clipping not supported with vertex shaders\n");
3687 warned = TRUE;
3689 if(wasrhw) {
3690 /* Apply the transform matrices when switching from rhw drawing to vertex shaders. Vertex
3691 * shaders themselves do not need it, but the matrices are not reapplied automatically when
3692 * switching back from vertex shaders to fixed function processing. So make sure we leave the
3693 * fixed function vertex processing states back in a sane state before switching to shaders
3695 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
3696 transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context);
3698 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)))) {
3699 transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context);
3705 /* Vertex and pixel shaders are applied together for now, so let the last dirty state do the
3706 * application
3708 if (!isStateDirty(context, STATE_PIXELSHADER)) {
3709 device->shader_backend->shader_select((IWineD3DDevice *)device, usePixelShaderFunction, useVertexShaderFunction);
3711 if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (useVertexShaderFunction || usePixelShaderFunction)) {
3712 shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock, context);
3716 context->last_was_vshader = useVertexShaderFunction;
3718 if(updateFog) {
3719 state_fog(STATE_RENDER(WINED3DRS_FOGENABLE), stateblock, context);
3721 if(!useVertexShaderFunction) {
3722 int i;
3723 for(i = 0; i < MAX_TEXTURES; i++) {
3724 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + i))) {
3725 transform_texture(STATE_TRANSFORM(WINED3DTS_TEXTURE0 + i), stateblock, context);
3731 static void viewport(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3732 UINT width, height;
3733 IWineD3DSurfaceImpl *target;
3735 glDepthRange(stateblock->viewport.MinZ, stateblock->viewport.MaxZ);
3736 checkGLcall("glDepthRange");
3737 /* Note: GL requires lower left, DirectX supplies upper left. This is reversed when using offscreen rendering
3739 if(stateblock->wineD3DDevice->render_offscreen) {
3740 glViewport(stateblock->viewport.X,
3741 stateblock->viewport.Y,
3742 stateblock->viewport.Width, stateblock->viewport.Height);
3743 } else {
3744 target = (IWineD3DSurfaceImpl *) stateblock->wineD3DDevice->render_targets[0];
3745 target->get_drawable_size(target, &width, &height);
3747 glViewport(stateblock->viewport.X,
3748 (height - (stateblock->viewport.Y + stateblock->viewport.Height)),
3749 stateblock->viewport.Width, stateblock->viewport.Height);
3752 checkGLcall("glViewport");
3754 stateblock->wineD3DDevice->posFixup[2] = 1.0 / stateblock->viewport.Width;
3755 stateblock->wineD3DDevice->posFixup[3] = -stateblock->wineD3DDevice->posFixup[1] / stateblock->viewport.Height;
3756 if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
3757 transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context);
3759 if(!isStateDirty(context, STATE_RENDER(WINED3DRS_POINTSCALEENABLE))) {
3760 state_pscale(STATE_RENDER(WINED3DRS_POINTSCALEENABLE), stateblock, context);
3764 static void light(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3765 UINT Index = state - STATE_ACTIVELIGHT(0);
3766 PLIGHTINFOEL *lightInfo = stateblock->activeLights[Index];
3768 if(!lightInfo) {
3769 glDisable(GL_LIGHT0 + Index);
3770 checkGLcall("glDisable(GL_LIGHT0 + Index)");
3771 } else {
3772 float quad_att;
3773 float colRGBA[] = {0.0, 0.0, 0.0, 0.0};
3775 /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
3776 glMatrixMode(GL_MODELVIEW);
3777 glPushMatrix();
3778 glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
3780 /* Diffuse: */
3781 colRGBA[0] = lightInfo->OriginalParms.Diffuse.r;
3782 colRGBA[1] = lightInfo->OriginalParms.Diffuse.g;
3783 colRGBA[2] = lightInfo->OriginalParms.Diffuse.b;
3784 colRGBA[3] = lightInfo->OriginalParms.Diffuse.a;
3785 glLightfv(GL_LIGHT0 + Index, GL_DIFFUSE, colRGBA);
3786 checkGLcall("glLightfv");
3788 /* Specular */
3789 colRGBA[0] = lightInfo->OriginalParms.Specular.r;
3790 colRGBA[1] = lightInfo->OriginalParms.Specular.g;
3791 colRGBA[2] = lightInfo->OriginalParms.Specular.b;
3792 colRGBA[3] = lightInfo->OriginalParms.Specular.a;
3793 glLightfv(GL_LIGHT0 + Index, GL_SPECULAR, colRGBA);
3794 checkGLcall("glLightfv");
3796 /* Ambient */
3797 colRGBA[0] = lightInfo->OriginalParms.Ambient.r;
3798 colRGBA[1] = lightInfo->OriginalParms.Ambient.g;
3799 colRGBA[2] = lightInfo->OriginalParms.Ambient.b;
3800 colRGBA[3] = lightInfo->OriginalParms.Ambient.a;
3801 glLightfv(GL_LIGHT0 + Index, GL_AMBIENT, colRGBA);
3802 checkGLcall("glLightfv");
3804 if ((lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range) >= FLT_MIN) {
3805 quad_att = 1.4/(lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range);
3806 } else {
3807 quad_att = 0; /* 0 or MAX? (0 seems to be ok) */
3810 /* Do not assign attenuation values for lights that do not use them. D3D apps are free to pass any junk,
3811 * but gl drivers use them and may crash due to bad Attenuation values. Need for Speed most wanted sets
3812 * Attenuation0 to NaN and crashes in the gl lib
3815 switch (lightInfo->OriginalParms.Type) {
3816 case WINED3DLIGHT_POINT:
3817 /* Position */
3818 glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]);
3819 checkGLcall("glLightfv");
3820 glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
3821 checkGLcall("glLightf");
3822 /* Attenuation - Are these right? guessing... */
3823 glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION, lightInfo->OriginalParms.Attenuation0);
3824 checkGLcall("glLightf");
3825 glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION, lightInfo->OriginalParms.Attenuation1);
3826 checkGLcall("glLightf");
3827 if (quad_att < lightInfo->OriginalParms.Attenuation2) quad_att = lightInfo->OriginalParms.Attenuation2;
3828 glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
3829 checkGLcall("glLightf");
3830 /* FIXME: Range */
3831 break;
3833 case WINED3DLIGHT_SPOT:
3834 /* Position */
3835 glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]);
3836 checkGLcall("glLightfv");
3837 /* Direction */
3838 glLightfv(GL_LIGHT0 + Index, GL_SPOT_DIRECTION, &lightInfo->lightDirn[0]);
3839 checkGLcall("glLightfv");
3840 glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, lightInfo->exponent);
3841 checkGLcall("glLightf");
3842 glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
3843 checkGLcall("glLightf");
3844 /* Attenuation - Are these right? guessing... */
3845 glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION, lightInfo->OriginalParms.Attenuation0);
3846 checkGLcall("glLightf");
3847 glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION, lightInfo->OriginalParms.Attenuation1);
3848 checkGLcall("glLightf");
3849 if (quad_att < lightInfo->OriginalParms.Attenuation2) quad_att = lightInfo->OriginalParms.Attenuation2;
3850 glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
3851 checkGLcall("glLightf");
3852 /* FIXME: Range */
3853 break;
3855 case WINED3DLIGHT_DIRECTIONAL:
3856 /* Direction */
3857 glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]); /* Note gl uses w position of 0 for direction! */
3858 checkGLcall("glLightfv");
3859 glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
3860 checkGLcall("glLightf");
3861 glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, 0.0f);
3862 checkGLcall("glLightf");
3863 break;
3865 default:
3866 FIXME("Unrecognized light type %d\n", lightInfo->OriginalParms.Type);
3869 /* Restore the modelview matrix */
3870 glPopMatrix();
3872 glEnable(GL_LIGHT0 + Index);
3873 checkGLcall("glEnable(GL_LIGHT0 + Index)");
3876 return;
3879 static void scissorrect(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3880 RECT *pRect = &stateblock->scissorRect;
3881 UINT height;
3882 UINT width;
3883 IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *) stateblock->wineD3DDevice->render_targets[0];
3885 target->get_drawable_size(target, &width, &height);
3886 /* Warning: glScissor uses window coordinates, not viewport coordinates, so our viewport correction does not apply
3887 * Warning2: Even in windowed mode the coords are relative to the window, not the screen
3889 TRACE("(%p) Setting new Scissor Rect to %d:%d-%d:%d\n", stateblock->wineD3DDevice, pRect->left, pRect->bottom - height,
3890 pRect->right - pRect->left, pRect->bottom - pRect->top);
3892 if (stateblock->wineD3DDevice->render_offscreen) {
3893 glScissor(pRect->left, pRect->top, pRect->right - pRect->left, pRect->bottom - pRect->top);
3894 } else {
3895 glScissor(pRect->left, height - pRect->bottom, pRect->right - pRect->left, pRect->bottom - pRect->top);
3897 checkGLcall("glScissor");
3900 static void indexbuffer(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3901 if(GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT)) {
3902 if(stateblock->streamIsUP || stateblock->pIndexData == NULL ) {
3903 GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
3904 } else {
3905 IWineD3DIndexBufferImpl *ib = (IWineD3DIndexBufferImpl *) stateblock->pIndexData;
3906 GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib->vbo));
3911 static void frontface(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
3912 if(stateblock->wineD3DDevice->render_offscreen) {
3913 glFrontFace(GL_CCW);
3914 checkGLcall("glFrontFace(GL_CCW)");
3915 } else {
3916 glFrontFace(GL_CW);
3917 checkGLcall("glFrontFace(GL_CW)");
3921 const struct StateEntry StateTable[] =
3923 /* State name representative, apply function */
3924 { /* 0, Undefined */ 0, state_undefined },
3925 { /* 1, WINED3DRS_TEXTUREHANDLE */ 0 /* Handled in ddraw */, state_undefined },
3926 { /* 2, WINED3DRS_ANTIALIAS */ STATE_RENDER(WINED3DRS_ANTIALIAS), state_antialias },
3927 { /* 3, WINED3DRS_TEXTUREADDRESS */ 0 /* Handled in ddraw */, state_undefined },
3928 { /* 4, WINED3DRS_TEXTUREPERSPECTIVE */ STATE_RENDER(WINED3DRS_TEXTUREPERSPECTIVE), state_perspective },
3929 { /* 5, WINED3DRS_WRAPU */ STATE_RENDER(WINED3DRS_WRAPU), state_wrapu },
3930 { /* 6, WINED3DRS_WRAPV */ STATE_RENDER(WINED3DRS_WRAPV), state_wrapv },
3931 { /* 7, WINED3DRS_ZENABLE */ STATE_RENDER(WINED3DRS_ZENABLE), state_zenable },
3932 { /* 8, WINED3DRS_FILLMODE */ STATE_RENDER(WINED3DRS_FILLMODE), state_fillmode },
3933 { /* 9, WINED3DRS_SHADEMODE */ STATE_RENDER(WINED3DRS_SHADEMODE), state_shademode },
3934 { /* 10, WINED3DRS_LINEPATTERN */ STATE_RENDER(WINED3DRS_LINEPATTERN), state_linepattern },
3935 { /* 11, WINED3DRS_MONOENABLE */ STATE_RENDER(WINED3DRS_MONOENABLE), state_monoenable },
3936 { /* 12, WINED3DRS_ROP2 */ STATE_RENDER(WINED3DRS_ROP2), state_rop2 },
3937 { /* 13, WINED3DRS_PLANEMASK */ STATE_RENDER(WINED3DRS_PLANEMASK), state_planemask },
3938 { /* 14, WINED3DRS_ZWRITEENABLE */ STATE_RENDER(WINED3DRS_ZWRITEENABLE), state_zwritenable },
3939 { /* 15, WINED3DRS_ALPHATESTENABLE */ STATE_RENDER(WINED3DRS_ALPHATESTENABLE), state_alpha },
3940 { /* 16, WINED3DRS_LASTPIXEL */ STATE_RENDER(WINED3DRS_LASTPIXEL), state_lastpixel },
3941 { /* 17, WINED3DRS_TEXTUREMAG */ 0 /* Handled in ddraw */, state_undefined },
3942 { /* 18, WINED3DRS_TEXTUREMIN */ 0 /* Handled in ddraw */, state_undefined },
3943 { /* 19, WINED3DRS_SRCBLEND */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
3944 { /* 20, WINED3DRS_DESTBLEND */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
3945 { /* 21, WINED3DRS_TEXTUREMAPBLEND */ 0 /* Handled in ddraw */, state_undefined },
3946 { /* 22, WINED3DRS_CULLMODE */ STATE_RENDER(WINED3DRS_CULLMODE), state_cullmode },
3947 { /* 23, WINED3DRS_ZFUNC */ STATE_RENDER(WINED3DRS_ZFUNC), state_zfunc },
3948 { /* 24, WINED3DRS_ALPHAREF */ STATE_RENDER(WINED3DRS_ALPHATESTENABLE), state_alpha },
3949 { /* 25, WINED3DRS_ALPHAFUNC */ STATE_RENDER(WINED3DRS_ALPHATESTENABLE), state_alpha },
3950 { /* 26, WINED3DRS_DITHERENABLE */ STATE_RENDER(WINED3DRS_DITHERENABLE), state_ditherenable },
3951 { /* 27, WINED3DRS_ALPHABLENDENABLE */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
3952 { /* 28, WINED3DRS_FOGENABLE */ STATE_RENDER(WINED3DRS_FOGENABLE), state_fog },
3953 { /* 29, WINED3DRS_SPECULARENABLE */ STATE_RENDER(WINED3DRS_SPECULARENABLE), state_specularenable},
3954 { /* 30, WINED3DRS_ZVISIBLE */ 0 /* Not supported according to the msdn */, state_nogl },
3955 { /* 31, WINED3DRS_SUBPIXEL */ STATE_RENDER(WINED3DRS_SUBPIXEL), state_subpixel },
3956 { /* 32, WINED3DRS_SUBPIXELX */ STATE_RENDER(WINED3DRS_SUBPIXELX), state_subpixelx },
3957 { /* 33, WINED3DRS_STIPPLEDALPHA */ STATE_RENDER(WINED3DRS_STIPPLEDALPHA), state_stippledalpha },
3958 { /* 34, WINED3DRS_FOGCOLOR */ STATE_RENDER(WINED3DRS_FOGCOLOR), state_fogcolor },
3959 { /* 35, WINED3DRS_FOGTABLEMODE */ STATE_RENDER(WINED3DRS_FOGENABLE), state_fog },
3960 { /* 36, WINED3DRS_FOGSTART */ STATE_RENDER(WINED3DRS_FOGENABLE), state_fog },
3961 { /* 37, WINED3DRS_FOGEND */ STATE_RENDER(WINED3DRS_FOGENABLE), state_fog },
3962 { /* 38, WINED3DRS_FOGDENSITY */ STATE_RENDER(WINED3DRS_FOGDENSITY), state_fogdensity },
3963 { /* 39, WINED3DRS_STIPPLEENABLE */ STATE_RENDER(WINED3DRS_STIPPLEENABLE), state_stippleenable },
3964 { /* 40, WINED3DRS_EDGEANTIALIAS */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
3965 { /* 41, WINED3DRS_COLORKEYENABLE */ STATE_RENDER(WINED3DRS_ALPHATESTENABLE), state_alpha },
3966 { /* 42, undefined */ 0, state_undefined },
3967 { /* 43, WINED3DRS_BORDERCOLOR */ STATE_RENDER(WINED3DRS_BORDERCOLOR), state_bordercolor },
3968 { /* 44, WINED3DRS_TEXTUREADDRESSU */ 0, /* Handled in ddraw */ state_undefined },
3969 { /* 45, WINED3DRS_TEXTUREADDRESSV */ 0, /* Handled in ddraw */ state_undefined },
3970 { /* 46, WINED3DRS_MIPMAPLODBIAS */ STATE_RENDER(WINED3DRS_MIPMAPLODBIAS), state_mipmaplodbias },
3971 { /* 47, WINED3DRS_ZBIAS */ STATE_RENDER(WINED3DRS_ZBIAS), state_zbias },
3972 { /* 48, WINED3DRS_RANGEFOGENABLE */ STATE_RENDER(WINED3DRS_RANGEFOGENABLE), state_rangefog },
3973 { /* 49, WINED3DRS_ANISOTROPY */ STATE_RENDER(WINED3DRS_ANISOTROPY), state_anisotropy },
3974 { /* 50, WINED3DRS_FLUSHBATCH */ STATE_RENDER(WINED3DRS_FLUSHBATCH), state_flushbatch },
3975 { /* 51, WINED3DRS_TRANSLUCENTSORTINDEPENDENT */ STATE_RENDER(WINED3DRS_TRANSLUCENTSORTINDEPENDENT), state_translucentsi },
3976 { /* 52, WINED3DRS_STENCILENABLE */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
3977 { /* 53, WINED3DRS_STENCILFAIL */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
3978 { /* 54, WINED3DRS_STENCILZFAIL */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
3979 { /* 55, WINED3DRS_STENCILPASS */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
3980 { /* 56, WINED3DRS_STENCILFUNC */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
3981 { /* 57, WINED3DRS_STENCILREF */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
3982 { /* 58, WINED3DRS_STENCILMASK */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
3983 { /* 59, WINED3DRS_STENCILWRITEMASK */ STATE_RENDER(WINED3DRS_STENCILWRITEMASK), state_stencilwrite },
3984 { /* 60, WINED3DRS_TEXTUREFACTOR */ STATE_RENDER(WINED3DRS_TEXTUREFACTOR), state_texfactor },
3985 { /* 61, Undefined */ 0, state_undefined },
3986 { /* 62, Undefined */ 0, state_undefined },
3987 { /* 63, Undefined */ 0, state_undefined },
3988 { /* 64, WINED3DRS_STIPPLEPATTERN00 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3989 { /* 65, WINED3DRS_STIPPLEPATTERN01 */ 0 /* Obsolete, should he handled by ddraw */, state_undefined },
3990 { /* 66, WINED3DRS_STIPPLEPATTERN02 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3991 { /* 67, WINED3DRS_STIPPLEPATTERN03 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3992 { /* 68, WINED3DRS_STIPPLEPATTERN04 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3993 { /* 69, WINED3DRS_STIPPLEPATTERN05 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3994 { /* 70, WINED3DRS_STIPPLEPATTERN06 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3995 { /* 71, WINED3DRS_STIPPLEPATTERN07 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3996 { /* 72, WINED3DRS_STIPPLEPATTERN08 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3997 { /* 73, WINED3DRS_STIPPLEPATTERN09 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3998 { /* 74, WINED3DRS_STIPPLEPATTERN10 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
3999 { /* 75, WINED3DRS_STIPPLEPATTERN11 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4000 { /* 76, WINED3DRS_STIPPLEPATTERN12 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4001 { /* 77, WINED3DRS_STIPPLEPATTERN13 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4002 { /* 78, WINED3DRS_STIPPLEPATTERN14 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4003 { /* 79, WINED3DRS_STIPPLEPATTERN15 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4004 { /* 80, WINED3DRS_STIPPLEPATTERN16 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4005 { /* 81, WINED3DRS_STIPPLEPATTERN17 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4006 { /* 82, WINED3DRS_STIPPLEPATTERN18 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4007 { /* 83, WINED3DRS_STIPPLEPATTERN19 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4008 { /* 84, WINED3DRS_STIPPLEPATTERN20 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4009 { /* 85, WINED3DRS_STIPPLEPATTERN21 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4010 { /* 86, WINED3DRS_STIPPLEPATTERN22 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4011 { /* 87, WINED3DRS_STIPPLEPATTERN23 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4012 { /* 88, WINED3DRS_STIPPLEPATTERN24 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4013 { /* 89, WINED3DRS_STIPPLEPATTERN25 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4014 { /* 90, WINED3DRS_STIPPLEPATTERN26 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4015 { /* 91, WINED3DRS_STIPPLEPATTERN27 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4016 { /* 92, WINED3DRS_STIPPLEPATTERN28 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4017 { /* 93, WINED3DRS_STIPPLEPATTERN29 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4018 { /* 94, WINED3DRS_STIPPLEPATTERN30 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4019 { /* 95, WINED3DRS_STIPPLEPATTERN31 */ 0 /* Obsolete, should be handled by ddraw */, state_undefined },
4020 { /* 96, Undefined */ 0, state_undefined },
4021 { /* 97, Undefined */ 0, state_undefined },
4022 { /* 98, Undefined */ 0, state_undefined },
4023 { /* 99, Undefined */ 0, state_undefined },
4024 { /*100, Undefined */ 0, state_undefined },
4025 { /*101, Undefined */ 0, state_undefined },
4026 { /*102, Undefined */ 0, state_undefined },
4027 { /*103, Undefined */ 0, state_undefined },
4028 { /*104, Undefined */ 0, state_undefined },
4029 { /*105, Undefined */ 0, state_undefined },
4030 { /*106, Undefined */ 0, state_undefined },
4031 { /*107, Undefined */ 0, state_undefined },
4032 { /*108, Undefined */ 0, state_undefined },
4033 { /*109, Undefined */ 0, state_undefined },
4034 { /*110, Undefined */ 0, state_undefined },
4035 { /*111, Undefined */ 0, state_undefined },
4036 { /*112, Undefined */ 0, state_undefined },
4037 { /*113, Undefined */ 0, state_undefined },
4038 { /*114, Undefined */ 0, state_undefined },
4039 { /*115, Undefined */ 0, state_undefined },
4040 { /*116, Undefined */ 0, state_undefined },
4041 { /*117, Undefined */ 0, state_undefined },
4042 { /*118, Undefined */ 0, state_undefined },
4043 { /*119, Undefined */ 0, state_undefined },
4044 { /*120, Undefined */ 0, state_undefined },
4045 { /*121, Undefined */ 0, state_undefined },
4046 { /*122, Undefined */ 0, state_undefined },
4047 { /*123, Undefined */ 0, state_undefined },
4048 { /*124, Undefined */ 0, state_undefined },
4049 { /*125, Undefined */ 0, state_undefined },
4050 { /*126, Undefined */ 0, state_undefined },
4051 { /*127, Undefined */ 0, state_undefined },
4052 /* Big hole ends */
4053 { /*128, WINED3DRS_WRAP0 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4054 { /*129, WINED3DRS_WRAP1 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4055 { /*130, WINED3DRS_WRAP2 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4056 { /*131, WINED3DRS_WRAP3 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4057 { /*132, WINED3DRS_WRAP4 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4058 { /*133, WINED3DRS_WRAP5 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4059 { /*134, WINED3DRS_WRAP6 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4060 { /*135, WINED3DRS_WRAP7 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4061 { /*136, WINED3DRS_CLIPPING */ STATE_RENDER(WINED3DRS_CLIPPING), state_clipping },
4062 { /*137, WINED3DRS_LIGHTING */ STATE_RENDER(WINED3DRS_LIGHTING), state_lighting },
4063 { /*138, WINED3DRS_EXTENTS */ STATE_RENDER(WINED3DRS_EXTENTS), state_extents },
4064 { /*139, WINED3DRS_AMBIENT */ STATE_RENDER(WINED3DRS_AMBIENT), state_ambient },
4065 { /*140, WINED3DRS_FOGVERTEXMODE */ STATE_RENDER(WINED3DRS_FOGENABLE), state_fog },
4066 { /*141, WINED3DRS_COLORVERTEX */ STATE_RENDER(WINED3DRS_COLORVERTEX), state_colormat },
4067 { /*142, WINED3DRS_LOCALVIEWER */ STATE_RENDER(WINED3DRS_LOCALVIEWER), state_localviewer },
4068 { /*143, WINED3DRS_NORMALIZENORMALS */ STATE_RENDER(WINED3DRS_NORMALIZENORMALS), state_normalize },
4069 { /*144, WINED3DRS_COLORKEYBLENDENABLE */ STATE_RENDER(WINED3DRS_COLORKEYBLENDENABLE), state_ckeyblend },
4070 { /*145, WINED3DRS_DIFFUSEMATERIALSOURCE */ STATE_RENDER(WINED3DRS_COLORVERTEX), state_colormat },
4071 { /*146, WINED3DRS_SPECULARMATERIALSOURCE */ STATE_RENDER(WINED3DRS_COLORVERTEX), state_colormat },
4072 { /*147, WINED3DRS_AMBIENTMATERIALSOURCE */ STATE_RENDER(WINED3DRS_COLORVERTEX), state_colormat },
4073 { /*148, WINED3DRS_EMISSIVEMATERIALSOURCE */ STATE_RENDER(WINED3DRS_COLORVERTEX), state_colormat },
4074 { /*149, Undefined */ 0, state_undefined },
4075 { /*150, Undefined */ 0, state_undefined },
4076 { /*151, WINED3DRS_VERTEXBLEND */ STATE_RENDER(WINED3DRS_VERTEXBLEND), state_vertexblend },
4077 { /*152, WINED3DRS_CLIPPLANEENABLE */ STATE_RENDER(WINED3DRS_CLIPPING), state_clipping },
4078 { /*153, WINED3DRS_SOFTWAREVERTEXPROCESSING */ 0, state_nogl },
4079 { /*154, WINED3DRS_POINTSIZE */ STATE_RENDER(WINED3DRS_POINTSCALEENABLE), state_pscale },
4080 { /*155, WINED3DRS_POINTSIZE_MIN */ STATE_RENDER(WINED3DRS_POINTSIZE_MIN), state_psizemin },
4081 { /*156, WINED3DRS_POINTSPRITEENABLE */ STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), state_pointsprite },
4082 { /*157, WINED3DRS_POINTSCALEENABLE */ STATE_RENDER(WINED3DRS_POINTSCALEENABLE), state_pscale },
4083 { /*158, WINED3DRS_POINTSCALE_A */ STATE_RENDER(WINED3DRS_POINTSCALEENABLE), state_pscale },
4084 { /*159, WINED3DRS_POINTSCALE_B */ STATE_RENDER(WINED3DRS_POINTSCALEENABLE), state_pscale },
4085 { /*160, WINED3DRS_POINTSCALE_C */ STATE_RENDER(WINED3DRS_POINTSCALEENABLE), state_pscale },
4086 { /*161, WINED3DRS_MULTISAMPLEANTIALIAS */ STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS), state_multisampleaa },
4087 { /*162, WINED3DRS_MULTISAMPLEMASK */ STATE_RENDER(WINED3DRS_MULTISAMPLEMASK), state_multisampmask },
4088 { /*163, WINED3DRS_PATCHEDGESTYLE */ STATE_RENDER(WINED3DRS_PATCHEDGESTYLE), state_patchedgestyle},
4089 { /*164, WINED3DRS_PATCHSEGMENTS */ STATE_RENDER(WINED3DRS_PATCHSEGMENTS), state_patchsegments },
4090 { /*165, WINED3DRS_DEBUGMONITORTOKEN */ STATE_RENDER(WINED3DRS_DEBUGMONITORTOKEN), state_nogl },
4091 { /*166, WINED3DRS_POINTSIZE_MAX */ STATE_RENDER(WINED3DRS_POINTSIZE_MAX), state_psizemax },
4092 { /*167, WINED3DRS_INDEXEDVERTEXBLENDENABLE */ 0, state_nogl },
4093 { /*168, WINED3DRS_COLORWRITEENABLE */ STATE_RENDER(WINED3DRS_COLORWRITEENABLE), state_colorwrite },
4094 { /*169, Undefined */ 0, state_undefined },
4095 { /*170, WINED3DRS_TWEENFACTOR */ 0, state_nogl },
4096 { /*171, WINED3DRS_BLENDOP */ STATE_RENDER(WINED3DRS_BLENDOP), state_blendop },
4097 { /*172, WINED3DRS_POSITIONDEGREE */ STATE_RENDER(WINED3DRS_POSITIONDEGREE), state_positiondegree},
4098 { /*173, WINED3DRS_NORMALDEGREE */ STATE_RENDER(WINED3DRS_NORMALDEGREE), state_normaldegree },
4099 /*172, WINED3DRS_POSITIONORDER */ /* Value assigned to 2 state names */
4100 /*173, WINED3DRS_NORMALORDER */ /* Value assigned to 2 state names */
4101 { /*174, WINED3DRS_SCISSORTESTENABLE */ STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), state_scissor },
4102 { /*175, WINED3DRS_SLOPESCALEDEPTHBIAS */ STATE_RENDER(WINED3DRS_DEPTHBIAS), state_depthbias },
4103 { /*176, WINED3DRS_ANTIALIASEDLINEENABLE */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
4104 { /*177, undefined */ 0, state_undefined },
4105 { /*178, WINED3DRS_MINTESSELLATIONLEVEL */ STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation },
4106 { /*179, WINED3DRS_MAXTESSELLATIONLEVEL */ STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation },
4107 { /*180, WINED3DRS_ADAPTIVETESS_X */ STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation },
4108 { /*181, WINED3DRS_ADAPTIVETESS_Y */ STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation },
4109 { /*182, WINED3DRS_ADAPTIVETESS_Z */ STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation },
4110 { /*183, WINED3DRS_ADAPTIVETESS_W */ STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation },
4111 { /*184, WINED3DRS_ENABLEADAPTIVETESSELLATION */ STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation },
4112 { /*185, WINED3DRS_TWOSIDEDSTENCILMODE */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
4113 { /*186, WINED3DRS_CCW_STENCILFAIL */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
4114 { /*187, WINED3DRS_CCW_STENCILZFAIL */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
4115 { /*188, WINED3DRS_CCW_STENCILPASS */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
4116 { /*189, WINED3DRS_CCW_STENCILFUNC */ STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil },
4117 { /*190, WINED3DRS_COLORWRITEENABLE1 */ STATE_RENDER(WINED3DRS_COLORWRITEENABLE), state_colorwrite },
4118 { /*191, WINED3DRS_COLORWRITEENABLE2 */ STATE_RENDER(WINED3DRS_COLORWRITEENABLE), state_colorwrite },
4119 { /*192, WINED3DRS_COLORWRITEENABLE3 */ STATE_RENDER(WINED3DRS_COLORWRITEENABLE), state_colorwrite },
4120 { /*193, WINED3DRS_BLENDFACTOR */ STATE_RENDER(WINED3DRS_BLENDFACTOR), state_blendfactor },
4121 { /*194, WINED3DRS_SRGBWRITEENABLE */ STATE_PIXELSHADER, pixelshader },
4122 { /*195, WINED3DRS_DEPTHBIAS */ STATE_RENDER(WINED3DRS_DEPTHBIAS), state_depthbias },
4123 { /*196, undefined */ 0, state_undefined },
4124 { /*197, undefined */ 0, state_undefined },
4125 { /*198, WINED3DRS_WRAP8 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4126 { /*199, WINED3DRS_WRAP9 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4127 { /*200, WINED3DRS_WRAP10 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4128 { /*201, WINED3DRS_WRAP11 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4129 { /*202, WINED3DRS_WRAP12 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4130 { /*203, WINED3DRS_WRAP13 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4131 { /*204, WINED3DRS_WRAP14 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4132 { /*205, WINED3DRS_WRAP15 */ STATE_RENDER(WINED3DRS_WRAP0), state_wrap },
4133 { /*206, WINED3DRS_SEPARATEALPHABLENDENABLE */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
4134 { /*207, WINED3DRS_SRCBLENDALPHA */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
4135 { /*208, WINED3DRS_DESTBLENDALPHA */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend },
4136 { /*209, WINED3DRS_BLENDOPALPHA */ STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blendop },
4137 /* Texture stage states */
4138 { /*0, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), tex_colorop },
4139 { /*0, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), tex_colorop },
4140 { /*0, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), tex_colorop },
4141 { /*0, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop },
4142 { /*0, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop },
4143 { /*0, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop },
4144 { /*0, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4145 { /*0, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4146 { /*0, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4147 { /*0, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4148 { /*0, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(0, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4149 { /*0, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4150 { /*0, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4151 { /*0, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4152 { /*0, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4153 { /*0, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4154 { /*0, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4155 { /*0, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4156 { /*0, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4157 { /*0, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4158 { /*0, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4159 { /*0, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4160 { /*0, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4161 { /*0, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE0), transform_texture },
4162 { /*0, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4163 { /*0, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), tex_colorop },
4164 { /*0, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop },
4165 { /*0, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), tex_resultarg },
4166 { /*0, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4167 { /*0, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4168 { /*0, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4169 { /*0, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4171 { /*1, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), tex_colorop },
4172 { /*1, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), tex_colorop },
4173 { /*1, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), tex_colorop },
4174 { /*1, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop },
4175 { /*1, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop },
4176 { /*1, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop },
4177 { /*1, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4178 { /*1, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4179 { /*1, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4180 { /*1, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4181 { /*1, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(1, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4182 { /*1, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4183 { /*1, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4184 { /*1, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4185 { /*1, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4186 { /*1, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4187 { /*1, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4188 { /*1, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4189 { /*1, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4190 { /*1, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4191 { /*1, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4192 { /*1, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4193 { /*1, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4194 { /*1, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE1), transform_texture },
4195 { /*1, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4196 { /*1, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), tex_colorop },
4197 { /*1, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop },
4198 { /*1, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), tex_resultarg },
4199 { /*1, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4200 { /*1, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4201 { /*1, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4202 { /*1, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4204 { /*2, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), tex_colorop },
4205 { /*2, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), tex_colorop },
4206 { /*2, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), tex_colorop },
4207 { /*2, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop },
4208 { /*2, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop },
4209 { /*2, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop },
4210 { /*2, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4211 { /*2, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4212 { /*2, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4213 { /*2, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4214 { /*2, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(2, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4215 { /*2, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4216 { /*2, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4217 { /*2, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4218 { /*2, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4219 { /*2, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4220 { /*2, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4221 { /*2, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4222 { /*2, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4223 { /*2, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4224 { /*2, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4225 { /*2, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4226 { /*2, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4227 { /*2, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE2), transform_texture },
4228 { /*2, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4229 { /*2, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), tex_colorop },
4230 { /*2, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop },
4231 { /*2, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), tex_resultarg },
4232 { /*2, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4233 { /*2, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4234 { /*2, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4235 { /*2, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4237 { /*3, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), tex_colorop },
4238 { /*3, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), tex_colorop },
4239 { /*3, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), tex_colorop },
4240 { /*3, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop },
4241 { /*3, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop },
4242 { /*3, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop },
4243 { /*3, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4244 { /*3, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4245 { /*3, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4246 { /*3, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4247 { /*3, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(3, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4248 { /*3, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4249 { /*3, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4250 { /*3, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4251 { /*3, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4252 { /*3, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4253 { /*3, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4254 { /*3, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4255 { /*3, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4256 { /*3, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4257 { /*3, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4258 { /*3, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4259 { /*3, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4260 { /*3, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE3), transform_texture },
4261 { /*3, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4262 { /*3, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), tex_colorop },
4263 { /*3, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop },
4264 { /*3, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), tex_resultarg },
4265 { /*3, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4266 { /*3, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4267 { /*3, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4268 { /*3, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4270 { /*4, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), tex_colorop },
4271 { /*4, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), tex_colorop },
4272 { /*4, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), tex_colorop },
4273 { /*4, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop },
4274 { /*4, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop },
4275 { /*4, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop },
4276 { /*4, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4277 { /*4, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4278 { /*4, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4279 { /*4, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4280 { /*4, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(4, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4281 { /*4, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4282 { /*4, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4283 { /*4, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4284 { /*4, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4285 { /*4, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4286 { /*4, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4287 { /*4, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4288 { /*4, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4289 { /*4, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4290 { /*4, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4291 { /*4, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4292 { /*4, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4293 { /*4, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE4), transform_texture },
4294 { /*4, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4295 { /*4, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), tex_colorop },
4296 { /*4, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop },
4297 { /*4, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), tex_resultarg },
4298 { /*4, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4299 { /*4, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4300 { /*4, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4301 { /*4, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4303 { /*5, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), tex_colorop },
4304 { /*5, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), tex_colorop },
4305 { /*5, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), tex_colorop },
4306 { /*5, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop },
4307 { /*5, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop },
4308 { /*5, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop },
4309 { /*5, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4310 { /*5, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4311 { /*5, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4312 { /*5, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4313 { /*5, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(5, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4314 { /*5, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4315 { /*5, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4316 { /*5, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4317 { /*5, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4318 { /*5, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4319 { /*5, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4320 { /*5, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4321 { /*5, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4322 { /*5, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4323 { /*5, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4324 { /*5, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4325 { /*5, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4326 { /*5, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE5), transform_texture },
4327 { /*5, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4328 { /*5, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), tex_colorop },
4329 { /*5, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop },
4330 { /*5, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), tex_resultarg },
4331 { /*5, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4332 { /*5, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4333 { /*5, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4334 { /*5, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4336 { /*6, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), tex_colorop },
4337 { /*6, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), tex_colorop },
4338 { /*6, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), tex_colorop },
4339 { /*6, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop },
4340 { /*6, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop },
4341 { /*6, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop },
4342 { /*6, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4343 { /*6, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4344 { /*6, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4345 { /*6, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4346 { /*6, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(6, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4347 { /*6, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4348 { /*6, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4349 { /*6, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4350 { /*6, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4351 { /*6, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4352 { /*6, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4353 { /*6, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4354 { /*6, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4355 { /*6, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4356 { /*6, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4357 { /*6, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4358 { /*6, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4359 { /*6, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE6), transform_texture },
4360 { /*6, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4361 { /*6, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), tex_colorop },
4362 { /*6, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop },
4363 { /*6, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), tex_resultarg },
4364 { /*6, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4365 { /*6, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4366 { /*6, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4367 { /*6, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4369 { /*7, 01, WINED3DTSS_COLOROP */ STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), tex_colorop },
4370 { /*7, 02, WINED3DTSS_COLORARG1 */ STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), tex_colorop },
4371 { /*7, 03, WINED3DTSS_COLORARG2 */ STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), tex_colorop },
4372 { /*7, 04, WINED3DTSS_ALPHAOP */ STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop },
4373 { /*7, 05, WINED3DTSS_ALPHAARG1 */ STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop },
4374 { /*7, 06, WINED3DTSS_ALPHAARG2 */ STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop },
4375 { /*7, 07, WINED3DTSS_BUMPENVMAT00 */ STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4376 { /*7, 08, WINED3DTSS_BUMPENVMAT01 */ STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4377 { /*7, 09, WINED3DTSS_BUMPENVMAT10 */ STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4378 { /*7, 10, WINED3DTSS_BUMPENVMAT11 */ STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), tex_bumpenvmat },
4379 { /*7, 11, WINED3DTSS_TEXCOORDINDEX */ STATE_TEXTURESTAGE(7, WINED3DTSS_TEXCOORDINDEX), tex_coordindex },
4380 { /*7, 12, WINED3DTSS_ADDRESS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4381 { /*7, 13, WINED3DTSS_ADDRESSU */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4382 { /*7, 14, WINED3DTSS_ADDRESSV */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4383 { /*7, 15, WINED3DTSS_BORDERCOLOR */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4384 { /*7, 16, WINED3DTSS_MAGFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4385 { /*7, 17, WINED3DTSS_MINFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4386 { /*7, 18, WINED3DTSS_MIPFILTER */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4387 { /*7, 19, WINED3DTSS_MIPMAPLODBIAS */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4388 { /*7, 20, WINED3DTSS_MAXMIPLEVEL */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4389 { /*7, 21, WINED3DTSS_MAXANISOTROPY */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4390 { /*7, 22, WINED3DTSS_BUMPENVLSCALE */ STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale },
4391 { /*7, 23, WINED3DTSS_BUMPENVLOFFSET */ STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLOFFSET), tex_bumpenvloffset },
4392 { /*7, 24, WINED3DTSS_TEXTURETRANSFORMFLAGS */ STATE_TRANSFORM(WINED3DTS_TEXTURE7), transform_texture },
4393 { /*7, 25, WINED3DTSS_ADDRESSW */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4394 { /*7, 26, WINED3DTSS_COLORARG0 */ STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), tex_colorop },
4395 { /*7, 27, WINED3DTSS_ALPHAARG0 */ STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop },
4396 { /*7, 28, WINED3DTSS_RESULTARG */ STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), tex_resultarg },
4397 { /*7, 29, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4398 { /*7, 30, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4399 { /*7, 31, undefined */ 0 /* -> sampler state in ddraw / d3d8 */, state_undefined },
4400 { /*7, 32, WINED3DTSS_CONSTANT */ 0 /* As long as we don't support D3DTA_CONSTANT */, state_nogl },
4401 /* Sampler states */
4402 { /* 0, Sampler 0 */ STATE_SAMPLER(0), sampler },
4403 { /* 1, Sampler 1 */ STATE_SAMPLER(1), sampler },
4404 { /* 2, Sampler 2 */ STATE_SAMPLER(2), sampler },
4405 { /* 3, Sampler 3 */ STATE_SAMPLER(3), sampler },
4406 { /* 4, Sampler 3 */ STATE_SAMPLER(4), sampler },
4407 { /* 5, Sampler 5 */ STATE_SAMPLER(5), sampler },
4408 { /* 6, Sampler 6 */ STATE_SAMPLER(6), sampler },
4409 { /* 7, Sampler 7 */ STATE_SAMPLER(7), sampler },
4410 { /* 8, Sampler 8 */ STATE_SAMPLER(8), sampler },
4411 { /* 9, Sampler 9 */ STATE_SAMPLER(9), sampler },
4412 { /*10, Sampler 10 */ STATE_SAMPLER(10), sampler },
4413 { /*11, Sampler 11 */ STATE_SAMPLER(11), sampler },
4414 { /*12, Sampler 12 */ STATE_SAMPLER(12), sampler },
4415 { /*13, Sampler 13 */ STATE_SAMPLER(13), sampler },
4416 { /*14, Sampler 14 */ STATE_SAMPLER(14), sampler },
4417 { /*15, Sampler 15 */ STATE_SAMPLER(15), sampler },
4418 { /*16, Vertex sampler 0 */ STATE_SAMPLER(16), sampler },
4419 { /*17, Vertex sampler 1 */ STATE_SAMPLER(17), sampler },
4420 { /*18, Vertex sampler 2 */ STATE_SAMPLER(18), sampler },
4421 { /*19, Vertex sampler 3 */ STATE_SAMPLER(19), sampler },
4422 /* Pixel shader */
4423 { /* , Pixel Shader */ STATE_PIXELSHADER, pixelshader },
4424 /* Transform states follow */
4425 { /* 1, undefined */ 0, state_undefined },
4426 { /* 2, WINED3DTS_VIEW */ STATE_TRANSFORM(WINED3DTS_VIEW), transform_view },
4427 { /* 3, WINED3DTS_PROJECTION */ STATE_TRANSFORM(WINED3DTS_PROJECTION), transform_projection},
4428 { /* 4, undefined */ 0, state_undefined },
4429 { /* 5, undefined */ 0, state_undefined },
4430 { /* 6, undefined */ 0, state_undefined },
4431 { /* 7, undefined */ 0, state_undefined },
4432 { /* 8, undefined */ 0, state_undefined },
4433 { /* 9, undefined */ 0, state_undefined },
4434 { /* 10, undefined */ 0, state_undefined },
4435 { /* 11, undefined */ 0, state_undefined },
4436 { /* 12, undefined */ 0, state_undefined },
4437 { /* 13, undefined */ 0, state_undefined },
4438 { /* 14, undefined */ 0, state_undefined },
4439 { /* 15, undefined */ 0, state_undefined },
4440 { /* 16, WINED3DTS_TEXTURE0 */ STATE_TRANSFORM(WINED3DTS_TEXTURE0), transform_texture },
4441 { /* 17, WINED3DTS_TEXTURE1 */ STATE_TRANSFORM(WINED3DTS_TEXTURE1), transform_texture },
4442 { /* 18, WINED3DTS_TEXTURE2 */ STATE_TRANSFORM(WINED3DTS_TEXTURE2), transform_texture },
4443 { /* 19, WINED3DTS_TEXTURE3 */ STATE_TRANSFORM(WINED3DTS_TEXTURE3), transform_texture },
4444 { /* 20, WINED3DTS_TEXTURE4 */ STATE_TRANSFORM(WINED3DTS_TEXTURE4), transform_texture },
4445 { /* 21, WINED3DTS_TEXTURE5 */ STATE_TRANSFORM(WINED3DTS_TEXTURE5), transform_texture },
4446 { /* 22, WINED3DTS_TEXTURE6 */ STATE_TRANSFORM(WINED3DTS_TEXTURE6), transform_texture },
4447 { /* 23, WINED3DTS_TEXTURE7 */ STATE_TRANSFORM(WINED3DTS_TEXTURE7), transform_texture },
4448 /* A huge gap between TEXTURE7 and WORLDMATRIX(0) :-( But entries are needed to catch then if a broken app sets them */
4449 { /* 24, undefined */ 0, state_undefined },
4450 { /* 25, undefined */ 0, state_undefined },
4451 { /* 26, undefined */ 0, state_undefined },
4452 { /* 27, undefined */ 0, state_undefined },
4453 { /* 28, undefined */ 0, state_undefined },
4454 { /* 29, undefined */ 0, state_undefined },
4455 { /* 30, undefined */ 0, state_undefined },
4456 { /* 31, undefined */ 0, state_undefined },
4457 { /* 32, undefined */ 0, state_undefined },
4458 { /* 33, undefined */ 0, state_undefined },
4459 { /* 34, undefined */ 0, state_undefined },
4460 { /* 35, undefined */ 0, state_undefined },
4461 { /* 36, undefined */ 0, state_undefined },
4462 { /* 37, undefined */ 0, state_undefined },
4463 { /* 38, undefined */ 0, state_undefined },
4464 { /* 39, undefined */ 0, state_undefined },
4465 { /* 40, undefined */ 0, state_undefined },
4466 { /* 41, undefined */ 0, state_undefined },
4467 { /* 42, undefined */ 0, state_undefined },
4468 { /* 43, undefined */ 0, state_undefined },
4469 { /* 44, undefined */ 0, state_undefined },
4470 { /* 45, undefined */ 0, state_undefined },
4471 { /* 46, undefined */ 0, state_undefined },
4472 { /* 47, undefined */ 0, state_undefined },
4473 { /* 48, undefined */ 0, state_undefined },
4474 { /* 49, undefined */ 0, state_undefined },
4475 { /* 50, undefined */ 0, state_undefined },
4476 { /* 51, undefined */ 0, state_undefined },
4477 { /* 52, undefined */ 0, state_undefined },
4478 { /* 53, undefined */ 0, state_undefined },
4479 { /* 54, undefined */ 0, state_undefined },
4480 { /* 55, undefined */ 0, state_undefined },
4481 { /* 56, undefined */ 0, state_undefined },
4482 { /* 57, undefined */ 0, state_undefined },
4483 { /* 58, undefined */ 0, state_undefined },
4484 { /* 59, undefined */ 0, state_undefined },
4485 { /* 60, undefined */ 0, state_undefined },
4486 { /* 61, undefined */ 0, state_undefined },
4487 { /* 62, undefined */ 0, state_undefined },
4488 { /* 63, undefined */ 0, state_undefined },
4489 { /* 64, undefined */ 0, state_undefined },
4490 { /* 65, undefined */ 0, state_undefined },
4491 { /* 66, undefined */ 0, state_undefined },
4492 { /* 67, undefined */ 0, state_undefined },
4493 { /* 68, undefined */ 0, state_undefined },
4494 { /* 69, undefined */ 0, state_undefined },
4495 { /* 70, undefined */ 0, state_undefined },
4496 { /* 71, undefined */ 0, state_undefined },
4497 { /* 72, undefined */ 0, state_undefined },
4498 { /* 73, undefined */ 0, state_undefined },
4499 { /* 74, undefined */ 0, state_undefined },
4500 { /* 75, undefined */ 0, state_undefined },
4501 { /* 76, undefined */ 0, state_undefined },
4502 { /* 77, undefined */ 0, state_undefined },
4503 { /* 78, undefined */ 0, state_undefined },
4504 { /* 79, undefined */ 0, state_undefined },
4505 { /* 80, undefined */ 0, state_undefined },
4506 { /* 81, undefined */ 0, state_undefined },
4507 { /* 82, undefined */ 0, state_undefined },
4508 { /* 83, undefined */ 0, state_undefined },
4509 { /* 84, undefined */ 0, state_undefined },
4510 { /* 85, undefined */ 0, state_undefined },
4511 { /* 86, undefined */ 0, state_undefined },
4512 { /* 87, undefined */ 0, state_undefined },
4513 { /* 88, undefined */ 0, state_undefined },
4514 { /* 89, undefined */ 0, state_undefined },
4515 { /* 90, undefined */ 0, state_undefined },
4516 { /* 91, undefined */ 0, state_undefined },
4517 { /* 92, undefined */ 0, state_undefined },
4518 { /* 93, undefined */ 0, state_undefined },
4519 { /* 94, undefined */ 0, state_undefined },
4520 { /* 95, undefined */ 0, state_undefined },
4521 { /* 96, undefined */ 0, state_undefined },
4522 { /* 97, undefined */ 0, state_undefined },
4523 { /* 98, undefined */ 0, state_undefined },
4524 { /* 99, undefined */ 0, state_undefined },
4525 { /*100, undefined */ 0, state_undefined },
4526 { /*101, undefined */ 0, state_undefined },
4527 { /*102, undefined */ 0, state_undefined },
4528 { /*103, undefined */ 0, state_undefined },
4529 { /*104, undefined */ 0, state_undefined },
4530 { /*105, undefined */ 0, state_undefined },
4531 { /*106, undefined */ 0, state_undefined },
4532 { /*107, undefined */ 0, state_undefined },
4533 { /*108, undefined */ 0, state_undefined },
4534 { /*109, undefined */ 0, state_undefined },
4535 { /*110, undefined */ 0, state_undefined },
4536 { /*111, undefined */ 0, state_undefined },
4537 { /*112, undefined */ 0, state_undefined },
4538 { /*113, undefined */ 0, state_undefined },
4539 { /*114, undefined */ 0, state_undefined },
4540 { /*115, undefined */ 0, state_undefined },
4541 { /*116, undefined */ 0, state_undefined },
4542 { /*117, undefined */ 0, state_undefined },
4543 { /*118, undefined */ 0, state_undefined },
4544 { /*119, undefined */ 0, state_undefined },
4545 { /*120, undefined */ 0, state_undefined },
4546 { /*121, undefined */ 0, state_undefined },
4547 { /*122, undefined */ 0, state_undefined },
4548 { /*123, undefined */ 0, state_undefined },
4549 { /*124, undefined */ 0, state_undefined },
4550 { /*125, undefined */ 0, state_undefined },
4551 { /*126, undefined */ 0, state_undefined },
4552 { /*127, undefined */ 0, state_undefined },
4553 { /*128, undefined */ 0, state_undefined },
4554 { /*129, undefined */ 0, state_undefined },
4555 { /*130, undefined */ 0, state_undefined },
4556 { /*131, undefined */ 0, state_undefined },
4557 { /*132, undefined */ 0, state_undefined },
4558 { /*133, undefined */ 0, state_undefined },
4559 { /*134, undefined */ 0, state_undefined },
4560 { /*135, undefined */ 0, state_undefined },
4561 { /*136, undefined */ 0, state_undefined },
4562 { /*137, undefined */ 0, state_undefined },
4563 { /*138, undefined */ 0, state_undefined },
4564 { /*139, undefined */ 0, state_undefined },
4565 { /*140, undefined */ 0, state_undefined },
4566 { /*141, undefined */ 0, state_undefined },
4567 { /*142, undefined */ 0, state_undefined },
4568 { /*143, undefined */ 0, state_undefined },
4569 { /*144, undefined */ 0, state_undefined },
4570 { /*145, undefined */ 0, state_undefined },
4571 { /*146, undefined */ 0, state_undefined },
4572 { /*147, undefined */ 0, state_undefined },
4573 { /*148, undefined */ 0, state_undefined },
4574 { /*149, undefined */ 0, state_undefined },
4575 { /*150, undefined */ 0, state_undefined },
4576 { /*151, undefined */ 0, state_undefined },
4577 { /*152, undefined */ 0, state_undefined },
4578 { /*153, undefined */ 0, state_undefined },
4579 { /*154, undefined */ 0, state_undefined },
4580 { /*155, undefined */ 0, state_undefined },
4581 { /*156, undefined */ 0, state_undefined },
4582 { /*157, undefined */ 0, state_undefined },
4583 { /*158, undefined */ 0, state_undefined },
4584 { /*159, undefined */ 0, state_undefined },
4585 { /*160, undefined */ 0, state_undefined },
4586 { /*161, undefined */ 0, state_undefined },
4587 { /*162, undefined */ 0, state_undefined },
4588 { /*163, undefined */ 0, state_undefined },
4589 { /*164, undefined */ 0, state_undefined },
4590 { /*165, undefined */ 0, state_undefined },
4591 { /*166, undefined */ 0, state_undefined },
4592 { /*167, undefined */ 0, state_undefined },
4593 { /*168, undefined */ 0, state_undefined },
4594 { /*169, undefined */ 0, state_undefined },
4595 { /*170, undefined */ 0, state_undefined },
4596 { /*171, undefined */ 0, state_undefined },
4597 { /*172, undefined */ 0, state_undefined },
4598 { /*173, undefined */ 0, state_undefined },
4599 { /*174, undefined */ 0, state_undefined },
4600 { /*175, undefined */ 0, state_undefined },
4601 { /*176, undefined */ 0, state_undefined },
4602 { /*177, undefined */ 0, state_undefined },
4603 { /*178, undefined */ 0, state_undefined },
4604 { /*179, undefined */ 0, state_undefined },
4605 { /*180, undefined */ 0, state_undefined },
4606 { /*181, undefined */ 0, state_undefined },
4607 { /*182, undefined */ 0, state_undefined },
4608 { /*183, undefined */ 0, state_undefined },
4609 { /*184, undefined */ 0, state_undefined },
4610 { /*185, undefined */ 0, state_undefined },
4611 { /*186, undefined */ 0, state_undefined },
4612 { /*187, undefined */ 0, state_undefined },
4613 { /*188, undefined */ 0, state_undefined },
4614 { /*189, undefined */ 0, state_undefined },
4615 { /*190, undefined */ 0, state_undefined },
4616 { /*191, undefined */ 0, state_undefined },
4617 { /*192, undefined */ 0, state_undefined },
4618 { /*193, undefined */ 0, state_undefined },
4619 { /*194, undefined */ 0, state_undefined },
4620 { /*195, undefined */ 0, state_undefined },
4621 { /*196, undefined */ 0, state_undefined },
4622 { /*197, undefined */ 0, state_undefined },
4623 { /*198, undefined */ 0, state_undefined },
4624 { /*199, undefined */ 0, state_undefined },
4625 { /*200, undefined */ 0, state_undefined },
4626 { /*201, undefined */ 0, state_undefined },
4627 { /*202, undefined */ 0, state_undefined },
4628 { /*203, undefined */ 0, state_undefined },
4629 { /*204, undefined */ 0, state_undefined },
4630 { /*205, undefined */ 0, state_undefined },
4631 { /*206, undefined */ 0, state_undefined },
4632 { /*207, undefined */ 0, state_undefined },
4633 { /*208, undefined */ 0, state_undefined },
4634 { /*209, undefined */ 0, state_undefined },
4635 { /*210, undefined */ 0, state_undefined },
4636 { /*211, undefined */ 0, state_undefined },
4637 { /*212, undefined */ 0, state_undefined },
4638 { /*213, undefined */ 0, state_undefined },
4639 { /*214, undefined */ 0, state_undefined },
4640 { /*215, undefined */ 0, state_undefined },
4641 { /*216, undefined */ 0, state_undefined },
4642 { /*217, undefined */ 0, state_undefined },
4643 { /*218, undefined */ 0, state_undefined },
4644 { /*219, undefined */ 0, state_undefined },
4645 { /*220, undefined */ 0, state_undefined },
4646 { /*221, undefined */ 0, state_undefined },
4647 { /*222, undefined */ 0, state_undefined },
4648 { /*223, undefined */ 0, state_undefined },
4649 { /*224, undefined */ 0, state_undefined },
4650 { /*225, undefined */ 0, state_undefined },
4651 { /*226, undefined */ 0, state_undefined },
4652 { /*227, undefined */ 0, state_undefined },
4653 { /*228, undefined */ 0, state_undefined },
4654 { /*229, undefined */ 0, state_undefined },
4655 { /*230, undefined */ 0, state_undefined },
4656 { /*231, undefined */ 0, state_undefined },
4657 { /*232, undefined */ 0, state_undefined },
4658 { /*233, undefined */ 0, state_undefined },
4659 { /*234, undefined */ 0, state_undefined },
4660 { /*235, undefined */ 0, state_undefined },
4661 { /*236, undefined */ 0, state_undefined },
4662 { /*237, undefined */ 0, state_undefined },
4663 { /*238, undefined */ 0, state_undefined },
4664 { /*239, undefined */ 0, state_undefined },
4665 { /*240, undefined */ 0, state_undefined },
4666 { /*241, undefined */ 0, state_undefined },
4667 { /*242, undefined */ 0, state_undefined },
4668 { /*243, undefined */ 0, state_undefined },
4669 { /*244, undefined */ 0, state_undefined },
4670 { /*245, undefined */ 0, state_undefined },
4671 { /*246, undefined */ 0, state_undefined },
4672 { /*247, undefined */ 0, state_undefined },
4673 { /*248, undefined */ 0, state_undefined },
4674 { /*249, undefined */ 0, state_undefined },
4675 { /*250, undefined */ 0, state_undefined },
4676 { /*251, undefined */ 0, state_undefined },
4677 { /*252, undefined */ 0, state_undefined },
4678 { /*253, undefined */ 0, state_undefined },
4679 { /*254, undefined */ 0, state_undefined },
4680 { /*255, undefined */ 0, state_undefined },
4681 /* End huge gap */
4682 { /*256, WINED3DTS_WORLDMATRIX(0) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), transform_world },
4683 { /*257, WINED3DTS_WORLDMATRIX(1) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(1)), transform_worldex },
4684 { /*258, WINED3DTS_WORLDMATRIX(2) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(2)), transform_worldex },
4685 { /*259, WINED3DTS_WORLDMATRIX(3) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(3)), transform_worldex },
4686 { /*260, WINED3DTS_WORLDMATRIX(4) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(4)), transform_worldex },
4687 { /*261, WINED3DTS_WORLDMATRIX(5) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(5)), transform_worldex },
4688 { /*262, WINED3DTS_WORLDMATRIX(6) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(6)), transform_worldex },
4689 { /*263, WINED3DTS_WORLDMATRIX(7) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(7)), transform_worldex },
4690 { /*264, WINED3DTS_WORLDMATRIX(8) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(8)), transform_worldex },
4691 { /*265, WINED3DTS_WORLDMATRIX(9) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(9)), transform_worldex },
4692 { /*266, WINED3DTS_WORLDMATRIX(10) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(10)), transform_worldex },
4693 { /*267, WINED3DTS_WORLDMATRIX(11) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(11)), transform_worldex },
4694 { /*268, WINED3DTS_WORLDMATRIX(12) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(12)), transform_worldex },
4695 { /*269, WINED3DTS_WORLDMATRIX(13) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(13)), transform_worldex },
4696 { /*270, WINED3DTS_WORLDMATRIX(14) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(14)), transform_worldex },
4697 { /*271, WINED3DTS_WORLDMATRIX(15) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(15)), transform_worldex },
4698 { /*272, WINED3DTS_WORLDMATRIX(16) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(16)), transform_worldex },
4699 { /*273, WINED3DTS_WORLDMATRIX(17) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(17)), transform_worldex },
4700 { /*274, WINED3DTS_WORLDMATRIX(18) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(18)), transform_worldex },
4701 { /*275, WINED3DTS_WORLDMATRIX(19) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(19)), transform_worldex },
4702 { /*276, WINED3DTS_WORLDMATRIX(20) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(20)), transform_worldex },
4703 { /*277, WINED3DTS_WORLDMATRIX(21) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(21)), transform_worldex },
4704 { /*278, WINED3DTS_WORLDMATRIX(22) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(22)), transform_worldex },
4705 { /*279, WINED3DTS_WORLDMATRIX(23) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(23)), transform_worldex },
4706 { /*280, WINED3DTS_WORLDMATRIX(24) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(24)), transform_worldex },
4707 { /*281, WINED3DTS_WORLDMATRIX(25) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(25)), transform_worldex },
4708 { /*282, WINED3DTS_WORLDMATRIX(26) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(26)), transform_worldex },
4709 { /*283, WINED3DTS_WORLDMATRIX(27) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(27)), transform_worldex },
4710 { /*284, WINED3DTS_WORLDMATRIX(28) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(28)), transform_worldex },
4711 { /*285, WINED3DTS_WORLDMATRIX(29) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(29)), transform_worldex },
4712 { /*286, WINED3DTS_WORLDMATRIX(30) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(30)), transform_worldex },
4713 { /*287, WINED3DTS_WORLDMATRIX(31) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(31)), transform_worldex },
4714 { /*288, WINED3DTS_WORLDMATRIX(32) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(32)), transform_worldex },
4715 { /*289, WINED3DTS_WORLDMATRIX(33) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(33)), transform_worldex },
4716 { /*290, WINED3DTS_WORLDMATRIX(34) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(34)), transform_worldex },
4717 { /*291, WINED3DTS_WORLDMATRIX(35) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(35)), transform_worldex },
4718 { /*292, WINED3DTS_WORLDMATRIX(36) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(36)), transform_worldex },
4719 { /*293, WINED3DTS_WORLDMATRIX(37) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(37)), transform_worldex },
4720 { /*294, WINED3DTS_WORLDMATRIX(38) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(38)), transform_worldex },
4721 { /*295, WINED3DTS_WORLDMATRIX(39) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(39)), transform_worldex },
4722 { /*296, WINED3DTS_WORLDMATRIX(40) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(40)), transform_worldex },
4723 { /*297, WINED3DTS_WORLDMATRIX(41) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(41)), transform_worldex },
4724 { /*298, WINED3DTS_WORLDMATRIX(42) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(42)), transform_worldex },
4725 { /*299, WINED3DTS_WORLDMATRIX(43) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(43)), transform_worldex },
4726 { /*300, WINED3DTS_WORLDMATRIX(44) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(44)), transform_worldex },
4727 { /*301, WINED3DTS_WORLDMATRIX(45) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(45)), transform_worldex },
4728 { /*302, WINED3DTS_WORLDMATRIX(46) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(46)), transform_worldex },
4729 { /*303, WINED3DTS_WORLDMATRIX(47) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(47)), transform_worldex },
4730 { /*304, WINED3DTS_WORLDMATRIX(48) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(48)), transform_worldex },
4731 { /*305, WINED3DTS_WORLDMATRIX(49) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(49)), transform_worldex },
4732 { /*306, WINED3DTS_WORLDMATRIX(50) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(50)), transform_worldex },
4733 { /*307, WINED3DTS_WORLDMATRIX(51) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(51)), transform_worldex },
4734 { /*308, WINED3DTS_WORLDMATRIX(52) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(52)), transform_worldex },
4735 { /*309, WINED3DTS_WORLDMATRIX(53) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(53)), transform_worldex },
4736 { /*310, WINED3DTS_WORLDMATRIX(54) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(54)), transform_worldex },
4737 { /*311, WINED3DTS_WORLDMATRIX(55) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(55)), transform_worldex },
4738 { /*312, WINED3DTS_WORLDMATRIX(56) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(56)), transform_worldex },
4739 { /*313, WINED3DTS_WORLDMATRIX(57) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(57)), transform_worldex },
4740 { /*314, WINED3DTS_WORLDMATRIX(58) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(58)), transform_worldex },
4741 { /*315, WINED3DTS_WORLDMATRIX(59) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(59)), transform_worldex },
4742 { /*316, WINED3DTS_WORLDMATRIX(60) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(60)), transform_worldex },
4743 { /*317, WINED3DTS_WORLDMATRIX(61) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(61)), transform_worldex },
4744 { /*318, WINED3DTS_WORLDMATRIX(62) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(62)), transform_worldex },
4745 { /*319, WINED3DTS_WORLDMATRIX(63) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(63)), transform_worldex },
4746 { /*320, WINED3DTS_WORLDMATRIX(64) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(64)), transform_worldex },
4747 { /*321, WINED3DTS_WORLDMATRIX(65) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(65)), transform_worldex },
4748 { /*322, WINED3DTS_WORLDMATRIX(66) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(66)), transform_worldex },
4749 { /*323, WINED3DTS_WORLDMATRIX(67) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(67)), transform_worldex },
4750 { /*324, WINED3DTS_WORLDMATRIX(68) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(68)), transform_worldex },
4751 { /*325, WINED3DTS_WORLDMATRIX(68) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(69)), transform_worldex },
4752 { /*326, WINED3DTS_WORLDMATRIX(70) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(70)), transform_worldex },
4753 { /*327, WINED3DTS_WORLDMATRIX(71) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(71)), transform_worldex },
4754 { /*328, WINED3DTS_WORLDMATRIX(72) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(72)), transform_worldex },
4755 { /*329, WINED3DTS_WORLDMATRIX(73) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(73)), transform_worldex },
4756 { /*330, WINED3DTS_WORLDMATRIX(74) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(74)), transform_worldex },
4757 { /*331, WINED3DTS_WORLDMATRIX(75) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(75)), transform_worldex },
4758 { /*332, WINED3DTS_WORLDMATRIX(76) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(76)), transform_worldex },
4759 { /*333, WINED3DTS_WORLDMATRIX(77) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(77)), transform_worldex },
4760 { /*334, WINED3DTS_WORLDMATRIX(78) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(78)), transform_worldex },
4761 { /*335, WINED3DTS_WORLDMATRIX(79) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(79)), transform_worldex },
4762 { /*336, WINED3DTS_WORLDMATRIX(80) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(80)), transform_worldex },
4763 { /*337, WINED3DTS_WORLDMATRIX(81) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(81)), transform_worldex },
4764 { /*338, WINED3DTS_WORLDMATRIX(82) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(82)), transform_worldex },
4765 { /*339, WINED3DTS_WORLDMATRIX(83) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(83)), transform_worldex },
4766 { /*340, WINED3DTS_WORLDMATRIX(84) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(84)), transform_worldex },
4767 { /*341, WINED3DTS_WORLDMATRIX(85) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(85)), transform_worldex },
4768 { /*341, WINED3DTS_WORLDMATRIX(86) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(86)), transform_worldex },
4769 { /*343, WINED3DTS_WORLDMATRIX(87) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(87)), transform_worldex },
4770 { /*344, WINED3DTS_WORLDMATRIX(88) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(88)), transform_worldex },
4771 { /*345, WINED3DTS_WORLDMATRIX(89) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(89)), transform_worldex },
4772 { /*346, WINED3DTS_WORLDMATRIX(90) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(90)), transform_worldex },
4773 { /*347, WINED3DTS_WORLDMATRIX(91) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(91)), transform_worldex },
4774 { /*348, WINED3DTS_WORLDMATRIX(92) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(92)), transform_worldex },
4775 { /*349, WINED3DTS_WORLDMATRIX(93) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(93)), transform_worldex },
4776 { /*350, WINED3DTS_WORLDMATRIX(94) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(94)), transform_worldex },
4777 { /*351, WINED3DTS_WORLDMATRIX(95) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(95)), transform_worldex },
4778 { /*352, WINED3DTS_WORLDMATRIX(96) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(96)), transform_worldex },
4779 { /*353, WINED3DTS_WORLDMATRIX(97) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(97)), transform_worldex },
4780 { /*354, WINED3DTS_WORLDMATRIX(98) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(98)), transform_worldex },
4781 { /*355, WINED3DTS_WORLDMATRIX(99) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(99)), transform_worldex },
4782 { /*356, WINED3DTS_WORLDMATRIX(100) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(100)), transform_worldex },
4783 { /*357, WINED3DTS_WORLDMATRIX(101) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(101)), transform_worldex },
4784 { /*358, WINED3DTS_WORLDMATRIX(102) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(102)), transform_worldex },
4785 { /*359, WINED3DTS_WORLDMATRIX(103) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(103)), transform_worldex },
4786 { /*360, WINED3DTS_WORLDMATRIX(104) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(104)), transform_worldex },
4787 { /*361, WINED3DTS_WORLDMATRIX(105) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(105)), transform_worldex },
4788 { /*362, WINED3DTS_WORLDMATRIX(106) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(106)), transform_worldex },
4789 { /*363, WINED3DTS_WORLDMATRIX(107) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(107)), transform_worldex },
4790 { /*364, WINED3DTS_WORLDMATRIX(108) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(108)), transform_worldex },
4791 { /*365, WINED3DTS_WORLDMATRIX(109) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(109)), transform_worldex },
4792 { /*366, WINED3DTS_WORLDMATRIX(110) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(110)), transform_worldex },
4793 { /*367, WINED3DTS_WORLDMATRIX(111) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(111)), transform_worldex },
4794 { /*368, WINED3DTS_WORLDMATRIX(112) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(112)), transform_worldex },
4795 { /*369, WINED3DTS_WORLDMATRIX(113) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(113)), transform_worldex },
4796 { /*370, WINED3DTS_WORLDMATRIX(114) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(114)), transform_worldex },
4797 { /*371, WINED3DTS_WORLDMATRIX(115) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(115)), transform_worldex },
4798 { /*372, WINED3DTS_WORLDMATRIX(116) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(116)), transform_worldex },
4799 { /*373, WINED3DTS_WORLDMATRIX(117) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(117)), transform_worldex },
4800 { /*374, WINED3DTS_WORLDMATRIX(118) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(118)), transform_worldex },
4801 { /*375, WINED3DTS_WORLDMATRIX(119) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(119)), transform_worldex },
4802 { /*376, WINED3DTS_WORLDMATRIX(120) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(120)), transform_worldex },
4803 { /*377, WINED3DTS_WORLDMATRIX(121) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(121)), transform_worldex },
4804 { /*378, WINED3DTS_WORLDMATRIX(122) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(122)), transform_worldex },
4805 { /*379, WINED3DTS_WORLDMATRIX(123) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(123)), transform_worldex },
4806 { /*380, WINED3DTS_WORLDMATRIX(124) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(124)), transform_worldex },
4807 { /*381, WINED3DTS_WORLDMATRIX(125) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(125)), transform_worldex },
4808 { /*382, WINED3DTS_WORLDMATRIX(126) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(126)), transform_worldex },
4809 { /*383, WINED3DTS_WORLDMATRIX(127) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(127)), transform_worldex },
4810 { /*384, WINED3DTS_WORLDMATRIX(128) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(128)), transform_worldex },
4811 { /*385, WINED3DTS_WORLDMATRIX(129) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(129)), transform_worldex },
4812 { /*386, WINED3DTS_WORLDMATRIX(130) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(130)), transform_worldex },
4813 { /*387, WINED3DTS_WORLDMATRIX(131) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(131)), transform_worldex },
4814 { /*388, WINED3DTS_WORLDMATRIX(132) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(132)), transform_worldex },
4815 { /*389, WINED3DTS_WORLDMATRIX(133) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(133)), transform_worldex },
4816 { /*390, WINED3DTS_WORLDMATRIX(134) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(134)), transform_worldex },
4817 { /*391, WINED3DTS_WORLDMATRIX(135) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(135)), transform_worldex },
4818 { /*392, WINED3DTS_WORLDMATRIX(136) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(136)), transform_worldex },
4819 { /*393, WINED3DTS_WORLDMATRIX(137) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(137)), transform_worldex },
4820 { /*394, WINED3DTS_WORLDMATRIX(138) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(138)), transform_worldex },
4821 { /*395, WINED3DTS_WORLDMATRIX(139) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(139)), transform_worldex },
4822 { /*396, WINED3DTS_WORLDMATRIX(140) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(140)), transform_worldex },
4823 { /*397, WINED3DTS_WORLDMATRIX(141) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(141)), transform_worldex },
4824 { /*398, WINED3DTS_WORLDMATRIX(142) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(142)), transform_worldex },
4825 { /*399, WINED3DTS_WORLDMATRIX(143) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(143)), transform_worldex },
4826 { /*400, WINED3DTS_WORLDMATRIX(144) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(144)), transform_worldex },
4827 { /*401, WINED3DTS_WORLDMATRIX(145) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(145)), transform_worldex },
4828 { /*402, WINED3DTS_WORLDMATRIX(146) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(146)), transform_worldex },
4829 { /*403, WINED3DTS_WORLDMATRIX(147) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(147)), transform_worldex },
4830 { /*404, WINED3DTS_WORLDMATRIX(148) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(148)), transform_worldex },
4831 { /*405, WINED3DTS_WORLDMATRIX(149) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(149)), transform_worldex },
4832 { /*406, WINED3DTS_WORLDMATRIX(150) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(150)), transform_worldex },
4833 { /*407, WINED3DTS_WORLDMATRIX(151) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(151)), transform_worldex },
4834 { /*408, WINED3DTS_WORLDMATRIX(152) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(152)), transform_worldex },
4835 { /*409, WINED3DTS_WORLDMATRIX(153) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(153)), transform_worldex },
4836 { /*410, WINED3DTS_WORLDMATRIX(154) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(154)), transform_worldex },
4837 { /*411, WINED3DTS_WORLDMATRIX(155) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(155)), transform_worldex },
4838 { /*412, WINED3DTS_WORLDMATRIX(156) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(156)), transform_worldex },
4839 { /*413, WINED3DTS_WORLDMATRIX(157) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(157)), transform_worldex },
4840 { /*414, WINED3DTS_WORLDMATRIX(158) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(158)), transform_worldex },
4841 { /*415, WINED3DTS_WORLDMATRIX(159) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(159)), transform_worldex },
4842 { /*416, WINED3DTS_WORLDMATRIX(160) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(160)), transform_worldex },
4843 { /*417, WINED3DTS_WORLDMATRIX(161) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(161)), transform_worldex },
4844 { /*418, WINED3DTS_WORLDMATRIX(162) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(162)), transform_worldex },
4845 { /*419, WINED3DTS_WORLDMATRIX(163) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(163)), transform_worldex },
4846 { /*420, WINED3DTS_WORLDMATRIX(164) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(164)), transform_worldex },
4847 { /*421, WINED3DTS_WORLDMATRIX(165) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(165)), transform_worldex },
4848 { /*422, WINED3DTS_WORLDMATRIX(166) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(166)), transform_worldex },
4849 { /*423, WINED3DTS_WORLDMATRIX(167) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(167)), transform_worldex },
4850 { /*424, WINED3DTS_WORLDMATRIX(168) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(168)), transform_worldex },
4851 { /*425, WINED3DTS_WORLDMATRIX(168) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(169)), transform_worldex },
4852 { /*426, WINED3DTS_WORLDMATRIX(170) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(170)), transform_worldex },
4853 { /*427, WINED3DTS_WORLDMATRIX(171) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(171)), transform_worldex },
4854 { /*428, WINED3DTS_WORLDMATRIX(172) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(172)), transform_worldex },
4855 { /*429, WINED3DTS_WORLDMATRIX(173) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(173)), transform_worldex },
4856 { /*430, WINED3DTS_WORLDMATRIX(174) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(174)), transform_worldex },
4857 { /*431, WINED3DTS_WORLDMATRIX(175) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(175)), transform_worldex },
4858 { /*432, WINED3DTS_WORLDMATRIX(176) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(176)), transform_worldex },
4859 { /*433, WINED3DTS_WORLDMATRIX(177) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(177)), transform_worldex },
4860 { /*434, WINED3DTS_WORLDMATRIX(178) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(178)), transform_worldex },
4861 { /*435, WINED3DTS_WORLDMATRIX(179) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(179)), transform_worldex },
4862 { /*436, WINED3DTS_WORLDMATRIX(180) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(180)), transform_worldex },
4863 { /*437, WINED3DTS_WORLDMATRIX(181) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(181)), transform_worldex },
4864 { /*438, WINED3DTS_WORLDMATRIX(182) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(182)), transform_worldex },
4865 { /*439, WINED3DTS_WORLDMATRIX(183) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(183)), transform_worldex },
4866 { /*440, WINED3DTS_WORLDMATRIX(184) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(184)), transform_worldex },
4867 { /*441, WINED3DTS_WORLDMATRIX(185) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(185)), transform_worldex },
4868 { /*441, WINED3DTS_WORLDMATRIX(186) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(186)), transform_worldex },
4869 { /*443, WINED3DTS_WORLDMATRIX(187) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(187)), transform_worldex },
4870 { /*444, WINED3DTS_WORLDMATRIX(188) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(188)), transform_worldex },
4871 { /*445, WINED3DTS_WORLDMATRIX(189) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(189)), transform_worldex },
4872 { /*446, WINED3DTS_WORLDMATRIX(190) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(190)), transform_worldex },
4873 { /*447, WINED3DTS_WORLDMATRIX(191) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(191)), transform_worldex },
4874 { /*448, WINED3DTS_WORLDMATRIX(192) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(192)), transform_worldex },
4875 { /*449, WINED3DTS_WORLDMATRIX(193) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(193)), transform_worldex },
4876 { /*450, WINED3DTS_WORLDMATRIX(194) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(194)), transform_worldex },
4877 { /*451, WINED3DTS_WORLDMATRIX(195) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(195)), transform_worldex },
4878 { /*452, WINED3DTS_WORLDMATRIX(196) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(196)), transform_worldex },
4879 { /*453, WINED3DTS_WORLDMATRIX(197) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(197)), transform_worldex },
4880 { /*454, WINED3DTS_WORLDMATRIX(198) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(198)), transform_worldex },
4881 { /*455, WINED3DTS_WORLDMATRIX(199) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(199)), transform_worldex },
4882 { /*356, WINED3DTS_WORLDMATRIX(200) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(200)), transform_worldex },
4883 { /*457, WINED3DTS_WORLDMATRIX(201) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(201)), transform_worldex },
4884 { /*458, WINED3DTS_WORLDMATRIX(202) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(202)), transform_worldex },
4885 { /*459, WINED3DTS_WORLDMATRIX(203) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(203)), transform_worldex },
4886 { /*460, WINED3DTS_WORLDMATRIX(204) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(204)), transform_worldex },
4887 { /*461, WINED3DTS_WORLDMATRIX(205) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(205)), transform_worldex },
4888 { /*462, WINED3DTS_WORLDMATRIX(206) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(206)), transform_worldex },
4889 { /*463, WINED3DTS_WORLDMATRIX(207) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(207)), transform_worldex },
4890 { /*464, WINED3DTS_WORLDMATRIX(208) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(208)), transform_worldex },
4891 { /*465, WINED3DTS_WORLDMATRIX(209) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(209)), transform_worldex },
4892 { /*466, WINED3DTS_WORLDMATRIX(210) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(210)), transform_worldex },
4893 { /*467, WINED3DTS_WORLDMATRIX(211) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(211)), transform_worldex },
4894 { /*468, WINED3DTS_WORLDMATRIX(212) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(212)), transform_worldex },
4895 { /*469, WINED3DTS_WORLDMATRIX(213) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(213)), transform_worldex },
4896 { /*470, WINED3DTS_WORLDMATRIX(214) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(214)), transform_worldex },
4897 { /*471, WINED3DTS_WORLDMATRIX(215) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(215)), transform_worldex },
4898 { /*472, WINED3DTS_WORLDMATRIX(216) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(216)), transform_worldex },
4899 { /*473, WINED3DTS_WORLDMATRIX(217) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(217)), transform_worldex },
4900 { /*474, WINED3DTS_WORLDMATRIX(218) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(218)), transform_worldex },
4901 { /*475, WINED3DTS_WORLDMATRIX(219) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(219)), transform_worldex },
4902 { /*476, WINED3DTS_WORLDMATRIX(220) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(220)), transform_worldex },
4903 { /*477, WINED3DTS_WORLDMATRIX(221) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(221)), transform_worldex },
4904 { /*478, WINED3DTS_WORLDMATRIX(222) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(222)), transform_worldex },
4905 { /*479, WINED3DTS_WORLDMATRIX(223) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(223)), transform_worldex },
4906 { /*480, WINED3DTS_WORLDMATRIX(224) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(224)), transform_worldex },
4907 { /*481, WINED3DTS_WORLDMATRIX(225) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(225)), transform_worldex },
4908 { /*482, WINED3DTS_WORLDMATRIX(226) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(226)), transform_worldex },
4909 { /*483, WINED3DTS_WORLDMATRIX(227) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(227)), transform_worldex },
4910 { /*484, WINED3DTS_WORLDMATRIX(228) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(228)), transform_worldex },
4911 { /*485, WINED3DTS_WORLDMATRIX(229) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(229)), transform_worldex },
4912 { /*486, WINED3DTS_WORLDMATRIX(230) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(230)), transform_worldex },
4913 { /*487, WINED3DTS_WORLDMATRIX(231) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(231)), transform_worldex },
4914 { /*488, WINED3DTS_WORLDMATRIX(232) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(232)), transform_worldex },
4915 { /*489, WINED3DTS_WORLDMATRIX(233) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(233)), transform_worldex },
4916 { /*490, WINED3DTS_WORLDMATRIX(234) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(234)), transform_worldex },
4917 { /*491, WINED3DTS_WORLDMATRIX(235) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(235)), transform_worldex },
4918 { /*492, WINED3DTS_WORLDMATRIX(236) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(236)), transform_worldex },
4919 { /*493, WINED3DTS_WORLDMATRIX(237) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(237)), transform_worldex },
4920 { /*494, WINED3DTS_WORLDMATRIX(238) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(238)), transform_worldex },
4921 { /*495, WINED3DTS_WORLDMATRIX(239) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(239)), transform_worldex },
4922 { /*496, WINED3DTS_WORLDMATRIX(240) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(240)), transform_worldex },
4923 { /*497, WINED3DTS_WORLDMATRIX(241) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(241)), transform_worldex },
4924 { /*498, WINED3DTS_WORLDMATRIX(242) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(242)), transform_worldex },
4925 { /*499, WINED3DTS_WORLDMATRIX(243) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(243)), transform_worldex },
4926 { /*500, WINED3DTS_WORLDMATRIX(244) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(244)), transform_worldex },
4927 { /*501, WINED3DTS_WORLDMATRIX(245) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(245)), transform_worldex },
4928 { /*502, WINED3DTS_WORLDMATRIX(246) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(246)), transform_worldex },
4929 { /*503, WINED3DTS_WORLDMATRIX(247) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(247)), transform_worldex },
4930 { /*504, WINED3DTS_WORLDMATRIX(248) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(248)), transform_worldex },
4931 { /*505, WINED3DTS_WORLDMATRIX(249) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(249)), transform_worldex },
4932 { /*506, WINED3DTS_WORLDMATRIX(250) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(250)), transform_worldex },
4933 { /*507, WINED3DTS_WORLDMATRIX(251) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(251)), transform_worldex },
4934 { /*508, WINED3DTS_WORLDMATRIX(252) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(252)), transform_worldex },
4935 { /*509, WINED3DTS_WORLDMATRIX(253) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(253)), transform_worldex },
4936 { /*510, WINED3DTS_WORLDMATRIX(254) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(254)), transform_worldex },
4937 { /*511, WINED3DTS_WORLDMATRIX(255) */ STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)), transform_worldex },
4938 /* Various Vertex states follow */
4939 { /* , STATE_STREAMSRC */ STATE_VDECL, vertexdeclaration },
4940 { /* , STATE_INDEXBUFFER */ STATE_INDEXBUFFER, indexbuffer },
4941 { /* , STATE_VDECL */ STATE_VDECL, vertexdeclaration },
4942 { /* , STATE_VSHADER */ STATE_VDECL, vertexdeclaration },
4943 { /* , STATE_VIEWPORT */ STATE_VIEWPORT, viewport },
4944 { /* , STATE_VERTEXSHADERCONSTANT */ STATE_VERTEXSHADERCONSTANT, shaderconstant },
4945 { /* , STATE_PIXELSHADERCONSTANT */ STATE_VERTEXSHADERCONSTANT, shaderconstant },
4946 /* Lights */
4947 { /* , STATE_ACTIVELIGHT(0) */ STATE_ACTIVELIGHT(0), light },
4948 { /* , STATE_ACTIVELIGHT(1) */ STATE_ACTIVELIGHT(1), light },
4949 { /* , STATE_ACTIVELIGHT(2) */ STATE_ACTIVELIGHT(2), light },
4950 { /* , STATE_ACTIVELIGHT(3) */ STATE_ACTIVELIGHT(3), light },
4951 { /* , STATE_ACTIVELIGHT(4) */ STATE_ACTIVELIGHT(4), light },
4952 { /* , STATE_ACTIVELIGHT(5) */ STATE_ACTIVELIGHT(5), light },
4953 { /* , STATE_ACTIVELIGHT(6) */ STATE_ACTIVELIGHT(6), light },
4954 { /* , STATE_ACTIVELIGHT(7) */ STATE_ACTIVELIGHT(7), light },
4956 { /* Scissor rect */ STATE_SCISSORRECT, scissorrect },
4957 /* Clip planes */
4958 { /* STATE_CLIPPLANE(0) */ STATE_CLIPPLANE(0), clipplane },
4959 { /* STATE_CLIPPLANE(1) */ STATE_CLIPPLANE(1), clipplane },
4960 { /* STATE_CLIPPLANE(2) */ STATE_CLIPPLANE(2), clipplane },
4961 { /* STATE_CLIPPLANE(3) */ STATE_CLIPPLANE(3), clipplane },
4962 { /* STATE_CLIPPLANE(4) */ STATE_CLIPPLANE(4), clipplane },
4963 { /* STATE_CLIPPLANE(5) */ STATE_CLIPPLANE(5), clipplane },
4964 { /* STATE_CLIPPLANE(6) */ STATE_CLIPPLANE(6), clipplane },
4965 { /* STATE_CLIPPLANE(7) */ STATE_CLIPPLANE(7), clipplane },
4966 { /* STATE_CLIPPLANE(8) */ STATE_CLIPPLANE(8), clipplane },
4967 { /* STATE_CLIPPLANE(9) */ STATE_CLIPPLANE(9), clipplane },
4968 { /* STATE_CLIPPLANE(10) */ STATE_CLIPPLANE(10), clipplane },
4969 { /* STATE_CLIPPLANE(11) */ STATE_CLIPPLANE(11), clipplane },
4970 { /* STATE_CLIPPLANE(12) */ STATE_CLIPPLANE(12), clipplane },
4971 { /* STATE_CLIPPLANE(13) */ STATE_CLIPPLANE(13), clipplane },
4972 { /* STATE_CLIPPLANE(14) */ STATE_CLIPPLANE(14), clipplane },
4973 { /* STATE_CLIPPLANE(15) */ STATE_CLIPPLANE(15), clipplane },
4974 { /* STATE_CLIPPLANE(16) */ STATE_CLIPPLANE(16), clipplane },
4975 { /* STATE_CLIPPLANE(17) */ STATE_CLIPPLANE(17), clipplane },
4976 { /* STATE_CLIPPLANE(18) */ STATE_CLIPPLANE(18), clipplane },
4977 { /* STATE_CLIPPLANE(19) */ STATE_CLIPPLANE(19), clipplane },
4978 { /* STATE_CLIPPLANE(20) */ STATE_CLIPPLANE(20), clipplane },
4979 { /* STATE_CLIPPLANE(21) */ STATE_CLIPPLANE(21), clipplane },
4980 { /* STATE_CLIPPLANE(22) */ STATE_CLIPPLANE(22), clipplane },
4981 { /* STATE_CLIPPLANE(23) */ STATE_CLIPPLANE(23), clipplane },
4982 { /* STATE_CLIPPLANE(24) */ STATE_CLIPPLANE(24), clipplane },
4983 { /* STATE_CLIPPLANE(25) */ STATE_CLIPPLANE(25), clipplane },
4984 { /* STATE_CLIPPLANE(26) */ STATE_CLIPPLANE(26), clipplane },
4985 { /* STATE_CLIPPLANE(27) */ STATE_CLIPPLANE(27), clipplane },
4986 { /* STATE_CLIPPLANE(28) */ STATE_CLIPPLANE(28), clipplane },
4987 { /* STATE_CLIPPLANE(29) */ STATE_CLIPPLANE(29), clipplane },
4988 { /* STATE_CLIPPLANE(30) */ STATE_CLIPPLANE(30), clipplane },
4989 { /* STATE_CLIPPLANE(31) */ STATE_CLIPPLANE(31), clipplane },
4991 { /* STATE_MATERIAL */ STATE_RENDER(WINED3DRS_SPECULARENABLE), state_specularenable},
4992 { /* STATE_FRONTFACE */ STATE_FRONTFACE, frontface },