[CMAKE]
[reactos.git] / reactos / dll / directx / wine / wined3d / state.c
1 /*
2 * Direct3D state management
3 *
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
12 *
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.
17 *
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.
22 *
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
26 */
27
28 #include "config.h"
29 #include <stdio.h>
30 #ifdef HAVE_FLOAT_H
31 # include <float.h>
32 #endif
33 #include "wined3d_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
36 WINE_DECLARE_DEBUG_CHANNEL(d3d_shader);
37
38 /* GL locking for state handlers is done by the caller. */
39
40 static void state_blendop(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context);
41
42 static void state_undefined(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
43 {
44 ERR("Undefined state.\n");
45 }
46
47 static void state_nop(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
48 {
49 TRACE("%s: nop in current pipe config.\n", debug_d3dstate(state));
50 }
51
52 static void state_fillmode(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
53 {
54 WINED3DFILLMODE Value = stateblock->state.render_states[WINED3DRS_FILLMODE];
55
56 switch(Value) {
57 case WINED3DFILL_POINT:
58 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
59 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
60 break;
61 case WINED3DFILL_WIREFRAME:
62 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
63 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
64 break;
65 case WINED3DFILL_SOLID:
66 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
67 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
68 break;
69 default:
70 FIXME("Unrecognized WINED3DRS_FILLMODE value %d\n", Value);
71 }
72 }
73
74 static void state_lighting(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
75 {
76 /* Lighting is not enabled if transformed vertices are drawn
77 * but lighting does not affect the stream sources, so it is not grouped for performance reasons.
78 * This state reads the decoded vertex declaration, so if it is dirty don't do anything. The
79 * vertex declaration applying function calls this function for updating
80 */
81
82 if(isStateDirty(context, STATE_VDECL)) {
83 return;
84 }
85
86 if (stateblock->state.render_states[WINED3DRS_LIGHTING]
87 && !stateblock->device->strided_streams.position_transformed)
88 {
89 glEnable(GL_LIGHTING);
90 checkGLcall("glEnable GL_LIGHTING");
91 } else {
92 glDisable(GL_LIGHTING);
93 checkGLcall("glDisable GL_LIGHTING");
94 }
95 }
96
97 static void state_zenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
98 {
99 /* No z test without depth stencil buffers */
100 if (!stateblock->device->fb.depth_stencil)
101 {
102 TRACE("No Z buffer - disabling depth test\n");
103 glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */
104 checkGLcall("glDisable GL_DEPTH_TEST");
105 return;
106 }
107
108 switch (stateblock->state.render_states[WINED3DRS_ZENABLE])
109 {
110 case WINED3DZB_FALSE:
111 glDisable(GL_DEPTH_TEST);
112 checkGLcall("glDisable GL_DEPTH_TEST");
113 break;
114 case WINED3DZB_TRUE:
115 glEnable(GL_DEPTH_TEST);
116 checkGLcall("glEnable GL_DEPTH_TEST");
117 break;
118 case WINED3DZB_USEW:
119 glEnable(GL_DEPTH_TEST);
120 checkGLcall("glEnable GL_DEPTH_TEST");
121 FIXME("W buffer is not well handled\n");
122 break;
123 default:
124 FIXME("Unrecognized D3DZBUFFERTYPE value %#x.\n",
125 stateblock->state.render_states[WINED3DRS_ZENABLE]);
126 }
127 }
128
129 static void state_cullmode(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
130 {
131 /* glFrontFace() is set in context.c at context init and on an
132 * offscreen / onscreen rendering switch. */
133 switch (stateblock->state.render_states[WINED3DRS_CULLMODE])
134 {
135 case WINED3DCULL_NONE:
136 glDisable(GL_CULL_FACE);
137 checkGLcall("glDisable GL_CULL_FACE");
138 break;
139 case WINED3DCULL_CW:
140 glEnable(GL_CULL_FACE);
141 checkGLcall("glEnable GL_CULL_FACE");
142 glCullFace(GL_FRONT);
143 checkGLcall("glCullFace(GL_FRONT)");
144 break;
145 case WINED3DCULL_CCW:
146 glEnable(GL_CULL_FACE);
147 checkGLcall("glEnable GL_CULL_FACE");
148 glCullFace(GL_BACK);
149 checkGLcall("glCullFace(GL_BACK)");
150 break;
151 default:
152 FIXME("Unrecognized/Unhandled WINED3DCULL value %#x.\n",
153 stateblock->state.render_states[WINED3DRS_CULLMODE]);
154 }
155 }
156
157 static void state_shademode(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
158 {
159 switch (stateblock->state.render_states[WINED3DRS_SHADEMODE])
160 {
161 case WINED3DSHADE_FLAT:
162 glShadeModel(GL_FLAT);
163 checkGLcall("glShadeModel(GL_FLAT)");
164 break;
165 case WINED3DSHADE_GOURAUD:
166 glShadeModel(GL_SMOOTH);
167 checkGLcall("glShadeModel(GL_SMOOTH)");
168 break;
169 case WINED3DSHADE_PHONG:
170 FIXME("WINED3DSHADE_PHONG isn't supported\n");
171 break;
172 default:
173 FIXME("Unrecognized/Unhandled WINED3DSHADEMODE value %#x.\n",
174 stateblock->state.render_states[WINED3DRS_SHADEMODE]);
175 }
176 }
177
178 static void state_ditherenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
179 {
180 if (stateblock->state.render_states[WINED3DRS_DITHERENABLE])
181 {
182 glEnable(GL_DITHER);
183 checkGLcall("glEnable GL_DITHER");
184 }
185 else
186 {
187 glDisable(GL_DITHER);
188 checkGLcall("glDisable GL_DITHER");
189 }
190 }
191
192 static void state_zwritenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
193 {
194 /* TODO: Test if in d3d z writing is enabled even if ZENABLE is off.
195 * If yes, this has to be merged with ZENABLE and ZFUNC. */
196 if (stateblock->state.render_states[WINED3DRS_ZWRITEENABLE])
197 {
198 glDepthMask(1);
199 checkGLcall("glDepthMask(1)");
200 }
201 else
202 {
203 glDepthMask(0);
204 checkGLcall("glDepthMask(0)");
205 }
206 }
207
208 static void state_zfunc(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
209 {
210 GLenum depth_func = CompareFunc(stateblock->state.render_states[WINED3DRS_ZFUNC]);
211
212 if (!depth_func) return;
213
214 if (depth_func == GL_EQUAL || depth_func == GL_NOTEQUAL)
215 {
216 static BOOL once;
217 /* There are a few issues with this: First, our inability to
218 * select a proper Z depth, most of the time we're stuck with
219 * D24S8, even if the app selects D32 or D16. There seem to be
220 * some other precision problems which have to be debugged to
221 * make NOTEQUAL and EQUAL work properly. */
222 if (!once)
223 {
224 once = TRUE;
225 FIXME("D3DCMP_NOTEQUAL and D3DCMP_EQUAL do not work correctly yet.\n");
226 }
227 }
228
229 glDepthFunc(depth_func);
230 checkGLcall("glDepthFunc");
231 }
232
233 static void state_ambient(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
234 {
235 float col[4];
236 D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_AMBIENT], col);
237
238 TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]);
239 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
240 checkGLcall("glLightModel for MODEL_AMBIENT");
241 }
242
243 static GLenum gl_blend_factor(WINED3DBLEND factor, const struct wined3d_format *dst_format)
244 {
245 switch (factor)
246 {
247 case WINED3DBLEND_ZERO:
248 return GL_ZERO;
249 case WINED3DBLEND_ONE:
250 return GL_ONE;
251 case WINED3DBLEND_SRCCOLOR:
252 return GL_SRC_COLOR;
253 case WINED3DBLEND_INVSRCCOLOR:
254 return GL_ONE_MINUS_SRC_COLOR;
255 case WINED3DBLEND_SRCALPHA:
256 return GL_SRC_ALPHA;
257 case WINED3DBLEND_INVSRCALPHA:
258 return GL_ONE_MINUS_SRC_ALPHA;
259 case WINED3DBLEND_DESTCOLOR:
260 return GL_DST_COLOR;
261 case WINED3DBLEND_INVDESTCOLOR:
262 return GL_ONE_MINUS_DST_COLOR;
263 /* To compensate for the lack of format switching with backbuffer
264 * offscreen rendering, and with onscreen rendering, we modify the
265 * alpha test parameters for (INV)DESTALPHA if the render target
266 * doesn't support alpha blending. A nonexistent alpha channel
267 * returns 1.0, so WINED3DBLEND_DESTALPHA becomes GL_ONE, and
268 * WINED3DBLEND_INVDESTALPHA becomes GL_ZERO. */
269 case WINED3DBLEND_DESTALPHA:
270 return dst_format->alpha_mask ? GL_DST_ALPHA : GL_ONE;
271 case WINED3DBLEND_INVDESTALPHA:
272 return dst_format->alpha_mask ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO;
273 case WINED3DBLEND_SRCALPHASAT:
274 return GL_SRC_ALPHA_SATURATE;
275 case WINED3DBLEND_BLENDFACTOR:
276 return GL_CONSTANT_COLOR_EXT;
277 case WINED3DBLEND_INVBLENDFACTOR:
278 return GL_ONE_MINUS_CONSTANT_COLOR_EXT;
279 default:
280 FIXME("Unhandled blend factor %#x.\n", factor);
281 return GL_NONE;
282 }
283 }
284
285 static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
286 {
287 struct wined3d_surface *target = stateblock->device->fb.render_targets[0];
288 const struct wined3d_gl_info *gl_info = context->gl_info;
289 GLenum srcBlend, dstBlend;
290 WINED3DBLEND d3d_blend;
291
292 /* According to the red book, GL_LINE_SMOOTH needs GL_BLEND with specific
293 * blending parameters to work. */
294 if (stateblock->state.render_states[WINED3DRS_ALPHABLENDENABLE]
295 || stateblock->state.render_states[WINED3DRS_EDGEANTIALIAS]
296 || stateblock->state.render_states[WINED3DRS_ANTIALIASEDLINEENABLE])
297 {
298 /* Disable blending in all cases even without pixelshaders.
299 * With blending on we could face a big performance penalty.
300 * The d3d9 visual test confirms the behavior. */
301 if (context->render_offscreen
302 && !(target->resource.format->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
303 {
304 glDisable(GL_BLEND);
305 checkGLcall("glDisable GL_BLEND");
306 return;
307 } else {
308 glEnable(GL_BLEND);
309 checkGLcall("glEnable GL_BLEND");
310 }
311 } else {
312 glDisable(GL_BLEND);
313 checkGLcall("glDisable GL_BLEND");
314 /* Nothing more to do - get out */
315 return;
316 };
317
318 /* WINED3DBLEND_BOTHSRCALPHA and WINED3DBLEND_BOTHINVSRCALPHA are legacy
319 * source blending values which are still valid up to d3d9. They should
320 * not occur as dest blend values. */
321 d3d_blend = stateblock->state.render_states[WINED3DRS_SRCBLEND];
322 if (d3d_blend == WINED3DBLEND_BOTHSRCALPHA)
323 {
324 srcBlend = GL_SRC_ALPHA;
325 dstBlend = GL_ONE_MINUS_SRC_ALPHA;
326 }
327 else if (d3d_blend == WINED3DBLEND_BOTHINVSRCALPHA)
328 {
329 srcBlend = GL_ONE_MINUS_SRC_ALPHA;
330 dstBlend = GL_SRC_ALPHA;
331 }
332 else
333 {
334 srcBlend = gl_blend_factor(d3d_blend, target->resource.format);
335 dstBlend = gl_blend_factor(stateblock->state.render_states[WINED3DRS_DESTBLEND],
336 target->resource.format);
337 }
338
339 if (stateblock->state.render_states[WINED3DRS_EDGEANTIALIAS]
340 || stateblock->state.render_states[WINED3DRS_ANTIALIASEDLINEENABLE])
341 {
342 glEnable(GL_LINE_SMOOTH);
343 checkGLcall("glEnable(GL_LINE_SMOOTH)");
344 if(srcBlend != GL_SRC_ALPHA) {
345 WARN("WINED3DRS_EDGEANTIALIAS enabled, but unexpected src blending param\n");
346 }
347 if(dstBlend != GL_ONE_MINUS_SRC_ALPHA && dstBlend != GL_ONE) {
348 WARN("WINED3DRS_EDGEANTIALIAS enabled, but unexpected dst blending param\n");
349 }
350 } else {
351 glDisable(GL_LINE_SMOOTH);
352 checkGLcall("glDisable(GL_LINE_SMOOTH)");
353 }
354
355 /* Re-apply BLENDOP(ALPHA) because of a possible SEPARATEALPHABLENDENABLE change */
356 if(!isStateDirty(context, STATE_RENDER(WINED3DRS_BLENDOP))) {
357 state_blendop(STATE_RENDER(WINED3DRS_BLENDOPALPHA), stateblock, context);
358 }
359
360 if (stateblock->state.render_states[WINED3DRS_SEPARATEALPHABLENDENABLE])
361 {
362 GLenum srcBlendAlpha, dstBlendAlpha;
363
364 /* Separate alpha blending requires GL_EXT_blend_function_separate, so make sure it is around */
365 if (!context->gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
366 {
367 WARN("Unsupported in local OpenGL implementation: glBlendFuncSeparateEXT\n");
368 return;
369 }
370
371 /* WINED3DBLEND_BOTHSRCALPHA and WINED3DBLEND_BOTHINVSRCALPHA are legacy
372 * source blending values which are still valid up to d3d9. They should
373 * not occur as dest blend values. */
374 d3d_blend = stateblock->state.render_states[WINED3DRS_SRCBLENDALPHA];
375 if (d3d_blend == WINED3DBLEND_BOTHSRCALPHA)
376 {
377 srcBlendAlpha = GL_SRC_ALPHA;
378 dstBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
379 }
380 else if (d3d_blend == WINED3DBLEND_BOTHINVSRCALPHA)
381 {
382 srcBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
383 dstBlendAlpha = GL_SRC_ALPHA;
384 }
385 else
386 {
387 srcBlendAlpha = gl_blend_factor(d3d_blend, target->resource.format);
388 dstBlendAlpha = gl_blend_factor(stateblock->state.render_states[WINED3DRS_DESTBLENDALPHA],
389 target->resource.format);
390 }
391
392 GL_EXTCALL(glBlendFuncSeparateEXT(srcBlend, dstBlend, srcBlendAlpha, dstBlendAlpha));
393 checkGLcall("glBlendFuncSeparateEXT");
394 } else {
395 TRACE("glBlendFunc src=%x, dst=%x\n", srcBlend, dstBlend);
396 glBlendFunc(srcBlend, dstBlend);
397 checkGLcall("glBlendFunc");
398 }
399
400 /* colorkey fixup for stage 0 alphaop depends on WINED3DRS_ALPHABLENDENABLE state,
401 so it may need updating */
402 if (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE])
403 stateblock_apply_state(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context);
404 }
405
406 static void state_blendfactor_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
407 {
408 WARN("Unsupported in local OpenGL implementation: glBlendColorEXT\n");
409 }
410
411 static void state_blendfactor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
412 {
413 const struct wined3d_gl_info *gl_info = context->gl_info;
414 float col[4];
415
416 TRACE("Setting blend factor to %#x.\n", stateblock->state.render_states[WINED3DRS_BLENDFACTOR]);
417 D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_BLENDFACTOR], col);
418 GL_EXTCALL(glBlendColorEXT (col[0],col[1],col[2],col[3]));
419 checkGLcall("glBlendColor");
420 }
421
422 static void state_alpha(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
423 {
424 int glParm = 0;
425 float ref;
426 BOOL enable_ckey = FALSE;
427
428 TRACE("state %#x, stateblock %p, context %p\n", state, stateblock, context);
429
430 /* Find out if the texture on the first stage has a ckey set
431 * The alpha state func reads the texture settings, even though alpha and texture are not grouped
432 * together. This is to avoid making a huge alpha+texture+texture stage+ckey block due to the hardly
433 * used WINED3DRS_COLORKEYENABLE state(which is d3d <= 3 only). The texture function will call alpha
434 * in case it finds some texture+colorkeyenable combination which needs extra care.
435 */
436 if (stateblock->state.textures[0])
437 {
438 struct wined3d_texture *texture = stateblock->state.textures[0];
439 GLenum texture_dimensions = texture->target;
440
441 if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
442 {
443 struct wined3d_surface *surf = surface_from_resource(texture->sub_resources[0]);
444
445 if (surf->CKeyFlags & WINEDDSD_CKSRCBLT)
446 {
447 /* The surface conversion does not do color keying conversion for surfaces that have an alpha
448 * channel on their own. Likewise, the alpha test shouldn't be set up for color keying if the
449 * surface has alpha bits */
450 if (!surf->resource.format->alpha_mask) enable_ckey = TRUE;
451 }
452 }
453 }
454
455 if (enable_ckey || context->last_was_ckey)
456 stateblock_apply_state(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context);
457 context->last_was_ckey = enable_ckey;
458
459 if (stateblock->state.render_states[WINED3DRS_ALPHATESTENABLE]
460 || (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE] && enable_ckey))
461 {
462 glEnable(GL_ALPHA_TEST);
463 checkGLcall("glEnable GL_ALPHA_TEST");
464 } else {
465 glDisable(GL_ALPHA_TEST);
466 checkGLcall("glDisable GL_ALPHA_TEST");
467 /* Alpha test is disabled, don't bother setting the params - it will happen on the next
468 * enable call
469 */
470 return;
471 }
472
473 if (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE] && enable_ckey)
474 {
475 glParm = GL_NOTEQUAL;
476 ref = 0.0f;
477 } else {
478 ref = ((float)stateblock->state.render_states[WINED3DRS_ALPHAREF]) / 255.0f;
479 glParm = CompareFunc(stateblock->state.render_states[WINED3DRS_ALPHAFUNC]);
480 }
481 if(glParm) {
482 glAlphaFunc(glParm, ref);
483 checkGLcall("glAlphaFunc");
484 }
485 }
486
487 static void state_clipping(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
488 {
489 const struct wined3d_gl_info *gl_info = context->gl_info;
490 const struct wined3d_state *state = &stateblock->state;
491 DWORD enable = 0xFFFFFFFF;
492 DWORD disable = 0x00000000;
493
494 if (!stateblock->device->vs_clipping && use_vs(state))
495 {
496 /* The spec says that opengl clipping planes are disabled when using shaders. Direct3D planes aren't,
497 * so that is an issue. The MacOS ATI driver keeps clipping planes activated with shaders in some
498 * conditions I got sick of tracking down. The shader state handler disables all clip planes because
499 * of that - don't do anything here and keep them disabled
500 */
501 if (state->render_states[WINED3DRS_CLIPPLANEENABLE])
502 {
503 static BOOL warned = FALSE;
504 if(!warned) {
505 FIXME("Clipping not supported with vertex shaders\n");
506 warned = TRUE;
507 }
508 }
509 return;
510 }
511
512 /* TODO: Keep track of previously enabled clipplanes to avoid unnecessary resetting
513 * of already set values
514 */
515
516 /* If enabling / disabling all
517 * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
518 */
519 if (state->render_states[WINED3DRS_CLIPPING])
520 {
521 enable = state->render_states[WINED3DRS_CLIPPLANEENABLE];
522 disable = ~state->render_states[WINED3DRS_CLIPPLANEENABLE];
523 if (gl_info->supported[ARB_DEPTH_CLAMP])
524 {
525 glDisable(GL_DEPTH_CLAMP);
526 checkGLcall("glDisable(GL_DEPTH_CLAMP)");
527 }
528 } else {
529 disable = 0xffffffff;
530 enable = 0x00;
531 if (gl_info->supported[ARB_DEPTH_CLAMP])
532 {
533 glEnable(GL_DEPTH_CLAMP);
534 checkGLcall("glEnable(GL_DEPTH_CLAMP)");
535 }
536 else
537 {
538 FIXME("Clipping disabled, but ARB_depth_clamp isn't supported.\n");
539 }
540 }
541
542 if (enable & WINED3DCLIPPLANE0) { glEnable(GL_CLIP_PLANE0); checkGLcall("glEnable(clip plane 0)"); }
543 if (enable & WINED3DCLIPPLANE1) { glEnable(GL_CLIP_PLANE1); checkGLcall("glEnable(clip plane 1)"); }
544 if (enable & WINED3DCLIPPLANE2) { glEnable(GL_CLIP_PLANE2); checkGLcall("glEnable(clip plane 2)"); }
545 if (enable & WINED3DCLIPPLANE3) { glEnable(GL_CLIP_PLANE3); checkGLcall("glEnable(clip plane 3)"); }
546 if (enable & WINED3DCLIPPLANE4) { glEnable(GL_CLIP_PLANE4); checkGLcall("glEnable(clip plane 4)"); }
547 if (enable & WINED3DCLIPPLANE5) { glEnable(GL_CLIP_PLANE5); checkGLcall("glEnable(clip plane 5)"); }
548
549 if (disable & WINED3DCLIPPLANE0) { glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)"); }
550 if (disable & WINED3DCLIPPLANE1) { glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)"); }
551 if (disable & WINED3DCLIPPLANE2) { glDisable(GL_CLIP_PLANE2); checkGLcall("glDisable(clip plane 2)"); }
552 if (disable & WINED3DCLIPPLANE3) { glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)"); }
553 if (disable & WINED3DCLIPPLANE4) { glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)"); }
554 if (disable & WINED3DCLIPPLANE5) { glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)"); }
555
556 /** update clipping status */
557 if (enable)
558 {
559 stateblock->state.clip_status.ClipUnion = 0;
560 stateblock->state.clip_status.ClipIntersection = 0xFFFFFFFF;
561 }
562 else
563 {
564 stateblock->state.clip_status.ClipUnion = 0;
565 stateblock->state.clip_status.ClipIntersection = 0;
566 }
567 }
568
569 static void state_blendop_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
570 {
571 WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
572 }
573
574 static GLenum gl_blend_op(WINED3DBLENDOP op)
575 {
576 switch (op)
577 {
578 case WINED3DBLENDOP_ADD:
579 return GL_FUNC_ADD_EXT;
580 case WINED3DBLENDOP_SUBTRACT:
581 return GL_FUNC_SUBTRACT_EXT;
582 case WINED3DBLENDOP_REVSUBTRACT:
583 return GL_FUNC_REVERSE_SUBTRACT_EXT;
584 case WINED3DBLENDOP_MIN:
585 return GL_MIN_EXT;
586 case WINED3DBLENDOP_MAX:
587 return GL_MAX_EXT;
588 default:
589 FIXME("Unhandled blend op %#x.\n", op);
590 return GL_NONE;
591 }
592 }
593
594 static void state_blendop(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
595 {
596 const struct wined3d_gl_info *gl_info = context->gl_info;
597 int blendEquation = GL_FUNC_ADD_EXT;
598 int blendEquationAlpha = GL_FUNC_ADD_EXT;
599
600 /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */
601 if (stateblock->state.render_states[WINED3DRS_BLENDOPALPHA]
602 && !gl_info->supported[EXT_BLEND_EQUATION_SEPARATE])
603 {
604 WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparateEXT\n");
605 return;
606 }
607
608 blendEquation = gl_blend_op(stateblock->state.render_states[WINED3DRS_BLENDOP]);
609 blendEquationAlpha = gl_blend_op(stateblock->state.render_states[WINED3DRS_BLENDOPALPHA]);
610
611 if (stateblock->state.render_states[WINED3DRS_SEPARATEALPHABLENDENABLE])
612 {
613 TRACE("glBlendEquationSeparateEXT(%x, %x)\n", blendEquation, blendEquationAlpha);
614 GL_EXTCALL(glBlendEquationSeparateEXT(blendEquation, blendEquationAlpha));
615 checkGLcall("glBlendEquationSeparateEXT");
616 } else {
617 TRACE("glBlendEquation(%x)\n", blendEquation);
618 GL_EXTCALL(glBlendEquationEXT(blendEquation));
619 checkGLcall("glBlendEquation");
620 }
621 }
622
623 static void state_specularenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
624 {
625 const struct wined3d_gl_info *gl_info = context->gl_info;
626 /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
627 * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
628 * specular color. This is wrong:
629 * Separate specular color means the specular colour is maintained separately, whereas
630 * single color means it is merged in. However in both cases they are being used to
631 * some extent.
632 * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
633 * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
634 * running 1.4 yet!
635 *
636 *
637 * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
638 * Instead, we need to setup the FinalCombiner properly.
639 *
640 * The default setup for the FinalCombiner is:
641 *
642 * <variable> <input> <mapping> <usage>
643 * GL_VARIABLE_A_NV GL_FOG, GL_UNSIGNED_IDENTITY_NV GL_ALPHA
644 * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV GL_UNSIGNED_IDENTITY_NV GL_RGB
645 * GL_VARIABLE_C_NV GL_FOG GL_UNSIGNED_IDENTITY_NV GL_RGB
646 * GL_VARIABLE_D_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
647 * GL_VARIABLE_E_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
648 * GL_VARIABLE_F_NV GL_ZERO GL_UNSIGNED_IDENTITY_NV GL_RGB
649 * GL_VARIABLE_G_NV GL_SPARE0_NV GL_UNSIGNED_IDENTITY_NV GL_ALPHA
650 *
651 * That's pretty much fine as it is, except for variable B, which needs to take
652 * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
653 * whether WINED3DRS_SPECULARENABLE is enabled or not.
654 */
655
656 TRACE("Setting specular enable state and materials\n");
657 if (stateblock->state.render_states[WINED3DRS_SPECULARENABLE])
658 {
659 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&stateblock->state.material.Specular);
660 checkGLcall("glMaterialfv");
661
662 if (stateblock->state.material.Power > gl_info->limits.shininess)
663 {
664 /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0
665 * and 128.0, although in d3d neither -1 nor 129 produce an error. GL_NV_max_light_exponent
666 * allows bigger values. If the extension is supported, gl_info->limits.shininess contains the
667 * value reported by the extension, otherwise 128. For values > gl_info->limits.shininess clamp
668 * them, it should be safe to do so without major visual distortions.
669 */
670 WARN("Material power = %f, limit %f\n", stateblock->state.material.Power, gl_info->limits.shininess);
671 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, gl_info->limits.shininess);
672 }
673 else
674 {
675 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, stateblock->state.material.Power);
676 }
677 checkGLcall("glMaterialf(GL_SHININESS)");
678
679 if (gl_info->supported[EXT_SECONDARY_COLOR])
680 {
681 glEnable(GL_COLOR_SUM_EXT);
682 }
683 else
684 {
685 TRACE("Specular colors cannot be enabled in this version of opengl\n");
686 }
687 checkGLcall("glEnable(GL_COLOR_SUM)");
688
689 if (gl_info->supported[NV_REGISTER_COMBINERS])
690 {
691 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
692 checkGLcall("glFinalCombinerInputNV()");
693 }
694 } else {
695 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
696
697 /* for the case of enabled lighting: */
698 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
699 checkGLcall("glMaterialfv");
700
701 /* for the case of disabled lighting: */
702 if (gl_info->supported[EXT_SECONDARY_COLOR])
703 {
704 glDisable(GL_COLOR_SUM_EXT);
705 }
706 else
707 {
708 TRACE("Specular colors cannot be disabled in this version of opengl\n");
709 }
710 checkGLcall("glDisable(GL_COLOR_SUM)");
711
712 if (gl_info->supported[NV_REGISTER_COMBINERS])
713 {
714 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
715 checkGLcall("glFinalCombinerInputNV()");
716 }
717 }
718
719 TRACE("(%p) : Diffuse {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
720 stateblock->state.material.Diffuse.r, stateblock->state.material.Diffuse.g,
721 stateblock->state.material.Diffuse.b, stateblock->state.material.Diffuse.a);
722 TRACE("(%p) : Ambient {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
723 stateblock->state.material.Ambient.r, stateblock->state.material.Ambient.g,
724 stateblock->state.material.Ambient.b, stateblock->state.material.Ambient.a);
725 TRACE("(%p) : Specular {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
726 stateblock->state.material.Specular.r, stateblock->state.material.Specular.g,
727 stateblock->state.material.Specular.b, stateblock->state.material.Specular.a);
728 TRACE("(%p) : Emissive {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
729 stateblock->state.material.Emissive.r, stateblock->state.material.Emissive.g,
730 stateblock->state.material.Emissive.b, stateblock->state.material.Emissive.a);
731
732 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&stateblock->state.material.Ambient);
733 checkGLcall("glMaterialfv(GL_AMBIENT)");
734 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&stateblock->state.material.Diffuse);
735 checkGLcall("glMaterialfv(GL_DIFFUSE)");
736 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&stateblock->state.material.Emissive);
737 checkGLcall("glMaterialfv(GL_EMISSION)");
738 }
739
740 static void state_texfactor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
741 {
742 const struct wined3d_gl_info *gl_info = context->gl_info;
743 unsigned int i;
744
745 /* Note the texture color applies to all textures whereas
746 * GL_TEXTURE_ENV_COLOR applies to active only
747 */
748 float col[4];
749 D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_TEXTUREFACTOR], col);
750
751 /* And now the default texture color as well */
752 for (i = 0; i < gl_info->limits.texture_stages; ++i)
753 {
754 /* Note the WINED3DRS value applies to all textures, but GL has one
755 * per texture, so apply it now ready to be used!
756 */
757 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
758 checkGLcall("glActiveTextureARB");
759
760 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
761 checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
762 }
763 }
764
765 static void renderstate_stencil_twosided(struct wined3d_context *context, GLint face,
766 GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass)
767 {
768 const struct wined3d_gl_info *gl_info = context->gl_info;
769
770 glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
771 checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
772 GL_EXTCALL(glActiveStencilFaceEXT(face));
773 checkGLcall("glActiveStencilFaceEXT(...)");
774 glStencilFunc(func, ref, mask);
775 checkGLcall("glStencilFunc(...)");
776 glStencilOp(stencilFail, depthFail, stencilPass);
777 checkGLcall("glStencilOp(...)");
778 }
779
780 static void state_stencil(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
781 {
782 const struct wined3d_gl_info *gl_info = context->gl_info;
783 DWORD onesided_enable = FALSE;
784 DWORD twosided_enable = FALSE;
785 GLint func = GL_ALWAYS;
786 GLint func_ccw = GL_ALWAYS;
787 GLint ref = 0;
788 GLuint mask = 0;
789 GLint stencilFail = GL_KEEP;
790 GLint depthFail = GL_KEEP;
791 GLint stencilPass = GL_KEEP;
792 GLint stencilFail_ccw = GL_KEEP;
793 GLint depthFail_ccw = GL_KEEP;
794 GLint stencilPass_ccw = GL_KEEP;
795
796 /* No stencil test without a stencil buffer. */
797 if (!stateblock->device->fb.depth_stencil)
798 {
799 glDisable(GL_STENCIL_TEST);
800 checkGLcall("glDisable GL_STENCIL_TEST");
801 return;
802 }
803
804 onesided_enable = stateblock->state.render_states[WINED3DRS_STENCILENABLE];
805 twosided_enable = stateblock->state.render_states[WINED3DRS_TWOSIDEDSTENCILMODE];
806 if (!(func = CompareFunc(stateblock->state.render_states[WINED3DRS_STENCILFUNC])))
807 func = GL_ALWAYS;
808 if (!(func_ccw = CompareFunc(stateblock->state.render_states[WINED3DRS_CCW_STENCILFUNC])))
809 func_ccw = GL_ALWAYS;
810 ref = stateblock->state.render_states[WINED3DRS_STENCILREF];
811 mask = stateblock->state.render_states[WINED3DRS_STENCILMASK];
812 stencilFail = StencilOp(stateblock->state.render_states[WINED3DRS_STENCILFAIL]);
813 depthFail = StencilOp(stateblock->state.render_states[WINED3DRS_STENCILZFAIL]);
814 stencilPass = StencilOp(stateblock->state.render_states[WINED3DRS_STENCILPASS]);
815 stencilFail_ccw = StencilOp(stateblock->state.render_states[WINED3DRS_CCW_STENCILFAIL]);
816 depthFail_ccw = StencilOp(stateblock->state.render_states[WINED3DRS_CCW_STENCILZFAIL]);
817 stencilPass_ccw = StencilOp(stateblock->state.render_states[WINED3DRS_CCW_STENCILPASS]);
818
819 TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
820 "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
821 "GL_BACK: func: %x, fail %x, zfail %x, zpass %x )\n",
822 onesided_enable, twosided_enable, ref, mask,
823 func, stencilFail, depthFail, stencilPass,
824 func_ccw, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
825
826 if (twosided_enable && onesided_enable) {
827 glEnable(GL_STENCIL_TEST);
828 checkGLcall("glEnable GL_STENCIL_TEST");
829
830 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
831 {
832 /* Apply back first, then front. This function calls glActiveStencilFaceEXT,
833 * which has an effect on the code below too. If we apply the front face
834 * afterwards, we are sure that the active stencil face is set to front,
835 * and other stencil functions which do not use two sided stencil do not have
836 * to set it back
837 */
838 renderstate_stencil_twosided(context, GL_BACK,
839 func_ccw, ref, mask, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
840 renderstate_stencil_twosided(context, GL_FRONT,
841 func, ref, mask, stencilFail, depthFail, stencilPass);
842 }
843 else if (gl_info->supported[ATI_SEPARATE_STENCIL])
844 {
845 GL_EXTCALL(glStencilFuncSeparateATI(func, func_ccw, ref, mask));
846 checkGLcall("glStencilFuncSeparateATI(...)");
847 GL_EXTCALL(glStencilOpSeparateATI(GL_FRONT, stencilFail, depthFail, stencilPass));
848 checkGLcall("glStencilOpSeparateATI(GL_FRONT, ...)");
849 GL_EXTCALL(glStencilOpSeparateATI(GL_BACK, stencilFail_ccw, depthFail_ccw, stencilPass_ccw));
850 checkGLcall("glStencilOpSeparateATI(GL_BACK, ...)");
851 } else {
852 ERR("Separate (two sided) stencil not supported on this version of opengl. Caps weren't honored?\n");
853 }
854 }
855 else if(onesided_enable)
856 {
857 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
858 {
859 glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
860 checkGLcall("glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
861 }
862
863 /* This code disables the ATI extension as well, since the standard stencil functions are equal
864 * to calling the ATI functions with GL_FRONT_AND_BACK as face parameter
865 */
866 glEnable(GL_STENCIL_TEST);
867 checkGLcall("glEnable GL_STENCIL_TEST");
868 glStencilFunc(func, ref, mask);
869 checkGLcall("glStencilFunc(...)");
870 glStencilOp(stencilFail, depthFail, stencilPass);
871 checkGLcall("glStencilOp(...)");
872 } else {
873 glDisable(GL_STENCIL_TEST);
874 checkGLcall("glDisable GL_STENCIL_TEST");
875 }
876 }
877
878 static void state_stencilwrite2s(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
879 {
880 DWORD mask = stateblock->device->fb.depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0;
881 const struct wined3d_gl_info *gl_info = context->gl_info;
882
883 GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
884 checkGLcall("glActiveStencilFaceEXT(GL_BACK)");
885 glStencilMask(mask);
886 checkGLcall("glStencilMask");
887 GL_EXTCALL(glActiveStencilFaceEXT(GL_FRONT));
888 checkGLcall("glActiveStencilFaceEXT(GL_FRONT)");
889 glStencilMask(mask);
890 }
891
892 static void state_stencilwrite(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
893 {
894 DWORD mask = stateblock->device->fb.depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0;
895
896 glStencilMask(mask);
897 checkGLcall("glStencilMask");
898 }
899
900 static void state_fog_vertexpart(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
901 {
902
903 TRACE("state %#x, stateblock %p, context %p\n", state, stateblock, context);
904
905 if (!stateblock->state.render_states[WINED3DRS_FOGENABLE]) return;
906
907 /* Table fog on: Never use fog coords, and use per-fragment fog */
908 if (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE] != WINED3DFOG_NONE)
909 {
910 glHint(GL_FOG_HINT, GL_NICEST);
911 if(context->fog_coord) {
912 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
913 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
914 context->fog_coord = FALSE;
915 }
916 return;
917 }
918
919 /* Otherwise use per-vertex fog in any case */
920 glHint(GL_FOG_HINT, GL_FASTEST);
921
922 if (stateblock->state.render_states[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || context->last_was_rhw)
923 {
924 /* No fog at all, or transformed vertices: Use fog coord */
925 if(!context->fog_coord) {
926 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
927 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)");
928 context->fog_coord = TRUE;
929 }
930 } else {
931 /* Otherwise, use the fragment depth */
932 if(context->fog_coord) {
933 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
934 checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
935 context->fog_coord = FALSE;
936 }
937 }
938 }
939
940 void state_fogstartend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
941 {
942 float fogstart, fogend;
943 union {
944 DWORD d;
945 float f;
946 } tmpvalue;
947
948 switch(context->fog_source) {
949 case FOGSOURCE_VS:
950 fogstart = 1.0f;
951 fogend = 0.0f;
952 break;
953
954 case FOGSOURCE_COORD:
955 fogstart = 255.0f;
956 fogend = 0.0f;
957 break;
958
959 case FOGSOURCE_FFP:
960 tmpvalue.d = stateblock->state.render_states[WINED3DRS_FOGSTART];
961 fogstart = tmpvalue.f;
962 tmpvalue.d = stateblock->state.render_states[WINED3DRS_FOGEND];
963 fogend = tmpvalue.f;
964 /* In GL, fogstart == fogend disables fog, in D3D everything's fogged.*/
965 if(fogstart == fogend) {
966 fogstart = -1.0f / 0.0f;
967 fogend = 0.0f;
968 }
969 break;
970
971 default:
972 /* This should not happen.context->fog_source is set in wined3d, not the app.
973 * Still this is needed to make the compiler happy
974 */
975 ERR("Unexpected fog coordinate source\n");
976 fogstart = 0.0f;
977 fogend = 0.0f;
978 }
979
980 glFogf(GL_FOG_START, fogstart);
981 checkGLcall("glFogf(GL_FOG_START, fogstart)");
982 TRACE("Fog Start == %f\n", fogstart);
983
984 glFogf(GL_FOG_END, fogend);
985 checkGLcall("glFogf(GL_FOG_END, fogend)");
986 TRACE("Fog End == %f\n", fogend);
987 }
988
989 void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
990 {
991 const struct wined3d_state *state = &stateblock->state;
992 enum fogsource new_source;
993
994 TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context);
995
996 if (!state->render_states[WINED3DRS_FOGENABLE])
997 {
998 /* No fog? Disable it, and we're done :-) */
999 glDisableWINE(GL_FOG);
1000 checkGLcall("glDisable GL_FOG");
1001 return;
1002 }
1003
1004 /* Fog Rules:
1005 *
1006 * With fixed function vertex processing, Direct3D knows 2 different fog input sources.
1007 * It can use the Z value of the vertex, or the alpha component of the specular color.
1008 * This depends on the fog vertex, fog table and the vertex declaration. If the Z value
1009 * is used, fogstart, fogend and the equation type are used, otherwise linear fog with
1010 * start = 255, end = 0 is used. Obviously the msdn is not very clear on that.
1011 *
1012 * FOGTABLEMODE != NONE:
1013 * The Z value is used, with the equation specified, no matter what vertex type.
1014 *
1015 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, untransformed:
1016 * Per vertex fog is calculated using the specified fog equation and the parameters
1017 *
1018 * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, transformed, OR
1019 * FOGTABLEMODE == NONE, FOGVERTEXMODE == NONE, untransformed:
1020 * Linear fog with start = 255.0, end = 0.0, input comes from the specular color
1021 *
1022 *
1023 * Rules for vertex fog with shaders:
1024 *
1025 * When mixing fixed function functionality with the programmable pipeline, D3D expects
1026 * the fog computation to happen during transformation while openGL expects it to happen
1027 * during rasterization. Also, prior to pixel shader 3.0 D3D handles fog blending after
1028 * the pixel shader while openGL always expects the pixel shader to handle the blending.
1029 * To solve this problem, WineD3D does:
1030 * 1) implement a linear fog equation and fog blending at the end of every pre 3.0 pixel
1031 * shader,
1032 * and 2) disables the fog computation (in either the fixed function or programmable
1033 * rasterizer) if using a vertex program.
1034 *
1035 * D3D shaders can provide an explicit fog coordinate. This fog coordinate is used with
1036 * D3DRS_FOGTABLEMODE==D3DFOG_NONE. The FOGVERTEXMODE is ignored, d3d always uses linear
1037 * fog with start=1.0 and end=0.0 in this case. This is similar to fog coordinates in
1038 * the specular color, a vertex shader counts as pretransformed geometry in this case.
1039 * There are some GL differences between specular fog coords and vertex shaders though.
1040 *
1041 * With table fog the vertex shader fog coordinate is ignored.
1042 *
1043 * If a fogtablemode and a fogvertexmode are specified, table fog is applied (with or
1044 * without shaders).
1045 */
1046
1047 /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
1048 * the system will apply only pixel(=table) fog effects."
1049 */
1050 if (state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE)
1051 {
1052 if (use_vs(state))
1053 {
1054 glFogi(GL_FOG_MODE, GL_LINEAR);
1055 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1056 new_source = FOGSOURCE_VS;
1057 }
1058 else
1059 {
1060 switch (state->render_states[WINED3DRS_FOGVERTEXMODE])
1061 {
1062 /* If processed vertices are used, fall through to the NONE case */
1063 case WINED3DFOG_EXP:
1064 if(!context->last_was_rhw) {
1065 glFogi(GL_FOG_MODE, GL_EXP);
1066 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1067 new_source = FOGSOURCE_FFP;
1068 break;
1069 }
1070 /* drop through */
1071
1072 case WINED3DFOG_EXP2:
1073 if(!context->last_was_rhw) {
1074 glFogi(GL_FOG_MODE, GL_EXP2);
1075 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1076 new_source = FOGSOURCE_FFP;
1077 break;
1078 }
1079 /* drop through */
1080
1081 case WINED3DFOG_LINEAR:
1082 if(!context->last_was_rhw) {
1083 glFogi(GL_FOG_MODE, GL_LINEAR);
1084 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1085 new_source = FOGSOURCE_FFP;
1086 break;
1087 }
1088 /* drop through */
1089
1090 case WINED3DFOG_NONE:
1091 /* Both are none? According to msdn the alpha channel of the specular
1092 * color contains a fog factor. Set it in drawStridedSlow.
1093 * Same happens with Vertexfog on transformed vertices
1094 */
1095 new_source = FOGSOURCE_COORD;
1096 glFogi(GL_FOG_MODE, GL_LINEAR);
1097 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1098 break;
1099
1100 default:
1101 FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %#x.\n",
1102 state->render_states[WINED3DRS_FOGVERTEXMODE]);
1103 new_source = FOGSOURCE_FFP; /* Make the compiler happy */
1104 }
1105 }
1106 } else {
1107 new_source = FOGSOURCE_FFP;
1108
1109 switch (state->render_states[WINED3DRS_FOGTABLEMODE])
1110 {
1111 case WINED3DFOG_EXP:
1112 glFogi(GL_FOG_MODE, GL_EXP);
1113 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1114 break;
1115
1116 case WINED3DFOG_EXP2:
1117 glFogi(GL_FOG_MODE, GL_EXP2);
1118 checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1119 break;
1120
1121 case WINED3DFOG_LINEAR:
1122 glFogi(GL_FOG_MODE, GL_LINEAR);
1123 checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1124 break;
1125
1126 case WINED3DFOG_NONE: /* Won't happen */
1127 default:
1128 FIXME("Unexpected WINED3DRS_FOGTABLEMODE %#x.\n",
1129 state->render_states[WINED3DRS_FOGTABLEMODE]);
1130 }
1131 }
1132
1133 glEnableWINE(GL_FOG);
1134 checkGLcall("glEnable GL_FOG");
1135 if(new_source != context->fog_source) {
1136 context->fog_source = new_source;
1137 state_fogstartend(STATE_RENDER(WINED3DRS_FOGSTART), stateblock, context);
1138 }
1139 }
1140
1141 static void state_rangefog_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1142 {
1143 if (stateblock->state.render_states[WINED3DRS_RANGEFOGENABLE])
1144 WARN("Range fog enabled, but not supported by this opengl implementation\n");
1145 }
1146
1147 static void state_rangefog(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1148 {
1149 if (stateblock->state.render_states[WINED3DRS_RANGEFOGENABLE])
1150 {
1151 glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
1152 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)");
1153 } else {
1154 glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
1155 checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
1156 }
1157 }
1158
1159 void state_fogcolor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1160 {
1161 float col[4];
1162 D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_FOGCOLOR], col);
1163 glFogfv(GL_FOG_COLOR, &col[0]);
1164 checkGLcall("glFog GL_FOG_COLOR");
1165 }
1166
1167 void state_fogdensity(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1168 {
1169 union {
1170 DWORD d;
1171 float f;
1172 } tmpvalue;
1173 tmpvalue.d = stateblock->state.render_states[WINED3DRS_FOGDENSITY];
1174 glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
1175 checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
1176 }
1177
1178 static void state_colormat(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1179 {
1180 const struct wined3d_state *state = &stateblock->state;
1181 struct wined3d_device *device = stateblock->device;
1182 GLenum Parm = 0;
1183
1184 /* Depends on the decoded vertex declaration to read the existence of diffuse data.
1185 * The vertex declaration will call this function if the fixed function pipeline is used.
1186 */
1187
1188 if(isStateDirty(context, STATE_VDECL)) {
1189 return;
1190 }
1191
1192 context->num_untracked_materials = 0;
1193 if ((device->strided_streams.use_map & (1 << WINED3D_FFP_DIFFUSE))
1194 && state->render_states[WINED3DRS_COLORVERTEX])
1195 {
1196 TRACE("diff %d, amb %d, emis %d, spec %d\n",
1197 state->render_states[WINED3DRS_DIFFUSEMATERIALSOURCE],
1198 state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE],
1199 state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE],
1200 state->render_states[WINED3DRS_SPECULARMATERIALSOURCE]);
1201
1202 if (state->render_states[WINED3DRS_DIFFUSEMATERIALSOURCE] == WINED3DMCS_COLOR1)
1203 {
1204 if (state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1)
1205 Parm = GL_AMBIENT_AND_DIFFUSE;
1206 else
1207 Parm = GL_DIFFUSE;
1208 if (state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1)
1209 {
1210 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1211 context->num_untracked_materials++;
1212 }
1213 if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1)
1214 {
1215 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1216 context->num_untracked_materials++;
1217 }
1218 }
1219 else if (state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1)
1220 {
1221 Parm = GL_AMBIENT;
1222 if (state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1)
1223 {
1224 context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
1225 context->num_untracked_materials++;
1226 }
1227 if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1)
1228 {
1229 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1230 context->num_untracked_materials++;
1231 }
1232 }
1233 else if (state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1)
1234 {
1235 Parm = GL_EMISSION;
1236 if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1)
1237 {
1238 context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
1239 context->num_untracked_materials++;
1240 }
1241 }
1242 else if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1)
1243 {
1244 Parm = GL_SPECULAR;
1245 }
1246 }
1247
1248 /* Nothing changed, return. */
1249 if (Parm == context->tracking_parm) return;
1250
1251 if(!Parm) {
1252 glDisable(GL_COLOR_MATERIAL);
1253 checkGLcall("glDisable GL_COLOR_MATERIAL");
1254 } else {
1255 glColorMaterial(GL_FRONT_AND_BACK, Parm);
1256 checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
1257 glEnable(GL_COLOR_MATERIAL);
1258 checkGLcall("glEnable(GL_COLOR_MATERIAL)");
1259 }
1260
1261 /* Apparently calls to glMaterialfv are ignored for properties we're
1262 * tracking with glColorMaterial, so apply those here. */
1263 switch (context->tracking_parm) {
1264 case GL_AMBIENT_AND_DIFFUSE:
1265 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.Ambient);
1266 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.Diffuse);
1267 checkGLcall("glMaterialfv");
1268 break;
1269
1270 case GL_DIFFUSE:
1271 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.Diffuse);
1272 checkGLcall("glMaterialfv");
1273 break;
1274
1275 case GL_AMBIENT:
1276 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.Ambient);
1277 checkGLcall("glMaterialfv");
1278 break;
1279
1280 case GL_EMISSION:
1281 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.Emissive);
1282 checkGLcall("glMaterialfv");
1283 break;
1284
1285 case GL_SPECULAR:
1286 /* Only change material color if specular is enabled, otherwise it is set to black */
1287 if (state->render_states[WINED3DRS_SPECULARENABLE])
1288 {
1289 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.Specular);
1290 checkGLcall("glMaterialfv");
1291 } else {
1292 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
1293 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
1294 checkGLcall("glMaterialfv");
1295 }
1296 break;
1297 }
1298
1299 context->tracking_parm = Parm;
1300 }
1301
1302 static void state_linepattern(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1303 {
1304 union {
1305 DWORD d;
1306 WINED3DLINEPATTERN lp;
1307 } tmppattern;
1308 tmppattern.d = stateblock->state.render_states[WINED3DRS_LINEPATTERN];
1309
1310 TRACE("Line pattern: repeat %d bits %x\n", tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
1311
1312 if (tmppattern.lp.wRepeatFactor) {
1313 glLineStipple(tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
1314 checkGLcall("glLineStipple(repeat, linepattern)");
1315 glEnable(GL_LINE_STIPPLE);
1316 checkGLcall("glEnable(GL_LINE_STIPPLE);");
1317 } else {
1318 glDisable(GL_LINE_STIPPLE);
1319 checkGLcall("glDisable(GL_LINE_STIPPLE);");
1320 }
1321 }
1322
1323 static void state_normalize(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1324 {
1325 if(isStateDirty(context, STATE_VDECL)) {
1326 return;
1327 }
1328 /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor
1329 * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division
1330 * by zero and is not properly defined in opengl, so avoid it
1331 */
1332 if (stateblock->state.render_states[WINED3DRS_NORMALIZENORMALS]
1333 && (stateblock->device->strided_streams.use_map & (1 << WINED3D_FFP_NORMAL)))
1334 {
1335 glEnable(GL_NORMALIZE);
1336 checkGLcall("glEnable(GL_NORMALIZE);");
1337 } else {
1338 glDisable(GL_NORMALIZE);
1339 checkGLcall("glDisable(GL_NORMALIZE);");
1340 }
1341 }
1342
1343 static void state_psizemin_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1344 {
1345 union {
1346 DWORD d;
1347 float f;
1348 } tmpvalue;
1349
1350 tmpvalue.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MIN];
1351 if (tmpvalue.f != 1.0f)
1352 {
1353 FIXME("WINED3DRS_POINTSIZE_MIN not supported on this opengl, value is %f\n", tmpvalue.f);
1354 }
1355 tmpvalue.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MAX];
1356 if (tmpvalue.f != 64.0f)
1357 {
1358 FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f);
1359 }
1360
1361 }
1362
1363 static void state_psizemin_ext(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1364 {
1365 const struct wined3d_gl_info *gl_info = context->gl_info;
1366 union
1367 {
1368 DWORD d;
1369 float f;
1370 } min, max;
1371
1372 min.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MIN];
1373 max.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MAX];
1374
1375 /* Max point size trumps min point size */
1376 if(min.f > max.f) {
1377 min.f = max.f;
1378 }
1379
1380 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, min.f);
1381 checkGLcall("glPointParameterfEXT(...)");
1382 GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, max.f);
1383 checkGLcall("glPointParameterfEXT(...)");
1384 }
1385
1386 static void state_psizemin_arb(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1387 {
1388 const struct wined3d_gl_info *gl_info = context->gl_info;
1389 union
1390 {
1391 DWORD d;
1392 float f;
1393 } min, max;
1394
1395 min.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MIN];
1396 max.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MAX];
1397
1398 /* Max point size trumps min point size */
1399 if(min.f > max.f) {
1400 min.f = max.f;
1401 }
1402
1403 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, min.f);
1404 checkGLcall("glPointParameterfARB(...)");
1405 GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, max.f);
1406 checkGLcall("glPointParameterfARB(...)");
1407 }
1408
1409 static void state_pscale(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1410 {
1411 const struct wined3d_gl_info *gl_info = context->gl_info;
1412 /* TODO: Group this with the viewport */
1413 /*
1414 * POINTSCALEENABLE controls how point size value is treated. If set to
1415 * true, the point size is scaled with respect to height of viewport.
1416 * When set to false point size is in pixels.
1417 */
1418
1419 /* Default values */
1420 GLfloat att[3] = {1.0f, 0.0f, 0.0f};
1421 union {
1422 DWORD d;
1423 float f;
1424 } pointSize, A, B, C;
1425
1426 pointSize.d = stateblock->state.render_states[WINED3DRS_POINTSIZE];
1427 A.d = stateblock->state.render_states[WINED3DRS_POINTSCALE_A];
1428 B.d = stateblock->state.render_states[WINED3DRS_POINTSCALE_B];
1429 C.d = stateblock->state.render_states[WINED3DRS_POINTSCALE_C];
1430
1431 if (stateblock->state.render_states[WINED3DRS_POINTSCALEENABLE])
1432 {
1433 GLfloat scaleFactor;
1434 DWORD h = stateblock->state.viewport.Height;
1435
1436 if (pointSize.f < gl_info->limits.pointsize_min)
1437 {
1438 /* Minimum valid point size for OpenGL is driver specific. For Direct3D it is
1439 * 0.0f. This means that OpenGL will clamp really small point sizes to the
1440 * driver minimum. To correct for this we need to multiply by the scale factor when sizes
1441 * are less than 1.0f. scale_factor = 1.0f / point_size.
1442 */
1443 scaleFactor = pointSize.f / gl_info->limits.pointsize_min;
1444 /* Clamp the point size, don't rely on the driver to do it. MacOS says min point size
1445 * is 1.0, but then accepts points below that and draws too small points
1446 */
1447 pointSize.f = gl_info->limits.pointsize_min;
1448 }
1449 else if(pointSize.f > gl_info->limits.pointsize_max)
1450 {
1451 /* gl already scales the input to glPointSize,
1452 * d3d scales the result after the point size scale.
1453 * If the point size is bigger than the max size, use the
1454 * scaling to scale it bigger, and set the gl point size to max
1455 */
1456 scaleFactor = pointSize.f / gl_info->limits.pointsize_max;
1457 TRACE("scale: %f\n", scaleFactor);
1458 pointSize.f = gl_info->limits.pointsize_max;
1459 } else {
1460 scaleFactor = 1.0f;
1461 }
1462 scaleFactor = powf(h * scaleFactor, 2);
1463
1464 att[0] = A.f / scaleFactor;
1465 att[1] = B.f / scaleFactor;
1466 att[2] = C.f / scaleFactor;
1467 }
1468
1469 if (gl_info->supported[ARB_POINT_PARAMETERS])
1470 {
1471 GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
1472 checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...)");
1473 }
1474 else if (gl_info->supported[EXT_POINT_PARAMETERS])
1475 {
1476 GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
1477 checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)");
1478 }
1479 else if(stateblock->state.render_states[WINED3DRS_POINTSCALEENABLE])
1480 {
1481 WARN("POINT_PARAMETERS not supported in this version of opengl\n");
1482 }
1483
1484 glPointSize(pointSize.f);
1485 checkGLcall("glPointSize(...);");
1486 }
1487
1488 static void state_debug_monitor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1489 {
1490 WARN("token: %#x\n", stateblock->state.render_states[WINED3DRS_DEBUGMONITORTOKEN]);
1491 }
1492
1493 static void state_colorwrite(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1494 {
1495 DWORD mask0 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE];
1496 DWORD mask1 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE1];
1497 DWORD mask2 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE2];
1498 DWORD mask3 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE3];
1499
1500 TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
1501 mask0 & WINED3DCOLORWRITEENABLE_RED ? 1 : 0,
1502 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? 1 : 0,
1503 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? 1 : 0,
1504 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1505 glColorMask(mask0 & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1506 mask0 & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1507 mask0 & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1508 mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1509 checkGLcall("glColorMask(...)");
1510
1511 if (!((mask1 == mask0 && mask2 == mask0 && mask3 == mask0)
1512 || (mask1 == 0xf && mask2 == 0xf && mask3 == 0xf)))
1513 {
1514 FIXME("WINED3DRS_COLORWRITEENABLE/1/2/3, %#x/%#x/%#x/%#x not yet implemented.\n",
1515 mask0, mask1, mask2, mask3);
1516 FIXME("Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n");
1517 }
1518 }
1519
1520 static void set_color_mask(const struct wined3d_gl_info *gl_info, UINT index, DWORD mask)
1521 {
1522 GL_EXTCALL(glColorMaskIndexedEXT(index,
1523 mask & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1524 mask & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
1525 mask & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
1526 mask & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE));
1527 }
1528
1529 static void state_colorwrite0(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1530 {
1531 set_color_mask(context->gl_info, 0, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE]);
1532 }
1533
1534 static void state_colorwrite1(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1535 {
1536 set_color_mask(context->gl_info, 1, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE1]);
1537 }
1538
1539 static void state_colorwrite2(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1540 {
1541 set_color_mask(context->gl_info, 2, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE2]);
1542 }
1543
1544 static void state_colorwrite3(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1545 {
1546 set_color_mask(context->gl_info, 3, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE3]);
1547 }
1548
1549 static void state_localviewer(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1550 {
1551 if (stateblock->state.render_states[WINED3DRS_LOCALVIEWER])
1552 {
1553 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1554 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1555 } else {
1556 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1557 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
1558 }
1559 }
1560
1561 static void state_lastpixel(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1562 {
1563 if (stateblock->state.render_states[WINED3DRS_LASTPIXEL])
1564 {
1565 TRACE("Last Pixel Drawing Enabled\n");
1566 } else {
1567 static BOOL warned;
1568 if (!warned) {
1569 FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1570 warned = TRUE;
1571 } else {
1572 TRACE("Last Pixel Drawing Disabled, not handled yet\n");
1573 }
1574 }
1575 }
1576
1577 static void state_pointsprite_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1578 {
1579 static BOOL warned;
1580
1581 /* TODO: NV_POINT_SPRITE */
1582 if (!warned && stateblock->state.render_states[WINED3DRS_POINTSPRITEENABLE])
1583 {
1584 /* A FIXME, not a WARN because point sprites should be software emulated if not supported by HW */
1585 FIXME("Point sprites not supported\n");
1586 warned = TRUE;
1587 }
1588 }
1589
1590 static void state_pointsprite(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1591 {
1592 const struct wined3d_gl_info *gl_info = context->gl_info;
1593 const struct wined3d_state *state = &stateblock->state;
1594
1595 if (state->render_states[WINED3DRS_POINTSPRITEENABLE])
1596 {
1597 static BOOL warned;
1598
1599 if (gl_info->limits.point_sprite_units < gl_info->limits.textures && !warned)
1600 {
1601 if (use_ps(state) || state->lowest_disabled_stage > gl_info->limits.point_sprite_units)
1602 {
1603 FIXME("The app uses point sprite texture coordinates on more units than supported by the driver\n");
1604 warned = TRUE;
1605 }
1606 }
1607
1608 glEnable(GL_POINT_SPRITE_ARB);
1609 checkGLcall("glEnable(GL_POINT_SPRITE_ARB)");
1610 } else {
1611 glDisable(GL_POINT_SPRITE_ARB);
1612 checkGLcall("glDisable(GL_POINT_SPRITE_ARB)");
1613 }
1614 }
1615
1616 static void state_wrap(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1617 {
1618 /**
1619 http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/texture/
1620 http://www.gamedev.net/reference/programming/features/rendererdll3/page2.asp
1621 Discussion on the ways to turn on WRAPing to solve an OpenGL conversion problem.
1622 http://www.flipcode.org/cgi-bin/fcmsg.cgi?thread_show=10248
1623
1624 so far as I can tell, wrapping and texture-coordinate generate go hand in hand,
1625 */
1626 if (stateblock->state.render_states[WINED3DRS_WRAP0]
1627 || stateblock->state.render_states[WINED3DRS_WRAP1]
1628 || stateblock->state.render_states[WINED3DRS_WRAP2]
1629 || stateblock->state.render_states[WINED3DRS_WRAP3]
1630 || stateblock->state.render_states[WINED3DRS_WRAP4]
1631 || stateblock->state.render_states[WINED3DRS_WRAP5]
1632 || stateblock->state.render_states[WINED3DRS_WRAP6]
1633 || stateblock->state.render_states[WINED3DRS_WRAP7]
1634 || stateblock->state.render_states[WINED3DRS_WRAP8]
1635 || stateblock->state.render_states[WINED3DRS_WRAP9]
1636 || stateblock->state.render_states[WINED3DRS_WRAP10]
1637 || stateblock->state.render_states[WINED3DRS_WRAP11]
1638 || stateblock->state.render_states[WINED3DRS_WRAP12]
1639 || stateblock->state.render_states[WINED3DRS_WRAP13]
1640 || stateblock->state.render_states[WINED3DRS_WRAP14]
1641 || stateblock->state.render_states[WINED3DRS_WRAP15])
1642 {
1643 FIXME("(WINED3DRS_WRAP0) Texture wrapping not yet supported.\n");
1644 }
1645 }
1646
1647 static void state_msaa_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1648 {
1649 if (stateblock->state.render_states[WINED3DRS_MULTISAMPLEANTIALIAS])
1650 WARN("Multisample antialiasing not supported by gl\n");
1651 }
1652
1653 static void state_msaa(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1654 {
1655 if (stateblock->state.render_states[WINED3DRS_MULTISAMPLEANTIALIAS])
1656 {
1657 glEnable(GL_MULTISAMPLE_ARB);
1658 checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1659 } else {
1660 glDisable(GL_MULTISAMPLE_ARB);
1661 checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1662 }
1663 }
1664
1665 static void state_scissor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1666 {
1667 if (stateblock->state.render_states[WINED3DRS_SCISSORTESTENABLE])
1668 {
1669 glEnable(GL_SCISSOR_TEST);
1670 checkGLcall("glEnable(GL_SCISSOR_TEST)");
1671 } else {
1672 glDisable(GL_SCISSOR_TEST);
1673 checkGLcall("glDisable(GL_SCISSOR_TEST)");
1674 }
1675 }
1676
1677 /* The Direct3D depth bias is specified in normalized depth coordinates. In
1678 * OpenGL the bias is specified in units of "the smallest value that is
1679 * guaranteed to produce a resolvable offset for a given implementation". To
1680 * convert from D3D to GL we need to divide the D3D depth bias by that value.
1681 * There's no practical way to retrieve that value from a given GL
1682 * implementation, but the D3D application has essentially the same problem,
1683 * which makes a guess of the depth buffer format's highest possible value a
1684 * reasonable guess. Note that SLOPESCALEDEPTHBIAS is a scaling factor for the
1685 * depth slope, and doesn't need to be scaled. */
1686 static void state_depthbias(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1687 {
1688 if (stateblock->state.render_states[WINED3DRS_SLOPESCALEDEPTHBIAS]
1689 || stateblock->state.render_states[WINED3DRS_DEPTHBIAS])
1690 {
1691 struct wined3d_surface *depth = stateblock->device->fb.depth_stencil;
1692 float scale;
1693
1694 union
1695 {
1696 DWORD d;
1697 float f;
1698 } scale_bias, const_bias;
1699
1700 scale_bias.d = stateblock->state.render_states[WINED3DRS_SLOPESCALEDEPTHBIAS];
1701 const_bias.d = stateblock->state.render_states[WINED3DRS_DEPTHBIAS];
1702
1703 glEnable(GL_POLYGON_OFFSET_FILL);
1704 checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
1705
1706 if (depth)
1707 {
1708 const struct wined3d_format *fmt = depth->resource.format;
1709 scale = powf(2, fmt->depth_size) - 1;
1710 TRACE("Depth format %s, using depthbias scale of %f\n",
1711 debug_d3dformat(fmt->id), scale);
1712 }
1713 else
1714 {
1715 /* The context manager will reapply this state on a depth stencil change */
1716 TRACE("No depth stencil, using depthbias scale of 0.0\n");
1717 scale = 0;
1718 }
1719
1720 glPolygonOffset(scale_bias.f, const_bias.f * scale);
1721 checkGLcall("glPolygonOffset(...)");
1722 } else {
1723 glDisable(GL_POLYGON_OFFSET_FILL);
1724 checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
1725 }
1726 }
1727
1728 static void state_zvisible(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1729 {
1730 if (stateblock->state.render_states[WINED3DRS_ZVISIBLE])
1731 FIXME("WINED3DRS_ZVISIBLE not implemented.\n");
1732 }
1733
1734 static void state_perspective(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1735 {
1736 if (stateblock->state.render_states[WINED3DRS_TEXTUREPERSPECTIVE])
1737 {
1738 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1739 checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)");
1740 } else {
1741 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1742 checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)");
1743 }
1744 }
1745
1746 static void state_stippledalpha(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1747 {
1748 if (stateblock->state.render_states[WINED3DRS_STIPPLEDALPHA])
1749 FIXME(" Stippled Alpha not supported yet.\n");
1750 }
1751
1752 static void state_antialias(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1753 {
1754 if (stateblock->state.render_states[WINED3DRS_ANTIALIAS])
1755 FIXME("Antialias not supported yet.\n");
1756 }
1757
1758 static void state_multisampmask(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1759 {
1760 if (stateblock->state.render_states[WINED3DRS_MULTISAMPLEMASK] != 0xffffffff)
1761 FIXME("WINED3DRS_MULTISAMPLEMASK %#x not yet implemented.\n",
1762 stateblock->state.render_states[WINED3DRS_MULTISAMPLEMASK]);
1763 }
1764
1765 static void state_patchedgestyle(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1766 {
1767 if (stateblock->state.render_states[WINED3DRS_PATCHEDGESTYLE] != WINED3DPATCHEDGE_DISCRETE)
1768 FIXME("WINED3DRS_PATCHEDGESTYLE %#x not yet implemented.\n",
1769 stateblock->state.render_states[WINED3DRS_PATCHEDGESTYLE]);
1770 }
1771
1772 static void state_patchsegments(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1773 {
1774 union {
1775 DWORD d;
1776 float f;
1777 } tmpvalue;
1778 tmpvalue.f = 1.0f;
1779
1780 if (stateblock->state.render_states[WINED3DRS_PATCHSEGMENTS] != tmpvalue.d)
1781 {
1782 static BOOL displayed = FALSE;
1783
1784 tmpvalue.d = stateblock->state.render_states[WINED3DRS_PATCHSEGMENTS];
1785 if(!displayed)
1786 FIXME("(WINED3DRS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f);
1787
1788 displayed = TRUE;
1789 }
1790 }
1791
1792 static void state_positiondegree(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1793 {
1794 if (stateblock->state.render_states[WINED3DRS_POSITIONDEGREE] != WINED3DDEGREE_CUBIC)
1795 FIXME("WINED3DRS_POSITIONDEGREE %#x not yet implemented.\n",
1796 stateblock->state.render_states[WINED3DRS_POSITIONDEGREE]);
1797 }
1798
1799 static void state_normaldegree(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1800 {
1801 if (stateblock->state.render_states[WINED3DRS_NORMALDEGREE] != WINED3DDEGREE_LINEAR)
1802 FIXME("WINED3DRS_NORMALDEGREE %#x not yet implemented.\n",
1803 stateblock->state.render_states[WINED3DRS_NORMALDEGREE]);
1804 }
1805
1806 static void state_tessellation(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1807 {
1808 if (stateblock->state.render_states[WINED3DRS_ENABLEADAPTIVETESSELLATION])
1809 FIXME("WINED3DRS_ENABLEADAPTIVETESSELLATION %#x not yet implemented.\n",
1810 stateblock->state.render_states[WINED3DRS_ENABLEADAPTIVETESSELLATION]);
1811 }
1812
1813 static void state_nvdb(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1814 {
1815 union {
1816 DWORD d;
1817 float f;
1818 } zmin, zmax;
1819
1820 const struct wined3d_gl_info *gl_info = context->gl_info;
1821
1822 if (stateblock->state.render_states[WINED3DRS_ADAPTIVETESS_X] == WINED3DFMT_NVDB)
1823 {
1824 zmin.d = stateblock->state.render_states[WINED3DRS_ADAPTIVETESS_Z];
1825 zmax.d = stateblock->state.render_states[WINED3DRS_ADAPTIVETESS_W];
1826
1827 /* If zmin is larger than zmax INVALID_VALUE error is generated.
1828 * In d3d9 test is not performed in this case*/
1829 if (zmin.f <= zmax.f)
1830 {
1831 glEnable(GL_DEPTH_BOUNDS_TEST_EXT);
1832 checkGLcall("glEnable(GL_DEPTH_BOUNDS_TEST_EXT)");
1833 GL_EXTCALL(glDepthBoundsEXT(zmin.f, zmax.f));
1834 checkGLcall("glDepthBoundsEXT(...)");
1835 }
1836 else {
1837 glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1838 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1839 }
1840 }
1841 else {
1842 glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1843 checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
1844 }
1845
1846 state_tessellation(state, stateblock, context);
1847 }
1848
1849 static void state_wrapu(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1850 {
1851 if (stateblock->state.render_states[WINED3DRS_WRAPU])
1852 FIXME("Render state WINED3DRS_WRAPU not implemented yet.\n");
1853 }
1854
1855 static void state_wrapv(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1856 {
1857 if (stateblock->state.render_states[WINED3DRS_WRAPV])
1858 FIXME("Render state WINED3DRS_WRAPV not implemented yet.\n");
1859 }
1860
1861 static void state_monoenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1862 {
1863 if (stateblock->state.render_states[WINED3DRS_MONOENABLE])
1864 FIXME("Render state WINED3DRS_MONOENABLE not implemented yet.\n");
1865 }
1866
1867 static void state_rop2(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1868 {
1869 if (stateblock->state.render_states[WINED3DRS_ROP2])
1870 FIXME("Render state WINED3DRS_ROP2 not implemented yet.\n");
1871 }
1872
1873 static void state_planemask(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1874 {
1875 if (stateblock->state.render_states[WINED3DRS_PLANEMASK])
1876 FIXME("Render state WINED3DRS_PLANEMASK not implemented yet.\n");
1877 }
1878
1879 static void state_subpixel(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1880 {
1881 if (stateblock->state.render_states[WINED3DRS_SUBPIXEL])
1882 FIXME("Render state WINED3DRS_SUBPIXEL not implemented yet.\n");
1883 }
1884
1885 static void state_subpixelx(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1886 {
1887 if (stateblock->state.render_states[WINED3DRS_SUBPIXELX])
1888 FIXME("Render state WINED3DRS_SUBPIXELX not implemented yet.\n");
1889 }
1890
1891 static void state_stippleenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1892 {
1893 if (stateblock->state.render_states[WINED3DRS_STIPPLEENABLE])
1894 FIXME("Render state WINED3DRS_STIPPLEENABLE not implemented yet.\n");
1895 }
1896
1897 static void state_mipmaplodbias(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1898 {
1899 if (stateblock->state.render_states[WINED3DRS_MIPMAPLODBIAS])
1900 FIXME("Render state WINED3DRS_MIPMAPLODBIAS not implemented yet.\n");
1901 }
1902
1903 static void state_anisotropy(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1904 {
1905 if (stateblock->state.render_states[WINED3DRS_ANISOTROPY])
1906 FIXME("Render state WINED3DRS_ANISOTROPY not implemented yet.\n");
1907 }
1908
1909 static void state_flushbatch(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1910 {
1911 if (stateblock->state.render_states[WINED3DRS_FLUSHBATCH])
1912 FIXME("Render state WINED3DRS_FLUSHBATCH not implemented yet.\n");
1913 }
1914
1915 static void state_translucentsi(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1916 {
1917 if (stateblock->state.render_states[WINED3DRS_TRANSLUCENTSORTINDEPENDENT])
1918 FIXME("Render state WINED3DRS_TRANSLUCENTSORTINDEPENDENT not implemented yet.\n");
1919 }
1920
1921 static void state_extents(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1922 {
1923 if (stateblock->state.render_states[WINED3DRS_EXTENTS])
1924 FIXME("Render state WINED3DRS_EXTENTS not implemented yet.\n");
1925 }
1926
1927 static void state_ckeyblend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1928 {
1929 if (stateblock->state.render_states[WINED3DRS_COLORKEYBLENDENABLE])
1930 FIXME("Render state WINED3DRS_COLORKEYBLENDENABLE not implemented yet.\n");
1931 }
1932
1933 static void state_swvp(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
1934 {
1935 if (stateblock->state.render_states[WINED3DRS_SOFTWAREVERTEXPROCESSING])
1936 FIXME("Software vertex processing not implemented.\n");
1937 }
1938
1939 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
1940 #if defined (GL_VERSION_1_3)
1941 # define useext(A) A
1942 #elif defined (GL_EXT_texture_env_combine)
1943 # define useext(A) A##_EXT
1944 #elif defined (GL_ARB_texture_env_combine)
1945 # define useext(A) A##_ARB
1946 #endif
1947
1948 static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* operand) {
1949 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the
1950 * input should be used for all input components. The WINED3DTA_COMPLEMENT
1951 * flag specifies the complement of the input should be used. */
1952 BOOL from_alpha = is_alpha || arg & WINED3DTA_ALPHAREPLICATE;
1953 BOOL complement = arg & WINED3DTA_COMPLEMENT;
1954
1955 /* Calculate the operand */
1956 if (complement) {
1957 if (from_alpha) *operand = GL_ONE_MINUS_SRC_ALPHA;
1958 else *operand = GL_ONE_MINUS_SRC_COLOR;
1959 } else {
1960 if (from_alpha) *operand = GL_SRC_ALPHA;
1961 else *operand = GL_SRC_COLOR;
1962 }
1963
1964 /* Calculate the source */
1965 switch (arg & WINED3DTA_SELECTMASK) {
1966 case WINED3DTA_CURRENT: *source = GL_PREVIOUS_EXT; break;
1967 case WINED3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT; break;
1968 case WINED3DTA_TEXTURE: *source = GL_TEXTURE; break;
1969 case WINED3DTA_TFACTOR: *source = GL_CONSTANT_EXT; break;
1970 case WINED3DTA_SPECULAR:
1971 /*
1972 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
1973 * 'Secondary color' and isn't supported until base GL supports it
1974 * There is no concept of temp registers as far as I can tell
1975 */
1976 FIXME("Unhandled texture arg WINED3DTA_SPECULAR\n");
1977 *source = GL_TEXTURE;
1978 break;
1979 default:
1980 FIXME("Unrecognized texture arg %#x\n", arg);
1981 *source = GL_TEXTURE;
1982 break;
1983 }
1984 }
1985
1986 /* Setup the texture operations texture stage states */
1987 static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
1988 BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
1989 {
1990 GLenum src1, src2, src3;
1991 GLenum opr1, opr2, opr3;
1992 GLenum comb_target;
1993 GLenum src0_target, src1_target, src2_target;
1994 GLenum opr0_target, opr1_target, opr2_target;
1995 GLenum scal_target;
1996 GLenum opr=0, invopr, src3_target, opr3_target;
1997 BOOL Handled = FALSE;
1998
1999 TRACE("Alpha?(%d), Stage:%d Op(%s), a1(%d), a2(%d), a3(%d)\n", isAlpha, Stage, debug_d3dtop(op), arg1, arg2, arg3);
2000
2001 /* This is called by a state handler which has the gl lock held and a context for the thread */
2002
2003 /* Note: Operations usually involve two ars, src0 and src1 and are operations of
2004 the form (a1 <operation> a2). However, some of the more complex operations
2005 take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
2006 in a third parameter called a0. Therefore these are operations of the form
2007 a0 <operation> a1 <operation> a2, i.e., the new parameter goes to the front.
2008
2009 However, below we treat the new (a0) parameter as src2/opr2, so in the actual
2010 functions below, expect their syntax to differ slightly to those listed in the
2011 manuals, i.e., replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
2012 This affects WINED3DTOP_MULTIPLYADD and WINED3DTOP_LERP */
2013
2014 if (isAlpha) {
2015 comb_target = useext(GL_COMBINE_ALPHA);
2016 src0_target = useext(GL_SOURCE0_ALPHA);
2017 src1_target = useext(GL_SOURCE1_ALPHA);
2018 src2_target = useext(GL_SOURCE2_ALPHA);
2019 opr0_target = useext(GL_OPERAND0_ALPHA);
2020 opr1_target = useext(GL_OPERAND1_ALPHA);
2021 opr2_target = useext(GL_OPERAND2_ALPHA);
2022 scal_target = GL_ALPHA_SCALE;
2023 }
2024 else {
2025 comb_target = useext(GL_COMBINE_RGB);
2026 src0_target = useext(GL_SOURCE0_RGB);
2027 src1_target = useext(GL_SOURCE1_RGB);
2028 src2_target = useext(GL_SOURCE2_RGB);
2029 opr0_target = useext(GL_OPERAND0_RGB);
2030 opr1_target = useext(GL_OPERAND1_RGB);
2031 opr2_target = useext(GL_OPERAND2_RGB);
2032 scal_target = useext(GL_RGB_SCALE);
2033 }
2034
2035 /* If a texture stage references an invalid texture unit the stage just
2036 * passes through the result from the previous stage */
2037 if (is_invalid_op(state, Stage, op, arg1, arg2, arg3))
2038 {
2039 arg1 = WINED3DTA_CURRENT;
2040 op = WINED3DTOP_SELECTARG1;
2041 }
2042
2043 if (isAlpha && !state->textures[Stage] && arg1 == WINED3DTA_TEXTURE)
2044 {
2045 get_src_and_opr(WINED3DTA_DIFFUSE, isAlpha, &src1, &opr1);
2046 } else {
2047 get_src_and_opr(arg1, isAlpha, &src1, &opr1);
2048 }
2049 get_src_and_opr(arg2, isAlpha, &src2, &opr2);
2050 get_src_and_opr(arg3, isAlpha, &src3, &opr3);
2051
2052 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
2053
2054 Handled = TRUE; /* Assume will be handled */
2055
2056 /* Other texture operations require special extensions: */
2057 if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
2058 {
2059 if (isAlpha) {
2060 opr = GL_SRC_ALPHA;
2061 invopr = GL_ONE_MINUS_SRC_ALPHA;
2062 src3_target = GL_SOURCE3_ALPHA_NV;
2063 opr3_target = GL_OPERAND3_ALPHA_NV;
2064 } else {
2065 opr = GL_SRC_COLOR;
2066 invopr = GL_ONE_MINUS_SRC_COLOR;
2067 src3_target = GL_SOURCE3_RGB_NV;
2068 opr3_target = GL_OPERAND3_RGB_NV;
2069 }
2070 switch (op) {
2071 case WINED3DTOP_DISABLE: /* Only for alpha */
2072 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2073 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2074 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2075 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2076 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2077 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2078 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2079 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2080 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2081 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2082 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2083 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2084 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2085 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2086 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2087 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2088 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2089 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2090 break;
2091 case WINED3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */
2092 case WINED3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */
2093 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2094 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2095 if (op == WINED3DTOP_SELECTARG1) {
2096 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2097 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2098 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2099 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2100 } else {
2101 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2102 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2103 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2104 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2105 }
2106 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2107 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2108 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2109 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2110 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2111 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2112 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2113 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2114 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2115 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2116 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2117 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2118 break;
2119
2120 case WINED3DTOP_MODULATE:
2121 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2122 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2123 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2124 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2125 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2126 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2127 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2128 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2129 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2130 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2131 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2132 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2133 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2134 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2135 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2136 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2137 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2138 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2139 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2140 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2141 break;
2142 case WINED3DTOP_MODULATE2X:
2143 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2144 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2145 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2146 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2147 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2148 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2149 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2150 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2151 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2152 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2153 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2154 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2155 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2156 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2157 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2158 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2159 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2160 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2161 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2162 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2163 break;
2164 case WINED3DTOP_MODULATE4X:
2165 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2166 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2167 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2168 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2169 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2170 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2171 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2172 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2173 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2174 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2175 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2176 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2177 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2178 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2179 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2180 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2181 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2182 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2183 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2184 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2185 break;
2186
2187 case WINED3DTOP_ADD:
2188 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2189 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2190 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2191 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2192 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2193 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2194 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2195 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2196 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2197 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2198 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2199 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2200 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2201 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2202 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2203 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2204 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2205 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2206 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2207 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2208 break;
2209
2210 case WINED3DTOP_ADDSIGNED:
2211 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
2212 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
2213 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2214 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2215 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2216 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2217 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2218 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2219 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2220 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2221 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2222 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2223 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2224 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2225 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2226 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2227 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2228 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2229 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2230 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2231 break;
2232
2233 case WINED3DTOP_ADDSIGNED2X:
2234 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
2235 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
2236 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2237 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2238 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2239 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2240 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2241 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2242 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2243 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2244 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2245 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2246 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2247 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2248 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2249 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2250 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2251 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2252 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2253 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2254 break;
2255
2256 case WINED3DTOP_ADDSMOOTH:
2257 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2258 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2259 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2260 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2261 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2262 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2263 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2264 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2265 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2266 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2267 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2268 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2269 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2270 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2271 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2272 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2273 switch (opr1) {
2274 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2275 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2276 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2277 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2278 }
2279 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2280 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2281 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2282 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2283 break;
2284
2285 case WINED3DTOP_BLENDDIFFUSEALPHA:
2286 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2287 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2288 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2289 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2290 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2291 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2292 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
2293 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
2294 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2295 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2296 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2297 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2298 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2299 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2300 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
2301 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
2302 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2303 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2304 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2305 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2306 break;
2307 case WINED3DTOP_BLENDTEXTUREALPHA:
2308 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2309 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2310 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2311 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2312 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2313 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2314 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
2315 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
2316 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2317 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2318 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2319 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2320 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2321 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2322 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2323 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2324 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2325 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2326 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2327 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2328 break;
2329 case WINED3DTOP_BLENDFACTORALPHA:
2330 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2331 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2332 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2333 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2334 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2335 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2336 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT));
2337 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
2338 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2339 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2340 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2341 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2342 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2343 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2344 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
2345 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
2346 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2347 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2348 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2349 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2350 break;
2351 case WINED3DTOP_BLENDTEXTUREALPHAPM:
2352 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2353 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2354 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2355 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2356 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2357 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2358 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2359 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2360 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2361 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2362 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2363 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2364 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2365 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2366 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2367 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2368 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2369 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2370 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2371 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2372 break;
2373 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
2374 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2375 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2376 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
2377 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2378 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2379 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
2380 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2381 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2382 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2383 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2384 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
2385 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2386 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2387 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
2388 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2389 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2390 switch (opr) {
2391 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2392 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2393 }
2394 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2395 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2396 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2397 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2398 break;
2399 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
2400 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2401 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2402 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2403 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2404 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2405 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2406 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2407 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2408 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2409 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2410 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2411 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2412 switch (opr1) {
2413 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2414 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2415 }
2416 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2417 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2418 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2419 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2420 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2421 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2422 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2423 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2424 break;
2425 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
2426 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2427 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2428 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2429 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2430 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2431 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2432 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2433 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2434 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2435 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2436 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2437 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2438 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2439 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2440 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2441 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
2442 switch (opr1) {
2443 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2444 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2445 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2446 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2447 }
2448 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2449 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2450 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2451 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2452 break;
2453 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
2454 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2455 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2456 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2457 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2458 switch (opr1) {
2459 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2460 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2461 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2462 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2463 }
2464 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2465 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2466 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2467 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2468 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2469 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2470 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2471 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
2472 switch (opr1) {
2473 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2474 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2475 }
2476 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2477 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2478 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2479 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2480 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2481 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2482 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2483 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2484 break;
2485 case WINED3DTOP_MULTIPLYADD:
2486 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2487 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2488 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
2489 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2490 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
2491 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2492 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2493 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2494 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2495 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2496 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2497 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2498 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
2499 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2500 glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
2501 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
2502 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
2503 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
2504 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2505 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2506 break;
2507
2508 case WINED3DTOP_BUMPENVMAP:
2509 {
2510 }
2511
2512 case WINED3DTOP_BUMPENVMAPLUMINANCE:
2513 FIXME("Implement bump environment mapping in GL_NV_texture_env_combine4 path\n");
2514
2515 default:
2516 Handled = FALSE;
2517 }
2518 if (Handled) {
2519 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
2520 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
2521
2522 return;
2523 }
2524 } /* GL_NV_texture_env_combine4 */
2525
2526 Handled = TRUE; /* Again, assume handled */
2527 switch (op) {
2528 case WINED3DTOP_DISABLE: /* Only for alpha */
2529 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2530 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2531 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2532 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
2533 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2534 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
2535 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2536 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2537 break;
2538 case WINED3DTOP_SELECTARG1:
2539 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2540 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2541 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2542 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2543 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2544 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2545 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2546 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2547 break;
2548 case WINED3DTOP_SELECTARG2:
2549 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2550 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2551 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2552 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2553 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2554 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2555 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2556 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2557 break;
2558 case WINED3DTOP_MODULATE:
2559 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2560 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2561 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2562 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2563 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2564 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2565 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2566 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2567 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2568 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2569 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2570 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2571 break;
2572 case WINED3DTOP_MODULATE2X:
2573 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2574 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2575 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2576 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2577 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2578 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2579 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2580 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2581 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2582 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2583 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2584 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2585 break;
2586 case WINED3DTOP_MODULATE4X:
2587 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2588 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2589 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2590 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2591 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2592 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2593 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2594 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2595 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2596 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2597 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2598 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
2599 break;
2600 case WINED3DTOP_ADD:
2601 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2602 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2603 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2604 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2605 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2606 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2607 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2608 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2609 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2610 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2611 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2612 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2613 break;
2614 case WINED3DTOP_ADDSIGNED:
2615 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
2616 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
2617 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2618 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2619 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2620 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2621 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2622 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2623 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2624 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2625 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2626 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2627 break;
2628 case WINED3DTOP_ADDSIGNED2X:
2629 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
2630 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
2631 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2632 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2633 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2634 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2635 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2636 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2637 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2638 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2639 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2640 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
2641 break;
2642 case WINED3DTOP_SUBTRACT:
2643 if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE])
2644 {
2645 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
2646 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
2647 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2648 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2649 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2650 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2651 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2652 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2653 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2654 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2655 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2656 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2657 } else {
2658 FIXME("This version of opengl does not support GL_SUBTRACT\n");
2659 }
2660 break;
2661
2662 case WINED3DTOP_BLENDDIFFUSEALPHA:
2663 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
2664 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
2665 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2666 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2667 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2668 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2669 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2670 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2671 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2672 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2673 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
2674 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
2675 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2676 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2677 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2678 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2679 break;
2680 case WINED3DTOP_BLENDTEXTUREALPHA:
2681 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
2682 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
2683 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2684 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2685 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2686 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2687 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2688 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2689 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2690 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2691 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
2692 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
2693 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2694 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2695 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2696 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2697 break;
2698 case WINED3DTOP_BLENDFACTORALPHA:
2699 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
2700 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
2701 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2702 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2703 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2704 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2705 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2706 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2707 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2708 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2709 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
2710 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
2711 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2712 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2713 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2714 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2715 break;
2716 case WINED3DTOP_BLENDCURRENTALPHA:
2717 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
2718 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
2719 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2720 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2721 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2722 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2723 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2724 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2725 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2726 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2727 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
2728 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
2729 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2730 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2731 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2732 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2733 break;
2734 case WINED3DTOP_DOTPRODUCT3:
2735 if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
2736 {
2737 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
2738 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
2739 }
2740 else if (gl_info->supported[EXT_TEXTURE_ENV_DOT3])
2741 {
2742 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
2743 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
2744 } else {
2745 FIXME("This version of opengl does not support GL_DOT3\n");
2746 }
2747 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2748 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2749 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2750 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2751 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2752 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2753 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2754 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2755 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2756 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2757 break;
2758 case WINED3DTOP_LERP:
2759 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
2760 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
2761 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2762 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2763 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2764 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2765 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2766 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2767 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2768 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2769 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
2770 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
2771 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
2772 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
2773 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2774 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2775 break;
2776 case WINED3DTOP_ADDSMOOTH:
2777 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2778 {
2779 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2780 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2781 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2782 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2783 switch (opr1) {
2784 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2785 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2786 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2787 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2788 }
2789 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2790 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2791 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2792 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2793 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2794 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2795 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2796 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2797 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2798 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2799 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2800 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2801 } else
2802 Handled = FALSE;
2803 break;
2804 case WINED3DTOP_BLENDTEXTUREALPHAPM:
2805 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2806 {
2807 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2808 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2809 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
2810 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
2811 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
2812 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
2813 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2814 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2815 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2816 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2817 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2818 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2819 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2820 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2821 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2822 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2823 } else
2824 Handled = FALSE;
2825 break;
2826 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
2827 if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2828 {
2829 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2830 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2831 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2832 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2833 switch (opr1) {
2834 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2835 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2836 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2837 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2838 }