Sync to trunk revision 61757.
[reactos.git] / dll / directx / wine / d3d8 / d3d8_private.h
1 /*
2 * Direct3D 8 private include file
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #ifndef __WINE_D3D8_PRIVATE_H
24 #define __WINE_D3D8_PRIVATE_H
25
26 #include <config.h>
27
28 #include <assert.h>
29 #include <stdarg.h>
30
31 #define WIN32_NO_STATUS
32 #define _INC_WINDOWS
33 #define COM_NO_WINDOWS_H
34
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
37 #define COBJMACROS
38
39 #include <windef.h>
40 #include <winbase.h>
41 #include <wingdi.h>
42
43 #include <wine/debug.h>
44 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
45
46 #include <d3d8.h>
47 #include <wine/wined3d.h>
48
49 /* CreateVertexShader can return > 0xFFFF */
50 #define VS_HIGHESTFIXEDFXF 0xF0000000
51
52 /* ===========================================================================
53 Macros
54 =========================================================================== */
55 /* Not nice, but it lets wined3d support different versions of directx */
56 #define WINECAPSTOD3D8CAPS(_pD3D8Caps, _pWineCaps) \
57 _pD3D8Caps->DeviceType = (D3DDEVTYPE) _pWineCaps->DeviceType; \
58 _pD3D8Caps->AdapterOrdinal = _pWineCaps->AdapterOrdinal; \
59 _pD3D8Caps->Caps = _pWineCaps->Caps; \
60 _pD3D8Caps->Caps2 = _pWineCaps->Caps2; \
61 _pD3D8Caps->Caps3 = _pWineCaps->Caps3; \
62 _pD3D8Caps->PresentationIntervals = _pWineCaps->PresentationIntervals; \
63 _pD3D8Caps->CursorCaps = _pWineCaps->CursorCaps; \
64 _pD3D8Caps->DevCaps = _pWineCaps->DevCaps; \
65 _pD3D8Caps->PrimitiveMiscCaps = _pWineCaps->PrimitiveMiscCaps; \
66 _pD3D8Caps->RasterCaps = _pWineCaps->RasterCaps; \
67 _pD3D8Caps->ZCmpCaps = _pWineCaps->ZCmpCaps; \
68 _pD3D8Caps->SrcBlendCaps = _pWineCaps->SrcBlendCaps; \
69 _pD3D8Caps->DestBlendCaps = _pWineCaps->DestBlendCaps; \
70 _pD3D8Caps->AlphaCmpCaps = _pWineCaps->AlphaCmpCaps; \
71 _pD3D8Caps->ShadeCaps = _pWineCaps->ShadeCaps; \
72 _pD3D8Caps->TextureCaps = _pWineCaps->TextureCaps; \
73 _pD3D8Caps->TextureFilterCaps = _pWineCaps->TextureFilterCaps; \
74 _pD3D8Caps->CubeTextureFilterCaps = _pWineCaps->CubeTextureFilterCaps; \
75 _pD3D8Caps->VolumeTextureFilterCaps = _pWineCaps->VolumeTextureFilterCaps; \
76 _pD3D8Caps->TextureAddressCaps = _pWineCaps->TextureAddressCaps; \
77 _pD3D8Caps->VolumeTextureAddressCaps = _pWineCaps->VolumeTextureAddressCaps; \
78 _pD3D8Caps->LineCaps = _pWineCaps->LineCaps; \
79 _pD3D8Caps->MaxTextureWidth = _pWineCaps->MaxTextureWidth; \
80 _pD3D8Caps->MaxTextureHeight = _pWineCaps->MaxTextureHeight; \
81 _pD3D8Caps->MaxVolumeExtent = _pWineCaps->MaxVolumeExtent; \
82 _pD3D8Caps->MaxTextureRepeat = _pWineCaps->MaxTextureRepeat; \
83 _pD3D8Caps->MaxTextureAspectRatio = _pWineCaps->MaxTextureAspectRatio; \
84 _pD3D8Caps->MaxAnisotropy = _pWineCaps->MaxAnisotropy; \
85 _pD3D8Caps->MaxVertexW = _pWineCaps->MaxVertexW; \
86 _pD3D8Caps->GuardBandLeft = _pWineCaps->GuardBandLeft; \
87 _pD3D8Caps->GuardBandTop = _pWineCaps->GuardBandTop; \
88 _pD3D8Caps->GuardBandRight = _pWineCaps->GuardBandRight; \
89 _pD3D8Caps->GuardBandBottom = _pWineCaps->GuardBandBottom; \
90 _pD3D8Caps->ExtentsAdjust = _pWineCaps->ExtentsAdjust; \
91 _pD3D8Caps->StencilCaps = _pWineCaps->StencilCaps; \
92 _pD3D8Caps->FVFCaps = _pWineCaps->FVFCaps; \
93 _pD3D8Caps->TextureOpCaps = _pWineCaps->TextureOpCaps; \
94 _pD3D8Caps->MaxTextureBlendStages = _pWineCaps->MaxTextureBlendStages; \
95 _pD3D8Caps->MaxSimultaneousTextures = _pWineCaps->MaxSimultaneousTextures; \
96 _pD3D8Caps->VertexProcessingCaps = _pWineCaps->VertexProcessingCaps; \
97 _pD3D8Caps->MaxActiveLights = _pWineCaps->MaxActiveLights; \
98 _pD3D8Caps->MaxUserClipPlanes = _pWineCaps->MaxUserClipPlanes; \
99 _pD3D8Caps->MaxVertexBlendMatrices = _pWineCaps->MaxVertexBlendMatrices; \
100 _pD3D8Caps->MaxVertexBlendMatrixIndex = _pWineCaps->MaxVertexBlendMatrixIndex; \
101 _pD3D8Caps->MaxPointSize = _pWineCaps->MaxPointSize; \
102 _pD3D8Caps->MaxPrimitiveCount = _pWineCaps->MaxPrimitiveCount; \
103 _pD3D8Caps->MaxVertexIndex = _pWineCaps->MaxVertexIndex; \
104 _pD3D8Caps->MaxStreams = _pWineCaps->MaxStreams; \
105 _pD3D8Caps->MaxStreamStride = _pWineCaps->MaxStreamStride; \
106 _pD3D8Caps->VertexShaderVersion = _pWineCaps->VertexShaderVersion; \
107 _pD3D8Caps->MaxVertexShaderConst = _pWineCaps->MaxVertexShaderConst; \
108 _pD3D8Caps->PixelShaderVersion = _pWineCaps->PixelShaderVersion; \
109 _pD3D8Caps->MaxPixelShaderValue = _pWineCaps->PixelShader1xMaxValue;
110
111 void fixup_caps(WINED3DCAPS *pWineCaps) DECLSPEC_HIDDEN;
112
113 struct d3d8
114 {
115 IDirect3D8 IDirect3D8_iface;
116 LONG refcount;
117 struct wined3d *wined3d;
118 };
119
120 BOOL d3d8_init(struct d3d8 *d3d8) DECLSPEC_HIDDEN;
121
122 /*****************************************************************************
123 * IDirect3DDevice8 implementation structure
124 */
125
126 #define D3D8_INITIAL_HANDLE_TABLE_SIZE 64
127 #define D3D8_INVALID_HANDLE ~0U
128
129 enum d3d8_handle_type
130 {
131 D3D8_HANDLE_FREE,
132 D3D8_HANDLE_VS,
133 D3D8_HANDLE_PS,
134 D3D8_HANDLE_SB,
135 };
136
137 struct d3d8_handle_entry
138 {
139 void *object;
140 enum d3d8_handle_type type;
141 };
142
143 struct d3d8_handle_table
144 {
145 struct d3d8_handle_entry *entries;
146 struct d3d8_handle_entry *free_entries;
147 UINT table_size;
148 UINT entry_count;
149 };
150
151 struct FvfToDecl
152 {
153 DWORD fvf;
154 struct d3d8_vertex_declaration *declaration;
155 };
156
157 struct d3d8_device
158 {
159 /* IUnknown fields */
160 IDirect3DDevice8 IDirect3DDevice8_iface;
161 struct wined3d_device_parent device_parent;
162 LONG ref;
163 struct wined3d_device *wined3d_device;
164 IDirect3D8 *d3d_parent;
165 struct d3d8_handle_table handle_table;
166
167 /* FVF management */
168 struct FvfToDecl *decls;
169 UINT numConvertedDecls, declArraySize;
170
171 /* User data draws */
172 struct wined3d_buffer *vertex_buffer;
173 UINT vertex_buffer_size;
174 UINT vertex_buffer_pos;
175 struct wined3d_buffer *index_buffer;
176 UINT index_buffer_size;
177 UINT index_buffer_pos;
178
179 /* Avoids recursion with nested ReleaseRef to 0 */
180 BOOL inDestruction;
181 BOOL lost;
182 };
183
184 HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter,
185 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
186
187 struct d3d8_volume
188 {
189 IDirect3DVolume8 IDirect3DVolume8_iface;
190 LONG refcount;
191 struct wined3d_volume *wined3d_volume;
192 IUnknown *container;
193 IUnknown *forwardReference;
194 };
195
196 HRESULT volume_init(struct d3d8_volume *volume, struct d3d8_device *device, UINT width, UINT height,
197 UINT depth, UINT level, DWORD usage, enum wined3d_format_id format,
198 enum wined3d_pool pool) DECLSPEC_HIDDEN;
199
200 struct d3d8_swapchain
201 {
202 IDirect3DSwapChain8 IDirect3DSwapChain8_iface;
203 LONG refcount;
204 struct wined3d_swapchain *wined3d_swapchain;
205 IDirect3DDevice8 *parent_device;
206 };
207
208 HRESULT d3d8_swapchain_create(struct d3d8_device *device, struct wined3d_swapchain_desc *desc,
209 struct d3d8_swapchain **swapchain) DECLSPEC_HIDDEN;
210
211 struct d3d8_surface
212 {
213 IDirect3DSurface8 IDirect3DSurface8_iface;
214 LONG refcount;
215 struct wined3d_surface *wined3d_surface;
216 IDirect3DDevice8 *parent_device;
217
218 /* The surface container */
219 IUnknown *container;
220
221 /* If set forward refcounting to this object */
222 IUnknown *forwardReference;
223 };
224
225 HRESULT surface_init(struct d3d8_surface *surface, struct d3d8_device *device, UINT width, UINT height,
226 D3DFORMAT format, DWORD flags, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type,
227 DWORD multisample_quality) DECLSPEC_HIDDEN;
228 struct d3d8_surface *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface) DECLSPEC_HIDDEN;
229
230 struct d3d8_vertexbuffer
231 {
232 IDirect3DVertexBuffer8 IDirect3DVertexBuffer8_iface;
233 LONG refcount;
234 struct wined3d_buffer *wined3d_buffer;
235 IDirect3DDevice8 *parent_device;
236 DWORD fvf;
237 };
238
239 HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *device,
240 UINT size, DWORD usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
241 struct d3d8_vertexbuffer *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface) DECLSPEC_HIDDEN;
242
243 struct d3d8_indexbuffer
244 {
245 IDirect3DIndexBuffer8 IDirect3DIndexBuffer8_iface;
246 LONG refcount;
247 struct wined3d_buffer *wined3d_buffer;
248 IDirect3DDevice8 *parent_device;
249 enum wined3d_format_id format;
250 };
251
252 HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *device,
253 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
254 struct d3d8_indexbuffer *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface) DECLSPEC_HIDDEN;
255
256 struct d3d8_texture
257 {
258 IDirect3DBaseTexture8 IDirect3DBaseTexture8_iface;
259 LONG refcount;
260 struct wined3d_texture *wined3d_texture;
261 IDirect3DDevice8 *parent_device;
262 };
263
264 HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *device,
265 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
266 HRESULT texture_init(struct d3d8_texture *texture, struct d3d8_device *device,
267 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
268 HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *device,
269 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
270 struct d3d8_texture *unsafe_impl_from_IDirect3DBaseTexture8(IDirect3DBaseTexture8 *iface) DECLSPEC_HIDDEN;
271
272 struct d3d8_vertex_declaration
273 {
274 DWORD *elements;
275 DWORD elements_size; /* Size of elements, in bytes */
276 struct wined3d_vertex_declaration *wined3d_vertex_declaration;
277 DWORD shader_handle;
278 };
279
280 void d3d8_vertex_declaration_destroy(struct d3d8_vertex_declaration *declaration) DECLSPEC_HIDDEN;
281 HRESULT d3d8_vertex_declaration_init(struct d3d8_vertex_declaration *declaration,
282 struct d3d8_device *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN;
283 HRESULT d3d8_vertex_declaration_init_fvf(struct d3d8_vertex_declaration *declaration,
284 struct d3d8_device *device, DWORD fvf) DECLSPEC_HIDDEN;
285
286 struct d3d8_vertex_shader
287 {
288 struct d3d8_vertex_declaration *vertex_declaration;
289 struct wined3d_shader *wined3d_shader;
290 };
291
292 void d3d8_vertex_shader_destroy(struct d3d8_vertex_shader *shader) DECLSPEC_HIDDEN;
293 HRESULT d3d8_vertex_shader_init(struct d3d8_vertex_shader *shader, struct d3d8_device *device,
294 const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage) DECLSPEC_HIDDEN;
295
296 #define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
297
298 struct d3d8_pixel_shader
299 {
300 DWORD handle;
301 struct wined3d_shader *wined3d_shader;
302 };
303
304 void d3d8_pixel_shader_destroy(struct d3d8_pixel_shader *shader) DECLSPEC_HIDDEN;
305 HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_device *device,
306 const DWORD *byte_code, DWORD shader_handle) DECLSPEC_HIDDEN;
307
308 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
309 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
310 void load_local_constants(const DWORD *d3d8_elements, struct wined3d_shader *wined3d_vertex_shader) DECLSPEC_HIDDEN;
311 size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN;
312
313 #endif /* __WINE_D3DX8_PRIVATE_H */