odbc32: Use the ARRAY_SIZE() macro.
[wine.git] / dlls / wined3d / state.c
blob42c109da57bae75008124d1608a8742feaacbd8e
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);
40 ULONG CDECL wined3d_blend_state_incref(struct wined3d_blend_state *state)
42 ULONG refcount = InterlockedIncrement(&state->refcount);
44 TRACE("%p increasing refcount to %u.\n", state, refcount);
46 return refcount;
49 static void wined3d_blend_state_destroy_object(void *object)
51 heap_free(object);
54 ULONG CDECL wined3d_blend_state_decref(struct wined3d_blend_state *state)
56 ULONG refcount = InterlockedDecrement(&state->refcount);
57 struct wined3d_device *device = state->device;
59 TRACE("%p decreasing refcount to %u.\n", state, refcount);
61 if (!refcount)
63 state->parent_ops->wined3d_object_destroyed(state->parent);
64 wined3d_cs_destroy_object(device->cs, wined3d_blend_state_destroy_object, state);
67 return refcount;
70 void * CDECL wined3d_blend_state_get_parent(const struct wined3d_blend_state *state)
72 TRACE("state %p.\n", state);
74 return state->parent;
77 HRESULT CDECL wined3d_blend_state_create(struct wined3d_device *device,
78 const struct wined3d_blend_state_desc *desc, void *parent,
79 const struct wined3d_parent_ops *parent_ops, struct wined3d_blend_state **state)
81 struct wined3d_blend_state *object;
83 TRACE("device %p, desc %p, parent %p, parent_ops %p, state %p.\n",
84 device, desc, parent, parent_ops, state);
86 if (!(object = heap_alloc_zero(sizeof(*object))))
87 return E_OUTOFMEMORY;
89 object->refcount = 1;
90 object->desc = *desc;
91 object->parent = parent;
92 object->parent_ops = parent_ops;
93 object->device = device;
95 TRACE("Created blend state %p.\n", object);
96 *state = object;
98 return WINED3D_OK;
101 ULONG CDECL wined3d_rasterizer_state_incref(struct wined3d_rasterizer_state *state)
103 ULONG refcount = InterlockedIncrement(&state->refcount);
105 TRACE("%p increasing refcount to %u.\n", state, refcount);
107 return refcount;
110 static void wined3d_rasterizer_state_destroy_object(void *object)
112 heap_free(object);
115 ULONG CDECL wined3d_rasterizer_state_decref(struct wined3d_rasterizer_state *state)
117 ULONG refcount = InterlockedDecrement(&state->refcount);
118 struct wined3d_device *device = state->device;
120 TRACE("%p decreasing refcount to %u.\n", state, refcount);
122 if (!refcount)
124 state->parent_ops->wined3d_object_destroyed(state->parent);
125 wined3d_cs_destroy_object(device->cs, wined3d_rasterizer_state_destroy_object, state);
128 return refcount;
131 void * CDECL wined3d_rasterizer_state_get_parent(const struct wined3d_rasterizer_state *state)
133 TRACE("rasterizer_state %p.\n", state);
135 return state->parent;
138 HRESULT CDECL wined3d_rasterizer_state_create(struct wined3d_device *device,
139 const struct wined3d_rasterizer_state_desc *desc, void *parent,
140 const struct wined3d_parent_ops *parent_ops, struct wined3d_rasterizer_state **state)
142 struct wined3d_rasterizer_state *object;
144 TRACE("device %p, desc %p, parent %p, parent_ops %p, state %p.\n",
145 device, desc, parent, parent_ops, state);
147 if (!(object = heap_alloc_zero(sizeof(*object))))
148 return E_OUTOFMEMORY;
150 object->refcount = 1;
151 object->desc = *desc;
152 object->parent = parent;
153 object->parent_ops = parent_ops;
154 object->device = device;
156 TRACE("Created rasterizer state %p.\n", object);
157 *state = object;
159 return WINED3D_OK;
162 /* Context activation for state handler is done by the caller. */
164 static void state_undefined(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
166 ERR("Undefined state %s (%#x).\n", debug_d3dstate(state_id), state_id);
169 void state_nop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
171 TRACE("%s: nop in current pipe config.\n", debug_d3dstate(state_id));
174 static void state_fillmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
176 enum wined3d_fill_mode mode = state->render_states[WINED3D_RS_FILLMODE];
177 const struct wined3d_gl_info *gl_info = context->gl_info;
179 switch (mode)
181 case WINED3D_FILL_POINT:
182 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
183 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
184 break;
185 case WINED3D_FILL_WIREFRAME:
186 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
187 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
188 break;
189 case WINED3D_FILL_SOLID:
190 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
191 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
192 break;
193 default:
194 FIXME("Unrecognized fill mode %#x.\n", mode);
198 static void state_lighting(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
200 const struct wined3d_gl_info *gl_info = context->gl_info;
202 /* Lighting is not enabled if transformed vertices are drawn, but lighting
203 * does not affect the stream sources, so it is not grouped for
204 * performance reasons. This state reads the decoded vertex declaration,
205 * so if it is dirty don't do anything. The vertex declaration applying
206 * function calls this function for updating. */
207 if (isStateDirty(context, STATE_VDECL))
208 return;
210 if (state->render_states[WINED3D_RS_LIGHTING]
211 && !context->stream_info.position_transformed)
213 gl_info->gl_ops.gl.p_glEnable(GL_LIGHTING);
214 checkGLcall("glEnable GL_LIGHTING");
216 else
218 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
219 checkGLcall("glDisable GL_LIGHTING");
223 static void state_zenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
225 enum wined3d_depth_buffer_type zenable = state->render_states[WINED3D_RS_ZENABLE];
226 const struct wined3d_gl_info *gl_info = context->gl_info;
228 /* No z test without depth stencil buffers */
229 if (!state->fb->depth_stencil)
231 TRACE("No Z buffer - disabling depth test\n");
232 zenable = WINED3D_ZB_FALSE;
235 switch (zenable)
237 case WINED3D_ZB_FALSE:
238 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
239 checkGLcall("glDisable GL_DEPTH_TEST");
240 break;
241 case WINED3D_ZB_TRUE:
242 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
243 checkGLcall("glEnable GL_DEPTH_TEST");
244 break;
245 case WINED3D_ZB_USEW:
246 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
247 checkGLcall("glEnable GL_DEPTH_TEST");
248 FIXME("W buffer is not well handled\n");
249 break;
250 default:
251 FIXME("Unrecognized depth buffer type %#x.\n", zenable);
252 break;
255 if (context->last_was_rhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
256 context_apply_state(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
259 static void state_cullmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
261 const struct wined3d_gl_info *gl_info = context->gl_info;
263 /* glFrontFace() is set in context.c at context init and on an
264 * offscreen / onscreen rendering switch. */
265 switch (state->render_states[WINED3D_RS_CULLMODE])
267 case WINED3D_CULL_NONE:
268 gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
269 checkGLcall("glDisable GL_CULL_FACE");
270 break;
271 case WINED3D_CULL_FRONT:
272 gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
273 checkGLcall("glEnable GL_CULL_FACE");
274 gl_info->gl_ops.gl.p_glCullFace(GL_FRONT);
275 checkGLcall("glCullFace(GL_FRONT)");
276 break;
277 case WINED3D_CULL_BACK:
278 gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
279 checkGLcall("glEnable GL_CULL_FACE");
280 gl_info->gl_ops.gl.p_glCullFace(GL_BACK);
281 checkGLcall("glCullFace(GL_BACK)");
282 break;
283 default:
284 FIXME("Unrecognized cull mode %#x.\n",
285 state->render_states[WINED3D_RS_CULLMODE]);
289 void state_shademode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
291 const struct wined3d_gl_info *gl_info = context->gl_info;
293 switch (state->render_states[WINED3D_RS_SHADEMODE])
295 case WINED3D_SHADE_FLAT:
296 gl_info->gl_ops.gl.p_glShadeModel(GL_FLAT);
297 checkGLcall("glShadeModel(GL_FLAT)");
298 break;
299 case WINED3D_SHADE_GOURAUD:
300 /* WINED3D_SHADE_PHONG in practice is the same as WINED3D_SHADE_GOURAUD
301 * in D3D. */
302 case WINED3D_SHADE_PHONG:
303 gl_info->gl_ops.gl.p_glShadeModel(GL_SMOOTH);
304 checkGLcall("glShadeModel(GL_SMOOTH)");
305 break;
306 default:
307 FIXME("Unrecognized shade mode %#x.\n",
308 state->render_states[WINED3D_RS_SHADEMODE]);
312 static void state_ditherenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
314 const struct wined3d_gl_info *gl_info = context->gl_info;
316 if (state->render_states[WINED3D_RS_DITHERENABLE])
318 gl_info->gl_ops.gl.p_glEnable(GL_DITHER);
319 checkGLcall("glEnable GL_DITHER");
321 else
323 gl_info->gl_ops.gl.p_glDisable(GL_DITHER);
324 checkGLcall("glDisable GL_DITHER");
328 static void state_zwriteenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
330 const struct wined3d_gl_info *gl_info = context->gl_info;
332 if (state->render_states[WINED3D_RS_ZWRITEENABLE])
334 gl_info->gl_ops.gl.p_glDepthMask(1);
335 checkGLcall("glDepthMask(1)");
337 else
339 gl_info->gl_ops.gl.p_glDepthMask(0);
340 checkGLcall("glDepthMask(0)");
344 GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f)
346 switch (f)
348 case WINED3D_CMP_NEVER:
349 return GL_NEVER;
350 case WINED3D_CMP_LESS:
351 return GL_LESS;
352 case WINED3D_CMP_EQUAL:
353 return GL_EQUAL;
354 case WINED3D_CMP_LESSEQUAL:
355 return GL_LEQUAL;
356 case WINED3D_CMP_GREATER:
357 return GL_GREATER;
358 case WINED3D_CMP_NOTEQUAL:
359 return GL_NOTEQUAL;
360 case WINED3D_CMP_GREATEREQUAL:
361 return GL_GEQUAL;
362 case WINED3D_CMP_ALWAYS:
363 return GL_ALWAYS;
364 default:
365 if (!f)
366 WARN("Unrecognized compare function %#x.\n", f);
367 else
368 FIXME("Unrecognized compare function %#x.\n", f);
369 return GL_NONE;
373 static void state_zfunc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
375 GLenum depth_func = wined3d_gl_compare_func(state->render_states[WINED3D_RS_ZFUNC]);
376 const struct wined3d_gl_info *gl_info = context->gl_info;
378 if (!depth_func) return;
380 gl_info->gl_ops.gl.p_glDepthFunc(depth_func);
381 checkGLcall("glDepthFunc");
384 static void state_ambient(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
386 const struct wined3d_gl_info *gl_info = context->gl_info;
387 struct wined3d_color color;
389 wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_AMBIENT]);
390 TRACE("Setting ambient to %s.\n", debug_color(&color));
391 gl_info->gl_ops.gl.p_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &color.r);
392 checkGLcall("glLightModel for MODEL_AMBIENT");
395 static void state_blendop_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
397 WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
400 static GLenum gl_blend_op(const struct wined3d_gl_info *gl_info, enum wined3d_blend_op op)
402 switch (op)
404 case WINED3D_BLEND_OP_ADD:
405 return GL_FUNC_ADD;
406 case WINED3D_BLEND_OP_SUBTRACT:
407 return gl_info->supported[EXT_BLEND_SUBTRACT] ? GL_FUNC_SUBTRACT : GL_FUNC_ADD;
408 case WINED3D_BLEND_OP_REVSUBTRACT:
409 return gl_info->supported[EXT_BLEND_SUBTRACT] ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD;
410 case WINED3D_BLEND_OP_MIN:
411 return gl_info->supported[EXT_BLEND_MINMAX] ? GL_MIN : GL_FUNC_ADD;
412 case WINED3D_BLEND_OP_MAX:
413 return gl_info->supported[EXT_BLEND_MINMAX] ? GL_MAX : GL_FUNC_ADD;
414 default:
415 if (!op)
416 WARN("Unhandled blend op %#x.\n", op);
417 else
418 FIXME("Unhandled blend op %#x.\n", op);
419 return GL_FUNC_ADD;
423 static void state_blendop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
425 const struct wined3d_gl_info *gl_info = context->gl_info;
426 GLenum blend_equation_alpha = GL_FUNC_ADD_EXT;
427 GLenum blend_equation = GL_FUNC_ADD_EXT;
429 /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */
430 if (state->render_states[WINED3D_RS_BLENDOPALPHA]
431 && !gl_info->supported[EXT_BLEND_EQUATION_SEPARATE])
433 WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparate.\n");
434 return;
437 blend_equation = gl_blend_op(gl_info, state->render_states[WINED3D_RS_BLENDOP]);
438 blend_equation_alpha = gl_blend_op(gl_info, state->render_states[WINED3D_RS_BLENDOPALPHA]);
439 TRACE("blend_equation %#x, blend_equation_alpha %#x.\n", blend_equation, blend_equation_alpha);
441 if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
443 GL_EXTCALL(glBlendEquationSeparate(blend_equation, blend_equation_alpha));
444 checkGLcall("glBlendEquationSeparate");
446 else
448 GL_EXTCALL(glBlendEquation(blend_equation));
449 checkGLcall("glBlendEquation");
453 static GLenum gl_blend_factor(enum wined3d_blend factor, const struct wined3d_format *dst_format)
455 switch (factor)
457 case WINED3D_BLEND_ZERO:
458 return GL_ZERO;
459 case WINED3D_BLEND_ONE:
460 return GL_ONE;
461 case WINED3D_BLEND_SRCCOLOR:
462 return GL_SRC_COLOR;
463 case WINED3D_BLEND_INVSRCCOLOR:
464 return GL_ONE_MINUS_SRC_COLOR;
465 case WINED3D_BLEND_SRCALPHA:
466 return GL_SRC_ALPHA;
467 case WINED3D_BLEND_INVSRCALPHA:
468 return GL_ONE_MINUS_SRC_ALPHA;
469 case WINED3D_BLEND_DESTCOLOR:
470 return GL_DST_COLOR;
471 case WINED3D_BLEND_INVDESTCOLOR:
472 return GL_ONE_MINUS_DST_COLOR;
473 /* To compensate for the lack of format switching with backbuffer
474 * offscreen rendering, and with onscreen rendering, we modify the
475 * alpha test parameters for (INV)DESTALPHA if the render target
476 * doesn't support alpha blending. A nonexistent alpha channel
477 * returns 1.0, so WINED3D_BLEND_DESTALPHA becomes GL_ONE, and
478 * WINED3D_BLEND_INVDESTALPHA becomes GL_ZERO. */
479 case WINED3D_BLEND_DESTALPHA:
480 return dst_format->alpha_size ? GL_DST_ALPHA : GL_ONE;
481 case WINED3D_BLEND_INVDESTALPHA:
482 return dst_format->alpha_size ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO;
483 case WINED3D_BLEND_SRCALPHASAT:
484 return GL_SRC_ALPHA_SATURATE;
485 case WINED3D_BLEND_BLENDFACTOR:
486 return GL_CONSTANT_COLOR_EXT;
487 case WINED3D_BLEND_INVBLENDFACTOR:
488 return GL_ONE_MINUS_CONSTANT_COLOR_EXT;
489 case WINED3D_BLEND_SRC1COLOR:
490 return GL_SRC1_COLOR;
491 case WINED3D_BLEND_INVSRC1COLOR:
492 return GL_ONE_MINUS_SRC1_COLOR;
493 case WINED3D_BLEND_SRC1ALPHA:
494 return GL_SRC1_ALPHA;
495 case WINED3D_BLEND_INVSRC1ALPHA:
496 return GL_ONE_MINUS_SRC1_ALPHA;
497 default:
498 if (!factor)
499 WARN("Unhandled blend factor %#x.\n", factor);
500 else
501 FIXME("Unhandled blend factor %#x.\n", factor);
502 return GL_NONE;
506 static void gl_blend_from_d3d(GLenum *src_blend, GLenum *dst_blend,
507 enum wined3d_blend d3d_src_blend, enum wined3d_blend d3d_dst_blend,
508 const struct wined3d_format *rt_format)
510 /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy
511 * source blending values which are still valid up to d3d9. They should
512 * not occur as dest blend values. */
513 if (d3d_src_blend == WINED3D_BLEND_BOTHSRCALPHA)
515 *src_blend = GL_SRC_ALPHA;
516 *dst_blend = GL_ONE_MINUS_SRC_ALPHA;
518 else if (d3d_src_blend == WINED3D_BLEND_BOTHINVSRCALPHA)
520 *src_blend = GL_ONE_MINUS_SRC_ALPHA;
521 *dst_blend = GL_SRC_ALPHA;
523 else
525 *src_blend = gl_blend_factor(d3d_src_blend, rt_format);
526 *dst_blend = gl_blend_factor(d3d_dst_blend, rt_format);
530 static void state_blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
532 const struct wined3d_gl_info *gl_info = context->gl_info;
533 const struct wined3d_format *rt_format;
534 GLenum src_blend, dst_blend;
535 unsigned int rt_fmt_flags;
536 BOOL enable_blend;
538 enable_blend = state->fb->render_targets[0] && state->render_states[WINED3D_RS_ALPHABLENDENABLE];
539 if (enable_blend)
541 rt_format = state->fb->render_targets[0]->format;
542 rt_fmt_flags = state->fb->render_targets[0]->format_flags;
544 /* Disable blending in all cases even without pixelshaders.
545 * With blending on we could face a big performance penalty.
546 * The d3d9 visual test confirms the behavior. */
547 if (context->render_offscreen && !(rt_fmt_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
548 enable_blend = FALSE;
551 if (!enable_blend)
553 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
554 checkGLcall("glDisable(GL_BLEND)");
555 return;
558 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
559 checkGLcall("glEnable(GL_BLEND)");
561 gl_blend_from_d3d(&src_blend, &dst_blend,
562 state->render_states[WINED3D_RS_SRCBLEND],
563 state->render_states[WINED3D_RS_DESTBLEND], rt_format);
565 /* Re-apply BLENDOP(ALPHA) because of a possible SEPARATEALPHABLENDENABLE change */
566 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_BLENDOP)))
567 state_blendop(context, state, STATE_RENDER(WINED3D_RS_BLENDOPALPHA));
569 if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
571 GLenum src_blend_alpha, dst_blend_alpha;
573 /* Separate alpha blending requires GL_EXT_blend_function_separate, so make sure it is around */
574 if (!context->gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
576 WARN("Unsupported in local OpenGL implementation: glBlendFuncSeparate.\n");
577 return;
580 gl_blend_from_d3d(&src_blend_alpha, &dst_blend_alpha,
581 state->render_states[WINED3D_RS_SRCBLENDALPHA],
582 state->render_states[WINED3D_RS_DESTBLENDALPHA], rt_format);
584 GL_EXTCALL(glBlendFuncSeparate(src_blend, dst_blend, src_blend_alpha, dst_blend_alpha));
585 checkGLcall("glBlendFuncSeparate");
587 else
589 TRACE("glBlendFunc src=%x, dst=%x.\n", src_blend, dst_blend);
590 gl_info->gl_ops.gl.p_glBlendFunc(src_blend, dst_blend);
591 checkGLcall("glBlendFunc");
594 /* Colorkey fixup for stage 0 alphaop depends on
595 * WINED3D_RS_ALPHABLENDENABLE state, so it may need updating. */
596 if (state->render_states[WINED3D_RS_COLORKEYENABLE])
597 context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
600 static void state_blend_factor_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
602 WARN("Unsupported in local OpenGL implementation: glBlendColor.\n");
605 static void state_blend_factor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
607 const struct wined3d_color *factor = &state->blend_factor;
608 const struct wined3d_gl_info *gl_info = context->gl_info;
610 TRACE("Setting blend factor to %s.\n", debug_color(factor));
612 GL_EXTCALL(glBlendColor(factor->r, factor->g, factor->b, factor->a));
613 checkGLcall("glBlendColor");
616 static void state_blend_object(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
618 const struct wined3d_gl_info *gl_info = context->gl_info;
619 BOOL alpha_to_coverage = FALSE;
621 if (!gl_info->supported[ARB_MULTISAMPLE])
622 return;
624 if (state->blend_state)
626 struct wined3d_blend_state_desc *desc = &state->blend_state->desc;
627 alpha_to_coverage = desc->alpha_to_coverage;
630 if (alpha_to_coverage)
631 gl_info->gl_ops.gl.p_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
632 else
633 gl_info->gl_ops.gl.p_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
635 checkGLcall("blend state");
638 void state_alpha_test(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
640 const struct wined3d_gl_info *gl_info = context->gl_info;
641 int glParm = 0;
642 float ref;
643 BOOL enable_ckey = FALSE;
645 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
647 /* Find out if the texture on the first stage has a ckey set. The alpha
648 * state func reads the texture settings, even though alpha and texture
649 * are not grouped together. This is to avoid making a huge alpha +
650 * texture + texture stage + ckey block due to the hardly used
651 * WINED3D_RS_COLORKEYENABLE state(which is d3d <= 3 only). The texture
652 * function will call alpha in case it finds some texture + colorkeyenable
653 * combination which needs extra care. */
654 if (state->textures[0] && (state->textures[0]->async.color_key_flags & WINED3D_CKEY_SRC_BLT))
655 enable_ckey = TRUE;
657 if (enable_ckey || context->last_was_ckey)
658 context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
659 context->last_was_ckey = enable_ckey;
661 if (state->render_states[WINED3D_RS_ALPHATESTENABLE]
662 || (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey))
664 gl_info->gl_ops.gl.p_glEnable(GL_ALPHA_TEST);
665 checkGLcall("glEnable GL_ALPHA_TEST");
667 else
669 gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
670 checkGLcall("glDisable GL_ALPHA_TEST");
671 /* Alpha test is disabled, don't bother setting the params - it will happen on the next
672 * enable call
674 return;
677 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey)
679 glParm = GL_NOTEQUAL;
680 ref = 0.0f;
682 else
684 ref = ((float)state->render_states[WINED3D_RS_ALPHAREF]) / 255.0f;
685 glParm = wined3d_gl_compare_func(state->render_states[WINED3D_RS_ALPHAFUNC]);
687 if (glParm)
689 gl_info->gl_ops.gl.p_glAlphaFunc(glParm, ref);
690 checkGLcall("glAlphaFunc");
694 void state_clipping(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
696 unsigned int enable_mask;
698 if (use_vs(state) && !context->d3d_info->vs_clipping)
700 static BOOL warned;
702 /* The OpenGL spec says that clipping planes are disabled when using
703 * shaders. Direct3D planes aren't, so that is an issue. The MacOS ATI
704 * driver keeps clipping planes activated with shaders in some
705 * conditions I got sick of tracking down. The shader state handler
706 * disables all clip planes because of that - don't do anything here
707 * and keep them disabled. */
708 if (state->render_states[WINED3D_RS_CLIPPLANEENABLE] && !warned++)
709 FIXME("Clipping not supported with vertex shaders.\n");
710 return;
713 /* glEnable(GL_CLIP_PLANEx) doesn't apply to (ARB backend) vertex shaders.
714 * The enabled / disabled planes are hardcoded into the shader. Update the
715 * shader to update the enabled clipplanes. In case of fixed function, we
716 * need to update the clipping field from ffp_vertex_settings. */
717 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
719 /* If enabling / disabling all
720 * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
722 enable_mask = state->render_states[WINED3D_RS_CLIPPING] ?
723 state->render_states[WINED3D_RS_CLIPPLANEENABLE] : 0;
724 context_enable_clip_distances(context, enable_mask);
727 static void state_specularenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
729 const struct wined3d_gl_info *gl_info = context->gl_info;
730 /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
731 * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
732 * specular color. This is wrong:
733 * Separate specular color means the specular colour is maintained separately, whereas
734 * single color means it is merged in. However in both cases they are being used to
735 * some extent.
736 * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
737 * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
738 * running 1.4 yet!
741 * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
742 * Instead, we need to setup the FinalCombiner properly.
744 * The default setup for the FinalCombiner is:
746 * <variable> <input> <mapping> <usage>
747 * GL_VARIABLE_A_NV GL_FOG, GL_UNSIGNED_IDENTITY_NV GL_ALPHA
748 * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV GL_UNSIGNED_IDENTITY_NV GL_RGB
749 * GL_VARIABLE_C_NV GL_FOG GL_UNSIGNED_IDENTITY_NV GL_RGB
750 * GL_VARIABLE_D_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
751 * GL_VARIABLE_E_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
752 * GL_VARIABLE_F_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
753 * GL_VARIABLE_G_NV GL_SPARE0_NV GL_UNSIGNED_IDENTITY_NV GL_ALPHA
755 * That's pretty much fine as it is, except for variable B, which needs to take
756 * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
757 * whether WINED3D_RS_SPECULARENABLE is enabled or not.
760 TRACE("Setting specular enable state and materials\n");
761 if (state->render_states[WINED3D_RS_SPECULARENABLE])
763 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
764 checkGLcall("glMaterialfv");
766 if (state->material.power > gl_info->limits.shininess)
768 /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0
769 * and 128.0, although in d3d neither -1 nor 129 produce an error. GL_NV_max_light_exponent
770 * allows bigger values. If the extension is supported, gl_info->limits.shininess contains the
771 * value reported by the extension, otherwise 128. For values > gl_info->limits.shininess clamp
772 * them, it should be safe to do so without major visual distortions.
774 WARN("Material power = %.8e, limit %.8e\n", state->material.power, gl_info->limits.shininess);
775 gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, gl_info->limits.shininess);
777 else
779 gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, state->material.power);
781 checkGLcall("glMaterialf(GL_SHININESS)");
783 if (gl_info->supported[EXT_SECONDARY_COLOR])
784 gl_info->gl_ops.gl.p_glEnable(GL_COLOR_SUM_EXT);
785 else
786 TRACE("Specular colors cannot be enabled in this version of opengl\n");
787 checkGLcall("glEnable(GL_COLOR_SUM)");
789 if (gl_info->supported[NV_REGISTER_COMBINERS])
791 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
792 checkGLcall("glFinalCombinerInputNV()");
794 } else {
795 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
797 /* for the case of enabled lighting: */
798 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
799 checkGLcall("glMaterialfv");
801 /* for the case of disabled lighting: */
802 if (gl_info->supported[EXT_SECONDARY_COLOR])
803 gl_info->gl_ops.gl.p_glDisable(GL_COLOR_SUM_EXT);
804 else
805 TRACE("Specular colors cannot be disabled in this version of opengl\n");
806 checkGLcall("glDisable(GL_COLOR_SUM)");
808 if (gl_info->supported[NV_REGISTER_COMBINERS])
810 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
811 checkGLcall("glFinalCombinerInputNV()");
815 TRACE("diffuse %s\n", debug_color(&state->material.diffuse));
816 TRACE("ambient %s\n", debug_color(&state->material.ambient));
817 TRACE("specular %s\n", debug_color(&state->material.specular));
818 TRACE("emissive %s\n", debug_color(&state->material.emissive));
820 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
821 checkGLcall("glMaterialfv(GL_AMBIENT)");
822 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
823 checkGLcall("glMaterialfv(GL_DIFFUSE)");
824 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
825 checkGLcall("glMaterialfv(GL_EMISSION)");
828 static void state_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
830 const struct wined3d_gl_info *gl_info = context->gl_info;
831 struct wined3d_color color;
832 unsigned int i;
834 /* Note the texture color applies to all textures whereas
835 * GL_TEXTURE_ENV_COLOR applies to active only. */
836 wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_TEXTUREFACTOR]);
838 /* And now the default texture color as well */
839 for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
841 /* Note the WINED3D_RS value applies to all textures, but GL has one
842 * per texture, so apply it now ready to be used! */
843 context_active_texture(context, gl_info, i);
845 gl_info->gl_ops.gl.p_glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &color.r);
846 checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
850 static void renderstate_stencil_twosided(struct wined3d_context *context, GLint face,
851 GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass)
853 const struct wined3d_gl_info *gl_info = context->gl_info;
855 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
856 checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
857 GL_EXTCALL(glActiveStencilFaceEXT(face));
858 checkGLcall("glActiveStencilFaceEXT(...)");
859 gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
860 checkGLcall("glStencilFunc(...)");
861 gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
862 checkGLcall("glStencilOp(...)");
865 static GLenum gl_stencil_op(enum wined3d_stencil_op op)
867 switch (op)
869 case WINED3D_STENCIL_OP_KEEP:
870 return GL_KEEP;
871 case WINED3D_STENCIL_OP_ZERO:
872 return GL_ZERO;
873 case WINED3D_STENCIL_OP_REPLACE:
874 return GL_REPLACE;
875 case WINED3D_STENCIL_OP_INCR_SAT:
876 return GL_INCR;
877 case WINED3D_STENCIL_OP_DECR_SAT:
878 return GL_DECR;
879 case WINED3D_STENCIL_OP_INVERT:
880 return GL_INVERT;
881 case WINED3D_STENCIL_OP_INCR:
882 return GL_INCR_WRAP;
883 case WINED3D_STENCIL_OP_DECR:
884 return GL_DECR_WRAP;
885 default:
886 if (!op)
887 WARN("Unrecognized stencil op %#x.\n", op);
888 else
889 FIXME("Unrecognized stencil op %#x.\n", op);
890 return GL_KEEP;
894 static void state_stencil(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
896 const struct wined3d_gl_info *gl_info = context->gl_info;
897 DWORD onesided_enable;
898 DWORD twosided_enable;
899 GLint func;
900 GLint func_back;
901 GLint ref;
902 GLuint mask;
903 GLint stencilFail;
904 GLint stencilFail_back;
905 GLint stencilPass;
906 GLint stencilPass_back;
907 GLint depthFail;
908 GLint depthFail_back;
910 /* No stencil test without a stencil buffer. */
911 if (!state->fb->depth_stencil)
913 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
914 checkGLcall("glDisable GL_STENCIL_TEST");
915 return;
918 onesided_enable = state->render_states[WINED3D_RS_STENCILENABLE];
919 twosided_enable = state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE];
920 if (!(func = wined3d_gl_compare_func(state->render_states[WINED3D_RS_STENCILFUNC])))
921 func = GL_ALWAYS;
922 if (!(func_back = wined3d_gl_compare_func(state->render_states[WINED3D_RS_BACK_STENCILFUNC])))
923 func_back = GL_ALWAYS;
924 ref = state->render_states[WINED3D_RS_STENCILREF];
925 mask = state->render_states[WINED3D_RS_STENCILMASK];
926 stencilFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILFAIL]);
927 depthFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILZFAIL]);
928 stencilPass = gl_stencil_op(state->render_states[WINED3D_RS_STENCILPASS]);
929 stencilFail_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILFAIL]);
930 depthFail_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILZFAIL]);
931 stencilPass_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILPASS]);
933 TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
934 "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
935 "GL_BACK: func: %x, fail %x, zfail %x, zpass %x)\n",
936 onesided_enable, twosided_enable, ref, mask,
937 func, stencilFail, depthFail, stencilPass,
938 func_back, stencilFail_back, depthFail_back, stencilPass_back);
940 if (twosided_enable && onesided_enable)
942 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
943 checkGLcall("glEnable GL_STENCIL_TEST");
945 if (gl_info->supported[WINED3D_GL_VERSION_2_0])
947 GL_EXTCALL(glStencilFuncSeparate(GL_FRONT, func, ref, mask));
948 GL_EXTCALL(glStencilOpSeparate(GL_FRONT, stencilFail, depthFail, stencilPass));
949 GL_EXTCALL(glStencilFuncSeparate(GL_BACK, func_back, ref, mask));
950 GL_EXTCALL(glStencilOpSeparate(GL_BACK, stencilFail_back, depthFail_back, stencilPass_back));
951 checkGLcall("setting two sided stencil state");
953 else if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
955 /* Apply back first, then front. This function calls glActiveStencilFaceEXT,
956 * which has an effect on the code below too. If we apply the front face
957 * afterwards, we are sure that the active stencil face is set to front,
958 * and other stencil functions which do not use two sided stencil do not have
959 * to set it back
961 renderstate_stencil_twosided(context, GL_BACK,
962 func_back, ref, mask, stencilFail_back, depthFail_back, stencilPass_back);
963 renderstate_stencil_twosided(context, GL_FRONT,
964 func, ref, mask, stencilFail, depthFail, stencilPass);
966 else if (gl_info->supported[ATI_SEPARATE_STENCIL])
968 GL_EXTCALL(glStencilFuncSeparateATI(func, func_back, ref, mask));
969 checkGLcall("glStencilFuncSeparateATI(...)");
970 GL_EXTCALL(glStencilOpSeparateATI(GL_FRONT, stencilFail, depthFail, stencilPass));
971 checkGLcall("glStencilOpSeparateATI(GL_FRONT, ...)");
972 GL_EXTCALL(glStencilOpSeparateATI(GL_BACK, stencilFail_back, depthFail_back, stencilPass_back));
973 checkGLcall("glStencilOpSeparateATI(GL_BACK, ...)");
975 else
977 FIXME("Separate (two sided) stencil not supported on this version of OpenGL. Caps weren't honored?\n");
980 else if(onesided_enable)
982 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
984 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
985 checkGLcall("glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
988 /* This code disables the ATI extension as well, since the standard stencil functions are equal
989 * to calling the ATI functions with GL_FRONT_AND_BACK as face parameter
991 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
992 checkGLcall("glEnable GL_STENCIL_TEST");
993 gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
994 checkGLcall("glStencilFunc(...)");
995 gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
996 checkGLcall("glStencilOp(...)");
998 else
1000 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
1001 checkGLcall("glDisable GL_STENCIL_TEST");
1005 static void state_stencilwrite2s_ext(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1007 DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
1008 const struct wined3d_gl_info *gl_info = context->gl_info;
1010 GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
1011 checkGLcall("glActiveStencilFaceEXT(GL_BACK)");
1012 gl_info->gl_ops.gl.p_glStencilMask(mask);
1013 checkGLcall("glStencilMask");
1014 GL_EXTCALL(glActiveStencilFaceEXT(GL_FRONT));
1015 checkGLcall("glActiveStencilFaceEXT(GL_FRONT)");
1016 gl_info->gl_ops.gl.p_glStencilMask(mask);
1019 static void state_stencilwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1021 DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
1022 const struct wined3d_gl_info *gl_info = context->gl_info;
1024 gl_info->gl_ops.gl.p_glStencilMask(mask);
1025 checkGLcall("glStencilMask");
1028 static void state_fog_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1030 const struct wined3d_gl_info *gl_info = context->gl_info;
1032 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
1034 if (!state->render_states[WINED3D_RS_FOGENABLE])
1035 return;
1037 /* Table fog on: Never use fog coords, and use per-fragment fog */
1038 if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
1040 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
1041 if (context->fog_coord)
1043 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1044 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1045 context->fog_coord = FALSE;
1048 /* Range fog is only used with per-vertex fog in d3d */
1049 if (gl_info->supported[NV_FOG_DISTANCE])
1051 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
1052 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
1054 return;
1057 /* Otherwise use per-vertex fog in any case */
1058 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_FASTEST);
1060 if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || context->last_was_rhw)
1062 /* No fog at all, or transformed vertices: Use fog coord */
1063 if (!context->fog_coord)
1065 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
1066 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)");
1067 context->fog_coord = TRUE;
1070 else
1072 /* Otherwise, use the fragment depth */
1073 if (context->fog_coord)
1075 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1076 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1077 context->fog_coord = FALSE;
1080 if (state->render_states[WINED3D_RS_RANGEFOGENABLE])
1082 if (gl_info->supported[NV_FOG_DISTANCE])
1084 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
1085 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)");
1087 else
1089 WARN("Range fog enabled, but not supported by this GL implementation.\n");
1092 else if (gl_info->supported[NV_FOG_DISTANCE])
1094 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
1095 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
1100 void state_fogstartend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1102 const struct wined3d_gl_info *gl_info = context->gl_info;
1103 float fogstart, fogend;
1105 get_fog_start_end(context, state, &fogstart, &fogend);
1107 gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, fogstart);
1108 checkGLcall("glFogf(GL_FOG_START, fogstart)");
1109 TRACE("Fog Start == %f\n", fogstart);
1111 gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, fogend);
1112 checkGLcall("glFogf(GL_FOG_END, fogend)");
1113 TRACE("Fog End == %f\n", fogend);
1116 void state_fog_fragpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1118 const struct wined3d_gl_info *gl_info = context->gl_info;
1119 enum fogsource new_source;
1120 DWORD fogstart = state->render_states[WINED3D_RS_FOGSTART];
1121 DWORD fogend = state->render_states[WINED3D_RS_FOGEND];
1123 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
1125 if (!state->render_states[WINED3D_RS_FOGENABLE])
1127 /* No fog? Disable it, and we're done :-) */
1128 glDisableWINE(GL_FOG);
1129 checkGLcall("glDisable GL_FOG");
1130 return;
1133 /* Fog Rules:
1135 * With fixed function vertex processing, Direct3D knows 2 different fog input sources.
1136 * It can use the Z value of the vertex, or the alpha component of the specular color.
1137 * This depends on the fog vertex, fog table and the vertex declaration. If the Z value
1138 * is used, fogstart, fogend and the equation type are used, otherwise linear fog with
1139 * start = 255, end = 0 is used. Obviously the msdn is not very clear on that.
1141 * FOGTABLEMODE != NONE:
1142 * The Z value is used, with the equation specified, no matter what vertex type.
1144 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, untransformed:
1145 * Per vertex fog is calculated using the specified fog equation and the parameters
1147 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, transformed, OR
1148 * FOGTABLEMODE == NONE, FOGVERTEXMODE == NONE, untransformed:
1149 * Linear fog with start = 255.0, end = 0.0, input comes from the specular color
1152 * Rules for vertex fog with shaders:
1154 * When mixing fixed function functionality with the programmable pipeline, D3D expects
1155 * the fog computation to happen during transformation while openGL expects it to happen
1156 * during rasterization. Also, prior to pixel shader 3.0 D3D handles fog blending after
1157 * the pixel shader while openGL always expects the pixel shader to handle the blending.
1158 * To solve this problem, WineD3D does:
1159 * 1) implement a linear fog equation and fog blending at the end of every pre 3.0 pixel
1160 * shader,
1161 * and 2) disables the fog computation (in either the fixed function or programmable
1162 * rasterizer) if using a vertex program.
1164 * D3D shaders can provide an explicit fog coordinate. This fog coordinate is used with
1165 * D3DRS_FOGTABLEMODE==D3DFOG_NONE. The FOGVERTEXMODE is ignored, d3d always uses linear
1166 * fog with start=1.0 and end=0.0 in this case. This is similar to fog coordinates in
1167 * the specular color, a vertex shader counts as pretransformed geometry in this case.
1168 * There are some GL differences between specular fog coords and vertex shaders though.
1170 * With table fog the vertex shader fog coordinate is ignored.
1172 * If a fogtablemode and a fogvertexmode are specified, table fog is applied (with or
1173 * without shaders).
1176 /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
1177 * the system will apply only pixel(=table) fog effects."
1179 if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
1181 if (use_vs(state))
1183 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1184 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1185 new_source = FOGSOURCE_VS;
1187 else
1189 switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
1191 /* If processed vertices are used, fall through to the NONE case */
1192 case WINED3D_FOG_EXP:
1193 if (!context->last_was_rhw)
1195 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1196 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1197 new_source = FOGSOURCE_FFP;
1198 break;
1200 /* drop through */
1202 case WINED3D_FOG_EXP2:
1203 if (!context->last_was_rhw)
1205 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1206 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1207 new_source = FOGSOURCE_FFP;
1208 break;
1210 /* drop through */
1212 case WINED3D_FOG_LINEAR:
1213 if (!context->last_was_rhw)
1215 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1216 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1217 new_source = FOGSOURCE_FFP;
1218 break;
1220 /* drop through */
1222 case WINED3D_FOG_NONE:
1223 /* Both are none? According to msdn the alpha channel of
1224 * the specular colour contains a fog factor. Set it in
1225 * draw_primitive_immediate_mode(). Same happens with
1226 * vertex fog on transformed vertices. */
1227 new_source = FOGSOURCE_COORD;
1228 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1229 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1230 break;
1232 default:
1233 FIXME("Unexpected WINED3D_RS_FOGVERTEXMODE %#x.\n",
1234 state->render_states[WINED3D_RS_FOGVERTEXMODE]);
1235 new_source = FOGSOURCE_FFP; /* Make the compiler happy */
1238 } else {
1239 new_source = FOGSOURCE_FFP;
1241 switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
1243 case WINED3D_FOG_EXP:
1244 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1245 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1246 break;
1248 case WINED3D_FOG_EXP2:
1249 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1250 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1251 break;
1253 case WINED3D_FOG_LINEAR:
1254 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1255 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1256 break;
1258 case WINED3D_FOG_NONE: /* Won't happen */
1259 default:
1260 FIXME("Unexpected WINED3D_RS_FOGTABLEMODE %#x.\n",
1261 state->render_states[WINED3D_RS_FOGTABLEMODE]);
1265 glEnableWINE(GL_FOG);
1266 checkGLcall("glEnable GL_FOG");
1267 if (new_source != context->fog_source || fogstart == fogend)
1269 context->fog_source = new_source;
1270 state_fogstartend(context, state, STATE_RENDER(WINED3D_RS_FOGSTART));
1274 void state_fogcolor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1276 const struct wined3d_gl_info *gl_info = context->gl_info;
1277 struct wined3d_color color;
1279 wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_FOGCOLOR]);
1280 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, &color.r);
1281 checkGLcall("glFog GL_FOG_COLOR");
1284 void state_fogdensity(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1286 const struct wined3d_gl_info *gl_info = context->gl_info;
1287 union {
1288 DWORD d;
1289 float f;
1290 } tmpvalue;
1292 tmpvalue.d = state->render_states[WINED3D_RS_FOGDENSITY];
1293 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
1294 checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
1297 static void state_colormat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1299 const struct wined3d_gl_info *gl_info = context->gl_info;
1300 GLenum Parm = 0;
1302 /* Depends on the decoded vertex declaration to read the existence of diffuse data.
1303 * The vertex declaration will call this function if the fixed function pipeline is used.
1306 if(isStateDirty(context, STATE_VDECL)) {
1307 return;
1310 context->num_untracked_materials = 0;
1311 if ((context->stream_info.use_map & (1u << WINED3D_FFP_DIFFUSE))
1312 && state->render_states[WINED3D_RS_COLORVERTEX])
1314 TRACE("diff %d, amb %d, emis %d, spec %d\n",
1315 state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE],
1316 state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE],
1317 state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE],
1318 state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]);
1320 if (state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1322 if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1323 Parm = GL_AMBIENT_AND_DIFFUSE;
1324 else
1325 Parm = GL_DIFFUSE;
1326 if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1328 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1329 context->num_untracked_materials++;
1331 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1333 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1334 context->num_untracked_materials++;
1337 else if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1339 Parm = GL_AMBIENT;
1340 if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1342 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1343 context->num_untracked_materials++;
1345 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1347 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1348 context->num_untracked_materials++;
1351 else if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1353 Parm = GL_EMISSION;
1354 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1356 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1357 context->num_untracked_materials++;
1360 else if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1362 Parm = GL_SPECULAR;
1366 /* Nothing changed, return. */
1367 if (Parm == context->tracking_parm) return;
1369 if (!Parm)
1371 gl_info->gl_ops.gl.p_glDisable(GL_COLOR_MATERIAL);
1372 checkGLcall("glDisable GL_COLOR_MATERIAL");
1374 else
1376 gl_info->gl_ops.gl.p_glColorMaterial(GL_FRONT_AND_BACK, Parm);
1377 checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
1378 gl_info->gl_ops.gl.p_glEnable(GL_COLOR_MATERIAL);
1379 checkGLcall("glEnable(GL_COLOR_MATERIAL)");
1382 /* Apparently calls to glMaterialfv are ignored for properties we're
1383 * tracking with glColorMaterial, so apply those here. */
1384 switch (context->tracking_parm)
1386 case GL_AMBIENT_AND_DIFFUSE:
1387 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
1388 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1389 checkGLcall("glMaterialfv");
1390 break;
1392 case GL_DIFFUSE:
1393 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1394 checkGLcall("glMaterialfv");
1395 break;
1397 case GL_AMBIENT:
1398 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
1399 checkGLcall("glMaterialfv");
1400 break;
1402 case GL_EMISSION:
1403 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
1404 checkGLcall("glMaterialfv");
1405 break;
1407 case GL_SPECULAR:
1408 /* Only change material color if specular is enabled, otherwise it is set to black */
1409 if (state->render_states[WINED3D_RS_SPECULARENABLE])
1411 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
1412 checkGLcall("glMaterialfv");
1414 else
1416 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
1417 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
1418 checkGLcall("glMaterialfv");
1420 break;
1423 context->tracking_parm = Parm;
1426 static void state_linepattern(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1428 const struct wined3d_gl_info *gl_info = context->gl_info;
1429 union
1431 DWORD d;
1432 struct wined3d_line_pattern lp;
1433 } tmppattern;
1434 tmppattern.d = state->render_states[WINED3D_RS_LINEPATTERN];
1436 TRACE("Line pattern: repeat %d bits %x.\n", tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1438 if (tmppattern.lp.repeat_factor)
1440 gl_info->gl_ops.gl.p_glLineStipple(tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1441 checkGLcall("glLineStipple(repeat, linepattern)");
1442 gl_info->gl_ops.gl.p_glEnable(GL_LINE_STIPPLE);
1443 checkGLcall("glEnable(GL_LINE_STIPPLE);");
1445 else
1447 gl_info->gl_ops.gl.p_glDisable(GL_LINE_STIPPLE);
1448 checkGLcall("glDisable(GL_LINE_STIPPLE);");
1452 static void state_linepattern_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1454 static unsigned int once;
1456 if (!once++)
1457 FIXME("Setting line patterns is not supported in OpenGL core contexts.\n");
1460 static void state_normalize(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1462 const struct wined3d_gl_info *gl_info = context->gl_info;
1464 if (isStateDirty(context, STATE_VDECL))
1465 return;
1467 /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor
1468 * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division
1469 * by zero and is not properly defined in opengl, so avoid it
1471 if (state->render_states[WINED3D_RS_NORMALIZENORMALS]
1472 && (context->stream_info.use_map & (1u << WINED3D_FFP_NORMAL)))
1474 gl_info->gl_ops.gl.p_glEnable(GL_NORMALIZE);
1475 checkGLcall("glEnable(GL_NORMALIZE);");
1477 else
1479 gl_info->gl_ops.gl.p_glDisable(GL_NORMALIZE);
1480 checkGLcall("glDisable(GL_NORMALIZE);");
1484 static void state_psizemin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1486 float min, max;
1488 get_pointsize_minmax(context, state, &min, &max);
1490 if (min != 1.0f)
1491 FIXME("WINED3D_RS_POINTSIZE_MIN value %.8e not supported on this OpenGL implementation.\n", min);
1492 if (max != 64.0f)
1493 FIXME("WINED3D_RS_POINTSIZE_MAX value %.8e not supported on this OpenGL implementation.\n", max);
1496 static void state_psizemin_ext(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1498 const struct wined3d_gl_info *gl_info = context->gl_info;
1499 float min, max;
1501 get_pointsize_minmax(context, state, &min, &max);
1503 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, min);
1504 checkGLcall("glPointParameterfEXT(...)");
1505 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, max);
1506 checkGLcall("glPointParameterfEXT(...)");
1509 static void state_psizemin_arb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1511 const struct wined3d_gl_info *gl_info = context->gl_info;
1512 float min, max;
1514 get_pointsize_minmax(context, state, &min, &max);
1516 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, min);
1517 checkGLcall("glPointParameterfARB(...)");
1518 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, max);
1519 checkGLcall("glPointParameterfARB(...)");
1522 static void state_pscale(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1524 const struct wined3d_gl_info *gl_info = context->gl_info;
1525 float att[3];
1526 float pointsize;
1528 get_pointsize(context, state, &pointsize, att);
1530 if (gl_info->supported[ARB_POINT_PARAMETERS])
1532 GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
1533 checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...)");
1535 else if (gl_info->supported[EXT_POINT_PARAMETERS])
1537 GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
1538 checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)");
1540 else if (state->render_states[WINED3D_RS_POINTSCALEENABLE])
1542 WARN("POINT_PARAMETERS not supported in this version of opengl\n");
1545 gl_info->gl_ops.gl.p_glPointSize(max(pointsize, FLT_MIN));
1546 checkGLcall("glPointSize(...);");
1549 static void state_debug_monitor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1551 WARN("token: %#x.\n", state->render_states[WINED3D_RS_DEBUGMONITORTOKEN]);
1554 static void state_colorwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1556 DWORD mask0 = state->render_states[WINED3D_RS_COLORWRITEENABLE];
1557 DWORD mask1 = state->render_states[WINED3D_RS_COLORWRITEENABLE1];
1558 DWORD mask2 = state->render_states[WINED3D_RS_COLORWRITEENABLE2];
1559 DWORD mask3 = state->render_states[WINED3D_RS_COLORWRITEENABLE3];
1560 const struct wined3d_gl_info *gl_info = context->gl_info;
1562 TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
1563 mask0 & WINED3DCOLORWRITEENABLE_RED ? 1 : 0,
1564 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? 1 : 0,
1565 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? 1 : 0,
1566 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1567 gl_info->gl_ops.gl.p_glColorMask(mask0 & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1568 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1569 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1570 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1571 checkGLcall("glColorMask(...)");
1573 if (!((mask1 == mask0 && mask2 == mask0 && mask3 == mask0)
1574 || (mask1 == 0xf && mask2 == 0xf && mask3 == 0xf)))
1576 FIXME("WINED3D_RS_COLORWRITEENABLE/1/2/3, %#x/%#x/%#x/%#x not yet implemented.\n",
1577 mask0, mask1, mask2, mask3);
1578 FIXME("Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n");
1582 static void set_color_mask(const struct wined3d_gl_info *gl_info, UINT index, DWORD mask)
1584 GL_EXTCALL(glColorMaski(index,
1585 mask & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1586 mask & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1587 mask & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1588 mask & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE));
1589 checkGLcall("glColorMaski");
1592 static void state_colorwrite0(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1594 set_color_mask(context->gl_info, 0, state->render_states[WINED3D_RS_COLORWRITEENABLE]);
1597 static void state_colorwrite1(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1599 set_color_mask(context->gl_info, 1, state->render_states[WINED3D_RS_COLORWRITEENABLE1]);
1602 static void state_colorwrite2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1604 set_color_mask(context->gl_info, 2, state->render_states[WINED3D_RS_COLORWRITEENABLE2]);
1607 static void state_colorwrite3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1609 set_color_mask(context->gl_info, 3, state->render_states[WINED3D_RS_COLORWRITEENABLE3]);
1612 static void state_localviewer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1614 const struct wined3d_gl_info *gl_info = context->gl_info;
1616 if (state->render_states[WINED3D_RS_LOCALVIEWER])
1618 gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1619 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1621 else
1623 gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1624 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
1628 static void state_lastpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1630 if (state->render_states[WINED3D_RS_LASTPIXEL])
1632 TRACE("Last Pixel Drawing Enabled\n");
1634 else
1636 static BOOL warned;
1637 if (!warned) {
1638 FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1639 warned = TRUE;
1640 } else {
1641 TRACE("Last Pixel Drawing Disabled, not handled yet\n");
1646 void state_pointsprite_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1648 static BOOL warned;
1650 /* TODO: NV_POINT_SPRITE */
1651 if (!warned && state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1653 /* A FIXME, not a WARN because point sprites should be software emulated if not supported by HW */
1654 FIXME("Point sprites not supported\n");
1655 warned = TRUE;
1659 void state_pointsprite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1661 const struct wined3d_gl_info *gl_info = context->gl_info;
1663 if (state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1665 gl_info->gl_ops.gl.p_glEnable(GL_POINT_SPRITE_ARB);
1666 checkGLcall("glEnable(GL_POINT_SPRITE_ARB)");
1668 else
1670 gl_info->gl_ops.gl.p_glDisable(GL_POINT_SPRITE_ARB);
1671 checkGLcall("glDisable(GL_POINT_SPRITE_ARB)");
1675 static void state_wrap(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1677 static unsigned int once;
1679 if ((state->render_states[WINED3D_RS_WRAP0]
1680 || state->render_states[WINED3D_RS_WRAP1]
1681 || state->render_states[WINED3D_RS_WRAP2]
1682 || state->render_states[WINED3D_RS_WRAP3]
1683 || state->render_states[WINED3D_RS_WRAP4]
1684 || state->render_states[WINED3D_RS_WRAP5]
1685 || state->render_states[WINED3D_RS_WRAP6]
1686 || state->render_states[WINED3D_RS_WRAP7]
1687 || state->render_states[WINED3D_RS_WRAP8]
1688 || state->render_states[WINED3D_RS_WRAP9]
1689 || state->render_states[WINED3D_RS_WRAP10]
1690 || state->render_states[WINED3D_RS_WRAP11]
1691 || state->render_states[WINED3D_RS_WRAP12]
1692 || state->render_states[WINED3D_RS_WRAP13]
1693 || state->render_states[WINED3D_RS_WRAP14]
1694 || state->render_states[WINED3D_RS_WRAP15])
1695 && !once++)
1696 FIXME("(WINED3D_RS_WRAP0) Texture wrapping not yet supported.\n");
1699 static void state_msaa_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1701 if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1702 WARN("Multisample antialiasing not supported by GL.\n");
1705 static void state_msaa(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1707 const struct wined3d_gl_info *gl_info = context->gl_info;
1709 if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1711 gl_info->gl_ops.gl.p_glEnable(GL_MULTISAMPLE_ARB);
1712 checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1714 else
1716 gl_info->gl_ops.gl.p_glDisable(GL_MULTISAMPLE_ARB);
1717 checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1721 static void state_line_antialias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1723 const struct wined3d_gl_info *gl_info = context->gl_info;
1725 if (state->render_states[WINED3D_RS_EDGEANTIALIAS]
1726 || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE])
1728 gl_info->gl_ops.gl.p_glEnable(GL_LINE_SMOOTH);
1729 checkGLcall("glEnable(GL_LINE_SMOOTH)");
1731 else
1733 gl_info->gl_ops.gl.p_glDisable(GL_LINE_SMOOTH);
1734 checkGLcall("glDisable(GL_LINE_SMOOTH)");
1738 static void state_scissor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1740 const struct wined3d_gl_info *gl_info = context->gl_info;
1742 if (state->render_states[WINED3D_RS_SCISSORTESTENABLE])
1744 gl_info->gl_ops.gl.p_glEnable(GL_SCISSOR_TEST);
1745 checkGLcall("glEnable(GL_SCISSOR_TEST)");
1747 else
1749 gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
1750 checkGLcall("glDisable(GL_SCISSOR_TEST)");
1754 /* The Direct3D depth bias is specified in normalized depth coordinates. In
1755 * OpenGL the bias is specified in units of "the smallest value that is
1756 * guaranteed to produce a resolvable offset for a given implementation". To
1757 * convert from D3D to GL we need to divide the D3D depth bias by that value.
1758 * We try to detect the value from GL with test draws. On most drivers (r300g,
1759 * 600g, Nvidia, i965 on Mesa) the value is 2^23 for fixed point depth buffers,
1760 * for r200 and i965 on OSX it is 2^24, for r500 on OSX it is 2^22. For floating
1761 * point buffers it is 2^22, 2^23 or 2^24 depending on the GPU. The value does
1762 * not depend on the depth buffer precision on any driver.
1764 * Two games that are picky regarding depth bias are Mass Effect 2 (flickering
1765 * decals) and F.E.A.R and F.E.A.R. 2 (semi-transparent guns).
1767 * Note that SLOPESCALEDEPTHBIAS is a scaling factor for the depth slope, and
1768 * doesn't need to be scaled to account for GL vs D3D differences. */
1769 static void state_depthbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1771 const struct wined3d_gl_info *gl_info = context->gl_info;
1773 if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]
1774 || state->render_states[WINED3D_RS_DEPTHBIAS])
1776 const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil;
1777 float factor, units, scale, clamp;
1779 union
1781 DWORD d;
1782 float f;
1783 } scale_bias, const_bias;
1785 clamp = state->rasterizer_state ? state->rasterizer_state->desc.depth_bias_clamp : 0.0f;
1786 scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS];
1787 const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS];
1789 if (context->d3d_info->wined3d_creation_flags & WINED3D_LEGACY_DEPTH_BIAS)
1791 factor = units = -(float)const_bias.d;
1793 else
1795 if (depth)
1797 scale = depth->format->depth_bias_scale;
1799 TRACE("Depth format %s, using depthbias scale of %.8e.\n",
1800 debug_d3dformat(depth->format->id), scale);
1802 else
1804 /* The context manager will reapply this state on a depth stencil change */
1805 TRACE("No depth stencil, using depth bias scale of 0.0.\n");
1806 scale = 0.0f;
1809 factor = scale_bias.f;
1810 units = const_bias.f * scale;
1813 gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
1814 if (gl_info->supported[ARB_POLYGON_OFFSET_CLAMP])
1816 gl_info->gl_ops.ext.p_glPolygonOffsetClamp(factor, units, clamp);
1818 else
1820 if (clamp != 0.0f)
1821 WARN("Ignoring depth bias clamp %.8e.\n", clamp);
1822 gl_info->gl_ops.gl.p_glPolygonOffset(factor, units);
1825 else
1827 gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL);
1830 checkGLcall("depth bias");
1833 static void state_zvisible(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1835 if (state->render_states[WINED3D_RS_ZVISIBLE])
1836 FIXME("WINED3D_RS_ZVISIBLE not implemented.\n");
1839 static void state_stippledalpha(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1841 if (state->render_states[WINED3D_RS_STIPPLEDALPHA])
1842 FIXME("Stippled Alpha not supported yet.\n");
1845 static void state_antialias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1847 if (state->render_states[WINED3D_RS_ANTIALIAS])
1848 FIXME("Antialias not supported yet.\n");
1851 static void state_multisampmask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1853 if (state->render_states[WINED3D_RS_MULTISAMPLEMASK] != 0xffffffff)
1854 FIXME("WINED3D_RS_MULTISAMPLEMASK %#x not yet implemented.\n",
1855 state->render_states[WINED3D_RS_MULTISAMPLEMASK]);
1858 static void state_patchedgestyle(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1860 if (state->render_states[WINED3D_RS_PATCHEDGESTYLE] != WINED3D_PATCH_EDGE_DISCRETE)
1861 FIXME("WINED3D_RS_PATCHEDGESTYLE %#x not yet implemented.\n",
1862 state->render_states[WINED3D_RS_PATCHEDGESTYLE]);
1865 static void state_patchsegments(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1867 union {
1868 DWORD d;
1869 float f;
1870 } tmpvalue;
1871 tmpvalue.f = 1.0f;
1873 if (state->render_states[WINED3D_RS_PATCHSEGMENTS] != tmpvalue.d)
1875 static BOOL displayed = FALSE;
1877 tmpvalue.d = state->render_states[WINED3D_RS_PATCHSEGMENTS];
1878 if(!displayed)
1879 FIXME("(WINED3D_RS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f);
1881 displayed = TRUE;
1885 static void state_positiondegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1887 if (state->render_states[WINED3D_RS_POSITIONDEGREE] != WINED3D_DEGREE_CUBIC)
1888 FIXME("WINED3D_RS_POSITIONDEGREE %#x not yet implemented.\n",
1889 state->render_states[WINED3D_RS_POSITIONDEGREE]);
1892 static void state_normaldegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1894 if (state->render_states[WINED3D_RS_NORMALDEGREE] != WINED3D_DEGREE_LINEAR)
1895 FIXME("WINED3D_RS_NORMALDEGREE %#x not yet implemented.\n",
1896 state->render_states[WINED3D_RS_NORMALDEGREE]);
1899 static void state_tessellation(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1901 if (state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION])
1902 FIXME("WINED3D_RS_ENABLEADAPTIVETESSELLATION %#x not yet implemented.\n",
1903 state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION]);
1906 static void state_nvdb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1908 union {
1909 DWORD d;
1910 float f;
1911 } zmin, zmax;
1913 const struct wined3d_gl_info *gl_info = context->gl_info;
1915 if (state->render_states[WINED3D_RS_ADAPTIVETESS_X] == WINED3DFMT_NVDB)
1917 zmin.d = state->render_states[WINED3D_RS_ADAPTIVETESS_Z];
1918 zmax.d = state->render_states[WINED3D_RS_ADAPTIVETESS_W];
1920 /* If zmin is larger than zmax INVALID_VALUE error is generated.
1921 * In d3d9 test is not performed in this case*/
1922 if (zmin.f <= zmax.f)
1924 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_BOUNDS_TEST_EXT);
1925 checkGLcall("glEnable(GL_DEPTH_BOUNDS_TEST_EXT)");
1926 GL_EXTCALL(glDepthBoundsEXT(zmin.f, zmax.f));
1927 checkGLcall("glDepthBoundsEXT(...)");
1929 else
1931 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1932 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1935 else
1937 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1938 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1941 state_tessellation(context, state, STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION));
1944 static void state_wrapu(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1946 if (state->render_states[WINED3D_RS_WRAPU])
1947 FIXME("Render state WINED3D_RS_WRAPU not implemented yet.\n");
1950 static void state_wrapv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1952 if (state->render_states[WINED3D_RS_WRAPV])
1953 FIXME("Render state WINED3D_RS_WRAPV not implemented yet.\n");
1956 static void state_monoenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1958 if (state->render_states[WINED3D_RS_MONOENABLE])
1959 FIXME("Render state WINED3D_RS_MONOENABLE not implemented yet.\n");
1962 static void state_rop2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1964 if (state->render_states[WINED3D_RS_ROP2])
1965 FIXME("Render state WINED3D_RS_ROP2 not implemented yet.\n");
1968 static void state_planemask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1970 if (state->render_states[WINED3D_RS_PLANEMASK])
1971 FIXME("Render state WINED3D_RS_PLANEMASK not implemented yet.\n");
1974 static void state_subpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1976 if (state->render_states[WINED3D_RS_SUBPIXEL])
1977 FIXME("Render state WINED3D_RS_SUBPIXEL not implemented yet.\n");
1980 static void state_subpixelx(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1982 if (state->render_states[WINED3D_RS_SUBPIXELX])
1983 FIXME("Render state WINED3D_RS_SUBPIXELX not implemented yet.\n");
1986 static void state_stippleenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1988 if (state->render_states[WINED3D_RS_STIPPLEENABLE])
1989 FIXME("Render state WINED3D_RS_STIPPLEENABLE not implemented yet.\n");
1992 static void state_mipmaplodbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1994 if (state->render_states[WINED3D_RS_MIPMAPLODBIAS])
1995 FIXME("Render state WINED3D_RS_MIPMAPLODBIAS not implemented yet.\n");
1998 static void state_anisotropy(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2000 if (state->render_states[WINED3D_RS_ANISOTROPY])
2001 FIXME("Render state WINED3D_RS_ANISOTROPY not implemented yet.\n");
2004 static void state_flushbatch(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2006 if (state->render_states[WINED3D_RS_FLUSHBATCH])
2007 FIXME("Render state WINED3D_RS_FLUSHBATCH not implemented yet.\n");
2010 static void state_translucentsi(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2012 if (state->render_states[WINED3D_RS_TRANSLUCENTSORTINDEPENDENT])
2013 FIXME("Render state WINED3D_RS_TRANSLUCENTSORTINDEPENDENT not implemented yet.\n");
2016 static void state_extents(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2018 if (state->render_states[WINED3D_RS_EXTENTS])
2019 FIXME("Render state WINED3D_RS_EXTENTS not implemented yet.\n");
2022 static void state_ckeyblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2024 if (state->render_states[WINED3D_RS_COLORKEYBLENDENABLE])
2025 FIXME("Render state WINED3D_RS_COLORKEYBLENDENABLE not implemented yet.\n");
2028 static void state_swvp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
2030 static int once;
2031 if (state->render_states[WINED3D_RS_SOFTWAREVERTEXPROCESSING])
2033 if (!once++)
2034 FIXME("Software vertex processing not implemented.\n");
2038 static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* operand) {
2039 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the
2040 * input should be used for all input components. The WINED3DTA_COMPLEMENT
2041 * flag specifies the complement of the input should be used. */
2042 BOOL from_alpha = is_alpha || arg & WINED3DTA_ALPHAREPLICATE;
2043 BOOL complement = arg & WINED3DTA_COMPLEMENT;
2045 /* Calculate the operand */
2046 if (complement) {
2047 if (from_alpha) *operand = GL_ONE_MINUS_SRC_ALPHA;
2048 else *operand = GL_ONE_MINUS_SRC_COLOR;
2049 } else {
2050 if (from_alpha) *operand = GL_SRC_ALPHA;
2051 else *operand = GL_SRC_COLOR;
2054 /* Calculate the source */
2055 switch (arg & WINED3DTA_SELECTMASK) {
2056 case WINED3DTA_CURRENT: *source = GL_PREVIOUS_EXT; break;
2057 case WINED3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT; break;
2058 case WINED3DTA_TEXTURE: *source = GL_TEXTURE; break;
2059 case WINED3DTA_TFACTOR: *source = GL_CONSTANT_EXT; break;
2060 case WINED3DTA_SPECULAR:
2062 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
2063 * 'Secondary color' and isn't supported until base GL supports it
2064 * There is no concept of temp registers as far as I can tell
2066 FIXME("Unhandled texture arg WINED3DTA_SPECULAR\n");
2067 *source = GL_TEXTURE;
2068 break;
2069 default:
2070 FIXME("Unrecognized texture arg %#x\n", arg);
2071 *source = GL_TEXTURE;
2072 break;
2076 /* Setup the texture operations texture stage states */
2077 static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
2078 BOOL isAlpha, int Stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3)
2080 GLenum src1, src2, src3;
2081 GLenum opr1, opr2, opr3;
2082 GLenum comb_target;
2083 GLenum src0_target, src1_target, src2_target;
2084 GLenum opr0_target, opr1_target, opr2_target;
2085 GLenum scal_target;
2086 GLenum opr=0, invopr, src3_target, opr3_target;
2087 BOOL Handled = FALSE;
2089 TRACE("Alpha?(%d), Stage:%d Op(%s), a1(%d), a2(%d), a3(%d)\n", isAlpha, Stage, debug_d3dtop(op), arg1, arg2, arg3);
2091 /* Operations usually involve two args, src0 and src1 and are operations
2092 * of the form (a1 <operation> a2). However, some of the more complex
2093 * operations take 3 parameters. Instead of the (sensible) addition of a3,
2094 * Microsoft added in a third parameter called a0. Therefore these are
2095 * operations of the form a0 <operation> a1 <operation> a2. I.e., the new
2096 * parameter goes to the front.
2098 * However, below we treat the new (a0) parameter as src2/opr2, so in the
2099 * actual functions below, expect their syntax to differ slightly to those
2100 * listed in the manuals. I.e., replace arg1 with arg3, arg2 with arg1 and
2101 * arg3 with arg2. This affects WINED3DTOP_MULTIPLYADD and WINED3DTOP_LERP. */
2103 if (isAlpha)
2105 comb_target = GL_COMBINE_ALPHA;
2106 src0_target = GL_SOURCE0_ALPHA;
2107 src1_target = GL_SOURCE1_ALPHA;
2108 src2_target = GL_SOURCE2_ALPHA;
2109 opr0_target = GL_OPERAND0_ALPHA;
2110 opr1_target = GL_OPERAND1_ALPHA;
2111 opr2_target = GL_OPERAND2_ALPHA;
2112 scal_target = GL_ALPHA_SCALE;
2114 else
2116 comb_target = GL_COMBINE_RGB;
2117 src0_target = GL_SOURCE0_RGB;
2118 src1_target = GL_SOURCE1_RGB;
2119 src2_target = GL_SOURCE2_RGB;
2120 opr0_target = GL_OPERAND0_RGB;
2121 opr1_target = GL_OPERAND1_RGB;
2122 opr2_target = GL_OPERAND2_RGB;
2123 scal_target = GL_RGB_SCALE;
2126 /* If a texture stage references an invalid texture unit the stage just
2127 * passes through the result from the previous stage */
2128 if (is_invalid_op(state, Stage, op, arg1, arg2, arg3))
2130 arg1 = WINED3DTA_CURRENT;
2131 op = WINED3D_TOP_SELECT_ARG1;
2134 if (isAlpha && !state->textures[Stage] && arg1 == WINED3DTA_TEXTURE)
2136 get_src_and_opr(WINED3DTA_DIFFUSE, isAlpha, &src1, &opr1);
2137 } else {
2138 get_src_and_opr(arg1, isAlpha, &src1, &opr1);
2140 get_src_and_opr(arg2, isAlpha, &src2, &opr2);
2141 get_src_and_opr(arg3, isAlpha, &src3, &opr3);
2143 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
2145 Handled = TRUE; /* Assume will be handled */
2147 /* Other texture operations require special extensions: */
2148 if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
2150 if (isAlpha) {
2151 opr = GL_SRC_ALPHA;
2152 invopr = GL_ONE_MINUS_SRC_ALPHA;
2153 src3_target = GL_SOURCE3_ALPHA_NV;
2154 opr3_target = GL_OPERAND3_ALPHA_NV;
2155 } else {
2156 opr = GL_SRC_COLOR;
2157 invopr = GL_ONE_MINUS_SRC_COLOR;
2158 src3_target = GL_SOURCE3_RGB_NV;
2159 opr3_target = GL_OPERAND3_RGB_NV;
2161 switch (op)
2163 case WINED3D_TOP_DISABLE: /* Only for alpha */
2164 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2165 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2166 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2167 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2168 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2169 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2170 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2171 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2172 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2173 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2174 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2175 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2176 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2177 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2178 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2179 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2180 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2181 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2182 break;
2184 case WINED3D_TOP_SELECT_ARG1: /* = a1 * 1 + 0 * 0 */
2185 case WINED3D_TOP_SELECT_ARG2: /* = a2 * 1 + 0 * 0 */
2186 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2187 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2188 if (op == WINED3D_TOP_SELECT_ARG1)
2190 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2191 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2192 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2193 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2195 else
2197 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2198 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2199 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2200 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2202 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2203 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2204 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2205 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2206 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2207 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2208 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2209 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2210 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2211 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2212 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2213 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2214 break;
2216 case WINED3D_TOP_MODULATE:
2217 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2218 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2219 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2220 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2221 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2222 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2223 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2224 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2225 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2226 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2227 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2228 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2229 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2230 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2231 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2232 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2233 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2234 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2235 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2236 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2237 break;
2238 case WINED3D_TOP_MODULATE_2X:
2239 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2240 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2241 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2242 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2243 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2244 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2245 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2246 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2247 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2248 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2249 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2250 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2251 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2252 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2253 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2254 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2255 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2256 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2257 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2258 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2259 break;
2260 case WINED3D_TOP_MODULATE_4X:
2261 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2262 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2263 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2264 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2265 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2266 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2267 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2268 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2269 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2270 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2271 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2272 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2273 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2274 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2275 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2276 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2277 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2278 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2279 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2280 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2281 break;
2283 case WINED3D_TOP_ADD:
2284 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2285 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2286 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2287 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2288 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2289 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2290 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2291 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2292 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2293 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2294 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2295 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2296 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2297 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2298 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2299 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2300 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2301 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2302 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2303 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2304 break;
2306 case WINED3D_TOP_ADD_SIGNED:
2307 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2308 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2309 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2310 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2311 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2312 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2313 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2314 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2315 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2316 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2317 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2318 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2319 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2320 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2321 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2322 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2323 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2324 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2325 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2326 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2327 break;
2329 case WINED3D_TOP_ADD_SIGNED_2X:
2330 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2331 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2332 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2333 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2334 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2335 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2336 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2337 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2338 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2339 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2340 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2341 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2342 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2343 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2344 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2345 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2346 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2347 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2348 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2349 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2350 break;
2352 case WINED3D_TOP_ADD_SMOOTH:
2353 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2354 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2355 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2356 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2357 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2358 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2359 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2360 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2361 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2362 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2363 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2364 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2365 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2366 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2367 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2368 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2369 switch (opr1) {
2370 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2371 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2372 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2373 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2375 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2376 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2377 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2378 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2379 break;
2381 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2382 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2383 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2384 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2385 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2386 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2387 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2388 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR);
2389 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR");
2390 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2391 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2392 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2393 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2394 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2395 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2396 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR);
2397 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR");
2398 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2399 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2400 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2401 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2402 break;
2403 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2404 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2405 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2406 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2407 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2408 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2409 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2410 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
2411 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
2412 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2413 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2414 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2415 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2416 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2417 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2418 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2419 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2420 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2421 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2422 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2423 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2424 break;
2425 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2426 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2427 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2428 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2429 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2430 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2431 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2432 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_CONSTANT);
2433 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_CONSTANT");
2434 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2435 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2436 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2437 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2438 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2439 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2440 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_CONSTANT);
2441 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_CONSTANT");
2442 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2443 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2444 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2445 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2446 break;
2447 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2448 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2449 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2450 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2451 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2452 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2453 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2454 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2455 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2456 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2457 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2458 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2459 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2460 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2461 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2462 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2463 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2464 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2465 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2466 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2467 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2468 break;
2469 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2470 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2471 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2472 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
2473 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2474 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2475 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
2476 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2477 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2478 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2479 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2480 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
2481 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2482 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2483 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
2484 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2485 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2486 switch (opr) {
2487 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2488 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2490 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2491 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2492 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2493 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2494 break;
2495 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2496 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2497 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2498 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2499 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2500 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2501 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2502 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2503 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2504 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2505 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2506 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2507 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2508 switch (opr1) {
2509 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2510 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2512 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2513 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2514 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2515 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2516 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2517 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2518 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2519 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2520 break;
2521 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2522 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2523 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2524 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2525 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2526 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2527 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2528 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2529 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2530 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2531 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2532 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2533 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2534 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2535 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2536 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2537 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2538 switch (opr1) {
2539 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2540 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2541 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2542 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2544 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2545 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2546 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2547 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2548 break;
2549 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
2550 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2551 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2552 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2553 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2554 switch (opr1) {
2555 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2556 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2557 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2558 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2560 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2561 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2562 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2563 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2564 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2565 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2566 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2567 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2568 switch (opr1) {
2569 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2570 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2572 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2573 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2574 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2575 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2576 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2577 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2578 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2579 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2580 break;
2581 case WINED3D_TOP_MULTIPLY_ADD:
2582 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2583 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2584 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
2585 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2586 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
2587 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2588 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2589 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2590 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2591 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2592 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2593 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2594 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
2595 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2596 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
2597 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
2598 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
2599 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
2600 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2601 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2602 break;
2604 case WINED3D_TOP_BUMPENVMAP:
2605 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
2606 FIXME("Implement bump environment mapping in GL_NV_texture_env_combine4 path\n");
2607 Handled = FALSE;
2608 break;
2610 default:
2611 Handled = FALSE;
2613 if (Handled)
2615 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
2616 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
2618 return;
2620 } /* GL_NV_texture_env_combine4 */
2622 Handled = TRUE; /* Again, assume handled */
2623 switch (op) {
2624 case WINED3D_TOP_DISABLE: /* Only for alpha */
2625 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2626 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2627 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2628 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
2629 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2630 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
2631 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2632 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2633 break;
2634 case WINED3D_TOP_SELECT_ARG1:
2635 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2636 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2637 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2638 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2639 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2640 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2641 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2642 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2643 break;
2644 case WINED3D_TOP_SELECT_ARG2:
2645 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2646 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2647 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2648 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2649 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2650 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2651 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2652 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2653 break;
2654 case WINED3D_TOP_MODULATE:
2655 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2656 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2657 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2658 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2659 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2660 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2661 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2662 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2663 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2664 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2665 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2666 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2667 break;
2668 case WINED3D_TOP_MODULATE_2X:
2669 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2670 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2671 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2672 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2673 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2674 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2675 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2676 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2677 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2678 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2679 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2680 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2681 break;
2682 case WINED3D_TOP_MODULATE_4X:
2683 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2684 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2685 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2686 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2687 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2688 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2689 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2690 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2691 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2692 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2693 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2694 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2695 break;
2696 case WINED3D_TOP_ADD:
2697 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2698 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2699 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2700 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2701 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2702 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2703 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2704 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2705 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2706 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2707 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2708 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2709 break;
2710 case WINED3D_TOP_ADD_SIGNED:
2711 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2712 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2713 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2714 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2715 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2716 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2717 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2718 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2719 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2720 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2721 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2722 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2723 break;
2724 case WINED3D_TOP_ADD_SIGNED_2X:
2725 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2726 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2727 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2728 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2729 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2730 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2731 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2732 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2733 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2734 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2735 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2736 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2737 break;
2738 case WINED3D_TOP_SUBTRACT:
2739 if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE])
2741 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
2742 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_SUBTRACT");
2743 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2744 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2745 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2746 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2747 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2748 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2749 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2750 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2751 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2752 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2753 } else {
2754 FIXME("This version of opengl does not support GL_SUBTRACT\n");
2756 break;
2758 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2759 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2760 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2761 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2762 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2763 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2764 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2765 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2766 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2767 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2768 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2769 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR);
2770 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
2771 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2772 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2773 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2774 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2775 break;
2776 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2777 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2778 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2779 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2780 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2781 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2782 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2783 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2784 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2785 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2786 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2787 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
2788 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
2789 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2790 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2791 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2792 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2793 break;
2794 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2795 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2796 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2797 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2798 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2799 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2800 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2801 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2802 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2803 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2804 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2805 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_CONSTANT);
2806 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
2807 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2808 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2809 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2810 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2811 break;
2812 case WINED3D_TOP_BLEND_CURRENT_ALPHA:
2813 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2814 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2815 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2816 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2817 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2818 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2819 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2820 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2821 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2822 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2823 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PREVIOUS);
2824 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
2825 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2826 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2827 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2828 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2829 break;
2830 case WINED3D_TOP_DOTPRODUCT3:
2831 if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
2833 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
2834 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
2836 else if (gl_info->supported[EXT_TEXTURE_ENV_DOT3])
2838 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
2839 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
2840 } else {
2841 FIXME("This version of opengl does not support GL_DOT3\n");
2843 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2844 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2845 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2846 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2847 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2848 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2849 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2850 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2851 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2852 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2853 break;
2854 case WINED3D_TOP_LERP:
2855 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2856 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2857 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2858 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2859 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2860 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2861 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2862 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2863 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2864 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2865 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
2866 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
2867 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
2868 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
2869 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2870 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2871 break;
2872 case WINED3D_TOP_ADD_SMOOTH:
2873 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2875 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2876 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2877 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2878 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2879 switch (opr1) {
2880 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2881 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2882 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2883 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2885 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2886 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2887 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2888 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2889 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2890 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2891 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2892 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2893 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2894 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2895 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2896 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2897 } else
2898 Handled = FALSE;
2899 break;
2900 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2901 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2903 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2904 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2905 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
2906 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
2907 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
2908 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
2909 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2910 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2911 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2912 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2913 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2914 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2915 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2916 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2917 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2918 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2919 } else
2920 Handled = FALSE;
2921 break;
2922 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2923 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2925 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2926 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2927 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2928 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2929 switch (opr1) {
2930 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2931 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2932 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2933 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2935 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2936 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2937 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2938 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2939 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2940 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2941 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2942 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2943 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2944 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2945 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2946 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2947 } else
2948 Handled = FALSE;
2949 break;
2950 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2951 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2953 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2954 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2955 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2956 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2957 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2958 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2959 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2960 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2961 switch (opr1) {
2962 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2963 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2964 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2965 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2967 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2968 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2969 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2970 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2971 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2972 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2973 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2974 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2975 } else
2976 Handled = FALSE;
2977 break;
2978 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2979 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2981 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2982 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2983 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2984 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2985 switch (opr1) {
2986 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2987 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2988 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2989 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2991 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2992 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2993 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2994 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2995 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2996 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2997 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2998 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2999 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
3000 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
3001 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
3002 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
3003 } else
3004 Handled = FALSE;
3005 break;
3006 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
3007 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
3009 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
3010 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
3011 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
3012 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
3013 switch (opr1) {
3014 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
3015 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
3016 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
3017 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
3019 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
3020 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
3021 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
3022 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
3023 switch (opr1) {
3024 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
3025 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
3026 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
3027 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
3029 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
3030 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
3031 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
3032 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
3033 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
3034 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
3035 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
3036 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
3037 } else
3038 Handled = FALSE;
3039 break;
3040 case WINED3D_TOP_MULTIPLY_ADD:
3041 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
3043 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
3044 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
3045 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
3046 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
3047 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
3048 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
3049 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src3);
3050 checkGLcall("GL_TEXTURE_ENV, src1_target, src3");
3051 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr3);
3052 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr3");
3053 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
3054 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
3055 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
3056 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
3057 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
3058 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
3059 } else
3060 Handled = FALSE;
3061 break;
3062 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
3063 case WINED3D_TOP_BUMPENVMAP:
3064 if (gl_info->supported[NV_TEXTURE_SHADER2])
3066 /* Technically texture shader support without register combiners is possible, but not expected to occur
3067 * on real world cards, so for now a fixme should be enough
3069 FIXME("Implement bump mapping with GL_NV_texture_shader in non register combiner path\n");
3071 Handled = FALSE;
3072 break;
3074 default:
3075 Handled = FALSE;
3078 if (Handled) {
3079 BOOL combineOK = TRUE;
3080 if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
3082 DWORD op2;
3084 if (isAlpha)
3085 op2 = state->texture_states[Stage][WINED3D_TSS_COLOR_OP];
3086 else
3087 op2 = state->texture_states[Stage][WINED3D_TSS_ALPHA_OP];
3089 /* Note: If COMBINE4 in effect can't go back to combine! */
3090 switch (op2)
3092 case WINED3D_TOP_ADD_SMOOTH:
3093 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
3094 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
3095 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
3096 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
3097 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
3098 case WINED3D_TOP_MULTIPLY_ADD:
3099 /* Ignore those implemented in both cases */
3100 switch (op)
3102 case WINED3D_TOP_SELECT_ARG1:
3103 case WINED3D_TOP_SELECT_ARG2:
3104 combineOK = FALSE;
3105 Handled = FALSE;
3106 break;
3107 default:
3108 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%s, otherop=%s, isAlpha(%d)\n", debug_d3dtop(op), debug_d3dtop(op2), isAlpha);
3109 return;
3114 if (combineOK)
3116 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
3117 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE");
3119 return;
3123 /* After all the extensions, if still unhandled, report fixme */
3124 FIXME("Unhandled texture operation %s\n", debug_d3dtop(op));
3128 static void tex_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3130 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3131 BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
3132 DWORD mapped_stage = context->tex_unit_map[stage];
3133 const struct wined3d_gl_info *gl_info = context->gl_info;
3135 TRACE("Setting color op for stage %d\n", stage);
3137 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
3138 if (use_ps(state)) return;
3140 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
3142 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3144 if (tex_used && mapped_stage >= gl_info->limits.textures)
3146 FIXME("Attempt to enable unsupported stage!\n");
3147 return;
3149 context_active_texture(context, gl_info, mapped_stage);
3152 if (stage >= context->lowest_disabled_stage)
3154 TRACE("Stage disabled\n");
3155 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3157 /* Disable everything here */
3158 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3159 checkGLcall("glDisable(GL_TEXTURE_2D)");
3160 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3161 checkGLcall("glDisable(GL_TEXTURE_3D)");
3162 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3164 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3165 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
3167 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3169 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3170 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
3173 /* All done */
3174 return;
3177 /* The sampler will also activate the correct texture dimensions, so no
3178 * need to do it here if the sampler for this stage is dirty. */
3179 if (!isStateDirty(context, STATE_SAMPLER(stage)) && tex_used)
3180 texture_activate_dimensions(state->textures[stage], gl_info);
3182 set_tex_op(gl_info, state, FALSE, stage,
3183 state->texture_states[stage][WINED3D_TSS_COLOR_OP],
3184 state->texture_states[stage][WINED3D_TSS_COLOR_ARG1],
3185 state->texture_states[stage][WINED3D_TSS_COLOR_ARG2],
3186 state->texture_states[stage][WINED3D_TSS_COLOR_ARG0]);
3189 void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3191 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3192 BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
3193 DWORD mapped_stage = context->tex_unit_map[stage];
3194 const struct wined3d_gl_info *gl_info = context->gl_info;
3195 DWORD op, arg1, arg2, arg0;
3197 TRACE("Setting alpha op for stage %d\n", stage);
3198 /* Do not care for enabled / disabled stages, just assign the settings. colorop disables / enables required stuff */
3199 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3201 if (tex_used && mapped_stage >= gl_info->limits.textures)
3203 FIXME("Attempt to enable unsupported stage!\n");
3204 return;
3206 context_active_texture(context, gl_info, mapped_stage);
3209 op = state->texture_states[stage][WINED3D_TSS_ALPHA_OP];
3210 arg1 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG1];
3211 arg2 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG2];
3212 arg0 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG0];
3214 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !stage && state->textures[0])
3216 struct wined3d_texture_gl *texture_gl = wined3d_texture_gl(state->textures[0]);
3217 GLenum texture_dimensions = texture_gl->target;
3219 if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
3221 if (texture_gl->t.async.color_key_flags & WINED3D_CKEY_SRC_BLT
3222 && !texture_gl->t.resource.format->alpha_size)
3224 /* Color keying needs to pass alpha values from the texture through to have the alpha test work
3225 * properly. On the other hand applications can still use texture combiners apparently. This code
3226 * takes care that apps cannot remove the texture's alpha channel entirely.
3228 * The fixup is required for Prince of Persia 3D(prison bars), while Moto racer 2 requires
3229 * D3DTOP_MODULATE to work on color keyed surfaces. Aliens vs Predator 1 uses color keyed textures
3230 * and alpha component of diffuse color to draw things like translucent text and perform other
3231 * blending effects.
3233 * Aliens vs Predator 1 relies on diffuse alpha having an effect, so it cannot be ignored. To
3234 * provide the behavior expected by the game, while emulating the colorkey, diffuse alpha must be
3235 * modulated with texture alpha. OTOH, Moto racer 2 at some points sets alphaop/alphaarg to
3236 * SELECTARG/CURRENT, yet puts garbage in diffuse alpha (zeroes). This works on native, because the
3237 * game disables alpha test and alpha blending. Alpha test is overwritten by wine's for purposes of
3238 * color-keying though, so this will lead to missing geometry if texture alpha is modulated (pixels
3239 * fail alpha test). To get around this, ALPHABLENDENABLE state is checked: if the app enables alpha
3240 * blending, it can be expected to provide meaningful values in diffuse alpha, so it should be
3241 * modulated with texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture
3242 * alpha.
3244 * What to do with multitexturing? So far no app has been found that uses color keying with
3245 * multitexturing */
3246 if (op == WINED3D_TOP_DISABLE)
3248 arg1 = WINED3DTA_TEXTURE;
3249 op = WINED3D_TOP_SELECT_ARG1;
3251 else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE)
3253 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3255 arg2 = WINED3DTA_TEXTURE;
3256 op = WINED3D_TOP_MODULATE;
3258 else arg1 = WINED3DTA_TEXTURE;
3260 else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE)
3262 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3264 arg1 = WINED3DTA_TEXTURE;
3265 op = WINED3D_TOP_MODULATE;
3267 else arg2 = WINED3DTA_TEXTURE;
3273 /* tex_alphaop is shared between the ffp and nvrc because the difference only comes down to
3274 * this if block here, and the other code(color keying, texture unit selection) are the same
3276 TRACE("Setting alpha op for stage %d\n", stage);
3277 if (gl_info->supported[NV_REGISTER_COMBINERS])
3279 set_tex_op_nvrc(gl_info, state, TRUE, stage, op, arg1, arg2, arg0,
3280 mapped_stage, state->texture_states[stage][WINED3D_TSS_RESULT_ARG]);
3282 else
3284 set_tex_op(gl_info, state, TRUE, stage, op, arg1, arg2, arg0);
3288 static void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3290 const struct wined3d_gl_info *gl_info = context->gl_info;
3291 unsigned int tex = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3292 unsigned int mapped_stage = context->tex_unit_map[tex];
3293 struct wined3d_matrix mat;
3295 /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
3296 if (use_vs(state) || isStateDirty(context, STATE_VDECL))
3298 TRACE("Using a vertex shader, or stream sources not sorted out yet, skipping\n");
3299 return;
3302 if (mapped_stage == WINED3D_UNMAPPED_STAGE) return;
3303 if (mapped_stage >= gl_info->limits.textures) return;
3305 context_active_texture(context, gl_info, mapped_stage);
3306 gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
3307 checkGLcall("glMatrixMode(GL_TEXTURE)");
3309 get_texture_matrix(context, state, mapped_stage, &mat);
3311 gl_info->gl_ops.gl.p_glLoadMatrixf(&mat._11);
3312 checkGLcall("glLoadMatrixf");
3315 static void tex_coordindex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3317 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3318 static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f };
3319 static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f };
3320 static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f };
3321 static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f };
3322 const struct wined3d_gl_info *gl_info = context->gl_info;
3323 DWORD mapped_stage = context->tex_unit_map[stage];
3325 if (mapped_stage == WINED3D_UNMAPPED_STAGE)
3327 TRACE("No texture unit mapped to stage %d. Skipping texture coordinates.\n", stage);
3328 return;
3331 if (mapped_stage >= min(gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL], MAX_FRAGMENT_SAMPLERS))
3333 WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage);
3334 return;
3336 context_active_texture(context, gl_info, mapped_stage);
3338 /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
3340 * FIXME: When using generated texture coordinates, the index value is used to specify the wrapping mode.
3341 * eg. SetTextureStageState( 0, WINED3D_TSS_TEXCOORDINDEX, WINED3D_TSS_TCI_CAMERASPACEPOSITION | 1 );
3342 * means use the vertex position (camera-space) as the input texture coordinates
3343 * for this texture stage, and the wrap mode set in the WINED3D_RS_WRAP1 render
3344 * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up
3345 * to the TEXCOORDINDEX value
3347 switch (state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
3349 case WINED3DTSS_TCI_PASSTHRU:
3350 /* Use the specified texture coordinates contained within the
3351 * vertex format. This value resolves to zero. */
3352 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
3353 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
3354 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3355 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3356 checkGLcall("WINED3DTSS_TCI_PASSTHRU - Disable texgen.");
3357 break;
3359 case WINED3DTSS_TCI_CAMERASPACEPOSITION:
3360 /* CameraSpacePosition means use the vertex position, transformed to camera space,
3361 * as the input texture coordinates for this stage's texture transformation. This
3362 * equates roughly to EYE_LINEAR */
3364 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3365 gl_info->gl_ops.gl.p_glPushMatrix();
3366 gl_info->gl_ops.gl.p_glLoadIdentity();
3367 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3368 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3369 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3370 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3371 gl_info->gl_ops.gl.p_glPopMatrix();
3372 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set eye plane.");
3374 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3375 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3376 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3377 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set texgen mode.");
3379 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3380 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3381 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3382 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Enable texgen.");
3384 break;
3386 case WINED3DTSS_TCI_CAMERASPACENORMAL:
3387 /* Note that NV_TEXGEN_REFLECTION support is implied when
3388 * ARB_TEXTURE_CUBE_MAP is supported */
3389 if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3391 FIXME("WINED3DTSS_TCI_CAMERASPACENORMAL not supported.\n");
3392 break;
3395 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3396 gl_info->gl_ops.gl.p_glPushMatrix();
3397 gl_info->gl_ops.gl.p_glLoadIdentity();
3398 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3399 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3400 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3401 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3402 gl_info->gl_ops.gl.p_glPopMatrix();
3403 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set eye plane.");
3405 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3406 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3407 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3408 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set texgen mode.");
3410 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3411 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3412 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3413 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Enable texgen.");
3415 break;
3417 case WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
3418 /* Note that NV_TEXGEN_REFLECTION support is implied when
3419 * ARB_TEXTURE_CUBE_MAP is supported */
3420 if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3422 FIXME("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR not supported.\n");
3423 break;
3426 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3427 gl_info->gl_ops.gl.p_glPushMatrix();
3428 gl_info->gl_ops.gl.p_glLoadIdentity();
3429 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3430 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3431 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3432 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3433 gl_info->gl_ops.gl.p_glPopMatrix();
3434 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set eye plane.");
3436 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3437 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3438 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3439 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set texgen mode.");
3441 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3442 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3443 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3444 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Enable texgen.");
3446 break;
3448 case WINED3DTSS_TCI_SPHEREMAP:
3449 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
3450 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
3451 checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Set texgen mode.");
3453 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3454 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3455 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3456 checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Enable texgen.");
3458 break;
3460 default:
3461 FIXME("Unhandled WINED3D_TSS_TEXCOORD_INDEX %#x.\n",
3462 state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX]);
3463 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
3464 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
3465 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3466 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3467 checkGLcall("Disable texgen.");
3469 break;
3472 /* Update the texture matrix. */
3473 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + stage)))
3474 transform_texture(context, state, STATE_TEXTURESTAGE(stage, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3476 if (!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded)
3478 /* Reload the arrays if we are using fixed function arrays to reflect the selected coord input
3479 * source. Call loadTexCoords directly because there is no need to reparse the vertex declaration
3480 * and do all the things linked to it
3481 * TODO: Tidy that up to reload only the arrays of the changed unit
3483 GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
3485 context_unload_tex_coords(context);
3486 context_load_tex_coords(context, &context->stream_info, &curVBO, state);
3490 static void sampler_texmatrix(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3492 const DWORD sampler = state_id - STATE_SAMPLER(0);
3493 const struct wined3d_texture *texture = state->textures[sampler];
3495 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
3497 if (!texture)
3498 return;
3500 /* The fixed function np2 texture emulation uses the texture matrix to fix up the coordinates
3501 * wined3d_texture_apply_state_changes() multiplies the set matrix with a fixup matrix. Before the
3502 * scaling is reapplied or removed, the texture matrix has to be reapplied.
3504 if (sampler < MAX_TEXTURES)
3506 const BOOL tex_is_pow2 = !(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT);
3508 if (tex_is_pow2 || (context->lastWasPow2Texture & (1u << sampler)))
3510 if (tex_is_pow2)
3511 context->lastWasPow2Texture |= 1u << sampler;
3512 else
3513 context->lastWasPow2Texture &= ~(1u << sampler);
3515 transform_texture(context, state, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3520 static enum wined3d_texture_address wined3d_texture_gl_address_mode(const struct wined3d_texture_gl *texture_gl,
3521 enum wined3d_texture_address t)
3523 if (t < WINED3D_TADDRESS_WRAP || t > WINED3D_TADDRESS_MIRROR_ONCE)
3525 FIXME("Unrecognized or unsupported texture address mode %#x.\n", t);
3526 return WINED3D_TADDRESS_WRAP;
3529 /* Cubemaps are always set to clamp, regardless of the sampler state. */
3530 if (texture_gl->target == GL_TEXTURE_CUBE_MAP_ARB || ((texture_gl->t.flags & WINED3D_TEXTURE_COND_NP2)
3531 && t == WINED3D_TADDRESS_WRAP))
3532 return WINED3D_TADDRESS_CLAMP;
3534 return t;
3537 static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc *desc,
3538 const struct wined3d_context *context, const DWORD *sampler_states,
3539 const struct wined3d_texture_gl *texture_gl)
3541 union
3543 float f;
3544 DWORD d;
3545 } lod_bias;
3547 desc->address_u = wined3d_texture_gl_address_mode(texture_gl, sampler_states[WINED3D_SAMP_ADDRESS_U]);
3548 desc->address_v = wined3d_texture_gl_address_mode(texture_gl, sampler_states[WINED3D_SAMP_ADDRESS_V]);
3549 desc->address_w = wined3d_texture_gl_address_mode(texture_gl, sampler_states[WINED3D_SAMP_ADDRESS_W]);
3550 wined3d_color_from_d3dcolor((struct wined3d_color *)desc->border_color,
3551 sampler_states[WINED3D_SAMP_BORDER_COLOR]);
3552 if (sampler_states[WINED3D_SAMP_MAG_FILTER] > WINED3D_TEXF_ANISOTROPIC)
3553 FIXME("Unrecognized or unsupported WINED3D_SAMP_MAG_FILTER %#x.\n",
3554 sampler_states[WINED3D_SAMP_MAG_FILTER]);
3555 desc->mag_filter = min(max(sampler_states[WINED3D_SAMP_MAG_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
3556 if (sampler_states[WINED3D_SAMP_MIN_FILTER] > WINED3D_TEXF_ANISOTROPIC)
3557 FIXME("Unrecognized or unsupported WINED3D_SAMP_MIN_FILTER %#x.\n",
3558 sampler_states[WINED3D_SAMP_MIN_FILTER]);
3559 desc->min_filter = min(max(sampler_states[WINED3D_SAMP_MIN_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
3560 if (sampler_states[WINED3D_SAMP_MIP_FILTER] > WINED3D_TEXF_ANISOTROPIC)
3561 FIXME("Unrecognized or unsupported WINED3D_SAMP_MIP_FILTER %#x.\n",
3562 sampler_states[WINED3D_SAMP_MIP_FILTER]);
3563 desc->mip_filter = min(max(sampler_states[WINED3D_SAMP_MIP_FILTER], WINED3D_TEXF_NONE), WINED3D_TEXF_LINEAR);
3564 lod_bias.d = sampler_states[WINED3D_SAMP_MIPMAP_LOD_BIAS];
3565 desc->lod_bias = lod_bias.f;
3566 desc->min_lod = -1000.0f;
3567 desc->max_lod = 1000.0f;
3568 desc->mip_base_level = sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL];
3569 desc->max_anisotropy = sampler_states[WINED3D_SAMP_MAX_ANISOTROPY];
3570 if ((sampler_states[WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_ANISOTROPIC
3571 && sampler_states[WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_ANISOTROPIC
3572 && sampler_states[WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_ANISOTROPIC)
3573 || (texture_gl->t.flags & WINED3D_TEXTURE_COND_NP2))
3574 desc->max_anisotropy = 1;
3575 desc->compare = texture_gl->t.resource.format_flags & WINED3DFMT_FLAG_SHADOW;
3576 desc->comparison_func = WINED3D_CMP_LESSEQUAL;
3577 desc->srgb_decode = sampler_states[WINED3D_SAMP_SRGB_TEXTURE];
3579 if (!(texture_gl->t.resource.format_flags & WINED3DFMT_FLAG_FILTERING))
3581 desc->mag_filter = WINED3D_TEXF_POINT;
3582 desc->min_filter = WINED3D_TEXF_POINT;
3583 desc->mip_filter = WINED3D_TEXF_NONE;
3586 if (texture_gl->t.flags & WINED3D_TEXTURE_COND_NP2)
3588 desc->mip_filter = WINED3D_TEXF_NONE;
3589 if (context->gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
3590 desc->min_filter = WINED3D_TEXF_POINT;
3594 /* Enabling and disabling texture dimensions is done by texture stage state /
3595 * pixel shader setup, this function only has to bind textures and set the per
3596 * texture states. */
3597 static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3599 DWORD sampler_idx = state_id - STATE_SAMPLER(0);
3600 DWORD mapped_stage = context->tex_unit_map[sampler_idx];
3601 const struct wined3d_gl_info *gl_info = context->gl_info;
3603 TRACE("Sampler %u.\n", sampler_idx);
3605 if (mapped_stage == WINED3D_UNMAPPED_STAGE)
3607 TRACE("No sampler mapped to stage %u. Returning.\n", sampler_idx);
3608 return;
3611 if (mapped_stage >= gl_info->limits.graphics_samplers)
3612 return;
3613 context_active_texture(context, gl_info, mapped_stage);
3615 if (state->textures[sampler_idx])
3617 struct wined3d_texture_gl *texture_gl = wined3d_texture_gl(state->textures[sampler_idx]);
3618 BOOL srgb = state->sampler_states[sampler_idx][WINED3D_SAMP_SRGB_TEXTURE];
3619 const DWORD *sampler_states = state->sampler_states[sampler_idx];
3620 struct wined3d_device *device = context->device;
3621 struct wined3d_sampler_desc desc;
3622 struct wined3d_sampler *sampler;
3623 struct wine_rb_entry *entry;
3625 wined3d_sampler_desc_from_sampler_states(&desc, context, sampler_states, texture_gl);
3627 wined3d_texture_gl_bind(texture_gl, context, srgb);
3629 if ((entry = wine_rb_get(&device->samplers, &desc)))
3631 sampler = WINE_RB_ENTRY_VALUE(entry, struct wined3d_sampler, entry);
3633 else
3635 if (FAILED(wined3d_sampler_create(device, &desc, NULL, &wined3d_null_parent_ops, &sampler)))
3637 ERR("Failed to create sampler.\n");
3638 return;
3640 if (wine_rb_put(&device->samplers, &desc, &sampler->entry) == -1)
3642 ERR("Failed to insert sampler.\n");
3643 wined3d_sampler_decref(sampler);
3644 return;
3648 wined3d_sampler_bind(sampler, mapped_stage, texture_gl, context);
3650 /* Trigger shader constant reloading (for NP2 texcoord fixup) */
3651 if (!(texture_gl->t.flags & WINED3D_TEXTURE_POW2_MAT_IDENT))
3652 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_NP2_FIXUP;
3654 else
3656 context_bind_texture(context, GL_NONE, 0);
3657 if (gl_info->supported[ARB_SAMPLER_OBJECTS])
3659 GL_EXTCALL(glBindSampler(mapped_stage, 0));
3660 checkGLcall("glBindSampler");
3665 void apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3667 unsigned int i;
3669 if (use_ps(state))
3671 if (!context->last_was_pshader)
3673 /* Former draw without a pixel shader, some samplers may be
3674 * disabled because of WINED3D_TSS_COLOR_OP = WINED3DTOP_DISABLE
3675 * make sure to enable them. */
3676 for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
3678 if (!isStateDirty(context, STATE_SAMPLER(i)))
3679 sampler(context, state, STATE_SAMPLER(i));
3681 context->last_was_pshader = TRUE;
3683 else
3685 /* Otherwise all samplers were activated by the code above in
3686 * earlier draws, or by sampler() if a different texture was
3687 * bound. I don't have to do anything. */
3690 else
3692 /* Disabled the pixel shader - color ops weren't applied while it was
3693 * enabled, so re-apply them. */
3694 for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
3696 if (!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP)))
3697 context_apply_state(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
3699 context->last_was_pshader = FALSE;
3702 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
3705 static void state_compute_shader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3707 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_COMPUTE;
3710 static void state_shader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3712 enum wined3d_shader_type shader_type = state_id - STATE_SHADER(0);
3713 context->shader_update_mask |= 1u << shader_type;
3716 static void shader_bumpenv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3718 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_BUMP_ENV;
3721 static void transform_world(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3723 const struct wined3d_gl_info *gl_info = context->gl_info;
3724 struct wined3d_matrix mat;
3726 /* This function is called by transform_view below if the view matrix was changed too
3728 * Deliberately no check if the vertex declaration is dirty because the vdecl state
3729 * does not always update the world matrix, only on a switch between transformed
3730 * and untransformed draws. It *may* happen that the world matrix is set 2 times during one
3731 * draw, but that should be rather rare and cheaper in total.
3733 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3734 checkGLcall("glMatrixMode");
3736 get_modelview_matrix(context, state, 0, &mat);
3738 gl_info->gl_ops.gl.p_glLoadMatrixf((GLfloat *)&mat);
3739 checkGLcall("glLoadMatrixf");
3742 void clipplane(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3744 const struct wined3d_gl_info *gl_info = context->gl_info;
3745 UINT index = state_id - STATE_CLIPPLANE(0);
3746 GLdouble plane[4];
3748 if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)) || index >= gl_info->limits.user_clip_distances)
3749 return;
3751 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3752 gl_info->gl_ops.gl.p_glPushMatrix();
3754 /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */
3755 if (!use_vs(state))
3756 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3757 else
3758 /* With vertex shaders, clip planes are not transformed in Direct3D,
3759 * while in OpenGL they are still transformed by the model view matrix. */
3760 gl_info->gl_ops.gl.p_glLoadIdentity();
3762 plane[0] = state->clip_planes[index].x;
3763 plane[1] = state->clip_planes[index].y;
3764 plane[2] = state->clip_planes[index].z;
3765 plane[3] = state->clip_planes[index].w;
3767 TRACE("Clipplane [%.8e, %.8e, %.8e, %.8e]\n",
3768 plane[0], plane[1], plane[2], plane[3]);
3769 gl_info->gl_ops.gl.p_glClipPlane(GL_CLIP_PLANE0 + index, plane);
3770 checkGLcall("glClipPlane");
3772 gl_info->gl_ops.gl.p_glPopMatrix();
3775 static void transform_worldex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3777 unsigned int matrix = state_id - STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0));
3779 WARN("Unsupported world matrix %u set.\n", matrix);
3782 static void state_vertexblend_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3784 enum wined3d_vertex_blend_flags f = state->render_states[WINED3D_RS_VERTEXBLEND];
3785 static unsigned int once;
3787 if (f == WINED3D_VBF_DISABLE)
3788 return;
3790 if (!once++) FIXME("Vertex blend flags %#x not supported.\n", f);
3791 else WARN("Vertex blend flags %#x not supported.\n", f);
3794 static void transform_view(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3796 const struct wined3d_gl_info *gl_info = context->gl_info;
3797 const struct wined3d_light_info *light = NULL;
3798 unsigned int k;
3800 /* If we are changing the View matrix, reset the light and clipping planes to the new view
3801 * NOTE: We have to reset the positions even if the light/plane is not currently
3802 * enabled, since the call to enable it will not reset the position.
3803 * NOTE2: Apparently texture transforms do NOT need reapplying
3806 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3807 checkGLcall("glMatrixMode(GL_MODELVIEW)");
3808 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3809 checkGLcall("glLoadMatrixf(...)");
3811 /* Reset lights. TODO: Call light apply func */
3812 for (k = 0; k < gl_info->limits.lights; ++k)
3814 if (!(light = state->lights[k]))
3815 continue;
3816 if (light->OriginalParms.type == WINED3D_LIGHT_DIRECTIONAL)
3817 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, &light->direction.x);
3818 else
3819 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, &light->position.x);
3820 checkGLcall("glLightfv posn");
3821 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_SPOT_DIRECTION, &light->direction.x);
3822 checkGLcall("glLightfv dirn");
3825 /* Reset Clipping Planes */
3826 for (k = 0; k < gl_info->limits.user_clip_distances; ++k)
3828 if (!isStateDirty(context, STATE_CLIPPLANE(k)))
3829 clipplane(context, state, STATE_CLIPPLANE(k));
3832 if (context->last_was_rhw)
3834 gl_info->gl_ops.gl.p_glLoadIdentity();
3835 checkGLcall("glLoadIdentity()");
3836 /* No need to update the world matrix, the identity is fine */
3837 return;
3840 /* Call the world matrix state, this will apply the combined WORLD + VIEW matrix
3841 * No need to do it here if the state is scheduled for update. */
3842 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
3843 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
3846 static void transform_projection(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3848 const struct wined3d_gl_info *gl_info = context->gl_info;
3849 struct wined3d_matrix projection;
3851 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
3852 checkGLcall("glMatrixMode(GL_PROJECTION)");
3854 get_projection_matrix(context, state, &projection);
3855 gl_info->gl_ops.gl.p_glLoadMatrixf(&projection._11);
3856 checkGLcall("glLoadMatrixf");
3859 static void streamsrc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3861 if (isStateDirty(context, STATE_VDECL))
3862 return;
3863 context_update_stream_sources(context, state);
3866 static void vdecl_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3868 if (isStateDirty(context, STATE_STREAMSRC))
3869 return;
3870 context_update_stream_sources(context, state);
3873 static void vertexdeclaration(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3875 const struct wined3d_gl_info *gl_info = context->gl_info;
3876 BOOL useVertexShaderFunction = use_vs(state);
3877 BOOL updateFog = FALSE;
3878 BOOL transformed;
3879 BOOL wasrhw = context->last_was_rhw;
3880 unsigned int i;
3882 transformed = context->stream_info.position_transformed;
3883 if (transformed != context->last_was_rhw && !useVertexShaderFunction)
3884 updateFog = TRUE;
3886 context->last_was_rhw = transformed;
3888 if (context->stream_info.swizzle_map != context->last_swizzle_map)
3889 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
3891 context->last_swizzle_map = context->stream_info.swizzle_map;
3893 /* Don't have to apply the matrices when vertex shaders are used. When
3894 * vshaders are turned off this function will be called again anyway to
3895 * make sure they're properly set. */
3896 if (!useVertexShaderFunction)
3898 /* TODO: Move this mainly to the viewport state and only apply when
3899 * the vp has changed or transformed / untransformed was switched. */
3900 if (wasrhw != context->last_was_rhw
3901 && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))
3902 && !isStateDirty(context, STATE_VIEWPORT))
3903 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
3904 /* World matrix needs reapplication here only if we're switching between rhw and non-rhw
3905 * mode.
3907 * If a vertex shader is used, the world matrix changed and then vertex shader unbound
3908 * this check will fail and the matrix not applied again. This is OK because a simple
3909 * world matrix change reapplies the matrix - These checks here are only to satisfy the
3910 * needs of the vertex declaration.
3912 * World and view matrix go into the same gl matrix, so only apply them when neither is
3913 * dirty
3915 if (transformed != wasrhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)))
3916 && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)))
3917 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
3918 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_COLORVERTEX)))
3919 context_apply_state(context, state, STATE_RENDER(WINED3D_RS_COLORVERTEX));
3920 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_LIGHTING)))
3921 state_lighting(context, state, STATE_RENDER(WINED3D_RS_LIGHTING));
3923 if (context->last_was_vshader)
3925 updateFog = TRUE;
3927 if (!context->d3d_info->vs_clipping
3928 && !isStateDirty(context, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE)))
3930 state_clipping(context, state, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE));
3933 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
3935 clipplane(context, state, STATE_CLIPPLANE(i));
3938 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS)))
3939 state_normalize(context, state, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS));
3941 else
3943 if (!context->last_was_vshader)
3945 static BOOL warned = FALSE;
3946 if (!context->d3d_info->vs_clipping)
3948 /* Disable all clip planes to get defined results on all drivers. See comment in the
3949 * state_clipping state handler
3951 context_enable_clip_distances(context, 0);
3953 if (!warned && state->render_states[WINED3D_RS_CLIPPLANEENABLE])
3955 FIXME("Clipping not supported with vertex shaders.\n");
3956 warned = TRUE;
3959 if (wasrhw)
3961 /* Apply the transform matrices when switching from rhw
3962 * drawing to vertex shaders. Vertex shaders themselves do
3963 * not need it, but the matrices are not reapplied
3964 * automatically when switching back from vertex shaders to
3965 * fixed function processing. So make sure we leave the fixed
3966 * function vertex processing states back in a sane state
3967 * before switching to shaders. */
3968 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
3969 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
3970 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
3971 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
3973 updateFog = TRUE;
3975 /* Vertex shader clipping ignores the view matrix. Update all clipplanes
3976 * (Note: ARB shaders can read the clip planes for clipping emulation even if
3977 * device->vs_clipping is false.
3979 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
3981 clipplane(context, state, STATE_CLIPPLANE(i));
3986 context->last_was_vshader = useVertexShaderFunction;
3987 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
3989 if (updateFog)
3990 context_apply_state(context, state, STATE_RENDER(WINED3D_RS_FOGVERTEXMODE));
3992 if (!useVertexShaderFunction)
3994 unsigned int i;
3996 for (i = 0; i < MAX_TEXTURES; ++i)
3998 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + i)))
3999 transform_texture(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
4002 if (use_ps(state) && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.major == 1
4003 && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.minor <= 3)
4004 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
4008 static void get_viewports(struct wined3d_context *context, const struct wined3d_state *state,
4009 unsigned int viewport_count, struct wined3d_viewport *viewports)
4011 const struct wined3d_rendertarget_view *depth_stencil = state->fb->depth_stencil;
4012 const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4013 unsigned int width, height, i;
4015 for (i = 0; i < viewport_count; ++i)
4016 viewports[i] = state->viewports[i];
4018 /* Note: GL uses a lower left origin while DirectX uses upper left. This
4019 * is reversed when using offscreen rendering. */
4020 if (context->render_offscreen)
4021 return;
4023 if (target)
4025 wined3d_rendertarget_view_get_drawable_size(target, context, &width, &height);
4027 else if (depth_stencil)
4029 height = depth_stencil->height;
4031 else
4033 FIXME("Could not get the height of render targets.\n");
4034 return;
4037 for (i = 0; i < viewport_count; ++i)
4038 viewports[i].y = height - (viewports[i].y + viewports[i].height);
4041 static void viewport_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4043 const struct wined3d_gl_info *gl_info = context->gl_info;
4044 struct wined3d_viewport vp[WINED3D_MAX_VIEWPORTS];
4046 if (gl_info->supported[ARB_VIEWPORT_ARRAY])
4048 GLdouble depth_ranges[2 * WINED3D_MAX_VIEWPORTS];
4049 GLfloat viewports[4 * WINED3D_MAX_VIEWPORTS];
4051 unsigned int i, reset_count = 0;
4053 get_viewports(context, state, state->viewport_count, vp);
4054 for (i = 0; i < state->viewport_count; ++i)
4056 depth_ranges[i * 2] = vp[i].min_z;
4057 depth_ranges[i * 2 + 1] = vp[i].max_z;
4059 viewports[i * 4] = vp[i].x;
4060 viewports[i * 4 + 1] = vp[i].y;
4061 viewports[i * 4 + 2] = vp[i].width;
4062 viewports[i * 4 + 3] = vp[i].height;
4065 if (context->viewport_count > state->viewport_count)
4066 reset_count = context->viewport_count - state->viewport_count;
4068 if (reset_count)
4070 memset(&depth_ranges[state->viewport_count * 2], 0, reset_count * 2 * sizeof(*depth_ranges));
4071 memset(&viewports[state->viewport_count * 4], 0, reset_count * 4 * sizeof(*viewports));
4074 GL_EXTCALL(glDepthRangeArrayv(0, state->viewport_count + reset_count, depth_ranges));
4075 GL_EXTCALL(glViewportArrayv(0, state->viewport_count + reset_count, viewports));
4076 context->viewport_count = state->viewport_count;
4078 else
4080 get_viewports(context, state, 1, vp);
4081 gl_info->gl_ops.gl.p_glDepthRange(vp[0].min_z, vp[0].max_z);
4082 gl_info->gl_ops.gl.p_glViewport(vp[0].x, vp[0].y, vp[0].width, vp[0].height);
4084 checkGLcall("setting clip space and viewport");
4087 static void viewport_miscpart_cc(struct wined3d_context *context,
4088 const struct wined3d_state *state, DWORD state_id)
4090 /* See get_projection_matrix() in utils.c for a discussion about those values. */
4091 float pixel_center_offset = context->d3d_info->wined3d_creation_flags
4092 & WINED3D_PIXEL_CENTER_INTEGER ? 63.0f / 128.0f : -1.0f / 128.0f;
4093 const struct wined3d_gl_info *gl_info = context->gl_info;
4094 struct wined3d_viewport vp[WINED3D_MAX_VIEWPORTS];
4095 GLdouble depth_ranges[2 * WINED3D_MAX_VIEWPORTS];
4096 GLfloat viewports[4 * WINED3D_MAX_VIEWPORTS];
4097 unsigned int i, reset_count = 0;
4099 get_viewports(context, state, state->viewport_count, vp);
4101 GL_EXTCALL(glClipControl(context->render_offscreen ? GL_UPPER_LEFT : GL_LOWER_LEFT, GL_ZERO_TO_ONE));
4103 for (i = 0; i < state->viewport_count; ++i)
4105 depth_ranges[i * 2] = vp[i].min_z;
4106 depth_ranges[i * 2 + 1] = vp[i].max_z;
4108 viewports[i * 4] = vp[i].x + pixel_center_offset;
4109 viewports[i * 4 + 1] = vp[i].y + pixel_center_offset;
4110 viewports[i * 4 + 2] = vp[i].width;
4111 viewports[i * 4 + 3] = vp[i].height;
4114 if (context->viewport_count > state->viewport_count)
4115 reset_count = context->viewport_count - state->viewport_count;
4117 if (reset_count)
4119 memset(&depth_ranges[state->viewport_count * 2], 0, reset_count * 2 * sizeof(*depth_ranges));
4120 memset(&viewports[state->viewport_count * 4], 0, reset_count * 4 * sizeof(*viewports));
4123 GL_EXTCALL(glDepthRangeArrayv(0, state->viewport_count + reset_count, depth_ranges));
4124 GL_EXTCALL(glViewportArrayv(0, state->viewport_count + reset_count, viewports));
4125 context->viewport_count = state->viewport_count;
4127 checkGLcall("setting clip space and viewport");
4130 static void viewport_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4132 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
4133 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4134 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE))
4135 && state->render_states[WINED3D_RS_POINTSCALEENABLE])
4136 state_pscale(context, state, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE));
4137 /* Update the position fixup. */
4138 context->constant_update_mask |= WINED3D_SHADER_CONST_POS_FIXUP;
4141 static void light(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4143 const struct wined3d_gl_info *gl_info = context->gl_info;
4144 UINT Index = state_id - STATE_ACTIVELIGHT(0);
4145 const struct wined3d_light_info *lightInfo = state->lights[Index];
4147 if (!lightInfo)
4149 gl_info->gl_ops.gl.p_glDisable(GL_LIGHT0 + Index);
4150 checkGLcall("glDisable(GL_LIGHT0 + Index)");
4152 else
4154 float quad_att;
4155 float colRGBA[] = {0.0f, 0.0f, 0.0f, 0.0f};
4157 /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
4158 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
4159 gl_info->gl_ops.gl.p_glPushMatrix();
4160 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
4162 /* Diffuse: */
4163 colRGBA[0] = lightInfo->OriginalParms.diffuse.r;
4164 colRGBA[1] = lightInfo->OriginalParms.diffuse.g;
4165 colRGBA[2] = lightInfo->OriginalParms.diffuse.b;
4166 colRGBA[3] = lightInfo->OriginalParms.diffuse.a;
4167 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_DIFFUSE, colRGBA);
4168 checkGLcall("glLightfv");
4170 /* Specular */
4171 colRGBA[0] = lightInfo->OriginalParms.specular.r;
4172 colRGBA[1] = lightInfo->OriginalParms.specular.g;
4173 colRGBA[2] = lightInfo->OriginalParms.specular.b;
4174 colRGBA[3] = lightInfo->OriginalParms.specular.a;
4175 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPECULAR, colRGBA);
4176 checkGLcall("glLightfv");
4178 /* Ambient */
4179 colRGBA[0] = lightInfo->OriginalParms.ambient.r;
4180 colRGBA[1] = lightInfo->OriginalParms.ambient.g;
4181 colRGBA[2] = lightInfo->OriginalParms.ambient.b;
4182 colRGBA[3] = lightInfo->OriginalParms.ambient.a;
4183 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_AMBIENT, colRGBA);
4184 checkGLcall("glLightfv");
4186 if ((lightInfo->OriginalParms.range * lightInfo->OriginalParms.range) >= FLT_MIN)
4187 quad_att = 1.4f / (lightInfo->OriginalParms.range * lightInfo->OriginalParms.range);
4188 else
4189 quad_att = 0.0f; /* 0 or MAX? (0 seems to be ok) */
4191 /* Do not assign attenuation values for lights that do not use them. D3D apps are free to pass any junk,
4192 * but gl drivers use them and may crash due to bad Attenuation values. Need for Speed most wanted sets
4193 * Attenuation0 to NaN and crashes in the gl lib
4196 switch (lightInfo->OriginalParms.type)
4198 case WINED3D_LIGHT_POINT:
4199 /* Position */
4200 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->position.x);
4201 checkGLcall("glLightfv");
4202 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4203 checkGLcall("glLightf");
4204 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
4205 lightInfo->OriginalParms.attenuation0);
4206 checkGLcall("glLightf");
4207 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
4208 lightInfo->OriginalParms.attenuation1);
4209 checkGLcall("glLightf");
4210 if (quad_att < lightInfo->OriginalParms.attenuation2)
4211 quad_att = lightInfo->OriginalParms.attenuation2;
4212 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4213 checkGLcall("glLightf");
4214 /* FIXME: Range */
4215 break;
4217 case WINED3D_LIGHT_SPOT:
4218 /* Position */
4219 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->position.x);
4220 checkGLcall("glLightfv");
4221 /* Direction */
4222 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPOT_DIRECTION, &lightInfo->direction.x);
4223 checkGLcall("glLightfv");
4224 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, lightInfo->exponent);
4225 checkGLcall("glLightf");
4226 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4227 checkGLcall("glLightf");
4228 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
4229 lightInfo->OriginalParms.attenuation0);
4230 checkGLcall("glLightf");
4231 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
4232 lightInfo->OriginalParms.attenuation1);
4233 checkGLcall("glLightf");
4234 if (quad_att < lightInfo->OriginalParms.attenuation2)
4235 quad_att = lightInfo->OriginalParms.attenuation2;
4236 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4237 checkGLcall("glLightf");
4238 /* FIXME: Range */
4239 break;
4241 case WINED3D_LIGHT_DIRECTIONAL:
4242 /* Direction */
4243 /* Note GL uses w position of 0 for direction! */
4244 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->direction.x);
4245 checkGLcall("glLightfv");
4246 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4247 checkGLcall("glLightf");
4248 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, 0.0f);
4249 checkGLcall("glLightf");
4250 break;
4252 default:
4253 FIXME("Unrecognized light type %#x.\n", lightInfo->OriginalParms.type);
4256 /* Restore the modelview matrix */
4257 gl_info->gl_ops.gl.p_glPopMatrix();
4259 gl_info->gl_ops.gl.p_glEnable(GL_LIGHT0 + Index);
4260 checkGLcall("glEnable(GL_LIGHT0 + Index)");
4264 static void scissorrect(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4266 const struct wined3d_gl_info *gl_info = context->gl_info;
4267 unsigned int height = 0;
4268 const RECT *r;
4270 /* Warning: glScissor uses window coordinates, not viewport coordinates,
4271 * so our viewport correction does not apply. Warning2: Even in windowed
4272 * mode the coords are relative to the window, not the screen. */
4274 if (!context->render_offscreen)
4276 const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4277 unsigned int width;
4279 wined3d_rendertarget_view_get_drawable_size(target, context, &width, &height);
4282 if (gl_info->supported[ARB_VIEWPORT_ARRAY])
4284 GLint sr[4 * WINED3D_MAX_VIEWPORTS];
4285 unsigned int i, reset_count = 0;
4287 for (i = 0; i < state->scissor_rect_count; ++i)
4289 r = &state->scissor_rects[i];
4291 sr[i * 4] = r->left;
4292 sr[i * 4 + 1] = height ? height - r->top : r->top;
4293 sr[i * 4 + 2] = r->right - r->left;
4294 sr[i * 4 + 3] = r->bottom - r->top;
4297 if (context->scissor_rect_count > state->scissor_rect_count)
4298 reset_count = context->scissor_rect_count - state->scissor_rect_count;
4300 if (reset_count)
4301 memset(&sr[state->scissor_rect_count * 4], 0, reset_count * 4 * sizeof(GLint));
4303 GL_EXTCALL(glScissorArrayv(0, state->scissor_rect_count + reset_count, sr));
4304 checkGLcall("glScissorArrayv");
4305 context->scissor_rect_count = state->scissor_rect_count;
4307 else
4309 r = &state->scissor_rects[0];
4310 gl_info->gl_ops.gl.p_glScissor(r->left, height ? height - r->top : r->top,
4311 r->right - r->left, r->bottom - r->top);
4312 checkGLcall("glScissor");
4316 static void indexbuffer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4318 const struct wined3d_stream_info *stream_info = &context->stream_info;
4319 const struct wined3d_gl_info *gl_info = context->gl_info;
4321 if (!state->index_buffer || !stream_info->all_vbo)
4323 GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
4325 else
4327 struct wined3d_buffer_gl *ib = wined3d_buffer_gl(state->index_buffer);
4328 GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib->buffer_object));
4332 static void depth_clip(const struct wined3d_rasterizer_state *r, const struct wined3d_gl_info *gl_info)
4334 if (!gl_info->supported[ARB_DEPTH_CLAMP])
4336 if (r && !r->desc.depth_clip)
4337 FIXME("Depth clamp not supported by this GL implementation.\n");
4338 return;
4341 if (r && !r->desc.depth_clip)
4342 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_CLAMP);
4343 else
4344 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_CLAMP);
4345 checkGLcall("depth clip");
4348 static void rasterizer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4350 const struct wined3d_gl_info *gl_info = context->gl_info;
4351 GLenum mode;
4353 mode = state->rasterizer_state && state->rasterizer_state->desc.front_ccw ? GL_CCW : GL_CW;
4354 if (context->render_offscreen)
4355 mode = (mode == GL_CW) ? GL_CCW : GL_CW;
4357 gl_info->gl_ops.gl.p_glFrontFace(mode);
4358 checkGLcall("glFrontFace");
4359 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_DEPTHBIAS)))
4360 state_depthbias(context, state, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
4361 depth_clip(state->rasterizer_state, gl_info);
4364 static void rasterizer_cc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4366 const struct wined3d_gl_info *gl_info = context->gl_info;
4367 GLenum mode;
4369 mode = state->rasterizer_state && state->rasterizer_state->desc.front_ccw ? GL_CCW : GL_CW;
4371 gl_info->gl_ops.gl.p_glFrontFace(mode);
4372 checkGLcall("glFrontFace");
4373 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_DEPTHBIAS)))
4374 state_depthbias(context, state, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
4375 depth_clip(state->rasterizer_state, gl_info);
4378 static void psorigin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4380 static BOOL warned;
4382 if (!warned)
4384 WARN("Point sprite coordinate origin switching not supported.\n");
4385 warned = TRUE;
4389 static void psorigin(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4391 const struct wined3d_gl_info *gl_info = context->gl_info;
4392 GLint origin = context->render_offscreen ? GL_LOWER_LEFT : GL_UPPER_LEFT;
4394 GL_EXTCALL(glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, origin));
4395 checkGLcall("glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, ...)");
4398 void state_srgbwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4400 const struct wined3d_gl_info *gl_info = context->gl_info;
4402 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4404 if (needs_srgb_write(context, state, state->fb))
4405 gl_info->gl_ops.gl.p_glEnable(GL_FRAMEBUFFER_SRGB);
4406 else
4407 gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB);
4410 static void state_cb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4412 const struct wined3d_gl_info *gl_info = context->gl_info;
4413 enum wined3d_shader_type shader_type;
4414 struct wined3d_buffer *buffer;
4415 unsigned int i, base, count;
4417 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4419 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state_id))
4420 shader_type = state_id - STATE_GRAPHICS_CONSTANT_BUFFER(0);
4421 else
4422 shader_type = WINED3D_SHADER_TYPE_COMPUTE;
4424 wined3d_gl_limits_get_uniform_block_range(&gl_info->limits, shader_type, &base, &count);
4425 for (i = 0; i < count; ++i)
4427 buffer = state->cb[shader_type][i];
4428 GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i,
4429 buffer ? wined3d_buffer_gl(buffer)->buffer_object : 0));
4431 checkGLcall("bind constant buffers");
4434 static void state_cb_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4436 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4438 WARN("Constant buffers (%s) no supported.\n", debug_d3dstate(state_id));
4441 static void state_shader_resource_binding(struct wined3d_context *context,
4442 const struct wined3d_state *state, DWORD state_id)
4444 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4446 context->update_shader_resource_bindings = 1;
4449 static void state_cs_resource_binding(struct wined3d_context *context,
4450 const struct wined3d_state *state, DWORD state_id)
4452 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4453 context->update_compute_shader_resource_bindings = 1;
4456 static void state_uav_binding(struct wined3d_context *context,
4457 const struct wined3d_state *state, DWORD state_id)
4459 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4460 context->update_unordered_access_view_bindings = 1;
4463 static void state_cs_uav_binding(struct wined3d_context *context,
4464 const struct wined3d_state *state, DWORD state_id)
4466 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4467 context->update_compute_unordered_access_view_bindings = 1;
4470 static void state_uav_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4472 WARN("ARB_image_load_store is not supported by OpenGL implementation.\n");
4475 static void state_so(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4477 const struct wined3d_gl_info *gl_info = context->gl_info;
4478 struct wined3d_buffer *buffer;
4479 unsigned int offset, size, i;
4481 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4483 context_end_transform_feedback(context);
4485 for (i = 0; i < ARRAY_SIZE(state->stream_output); ++i)
4487 if (!(buffer = state->stream_output[i].buffer))
4489 GL_EXTCALL(glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, i, 0));
4490 continue;
4493 offset = state->stream_output[i].offset;
4494 if (offset == ~0u)
4496 FIXME("Appending to stream output buffers not implemented.\n");
4497 offset = 0;
4499 size = buffer->resource.size - offset;
4500 GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i,
4501 wined3d_buffer_gl(buffer)->buffer_object, offset, size));
4503 checkGLcall("bind transform feedback buffers");
4506 static void state_so_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4508 WARN("Transform feedback not supported.\n");
4511 const struct StateEntryTemplate misc_state_template[] =
4513 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
4514 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), state_cb_warn, }, WINED3D_GL_EXT_NONE },
4515 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
4516 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), state_cb_warn, }, WINED3D_GL_EXT_NONE },
4517 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
4518 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), state_cb_warn, }, WINED3D_GL_EXT_NONE },
4519 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
4520 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb_warn, }, WINED3D_GL_EXT_NONE },
4521 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
4522 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), state_cb_warn, }, WINED3D_GL_EXT_NONE },
4523 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
4524 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), state_cb_warn, }, WINED3D_GL_EXT_NONE },
4525 { STATE_GRAPHICS_SHADER_RESOURCE_BINDING, { STATE_GRAPHICS_SHADER_RESOURCE_BINDING, state_shader_resource_binding}, WINED3D_GL_EXT_NONE },
4526 { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, state_uav_binding }, ARB_SHADER_IMAGE_LOAD_STORE },
4527 { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, state_uav_warn }, WINED3D_GL_EXT_NONE },
4528 { STATE_COMPUTE_SHADER_RESOURCE_BINDING, { STATE_COMPUTE_SHADER_RESOURCE_BINDING, state_cs_resource_binding}, WINED3D_GL_EXT_NONE },
4529 { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, state_cs_uav_binding}, ARB_SHADER_IMAGE_LOAD_STORE },
4530 { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, state_uav_warn }, WINED3D_GL_EXT_NONE },
4531 { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so, }, WINED3D_GL_VERSION_3_2 },
4532 { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so_warn, }, WINED3D_GL_EXT_NONE },
4533 { STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4534 { STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4535 { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), state_blend }, WINED3D_GL_EXT_NONE },
4536 { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), state_line_antialias}, WINED3D_GL_EXT_NONE },
4537 { STATE_RENDER(WINED3D_RS_ANTIALIASEDLINEENABLE), { STATE_RENDER(WINED3D_RS_ANTIALIASEDLINEENABLE), state_line_antialias}, WINED3D_GL_EXT_NONE },
4538 { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4539 { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4540 { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4541 { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4542 { STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
4543 { STATE_BLEND, { STATE_BLEND, state_blend_object }, WINED3D_GL_EXT_NONE },
4544 { STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor }, EXT_BLEND_COLOR },
4545 { STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor_w}, WINED3D_GL_EXT_NONE },
4546 { STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE },
4547 { STATE_VDECL, { STATE_VDECL, vdecl_miscpart }, WINED3D_GL_EXT_NONE },
4548 { STATE_RASTERIZER, { STATE_RASTERIZER, rasterizer_cc }, ARB_CLIP_CONTROL },
4549 { STATE_RASTERIZER, { STATE_RASTERIZER, rasterizer }, WINED3D_GL_EXT_NONE },
4550 { STATE_SCISSORRECT, { STATE_SCISSORRECT, scissorrect }, WINED3D_GL_EXT_NONE },
4551 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, state_nop }, ARB_CLIP_CONTROL },
4552 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin }, WINED3D_GL_VERSION_2_0 },
4553 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin_w }, WINED3D_GL_EXT_NONE },
4555 /* TODO: Move shader constant loading to vertex and fragment pipeline respectively, as soon as the pshader and
4556 * vshader loadings are untied from each other
4558 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4559 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4560 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4561 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4562 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4563 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4564 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4565 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4566 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4567 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4568 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4569 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4570 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4571 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4572 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4573 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4574 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4575 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4576 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4577 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4578 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4579 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4580 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4581 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4582 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4583 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4584 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4585 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4586 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4587 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4588 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4589 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
4590 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4591 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4592 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4593 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4594 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4595 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4596 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4597 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4598 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4599 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4600 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4601 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4602 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4603 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4604 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
4605 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
4607 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_miscpart_cc}, ARB_CLIP_CONTROL },
4608 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_miscpart }, WINED3D_GL_EXT_NONE },
4609 { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, indexbuffer }, ARB_VERTEX_BUFFER_OBJECT },
4610 { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, state_nop }, WINED3D_GL_EXT_NONE },
4611 { STATE_RENDER(WINED3D_RS_ANTIALIAS), { STATE_RENDER(WINED3D_RS_ANTIALIAS), state_antialias }, WINED3D_GL_EXT_NONE },
4612 { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), state_nop }, WINED3D_GL_EXT_NONE },
4613 { STATE_RENDER(WINED3D_RS_ZENABLE), { STATE_RENDER(WINED3D_RS_ZENABLE), state_zenable }, WINED3D_GL_EXT_NONE },
4614 { STATE_RENDER(WINED3D_RS_WRAPU), { STATE_RENDER(WINED3D_RS_WRAPU), state_wrapu }, WINED3D_GL_EXT_NONE },
4615 { STATE_RENDER(WINED3D_RS_WRAPV), { STATE_RENDER(WINED3D_RS_WRAPV), state_wrapv }, WINED3D_GL_EXT_NONE },
4616 { STATE_RENDER(WINED3D_RS_FILLMODE), { STATE_RENDER(WINED3D_RS_FILLMODE), state_fillmode }, WINED3D_GL_EXT_NONE },
4617 { STATE_RENDER(WINED3D_RS_LINEPATTERN), { STATE_RENDER(WINED3D_RS_LINEPATTERN), state_linepattern }, WINED3D_GL_LEGACY_CONTEXT },
4618 { STATE_RENDER(WINED3D_RS_LINEPATTERN), { STATE_RENDER(WINED3D_RS_LINEPATTERN), state_linepattern_w }, WINED3D_GL_EXT_NONE },
4619 { STATE_RENDER(WINED3D_RS_MONOENABLE), { STATE_RENDER(WINED3D_RS_MONOENABLE), state_monoenable }, WINED3D_GL_EXT_NONE },
4620 { STATE_RENDER(WINED3D_RS_ROP2), { STATE_RENDER(WINED3D_RS_ROP2), state_rop2 }, WINED3D_GL_EXT_NONE },
4621 { STATE_RENDER(WINED3D_RS_PLANEMASK), { STATE_RENDER(WINED3D_RS_PLANEMASK), state_planemask }, WINED3D_GL_EXT_NONE },
4622 { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), state_zwriteenable }, WINED3D_GL_EXT_NONE },
4623 { STATE_RENDER(WINED3D_RS_LASTPIXEL), { STATE_RENDER(WINED3D_RS_LASTPIXEL), state_lastpixel }, WINED3D_GL_EXT_NONE },
4624 { STATE_RENDER(WINED3D_RS_CULLMODE), { STATE_RENDER(WINED3D_RS_CULLMODE), state_cullmode }, WINED3D_GL_EXT_NONE },
4625 { STATE_RENDER(WINED3D_RS_ZFUNC), { STATE_RENDER(WINED3D_RS_ZFUNC), state_zfunc }, WINED3D_GL_EXT_NONE },
4626 { STATE_RENDER(WINED3D_RS_DITHERENABLE), { STATE_RENDER(WINED3D_RS_DITHERENABLE), state_ditherenable }, WINED3D_GL_EXT_NONE },
4627 { STATE_RENDER(WINED3D_RS_SUBPIXEL), { STATE_RENDER(WINED3D_RS_SUBPIXEL), state_subpixel }, WINED3D_GL_EXT_NONE },
4628 { STATE_RENDER(WINED3D_RS_SUBPIXELX), { STATE_RENDER(WINED3D_RS_SUBPIXELX), state_subpixelx }, WINED3D_GL_EXT_NONE },
4629 { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), state_stippledalpha }, WINED3D_GL_EXT_NONE },
4630 { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), state_stippleenable }, WINED3D_GL_EXT_NONE },
4631 { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), state_mipmaplodbias }, WINED3D_GL_EXT_NONE },
4632 { STATE_RENDER(WINED3D_RS_ANISOTROPY), { STATE_RENDER(WINED3D_RS_ANISOTROPY), state_anisotropy }, WINED3D_GL_EXT_NONE },
4633 { STATE_RENDER(WINED3D_RS_FLUSHBATCH), { STATE_RENDER(WINED3D_RS_FLUSHBATCH), state_flushbatch }, WINED3D_GL_EXT_NONE },
4634 { STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),{ STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),state_translucentsi }, WINED3D_GL_EXT_NONE },
4635 { STATE_RENDER(WINED3D_RS_STENCILENABLE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), state_stencil }, WINED3D_GL_EXT_NONE },
4636 { STATE_RENDER(WINED3D_RS_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4637 { STATE_RENDER(WINED3D_RS_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4638 { STATE_RENDER(WINED3D_RS_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4639 { STATE_RENDER(WINED3D_RS_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4640 { STATE_RENDER(WINED3D_RS_STENCILREF), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4641 { STATE_RENDER(WINED3D_RS_STENCILMASK), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4642 { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite2s_ext}, EXT_STENCIL_TWO_SIDE },
4643 { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite }, WINED3D_GL_EXT_NONE },
4644 { STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4645 { STATE_RENDER(WINED3D_RS_BACK_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4646 { STATE_RENDER(WINED3D_RS_BACK_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4647 { STATE_RENDER(WINED3D_RS_BACK_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4648 { STATE_RENDER(WINED3D_RS_BACK_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
4649 { STATE_RENDER(WINED3D_RS_WRAP0), { STATE_RENDER(WINED3D_RS_WRAP0), state_wrap }, WINED3D_GL_EXT_NONE },
4650 { STATE_RENDER(WINED3D_RS_WRAP1), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4651 { STATE_RENDER(WINED3D_RS_WRAP2), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4652 { STATE_RENDER(WINED3D_RS_WRAP3), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4653 { STATE_RENDER(WINED3D_RS_WRAP4), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4654 { STATE_RENDER(WINED3D_RS_WRAP5), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4655 { STATE_RENDER(WINED3D_RS_WRAP6), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4656 { STATE_RENDER(WINED3D_RS_WRAP7), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4657 { STATE_RENDER(WINED3D_RS_WRAP8), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4658 { STATE_RENDER(WINED3D_RS_WRAP9), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4659 { STATE_RENDER(WINED3D_RS_WRAP10), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4660 { STATE_RENDER(WINED3D_RS_WRAP11), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4661 { STATE_RENDER(WINED3D_RS_WRAP12), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4662 { STATE_RENDER(WINED3D_RS_WRAP13), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4663 { STATE_RENDER(WINED3D_RS_WRAP14), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4664 { STATE_RENDER(WINED3D_RS_WRAP15), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
4665 { STATE_RENDER(WINED3D_RS_EXTENTS), { STATE_RENDER(WINED3D_RS_EXTENTS), state_extents }, WINED3D_GL_EXT_NONE },
4666 { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), state_ckeyblend }, WINED3D_GL_EXT_NONE },
4667 { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), state_swvp }, WINED3D_GL_EXT_NONE },
4668 { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), state_patchedgestyle}, WINED3D_GL_EXT_NONE },
4669 { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), state_patchsegments }, WINED3D_GL_EXT_NONE },
4670 { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), state_positiondegree}, WINED3D_GL_EXT_NONE },
4671 { STATE_RENDER(WINED3D_RS_NORMALDEGREE), { STATE_RENDER(WINED3D_RS_NORMALDEGREE), state_normaldegree }, WINED3D_GL_EXT_NONE },
4672 { STATE_RENDER(WINED3D_RS_MINTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
4673 { STATE_RENDER(WINED3D_RS_MAXTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
4674 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_X), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
4675 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Y), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
4676 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Z), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
4677 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_W), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
4678 { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_nvdb }, EXT_DEPTH_BOUNDS_TEST },
4679 { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_tessellation }, WINED3D_GL_EXT_NONE },
4680 { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa }, ARB_MULTISAMPLE },
4681 { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa_w }, WINED3D_GL_EXT_NONE },
4682 { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), state_multisampmask }, WINED3D_GL_EXT_NONE },
4683 { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), state_debug_monitor }, WINED3D_GL_EXT_NONE },
4684 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite0 }, EXT_DRAW_BUFFERS2 },
4685 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite }, WINED3D_GL_EXT_NONE },
4686 { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop }, WINED3D_GL_BLEND_EQUATION },
4687 { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop_w }, WINED3D_GL_EXT_NONE },
4688 { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), state_scissor }, WINED3D_GL_EXT_NONE },
4689 { STATE_RENDER(WINED3D_RS_SLOPESCALEDEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), NULL }, WINED3D_GL_EXT_NONE },
4690 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), state_colorwrite1 }, EXT_DRAW_BUFFERS2 },
4691 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
4692 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), state_colorwrite2 }, EXT_DRAW_BUFFERS2 },
4693 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
4694 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), state_colorwrite3 }, EXT_DRAW_BUFFERS2 },
4695 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
4696 { STATE_RENDER(WINED3D_RS_DEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), state_depthbias }, WINED3D_GL_EXT_NONE },
4697 { STATE_RENDER(WINED3D_RS_ZVISIBLE), { STATE_RENDER(WINED3D_RS_ZVISIBLE), state_zvisible }, WINED3D_GL_EXT_NONE },
4698 /* Samplers */
4699 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler }, WINED3D_GL_EXT_NONE },
4700 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler }, WINED3D_GL_EXT_NONE },
4701 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler }, WINED3D_GL_EXT_NONE },
4702 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler }, WINED3D_GL_EXT_NONE },
4703 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler }, WINED3D_GL_EXT_NONE },
4704 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler }, WINED3D_GL_EXT_NONE },
4705 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler }, WINED3D_GL_EXT_NONE },
4706 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler }, WINED3D_GL_EXT_NONE },
4707 { STATE_SAMPLER(8), { STATE_SAMPLER(8), sampler }, WINED3D_GL_EXT_NONE },
4708 { STATE_SAMPLER(9), { STATE_SAMPLER(9), sampler }, WINED3D_GL_EXT_NONE },
4709 { STATE_SAMPLER(10), { STATE_SAMPLER(10), sampler }, WINED3D_GL_EXT_NONE },
4710 { STATE_SAMPLER(11), { STATE_SAMPLER(11), sampler }, WINED3D_GL_EXT_NONE },
4711 { STATE_SAMPLER(12), { STATE_SAMPLER(12), sampler }, WINED3D_GL_EXT_NONE },
4712 { STATE_SAMPLER(13), { STATE_SAMPLER(13), sampler }, WINED3D_GL_EXT_NONE },
4713 { STATE_SAMPLER(14), { STATE_SAMPLER(14), sampler }, WINED3D_GL_EXT_NONE },
4714 { STATE_SAMPLER(15), { STATE_SAMPLER(15), sampler }, WINED3D_GL_EXT_NONE },
4715 { STATE_SAMPLER(16), /* Vertex sampler 0 */ { STATE_SAMPLER(16), sampler }, WINED3D_GL_EXT_NONE },
4716 { STATE_SAMPLER(17), /* Vertex sampler 1 */ { STATE_SAMPLER(17), sampler }, WINED3D_GL_EXT_NONE },
4717 { STATE_SAMPLER(18), /* Vertex sampler 2 */ { STATE_SAMPLER(18), sampler }, WINED3D_GL_EXT_NONE },
4718 { STATE_SAMPLER(19), /* Vertex sampler 3 */ { STATE_SAMPLER(19), sampler }, WINED3D_GL_EXT_NONE },
4719 { STATE_BASEVERTEXINDEX, { STATE_BASEVERTEXINDEX, state_nop, }, ARB_DRAW_ELEMENTS_BASE_VERTEX },
4720 { STATE_BASEVERTEXINDEX, { STATE_STREAMSRC, NULL, }, WINED3D_GL_EXT_NONE },
4721 { STATE_FRAMEBUFFER, { STATE_FRAMEBUFFER, context_state_fb }, WINED3D_GL_EXT_NONE },
4722 { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), context_state_drawbuf},WINED3D_GL_EXT_NONE },
4723 { STATE_SHADER(WINED3D_SHADER_TYPE_HULL), { STATE_SHADER(WINED3D_SHADER_TYPE_HULL), state_shader }, WINED3D_GL_EXT_NONE },
4724 { STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN), { STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN), state_shader }, WINED3D_GL_EXT_NONE },
4725 { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY), { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY), state_shader }, WINED3D_GL_EXT_NONE },
4726 { STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE), { STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE), state_compute_shader}, WINED3D_GL_EXT_NONE },
4727 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
4730 static const struct StateEntryTemplate vp_ffp_states[] =
4732 { STATE_VDECL, { STATE_VDECL, vertexdeclaration }, WINED3D_GL_EXT_NONE },
4733 { STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX), { STATE_VDECL, NULL }, WINED3D_GL_EXT_NONE },
4734 { STATE_MATERIAL, { STATE_RENDER(WINED3D_RS_SPECULARENABLE), NULL }, WINED3D_GL_EXT_NONE },
4735 { STATE_RENDER(WINED3D_RS_SPECULARENABLE), { STATE_RENDER(WINED3D_RS_SPECULARENABLE), state_specularenable}, WINED3D_GL_EXT_NONE },
4736 /* Clip planes */
4737 { STATE_CLIPPLANE(0), { STATE_CLIPPLANE(0), clipplane }, WINED3D_GL_EXT_NONE },
4738 { STATE_CLIPPLANE(1), { STATE_CLIPPLANE(1), clipplane }, WINED3D_GL_EXT_NONE },
4739 { STATE_CLIPPLANE(2), { STATE_CLIPPLANE(2), clipplane }, WINED3D_GL_EXT_NONE },
4740 { STATE_CLIPPLANE(3), { STATE_CLIPPLANE(3), clipplane }, WINED3D_GL_EXT_NONE },
4741 { STATE_CLIPPLANE(4), { STATE_CLIPPLANE(4), clipplane }, WINED3D_GL_EXT_NONE },
4742 { STATE_CLIPPLANE(5), { STATE_CLIPPLANE(5), clipplane }, WINED3D_GL_EXT_NONE },
4743 { STATE_CLIPPLANE(6), { STATE_CLIPPLANE(6), clipplane }, WINED3D_GL_EXT_NONE },
4744 { STATE_CLIPPLANE(7), { STATE_CLIPPLANE(7), clipplane }, WINED3D_GL_EXT_NONE },
4745 /* Lights */
4746 { STATE_LIGHT_TYPE, { STATE_LIGHT_TYPE, state_nop }, WINED3D_GL_EXT_NONE },
4747 { STATE_ACTIVELIGHT(0), { STATE_ACTIVELIGHT(0), light }, WINED3D_GL_EXT_NONE },
4748 { STATE_ACTIVELIGHT(1), { STATE_ACTIVELIGHT(1), light }, WINED3D_GL_EXT_NONE },
4749 { STATE_ACTIVELIGHT(2), { STATE_ACTIVELIGHT(2), light }, WINED3D_GL_EXT_NONE },
4750 { STATE_ACTIVELIGHT(3), { STATE_ACTIVELIGHT(3), light }, WINED3D_GL_EXT_NONE },
4751 { STATE_ACTIVELIGHT(4), { STATE_ACTIVELIGHT(4), light }, WINED3D_GL_EXT_NONE },
4752 { STATE_ACTIVELIGHT(5), { STATE_ACTIVELIGHT(5), light }, WINED3D_GL_EXT_NONE },
4753 { STATE_ACTIVELIGHT(6), { STATE_ACTIVELIGHT(6), light }, WINED3D_GL_EXT_NONE },
4754 { STATE_ACTIVELIGHT(7), { STATE_ACTIVELIGHT(7), light }, WINED3D_GL_EXT_NONE },
4755 /* Viewport */
4756 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_vertexpart }, WINED3D_GL_EXT_NONE },
4757 /* Transform states follow */
4758 { STATE_TRANSFORM(WINED3D_TS_VIEW), { STATE_TRANSFORM(WINED3D_TS_VIEW), transform_view }, WINED3D_GL_EXT_NONE },
4759 { STATE_TRANSFORM(WINED3D_TS_PROJECTION), { STATE_TRANSFORM(WINED3D_TS_PROJECTION), transform_projection}, WINED3D_GL_EXT_NONE },
4760 { STATE_TRANSFORM(WINED3D_TS_TEXTURE0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4761 { STATE_TRANSFORM(WINED3D_TS_TEXTURE1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4762 { STATE_TRANSFORM(WINED3D_TS_TEXTURE2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4763 { STATE_TRANSFORM(WINED3D_TS_TEXTURE3), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4764 { STATE_TRANSFORM(WINED3D_TS_TEXTURE4), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4765 { STATE_TRANSFORM(WINED3D_TS_TEXTURE5), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4766 { STATE_TRANSFORM(WINED3D_TS_TEXTURE6), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4767 { STATE_TRANSFORM(WINED3D_TS_TEXTURE7), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
4768 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), transform_world }, WINED3D_GL_EXT_NONE },
4769 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), transform_worldex }, WINED3D_GL_EXT_NONE },
4770 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), transform_worldex }, WINED3D_GL_EXT_NONE },
4771 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), transform_worldex }, WINED3D_GL_EXT_NONE },
4772 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), transform_worldex }, WINED3D_GL_EXT_NONE },
4773 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), transform_worldex }, WINED3D_GL_EXT_NONE },
4774 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), transform_worldex }, WINED3D_GL_EXT_NONE },
4775 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), transform_worldex }, WINED3D_GL_EXT_NONE },
4776 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), transform_worldex }, WINED3D_GL_EXT_NONE },
4777 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), transform_worldex }, WINED3D_GL_EXT_NONE },
4778 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), transform_worldex }, WINED3D_GL_EXT_NONE },
4779 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), transform_worldex }, WINED3D_GL_EXT_NONE },
4780 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), transform_worldex }, WINED3D_GL_EXT_NONE },
4781 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), transform_worldex }, WINED3D_GL_EXT_NONE },
4782 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), transform_worldex }, WINED3D_GL_EXT_NONE },
4783 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), transform_worldex }, WINED3D_GL_EXT_NONE },
4784 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), transform_worldex }, WINED3D_GL_EXT_NONE },
4785 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), transform_worldex }, WINED3D_GL_EXT_NONE },
4786 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), transform_worldex }, WINED3D_GL_EXT_NONE },
4787 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), transform_worldex }, WINED3D_GL_EXT_NONE },
4788 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), transform_worldex }, WINED3D_GL_EXT_NONE },
4789 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), transform_worldex }, WINED3D_GL_EXT_NONE },
4790 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), transform_worldex }, WINED3D_GL_EXT_NONE },
4791 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), transform_worldex }, WINED3D_GL_EXT_NONE },
4792 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), transform_worldex }, WINED3D_GL_EXT_NONE },
4793 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), transform_worldex }, WINED3D_GL_EXT_NONE },
4794 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), transform_worldex }, WINED3D_GL_EXT_NONE },
4795 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), transform_worldex }, WINED3D_GL_EXT_NONE },
4796 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), transform_worldex }, WINED3D_GL_EXT_NONE },
4797 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), transform_worldex }, WINED3D_GL_EXT_NONE },
4798 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), transform_worldex }, WINED3D_GL_EXT_NONE },
4799 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), transform_worldex }, WINED3D_GL_EXT_NONE },
4800 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), transform_worldex }, WINED3D_GL_EXT_NONE },
4801 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), transform_worldex }, WINED3D_GL_EXT_NONE },
4802 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), transform_worldex }, WINED3D_GL_EXT_NONE },
4803 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), transform_worldex }, WINED3D_GL_EXT_NONE },
4804 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), transform_worldex }, WINED3D_GL_EXT_NONE },
4805 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), transform_worldex }, WINED3D_GL_EXT_NONE },
4806 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), transform_worldex }, WINED3D_GL_EXT_NONE },
4807 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), transform_worldex }, WINED3D_GL_EXT_NONE },
4808 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), transform_worldex }, WINED3D_GL_EXT_NONE },
4809 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), transform_worldex }, WINED3D_GL_EXT_NONE },
4810 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), transform_worldex }, WINED3D_GL_EXT_NONE },
4811 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), transform_worldex }, WINED3D_GL_EXT_NONE },
4812 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), transform_worldex }, WINED3D_GL_EXT_NONE },
4813 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), transform_worldex }, WINED3D_GL_EXT_NONE },
4814 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), transform_worldex }, WINED3D_GL_EXT_NONE },
4815 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), transform_worldex }, WINED3D_GL_EXT_NONE },
4816 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), transform_worldex }, WINED3D_GL_EXT_NONE },
4817 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), transform_worldex }, WINED3D_GL_EXT_NONE },
4818 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), transform_worldex }, WINED3D_GL_EXT_NONE },
4819 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), transform_worldex }, WINED3D_GL_EXT_NONE },
4820 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), transform_worldex }, WINED3D_GL_EXT_NONE },
4821 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), transform_worldex }, WINED3D_GL_EXT_NONE },
4822 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), transform_worldex }, WINED3D_GL_EXT_NONE },
4823 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), transform_worldex }, WINED3D_GL_EXT_NONE },
4824 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), transform_worldex }, WINED3D_GL_EXT_NONE },
4825 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), transform_worldex }, WINED3D_GL_EXT_NONE },
4826 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), transform_worldex }, WINED3D_GL_EXT_NONE },
4827 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), transform_worldex }, WINED3D_GL_EXT_NONE },
4828 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), transform_worldex }, WINED3D_GL_EXT_NONE },
4829 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), transform_worldex }, WINED3D_GL_EXT_NONE },
4830 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), transform_worldex }, WINED3D_GL_EXT_NONE },
4831 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), transform_worldex }, WINED3D_GL_EXT_NONE },
4832 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), transform_worldex }, WINED3D_GL_EXT_NONE },
4833 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), transform_worldex }, WINED3D_GL_EXT_NONE },
4834 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), transform_worldex }, WINED3D_GL_EXT_NONE },
4835 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), transform_worldex }, WINED3D_GL_EXT_NONE },
4836 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), transform_worldex }, WINED3D_GL_EXT_NONE },
4837 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), transform_worldex }, WINED3D_GL_EXT_NONE },
4838 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), transform_worldex }, WINED3D_GL_EXT_NONE },
4839 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), transform_worldex }, WINED3D_GL_EXT_NONE },
4840 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), transform_worldex }, WINED3D_GL_EXT_NONE },
4841 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), transform_worldex }, WINED3D_GL_EXT_NONE },
4842 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), transform_worldex }, WINED3D_GL_EXT_NONE },
4843 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), transform_worldex }, WINED3D_GL_EXT_NONE },
4844 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), transform_worldex }, WINED3D_GL_EXT_NONE },
4845 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), transform_worldex }, WINED3D_GL_EXT_NONE },
4846 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), transform_worldex }, WINED3D_GL_EXT_NONE },
4847 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), transform_worldex }, WINED3D_GL_EXT_NONE },
4848 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), transform_worldex }, WINED3D_GL_EXT_NONE },
4849 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), transform_worldex }, WINED3D_GL_EXT_NONE },
4850 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), transform_worldex }, WINED3D_GL_EXT_NONE },
4851 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), transform_worldex }, WINED3D_GL_EXT_NONE },
4852 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), transform_worldex }, WINED3D_GL_EXT_NONE },
4853 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), transform_worldex }, WINED3D_GL_EXT_NONE },
4854 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), transform_worldex }, WINED3D_GL_EXT_NONE },
4855 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), transform_worldex }, WINED3D_GL_EXT_NONE },
4856 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), transform_worldex }, WINED3D_GL_EXT_NONE },
4857 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), transform_worldex }, WINED3D_GL_EXT_NONE },
4858 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), transform_worldex }, WINED3D_GL_EXT_NONE },
4859 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), transform_worldex }, WINED3D_GL_EXT_NONE },
4860 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), transform_worldex }, WINED3D_GL_EXT_NONE },
4861 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), transform_worldex }, WINED3D_GL_EXT_NONE },
4862 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), transform_worldex }, WINED3D_GL_EXT_NONE },
4863 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), transform_worldex }, WINED3D_GL_EXT_NONE },
4864 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), transform_worldex }, WINED3D_GL_EXT_NONE },
4865 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), transform_worldex }, WINED3D_GL_EXT_NONE },
4866 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), transform_worldex }, WINED3D_GL_EXT_NONE },
4867 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), transform_worldex }, WINED3D_GL_EXT_NONE },
4868 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), transform_worldex }, WINED3D_GL_EXT_NONE },
4869 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), transform_worldex }, WINED3D_GL_EXT_NONE },
4870 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), transform_worldex }, WINED3D_GL_EXT_NONE },
4871 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), transform_worldex }, WINED3D_GL_EXT_NONE },
4872 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), transform_worldex }, WINED3D_GL_EXT_NONE },
4873 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), transform_worldex }, WINED3D_GL_EXT_NONE },
4874 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), transform_worldex }, WINED3D_GL_EXT_NONE },
4875 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), transform_worldex }, WINED3D_GL_EXT_NONE },
4876 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), transform_worldex }, WINED3D_GL_EXT_NONE },
4877 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), transform_worldex }, WINED3D_GL_EXT_NONE },
4878 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), transform_worldex }, WINED3D_GL_EXT_NONE },
4879 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), transform_worldex }, WINED3D_GL_EXT_NONE },
4880 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), transform_worldex }, WINED3D_GL_EXT_NONE },
4881 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), transform_worldex }, WINED3D_GL_EXT_NONE },
4882 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), transform_worldex }, WINED3D_GL_EXT_NONE },
4883 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), transform_worldex }, WINED3D_GL_EXT_NONE },
4884 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), transform_worldex }, WINED3D_GL_EXT_NONE },
4885 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), transform_worldex }, WINED3D_GL_EXT_NONE },
4886 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), transform_worldex }, WINED3D_GL_EXT_NONE },
4887 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), transform_worldex }, WINED3D_GL_EXT_NONE },
4888 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), transform_worldex }, WINED3D_GL_EXT_NONE },
4889 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), transform_worldex }, WINED3D_GL_EXT_NONE },
4890 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), transform_worldex }, WINED3D_GL_EXT_NONE },
4891 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), transform_worldex }, WINED3D_GL_EXT_NONE },
4892 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), transform_worldex }, WINED3D_GL_EXT_NONE },
4893 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), transform_worldex }, WINED3D_GL_EXT_NONE },
4894 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), transform_worldex }, WINED3D_GL_EXT_NONE },
4895 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), transform_worldex }, WINED3D_GL_EXT_NONE },
4896 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), transform_worldex }, WINED3D_GL_EXT_NONE },
4897 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), transform_worldex }, WINED3D_GL_EXT_NONE },
4898 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), transform_worldex }, WINED3D_GL_EXT_NONE },
4899 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), transform_worldex }, WINED3D_GL_EXT_NONE },
4900 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), transform_worldex }, WINED3D_GL_EXT_NONE },
4901 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), transform_worldex }, WINED3D_GL_EXT_NONE },
4902 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), transform_worldex }, WINED3D_GL_EXT_NONE },
4903 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), transform_worldex }, WINED3D_GL_EXT_NONE },
4904 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), transform_worldex }, WINED3D_GL_EXT_NONE },
4905 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), transform_worldex }, WINED3D_GL_EXT_NONE },
4906 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), transform_worldex }, WINED3D_GL_EXT_NONE },
4907 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), transform_worldex }, WINED3D_GL_EXT_NONE },
4908 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), transform_worldex }, WINED3D_GL_EXT_NONE },
4909 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), transform_worldex }, WINED3D_GL_EXT_NONE },
4910 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), transform_worldex }, WINED3D_GL_EXT_NONE },
4911 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), transform_worldex }, WINED3D_GL_EXT_NONE },
4912 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), transform_worldex }, WINED3D_GL_EXT_NONE },
4913 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), transform_worldex }, WINED3D_GL_EXT_NONE },
4914 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), transform_worldex }, WINED3D_GL_EXT_NONE },
4915 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), transform_worldex }, WINED3D_GL_EXT_NONE },
4916 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), transform_worldex }, WINED3D_GL_EXT_NONE },
4917 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), transform_worldex }, WINED3D_GL_EXT_NONE },
4918 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), transform_worldex }, WINED3D_GL_EXT_NONE },
4919 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), transform_worldex }, WINED3D_GL_EXT_NONE },
4920 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), transform_worldex }, WINED3D_GL_EXT_NONE },
4921 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), transform_worldex }, WINED3D_GL_EXT_NONE },
4922 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), transform_worldex }, WINED3D_GL_EXT_NONE },
4923 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), transform_worldex }, WINED3D_GL_EXT_NONE },
4924 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), transform_worldex }, WINED3D_GL_EXT_NONE },
4925 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), transform_worldex }, WINED3D_GL_EXT_NONE },
4926 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), transform_worldex }, WINED3D_GL_EXT_NONE },
4927 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), transform_worldex }, WINED3D_GL_EXT_NONE },
4928 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), transform_worldex }, WINED3D_GL_EXT_NONE },
4929 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), transform_worldex }, WINED3D_GL_EXT_NONE },
4930 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), transform_worldex }, WINED3D_GL_EXT_NONE },
4931 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), transform_worldex }, WINED3D_GL_EXT_NONE },
4932 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), transform_worldex }, WINED3D_GL_EXT_NONE },
4933 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), transform_worldex }, WINED3D_GL_EXT_NONE },
4934 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), transform_worldex }, WINED3D_GL_EXT_NONE },
4935 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), transform_worldex }, WINED3D_GL_EXT_NONE },
4936 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), transform_worldex }, WINED3D_GL_EXT_NONE },
4937 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), transform_worldex }, WINED3D_GL_EXT_NONE },
4938 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), transform_worldex }, WINED3D_GL_EXT_NONE },
4939 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), transform_worldex }, WINED3D_GL_EXT_NONE },
4940 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), transform_worldex }, WINED3D_GL_EXT_NONE },
4941 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), transform_worldex }, WINED3D_GL_EXT_NONE },
4942 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), transform_worldex }, WINED3D_GL_EXT_NONE },
4943 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), transform_worldex }, WINED3D_GL_EXT_NONE },
4944 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), transform_worldex }, WINED3D_GL_EXT_NONE },
4945 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), transform_worldex }, WINED3D_GL_EXT_NONE },
4946 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), transform_worldex }, WINED3D_GL_EXT_NONE },
4947 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), transform_worldex }, WINED3D_GL_EXT_NONE },
4948 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), transform_worldex }, WINED3D_GL_EXT_NONE },
4949 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), transform_worldex }, WINED3D_GL_EXT_NONE },
4950 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), transform_worldex }, WINED3D_GL_EXT_NONE },
4951 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), transform_worldex }, WINED3D_GL_EXT_NONE },
4952 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), transform_worldex }, WINED3D_GL_EXT_NONE },
4953 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), transform_worldex }, WINED3D_GL_EXT_NONE },
4954 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), transform_worldex }, WINED3D_GL_EXT_NONE },
4955 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), transform_worldex }, WINED3D_GL_EXT_NONE },
4956 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), transform_worldex }, WINED3D_GL_EXT_NONE },
4957 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), transform_worldex }, WINED3D_GL_EXT_NONE },
4958 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), transform_worldex }, WINED3D_GL_EXT_NONE },
4959 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), transform_worldex }, WINED3D_GL_EXT_NONE },
4960 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), transform_worldex }, WINED3D_GL_EXT_NONE },
4961 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), transform_worldex }, WINED3D_GL_EXT_NONE },
4962 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), transform_worldex }, WINED3D_GL_EXT_NONE },
4963 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), transform_worldex }, WINED3D_GL_EXT_NONE },
4964 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), transform_worldex }, WINED3D_GL_EXT_NONE },
4965 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), transform_worldex }, WINED3D_GL_EXT_NONE },
4966 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), transform_worldex }, WINED3D_GL_EXT_NONE },
4967 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), transform_worldex }, WINED3D_GL_EXT_NONE },
4968 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), transform_worldex }, WINED3D_GL_EXT_NONE },
4969 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), transform_worldex }, WINED3D_GL_EXT_NONE },
4970 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), transform_worldex }, WINED3D_GL_EXT_NONE },
4971 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), transform_worldex }, WINED3D_GL_EXT_NONE },
4972 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), transform_worldex }, WINED3D_GL_EXT_NONE },
4973 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), transform_worldex }, WINED3D_GL_EXT_NONE },
4974 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), transform_worldex }, WINED3D_GL_EXT_NONE },
4975 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), transform_worldex }, WINED3D_GL_EXT_NONE },
4976 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), transform_worldex }, WINED3D_GL_EXT_NONE },
4977 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), transform_worldex }, WINED3D_GL_EXT_NONE },
4978 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), transform_worldex }, WINED3D_GL_EXT_NONE },
4979 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), transform_worldex }, WINED3D_GL_EXT_NONE },
4980 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), transform_worldex }, WINED3D_GL_EXT_NONE },
4981 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), transform_worldex }, WINED3D_GL_EXT_NONE },
4982 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), transform_worldex }, WINED3D_GL_EXT_NONE },
4983 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), transform_worldex }, WINED3D_GL_EXT_NONE },
4984 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), transform_worldex }, WINED3D_GL_EXT_NONE },
4985 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), transform_worldex }, WINED3D_GL_EXT_NONE },
4986 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), transform_worldex }, WINED3D_GL_EXT_NONE },
4987 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), transform_worldex }, WINED3D_GL_EXT_NONE },
4988 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), transform_worldex }, WINED3D_GL_EXT_NONE },
4989 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), transform_worldex }, WINED3D_GL_EXT_NONE },
4990 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), transform_worldex }, WINED3D_GL_EXT_NONE },
4991 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), transform_worldex }, WINED3D_GL_EXT_NONE },
4992 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), transform_worldex }, WINED3D_GL_EXT_NONE },
4993 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), transform_worldex }, WINED3D_GL_EXT_NONE },
4994 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), transform_worldex }, WINED3D_GL_EXT_NONE },
4995 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), transform_worldex }, WINED3D_GL_EXT_NONE },
4996 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), transform_worldex }, WINED3D_GL_EXT_NONE },
4997 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), transform_worldex }, WINED3D_GL_EXT_NONE },
4998 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), transform_worldex }, WINED3D_GL_EXT_NONE },
4999 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), transform_worldex }, WINED3D_GL_EXT_NONE },
5000 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), transform_worldex }, WINED3D_GL_EXT_NONE },
5001 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), transform_worldex }, WINED3D_GL_EXT_NONE },
5002 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), transform_worldex }, WINED3D_GL_EXT_NONE },
5003 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), transform_worldex }, WINED3D_GL_EXT_NONE },
5004 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), transform_worldex }, WINED3D_GL_EXT_NONE },
5005 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), transform_worldex }, WINED3D_GL_EXT_NONE },
5006 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), transform_worldex }, WINED3D_GL_EXT_NONE },
5007 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), transform_worldex }, WINED3D_GL_EXT_NONE },
5008 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), transform_worldex }, WINED3D_GL_EXT_NONE },
5009 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), transform_worldex }, WINED3D_GL_EXT_NONE },
5010 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), transform_worldex }, WINED3D_GL_EXT_NONE },
5011 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), transform_worldex }, WINED3D_GL_EXT_NONE },
5012 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), transform_worldex }, WINED3D_GL_EXT_NONE },
5013 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), transform_worldex }, WINED3D_GL_EXT_NONE },
5014 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), transform_worldex }, WINED3D_GL_EXT_NONE },
5015 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), transform_worldex }, WINED3D_GL_EXT_NONE },
5016 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), transform_worldex }, WINED3D_GL_EXT_NONE },
5017 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), transform_worldex }, WINED3D_GL_EXT_NONE },
5018 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), transform_worldex }, WINED3D_GL_EXT_NONE },
5019 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), transform_worldex }, WINED3D_GL_EXT_NONE },
5020 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), transform_worldex }, WINED3D_GL_EXT_NONE },
5021 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), transform_worldex }, WINED3D_GL_EXT_NONE },
5022 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), transform_worldex }, WINED3D_GL_EXT_NONE },
5023 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), transform_worldex }, WINED3D_GL_EXT_NONE },
5024 { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5025 { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5026 { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5027 { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5028 { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5029 { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5030 { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5031 { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5032 { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5033 { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5034 { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5035 { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5036 { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5037 { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5038 { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5039 { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5040 /* Fog */
5041 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_vertexpart}, WINED3D_GL_EXT_NONE },
5042 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5043 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5044 { STATE_RENDER(WINED3D_RS_RANGEFOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5045 { STATE_RENDER(WINED3D_RS_CLIPPING), { STATE_RENDER(WINED3D_RS_CLIPPING), state_clipping }, WINED3D_GL_EXT_NONE },
5046 { STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE), { STATE_RENDER(WINED3D_RS_CLIPPING), NULL }, WINED3D_GL_EXT_NONE },
5047 { STATE_RENDER(WINED3D_RS_LIGHTING), { STATE_RENDER(WINED3D_RS_LIGHTING), state_lighting }, WINED3D_GL_EXT_NONE },
5048 { STATE_RENDER(WINED3D_RS_AMBIENT), { STATE_RENDER(WINED3D_RS_AMBIENT), state_ambient }, WINED3D_GL_EXT_NONE },
5049 { STATE_RENDER(WINED3D_RS_COLORVERTEX), { STATE_RENDER(WINED3D_RS_COLORVERTEX), state_colormat }, WINED3D_GL_EXT_NONE },
5050 { STATE_RENDER(WINED3D_RS_LOCALVIEWER), { STATE_RENDER(WINED3D_RS_LOCALVIEWER), state_localviewer }, WINED3D_GL_EXT_NONE },
5051 { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), state_normalize }, WINED3D_GL_EXT_NONE },
5052 { STATE_RENDER(WINED3D_RS_DIFFUSEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5053 { STATE_RENDER(WINED3D_RS_SPECULARMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5054 { STATE_RENDER(WINED3D_RS_AMBIENTMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5055 { STATE_RENDER(WINED3D_RS_EMISSIVEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5056 { STATE_RENDER(WINED3D_RS_VERTEXBLEND), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), state_vertexblend_w }, WINED3D_GL_EXT_NONE },
5057 { STATE_RENDER(WINED3D_RS_POINTSIZE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5058 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_arb }, ARB_POINT_PARAMETERS },
5059 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_ext }, EXT_POINT_PARAMETERS },
5060 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_w }, WINED3D_GL_EXT_NONE },
5061 { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite }, ARB_POINT_SPRITE },
5062 { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite_w }, WINED3D_GL_EXT_NONE },
5063 { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), state_pscale }, WINED3D_GL_EXT_NONE },
5064 { STATE_RENDER(WINED3D_RS_POINTSCALE_A), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5065 { STATE_RENDER(WINED3D_RS_POINTSCALE_B), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5066 { STATE_RENDER(WINED3D_RS_POINTSCALE_C), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5067 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, ARB_POINT_PARAMETERS },
5068 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, EXT_POINT_PARAMETERS },
5069 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, WINED3D_GL_EXT_NONE },
5070 { STATE_RENDER(WINED3D_RS_TWEENFACTOR), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE },
5071 { STATE_RENDER(WINED3D_RS_INDEXEDVERTEXBLENDENABLE), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE },
5073 /* Samplers for NP2 texture matrix adjustions. They are not needed if GL_ARB_texture_non_power_of_two is supported,
5074 * so register a NULL state handler in that case to get the vertex part of sampler() skipped(VTF is handled in the misc states.
5075 * otherwise, register sampler_texmatrix, which takes care of updating the texture matrix
5077 { STATE_SAMPLER(0), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5078 { STATE_SAMPLER(0), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5079 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5080 { STATE_SAMPLER(1), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5081 { STATE_SAMPLER(1), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5082 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5083 { STATE_SAMPLER(2), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5084 { STATE_SAMPLER(2), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5085 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5086 { STATE_SAMPLER(3), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5087 { STATE_SAMPLER(3), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5088 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5089 { STATE_SAMPLER(4), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5090 { STATE_SAMPLER(4), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5091 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5092 { STATE_SAMPLER(5), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5093 { STATE_SAMPLER(5), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5094 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5095 { STATE_SAMPLER(6), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5096 { STATE_SAMPLER(6), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5097 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5098 { STATE_SAMPLER(7), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5099 { STATE_SAMPLER(7), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5100 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5101 { STATE_POINT_ENABLE, { STATE_POINT_ENABLE, state_nop }, WINED3D_GL_EXT_NONE },
5102 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5105 static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
5106 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5107 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5108 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5109 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5110 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5111 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5112 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5113 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5114 { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5115 { STATE_TEXTURESTAGE(0, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5116 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5117 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5118 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5119 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5120 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5121 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5122 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5123 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5124 { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5125 { STATE_TEXTURESTAGE(1, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5126 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5127 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5128 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5129 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5130 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5131 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5132 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5133 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5134 { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5135 { STATE_TEXTURESTAGE(2, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5136 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5137 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5138 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5139 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5140 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5141 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5142 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5143 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5144 { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5145 { STATE_TEXTURESTAGE(3, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5146 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5147 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5148 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5149 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5150 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5151 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5152 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5153 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5154 { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5155 { STATE_TEXTURESTAGE(4, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5156 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5157 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5158 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5159 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5160 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5161 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5162 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5163 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5164 { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5165 { STATE_TEXTURESTAGE(5, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5166 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5167 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5168 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5169 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5170 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5171 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5172 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5173 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5174 { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5175 { STATE_TEXTURESTAGE(6, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5176 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5177 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5178 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5179 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5180 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5181 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5182 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5183 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5184 { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5185 { STATE_TEXTURESTAGE(7, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5186 { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), apply_pixelshader }, WINED3D_GL_EXT_NONE },
5187 { STATE_RENDER(WINED3D_RS_ALPHAFUNC), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5188 { STATE_RENDER(WINED3D_RS_ALPHAREF), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5189 { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), state_alpha_test }, WINED3D_GL_EXT_NONE },
5190 { STATE_RENDER(WINED3D_RS_COLORKEYENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5191 { STATE_COLOR_KEY, { STATE_COLOR_KEY, state_nop }, WINED3D_GL_EXT_NONE },
5192 { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), NULL }, WINED3D_GL_EXT_NONE },
5193 { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), state_texfactor }, WINED3D_GL_EXT_NONE },
5194 { STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
5195 { STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
5196 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
5197 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5198 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5199 { STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
5200 { STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE },
5201 { STATE_RENDER(WINED3D_RS_SHADEMODE), { STATE_RENDER(WINED3D_RS_SHADEMODE), state_shademode }, WINED3D_GL_EXT_NONE },
5202 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE },
5203 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE },
5204 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE },
5205 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, WINED3D_GL_EXT_NONE },
5206 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, WINED3D_GL_EXT_NONE },
5207 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE },
5208 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE },
5209 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE },
5210 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5213 /* Context activation is done by the caller. */
5214 static void ffp_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5216 static void *ffp_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
5218 return shader_priv;
5221 static void ffp_free(struct wined3d_device *device) {}
5223 static void vp_ffp_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
5225 caps->xyzrhw = FALSE;
5226 caps->ffp_generic_attributes = FALSE;
5227 caps->max_active_lights = gl_info->limits.lights;
5228 caps->max_vertex_blend_matrices = 1;
5229 caps->max_vertex_blend_matrix_index = 0;
5230 caps->vertex_processing_caps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS
5231 | WINED3DVTXPCAPS_MATERIALSOURCE7
5232 | WINED3DVTXPCAPS_POSITIONALLIGHTS
5233 | WINED3DVTXPCAPS_LOCALVIEWER
5234 | WINED3DVTXPCAPS_VERTEXFOG
5235 | WINED3DVTXPCAPS_TEXGEN
5236 | WINED3DVTXPCAPS_TEXGEN_SPHEREMAP;
5237 caps->fvf_caps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
5238 caps->max_user_clip_planes = gl_info->limits.user_clip_distances;
5239 caps->raster_caps = 0;
5240 if (gl_info->supported[NV_FOG_DISTANCE])
5241 caps->raster_caps |= WINED3DPRASTERCAPS_FOGRANGE;
5244 static DWORD vp_ffp_get_emul_mask(const struct wined3d_gl_info *gl_info)
5246 return GL_EXT_EMUL_ARB_MULTITEXTURE | GL_EXT_EMUL_EXT_FOG_COORD;
5249 const struct wined3d_vertex_pipe_ops ffp_vertex_pipe =
5251 ffp_enable,
5252 vp_ffp_get_caps,
5253 vp_ffp_get_emul_mask,
5254 ffp_alloc,
5255 ffp_free,
5256 vp_ffp_states,
5259 static void ffp_fragment_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
5261 caps->wined3d_caps = 0;
5262 caps->PrimitiveMiscCaps = 0;
5263 caps->TextureOpCaps = WINED3DTEXOPCAPS_ADD
5264 | WINED3DTEXOPCAPS_ADDSIGNED
5265 | WINED3DTEXOPCAPS_ADDSIGNED2X
5266 | WINED3DTEXOPCAPS_MODULATE
5267 | WINED3DTEXOPCAPS_MODULATE2X
5268 | WINED3DTEXOPCAPS_MODULATE4X
5269 | WINED3DTEXOPCAPS_SELECTARG1
5270 | WINED3DTEXOPCAPS_SELECTARG2
5271 | WINED3DTEXOPCAPS_DISABLE;
5273 if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE]
5274 || gl_info->supported[EXT_TEXTURE_ENV_COMBINE]
5275 || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
5277 caps->TextureOpCaps |= WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
5278 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
5279 | WINED3DTEXOPCAPS_BLENDFACTORALPHA
5280 | WINED3DTEXOPCAPS_BLENDCURRENTALPHA
5281 | WINED3DTEXOPCAPS_LERP
5282 | WINED3DTEXOPCAPS_SUBTRACT;
5284 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]
5285 || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
5287 caps->TextureOpCaps |= WINED3DTEXOPCAPS_ADDSMOOTH
5288 | WINED3DTEXOPCAPS_MULTIPLYADD
5289 | WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
5290 | WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
5291 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
5293 if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
5294 caps->TextureOpCaps |= WINED3DTEXOPCAPS_DOTPRODUCT3;
5296 caps->MaxTextureBlendStages = gl_info->limits.textures;
5297 caps->MaxSimultaneousTextures = gl_info->limits.textures;
5300 static DWORD ffp_fragment_get_emul_mask(const struct wined3d_gl_info *gl_info)
5302 return GL_EXT_EMUL_ARB_MULTITEXTURE | GL_EXT_EMUL_EXT_FOG_COORD;
5305 static BOOL ffp_color_fixup_supported(struct color_fixup_desc fixup)
5307 /* We only support identity conversions. */
5308 return is_identity_fixup(fixup);
5311 static BOOL ffp_none_context_alloc(struct wined3d_context *context)
5313 return TRUE;
5316 static void ffp_none_context_free(struct wined3d_context *context)
5320 const struct fragment_pipeline ffp_fragment_pipeline = {
5321 ffp_enable,
5322 ffp_fragment_get_caps,
5323 ffp_fragment_get_emul_mask,
5324 ffp_alloc,
5325 ffp_free,
5326 ffp_none_context_alloc,
5327 ffp_none_context_free,
5328 ffp_color_fixup_supported,
5329 ffp_fragmentstate_template,
5332 static void none_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5334 static void *none_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
5336 return shader_priv;
5339 static void none_free(struct wined3d_device *device) {}
5341 static void vp_none_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
5343 memset(caps, 0, sizeof(*caps));
5346 static DWORD vp_none_get_emul_mask(const struct wined3d_gl_info *gl_info)
5348 return 0;
5351 const struct wined3d_vertex_pipe_ops none_vertex_pipe =
5353 none_enable,
5354 vp_none_get_caps,
5355 vp_none_get_emul_mask,
5356 none_alloc,
5357 none_free,
5358 NULL,
5361 static void fp_none_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
5363 memset(caps, 0, sizeof(*caps));
5366 static DWORD fp_none_get_emul_mask(const struct wined3d_gl_info *gl_info)
5368 return 0;
5371 static BOOL fp_none_color_fixup_supported(struct color_fixup_desc fixup)
5373 return is_identity_fixup(fixup);
5376 const struct fragment_pipeline none_fragment_pipe =
5378 none_enable,
5379 fp_none_get_caps,
5380 fp_none_get_emul_mask,
5381 none_alloc,
5382 none_free,
5383 ffp_none_context_alloc,
5384 ffp_none_context_free,
5385 fp_none_color_fixup_supported,
5386 NULL,
5389 static unsigned int num_handlers(const APPLYSTATEFUNC *funcs)
5391 unsigned int i;
5392 for(i = 0; funcs[i]; i++);
5393 return i;
5396 static void multistate_apply_2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5398 context->device->multistate_funcs[state_id][0](context, state, state_id);
5399 context->device->multistate_funcs[state_id][1](context, state, state_id);
5402 static void multistate_apply_3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5404 context->device->multistate_funcs[state_id][0](context, state, state_id);
5405 context->device->multistate_funcs[state_id][1](context, state, state_id);
5406 context->device->multistate_funcs[state_id][2](context, state, state_id);
5409 static void prune_invalid_states(struct StateEntry *state_table, const struct wined3d_gl_info *gl_info,
5410 const struct wined3d_d3d_info *d3d_info)
5412 unsigned int start, last, i;
5414 start = STATE_TEXTURESTAGE(d3d_info->limits.ffp_blend_stages, 0);
5415 last = STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE);
5416 for (i = start; i <= last; ++i)
5418 state_table[i].representative = 0;
5419 state_table[i].apply = state_undefined;
5422 start = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + d3d_info->limits.ffp_blend_stages);
5423 last = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + MAX_TEXTURES - 1);
5424 for (i = start; i <= last; ++i)
5426 state_table[i].representative = 0;
5427 state_table[i].apply = state_undefined;
5430 start = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(d3d_info->limits.ffp_vertex_blend_matrices));
5431 last = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255));
5432 for (i = start; i <= last; ++i)
5434 state_table[i].representative = 0;
5435 state_table[i].apply = state_undefined;
5439 static void validate_state_table(struct StateEntry *state_table)
5441 static const struct
5443 DWORD first;
5444 DWORD last;
5446 rs_holes[] =
5448 { 1, 1},
5449 { 3, 3},
5450 { 17, 18},
5451 { 21, 21},
5452 { 42, 45},
5453 { 47, 47},
5454 { 61, 127},
5455 {149, 150},
5456 {169, 169},
5457 {177, 177},
5458 {193, 193},
5459 {196, 197},
5460 { 0, 0},
5462 static const DWORD simple_states[] =
5464 STATE_MATERIAL,
5465 STATE_VDECL,
5466 STATE_STREAMSRC,
5467 STATE_INDEXBUFFER,
5468 STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX),
5469 STATE_SHADER(WINED3D_SHADER_TYPE_HULL),
5470 STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN),
5471 STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY),
5472 STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),
5473 STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE),
5474 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),
5475 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL),
5476 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN),
5477 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),
5478 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),
5479 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE),
5480 STATE_COMPUTE_SHADER_RESOURCE_BINDING,
5481 STATE_GRAPHICS_SHADER_RESOURCE_BINDING,
5482 STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING,
5483 STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING,
5484 STATE_VIEWPORT,
5485 STATE_LIGHT_TYPE,
5486 STATE_SCISSORRECT,
5487 STATE_RASTERIZER,
5488 STATE_POINTSPRITECOORDORIGIN,
5489 STATE_BASEVERTEXINDEX,
5490 STATE_FRAMEBUFFER,
5491 STATE_POINT_ENABLE,
5492 STATE_COLOR_KEY,
5493 STATE_BLEND,
5494 STATE_BLEND_FACTOR,
5496 unsigned int i, current;
5498 for (i = STATE_RENDER(1), current = 0; i <= STATE_RENDER(WINEHIGHEST_RENDER_STATE); ++i)
5500 if (!rs_holes[current].first || i < STATE_RENDER(rs_holes[current].first))
5502 if (!state_table[i].representative)
5503 ERR("State %s (%#x) should have a representative.\n", debug_d3dstate(i), i);
5505 else if (state_table[i].representative)
5506 ERR("State %s (%#x) shouldn't have a representative.\n", debug_d3dstate(i), i);
5508 if (i == STATE_RENDER(rs_holes[current].last)) ++current;
5511 for (i = 0; i < ARRAY_SIZE(simple_states); ++i)
5513 if (!state_table[simple_states[i]].representative)
5514 ERR("State %s (%#x) should have a representative.\n",
5515 debug_d3dstate(simple_states[i]), simple_states[i]);
5518 for (i = 0; i < STATE_HIGHEST + 1; ++i)
5520 DWORD rep = state_table[i].representative;
5521 if (rep)
5523 if (state_table[rep].representative != rep)
5525 ERR("State %s (%#x) has invalid representative %s (%#x).\n",
5526 debug_d3dstate(i), i, debug_d3dstate(rep), rep);
5527 state_table[i].representative = 0;
5530 if (rep != i)
5532 if (state_table[i].apply)
5533 ERR("State %s (%#x) has both a handler and representative.\n", debug_d3dstate(i), i);
5535 else if (!state_table[i].apply)
5537 ERR("Self representing state %s (%#x) has no handler.\n", debug_d3dstate(i), i);
5543 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
5544 const struct wined3d_gl_info *gl_info, const struct wined3d_d3d_info *d3d_info,
5545 const struct wined3d_vertex_pipe_ops *vertex, const struct fragment_pipeline *fragment,
5546 const struct StateEntryTemplate *misc)
5548 unsigned int i, type, handlers;
5549 APPLYSTATEFUNC multistate_funcs[STATE_HIGHEST + 1][3];
5550 const struct StateEntryTemplate *cur;
5551 BOOL set[STATE_HIGHEST + 1];
5553 memset(multistate_funcs, 0, sizeof(multistate_funcs));
5555 for(i = 0; i < STATE_HIGHEST + 1; i++) {
5556 StateTable[i].representative = 0;
5557 StateTable[i].apply = state_undefined;
5560 for(type = 0; type < 3; type++) {
5561 /* This switch decides the order in which the states are applied */
5562 switch(type) {
5563 case 0: cur = misc; break;
5564 case 1: cur = fragment->states; break;
5565 case 2: cur = vertex->vp_states; break;
5566 default: cur = NULL; /* Stupid compiler */
5568 if(!cur) continue;
5570 /* GL extension filtering should not prevent multiple handlers being applied from different
5571 * pipeline parts
5573 memset(set, 0, sizeof(set));
5575 for(i = 0; cur[i].state; i++) {
5576 APPLYSTATEFUNC *funcs_array;
5578 /* Only use the first matching state with the available extension from one template.
5579 * e.g.
5580 * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func1}, XYZ_FANCY},
5581 * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func2}, 0 }
5583 * if GL_XYZ_fancy is supported, ignore the 2nd line
5585 if(set[cur[i].state]) continue;
5586 /* Skip state lines depending on unsupported extensions */
5587 if (!gl_info->supported[cur[i].extension]) continue;
5588 set[cur[i].state] = TRUE;
5589 /* In some cases having an extension means that nothing has to be
5590 * done for a state, e.g. if GL_ARB_texture_non_power_of_two is
5591 * supported, the texture coordinate fixup can be ignored. If the
5592 * apply function is used, mark the state set(done above) to prevent
5593 * applying later lines, but do not record anything in the state
5594 * table
5596 if (!cur[i].content.representative) continue;
5598 handlers = num_handlers(multistate_funcs[cur[i].state]);
5599 multistate_funcs[cur[i].state][handlers] = cur[i].content.apply;
5600 switch(handlers) {
5601 case 0:
5602 StateTable[cur[i].state].apply = cur[i].content.apply;
5603 break;
5604 case 1:
5605 StateTable[cur[i].state].apply = multistate_apply_2;
5606 if (!(dev_multistate_funcs[cur[i].state] = heap_calloc(2, sizeof(**dev_multistate_funcs))))
5607 goto out_of_mem;
5609 dev_multistate_funcs[cur[i].state][0] = multistate_funcs[cur[i].state][0];
5610 dev_multistate_funcs[cur[i].state][1] = multistate_funcs[cur[i].state][1];
5611 break;
5612 case 2:
5613 StateTable[cur[i].state].apply = multistate_apply_3;
5614 if (!(funcs_array = heap_realloc(dev_multistate_funcs[cur[i].state],
5615 sizeof(**dev_multistate_funcs) * 3)))
5616 goto out_of_mem;
5618 dev_multistate_funcs[cur[i].state] = funcs_array;
5619 dev_multistate_funcs[cur[i].state][2] = multistate_funcs[cur[i].state][2];
5620 break;
5621 default:
5622 ERR("Unexpected amount of state handlers for state %u: %u\n",
5623 cur[i].state, handlers + 1);
5626 if (StateTable[cur[i].state].representative
5627 && StateTable[cur[i].state].representative != cur[i].content.representative)
5629 FIXME("State %s (%#x) has different representatives in different pipeline parts.\n",
5630 debug_d3dstate(cur[i].state), cur[i].state);
5632 StateTable[cur[i].state].representative = cur[i].content.representative;
5636 prune_invalid_states(StateTable, gl_info, d3d_info);
5637 validate_state_table(StateTable);
5639 return WINED3D_OK;
5641 out_of_mem:
5642 for (i = 0; i <= STATE_HIGHEST; ++i)
5644 heap_free(dev_multistate_funcs[i]);
5647 memset(dev_multistate_funcs, 0, (STATE_HIGHEST + 1)*sizeof(*dev_multistate_funcs));
5649 return E_OUTOFMEMORY;