Correct a few formats that were incorrect.
[wine] / dlls / wined3d / utils.c
1 /*
2  * Utility functions for the WineD3D Library
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  * Copyright 2003-2004 Raphael Junqueira
6  * Copyright 2004 Christian Costa
7  * Copyright 2005 Oliver Stieber
8  *
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.
13  *
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.
18  *
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
22  */
23
24 #include "config.h"
25 #include "wined3d_private.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
28
29 /*****************************************************************************
30  * Trace formatting of useful values
31  */
32 const char* debug_d3dformat(WINED3DFORMAT fmt) {
33   switch (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);
87 #undef FMT_TO_STR
88   default:
89     FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
90     return "unrecognized";
91   }
92 }
93
94 const char* debug_d3ddevicetype(D3DDEVTYPE devtype) {
95   switch (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
101   default:
102     FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
103     return "unrecognized";
104   }
105 }
106
107 const char* debug_d3dusage(DWORD usage) {
108   switch (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";
121   default:
122     FIXME("Unrecognized %lu Usage!\n", usage);
123     return "unrecognized";
124   }
125 }
126
127 const char* debug_d3dresourcetype(D3DRESOURCETYPE res) {
128   switch (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);
137 #undef  RES_TO_STR
138   default:
139     FIXME("Unrecognized %u D3DRESOURCETYPE!\n", res);
140     return "unrecognized";
141   }
142 }
143
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);
153 #undef  PRIM_TO_STR
154   default:
155     FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
156     return "unrecognized";
157   }
158 }
159
160 const char* debug_d3drenderstate(DWORD state) {
161   switch (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
240   default:
241     FIXME("Unrecognized %lu render state!\n", state);
242     return "unrecognized";
243   }
244 }
245
246 const char* debug_d3dsamplerstate(DWORD state) {
247   switch (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
263   default:
264     FIXME("Unrecognized %lu sampler state!\n", state);
265     return "unrecognized";
266   }
267 }
268
269 const char* debug_d3dtexturestate(DWORD state) {
270   switch (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
292   case 12:
293     /* Note D3DTSS are not consecutive, so skip these */
294     return "unused";
295     break;
296   default:
297     FIXME("Unrecognized %lu texture state!\n", state);
298     return "unrecognized";
299   }
300 }
301
302 const char* debug_d3dpool(D3DPOOL Pool) {
303   switch (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);
309 #undef  POOL_TO_STR
310   default:
311     FIXME("Unrecognized %u D3DPOOL!\n", Pool);
312     return "unrecognized";
313   }
314 }
315 /*****************************************************************************
316  * Useful functions mapping GL <-> D3D values
317  */
318 GLenum StencilOp(DWORD op) {
319     switch(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;
328     default:
329         FIXME("Invalid stencil op %ld\n", op);
330         return GL_ALWAYS;
331     }
332 }
333
334 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
335 #if defined (GL_VERSION_1_3)
336 # define useext(A) A
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
344 #else
345 # undef combine_ext
346 #endif
347
348 #if !defined(combine_ext)
349 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
350 {
351         FIXME("Requires opengl combine extensions to work\n");
352         return;
353 }
354 #else
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)
357 {
358 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
359         GLenum src1, src2, src3;
360         GLenum opr1, opr2, opr3;
361         GLenum comb_target;
362         GLenum src0_target, src1_target, src2_target;
363         GLenum opr0_target, opr1_target, opr2_target;
364         GLenum scal_target;
365         GLenum opr=0, invopr, src3_target, opr3_target;
366         BOOL Handled = FALSE;
367         IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
368
369         TRACE("Alpha?(%d), Stage:%d Op(%d), a1(%ld), a2(%ld), a3(%ld)\n", isAlpha, Stage, op, arg1, arg2, arg3);
370
371         ENTER_GL();
372
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.
378
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                               */
383
384         if (isAlpha) {
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;
393         }
394         else {
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);
403         }
404
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);
411         } else {
412             GetSrcAndOpFromValue(arg1, isAlpha, &src1, &opr1);
413         }
414         GetSrcAndOpFromValue(arg2, isAlpha, &src2, &opr2);
415         GetSrcAndOpFromValue(arg3, isAlpha, &src3, &opr3);
416
417         TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
418
419         Handled = TRUE; /* Assume will be handled */
420
421         /* Other texture operations require special extensions: */
422         if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
423           if (isAlpha) {
424             opr = GL_SRC_ALPHA;
425             invopr = GL_ONE_MINUS_SRC_ALPHA;
426             src3_target = GL_SOURCE3_ALPHA_NV;
427             opr3_target = GL_OPERAND3_ALPHA_NV;
428           } else {
429             opr = GL_SRC_COLOR;
430             invopr = GL_ONE_MINUS_SRC_COLOR;
431             src3_target = GL_SOURCE3_RGB_NV;
432             opr3_target = GL_OPERAND3_RGB_NV;
433           }
434           switch (op) {
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");
454             break;
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");
464             } else {
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");
469             }
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");
482             break;
483
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");
505             break;
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");
527             break;
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");
549             break;
550
551           case D3DTOP_ADD:
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");
572             break;
573
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");
595             break;
596
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");
618             break;
619
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");
637             switch (opr1) {
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;
642             }
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");
647             break;
648
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");
670             break;
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");
692             break;
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");
714             break;
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");
736             break;
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");
754             switch (opr) {
755             case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
756             case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
757             }
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");
762             break;
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");
776             switch (opr1) {
777             case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
778             case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
779             }
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");
788             break;
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");
806             switch (opr1) {
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;
811             }
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");
816             break;
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");
822             switch (opr1) {
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;
827             }
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");
836             switch (opr1) {
837             case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
838             case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
839             }
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");
848             break;
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");
870             break;
871
872           case D3DTOP_BUMPENVMAP:
873             {
874               if (GL_SUPPORT(NV_TEXTURE_SHADER)) {
875                 /*
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
880                 */
881                 float m[2][2];
882
883                 union {
884                   float f;
885                   DWORD d;
886                 } tmpvalue;
887
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;
896
897                 /*FIXME("Stage %d matrix is (%.2f,%.2f),(%.2f,%.2f)\n", Stage, m[0][0], m[0][1], m[1][0], m[1][0]);*/
898
899                 if (FALSE == This->texture_shader_active) {
900                   This->texture_shader_active = TRUE;
901                   glEnable(GL_TEXTURE_SHADER_NV);
902                 }
903
904                 /*
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);
926                 */
927                 /*
928                 int i;
929                 for (i = 0; i < Stage; i++) {
930                   if (GL_SUPPORT(ARB_MULTITEXTURE)) {
931                     GL_ACTIVETEXTURE(i);
932                     glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
933                     checkGLcall("Activate texture..");
934                   } else if (i>0) {
935                     FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
936                   }
937                 }
938                 */
939                 /*
940                   GL_ACTIVETEXTURE(Stage - 1);
941                   glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
942                 */
943                 /*
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");
952                 */
953                 LEAVE_GL();
954                 return;
955                 break;
956               }
957             }
958
959           case D3DTOP_BUMPENVMAPLUMINANCE:
960
961           default:
962             Handled = FALSE;
963           }
964           if (Handled) {
965             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
966             checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
967
968             LEAVE_GL();
969             return;
970           }
971         } /* GL_NV_texture_env_combine4 */
972
973         Handled = TRUE; /* Again, assume handled */
974         switch (op) {
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");
984                 break;
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");
994                 break;
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");
1004                 break;
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");
1018                 break;
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");
1032                 break;
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");
1046                 break;
1047         case D3DTOP_ADD:
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");
1060                 break;
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");
1074                 break;
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");
1088                 break;
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");
1103           } else {
1104                 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1105           }
1106           break;
1107
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");
1125                 break;
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");
1143                 break;
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");
1161                 break;
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");
1179                 break;
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");
1187                 } else {
1188                   FIXME("This version of opengl does not support GL_DOT3\n");
1189                 }
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");
1200                 break;
1201         case D3DTOP_LERP:
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");
1218                 break;
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");
1225                   switch (opr1) {
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;
1230                   }
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");
1243                 } else
1244                   Handled = FALSE;
1245                 break;
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");
1264                 } else
1265                   Handled = FALSE;
1266                 break;
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");
1273                   switch (opr1) {
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;
1278                   }
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");
1291                 } else
1292                   Handled = FALSE;
1293                 break;
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");
1304                   switch (opr1) {
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;
1309                   }
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");
1318                 } else
1319                   Handled = FALSE;
1320                 break;
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");
1327                   switch (opr1) {
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;
1332                   }
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");
1345                 } else
1346                   Handled = FALSE;
1347                 break;
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");
1354                   switch (opr1) {
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;
1359                   }
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");
1364                   switch (opr1) {
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;
1369                   }
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");
1378                 } else
1379                   Handled = FALSE;
1380                 break;
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");
1399                 } else
1400                   Handled = FALSE;
1401                 break;
1402         default:
1403                 Handled = FALSE;
1404         }
1405
1406         if (Handled) {
1407           BOOL  combineOK = TRUE;
1408           if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1409             DWORD op2;
1410
1411             if (isAlpha) {
1412               op2 = This->stateBlock->textureState[Stage][WINED3DTSS_COLOROP];
1413             } else {
1414               op2 = This->stateBlock->textureState[Stage][WINED3DTSS_ALPHAOP];
1415             }
1416
1417             /* Note: If COMBINE4 in effect can't go back to combine! */
1418             switch (op2) {
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 */
1427               switch (op) {
1428               case D3DTOP_SELECTARG1:
1429               case D3DTOP_SELECTARG2:
1430                 combineOK = FALSE;
1431                 Handled   = FALSE;
1432                 break;
1433               default:
1434                 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%d, otherop=%ld, isAlpha(%d)\n", op, op2, isAlpha);
1435                 LEAVE_GL();
1436                 return;
1437               }
1438             }
1439           }
1440
1441           if (combineOK) {
1442             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
1443             checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
1444
1445             LEAVE_GL();
1446             return;
1447           }
1448         }
1449
1450         LEAVE_GL();
1451
1452         /* After all the extensions, if still unhandled, report fixme */
1453         FIXME("Unhandled texture operation %d\n", op);
1454         #undef GLINFO_LOCATION
1455 }
1456 #endif
1457
1458 /* Setup this textures matrix according to the texture flags*/
1459 void set_texture_matrix(const float *smat, DWORD flags)
1460 {
1461     float mat[16];
1462
1463     glMatrixMode(GL_TEXTURE);
1464
1465     if (flags == D3DTTFF_DISABLE) {
1466         glLoadIdentity();
1467         checkGLcall("glLoadIdentity()");
1468         return;
1469     }
1470
1471     if (flags == (D3DTTFF_COUNT1|D3DTTFF_PROJECTED)) {
1472         ERR("Invalid texture transform flags: D3DTTFF_COUNT1|D3DTTFF_PROJECTED\n");
1473         checkGLcall("glLoadIdentity()");
1474         return;
1475     }
1476
1477     memcpy(mat, smat, 16*sizeof(float));
1478
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;
1483     }
1484
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;
1489         break;
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;
1493         break;
1494     }
1495     glLoadMatrixf(mat);
1496     checkGLcall("glLoadMatrixf(mat)");
1497 }
1498
1499 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand)
1500 {
1501   BOOL isAlphaReplicate = FALSE;
1502   BOOL isComplement     = FALSE;
1503
1504   *operand = GL_SRC_COLOR;
1505   *source = GL_TEXTURE;
1506
1507   /* Catch alpha replicate */
1508   if (iValue & D3DTA_ALPHAREPLICATE) {
1509     iValue = iValue & ~D3DTA_ALPHAREPLICATE;
1510     isAlphaReplicate = TRUE;
1511   }
1512
1513   /* Catch Complement */
1514   if (iValue & D3DTA_COMPLEMENT) {
1515     iValue = iValue & ~D3DTA_COMPLEMENT;
1516     isComplement = TRUE;
1517   }
1518
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) {
1525     if (isAlphaArg) {
1526       *operand = GL_ONE_MINUS_SRC_ALPHA;
1527     } else {
1528       *operand = GL_ONE_MINUS_SRC_COLOR;
1529     }
1530   } else {
1531     if (isAlphaArg) {
1532       *operand = GL_SRC_ALPHA;
1533     } else {
1534       *operand = GL_SRC_COLOR;
1535     }
1536   }
1537
1538   /* Calculate the source */
1539   switch (iValue & D3DTA_SELECTMASK) {
1540   case D3DTA_CURRENT:   *source  = GL_PREVIOUS_EXT;
1541     break;
1542   case D3DTA_DIFFUSE:   *source  = GL_PRIMARY_COLOR_EXT;
1543     break;
1544   case D3DTA_TEXTURE:   *source  = GL_TEXTURE;
1545     break;
1546   case D3DTA_TFACTOR:   *source  = GL_CONSTANT_EXT;
1547     break;
1548   case D3DTA_SPECULAR:
1549     /*
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
1553      */
1554     FIXME("Unhandled texture arg D3DTA_SPECULAR\n");
1555     *source = GL_TEXTURE;
1556     break;
1557
1558   default:
1559     FIXME("Unrecognized texture arg %ld\n", iValue);
1560     *source = GL_TEXTURE;
1561   }
1562 }
1563
1564
1565 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
1566 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1567     GLint retVal = 0;
1568
1569     if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1570         switch (fmt) {
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;
1574         default:
1575             /* stupid compiler */
1576             break;
1577         }
1578     }
1579
1580     if (retVal == 0) {
1581         switch (fmt) {
1582             /* Paletted */
1583         case WINED3DFMT_P8:               retVal = GL_COLOR_INDEX8_EXT; break;
1584         case WINED3DFMT_A8P8:             retVal = GL_COLOR_INDEX8_EXT; break;
1585             /* Luminance */
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;
1589             /* Bump */
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... */
1596             /* color buffer */
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;
1606             /* to see */
1607         case WINED3DFMT_A8:               retVal = GL_ALPHA8; break;
1608
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;
1617
1618         default:
1619             FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1620             retVal = GL_RGB8;
1621         }
1622     }
1623     TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1624     return retVal;
1625 }
1626
1627 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1628     GLenum retVal = 0;
1629
1630     if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1631         switch (fmt) {
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;
1635         default:
1636             /* stupid compiler */
1637             break;
1638         }
1639     }
1640
1641     if (retVal == 0) {
1642         switch (fmt) {
1643         /* Paletted */
1644         case WINED3DFMT_P8:               retVal = GL_COLOR_INDEX; break;
1645         case WINED3DFMT_A8P8:             retVal = GL_COLOR_INDEX; break;
1646             /* Luminance */
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;
1650             /* Bump */
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;
1657             /* color buffer */
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;
1667             /* to see */
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;
1677         default:
1678             FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1679             retVal = GL_BGR;
1680         }
1681     }
1682
1683     TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1684     return retVal;
1685 }
1686
1687 GLenum D3DFmt2GLType(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1688     GLenum retVal = 0;
1689
1690     if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1691         switch (fmt) {
1692         case WINED3DFMT_DXT1:             retVal = 0; break;
1693         case WINED3DFMT_DXT3:             retVal = 0; break;
1694         case WINED3DFMT_DXT5:             retVal = 0; break;
1695         default:
1696             /* stupid compiler */
1697             break;
1698         }
1699     }
1700
1701     if (retVal == 0) {
1702         switch (fmt) {
1703         /* Paletted */
1704         case WINED3DFMT_P8:               retVal = GL_UNSIGNED_BYTE; break;
1705         case WINED3DFMT_A8P8:             retVal = GL_UNSIGNED_BYTE; break;
1706             /* Luminance */
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;
1710             /* Bump */
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;
1715             /* Color buffer */
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;
1725             /* to see */
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;
1739
1740         default:
1741             FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1742             retVal = GL_UNSIGNED_BYTE;
1743         }
1744     }
1745
1746     TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1747     return retVal;
1748 }
1749
1750 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1751     SHORT retVal;
1752
1753     switch (fmt) {
1754     /* color buffer */
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;
1764         /* Paletted */
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;
1775         /* Luminance */
1776     case WINED3DFMT_L8:               retVal = 1; break;
1777     case WINED3DFMT_A4L4:             retVal = 1; break;
1778     case WINED3DFMT_A8L8:             retVal = 2; break;
1779         /* Bump */
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;
1786         /* Compressed */
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 */
1790         /* to see */
1791     case WINED3DFMT_A8:               retVal = 1; break;
1792         /* unknown */
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);
1796         retVal = 4;
1797         break;
1798
1799     default:
1800         FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1801         retVal = 4;
1802     }
1803     TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
1804     return retVal;
1805 }
1806
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
1814     */
1815     switch (BackBufferFormat) {
1816         /* color buffer */
1817     case WINED3DFMT_P8:
1818         PUSH2(GLX_RENDER_TYPE,  GLX_COLOR_INDEX_BIT);
1819         PUSH2(GLX_BUFFER_SIZE,  8);
1820         PUSH2(GLX_DOUBLEBUFFER, TRUE);
1821         break;
1822
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);
1828         break;
1829
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);
1836         break;
1837
1838     case WINED3DFMT_R5G6B5:
1839         PUSH2(GLX_RED_SIZE,     5);
1840         PUSH2(GLX_GREEN_SIZE,   6);
1841         PUSH2(GLX_BLUE_SIZE,    5);
1842         break;
1843
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);
1850         break;
1851
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);
1859         break;
1860
1861     default:
1862         break;
1863     }
1864     if(!alternate){
1865         switch (StencilBufferFormat) {
1866     case WINED3DFMT_D16_LOCKABLE:
1867     case WINED3DFMT_D16:
1868         PUSH2(GLX_DEPTH_SIZE,   16);
1869         break;
1870
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*/
1876         break;
1877
1878     case WINED3DFMT_D24X8:
1879         PUSH2(GLX_DEPTH_SIZE,   24);
1880         break;
1881
1882     case WINED3DFMT_D24X4S4:
1883         PUSH2(GLX_DEPTH_SIZE,   24);
1884         PUSH2(GLX_STENCIL_SIZE, 4);
1885         break;
1886
1887     case WINED3DFMT_D24S8:
1888         PUSH2(GLX_DEPTH_SIZE,   24);
1889         PUSH2(GLX_STENCIL_SIZE, 8);
1890         break;
1891
1892     case WINED3DFMT_D32:
1893         PUSH2(GLX_DEPTH_SIZE,   32);
1894         break;
1895
1896     default:
1897         break;
1898     }
1899
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);
1905             break;
1906
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*/
1912             break;
1913
1914         case WINED3DFMT_D24X8:
1915             PUSH2(GLX_DEPTH_SIZE,   1);
1916             break;
1917
1918         case WINED3DFMT_D24X4S4:
1919             PUSH2(GLX_DEPTH_SIZE,   1);
1920             PUSH2(GLX_STENCIL_SIZE, 1);
1921             break;
1922
1923         case WINED3DFMT_D24S8:
1924             PUSH2(GLX_DEPTH_SIZE,   1);
1925             PUSH2(GLX_STENCIL_SIZE, 1);
1926             break;
1927
1928         case WINED3DFMT_D32:
1929             PUSH2(GLX_DEPTH_SIZE,   1);
1930             break;
1931
1932         default:
1933             break;
1934         }
1935     }
1936
1937     return *nAttribs;
1938 }
1939
1940 #undef GLINFO_LOCATION