4 * Copyright 2002-2003 Jason Edmeades
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
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
39 const char* debug_d3ddevicetype(D3DDEVTYPE 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);
47 FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
48 return "unrecognized";
52 const char* debug_d3dusage(DWORD 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";
67 FIXME("Unrecognized %lu Usage!\n", usage);
68 return "unrecognized";
72 const char* debug_d3dformat(D3DFORMAT 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);
117 FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
118 return "unrecognized";
122 const char* debug_d3dressourcetype(D3DRESOURCETYPE 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);
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);
150 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
151 return "unrecognized";
155 const char* debug_d3dpool(D3DPOOL 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);
164 FIXME("Unrecognized %u D3DPOOL!\n", Pool);
165 return "unrecognized";
169 const char* debug_d3drenderstate(DWORD 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
250 FIXME("Unrecognized %lu render state!\n", state);
251 return "unrecognized";
255 const char* debug_d3dtexturestate(DWORD 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
287 /* Note D3DTSS are not consecutive, so skip these */
291 FIXME("Unrecognized %lu texture state!\n", state);
292 return "unrecognized";
297 * Simple utility routines used for dx -> gl mapping of byte formats
299 int D3DPrimitiveListGetVertexSize(D3DPRIMITIVETYPE PrimitiveType, int iNumPrim) {
300 switch (PrimitiveType) {
301 case D3DPT_POINTLIST: return iNumPrim;
302 case D3DPT_LINELIST: return iNumPrim * 2;
303 case D3DPT_LINESTRIP: return iNumPrim + 1;
304 case D3DPT_TRIANGLELIST: return iNumPrim * 3;
305 case D3DPT_TRIANGLESTRIP: return iNumPrim + 2;
306 case D3DPT_TRIANGLEFAN: return iNumPrim + 2;
308 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
313 int D3DPrimitive2GLenum(D3DPRIMITIVETYPE PrimitiveType) {
314 switch (PrimitiveType) {
315 case D3DPT_POINTLIST: return GL_POINTS;
316 case D3DPT_LINELIST: return GL_LINES;
317 case D3DPT_LINESTRIP: return GL_LINE_STRIP;
318 case D3DPT_TRIANGLELIST: return GL_TRIANGLES;
319 case D3DPT_TRIANGLESTRIP: return GL_TRIANGLE_STRIP;
320 case D3DPT_TRIANGLEFAN: return GL_TRIANGLE_FAN;
322 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
327 int D3DFVFGetSize(D3DFORMAT fvf) {
329 if (fvf & D3DFVF_XYZ) ret += 3 * sizeof(float);
330 else if (fvf & D3DFVF_XYZRHW) ret += 4 * sizeof(float);
331 if (fvf & D3DFVF_NORMAL) ret += 3 * sizeof(float);
332 if (fvf & D3DFVF_PSIZE) ret += sizeof(float);
333 if (fvf & D3DFVF_DIFFUSE) ret += sizeof(DWORD);
334 if (fvf & D3DFVF_SPECULAR) ret += sizeof(DWORD);
335 /*if (fvf & D3DFVF_TEX1) ret += 1;*/
339 GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt) {
341 /* depth/stencil buffer */
342 case D3DFMT_D16_LOCKABLE:
349 return GL_DEPTH_COMPONENT;
351 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
356 GLenum D3DFmt2GLDepthType(D3DFORMAT fmt) {
358 /* depth/stencil buffer */
360 case D3DFMT_D16_LOCKABLE:
362 return GL_UNSIGNED_SHORT;
367 return GL_UNSIGNED_INT;
369 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
374 SHORT D3DFmtGetBpp(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
379 case D3DFMT_R3G3B2: retVal = 1; break;
380 case D3DFMT_R5G6B5: retVal = 2; break;
381 case D3DFMT_R8G8B8: retVal = 3; break;
382 case D3DFMT_A1R5G5B5: retVal = 2; break;
383 case D3DFMT_X1R5G5B5: retVal = 2; break;
384 case D3DFMT_A4R4G4B4: retVal = 2; break;
385 case D3DFMT_X4R4G4B4: retVal = 2; break;
386 case D3DFMT_A8R8G8B8: retVal = 4; break;
387 case D3DFMT_X8R8G8B8: retVal = 4; break;
389 case D3DFMT_P8: retVal = 1; break;
390 case D3DFMT_A8P8: retVal = 2; break;
391 /* depth/stencil buffer */
392 case D3DFMT_D16_LOCKABLE: retVal = 2; break;
393 case D3DFMT_D16: retVal = 2; break;
394 case D3DFMT_D32: retVal = 4; break;
395 case D3DFMT_D15S1: retVal = 2; break;
396 case D3DFMT_D24X4S4: retVal = 4; break;
397 case D3DFMT_D24S8: retVal = 4; break;
398 case D3DFMT_D24X8: retVal = 4; break;
400 case D3DFMT_L8: retVal = 1; break;
401 case D3DFMT_A4L4: retVal = 1; break;
402 case D3DFMT_A8L8: retVal = 2; break;
404 case D3DFMT_V8U8: retVal = 2; break;
405 case D3DFMT_L6V5U5: retVal = 2; break;
406 case D3DFMT_V16U16: retVal = 4; break;
407 case D3DFMT_X8L8V8U8: retVal = 4; break;
409 case D3DFMT_DXT1: retVal = 1; break; /* Actually 8 bytes per 16 pixels - Special cased later */
410 case D3DFMT_DXT3: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
411 case D3DFMT_DXT5: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
413 case D3DFMT_A8: retVal = 1; break;
416 /* Guess at the highest value of the above */
417 TRACE("D3DFMT_UNKNOWN - Guessing at 4 bytes/pixel %u\n", fmt);
422 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
425 TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
429 GLint D3DFmt2GLIntFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
432 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
434 case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
435 case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
436 case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
438 /* stupid compiler */
446 case D3DFMT_P8: retVal = GL_COLOR_INDEX8_EXT; break;
447 case D3DFMT_A8P8: retVal = GL_COLOR_INDEX8_EXT; break;
449 case D3DFMT_L8: retVal = GL_LUMINANCE8; break;
450 case D3DFMT_A8L8: retVal = GL_LUMINANCE8_ALPHA8; break;
451 case D3DFMT_A4L4: retVal = GL_LUMINANCE4_ALPHA4; break;
453 case D3DFMT_V8U8: retVal = GL_COLOR_INDEX8_EXT; break;
454 case D3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
455 case D3DFMT_L6V5U5: retVal = GL_COLOR_INDEX8_EXT; break;
456 case D3DFMT_X8L8V8U8: retVal = GL_COLOR_INDEX; break;
458 case D3DFMT_R3G3B2: retVal = GL_R3_G3_B2; break;
459 case D3DFMT_R5G6B5: retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
460 case D3DFMT_R8G8B8: retVal = GL_RGB8; break;
461 case D3DFMT_A1R5G5B5: retVal = GL_RGB5_A1; break;
462 case D3DFMT_X1R5G5B5: retVal = GL_RGB5_A1; break;
463 case D3DFMT_A4R4G4B4: retVal = GL_RGBA4; break;
464 case D3DFMT_X4R4G4B4: retVal = GL_RGBA4; break;
465 case D3DFMT_A8R8G8B8: retVal = GL_RGBA8; break;
466 case D3DFMT_X8R8G8B8: retVal = GL_RGBA8; break;
468 case D3DFMT_A8: retVal = GL_ALPHA8; break;
470 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
474 TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
478 GLenum D3DFmt2GLFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
481 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
483 case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
484 case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
485 case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
487 /* stupid compiler */
495 case D3DFMT_P8: retVal = GL_COLOR_INDEX; break;
496 case D3DFMT_A8P8: retVal = GL_COLOR_INDEX; break;
498 case D3DFMT_L8: retVal = GL_LUMINANCE; break;
499 case D3DFMT_A8L8: retVal = GL_LUMINANCE_ALPHA; break;
500 case D3DFMT_A4L4: retVal = GL_LUMINANCE_ALPHA; break;
502 case D3DFMT_V8U8: retVal = GL_COLOR_INDEX; break;
503 case D3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
504 case D3DFMT_L6V5U5: retVal = GL_COLOR_INDEX; break;
505 case D3DFMT_X8L8V8U8: retVal = GL_COLOR_INDEX; break;
507 case D3DFMT_R3G3B2: retVal = GL_BGR; break;
508 case D3DFMT_R5G6B5: retVal = GL_RGB; break;
509 case D3DFMT_R8G8B8: retVal = GL_RGB; break;
510 case D3DFMT_A1R5G5B5: retVal = GL_BGRA; break;
511 case D3DFMT_X1R5G5B5: retVal = GL_BGRA; break;
512 case D3DFMT_A4R4G4B4: retVal = GL_BGRA; break;
513 case D3DFMT_X4R4G4B4: retVal = GL_BGRA; break;
514 case D3DFMT_A8R8G8B8: retVal = GL_BGRA; break;
515 case D3DFMT_X8R8G8B8: retVal = GL_BGRA; break;
517 case D3DFMT_A8: retVal = GL_ALPHA; break;
519 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
524 TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
528 GLenum D3DFmt2GLType(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
531 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
533 case D3DFMT_DXT1: retVal = 0; break;
534 case D3DFMT_DXT3: retVal = 0; break;
535 case D3DFMT_DXT5: retVal = 0; break;
537 /* stupid compiler */
545 case D3DFMT_P8: retVal = GL_UNSIGNED_BYTE; break;
546 case D3DFMT_A8P8: retVal = GL_UNSIGNED_BYTE; break;
548 case D3DFMT_L8: retVal = GL_UNSIGNED_BYTE; break;
549 case D3DFMT_A8L8: retVal = GL_UNSIGNED_BYTE; break;
550 case D3DFMT_A4L4: retVal = GL_UNSIGNED_BYTE; break;
552 case D3DFMT_V8U8: retVal = GL_UNSIGNED_BYTE; break;
553 case D3DFMT_V16U16: retVal = GL_UNSIGNED_SHORT; break;
554 case D3DFMT_L6V5U5: retVal = GL_UNSIGNED_SHORT_5_5_5_1; break;
555 case D3DFMT_X8L8V8U8: retVal = GL_UNSIGNED_BYTE; break;
557 case D3DFMT_R3G3B2: retVal = GL_UNSIGNED_BYTE_2_3_3_REV; break;
558 case D3DFMT_R5G6B5: retVal = GL_UNSIGNED_SHORT_5_6_5; break;
559 case D3DFMT_R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
560 case D3DFMT_A1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
561 case D3DFMT_X1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
562 case D3DFMT_A4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
563 case D3DFMT_X4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
564 case D3DFMT_A8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
565 case D3DFMT_X8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
567 case D3DFMT_A8: retVal = GL_ALPHA; break;
569 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
570 retVal = GL_UNSIGNED_BYTE;
574 TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
578 int SOURCEx_RGB_EXT(DWORD arg) {
580 case D3DTSS_COLORARG0: return GL_SOURCE2_RGB_EXT;
581 case D3DTSS_COLORARG1: return GL_SOURCE0_RGB_EXT;
582 case D3DTSS_COLORARG2: return GL_SOURCE1_RGB_EXT;
583 case D3DTSS_ALPHAARG0:
584 case D3DTSS_ALPHAARG1:
585 case D3DTSS_ALPHAARG2:
587 FIXME("Invalid arg %ld\n", arg);
588 return GL_SOURCE0_RGB_EXT;
592 int OPERANDx_RGB_EXT(DWORD arg) {
594 case D3DTSS_COLORARG0: return GL_OPERAND2_RGB_EXT;
595 case D3DTSS_COLORARG1: return GL_OPERAND0_RGB_EXT;
596 case D3DTSS_COLORARG2: return GL_OPERAND1_RGB_EXT;
597 case D3DTSS_ALPHAARG0:
598 case D3DTSS_ALPHAARG1:
599 case D3DTSS_ALPHAARG2:
601 FIXME("Invalid arg %ld\n", arg);
602 return GL_OPERAND0_RGB_EXT;
606 int SOURCEx_ALPHA_EXT(DWORD arg) {
608 case D3DTSS_ALPHAARG0: return GL_SOURCE2_ALPHA_EXT;
609 case D3DTSS_ALPHAARG1: return GL_SOURCE0_ALPHA_EXT;
610 case D3DTSS_ALPHAARG2: return GL_SOURCE1_ALPHA_EXT;
611 case D3DTSS_COLORARG0:
612 case D3DTSS_COLORARG1:
613 case D3DTSS_COLORARG2:
615 FIXME("Invalid arg %ld\n", arg);
616 return GL_SOURCE0_ALPHA_EXT;
620 int OPERANDx_ALPHA_EXT(DWORD arg) {
622 case D3DTSS_ALPHAARG0: return GL_OPERAND2_ALPHA_EXT;
623 case D3DTSS_ALPHAARG1: return GL_OPERAND0_ALPHA_EXT;
624 case D3DTSS_ALPHAARG2: return GL_OPERAND1_ALPHA_EXT;
625 case D3DTSS_COLORARG0:
626 case D3DTSS_COLORARG1:
627 case D3DTSS_COLORARG2:
629 FIXME("Invalid arg %ld\n", arg);
630 return GL_OPERAND0_ALPHA_EXT;
634 GLenum StencilOp(DWORD op) {
636 case D3DSTENCILOP_KEEP : return GL_KEEP;
637 case D3DSTENCILOP_ZERO : return GL_ZERO;
638 case D3DSTENCILOP_REPLACE : return GL_REPLACE;
639 case D3DSTENCILOP_INCRSAT : return GL_INCR;
640 case D3DSTENCILOP_DECRSAT : return GL_DECR;
641 case D3DSTENCILOP_INVERT : return GL_INVERT;
642 case D3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
643 case D3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
645 FIXME("Invalid stencil op %ld\n", op);
653 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand)
655 BOOL isAlphaReplicate = FALSE;
656 BOOL isComplement = FALSE;
658 *operand = GL_SRC_COLOR;
659 *source = GL_TEXTURE;
661 /* Catch alpha replicate */
662 if (iValue & D3DTA_ALPHAREPLICATE) {
663 iValue = iValue & ~D3DTA_ALPHAREPLICATE;
664 isAlphaReplicate = TRUE;
667 /* Catch Complement */
668 if (iValue & D3DTA_COMPLEMENT) {
669 iValue = iValue & ~D3DTA_COMPLEMENT;
673 /* Calculate the operand */
674 if (isAlphaReplicate && !isComplement) {
675 *operand = GL_SRC_ALPHA;
676 } else if (isAlphaReplicate && isComplement) {
677 *operand = GL_ONE_MINUS_SRC_ALPHA;
678 } else if (isComplement) {
680 *operand = GL_ONE_MINUS_SRC_ALPHA;
682 *operand = GL_ONE_MINUS_SRC_COLOR;
686 *operand = GL_SRC_ALPHA;
688 *operand = GL_SRC_COLOR;
692 /* Calculate the source */
693 switch (iValue & D3DTA_SELECTMASK) {
694 case D3DTA_CURRENT: *source = GL_PREVIOUS_EXT;
696 case D3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT;
698 case D3DTA_TEXTURE: *source = GL_TEXTURE;
700 case D3DTA_TFACTOR: *source = GL_CONSTANT_EXT;
704 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
705 * 'Secondary color' and isn't supported until base GL supports it
706 * There is no concept of temp registers as far as I can tell
708 FIXME("Unhandled texture arg D3DTA_SPECULAR\n");
709 *source = GL_TEXTURE;
713 FIXME("Unrecognized texture arg %ld\n", iValue);
714 *source = GL_TEXTURE;
719 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
720 #if defined (GL_VERSION_1_3)
722 # define combine_ext 1
723 #elif defined (GL_EXT_texture_env_combine)
724 # define useext(A) A##_EXT
725 # define combine_ext 1
726 #elif defined (GL_ARB_texture_env_combine)
727 # define useext(A) A##_ARB
728 # define combine_ext 1
733 #if !defined(combine_ext)
734 void set_tex_op(LPDIRECT3DDEVICE8 iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
736 FIXME("Requires opengl combine extensions to work\n");
740 /* Setup the texture operations texture stage states */
741 void set_tex_op(LPDIRECT3DDEVICE8 iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
743 GLenum src1, src2, src3;
744 GLenum opr1, opr2, opr3;
746 GLenum src0_target, src1_target, src2_target;
747 GLenum opr0_target, opr1_target, opr2_target;
749 GLenum opr=0, invopr, src3_target, opr3_target;
750 BOOL Handled = FALSE;
751 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
753 TRACE("Alpha?(%d), Stage:%d Op(%d), a1(%ld), a2(%ld), a3(%ld)\n", isAlpha, Stage, op, arg1, arg2, arg3);
757 /* Note: Operations usually involve two ars, src0 and src1 and are operations of
758 the form (a1 <operation> a2). However, some of the more complex operations
759 take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
760 in a third parameter called a0. Therefore these are operations of the form
761 a0 <operation> a1 <operation> a2, ie the new parameter goes to the front.
763 However, below we treat the new (a0) parameter as src2/opr2, so in the actual
764 functions below, expect their syntax to differ slightly to those listed in the
765 manuals, ie replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
766 This affects D3DTOP_MULTIPLYADD and D3DTOP_LERP */
769 comb_target = useext(GL_COMBINE_ALPHA);
770 src0_target = useext(GL_SOURCE0_ALPHA);
771 src1_target = useext(GL_SOURCE1_ALPHA);
772 src2_target = useext(GL_SOURCE2_ALPHA);
773 opr0_target = useext(GL_OPERAND0_ALPHA);
774 opr1_target = useext(GL_OPERAND1_ALPHA);
775 opr2_target = useext(GL_OPERAND2_ALPHA);
776 scal_target = GL_ALPHA_SCALE;
779 comb_target = useext(GL_COMBINE_RGB);
780 src0_target = useext(GL_SOURCE0_RGB);
781 src1_target = useext(GL_SOURCE1_RGB);
782 src2_target = useext(GL_SOURCE2_RGB);
783 opr0_target = useext(GL_OPERAND0_RGB);
784 opr1_target = useext(GL_OPERAND1_RGB);
785 opr2_target = useext(GL_OPERAND2_RGB);
786 scal_target = useext(GL_RGB_SCALE);
789 /* From MSDN (D3DTSS_ALPHAARG1) :
790 The default argument is D3DTA_TEXTURE. If no texture is set for this stage,
791 then the default argument is D3DTA_DIFFUSE.
792 FIXME? If texture added/removed, may need to reset back as well? */
793 if (isAlpha && This->StateBlock->textures[Stage] == NULL && arg1 == D3DTA_TEXTURE) {
794 GetSrcAndOpFromValue(D3DTA_DIFFUSE, isAlpha, &src1, &opr1);
796 GetSrcAndOpFromValue(arg1, isAlpha, &src1, &opr1);
798 GetSrcAndOpFromValue(arg2, isAlpha, &src2, &opr2);
799 GetSrcAndOpFromValue(arg3, isAlpha, &src3, &opr3);
801 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
803 Handled = TRUE; /* Assume will be handled */
805 /* Other texture operations require special extensions: */
806 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
809 invopr = GL_ONE_MINUS_SRC_ALPHA;
810 src3_target = GL_SOURCE3_ALPHA_NV;
811 opr3_target = GL_OPERAND3_ALPHA_NV;
814 invopr = GL_ONE_MINUS_SRC_COLOR;
815 src3_target = GL_SOURCE3_RGB_NV;
816 opr3_target = GL_OPERAND3_RGB_NV;
819 case D3DTOP_DISABLE: /* Only for alpha */
820 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
821 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
822 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
823 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
824 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
825 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
826 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
827 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
828 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
829 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
830 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
831 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
832 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
833 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
834 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
835 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
836 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
837 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
839 case D3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */
840 case D3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */
841 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
842 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
843 if (op == D3DTOP_SELECTARG1) {
844 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
845 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
846 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
847 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
849 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
850 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
851 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
852 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
854 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
855 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
856 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
857 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
858 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
859 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
860 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
861 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
862 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
863 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
864 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
865 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
868 case D3DTOP_MODULATE:
869 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
870 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
871 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
872 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
873 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
874 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
875 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
876 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
877 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
878 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
879 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
880 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
881 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
882 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
883 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
884 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
885 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
886 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
887 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
888 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
890 case D3DTOP_MODULATE2X:
891 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
892 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
893 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
894 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
895 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
896 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
897 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
898 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
899 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
900 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
901 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
902 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
903 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
904 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
905 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
906 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
907 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
908 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
909 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
910 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
912 case D3DTOP_MODULATE4X:
913 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
914 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
915 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
916 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
917 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
918 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
919 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
920 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
921 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
922 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
923 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
924 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
925 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
926 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
927 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
928 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
929 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
930 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
931 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
932 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
936 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
937 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
938 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
939 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
940 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
941 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
942 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
943 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
944 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
945 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
946 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
947 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
948 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
949 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
950 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
951 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
952 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
953 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
954 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
955 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
958 case D3DTOP_ADDSIGNED:
959 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
960 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
961 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
962 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
963 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
964 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
965 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
966 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
967 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
968 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
969 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
970 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
971 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
972 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
973 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
974 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
975 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
976 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
977 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
978 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
981 case D3DTOP_ADDSIGNED2X:
982 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
983 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
984 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
985 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
986 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
987 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
988 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
989 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
990 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
991 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
992 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
993 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
994 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
995 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
996 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
997 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
998 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
999 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1000 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1001 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1004 case D3DTOP_ADDSMOOTH:
1005 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1006 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1007 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1008 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1009 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1010 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1011 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1012 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1013 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1014 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1015 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1016 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1017 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1018 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1019 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1020 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1022 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1023 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1024 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1025 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1027 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1028 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1029 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1030 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1033 case D3DTOP_BLENDDIFFUSEALPHA:
1034 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1035 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1036 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1037 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1038 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1039 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1040 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
1041 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
1042 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1043 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1044 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1045 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1046 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1047 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1048 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
1049 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
1050 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1051 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1052 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1053 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1055 case D3DTOP_BLENDTEXTUREALPHA:
1056 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1057 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1058 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1059 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1060 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1061 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1062 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
1063 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
1064 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1065 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1066 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1067 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1068 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1069 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1070 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1071 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1072 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1073 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1074 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1075 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1077 case D3DTOP_BLENDFACTORALPHA:
1078 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1079 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1080 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1081 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1082 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1083 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1084 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT));
1085 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
1086 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1087 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1088 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1089 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1090 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1091 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1092 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
1093 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
1094 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1095 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1096 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1097 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1099 case D3DTOP_BLENDTEXTUREALPHAPM:
1100 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1101 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1102 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1103 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1104 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1105 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1106 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1107 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1108 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1109 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1110 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1111 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1112 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1113 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1114 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1115 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1116 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1117 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1118 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1119 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1121 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1122 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1123 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
1124 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
1125 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1126 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1127 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
1128 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1129 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1130 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1131 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1132 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
1133 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1134 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1135 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
1136 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1137 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1139 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1140 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1142 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1143 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1144 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1145 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1147 case D3DTOP_MODULATECOLOR_ADDALPHA:
1148 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1149 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1150 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1151 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1152 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1153 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1154 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1155 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1156 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1157 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1158 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1159 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1161 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1162 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1164 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1165 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1166 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1167 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1168 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1169 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1170 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1171 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1173 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1174 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1175 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1176 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1177 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1178 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1179 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1180 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1181 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1182 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1183 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1184 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1185 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1186 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1187 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1188 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1189 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1191 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1192 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1193 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1194 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1196 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1197 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1198 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1199 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1201 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1202 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1203 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1204 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1205 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1207 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1208 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1209 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1210 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1212 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1213 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1214 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1215 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1216 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1217 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1218 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1219 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1221 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1222 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1224 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1225 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1226 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1227 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1228 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1229 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1230 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1231 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1233 case D3DTOP_MULTIPLYADD:
1234 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1235 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1236 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1237 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1238 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1239 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1240 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1241 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1242 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1243 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1244 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1245 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1246 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
1247 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1248 glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
1249 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
1250 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
1251 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
1252 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1253 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1256 case D3DTOP_BUMPENVMAP:
1258 if (GL_SUPPORT(NV_TEXTURE_SHADER)) {
1260 texture unit 0: GL_TEXTURE_2D
1261 texture unit 1: GL_DOT_PRODUCT_NV
1262 texture unit 2: GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV
1263 texture unit 3: GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV
1272 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT00];
1273 m[0][0] = tmpvalue.f;
1274 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT01];
1275 m[0][1] = tmpvalue.f;
1276 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT10];
1277 m[1][0] = tmpvalue.f;
1278 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT11];
1279 m[1][1] = tmpvalue.f;
1281 /*FIXME("Stage %d matrix is (%.2f,%.2f),(%.2f,%.2f)\n", Stage, m[0][0], m[0][1], m[1][0], m[1][0]);*/
1283 if (FALSE == This->texture_shader_active) {
1284 This->texture_shader_active = TRUE;
1285 glEnable(GL_TEXTURE_SHADER_NV);
1289 glEnable(GL_REGISTER_COMBINERS_NV);
1290 glCombinerParameteriNV (GL_NUM_GENERAL_COMBINERS_NV, 1);
1291 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
1292 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
1293 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
1294 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
1295 glCombinerOutputNV (GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
1296 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
1297 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
1298 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
1299 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
1300 glCombinerOutputNV (GL_COMBINER0_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
1301 glDisable (GL_PER_STAGE_CONSTANTS_NV);
1302 glCombinerParameteriNV (GL_COLOR_SUM_CLAMP_NV, 0);
1303 glFinalCombinerInputNV (GL_VARIABLE_A_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1304 glFinalCombinerInputNV (GL_VARIABLE_B_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1305 glFinalCombinerInputNV (GL_VARIABLE_C_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1306 glFinalCombinerInputNV (GL_VARIABLE_D_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1307 glFinalCombinerInputNV (GL_VARIABLE_E_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1308 glFinalCombinerInputNV (GL_VARIABLE_F_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1309 glFinalCombinerInputNV (GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
1313 for (i = 0; i < Stage; i++) {
1314 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1315 glActiveTexture(GL_TEXTURE0 + i);
1316 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
1317 checkGLcall("Activate texture..");
1319 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1324 glActiveTextureARB(GL_TEXTURE0_ARB + Stage - 1);
1325 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
1328 glActiveTextureARB(GL_TEXTURE0_ARB + Stage);
1329 checkGLcall("Activate texture.. to update const color");
1330 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
1331 checkGLcall("glTexEnv");
1332 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + Stage - 1);
1333 checkGLcall("glTexEnv");
1334 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float*)&m[0]);
1335 checkGLcall("glTexEnv");
1343 case D3DTOP_BUMPENVMAPLUMINANCE:
1349 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
1350 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
1355 } /* GL_NV_texture_env_combine4 */
1357 Handled = TRUE; /* Again, assume handled */
1359 case D3DTOP_DISABLE: /* Only for alpha */
1360 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1361 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1362 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
1363 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
1364 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
1365 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
1366 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1367 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1369 case D3DTOP_SELECTARG1:
1370 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1371 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1372 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1373 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1374 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1375 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1376 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1377 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1379 case D3DTOP_SELECTARG2:
1380 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1381 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1382 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
1383 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1384 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1385 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1386 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1387 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1389 case D3DTOP_MODULATE:
1390 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1391 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1392 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1393 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1394 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1395 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1396 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1397 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1398 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1399 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1400 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1401 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1403 case D3DTOP_MODULATE2X:
1404 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1405 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1406 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1407 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1408 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1409 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1410 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1411 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1412 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1413 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1414 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1415 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1417 case D3DTOP_MODULATE4X:
1418 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1419 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1420 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1421 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1422 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1423 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1424 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1425 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1426 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1427 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1428 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1429 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1432 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1433 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1434 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1435 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1436 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1437 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1438 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1439 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1440 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1441 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1442 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1443 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1445 case D3DTOP_ADDSIGNED:
1446 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1447 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
1448 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1449 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1450 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1451 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1452 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1453 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1454 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1455 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1456 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1457 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1459 case D3DTOP_ADDSIGNED2X:
1460 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1461 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1462 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1463 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1464 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1465 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1466 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1467 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1468 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1469 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1470 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1471 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1473 case D3DTOP_SUBTRACT:
1474 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
1475 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
1476 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
1477 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1478 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1479 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1480 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1481 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1482 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1483 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1484 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1485 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1486 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1488 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1492 case D3DTOP_BLENDDIFFUSEALPHA:
1493 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1494 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1495 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1496 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1497 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1498 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1499 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1500 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1501 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1502 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1503 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
1504 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
1505 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1506 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1507 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1508 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1510 case D3DTOP_BLENDTEXTUREALPHA:
1511 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1512 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1513 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1514 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1515 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1516 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1517 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1518 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1519 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1520 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1521 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
1522 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
1523 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1524 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1525 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1526 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1528 case D3DTOP_BLENDFACTORALPHA:
1529 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1530 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1531 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1532 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1533 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1534 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1535 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1536 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1537 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1538 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1539 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
1540 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
1541 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1542 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1543 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1544 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1546 case D3DTOP_BLENDCURRENTALPHA:
1547 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1548 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1549 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1550 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1551 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1552 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1553 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1554 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1555 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1556 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1557 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
1558 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
1559 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1560 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1561 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1562 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1564 case D3DTOP_DOTPRODUCT3:
1565 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
1566 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
1567 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
1568 } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
1569 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
1570 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
1572 FIXME("This version of opengl does not support GL_DOT3\n");
1574 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1575 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1576 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1577 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1578 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1579 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1580 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1581 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1582 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1583 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1586 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1587 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1588 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1589 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1590 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1591 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1592 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1593 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1594 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1595 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1596 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
1597 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
1598 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
1599 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
1600 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1601 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1603 case D3DTOP_ADDSMOOTH:
1604 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1605 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1606 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1607 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1608 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1610 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1611 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1612 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1613 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1615 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1616 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1617 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1618 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1619 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1620 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1621 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1622 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1623 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1624 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1625 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1626 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1630 case D3DTOP_BLENDTEXTUREALPHAPM:
1631 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1632 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1633 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1634 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
1635 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
1636 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
1637 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
1638 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1639 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1640 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1641 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1642 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1643 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1644 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1645 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1646 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1647 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1651 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1652 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1653 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1654 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1655 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1656 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1658 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1659 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1660 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1661 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1663 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1664 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1665 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1666 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1667 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1668 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1669 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1670 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1671 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1672 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1673 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1674 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1678 case D3DTOP_MODULATECOLOR_ADDALPHA:
1679 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1680 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1681 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1682 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1683 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1684 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1685 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1686 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1687 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1689 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1690 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1691 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1692 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1694 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1695 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1696 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1697 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1698 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1699 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1700 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1701 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1705 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1706 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1707 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1708 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1709 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1710 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1712 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1713 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1714 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1715 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1717 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1718 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1719 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1720 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1721 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1722 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1723 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1724 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1725 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1726 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1727 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1728 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1732 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1733 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1734 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1735 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1736 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1737 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1739 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1740 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1741 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1742 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1744 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1745 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1746 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1747 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1749 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1750 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1751 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1752 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1754 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1755 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1756 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1757 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1758 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1759 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1760 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1761 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1765 case D3DTOP_MULTIPLYADD:
1766 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1767 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1768 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1769 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1770 checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
1771 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1772 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
1773 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1774 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1775 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1776 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1777 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1778 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1779 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1780 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1781 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1782 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1791 BOOL combineOK = TRUE;
1792 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1796 op2 = This->UpdateStateBlock->texture_state[Stage][D3DTSS_COLOROP];
1798 op2 = This->UpdateStateBlock->texture_state[Stage][D3DTSS_ALPHAOP];
1801 /* Note: If COMBINE4 in effect can't go back to combine! */
1803 case D3DTOP_ADDSMOOTH:
1804 case D3DTOP_BLENDTEXTUREALPHAPM:
1805 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1806 case D3DTOP_MODULATECOLOR_ADDALPHA:
1807 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1808 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1809 case D3DTOP_MULTIPLYADD:
1810 /* Ignore those implemented in both cases */
1812 case D3DTOP_SELECTARG1:
1813 case D3DTOP_SELECTARG2:
1818 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%d, otherop=%ld, isAlpha(%d)\n", op, op2, isAlpha);
1825 if (combineOK == TRUE) {
1826 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
1827 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
1836 /* After all the extensions, if still unhandled, report fixme */
1837 FIXME("Unhandled texture operation %d\n", op);