2 * Utility functions for the WineD3D Library
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
29 /*****************************************************************************
30 * Trace formatting of useful values
32 const char* debug_d3dformat(WINED3DFORMAT fmt) {
34 #define FMT_TO_STR(fmt) case fmt: return #fmt
35 FMT_TO_STR(WINED3DFMT_UNKNOWN);
36 FMT_TO_STR(WINED3DFMT_R8G8B8);
37 FMT_TO_STR(WINED3DFMT_A8R8G8B8);
38 FMT_TO_STR(WINED3DFMT_X8R8G8B8);
39 FMT_TO_STR(WINED3DFMT_R5G6B5);
40 FMT_TO_STR(WINED3DFMT_X1R5G5B5);
41 FMT_TO_STR(WINED3DFMT_A1R5G5B5);
42 FMT_TO_STR(WINED3DFMT_A4R4G4B4);
43 FMT_TO_STR(WINED3DFMT_R3G3B2);
44 FMT_TO_STR(WINED3DFMT_A8);
45 FMT_TO_STR(WINED3DFMT_A8R3G3B2);
46 FMT_TO_STR(WINED3DFMT_X4R4G4B4);
47 FMT_TO_STR(WINED3DFMT_A2B10G10R10);
48 FMT_TO_STR(WINED3DFMT_A8B8G8R8);
49 FMT_TO_STR(WINED3DFMT_X8B8G8R8);
50 FMT_TO_STR(WINED3DFMT_G16R16);
51 FMT_TO_STR(WINED3DFMT_A2R10G10B10);
52 FMT_TO_STR(WINED3DFMT_A16B16G16R16);
53 FMT_TO_STR(WINED3DFMT_A8P8);
54 FMT_TO_STR(WINED3DFMT_P8);
55 FMT_TO_STR(WINED3DFMT_L8);
56 FMT_TO_STR(WINED3DFMT_A8L8);
57 FMT_TO_STR(WINED3DFMT_A4L4);
58 FMT_TO_STR(WINED3DFMT_V8U8);
59 FMT_TO_STR(WINED3DFMT_L6V5U5);
60 FMT_TO_STR(WINED3DFMT_X8L8V8U8);
61 FMT_TO_STR(WINED3DFMT_Q8W8V8U8);
62 FMT_TO_STR(WINED3DFMT_V16U16);
63 FMT_TO_STR(WINED3DFMT_W11V11U10);
64 FMT_TO_STR(WINED3DFMT_A2W10V10U10);
65 FMT_TO_STR(WINED3DFMT_UYVY);
66 FMT_TO_STR(WINED3DFMT_YUY2);
67 FMT_TO_STR(WINED3DFMT_DXT1);
68 FMT_TO_STR(WINED3DFMT_DXT2);
69 FMT_TO_STR(WINED3DFMT_DXT3);
70 FMT_TO_STR(WINED3DFMT_DXT4);
71 FMT_TO_STR(WINED3DFMT_DXT5);
72 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB);
73 FMT_TO_STR(WINED3DFMT_G8R8_G8B8);
74 FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
75 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
76 FMT_TO_STR(WINED3DFMT_D32);
77 FMT_TO_STR(WINED3DFMT_D15S1);
78 FMT_TO_STR(WINED3DFMT_D24S8);
79 FMT_TO_STR(WINED3DFMT_D24X8);
80 FMT_TO_STR(WINED3DFMT_D24X4S4);
81 FMT_TO_STR(WINED3DFMT_D16);
82 FMT_TO_STR(WINED3DFMT_L16);
83 FMT_TO_STR(WINED3DFMT_D32F_LOCKABLE);
84 FMT_TO_STR(WINED3DFMT_D24FS8);
85 FMT_TO_STR(WINED3DFMT_VERTEXDATA);
86 FMT_TO_STR(WINED3DFMT_INDEX16);
87 FMT_TO_STR(WINED3DFMT_INDEX32);
88 FMT_TO_STR(WINED3DFMT_Q16W16V16U16);
89 FMT_TO_STR(WINED3DFMT_R16F);
90 FMT_TO_STR(WINED3DFMT_G16R16F);
91 FMT_TO_STR(WINED3DFMT_A16B16G16R16F);
92 FMT_TO_STR(WINED3DFMT_R32F);
93 FMT_TO_STR(WINED3DFMT_G32R32F);
94 FMT_TO_STR(WINED3DFMT_A32B32G32R32F);
95 FMT_TO_STR(WINED3DFMT_CxV8U8);
98 FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
99 return "unrecognized";
103 const char* debug_d3ddevicetype(D3DDEVTYPE devtype) {
105 #define DEVTYPE_TO_STR(dev) case dev: return #dev
106 DEVTYPE_TO_STR(D3DDEVTYPE_HAL);
107 DEVTYPE_TO_STR(D3DDEVTYPE_REF);
108 DEVTYPE_TO_STR(D3DDEVTYPE_SW);
109 #undef DEVTYPE_TO_STR
111 FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
112 return "unrecognized";
116 const char* debug_d3dusage(DWORD usage) {
118 #define WINED3DUSAGE_TO_STR(u) case u: return #u
119 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET);
120 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL);
121 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY);
122 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING);
123 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP);
124 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS);
125 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES);
126 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES);
127 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC);
128 #undef WINED3DUSAGE_TO_STR
129 case 0: return "none";
131 FIXME("Unrecognized %lu Usage!\n", usage);
132 return "unrecognized";
136 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res) {
138 #define RES_TO_STR(res) case res: return #res;
139 RES_TO_STR(WINED3DRTYPE_SURFACE);
140 RES_TO_STR(WINED3DRTYPE_VOLUME);
141 RES_TO_STR(WINED3DRTYPE_TEXTURE);
142 RES_TO_STR(WINED3DRTYPE_VOLUMETEXTURE);
143 RES_TO_STR(WINED3DRTYPE_CUBETEXTURE);
144 RES_TO_STR(WINED3DRTYPE_VERTEXBUFFER);
145 RES_TO_STR(WINED3DRTYPE_INDEXBUFFER);
148 FIXME("Unrecognized %u WINED3DRESOURCETYPE!\n", res);
149 return "unrecognized";
153 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType) {
154 switch (PrimitiveType) {
155 #define PRIM_TO_STR(prim) case prim: return #prim;
156 PRIM_TO_STR(D3DPT_POINTLIST);
157 PRIM_TO_STR(D3DPT_LINELIST);
158 PRIM_TO_STR(D3DPT_LINESTRIP);
159 PRIM_TO_STR(D3DPT_TRIANGLELIST);
160 PRIM_TO_STR(D3DPT_TRIANGLESTRIP);
161 PRIM_TO_STR(D3DPT_TRIANGLEFAN);
164 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
165 return "unrecognized";
169 const char* debug_d3drenderstate(DWORD state) {
171 #define D3DSTATE_TO_STR(u) case u: return #u
172 D3DSTATE_TO_STR(WINED3DRS_ZENABLE );
173 D3DSTATE_TO_STR(WINED3DRS_FILLMODE );
174 D3DSTATE_TO_STR(WINED3DRS_SHADEMODE );
175 D3DSTATE_TO_STR(WINED3DRS_LINEPATTERN );
176 D3DSTATE_TO_STR(WINED3DRS_ZWRITEENABLE );
177 D3DSTATE_TO_STR(WINED3DRS_ALPHATESTENABLE );
178 D3DSTATE_TO_STR(WINED3DRS_LASTPIXEL );
179 D3DSTATE_TO_STR(WINED3DRS_SRCBLEND );
180 D3DSTATE_TO_STR(WINED3DRS_DESTBLEND );
181 D3DSTATE_TO_STR(WINED3DRS_CULLMODE );
182 D3DSTATE_TO_STR(WINED3DRS_ZFUNC );
183 D3DSTATE_TO_STR(WINED3DRS_ALPHAREF );
184 D3DSTATE_TO_STR(WINED3DRS_ALPHAFUNC );
185 D3DSTATE_TO_STR(WINED3DRS_DITHERENABLE );
186 D3DSTATE_TO_STR(WINED3DRS_ALPHABLENDENABLE );
187 D3DSTATE_TO_STR(WINED3DRS_FOGENABLE );
188 D3DSTATE_TO_STR(WINED3DRS_SPECULARENABLE );
189 D3DSTATE_TO_STR(WINED3DRS_ZVISIBLE );
190 D3DSTATE_TO_STR(WINED3DRS_FOGCOLOR );
191 D3DSTATE_TO_STR(WINED3DRS_FOGTABLEMODE );
192 D3DSTATE_TO_STR(WINED3DRS_FOGSTART );
193 D3DSTATE_TO_STR(WINED3DRS_FOGEND );
194 D3DSTATE_TO_STR(WINED3DRS_FOGDENSITY );
195 D3DSTATE_TO_STR(WINED3DRS_EDGEANTIALIAS );
196 D3DSTATE_TO_STR(WINED3DRS_ZBIAS );
197 D3DSTATE_TO_STR(WINED3DRS_RANGEFOGENABLE );
198 D3DSTATE_TO_STR(WINED3DRS_STENCILENABLE );
199 D3DSTATE_TO_STR(WINED3DRS_STENCILFAIL );
200 D3DSTATE_TO_STR(WINED3DRS_STENCILZFAIL );
201 D3DSTATE_TO_STR(WINED3DRS_STENCILPASS );
202 D3DSTATE_TO_STR(WINED3DRS_STENCILFUNC );
203 D3DSTATE_TO_STR(WINED3DRS_STENCILREF );
204 D3DSTATE_TO_STR(WINED3DRS_STENCILMASK );
205 D3DSTATE_TO_STR(WINED3DRS_STENCILWRITEMASK );
206 D3DSTATE_TO_STR(WINED3DRS_TEXTUREFACTOR );
207 D3DSTATE_TO_STR(WINED3DRS_WRAP0 );
208 D3DSTATE_TO_STR(WINED3DRS_WRAP1 );
209 D3DSTATE_TO_STR(WINED3DRS_WRAP2 );
210 D3DSTATE_TO_STR(WINED3DRS_WRAP3 );
211 D3DSTATE_TO_STR(WINED3DRS_WRAP4 );
212 D3DSTATE_TO_STR(WINED3DRS_WRAP5 );
213 D3DSTATE_TO_STR(WINED3DRS_WRAP6 );
214 D3DSTATE_TO_STR(WINED3DRS_WRAP7 );
215 D3DSTATE_TO_STR(WINED3DRS_CLIPPING );
216 D3DSTATE_TO_STR(WINED3DRS_LIGHTING );
217 D3DSTATE_TO_STR(WINED3DRS_AMBIENT );
218 D3DSTATE_TO_STR(WINED3DRS_FOGVERTEXMODE );
219 D3DSTATE_TO_STR(WINED3DRS_COLORVERTEX );
220 D3DSTATE_TO_STR(WINED3DRS_LOCALVIEWER );
221 D3DSTATE_TO_STR(WINED3DRS_NORMALIZENORMALS );
222 D3DSTATE_TO_STR(WINED3DRS_DIFFUSEMATERIALSOURCE );
223 D3DSTATE_TO_STR(WINED3DRS_SPECULARMATERIALSOURCE );
224 D3DSTATE_TO_STR(WINED3DRS_AMBIENTMATERIALSOURCE );
225 D3DSTATE_TO_STR(WINED3DRS_EMISSIVEMATERIALSOURCE );
226 D3DSTATE_TO_STR(WINED3DRS_VERTEXBLEND );
227 D3DSTATE_TO_STR(WINED3DRS_CLIPPLANEENABLE );
228 D3DSTATE_TO_STR(WINED3DRS_SOFTWAREVERTEXPROCESSING );
229 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE );
230 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MIN );
231 D3DSTATE_TO_STR(WINED3DRS_POINTSPRITEENABLE );
232 D3DSTATE_TO_STR(WINED3DRS_POINTSCALEENABLE );
233 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_A );
234 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_B );
235 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_C );
236 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEANTIALIAS );
237 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEMASK );
238 D3DSTATE_TO_STR(WINED3DRS_PATCHEDGESTYLE );
239 D3DSTATE_TO_STR(WINED3DRS_PATCHSEGMENTS );
240 D3DSTATE_TO_STR(WINED3DRS_DEBUGMONITORTOKEN );
241 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MAX );
242 D3DSTATE_TO_STR(WINED3DRS_INDEXEDVERTEXBLENDENABLE );
243 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE );
244 D3DSTATE_TO_STR(WINED3DRS_TWEENFACTOR );
245 D3DSTATE_TO_STR(WINED3DRS_BLENDOP );
246 D3DSTATE_TO_STR(WINED3DRS_POSITIONDEGREE );
247 D3DSTATE_TO_STR(WINED3DRS_NORMALDEGREE );
248 D3DSTATE_TO_STR(WINED3DRS_SCISSORTESTENABLE );
249 D3DSTATE_TO_STR(WINED3DRS_SLOPESCALEDEPTHBIAS );
250 D3DSTATE_TO_STR(WINED3DRS_ANTIALIASEDLINEENABLE );
251 D3DSTATE_TO_STR(WINED3DRS_MINTESSELLATIONLEVEL );
252 D3DSTATE_TO_STR(WINED3DRS_MAXTESSELLATIONLEVEL );
253 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_X );
254 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Y );
255 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Z );
256 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_W );
257 D3DSTATE_TO_STR(WINED3DRS_ENABLEADAPTIVETESSELLATION);
258 D3DSTATE_TO_STR(WINED3DRS_TWOSIDEDSTENCILMODE );
259 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFAIL );
260 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILZFAIL );
261 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILPASS );
262 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFUNC );
263 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE1 );
264 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE2 );
265 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE3 );
266 D3DSTATE_TO_STR(WINED3DRS_BLENDFACTOR );
267 D3DSTATE_TO_STR(WINED3DRS_SRGBWRITEENABLE );
268 D3DSTATE_TO_STR(WINED3DRS_DEPTHBIAS );
269 D3DSTATE_TO_STR(WINED3DRS_WRAP8 );
270 D3DSTATE_TO_STR(WINED3DRS_WRAP9 );
271 D3DSTATE_TO_STR(WINED3DRS_WRAP10 );
272 D3DSTATE_TO_STR(WINED3DRS_WRAP11 );
273 D3DSTATE_TO_STR(WINED3DRS_WRAP12 );
274 D3DSTATE_TO_STR(WINED3DRS_WRAP13 );
275 D3DSTATE_TO_STR(WINED3DRS_WRAP14 );
276 D3DSTATE_TO_STR(WINED3DRS_WRAP15 );
277 D3DSTATE_TO_STR(WINED3DRS_SEPARATEALPHABLENDENABLE );
278 D3DSTATE_TO_STR(WINED3DRS_SRCBLENDALPHA );
279 D3DSTATE_TO_STR(WINED3DRS_DESTBLENDALPHA );
280 D3DSTATE_TO_STR(WINED3DRS_BLENDOPALPHA );
281 #undef D3DSTATE_TO_STR
283 FIXME("Unrecognized %lu render state!\n", state);
284 return "unrecognized";
288 const char* debug_d3dsamplerstate(DWORD state) {
290 #define D3DSTATE_TO_STR(u) case u: return #u
291 D3DSTATE_TO_STR(WINED3DSAMP_BORDERCOLOR );
292 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSU );
293 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSV );
294 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSW );
295 D3DSTATE_TO_STR(WINED3DSAMP_MAGFILTER );
296 D3DSTATE_TO_STR(WINED3DSAMP_MINFILTER );
297 D3DSTATE_TO_STR(WINED3DSAMP_MIPFILTER );
298 D3DSTATE_TO_STR(WINED3DSAMP_MIPMAPLODBIAS);
299 D3DSTATE_TO_STR(WINED3DSAMP_MAXMIPLEVEL );
300 D3DSTATE_TO_STR(WINED3DSAMP_MAXANISOTROPY);
301 D3DSTATE_TO_STR(WINED3DSAMP_SRGBTEXTURE );
302 D3DSTATE_TO_STR(WINED3DSAMP_ELEMENTINDEX );
303 D3DSTATE_TO_STR(WINED3DSAMP_DMAPOFFSET );
304 #undef D3DSTATE_TO_STR
306 FIXME("Unrecognized %lu sampler state!\n", state);
307 return "unrecognized";
311 const char* debug_d3dtexturestate(DWORD state) {
313 #define D3DSTATE_TO_STR(u) case u: return #u
314 D3DSTATE_TO_STR(WINED3DTSS_COLOROP );
315 D3DSTATE_TO_STR(WINED3DTSS_COLORARG1 );
316 D3DSTATE_TO_STR(WINED3DTSS_COLORARG2 );
317 D3DSTATE_TO_STR(WINED3DTSS_ALPHAOP );
318 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG1 );
319 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG2 );
320 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT00 );
321 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT01 );
322 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT10 );
323 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT11 );
324 D3DSTATE_TO_STR(WINED3DTSS_TEXCOORDINDEX );
325 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLSCALE );
326 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLOFFSET );
327 D3DSTATE_TO_STR(WINED3DTSS_TEXTURETRANSFORMFLAGS );
328 D3DSTATE_TO_STR(WINED3DTSS_ADDRESSW );
329 D3DSTATE_TO_STR(WINED3DTSS_COLORARG0 );
330 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG0 );
331 D3DSTATE_TO_STR(WINED3DTSS_RESULTARG );
332 D3DSTATE_TO_STR(WINED3DTSS_CONSTANT );
333 #undef D3DSTATE_TO_STR
335 /* Note D3DTSS are not consecutive, so skip these */
339 FIXME("Unrecognized %lu texture state!\n", state);
340 return "unrecognized";
344 const char* debug_d3dpool(WINED3DPOOL Pool) {
346 #define POOL_TO_STR(p) case p: return #p;
347 POOL_TO_STR(WINED3DPOOL_DEFAULT);
348 POOL_TO_STR(WINED3DPOOL_MANAGED);
349 POOL_TO_STR(WINED3DPOOL_SYSTEMMEM);
350 POOL_TO_STR(WINED3DPOOL_SCRATCH);
353 FIXME("Unrecognized %u WINED3DPOOL!\n", Pool);
354 return "unrecognized";
357 /*****************************************************************************
358 * Useful functions mapping GL <-> D3D values
360 GLenum StencilOp(DWORD op) {
362 case D3DSTENCILOP_KEEP : return GL_KEEP;
363 case D3DSTENCILOP_ZERO : return GL_ZERO;
364 case D3DSTENCILOP_REPLACE : return GL_REPLACE;
365 case D3DSTENCILOP_INCRSAT : return GL_INCR;
366 case D3DSTENCILOP_DECRSAT : return GL_DECR;
367 case D3DSTENCILOP_INVERT : return GL_INVERT;
368 case D3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
369 case D3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
371 FIXME("Invalid stencil op %ld\n", op);
376 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
377 #if defined (GL_VERSION_1_3)
379 # define combine_ext 1
380 #elif defined (GL_EXT_texture_env_combine)
381 # define useext(A) A##_EXT
382 # define combine_ext 1
383 #elif defined (GL_ARB_texture_env_combine)
384 # define useext(A) A##_ARB
385 # define combine_ext 1
390 #if !defined(combine_ext)
391 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
393 FIXME("Requires opengl combine extensions to work\n");
397 /* Setup the texture operations texture stage states */
398 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
400 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
401 GLenum src1, src2, src3;
402 GLenum opr1, opr2, opr3;
404 GLenum src0_target, src1_target, src2_target;
405 GLenum opr0_target, opr1_target, opr2_target;
407 GLenum opr=0, invopr, src3_target, opr3_target;
408 BOOL Handled = FALSE;
409 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
411 TRACE("Alpha?(%d), Stage:%d Op(%d), a1(%ld), a2(%ld), a3(%ld)\n", isAlpha, Stage, op, arg1, arg2, arg3);
415 /* Note: Operations usually involve two ars, src0 and src1 and are operations of
416 the form (a1 <operation> a2). However, some of the more complex operations
417 take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
418 in a third parameter called a0. Therefore these are operations of the form
419 a0 <operation> a1 <operation> a2, ie the new parameter goes to the front.
421 However, below we treat the new (a0) parameter as src2/opr2, so in the actual
422 functions below, expect their syntax to differ slightly to those listed in the
423 manuals, ie replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
424 This affects D3DTOP_MULTIPLYADD and D3DTOP_LERP */
427 comb_target = useext(GL_COMBINE_ALPHA);
428 src0_target = useext(GL_SOURCE0_ALPHA);
429 src1_target = useext(GL_SOURCE1_ALPHA);
430 src2_target = useext(GL_SOURCE2_ALPHA);
431 opr0_target = useext(GL_OPERAND0_ALPHA);
432 opr1_target = useext(GL_OPERAND1_ALPHA);
433 opr2_target = useext(GL_OPERAND2_ALPHA);
434 scal_target = GL_ALPHA_SCALE;
437 comb_target = useext(GL_COMBINE_RGB);
438 src0_target = useext(GL_SOURCE0_RGB);
439 src1_target = useext(GL_SOURCE1_RGB);
440 src2_target = useext(GL_SOURCE2_RGB);
441 opr0_target = useext(GL_OPERAND0_RGB);
442 opr1_target = useext(GL_OPERAND1_RGB);
443 opr2_target = useext(GL_OPERAND2_RGB);
444 scal_target = useext(GL_RGB_SCALE);
447 /* From MSDN (WINED3DTSS_ALPHAARG1) :
448 The default argument is D3DTA_TEXTURE. If no texture is set for this stage,
449 then the default argument is D3DTA_DIFFUSE.
450 FIXME? If texture added/removed, may need to reset back as well? */
451 if (isAlpha && This->stateBlock->textures[Stage] == NULL && arg1 == D3DTA_TEXTURE) {
452 GetSrcAndOpFromValue(D3DTA_DIFFUSE, isAlpha, &src1, &opr1);
454 GetSrcAndOpFromValue(arg1, isAlpha, &src1, &opr1);
456 GetSrcAndOpFromValue(arg2, isAlpha, &src2, &opr2);
457 GetSrcAndOpFromValue(arg3, isAlpha, &src3, &opr3);
459 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
461 Handled = TRUE; /* Assume will be handled */
463 /* Other texture operations require special extensions: */
464 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
467 invopr = GL_ONE_MINUS_SRC_ALPHA;
468 src3_target = GL_SOURCE3_ALPHA_NV;
469 opr3_target = GL_OPERAND3_ALPHA_NV;
472 invopr = GL_ONE_MINUS_SRC_COLOR;
473 src3_target = GL_SOURCE3_RGB_NV;
474 opr3_target = GL_OPERAND3_RGB_NV;
477 case D3DTOP_DISABLE: /* Only for alpha */
478 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
479 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
480 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
481 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
482 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
483 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
484 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
485 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
486 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
487 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
488 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
489 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
490 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
491 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
492 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
493 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
494 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
495 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
497 case D3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */
498 case D3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */
499 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
500 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
501 if (op == D3DTOP_SELECTARG1) {
502 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
503 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
504 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
505 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
507 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
508 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
509 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
510 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
512 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
513 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
514 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
515 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
516 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
517 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
518 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
519 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
520 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
521 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
522 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
523 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
526 case D3DTOP_MODULATE:
527 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
528 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
529 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
530 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
531 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
532 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
533 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
534 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
535 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
536 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
537 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
538 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
539 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
540 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
541 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
542 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
543 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
544 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
545 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
546 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
548 case D3DTOP_MODULATE2X:
549 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
550 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
551 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
552 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
553 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
554 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
555 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
556 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
557 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
558 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
559 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
560 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
561 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
562 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
563 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
564 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
565 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
566 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
567 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
568 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
570 case D3DTOP_MODULATE4X:
571 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
572 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
573 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
574 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
575 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
576 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
577 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
578 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
579 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
580 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
581 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
582 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
583 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
584 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
585 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
586 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
587 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
588 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
589 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
590 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
594 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
595 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
596 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
597 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
598 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
599 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
600 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
601 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
602 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
603 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
604 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
605 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
606 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
607 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
608 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
609 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
610 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
611 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
612 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
613 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
616 case D3DTOP_ADDSIGNED:
617 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
618 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
619 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
620 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
621 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
622 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
623 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
624 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
625 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
626 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
627 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
628 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
629 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
630 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
631 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
632 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
633 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
634 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
635 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
636 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
639 case D3DTOP_ADDSIGNED2X:
640 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
641 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
642 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
643 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
644 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
645 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
646 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
647 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
648 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
649 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
650 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
651 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
652 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
653 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
654 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
655 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
656 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
657 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
658 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
659 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
662 case D3DTOP_ADDSMOOTH:
663 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
664 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
665 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
666 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
667 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
668 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
669 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
670 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
671 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
672 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
673 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
674 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
675 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
676 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
677 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
678 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
680 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
681 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
682 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
683 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
685 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
686 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
687 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
688 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
691 case D3DTOP_BLENDDIFFUSEALPHA:
692 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
693 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
694 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
695 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
696 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
697 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
698 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
699 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
700 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
701 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
702 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
703 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
704 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
705 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
706 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
707 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
708 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
709 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
710 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
711 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
713 case D3DTOP_BLENDTEXTUREALPHA:
714 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
715 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
716 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
717 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
718 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
719 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
720 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
721 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
722 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
723 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
724 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
725 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
726 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
727 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
728 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
729 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
730 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
731 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
732 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
733 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
735 case D3DTOP_BLENDFACTORALPHA:
736 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
737 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
738 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
739 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
740 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
741 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
742 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT));
743 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
744 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
745 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
746 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
747 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
748 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
749 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
750 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
751 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
752 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
753 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
754 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
755 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
757 case D3DTOP_BLENDTEXTUREALPHAPM:
758 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
759 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
760 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
761 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
762 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
763 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
764 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
765 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
766 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
767 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
768 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
769 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
770 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
771 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
772 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
773 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
774 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
775 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
776 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
777 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
779 case D3DTOP_MODULATEALPHA_ADDCOLOR:
780 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
781 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
782 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
783 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
784 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
785 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
786 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
787 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
788 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
789 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
790 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
791 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
792 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
793 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
794 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
795 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
797 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
798 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
800 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
801 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
802 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
803 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
805 case D3DTOP_MODULATECOLOR_ADDALPHA:
806 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
807 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
808 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
809 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
810 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
811 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
812 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
813 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
814 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
815 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
816 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
817 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
819 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
820 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
822 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
823 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
824 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
825 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
826 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
827 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
828 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
829 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
831 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
832 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
833 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
834 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
835 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
836 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
837 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
838 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
839 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
840 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
841 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
842 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
843 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
844 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
845 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
846 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
847 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
849 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
850 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
851 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
852 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
854 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
855 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
856 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
857 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
859 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
860 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
861 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
862 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
863 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
865 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
866 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
867 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
868 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
870 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
871 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
872 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
873 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
874 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
875 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
876 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
877 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
879 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
880 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
882 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
883 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
884 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
885 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
886 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
887 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
888 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
889 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
891 case D3DTOP_MULTIPLYADD:
892 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
893 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
894 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
895 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
896 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
897 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
898 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
899 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
900 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
901 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
902 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
903 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
904 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
905 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
906 glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
907 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
908 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
909 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
910 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
911 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
914 case D3DTOP_BUMPENVMAP:
916 if (GL_SUPPORT(NV_TEXTURE_SHADER)) {
918 texture unit 0: GL_TEXTURE_2D
919 texture unit 1: GL_DOT_PRODUCT_NV
920 texture unit 2: GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV
921 texture unit 3: GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV
930 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT00];
931 m[0][0] = tmpvalue.f;
932 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT01];
933 m[0][1] = tmpvalue.f;
934 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT10];
935 m[1][0] = tmpvalue.f;
936 tmpvalue.d = This->stateBlock->textureState[Stage][WINED3DTSS_BUMPENVMAT11];
937 m[1][1] = tmpvalue.f;
939 /*FIXME("Stage %d matrix is (%.2f,%.2f),(%.2f,%.2f)\n", Stage, m[0][0], m[0][1], m[1][0], m[1][0]);*/
941 if (FALSE == This->texture_shader_active) {
942 This->texture_shader_active = TRUE;
943 glEnable(GL_TEXTURE_SHADER_NV);
947 glEnable(GL_REGISTER_COMBINERS_NV);
948 glCombinerParameteriNV (GL_NUM_GENERAL_COMBINERS_NV, 1);
949 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
950 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
951 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
952 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
953 glCombinerOutputNV (GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
954 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
955 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
956 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
957 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
958 glCombinerOutputNV (GL_COMBINER0_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
959 glDisable (GL_PER_STAGE_CONSTANTS_NV);
960 glCombinerParameteriNV (GL_COLOR_SUM_CLAMP_NV, 0);
961 glFinalCombinerInputNV (GL_VARIABLE_A_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
962 glFinalCombinerInputNV (GL_VARIABLE_B_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
963 glFinalCombinerInputNV (GL_VARIABLE_C_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
964 glFinalCombinerInputNV (GL_VARIABLE_D_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
965 glFinalCombinerInputNV (GL_VARIABLE_E_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
966 glFinalCombinerInputNV (GL_VARIABLE_F_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
967 glFinalCombinerInputNV (GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
971 for (i = 0; i < Stage; i++) {
972 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
974 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
975 checkGLcall("Activate texture..");
977 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
982 GL_ACTIVETEXTURE(Stage - 1);
983 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
986 GL_ACTIVETEXTURE(Stage);
987 checkGLcall("Activate texture.. to update const color");
988 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
989 checkGLcall("glTexEnv");
990 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + Stage - 1);
991 checkGLcall("glTexEnv");
992 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float*)&m[0]);
993 checkGLcall("glTexEnv");
1001 case D3DTOP_BUMPENVMAPLUMINANCE:
1007 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
1008 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
1013 } /* GL_NV_texture_env_combine4 */
1015 Handled = TRUE; /* Again, assume handled */
1017 case D3DTOP_DISABLE: /* Only for alpha */
1018 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1019 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1020 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
1021 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
1022 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
1023 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
1024 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1025 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1027 case D3DTOP_SELECTARG1:
1028 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1029 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1030 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1031 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1032 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1033 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1034 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1035 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1037 case D3DTOP_SELECTARG2:
1038 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1039 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1040 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
1041 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1042 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1043 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1044 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1045 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1047 case D3DTOP_MODULATE:
1048 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1049 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1050 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1051 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1052 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1053 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1054 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1055 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1056 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1057 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1058 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1059 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1061 case D3DTOP_MODULATE2X:
1062 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1063 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1064 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1065 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1066 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1067 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1068 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1069 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1070 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1071 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1072 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1073 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1075 case D3DTOP_MODULATE4X:
1076 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1077 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1078 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1079 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1080 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1081 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1082 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1083 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1084 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1085 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1086 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1087 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1090 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1091 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1092 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1093 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1094 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1095 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1096 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1097 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1098 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1099 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1100 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1101 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1103 case D3DTOP_ADDSIGNED:
1104 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1105 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
1106 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1107 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1108 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1109 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1110 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1111 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1112 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1113 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1114 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1115 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1117 case D3DTOP_ADDSIGNED2X:
1118 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1119 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1120 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1121 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1122 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1123 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1124 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1125 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1126 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1127 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1128 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1129 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1131 case D3DTOP_SUBTRACT:
1132 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
1133 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
1134 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
1135 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1136 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1137 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1138 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1139 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1140 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1141 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1142 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1143 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1144 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1146 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1150 case D3DTOP_BLENDDIFFUSEALPHA:
1151 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1152 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1153 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1154 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1155 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1156 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1157 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1158 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1159 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1160 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1161 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
1162 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
1163 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1164 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1165 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1166 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1168 case D3DTOP_BLENDTEXTUREALPHA:
1169 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1170 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1171 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1172 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1173 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1174 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1175 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1176 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1177 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1178 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1179 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
1180 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
1181 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1182 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1183 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1184 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1186 case D3DTOP_BLENDFACTORALPHA:
1187 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1188 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1189 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1190 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1191 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1192 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1193 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1194 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1195 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1196 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1197 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
1198 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
1199 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1200 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1201 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1202 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1204 case D3DTOP_BLENDCURRENTALPHA:
1205 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1206 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1207 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1208 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1209 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1210 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1211 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1212 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1213 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1214 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1215 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
1216 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
1217 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1218 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1219 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1220 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1222 case D3DTOP_DOTPRODUCT3:
1223 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
1224 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
1225 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
1226 } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
1227 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
1228 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
1230 FIXME("This version of opengl does not support GL_DOT3\n");
1232 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1233 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1234 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1235 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1236 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1237 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1238 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1239 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1240 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1241 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1244 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1245 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1246 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1247 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1248 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1249 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1250 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1251 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1252 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1253 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1254 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
1255 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
1256 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
1257 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
1258 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1259 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1261 case D3DTOP_ADDSMOOTH:
1262 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1263 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1264 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1265 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1266 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1268 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1269 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1270 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1271 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1273 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1274 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1275 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1276 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1277 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1278 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1279 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1280 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1281 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1282 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1283 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1284 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1288 case D3DTOP_BLENDTEXTUREALPHAPM:
1289 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1290 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1291 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1292 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
1293 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
1294 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
1295 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
1296 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1297 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1298 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1299 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1300 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1301 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1302 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1303 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1304 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1305 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1309 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1310 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1311 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1312 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1313 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1314 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1316 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1317 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1318 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1319 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1321 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1322 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1323 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1324 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1325 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1326 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1327 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1328 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1329 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1330 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1331 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1332 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1336 case D3DTOP_MODULATECOLOR_ADDALPHA:
1337 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1338 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1339 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1340 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1341 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1342 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1343 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1344 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1345 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1347 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1348 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1349 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1350 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1352 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1353 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1354 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1355 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1356 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1357 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1358 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1359 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1363 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1364 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1365 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1366 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1367 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1368 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1370 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1371 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1372 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1373 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1375 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1376 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1377 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1378 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1379 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1380 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1381 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1382 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1383 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1384 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1385 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1386 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1390 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1391 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1392 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1393 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1394 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1395 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1397 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1398 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1399 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1400 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1402 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1403 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1404 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1405 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1407 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1408 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1409 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1410 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1412 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1413 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1414 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1415 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1416 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1417 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1418 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1419 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1423 case D3DTOP_MULTIPLYADD:
1424 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1425 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1426 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1427 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1428 checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
1429 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1430 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
1431 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1432 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1433 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1434 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1435 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1436 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1437 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1438 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1439 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1440 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1449 BOOL combineOK = TRUE;
1450 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1454 op2 = This->stateBlock->textureState[Stage][WINED3DTSS_COLOROP];
1456 op2 = This->stateBlock->textureState[Stage][WINED3DTSS_ALPHAOP];
1459 /* Note: If COMBINE4 in effect can't go back to combine! */
1461 case D3DTOP_ADDSMOOTH:
1462 case D3DTOP_BLENDTEXTUREALPHAPM:
1463 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1464 case D3DTOP_MODULATECOLOR_ADDALPHA:
1465 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1466 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1467 case D3DTOP_MULTIPLYADD:
1468 /* Ignore those implemented in both cases */
1470 case D3DTOP_SELECTARG1:
1471 case D3DTOP_SELECTARG2:
1476 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%d, otherop=%ld, isAlpha(%d)\n", op, op2, isAlpha);
1484 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
1485 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
1494 /* After all the extensions, if still unhandled, report fixme */
1495 FIXME("Unhandled texture operation %d\n", op);
1496 #undef GLINFO_LOCATION
1500 /* Setup this textures matrix according to the texture flags*/
1501 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords)
1505 glMatrixMode(GL_TEXTURE);
1506 checkGLcall("glMatrixMode(GL_TEXTURE)");
1508 if (flags == D3DTTFF_DISABLE) {
1510 checkGLcall("glLoadIdentity()");
1514 if (flags == (D3DTTFF_COUNT1|D3DTTFF_PROJECTED)) {
1515 ERR("Invalid texture transform flags: D3DTTFF_COUNT1|D3DTTFF_PROJECTED\n");
1519 memcpy(mat, smat, 16 * sizeof(float));
1521 switch (flags & ~D3DTTFF_PROJECTED) {
1522 case D3DTTFF_COUNT1: mat[1] = mat[5] = mat[13] = 0;
1523 case D3DTTFF_COUNT2: mat[2] = mat[6] = mat[10] = mat[14] = 0;
1524 default: mat[3] = mat[7] = mat[11] = 0, mat[15] = 1;
1527 if (flags & D3DTTFF_PROJECTED) {
1528 switch (flags & ~D3DTTFF_PROJECTED) {
1529 case D3DTTFF_COUNT2:
1530 mat[3] = mat[1], mat[7] = mat[5], mat[11] = mat[9], mat[15] = mat[13];
1531 mat[1] = mat[5] = mat[9] = mat[13] = 0;
1533 case D3DTTFF_COUNT3:
1534 mat[3] = mat[2], mat[7] = mat[6], mat[11] = mat[10], mat[15] = mat[14];
1535 mat[2] = mat[6] = mat[10] = mat[14] = 0;
1538 } else if(!calculatedCoords) { /* under directx the R/Z coord can be used for translation, under opengl we use the Q coord instead */
1544 checkGLcall("glLoadMatrixf(mat)");
1547 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand)
1549 BOOL isAlphaReplicate = FALSE;
1550 BOOL isComplement = FALSE;
1552 *operand = GL_SRC_COLOR;
1553 *source = GL_TEXTURE;
1555 /* Catch alpha replicate */
1556 if (iValue & D3DTA_ALPHAREPLICATE) {
1557 iValue = iValue & ~D3DTA_ALPHAREPLICATE;
1558 isAlphaReplicate = TRUE;
1561 /* Catch Complement */
1562 if (iValue & D3DTA_COMPLEMENT) {
1563 iValue = iValue & ~D3DTA_COMPLEMENT;
1564 isComplement = TRUE;
1567 /* Calculate the operand */
1568 if (isAlphaReplicate && !isComplement) {
1569 *operand = GL_SRC_ALPHA;
1570 } else if (isAlphaReplicate && isComplement) {
1571 *operand = GL_ONE_MINUS_SRC_ALPHA;
1572 } else if (isComplement) {
1574 *operand = GL_ONE_MINUS_SRC_ALPHA;
1576 *operand = GL_ONE_MINUS_SRC_COLOR;
1580 *operand = GL_SRC_ALPHA;
1582 *operand = GL_SRC_COLOR;
1586 /* Calculate the source */
1587 switch (iValue & D3DTA_SELECTMASK) {
1588 case D3DTA_CURRENT: *source = GL_PREVIOUS_EXT;
1590 case D3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT;
1592 case D3DTA_TEXTURE: *source = GL_TEXTURE;
1594 case D3DTA_TFACTOR: *source = GL_CONSTANT_EXT;
1596 case D3DTA_SPECULAR:
1598 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
1599 * 'Secondary color' and isn't supported until base GL supports it
1600 * There is no concept of temp registers as far as I can tell
1602 FIXME("Unhandled texture arg D3DTA_SPECULAR\n");
1603 *source = GL_TEXTURE;
1607 FIXME("Unrecognized texture arg %ld\n", iValue);
1608 *source = GL_TEXTURE;
1613 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
1614 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1617 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1619 case WINED3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
1620 case WINED3DFMT_DXT2: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1621 case WINED3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1622 case WINED3DFMT_DXT4: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1623 case WINED3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1625 /* stupid compiler */
1633 case WINED3DFMT_P8: retVal = GL_COLOR_INDEX8_EXT; break;
1634 case WINED3DFMT_A8P8: retVal = GL_COLOR_INDEX8_EXT; break;
1636 case WINED3DFMT_L8: retVal = GL_LUMINANCE8; break;
1637 case WINED3DFMT_L16: retVal = GL_LUMINANCE16_EXT; break;
1638 case WINED3DFMT_A8L8: retVal = GL_LUMINANCE8_ALPHA8; break;
1639 case WINED3DFMT_A4L4: retVal = GL_LUMINANCE4_ALPHA4; break;
1641 case WINED3DFMT_V8U8: retVal = GL_COLOR_INDEX8_EXT; break;
1642 case WINED3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
1643 case WINED3DFMT_L6V5U5: retVal = GL_COLOR_INDEX8_EXT; break;
1644 case WINED3DFMT_X8L8V8U8: retVal = GL_RGBA8; break;
1645 case WINED3DFMT_Q8W8V8U8: retVal = GL_RGBA8; break; /* almost but not quite... */
1646 case WINED3DFMT_Q16W16V16U16: retVal = GL_COLOR_INDEX; break; /* almost but not quite... */
1648 case WINED3DFMT_R3G3B2: retVal = GL_R3_G3_B2; break;
1649 case WINED3DFMT_R5G6B5: retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
1650 case WINED3DFMT_R8G8B8: retVal = GL_RGB8; break;
1651 case WINED3DFMT_A1R5G5B5: retVal = GL_RGB5_A1; break;
1652 case WINED3DFMT_X1R5G5B5: retVal = GL_RGB5_A1; break;
1653 case WINED3DFMT_A4R4G4B4: retVal = GL_RGBA4; break;
1654 case WINED3DFMT_X4R4G4B4: retVal = GL_RGB4; break;
1655 case WINED3DFMT_A8R8G8B8: retVal = GL_RGBA8; break;
1656 case WINED3DFMT_A8B8G8R8: retVal = GL_RGBA8; break;
1657 case WINED3DFMT_A2R10G10B10: retVal = GL_RGBA8; break;
1658 case WINED3DFMT_X8R8G8B8: retVal = GL_RGB8; break;
1659 case WINED3DFMT_A16B16G16R16: retVal = GL_RGBA16_EXT; break;
1661 case WINED3DFMT_A8: retVal = GL_ALPHA8; break;
1663 /* Depth + Stencil NOTE: OpenGL doesn't support depth-stencil surfaces so the formats are the closes bits match for the data */
1664 case WINED3DFMT_D24S8: retVal = GL_COLOR_INDEX; break;
1665 case WINED3DFMT_D24FS8: retVal = GL_COLOR_INDEX; break;
1666 case WINED3DFMT_D24X8: retVal = GL_COLOR_INDEX; break;
1667 case WINED3DFMT_D24X4S4: retVal = GL_COLOR_INDEX; break;
1668 case WINED3DFMT_D32: retVal = GL_COLOR_INDEX; break;
1669 case WINED3DFMT_D16: retVal = GL_COLOR_INDEX; break;
1670 case WINED3DFMT_D15S1: retVal = GL_COLOR_INDEX; break;
1671 case WINED3DFMT_D16_LOCKABLE: retVal = GL_COLOR_INDEX; break;
1674 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1678 TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1682 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1685 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1687 case WINED3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
1688 case WINED3DFMT_DXT2: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1689 case WINED3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
1690 case WINED3DFMT_DXT4: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1691 case WINED3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
1693 /* stupid compiler */
1701 case WINED3DFMT_P8: retVal = GL_COLOR_INDEX; break;
1702 case WINED3DFMT_A8P8: retVal = GL_COLOR_INDEX; break;
1704 case WINED3DFMT_L8: retVal = GL_LUMINANCE; break;
1705 case WINED3DFMT_L16: retVal = GL_LUMINANCE; break;
1706 case WINED3DFMT_A8L8: retVal = GL_LUMINANCE_ALPHA; break;
1707 case WINED3DFMT_A4L4: retVal = GL_LUMINANCE_ALPHA; break;
1709 case WINED3DFMT_V8U8: retVal = GL_COLOR_INDEX; break;
1710 case WINED3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
1711 case WINED3DFMT_L6V5U5: retVal = GL_COLOR_INDEX; break;
1712 case WINED3DFMT_X8L8V8U8: retVal = GL_BGRA; break;
1713 case WINED3DFMT_Q8W8V8U8: retVal = GL_RGBA; break;
1714 case WINED3DFMT_Q16W16V16U16: retVal = GL_COLOR_INDEX; break;
1716 case WINED3DFMT_R3G3B2: retVal = GL_RGB; break;
1717 case WINED3DFMT_R5G6B5: retVal = GL_RGB; break;
1718 case WINED3DFMT_R8G8B8: retVal = GL_RGB; break;
1719 case WINED3DFMT_A1R5G5B5: retVal = GL_BGRA; break;
1720 case WINED3DFMT_X1R5G5B5: retVal = GL_BGRA; break;
1721 case WINED3DFMT_A4R4G4B4: retVal = GL_BGRA; break;
1722 case WINED3DFMT_X4R4G4B4: retVal = GL_BGRA; break;
1723 case WINED3DFMT_A8R8G8B8: retVal = GL_BGRA; break;
1724 case WINED3DFMT_A8B8G8R8: retVal = GL_RGBA; break;
1725 case WINED3DFMT_A2R10G10B10: retVal = GL_BGRA; break;
1726 case WINED3DFMT_X8R8G8B8: retVal = GL_BGRA; break;
1727 case WINED3DFMT_A16B16G16R16: retVal = GL_RGBA; break;
1729 case WINED3DFMT_A8: retVal = GL_ALPHA; break;
1730 /* Depth + Stencil */
1731 case WINED3DFMT_D24S8: retVal = GL_COLOR_INDEX; break;
1732 case WINED3DFMT_D24FS8: retVal = GL_COLOR_INDEX; break;
1733 case WINED3DFMT_D24X8: retVal = GL_COLOR_INDEX; break;
1734 case WINED3DFMT_D24X4S4: retVal = GL_COLOR_INDEX; break;
1735 case WINED3DFMT_D32: retVal = GL_COLOR_INDEX; break;
1736 case WINED3DFMT_D16: retVal = GL_COLOR_INDEX; break;
1737 case WINED3DFMT_D15S1: retVal = GL_COLOR_INDEX; break;
1738 case WINED3DFMT_D16_LOCKABLE: retVal = GL_COLOR_INDEX; break;
1740 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1745 TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1749 GLenum D3DFmt2GLType(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1752 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1754 case WINED3DFMT_DXT1: retVal = 0; break;
1755 case WINED3DFMT_DXT2: retVal = 0; break;
1756 case WINED3DFMT_DXT3: retVal = 0; break;
1757 case WINED3DFMT_DXT4: retVal = 0; break;
1758 case WINED3DFMT_DXT5: retVal = 0; break;
1760 /* stupid compiler */
1768 case WINED3DFMT_P8: retVal = GL_UNSIGNED_BYTE; break;
1769 case WINED3DFMT_A8P8: retVal = GL_UNSIGNED_BYTE; break;
1771 case WINED3DFMT_L8: retVal = GL_UNSIGNED_BYTE; break;
1772 case WINED3DFMT_L16: retVal = GL_UNSIGNED_SHORT; break;
1773 case WINED3DFMT_A8L8: retVal = GL_UNSIGNED_BYTE; break;
1774 case WINED3DFMT_A4L4: retVal = GL_UNSIGNED_BYTE; break;
1776 case WINED3DFMT_V8U8: retVal = GL_UNSIGNED_BYTE; break;
1777 case WINED3DFMT_V16U16: retVal = GL_UNSIGNED_SHORT; break;
1778 case WINED3DFMT_L6V5U5: retVal = GL_UNSIGNED_SHORT_5_5_5_1; break;
1779 case WINED3DFMT_X8L8V8U8: retVal = GL_UNSIGNED_BYTE; break;
1781 case WINED3DFMT_R3G3B2: retVal = GL_UNSIGNED_BYTE_2_3_3_REV; break;
1782 case WINED3DFMT_R5G6B5: retVal = GL_UNSIGNED_SHORT_5_6_5; break;
1783 case WINED3DFMT_R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
1784 case WINED3DFMT_A1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
1785 case WINED3DFMT_X1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
1786 case WINED3DFMT_A4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
1787 case WINED3DFMT_X4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
1788 case WINED3DFMT_A8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
1789 case WINED3DFMT_A8B8G8R8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
1790 case WINED3DFMT_A2R10G10B10: retVal = GL_UNSIGNED_INT_2_10_10_10_REV; break;
1791 case WINED3DFMT_X8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
1792 case WINED3DFMT_A16B16G16R16: retVal = GL_UNSIGNED_SHORT; break;
1794 case WINED3DFMT_A8: retVal = GL_ALPHA; break;
1795 /* Depth + Stencil */
1796 case WINED3DFMT_D24S8: retVal = GL_UNSIGNED_INT; break;
1797 case WINED3DFMT_D24FS8: retVal = GL_UNSIGNED_INT; break;
1798 case WINED3DFMT_D24X8: retVal = GL_UNSIGNED_INT; break;
1799 case WINED3DFMT_D24X4S4: retVal = GL_UNSIGNED_INT; break;
1800 case WINED3DFMT_D32: retVal = GL_UNSIGNED_INT; break;
1801 case WINED3DFMT_D16: retVal = GL_UNSIGNED_SHORT; break;
1802 case WINED3DFMT_D15S1: retVal = GL_UNSIGNED_SHORT; break;
1803 case WINED3DFMT_D16_LOCKABLE: retVal = GL_UNSIGNED_SHORT; break;
1804 /* compressed textures */
1805 case WINED3DFMT_DXT1: retVal = 0; break;
1806 case WINED3DFMT_DXT2: retVal = 0; break;
1807 case WINED3DFMT_DXT3: retVal = 0; break;
1808 case WINED3DFMT_DXT4: retVal = 0; break;
1809 case WINED3DFMT_DXT5: retVal = 0; break;
1812 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1813 retVal = GL_UNSIGNED_BYTE;
1817 TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
1821 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
1826 case WINED3DFMT_R3G3B2: retVal = 1; break;
1827 case WINED3DFMT_R5G6B5: retVal = 2; break;
1828 case WINED3DFMT_R8G8B8: retVal = 3; break;
1829 case WINED3DFMT_A1R5G5B5: retVal = 2; break;
1830 case WINED3DFMT_X1R5G5B5: retVal = 2; break;
1831 case WINED3DFMT_A4R4G4B4: retVal = 2; break;
1832 case WINED3DFMT_X4R4G4B4: retVal = 2; break;
1833 case WINED3DFMT_A8R8G8B8: retVal = 4; break;
1834 case WINED3DFMT_A8B8G8R8: retVal = 4; break;
1835 case WINED3DFMT_A2R10G10B10: retVal = 4; break;
1836 case WINED3DFMT_X8R8G8B8: retVal = 4; break;
1837 case WINED3DFMT_A16B16G16R16: retVal = 8; break;
1839 case WINED3DFMT_P8: retVal = 1; break;
1840 case WINED3DFMT_A8P8: retVal = 2; break;
1841 /* depth/stencil buffer */
1842 case WINED3DFMT_D16_LOCKABLE: retVal = 2; break;
1843 case WINED3DFMT_D16: retVal = 2; break;
1844 case WINED3DFMT_D32: retVal = 4; break;
1845 case WINED3DFMT_D15S1: retVal = 2; break;
1846 case WINED3DFMT_D24X4S4: retVal = 4; break;
1847 case WINED3DFMT_D24S8: retVal = 4; break;
1848 case WINED3DFMT_D24FS8: retVal = 4; break;
1849 case WINED3DFMT_D24X8: retVal = 4; break;
1851 case WINED3DFMT_L8: retVal = 1; break;
1852 case WINED3DFMT_L16: retVal = 2; break;
1853 case WINED3DFMT_A4L4: retVal = 1; break;
1854 case WINED3DFMT_A8L8: retVal = 2; break;
1856 case WINED3DFMT_V8U8: retVal = 2; break;
1857 case WINED3DFMT_L6V5U5: retVal = 2; break;
1858 case WINED3DFMT_V16U16: retVal = 4; break;
1859 case WINED3DFMT_X8L8V8U8: retVal = 4; break;
1860 case WINED3DFMT_Q8W8V8U8: retVal = 4; break;
1861 case WINED3DFMT_Q16W16V16U16: retVal = 8; break;
1863 case WINED3DFMT_DXT1: retVal = 1; break; /* Actually 8 bytes per 16 pixels - Special cased later */
1864 case WINED3DFMT_DXT2: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1865 case WINED3DFMT_DXT3: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1866 case WINED3DFMT_DXT4: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1867 case WINED3DFMT_DXT5: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
1869 case WINED3DFMT_A8: retVal = 1; break;
1871 case WINED3DFMT_UNKNOWN:
1872 /* Guess at the highest value of the above */
1873 TRACE("WINED3DFMT_UNKNOWN - Guessing at 8 bytes/pixel %u\n", fmt);
1878 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
1881 TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
1885 /* Convertes a D3D format into a OpenGL configuration format */
1886 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate){
1887 #define PUSH1(att) attribs[(*nAttribs)++] = (att);
1888 #define PUSH2(att,value) attribs[(*nAttribs)++] = (att); attribs[(*nAttribs)++] = (value);
1889 /*We need to do some Card specific stuff in here at some point,
1890 D3D now supports floating point format buffers, and there are a number of different OpelGl ways of managing these e.g.
1891 GLX_ATI_pixel_format_float
1893 switch (BackBufferFormat) {
1896 PUSH2(GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT);
1897 PUSH2(GLX_BUFFER_SIZE, 8);
1898 PUSH2(GLX_DOUBLEBUFFER, TRUE);
1901 case WINED3DFMT_R3G3B2:
1902 PUSH2(GLX_RENDER_TYPE, GLX_RGBA_BIT);
1903 PUSH2(GLX_RED_SIZE, 3);
1904 PUSH2(GLX_GREEN_SIZE, 3);
1905 PUSH2(GLX_BLUE_SIZE, 2);
1908 case WINED3DFMT_A1R5G5B5:
1909 PUSH2(GLX_ALPHA_SIZE, 1);
1910 case WINED3DFMT_X1R5G5B5:
1911 PUSH2(GLX_RED_SIZE, 5);
1912 PUSH2(GLX_GREEN_SIZE, 5);
1913 PUSH2(GLX_BLUE_SIZE, 5);
1916 case WINED3DFMT_R5G6B5:
1917 PUSH2(GLX_RED_SIZE, 5);
1918 PUSH2(GLX_GREEN_SIZE, 6);
1919 PUSH2(GLX_BLUE_SIZE, 5);
1922 case WINED3DFMT_A4R4G4B4:
1923 PUSH2(GLX_ALPHA_SIZE, 4);
1924 case WINED3DFMT_X4R4G4B4:
1925 PUSH2(GLX_RED_SIZE, 4);
1926 PUSH2(GLX_GREEN_SIZE, 4);
1927 PUSH2(GLX_BLUE_SIZE, 4);
1930 case WINED3DFMT_A8R8G8B8:
1931 PUSH2(GLX_ALPHA_SIZE, 8);
1932 case WINED3DFMT_R8G8B8:
1933 case WINED3DFMT_X8R8G8B8:
1934 PUSH2(GLX_RED_SIZE, 8);
1935 PUSH2(GLX_GREEN_SIZE, 8);
1936 PUSH2(GLX_BLUE_SIZE, 8);
1939 case WINED3DFMT_A2R10G10B10:
1940 PUSH2(GLX_ALPHA_SIZE, 2);
1941 PUSH2(GLX_RED_SIZE, 10);
1942 PUSH2(GLX_GREEN_SIZE, 10);
1943 PUSH2(GLX_BLUE_SIZE, 10);
1946 case WINED3DFMT_A16B16G16R16:
1947 PUSH2(GLX_ALPHA_SIZE, 16);
1948 PUSH2(GLX_RED_SIZE, 16);
1949 PUSH2(GLX_GREEN_SIZE, 16);
1950 PUSH2(GLX_BLUE_SIZE, 16);
1954 FIXME("Unsupported color format: %s\n", debug_d3dformat(BackBufferFormat));
1958 switch (StencilBufferFormat) {
1962 case WINED3DFMT_D16_LOCKABLE:
1963 case WINED3DFMT_D16:
1964 PUSH2(GLX_DEPTH_SIZE, 16);
1967 case WINED3DFMT_D15S1:
1968 PUSH2(GLX_DEPTH_SIZE, 15);
1969 PUSH2(GLX_STENCIL_SIZE, 1);
1970 /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
1971 e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
1974 case WINED3DFMT_D24X8:
1975 PUSH2(GLX_DEPTH_SIZE, 24);
1978 case WINED3DFMT_D24X4S4:
1979 PUSH2(GLX_DEPTH_SIZE, 24);
1980 PUSH2(GLX_STENCIL_SIZE, 4);
1983 case WINED3DFMT_D24S8:
1984 PUSH2(GLX_DEPTH_SIZE, 24);
1985 PUSH2(GLX_STENCIL_SIZE, 8);
1988 case WINED3DFMT_D24FS8:
1989 PUSH2(GLX_DEPTH_SIZE, 24);
1990 PUSH2(GLX_STENCIL_SIZE, 8);
1993 case WINED3DFMT_D32:
1994 PUSH2(GLX_DEPTH_SIZE, 32);
1998 FIXME("Unsupported stencil format: %s\n", debug_d3dformat(StencilBufferFormat));
2002 } else { /* it the device doesn't support the 'exact' format, try to find something close */
2003 switch (StencilBufferFormat) {
2007 case WINED3DFMT_D16_LOCKABLE:
2008 case WINED3DFMT_D16:
2009 PUSH2(GLX_DEPTH_SIZE, 1);
2012 case WINED3DFMT_D15S1:
2013 PUSH2(GLX_DEPTH_SIZE, 1);
2014 PUSH2(GLX_STENCIL_SIZE, 1);
2015 /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
2016 e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
2019 case WINED3DFMT_D24X8:
2020 PUSH2(GLX_DEPTH_SIZE, 1);
2023 case WINED3DFMT_D24X4S4:
2024 PUSH2(GLX_DEPTH_SIZE, 1);
2025 PUSH2(GLX_STENCIL_SIZE, 1);
2028 case WINED3DFMT_D24S8:
2029 PUSH2(GLX_DEPTH_SIZE, 1);
2030 PUSH2(GLX_STENCIL_SIZE, 1);
2033 case WINED3DFMT_D24FS8:
2034 PUSH2(GLX_DEPTH_SIZE, 1);
2035 PUSH2(GLX_STENCIL_SIZE, 1);
2038 case WINED3DFMT_D32:
2039 PUSH2(GLX_DEPTH_SIZE, 1);
2043 FIXME("Unsupported stencil format: %s\n", debug_d3dformat(StencilBufferFormat));
2051 #undef GLINFO_LOCATION
2053 /* DirectDraw stuff */
2054 WINED3DFORMAT pixelformat_for_depth(DWORD depth) {
2056 case 8: return D3DFMT_P8; break;
2057 case 15: return WINED3DFMT_X1R5G5B5; break;
2058 case 16: return WINED3DFMT_R5G6B5; break;
2059 case 24: return WINED3DFMT_R8G8B8; break;
2060 case 32: return WINED3DFMT_X8R8G8B8; break;
2061 default: return WINED3DFMT_UNKNOWN;
2065 LONG get_bitmask_red(WINED3DFORMAT fmt)
2068 case WINED3DFMT_R8G8B8:
2069 case WINED3DFMT_A8R8G8B8:
2070 case WINED3DFMT_X8R8G8B8:
2073 case WINED3DFMT_X1R5G5B5:
2074 case WINED3DFMT_A1R5G5B5:
2077 case WINED3DFMT_A4R4G4B4:
2078 case WINED3DFMT_X4R4G4B4:
2081 case WINED3DFMT_R3G3B2:
2082 case WINED3DFMT_A8R3G3B2:
2085 case WINED3DFMT_A2R10G10B10:
2089 case WINED3DFMT_A2B10G10R10:
2092 case WINED3DFMT_A8B8G8R8:
2093 case WINED3DFMT_X8B8G8R8:
2096 case WINED3DFMT_R5G6B5:
2100 /* No fixed mask for this format */
2104 case WINED3DFMT_A16B16G16R16:
2105 return 0x00000000ffff;
2110 ERR("Unknown bitmask for format %d\n", fmt);
2115 LONG get_bitmask_green(WINED3DFORMAT fmt)
2118 case WINED3DFMT_R8G8B8:
2119 case WINED3DFMT_A8R8G8B8:
2120 case WINED3DFMT_X8R8G8B8:
2123 case WINED3DFMT_X1R5G5B5:
2124 case WINED3DFMT_A1R5G5B5:
2127 case WINED3DFMT_A4R4G4B4:
2128 case WINED3DFMT_X4R4G4B4:
2131 case WINED3DFMT_R3G3B2:
2132 case WINED3DFMT_A8R3G3B2:
2135 case WINED3DFMT_A2B10G10R10:
2138 case WINED3DFMT_A8B8G8R8:
2139 case WINED3DFMT_X8B8G8R8:
2143 case WINED3DFMT_A2R10G10B10:
2147 case WINED3DFMT_R5G6B5:
2151 /* No fixed mask for this format */
2155 case WINED3DFMT_A16B16G16R16:
2156 return 0x0000ffff0000;
2161 ERR("Unknown bitmask for format %d\n", fmt);
2166 LONG get_bitmask_blue(WINED3DFORMAT fmt)
2169 case WINED3DFMT_R8G8B8:
2170 case WINED3DFMT_A8R8G8B8:
2171 case WINED3DFMT_X8R8G8B8:
2174 case WINED3DFMT_X1R5G5B5:
2175 case WINED3DFMT_A1R5G5B5:
2178 case WINED3DFMT_A4R4G4B4:
2179 case WINED3DFMT_X4R4G4B4:
2182 case WINED3DFMT_R3G3B2:
2183 case WINED3DFMT_A8R3G3B2:
2186 case WINED3DFMT_A2B10G10R10:
2189 case WINED3DFMT_A8B8G8R8:
2190 case WINED3DFMT_X8B8G8R8:
2193 case WINED3DFMT_A2R10G10B10:
2196 case WINED3DFMT_R5G6B5:
2200 /* No fixed mask for this format */
2204 case WINED3DFMT_A16B16G16R16:
2205 return 0xffff00000000;
2210 ERR("Unknown bitmask for format %d\n", fmt);
2216 LONG get_bitmask_alpha(WINED3DFORMAT fmt)
2219 case WINED3DFMT_A8R8G8B8:
2222 case WINED3DFMT_A1R5G5B5:
2225 case WINED3DFMT_A4R4G4B4:
2228 case WINED3DFMT_A8R3G3B2:
2231 case WINED3DFMT_A2B10G10R10:
2234 case WINED3DFMT_A8B8G8R8:
2237 case WINED3DFMT_A2R10G10B10: