ntdll/tests: Fix a couple of tests failing on NT4.
[wine.git] / dlls / wined3d / utils.c
blob57e2b37778a40a9a4b05dc9207fa6e177c39f1d1
1 /*
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-2008 Henri Verbeet
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "config.h"
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
31 /*****************************************************************************
32 * Pixel format array
34 * For the formats WINED3DFMT_A32B32G32R32F, WINED3DFMT_A16B16G16R16F,
35 * and WINED3DFMT_A16B16G16R16 do not have correct alpha masks, because the
36 * high masks do not fit into the 32 bit values needed for ddraw. It is only
37 * used for ddraw mostly, and to figure out if the format has alpha at all, so
38 * setting a mask like 0x1 for those surfaces is correct. The 64 and 128 bit
39 * formats are not usable in 2D rendering because ddraw doesn't support them.
41 static const StaticPixelFormatDesc formats[] = {
42 /*{WINED3DFORMAT ,alphamask ,redmask ,greenmask ,bluemask ,bpp ,depth ,stencil, isFourcc*/
43 {WINED3DFMT_UNKNOWN ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,FALSE },
44 /* FourCC formats, kept here to have WINED3DFMT_R8G8B8(=20) at position 20 */
45 {WINED3DFMT_UYVY ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,TRUE },
46 {WINED3DFMT_YUY2 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,TRUE },
47 {WINED3DFMT_YV12 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,TRUE },
48 {WINED3DFMT_DXT1 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,TRUE },
49 {WINED3DFMT_DXT2 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,TRUE },
50 {WINED3DFMT_DXT3 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,TRUE },
51 {WINED3DFMT_DXT4 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,TRUE },
52 {WINED3DFMT_DXT5 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,TRUE },
53 {WINED3DFMT_MULTI2_ARGB8,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,0 ,0 ,TRUE },
54 {WINED3DFMT_G8R8_G8B8 ,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,0 ,0 ,TRUE },
55 {WINED3DFMT_R8G8_B8G8 ,0x0 ,0x0 ,0x0 ,0x0 ,1/*?*/ ,0 ,0 ,TRUE },
56 /* IEEE formats */
57 {WINED3DFMT_R32F ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
58 {WINED3DFMT_G32R32F ,0x0 ,0x0 ,0x0 ,0x0 ,8 ,0 ,0 ,FALSE },
59 {WINED3DFMT_A32B32G32R32F,0x1 ,0x0 ,0x0 ,0x0 ,16 ,0 ,0 ,FALSE },
60 /* Hmm? */
61 {WINED3DFMT_CxV8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,FALSE },
62 /* Float */
63 {WINED3DFMT_R16F ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,FALSE },
64 {WINED3DFMT_G16R16F ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
65 {WINED3DFMT_A16B16G16R16F,0x1 ,0x0 ,0x0 ,0x0 ,8 ,0 ,0 ,FALSE },
66 /* Palettized formats */
67 {WINED3DFMT_A8P8 ,0x0000ff00 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,FALSE },
68 {WINED3DFMT_P8 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,FALSE },
69 /* Standard ARGB formats. Keep WINED3DFMT_R8G8B8(=20) at position 20 */
70 {WINED3DFMT_R8G8B8 ,0x0 ,0x00ff0000 ,0x0000ff00 ,0x000000ff ,3 ,0 ,0 ,FALSE },
71 {WINED3DFMT_A8R8G8B8 ,0xff000000 ,0x00ff0000 ,0x0000ff00 ,0x000000ff ,4 ,0 ,0 ,FALSE },
72 {WINED3DFMT_X8R8G8B8 ,0x0 ,0x00ff0000 ,0x0000ff00 ,0x000000ff ,4 ,0 ,0 ,FALSE },
73 {WINED3DFMT_R5G6B5 ,0x0 ,0x0000F800 ,0x000007e0 ,0x0000001f ,2 ,0 ,0 ,FALSE },
74 {WINED3DFMT_X1R5G5B5 ,0x0 ,0x00007c00 ,0x000003e0 ,0x0000001f ,2 ,0 ,0 ,FALSE },
75 {WINED3DFMT_A1R5G5B5 ,0x00008000 ,0x00007c00 ,0x000003e0 ,0x0000001f ,2 ,0 ,0 ,FALSE },
76 {WINED3DFMT_A4R4G4B4 ,0x0000f000 ,0x00000f00 ,0x000000f0 ,0x0000000f ,2 ,0 ,0 ,FALSE },
77 {WINED3DFMT_R3G3B2 ,0x0 ,0x000000e0 ,0x0000001c ,0x00000003 ,1 ,0 ,0 ,FALSE },
78 {WINED3DFMT_A8 ,0x000000ff ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,FALSE },
79 {WINED3DFMT_A8R3G3B2 ,0x0000ff00 ,0x000000e0 ,0x0000001c ,0x00000003 ,2 ,0 ,0 ,FALSE },
80 {WINED3DFMT_X4R4G4B4 ,0x0 ,0x00000f00 ,0x000000f0 ,0x0000000f ,2 ,0 ,0 ,FALSE },
81 {WINED3DFMT_A2B10G10R10 ,0xb0000000 ,0x000003ff ,0x000ffc00 ,0x3ff00000 ,4 ,0 ,0 ,FALSE },
82 {WINED3DFMT_A8B8G8R8 ,0xff000000 ,0x000000ff ,0x0000ff00 ,0x00ff0000 ,4 ,0 ,0 ,FALSE },
83 {WINED3DFMT_X8B8G8R8 ,0x0 ,0x000000ff ,0x0000ff00 ,0x00ff0000 ,4 ,0 ,0 ,FALSE },
84 {WINED3DFMT_G16R16 ,0x0 ,0x0000ffff ,0xffff0000 ,0x0 ,4 ,0 ,0 ,FALSE },
85 {WINED3DFMT_A2R10G10B10 ,0xb0000000 ,0x3ff00000 ,0x000ffc00 ,0x000003ff ,4 ,0 ,0 ,FALSE },
86 {WINED3DFMT_A16B16G16R16,0x1 ,0x0000ffff ,0xffff0000 ,0x0 ,8 ,0 ,0 ,FALSE },
87 /* Luminance */
88 {WINED3DFMT_L8 ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,FALSE },
89 {WINED3DFMT_A8L8 ,0x0000ff00 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,FALSE },
90 {WINED3DFMT_A4L4 ,0x000000f0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,FALSE },
91 /* Bump mapping stuff */
92 {WINED3DFMT_V8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,FALSE },
93 {WINED3DFMT_L6V5U5 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,FALSE },
94 {WINED3DFMT_X8L8V8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
95 {WINED3DFMT_Q8W8V8U8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
96 {WINED3DFMT_V16U16 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
97 {WINED3DFMT_W11V11U10 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
98 {WINED3DFMT_A2W10V10U10 ,0xb0000000 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
99 /* Depth stencil formats */
100 {WINED3DFMT_D16_LOCKABLE,0x0 ,0x0 ,0x0 ,0x0 ,2 ,16 ,0 ,FALSE },
101 {WINED3DFMT_D32 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,32 ,0 ,FALSE },
102 {WINED3DFMT_D15S1 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,15 ,1 ,FALSE },
103 {WINED3DFMT_D24S8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,24 ,8 ,FALSE },
104 {WINED3DFMT_D24X8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,24 ,0 ,FALSE },
105 {WINED3DFMT_D24X4S4 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,24 ,4 ,FALSE },
106 {WINED3DFMT_D16 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,16 ,0 ,FALSE },
107 {WINED3DFMT_L16 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,16 ,0 ,FALSE },
108 {WINED3DFMT_D32F_LOCKABLE,0x0 ,0x0 ,0x0 ,0x0 ,4 ,32 ,0 ,FALSE },
109 {WINED3DFMT_D24FS8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,24 ,8 ,FALSE },
110 /* Is this a vertex buffer? */
111 {WINED3DFMT_VERTEXDATA ,0x0 ,0x0 ,0x0 ,0x0 ,0 ,0 ,0 ,FALSE },
112 {WINED3DFMT_INDEX16 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,FALSE },
113 {WINED3DFMT_INDEX32 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,0 ,0 ,FALSE },
114 {WINED3DFMT_Q16W16V16U16,0x0 ,0x0 ,0x0 ,0x0 ,8 ,0 ,0 ,FALSE },
115 /* Vendor-specific formats */
116 {WINED3DFMT_ATI2N ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,0 ,0 ,TRUE },
117 {WINED3DFMT_NVHU ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,TRUE },
118 {WINED3DFMT_NVHS ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,0 ,0 ,TRUE },
121 typedef struct {
122 WINED3DFORMAT fmt;
123 GLint glInternal, glGammaInternal, rtInternal, glFormat, glType;
124 unsigned int Flags;
125 } GlPixelFormatDescTemplate;
127 /*****************************************************************************
128 * OpenGL format template. Contains unexciting formats which do not need
129 * extension checks. The order in this table is independent of the order in
130 * the table StaticPixelFormatDesc above. Not all formats have to be in this
131 * table.
133 static const GlPixelFormatDescTemplate gl_formats_template[] = {
134 /*{ internal ,srgbInternal , rtInternal, format ,type \
135 ,Flags }*/
136 {WINED3DFMT_UNKNOWN ,0 ,0 , 0, 0 ,0
137 ,0 },
138 /* FourCC formats */
139 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
140 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
141 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
142 * Macs, so probably the endianess differs. This could be tested as soon as we have a Windows and MacOS on a big
143 * endian machine
145 {WINED3DFMT_UYVY ,GL_RGB ,GL_RGB , 0, GL_YCBCR_422_APPLE ,UNSIGNED_SHORT_8_8_APPLE
146 ,WINED3DFMT_FLAG_FILTERING },
147 {WINED3DFMT_YUY2 ,GL_RGB ,GL_RGB , 0, GL_YCBCR_422_APPLE ,UNSIGNED_SHORT_8_8_REV_APPLE
148 ,WINED3DFMT_FLAG_FILTERING },
149 {WINED3DFMT_YV12 ,GL_ALPHA ,GL_ALPHA , 0, GL_ALPHA ,GL_UNSIGNED_BYTE
150 ,WINED3DFMT_FLAG_FILTERING },
151 {WINED3DFMT_DXT1 ,GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ,GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT , 0, GL_RGBA ,GL_UNSIGNED_BYTE
152 ,WINED3DFMT_FLAG_FILTERING },
153 {WINED3DFMT_DXT2 ,GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ,GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT , 0, GL_RGBA ,GL_UNSIGNED_BYTE
154 ,WINED3DFMT_FLAG_FILTERING },
155 {WINED3DFMT_DXT3 ,GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ,GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT , 0, GL_RGBA ,GL_UNSIGNED_BYTE
156 ,WINED3DFMT_FLAG_FILTERING },
157 {WINED3DFMT_DXT4 ,GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ,GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT , 0, GL_RGBA ,GL_UNSIGNED_BYTE
158 ,WINED3DFMT_FLAG_FILTERING },
159 {WINED3DFMT_DXT5 ,GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ,GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT , 0, GL_RGBA ,GL_UNSIGNED_BYTE
160 ,WINED3DFMT_FLAG_FILTERING },
161 {WINED3DFMT_MULTI2_ARGB8 ,0 ,0 , 0, 0 ,0
162 ,0 },
163 {WINED3DFMT_G8R8_G8B8 ,0 ,0 , 0, 0 ,0
164 ,0 },
165 {WINED3DFMT_R8G8_B8G8 ,0 ,0 , 0, 0 ,0
166 ,0 },
167 /* IEEE formats */
168 {WINED3DFMT_R32F ,GL_RGB32F_ARB ,GL_RGB32F_ARB , 0, GL_RED ,GL_FLOAT
169 ,WINED3DFMT_FLAG_RENDERTARGET },
170 {WINED3DFMT_G32R32F ,0 ,0 , 0, 0 ,0
171 ,WINED3DFMT_FLAG_RENDERTARGET },
172 {WINED3DFMT_A32B32G32R32F ,GL_RGBA32F_ARB ,GL_RGBA32F_ARB , 0, GL_RGBA ,GL_FLOAT
173 ,WINED3DFMT_FLAG_RENDERTARGET },
174 /* Hmm? */
175 {WINED3DFMT_CxV8U8 ,0 ,0 , 0, 0 ,0
176 ,0 },
177 /* Float */
178 {WINED3DFMT_R16F ,GL_RGB16F_ARB ,GL_RGB16F_ARB , 0, GL_RED ,GL_HALF_FLOAT_ARB
179 ,WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
180 {WINED3DFMT_G16R16F ,0 ,0 , 0, 0 ,0
181 ,WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
182 {WINED3DFMT_A16B16G16R16F ,GL_RGBA16F_ARB ,GL_RGBA16F_ARB , 0, GL_RGBA ,GL_HALF_FLOAT_ARB
183 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
184 /* Palettized formats */
185 {WINED3DFMT_A8P8, 0 ,0 , 0, 0 ,0
186 ,0 },
187 {WINED3DFMT_P8, GL_COLOR_INDEX8_EXT ,GL_COLOR_INDEX8_EXT , 0, GL_COLOR_INDEX ,GL_UNSIGNED_BYTE
188 ,0 },
189 /* Standard ARGB formats */
190 {WINED3DFMT_R8G8B8 ,GL_RGB8 ,GL_RGB8 , 0, GL_BGR ,GL_UNSIGNED_BYTE
191 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
192 {WINED3DFMT_A8R8G8B8 ,GL_RGBA8 ,GL_SRGB8_ALPHA8_EXT , 0, GL_BGRA ,GL_UNSIGNED_INT_8_8_8_8_REV
193 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
194 {WINED3DFMT_X8R8G8B8 ,GL_RGB8 ,GL_SRGB8_EXT , 0, GL_BGRA ,GL_UNSIGNED_INT_8_8_8_8_REV
195 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
196 {WINED3DFMT_R5G6B5 ,GL_RGB5 ,GL_RGB5 , GL_RGB8, GL_RGB ,GL_UNSIGNED_SHORT_5_6_5
197 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
198 {WINED3DFMT_X1R5G5B5 ,GL_RGB5 ,GL_RGB5_A1 , 0, GL_BGRA ,GL_UNSIGNED_SHORT_1_5_5_5_REV
199 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING },
200 {WINED3DFMT_A1R5G5B5 ,GL_RGB5_A1 ,GL_RGB5_A1 , 0, GL_BGRA ,GL_UNSIGNED_SHORT_1_5_5_5_REV
201 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING },
202 {WINED3DFMT_A4R4G4B4 ,GL_RGBA4 ,GL_SRGB8_ALPHA8_EXT , 0, GL_BGRA ,GL_UNSIGNED_SHORT_4_4_4_4_REV
203 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING },
204 {WINED3DFMT_R3G3B2 ,GL_R3_G3_B2 ,GL_R3_G3_B2 , 0, GL_RGB ,GL_UNSIGNED_BYTE_3_3_2
205 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING },
206 {WINED3DFMT_A8 ,GL_ALPHA8 ,GL_ALPHA8 , 0, GL_ALPHA ,GL_UNSIGNED_BYTE
207 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING },
208 {WINED3DFMT_A8R3G3B2 ,0 ,0 , 0, 0 ,0
209 ,0 },
210 {WINED3DFMT_X4R4G4B4 ,GL_RGB4 ,GL_RGB4 , 0, GL_BGRA ,GL_UNSIGNED_SHORT_4_4_4_4_REV
211 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING},
212 {WINED3DFMT_A2B10G10R10 ,GL_RGB10_A2 ,GL_RGB10_A2 , 0, GL_RGBA ,GL_UNSIGNED_INT_2_10_10_10_REV
213 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING},
214 {WINED3DFMT_A8B8G8R8 ,GL_RGBA8 ,GL_RGBA8 , 0, GL_RGBA ,GL_UNSIGNED_INT_8_8_8_8_REV
215 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING},
216 {WINED3DFMT_X8B8G8R8 ,GL_RGB8 ,GL_RGB8 , 0, GL_RGBA ,GL_UNSIGNED_INT_8_8_8_8_REV
217 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING},
218 {WINED3DFMT_G16R16 ,GL_RGB16_EXT ,GL_RGB16_EXT , 0, GL_RGB ,GL_UNSIGNED_SHORT
219 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING },
220 {WINED3DFMT_A2R10G10B10 ,GL_RGB10_A2 ,GL_RGB10_A2 , 0, GL_BGRA ,GL_UNSIGNED_INT_2_10_10_10_REV
221 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING },
222 {WINED3DFMT_A16B16G16R16 ,GL_RGBA16_EXT ,GL_RGBA16_EXT , 0, GL_RGBA ,GL_UNSIGNED_SHORT
223 ,WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET },
224 /* Luminance */
225 {WINED3DFMT_L8 ,GL_LUMINANCE8 ,GL_SLUMINANCE8_EXT , 0, GL_LUMINANCE ,GL_UNSIGNED_BYTE
226 ,WINED3DFMT_FLAG_FILTERING },
227 {WINED3DFMT_A8L8 ,GL_LUMINANCE8_ALPHA8 ,GL_SLUMINANCE8_ALPHA8_EXT , 0, GL_LUMINANCE_ALPHA ,GL_UNSIGNED_BYTE
228 ,WINED3DFMT_FLAG_FILTERING },
229 {WINED3DFMT_A4L4 ,GL_LUMINANCE4_ALPHA4 ,GL_LUMINANCE4_ALPHA4 , 0, GL_LUMINANCE_ALPHA ,GL_UNSIGNED_BYTE
230 ,0 },
231 /* Bump mapping stuff */
232 {WINED3DFMT_V8U8 ,GL_DSDT8_NV ,GL_DSDT8_NV , 0, GL_DSDT_NV ,GL_BYTE
233 ,WINED3DFMT_FLAG_FILTERING },
234 {WINED3DFMT_L6V5U5 ,GL_DSDT8_MAG8_NV ,GL_DSDT8_MAG8_NV , 0, GL_DSDT_MAG_NV ,GL_BYTE
235 ,WINED3DFMT_FLAG_FILTERING },
236 {WINED3DFMT_X8L8V8U8 ,GL_DSDT8_MAG8_INTENSITY8_NV ,GL_DSDT8_MAG8_INTENSITY8_NV , 0, GL_DSDT_MAG_VIB_NV ,GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
237 ,WINED3DFMT_FLAG_FILTERING },
238 {WINED3DFMT_Q8W8V8U8 ,GL_SIGNED_RGBA8_NV ,GL_SIGNED_RGBA8_NV , 0, GL_RGBA ,GL_BYTE
239 ,WINED3DFMT_FLAG_FILTERING },
240 {WINED3DFMT_V16U16 ,GL_SIGNED_HILO16_NV ,GL_SIGNED_HILO16_NV , 0, GL_HILO_NV ,GL_SHORT
241 ,WINED3DFMT_FLAG_FILTERING },
242 {WINED3DFMT_W11V11U10 ,0 ,0 , 0, 0 ,0
243 ,0 },
244 {WINED3DFMT_A2W10V10U10 ,0 ,0 , 0, 0 ,0
245 ,0 },
246 /* Depth stencil formats */
247 {WINED3DFMT_D16_LOCKABLE ,GL_DEPTH_COMPONENT24_ARB ,GL_DEPTH_COMPONENT24_ARB , 0, GL_DEPTH_COMPONENT ,GL_UNSIGNED_SHORT
248 ,WINED3DFMT_FLAG_DEPTH },
249 {WINED3DFMT_D32 ,GL_DEPTH_COMPONENT32_ARB ,GL_DEPTH_COMPONENT32_ARB , 0, GL_DEPTH_COMPONENT ,GL_UNSIGNED_INT
250 ,WINED3DFMT_FLAG_DEPTH },
251 {WINED3DFMT_D15S1 ,GL_DEPTH_COMPONENT24_ARB ,GL_DEPTH_COMPONENT24_ARB , 0, GL_DEPTH_COMPONENT ,GL_UNSIGNED_SHORT
252 ,WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL },
253 {WINED3DFMT_D24S8 ,GL_DEPTH_COMPONENT24_ARB ,GL_DEPTH_COMPONENT24_ARB , 0, GL_DEPTH_COMPONENT ,GL_UNSIGNED_INT
254 ,WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL },
255 {WINED3DFMT_D24X8 ,GL_DEPTH_COMPONENT24_ARB ,GL_DEPTH_COMPONENT24_ARB , 0, GL_DEPTH_COMPONENT ,GL_UNSIGNED_INT
256 ,WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH },
257 {WINED3DFMT_D24X4S4 ,GL_DEPTH_COMPONENT24_ARB ,GL_DEPTH_COMPONENT24_ARB , 0, GL_DEPTH_COMPONENT ,GL_UNSIGNED_INT
258 ,WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL },
259 {WINED3DFMT_D16 ,GL_DEPTH_COMPONENT24_ARB ,GL_DEPTH_COMPONENT24_ARB , 0, GL_DEPTH_COMPONENT ,GL_UNSIGNED_SHORT
260 ,WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH },
261 {WINED3DFMT_L16 ,GL_LUMINANCE16_EXT ,GL_LUMINANCE16_EXT , 0, GL_LUMINANCE ,GL_UNSIGNED_SHORT
262 ,WINED3DFMT_FLAG_FILTERING },
263 {WINED3DFMT_D32F_LOCKABLE ,GL_DEPTH_COMPONENT32_ARB ,GL_DEPTH_COMPONENT32_ARB , 0, GL_DEPTH_COMPONENT ,GL_FLOAT
264 ,WINED3DFMT_FLAG_DEPTH },
265 {WINED3DFMT_D24FS8 ,GL_DEPTH_COMPONENT24_ARB ,GL_DEPTH_COMPONENT24_ARB , 0, GL_DEPTH_COMPONENT ,GL_FLOAT
266 ,WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL},
267 /* Is this a vertex buffer? */
268 {WINED3DFMT_VERTEXDATA ,0 ,0 , 0, 0 ,0
269 ,0 },
270 {WINED3DFMT_INDEX16 ,0 ,0 , 0, 0 ,0
271 ,0 },
272 {WINED3DFMT_INDEX32 ,0 ,0 , 0, 0 ,0
273 ,0 },
274 {WINED3DFMT_Q16W16V16U16 ,GL_COLOR_INDEX ,GL_COLOR_INDEX , 0, GL_COLOR_INDEX ,GL_UNSIGNED_SHORT
275 ,0 },
276 /* Vendor-specific formats */
277 {WINED3DFMT_ATI2N ,0 ,0 , 0, GL_LUMINANCE_ALPHA ,GL_UNSIGNED_BYTE
278 ,0 },
279 {WINED3DFMT_NVHU ,0 ,0 , 0, GL_LUMINANCE_ALPHA ,GL_UNSIGNED_BYTE
280 ,0 },
281 {WINED3DFMT_NVHS ,0 ,0 , 0, GL_LUMINANCE_ALPHA ,GL_UNSIGNED_BYTE
282 ,0 }
285 static inline int getFmtIdx(WINED3DFORMAT fmt) {
286 /* First check if the format is at the position of its value.
287 * This will catch the argb formats before the loop is entered
289 if(fmt < (sizeof(formats) / sizeof(formats[0])) && formats[fmt].format == fmt) {
290 return fmt;
291 } else {
292 unsigned int i;
293 for(i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
294 if(formats[i].format == fmt) {
295 return i;
299 return -1;
302 #define GLINFO_LOCATION (*gl_info)
303 BOOL initPixelFormats(WineD3D_GL_Info *gl_info)
305 unsigned int src;
306 int dst;
308 gl_info->gl_formats = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
309 sizeof(formats) / sizeof(formats[0]) * sizeof(gl_info->gl_formats[0]));
310 if(!gl_info->gl_formats) return FALSE;
312 /* If a format depends on some extensions, remove them from the table above and initialize them
313 * after this loop
315 for(src = 0; src < sizeof(gl_formats_template) / sizeof(gl_formats_template[0]); src++) {
316 dst = getFmtIdx(gl_formats_template[src].fmt);
317 gl_info->gl_formats[dst].glInternal = gl_formats_template[src].glInternal;
318 gl_info->gl_formats[dst].glGammaInternal = gl_formats_template[src].glGammaInternal;
319 gl_info->gl_formats[dst].glFormat = gl_formats_template[src].glFormat;
320 gl_info->gl_formats[dst].glType = gl_formats_template[src].glType;
321 gl_info->gl_formats[dst].conversion_group= WINED3DFMT_UNKNOWN;
322 gl_info->gl_formats[dst].Flags = gl_formats_template[src].Flags;
323 gl_info->gl_formats[dst].heightscale = 1.0;
325 if(wined3d_settings.offscreen_rendering_mode == ORM_FBO &&
326 gl_formats_template[src].rtInternal != 0) {
327 GLuint tex, fb;
328 GLenum status;
330 /* Check if the default internal format is supported as a frame buffer target, otherwise
331 * fall back to the render target internal.
333 * Try to stick to the standard format if possible, this limits precision differences
335 while(glGetError());
336 glGenTextures(1, &tex);
337 glBindTexture(GL_TEXTURE_2D, tex);
338 glTexImage2D(GL_TEXTURE_2D, 0, gl_formats_template[src].glInternal, 16, 16, 0,
339 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
341 GL_EXTCALL(glGenFramebuffersEXT(1, &fb));
342 GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb));
343 GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
344 GL_TEXTURE_2D, tex, 0));
346 status = GL_EXTCALL(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
347 GL_EXTCALL(glDeleteFramebuffersEXT(1, &fb));
348 glDeleteTextures(1, &tex);
350 checkGLcall("Framebuffer format check");
352 if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
353 TRACE("Internal format of %s not supported as frame buffer target, using render target internal instead\n",
354 debug_d3dformat(gl_formats_template[src].fmt));
355 gl_info->gl_formats[dst].rtInternal = gl_formats_template[src].rtInternal;
356 } else {
357 TRACE("Format %s is supported as fbo target\n", debug_d3dformat(gl_formats_template[src].fmt));
358 gl_info->gl_formats[dst].rtInternal = gl_formats_template[src].glInternal;
361 } else {
362 gl_info->gl_formats[dst].rtInternal = gl_formats_template[src].glInternal;
366 /* V8U8 is supported natively by GL_ATI_envmap_bumpmap and GL_NV_texture_shader.
367 * V16U16 is only supported by GL_NV_texture_shader. The formats need fixup if
368 * their extensions are not available.
370 * In theory, V8U8 and V16U16 need a fixup of the undefined blue channel. OpenGL
371 * returns 0.0 when sampling from it, DirectX 1.0. This is disabled until we find
372 * an application that needs this because it causes performance problems due to
373 * shader recompiling in some games.
375 if(!GL_SUPPORT(ATI_ENVMAP_BUMPMAP) && !GL_SUPPORT(NV_TEXTURE_SHADER2)) {
376 /* signed -> unsigned fixup */
377 dst = getFmtIdx(WINED3DFMT_V8U8);
378 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_V8U8;
379 dst = getFmtIdx(WINED3DFMT_V16U16);
380 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_V8U8;
381 } else if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
382 /* signed -> unsigned fixup */
383 dst = getFmtIdx(WINED3DFMT_V16U16);
384 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_V16U16;
385 } else {
386 /* Blue = 1.0 fixup, disabled for now */
387 if(0) {
388 dst = getFmtIdx(WINED3DFMT_V8U8);
389 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_V8U8;
390 dst = getFmtIdx(WINED3DFMT_V16U16);
391 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_V8U8;
395 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
396 /* If GL_NV_texture_shader is not supported, those formats are converted, incompatibly
397 * with each other
399 dst = getFmtIdx(WINED3DFMT_L6V5U5);
400 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_L6V5U5;
401 dst = getFmtIdx(WINED3DFMT_X8L8V8U8);
402 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_X8L8V8U8;
403 dst = getFmtIdx(WINED3DFMT_Q8W8V8U8);
404 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_Q8W8V8U8;
405 } else {
406 /* If GL_NV_texture_shader is supported, WINED3DFMT_L6V5U5 and WINED3DFMT_X8L8V8U8
407 * are converted at surface loading time, but they do not need any modification in
408 * the shader, thus they are compatible with all WINED3DFMT_UNKNOWN group formats.
409 * WINED3DFMT_Q8W8V8U8 doesn't even need load-time conversion
413 if(GL_SUPPORT(EXT_TEXTURE_COMPRESSION_RGTC)) {
414 dst = getFmtIdx(WINED3DFMT_ATI2N);
415 gl_info->gl_formats[dst].glInternal = GL_COMPRESSED_RED_GREEN_RGTC2_EXT;
416 gl_info->gl_formats[dst].glGammaInternal = GL_COMPRESSED_RED_GREEN_RGTC2_EXT;
417 gl_info->gl_formats[dst].conversion_group= WINED3DFMT_ATI2N;
418 } else if(GL_SUPPORT(ATI_TEXTURE_COMPRESSION_3DC)) {
419 dst = getFmtIdx(WINED3DFMT_ATI2N);
420 gl_info->gl_formats[dst].glInternal = GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI;
421 gl_info->gl_formats[dst].glGammaInternal = GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI;
422 gl_info->gl_formats[dst].conversion_group= WINED3DFMT_ATI2N;
425 if(!GL_SUPPORT(APPLE_YCBCR_422)) {
426 dst = getFmtIdx(WINED3DFMT_YUY2);
427 gl_info->gl_formats[dst].glInternal = GL_LUMINANCE_ALPHA;
428 gl_info->gl_formats[dst].glGammaInternal = GL_LUMINANCE_ALPHA; /* not srgb */
429 gl_info->gl_formats[dst].glFormat = GL_LUMINANCE_ALPHA;
430 gl_info->gl_formats[dst].glType = GL_UNSIGNED_BYTE;
431 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_YUY2;
433 dst = getFmtIdx(WINED3DFMT_UYVY);
434 gl_info->gl_formats[dst].glInternal = GL_LUMINANCE_ALPHA;
435 gl_info->gl_formats[dst].glGammaInternal = GL_LUMINANCE_ALPHA; /* not srgb */
436 gl_info->gl_formats[dst].glFormat = GL_LUMINANCE_ALPHA;
437 gl_info->gl_formats[dst].glType = GL_UNSIGNED_BYTE;
438 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_UYVY;
441 dst = getFmtIdx(WINED3DFMT_YV12);
442 gl_info->gl_formats[dst].heightscale = 1.5;
443 gl_info->gl_formats[dst].conversion_group = WINED3DFMT_YV12;
445 return TRUE;
448 /* NOTE: Make sure these are in the correct numerical order. (see /include/wined3d_types.h) */
449 static WINED3DGLTYPE const glTypeLookupTemplate[WINED3DDECLTYPE_UNUSED] = {
450 {WINED3DDECLTYPE_FLOAT1, 1, GL_FLOAT , GL_FALSE ,sizeof(float)},
451 {WINED3DDECLTYPE_FLOAT2, 2, GL_FLOAT , GL_FALSE ,sizeof(float)},
452 {WINED3DDECLTYPE_FLOAT3, 3, GL_FLOAT , GL_FALSE ,sizeof(float)},
453 {WINED3DDECLTYPE_FLOAT4, 4, GL_FLOAT , GL_FALSE ,sizeof(float)},
454 {WINED3DDECLTYPE_D3DCOLOR, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
455 {WINED3DDECLTYPE_UBYTE4, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
456 {WINED3DDECLTYPE_SHORT2, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
457 {WINED3DDECLTYPE_SHORT4, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
458 {WINED3DDECLTYPE_UBYTE4N, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
459 {WINED3DDECLTYPE_SHORT2N, 2, GL_SHORT , GL_TRUE ,sizeof(short int)},
460 {WINED3DDECLTYPE_SHORT4N, 4, GL_SHORT , GL_TRUE ,sizeof(short int)},
461 {WINED3DDECLTYPE_USHORT2N, 2, GL_UNSIGNED_SHORT , GL_TRUE ,sizeof(short int)},
462 {WINED3DDECLTYPE_USHORT4N, 4, GL_UNSIGNED_SHORT , GL_TRUE ,sizeof(short int)},
463 {WINED3DDECLTYPE_UDEC3, 3, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
464 {WINED3DDECLTYPE_DEC3N, 3, GL_SHORT , GL_TRUE ,sizeof(short int)},
465 {WINED3DDECLTYPE_FLOAT16_2, 2, GL_HALF_FLOAT_NV , GL_FALSE ,sizeof(GLhalfNV)},
466 {WINED3DDECLTYPE_FLOAT16_4, 4, GL_HALF_FLOAT_NV , GL_FALSE ,sizeof(GLhalfNV)}};
468 void init_type_lookup(WineD3D_GL_Info *gl_info) {
469 memcpy(gl_info->glTypeLookup, glTypeLookupTemplate, sizeof(glTypeLookupTemplate));
470 if(!GL_SUPPORT(NV_HALF_FLOAT)) {
471 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
472 * It is the job of the vertex buffer code to make sure that the vbos have the right format
474 gl_info->glTypeLookup[WINED3DDECLTYPE_FLOAT16_2].glType = GL_FLOAT;
475 gl_info->glTypeLookup[WINED3DDECLTYPE_FLOAT16_4].glType = GL_FLOAT;
479 #undef GLINFO_LOCATION
481 #define GLINFO_LOCATION This->adapter->gl_info
483 const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, WineD3D_GL_Info *gl_info, const GlPixelFormatDesc **glDesc)
485 int idx = getFmtIdx(fmt);
487 if(idx == -1) {
488 FIXME("Can't find format %s(%d) in the format lookup table\n", debug_d3dformat(fmt), fmt);
489 /* Get the caller a valid pointer */
490 idx = getFmtIdx(WINED3DFMT_UNKNOWN);
492 if(glDesc) {
493 if(!gl_info->gl_formats) {
494 /* If we do not have gl format information, provide a dummy NULL format. This is an easy way to make
495 * all gl caps check return "unsupported" than catching the lack of gl all over the code. ANSI C requires
496 * static variables to be initialized to 0.
498 static const GlPixelFormatDesc dummyFmt;
499 *glDesc = &dummyFmt;
500 } else {
501 *glDesc = &gl_info->gl_formats[idx];
504 return &formats[idx];
507 /*****************************************************************************
508 * Trace formatting of useful values
510 const char* debug_d3dformat(WINED3DFORMAT fmt) {
511 switch (fmt) {
512 #define FMT_TO_STR(fmt) case fmt: return #fmt
513 FMT_TO_STR(WINED3DFMT_UNKNOWN);
514 FMT_TO_STR(WINED3DFMT_R8G8B8);
515 FMT_TO_STR(WINED3DFMT_A8R8G8B8);
516 FMT_TO_STR(WINED3DFMT_X8R8G8B8);
517 FMT_TO_STR(WINED3DFMT_R5G6B5);
518 FMT_TO_STR(WINED3DFMT_X1R5G5B5);
519 FMT_TO_STR(WINED3DFMT_A1R5G5B5);
520 FMT_TO_STR(WINED3DFMT_A4R4G4B4);
521 FMT_TO_STR(WINED3DFMT_R3G3B2);
522 FMT_TO_STR(WINED3DFMT_A8);
523 FMT_TO_STR(WINED3DFMT_A8R3G3B2);
524 FMT_TO_STR(WINED3DFMT_X4R4G4B4);
525 FMT_TO_STR(WINED3DFMT_A2B10G10R10);
526 FMT_TO_STR(WINED3DFMT_A8B8G8R8);
527 FMT_TO_STR(WINED3DFMT_X8B8G8R8);
528 FMT_TO_STR(WINED3DFMT_G16R16);
529 FMT_TO_STR(WINED3DFMT_A2R10G10B10);
530 FMT_TO_STR(WINED3DFMT_A16B16G16R16);
531 FMT_TO_STR(WINED3DFMT_A8P8);
532 FMT_TO_STR(WINED3DFMT_P8);
533 FMT_TO_STR(WINED3DFMT_L8);
534 FMT_TO_STR(WINED3DFMT_A8L8);
535 FMT_TO_STR(WINED3DFMT_A4L4);
536 FMT_TO_STR(WINED3DFMT_V8U8);
537 FMT_TO_STR(WINED3DFMT_L6V5U5);
538 FMT_TO_STR(WINED3DFMT_X8L8V8U8);
539 FMT_TO_STR(WINED3DFMT_Q8W8V8U8);
540 FMT_TO_STR(WINED3DFMT_V16U16);
541 FMT_TO_STR(WINED3DFMT_W11V11U10);
542 FMT_TO_STR(WINED3DFMT_A2W10V10U10);
543 FMT_TO_STR(WINED3DFMT_UYVY);
544 FMT_TO_STR(WINED3DFMT_YUY2);
545 FMT_TO_STR(WINED3DFMT_YV12);
546 FMT_TO_STR(WINED3DFMT_DXT1);
547 FMT_TO_STR(WINED3DFMT_DXT2);
548 FMT_TO_STR(WINED3DFMT_DXT3);
549 FMT_TO_STR(WINED3DFMT_DXT4);
550 FMT_TO_STR(WINED3DFMT_DXT5);
551 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8);
552 FMT_TO_STR(WINED3DFMT_G8R8_G8B8);
553 FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
554 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
555 FMT_TO_STR(WINED3DFMT_D32);
556 FMT_TO_STR(WINED3DFMT_D15S1);
557 FMT_TO_STR(WINED3DFMT_D24S8);
558 FMT_TO_STR(WINED3DFMT_D24X8);
559 FMT_TO_STR(WINED3DFMT_D24X4S4);
560 FMT_TO_STR(WINED3DFMT_D16);
561 FMT_TO_STR(WINED3DFMT_L16);
562 FMT_TO_STR(WINED3DFMT_D32F_LOCKABLE);
563 FMT_TO_STR(WINED3DFMT_D24FS8);
564 FMT_TO_STR(WINED3DFMT_VERTEXDATA);
565 FMT_TO_STR(WINED3DFMT_INDEX16);
566 FMT_TO_STR(WINED3DFMT_INDEX32);
567 FMT_TO_STR(WINED3DFMT_Q16W16V16U16);
568 FMT_TO_STR(WINED3DFMT_R16F);
569 FMT_TO_STR(WINED3DFMT_G16R16F);
570 FMT_TO_STR(WINED3DFMT_A16B16G16R16F);
571 FMT_TO_STR(WINED3DFMT_R32F);
572 FMT_TO_STR(WINED3DFMT_G32R32F);
573 FMT_TO_STR(WINED3DFMT_A32B32G32R32F);
574 FMT_TO_STR(WINED3DFMT_CxV8U8);
575 FMT_TO_STR(WINED3DFMT_ATI2N);
576 FMT_TO_STR(WINED3DFMT_NVHU);
577 FMT_TO_STR(WINED3DFMT_NVHS);
578 #undef FMT_TO_STR
579 default:
581 char fourcc[5];
582 fourcc[0] = (char)(fmt);
583 fourcc[1] = (char)(fmt >> 8);
584 fourcc[2] = (char)(fmt >> 16);
585 fourcc[3] = (char)(fmt >> 24);
586 fourcc[4] = 0;
587 if( isprint(fourcc[0]) && isprint(fourcc[1]) && isprint(fourcc[2]) && isprint(fourcc[3]) )
588 FIXME("Unrecognized %u (as fourcc: %s) WINED3DFORMAT!\n", fmt, fourcc);
589 else
590 FIXME("Unrecognized %u WINED3DFORMAT!\n", fmt);
592 return "unrecognized";
596 const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype) {
597 switch (devtype) {
598 #define DEVTYPE_TO_STR(dev) case dev: return #dev
599 DEVTYPE_TO_STR(WINED3DDEVTYPE_HAL);
600 DEVTYPE_TO_STR(WINED3DDEVTYPE_REF);
601 DEVTYPE_TO_STR(WINED3DDEVTYPE_SW);
602 #undef DEVTYPE_TO_STR
603 default:
604 FIXME("Unrecognized %u WINED3DDEVTYPE!\n", devtype);
605 return "unrecognized";
609 const char* debug_d3dusage(DWORD usage) {
610 switch (usage & WINED3DUSAGE_MASK) {
611 #define WINED3DUSAGE_TO_STR(u) case u: return #u
612 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET);
613 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL);
614 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY);
615 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING);
616 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP);
617 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS);
618 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES);
619 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES);
620 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC);
621 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP);
622 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP);
623 #undef WINED3DUSAGE_TO_STR
624 case 0: return "none";
625 default:
626 FIXME("Unrecognized %u Usage!\n", usage);
627 return "unrecognized";
631 const char* debug_d3dusagequery(DWORD usagequery) {
632 switch (usagequery & WINED3DUSAGE_QUERY_MASK) {
633 #define WINED3DUSAGEQUERY_TO_STR(u) case u: return #u
634 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER);
635 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
636 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING);
637 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD);
638 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE);
639 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE);
640 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP);
641 #undef WINED3DUSAGEQUERY_TO_STR
642 case 0: return "none";
643 default:
644 FIXME("Unrecognized %u Usage Query!\n", usagequery);
645 return "unrecognized";
649 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method) {
650 switch (method) {
651 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
652 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_DEFAULT);
653 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_PARTIALU);
654 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_PARTIALV);
655 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_CROSSUV);
656 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_UV);
657 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_LOOKUP);
658 WINED3DDECLMETHOD_TO_STR(WINED3DDECLMETHOD_LOOKUPPRESAMPLED);
659 #undef WINED3DDECLMETHOD_TO_STR
660 default:
661 FIXME("Unrecognized %u declaration method!\n", method);
662 return "unrecognized";
666 const char* debug_d3ddecltype(WINED3DDECLTYPE type) {
667 switch (type) {
668 #define WINED3DDECLTYPE_TO_STR(u) case u: return #u
669 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT1);
670 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT2);
671 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT3);
672 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT4);
673 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_D3DCOLOR);
674 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UBYTE4);
675 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT2);
676 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT4);
677 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UBYTE4N);
678 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT2N);
679 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_SHORT4N);
680 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_USHORT2N);
681 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_USHORT4N);
682 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UDEC3);
683 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_DEC3N);
684 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT16_2);
685 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_FLOAT16_4);
686 WINED3DDECLTYPE_TO_STR(WINED3DDECLTYPE_UNUSED);
687 #undef WINED3DDECLTYPE_TO_STR
688 default:
689 FIXME("Unrecognized %u declaration type!\n", type);
690 return "unrecognized";
694 const char* debug_d3ddeclusage(BYTE usage) {
695 switch (usage) {
696 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
697 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_POSITION);
698 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_BLENDWEIGHT);
699 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_BLENDINDICES);
700 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_NORMAL);
701 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_PSIZE);
702 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_TEXCOORD);
703 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_TANGENT);
704 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_BINORMAL);
705 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_TESSFACTOR);
706 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_POSITIONT);
707 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_COLOR);
708 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_FOG);
709 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_DEPTH);
710 WINED3DDECLUSAGE_TO_STR(WINED3DDECLUSAGE_SAMPLE);
711 #undef WINED3DDECLUSAGE_TO_STR
712 default:
713 FIXME("Unrecognized %u declaration usage!\n", usage);
714 return "unrecognized";
718 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res) {
719 switch (res) {
720 #define RES_TO_STR(res) case res: return #res;
721 RES_TO_STR(WINED3DRTYPE_SURFACE);
722 RES_TO_STR(WINED3DRTYPE_VOLUME);
723 RES_TO_STR(WINED3DRTYPE_TEXTURE);
724 RES_TO_STR(WINED3DRTYPE_VOLUMETEXTURE);
725 RES_TO_STR(WINED3DRTYPE_CUBETEXTURE);
726 RES_TO_STR(WINED3DRTYPE_VERTEXBUFFER);
727 RES_TO_STR(WINED3DRTYPE_INDEXBUFFER);
728 #undef RES_TO_STR
729 default:
730 FIXME("Unrecognized %u WINED3DRESOURCETYPE!\n", res);
731 return "unrecognized";
735 const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType) {
736 switch (PrimitiveType) {
737 #define PRIM_TO_STR(prim) case prim: return #prim;
738 PRIM_TO_STR(WINED3DPT_POINTLIST);
739 PRIM_TO_STR(WINED3DPT_LINELIST);
740 PRIM_TO_STR(WINED3DPT_LINESTRIP);
741 PRIM_TO_STR(WINED3DPT_TRIANGLELIST);
742 PRIM_TO_STR(WINED3DPT_TRIANGLESTRIP);
743 PRIM_TO_STR(WINED3DPT_TRIANGLEFAN);
744 #undef PRIM_TO_STR
745 default:
746 FIXME("Unrecognized %u WINED3DPRIMITIVETYPE!\n", PrimitiveType);
747 return "unrecognized";
751 const char* debug_d3drenderstate(DWORD state) {
752 switch (state) {
753 #define D3DSTATE_TO_STR(u) case u: return #u
754 D3DSTATE_TO_STR(WINED3DRS_TEXTUREHANDLE );
755 D3DSTATE_TO_STR(WINED3DRS_ANTIALIAS );
756 D3DSTATE_TO_STR(WINED3DRS_TEXTUREADDRESS );
757 D3DSTATE_TO_STR(WINED3DRS_TEXTUREPERSPECTIVE );
758 D3DSTATE_TO_STR(WINED3DRS_WRAPU );
759 D3DSTATE_TO_STR(WINED3DRS_WRAPV );
760 D3DSTATE_TO_STR(WINED3DRS_ZENABLE );
761 D3DSTATE_TO_STR(WINED3DRS_FILLMODE );
762 D3DSTATE_TO_STR(WINED3DRS_SHADEMODE );
763 D3DSTATE_TO_STR(WINED3DRS_LINEPATTERN );
764 D3DSTATE_TO_STR(WINED3DRS_MONOENABLE );
765 D3DSTATE_TO_STR(WINED3DRS_ROP2 );
766 D3DSTATE_TO_STR(WINED3DRS_PLANEMASK );
767 D3DSTATE_TO_STR(WINED3DRS_ZWRITEENABLE );
768 D3DSTATE_TO_STR(WINED3DRS_ALPHATESTENABLE );
769 D3DSTATE_TO_STR(WINED3DRS_LASTPIXEL );
770 D3DSTATE_TO_STR(WINED3DRS_TEXTUREMAG );
771 D3DSTATE_TO_STR(WINED3DRS_TEXTUREMIN );
772 D3DSTATE_TO_STR(WINED3DRS_SRCBLEND );
773 D3DSTATE_TO_STR(WINED3DRS_DESTBLEND );
774 D3DSTATE_TO_STR(WINED3DRS_TEXTUREMAPBLEND );
775 D3DSTATE_TO_STR(WINED3DRS_CULLMODE );
776 D3DSTATE_TO_STR(WINED3DRS_ZFUNC );
777 D3DSTATE_TO_STR(WINED3DRS_ALPHAREF );
778 D3DSTATE_TO_STR(WINED3DRS_ALPHAFUNC );
779 D3DSTATE_TO_STR(WINED3DRS_DITHERENABLE );
780 D3DSTATE_TO_STR(WINED3DRS_ALPHABLENDENABLE );
781 D3DSTATE_TO_STR(WINED3DRS_FOGENABLE );
782 D3DSTATE_TO_STR(WINED3DRS_SPECULARENABLE );
783 D3DSTATE_TO_STR(WINED3DRS_ZVISIBLE );
784 D3DSTATE_TO_STR(WINED3DRS_SUBPIXEL );
785 D3DSTATE_TO_STR(WINED3DRS_SUBPIXELX );
786 D3DSTATE_TO_STR(WINED3DRS_STIPPLEDALPHA );
787 D3DSTATE_TO_STR(WINED3DRS_FOGCOLOR );
788 D3DSTATE_TO_STR(WINED3DRS_FOGTABLEMODE );
789 D3DSTATE_TO_STR(WINED3DRS_FOGSTART );
790 D3DSTATE_TO_STR(WINED3DRS_FOGEND );
791 D3DSTATE_TO_STR(WINED3DRS_FOGDENSITY );
792 D3DSTATE_TO_STR(WINED3DRS_STIPPLEENABLE );
793 D3DSTATE_TO_STR(WINED3DRS_EDGEANTIALIAS );
794 D3DSTATE_TO_STR(WINED3DRS_COLORKEYENABLE );
795 D3DSTATE_TO_STR(WINED3DRS_BORDERCOLOR );
796 D3DSTATE_TO_STR(WINED3DRS_TEXTUREADDRESSU );
797 D3DSTATE_TO_STR(WINED3DRS_TEXTUREADDRESSV );
798 D3DSTATE_TO_STR(WINED3DRS_MIPMAPLODBIAS );
799 D3DSTATE_TO_STR(WINED3DRS_ZBIAS );
800 D3DSTATE_TO_STR(WINED3DRS_RANGEFOGENABLE );
801 D3DSTATE_TO_STR(WINED3DRS_ANISOTROPY );
802 D3DSTATE_TO_STR(WINED3DRS_FLUSHBATCH );
803 D3DSTATE_TO_STR(WINED3DRS_TRANSLUCENTSORTINDEPENDENT);
804 D3DSTATE_TO_STR(WINED3DRS_STENCILENABLE );
805 D3DSTATE_TO_STR(WINED3DRS_STENCILFAIL );
806 D3DSTATE_TO_STR(WINED3DRS_STENCILZFAIL );
807 D3DSTATE_TO_STR(WINED3DRS_STENCILPASS );
808 D3DSTATE_TO_STR(WINED3DRS_STENCILFUNC );
809 D3DSTATE_TO_STR(WINED3DRS_STENCILREF );
810 D3DSTATE_TO_STR(WINED3DRS_STENCILMASK );
811 D3DSTATE_TO_STR(WINED3DRS_STENCILWRITEMASK );
812 D3DSTATE_TO_STR(WINED3DRS_TEXTUREFACTOR );
813 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN00 );
814 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN01 );
815 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN02 );
816 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN03 );
817 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN04 );
818 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN05 );
819 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN06 );
820 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN07 );
821 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN08 );
822 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN09 );
823 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN10 );
824 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN11 );
825 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN12 );
826 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN13 );
827 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN14 );
828 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN15 );
829 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN16 );
830 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN17 );
831 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN18 );
832 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN19 );
833 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN20 );
834 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN21 );
835 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN22 );
836 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN23 );
837 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN24 );
838 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN25 );
839 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN26 );
840 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN27 );
841 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN28 );
842 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN29 );
843 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN30 );
844 D3DSTATE_TO_STR(WINED3DRS_STIPPLEPATTERN31 );
845 D3DSTATE_TO_STR(WINED3DRS_WRAP0 );
846 D3DSTATE_TO_STR(WINED3DRS_WRAP1 );
847 D3DSTATE_TO_STR(WINED3DRS_WRAP2 );
848 D3DSTATE_TO_STR(WINED3DRS_WRAP3 );
849 D3DSTATE_TO_STR(WINED3DRS_WRAP4 );
850 D3DSTATE_TO_STR(WINED3DRS_WRAP5 );
851 D3DSTATE_TO_STR(WINED3DRS_WRAP6 );
852 D3DSTATE_TO_STR(WINED3DRS_WRAP7 );
853 D3DSTATE_TO_STR(WINED3DRS_CLIPPING );
854 D3DSTATE_TO_STR(WINED3DRS_LIGHTING );
855 D3DSTATE_TO_STR(WINED3DRS_EXTENTS );
856 D3DSTATE_TO_STR(WINED3DRS_AMBIENT );
857 D3DSTATE_TO_STR(WINED3DRS_FOGVERTEXMODE );
858 D3DSTATE_TO_STR(WINED3DRS_COLORVERTEX );
859 D3DSTATE_TO_STR(WINED3DRS_LOCALVIEWER );
860 D3DSTATE_TO_STR(WINED3DRS_NORMALIZENORMALS );
861 D3DSTATE_TO_STR(WINED3DRS_COLORKEYBLENDENABLE );
862 D3DSTATE_TO_STR(WINED3DRS_DIFFUSEMATERIALSOURCE );
863 D3DSTATE_TO_STR(WINED3DRS_SPECULARMATERIALSOURCE );
864 D3DSTATE_TO_STR(WINED3DRS_AMBIENTMATERIALSOURCE );
865 D3DSTATE_TO_STR(WINED3DRS_EMISSIVEMATERIALSOURCE );
866 D3DSTATE_TO_STR(WINED3DRS_VERTEXBLEND );
867 D3DSTATE_TO_STR(WINED3DRS_CLIPPLANEENABLE );
868 D3DSTATE_TO_STR(WINED3DRS_SOFTWAREVERTEXPROCESSING );
869 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE );
870 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MIN );
871 D3DSTATE_TO_STR(WINED3DRS_POINTSPRITEENABLE );
872 D3DSTATE_TO_STR(WINED3DRS_POINTSCALEENABLE );
873 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_A );
874 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_B );
875 D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_C );
876 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEANTIALIAS );
877 D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEMASK );
878 D3DSTATE_TO_STR(WINED3DRS_PATCHEDGESTYLE );
879 D3DSTATE_TO_STR(WINED3DRS_PATCHSEGMENTS );
880 D3DSTATE_TO_STR(WINED3DRS_DEBUGMONITORTOKEN );
881 D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MAX );
882 D3DSTATE_TO_STR(WINED3DRS_INDEXEDVERTEXBLENDENABLE );
883 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE );
884 D3DSTATE_TO_STR(WINED3DRS_TWEENFACTOR );
885 D3DSTATE_TO_STR(WINED3DRS_BLENDOP );
886 D3DSTATE_TO_STR(WINED3DRS_POSITIONDEGREE );
887 D3DSTATE_TO_STR(WINED3DRS_NORMALDEGREE );
888 D3DSTATE_TO_STR(WINED3DRS_SCISSORTESTENABLE );
889 D3DSTATE_TO_STR(WINED3DRS_SLOPESCALEDEPTHBIAS );
890 D3DSTATE_TO_STR(WINED3DRS_ANTIALIASEDLINEENABLE );
891 D3DSTATE_TO_STR(WINED3DRS_MINTESSELLATIONLEVEL );
892 D3DSTATE_TO_STR(WINED3DRS_MAXTESSELLATIONLEVEL );
893 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_X );
894 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Y );
895 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Z );
896 D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_W );
897 D3DSTATE_TO_STR(WINED3DRS_ENABLEADAPTIVETESSELLATION);
898 D3DSTATE_TO_STR(WINED3DRS_TWOSIDEDSTENCILMODE );
899 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFAIL );
900 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILZFAIL );
901 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILPASS );
902 D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFUNC );
903 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE1 );
904 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE2 );
905 D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE3 );
906 D3DSTATE_TO_STR(WINED3DRS_BLENDFACTOR );
907 D3DSTATE_TO_STR(WINED3DRS_SRGBWRITEENABLE );
908 D3DSTATE_TO_STR(WINED3DRS_DEPTHBIAS );
909 D3DSTATE_TO_STR(WINED3DRS_WRAP8 );
910 D3DSTATE_TO_STR(WINED3DRS_WRAP9 );
911 D3DSTATE_TO_STR(WINED3DRS_WRAP10 );
912 D3DSTATE_TO_STR(WINED3DRS_WRAP11 );
913 D3DSTATE_TO_STR(WINED3DRS_WRAP12 );
914 D3DSTATE_TO_STR(WINED3DRS_WRAP13 );
915 D3DSTATE_TO_STR(WINED3DRS_WRAP14 );
916 D3DSTATE_TO_STR(WINED3DRS_WRAP15 );
917 D3DSTATE_TO_STR(WINED3DRS_SEPARATEALPHABLENDENABLE );
918 D3DSTATE_TO_STR(WINED3DRS_SRCBLENDALPHA );
919 D3DSTATE_TO_STR(WINED3DRS_DESTBLENDALPHA );
920 D3DSTATE_TO_STR(WINED3DRS_BLENDOPALPHA );
921 #undef D3DSTATE_TO_STR
922 default:
923 FIXME("Unrecognized %u render state!\n", state);
924 return "unrecognized";
928 const char* debug_d3dsamplerstate(DWORD state) {
929 switch (state) {
930 #define D3DSTATE_TO_STR(u) case u: return #u
931 D3DSTATE_TO_STR(WINED3DSAMP_BORDERCOLOR );
932 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSU );
933 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSV );
934 D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSW );
935 D3DSTATE_TO_STR(WINED3DSAMP_MAGFILTER );
936 D3DSTATE_TO_STR(WINED3DSAMP_MINFILTER );
937 D3DSTATE_TO_STR(WINED3DSAMP_MIPFILTER );
938 D3DSTATE_TO_STR(WINED3DSAMP_MIPMAPLODBIAS);
939 D3DSTATE_TO_STR(WINED3DSAMP_MAXMIPLEVEL );
940 D3DSTATE_TO_STR(WINED3DSAMP_MAXANISOTROPY);
941 D3DSTATE_TO_STR(WINED3DSAMP_SRGBTEXTURE );
942 D3DSTATE_TO_STR(WINED3DSAMP_ELEMENTINDEX );
943 D3DSTATE_TO_STR(WINED3DSAMP_DMAPOFFSET );
944 #undef D3DSTATE_TO_STR
945 default:
946 FIXME("Unrecognized %u sampler state!\n", state);
947 return "unrecognized";
951 const char *debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type) {
952 switch (filter_type) {
953 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
954 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_NONE);
955 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_POINT);
956 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_LINEAR);
957 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_ANISOTROPIC);
958 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_FLATCUBIC);
959 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_GAUSSIANCUBIC);
960 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_PYRAMIDALQUAD);
961 D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_GAUSSIANQUAD);
962 #undef D3DTEXTUREFILTERTYPE_TO_STR
963 default:
964 FIXME("Unrecognied texture filter type 0x%08x\n", filter_type);
965 return "unrecognized";
969 const char* debug_d3dtexturestate(DWORD state) {
970 switch (state) {
971 #define D3DSTATE_TO_STR(u) case u: return #u
972 D3DSTATE_TO_STR(WINED3DTSS_COLOROP );
973 D3DSTATE_TO_STR(WINED3DTSS_COLORARG1 );
974 D3DSTATE_TO_STR(WINED3DTSS_COLORARG2 );
975 D3DSTATE_TO_STR(WINED3DTSS_ALPHAOP );
976 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG1 );
977 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG2 );
978 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT00 );
979 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT01 );
980 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT10 );
981 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT11 );
982 D3DSTATE_TO_STR(WINED3DTSS_TEXCOORDINDEX );
983 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLSCALE );
984 D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLOFFSET );
985 D3DSTATE_TO_STR(WINED3DTSS_TEXTURETRANSFORMFLAGS );
986 D3DSTATE_TO_STR(WINED3DTSS_ADDRESSW );
987 D3DSTATE_TO_STR(WINED3DTSS_COLORARG0 );
988 D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG0 );
989 D3DSTATE_TO_STR(WINED3DTSS_RESULTARG );
990 D3DSTATE_TO_STR(WINED3DTSS_CONSTANT );
991 #undef D3DSTATE_TO_STR
992 case 12:
993 /* Note WINED3DTSS are not consecutive, so skip these */
994 return "unused";
995 default:
996 FIXME("Unrecognized %u texture state!\n", state);
997 return "unrecognized";
1001 const char* debug_d3dtop(WINED3DTEXTUREOP d3dtop) {
1002 switch (d3dtop) {
1003 #define D3DTOP_TO_STR(u) case u: return #u
1004 D3DTOP_TO_STR(WINED3DTOP_DISABLE);
1005 D3DTOP_TO_STR(WINED3DTOP_SELECTARG1);
1006 D3DTOP_TO_STR(WINED3DTOP_SELECTARG2);
1007 D3DTOP_TO_STR(WINED3DTOP_MODULATE);
1008 D3DTOP_TO_STR(WINED3DTOP_MODULATE2X);
1009 D3DTOP_TO_STR(WINED3DTOP_MODULATE4X);
1010 D3DTOP_TO_STR(WINED3DTOP_ADD);
1011 D3DTOP_TO_STR(WINED3DTOP_ADDSIGNED);
1012 D3DTOP_TO_STR(WINED3DTOP_ADDSIGNED2X);
1013 D3DTOP_TO_STR(WINED3DTOP_SUBTRACT);
1014 D3DTOP_TO_STR(WINED3DTOP_ADDSMOOTH);
1015 D3DTOP_TO_STR(WINED3DTOP_BLENDDIFFUSEALPHA);
1016 D3DTOP_TO_STR(WINED3DTOP_BLENDTEXTUREALPHA);
1017 D3DTOP_TO_STR(WINED3DTOP_BLENDFACTORALPHA);
1018 D3DTOP_TO_STR(WINED3DTOP_BLENDTEXTUREALPHAPM);
1019 D3DTOP_TO_STR(WINED3DTOP_BLENDCURRENTALPHA);
1020 D3DTOP_TO_STR(WINED3DTOP_PREMODULATE);
1021 D3DTOP_TO_STR(WINED3DTOP_MODULATEALPHA_ADDCOLOR);
1022 D3DTOP_TO_STR(WINED3DTOP_MODULATECOLOR_ADDALPHA);
1023 D3DTOP_TO_STR(WINED3DTOP_MODULATEINVALPHA_ADDCOLOR);
1024 D3DTOP_TO_STR(WINED3DTOP_MODULATEINVCOLOR_ADDALPHA);
1025 D3DTOP_TO_STR(WINED3DTOP_BUMPENVMAP);
1026 D3DTOP_TO_STR(WINED3DTOP_BUMPENVMAPLUMINANCE);
1027 D3DTOP_TO_STR(WINED3DTOP_DOTPRODUCT3);
1028 D3DTOP_TO_STR(WINED3DTOP_MULTIPLYADD);
1029 D3DTOP_TO_STR(WINED3DTOP_LERP);
1030 #undef D3DTOP_TO_STR
1031 default:
1032 FIXME("Unrecognized %u WINED3DTOP\n", d3dtop);
1033 return "unrecognized";
1037 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype) {
1038 switch (tstype) {
1039 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
1040 TSTYPE_TO_STR(WINED3DTS_VIEW);
1041 TSTYPE_TO_STR(WINED3DTS_PROJECTION);
1042 TSTYPE_TO_STR(WINED3DTS_TEXTURE0);
1043 TSTYPE_TO_STR(WINED3DTS_TEXTURE1);
1044 TSTYPE_TO_STR(WINED3DTS_TEXTURE2);
1045 TSTYPE_TO_STR(WINED3DTS_TEXTURE3);
1046 TSTYPE_TO_STR(WINED3DTS_TEXTURE4);
1047 TSTYPE_TO_STR(WINED3DTS_TEXTURE5);
1048 TSTYPE_TO_STR(WINED3DTS_TEXTURE6);
1049 TSTYPE_TO_STR(WINED3DTS_TEXTURE7);
1050 TSTYPE_TO_STR(WINED3DTS_WORLDMATRIX(0));
1051 #undef TSTYPE_TO_STR
1052 default:
1053 if (tstype > 256 && tstype < 512) {
1054 FIXME("WINED3DTS_WORLDMATRIX(%u). 1..255 not currently supported\n", tstype);
1055 return ("WINED3DTS_WORLDMATRIX > 0");
1057 FIXME("Unrecognized %u WINED3DTS\n", tstype);
1058 return "unrecognized";
1062 const char* debug_d3dpool(WINED3DPOOL Pool) {
1063 switch (Pool) {
1064 #define POOL_TO_STR(p) case p: return #p;
1065 POOL_TO_STR(WINED3DPOOL_DEFAULT);
1066 POOL_TO_STR(WINED3DPOOL_MANAGED);
1067 POOL_TO_STR(WINED3DPOOL_SYSTEMMEM);
1068 POOL_TO_STR(WINED3DPOOL_SCRATCH);
1069 #undef POOL_TO_STR
1070 default:
1071 FIXME("Unrecognized %u WINED3DPOOL!\n", Pool);
1072 return "unrecognized";
1076 const char *debug_fbostatus(GLenum status) {
1077 switch(status) {
1078 #define FBOSTATUS_TO_STR(u) case u: return #u
1079 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE_EXT);
1080 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT);
1081 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT);
1082 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT);
1083 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT);
1084 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT);
1085 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT);
1086 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED_EXT);
1087 #undef FBOSTATUS_TO_STR
1088 default:
1089 FIXME("Unrecognied FBO status 0x%08x\n", status);
1090 return "unrecognized";
1094 const char *debug_glerror(GLenum error) {
1095 switch(error) {
1096 #define GLERROR_TO_STR(u) case u: return #u
1097 GLERROR_TO_STR(GL_NO_ERROR);
1098 GLERROR_TO_STR(GL_INVALID_ENUM);
1099 GLERROR_TO_STR(GL_INVALID_VALUE);
1100 GLERROR_TO_STR(GL_INVALID_OPERATION);
1101 GLERROR_TO_STR(GL_STACK_OVERFLOW);
1102 GLERROR_TO_STR(GL_STACK_UNDERFLOW);
1103 GLERROR_TO_STR(GL_OUT_OF_MEMORY);
1104 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION_EXT);
1105 #undef GLERROR_TO_STR
1106 default:
1107 FIXME("Unrecognied GL error 0x%08x\n", error);
1108 return "unrecognized";
1112 const char *debug_d3dbasis(WINED3DBASISTYPE basis) {
1113 switch(basis) {
1114 case WINED3DBASIS_BEZIER: return "WINED3DBASIS_BEZIER";
1115 case WINED3DBASIS_BSPLINE: return "WINED3DBASIS_BSPLINE";
1116 case WINED3DBASIS_INTERPOLATE: return "WINED3DBASIS_INTERPOLATE";
1117 default: return "unrecognized";
1121 const char *debug_d3ddegree(WINED3DDEGREETYPE degree) {
1122 switch(degree) {
1123 case WINED3DDEGREE_LINEAR: return "WINED3DDEGREE_LINEAR";
1124 case WINED3DDEGREE_QUADRATIC: return "WINED3DDEGREE_QUADRATIC";
1125 case WINED3DDEGREE_CUBIC: return "WINED3DDEGREE_CUBIC";
1126 case WINED3DDEGREE_QUINTIC: return "WINED3DDEGREE_QUINTIC";
1127 default: return "unrecognized";
1131 /*****************************************************************************
1132 * Useful functions mapping GL <-> D3D values
1134 GLenum StencilOp(DWORD op) {
1135 switch(op) {
1136 case WINED3DSTENCILOP_KEEP : return GL_KEEP;
1137 case WINED3DSTENCILOP_ZERO : return GL_ZERO;
1138 case WINED3DSTENCILOP_REPLACE : return GL_REPLACE;
1139 case WINED3DSTENCILOP_INCRSAT : return GL_INCR;
1140 case WINED3DSTENCILOP_DECRSAT : return GL_DECR;
1141 case WINED3DSTENCILOP_INVERT : return GL_INVERT;
1142 case WINED3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
1143 case WINED3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
1144 default:
1145 FIXME("Unrecognized stencil op %d\n", op);
1146 return GL_KEEP;
1150 GLenum CompareFunc(DWORD func) {
1151 switch ((WINED3DCMPFUNC)func) {
1152 case WINED3DCMP_NEVER : return GL_NEVER;
1153 case WINED3DCMP_LESS : return GL_LESS;
1154 case WINED3DCMP_EQUAL : return GL_EQUAL;
1155 case WINED3DCMP_LESSEQUAL : return GL_LEQUAL;
1156 case WINED3DCMP_GREATER : return GL_GREATER;
1157 case WINED3DCMP_NOTEQUAL : return GL_NOTEQUAL;
1158 case WINED3DCMP_GREATEREQUAL : return GL_GEQUAL;
1159 case WINED3DCMP_ALWAYS : return GL_ALWAYS;
1160 default:
1161 FIXME("Unrecognized WINED3DCMPFUNC value %d\n", func);
1162 return 0;
1166 BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3) {
1167 if (op == WINED3DTOP_DISABLE) return FALSE;
1168 if (This->stateBlock->textures[stage]) return FALSE;
1170 if ((arg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
1171 && op != WINED3DTOP_SELECTARG2) return TRUE;
1172 if ((arg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
1173 && op != WINED3DTOP_SELECTARG1) return TRUE;
1174 if ((arg3 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
1175 && (op == WINED3DTOP_MULTIPLYADD || op == WINED3DTOP_LERP)) return TRUE;
1177 return FALSE;
1180 /* Setup this textures matrix according to the texture flags*/
1181 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, BOOL transformed, DWORD coordtype,
1182 BOOL ffp_proj_control)
1184 float mat[16];
1186 glMatrixMode(GL_TEXTURE);
1187 checkGLcall("glMatrixMode(GL_TEXTURE)");
1189 if (flags == WINED3DTTFF_DISABLE || flags == WINED3DTTFF_COUNT1 || transformed) {
1190 glLoadIdentity();
1191 checkGLcall("glLoadIdentity()");
1192 return;
1195 if (flags == (WINED3DTTFF_COUNT1|WINED3DTTFF_PROJECTED)) {
1196 ERR("Invalid texture transform flags: WINED3DTTFF_COUNT1|WINED3DTTFF_PROJECTED\n");
1197 return;
1200 memcpy(mat, smat, 16 * sizeof(float));
1202 if (flags & WINED3DTTFF_PROJECTED) {
1203 if(!ffp_proj_control) {
1204 switch (flags & ~WINED3DTTFF_PROJECTED) {
1205 case WINED3DTTFF_COUNT2:
1206 mat[3] = mat[1], mat[7] = mat[5], mat[11] = mat[9], mat[15] = mat[13];
1207 mat[1] = mat[5] = mat[9] = mat[13] = 0;
1208 break;
1209 case WINED3DTTFF_COUNT3:
1210 mat[3] = mat[2], mat[7] = mat[6], mat[11] = mat[10], mat[15] = mat[14];
1211 mat[2] = mat[6] = mat[10] = mat[14] = 0;
1212 break;
1215 } else { /* under directx the R/Z coord can be used for translation, under opengl we use the Q coord instead */
1216 if(!calculatedCoords) {
1217 switch(coordtype) {
1218 case WINED3DDECLTYPE_FLOAT1:
1219 /* Direct3D passes the default 1.0 in the 2nd coord, while gl passes it in the 4th.
1220 * swap 2nd and 4th coord. No need to store the value of mat[12] in mat[4] because
1221 * the input value to the transformation will be 0, so the matrix value is irrelevant
1223 mat[12] = mat[4];
1224 mat[13] = mat[5];
1225 mat[14] = mat[6];
1226 mat[15] = mat[7];
1227 break;
1228 case WINED3DDECLTYPE_FLOAT2:
1229 /* See above, just 3rd and 4th coord
1231 mat[12] = mat[8];
1232 mat[13] = mat[9];
1233 mat[14] = mat[10];
1234 mat[15] = mat[11];
1235 break;
1236 case WINED3DDECLTYPE_FLOAT3: /* Opengl defaults match dx defaults */
1237 case WINED3DDECLTYPE_FLOAT4: /* No defaults apply, all app defined */
1239 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
1240 * into a bad place. The division elimination below will apply to make sure the
1241 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
1243 case WINED3DDECLTYPE_UNUSED: /* No texture coords, 0/0/0/1 defaults are passed */
1244 break;
1245 default:
1246 FIXME("Unexpected fixed function texture coord input\n");
1249 if(!ffp_proj_control) {
1250 switch (flags & ~WINED3DTTFF_PROJECTED) {
1251 /* case WINED3DTTFF_COUNT1: Won't ever get here */
1252 case WINED3DTTFF_COUNT2: mat[2] = mat[6] = mat[10] = mat[14] = 0;
1253 /* OpenGL divides the first 3 vertex coord by the 4th by default,
1254 * which is essentially the same as D3DTTFF_PROJECTED. Make sure that
1255 * the 4th coord evaluates to 1.0 to eliminate that.
1257 * If the fixed function pipeline is used, the 4th value remains unused,
1258 * so there is no danger in doing this. With vertex shaders we have a
1259 * problem. Should an app hit that problem, the code here would have to
1260 * check for pixel shaders, and the shader has to undo the default gl divide.
1262 * A more serious problem occurs if the app passes 4 coordinates in, and the
1263 * 4th is != 1.0(opengl default). This would have to be fixed in drawStridedSlow
1264 * or a replacement shader
1266 default: mat[3] = mat[7] = mat[11] = 0; mat[15] = 1;
1271 glLoadMatrixf(mat);
1272 checkGLcall("glLoadMatrixf(mat)");
1274 #undef GLINFO_LOCATION
1276 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
1278 /* This small helper function is used to convert a bitmask into the number of masked bits */
1279 unsigned int count_bits(unsigned int mask)
1281 unsigned int count;
1282 for (count = 0; mask; ++count)
1284 mask &= mask - 1;
1286 return count;
1289 /* Helper function for retrieving color info for ChoosePixelFormat and wglChoosePixelFormatARB.
1290 * The later function requires individual color components. */
1291 BOOL getColorBits(WINED3DFORMAT fmt, short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize)
1293 const StaticPixelFormatDesc *desc;
1295 TRACE("fmt: %s\n", debug_d3dformat(fmt));
1296 switch(fmt)
1298 case WINED3DFMT_X8R8G8B8:
1299 case WINED3DFMT_R8G8B8:
1300 case WINED3DFMT_A8R8G8B8:
1301 case WINED3DFMT_A2R10G10B10:
1302 case WINED3DFMT_X1R5G5B5:
1303 case WINED3DFMT_A1R5G5B5:
1304 case WINED3DFMT_R5G6B5:
1305 case WINED3DFMT_X4R4G4B4:
1306 case WINED3DFMT_A4R4G4B4:
1307 case WINED3DFMT_R3G3B2:
1308 case WINED3DFMT_A8P8:
1309 case WINED3DFMT_P8:
1310 break;
1311 default:
1312 ERR("Unsupported format: %s\n", debug_d3dformat(fmt));
1313 return FALSE;
1316 desc = getFormatDescEntry(fmt, NULL, NULL);
1317 if(!desc)
1319 ERR("Unable to look up format: 0x%x\n", fmt);
1320 return FALSE;
1322 *redSize = count_bits(desc->redMask);
1323 *greenSize = count_bits(desc->greenMask);
1324 *blueSize = count_bits(desc->blueMask);
1325 *alphaSize = count_bits(desc->alphaMask);
1326 *totalSize = *redSize + *greenSize + *blueSize + *alphaSize;
1328 TRACE("Returning red: %d, green: %d, blue: %d, alpha: %d, total: %d for fmt=%s\n", *redSize, *greenSize, *blueSize, *alphaSize, *totalSize, debug_d3dformat(fmt));
1329 return TRUE;
1332 /* Helper function for retrieving depth/stencil info for ChoosePixelFormat and wglChoosePixelFormatARB */
1333 BOOL getDepthStencilBits(WINED3DFORMAT fmt, short *depthSize, short *stencilSize)
1335 const StaticPixelFormatDesc *desc;
1337 TRACE("fmt: %s\n", debug_d3dformat(fmt));
1338 switch(fmt)
1340 case WINED3DFMT_D16_LOCKABLE:
1341 case WINED3DFMT_D16:
1342 case WINED3DFMT_D15S1:
1343 case WINED3DFMT_D24X8:
1344 case WINED3DFMT_D24X4S4:
1345 case WINED3DFMT_D24S8:
1346 case WINED3DFMT_D24FS8:
1347 case WINED3DFMT_D32:
1348 case WINED3DFMT_D32F_LOCKABLE:
1349 break;
1350 default:
1351 FIXME("Unsupported stencil format: %s\n", debug_d3dformat(fmt));
1352 return FALSE;
1355 desc = getFormatDescEntry(fmt, NULL, NULL);
1356 if(!desc)
1358 ERR("Unable to look up format: 0x%x\n", fmt);
1359 return FALSE;
1361 *depthSize = desc->depthSize;
1362 *stencilSize = desc->stencilSize;
1364 TRACE("Returning depthSize: %d and stencilSize: %d for fmt=%s\n", *depthSize, *stencilSize, debug_d3dformat(fmt));
1365 return TRUE;
1368 #undef GLINFO_LOCATION
1370 /* DirectDraw stuff */
1371 WINED3DFORMAT pixelformat_for_depth(DWORD depth) {
1372 switch(depth) {
1373 case 8: return WINED3DFMT_P8;
1374 case 15: return WINED3DFMT_X1R5G5B5;
1375 case 16: return WINED3DFMT_R5G6B5;
1376 case 24: return WINED3DFMT_X8R8G8B8; /* Robots needs 24bit to be X8R8G8B8 */
1377 case 32: return WINED3DFMT_X8R8G8B8; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return X8R8G8B8 */
1378 default: return WINED3DFMT_UNKNOWN;
1382 void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2) {
1383 WINED3DMATRIX temp;
1385 /* Now do the multiplication 'by hand'.
1386 I know that all this could be optimised, but this will be done later :-) */
1387 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);
1388 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);
1389 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);
1390 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);
1392 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);
1393 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);
1394 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);
1395 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);
1397 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);
1398 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);
1399 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);
1400 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);
1402 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);
1403 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);
1404 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);
1405 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);
1407 /* And copy the new matrix in the good storage.. */
1408 memcpy(dest, &temp, 16 * sizeof(float));
1411 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) {
1412 DWORD size = 0;
1413 int i;
1414 int numTextures = (d3dvtVertexType & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
1416 if (d3dvtVertexType & WINED3DFVF_NORMAL) size += 3 * sizeof(float);
1417 if (d3dvtVertexType & WINED3DFVF_DIFFUSE) size += sizeof(DWORD);
1418 if (d3dvtVertexType & WINED3DFVF_SPECULAR) size += sizeof(DWORD);
1419 if (d3dvtVertexType & WINED3DFVF_PSIZE) size += sizeof(DWORD);
1420 switch (d3dvtVertexType & WINED3DFVF_POSITION_MASK) {
1421 case WINED3DFVF_XYZ: size += 3 * sizeof(float); break;
1422 case WINED3DFVF_XYZRHW: size += 4 * sizeof(float); break;
1423 case WINED3DFVF_XYZB1: size += 4 * sizeof(float); break;
1424 case WINED3DFVF_XYZB2: size += 5 * sizeof(float); break;
1425 case WINED3DFVF_XYZB3: size += 6 * sizeof(float); break;
1426 case WINED3DFVF_XYZB4: size += 7 * sizeof(float); break;
1427 case WINED3DFVF_XYZB5: size += 8 * sizeof(float); break;
1428 default: ERR("Unexpected position mask\n");
1430 for (i = 0; i < numTextures; i++) {
1431 size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(float);
1434 return size;
1437 /***********************************************************************
1438 * CalculateTexRect
1440 * Calculates the dimensions of the opengl texture used for blits.
1441 * Handled oversized opengl textures and updates the source rectangle
1442 * accordingly
1444 * Params:
1445 * This: Surface to operate on
1446 * Rect: Requested rectangle
1448 * Returns:
1449 * TRUE if the texture part can be loaded,
1450 * FALSE otherwise
1452 *********************************************************************/
1453 #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
1455 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]) {
1456 int x1 = Rect->left, x2 = Rect->right;
1457 int y1 = Rect->top, y2 = Rect->bottom;
1458 GLint maxSize = GL_LIMITS(texture_size);
1460 TRACE("(%p)->(%d,%d)-(%d,%d)\n", This,
1461 Rect->left, Rect->top, Rect->right, Rect->bottom);
1463 /* The sizes might be reversed */
1464 if(Rect->left > Rect->right) {
1465 x1 = Rect->right;
1466 x2 = Rect->left;
1468 if(Rect->top > Rect->bottom) {
1469 y1 = Rect->bottom;
1470 y2 = Rect->top;
1473 /* No oversized texture? This is easy */
1474 if(!(This->Flags & SFLAG_OVERSIZE)) {
1475 /* Which rect from the texture do I need? */
1476 if(This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB) {
1477 glTexCoord[0] = (float) Rect->left;
1478 glTexCoord[2] = (float) Rect->top;
1479 glTexCoord[1] = (float) Rect->right;
1480 glTexCoord[3] = (float) Rect->bottom;
1481 } else {
1482 glTexCoord[0] = (float) Rect->left / (float) This->pow2Width;
1483 glTexCoord[2] = (float) Rect->top / (float) This->pow2Height;
1484 glTexCoord[1] = (float) Rect->right / (float) This->pow2Width;
1485 glTexCoord[3] = (float) Rect->bottom / (float) This->pow2Height;
1488 return TRUE;
1489 } else {
1490 /* Check if we can succeed at all */
1491 if( (x2 - x1) > maxSize ||
1492 (y2 - y1) > maxSize ) {
1493 TRACE("Requested rectangle is too large for gl\n");
1494 return FALSE;
1497 /* A part of the texture has to be picked. First, check if
1498 * some texture part is loaded already, if yes try to re-use it.
1499 * If the texture is dirty, or the part can't be used,
1500 * re-position the part to load
1502 if(This->Flags & SFLAG_INTEXTURE) {
1503 if(This->glRect.left <= x1 && This->glRect.right >= x2 &&
1504 This->glRect.top <= y1 && This->glRect.bottom >= x2 ) {
1505 /* Ok, the rectangle is ok, re-use it */
1506 TRACE("Using existing gl Texture\n");
1507 } else {
1508 /* Rectangle is not ok, dirtify the texture to reload it */
1509 TRACE("Dirtifying texture to force reload\n");
1510 This->Flags &= ~SFLAG_INTEXTURE;
1514 /* Now if we are dirty(no else if!) */
1515 if(!(This->Flags & SFLAG_INTEXTURE)) {
1516 /* Set the new rectangle. Use the following strategy:
1517 * 1) Use as big textures as possible.
1518 * 2) Place the texture part in the way that the requested
1519 * part is in the middle of the texture(well, almost)
1520 * 3) If the texture is moved over the edges of the
1521 * surface, replace it nicely
1522 * 4) If the coord is not limiting the texture size,
1523 * use the whole size
1525 if((This->pow2Width) > maxSize) {
1526 This->glRect.left = x1 - maxSize / 2;
1527 if(This->glRect.left < 0) {
1528 This->glRect.left = 0;
1530 This->glRect.right = This->glRect.left + maxSize;
1531 if(This->glRect.right > This->currentDesc.Width) {
1532 This->glRect.right = This->currentDesc.Width;
1533 This->glRect.left = This->glRect.right - maxSize;
1535 } else {
1536 This->glRect.left = 0;
1537 This->glRect.right = This->pow2Width;
1540 if(This->pow2Height > maxSize) {
1541 This->glRect.top = x1 - GL_LIMITS(texture_size) / 2;
1542 if(This->glRect.top < 0) This->glRect.top = 0;
1543 This->glRect.bottom = This->glRect.left + maxSize;
1544 if(This->glRect.bottom > This->currentDesc.Height) {
1545 This->glRect.bottom = This->currentDesc.Height;
1546 This->glRect.top = This->glRect.bottom - maxSize;
1548 } else {
1549 This->glRect.top = 0;
1550 This->glRect.bottom = This->pow2Height;
1552 TRACE("(%p): Using rect (%d,%d)-(%d,%d)\n", This,
1553 This->glRect.left, This->glRect.top, This->glRect.right, This->glRect.bottom);
1556 /* Re-calculate the rect to draw */
1557 Rect->left -= This->glRect.left;
1558 Rect->right -= This->glRect.left;
1559 Rect->top -= This->glRect.top;
1560 Rect->bottom -= This->glRect.top;
1562 /* Get the gl coordinates. The gl rectangle is a power of 2, eigher the max size,
1563 * or the pow2Width / pow2Height of the surface.
1565 * Can never be GL_TEXTURE_RECTANGLE_ARB because oversized surfaces are always set up
1566 * as regular GL_TEXTURE_2D.
1568 glTexCoord[0] = (float) Rect->left / (float) (This->glRect.right - This->glRect.left);
1569 glTexCoord[2] = (float) Rect->top / (float) (This->glRect.bottom - This->glRect.top);
1570 glTexCoord[1] = (float) Rect->right / (float) (This->glRect.right - This->glRect.left);
1571 glTexCoord[3] = (float) Rect->bottom / (float) (This->glRect.bottom - This->glRect.top);
1573 return TRUE;
1575 #undef GLINFO_LOCATION
1577 /* Hash table functions */
1579 struct hash_table_t *hash_table_create(hash_function_t *hash_function, compare_function_t *compare_function)
1581 struct hash_table_t *table;
1582 unsigned int initial_size = 8;
1584 table = HeapAlloc(GetProcessHeap(), 0, sizeof(struct hash_table_t) + (initial_size * sizeof(struct list)));
1585 if (!table)
1587 ERR("Failed to allocate table, returning NULL.\n");
1588 return NULL;
1591 table->hash_function = hash_function;
1592 table->compare_function = compare_function;
1594 table->grow_size = initial_size - (initial_size >> 2);
1595 table->shrink_size = 0;
1597 table->buckets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, initial_size * sizeof(struct list));
1598 if (!table->buckets)
1600 ERR("Failed to allocate table buckets, returning NULL.\n");
1601 HeapFree(GetProcessHeap(), 0, table);
1602 return NULL;
1604 table->bucket_count = initial_size;
1606 table->entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, table->grow_size * sizeof(struct hash_table_entry_t));
1607 if (!table->entries)
1609 ERR("Failed to allocate table entries, returning NULL.\n");
1610 HeapFree(GetProcessHeap(), 0, table->buckets);
1611 HeapFree(GetProcessHeap(), 0, table);
1612 return NULL;
1614 table->entry_count = 0;
1616 list_init(&table->free_entries);
1617 table->count = 0;
1619 return table;
1622 void hash_table_destroy(struct hash_table_t *table, void (*free_value)(void *value, void *cb), void *cb)
1624 unsigned int i = 0;
1626 for (i = 0; i < table->entry_count; ++i)
1628 if(free_value) {
1629 free_value(table->entries[i].value, cb);
1631 HeapFree(GetProcessHeap(), 0, table->entries[i].key);
1634 HeapFree(GetProcessHeap(), 0, table->entries);
1635 HeapFree(GetProcessHeap(), 0, table->buckets);
1636 HeapFree(GetProcessHeap(), 0, table);
1639 static inline struct hash_table_entry_t *hash_table_get_by_idx(struct hash_table_t *table, void *key, unsigned int idx)
1641 struct hash_table_entry_t *entry;
1643 if (table->buckets[idx].next)
1644 LIST_FOR_EACH_ENTRY(entry, &(table->buckets[idx]), struct hash_table_entry_t, entry)
1645 if (table->compare_function(entry->key, key)) return entry;
1647 return NULL;
1650 static BOOL hash_table_resize(struct hash_table_t *table, unsigned int new_bucket_count)
1652 unsigned int new_entry_count = 0;
1653 struct hash_table_entry_t *new_entries;
1654 struct list *new_buckets;
1655 unsigned int grow_size = new_bucket_count - (new_bucket_count >> 2);
1656 unsigned int i;
1658 new_buckets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, new_bucket_count * sizeof(struct list));
1659 if (!new_buckets)
1661 ERR("Failed to allocate new buckets, returning FALSE.\n");
1662 return FALSE;
1665 new_entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, grow_size * sizeof(struct hash_table_entry_t));
1666 if (!new_entries)
1668 ERR("Failed to allocate new entries, returning FALSE.\n");
1669 HeapFree(GetProcessHeap(), 0, new_buckets);
1670 return FALSE;
1673 for (i = 0; i < table->bucket_count; ++i)
1675 if (table->buckets[i].next)
1677 struct hash_table_entry_t *entry, *entry2;
1679 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &table->buckets[i], struct hash_table_entry_t, entry)
1681 int j;
1682 struct hash_table_entry_t *new_entry = new_entries + (new_entry_count++);
1683 *new_entry = *entry;
1685 j = new_entry->hash & (new_bucket_count - 1);
1687 if (!new_buckets[j].next) list_init(&new_buckets[j]);
1688 list_add_head(&new_buckets[j], &new_entry->entry);
1693 HeapFree(GetProcessHeap(), 0, table->buckets);
1694 table->buckets = new_buckets;
1696 HeapFree(GetProcessHeap(), 0, table->entries);
1697 table->entries = new_entries;
1699 table->entry_count = new_entry_count;
1700 list_init(&table->free_entries);
1702 table->bucket_count = new_bucket_count;
1703 table->grow_size = grow_size;
1704 table->shrink_size = new_bucket_count > 8 ? new_bucket_count >> 2 : 0;
1706 return TRUE;
1709 void hash_table_put(struct hash_table_t *table, void *key, void *value)
1711 unsigned int idx;
1712 unsigned int hash;
1713 struct hash_table_entry_t *entry;
1715 hash = table->hash_function(key);
1716 idx = hash & (table->bucket_count - 1);
1717 entry = hash_table_get_by_idx(table, key, idx);
1719 if (entry)
1721 HeapFree(GetProcessHeap(), 0, key);
1722 entry->value = value;
1724 if (!value)
1726 HeapFree(GetProcessHeap(), 0, entry->key);
1727 entry->key = NULL;
1729 /* Remove the entry */
1730 list_remove(&entry->entry);
1731 list_add_head(&table->free_entries, &entry->entry);
1733 --table->count;
1735 /* Shrink if necessary */
1736 if (table->count < table->shrink_size) {
1737 if (!hash_table_resize(table, table->bucket_count >> 1))
1739 ERR("Failed to shrink the table...\n");
1744 return;
1747 if (!value) return;
1749 /* Grow if necessary */
1750 if (table->count >= table->grow_size)
1752 if (!hash_table_resize(table, table->bucket_count << 1))
1754 ERR("Failed to grow the table, returning.\n");
1755 return;
1758 idx = hash & (table->bucket_count - 1);
1761 /* Find an entry to insert */
1762 if (!list_empty(&table->free_entries))
1764 struct list *elem = list_head(&table->free_entries);
1766 list_remove(elem);
1767 entry = LIST_ENTRY(elem, struct hash_table_entry_t, entry);
1768 } else {
1769 entry = table->entries + (table->entry_count++);
1772 /* Insert the entry */
1773 entry->key = key;
1774 entry->value = value;
1775 entry->hash = hash;
1776 if (!table->buckets[idx].next) list_init(&table->buckets[idx]);
1777 list_add_head(&table->buckets[idx], &entry->entry);
1779 ++table->count;
1782 void hash_table_remove(struct hash_table_t *table, void *key)
1784 hash_table_put(table, key, NULL);
1787 void *hash_table_get(struct hash_table_t *table, void *key)
1789 unsigned int idx;
1790 struct hash_table_entry_t *entry;
1792 idx = table->hash_function(key) & (table->bucket_count - 1);
1793 entry = hash_table_get_by_idx(table, key, idx);
1795 return entry ? entry->value : NULL;
1798 #define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
1799 void gen_ffp_op(IWineD3DStateBlockImpl *stateblock, struct ffp_settings *settings, BOOL ignore_textype) {
1800 #define ARG1 0x01
1801 #define ARG2 0x02
1802 #define ARG0 0x04
1803 static const unsigned char args[WINED3DTOP_LERP + 1] = {
1804 /* undefined */ 0,
1805 /* D3DTOP_DISABLE */ 0,
1806 /* D3DTOP_SELECTARG1 */ ARG1,
1807 /* D3DTOP_SELECTARG2 */ ARG2,
1808 /* D3DTOP_MODULATE */ ARG1 | ARG2,
1809 /* D3DTOP_MODULATE2X */ ARG1 | ARG2,
1810 /* D3DTOP_MODULATE4X */ ARG1 | ARG2,
1811 /* D3DTOP_ADD */ ARG1 | ARG2,
1812 /* D3DTOP_ADDSIGNED */ ARG1 | ARG2,
1813 /* D3DTOP_ADDSIGNED2X */ ARG1 | ARG2,
1814 /* D3DTOP_SUBTRACT */ ARG1 | ARG2,
1815 /* D3DTOP_ADDSMOOTH */ ARG1 | ARG2,
1816 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1 | ARG2,
1817 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1 | ARG2,
1818 /* D3DTOP_BLENDFACTORALPHA */ ARG1 | ARG2,
1819 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1 | ARG2,
1820 /* D3DTOP_BLENDCURRENTALPHA */ ARG1 | ARG2,
1821 /* D3DTOP_PREMODULATE */ ARG1 | ARG2,
1822 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1 | ARG2,
1823 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1 | ARG2,
1824 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1 | ARG2,
1825 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1 | ARG2,
1826 /* D3DTOP_BUMPENVMAP */ ARG1 | ARG2,
1827 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1 | ARG2,
1828 /* D3DTOP_DOTPRODUCT3 */ ARG1 | ARG2,
1829 /* D3DTOP_MULTIPLYADD */ ARG1 | ARG2 | ARG0,
1830 /* D3DTOP_LERP */ ARG1 | ARG2 | ARG0
1832 unsigned int i;
1833 DWORD ttff;
1834 DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2;
1836 for(i = 0; i < GL_LIMITS(texture_stages); i++) {
1837 IWineD3DBaseTextureImpl *texture;
1838 settings->op[i].padding = 0;
1839 if(stateblock->textureState[i][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
1840 settings->op[i].cop = WINED3DTOP_DISABLE;
1841 settings->op[i].aop = WINED3DTOP_DISABLE;
1842 settings->op[i].carg0 = settings->op[i].carg1 = settings->op[i].carg2 = ARG_UNUSED;
1843 settings->op[i].aarg0 = settings->op[i].aarg1 = settings->op[i].aarg2 = ARG_UNUSED;
1844 settings->op[i].color_correction = WINED3DFMT_UNKNOWN;
1845 settings->op[i].dst = resultreg;
1846 settings->op[i].tex_type = tex_1d;
1847 settings->op[i].projected = proj_none;
1848 i++;
1849 break;
1852 texture = (IWineD3DBaseTextureImpl *) stateblock->textures[i];
1853 if(texture) {
1854 settings->op[i].color_correction = texture->baseTexture.shader_conversion_group;
1855 if(ignore_textype) {
1856 settings->op[i].tex_type = tex_1d;
1857 } else {
1858 switch(stateblock->textureDimensions[i]) {
1859 case GL_TEXTURE_1D:
1860 settings->op[i].tex_type = tex_1d;
1861 break;
1862 case GL_TEXTURE_2D:
1863 settings->op[i].tex_type = tex_2d;
1864 break;
1865 case GL_TEXTURE_3D:
1866 settings->op[i].tex_type = tex_3d;
1867 break;
1868 case GL_TEXTURE_CUBE_MAP_ARB:
1869 settings->op[i].tex_type = tex_cube;
1870 break;
1871 case GL_TEXTURE_RECTANGLE_ARB:
1872 settings->op[i].tex_type = tex_rect;
1873 break;
1876 } else {
1877 settings->op[i].color_correction = WINED3DFMT_UNKNOWN;
1878 settings->op[i].tex_type = tex_1d;
1881 cop = stateblock->textureState[i][WINED3DTSS_COLOROP];
1882 aop = stateblock->textureState[i][WINED3DTSS_ALPHAOP];
1884 carg1 = (args[cop] & ARG1) ? stateblock->textureState[i][WINED3DTSS_COLORARG1] : 0xffffffff;
1885 carg2 = (args[cop] & ARG2) ? stateblock->textureState[i][WINED3DTSS_COLORARG2] : 0xffffffff;
1886 carg0 = (args[cop] & ARG0) ? stateblock->textureState[i][WINED3DTSS_COLORARG0] : 0xffffffff;
1888 if(is_invalid_op(stateblock->wineD3DDevice, i, cop,
1889 carg1, carg2, carg0)) {
1890 carg0 = 0xffffffff;
1891 carg2 = 0xffffffff;
1892 carg1 = WINED3DTA_CURRENT;
1893 cop = WINED3DTOP_SELECTARG1;
1896 if(cop == WINED3DTOP_DOTPRODUCT3) {
1897 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
1898 * the color result to the alpha component of the destination
1900 aop = cop;
1901 aarg1 = carg1;
1902 aarg2 = carg2;
1903 aarg0 = carg0;
1904 } else {
1905 aarg1 = (args[aop] & ARG1) ? stateblock->textureState[i][WINED3DTSS_ALPHAARG1] : 0xffffffff;
1906 aarg2 = (args[aop] & ARG2) ? stateblock->textureState[i][WINED3DTSS_ALPHAARG2] : 0xffffffff;
1907 aarg0 = (args[aop] & ARG0) ? stateblock->textureState[i][WINED3DTSS_ALPHAARG0] : 0xffffffff;
1910 if(i == 0 && stateblock->textures[0] &&
1911 stateblock->renderState[WINED3DRS_COLORKEYENABLE] &&
1912 (stateblock->textureDimensions[0] == GL_TEXTURE_2D ||
1913 stateblock->textureDimensions[0] == GL_TEXTURE_RECTANGLE_ARB)) {
1914 IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *) stateblock->textures[0])->surfaces[0];
1916 if(surf->CKeyFlags & WINEDDSD_CKSRCBLT &&
1917 getFormatDescEntry(surf->resource.format, NULL, NULL)->alphaMask == 0x00000000) {
1919 if(aop == WINED3DTOP_DISABLE) {
1920 aarg1 = WINED3DTA_TEXTURE;
1921 aop = WINED3DTOP_SELECTARG1;
1923 else if(aop == WINED3DTOP_SELECTARG1 && aarg1 != WINED3DTA_TEXTURE) {
1924 if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE]) {
1925 aarg2 = WINED3DTA_TEXTURE;
1926 aop = WINED3DTOP_MODULATE;
1928 else aarg1 = WINED3DTA_TEXTURE;
1930 else if(aop == WINED3DTOP_SELECTARG2 && aarg2 != WINED3DTA_TEXTURE) {
1931 if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE]) {
1932 aarg1 = WINED3DTA_TEXTURE;
1933 aop = WINED3DTOP_MODULATE;
1935 else aarg2 = WINED3DTA_TEXTURE;
1940 if(is_invalid_op(stateblock->wineD3DDevice, i, aop,
1941 aarg1, aarg2, aarg0)) {
1942 aarg0 = 0xffffffff;
1943 aarg2 = 0xffffffff;
1944 aarg1 = WINED3DTA_CURRENT;
1945 aop = WINED3DTOP_SELECTARG1;
1948 if(carg1 == WINED3DTA_TEXTURE || carg2 == WINED3DTA_TEXTURE || carg0 == WINED3DTA_TEXTURE ||
1949 aarg1 == WINED3DTA_TEXTURE || aarg2 == WINED3DTA_TEXTURE || aarg0 == WINED3DTA_TEXTURE) {
1950 ttff = stateblock->textureState[i][WINED3DTSS_TEXTURETRANSFORMFLAGS];
1951 if(ttff == (WINED3DTTFF_PROJECTED | WINED3DTTFF_COUNT3)) {
1952 settings->op[i].projected = proj_count3;
1953 } else if(ttff == (WINED3DTTFF_PROJECTED | WINED3DTTFF_COUNT4)) {
1954 settings->op[i].projected = proj_count4;
1955 } else {
1956 settings->op[i].projected = proj_none;
1958 } else {
1959 settings->op[i].projected = proj_none;
1962 settings->op[i].cop = cop;
1963 settings->op[i].aop = aop;
1964 settings->op[i].carg0 = carg0;
1965 settings->op[i].carg1 = carg1;
1966 settings->op[i].carg2 = carg2;
1967 settings->op[i].aarg0 = aarg0;
1968 settings->op[i].aarg1 = aarg1;
1969 settings->op[i].aarg2 = aarg2;
1971 if(stateblock->textureState[i][WINED3DTSS_RESULTARG] == WINED3DTA_TEMP) {
1972 settings->op[i].dst = tempreg;
1973 } else {
1974 settings->op[i].dst = resultreg;
1978 /* Clear unsupported stages */
1979 for(; i < MAX_TEXTURES; i++) {
1980 memset(&settings->op[i], 0xff, sizeof(settings->op[i]));
1983 if(stateblock->renderState[WINED3DRS_FOGENABLE] == FALSE) {
1984 settings->fog = FOG_OFF;
1985 } else if(stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) {
1986 switch(stateblock->renderState[WINED3DRS_FOGVERTEXMODE]) {
1987 case WINED3DFOG_NONE:
1988 case WINED3DFOG_LINEAR:
1989 settings->fog = FOG_LINEAR;
1990 break;
1991 case WINED3DFOG_EXP:
1992 settings->fog = FOG_EXP;
1993 break;
1994 case WINED3DFOG_EXP2:
1995 settings->fog = FOG_EXP2;
1996 break;
1998 } else {
1999 switch(stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
2000 case WINED3DFOG_LINEAR:
2001 settings->fog = FOG_LINEAR;
2002 break;
2003 case WINED3DFOG_EXP:
2004 settings->fog = FOG_EXP;
2005 break;
2006 case WINED3DFOG_EXP2:
2007 settings->fog = FOG_EXP2;
2008 break;
2011 if(stateblock->renderState[WINED3DRS_SRGBWRITEENABLE]) {
2012 settings->sRGB_write = 1;
2013 } else {
2014 settings->sRGB_write = 0;
2017 #undef GLINFO_LOCATION
2019 struct ffp_desc *find_ffp_shader(struct hash_table_t *fragment_shaders, struct ffp_settings *settings)
2021 return (struct ffp_desc *)hash_table_get(fragment_shaders, settings);}
2023 void add_ffp_shader(struct hash_table_t *shaders, struct ffp_desc *desc) {
2024 struct ffp_settings *key = HeapAlloc(GetProcessHeap(), 0, sizeof(*key));
2025 /* Note that the key is the implementation independent part of the ffp_desc structure,
2026 * whereas desc points to an extended structure with implementation specific parts.
2027 * Make a copy of the key because hash_table_put takes ownership of it
2029 *key = desc->settings;
2030 hash_table_put(shaders, key, desc);
2033 /* Activates the texture dimension according to the bound D3D texture.
2034 * Does not care for the colorop or correct gl texture unit(when using nvrc)
2035 * Requires the caller to activate the correct unit before
2037 #define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
2038 void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2039 if(stateblock->textures[stage]) {
2040 switch(stateblock->textureDimensions[stage]) {
2041 case GL_TEXTURE_2D:
2042 glDisable(GL_TEXTURE_3D);
2043 checkGLcall("glDisable(GL_TEXTURE_3D)");
2044 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2045 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
2046 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
2048 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
2049 glDisable(GL_TEXTURE_RECTANGLE_ARB);
2050 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
2052 glEnable(GL_TEXTURE_2D);
2053 checkGLcall("glEnable(GL_TEXTURE_2D)");
2054 break;
2055 case GL_TEXTURE_RECTANGLE_ARB:
2056 glDisable(GL_TEXTURE_2D);
2057 checkGLcall("glDisable(GL_TEXTURE_2D)");
2058 glDisable(GL_TEXTURE_3D);
2059 checkGLcall("glDisable(GL_TEXTURE_3D)");
2060 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2061 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
2062 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
2064 glEnable(GL_TEXTURE_RECTANGLE_ARB);
2065 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
2066 break;
2067 case GL_TEXTURE_3D:
2068 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2069 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
2070 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
2072 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
2073 glDisable(GL_TEXTURE_RECTANGLE_ARB);
2074 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
2076 glDisable(GL_TEXTURE_2D);
2077 checkGLcall("glDisable(GL_TEXTURE_2D)");
2078 glEnable(GL_TEXTURE_3D);
2079 checkGLcall("glEnable(GL_TEXTURE_3D)");
2080 break;
2081 case GL_TEXTURE_CUBE_MAP_ARB:
2082 glDisable(GL_TEXTURE_2D);
2083 checkGLcall("glDisable(GL_TEXTURE_2D)");
2084 glDisable(GL_TEXTURE_3D);
2085 checkGLcall("glDisable(GL_TEXTURE_3D)");
2086 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
2087 glDisable(GL_TEXTURE_RECTANGLE_ARB);
2088 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
2090 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
2091 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
2092 break;
2094 } else {
2095 glEnable(GL_TEXTURE_2D);
2096 checkGLcall("glEnable(GL_TEXTURE_2D)");
2097 glDisable(GL_TEXTURE_3D);
2098 checkGLcall("glDisable(GL_TEXTURE_3D)");
2099 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2100 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
2101 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
2103 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
2104 glDisable(GL_TEXTURE_RECTANGLE_ARB);
2105 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
2107 /* Binding textures is done by samplers. A dummy texture will be bound */
2111 void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
2112 DWORD sampler = state - STATE_SAMPLER(0);
2113 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
2115 /* No need to enable / disable anything here for unused samplers. The tex_colorop
2116 * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
2117 * will take care of this business
2119 if(mapped_stage == -1 || mapped_stage >= GL_LIMITS(textures)) return;
2120 if(sampler >= stateblock->lowest_disabled_stage) return;
2121 if(isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return;
2123 texture_activate_dimensions(sampler, stateblock, context);
2125 #undef GLINFO_LOCATION
2127 unsigned int ffp_program_key_hash(void *key) {
2128 struct ffp_settings *k = (struct ffp_settings *)key;
2129 unsigned int hash = 0, i;
2130 DWORD *blob;
2132 /* This takes the texture op settings of stage 0 and 1 into account.
2133 * how exactly depends on the memory laybout of the compiler, but it
2134 * should not matter too much. Stages > 1 are used rarely, so there's
2135 * no need to process them. Even if they're used it is likely that
2136 * the ffp setup has distinct stage 0 and 1 settings.
2138 for(i = 0; i < 2; i++) {
2139 blob = (DWORD *) &k->op[i];
2140 hash ^= blob[0] ^ blob[1];
2143 hash += ~(hash << 15);
2144 hash ^= (hash >> 10);
2145 hash += (hash << 3);
2146 hash ^= (hash >> 6);
2147 hash += ~(hash << 11);
2148 hash ^= (hash >> 16);
2150 return hash;
2153 BOOL ffp_program_key_compare(void *keya, void *keyb) {
2154 struct ffp_settings *ka = (struct ffp_settings *)keya;
2155 struct ffp_settings *kb = (struct ffp_settings *)keyb;
2157 return memcmp(ka, kb, sizeof(*ka)) == 0;