gphoto2.ds: Set supported groups.
[wine.git] / dlls / wined3d / state.c
blob61337392f773f904fbb8b4536f2c1be813d67e3f
1 /*
2 * Direct3D state management
4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2002-2005 Jason Edmeades
6 * Copyright 2003-2004 Raphael Junqueira
7 * Copyright 2004 Christian Costa
8 * Copyright 2005 Oliver Stieber
9 * Copyright 2006 Henri Verbeet
10 * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
11 * Copyright 2009-2011 Henri Verbeet for CodeWeavers
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "config.h"
29 #include "wine/port.h"
31 #include <stdio.h>
32 #ifdef HAVE_FLOAT_H
33 # include <float.h>
34 #endif
36 #include "wined3d_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
39 WINE_DECLARE_DEBUG_CHANNEL(d3d_shader);
41 ULONG CDECL wined3d_rasterizer_state_incref(struct wined3d_rasterizer_state *state)
43 ULONG refcount = InterlockedIncrement(&state->refcount);
45 TRACE("%p increasing refcount to %u.\n", state, refcount);
47 return refcount;
50 static void wined3d_rasterizer_state_destroy_object(void *object)
52 HeapFree(GetProcessHeap(), 0, object);
55 ULONG CDECL wined3d_rasterizer_state_decref(struct wined3d_rasterizer_state *state)
57 ULONG refcount = InterlockedDecrement(&state->refcount);
58 struct wined3d_device *device = state->device;
60 TRACE("%p decreasing refcount to %u.\n", state, refcount);
62 if (!refcount)
64 state->parent_ops->wined3d_object_destroyed(state->parent);
65 wined3d_cs_destroy_object(device->cs, wined3d_rasterizer_state_destroy_object, state);
68 return refcount;
71 void * CDECL wined3d_rasterizer_state_get_parent(const struct wined3d_rasterizer_state *state)
73 TRACE("rasterizer_state %p.\n", state);
75 return state->parent;
78 HRESULT CDECL wined3d_rasterizer_state_create(struct wined3d_device *device,
79 const struct wined3d_rasterizer_state_desc *desc, void *parent,
80 const struct wined3d_parent_ops *parent_ops, struct wined3d_rasterizer_state **state)
82 struct wined3d_rasterizer_state *object;
84 TRACE("device %p, desc %p, state %p.\n", device, desc, state);
86 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 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 rasterizer state %p.\n", object);
96 *state = object;
98 return WINED3D_OK;
101 /* Context activation for state handler is done by the caller. */
103 static void state_undefined(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
105 ERR("Undefined state %s (%#x).\n", debug_d3dstate(state_id), state_id);
108 void state_nop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
110 TRACE("%s: nop in current pipe config.\n", debug_d3dstate(state_id));
113 static void state_fillmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
115 enum wined3d_fill_mode mode = state->render_states[WINED3D_RS_FILLMODE];
116 const struct wined3d_gl_info *gl_info = context->gl_info;
118 switch (mode)
120 case WINED3D_FILL_POINT:
121 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
122 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
123 break;
124 case WINED3D_FILL_WIREFRAME:
125 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
126 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
127 break;
128 case WINED3D_FILL_SOLID:
129 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
130 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
131 break;
132 default:
133 FIXME("Unrecognized fill mode %#x.\n", mode);
137 static void state_lighting(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
139 const struct wined3d_gl_info *gl_info = context->gl_info;
141 /* Lighting is not enabled if transformed vertices are drawn, but lighting
142 * does not affect the stream sources, so it is not grouped for
143 * performance reasons. This state reads the decoded vertex declaration,
144 * so if it is dirty don't do anything. The vertex declaration applying
145 * function calls this function for updating. */
146 if (isStateDirty(context, STATE_VDECL))
147 return;
149 if (state->render_states[WINED3D_RS_LIGHTING]
150 && !context->stream_info.position_transformed)
152 gl_info->gl_ops.gl.p_glEnable(GL_LIGHTING);
153 checkGLcall("glEnable GL_LIGHTING");
155 else
157 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
158 checkGLcall("glDisable GL_LIGHTING");
162 static void state_zenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
164 enum wined3d_depth_buffer_type zenable = state->render_states[WINED3D_RS_ZENABLE];
165 const struct wined3d_gl_info *gl_info = context->gl_info;
167 /* No z test without depth stencil buffers */
168 if (!state->fb->depth_stencil)
170 TRACE("No Z buffer - disabling depth test\n");
171 zenable = WINED3D_ZB_FALSE;
174 switch (zenable)
176 case WINED3D_ZB_FALSE:
177 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
178 checkGLcall("glDisable GL_DEPTH_TEST");
179 break;
180 case WINED3D_ZB_TRUE:
181 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
182 checkGLcall("glEnable GL_DEPTH_TEST");
183 break;
184 case WINED3D_ZB_USEW:
185 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
186 checkGLcall("glEnable GL_DEPTH_TEST");
187 FIXME("W buffer is not well handled\n");
188 break;
189 default:
190 FIXME("Unrecognized depth buffer type %#x.\n", zenable);
191 break;
194 if (context->last_was_rhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
195 context_apply_state(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
198 static void state_cullmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
200 const struct wined3d_gl_info *gl_info = context->gl_info;
202 /* glFrontFace() is set in context.c at context init and on an
203 * offscreen / onscreen rendering switch. */
204 switch (state->render_states[WINED3D_RS_CULLMODE])
206 case WINED3D_CULL_NONE:
207 gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
208 checkGLcall("glDisable GL_CULL_FACE");
209 break;
210 case WINED3D_CULL_FRONT:
211 gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
212 checkGLcall("glEnable GL_CULL_FACE");
213 gl_info->gl_ops.gl.p_glCullFace(GL_FRONT);
214 checkGLcall("glCullFace(GL_FRONT)");
215 break;
216 case WINED3D_CULL_BACK:
217 gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
218 checkGLcall("glEnable GL_CULL_FACE");
219 gl_info->gl_ops.gl.p_glCullFace(GL_BACK);
220 checkGLcall("glCullFace(GL_BACK)");
221 break;
222 default:
223 FIXME("Unrecognized cull mode %#x.\n",
224 state->render_states[WINED3D_RS_CULLMODE]);
228 void state_shademode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
230 const struct wined3d_gl_info *gl_info = context->gl_info;
232 switch (state->render_states[WINED3D_RS_SHADEMODE])
234 case WINED3D_SHADE_FLAT:
235 gl_info->gl_ops.gl.p_glShadeModel(GL_FLAT);
236 checkGLcall("glShadeModel(GL_FLAT)");
237 break;
238 case WINED3D_SHADE_GOURAUD:
239 /* WINED3D_SHADE_PHONG in practice is the same as WINED3D_SHADE_GOURAUD
240 * in D3D. */
241 case WINED3D_SHADE_PHONG:
242 gl_info->gl_ops.gl.p_glShadeModel(GL_SMOOTH);
243 checkGLcall("glShadeModel(GL_SMOOTH)");
244 break;
245 default:
246 FIXME("Unrecognized shade mode %#x.\n",
247 state->render_states[WINED3D_RS_SHADEMODE]);
251 static void state_ditherenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
253 const struct wined3d_gl_info *gl_info = context->gl_info;
255 if (state->render_states[WINED3D_RS_DITHERENABLE])
257 gl_info->gl_ops.gl.p_glEnable(GL_DITHER);
258 checkGLcall("glEnable GL_DITHER");
260 else
262 gl_info->gl_ops.gl.p_glDisable(GL_DITHER);
263 checkGLcall("glDisable GL_DITHER");
267 static void state_zwriteenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
269 const struct wined3d_gl_info *gl_info = context->gl_info;
271 if (state->render_states[WINED3D_RS_ZWRITEENABLE])
273 gl_info->gl_ops.gl.p_glDepthMask(1);
274 checkGLcall("glDepthMask(1)");
276 else
278 gl_info->gl_ops.gl.p_glDepthMask(0);
279 checkGLcall("glDepthMask(0)");
283 GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f)
285 switch (f)
287 case WINED3D_CMP_NEVER:
288 return GL_NEVER;
289 case WINED3D_CMP_LESS:
290 return GL_LESS;
291 case WINED3D_CMP_EQUAL:
292 return GL_EQUAL;
293 case WINED3D_CMP_LESSEQUAL:
294 return GL_LEQUAL;
295 case WINED3D_CMP_GREATER:
296 return GL_GREATER;
297 case WINED3D_CMP_NOTEQUAL:
298 return GL_NOTEQUAL;
299 case WINED3D_CMP_GREATEREQUAL:
300 return GL_GEQUAL;
301 case WINED3D_CMP_ALWAYS:
302 return GL_ALWAYS;
303 default:
304 if (!f)
305 WARN("Unrecognized compare function %#x.\n", f);
306 else
307 FIXME("Unrecognized compare function %#x.\n", f);
308 return GL_NONE;
312 static void state_zfunc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
314 GLenum depth_func = wined3d_gl_compare_func(state->render_states[WINED3D_RS_ZFUNC]);
315 const struct wined3d_gl_info *gl_info = context->gl_info;
317 if (!depth_func) return;
319 gl_info->gl_ops.gl.p_glDepthFunc(depth_func);
320 checkGLcall("glDepthFunc");
323 static void state_ambient(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
325 const struct wined3d_gl_info *gl_info = context->gl_info;
326 struct wined3d_color color;
328 wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_AMBIENT]);
329 TRACE("Setting ambient to %s.\n", debug_color(&color));
330 gl_info->gl_ops.gl.p_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &color.r);
331 checkGLcall("glLightModel for MODEL_AMBIENT");
334 static void state_blendop_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
336 WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
339 static GLenum gl_blend_op(const struct wined3d_gl_info *gl_info, enum wined3d_blend_op op)
341 switch (op)
343 case WINED3D_BLEND_OP_ADD:
344 return GL_FUNC_ADD;
345 case WINED3D_BLEND_OP_SUBTRACT:
346 return gl_info->supported[EXT_BLEND_SUBTRACT] ? GL_FUNC_SUBTRACT : GL_FUNC_ADD;
347 case WINED3D_BLEND_OP_REVSUBTRACT:
348 return gl_info->supported[EXT_BLEND_SUBTRACT] ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD;
349 case WINED3D_BLEND_OP_MIN:
350 return gl_info->supported[EXT_BLEND_MINMAX] ? GL_MIN : GL_FUNC_ADD;
351 case WINED3D_BLEND_OP_MAX:
352 return gl_info->supported[EXT_BLEND_MINMAX] ? GL_MAX : GL_FUNC_ADD;
353 default:
354 if (!op)
355 WARN("Unhandled blend op %#x.\n", op);
356 else
357 FIXME("Unhandled blend op %#x.\n", op);
358 return GL_FUNC_ADD;
362 static void state_blendop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
364 const struct wined3d_gl_info *gl_info = context->gl_info;
365 GLenum blend_equation_alpha = GL_FUNC_ADD_EXT;
366 GLenum blend_equation = GL_FUNC_ADD_EXT;
368 /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */
369 if (state->render_states[WINED3D_RS_BLENDOPALPHA]
370 && !gl_info->supported[EXT_BLEND_EQUATION_SEPARATE])
372 WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparate.\n");
373 return;
376 blend_equation = gl_blend_op(gl_info, state->render_states[WINED3D_RS_BLENDOP]);
377 blend_equation_alpha = gl_blend_op(gl_info, state->render_states[WINED3D_RS_BLENDOPALPHA]);
378 TRACE("blend_equation %#x, blend_equation_alpha %#x.\n", blend_equation, blend_equation_alpha);
380 if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
382 GL_EXTCALL(glBlendEquationSeparate(blend_equation, blend_equation_alpha));
383 checkGLcall("glBlendEquationSeparate");
385 else
387 GL_EXTCALL(glBlendEquation(blend_equation));
388 checkGLcall("glBlendEquation");
392 static GLenum gl_blend_factor(enum wined3d_blend factor, const struct wined3d_format *dst_format)
394 switch (factor)
396 case WINED3D_BLEND_ZERO:
397 return GL_ZERO;
398 case WINED3D_BLEND_ONE:
399 return GL_ONE;
400 case WINED3D_BLEND_SRCCOLOR:
401 return GL_SRC_COLOR;
402 case WINED3D_BLEND_INVSRCCOLOR:
403 return GL_ONE_MINUS_SRC_COLOR;
404 case WINED3D_BLEND_SRCALPHA:
405 return GL_SRC_ALPHA;
406 case WINED3D_BLEND_INVSRCALPHA:
407 return GL_ONE_MINUS_SRC_ALPHA;
408 case WINED3D_BLEND_DESTCOLOR:
409 return GL_DST_COLOR;
410 case WINED3D_BLEND_INVDESTCOLOR:
411 return GL_ONE_MINUS_DST_COLOR;
412 /* To compensate for the lack of format switching with backbuffer
413 * offscreen rendering, and with onscreen rendering, we modify the
414 * alpha test parameters for (INV)DESTALPHA if the render target
415 * doesn't support alpha blending. A nonexistent alpha channel
416 * returns 1.0, so WINED3D_BLEND_DESTALPHA becomes GL_ONE, and
417 * WINED3D_BLEND_INVDESTALPHA becomes GL_ZERO. */
418 case WINED3D_BLEND_DESTALPHA:
419 return dst_format->alpha_size ? GL_DST_ALPHA : GL_ONE;
420 case WINED3D_BLEND_INVDESTALPHA:
421 return dst_format->alpha_size ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO;
422 case WINED3D_BLEND_SRCALPHASAT:
423 return GL_SRC_ALPHA_SATURATE;
424 case WINED3D_BLEND_BLENDFACTOR:
425 return GL_CONSTANT_COLOR_EXT;
426 case WINED3D_BLEND_INVBLENDFACTOR:
427 return GL_ONE_MINUS_CONSTANT_COLOR_EXT;
428 case WINED3D_BLEND_SRC1COLOR:
429 return GL_SRC1_COLOR;
430 case WINED3D_BLEND_INVSRC1COLOR:
431 return GL_ONE_MINUS_SRC1_COLOR;
432 case WINED3D_BLEND_SRC1ALPHA:
433 return GL_SRC1_ALPHA;
434 case WINED3D_BLEND_INVSRC1ALPHA:
435 return GL_ONE_MINUS_SRC1_ALPHA;
436 default:
437 if (!factor)
438 WARN("Unhandled blend factor %#x.\n", factor);
439 else
440 FIXME("Unhandled blend factor %#x.\n", factor);
441 return GL_NONE;
445 static void gl_blend_from_d3d(GLenum *src_blend, GLenum *dst_blend,
446 enum wined3d_blend d3d_src_blend, enum wined3d_blend d3d_dst_blend,
447 const struct wined3d_format *rt_format)
449 /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy
450 * source blending values which are still valid up to d3d9. They should
451 * not occur as dest blend values. */
452 if (d3d_src_blend == WINED3D_BLEND_BOTHSRCALPHA)
454 *src_blend = GL_SRC_ALPHA;
455 *dst_blend = GL_ONE_MINUS_SRC_ALPHA;
457 else if (d3d_src_blend == WINED3D_BLEND_BOTHINVSRCALPHA)
459 *src_blend = GL_ONE_MINUS_SRC_ALPHA;
460 *dst_blend = GL_SRC_ALPHA;
462 else
464 *src_blend = gl_blend_factor(d3d_src_blend, rt_format);
465 *dst_blend = gl_blend_factor(d3d_dst_blend, rt_format);
469 static void state_blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
471 const struct wined3d_gl_info *gl_info = context->gl_info;
472 const struct wined3d_format *rt_format;
473 GLenum src_blend, dst_blend;
474 unsigned int rt_fmt_flags;
475 BOOL enable_blend;
477 enable_blend = state->fb->render_targets[0] && state->render_states[WINED3D_RS_ALPHABLENDENABLE];
478 if (enable_blend)
480 rt_format = state->fb->render_targets[0]->format;
481 rt_fmt_flags = state->fb->render_targets[0]->format_flags;
483 /* Disable blending in all cases even without pixelshaders.
484 * With blending on we could face a big performance penalty.
485 * The d3d9 visual test confirms the behavior. */
486 if (context->render_offscreen && !(rt_fmt_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
487 enable_blend = FALSE;
490 if (!enable_blend)
492 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
493 checkGLcall("glDisable(GL_BLEND)");
494 return;
497 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
498 checkGLcall("glEnable(GL_BLEND)");
500 gl_blend_from_d3d(&src_blend, &dst_blend,
501 state->render_states[WINED3D_RS_SRCBLEND],
502 state->render_states[WINED3D_RS_DESTBLEND], rt_format);
504 /* Re-apply BLENDOP(ALPHA) because of a possible SEPARATEALPHABLENDENABLE change */
505 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_BLENDOP)))
506 state_blendop(context, state, STATE_RENDER(WINED3D_RS_BLENDOPALPHA));
508 if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
510 GLenum src_blend_alpha, dst_blend_alpha;
512 /* Separate alpha blending requires GL_EXT_blend_function_separate, so make sure it is around */
513 if (!context->gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
515 WARN("Unsupported in local OpenGL implementation: glBlendFuncSeparate.\n");
516 return;
519 gl_blend_from_d3d(&src_blend_alpha, &dst_blend_alpha,
520 state->render_states[WINED3D_RS_SRCBLENDALPHA],
521 state->render_states[WINED3D_RS_DESTBLENDALPHA], rt_format);
523 GL_EXTCALL(glBlendFuncSeparate(src_blend, dst_blend, src_blend_alpha, dst_blend_alpha));
524 checkGLcall("glBlendFuncSeparate");
526 else
528 TRACE("glBlendFunc src=%x, dst=%x.\n", src_blend, dst_blend);
529 gl_info->gl_ops.gl.p_glBlendFunc(src_blend, dst_blend);
530 checkGLcall("glBlendFunc");
533 /* Colorkey fixup for stage 0 alphaop depends on
534 * WINED3D_RS_ALPHABLENDENABLE state, so it may need updating. */
535 if (state->render_states[WINED3D_RS_COLORKEYENABLE])
536 context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
539 static void state_blendfactor_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
541 WARN("Unsupported in local OpenGL implementation: glBlendColor.\n");
544 static void state_blendfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
546 const struct wined3d_gl_info *gl_info = context->gl_info;
547 struct wined3d_color color;
549 TRACE("Setting blend factor to %#x.\n", state->render_states[WINED3D_RS_BLENDFACTOR]);
551 wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_BLENDFACTOR]);
552 GL_EXTCALL(glBlendColor(color.r, color.g, color.b, color.a));
553 checkGLcall("glBlendColor");
556 void state_alpha_test(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
558 const struct wined3d_gl_info *gl_info = context->gl_info;
559 int glParm = 0;
560 float ref;
561 BOOL enable_ckey = FALSE;
563 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
565 /* Find out if the texture on the first stage has a ckey set. The alpha
566 * state func reads the texture settings, even though alpha and texture
567 * are not grouped together. This is to avoid making a huge alpha +
568 * texture + texture stage + ckey block due to the hardly used
569 * WINED3D_RS_COLORKEYENABLE state(which is d3d <= 3 only). The texture
570 * function will call alpha in case it finds some texture + colorkeyenable
571 * combination which needs extra care. */
572 if (state->textures[0] && (state->textures[0]->async.color_key_flags & WINED3D_CKEY_SRC_BLT))
573 enable_ckey = TRUE;
575 if (enable_ckey || context->last_was_ckey)
576 context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
577 context->last_was_ckey = enable_ckey;
579 if (state->render_states[WINED3D_RS_ALPHATESTENABLE]
580 || (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey))
582 gl_info->gl_ops.gl.p_glEnable(GL_ALPHA_TEST);
583 checkGLcall("glEnable GL_ALPHA_TEST");
585 else
587 gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
588 checkGLcall("glDisable GL_ALPHA_TEST");
589 /* Alpha test is disabled, don't bother setting the params - it will happen on the next
590 * enable call
592 return;
595 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey)
597 glParm = GL_NOTEQUAL;
598 ref = 0.0f;
600 else
602 ref = ((float)state->render_states[WINED3D_RS_ALPHAREF]) / 255.0f;
603 glParm = wined3d_gl_compare_func(state->render_states[WINED3D_RS_ALPHAFUNC]);
605 if (glParm)
607 gl_info->gl_ops.gl.p_glAlphaFunc(glParm, ref);
608 checkGLcall("glAlphaFunc");
612 void state_clipping(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
614 const struct wined3d_gl_info *gl_info = context->gl_info;
615 unsigned int clipplane_count = gl_info->limits.user_clip_distances;
616 unsigned int i, enable_mask, disable_mask;
618 if (use_vs(state) && !context->d3d_info->vs_clipping)
620 static BOOL warned;
622 /* The OpenGL spec says that clipping planes are disabled when using
623 * shaders. Direct3D planes aren't, so that is an issue. The MacOS ATI
624 * driver keeps clipping planes activated with shaders in some
625 * conditions I got sick of tracking down. The shader state handler
626 * disables all clip planes because of that - don't do anything here
627 * and keep them disabled. */
628 if (state->render_states[WINED3D_RS_CLIPPLANEENABLE] && !warned++)
629 FIXME("Clipping not supported with vertex shaders\n");
630 return;
633 /* glEnable(GL_CLIP_PLANEx) doesn't apply to (ARB backend) vertex shaders.
634 * The enabled / disabled planes are hardcoded into the shader. Update the
635 * shader to update the enabled clipplanes. In case of fixed function, we
636 * need to update the clipping field from ffp_vertex_settings. */
637 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
639 /* TODO: Keep track of previously enabled clipplanes to avoid unnecessary resetting
640 * of already set values
643 /* If enabling / disabling all
644 * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
646 if (state->render_states[WINED3D_RS_CLIPPING])
648 enable_mask = state->render_states[WINED3D_RS_CLIPPLANEENABLE];
649 disable_mask = ~state->render_states[WINED3D_RS_CLIPPLANEENABLE];
651 else
653 enable_mask = 0;
654 disable_mask = ~0u;
657 if (clipplane_count < 32)
659 enable_mask &= (1u << clipplane_count) - 1;
660 disable_mask &= (1u << clipplane_count) - 1;
663 for (i = 0; enable_mask && i < clipplane_count; enable_mask >>= 1, ++i)
664 if (enable_mask & 1)
665 gl_info->gl_ops.gl.p_glEnable(GL_CLIP_DISTANCE0 + i);
666 checkGLcall("clip plane enable");
668 for (i = 0; disable_mask && i < clipplane_count; disable_mask >>= 1, ++i)
669 if (disable_mask & 1)
670 gl_info->gl_ops.gl.p_glDisable(GL_CLIP_DISTANCE0 + i);
671 checkGLcall("clip plane disable");
674 static void state_specularenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
676 const struct wined3d_gl_info *gl_info = context->gl_info;
677 /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
678 * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
679 * specular color. This is wrong:
680 * Separate specular color means the specular colour is maintained separately, whereas
681 * single color means it is merged in. However in both cases they are being used to
682 * some extent.
683 * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
684 * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
685 * running 1.4 yet!
688 * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
689 * Instead, we need to setup the FinalCombiner properly.
691 * The default setup for the FinalCombiner is:
693 * <variable> <input> <mapping> <usage>
694 * GL_VARIABLE_A_NV GL_FOG, GL_UNSIGNED_IDENTITY_NV GL_ALPHA
695 * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV GL_UNSIGNED_IDENTITY_NV GL_RGB
696 * GL_VARIABLE_C_NV GL_FOG GL_UNSIGNED_IDENTITY_NV GL_RGB
697 * GL_VARIABLE_D_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
698 * GL_VARIABLE_E_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
699 * GL_VARIABLE_F_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
700 * GL_VARIABLE_G_NV GL_SPARE0_NV GL_UNSIGNED_IDENTITY_NV GL_ALPHA
702 * That's pretty much fine as it is, except for variable B, which needs to take
703 * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
704 * whether WINED3D_RS_SPECULARENABLE is enabled or not.
707 TRACE("Setting specular enable state and materials\n");
708 if (state->render_states[WINED3D_RS_SPECULARENABLE])
710 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
711 checkGLcall("glMaterialfv");
713 if (state->material.power > gl_info->limits.shininess)
715 /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0
716 * and 128.0, although in d3d neither -1 nor 129 produce an error. GL_NV_max_light_exponent
717 * allows bigger values. If the extension is supported, gl_info->limits.shininess contains the
718 * value reported by the extension, otherwise 128. For values > gl_info->limits.shininess clamp
719 * them, it should be safe to do so without major visual distortions.
721 WARN("Material power = %.8e, limit %.8e\n", state->material.power, gl_info->limits.shininess);
722 gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, gl_info->limits.shininess);
724 else
726 gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, state->material.power);
728 checkGLcall("glMaterialf(GL_SHININESS)");
730 if (gl_info->supported[EXT_SECONDARY_COLOR])
731 gl_info->gl_ops.gl.p_glEnable(GL_COLOR_SUM_EXT);
732 else
733 TRACE("Specular colors cannot be enabled in this version of opengl\n");
734 checkGLcall("glEnable(GL_COLOR_SUM)");
736 if (gl_info->supported[NV_REGISTER_COMBINERS])
738 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
739 checkGLcall("glFinalCombinerInputNV()");
741 } else {
742 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
744 /* for the case of enabled lighting: */
745 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
746 checkGLcall("glMaterialfv");
748 /* for the case of disabled lighting: */
749 if (gl_info->supported[EXT_SECONDARY_COLOR])
750 gl_info->gl_ops.gl.p_glDisable(GL_COLOR_SUM_EXT);
751 else
752 TRACE("Specular colors cannot be disabled in this version of opengl\n");
753 checkGLcall("glDisable(GL_COLOR_SUM)");
755 if (gl_info->supported[NV_REGISTER_COMBINERS])
757 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
758 checkGLcall("glFinalCombinerInputNV()");
762 TRACE("diffuse %s\n", debug_color(&state->material.diffuse));
763 TRACE("ambient %s\n", debug_color(&state->material.ambient));
764 TRACE("specular %s\n", debug_color(&state->material.specular));
765 TRACE("emissive %s\n", debug_color(&state->material.emissive));
767 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
768 checkGLcall("glMaterialfv(GL_AMBIENT)");
769 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
770 checkGLcall("glMaterialfv(GL_DIFFUSE)");
771 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
772 checkGLcall("glMaterialfv(GL_EMISSION)");
775 static void state_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
777 const struct wined3d_gl_info *gl_info = context->gl_info;
778 struct wined3d_color color;
779 unsigned int i;
781 /* Note the texture color applies to all textures whereas
782 * GL_TEXTURE_ENV_COLOR applies to active only. */
783 wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_TEXTUREFACTOR]);
785 /* And now the default texture color as well */
786 for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
788 /* Note the WINED3D_RS value applies to all textures, but GL has one
789 * per texture, so apply it now ready to be used! */
790 context_active_texture(context, gl_info, i);
792 gl_info->gl_ops.gl.p_glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &color.r);
793 checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
797 static void renderstate_stencil_twosided(struct wined3d_context *context, GLint face,
798 GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass)
800 const struct wined3d_gl_info *gl_info = context->gl_info;
802 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
803 checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
804 GL_EXTCALL(glActiveStencilFaceEXT(face));
805 checkGLcall("glActiveStencilFaceEXT(...)");
806 gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
807 checkGLcall("glStencilFunc(...)");
808 gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
809 checkGLcall("glStencilOp(...)");
812 static GLenum gl_stencil_op(enum wined3d_stencil_op op)
814 switch (op)
816 case WINED3D_STENCIL_OP_KEEP:
817 return GL_KEEP;
818 case WINED3D_STENCIL_OP_ZERO:
819 return GL_ZERO;
820 case WINED3D_STENCIL_OP_REPLACE:
821 return GL_REPLACE;
822 case WINED3D_STENCIL_OP_INCR_SAT:
823 return GL_INCR;
824 case WINED3D_STENCIL_OP_DECR_SAT:
825 return GL_DECR;
826 case WINED3D_STENCIL_OP_INVERT:
827 return GL_INVERT;
828 case WINED3D_STENCIL_OP_INCR:
829 return GL_INCR_WRAP;
830 case WINED3D_STENCIL_OP_DECR:
831 return GL_DECR_WRAP;
832 default:
833 if (!op)
834 WARN("Unrecognized stencil op %#x.\n", op);
835 else
836 FIXME("Unrecognized stencil op %#x.\n", op);
837 return GL_KEEP;
841 static void state_stencil(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
843 const struct wined3d_gl_info *gl_info = context->gl_info;
844 DWORD onesided_enable;
845 DWORD twosided_enable;
846 GLint func;
847 GLint func_back;
848 GLint ref;
849 GLuint mask;
850 GLint stencilFail;
851 GLint stencilFail_back;
852 GLint stencilPass;
853 GLint stencilPass_back;
854 GLint depthFail;
855 GLint depthFail_back;
857 /* No stencil test without a stencil buffer. */
858 if (!state->fb->depth_stencil)
860 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
861 checkGLcall("glDisable GL_STENCIL_TEST");
862 return;
865 onesided_enable = state->render_states[WINED3D_RS_STENCILENABLE];
866 twosided_enable = state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE];
867 if (!(func = wined3d_gl_compare_func(state->render_states[WINED3D_RS_STENCILFUNC])))
868 func = GL_ALWAYS;
869 if (!(func_back = wined3d_gl_compare_func(state->render_states[WINED3D_RS_BACK_STENCILFUNC])))
870 func_back = GL_ALWAYS;
871 ref = state->render_states[WINED3D_RS_STENCILREF];
872 mask = state->render_states[WINED3D_RS_STENCILMASK];
873 stencilFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILFAIL]);
874 depthFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILZFAIL]);
875 stencilPass = gl_stencil_op(state->render_states[WINED3D_RS_STENCILPASS]);
876 stencilFail_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILFAIL]);
877 depthFail_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILZFAIL]);
878 stencilPass_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILPASS]);
880 TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
881 "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
882 "GL_BACK: func: %x, fail %x, zfail %x, zpass %x)\n",
883 onesided_enable, twosided_enable, ref, mask,
884 func, stencilFail, depthFail, stencilPass,
885 func_back, stencilFail_back, depthFail_back, stencilPass_back);
887 if (twosided_enable && onesided_enable)
889 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
890 checkGLcall("glEnable GL_STENCIL_TEST");
892 if (gl_info->supported[WINED3D_GL_VERSION_2_0])
894 GL_EXTCALL(glStencilFuncSeparate(GL_FRONT, func, ref, mask));
895 GL_EXTCALL(glStencilOpSeparate(GL_FRONT, stencilFail, depthFail, stencilPass));
896 GL_EXTCALL(glStencilFuncSeparate(GL_BACK, func_back, ref, mask));
897 GL_EXTCALL(glStencilOpSeparate(GL_BACK, stencilFail_back, depthFail_back, stencilPass_back));
898 checkGLcall("setting two sided stencil state");
900 else if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
902 /* Apply back first, then front. This function calls glActiveStencilFaceEXT,
903 * which has an effect on the code below too. If we apply the front face
904 * afterwards, we are sure that the active stencil face is set to front,
905 * and other stencil functions which do not use two sided stencil do not have
906 * to set it back
908 renderstate_stencil_twosided(context, GL_BACK,
909 func_back, ref, mask, stencilFail_back, depthFail_back, stencilPass_back);
910 renderstate_stencil_twosided(context, GL_FRONT,
911 func, ref, mask, stencilFail, depthFail, stencilPass);
913 else if (gl_info->supported[ATI_SEPARATE_STENCIL])
915 GL_EXTCALL(glStencilFuncSeparateATI(func, func_back, ref, mask));
916 checkGLcall("glStencilFuncSeparateATI(...)");
917 GL_EXTCALL(glStencilOpSeparateATI(GL_FRONT, stencilFail, depthFail, stencilPass));
918 checkGLcall("glStencilOpSeparateATI(GL_FRONT, ...)");
919 GL_EXTCALL(glStencilOpSeparateATI(GL_BACK, stencilFail_back, depthFail_back, stencilPass_back));
920 checkGLcall("glStencilOpSeparateATI(GL_BACK, ...)");
922 else
924 FIXME("Separate (two sided) stencil not supported on this version of OpenGL. Caps weren't honored?\n");
927 else if(onesided_enable)
929 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
931 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
932 checkGLcall("glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
935 /* This code disables the ATI extension as well, since the standard stencil functions are equal
936 * to calling the ATI functions with GL_FRONT_AND_BACK as face parameter
938 gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
939 checkGLcall("glEnable GL_STENCIL_TEST");
940 gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
941 checkGLcall("glStencilFunc(...)");
942 gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
943 checkGLcall("glStencilOp(...)");
945 else
947 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
948 checkGLcall("glDisable GL_STENCIL_TEST");
952 static void state_stencilwrite2s(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
954 DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
955 const struct wined3d_gl_info *gl_info = context->gl_info;
957 GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
958 checkGLcall("glActiveStencilFaceEXT(GL_BACK)");
959 gl_info->gl_ops.gl.p_glStencilMask(mask);
960 checkGLcall("glStencilMask");
961 GL_EXTCALL(glActiveStencilFaceEXT(GL_FRONT));
962 checkGLcall("glActiveStencilFaceEXT(GL_FRONT)");
963 gl_info->gl_ops.gl.p_glStencilMask(mask);
966 static void state_stencilwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
968 DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
969 const struct wined3d_gl_info *gl_info = context->gl_info;
971 gl_info->gl_ops.gl.p_glStencilMask(mask);
972 checkGLcall("glStencilMask");
975 static void state_fog_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
977 const struct wined3d_gl_info *gl_info = context->gl_info;
979 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
981 if (!state->render_states[WINED3D_RS_FOGENABLE])
982 return;
984 /* Table fog on: Never use fog coords, and use per-fragment fog */
985 if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
987 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
988 if (context->fog_coord)
990 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
991 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
992 context->fog_coord = FALSE;
995 /* Range fog is only used with per-vertex fog in d3d */
996 if (gl_info->supported[NV_FOG_DISTANCE])
998 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
999 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
1001 return;
1004 /* Otherwise use per-vertex fog in any case */
1005 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_FASTEST);
1007 if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || context->last_was_rhw)
1009 /* No fog at all, or transformed vertices: Use fog coord */
1010 if (!context->fog_coord)
1012 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
1013 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)");
1014 context->fog_coord = TRUE;
1017 else
1019 /* Otherwise, use the fragment depth */
1020 if (context->fog_coord)
1022 gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
1023 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
1024 context->fog_coord = FALSE;
1027 if (state->render_states[WINED3D_RS_RANGEFOGENABLE])
1029 if (gl_info->supported[NV_FOG_DISTANCE])
1031 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
1032 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)");
1034 else
1036 WARN("Range fog enabled, but not supported by this GL implementation.\n");
1039 else if (gl_info->supported[NV_FOG_DISTANCE])
1041 gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
1042 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
1047 void state_fogstartend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1049 const struct wined3d_gl_info *gl_info = context->gl_info;
1050 float fogstart, fogend;
1052 get_fog_start_end(context, state, &fogstart, &fogend);
1054 gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, fogstart);
1055 checkGLcall("glFogf(GL_FOG_START, fogstart)");
1056 TRACE("Fog Start == %f\n", fogstart);
1058 gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, fogend);
1059 checkGLcall("glFogf(GL_FOG_END, fogend)");
1060 TRACE("Fog End == %f\n", fogend);
1063 void state_fog_fragpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1065 const struct wined3d_gl_info *gl_info = context->gl_info;
1066 enum fogsource new_source;
1067 DWORD fogstart = state->render_states[WINED3D_RS_FOGSTART];
1068 DWORD fogend = state->render_states[WINED3D_RS_FOGEND];
1070 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
1072 if (!state->render_states[WINED3D_RS_FOGENABLE])
1074 /* No fog? Disable it, and we're done :-) */
1075 glDisableWINE(GL_FOG);
1076 checkGLcall("glDisable GL_FOG");
1077 return;
1080 /* Fog Rules:
1082 * With fixed function vertex processing, Direct3D knows 2 different fog input sources.
1083 * It can use the Z value of the vertex, or the alpha component of the specular color.
1084 * This depends on the fog vertex, fog table and the vertex declaration. If the Z value
1085 * is used, fogstart, fogend and the equation type are used, otherwise linear fog with
1086 * start = 255, end = 0 is used. Obviously the msdn is not very clear on that.
1088 * FOGTABLEMODE != NONE:
1089 * The Z value is used, with the equation specified, no matter what vertex type.
1091 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, untransformed:
1092 * Per vertex fog is calculated using the specified fog equation and the parameters
1094 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, transformed, OR
1095 * FOGTABLEMODE == NONE, FOGVERTEXMODE == NONE, untransformed:
1096 * Linear fog with start = 255.0, end = 0.0, input comes from the specular color
1099 * Rules for vertex fog with shaders:
1101 * When mixing fixed function functionality with the programmable pipeline, D3D expects
1102 * the fog computation to happen during transformation while openGL expects it to happen
1103 * during rasterization. Also, prior to pixel shader 3.0 D3D handles fog blending after
1104 * the pixel shader while openGL always expects the pixel shader to handle the blending.
1105 * To solve this problem, WineD3D does:
1106 * 1) implement a linear fog equation and fog blending at the end of every pre 3.0 pixel
1107 * shader,
1108 * and 2) disables the fog computation (in either the fixed function or programmable
1109 * rasterizer) if using a vertex program.
1111 * D3D shaders can provide an explicit fog coordinate. This fog coordinate is used with
1112 * D3DRS_FOGTABLEMODE==D3DFOG_NONE. The FOGVERTEXMODE is ignored, d3d always uses linear
1113 * fog with start=1.0 and end=0.0 in this case. This is similar to fog coordinates in
1114 * the specular color, a vertex shader counts as pretransformed geometry in this case.
1115 * There are some GL differences between specular fog coords and vertex shaders though.
1117 * With table fog the vertex shader fog coordinate is ignored.
1119 * If a fogtablemode and a fogvertexmode are specified, table fog is applied (with or
1120 * without shaders).
1123 /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
1124 * the system will apply only pixel(=table) fog effects."
1126 if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
1128 if (use_vs(state))
1130 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1131 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1132 new_source = FOGSOURCE_VS;
1134 else
1136 switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
1138 /* If processed vertices are used, fall through to the NONE case */
1139 case WINED3D_FOG_EXP:
1140 if (!context->last_was_rhw)
1142 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1143 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1144 new_source = FOGSOURCE_FFP;
1145 break;
1147 /* drop through */
1149 case WINED3D_FOG_EXP2:
1150 if (!context->last_was_rhw)
1152 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1153 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1154 new_source = FOGSOURCE_FFP;
1155 break;
1157 /* drop through */
1159 case WINED3D_FOG_LINEAR:
1160 if (!context->last_was_rhw)
1162 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1163 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1164 new_source = FOGSOURCE_FFP;
1165 break;
1167 /* drop through */
1169 case WINED3D_FOG_NONE:
1170 /* Both are none? According to msdn the alpha channel of
1171 * the specular colour contains a fog factor. Set it in
1172 * draw_primitive_immediate_mode(). Same happens with
1173 * vertex fog on transformed vertices. */
1174 new_source = FOGSOURCE_COORD;
1175 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1176 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1177 break;
1179 default:
1180 FIXME("Unexpected WINED3D_RS_FOGVERTEXMODE %#x.\n",
1181 state->render_states[WINED3D_RS_FOGVERTEXMODE]);
1182 new_source = FOGSOURCE_FFP; /* Make the compiler happy */
1185 } else {
1186 new_source = FOGSOURCE_FFP;
1188 switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
1190 case WINED3D_FOG_EXP:
1191 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1192 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1193 break;
1195 case WINED3D_FOG_EXP2:
1196 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1197 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1198 break;
1200 case WINED3D_FOG_LINEAR:
1201 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1202 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1203 break;
1205 case WINED3D_FOG_NONE: /* Won't happen */
1206 default:
1207 FIXME("Unexpected WINED3D_RS_FOGTABLEMODE %#x.\n",
1208 state->render_states[WINED3D_RS_FOGTABLEMODE]);
1212 glEnableWINE(GL_FOG);
1213 checkGLcall("glEnable GL_FOG");
1214 if (new_source != context->fog_source || fogstart == fogend)
1216 context->fog_source = new_source;
1217 state_fogstartend(context, state, STATE_RENDER(WINED3D_RS_FOGSTART));
1221 void state_fogcolor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1223 const struct wined3d_gl_info *gl_info = context->gl_info;
1224 struct wined3d_color color;
1226 wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_FOGCOLOR]);
1227 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, &color.r);
1228 checkGLcall("glFog GL_FOG_COLOR");
1231 void state_fogdensity(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1233 const struct wined3d_gl_info *gl_info = context->gl_info;
1234 union {
1235 DWORD d;
1236 float f;
1237 } tmpvalue;
1239 tmpvalue.d = state->render_states[WINED3D_RS_FOGDENSITY];
1240 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
1241 checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
1244 static void state_colormat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1246 const struct wined3d_gl_info *gl_info = context->gl_info;
1247 GLenum Parm = 0;
1249 /* Depends on the decoded vertex declaration to read the existence of diffuse data.
1250 * The vertex declaration will call this function if the fixed function pipeline is used.
1253 if(isStateDirty(context, STATE_VDECL)) {
1254 return;
1257 context->num_untracked_materials = 0;
1258 if ((context->stream_info.use_map & (1u << WINED3D_FFP_DIFFUSE))
1259 && state->render_states[WINED3D_RS_COLORVERTEX])
1261 TRACE("diff %d, amb %d, emis %d, spec %d\n",
1262 state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE],
1263 state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE],
1264 state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE],
1265 state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]);
1267 if (state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1269 if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1270 Parm = GL_AMBIENT_AND_DIFFUSE;
1271 else
1272 Parm = GL_DIFFUSE;
1273 if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1275 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1276 context->num_untracked_materials++;
1278 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1280 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1281 context->num_untracked_materials++;
1284 else if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1286 Parm = GL_AMBIENT;
1287 if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1289 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1290 context->num_untracked_materials++;
1292 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1294 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1295 context->num_untracked_materials++;
1298 else if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1300 Parm = GL_EMISSION;
1301 if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1303 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1304 context->num_untracked_materials++;
1307 else if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1309 Parm = GL_SPECULAR;
1313 /* Nothing changed, return. */
1314 if (Parm == context->tracking_parm) return;
1316 if (!Parm)
1318 gl_info->gl_ops.gl.p_glDisable(GL_COLOR_MATERIAL);
1319 checkGLcall("glDisable GL_COLOR_MATERIAL");
1321 else
1323 gl_info->gl_ops.gl.p_glColorMaterial(GL_FRONT_AND_BACK, Parm);
1324 checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
1325 gl_info->gl_ops.gl.p_glEnable(GL_COLOR_MATERIAL);
1326 checkGLcall("glEnable(GL_COLOR_MATERIAL)");
1329 /* Apparently calls to glMaterialfv are ignored for properties we're
1330 * tracking with glColorMaterial, so apply those here. */
1331 switch (context->tracking_parm)
1333 case GL_AMBIENT_AND_DIFFUSE:
1334 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
1335 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1336 checkGLcall("glMaterialfv");
1337 break;
1339 case GL_DIFFUSE:
1340 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1341 checkGLcall("glMaterialfv");
1342 break;
1344 case GL_AMBIENT:
1345 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
1346 checkGLcall("glMaterialfv");
1347 break;
1349 case GL_EMISSION:
1350 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
1351 checkGLcall("glMaterialfv");
1352 break;
1354 case GL_SPECULAR:
1355 /* Only change material color if specular is enabled, otherwise it is set to black */
1356 if (state->render_states[WINED3D_RS_SPECULARENABLE])
1358 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
1359 checkGLcall("glMaterialfv");
1361 else
1363 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
1364 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
1365 checkGLcall("glMaterialfv");
1367 break;
1370 context->tracking_parm = Parm;
1373 static void state_linepattern(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1375 const struct wined3d_gl_info *gl_info = context->gl_info;
1376 union
1378 DWORD d;
1379 struct wined3d_line_pattern lp;
1380 } tmppattern;
1381 tmppattern.d = state->render_states[WINED3D_RS_LINEPATTERN];
1383 TRACE("Line pattern: repeat %d bits %x.\n", tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1385 if (tmppattern.lp.repeat_factor)
1387 gl_info->gl_ops.gl.p_glLineStipple(tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1388 checkGLcall("glLineStipple(repeat, linepattern)");
1389 gl_info->gl_ops.gl.p_glEnable(GL_LINE_STIPPLE);
1390 checkGLcall("glEnable(GL_LINE_STIPPLE);");
1392 else
1394 gl_info->gl_ops.gl.p_glDisable(GL_LINE_STIPPLE);
1395 checkGLcall("glDisable(GL_LINE_STIPPLE);");
1399 static void state_linepattern_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1401 static unsigned int once;
1403 if (!once++)
1404 FIXME("Setting line patterns is not supported in OpenGL core contexts.\n");
1407 static void state_normalize(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1409 const struct wined3d_gl_info *gl_info = context->gl_info;
1411 if (isStateDirty(context, STATE_VDECL))
1412 return;
1414 /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor
1415 * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division
1416 * by zero and is not properly defined in opengl, so avoid it
1418 if (state->render_states[WINED3D_RS_NORMALIZENORMALS]
1419 && (context->stream_info.use_map & (1u << WINED3D_FFP_NORMAL)))
1421 gl_info->gl_ops.gl.p_glEnable(GL_NORMALIZE);
1422 checkGLcall("glEnable(GL_NORMALIZE);");
1424 else
1426 gl_info->gl_ops.gl.p_glDisable(GL_NORMALIZE);
1427 checkGLcall("glDisable(GL_NORMALIZE);");
1431 static void state_psizemin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1433 float min, max;
1435 get_pointsize_minmax(context, state, &min, &max);
1437 if (min != 1.0f)
1438 FIXME("WINED3D_RS_POINTSIZE_MIN value %.8e not supported on this OpenGL implementation.\n", min);
1439 if (max != 64.0f)
1440 FIXME("WINED3D_RS_POINTSIZE_MAX value %.8e not supported on this OpenGL implementation.\n", max);
1443 static void state_psizemin_ext(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1445 const struct wined3d_gl_info *gl_info = context->gl_info;
1446 float min, max;
1448 get_pointsize_minmax(context, state, &min, &max);
1450 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, min);
1451 checkGLcall("glPointParameterfEXT(...)");
1452 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, max);
1453 checkGLcall("glPointParameterfEXT(...)");
1456 static void state_psizemin_arb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1458 const struct wined3d_gl_info *gl_info = context->gl_info;
1459 float min, max;
1461 get_pointsize_minmax(context, state, &min, &max);
1463 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, min);
1464 checkGLcall("glPointParameterfARB(...)");
1465 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, max);
1466 checkGLcall("glPointParameterfARB(...)");
1469 static void state_pscale(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1471 const struct wined3d_gl_info *gl_info = context->gl_info;
1472 float att[3];
1473 float pointsize;
1475 get_pointsize(context, state, &pointsize, att);
1477 if (gl_info->supported[ARB_POINT_PARAMETERS])
1479 GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
1480 checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...)");
1482 else if (gl_info->supported[EXT_POINT_PARAMETERS])
1484 GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
1485 checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)");
1487 else if (state->render_states[WINED3D_RS_POINTSCALEENABLE])
1489 WARN("POINT_PARAMETERS not supported in this version of opengl\n");
1492 gl_info->gl_ops.gl.p_glPointSize(max(pointsize, FLT_MIN));
1493 checkGLcall("glPointSize(...);");
1496 static void state_debug_monitor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1498 WARN("token: %#x.\n", state->render_states[WINED3D_RS_DEBUGMONITORTOKEN]);
1501 static void state_colorwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1503 DWORD mask0 = state->render_states[WINED3D_RS_COLORWRITEENABLE];
1504 DWORD mask1 = state->render_states[WINED3D_RS_COLORWRITEENABLE1];
1505 DWORD mask2 = state->render_states[WINED3D_RS_COLORWRITEENABLE2];
1506 DWORD mask3 = state->render_states[WINED3D_RS_COLORWRITEENABLE3];
1507 const struct wined3d_gl_info *gl_info = context->gl_info;
1509 TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
1510 mask0 & WINED3DCOLORWRITEENABLE_RED ? 1 : 0,
1511 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? 1 : 0,
1512 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? 1 : 0,
1513 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1514 gl_info->gl_ops.gl.p_glColorMask(mask0 & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1515 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1516 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1517 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1518 checkGLcall("glColorMask(...)");
1520 if (!((mask1 == mask0 && mask2 == mask0 && mask3 == mask0)
1521 || (mask1 == 0xf && mask2 == 0xf && mask3 == 0xf)))
1523 FIXME("WINED3D_RS_COLORWRITEENABLE/1/2/3, %#x/%#x/%#x/%#x not yet implemented.\n",
1524 mask0, mask1, mask2, mask3);
1525 FIXME("Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n");
1529 static void set_color_mask(const struct wined3d_gl_info *gl_info, UINT index, DWORD mask)
1531 GL_EXTCALL(glColorMaski(index,
1532 mask & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1533 mask & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1534 mask & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1535 mask & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE));
1536 checkGLcall("glColorMaski");
1539 static void state_colorwrite0(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1541 set_color_mask(context->gl_info, 0, state->render_states[WINED3D_RS_COLORWRITEENABLE]);
1544 static void state_colorwrite1(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1546 set_color_mask(context->gl_info, 1, state->render_states[WINED3D_RS_COLORWRITEENABLE1]);
1549 static void state_colorwrite2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1551 set_color_mask(context->gl_info, 2, state->render_states[WINED3D_RS_COLORWRITEENABLE2]);
1554 static void state_colorwrite3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1556 set_color_mask(context->gl_info, 3, state->render_states[WINED3D_RS_COLORWRITEENABLE3]);
1559 static void state_localviewer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1561 const struct wined3d_gl_info *gl_info = context->gl_info;
1563 if (state->render_states[WINED3D_RS_LOCALVIEWER])
1565 gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1566 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1568 else
1570 gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1571 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
1575 static void state_lastpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1577 if (state->render_states[WINED3D_RS_LASTPIXEL])
1579 TRACE("Last Pixel Drawing Enabled\n");
1581 else
1583 static BOOL warned;
1584 if (!warned) {
1585 FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1586 warned = TRUE;
1587 } else {
1588 TRACE("Last Pixel Drawing Disabled, not handled yet\n");
1593 void state_pointsprite_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1595 static BOOL warned;
1597 /* TODO: NV_POINT_SPRITE */
1598 if (!warned && state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1600 /* A FIXME, not a WARN because point sprites should be software emulated if not supported by HW */
1601 FIXME("Point sprites not supported\n");
1602 warned = TRUE;
1606 void state_pointsprite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1608 const struct wined3d_gl_info *gl_info = context->gl_info;
1610 if (state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1612 gl_info->gl_ops.gl.p_glEnable(GL_POINT_SPRITE_ARB);
1613 checkGLcall("glEnable(GL_POINT_SPRITE_ARB)");
1615 else
1617 gl_info->gl_ops.gl.p_glDisable(GL_POINT_SPRITE_ARB);
1618 checkGLcall("glDisable(GL_POINT_SPRITE_ARB)");
1622 static void state_wrap(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1624 static unsigned int once;
1626 if ((state->render_states[WINED3D_RS_WRAP0]
1627 || state->render_states[WINED3D_RS_WRAP1]
1628 || state->render_states[WINED3D_RS_WRAP2]
1629 || state->render_states[WINED3D_RS_WRAP3]
1630 || state->render_states[WINED3D_RS_WRAP4]
1631 || state->render_states[WINED3D_RS_WRAP5]
1632 || state->render_states[WINED3D_RS_WRAP6]
1633 || state->render_states[WINED3D_RS_WRAP7]
1634 || state->render_states[WINED3D_RS_WRAP8]
1635 || state->render_states[WINED3D_RS_WRAP9]
1636 || state->render_states[WINED3D_RS_WRAP10]
1637 || state->render_states[WINED3D_RS_WRAP11]
1638 || state->render_states[WINED3D_RS_WRAP12]
1639 || state->render_states[WINED3D_RS_WRAP13]
1640 || state->render_states[WINED3D_RS_WRAP14]
1641 || state->render_states[WINED3D_RS_WRAP15])
1642 && !once++)
1643 FIXME("(WINED3D_RS_WRAP0) Texture wrapping not yet supported.\n");
1646 static void state_msaa_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1648 if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1649 WARN("Multisample antialiasing not supported by GL.\n");
1652 static void state_msaa(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1654 const struct wined3d_gl_info *gl_info = context->gl_info;
1656 if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1658 gl_info->gl_ops.gl.p_glEnable(GL_MULTISAMPLE_ARB);
1659 checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1661 else
1663 gl_info->gl_ops.gl.p_glDisable(GL_MULTISAMPLE_ARB);
1664 checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1668 static void state_line_antialias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1670 const struct wined3d_gl_info *gl_info = context->gl_info;
1672 if (state->render_states[WINED3D_RS_EDGEANTIALIAS]
1673 || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE])
1675 gl_info->gl_ops.gl.p_glEnable(GL_LINE_SMOOTH);
1676 checkGLcall("glEnable(GL_LINE_SMOOTH)");
1678 else
1680 gl_info->gl_ops.gl.p_glDisable(GL_LINE_SMOOTH);
1681 checkGLcall("glDisable(GL_LINE_SMOOTH)");
1685 static void state_scissor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1687 const struct wined3d_gl_info *gl_info = context->gl_info;
1689 if (state->render_states[WINED3D_RS_SCISSORTESTENABLE])
1691 gl_info->gl_ops.gl.p_glEnable(GL_SCISSOR_TEST);
1692 checkGLcall("glEnable(GL_SCISSOR_TEST)");
1694 else
1696 gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
1697 checkGLcall("glDisable(GL_SCISSOR_TEST)");
1701 /* The Direct3D depth bias is specified in normalized depth coordinates. In
1702 * OpenGL the bias is specified in units of "the smallest value that is
1703 * guaranteed to produce a resolvable offset for a given implementation". To
1704 * convert from D3D to GL we need to divide the D3D depth bias by that value.
1705 * We try to detect the value from GL with test draws. On most drivers (r300g,
1706 * 600g, Nvidia, i965 on Mesa) the value is 2^23 for fixed point depth buffers,
1707 * for r200 and i965 on OSX it is 2^24, for r500 on OSX it is 2^22. For floating
1708 * point buffers it is 2^22, 2^23 or 2^24 depending on the GPU. The value does
1709 * not depend on the depth buffer precision on any driver.
1711 * Two games that are picky regarding depth bias are Mass Effect 2 (flickering
1712 * decals) and F.E.A.R and F.E.A.R. 2 (semi-transparent guns).
1714 * Note that SLOPESCALEDEPTHBIAS is a scaling factor for the depth slope, and
1715 * doesn't need to be scaled to account for GL vs D3D differences. */
1716 static void state_depthbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1718 const struct wined3d_gl_info *gl_info = context->gl_info;
1720 if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]
1721 || state->render_states[WINED3D_RS_DEPTHBIAS])
1723 const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil;
1724 float scale;
1726 union
1728 DWORD d;
1729 float f;
1730 } scale_bias, const_bias;
1732 scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS];
1733 const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS];
1735 gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
1736 checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
1738 if (context->d3d_info->wined3d_creation_flags & WINED3D_LEGACY_DEPTH_BIAS)
1740 float bias = -(float)const_bias.d;
1741 gl_info->gl_ops.gl.p_glPolygonOffset(bias, bias);
1742 checkGLcall("glPolygonOffset");
1744 else
1746 if (depth)
1748 if (depth->format_flags & WINED3DFMT_FLAG_FLOAT)
1749 scale = gl_info->float_polyoffset_scale;
1750 else
1751 scale = gl_info->fixed_polyoffset_scale;
1753 TRACE("Depth format %s, using depthbias scale of %.8e.\n",
1754 debug_d3dformat(depth->format->id), scale);
1756 else
1758 /* The context manager will reapply this state on a depth stencil change */
1759 TRACE("No depth stencil, using depthbias scale of 0.0.\n");
1760 scale = 0.0f;
1763 gl_info->gl_ops.gl.p_glPolygonOffset(scale_bias.f, const_bias.f * scale);
1764 checkGLcall("glPolygonOffset(...)");
1767 else
1769 gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL);
1770 checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
1774 static void state_zvisible(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1776 if (state->render_states[WINED3D_RS_ZVISIBLE])
1777 FIXME("WINED3D_RS_ZVISIBLE not implemented.\n");
1780 static void state_stippledalpha(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1782 if (state->render_states[WINED3D_RS_STIPPLEDALPHA])
1783 FIXME("Stippled Alpha not supported yet.\n");
1786 static void state_antialias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1788 if (state->render_states[WINED3D_RS_ANTIALIAS])
1789 FIXME("Antialias not supported yet.\n");
1792 static void state_multisampmask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1794 if (state->render_states[WINED3D_RS_MULTISAMPLEMASK] != 0xffffffff)
1795 FIXME("WINED3D_RS_MULTISAMPLEMASK %#x not yet implemented.\n",
1796 state->render_states[WINED3D_RS_MULTISAMPLEMASK]);
1799 static void state_patchedgestyle(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1801 if (state->render_states[WINED3D_RS_PATCHEDGESTYLE] != WINED3D_PATCH_EDGE_DISCRETE)
1802 FIXME("WINED3D_RS_PATCHEDGESTYLE %#x not yet implemented.\n",
1803 state->render_states[WINED3D_RS_PATCHEDGESTYLE]);
1806 static void state_patchsegments(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1808 union {
1809 DWORD d;
1810 float f;
1811 } tmpvalue;
1812 tmpvalue.f = 1.0f;
1814 if (state->render_states[WINED3D_RS_PATCHSEGMENTS] != tmpvalue.d)
1816 static BOOL displayed = FALSE;
1818 tmpvalue.d = state->render_states[WINED3D_RS_PATCHSEGMENTS];
1819 if(!displayed)
1820 FIXME("(WINED3D_RS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f);
1822 displayed = TRUE;
1826 static void state_positiondegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1828 if (state->render_states[WINED3D_RS_POSITIONDEGREE] != WINED3D_DEGREE_CUBIC)
1829 FIXME("WINED3D_RS_POSITIONDEGREE %#x not yet implemented.\n",
1830 state->render_states[WINED3D_RS_POSITIONDEGREE]);
1833 static void state_normaldegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1835 if (state->render_states[WINED3D_RS_NORMALDEGREE] != WINED3D_DEGREE_LINEAR)
1836 FIXME("WINED3D_RS_NORMALDEGREE %#x not yet implemented.\n",
1837 state->render_states[WINED3D_RS_NORMALDEGREE]);
1840 static void state_tessellation(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1842 if (state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION])
1843 FIXME("WINED3D_RS_ENABLEADAPTIVETESSELLATION %#x not yet implemented.\n",
1844 state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION]);
1847 static void state_nvdb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1849 union {
1850 DWORD d;
1851 float f;
1852 } zmin, zmax;
1854 const struct wined3d_gl_info *gl_info = context->gl_info;
1856 if (state->render_states[WINED3D_RS_ADAPTIVETESS_X] == WINED3DFMT_NVDB)
1858 zmin.d = state->render_states[WINED3D_RS_ADAPTIVETESS_Z];
1859 zmax.d = state->render_states[WINED3D_RS_ADAPTIVETESS_W];
1861 /* If zmin is larger than zmax INVALID_VALUE error is generated.
1862 * In d3d9 test is not performed in this case*/
1863 if (zmin.f <= zmax.f)
1865 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_BOUNDS_TEST_EXT);
1866 checkGLcall("glEnable(GL_DEPTH_BOUNDS_TEST_EXT)");
1867 GL_EXTCALL(glDepthBoundsEXT(zmin.f, zmax.f));
1868 checkGLcall("glDepthBoundsEXT(...)");
1870 else
1872 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1873 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1876 else
1878 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1879 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1882 state_tessellation(context, state, STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION));
1885 static void state_wrapu(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1887 if (state->render_states[WINED3D_RS_WRAPU])
1888 FIXME("Render state WINED3D_RS_WRAPU not implemented yet.\n");
1891 static void state_wrapv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1893 if (state->render_states[WINED3D_RS_WRAPV])
1894 FIXME("Render state WINED3D_RS_WRAPV not implemented yet.\n");
1897 static void state_monoenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1899 if (state->render_states[WINED3D_RS_MONOENABLE])
1900 FIXME("Render state WINED3D_RS_MONOENABLE not implemented yet.\n");
1903 static void state_rop2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1905 if (state->render_states[WINED3D_RS_ROP2])
1906 FIXME("Render state WINED3D_RS_ROP2 not implemented yet.\n");
1909 static void state_planemask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1911 if (state->render_states[WINED3D_RS_PLANEMASK])
1912 FIXME("Render state WINED3D_RS_PLANEMASK not implemented yet.\n");
1915 static void state_subpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1917 if (state->render_states[WINED3D_RS_SUBPIXEL])
1918 FIXME("Render state WINED3D_RS_SUBPIXEL not implemented yet.\n");
1921 static void state_subpixelx(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1923 if (state->render_states[WINED3D_RS_SUBPIXELX])
1924 FIXME("Render state WINED3D_RS_SUBPIXELX not implemented yet.\n");
1927 static void state_stippleenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1929 if (state->render_states[WINED3D_RS_STIPPLEENABLE])
1930 FIXME("Render state WINED3D_RS_STIPPLEENABLE not implemented yet.\n");
1933 static void state_mipmaplodbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1935 if (state->render_states[WINED3D_RS_MIPMAPLODBIAS])
1936 FIXME("Render state WINED3D_RS_MIPMAPLODBIAS not implemented yet.\n");
1939 static void state_anisotropy(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1941 if (state->render_states[WINED3D_RS_ANISOTROPY])
1942 FIXME("Render state WINED3D_RS_ANISOTROPY not implemented yet.\n");
1945 static void state_flushbatch(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1947 if (state->render_states[WINED3D_RS_FLUSHBATCH])
1948 FIXME("Render state WINED3D_RS_FLUSHBATCH not implemented yet.\n");
1951 static void state_translucentsi(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1953 if (state->render_states[WINED3D_RS_TRANSLUCENTSORTINDEPENDENT])
1954 FIXME("Render state WINED3D_RS_TRANSLUCENTSORTINDEPENDENT not implemented yet.\n");
1957 static void state_extents(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1959 if (state->render_states[WINED3D_RS_EXTENTS])
1960 FIXME("Render state WINED3D_RS_EXTENTS not implemented yet.\n");
1963 static void state_ckeyblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1965 if (state->render_states[WINED3D_RS_COLORKEYBLENDENABLE])
1966 FIXME("Render state WINED3D_RS_COLORKEYBLENDENABLE not implemented yet.\n");
1969 static void state_swvp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1971 static int once;
1972 if (state->render_states[WINED3D_RS_SOFTWAREVERTEXPROCESSING])
1974 if (!once++)
1975 FIXME("Software vertex processing not implemented.\n");
1979 static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* operand) {
1980 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the
1981 * input should be used for all input components. The WINED3DTA_COMPLEMENT
1982 * flag specifies the complement of the input should be used. */
1983 BOOL from_alpha = is_alpha || arg & WINED3DTA_ALPHAREPLICATE;
1984 BOOL complement = arg & WINED3DTA_COMPLEMENT;
1986 /* Calculate the operand */
1987 if (complement) {
1988 if (from_alpha) *operand = GL_ONE_MINUS_SRC_ALPHA;
1989 else *operand = GL_ONE_MINUS_SRC_COLOR;
1990 } else {
1991 if (from_alpha) *operand = GL_SRC_ALPHA;
1992 else *operand = GL_SRC_COLOR;
1995 /* Calculate the source */
1996 switch (arg & WINED3DTA_SELECTMASK) {
1997 case WINED3DTA_CURRENT: *source = GL_PREVIOUS_EXT; break;
1998 case WINED3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT; break;
1999 case WINED3DTA_TEXTURE: *source = GL_TEXTURE; break;
2000 case WINED3DTA_TFACTOR: *source = GL_CONSTANT_EXT; break;
2001 case WINED3DTA_SPECULAR:
2003 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
2004 * 'Secondary color' and isn't supported until base GL supports it
2005 * There is no concept of temp registers as far as I can tell
2007 FIXME("Unhandled texture arg WINED3DTA_SPECULAR\n");
2008 *source = GL_TEXTURE;
2009 break;
2010 default:
2011 FIXME("Unrecognized texture arg %#x\n", arg);
2012 *source = GL_TEXTURE;
2013 break;
2017 /* Setup the texture operations texture stage states */
2018 static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
2019 BOOL isAlpha, int Stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3)
2021 GLenum src1, src2, src3;
2022 GLenum opr1, opr2, opr3;
2023 GLenum comb_target;
2024 GLenum src0_target, src1_target, src2_target;
2025 GLenum opr0_target, opr1_target, opr2_target;
2026 GLenum scal_target;
2027 GLenum opr=0, invopr, src3_target, opr3_target;
2028 BOOL Handled = FALSE;
2030 TRACE("Alpha?(%d), Stage:%d Op(%s), a1(%d), a2(%d), a3(%d)\n", isAlpha, Stage, debug_d3dtop(op), arg1, arg2, arg3);
2032 /* Operations usually involve two args, src0 and src1 and are operations
2033 * of the form (a1 <operation> a2). However, some of the more complex
2034 * operations take 3 parameters. Instead of the (sensible) addition of a3,
2035 * Microsoft added in a third parameter called a0. Therefore these are
2036 * operations of the form a0 <operation> a1 <operation> a2. I.e., the new
2037 * parameter goes to the front.
2039 * However, below we treat the new (a0) parameter as src2/opr2, so in the
2040 * actual functions below, expect their syntax to differ slightly to those
2041 * listed in the manuals. I.e., replace arg1 with arg3, arg2 with arg1 and
2042 * arg3 with arg2. This affects WINED3DTOP_MULTIPLYADD and WINED3DTOP_LERP. */
2044 if (isAlpha)
2046 comb_target = GL_COMBINE_ALPHA;
2047 src0_target = GL_SOURCE0_ALPHA;
2048 src1_target = GL_SOURCE1_ALPHA;
2049 src2_target = GL_SOURCE2_ALPHA;
2050 opr0_target = GL_OPERAND0_ALPHA;
2051 opr1_target = GL_OPERAND1_ALPHA;
2052 opr2_target = GL_OPERAND2_ALPHA;
2053 scal_target = GL_ALPHA_SCALE;
2055 else
2057 comb_target = GL_COMBINE_RGB;
2058 src0_target = GL_SOURCE0_RGB;
2059 src1_target = GL_SOURCE1_RGB;
2060 src2_target = GL_SOURCE2_RGB;
2061 opr0_target = GL_OPERAND0_RGB;
2062 opr1_target = GL_OPERAND1_RGB;
2063 opr2_target = GL_OPERAND2_RGB;
2064 scal_target = GL_RGB_SCALE;
2067 /* If a texture stage references an invalid texture unit the stage just
2068 * passes through the result from the previous stage */
2069 if (is_invalid_op(state, Stage, op, arg1, arg2, arg3))
2071 arg1 = WINED3DTA_CURRENT;
2072 op = WINED3D_TOP_SELECT_ARG1;
2075 if (isAlpha && !state->textures[Stage] && arg1 == WINED3DTA_TEXTURE)
2077 get_src_and_opr(WINED3DTA_DIFFUSE, isAlpha, &src1, &opr1);
2078 } else {
2079 get_src_and_opr(arg1, isAlpha, &src1, &opr1);
2081 get_src_and_opr(arg2, isAlpha, &src2, &opr2);
2082 get_src_and_opr(arg3, isAlpha, &src3, &opr3);
2084 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
2086 Handled = TRUE; /* Assume will be handled */
2088 /* Other texture operations require special extensions: */
2089 if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
2091 if (isAlpha) {
2092 opr = GL_SRC_ALPHA;
2093 invopr = GL_ONE_MINUS_SRC_ALPHA;
2094 src3_target = GL_SOURCE3_ALPHA_NV;
2095 opr3_target = GL_OPERAND3_ALPHA_NV;
2096 } else {
2097 opr = GL_SRC_COLOR;
2098 invopr = GL_ONE_MINUS_SRC_COLOR;
2099 src3_target = GL_SOURCE3_RGB_NV;
2100 opr3_target = GL_OPERAND3_RGB_NV;
2102 switch (op)
2104 case WINED3D_TOP_DISABLE: /* Only for alpha */
2105 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2106 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2107 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2108 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2109 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2110 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2111 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2112 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2113 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2114 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2115 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2116 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2117 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2118 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2119 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2120 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2121 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2122 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2123 break;
2125 case WINED3D_TOP_SELECT_ARG1: /* = a1 * 1 + 0 * 0 */
2126 case WINED3D_TOP_SELECT_ARG2: /* = a2 * 1 + 0 * 0 */
2127 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2128 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2129 if (op == WINED3D_TOP_SELECT_ARG1)
2131 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2132 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2133 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2134 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2136 else
2138 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2139 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2140 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2141 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2143 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2144 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2145 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2146 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2147 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2148 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2149 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2150 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2151 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2152 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2153 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2154 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2155 break;
2157 case WINED3D_TOP_MODULATE:
2158 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2159 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2160 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2161 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2162 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2163 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2164 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2165 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2166 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2167 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2168 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2169 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2170 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2171 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2172 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2173 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2174 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2175 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2176 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2177 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2178 break;
2179 case WINED3D_TOP_MODULATE_2X:
2180 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2181 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2182 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2183 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2184 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2185 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2186 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2187 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2188 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2189 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2190 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2191 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2192 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2193 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2194 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2195 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2196 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2197 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2198 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2199 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2200 break;
2201 case WINED3D_TOP_MODULATE_4X:
2202 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2203 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2204 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2205 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2206 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2207 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2208 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2209 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2210 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2211 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2212 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2213 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2214 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2215 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2216 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2217 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2218 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2219 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2220 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2221 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2222 break;
2224 case WINED3D_TOP_ADD:
2225 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2226 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2227 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2228 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2229 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2230 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2231 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2232 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2233 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2234 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2235 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2236 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2237 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2238 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2239 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2240 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2241 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2242 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2243 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2244 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2245 break;
2247 case WINED3D_TOP_ADD_SIGNED:
2248 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2249 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2250 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2251 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2252 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2253 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2254 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2255 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2256 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2257 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2258 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2259 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2260 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2261 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2262 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2263 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2264 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2265 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2266 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2267 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2268 break;
2270 case WINED3D_TOP_ADD_SIGNED_2X:
2271 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2272 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2273 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2274 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2275 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2276 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2277 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2278 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2279 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2280 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2281 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2282 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2283 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2284 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2285 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2286 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2287 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2288 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2289 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2290 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2291 break;
2293 case WINED3D_TOP_ADD_SMOOTH:
2294 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2295 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2296 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2297 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2298 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2299 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2300 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2301 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2302 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2303 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2304 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2305 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2306 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2307 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2308 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2309 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2310 switch (opr1) {
2311 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2312 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2313 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2314 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2316 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2317 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2318 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2319 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2320 break;
2322 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2323 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2324 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2325 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2326 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2327 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2328 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2329 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR);
2330 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR");
2331 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2332 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2333 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2334 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2335 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2336 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2337 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR);
2338 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR");
2339 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2340 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2341 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2342 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2343 break;
2344 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2345 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2346 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2347 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2348 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2349 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2350 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2351 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
2352 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
2353 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2354 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2355 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2356 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2357 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2358 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2359 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2360 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2361 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2362 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2363 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2364 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2365 break;
2366 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2367 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2368 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2369 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2370 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2371 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2372 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2373 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_CONSTANT);
2374 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_CONSTANT");
2375 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2376 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2377 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2378 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2379 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2380 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2381 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_CONSTANT);
2382 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_CONSTANT");
2383 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2384 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2385 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2386 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2387 break;
2388 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2389 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2390 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2391 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2392 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2393 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2394 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2395 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2396 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2397 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2398 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2399 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2400 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2401 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2402 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2403 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2404 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2405 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2406 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2407 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2408 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2409 break;
2410 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2411 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2412 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2413 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
2414 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2415 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2416 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
2417 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2418 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2419 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2420 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2421 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
2422 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2423 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2424 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
2425 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2426 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2427 switch (opr) {
2428 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2429 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2431 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2432 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2433 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2434 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2435 break;
2436 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2437 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2438 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2439 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2440 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2441 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2442 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2443 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2444 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2445 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2446 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2447 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2448 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2449 switch (opr1) {
2450 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2451 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2453 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2454 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2455 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2456 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2457 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2458 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2459 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2460 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2461 break;
2462 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2463 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2464 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2465 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2466 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2467 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2468 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2469 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2470 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2471 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2472 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2473 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2474 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2475 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2476 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2477 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2478 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2479 switch (opr1) {
2480 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2481 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2482 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2483 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2485 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2486 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2487 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2488 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2489 break;
2490 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
2491 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2492 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2493 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2494 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2495 switch (opr1) {
2496 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2497 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2498 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2499 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2501 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2502 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2503 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2504 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2505 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2506 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2507 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2508 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2509 switch (opr1) {
2510 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2511 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2513 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2514 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2515 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2516 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2517 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2518 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2519 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2520 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2521 break;
2522 case WINED3D_TOP_MULTIPLY_ADD:
2523 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2524 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2525 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
2526 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2527 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
2528 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2529 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2530 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2531 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2532 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2533 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2534 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2535 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
2536 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2537 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
2538 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
2539 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
2540 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
2541 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2542 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2543 break;
2545 case WINED3D_TOP_BUMPENVMAP:
2546 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
2547 FIXME("Implement bump environment mapping in GL_NV_texture_env_combine4 path\n");
2548 Handled = FALSE;
2549 break;
2551 default:
2552 Handled = FALSE;
2554 if (Handled)
2556 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
2557 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
2559 return;
2561 } /* GL_NV_texture_env_combine4 */
2563 Handled = TRUE; /* Again, assume handled */
2564 switch (op) {
2565 case WINED3D_TOP_DISABLE: /* Only for alpha */
2566 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2567 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2568 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2569 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
2570 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2571 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
2572 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2573 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2574 break;
2575 case WINED3D_TOP_SELECT_ARG1:
2576 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2577 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2578 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2579 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2580 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2581 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2582 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2583 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2584 break;
2585 case WINED3D_TOP_SELECT_ARG2:
2586 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2587 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2588 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2589 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2590 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2591 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2592 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2593 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2594 break;
2595 case WINED3D_TOP_MODULATE:
2596 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2597 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2598 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2599 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2600 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2601 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2602 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2603 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2604 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2605 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2606 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2607 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2608 break;
2609 case WINED3D_TOP_MODULATE_2X:
2610 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2611 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2612 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2613 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2614 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2615 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2616 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2617 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2618 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2619 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2620 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2621 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2622 break;
2623 case WINED3D_TOP_MODULATE_4X:
2624 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2625 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2626 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2627 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2628 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2629 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2630 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2631 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2632 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2633 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2634 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2635 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2636 break;
2637 case WINED3D_TOP_ADD:
2638 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2639 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2640 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2641 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2642 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2643 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2644 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2645 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2646 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2647 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2648 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2649 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2650 break;
2651 case WINED3D_TOP_ADD_SIGNED:
2652 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2653 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2654 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2655 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2656 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2657 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2658 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2659 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2660 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2661 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2662 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2663 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2664 break;
2665 case WINED3D_TOP_ADD_SIGNED_2X:
2666 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2667 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2668 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2669 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2670 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2671 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2672 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2673 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2674 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2675 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2676 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2677 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2678 break;
2679 case WINED3D_TOP_SUBTRACT:
2680 if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE])
2682 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
2683 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_SUBTRACT");
2684 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2685 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2686 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2687 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2688 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2689 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2690 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2691 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2692 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2693 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2694 } else {
2695 FIXME("This version of opengl does not support GL_SUBTRACT\n");
2697 break;
2699 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2700 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2701 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2702 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2703 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2704 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2705 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2706 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2707 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2708 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2709 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2710 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR);
2711 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
2712 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2713 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2714 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2715 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2716 break;
2717 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2718 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2719 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2720 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2721 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2722 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2723 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2724 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2725 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2726 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2727 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2728 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
2729 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
2730 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2731 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2732 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2733 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2734 break;
2735 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2736 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2737 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2738 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2739 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2740 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2741 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2742 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2743 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2744 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2745 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2746 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_CONSTANT);
2747 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
2748 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2749 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2750 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2751 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2752 break;
2753 case WINED3D_TOP_BLEND_CURRENT_ALPHA:
2754 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2755 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2756 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2757 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2758 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2759 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2760 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2761 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2762 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2763 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2764 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PREVIOUS);
2765 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
2766 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2767 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2768 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2769 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2770 break;
2771 case WINED3D_TOP_DOTPRODUCT3:
2772 if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
2774 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
2775 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
2777 else if (gl_info->supported[EXT_TEXTURE_ENV_DOT3])
2779 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
2780 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
2781 } else {
2782 FIXME("This version of opengl does not support GL_DOT3\n");
2784 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2785 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2786 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2787 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2788 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2789 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2790 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2791 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2792 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2793 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2794 break;
2795 case WINED3D_TOP_LERP:
2796 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2797 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2798 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2799 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2800 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2801 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2802 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2803 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2804 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2805 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2806 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
2807 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
2808 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
2809 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
2810 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2811 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2812 break;
2813 case WINED3D_TOP_ADD_SMOOTH:
2814 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2816 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2817 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2818 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2819 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2820 switch (opr1) {
2821 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2822 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2823 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2824 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2826 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2827 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2828 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2829 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2830 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2831 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2832 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2833 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2834 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2835 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2836 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2837 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2838 } else
2839 Handled = FALSE;
2840 break;
2841 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2842 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2844 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2845 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2846 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
2847 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
2848 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
2849 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
2850 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2851 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2852 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2853 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2854 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2855 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2856 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2857 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2858 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2859 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2860 } else
2861 Handled = FALSE;
2862 break;
2863 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2864 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2866 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2867 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2868 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2869 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2870 switch (opr1) {
2871 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2872 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2873 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2874 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2876 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2877 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2878 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2879 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2880 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2881 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2882 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2883 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2884 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2885 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2886 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2887 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2888 } else
2889 Handled = FALSE;
2890 break;
2891 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2892 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2894 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2895 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2896 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2897 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2898 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2899 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2900 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2901 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2902 switch (opr1) {
2903 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2904 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2905 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2906 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2908 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2909 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2910 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2911 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2912 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2913 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2914 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2915 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2916 } else
2917 Handled = FALSE;
2918 break;
2919 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2920 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2922 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2923 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2924 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2925 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2926 switch (opr1) {
2927 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2928 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2929 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2930 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2932 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2933 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2934 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2935 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2936 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2937 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2938 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2939 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2940 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2941 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2942 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2943 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2944 } else
2945 Handled = FALSE;
2946 break;
2947 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
2948 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2950 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2951 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2952 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2953 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2954 switch (opr1) {
2955 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2956 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2957 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2958 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2960 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2961 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2962 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2963 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2964 switch (opr1) {
2965 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2966 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2967 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2968 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2970 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2971 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2972 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2973 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2974 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2975 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2976 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2977 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2978 } else
2979 Handled = FALSE;
2980 break;
2981 case WINED3D_TOP_MULTIPLY_ADD:
2982 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2984 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2985 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2986 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2987 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2988 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2989 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2990 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src3);
2991 checkGLcall("GL_TEXTURE_ENV, src1_target, src3");
2992 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr3);
2993 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr3");
2994 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2995 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2996 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2997 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2998 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2999 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
3000 } else
3001 Handled = FALSE;
3002 break;
3003 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
3004 case WINED3D_TOP_BUMPENVMAP:
3005 if (gl_info->supported[NV_TEXTURE_SHADER2])
3007 /* Technically texture shader support without register combiners is possible, but not expected to occur
3008 * on real world cards, so for now a fixme should be enough
3010 FIXME("Implement bump mapping with GL_NV_texture_shader in non register combiner path\n");
3012 Handled = FALSE;
3013 break;
3015 default:
3016 Handled = FALSE;
3019 if (Handled) {
3020 BOOL combineOK = TRUE;
3021 if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
3023 DWORD op2;
3025 if (isAlpha)
3026 op2 = state->texture_states[Stage][WINED3D_TSS_COLOR_OP];
3027 else
3028 op2 = state->texture_states[Stage][WINED3D_TSS_ALPHA_OP];
3030 /* Note: If COMBINE4 in effect can't go back to combine! */
3031 switch (op2)
3033 case WINED3D_TOP_ADD_SMOOTH:
3034 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
3035 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
3036 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
3037 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
3038 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
3039 case WINED3D_TOP_MULTIPLY_ADD:
3040 /* Ignore those implemented in both cases */
3041 switch (op)
3043 case WINED3D_TOP_SELECT_ARG1:
3044 case WINED3D_TOP_SELECT_ARG2:
3045 combineOK = FALSE;
3046 Handled = FALSE;
3047 break;
3048 default:
3049 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%s, otherop=%s, isAlpha(%d)\n", debug_d3dtop(op), debug_d3dtop(op2), isAlpha);
3050 return;
3055 if (combineOK)
3057 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
3058 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE");
3060 return;
3064 /* After all the extensions, if still unhandled, report fixme */
3065 FIXME("Unhandled texture operation %s\n", debug_d3dtop(op));
3069 static void tex_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3071 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3072 BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
3073 DWORD mapped_stage = context->tex_unit_map[stage];
3074 const struct wined3d_gl_info *gl_info = context->gl_info;
3076 TRACE("Setting color op for stage %d\n", stage);
3078 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
3079 if (use_ps(state)) return;
3081 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
3083 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3085 if (tex_used && mapped_stage >= gl_info->limits.textures)
3087 FIXME("Attempt to enable unsupported stage!\n");
3088 return;
3090 context_active_texture(context, gl_info, mapped_stage);
3093 if (stage >= context->lowest_disabled_stage)
3095 TRACE("Stage disabled\n");
3096 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3098 /* Disable everything here */
3099 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3100 checkGLcall("glDisable(GL_TEXTURE_2D)");
3101 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3102 checkGLcall("glDisable(GL_TEXTURE_3D)");
3103 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3105 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3106 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
3108 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3110 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3111 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
3114 /* All done */
3115 return;
3118 /* The sampler will also activate the correct texture dimensions, so no
3119 * need to do it here if the sampler for this stage is dirty. */
3120 if (!isStateDirty(context, STATE_SAMPLER(stage)) && tex_used)
3121 texture_activate_dimensions(state->textures[stage], gl_info);
3123 set_tex_op(gl_info, state, FALSE, stage,
3124 state->texture_states[stage][WINED3D_TSS_COLOR_OP],
3125 state->texture_states[stage][WINED3D_TSS_COLOR_ARG1],
3126 state->texture_states[stage][WINED3D_TSS_COLOR_ARG2],
3127 state->texture_states[stage][WINED3D_TSS_COLOR_ARG0]);
3130 void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3132 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3133 BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
3134 DWORD mapped_stage = context->tex_unit_map[stage];
3135 const struct wined3d_gl_info *gl_info = context->gl_info;
3136 DWORD op, arg1, arg2, arg0;
3138 TRACE("Setting alpha op for stage %d\n", stage);
3139 /* Do not care for enabled / disabled stages, just assign the settings. colorop disables / enables required stuff */
3140 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
3142 if (tex_used && mapped_stage >= gl_info->limits.textures)
3144 FIXME("Attempt to enable unsupported stage!\n");
3145 return;
3147 context_active_texture(context, gl_info, mapped_stage);
3150 op = state->texture_states[stage][WINED3D_TSS_ALPHA_OP];
3151 arg1 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG1];
3152 arg2 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG2];
3153 arg0 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG0];
3155 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !stage && state->textures[0])
3157 struct wined3d_texture *texture = state->textures[0];
3158 GLenum texture_dimensions = texture->target;
3160 if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
3162 if (texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT && !texture->resource.format->alpha_size)
3164 /* Color keying needs to pass alpha values from the texture through to have the alpha test work
3165 * properly. On the other hand applications can still use texture combiners apparently. This code
3166 * takes care that apps cannot remove the texture's alpha channel entirely.
3168 * The fixup is required for Prince of Persia 3D(prison bars), while Moto racer 2 requires
3169 * D3DTOP_MODULATE to work on color keyed surfaces. Aliens vs Predator 1 uses color keyed textures
3170 * and alpha component of diffuse color to draw things like translucent text and perform other
3171 * blending effects.
3173 * Aliens vs Predator 1 relies on diffuse alpha having an effect, so it cannot be ignored. To
3174 * provide the behavior expected by the game, while emulating the colorkey, diffuse alpha must be
3175 * modulated with texture alpha. OTOH, Moto racer 2 at some points sets alphaop/alphaarg to
3176 * SELECTARG/CURRENT, yet puts garbage in diffuse alpha (zeroes). This works on native, because the
3177 * game disables alpha test and alpha blending. Alpha test is overwritten by wine's for purposes of
3178 * color-keying though, so this will lead to missing geometry if texture alpha is modulated (pixels
3179 * fail alpha test). To get around this, ALPHABLENDENABLE state is checked: if the app enables alpha
3180 * blending, it can be expected to provide meaningful values in diffuse alpha, so it should be
3181 * modulated with texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture
3182 * alpha.
3184 * What to do with multitexturing? So far no app has been found that uses color keying with
3185 * multitexturing */
3186 if (op == WINED3D_TOP_DISABLE)
3188 arg1 = WINED3DTA_TEXTURE;
3189 op = WINED3D_TOP_SELECT_ARG1;
3191 else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE)
3193 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3195 arg2 = WINED3DTA_TEXTURE;
3196 op = WINED3D_TOP_MODULATE;
3198 else arg1 = WINED3DTA_TEXTURE;
3200 else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE)
3202 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3204 arg1 = WINED3DTA_TEXTURE;
3205 op = WINED3D_TOP_MODULATE;
3207 else arg2 = WINED3DTA_TEXTURE;
3213 /* tex_alphaop is shared between the ffp and nvrc because the difference only comes down to
3214 * this if block here, and the other code(color keying, texture unit selection) are the same
3216 TRACE("Setting alpha op for stage %d\n", stage);
3217 if (gl_info->supported[NV_REGISTER_COMBINERS])
3219 set_tex_op_nvrc(gl_info, state, TRUE, stage, op, arg1, arg2, arg0,
3220 mapped_stage, state->texture_states[stage][WINED3D_TSS_RESULT_ARG]);
3222 else
3224 set_tex_op(gl_info, state, TRUE, stage, op, arg1, arg2, arg0);
3228 static void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3230 const struct wined3d_gl_info *gl_info = context->gl_info;
3231 unsigned int tex = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3232 unsigned int mapped_stage = context->tex_unit_map[tex];
3233 struct wined3d_matrix mat;
3235 /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
3236 if (use_vs(state) || isStateDirty(context, STATE_VDECL))
3238 TRACE("Using a vertex shader, or stream sources not sorted out yet, skipping\n");
3239 return;
3242 if (mapped_stage == WINED3D_UNMAPPED_STAGE) return;
3243 if (mapped_stage >= gl_info->limits.textures) return;
3245 context_active_texture(context, gl_info, mapped_stage);
3246 gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
3247 checkGLcall("glMatrixMode(GL_TEXTURE)");
3249 get_texture_matrix(context, state, mapped_stage, &mat);
3251 gl_info->gl_ops.gl.p_glLoadMatrixf(&mat._11);
3252 checkGLcall("glLoadMatrixf");
3255 static void unload_tex_coords(const struct wined3d_gl_info *gl_info)
3257 unsigned int texture_idx;
3259 for (texture_idx = 0; texture_idx < gl_info->limits.texture_coords; ++texture_idx)
3261 GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx));
3262 gl_info->gl_ops.gl.p_glDisableClientState(GL_TEXTURE_COORD_ARRAY);
3266 static void load_tex_coords(const struct wined3d_context *context, const struct wined3d_stream_info *si,
3267 GLuint *curVBO, const struct wined3d_state *state)
3269 const struct wined3d_gl_info *gl_info = context->gl_info;
3270 unsigned int mapped_stage = 0;
3271 unsigned int textureNo;
3273 for (textureNo = 0; textureNo < context->d3d_info->limits.ffp_blend_stages; ++textureNo)
3275 int coordIdx = state->texture_states[textureNo][WINED3D_TSS_TEXCOORD_INDEX];
3277 mapped_stage = context->tex_unit_map[textureNo];
3278 if (mapped_stage == WINED3D_UNMAPPED_STAGE) continue;
3280 if (mapped_stage >= gl_info->limits.texture_coords)
3282 FIXME("Attempted to load unsupported texture coordinate %u\n", mapped_stage);
3283 continue;
3286 if (coordIdx < MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coordIdx))))
3288 const struct wined3d_stream_info_element *e = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
3290 TRACE("Setting up texture %u, idx %d, coordindx %u, data {%#x:%p}.\n",
3291 textureNo, mapped_stage, coordIdx, e->data.buffer_object, e->data.addr);
3293 if (*curVBO != e->data.buffer_object)
3295 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
3296 checkGLcall("glBindBuffer");
3297 *curVBO = e->data.buffer_object;
3300 GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
3301 checkGLcall("glClientActiveTextureARB");
3303 /* The coords to supply depend completely on the fvf / vertex shader */
3304 gl_info->gl_ops.gl.p_glTexCoordPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
3305 e->data.addr + state->load_base_vertex_index * e->stride);
3306 gl_info->gl_ops.gl.p_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
3308 else
3310 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + mapped_stage, 0, 0, 0, 1));
3313 if (gl_info->supported[NV_REGISTER_COMBINERS])
3315 /* The number of the mapped stages increases monotonically, so it's fine to use the last used one. */
3316 for (textureNo = mapped_stage + 1; textureNo < gl_info->limits.textures; ++textureNo)
3318 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1));
3322 checkGLcall("loadTexCoords");
3325 static void tex_coordindex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3327 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3328 static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f };
3329 static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f };
3330 static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f };
3331 static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f };
3332 const struct wined3d_gl_info *gl_info = context->gl_info;
3333 DWORD mapped_stage = context->tex_unit_map[stage];
3335 if (mapped_stage == WINED3D_UNMAPPED_STAGE)
3337 TRACE("No texture unit mapped to stage %d. Skipping texture coordinates.\n", stage);
3338 return;
3341 if (mapped_stage >= min(gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL], MAX_FRAGMENT_SAMPLERS))
3343 WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage);
3344 return;
3346 context_active_texture(context, gl_info, mapped_stage);
3348 /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
3350 * FIXME: When using generated texture coordinates, the index value is used to specify the wrapping mode.
3351 * eg. SetTextureStageState( 0, WINED3D_TSS_TEXCOORDINDEX, WINED3D_TSS_TCI_CAMERASPACEPOSITION | 1 );
3352 * means use the vertex position (camera-space) as the input texture coordinates
3353 * for this texture stage, and the wrap mode set in the WINED3D_RS_WRAP1 render
3354 * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up
3355 * to the TEXCOORDINDEX value
3357 switch (state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
3359 case WINED3DTSS_TCI_PASSTHRU:
3360 /* Use the specified texture coordinates contained within the
3361 * vertex format. This value resolves to zero. */
3362 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
3363 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
3364 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3365 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3366 checkGLcall("WINED3DTSS_TCI_PASSTHRU - Disable texgen.");
3367 break;
3369 case WINED3DTSS_TCI_CAMERASPACEPOSITION:
3370 /* CameraSpacePosition means use the vertex position, transformed to camera space,
3371 * as the input texture coordinates for this stage's texture transformation. This
3372 * equates roughly to EYE_LINEAR */
3374 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3375 gl_info->gl_ops.gl.p_glPushMatrix();
3376 gl_info->gl_ops.gl.p_glLoadIdentity();
3377 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3378 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3379 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3380 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3381 gl_info->gl_ops.gl.p_glPopMatrix();
3382 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set eye plane.");
3384 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3385 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3386 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3387 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set texgen mode.");
3389 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3390 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3391 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3392 checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Enable texgen.");
3394 break;
3396 case WINED3DTSS_TCI_CAMERASPACENORMAL:
3397 /* Note that NV_TEXGEN_REFLECTION support is implied when
3398 * ARB_TEXTURE_CUBE_MAP is supported */
3399 if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3401 FIXME("WINED3DTSS_TCI_CAMERASPACENORMAL not supported.\n");
3402 break;
3405 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3406 gl_info->gl_ops.gl.p_glPushMatrix();
3407 gl_info->gl_ops.gl.p_glLoadIdentity();
3408 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3409 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3410 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3411 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3412 gl_info->gl_ops.gl.p_glPopMatrix();
3413 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set eye plane.");
3415 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3416 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3417 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3418 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set texgen mode.");
3420 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3421 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3422 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3423 checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Enable texgen.");
3425 break;
3427 case WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
3428 /* Note that NV_TEXGEN_REFLECTION support is implied when
3429 * ARB_TEXTURE_CUBE_MAP is supported */
3430 if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3432 FIXME("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR not supported.\n");
3433 break;
3436 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3437 gl_info->gl_ops.gl.p_glPushMatrix();
3438 gl_info->gl_ops.gl.p_glLoadIdentity();
3439 gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
3440 gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
3441 gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
3442 gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
3443 gl_info->gl_ops.gl.p_glPopMatrix();
3444 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set eye plane.");
3446 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3447 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3448 gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3449 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set texgen mode.");
3451 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3452 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3453 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3454 checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Enable texgen.");
3456 break;
3458 case WINED3DTSS_TCI_SPHEREMAP:
3459 gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
3460 gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
3461 checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Set texgen mode.");
3463 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
3464 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
3465 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3466 checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Enable texgen.");
3468 break;
3470 default:
3471 FIXME("Unhandled WINED3D_TSS_TEXCOORD_INDEX %#x.\n",
3472 state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX]);
3473 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
3474 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
3475 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3476 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3477 checkGLcall("Disable texgen.");
3479 break;
3482 /* Update the texture matrix. */
3483 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + stage)))
3484 transform_texture(context, state, STATE_TEXTURESTAGE(stage, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3486 if (!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded)
3488 /* Reload the arrays if we are using fixed function arrays to reflect the selected coord input
3489 * source. Call loadTexCoords directly because there is no need to reparse the vertex declaration
3490 * and do all the things linked to it
3491 * TODO: Tidy that up to reload only the arrays of the changed unit
3493 GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
3495 unload_tex_coords(gl_info);
3496 load_tex_coords(context, &context->stream_info, &curVBO, state);
3500 static void sampler_texmatrix(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3502 const DWORD sampler = state_id - STATE_SAMPLER(0);
3503 const struct wined3d_texture *texture = state->textures[sampler];
3505 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
3507 if (!texture)
3508 return;
3510 /* The fixed function np2 texture emulation uses the texture matrix to fix up the coordinates
3511 * wined3d_texture_apply_state_changes() multiplies the set matrix with a fixup matrix. Before the
3512 * scaling is reapplied or removed, the texture matrix has to be reapplied.
3514 if (sampler < MAX_TEXTURES)
3516 const BOOL tex_is_pow2 = !(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT);
3518 if (tex_is_pow2 || (context->lastWasPow2Texture & (1u << sampler)))
3520 if (tex_is_pow2)
3521 context->lastWasPow2Texture |= 1u << sampler;
3522 else
3523 context->lastWasPow2Texture &= ~(1u << sampler);
3525 transform_texture(context, state, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3530 static enum wined3d_texture_address wined3d_texture_address_mode(const struct wined3d_texture *texture,
3531 enum wined3d_texture_address t)
3533 if (t < WINED3D_TADDRESS_WRAP || t > WINED3D_TADDRESS_MIRROR_ONCE)
3535 FIXME("Unrecognized or unsupported texture address mode %#x.\n", t);
3536 return WINED3D_TADDRESS_WRAP;
3539 /* Cubemaps are always set to clamp, regardless of the sampler state. */
3540 if (texture->target == GL_TEXTURE_CUBE_MAP_ARB || ((texture->flags & WINED3D_TEXTURE_COND_NP2)
3541 && t == WINED3D_TADDRESS_WRAP))
3542 return WINED3D_TADDRESS_CLAMP;
3544 return t;
3547 static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc *desc,
3548 const struct wined3d_context *context, const DWORD *sampler_states, const struct wined3d_texture *texture)
3550 union
3552 float f;
3553 DWORD d;
3554 } lod_bias;
3556 desc->address_u = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_U]);
3557 desc->address_v = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_V]);
3558 desc->address_w = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_W]);
3559 wined3d_color_from_d3dcolor((struct wined3d_color *)desc->border_color,
3560 sampler_states[WINED3D_SAMP_BORDER_COLOR]);
3561 if (sampler_states[WINED3D_SAMP_MAG_FILTER] > WINED3D_TEXF_ANISOTROPIC)
3562 FIXME("Unrecognized or unsupported WINED3D_SAMP_MAG_FILTER %#x.\n",
3563 sampler_states[WINED3D_SAMP_MAG_FILTER]);
3564 desc->mag_filter = min(max(sampler_states[WINED3D_SAMP_MAG_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
3565 if (sampler_states[WINED3D_SAMP_MIN_FILTER] > WINED3D_TEXF_ANISOTROPIC)
3566 FIXME("Unrecognized or unsupported WINED3D_SAMP_MIN_FILTER %#x.\n",
3567 sampler_states[WINED3D_SAMP_MIN_FILTER]);
3568 desc->min_filter = min(max(sampler_states[WINED3D_SAMP_MIN_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
3569 if (sampler_states[WINED3D_SAMP_MIP_FILTER] > WINED3D_TEXF_ANISOTROPIC)
3570 FIXME("Unrecognized or unsupported WINED3D_SAMP_MIP_FILTER %#x.\n",
3571 sampler_states[WINED3D_SAMP_MIP_FILTER]);
3572 desc->mip_filter = min(max(sampler_states[WINED3D_SAMP_MIP_FILTER], WINED3D_TEXF_NONE), WINED3D_TEXF_LINEAR);
3573 lod_bias.d = sampler_states[WINED3D_SAMP_MIPMAP_LOD_BIAS];
3574 desc->lod_bias = lod_bias.f;
3575 desc->min_lod = -1000.0f;
3576 desc->max_lod = 1000.0f;
3577 desc->mip_base_level = sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL];
3578 desc->max_anisotropy = sampler_states[WINED3D_SAMP_MAX_ANISOTROPY];
3579 if ((sampler_states[WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_ANISOTROPIC
3580 && sampler_states[WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_ANISOTROPIC
3581 && sampler_states[WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_ANISOTROPIC)
3582 || (texture->flags & WINED3D_TEXTURE_COND_NP2))
3583 desc->max_anisotropy = 1;
3584 desc->compare = texture->resource.format_flags & WINED3DFMT_FLAG_SHADOW;
3585 desc->comparison_func = WINED3D_CMP_LESSEQUAL;
3586 desc->srgb_decode = sampler_states[WINED3D_SAMP_SRGB_TEXTURE];
3588 if (!(texture->resource.format_flags & WINED3DFMT_FLAG_FILTERING))
3590 desc->mag_filter = WINED3D_TEXF_POINT;
3591 desc->min_filter = WINED3D_TEXF_POINT;
3592 desc->mip_filter = WINED3D_TEXF_NONE;
3595 if (texture->flags & WINED3D_TEXTURE_COND_NP2)
3597 desc->mip_filter = WINED3D_TEXF_NONE;
3598 if (context->gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
3599 desc->min_filter = WINED3D_TEXF_POINT;
3603 /* Enabling and disabling texture dimensions is done by texture stage state /
3604 * pixel shader setup, this function only has to bind textures and set the per
3605 * texture states. */
3606 static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3608 DWORD sampler_idx = state_id - STATE_SAMPLER(0);
3609 DWORD mapped_stage = context->tex_unit_map[sampler_idx];
3610 const struct wined3d_gl_info *gl_info = context->gl_info;
3612 TRACE("Sampler %u.\n", sampler_idx);
3614 if (mapped_stage == WINED3D_UNMAPPED_STAGE)
3616 TRACE("No sampler mapped to stage %u. Returning.\n", sampler_idx);
3617 return;
3620 if (mapped_stage >= gl_info->limits.graphics_samplers)
3621 return;
3622 context_active_texture(context, gl_info, mapped_stage);
3624 if (state->textures[sampler_idx])
3626 BOOL srgb = state->sampler_states[sampler_idx][WINED3D_SAMP_SRGB_TEXTURE];
3627 const DWORD *sampler_states = state->sampler_states[sampler_idx];
3628 struct wined3d_texture *texture = state->textures[sampler_idx];
3629 struct wined3d_device *device = context->device;
3630 struct wined3d_sampler_desc desc;
3631 struct wined3d_sampler *sampler;
3632 struct wine_rb_entry *entry;
3634 wined3d_sampler_desc_from_sampler_states(&desc, context, sampler_states, texture);
3636 wined3d_texture_bind(texture, context, srgb);
3638 if ((entry = wine_rb_get(&device->samplers, &desc)))
3640 sampler = WINE_RB_ENTRY_VALUE(entry, struct wined3d_sampler, entry);
3642 else
3644 if (FAILED(wined3d_sampler_create(device, &desc, NULL, &wined3d_null_parent_ops, &sampler)))
3646 ERR("Failed to create sampler.\n");
3647 return;
3649 if (wine_rb_put(&device->samplers, &desc, &sampler->entry) == -1)
3651 ERR("Failed to insert sampler.\n");
3652 wined3d_sampler_decref(sampler);
3653 return;
3657 wined3d_sampler_bind(sampler, mapped_stage, texture, context);
3659 /* Trigger shader constant reloading (for NP2 texcoord fixup) */
3660 if (!(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT))
3661 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_NP2_FIXUP;
3663 else
3665 context_bind_texture(context, GL_NONE, 0);
3666 if (gl_info->supported[ARB_SAMPLER_OBJECTS])
3668 GL_EXTCALL(glBindSampler(mapped_stage, 0));
3669 checkGLcall("glBindSampler");
3674 void apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3676 unsigned int i;
3678 if (use_ps(state))
3680 if (!context->last_was_pshader)
3682 /* Former draw without a pixel shader, some samplers may be
3683 * disabled because of WINED3D_TSS_COLOR_OP = WINED3DTOP_DISABLE
3684 * make sure to enable them. */
3685 for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
3687 if (!isStateDirty(context, STATE_SAMPLER(i)))
3688 sampler(context, state, STATE_SAMPLER(i));
3690 context->last_was_pshader = TRUE;
3692 else
3694 /* Otherwise all samplers were activated by the code above in
3695 * earlier draws, or by sampler() if a different texture was
3696 * bound. I don't have to do anything. */
3699 else
3701 /* Disabled the pixel shader - color ops weren't applied while it was
3702 * enabled, so re-apply them. */
3703 for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
3705 if (!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP)))
3706 context_apply_state(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
3708 context->last_was_pshader = FALSE;
3711 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
3714 static void state_compute_shader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3716 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_COMPUTE;
3719 static void state_shader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3721 enum wined3d_shader_type shader_type = state_id - STATE_SHADER(0);
3722 context->shader_update_mask |= 1u << shader_type;
3725 static void shader_bumpenv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3727 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_BUMP_ENV;
3730 static void transform_world(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3732 const struct wined3d_gl_info *gl_info = context->gl_info;
3733 struct wined3d_matrix mat;
3735 /* This function is called by transform_view below if the view matrix was changed too
3737 * Deliberately no check if the vertex declaration is dirty because the vdecl state
3738 * does not always update the world matrix, only on a switch between transformed
3739 * and untransformed draws. It *may* happen that the world matrix is set 2 times during one
3740 * draw, but that should be rather rare and cheaper in total.
3742 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3743 checkGLcall("glMatrixMode");
3745 get_modelview_matrix(context, state, 0, &mat);
3747 gl_info->gl_ops.gl.p_glLoadMatrixf((GLfloat *)&mat);
3748 checkGLcall("glLoadMatrixf");
3751 void clipplane(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3753 const struct wined3d_gl_info *gl_info = context->gl_info;
3754 UINT index = state_id - STATE_CLIPPLANE(0);
3755 GLdouble plane[4];
3757 if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)) || index >= gl_info->limits.user_clip_distances)
3758 return;
3760 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3761 gl_info->gl_ops.gl.p_glPushMatrix();
3763 /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */
3764 if (!use_vs(state))
3765 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3766 else
3767 /* With vertex shaders, clip planes are not transformed in Direct3D,
3768 * while in OpenGL they are still transformed by the model view matrix. */
3769 gl_info->gl_ops.gl.p_glLoadIdentity();
3771 plane[0] = state->clip_planes[index].x;
3772 plane[1] = state->clip_planes[index].y;
3773 plane[2] = state->clip_planes[index].z;
3774 plane[3] = state->clip_planes[index].w;
3776 TRACE("Clipplane [%.8e, %.8e, %.8e, %.8e]\n",
3777 plane[0], plane[1], plane[2], plane[3]);
3778 gl_info->gl_ops.gl.p_glClipPlane(GL_CLIP_PLANE0 + index, plane);
3779 checkGLcall("glClipPlane");
3781 gl_info->gl_ops.gl.p_glPopMatrix();
3784 static void transform_worldex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3786 UINT matrix = state_id - STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0));
3787 const struct wined3d_gl_info *gl_info = context->gl_info;
3788 GLenum glMat;
3790 TRACE("Setting world matrix %d\n", matrix);
3792 if (matrix >= gl_info->limits.blends)
3794 WARN("Unsupported blend matrix set\n");
3795 return;
3798 if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)))
3799 return;
3801 /* GL_MODELVIEW0_ARB: 0x1700
3802 * GL_MODELVIEW1_ARB: 0x850a
3803 * GL_MODELVIEW2_ARB: 0x8722
3804 * GL_MODELVIEW3_ARB: 0x8723
3805 * etc
3806 * GL_MODELVIEW31_ARB: 0x873f
3808 if(matrix == 1) glMat = GL_MODELVIEW1_ARB;
3809 else glMat = GL_MODELVIEW2_ARB - 2 + matrix;
3811 gl_info->gl_ops.gl.p_glMatrixMode(glMat);
3812 checkGLcall("glMatrixMode(glMat)");
3814 /* World matrix 0 is multiplied with the view matrix because d3d uses 3
3815 * matrices while gl uses only 2. To avoid weighting the view matrix
3816 * incorrectly it has to be multiplied into every GL modelview matrix. */
3817 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3818 checkGLcall("glLoadMatrixf");
3819 gl_info->gl_ops.gl.p_glMultMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(matrix)]._11);
3820 checkGLcall("glMultMatrixf");
3823 static void state_vertexblend_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3825 enum wined3d_vertex_blend_flags f = state->render_states[WINED3D_RS_VERTEXBLEND];
3826 static unsigned int once;
3828 if (f == WINED3D_VBF_DISABLE)
3829 return;
3831 if (!once++) FIXME("Vertex blend flags %#x not supported.\n", f);
3832 else WARN("Vertex blend flags %#x not supported.\n", f);
3835 static void state_vertexblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3837 enum wined3d_vertex_blend_flags val = state->render_states[WINED3D_RS_VERTEXBLEND];
3838 const struct wined3d_gl_info *gl_info = context->gl_info;
3839 struct wined3d_device *device = context->device;
3840 static unsigned int once;
3842 switch (val)
3844 case WINED3D_VBF_1WEIGHTS:
3845 case WINED3D_VBF_2WEIGHTS:
3846 case WINED3D_VBF_3WEIGHTS:
3847 gl_info->gl_ops.gl.p_glEnable(GL_VERTEX_BLEND_ARB);
3848 checkGLcall("glEnable(GL_VERTEX_BLEND_ARB)");
3850 /* D3D adds one more matrix which has weight (1 - sum(weights)).
3851 * This is enabled at context creation with enabling
3852 * GL_WEIGHT_SUM_UNITY_ARB. */
3853 GL_EXTCALL(glVertexBlendARB(state->render_states[WINED3D_RS_VERTEXBLEND] + 1));
3855 if (!device->vertexBlendUsed)
3857 unsigned int i;
3858 for (i = 1; i < gl_info->limits.blends; ++i)
3860 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i))))
3861 transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i)));
3863 device->vertexBlendUsed = TRUE;
3865 break;
3867 case WINED3D_VBF_TWEENING:
3868 case WINED3D_VBF_0WEIGHTS: /* Indexed vertex blending, not supported. */
3869 if (!once++) FIXME("Vertex blend flags %#x not supported.\n", val);
3870 else WARN("Vertex blend flags %#x not supported.\n", val);
3871 /* Fall through. */
3872 case WINED3D_VBF_DISABLE:
3873 gl_info->gl_ops.gl.p_glDisable(GL_VERTEX_BLEND_ARB);
3874 checkGLcall("glDisable(GL_VERTEX_BLEND_ARB)");
3875 break;
3879 static void transform_view(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3881 const struct wined3d_gl_info *gl_info = context->gl_info;
3882 const struct wined3d_light_info *light = NULL;
3883 unsigned int k;
3885 /* If we are changing the View matrix, reset the light and clipping planes to the new view
3886 * NOTE: We have to reset the positions even if the light/plane is not currently
3887 * enabled, since the call to enable it will not reset the position.
3888 * NOTE2: Apparently texture transforms do NOT need reapplying
3891 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3892 checkGLcall("glMatrixMode(GL_MODELVIEW)");
3893 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3894 checkGLcall("glLoadMatrixf(...)");
3896 /* Reset lights. TODO: Call light apply func */
3897 for (k = 0; k < gl_info->limits.lights; ++k)
3899 if (!(light = state->lights[k]))
3900 continue;
3901 if (light->OriginalParms.type == WINED3D_LIGHT_DIRECTIONAL)
3902 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, &light->direction.x);
3903 else
3904 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, &light->position.x);
3905 checkGLcall("glLightfv posn");
3906 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_SPOT_DIRECTION, &light->direction.x);
3907 checkGLcall("glLightfv dirn");
3910 /* Reset Clipping Planes */
3911 for (k = 0; k < gl_info->limits.user_clip_distances; ++k)
3913 if (!isStateDirty(context, STATE_CLIPPLANE(k)))
3914 clipplane(context, state, STATE_CLIPPLANE(k));
3917 if (context->last_was_rhw)
3919 gl_info->gl_ops.gl.p_glLoadIdentity();
3920 checkGLcall("glLoadIdentity()");
3921 /* No need to update the world matrix, the identity is fine */
3922 return;
3925 /* Call the world matrix state, this will apply the combined WORLD + VIEW matrix
3926 * No need to do it here if the state is scheduled for update. */
3927 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
3928 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
3930 /* Avoid looping over a number of matrices if the app never used the functionality */
3931 if (context->device->vertexBlendUsed)
3933 for (k = 1; k < gl_info->limits.blends; ++k)
3935 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k))))
3936 transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k)));
3941 static void transform_projection(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3943 const struct wined3d_gl_info *gl_info = context->gl_info;
3944 struct wined3d_matrix projection;
3946 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
3947 checkGLcall("glMatrixMode(GL_PROJECTION)");
3949 get_projection_matrix(context, state, &projection);
3950 gl_info->gl_ops.gl.p_glLoadMatrixf(&projection._11);
3951 checkGLcall("glLoadMatrixf");
3954 /* This should match any arrays loaded in load_vertex_data.
3955 * TODO: Only load / unload arrays if we have to. */
3956 static void unload_vertex_data(const struct wined3d_gl_info *gl_info)
3958 gl_info->gl_ops.gl.p_glDisableClientState(GL_VERTEX_ARRAY);
3959 gl_info->gl_ops.gl.p_glDisableClientState(GL_NORMAL_ARRAY);
3960 gl_info->gl_ops.gl.p_glDisableClientState(GL_COLOR_ARRAY);
3961 if (gl_info->supported[EXT_SECONDARY_COLOR])
3962 gl_info->gl_ops.gl.p_glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
3963 if (gl_info->supported[ARB_VERTEX_BLEND])
3964 gl_info->gl_ops.gl.p_glDisableClientState(GL_WEIGHT_ARRAY_ARB);
3965 unload_tex_coords(gl_info);
3968 static inline void unload_numbered_array(struct wined3d_context *context, int i)
3970 const struct wined3d_gl_info *gl_info = context->gl_info;
3972 GL_EXTCALL(glDisableVertexAttribArray(i));
3973 checkGLcall("glDisableVertexAttribArray");
3974 if (gl_info->supported[ARB_INSTANCED_ARRAYS])
3975 GL_EXTCALL(glVertexAttribDivisor(i, 0));
3977 context->numbered_array_mask &= ~(1u << i);
3980 /* This should match any arrays loaded in loadNumberedArrays
3981 * TODO: Only load / unload arrays if we have to. */
3982 static void unload_numbered_arrays(struct wined3d_context *context)
3984 /* disable any attribs (this is the same for both GLSL and ARB modes) */
3985 int i;
3987 for (i = 0; i < context->gl_info->limits.vertex_attribs; ++i) {
3988 unload_numbered_array(context, i);
3992 static void load_numbered_arrays(struct wined3d_context *context,
3993 const struct wined3d_stream_info *stream_info, const struct wined3d_state *state)
3995 const struct wined3d_shader *vs = state->shader[WINED3D_SHADER_TYPE_VERTEX];
3996 const struct wined3d_gl_info *gl_info = context->gl_info;
3997 GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
3998 unsigned int i;
4000 /* Default to no instancing */
4001 context->instance_count = 0;
4003 for (i = 0; i < MAX_ATTRIBS; ++i)
4005 const struct wined3d_stream_info_element *element = &stream_info->elements[i];
4006 const struct wined3d_stream_state *stream;
4008 if (!(stream_info->use_map & (1u << i)))
4010 if (context->numbered_array_mask & (1u << i))
4011 unload_numbered_array(context, i);
4012 if (!use_vs(state) && i == WINED3D_FFP_DIFFUSE)
4013 GL_EXTCALL(glVertexAttrib4f(i, 1.0f, 1.0f, 1.0f, 1.0f));
4014 else
4015 GL_EXTCALL(glVertexAttrib4f(i, 0.0f, 0.0f, 0.0f, 0.0f));
4016 continue;
4019 stream = &state->streams[element->stream_idx];
4021 if ((stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA) && !context->instance_count)
4022 context->instance_count = state->streams[0].frequency ? state->streams[0].frequency : 1;
4024 if (gl_info->supported[ARB_INSTANCED_ARRAYS])
4026 GL_EXTCALL(glVertexAttribDivisor(i, element->divisor));
4028 else if (element->divisor)
4030 /* Unload instanced arrays, they will be loaded using
4031 * immediate mode instead. */
4032 if (context->numbered_array_mask & (1u << i))
4033 unload_numbered_array(context, i);
4034 continue;
4037 TRACE_(d3d_shader)("Loading array %u [VBO=%u].\n", i, element->data.buffer_object);
4039 if (element->stride)
4041 if (curVBO != element->data.buffer_object)
4043 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, element->data.buffer_object));
4044 checkGLcall("glBindBuffer");
4045 curVBO = element->data.buffer_object;
4047 /* Use the VBO to find out if a vertex buffer exists, not the vb
4048 * pointer. vb can point to a user pointer data blob. In that case
4049 * curVBO will be 0. If there is a vertex buffer but no vbo we
4050 * won't be load converted attributes anyway. */
4051 if (vs && vs->reg_maps.shader_version.major >= 4
4052 && (element->format->flags[WINED3D_GL_RES_TYPE_BUFFER] & WINED3DFMT_FLAG_INTEGER))
4054 GL_EXTCALL(glVertexAttribIPointer(i, element->format->gl_vtx_format, element->format->gl_vtx_type,
4055 element->stride, element->data.addr + state->load_base_vertex_index * element->stride));
4057 else
4059 GL_EXTCALL(glVertexAttribPointer(i, element->format->gl_vtx_format, element->format->gl_vtx_type,
4060 element->format->gl_normalized, element->stride,
4061 element->data.addr + state->load_base_vertex_index * element->stride));
4064 if (!(context->numbered_array_mask & (1u << i)))
4066 GL_EXTCALL(glEnableVertexAttribArray(i));
4067 context->numbered_array_mask |= (1u << i);
4070 else
4072 /* Stride = 0 means always the same values.
4073 * glVertexAttribPointer doesn't do that. Instead disable the
4074 * pointer and set up the attribute statically. But we have to
4075 * figure out the system memory address. */
4076 const BYTE *ptr = element->data.addr;
4077 if (element->data.buffer_object)
4078 ptr += (ULONG_PTR)wined3d_buffer_load_sysmem(stream->buffer, context);
4080 if (context->numbered_array_mask & (1u << i))
4081 unload_numbered_array(context, i);
4083 switch (element->format->id)
4085 case WINED3DFMT_R32_FLOAT:
4086 GL_EXTCALL(glVertexAttrib1fv(i, (const GLfloat *)ptr));
4087 break;
4088 case WINED3DFMT_R32G32_FLOAT:
4089 GL_EXTCALL(glVertexAttrib2fv(i, (const GLfloat *)ptr));
4090 break;
4091 case WINED3DFMT_R32G32B32_FLOAT:
4092 GL_EXTCALL(glVertexAttrib3fv(i, (const GLfloat *)ptr));
4093 break;
4094 case WINED3DFMT_R32G32B32A32_FLOAT:
4095 GL_EXTCALL(glVertexAttrib4fv(i, (const GLfloat *)ptr));
4096 break;
4098 case WINED3DFMT_R8G8B8A8_UINT:
4099 GL_EXTCALL(glVertexAttrib4ubv(i, ptr));
4100 break;
4101 case WINED3DFMT_B8G8R8A8_UNORM:
4102 if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
4104 const DWORD *src = (const DWORD *)ptr;
4105 DWORD c = *src & 0xff00ff00u;
4106 c |= (*src & 0xff0000u) >> 16;
4107 c |= (*src & 0xffu) << 16;
4108 GL_EXTCALL(glVertexAttrib4Nubv(i, (GLubyte *)&c));
4109 break;
4111 /* else fallthrough */
4112 case WINED3DFMT_R8G8B8A8_UNORM:
4113 GL_EXTCALL(glVertexAttrib4Nubv(i, ptr));
4114 break;
4116 case WINED3DFMT_R16G16_SINT:
4117 GL_EXTCALL(glVertexAttrib2sv(i, (const GLshort *)ptr));
4118 break;
4119 case WINED3DFMT_R16G16B16A16_SINT:
4120 GL_EXTCALL(glVertexAttrib4sv(i, (const GLshort *)ptr));
4121 break;
4123 case WINED3DFMT_R16G16_SNORM:
4125 const GLshort s[4] = {((const GLshort *)ptr)[0], ((const GLshort *)ptr)[1], 0, 1};
4126 GL_EXTCALL(glVertexAttrib4Nsv(i, s));
4127 break;
4129 case WINED3DFMT_R16G16_UNORM:
4131 const GLushort s[4] = {((const GLushort *)ptr)[0], ((const GLushort *)ptr)[1], 0, 1};
4132 GL_EXTCALL(glVertexAttrib4Nusv(i, s));
4133 break;
4135 case WINED3DFMT_R16G16B16A16_SNORM:
4136 GL_EXTCALL(glVertexAttrib4Nsv(i, (const GLshort *)ptr));
4137 break;
4138 case WINED3DFMT_R16G16B16A16_UNORM:
4139 GL_EXTCALL(glVertexAttrib4Nusv(i, (const GLushort *)ptr));
4140 break;
4142 case WINED3DFMT_R10G10B10X2_UINT:
4143 FIXME("Unsure about WINED3DDECLTYPE_UDEC3.\n");
4144 /*glVertexAttrib3usvARB(i, (const GLushort *)ptr); Does not exist */
4145 break;
4146 case WINED3DFMT_R10G10B10X2_SNORM:
4147 FIXME("Unsure about WINED3DDECLTYPE_DEC3N.\n");
4148 /*glVertexAttrib3NusvARB(i, (const GLushort *)ptr); Does not exist */
4149 break;
4151 case WINED3DFMT_R16G16_FLOAT:
4152 if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
4154 /* Not supported by GL_ARB_half_float_vertex. */
4155 GL_EXTCALL(glVertexAttrib2hvNV(i, (const GLhalfNV *)ptr));
4157 else
4159 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
4160 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
4161 GL_EXTCALL(glVertexAttrib2f(i, x, y));
4163 break;
4164 case WINED3DFMT_R16G16B16A16_FLOAT:
4165 if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
4167 /* Not supported by GL_ARB_half_float_vertex. */
4168 GL_EXTCALL(glVertexAttrib4hvNV(i, (const GLhalfNV *)ptr));
4170 else
4172 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
4173 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
4174 float z = float_16_to_32(((const unsigned short *)ptr) + 2);
4175 float w = float_16_to_32(((const unsigned short *)ptr) + 3);
4176 GL_EXTCALL(glVertexAttrib4f(i, x, y, z, w));
4178 break;
4180 default:
4181 ERR("Unexpected declaration in stride 0 attributes.\n");
4182 break;
4187 checkGLcall("Loading numbered arrays");
4190 static void load_vertex_data(struct wined3d_context *context,
4191 const struct wined3d_stream_info *si, const struct wined3d_state *state)
4193 const struct wined3d_gl_info *gl_info = context->gl_info;
4194 GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
4195 const struct wined3d_stream_info_element *e;
4197 TRACE("Using fast vertex array code\n");
4199 /* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */
4200 context->instance_count = 0;
4202 /* Blend Data ---------------------------------------------- */
4203 if ((si->use_map & (1u << WINED3D_FFP_BLENDWEIGHT))
4204 || si->use_map & (1u << WINED3D_FFP_BLENDINDICES))
4206 e = &si->elements[WINED3D_FFP_BLENDWEIGHT];
4208 if (gl_info->supported[ARB_VERTEX_BLEND])
4210 TRACE("Blend %u %p %u\n", e->format->component_count,
4211 e->data.addr + state->load_base_vertex_index * e->stride, e->stride);
4213 gl_info->gl_ops.gl.p_glEnableClientState(GL_WEIGHT_ARRAY_ARB);
4214 checkGLcall("glEnableClientState(GL_WEIGHT_ARRAY_ARB)");
4216 GL_EXTCALL(glVertexBlendARB(e->format->component_count + 1));
4218 if (curVBO != e->data.buffer_object)
4220 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
4221 checkGLcall("glBindBuffer");
4222 curVBO = e->data.buffer_object;
4225 TRACE("glWeightPointerARB(%#x, %#x, %#x, %p);\n",
4226 e->format->gl_vtx_format,
4227 e->format->gl_vtx_type,
4228 e->stride,
4229 e->data.addr + state->load_base_vertex_index * e->stride);
4230 GL_EXTCALL(glWeightPointerARB(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4231 e->data.addr + state->load_base_vertex_index * e->stride));
4233 checkGLcall("glWeightPointerARB");
4235 if (si->use_map & (1u << WINED3D_FFP_BLENDINDICES))
4237 static BOOL warned;
4238 if (!warned)
4240 FIXME("blendMatrixIndices support\n");
4241 warned = TRUE;
4245 else
4247 /* TODO: Support vertex blending in immediate mode draws. No need
4248 * to write a FIXME here, this is done after the general vertex
4249 * declaration decoding. */
4250 WARN("Vertex blending not supported.\n");
4253 else
4255 if (gl_info->supported[ARB_VERTEX_BLEND])
4257 static const GLbyte one = 1;
4258 GL_EXTCALL(glWeightbvARB(1, &one));
4259 checkGLcall("glWeightbvARB(gl_info->max_blends, weights)");
4263 /* Point Size ----------------------------------------------*/
4264 if (si->use_map & (1u << WINED3D_FFP_PSIZE))
4266 /* no such functionality in the fixed function GL pipeline */
4267 TRACE("Cannot change ptSize here in openGl\n");
4268 /* TODO: Implement this function in using shaders if they are available */
4271 /* Vertex Pointers -----------------------------------------*/
4272 if (si->use_map & (1u << WINED3D_FFP_POSITION))
4274 e = &si->elements[WINED3D_FFP_POSITION];
4276 if (curVBO != e->data.buffer_object)
4278 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
4279 checkGLcall("glBindBuffer");
4280 curVBO = e->data.buffer_object;
4283 TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
4284 e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4285 e->data.addr + state->load_base_vertex_index * e->stride);
4286 gl_info->gl_ops.gl.p_glVertexPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4287 e->data.addr + state->load_base_vertex_index * e->stride);
4288 checkGLcall("glVertexPointer(...)");
4289 gl_info->gl_ops.gl.p_glEnableClientState(GL_VERTEX_ARRAY);
4290 checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)");
4293 /* Normals -------------------------------------------------*/
4294 if (si->use_map & (1u << WINED3D_FFP_NORMAL))
4296 e = &si->elements[WINED3D_FFP_NORMAL];
4298 if (curVBO != e->data.buffer_object)
4300 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
4301 checkGLcall("glBindBuffer");
4302 curVBO = e->data.buffer_object;
4305 TRACE("glNormalPointer(%#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride,
4306 e->data.addr + state->load_base_vertex_index * e->stride);
4307 gl_info->gl_ops.gl.p_glNormalPointer(e->format->gl_vtx_type, e->stride,
4308 e->data.addr + state->load_base_vertex_index * e->stride);
4309 checkGLcall("glNormalPointer(...)");
4310 gl_info->gl_ops.gl.p_glEnableClientState(GL_NORMAL_ARRAY);
4311 checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
4314 else
4316 gl_info->gl_ops.gl.p_glNormal3f(0, 0, 0);
4317 checkGLcall("glNormal3f(0, 0, 0)");
4320 /* Diffuse Colour --------------------------------------------*/
4321 if (si->use_map & (1u << WINED3D_FFP_DIFFUSE))
4323 e = &si->elements[WINED3D_FFP_DIFFUSE];
4325 if (curVBO != e->data.buffer_object)
4327 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
4328 checkGLcall("glBindBuffer");
4329 curVBO = e->data.buffer_object;
4332 TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
4333 e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4334 e->data.addr + state->load_base_vertex_index * e->stride);
4335 gl_info->gl_ops.gl.p_glColorPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4336 e->data.addr + state->load_base_vertex_index * e->stride);
4337 checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
4338 gl_info->gl_ops.gl.p_glEnableClientState(GL_COLOR_ARRAY);
4339 checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");
4342 else
4344 gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
4345 checkGLcall("glColor4f(1, 1, 1, 1)");
4348 /* Specular Colour ------------------------------------------*/
4349 if (si->use_map & (1u << WINED3D_FFP_SPECULAR))
4351 TRACE("setting specular colour\n");
4353 e = &si->elements[WINED3D_FFP_SPECULAR];
4355 if (gl_info->supported[EXT_SECONDARY_COLOR])
4357 GLenum type = e->format->gl_vtx_type;
4358 GLint format = e->format->gl_vtx_format;
4360 if (curVBO != e->data.buffer_object)
4362 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
4363 checkGLcall("glBindBuffer");
4364 curVBO = e->data.buffer_object;
4367 if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
4369 /* Usually specular colors only allow 3 components, since they have no alpha. In D3D, the specular alpha
4370 * contains the fog coordinate, which is passed to GL with GL_EXT_fog_coord. However, the fixed function
4371 * vertex pipeline can pass the specular alpha through, and pixel shaders can read it. So it GL accepts
4372 * 4 component secondary colors use it
4374 TRACE("glSecondaryColorPointer(%#x, %#x, %#x, %p);\n", format, type, e->stride,
4375 e->data.addr + state->load_base_vertex_index * e->stride);
4376 GL_EXTCALL(glSecondaryColorPointerEXT(format, type, e->stride,
4377 e->data.addr + state->load_base_vertex_index * e->stride));
4378 checkGLcall("glSecondaryColorPointerEXT(format, type, ...)");
4380 else
4382 switch(type)
4384 case GL_UNSIGNED_BYTE:
4385 TRACE("glSecondaryColorPointer(3, GL_UNSIGNED_BYTE, %#x, %p);\n", e->stride,
4386 e->data.addr + state->load_base_vertex_index * e->stride);
4387 GL_EXTCALL(glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, e->stride,
4388 e->data.addr + state->load_base_vertex_index * e->stride));
4389 checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)");
4390 break;
4392 default:
4393 FIXME("Add 4 component specular color pointers for type %x\n", type);
4394 /* Make sure that the right color component is dropped */
4395 TRACE("glSecondaryColorPointer(3, %#x, %#x, %p);\n", type, e->stride,
4396 e->data.addr + state->load_base_vertex_index * e->stride);
4397 GL_EXTCALL(glSecondaryColorPointerEXT(3, type, e->stride,
4398 e->data.addr + state->load_base_vertex_index * e->stride));
4399 checkGLcall("glSecondaryColorPointerEXT(3, type, ...)");
4402 gl_info->gl_ops.gl.p_glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
4403 checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
4405 else
4407 WARN("Specular colour is not supported in this GL implementation.\n");
4410 else
4412 if (gl_info->supported[EXT_SECONDARY_COLOR])
4414 GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
4415 checkGLcall("glSecondaryColor3fEXT(0, 0, 0)");
4417 else
4419 WARN("Specular colour is not supported in this GL implementation.\n");
4423 /* Texture coords -------------------------------------------*/
4424 load_tex_coords(context, si, &curVBO, state);
4427 static void streamsrc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4429 BOOL load_numbered = context->d3d_info->ffp_generic_attributes
4430 || (use_vs(state) && !context->use_immediate_mode_draw);
4431 BOOL load_named = !context->d3d_info->ffp_generic_attributes
4432 && !use_vs(state) && !context->use_immediate_mode_draw;
4434 if (isStateDirty(context, STATE_VDECL)) return;
4435 if (context->numberedArraysLoaded && !load_numbered)
4437 unload_numbered_arrays(context);
4438 context->numberedArraysLoaded = FALSE;
4439 context->numbered_array_mask = 0;
4441 else if (context->namedArraysLoaded)
4443 unload_vertex_data(context->gl_info);
4444 context->namedArraysLoaded = FALSE;
4447 if (load_numbered)
4449 TRACE("Loading numbered arrays\n");
4450 load_numbered_arrays(context, &context->stream_info, state);
4451 context->numberedArraysLoaded = TRUE;
4453 else if (load_named)
4455 TRACE("Loading vertex data\n");
4456 load_vertex_data(context, &context->stream_info, state);
4457 context->namedArraysLoaded = TRUE;
4461 static void vdecl_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4463 if (isStateDirty(context, STATE_STREAMSRC))
4464 return;
4465 streamsrc(context, state, STATE_STREAMSRC);
4468 static void vertexdeclaration(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4470 const struct wined3d_gl_info *gl_info = context->gl_info;
4471 BOOL useVertexShaderFunction = use_vs(state);
4472 BOOL updateFog = FALSE;
4473 BOOL transformed;
4474 BOOL wasrhw = context->last_was_rhw;
4475 unsigned int i;
4477 transformed = context->stream_info.position_transformed;
4478 if (transformed != context->last_was_rhw && !useVertexShaderFunction)
4479 updateFog = TRUE;
4481 context->last_was_rhw = transformed;
4483 if (context->stream_info.swizzle_map != context->last_swizzle_map)
4484 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
4486 context->last_swizzle_map = context->stream_info.swizzle_map;
4488 /* Don't have to apply the matrices when vertex shaders are used. When
4489 * vshaders are turned off this function will be called again anyway to
4490 * make sure they're properly set. */
4491 if (!useVertexShaderFunction)
4493 /* TODO: Move this mainly to the viewport state and only apply when
4494 * the vp has changed or transformed / untransformed was switched. */
4495 if (wasrhw != context->last_was_rhw
4496 && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))
4497 && !isStateDirty(context, STATE_VIEWPORT))
4498 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4499 /* World matrix needs reapplication here only if we're switching between rhw and non-rhw
4500 * mode.
4502 * If a vertex shader is used, the world matrix changed and then vertex shader unbound
4503 * this check will fail and the matrix not applied again. This is OK because a simple
4504 * world matrix change reapplies the matrix - These checks here are only to satisfy the
4505 * needs of the vertex declaration.
4507 * World and view matrix go into the same gl matrix, so only apply them when neither is
4508 * dirty
4510 if (transformed != wasrhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)))
4511 && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)))
4512 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
4513 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_COLORVERTEX)))
4514 context_apply_state(context, state, STATE_RENDER(WINED3D_RS_COLORVERTEX));
4515 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_LIGHTING)))
4516 state_lighting(context, state, STATE_RENDER(WINED3D_RS_LIGHTING));
4518 if (context->last_was_vshader)
4520 updateFog = TRUE;
4522 if (!context->d3d_info->vs_clipping
4523 && !isStateDirty(context, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE)))
4525 state_clipping(context, state, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE));
4528 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
4530 clipplane(context, state, STATE_CLIPPLANE(i));
4533 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS)))
4534 state_normalize(context, state, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS));
4536 else
4538 if(!context->last_was_vshader) {
4539 static BOOL warned = FALSE;
4540 if (!context->d3d_info->vs_clipping)
4542 /* Disable all clip planes to get defined results on all drivers. See comment in the
4543 * state_clipping state handler
4545 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
4547 gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE0 + i);
4548 checkGLcall("glDisable(GL_CLIP_PLANE0 + i)");
4551 if (!warned && state->render_states[WINED3D_RS_CLIPPLANEENABLE])
4553 FIXME("Clipping not supported with vertex shaders\n");
4554 warned = TRUE;
4557 if (wasrhw)
4559 /* Apply the transform matrices when switching from rhw
4560 * drawing to vertex shaders. Vertex shaders themselves do
4561 * not need it, but the matrices are not reapplied
4562 * automatically when switching back from vertex shaders to
4563 * fixed function processing. So make sure we leave the fixed
4564 * function vertex processing states back in a sane state
4565 * before switching to shaders. */
4566 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
4567 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4568 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
4569 transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
4571 updateFog = TRUE;
4573 /* Vertex shader clipping ignores the view matrix. Update all clipplanes
4574 * (Note: ARB shaders can read the clip planes for clipping emulation even if
4575 * device->vs_clipping is false.
4577 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
4579 clipplane(context, state, STATE_CLIPPLANE(i));
4584 context->last_was_vshader = useVertexShaderFunction;
4585 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
4587 if (updateFog)
4588 context_apply_state(context, state, STATE_RENDER(WINED3D_RS_FOGVERTEXMODE));
4590 if (!useVertexShaderFunction)
4592 unsigned int i;
4594 for (i = 0; i < MAX_TEXTURES; ++i)
4596 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + i)))
4597 transform_texture(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
4600 if (use_ps(state) && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.major == 1
4601 && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.minor <= 3)
4602 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
4606 static void viewport_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4608 const struct wined3d_rendertarget_view *depth_stencil = state->fb->depth_stencil;
4609 const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4610 const struct wined3d_gl_info *gl_info = context->gl_info;
4611 struct wined3d_viewport vp = state->viewport;
4612 unsigned int width, height;
4613 float y;
4615 if (target)
4617 if (vp.width > target->width)
4618 vp.width = target->width;
4619 if (vp.height > target->height)
4620 vp.height = target->height;
4622 wined3d_rendertarget_view_get_drawable_size(target, context, &width, &height);
4624 else if (depth_stencil)
4626 width = depth_stencil->width;
4627 height = depth_stencil->height;
4629 else
4631 FIXME("No attachments draw calls not supported.\n");
4632 return;
4635 gl_info->gl_ops.gl.p_glDepthRange(vp.min_z, vp.max_z);
4636 checkGLcall("glDepthRange");
4637 /* Note: GL requires lower left, DirectX supplies upper left. This is
4638 * reversed when using offscreen rendering. */
4639 y = context->render_offscreen ? vp.y : height - (vp.y + vp.height);
4641 if (gl_info->supported[ARB_VIEWPORT_ARRAY])
4642 GL_EXTCALL(glViewportIndexedf(0, vp.x, y, vp.width, vp.height));
4643 else
4644 gl_info->gl_ops.gl.p_glViewport(vp.x, y, vp.width, vp.height);
4645 checkGLcall("glViewport");
4648 static void viewport_miscpart_cc(struct wined3d_context *context,
4649 const struct wined3d_state *state, DWORD state_id)
4651 const struct wined3d_rendertarget_view *depth_stencil = state->fb->depth_stencil;
4652 const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4653 /* See get_projection_matrix() in utils.c for a discussion about those
4654 * values. */
4655 float pixel_center_offset = context->d3d_info->wined3d_creation_flags
4656 & WINED3D_PIXEL_CENTER_INTEGER ? 63.0f / 128.0f : -1.0f / 128.0f;
4657 const struct wined3d_gl_info *gl_info = context->gl_info;
4658 struct wined3d_viewport vp = state->viewport;
4659 unsigned int width, height;
4661 if (target)
4663 if (vp.width > target->width)
4664 vp.width = target->width;
4665 if (vp.height > target->height)
4666 vp.height = target->height;
4668 wined3d_rendertarget_view_get_drawable_size(target, context, &width, &height);
4670 else if (depth_stencil)
4672 width = depth_stencil->width;
4673 height = depth_stencil->height;
4675 else
4677 FIXME("No attachments draw calls not supported.\n");
4678 return;
4681 gl_info->gl_ops.gl.p_glDepthRange(vp.min_z, vp.max_z);
4682 checkGLcall("glDepthRange");
4684 if (context->render_offscreen)
4686 GL_EXTCALL(glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE));
4687 GL_EXTCALL(glViewportIndexedf(0, vp.x + pixel_center_offset, vp.y + pixel_center_offset,
4688 vp.width, vp.height));
4690 else
4692 GL_EXTCALL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE));
4693 GL_EXTCALL(glViewportIndexedf(0, vp.x + pixel_center_offset,
4694 (height - (vp.y + vp.height)) + pixel_center_offset, vp.width, vp.height));
4696 checkGLcall("setting clip space and viewport");
4699 static void viewport_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4701 if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
4702 transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4703 if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE))
4704 && state->render_states[WINED3D_RS_POINTSCALEENABLE])
4705 state_pscale(context, state, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE));
4706 /* Update the position fixup. */
4707 context->constant_update_mask |= WINED3D_SHADER_CONST_POS_FIXUP;
4710 static void light(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4712 const struct wined3d_gl_info *gl_info = context->gl_info;
4713 UINT Index = state_id - STATE_ACTIVELIGHT(0);
4714 const struct wined3d_light_info *lightInfo = state->lights[Index];
4716 if (!lightInfo)
4718 gl_info->gl_ops.gl.p_glDisable(GL_LIGHT0 + Index);
4719 checkGLcall("glDisable(GL_LIGHT0 + Index)");
4721 else
4723 float quad_att;
4724 float colRGBA[] = {0.0f, 0.0f, 0.0f, 0.0f};
4726 /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
4727 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
4728 gl_info->gl_ops.gl.p_glPushMatrix();
4729 gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
4731 /* Diffuse: */
4732 colRGBA[0] = lightInfo->OriginalParms.diffuse.r;
4733 colRGBA[1] = lightInfo->OriginalParms.diffuse.g;
4734 colRGBA[2] = lightInfo->OriginalParms.diffuse.b;
4735 colRGBA[3] = lightInfo->OriginalParms.diffuse.a;
4736 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_DIFFUSE, colRGBA);
4737 checkGLcall("glLightfv");
4739 /* Specular */
4740 colRGBA[0] = lightInfo->OriginalParms.specular.r;
4741 colRGBA[1] = lightInfo->OriginalParms.specular.g;
4742 colRGBA[2] = lightInfo->OriginalParms.specular.b;
4743 colRGBA[3] = lightInfo->OriginalParms.specular.a;
4744 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPECULAR, colRGBA);
4745 checkGLcall("glLightfv");
4747 /* Ambient */
4748 colRGBA[0] = lightInfo->OriginalParms.ambient.r;
4749 colRGBA[1] = lightInfo->OriginalParms.ambient.g;
4750 colRGBA[2] = lightInfo->OriginalParms.ambient.b;
4751 colRGBA[3] = lightInfo->OriginalParms.ambient.a;
4752 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_AMBIENT, colRGBA);
4753 checkGLcall("glLightfv");
4755 if ((lightInfo->OriginalParms.range * lightInfo->OriginalParms.range) >= FLT_MIN)
4756 quad_att = 1.4f / (lightInfo->OriginalParms.range * lightInfo->OriginalParms.range);
4757 else
4758 quad_att = 0.0f; /* 0 or MAX? (0 seems to be ok) */
4760 /* Do not assign attenuation values for lights that do not use them. D3D apps are free to pass any junk,
4761 * but gl drivers use them and may crash due to bad Attenuation values. Need for Speed most wanted sets
4762 * Attenuation0 to NaN and crashes in the gl lib
4765 switch (lightInfo->OriginalParms.type)
4767 case WINED3D_LIGHT_POINT:
4768 /* Position */
4769 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->position.x);
4770 checkGLcall("glLightfv");
4771 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4772 checkGLcall("glLightf");
4773 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
4774 lightInfo->OriginalParms.attenuation0);
4775 checkGLcall("glLightf");
4776 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
4777 lightInfo->OriginalParms.attenuation1);
4778 checkGLcall("glLightf");
4779 if (quad_att < lightInfo->OriginalParms.attenuation2)
4780 quad_att = lightInfo->OriginalParms.attenuation2;
4781 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4782 checkGLcall("glLightf");
4783 /* FIXME: Range */
4784 break;
4786 case WINED3D_LIGHT_SPOT:
4787 /* Position */
4788 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->position.x);
4789 checkGLcall("glLightfv");
4790 /* Direction */
4791 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPOT_DIRECTION, &lightInfo->direction.x);
4792 checkGLcall("glLightfv");
4793 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, lightInfo->exponent);
4794 checkGLcall("glLightf");
4795 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4796 checkGLcall("glLightf");
4797 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
4798 lightInfo->OriginalParms.attenuation0);
4799 checkGLcall("glLightf");
4800 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
4801 lightInfo->OriginalParms.attenuation1);
4802 checkGLcall("glLightf");
4803 if (quad_att < lightInfo->OriginalParms.attenuation2)
4804 quad_att = lightInfo->OriginalParms.attenuation2;
4805 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4806 checkGLcall("glLightf");
4807 /* FIXME: Range */
4808 break;
4810 case WINED3D_LIGHT_DIRECTIONAL:
4811 /* Direction */
4812 /* Note GL uses w position of 0 for direction! */
4813 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->direction.x);
4814 checkGLcall("glLightfv");
4815 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4816 checkGLcall("glLightf");
4817 gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, 0.0f);
4818 checkGLcall("glLightf");
4819 break;
4821 default:
4822 FIXME("Unrecognized light type %#x.\n", lightInfo->OriginalParms.type);
4825 /* Restore the modelview matrix */
4826 gl_info->gl_ops.gl.p_glPopMatrix();
4828 gl_info->gl_ops.gl.p_glEnable(GL_LIGHT0 + Index);
4829 checkGLcall("glEnable(GL_LIGHT0 + Index)");
4833 static void scissorrect(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4835 const struct wined3d_gl_info *gl_info = context->gl_info;
4836 const RECT *r = &state->scissor_rect;
4838 /* Warning: glScissor uses window coordinates, not viewport coordinates,
4839 * so our viewport correction does not apply. Warning2: Even in windowed
4840 * mode the coords are relative to the window, not the screen. */
4841 TRACE("Setting new scissor rect to %s.\n", wine_dbgstr_rect(r));
4843 if (context->render_offscreen)
4845 gl_info->gl_ops.gl.p_glScissor(r->left, r->top, r->right - r->left, r->bottom - r->top);
4847 else
4849 const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4850 UINT height;
4851 UINT width;
4853 wined3d_rendertarget_view_get_drawable_size(target, context, &width, &height);
4854 gl_info->gl_ops.gl.p_glScissor(r->left, height - r->bottom, r->right - r->left, r->bottom - r->top);
4856 checkGLcall("glScissor");
4859 static void indexbuffer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4861 const struct wined3d_stream_info *stream_info = &context->stream_info;
4862 const struct wined3d_gl_info *gl_info = context->gl_info;
4864 if (!state->index_buffer || !stream_info->all_vbo)
4866 GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
4868 else
4870 struct wined3d_buffer *ib = state->index_buffer;
4871 GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib->buffer_object));
4875 static void frontface(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4877 const struct wined3d_gl_info *gl_info = context->gl_info;
4878 GLenum mode;
4880 mode = state->rasterizer_state && state->rasterizer_state->desc.front_ccw ? GL_CCW : GL_CW;
4881 if (context->render_offscreen)
4882 mode = (mode == GL_CW) ? GL_CCW : GL_CW;
4884 gl_info->gl_ops.gl.p_glFrontFace(mode);
4885 checkGLcall("glFrontFace");
4888 static void frontface_cc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4890 const struct wined3d_gl_info *gl_info = context->gl_info;
4891 GLenum mode;
4893 mode = state->rasterizer_state && state->rasterizer_state->desc.front_ccw ? GL_CCW : GL_CW;
4895 gl_info->gl_ops.gl.p_glFrontFace(mode);
4896 checkGLcall("glFrontFace");
4899 static void psorigin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4901 static BOOL warned;
4903 if (!warned)
4905 WARN("Point sprite coordinate origin switching not supported.\n");
4906 warned = TRUE;
4910 static void psorigin(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4912 const struct wined3d_gl_info *gl_info = context->gl_info;
4913 GLint origin = context->render_offscreen ? GL_LOWER_LEFT : GL_UPPER_LEFT;
4915 GL_EXTCALL(glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, origin));
4916 checkGLcall("glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, ...)");
4919 void state_srgbwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4921 const struct wined3d_gl_info *gl_info = context->gl_info;
4923 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4925 if (needs_srgb_write(context, state, state->fb))
4926 gl_info->gl_ops.gl.p_glEnable(GL_FRAMEBUFFER_SRGB);
4927 else
4928 gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB);
4931 static void state_cb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4933 const struct wined3d_gl_info *gl_info = context->gl_info;
4934 enum wined3d_shader_type shader_type;
4935 struct wined3d_buffer *buffer;
4936 unsigned int i, base, count;
4938 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4940 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state_id))
4941 shader_type = state_id - STATE_GRAPHICS_CONSTANT_BUFFER(0);
4942 else
4943 shader_type = WINED3D_SHADER_TYPE_COMPUTE;
4945 wined3d_gl_limits_get_uniform_block_range(&gl_info->limits, shader_type, &base, &count);
4946 for (i = 0; i < count; ++i)
4948 buffer = state->cb[shader_type][i];
4949 GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, buffer ? buffer->buffer_object : 0));
4951 checkGLcall("bind constant buffers");
4954 static void state_cb_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4956 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4958 WARN("Constant buffers (%s) no supported.\n", debug_d3dstate(state_id));
4961 static void state_shader_resource_binding(struct wined3d_context *context,
4962 const struct wined3d_state *state, DWORD state_id)
4964 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4966 context->update_shader_resource_bindings = 1;
4969 static void state_cs_resource_binding(struct wined3d_context *context,
4970 const struct wined3d_state *state, DWORD state_id)
4972 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4973 context->update_compute_shader_resource_bindings = 1;
4976 static void state_uav_binding(struct wined3d_context *context,
4977 const struct wined3d_state *state, DWORD state_id)
4979 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4980 context->update_unordered_access_view_bindings = 1;
4983 static void state_cs_uav_binding(struct wined3d_context *context,
4984 const struct wined3d_state *state, DWORD state_id)
4986 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
4987 context->update_compute_unordered_access_view_bindings = 1;
4990 static void state_uav_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4992 WARN("ARB_image_load_store is not supported by OpenGL implementation.\n");
4995 static void state_so(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4997 const struct wined3d_gl_info *gl_info = context->gl_info;
4998 struct wined3d_buffer *buffer;
4999 unsigned int offset, size, i;
5001 TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
5003 context_end_transform_feedback(context);
5005 for (i = 0; i < ARRAY_SIZE(state->stream_output); ++i)
5007 if (!(buffer = state->stream_output[i].buffer))
5009 GL_EXTCALL(glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, i, 0));
5010 continue;
5013 offset = state->stream_output[i].offset;
5014 if (offset == ~0u)
5016 FIXME("Appending to stream output buffers not implemented.\n");
5017 offset = 0;
5019 size = buffer->resource.size - offset;
5020 GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i,
5021 buffer->buffer_object, offset, size));
5023 checkGLcall("bind transform feedback buffers");
5026 static void state_so_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5028 WARN("Transform feedback not supported.\n");
5031 const struct StateEntryTemplate misc_state_template[] =
5033 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
5034 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), state_cb_warn, }, WINED3D_GL_EXT_NONE },
5035 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
5036 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), state_cb_warn, }, WINED3D_GL_EXT_NONE },
5037 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
5038 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), state_cb_warn, }, WINED3D_GL_EXT_NONE },
5039 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
5040 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb_warn, }, WINED3D_GL_EXT_NONE },
5041 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
5042 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), state_cb_warn, }, WINED3D_GL_EXT_NONE },
5043 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), state_cb, }, ARB_UNIFORM_BUFFER_OBJECT },
5044 { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), state_cb_warn, }, WINED3D_GL_EXT_NONE },
5045 { STATE_GRAPHICS_SHADER_RESOURCE_BINDING, { STATE_GRAPHICS_SHADER_RESOURCE_BINDING, state_shader_resource_binding}, WINED3D_GL_EXT_NONE },
5046 { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, state_uav_binding }, ARB_SHADER_IMAGE_LOAD_STORE },
5047 { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, { STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, state_uav_warn }, WINED3D_GL_EXT_NONE },
5048 { STATE_COMPUTE_SHADER_RESOURCE_BINDING, { STATE_COMPUTE_SHADER_RESOURCE_BINDING, state_cs_resource_binding}, WINED3D_GL_EXT_NONE },
5049 { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, state_cs_uav_binding}, ARB_SHADER_IMAGE_LOAD_STORE },
5050 { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, state_uav_warn }, WINED3D_GL_EXT_NONE },
5051 { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so, }, WINED3D_GL_VERSION_3_2 },
5052 { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so_warn, }, WINED3D_GL_EXT_NONE },
5053 { STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
5054 { STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
5055 { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), state_blend }, WINED3D_GL_EXT_NONE },
5056 { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), state_line_antialias}, WINED3D_GL_EXT_NONE },
5057 { STATE_RENDER(WINED3D_RS_ANTIALIASEDLINEENABLE), { STATE_RENDER(WINED3D_RS_ANTIALIASEDLINEENABLE), state_line_antialias}, WINED3D_GL_EXT_NONE },
5058 { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
5059 { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
5060 { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
5061 { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
5062 { STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE },
5063 { STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE },
5064 { STATE_VDECL, { STATE_VDECL, vdecl_miscpart }, WINED3D_GL_EXT_NONE },
5065 { STATE_FRONTFACE, { STATE_FRONTFACE, frontface_cc }, ARB_CLIP_CONTROL },
5066 { STATE_FRONTFACE, { STATE_FRONTFACE, frontface }, WINED3D_GL_EXT_NONE },
5067 { STATE_SCISSORRECT, { STATE_SCISSORRECT, scissorrect }, WINED3D_GL_EXT_NONE },
5068 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, state_nop }, ARB_CLIP_CONTROL },
5069 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin }, WINED3D_GL_VERSION_2_0 },
5070 { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin_w }, WINED3D_GL_EXT_NONE },
5072 /* TODO: Move shader constant loading to vertex and fragment pipeline respectively, as soon as the pshader and
5073 * vshader loadings are untied from each other
5075 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5076 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5077 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5078 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5079 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5080 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5081 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5082 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5083 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5084 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5085 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5086 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5087 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5088 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5089 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5090 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5091 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5092 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5093 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5094 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5095 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5096 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5097 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5098 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5099 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5100 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5101 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5102 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5103 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5104 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5105 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5106 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
5107 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5108 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5109 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5110 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5111 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5112 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5113 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5114 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5115 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5116 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5117 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5118 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5119 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5120 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5121 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), shader_bumpenv }, WINED3D_GL_EXT_NONE },
5122 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
5124 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_miscpart_cc}, ARB_CLIP_CONTROL },
5125 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_miscpart }, WINED3D_GL_EXT_NONE },
5126 { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, indexbuffer }, ARB_VERTEX_BUFFER_OBJECT },
5127 { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, state_nop }, WINED3D_GL_EXT_NONE },
5128 { STATE_RENDER(WINED3D_RS_ANTIALIAS), { STATE_RENDER(WINED3D_RS_ANTIALIAS), state_antialias }, WINED3D_GL_EXT_NONE },
5129 { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), state_nop }, WINED3D_GL_EXT_NONE },
5130 { STATE_RENDER(WINED3D_RS_ZENABLE), { STATE_RENDER(WINED3D_RS_ZENABLE), state_zenable }, WINED3D_GL_EXT_NONE },
5131 { STATE_RENDER(WINED3D_RS_WRAPU), { STATE_RENDER(WINED3D_RS_WRAPU), state_wrapu }, WINED3D_GL_EXT_NONE },
5132 { STATE_RENDER(WINED3D_RS_WRAPV), { STATE_RENDER(WINED3D_RS_WRAPV), state_wrapv }, WINED3D_GL_EXT_NONE },
5133 { STATE_RENDER(WINED3D_RS_FILLMODE), { STATE_RENDER(WINED3D_RS_FILLMODE), state_fillmode }, WINED3D_GL_EXT_NONE },
5134 { STATE_RENDER(WINED3D_RS_LINEPATTERN), { STATE_RENDER(WINED3D_RS_LINEPATTERN), state_linepattern }, WINED3D_GL_LEGACY_CONTEXT },
5135 { STATE_RENDER(WINED3D_RS_LINEPATTERN), { STATE_RENDER(WINED3D_RS_LINEPATTERN), state_linepattern_w }, WINED3D_GL_EXT_NONE },
5136 { STATE_RENDER(WINED3D_RS_MONOENABLE), { STATE_RENDER(WINED3D_RS_MONOENABLE), state_monoenable }, WINED3D_GL_EXT_NONE },
5137 { STATE_RENDER(WINED3D_RS_ROP2), { STATE_RENDER(WINED3D_RS_ROP2), state_rop2 }, WINED3D_GL_EXT_NONE },
5138 { STATE_RENDER(WINED3D_RS_PLANEMASK), { STATE_RENDER(WINED3D_RS_PLANEMASK), state_planemask }, WINED3D_GL_EXT_NONE },
5139 { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), state_zwriteenable }, WINED3D_GL_EXT_NONE },
5140 { STATE_RENDER(WINED3D_RS_LASTPIXEL), { STATE_RENDER(WINED3D_RS_LASTPIXEL), state_lastpixel }, WINED3D_GL_EXT_NONE },
5141 { STATE_RENDER(WINED3D_RS_CULLMODE), { STATE_RENDER(WINED3D_RS_CULLMODE), state_cullmode }, WINED3D_GL_EXT_NONE },
5142 { STATE_RENDER(WINED3D_RS_ZFUNC), { STATE_RENDER(WINED3D_RS_ZFUNC), state_zfunc }, WINED3D_GL_EXT_NONE },
5143 { STATE_RENDER(WINED3D_RS_DITHERENABLE), { STATE_RENDER(WINED3D_RS_DITHERENABLE), state_ditherenable }, WINED3D_GL_EXT_NONE },
5144 { STATE_RENDER(WINED3D_RS_SUBPIXEL), { STATE_RENDER(WINED3D_RS_SUBPIXEL), state_subpixel }, WINED3D_GL_EXT_NONE },
5145 { STATE_RENDER(WINED3D_RS_SUBPIXELX), { STATE_RENDER(WINED3D_RS_SUBPIXELX), state_subpixelx }, WINED3D_GL_EXT_NONE },
5146 { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), state_stippledalpha }, WINED3D_GL_EXT_NONE },
5147 { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), state_stippleenable }, WINED3D_GL_EXT_NONE },
5148 { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), state_mipmaplodbias }, WINED3D_GL_EXT_NONE },
5149 { STATE_RENDER(WINED3D_RS_ANISOTROPY), { STATE_RENDER(WINED3D_RS_ANISOTROPY), state_anisotropy }, WINED3D_GL_EXT_NONE },
5150 { STATE_RENDER(WINED3D_RS_FLUSHBATCH), { STATE_RENDER(WINED3D_RS_FLUSHBATCH), state_flushbatch }, WINED3D_GL_EXT_NONE },
5151 { STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),{ STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),state_translucentsi }, WINED3D_GL_EXT_NONE },
5152 { STATE_RENDER(WINED3D_RS_STENCILENABLE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), state_stencil }, WINED3D_GL_EXT_NONE },
5153 { STATE_RENDER(WINED3D_RS_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5154 { STATE_RENDER(WINED3D_RS_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5155 { STATE_RENDER(WINED3D_RS_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5156 { STATE_RENDER(WINED3D_RS_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5157 { STATE_RENDER(WINED3D_RS_STENCILREF), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5158 { STATE_RENDER(WINED3D_RS_STENCILMASK), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5159 { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite2s}, EXT_STENCIL_TWO_SIDE },
5160 { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite }, WINED3D_GL_EXT_NONE },
5161 { STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5162 { STATE_RENDER(WINED3D_RS_BACK_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5163 { STATE_RENDER(WINED3D_RS_BACK_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5164 { STATE_RENDER(WINED3D_RS_BACK_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5165 { STATE_RENDER(WINED3D_RS_BACK_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
5166 { STATE_RENDER(WINED3D_RS_WRAP0), { STATE_RENDER(WINED3D_RS_WRAP0), state_wrap }, WINED3D_GL_EXT_NONE },
5167 { STATE_RENDER(WINED3D_RS_WRAP1), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5168 { STATE_RENDER(WINED3D_RS_WRAP2), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5169 { STATE_RENDER(WINED3D_RS_WRAP3), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5170 { STATE_RENDER(WINED3D_RS_WRAP4), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5171 { STATE_RENDER(WINED3D_RS_WRAP5), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5172 { STATE_RENDER(WINED3D_RS_WRAP6), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5173 { STATE_RENDER(WINED3D_RS_WRAP7), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5174 { STATE_RENDER(WINED3D_RS_WRAP8), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5175 { STATE_RENDER(WINED3D_RS_WRAP9), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5176 { STATE_RENDER(WINED3D_RS_WRAP10), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5177 { STATE_RENDER(WINED3D_RS_WRAP11), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5178 { STATE_RENDER(WINED3D_RS_WRAP12), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5179 { STATE_RENDER(WINED3D_RS_WRAP13), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5180 { STATE_RENDER(WINED3D_RS_WRAP14), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5181 { STATE_RENDER(WINED3D_RS_WRAP15), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
5182 { STATE_RENDER(WINED3D_RS_EXTENTS), { STATE_RENDER(WINED3D_RS_EXTENTS), state_extents }, WINED3D_GL_EXT_NONE },
5183 { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), state_ckeyblend }, WINED3D_GL_EXT_NONE },
5184 { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), state_swvp }, WINED3D_GL_EXT_NONE },
5185 { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), state_patchedgestyle}, WINED3D_GL_EXT_NONE },
5186 { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), state_patchsegments }, WINED3D_GL_EXT_NONE },
5187 { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), state_positiondegree}, WINED3D_GL_EXT_NONE },
5188 { STATE_RENDER(WINED3D_RS_NORMALDEGREE), { STATE_RENDER(WINED3D_RS_NORMALDEGREE), state_normaldegree }, WINED3D_GL_EXT_NONE },
5189 { STATE_RENDER(WINED3D_RS_MINTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5190 { STATE_RENDER(WINED3D_RS_MAXTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5191 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_X), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5192 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Y), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5193 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Z), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5194 { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_W), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE },
5195 { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_nvdb }, EXT_DEPTH_BOUNDS_TEST },
5196 { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_tessellation }, WINED3D_GL_EXT_NONE },
5197 { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa }, ARB_MULTISAMPLE },
5198 { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa_w }, WINED3D_GL_EXT_NONE },
5199 { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), state_multisampmask }, WINED3D_GL_EXT_NONE },
5200 { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), state_debug_monitor }, WINED3D_GL_EXT_NONE },
5201 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite0 }, EXT_DRAW_BUFFERS2 },
5202 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite }, WINED3D_GL_EXT_NONE },
5203 { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop }, WINED3D_GL_BLEND_EQUATION },
5204 { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop_w }, WINED3D_GL_EXT_NONE },
5205 { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), state_scissor }, WINED3D_GL_EXT_NONE },
5206 { STATE_RENDER(WINED3D_RS_SLOPESCALEDEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), NULL }, WINED3D_GL_EXT_NONE },
5207 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), state_colorwrite1 }, EXT_DRAW_BUFFERS2 },
5208 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5209 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), state_colorwrite2 }, EXT_DRAW_BUFFERS2 },
5210 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5211 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), state_colorwrite3 }, EXT_DRAW_BUFFERS2 },
5212 { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5213 { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor }, EXT_BLEND_COLOR },
5214 { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor_w }, WINED3D_GL_EXT_NONE },
5215 { STATE_RENDER(WINED3D_RS_DEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), state_depthbias }, WINED3D_GL_EXT_NONE },
5216 { STATE_RENDER(WINED3D_RS_ZVISIBLE), { STATE_RENDER(WINED3D_RS_ZVISIBLE), state_zvisible }, WINED3D_GL_EXT_NONE },
5217 /* Samplers */
5218 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler }, WINED3D_GL_EXT_NONE },
5219 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler }, WINED3D_GL_EXT_NONE },
5220 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler }, WINED3D_GL_EXT_NONE },
5221 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler }, WINED3D_GL_EXT_NONE },
5222 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler }, WINED3D_GL_EXT_NONE },
5223 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler }, WINED3D_GL_EXT_NONE },
5224 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler }, WINED3D_GL_EXT_NONE },
5225 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler }, WINED3D_GL_EXT_NONE },
5226 { STATE_SAMPLER(8), { STATE_SAMPLER(8), sampler }, WINED3D_GL_EXT_NONE },
5227 { STATE_SAMPLER(9), { STATE_SAMPLER(9), sampler }, WINED3D_GL_EXT_NONE },
5228 { STATE_SAMPLER(10), { STATE_SAMPLER(10), sampler }, WINED3D_GL_EXT_NONE },
5229 { STATE_SAMPLER(11), { STATE_SAMPLER(11), sampler }, WINED3D_GL_EXT_NONE },
5230 { STATE_SAMPLER(12), { STATE_SAMPLER(12), sampler }, WINED3D_GL_EXT_NONE },
5231 { STATE_SAMPLER(13), { STATE_SAMPLER(13), sampler }, WINED3D_GL_EXT_NONE },
5232 { STATE_SAMPLER(14), { STATE_SAMPLER(14), sampler }, WINED3D_GL_EXT_NONE },
5233 { STATE_SAMPLER(15), { STATE_SAMPLER(15), sampler }, WINED3D_GL_EXT_NONE },
5234 { STATE_SAMPLER(16), /* Vertex sampler 0 */ { STATE_SAMPLER(16), sampler }, WINED3D_GL_EXT_NONE },
5235 { STATE_SAMPLER(17), /* Vertex sampler 1 */ { STATE_SAMPLER(17), sampler }, WINED3D_GL_EXT_NONE },
5236 { STATE_SAMPLER(18), /* Vertex sampler 2 */ { STATE_SAMPLER(18), sampler }, WINED3D_GL_EXT_NONE },
5237 { STATE_SAMPLER(19), /* Vertex sampler 3 */ { STATE_SAMPLER(19), sampler }, WINED3D_GL_EXT_NONE },
5238 { STATE_BASEVERTEXINDEX, { STATE_BASEVERTEXINDEX, state_nop, }, ARB_DRAW_ELEMENTS_BASE_VERTEX },
5239 { STATE_BASEVERTEXINDEX, { STATE_STREAMSRC, NULL, }, WINED3D_GL_EXT_NONE },
5240 { STATE_FRAMEBUFFER, { STATE_FRAMEBUFFER, context_state_fb }, WINED3D_GL_EXT_NONE },
5241 { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), context_state_drawbuf},WINED3D_GL_EXT_NONE },
5242 { STATE_SHADER(WINED3D_SHADER_TYPE_HULL), { STATE_SHADER(WINED3D_SHADER_TYPE_HULL), state_shader }, WINED3D_GL_EXT_NONE },
5243 { STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN), { STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN), state_shader }, WINED3D_GL_EXT_NONE },
5244 { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY), { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY), state_shader }, WINED3D_GL_EXT_NONE },
5245 { STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE), { STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE), state_compute_shader}, WINED3D_GL_EXT_NONE },
5246 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5249 static const struct StateEntryTemplate vp_ffp_states[] =
5251 { STATE_VDECL, { STATE_VDECL, vertexdeclaration }, WINED3D_GL_EXT_NONE },
5252 { STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX), { STATE_VDECL, NULL }, WINED3D_GL_EXT_NONE },
5253 { STATE_MATERIAL, { STATE_RENDER(WINED3D_RS_SPECULARENABLE), NULL }, WINED3D_GL_EXT_NONE },
5254 { STATE_RENDER(WINED3D_RS_SPECULARENABLE), { STATE_RENDER(WINED3D_RS_SPECULARENABLE), state_specularenable}, WINED3D_GL_EXT_NONE },
5255 /* Clip planes */
5256 { STATE_CLIPPLANE(0), { STATE_CLIPPLANE(0), clipplane }, WINED3D_GL_EXT_NONE },
5257 { STATE_CLIPPLANE(1), { STATE_CLIPPLANE(1), clipplane }, WINED3D_GL_EXT_NONE },
5258 { STATE_CLIPPLANE(2), { STATE_CLIPPLANE(2), clipplane }, WINED3D_GL_EXT_NONE },
5259 { STATE_CLIPPLANE(3), { STATE_CLIPPLANE(3), clipplane }, WINED3D_GL_EXT_NONE },
5260 { STATE_CLIPPLANE(4), { STATE_CLIPPLANE(4), clipplane }, WINED3D_GL_EXT_NONE },
5261 { STATE_CLIPPLANE(5), { STATE_CLIPPLANE(5), clipplane }, WINED3D_GL_EXT_NONE },
5262 { STATE_CLIPPLANE(6), { STATE_CLIPPLANE(6), clipplane }, WINED3D_GL_EXT_NONE },
5263 { STATE_CLIPPLANE(7), { STATE_CLIPPLANE(7), clipplane }, WINED3D_GL_EXT_NONE },
5264 { STATE_CLIPPLANE(8), { STATE_CLIPPLANE(8), clipplane }, WINED3D_GL_EXT_NONE },
5265 { STATE_CLIPPLANE(9), { STATE_CLIPPLANE(9), clipplane }, WINED3D_GL_EXT_NONE },
5266 { STATE_CLIPPLANE(10), { STATE_CLIPPLANE(10), clipplane }, WINED3D_GL_EXT_NONE },
5267 { STATE_CLIPPLANE(11), { STATE_CLIPPLANE(11), clipplane }, WINED3D_GL_EXT_NONE },
5268 { STATE_CLIPPLANE(12), { STATE_CLIPPLANE(12), clipplane }, WINED3D_GL_EXT_NONE },
5269 { STATE_CLIPPLANE(13), { STATE_CLIPPLANE(13), clipplane }, WINED3D_GL_EXT_NONE },
5270 { STATE_CLIPPLANE(14), { STATE_CLIPPLANE(14), clipplane }, WINED3D_GL_EXT_NONE },
5271 { STATE_CLIPPLANE(15), { STATE_CLIPPLANE(15), clipplane }, WINED3D_GL_EXT_NONE },
5272 { STATE_CLIPPLANE(16), { STATE_CLIPPLANE(16), clipplane }, WINED3D_GL_EXT_NONE },
5273 { STATE_CLIPPLANE(17), { STATE_CLIPPLANE(17), clipplane }, WINED3D_GL_EXT_NONE },
5274 { STATE_CLIPPLANE(18), { STATE_CLIPPLANE(18), clipplane }, WINED3D_GL_EXT_NONE },
5275 { STATE_CLIPPLANE(19), { STATE_CLIPPLANE(19), clipplane }, WINED3D_GL_EXT_NONE },
5276 { STATE_CLIPPLANE(20), { STATE_CLIPPLANE(20), clipplane }, WINED3D_GL_EXT_NONE },
5277 { STATE_CLIPPLANE(21), { STATE_CLIPPLANE(21), clipplane }, WINED3D_GL_EXT_NONE },
5278 { STATE_CLIPPLANE(22), { STATE_CLIPPLANE(22), clipplane }, WINED3D_GL_EXT_NONE },
5279 { STATE_CLIPPLANE(23), { STATE_CLIPPLANE(23), clipplane }, WINED3D_GL_EXT_NONE },
5280 { STATE_CLIPPLANE(24), { STATE_CLIPPLANE(24), clipplane }, WINED3D_GL_EXT_NONE },
5281 { STATE_CLIPPLANE(25), { STATE_CLIPPLANE(25), clipplane }, WINED3D_GL_EXT_NONE },
5282 { STATE_CLIPPLANE(26), { STATE_CLIPPLANE(26), clipplane }, WINED3D_GL_EXT_NONE },
5283 { STATE_CLIPPLANE(27), { STATE_CLIPPLANE(27), clipplane }, WINED3D_GL_EXT_NONE },
5284 { STATE_CLIPPLANE(28), { STATE_CLIPPLANE(28), clipplane }, WINED3D_GL_EXT_NONE },
5285 { STATE_CLIPPLANE(29), { STATE_CLIPPLANE(29), clipplane }, WINED3D_GL_EXT_NONE },
5286 { STATE_CLIPPLANE(30), { STATE_CLIPPLANE(30), clipplane }, WINED3D_GL_EXT_NONE },
5287 { STATE_CLIPPLANE(31), { STATE_CLIPPLANE(31), clipplane }, WINED3D_GL_EXT_NONE },
5288 /* Lights */
5289 { STATE_LIGHT_TYPE, { STATE_LIGHT_TYPE, state_nop }, WINED3D_GL_EXT_NONE },
5290 { STATE_ACTIVELIGHT(0), { STATE_ACTIVELIGHT(0), light }, WINED3D_GL_EXT_NONE },
5291 { STATE_ACTIVELIGHT(1), { STATE_ACTIVELIGHT(1), light }, WINED3D_GL_EXT_NONE },
5292 { STATE_ACTIVELIGHT(2), { STATE_ACTIVELIGHT(2), light }, WINED3D_GL_EXT_NONE },
5293 { STATE_ACTIVELIGHT(3), { STATE_ACTIVELIGHT(3), light }, WINED3D_GL_EXT_NONE },
5294 { STATE_ACTIVELIGHT(4), { STATE_ACTIVELIGHT(4), light }, WINED3D_GL_EXT_NONE },
5295 { STATE_ACTIVELIGHT(5), { STATE_ACTIVELIGHT(5), light }, WINED3D_GL_EXT_NONE },
5296 { STATE_ACTIVELIGHT(6), { STATE_ACTIVELIGHT(6), light }, WINED3D_GL_EXT_NONE },
5297 { STATE_ACTIVELIGHT(7), { STATE_ACTIVELIGHT(7), light }, WINED3D_GL_EXT_NONE },
5298 /* Viewport */
5299 { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_vertexpart }, WINED3D_GL_EXT_NONE },
5300 /* Transform states follow */
5301 { STATE_TRANSFORM(WINED3D_TS_VIEW), { STATE_TRANSFORM(WINED3D_TS_VIEW), transform_view }, WINED3D_GL_EXT_NONE },
5302 { STATE_TRANSFORM(WINED3D_TS_PROJECTION), { STATE_TRANSFORM(WINED3D_TS_PROJECTION), transform_projection}, WINED3D_GL_EXT_NONE },
5303 { STATE_TRANSFORM(WINED3D_TS_TEXTURE0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5304 { STATE_TRANSFORM(WINED3D_TS_TEXTURE1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5305 { STATE_TRANSFORM(WINED3D_TS_TEXTURE2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5306 { STATE_TRANSFORM(WINED3D_TS_TEXTURE3), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5307 { STATE_TRANSFORM(WINED3D_TS_TEXTURE4), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5308 { STATE_TRANSFORM(WINED3D_TS_TEXTURE5), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5309 { STATE_TRANSFORM(WINED3D_TS_TEXTURE6), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5310 { STATE_TRANSFORM(WINED3D_TS_TEXTURE7), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
5311 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), transform_world }, WINED3D_GL_EXT_NONE },
5312 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), transform_worldex }, WINED3D_GL_EXT_NONE },
5313 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), transform_worldex }, WINED3D_GL_EXT_NONE },
5314 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), transform_worldex }, WINED3D_GL_EXT_NONE },
5315 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), transform_worldex }, WINED3D_GL_EXT_NONE },
5316 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), transform_worldex }, WINED3D_GL_EXT_NONE },
5317 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), transform_worldex }, WINED3D_GL_EXT_NONE },
5318 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), transform_worldex }, WINED3D_GL_EXT_NONE },
5319 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), transform_worldex }, WINED3D_GL_EXT_NONE },
5320 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), transform_worldex }, WINED3D_GL_EXT_NONE },
5321 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), transform_worldex }, WINED3D_GL_EXT_NONE },
5322 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), transform_worldex }, WINED3D_GL_EXT_NONE },
5323 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), transform_worldex }, WINED3D_GL_EXT_NONE },
5324 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), transform_worldex }, WINED3D_GL_EXT_NONE },
5325 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), transform_worldex }, WINED3D_GL_EXT_NONE },
5326 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), transform_worldex }, WINED3D_GL_EXT_NONE },
5327 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), transform_worldex }, WINED3D_GL_EXT_NONE },
5328 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), transform_worldex }, WINED3D_GL_EXT_NONE },
5329 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), transform_worldex }, WINED3D_GL_EXT_NONE },
5330 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), transform_worldex }, WINED3D_GL_EXT_NONE },
5331 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), transform_worldex }, WINED3D_GL_EXT_NONE },
5332 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), transform_worldex }, WINED3D_GL_EXT_NONE },
5333 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), transform_worldex }, WINED3D_GL_EXT_NONE },
5334 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), transform_worldex }, WINED3D_GL_EXT_NONE },
5335 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), transform_worldex }, WINED3D_GL_EXT_NONE },
5336 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), transform_worldex }, WINED3D_GL_EXT_NONE },
5337 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), transform_worldex }, WINED3D_GL_EXT_NONE },
5338 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), transform_worldex }, WINED3D_GL_EXT_NONE },
5339 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), transform_worldex }, WINED3D_GL_EXT_NONE },
5340 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), transform_worldex }, WINED3D_GL_EXT_NONE },
5341 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), transform_worldex }, WINED3D_GL_EXT_NONE },
5342 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), transform_worldex }, WINED3D_GL_EXT_NONE },
5343 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), transform_worldex }, WINED3D_GL_EXT_NONE },
5344 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), transform_worldex }, WINED3D_GL_EXT_NONE },
5345 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), transform_worldex }, WINED3D_GL_EXT_NONE },
5346 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), transform_worldex }, WINED3D_GL_EXT_NONE },
5347 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), transform_worldex }, WINED3D_GL_EXT_NONE },
5348 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), transform_worldex }, WINED3D_GL_EXT_NONE },
5349 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), transform_worldex }, WINED3D_GL_EXT_NONE },
5350 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), transform_worldex }, WINED3D_GL_EXT_NONE },
5351 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), transform_worldex }, WINED3D_GL_EXT_NONE },
5352 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), transform_worldex }, WINED3D_GL_EXT_NONE },
5353 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), transform_worldex }, WINED3D_GL_EXT_NONE },
5354 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), transform_worldex }, WINED3D_GL_EXT_NONE },
5355 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), transform_worldex }, WINED3D_GL_EXT_NONE },
5356 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), transform_worldex }, WINED3D_GL_EXT_NONE },
5357 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), transform_worldex }, WINED3D_GL_EXT_NONE },
5358 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), transform_worldex }, WINED3D_GL_EXT_NONE },
5359 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), transform_worldex }, WINED3D_GL_EXT_NONE },
5360 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), transform_worldex }, WINED3D_GL_EXT_NONE },
5361 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), transform_worldex }, WINED3D_GL_EXT_NONE },
5362 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), transform_worldex }, WINED3D_GL_EXT_NONE },
5363 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), transform_worldex }, WINED3D_GL_EXT_NONE },
5364 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), transform_worldex }, WINED3D_GL_EXT_NONE },
5365 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), transform_worldex }, WINED3D_GL_EXT_NONE },
5366 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), transform_worldex }, WINED3D_GL_EXT_NONE },
5367 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), transform_worldex }, WINED3D_GL_EXT_NONE },
5368 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), transform_worldex }, WINED3D_GL_EXT_NONE },
5369 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), transform_worldex }, WINED3D_GL_EXT_NONE },
5370 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), transform_worldex }, WINED3D_GL_EXT_NONE },
5371 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), transform_worldex }, WINED3D_GL_EXT_NONE },
5372 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), transform_worldex }, WINED3D_GL_EXT_NONE },
5373 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), transform_worldex }, WINED3D_GL_EXT_NONE },
5374 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), transform_worldex }, WINED3D_GL_EXT_NONE },
5375 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), transform_worldex }, WINED3D_GL_EXT_NONE },
5376 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), transform_worldex }, WINED3D_GL_EXT_NONE },
5377 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), transform_worldex }, WINED3D_GL_EXT_NONE },
5378 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), transform_worldex }, WINED3D_GL_EXT_NONE },
5379 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), transform_worldex }, WINED3D_GL_EXT_NONE },
5380 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), transform_worldex }, WINED3D_GL_EXT_NONE },
5381 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), transform_worldex }, WINED3D_GL_EXT_NONE },
5382 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), transform_worldex }, WINED3D_GL_EXT_NONE },
5383 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), transform_worldex }, WINED3D_GL_EXT_NONE },
5384 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), transform_worldex }, WINED3D_GL_EXT_NONE },
5385 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), transform_worldex }, WINED3D_GL_EXT_NONE },
5386 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), transform_worldex }, WINED3D_GL_EXT_NONE },
5387 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), transform_worldex }, WINED3D_GL_EXT_NONE },
5388 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), transform_worldex }, WINED3D_GL_EXT_NONE },
5389 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), transform_worldex }, WINED3D_GL_EXT_NONE },
5390 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), transform_worldex }, WINED3D_GL_EXT_NONE },
5391 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), transform_worldex }, WINED3D_GL_EXT_NONE },
5392 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), transform_worldex }, WINED3D_GL_EXT_NONE },
5393 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), transform_worldex }, WINED3D_GL_EXT_NONE },
5394 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), transform_worldex }, WINED3D_GL_EXT_NONE },
5395 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), transform_worldex }, WINED3D_GL_EXT_NONE },
5396 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), transform_worldex }, WINED3D_GL_EXT_NONE },
5397 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), transform_worldex }, WINED3D_GL_EXT_NONE },
5398 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), transform_worldex }, WINED3D_GL_EXT_NONE },
5399 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), transform_worldex }, WINED3D_GL_EXT_NONE },
5400 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), transform_worldex }, WINED3D_GL_EXT_NONE },
5401 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), transform_worldex }, WINED3D_GL_EXT_NONE },
5402 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), transform_worldex }, WINED3D_GL_EXT_NONE },
5403 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), transform_worldex }, WINED3D_GL_EXT_NONE },
5404 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), transform_worldex }, WINED3D_GL_EXT_NONE },
5405 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), transform_worldex }, WINED3D_GL_EXT_NONE },
5406 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), transform_worldex }, WINED3D_GL_EXT_NONE },
5407 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), transform_worldex }, WINED3D_GL_EXT_NONE },
5408 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), transform_worldex }, WINED3D_GL_EXT_NONE },
5409 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), transform_worldex }, WINED3D_GL_EXT_NONE },
5410 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), transform_worldex }, WINED3D_GL_EXT_NONE },
5411 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), transform_worldex }, WINED3D_GL_EXT_NONE },
5412 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), transform_worldex }, WINED3D_GL_EXT_NONE },
5413 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), transform_worldex }, WINED3D_GL_EXT_NONE },
5414 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), transform_worldex }, WINED3D_GL_EXT_NONE },
5415 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), transform_worldex }, WINED3D_GL_EXT_NONE },
5416 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), transform_worldex }, WINED3D_GL_EXT_NONE },
5417 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), transform_worldex }, WINED3D_GL_EXT_NONE },
5418 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), transform_worldex }, WINED3D_GL_EXT_NONE },
5419 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), transform_worldex }, WINED3D_GL_EXT_NONE },
5420 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), transform_worldex }, WINED3D_GL_EXT_NONE },
5421 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), transform_worldex }, WINED3D_GL_EXT_NONE },
5422 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), transform_worldex }, WINED3D_GL_EXT_NONE },
5423 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), transform_worldex }, WINED3D_GL_EXT_NONE },
5424 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), transform_worldex }, WINED3D_GL_EXT_NONE },
5425 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), transform_worldex }, WINED3D_GL_EXT_NONE },
5426 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), transform_worldex }, WINED3D_GL_EXT_NONE },
5427 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), transform_worldex }, WINED3D_GL_EXT_NONE },
5428 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), transform_worldex }, WINED3D_GL_EXT_NONE },
5429 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), transform_worldex }, WINED3D_GL_EXT_NONE },
5430 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), transform_worldex }, WINED3D_GL_EXT_NONE },
5431 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), transform_worldex }, WINED3D_GL_EXT_NONE },
5432 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), transform_worldex }, WINED3D_GL_EXT_NONE },
5433 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), transform_worldex }, WINED3D_GL_EXT_NONE },
5434 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), transform_worldex }, WINED3D_GL_EXT_NONE },
5435 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), transform_worldex }, WINED3D_GL_EXT_NONE },
5436 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), transform_worldex }, WINED3D_GL_EXT_NONE },
5437 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), transform_worldex }, WINED3D_GL_EXT_NONE },
5438 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), transform_worldex }, WINED3D_GL_EXT_NONE },
5439 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), transform_worldex }, WINED3D_GL_EXT_NONE },
5440 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), transform_worldex }, WINED3D_GL_EXT_NONE },
5441 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), transform_worldex }, WINED3D_GL_EXT_NONE },
5442 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), transform_worldex }, WINED3D_GL_EXT_NONE },
5443 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), transform_worldex }, WINED3D_GL_EXT_NONE },
5444 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), transform_worldex }, WINED3D_GL_EXT_NONE },
5445 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), transform_worldex }, WINED3D_GL_EXT_NONE },
5446 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), transform_worldex }, WINED3D_GL_EXT_NONE },
5447 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), transform_worldex }, WINED3D_GL_EXT_NONE },
5448 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), transform_worldex }, WINED3D_GL_EXT_NONE },
5449 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), transform_worldex }, WINED3D_GL_EXT_NONE },
5450 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), transform_worldex }, WINED3D_GL_EXT_NONE },
5451 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), transform_worldex }, WINED3D_GL_EXT_NONE },
5452 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), transform_worldex }, WINED3D_GL_EXT_NONE },
5453 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), transform_worldex }, WINED3D_GL_EXT_NONE },
5454 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), transform_worldex }, WINED3D_GL_EXT_NONE },
5455 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), transform_worldex }, WINED3D_GL_EXT_NONE },
5456 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), transform_worldex }, WINED3D_GL_EXT_NONE },
5457 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), transform_worldex }, WINED3D_GL_EXT_NONE },
5458 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), transform_worldex }, WINED3D_GL_EXT_NONE },
5459 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), transform_worldex }, WINED3D_GL_EXT_NONE },
5460 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), transform_worldex }, WINED3D_GL_EXT_NONE },
5461 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), transform_worldex }, WINED3D_GL_EXT_NONE },
5462 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), transform_worldex }, WINED3D_GL_EXT_NONE },
5463 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), transform_worldex }, WINED3D_GL_EXT_NONE },
5464 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), transform_worldex }, WINED3D_GL_EXT_NONE },
5465 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), transform_worldex }, WINED3D_GL_EXT_NONE },
5466 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), transform_worldex }, WINED3D_GL_EXT_NONE },
5467 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), transform_worldex }, WINED3D_GL_EXT_NONE },
5468 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), transform_worldex }, WINED3D_GL_EXT_NONE },
5469 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), transform_worldex }, WINED3D_GL_EXT_NONE },
5470 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), transform_worldex }, WINED3D_GL_EXT_NONE },
5471 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), transform_worldex }, WINED3D_GL_EXT_NONE },
5472 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), transform_worldex }, WINED3D_GL_EXT_NONE },
5473 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), transform_worldex }, WINED3D_GL_EXT_NONE },
5474 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), transform_worldex }, WINED3D_GL_EXT_NONE },
5475 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), transform_worldex }, WINED3D_GL_EXT_NONE },
5476 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), transform_worldex }, WINED3D_GL_EXT_NONE },
5477 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), transform_worldex }, WINED3D_GL_EXT_NONE },
5478 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), transform_worldex }, WINED3D_GL_EXT_NONE },
5479 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), transform_worldex }, WINED3D_GL_EXT_NONE },
5480 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), transform_worldex }, WINED3D_GL_EXT_NONE },
5481 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), transform_worldex }, WINED3D_GL_EXT_NONE },
5482 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), transform_worldex }, WINED3D_GL_EXT_NONE },
5483 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), transform_worldex }, WINED3D_GL_EXT_NONE },
5484 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), transform_worldex }, WINED3D_GL_EXT_NONE },
5485 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), transform_worldex }, WINED3D_GL_EXT_NONE },
5486 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), transform_worldex }, WINED3D_GL_EXT_NONE },
5487 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), transform_worldex }, WINED3D_GL_EXT_NONE },
5488 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), transform_worldex }, WINED3D_GL_EXT_NONE },
5489 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), transform_worldex }, WINED3D_GL_EXT_NONE },
5490 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), transform_worldex }, WINED3D_GL_EXT_NONE },
5491 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), transform_worldex }, WINED3D_GL_EXT_NONE },
5492 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), transform_worldex }, WINED3D_GL_EXT_NONE },
5493 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), transform_worldex }, WINED3D_GL_EXT_NONE },
5494 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), transform_worldex }, WINED3D_GL_EXT_NONE },
5495 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), transform_worldex }, WINED3D_GL_EXT_NONE },
5496 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), transform_worldex }, WINED3D_GL_EXT_NONE },
5497 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), transform_worldex }, WINED3D_GL_EXT_NONE },
5498 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), transform_worldex }, WINED3D_GL_EXT_NONE },
5499 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), transform_worldex }, WINED3D_GL_EXT_NONE },
5500 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), transform_worldex }, WINED3D_GL_EXT_NONE },
5501 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), transform_worldex }, WINED3D_GL_EXT_NONE },
5502 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), transform_worldex }, WINED3D_GL_EXT_NONE },
5503 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), transform_worldex }, WINED3D_GL_EXT_NONE },
5504 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), transform_worldex }, WINED3D_GL_EXT_NONE },
5505 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), transform_worldex }, WINED3D_GL_EXT_NONE },
5506 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), transform_worldex }, WINED3D_GL_EXT_NONE },
5507 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), transform_worldex }, WINED3D_GL_EXT_NONE },
5508 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), transform_worldex }, WINED3D_GL_EXT_NONE },
5509 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), transform_worldex }, WINED3D_GL_EXT_NONE },
5510 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), transform_worldex }, WINED3D_GL_EXT_NONE },
5511 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), transform_worldex }, WINED3D_GL_EXT_NONE },
5512 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), transform_worldex }, WINED3D_GL_EXT_NONE },
5513 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), transform_worldex }, WINED3D_GL_EXT_NONE },
5514 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), transform_worldex }, WINED3D_GL_EXT_NONE },
5515 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), transform_worldex }, WINED3D_GL_EXT_NONE },
5516 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), transform_worldex }, WINED3D_GL_EXT_NONE },
5517 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), transform_worldex }, WINED3D_GL_EXT_NONE },
5518 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), transform_worldex }, WINED3D_GL_EXT_NONE },
5519 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), transform_worldex }, WINED3D_GL_EXT_NONE },
5520 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), transform_worldex }, WINED3D_GL_EXT_NONE },
5521 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), transform_worldex }, WINED3D_GL_EXT_NONE },
5522 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), transform_worldex }, WINED3D_GL_EXT_NONE },
5523 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), transform_worldex }, WINED3D_GL_EXT_NONE },
5524 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), transform_worldex }, WINED3D_GL_EXT_NONE },
5525 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), transform_worldex }, WINED3D_GL_EXT_NONE },
5526 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), transform_worldex }, WINED3D_GL_EXT_NONE },
5527 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), transform_worldex }, WINED3D_GL_EXT_NONE },
5528 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), transform_worldex }, WINED3D_GL_EXT_NONE },
5529 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), transform_worldex }, WINED3D_GL_EXT_NONE },
5530 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), transform_worldex }, WINED3D_GL_EXT_NONE },
5531 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), transform_worldex }, WINED3D_GL_EXT_NONE },
5532 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), transform_worldex }, WINED3D_GL_EXT_NONE },
5533 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), transform_worldex }, WINED3D_GL_EXT_NONE },
5534 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), transform_worldex }, WINED3D_GL_EXT_NONE },
5535 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), transform_worldex }, WINED3D_GL_EXT_NONE },
5536 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), transform_worldex }, WINED3D_GL_EXT_NONE },
5537 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), transform_worldex }, WINED3D_GL_EXT_NONE },
5538 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), transform_worldex }, WINED3D_GL_EXT_NONE },
5539 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), transform_worldex }, WINED3D_GL_EXT_NONE },
5540 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), transform_worldex }, WINED3D_GL_EXT_NONE },
5541 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), transform_worldex }, WINED3D_GL_EXT_NONE },
5542 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), transform_worldex }, WINED3D_GL_EXT_NONE },
5543 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), transform_worldex }, WINED3D_GL_EXT_NONE },
5544 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), transform_worldex }, WINED3D_GL_EXT_NONE },
5545 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), transform_worldex }, WINED3D_GL_EXT_NONE },
5546 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), transform_worldex }, WINED3D_GL_EXT_NONE },
5547 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), transform_worldex }, WINED3D_GL_EXT_NONE },
5548 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), transform_worldex }, WINED3D_GL_EXT_NONE },
5549 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), transform_worldex }, WINED3D_GL_EXT_NONE },
5550 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), transform_worldex }, WINED3D_GL_EXT_NONE },
5551 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), transform_worldex }, WINED3D_GL_EXT_NONE },
5552 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), transform_worldex }, WINED3D_GL_EXT_NONE },
5553 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), transform_worldex }, WINED3D_GL_EXT_NONE },
5554 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), transform_worldex }, WINED3D_GL_EXT_NONE },
5555 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), transform_worldex }, WINED3D_GL_EXT_NONE },
5556 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), transform_worldex }, WINED3D_GL_EXT_NONE },
5557 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), transform_worldex }, WINED3D_GL_EXT_NONE },
5558 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), transform_worldex }, WINED3D_GL_EXT_NONE },
5559 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), transform_worldex }, WINED3D_GL_EXT_NONE },
5560 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), transform_worldex }, WINED3D_GL_EXT_NONE },
5561 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), transform_worldex }, WINED3D_GL_EXT_NONE },
5562 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), transform_worldex }, WINED3D_GL_EXT_NONE },
5563 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), transform_worldex }, WINED3D_GL_EXT_NONE },
5564 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), transform_worldex }, WINED3D_GL_EXT_NONE },
5565 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), transform_worldex }, WINED3D_GL_EXT_NONE },
5566 { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), transform_worldex }, WINED3D_GL_EXT_NONE },
5567 { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5568 { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5569 { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5570 { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5571 { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5572 { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5573 { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5574 { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
5575 { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5576 { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5577 { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5578 { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5579 { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5580 { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5581 { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5582 { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE },
5583 /* Fog */
5584 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_vertexpart}, WINED3D_GL_EXT_NONE },
5585 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5586 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5587 { STATE_RENDER(WINED3D_RS_RANGEFOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5588 { STATE_RENDER(WINED3D_RS_CLIPPING), { STATE_RENDER(WINED3D_RS_CLIPPING), state_clipping }, WINED3D_GL_EXT_NONE },
5589 { STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE), { STATE_RENDER(WINED3D_RS_CLIPPING), NULL }, WINED3D_GL_EXT_NONE },
5590 { STATE_RENDER(WINED3D_RS_LIGHTING), { STATE_RENDER(WINED3D_RS_LIGHTING), state_lighting }, WINED3D_GL_EXT_NONE },
5591 { STATE_RENDER(WINED3D_RS_AMBIENT), { STATE_RENDER(WINED3D_RS_AMBIENT), state_ambient }, WINED3D_GL_EXT_NONE },
5592 { STATE_RENDER(WINED3D_RS_COLORVERTEX), { STATE_RENDER(WINED3D_RS_COLORVERTEX), state_colormat }, WINED3D_GL_EXT_NONE },
5593 { STATE_RENDER(WINED3D_RS_LOCALVIEWER), { STATE_RENDER(WINED3D_RS_LOCALVIEWER), state_localviewer }, WINED3D_GL_EXT_NONE },
5594 { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), state_normalize }, WINED3D_GL_EXT_NONE },
5595 { STATE_RENDER(WINED3D_RS_DIFFUSEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5596 { STATE_RENDER(WINED3D_RS_SPECULARMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5597 { STATE_RENDER(WINED3D_RS_AMBIENTMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5598 { STATE_RENDER(WINED3D_RS_EMISSIVEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE },
5599 { STATE_RENDER(WINED3D_RS_VERTEXBLEND), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), state_vertexblend }, ARB_VERTEX_BLEND },
5600 { STATE_RENDER(WINED3D_RS_VERTEXBLEND), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), state_vertexblend_w }, WINED3D_GL_EXT_NONE },
5601 { STATE_RENDER(WINED3D_RS_POINTSIZE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5602 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_arb }, ARB_POINT_PARAMETERS },
5603 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_ext }, EXT_POINT_PARAMETERS },
5604 { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_w }, WINED3D_GL_EXT_NONE },
5605 { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite }, ARB_POINT_SPRITE },
5606 { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite_w }, WINED3D_GL_EXT_NONE },
5607 { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), state_pscale }, WINED3D_GL_EXT_NONE },
5608 { STATE_RENDER(WINED3D_RS_POINTSCALE_A), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5609 { STATE_RENDER(WINED3D_RS_POINTSCALE_B), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5610 { STATE_RENDER(WINED3D_RS_POINTSCALE_C), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
5611 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, ARB_POINT_PARAMETERS },
5612 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, EXT_POINT_PARAMETERS },
5613 { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, WINED3D_GL_EXT_NONE },
5614 { STATE_RENDER(WINED3D_RS_TWEENFACTOR), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE },
5615 { STATE_RENDER(WINED3D_RS_INDEXEDVERTEXBLENDENABLE), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE },
5617 /* Samplers for NP2 texture matrix adjustions. They are not needed if GL_ARB_texture_non_power_of_two is supported,
5618 * so register a NULL state handler in that case to get the vertex part of sampler() skipped(VTF is handled in the misc states.
5619 * otherwise, register sampler_texmatrix, which takes care of updating the texture matrix
5621 { STATE_SAMPLER(0), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5622 { STATE_SAMPLER(0), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5623 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5624 { STATE_SAMPLER(1), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5625 { STATE_SAMPLER(1), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5626 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5627 { STATE_SAMPLER(2), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5628 { STATE_SAMPLER(2), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5629 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5630 { STATE_SAMPLER(3), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5631 { STATE_SAMPLER(3), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5632 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5633 { STATE_SAMPLER(4), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5634 { STATE_SAMPLER(4), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5635 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5636 { STATE_SAMPLER(5), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5637 { STATE_SAMPLER(5), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5638 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5639 { STATE_SAMPLER(6), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5640 { STATE_SAMPLER(6), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5641 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5642 { STATE_SAMPLER(7), { 0, NULL }, ARB_TEXTURE_NON_POWER_OF_TWO },
5643 { STATE_SAMPLER(7), { 0, NULL }, WINED3D_GL_NORMALIZED_TEXRECT },
5644 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texmatrix }, WINED3D_GL_EXT_NONE },
5645 { STATE_POINT_ENABLE, { STATE_POINT_ENABLE, state_nop }, WINED3D_GL_EXT_NONE },
5646 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5649 static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
5650 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5651 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5652 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5653 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5654 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5655 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5656 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5657 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5658 { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5659 { STATE_TEXTURESTAGE(0, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5660 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5661 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5662 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5663 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5664 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5665 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5666 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5667 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5668 { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5669 { STATE_TEXTURESTAGE(1, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5670 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5671 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5672 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5673 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5674 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5675 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5676 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5677 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5678 { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5679 { STATE_TEXTURESTAGE(2, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5680 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5681 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5682 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5683 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5684 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5685 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5686 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5687 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5688 { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5689 { STATE_TEXTURESTAGE(3, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5690 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5691 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5692 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5693 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5694 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5695 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5696 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5697 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5698 { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5699 { STATE_TEXTURESTAGE(4, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5700 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5701 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5702 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5703 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5704 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5705 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5706 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5707 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5708 { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5709 { STATE_TEXTURESTAGE(5, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5710 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5711 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5712 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5713 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5714 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5715 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5716 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5717 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5718 { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5719 { STATE_TEXTURESTAGE(6, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5720 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE },
5721 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5722 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5723 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
5724 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5725 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5726 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5727 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
5728 { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
5729 { STATE_TEXTURESTAGE(7, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE },
5730 { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), apply_pixelshader }, WINED3D_GL_EXT_NONE },
5731 { STATE_RENDER(WINED3D_RS_ALPHAFUNC), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5732 { STATE_RENDER(WINED3D_RS_ALPHAREF), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5733 { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), state_alpha_test }, WINED3D_GL_EXT_NONE },
5734 { STATE_RENDER(WINED3D_RS_COLORKEYENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE },
5735 { STATE_COLOR_KEY, { STATE_COLOR_KEY, state_nop }, WINED3D_GL_EXT_NONE },
5736 { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), NULL }, WINED3D_GL_EXT_NONE },
5737 { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), state_texfactor }, WINED3D_GL_EXT_NONE },
5738 { STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
5739 { STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
5740 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
5741 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5742 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
5743 { STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
5744 { STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE },
5745 { STATE_RENDER(WINED3D_RS_SHADEMODE), { STATE_RENDER(WINED3D_RS_SHADEMODE), state_shademode }, WINED3D_GL_EXT_NONE },
5746 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE },
5747 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE },
5748 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE },
5749 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, WINED3D_GL_EXT_NONE },
5750 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, WINED3D_GL_EXT_NONE },
5751 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE },
5752 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE },
5753 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE },
5754 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
5757 /* Context activation is done by the caller. */
5758 static void ffp_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5760 static void *ffp_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
5762 return shader_priv;
5765 static void ffp_free(struct wined3d_device *device) {}
5767 static void vp_ffp_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
5769 caps->xyzrhw = FALSE;
5770 caps->ffp_generic_attributes = FALSE;
5771 caps->max_active_lights = gl_info->limits.lights;
5772 caps->max_vertex_blend_matrices = gl_info->limits.blends;
5773 caps->max_vertex_blend_matrix_index = 0;
5774 caps->vertex_processing_caps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS
5775 | WINED3DVTXPCAPS_MATERIALSOURCE7
5776 | WINED3DVTXPCAPS_POSITIONALLIGHTS
5777 | WINED3DVTXPCAPS_LOCALVIEWER
5778 | WINED3DVTXPCAPS_VERTEXFOG
5779 | WINED3DVTXPCAPS_TEXGEN
5780 | WINED3DVTXPCAPS_TEXGEN_SPHEREMAP;
5781 caps->fvf_caps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
5782 caps->max_user_clip_planes = gl_info->limits.user_clip_distances;
5783 caps->raster_caps = 0;
5784 if (gl_info->supported[NV_FOG_DISTANCE])
5785 caps->raster_caps |= WINED3DPRASTERCAPS_FOGRANGE;
5788 static DWORD vp_ffp_get_emul_mask(const struct wined3d_gl_info *gl_info)
5790 return GL_EXT_EMUL_ARB_MULTITEXTURE | GL_EXT_EMUL_EXT_FOG_COORD;
5793 const struct wined3d_vertex_pipe_ops ffp_vertex_pipe =
5795 ffp_enable,
5796 vp_ffp_get_caps,
5797 vp_ffp_get_emul_mask,
5798 ffp_alloc,
5799 ffp_free,
5800 vp_ffp_states,
5803 static void ffp_fragment_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
5805 caps->wined3d_caps = 0;
5806 caps->PrimitiveMiscCaps = 0;
5807 caps->TextureOpCaps = WINED3DTEXOPCAPS_ADD
5808 | WINED3DTEXOPCAPS_ADDSIGNED
5809 | WINED3DTEXOPCAPS_ADDSIGNED2X
5810 | WINED3DTEXOPCAPS_MODULATE
5811 | WINED3DTEXOPCAPS_MODULATE2X
5812 | WINED3DTEXOPCAPS_MODULATE4X
5813 | WINED3DTEXOPCAPS_SELECTARG1
5814 | WINED3DTEXOPCAPS_SELECTARG2
5815 | WINED3DTEXOPCAPS_DISABLE;
5817 if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE]
5818 || gl_info->supported[EXT_TEXTURE_ENV_COMBINE]
5819 || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
5821 caps->TextureOpCaps |= WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
5822 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
5823 | WINED3DTEXOPCAPS_BLENDFACTORALPHA
5824 | WINED3DTEXOPCAPS_BLENDCURRENTALPHA
5825 | WINED3DTEXOPCAPS_LERP
5826 | WINED3DTEXOPCAPS_SUBTRACT;
5828 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]
5829 || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
5831 caps->TextureOpCaps |= WINED3DTEXOPCAPS_ADDSMOOTH
5832 | WINED3DTEXOPCAPS_MULTIPLYADD
5833 | WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
5834 | WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
5835 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
5837 if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
5838 caps->TextureOpCaps |= WINED3DTEXOPCAPS_DOTPRODUCT3;
5840 caps->MaxTextureBlendStages = gl_info->limits.textures;
5841 caps->MaxSimultaneousTextures = gl_info->limits.textures;
5844 static DWORD ffp_fragment_get_emul_mask(const struct wined3d_gl_info *gl_info)
5846 return GL_EXT_EMUL_ARB_MULTITEXTURE | GL_EXT_EMUL_EXT_FOG_COORD;
5849 static BOOL ffp_color_fixup_supported(struct color_fixup_desc fixup)
5851 /* We only support identity conversions. */
5852 return is_identity_fixup(fixup);
5855 static BOOL ffp_none_context_alloc(struct wined3d_context *context)
5857 return TRUE;
5860 static void ffp_none_context_free(struct wined3d_context *context)
5864 const struct fragment_pipeline ffp_fragment_pipeline = {
5865 ffp_enable,
5866 ffp_fragment_get_caps,
5867 ffp_fragment_get_emul_mask,
5868 ffp_alloc,
5869 ffp_free,
5870 ffp_none_context_alloc,
5871 ffp_none_context_free,
5872 ffp_color_fixup_supported,
5873 ffp_fragmentstate_template,
5876 static void none_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5878 static void *none_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
5880 return shader_priv;
5883 static void none_free(struct wined3d_device *device) {}
5885 static void vp_none_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
5887 memset(caps, 0, sizeof(*caps));
5890 static DWORD vp_none_get_emul_mask(const struct wined3d_gl_info *gl_info)
5892 return 0;
5895 const struct wined3d_vertex_pipe_ops none_vertex_pipe =
5897 none_enable,
5898 vp_none_get_caps,
5899 vp_none_get_emul_mask,
5900 none_alloc,
5901 none_free,
5902 NULL,
5905 static void fp_none_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
5907 memset(caps, 0, sizeof(*caps));
5910 static DWORD fp_none_get_emul_mask(const struct wined3d_gl_info *gl_info)
5912 return 0;
5915 static BOOL fp_none_color_fixup_supported(struct color_fixup_desc fixup)
5917 return is_identity_fixup(fixup);
5920 const struct fragment_pipeline none_fragment_pipe =
5922 none_enable,
5923 fp_none_get_caps,
5924 fp_none_get_emul_mask,
5925 none_alloc,
5926 none_free,
5927 ffp_none_context_alloc,
5928 ffp_none_context_free,
5929 fp_none_color_fixup_supported,
5930 NULL,
5933 static unsigned int num_handlers(const APPLYSTATEFUNC *funcs)
5935 unsigned int i;
5936 for(i = 0; funcs[i]; i++);
5937 return i;
5940 static void multistate_apply_2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5942 context->device->multistate_funcs[state_id][0](context, state, state_id);
5943 context->device->multistate_funcs[state_id][1](context, state, state_id);
5946 static void multistate_apply_3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5948 context->device->multistate_funcs[state_id][0](context, state, state_id);
5949 context->device->multistate_funcs[state_id][1](context, state, state_id);
5950 context->device->multistate_funcs[state_id][2](context, state, state_id);
5953 static void prune_invalid_states(struct StateEntry *state_table, const struct wined3d_gl_info *gl_info,
5954 const struct wined3d_d3d_info *d3d_info)
5956 unsigned int start, last, i;
5958 start = STATE_TEXTURESTAGE(d3d_info->limits.ffp_blend_stages, 0);
5959 last = STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE);
5960 for (i = start; i <= last; ++i)
5962 state_table[i].representative = 0;
5963 state_table[i].apply = state_undefined;
5966 start = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + d3d_info->limits.ffp_blend_stages);
5967 last = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + MAX_TEXTURES - 1);
5968 for (i = start; i <= last; ++i)
5970 state_table[i].representative = 0;
5971 state_table[i].apply = state_undefined;
5974 start = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(d3d_info->limits.ffp_vertex_blend_matrices));
5975 last = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255));
5976 for (i = start; i <= last; ++i)
5978 state_table[i].representative = 0;
5979 state_table[i].apply = state_undefined;
5983 static void validate_state_table(struct StateEntry *state_table)
5985 static const struct
5987 DWORD first;
5988 DWORD last;
5990 rs_holes[] =
5992 { 1, 1},
5993 { 3, 3},
5994 { 17, 18},
5995 { 21, 21},
5996 { 42, 45},
5997 { 47, 47},
5998 { 61, 127},
5999 {149, 150},
6000 {169, 169},
6001 {177, 177},
6002 {196, 197},
6003 { 0, 0},
6005 static const DWORD simple_states[] =
6007 STATE_MATERIAL,
6008 STATE_VDECL,
6009 STATE_STREAMSRC,
6010 STATE_INDEXBUFFER,
6011 STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX),
6012 STATE_SHADER(WINED3D_SHADER_TYPE_HULL),
6013 STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN),
6014 STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY),
6015 STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),
6016 STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE),
6017 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),
6018 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL),
6019 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN),
6020 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),
6021 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),
6022 STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE),
6023 STATE_COMPUTE_SHADER_RESOURCE_BINDING,
6024 STATE_GRAPHICS_SHADER_RESOURCE_BINDING,
6025 STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING,
6026 STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING,
6027 STATE_VIEWPORT,
6028 STATE_LIGHT_TYPE,
6029 STATE_SCISSORRECT,
6030 STATE_FRONTFACE,
6031 STATE_POINTSPRITECOORDORIGIN,
6032 STATE_BASEVERTEXINDEX,
6033 STATE_FRAMEBUFFER,
6034 STATE_POINT_ENABLE,
6035 STATE_COLOR_KEY,
6037 unsigned int i, current;
6039 for (i = STATE_RENDER(1), current = 0; i <= STATE_RENDER(WINEHIGHEST_RENDER_STATE); ++i)
6041 if (!rs_holes[current].first || i < STATE_RENDER(rs_holes[current].first))
6043 if (!state_table[i].representative)
6044 ERR("State %s (%#x) should have a representative.\n", debug_d3dstate(i), i);
6046 else if (state_table[i].representative)
6047 ERR("State %s (%#x) shouldn't have a representative.\n", debug_d3dstate(i), i);
6049 if (i == STATE_RENDER(rs_holes[current].last)) ++current;
6052 for (i = 0; i < ARRAY_SIZE(simple_states); ++i)
6054 if (!state_table[simple_states[i]].representative)
6055 ERR("State %s (%#x) should have a representative.\n",
6056 debug_d3dstate(simple_states[i]), simple_states[i]);
6059 for (i = 0; i < STATE_HIGHEST + 1; ++i)
6061 DWORD rep = state_table[i].representative;
6062 if (rep)
6064 if (state_table[rep].representative != rep)
6066 ERR("State %s (%#x) has invalid representative %s (%#x).\n",
6067 debug_d3dstate(i), i, debug_d3dstate(rep), rep);
6068 state_table[i].representative = 0;
6071 if (rep != i)
6073 if (state_table[i].apply)
6074 ERR("State %s (%#x) has both a handler and representative.\n", debug_d3dstate(i), i);
6076 else if (!state_table[i].apply)
6078 ERR("Self representing state %s (%#x) has no handler.\n", debug_d3dstate(i), i);
6084 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
6085 const struct wined3d_gl_info *gl_info, const struct wined3d_d3d_info *d3d_info,
6086 const struct wined3d_vertex_pipe_ops *vertex, const struct fragment_pipeline *fragment,
6087 const struct StateEntryTemplate *misc)
6089 unsigned int i, type, handlers;
6090 APPLYSTATEFUNC multistate_funcs[STATE_HIGHEST + 1][3];
6091 const struct StateEntryTemplate *cur;
6092 BOOL set[STATE_HIGHEST + 1];
6094 memset(multistate_funcs, 0, sizeof(multistate_funcs));
6096 for(i = 0; i < STATE_HIGHEST + 1; i++) {
6097 StateTable[i].representative = 0;
6098 StateTable[i].apply = state_undefined;
6101 for(type = 0; type < 3; type++) {
6102 /* This switch decides the order in which the states are applied */
6103 switch(type) {
6104 case 0: cur = misc; break;
6105 case 1: cur = fragment->states; break;
6106 case 2: cur = vertex->vp_states; break;
6107 default: cur = NULL; /* Stupid compiler */
6109 if(!cur) continue;
6111 /* GL extension filtering should not prevent multiple handlers being applied from different
6112 * pipeline parts
6114 memset(set, 0, sizeof(set));
6116 for(i = 0; cur[i].state; i++) {
6117 APPLYSTATEFUNC *funcs_array;
6119 /* Only use the first matching state with the available extension from one template.
6120 * e.g.
6121 * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func1}, XYZ_FANCY},
6122 * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func2}, 0 }
6124 * if GL_XYZ_fancy is supported, ignore the 2nd line
6126 if(set[cur[i].state]) continue;
6127 /* Skip state lines depending on unsupported extensions */
6128 if (!gl_info->supported[cur[i].extension]) continue;
6129 set[cur[i].state] = TRUE;
6130 /* In some cases having an extension means that nothing has to be
6131 * done for a state, e.g. if GL_ARB_texture_non_power_of_two is
6132 * supported, the texture coordinate fixup can be ignored. If the
6133 * apply function is used, mark the state set(done above) to prevent
6134 * applying later lines, but do not record anything in the state
6135 * table
6137 if (!cur[i].content.representative) continue;
6139 handlers = num_handlers(multistate_funcs[cur[i].state]);
6140 multistate_funcs[cur[i].state][handlers] = cur[i].content.apply;
6141 switch(handlers) {
6142 case 0:
6143 StateTable[cur[i].state].apply = cur[i].content.apply;
6144 break;
6145 case 1:
6146 StateTable[cur[i].state].apply = multistate_apply_2;
6147 if (!(dev_multistate_funcs[cur[i].state] = wined3d_calloc(2, sizeof(**dev_multistate_funcs))))
6148 goto out_of_mem;
6150 dev_multistate_funcs[cur[i].state][0] = multistate_funcs[cur[i].state][0];
6151 dev_multistate_funcs[cur[i].state][1] = multistate_funcs[cur[i].state][1];
6152 break;
6153 case 2:
6154 StateTable[cur[i].state].apply = multistate_apply_3;
6155 funcs_array = HeapReAlloc(GetProcessHeap(),
6157 dev_multistate_funcs[cur[i].state],
6158 sizeof(**dev_multistate_funcs) * 3);
6159 if (!funcs_array) {
6160 goto out_of_mem;
6163 dev_multistate_funcs[cur[i].state] = funcs_array;
6164 dev_multistate_funcs[cur[i].state][2] = multistate_funcs[cur[i].state][2];
6165 break;
6166 default:
6167 ERR("Unexpected amount of state handlers for state %u: %u\n",
6168 cur[i].state, handlers + 1);
6171 if (StateTable[cur[i].state].representative
6172 && StateTable[cur[i].state].representative != cur[i].content.representative)
6174 FIXME("State %s (%#x) has different representatives in different pipeline parts.\n",
6175 debug_d3dstate(cur[i].state), cur[i].state);
6177 StateTable[cur[i].state].representative = cur[i].content.representative;
6181 prune_invalid_states(StateTable, gl_info, d3d_info);
6182 validate_state_table(StateTable);
6184 return WINED3D_OK;
6186 out_of_mem:
6187 for (i = 0; i <= STATE_HIGHEST; ++i) {
6188 HeapFree(GetProcessHeap(), 0, dev_multistate_funcs[i]);
6191 memset(dev_multistate_funcs, 0, (STATE_HIGHEST + 1)*sizeof(*dev_multistate_funcs));
6193 return E_OUTOFMEMORY;