2 * Utility functions for the WineD3D Library
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006 Henri Verbeet
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
32 /*****************************************************************************
35 static const PixelFormatDesc formats[] = {
36 /*{WINED3DFORMAT ,alphamask ,redmask ,greenmask ,bluemask ,bpp ,isFourcc ,internal ,format ,type }*/
37 {WINED3DFMT_UNKNOWN ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,FALSE ,0 ,0 ,0 },
38 /* FourCC formats, kept here to have WINED3DFMT_R8G8B8(=20) at position 20 */
39 {WINED3DFMT_UYVY ,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,TRUE ,0 ,0 ,0 },
40 {WINED3DFMT_YUY2 ,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,TRUE ,0 ,0 ,0 },
41 {WINED3DFMT_DXT1 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,TRUE ,GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,GL_RGBA ,GL_UNSIGNED_BYTE },
42 {WINED3DFMT_DXT2 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,TRUE ,GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,GL_RGBA ,GL_UNSIGNED_BYTE },
43 {WINED3DFMT_DXT3 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,TRUE ,GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,GL_RGBA ,GL_UNSIGNED_BYTE },
44 {WINED3DFMT_DXT4 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,TRUE ,GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,GL_RGBA ,GL_UNSIGNED_BYTE },
45 {WINED3DFMT_DXT5 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,TRUE ,GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,GL_RGBA ,GL_UNSIGNED_BYTE },
46 {WINED3DFMT_MULTI2_ARGB8,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,TRUE ,0 ,0 ,0 },
47 {WINED3DFMT_G8R8_G8B8 ,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,TRUE ,0 ,0 ,0 },
48 {WINED3DFMT_R8G8_B8G8 ,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,TRUE ,0 ,0 ,0 },
50 {WINED3DFMT_R32F ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_RGB32F_ARB ,GL_RED ,GL_FLOAT },
51 {WINED3DFMT_G32R32F ,0x0 ,0x0 ,0x0 ,0x0 ,8 ,FALSE ,0 ,0 ,0 },
52 {WINED3DFMT_A32B32G32R32F,0x0 ,0x0 ,0x0 ,0x0 ,16 ,FALSE ,GL_RGBA32F_ARB ,GL_RGBA ,GL_FLOAT },
54 {WINED3DFMT_CxV8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,0 ,0 ,0 },
56 {WINED3DFMT_R16F ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,GL_RGB16F_ARB ,GL_RED ,GL_HALF_FLOAT_ARB },
57 {WINED3DFMT_G16R16F ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
58 {WINED3DFMT_A16B16G16R16F,0x0 ,0x0 ,0x0 ,0x0 ,8 ,FALSE ,GL_RGBA16F_ARB ,GL_RGBA ,GL_HALF_FLOAT_ARB },
59 /* Palettized formats */
60 {WINED3DFMT_A8P8 ,0x0000ff00 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,0 ,0 ,0 },
61 {WINED3DFMT_P8 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,FALSE ,GL_COLOR_INDEX8_EXT ,GL_COLOR_INDEX ,GL_UNSIGNED_BYTE },
62 /* Standard ARGB formats. Keep WINED3DFMT_R8G8B8(=20) at position 20 */
63 {WINED3DFMT_R8G8B8 ,0x0 ,0x00ff0000 ,0x0000ff00 ,0x000000ff ,3 ,FALSE ,GL_RGB8 ,GL_BGR ,GL_UNSIGNED_BYTE },
64 {WINED3DFMT_A8R8G8B8 ,0xff000000 ,0x00ff0000 ,0x0000ff00 ,0x000000ff ,4 ,FALSE ,GL_RGBA8 ,GL_BGRA ,GL_UNSIGNED_INT_8_8_8_8_REV },
65 {WINED3DFMT_X8R8G8B8 ,0x0 ,0x00ff0000 ,0x0000ff00 ,0x000000ff ,4 ,FALSE ,GL_RGB8 ,GL_BGRA ,GL_UNSIGNED_INT_8_8_8_8_REV },
66 {WINED3DFMT_R5G6B5 ,0x0 ,0x0000F800 ,0x000007e0 ,0x0000001f ,2 ,FALSE ,GL_RGB5 ,GL_RGB ,GL_UNSIGNED_SHORT_5_6_5 },
67 {WINED3DFMT_X1R5G5B5 ,0x0 ,0x00007c00 ,0x000003e0 ,0x0000001f ,2 ,FALSE ,GL_RGB5_A1 ,GL_BGRA ,GL_UNSIGNED_SHORT_1_5_5_5_REV },
68 {WINED3DFMT_A1R5G5B5 ,0x00008000 ,0x00007c00 ,0x000003e0 ,0x0000001f ,2 ,FALSE ,GL_RGB5_A1 ,GL_BGRA ,GL_UNSIGNED_SHORT_1_5_5_5_REV },
69 {WINED3DFMT_A4R4G4B4 ,0x0000f000 ,0x00000f00 ,0x000000f0 ,0x0000000f ,2 ,FALSE ,GL_RGBA4 ,GL_BGRA ,GL_UNSIGNED_SHORT_4_4_4_4_REV },
70 {WINED3DFMT_R3G3B2 ,0x0 ,0x000000e0 ,0x0000001c ,0x00000003 ,1 ,FALSE ,GL_R3_G3_B2 ,GL_RGB ,GL_UNSIGNED_BYTE_2_3_3_REV },
71 {WINED3DFMT_A8 ,0x000000ff ,0x0 ,0x0 ,0x0 ,1 ,FALSE ,GL_ALPHA8 ,GL_ALPHA ,GL_ALPHA },
72 {WINED3DFMT_A8R3G3B2 ,0x0000ff00 ,0x000000e0 ,0x0000001c ,0x00000003 ,2 ,FALSE ,0 ,0 ,0 },
73 {WINED3DFMT_X4R4G4B4 ,0x0 ,0x00000f00 ,0x000000f0 ,0x0000000f ,2 ,FALSE ,GL_RGB4 ,GL_BGRA ,GL_UNSIGNED_SHORT_4_4_4_4_REV },
74 {WINED3DFMT_A2B10G10R10 ,0xb0000000 ,0x000003ff ,0x000ffc00 ,0x3ff00000 ,4 ,FALSE ,GL_RGB ,GL_RGBA ,GL_UNSIGNED_INT_2_10_10_10_REV },
75 {WINED3DFMT_A8B8G8R8 ,0xff000000 ,0x000000ff ,0x0000ff00 ,0x00ff0000 ,4 ,FALSE ,GL_RGBA8 ,GL_RGBA ,GL_UNSIGNED_INT_8_8_8_8_REV },
76 {WINED3DFMT_X8B8G8R8 ,0x0 ,0x000000ff ,0x0000ff00 ,0x00ff0000 ,4 ,FALSE ,GL_RGB8 ,GL_RGBA ,GL_UNSIGNED_INT_8_8_8_8_REV },
77 {WINED3DFMT_G16R16 ,0x0 ,0x0000ffff ,0xffff0000 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
78 {WINED3DFMT_A2R10G10B10 ,0xb0000000 ,0x3ff00000 ,0x000ffc00 ,0x000003ff ,4 ,FALSE ,GL_RGBA ,GL_BGRA ,GL_UNSIGNED_INT_2_10_10_10_REV },
79 {WINED3DFMT_A16B16G16R16,0x0 ,0x0000ffff ,0xffff0000 ,0x0 ,8 ,FALSE ,GL_RGBA16_EXT ,GL_RGBA ,GL_UNSIGNED_SHORT },
81 {WINED3DFMT_L8 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,FALSE ,GL_LUMINANCE8 ,GL_LUMINANCE ,GL_UNSIGNED_BYTE },
82 {WINED3DFMT_A8L8 ,0x0000ff00 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,GL_LUMINANCE8_ALPHA8 ,GL_LUMINANCE_ALPHA ,GL_UNSIGNED_BYTE },
83 {WINED3DFMT_A4L4 ,0x000000f0 ,0x0 ,0x0 ,0x0 ,1 ,FALSE ,GL_LUMINANCE4_ALPHA4 ,GL_LUMINANCE_ALPHA ,GL_UNSIGNED_BYTE },
84 /* Bump mapping stuff */
85 {WINED3DFMT_V8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,GL_COLOR_INDEX8_EXT ,GL_COLOR_INDEX ,GL_UNSIGNED_BYTE },
86 {WINED3DFMT_L6V5U5 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,GL_COLOR_INDEX8_EXT ,GL_COLOR_INDEX ,GL_UNSIGNED_SHORT_5_5_5_1 },
87 {WINED3DFMT_X8L8V8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_RGBA8 ,GL_BGRA ,GL_UNSIGNED_BYTE },
88 {WINED3DFMT_Q8W8V8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_RGBA8 ,GL_RGBA ,GL_UNSIGNED_INT_8_8_8_8_REV/*?*/},
89 {WINED3DFMT_V16U16 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_COLOR_INDEX ,GL_COLOR_INDEX ,GL_UNSIGNED_SHORT },
90 {WINED3DFMT_W11V11U10 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
91 {WINED3DFMT_A2W10V10U10 ,0xb0000000 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
92 /* Depth stencil formats */
93 {WINED3DFMT_D16_LOCKABLE,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,GL_DEPTH_COMPONENT24_ARB,GL_DEPTH_COMPONENT,GL_UNSIGNED_SHORT },
94 {WINED3DFMT_D32 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_DEPTH_COMPONENT32_ARB,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT },
95 {WINED3DFMT_D15S1 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,GL_DEPTH_COMPONENT24_ARB,GL_DEPTH_COMPONENT,GL_UNSIGNED_SHORT },
96 {WINED3DFMT_D24S8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_DEPTH_COMPONENT24_ARB,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT },
97 {WINED3DFMT_D24X8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_DEPTH_COMPONENT24_ARB,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT },
98 {WINED3DFMT_D24X4S4 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_DEPTH_COMPONENT24_ARB,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT },
99 {WINED3DFMT_D16 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_DEPTH_COMPONENT24_ARB,GL_DEPTH_COMPONENT,GL_UNSIGNED_SHORT },
100 {WINED3DFMT_L16 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,GL_LUMINANCE16_EXT ,GL_LUMINANCE ,GL_UNSIGNED_SHORT },
101 {WINED3DFMT_D32F_LOCKABLE,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_DEPTH_COMPONENT32_ARB,GL_DEPTH_COMPONENT,GL_FLOAT },
102 {WINED3DFMT_D24FS8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,GL_DEPTH_COMPONENT24_ARB,GL_DEPTH_COMPONENT,GL_FLOAT },
103 /* Is this a vertex buffer? */
104 {WINED3DFMT_VERTEXDATA ,0x0 ,0x0 ,0x0 ,0x0 ,0 ,FALSE ,0 ,0 ,0 },
105 {WINED3DFMT_INDEX16 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,0 ,0 ,0 },
106 {WINED3DFMT_INDEX32 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
107 {WINED3DFMT_Q16W16V16U16,0x0 ,0x0 ,0x0 ,0x0 ,8 ,FALSE ,GL_COLOR_INDEX ,GL_COLOR_INDEX ,GL_UNSIGNED_SHORT }
110 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt)
112 /* First check if the format is at the position of its value.
113 * This will catch the argb formats before the loop is entered
115 if(fmt < (sizeof(formats) / sizeof(formats[0])) && formats[fmt].format == fmt) {
116 return &formats[fmt];
119 for(i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
120 if(formats[i].format == fmt) {
125 FIXME("Can't find format %s(%d) in the format lookup table\n", debug_d3dformat(fmt), fmt);
126 if(fmt == WINED3DFMT_UNKNOWN) {
127 ERR("Format table corrupt - Can't find WINED3DFMT_UNKNOWN\n");
130 /* Get the caller a valid pointer */
131 return getFormatDescEntry(WINED3DFMT_UNKNOWN);
134 /*****************************************************************************
135 * Trace formatting of useful values
137 const char* debug_d3dformat(WINED3DFORMAT fmt) {
139 #define FMT_TO_STR(fmt) case fmt: return #fmt
140 FMT_TO_STR(WINED3DFMT_UNKNOWN);
141 FMT_TO_STR(WINED3DFMT_R8G8B8);
142 FMT_TO_STR(WINED3DFMT_A8R8G8B8);
143 FMT_TO_STR(WINED3DFMT_X8R8G8B8);
144 FMT_TO_STR(WINED3DFMT_R5G6B5);
145 FMT_TO_STR(WINED3DFMT_X1R5G5B5);
146 FMT_TO_STR(WINED3DFMT_A1R5G5B5);
147 FMT_TO_STR(WINED3DFMT_A4R4G4B4);
148 FMT_TO_STR(WINED3DFMT_R3G3B2);
149 FMT_TO_STR(WINED3DFMT_A8);
150 FMT_TO_STR(WINED3DFMT_A8R3G3B2);
151 FMT_TO_STR(WINED3DFMT_X4R4G4B4);
152 FMT_TO_STR(WINED3DFMT_A2B10G10R10);
153 FMT_TO_STR(WINED3DFMT_A8B8G8R8);
154 FMT_TO_STR(WINED3DFMT_X8B8G8R8);
155 FMT_TO_STR(WINED3DFMT_G16R16);
156 FMT_TO_STR(WINED3DFMT_A2R10G10B10);
157 FMT_TO_STR(WINED3DFMT_A16B16G16R16);
158 FMT_TO_STR(WINED3DFMT_A8P8);
159 FMT_TO_STR(WINED3DFMT_P8);
160 FMT_TO_STR(WINED3DFMT_L8);
161 FMT_TO_STR(WINED3DFMT_A8L8);
162 FMT_TO_STR(WINED3DFMT_A4L4);
163 FMT_TO_STR(WINED3DFMT_V8U8);
164 FMT_TO_STR(WINED3DFMT_L6V5U5);
165 FMT_TO_STR(WINED3DFMT_X8L8V8U8);
166 FMT_TO_STR(WINED3DFMT_Q8W8V8U8);
167 FMT_TO_STR(WINED3DFMT_V16U16);
168 FMT_TO_STR(WINED3DFMT_W11V11U10);
169 FMT_TO_STR(WINED3DFMT_A2W10V10U10);
170 FMT_TO_STR(WINED3DFMT_UYVY);
171 FMT_TO_STR(WINED3DFMT_YUY2);
172 FMT_TO_STR(WINED3DFMT_DXT1);
173 FMT_TO_STR(WINED3DFMT_DXT2);
174 FMT_TO_STR(WINED3DFMT_DXT3);
175 FMT_TO_STR(WINED3DFMT_DXT4);
176 FMT_TO_STR(WINED3DFMT_DXT5);
177 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8);
178 FMT_TO_STR(WINED3DFMT_G8R8_G8B8);
179 FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
180 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
181 FMT_TO_STR(WINED3DFMT_D32);
182 FMT_TO_STR(WINED3DFMT_D15S1);
183 FMT_TO_STR(WINED3DFMT_D24S8);
184 FMT_TO_STR(WINED3DFMT_D24X8);
185 FMT_TO_STR(WINED3DFMT_D24X4S4);
186 FMT_TO_STR(WINED3DFMT_D16);
187 FMT_TO_STR(WINED3DFMT_L16);
188 FMT_TO_STR(WINED3DFMT_D32F_LOCKABLE);
189 FMT_TO_STR(WINED3DFMT_D24FS8);
190 FMT_TO_STR(WINED3DFMT_VERTEXDATA);
191 FMT_TO_STR(WINED3DFMT_INDEX16);
192 FMT_TO_STR(WINED3DFMT_INDEX32);
193 FMT_TO_STR(WINED3DFMT_Q16W16V16U16);
194 FMT_TO_STR(WINED3DFMT_R16F);
195 FMT_TO_STR(WINED3DFMT_G16R16F);
196 FMT_TO_STR(WINED3DFMT_A16B16G16R16F);
197 FMT_TO_STR(WINED3DFMT_R32F);
198 FMT_TO_STR(WINED3DFMT_G32R32F);
199 FMT_TO_STR(WINED3DFMT_A32B32G32R32F);
200 FMT_TO_STR(WINED3DFMT_CxV8U8);
205 fourcc[0] = (char)(fmt);
206 fourcc[1] = (char)(fmt >> 8);
207 fourcc[2] = (char)(fmt >> 16);
208 fourcc[3] = (char)(fmt >> 24);
210 if( isprint(fourcc[0]) && isprint(fourcc[1]) && isprint(fourcc[2]) && isprint(fourcc[3]) )
211 FIXME("Unrecognized %u (as fourcc: %s) WINED3DFORMAT!\n", fmt, fourcc);
213 FIXME("Unrecognized %u WINED3DFORMAT!\n", fmt);
215 return "unrecognized";
219 const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype) {
221 #define DEVTYPE_TO_STR(dev) case dev: return #dev
222 DEVTYPE_TO_STR(WINED3DDEVTYPE_HAL);
223 DEVTYPE_TO_STR(WINED3DDEVTYPE_REF);
224 DEVTYPE_TO_STR(WINED3DDEVTYPE_SW);
225 #undef DEVTYPE_TO_STR
227 FIXME("Unrecognized %u WINED3DDEVTYPE!\n", devtype);
228 return "unrecognized";
232 const char* debug_d3dusage(DWORD usage) {
233 switch (usage & WINED3DUSAGE_MASK) {
234 #define WINED3DUSAGE_TO_STR(u) case u: return #u
235 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET);
236 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL);
237 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY);
238 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING);
239 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP);
240 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS);
241 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES);
242 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES);
243 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC);
244 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP);
245 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP);
246 #undef WINED3DUSAGE_TO_STR
247 case 0: return "none";
249 FIXME("Unrecognized %u Usage!\n", usage);
250 return "unrecognized";
254 const char* debug_d3dusagequery(DWORD usagequery) {
255 switch (usagequery & WINED3DUSAGE_QUERY_MASK) {
256 #define WINED3DUSAGEQUERY_TO_STR(u) case u: return #u
257 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER);
258 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
259 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING);
260 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD);
261 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE);
262 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE);
263 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP);
264 #undef WINED3DUSAGEQUERY_TO_STR
265 case 0: return "none";
267 FIXME("Unrecognized %u Usage Query!\n", usagequery);
268 return "unrecognized";
272 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method) {
274 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
275 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_DEFAULT);
276 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_PARTIALU);
277 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_PARTIALV);
278 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_CROSSUV);
279 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_UV);
280 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_LOOKUP);
281 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_LOOKUPPRESAMPLED);
282 #undef WINED3DDECLMETHOD_TO_STR
284 FIXME("Unrecognized %u declaration method!\n", method);
285 return "unrecognized";
289 const char* debug_d3ddecltype(WINED3DDECLTYPE type) {
291 #define WINED3DDECLTYPE_TO_STR(u) case u: return #u
292 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT1);
293 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT2);
294 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT3);
295 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT4);
296 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_D3DCOLOR);
297 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UBYTE4);
298 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT2);
299 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT4);
300 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UBYTE4N);
301 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT2N);
302 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT4N);
303 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_USHORT2N);
304 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_USHORT4N);
305 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UDEC3);
306 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_DEC3N);
307 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT16_2);
308 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT16_4);
309 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UNUSED);
310 #undef WINED3DDECLTYPE_TO_STR
312 FIXME("Unrecognized %u declaration type!\n", type);
313 return "unrecognized";
317 const char* debug_d3ddeclusage(BYTE usage) {
319 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
320 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_POSITION);
321 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_BLENDWEIGHT);
322 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_BLENDINDICES);
323 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_NORMAL);
324 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_PSIZE);
325 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_TEXCOORD);
326 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_TANGENT);
327 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_BINORMAL);
328 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_TESSFACTOR);
329 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_POSITIONT);
330 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_COLOR);
331 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_FOG);
332 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_DEPTH);
333 WINED3DDECLUSAGE_TO_STR(D3DDECLUSAGE_SAMPLE);
334 #undef WINED3DDECLUSAGE_TO_STR
336 FIXME("Unrecognized %u declaration usage!\n", usage);
337 return "unrecognized";
341 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res) {
343 #define RES_TO_STR(res) case res: return #res;
344 RES_TO_STR(WINED3DRTYPE_SURFACE);
345 RES_TO_STR(WINED3DRTYPE_VOLUME);
346 RES_TO_STR(WINED3DRTYPE_TEXTURE);
347 RES_TO_STR(WINED3DRTYPE_VOLUMETEXTURE);
348 RES_TO_STR(WINED3DRTYPE_CUBETEXTURE);
349 RES_TO_STR(WINED3DRTYPE_VERTEXBUFFER);
350 RES_TO_STR(WINED3DRTYPE_INDEXBUFFER);
353 FIXME("Unrecognized %u WINED3DRESOURCETYPE!\n", res);
354 return "unrecognized";
358 const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType) {
359 switch (PrimitiveType) {
360 #define PRIM_TO_STR(prim) case prim: return #prim;
361 PRIM_TO_STR(WINED3DPT_POINTLIST);
362 PRIM_TO_STR(WINED3DPT_LINELIST);
363 PRIM_TO_STR(WINED3DPT_LINESTRIP);
364 PRIM_TO_STR(WINED3DPT_TRIANGLELIST);
365 PRIM_TO_STR(WINED3DPT_TRIANGLESTRIP);
366 PRIM_TO_STR(WINED3DPT_TRIANGLEFAN);
369 FIXME("Unrecognized %u WINED3DPRIMITIVETYPE!\n", PrimitiveType);
370 return "unrecognized";
374 const char* debug_d3drenderstate(DWORD state) {
376 #define D3DSTATE_TO_STR(u) case u: return #u
377 D3DSTATE_TO_STR(WINED3DRS_TEXTUREHANDLE );
378 D3DSTATE_TO_STR(WINED3DRS_ANTIALIAS );
379 D3DSTATE_TO_STR(WINED3DRS_TEXTUREADDRESS );
380 D3DSTATE_TO_STR(WINED3DRS_TEXTUREPERSPECTIVE );
381 D3DSTATE_TO_STR(WINED3DRS_WRAPU );
382 D3DSTATE_TO_STR(WINED3DRS_WRAPV );
383 D3DSTATE_TO_STR(WINED3DRS_ZENABLE );
384 D3DSTATE_TO_STR(WINED3DRS_FILLMODE );
385 D3DSTATE_TO_STR(WINED3DRS_SHADEMODE );
386 D3DSTATE_TO_STR(WINED3DRS_LINEPATTERN );
387 D3DSTATE_TO_STR(WINED3DRS_MONOENABLE );
388 D3DSTATE_TO_STR(WINED3DRS_ROP2 );
389 D3DSTATE_TO_STR(WINED3DRS_PLANEMASK );
390 D3DSTATE_TO_STR(WINED3DRS_ZWRITEENABLE );
391 D3DSTATE_TO_STR(WINED3DRS_ALPHATESTENABLE );
392 D3DSTATE_TO_STR(WINED3DRS_LASTPIXEL );
393 D3DSTATE_TO_STR(WINED3DRS_TEXTUREMAG );
394 D3DSTATE_TO_STR(WINED3DRS_TEXTUREMIN );
395 D3DSTATE_TO_STR(WINED3DRS_SRCBLEND );
396 D3DSTATE_TO_STR(WINED3DRS_DESTBLEND );
397 D3DSTATE_TO_STR(WINED3DRS_TEXTUREMAPBLEND );
398 D3DSTATE_TO_STR(WINED3DRS_CULLMODE );
399 D3DSTATE_TO_STR(WINED3DRS_ZFUNC );
400 D3DSTATE_TO_STR(WINED3DRS_ALPHAREF );
401 D3DSTATE_TO_STR(WINED3DRS_ALPHAFUNC );
402 D3DSTATE_TO_STR(WINED3DRS_DITHERENABLE );
403 D3DSTATE_TO_STR(WINED3DRS_ALPHABLENDENABLE );
404 D3DSTATE_TO_STR(WINED3DRS_FOGENABLE );
405 D3DSTATE_TO_STR(WINED3DRS_SPECULARENABLE );
406 D3DSTATE_TO_STR(WINED3DRS_ZVISIBLE );
407 D3DSTATE_TO_STR(WINED3DRS_SUBPIXEL );
408 D3DSTATE_TO_STR(WINED3DRS_SUBPIXELX );
409 D3DSTATE_TO_STR(WINED3DRS_STIPPLEDALPHA );
410 D3DSTATE_TO_STR(WINED3DRS_FOGCOLOR );
411 D3DSTATE_TO_STR(WINED3DRS_FOGTABLEMODE );
412 D3DSTATE_TO_STR(WINED3DRS_FOGSTART );
413 D3DSTATE_TO_STR(WINED3DRS_FOGEND );
414 D3DSTATE_TO_STR(WINED3DRS_FOGDENSITY );
415 D3DSTATE_TO_STR(WINED3DRS_STIPPLEENABLE );
416 D3DSTATE_TO_STR(WINED3DRS_EDGEANTIALIAS );
417 D3DSTATE_TO_STR(WINED3DRS_COLORKEYENABLE );
418 D3DSTATE_TO_STR(WINED3DRS_BORDERCOLOR );
419 D3DSTATE_TO_STR(WINED3DRS_TEXTUREADDRESSU );
420 D3DSTATE_TO_STR(WINED3DRS_TEXTUREADDRESSV );
421 D3DSTATE_TO_STR(WINED3DRS_MIPMAPLODBIAS );
422 D3DSTATE_TO_STR(WINED3DRS_ZBIAS );
423 D3DSTATE_TO_STR(WINED3DRS_RANGEFOGENABLE );
424 D3DSTATE_TO_STR(WINED3DRS_ANISOTROPY );
425 D3DSTATE_TO_STR(WINED3DRS_FLUSHBATCH );
426 D3DSTATE_TO_STR(WINED3DRS_TRANSLUCENTSORTINDEPENDENT);
427 D3DSTATE_TO_STR(WINED3DRS_STENCILENABLE );
428 D3DSTATE_TO_STR(WINED3DRS_STENCILFAIL );
429 D3DSTATE_TO_STR(WINED3DRS_STENCILZFAIL );
430 D3DSTATE_TO_STR(WINED3DRS_STENCILPASS );
431 D3DSTATE_TO_STR(WINED3DRS_STENCILFUNC );
432 D3DSTATE_TO_STR(WINED3DRS_STENCILREF );
433 D3DSTATE_TO_STR(WINED3DRS_STENCILMASK );
434 D3DSTATE_TO_STR(WINED3DRS_STENCILWRITEMASK );
435 D3DSTATE_TO_STR(WINED3DRS_TEXTUREFACTOR );
436 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN00 );
437 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN01 );
438 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN02 );
439 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN03 );
440 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN04 );
441 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN05 );
442 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN06 );
443 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN07 );
444 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN08 );
445 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN09 );
446 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN10 );
447 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN11 );
448 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN12 );
449 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN13 );
450 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN14 );
451 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN15 );
452 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN16 );
453 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN17 );
454 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN18 );
455 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN19 );
456 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN20 );
457 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN21 );
458 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN22 );
459 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN23 );
460 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN24 );
461 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN25 );
462 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN26 );
463 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN27 );
464 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN28 );
465 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN29 );
466 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN30 );
467 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN31 );
468 D3DSTATE_TO_STR(WINED3DRS_WRAP0 );
469 D3DSTATE_TO_STR(WINED3DRS_WRAP1 );
470 D3DSTATE_TO_STR(WINED3DRS_WRAP2 );
471 D3DSTATE_TO_STR(WINED3DRS_WRAP3 );
472 D3DSTATE_TO_STR(WINED3DRS_WRAP4 );
473 D3DSTATE_TO_STR(WINED3DRS_WRAP5 );
474 D3DSTATE_TO_STR(WINED3DRS_WRAP6 );
475 D3DSTATE_TO_STR(WINED3DRS_WRAP7 );
476 D3DSTATE_TO_STR(WINED3DRS_CLIPPING );
477 D3DSTATE_TO_STR(WINED3DRS_LIGHTING );
478 D3DSTATE_TO_STR(WINED3DRS_EXTENTS );
479 D3DSTATE_TO_STR(WINED3DRS_AMBIENT );
480 D3DSTATE_TO_STR(WINED3DRS_FOGVERTEXMODE );
481 D3DSTATE_TO_STR(WINED3DRS_COLORVERTEX );
482 D3DSTATE_TO_STR(WINED3DRS_LOCALVIEWER );
483 D3DSTATE_TO_STR(WINED3DRS_NORMALIZENORMALS );
484 D3DSTATE_TO_STR(WINED3DRS_COLORKEYBLENDENABLE );
485 D3DSTATE_TO_STR(WINED3DRS_DIFFUSEMATERIALSOURCE );
486 D3DSTATE_TO_STR(WINED3DRS_SPECULARMATERIALSOURCE );
487 D3DSTATE_TO_STR(WINED3DRS_AMBIENTMATERIALSOURCE );
488 D3DSTATE_TO_STR(WINED3DRS_EMISSIVEMATERIALSOURCE );
489 D3DSTATE_TO_STR(WINED3DRS_VERTEXBLEND );
490 D3DSTATE_TO_STR(WINED3DRS_CLIPPLANEENABLE );
491 D3DSTATE_TO_STR(WINED3DRS_SOFTWAREVERTEXPROCESSING );
492 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE );
493 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MIN );
494 D3DSTATE_TO_STR(WINED3DRS_POINTSPRITEENABLE );
495 D3DSTATE_TO_STR(WINED3DRS_POINTSCALEENABLE );
496 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_A );
497 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_B );
498 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_C );
499 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEANTIALIAS );
500 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEMASK );
501 D3DSTATE_TO_STR(WINED3DRS_PATCHEDGESTYLE );
502 D3DSTATE_TO_STR(WINED3DRS_PATCHSEGMENTS );
503 D3DSTATE_TO_STR(WINED3DRS_DEBUGMONITORTOKEN );
504 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MAX );
505 D3DSTATE_TO_STR(WINED3DRS_INDEXEDVERTEXBLENDENABLE );
506 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE );
507 D3DSTATE_TO_STR(WINED3DRS_TWEENFACTOR );
508 D3DSTATE_TO_STR(WINED3DRS_BLENDOP );
509 D3DSTATE_TO_STR(WINED3DRS_POSITIONDEGREE );
510 D3DSTATE_TO_STR(WINED3DRS_NORMALDEGREE );
511 D3DSTATE_TO_STR(WINED3DRS_SCISSORTESTENABLE );
512 D3DSTATE_TO_STR(WINED3DRS_SLOPESCALEDEPTHBIAS );
513 D3DSTATE_TO_STR(WINED3DRS_ANTIALIASEDLINEENABLE );
514 D3DSTATE_TO_STR(WINED3DRS_MINTESSELLATIONLEVEL );
515 D3DSTATE_TO_STR(WINED3DRS_MAXTESSELLATIONLEVEL );
516 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_X );
517 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Y );
518 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Z );
519 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_W );
520 D3DSTATE_TO_STR(WINED3DRS_ENABLEADAPTIVETESSELLATION);
521 D3DSTATE_TO_STR(WINED3DRS_TWOSIDEDSTENCILMODE );
522 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFAIL );
523 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILZFAIL );
524 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILPASS );
525 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFUNC );
526 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE1 );
527 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE2 );
528 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE3 );
529 D3DSTATE_TO_STR(WINED3DRS_BLENDFACTOR );
530 D3DSTATE_TO_STR(WINED3DRS_SRGBWRITEENABLE );
531 D3DSTATE_TO_STR(WINED3DRS_DEPTHBIAS );
532 D3DSTATE_TO_STR(WINED3DRS_WRAP8 );
533 D3DSTATE_TO_STR(WINED3DRS_WRAP9 );
534 D3DSTATE_TO_STR(WINED3DRS_WRAP10 );
535 D3DSTATE_TO_STR(WINED3DRS_WRAP11 );
536 D3DSTATE_TO_STR(WINED3DRS_WRAP12 );
537 D3DSTATE_TO_STR(WINED3DRS_WRAP13 );
538 D3DSTATE_TO_STR(WINED3DRS_WRAP14 );
539 D3DSTATE_TO_STR(WINED3DRS_WRAP15 );
540 D3DSTATE_TO_STR(WINED3DRS_SEPARATEALPHABLENDENABLE );
541 D3DSTATE_TO_STR(WINED3DRS_SRCBLENDALPHA );
542 D3DSTATE_TO_STR(WINED3DRS_DESTBLENDALPHA );
543 D3DSTATE_TO_STR(WINED3DRS_BLENDOPALPHA );
544 #undef D3DSTATE_TO_STR
546 FIXME("Unrecognized %u render state!\n", state);
547 return "unrecognized";
551 const char* debug_d3dsamplerstate(DWORD state) {
553 #define D3DSTATE_TO_STR(u) case u: return #u
554 D3DSTATE_TO_STR(WINED3DSAMP_BORDERCOLOR );
555 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSU );
556 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSV );
557 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSW );
558 D3DSTATE_TO_STR(WINED3DSAMP_MAGFILTER );
559 D3DSTATE_TO_STR(WINED3DSAMP_MINFILTER );
560 D3DSTATE_TO_STR(WINED3DSAMP_MIPFILTER );
561 D3DSTATE_TO_STR(WINED3DSAMP_MIPMAPLODBIAS);
562 D3DSTATE_TO_STR(WINED3DSAMP_MAXMIPLEVEL );
563 D3DSTATE_TO_STR(WINED3DSAMP_MAXANISOTROPY);
564 D3DSTATE_TO_STR(WINED3DSAMP_SRGBTEXTURE );
565 D3DSTATE_TO_STR(WINED3DSAMP_ELEMENTINDEX );
566 D3DSTATE_TO_STR(WINED3DSAMP_DMAPOFFSET );
567 #undef D3DSTATE_TO_STR
569 FIXME("Unrecognized %u sampler state!\n", state);
570 return "unrecognized";
574 const char* debug_d3dtexturestate(DWORD state) {
576 #define D3DSTATE_TO_STR(u) case u: return #u
577 D3DSTATE_TO_STR(WINED3DTSS_COLOROP );
578 D3DSTATE_TO_STR(WINED3DTSS_COLORARG1 );
579 D3DSTATE_TO_STR(WINED3DTSS_COLORARG2 );
580 D3DSTATE_TO_STR(WINED3DTSS_ALPHAOP );
581 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG1 );
582 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG2 );
583 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT00 );
584 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT01 );
585 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT10 );
586 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT11 );
587 D3DSTATE_TO_STR(WINED3DTSS_TEXCOORDINDEX );
588 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLSCALE );
589 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLOFFSET );
590 D3DSTATE_TO_STR(WINED3DTSS_TEXTURETRANSFORMFLAGS );
591 D3DSTATE_TO_STR(WINED3DTSS_ADDRESSW );
592 D3DSTATE_TO_STR(WINED3DTSS_COLORARG0 );
593 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG0 );
594 D3DSTATE_TO_STR(WINED3DTSS_RESULTARG );
595 D3DSTATE_TO_STR(WINED3DTSS_CONSTANT );
596 #undef D3DSTATE_TO_STR
598 /* Note WINED3DTSS are not consecutive, so skip these */
602 FIXME("Unrecognized %u texture state!\n", state);
603 return "unrecognized";
607 const char* debug_d3dtop(WINED3DTEXTUREOP d3dtop) {
609 #define D3DTOP_TO_STR(u) case u: return #u
610 D3DTOP_TO_STR(WINED3DTOP_DISABLE);
611 D3DTOP_TO_STR(WINED3DTOP_SELECTARG1);
612 D3DTOP_TO_STR(WINED3DTOP_SELECTARG2);
613 D3DTOP_TO_STR(WINED3DTOP_MODULATE);
614 D3DTOP_TO_STR(WINED3DTOP_MODULATE2X);
615 D3DTOP_TO_STR(WINED3DTOP_MODULATE4X);
616 D3DTOP_TO_STR(WINED3DTOP_ADD);
617 D3DTOP_TO_STR(WINED3DTOP_ADDSIGNED);
618 D3DTOP_TO_STR(WINED3DTOP_SUBTRACT);
619 D3DTOP_TO_STR(WINED3DTOP_ADDSMOOTH);
620 D3DTOP_TO_STR(WINED3DTOP_BLENDDIFFUSEALPHA);
621 D3DTOP_TO_STR(WINED3DTOP_BLENDTEXTUREALPHA);
622 D3DTOP_TO_STR(WINED3DTOP_BLENDFACTORALPHA);
623 D3DTOP_TO_STR(WINED3DTOP_BLENDTEXTUREALPHAPM);
624 D3DTOP_TO_STR(WINED3DTOP_BLENDCURRENTALPHA);
625 D3DTOP_TO_STR(WINED3DTOP_PREMODULATE);
626 D3DTOP_TO_STR(WINED3DTOP_MODULATEALPHA_ADDCOLOR);
627 D3DTOP_TO_STR(WINED3DTOP_MODULATECOLOR_ADDALPHA);
628 D3DTOP_TO_STR(WINED3DTOP_MODULATEINVALPHA_ADDCOLOR);
629 D3DTOP_TO_STR(WINED3DTOP_MODULATEINVCOLOR_ADDALPHA);
630 D3DTOP_TO_STR(WINED3DTOP_BUMPENVMAP);
631 D3DTOP_TO_STR(WINED3DTOP_BUMPENVMAPLUMINANCE);
632 D3DTOP_TO_STR(WINED3DTOP_DOTPRODUCT3);
633 D3DTOP_TO_STR(WINED3DTOP_MULTIPLYADD);
634 D3DTOP_TO_STR(WINED3DTOP_LERP);
637 FIXME("Unrecognized %u WINED3DTOP\n", d3dtop);
638 return "unrecognized";
642 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype) {
644 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
645 TSTYPE_TO_STR(WINED3DTS_VIEW);
646 TSTYPE_TO_STR(WINED3DTS_PROJECTION);
647 TSTYPE_TO_STR(WINED3DTS_TEXTURE0);
648 TSTYPE_TO_STR(WINED3DTS_TEXTURE1);
649 TSTYPE_TO_STR(WINED3DTS_TEXTURE2);
650 TSTYPE_TO_STR(WINED3DTS_TEXTURE3);
651 TSTYPE_TO_STR(WINED3DTS_TEXTURE4);
652 TSTYPE_TO_STR(WINED3DTS_TEXTURE5);
653 TSTYPE_TO_STR(WINED3DTS_TEXTURE6);
654 TSTYPE_TO_STR(WINED3DTS_TEXTURE7);
655 TSTYPE_TO_STR(WINED3DTS_WORLDMATRIX(0));
658 if (tstype > 256 && tstype < 512) {
659 FIXME("WINED3DTS_WORLDMATRIX(%u). 1..255 not currently supported\n", tstype);
660 return ("WINED3DTS_WORLDMATRIX > 0");
662 FIXME("Unrecognized %u WINED3DTS\n", tstype);
663 return "unrecognized";
667 const char* debug_d3dpool(WINED3DPOOL Pool) {
669 #define POOL_TO_STR(p) case p: return #p;
670 POOL_TO_STR(WINED3DPOOL_DEFAULT);
671 POOL_TO_STR(WINED3DPOOL_MANAGED);
672 POOL_TO_STR(WINED3DPOOL_SYSTEMMEM);
673 POOL_TO_STR(WINED3DPOOL_SCRATCH);
676 FIXME("Unrecognized %u WINED3DPOOL!\n", Pool);
677 return "unrecognized";
681 /*****************************************************************************
682 * Useful functions mapping GL <-> D3D values
684 GLenum StencilOp(DWORD op) {
686 case WINED3DSTENCILOP_KEEP : return GL_KEEP;
687 case WINED3DSTENCILOP_ZERO : return GL_ZERO;
688 case WINED3DSTENCILOP_REPLACE : return GL_REPLACE;
689 case WINED3DSTENCILOP_INCRSAT : return GL_INCR;
690 case WINED3DSTENCILOP_DECRSAT : return GL_DECR;
691 case WINED3DSTENCILOP_INVERT : return GL_INVERT;
692 case WINED3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
693 case WINED3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
695 FIXME("Unrecognized stencil op %d\n", op);
700 GLenum CompareFunc(DWORD func) {
701 switch ((WINED3DCMPFUNC)func) {
702 case WINED3DCMP_NEVER : return GL_NEVER;
703 case WINED3DCMP_LESS : return GL_LESS;
704 case WINED3DCMP_EQUAL : return GL_EQUAL;
705 case WINED3DCMP_LESSEQUAL : return GL_LEQUAL;
706 case WINED3DCMP_GREATER : return GL_GREATER;
707 case WINED3DCMP_NOTEQUAL : return GL_NOTEQUAL;
708 case WINED3DCMP_GREATEREQUAL : return GL_GEQUAL;
709 case WINED3DCMP_ALWAYS : return GL_ALWAYS;
711 FIXME("Unrecognized WINED3DCMPFUNC value %d\n", func);
716 static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) {
718 case WINED3DTA_DIFFUSE:
719 return GL_PRIMARY_COLOR_NV;
721 case WINED3DTA_CURRENT:
722 if (stage) return GL_SPARE0_NV;
723 else return GL_PRIMARY_COLOR_NV;
725 case WINED3DTA_TEXTURE:
726 if (texture_idx > -1) return GL_TEXTURE0_ARB + texture_idx;
727 else return GL_PRIMARY_COLOR_NV;
729 case WINED3DTA_TFACTOR:
730 return GL_CONSTANT_COLOR0_NV;
732 case WINED3DTA_SPECULAR:
733 return GL_SECONDARY_COLOR_NV;
736 /* TODO: Support WINED3DTSS_RESULTARG */
737 FIXME("WINED3DTA_TEMP, not properly supported.\n");
740 case WINED3DTA_CONSTANT:
741 /* TODO: Support per stage constants (WINED3DTSS_CONSTANT, NV_register_combiners2) */
742 FIXME("WINED3DTA_CONSTANT, not properly supported.\n");
743 return GL_CONSTANT_COLOR1_NV;
746 FIXME("Unrecognized texture arg %#x\n", d3dta);
751 static GLenum invert_mapping(GLenum mapping) {
752 if (mapping == GL_UNSIGNED_INVERT_NV) return GL_SIGNED_IDENTITY_NV;
753 else if (mapping == GL_SIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
755 FIXME("Unhandled mapping %#x\n", mapping);
759 static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* input, GLenum* mapping, GLenum *component_usage, INT texture_idx) {
760 /* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
762 if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
763 else *mapping = GL_SIGNED_IDENTITY_NV;
765 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
766 * should be used for all input components. */
767 if (is_alpha || arg & WINED3DTA_ALPHAREPLICATE) *component_usage = GL_ALPHA;
768 else *component_usage = GL_RGB;
770 *input = d3dta_to_combiner_input(arg & WINED3DTA_SELECTMASK, stage, texture_idx);
776 GLenum component_usage[3];
779 static BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3) {
780 if (op == WINED3DTOP_DISABLE) return FALSE;
781 if (This->stateBlock->textures[stage]) return FALSE;
783 if (arg1 == WINED3DTA_TEXTURE && op != WINED3DTOP_SELECTARG2) return TRUE;
784 if (arg2 == WINED3DTA_TEXTURE && op != WINED3DTOP_SELECTARG1) return TRUE;
785 if (arg3 == WINED3DTA_TEXTURE && (op == WINED3DTOP_MULTIPLYADD || op == WINED3DTOP_LERP)) return TRUE;
790 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx) {
791 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl*)iface;
792 tex_op_args tex_op_args = {{0}, {0}, {0}};
793 GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
794 GLenum target = GL_COMBINER0_NV + stage;
796 TRACE("stage %d, is_alpha %d, op %s, arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
797 stage, is_alpha, debug_d3dtop(op), arg1, arg2, arg3, texture_idx);
799 /* If a texture stage references an invalid texture unit the stage just
800 * passes through the result from the previous stage */
801 if (is_invalid_op(This, stage, op, arg1, arg2, arg3)) {
802 arg1 = WINED3DTA_CURRENT;
803 op = WINED3DTOP_SELECTARG1;
806 get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0],
807 &tex_op_args.mapping[0], &tex_op_args.component_usage[0], texture_idx);
808 get_src_and_opr_nvrc(stage, arg2, is_alpha, &tex_op_args.input[1],
809 &tex_op_args.mapping[1], &tex_op_args.component_usage[1], texture_idx);
810 get_src_and_opr_nvrc(stage, arg3, is_alpha, &tex_op_args.input[2],
811 &tex_op_args.mapping[2], &tex_op_args.component_usage[2], texture_idx);
817 case WINED3DTOP_DISABLE:
819 if (!is_alpha) ERR("Shouldn't be called for WINED3DTSS_COLOROP (WINED3DTOP_DISABLE)\n");
820 /* Input, prev_alpha*1 */
821 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
822 GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
823 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
824 GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
827 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
828 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
831 case WINED3DTOP_SELECTARG1:
832 case WINED3DTOP_SELECTARG2:
834 if (op == WINED3DTOP_SELECTARG1) {
835 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
836 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
838 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
839 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
841 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
842 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
845 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
846 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
849 case WINED3DTOP_MODULATE:
850 case WINED3DTOP_MODULATE2X:
851 case WINED3DTOP_MODULATE4X:
852 /* Input, arg1*arg2 */
853 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
854 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
855 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
856 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
859 if (op == WINED3DTOP_MODULATE) {
860 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
861 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
862 } else if (op == WINED3DTOP_MODULATE2X) {
863 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
864 GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
865 } else if (op == WINED3DTOP_MODULATE4X) {
866 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
867 GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
872 case WINED3DTOP_ADDSIGNED:
873 case WINED3DTOP_ADDSIGNED2X:
874 /* Input, arg1*1+arg2*1 */
875 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
876 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
877 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
878 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
879 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
880 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
881 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
882 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
885 if (op == WINED3DTOP_ADD) {
886 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
887 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
888 } else if (op == WINED3DTOP_ADDSIGNED) {
889 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
890 GL_SPARE0_NV, GL_NONE, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
891 } else if (op == WINED3DTOP_ADDSIGNED2X) {
892 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
893 GL_SPARE0_NV, GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
897 case WINED3DTOP_SUBTRACT:
898 /* Input, arg1*1+-arg2*1 */
899 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
900 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
901 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
902 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
903 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
904 tex_op_args.input[1], GL_SIGNED_NEGATE_NV, tex_op_args.component_usage[1]));
905 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
906 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
909 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
910 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
913 case WINED3DTOP_ADDSMOOTH:
914 /* Input, arg1*1+(1-arg1)*arg2 */
915 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
916 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
917 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
918 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
919 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
920 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
921 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
922 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
925 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
926 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
929 case WINED3DTOP_BLENDDIFFUSEALPHA:
930 case WINED3DTOP_BLENDTEXTUREALPHA:
931 case WINED3DTOP_BLENDFACTORALPHA:
932 case WINED3DTOP_BLENDTEXTUREALPHAPM:
933 case WINED3DTOP_BLENDCURRENTALPHA:
935 GLenum alpha_src = GL_PRIMARY_COLOR_NV;
936 if (op == WINED3DTOP_BLENDDIFFUSEALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx);
937 else if (op == WINED3DTOP_BLENDTEXTUREALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
938 else if (op == WINED3DTOP_BLENDFACTORALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx);
939 else if (op == WINED3DTOP_BLENDTEXTUREALPHAPM) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
940 else if (op == WINED3DTOP_BLENDCURRENTALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx);
941 else FIXME("Unhandled WINED3DTOP %s, shouldn't happen\n", debug_d3dtop(op));
943 /* Input, arg1*alpha_src+arg2*(1-alpha_src) */
944 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
945 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
946 if (op == WINED3DTOP_BLENDTEXTUREALPHAPM)
948 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
949 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
951 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
952 alpha_src, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
954 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
955 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
956 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
957 alpha_src, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
960 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
961 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
965 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
966 /* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */
967 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEALPHA_ADDCOLOR)\n");
968 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
969 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
970 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
971 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
972 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
973 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
974 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
975 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
978 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
979 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
982 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
983 /* Input, arg1_rgb*arg2_rgb+arg1_alpha*1 */
984 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATECOLOR_ADDALPHA)\n");
985 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
986 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
987 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
988 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
989 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
990 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
991 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
992 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
995 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
996 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
999 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
1000 /* Input, (1-arg1_alpha)*arg2_rgb+arg1_rgb*1 */
1001 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR)\n");
1002 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
1003 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), GL_ALPHA));
1004 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
1005 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
1006 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
1007 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
1008 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
1009 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
1012 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
1013 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
1016 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
1017 /* Input, (1-arg1_rgb)*arg2_rgb+arg1_alpha*1 */
1018 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA)\n");
1019 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
1020 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
1021 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
1022 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
1023 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
1024 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
1025 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
1026 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
1029 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
1030 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
1033 case WINED3DTOP_DOTPRODUCT3:
1034 /* Input, arg1 . arg2 */
1035 /* FIXME: DX7 uses a different calculation? */
1036 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
1037 tex_op_args.input[0], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[0]));
1038 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
1039 tex_op_args.input[1], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[1]));
1042 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
1043 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE));
1046 case WINED3DTOP_MULTIPLYADD:
1047 /* Input, arg1*1+arg2*arg3 */
1048 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
1049 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
1050 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
1051 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
1052 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
1053 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
1054 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
1055 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
1058 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
1059 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
1062 case WINED3DTOP_LERP:
1063 /* Input, arg1*arg2+(1-arg1)*arg3 */
1064 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
1065 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
1066 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
1067 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
1068 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
1069 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
1070 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
1071 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
1074 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
1075 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
1079 FIXME("Unhandled WINED3DTOP: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
1080 stage, is_alpha, debug_d3dtop(op), op, arg1, arg2, arg3, texture_idx);
1083 checkGLcall("set_tex_op_nvrc()\n");
1088 static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* operand) {
1089 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the
1090 * input should be used for all input components. The WINED3DTA_COMPLEMENT
1091 * flag specifies the complement of the input should be used. */
1092 BOOL from_alpha = is_alpha || arg & WINED3DTA_ALPHAREPLICATE;
1093 BOOL complement = arg & WINED3DTA_COMPLEMENT;
1095 /* Calculate the operand */
1097 if (from_alpha) *operand = GL_ONE_MINUS_SRC_ALPHA;
1098 else *operand = GL_ONE_MINUS_SRC_COLOR;
1100 if (from_alpha) *operand = GL_SRC_ALPHA;
1101 else *operand = GL_SRC_COLOR;
1104 /* Calculate the source */
1105 switch (arg & WINED3DTA_SELECTMASK) {
1106 case WINED3DTA_CURRENT: *source = GL_PREVIOUS_EXT; break;
1107 case WINED3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT; break;
1108 case WINED3DTA_TEXTURE: *source = GL_TEXTURE; break;
1109 case WINED3DTA_TFACTOR: *source = GL_CONSTANT_EXT; break;
1110 case WINED3DTA_SPECULAR:
1112 * According to the GL_ARB_texture_env_combine specs, SPECULAR is
1113 * 'Secondary color' and isn't supported until base GL supports it
1114 * There is no concept of temp registers as far as I can tell
1116 FIXME("Unhandled texture arg WINED3DTA_SPECULAR\n");
1117 *source = GL_TEXTURE;
1120 FIXME("Unrecognized texture arg %#x\n", arg);
1121 *source = GL_TEXTURE;
1126 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
1127 #if defined (GL_VERSION_1_3)
1128 # define useext(A) A
1129 # define combine_ext 1
1130 #elif defined (GL_EXT_texture_env_combine)
1131 # define useext(A) A##_EXT
1132 # define combine_ext 1
1133 #elif defined (GL_ARB_texture_env_combine)
1134 # define useext(A) A##_ARB
1135 # define combine_ext 1
1140 #if !defined(combine_ext)
1141 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
1143 FIXME("Requires opengl combine extensions to work\n");
1147 /* Setup the texture operations texture stage states */
1148 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
1150 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
1151 GLenum src1, src2, src3;
1152 GLenum opr1, opr2, opr3;
1154 GLenum src0_target, src1_target, src2_target;
1155 GLenum opr0_target, opr1_target, opr2_target;
1157 GLenum opr=0, invopr, src3_target, opr3_target;
1158 BOOL Handled = FALSE;
1159 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
1161 TRACE("Alpha?(%d), Stage:%d Op(%s), a1(%d), a2(%d), a3(%d)\n", isAlpha, Stage, debug_d3dtop(op), arg1, arg2, arg3);
1165 /* Note: Operations usually involve two ars, src0 and src1 and are operations of
1166 the form (a1 <operation> a2). However, some of the more complex operations
1167 take 3 parameters. Instead of the (sensible) addition of a3, Microsoft added
1168 in a third parameter called a0. Therefore these are operations of the form
1169 a0 <operation> a1 <operation> a2, ie the new parameter goes to the front.
1171 However, below we treat the new (a0) parameter as src2/opr2, so in the actual
1172 functions below, expect their syntax to differ slightly to those listed in the
1173 manuals, ie replace arg1 with arg3, arg2 with arg1 and arg3 with arg2
1174 This affects WINED3DTOP_MULTIPLYADD and WINED3DTOP_LERP */
1177 comb_target = useext(GL_COMBINE_ALPHA);
1178 src0_target = useext(GL_SOURCE0_ALPHA);
1179 src1_target = useext(GL_SOURCE1_ALPHA);
1180 src2_target = useext(GL_SOURCE2_ALPHA);
1181 opr0_target = useext(GL_OPERAND0_ALPHA);
1182 opr1_target = useext(GL_OPERAND1_ALPHA);
1183 opr2_target = useext(GL_OPERAND2_ALPHA);
1184 scal_target = GL_ALPHA_SCALE;
1187 comb_target = useext(GL_COMBINE_RGB);
1188 src0_target = useext(GL_SOURCE0_RGB);
1189 src1_target = useext(GL_SOURCE1_RGB);
1190 src2_target = useext(GL_SOURCE2_RGB);
1191 opr0_target = useext(GL_OPERAND0_RGB);
1192 opr1_target = useext(GL_OPERAND1_RGB);
1193 opr2_target = useext(GL_OPERAND2_RGB);
1194 scal_target = useext(GL_RGB_SCALE);
1197 /* If a texture stage references an invalid texture unit the stage just
1198 * passes through the result from the previous stage */
1199 if (is_invalid_op(This, Stage, op, arg1, arg2, arg3)) {
1200 arg1 = WINED3DTA_CURRENT;
1201 op = WINED3DTOP_SELECTARG1;
1204 /* From MSDN (WINED3DTSS_ALPHAARG1) :
1205 The default argument is WINED3DTA_TEXTURE. If no texture is set for this stage,
1206 then the default argument is WINED3DTA_DIFFUSE.
1207 FIXME? If texture added/removed, may need to reset back as well? */
1208 if (isAlpha && This->stateBlock->textures[Stage] == NULL && arg1 == WINED3DTA_TEXTURE) {
1209 get_src_and_opr(WINED3DTA_DIFFUSE, isAlpha, &src1, &opr1);
1211 get_src_and_opr(arg1, isAlpha, &src1, &opr1);
1213 get_src_and_opr(arg2, isAlpha, &src2, &opr2);
1214 get_src_and_opr(arg3, isAlpha, &src3, &opr3);
1216 TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);
1218 Handled = TRUE; /* Assume will be handled */
1220 /* Other texture operations require special extensions: */
1221 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1224 invopr = GL_ONE_MINUS_SRC_ALPHA;
1225 src3_target = GL_SOURCE3_ALPHA_NV;
1226 opr3_target = GL_OPERAND3_ALPHA_NV;
1229 invopr = GL_ONE_MINUS_SRC_COLOR;
1230 src3_target = GL_SOURCE3_RGB_NV;
1231 opr3_target = GL_OPERAND3_RGB_NV;
1234 case WINED3DTOP_DISABLE: /* Only for alpha */
1235 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1236 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1237 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
1238 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1239 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
1240 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1241 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1242 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1243 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1244 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1245 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
1246 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
1247 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1248 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1249 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1250 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1251 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1252 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1254 case WINED3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */
1255 case WINED3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */
1256 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1257 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1258 if (op == WINED3DTOP_SELECTARG1) {
1259 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1260 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1261 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1262 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1264 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
1265 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1266 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1267 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1269 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1270 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1271 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1272 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1273 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
1274 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
1275 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1276 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1277 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1278 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1279 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1280 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1283 case WINED3DTOP_MODULATE:
1284 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1285 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
1286 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1287 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1288 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1289 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1290 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1291 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1292 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1293 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1294 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
1295 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1296 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1297 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1298 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1299 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1300 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1301 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
1302 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1303 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1305 case WINED3DTOP_MODULATE2X:
1306 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1307 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
1308 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1309 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1310 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1311 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1312 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1313 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1314 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1315 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1316 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
1317 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1318 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1319 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1320 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1321 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1322 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1323 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
1324 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1325 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1327 case WINED3DTOP_MODULATE4X:
1328 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1329 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
1330 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1331 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1332 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1333 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1334 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1335 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1336 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1337 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1338 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
1339 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1340 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1341 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1342 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1343 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1344 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1345 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
1346 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1347 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1350 case WINED3DTOP_ADD:
1351 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1352 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1353 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1354 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1355 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1356 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1357 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1358 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1359 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1360 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1361 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1362 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1363 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1364 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1365 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1366 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1367 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1368 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1369 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1370 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1373 case WINED3DTOP_ADDSIGNED:
1374 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1375 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1376 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1377 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1378 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1379 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1380 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1381 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1382 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1383 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1384 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1385 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1386 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1387 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1388 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1389 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1390 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1391 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1392 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1393 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1396 case WINED3DTOP_ADDSIGNED2X:
1397 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1398 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1399 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1400 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1401 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1402 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1403 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1404 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1405 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1406 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1407 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1408 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1409 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1410 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1411 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1412 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1413 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1414 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1415 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1416 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1419 case WINED3DTOP_ADDSMOOTH:
1420 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1421 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1422 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1423 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1424 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1425 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1426 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1427 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1428 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1429 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1430 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1431 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1432 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1433 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1434 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1435 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1437 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1438 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1439 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1440 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1442 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1443 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1444 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1445 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1448 case WINED3DTOP_BLENDDIFFUSEALPHA:
1449 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1450 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1451 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1452 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1453 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1454 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1455 glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR));
1456 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)");
1457 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1458 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1459 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1460 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1461 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1462 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1463 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR));
1464 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)");
1465 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1466 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1467 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1468 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1470 case WINED3DTOP_BLENDTEXTUREALPHA:
1471 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1472 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1473 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1474 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1475 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1476 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1477 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
1478 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
1479 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1480 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1481 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1482 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1483 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1484 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1485 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1486 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1487 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1488 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1489 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1490 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1492 case WINED3DTOP_BLENDFACTORALPHA:
1493 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1494 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
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, useext(GL_CONSTANT));
1500 checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)");
1501 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1502 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1503 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1504 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1505 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1506 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1507 glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT));
1508 checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)");
1509 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1510 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1511 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1512 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1514 case WINED3DTOP_BLENDTEXTUREALPHAPM:
1515 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1516 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1517 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1518 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1519 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1520 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1521 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1522 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1523 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1524 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1525 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1526 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1527 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1528 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1529 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
1530 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
1531 glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
1532 checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
1533 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1534 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1536 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
1537 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1538 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
1539 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */
1540 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1541 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1542 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); /* a1 = 1 (see docs) */
1543 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1544 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1545 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1546 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1547 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); /* a2 = arg2 */
1548 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1549 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1550 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); /* a3 = src1 alpha */
1551 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1552 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1554 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1555 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1557 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1558 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1559 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1560 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1562 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
1563 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1564 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1565 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1566 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1567 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1568 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1569 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1570 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1571 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1572 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1573 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1574 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1576 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1577 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1579 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1580 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1581 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1582 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1583 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1584 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1585 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1586 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1588 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
1589 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1590 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1591 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1592 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1593 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1594 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1595 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1596 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1597 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1598 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1599 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1600 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1601 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1602 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1603 glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
1604 checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
1606 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1607 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1608 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1609 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1611 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
1612 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
1613 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1614 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1616 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
1617 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1618 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1619 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1620 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1622 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1623 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1624 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1625 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1627 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1628 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1629 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1630 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1631 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1632 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1633 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1634 checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
1636 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1637 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1639 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
1640 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
1641 glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
1642 checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
1643 glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
1644 checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
1645 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1646 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1648 case WINED3DTOP_MULTIPLYADD:
1649 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1650 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1651 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
1652 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1653 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
1654 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1655 glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
1656 checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
1657 glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
1658 checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
1659 glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
1660 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1661 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
1662 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1663 glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
1664 checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
1665 glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
1666 checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
1667 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1668 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1671 case WINED3DTOP_BUMPENVMAP:
1675 case WINED3DTOP_BUMPENVMAPLUMINANCE:
1681 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
1682 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");
1687 } /* GL_NV_texture_env_combine4 */
1689 Handled = TRUE; /* Again, assume handled */
1691 case WINED3DTOP_DISABLE: /* Only for alpha */
1692 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1693 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1694 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
1695 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
1696 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
1697 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
1698 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1699 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1701 case WINED3DTOP_SELECTARG1:
1702 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1703 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1704 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1705 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1706 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1707 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1708 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1709 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1711 case WINED3DTOP_SELECTARG2:
1712 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
1713 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
1714 glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
1715 checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
1716 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
1717 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
1718 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1719 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1721 case WINED3DTOP_MODULATE:
1722 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1723 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1724 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1725 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1726 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1727 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1728 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1729 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1730 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1731 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1732 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1733 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1735 case WINED3DTOP_MODULATE2X:
1736 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1737 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1738 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1739 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1740 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1741 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1742 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1743 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1744 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1745 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1746 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1747 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1749 case WINED3DTOP_MODULATE4X:
1750 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
1751 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
1752 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1753 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1754 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1755 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1756 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1757 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1758 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1759 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1760 glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
1761 checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
1763 case WINED3DTOP_ADD:
1764 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
1765 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
1766 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1767 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1768 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1769 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1770 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1771 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1772 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1773 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1774 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1775 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1777 case WINED3DTOP_ADDSIGNED:
1778 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1779 checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)");
1780 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1781 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1782 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1783 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1784 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1785 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1786 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1787 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1788 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1789 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1791 case WINED3DTOP_ADDSIGNED2X:
1792 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED));
1793 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)");
1794 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1795 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1796 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1797 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1798 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1799 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1800 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1801 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1802 glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
1803 checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
1805 case WINED3DTOP_SUBTRACT:
1806 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
1807 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
1808 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
1809 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1810 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1811 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1812 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1813 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1814 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1815 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1816 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1817 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1818 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1820 FIXME("This version of opengl does not support GL_SUBTRACT\n");
1824 case WINED3DTOP_BLENDDIFFUSEALPHA:
1825 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1826 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1827 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1828 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1829 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1830 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1831 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1832 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1833 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1834 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1835 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR));
1836 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
1837 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1838 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1839 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1840 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1842 case WINED3DTOP_BLENDTEXTUREALPHA:
1843 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1844 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1845 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1846 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1847 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1848 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1849 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1850 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1851 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1852 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1853 glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
1854 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
1855 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1856 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1857 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1858 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1860 case WINED3DTOP_BLENDFACTORALPHA:
1861 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1862 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1863 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1864 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1865 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1866 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1867 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1868 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1869 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1870 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1871 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT));
1872 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
1873 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1874 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1875 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1876 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1878 case WINED3DTOP_BLENDCURRENTALPHA:
1879 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1880 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1881 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1882 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1883 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1884 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1885 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1886 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1887 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1888 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1889 glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS));
1890 checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
1891 glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
1892 checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
1893 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1894 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1896 case WINED3DTOP_DOTPRODUCT3:
1897 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
1898 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
1899 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
1900 } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
1901 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
1902 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
1904 FIXME("This version of opengl does not support GL_DOT3\n");
1906 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1907 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1908 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1909 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1910 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1911 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1912 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1913 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1914 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1915 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1917 case WINED3DTOP_LERP:
1918 glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE));
1919 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)");
1920 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1921 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1922 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
1923 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
1924 glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
1925 checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
1926 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
1927 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
1928 glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
1929 checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
1930 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
1931 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
1932 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1933 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1935 case WINED3DTOP_ADDSMOOTH:
1936 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1937 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1938 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1939 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1940 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1942 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
1943 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
1944 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1945 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1947 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1948 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1949 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1950 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1951 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1952 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1953 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1954 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1955 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1956 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1957 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1958 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1962 case WINED3DTOP_BLENDTEXTUREALPHAPM:
1963 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1964 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1965 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1966 glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
1967 checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
1968 glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
1969 checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
1970 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1971 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1972 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
1973 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
1974 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
1975 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
1976 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
1977 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
1978 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
1979 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
1983 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
1984 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
1985 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
1986 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
1987 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
1988 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
1990 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
1991 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1992 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
1993 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
1995 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
1996 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
1997 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
1998 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
1999 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2000 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2001 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2002 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2003 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2004 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2005 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2006 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2010 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
2011 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
2012 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2013 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2014 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2015 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2016 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2017 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2018 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2019 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2021 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2022 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2023 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2024 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2026 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2027 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2028 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2029 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2030 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2031 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2032 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2033 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2037 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
2038 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
2039 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2040 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2041 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2042 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2044 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2045 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2046 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2047 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2049 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2050 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2051 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2052 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2053 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2054 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2055 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2056 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2057 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2058 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2059 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2060 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2064 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
2065 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
2066 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2067 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2068 glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2069 checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2071 case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
2072 case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
2073 case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2074 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2076 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2077 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2078 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2079 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2081 case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
2082 case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2083 case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
2084 case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
2086 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2087 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2088 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2089 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2090 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2091 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2092 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2093 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2097 case WINED3DTOP_MULTIPLYADD:
2098 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
2099 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2100 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2101 glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
2102 checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
2103 glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
2104 checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
2105 glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2106 checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2107 glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2108 checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2109 glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2110 checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2111 glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2112 checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2113 glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2114 checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
2123 BOOL combineOK = TRUE;
2124 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
2128 op2 = This->stateBlock->textureState[Stage][WINED3DTSS_COLOROP];
2130 op2 = This->stateBlock->textureState[Stage][WINED3DTSS_ALPHAOP];
2133 /* Note: If COMBINE4 in effect can't go back to combine! */
2135 case WINED3DTOP_ADDSMOOTH:
2136 case WINED3DTOP_BLENDTEXTUREALPHAPM:
2137 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
2138 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
2139 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
2140 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
2141 case WINED3DTOP_MULTIPLYADD:
2142 /* Ignore those implemented in both cases */
2144 case WINED3DTOP_SELECTARG1:
2145 case WINED3DTOP_SELECTARG2:
2150 FIXME("Can't use COMBINE4 and COMBINE together, thisop=%s, otherop=%s, isAlpha(%d)\n", debug_d3dtop(op), debug_d3dtop(op2), isAlpha);
2158 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE));
2159 checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)");
2168 /* After all the extensions, if still unhandled, report fixme */
2169 FIXME("Unhandled texture operation %s\n", debug_d3dtop(op));
2170 #undef GLINFO_LOCATION
2174 /* Setup this textures matrix according to the texture flags*/
2175 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords)
2179 glMatrixMode(GL_TEXTURE);
2180 checkGLcall("glMatrixMode(GL_TEXTURE)");
2182 if (flags == WINED3DTTFF_DISABLE) {
2184 checkGLcall("glLoadIdentity()");
2188 if (flags == (WINED3DTTFF_COUNT1|WINED3DTTFF_PROJECTED)) {
2189 ERR("Invalid texture transform flags: WINED3DTTFF_COUNT1|WINED3DTTFF_PROJECTED\n");
2193 memcpy(mat, smat, 16 * sizeof(float));
2195 switch (flags & ~WINED3DTTFF_PROJECTED) {
2196 case WINED3DTTFF_COUNT1: mat[1] = mat[5] = mat[13] = 0;
2197 case WINED3DTTFF_COUNT2: mat[2] = mat[6] = mat[10] = mat[14] = 0;
2198 default: mat[3] = mat[7] = mat[11] = 0, mat[15] = 1;
2201 if (flags & WINED3DTTFF_PROJECTED) {
2202 switch (flags & ~WINED3DTTFF_PROJECTED) {
2203 case WINED3DTTFF_COUNT2:
2204 mat[3] = mat[1], mat[7] = mat[5], mat[11] = mat[9], mat[15] = mat[13];
2205 mat[1] = mat[5] = mat[9] = mat[13] = 0;
2207 case WINED3DTTFF_COUNT3:
2208 mat[3] = mat[2], mat[7] = mat[6], mat[11] = mat[10], mat[15] = mat[14];
2209 mat[2] = mat[6] = mat[10] = mat[14] = 0;
2212 } else if(!calculatedCoords) { /* under directx the R/Z coord can be used for translation, under opengl we use the Q coord instead */
2218 checkGLcall("glLoadMatrixf(mat)");
2221 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
2223 /* Convertes a D3D format into a OpenGL configuration format */
2224 int D3DFmtMakeGlCfg(WINED3DFORMAT BackBufferFormat, WINED3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate){
2225 #define PUSH1(att) attribs[(*nAttribs)++] = (att);
2226 #define PUSH2(att,value) attribs[(*nAttribs)++] = (att); attribs[(*nAttribs)++] = (value);
2227 /*We need to do some Card specific stuff in here at some point,
2228 D3D now supports floating point format buffers, and there are a number of different OpelGl ways of managing these e.g.
2229 GLX_ATI_pixel_format_float
2231 switch (BackBufferFormat) {
2234 PUSH2(GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT);
2235 PUSH2(GLX_BUFFER_SIZE, 8);
2236 PUSH2(GLX_DOUBLEBUFFER, TRUE);
2239 case WINED3DFMT_R3G3B2:
2240 PUSH2(GLX_RENDER_TYPE, GLX_RGBA_BIT);
2241 PUSH2(GLX_RED_SIZE, 3);
2242 PUSH2(GLX_GREEN_SIZE, 3);
2243 PUSH2(GLX_BLUE_SIZE, 2);
2246 case WINED3DFMT_A1R5G5B5:
2247 PUSH2(GLX_ALPHA_SIZE, 1);
2248 case WINED3DFMT_X1R5G5B5:
2249 PUSH2(GLX_RED_SIZE, 5);
2250 PUSH2(GLX_GREEN_SIZE, 5);
2251 PUSH2(GLX_BLUE_SIZE, 5);
2254 case WINED3DFMT_R5G6B5:
2255 PUSH2(GLX_RED_SIZE, 5);
2256 PUSH2(GLX_GREEN_SIZE, 6);
2257 PUSH2(GLX_BLUE_SIZE, 5);
2260 case WINED3DFMT_A4R4G4B4:
2261 PUSH2(GLX_ALPHA_SIZE, 4);
2262 case WINED3DFMT_X4R4G4B4:
2263 PUSH2(GLX_RED_SIZE, 4);
2264 PUSH2(GLX_GREEN_SIZE, 4);
2265 PUSH2(GLX_BLUE_SIZE, 4);
2268 case WINED3DFMT_A8R8G8B8:
2269 PUSH2(GLX_ALPHA_SIZE, 8);
2270 case WINED3DFMT_R8G8B8:
2271 case WINED3DFMT_X8R8G8B8:
2272 PUSH2(GLX_RED_SIZE, 8);
2273 PUSH2(GLX_GREEN_SIZE, 8);
2274 PUSH2(GLX_BLUE_SIZE, 8);
2277 case WINED3DFMT_A2R10G10B10:
2278 PUSH2(GLX_ALPHA_SIZE, 2);
2279 PUSH2(GLX_RED_SIZE, 10);
2280 PUSH2(GLX_GREEN_SIZE, 10);
2281 PUSH2(GLX_BLUE_SIZE, 10);
2284 case WINED3DFMT_A16B16G16R16:
2285 PUSH2(GLX_ALPHA_SIZE, 16);
2286 PUSH2(GLX_RED_SIZE, 16);
2287 PUSH2(GLX_GREEN_SIZE, 16);
2288 PUSH2(GLX_BLUE_SIZE, 16);
2292 FIXME("Unsupported color format: %s\n", debug_d3dformat(BackBufferFormat));
2296 switch (StencilBufferFormat) {
2300 case WINED3DFMT_D16_LOCKABLE:
2301 case WINED3DFMT_D16:
2302 PUSH2(GLX_DEPTH_SIZE, 16);
2305 case WINED3DFMT_D15S1:
2306 PUSH2(GLX_DEPTH_SIZE, 15);
2307 PUSH2(GLX_STENCIL_SIZE, 1);
2308 /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
2309 e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
2312 case WINED3DFMT_D24X8:
2313 PUSH2(GLX_DEPTH_SIZE, 24);
2316 case WINED3DFMT_D24X4S4:
2317 PUSH2(GLX_DEPTH_SIZE, 24);
2318 PUSH2(GLX_STENCIL_SIZE, 4);
2321 case WINED3DFMT_D24S8:
2322 PUSH2(GLX_DEPTH_SIZE, 24);
2323 PUSH2(GLX_STENCIL_SIZE, 8);
2326 case WINED3DFMT_D24FS8:
2327 PUSH2(GLX_DEPTH_SIZE, 24);
2328 PUSH2(GLX_STENCIL_SIZE, 8);
2331 case WINED3DFMT_D32:
2332 PUSH2(GLX_DEPTH_SIZE, 32);
2336 FIXME("Unsupported stencil format: %s\n", debug_d3dformat(StencilBufferFormat));
2340 } else { /* it the device doesn't support the 'exact' format, try to find something close */
2341 switch (StencilBufferFormat) {
2345 case WINED3DFMT_D16_LOCKABLE:
2346 case WINED3DFMT_D16:
2347 PUSH2(GLX_DEPTH_SIZE, 1);
2350 case WINED3DFMT_D15S1:
2351 PUSH2(GLX_DEPTH_SIZE, 1);
2352 PUSH2(GLX_STENCIL_SIZE, 1);
2353 /*Does openGl support a 1bit stencil?, I've seen it used elsewhere
2354 e.g. http://www.ks.uiuc.edu/Research/vmd/doxygen/OpenGLDisplayDevice_8C-source.html*/
2357 case WINED3DFMT_D24X8:
2358 PUSH2(GLX_DEPTH_SIZE, 1);
2361 case WINED3DFMT_D24X4S4:
2362 PUSH2(GLX_DEPTH_SIZE, 1);
2363 PUSH2(GLX_STENCIL_SIZE, 1);
2366 case WINED3DFMT_D24S8:
2367 PUSH2(GLX_DEPTH_SIZE, 1);
2368 PUSH2(GLX_STENCIL_SIZE, 1);
2371 case WINED3DFMT_D24FS8:
2372 PUSH2(GLX_DEPTH_SIZE, 1);
2373 PUSH2(GLX_STENCIL_SIZE, 1);
2376 case WINED3DFMT_D32:
2377 PUSH2(GLX_DEPTH_SIZE, 1);
2381 FIXME("Unsupported stencil format: %s\n", debug_d3dformat(StencilBufferFormat));
2389 #undef GLINFO_LOCATION
2391 /* DirectDraw stuff */
2392 WINED3DFORMAT pixelformat_for_depth(DWORD depth) {
2394 case 8: return WINED3DFMT_P8; break;
2395 case 15: return WINED3DFMT_X1R5G5B5; break;
2396 case 16: return WINED3DFMT_R5G6B5; break;
2397 case 24: return WINED3DFMT_R8G8B8; break;
2398 case 32: return WINED3DFMT_X8R8G8B8; break;
2399 default: return WINED3DFMT_UNKNOWN;
2403 void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2) {
2406 /* Now do the multiplication 'by hand'.
2407 I know that all this could be optimised, but this will be done later :-) */
2408 temp.u.s._11 = (src1->u.s._11 * src2->u.s._11) + (src1->u.s._21 * src2->u.s._12) + (src1->u.s._31 * src2->u.s._13) + (src1->u.s._41 * src2->u.s._14);
2409 temp.u.s._21 = (src1->u.s._11 * src2->u.s._21) + (src1->u.s._21 * src2->u.s._22) + (src1->u.s._31 * src2->u.s._23) + (src1->u.s._41 * src2->u.s._24);
2410 temp.u.s._31 = (src1->u.s._11 * src2->u.s._31) + (src1->u.s._21 * src2->u.s._32) + (src1->u.s._31 * src2->u.s._33) + (src1->u.s._41 * src2->u.s._34);
2411 temp.u.s._41 = (src1->u.s._11 * src2->u.s._41) + (src1->u.s._21 * src2->u.s._42) + (src1->u.s._31 * src2->u.s._43) + (src1->u.s._41 * src2->u.s._44);
2413 temp.u.s._12 = (src1->u.s._12 * src2->u.s._11) + (src1->u.s._22 * src2->u.s._12) + (src1->u.s._32 * src2->u.s._13) + (src1->u.s._42 * src2->u.s._14);
2414 temp.u.s._22 = (src1->u.s._12 * src2->u.s._21) + (src1->u.s._22 * src2->u.s._22) + (src1->u.s._32 * src2->u.s._23) + (src1->u.s._42 * src2->u.s._24);
2415 temp.u.s._32 = (src1->u.s._12 * src2->u.s._31) + (src1->u.s._22 * src2->u.s._32) + (src1->u.s._32 * src2->u.s._33) + (src1->u.s._42 * src2->u.s._34);
2416 temp.u.s._42 = (src1->u.s._12 * src2->u.s._41) + (src1->u.s._22 * src2->u.s._42) + (src1->u.s._32 * src2->u.s._43) + (src1->u.s._42 * src2->u.s._44);
2418 temp.u.s._13 = (src1->u.s._13 * src2->u.s._11) + (src1->u.s._23 * src2->u.s._12) + (src1->u.s._33 * src2->u.s._13) + (src1->u.s._43 * src2->u.s._14);
2419 temp.u.s._23 = (src1->u.s._13 * src2->u.s._21) + (src1->u.s._23 * src2->u.s._22) + (src1->u.s._33 * src2->u.s._23) + (src1->u.s._43 * src2->u.s._24);
2420 temp.u.s._33 = (src1->u.s._13 * src2->u.s._31) + (src1->u.s._23 * src2->u.s._32) + (src1->u.s._33 * src2->u.s._33) + (src1->u.s._43 * src2->u.s._34);
2421 temp.u.s._43 = (src1->u.s._13 * src2->u.s._41) + (src1->u.s._23 * src2->u.s._42) + (src1->u.s._33 * src2->u.s._43) + (src1->u.s._43 * src2->u.s._44);
2423 temp.u.s._14 = (src1->u.s._14 * src2->u.s._11) + (src1->u.s._24 * src2->u.s._12) + (src1->u.s._34 * src2->u.s._13) + (src1->u.s._44 * src2->u.s._14);
2424 temp.u.s._24 = (src1->u.s._14 * src2->u.s._21) + (src1->u.s._24 * src2->u.s._22) + (src1->u.s._34 * src2->u.s._23) + (src1->u.s._44 * src2->u.s._24);
2425 temp.u.s._34 = (src1->u.s._14 * src2->u.s._31) + (src1->u.s._24 * src2->u.s._32) + (src1->u.s._34 * src2->u.s._33) + (src1->u.s._44 * src2->u.s._34);
2426 temp.u.s._44 = (src1->u.s._14 * src2->u.s._41) + (src1->u.s._24 * src2->u.s._42) + (src1->u.s._34 * src2->u.s._43) + (src1->u.s._44 * src2->u.s._44);
2428 /* And copy the new matrix in the good storage.. */
2429 memcpy(dest, &temp, 16 * sizeof(float));
2432 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) {
2435 int numTextures = (d3dvtVertexType & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
2437 if (d3dvtVertexType & WINED3DFVF_NORMAL) size += 3 * sizeof(float);
2438 if (d3dvtVertexType & WINED3DFVF_DIFFUSE) size += sizeof(DWORD);
2439 if (d3dvtVertexType & WINED3DFVF_SPECULAR) size += sizeof(DWORD);
2440 if (d3dvtVertexType & WINED3DFVF_PSIZE) size += sizeof(DWORD);
2441 switch (d3dvtVertexType & WINED3DFVF_POSITION_MASK) {
2442 case WINED3DFVF_XYZ: size += 3 * sizeof(float); break;
2443 case WINED3DFVF_XYZRHW: size += 4 * sizeof(float); break;
2444 default: TRACE(" matrix weighting not handled yet...\n");
2446 for (i = 0; i < numTextures; i++) {
2447 size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(float);
2453 /***********************************************************************
2456 * Calculates the dimensions of the opengl texture used for blits.
2457 * Handled oversized opengl textures and updates the source rectangle
2461 * This: Surface to operate on
2462 * Rect: Requested rectangle
2465 * TRUE if the texture part can be loaded,
2468 *********************************************************************/
2469 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->resource.wineD3DDevice->wineD3D))->gl_info
2471 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]) {
2472 int x1 = Rect->left, x2 = Rect->right;
2473 int y1 = Rect->top, y2 = Rect->bottom;
2474 GLint maxSize = GL_LIMITS(texture_size);
2476 TRACE("(%p)->(%d,%d)-(%d,%d)\n", This,
2477 Rect->left, Rect->top, Rect->right, Rect->bottom);
2479 /* The sizes might be reversed */
2480 if(Rect->left > Rect->right) {
2484 if(Rect->top > Rect->bottom) {
2489 /* No oversized texture? This is easy */
2490 if(!(This->Flags & SFLAG_OVERSIZE)) {
2491 /* Which rect from the texture do I need? */
2492 glTexCoord[0] = (float) Rect->left / (float) This->pow2Width;
2493 glTexCoord[2] = (float) Rect->top / (float) This->pow2Height;
2494 glTexCoord[1] = (float) Rect->right / (float) This->pow2Width;
2495 glTexCoord[3] = (float) Rect->bottom / (float) This->pow2Height;
2499 /* Check if we can succeed at all */
2500 if( (x2 - x1) > maxSize ||
2501 (y2 - y1) > maxSize ) {
2502 TRACE("Requested rectangle is too large for gl\n");
2506 /* A part of the texture has to be picked. First, check if
2507 * some texture part is loaded already, if yes try to re-use it.
2508 * If the texture is dirty, or the part can't be used,
2509 * re-position the part to load
2511 if(!(This->Flags & SFLAG_DIRTY)) {
2512 if(This->glRect.left <= x1 && This->glRect.right >= x2 &&
2513 This->glRect.top <= y1 && This->glRect.bottom >= x2 ) {
2514 /* Ok, the rectangle is ok, re-use it */
2515 TRACE("Using existing gl Texture\n");
2517 /* Rectangle is not ok, dirtify the texture to reload it */
2518 TRACE("Dirtifying texture to force reload\n");
2519 This->Flags |= SFLAG_DIRTY;
2523 /* Now if we are dirty(no else if!) */
2524 if(This->Flags & SFLAG_DIRTY) {
2525 /* Set the new rectangle. Use the following strategy:
2526 * 1) Use as big textures as possible.
2527 * 2) Place the texture part in the way that the requested
2528 * part is in the middle of the texture(well, almost)
2529 * 3) If the texture is moved over the edges of the
2530 * surface, replace it nicely
2531 * 4) If the coord is not limiting the texture size,
2532 * use the whole size
2534 if((This->pow2Width) > maxSize) {
2535 This->glRect.left = x1 - maxSize / 2;
2536 if(This->glRect.left < 0) {
2537 This->glRect.left = 0;
2539 This->glRect.right = This->glRect.left + maxSize;
2540 if(This->glRect.right > This->currentDesc.Width) {
2541 This->glRect.right = This->currentDesc.Width;
2542 This->glRect.left = This->glRect.right - maxSize;
2545 This->glRect.left = 0;
2546 This->glRect.right = This->pow2Width;
2549 if(This->pow2Height > maxSize) {
2550 This->glRect.top = x1 - GL_LIMITS(texture_size) / 2;
2551 if(This->glRect.top < 0) This->glRect.top = 0;
2552 This->glRect.bottom = This->glRect.left + maxSize;
2553 if(This->glRect.bottom > This->currentDesc.Height) {
2554 This->glRect.bottom = This->currentDesc.Height;
2555 This->glRect.top = This->glRect.bottom - maxSize;
2558 This->glRect.top = 0;
2559 This->glRect.bottom = This->pow2Height;
2561 TRACE("(%p): Using rect (%d,%d)-(%d,%d)\n", This,
2562 This->glRect.left, This->glRect.top, This->glRect.right, This->glRect.bottom);
2565 /* Re-calculate the rect to draw */
2566 Rect->left -= This->glRect.left;
2567 Rect->right -= This->glRect.left;
2568 Rect->top -= This->glRect.top;
2569 Rect->bottom -= This->glRect.top;
2571 /* Get the gl coordinates. The gl rectangle is a power of 2, eigher the max size,
2572 * or the pow2Width / pow2Height of the surface
2574 glTexCoord[0] = (float) Rect->left / (float) (This->glRect.right - This->glRect.left);
2575 glTexCoord[2] = (float) Rect->top / (float) (This->glRect.bottom - This->glRect.top);
2576 glTexCoord[1] = (float) Rect->right / (float) (This->glRect.right - This->glRect.left);
2577 glTexCoord[3] = (float) Rect->bottom / (float) (This->glRect.bottom - This->glRect.top);
2581 #undef GLINFO_LOCATION