wined3d: Get rid of SFLAG_DONOTFREE.
[wine.git] / dlls / wined3d / state.c
blob700db847ec6efd31cc00576b4efe28b1b3fc2664
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-2008 Stefan Dösinger for CodeWeavers
11 * Copyright 2009-2011 Henri Verbeet for CodeWeavers
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "config.h"
29 #include "wine/port.h"
31 #include <stdio.h>
32 #ifdef HAVE_FLOAT_H
33 # include <float.h>
34 #endif
36 #include "wined3d_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
39 WINE_DECLARE_DEBUG_CHANNEL(d3d_shader);
41 /* Context activation for state handler is done by the caller. */
43 static void state_undefined(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
45 ERR("Undefined state.\n");
48 static void state_nop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
50 TRACE("%s: nop in current pipe config.\n", debug_d3dstate(state_id));
53 static void state_fillmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
55 enum wined3d_fill_mode mode = state->render_states[WINED3D_RS_FILLMODE];
56 const struct wined3d_gl_info *gl_info = context->gl_info;
58 switch (mode)
60 case WINED3D_FILL_POINT:
61 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
62 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
63 break;
64 case WINED3D_FILL_WIREFRAME:
65 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
66 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
67 break;
68 case WINED3D_FILL_SOLID:
69 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
70 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
71 break;
72 default:
73 FIXME("Unrecognized fill mode %#x.\n", mode);
77 static void state_lighting(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
79 const struct wined3d_gl_info *gl_info = context->gl_info;
81 /* Lighting is not enabled if transformed vertices are drawn, but lighting
82 * does not affect the stream sources, so it is not grouped for
83 * performance reasons. This state reads the decoded vertex declaration,
84 * so if it is dirty don't do anything. The vertex declaration applying
85 * function calls this function for updating. */
86 if (isStateDirty(context, STATE_VDECL))
87 return;
89 if (state->render_states[WINED3D_RS_LIGHTING]
90 && !context->stream_info.position_transformed)
92 gl_info->gl_ops.gl.p_glEnable(GL_LIGHTING);
93 checkGLcall("glEnable GL_LIGHTING");
95 else
97 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
98 checkGLcall("glDisable GL_LIGHTING");
102 static void state_zenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
104 enum wined3d_depth_buffer_type zenable = state->render_states[WINED3D_RS_ZENABLE];
105 const struct wined3d_gl_info *gl_info = context->gl_info;
106 static UINT once;
108 /* No z test without depth stencil buffers */
109 if (!state->fb->depth_stencil)
111 TRACE("No Z buffer - disabling depth test\n");
112 zenable = WINED3D_ZB_FALSE;
115 switch (zenable)
117 case WINED3D_ZB_FALSE:
118 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
119 checkGLcall("glDisable GL_DEPTH_TEST");
120 break;
121 case WINED3D_ZB_TRUE:
122 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
123 checkGLcall("glEnable GL_DEPTH_TEST");
124 break;
125 case WINED3D_ZB_USEW:
126 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
127 checkGLcall("glEnable GL_DEPTH_TEST");
128 FIXME("W buffer is not well handled\n");
129 break;
130 default:
131 FIXME("Unrecognized depth buffer type %#x.\n", zenable);
132 break;
135 if (context->gl_info->supported[ARB_DEPTH_CLAMP])
137 if (!zenable && context->stream_info.position_transformed)
139 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_CLAMP);
140 checkGLcall("glEnable(GL_DEPTH_CLAMP)");
142 else
144 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_CLAMP);
145 checkGLcall("glDisable(GL_DEPTH_CLAMP)");
148 else if (!zenable && !once++)
149 FIXME("Z buffer disabled, but ARB_depth_clamp isn't supported.\n");
152 static void state_cullmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
154 const struct wined3d_gl_info *gl_info = context->gl_info;
156 /* glFrontFace() is set in context.c at context init and on an
157 * offscreen / onscreen rendering switch. */
158 switch (state->render_states[WINED3D_RS_CULLMODE])
160 case WINED3D_CULL_NONE:
161 gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
162 checkGLcall("glDisable GL_CULL_FACE");
163 break;
164 case WINED3D_CULL_CW:
165 gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
166 checkGLcall("glEnable GL_CULL_FACE");
167 gl_info->gl_ops.gl.p_glCullFace(GL_FRONT);
168 checkGLcall("glCullFace(GL_FRONT)");
169 break;
170 case WINED3D_CULL_CCW:
171 gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
172 checkGLcall("glEnable GL_CULL_FACE");
173 gl_info->gl_ops.gl.p_glCullFace(GL_BACK);
174 checkGLcall("glCullFace(GL_BACK)");
175 break;
176 default:
177 FIXME("Unrecognized cull mode %#x.\n",
178 state->render_states[WINED3D_RS_CULLMODE]);
182 static void state_shademode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
184 const struct wined3d_gl_info *gl_info = context->gl_info;
186 switch (state->render_states[WINED3D_RS_SHADEMODE])
188 case WINED3D_SHADE_FLAT:
189 gl_info->gl_ops.gl.p_glShadeModel(GL_FLAT);
190 checkGLcall("glShadeModel(GL_FLAT)");
191 break;
192 case WINED3D_SHADE_GOURAUD:
193 gl_info->gl_ops.gl.p_glShadeModel(GL_SMOOTH);
194 checkGLcall("glShadeModel(GL_SMOOTH)");
195 break;
196 case WINED3D_SHADE_PHONG:
197 FIXME("WINED3D_SHADE_PHONG isn't supported.\n");
198 break;
199 default:
200 FIXME("Unrecognized shade mode %#x.\n",
201 state->render_states[WINED3D_RS_SHADEMODE]);
205 static void state_ditherenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
207 const struct wined3d_gl_info *gl_info = context->gl_info;
209 if (state->render_states[WINED3D_RS_DITHERENABLE])
211 gl_info->gl_ops.gl.p_glEnable(GL_DITHER);
212 checkGLcall("glEnable GL_DITHER");
214 else
216 gl_info->gl_ops.gl.p_glDisable(GL_DITHER);
217 checkGLcall("glDisable GL_DITHER");
221 static void state_zwritenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
223 const struct wined3d_gl_info *gl_info = context->gl_info;
225 if (state->render_states[WINED3D_RS_ZWRITEENABLE])
227 gl_info->gl_ops.gl.p_glDepthMask(1);
228 checkGLcall("glDepthMask(1)");
230 else
232 gl_info->gl_ops.gl.p_glDepthMask(0);
233 checkGLcall("glDepthMask(0)");
237 static GLenum gl_compare_func(enum wined3d_cmp_func f)
239 switch (f)
241 case WINED3D_CMP_NEVER:
242 return GL_NEVER;
243 case WINED3D_CMP_LESS:
244 return GL_LESS;
245 case WINED3D_CMP_EQUAL:
246 return GL_EQUAL;
247 case WINED3D_CMP_LESSEQUAL:
248 return GL_LEQUAL;
249 case WINED3D_CMP_GREATER:
250 return GL_GREATER;
251 case WINED3D_CMP_NOTEQUAL:
252 return GL_NOTEQUAL;
253 case WINED3D_CMP_GREATEREQUAL:
254 return GL_GEQUAL;
255 case WINED3D_CMP_ALWAYS:
256 return GL_ALWAYS;
257 default:
258 FIXME("Unrecognized compare function %#x.\n", f);
259 return GL_NONE;
263 static void state_zfunc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
265 GLenum depth_func = gl_compare_func(state->render_states[WINED3D_RS_ZFUNC]);
266 const struct wined3d_gl_info *gl_info = context->gl_info;
268 if (!depth_func) return;
270 gl_info->gl_ops.gl.p_glDepthFunc(depth_func);
271 checkGLcall("glDepthFunc");
274 void state_ambient(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
276 const struct wined3d_gl_info *gl_info = context->gl_info;
277 float col[4];
279 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_AMBIENT], col);
280 TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]);
281 gl_info->gl_ops.gl.p_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
282 checkGLcall("glLightModel for MODEL_AMBIENT");
285 static void state_blendop_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
287 WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
290 static GLenum gl_blend_op(enum wined3d_blend_op op)
292 switch (op)
294 case WINED3D_BLEND_OP_ADD:
295 return GL_FUNC_ADD_EXT;
296 case WINED3D_BLEND_OP_SUBTRACT:
297 return GL_FUNC_SUBTRACT_EXT;
298 case WINED3D_BLEND_OP_REVSUBTRACT:
299 return GL_FUNC_REVERSE_SUBTRACT_EXT;
300 case WINED3D_BLEND_OP_MIN:
301 return GL_MIN_EXT;
302 case WINED3D_BLEND_OP_MAX:
303 return GL_MAX_EXT;
304 default:
305 FIXME("Unhandled blend op %#x.\n", op);
306 return GL_NONE;
310 static void state_blendop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
312 const struct wined3d_gl_info *gl_info = context->gl_info;
313 GLenum blend_equation_alpha = GL_FUNC_ADD_EXT;
314 GLenum blend_equation = GL_FUNC_ADD_EXT;
316 /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */
317 if (state->render_states[WINED3D_RS_BLENDOPALPHA]
318 && !gl_info->supported[EXT_BLEND_EQUATION_SEPARATE])
320 WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparateEXT\n");
321 return;
324 blend_equation = gl_blend_op(state->render_states[WINED3D_RS_BLENDOP]);
325 blend_equation_alpha = gl_blend_op(state->render_states[WINED3D_RS_BLENDOPALPHA]);
326 TRACE("blend_equation %#x, blend_equation_alpha %#x.\n", blend_equation, blend_equation_alpha);
328 if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
330 GL_EXTCALL(glBlendEquationSeparateEXT(blend_equation, blend_equation_alpha));
331 checkGLcall("glBlendEquationSeparateEXT");
333 else
335 GL_EXTCALL(glBlendEquationEXT(blend_equation));
336 checkGLcall("glBlendEquation");
340 static GLenum gl_blend_factor(enum wined3d_blend factor, const struct wined3d_format *dst_format)
342 switch (factor)
344 case WINED3D_BLEND_ZERO:
345 return GL_ZERO;
346 case WINED3D_BLEND_ONE:
347 return GL_ONE;
348 case WINED3D_BLEND_SRCCOLOR:
349 return GL_SRC_COLOR;
350 case WINED3D_BLEND_INVSRCCOLOR:
351 return GL_ONE_MINUS_SRC_COLOR;
352 case WINED3D_BLEND_SRCALPHA:
353 return GL_SRC_ALPHA;
354 case WINED3D_BLEND_INVSRCALPHA:
355 return GL_ONE_MINUS_SRC_ALPHA;
356 case WINED3D_BLEND_DESTCOLOR:
357 return GL_DST_COLOR;
358 case WINED3D_BLEND_INVDESTCOLOR:
359 return GL_ONE_MINUS_DST_COLOR;
360 /* To compensate for the lack of format switching with backbuffer
361 * offscreen rendering, and with onscreen rendering, we modify the
362 * alpha test parameters for (INV)DESTALPHA if the render target
363 * doesn't support alpha blending. A nonexistent alpha channel
364 * returns 1.0, so WINED3D_BLEND_DESTALPHA becomes GL_ONE, and
365 * WINED3D_BLEND_INVDESTALPHA becomes GL_ZERO. */
366 case WINED3D_BLEND_DESTALPHA:
367 return dst_format->alpha_size ? GL_DST_ALPHA : GL_ONE;
368 case WINED3D_BLEND_INVDESTALPHA:
369 return dst_format->alpha_size ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO;
370 case WINED3D_BLEND_SRCALPHASAT:
371 return GL_SRC_ALPHA_SATURATE;
372 case WINED3D_BLEND_BLENDFACTOR:
373 return GL_CONSTANT_COLOR_EXT;
374 case WINED3D_BLEND_INVBLENDFACTOR:
375 return GL_ONE_MINUS_CONSTANT_COLOR_EXT;
376 default:
377 FIXME("Unhandled blend factor %#x.\n", factor);
378 return GL_NONE;
382 static void state_blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
384 const struct wined3d_format *rt_format = state->fb->render_targets[0]->format;
385 const struct wined3d_gl_info *gl_info = context->gl_info;
386 GLenum srcBlend, dstBlend;
387 enum wined3d_blend d3d_blend;
389 /* According to the red book, GL_LINE_SMOOTH needs GL_BLEND with specific
390 * blending parameters to work. */
391 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]
392 || state->render_states[WINED3D_RS_EDGEANTIALIAS]
393 || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE])
395 /* Disable blending in all cases even without pixelshaders.
396 * With blending on we could face a big performance penalty.
397 * The d3d9 visual test confirms the behavior. */
398 if (context->render_offscreen && !(rt_format->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
400 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
401 checkGLcall("glDisable GL_BLEND");
402 return;
404 else
406 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
407 checkGLcall("glEnable GL_BLEND");
410 else
412 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
413 checkGLcall("glDisable GL_BLEND");
414 /* Nothing more to do - get out */
415 return;
418 /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy
419 * source blending values which are still valid up to d3d9. They should
420 * not occur as dest blend values. */
421 d3d_blend = state->render_states[WINED3D_RS_SRCBLEND];
422 if (d3d_blend == WINED3D_BLEND_BOTHSRCALPHA)
424 srcBlend = GL_SRC_ALPHA;
425 dstBlend = GL_ONE_MINUS_SRC_ALPHA;
427 else if (d3d_blend == WINED3D_BLEND_BOTHINVSRCALPHA)
429 srcBlend = GL_ONE_MINUS_SRC_ALPHA;
430 dstBlend = GL_SRC_ALPHA;
432 else
434 srcBlend = gl_blend_factor(d3d_blend, rt_format);
435 dstBlend = gl_blend_factor(state->render_states[WINED3D_RS_DESTBLEND], rt_format);
438 if (state->render_states[WINED3D_RS_EDGEANTIALIAS]
439 || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE])
441 gl_info->gl_ops.gl.p_glEnable(GL_LINE_SMOOTH);
442 checkGLcall("glEnable(GL_LINE_SMOOTH)");
443 if (srcBlend != GL_SRC_ALPHA)
444 WARN("WINED3D_RS_EDGEANTIALIAS enabled, but unexpected src blending param.\n");
445 if (dstBlend != GL_ONE_MINUS_SRC_ALPHA && dstBlend != GL_ONE)
446 WARN("WINED3D_RS_EDGEANTIALIAS enabled, but unexpected dst blending param.\n");
448 else
450 gl_info->gl_ops.gl.p_glDisable(GL_LINE_SMOOTH);
451 checkGLcall("glDisable(GL_LINE_SMOOTH)");
454 /* Re-apply BLENDOP(ALPHA) because of a possible SEPARATEALPHABLENDENABLE change */
455 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_BLENDOP)))
456 state_blendop(context, state, STATE_RENDER(WINED3D_RS_BLENDOPALPHA));
458 if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
460 GLenum srcBlendAlpha, dstBlendAlpha;
462 /* Separate alpha blending requires GL_EXT_blend_function_separate, so make sure it is around */
463 if (!context->gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
465 WARN("Unsupported in local OpenGL implementation: glBlendFuncSeparateEXT\n");
466 return;
469 /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy
470 * source blending values which are still valid up to d3d9. They should
471 * not occur as dest blend values. */
472 d3d_blend = state->render_states[WINED3D_RS_SRCBLENDALPHA];
473 if (d3d_blend == WINED3D_BLEND_BOTHSRCALPHA)
475 srcBlendAlpha = GL_SRC_ALPHA;
476 dstBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
478 else if (d3d_blend == WINED3D_BLEND_BOTHINVSRCALPHA)
480 srcBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
481 dstBlendAlpha = GL_SRC_ALPHA;
483 else
485 srcBlendAlpha = gl_blend_factor(d3d_blend, rt_format);
486 dstBlendAlpha = gl_blend_factor(state->render_states[WINED3D_RS_DESTBLENDALPHA], rt_format);
489 GL_EXTCALL(glBlendFuncSeparateEXT(srcBlend, dstBlend, srcBlendAlpha, dstBlendAlpha));
490 checkGLcall("glBlendFuncSeparateEXT");
492 else
494 TRACE("glBlendFunc src=%x, dst=%x\n", srcBlend, dstBlend);
495 gl_info->gl_ops.gl.p_glBlendFunc(srcBlend, dstBlend);
496 checkGLcall("glBlendFunc");
499 /* Colorkey fixup for stage 0 alphaop depends on
500 * WINED3D_RS_ALPHABLENDENABLE state, so it may need updating. */
501 if (state->render_states[WINED3D_RS_COLORKEYENABLE])
502 context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
505 static void state_blendfactor_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
507 WARN("Unsupported in local OpenGL implementation: glBlendColorEXT\n");
510 static void state_blendfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
512 const struct wined3d_gl_info *gl_info = context->gl_info;
513 float col[4];
515 TRACE("Setting blend factor to %#x.\n", state->render_states[WINED3D_RS_BLENDFACTOR]);
517 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_BLENDFACTOR], col);
518 GL_EXTCALL(glBlendColorEXT (col[0],col[1],col[2],col[3]));
519 checkGLcall("glBlendColor");
522 static void state_alpha(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
524 const struct wined3d_gl_info *gl_info = context->gl_info;
525 int glParm = 0;
526 float ref;
527 BOOL enable_ckey = FALSE;
529 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
531 /* Find out if the texture on the first stage has a ckey set. The alpha
532 * state func reads the texture settings, even though alpha and texture
533 * are not grouped together. This is to avoid making a huge alpha +
534 * texture + texture stage + ckey block due to the hardly used
535 * WINED3D_RS_COLORKEYENABLE state(which is d3d <= 3 only). The texture
536 * function will call alpha in case it finds some texture + colorkeyenable
537 * combination which needs extra care. */
538 if (state->textures[0] && (state->textures[0]->color_key_flags & WINEDDSD_CKSRCBLT))
539 enable_ckey = TRUE;
541 if (enable_ckey || context->last_was_ckey)
542 context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
543 context->last_was_ckey = enable_ckey;
545 if (state->render_states[WINED3D_RS_ALPHATESTENABLE]
546 || (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey))
548 gl_info->gl_ops.gl.p_glEnable(GL_ALPHA_TEST);
549 checkGLcall("glEnable GL_ALPHA_TEST");
551 else
553 gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
554 checkGLcall("glDisable GL_ALPHA_TEST");
555 /* Alpha test is disabled, don't bother setting the params - it will happen on the next
556 * enable call
558 return;
561 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey)
563 glParm = GL_NOTEQUAL;
564 ref = 0.0f;
566 else
568 ref = ((float)state->render_states[WINED3D_RS_ALPHAREF]) / 255.0f;
569 glParm = gl_compare_func(state->render_states[WINED3D_RS_ALPHAFUNC]);
571 if (glParm)
573 gl_info->gl_ops.gl.p_glAlphaFunc(glParm, ref);
574 checkGLcall("glAlphaFunc");
578 void state_clipping(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
580 const struct wined3d_gl_info *gl_info = context->gl_info;
581 DWORD enable = 0xffffffff;
582 DWORD disable = 0x00000000;
584 if (use_vs(state) && !context->d3d_info->vs_clipping)
586 static BOOL warned;
588 /* The OpenGL spec says that clipping planes are disabled when using
589 * shaders. Direct3D planes aren't, so that is an issue. The MacOS ATI
590 * driver keeps clipping planes activated with shaders in some
591 * conditions I got sick of tracking down. The shader state handler
592 * disables all clip planes because of that - don't do anything here
593 * and keep them disabled. */
594 if (state->render_states[WINED3D_RS_CLIPPLANEENABLE] && !warned++)
595 FIXME("Clipping not supported with vertex shaders\n");
596 return;
599 /* glEnable(GL_CLIP_PLANEx) doesn't apply to (ARB backend) vertex shaders.
600 * The enabled / disabled planes are hardcoded into the shader. Update the
601 * shader to update the enabled clipplanes. In case of fixed function, we
602 * need to update the clipping field from ffp_vertex_settings. */
603 context->shader_update_mask |= 1 << WINED3D_SHADER_TYPE_VERTEX;
605 /* TODO: Keep track of previously enabled clipplanes to avoid unnecessary resetting
606 * of already set values
609 /* If enabling / disabling all
610 * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
612 if (state->render_states[WINED3D_RS_CLIPPING])
614 enable = state->render_states[WINED3D_RS_CLIPPLANEENABLE];
615 disable = ~state->render_states[WINED3D_RS_CLIPPLANEENABLE];
617 else
619 disable = 0xffffffff;
620 enable = 0x00;
623 if (enable & WINED3DCLIPPLANE0) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE0);
624 if (enable & WINED3DCLIPPLANE1) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE1);
625 if (enable & WINED3DCLIPPLANE2) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE2);
626 if (enable & WINED3DCLIPPLANE3) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE3);
627 if (enable & WINED3DCLIPPLANE4) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE4);
628 if (enable & WINED3DCLIPPLANE5) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE5);
629 checkGLcall("clip plane enable");
631 if (disable & WINED3DCLIPPLANE0) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE0);
632 if (disable & WINED3DCLIPPLANE1) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE1);
633 if (disable & WINED3DCLIPPLANE2) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE2);
634 if (disable & WINED3DCLIPPLANE3) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE3);
635 if (disable & WINED3DCLIPPLANE4) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE4);
636 if (disable & WINED3DCLIPPLANE5) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE5);
637 checkGLcall("clip plane disable");
640 void state_specularenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
642 const struct wined3d_gl_info *gl_info = context->gl_info;
643 /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
644 * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
645 * specular color. This is wrong:
646 * Separate specular color means the specular colour is maintained separately, whereas
647 * single color means it is merged in. However in both cases they are being used to
648 * some extent.
649 * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
650 * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
651 * running 1.4 yet!
654 * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
655 * Instead, we need to setup the FinalCombiner properly.
657 * The default setup for the FinalCombiner is:
659 * <variable> <input> <mapping> <usage>
660 * GL_VARIABLE_A_NV GL_FOG, GL_UNSIGNED_IDENTITY_NV GL_ALPHA
661 * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV GL_UNSIGNED_IDENTITY_NV GL_RGB
662 * GL_VARIABLE_C_NV GL_FOG GL_UNSIGNED_IDENTITY_NV GL_RGB
663 * GL_VARIABLE_D_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
664 * GL_VARIABLE_E_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
665 * GL_VARIABLE_F_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
666 * GL_VARIABLE_G_NV GL_SPARE0_NV GL_UNSIGNED_IDENTITY_NV GL_ALPHA
668 * That's pretty much fine as it is, except for variable B, which needs to take
669 * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
670 * whether WINED3D_RS_SPECULARENABLE is enabled or not.
673 TRACE("Setting specular enable state and materials\n");
674 if (state->render_states[WINED3D_RS_SPECULARENABLE])
676 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
677 checkGLcall("glMaterialfv");
679 if (state->material.power > gl_info->limits.shininess)
681 /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0
682 * and 128.0, although in d3d neither -1 nor 129 produce an error. GL_NV_max_light_exponent
683 * allows bigger values. If the extension is supported, gl_info->limits.shininess contains the
684 * value reported by the extension, otherwise 128. For values > gl_info->limits.shininess clamp
685 * them, it should be safe to do so without major visual distortions.
687 WARN("Material power = %.8e, limit %.8e\n", state->material.power, gl_info->limits.shininess);
688 gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, gl_info->limits.shininess);
690 else
692 gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, state->material.power);
694 checkGLcall("glMaterialf(GL_SHININESS)");
696 if (gl_info->supported[EXT_SECONDARY_COLOR])
697 gl_info->gl_ops.gl.p_glEnable(GL_COLOR_SUM_EXT);
698 else
699 TRACE("Specular colors cannot be enabled in this version of opengl\n");
700 checkGLcall("glEnable(GL_COLOR_SUM)");
702 if (gl_info->supported[NV_REGISTER_COMBINERS])
704 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
705 checkGLcall("glFinalCombinerInputNV()");
707 } else {
708 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
710 /* for the case of enabled lighting: */
711 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
712 checkGLcall("glMaterialfv");
714 /* for the case of disabled lighting: */
715 if (gl_info->supported[EXT_SECONDARY_COLOR])
716 gl_info->gl_ops.gl.p_glDisable(GL_COLOR_SUM_EXT);
717 else
718 TRACE("Specular colors cannot be disabled in this version of opengl\n");
719 checkGLcall("glDisable(GL_COLOR_SUM)");
721 if (gl_info->supported[NV_REGISTER_COMBINERS])
723 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
724 checkGLcall("glFinalCombinerInputNV()");
728 TRACE("diffuse {%.8e, %.8e, %.8e, %.8e}\n",
729 state->material.diffuse.r, state->material.diffuse.g,
730 state->material.diffuse.b, state->material.diffuse.a);
731 TRACE("ambient {%.8e, %.8e, %.8e, %.8e}\n",
732 state->material.ambient.r, state->material.ambient.g,
733 state->material.ambient.b, state->material.ambient.a);
734 TRACE("specular {%.8e, %.8e, %.8e, %.8e}\n",
735 state->material.specular.r, state->material.specular.g,
736 state->material.specular.b, state->material.specular.a);
737 TRACE("emissive {%.8e, %.8e, %.8e, %.8e}\n",
738 state->material.emissive.r, state->material.emissive.g,
739 state->material.emissive.b, state->material.emissive.a);
741 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
742 checkGLcall("glMaterialfv(GL_AMBIENT)");
743 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
744 checkGLcall("glMaterialfv(GL_DIFFUSE)");
745 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
746 checkGLcall("glMaterialfv(GL_EMISSION)");
749 static void state_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
751 const struct wined3d_gl_info *gl_info = context->gl_info;
752 unsigned int i;
754 /* Note the texture color applies to all textures whereas
755 * GL_TEXTURE_ENV_COLOR applies to active only. */
756 float col[4];
757 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col);
759 /* And now the default texture color as well */
760 for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
762 /* Note the WINED3D_RS value applies to all textures, but GL has one
763 * per texture, so apply it now ready to be used! */
764 context_active_texture(context, gl_info, i);
766 gl_info->gl_ops.gl.p_glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
767 checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
771 static void renderstate_stencil_twosided(struct wined3d_context *context, GLint face,
772 GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass)
774 const struct wined3d_gl_info *gl_info = context->gl_info;
776 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
777 checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
778 GL_EXTCALL(glActiveStencilFaceEXT(face));
779 checkGLcall("glActiveStencilFaceEXT(...)");
780 gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
781 checkGLcall("glStencilFunc(...)");
782 gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
783 checkGLcall("glStencilOp(...)");
786 static GLenum gl_stencil_op(enum wined3d_stencil_op op)
788 switch (op)
790 case WINED3D_STENCIL_OP_KEEP:
791 return GL_KEEP;
792 case WINED3D_STENCIL_OP_ZERO:
793 return GL_ZERO;
794 case WINED3D_STENCIL_OP_REPLACE:
795 return GL_REPLACE;
796 case WINED3D_STENCIL_OP_INCR_SAT:
797 return GL_INCR;
798 case WINED3D_STENCIL_OP_DECR_SAT:
799 return GL_DECR;
800 case WINED3D_STENCIL_OP_INVERT:
801 return GL_INVERT;
802 case WINED3D_STENCIL_OP_INCR:
803 return GL_INCR_WRAP_EXT;
804 case WINED3D_STENCIL_OP_DECR:
805 return GL_DECR_WRAP_EXT;
806 default:
807 FIXME("Unrecognized stencil op %#x.\n", op);
808 return GL_KEEP;
812 static void state_stencil(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
814 const struct wined3d_gl_info *gl_info = context->gl_info;
815 DWORD onesided_enable;
816 DWORD twosided_enable;
817 GLint func;
818 GLint func_ccw;
819 GLint ref;
820 GLuint mask;
821 GLint stencilFail;
822 GLint stencilFail_ccw;
823 GLint stencilPass;
824 GLint stencilPass_ccw;
825 GLint depthFail;
826 GLint depthFail_ccw;
828 /* No stencil test without a stencil buffer. */
829 if (!state->fb->depth_stencil)
831 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
832 checkGLcall("glDisable GL_STENCIL_TEST");
833 return;
836 onesided_enable = state->render_states[WINED3D_RS_STENCILENABLE];
837 twosided_enable = state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE];
838 if (!(func = gl_compare_func(state->render_states[WINED3D_RS_STENCILFUNC])))
839 func = GL_ALWAYS;
840 if (!(func_ccw = gl_compare_func(state->render_states[WINED3D_RS_CCW_STENCILFUNC])))
841 func_ccw = GL_ALWAYS;
842 ref = state->render_states[WINED3D_RS_STENCILREF];
843 mask = state->render_states[WINED3D_RS_STENCILMASK];
844 stencilFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILFAIL]);
845 depthFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILZFAIL]);
846 stencilPass = gl_stencil_op(state->render_states[WINED3D_RS_STENCILPASS]);
847 stencilFail_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILFAIL]);
848 depthFail_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILZFAIL]);
849 stencilPass_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILPASS]);
851 TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
852 "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
853 "GL_BACK: func: %x, fail %x, zfail %x, zpass %x )\n",
854 onesided_enable, twosided_enable, ref, mask,
855 func, stencilFail, depthFail, stencilPass,
856 func_ccw, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
858 if (twosided_enable && onesided_enable)
860 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
861 checkGLcall("glEnable GL_STENCIL_TEST");
863 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
865 /* Apply back first, then front. This function calls glActiveStencilFaceEXT,
866 * which has an effect on the code below too. If we apply the front face
867 * afterwards, we are sure that the active stencil face is set to front,
868 * and other stencil functions which do not use two sided stencil do not have
869 * to set it back
871 renderstate_stencil_twosided(context, GL_BACK,
872 func_ccw, ref, mask, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
873 renderstate_stencil_twosided(context, GL_FRONT,
874 func, ref, mask, stencilFail, depthFail, stencilPass);
876 else if (gl_info->supported[ATI_SEPARATE_STENCIL])
878 GL_EXTCALL(glStencilFuncSeparateATI(func, func_ccw, ref, mask));
879 checkGLcall("glStencilFuncSeparateATI(...)");
880 GL_EXTCALL(glStencilOpSeparateATI(GL_FRONT, stencilFail, depthFail, stencilPass));
881 checkGLcall("glStencilOpSeparateATI(GL_FRONT, ...)");
882 GL_EXTCALL(glStencilOpSeparateATI(GL_BACK, stencilFail_ccw, depthFail_ccw, stencilPass_ccw));
883 checkGLcall("glStencilOpSeparateATI(GL_BACK, ...)");
884 } else {
885 ERR("Separate (two sided) stencil not supported on this version of opengl. Caps weren't honored?\n");
888 else if(onesided_enable)
890 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
892 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
893 checkGLcall("glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
896 /* This code disables the ATI extension as well, since the standard stencil functions are equal
897 * to calling the ATI functions with GL_FRONT_AND_BACK as face parameter
899 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
900 checkGLcall("glEnable GL_STENCIL_TEST");
901 gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
902 checkGLcall("glStencilFunc(...)");
903 gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
904 checkGLcall("glStencilOp(...)");
906 else
908 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
909 checkGLcall("glDisable GL_STENCIL_TEST");
913 static void state_stencilwrite2s(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
915 DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
916 const struct wined3d_gl_info *gl_info = context->gl_info;
918 GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
919 checkGLcall("glActiveStencilFaceEXT(GL_BACK)");
920 gl_info->gl_ops.gl.p_glStencilMask(mask);
921 checkGLcall("glStencilMask");
922 GL_EXTCALL(glActiveStencilFaceEXT(GL_FRONT));
923 checkGLcall("glActiveStencilFaceEXT(GL_FRONT)");
924 gl_info->gl_ops.gl.p_glStencilMask(mask);
927 static void state_stencilwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
929 DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
930 const struct wined3d_gl_info *gl_info = context->gl_info;
932 gl_info->gl_ops.gl.p_glStencilMask(mask);
933 checkGLcall("glStencilMask");
936 static void state_fog_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
938 const struct wined3d_gl_info *gl_info = context->gl_info;
940 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
942 if (!state->render_states[WINED3D_RS_FOGENABLE])
943 return;
945 /* Table fog on: Never use fog coords, and use per-fragment fog */
946 if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
948 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
949 if (context->fog_coord)
951 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
952 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
953 context->fog_coord = FALSE;
956 /* Range fog is only used with per-vertex fog in d3d */
957 if (gl_info->supported[NV_FOG_DISTANCE])
959 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
960 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
962 return;
965 /* Otherwise use per-vertex fog in any case */
966 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_FASTEST);
968 if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || context->last_was_rhw)
970 /* No fog at all, or transformed vertices: Use fog coord */
971 if (!context->fog_coord)
973 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
974 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)");
975 context->fog_coord = TRUE;
978 else
980 /* Otherwise, use the fragment depth */
981 if (context->fog_coord)
983 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
984 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
985 context->fog_coord = FALSE;
988 if (state->render_states[WINED3D_RS_RANGEFOGENABLE])
990 if (gl_info->supported[NV_FOG_DISTANCE])
992 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
993 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)");
995 else
997 WARN("Range fog enabled, but not supported by this GL implementation.\n");
1000 else if (gl_info->supported[NV_FOG_DISTANCE])
1002 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
1003 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
1008 void state_fogstartend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1010 const struct wined3d_gl_info *gl_info = context->gl_info;
1011 float fogstart, fogend;
1012 union {
1013 DWORD d;
1014 float f;
1015 } tmpvalue;
1017 switch(context->fog_source) {
1018 case FOGSOURCE_VS:
1019 fogstart = 1.0f;
1020 fogend = 0.0f;
1021 break;
1023 case FOGSOURCE_COORD:
1024 fogstart = 255.0f;
1025 fogend = 0.0f;
1026 break;
1028 case FOGSOURCE_FFP:
1029 tmpvalue.d = state->render_states[WINED3D_RS_FOGSTART];
1030 fogstart = tmpvalue.f;
1031 tmpvalue.d = state->render_states[WINED3D_RS_FOGEND];
1032 fogend = tmpvalue.f;
1033 /* Special handling for fogstart == fogend. In d3d with vertex
1034 * fog, everything is fogged. With table fog, everything with
1035 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
1036 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
1037 if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE
1038 && fogstart == fogend)
1040 fogstart = -INFINITY;
1041 fogend = 0.0f;
1043 break;
1045 default:
1046 /* This should not happen.context->fog_source is set in wined3d, not the app.
1047 * Still this is needed to make the compiler happy
1049 ERR("Unexpected fog coordinate source\n");
1050 fogstart = 0.0f;
1051 fogend = 0.0f;
1054 gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, fogstart);
1055 checkGLcall("glFogf(GL_FOG_START, fogstart)");
1056 TRACE("Fog Start == %f\n", fogstart);
1058 gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, fogend);
1059 checkGLcall("glFogf(GL_FOG_END, fogend)");
1060 TRACE("Fog End == %f\n", fogend);
1063 void state_fog_fragpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1065 const struct wined3d_gl_info *gl_info = context->gl_info;
1066 enum fogsource new_source;
1067 DWORD fogstart = state->render_states[WINED3D_RS_FOGSTART];
1068 DWORD fogend = state->render_states[WINED3D_RS_FOGEND];
1070 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
1072 if (!state->render_states[WINED3D_RS_FOGENABLE])
1074 /* No fog? Disable it, and we're done :-) */
1075 glDisableWINE(GL_FOG);
1076 checkGLcall("glDisable GL_FOG");
1077 return;
1080 /* Fog Rules:
1082 * With fixed function vertex processing, Direct3D knows 2 different fog input sources.
1083 * It can use the Z value of the vertex, or the alpha component of the specular color.
1084 * This depends on the fog vertex, fog table and the vertex declaration. If the Z value
1085 * is used, fogstart, fogend and the equation type are used, otherwise linear fog with
1086 * start = 255, end = 0 is used. Obviously the msdn is not very clear on that.
1088 * FOGTABLEMODE != NONE:
1089 * The Z value is used, with the equation specified, no matter what vertex type.
1091 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, untransformed:
1092 * Per vertex fog is calculated using the specified fog equation and the parameters
1094 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, transformed, OR
1095 * FOGTABLEMODE == NONE, FOGVERTEXMODE == NONE, untransformed:
1096 * Linear fog with start = 255.0, end = 0.0, input comes from the specular color
1099 * Rules for vertex fog with shaders:
1101 * When mixing fixed function functionality with the programmable pipeline, D3D expects
1102 * the fog computation to happen during transformation while openGL expects it to happen
1103 * during rasterization. Also, prior to pixel shader 3.0 D3D handles fog blending after
1104 * the pixel shader while openGL always expects the pixel shader to handle the blending.
1105 * To solve this problem, WineD3D does:
1106 * 1) implement a linear fog equation and fog blending at the end of every pre 3.0 pixel
1107 * shader,
1108 * and 2) disables the fog computation (in either the fixed function or programmable
1109 * rasterizer) if using a vertex program.
1111 * D3D shaders can provide an explicit fog coordinate. This fog coordinate is used with
1112 * D3DRS_FOGTABLEMODE==D3DFOG_NONE. The FOGVERTEXMODE is ignored, d3d always uses linear
1113 * fog with start=1.0 and end=0.0 in this case. This is similar to fog coordinates in
1114 * the specular color, a vertex shader counts as pretransformed geometry in this case.
1115 * There are some GL differences between specular fog coords and vertex shaders though.
1117 * With table fog the vertex shader fog coordinate is ignored.
1119 * If a fogtablemode and a fogvertexmode are specified, table fog is applied (with or
1120 * without shaders).
1123 /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
1124 * the system will apply only pixel(=table) fog effects."
1126 if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
1128 if (use_vs(state))
1130 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1131 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1132 new_source = FOGSOURCE_VS;
1134 else
1136 switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
1138 /* If processed vertices are used, fall through to the NONE case */
1139 case WINED3D_FOG_EXP:
1140 if (!context->last_was_rhw)
1142 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1143 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1144 new_source = FOGSOURCE_FFP;
1145 break;
1147 /* drop through */
1149 case WINED3D_FOG_EXP2:
1150 if (!context->last_was_rhw)
1152 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1153 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1154 new_source = FOGSOURCE_FFP;
1155 break;
1157 /* drop through */
1159 case WINED3D_FOG_LINEAR:
1160 if (!context->last_was_rhw)
1162 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1163 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1164 new_source = FOGSOURCE_FFP;
1165 break;
1167 /* drop through */
1169 case WINED3D_FOG_NONE:
1170 /* Both are none? According to msdn the alpha channel of the specular
1171 * color contains a fog factor. Set it in drawStridedSlow.
1172 * Same happens with Vertexfog on transformed vertices
1174 new_source = FOGSOURCE_COORD;
1175 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1176 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1177 break;
1179 default:
1180 FIXME("Unexpected WINED3D_RS_FOGVERTEXMODE %#x.\n",
1181 state->render_states[WINED3D_RS_FOGVERTEXMODE]);
1182 new_source = FOGSOURCE_FFP; /* Make the compiler happy */
1185 } else {
1186 new_source = FOGSOURCE_FFP;
1188 switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
1190 case WINED3D_FOG_EXP:
1191 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1192 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1193 break;
1195 case WINED3D_FOG_EXP2:
1196 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1197 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1198 break;
1200 case WINED3D_FOG_LINEAR:
1201 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1202 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1203 break;
1205 case WINED3D_FOG_NONE: /* Won't happen */
1206 default:
1207 FIXME("Unexpected WINED3D_RS_FOGTABLEMODE %#x.\n",
1208 state->render_states[WINED3D_RS_FOGTABLEMODE]);
1212 glEnableWINE(GL_FOG);
1213 checkGLcall("glEnable GL_FOG");
1214 if (new_source != context->fog_source || fogstart == fogend)
1216 context->fog_source = new_source;
1217 state_fogstartend(context, state, STATE_RENDER(WINED3D_RS_FOGSTART));
1221 void state_fogcolor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1223 const struct wined3d_gl_info *gl_info = context->gl_info;
1224 float col[4];
1226 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_FOGCOLOR], col);
1227 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, &col[0]);
1228 checkGLcall("glFog GL_FOG_COLOR");
1231 void state_fogdensity(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1233 const struct wined3d_gl_info *gl_info = context->gl_info;
1234 union {
1235 DWORD d;
1236 float f;
1237 } tmpvalue;
1239 tmpvalue.d = state->render_states[WINED3D_RS_FOGDENSITY];
1240 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
1241 checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
1244 static void state_colormat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1246 const struct wined3d_gl_info *gl_info = context->gl_info;
1247 GLenum Parm = 0;
1249 /* Depends on the decoded vertex declaration to read the existence of diffuse data.
1250 * The vertex declaration will call this function if the fixed function pipeline is used.
1253 if(isStateDirty(context, STATE_VDECL)) {
1254 return;
1257 context->num_untracked_materials = 0;
1258 if ((context->stream_info.use_map & (1 << WINED3D_FFP_DIFFUSE))
1259 && state->render_states[WINED3D_RS_COLORVERTEX])
1261 TRACE("diff %d, amb %d, emis %d, spec %d\n",
1262 state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE],
1263 state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE],
1264 state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE],
1265 state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]);
1267 if (state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1269 if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1270 Parm = GL_AMBIENT_AND_DIFFUSE;
1271 else
1272 Parm = GL_DIFFUSE;
1273 if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1275 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1276 context->num_untracked_materials++;
1278 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1280 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1281 context->num_untracked_materials++;
1284 else if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1286 Parm = GL_AMBIENT;
1287 if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1289 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1290 context->num_untracked_materials++;
1292 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1294 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1295 context->num_untracked_materials++;
1298 else if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1300 Parm = GL_EMISSION;
1301 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1303 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1304 context->num_untracked_materials++;
1307 else if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1309 Parm = GL_SPECULAR;
1313 /* Nothing changed, return. */
1314 if (Parm == context->tracking_parm) return;
1316 if (!Parm)
1318 gl_info->gl_ops.gl.p_glDisable(GL_COLOR_MATERIAL);
1319 checkGLcall("glDisable GL_COLOR_MATERIAL");
1321 else
1323 gl_info->gl_ops.gl.p_glColorMaterial(GL_FRONT_AND_BACK, Parm);
1324 checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
1325 gl_info->gl_ops.gl.p_glEnable(GL_COLOR_MATERIAL);
1326 checkGLcall("glEnable(GL_COLOR_MATERIAL)");
1329 /* Apparently calls to glMaterialfv are ignored for properties we're
1330 * tracking with glColorMaterial, so apply those here. */
1331 switch (context->tracking_parm)
1333 case GL_AMBIENT_AND_DIFFUSE:
1334 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
1335 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1336 checkGLcall("glMaterialfv");
1337 break;
1339 case GL_DIFFUSE:
1340 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1341 checkGLcall("glMaterialfv");
1342 break;
1344 case GL_AMBIENT:
1345 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
1346 checkGLcall("glMaterialfv");
1347 break;
1349 case GL_EMISSION:
1350 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
1351 checkGLcall("glMaterialfv");
1352 break;
1354 case GL_SPECULAR:
1355 /* Only change material color if specular is enabled, otherwise it is set to black */
1356 if (state->render_states[WINED3D_RS_SPECULARENABLE])
1358 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
1359 checkGLcall("glMaterialfv");
1361 else
1363 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
1364 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
1365 checkGLcall("glMaterialfv");
1367 break;
1370 context->tracking_parm = Parm;
1373 static void state_linepattern(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1375 const struct wined3d_gl_info *gl_info = context->gl_info;
1376 union
1378 DWORD d;
1379 struct wined3d_line_pattern lp;
1380 } tmppattern;
1381 tmppattern.d = state->render_states[WINED3D_RS_LINEPATTERN];
1383 TRACE("Line pattern: repeat %d bits %x.\n", tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1385 if (tmppattern.lp.repeat_factor)
1387 gl_info->gl_ops.gl.p_glLineStipple(tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1388 checkGLcall("glLineStipple(repeat, linepattern)");
1389 gl_info->gl_ops.gl.p_glEnable(GL_LINE_STIPPLE);
1390 checkGLcall("glEnable(GL_LINE_STIPPLE);");
1392 else
1394 gl_info->gl_ops.gl.p_glDisable(GL_LINE_STIPPLE);
1395 checkGLcall("glDisable(GL_LINE_STIPPLE);");
1399 static void state_normalize(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1401 const struct wined3d_gl_info *gl_info = context->gl_info;
1403 if (isStateDirty(context, STATE_VDECL))
1404 return;
1406 /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor
1407 * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division
1408 * by zero and is not properly defined in opengl, so avoid it
1410 if (state->render_states[WINED3D_RS_NORMALIZENORMALS]
1411 && (context->stream_info.use_map & (1 << WINED3D_FFP_NORMAL)))
1413 gl_info->gl_ops.gl.p_glEnable(GL_NORMALIZE);
1414 checkGLcall("glEnable(GL_NORMALIZE);");
1416 else
1418 gl_info->gl_ops.gl.p_glDisable(GL_NORMALIZE);
1419 checkGLcall("glDisable(GL_NORMALIZE);");
1423 void state_psizemin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1425 union {
1426 DWORD d;
1427 float f;
1428 } tmpvalue;
1430 tmpvalue.d = state->render_states[WINED3D_RS_POINTSIZE_MIN];
1431 if (tmpvalue.f != 1.0f)
1433 FIXME("WINED3D_RS_POINTSIZE_MIN not supported on this opengl, value is %f\n", tmpvalue.f);
1435 tmpvalue.d = state->render_states[WINED3D_RS_POINTSIZE_MAX];
1436 if (tmpvalue.f != 64.0f)
1438 FIXME("WINED3D_RS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f);
1443 void state_psizemin_ext(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1445 const struct wined3d_gl_info *gl_info = context->gl_info;
1446 union
1448 DWORD d;
1449 float f;
1450 } min, max;
1452 min.d = state->render_states[WINED3D_RS_POINTSIZE_MIN];
1453 max.d = state->render_states[WINED3D_RS_POINTSIZE_MAX];
1455 /* Max point size trumps min point size */
1456 if(min.f > max.f) {
1457 min.f = max.f;
1460 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, min.f);
1461 checkGLcall("glPointParameterfEXT(...)");
1462 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, max.f);
1463 checkGLcall("glPointParameterfEXT(...)");
1466 void state_psizemin_arb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1468 const struct wined3d_gl_info *gl_info = context->gl_info;
1469 union
1471 DWORD d;
1472 float f;
1473 } min, max;
1475 min.d = state->render_states[WINED3D_RS_POINTSIZE_MIN];
1476 max.d = state->render_states[WINED3D_RS_POINTSIZE_MAX];
1478 /* Max point size trumps min point size */
1479 if(min.f > max.f) {
1480 min.f = max.f;
1483 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, min.f);
1484 checkGLcall("glPointParameterfARB(...)");
1485 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, max.f);
1486 checkGLcall("glPointParameterfARB(...)");
1489 void state_pscale(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1491 const struct wined3d_gl_info *gl_info = context->gl_info;
1492 /* TODO: Group this with the viewport */
1494 * POINTSCALEENABLE controls how point size value is treated. If set to
1495 * true, the point size is scaled with respect to height of viewport.
1496 * When set to false point size is in pixels.
1499 /* Default values */
1500 GLfloat att[3] = {1.0f, 0.0f, 0.0f};
1501 union {
1502 DWORD d;
1503 float f;
1504 } pointSize, A, B, C;
1506 pointSize.d = state->render_states[WINED3D_RS_POINTSIZE];
1507 A.d = state->render_states[WINED3D_RS_POINTSCALE_A];
1508 B.d = state->render_states[WINED3D_RS_POINTSCALE_B];
1509 C.d = state->render_states[WINED3D_RS_POINTSCALE_C];
1511 if (state->render_states[WINED3D_RS_POINTSCALEENABLE])
1513 DWORD h = state->viewport.height;
1514 GLfloat scaleFactor;
1516 if (pointSize.f < gl_info->limits.pointsize_min)
1518 /* Minimum valid point size for OpenGL is driver specific. For Direct3D it is
1519 * 0.0f. This means that OpenGL will clamp really small point sizes to the
1520 * driver minimum. To correct for this we need to multiply by the scale factor when sizes
1521 * are less than 1.0f. scale_factor = 1.0f / point_size.
1523 scaleFactor = pointSize.f / gl_info->limits.pointsize_min;
1524 /* Clamp the point size, don't rely on the driver to do it. MacOS says min point size
1525 * is 1.0, but then accepts points below that and draws too small points
1527 pointSize.f = gl_info->limits.pointsize_min;
1529 else if(pointSize.f > gl_info->limits.pointsize_max)
1531 /* gl already scales the input to glPointSize,
1532 * d3d scales the result after the point size scale.
1533 * If the point size is bigger than the max size, use the
1534 * scaling to scale it bigger, and set the gl point size to max
1536 scaleFactor = pointSize.f / gl_info->limits.pointsize_max;
1537 TRACE("scale: %f\n", scaleFactor);
1538 pointSize.f = gl_info->limits.pointsize_max;
1539 } else {
1540 scaleFactor = 1.0f;
1542 scaleFactor = powf(h * scaleFactor, 2);
1544 att[0] = A.f / scaleFactor;
1545 att[1] = B.f / scaleFactor;
1546 att[2] = C.f / scaleFactor;
1549 if (gl_info->supported[ARB_POINT_PARAMETERS])
1551 GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
1552 checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...)");
1554 else if (gl_info->supported[EXT_POINT_PARAMETERS])
1556 GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
1557 checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)");
1559 else if (state->render_states[WINED3D_RS_POINTSCALEENABLE])
1561 WARN("POINT_PARAMETERS not supported in this version of opengl\n");
1564 gl_info->gl_ops.gl.p_glPointSize(pointSize.f);
1565 checkGLcall("glPointSize(...);");
1568 static void state_debug_monitor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1570 WARN("token: %#x.\n", state->render_states[WINED3D_RS_DEBUGMONITORTOKEN]);
1573 static void state_colorwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1575 DWORD mask0 = state->render_states[WINED3D_RS_COLORWRITEENABLE];
1576 DWORD mask1 = state->render_states[WINED3D_RS_COLORWRITEENABLE1];
1577 DWORD mask2 = state->render_states[WINED3D_RS_COLORWRITEENABLE2];
1578 DWORD mask3 = state->render_states[WINED3D_RS_COLORWRITEENABLE3];
1579 const struct wined3d_gl_info *gl_info = context->gl_info;
1581 TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
1582 mask0 & WINED3DCOLORWRITEENABLE_RED ? 1 : 0,
1583 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? 1 : 0,
1584 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? 1 : 0,
1585 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1586 gl_info->gl_ops.gl.p_glColorMask(mask0 & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1587 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1588 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1589 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1590 checkGLcall("glColorMask(...)");
1592 if (!((mask1 == mask0 && mask2 == mask0 && mask3 == mask0)
1593 || (mask1 == 0xf && mask2 == 0xf && mask3 == 0xf)))
1595 FIXME("WINED3D_RS_COLORWRITEENABLE/1/2/3, %#x/%#x/%#x/%#x not yet implemented.\n",
1596 mask0, mask1, mask2, mask3);
1597 FIXME("Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n");
1601 static void set_color_mask(const struct wined3d_gl_info *gl_info, UINT index, DWORD mask)
1603 GL_EXTCALL(glColorMaskIndexedEXT(index,
1604 mask & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1605 mask & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1606 mask & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1607 mask & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE));
1610 static void state_colorwrite0(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1612 set_color_mask(context->gl_info, 0, state->render_states[WINED3D_RS_COLORWRITEENABLE]);
1615 static void state_colorwrite1(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1617 set_color_mask(context->gl_info, 1, state->render_states[WINED3D_RS_COLORWRITEENABLE1]);
1620 static void state_colorwrite2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1622 set_color_mask(context->gl_info, 2, state->render_states[WINED3D_RS_COLORWRITEENABLE2]);
1625 static void state_colorwrite3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1627 set_color_mask(context->gl_info, 3, state->render_states[WINED3D_RS_COLORWRITEENABLE3]);
1630 static void state_localviewer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1632 const struct wined3d_gl_info *gl_info = context->gl_info;
1634 if (state->render_states[WINED3D_RS_LOCALVIEWER])
1636 gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1637 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1639 else
1641 gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1642 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
1646 static void state_lastpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1648 if (state->render_states[WINED3D_RS_LASTPIXEL])
1650 TRACE("Last Pixel Drawing Enabled\n");
1652 else
1654 static BOOL warned;
1655 if (!warned) {
1656 FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1657 warned = TRUE;
1658 } else {
1659 TRACE("Last Pixel Drawing Disabled, not handled yet\n");
1664 void state_pointsprite_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1666 static BOOL warned;
1668 /* TODO: NV_POINT_SPRITE */
1669 if (!warned && state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1671 /* A FIXME, not a WARN because point sprites should be software emulated if not supported by HW */
1672 FIXME("Point sprites not supported\n");
1673 warned = TRUE;
1677 void state_pointsprite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1679 const struct wined3d_gl_info *gl_info = context->gl_info;
1681 if (state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1683 gl_info->gl_ops.gl.p_glEnable(GL_POINT_SPRITE_ARB);
1684 checkGLcall("glEnable(GL_POINT_SPRITE_ARB)");
1686 else
1688 gl_info->gl_ops.gl.p_glDisable(GL_POINT_SPRITE_ARB);
1689 checkGLcall("glDisable(GL_POINT_SPRITE_ARB)");
1693 static void state_wrap(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1695 if (state->render_states[WINED3D_RS_WRAP0]
1696 || state->render_states[WINED3D_RS_WRAP1]
1697 || state->render_states[WINED3D_RS_WRAP2]
1698 || state->render_states[WINED3D_RS_WRAP3]
1699 || state->render_states[WINED3D_RS_WRAP4]
1700 || state->render_states[WINED3D_RS_WRAP5]
1701 || state->render_states[WINED3D_RS_WRAP6]
1702 || state->render_states[WINED3D_RS_WRAP7]
1703 || state->render_states[WINED3D_RS_WRAP8]
1704 || state->render_states[WINED3D_RS_WRAP9]
1705 || state->render_states[WINED3D_RS_WRAP10]
1706 || state->render_states[WINED3D_RS_WRAP11]
1707 || state->render_states[WINED3D_RS_WRAP12]
1708 || state->render_states[WINED3D_RS_WRAP13]
1709 || state->render_states[WINED3D_RS_WRAP14]
1710 || state->render_states[WINED3D_RS_WRAP15])
1711 FIXME("(WINED3D_RS_WRAP0) Texture wrapping not yet supported.\n");
1714 static void state_msaa_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1716 if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1717 WARN("Multisample antialiasing not supported by GL.\n");
1720 static void state_msaa(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1722 const struct wined3d_gl_info *gl_info = context->gl_info;
1724 if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1726 gl_info->gl_ops.gl.p_glEnable(GL_MULTISAMPLE_ARB);
1727 checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1729 else
1731 gl_info->gl_ops.gl.p_glDisable(GL_MULTISAMPLE_ARB);
1732 checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1736 static void state_scissor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1738 const struct wined3d_gl_info *gl_info = context->gl_info;
1740 if (state->render_states[WINED3D_RS_SCISSORTESTENABLE])
1742 gl_info->gl_ops.gl.p_glEnable(GL_SCISSOR_TEST);
1743 checkGLcall("glEnable(GL_SCISSOR_TEST)");
1745 else
1747 gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
1748 checkGLcall("glDisable(GL_SCISSOR_TEST)");
1752 /* The Direct3D depth bias is specified in normalized depth coordinates. In
1753 * OpenGL the bias is specified in units of "the smallest value that is
1754 * guaranteed to produce a resolvable offset for a given implementation". To
1755 * convert from D3D to GL we need to divide the D3D depth bias by that value.
1756 * There's no practical way to retrieve that value from a given GL
1757 * implementation, but the D3D application has essentially the same problem,
1758 * which makes a guess of the depth buffer format's highest possible value a
1759 * reasonable guess. Note that SLOPESCALEDEPTHBIAS is a scaling factor for the
1760 * depth slope, and doesn't need to be scaled. */
1761 static void state_depthbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1763 const struct wined3d_gl_info *gl_info = context->gl_info;
1765 if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]
1766 || state->render_states[WINED3D_RS_DEPTHBIAS])
1768 const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil;
1769 float scale;
1771 union
1773 DWORD d;
1774 float f;
1775 } scale_bias, const_bias;
1777 scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS];
1778 const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS];
1780 gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
1781 checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
1783 if (context->swapchain->device->wined3d->flags & WINED3D_LEGACY_DEPTH_BIAS)
1785 float bias = -(float)const_bias.d;
1786 gl_info->gl_ops.gl.p_glPolygonOffset(bias, bias);
1787 checkGLcall("glPolygonOffset");
1789 else
1791 if (depth)
1793 const struct wined3d_format *fmt = depth->format;
1794 scale = powf(2, fmt->depth_size) - 1;
1795 TRACE("Depth format %s, using depthbias scale of %.8e.\n",
1796 debug_d3dformat(fmt->id), scale);
1798 else
1800 /* The context manager will reapply this state on a depth stencil change */
1801 TRACE("No depth stencil, using depthbias scale of 0.0.\n");
1802 scale = 0.0f;
1805 gl_info->gl_ops.gl.p_glPolygonOffset(scale_bias.f, const_bias.f * scale);
1806 checkGLcall("glPolygonOffset(...)");
1809 else
1811 gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL);
1812 checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
1816 static void state_zvisible(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1818 if (state->render_states[WINED3D_RS_ZVISIBLE])
1819 FIXME("WINED3D_RS_ZVISIBLE not implemented.\n");
1822 static void state_perspective(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1824 const struct wined3d_gl_info *gl_info = context->gl_info;
1826 if (state->render_states[WINED3D_RS_TEXTUREPERSPECTIVE])
1828 gl_info->gl_ops.gl.p_glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1829 checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)");
1831 else
1833 gl_info->gl_ops.gl.p_glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1834 checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)");
1838 static void state_stippledalpha(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1840 if (state->render_states[WINED3D_RS_STIPPLEDALPHA])
1841 FIXME("Stippled Alpha not supported yet.\n");
1844 static void state_antialias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1846 if (state->render_states[WINED3D_RS_ANTIALIAS])
1847 FIXME("Antialias not supported yet.\n");
1850 static void state_multisampmask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1852 if (state->render_states[WINED3D_RS_MULTISAMPLEMASK] != 0xffffffff)
1853 FIXME("WINED3D_RS_MULTISAMPLEMASK %#x not yet implemented.\n",
1854 state->render_states[WINED3D_RS_MULTISAMPLEMASK]);
1857 static void state_patchedgestyle(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1859 if (state->render_states[WINED3D_RS_PATCHEDGESTYLE] != WINED3D_PATCH_EDGE_DISCRETE)
1860 FIXME("WINED3D_RS_PATCHEDGESTYLE %#x not yet implemented.\n",
1861 state->render_states[WINED3D_RS_PATCHEDGESTYLE]);
1864 static void state_patchsegments(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1866 union {
1867 DWORD d;
1868 float f;
1869 } tmpvalue;
1870 tmpvalue.f = 1.0f;
1872 if (state->render_states[WINED3D_RS_PATCHSEGMENTS] != tmpvalue.d)
1874 static BOOL displayed = FALSE;
1876 tmpvalue.d = state->render_states[WINED3D_RS_PATCHSEGMENTS];
1877 if(!displayed)
1878 FIXME("(WINED3D_RS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f);
1880 displayed = TRUE;
1884 static void state_positiondegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1886 if (state->render_states[WINED3D_RS_POSITIONDEGREE] != WINED3D_DEGREE_CUBIC)
1887 FIXME("WINED3D_RS_POSITIONDEGREE %#x not yet implemented.\n",
1888 state->render_states[WINED3D_RS_POSITIONDEGREE]);
1891 static void state_normaldegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1893 if (state->render_states[WINED3D_RS_NORMALDEGREE] != WINED3D_DEGREE_LINEAR)
1894 FIXME("WINED3D_RS_NORMALDEGREE %#x not yet implemented.\n",
1895 state->render_states[WINED3D_RS_NORMALDEGREE]);
1898 static void state_tessellation(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1900 if (state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION])
1901 FIXME("WINED3D_RS_ENABLEADAPTIVETESSELLATION %#x not yet implemented.\n",
1902 state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION]);
1905 static void state_nvdb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1907 union {
1908 DWORD d;
1909 float f;
1910 } zmin, zmax;
1912 const struct wined3d_gl_info *gl_info = context->gl_info;
1914 if (state->render_states[WINED3D_RS_ADAPTIVETESS_X] == WINED3DFMT_NVDB)
1916 zmin.d = state->render_states[WINED3D_RS_ADAPTIVETESS_Z];
1917 zmax.d = state->render_states[WINED3D_RS_ADAPTIVETESS_W];
1919 /* If zmin is larger than zmax INVALID_VALUE error is generated.
1920 * In d3d9 test is not performed in this case*/
1921 if (zmin.f <= zmax.f)
1923 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_BOUNDS_TEST_EXT);
1924 checkGLcall("glEnable(GL_DEPTH_BOUNDS_TEST_EXT)");
1925 GL_EXTCALL(glDepthBoundsEXT(zmin.f, zmax.f));
1926 checkGLcall("glDepthBoundsEXT(...)");
1928 else
1930 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1931 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1934 else
1936 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1937 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1940 state_tessellation(context, state, STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION));
1943 static void state_wrapu(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1945 if (state->render_states[WINED3D_RS_WRAPU])
1946 FIXME("Render state WINED3D_RS_WRAPU not implemented yet.\n");
1949 static void state_wrapv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1951 if (state->render_states[WINED3D_RS_WRAPV])
1952 FIXME("Render state WINED3D_RS_WRAPV not implemented yet.\n");
1955 static void state_monoenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1957 if (state->render_states[WINED3D_RS_MONOENABLE])
1958 FIXME("Render state WINED3D_RS_MONOENABLE not implemented yet.\n");
1961 static void state_rop2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1963 if (state->render_states[WINED3D_RS_ROP2])
1964 FIXME("Render state WINED3D_RS_ROP2 not implemented yet.\n");
1967 static void state_planemask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1969 if (state->render_states[WINED3D_RS_PLANEMASK])
1970 FIXME("Render state WINED3D_RS_PLANEMASK not implemented yet.\n");
1973 static void state_subpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1975 if (state->render_states[WINED3D_RS_SUBPIXEL])
1976 FIXME("Render state WINED3D_RS_SUBPIXEL not implemented yet.\n");
1979 static void state_subpixelx(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1981 if (state->render_states[WINED3D_RS_SUBPIXELX])
1982 FIXME("Render state WINED3D_RS_SUBPIXELX not implemented yet.\n");
1985 static void state_stippleenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1987 if (state->render_states[WINED3D_RS_STIPPLEENABLE])
1988 FIXME("Render state WINED3D_RS_STIPPLEENABLE not implemented yet.\n");
1991 static void state_mipmaplodbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1993 if (state->render_states[WINED3D_RS_MIPMAPLODBIAS])
1994 FIXME("Render state WINED3D_RS_MIPMAPLODBIAS not implemented yet.\n");
1997 static void state_anisotropy(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1999 if (state->render_states[WINED3D_RS_ANISOTROPY])
2000 FIXME("Render state WINED3D_RS_ANISOTROPY not implemented yet.\n");
2003 static void state_flushbatch(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2005 if (state->render_states[WINED3D_RS_FLUSHBATCH])
2006 FIXME("Render state WINED3D_RS_FLUSHBATCH not implemented yet.\n");
2009 static void state_translucentsi(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2011 if (state->render_states[WINED3D_RS_TRANSLUCENTSORTINDEPENDENT])
2012 FIXME("Render state WINED3D_RS_TRANSLUCENTSORTINDEPENDENT not implemented yet.\n");
2015 static void state_extents(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2017 if (state->render_states[WINED3D_RS_EXTENTS])
2018 FIXME("Render state WINED3D_RS_EXTENTS not implemented yet.\n");
2021 static void state_ckeyblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2023 if (state->render_states[WINED3D_RS_COLORKEYBLENDENABLE])
2024 FIXME("Render state WINED3D_RS_COLORKEYBLENDENABLE not implemented yet.\n");
2027 static void state_swvp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2029 if (state->render_states[WINED3D_RS_SOFTWAREVERTEXPROCESSING])
2030 FIXME("Software vertex processing not implemented.\n");
2033 static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* operand) {
2034 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the
2035 * input should be used for all input components. The WINED3DTA_COMPLEMENT
2036 * flag specifies the complement of the input should be used. */
2037 BOOL from_alpha = is_alpha || arg & WINED3DTA_ALPHAREPLICATE;
2038 BOOL complement = arg & WINED3DTA_COMPLEMENT;
2040 /* Calculate the operand */
2041 if (complement) {
2042 if (from_alpha) *operand = GL_ONE_MINUS_SRC_ALPHA;
2043 else *operand = GL_ONE_MINUS_SRC_COLOR;
2044 } else {
2045 if (from_alpha) *operand = GL_SRC_ALPHA;
2046 else *operand = GL_SRC_COLOR;
2049 /* Calculate the source */
2050 switch (arg & WINED3DTA_SELECTMASK) {
2051 case WINED3DTA_CURRENT: *source = GL_PREVIOUS_EXT; break;
2052 case WINED3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT; break;
2053 case WINED3DTA_TEXTURE: *source = GL_TEXTURE; break;
2054 case WINED3DTA_TFACTOR: *source = GL_CONSTANT_EXT; break;
2055 case WINED3DTA_SPECULAR:
2057 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
2058 * 'Secondary color' and isn't supported until base GL supports it
2059 * There is no concept of temp registers as far as I can tell
2061 FIXME("Unhandled texture arg WINED3DTA_SPECULAR\n");
2062 *source = GL_TEXTURE;
2063 break;
2064 default:
2065 FIXME("Unrecognized texture arg %#x\n", arg);
2066 *source = GL_TEXTURE;
2067 break;
2071 /* Setup the texture operations texture stage states */
2072 static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
2073 BOOL isAlpha, int Stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3)
2075 GLenum src1, src2, src3;
2076 GLenum opr1, opr2, opr3;
2077 GLenum comb_target;
2078 GLenum src0_target, src1_target, src2_target;
2079 GLenum opr0_target, opr1_target, opr2_target;
2080 GLenum scal_target;
2081 GLenum opr=0, invopr, src3_target, opr3_target;
2082 BOOL Handled = FALSE;
2084 TRACE("Alpha?(%d), Stage:%d Op(%s), a1(%d), a2(%d), a3(%d)\n", isAlpha, Stage, debug_d3dtop(op), arg1, arg2, arg3);
2086 /* Operations usually involve two args, src0 and src1 and are operations
2087 * of the form (a1 <operation> a2). However, some of the more complex
2088 * operations take 3 parameters. Instead of the (sensible) addition of a3,
2089 * Microsoft added in a third parameter called a0. Therefore these are
2090 * operations of the form a0 <operation> a1 <operation> a2. I.e., the new
2091 * parameter goes to the front.
2093 * However, below we treat the new (a0) parameter as src2/opr2, so in the
2094 * actual functions below, expect their syntax to differ slightly to those
2095 * listed in the manuals. I.e., replace arg1 with arg3, arg2 with arg1 and
2096 * arg3 with arg2. This affects WINED3DTOP_MULTIPLYADD and WINED3DTOP_LERP. */
2098 if (isAlpha)
2100 comb_target = GL_COMBINE_ALPHA;
2101 src0_target = GL_SOURCE0_ALPHA;
2102 src1_target = GL_SOURCE1_ALPHA;
2103 src2_target = GL_SOURCE2_ALPHA;
2104 opr0_target = GL_OPERAND0_ALPHA;
2105 opr1_target = GL_OPERAND1_ALPHA;
2106 opr2_target = GL_OPERAND2_ALPHA;
2107 scal_target = GL_ALPHA_SCALE;
2109 else
2111 comb_target = GL_COMBINE_RGB;
2112 src0_target = GL_SOURCE0_RGB;
2113 src1_target = GL_SOURCE1_RGB;
2114 src2_target = GL_SOURCE2_RGB;
2115 opr0_target = GL_OPERAND0_RGB;
2116 opr1_target = GL_OPERAND1_RGB;
2117 opr2_target = GL_OPERAND2_RGB;
2118 scal_target = GL_RGB_SCALE;
2121 /* If a texture stage references an invalid texture unit the stage just
2122 * passes through the result from the previous stage */
2123 if (is_invalid_op(state, Stage, op, arg1, arg2, arg3))
2125 arg1 = WINED3DTA_CURRENT;
2126 op = WINED3D_TOP_SELECT_ARG1;
2129 if (isAlpha && !state->textures[Stage] && arg1 == WINED3DTA_TEXTURE)
2131 get_src_and_opr(WINED3DTA_DIFFUSE, isAlpha, &src1, &opr1);
2132 } else {
2133 get_src_and_opr(arg1, isAlpha, &src1, &opr1);
2135 get_src_and_opr(arg2, isAlpha, &src2, &opr2);
2136 get_src_and_opr(arg3, isAlpha, &src3, &opr3);
2138 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
2140 Handled = TRUE; /* Assume will be handled */
2142 /* Other texture operations require special extensions: */
2143 if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
2145 if (isAlpha) {
2146 opr = GL_SRC_ALPHA;
2147 invopr = GL_ONE_MINUS_SRC_ALPHA;
2148 src3_target = GL_SOURCE3_ALPHA_NV;
2149 opr3_target = GL_OPERAND3_ALPHA_NV;
2150 } else {
2151 opr = GL_SRC_COLOR;
2152 invopr = GL_ONE_MINUS_SRC_COLOR;
2153 src3_target = GL_SOURCE3_RGB_NV;
2154 opr3_target = GL_OPERAND3_RGB_NV;
2156 switch (op)
2158 case WINED3D_TOP_DISABLE: /* Only for alpha */
2159 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2160 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2161 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2162 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2163 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2164 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2165 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2166 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2167 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2168 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2169 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2170 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2171 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2172 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2173 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2174 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2175 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2176 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2177 break;
2179 case WINED3D_TOP_SELECT_ARG1: /* = a1 * 1 + 0 * 0 */
2180 case WINED3D_TOP_SELECT_ARG2: /* = a2 * 1 + 0 * 0 */
2181 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2182 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2183 if (op == WINED3D_TOP_SELECT_ARG1)
2185 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2186 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2187 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2188 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2190 else
2192 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2193 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2194 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2195 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2197 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2198 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2199 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2200 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2201 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2202 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2203 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2204 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2205 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2206 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2207 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2208 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2209 break;
2211 case WINED3D_TOP_MODULATE:
2212 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2213 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2214 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2215 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2216 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2217 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2218 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2219 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2220 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2221 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2222 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2223 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2224 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2225 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2226 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2227 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2228 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2229 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2230 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2231 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2232 break;
2233 case WINED3D_TOP_MODULATE_2X:
2234 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2235 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2236 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2237 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2238 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2239 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2240 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2241 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2242 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2243 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2244 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2245 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2246 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2247 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2248 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2249 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2250 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2251 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2252 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2253 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2254 break;
2255 case WINED3D_TOP_MODULATE_4X:
2256 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2257 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2258 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2259 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2260 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2261 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2262 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2263 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2264 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2265 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2266 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2267 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2268 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2269 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2270 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2271 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2272 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2273 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2274 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2275 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2276 break;
2278 case WINED3D_TOP_ADD:
2279 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2280 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2281 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2282 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2283 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2284 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2285 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2286 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2287 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2288 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2289 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2290 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2291 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2292 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2293 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2294 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2295 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2296 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2297 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2298 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2299 break;
2301 case WINED3D_TOP_ADD_SIGNED:
2302 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2303 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2304 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2305 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2306 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2307 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2308 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2309 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2310 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2311 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2312 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2313 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2314 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2315 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2316 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2317 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2318 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2319 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2320 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2321 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2322 break;
2324 case WINED3D_TOP_ADD_SIGNED_2X:
2325 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2326 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2327 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2328 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2329 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2330 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2331 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2332 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2333 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2334 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2335 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2336 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2337 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2338 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2339 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2340 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2341 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2342 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2343 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2344 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2345 break;
2347 case WINED3D_TOP_ADD_SMOOTH:
2348 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2349 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2350 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2351 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2352 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2353 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2354 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2355 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2356 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2357 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2358 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2359 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2360 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2361 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2362 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2363 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2364 switch (opr1) {
2365 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2366 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2367 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2368 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2370 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2371 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2372 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2373 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2374 break;
2376 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2377 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2378 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2379 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2380 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2381 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2382 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2383 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR);
2384 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR");
2385 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2386 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2387 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2388 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2389 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2390 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2391 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR);
2392 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR");
2393 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2394 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2395 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2396 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2397 break;
2398 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2399 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2400 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2401 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2402 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2403 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2404 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2405 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
2406 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
2407 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2408 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2409 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2410 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2411 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2412 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2413 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2414 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2415 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2416 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2417 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2418 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2419 break;
2420 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2421 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2422 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2423 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2424 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2425 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2426 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2427 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_CONSTANT);
2428 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_CONSTANT");
2429 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2430 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2431 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2432 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2433 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2434 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2435 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_CONSTANT);
2436 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_CONSTANT");
2437 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2438 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2439 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2440 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2441 break;
2442 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2443 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2444 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2445 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2446 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2447 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2448 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2449 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2450 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2451 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2452 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2453 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2454 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2455 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2456 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2457 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2458 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2459 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2460 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2461 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2462 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2463 break;
2464 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2465 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2466 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2467 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
2468 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2469 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2470 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
2471 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2472 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2473 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2474 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2475 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
2476 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2477 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2478 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
2479 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2480 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2481 switch (opr) {
2482 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2483 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2485 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2486 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2487 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2488 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2489 break;
2490 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2491 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2492 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2493 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2494 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2495 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2496 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2497 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2498 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2499 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2500 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2501 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2502 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2503 switch (opr1) {
2504 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2505 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2507 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2508 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2509 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2510 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2511 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2512 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2513 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2514 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2515 break;
2516 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2517 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2518 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2519 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2520 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2521 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2522 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2523 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2524 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2525 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2526 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2527 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2528 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2529 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2530 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2531 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2532 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2533 switch (opr1) {
2534 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2535 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2536 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2537 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2539 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2540 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2541 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2542 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2543 break;
2544 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
2545 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2546 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2547 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2548 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2549 switch (opr1) {
2550 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2551 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2552 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2553 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2555 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2556 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2557 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2558 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2559 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2560 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2561 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2562 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2563 switch (opr1) {
2564 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2565 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2567 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2568 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2569 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2570 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2571 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2572 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2573 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2574 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2575 break;
2576 case WINED3D_TOP_MULTIPLY_ADD:
2577 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2578 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2579 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
2580 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2581 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
2582 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2583 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2584 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2585 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2586 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2587 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2588 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2589 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
2590 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2591 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
2592 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
2593 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
2594 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
2595 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2596 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2597 break;
2599 case WINED3D_TOP_BUMPENVMAP:
2600 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
2601 FIXME("Implement bump environment mapping in GL_NV_texture_env_combine4 path\n");
2602 Handled = FALSE;
2603 break;
2605 default:
2606 Handled = FALSE;
2608 if (Handled)
2610 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
2611 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
2613 return;
2615 } /* GL_NV_texture_env_combine4 */
2617 Handled = TRUE; /* Again, assume handled */
2618 switch (op) {
2619 case WINED3D_TOP_DISABLE: /* Only for alpha */
2620 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2621 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2622 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2623 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
2624 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2625 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
2626 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2627 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2628 break;
2629 case WINED3D_TOP_SELECT_ARG1:
2630 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2631 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2632 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2633 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2634 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2635 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2636 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2637 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2638 break;
2639 case WINED3D_TOP_SELECT_ARG2:
2640 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2641 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2642 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2643 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2644 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2645 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2646 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2647 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2648 break;
2649 case WINED3D_TOP_MODULATE:
2650 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2651 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2652 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2653 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2654 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2655 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2656 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2657 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2658 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2659 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2660 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2661 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2662 break;
2663 case WINED3D_TOP_MODULATE_2X:
2664 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2665 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2666 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2667 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2668 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2669 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2670 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2671 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2672 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2673 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2674 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2675 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2676 break;
2677 case WINED3D_TOP_MODULATE_4X:
2678 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2679 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2680 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2681 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2682 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2683 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2684 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2685 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2686 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2687 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2688 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2689 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2690 break;
2691 case WINED3D_TOP_ADD:
2692 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2693 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2694 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2695 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2696 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2697 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2698 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2699 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2700 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2701 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2702 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2703 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2704 break;
2705 case WINED3D_TOP_ADD_SIGNED:
2706 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2707 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2708 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2709 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2710 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2711 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2712 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2713 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2714 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2715 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2716 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2717 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2718 break;
2719 case WINED3D_TOP_ADD_SIGNED_2X:
2720 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2721 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2722 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2723 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2724 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2725 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2726 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2727 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2728 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2729 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2730 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2731 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2732 break;
2733 case WINED3D_TOP_SUBTRACT:
2734 if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE])
2736 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
2737 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_SUBTRACT");
2738 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2739 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2740 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2741 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2742 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2743 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2744 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2745 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2746 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2747 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2748 } else {
2749 FIXME("This version of opengl does not support GL_SUBTRACT\n");
2751 break;
2753 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2754 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2755 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2756 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2757 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2758 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2759 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2760 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2761 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2762 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2763 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2764 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR);
2765 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
2766 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2767 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2768 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2769 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2770 break;
2771 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2772 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2773 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2774 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2775 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2776 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2777 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2778 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2779 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2780 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2781 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2782 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
2783 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
2784 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2785 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2786 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2787 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2788 break;
2789 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2790 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2791 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2792 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2793 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2794 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2795 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2796 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2797 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2798 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2799 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2800 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_CONSTANT);
2801 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
2802 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2803 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2804 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2805 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2806 break;
2807 case WINED3D_TOP_BLEND_CURRENT_ALPHA:
2808 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2809 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2810 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2811 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2812 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2813 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2814 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2815 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2816 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2817 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2818 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PREVIOUS);
2819 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
2820 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2821 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2822 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2823 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2824 break;
2825 case WINED3D_TOP_DOTPRODUCT3:
2826 if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
2828 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
2829 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
2831 else if (gl_info->supported[EXT_TEXTURE_ENV_DOT3])
2833 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
2834 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
2835 } else {
2836 FIXME("This version of opengl does not support GL_DOT3\n");
2838 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2839 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2840 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2841 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2842 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2843 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2844 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2845 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2846 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2847 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2848 break;
2849 case WINED3D_TOP_LERP:
2850 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2851 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2852 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2853 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2854 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2855 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2856 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2857 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2858 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2859 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2860 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
2861 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
2862 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
2863 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
2864 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2865 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2866 break;
2867 case WINED3D_TOP_ADD_SMOOTH:
2868 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2870 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2871 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2872 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2873 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2874 switch (opr1) {
2875 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2876 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2877 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2878 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2880 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2881 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2882 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2883 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2884 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2885 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2886 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2887 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2888 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2889 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2890 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2891 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2892 } else
2893 Handled = FALSE;
2894 break;
2895 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2896 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2898 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2899 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2900 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
2901 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
2902 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
2903 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
2904 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2905 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2906 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2907 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2908 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2909 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2910 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2911 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2912 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2913 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2914 } else
2915 Handled = FALSE;
2916 break;
2917 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2918 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2920 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2921 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2922 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2923 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2924 switch (opr1) {
2925 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2926 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2927 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2928 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2930 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2931 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2932 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2933 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2934 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2935 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2936 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2937 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2938 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2939 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2940 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2941 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2942 } else
2943 Handled = FALSE;
2944 break;
2945 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2946 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2948 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2949 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2950 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2951 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2952 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2953 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2954 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2955 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2956 switch (opr1) {
2957 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2958 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2959 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2960 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2962 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2963 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2964 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2965 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2966 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2967 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2968 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2969 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2970 } else
2971 Handled = FALSE;
2972 break;
2973 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2974 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2976 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2977 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2978 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2979 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2980 switch (opr1) {
2981 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2982 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2983 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2984 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2986 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2987 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2988 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2989 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2990 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2991 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2992 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2993 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2994 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2995 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2996 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2997 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2998 } else
2999 Handled = FALSE;
3000 break;
3001 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
3002 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
3004 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
3005 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
3006 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
3007 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
3008 switch (opr1) {
3009 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
3010 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
3011 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
3012 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
3014 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
3015 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
3016 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
3017 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
3018 switch (opr1) {
3019 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
3020 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
3021 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
3022 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
3024 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
3025 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
3026 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
3027 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
3028 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
3029 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
3030 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
3031 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
3032 } else
3033 Handled = FALSE;
3034 break;
3035 case WINED3D_TOP_MULTIPLY_ADD:
3036 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
3038 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
3039 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
3040 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
3041 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
3042 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
3043 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
3044 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src3);
3045 checkGLcall("GL_TEXTURE_ENV, src1_target, src3");
3046 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr3);
3047 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr3");
3048 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
3049 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
3050 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
3051 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
3052 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
3053 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
3054 } else
3055 Handled = FALSE;
3056 break;
3057 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
3058 case WINED3D_TOP_BUMPENVMAP:
3059 if (gl_info->supported[NV_TEXTURE_SHADER2])
3061 /* Technically texture shader support without register combiners is possible, but not expected to occur
3062 * on real world cards, so for now a fixme should be enough
3064 FIXME("Implement bump mapping with GL_NV_texture_shader in non register combiner path\n");
3066 Handled = FALSE;
3067 break;
3069 default:
3070 Handled = FALSE;
3073 if (Handled) {
3074 BOOL combineOK = TRUE;
3075 if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
3077 DWORD op2;
3079 if (isAlpha)
3080 op2 = state->texture_states[Stage][WINED3D_TSS_COLOR_OP];
3081 else
3082 op2 = state->texture_states[Stage][WINED3D_TSS_ALPHA_OP];
3084 /* Note: If COMBINE4 in effect can't go back to combine! */
3085 switch (op2)
3087 case WINED3D_TOP_ADD_SMOOTH:
3088 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
3089 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
3090 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
3091 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
3092 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
3093 case WINED3D_TOP_MULTIPLY_ADD:
3094 /* Ignore those implemented in both cases */
3095 switch (op)
3097 case WINED3D_TOP_SELECT_ARG1:
3098 case WINED3D_TOP_SELECT_ARG2:
3099 combineOK = FALSE;
3100 Handled = FALSE;
3101 break;
3102 default:
3103 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%s, otherop=%s, isAlpha(%d)\n", debug_d3dtop(op), debug_d3dtop(op2), isAlpha);
3104 return;
3109 if (combineOK)
3111 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
3112 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE");
3114 return;
3118 /* After all the extensions, if still unhandled, report fixme */
3119 FIXME("Unhandled texture operation %s\n", debug_d3dtop(op));
3123 static void tex_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3125 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3126 BOOL tex_used = context->fixed_function_usage_map & (1 << stage);
3127 DWORD mapped_stage = context->tex_unit_map[stage];
3128 const struct wined3d_gl_info *gl_info = context->gl_info;
3130 TRACE("Setting color op for stage %d\n", stage);
3132 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
3133 if (use_ps(state)) return;
3135 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
3137 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3139 if (tex_used && mapped_stage >= gl_info->limits.textures)
3141 FIXME("Attempt to enable unsupported stage!\n");
3142 return;
3144 context_active_texture(context, gl_info, mapped_stage);
3147 if (stage >= context->lowest_disabled_stage)
3149 TRACE("Stage disabled\n");
3150 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3152 /* Disable everything here */
3153 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3154 checkGLcall("glDisable(GL_TEXTURE_2D)");
3155 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3156 checkGLcall("glDisable(GL_TEXTURE_3D)");
3157 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3159 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3160 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
3162 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3164 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3165 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
3168 /* All done */
3169 return;
3172 /* The sampler will also activate the correct texture dimensions, so no
3173 * need to do it here if the sampler for this stage is dirty. */
3174 if (!isStateDirty(context, STATE_SAMPLER(stage)) && tex_used)
3175 texture_activate_dimensions(state->textures[stage], gl_info);
3177 set_tex_op(gl_info, state, FALSE, stage,
3178 state->texture_states[stage][WINED3D_TSS_COLOR_OP],
3179 state->texture_states[stage][WINED3D_TSS_COLOR_ARG1],
3180 state->texture_states[stage][WINED3D_TSS_COLOR_ARG2],
3181 state->texture_states[stage][WINED3D_TSS_COLOR_ARG0]);
3184 void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3186 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3187 BOOL tex_used = context->fixed_function_usage_map & (1 << stage);
3188 DWORD mapped_stage = context->tex_unit_map[stage];
3189 const struct wined3d_gl_info *gl_info = context->gl_info;
3190 DWORD op, arg1, arg2, arg0;
3192 TRACE("Setting alpha op for stage %d\n", stage);
3193 /* Do not care for enabled / disabled stages, just assign the settings. colorop disables / enables required stuff */
3194 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3196 if (tex_used && mapped_stage >= gl_info->limits.textures)
3198 FIXME("Attempt to enable unsupported stage!\n");
3199 return;
3201 context_active_texture(context, gl_info, mapped_stage);
3204 op = state->texture_states[stage][WINED3D_TSS_ALPHA_OP];
3205 arg1 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG1];
3206 arg2 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG2];
3207 arg0 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG0];
3209 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !stage && state->textures[0])
3211 struct wined3d_texture *texture = state->textures[0];
3212 GLenum texture_dimensions = texture->target;
3214 if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
3216 if (texture->color_key_flags & WINEDDSD_CKSRCBLT && !texture->resource.format->alpha_size)
3218 /* Color keying needs to pass alpha values from the texture through to have the alpha test work
3219 * properly. On the other hand applications can still use texture combiners apparently. This code
3220 * takes care that apps cannot remove the texture's alpha channel entirely.
3222 * The fixup is required for Prince of Persia 3D(prison bars), while Moto racer 2 requires
3223 * D3DTOP_MODULATE to work on color keyed surfaces. Aliens vs Predator 1 uses color keyed textures
3224 * and alpha component of diffuse color to draw things like translucent text and perform other
3225 * blending effects.
3227 * Aliens vs Predator 1 relies on diffuse alpha having an effect, so it cannot be ignored. To
3228 * provide the behavior expected by the game, while emulating the colorkey, diffuse alpha must be
3229 * modulated with texture alpha. OTOH, Moto racer 2 at some points sets alphaop/alphaarg to
3230 * SELECTARG/CURRENT, yet puts garbage in diffuse alpha (zeroes). This works on native, because the
3231 * game disables alpha test and alpha blending. Alpha test is overwritten by wine's for purposes of
3232 * color-keying though, so this will lead to missing geometry if texture alpha is modulated (pixels
3233 * fail alpha test). To get around this, ALPHABLENDENABLE state is checked: if the app enables alpha
3234 * blending, it can be expected to provide meaningful values in diffuse alpha, so it should be
3235 * modulated with texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture
3236 * alpha.
3238 * What to do with multitexturing? So far no app has been found that uses color keying with
3239 * multitexturing */
3240 if (op == WINED3D_TOP_DISABLE)
3242 arg1 = WINED3DTA_TEXTURE;
3243 op = WINED3D_TOP_SELECT_ARG1;
3245 else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE)
3247 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3249 arg2 = WINED3DTA_TEXTURE;
3250 op = WINED3D_TOP_MODULATE;
3252 else arg1 = WINED3DTA_TEXTURE;
3254 else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE)
3256 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3258 arg1 = WINED3DTA_TEXTURE;
3259 op = WINED3D_TOP_MODULATE;
3261 else arg2 = WINED3DTA_TEXTURE;
3267 /* tex_alphaop is shared between the ffp and nvrc because the difference only comes down to
3268 * this if block here, and the other code(color keying, texture unit selection) are the same
3270 TRACE("Setting alpha op for stage %d\n", stage);
3271 if (gl_info->supported[NV_REGISTER_COMBINERS])
3273 set_tex_op_nvrc(gl_info, state, TRUE, stage, op, arg1, arg2, arg0,
3274 mapped_stage, state->texture_states[stage][WINED3D_TSS_RESULT_ARG]);
3276 else
3278 set_tex_op(gl_info, state, TRUE, stage, op, arg1, arg2, arg0);
3282 void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3284 DWORD texUnit = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3285 const struct wined3d_device *device = context->swapchain->device;
3286 const struct wined3d_gl_info *gl_info = context->gl_info;
3287 DWORD mapped_stage = context->tex_unit_map[texUnit];
3288 BOOL generated;
3289 int coordIdx;
3291 /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
3292 if (use_vs(state) || isStateDirty(context, STATE_VDECL))
3294 TRACE("Using a vertex shader, or stream sources not sorted out yet, skipping\n");
3295 return;
3298 if (mapped_stage == WINED3D_UNMAPPED_STAGE) return;
3299 if (mapped_stage >= gl_info->limits.textures) return;
3301 context_active_texture(context, gl_info, mapped_stage);
3302 generated = (state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU;
3303 coordIdx = min(state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff], MAX_TEXTURES - 1);
3305 set_texture_matrix(gl_info, &state->transforms[WINED3D_TS_TEXTURE0 + texUnit].u.m[0][0],
3306 state->texture_states[texUnit][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS],
3307 generated, context->last_was_rhw,
3308 context->stream_info.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))
3309 ? context->stream_info.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format->id
3310 : WINED3DFMT_UNKNOWN,
3311 device->shader_backend->shader_has_ffp_proj_control(device->shader_priv));
3313 /* The sampler applying function calls us if this changes */
3314 if ((context->lastWasPow2Texture & (1 << texUnit)) && state->textures[texUnit])
3316 if(generated) {
3317 FIXME("Non-power2 texture being used with generated texture coords\n");
3319 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
3320 fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
3321 if (!use_ps(state))
3323 TRACE("Non power two matrix multiply fixup\n");
3324 gl_info->gl_ops.gl.p_glMultMatrixf(state->textures[texUnit]->pow2_matrix);
3329 static void unload_tex_coords(const struct wined3d_gl_info *gl_info)
3331 unsigned int texture_idx;
3333 for (texture_idx = 0; texture_idx < gl_info->limits.texture_coords; ++texture_idx)
3335 GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx));
3336 gl_info->gl_ops.gl.p_glDisableClientState(GL_TEXTURE_COORD_ARRAY);
3340 static void load_tex_coords(const struct wined3d_context *context, const struct wined3d_stream_info *si,
3341 GLuint *curVBO, const struct wined3d_state *state)
3343 const struct wined3d_gl_info *gl_info = context->gl_info;
3344 unsigned int mapped_stage = 0;
3345 unsigned int textureNo = 0;
3347 for (textureNo = 0; textureNo < context->d3d_info->limits.ffp_blend_stages; ++textureNo)
3349 int coordIdx = state->texture_states[textureNo][WINED3D_TSS_TEXCOORD_INDEX];
3351 mapped_stage = context->tex_unit_map[textureNo];
3352 if (mapped_stage == WINED3D_UNMAPPED_STAGE) continue;
3354 if (mapped_stage >= gl_info->limits.texture_coords)
3356 FIXME("Attempted to load unsupported texture coordinate %u\n", mapped_stage);
3357 continue;
3360 if (coordIdx < MAX_TEXTURES && (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))))
3362 const struct wined3d_stream_info_element *e = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
3364 TRACE("Setting up texture %u, idx %d, coordindx %u, data {%#x:%p}.\n",
3365 textureNo, mapped_stage, coordIdx, e->data.buffer_object, e->data.addr);
3367 if (*curVBO != e->data.buffer_object)
3369 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object));
3370 checkGLcall("glBindBufferARB");
3371 *curVBO = e->data.buffer_object;
3374 GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
3375 checkGLcall("glClientActiveTextureARB");
3377 /* The coords to supply depend completely on the fvf / vertex shader */
3378 gl_info->gl_ops.gl.p_glTexCoordPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
3379 e->data.addr + state->load_base_vertex_index * e->stride);
3380 gl_info->gl_ops.gl.p_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
3382 else
3384 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + mapped_stage, 0, 0, 0, 1));
3387 if (gl_info->supported[NV_REGISTER_COMBINERS])
3389 /* The number of the mapped stages increases monotonically, so it's fine to use the last used one. */
3390 for (textureNo = mapped_stage + 1; textureNo < gl_info->limits.textures; ++textureNo)
3392 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1));
3396 checkGLcall("loadTexCoords");
3399 static void tex_coordindex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3401 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3402 static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f };
3403 static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f };
3404 static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f };
3405 static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f };
3406 const struct wined3d_gl_info *gl_info = context->gl_info;
3407 DWORD mapped_stage = context->tex_unit_map[stage];
3409 if (mapped_stage == WINED3D_UNMAPPED_STAGE)
3411 TRACE("No texture unit mapped to stage %d. Skipping texture coordinates.\n", stage);
3412 return;
3415 if (mapped_stage >= gl_info->limits.fragment_samplers)
3417 WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage);
3418 return;
3420 context_active_texture(context, gl_info, mapped_stage);
3422 /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
3424 * FIXME: When using generated texture coordinates, the index value is used to specify the wrapping mode.
3425 * eg. SetTextureStageState( 0, WINED3D_TSS_TEXCOORDINDEX, WINED3D_TSS_TCI_CAMERASPACEPOSITION | 1 );
3426 * means use the vertex position (camera-space) as the input texture coordinates
3427 * for this texture stage, and the wrap mode set in the WINED3D_RS_WRAP1 render
3428 * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up
3429 * to the TEXCOORDINDEX value
3431 switch (state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
3433 case WINED3DTSS_TCI_PASSTHRU:
3434 /* Use the specified texture coordinates contained within the
3435 * vertex format. This value resolves to zero. */
3436 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
3437 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
3438 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3439 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3440 checkGLcall("WINED3DTSS_TCI_PASSTHRU - Disable texgen.");
3441 break;
3443 case WINED3DTSS_TCI_CAMERASPACEPOSITION:
3444 /* CameraSpacePosition means use the vertex position, transformed to camera space,
3445 * as the input texture coordinates for this stage's texture transformation. This
3446 * equates roughly to EYE_LINEAR */
3448 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3449 gl_info->gl_ops.gl.p_glPushMatrix();
3450 gl_info->gl_ops.gl.p_glLoadIdentity();
3451 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3452 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3453 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3454 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3455 gl_info->gl_ops.gl.p_glPopMatrix();
3456 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set eye plane.");
3458 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3459 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3460 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3461 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set texgen mode.");
3463 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3464 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3465 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3466 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Enable texgen.");
3468 break;
3470 case WINED3DTSS_TCI_CAMERASPACENORMAL:
3471 /* Note that NV_TEXGEN_REFLECTION support is implied when
3472 * ARB_TEXTURE_CUBE_MAP is supported */
3473 if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3475 FIXME("WINED3DTSS_TCI_CAMERASPACENORMAL not supported.\n");
3476 break;
3479 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3480 gl_info->gl_ops.gl.p_glPushMatrix();
3481 gl_info->gl_ops.gl.p_glLoadIdentity();
3482 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3483 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3484 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3485 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3486 gl_info->gl_ops.gl.p_glPopMatrix();
3487 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set eye plane.");
3489 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3490 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3491 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3492 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set texgen mode.");
3494 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3495 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3496 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3497 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Enable texgen.");
3499 break;
3501 case WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
3502 /* Note that NV_TEXGEN_REFLECTION support is implied when
3503 * ARB_TEXTURE_CUBE_MAP is supported */
3504 if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3506 FIXME("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR not supported.\n");
3507 break;
3510 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3511 gl_info->gl_ops.gl.p_glPushMatrix();
3512 gl_info->gl_ops.gl.p_glLoadIdentity();
3513 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3514 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3515 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3516 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3517 gl_info->gl_ops.gl.p_glPopMatrix();
3518 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set eye plane.");
3520 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3521 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3522 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3523 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set texgen mode.");
3525 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3526 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3527 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3528 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Enable texgen.");
3530 break;
3532 case WINED3DTSS_TCI_SPHEREMAP:
3533 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
3534 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
3535 checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Set texgen mode.");
3537 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3538 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3539 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3540 checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Enable texgen.");
3542 break;
3544 default:
3545 FIXME("Unhandled WINED3D_TSS_TEXCOORD_INDEX %#x.\n",
3546 state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX]);
3547 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
3548 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
3549 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3550 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3551 checkGLcall("Disable texgen.");
3553 break;
3556 /* Update the texture matrix. */
3557 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + stage)))
3558 transform_texture(context, state, STATE_TEXTURESTAGE(stage, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3560 if (!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded)
3562 /* Reload the arrays if we are using fixed function arrays to reflect the selected coord input
3563 * source. Call loadTexCoords directly because there is no need to reparse the vertex declaration
3564 * and do all the things linked to it
3565 * TODO: Tidy that up to reload only the arrays of the changed unit
3567 GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
3569 unload_tex_coords(gl_info);
3570 load_tex_coords(context, &context->stream_info, &curVBO, state);
3574 void sampler_texmatrix(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3576 const DWORD sampler = state_id - STATE_SAMPLER(0);
3577 const struct wined3d_texture *texture = state->textures[sampler];
3579 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
3581 if(!texture) return;
3582 /* The fixed function np2 texture emulation uses the texture matrix to fix up the coordinates
3583 * wined3d_texture_apply_state_changes() multiplies the set matrix with a fixup matrix. Before the
3584 * scaling is reapplied or removed, the texture matrix has to be reapplied
3586 * The mapped stage is already active because the sampler() function below, which is part of the
3587 * misc pipeline
3589 if (sampler < MAX_TEXTURES)
3591 const BOOL texIsPow2 = !(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT);
3593 if (texIsPow2 || (context->lastWasPow2Texture & (1 << sampler)))
3595 if (texIsPow2)
3596 context->lastWasPow2Texture |= 1 << sampler;
3597 else
3598 context->lastWasPow2Texture &= ~(1 << sampler);
3600 transform_texture(context, state,
3601 STATE_TEXTURESTAGE(context->tex_unit_map[sampler], WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3606 static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3608 DWORD sampler = state_id - STATE_SAMPLER(0);
3609 DWORD mapped_stage = context->tex_unit_map[sampler];
3610 const struct wined3d_gl_info *gl_info = context->gl_info;
3611 union {
3612 float f;
3613 DWORD d;
3614 } tmpvalue;
3616 TRACE("Sampler: %d\n", sampler);
3617 /* Enabling and disabling texture dimensions is done by texture stage state / pixel shader setup, this function
3618 * only has to bind textures and set the per texture states
3621 if (mapped_stage == WINED3D_UNMAPPED_STAGE)
3623 TRACE("No sampler mapped to stage %d. Returning.\n", sampler);
3624 return;
3627 if (mapped_stage >= gl_info->limits.combined_samplers)
3629 return;
3631 context_active_texture(context, gl_info, mapped_stage);
3633 if (state->textures[sampler])
3635 struct wined3d_texture *texture = state->textures[sampler];
3636 BOOL srgb = state->sampler_states[sampler][WINED3D_SAMP_SRGB_TEXTURE];
3638 wined3d_texture_bind(texture, context, srgb);
3639 wined3d_texture_apply_state_changes(texture, state->sampler_states[sampler], gl_info);
3641 if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
3643 tmpvalue.d = state->sampler_states[sampler][WINED3D_SAMP_MIPMAP_LOD_BIAS];
3644 gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
3645 GL_TEXTURE_LOD_BIAS_EXT, tmpvalue.f);
3646 checkGLcall("glTexEnvf(GL_TEXTURE_LOD_BIAS_EXT, ...)");
3649 if (!use_ps(state) && sampler < context->lowest_disabled_stage)
3651 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler)
3653 /* If color keying is enabled update the alpha test, it
3654 * depends on the existence of a color key in stage 0. */
3655 state_alpha(context, state, WINED3D_RS_COLORKEYENABLE);
3659 /* Trigger shader constant reloading (for NP2 texcoord fixup) */
3660 if (!(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT))
3661 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_NP2_FIXUP;
3663 else
3665 if (sampler < context->lowest_disabled_stage)
3667 /* TODO: What should I do with pixel shaders here ??? */
3668 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler)
3670 /* If color keying is enabled update the alpha test, it
3671 * depends on the existence of a color key in stage 0. */
3672 state_alpha(context, state, WINED3D_RS_COLORKEYENABLE);
3674 } /* Otherwise tex_colorop disables the stage */
3675 context_bind_texture(context, GL_NONE, 0);
3679 void apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3681 unsigned int i;
3683 if (use_ps(state))
3685 if (!context->last_was_pshader)
3687 /* Former draw without a pixel shader, some samplers may be
3688 * disabled because of WINED3D_TSS_COLOR_OP = WINED3DTOP_DISABLE
3689 * make sure to enable them. */
3690 for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
3692 if (!isStateDirty(context, STATE_SAMPLER(i)))
3693 sampler(context, state, STATE_SAMPLER(i));
3695 context->last_was_pshader = TRUE;
3697 else
3699 /* Otherwise all samplers were activated by the code above in
3700 * earlier draws, or by sampler() if a different texture was
3701 * bound. I don't have to do anything. */
3704 else
3706 /* Disabled the pixel shader - color ops weren't applied while it was
3707 * enabled, so re-apply them. */
3708 for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
3710 if (!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP)))
3711 context_apply_state(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
3713 context->last_was_pshader = FALSE;
3716 context->shader_update_mask |= 1 << WINED3D_SHADER_TYPE_PIXEL;
3719 static void state_geometry_shader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3721 context->shader_update_mask |= 1 << WINED3D_SHADER_TYPE_GEOMETRY;
3724 static void shader_bumpenv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3726 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_BUMP_ENV;
3729 void transform_world(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3731 const struct wined3d_gl_info *gl_info = context->gl_info;
3733 /* This function is called by transform_view below if the view matrix was changed too
3735 * Deliberately no check if the vertex declaration is dirty because the vdecl state
3736 * does not always update the world matrix, only on a switch between transformed
3737 * and untransformed draws. It *may* happen that the world matrix is set 2 times during one
3738 * draw, but that should be rather rare and cheaper in total.
3740 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3741 checkGLcall("glMatrixMode");
3743 if (context->last_was_rhw)
3745 gl_info->gl_ops.gl.p_glLoadIdentity();
3746 checkGLcall("glLoadIdentity()");
3748 else
3750 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]);
3751 checkGLcall("glLoadMatrixf");
3752 gl_info->gl_ops.gl.p_glMultMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(0)].u.m[0][0]);
3753 checkGLcall("glMultMatrixf");
3757 void clipplane(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3759 const struct wined3d_gl_info *gl_info = context->gl_info;
3760 UINT index = state_id - STATE_CLIPPLANE(0);
3761 GLdouble plane[4];
3763 if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)) || index >= gl_info->limits.clipplanes)
3764 return;
3766 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3767 gl_info->gl_ops.gl.p_glPushMatrix();
3769 /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */
3770 if (!use_vs(state))
3771 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]);
3772 else
3773 /* With vertex shaders, clip planes are not transformed in Direct3D,
3774 * while in OpenGL they are still transformed by the model view matix. */
3775 gl_info->gl_ops.gl.p_glLoadIdentity();
3777 plane[0] = state->clip_planes[index].x;
3778 plane[1] = state->clip_planes[index].y;
3779 plane[2] = state->clip_planes[index].z;
3780 plane[3] = state->clip_planes[index].w;
3782 TRACE("Clipplane [%.8e, %.8e, %.8e, %.8e]\n",
3783 plane[0], plane[1], plane[2], plane[3]);
3784 gl_info->gl_ops.gl.p_glClipPlane(GL_CLIP_PLANE0 + index, plane);
3785 checkGLcall("glClipPlane");
3787 gl_info->gl_ops.gl.p_glPopMatrix();
3790 static void transform_worldex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3792 UINT matrix = state_id - STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0));
3793 const struct wined3d_gl_info *gl_info = context->gl_info;
3794 GLenum glMat;
3796 TRACE("Setting world matrix %d\n", matrix);
3798 if (matrix >= gl_info->limits.blends)
3800 WARN("Unsupported blend matrix set\n");
3801 return;
3804 if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)))
3805 return;
3807 /* GL_MODELVIEW0_ARB: 0x1700
3808 * GL_MODELVIEW1_ARB: 0x850a
3809 * GL_MODELVIEW2_ARB: 0x8722
3810 * GL_MODELVIEW3_ARB: 0x8723
3811 * etc
3812 * GL_MODELVIEW31_ARB: 0x873f
3814 if(matrix == 1) glMat = GL_MODELVIEW1_ARB;
3815 else glMat = GL_MODELVIEW2_ARB - 2 + matrix;
3817 gl_info->gl_ops.gl.p_glMatrixMode(glMat);
3818 checkGLcall("glMatrixMode(glMat)");
3820 /* World matrix 0 is multiplied with the view matrix because d3d uses 3
3821 * matrices while gl uses only 2. To avoid weighting the view matrix
3822 * incorrectly it has to be multiplied into every GL modelview matrix. */
3823 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]);
3824 checkGLcall("glLoadMatrixf");
3825 gl_info->gl_ops.gl.p_glMultMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(matrix)].u.m[0][0]);
3826 checkGLcall("glMultMatrixf");
3829 static void state_vertexblend_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3831 enum wined3d_vertex_blend_flags f = state->render_states[WINED3D_RS_VERTEXBLEND];
3832 static unsigned int once;
3834 if (f == WINED3D_VBF_DISABLE)
3835 return;
3837 if (!once++) FIXME("Vertex blend flags %#x not supported.\n", f);
3838 else WARN("Vertex blend flags %#x not supported.\n", f);
3841 static void state_vertexblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3843 enum wined3d_vertex_blend_flags val = state->render_states[WINED3D_RS_VERTEXBLEND];
3844 struct wined3d_device *device = context->swapchain->device;
3845 const struct wined3d_gl_info *gl_info = context->gl_info;
3846 static unsigned int once;
3848 switch (val)
3850 case WINED3D_VBF_1WEIGHTS:
3851 case WINED3D_VBF_2WEIGHTS:
3852 case WINED3D_VBF_3WEIGHTS:
3853 gl_info->gl_ops.gl.p_glEnable(GL_VERTEX_BLEND_ARB);
3854 checkGLcall("glEnable(GL_VERTEX_BLEND_ARB)");
3856 /* D3D adds one more matrix which has weight (1 - sum(weights)).
3857 * This is enabled at context creation with enabling
3858 * GL_WEIGHT_SUM_UNITY_ARB. */
3859 GL_EXTCALL(glVertexBlendARB(state->render_states[WINED3D_RS_VERTEXBLEND] + 1));
3861 if (!device->vertexBlendUsed)
3863 unsigned int i;
3864 for (i = 1; i < gl_info->limits.blends; ++i)
3866 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i))))
3867 transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i)));
3869 device->vertexBlendUsed = TRUE;
3871 break;
3873 case WINED3D_VBF_TWEENING:
3874 case WINED3D_VBF_0WEIGHTS: /* Indexed vertex blending, not supported. */
3875 if (!once++) FIXME("Vertex blend flags %#x not supported.\n", val);
3876 else WARN("Vertex blend flags %#x not supported.\n", val);
3877 /* Fall through. */
3878 case WINED3D_VBF_DISABLE:
3879 gl_info->gl_ops.gl.p_glDisable(GL_VERTEX_BLEND_ARB);
3880 checkGLcall("glDisable(GL_VERTEX_BLEND_ARB)");
3881 break;
3885 void transform_view(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3887 const struct wined3d_gl_info *gl_info = context->gl_info;
3888 const struct wined3d_light_info *light = NULL;
3889 unsigned int k;
3891 /* If we are changing the View matrix, reset the light and clipping planes to the new view
3892 * NOTE: We have to reset the positions even if the light/plane is not currently
3893 * enabled, since the call to enable it will not reset the position.
3894 * NOTE2: Apparently texture transforms do NOT need reapplying
3897 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3898 checkGLcall("glMatrixMode(GL_MODELVIEW)");
3899 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]);
3900 checkGLcall("glLoadMatrixf(...)");
3902 /* Reset lights. TODO: Call light apply func */
3903 for (k = 0; k < gl_info->limits.lights; ++k)
3905 if (!(light = state->lights[k]))
3906 continue;
3907 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, light->lightPosn);
3908 checkGLcall("glLightfv posn");
3909 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_SPOT_DIRECTION, light->lightDirn);
3910 checkGLcall("glLightfv dirn");
3913 /* Reset Clipping Planes */
3914 for (k = 0; k < gl_info->limits.clipplanes; ++k)
3916 if (!isStateDirty(context, STATE_CLIPPLANE(k)))
3917 clipplane(context, state, STATE_CLIPPLANE(k));
3920 if (context->last_was_rhw)
3922 gl_info->gl_ops.gl.p_glLoadIdentity();
3923 checkGLcall("glLoadIdentity()");
3924 /* No need to update the world matrix, the identity is fine */
3925 return;
3928 /* Call the world matrix state, this will apply the combined WORLD + VIEW matrix
3929 * No need to do it here if the state is scheduled for update. */
3930 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
3931 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
3933 /* Avoid looping over a number of matrices if the app never used the functionality */
3934 if (context->swapchain->device->vertexBlendUsed)
3936 for (k = 1; k < gl_info->limits.blends; ++k)
3938 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k))))
3939 transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k)));
3944 void transform_projection(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3946 const struct wined3d_gl_info *gl_info = context->gl_info;
3948 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
3949 checkGLcall("glMatrixMode(GL_PROJECTION)");
3951 /* There are a couple of additional things we have to take into account
3952 * here besides the projection transformation itself:
3953 * - We need to flip along the y-axis in case of offscreen rendering.
3954 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
3955 * - D3D coordinates refer to pixel centers while GL coordinates refer
3956 * to pixel corners.
3957 * - D3D has a top-left filling convention. We need to maintain this
3958 * even after the y-flip mentioned above.
3959 * In order to handle the last two points, we translate by
3960 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
3961 * translating slightly less than half a pixel. We want the difference to
3962 * be large enough that it doesn't get lost due to rounding inside the
3963 * driver, but small enough to prevent it from interfering with any
3964 * anti-aliasing. */
3966 if (context->last_was_rhw)
3968 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
3969 double x = state->viewport.x;
3970 double y = state->viewport.y;
3971 double w = state->viewport.width;
3972 double h = state->viewport.height;
3973 double x_scale = 2.0 / w;
3974 double x_offset = ((63.0 / 64.0) - (2.0 * x) - w) / w;
3975 double y_scale = context->render_offscreen ? 2.0 / h : 2.0 / -h;
3976 double y_offset = context->render_offscreen
3977 ? ((63.0 / 64.0) - (2.0 * y) - h) / h
3978 : ((63.0 / 64.0) - (2.0 * y) - h) / -h;
3979 const GLdouble projection[] =
3981 x_scale, 0.0, 0.0, 0.0,
3982 0.0, y_scale, 0.0, 0.0,
3983 0.0, 0.0, 2.0, 0.0,
3984 x_offset, y_offset, -1.0, 1.0,
3987 gl_info->gl_ops.gl.p_glLoadMatrixd(projection);
3988 checkGLcall("glLoadMatrixd");
3990 else
3992 double y_scale = context->render_offscreen ? -1.0 : 1.0;
3993 double x_offset = (63.0 / 64.0) / state->viewport.width;
3994 double y_offset = context->render_offscreen
3995 ? (63.0 / 64.0) / state->viewport.height
3996 : -(63.0 / 64.0) / state->viewport.height;
3997 const GLdouble projection[] =
3999 1.0, 0.0, 0.0, 0.0,
4000 0.0, y_scale, 0.0, 0.0,
4001 0.0, 0.0, 2.0, 0.0,
4002 x_offset, y_offset, -1.0, 1.0,
4005 gl_info->gl_ops.gl.p_glLoadMatrixd(projection);
4006 checkGLcall("glLoadMatrixd");
4008 gl_info->gl_ops.gl.p_glMultMatrixf(&state->transforms[WINED3D_TS_PROJECTION].u.m[0][0]);
4009 checkGLcall("glLoadMatrixf");
4013 /* This should match any arrays loaded in load_vertex_data.
4014 * TODO: Only load / unload arrays if we have to. */
4015 static void unload_vertex_data(const struct wined3d_gl_info *gl_info)
4017 gl_info->gl_ops.gl.p_glDisableClientState(GL_VERTEX_ARRAY);
4018 gl_info->gl_ops.gl.p_glDisableClientState(GL_NORMAL_ARRAY);
4019 gl_info->gl_ops.gl.p_glDisableClientState(GL_COLOR_ARRAY);
4020 if (gl_info->supported[EXT_SECONDARY_COLOR])
4021 gl_info->gl_ops.gl.p_glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
4022 if (gl_info->supported[ARB_VERTEX_BLEND])
4023 gl_info->gl_ops.gl.p_glDisableClientState(GL_WEIGHT_ARRAY_ARB);
4024 unload_tex_coords(gl_info);
4027 static inline void unload_numbered_array(struct wined3d_context *context, int i)
4029 const struct wined3d_gl_info *gl_info = context->gl_info;
4031 GL_EXTCALL(glDisableVertexAttribArrayARB(i));
4032 checkGLcall("glDisableVertexAttribArrayARB(reg)");
4033 if (gl_info->supported[ARB_INSTANCED_ARRAYS])
4034 GL_EXTCALL(glVertexAttribDivisorARB(i, 0));
4036 context->numbered_array_mask &= ~(1 << i);
4039 /* This should match any arrays loaded in loadNumberedArrays
4040 * TODO: Only load / unload arrays if we have to. */
4041 static void unload_numbered_arrays(struct wined3d_context *context)
4043 /* disable any attribs (this is the same for both GLSL and ARB modes) */
4044 int i;
4046 for (i = 0; i < context->gl_info->limits.vertex_attribs; ++i) {
4047 unload_numbered_array(context, i);
4051 static void load_numbered_arrays(struct wined3d_context *context,
4052 const struct wined3d_stream_info *stream_info, const struct wined3d_state *state)
4054 const struct wined3d_gl_info *gl_info = context->gl_info;
4055 GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
4056 int i;
4058 /* Default to no instancing */
4059 context->instance_count = 0;
4061 for (i = 0; i < MAX_ATTRIBS; i++)
4063 const struct wined3d_stream_state *stream;
4065 if (!(stream_info->use_map & (1 << i)))
4067 if (context->numbered_array_mask & (1 << i))
4068 unload_numbered_array(context, i);
4069 if (state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.input_registers & (1 << i))
4070 GL_EXTCALL(glVertexAttrib4fARB(i, 0.0f, 0.0f, 0.0f, 0.0f));
4071 continue;
4074 stream = &state->streams[stream_info->elements[i].stream_idx];
4076 if (stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
4078 if (!context->instance_count)
4079 context->instance_count = state->streams[0].frequency ? state->streams[0].frequency : 1;
4081 if (!gl_info->supported[ARB_INSTANCED_ARRAYS])
4083 /* Unload instanced arrays, they will be loaded using
4084 * immediate mode instead. */
4085 if (context->numbered_array_mask & (1 << i))
4086 unload_numbered_array(context, i);
4087 continue;
4090 GL_EXTCALL(glVertexAttribDivisorARB(i, 1));
4092 else if (gl_info->supported[ARB_INSTANCED_ARRAYS])
4094 GL_EXTCALL(glVertexAttribDivisorARB(i, 0));
4097 TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, stream_info->elements[i].data.buffer_object);
4099 if (stream_info->elements[i].stride)
4101 if (curVBO != stream_info->elements[i].data.buffer_object)
4103 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, stream_info->elements[i].data.buffer_object));
4104 checkGLcall("glBindBufferARB");
4105 curVBO = stream_info->elements[i].data.buffer_object;
4107 /* Use the VBO to find out if a vertex buffer exists, not the vb
4108 * pointer. vb can point to a user pointer data blob. In that case
4109 * curVBO will be 0. If there is a vertex buffer but no vbo we
4110 * won't be load converted attributes anyway. */
4111 GL_EXTCALL(glVertexAttribPointerARB(i, stream_info->elements[i].format->gl_vtx_format,
4112 stream_info->elements[i].format->gl_vtx_type,
4113 stream_info->elements[i].format->gl_normalized,
4114 stream_info->elements[i].stride, stream_info->elements[i].data.addr
4115 + state->load_base_vertex_index * stream_info->elements[i].stride));
4117 if (!(context->numbered_array_mask & (1 << i)))
4119 GL_EXTCALL(glEnableVertexAttribArrayARB(i));
4120 context->numbered_array_mask |= (1 << i);
4123 else
4125 /* Stride = 0 means always the same values.
4126 * glVertexAttribPointerARB doesn't do that. Instead disable the
4127 * pointer and set up the attribute statically. But we have to
4128 * figure out the system memory address. */
4129 const BYTE *ptr = stream_info->elements[i].data.addr;
4130 if (stream_info->elements[i].data.buffer_object)
4132 ptr += (ULONG_PTR)buffer_get_sysmem(stream->buffer, context);
4135 if (context->numbered_array_mask & (1 << i)) unload_numbered_array(context, i);
4137 switch (stream_info->elements[i].format->id)
4139 case WINED3DFMT_R32_FLOAT:
4140 GL_EXTCALL(glVertexAttrib1fvARB(i, (const GLfloat *)ptr));
4141 break;
4142 case WINED3DFMT_R32G32_FLOAT:
4143 GL_EXTCALL(glVertexAttrib2fvARB(i, (const GLfloat *)ptr));
4144 break;
4145 case WINED3DFMT_R32G32B32_FLOAT:
4146 GL_EXTCALL(glVertexAttrib3fvARB(i, (const GLfloat *)ptr));
4147 break;
4148 case WINED3DFMT_R32G32B32A32_FLOAT:
4149 GL_EXTCALL(glVertexAttrib4fvARB(i, (const GLfloat *)ptr));
4150 break;
4152 case WINED3DFMT_R8G8B8A8_UINT:
4153 GL_EXTCALL(glVertexAttrib4NubvARB(i, ptr));
4154 break;
4155 case WINED3DFMT_B8G8R8A8_UNORM:
4156 if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
4158 const DWORD *src = (const DWORD *)ptr;
4159 DWORD c = *src & 0xff00ff00;
4160 c |= (*src & 0xff0000) >> 16;
4161 c |= (*src & 0xff) << 16;
4162 GL_EXTCALL(glVertexAttrib4NubvARB(i, (GLubyte *)&c));
4163 break;
4165 /* else fallthrough */
4166 case WINED3DFMT_R8G8B8A8_UNORM:
4167 GL_EXTCALL(glVertexAttrib4NubvARB(i, ptr));
4168 break;
4170 case WINED3DFMT_R16G16_SINT:
4171 GL_EXTCALL(glVertexAttrib4svARB(i, (const GLshort *)ptr));
4172 break;
4173 case WINED3DFMT_R16G16B16A16_SINT:
4174 GL_EXTCALL(glVertexAttrib4svARB(i, (const GLshort *)ptr));
4175 break;
4177 case WINED3DFMT_R16G16_SNORM:
4179 const GLshort s[4] = {((const GLshort *)ptr)[0], ((const GLshort *)ptr)[1], 0, 1};
4180 GL_EXTCALL(glVertexAttrib4NsvARB(i, s));
4181 break;
4183 case WINED3DFMT_R16G16_UNORM:
4185 const GLushort s[4] = {((const GLushort *)ptr)[0], ((const GLushort *)ptr)[1], 0, 1};
4186 GL_EXTCALL(glVertexAttrib4NusvARB(i, s));
4187 break;
4189 case WINED3DFMT_R16G16B16A16_SNORM:
4190 GL_EXTCALL(glVertexAttrib4NsvARB(i, (const GLshort *)ptr));
4191 break;
4192 case WINED3DFMT_R16G16B16A16_UNORM:
4193 GL_EXTCALL(glVertexAttrib4NusvARB(i, (const GLushort *)ptr));
4194 break;
4196 case WINED3DFMT_R10G10B10A2_UINT:
4197 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
4198 /*glVertexAttrib3usvARB(i, (const GLushort *)ptr); Does not exist */
4199 break;
4200 case WINED3DFMT_R10G10B10A2_SNORM:
4201 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
4202 /*glVertexAttrib3NusvARB(i, (const GLushort *)ptr); Does not exist */
4203 break;
4205 case WINED3DFMT_R16G16_FLOAT:
4206 if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
4208 /* Not supported by GL_ARB_half_float_vertex. */
4209 GL_EXTCALL(glVertexAttrib2hvNV(i, (const GLhalfNV *)ptr));
4211 else
4213 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
4214 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
4215 GL_EXTCALL(glVertexAttrib2fARB(i, x, y));
4217 break;
4218 case WINED3DFMT_R16G16B16A16_FLOAT:
4219 if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
4221 /* Not supported by GL_ARB_half_float_vertex. */
4222 GL_EXTCALL(glVertexAttrib4hvNV(i, (const GLhalfNV *)ptr));
4224 else
4226 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
4227 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
4228 float z = float_16_to_32(((const unsigned short *)ptr) + 2);
4229 float w = float_16_to_32(((const unsigned short *)ptr) + 3);
4230 GL_EXTCALL(glVertexAttrib4fARB(i, x, y, z, w));
4232 break;
4234 default:
4235 ERR("Unexpected declaration in stride 0 attributes\n");
4236 break;
4241 checkGLcall("Loading numbered arrays");
4244 static void load_vertex_data(struct wined3d_context *context,
4245 const struct wined3d_stream_info *si, const struct wined3d_state *state)
4247 const struct wined3d_gl_info *gl_info = context->gl_info;
4248 GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
4249 const struct wined3d_stream_info_element *e;
4251 TRACE("Using fast vertex array code\n");
4253 /* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */
4254 context->instance_count = 0;
4256 /* Blend Data ---------------------------------------------- */
4257 if ((si->use_map & (1 << WINED3D_FFP_BLENDWEIGHT))
4258 || si->use_map & (1 << WINED3D_FFP_BLENDINDICES))
4260 e = &si->elements[WINED3D_FFP_BLENDWEIGHT];
4262 if (gl_info->supported[ARB_VERTEX_BLEND])
4264 TRACE("Blend %u %p %u\n", e->format->component_count,
4265 e->data.addr + state->load_base_vertex_index * e->stride, e->stride);
4267 gl_info->gl_ops.gl.p_glEnableClientState(GL_WEIGHT_ARRAY_ARB);
4268 checkGLcall("glEnableClientState(GL_WEIGHT_ARRAY_ARB)");
4270 GL_EXTCALL(glVertexBlendARB(e->format->component_count + 1));
4272 if (curVBO != e->data.buffer_object)
4274 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object));
4275 checkGLcall("glBindBufferARB");
4276 curVBO = e->data.buffer_object;
4279 TRACE("glWeightPointerARB(%#x, %#x, %#x, %p);\n",
4280 e->format->gl_vtx_format,
4281 e->format->gl_vtx_type,
4282 e->stride,
4283 e->data.addr + state->load_base_vertex_index * e->stride);
4284 GL_EXTCALL(glWeightPointerARB(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4285 e->data.addr + state->load_base_vertex_index * e->stride));
4287 checkGLcall("glWeightPointerARB");
4289 if (si->use_map & (1 << WINED3D_FFP_BLENDINDICES))
4291 static BOOL warned;
4292 if (!warned)
4294 FIXME("blendMatrixIndices support\n");
4295 warned = TRUE;
4298 } else {
4299 /* TODO: support blends in drawStridedSlow
4300 * No need to write a FIXME here, this is done after the general vertex decl decoding
4302 WARN("unsupported blending in openGl\n");
4305 else
4307 if (gl_info->supported[ARB_VERTEX_BLEND])
4309 static const GLbyte one = 1;
4310 GL_EXTCALL(glWeightbvARB(1, &one));
4311 checkGLcall("glWeightbvARB(gl_info->max_blends, weights)");
4315 /* Point Size ----------------------------------------------*/
4316 if (si->use_map & (1 << WINED3D_FFP_PSIZE))
4318 /* no such functionality in the fixed function GL pipeline */
4319 TRACE("Cannot change ptSize here in openGl\n");
4320 /* TODO: Implement this function in using shaders if they are available */
4323 /* Vertex Pointers -----------------------------------------*/
4324 if (si->use_map & (1 << WINED3D_FFP_POSITION))
4326 e = &si->elements[WINED3D_FFP_POSITION];
4328 if (curVBO != e->data.buffer_object)
4330 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object));
4331 checkGLcall("glBindBufferARB");
4332 curVBO = e->data.buffer_object;
4335 TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
4336 e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4337 e->data.addr + state->load_base_vertex_index * e->stride);
4338 gl_info->gl_ops.gl.p_glVertexPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4339 e->data.addr + state->load_base_vertex_index * e->stride);
4340 checkGLcall("glVertexPointer(...)");
4341 gl_info->gl_ops.gl.p_glEnableClientState(GL_VERTEX_ARRAY);
4342 checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)");
4345 /* Normals -------------------------------------------------*/
4346 if (si->use_map & (1 << WINED3D_FFP_NORMAL))
4348 e = &si->elements[WINED3D_FFP_NORMAL];
4350 if (curVBO != e->data.buffer_object)
4352 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object));
4353 checkGLcall("glBindBufferARB");
4354 curVBO = e->data.buffer_object;
4357 TRACE("glNormalPointer(%#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride,
4358 e->data.addr + state->load_base_vertex_index * e->stride);
4359 gl_info->gl_ops.gl.p_glNormalPointer(e->format->gl_vtx_type, e->stride,
4360 e->data.addr + state->load_base_vertex_index * e->stride);
4361 checkGLcall("glNormalPointer(...)");
4362 gl_info->gl_ops.gl.p_glEnableClientState(GL_NORMAL_ARRAY);
4363 checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
4366 else
4368 gl_info->gl_ops.gl.p_glNormal3f(0, 0, 0);
4369 checkGLcall("glNormal3f(0, 0, 0)");
4372 /* Diffuse Colour --------------------------------------------*/
4373 if (si->use_map & (1 << WINED3D_FFP_DIFFUSE))
4375 e = &si->elements[WINED3D_FFP_DIFFUSE];
4377 if (curVBO != e->data.buffer_object)
4379 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object));
4380 checkGLcall("glBindBufferARB");
4381 curVBO = e->data.buffer_object;
4384 TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
4385 e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4386 e->data.addr + state->load_base_vertex_index * e->stride);
4387 gl_info->gl_ops.gl.p_glColorPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4388 e->data.addr + state->load_base_vertex_index * e->stride);
4389 checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
4390 gl_info->gl_ops.gl.p_glEnableClientState(GL_COLOR_ARRAY);
4391 checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");
4394 else
4396 gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
4397 checkGLcall("glColor4f(1, 1, 1, 1)");
4400 /* Specular Colour ------------------------------------------*/
4401 if (si->use_map & (1 << WINED3D_FFP_SPECULAR))
4403 TRACE("setting specular colour\n");
4405 e = &si->elements[WINED3D_FFP_SPECULAR];
4407 if (gl_info->supported[EXT_SECONDARY_COLOR])
4409 GLenum type = e->format->gl_vtx_type;
4410 GLint format = e->format->gl_vtx_format;
4412 if (curVBO != e->data.buffer_object)
4414 GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object));
4415 checkGLcall("glBindBufferARB");
4416 curVBO = e->data.buffer_object;
4419 if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
4421 /* Usually specular colors only allow 3 components, since they have no alpha. In D3D, the specular alpha
4422 * contains the fog coordinate, which is passed to GL with GL_EXT_fog_coord. However, the fixed function
4423 * vertex pipeline can pass the specular alpha through, and pixel shaders can read it. So it GL accepts
4424 * 4 component secondary colors use it
4426 TRACE("glSecondaryColorPointer(%#x, %#x, %#x, %p);\n", format, type, e->stride,
4427 e->data.addr + state->load_base_vertex_index * e->stride);
4428 GL_EXTCALL(glSecondaryColorPointerEXT(format, type, e->stride,
4429 e->data.addr + state->load_base_vertex_index * e->stride));
4430 checkGLcall("glSecondaryColorPointerEXT(format, type, ...)");
4432 else
4434 switch(type)
4436 case GL_UNSIGNED_BYTE:
4437 TRACE("glSecondaryColorPointer(3, GL_UNSIGNED_BYTE, %#x, %p);\n", e->stride,
4438 e->data.addr + state->load_base_vertex_index * e->stride);
4439 GL_EXTCALL(glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, e->stride,
4440 e->data.addr + state->load_base_vertex_index * e->stride));
4441 checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)");
4442 break;
4444 default:
4445 FIXME("Add 4 component specular color pointers for type %x\n", type);
4446 /* Make sure that the right color component is dropped */
4447 TRACE("glSecondaryColorPointer(3, %#x, %#x, %p);\n", type, e->stride,
4448 e->data.addr + state->load_base_vertex_index * e->stride);
4449 GL_EXTCALL(glSecondaryColorPointerEXT(3, type, e->stride,
4450 e->data.addr + state->load_base_vertex_index * e->stride));
4451 checkGLcall("glSecondaryColorPointerEXT(3, type, ...)");
4454 gl_info->gl_ops.gl.p_glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
4455 checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
4457 else
4459 WARN("Specular colour is not supported in this GL implementation.\n");
4462 else
4464 if (gl_info->supported[EXT_SECONDARY_COLOR])
4466 GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
4467 checkGLcall("glSecondaryColor3fEXT(0, 0, 0)");
4469 else
4471 WARN("Specular colour is not supported in this GL implementation.\n");
4475 /* Texture coords -------------------------------------------*/
4476 load_tex_coords(context, si, &curVBO, state);
4479 static void streamsrc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4481 BOOL load_numbered = use_vs(state) && !context->use_immediate_mode_draw;
4482 BOOL load_named = !use_vs(state) && !context->use_immediate_mode_draw;
4484 if (isStateDirty(context, STATE_VDECL)) return;
4485 if (context->numberedArraysLoaded && !load_numbered)
4487 unload_numbered_arrays(context);
4488 context->numberedArraysLoaded = FALSE;
4489 context->numbered_array_mask = 0;
4491 else if (context->namedArraysLoaded)
4493 unload_vertex_data(context->gl_info);
4494 context->namedArraysLoaded = FALSE;
4497 if (load_numbered)
4499 TRACE("Loading numbered arrays\n");
4500 load_numbered_arrays(context, &context->stream_info, state);
4501 context->numberedArraysLoaded = TRUE;
4503 else if (load_named)
4505 TRACE("Loading vertex data\n");
4506 load_vertex_data(context, &context->stream_info, state);
4507 context->namedArraysLoaded = TRUE;
4511 static void vdecl_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4513 if (isStateDirty(context, STATE_STREAMSRC))
4514 return;
4515 streamsrc(context, state, STATE_STREAMSRC);
4518 void vertexdeclaration(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4520 const struct wined3d_gl_info *gl_info = context->gl_info;
4521 BOOL useVertexShaderFunction = use_vs(state);
4522 BOOL updateFog = FALSE;
4523 BOOL transformed;
4524 BOOL wasrhw = context->last_was_rhw;
4525 unsigned int i;
4527 transformed = context->stream_info.position_transformed;
4528 if (transformed != context->last_was_rhw && !useVertexShaderFunction)
4529 updateFog = TRUE;
4531 context->last_was_rhw = transformed;
4533 /* Don't have to apply the matrices when vertex shaders are used. When
4534 * vshaders are turned off this function will be called again anyway to
4535 * make sure they're properly set. */
4536 if (!useVertexShaderFunction)
4538 /* TODO: Move this mainly to the viewport state and only apply when
4539 * the vp has changed or transformed / untransformed was switched. */
4540 if (wasrhw != context->last_was_rhw
4541 && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))
4542 && !isStateDirty(context, STATE_VIEWPORT))
4543 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4544 /* World matrix needs reapplication here only if we're switching between rhw and non-rhw
4545 * mode.
4547 * If a vertex shader is used, the world matrix changed and then vertex shader unbound
4548 * this check will fail and the matrix not applied again. This is OK because a simple
4549 * world matrix change reapplies the matrix - These checks here are only to satisfy the
4550 * needs of the vertex declaration.
4552 * World and view matrix go into the same gl matrix, so only apply them when neither is
4553 * dirty
4555 if (transformed != wasrhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)))
4556 && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)))
4557 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
4558 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_COLORVERTEX)))
4559 context_apply_state(context, state, STATE_RENDER(WINED3D_RS_COLORVERTEX));
4560 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_LIGHTING)))
4561 state_lighting(context, state, STATE_RENDER(WINED3D_RS_LIGHTING));
4563 if (context->last_was_vshader)
4565 updateFog = TRUE;
4567 if (!context->d3d_info->vs_clipping
4568 && !isStateDirty(context, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE)))
4570 state_clipping(context, state, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE));
4573 for (i = 0; i < gl_info->limits.clipplanes; ++i)
4575 clipplane(context, state, STATE_CLIPPLANE(i));
4578 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS)))
4579 state_normalize(context, state, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS));
4581 else
4583 if(!context->last_was_vshader) {
4584 static BOOL warned = FALSE;
4585 if (!context->d3d_info->vs_clipping)
4587 /* Disable all clip planes to get defined results on all drivers. See comment in the
4588 * state_clipping state handler
4590 for (i = 0; i < gl_info->limits.clipplanes; ++i)
4592 gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE0 + i);
4593 checkGLcall("glDisable(GL_CLIP_PLANE0 + i)");
4596 if (!warned && state->render_states[WINED3D_RS_CLIPPLANEENABLE])
4598 FIXME("Clipping not supported with vertex shaders\n");
4599 warned = TRUE;
4602 if (wasrhw)
4604 /* Apply the transform matrices when switching from rhw
4605 * drawing to vertex shaders. Vertex shaders themselves do
4606 * not need it, but the matrices are not reapplied
4607 * automatically when switching back from vertex shaders to
4608 * fixed function processing. So make sure we leave the fixed
4609 * function vertex processing states back in a sane state
4610 * before switching to shaders. */
4611 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
4612 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4613 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
4614 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
4616 updateFog = TRUE;
4618 /* Vertex shader clipping ignores the view matrix. Update all clipplanes
4619 * (Note: ARB shaders can read the clip planes for clipping emulation even if
4620 * device->vs_clipping is false.
4622 for (i = 0; i < gl_info->limits.clipplanes; ++i)
4624 clipplane(context, state, STATE_CLIPPLANE(i));
4629 context->last_was_vshader = useVertexShaderFunction;
4630 context->shader_update_mask |= 1 << WINED3D_SHADER_TYPE_VERTEX;
4632 if (updateFog)
4633 context_apply_state(context, state, STATE_RENDER(WINED3D_RS_FOGVERTEXMODE));
4635 if (!useVertexShaderFunction)
4637 unsigned int i;
4639 for (i = 0; i < MAX_TEXTURES; ++i)
4641 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + i)))
4642 transform_texture(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
4645 if (use_ps(state) && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.major == 1
4646 && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.minor <= 3)
4647 context->shader_update_mask |= 1 << WINED3D_SHADER_TYPE_PIXEL;
4650 if (transformed != wasrhw && !isStateDirty(context, STATE_RENDER(WINED3D_RS_ZENABLE)))
4651 state_zenable(context, state, STATE_RENDER(WINED3D_RS_ZENABLE));
4654 static void viewport_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4656 const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4657 const struct wined3d_gl_info *gl_info = context->gl_info;
4658 struct wined3d_viewport vp = state->viewport;
4660 if (vp.width > target->width)
4661 vp.width = target->width;
4662 if (vp.height > target->height)
4663 vp.height = target->height;
4665 gl_info->gl_ops.gl.p_glDepthRange(vp.min_z, vp.max_z);
4666 checkGLcall("glDepthRange");
4667 /* Note: GL requires lower left, DirectX supplies upper left. This is
4668 * reversed when using offscreen rendering. */
4669 if (context->render_offscreen)
4671 gl_info->gl_ops.gl.p_glViewport(vp.x, vp.y, vp.width, vp.height);
4673 else
4675 UINT width, height;
4677 surface_get_drawable_size(wined3d_rendertarget_view_get_surface(target), context, &width, &height);
4678 gl_info->gl_ops.gl.p_glViewport(vp.x, (height - (vp.y + vp.height)),
4679 vp.width, vp.height);
4681 checkGLcall("glViewport");
4684 void viewport_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4686 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
4687 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4688 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE))
4689 && state->render_states[WINED3D_RS_POINTSCALEENABLE])
4690 state_pscale(context, state, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE));
4691 /* Update the position fixup. */
4692 context->constant_update_mask |= WINED3D_SHADER_CONST_VS_POS_FIXUP;
4695 void light(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4697 const struct wined3d_gl_info *gl_info = context->gl_info;
4698 UINT Index = state_id - STATE_ACTIVELIGHT(0);
4699 const struct wined3d_light_info *lightInfo = state->lights[Index];
4701 if (!lightInfo)
4703 gl_info->gl_ops.gl.p_glDisable(GL_LIGHT0 + Index);
4704 checkGLcall("glDisable(GL_LIGHT0 + Index)");
4706 else
4708 float quad_att;
4709 float colRGBA[] = {0.0f, 0.0f, 0.0f, 0.0f};
4711 /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
4712 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
4713 gl_info->gl_ops.gl.p_glPushMatrix();
4714 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]);
4716 /* Diffuse: */
4717 colRGBA[0] = lightInfo->OriginalParms.diffuse.r;
4718 colRGBA[1] = lightInfo->OriginalParms.diffuse.g;
4719 colRGBA[2] = lightInfo->OriginalParms.diffuse.b;
4720 colRGBA[3] = lightInfo->OriginalParms.diffuse.a;
4721 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_DIFFUSE, colRGBA);
4722 checkGLcall("glLightfv");
4724 /* Specular */
4725 colRGBA[0] = lightInfo->OriginalParms.specular.r;
4726 colRGBA[1] = lightInfo->OriginalParms.specular.g;
4727 colRGBA[2] = lightInfo->OriginalParms.specular.b;
4728 colRGBA[3] = lightInfo->OriginalParms.specular.a;
4729 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPECULAR, colRGBA);
4730 checkGLcall("glLightfv");
4732 /* Ambient */
4733 colRGBA[0] = lightInfo->OriginalParms.ambient.r;
4734 colRGBA[1] = lightInfo->OriginalParms.ambient.g;
4735 colRGBA[2] = lightInfo->OriginalParms.ambient.b;
4736 colRGBA[3] = lightInfo->OriginalParms.ambient.a;
4737 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_AMBIENT, colRGBA);
4738 checkGLcall("glLightfv");
4740 if ((lightInfo->OriginalParms.range * lightInfo->OriginalParms.range) >= FLT_MIN)
4741 quad_att = 1.4f / (lightInfo->OriginalParms.range * lightInfo->OriginalParms.range);
4742 else
4743 quad_att = 0.0f; /* 0 or MAX? (0 seems to be ok) */
4745 /* Do not assign attenuation values for lights that do not use them. D3D apps are free to pass any junk,
4746 * but gl drivers use them and may crash due to bad Attenuation values. Need for Speed most wanted sets
4747 * Attenuation0 to NaN and crashes in the gl lib
4750 switch (lightInfo->OriginalParms.type)
4752 case WINED3D_LIGHT_POINT:
4753 /* Position */
4754 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]);
4755 checkGLcall("glLightfv");
4756 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4757 checkGLcall("glLightf");
4758 /* Attenuation - Are these right? guessing... */
4759 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
4760 lightInfo->OriginalParms.attenuation0);
4761 checkGLcall("glLightf");
4762 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
4763 lightInfo->OriginalParms.attenuation1);
4764 checkGLcall("glLightf");
4765 if (quad_att < lightInfo->OriginalParms.attenuation2)
4766 quad_att = lightInfo->OriginalParms.attenuation2;
4767 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4768 checkGLcall("glLightf");
4769 /* FIXME: Range */
4770 break;
4772 case WINED3D_LIGHT_SPOT:
4773 /* Position */
4774 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]);
4775 checkGLcall("glLightfv");
4776 /* Direction */
4777 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPOT_DIRECTION, &lightInfo->lightDirn[0]);
4778 checkGLcall("glLightfv");
4779 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, lightInfo->exponent);
4780 checkGLcall("glLightf");
4781 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4782 checkGLcall("glLightf");
4783 /* Attenuation - Are these right? guessing... */
4784 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
4785 lightInfo->OriginalParms.attenuation0);
4786 checkGLcall("glLightf");
4787 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
4788 lightInfo->OriginalParms.attenuation1);
4789 checkGLcall("glLightf");
4790 if (quad_att < lightInfo->OriginalParms.attenuation2)
4791 quad_att = lightInfo->OriginalParms.attenuation2;
4792 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4793 checkGLcall("glLightf");
4794 /* FIXME: Range */
4795 break;
4797 case WINED3D_LIGHT_DIRECTIONAL:
4798 /* Direction */
4799 /* Note GL uses w position of 0 for direction! */
4800 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]);
4801 checkGLcall("glLightfv");
4802 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4803 checkGLcall("glLightf");
4804 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, 0.0f);
4805 checkGLcall("glLightf");
4806 break;
4808 default:
4809 FIXME("Unrecognized light type %#x.\n", lightInfo->OriginalParms.type);
4812 /* Restore the modelview matrix */
4813 gl_info->gl_ops.gl.p_glPopMatrix();
4815 gl_info->gl_ops.gl.p_glEnable(GL_LIGHT0 + Index);
4816 checkGLcall("glEnable(GL_LIGHT0 + Index)");
4820 static void scissorrect(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4822 const struct wined3d_gl_info *gl_info = context->gl_info;
4823 const RECT *r = &state->scissor_rect;
4825 /* Warning: glScissor uses window coordinates, not viewport coordinates,
4826 * so our viewport correction does not apply. Warning2: Even in windowed
4827 * mode the coords are relative to the window, not the screen. */
4828 TRACE("Setting new scissor rect to %s.\n", wine_dbgstr_rect(r));
4830 if (context->render_offscreen)
4832 gl_info->gl_ops.gl.p_glScissor(r->left, r->top, r->right - r->left, r->bottom - r->top);
4834 else
4836 const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4837 UINT height;
4838 UINT width;
4840 surface_get_drawable_size(wined3d_rendertarget_view_get_surface(target), context, &width, &height);
4841 gl_info->gl_ops.gl.p_glScissor(r->left, height - r->bottom, r->right - r->left, r->bottom - r->top);
4843 checkGLcall("glScissor");
4846 static void indexbuffer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4848 const struct wined3d_stream_info *stream_info = &context->stream_info;
4849 const struct wined3d_gl_info *gl_info = context->gl_info;
4851 if (!state->index_buffer || !stream_info->all_vbo)
4853 GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
4855 else
4857 struct wined3d_buffer *ib = state->index_buffer;
4858 GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib->buffer_object));
4862 static void frontface(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4864 const struct wined3d_gl_info *gl_info = context->gl_info;
4866 if (context->render_offscreen)
4868 gl_info->gl_ops.gl.p_glFrontFace(GL_CCW);
4869 checkGLcall("glFrontFace(GL_CCW)");
4871 else
4873 gl_info->gl_ops.gl.p_glFrontFace(GL_CW);
4874 checkGLcall("glFrontFace(GL_CW)");
4878 static void psorigin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4880 static BOOL warned;
4882 if (!warned)
4884 WARN("Point sprite coordinate origin switching not supported.\n");
4885 warned = TRUE;
4889 static void psorigin(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4891 const struct wined3d_gl_info *gl_info = context->gl_info;
4892 GLint origin = context->render_offscreen ? GL_LOWER_LEFT : GL_UPPER_LEFT;
4894 if (gl_info->supported[NV_POINT_SPRITE])
4896 GL_EXTCALL(glPointParameteriNV(GL_POINT_SPRITE_COORD_ORIGIN, origin));
4897 checkGLcall("glPointParameteriNV(GL_POINT_SPRITE_COORD_ORIGIN, ...)");
4901 void state_srgbwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4903 const struct wined3d_format *rt_format = state->fb->render_targets[0]->format;
4904 const struct wined3d_gl_info *gl_info = context->gl_info;
4906 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4908 if (state->render_states[WINED3D_RS_SRGBWRITEENABLE]
4909 && rt_format->flags & WINED3DFMT_FLAG_SRGB_WRITE)
4910 gl_info->gl_ops.gl.p_glEnable(GL_FRAMEBUFFER_SRGB);
4911 else
4912 gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB);
4915 static void state_cb(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
4916 enum wined3d_shader_type type, unsigned int base, unsigned int count)
4918 struct wined3d_buffer *buffer;
4919 unsigned int i;
4921 for (i = 0; i < count; ++i)
4923 buffer = state->cb[type][i];
4924 GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, buffer ? buffer->buffer_object : 0));
4926 checkGLcall("glBindBufferBase");
4929 static void state_cb_vs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4931 const struct wined3d_gl_limits *limits = &context->gl_info->limits;
4933 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4935 state_cb(context->gl_info, state, WINED3D_SHADER_TYPE_VERTEX, 0, limits->vertex_uniform_blocks);
4938 static void state_cb_gs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4940 const struct wined3d_gl_limits *limits = &context->gl_info->limits;
4942 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4944 state_cb(context->gl_info, state, WINED3D_SHADER_TYPE_GEOMETRY,
4945 limits->vertex_uniform_blocks, limits->geometry_uniform_blocks);
4948 static void state_cb_ps(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4950 const struct wined3d_gl_limits *limits = &context->gl_info->limits;
4952 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4954 state_cb(context->gl_info, state, WINED3D_SHADER_TYPE_PIXEL,
4955 limits->vertex_uniform_blocks + limits->geometry_uniform_blocks, limits->fragment_uniform_blocks);
4958 static void state_cb_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4960 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4962 WARN("Constant buffers (%s) no supported.\n", debug_d3dstate(state_id));
4965 const struct StateEntryTemplate misc_state_template[] =
4967 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), state_cb_vs, }, ARB_UNIFORM_BUFFER_OBJECT },
4968 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), state_cb_warn, }, WINED3D_GL_EXT_NONE },
4969 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb_gs, }, ARB_UNIFORM_BUFFER_OBJECT },
4970 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb_warn, }, WINED3D_GL_EXT_NONE },
4971 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), state_cb_ps, }, ARB_UNIFORM_BUFFER_OBJECT },
4972 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), state_cb_warn, }, WINED3D_GL_EXT_NONE },
4973 { STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4974 { STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4975 { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), state_blend }, WINED3D_GL_EXT_NONE },
4976 { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4977 { STATE_RENDER(WINED3D_RS_ANTIALIASEDLINEENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4978 { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4979 { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4980 { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4981 { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4982 { STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4983 { STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE },
4984 { STATE_VDECL, { STATE_VDECL, vdecl_miscpart }, WINED3D_GL_EXT_NONE },
4985 { STATE_FRONTFACE, { STATE_FRONTFACE, frontface }, WINED3D_GL_EXT_NONE },
4986 { STATE_SCISSORRECT, { STATE_SCISSORRECT, scissorrect }, WINED3D_GL_EXT_NONE },
4987 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin }, WINED3D_GL_VERSION_2_0 },
4988 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin_w }, WINED3D_GL_EXT_NONE },
4990 /* TODO: Move shader constant loading to vertex and fragment pipeline respectively, as soon as the pshader and
4991 * vshader loadings are untied from each other
4993 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4994 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4995 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4996 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4997 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4998 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4999 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5000 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5001 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5002 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5003 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5004 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5005 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5006 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5007 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5008 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5009 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5010 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5011 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5012 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5013 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5014 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5015 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5016 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5017 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5018 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5019 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5020 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5021 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5022 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5023 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5024 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5025 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5026 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5027 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5028 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5029 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5030 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5031 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5032 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5033 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5034 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5035 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5036 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5037 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5038 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5039 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5040 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5042 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_miscpart }, WINED3D_GL_EXT_NONE },
5043 { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, indexbuffer }, ARB_VERTEX_BUFFER_OBJECT },
5044 { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, state_nop }, WINED3D_GL_EXT_NONE },
5045 { STATE_RENDER(WINED3D_RS_ANTIALIAS), { STATE_RENDER(WINED3D_RS_ANTIALIAS), state_antialias }, WINED3D_GL_EXT_NONE },
5046 { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), state_perspective }, WINED3D_GL_EXT_NONE },
5047 { STATE_RENDER(WINED3D_RS_ZENABLE), { STATE_RENDER(WINED3D_RS_ZENABLE), state_zenable }, WINED3D_GL_EXT_NONE },
5048 { STATE_RENDER(WINED3D_RS_WRAPU), { STATE_RENDER(WINED3D_RS_WRAPU), state_wrapu }, WINED3D_GL_EXT_NONE },
5049 { STATE_RENDER(WINED3D_RS_WRAPV), { STATE_RENDER(WINED3D_RS_WRAPV), state_wrapv }, WINED3D_GL_EXT_NONE },
5050 { STATE_RENDER(WINED3D_RS_FILLMODE), { STATE_RENDER(WINED3D_RS_FILLMODE), state_fillmode }, WINED3D_GL_EXT_NONE },
5051 { STATE_RENDER(WINED3D_RS_SHADEMODE), { STATE_RENDER(WINED3D_RS_SHADEMODE), state_shademode }, WINED3D_GL_EXT_NONE },
5052 { STATE_RENDER(WINED3D_RS_LINEPATTERN), { STATE_RENDER(WINED3D_RS_LINEPATTERN), state_linepattern }, WINED3D_GL_EXT_NONE },
5053 { STATE_RENDER(WINED3D_RS_MONOENABLE), { STATE_RENDER(WINED3D_RS_MONOENABLE), state_monoenable }, WINED3D_GL_EXT_NONE },
5054 { STATE_RENDER(WINED3D_RS_ROP2), { STATE_RENDER(WINED3D_RS_ROP2), state_rop2 }, WINED3D_GL_EXT_NONE },
5055 { STATE_RENDER(WINED3D_RS_PLANEMASK), { STATE_RENDER(WINED3D_RS_PLANEMASK), state_planemask }, WINED3D_GL_EXT_NONE },
5056 { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), state_zwritenable }, WINED3D_GL_EXT_NONE },
5057 { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), state_alpha }, WINED3D_GL_EXT_NONE },
5058 { STATE_RENDER(WINED3D_RS_ALPHAREF), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5059 { STATE_RENDER(WINED3D_RS_ALPHAFUNC), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5060 { STATE_RENDER(WINED3D_RS_COLORKEYENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5061 { STATE_RENDER(WINED3D_RS_LASTPIXEL), { STATE_RENDER(WINED3D_RS_LASTPIXEL), state_lastpixel }, WINED3D_GL_EXT_NONE },
5062 { STATE_RENDER(WINED3D_RS_CULLMODE), { STATE_RENDER(WINED3D_RS_CULLMODE), state_cullmode }, WINED3D_GL_EXT_NONE },
5063 { STATE_RENDER(WINED3D_RS_ZFUNC), { STATE_RENDER(WINED3D_RS_ZFUNC), state_zfunc }, WINED3D_GL_EXT_NONE },
5064 { STATE_RENDER(WINED3D_RS_DITHERENABLE), { STATE_RENDER(WINED3D_RS_DITHERENABLE), state_ditherenable }, WINED3D_GL_EXT_NONE },
5065 { STATE_RENDER(WINED3D_RS_SUBPIXEL), { STATE_RENDER(WINED3D_RS_SUBPIXEL), state_subpixel }, WINED3D_GL_EXT_NONE },
5066 { STATE_RENDER(WINED3D_RS_SUBPIXELX), { STATE_RENDER(WINED3D_RS_SUBPIXELX), state_subpixelx }, WINED3D_GL_EXT_NONE },
5067 { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), state_stippledalpha }, WINED3D_GL_EXT_NONE },
5068 { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), state_stippleenable }, WINED3D_GL_EXT_NONE },
5069 { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), state_mipmaplodbias }, WINED3D_GL_EXT_NONE },
5070 { STATE_RENDER(WINED3D_RS_ANISOTROPY), { STATE_RENDER(WINED3D_RS_ANISOTROPY), state_anisotropy }, WINED3D_GL_EXT_NONE },
5071 { STATE_RENDER(WINED3D_RS_FLUSHBATCH), { STATE_RENDER(WINED3D_RS_FLUSHBATCH), state_flushbatch }, WINED3D_GL_EXT_NONE },
5072 { STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),{ STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),state_translucentsi }, WINED3D_GL_EXT_NONE },
5073 { STATE_RENDER(WINED3D_RS_STENCILENABLE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), state_stencil }, WINED3D_GL_EXT_NONE },
5074 { STATE_RENDER(WINED3D_RS_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5075 { STATE_RENDER(WINED3D_RS_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5076 { STATE_RENDER(WINED3D_RS_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5077 { STATE_RENDER(WINED3D_RS_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5078 { STATE_RENDER(WINED3D_RS_STENCILREF), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5079 { STATE_RENDER(WINED3D_RS_STENCILMASK), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5080 { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite2s}, EXT_STENCIL_TWO_SIDE },
5081 { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite }, WINED3D_GL_EXT_NONE },
5082 { STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5083 { STATE_RENDER(WINED3D_RS_CCW_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5084 { STATE_RENDER(WINED3D_RS_CCW_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5085 { STATE_RENDER(WINED3D_RS_CCW_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5086 { STATE_RENDER(WINED3D_RS_CCW_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5087 { STATE_RENDER(WINED3D_RS_WRAP0), { STATE_RENDER(WINED3D_RS_WRAP0), state_wrap }, WINED3D_GL_EXT_NONE },
5088 { STATE_RENDER(WINED3D_RS_WRAP1), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5089 { STATE_RENDER(WINED3D_RS_WRAP2), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5090 { STATE_RENDER(WINED3D_RS_WRAP3), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5091 { STATE_RENDER(WINED3D_RS_WRAP4), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5092 { STATE_RENDER(WINED3D_RS_WRAP5), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5093 { STATE_RENDER(WINED3D_RS_WRAP6), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5094 { STATE_RENDER(WINED3D_RS_WRAP7), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5095 { STATE_RENDER(WINED3D_RS_WRAP8), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5096 { STATE_RENDER(WINED3D_RS_WRAP9), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5097 { STATE_RENDER(WINED3D_RS_WRAP10), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5098 { STATE_RENDER(WINED3D_RS_WRAP11), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5099 { STATE_RENDER(WINED3D_RS_WRAP12), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5100 { STATE_RENDER(WINED3D_RS_WRAP13), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5101 { STATE_RENDER(WINED3D_RS_WRAP14), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5102 { STATE_RENDER(WINED3D_RS_WRAP15), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5103 { STATE_RENDER(WINED3D_RS_EXTENTS), { STATE_RENDER(WINED3D_RS_EXTENTS), state_extents }, WINED3D_GL_EXT_NONE },
5104 { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), state_ckeyblend }, WINED3D_GL_EXT_NONE },
5105 { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), state_swvp }, WINED3D_GL_EXT_NONE },
5106 { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), state_patchedgestyle}, WINED3D_GL_EXT_NONE },
5107 { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), state_patchsegments }, WINED3D_GL_EXT_NONE },
5108 { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), state_positiondegree}, WINED3D_GL_EXT_NONE },
5109 { STATE_RENDER(WINED3D_RS_NORMALDEGREE), { STATE_RENDER(WINED3D_RS_NORMALDEGREE), state_normaldegree }, WINED3D_GL_EXT_NONE },
5110 { STATE_RENDER(WINED3D_RS_MINTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5111 { STATE_RENDER(WINED3D_RS_MAXTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5112 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_X), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5113 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Y), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5114 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Z), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5115 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_W), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5116 { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_nvdb }, EXT_DEPTH_BOUNDS_TEST },
5117 { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_tessellation }, WINED3D_GL_EXT_NONE },
5118 { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa }, ARB_MULTISAMPLE },
5119 { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa_w }, WINED3D_GL_EXT_NONE },
5120 { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), state_multisampmask }, WINED3D_GL_EXT_NONE },
5121 { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), state_debug_monitor }, WINED3D_GL_EXT_NONE },
5122 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite0 }, EXT_DRAW_BUFFERS2 },
5123 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite }, WINED3D_GL_EXT_NONE },
5124 { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop }, EXT_BLEND_MINMAX },
5125 { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop_w }, WINED3D_GL_EXT_NONE },
5126 { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), state_scissor }, WINED3D_GL_EXT_NONE },
5127 { STATE_RENDER(WINED3D_RS_SLOPESCALEDEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), NULL }, WINED3D_GL_EXT_NONE },
5128 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), state_colorwrite1 }, EXT_DRAW_BUFFERS2 },
5129 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5130 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), state_colorwrite2 }, EXT_DRAW_BUFFERS2 },
5131 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5132 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), state_colorwrite3 }, EXT_DRAW_BUFFERS2 },
5133 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5134 { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor }, EXT_BLEND_COLOR },
5135 { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor_w }, WINED3D_GL_EXT_NONE },
5136 { STATE_RENDER(WINED3D_RS_DEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), state_depthbias }, WINED3D_GL_EXT_NONE },
5137 { STATE_RENDER(WINED3D_RS_ZVISIBLE), { STATE_RENDER(WINED3D_RS_ZVISIBLE), state_zvisible }, WINED3D_GL_EXT_NONE },
5138 /* Samplers */
5139 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler }, WINED3D_GL_EXT_NONE },
5140 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler }, WINED3D_GL_EXT_NONE },
5141 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler }, WINED3D_GL_EXT_NONE },
5142 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler }, WINED3D_GL_EXT_NONE },
5143 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler }, WINED3D_GL_EXT_NONE },
5144 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler }, WINED3D_GL_EXT_NONE },
5145 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler }, WINED3D_GL_EXT_NONE },
5146 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler }, WINED3D_GL_EXT_NONE },
5147 { STATE_SAMPLER(8), { STATE_SAMPLER(8), sampler }, WINED3D_GL_EXT_NONE },
5148 { STATE_SAMPLER(9), { STATE_SAMPLER(9), sampler }, WINED3D_GL_EXT_NONE },
5149 { STATE_SAMPLER(10), { STATE_SAMPLER(10), sampler }, WINED3D_GL_EXT_NONE },
5150 { STATE_SAMPLER(11), { STATE_SAMPLER(11), sampler }, WINED3D_GL_EXT_NONE },
5151 { STATE_SAMPLER(12), { STATE_SAMPLER(12), sampler }, WINED3D_GL_EXT_NONE },
5152 { STATE_SAMPLER(13), { STATE_SAMPLER(13), sampler }, WINED3D_GL_EXT_NONE },
5153 { STATE_SAMPLER(14), { STATE_SAMPLER(14), sampler }, WINED3D_GL_EXT_NONE },
5154 { STATE_SAMPLER(15), { STATE_SAMPLER(15), sampler }, WINED3D_GL_EXT_NONE },
5155 { STATE_SAMPLER(16), /* Vertex sampler 0 */ { STATE_SAMPLER(16), sampler }, WINED3D_GL_EXT_NONE },
5156 { STATE_SAMPLER(17), /* Vertex sampler 1 */ { STATE_SAMPLER(17), sampler }, WINED3D_GL_EXT_NONE },
5157 { STATE_SAMPLER(18), /* Vertex sampler 2 */ { STATE_SAMPLER(18), sampler }, WINED3D_GL_EXT_NONE },
5158 { STATE_SAMPLER(19), /* Vertex sampler 3 */ { STATE_SAMPLER(19), sampler }, WINED3D_GL_EXT_NONE },
5159 { STATE_BASEVERTEXINDEX, { STATE_BASEVERTEXINDEX, state_nop, }, ARB_DRAW_ELEMENTS_BASE_VERTEX },
5160 { STATE_BASEVERTEXINDEX, { STATE_STREAMSRC, NULL, }, WINED3D_GL_EXT_NONE },
5161 { STATE_FRAMEBUFFER, { STATE_FRAMEBUFFER, context_state_fb }, WINED3D_GL_EXT_NONE },
5162 { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), context_state_drawbuf},WINED3D_GL_EXT_NONE },
5163 { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY), { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY), state_geometry_shader}, WINED3D_GL_EXT_NONE },
5164 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5167 static const struct StateEntryTemplate vp_ffp_states[] =
5169 { STATE_VDECL, { STATE_VDECL, vertexdeclaration }, WINED3D_GL_EXT_NONE },
5170 { STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX), { STATE_VDECL, NULL }, WINED3D_GL_EXT_NONE },
5171 { STATE_MATERIAL, { STATE_RENDER(WINED3D_RS_SPECULARENABLE), NULL }, WINED3D_GL_EXT_NONE },
5172 { STATE_RENDER(WINED3D_RS_SPECULARENABLE), { STATE_RENDER(WINED3D_RS_SPECULARENABLE), state_specularenable}, WINED3D_GL_EXT_NONE },
5173 /* Clip planes */
5174 { STATE_CLIPPLANE(0), { STATE_CLIPPLANE(0), clipplane }, WINED3D_GL_EXT_NONE },
5175 { STATE_CLIPPLANE(1), { STATE_CLIPPLANE(1), clipplane }, WINED3D_GL_EXT_NONE },
5176 { STATE_CLIPPLANE(2), { STATE_CLIPPLANE(2), clipplane }, WINED3D_GL_EXT_NONE },
5177 { STATE_CLIPPLANE(3), { STATE_CLIPPLANE(3), clipplane }, WINED3D_GL_EXT_NONE },
5178 { STATE_CLIPPLANE(4), { STATE_CLIPPLANE(4), clipplane }, WINED3D_GL_EXT_NONE },
5179 { STATE_CLIPPLANE(5), { STATE_CLIPPLANE(5), clipplane }, WINED3D_GL_EXT_NONE },
5180 { STATE_CLIPPLANE(6), { STATE_CLIPPLANE(6), clipplane }, WINED3D_GL_EXT_NONE },
5181 { STATE_CLIPPLANE(7), { STATE_CLIPPLANE(7), clipplane }, WINED3D_GL_EXT_NONE },
5182 { STATE_CLIPPLANE(8), { STATE_CLIPPLANE(8), clipplane }, WINED3D_GL_EXT_NONE },
5183 { STATE_CLIPPLANE(9), { STATE_CLIPPLANE(9), clipplane }, WINED3D_GL_EXT_NONE },
5184 { STATE_CLIPPLANE(10), { STATE_CLIPPLANE(10), clipplane }, WINED3D_GL_EXT_NONE },
5185 { STATE_CLIPPLANE(11), { STATE_CLIPPLANE(11), clipplane }, WINED3D_GL_EXT_NONE },
5186 { STATE_CLIPPLANE(12), { STATE_CLIPPLANE(12), clipplane }, WINED3D_GL_EXT_NONE },
5187 { STATE_CLIPPLANE(13), { STATE_CLIPPLANE(13), clipplane }, WINED3D_GL_EXT_NONE },
5188 { STATE_CLIPPLANE(14), { STATE_CLIPPLANE(14), clipplane }, WINED3D_GL_EXT_NONE },
5189 { STATE_CLIPPLANE(15), { STATE_CLIPPLANE(15), clipplane }, WINED3D_GL_EXT_NONE },
5190 { STATE_CLIPPLANE(16), { STATE_CLIPPLANE(16), clipplane }, WINED3D_GL_EXT_NONE },
5191 { STATE_CLIPPLANE(17), { STATE_CLIPPLANE(17), clipplane }, WINED3D_GL_EXT_NONE },
5192 { STATE_CLIPPLANE(18), { STATE_CLIPPLANE(18), clipplane }, WINED3D_GL_EXT_NONE },
5193 { STATE_CLIPPLANE(19), { STATE_CLIPPLANE(19), clipplane }, WINED3D_GL_EXT_NONE },
5194 { STATE_CLIPPLANE(20), { STATE_CLIPPLANE(20), clipplane }, WINED3D_GL_EXT_NONE },
5195 { STATE_CLIPPLANE(21), { STATE_CLIPPLANE(21), clipplane }, WINED3D_GL_EXT_NONE },
5196 { STATE_CLIPPLANE(22), { STATE_CLIPPLANE(22), clipplane }, WINED3D_GL_EXT_NONE },
5197 { STATE_CLIPPLANE(23), { STATE_CLIPPLANE(23), clipplane }, WINED3D_GL_EXT_NONE },
5198 { STATE_CLIPPLANE(24), { STATE_CLIPPLANE(24), clipplane }, WINED3D_GL_EXT_NONE },
5199 { STATE_CLIPPLANE(25), { STATE_CLIPPLANE(25), clipplane }, WINED3D_GL_EXT_NONE },
5200 { STATE_CLIPPLANE(26), { STATE_CLIPPLANE(26), clipplane }, WINED3D_GL_EXT_NONE },
5201 { STATE_CLIPPLANE(27), { STATE_CLIPPLANE(27), clipplane }, WINED3D_GL_EXT_NONE },
5202 { STATE_CLIPPLANE(28), { STATE_CLIPPLANE(28), clipplane }, WINED3D_GL_EXT_NONE },
5203 { STATE_CLIPPLANE(29), { STATE_CLIPPLANE(29), clipplane }, WINED3D_GL_EXT_NONE },
5204 { STATE_CLIPPLANE(30), { STATE_CLIPPLANE(30), clipplane }, WINED3D_GL_EXT_NONE },
5205 { STATE_CLIPPLANE(31), { STATE_CLIPPLANE(31), clipplane }, WINED3D_GL_EXT_NONE },
5206 /* Lights */
5207 { STATE_LIGHT_TYPE, { STATE_LIGHT_TYPE, state_nop }, WINED3D_GL_EXT_NONE },
5208 { STATE_ACTIVELIGHT(0), { STATE_ACTIVELIGHT(0), light }, WINED3D_GL_EXT_NONE },
5209 { STATE_ACTIVELIGHT(1), { STATE_ACTIVELIGHT(1), light }, WINED3D_GL_EXT_NONE },
5210 { STATE_ACTIVELIGHT(2), { STATE_ACTIVELIGHT(2), light }, WINED3D_GL_EXT_NONE },
5211 { STATE_ACTIVELIGHT(3), { STATE_ACTIVELIGHT(3), light }, WINED3D_GL_EXT_NONE },
5212 { STATE_ACTIVELIGHT(4), { STATE_ACTIVELIGHT(4), light }, WINED3D_GL_EXT_NONE },
5213 { STATE_ACTIVELIGHT(5), { STATE_ACTIVELIGHT(5), light }, WINED3D_GL_EXT_NONE },
5214 { STATE_ACTIVELIGHT(6), { STATE_ACTIVELIGHT(6), light }, WINED3D_GL_EXT_NONE },
5215 { STATE_ACTIVELIGHT(7), { STATE_ACTIVELIGHT(7), light }, WINED3D_GL_EXT_NONE },
5216 /* Viewport */
5217 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_vertexpart }, WINED3D_GL_EXT_NONE },
5218 /* Transform states follow */
5219 { STATE_TRANSFORM(WINED3D_TS_VIEW), { STATE_TRANSFORM(WINED3D_TS_VIEW), transform_view }, WINED3D_GL_EXT_NONE },
5220 { STATE_TRANSFORM(WINED3D_TS_PROJECTION), { STATE_TRANSFORM(WINED3D_TS_PROJECTION), transform_projection}, WINED3D_GL_EXT_NONE },
5221 { STATE_TRANSFORM(WINED3D_TS_TEXTURE0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5222 { STATE_TRANSFORM(WINED3D_TS_TEXTURE1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5223 { STATE_TRANSFORM(WINED3D_TS_TEXTURE2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5224 { STATE_TRANSFORM(WINED3D_TS_TEXTURE3), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5225 { STATE_TRANSFORM(WINED3D_TS_TEXTURE4), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5226 { STATE_TRANSFORM(WINED3D_TS_TEXTURE5), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5227 { STATE_TRANSFORM(WINED3D_TS_TEXTURE6), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5228 { STATE_TRANSFORM(WINED3D_TS_TEXTURE7), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5229 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), transform_world }, WINED3D_GL_EXT_NONE },
5230 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), transform_worldex }, WINED3D_GL_EXT_NONE },
5231 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), transform_worldex }, WINED3D_GL_EXT_NONE },
5232 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), transform_worldex }, WINED3D_GL_EXT_NONE },
5233 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), transform_worldex }, WINED3D_GL_EXT_NONE },
5234 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), transform_worldex }, WINED3D_GL_EXT_NONE },
5235 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), transform_worldex }, WINED3D_GL_EXT_NONE },
5236 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), transform_worldex }, WINED3D_GL_EXT_NONE },
5237 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), transform_worldex }, WINED3D_GL_EXT_NONE },
5238 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), transform_worldex }, WINED3D_GL_EXT_NONE },
5239 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), transform_worldex }, WINED3D_GL_EXT_NONE },
5240 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), transform_worldex }, WINED3D_GL_EXT_NONE },
5241 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), transform_worldex }, WINED3D_GL_EXT_NONE },
5242 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), transform_worldex }, WINED3D_GL_EXT_NONE },
5243 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), transform_worldex }, WINED3D_GL_EXT_NONE },
5244 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), transform_worldex }, WINED3D_GL_EXT_NONE },
5245 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), transform_worldex }, WINED3D_GL_EXT_NONE },
5246 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), transform_worldex }, WINED3D_GL_EXT_NONE },
5247 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), transform_worldex }, WINED3D_GL_EXT_NONE },
5248 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), transform_worldex }, WINED3D_GL_EXT_NONE },
5249 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), transform_worldex }, WINED3D_GL_EXT_NONE },
5250 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), transform_worldex }, WINED3D_GL_EXT_NONE },
5251 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), transform_worldex }, WINED3D_GL_EXT_NONE },
5252 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), transform_worldex }, WINED3D_GL_EXT_NONE },
5253 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), transform_worldex }, WINED3D_GL_EXT_NONE },
5254 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), transform_worldex }, WINED3D_GL_EXT_NONE },
5255 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), transform_worldex }, WINED3D_GL_EXT_NONE },
5256 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), transform_worldex }, WINED3D_GL_EXT_NONE },
5257 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), transform_worldex }, WINED3D_GL_EXT_NONE },
5258 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), transform_worldex }, WINED3D_GL_EXT_NONE },
5259 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), transform_worldex }, WINED3D_GL_EXT_NONE },
5260 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), transform_worldex }, WINED3D_GL_EXT_NONE },
5261 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), transform_worldex }, WINED3D_GL_EXT_NONE },
5262 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), transform_worldex }, WINED3D_GL_EXT_NONE },
5263 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), transform_worldex }, WINED3D_GL_EXT_NONE },
5264 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), transform_worldex }, WINED3D_GL_EXT_NONE },
5265 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), transform_worldex }, WINED3D_GL_EXT_NONE },
5266 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), transform_worldex }, WINED3D_GL_EXT_NONE },
5267 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), transform_worldex }, WINED3D_GL_EXT_NONE },
5268 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), transform_worldex }, WINED3D_GL_EXT_NONE },
5269 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), transform_worldex }, WINED3D_GL_EXT_NONE },
5270 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), transform_worldex }, WINED3D_GL_EXT_NONE },
5271 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), transform_worldex }, WINED3D_GL_EXT_NONE },
5272 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), transform_worldex }, WINED3D_GL_EXT_NONE },
5273 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), transform_worldex }, WINED3D_GL_EXT_NONE },
5274 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), transform_worldex }, WINED3D_GL_EXT_NONE },
5275 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), transform_worldex }, WINED3D_GL_EXT_NONE },
5276 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), transform_worldex }, WINED3D_GL_EXT_NONE },
5277 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), transform_worldex }, WINED3D_GL_EXT_NONE },
5278 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), transform_worldex }, WINED3D_GL_EXT_NONE },
5279 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), transform_worldex }, WINED3D_GL_EXT_NONE },
5280 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), transform_worldex }, WINED3D_GL_EXT_NONE },
5281 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), transform_worldex }, WINED3D_GL_EXT_NONE },
5282 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), transform_worldex }, WINED3D_GL_EXT_NONE },
5283 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), transform_worldex }, WINED3D_GL_EXT_NONE },
5284 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), transform_worldex }, WINED3D_GL_EXT_NONE },
5285 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), transform_worldex }, WINED3D_GL_EXT_NONE },
5286 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), transform_worldex }, WINED3D_GL_EXT_NONE },
5287 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), transform_worldex }, WINED3D_GL_EXT_NONE },
5288 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), transform_worldex }, WINED3D_GL_EXT_NONE },
5289 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), transform_worldex }, WINED3D_GL_EXT_NONE },
5290 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), transform_worldex }, WINED3D_GL_EXT_NONE },
5291 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), transform_worldex }, WINED3D_GL_EXT_NONE },
5292 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), transform_worldex }, WINED3D_GL_EXT_NONE },
5293 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), transform_worldex }, WINED3D_GL_EXT_NONE },
5294 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), transform_worldex }, WINED3D_GL_EXT_NONE },
5295 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), transform_worldex }, WINED3D_GL_EXT_NONE },
5296 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), transform_worldex }, WINED3D_GL_EXT_NONE },
5297 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), transform_worldex }, WINED3D_GL_EXT_NONE },
5298 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), transform_worldex }, WINED3D_GL_EXT_NONE },
5299 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), transform_worldex }, WINED3D_GL_EXT_NONE },
5300 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), transform_worldex }, WINED3D_GL_EXT_NONE },
5301 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), transform_worldex }, WINED3D_GL_EXT_NONE },
5302 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), transform_worldex }, WINED3D_GL_EXT_NONE },
5303 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), transform_worldex }, WINED3D_GL_EXT_NONE },
5304 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), transform_worldex }, WINED3D_GL_EXT_NONE },
5305 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), transform_worldex }, WINED3D_GL_EXT_NONE },
5306 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), transform_worldex }, WINED3D_GL_EXT_NONE },
5307 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), transform_worldex }, WINED3D_GL_EXT_NONE },
5308 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), transform_worldex }, WINED3D_GL_EXT_NONE },
5309 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), transform_worldex }, WINED3D_GL_EXT_NONE },
5310 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), transform_worldex }, WINED3D_GL_EXT_NONE },
5311 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), transform_worldex }, WINED3D_GL_EXT_NONE },
5312 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), transform_worldex }, WINED3D_GL_EXT_NONE },
5313 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), transform_worldex }, WINED3D_GL_EXT_NONE },
5314 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), transform_worldex }, WINED3D_GL_EXT_NONE },
5315 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), transform_worldex }, WINED3D_GL_EXT_NONE },
5316 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), transform_worldex }, WINED3D_GL_EXT_NONE },
5317 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), transform_worldex }, WINED3D_GL_EXT_NONE },
5318 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), transform_worldex }, WINED3D_GL_EXT_NONE },
5319 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), transform_worldex }, WINED3D_GL_EXT_NONE },
5320 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), transform_worldex }, WINED3D_GL_EXT_NONE },
5321 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), transform_worldex }, WINED3D_GL_EXT_NONE },
5322 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), transform_worldex }, WINED3D_GL_EXT_NONE },
5323 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), transform_worldex }, WINED3D_GL_EXT_NONE },
5324 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), transform_worldex }, WINED3D_GL_EXT_NONE },
5325 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), transform_worldex }, WINED3D_GL_EXT_NONE },
5326 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), transform_worldex }, WINED3D_GL_EXT_NONE },
5327 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), transform_worldex }, WINED3D_GL_EXT_NONE },
5328 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), transform_worldex }, WINED3D_GL_EXT_NONE },
5329 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), transform_worldex }, WINED3D_GL_EXT_NONE },
5330 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), transform_worldex }, WINED3D_GL_EXT_NONE },
5331 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), transform_worldex }, WINED3D_GL_EXT_NONE },
5332 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), transform_worldex }, WINED3D_GL_EXT_NONE },
5333 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), transform_worldex }, WINED3D_GL_EXT_NONE },
5334 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), transform_worldex }, WINED3D_GL_EXT_NONE },
5335 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), transform_worldex }, WINED3D_GL_EXT_NONE },
5336 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), transform_worldex }, WINED3D_GL_EXT_NONE },
5337 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), transform_worldex }, WINED3D_GL_EXT_NONE },
5338 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), transform_worldex }, WINED3D_GL_EXT_NONE },
5339 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), transform_worldex }, WINED3D_GL_EXT_NONE },
5340 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), transform_worldex }, WINED3D_GL_EXT_NONE },
5341 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), transform_worldex }, WINED3D_GL_EXT_NONE },
5342 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), transform_worldex }, WINED3D_GL_EXT_NONE },
5343 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), transform_worldex }, WINED3D_GL_EXT_NONE },
5344 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), transform_worldex }, WINED3D_GL_EXT_NONE },
5345 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), transform_worldex }, WINED3D_GL_EXT_NONE },
5346 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), transform_worldex }, WINED3D_GL_EXT_NONE },
5347 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), transform_worldex }, WINED3D_GL_EXT_NONE },
5348 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), transform_worldex }, WINED3D_GL_EXT_NONE },
5349 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), transform_worldex }, WINED3D_GL_EXT_NONE },
5350 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), transform_worldex }, WINED3D_GL_EXT_NONE },
5351 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), transform_worldex }, WINED3D_GL_EXT_NONE },
5352 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), transform_worldex }, WINED3D_GL_EXT_NONE },
5353 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), transform_worldex }, WINED3D_GL_EXT_NONE },
5354 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), transform_worldex }, WINED3D_GL_EXT_NONE },
5355 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), transform_worldex }, WINED3D_GL_EXT_NONE },
5356 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), transform_worldex }, WINED3D_GL_EXT_NONE },
5357 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), transform_worldex }, WINED3D_GL_EXT_NONE },
5358 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), transform_worldex }, WINED3D_GL_EXT_NONE },
5359 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), transform_worldex }, WINED3D_GL_EXT_NONE },
5360 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), transform_worldex }, WINED3D_GL_EXT_NONE },
5361 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), transform_worldex }, WINED3D_GL_EXT_NONE },
5362 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), transform_worldex }, WINED3D_GL_EXT_NONE },
5363 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), transform_worldex }, WINED3D_GL_EXT_NONE },
5364 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), transform_worldex }, WINED3D_GL_EXT_NONE },
5365 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), transform_worldex }, WINED3D_GL_EXT_NONE },
5366 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), transform_worldex }, WINED3D_GL_EXT_NONE },
5367 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), transform_worldex }, WINED3D_GL_EXT_NONE },
5368 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), transform_worldex }, WINED3D_GL_EXT_NONE },
5369 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), transform_worldex }, WINED3D_GL_EXT_NONE },
5370 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), transform_worldex }, WINED3D_GL_EXT_NONE },
5371 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), transform_worldex }, WINED3D_GL_EXT_NONE },
5372 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), transform_worldex }, WINED3D_GL_EXT_NONE },
5373 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), transform_worldex }, WINED3D_GL_EXT_NONE },
5374 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), transform_worldex }, WINED3D_GL_EXT_NONE },
5375 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), transform_worldex }, WINED3D_GL_EXT_NONE },
5376 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), transform_worldex }, WINED3D_GL_EXT_NONE },
5377 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), transform_worldex }, WINED3D_GL_EXT_NONE },
5378 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), transform_worldex }, WINED3D_GL_EXT_NONE },
5379 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), transform_worldex }, WINED3D_GL_EXT_NONE },
5380 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), transform_worldex }, WINED3D_GL_EXT_NONE },
5381 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), transform_worldex }, WINED3D_GL_EXT_NONE },
5382 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), transform_worldex }, WINED3D_GL_EXT_NONE },
5383 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), transform_worldex }, WINED3D_GL_EXT_NONE },
5384 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), transform_worldex }, WINED3D_GL_EXT_NONE },
5385 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), transform_worldex }, WINED3D_GL_EXT_NONE },
5386 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), transform_worldex }, WINED3D_GL_EXT_NONE },
5387 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), transform_worldex }, WINED3D_GL_EXT_NONE },
5388 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), transform_worldex }, WINED3D_GL_EXT_NONE },
5389 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), transform_worldex }, WINED3D_GL_EXT_NONE },
5390 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), transform_worldex }, WINED3D_GL_EXT_NONE },
5391 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), transform_worldex }, WINED3D_GL_EXT_NONE },
5392 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), transform_worldex }, WINED3D_GL_EXT_NONE },
5393 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), transform_worldex }, WINED3D_GL_EXT_NONE },
5394 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), transform_worldex }, WINED3D_GL_EXT_NONE },
5395 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), transform_worldex }, WINED3D_GL_EXT_NONE },
5396 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), transform_worldex }, WINED3D_GL_EXT_NONE },
5397 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), transform_worldex }, WINED3D_GL_EXT_NONE },
5398 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), transform_worldex }, WINED3D_GL_EXT_NONE },
5399 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), transform_worldex }, WINED3D_GL_EXT_NONE },
5400 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), transform_worldex }, WINED3D_GL_EXT_NONE },
5401 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), transform_worldex }, WINED3D_GL_EXT_NONE },
5402 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), transform_worldex }, WINED3D_GL_EXT_NONE },
5403 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), transform_worldex }, WINED3D_GL_EXT_NONE },
5404 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), transform_worldex }, WINED3D_GL_EXT_NONE },
5405 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), transform_worldex }, WINED3D_GL_EXT_NONE },
5406 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), transform_worldex }, WINED3D_GL_EXT_NONE },
5407 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), transform_worldex }, WINED3D_GL_EXT_NONE },
5408 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), transform_worldex }, WINED3D_GL_EXT_NONE },
5409 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), transform_worldex }, WINED3D_GL_EXT_NONE },
5410 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), transform_worldex }, WINED3D_GL_EXT_NONE },
5411 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), transform_worldex }, WINED3D_GL_EXT_NONE },
5412 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), transform_worldex }, WINED3D_GL_EXT_NONE },
5413 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), transform_worldex }, WINED3D_GL_EXT_NONE },
5414 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), transform_worldex }, WINED3D_GL_EXT_NONE },
5415 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), transform_worldex }, WINED3D_GL_EXT_NONE },
5416 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), transform_worldex }, WINED3D_GL_EXT_NONE },
5417 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), transform_worldex }, WINED3D_GL_EXT_NONE },
5418 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), transform_worldex }, WINED3D_GL_EXT_NONE },
5419 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), transform_worldex }, WINED3D_GL_EXT_NONE },
5420 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), transform_worldex }, WINED3D_GL_EXT_NONE },
5421 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), transform_worldex }, WINED3D_GL_EXT_NONE },
5422 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), transform_worldex }, WINED3D_GL_EXT_NONE },
5423 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), transform_worldex }, WINED3D_GL_EXT_NONE },
5424 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), transform_worldex }, WINED3D_GL_EXT_NONE },
5425 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), transform_worldex }, WINED3D_GL_EXT_NONE },
5426 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), transform_worldex }, WINED3D_GL_EXT_NONE },
5427 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), transform_worldex }, WINED3D_GL_EXT_NONE },
5428 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), transform_worldex }, WINED3D_GL_EXT_NONE },
5429 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), transform_worldex }, WINED3D_GL_EXT_NONE },
5430 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), transform_worldex }, WINED3D_GL_EXT_NONE },
5431 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), transform_worldex }, WINED3D_GL_EXT_NONE },
5432 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), transform_worldex }, WINED3D_GL_EXT_NONE },
5433 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), transform_worldex }, WINED3D_GL_EXT_NONE },
5434 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), transform_worldex }, WINED3D_GL_EXT_NONE },
5435 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), transform_worldex }, WINED3D_GL_EXT_NONE },
5436 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), transform_worldex }, WINED3D_GL_EXT_NONE },
5437 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), transform_worldex }, WINED3D_GL_EXT_NONE },
5438 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), transform_worldex }, WINED3D_GL_EXT_NONE },
5439 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), transform_worldex }, WINED3D_GL_EXT_NONE },
5440 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), transform_worldex }, WINED3D_GL_EXT_NONE },
5441 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), transform_worldex }, WINED3D_GL_EXT_NONE },
5442 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), transform_worldex }, WINED3D_GL_EXT_NONE },
5443 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), transform_worldex }, WINED3D_GL_EXT_NONE },
5444 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), transform_worldex }, WINED3D_GL_EXT_NONE },
5445 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), transform_worldex }, WINED3D_GL_EXT_NONE },
5446 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), transform_worldex }, WINED3D_GL_EXT_NONE },
5447 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), transform_worldex }, WINED3D_GL_EXT_NONE },
5448 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), transform_worldex }, WINED3D_GL_EXT_NONE },
5449 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), transform_worldex }, WINED3D_GL_EXT_NONE },
5450 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), transform_worldex }, WINED3D_GL_EXT_NONE },
5451 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), transform_worldex }, WINED3D_GL_EXT_NONE },
5452 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), transform_worldex }, WINED3D_GL_EXT_NONE },
5453 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), transform_worldex }, WINED3D_GL_EXT_NONE },
5454 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), transform_worldex }, WINED3D_GL_EXT_NONE },
5455 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), transform_worldex }, WINED3D_GL_EXT_NONE },
5456 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), transform_worldex }, WINED3D_GL_EXT_NONE },
5457 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), transform_worldex }, WINED3D_GL_EXT_NONE },
5458 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), transform_worldex }, WINED3D_GL_EXT_NONE },
5459 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), transform_worldex }, WINED3D_GL_EXT_NONE },
5460 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), transform_worldex }, WINED3D_GL_EXT_NONE },
5461 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), transform_worldex }, WINED3D_GL_EXT_NONE },
5462 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), transform_worldex }, WINED3D_GL_EXT_NONE },
5463 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), transform_worldex }, WINED3D_GL_EXT_NONE },
5464 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), transform_worldex }, WINED3D_GL_EXT_NONE },
5465 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), transform_worldex }, WINED3D_GL_EXT_NONE },
5466 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), transform_worldex }, WINED3D_GL_EXT_NONE },
5467 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), transform_worldex }, WINED3D_GL_EXT_NONE },
5468 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), transform_worldex }, WINED3D_GL_EXT_NONE },
5469 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), transform_worldex }, WINED3D_GL_EXT_NONE },
5470 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), transform_worldex }, WINED3D_GL_EXT_NONE },
5471 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), transform_worldex }, WINED3D_GL_EXT_NONE },
5472 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), transform_worldex }, WINED3D_GL_EXT_NONE },
5473 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), transform_worldex }, WINED3D_GL_EXT_NONE },
5474 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), transform_worldex }, WINED3D_GL_EXT_NONE },
5475 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), transform_worldex }, WINED3D_GL_EXT_NONE },
5476 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), transform_worldex }, WINED3D_GL_EXT_NONE },
5477 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), transform_worldex }, WINED3D_GL_EXT_NONE },
5478 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), transform_worldex }, WINED3D_GL_EXT_NONE },
5479 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), transform_worldex }, WINED3D_GL_EXT_NONE },
5480 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), transform_worldex }, WINED3D_GL_EXT_NONE },
5481 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), transform_worldex }, WINED3D_GL_EXT_NONE },
5482 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), transform_worldex }, WINED3D_GL_EXT_NONE },
5483 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), transform_worldex }, WINED3D_GL_EXT_NONE },
5484 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), transform_worldex }, WINED3D_GL_EXT_NONE },
5485 { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5486 { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5487 { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5488 { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5489 { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5490 { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5491 { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5492 { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5493 { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5494 { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5495 { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5496 { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5497 { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5498 { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5499 { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5500 { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5501 /* Fog */
5502 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_vertexpart}, WINED3D_GL_EXT_NONE },
5503 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5504 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5505 { STATE_RENDER(WINED3D_RS_RANGEFOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5506 { STATE_RENDER(WINED3D_RS_CLIPPING), { STATE_RENDER(WINED3D_RS_CLIPPING), state_clipping }, WINED3D_GL_EXT_NONE },
5507 { STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE), { STATE_RENDER(WINED3D_RS_CLIPPING), NULL }, WINED3D_GL_EXT_NONE },
5508 { STATE_RENDER(WINED3D_RS_LIGHTING), { STATE_RENDER(WINED3D_RS_LIGHTING), state_lighting }, WINED3D_GL_EXT_NONE },
5509 { STATE_RENDER(WINED3D_RS_AMBIENT), { STATE_RENDER(WINED3D_RS_AMBIENT), state_ambient }, WINED3D_GL_EXT_NONE },
5510 { STATE_RENDER(WINED3D_RS_COLORVERTEX), { STATE_RENDER(WINED3D_RS_COLORVERTEX), state_colormat }, WINED3D_GL_EXT_NONE },
5511 { STATE_RENDER(WINED3D_RS_LOCALVIEWER), { STATE_RENDER(WINED3D_RS_LOCALVIEWER), state_localviewer }, WINED3D_GL_EXT_NONE },
5512 { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), state_normalize }, WINED3D_GL_EXT_NONE },
5513 { STATE_RENDER(WINED3D_RS_DIFFUSEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5514 { STATE_RENDER(WINED3D_RS_SPECULARMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5515 { STATE_RENDER(WINED3D_RS_AMBIENTMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5516 { STATE_RENDER(WINED3D_RS_EMISSIVEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5517 { STATE_RENDER(WINED3D_RS_VERTEXBLEND), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), state_vertexblend }, ARB_VERTEX_BLEND },
5518 { STATE_RENDER(WINED3D_RS_VERTEXBLEND), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), state_vertexblend_w }, WINED3D_GL_EXT_NONE },
5519 { STATE_RENDER(WINED3D_RS_POINTSIZE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5520 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_arb }, ARB_POINT_PARAMETERS },
5521 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_ext }, EXT_POINT_PARAMETERS },
5522 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_w }, WINED3D_GL_EXT_NONE },
5523 { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite }, ARB_POINT_SPRITE },
5524 { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite_w }, WINED3D_GL_EXT_NONE },
5525 { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), state_pscale }, WINED3D_GL_EXT_NONE },
5526 { STATE_RENDER(WINED3D_RS_POINTSCALE_A), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5527 { STATE_RENDER(WINED3D_RS_POINTSCALE_B), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5528 { STATE_RENDER(WINED3D_RS_POINTSCALE_C), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5529 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, ARB_POINT_PARAMETERS },
5530 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, EXT_POINT_PARAMETERS },
5531 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, WINED3D_GL_EXT_NONE },
5532 { STATE_RENDER(WINED3D_RS_TWEENFACTOR), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE },
5533 { STATE_RENDER(WINED3D_RS_INDEXEDVERTEXBLENDENABLE), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE },
5535 /* Samplers for NP2 texture matrix adjustions. They are not needed if GL_ARB_texture_non_power_of_two is supported,
5536 * so register a NULL state handler in that case to get the vertex part of sampler() skipped(VTF is handled in the misc states.
5537 * otherwise, register sampler_texmatrix, which takes care of updating the texture matrix
5539 { STATE_SAMPLER(0), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5540 { STATE_SAMPLER(0), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5541 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5542 { STATE_SAMPLER(1), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5543 { STATE_SAMPLER(1), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5544 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5545 { STATE_SAMPLER(2), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5546 { STATE_SAMPLER(2), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5547 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5548 { STATE_SAMPLER(3), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5549 { STATE_SAMPLER(3), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5550 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5551 { STATE_SAMPLER(4), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5552 { STATE_SAMPLER(4), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5553 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5554 { STATE_SAMPLER(5), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5555 { STATE_SAMPLER(5), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5556 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5557 { STATE_SAMPLER(6), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5558 { STATE_SAMPLER(6), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5559 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5560 { STATE_SAMPLER(7), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5561 { STATE_SAMPLER(7), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5562 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5563 { STATE_POINT_SIZE_ENABLE, { STATE_POINT_SIZE_ENABLE, state_nop }, WINED3D_GL_EXT_NONE },
5564 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5567 static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
5568 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5569 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5570 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5571 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5572 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5573 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5574 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5575 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5576 { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5577 { STATE_TEXTURESTAGE(0, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5578 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5579 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5580 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5581 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5582 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5583 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5584 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5585 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5586 { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5587 { STATE_TEXTURESTAGE(1, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5588 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5589 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5590 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5591 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5592 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5593 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5594 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5595 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5596 { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5597 { STATE_TEXTURESTAGE(2, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5598 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5599 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5600 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5601 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5602 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5603 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5604 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5605 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5606 { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5607 { STATE_TEXTURESTAGE(3, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5608 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5609 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5610 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5611 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5612 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5613 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5614 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5615 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5616 { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5617 { STATE_TEXTURESTAGE(4, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5618 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5619 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5620 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5621 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5622 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5623 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5624 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5625 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5626 { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5627 { STATE_TEXTURESTAGE(5, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5628 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5629 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5630 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5631 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5632 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5633 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5634 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5635 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5636 { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5637 { STATE_TEXTURESTAGE(6, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5638 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5639 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5640 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5641 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5642 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5643 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5644 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5645 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5646 { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5647 { STATE_TEXTURESTAGE(7, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5648 { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), apply_pixelshader }, WINED3D_GL_EXT_NONE },
5649 { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), NULL }, WINED3D_GL_EXT_NONE },
5650 { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), state_texfactor }, WINED3D_GL_EXT_NONE },
5651 { STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
5652 { STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
5653 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
5654 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5655 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5656 { STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
5657 { STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE },
5658 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE },
5659 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE },
5660 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE },
5661 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, WINED3D_GL_EXT_NONE },
5662 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, WINED3D_GL_EXT_NONE },
5663 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE },
5664 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE },
5665 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE },
5666 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5669 /* Context activation is done by the caller. */
5670 static void ffp_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5672 static void *ffp_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
5674 return shader_priv;
5677 static void ffp_free(struct wined3d_device *device) {}
5679 static void vp_ffp_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
5681 caps->xyzrhw = FALSE;
5682 caps->max_active_lights = gl_info->limits.lights;
5683 caps->max_vertex_blend_matrices = gl_info->limits.blends;
5684 caps->max_vertex_blend_matrix_index = 0;
5685 caps->vertex_processing_caps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS
5686 | WINED3DVTXPCAPS_MATERIALSOURCE7
5687 | WINED3DVTXPCAPS_POSITIONALLIGHTS
5688 | WINED3DVTXPCAPS_LOCALVIEWER
5689 | WINED3DVTXPCAPS_VERTEXFOG
5690 | WINED3DVTXPCAPS_TEXGEN
5691 | WINED3DVTXPCAPS_TEXGEN_SPHEREMAP;
5692 caps->fvf_caps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
5693 caps->max_user_clip_planes = gl_info->limits.clipplanes;
5694 caps->raster_caps = 0;
5695 if (gl_info->supported[NV_FOG_DISTANCE])
5696 caps->raster_caps |= WINED3DPRASTERCAPS_FOGRANGE;
5699 const struct wined3d_vertex_pipe_ops ffp_vertex_pipe =
5701 ffp_enable,
5702 vp_ffp_get_caps,
5703 ffp_alloc,
5704 ffp_free,
5705 vp_ffp_states,
5708 static void ffp_fragment_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
5710 caps->wined3d_caps = 0;
5711 caps->PrimitiveMiscCaps = 0;
5712 caps->TextureOpCaps = WINED3DTEXOPCAPS_ADD
5713 | WINED3DTEXOPCAPS_ADDSIGNED
5714 | WINED3DTEXOPCAPS_ADDSIGNED2X
5715 | WINED3DTEXOPCAPS_MODULATE
5716 | WINED3DTEXOPCAPS_MODULATE2X
5717 | WINED3DTEXOPCAPS_MODULATE4X
5718 | WINED3DTEXOPCAPS_SELECTARG1
5719 | WINED3DTEXOPCAPS_SELECTARG2
5720 | WINED3DTEXOPCAPS_DISABLE;
5722 if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE]
5723 || gl_info->supported[EXT_TEXTURE_ENV_COMBINE]
5724 || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
5726 caps->TextureOpCaps |= WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
5727 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
5728 | WINED3DTEXOPCAPS_BLENDFACTORALPHA
5729 | WINED3DTEXOPCAPS_BLENDCURRENTALPHA
5730 | WINED3DTEXOPCAPS_LERP
5731 | WINED3DTEXOPCAPS_SUBTRACT;
5733 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]
5734 || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
5736 caps->TextureOpCaps |= WINED3DTEXOPCAPS_ADDSMOOTH
5737 | WINED3DTEXOPCAPS_MULTIPLYADD
5738 | WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
5739 | WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
5740 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
5742 if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
5743 caps->TextureOpCaps |= WINED3DTEXOPCAPS_DOTPRODUCT3;
5745 caps->MaxTextureBlendStages = gl_info->limits.textures;
5746 caps->MaxSimultaneousTextures = gl_info->limits.textures;
5749 static BOOL ffp_color_fixup_supported(struct color_fixup_desc fixup)
5751 if (TRACE_ON(d3d))
5753 TRACE("Checking support for fixup:\n");
5754 dump_color_fixup_desc(fixup);
5757 /* We only support identity conversions. */
5758 if (is_identity_fixup(fixup))
5760 TRACE("[OK]\n");
5761 return TRUE;
5764 TRACE("[FAILED]\n");
5765 return FALSE;
5768 const struct fragment_pipeline ffp_fragment_pipeline = {
5769 ffp_enable,
5770 ffp_fragment_get_caps,
5771 ffp_alloc,
5772 ffp_free,
5773 ffp_color_fixup_supported,
5774 ffp_fragmentstate_template,
5777 static void none_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5779 static void *none_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
5781 return shader_priv;
5784 static void none_free(struct wined3d_device *device) {}
5786 static void vp_none_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
5788 memset(caps, 0, sizeof(*caps));
5791 const struct wined3d_vertex_pipe_ops none_vertex_pipe =
5793 none_enable,
5794 vp_none_get_caps,
5795 none_alloc,
5796 none_free,
5797 NULL,
5800 static void fp_none_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
5802 memset(caps, 0, sizeof(*caps));
5805 static BOOL fp_none_color_fixup_supported(struct color_fixup_desc fixup)
5807 return is_identity_fixup(fixup);
5810 const struct fragment_pipeline none_fragment_pipe =
5812 none_enable,
5813 fp_none_get_caps,
5814 none_alloc,
5815 none_free,
5816 fp_none_color_fixup_supported,
5817 NULL,
5820 static unsigned int num_handlers(const APPLYSTATEFUNC *funcs)
5822 unsigned int i;
5823 for(i = 0; funcs[i]; i++);
5824 return i;
5827 static void multistate_apply_2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5829 context->swapchain->device->multistate_funcs[state_id][0](context, state, state_id);
5830 context->swapchain->device->multistate_funcs[state_id][1](context, state, state_id);
5833 static void multistate_apply_3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5835 context->swapchain->device->multistate_funcs[state_id][0](context, state, state_id);
5836 context->swapchain->device->multistate_funcs[state_id][1](context, state, state_id);
5837 context->swapchain->device->multistate_funcs[state_id][2](context, state, state_id);
5840 static void prune_invalid_states(struct StateEntry *state_table, const struct wined3d_gl_info *gl_info,
5841 const struct wined3d_d3d_info *d3d_info)
5843 unsigned int start, last, i;
5845 start = STATE_TEXTURESTAGE(d3d_info->limits.ffp_blend_stages, 0);
5846 last = STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE);
5847 for (i = start; i <= last; ++i)
5849 state_table[i].representative = 0;
5850 state_table[i].apply = state_undefined;
5853 start = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + d3d_info->limits.ffp_blend_stages);
5854 last = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + MAX_TEXTURES - 1);
5855 for (i = start; i <= last; ++i)
5857 state_table[i].representative = 0;
5858 state_table[i].apply = state_undefined;
5861 start = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(gl_info->limits.blends));
5862 last = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255));
5863 for (i = start; i <= last; ++i)
5865 state_table[i].representative = 0;
5866 state_table[i].apply = state_undefined;
5870 static void validate_state_table(struct StateEntry *state_table)
5872 static const struct
5874 DWORD first;
5875 DWORD last;
5877 rs_holes[] =
5879 { 1, 1},
5880 { 3, 3},
5881 { 17, 18},
5882 { 21, 21},
5883 { 42, 45},
5884 { 47, 47},
5885 { 61, 127},
5886 {149, 150},
5887 {169, 169},
5888 {177, 177},
5889 {196, 197},
5890 { 0, 0},
5892 static const DWORD simple_states[] =
5894 STATE_MATERIAL,
5895 STATE_VDECL,
5896 STATE_STREAMSRC,
5897 STATE_INDEXBUFFER,
5898 STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX),
5899 STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY),
5900 STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),
5901 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),
5902 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),
5903 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),
5904 STATE_VIEWPORT,
5905 STATE_LIGHT_TYPE,
5906 STATE_SCISSORRECT,
5907 STATE_FRONTFACE,
5908 STATE_POINTSPRITECOORDORIGIN,
5909 STATE_BASEVERTEXINDEX,
5910 STATE_FRAMEBUFFER,
5911 STATE_POINT_SIZE_ENABLE,
5913 unsigned int i, current;
5915 for (i = STATE_RENDER(1), current = 0; i <= STATE_RENDER(WINEHIGHEST_RENDER_STATE); ++i)
5917 if (!rs_holes[current].first || i < STATE_RENDER(rs_holes[current].first))
5919 if (!state_table[i].representative)
5920 ERR("State %s (%#x) should have a representative.\n", debug_d3dstate(i), i);
5922 else if (state_table[i].representative)
5923 ERR("State %s (%#x) shouldn't have a representative.\n", debug_d3dstate(i), i);
5925 if (i == STATE_RENDER(rs_holes[current].last)) ++current;
5928 for (i = 0; i < sizeof(simple_states) / sizeof(*simple_states); ++i)
5930 if (!state_table[simple_states[i]].representative)
5931 ERR("State %s (%#x) should have a representative.\n",
5932 debug_d3dstate(simple_states[i]), simple_states[i]);
5935 for (i = 0; i < STATE_HIGHEST + 1; ++i)
5937 DWORD rep = state_table[i].representative;
5938 if (rep)
5940 if (state_table[rep].representative != rep)
5942 ERR("State %s (%#x) has invalid representative %s (%#x).\n",
5943 debug_d3dstate(i), i, debug_d3dstate(rep), rep);
5944 state_table[i].representative = 0;
5947 if (rep != i)
5949 if (state_table[i].apply)
5950 ERR("State %s (%#x) has both a handler and representative.\n", debug_d3dstate(i), i);
5952 else if (!state_table[i].apply)
5954 ERR("Self representing state %s (%#x) has no handler.\n", debug_d3dstate(i), i);
5960 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
5961 const struct wined3d_gl_info *gl_info, const struct wined3d_d3d_info *d3d_info,
5962 const struct wined3d_vertex_pipe_ops *vertex, const struct fragment_pipeline *fragment,
5963 const struct StateEntryTemplate *misc)
5965 unsigned int i, type, handlers;
5966 APPLYSTATEFUNC multistate_funcs[STATE_HIGHEST + 1][3];
5967 const struct StateEntryTemplate *cur;
5968 BOOL set[STATE_HIGHEST + 1];
5970 memset(multistate_funcs, 0, sizeof(multistate_funcs));
5972 for(i = 0; i < STATE_HIGHEST + 1; i++) {
5973 StateTable[i].representative = 0;
5974 StateTable[i].apply = state_undefined;
5977 for(type = 0; type < 3; type++) {
5978 /* This switch decides the order in which the states are applied */
5979 switch(type) {
5980 case 0: cur = misc; break;
5981 case 1: cur = fragment->states; break;
5982 case 2: cur = vertex->vp_states; break;
5983 default: cur = NULL; /* Stupid compiler */
5985 if(!cur) continue;
5987 /* GL extension filtering should not prevent multiple handlers being applied from different
5988 * pipeline parts
5990 memset(set, 0, sizeof(set));
5992 for(i = 0; cur[i].state; i++) {
5993 APPLYSTATEFUNC *funcs_array;
5995 /* Only use the first matching state with the available extension from one template.
5996 * e.g.
5997 * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func1}, XYZ_FANCY},
5998 * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func2}, 0 }
6000 * if GL_XYZ_fancy is supported, ignore the 2nd line
6002 if(set[cur[i].state]) continue;
6003 /* Skip state lines depending on unsupported extensions */
6004 if (!gl_info->supported[cur[i].extension]) continue;
6005 set[cur[i].state] = TRUE;
6006 /* In some cases having an extension means that nothing has to be
6007 * done for a state, e.g. if GL_ARB_texture_non_power_of_two is
6008 * supported, the texture coordinate fixup can be ignored. If the
6009 * apply function is used, mark the state set(done above) to prevent
6010 * applying later lines, but do not record anything in the state
6011 * table
6013 if (!cur[i].content.representative) continue;
6015 handlers = num_handlers(multistate_funcs[cur[i].state]);
6016 multistate_funcs[cur[i].state][handlers] = cur[i].content.apply;
6017 switch(handlers) {
6018 case 0:
6019 StateTable[cur[i].state].apply = cur[i].content.apply;
6020 break;
6021 case 1:
6022 StateTable[cur[i].state].apply = multistate_apply_2;
6023 dev_multistate_funcs[cur[i].state] = HeapAlloc(GetProcessHeap(),
6025 sizeof(**dev_multistate_funcs) * 2);
6026 if (!dev_multistate_funcs[cur[i].state]) {
6027 goto out_of_mem;
6030 dev_multistate_funcs[cur[i].state][0] = multistate_funcs[cur[i].state][0];
6031 dev_multistate_funcs[cur[i].state][1] = multistate_funcs[cur[i].state][1];
6032 break;
6033 case 2:
6034 StateTable[cur[i].state].apply = multistate_apply_3;
6035 funcs_array = HeapReAlloc(GetProcessHeap(),
6037 dev_multistate_funcs[cur[i].state],
6038 sizeof(**dev_multistate_funcs) * 3);
6039 if (!funcs_array) {
6040 goto out_of_mem;
6043 dev_multistate_funcs[cur[i].state] = funcs_array;
6044 dev_multistate_funcs[cur[i].state][2] = multistate_funcs[cur[i].state][2];
6045 break;
6046 default:
6047 ERR("Unexpected amount of state handlers for state %u: %u\n",
6048 cur[i].state, handlers + 1);
6051 if (StateTable[cur[i].state].representative
6052 && StateTable[cur[i].state].representative != cur[i].content.representative)
6054 FIXME("State %s (%#x) has different representatives in different pipeline parts.\n",
6055 debug_d3dstate(cur[i].state), cur[i].state);
6057 StateTable[cur[i].state].representative = cur[i].content.representative;
6061 prune_invalid_states(StateTable, gl_info, d3d_info);
6062 validate_state_table(StateTable);
6064 return WINED3D_OK;
6066 out_of_mem:
6067 for (i = 0; i <= STATE_HIGHEST; ++i) {
6068 HeapFree(GetProcessHeap(), 0, dev_multistate_funcs[i]);
6071 memset(dev_multistate_funcs, 0, (STATE_HIGHEST + 1)*sizeof(*dev_multistate_funcs));
6073 return E_OUTOFMEMORY;