2 * Utility functions for the WineD3D Library
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
29 /*****************************************************************************
30 * Trace formatting of useful values
32 const char* debug_d3dformat(WINED3DFORMAT fmt) {
34 #define FMT_TO_STR(fmt) case fmt: return #fmt
35 FMT_TO_STR(WINED3DFMT_UNKNOWN);
36 FMT_TO_STR(WINED3DFMT_R8G8B8);
37 FMT_TO_STR(WINED3DFMT_A8R8G8B8);
38 FMT_TO_STR(WINED3DFMT_X8R8G8B8);
39 FMT_TO_STR(WINED3DFMT_R5G6B5);
40 FMT_TO_STR(WINED3DFMT_X1R5G5B5);
41 FMT_TO_STR(WINED3DFMT_A1R5G5B5);
42 FMT_TO_STR(WINED3DFMT_A4R4G4B4);
43 FMT_TO_STR(WINED3DFMT_R3G3B2);
44 FMT_TO_STR(WINED3DFMT_A8);
45 FMT_TO_STR(WINED3DFMT_A8R3G3B2);
46 FMT_TO_STR(WINED3DFMT_X4R4G4B4);
47 FMT_TO_STR(WINED3DFMT_G16R16);
48 FMT_TO_STR(WINED3DFMT_A2R10G10B10);
49 FMT_TO_STR(WINED3DFMT_A16B16G16R16);
50 FMT_TO_STR(WINED3DFMT_A8P8);
51 FMT_TO_STR(WINED3DFMT_P8);
52 FMT_TO_STR(WINED3DFMT_L8);
53 FMT_TO_STR(WINED3DFMT_A8L8);
54 FMT_TO_STR(WINED3DFMT_A4L4);
55 FMT_TO_STR(WINED3DFMT_V8U8);
56 FMT_TO_STR(WINED3DFMT_L6V5U5);
57 FMT_TO_STR(WINED3DFMT_X8L8V8U8);
58 FMT_TO_STR(WINED3DFMT_Q8W8V8U8);
59 FMT_TO_STR(WINED3DFMT_V16U16);
60 FMT_TO_STR(WINED3DFMT_W11V11U10);
61 FMT_TO_STR(WINED3DFMT_A2W10V10U10);
62 FMT_TO_STR(WINED3DFMT_UYVY);
63 FMT_TO_STR(WINED3DFMT_YUY2);
64 FMT_TO_STR(WINED3DFMT_DXT1);
65 FMT_TO_STR(WINED3DFMT_DXT2);
66 FMT_TO_STR(WINED3DFMT_DXT3);
67 FMT_TO_STR(WINED3DFMT_DXT4);
68 FMT_TO_STR(WINED3DFMT_DXT5);
69 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB);
70 FMT_TO_STR(WINED3DFMT_G8R8_G8B8);
71 FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
72 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
73 FMT_TO_STR(WINED3DFMT_D32);
74 FMT_TO_STR(WINED3DFMT_D15S1);
75 FMT_TO_STR(WINED3DFMT_D24S8);
76 FMT_TO_STR(WINED3DFMT_D24X8);
77 FMT_TO_STR(WINED3DFMT_D24X4S4);
78 FMT_TO_STR(WINED3DFMT_D16);
79 FMT_TO_STR(WINED3DFMT_D32F_LOCKABLE);
80 FMT_TO_STR(WINED3DFMT_VERTEXDATA);
81 FMT_TO_STR(WINED3DFMT_INDEX16);
82 FMT_TO_STR(WINED3DFMT_INDEX32);
83 FMT_TO_STR(WINED3DFMT_Q16W16V16U16);
84 FMT_TO_STR(WINED3DFMT_R16F);
85 FMT_TO_STR(WINED3DFMT_G16R16F);
86 FMT_TO_STR(WINED3DFMT_A16B16G16R16F);
89 FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
90 return "unrecognized";
94 const char* debug_d3ddevicetype(D3DDEVTYPE devtype) {
96 #define DEVTYPE_TO_STR(dev) case dev: return #dev
97 DEVTYPE_TO_STR(D3DDEVTYPE_HAL);
98 DEVTYPE_TO_STR(D3DDEVTYPE_REF);
99 DEVTYPE_TO_STR(D3DDEVTYPE_SW);
100 #undef DEVTYPE_TO_STR
102 FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
103 return "unrecognized";
107 const char* debug_d3dusage(DWORD usage) {
109 #define D3DUSAGE_TO_STR(u) case u: return #u
110 D3DUSAGE_TO_STR(D3DUSAGE_RENDERTARGET);
111 D3DUSAGE_TO_STR(D3DUSAGE_DEPTHSTENCIL);
112 D3DUSAGE_TO_STR(D3DUSAGE_WRITEONLY);
113 D3DUSAGE_TO_STR(D3DUSAGE_SOFTWAREPROCESSING);
114 D3DUSAGE_TO_STR(D3DUSAGE_DONOTCLIP);
115 D3DUSAGE_TO_STR(D3DUSAGE_POINTS);
116 D3DUSAGE_TO_STR(D3DUSAGE_RTPATCHES);
117 D3DUSAGE_TO_STR(D3DUSAGE_NPATCHES);
118 D3DUSAGE_TO_STR(D3DUSAGE_DYNAMIC);
119 #undef D3DUSAGE_TO_STR
120 case 0: return "none";
122 FIXME("Unrecognized %lu Usage!\n", usage);
123 return "unrecognized";
127 const char* debug_d3dresourcetype(D3DRESOURCETYPE res) {
129 #define RES_TO_STR(res) case res: return #res;
130 RES_TO_STR(D3DRTYPE_SURFACE);
131 RES_TO_STR(D3DRTYPE_VOLUME);
132 RES_TO_STR(D3DRTYPE_TEXTURE);
133 RES_TO_STR(D3DRTYPE_VOLUMETEXTURE);
134 RES_TO_STR(D3DRTYPE_CUBETEXTURE);
135 RES_TO_STR(D3DRTYPE_VERTEXBUFFER);
136 RES_TO_STR(D3DRTYPE_INDEXBUFFER);
139 FIXME("Unrecognized %u D3DRESOURCETYPE!\n", res);
140 return "unrecognized";
144 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType) {
145 switch (PrimitiveType) {
146 #define PRIM_TO_STR(prim) case prim: return #prim;
147 PRIM_TO_STR(D3DPT_POINTLIST);
148 PRIM_TO_STR(D3DPT_LINELIST);
149 PRIM_TO_STR(D3DPT_LINESTRIP);
150 PRIM_TO_STR(D3DPT_TRIANGLELIST);
151 PRIM_TO_STR(D3DPT_TRIANGLESTRIP);
152 PRIM_TO_STR(D3DPT_TRIANGLEFAN);
155 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
156 return "unrecognized";
160 const char* debug_d3drenderstate(DWORD state) {
162 #define D3DSTATE_TO_STR(u) case u: return #u
163 D3DSTATE_TO_STR(WINED3DRS_ZENABLE );
164 D3DSTATE_TO_STR(WINED3DRS_FILLMODE );
165 D3DSTATE_TO_STR(WINED3DRS_SHADEMODE );
166 D3DSTATE_TO_STR(WINED3DRS_LINEPATTERN );
167 D3DSTATE_TO_STR(WINED3DRS_ZWRITEENABLE );
168 D3DSTATE_TO_STR(WINED3DRS_ALPHATESTENABLE );
169 D3DSTATE_TO_STR(WINED3DRS_LASTPIXEL );
170 D3DSTATE_TO_STR(WINED3DRS_SRCBLEND );
171 D3DSTATE_TO_STR(WINED3DRS_DESTBLEND );
172 D3DSTATE_TO_STR(WINED3DRS_CULLMODE );
173 D3DSTATE_TO_STR(WINED3DRS_ZFUNC );
174 D3DSTATE_TO_STR(WINED3DRS_ALPHAREF );
175 D3DSTATE_TO_STR(WINED3DRS_ALPHAFUNC );
176 D3DSTATE_TO_STR(WINED3DRS_DITHERENABLE );
177 D3DSTATE_TO_STR(WINED3DRS_ALPHABLENDENABLE );
178 D3DSTATE_TO_STR(WINED3DRS_FOGENABLE );
179 D3DSTATE_TO_STR(WINED3DRS_SPECULARENABLE );
180 D3DSTATE_TO_STR(WINED3DRS_ZVISIBLE );
181 D3DSTATE_TO_STR(WINED3DRS_FOGCOLOR );
182 D3DSTATE_TO_STR(WINED3DRS_FOGTABLEMODE );
183 D3DSTATE_TO_STR(WINED3DRS_FOGSTART );
184 D3DSTATE_TO_STR(WINED3DRS_FOGEND );
185 D3DSTATE_TO_STR(WINED3DRS_FOGDENSITY );
186 D3DSTATE_TO_STR(WINED3DRS_EDGEANTIALIAS );
187 D3DSTATE_TO_STR(WINED3DRS_ZBIAS );
188 D3DSTATE_TO_STR(WINED3DRS_RANGEFOGENABLE );
189 D3DSTATE_TO_STR(WINED3DRS_STENCILENABLE );
190 D3DSTATE_TO_STR(WINED3DRS_STENCILFAIL );
191 D3DSTATE_TO_STR(WINED3DRS_STENCILZFAIL );
192 D3DSTATE_TO_STR(WINED3DRS_STENCILPASS );
193 D3DSTATE_TO_STR(WINED3DRS_STENCILFUNC );
194 D3DSTATE_TO_STR(WINED3DRS_STENCILREF );
195 D3DSTATE_TO_STR(WINED3DRS_STENCILMASK );
196 D3DSTATE_TO_STR(WINED3DRS_STENCILWRITEMASK );
197 D3DSTATE_TO_STR(WINED3DRS_TEXTUREFACTOR );
198 D3DSTATE_TO_STR(WINED3DRS_WRAP0 );
199 D3DSTATE_TO_STR(WINED3DRS_WRAP1 );
200 D3DSTATE_TO_STR(WINED3DRS_WRAP2 );
201 D3DSTATE_TO_STR(WINED3DRS_WRAP3 );
202 D3DSTATE_TO_STR(WINED3DRS_WRAP4 );
203 D3DSTATE_TO_STR(WINED3DRS_WRAP5 );
204 D3DSTATE_TO_STR(WINED3DRS_WRAP6 );
205 D3DSTATE_TO_STR(WINED3DRS_WRAP7 );
206 D3DSTATE_TO_STR(WINED3DRS_CLIPPING );
207 D3DSTATE_TO_STR(WINED3DRS_LIGHTING );
208 D3DSTATE_TO_STR(WINED3DRS_AMBIENT );
209 D3DSTATE_TO_STR(WINED3DRS_FOGVERTEXMODE );
210 D3DSTATE_TO_STR(WINED3DRS_COLORVERTEX );
211 D3DSTATE_TO_STR(WINED3DRS_LOCALVIEWER );
212 D3DSTATE_TO_STR(WINED3DRS_NORMALIZENORMALS );
213 D3DSTATE_TO_STR(WINED3DRS_DIFFUSEMATERIALSOURCE );
214 D3DSTATE_TO_STR(WINED3DRS_SPECULARMATERIALSOURCE );
215 D3DSTATE_TO_STR(WINED3DRS_AMBIENTMATERIALSOURCE );
216 D3DSTATE_TO_STR(WINED3DRS_EMISSIVEMATERIALSOURCE );
217 D3DSTATE_TO_STR(WINED3DRS_VERTEXBLEND );
218 D3DSTATE_TO_STR(WINED3DRS_CLIPPLANEENABLE );
219 D3DSTATE_TO_STR(WINED3DRS_SOFTWAREVERTEXPROCESSING );
220 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE );
221 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MIN );
222 D3DSTATE_TO_STR(WINED3DRS_POINTSPRITEENABLE );
223 D3DSTATE_TO_STR(WINED3DRS_POINTSCALEENABLE );
224 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_A );
225 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_B );
226 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_C );
227 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEANTIALIAS );
228 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEMASK );
229 D3DSTATE_TO_STR(WINED3DRS_PATCHEDGESTYLE );
230 D3DSTATE_TO_STR(WINED3DRS_PATCHSEGMENTS );
231 D3DSTATE_TO_STR(WINED3DRS_DEBUGMONITORTOKEN );
232 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MAX );
233 D3DSTATE_TO_STR(WINED3DRS_INDEXEDVERTEXBLENDENABLE );
234 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE );
235 D3DSTATE_TO_STR(WINED3DRS_TWEENFACTOR );
236 D3DSTATE_TO_STR(WINED3DRS_BLENDOP );
237 D3DSTATE_TO_STR(WINED3DRS_POSITIONDEGREE );
238 D3DSTATE_TO_STR(WINED3DRS_NORMALDEGREE );
239 #undef D3DSTATE_TO_STR
241 FIXME("Unrecognized %lu render state!\n", state);
242 return "unrecognized";
246 const char* debug_d3dsamplerstate(DWORD state) {
248 #define D3DSTATE_TO_STR(u) case u: return #u
249 D3DSTATE_TO_STR(WINED3DSAMP_BORDERCOLOR );
250 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSU );
251 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSV );
252 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSW );
253 D3DSTATE_TO_STR(WINED3DSAMP_MAGFILTER );
254 D3DSTATE_TO_STR(WINED3DSAMP_MINFILTER );
255 D3DSTATE_TO_STR(WINED3DSAMP_MIPFILTER );
256 D3DSTATE_TO_STR(WINED3DSAMP_MIPMAPLODBIAS);
257 D3DSTATE_TO_STR(WINED3DSAMP_MAXMIPLEVEL );
258 D3DSTATE_TO_STR(WINED3DSAMP_MAXANISOTROPY);
259 D3DSTATE_TO_STR(WINED3DSAMP_SRGBTEXTURE );
260 D3DSTATE_TO_STR(WINED3DSAMP_ELEMENTINDEX );
261 D3DSTATE_TO_STR(WINED3DSAMP_DMAPOFFSET );
262 #undef D3DSTATE_TO_STR
264 FIXME("Unrecognized %lu sampler state!\n", state);
265 return "unrecognized";
269 const char* debug_d3dtexturestate(DWORD state) {
271 #define D3DSTATE_TO_STR(u) case u: return #u
272 D3DSTATE_TO_STR(WINED3DTSS_COLOROP );
273 D3DSTATE_TO_STR(WINED3DTSS_COLORARG1 );
274 D3DSTATE_TO_STR(WINED3DTSS_COLORARG2 );
275 D3DSTATE_TO_STR(WINED3DTSS_ALPHAOP );
276 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG1 );
277 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG2 );
278 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT00 );
279 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT01 );
280 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT10 );
281 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT11 );
282 D3DSTATE_TO_STR(WINED3DTSS_TEXCOORDINDEX );
283 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLSCALE );
284 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLOFFSET );
285 D3DSTATE_TO_STR(WINED3DTSS_TEXTURETRANSFORMFLAGS );
286 D3DSTATE_TO_STR(WINED3DTSS_ADDRESSW );
287 D3DSTATE_TO_STR(WINED3DTSS_COLORARG0 );
288 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG0 );
289 D3DSTATE_TO_STR(WINED3DTSS_RESULTARG );
290 D3DSTATE_TO_STR(WINED3DTSS_CONSTANT );
291 #undef D3DSTATE_TO_STR
293 /* Note D3DTSS are not consecutive, so skip these */
297 FIXME("Unrecognized %lu texture state!\n", state);
298 return "unrecognized";
302 const char* debug_d3dpool(D3DPOOL Pool) {
304 #define POOL_TO_STR(p) case p: return #p;
305 POOL_TO_STR(D3DPOOL_DEFAULT);
306 POOL_TO_STR(D3DPOOL_MANAGED);
307 POOL_TO_STR(D3DPOOL_SYSTEMMEM);
308 POOL_TO_STR(D3DPOOL_SCRATCH);
311 FIXME("Unrecognized %u D3DPOOL!\n", Pool);
312 return "unrecognized";
315 /*****************************************************************************
316 * Useful functions mapping GL <-> D3D values
318 GLenum StencilOp(DWORD op) {
320 case D3DSTENCILOP_KEEP : return GL_KEEP;
321 case D3DSTENCILOP_ZERO : return GL_ZERO;
322 case D3DSTENCILOP_REPLACE : return GL_REPLACE;
323 case D3DSTENCILOP_INCRSAT : return GL_INCR;
324 case D3DSTENCILOP_DECRSAT : return GL_DECR;
325 case D3DSTENCILOP_INVERT : return GL_INVERT;
326 case D3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
327 case D3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
329 FIXME("Invalid stencil op %ld\n", op);
334 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
335 #if defined (GL_VERSION_1_3)
337 # define combine_ext 1
338 #elif defined (GL_EXT_texture_env_combine)
339 # define useext(A) A##_EXT
340 # define combine_ext 1
341 #elif defined (GL_ARB_texture_env_combine)
342 # define useext(A) A##_ARB
343 # define combine_ext 1
348 #if !defined(combine_ext)
349 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
351 FIXME("Requires opengl combine extensions to work\n");
355 /* Setup the texture operations texture stage states */
356 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
358 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
359 GLenum src1, src2, src3;
360 GLenum opr1, opr2, opr3;
362 GLenum src0_target, src1_target, src2_target;
363 GLenum opr0_target, opr1_target, opr2_target;
365 GLenum opr=0, invopr, src3_target, opr3_target;
366 BOOL Handled = FALSE;
367 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
369 TRACE("Alpha?(%d), Stage:%d Op(%d), a1(%ld), a2(%ld), a3(%ld)\n", isAlpha, Stage, op, arg1, arg2, arg3);
373 /* Note: Operations usually involve two ars, src0 and src1 and are operations of
374 the form (a1 <operation> a2). However, some of the more complex operations
375 take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
376 in a third parameter called a0. Therefore these are operations of the form
377 a0 <operation> a1 <operation> a2, ie the new parameter goes to the front.
379 However, below we treat the new (a0) parameter as src2/opr2, so in the actual
380 functions below, expect their syntax to differ slightly to those listed in the
381 manuals, ie replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
382 This affects D3DTOP_MULTIPLYADD and D3DTOP_LERP */
385 comb_target = useext(GL_COMBINE_ALPHA);
386 src0_target = useext(GL_SOURCE0_ALPHA);
387 src1_target = useext(GL_SOURCE1_ALPHA);
388 src2_target = useext(GL_SOURCE2_ALPHA);
389 opr0_target = useext(GL_OPERAND0_ALPHA);
390 opr1_target = useext(GL_OPERAND1_ALPHA);
391 opr2_target = useext(GL_OPERAND2_ALPHA);
392 scal_target = GL_ALPHA_SCALE;
395 comb_target = useext(GL_COMBINE_RGB);
396 src0_target = useext(GL_SOURCE0_RGB);
397 src1_target = useext(GL_SOURCE1_RGB);
398 src2_target = useext(GL_SOURCE2_RGB);
399 opr0_target = useext(GL_OPERAND0_RGB);
400 opr1_target = useext(GL_OPERAND1_RGB);
401 opr2_target = useext(GL_OPERAND2_RGB);
402 scal_target = useext(GL_RGB_SCALE);
405 /* From MSDN (WINED3DTSS_ALPHAARG1) :
406 The default argument is D3DTA_TEXTURE. If no texture is set for this stage,
407 then the default argument is D3DTA_DIFFUSE.
408 FIXME? If texture added/removed, may need to reset back as well? */
409 if (isAlpha && This->stateBlock->textures[Stage] == NULL && arg1 == D3DTA_TEXTURE) {
410 GetSrcAndOpFromValue(D3DTA_DIFFUSE, isAlpha, &src1, &opr1);
412 GetSrcAndOpFromValue(arg1, isAlpha, &src1, &opr1);
414 GetSrcAndOpFromValue(arg2, isAlpha, &src2, &opr2);
415 GetSrcAndOpFromValue(arg3, isAlpha, &src3, &opr3);
417 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
419 Handled = TRUE; /* Assume will be handled */
421 /* Other texture operations require special extensions: */
422 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
425 invopr = GL_ONE_MINUS_SRC_ALPHA;
426 src3_target = GL_SOURCE3_ALPHA_NV;
427 opr3_target = GL_OPERAND3_ALPHA_NV;
430 invopr = GL_ONE_MINUS_SRC_COLOR;
431 src3_target = GL_SOURCE3_RGB_NV;
432 opr3_target = GL_OPERAND3_RGB_NV;
435 case D3DTOP_DISABLE: /* Only for alpha */
436 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
437 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
438 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
439 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
440 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
441 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
442 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
443 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
444 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
445 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
446 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
447 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
448 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
449 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
450 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
451 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
452 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
453 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
455 case D3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */
456 case D3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */
457 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
458 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
459 if (op == D3DTOP_SELECTARG1) {
460 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
461 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
462 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
463 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
465 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
466 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
467 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
468 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
470 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
471 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
472 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
473 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
474 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
475 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
476 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
477 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
478 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
479 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
480 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
481 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
484 case D3DTOP_MODULATE:
485 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
486 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
487 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
488 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
489 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
490 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
491 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
492 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
493 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
494 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
495 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
496 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
497 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
498 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
499 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
500 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
501 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
502 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
503 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
504 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
506 case D3DTOP_MODULATE2X:
507 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
508 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
509 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
510 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
511 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
512 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
513 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
514 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
515 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
516 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
517 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
518 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
519 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
520 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
521 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
522 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
523 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
524 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
525 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
526 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
528 case D3DTOP_MODULATE4X:
529 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
530 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
531 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
532 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
533 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
534 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
535 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
536 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
537 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
538 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
539 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
540 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
541 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
542 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
543 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
544 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
545 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
546 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
547 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
548 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
552 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
553 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
554 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
555 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
556 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
557 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
558 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
559 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
560 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
561 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
562 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
563 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
564 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
565 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
566 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
567 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
568 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
569 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
570 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
571 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
574 case D3DTOP_ADDSIGNED:
575 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
576 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
577 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
578 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
579 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
580 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
581 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
582 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
583 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
584 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
585 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
586 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
587 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
588 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
589 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
590 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
591 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
592 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
593 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
594 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
597 case D3DTOP_ADDSIGNED2X:
598 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
599 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
600 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
601 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
602 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
603 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
604 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
605 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
606 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
607 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
608 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
609 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
610 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
611 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
612 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
613 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
614 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
615 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
616 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
617 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
620 case D3DTOP_ADDSMOOTH:
621 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
622 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
623 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
624 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
625 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
626 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
627 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
628 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
629 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
630 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
631 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
632 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
633 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
634 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
635 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
636 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
638 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
639 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
640 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
641 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
643 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
644 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
645 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
646 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
649 case D3DTOP_BLENDDIFFUSEALPHA:
650 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
651 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
652 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
653 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
654 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
655 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
656 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
657 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
658 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
659 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
660 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
661 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
662 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
663 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
664 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
665 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
666 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
667 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
668 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
669 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
671 case D3DTOP_BLENDTEXTUREALPHA:
672 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
673 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
674 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
675 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
676 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
677 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
678 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
679 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
680 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
681 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
682 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
683 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
684 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
685 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
686 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
687 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
688 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
689 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
690 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
691 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
693 case D3DTOP_BLENDFACTORALPHA:
694 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
695 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
696 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
697 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
698 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
699 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
700 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT));
701 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
702 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
703 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
704 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
705 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
706 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
707 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
708 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
709 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
710 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
711 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
712 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
713 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
715 case D3DTOP_BLENDTEXTUREALPHAPM:
716 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
717 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
718 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
719 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
720 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
721 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
722 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
723 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
724 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
725 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
726 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
727 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
728 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
729 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
730 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
731 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
732 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
733 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
734 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
735 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
737 case D3DTOP_MODULATEALPHA_ADDCOLOR:
738 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
739 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
740 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
741 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
742 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
743 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
744 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
745 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
746 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
747 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
748 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
749 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
750 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
751 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
752 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
753 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
755 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
756 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
758 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
759 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
760 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
761 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
763 case D3DTOP_MODULATECOLOR_ADDALPHA:
764 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
765 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
766 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
767 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
768 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
769 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
770 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
771 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
772 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
773 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
774 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
775 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
777 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
778 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
780 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
781 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
782 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
783 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
784 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
785 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
786 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
787 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
789 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
790 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
791 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
792 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
793 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
794 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
795 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
796 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
797 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
798 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
799 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
800 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
801 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
802 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
803 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
804 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
805 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
807 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
808 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
809 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
810 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
812 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
813 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
814 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
815 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
817 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
818 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
819 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
820 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
821 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
823 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
824 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
825 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
826 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
828 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
829 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
830 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
831 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
832 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
833 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
834 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
835 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
837 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
838 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
840 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
841 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
842 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
843 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
844 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
845 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
846 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
847 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
849 case D3DTOP_MULTIPLYADD:
850 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
851 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
852 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
853 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
854 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
855 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
856 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
857 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
858 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
859 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
860 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
861 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
862 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
863 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
864 glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
865 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
866 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
867 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
868 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
869 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
872 case D3DTOP_BUMPENVMAP:
874 if (GL_SUPPORT(NV_TEXTURE_SHADER)) {
876 texture unit 0: GL_TEXTURE_2D
877 texture unit 1: GL_DOT_PRODUCT_NV
878 texture unit 2: GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV
879 texture unit 3: GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV
888 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT00];
889 m[0][0] = tmpvalue.f;
890 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT01];
891 m[0][1] = tmpvalue.f;
892 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT10];
893 m[1][0] = tmpvalue.f;
894 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT11];
895 m[1][1] = tmpvalue.f;
897 /*FIXME("Stage %d matrix is (%.2f,%.2f),(%.2f,%.2f)\n", Stage, m[0][0], m[0][1], m[1][0], m[1][0]);*/
899 if (FALSE == This->texture_shader_active) {
900 This->texture_shader_active = TRUE;
901 glEnable(GL_TEXTURE_SHADER_NV);
905 glEnable(GL_REGISTER_COMBINERS_NV);
906 glCombinerParameteriNV (GL_NUM_GENERAL_COMBINERS_NV, 1);
907 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
908 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
909 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
910 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
911 glCombinerOutputNV (GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
912 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
913 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
914 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
915 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
916 glCombinerOutputNV (GL_COMBINER0_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
917 glDisable (GL_PER_STAGE_CONSTANTS_NV);
918 glCombinerParameteriNV (GL_COLOR_SUM_CLAMP_NV, 0);
919 glFinalCombinerInputNV (GL_VARIABLE_A_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
920 glFinalCombinerInputNV (GL_VARIABLE_B_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
921 glFinalCombinerInputNV (GL_VARIABLE_C_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
922 glFinalCombinerInputNV (GL_VARIABLE_D_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
923 glFinalCombinerInputNV (GL_VARIABLE_E_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
924 glFinalCombinerInputNV (GL_VARIABLE_F_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
925 glFinalCombinerInputNV (GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
929 for (i = 0; i < Stage; i++) {
930 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
932 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
933 checkGLcall("Activate texture..");
935 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
940 GL_ACTIVETEXTURE(Stage - 1);
941 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
944 GL_ACTIVETEXTURE(Stage);
945 checkGLcall("Activate texture.. to update const color");
946 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
947 checkGLcall("glTexEnv");
948 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + Stage - 1);
949 checkGLcall("glTexEnv");
950 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float*)&m[0]);
951 checkGLcall("glTexEnv");
959 case D3DTOP_BUMPENVMAPLUMINANCE:
965 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
966 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
971 } /* GL_NV_texture_env_combine4 */
973 Handled = TRUE; /* Again, assume handled */
975 case D3DTOP_DISABLE: /* Only for alpha */
976 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
977 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
978 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
979 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
980 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
981 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
982 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
983 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
985 case D3DTOP_SELECTARG1:
986 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
987 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
988 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
989 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
990 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
991 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
992 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
993 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
995 case D3DTOP_SELECTARG2:
996 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
997 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
998 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
999 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1000 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1001 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1002 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1003 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1005 case D3DTOP_MODULATE:
1006 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1007 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1008 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1009 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1010 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1011 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1012 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1013 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1014 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1015 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1016 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1017 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1019 case D3DTOP_MODULATE2X:
1020 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1021 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1022 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1023 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1024 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1025 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1026 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1027 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1028 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1029 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1030 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1031 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1033 case D3DTOP_MODULATE4X:
1034 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1035 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1036 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1037 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1038 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1039 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1040 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1041 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1042 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1043 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1044 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1045 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1048 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1049 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1050 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1051 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1052 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1053 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1054 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1055 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1056 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1057 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1058 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1059 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1061 case D3DTOP_ADDSIGNED:
1062 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1063 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
1064 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1065 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1066 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1067 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1068 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1069 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1070 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1071 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1072 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1073 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1075 case D3DTOP_ADDSIGNED2X:
1076 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1077 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1078 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1079 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1080 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1081 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1082 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1083 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1084 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1085 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1086 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1087 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1089 case D3DTOP_SUBTRACT:
1090 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
1091 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
1092 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
1093 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1094 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1095 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1096 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1097 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1098 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1099 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1100 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1101 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1102 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1104 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1108 case D3DTOP_BLENDDIFFUSEALPHA:
1109 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1110 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1111 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1112 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1113 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1114 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1115 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1116 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1117 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1118 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1119 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
1120 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
1121 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1122 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1123 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1124 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1126 case D3DTOP_BLENDTEXTUREALPHA:
1127 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1128 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1129 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1130 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1131 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1132 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1133 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1134 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1135 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1136 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1137 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
1138 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
1139 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1140 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1141 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1142 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1144 case D3DTOP_BLENDFACTORALPHA:
1145 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1146 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1147 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1148 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1149 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1150 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1151 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1152 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1153 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1154 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1155 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
1156 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
1157 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1158 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1159 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1160 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1162 case D3DTOP_BLENDCURRENTALPHA:
1163 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1164 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1165 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1166 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1167 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1168 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1169 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1170 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1171 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1172 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1173 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
1174 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
1175 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1176 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1177 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1178 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1180 case D3DTOP_DOTPRODUCT3:
1181 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
1182 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
1183 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
1184 } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
1185 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
1186 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
1188 FIXME("This version of opengl does not support GL_DOT3\n");
1190 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1191 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1192 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1193 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1194 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1195 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1196 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1197 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1198 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1199 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1202 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1203 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1204 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1205 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1206 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1207 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1208 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1209 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1210 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1211 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1212 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
1213 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
1214 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
1215 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
1216 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1217 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1219 case D3DTOP_ADDSMOOTH:
1220 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1221 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1222 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1223 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1224 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1226 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1227 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1228 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1229 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1231 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1232 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1233 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1234 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1235 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1236 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1237 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1238 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1239 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1240 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1241 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1242 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1246 case D3DTOP_BLENDTEXTUREALPHAPM:
1247 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1248 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1249 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1250 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
1251 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
1252 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
1253 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
1254 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1255 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1256 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1257 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1258 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1259 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1260 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1261 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1262 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1263 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1267 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1268 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1269 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1270 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1271 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1272 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1274 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1275 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1276 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1277 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1279 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1280 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1281 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1282 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1283 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1284 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1285 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1286 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1287 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1288 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1289 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1290 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1294 case D3DTOP_MODULATECOLOR_ADDALPHA:
1295 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1296 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1297 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1298 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1299 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1300 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1301 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1302 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1303 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1305 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1306 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1307 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1308 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1310 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1311 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1312 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1313 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1314 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1315 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1316 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1317 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1321 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1322 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1323 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1324 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1325 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1326 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1328 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1329 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1330 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1331 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1333 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1334 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1335 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1336 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1337 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1338 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1339 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1340 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1341 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1342 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1343 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1344 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1348 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1349 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1350 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1351 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1352 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1353 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1355 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1356 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1357 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1358 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1360 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1361 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1362 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1363 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1365 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1366 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1367 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1368 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1370 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1371 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1372 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1373 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1374 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1375 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1376 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1377 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1381 case D3DTOP_MULTIPLYADD:
1382 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1383 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1384 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1385 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1386 checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
1387 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1388 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
1389 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1390 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1391 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1392 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1393 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1394 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1395 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1396 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1397 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1398 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1407 BOOL combineOK = TRUE;
1408 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1412 op2 = This->stateBlock->textureState[Stage][WINED3DTSS_COLOROP];
1414 op2 = This->stateBlock->textureState[Stage][WINED3DTSS_ALPHAOP];
1417 /* Note: If COMBINE4 in effect can't go back to combine! */
1419 case D3DTOP_ADDSMOOTH:
1420 case D3DTOP_BLENDTEXTUREALPHAPM:
1421 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1422 case D3DTOP_MODULATECOLOR_ADDALPHA:
1423 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1424 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1425 case D3DTOP_MULTIPLYADD:
1426 /* Ignore those implemented in both cases */
1428 case D3DTOP_SELECTARG1:
1429 case D3DTOP_SELECTARG2:
1434 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%d, otherop=%ld, isAlpha(%d)\n", op, op2, isAlpha);
1442 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
1443 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
1452 /* After all the extensions, if still unhandled, report fixme */
1453 FIXME("Unhandled texture operation %d\n", op);
1454 #undef GLINFO_LOCATION
1458 /* Setup this textures matrix according to the texture flags*/
1459 void set_texture_matrix(const float *smat, DWORD flags)
1463 glMatrixMode(GL_TEXTURE);
1465 if (flags == D3DTTFF_DISABLE) {
1467 checkGLcall("glLoadIdentity()");
1471 if (flags == (D3DTTFF_COUNT1|D3DTTFF_PROJECTED)) {
1472 ERR("Invalid texture transform flags: D3DTTFF_COUNT1|D3DTTFF_PROJECTED\n");
1473 checkGLcall("glLoadIdentity()");
1477 memcpy(mat, smat, 16*sizeof(float));
1479 switch (flags & ~D3DTTFF_PROJECTED) {
1480 case D3DTTFF_COUNT1: mat[1] = mat[5] = mat[9] = mat[13] = 0;
1481 case D3DTTFF_COUNT2: mat[2] = mat[6] = mat[10] = mat[14] = 0;
1482 default: mat[3] = mat[7] = mat[11] = 0, mat[15] = 1;
1485 if (flags & D3DTTFF_PROJECTED) switch (flags & ~D3DTTFF_PROJECTED) {
1486 case D3DTTFF_COUNT2:
1487 mat[3] = mat[1], mat[7] = mat[5], mat[11] = mat[9], mat[15] = mat[13];
1488 mat[1] = mat[5] = mat[9] = mat[13] = 0;
1490 case D3DTTFF_COUNT3:
1491 mat[3] = mat[2], mat[7] = mat[6], mat[11] = mat[10], mat[15] = mat[14];
1492 mat[2] = mat[6] = mat[10] = mat[14] = 0;
1496 checkGLcall("glLoadMatrixf(mat)");
1499 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand)
1501 BOOL isAlphaReplicate = FALSE;
1502 BOOL isComplement = FALSE;
1504 *operand = GL_SRC_COLOR;
1505 *source = GL_TEXTURE;
1507 /* Catch alpha replicate */
1508 if (iValue & D3DTA_ALPHAREPLICATE) {
1509 iValue = iValue & ~D3DTA_ALPHAREPLICATE;
1510 isAlphaReplicate = TRUE;
1513 /* Catch Complement */
1514 if (iValue & D3DTA_COMPLEMENT) {
1515 iValue = iValue & ~D3DTA_COMPLEMENT;
1516 isComplement = TRUE;
1519 /* Calculate the operand */
1520 if (isAlphaReplicate && !isComplement) {
1521 *operand = GL_SRC_ALPHA;
1522 } else if (isAlphaReplicate && isComplement) {
1523 *operand = GL_ONE_MINUS_SRC_ALPHA;
1524 } else if (isComplement) {
1526 *operand = GL_ONE_MINUS_SRC_ALPHA;
1528 *operand = GL_ONE_MINUS_SRC_COLOR;
1532 *operand = GL_SRC_ALPHA;
1534 *operand = GL_SRC_COLOR;
1538 /* Calculate the source */
1539 switch (iValue & D3DTA_SELECTMASK) {
1540 case D3DTA_CURRENT: *source = GL_PREVIOUS_EXT;
1542 case D3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT;
1544 case D3DTA_TEXTURE: *source = GL_TEXTURE;
1546 case D3DTA_TFACTOR: *source = GL_CONSTANT_EXT;
1548 case D3DTA_SPECULAR:
1550 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
1551 * 'Secondary color' and isn't supported until base GL supports it
1552 * There is no concept of temp registers as far as I can tell
1554 FIXME("Unhandled texture arg D3DTA_SPECULAR\n");
1555 *source = GL_TEXTURE;
1559 FIXME("Unrecognized texture arg %ld\n", iValue);
1560 *source = GL_TEXTURE;
1565 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
1566 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1569 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1571 case WINED3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
1572 case WINED3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1573 case WINED3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1575 /* stupid compiler */
1583 case WINED3DFMT_P8: retVal = GL_COLOR_INDEX8_EXT; break;
1584 case WINED3DFMT_A8P8: retVal = GL_COLOR_INDEX8_EXT; break;
1586 case WINED3DFMT_L8: retVal = GL_LUMINANCE8; break;
1587 case WINED3DFMT_A8L8: retVal = GL_LUMINANCE8_ALPHA8; break;
1588 case WINED3DFMT_A4L4: retVal = GL_LUMINANCE4_ALPHA4; break;
1590 case WINED3DFMT_V8U8: retVal = GL_COLOR_INDEX8_EXT; break;
1591 case WINED3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
1592 case WINED3DFMT_L6V5U5: retVal = GL_COLOR_INDEX8_EXT; break;
1593 case WINED3DFMT_X8L8V8U8: retVal = GL_RGBA8; break;
1594 case WINED3DFMT_Q8W8V8U8: retVal = GL_RGBA8; break; /* almost but not quite... */
1595 case WINED3DFMT_Q16W16V16U16: retVal = GL_COLOR_INDEX; break; /* almost but not quite... */
1597 case WINED3DFMT_R3G3B2: retVal = GL_R3_G3_B2; break;
1598 case WINED3DFMT_R5G6B5: retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
1599 case WINED3DFMT_R8G8B8: retVal = GL_RGB8; break;
1600 case WINED3DFMT_A1R5G5B5: retVal = GL_RGB5_A1; break;
1601 case WINED3DFMT_X1R5G5B5: retVal = GL_RGB5_A1; break;
1602 case WINED3DFMT_A4R4G4B4: retVal = GL_RGBA4; break;
1603 case WINED3DFMT_X4R4G4B4: retVal = GL_RGB4; break;
1604 case WINED3DFMT_A8R8G8B8: retVal = GL_RGBA8; break;
1605 case WINED3DFMT_X8R8G8B8: retVal = GL_RGB; break;
1607 case WINED3DFMT_A8: retVal = GL_ALPHA8; break;
1609 /* Depth + Stencil NOTE: OpenGL doesn't support depth-stencil surfaces so the formats are the closes bits match for the data */
1610 case WINED3DFMT_D24S8: retVal = GL_COLOR_INDEX; break;
1611 case WINED3DFMT_D24X8: retVal = GL_COLOR_INDEX; break;
1612 case WINED3DFMT_D24X4S4: retVal = GL_COLOR_INDEX; break;
1613 case WINED3DFMT_D32: retVal = GL_COLOR_INDEX; break;
1614 case WINED3DFMT_D16: retVal = GL_COLOR_INDEX; break;
1615 case WINED3DFMT_D15S1: retVal = GL_COLOR_INDEX; break;
1616 case WINED3DFMT_D16_LOCKABLE: retVal = GL_COLOR_INDEX; break;
1619 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1623 TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1627 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1630 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1632 case WINED3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
1633 case WINED3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1634 case WINED3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1636 /* stupid compiler */
1644 case WINED3DFMT_P8: retVal = GL_COLOR_INDEX; break;
1645 case WINED3DFMT_A8P8: retVal = GL_COLOR_INDEX; break;
1647 case WINED3DFMT_L8: retVal = GL_LUMINANCE; break;
1648 case WINED3DFMT_A8L8: retVal = GL_LUMINANCE_ALPHA; break;
1649 case WINED3DFMT_A4L4: retVal = GL_LUMINANCE_ALPHA; break;
1651 case WINED3DFMT_V8U8: retVal = GL_COLOR_INDEX; break;
1652 case WINED3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
1653 case WINED3DFMT_L6V5U5: retVal = GL_COLOR_INDEX; break;
1654 case WINED3DFMT_X8L8V8U8: retVal = GL_BGRA; break;
1655 case WINED3DFMT_Q8W8V8U8: retVal = GL_RGBA; break;
1656 case WINED3DFMT_Q16W16V16U16: retVal = GL_COLOR_INDEX; break;
1658 case WINED3DFMT_R3G3B2: retVal = GL_BGR; break;
1659 case WINED3DFMT_R5G6B5: retVal = GL_BGR; break;
1660 case WINED3DFMT_R8G8B8: retVal = GL_BGR; break;
1661 case WINED3DFMT_A1R5G5B5: retVal = GL_BGRA; break;
1662 case WINED3DFMT_X1R5G5B5: retVal = GL_BGRA; break;
1663 case WINED3DFMT_A4R4G4B4: retVal = GL_BGRA; break;
1664 case WINED3DFMT_X4R4G4B4: retVal = GL_BGRA; break;
1665 case WINED3DFMT_A8R8G8B8: retVal = GL_BGRA; break;
1666 case WINED3DFMT_X8R8G8B8: retVal = GL_BGRA; break;
1668 case WINED3DFMT_A8: retVal = GL_ALPHA; break;
1669 /* Depth + Stencil */
1670 case WINED3DFMT_D24S8: retVal = GL_COLOR_INDEX; break;
1671 case WINED3DFMT_D24X8: retVal = GL_COLOR_INDEX; break;
1672 case WINED3DFMT_D24X4S4: retVal = GL_COLOR_INDEX; break;
1673 case WINED3DFMT_D32: retVal = GL_COLOR_INDEX; break;
1674 case WINED3DFMT_D16: retVal = GL_COLOR_INDEX; break;
1675 case WINED3DFMT_D15S1: retVal = GL_COLOR_INDEX; break;
1676 case WINED3DFMT_D16_LOCKABLE: retVal = GL_COLOR_INDEX; break;
1678 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1683 TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1687 GLenum D3DFmt2GLType(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1690 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1692 case WINED3DFMT_DXT1: retVal = 0; break;
1693 case WINED3DFMT_DXT3: retVal = 0; break;
1694 case WINED3DFMT_DXT5: retVal = 0; break;
1696 /* stupid compiler */
1704 case WINED3DFMT_P8: retVal = GL_UNSIGNED_BYTE; break;
1705 case WINED3DFMT_A8P8: retVal = GL_UNSIGNED_BYTE; break;
1707 case WINED3DFMT_L8: retVal = GL_UNSIGNED_BYTE; break;
1708 case WINED3DFMT_A8L8: retVal = GL_UNSIGNED_BYTE; break;
1709 case WINED3DFMT_A4L4: retVal = GL_UNSIGNED_BYTE; break;
1711 case WINED3DFMT_V8U8: retVal = GL_UNSIGNED_BYTE; break;
1712 case WINED3DFMT_V16U16: retVal = GL_UNSIGNED_SHORT; break;
1713 case WINED3DFMT_L6V5U5: retVal = GL_UNSIGNED_SHORT_5_5_5_1; break;
1714 case WINED3DFMT_X8L8V8U8: retVal = GL_UNSIGNED_BYTE; break;
1716 case WINED3DFMT_R3G3B2: retVal = GL_UNSIGNED_BYTE_2_3_3_REV; break;
1717 case WINED3DFMT_R5G6B5: retVal = GL_UNSIGNED_SHORT_5_6_5; break;
1718 case WINED3DFMT_R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
1719 case WINED3DFMT_A1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
1720 case WINED3DFMT_X1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
1721 case WINED3DFMT_A4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
1722 case WINED3DFMT_X4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
1723 case WINED3DFMT_A8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
1724 case WINED3DFMT_X8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
1726 case WINED3DFMT_A8: retVal = GL_ALPHA; break;
1727 /* Depth + Stencil */
1728 case WINED3DFMT_D24S8: retVal = GL_UNSIGNED_INT; break;
1729 case WINED3DFMT_D24X8: retVal = GL_UNSIGNED_INT; break;
1730 case WINED3DFMT_D24X4S4: retVal = GL_UNSIGNED_INT; break;
1731 case WINED3DFMT_D32: retVal = GL_UNSIGNED_INT; break;
1732 case WINED3DFMT_D16: retVal = GL_UNSIGNED_SHORT; break;
1733 case WINED3DFMT_D15S1: retVal = GL_UNSIGNED_SHORT; break;
1734 case WINED3DFMT_D16_LOCKABLE: retVal = GL_UNSIGNED_SHORT; break;
1735 /* compressed textures */
1736 case WINED3DFMT_DXT1: retVal = 0; break;
1737 case WINED3DFMT_DXT3: retVal = 0; break;
1738 case WINED3DFMT_DXT5: retVal = 0; break;
1741 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1742 retVal = GL_UNSIGNED_BYTE;
1746 TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1750 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1755 case WINED3DFMT_R3G3B2: retVal = 1; break;
1756 case WINED3DFMT_R5G6B5: retVal = 2; break;
1757 case WINED3DFMT_R8G8B8: retVal = 3; break;
1758 case WINED3DFMT_A1R5G5B5: retVal = 2; break;
1759 case WINED3DFMT_X1R5G5B5: retVal = 2; break;
1760 case WINED3DFMT_A4R4G4B4: retVal = 2; break;
1761 case WINED3DFMT_X4R4G4B4: retVal = 2; break;
1762 case WINED3DFMT_A8R8G8B8: retVal = 4; break;
1763 case WINED3DFMT_X8R8G8B8: retVal = 4; break;
1765 case WINED3DFMT_P8: retVal = 1; break;
1766 case WINED3DFMT_A8P8: retVal = 2; break;
1767 /* depth/stencil buffer */
1768 case WINED3DFMT_D16_LOCKABLE: retVal = 2; break;
1769 case WINED3DFMT_D16: retVal = 2; break;
1770 case WINED3DFMT_D32: retVal = 4; break;
1771 case WINED3DFMT_D15S1: retVal = 2; break;
1772 case WINED3DFMT_D24X4S4: retVal = 4; break;
1773 case WINED3DFMT_D24S8: retVal = 4; break;
1774 case WINED3DFMT_D24X8: retVal = 4; break;
1776 case WINED3DFMT_L8: retVal = 1; break;
1777 case WINED3DFMT_A4L4: retVal = 1; break;
1778 case WINED3DFMT_A8L8: retVal = 2; break;
1780 case WINED3DFMT_V8U8: retVal = 2; break;
1781 case WINED3DFMT_L6V5U5: retVal = 2; break;
1782 case WINED3DFMT_V16U16: retVal = 4; break;
1783 case WINED3DFMT_X8L8V8U8: retVal = 4; break;
1784 case WINED3DFMT_Q8W8V8U8: retVal = 4; break;
1785 case WINED3DFMT_Q16W16V16U16: retVal = 8; break;
1787 case WINED3DFMT_DXT1: retVal = 1; break; /* Actually 8 bytes per 16 pixels - Special cased later */
1788 case WINED3DFMT_DXT3: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1789 case WINED3DFMT_DXT5: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1791 case WINED3DFMT_A8: retVal = 1; break;
1793 case WINED3DFMT_UNKNOWN:
1794 /* Guess at the highest value of the above */
1795 TRACE("WINED3DFMT_UNKNOWN - Guessing at 4 bytes/pixel %u\n", fmt);
1800 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1803 TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
1807 /* Convertes a D3D format into a OpenGL configuration format */
1808 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate){
1809 #define PUSH1(att) attribs[(*nAttribs)++] = (att);
1810 #define PUSH2(att,value) attribs[(*nAttribs)++] = (att); attribs[(*nAttribs)++] = (value);
1811 /*We need to do some Card specific stuff in here at some point,
1812 D3D now support floating point format buffers, and their are a number of different OpelGl ways on managing thease e.g.
1813 GLX_ATI_pixel_format_float
1815 switch (BackBufferFormat) {
1818 PUSH2(GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT);
1819 PUSH2(GLX_BUFFER_SIZE, 8);
1820 PUSH2(GLX_DOUBLEBUFFER, TRUE);
1823 case WINED3DFMT_R3G3B2:
1824 PUSH2(GLX_RENDER_TYPE, GLX_RGBA_BIT);
1825 PUSH2(GLX_RED_SIZE, 3);
1826 PUSH2(GLX_GREEN_SIZE, 3);
1827 PUSH2(GLX_BLUE_SIZE, 2);
1830 case WINED3DFMT_A1R5G5B5:
1831 PUSH2(GLX_ALPHA_SIZE, 1);
1832 case WINED3DFMT_X1R5G5B5:
1833 PUSH2(GLX_RED_SIZE, 5);
1834 PUSH2(GLX_GREEN_SIZE, 5);
1835 PUSH2(GLX_BLUE_SIZE, 5);
1838 case WINED3DFMT_R5G6B5:
1839 PUSH2(GLX_RED_SIZE, 5);
1840 PUSH2(GLX_GREEN_SIZE, 6);
1841 PUSH2(GLX_BLUE_SIZE, 5);
1844 case WINED3DFMT_A4R4G4B4:
1845 PUSH2(GLX_ALPHA_SIZE, 4);
1846 case WINED3DFMT_X4R4G4B4:
1847 PUSH2(GLX_RED_SIZE, 4);
1848 PUSH2(GLX_GREEN_SIZE, 4);
1849 PUSH2(GLX_BLUE_SIZE, 4);
1852 case WINED3DFMT_A8R8G8B8:
1853 PUSH2(GLX_ALPHA_SIZE, 8);
1854 case WINED3DFMT_R8G8B8:
1855 case WINED3DFMT_X8R8G8B8:
1856 PUSH2(GLX_RED_SIZE, 8);
1857 PUSH2(GLX_GREEN_SIZE, 8);
1858 PUSH2(GLX_BLUE_SIZE, 8);
1865 switch (StencilBufferFormat) {
1866 case WINED3DFMT_D16_LOCKABLE:
1867 case WINED3DFMT_D16:
1868 PUSH2(GLX_DEPTH_SIZE, 16);
1871 case WINED3DFMT_D15S1:
1872 PUSH2(GLX_DEPTH_SIZE, 15);
1873 PUSH2(GLX_STENCIL_SIZE, 1);
1874 /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
1875 e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
1878 case WINED3DFMT_D24X8:
1879 PUSH2(GLX_DEPTH_SIZE, 24);
1882 case WINED3DFMT_D24X4S4:
1883 PUSH2(GLX_DEPTH_SIZE, 24);
1884 PUSH2(GLX_STENCIL_SIZE, 4);
1887 case WINED3DFMT_D24S8:
1888 PUSH2(GLX_DEPTH_SIZE, 24);
1889 PUSH2(GLX_STENCIL_SIZE, 8);
1892 case WINED3DFMT_D32:
1893 PUSH2(GLX_DEPTH_SIZE, 32);
1900 } else { /* it the device doesn't support the 'exact' format, try to find something close */
1901 switch (StencilBufferFormat) {
1902 case WINED3DFMT_D16_LOCKABLE:
1903 case WINED3DFMT_D16:
1904 PUSH2(GLX_DEPTH_SIZE, 1);
1907 case WINED3DFMT_D15S1:
1908 PUSH2(GLX_DEPTH_SIZE, 1);
1909 PUSH2(GLX_STENCIL_SIZE, 1);
1910 /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
1911 e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
1914 case WINED3DFMT_D24X8:
1915 PUSH2(GLX_DEPTH_SIZE, 1);
1918 case WINED3DFMT_D24X4S4:
1919 PUSH2(GLX_DEPTH_SIZE, 1);
1920 PUSH2(GLX_STENCIL_SIZE, 1);
1923 case WINED3DFMT_D24S8:
1924 PUSH2(GLX_DEPTH_SIZE, 1);
1925 PUSH2(GLX_STENCIL_SIZE, 1);
1928 case WINED3DFMT_D32:
1929 PUSH2(GLX_DEPTH_SIZE, 1);
1940 #undef GLINFO_LOCATION