When scrolling, first update the new position of the control before
[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_D24FS8);
77     FMT_TO_STR(WINED3DFMT_D24X8);
78     FMT_TO_STR(WINED3DFMT_D24X4S4);
79     FMT_TO_STR(WINED3DFMT_D16);
80     FMT_TO_STR(WINED3DFMT_D32F_LOCKABLE);
81     FMT_TO_STR(WINED3DFMT_VERTEXDATA);
82     FMT_TO_STR(WINED3DFMT_INDEX16);
83     FMT_TO_STR(WINED3DFMT_INDEX32);
84     FMT_TO_STR(WINED3DFMT_Q16W16V16U16);
85     FMT_TO_STR(WINED3DFMT_R16F);
86     FMT_TO_STR(WINED3DFMT_G16R16F);
87     FMT_TO_STR(WINED3DFMT_A16B16G16R16F);
88 #undef FMT_TO_STR
89   default:
90     FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
91     return "unrecognized";
92   }
93 }
94
95 const char* debug_d3ddevicetype(D3DDEVTYPE devtype) {
96   switch (devtype) {
97 #define DEVTYPE_TO_STR(dev) case dev: return #dev
98     DEVTYPE_TO_STR(D3DDEVTYPE_HAL);
99     DEVTYPE_TO_STR(D3DDEVTYPE_REF);
100     DEVTYPE_TO_STR(D3DDEVTYPE_SW);
101 #undef DEVTYPE_TO_STR
102   default:
103     FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
104     return "unrecognized";
105   }
106 }
107
108 const char* debug_d3dusage(DWORD usage) {
109   switch (usage) {
110 #define D3DUSAGE_TO_STR(u) case u: return #u
111     D3DUSAGE_TO_STR(D3DUSAGE_RENDERTARGET);
112     D3DUSAGE_TO_STR(D3DUSAGE_DEPTHSTENCIL);
113     D3DUSAGE_TO_STR(D3DUSAGE_WRITEONLY);
114     D3DUSAGE_TO_STR(D3DUSAGE_SOFTWAREPROCESSING);
115     D3DUSAGE_TO_STR(D3DUSAGE_DONOTCLIP);
116     D3DUSAGE_TO_STR(D3DUSAGE_POINTS);
117     D3DUSAGE_TO_STR(D3DUSAGE_RTPATCHES);
118     D3DUSAGE_TO_STR(D3DUSAGE_NPATCHES);
119     D3DUSAGE_TO_STR(D3DUSAGE_DYNAMIC);
120 #undef D3DUSAGE_TO_STR
121   case 0: return "none";
122   default:
123     FIXME("Unrecognized %lu Usage!\n", usage);
124     return "unrecognized";
125   }
126 }
127
128 const char* debug_d3dresourcetype(D3DRESOURCETYPE res) {
129   switch (res) {
130 #define RES_TO_STR(res) case res: return #res;
131     RES_TO_STR(D3DRTYPE_SURFACE);
132     RES_TO_STR(D3DRTYPE_VOLUME);
133     RES_TO_STR(D3DRTYPE_TEXTURE);
134     RES_TO_STR(D3DRTYPE_VOLUMETEXTURE);
135     RES_TO_STR(D3DRTYPE_CUBETEXTURE);
136     RES_TO_STR(D3DRTYPE_VERTEXBUFFER);
137     RES_TO_STR(D3DRTYPE_INDEXBUFFER);
138 #undef  RES_TO_STR
139   default:
140     FIXME("Unrecognized %u D3DRESOURCETYPE!\n", res);
141     return "unrecognized";
142   }
143 }
144
145 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType) {
146   switch (PrimitiveType) {
147 #define PRIM_TO_STR(prim) case prim: return #prim;
148     PRIM_TO_STR(D3DPT_POINTLIST);
149     PRIM_TO_STR(D3DPT_LINELIST);
150     PRIM_TO_STR(D3DPT_LINESTRIP);
151     PRIM_TO_STR(D3DPT_TRIANGLELIST);
152     PRIM_TO_STR(D3DPT_TRIANGLESTRIP);
153     PRIM_TO_STR(D3DPT_TRIANGLEFAN);
154 #undef  PRIM_TO_STR
155   default:
156     FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
157     return "unrecognized";
158   }
159 }
160
161 const char* debug_d3drenderstate(DWORD state) {
162   switch (state) {
163 #define D3DSTATE_TO_STR(u) case u: return #u
164     D3DSTATE_TO_STR(WINED3DRS_ZENABLE                   );
165     D3DSTATE_TO_STR(WINED3DRS_FILLMODE                  );
166     D3DSTATE_TO_STR(WINED3DRS_SHADEMODE                 );
167     D3DSTATE_TO_STR(WINED3DRS_LINEPATTERN               );
168     D3DSTATE_TO_STR(WINED3DRS_ZWRITEENABLE              );
169     D3DSTATE_TO_STR(WINED3DRS_ALPHATESTENABLE           );
170     D3DSTATE_TO_STR(WINED3DRS_LASTPIXEL                 );
171     D3DSTATE_TO_STR(WINED3DRS_SRCBLEND                  );
172     D3DSTATE_TO_STR(WINED3DRS_DESTBLEND                 );
173     D3DSTATE_TO_STR(WINED3DRS_CULLMODE                  );
174     D3DSTATE_TO_STR(WINED3DRS_ZFUNC                     );
175     D3DSTATE_TO_STR(WINED3DRS_ALPHAREF                  );
176     D3DSTATE_TO_STR(WINED3DRS_ALPHAFUNC                 );
177     D3DSTATE_TO_STR(WINED3DRS_DITHERENABLE              );
178     D3DSTATE_TO_STR(WINED3DRS_ALPHABLENDENABLE          );
179     D3DSTATE_TO_STR(WINED3DRS_FOGENABLE                 );
180     D3DSTATE_TO_STR(WINED3DRS_SPECULARENABLE            );
181     D3DSTATE_TO_STR(WINED3DRS_ZVISIBLE                  );
182     D3DSTATE_TO_STR(WINED3DRS_FOGCOLOR                  );
183     D3DSTATE_TO_STR(WINED3DRS_FOGTABLEMODE              );
184     D3DSTATE_TO_STR(WINED3DRS_FOGSTART                  );
185     D3DSTATE_TO_STR(WINED3DRS_FOGEND                    );
186     D3DSTATE_TO_STR(WINED3DRS_FOGDENSITY                );
187     D3DSTATE_TO_STR(WINED3DRS_EDGEANTIALIAS             );
188     D3DSTATE_TO_STR(WINED3DRS_ZBIAS                     );
189     D3DSTATE_TO_STR(WINED3DRS_RANGEFOGENABLE            );
190     D3DSTATE_TO_STR(WINED3DRS_STENCILENABLE             );
191     D3DSTATE_TO_STR(WINED3DRS_STENCILFAIL               );
192     D3DSTATE_TO_STR(WINED3DRS_STENCILZFAIL              );
193     D3DSTATE_TO_STR(WINED3DRS_STENCILPASS               );
194     D3DSTATE_TO_STR(WINED3DRS_STENCILFUNC               );
195     D3DSTATE_TO_STR(WINED3DRS_STENCILREF                );
196     D3DSTATE_TO_STR(WINED3DRS_STENCILMASK               );
197     D3DSTATE_TO_STR(WINED3DRS_STENCILWRITEMASK          );
198     D3DSTATE_TO_STR(WINED3DRS_TEXTUREFACTOR             );
199     D3DSTATE_TO_STR(WINED3DRS_WRAP0                     );
200     D3DSTATE_TO_STR(WINED3DRS_WRAP1                     );
201     D3DSTATE_TO_STR(WINED3DRS_WRAP2                     );
202     D3DSTATE_TO_STR(WINED3DRS_WRAP3                     );
203     D3DSTATE_TO_STR(WINED3DRS_WRAP4                     );
204     D3DSTATE_TO_STR(WINED3DRS_WRAP5                     );
205     D3DSTATE_TO_STR(WINED3DRS_WRAP6                     );
206     D3DSTATE_TO_STR(WINED3DRS_WRAP7                     );
207     D3DSTATE_TO_STR(WINED3DRS_CLIPPING                  );
208     D3DSTATE_TO_STR(WINED3DRS_LIGHTING                  );
209     D3DSTATE_TO_STR(WINED3DRS_AMBIENT                   );
210     D3DSTATE_TO_STR(WINED3DRS_FOGVERTEXMODE             );
211     D3DSTATE_TO_STR(WINED3DRS_COLORVERTEX               );
212     D3DSTATE_TO_STR(WINED3DRS_LOCALVIEWER               );
213     D3DSTATE_TO_STR(WINED3DRS_NORMALIZENORMALS          );
214     D3DSTATE_TO_STR(WINED3DRS_DIFFUSEMATERIALSOURCE     );
215     D3DSTATE_TO_STR(WINED3DRS_SPECULARMATERIALSOURCE    );
216     D3DSTATE_TO_STR(WINED3DRS_AMBIENTMATERIALSOURCE     );
217     D3DSTATE_TO_STR(WINED3DRS_EMISSIVEMATERIALSOURCE    );
218     D3DSTATE_TO_STR(WINED3DRS_VERTEXBLEND               );
219     D3DSTATE_TO_STR(WINED3DRS_CLIPPLANEENABLE           );
220     D3DSTATE_TO_STR(WINED3DRS_SOFTWAREVERTEXPROCESSING  );
221     D3DSTATE_TO_STR(WINED3DRS_POINTSIZE                 );
222     D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MIN             );
223     D3DSTATE_TO_STR(WINED3DRS_POINTSPRITEENABLE         );
224     D3DSTATE_TO_STR(WINED3DRS_POINTSCALEENABLE          );
225     D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_A              );
226     D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_B              );
227     D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_C              );
228     D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEANTIALIAS      );
229     D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEMASK           );
230     D3DSTATE_TO_STR(WINED3DRS_PATCHEDGESTYLE            );
231     D3DSTATE_TO_STR(WINED3DRS_PATCHSEGMENTS             );
232     D3DSTATE_TO_STR(WINED3DRS_DEBUGMONITORTOKEN         );
233     D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MAX             );
234     D3DSTATE_TO_STR(WINED3DRS_INDEXEDVERTEXBLENDENABLE  );
235     D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE          );
236     D3DSTATE_TO_STR(WINED3DRS_TWEENFACTOR               );
237     D3DSTATE_TO_STR(WINED3DRS_BLENDOP                   );
238     D3DSTATE_TO_STR(WINED3DRS_POSITIONDEGREE            );
239     D3DSTATE_TO_STR(WINED3DRS_NORMALDEGREE              );
240 #undef D3DSTATE_TO_STR
241   default:
242     FIXME("Unrecognized %lu render state!\n", state);
243     return "unrecognized";
244   }
245 }
246
247 const char* debug_d3dsamplerstate(DWORD state) {
248   switch (state) {
249 #define D3DSTATE_TO_STR(u) case u: return #u
250     D3DSTATE_TO_STR(WINED3DSAMP_BORDERCOLOR  );
251     D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSU     );
252     D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSV     );
253     D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSW     );
254     D3DSTATE_TO_STR(WINED3DSAMP_MAGFILTER    );
255     D3DSTATE_TO_STR(WINED3DSAMP_MINFILTER    );
256     D3DSTATE_TO_STR(WINED3DSAMP_MIPFILTER    );
257     D3DSTATE_TO_STR(WINED3DSAMP_MIPMAPLODBIAS);
258     D3DSTATE_TO_STR(WINED3DSAMP_MAXMIPLEVEL  );
259     D3DSTATE_TO_STR(WINED3DSAMP_MAXANISOTROPY);
260     D3DSTATE_TO_STR(WINED3DSAMP_SRGBTEXTURE  );
261     D3DSTATE_TO_STR(WINED3DSAMP_ELEMENTINDEX );
262     D3DSTATE_TO_STR(WINED3DSAMP_DMAPOFFSET   );
263 #undef D3DSTATE_TO_STR
264   default:
265     FIXME("Unrecognized %lu sampler state!\n", state);
266     return "unrecognized";
267   }
268 }
269
270 const char* debug_d3dtexturestate(DWORD state) {
271   switch (state) {
272 #define D3DSTATE_TO_STR(u) case u: return #u
273     D3DSTATE_TO_STR(WINED3DTSS_COLOROP               );
274     D3DSTATE_TO_STR(WINED3DTSS_COLORARG1             );
275     D3DSTATE_TO_STR(WINED3DTSS_COLORARG2             );
276     D3DSTATE_TO_STR(WINED3DTSS_ALPHAOP               );
277     D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG1             );
278     D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG2             );
279     D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT00          );
280     D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT01          );
281     D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT10          );
282     D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT11          );
283     D3DSTATE_TO_STR(WINED3DTSS_TEXCOORDINDEX         );
284     D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLSCALE         );
285     D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLOFFSET        );
286     D3DSTATE_TO_STR(WINED3DTSS_TEXTURETRANSFORMFLAGS );
287     D3DSTATE_TO_STR(WINED3DTSS_ADDRESSW              );
288     D3DSTATE_TO_STR(WINED3DTSS_COLORARG0             );
289     D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG0             );
290     D3DSTATE_TO_STR(WINED3DTSS_RESULTARG             );
291     D3DSTATE_TO_STR(WINED3DTSS_CONSTANT              );
292 #undef D3DSTATE_TO_STR
293   case 12:
294     /* Note D3DTSS are not consecutive, so skip these */
295     return "unused";
296     break;
297   default:
298     FIXME("Unrecognized %lu texture state!\n", state);
299     return "unrecognized";
300   }
301 }
302
303 const char* debug_d3dpool(D3DPOOL Pool) {
304   switch (Pool) {
305 #define POOL_TO_STR(p) case p: return #p;
306     POOL_TO_STR(D3DPOOL_DEFAULT);
307     POOL_TO_STR(D3DPOOL_MANAGED);
308     POOL_TO_STR(D3DPOOL_SYSTEMMEM);
309     POOL_TO_STR(D3DPOOL_SCRATCH);
310 #undef  POOL_TO_STR
311   default:
312     FIXME("Unrecognized %u D3DPOOL!\n", Pool);
313     return "unrecognized";
314   }
315 }
316 /*****************************************************************************
317  * Useful functions mapping GL <-> D3D values
318  */
319 GLenum StencilOp(DWORD op) {
320     switch(op) {
321     case D3DSTENCILOP_KEEP    : return GL_KEEP;
322     case D3DSTENCILOP_ZERO    : return GL_ZERO;
323     case D3DSTENCILOP_REPLACE : return GL_REPLACE;
324     case D3DSTENCILOP_INCRSAT : return GL_INCR;
325     case D3DSTENCILOP_DECRSAT : return GL_DECR;
326     case D3DSTENCILOP_INVERT  : return GL_INVERT;
327     case D3DSTENCILOP_INCR    : return GL_INCR_WRAP_EXT;
328     case D3DSTENCILOP_DECR    : return GL_DECR_WRAP_EXT;
329     default:
330         FIXME("Invalid stencil op %ld\n", op);
331         return GL_ALWAYS;
332     }
333 }
334
335 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
336 #if defined (GL_VERSION_1_3)
337 # define useext(A) A
338 # define combine_ext 1
339 #elif defined (GL_EXT_texture_env_combine)
340 # define useext(A) A##_EXT
341 # define combine_ext 1
342 #elif defined (GL_ARB_texture_env_combine)
343 # define useext(A) A##_ARB
344 # define combine_ext 1
345 #else
346 # undef combine_ext
347 #endif
348
349 #if !defined(combine_ext)
350 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
351 {
352         FIXME("Requires opengl combine extensions to work\n");
353         return;
354 }
355 #else
356 /* Setup the texture operations texture stage states */
357 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
358 {
359 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
360         GLenum src1, src2, src3;
361         GLenum opr1, opr2, opr3;
362         GLenum comb_target;
363         GLenum src0_target, src1_target, src2_target;
364         GLenum opr0_target, opr1_target, opr2_target;
365         GLenum scal_target;
366         GLenum opr=0, invopr, src3_target, opr3_target;
367         BOOL Handled = FALSE;
368         IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
369
370         TRACE("Alpha?(%d), Stage:%d Op(%d), a1(%ld), a2(%ld), a3(%ld)\n", isAlpha, Stage, op, arg1, arg2, arg3);
371
372         ENTER_GL();
373
374         /* Note: Operations usually involve two ars, src0 and src1 and are operations of
375            the form (a1 <operation> a2). However, some of the more complex operations
376            take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
377            in a third parameter called a0. Therefore these are operations of the form
378            a0 <operation> a1 <operation> a2, ie the new parameter goes to the front.
379
380            However, below we treat the new (a0) parameter as src2/opr2, so in the actual
381            functions below, expect their syntax to differ slightly to those listed in the
382            manuals, ie replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
383            This affects D3DTOP_MULTIPLYADD and D3DTOP_LERP                               */
384
385         if (isAlpha) {
386                 comb_target = useext(GL_COMBINE_ALPHA);
387                 src0_target = useext(GL_SOURCE0_ALPHA);
388                 src1_target = useext(GL_SOURCE1_ALPHA);
389                 src2_target = useext(GL_SOURCE2_ALPHA);
390                 opr0_target = useext(GL_OPERAND0_ALPHA);
391                 opr1_target = useext(GL_OPERAND1_ALPHA);
392                 opr2_target = useext(GL_OPERAND2_ALPHA);
393                 scal_target = GL_ALPHA_SCALE;
394         }
395         else {
396                 comb_target = useext(GL_COMBINE_RGB);
397                 src0_target = useext(GL_SOURCE0_RGB);
398                 src1_target = useext(GL_SOURCE1_RGB);
399                 src2_target = useext(GL_SOURCE2_RGB);
400                 opr0_target = useext(GL_OPERAND0_RGB);
401                 opr1_target = useext(GL_OPERAND1_RGB);
402                 opr2_target = useext(GL_OPERAND2_RGB);
403                 scal_target = useext(GL_RGB_SCALE);
404         }
405
406         /* From MSDN (WINED3DTSS_ALPHAARG1) :
407            The default argument is D3DTA_TEXTURE. If no texture is set for this stage,
408                    then the default argument is D3DTA_DIFFUSE.
409                    FIXME? If texture added/removed, may need to reset back as well?    */
410         if (isAlpha && This->stateBlock->textures[Stage] == NULL && arg1 == D3DTA_TEXTURE) {
411             GetSrcAndOpFromValue(D3DTA_DIFFUSE, isAlpha, &src1, &opr1);
412         } else {
413             GetSrcAndOpFromValue(arg1, isAlpha, &src1, &opr1);
414         }
415         GetSrcAndOpFromValue(arg2, isAlpha, &src2, &opr2);
416         GetSrcAndOpFromValue(arg3, isAlpha, &src3, &opr3);
417
418         TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
419
420         Handled = TRUE; /* Assume will be handled */
421
422         /* Other texture operations require special extensions: */
423         if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
424           if (isAlpha) {
425             opr = GL_SRC_ALPHA;
426             invopr = GL_ONE_MINUS_SRC_ALPHA;
427             src3_target = GL_SOURCE3_ALPHA_NV;
428             opr3_target = GL_OPERAND3_ALPHA_NV;
429           } else {
430             opr = GL_SRC_COLOR;
431             invopr = GL_ONE_MINUS_SRC_COLOR;
432             src3_target = GL_SOURCE3_RGB_NV;
433             opr3_target = GL_OPERAND3_RGB_NV;
434           }
435           switch (op) {
436           case D3DTOP_DISABLE: /* Only for alpha */
437             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
438             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
439             glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
440             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
441             glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
442             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
443             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
444             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
445             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
446             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
447             glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
448             checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
449             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
450             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
451             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
452             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
453             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
454             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
455             break;
456           case D3DTOP_SELECTARG1:                                          /* = a1 * 1 + 0 * 0 */
457           case D3DTOP_SELECTARG2:                                          /* = a2 * 1 + 0 * 0 */
458             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
459             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
460             if (op == D3DTOP_SELECTARG1) {
461               glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
462               checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
463               glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
464               checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
465             } else {
466               glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
467               checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
468               glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
469               checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
470             }
471             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
472             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
473             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
474             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
475             glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
476             checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
477             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
478             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
479             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
480             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
481             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
482             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
483             break;
484
485           case D3DTOP_MODULATE:
486             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
487             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
488             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
489             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
490             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
491             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
492             glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
493             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
494             glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
495             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
496             glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
497             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
498             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
499             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
500             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
501             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
502             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
503             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
504             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
505             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
506             break;
507           case D3DTOP_MODULATE2X:
508             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
509             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
510             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
511             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
512             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
513             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
514             glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
515             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
516             glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
517             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
518             glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
519             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
520             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
521             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
522             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
523             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
524             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
525             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
526             glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
527             checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
528             break;
529           case D3DTOP_MODULATE4X:
530             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
531             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
532             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
533             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
534             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
535             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
536             glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
537             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
538             glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
539             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
540             glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
541             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
542             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
543             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
544             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
545             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
546             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
547             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
548             glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
549             checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
550             break;
551
552           case D3DTOP_ADD:
553             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
554             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
555             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
556             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
557             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
558             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
559             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
560             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
561             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
562             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
563             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
564             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
565             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
566             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
567             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
568             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
569             glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
570             checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
571             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
572             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
573             break;
574
575           case D3DTOP_ADDSIGNED:
576             glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
577             checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
578             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
579             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
580             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
581             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
582             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
583             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
584             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
585             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
586             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
587             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
588             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
589             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
590             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
591             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
592             glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
593             checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
594             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
595             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
596             break;
597
598           case D3DTOP_ADDSIGNED2X:
599             glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
600             checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
601             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
602             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
603             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
604             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
605             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
606             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
607             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
608             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
609             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
610             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
611             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
612             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
613             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
614             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
615             glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
616             checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
617             glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
618             checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
619             break;
620
621           case D3DTOP_ADDSMOOTH:
622             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
623             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
624             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
625             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
626             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
627             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
628             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
629             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
630             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
631             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
632             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
633             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
634             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
635             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
636             glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
637             checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
638             switch (opr1) {
639             case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
640             case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
641             case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
642             case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
643             }
644             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
645             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
646             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
647             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
648             break;
649
650           case D3DTOP_BLENDDIFFUSEALPHA:
651             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
652             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
653             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
654             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
655             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
656             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
657             glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
658             checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
659             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
660             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
661             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
662             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
663             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
664             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
665             glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
666             checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
667             glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
668             checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
669             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
670             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
671             break;
672           case D3DTOP_BLENDTEXTUREALPHA:
673             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
674             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
675             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
676             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
677             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
678             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
679             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
680             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
681             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
682             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
683             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
684             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
685             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
686             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
687             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
688             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
689             glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
690             checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
691             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
692             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
693             break;
694           case D3DTOP_BLENDFACTORALPHA:
695             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
696             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
697             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
698             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
699             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
700             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
701             glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT));
702             checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
703             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
704             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
705             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
706             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
707             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
708             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
709             glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
710             checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
711             glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
712             checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
713             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
714             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
715             break;
716           case D3DTOP_BLENDTEXTUREALPHAPM:
717             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
718             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
719             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
720             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
721             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
722             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
723             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
724             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
725             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
726             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
727             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
728             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
729             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
730             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
731             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
732             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
733             glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
734             checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
735             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
736             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
737             break;
738           case D3DTOP_MODULATEALPHA_ADDCOLOR:
739             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
740             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");  /* Add = a0*a1 + a2*a3 */
741             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);        /*   a0 = src1/opr1    */
742             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
743             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
744             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");    /*   a1 = 1 (see docs) */
745             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
746             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
747             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
748             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
749             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);        /*   a2 = arg2         */
750             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
751             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
752             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");     /*  a3 = src1 alpha   */
753             glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
754             checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
755             switch (opr) {
756             case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
757             case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
758             }
759             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
760             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
761             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
762             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
763             break;
764           case D3DTOP_MODULATECOLOR_ADDALPHA:
765             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
766             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
767             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
768             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
769             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
770             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
771             glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
772             checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
773             glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
774             checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
775             glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
776             checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
777             switch (opr1) {
778             case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
779             case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
780             }
781             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
782             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
783             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
784             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
785             glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
786             checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
787             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
788             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
789             break;
790           case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
791             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
792             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
793             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
794             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
795             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
796             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
797             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
798             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
799             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
800             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
801             glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
802             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
803             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
804             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
805             glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
806             checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
807             switch (opr1) {
808             case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
809             case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
810             case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
811             case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
812             }
813             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
814             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
815             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
816             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
817             break;
818           case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
819             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
820             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
821             glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
822             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
823             switch (opr1) {
824             case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
825             case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
826             case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
827             case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
828             }
829             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
830             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
831             glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
832             checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
833             glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
834             checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
835             glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
836             checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
837             switch (opr1) {
838             case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
839             case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
840             }
841             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
842             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
843             glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
844             checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
845             glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
846             checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
847             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
848             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
849             break;
850           case D3DTOP_MULTIPLYADD:
851             glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
852             checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
853             glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
854             checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
855             glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
856             checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
857             glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
858             checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
859             glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
860             checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
861             glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
862             checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
863             glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
864             checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
865             glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
866             checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
867             glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
868             checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
869             glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
870             checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
871             break;
872
873           case D3DTOP_BUMPENVMAP:
874             {
875               if (GL_SUPPORT(NV_TEXTURE_SHADER)) {
876                 /*
877                   texture unit 0: GL_TEXTURE_2D
878                   texture unit 1: GL_DOT_PRODUCT_NV
879                   texture unit 2: GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV
880                   texture unit 3: GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV
881                 */
882                 float m[2][2];
883
884                 union {
885                   float f;
886                   DWORD d;
887                 } tmpvalue;
888
889                 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT00];
890                 m[0][0] = tmpvalue.f;
891                 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT01];
892                 m[0][1] = tmpvalue.f;
893                 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT10];
894                 m[1][0] = tmpvalue.f;
895                 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT11];
896                 m[1][1] = tmpvalue.f;
897
898                 /*FIXME("Stage %d matrix is (%.2f,%.2f),(%.2f,%.2f)\n", Stage, m[0][0], m[0][1], m[1][0], m[1][0]);*/
899
900                 if (FALSE == This->texture_shader_active) {
901                   This->texture_shader_active = TRUE;
902                   glEnable(GL_TEXTURE_SHADER_NV);
903                 }
904
905                 /*
906                 glEnable(GL_REGISTER_COMBINERS_NV);
907                 glCombinerParameteriNV (GL_NUM_GENERAL_COMBINERS_NV, 1);
908                 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
909                 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
910                 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
911                 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
912                 glCombinerOutputNV (GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
913                 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
914                 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
915                 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
916                 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
917                 glCombinerOutputNV (GL_COMBINER0_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
918                 glDisable (GL_PER_STAGE_CONSTANTS_NV);
919                 glCombinerParameteriNV (GL_COLOR_SUM_CLAMP_NV, 0);
920                 glFinalCombinerInputNV (GL_VARIABLE_A_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
921                 glFinalCombinerInputNV (GL_VARIABLE_B_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
922                 glFinalCombinerInputNV (GL_VARIABLE_C_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
923                 glFinalCombinerInputNV (GL_VARIABLE_D_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
924                 glFinalCombinerInputNV (GL_VARIABLE_E_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
925                 glFinalCombinerInputNV (GL_VARIABLE_F_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
926                 glFinalCombinerInputNV (GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
927                 */
928                 /*
929                 int i;
930                 for (i = 0; i < Stage; i++) {
931                   if (GL_SUPPORT(ARB_MULTITEXTURE)) {
932                     GL_ACTIVETEXTURE(i);
933                     glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
934                     checkGLcall("Activate texture..");
935                   } else if (i>0) {
936                     FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
937                   }
938                 }
939                 */
940                 /*
941                   GL_ACTIVETEXTURE(Stage - 1);
942                   glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
943                 */
944                 /*
945                 GL_ACTIVETEXTURE(Stage);
946                 checkGLcall("Activate texture.. to update const color");
947                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
948                 checkGLcall("glTexEnv");
949                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + Stage - 1);
950                 checkGLcall("glTexEnv");
951                 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float*)&m[0]);
952                 checkGLcall("glTexEnv");
953                 */
954                 LEAVE_GL();
955                 return;
956                 break;
957               }
958             }
959
960           case D3DTOP_BUMPENVMAPLUMINANCE:
961
962           default:
963             Handled = FALSE;
964           }
965           if (Handled) {
966             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
967             checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
968
969             LEAVE_GL();
970             return;
971           }
972         } /* GL_NV_texture_env_combine4 */
973
974         Handled = TRUE; /* Again, assume handled */
975         switch (op) {
976         case D3DTOP_DISABLE: /* Only for alpha */
977                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
978                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
979                 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
980                 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
981                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
982                 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
983                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
984                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
985                 break;
986         case D3DTOP_SELECTARG1:
987                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
988                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
989                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
990                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
991                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
992                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
993                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
994                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
995                 break;
996         case D3DTOP_SELECTARG2:
997                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
998                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
999                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
1000                 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1001                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1002                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1003                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1004                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1005                 break;
1006         case D3DTOP_MODULATE:
1007                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1008                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1009                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1010                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1011                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1012                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1013                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1014                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1015                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1016                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1017                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1018                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1019                 break;
1020         case D3DTOP_MODULATE2X:
1021                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1022                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1023                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1024                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1025                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1026                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1027                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1028                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1029                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1030                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1031                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1032                 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1033                 break;
1034         case D3DTOP_MODULATE4X:
1035                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1036                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1037                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1038                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1039                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1040                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1041                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1042                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1043                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1044                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1045                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1046                 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1047                 break;
1048         case D3DTOP_ADD:
1049                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1050                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1051                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1052                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1053                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1054                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1055                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1056                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1057                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1058                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1059                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1060                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1061                 break;
1062         case D3DTOP_ADDSIGNED:
1063                 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1064                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
1065                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1066                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1067                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1068                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1069                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1070                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1071                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1072                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1073                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1074                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1075                 break;
1076         case D3DTOP_ADDSIGNED2X:
1077                 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1078                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1079                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1080                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1081                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1082                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1083                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1084                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1085                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1086                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1087                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1088                 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1089                 break;
1090         case D3DTOP_SUBTRACT:
1091           if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
1092                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
1093                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
1094                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1095                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1096                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1097                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1098                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1099                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1100                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1101                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1102                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1103                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1104           } else {
1105                 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1106           }
1107           break;
1108
1109         case D3DTOP_BLENDDIFFUSEALPHA:
1110                 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1111                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1112                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1113                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1114                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1115                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1116                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1117                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1118                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1119                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1120                 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
1121                 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
1122                 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1123                 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1124                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1125                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1126                 break;
1127         case D3DTOP_BLENDTEXTUREALPHA:
1128                 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1129                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1130                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1131                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1132                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1133                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1134                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1135                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1136                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1137                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1138                 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
1139                 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
1140                 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1141                 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1142                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1143                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1144                 break;
1145         case D3DTOP_BLENDFACTORALPHA:
1146                 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1147                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1148                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1149                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1150                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1151                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1152                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1153                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1154                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1155                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1156                 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
1157                 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
1158                 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1159                 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1160                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1161                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1162                 break;
1163         case D3DTOP_BLENDCURRENTALPHA:
1164                 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1165                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1166                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1167                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1168                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1169                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1170                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1171                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1172                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1173                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1174                 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
1175                 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
1176                 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1177                 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1178                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1179                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1180                 break;
1181         case D3DTOP_DOTPRODUCT3:
1182                 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
1183                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
1184                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
1185                 } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
1186                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
1187                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
1188                 } else {
1189                   FIXME("This version of opengl does not support GL_DOT3\n");
1190                 }
1191                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1192                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1193                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1194                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1195                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1196                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1197                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1198                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1199                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1200                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1201                 break;
1202         case D3DTOP_LERP:
1203                 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1204                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1205                 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1206                 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1207                 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1208                 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1209                 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1210                 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1211                 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1212                 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1213                 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
1214                 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
1215                 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
1216                 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
1217                 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1218                 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1219                 break;
1220         case D3DTOP_ADDSMOOTH:
1221                 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1222                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1223                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1224                   glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1225                   checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1226                   switch (opr1) {
1227                   case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1228                   case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1229                   case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1230                   case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1231                   }
1232                   glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1233                   checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1234                   glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1235                   checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1236                   glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1237                   checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1238                   glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1239                   checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1240                   glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1241                   checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1242                   glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1243                   checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1244                 } else
1245                   Handled = FALSE;
1246                 break;
1247         case D3DTOP_BLENDTEXTUREALPHAPM:
1248                 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1249                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1250                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1251                   glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
1252                   checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
1253                   glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
1254                   checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
1255                   glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1256                   checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1257                   glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1258                   checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1259                   glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1260                   checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1261                   glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1262                   checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1263                   glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1264                   checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1265                 } else
1266                   Handled = FALSE;
1267                 break;
1268         case D3DTOP_MODULATEALPHA_ADDCOLOR:
1269                 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1270                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1271                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1272                   glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1273                   checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1274                   switch (opr1) {
1275                   case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1276                   case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1277                   case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1278                   case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1279                   }
1280                   glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1281                   checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1282                   glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1283                   checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1284                   glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1285                   checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1286                   glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1287                   checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1288                   glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1289                   checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1290                   glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1291                   checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1292                 } else
1293                   Handled = FALSE;
1294                 break;
1295         case D3DTOP_MODULATECOLOR_ADDALPHA:
1296                 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1297                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1298                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1299                   glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1300                   checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1301                   glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1302                   checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1303                   glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1304                   checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1305                   switch (opr1) {
1306                   case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1307                   case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1308                   case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1309                   case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1310                   }
1311                   glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1312                   checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1313                   glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1314                   checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1315                   glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1316                   checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1317                   glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1318                   checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1319                 } else
1320                   Handled = FALSE;
1321                 break;
1322         case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1323                 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1324                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1325                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1326                   glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1327                   checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1328                   switch (opr1) {
1329                   case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1330                   case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1331                   case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1332                   case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1333                   }
1334                   glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1335                   checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1336                   glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1337                   checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1338                   glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1339                   checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1340                   glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1341                   checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1342                   glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1343                   checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1344                   glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1345                   checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1346                 } else
1347                   Handled = FALSE;
1348                 break;
1349         case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1350                 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1351                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1352                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1353                   glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1354                   checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1355                   switch (opr1) {
1356                   case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1357                   case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1358                   case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1359                   case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1360                   }
1361                   glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1362                   checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1363                   glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1364                   checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1365                   switch (opr1) {
1366                   case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1367                   case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1368                   case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1369                   case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1370                   }
1371                   glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1372                   checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1373                   glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1374                   checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1375                   glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1376                   checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1377                   glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1378                   checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1379                 } else
1380                   Handled = FALSE;
1381                 break;
1382         case D3DTOP_MULTIPLYADD:
1383                 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1384                   glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1385                   checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1386                   glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1387                   checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
1388                   glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1389                   checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
1390                   glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1391                   checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1392                   glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1393                   checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1394                   glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1395                   checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1396                   glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1397                   checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1398                   glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1399                   checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1400                 } else
1401                   Handled = FALSE;
1402                 break;
1403         default:
1404                 Handled = FALSE;
1405         }
1406
1407         if (Handled) {
1408           BOOL  combineOK = TRUE;
1409           if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1410             DWORD op2;
1411
1412             if (isAlpha) {
1413               op2 = This->stateBlock->textureState[Stage][WINED3DTSS_COLOROP];
1414             } else {
1415               op2 = This->stateBlock->textureState[Stage][WINED3DTSS_ALPHAOP];
1416             }
1417
1418             /* Note: If COMBINE4 in effect can't go back to combine! */
1419             switch (op2) {
1420             case D3DTOP_ADDSMOOTH:
1421             case D3DTOP_BLENDTEXTUREALPHAPM:
1422             case D3DTOP_MODULATEALPHA_ADDCOLOR:
1423             case D3DTOP_MODULATECOLOR_ADDALPHA:
1424             case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1425             case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1426             case D3DTOP_MULTIPLYADD:
1427               /* Ignore those implemented in both cases */
1428               switch (op) {
1429               case D3DTOP_SELECTARG1:
1430               case D3DTOP_SELECTARG2:
1431                 combineOK = FALSE;
1432                 Handled   = FALSE;
1433                 break;
1434               default:
1435                 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%d, otherop=%ld, isAlpha(%d)\n", op, op2, isAlpha);
1436                 LEAVE_GL();
1437                 return;
1438               }
1439             }
1440           }
1441
1442           if (combineOK) {
1443             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
1444             checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
1445
1446             LEAVE_GL();
1447             return;
1448           }
1449         }
1450
1451         LEAVE_GL();
1452
1453         /* After all the extensions, if still unhandled, report fixme */
1454         FIXME("Unhandled texture operation %d\n", op);
1455         #undef GLINFO_LOCATION
1456 }
1457 #endif
1458
1459 /* Setup this textures matrix according to the texture flags*/
1460 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords)
1461 {
1462     float mat[16];
1463
1464     glMatrixMode(GL_TEXTURE);
1465     checkGLcall("glMatrixMode(GL_TEXTURE)");
1466
1467     if (flags == D3DTTFF_DISABLE) {
1468         glLoadIdentity();
1469         checkGLcall("glLoadIdentity()");
1470         return;
1471     }
1472
1473     if (flags == (D3DTTFF_COUNT1|D3DTTFF_PROJECTED)) {
1474         ERR("Invalid texture transform flags: D3DTTFF_COUNT1|D3DTTFF_PROJECTED\n");
1475         return;
1476     }
1477
1478     memcpy(mat, smat, 16 * sizeof(float));
1479
1480     switch (flags & ~D3DTTFF_PROJECTED) {
1481     case D3DTTFF_COUNT1: mat[1] = mat[5] = mat[13] = 0;
1482     case D3DTTFF_COUNT2: mat[2] = mat[6] = mat[10] = mat[14] = 0;
1483     default: mat[3] = mat[7] = mat[11] = 0, mat[15] = 1;
1484     }
1485
1486     if (flags & D3DTTFF_PROJECTED) {
1487         switch (flags & ~D3DTTFF_PROJECTED) {
1488         case D3DTTFF_COUNT2:
1489             mat[3] = mat[1], mat[7] = mat[5], mat[11] = mat[9], mat[15] = mat[13];
1490             mat[1] = mat[5] = mat[9] = mat[13] = 0;
1491             break;
1492         case D3DTTFF_COUNT3:
1493             mat[3] = mat[2], mat[7] = mat[6], mat[11] = mat[10], mat[15] = mat[14];
1494             mat[2] = mat[6] = mat[10] = mat[14] = 0;
1495             break;
1496         }
1497     } else if(!calculatedCoords) { /* under directx the R/Z coord can be used for translation, under opengl we use the Q coord instead */
1498         mat[12] = mat[8];
1499         mat[13] = mat[9];
1500     }
1501
1502     glLoadMatrixf(mat);
1503     checkGLcall("glLoadMatrixf(mat)");
1504 }
1505
1506 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand)
1507 {
1508   BOOL isAlphaReplicate = FALSE;
1509   BOOL isComplement     = FALSE;
1510
1511   *operand = GL_SRC_COLOR;
1512   *source = GL_TEXTURE;
1513
1514   /* Catch alpha replicate */
1515   if (iValue & D3DTA_ALPHAREPLICATE) {
1516     iValue = iValue & ~D3DTA_ALPHAREPLICATE;
1517     isAlphaReplicate = TRUE;
1518   }
1519
1520   /* Catch Complement */
1521   if (iValue & D3DTA_COMPLEMENT) {
1522     iValue = iValue & ~D3DTA_COMPLEMENT;
1523     isComplement = TRUE;
1524   }
1525
1526   /* Calculate the operand */
1527   if (isAlphaReplicate && !isComplement) {
1528     *operand = GL_SRC_ALPHA;
1529   } else if (isAlphaReplicate && isComplement) {
1530     *operand = GL_ONE_MINUS_SRC_ALPHA;
1531   } else if (isComplement) {
1532     if (isAlphaArg) {
1533       *operand = GL_ONE_MINUS_SRC_ALPHA;
1534     } else {
1535       *operand = GL_ONE_MINUS_SRC_COLOR;
1536     }
1537   } else {
1538     if (isAlphaArg) {
1539       *operand = GL_SRC_ALPHA;
1540     } else {
1541       *operand = GL_SRC_COLOR;
1542     }
1543   }
1544
1545   /* Calculate the source */
1546   switch (iValue & D3DTA_SELECTMASK) {
1547   case D3DTA_CURRENT:   *source  = GL_PREVIOUS_EXT;
1548     break;
1549   case D3DTA_DIFFUSE:   *source  = GL_PRIMARY_COLOR_EXT;
1550     break;
1551   case D3DTA_TEXTURE:   *source  = GL_TEXTURE;
1552     break;
1553   case D3DTA_TFACTOR:   *source  = GL_CONSTANT_EXT;
1554     break;
1555   case D3DTA_SPECULAR:
1556     /*
1557      * According to the GL_ARB_texture_env_combine specs, SPECULAR is
1558      * 'Secondary color' and isn't supported until base GL supports it
1559      * There is no concept of temp registers as far as I can tell
1560      */
1561     FIXME("Unhandled texture arg D3DTA_SPECULAR\n");
1562     *source = GL_TEXTURE;
1563     break;
1564
1565   default:
1566     FIXME("Unrecognized texture arg %ld\n", iValue);
1567     *source = GL_TEXTURE;
1568   }
1569 }
1570
1571
1572 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
1573 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1574     GLint retVal = 0;
1575
1576     if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1577         switch (fmt) {
1578         case WINED3DFMT_DXT1:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
1579         case WINED3DFMT_DXT2:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1580         case WINED3DFMT_DXT3:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1581         case WINED3DFMT_DXT4:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1582         case WINED3DFMT_DXT5:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1583         default:
1584             /* stupid compiler */
1585             break;
1586         }
1587     }
1588
1589     if (retVal == 0) {
1590         switch (fmt) {
1591             /* Paletted */
1592         case WINED3DFMT_P8:               retVal = GL_COLOR_INDEX8_EXT; break;
1593         case WINED3DFMT_A8P8:             retVal = GL_COLOR_INDEX8_EXT; break;
1594             /* Luminance */
1595         case WINED3DFMT_L8:               retVal = GL_LUMINANCE8; break;
1596         case WINED3DFMT_A8L8:             retVal = GL_LUMINANCE8_ALPHA8; break;
1597         case WINED3DFMT_A4L4:             retVal = GL_LUMINANCE4_ALPHA4; break;
1598             /* Bump */
1599         case WINED3DFMT_V8U8:             retVal = GL_COLOR_INDEX8_EXT; break;
1600         case WINED3DFMT_V16U16:           retVal = GL_COLOR_INDEX; break;
1601         case WINED3DFMT_L6V5U5:           retVal = GL_COLOR_INDEX8_EXT; break;
1602         case WINED3DFMT_X8L8V8U8:         retVal = GL_RGBA8; break;
1603         case WINED3DFMT_Q8W8V8U8:         retVal = GL_RGBA8; break; /* almost but not quite... */
1604         case WINED3DFMT_Q16W16V16U16:     retVal = GL_COLOR_INDEX; break; /* almost but not quite... */
1605             /* color buffer */
1606         case WINED3DFMT_R3G3B2:           retVal = GL_R3_G3_B2; break;
1607         case WINED3DFMT_R5G6B5:           retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
1608         case WINED3DFMT_R8G8B8:           retVal = GL_RGB8; break;
1609         case WINED3DFMT_A1R5G5B5:         retVal = GL_RGB5_A1; break;
1610         case WINED3DFMT_X1R5G5B5:         retVal = GL_RGB5_A1; break;
1611         case WINED3DFMT_A4R4G4B4:         retVal = GL_RGBA4; break;
1612         case WINED3DFMT_X4R4G4B4:         retVal = GL_RGB4; break;
1613         case WINED3DFMT_A8R8G8B8:         retVal = GL_RGBA8; break;
1614         case WINED3DFMT_A2R10G10B10:      retVal = GL_RGBA8; break;
1615         case WINED3DFMT_X8R8G8B8:         retVal = GL_RGB; break;
1616             /* to see */
1617         case WINED3DFMT_A8:               retVal = GL_ALPHA8; break;
1618
1619         /* Depth + Stencil NOTE: OpenGL doesn't support depth-stencil surfaces so the formats are the closes bits match for the data */
1620         case WINED3DFMT_D24S8:            retVal = GL_COLOR_INDEX; break;
1621         case WINED3DFMT_D24FS8:           retVal = GL_COLOR_INDEX; break;
1622         case WINED3DFMT_D24X8:            retVal = GL_COLOR_INDEX; break;
1623         case WINED3DFMT_D24X4S4:          retVal = GL_COLOR_INDEX; break;
1624         case WINED3DFMT_D32:              retVal = GL_COLOR_INDEX; break;
1625         case WINED3DFMT_D16:              retVal = GL_COLOR_INDEX; break;
1626         case WINED3DFMT_D15S1:            retVal = GL_COLOR_INDEX; break;
1627         case WINED3DFMT_D16_LOCKABLE:     retVal = GL_COLOR_INDEX; break;
1628
1629         default:
1630             FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1631             retVal = GL_RGB8;
1632         }
1633     }
1634     TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1635     return retVal;
1636 }
1637
1638 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1639     GLenum retVal = 0;
1640
1641     if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1642         switch (fmt) {
1643         case WINED3DFMT_DXT1:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
1644         case WINED3DFMT_DXT2:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1645         case WINED3DFMT_DXT3:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1646         case WINED3DFMT_DXT4:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1647         case WINED3DFMT_DXT5:             retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1648         default:
1649             /* stupid compiler */
1650             break;
1651         }
1652     }
1653
1654     if (retVal == 0) {
1655         switch (fmt) {
1656         /* Paletted */
1657         case WINED3DFMT_P8:               retVal = GL_COLOR_INDEX; break;
1658         case WINED3DFMT_A8P8:             retVal = GL_COLOR_INDEX; break;
1659             /* Luminance */
1660         case WINED3DFMT_L8:               retVal = GL_LUMINANCE; break;
1661         case WINED3DFMT_A8L8:             retVal = GL_LUMINANCE_ALPHA; break;
1662         case WINED3DFMT_A4L4:             retVal = GL_LUMINANCE_ALPHA; break;
1663             /* Bump */
1664         case WINED3DFMT_V8U8:             retVal = GL_COLOR_INDEX; break;
1665         case WINED3DFMT_V16U16:           retVal = GL_COLOR_INDEX; break;
1666         case WINED3DFMT_L6V5U5:           retVal = GL_COLOR_INDEX; break;
1667         case WINED3DFMT_X8L8V8U8:         retVal = GL_BGRA; break;
1668         case WINED3DFMT_Q8W8V8U8:         retVal = GL_RGBA; break;
1669         case WINED3DFMT_Q16W16V16U16:     retVal = GL_COLOR_INDEX; break;
1670             /* color buffer */
1671         case WINED3DFMT_R3G3B2:           retVal = GL_BGR; break;
1672         case WINED3DFMT_R5G6B5:           retVal = GL_BGR; break;
1673         case WINED3DFMT_R8G8B8:           retVal = GL_BGR; break;
1674         case WINED3DFMT_A1R5G5B5:         retVal = GL_BGRA; break;
1675         case WINED3DFMT_X1R5G5B5:         retVal = GL_BGRA; break;
1676         case WINED3DFMT_A4R4G4B4:         retVal = GL_BGRA; break;
1677         case WINED3DFMT_X4R4G4B4:         retVal = GL_BGRA; break;
1678         case WINED3DFMT_A8R8G8B8:         retVal = GL_BGRA; break;
1679         case WINED3DFMT_A2R10G10B10:      retVal = GL_BGRA; break;
1680         case WINED3DFMT_X8R8G8B8:         retVal = GL_BGRA; break;
1681             /* to see */
1682         case WINED3DFMT_A8:               retVal = GL_ALPHA; break;
1683             /* Depth + Stencil */
1684         case WINED3DFMT_D24S8:            retVal = GL_COLOR_INDEX; break;
1685         case WINED3DFMT_D24FS8:           retVal = GL_COLOR_INDEX; break;
1686         case WINED3DFMT_D24X8:            retVal = GL_COLOR_INDEX; break;
1687         case WINED3DFMT_D24X4S4:          retVal = GL_COLOR_INDEX; break;
1688         case WINED3DFMT_D32:              retVal = GL_COLOR_INDEX; break;
1689         case WINED3DFMT_D16:              retVal = GL_COLOR_INDEX; break;
1690         case WINED3DFMT_D15S1:            retVal = GL_COLOR_INDEX; break;
1691         case WINED3DFMT_D16_LOCKABLE:     retVal = GL_COLOR_INDEX; break;
1692         default:
1693             FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1694             retVal = GL_BGR;
1695         }
1696     }
1697
1698     TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1699     return retVal;
1700 }
1701
1702 GLenum D3DFmt2GLType(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1703     GLenum retVal = 0;
1704
1705     if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1706         switch (fmt) {
1707         case WINED3DFMT_DXT1:             retVal = 0; break;
1708         case WINED3DFMT_DXT2:             retVal = 0; break;
1709         case WINED3DFMT_DXT3:             retVal = 0; break;
1710         case WINED3DFMT_DXT4:             retVal = 0; break;
1711         case WINED3DFMT_DXT5:             retVal = 0; break;
1712         default:
1713             /* stupid compiler */
1714             break;
1715         }
1716     }
1717
1718     if (retVal == 0) {
1719         switch (fmt) {
1720         /* Paletted */
1721         case WINED3DFMT_P8:               retVal = GL_UNSIGNED_BYTE; break;
1722         case WINED3DFMT_A8P8:             retVal = GL_UNSIGNED_BYTE; break;
1723             /* Luminance */
1724         case WINED3DFMT_L8:               retVal = GL_UNSIGNED_BYTE; break;
1725         case WINED3DFMT_A8L8:             retVal = GL_UNSIGNED_BYTE; break;
1726         case WINED3DFMT_A4L4:             retVal = GL_UNSIGNED_BYTE; break;
1727             /* Bump */
1728         case WINED3DFMT_V8U8:             retVal = GL_UNSIGNED_BYTE; break;
1729         case WINED3DFMT_V16U16:           retVal = GL_UNSIGNED_SHORT; break;
1730         case WINED3DFMT_L6V5U5:           retVal = GL_UNSIGNED_SHORT_5_5_5_1; break;
1731         case WINED3DFMT_X8L8V8U8:         retVal = GL_UNSIGNED_BYTE; break;
1732             /* Color buffer */
1733         case WINED3DFMT_R3G3B2:           retVal = GL_UNSIGNED_BYTE_2_3_3_REV; break;
1734         case WINED3DFMT_R5G6B5:           retVal = GL_UNSIGNED_SHORT_5_6_5; break;
1735         case WINED3DFMT_R8G8B8:           retVal = GL_UNSIGNED_BYTE; break;
1736         case WINED3DFMT_A1R5G5B5:         retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
1737         case WINED3DFMT_X1R5G5B5:         retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
1738         case WINED3DFMT_A4R4G4B4:         retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
1739         case WINED3DFMT_X4R4G4B4:         retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
1740         case WINED3DFMT_A8R8G8B8:         retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
1741         case WINED3DFMT_A2R10G10B10:      retVal = GL_UNSIGNED_INT_2_10_10_10_REV; break;
1742         case WINED3DFMT_X8R8G8B8:         retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
1743             /* to see */
1744         case WINED3DFMT_A8:               retVal = GL_ALPHA; break;
1745             /* Depth + Stencil */
1746         case WINED3DFMT_D24S8:            retVal = GL_UNSIGNED_INT; break;
1747         case WINED3DFMT_D24FS8:           retVal = GL_UNSIGNED_INT; break;
1748         case WINED3DFMT_D24X8:            retVal = GL_UNSIGNED_INT; break;
1749         case WINED3DFMT_D24X4S4:          retVal = GL_UNSIGNED_INT; break;
1750         case WINED3DFMT_D32:              retVal = GL_UNSIGNED_INT; break;
1751         case WINED3DFMT_D16:              retVal = GL_UNSIGNED_SHORT; break;
1752         case WINED3DFMT_D15S1:            retVal = GL_UNSIGNED_SHORT; break;
1753         case WINED3DFMT_D16_LOCKABLE:     retVal = GL_UNSIGNED_SHORT; break;
1754             /* compressed textures */
1755         case WINED3DFMT_DXT1:             retVal = 0; break;
1756         case WINED3DFMT_DXT2:             retVal = 0; break;
1757         case WINED3DFMT_DXT3:             retVal = 0; break;
1758         case WINED3DFMT_DXT4:             retVal = 0; break;
1759         case WINED3DFMT_DXT5:             retVal = 0; break;
1760
1761         default:
1762             FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1763             retVal = GL_UNSIGNED_BYTE;
1764         }
1765     }
1766
1767     TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1768     return retVal;
1769 }
1770
1771 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1772     SHORT retVal;
1773
1774     switch (fmt) {
1775     /* color buffer */
1776     case WINED3DFMT_R3G3B2:           retVal = 1; break;
1777     case WINED3DFMT_R5G6B5:           retVal = 2; break;
1778     case WINED3DFMT_R8G8B8:           retVal = 3; break;
1779     case WINED3DFMT_A1R5G5B5:         retVal = 2; break;
1780     case WINED3DFMT_X1R5G5B5:         retVal = 2; break;
1781     case WINED3DFMT_A4R4G4B4:         retVal = 2; break;
1782     case WINED3DFMT_X4R4G4B4:         retVal = 2; break;
1783     case WINED3DFMT_A8R8G8B8:         retVal = 4; break;
1784     case WINED3DFMT_A2R10G10B10:      retVal = 4; break;
1785     case WINED3DFMT_X8R8G8B8:         retVal = 4; break;
1786         /* Paletted */
1787     case WINED3DFMT_P8:               retVal = 1; break;
1788     case WINED3DFMT_A8P8:             retVal = 2; break;
1789         /* depth/stencil buffer */
1790     case WINED3DFMT_D16_LOCKABLE:     retVal = 2; break;
1791     case WINED3DFMT_D16:              retVal = 2; break;
1792     case WINED3DFMT_D32:              retVal = 4; break;
1793     case WINED3DFMT_D15S1:            retVal = 2; break;
1794     case WINED3DFMT_D24X4S4:          retVal = 4; break;
1795     case WINED3DFMT_D24S8:            retVal = 4; break;
1796     case WINED3DFMT_D24FS8:           retVal = 4; break;
1797     case WINED3DFMT_D24X8:            retVal = 4; break;
1798         /* Luminance */
1799     case WINED3DFMT_L8:               retVal = 1; break;
1800     case WINED3DFMT_A4L4:             retVal = 1; break;
1801     case WINED3DFMT_A8L8:             retVal = 2; break;
1802         /* Bump */
1803     case WINED3DFMT_V8U8:             retVal = 2; break;
1804     case WINED3DFMT_L6V5U5:           retVal = 2; break;
1805     case WINED3DFMT_V16U16:           retVal = 4; break;
1806     case WINED3DFMT_X8L8V8U8:         retVal = 4; break;
1807     case WINED3DFMT_Q8W8V8U8:         retVal = 4; break;
1808     case WINED3DFMT_Q16W16V16U16:     retVal = 8; break;
1809         /* Compressed */
1810     case WINED3DFMT_DXT1:             retVal = 1; break; /* Actually  8 bytes per 16 pixels - Special cased later */
1811     case WINED3DFMT_DXT2:             retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1812     case WINED3DFMT_DXT3:             retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1813     case WINED3DFMT_DXT4:             retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1814     case WINED3DFMT_DXT5:             retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1815         /* to see */
1816     case WINED3DFMT_A8:               retVal = 1; break;
1817         /* unknown */
1818     case WINED3DFMT_UNKNOWN:
1819         /* Guess at the highest value of the above */
1820         TRACE("WINED3DFMT_UNKNOWN - Guessing at 4 bytes/pixel %u\n", fmt);
1821         retVal = 4;
1822         break;
1823
1824     default:
1825         FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1826         retVal = 4;
1827     }
1828     TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
1829     return retVal;
1830 }
1831
1832 /* Convertes a D3D format into a OpenGL configuration format */
1833 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate){
1834 #define PUSH1(att)        attribs[(*nAttribs)++] = (att);
1835 #define PUSH2(att,value)  attribs[(*nAttribs)++] = (att); attribs[(*nAttribs)++] = (value);
1836     /*We need to do some Card specific stuff in here at some point,
1837     D3D now support floating point format buffers, and their are a number of different OpelGl ways on managing thease e.g.
1838     GLX_ATI_pixel_format_float
1839     */
1840     switch (BackBufferFormat) {
1841         /* color buffer */
1842     case WINED3DFMT_P8:
1843         PUSH2(GLX_RENDER_TYPE,  GLX_COLOR_INDEX_BIT);
1844         PUSH2(GLX_BUFFER_SIZE,  8);
1845         PUSH2(GLX_DOUBLEBUFFER, TRUE);
1846         break;
1847
1848     case WINED3DFMT_R3G3B2:
1849         PUSH2(GLX_RENDER_TYPE,  GLX_RGBA_BIT);
1850         PUSH2(GLX_RED_SIZE,     3);
1851         PUSH2(GLX_GREEN_SIZE,   3);
1852         PUSH2(GLX_BLUE_SIZE,    2);
1853         break;
1854
1855     case WINED3DFMT_A1R5G5B5:
1856         PUSH2(GLX_ALPHA_SIZE,   1);
1857     case WINED3DFMT_X1R5G5B5:
1858         PUSH2(GLX_RED_SIZE,     5);
1859         PUSH2(GLX_GREEN_SIZE,   5);
1860         PUSH2(GLX_BLUE_SIZE,    5);
1861         break;
1862
1863     case WINED3DFMT_R5G6B5:
1864         PUSH2(GLX_RED_SIZE,     5);
1865         PUSH2(GLX_GREEN_SIZE,   6);
1866         PUSH2(GLX_BLUE_SIZE,    5);
1867         break;
1868
1869     case WINED3DFMT_A4R4G4B4:
1870         PUSH2(GLX_ALPHA_SIZE,   4);
1871     case WINED3DFMT_X4R4G4B4:
1872         PUSH2(GLX_RED_SIZE,     4);
1873         PUSH2(GLX_GREEN_SIZE,   4);
1874         PUSH2(GLX_BLUE_SIZE,    4);
1875         break;
1876
1877     case WINED3DFMT_A8R8G8B8:
1878         PUSH2(GLX_ALPHA_SIZE,   8);
1879     case WINED3DFMT_R8G8B8:
1880     case WINED3DFMT_X8R8G8B8:
1881         PUSH2(GLX_RED_SIZE,     8);
1882         PUSH2(GLX_GREEN_SIZE,   8);
1883         PUSH2(GLX_BLUE_SIZE,    8);
1884         break;
1885
1886     case WINED3DFMT_A2R10G10B10:
1887         PUSH2(GLX_ALPHA_SIZE,   2);
1888         PUSH2(GLX_RED_SIZE,    10);
1889         PUSH2(GLX_GREEN_SIZE,  10);
1890         PUSH2(GLX_BLUE_SIZE,   10);
1891         break;
1892
1893     default:
1894         break;
1895     }
1896     if(!alternate){
1897         switch (StencilBufferFormat) {
1898     case WINED3DFMT_D16_LOCKABLE:
1899     case WINED3DFMT_D16:
1900         PUSH2(GLX_DEPTH_SIZE,   16);
1901         break;
1902
1903     case WINED3DFMT_D15S1:
1904         PUSH2(GLX_DEPTH_SIZE,   15);
1905         PUSH2(GLX_STENCIL_SIZE, 1);
1906         /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
1907         e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
1908         break;
1909
1910     case WINED3DFMT_D24X8:
1911         PUSH2(GLX_DEPTH_SIZE,   24);
1912         break;
1913
1914     case WINED3DFMT_D24X4S4:
1915         PUSH2(GLX_DEPTH_SIZE,   24);
1916         PUSH2(GLX_STENCIL_SIZE, 4);
1917         break;
1918
1919     case WINED3DFMT_D24S8:
1920         PUSH2(GLX_DEPTH_SIZE,   24);
1921         PUSH2(GLX_STENCIL_SIZE, 8);
1922         break;
1923
1924     case WINED3DFMT_D24FS8:
1925         PUSH2(GLX_DEPTH_SIZE,   24);
1926         PUSH2(GLX_STENCIL_SIZE, 8);
1927         break;
1928
1929     case WINED3DFMT_D32:
1930         PUSH2(GLX_DEPTH_SIZE,   32);
1931         break;
1932
1933     default:
1934         break;
1935     }
1936
1937     } else { /* it the device doesn't support the 'exact' format, try to find something close */
1938         switch (StencilBufferFormat) {
1939         case WINED3DFMT_D16_LOCKABLE:
1940         case WINED3DFMT_D16:
1941             PUSH2(GLX_DEPTH_SIZE,   1);
1942             break;
1943
1944         case WINED3DFMT_D15S1:
1945             PUSH2(GLX_DEPTH_SIZE,   1);
1946             PUSH2(GLX_STENCIL_SIZE, 1);
1947             /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
1948             e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
1949             break;
1950
1951         case WINED3DFMT_D24X8:
1952             PUSH2(GLX_DEPTH_SIZE,   1);
1953             break;
1954
1955         case WINED3DFMT_D24X4S4:
1956             PUSH2(GLX_DEPTH_SIZE,   1);
1957             PUSH2(GLX_STENCIL_SIZE, 1);
1958             break;
1959
1960         case WINED3DFMT_D24S8:
1961             PUSH2(GLX_DEPTH_SIZE,   1);
1962             PUSH2(GLX_STENCIL_SIZE, 1);
1963             break;
1964
1965         case WINED3DFMT_D24FS8:
1966             PUSH2(GLX_DEPTH_SIZE,   1);
1967             PUSH2(GLX_STENCIL_SIZE, 1);
1968             break;
1969
1970         case WINED3DFMT_D32:
1971             PUSH2(GLX_DEPTH_SIZE,   1);
1972             break;
1973
1974         default:
1975             break;
1976         }
1977     }
1978
1979     return *nAttribs;
1980 }
1981
1982 #undef GLINFO_LOCATION