shell: Convert the filesystem shell folder to Unicode.
[wine/multimedia.git] / dlls / d3d8 / utils.c
blob8cd8766607bd59c1e46d1f7716270c40104d8b62
1 /*
2 * D3D8 utils
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <math.h>
25 #include <stdarg.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "wingdi.h"
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
39 const char* debug_d3ddevicetype(D3DDEVTYPE devtype) {
40 switch (devtype) {
41 #define DEVTYPE_TO_STR(dev) case dev: return #dev
42 DEVTYPE_TO_STR(D3DDEVTYPE_HAL);
43 DEVTYPE_TO_STR(D3DDEVTYPE_REF);
44 DEVTYPE_TO_STR(D3DDEVTYPE_SW);
45 #undef DEVTYPE_TO_STR
46 default:
47 FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
48 return "unrecognized";
52 const char* debug_d3dusage(DWORD usage) {
53 switch (usage) {
54 #define D3DUSAGE_TO_STR(u) case u: return #u
55 D3DUSAGE_TO_STR(D3DUSAGE_RENDERTARGET);
56 D3DUSAGE_TO_STR(D3DUSAGE_DEPTHSTENCIL);
57 D3DUSAGE_TO_STR(D3DUSAGE_WRITEONLY);
58 D3DUSAGE_TO_STR(D3DUSAGE_SOFTWAREPROCESSING);
59 D3DUSAGE_TO_STR(D3DUSAGE_DONOTCLIP);
60 D3DUSAGE_TO_STR(D3DUSAGE_POINTS);
61 D3DUSAGE_TO_STR(D3DUSAGE_RTPATCHES);
62 D3DUSAGE_TO_STR(D3DUSAGE_NPATCHES);
63 D3DUSAGE_TO_STR(D3DUSAGE_DYNAMIC);
64 #undef D3DUSAGE_TO_STR
65 case 0: return "none";
66 default:
67 FIXME("Unrecognized %lu Usage!\n", usage);
68 return "unrecognized";
72 const char* debug_d3dformat(D3DFORMAT fmt) {
73 switch (fmt) {
74 #define FMT_TO_STR(fmt) case fmt: return #fmt
75 FMT_TO_STR(D3DFMT_UNKNOWN);
76 FMT_TO_STR(D3DFMT_R8G8B8);
77 FMT_TO_STR(D3DFMT_A8R8G8B8);
78 FMT_TO_STR(D3DFMT_X8R8G8B8);
79 FMT_TO_STR(D3DFMT_R5G6B5);
80 FMT_TO_STR(D3DFMT_X1R5G5B5);
81 FMT_TO_STR(D3DFMT_A1R5G5B5);
82 FMT_TO_STR(D3DFMT_A4R4G4B4);
83 FMT_TO_STR(D3DFMT_R3G3B2);
84 FMT_TO_STR(D3DFMT_A8);
85 FMT_TO_STR(D3DFMT_A8R3G3B2);
86 FMT_TO_STR(D3DFMT_X4R4G4B4);
87 FMT_TO_STR(D3DFMT_A8P8);
88 FMT_TO_STR(D3DFMT_P8);
89 FMT_TO_STR(D3DFMT_L8);
90 FMT_TO_STR(D3DFMT_A8L8);
91 FMT_TO_STR(D3DFMT_A4L4);
92 FMT_TO_STR(D3DFMT_V8U8);
93 FMT_TO_STR(D3DFMT_L6V5U5);
94 FMT_TO_STR(D3DFMT_X8L8V8U8);
95 FMT_TO_STR(D3DFMT_Q8W8V8U8);
96 FMT_TO_STR(D3DFMT_V16U16);
97 FMT_TO_STR(D3DFMT_W11V11U10);
98 FMT_TO_STR(D3DFMT_UYVY);
99 FMT_TO_STR(D3DFMT_YUY2);
100 FMT_TO_STR(D3DFMT_DXT1);
101 FMT_TO_STR(D3DFMT_DXT2);
102 FMT_TO_STR(D3DFMT_DXT3);
103 FMT_TO_STR(D3DFMT_DXT4);
104 FMT_TO_STR(D3DFMT_DXT5);
105 FMT_TO_STR(D3DFMT_D16_LOCKABLE);
106 FMT_TO_STR(D3DFMT_D32);
107 FMT_TO_STR(D3DFMT_D15S1);
108 FMT_TO_STR(D3DFMT_D24S8);
109 FMT_TO_STR(D3DFMT_D16);
110 FMT_TO_STR(D3DFMT_D24X8);
111 FMT_TO_STR(D3DFMT_D24X4S4);
112 FMT_TO_STR(D3DFMT_VERTEXDATA);
113 FMT_TO_STR(D3DFMT_INDEX16);
114 FMT_TO_STR(D3DFMT_INDEX32);
115 #undef FMT_TO_STR
116 default:
117 FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
118 return "unrecognized";
122 const char* debug_d3dressourcetype(D3DRESOURCETYPE res) {
123 switch (res) {
124 #define RES_TO_STR(res) case res: return #res;
125 RES_TO_STR(D3DRTYPE_SURFACE);
126 RES_TO_STR(D3DRTYPE_VOLUME);
127 RES_TO_STR(D3DRTYPE_TEXTURE);
128 RES_TO_STR(D3DRTYPE_VOLUMETEXTURE);
129 RES_TO_STR(D3DRTYPE_CUBETEXTURE);
130 RES_TO_STR(D3DRTYPE_VERTEXBUFFER);
131 RES_TO_STR(D3DRTYPE_INDEXBUFFER);
132 #undef RES_TO_STR
133 default:
134 FIXME("Unrecognized %u D3DRESOURCETYPE!\n", res);
135 return "unrecognized";
139 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType) {
140 switch (PrimitiveType) {
141 #define PRIM_TO_STR(prim) case prim: return #prim;
142 PRIM_TO_STR(D3DPT_POINTLIST);
143 PRIM_TO_STR(D3DPT_LINELIST);
144 PRIM_TO_STR(D3DPT_LINESTRIP);
145 PRIM_TO_STR(D3DPT_TRIANGLELIST);
146 PRIM_TO_STR(D3DPT_TRIANGLESTRIP);
147 PRIM_TO_STR(D3DPT_TRIANGLEFAN);
148 #undef PRIM_TO_STR
149 default:
150 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
151 return "unrecognized";
155 const char* debug_d3dpool(D3DPOOL Pool) {
156 switch (Pool) {
157 #define POOL_TO_STR(p) case p: return #p;
158 POOL_TO_STR(D3DPOOL_DEFAULT);
159 POOL_TO_STR(D3DPOOL_MANAGED);
160 POOL_TO_STR(D3DPOOL_SYSTEMMEM);
161 POOL_TO_STR(D3DPOOL_SCRATCH);
162 #undef POOL_TO_STR
163 default:
164 FIXME("Unrecognized %u D3DPOOL!\n", Pool);
165 return "unrecognized";
169 const char* debug_d3drenderstate(DWORD state) {
170 switch (state) {
171 #define D3DSTATE_TO_STR(u) case u: return #u
172 D3DSTATE_TO_STR(D3DRS_ZENABLE );
173 D3DSTATE_TO_STR(D3DRS_FILLMODE );
174 D3DSTATE_TO_STR(D3DRS_SHADEMODE );
175 D3DSTATE_TO_STR(D3DRS_LINEPATTERN );
176 D3DSTATE_TO_STR(D3DRS_ZWRITEENABLE );
177 D3DSTATE_TO_STR(D3DRS_ALPHATESTENABLE );
178 D3DSTATE_TO_STR(D3DRS_LASTPIXEL );
179 D3DSTATE_TO_STR(D3DRS_SRCBLEND );
180 D3DSTATE_TO_STR(D3DRS_DESTBLEND );
181 D3DSTATE_TO_STR(D3DRS_CULLMODE );
182 D3DSTATE_TO_STR(D3DRS_ZFUNC );
183 D3DSTATE_TO_STR(D3DRS_ALPHAREF );
184 D3DSTATE_TO_STR(D3DRS_ALPHAFUNC );
185 D3DSTATE_TO_STR(D3DRS_DITHERENABLE );
186 D3DSTATE_TO_STR(D3DRS_ALPHABLENDENABLE );
187 D3DSTATE_TO_STR(D3DRS_FOGENABLE );
188 D3DSTATE_TO_STR(D3DRS_SPECULARENABLE );
189 D3DSTATE_TO_STR(D3DRS_ZVISIBLE );
190 D3DSTATE_TO_STR(D3DRS_FOGCOLOR );
191 D3DSTATE_TO_STR(D3DRS_FOGTABLEMODE );
192 D3DSTATE_TO_STR(D3DRS_FOGSTART );
193 D3DSTATE_TO_STR(D3DRS_FOGEND );
194 D3DSTATE_TO_STR(D3DRS_FOGDENSITY );
195 D3DSTATE_TO_STR(D3DRS_EDGEANTIALIAS );
196 D3DSTATE_TO_STR(D3DRS_ZBIAS );
197 D3DSTATE_TO_STR(D3DRS_RANGEFOGENABLE );
198 D3DSTATE_TO_STR(D3DRS_STENCILENABLE );
199 D3DSTATE_TO_STR(D3DRS_STENCILFAIL );
200 D3DSTATE_TO_STR(D3DRS_STENCILZFAIL );
201 D3DSTATE_TO_STR(D3DRS_STENCILPASS );
202 D3DSTATE_TO_STR(D3DRS_STENCILFUNC );
203 D3DSTATE_TO_STR(D3DRS_STENCILREF );
204 D3DSTATE_TO_STR(D3DRS_STENCILMASK );
205 D3DSTATE_TO_STR(D3DRS_STENCILWRITEMASK );
206 D3DSTATE_TO_STR(D3DRS_TEXTUREFACTOR );
207 D3DSTATE_TO_STR(D3DRS_WRAP0 );
208 D3DSTATE_TO_STR(D3DRS_WRAP1 );
209 D3DSTATE_TO_STR(D3DRS_WRAP2 );
210 D3DSTATE_TO_STR(D3DRS_WRAP3 );
211 D3DSTATE_TO_STR(D3DRS_WRAP4 );
212 D3DSTATE_TO_STR(D3DRS_WRAP5 );
213 D3DSTATE_TO_STR(D3DRS_WRAP6 );
214 D3DSTATE_TO_STR(D3DRS_WRAP7 );
215 D3DSTATE_TO_STR(D3DRS_CLIPPING );
216 D3DSTATE_TO_STR(D3DRS_LIGHTING );
217 D3DSTATE_TO_STR(D3DRS_AMBIENT );
218 D3DSTATE_TO_STR(D3DRS_FOGVERTEXMODE );
219 D3DSTATE_TO_STR(D3DRS_COLORVERTEX );
220 D3DSTATE_TO_STR(D3DRS_LOCALVIEWER );
221 D3DSTATE_TO_STR(D3DRS_NORMALIZENORMALS );
222 D3DSTATE_TO_STR(D3DRS_DIFFUSEMATERIALSOURCE );
223 D3DSTATE_TO_STR(D3DRS_SPECULARMATERIALSOURCE );
224 D3DSTATE_TO_STR(D3DRS_AMBIENTMATERIALSOURCE );
225 D3DSTATE_TO_STR(D3DRS_EMISSIVEMATERIALSOURCE );
226 D3DSTATE_TO_STR(D3DRS_VERTEXBLEND );
227 D3DSTATE_TO_STR(D3DRS_CLIPPLANEENABLE );
228 D3DSTATE_TO_STR(D3DRS_SOFTWAREVERTEXPROCESSING );
229 D3DSTATE_TO_STR(D3DRS_POINTSIZE );
230 D3DSTATE_TO_STR(D3DRS_POINTSIZE_MIN );
231 D3DSTATE_TO_STR(D3DRS_POINTSPRITEENABLE );
232 D3DSTATE_TO_STR(D3DRS_POINTSCALEENABLE );
233 D3DSTATE_TO_STR(D3DRS_POINTSCALE_A );
234 D3DSTATE_TO_STR(D3DRS_POINTSCALE_B );
235 D3DSTATE_TO_STR(D3DRS_POINTSCALE_C );
236 D3DSTATE_TO_STR(D3DRS_MULTISAMPLEANTIALIAS );
237 D3DSTATE_TO_STR(D3DRS_MULTISAMPLEMASK );
238 D3DSTATE_TO_STR(D3DRS_PATCHEDGESTYLE );
239 D3DSTATE_TO_STR(D3DRS_PATCHSEGMENTS );
240 D3DSTATE_TO_STR(D3DRS_DEBUGMONITORTOKEN );
241 D3DSTATE_TO_STR(D3DRS_POINTSIZE_MAX );
242 D3DSTATE_TO_STR(D3DRS_INDEXEDVERTEXBLENDENABLE );
243 D3DSTATE_TO_STR(D3DRS_COLORWRITEENABLE );
244 D3DSTATE_TO_STR(D3DRS_TWEENFACTOR );
245 D3DSTATE_TO_STR(D3DRS_BLENDOP );
246 D3DSTATE_TO_STR(D3DRS_POSITIONORDER );
247 D3DSTATE_TO_STR(D3DRS_NORMALORDER );
248 #undef D3DSTATE_TO_STR
249 default:
250 FIXME("Unrecognized %lu render state!\n", state);
251 return "unrecognized";
255 const char* debug_d3dtexturestate(DWORD state) {
256 switch (state) {
257 #define D3DSTATE_TO_STR(u) case u: return #u
258 D3DSTATE_TO_STR(D3DTSS_COLOROP );
259 D3DSTATE_TO_STR(D3DTSS_COLORARG1 );
260 D3DSTATE_TO_STR(D3DTSS_COLORARG2 );
261 D3DSTATE_TO_STR(D3DTSS_ALPHAOP );
262 D3DSTATE_TO_STR(D3DTSS_ALPHAARG1 );
263 D3DSTATE_TO_STR(D3DTSS_ALPHAARG2 );
264 D3DSTATE_TO_STR(D3DTSS_BUMPENVMAT00 );
265 D3DSTATE_TO_STR(D3DTSS_BUMPENVMAT01 );
266 D3DSTATE_TO_STR(D3DTSS_BUMPENVMAT10 );
267 D3DSTATE_TO_STR(D3DTSS_BUMPENVMAT11 );
268 D3DSTATE_TO_STR(D3DTSS_TEXCOORDINDEX );
269 D3DSTATE_TO_STR(D3DTSS_ADDRESSU );
270 D3DSTATE_TO_STR(D3DTSS_ADDRESSV );
271 D3DSTATE_TO_STR(D3DTSS_BORDERCOLOR );
272 D3DSTATE_TO_STR(D3DTSS_MAGFILTER );
273 D3DSTATE_TO_STR(D3DTSS_MINFILTER );
274 D3DSTATE_TO_STR(D3DTSS_MIPFILTER );
275 D3DSTATE_TO_STR(D3DTSS_MIPMAPLODBIAS );
276 D3DSTATE_TO_STR(D3DTSS_MAXMIPLEVEL );
277 D3DSTATE_TO_STR(D3DTSS_MAXANISOTROPY );
278 D3DSTATE_TO_STR(D3DTSS_BUMPENVLSCALE );
279 D3DSTATE_TO_STR(D3DTSS_BUMPENVLOFFSET );
280 D3DSTATE_TO_STR(D3DTSS_TEXTURETRANSFORMFLAGS );
281 D3DSTATE_TO_STR(D3DTSS_ADDRESSW );
282 D3DSTATE_TO_STR(D3DTSS_COLORARG0 );
283 D3DSTATE_TO_STR(D3DTSS_ALPHAARG0 );
284 D3DSTATE_TO_STR(D3DTSS_RESULTARG );
285 #undef D3DSTATE_TO_STR
286 case 12:
287 /* Note D3DTSS are not consecutive, so skip these */
288 return "unused";
289 default:
290 FIXME("Unrecognized %lu texture state!\n", state);
291 return "unrecognized";
296 * Simple utility routines used for dx -> gl mapping of byte formats
298 int D3DPrimitiveListGetVertexSize(D3DPRIMITIVETYPE PrimitiveType, int iNumPrim) {
299 switch (PrimitiveType) {
300 case D3DPT_POINTLIST: return iNumPrim;
301 case D3DPT_LINELIST: return iNumPrim * 2;
302 case D3DPT_LINESTRIP: return iNumPrim + 1;
303 case D3DPT_TRIANGLELIST: return iNumPrim * 3;
304 case D3DPT_TRIANGLESTRIP: return iNumPrim + 2;
305 case D3DPT_TRIANGLEFAN: return iNumPrim + 2;
306 default:
307 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
308 return 0;
312 int D3DPrimitive2GLenum(D3DPRIMITIVETYPE PrimitiveType) {
313 switch (PrimitiveType) {
314 case D3DPT_POINTLIST: return GL_POINTS;
315 case D3DPT_LINELIST: return GL_LINES;
316 case D3DPT_LINESTRIP: return GL_LINE_STRIP;
317 case D3DPT_TRIANGLELIST: return GL_TRIANGLES;
318 case D3DPT_TRIANGLESTRIP: return GL_TRIANGLE_STRIP;
319 case D3DPT_TRIANGLEFAN: return GL_TRIANGLE_FAN;
320 default:
321 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
322 return GL_POLYGON;
326 int D3DFVFGetSize(D3DFORMAT fvf) {
327 int ret = 0;
328 if (fvf & D3DFVF_XYZ) ret += 3 * sizeof(float);
329 else if (fvf & D3DFVF_XYZRHW) ret += 4 * sizeof(float);
330 if (fvf & D3DFVF_NORMAL) ret += 3 * sizeof(float);
331 if (fvf & D3DFVF_PSIZE) ret += sizeof(float);
332 if (fvf & D3DFVF_DIFFUSE) ret += sizeof(DWORD);
333 if (fvf & D3DFVF_SPECULAR) ret += sizeof(DWORD);
334 /*if (fvf & D3DFVF_TEX1) ret += 1;*/
335 return ret;
338 GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt) {
339 switch (fmt) {
340 /* depth/stencil buffer */
341 case D3DFMT_D16_LOCKABLE:
342 case D3DFMT_D16:
343 case D3DFMT_D15S1:
344 case D3DFMT_D24X4S4:
345 case D3DFMT_D24S8:
346 case D3DFMT_D24X8:
347 case D3DFMT_D32:
348 return GL_DEPTH_COMPONENT;
349 default:
350 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
352 return 0;
355 GLenum D3DFmt2GLDepthType(D3DFORMAT fmt) {
356 switch (fmt) {
357 /* depth/stencil buffer */
358 case D3DFMT_D15S1:
359 case D3DFMT_D16_LOCKABLE:
360 case D3DFMT_D16:
361 return GL_UNSIGNED_SHORT;
362 case D3DFMT_D24X4S4:
363 case D3DFMT_D24S8:
364 case D3DFMT_D24X8:
365 case D3DFMT_D32:
366 return GL_UNSIGNED_INT;
367 default:
368 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
370 return 0;
373 SHORT D3DFmtGetBpp(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
374 SHORT retVal;
376 switch (fmt) {
377 /* color buffer */
378 case D3DFMT_R3G3B2: retVal = 1; break;
379 case D3DFMT_R5G6B5: retVal = 2; break;
380 case D3DFMT_R8G8B8: retVal = 3; break;
381 case D3DFMT_A1R5G5B5: retVal = 2; break;
382 case D3DFMT_X1R5G5B5: retVal = 2; break;
383 case D3DFMT_A4R4G4B4: retVal = 2; break;
384 case D3DFMT_X4R4G4B4: retVal = 2; break;
385 case D3DFMT_A8R8G8B8: retVal = 4; break;
386 case D3DFMT_X8R8G8B8: retVal = 4; break;
387 /* Paletted */
388 case D3DFMT_P8: retVal = 1; break;
389 case D3DFMT_A8P8: retVal = 2; break;
390 /* depth/stencil buffer */
391 case D3DFMT_D16_LOCKABLE: retVal = 2; break;
392 case D3DFMT_D16: retVal = 2; break;
393 case D3DFMT_D32: retVal = 4; break;
394 case D3DFMT_D15S1: retVal = 2; break;
395 case D3DFMT_D24X4S4: retVal = 4; break;
396 case D3DFMT_D24S8: retVal = 4; break;
397 case D3DFMT_D24X8: retVal = 4; break;
398 /* Luminance */
399 case D3DFMT_L8: retVal = 1; break;
400 case D3DFMT_A4L4: retVal = 1; break;
401 case D3DFMT_A8L8: retVal = 2; break;
402 /* Bump */
403 case D3DFMT_V8U8: retVal = 2; break;
404 case D3DFMT_L6V5U5: retVal = 2; break;
405 case D3DFMT_V16U16: retVal = 4; break;
406 case D3DFMT_X8L8V8U8: retVal = 4; break;
407 /* Compressed */
408 case D3DFMT_DXT1: retVal = 1; break; /* Actually 8 bytes per 16 pixels - Special cased later */
409 case D3DFMT_DXT2: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
410 case D3DFMT_DXT3: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
411 case D3DFMT_DXT4: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
412 case D3DFMT_DXT5: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
413 /* to see */
414 case D3DFMT_A8: retVal = 1; break;
415 /* unknown */
416 case D3DFMT_UNKNOWN:
417 /* Guess at the highest value of the above */
418 TRACE("D3DFMT_UNKNOWN - Guessing at 4 bytes/pixel %u\n", fmt);
419 retVal = 4;
420 break;
422 default:
423 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
424 retVal = 4;
426 TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
427 return retVal;
430 GLint D3DFmt2GLIntFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
431 GLint retVal = 0;
433 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
434 switch (fmt) {
435 case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
436 case D3DFMT_DXT2: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
437 case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
438 case D3DFMT_DXT4: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
439 case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
440 default:
441 /* stupid compiler */
442 break;
446 if (retVal == 0) {
447 switch (fmt) {
448 /* Paletted */
449 case D3DFMT_P8: retVal = GL_COLOR_INDEX8_EXT; break;
450 case D3DFMT_A8P8: retVal = GL_COLOR_INDEX8_EXT; break;
451 /* Luminance */
452 case D3DFMT_L8: retVal = GL_LUMINANCE8; break;
453 case D3DFMT_A8L8: retVal = GL_LUMINANCE8_ALPHA8; break;
454 case D3DFMT_A4L4: retVal = GL_LUMINANCE4_ALPHA4; break;
455 /* Bump */
456 case D3DFMT_V8U8: retVal = GL_COLOR_INDEX8_EXT; break;
457 case D3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
458 case D3DFMT_L6V5U5: retVal = GL_COLOR_INDEX8_EXT; break;
459 case D3DFMT_X8L8V8U8: retVal = GL_COLOR_INDEX; break;
460 /* color buffer */
461 case D3DFMT_R3G3B2: retVal = GL_R3_G3_B2; break;
462 case D3DFMT_R5G6B5: retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
463 case D3DFMT_R8G8B8: retVal = GL_RGB8; break;
464 case D3DFMT_A1R5G5B5: retVal = GL_RGB5_A1; break;
465 case D3DFMT_X1R5G5B5: retVal = GL_RGB5_A1; break;
466 case D3DFMT_A4R4G4B4: retVal = GL_RGBA4; break;
467 case D3DFMT_X4R4G4B4: retVal = GL_RGBA4; break;
468 case D3DFMT_A8R8G8B8: retVal = GL_RGBA8; break;
469 case D3DFMT_X8R8G8B8: retVal = GL_RGBA8; break;
470 /* to see */
471 case D3DFMT_A8: retVal = GL_ALPHA8; break;
472 default:
473 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
474 retVal = GL_RGB8;
477 TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
478 return retVal;
481 GLenum D3DFmt2GLFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
482 GLenum retVal = 0;
484 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
485 switch (fmt) {
486 case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
487 case D3DFMT_DXT2: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
488 case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
489 case D3DFMT_DXT4: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
490 case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
491 default:
492 /* stupid compiler */
493 break;
497 if (retVal == 0) {
498 switch (fmt) {
499 /* Paletted */
500 case D3DFMT_P8: retVal = GL_COLOR_INDEX; break;
501 case D3DFMT_A8P8: retVal = GL_COLOR_INDEX; break;
502 /* Luminance */
503 case D3DFMT_L8: retVal = GL_LUMINANCE; break;
504 case D3DFMT_A8L8: retVal = GL_LUMINANCE_ALPHA; break;
505 case D3DFMT_A4L4: retVal = GL_LUMINANCE_ALPHA; break;
506 /* Bump */
507 case D3DFMT_V8U8: retVal = GL_COLOR_INDEX; break;
508 case D3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
509 case D3DFMT_L6V5U5: retVal = GL_COLOR_INDEX; break;
510 case D3DFMT_X8L8V8U8: retVal = GL_COLOR_INDEX; break;
511 /* color buffer */
512 case D3DFMT_R3G3B2: retVal = GL_BGR; break;
513 case D3DFMT_R5G6B5: retVal = GL_RGB; break;
514 case D3DFMT_R8G8B8: retVal = GL_RGB; break;
515 case D3DFMT_A1R5G5B5: retVal = GL_BGRA; break;
516 case D3DFMT_X1R5G5B5: retVal = GL_BGRA; break;
517 case D3DFMT_A4R4G4B4: retVal = GL_BGRA; break;
518 case D3DFMT_X4R4G4B4: retVal = GL_BGRA; break;
519 case D3DFMT_A8R8G8B8: retVal = GL_BGRA; break;
520 case D3DFMT_X8R8G8B8: retVal = GL_BGRA; break;
521 /* to see */
522 case D3DFMT_A8: retVal = GL_ALPHA; break;
523 default:
524 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
525 retVal = GL_BGR;
529 TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
530 return retVal;
533 GLenum D3DFmt2GLType(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
534 GLenum retVal = 0;
536 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
537 switch (fmt) {
538 case D3DFMT_DXT1: retVal = 0; break;
539 case D3DFMT_DXT2: retVal = 0; break;
540 case D3DFMT_DXT3: retVal = 0; break;
541 case D3DFMT_DXT4: retVal = 0; break;
542 case D3DFMT_DXT5: retVal = 0; break;
543 default:
544 /* stupid compiler */
545 break;
549 if (retVal == 0) {
550 switch (fmt) {
551 /* Paletted */
552 case D3DFMT_P8: retVal = GL_UNSIGNED_BYTE; break;
553 case D3DFMT_A8P8: retVal = GL_UNSIGNED_BYTE; break;
554 /* Luminance */
555 case D3DFMT_L8: retVal = GL_UNSIGNED_BYTE; break;
556 case D3DFMT_A8L8: retVal = GL_UNSIGNED_BYTE; break;
557 case D3DFMT_A4L4: retVal = GL_UNSIGNED_BYTE; break;
558 /* Bump */
559 case D3DFMT_V8U8: retVal = GL_UNSIGNED_BYTE; break;
560 case D3DFMT_V16U16: retVal = GL_UNSIGNED_SHORT; break;
561 case D3DFMT_L6V5U5: retVal = GL_UNSIGNED_SHORT_5_5_5_1; break;
562 case D3DFMT_X8L8V8U8: retVal = GL_UNSIGNED_BYTE; break;
563 /* Color buffer */
564 case D3DFMT_R3G3B2: retVal = GL_UNSIGNED_BYTE_2_3_3_REV; break;
565 case D3DFMT_R5G6B5: retVal = GL_UNSIGNED_SHORT_5_6_5; break;
566 case D3DFMT_R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
567 case D3DFMT_A1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
568 case D3DFMT_X1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
569 case D3DFMT_A4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
570 case D3DFMT_X4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
571 case D3DFMT_A8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
572 case D3DFMT_X8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
573 /* to see */
574 case D3DFMT_A8: retVal = GL_ALPHA; break;
575 default:
576 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
577 retVal = GL_UNSIGNED_BYTE;
581 TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
582 return retVal;
585 int SOURCEx_RGB_EXT(DWORD arg) {
586 switch(arg) {
587 case D3DTSS_COLORARG0: return GL_SOURCE2_RGB_EXT;
588 case D3DTSS_COLORARG1: return GL_SOURCE0_RGB_EXT;
589 case D3DTSS_COLORARG2: return GL_SOURCE1_RGB_EXT;
590 case D3DTSS_ALPHAARG0:
591 case D3DTSS_ALPHAARG1:
592 case D3DTSS_ALPHAARG2:
593 default:
594 FIXME("Invalid arg %ld\n", arg);
595 return GL_SOURCE0_RGB_EXT;
599 int OPERANDx_RGB_EXT(DWORD arg) {
600 switch(arg) {
601 case D3DTSS_COLORARG0: return GL_OPERAND2_RGB_EXT;
602 case D3DTSS_COLORARG1: return GL_OPERAND0_RGB_EXT;
603 case D3DTSS_COLORARG2: return GL_OPERAND1_RGB_EXT;
604 case D3DTSS_ALPHAARG0:
605 case D3DTSS_ALPHAARG1:
606 case D3DTSS_ALPHAARG2:
607 default:
608 FIXME("Invalid arg %ld\n", arg);
609 return GL_OPERAND0_RGB_EXT;
613 int SOURCEx_ALPHA_EXT(DWORD arg) {
614 switch(arg) {
615 case D3DTSS_ALPHAARG0: return GL_SOURCE2_ALPHA_EXT;
616 case D3DTSS_ALPHAARG1: return GL_SOURCE0_ALPHA_EXT;
617 case D3DTSS_ALPHAARG2: return GL_SOURCE1_ALPHA_EXT;
618 case D3DTSS_COLORARG0:
619 case D3DTSS_COLORARG1:
620 case D3DTSS_COLORARG2:
621 default:
622 FIXME("Invalid arg %ld\n", arg);
623 return GL_SOURCE0_ALPHA_EXT;
627 int OPERANDx_ALPHA_EXT(DWORD arg) {
628 switch(arg) {
629 case D3DTSS_ALPHAARG0: return GL_OPERAND2_ALPHA_EXT;
630 case D3DTSS_ALPHAARG1: return GL_OPERAND0_ALPHA_EXT;
631 case D3DTSS_ALPHAARG2: return GL_OPERAND1_ALPHA_EXT;
632 case D3DTSS_COLORARG0:
633 case D3DTSS_COLORARG1:
634 case D3DTSS_COLORARG2:
635 default:
636 FIXME("Invalid arg %ld\n", arg);
637 return GL_OPERAND0_ALPHA_EXT;
641 GLenum StencilOp(DWORD op) {
642 switch(op) {
643 case D3DSTENCILOP_KEEP : return GL_KEEP;
644 case D3DSTENCILOP_ZERO : return GL_ZERO;
645 case D3DSTENCILOP_REPLACE : return GL_REPLACE;
646 case D3DSTENCILOP_INCRSAT : return GL_INCR;
647 case D3DSTENCILOP_DECRSAT : return GL_DECR;
648 case D3DSTENCILOP_INVERT : return GL_INVERT;
649 case D3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
650 case D3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
651 default:
652 FIXME("Invalid stencil op %ld\n", op);
653 return GL_ALWAYS;
658 * @nodoc: todo
660 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand)
662 BOOL isAlphaReplicate = FALSE;
663 BOOL isComplement = FALSE;
665 *operand = GL_SRC_COLOR;
666 *source = GL_TEXTURE;
668 /* Catch alpha replicate */
669 if (iValue & D3DTA_ALPHAREPLICATE) {
670 iValue = iValue & ~D3DTA_ALPHAREPLICATE;
671 isAlphaReplicate = TRUE;
674 /* Catch Complement */
675 if (iValue & D3DTA_COMPLEMENT) {
676 iValue = iValue & ~D3DTA_COMPLEMENT;
677 isComplement = TRUE;
680 /* Calculate the operand */
681 if (isAlphaReplicate && !isComplement) {
682 *operand = GL_SRC_ALPHA;
683 } else if (isAlphaReplicate && isComplement) {
684 *operand = GL_ONE_MINUS_SRC_ALPHA;
685 } else if (isComplement) {
686 if (isAlphaArg) {
687 *operand = GL_ONE_MINUS_SRC_ALPHA;
688 } else {
689 *operand = GL_ONE_MINUS_SRC_COLOR;
691 } else {
692 if (isAlphaArg) {
693 *operand = GL_SRC_ALPHA;
694 } else {
695 *operand = GL_SRC_COLOR;
699 /* Calculate the source */
700 switch (iValue & D3DTA_SELECTMASK) {
701 case D3DTA_CURRENT: *source = GL_PREVIOUS_EXT;
702 break;
703 case D3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT;
704 break;
705 case D3DTA_TEXTURE: *source = GL_TEXTURE;
706 break;
707 case D3DTA_TFACTOR: *source = GL_CONSTANT_EXT;
708 break;
709 case D3DTA_SPECULAR:
711 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
712 * 'Secondary color' and isn't supported until base GL supports it
713 * There is no concept of temp registers as far as I can tell
715 FIXME("Unhandled texture arg D3DTA_SPECULAR\n");
716 *source = GL_TEXTURE;
717 break;
719 default:
720 FIXME("Unrecognized texture arg %ld\n", iValue);
721 *source = GL_TEXTURE;
726 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
727 #if defined (GL_VERSION_1_3)
728 # define useext(A) A
729 # define combine_ext 1
730 #elif defined (GL_EXT_texture_env_combine)
731 # define useext(A) A##_EXT
732 # define combine_ext 1
733 #elif defined (GL_ARB_texture_env_combine)
734 # define useext(A) A##_ARB
735 # define combine_ext 1
736 #else
737 # undef combine_ext
738 #endif
740 #if !defined(combine_ext)
741 void set_tex_op(LPDIRECT3DDEVICE8 iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
743 FIXME("Requires opengl combine extensions to work\n");
744 return;
746 #else
747 /* Setup the texture operations texture stage states */
748 void set_tex_op(LPDIRECT3DDEVICE8 iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
750 GLenum src1, src2, src3;
751 GLenum opr1, opr2, opr3;
752 GLenum comb_target;
753 GLenum src0_target, src1_target, src2_target;
754 GLenum opr0_target, opr1_target, opr2_target;
755 GLenum scal_target;
756 GLenum opr=0, invopr, src3_target, opr3_target;
757 BOOL Handled = FALSE;
758 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
760 TRACE("Alpha?(%d), Stage:%d Op(%d), a1(%ld), a2(%ld), a3(%ld)\n", isAlpha, Stage, op, arg1, arg2, arg3);
762 ENTER_GL();
764 /* Note: Operations usually involve two ars, src0 and src1 and are operations of
765 the form (a1 <operation> a2). However, some of the more complex operations
766 take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
767 in a third parameter called a0. Therefore these are operations of the form
768 a0 <operation> a1 <operation> a2, ie the new parameter goes to the front.
770 However, below we treat the new (a0) parameter as src2/opr2, so in the actual
771 functions below, expect their syntax to differ slightly to those listed in the
772 manuals, ie replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
773 This affects D3DTOP_MULTIPLYADD and D3DTOP_LERP */
775 if (isAlpha) {
776 comb_target = useext(GL_COMBINE_ALPHA);
777 src0_target = useext(GL_SOURCE0_ALPHA);
778 src1_target = useext(GL_SOURCE1_ALPHA);
779 src2_target = useext(GL_SOURCE2_ALPHA);
780 opr0_target = useext(GL_OPERAND0_ALPHA);
781 opr1_target = useext(GL_OPERAND1_ALPHA);
782 opr2_target = useext(GL_OPERAND2_ALPHA);
783 scal_target = GL_ALPHA_SCALE;
785 else {
786 comb_target = useext(GL_COMBINE_RGB);
787 src0_target = useext(GL_SOURCE0_RGB);
788 src1_target = useext(GL_SOURCE1_RGB);
789 src2_target = useext(GL_SOURCE2_RGB);
790 opr0_target = useext(GL_OPERAND0_RGB);
791 opr1_target = useext(GL_OPERAND1_RGB);
792 opr2_target = useext(GL_OPERAND2_RGB);
793 scal_target = useext(GL_RGB_SCALE);
796 /* From MSDN (D3DTSS_ALPHAARG1) :
797 The default argument is D3DTA_TEXTURE. If no texture is set for this stage,
798 then the default argument is D3DTA_DIFFUSE.
799 FIXME? If texture added/removed, may need to reset back as well? */
800 if (isAlpha && This->StateBlock->textures[Stage] == NULL && arg1 == D3DTA_TEXTURE) {
801 GetSrcAndOpFromValue(D3DTA_DIFFUSE, isAlpha, &src1, &opr1);
802 } else {
803 GetSrcAndOpFromValue(arg1, isAlpha, &src1, &opr1);
805 GetSrcAndOpFromValue(arg2, isAlpha, &src2, &opr2);
806 GetSrcAndOpFromValue(arg3, isAlpha, &src3, &opr3);
808 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
810 Handled = TRUE; /* Assume will be handled */
812 /* Other texture operations require special extensions: */
813 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
814 if (isAlpha) {
815 opr = GL_SRC_ALPHA;
816 invopr = GL_ONE_MINUS_SRC_ALPHA;
817 src3_target = GL_SOURCE3_ALPHA_NV;
818 opr3_target = GL_OPERAND3_ALPHA_NV;
819 } else {
820 opr = GL_SRC_COLOR;
821 invopr = GL_ONE_MINUS_SRC_COLOR;
822 src3_target = GL_SOURCE3_RGB_NV;
823 opr3_target = GL_OPERAND3_RGB_NV;
825 switch (op) {
826 case D3DTOP_DISABLE: /* Only for alpha */
827 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
828 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
829 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
830 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
831 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
832 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
833 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
834 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
835 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
836 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
837 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
838 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
839 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
840 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
841 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
842 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
843 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
844 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
845 break;
846 case D3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */
847 case D3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */
848 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
849 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
850 if (op == D3DTOP_SELECTARG1) {
851 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
852 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
853 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
854 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
855 } else {
856 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
857 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
858 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
859 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
861 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
862 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
863 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
864 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
865 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
866 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
867 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
868 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
869 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
870 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
871 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
872 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
873 break;
875 case D3DTOP_MODULATE:
876 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
877 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
878 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
879 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
880 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
881 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
882 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
883 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
884 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
885 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
886 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
887 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
888 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
889 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
890 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
891 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
892 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
893 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
894 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
895 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
896 break;
897 case D3DTOP_MODULATE2X:
898 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
899 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
900 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
901 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
902 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
903 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
904 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
905 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
906 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
907 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
908 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
909 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
910 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
911 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
912 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
913 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
914 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
915 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
916 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
917 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
918 break;
919 case D3DTOP_MODULATE4X:
920 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
921 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
922 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
923 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
924 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
925 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
926 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
927 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
928 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
929 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
930 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
931 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
932 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
933 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
934 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
935 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
936 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
937 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
938 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
939 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
940 break;
942 case D3DTOP_ADD:
943 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
944 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
945 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
946 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
947 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
948 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
949 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
950 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
951 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
952 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
953 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
954 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
955 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
956 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
957 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
958 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
959 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
960 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
961 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
962 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
963 break;
965 case D3DTOP_ADDSIGNED:
966 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
967 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
968 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
969 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
970 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
971 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
972 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
973 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
974 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
975 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
976 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
977 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
978 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
979 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
980 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
981 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
982 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
983 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
984 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
985 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
986 break;
988 case D3DTOP_ADDSIGNED2X:
989 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
990 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
991 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
992 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
993 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
994 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
995 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
996 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
997 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
998 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
999 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1000 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1001 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1002 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1003 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1004 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1005 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1006 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1007 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1008 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1009 break;
1011 case D3DTOP_ADDSMOOTH:
1012 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1013 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1014 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1015 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1016 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1017 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1018 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1019 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1020 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1021 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1022 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1023 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1024 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1025 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1026 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1027 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1028 switch (opr1) {
1029 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1030 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1031 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1032 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1034 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1035 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1036 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1037 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1038 break;
1040 case D3DTOP_BLENDDIFFUSEALPHA:
1041 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1042 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1043 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1044 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1045 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1046 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1047 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
1048 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
1049 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1050 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1051 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1052 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1053 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1054 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1055 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
1056 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
1057 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1058 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1059 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1060 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1061 break;
1062 case D3DTOP_BLENDTEXTUREALPHA:
1063 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1064 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
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, GL_TEXTURE);
1070 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
1071 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1072 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1073 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1074 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1075 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1076 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1077 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1078 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1079 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1080 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1081 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1082 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1083 break;
1084 case D3DTOP_BLENDFACTORALPHA:
1085 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1086 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1087 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1088 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1089 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1090 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1091 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT));
1092 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
1093 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1094 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1095 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1096 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1097 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1098 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1099 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
1100 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
1101 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1102 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1103 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1104 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1105 break;
1106 case D3DTOP_BLENDTEXTUREALPHAPM:
1107 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1108 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1109 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1110 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1111 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1112 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1113 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1114 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1115 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1116 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1117 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1118 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1119 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1120 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1121 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1122 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1123 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1124 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1125 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1126 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1127 break;
1128 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1129 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1130 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
1131 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
1132 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1133 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1134 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
1135 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1136 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1137 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1138 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1139 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
1140 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1141 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1142 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
1143 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1144 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1145 switch (opr) {
1146 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1147 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1149 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1150 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1151 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1152 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1153 break;
1154 case D3DTOP_MODULATECOLOR_ADDALPHA:
1155 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1156 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1157 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1158 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1159 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1160 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1161 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1162 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1163 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1164 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1165 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1166 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1167 switch (opr1) {
1168 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1169 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1171 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1172 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1173 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1174 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1175 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1176 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1177 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1178 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1179 break;
1180 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1181 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1182 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1183 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1184 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1185 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1186 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1187 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1188 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1189 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1190 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1191 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1192 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1193 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1194 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1195 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1196 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1197 switch (opr1) {
1198 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1199 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1200 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1201 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1203 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1204 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1205 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1206 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1207 break;
1208 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1209 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1210 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1211 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1212 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1213 switch (opr1) {
1214 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1215 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1216 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1217 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1219 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1220 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1221 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1222 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1223 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1224 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1225 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1226 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1227 switch (opr1) {
1228 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1229 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1231 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1232 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1233 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1234 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1235 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1236 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1237 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1238 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1239 break;
1240 case D3DTOP_MULTIPLYADD:
1241 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1242 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1243 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1244 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1245 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1246 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1247 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1248 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1249 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1250 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1251 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1252 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1253 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
1254 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1255 glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
1256 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
1257 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
1258 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
1259 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1260 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1261 break;
1263 case D3DTOP_BUMPENVMAP:
1265 if (GL_SUPPORT(NV_TEXTURE_SHADER)) {
1267 texture unit 0: GL_TEXTURE_2D
1268 texture unit 1: GL_DOT_PRODUCT_NV
1269 texture unit 2: GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV
1270 texture unit 3: GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV
1272 float m[2][2];
1274 union {
1275 float f;
1276 DWORD d;
1277 } tmpvalue;
1279 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT00];
1280 m[0][0] = tmpvalue.f;
1281 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT01];
1282 m[0][1] = tmpvalue.f;
1283 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT10];
1284 m[1][0] = tmpvalue.f;
1285 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT11];
1286 m[1][1] = tmpvalue.f;
1288 /*FIXME("Stage %d matrix is (%.2f,%.2f),(%.2f,%.2f)\n", Stage, m[0][0], m[0][1], m[1][0], m[1][0]);*/
1290 if (FALSE == This->texture_shader_active) {
1291 This->texture_shader_active = TRUE;
1292 glEnable(GL_TEXTURE_SHADER_NV);
1296 glEnable(GL_REGISTER_COMBINERS_NV);
1297 glCombinerParameteriNV (GL_NUM_GENERAL_COMBINERS_NV, 1);
1298 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
1299 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
1300 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
1301 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
1302 glCombinerOutputNV (GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
1303 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
1304 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
1305 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
1306 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
1307 glCombinerOutputNV (GL_COMBINER0_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
1308 glDisable (GL_PER_STAGE_CONSTANTS_NV);
1309 glCombinerParameteriNV (GL_COLOR_SUM_CLAMP_NV, 0);
1310 glFinalCombinerInputNV (GL_VARIABLE_A_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1311 glFinalCombinerInputNV (GL_VARIABLE_B_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1312 glFinalCombinerInputNV (GL_VARIABLE_C_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1313 glFinalCombinerInputNV (GL_VARIABLE_D_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1314 glFinalCombinerInputNV (GL_VARIABLE_E_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1315 glFinalCombinerInputNV (GL_VARIABLE_F_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1316 glFinalCombinerInputNV (GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
1319 int i;
1320 for (i = 0; i < Stage; i++) {
1321 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1322 glActiveTexture(GL_TEXTURE0 + i);
1323 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
1324 checkGLcall("Activate texture..");
1325 } else if (i>0) {
1326 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1331 glActiveTextureARB(GL_TEXTURE0_ARB + Stage - 1);
1332 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
1335 glActiveTextureARB(GL_TEXTURE0_ARB + Stage);
1336 checkGLcall("Activate texture.. to update const color");
1337 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
1338 checkGLcall("glTexEnv");
1339 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + Stage - 1);
1340 checkGLcall("glTexEnv");
1341 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float*)&m[0]);
1342 checkGLcall("glTexEnv");
1344 LEAVE_GL();
1345 return;
1349 case D3DTOP_BUMPENVMAPLUMINANCE:
1351 default:
1352 Handled = FALSE;
1354 if (Handled) {
1355 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
1356 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
1358 LEAVE_GL();
1359 return;
1361 } /* GL_NV_texture_env_combine4 */
1363 Handled = TRUE; /* Again, assume handled */
1364 switch (op) {
1365 case D3DTOP_DISABLE: /* Only for alpha */
1366 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1367 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1368 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
1369 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
1370 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
1371 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
1372 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1373 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1374 break;
1375 case D3DTOP_SELECTARG1:
1376 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1377 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1378 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1379 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1380 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1381 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1382 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1383 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1384 break;
1385 case D3DTOP_SELECTARG2:
1386 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1387 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1388 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
1389 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1390 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1391 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1392 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1393 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1394 break;
1395 case D3DTOP_MODULATE:
1396 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1397 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1398 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1399 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1400 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1401 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1402 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1403 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1404 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1405 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1406 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1407 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1408 break;
1409 case D3DTOP_MODULATE2X:
1410 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1411 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1412 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1413 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1414 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1415 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1416 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1417 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1418 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1419 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1420 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1421 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1422 break;
1423 case D3DTOP_MODULATE4X:
1424 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1425 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1426 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1427 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1428 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1429 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1430 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1431 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1432 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1433 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1434 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1435 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1436 break;
1437 case D3DTOP_ADD:
1438 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1439 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1440 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1441 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1442 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1443 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1444 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1445 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1446 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1447 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1448 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1449 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1450 break;
1451 case D3DTOP_ADDSIGNED:
1452 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1453 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
1454 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1455 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1456 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1457 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1458 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1459 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1460 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1461 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1462 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1463 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1464 break;
1465 case D3DTOP_ADDSIGNED2X:
1466 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1467 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1468 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1469 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1470 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1471 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1472 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1473 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1474 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1475 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1476 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1477 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1478 break;
1479 case D3DTOP_SUBTRACT:
1480 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
1481 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
1482 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
1483 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1484 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1485 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1486 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1487 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1488 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1489 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1490 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1491 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1492 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1493 } else {
1494 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1496 break;
1498 case D3DTOP_BLENDDIFFUSEALPHA:
1499 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1500 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1501 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1502 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1503 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1504 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1505 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1506 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1507 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1508 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1509 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
1510 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
1511 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1512 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1513 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1514 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1515 break;
1516 case D3DTOP_BLENDTEXTUREALPHA:
1517 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1518 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1519 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1520 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1521 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1522 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1523 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1524 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1525 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1526 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1527 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
1528 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
1529 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1530 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1531 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1532 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1533 break;
1534 case D3DTOP_BLENDFACTORALPHA:
1535 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1536 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1537 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1538 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1539 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1540 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1541 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1542 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1543 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1544 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1545 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
1546 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
1547 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1548 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1549 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1550 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1551 break;
1552 case D3DTOP_BLENDCURRENTALPHA:
1553 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1554 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1555 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1556 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1557 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1558 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1559 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1560 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1561 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1562 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1563 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
1564 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
1565 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1566 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1567 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1568 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1569 break;
1570 case D3DTOP_DOTPRODUCT3:
1571 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
1572 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
1573 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
1574 } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
1575 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
1576 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
1577 } else {
1578 FIXME("This version of opengl does not support GL_DOT3\n");
1580 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1581 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1582 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1583 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1584 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1585 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1586 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1587 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1588 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1589 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1590 break;
1591 case D3DTOP_LERP:
1592 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1593 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1594 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1595 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1596 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1597 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1598 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1599 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1600 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1601 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1602 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
1603 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
1604 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
1605 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
1606 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1607 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1608 break;
1609 case D3DTOP_ADDSMOOTH:
1610 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1611 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1612 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1613 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1614 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1615 switch (opr1) {
1616 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1617 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1618 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1619 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1621 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1622 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1623 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1624 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1625 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1626 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1627 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1628 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1629 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1630 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1631 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1632 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1633 } else
1634 Handled = FALSE;
1635 break;
1636 case D3DTOP_BLENDTEXTUREALPHAPM:
1637 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1638 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1639 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1640 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
1641 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
1642 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
1643 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
1644 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1645 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1646 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1647 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1648 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1649 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1650 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1651 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1652 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1653 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1654 } else
1655 Handled = FALSE;
1656 break;
1657 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1658 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1659 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1660 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1661 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1662 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1663 switch (opr1) {
1664 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1665 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1666 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1667 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1669 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1670 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1671 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1672 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1673 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1674 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1675 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1676 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1677 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1678 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1679 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1680 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1681 } else
1682 Handled = FALSE;
1683 break;
1684 case D3DTOP_MODULATECOLOR_ADDALPHA:
1685 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1686 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1687 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1688 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1689 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1690 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1691 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1692 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1693 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1694 switch (opr1) {
1695 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1696 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1697 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1698 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1700 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1701 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1702 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1703 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1704 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1705 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1706 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1707 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1708 } else
1709 Handled = FALSE;
1710 break;
1711 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1712 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1713 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1714 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1715 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1716 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1717 switch (opr1) {
1718 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1719 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1720 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1721 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1723 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1724 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1725 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1726 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1727 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1728 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1729 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1730 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1731 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1732 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1733 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1734 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1735 } else
1736 Handled = FALSE;
1737 break;
1738 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1739 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1740 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1741 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1742 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1743 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1744 switch (opr1) {
1745 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1746 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1747 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1748 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1750 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1751 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1752 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1753 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1754 switch (opr1) {
1755 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1756 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1757 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1758 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1760 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1761 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1762 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1763 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1764 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1765 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1766 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1767 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1768 } else
1769 Handled = FALSE;
1770 break;
1771 case D3DTOP_MULTIPLYADD:
1772 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1773 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1774 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1775 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1776 checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
1777 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1778 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
1779 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1780 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1781 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1782 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1783 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1784 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1785 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1786 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1787 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1788 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1789 } else
1790 Handled = FALSE;
1791 break;
1792 default:
1793 Handled = FALSE;
1796 if (Handled) {
1797 BOOL combineOK = TRUE;
1798 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1799 DWORD op2;
1801 if (isAlpha) {
1802 op2 = This->UpdateStateBlock->texture_state[Stage][D3DTSS_COLOROP];
1803 } else {
1804 op2 = This->UpdateStateBlock->texture_state[Stage][D3DTSS_ALPHAOP];
1807 /* Note: If COMBINE4 in effect can't go back to combine! */
1808 switch (op2) {
1809 case D3DTOP_ADDSMOOTH:
1810 case D3DTOP_BLENDTEXTUREALPHAPM:
1811 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1812 case D3DTOP_MODULATECOLOR_ADDALPHA:
1813 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1814 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1815 case D3DTOP_MULTIPLYADD:
1816 /* Ignore those implemented in both cases */
1817 switch (op) {
1818 case D3DTOP_SELECTARG1:
1819 case D3DTOP_SELECTARG2:
1820 combineOK = FALSE;
1821 Handled = FALSE;
1822 break;
1823 default:
1824 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%d, otherop=%ld, isAlpha(%d)\n", op, op2, isAlpha);
1825 LEAVE_GL();
1826 return;
1831 if (combineOK) {
1832 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
1833 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
1835 LEAVE_GL();
1836 return;
1840 LEAVE_GL();
1842 /* After all the extensions, if still unhandled, report fixme */
1843 FIXME("Unhandled texture operation %d\n", op);
1845 #endif