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 */
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;
307 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
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;
321 FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
326 int D3DFVFGetSize(D3DFORMAT fvf) {
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;*/
338 GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt) {
340 /* depth/stencil buffer */
341 case D3DFMT_D16_LOCKABLE:
348 return GL_DEPTH_COMPONENT;
350 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
355 GLenum D3DFmt2GLDepthType(D3DFORMAT fmt) {
357 /* depth/stencil buffer */
359 case D3DFMT_D16_LOCKABLE:
361 return GL_UNSIGNED_SHORT;
366 return GL_UNSIGNED_INT;
368 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
373 SHORT D3DFmtGetBpp(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
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;
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;
399 case D3DFMT_L8: retVal = 1; break;
400 case D3DFMT_A4L4: retVal = 1; break;
401 case D3DFMT_A8L8: retVal = 2; break;
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;
408 case D3DFMT_DXT1: retVal = 1; break; /* Actually 8 bytes per 16 pixels - Special cased later */
409 case D3DFMT_DXT3: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
410 case D3DFMT_DXT5: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
412 case D3DFMT_A8: retVal = 1; break;
415 /* Guess at the highest value of the above */
416 TRACE("D3DFMT_UNKNOWN - Guessing at 4 bytes/pixel %u\n", fmt);
421 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
424 TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
428 GLint D3DFmt2GLIntFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
431 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
433 case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
434 case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
435 case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
437 /* stupid compiler */
445 case D3DFMT_P8: retVal = GL_COLOR_INDEX8_EXT; break;
446 case D3DFMT_A8P8: retVal = GL_COLOR_INDEX8_EXT; break;
448 case D3DFMT_L8: retVal = GL_LUMINANCE8; break;
449 case D3DFMT_A8L8: retVal = GL_LUMINANCE8_ALPHA8; break;
450 case D3DFMT_A4L4: retVal = GL_LUMINANCE4_ALPHA4; break;
452 case D3DFMT_V8U8: retVal = GL_COLOR_INDEX8_EXT; break;
453 case D3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
454 case D3DFMT_L6V5U5: retVal = GL_COLOR_INDEX8_EXT; break;
455 case D3DFMT_X8L8V8U8: retVal = GL_COLOR_INDEX; break;
457 case D3DFMT_R3G3B2: retVal = GL_R3_G3_B2; break;
458 case D3DFMT_R5G6B5: retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
459 case D3DFMT_R8G8B8: retVal = GL_RGB8; break;
460 case D3DFMT_A1R5G5B5: retVal = GL_RGB5_A1; break;
461 case D3DFMT_X1R5G5B5: retVal = GL_RGB5_A1; break;
462 case D3DFMT_A4R4G4B4: retVal = GL_RGBA4; break;
463 case D3DFMT_X4R4G4B4: retVal = GL_RGBA4; break;
464 case D3DFMT_A8R8G8B8: retVal = GL_RGBA8; break;
465 case D3DFMT_X8R8G8B8: retVal = GL_RGBA8; break;
467 case D3DFMT_A8: retVal = GL_ALPHA8; break;
469 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
473 TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
477 GLenum D3DFmt2GLFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
480 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
482 case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
483 case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
484 case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
486 /* stupid compiler */
494 case D3DFMT_P8: retVal = GL_COLOR_INDEX; break;
495 case D3DFMT_A8P8: retVal = GL_COLOR_INDEX; break;
497 case D3DFMT_L8: retVal = GL_LUMINANCE; break;
498 case D3DFMT_A8L8: retVal = GL_LUMINANCE_ALPHA; break;
499 case D3DFMT_A4L4: retVal = GL_LUMINANCE_ALPHA; break;
501 case D3DFMT_V8U8: retVal = GL_COLOR_INDEX; break;
502 case D3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
503 case D3DFMT_L6V5U5: retVal = GL_COLOR_INDEX; break;
504 case D3DFMT_X8L8V8U8: retVal = GL_COLOR_INDEX; break;
506 case D3DFMT_R3G3B2: retVal = GL_BGR; break;
507 case D3DFMT_R5G6B5: retVal = GL_RGB; break;
508 case D3DFMT_R8G8B8: retVal = GL_RGB; break;
509 case D3DFMT_A1R5G5B5: retVal = GL_BGRA; break;
510 case D3DFMT_X1R5G5B5: retVal = GL_BGRA; break;
511 case D3DFMT_A4R4G4B4: retVal = GL_BGRA; break;
512 case D3DFMT_X4R4G4B4: retVal = GL_BGRA; break;
513 case D3DFMT_A8R8G8B8: retVal = GL_BGRA; break;
514 case D3DFMT_X8R8G8B8: retVal = GL_BGRA; break;
516 case D3DFMT_A8: retVal = GL_ALPHA; break;
518 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
523 TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
527 GLenum D3DFmt2GLType(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
530 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
532 case D3DFMT_DXT1: retVal = 0; break;
533 case D3DFMT_DXT3: retVal = 0; break;
534 case D3DFMT_DXT5: retVal = 0; break;
536 /* stupid compiler */
544 case D3DFMT_P8: retVal = GL_UNSIGNED_BYTE; break;
545 case D3DFMT_A8P8: retVal = GL_UNSIGNED_BYTE; break;
547 case D3DFMT_L8: retVal = GL_UNSIGNED_BYTE; break;
548 case D3DFMT_A8L8: retVal = GL_UNSIGNED_BYTE; break;
549 case D3DFMT_A4L4: retVal = GL_UNSIGNED_BYTE; break;
551 case D3DFMT_V8U8: retVal = GL_UNSIGNED_BYTE; break;
552 case D3DFMT_V16U16: retVal = GL_UNSIGNED_SHORT; break;
553 case D3DFMT_L6V5U5: retVal = GL_UNSIGNED_SHORT_5_5_5_1; break;
554 case D3DFMT_X8L8V8U8: retVal = GL_UNSIGNED_BYTE; break;
556 case D3DFMT_R3G3B2: retVal = GL_UNSIGNED_BYTE_2_3_3_REV; break;
557 case D3DFMT_R5G6B5: retVal = GL_UNSIGNED_SHORT_5_6_5; break;
558 case D3DFMT_R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
559 case D3DFMT_A1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
560 case D3DFMT_X1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
561 case D3DFMT_A4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
562 case D3DFMT_X4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
563 case D3DFMT_A8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
564 case D3DFMT_X8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
566 case D3DFMT_A8: retVal = GL_ALPHA; break;
568 FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
569 retVal = GL_UNSIGNED_BYTE;
573 TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
577 int SOURCEx_RGB_EXT(DWORD arg) {
579 case D3DTSS_COLORARG0: return GL_SOURCE2_RGB_EXT;
580 case D3DTSS_COLORARG1: return GL_SOURCE0_RGB_EXT;
581 case D3DTSS_COLORARG2: return GL_SOURCE1_RGB_EXT;
582 case D3DTSS_ALPHAARG0:
583 case D3DTSS_ALPHAARG1:
584 case D3DTSS_ALPHAARG2:
586 FIXME("Invalid arg %ld\n", arg);
587 return GL_SOURCE0_RGB_EXT;
591 int OPERANDx_RGB_EXT(DWORD arg) {
593 case D3DTSS_COLORARG0: return GL_OPERAND2_RGB_EXT;
594 case D3DTSS_COLORARG1: return GL_OPERAND0_RGB_EXT;
595 case D3DTSS_COLORARG2: return GL_OPERAND1_RGB_EXT;
596 case D3DTSS_ALPHAARG0:
597 case D3DTSS_ALPHAARG1:
598 case D3DTSS_ALPHAARG2:
600 FIXME("Invalid arg %ld\n", arg);
601 return GL_OPERAND0_RGB_EXT;
605 int SOURCEx_ALPHA_EXT(DWORD arg) {
607 case D3DTSS_ALPHAARG0: return GL_SOURCE2_ALPHA_EXT;
608 case D3DTSS_ALPHAARG1: return GL_SOURCE0_ALPHA_EXT;
609 case D3DTSS_ALPHAARG2: return GL_SOURCE1_ALPHA_EXT;
610 case D3DTSS_COLORARG0:
611 case D3DTSS_COLORARG1:
612 case D3DTSS_COLORARG2:
614 FIXME("Invalid arg %ld\n", arg);
615 return GL_SOURCE0_ALPHA_EXT;
619 int OPERANDx_ALPHA_EXT(DWORD arg) {
621 case D3DTSS_ALPHAARG0: return GL_OPERAND2_ALPHA_EXT;
622 case D3DTSS_ALPHAARG1: return GL_OPERAND0_ALPHA_EXT;
623 case D3DTSS_ALPHAARG2: return GL_OPERAND1_ALPHA_EXT;
624 case D3DTSS_COLORARG0:
625 case D3DTSS_COLORARG1:
626 case D3DTSS_COLORARG2:
628 FIXME("Invalid arg %ld\n", arg);
629 return GL_OPERAND0_ALPHA_EXT;
633 GLenum StencilOp(DWORD op) {
635 case D3DSTENCILOP_KEEP : return GL_KEEP;
636 case D3DSTENCILOP_ZERO : return GL_ZERO;
637 case D3DSTENCILOP_REPLACE : return GL_REPLACE;
638 case D3DSTENCILOP_INCRSAT : return GL_INCR;
639 case D3DSTENCILOP_DECRSAT : return GL_DECR;
640 case D3DSTENCILOP_INVERT : return GL_INVERT;
641 case D3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
642 case D3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
644 FIXME("Invalid stencil op %ld\n", op);
652 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand)
654 BOOL isAlphaReplicate = FALSE;
655 BOOL isComplement = FALSE;
657 *operand = GL_SRC_COLOR;
658 *source = GL_TEXTURE;
660 /* Catch alpha replicate */
661 if (iValue & D3DTA_ALPHAREPLICATE) {
662 iValue = iValue & ~D3DTA_ALPHAREPLICATE;
663 isAlphaReplicate = TRUE;
666 /* Catch Complement */
667 if (iValue & D3DTA_COMPLEMENT) {
668 iValue = iValue & ~D3DTA_COMPLEMENT;
672 /* Calculate the operand */
673 if (isAlphaReplicate && !isComplement) {
674 *operand = GL_SRC_ALPHA;
675 } else if (isAlphaReplicate && isComplement) {
676 *operand = GL_ONE_MINUS_SRC_ALPHA;
677 } else if (isComplement) {
679 *operand = GL_ONE_MINUS_SRC_ALPHA;
681 *operand = GL_ONE_MINUS_SRC_COLOR;
685 *operand = GL_SRC_ALPHA;
687 *operand = GL_SRC_COLOR;
691 /* Calculate the source */
692 switch (iValue & D3DTA_SELECTMASK) {
693 case D3DTA_CURRENT: *source = GL_PREVIOUS_EXT;
695 case D3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT;
697 case D3DTA_TEXTURE: *source = GL_TEXTURE;
699 case D3DTA_TFACTOR: *source = GL_CONSTANT_EXT;
703 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
704 * 'Secondary color' and isn't supported until base GL supports it
705 * There is no concept of temp registers as far as I can tell
707 FIXME("Unhandled texture arg D3DTA_SPECULAR\n");
708 *source = GL_TEXTURE;
712 FIXME("Unrecognized texture arg %ld\n", iValue);
713 *source = GL_TEXTURE;
718 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
719 #if defined (GL_VERSION_1_3)
721 # define combine_ext 1
722 #elif defined (GL_EXT_texture_env_combine)
723 # define useext(A) A##_EXT
724 # define combine_ext 1
725 #elif defined (GL_ARB_texture_env_combine)
726 # define useext(A) A##_ARB
727 # define combine_ext 1
732 #if !defined(combine_ext)
733 void set_tex_op(LPDIRECT3DDEVICE8 iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
735 FIXME("Requires opengl combine extensions to work\n");
739 /* Setup the texture operations texture stage states */
740 void set_tex_op(LPDIRECT3DDEVICE8 iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
742 GLenum src1, src2, src3;
743 GLenum opr1, opr2, opr3;
745 GLenum src0_target, src1_target, src2_target;
746 GLenum opr0_target, opr1_target, opr2_target;
748 GLenum opr=0, invopr, src3_target, opr3_target;
749 BOOL Handled = FALSE;
750 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
752 TRACE("Alpha?(%d), Stage:%d Op(%d), a1(%ld), a2(%ld), a3(%ld)\n", isAlpha, Stage, op, arg1, arg2, arg3);
756 /* Note: Operations usually involve two ars, src0 and src1 and are operations of
757 the form (a1 <operation> a2). However, some of the more complex operations
758 take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
759 in a third parameter called a0. Therefore these are operations of the form
760 a0 <operation> a1 <operation> a2, ie the new parameter goes to the front.
762 However, below we treat the new (a0) parameter as src2/opr2, so in the actual
763 functions below, expect their syntax to differ slightly to those listed in the
764 manuals, ie replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
765 This affects D3DTOP_MULTIPLYADD and D3DTOP_LERP */
768 comb_target = useext(GL_COMBINE_ALPHA);
769 src0_target = useext(GL_SOURCE0_ALPHA);
770 src1_target = useext(GL_SOURCE1_ALPHA);
771 src2_target = useext(GL_SOURCE2_ALPHA);
772 opr0_target = useext(GL_OPERAND0_ALPHA);
773 opr1_target = useext(GL_OPERAND1_ALPHA);
774 opr2_target = useext(GL_OPERAND2_ALPHA);
775 scal_target = GL_ALPHA_SCALE;
778 comb_target = useext(GL_COMBINE_RGB);
779 src0_target = useext(GL_SOURCE0_RGB);
780 src1_target = useext(GL_SOURCE1_RGB);
781 src2_target = useext(GL_SOURCE2_RGB);
782 opr0_target = useext(GL_OPERAND0_RGB);
783 opr1_target = useext(GL_OPERAND1_RGB);
784 opr2_target = useext(GL_OPERAND2_RGB);
785 scal_target = useext(GL_RGB_SCALE);
788 /* From MSDN (D3DTSS_ALPHAARG1) :
789 The default argument is D3DTA_TEXTURE. If no texture is set for this stage,
790 then the default argument is D3DTA_DIFFUSE.
791 FIXME? If texture added/removed, may need to reset back as well? */
792 if (isAlpha && This->StateBlock->textures[Stage] == NULL && arg1 == D3DTA_TEXTURE) {
793 GetSrcAndOpFromValue(D3DTA_DIFFUSE, isAlpha, &src1, &opr1);
795 GetSrcAndOpFromValue(arg1, isAlpha, &src1, &opr1);
797 GetSrcAndOpFromValue(arg2, isAlpha, &src2, &opr2);
798 GetSrcAndOpFromValue(arg3, isAlpha, &src3, &opr3);
800 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
802 Handled = TRUE; /* Assume will be handled */
804 /* Other texture operations require special extensions: */
805 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
808 invopr = GL_ONE_MINUS_SRC_ALPHA;
809 src3_target = GL_SOURCE3_ALPHA_NV;
810 opr3_target = GL_OPERAND3_ALPHA_NV;
813 invopr = GL_ONE_MINUS_SRC_COLOR;
814 src3_target = GL_SOURCE3_RGB_NV;
815 opr3_target = GL_OPERAND3_RGB_NV;
818 case D3DTOP_DISABLE: /* Only for alpha */
819 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
820 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
821 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
822 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
823 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
824 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
825 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
826 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
827 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
828 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
829 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
830 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
831 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
832 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
833 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
834 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
835 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
836 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
838 case D3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */
839 case D3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */
840 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
841 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
842 if (op == D3DTOP_SELECTARG1) {
843 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
844 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
845 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
846 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
848 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
849 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
850 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
851 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
853 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
854 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
855 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
856 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
857 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
858 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
859 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
860 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
861 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
862 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
863 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
864 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
867 case D3DTOP_MODULATE:
868 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
869 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
870 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
871 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
872 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
873 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
874 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
875 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
876 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
877 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
878 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
879 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
880 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
881 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
882 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
883 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
884 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
885 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
886 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
887 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
889 case D3DTOP_MODULATE2X:
890 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
891 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
892 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
893 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
894 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
895 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
896 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
897 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
898 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
899 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
900 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
901 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
902 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
903 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
904 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
905 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
906 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
907 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
908 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
909 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
911 case D3DTOP_MODULATE4X:
912 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
913 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
914 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
915 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
916 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
917 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
918 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
919 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
920 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
921 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
922 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
923 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
924 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
925 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
926 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
927 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
928 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
929 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
930 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
931 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
935 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
936 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
937 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
938 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
939 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
940 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
941 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
942 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
943 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
944 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
945 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
946 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
947 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
948 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
949 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
950 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
951 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
952 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
953 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
954 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
957 case D3DTOP_ADDSIGNED:
958 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
959 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
960 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
961 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
962 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
963 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
964 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
965 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
966 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
967 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
968 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
969 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
970 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
971 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
972 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
973 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
974 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
975 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
976 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
977 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
980 case D3DTOP_ADDSIGNED2X:
981 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
982 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
983 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
984 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
985 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
986 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
987 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
988 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
989 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
990 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
991 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
992 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
993 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
994 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
995 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
996 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
997 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
998 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
999 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1000 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1003 case D3DTOP_ADDSMOOTH:
1004 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1005 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1006 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1007 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1008 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1009 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1010 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1011 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1012 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1013 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1014 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1015 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1016 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1017 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1018 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1019 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1021 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1022 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1023 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1024 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1026 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1027 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1028 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1029 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1032 case D3DTOP_BLENDDIFFUSEALPHA:
1033 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1034 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1035 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1036 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1037 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1038 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1039 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
1040 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
1041 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1042 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1043 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1044 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1045 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1046 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1047 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
1048 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
1049 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1050 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1051 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1052 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1054 case D3DTOP_BLENDTEXTUREALPHA:
1055 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1056 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1057 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1058 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1059 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1060 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1061 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
1062 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
1063 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1064 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1065 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1066 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1067 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1068 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1069 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1070 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1071 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1072 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1073 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1074 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1076 case D3DTOP_BLENDFACTORALPHA:
1077 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1078 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1079 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1080 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1081 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1082 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1083 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT));
1084 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
1085 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1086 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1087 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1088 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1089 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1090 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1091 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
1092 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
1093 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1094 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1095 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1096 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1098 case D3DTOP_BLENDTEXTUREALPHAPM:
1099 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1100 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1101 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1102 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1103 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1104 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1105 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1106 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1107 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1108 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1109 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1110 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1111 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1112 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1113 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1114 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1115 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1116 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1117 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1118 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1120 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1121 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1122 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
1123 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
1124 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1125 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1126 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
1127 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1128 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1129 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1130 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1131 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
1132 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1133 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1134 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
1135 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1136 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1138 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1139 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1141 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1142 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1143 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1144 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1146 case D3DTOP_MODULATECOLOR_ADDALPHA:
1147 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1148 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1149 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1150 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1151 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1152 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1153 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1154 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1155 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1156 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1157 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1158 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1160 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1161 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1163 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1164 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1165 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1166 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1167 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1168 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1169 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1170 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1172 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1173 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1174 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1175 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1176 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1177 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1178 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1179 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1180 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1181 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1182 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1183 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1184 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1185 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1186 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1187 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1188 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1190 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1191 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1192 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1193 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1195 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1196 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1197 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1198 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1200 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1201 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1202 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1203 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1204 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1206 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1207 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1208 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1209 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1211 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1212 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1213 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1214 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1215 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1216 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1217 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1218 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1220 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1221 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1223 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1224 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1225 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1226 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1227 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1228 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1229 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1230 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1232 case D3DTOP_MULTIPLYADD:
1233 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1234 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1235 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1236 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1237 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1238 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1239 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1240 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1241 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1242 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1243 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1244 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1245 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
1246 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1247 glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
1248 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
1249 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
1250 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
1251 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1252 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1255 case D3DTOP_BUMPENVMAP:
1257 if (GL_SUPPORT(NV_TEXTURE_SHADER)) {
1259 texture unit 0: GL_TEXTURE_2D
1260 texture unit 1: GL_DOT_PRODUCT_NV
1261 texture unit 2: GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV
1262 texture unit 3: GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV
1271 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT00];
1272 m[0][0] = tmpvalue.f;
1273 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT01];
1274 m[0][1] = tmpvalue.f;
1275 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT10];
1276 m[1][0] = tmpvalue.f;
1277 tmpvalue.d = This->StateBlock->texture_state[Stage][D3DTSS_BUMPENVMAT11];
1278 m[1][1] = tmpvalue.f;
1280 /*FIXME("Stage %d matrix is (%.2f,%.2f),(%.2f,%.2f)\n", Stage, m[0][0], m[0][1], m[1][0], m[1][0]);*/
1282 if (FALSE == This->texture_shader_active) {
1283 This->texture_shader_active = TRUE;
1284 glEnable(GL_TEXTURE_SHADER_NV);
1288 glEnable(GL_REGISTER_COMBINERS_NV);
1289 glCombinerParameteriNV (GL_NUM_GENERAL_COMBINERS_NV, 1);
1290 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
1291 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
1292 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
1293 glCombinerInputNV (GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_RGB);
1294 glCombinerOutputNV (GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
1295 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
1296 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
1297 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_SIGNED_IDENTITY_NV, GL_ALPHA);
1298 glCombinerInputNV (GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_NONE, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
1299 glCombinerOutputNV (GL_COMBINER0_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_PRIMARY_COLOR_NV, 0, 0, 0, 0, 0);
1300 glDisable (GL_PER_STAGE_CONSTANTS_NV);
1301 glCombinerParameteriNV (GL_COLOR_SUM_CLAMP_NV, 0);
1302 glFinalCombinerInputNV (GL_VARIABLE_A_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1303 glFinalCombinerInputNV (GL_VARIABLE_B_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1304 glFinalCombinerInputNV (GL_VARIABLE_C_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1305 glFinalCombinerInputNV (GL_VARIABLE_D_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1306 glFinalCombinerInputNV (GL_VARIABLE_E_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1307 glFinalCombinerInputNV (GL_VARIABLE_F_NV, 0, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
1308 glFinalCombinerInputNV (GL_VARIABLE_G_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
1312 for (i = 0; i < Stage; i++) {
1313 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
1314 glActiveTexture(GL_TEXTURE0 + i);
1315 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
1316 checkGLcall("Activate texture..");
1318 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
1323 glActiveTextureARB(GL_TEXTURE0_ARB + Stage - 1);
1324 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
1327 glActiveTextureARB(GL_TEXTURE0_ARB + Stage);
1328 checkGLcall("Activate texture.. to update const color");
1329 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
1330 checkGLcall("glTexEnv");
1331 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + Stage - 1);
1332 checkGLcall("glTexEnv");
1333 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float*)&m[0]);
1334 checkGLcall("glTexEnv");
1341 case D3DTOP_BUMPENVMAPLUMINANCE:
1347 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
1348 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
1353 } /* GL_NV_texture_env_combine4 */
1355 Handled = TRUE; /* Again, assume handled */
1357 case D3DTOP_DISABLE: /* Only for alpha */
1358 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1359 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1360 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
1361 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
1362 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
1363 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
1364 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1365 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1367 case D3DTOP_SELECTARG1:
1368 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1369 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1370 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1371 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1372 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1373 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1374 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1375 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1377 case D3DTOP_SELECTARG2:
1378 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1379 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1380 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
1381 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1382 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1383 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1384 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1385 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1387 case D3DTOP_MODULATE:
1388 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1389 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1390 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1391 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1392 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1393 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1394 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1395 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1396 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1397 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1398 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1399 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1401 case D3DTOP_MODULATE2X:
1402 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1403 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1404 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1405 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1406 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1407 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1408 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1409 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1410 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1411 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1412 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1413 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1415 case D3DTOP_MODULATE4X:
1416 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1417 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1418 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1419 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1420 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1421 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1422 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1423 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1424 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1425 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1426 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1427 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1430 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1431 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1432 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1433 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1434 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1435 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1436 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1437 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1438 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1439 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1440 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1441 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1443 case D3DTOP_ADDSIGNED:
1444 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1445 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
1446 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1447 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1448 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1449 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1450 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1451 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1452 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1453 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1454 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1455 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1457 case D3DTOP_ADDSIGNED2X:
1458 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1459 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1460 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1461 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1462 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1463 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1464 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1465 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1466 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1467 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1468 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1469 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1471 case D3DTOP_SUBTRACT:
1472 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
1473 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
1474 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
1475 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1476 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1477 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1478 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1479 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1480 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1481 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1482 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1483 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1484 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1486 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1490 case D3DTOP_BLENDDIFFUSEALPHA:
1491 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1492 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1493 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1494 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1495 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1496 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1497 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1498 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1499 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1500 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1501 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
1502 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
1503 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1504 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1505 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1506 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1508 case D3DTOP_BLENDTEXTUREALPHA:
1509 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1510 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1511 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1512 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1513 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1514 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1515 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1516 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1517 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1518 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1519 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
1520 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
1521 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1522 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1523 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1524 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1526 case D3DTOP_BLENDFACTORALPHA:
1527 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1528 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1529 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1530 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1531 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1532 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1533 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1534 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1535 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1536 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1537 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
1538 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
1539 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1540 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1541 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1542 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1544 case D3DTOP_BLENDCURRENTALPHA:
1545 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1546 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1547 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1548 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1549 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1550 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1551 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1552 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1553 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1554 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1555 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
1556 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
1557 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1558 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1559 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1560 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1562 case D3DTOP_DOTPRODUCT3:
1563 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
1564 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
1565 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
1566 } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
1567 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
1568 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
1570 FIXME("This version of opengl does not support GL_DOT3\n");
1572 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1573 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1574 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1575 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1576 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1577 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1578 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1579 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1580 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1581 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1584 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1585 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1586 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1587 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1588 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1589 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1590 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1591 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1592 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1593 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1594 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
1595 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
1596 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
1597 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
1598 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1599 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1601 case D3DTOP_ADDSMOOTH:
1602 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1603 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1604 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1605 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1606 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1608 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1609 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1610 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1611 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1613 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1614 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1615 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1616 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1617 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1618 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1619 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1620 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1621 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1622 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1623 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1624 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1628 case D3DTOP_BLENDTEXTUREALPHAPM:
1629 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1630 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1631 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1632 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
1633 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
1634 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
1635 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
1636 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1637 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1638 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1639 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1640 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1641 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1642 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1643 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1644 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1645 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1649 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1650 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1651 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1652 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1653 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1654 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1656 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1657 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1658 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1659 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1661 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1662 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1663 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1664 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1665 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1666 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1667 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1668 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1669 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1670 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1671 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1672 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1676 case D3DTOP_MODULATECOLOR_ADDALPHA:
1677 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1678 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1679 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1680 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1681 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1682 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1683 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1684 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1685 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1687 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1688 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1689 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1690 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1692 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1693 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1694 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1695 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1696 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1697 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1698 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1699 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1703 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1704 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1705 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1706 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1707 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1708 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1710 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1711 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1712 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1713 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1715 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1716 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1717 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1718 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1719 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1720 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1721 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1722 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1723 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1724 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1725 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1726 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1730 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1731 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1732 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1733 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1734 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1735 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1737 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1738 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1739 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1740 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1742 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1743 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1744 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1745 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1747 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1748 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1749 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1750 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1752 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
1753 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
1754 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1755 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1756 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1757 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1758 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1759 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1763 case D3DTOP_MULTIPLYADD:
1764 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1765 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1766 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1767 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1768 checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
1769 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1770 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
1771 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1772 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1773 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1774 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1775 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1776 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1777 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1778 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1779 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1780 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1789 BOOL combineOK = TRUE;
1790 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1794 op2 = This->UpdateStateBlock->texture_state[Stage][D3DTSS_COLOROP];
1796 op2 = This->UpdateStateBlock->texture_state[Stage][D3DTSS_ALPHAOP];
1799 /* Note: If COMBINE4 in effect can't go back to combine! */
1801 case D3DTOP_ADDSMOOTH:
1802 case D3DTOP_BLENDTEXTUREALPHAPM:
1803 case D3DTOP_MODULATEALPHA_ADDCOLOR:
1804 case D3DTOP_MODULATECOLOR_ADDALPHA:
1805 case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
1806 case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
1807 case D3DTOP_MULTIPLYADD:
1808 /* Ignore those implemented in both cases */
1810 case D3DTOP_SELECTARG1:
1811 case D3DTOP_SELECTARG2:
1816 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%d, otherop=%ld, isAlpha(%d)\n", op, op2, isAlpha);
1824 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
1825 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
1834 /* After all the extensions, if still unhandled, report fixme */
1835 FIXME("Unhandled texture operation %d\n", op);