1c2c66affSColin Finck /*
2c2c66affSColin Finck * IDirect3DDevice8 implementation
3c2c66affSColin Finck *
4c2c66affSColin Finck * Copyright 2002-2004 Jason Edmeades
5c2c66affSColin Finck * Copyright 2004 Christian Costa
6c2c66affSColin Finck *
7c2c66affSColin Finck * This library is free software; you can redistribute it and/or
8c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
9c2c66affSColin Finck * License as published by the Free Software Foundation; either
10c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
11c2c66affSColin Finck *
12c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
13c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15c2c66affSColin Finck * Lesser General Public License for more details.
16c2c66affSColin Finck *
17c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
18c2c66affSColin Finck * License along with this library; if not, write to the Free Software
19c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20c2c66affSColin Finck */
21c2c66affSColin Finck
229987f029SAmine Khaldi #include "config.h"
239987f029SAmine Khaldi
249987f029SAmine Khaldi #include <math.h>
259987f029SAmine Khaldi #include <stdarg.h>
269987f029SAmine Khaldi
279987f029SAmine Khaldi #include "windef.h"
289987f029SAmine Khaldi #include "winbase.h"
299987f029SAmine Khaldi #include "winuser.h"
309987f029SAmine Khaldi #include "wingdi.h"
319987f029SAmine Khaldi #include "wine/debug.h"
329987f029SAmine Khaldi
33c2c66affSColin Finck #include "d3d8_private.h"
34c2c66affSColin Finck
359987f029SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
369987f029SAmine Khaldi
d3d8_null_wined3d_object_destroyed(void * parent)37c2c66affSColin Finck static void STDMETHODCALLTYPE d3d8_null_wined3d_object_destroyed(void *parent) {}
38c2c66affSColin Finck
39c2c66affSColin Finck static const struct wined3d_parent_ops d3d8_null_wined3d_parent_ops =
40c2c66affSColin Finck {
41c2c66affSColin Finck d3d8_null_wined3d_object_destroyed,
42c2c66affSColin Finck };
43c2c66affSColin Finck
d3dformat_from_wined3dformat(enum wined3d_format_id format)44c2c66affSColin Finck D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format)
45c2c66affSColin Finck {
46c2c66affSColin Finck BYTE *c = (BYTE *)&format;
47c2c66affSColin Finck
48c2c66affSColin Finck /* Don't translate FOURCC formats */
49c2c66affSColin Finck if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
50c2c66affSColin Finck
51c2c66affSColin Finck switch(format)
52c2c66affSColin Finck {
53c2c66affSColin Finck case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
54c2c66affSColin Finck case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
55c2c66affSColin Finck case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
56c2c66affSColin Finck case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
57c2c66affSColin Finck case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
58c2c66affSColin Finck case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
59c2c66affSColin Finck case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
60c2c66affSColin Finck case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
61c2c66affSColin Finck case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
62c2c66affSColin Finck case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
63c2c66affSColin Finck case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
64c2c66affSColin Finck case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
65c2c66affSColin Finck case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
66c2c66affSColin Finck case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
67c2c66affSColin Finck case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
68c2c66affSColin Finck case WINED3DFMT_P8_UINT: return D3DFMT_P8;
69c2c66affSColin Finck case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
70c2c66affSColin Finck case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
71c2c66affSColin Finck case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
72c2c66affSColin Finck case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
73c2c66affSColin Finck case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
74c2c66affSColin Finck case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
75c2c66affSColin Finck case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
76c2c66affSColin Finck case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
77c2c66affSColin Finck case WINED3DFMT_R10G11B11_SNORM: return D3DFMT_W11V11U10;
78c2c66affSColin Finck case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
79c2c66affSColin Finck case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
80c2c66affSColin Finck case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
81c2c66affSColin Finck case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
82c2c66affSColin Finck case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
83c2c66affSColin Finck case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
84c2c66affSColin Finck case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
85c2c66affSColin Finck case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
86c2c66affSColin Finck case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
87c2c66affSColin Finck case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
88c2c66affSColin Finck default:
89c2c66affSColin Finck FIXME("Unhandled wined3d format %#x.\n", format);
90c2c66affSColin Finck return D3DFMT_UNKNOWN;
91c2c66affSColin Finck }
92c2c66affSColin Finck }
93c2c66affSColin Finck
wined3dformat_from_d3dformat(D3DFORMAT format)94c2c66affSColin Finck enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
95c2c66affSColin Finck {
96c2c66affSColin Finck BYTE *c = (BYTE *)&format;
97c2c66affSColin Finck
98c2c66affSColin Finck /* Don't translate FOURCC formats */
99c2c66affSColin Finck if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
100c2c66affSColin Finck
101c2c66affSColin Finck switch(format)
102c2c66affSColin Finck {
103c2c66affSColin Finck case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
104c2c66affSColin Finck case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
105c2c66affSColin Finck case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
106c2c66affSColin Finck case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
107c2c66affSColin Finck case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
108c2c66affSColin Finck case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
109c2c66affSColin Finck case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
110c2c66affSColin Finck case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
111c2c66affSColin Finck case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
112c2c66affSColin Finck case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
113c2c66affSColin Finck case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
114c2c66affSColin Finck case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
115c2c66affSColin Finck case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
116c2c66affSColin Finck case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
117c2c66affSColin Finck case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
118c2c66affSColin Finck case D3DFMT_P8: return WINED3DFMT_P8_UINT;
119c2c66affSColin Finck case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
120c2c66affSColin Finck case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
121c2c66affSColin Finck case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
122c2c66affSColin Finck case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
123c2c66affSColin Finck case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
124c2c66affSColin Finck case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
125c2c66affSColin Finck case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
126c2c66affSColin Finck case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
127c2c66affSColin Finck case D3DFMT_W11V11U10: return WINED3DFMT_R10G11B11_SNORM;
128c2c66affSColin Finck case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
129c2c66affSColin Finck case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
130c2c66affSColin Finck case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
131c2c66affSColin Finck case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
132c2c66affSColin Finck case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
133c2c66affSColin Finck case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
134c2c66affSColin Finck case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
135c2c66affSColin Finck case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
136c2c66affSColin Finck case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
137c2c66affSColin Finck case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
138c2c66affSColin Finck default:
139c2c66affSColin Finck FIXME("Unhandled D3DFORMAT %#x.\n", format);
140c2c66affSColin Finck return WINED3DFMT_UNKNOWN;
141c2c66affSColin Finck }
142c2c66affSColin Finck }
143c2c66affSColin Finck
wined3dmapflags_from_d3dmapflags(unsigned int flags)1449987f029SAmine Khaldi unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags)
1459987f029SAmine Khaldi {
1469987f029SAmine Khaldi static const unsigned int handled = D3DLOCK_NOSYSLOCK
1479987f029SAmine Khaldi | D3DLOCK_NOOVERWRITE
1489987f029SAmine Khaldi | D3DLOCK_DISCARD
1499987f029SAmine Khaldi | D3DLOCK_NO_DIRTY_UPDATE;
1509987f029SAmine Khaldi unsigned int wined3d_flags;
1519987f029SAmine Khaldi
1529987f029SAmine Khaldi wined3d_flags = flags & handled;
1539987f029SAmine Khaldi if (!(flags & (D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD)))
1549987f029SAmine Khaldi wined3d_flags |= WINED3D_MAP_READ;
1559987f029SAmine Khaldi if (!(flags & D3DLOCK_READONLY))
1569987f029SAmine Khaldi wined3d_flags |= WINED3D_MAP_WRITE;
1579987f029SAmine Khaldi if (!(wined3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE)))
1589987f029SAmine Khaldi wined3d_flags |= WINED3D_MAP_READ | WINED3D_MAP_WRITE;
1599987f029SAmine Khaldi flags &= ~(handled | D3DLOCK_READONLY);
1609987f029SAmine Khaldi
1619987f029SAmine Khaldi if (flags)
1629987f029SAmine Khaldi FIXME("Unhandled flags %#x.\n", flags);
1639987f029SAmine Khaldi
1649987f029SAmine Khaldi return wined3d_flags;
1659987f029SAmine Khaldi }
1669987f029SAmine Khaldi
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type,UINT primitive_count)167c2c66affSColin Finck static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
168c2c66affSColin Finck {
169c2c66affSColin Finck switch (primitive_type)
170c2c66affSColin Finck {
171c2c66affSColin Finck case D3DPT_POINTLIST:
172c2c66affSColin Finck return primitive_count;
173c2c66affSColin Finck
174c2c66affSColin Finck case D3DPT_LINELIST:
175c2c66affSColin Finck return primitive_count * 2;
176c2c66affSColin Finck
177c2c66affSColin Finck case D3DPT_LINESTRIP:
178c2c66affSColin Finck return primitive_count + 1;
179c2c66affSColin Finck
180c2c66affSColin Finck case D3DPT_TRIANGLELIST:
181c2c66affSColin Finck return primitive_count * 3;
182c2c66affSColin Finck
183c2c66affSColin Finck case D3DPT_TRIANGLESTRIP:
184c2c66affSColin Finck case D3DPT_TRIANGLEFAN:
185c2c66affSColin Finck return primitive_count + 2;
186c2c66affSColin Finck
187c2c66affSColin Finck default:
188c2c66affSColin Finck FIXME("Unhandled primitive type %#x.\n", primitive_type);
189c2c66affSColin Finck return 0;
190c2c66affSColin Finck }
191c2c66affSColin Finck }
192c2c66affSColin Finck
d3dswapeffect_from_wined3dswapeffect(enum wined3d_swap_effect effect)1939987f029SAmine Khaldi static D3DSWAPEFFECT d3dswapeffect_from_wined3dswapeffect(enum wined3d_swap_effect effect)
1949987f029SAmine Khaldi {
1959987f029SAmine Khaldi switch (effect)
1969987f029SAmine Khaldi {
1979987f029SAmine Khaldi case WINED3D_SWAP_EFFECT_DISCARD:
1989987f029SAmine Khaldi return D3DSWAPEFFECT_DISCARD;
1999987f029SAmine Khaldi case WINED3D_SWAP_EFFECT_SEQUENTIAL:
2009987f029SAmine Khaldi return D3DSWAPEFFECT_FLIP;
2019987f029SAmine Khaldi case WINED3D_SWAP_EFFECT_COPY:
2029987f029SAmine Khaldi return D3DSWAPEFFECT_COPY;
2039987f029SAmine Khaldi case WINED3D_SWAP_EFFECT_COPY_VSYNC:
2049987f029SAmine Khaldi return D3DSWAPEFFECT_COPY_VSYNC;
2059987f029SAmine Khaldi default:
2069987f029SAmine Khaldi FIXME("Unhandled swap effect %#x.\n", effect);
2079987f029SAmine Khaldi return D3DSWAPEFFECT_FLIP;
2089987f029SAmine Khaldi }
2099987f029SAmine Khaldi }
2109987f029SAmine Khaldi
present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS * present_parameters,const struct wined3d_swapchain_desc * swapchain_desc)211c2c66affSColin Finck static void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS *present_parameters,
212*81cffd76SJoachim Henze const struct wined3d_swapchain_desc *swapchain_desc)
213c2c66affSColin Finck {
214c2c66affSColin Finck present_parameters->BackBufferWidth = swapchain_desc->backbuffer_width;
215c2c66affSColin Finck present_parameters->BackBufferHeight = swapchain_desc->backbuffer_height;
216c2c66affSColin Finck present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc->backbuffer_format);
217c2c66affSColin Finck present_parameters->BackBufferCount = swapchain_desc->backbuffer_count;
218c2c66affSColin Finck present_parameters->MultiSampleType = swapchain_desc->multisample_type;
2199987f029SAmine Khaldi present_parameters->SwapEffect = d3dswapeffect_from_wined3dswapeffect(swapchain_desc->swap_effect);
220c2c66affSColin Finck present_parameters->hDeviceWindow = swapchain_desc->device_window;
221c2c66affSColin Finck present_parameters->Windowed = swapchain_desc->windowed;
222c2c66affSColin Finck present_parameters->EnableAutoDepthStencil = swapchain_desc->enable_auto_depth_stencil;
223c2c66affSColin Finck present_parameters->AutoDepthStencilFormat
224c2c66affSColin Finck = d3dformat_from_wined3dformat(swapchain_desc->auto_depth_stencil_format);
225c2c66affSColin Finck present_parameters->Flags = swapchain_desc->flags & D3DPRESENTFLAGS_MASK;
226c2c66affSColin Finck present_parameters->FullScreen_RefreshRateInHz = swapchain_desc->refresh_rate;
227*81cffd76SJoachim Henze present_parameters->FullScreen_PresentationInterval = swapchain_desc->swap_interval;
228c2c66affSColin Finck }
229c2c66affSColin Finck
wined3dswapeffect_from_d3dswapeffect(D3DSWAPEFFECT effect)2309987f029SAmine Khaldi static enum wined3d_swap_effect wined3dswapeffect_from_d3dswapeffect(D3DSWAPEFFECT effect)
2319987f029SAmine Khaldi {
2329987f029SAmine Khaldi switch (effect)
2339987f029SAmine Khaldi {
2349987f029SAmine Khaldi case D3DSWAPEFFECT_DISCARD:
2359987f029SAmine Khaldi return WINED3D_SWAP_EFFECT_DISCARD;
2369987f029SAmine Khaldi case D3DSWAPEFFECT_FLIP:
2379987f029SAmine Khaldi return WINED3D_SWAP_EFFECT_SEQUENTIAL;
2389987f029SAmine Khaldi case D3DSWAPEFFECT_COPY:
2399987f029SAmine Khaldi return WINED3D_SWAP_EFFECT_COPY;
2409987f029SAmine Khaldi case D3DSWAPEFFECT_COPY_VSYNC:
2419987f029SAmine Khaldi return WINED3D_SWAP_EFFECT_COPY_VSYNC;
2429987f029SAmine Khaldi default:
2439987f029SAmine Khaldi FIXME("Unhandled swap effect %#x.\n", effect);
2449987f029SAmine Khaldi return WINED3D_SWAP_EFFECT_SEQUENTIAL;
2459987f029SAmine Khaldi }
2469987f029SAmine Khaldi }
2479987f029SAmine Khaldi
wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc * swapchain_desc,const D3DPRESENT_PARAMETERS * present_parameters)248c2c66affSColin Finck static BOOL wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc *swapchain_desc,
249c2c66affSColin Finck const D3DPRESENT_PARAMETERS *present_parameters)
250c2c66affSColin Finck {
251c2c66affSColin Finck if (!present_parameters->SwapEffect || present_parameters->SwapEffect > D3DSWAPEFFECT_COPY_VSYNC)
252c2c66affSColin Finck {
253c2c66affSColin Finck WARN("Invalid swap effect %u passed.\n", present_parameters->SwapEffect);
254c2c66affSColin Finck return FALSE;
255c2c66affSColin Finck }
256c2c66affSColin Finck if (present_parameters->BackBufferCount > 3
257c2c66affSColin Finck || ((present_parameters->SwapEffect == D3DSWAPEFFECT_COPY
258c2c66affSColin Finck || present_parameters->SwapEffect == D3DSWAPEFFECT_COPY_VSYNC)
259c2c66affSColin Finck && present_parameters->BackBufferCount > 1))
260c2c66affSColin Finck {
261c2c66affSColin Finck WARN("Invalid backbuffer count %u.\n", present_parameters->BackBufferCount);
262c2c66affSColin Finck return FALSE;
263c2c66affSColin Finck }
264c2c66affSColin Finck
265c2c66affSColin Finck swapchain_desc->backbuffer_width = present_parameters->BackBufferWidth;
266c2c66affSColin Finck swapchain_desc->backbuffer_height = present_parameters->BackBufferHeight;
267c2c66affSColin Finck swapchain_desc->backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
268c2c66affSColin Finck swapchain_desc->backbuffer_count = max(1, present_parameters->BackBufferCount);
2699987f029SAmine Khaldi swapchain_desc->backbuffer_usage = WINED3DUSAGE_RENDERTARGET;
270c2c66affSColin Finck swapchain_desc->multisample_type = present_parameters->MultiSampleType;
271c2c66affSColin Finck swapchain_desc->multisample_quality = 0; /* d3d9 only */
2729987f029SAmine Khaldi swapchain_desc->swap_effect = wined3dswapeffect_from_d3dswapeffect(present_parameters->SwapEffect);
273c2c66affSColin Finck swapchain_desc->device_window = present_parameters->hDeviceWindow;
274c2c66affSColin Finck swapchain_desc->windowed = present_parameters->Windowed;
275c2c66affSColin Finck swapchain_desc->enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
276c2c66affSColin Finck swapchain_desc->auto_depth_stencil_format
277c2c66affSColin Finck = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
278c2c66affSColin Finck swapchain_desc->flags
279c2c66affSColin Finck = (present_parameters->Flags & D3DPRESENTFLAGS_MASK) | WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH;
280c2c66affSColin Finck swapchain_desc->refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
281*81cffd76SJoachim Henze swapchain_desc->swap_interval = present_parameters->FullScreen_PresentationInterval;
282c2c66affSColin Finck swapchain_desc->auto_restore_display_mode = TRUE;
283c2c66affSColin Finck
284c2c66affSColin Finck if (present_parameters->Flags & ~D3DPRESENTFLAGS_MASK)
285c2c66affSColin Finck FIXME("Unhandled flags %#x.\n", present_parameters->Flags & ~D3DPRESENTFLAGS_MASK);
286c2c66affSColin Finck
287c2c66affSColin Finck return TRUE;
288c2c66affSColin Finck }
289c2c66affSColin Finck
d3dcaps_from_wined3dcaps(D3DCAPS8 * caps,const WINED3DCAPS * wined3d_caps)290c2c66affSColin Finck void d3dcaps_from_wined3dcaps(D3DCAPS8 *caps, const WINED3DCAPS *wined3d_caps)
291c2c66affSColin Finck {
292c2c66affSColin Finck caps->DeviceType = (D3DDEVTYPE)wined3d_caps->DeviceType;
293c2c66affSColin Finck caps->AdapterOrdinal = wined3d_caps->AdapterOrdinal;
294c2c66affSColin Finck caps->Caps = wined3d_caps->Caps;
295c2c66affSColin Finck caps->Caps2 = wined3d_caps->Caps2;
296c2c66affSColin Finck caps->Caps3 = wined3d_caps->Caps3;
297*81cffd76SJoachim Henze caps->PresentationIntervals = wined3d_caps->PresentationIntervals;
298c2c66affSColin Finck caps->CursorCaps = wined3d_caps->CursorCaps;
299c2c66affSColin Finck caps->DevCaps = wined3d_caps->DevCaps;
300c2c66affSColin Finck caps->PrimitiveMiscCaps = wined3d_caps->PrimitiveMiscCaps;
301c2c66affSColin Finck caps->RasterCaps = wined3d_caps->RasterCaps;
302c2c66affSColin Finck caps->ZCmpCaps = wined3d_caps->ZCmpCaps;
303c2c66affSColin Finck caps->SrcBlendCaps = wined3d_caps->SrcBlendCaps;
304c2c66affSColin Finck caps->DestBlendCaps = wined3d_caps->DestBlendCaps;
305c2c66affSColin Finck caps->AlphaCmpCaps = wined3d_caps->AlphaCmpCaps;
306c2c66affSColin Finck caps->ShadeCaps = wined3d_caps->ShadeCaps;
307c2c66affSColin Finck caps->TextureCaps = wined3d_caps->TextureCaps;
308c2c66affSColin Finck caps->TextureFilterCaps = wined3d_caps->TextureFilterCaps;
309c2c66affSColin Finck caps->CubeTextureFilterCaps = wined3d_caps->CubeTextureFilterCaps;
310c2c66affSColin Finck caps->VolumeTextureFilterCaps = wined3d_caps->VolumeTextureFilterCaps;
311c2c66affSColin Finck caps->TextureAddressCaps = wined3d_caps->TextureAddressCaps;
312c2c66affSColin Finck caps->VolumeTextureAddressCaps = wined3d_caps->VolumeTextureAddressCaps;
313c2c66affSColin Finck caps->LineCaps = wined3d_caps->LineCaps;
314c2c66affSColin Finck caps->MaxTextureWidth = wined3d_caps->MaxTextureWidth;
315c2c66affSColin Finck caps->MaxTextureHeight = wined3d_caps->MaxTextureHeight;
316c2c66affSColin Finck caps->MaxVolumeExtent = wined3d_caps->MaxVolumeExtent;
317c2c66affSColin Finck caps->MaxTextureRepeat = wined3d_caps->MaxTextureRepeat;
318c2c66affSColin Finck caps->MaxTextureAspectRatio = wined3d_caps->MaxTextureAspectRatio;
319c2c66affSColin Finck caps->MaxAnisotropy = wined3d_caps->MaxAnisotropy;
320c2c66affSColin Finck caps->MaxVertexW = wined3d_caps->MaxVertexW;
321c2c66affSColin Finck caps->GuardBandLeft = wined3d_caps->GuardBandLeft;
322c2c66affSColin Finck caps->GuardBandTop = wined3d_caps->GuardBandTop;
323c2c66affSColin Finck caps->GuardBandRight = wined3d_caps->GuardBandRight;
324c2c66affSColin Finck caps->GuardBandBottom = wined3d_caps->GuardBandBottom;
325c2c66affSColin Finck caps->ExtentsAdjust = wined3d_caps->ExtentsAdjust;
326c2c66affSColin Finck caps->StencilCaps = wined3d_caps->StencilCaps;
327c2c66affSColin Finck caps->FVFCaps = wined3d_caps->FVFCaps;
328c2c66affSColin Finck caps->TextureOpCaps = wined3d_caps->TextureOpCaps;
329c2c66affSColin Finck caps->MaxTextureBlendStages = wined3d_caps->MaxTextureBlendStages;
330c2c66affSColin Finck caps->MaxSimultaneousTextures = wined3d_caps->MaxSimultaneousTextures;
331c2c66affSColin Finck caps->VertexProcessingCaps = wined3d_caps->VertexProcessingCaps;
332c2c66affSColin Finck caps->MaxActiveLights = wined3d_caps->MaxActiveLights;
333c2c66affSColin Finck caps->MaxUserClipPlanes = wined3d_caps->MaxUserClipPlanes;
334c2c66affSColin Finck caps->MaxVertexBlendMatrices = wined3d_caps->MaxVertexBlendMatrices;
335c2c66affSColin Finck caps->MaxVertexBlendMatrixIndex = wined3d_caps->MaxVertexBlendMatrixIndex;
336c2c66affSColin Finck caps->MaxPointSize = wined3d_caps->MaxPointSize;
337c2c66affSColin Finck caps->MaxPrimitiveCount = wined3d_caps->MaxPrimitiveCount;
338c2c66affSColin Finck caps->MaxVertexIndex = wined3d_caps->MaxVertexIndex;
339c2c66affSColin Finck caps->MaxStreams = wined3d_caps->MaxStreams;
340c2c66affSColin Finck caps->MaxStreamStride = wined3d_caps->MaxStreamStride;
341c2c66affSColin Finck caps->VertexShaderVersion = wined3d_caps->VertexShaderVersion;
342c2c66affSColin Finck caps->MaxVertexShaderConst = wined3d_caps->MaxVertexShaderConst;
343c2c66affSColin Finck caps->PixelShaderVersion = wined3d_caps->PixelShaderVersion;
344c2c66affSColin Finck caps->MaxPixelShaderValue = wined3d_caps->PixelShader1xMaxValue;
345c2c66affSColin Finck
346c2c66affSColin Finck /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
347c2c66affSColin Finck if (caps->PixelShaderVersion)
348c2c66affSColin Finck caps->PixelShaderVersion = D3DPS_VERSION(1, 4);
349c2c66affSColin Finck else
350c2c66affSColin Finck caps->PixelShaderVersion = D3DPS_VERSION(0, 0);
351c2c66affSColin Finck if (caps->VertexShaderVersion)
352c2c66affSColin Finck caps->VertexShaderVersion = D3DVS_VERSION(1, 1);
353c2c66affSColin Finck else
354c2c66affSColin Finck caps->VertexShaderVersion = D3DVS_VERSION(0, 0);
355c2c66affSColin Finck caps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, caps->MaxVertexShaderConst);
356*81cffd76SJoachim Henze
357*81cffd76SJoachim Henze caps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED;
358c2c66affSColin Finck }
359c2c66affSColin Finck
360c2c66affSColin Finck /* Handle table functions */
d3d8_allocate_handle(struct d3d8_handle_table * t,void * object,enum d3d8_handle_type type)361c2c66affSColin Finck static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
362c2c66affSColin Finck {
363c2c66affSColin Finck struct d3d8_handle_entry *entry;
364c2c66affSColin Finck
365c2c66affSColin Finck if (t->free_entries)
366c2c66affSColin Finck {
367c2c66affSColin Finck DWORD index = t->free_entries - t->entries;
368c2c66affSColin Finck /* Use a free handle */
369c2c66affSColin Finck entry = t->free_entries;
370c2c66affSColin Finck if (entry->type != D3D8_HANDLE_FREE)
371c2c66affSColin Finck {
372c2c66affSColin Finck ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index, entry, entry->type);
373c2c66affSColin Finck return D3D8_INVALID_HANDLE;
374c2c66affSColin Finck }
375c2c66affSColin Finck t->free_entries = entry->object;
376c2c66affSColin Finck entry->object = object;
377c2c66affSColin Finck entry->type = type;
378c2c66affSColin Finck
379c2c66affSColin Finck return index;
380c2c66affSColin Finck }
381c2c66affSColin Finck
382c2c66affSColin Finck if (!(t->entry_count < t->table_size))
383c2c66affSColin Finck {
384c2c66affSColin Finck /* Grow the table */
385c2c66affSColin Finck UINT new_size = t->table_size + (t->table_size >> 1);
3869987f029SAmine Khaldi struct d3d8_handle_entry *new_entries;
3879987f029SAmine Khaldi
3889987f029SAmine Khaldi if (!(new_entries = heap_realloc(t->entries, new_size * sizeof(*t->entries))))
389c2c66affSColin Finck {
390c2c66affSColin Finck ERR("Failed to grow the handle table.\n");
391c2c66affSColin Finck return D3D8_INVALID_HANDLE;
392c2c66affSColin Finck }
393c2c66affSColin Finck t->entries = new_entries;
394c2c66affSColin Finck t->table_size = new_size;
395c2c66affSColin Finck }
396c2c66affSColin Finck
397c2c66affSColin Finck entry = &t->entries[t->entry_count];
398c2c66affSColin Finck entry->object = object;
399c2c66affSColin Finck entry->type = type;
400c2c66affSColin Finck
401c2c66affSColin Finck return t->entry_count++;
402c2c66affSColin Finck }
403c2c66affSColin Finck
d3d8_free_handle(struct d3d8_handle_table * t,DWORD handle,enum d3d8_handle_type type)404c2c66affSColin Finck static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
405c2c66affSColin Finck {
406c2c66affSColin Finck struct d3d8_handle_entry *entry;
407c2c66affSColin Finck void *object;
408c2c66affSColin Finck
409c2c66affSColin Finck if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
410c2c66affSColin Finck {
411c2c66affSColin Finck WARN("Invalid handle %u passed.\n", handle);
412c2c66affSColin Finck return NULL;
413c2c66affSColin Finck }
414c2c66affSColin Finck
415c2c66affSColin Finck entry = &t->entries[handle];
416c2c66affSColin Finck if (entry->type != type)
417c2c66affSColin Finck {
418c2c66affSColin Finck WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
419c2c66affSColin Finck return NULL;
420c2c66affSColin Finck }
421c2c66affSColin Finck
422c2c66affSColin Finck object = entry->object;
423c2c66affSColin Finck entry->object = t->free_entries;
424c2c66affSColin Finck entry->type = D3D8_HANDLE_FREE;
425c2c66affSColin Finck t->free_entries = entry;
426c2c66affSColin Finck
427c2c66affSColin Finck return object;
428c2c66affSColin Finck }
429c2c66affSColin Finck
d3d8_get_object(struct d3d8_handle_table * t,DWORD handle,enum d3d8_handle_type type)430c2c66affSColin Finck static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
431c2c66affSColin Finck {
432c2c66affSColin Finck struct d3d8_handle_entry *entry;
433c2c66affSColin Finck
434c2c66affSColin Finck if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
435c2c66affSColin Finck {
436c2c66affSColin Finck WARN("Invalid handle %u passed.\n", handle);
437c2c66affSColin Finck return NULL;
438c2c66affSColin Finck }
439c2c66affSColin Finck
440c2c66affSColin Finck entry = &t->entries[handle];
441c2c66affSColin Finck if (entry->type != type)
442c2c66affSColin Finck {
443c2c66affSColin Finck WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
444c2c66affSColin Finck return NULL;
445c2c66affSColin Finck }
446c2c66affSColin Finck
447c2c66affSColin Finck return entry->object;
448c2c66affSColin Finck }
449c2c66affSColin Finck
d3d8_device_QueryInterface(IDirect3DDevice8 * iface,REFIID riid,void ** out)450c2c66affSColin Finck static HRESULT WINAPI d3d8_device_QueryInterface(IDirect3DDevice8 *iface, REFIID riid, void **out)
451c2c66affSColin Finck {
452c2c66affSColin Finck TRACE("iface %p, riid %s, out %p.\n",
453c2c66affSColin Finck iface, debugstr_guid(riid), out);
454c2c66affSColin Finck
455c2c66affSColin Finck if (IsEqualGUID(riid, &IID_IDirect3DDevice8)
456c2c66affSColin Finck || IsEqualGUID(riid, &IID_IUnknown))
457c2c66affSColin Finck {
458c2c66affSColin Finck IDirect3DDevice8_AddRef(iface);
459c2c66affSColin Finck *out = iface;
460c2c66affSColin Finck return S_OK;
461c2c66affSColin Finck }
462c2c66affSColin Finck
463c2c66affSColin Finck WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
464c2c66affSColin Finck
465c2c66affSColin Finck *out = NULL;
466c2c66affSColin Finck return E_NOINTERFACE;
467c2c66affSColin Finck }
468c2c66affSColin Finck
d3d8_device_AddRef(IDirect3DDevice8 * iface)469c2c66affSColin Finck static ULONG WINAPI d3d8_device_AddRef(IDirect3DDevice8 *iface)
470c2c66affSColin Finck {
471c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
472c2c66affSColin Finck ULONG ref = InterlockedIncrement(&device->ref);
473c2c66affSColin Finck
474c2c66affSColin Finck TRACE("%p increasing refcount to %u.\n", iface, ref);
475c2c66affSColin Finck
476c2c66affSColin Finck return ref;
477c2c66affSColin Finck }
478c2c66affSColin Finck
d3d8_device_Release(IDirect3DDevice8 * iface)479c2c66affSColin Finck static ULONG WINAPI d3d8_device_Release(IDirect3DDevice8 *iface)
480c2c66affSColin Finck {
481c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
482c2c66affSColin Finck ULONG ref;
483c2c66affSColin Finck
484c2c66affSColin Finck if (device->inDestruction)
485c2c66affSColin Finck return 0;
486c2c66affSColin Finck
487c2c66affSColin Finck ref = InterlockedDecrement(&device->ref);
488c2c66affSColin Finck
489c2c66affSColin Finck TRACE("%p decreasing refcount to %u.\n", iface, ref);
490c2c66affSColin Finck
491c2c66affSColin Finck if (!ref)
492c2c66affSColin Finck {
493c2c66affSColin Finck IDirect3D8 *parent = device->d3d_parent;
494c2c66affSColin Finck unsigned i;
495c2c66affSColin Finck
496c2c66affSColin Finck TRACE("Releasing wined3d device %p.\n", device->wined3d_device);
497c2c66affSColin Finck
498c2c66affSColin Finck wined3d_mutex_lock();
499c2c66affSColin Finck
500c2c66affSColin Finck device->inDestruction = TRUE;
501c2c66affSColin Finck
502c2c66affSColin Finck for (i = 0; i < device->numConvertedDecls; ++i)
503c2c66affSColin Finck {
504c2c66affSColin Finck d3d8_vertex_declaration_destroy(device->decls[i].declaration);
505c2c66affSColin Finck }
5069987f029SAmine Khaldi heap_free(device->decls);
507c2c66affSColin Finck
508c2c66affSColin Finck if (device->vertex_buffer)
509c2c66affSColin Finck wined3d_buffer_decref(device->vertex_buffer);
510c2c66affSColin Finck if (device->index_buffer)
511c2c66affSColin Finck wined3d_buffer_decref(device->index_buffer);
512c2c66affSColin Finck
513c2c66affSColin Finck wined3d_device_uninit_3d(device->wined3d_device);
514c2c66affSColin Finck wined3d_device_release_focus_window(device->wined3d_device);
515c2c66affSColin Finck wined3d_device_decref(device->wined3d_device);
5169987f029SAmine Khaldi heap_free(device->handle_table.entries);
5179987f029SAmine Khaldi heap_free(device);
518c2c66affSColin Finck
519c2c66affSColin Finck wined3d_mutex_unlock();
520c2c66affSColin Finck
521c2c66affSColin Finck IDirect3D8_Release(parent);
522c2c66affSColin Finck }
523c2c66affSColin Finck return ref;
524c2c66affSColin Finck }
525c2c66affSColin Finck
d3d8_device_TestCooperativeLevel(IDirect3DDevice8 * iface)526c2c66affSColin Finck static HRESULT WINAPI d3d8_device_TestCooperativeLevel(IDirect3DDevice8 *iface)
527c2c66affSColin Finck {
528c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
529c2c66affSColin Finck
530c2c66affSColin Finck TRACE("iface %p.\n", iface);
531c2c66affSColin Finck
532c2c66affSColin Finck TRACE("device state: %#x.\n", device->device_state);
533c2c66affSColin Finck
534c2c66affSColin Finck switch (device->device_state)
535c2c66affSColin Finck {
536c2c66affSColin Finck default:
537c2c66affSColin Finck case D3D8_DEVICE_STATE_OK:
538c2c66affSColin Finck return D3D_OK;
539c2c66affSColin Finck case D3D8_DEVICE_STATE_LOST:
540c2c66affSColin Finck return D3DERR_DEVICELOST;
541c2c66affSColin Finck case D3D8_DEVICE_STATE_NOT_RESET:
542c2c66affSColin Finck return D3DERR_DEVICENOTRESET;
543c2c66affSColin Finck }
544c2c66affSColin Finck }
545c2c66affSColin Finck
d3d8_device_GetAvailableTextureMem(IDirect3DDevice8 * iface)546c2c66affSColin Finck static UINT WINAPI d3d8_device_GetAvailableTextureMem(IDirect3DDevice8 *iface)
547c2c66affSColin Finck {
548c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
549c2c66affSColin Finck UINT ret;
550c2c66affSColin Finck
551c2c66affSColin Finck TRACE("iface %p.\n", iface);
552c2c66affSColin Finck
553c2c66affSColin Finck wined3d_mutex_lock();
554c2c66affSColin Finck ret = wined3d_device_get_available_texture_mem(device->wined3d_device);
555c2c66affSColin Finck wined3d_mutex_unlock();
556c2c66affSColin Finck
557c2c66affSColin Finck return ret;
558c2c66affSColin Finck }
559c2c66affSColin Finck
d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8 * iface,DWORD byte_count)560c2c66affSColin Finck static HRESULT WINAPI d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8 *iface, DWORD byte_count)
561c2c66affSColin Finck {
562c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
563c2c66affSColin Finck
564c2c66affSColin Finck TRACE("iface %p, byte_count %u.\n", iface, byte_count);
565c2c66affSColin Finck
566c2c66affSColin Finck if (byte_count)
567c2c66affSColin Finck FIXME("Byte count ignored.\n");
568c2c66affSColin Finck
569c2c66affSColin Finck wined3d_mutex_lock();
570c2c66affSColin Finck wined3d_device_evict_managed_resources(device->wined3d_device);
571c2c66affSColin Finck wined3d_mutex_unlock();
572c2c66affSColin Finck
573c2c66affSColin Finck return D3D_OK;
574c2c66affSColin Finck }
575c2c66affSColin Finck
d3d8_device_GetDirect3D(IDirect3DDevice8 * iface,IDirect3D8 ** d3d8)576c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **d3d8)
577c2c66affSColin Finck {
578c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
579c2c66affSColin Finck
580c2c66affSColin Finck TRACE("iface %p, d3d8 %p.\n", iface, d3d8);
581c2c66affSColin Finck
582c2c66affSColin Finck if (!d3d8)
583c2c66affSColin Finck return D3DERR_INVALIDCALL;
584c2c66affSColin Finck
585c2c66affSColin Finck return IDirect3D8_QueryInterface(device->d3d_parent, &IID_IDirect3D8, (void **)d3d8);
586c2c66affSColin Finck }
587c2c66affSColin Finck
d3d8_device_GetDeviceCaps(IDirect3DDevice8 * iface,D3DCAPS8 * caps)588c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *caps)
589c2c66affSColin Finck {
590c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
591c2c66affSColin Finck WINED3DCAPS wined3d_caps;
592c2c66affSColin Finck HRESULT hr;
593c2c66affSColin Finck
594c2c66affSColin Finck TRACE("iface %p, caps %p.\n", iface, caps);
595c2c66affSColin Finck
596c2c66affSColin Finck if (!caps)
597c2c66affSColin Finck return D3DERR_INVALIDCALL;
598c2c66affSColin Finck
599c2c66affSColin Finck wined3d_mutex_lock();
600c2c66affSColin Finck hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
601c2c66affSColin Finck wined3d_mutex_unlock();
602c2c66affSColin Finck
603c2c66affSColin Finck d3dcaps_from_wined3dcaps(caps, &wined3d_caps);
604c2c66affSColin Finck
605c2c66affSColin Finck return hr;
606c2c66affSColin Finck }
607c2c66affSColin Finck
d3d8_device_GetDisplayMode(IDirect3DDevice8 * iface,D3DDISPLAYMODE * mode)608c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetDisplayMode(IDirect3DDevice8 *iface, D3DDISPLAYMODE *mode)
609c2c66affSColin Finck {
610c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
611c2c66affSColin Finck struct wined3d_display_mode wined3d_mode;
612c2c66affSColin Finck HRESULT hr;
613c2c66affSColin Finck
614c2c66affSColin Finck TRACE("iface %p, mode %p.\n", iface, mode);
615c2c66affSColin Finck
616c2c66affSColin Finck wined3d_mutex_lock();
617c2c66affSColin Finck hr = wined3d_device_get_display_mode(device->wined3d_device, 0, &wined3d_mode, NULL);
618c2c66affSColin Finck wined3d_mutex_unlock();
619c2c66affSColin Finck
620c2c66affSColin Finck if (SUCCEEDED(hr))
621c2c66affSColin Finck {
622c2c66affSColin Finck mode->Width = wined3d_mode.width;
623c2c66affSColin Finck mode->Height = wined3d_mode.height;
624c2c66affSColin Finck mode->RefreshRate = wined3d_mode.refresh_rate;
625c2c66affSColin Finck mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
626c2c66affSColin Finck }
627c2c66affSColin Finck
628c2c66affSColin Finck return hr;
629c2c66affSColin Finck }
630c2c66affSColin Finck
d3d8_device_GetCreationParameters(IDirect3DDevice8 * iface,D3DDEVICE_CREATION_PARAMETERS * parameters)631c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetCreationParameters(IDirect3DDevice8 *iface,
632c2c66affSColin Finck D3DDEVICE_CREATION_PARAMETERS *parameters)
633c2c66affSColin Finck {
634c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
635c2c66affSColin Finck
636c2c66affSColin Finck TRACE("iface %p, parameters %p.\n", iface, parameters);
637c2c66affSColin Finck
638c2c66affSColin Finck wined3d_mutex_lock();
639c2c66affSColin Finck wined3d_device_get_creation_parameters(device->wined3d_device,
640c2c66affSColin Finck (struct wined3d_device_creation_parameters *)parameters);
641c2c66affSColin Finck wined3d_mutex_unlock();
642c2c66affSColin Finck
643c2c66affSColin Finck return D3D_OK;
644c2c66affSColin Finck }
645c2c66affSColin Finck
d3d8_device_SetCursorProperties(IDirect3DDevice8 * iface,UINT hotspot_x,UINT hotspot_y,IDirect3DSurface8 * bitmap)646c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetCursorProperties(IDirect3DDevice8 *iface,
647c2c66affSColin Finck UINT hotspot_x, UINT hotspot_y, IDirect3DSurface8 *bitmap)
648c2c66affSColin Finck {
649c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
650c2c66affSColin Finck struct d3d8_surface *bitmap_impl = unsafe_impl_from_IDirect3DSurface8(bitmap);
651c2c66affSColin Finck HRESULT hr;
652c2c66affSColin Finck
653c2c66affSColin Finck TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
654c2c66affSColin Finck iface, hotspot_x, hotspot_y, bitmap);
655c2c66affSColin Finck
656c2c66affSColin Finck if (!bitmap)
657c2c66affSColin Finck {
658c2c66affSColin Finck WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
659c2c66affSColin Finck return D3DERR_INVALIDCALL;
660c2c66affSColin Finck }
661c2c66affSColin Finck
662c2c66affSColin Finck wined3d_mutex_lock();
663c2c66affSColin Finck hr = wined3d_device_set_cursor_properties(device->wined3d_device,
664c2c66affSColin Finck hotspot_x, hotspot_y, bitmap_impl->wined3d_texture, bitmap_impl->sub_resource_idx);
665c2c66affSColin Finck wined3d_mutex_unlock();
666c2c66affSColin Finck
667c2c66affSColin Finck return hr;
668c2c66affSColin Finck }
669c2c66affSColin Finck
d3d8_device_SetCursorPosition(IDirect3DDevice8 * iface,UINT x,UINT y,DWORD flags)670c2c66affSColin Finck static void WINAPI d3d8_device_SetCursorPosition(IDirect3DDevice8 *iface, UINT x, UINT y, DWORD flags)
671c2c66affSColin Finck {
672c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
673c2c66affSColin Finck
674c2c66affSColin Finck TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, x, y, flags);
675c2c66affSColin Finck
676c2c66affSColin Finck wined3d_mutex_lock();
677c2c66affSColin Finck wined3d_device_set_cursor_position(device->wined3d_device, x, y, flags);
678c2c66affSColin Finck wined3d_mutex_unlock();
679c2c66affSColin Finck }
680c2c66affSColin Finck
d3d8_device_ShowCursor(IDirect3DDevice8 * iface,BOOL show)681c2c66affSColin Finck static BOOL WINAPI d3d8_device_ShowCursor(IDirect3DDevice8 *iface, BOOL show)
682c2c66affSColin Finck {
683c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
684c2c66affSColin Finck BOOL ret;
685c2c66affSColin Finck
686c2c66affSColin Finck TRACE("iface %p, show %#x.\n", iface, show);
687c2c66affSColin Finck
688c2c66affSColin Finck wined3d_mutex_lock();
689c2c66affSColin Finck ret = wined3d_device_show_cursor(device->wined3d_device, show);
690c2c66affSColin Finck wined3d_mutex_unlock();
691c2c66affSColin Finck
692c2c66affSColin Finck return ret;
693c2c66affSColin Finck }
694c2c66affSColin Finck
d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8 * iface,D3DPRESENT_PARAMETERS * present_parameters,IDirect3DSwapChain8 ** swapchain)695c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
696c2c66affSColin Finck D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
697c2c66affSColin Finck {
698c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
699c2c66affSColin Finck struct wined3d_swapchain_desc desc;
700c2c66affSColin Finck struct d3d8_swapchain *object;
701*81cffd76SJoachim Henze UINT i, count;
702c2c66affSColin Finck HRESULT hr;
703c2c66affSColin Finck
704c2c66affSColin Finck TRACE("iface %p, present_parameters %p, swapchain %p.\n",
705c2c66affSColin Finck iface, present_parameters, swapchain);
706c2c66affSColin Finck
707c2c66affSColin Finck if (!present_parameters->Windowed)
708c2c66affSColin Finck {
709c2c66affSColin Finck WARN("Trying to create an additional fullscreen swapchain, returning D3DERR_INVALIDCALL.\n");
710c2c66affSColin Finck return D3DERR_INVALIDCALL;
711c2c66affSColin Finck }
712c2c66affSColin Finck
713c2c66affSColin Finck wined3d_mutex_lock();
714c2c66affSColin Finck count = wined3d_device_get_swapchain_count(device->wined3d_device);
715c2c66affSColin Finck for (i = 0; i < count; ++i)
716c2c66affSColin Finck {
717c2c66affSColin Finck struct wined3d_swapchain *wined3d_swapchain;
718c2c66affSColin Finck
719c2c66affSColin Finck wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, i);
720c2c66affSColin Finck wined3d_swapchain_get_desc(wined3d_swapchain, &desc);
721c2c66affSColin Finck
722c2c66affSColin Finck if (!desc.windowed)
723c2c66affSColin Finck {
724c2c66affSColin Finck wined3d_mutex_unlock();
725c2c66affSColin Finck WARN("Trying to create an additional swapchain in fullscreen mode, returning D3DERR_INVALIDCALL.\n");
726c2c66affSColin Finck return D3DERR_INVALIDCALL;
727c2c66affSColin Finck }
728c2c66affSColin Finck }
729c2c66affSColin Finck wined3d_mutex_unlock();
730c2c66affSColin Finck
731c2c66affSColin Finck if (!wined3d_swapchain_desc_from_present_parameters(&desc, present_parameters))
732c2c66affSColin Finck return D3DERR_INVALIDCALL;
733*81cffd76SJoachim Henze if (SUCCEEDED(hr = d3d8_swapchain_create(device, &desc, &object)))
734c2c66affSColin Finck *swapchain = &object->IDirect3DSwapChain8_iface;
735*81cffd76SJoachim Henze present_parameters_from_wined3d_swapchain_desc(present_parameters, &desc);
736c2c66affSColin Finck
737c2c66affSColin Finck return hr;
738c2c66affSColin Finck }
739c2c66affSColin Finck
reset_enum_callback(struct wined3d_resource * resource)740c2c66affSColin Finck static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
741c2c66affSColin Finck {
742c2c66affSColin Finck struct wined3d_resource_desc desc;
743c2c66affSColin Finck IDirect3DBaseTexture8 *texture;
744c2c66affSColin Finck struct d3d8_surface *surface;
745c2c66affSColin Finck IUnknown *parent;
746c2c66affSColin Finck
747c2c66affSColin Finck wined3d_resource_get_desc(resource, &desc);
7489987f029SAmine Khaldi if (desc.access & WINED3D_RESOURCE_ACCESS_CPU)
749c2c66affSColin Finck return D3D_OK;
750c2c66affSColin Finck
751c2c66affSColin Finck if (desc.resource_type != WINED3D_RTYPE_TEXTURE_2D)
752c2c66affSColin Finck {
753c2c66affSColin Finck WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
754c2c66affSColin Finck return D3DERR_DEVICELOST;
755c2c66affSColin Finck }
756c2c66affSColin Finck
757c2c66affSColin Finck parent = wined3d_resource_get_parent(resource);
758c2c66affSColin Finck if (parent && SUCCEEDED(IUnknown_QueryInterface(parent, &IID_IDirect3DBaseTexture8, (void **)&texture)))
759c2c66affSColin Finck {
760c2c66affSColin Finck IDirect3DBaseTexture8_Release(texture);
761c2c66affSColin Finck WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture, resource);
762c2c66affSColin Finck return D3DERR_DEVICELOST;
763c2c66affSColin Finck }
764c2c66affSColin Finck
765c2c66affSColin Finck surface = wined3d_texture_get_sub_resource_parent(wined3d_texture_from_resource(resource), 0);
766c2c66affSColin Finck if (!surface->resource.refcount)
767c2c66affSColin Finck return D3D_OK;
768c2c66affSColin Finck
769c2c66affSColin Finck WARN("Surface %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface);
770c2c66affSColin Finck return D3DERR_DEVICELOST;
771c2c66affSColin Finck }
772c2c66affSColin Finck
d3d8_device_Reset(IDirect3DDevice8 * iface,D3DPRESENT_PARAMETERS * present_parameters)773c2c66affSColin Finck static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface,
774c2c66affSColin Finck D3DPRESENT_PARAMETERS *present_parameters)
775c2c66affSColin Finck {
776c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
777c2c66affSColin Finck struct wined3d_swapchain_desc swapchain_desc;
778c2c66affSColin Finck HRESULT hr;
779c2c66affSColin Finck
780c2c66affSColin Finck TRACE("iface %p, present_parameters %p.\n", iface, present_parameters);
781c2c66affSColin Finck
782c2c66affSColin Finck if (device->device_state == D3D8_DEVICE_STATE_LOST)
783c2c66affSColin Finck {
784c2c66affSColin Finck WARN("App not active, returning D3DERR_DEVICELOST.\n");
785c2c66affSColin Finck return D3DERR_DEVICELOST;
786c2c66affSColin Finck }
787c2c66affSColin Finck if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, present_parameters))
788c2c66affSColin Finck return D3DERR_INVALIDCALL;
789c2c66affSColin Finck
790c2c66affSColin Finck wined3d_mutex_lock();
791c2c66affSColin Finck
792c2c66affSColin Finck if (device->vertex_buffer)
793c2c66affSColin Finck {
794c2c66affSColin Finck wined3d_buffer_decref(device->vertex_buffer);
795c2c66affSColin Finck device->vertex_buffer = NULL;
796c2c66affSColin Finck device->vertex_buffer_size = 0;
797c2c66affSColin Finck }
798c2c66affSColin Finck if (device->index_buffer)
799c2c66affSColin Finck {
800c2c66affSColin Finck wined3d_buffer_decref(device->index_buffer);
801c2c66affSColin Finck device->index_buffer = NULL;
802c2c66affSColin Finck device->index_buffer_size = 0;
803c2c66affSColin Finck }
804c2c66affSColin Finck
805c2c66affSColin Finck if (SUCCEEDED(hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc,
806c2c66affSColin Finck NULL, reset_enum_callback, TRUE)))
807c2c66affSColin Finck {
808c2c66affSColin Finck present_parameters->BackBufferCount = swapchain_desc.backbuffer_count;
809c2c66affSColin Finck wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
810e6c95b14SAmine Khaldi wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE,
811e6c95b14SAmine Khaldi !!swapchain_desc.enable_auto_depth_stencil);
812c2c66affSColin Finck device->device_state = D3D8_DEVICE_STATE_OK;
813c2c66affSColin Finck }
814c2c66affSColin Finck else
815c2c66affSColin Finck {
816c2c66affSColin Finck device->device_state = D3D8_DEVICE_STATE_NOT_RESET;
817c2c66affSColin Finck }
818c2c66affSColin Finck wined3d_mutex_unlock();
819c2c66affSColin Finck
820c2c66affSColin Finck return hr;
821c2c66affSColin Finck }
822c2c66affSColin Finck
d3d8_device_Present(IDirect3DDevice8 * iface,const RECT * src_rect,const RECT * dst_rect,HWND dst_window_override,const RGNDATA * dirty_region)823c2c66affSColin Finck static HRESULT WINAPI d3d8_device_Present(IDirect3DDevice8 *iface, const RECT *src_rect,
824c2c66affSColin Finck const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region)
825c2c66affSColin Finck {
826c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
827c2c66affSColin Finck
828c2c66affSColin Finck TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
829c2c66affSColin Finck iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), dst_window_override, dirty_region);
830c2c66affSColin Finck
831c2c66affSColin Finck /* Fraps does not hook IDirect3DDevice8::Present regardless of the hotpatch
832c2c66affSColin Finck * attribute. It only hooks IDirect3DSwapChain8::Present. Yet it properly
833c2c66affSColin Finck * shows a framerate on Windows in applications that only call the device
834c2c66affSColin Finck * method, like e.g. the dx8 sdk samples. The conclusion is that native
835c2c66affSColin Finck * calls the swapchain's public method from the device. */
836c2c66affSColin Finck return IDirect3DSwapChain8_Present(&device->implicit_swapchain->IDirect3DSwapChain8_iface,
837c2c66affSColin Finck src_rect, dst_rect, dst_window_override, dirty_region);
838c2c66affSColin Finck }
839c2c66affSColin Finck
d3d8_device_GetBackBuffer(IDirect3DDevice8 * iface,UINT backbuffer_idx,D3DBACKBUFFER_TYPE backbuffer_type,IDirect3DSurface8 ** backbuffer)840c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetBackBuffer(IDirect3DDevice8 *iface,
841c2c66affSColin Finck UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
842c2c66affSColin Finck {
843c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
844c2c66affSColin Finck struct wined3d_swapchain *wined3d_swapchain;
845c2c66affSColin Finck struct wined3d_texture *wined3d_texture;
846c2c66affSColin Finck struct d3d8_surface *surface_impl;
847c2c66affSColin Finck
848c2c66affSColin Finck TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
849c2c66affSColin Finck iface, backbuffer_idx, backbuffer_type, backbuffer);
850c2c66affSColin Finck
851c2c66affSColin Finck /* backbuffer_type is ignored by native. */
852c2c66affSColin Finck
853c2c66affSColin Finck /* No need to check for backbuffer == NULL, Windows crashes in that case. */
854c2c66affSColin Finck wined3d_mutex_lock();
855c2c66affSColin Finck
856c2c66affSColin Finck wined3d_swapchain = device->implicit_swapchain->wined3d_swapchain;
857c2c66affSColin Finck if (!(wined3d_texture = wined3d_swapchain_get_back_buffer(wined3d_swapchain, backbuffer_idx)))
858c2c66affSColin Finck {
859c2c66affSColin Finck wined3d_mutex_unlock();
860c2c66affSColin Finck *backbuffer = NULL;
861c2c66affSColin Finck return D3DERR_INVALIDCALL;
862c2c66affSColin Finck }
863c2c66affSColin Finck
864c2c66affSColin Finck surface_impl = wined3d_texture_get_sub_resource_parent(wined3d_texture, 0);
865c2c66affSColin Finck *backbuffer = &surface_impl->IDirect3DSurface8_iface;
866c2c66affSColin Finck IDirect3DSurface8_AddRef(*backbuffer);
867c2c66affSColin Finck
868c2c66affSColin Finck wined3d_mutex_unlock();
869c2c66affSColin Finck return D3D_OK;
870c2c66affSColin Finck }
871c2c66affSColin Finck
d3d8_device_GetRasterStatus(IDirect3DDevice8 * iface,D3DRASTER_STATUS * raster_status)872c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetRasterStatus(IDirect3DDevice8 *iface, D3DRASTER_STATUS *raster_status)
873c2c66affSColin Finck {
874c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
875c2c66affSColin Finck HRESULT hr;
876c2c66affSColin Finck
877c2c66affSColin Finck TRACE("iface %p, raster_status %p.\n", iface, raster_status);
878c2c66affSColin Finck
879c2c66affSColin Finck wined3d_mutex_lock();
880c2c66affSColin Finck hr = wined3d_device_get_raster_status(device->wined3d_device, 0, (struct wined3d_raster_status *)raster_status);
881c2c66affSColin Finck wined3d_mutex_unlock();
882c2c66affSColin Finck
883c2c66affSColin Finck return hr;
884c2c66affSColin Finck }
885c2c66affSColin Finck
d3d8_device_SetGammaRamp(IDirect3DDevice8 * iface,DWORD flags,const D3DGAMMARAMP * ramp)886c2c66affSColin Finck static void WINAPI d3d8_device_SetGammaRamp(IDirect3DDevice8 *iface, DWORD flags, const D3DGAMMARAMP *ramp)
887c2c66affSColin Finck {
888c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
889c2c66affSColin Finck
890c2c66affSColin Finck TRACE("iface %p, flags %#x, ramp %p.\n", iface, flags, ramp);
891c2c66affSColin Finck
892c2c66affSColin Finck /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
893c2c66affSColin Finck wined3d_mutex_lock();
894c2c66affSColin Finck wined3d_device_set_gamma_ramp(device->wined3d_device, 0, flags, (const struct wined3d_gamma_ramp *)ramp);
895c2c66affSColin Finck wined3d_mutex_unlock();
896c2c66affSColin Finck }
897c2c66affSColin Finck
d3d8_device_GetGammaRamp(IDirect3DDevice8 * iface,D3DGAMMARAMP * ramp)898c2c66affSColin Finck static void WINAPI d3d8_device_GetGammaRamp(IDirect3DDevice8 *iface, D3DGAMMARAMP *ramp)
899c2c66affSColin Finck {
900c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
901c2c66affSColin Finck
902c2c66affSColin Finck TRACE("iface %p, ramp %p.\n", iface, ramp);
903c2c66affSColin Finck
904c2c66affSColin Finck /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
905c2c66affSColin Finck wined3d_mutex_lock();
906c2c66affSColin Finck wined3d_device_get_gamma_ramp(device->wined3d_device, 0, (struct wined3d_gamma_ramp *)ramp);
907c2c66affSColin Finck wined3d_mutex_unlock();
908c2c66affSColin Finck }
909c2c66affSColin Finck
d3d8_device_CreateTexture(IDirect3DDevice8 * iface,UINT width,UINT height,UINT levels,DWORD usage,D3DFORMAT format,D3DPOOL pool,IDirect3DTexture8 ** texture)910c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateTexture(IDirect3DDevice8 *iface,
911c2c66affSColin Finck UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
912c2c66affSColin Finck D3DPOOL pool, IDirect3DTexture8 **texture)
913c2c66affSColin Finck {
914c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
915c2c66affSColin Finck struct d3d8_texture *object;
916c2c66affSColin Finck HRESULT hr;
917c2c66affSColin Finck
918c2c66affSColin Finck TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
919c2c66affSColin Finck iface, width, height, levels, usage, format, pool, texture);
920c2c66affSColin Finck
921c2c66affSColin Finck if (!format)
922c2c66affSColin Finck return D3DERR_INVALIDCALL;
923c2c66affSColin Finck
924c2c66affSColin Finck *texture = NULL;
9259987f029SAmine Khaldi if (!(object = heap_alloc_zero(sizeof(*object))))
926c2c66affSColin Finck return D3DERR_OUTOFVIDEOMEMORY;
927c2c66affSColin Finck
928c2c66affSColin Finck hr = texture_init(object, device, width, height, levels, usage, format, pool);
929c2c66affSColin Finck if (FAILED(hr))
930c2c66affSColin Finck {
931c2c66affSColin Finck WARN("Failed to initialize texture, hr %#x.\n", hr);
9329987f029SAmine Khaldi heap_free(object);
933c2c66affSColin Finck return hr;
934c2c66affSColin Finck }
935c2c66affSColin Finck
936c2c66affSColin Finck TRACE("Created texture %p.\n", object);
937c2c66affSColin Finck *texture = (IDirect3DTexture8 *)&object->IDirect3DBaseTexture8_iface;
938c2c66affSColin Finck
939c2c66affSColin Finck return D3D_OK;
940c2c66affSColin Finck }
941c2c66affSColin Finck
d3d8_device_CreateVolumeTexture(IDirect3DDevice8 * iface,UINT width,UINT height,UINT depth,UINT levels,DWORD usage,D3DFORMAT format,D3DPOOL pool,IDirect3DVolumeTexture8 ** texture)942c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateVolumeTexture(IDirect3DDevice8 *iface,
943c2c66affSColin Finck UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
944c2c66affSColin Finck D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
945c2c66affSColin Finck {
946c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
947c2c66affSColin Finck struct d3d8_texture *object;
948c2c66affSColin Finck HRESULT hr;
949c2c66affSColin Finck
950c2c66affSColin Finck TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
951c2c66affSColin Finck iface, width, height, depth, levels, usage, format, pool, texture);
952c2c66affSColin Finck
953c2c66affSColin Finck if (!format)
954c2c66affSColin Finck return D3DERR_INVALIDCALL;
955c2c66affSColin Finck
956c2c66affSColin Finck *texture = NULL;
9579987f029SAmine Khaldi if (!(object = heap_alloc_zero(sizeof(*object))))
958c2c66affSColin Finck return D3DERR_OUTOFVIDEOMEMORY;
959c2c66affSColin Finck
960c2c66affSColin Finck hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool);
961c2c66affSColin Finck if (FAILED(hr))
962c2c66affSColin Finck {
963c2c66affSColin Finck WARN("Failed to initialize volume texture, hr %#x.\n", hr);
9649987f029SAmine Khaldi heap_free(object);
965c2c66affSColin Finck return hr;
966c2c66affSColin Finck }
967c2c66affSColin Finck
968c2c66affSColin Finck TRACE("Created volume texture %p.\n", object);
969c2c66affSColin Finck *texture = (IDirect3DVolumeTexture8 *)&object->IDirect3DBaseTexture8_iface;
970c2c66affSColin Finck
971c2c66affSColin Finck return D3D_OK;
972c2c66affSColin Finck }
973c2c66affSColin Finck
d3d8_device_CreateCubeTexture(IDirect3DDevice8 * iface,UINT edge_length,UINT levels,DWORD usage,D3DFORMAT format,D3DPOOL pool,IDirect3DCubeTexture8 ** texture)974c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
975c2c66affSColin Finck UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
976c2c66affSColin Finck {
977c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
978c2c66affSColin Finck struct d3d8_texture *object;
979c2c66affSColin Finck HRESULT hr;
980c2c66affSColin Finck
981c2c66affSColin Finck TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
982c2c66affSColin Finck iface, edge_length, levels, usage, format, pool, texture);
983c2c66affSColin Finck
984c2c66affSColin Finck if (!format)
985c2c66affSColin Finck return D3DERR_INVALIDCALL;
986c2c66affSColin Finck
987c2c66affSColin Finck *texture = NULL;
9889987f029SAmine Khaldi if (!(object = heap_alloc_zero(sizeof(*object))))
989c2c66affSColin Finck return D3DERR_OUTOFVIDEOMEMORY;
990c2c66affSColin Finck
991c2c66affSColin Finck hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool);
992c2c66affSColin Finck if (FAILED(hr))
993c2c66affSColin Finck {
994c2c66affSColin Finck WARN("Failed to initialize cube texture, hr %#x.\n", hr);
9959987f029SAmine Khaldi heap_free(object);
996c2c66affSColin Finck return hr;
997c2c66affSColin Finck }
998c2c66affSColin Finck
999c2c66affSColin Finck TRACE("Created cube texture %p.\n", object);
1000c2c66affSColin Finck *texture = (IDirect3DCubeTexture8 *)&object->IDirect3DBaseTexture8_iface;
1001c2c66affSColin Finck
1002c2c66affSColin Finck return hr;
1003c2c66affSColin Finck }
1004c2c66affSColin Finck
d3d8_device_CreateVertexBuffer(IDirect3DDevice8 * iface,UINT size,DWORD usage,DWORD fvf,D3DPOOL pool,IDirect3DVertexBuffer8 ** buffer)1005c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size,
1006c2c66affSColin Finck DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
1007c2c66affSColin Finck {
1008c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1009c2c66affSColin Finck struct d3d8_vertexbuffer *object;
1010c2c66affSColin Finck HRESULT hr;
1011c2c66affSColin Finck
1012c2c66affSColin Finck TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
1013c2c66affSColin Finck iface, size, usage, fvf, pool, buffer);
1014c2c66affSColin Finck
10159987f029SAmine Khaldi if (!(object = heap_alloc_zero(sizeof(*object))))
1016c2c66affSColin Finck return D3DERR_OUTOFVIDEOMEMORY;
1017c2c66affSColin Finck
1018c2c66affSColin Finck hr = vertexbuffer_init(object, device, size, usage, fvf, pool);
1019c2c66affSColin Finck if (FAILED(hr))
1020c2c66affSColin Finck {
1021c2c66affSColin Finck WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
10229987f029SAmine Khaldi heap_free(object);
1023c2c66affSColin Finck return hr;
1024c2c66affSColin Finck }
1025c2c66affSColin Finck
1026c2c66affSColin Finck TRACE("Created vertex buffer %p.\n", object);
1027c2c66affSColin Finck *buffer = &object->IDirect3DVertexBuffer8_iface;
1028c2c66affSColin Finck
1029c2c66affSColin Finck return D3D_OK;
1030c2c66affSColin Finck }
1031c2c66affSColin Finck
d3d8_device_CreateIndexBuffer(IDirect3DDevice8 * iface,UINT size,DWORD usage,D3DFORMAT format,D3DPOOL pool,IDirect3DIndexBuffer8 ** buffer)1032c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size,
1033c2c66affSColin Finck DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
1034c2c66affSColin Finck {
1035c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1036c2c66affSColin Finck struct d3d8_indexbuffer *object;
1037c2c66affSColin Finck HRESULT hr;
1038c2c66affSColin Finck
1039c2c66affSColin Finck TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
1040c2c66affSColin Finck iface, size, usage, format, pool, buffer);
1041c2c66affSColin Finck
10429987f029SAmine Khaldi if (!(object = heap_alloc_zero(sizeof(*object))))
1043c2c66affSColin Finck return D3DERR_OUTOFVIDEOMEMORY;
1044c2c66affSColin Finck
1045c2c66affSColin Finck hr = indexbuffer_init(object, device, size, usage, format, pool);
1046c2c66affSColin Finck if (FAILED(hr))
1047c2c66affSColin Finck {
1048c2c66affSColin Finck WARN("Failed to initialize index buffer, hr %#x.\n", hr);
10499987f029SAmine Khaldi heap_free(object);
1050c2c66affSColin Finck return hr;
1051c2c66affSColin Finck }
1052c2c66affSColin Finck
1053c2c66affSColin Finck TRACE("Created index buffer %p.\n", object);
1054c2c66affSColin Finck *buffer = &object->IDirect3DIndexBuffer8_iface;
1055c2c66affSColin Finck
1056c2c66affSColin Finck return D3D_OK;
1057c2c66affSColin Finck }
1058c2c66affSColin Finck
d3d8_device_create_surface(struct d3d8_device * device,UINT width,UINT height,D3DFORMAT format,DWORD flags,IDirect3DSurface8 ** surface,UINT usage,D3DPOOL pool,D3DMULTISAMPLE_TYPE multisample_type,DWORD multisample_quality)1059c2c66affSColin Finck static HRESULT d3d8_device_create_surface(struct d3d8_device *device, UINT width, UINT height,
1060c2c66affSColin Finck D3DFORMAT format, DWORD flags, IDirect3DSurface8 **surface, UINT usage, D3DPOOL pool,
1061c2c66affSColin Finck D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
1062c2c66affSColin Finck {
1063c2c66affSColin Finck struct wined3d_resource_desc desc;
1064c2c66affSColin Finck struct d3d8_surface *surface_impl;
1065c2c66affSColin Finck struct wined3d_texture *texture;
1066c2c66affSColin Finck HRESULT hr;
1067c2c66affSColin Finck
1068c2c66affSColin Finck TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p, "
1069c2c66affSColin Finck "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
1070c2c66affSColin Finck device, width, height, format, flags, surface,
1071c2c66affSColin Finck usage, pool, multisample_type, multisample_quality);
1072c2c66affSColin Finck
1073c2c66affSColin Finck desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
1074c2c66affSColin Finck desc.format = wined3dformat_from_d3dformat(format);
1075c2c66affSColin Finck desc.multisample_type = multisample_type;
1076c2c66affSColin Finck desc.multisample_quality = multisample_quality;
1077c2c66affSColin Finck desc.usage = usage & WINED3DUSAGE_MASK;
10789987f029SAmine Khaldi if (pool == D3DPOOL_SCRATCH)
10799987f029SAmine Khaldi desc.usage |= WINED3DUSAGE_SCRATCH;
10809987f029SAmine Khaldi desc.access = wined3daccess_from_d3dpool(pool, usage)
10819987f029SAmine Khaldi | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
1082c2c66affSColin Finck desc.width = width;
1083c2c66affSColin Finck desc.height = height;
1084c2c66affSColin Finck desc.depth = 1;
1085c2c66affSColin Finck desc.size = 0;
1086c2c66affSColin Finck
1087c2c66affSColin Finck wined3d_mutex_lock();
1088c2c66affSColin Finck
1089c2c66affSColin Finck if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &desc,
1090c2c66affSColin Finck 1, 1, flags, NULL, NULL, &d3d8_null_wined3d_parent_ops, &texture)))
1091c2c66affSColin Finck {
1092c2c66affSColin Finck wined3d_mutex_unlock();
1093c2c66affSColin Finck WARN("Failed to create texture, hr %#x.\n", hr);
1094c2c66affSColin Finck return hr;
1095c2c66affSColin Finck }
1096c2c66affSColin Finck
1097c2c66affSColin Finck surface_impl = wined3d_texture_get_sub_resource_parent(texture, 0);
1098c2c66affSColin Finck surface_impl->parent_device = &device->IDirect3DDevice8_iface;
1099c2c66affSColin Finck *surface = &surface_impl->IDirect3DSurface8_iface;
1100c2c66affSColin Finck IDirect3DSurface8_AddRef(*surface);
1101c2c66affSColin Finck wined3d_texture_decref(texture);
1102c2c66affSColin Finck
1103c2c66affSColin Finck wined3d_mutex_unlock();
1104c2c66affSColin Finck
1105c2c66affSColin Finck return D3D_OK;
1106c2c66affSColin Finck }
1107c2c66affSColin Finck
d3d8_device_CreateRenderTarget(IDirect3DDevice8 * iface,UINT width,UINT height,D3DFORMAT format,D3DMULTISAMPLE_TYPE multisample_type,BOOL lockable,IDirect3DSurface8 ** surface)1108c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateRenderTarget(IDirect3DDevice8 *iface, UINT width,
1109c2c66affSColin Finck UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, BOOL lockable,
1110c2c66affSColin Finck IDirect3DSurface8 **surface)
1111c2c66affSColin Finck {
1112c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1113c2c66affSColin Finck DWORD flags = 0;
1114c2c66affSColin Finck
1115c2c66affSColin Finck TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
1116c2c66affSColin Finck iface, width, height, format, multisample_type, lockable, surface);
1117c2c66affSColin Finck
1118c2c66affSColin Finck if (!format)
1119c2c66affSColin Finck return D3DERR_INVALIDCALL;
1120c2c66affSColin Finck
1121c2c66affSColin Finck *surface = NULL;
1122c2c66affSColin Finck if (lockable)
1123c2c66affSColin Finck flags |= WINED3D_TEXTURE_CREATE_MAPPABLE;
1124c2c66affSColin Finck
1125c2c66affSColin Finck return d3d8_device_create_surface(device, width, height, format, flags, surface,
1126c2c66affSColin Finck D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, multisample_type, 0);
1127c2c66affSColin Finck }
1128c2c66affSColin Finck
d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8 * iface,UINT width,UINT height,D3DFORMAT format,D3DMULTISAMPLE_TYPE multisample_type,IDirect3DSurface8 ** surface)1129c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8 *iface,
1130c2c66affSColin Finck UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type,
1131c2c66affSColin Finck IDirect3DSurface8 **surface)
1132c2c66affSColin Finck {
1133c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1134c2c66affSColin Finck
1135c2c66affSColin Finck TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
1136c2c66affSColin Finck iface, width, height, format, multisample_type, surface);
1137c2c66affSColin Finck
1138c2c66affSColin Finck if (!format)
1139c2c66affSColin Finck return D3DERR_INVALIDCALL;
1140c2c66affSColin Finck
1141c2c66affSColin Finck *surface = NULL;
1142c2c66affSColin Finck
1143c2c66affSColin Finck /* TODO: Verify that Discard is false */
1144c2c66affSColin Finck return d3d8_device_create_surface(device, width, height, format, WINED3D_TEXTURE_CREATE_MAPPABLE,
1145c2c66affSColin Finck surface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, multisample_type, 0);
1146c2c66affSColin Finck }
1147c2c66affSColin Finck
1148c2c66affSColin Finck /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
d3d8_device_CreateImageSurface(IDirect3DDevice8 * iface,UINT width,UINT height,D3DFORMAT format,IDirect3DSurface8 ** surface)1149c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateImageSurface(IDirect3DDevice8 *iface, UINT width,
1150c2c66affSColin Finck UINT height, D3DFORMAT format, IDirect3DSurface8 **surface)
1151c2c66affSColin Finck {
1152c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1153c2c66affSColin Finck
1154c2c66affSColin Finck TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
1155c2c66affSColin Finck iface, width, height, format, surface);
1156c2c66affSColin Finck
1157c2c66affSColin Finck *surface = NULL;
1158c2c66affSColin Finck
1159c2c66affSColin Finck return d3d8_device_create_surface(device, width, height, format, WINED3D_TEXTURE_CREATE_MAPPABLE,
1160c2c66affSColin Finck surface, 0, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0);
1161c2c66affSColin Finck }
1162c2c66affSColin Finck
d3d8_device_CopyRects(IDirect3DDevice8 * iface,IDirect3DSurface8 * src_surface,const RECT * src_rects,UINT rect_count,IDirect3DSurface8 * dst_surface,const POINT * dst_points)1163c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CopyRects(IDirect3DDevice8 *iface,
1164c2c66affSColin Finck IDirect3DSurface8 *src_surface, const RECT *src_rects, UINT rect_count,
1165c2c66affSColin Finck IDirect3DSurface8 *dst_surface, const POINT *dst_points)
1166c2c66affSColin Finck {
1167c2c66affSColin Finck struct d3d8_surface *src = unsafe_impl_from_IDirect3DSurface8(src_surface);
1168c2c66affSColin Finck struct d3d8_surface *dst = unsafe_impl_from_IDirect3DSurface8(dst_surface);
1169c2c66affSColin Finck enum wined3d_format_id src_format, dst_format;
1170c2c66affSColin Finck struct wined3d_sub_resource_desc wined3d_desc;
1171c2c66affSColin Finck UINT src_w, src_h;
1172c2c66affSColin Finck
1173c2c66affSColin Finck TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
1174c2c66affSColin Finck iface, src_surface, src_rects, rect_count, dst_surface, dst_points);
1175c2c66affSColin Finck
1176c2c66affSColin Finck /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
1177c2c66affSColin Finck * destination texture is in WINED3D_POOL_DEFAULT. */
1178c2c66affSColin Finck
1179c2c66affSColin Finck wined3d_mutex_lock();
1180c2c66affSColin Finck wined3d_texture_get_sub_resource_desc(src->wined3d_texture, src->sub_resource_idx, &wined3d_desc);
1181c2c66affSColin Finck if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
1182c2c66affSColin Finck {
1183c2c66affSColin Finck WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface);
1184c2c66affSColin Finck wined3d_mutex_unlock();
1185c2c66affSColin Finck return D3DERR_INVALIDCALL;
1186c2c66affSColin Finck }
1187c2c66affSColin Finck src_format = wined3d_desc.format;
1188c2c66affSColin Finck src_w = wined3d_desc.width;
1189c2c66affSColin Finck src_h = wined3d_desc.height;
1190c2c66affSColin Finck
1191c2c66affSColin Finck wined3d_texture_get_sub_resource_desc(dst->wined3d_texture, dst->sub_resource_idx, &wined3d_desc);
1192c2c66affSColin Finck if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
1193c2c66affSColin Finck {
1194c2c66affSColin Finck WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface);
1195c2c66affSColin Finck wined3d_mutex_unlock();
1196c2c66affSColin Finck return D3DERR_INVALIDCALL;
1197c2c66affSColin Finck }
1198c2c66affSColin Finck dst_format = wined3d_desc.format;
1199c2c66affSColin Finck
1200c2c66affSColin Finck /* Check that the source and destination formats match */
1201c2c66affSColin Finck if (src_format != dst_format)
1202c2c66affSColin Finck {
1203c2c66affSColin Finck WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
1204c2c66affSColin Finck src_surface, dst_surface);
1205c2c66affSColin Finck wined3d_mutex_unlock();
1206c2c66affSColin Finck return D3DERR_INVALIDCALL;
1207c2c66affSColin Finck }
1208c2c66affSColin Finck
1209c2c66affSColin Finck /* Quick if complete copy ... */
1210c2c66affSColin Finck if (!rect_count && !src_rects && !dst_points)
1211c2c66affSColin Finck {
1212c2c66affSColin Finck RECT rect = {0, 0, src_w, src_h};
1213c2c66affSColin Finck wined3d_texture_blt(dst->wined3d_texture, dst->sub_resource_idx, &rect,
1214c2c66affSColin Finck src->wined3d_texture, src->sub_resource_idx, &rect, 0, NULL, WINED3D_TEXF_POINT);
1215c2c66affSColin Finck }
1216c2c66affSColin Finck else
1217c2c66affSColin Finck {
1218c2c66affSColin Finck unsigned int i;
1219c2c66affSColin Finck /* Copy rect by rect */
1220c2c66affSColin Finck if (src_rects && dst_points)
1221c2c66affSColin Finck {
1222c2c66affSColin Finck for (i = 0; i < rect_count; ++i)
1223c2c66affSColin Finck {
1224c2c66affSColin Finck UINT w = src_rects[i].right - src_rects[i].left;
1225c2c66affSColin Finck UINT h = src_rects[i].bottom - src_rects[i].top;
1226c2c66affSColin Finck RECT dst_rect = {dst_points[i].x, dst_points[i].y,
1227c2c66affSColin Finck dst_points[i].x + w, dst_points[i].y + h};
1228c2c66affSColin Finck
1229c2c66affSColin Finck wined3d_texture_blt(dst->wined3d_texture, dst->sub_resource_idx, &dst_rect,
1230c2c66affSColin Finck src->wined3d_texture, src->sub_resource_idx, &src_rects[i], 0, NULL, WINED3D_TEXF_POINT);
1231c2c66affSColin Finck }
1232c2c66affSColin Finck }
1233c2c66affSColin Finck else
1234c2c66affSColin Finck {
1235c2c66affSColin Finck for (i = 0; i < rect_count; ++i)
1236c2c66affSColin Finck {
1237c2c66affSColin Finck UINT w = src_rects[i].right - src_rects[i].left;
1238c2c66affSColin Finck UINT h = src_rects[i].bottom - src_rects[i].top;
1239c2c66affSColin Finck RECT dst_rect = {0, 0, w, h};
1240c2c66affSColin Finck
1241c2c66affSColin Finck wined3d_texture_blt(dst->wined3d_texture, dst->sub_resource_idx, &dst_rect,
1242c2c66affSColin Finck src->wined3d_texture, src->sub_resource_idx, &src_rects[i], 0, NULL, WINED3D_TEXF_POINT);
1243c2c66affSColin Finck }
1244c2c66affSColin Finck }
1245c2c66affSColin Finck }
1246c2c66affSColin Finck wined3d_mutex_unlock();
1247c2c66affSColin Finck
1248c2c66affSColin Finck return WINED3D_OK;
1249c2c66affSColin Finck }
1250c2c66affSColin Finck
d3d8_device_UpdateTexture(IDirect3DDevice8 * iface,IDirect3DBaseTexture8 * src_texture,IDirect3DBaseTexture8 * dst_texture)1251c2c66affSColin Finck static HRESULT WINAPI d3d8_device_UpdateTexture(IDirect3DDevice8 *iface,
1252c2c66affSColin Finck IDirect3DBaseTexture8 *src_texture, IDirect3DBaseTexture8 *dst_texture)
1253c2c66affSColin Finck {
1254c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1255c2c66affSColin Finck struct d3d8_texture *src_impl, *dst_impl;
1256c2c66affSColin Finck HRESULT hr;
1257c2c66affSColin Finck
1258c2c66affSColin Finck TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1259c2c66affSColin Finck
1260c2c66affSColin Finck src_impl = unsafe_impl_from_IDirect3DBaseTexture8(src_texture);
1261c2c66affSColin Finck dst_impl = unsafe_impl_from_IDirect3DBaseTexture8(dst_texture);
1262c2c66affSColin Finck
1263c2c66affSColin Finck wined3d_mutex_lock();
1264c2c66affSColin Finck hr = wined3d_device_update_texture(device->wined3d_device,
1265c2c66affSColin Finck src_impl->wined3d_texture, dst_impl->wined3d_texture);
1266c2c66affSColin Finck wined3d_mutex_unlock();
1267c2c66affSColin Finck
1268c2c66affSColin Finck return hr;
1269c2c66affSColin Finck }
1270c2c66affSColin Finck
d3d8_device_GetFrontBuffer(IDirect3DDevice8 * iface,IDirect3DSurface8 * dst_surface)1271c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetFrontBuffer(IDirect3DDevice8 *iface, IDirect3DSurface8 *dst_surface)
1272c2c66affSColin Finck {
1273c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1274c2c66affSColin Finck struct d3d8_surface *dst_impl = unsafe_impl_from_IDirect3DSurface8(dst_surface);
1275c2c66affSColin Finck HRESULT hr;
1276c2c66affSColin Finck
1277c2c66affSColin Finck TRACE("iface %p, dst_surface %p.\n", iface, dst_surface);
1278c2c66affSColin Finck
1279c2c66affSColin Finck if (!dst_surface)
1280c2c66affSColin Finck {
1281c2c66affSColin Finck WARN("Invalid destination surface passed.\n");
1282c2c66affSColin Finck return D3DERR_INVALIDCALL;
1283c2c66affSColin Finck }
1284c2c66affSColin Finck
1285c2c66affSColin Finck wined3d_mutex_lock();
1286c2c66affSColin Finck hr = wined3d_swapchain_get_front_buffer_data(device->implicit_swapchain->wined3d_swapchain,
1287c2c66affSColin Finck dst_impl->wined3d_texture, dst_impl->sub_resource_idx);
1288c2c66affSColin Finck wined3d_mutex_unlock();
1289c2c66affSColin Finck
1290c2c66affSColin Finck return hr;
1291c2c66affSColin Finck }
1292c2c66affSColin Finck
d3d8_device_SetRenderTarget(IDirect3DDevice8 * iface,IDirect3DSurface8 * render_target,IDirect3DSurface8 * depth_stencil)1293c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
1294c2c66affSColin Finck IDirect3DSurface8 *render_target, IDirect3DSurface8 *depth_stencil)
1295c2c66affSColin Finck {
1296c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1297c2c66affSColin Finck struct d3d8_surface *rt_impl = unsafe_impl_from_IDirect3DSurface8(render_target);
1298c2c66affSColin Finck struct d3d8_surface *ds_impl = unsafe_impl_from_IDirect3DSurface8(depth_stencil);
1299c2c66affSColin Finck struct wined3d_rendertarget_view *original_dsv, *rtv;
1300c2c66affSColin Finck HRESULT hr = D3D_OK;
1301c2c66affSColin Finck
1302c2c66affSColin Finck TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, render_target, depth_stencil);
1303c2c66affSColin Finck
1304c2c66affSColin Finck if (rt_impl && d3d8_surface_get_device(rt_impl) != device)
1305c2c66affSColin Finck {
1306c2c66affSColin Finck WARN("Render target surface does not match device.\n");
1307c2c66affSColin Finck return D3DERR_INVALIDCALL;
1308c2c66affSColin Finck }
1309c2c66affSColin Finck
1310c2c66affSColin Finck wined3d_mutex_lock();
1311c2c66affSColin Finck
1312c2c66affSColin Finck if (ds_impl)
1313c2c66affSColin Finck {
1314c2c66affSColin Finck struct wined3d_sub_resource_desc ds_desc, rt_desc;
1315c2c66affSColin Finck struct wined3d_rendertarget_view *original_rtv;
1316c2c66affSColin Finck struct d3d8_surface *original_surface;
1317c2c66affSColin Finck
1318c2c66affSColin Finck /* If no render target is passed in check the size against the current RT */
1319c2c66affSColin Finck if (!render_target)
1320c2c66affSColin Finck {
1321c2c66affSColin Finck if (!(original_rtv = wined3d_device_get_rendertarget_view(device->wined3d_device, 0)))
1322c2c66affSColin Finck {
1323c2c66affSColin Finck wined3d_mutex_unlock();
1324c2c66affSColin Finck return D3DERR_NOTFOUND;
1325c2c66affSColin Finck }
1326c2c66affSColin Finck original_surface = wined3d_rendertarget_view_get_sub_resource_parent(original_rtv);
1327c2c66affSColin Finck wined3d_texture_get_sub_resource_desc(original_surface->wined3d_texture,
1328c2c66affSColin Finck original_surface->sub_resource_idx, &rt_desc);
1329c2c66affSColin Finck }
1330c2c66affSColin Finck else
1331c2c66affSColin Finck wined3d_texture_get_sub_resource_desc(rt_impl->wined3d_texture,
1332c2c66affSColin Finck rt_impl->sub_resource_idx, &rt_desc);
1333c2c66affSColin Finck
1334c2c66affSColin Finck wined3d_texture_get_sub_resource_desc(ds_impl->wined3d_texture, ds_impl->sub_resource_idx, &ds_desc);
1335c2c66affSColin Finck
1336c2c66affSColin Finck if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
1337c2c66affSColin Finck {
1338c2c66affSColin Finck WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1339c2c66affSColin Finck wined3d_mutex_unlock();
1340c2c66affSColin Finck return D3DERR_INVALIDCALL;
1341c2c66affSColin Finck }
1342c2c66affSColin Finck if (ds_desc.multisample_type != rt_desc.multisample_type
1343c2c66affSColin Finck || ds_desc.multisample_quality != rt_desc.multisample_quality)
1344c2c66affSColin Finck {
1345c2c66affSColin Finck WARN("Multisample settings do not match, returning D3DERR_INVALIDCALL\n");
1346c2c66affSColin Finck wined3d_mutex_unlock();
1347c2c66affSColin Finck return D3DERR_INVALIDCALL;
1348c2c66affSColin Finck }
1349c2c66affSColin Finck }
1350c2c66affSColin Finck
1351c2c66affSColin Finck original_dsv = wined3d_device_get_depth_stencil_view(device->wined3d_device);
1352c2c66affSColin Finck rtv = ds_impl ? d3d8_surface_acquire_rendertarget_view(ds_impl) : NULL;
1353c2c66affSColin Finck wined3d_device_set_depth_stencil_view(device->wined3d_device, rtv);
1354c2c66affSColin Finck d3d8_surface_release_rendertarget_view(ds_impl, rtv);
1355c2c66affSColin Finck rtv = render_target ? d3d8_surface_acquire_rendertarget_view(rt_impl) : NULL;
1356c2c66affSColin Finck if (render_target && FAILED(hr = wined3d_device_set_rendertarget_view(device->wined3d_device, 0, rtv, TRUE)))
1357c2c66affSColin Finck wined3d_device_set_depth_stencil_view(device->wined3d_device, original_dsv);
1358c2c66affSColin Finck d3d8_surface_release_rendertarget_view(rt_impl, rtv);
1359c2c66affSColin Finck
1360c2c66affSColin Finck wined3d_mutex_unlock();
1361c2c66affSColin Finck
1362c2c66affSColin Finck return hr;
1363c2c66affSColin Finck }
1364c2c66affSColin Finck
d3d8_device_GetRenderTarget(IDirect3DDevice8 * iface,IDirect3DSurface8 ** render_target)1365c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetRenderTarget(IDirect3DDevice8 *iface, IDirect3DSurface8 **render_target)
1366c2c66affSColin Finck {
1367c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1368c2c66affSColin Finck struct wined3d_rendertarget_view *wined3d_rtv;
1369c2c66affSColin Finck struct d3d8_surface *surface_impl;
1370c2c66affSColin Finck HRESULT hr;
1371c2c66affSColin Finck
1372c2c66affSColin Finck TRACE("iface %p, render_target %p.\n", iface, render_target);
1373c2c66affSColin Finck
1374c2c66affSColin Finck if (!render_target)
1375c2c66affSColin Finck return D3DERR_INVALIDCALL;
1376c2c66affSColin Finck
1377c2c66affSColin Finck wined3d_mutex_lock();
1378c2c66affSColin Finck if ((wined3d_rtv = wined3d_device_get_rendertarget_view(device->wined3d_device, 0)))
1379c2c66affSColin Finck {
1380c2c66affSColin Finck /* We want the sub resource parent here, since the view itself may be
1381c2c66affSColin Finck * internal to wined3d and may not have a parent. */
1382c2c66affSColin Finck surface_impl = wined3d_rendertarget_view_get_sub_resource_parent(wined3d_rtv);
1383c2c66affSColin Finck *render_target = &surface_impl->IDirect3DSurface8_iface;
1384c2c66affSColin Finck IDirect3DSurface8_AddRef(*render_target);
1385c2c66affSColin Finck hr = D3D_OK;
1386c2c66affSColin Finck }
1387c2c66affSColin Finck else
1388c2c66affSColin Finck {
1389c2c66affSColin Finck ERR("Failed to get wined3d render target.\n");
1390c2c66affSColin Finck *render_target = NULL;
1391c2c66affSColin Finck hr = D3DERR_NOTFOUND;
1392c2c66affSColin Finck }
1393c2c66affSColin Finck wined3d_mutex_unlock();
1394c2c66affSColin Finck
1395c2c66affSColin Finck return hr;
1396c2c66affSColin Finck }
1397c2c66affSColin Finck
d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 * iface,IDirect3DSurface8 ** depth_stencil)1398c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface, IDirect3DSurface8 **depth_stencil)
1399c2c66affSColin Finck {
1400c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1401c2c66affSColin Finck struct wined3d_rendertarget_view *wined3d_dsv;
1402c2c66affSColin Finck struct d3d8_surface *surface_impl;
1403c2c66affSColin Finck HRESULT hr = D3D_OK;
1404c2c66affSColin Finck
1405c2c66affSColin Finck TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
1406c2c66affSColin Finck
1407c2c66affSColin Finck if (!depth_stencil)
1408c2c66affSColin Finck return D3DERR_INVALIDCALL;
1409c2c66affSColin Finck
1410c2c66affSColin Finck wined3d_mutex_lock();
1411c2c66affSColin Finck if ((wined3d_dsv = wined3d_device_get_depth_stencil_view(device->wined3d_device)))
1412c2c66affSColin Finck {
1413c2c66affSColin Finck /* We want the sub resource parent here, since the view itself may be
1414c2c66affSColin Finck * internal to wined3d and may not have a parent. */
1415c2c66affSColin Finck surface_impl = wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv);
1416c2c66affSColin Finck *depth_stencil = &surface_impl->IDirect3DSurface8_iface;
1417c2c66affSColin Finck IDirect3DSurface8_AddRef(*depth_stencil);
1418c2c66affSColin Finck }
1419c2c66affSColin Finck else
1420c2c66affSColin Finck {
1421c2c66affSColin Finck hr = D3DERR_NOTFOUND;
1422c2c66affSColin Finck *depth_stencil = NULL;
1423c2c66affSColin Finck }
1424c2c66affSColin Finck wined3d_mutex_unlock();
1425c2c66affSColin Finck
1426c2c66affSColin Finck return hr;
1427c2c66affSColin Finck }
1428c2c66affSColin Finck
d3d8_device_BeginScene(IDirect3DDevice8 * iface)1429c2c66affSColin Finck static HRESULT WINAPI d3d8_device_BeginScene(IDirect3DDevice8 *iface)
1430c2c66affSColin Finck {
1431c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1432c2c66affSColin Finck HRESULT hr;
1433c2c66affSColin Finck
1434c2c66affSColin Finck TRACE("iface %p.\n", iface);
1435c2c66affSColin Finck
1436c2c66affSColin Finck wined3d_mutex_lock();
1437c2c66affSColin Finck hr = wined3d_device_begin_scene(device->wined3d_device);
1438c2c66affSColin Finck wined3d_mutex_unlock();
1439c2c66affSColin Finck
1440c2c66affSColin Finck return hr;
1441c2c66affSColin Finck }
1442c2c66affSColin Finck
d3d8_device_EndScene(IDirect3DDevice8 * iface)1443c2c66affSColin Finck static HRESULT WINAPI DECLSPEC_HOTPATCH d3d8_device_EndScene(IDirect3DDevice8 *iface)
1444c2c66affSColin Finck {
1445c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1446c2c66affSColin Finck HRESULT hr;
1447c2c66affSColin Finck
1448c2c66affSColin Finck TRACE("iface %p.\n", iface);
1449c2c66affSColin Finck
1450c2c66affSColin Finck wined3d_mutex_lock();
1451c2c66affSColin Finck hr = wined3d_device_end_scene(device->wined3d_device);
1452c2c66affSColin Finck wined3d_mutex_unlock();
1453c2c66affSColin Finck
1454c2c66affSColin Finck return hr;
1455c2c66affSColin Finck }
1456c2c66affSColin Finck
d3d8_device_Clear(IDirect3DDevice8 * iface,DWORD rect_count,const D3DRECT * rects,DWORD flags,D3DCOLOR color,float z,DWORD stencil)1457c2c66affSColin Finck static HRESULT WINAPI d3d8_device_Clear(IDirect3DDevice8 *iface, DWORD rect_count,
1458c2c66affSColin Finck const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
1459c2c66affSColin Finck {
1460c2c66affSColin Finck const struct wined3d_color c =
1461c2c66affSColin Finck {
1462c2c66affSColin Finck ((color >> 16) & 0xff) / 255.0f,
1463c2c66affSColin Finck ((color >> 8) & 0xff) / 255.0f,
1464c2c66affSColin Finck (color & 0xff) / 255.0f,
1465c2c66affSColin Finck ((color >> 24) & 0xff) / 255.0f,
1466c2c66affSColin Finck };
1467c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1468c2c66affSColin Finck HRESULT hr;
1469c2c66affSColin Finck
1470c2c66affSColin Finck TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1471c2c66affSColin Finck iface, rect_count, rects, flags, color, z, stencil);
1472c2c66affSColin Finck
1473c2c66affSColin Finck if (rect_count && !rects)
1474c2c66affSColin Finck {
1475c2c66affSColin Finck WARN("count %u with NULL rects.\n", rect_count);
1476c2c66affSColin Finck rect_count = 0;
1477c2c66affSColin Finck }
1478c2c66affSColin Finck
1479c2c66affSColin Finck wined3d_mutex_lock();
1480c2c66affSColin Finck hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
1481c2c66affSColin Finck wined3d_mutex_unlock();
1482c2c66affSColin Finck
1483c2c66affSColin Finck return hr;
1484c2c66affSColin Finck }
1485c2c66affSColin Finck
d3d8_device_SetTransform(IDirect3DDevice8 * iface,D3DTRANSFORMSTATETYPE state,const D3DMATRIX * matrix)1486c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetTransform(IDirect3DDevice8 *iface,
1487c2c66affSColin Finck D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
1488c2c66affSColin Finck {
1489c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1490c2c66affSColin Finck
1491c2c66affSColin Finck TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1492c2c66affSColin Finck
1493c2c66affSColin Finck /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1494c2c66affSColin Finck wined3d_mutex_lock();
1495c2c66affSColin Finck wined3d_device_set_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1496c2c66affSColin Finck wined3d_mutex_unlock();
1497c2c66affSColin Finck
1498c2c66affSColin Finck return D3D_OK;
1499c2c66affSColin Finck }
1500c2c66affSColin Finck
d3d8_device_GetTransform(IDirect3DDevice8 * iface,D3DTRANSFORMSTATETYPE state,D3DMATRIX * matrix)1501c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetTransform(IDirect3DDevice8 *iface,
1502c2c66affSColin Finck D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
1503c2c66affSColin Finck {
1504c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1505c2c66affSColin Finck
1506c2c66affSColin Finck TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1507c2c66affSColin Finck
1508c2c66affSColin Finck /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1509c2c66affSColin Finck wined3d_mutex_lock();
1510c2c66affSColin Finck wined3d_device_get_transform(device->wined3d_device, state, (struct wined3d_matrix *)matrix);
1511c2c66affSColin Finck wined3d_mutex_unlock();
1512c2c66affSColin Finck
1513c2c66affSColin Finck return D3D_OK;
1514c2c66affSColin Finck }
1515c2c66affSColin Finck
d3d8_device_MultiplyTransform(IDirect3DDevice8 * iface,D3DTRANSFORMSTATETYPE state,const D3DMATRIX * matrix)1516c2c66affSColin Finck static HRESULT WINAPI d3d8_device_MultiplyTransform(IDirect3DDevice8 *iface,
1517c2c66affSColin Finck D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
1518c2c66affSColin Finck {
1519c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1520c2c66affSColin Finck
1521c2c66affSColin Finck TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1522c2c66affSColin Finck
1523c2c66affSColin Finck /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1524c2c66affSColin Finck wined3d_mutex_lock();
1525c2c66affSColin Finck wined3d_device_multiply_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1526c2c66affSColin Finck wined3d_mutex_unlock();
1527c2c66affSColin Finck
1528c2c66affSColin Finck return D3D_OK;
1529c2c66affSColin Finck }
1530c2c66affSColin Finck
d3d8_device_SetViewport(IDirect3DDevice8 * iface,const D3DVIEWPORT8 * viewport)1531c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetViewport(IDirect3DDevice8 *iface, const D3DVIEWPORT8 *viewport)
1532c2c66affSColin Finck {
1533c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1534c2c66affSColin Finck struct wined3d_viewport vp;
1535c2c66affSColin Finck
1536c2c66affSColin Finck TRACE("iface %p, viewport %p.\n", iface, viewport);
1537c2c66affSColin Finck
1538c2c66affSColin Finck vp.x = viewport->X;
1539c2c66affSColin Finck vp.y = viewport->Y;
1540c2c66affSColin Finck vp.width = viewport->Width;
1541c2c66affSColin Finck vp.height = viewport->Height;
1542c2c66affSColin Finck vp.min_z = viewport->MinZ;
1543c2c66affSColin Finck vp.max_z = viewport->MaxZ;
1544c2c66affSColin Finck
1545*81cffd76SJoachim Henze wined3d_mutex_lock();
1546*81cffd76SJoachim Henze wined3d_device_set_viewport(device->wined3d_device, &vp);
1547c2c66affSColin Finck wined3d_mutex_unlock();
1548c2c66affSColin Finck
1549c2c66affSColin Finck return D3D_OK;
1550c2c66affSColin Finck }
1551c2c66affSColin Finck
d3d8_device_GetViewport(IDirect3DDevice8 * iface,D3DVIEWPORT8 * viewport)1552c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetViewport(IDirect3DDevice8 *iface, D3DVIEWPORT8 *viewport)
1553c2c66affSColin Finck {
1554c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1555c2c66affSColin Finck struct wined3d_viewport wined3d_viewport;
1556c2c66affSColin Finck
1557c2c66affSColin Finck TRACE("iface %p, viewport %p.\n", iface, viewport);
1558c2c66affSColin Finck
1559c2c66affSColin Finck wined3d_mutex_lock();
1560*81cffd76SJoachim Henze wined3d_device_get_viewport(device->wined3d_device, &wined3d_viewport);
1561c2c66affSColin Finck wined3d_mutex_unlock();
1562c2c66affSColin Finck
1563c2c66affSColin Finck viewport->X = wined3d_viewport.x;
1564c2c66affSColin Finck viewport->Y = wined3d_viewport.y;
1565c2c66affSColin Finck viewport->Width = wined3d_viewport.width;
1566c2c66affSColin Finck viewport->Height = wined3d_viewport.height;
1567c2c66affSColin Finck viewport->MinZ = wined3d_viewport.min_z;
1568c2c66affSColin Finck viewport->MaxZ = wined3d_viewport.max_z;
1569c2c66affSColin Finck
1570c2c66affSColin Finck return D3D_OK;
1571c2c66affSColin Finck }
1572c2c66affSColin Finck
d3d8_device_SetMaterial(IDirect3DDevice8 * iface,const D3DMATERIAL8 * material)1573c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetMaterial(IDirect3DDevice8 *iface, const D3DMATERIAL8 *material)
1574c2c66affSColin Finck {
1575c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1576c2c66affSColin Finck
1577c2c66affSColin Finck TRACE("iface %p, material %p.\n", iface, material);
1578c2c66affSColin Finck
1579c2c66affSColin Finck /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1580c2c66affSColin Finck wined3d_mutex_lock();
1581c2c66affSColin Finck wined3d_device_set_material(device->wined3d_device, (const struct wined3d_material *)material);
1582c2c66affSColin Finck wined3d_mutex_unlock();
1583c2c66affSColin Finck
1584c2c66affSColin Finck return D3D_OK;
1585c2c66affSColin Finck }
1586c2c66affSColin Finck
d3d8_device_GetMaterial(IDirect3DDevice8 * iface,D3DMATERIAL8 * material)1587c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetMaterial(IDirect3DDevice8 *iface, D3DMATERIAL8 *material)
1588c2c66affSColin Finck {
1589c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1590c2c66affSColin Finck
1591c2c66affSColin Finck TRACE("iface %p, material %p.\n", iface, material);
1592c2c66affSColin Finck
1593c2c66affSColin Finck /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1594c2c66affSColin Finck wined3d_mutex_lock();
1595c2c66affSColin Finck wined3d_device_get_material(device->wined3d_device, (struct wined3d_material *)material);
1596c2c66affSColin Finck wined3d_mutex_unlock();
1597c2c66affSColin Finck
1598c2c66affSColin Finck return D3D_OK;
1599c2c66affSColin Finck }
1600c2c66affSColin Finck
d3d8_device_SetLight(IDirect3DDevice8 * iface,DWORD index,const D3DLIGHT8 * light)1601c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetLight(IDirect3DDevice8 *iface, DWORD index, const D3DLIGHT8 *light)
1602c2c66affSColin Finck {
1603c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1604c2c66affSColin Finck HRESULT hr;
1605c2c66affSColin Finck
1606c2c66affSColin Finck TRACE("iface %p, index %u, light %p.\n", iface, index, light);
1607c2c66affSColin Finck
1608c2c66affSColin Finck /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1609c2c66affSColin Finck wined3d_mutex_lock();
1610c2c66affSColin Finck hr = wined3d_device_set_light(device->wined3d_device, index, (const struct wined3d_light *)light);
1611c2c66affSColin Finck wined3d_mutex_unlock();
1612c2c66affSColin Finck
1613c2c66affSColin Finck return hr;
1614c2c66affSColin Finck }
1615c2c66affSColin Finck
d3d8_device_GetLight(IDirect3DDevice8 * iface,DWORD index,D3DLIGHT8 * light)1616c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetLight(IDirect3DDevice8 *iface, DWORD index, D3DLIGHT8 *light)
1617c2c66affSColin Finck {
1618c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1619c2c66affSColin Finck HRESULT hr;
1620c2c66affSColin Finck
1621c2c66affSColin Finck TRACE("iface %p, index %u, light %p.\n", iface, index, light);
1622c2c66affSColin Finck
1623c2c66affSColin Finck /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1624c2c66affSColin Finck wined3d_mutex_lock();
1625c2c66affSColin Finck hr = wined3d_device_get_light(device->wined3d_device, index, (struct wined3d_light *)light);
1626c2c66affSColin Finck wined3d_mutex_unlock();
1627c2c66affSColin Finck
1628c2c66affSColin Finck return hr;
1629c2c66affSColin Finck }
1630c2c66affSColin Finck
d3d8_device_LightEnable(IDirect3DDevice8 * iface,DWORD index,BOOL enable)1631c2c66affSColin Finck static HRESULT WINAPI d3d8_device_LightEnable(IDirect3DDevice8 *iface, DWORD index, BOOL enable)
1632c2c66affSColin Finck {
1633c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1634c2c66affSColin Finck HRESULT hr;
1635c2c66affSColin Finck
1636c2c66affSColin Finck TRACE("iface %p, index %u, enable %#x.\n", iface, index, enable);
1637c2c66affSColin Finck
1638c2c66affSColin Finck wined3d_mutex_lock();
1639c2c66affSColin Finck hr = wined3d_device_set_light_enable(device->wined3d_device, index, enable);
1640c2c66affSColin Finck wined3d_mutex_unlock();
1641c2c66affSColin Finck
1642c2c66affSColin Finck return hr;
1643c2c66affSColin Finck }
1644c2c66affSColin Finck
d3d8_device_GetLightEnable(IDirect3DDevice8 * iface,DWORD index,BOOL * enable)1645c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetLightEnable(IDirect3DDevice8 *iface, DWORD index, BOOL *enable)
1646c2c66affSColin Finck {
1647c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1648c2c66affSColin Finck HRESULT hr;
1649c2c66affSColin Finck
1650c2c66affSColin Finck TRACE("iface %p, index %u, enable %p.\n", iface, index, enable);
1651c2c66affSColin Finck
1652c2c66affSColin Finck wined3d_mutex_lock();
1653c2c66affSColin Finck hr = wined3d_device_get_light_enable(device->wined3d_device, index, enable);
1654c2c66affSColin Finck wined3d_mutex_unlock();
1655c2c66affSColin Finck
1656c2c66affSColin Finck return hr;
1657c2c66affSColin Finck }
1658c2c66affSColin Finck
d3d8_device_SetClipPlane(IDirect3DDevice8 * iface,DWORD index,const float * plane)1659c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetClipPlane(IDirect3DDevice8 *iface, DWORD index, const float *plane)
1660c2c66affSColin Finck {
1661c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1662c2c66affSColin Finck HRESULT hr;
1663c2c66affSColin Finck
1664c2c66affSColin Finck TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1665c2c66affSColin Finck
1666c2c66affSColin Finck wined3d_mutex_lock();
1667c2c66affSColin Finck hr = wined3d_device_set_clip_plane(device->wined3d_device, index, (const struct wined3d_vec4 *)plane);
1668c2c66affSColin Finck wined3d_mutex_unlock();
1669c2c66affSColin Finck
1670c2c66affSColin Finck return hr;
1671c2c66affSColin Finck }
1672c2c66affSColin Finck
d3d8_device_GetClipPlane(IDirect3DDevice8 * iface,DWORD index,float * plane)1673c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetClipPlane(IDirect3DDevice8 *iface, DWORD index, float *plane)
1674c2c66affSColin Finck {
1675c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1676c2c66affSColin Finck HRESULT hr;
1677c2c66affSColin Finck
1678c2c66affSColin Finck TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1679c2c66affSColin Finck
1680c2c66affSColin Finck wined3d_mutex_lock();
1681c2c66affSColin Finck hr = wined3d_device_get_clip_plane(device->wined3d_device, index, (struct wined3d_vec4 *)plane);
1682c2c66affSColin Finck wined3d_mutex_unlock();
1683c2c66affSColin Finck
1684c2c66affSColin Finck return hr;
1685c2c66affSColin Finck }
1686c2c66affSColin Finck
d3d8_device_SetRenderState(IDirect3DDevice8 * iface,D3DRENDERSTATETYPE state,DWORD value)1687c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetRenderState(IDirect3DDevice8 *iface,
1688c2c66affSColin Finck D3DRENDERSTATETYPE state, DWORD value)
1689c2c66affSColin Finck {
1690c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1691c2c66affSColin Finck
1692c2c66affSColin Finck TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
1693c2c66affSColin Finck
1694c2c66affSColin Finck wined3d_mutex_lock();
1695c2c66affSColin Finck switch (state)
1696c2c66affSColin Finck {
1697c2c66affSColin Finck case D3DRS_ZBIAS:
1698c2c66affSColin Finck wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, value);
1699c2c66affSColin Finck break;
1700c2c66affSColin Finck
1701c2c66affSColin Finck default:
1702c2c66affSColin Finck wined3d_device_set_render_state(device->wined3d_device, state, value);
1703c2c66affSColin Finck }
1704c2c66affSColin Finck wined3d_mutex_unlock();
1705c2c66affSColin Finck
1706c2c66affSColin Finck return D3D_OK;
1707c2c66affSColin Finck }
1708c2c66affSColin Finck
d3d8_device_GetRenderState(IDirect3DDevice8 * iface,D3DRENDERSTATETYPE state,DWORD * value)1709c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetRenderState(IDirect3DDevice8 *iface,
1710c2c66affSColin Finck D3DRENDERSTATETYPE state, DWORD *value)
1711c2c66affSColin Finck {
1712c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1713c2c66affSColin Finck
1714c2c66affSColin Finck TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
1715c2c66affSColin Finck
1716c2c66affSColin Finck wined3d_mutex_lock();
1717c2c66affSColin Finck switch (state)
1718c2c66affSColin Finck {
1719c2c66affSColin Finck case D3DRS_ZBIAS:
1720c2c66affSColin Finck *value = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS);
1721c2c66affSColin Finck break;
1722c2c66affSColin Finck
1723c2c66affSColin Finck default:
1724c2c66affSColin Finck *value = wined3d_device_get_render_state(device->wined3d_device, state);
1725c2c66affSColin Finck }
1726c2c66affSColin Finck wined3d_mutex_unlock();
1727c2c66affSColin Finck
1728c2c66affSColin Finck return D3D_OK;
1729c2c66affSColin Finck }
1730c2c66affSColin Finck
d3d8_device_BeginStateBlock(IDirect3DDevice8 * iface)1731c2c66affSColin Finck static HRESULT WINAPI d3d8_device_BeginStateBlock(IDirect3DDevice8 *iface)
1732c2c66affSColin Finck {
1733c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1734c2c66affSColin Finck HRESULT hr;
1735c2c66affSColin Finck
1736c2c66affSColin Finck TRACE("iface %p.\n", iface);
1737c2c66affSColin Finck
1738c2c66affSColin Finck wined3d_mutex_lock();
1739c2c66affSColin Finck hr = wined3d_device_begin_stateblock(device->wined3d_device);
1740c2c66affSColin Finck wined3d_mutex_unlock();
1741c2c66affSColin Finck
1742c2c66affSColin Finck return hr;
1743c2c66affSColin Finck }
1744c2c66affSColin Finck
d3d8_device_EndStateBlock(IDirect3DDevice8 * iface,DWORD * token)1745c2c66affSColin Finck static HRESULT WINAPI d3d8_device_EndStateBlock(IDirect3DDevice8 *iface, DWORD *token)
1746c2c66affSColin Finck {
1747c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1748c2c66affSColin Finck struct wined3d_stateblock *stateblock;
1749c2c66affSColin Finck HRESULT hr;
1750c2c66affSColin Finck
1751c2c66affSColin Finck TRACE("iface %p, token %p.\n", iface, token);
1752c2c66affSColin Finck
1753c2c66affSColin Finck /* Tell wineD3D to endstateblock before anything else (in case we run out
1754c2c66affSColin Finck * of memory later and cause locking problems)
1755c2c66affSColin Finck */
1756c2c66affSColin Finck wined3d_mutex_lock();
1757c2c66affSColin Finck hr = wined3d_device_end_stateblock(device->wined3d_device, &stateblock);
1758c2c66affSColin Finck if (FAILED(hr))
1759c2c66affSColin Finck {
1760c2c66affSColin Finck WARN("Failed to end the state block, %#x.\n", hr);
1761c2c66affSColin Finck wined3d_mutex_unlock();
1762c2c66affSColin Finck return hr;
1763c2c66affSColin Finck }
1764c2c66affSColin Finck
1765c2c66affSColin Finck *token = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
1766c2c66affSColin Finck wined3d_mutex_unlock();
1767c2c66affSColin Finck
1768c2c66affSColin Finck if (*token == D3D8_INVALID_HANDLE)
1769c2c66affSColin Finck {
1770c2c66affSColin Finck ERR("Failed to create a handle\n");
1771c2c66affSColin Finck wined3d_mutex_lock();
1772c2c66affSColin Finck wined3d_stateblock_decref(stateblock);
1773c2c66affSColin Finck wined3d_mutex_unlock();
1774c2c66affSColin Finck return E_FAIL;
1775c2c66affSColin Finck }
1776c2c66affSColin Finck ++*token;
1777c2c66affSColin Finck
1778c2c66affSColin Finck TRACE("Returning %#x (%p).\n", *token, stateblock);
1779c2c66affSColin Finck
1780c2c66affSColin Finck return hr;
1781c2c66affSColin Finck }
1782c2c66affSColin Finck
d3d8_device_ApplyStateBlock(IDirect3DDevice8 * iface,DWORD token)1783c2c66affSColin Finck static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD token)
1784c2c66affSColin Finck {
1785c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1786c2c66affSColin Finck struct wined3d_stateblock *stateblock;
1787c2c66affSColin Finck
1788c2c66affSColin Finck TRACE("iface %p, token %#x.\n", iface, token);
1789c2c66affSColin Finck
1790c2c66affSColin Finck if (!token)
1791c2c66affSColin Finck return D3D_OK;
1792c2c66affSColin Finck
1793c2c66affSColin Finck wined3d_mutex_lock();
1794c2c66affSColin Finck stateblock = d3d8_get_object(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1795c2c66affSColin Finck if (!stateblock)
1796c2c66affSColin Finck {
1797c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", token);
1798c2c66affSColin Finck wined3d_mutex_unlock();
1799c2c66affSColin Finck return D3DERR_INVALIDCALL;
1800c2c66affSColin Finck }
1801c2c66affSColin Finck wined3d_stateblock_apply(stateblock);
1802c2c66affSColin Finck wined3d_mutex_unlock();
1803c2c66affSColin Finck
1804c2c66affSColin Finck return D3D_OK;
1805c2c66affSColin Finck }
1806c2c66affSColin Finck
d3d8_device_CaptureStateBlock(IDirect3DDevice8 * iface,DWORD token)1807c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD token)
1808c2c66affSColin Finck {
1809c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1810c2c66affSColin Finck struct wined3d_stateblock *stateblock;
1811c2c66affSColin Finck
1812c2c66affSColin Finck TRACE("iface %p, token %#x.\n", iface, token);
1813c2c66affSColin Finck
1814c2c66affSColin Finck wined3d_mutex_lock();
1815c2c66affSColin Finck stateblock = d3d8_get_object(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1816c2c66affSColin Finck if (!stateblock)
1817c2c66affSColin Finck {
1818c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", token);
1819c2c66affSColin Finck wined3d_mutex_unlock();
1820c2c66affSColin Finck return D3DERR_INVALIDCALL;
1821c2c66affSColin Finck }
1822c2c66affSColin Finck wined3d_stateblock_capture(stateblock);
1823c2c66affSColin Finck wined3d_mutex_unlock();
1824c2c66affSColin Finck
1825c2c66affSColin Finck return D3D_OK;
1826c2c66affSColin Finck }
1827c2c66affSColin Finck
d3d8_device_DeleteStateBlock(IDirect3DDevice8 * iface,DWORD token)1828c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD token)
1829c2c66affSColin Finck {
1830c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1831c2c66affSColin Finck struct wined3d_stateblock *stateblock;
1832c2c66affSColin Finck
1833c2c66affSColin Finck TRACE("iface %p, token %#x.\n", iface, token);
1834c2c66affSColin Finck
1835c2c66affSColin Finck wined3d_mutex_lock();
1836c2c66affSColin Finck stateblock = d3d8_free_handle(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1837c2c66affSColin Finck
1838c2c66affSColin Finck if (!stateblock)
1839c2c66affSColin Finck {
1840c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", token);
1841c2c66affSColin Finck wined3d_mutex_unlock();
1842c2c66affSColin Finck return D3DERR_INVALIDCALL;
1843c2c66affSColin Finck }
1844c2c66affSColin Finck
1845c2c66affSColin Finck if (wined3d_stateblock_decref(stateblock))
1846c2c66affSColin Finck {
1847c2c66affSColin Finck ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1848c2c66affSColin Finck }
1849c2c66affSColin Finck wined3d_mutex_unlock();
1850c2c66affSColin Finck
1851c2c66affSColin Finck return D3D_OK;
1852c2c66affSColin Finck }
1853c2c66affSColin Finck
d3d8_device_CreateStateBlock(IDirect3DDevice8 * iface,D3DSTATEBLOCKTYPE type,DWORD * handle)1854c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateStateBlock(IDirect3DDevice8 *iface,
1855c2c66affSColin Finck D3DSTATEBLOCKTYPE type, DWORD *handle)
1856c2c66affSColin Finck {
1857c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1858c2c66affSColin Finck struct wined3d_stateblock *stateblock;
1859c2c66affSColin Finck HRESULT hr;
1860c2c66affSColin Finck
1861c2c66affSColin Finck TRACE("iface %p, type %#x, handle %p.\n", iface, type, handle);
1862c2c66affSColin Finck
1863c2c66affSColin Finck if (type != D3DSBT_ALL
1864c2c66affSColin Finck && type != D3DSBT_PIXELSTATE
1865c2c66affSColin Finck && type != D3DSBT_VERTEXSTATE)
1866c2c66affSColin Finck {
1867c2c66affSColin Finck WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1868c2c66affSColin Finck return D3DERR_INVALIDCALL;
1869c2c66affSColin Finck }
1870c2c66affSColin Finck
1871c2c66affSColin Finck wined3d_mutex_lock();
1872c2c66affSColin Finck hr = wined3d_stateblock_create(device->wined3d_device, (enum wined3d_stateblock_type)type, &stateblock);
1873c2c66affSColin Finck if (FAILED(hr))
1874c2c66affSColin Finck {
1875c2c66affSColin Finck wined3d_mutex_unlock();
1876c2c66affSColin Finck ERR("Failed to create the state block, hr %#x\n", hr);
1877c2c66affSColin Finck return hr;
1878c2c66affSColin Finck }
1879c2c66affSColin Finck
1880c2c66affSColin Finck *handle = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
1881c2c66affSColin Finck wined3d_mutex_unlock();
1882c2c66affSColin Finck
1883c2c66affSColin Finck if (*handle == D3D8_INVALID_HANDLE)
1884c2c66affSColin Finck {
1885c2c66affSColin Finck ERR("Failed to allocate a handle.\n");
1886c2c66affSColin Finck wined3d_mutex_lock();
1887c2c66affSColin Finck wined3d_stateblock_decref(stateblock);
1888c2c66affSColin Finck wined3d_mutex_unlock();
1889c2c66affSColin Finck return E_FAIL;
1890c2c66affSColin Finck }
1891c2c66affSColin Finck ++*handle;
1892c2c66affSColin Finck
1893c2c66affSColin Finck TRACE("Returning %#x (%p).\n", *handle, stateblock);
1894c2c66affSColin Finck
1895c2c66affSColin Finck return hr;
1896c2c66affSColin Finck }
1897c2c66affSColin Finck
d3d8_device_SetClipStatus(IDirect3DDevice8 * iface,const D3DCLIPSTATUS8 * clip_status)1898c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetClipStatus(IDirect3DDevice8 *iface, const D3DCLIPSTATUS8 *clip_status)
1899c2c66affSColin Finck {
1900c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1901c2c66affSColin Finck HRESULT hr;
1902c2c66affSColin Finck
1903c2c66affSColin Finck TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1904c2c66affSColin Finck /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1905c2c66affSColin Finck
1906c2c66affSColin Finck wined3d_mutex_lock();
1907c2c66affSColin Finck hr = wined3d_device_set_clip_status(device->wined3d_device, (const struct wined3d_clip_status *)clip_status);
1908c2c66affSColin Finck wined3d_mutex_unlock();
1909c2c66affSColin Finck
1910c2c66affSColin Finck return hr;
1911c2c66affSColin Finck }
1912c2c66affSColin Finck
d3d8_device_GetClipStatus(IDirect3DDevice8 * iface,D3DCLIPSTATUS8 * clip_status)1913c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetClipStatus(IDirect3DDevice8 *iface, D3DCLIPSTATUS8 *clip_status)
1914c2c66affSColin Finck {
1915c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1916c2c66affSColin Finck HRESULT hr;
1917c2c66affSColin Finck
1918c2c66affSColin Finck TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1919c2c66affSColin Finck
1920c2c66affSColin Finck wined3d_mutex_lock();
1921c2c66affSColin Finck hr = wined3d_device_get_clip_status(device->wined3d_device, (struct wined3d_clip_status *)clip_status);
1922c2c66affSColin Finck wined3d_mutex_unlock();
1923c2c66affSColin Finck
1924c2c66affSColin Finck return hr;
1925c2c66affSColin Finck }
1926c2c66affSColin Finck
d3d8_device_GetTexture(IDirect3DDevice8 * iface,DWORD stage,IDirect3DBaseTexture8 ** texture)1927c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetTexture(IDirect3DDevice8 *iface, DWORD stage, IDirect3DBaseTexture8 **texture)
1928c2c66affSColin Finck {
1929c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1930c2c66affSColin Finck struct wined3d_texture *wined3d_texture;
1931c2c66affSColin Finck struct d3d8_texture *texture_impl;
1932c2c66affSColin Finck
1933c2c66affSColin Finck TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1934c2c66affSColin Finck
1935c2c66affSColin Finck if (!texture)
1936c2c66affSColin Finck return D3DERR_INVALIDCALL;
1937c2c66affSColin Finck
1938c2c66affSColin Finck wined3d_mutex_lock();
1939c2c66affSColin Finck if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage)))
1940c2c66affSColin Finck {
1941c2c66affSColin Finck texture_impl = wined3d_texture_get_parent(wined3d_texture);
1942c2c66affSColin Finck *texture = &texture_impl->IDirect3DBaseTexture8_iface;
1943c2c66affSColin Finck IDirect3DBaseTexture8_AddRef(*texture);
1944c2c66affSColin Finck }
1945c2c66affSColin Finck else
1946c2c66affSColin Finck {
1947c2c66affSColin Finck *texture = NULL;
1948c2c66affSColin Finck }
1949c2c66affSColin Finck wined3d_mutex_unlock();
1950c2c66affSColin Finck
1951c2c66affSColin Finck return D3D_OK;
1952c2c66affSColin Finck }
1953c2c66affSColin Finck
d3d8_device_SetTexture(IDirect3DDevice8 * iface,DWORD stage,IDirect3DBaseTexture8 * texture)1954c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetTexture(IDirect3DDevice8 *iface, DWORD stage, IDirect3DBaseTexture8 *texture)
1955c2c66affSColin Finck {
1956c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1957c2c66affSColin Finck struct d3d8_texture *texture_impl;
1958c2c66affSColin Finck HRESULT hr;
1959c2c66affSColin Finck
1960c2c66affSColin Finck TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1961c2c66affSColin Finck
1962c2c66affSColin Finck texture_impl = unsafe_impl_from_IDirect3DBaseTexture8(texture);
1963c2c66affSColin Finck
1964c2c66affSColin Finck wined3d_mutex_lock();
1965c2c66affSColin Finck hr = wined3d_device_set_texture(device->wined3d_device, stage,
1966c2c66affSColin Finck texture_impl ? texture_impl->wined3d_texture : NULL);
1967c2c66affSColin Finck wined3d_mutex_unlock();
1968c2c66affSColin Finck
1969c2c66affSColin Finck return hr;
1970c2c66affSColin Finck }
1971c2c66affSColin Finck
1972c2c66affSColin Finck static const struct tss_lookup
1973c2c66affSColin Finck {
1974c2c66affSColin Finck BOOL sampler_state;
1975c2c66affSColin Finck union
1976c2c66affSColin Finck {
1977c2c66affSColin Finck enum wined3d_texture_stage_state texture_state;
1978c2c66affSColin Finck enum wined3d_sampler_state sampler_state;
1979c2c66affSColin Finck } u;
1980c2c66affSColin Finck }
1981c2c66affSColin Finck tss_lookup[] =
1982c2c66affSColin Finck {
1983c2c66affSColin Finck {FALSE, {WINED3D_TSS_INVALID}}, /* 0, unused */
1984c2c66affSColin Finck {FALSE, {WINED3D_TSS_COLOR_OP}}, /* 1, D3DTSS_COLOROP */
1985c2c66affSColin Finck {FALSE, {WINED3D_TSS_COLOR_ARG1}}, /* 2, D3DTSS_COLORARG1 */
1986c2c66affSColin Finck {FALSE, {WINED3D_TSS_COLOR_ARG2}}, /* 3, D3DTSS_COLORARG2 */
1987c2c66affSColin Finck {FALSE, {WINED3D_TSS_ALPHA_OP}}, /* 4, D3DTSS_ALPHAOP */
1988c2c66affSColin Finck {FALSE, {WINED3D_TSS_ALPHA_ARG1}}, /* 5, D3DTSS_ALPHAARG1 */
1989c2c66affSColin Finck {FALSE, {WINED3D_TSS_ALPHA_ARG2}}, /* 6, D3DTSS_ALPHAARG2 */
1990c2c66affSColin Finck {FALSE, {WINED3D_TSS_BUMPENV_MAT00}}, /* 7, D3DTSS_BUMPENVMAT00 */
1991c2c66affSColin Finck {FALSE, {WINED3D_TSS_BUMPENV_MAT01}}, /* 8, D3DTSS_BUMPENVMAT01 */
1992c2c66affSColin Finck {FALSE, {WINED3D_TSS_BUMPENV_MAT10}}, /* 9, D3DTSS_BUMPENVMAT10 */
1993c2c66affSColin Finck {FALSE, {WINED3D_TSS_BUMPENV_MAT11}}, /* 10, D3DTSS_BUMPENVMAT11 */
1994c2c66affSColin Finck {FALSE, {WINED3D_TSS_TEXCOORD_INDEX}}, /* 11, D3DTSS_TEXCOORDINDEX */
1995c2c66affSColin Finck {FALSE, {WINED3D_TSS_INVALID}}, /* 12, unused */
1996c2c66affSColin Finck {TRUE, {WINED3D_SAMP_ADDRESS_U}}, /* 13, D3DTSS_ADDRESSU */
1997c2c66affSColin Finck {TRUE, {WINED3D_SAMP_ADDRESS_V}}, /* 14, D3DTSS_ADDRESSV */
1998c2c66affSColin Finck {TRUE, {WINED3D_SAMP_BORDER_COLOR}}, /* 15, D3DTSS_BORDERCOLOR */
1999c2c66affSColin Finck {TRUE, {WINED3D_SAMP_MAG_FILTER}}, /* 16, D3DTSS_MAGFILTER */
2000c2c66affSColin Finck {TRUE, {WINED3D_SAMP_MIN_FILTER}}, /* 17, D3DTSS_MINFILTER */
2001c2c66affSColin Finck {TRUE, {WINED3D_SAMP_MIP_FILTER}}, /* 18, D3DTSS_MIPFILTER */
2002c2c66affSColin Finck {TRUE, {WINED3D_SAMP_MIPMAP_LOD_BIAS}}, /* 19, D3DTSS_MIPMAPLODBIAS */
2003c2c66affSColin Finck {TRUE, {WINED3D_SAMP_MAX_MIP_LEVEL}}, /* 20, D3DTSS_MAXMIPLEVEL */
2004c2c66affSColin Finck {TRUE, {WINED3D_SAMP_MAX_ANISOTROPY}}, /* 21, D3DTSS_MAXANISOTROPY */
2005c2c66affSColin Finck {FALSE, {WINED3D_TSS_BUMPENV_LSCALE}}, /* 22, D3DTSS_BUMPENVLSCALE */
2006c2c66affSColin Finck {FALSE, {WINED3D_TSS_BUMPENV_LOFFSET}}, /* 23, D3DTSS_BUMPENVLOFFSET */
2007c2c66affSColin Finck {FALSE, {WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS}}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
2008c2c66affSColin Finck {TRUE, {WINED3D_SAMP_ADDRESS_W}}, /* 25, D3DTSS_ADDRESSW */
2009c2c66affSColin Finck {FALSE, {WINED3D_TSS_COLOR_ARG0}}, /* 26, D3DTSS_COLORARG0 */
2010c2c66affSColin Finck {FALSE, {WINED3D_TSS_ALPHA_ARG0}}, /* 27, D3DTSS_ALPHAARG0 */
2011c2c66affSColin Finck {FALSE, {WINED3D_TSS_RESULT_ARG}}, /* 28, D3DTSS_RESULTARG */
2012c2c66affSColin Finck };
2013c2c66affSColin Finck
d3d8_device_GetTextureStageState(IDirect3DDevice8 * iface,DWORD stage,D3DTEXTURESTAGESTATETYPE Type,DWORD * value)2014c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetTextureStageState(IDirect3DDevice8 *iface,
2015c2c66affSColin Finck DWORD stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *value)
2016c2c66affSColin Finck {
2017c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2018c2c66affSColin Finck const struct tss_lookup *l;
2019c2c66affSColin Finck
2020c2c66affSColin Finck TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, stage, Type, value);
2021c2c66affSColin Finck
2022c2c66affSColin Finck if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
2023c2c66affSColin Finck {
2024c2c66affSColin Finck WARN("Invalid Type %#x passed.\n", Type);
2025c2c66affSColin Finck return D3D_OK;
2026c2c66affSColin Finck }
2027c2c66affSColin Finck
2028c2c66affSColin Finck l = &tss_lookup[Type];
2029c2c66affSColin Finck
2030c2c66affSColin Finck wined3d_mutex_lock();
2031c2c66affSColin Finck if (l->sampler_state)
2032c2c66affSColin Finck *value = wined3d_device_get_sampler_state(device->wined3d_device, stage, l->u.sampler_state);
2033c2c66affSColin Finck else
2034c2c66affSColin Finck *value = wined3d_device_get_texture_stage_state(device->wined3d_device, stage, l->u.texture_state);
2035c2c66affSColin Finck wined3d_mutex_unlock();
2036c2c66affSColin Finck
2037c2c66affSColin Finck return D3D_OK;
2038c2c66affSColin Finck }
2039c2c66affSColin Finck
d3d8_device_SetTextureStageState(IDirect3DDevice8 * iface,DWORD stage,D3DTEXTURESTAGESTATETYPE type,DWORD value)2040c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetTextureStageState(IDirect3DDevice8 *iface,
2041c2c66affSColin Finck DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
2042c2c66affSColin Finck {
2043c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2044c2c66affSColin Finck const struct tss_lookup *l;
2045c2c66affSColin Finck
2046c2c66affSColin Finck TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, stage, type, value);
2047c2c66affSColin Finck
2048c2c66affSColin Finck if (type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
2049c2c66affSColin Finck {
2050c2c66affSColin Finck WARN("Invalid type %#x passed.\n", type);
2051c2c66affSColin Finck return D3D_OK;
2052c2c66affSColin Finck }
2053c2c66affSColin Finck
2054c2c66affSColin Finck l = &tss_lookup[type];
2055c2c66affSColin Finck
2056c2c66affSColin Finck wined3d_mutex_lock();
2057c2c66affSColin Finck if (l->sampler_state)
2058c2c66affSColin Finck wined3d_device_set_sampler_state(device->wined3d_device, stage, l->u.sampler_state, value);
2059c2c66affSColin Finck else
2060c2c66affSColin Finck wined3d_device_set_texture_stage_state(device->wined3d_device, stage, l->u.texture_state, value);
2061c2c66affSColin Finck wined3d_mutex_unlock();
2062c2c66affSColin Finck
2063c2c66affSColin Finck return D3D_OK;
2064c2c66affSColin Finck }
2065c2c66affSColin Finck
d3d8_device_ValidateDevice(IDirect3DDevice8 * iface,DWORD * pass_count)2066c2c66affSColin Finck static HRESULT WINAPI d3d8_device_ValidateDevice(IDirect3DDevice8 *iface, DWORD *pass_count)
2067c2c66affSColin Finck {
2068c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2069c2c66affSColin Finck HRESULT hr;
2070c2c66affSColin Finck
2071c2c66affSColin Finck TRACE("iface %p, pass_count %p.\n", iface, pass_count);
2072c2c66affSColin Finck
2073c2c66affSColin Finck wined3d_mutex_lock();
2074c2c66affSColin Finck hr = wined3d_device_validate_device(device->wined3d_device, pass_count);
2075c2c66affSColin Finck wined3d_mutex_unlock();
2076c2c66affSColin Finck
2077c2c66affSColin Finck return hr;
2078c2c66affSColin Finck }
2079c2c66affSColin Finck
d3d8_device_GetInfo(IDirect3DDevice8 * iface,DWORD info_id,void * info,DWORD info_size)2080c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetInfo(IDirect3DDevice8 *iface,
2081c2c66affSColin Finck DWORD info_id, void *info, DWORD info_size)
2082c2c66affSColin Finck {
2083*81cffd76SJoachim Henze FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
2084c2c66affSColin Finck
2085*81cffd76SJoachim Henze return D3D_OK;
2086c2c66affSColin Finck }
2087c2c66affSColin Finck
d3d8_device_SetPaletteEntries(IDirect3DDevice8 * iface,UINT palette_idx,const PALETTEENTRY * entries)2088c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetPaletteEntries(IDirect3DDevice8 *iface,
2089c2c66affSColin Finck UINT palette_idx, const PALETTEENTRY *entries)
2090c2c66affSColin Finck {
2091c2c66affSColin Finck WARN("iface %p, palette_idx %u, entries %p unimplemented\n", iface, palette_idx, entries);
2092c2c66affSColin Finck
2093c2c66affSColin Finck /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
2094c2c66affSColin Finck * does not have a d3d8/9-style palette API */
2095c2c66affSColin Finck
2096c2c66affSColin Finck return D3D_OK;
2097c2c66affSColin Finck }
2098c2c66affSColin Finck
d3d8_device_GetPaletteEntries(IDirect3DDevice8 * iface,UINT palette_idx,PALETTEENTRY * entries)2099c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetPaletteEntries(IDirect3DDevice8 *iface,
2100c2c66affSColin Finck UINT palette_idx, PALETTEENTRY *entries)
2101c2c66affSColin Finck {
2102c2c66affSColin Finck FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
2103c2c66affSColin Finck
2104c2c66affSColin Finck return D3DERR_INVALIDCALL;
2105c2c66affSColin Finck }
2106c2c66affSColin Finck
d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8 * iface,UINT palette_idx)2107c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT palette_idx)
2108c2c66affSColin Finck {
2109c2c66affSColin Finck WARN("iface %p, palette_idx %u unimplemented.\n", iface, palette_idx);
2110c2c66affSColin Finck
2111c2c66affSColin Finck return D3D_OK;
2112c2c66affSColin Finck }
2113c2c66affSColin Finck
d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8 * iface,UINT * palette_idx)2114c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT *palette_idx)
2115c2c66affSColin Finck {
2116c2c66affSColin Finck FIXME("iface %p, palette_idx %p unimplemented.\n", iface, palette_idx);
2117c2c66affSColin Finck
2118c2c66affSColin Finck return D3DERR_INVALIDCALL;
2119c2c66affSColin Finck }
2120c2c66affSColin Finck
d3d8_device_DrawPrimitive(IDirect3DDevice8 * iface,D3DPRIMITIVETYPE primitive_type,UINT start_vertex,UINT primitive_count)2121c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DrawPrimitive(IDirect3DDevice8 *iface,
2122c2c66affSColin Finck D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
2123c2c66affSColin Finck {
2124c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2125c2c66affSColin Finck HRESULT hr;
2126c2c66affSColin Finck
2127c2c66affSColin Finck TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2128c2c66affSColin Finck iface, primitive_type, start_vertex, primitive_count);
2129c2c66affSColin Finck
2130c2c66affSColin Finck wined3d_mutex_lock();
2131c2c66affSColin Finck wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
2132c2c66affSColin Finck hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
2133c2c66affSColin Finck vertex_count_from_primitive_count(primitive_type, primitive_count));
2134c2c66affSColin Finck wined3d_mutex_unlock();
2135c2c66affSColin Finck
2136c2c66affSColin Finck return hr;
2137c2c66affSColin Finck }
2138c2c66affSColin Finck
d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8 * iface,D3DPRIMITIVETYPE primitive_type,UINT min_vertex_idx,UINT vertex_count,UINT start_idx,UINT primitive_count)2139c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
2140c2c66affSColin Finck D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT vertex_count,
2141c2c66affSColin Finck UINT start_idx, UINT primitive_count)
2142c2c66affSColin Finck {
2143c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2144c2c66affSColin Finck HRESULT hr;
2145c2c66affSColin Finck
2146c2c66affSColin Finck TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
2147c2c66affSColin Finck iface, primitive_type, min_vertex_idx, vertex_count, start_idx, primitive_count);
2148c2c66affSColin Finck
2149c2c66affSColin Finck wined3d_mutex_lock();
2150c2c66affSColin Finck wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
2151c2c66affSColin Finck hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
2152c2c66affSColin Finck vertex_count_from_primitive_count(primitive_type, primitive_count));
2153c2c66affSColin Finck wined3d_mutex_unlock();
2154c2c66affSColin Finck
2155c2c66affSColin Finck return hr;
2156c2c66affSColin Finck }
2157c2c66affSColin Finck
2158c2c66affSColin Finck /* The caller is responsible for wined3d locking */
d3d8_device_prepare_vertex_buffer(struct d3d8_device * device,UINT min_size)2159c2c66affSColin Finck static HRESULT d3d8_device_prepare_vertex_buffer(struct d3d8_device *device, UINT min_size)
2160c2c66affSColin Finck {
2161c2c66affSColin Finck HRESULT hr;
2162c2c66affSColin Finck
2163c2c66affSColin Finck if (device->vertex_buffer_size < min_size || !device->vertex_buffer)
2164c2c66affSColin Finck {
2165c2c66affSColin Finck UINT size = max(device->vertex_buffer_size * 2, min_size);
21669987f029SAmine Khaldi struct wined3d_buffer_desc desc;
2167c2c66affSColin Finck struct wined3d_buffer *buffer;
2168c2c66affSColin Finck
2169c2c66affSColin Finck TRACE("Growing vertex buffer to %u bytes\n", size);
2170c2c66affSColin Finck
21719987f029SAmine Khaldi desc.byte_width = size;
21729987f029SAmine Khaldi desc.usage = WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY;
21739987f029SAmine Khaldi desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
21749987f029SAmine Khaldi desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
21759987f029SAmine Khaldi desc.misc_flags = 0;
21769987f029SAmine Khaldi desc.structure_byte_stride = 0;
21779987f029SAmine Khaldi
21789987f029SAmine Khaldi if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc,
21799987f029SAmine Khaldi NULL, NULL, &d3d8_null_wined3d_parent_ops, &buffer)))
2180c2c66affSColin Finck {
21819987f029SAmine Khaldi ERR("Failed to create vertex buffer, hr %#x.\n", hr);
2182c2c66affSColin Finck return hr;
2183c2c66affSColin Finck }
2184c2c66affSColin Finck
2185c2c66affSColin Finck if (device->vertex_buffer)
2186c2c66affSColin Finck wined3d_buffer_decref(device->vertex_buffer);
2187c2c66affSColin Finck
2188c2c66affSColin Finck device->vertex_buffer = buffer;
2189c2c66affSColin Finck device->vertex_buffer_size = size;
2190c2c66affSColin Finck device->vertex_buffer_pos = 0;
2191c2c66affSColin Finck }
2192c2c66affSColin Finck return D3D_OK;
2193c2c66affSColin Finck }
2194c2c66affSColin Finck
d3d8_device_DrawPrimitiveUP(IDirect3DDevice8 * iface,D3DPRIMITIVETYPE primitive_type,UINT primitive_count,const void * data,UINT stride)2195c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DrawPrimitiveUP(IDirect3DDevice8 *iface,
2196c2c66affSColin Finck D3DPRIMITIVETYPE primitive_type, UINT primitive_count, const void *data,
2197c2c66affSColin Finck UINT stride)
2198c2c66affSColin Finck {
2199c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2200c2c66affSColin Finck HRESULT hr;
2201c2c66affSColin Finck UINT vtx_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
2202c2c66affSColin Finck struct wined3d_map_desc wined3d_map_desc;
2203c2c66affSColin Finck struct wined3d_box wined3d_box = {0};
2204c2c66affSColin Finck UINT size = vtx_count * stride;
2205c2c66affSColin Finck struct wined3d_resource *vb;
2206c2c66affSColin Finck UINT vb_pos, align;
2207c2c66affSColin Finck
2208c2c66affSColin Finck TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2209c2c66affSColin Finck iface, primitive_type, primitive_count, data, stride);
2210c2c66affSColin Finck
2211c2c66affSColin Finck if (!primitive_count)
2212c2c66affSColin Finck {
2213c2c66affSColin Finck WARN("primitive_count is 0, returning D3D_OK\n");
2214c2c66affSColin Finck return D3D_OK;
2215c2c66affSColin Finck }
2216c2c66affSColin Finck
2217c2c66affSColin Finck wined3d_mutex_lock();
2218c2c66affSColin Finck hr = d3d8_device_prepare_vertex_buffer(device, size);
2219c2c66affSColin Finck if (FAILED(hr))
2220c2c66affSColin Finck goto done;
2221c2c66affSColin Finck
2222c2c66affSColin Finck vb_pos = device->vertex_buffer_pos;
2223c2c66affSColin Finck align = vb_pos % stride;
2224c2c66affSColin Finck if (align) align = stride - align;
2225c2c66affSColin Finck if (vb_pos + size + align > device->vertex_buffer_size)
2226c2c66affSColin Finck vb_pos = 0;
2227c2c66affSColin Finck else
2228c2c66affSColin Finck vb_pos += align;
2229c2c66affSColin Finck
2230c2c66affSColin Finck wined3d_box.left = vb_pos;
2231c2c66affSColin Finck wined3d_box.right = vb_pos + size;
2232c2c66affSColin Finck vb = wined3d_buffer_get_resource(device->vertex_buffer);
2233c2c66affSColin Finck if (FAILED(wined3d_resource_map(vb, 0, &wined3d_map_desc, &wined3d_box,
22349987f029SAmine Khaldi WINED3D_MAP_WRITE | (vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD))))
2235c2c66affSColin Finck goto done;
2236c2c66affSColin Finck memcpy(wined3d_map_desc.data, data, size);
2237c2c66affSColin Finck wined3d_resource_unmap(vb, 0);
2238c2c66affSColin Finck device->vertex_buffer_pos = vb_pos + size;
2239c2c66affSColin Finck
2240c2c66affSColin Finck hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, stride);
2241c2c66affSColin Finck if (FAILED(hr))
2242c2c66affSColin Finck goto done;
2243c2c66affSColin Finck
2244c2c66affSColin Finck wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
2245c2c66affSColin Finck hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / stride, vtx_count);
2246c2c66affSColin Finck wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
2247c2c66affSColin Finck
2248c2c66affSColin Finck done:
2249c2c66affSColin Finck wined3d_mutex_unlock();
2250c2c66affSColin Finck return hr;
2251c2c66affSColin Finck }
2252c2c66affSColin Finck
2253c2c66affSColin Finck /* The caller is responsible for wined3d locking */
d3d8_device_prepare_index_buffer(struct d3d8_device * device,UINT min_size)2254c2c66affSColin Finck static HRESULT d3d8_device_prepare_index_buffer(struct d3d8_device *device, UINT min_size)
2255c2c66affSColin Finck {
2256c2c66affSColin Finck HRESULT hr;
2257c2c66affSColin Finck
2258c2c66affSColin Finck if (device->index_buffer_size < min_size || !device->index_buffer)
2259c2c66affSColin Finck {
2260c2c66affSColin Finck UINT size = max(device->index_buffer_size * 2, min_size);
22619987f029SAmine Khaldi struct wined3d_buffer_desc desc;
2262c2c66affSColin Finck struct wined3d_buffer *buffer;
2263c2c66affSColin Finck
2264c2c66affSColin Finck TRACE("Growing index buffer to %u bytes\n", size);
2265c2c66affSColin Finck
22669987f029SAmine Khaldi desc.byte_width = size;
22679987f029SAmine Khaldi desc.usage = WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY | WINED3DUSAGE_STATICDECL;
22689987f029SAmine Khaldi desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
22699987f029SAmine Khaldi desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
22709987f029SAmine Khaldi desc.misc_flags = 0;
22719987f029SAmine Khaldi desc.structure_byte_stride = 0;
22729987f029SAmine Khaldi
22739987f029SAmine Khaldi if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc,
22749987f029SAmine Khaldi NULL, NULL, &d3d8_null_wined3d_parent_ops, &buffer)))
2275c2c66affSColin Finck {
22769987f029SAmine Khaldi ERR("Failed to create index buffer, hr %#x.\n", hr);
2277c2c66affSColin Finck return hr;
2278c2c66affSColin Finck }
2279c2c66affSColin Finck
2280c2c66affSColin Finck if (device->index_buffer)
2281c2c66affSColin Finck wined3d_buffer_decref(device->index_buffer);
2282c2c66affSColin Finck
2283c2c66affSColin Finck device->index_buffer = buffer;
2284c2c66affSColin Finck device->index_buffer_size = size;
2285c2c66affSColin Finck device->index_buffer_pos = 0;
2286c2c66affSColin Finck }
2287c2c66affSColin Finck return D3D_OK;
2288c2c66affSColin Finck }
2289c2c66affSColin Finck
d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8 * iface,D3DPRIMITIVETYPE primitive_type,UINT min_vertex_idx,UINT vertex_count,UINT primitive_count,const void * index_data,D3DFORMAT index_format,const void * vertex_data,UINT vertex_stride)2290c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
2291c2c66affSColin Finck D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT vertex_count,
2292c2c66affSColin Finck UINT primitive_count, const void *index_data, D3DFORMAT index_format,
2293c2c66affSColin Finck const void *vertex_data, UINT vertex_stride)
2294c2c66affSColin Finck {
2295c2c66affSColin Finck UINT idx_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
2296c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2297c2c66affSColin Finck UINT idx_fmt_size = index_format == D3DFMT_INDEX16 ? 2 : 4;
2298c2c66affSColin Finck UINT vtx_size = vertex_count * vertex_stride;
2299c2c66affSColin Finck UINT idx_size = idx_count * idx_fmt_size;
2300c2c66affSColin Finck struct wined3d_map_desc wined3d_map_desc;
2301c2c66affSColin Finck struct wined3d_box wined3d_box = {0};
2302c2c66affSColin Finck struct wined3d_resource *ib, *vb;
2303c2c66affSColin Finck UINT vb_pos, ib_pos, align;
2304c2c66affSColin Finck HRESULT hr;
2305c2c66affSColin Finck
2306c2c66affSColin Finck TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u, "
2307c2c66affSColin Finck "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2308c2c66affSColin Finck iface, primitive_type, min_vertex_idx, vertex_count, primitive_count,
2309c2c66affSColin Finck index_data, index_format, vertex_data, vertex_stride);
2310c2c66affSColin Finck
2311c2c66affSColin Finck if (!primitive_count)
2312c2c66affSColin Finck {
2313c2c66affSColin Finck WARN("primitive_count is 0, returning D3D_OK\n");
2314c2c66affSColin Finck return D3D_OK;
2315c2c66affSColin Finck }
2316c2c66affSColin Finck
2317c2c66affSColin Finck wined3d_mutex_lock();
2318c2c66affSColin Finck
2319c2c66affSColin Finck hr = d3d8_device_prepare_vertex_buffer(device, vtx_size);
2320c2c66affSColin Finck if (FAILED(hr))
2321c2c66affSColin Finck goto done;
2322c2c66affSColin Finck
2323c2c66affSColin Finck vb_pos = device->vertex_buffer_pos;
2324c2c66affSColin Finck align = vb_pos % vertex_stride;
2325c2c66affSColin Finck if (align) align = vertex_stride - align;
2326c2c66affSColin Finck if (vb_pos + vtx_size + align > device->vertex_buffer_size)
2327c2c66affSColin Finck vb_pos = 0;
2328c2c66affSColin Finck else
2329c2c66affSColin Finck vb_pos += align;
2330c2c66affSColin Finck
2331c2c66affSColin Finck wined3d_box.left = vb_pos;
2332c2c66affSColin Finck wined3d_box.right = vb_pos + vtx_size;
2333c2c66affSColin Finck vb = wined3d_buffer_get_resource(device->vertex_buffer);
2334c2c66affSColin Finck if (FAILED(hr = wined3d_resource_map(vb, 0, &wined3d_map_desc, &wined3d_box,
23359987f029SAmine Khaldi WINED3D_MAP_WRITE | (vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD))))
2336c2c66affSColin Finck goto done;
2337c2c66affSColin Finck memcpy(wined3d_map_desc.data, (char *)vertex_data + min_vertex_idx * vertex_stride, vtx_size);
2338c2c66affSColin Finck wined3d_resource_unmap(vb, 0);
2339c2c66affSColin Finck device->vertex_buffer_pos = vb_pos + vtx_size;
2340c2c66affSColin Finck
2341c2c66affSColin Finck hr = d3d8_device_prepare_index_buffer(device, idx_size);
2342c2c66affSColin Finck if (FAILED(hr))
2343c2c66affSColin Finck goto done;
2344c2c66affSColin Finck
2345c2c66affSColin Finck ib_pos = device->index_buffer_pos;
2346c2c66affSColin Finck align = ib_pos % idx_fmt_size;
2347c2c66affSColin Finck if (align) align = idx_fmt_size - align;
2348c2c66affSColin Finck if (ib_pos + idx_size + align > device->index_buffer_size)
2349c2c66affSColin Finck ib_pos = 0;
2350c2c66affSColin Finck else
2351c2c66affSColin Finck ib_pos += align;
2352c2c66affSColin Finck
2353c2c66affSColin Finck wined3d_box.left = ib_pos;
2354c2c66affSColin Finck wined3d_box.right = ib_pos + idx_size;
2355c2c66affSColin Finck ib = wined3d_buffer_get_resource(device->index_buffer);
2356c2c66affSColin Finck if (FAILED(hr = wined3d_resource_map(ib, 0, &wined3d_map_desc, &wined3d_box,
23579987f029SAmine Khaldi WINED3D_MAP_WRITE | (ib_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD))))
2358c2c66affSColin Finck goto done;
2359c2c66affSColin Finck memcpy(wined3d_map_desc.data, index_data, idx_size);
2360c2c66affSColin Finck wined3d_resource_unmap(ib, 0);
2361c2c66affSColin Finck device->index_buffer_pos = ib_pos + idx_size;
2362c2c66affSColin Finck
2363c2c66affSColin Finck hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, vertex_stride);
2364c2c66affSColin Finck if (FAILED(hr))
2365c2c66affSColin Finck goto done;
2366c2c66affSColin Finck
2367c2c66affSColin Finck wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer,
2368c2c66affSColin Finck wined3dformat_from_d3dformat(index_format), 0);
2369c2c66affSColin Finck wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / vertex_stride - min_vertex_idx);
2370c2c66affSColin Finck
2371c2c66affSColin Finck wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
2372c2c66affSColin Finck hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / idx_fmt_size, idx_count);
2373c2c66affSColin Finck
2374c2c66affSColin Finck wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
2375c2c66affSColin Finck wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
2376c2c66affSColin Finck wined3d_device_set_base_vertex_index(device->wined3d_device, 0);
2377c2c66affSColin Finck
2378c2c66affSColin Finck done:
2379c2c66affSColin Finck wined3d_mutex_unlock();
2380c2c66affSColin Finck return hr;
2381c2c66affSColin Finck }
2382c2c66affSColin Finck
d3d8_device_ProcessVertices(IDirect3DDevice8 * iface,UINT src_start_idx,UINT dst_idx,UINT vertex_count,IDirect3DVertexBuffer8 * dst_buffer,DWORD flags)2383c2c66affSColin Finck static HRESULT WINAPI d3d8_device_ProcessVertices(IDirect3DDevice8 *iface, UINT src_start_idx,
2384c2c66affSColin Finck UINT dst_idx, UINT vertex_count, IDirect3DVertexBuffer8 *dst_buffer, DWORD flags)
2385c2c66affSColin Finck {
2386c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2387c2c66affSColin Finck struct d3d8_vertexbuffer *dst = unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer);
2388c2c66affSColin Finck HRESULT hr;
2389c2c66affSColin Finck
2390c2c66affSColin Finck TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2391c2c66affSColin Finck iface, src_start_idx, dst_idx, vertex_count, dst_buffer, flags);
2392c2c66affSColin Finck
2393c2c66affSColin Finck wined3d_mutex_lock();
2394c2c66affSColin Finck hr = wined3d_device_process_vertices(device->wined3d_device, src_start_idx, dst_idx,
2395c2c66affSColin Finck vertex_count, dst->wined3d_buffer, NULL, flags, dst->fvf);
2396c2c66affSColin Finck wined3d_mutex_unlock();
2397c2c66affSColin Finck
2398c2c66affSColin Finck return hr;
2399c2c66affSColin Finck }
2400c2c66affSColin Finck
d3d8_device_CreateVertexShader(IDirect3DDevice8 * iface,const DWORD * declaration,const DWORD * byte_code,DWORD * shader,DWORD usage)2401c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreateVertexShader(IDirect3DDevice8 *iface,
2402c2c66affSColin Finck const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
2403c2c66affSColin Finck {
2404c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2405c2c66affSColin Finck struct d3d8_vertex_shader *object;
2406c2c66affSColin Finck DWORD shader_handle;
2407c2c66affSColin Finck DWORD handle;
2408c2c66affSColin Finck HRESULT hr;
2409c2c66affSColin Finck
2410c2c66affSColin Finck TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2411c2c66affSColin Finck iface, declaration, byte_code, shader, usage);
2412c2c66affSColin Finck
24139987f029SAmine Khaldi if (!(object = heap_alloc_zero(sizeof(*object))))
2414c2c66affSColin Finck {
2415c2c66affSColin Finck *shader = 0;
2416c2c66affSColin Finck return E_OUTOFMEMORY;
2417c2c66affSColin Finck }
2418c2c66affSColin Finck
2419c2c66affSColin Finck wined3d_mutex_lock();
2420c2c66affSColin Finck handle = d3d8_allocate_handle(&device->handle_table, object, D3D8_HANDLE_VS);
2421c2c66affSColin Finck wined3d_mutex_unlock();
2422c2c66affSColin Finck if (handle == D3D8_INVALID_HANDLE)
2423c2c66affSColin Finck {
2424c2c66affSColin Finck ERR("Failed to allocate vertex shader handle.\n");
24259987f029SAmine Khaldi heap_free(object);
2426c2c66affSColin Finck *shader = 0;
2427c2c66affSColin Finck return E_OUTOFMEMORY;
2428c2c66affSColin Finck }
2429c2c66affSColin Finck
2430c2c66affSColin Finck shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2431c2c66affSColin Finck
2432c2c66affSColin Finck hr = d3d8_vertex_shader_init(object, device, declaration, byte_code, shader_handle, usage);
2433c2c66affSColin Finck if (FAILED(hr))
2434c2c66affSColin Finck {
2435c2c66affSColin Finck WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2436c2c66affSColin Finck wined3d_mutex_lock();
2437c2c66affSColin Finck d3d8_free_handle(&device->handle_table, handle, D3D8_HANDLE_VS);
2438c2c66affSColin Finck wined3d_mutex_unlock();
24399987f029SAmine Khaldi heap_free(object);
2440c2c66affSColin Finck *shader = 0;
2441c2c66affSColin Finck return hr;
2442c2c66affSColin Finck }
2443c2c66affSColin Finck
2444c2c66affSColin Finck TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
2445c2c66affSColin Finck *shader = shader_handle;
2446c2c66affSColin Finck
2447c2c66affSColin Finck return D3D_OK;
2448c2c66affSColin Finck }
2449c2c66affSColin Finck
d3d8_device_get_fvf_declaration(struct d3d8_device * device,DWORD fvf)2450c2c66affSColin Finck static struct d3d8_vertex_declaration *d3d8_device_get_fvf_declaration(struct d3d8_device *device, DWORD fvf)
2451c2c66affSColin Finck {
2452c2c66affSColin Finck struct d3d8_vertex_declaration *d3d8_declaration;
2453c2c66affSColin Finck struct FvfToDecl *convertedDecls = device->decls;
2454c2c66affSColin Finck int p, low, high; /* deliberately signed */
2455c2c66affSColin Finck HRESULT hr;
2456c2c66affSColin Finck
2457c2c66affSColin Finck TRACE("Searching for declaration for fvf %08x... ", fvf);
2458c2c66affSColin Finck
2459c2c66affSColin Finck low = 0;
2460c2c66affSColin Finck high = device->numConvertedDecls - 1;
2461c2c66affSColin Finck while (low <= high)
2462c2c66affSColin Finck {
2463c2c66affSColin Finck p = (low + high) >> 1;
2464c2c66affSColin Finck TRACE("%d ", p);
2465c2c66affSColin Finck
2466c2c66affSColin Finck if (convertedDecls[p].fvf == fvf)
2467c2c66affSColin Finck {
2468c2c66affSColin Finck TRACE("found %p\n", convertedDecls[p].declaration);
2469c2c66affSColin Finck return convertedDecls[p].declaration;
2470c2c66affSColin Finck }
2471c2c66affSColin Finck
2472c2c66affSColin Finck if (convertedDecls[p].fvf < fvf)
2473c2c66affSColin Finck low = p + 1;
2474c2c66affSColin Finck else
2475c2c66affSColin Finck high = p - 1;
2476c2c66affSColin Finck }
2477c2c66affSColin Finck TRACE("not found. Creating and inserting at position %d.\n", low);
2478c2c66affSColin Finck
24799987f029SAmine Khaldi if (!(d3d8_declaration = heap_alloc(sizeof(*d3d8_declaration))))
2480c2c66affSColin Finck return NULL;
2481c2c66affSColin Finck
2482c2c66affSColin Finck if (FAILED(hr = d3d8_vertex_declaration_init_fvf(d3d8_declaration, device, fvf)))
2483c2c66affSColin Finck {
2484c2c66affSColin Finck WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
24859987f029SAmine Khaldi heap_free(d3d8_declaration);
2486c2c66affSColin Finck return NULL;
2487c2c66affSColin Finck }
2488c2c66affSColin Finck
2489c2c66affSColin Finck if (device->declArraySize == device->numConvertedDecls)
2490c2c66affSColin Finck {
2491c2c66affSColin Finck UINT grow = device->declArraySize / 2;
2492c2c66affSColin Finck
24939987f029SAmine Khaldi if (!(convertedDecls = heap_realloc(convertedDecls,
24949987f029SAmine Khaldi sizeof(*convertedDecls) * (device->numConvertedDecls + grow))))
2495c2c66affSColin Finck {
2496c2c66affSColin Finck d3d8_vertex_declaration_destroy(d3d8_declaration);
2497c2c66affSColin Finck return NULL;
2498c2c66affSColin Finck }
2499c2c66affSColin Finck device->decls = convertedDecls;
2500c2c66affSColin Finck device->declArraySize += grow;
2501c2c66affSColin Finck }
2502c2c66affSColin Finck
2503c2c66affSColin Finck memmove(convertedDecls + low + 1, convertedDecls + low,
2504c2c66affSColin Finck sizeof(*convertedDecls) * (device->numConvertedDecls - low));
2505c2c66affSColin Finck convertedDecls[low].declaration = d3d8_declaration;
2506c2c66affSColin Finck convertedDecls[low].fvf = fvf;
2507c2c66affSColin Finck ++device->numConvertedDecls;
2508c2c66affSColin Finck
2509c2c66affSColin Finck TRACE("Returning %p. %u decls in array.\n", d3d8_declaration, device->numConvertedDecls);
2510c2c66affSColin Finck
2511c2c66affSColin Finck return d3d8_declaration;
2512c2c66affSColin Finck }
2513c2c66affSColin Finck
d3d8_device_SetVertexShader(IDirect3DDevice8 * iface,DWORD shader)2514c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetVertexShader(IDirect3DDevice8 *iface, DWORD shader)
2515c2c66affSColin Finck {
2516c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2517c2c66affSColin Finck struct d3d8_vertex_shader *shader_impl;
2518c2c66affSColin Finck
2519c2c66affSColin Finck TRACE("iface %p, shader %#x.\n", iface, shader);
2520c2c66affSColin Finck
2521c2c66affSColin Finck if (VS_HIGHESTFIXEDFXF >= shader)
2522c2c66affSColin Finck {
2523c2c66affSColin Finck TRACE("Setting FVF, %#x\n", shader);
2524c2c66affSColin Finck
2525c2c66affSColin Finck wined3d_mutex_lock();
2526c2c66affSColin Finck wined3d_device_set_vertex_declaration(device->wined3d_device,
2527c2c66affSColin Finck d3d8_device_get_fvf_declaration(device, shader)->wined3d_vertex_declaration);
2528c2c66affSColin Finck wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
2529c2c66affSColin Finck wined3d_mutex_unlock();
2530c2c66affSColin Finck
2531c2c66affSColin Finck return D3D_OK;
2532c2c66affSColin Finck }
2533c2c66affSColin Finck
2534c2c66affSColin Finck TRACE("Setting shader\n");
2535c2c66affSColin Finck
2536c2c66affSColin Finck wined3d_mutex_lock();
2537c2c66affSColin Finck if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2538c2c66affSColin Finck {
2539c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", shader);
2540c2c66affSColin Finck wined3d_mutex_unlock();
2541c2c66affSColin Finck
2542c2c66affSColin Finck return D3DERR_INVALIDCALL;
2543c2c66affSColin Finck }
2544c2c66affSColin Finck
2545c2c66affSColin Finck wined3d_device_set_vertex_declaration(device->wined3d_device,
2546c2c66affSColin Finck shader_impl->vertex_declaration->wined3d_vertex_declaration);
2547c2c66affSColin Finck wined3d_device_set_vertex_shader(device->wined3d_device, shader_impl->wined3d_shader);
2548c2c66affSColin Finck wined3d_mutex_unlock();
2549c2c66affSColin Finck
2550c2c66affSColin Finck return D3D_OK;
2551c2c66affSColin Finck }
2552c2c66affSColin Finck
d3d8_device_GetVertexShader(IDirect3DDevice8 * iface,DWORD * shader)2553c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetVertexShader(IDirect3DDevice8 *iface, DWORD *shader)
2554c2c66affSColin Finck {
2555c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2556c2c66affSColin Finck struct wined3d_vertex_declaration *wined3d_declaration;
2557c2c66affSColin Finck struct d3d8_vertex_declaration *d3d8_declaration;
2558c2c66affSColin Finck
2559c2c66affSColin Finck TRACE("iface %p, shader %p.\n", iface, shader);
2560c2c66affSColin Finck
2561c2c66affSColin Finck wined3d_mutex_lock();
2562c2c66affSColin Finck if ((wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
2563c2c66affSColin Finck {
2564c2c66affSColin Finck d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2565c2c66affSColin Finck *shader = d3d8_declaration->shader_handle;
2566c2c66affSColin Finck }
2567c2c66affSColin Finck else
2568c2c66affSColin Finck {
2569c2c66affSColin Finck *shader = 0;
2570c2c66affSColin Finck }
2571c2c66affSColin Finck wined3d_mutex_unlock();
2572c2c66affSColin Finck
2573c2c66affSColin Finck TRACE("Returning %#x.\n", *shader);
2574c2c66affSColin Finck
2575c2c66affSColin Finck return D3D_OK;
2576c2c66affSColin Finck }
2577c2c66affSColin Finck
d3d8_device_DeleteVertexShader(IDirect3DDevice8 * iface,DWORD shader)2578c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DeleteVertexShader(IDirect3DDevice8 *iface, DWORD shader)
2579c2c66affSColin Finck {
2580c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2581c2c66affSColin Finck struct d3d8_vertex_shader *shader_impl;
2582c2c66affSColin Finck
2583c2c66affSColin Finck TRACE("iface %p, shader %#x.\n", iface, shader);
2584c2c66affSColin Finck
2585c2c66affSColin Finck wined3d_mutex_lock();
2586c2c66affSColin Finck if (!(shader_impl = d3d8_free_handle(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2587c2c66affSColin Finck {
2588c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", shader);
2589c2c66affSColin Finck wined3d_mutex_unlock();
2590c2c66affSColin Finck
2591c2c66affSColin Finck return D3DERR_INVALIDCALL;
2592c2c66affSColin Finck }
2593c2c66affSColin Finck
2594c2c66affSColin Finck if (shader_impl->wined3d_shader
2595c2c66affSColin Finck && wined3d_device_get_vertex_shader(device->wined3d_device) == shader_impl->wined3d_shader)
2596c2c66affSColin Finck IDirect3DDevice8_SetVertexShader(iface, 0);
2597c2c66affSColin Finck
2598c2c66affSColin Finck wined3d_mutex_unlock();
2599c2c66affSColin Finck
2600c2c66affSColin Finck d3d8_vertex_shader_destroy(shader_impl);
2601c2c66affSColin Finck
2602c2c66affSColin Finck return D3D_OK;
2603c2c66affSColin Finck }
2604c2c66affSColin Finck
d3d8_device_SetVertexShaderConstant(IDirect3DDevice8 * iface,DWORD start_register,const void * data,DWORD count)2605c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2606c2c66affSColin Finck DWORD start_register, const void *data, DWORD count)
2607c2c66affSColin Finck {
2608c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2609c2c66affSColin Finck HRESULT hr;
2610c2c66affSColin Finck
2611c2c66affSColin Finck TRACE("iface %p, start_register %u, data %p, count %u.\n",
2612c2c66affSColin Finck iface, start_register, data, count);
2613c2c66affSColin Finck
2614c2c66affSColin Finck if (start_register + count > D3D8_MAX_VERTEX_SHADER_CONSTANTF)
2615c2c66affSColin Finck {
2616c2c66affSColin Finck WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2617c2c66affSColin Finck start_register + count, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2618c2c66affSColin Finck return D3DERR_INVALIDCALL;
2619c2c66affSColin Finck }
2620c2c66affSColin Finck
2621c2c66affSColin Finck wined3d_mutex_lock();
2622c2c66affSColin Finck hr = wined3d_device_set_vs_consts_f(device->wined3d_device, start_register, count, data);
2623c2c66affSColin Finck wined3d_mutex_unlock();
2624c2c66affSColin Finck
2625c2c66affSColin Finck return hr;
2626c2c66affSColin Finck }
2627c2c66affSColin Finck
d3d8_device_GetVertexShaderConstant(IDirect3DDevice8 * iface,DWORD start_register,void * data,DWORD count)2628c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2629c2c66affSColin Finck DWORD start_register, void *data, DWORD count)
2630c2c66affSColin Finck {
2631c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2632c2c66affSColin Finck HRESULT hr;
2633c2c66affSColin Finck
2634c2c66affSColin Finck TRACE("iface %p, start_register %u, data %p, count %u.\n",
2635c2c66affSColin Finck iface, start_register, data, count);
2636c2c66affSColin Finck
2637c2c66affSColin Finck if (start_register + count > D3D8_MAX_VERTEX_SHADER_CONSTANTF)
2638c2c66affSColin Finck {
2639c2c66affSColin Finck WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2640c2c66affSColin Finck start_register + count, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2641c2c66affSColin Finck return D3DERR_INVALIDCALL;
2642c2c66affSColin Finck }
2643c2c66affSColin Finck
2644c2c66affSColin Finck wined3d_mutex_lock();
2645c2c66affSColin Finck hr = wined3d_device_get_vs_consts_f(device->wined3d_device, start_register, count, data);
2646c2c66affSColin Finck wined3d_mutex_unlock();
2647c2c66affSColin Finck
2648c2c66affSColin Finck return hr;
2649c2c66affSColin Finck }
2650c2c66affSColin Finck
d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8 * iface,DWORD shader,void * data,DWORD * data_size)2651c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2652c2c66affSColin Finck DWORD shader, void *data, DWORD *data_size)
2653c2c66affSColin Finck {
2654c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2655c2c66affSColin Finck struct d3d8_vertex_declaration *declaration;
2656c2c66affSColin Finck struct d3d8_vertex_shader *shader_impl;
2657c2c66affSColin Finck
2658c2c66affSColin Finck TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2659c2c66affSColin Finck iface, shader, data, data_size);
2660c2c66affSColin Finck
2661c2c66affSColin Finck wined3d_mutex_lock();
2662c2c66affSColin Finck shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2663c2c66affSColin Finck wined3d_mutex_unlock();
2664c2c66affSColin Finck
2665c2c66affSColin Finck if (!shader_impl)
2666c2c66affSColin Finck {
2667c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", shader);
2668c2c66affSColin Finck return D3DERR_INVALIDCALL;
2669c2c66affSColin Finck }
2670c2c66affSColin Finck declaration = shader_impl->vertex_declaration;
2671c2c66affSColin Finck
2672c2c66affSColin Finck if (!data)
2673c2c66affSColin Finck {
2674c2c66affSColin Finck *data_size = declaration->elements_size;
2675c2c66affSColin Finck return D3D_OK;
2676c2c66affSColin Finck }
2677c2c66affSColin Finck
2678c2c66affSColin Finck /* MSDN claims that if *data_size is smaller than the required size
2679c2c66affSColin Finck * we should write the required size and return D3DERR_MOREDATA.
2680c2c66affSColin Finck * That's not actually true. */
2681c2c66affSColin Finck if (*data_size < declaration->elements_size)
2682c2c66affSColin Finck return D3DERR_INVALIDCALL;
2683c2c66affSColin Finck
2684c2c66affSColin Finck memcpy(data, declaration->elements, declaration->elements_size);
2685c2c66affSColin Finck
2686c2c66affSColin Finck return D3D_OK;
2687c2c66affSColin Finck }
2688c2c66affSColin Finck
d3d8_device_GetVertexShaderFunction(IDirect3DDevice8 * iface,DWORD shader,void * data,DWORD * data_size)2689c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2690c2c66affSColin Finck DWORD shader, void *data, DWORD *data_size)
2691c2c66affSColin Finck {
2692c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2693c2c66affSColin Finck struct d3d8_vertex_shader *shader_impl = NULL;
2694c2c66affSColin Finck HRESULT hr;
2695c2c66affSColin Finck
2696c2c66affSColin Finck TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2697c2c66affSColin Finck iface, shader, data, data_size);
2698c2c66affSColin Finck
2699c2c66affSColin Finck wined3d_mutex_lock();
2700c2c66affSColin Finck if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2701c2c66affSColin Finck {
2702c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", shader);
2703c2c66affSColin Finck wined3d_mutex_unlock();
2704c2c66affSColin Finck
2705c2c66affSColin Finck return D3DERR_INVALIDCALL;
2706c2c66affSColin Finck }
2707c2c66affSColin Finck
2708c2c66affSColin Finck if (!shader_impl->wined3d_shader)
2709c2c66affSColin Finck {
2710c2c66affSColin Finck wined3d_mutex_unlock();
2711c2c66affSColin Finck *data_size = 0;
2712c2c66affSColin Finck return D3D_OK;
2713c2c66affSColin Finck }
2714c2c66affSColin Finck
2715c2c66affSColin Finck hr = wined3d_shader_get_byte_code(shader_impl->wined3d_shader, data, data_size);
2716c2c66affSColin Finck wined3d_mutex_unlock();
2717c2c66affSColin Finck
2718c2c66affSColin Finck return hr;
2719c2c66affSColin Finck }
2720c2c66affSColin Finck
d3d8_device_SetIndices(IDirect3DDevice8 * iface,IDirect3DIndexBuffer8 * buffer,UINT base_vertex_idx)2721c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetIndices(IDirect3DDevice8 *iface,
2722c2c66affSColin Finck IDirect3DIndexBuffer8 *buffer, UINT base_vertex_idx)
2723c2c66affSColin Finck {
2724c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2725c2c66affSColin Finck struct d3d8_indexbuffer *ib = unsafe_impl_from_IDirect3DIndexBuffer8(buffer);
2726c2c66affSColin Finck
2727c2c66affSColin Finck TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, buffer, base_vertex_idx);
2728c2c66affSColin Finck
2729c2c66affSColin Finck /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2730c2c66affSColin Finck * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2731c2c66affSColin Finck * vertex buffers can't be created to address them with an index that requires the 32nd bit
2732c2c66affSColin Finck * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2733c2c66affSColin Finck * problem)
2734c2c66affSColin Finck */
2735c2c66affSColin Finck wined3d_mutex_lock();
2736c2c66affSColin Finck wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
2737c2c66affSColin Finck wined3d_device_set_index_buffer(device->wined3d_device,
2738c2c66affSColin Finck ib ? ib->wined3d_buffer : NULL, ib ? ib->format : WINED3DFMT_UNKNOWN, 0);
2739c2c66affSColin Finck wined3d_mutex_unlock();
2740c2c66affSColin Finck
2741c2c66affSColin Finck return D3D_OK;
2742c2c66affSColin Finck }
2743c2c66affSColin Finck
d3d8_device_GetIndices(IDirect3DDevice8 * iface,IDirect3DIndexBuffer8 ** buffer,UINT * base_vertex_index)2744c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetIndices(IDirect3DDevice8 *iface,
2745c2c66affSColin Finck IDirect3DIndexBuffer8 **buffer, UINT *base_vertex_index)
2746c2c66affSColin Finck {
2747c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2748c2c66affSColin Finck enum wined3d_format_id wined3d_format;
2749c2c66affSColin Finck struct wined3d_buffer *wined3d_buffer;
2750c2c66affSColin Finck struct d3d8_indexbuffer *buffer_impl;
2751c2c66affSColin Finck
2752c2c66affSColin Finck TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, buffer, base_vertex_index);
2753c2c66affSColin Finck
2754c2c66affSColin Finck if (!buffer)
2755c2c66affSColin Finck return D3DERR_INVALIDCALL;
2756c2c66affSColin Finck
2757c2c66affSColin Finck /* The case from UINT to INT is safe because d3d8 will never set negative values */
2758c2c66affSColin Finck wined3d_mutex_lock();
2759c2c66affSColin Finck *base_vertex_index = wined3d_device_get_base_vertex_index(device->wined3d_device);
2760c2c66affSColin Finck if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, NULL)))
2761c2c66affSColin Finck {
2762c2c66affSColin Finck buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2763c2c66affSColin Finck *buffer = &buffer_impl->IDirect3DIndexBuffer8_iface;
2764c2c66affSColin Finck IDirect3DIndexBuffer8_AddRef(*buffer);
2765c2c66affSColin Finck }
2766c2c66affSColin Finck else
2767c2c66affSColin Finck {
2768c2c66affSColin Finck *buffer = NULL;
2769c2c66affSColin Finck }
2770c2c66affSColin Finck wined3d_mutex_unlock();
2771c2c66affSColin Finck
2772c2c66affSColin Finck return D3D_OK;
2773c2c66affSColin Finck }
2774c2c66affSColin Finck
d3d8_device_CreatePixelShader(IDirect3DDevice8 * iface,const DWORD * byte_code,DWORD * shader)2775c2c66affSColin Finck static HRESULT WINAPI d3d8_device_CreatePixelShader(IDirect3DDevice8 *iface,
2776c2c66affSColin Finck const DWORD *byte_code, DWORD *shader)
2777c2c66affSColin Finck {
2778c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2779c2c66affSColin Finck struct d3d8_pixel_shader *object;
2780c2c66affSColin Finck DWORD shader_handle;
2781c2c66affSColin Finck DWORD handle;
2782c2c66affSColin Finck HRESULT hr;
2783c2c66affSColin Finck
2784c2c66affSColin Finck TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2785c2c66affSColin Finck
2786c2c66affSColin Finck if (!shader)
2787c2c66affSColin Finck return D3DERR_INVALIDCALL;
2788c2c66affSColin Finck
27899987f029SAmine Khaldi if (!(object = heap_alloc_zero(sizeof(*object))))
2790c2c66affSColin Finck return E_OUTOFMEMORY;
2791c2c66affSColin Finck
2792c2c66affSColin Finck wined3d_mutex_lock();
2793c2c66affSColin Finck handle = d3d8_allocate_handle(&device->handle_table, object, D3D8_HANDLE_PS);
2794c2c66affSColin Finck wined3d_mutex_unlock();
2795c2c66affSColin Finck if (handle == D3D8_INVALID_HANDLE)
2796c2c66affSColin Finck {
2797c2c66affSColin Finck ERR("Failed to allocate pixel shader handle.\n");
27989987f029SAmine Khaldi heap_free(object);
2799c2c66affSColin Finck return E_OUTOFMEMORY;
2800c2c66affSColin Finck }
2801c2c66affSColin Finck
2802c2c66affSColin Finck shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2803c2c66affSColin Finck
2804c2c66affSColin Finck hr = d3d8_pixel_shader_init(object, device, byte_code, shader_handle);
2805c2c66affSColin Finck if (FAILED(hr))
2806c2c66affSColin Finck {
2807c2c66affSColin Finck WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2808c2c66affSColin Finck wined3d_mutex_lock();
2809c2c66affSColin Finck d3d8_free_handle(&device->handle_table, handle, D3D8_HANDLE_PS);
2810c2c66affSColin Finck wined3d_mutex_unlock();
28119987f029SAmine Khaldi heap_free(object);
2812c2c66affSColin Finck *shader = 0;
2813c2c66affSColin Finck return hr;
2814c2c66affSColin Finck }
2815c2c66affSColin Finck
2816c2c66affSColin Finck TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2817c2c66affSColin Finck *shader = shader_handle;
2818c2c66affSColin Finck
2819c2c66affSColin Finck return D3D_OK;
2820c2c66affSColin Finck }
2821c2c66affSColin Finck
d3d8_device_SetPixelShader(IDirect3DDevice8 * iface,DWORD shader)2822c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetPixelShader(IDirect3DDevice8 *iface, DWORD shader)
2823c2c66affSColin Finck {
2824c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2825c2c66affSColin Finck struct d3d8_pixel_shader *shader_impl;
2826c2c66affSColin Finck
2827c2c66affSColin Finck TRACE("iface %p, shader %#x.\n", iface, shader);
2828c2c66affSColin Finck
2829c2c66affSColin Finck wined3d_mutex_lock();
2830c2c66affSColin Finck
2831c2c66affSColin Finck if (!shader)
2832c2c66affSColin Finck {
2833c2c66affSColin Finck wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
2834c2c66affSColin Finck wined3d_mutex_unlock();
2835c2c66affSColin Finck return D3D_OK;
2836c2c66affSColin Finck }
2837c2c66affSColin Finck
2838c2c66affSColin Finck if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2839c2c66affSColin Finck {
2840c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", shader);
2841c2c66affSColin Finck wined3d_mutex_unlock();
2842c2c66affSColin Finck return D3DERR_INVALIDCALL;
2843c2c66affSColin Finck }
2844c2c66affSColin Finck
2845c2c66affSColin Finck TRACE("Setting shader %p.\n", shader_impl);
2846c2c66affSColin Finck wined3d_device_set_pixel_shader(device->wined3d_device, shader_impl->wined3d_shader);
2847c2c66affSColin Finck wined3d_mutex_unlock();
2848c2c66affSColin Finck
2849c2c66affSColin Finck return D3D_OK;
2850c2c66affSColin Finck }
2851c2c66affSColin Finck
d3d8_device_GetPixelShader(IDirect3DDevice8 * iface,DWORD * shader)2852c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetPixelShader(IDirect3DDevice8 *iface, DWORD *shader)
2853c2c66affSColin Finck {
2854c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2855c2c66affSColin Finck struct wined3d_shader *object;
2856c2c66affSColin Finck
2857c2c66affSColin Finck TRACE("iface %p, shader %p.\n", iface, shader);
2858c2c66affSColin Finck
2859c2c66affSColin Finck if (!shader)
2860c2c66affSColin Finck return D3DERR_INVALIDCALL;
2861c2c66affSColin Finck
2862c2c66affSColin Finck wined3d_mutex_lock();
2863c2c66affSColin Finck if ((object = wined3d_device_get_pixel_shader(device->wined3d_device)))
2864c2c66affSColin Finck {
2865c2c66affSColin Finck struct d3d8_pixel_shader *d3d8_shader;
2866c2c66affSColin Finck d3d8_shader = wined3d_shader_get_parent(object);
2867c2c66affSColin Finck *shader = d3d8_shader->handle;
2868c2c66affSColin Finck }
2869c2c66affSColin Finck else
2870c2c66affSColin Finck {
2871c2c66affSColin Finck *shader = 0;
2872c2c66affSColin Finck }
2873c2c66affSColin Finck wined3d_mutex_unlock();
2874c2c66affSColin Finck
2875c2c66affSColin Finck TRACE("Returning %#x.\n", *shader);
2876c2c66affSColin Finck
2877c2c66affSColin Finck return D3D_OK;
2878c2c66affSColin Finck }
2879c2c66affSColin Finck
d3d8_device_DeletePixelShader(IDirect3DDevice8 * iface,DWORD shader)2880c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DeletePixelShader(IDirect3DDevice8 *iface, DWORD shader)
2881c2c66affSColin Finck {
2882c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2883c2c66affSColin Finck struct d3d8_pixel_shader *shader_impl;
2884c2c66affSColin Finck
2885c2c66affSColin Finck TRACE("iface %p, shader %#x.\n", iface, shader);
2886c2c66affSColin Finck
2887c2c66affSColin Finck wined3d_mutex_lock();
2888c2c66affSColin Finck
2889c2c66affSColin Finck if (!(shader_impl = d3d8_free_handle(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2890c2c66affSColin Finck {
2891c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", shader);
2892c2c66affSColin Finck wined3d_mutex_unlock();
2893c2c66affSColin Finck return D3DERR_INVALIDCALL;
2894c2c66affSColin Finck }
2895c2c66affSColin Finck
2896c2c66affSColin Finck if (wined3d_device_get_pixel_shader(device->wined3d_device) == shader_impl->wined3d_shader)
2897c2c66affSColin Finck IDirect3DDevice8_SetPixelShader(iface, 0);
2898c2c66affSColin Finck
2899c2c66affSColin Finck wined3d_mutex_unlock();
2900c2c66affSColin Finck
2901c2c66affSColin Finck d3d8_pixel_shader_destroy(shader_impl);
2902c2c66affSColin Finck
2903c2c66affSColin Finck return D3D_OK;
2904c2c66affSColin Finck }
2905c2c66affSColin Finck
d3d8_device_SetPixelShaderConstant(IDirect3DDevice8 * iface,DWORD start_register,const void * data,DWORD count)2906c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2907c2c66affSColin Finck DWORD start_register, const void *data, DWORD count)
2908c2c66affSColin Finck {
2909c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2910c2c66affSColin Finck HRESULT hr;
2911c2c66affSColin Finck
2912c2c66affSColin Finck TRACE("iface %p, start_register %u, data %p, count %u.\n",
2913c2c66affSColin Finck iface, start_register, data, count);
2914c2c66affSColin Finck
2915c2c66affSColin Finck wined3d_mutex_lock();
2916c2c66affSColin Finck hr = wined3d_device_set_ps_consts_f(device->wined3d_device, start_register, count, data);
2917c2c66affSColin Finck wined3d_mutex_unlock();
2918c2c66affSColin Finck
2919c2c66affSColin Finck return hr;
2920c2c66affSColin Finck }
2921c2c66affSColin Finck
d3d8_device_GetPixelShaderConstant(IDirect3DDevice8 * iface,DWORD start_register,void * data,DWORD count)2922c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2923c2c66affSColin Finck DWORD start_register, void *data, DWORD count)
2924c2c66affSColin Finck {
2925c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2926c2c66affSColin Finck HRESULT hr;
2927c2c66affSColin Finck
2928c2c66affSColin Finck TRACE("iface %p, start_register %u, data %p, count %u.\n",
2929c2c66affSColin Finck iface, start_register, data, count);
2930c2c66affSColin Finck
2931c2c66affSColin Finck wined3d_mutex_lock();
2932c2c66affSColin Finck hr = wined3d_device_get_ps_consts_f(device->wined3d_device, start_register, count, data);
2933c2c66affSColin Finck wined3d_mutex_unlock();
2934c2c66affSColin Finck
2935c2c66affSColin Finck return hr;
2936c2c66affSColin Finck }
2937c2c66affSColin Finck
d3d8_device_GetPixelShaderFunction(IDirect3DDevice8 * iface,DWORD shader,void * data,DWORD * data_size)2938c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2939c2c66affSColin Finck DWORD shader, void *data, DWORD *data_size)
2940c2c66affSColin Finck {
2941c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2942c2c66affSColin Finck struct d3d8_pixel_shader *shader_impl = NULL;
2943c2c66affSColin Finck HRESULT hr;
2944c2c66affSColin Finck
2945c2c66affSColin Finck TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2946c2c66affSColin Finck iface, shader, data, data_size);
2947c2c66affSColin Finck
2948c2c66affSColin Finck wined3d_mutex_lock();
2949c2c66affSColin Finck if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2950c2c66affSColin Finck {
2951c2c66affSColin Finck WARN("Invalid handle (%#x) passed.\n", shader);
2952c2c66affSColin Finck wined3d_mutex_unlock();
2953c2c66affSColin Finck
2954c2c66affSColin Finck return D3DERR_INVALIDCALL;
2955c2c66affSColin Finck }
2956c2c66affSColin Finck
2957c2c66affSColin Finck hr = wined3d_shader_get_byte_code(shader_impl->wined3d_shader, data, data_size);
2958c2c66affSColin Finck wined3d_mutex_unlock();
2959c2c66affSColin Finck
2960c2c66affSColin Finck return hr;
2961c2c66affSColin Finck }
2962c2c66affSColin Finck
d3d8_device_DrawRectPatch(IDirect3DDevice8 * iface,UINT handle,const float * segment_count,const D3DRECTPATCH_INFO * patch_info)2963c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DrawRectPatch(IDirect3DDevice8 *iface, UINT handle,
2964c2c66affSColin Finck const float *segment_count, const D3DRECTPATCH_INFO *patch_info)
2965c2c66affSColin Finck {
2966c2c66affSColin Finck FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2967c2c66affSColin Finck iface, handle, segment_count, patch_info);
2968c2c66affSColin Finck return D3D_OK;
2969c2c66affSColin Finck }
2970c2c66affSColin Finck
d3d8_device_DrawTriPatch(IDirect3DDevice8 * iface,UINT handle,const float * segment_count,const D3DTRIPATCH_INFO * patch_info)2971c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DrawTriPatch(IDirect3DDevice8 *iface, UINT handle,
2972c2c66affSColin Finck const float *segment_count, const D3DTRIPATCH_INFO *patch_info)
2973c2c66affSColin Finck {
2974c2c66affSColin Finck FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2975c2c66affSColin Finck iface, handle, segment_count, patch_info);
2976c2c66affSColin Finck return D3D_OK;
2977c2c66affSColin Finck }
2978c2c66affSColin Finck
d3d8_device_DeletePatch(IDirect3DDevice8 * iface,UINT handle)2979c2c66affSColin Finck static HRESULT WINAPI d3d8_device_DeletePatch(IDirect3DDevice8 *iface, UINT handle)
2980c2c66affSColin Finck {
2981c2c66affSColin Finck FIXME("iface %p, handle %#x unimplemented.\n", iface, handle);
2982c2c66affSColin Finck return D3DERR_INVALIDCALL;
2983c2c66affSColin Finck }
2984c2c66affSColin Finck
d3d8_device_SetStreamSource(IDirect3DDevice8 * iface,UINT stream_idx,IDirect3DVertexBuffer8 * buffer,UINT stride)2985c2c66affSColin Finck static HRESULT WINAPI d3d8_device_SetStreamSource(IDirect3DDevice8 *iface,
2986c2c66affSColin Finck UINT stream_idx, IDirect3DVertexBuffer8 *buffer, UINT stride)
2987c2c66affSColin Finck {
2988c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2989c2c66affSColin Finck struct d3d8_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer8(buffer);
2990c2c66affSColin Finck HRESULT hr;
2991c2c66affSColin Finck
2992c2c66affSColin Finck TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2993c2c66affSColin Finck iface, stream_idx, buffer, stride);
2994c2c66affSColin Finck
2995c2c66affSColin Finck wined3d_mutex_lock();
2996c2c66affSColin Finck hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
2997c2c66affSColin Finck buffer_impl ? buffer_impl->wined3d_buffer : NULL, 0, stride);
2998c2c66affSColin Finck wined3d_mutex_unlock();
2999c2c66affSColin Finck
3000c2c66affSColin Finck return hr;
3001c2c66affSColin Finck }
3002c2c66affSColin Finck
d3d8_device_GetStreamSource(IDirect3DDevice8 * iface,UINT stream_idx,IDirect3DVertexBuffer8 ** buffer,UINT * stride)3003c2c66affSColin Finck static HRESULT WINAPI d3d8_device_GetStreamSource(IDirect3DDevice8 *iface,
3004c2c66affSColin Finck UINT stream_idx, IDirect3DVertexBuffer8 **buffer, UINT *stride)
3005c2c66affSColin Finck {
3006c2c66affSColin Finck struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
3007c2c66affSColin Finck struct d3d8_vertexbuffer *buffer_impl;
3008c2c66affSColin Finck struct wined3d_buffer *wined3d_buffer = NULL;
3009c2c66affSColin Finck HRESULT hr;
3010c2c66affSColin Finck
3011c2c66affSColin Finck TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
3012c2c66affSColin Finck iface, stream_idx, buffer, stride);
3013c2c66affSColin Finck
3014c2c66affSColin Finck if (!buffer)
3015c2c66affSColin Finck return D3DERR_INVALIDCALL;
3016c2c66affSColin Finck
3017c2c66affSColin Finck wined3d_mutex_lock();
3018c2c66affSColin Finck hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer, 0, stride);
3019c2c66affSColin Finck if (SUCCEEDED(hr) && wined3d_buffer)
3020c2c66affSColin Finck {
3021c2c66affSColin Finck buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3022c2c66affSColin Finck *buffer = &buffer_impl->IDirect3DVertexBuffer8_iface;
3023c2c66affSColin Finck IDirect3DVertexBuffer8_AddRef(*buffer);
3024c2c66affSColin Finck }
3025c2c66affSColin Finck else
3026c2c66affSColin Finck {
3027c2c66affSColin Finck if (FAILED(hr))
3028c2c66affSColin Finck ERR("Failed to get wined3d stream source, hr %#x.\n", hr);
3029c2c66affSColin Finck *buffer = NULL;
3030c2c66affSColin Finck }
3031c2c66affSColin Finck wined3d_mutex_unlock();
3032c2c66affSColin Finck
3033c2c66affSColin Finck return hr;
3034c2c66affSColin Finck }
3035c2c66affSColin Finck
3036c2c66affSColin Finck static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl =
3037c2c66affSColin Finck {
3038c2c66affSColin Finck d3d8_device_QueryInterface,
3039c2c66affSColin Finck d3d8_device_AddRef,
3040c2c66affSColin Finck d3d8_device_Release,
3041c2c66affSColin Finck d3d8_device_TestCooperativeLevel,
3042c2c66affSColin Finck d3d8_device_GetAvailableTextureMem,
3043c2c66affSColin Finck d3d8_device_ResourceManagerDiscardBytes,
3044c2c66affSColin Finck d3d8_device_GetDirect3D,
3045c2c66affSColin Finck d3d8_device_GetDeviceCaps,
3046c2c66affSColin Finck d3d8_device_GetDisplayMode,
3047c2c66affSColin Finck d3d8_device_GetCreationParameters,
3048c2c66affSColin Finck d3d8_device_SetCursorProperties,
3049c2c66affSColin Finck d3d8_device_SetCursorPosition,
3050c2c66affSColin Finck d3d8_device_ShowCursor,
3051c2c66affSColin Finck d3d8_device_CreateAdditionalSwapChain,
3052c2c66affSColin Finck d3d8_device_Reset,
3053c2c66affSColin Finck d3d8_device_Present,
3054c2c66affSColin Finck d3d8_device_GetBackBuffer,
3055c2c66affSColin Finck d3d8_device_GetRasterStatus,
3056c2c66affSColin Finck d3d8_device_SetGammaRamp,
3057c2c66affSColin Finck d3d8_device_GetGammaRamp,
3058c2c66affSColin Finck d3d8_device_CreateTexture,
3059c2c66affSColin Finck d3d8_device_CreateVolumeTexture,
3060c2c66affSColin Finck d3d8_device_CreateCubeTexture,
3061c2c66affSColin Finck d3d8_device_CreateVertexBuffer,
3062c2c66affSColin Finck d3d8_device_CreateIndexBuffer,
3063c2c66affSColin Finck d3d8_device_CreateRenderTarget,
3064c2c66affSColin Finck d3d8_device_CreateDepthStencilSurface,
3065c2c66affSColin Finck d3d8_device_CreateImageSurface,
3066c2c66affSColin Finck d3d8_device_CopyRects,
3067c2c66affSColin Finck d3d8_device_UpdateTexture,
3068c2c66affSColin Finck d3d8_device_GetFrontBuffer,
3069c2c66affSColin Finck d3d8_device_SetRenderTarget,
3070c2c66affSColin Finck d3d8_device_GetRenderTarget,
3071c2c66affSColin Finck d3d8_device_GetDepthStencilSurface,
3072c2c66affSColin Finck d3d8_device_BeginScene,
3073c2c66affSColin Finck d3d8_device_EndScene,
3074c2c66affSColin Finck d3d8_device_Clear,
3075c2c66affSColin Finck d3d8_device_SetTransform,
3076c2c66affSColin Finck d3d8_device_GetTransform,
3077c2c66affSColin Finck d3d8_device_MultiplyTransform,
3078c2c66affSColin Finck d3d8_device_SetViewport,
3079c2c66affSColin Finck d3d8_device_GetViewport,
3080c2c66affSColin Finck d3d8_device_SetMaterial,
3081c2c66affSColin Finck d3d8_device_GetMaterial,
3082c2c66affSColin Finck d3d8_device_SetLight,
3083c2c66affSColin Finck d3d8_device_GetLight,
3084c2c66affSColin Finck d3d8_device_LightEnable,
3085c2c66affSColin Finck d3d8_device_GetLightEnable,
3086c2c66affSColin Finck d3d8_device_SetClipPlane,
3087c2c66affSColin Finck d3d8_device_GetClipPlane,
3088c2c66affSColin Finck d3d8_device_SetRenderState,
3089c2c66affSColin Finck d3d8_device_GetRenderState,
3090c2c66affSColin Finck d3d8_device_BeginStateBlock,
3091c2c66affSColin Finck d3d8_device_EndStateBlock,
3092c2c66affSColin Finck d3d8_device_ApplyStateBlock,
3093c2c66affSColin Finck d3d8_device_CaptureStateBlock,
3094c2c66affSColin Finck d3d8_device_DeleteStateBlock,
3095c2c66affSColin Finck d3d8_device_CreateStateBlock,
3096c2c66affSColin Finck d3d8_device_SetClipStatus,
3097c2c66affSColin Finck d3d8_device_GetClipStatus,
3098c2c66affSColin Finck d3d8_device_GetTexture,
3099c2c66affSColin Finck d3d8_device_SetTexture,
3100c2c66affSColin Finck d3d8_device_GetTextureStageState,
3101c2c66affSColin Finck d3d8_device_SetTextureStageState,
3102c2c66affSColin Finck d3d8_device_ValidateDevice,
3103c2c66affSColin Finck d3d8_device_GetInfo,
3104c2c66affSColin Finck d3d8_device_SetPaletteEntries,
3105c2c66affSColin Finck d3d8_device_GetPaletteEntries,
3106c2c66affSColin Finck d3d8_device_SetCurrentTexturePalette,
3107c2c66affSColin Finck d3d8_device_GetCurrentTexturePalette,
3108c2c66affSColin Finck d3d8_device_DrawPrimitive,
3109c2c66affSColin Finck d3d8_device_DrawIndexedPrimitive,
3110c2c66affSColin Finck d3d8_device_DrawPrimitiveUP,
3111c2c66affSColin Finck d3d8_device_DrawIndexedPrimitiveUP,
3112c2c66affSColin Finck d3d8_device_ProcessVertices,
3113c2c66affSColin Finck d3d8_device_CreateVertexShader,
3114c2c66affSColin Finck d3d8_device_SetVertexShader,
3115c2c66affSColin Finck d3d8_device_GetVertexShader,
3116c2c66affSColin Finck d3d8_device_DeleteVertexShader,
3117c2c66affSColin Finck d3d8_device_SetVertexShaderConstant,
3118c2c66affSColin Finck d3d8_device_GetVertexShaderConstant,
3119c2c66affSColin Finck d3d8_device_GetVertexShaderDeclaration,
3120c2c66affSColin Finck d3d8_device_GetVertexShaderFunction,
3121c2c66affSColin Finck d3d8_device_SetStreamSource,
3122c2c66affSColin Finck d3d8_device_GetStreamSource,
3123c2c66affSColin Finck d3d8_device_SetIndices,
3124c2c66affSColin Finck d3d8_device_GetIndices,
3125c2c66affSColin Finck d3d8_device_CreatePixelShader,
3126c2c66affSColin Finck d3d8_device_SetPixelShader,
3127c2c66affSColin Finck d3d8_device_GetPixelShader,
3128c2c66affSColin Finck d3d8_device_DeletePixelShader,
3129c2c66affSColin Finck d3d8_device_SetPixelShaderConstant,
3130c2c66affSColin Finck d3d8_device_GetPixelShaderConstant,
3131c2c66affSColin Finck d3d8_device_GetPixelShaderFunction,
3132c2c66affSColin Finck d3d8_device_DrawRectPatch,
3133c2c66affSColin Finck d3d8_device_DrawTriPatch,
3134c2c66affSColin Finck d3d8_device_DeletePatch,
3135c2c66affSColin Finck };
3136c2c66affSColin Finck
device_from_device_parent(struct wined3d_device_parent * device_parent)3137c2c66affSColin Finck static inline struct d3d8_device *device_from_device_parent(struct wined3d_device_parent *device_parent)
3138c2c66affSColin Finck {
3139c2c66affSColin Finck return CONTAINING_RECORD(device_parent, struct d3d8_device, device_parent);
3140c2c66affSColin Finck }
3141c2c66affSColin Finck
device_parent_wined3d_device_created(struct wined3d_device_parent * device_parent,struct wined3d_device * device)3142c2c66affSColin Finck static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
3143c2c66affSColin Finck struct wined3d_device *device)
3144c2c66affSColin Finck {
3145c2c66affSColin Finck TRACE("device_parent %p, device %p\n", device_parent, device);
3146c2c66affSColin Finck }
3147c2c66affSColin Finck
device_parent_mode_changed(struct wined3d_device_parent * device_parent)3148c2c66affSColin Finck static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
3149c2c66affSColin Finck {
3150c2c66affSColin Finck TRACE("device_parent %p.\n", device_parent);
3151c2c66affSColin Finck }
3152c2c66affSColin Finck
device_parent_activate(struct wined3d_device_parent * device_parent,BOOL activate)3153c2c66affSColin Finck static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
3154c2c66affSColin Finck {
3155c2c66affSColin Finck struct d3d8_device *device = device_from_device_parent(device_parent);
3156c2c66affSColin Finck
3157c2c66affSColin Finck TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
3158c2c66affSColin Finck
3159c2c66affSColin Finck if (!activate)
3160c2c66affSColin Finck InterlockedCompareExchange(&device->device_state, D3D8_DEVICE_STATE_LOST, D3D8_DEVICE_STATE_OK);
3161c2c66affSColin Finck else
3162c2c66affSColin Finck InterlockedCompareExchange(&device->device_state, D3D8_DEVICE_STATE_NOT_RESET, D3D8_DEVICE_STATE_LOST);
3163c2c66affSColin Finck }
3164c2c66affSColin Finck
device_parent_surface_created(struct wined3d_device_parent * device_parent,struct wined3d_texture * wined3d_texture,unsigned int sub_resource_idx,void ** parent,const struct wined3d_parent_ops ** parent_ops)3165*81cffd76SJoachim Henze static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
3166*81cffd76SJoachim Henze struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
3167c2c66affSColin Finck void **parent, const struct wined3d_parent_ops **parent_ops)
3168c2c66affSColin Finck {
31697af3969eSAmine Khaldi struct d3d8_surface *d3d_surface;
3170c2c66affSColin Finck
3171*81cffd76SJoachim Henze TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
3172*81cffd76SJoachim Henze device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
3173*81cffd76SJoachim Henze
31749987f029SAmine Khaldi if (!(d3d_surface = heap_alloc_zero(sizeof(*d3d_surface))))
3175c2c66affSColin Finck return E_OUTOFMEMORY;
3176c2c66affSColin Finck
3177c2c66affSColin Finck surface_init(d3d_surface, wined3d_texture, sub_resource_idx, parent_ops);
3178c2c66affSColin Finck *parent = d3d_surface;
3179c2c66affSColin Finck TRACE("Created surface %p.\n", d3d_surface);
3180*81cffd76SJoachim Henze
3181*81cffd76SJoachim Henze return D3D_OK;
3182c2c66affSColin Finck }
3183*81cffd76SJoachim Henze
device_parent_volume_created(struct wined3d_device_parent * device_parent,struct wined3d_texture * wined3d_texture,unsigned int sub_resource_idx,void ** parent,const struct wined3d_parent_ops ** parent_ops)3184*81cffd76SJoachim Henze static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
3185*81cffd76SJoachim Henze struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
3186*81cffd76SJoachim Henze void **parent, const struct wined3d_parent_ops **parent_ops)
3187c2c66affSColin Finck {
3188c2c66affSColin Finck struct d3d8_volume *d3d_volume;
3189c2c66affSColin Finck
3190*81cffd76SJoachim Henze TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
3191*81cffd76SJoachim Henze device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
3192*81cffd76SJoachim Henze
31939987f029SAmine Khaldi if (!(d3d_volume = heap_alloc_zero(sizeof(*d3d_volume))))
3194c2c66affSColin Finck return E_OUTOFMEMORY;
3195c2c66affSColin Finck
3196c2c66affSColin Finck volume_init(d3d_volume, wined3d_texture, sub_resource_idx, parent_ops);
3197c2c66affSColin Finck *parent = d3d_volume;
3198c2c66affSColin Finck TRACE("Created volume %p.\n", d3d_volume);
3199c2c66affSColin Finck
3200c2c66affSColin Finck return D3D_OK;
3201c2c66affSColin Finck }
3202c2c66affSColin Finck
device_parent_create_swapchain_texture(struct wined3d_device_parent * device_parent,void * container_parent,const struct wined3d_resource_desc * desc,DWORD texture_flags,struct wined3d_texture ** texture)3203c2c66affSColin Finck static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
3204c2c66affSColin Finck void *container_parent, const struct wined3d_resource_desc *desc, DWORD texture_flags,
3205c2c66affSColin Finck struct wined3d_texture **texture)
3206c2c66affSColin Finck {
3207c2c66affSColin Finck struct d3d8_device *device = device_from_device_parent(device_parent);
3208c2c66affSColin Finck struct d3d8_surface *d3d_surface;
3209c2c66affSColin Finck HRESULT hr;
3210c2c66affSColin Finck
3211c2c66affSColin Finck TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
3212c2c66affSColin Finck device_parent, container_parent, desc, texture_flags, texture);
3213c2c66affSColin Finck
3214c2c66affSColin Finck if (FAILED(hr = wined3d_texture_create(device->wined3d_device, desc, 1, 1,
3215c2c66affSColin Finck texture_flags | WINED3D_TEXTURE_CREATE_MAPPABLE, NULL, &device->IDirect3DDevice8_iface,
3216c2c66affSColin Finck &d3d8_null_wined3d_parent_ops, texture)))
3217c2c66affSColin Finck {
3218c2c66affSColin Finck WARN("Failed to create texture, hr %#x.\n", hr);
3219c2c66affSColin Finck return hr;
3220c2c66affSColin Finck }
3221c2c66affSColin Finck
3222c2c66affSColin Finck d3d_surface = wined3d_texture_get_sub_resource_parent(*texture, 0);
3223c2c66affSColin Finck d3d_surface->parent_device = &device->IDirect3DDevice8_iface;
3224c2c66affSColin Finck
3225c2c66affSColin Finck return hr;
3226c2c66affSColin Finck }
3227c2c66affSColin Finck
device_parent_create_swapchain(struct wined3d_device_parent * device_parent,struct wined3d_swapchain_desc * desc,struct wined3d_swapchain ** swapchain)3228c2c66affSColin Finck static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
3229c2c66affSColin Finck struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
3230c2c66affSColin Finck {
3231c2c66affSColin Finck struct d3d8_device *device = device_from_device_parent(device_parent);
3232c2c66affSColin Finck struct d3d8_swapchain *d3d_swapchain;
3233c2c66affSColin Finck HRESULT hr;
3234c2c66affSColin Finck
3235c2c66affSColin Finck TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
3236c2c66affSColin Finck
3237*81cffd76SJoachim Henze if (FAILED(hr = d3d8_swapchain_create(device, desc, &d3d_swapchain)))
3238c2c66affSColin Finck {
3239c2c66affSColin Finck WARN("Failed to create swapchain, hr %#x.\n", hr);
3240c2c66affSColin Finck *swapchain = NULL;
3241c2c66affSColin Finck return hr;
3242c2c66affSColin Finck }
3243c2c66affSColin Finck
3244c2c66affSColin Finck *swapchain = d3d_swapchain->wined3d_swapchain;
3245c2c66affSColin Finck wined3d_swapchain_incref(*swapchain);
3246c2c66affSColin Finck IDirect3DSwapChain8_Release(&d3d_swapchain->IDirect3DSwapChain8_iface);
3247c2c66affSColin Finck
3248c2c66affSColin Finck return hr;
3249c2c66affSColin Finck }
3250c2c66affSColin Finck
3251c2c66affSColin Finck static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops =
3252c2c66affSColin Finck {
3253c2c66affSColin Finck device_parent_wined3d_device_created,
3254c2c66affSColin Finck device_parent_mode_changed,
3255c2c66affSColin Finck device_parent_activate,
3256*81cffd76SJoachim Henze device_parent_surface_created,
3257*81cffd76SJoachim Henze device_parent_volume_created,
3258c2c66affSColin Finck device_parent_create_swapchain_texture,
3259c2c66affSColin Finck device_parent_create_swapchain,
3260c2c66affSColin Finck };
3261c2c66affSColin Finck
setup_fpu(void)3262c2c66affSColin Finck static void setup_fpu(void)
3263c2c66affSColin Finck {
3264c2c66affSColin Finck #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3265c2c66affSColin Finck WORD cw;
3266c2c66affSColin Finck __asm__ volatile ("fnstcw %0" : "=m" (cw));
3267c2c66affSColin Finck cw = (cw & ~0xf3f) | 0x3f;
3268c2c66affSColin Finck __asm__ volatile ("fldcw %0" : : "m" (cw));
3269c2c66affSColin Finck #elif defined(__i386__) && defined(_MSC_VER)
3270c2c66affSColin Finck WORD cw;
3271c2c66affSColin Finck __asm fnstcw cw;
3272c2c66affSColin Finck cw = (cw & ~0xf3f) | 0x3f;
3273c2c66affSColin Finck __asm fldcw cw;
3274c2c66affSColin Finck #else
3275c2c66affSColin Finck FIXME("FPU setup not implemented for this platform.\n");
3276c2c66affSColin Finck #endif
3277c2c66affSColin Finck }
3278c2c66affSColin Finck
device_init(struct d3d8_device * device,struct d3d8 * parent,struct wined3d * wined3d,UINT adapter,D3DDEVTYPE device_type,HWND focus_window,DWORD flags,D3DPRESENT_PARAMETERS * parameters)3279c2c66affSColin Finck HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter,
3280c2c66affSColin Finck D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3281c2c66affSColin Finck {
3282c2c66affSColin Finck struct wined3d_swapchain_desc swapchain_desc;
3283c2c66affSColin Finck struct wined3d_swapchain *wined3d_swapchain;
3284c2c66affSColin Finck HRESULT hr;
3285c2c66affSColin Finck
3286c2c66affSColin Finck device->IDirect3DDevice8_iface.lpVtbl = &d3d8_device_vtbl;
3287c2c66affSColin Finck device->device_parent.ops = &d3d8_wined3d_device_parent_ops;
3288c2c66affSColin Finck device->ref = 1;
32899987f029SAmine Khaldi if (!(device->handle_table.entries = heap_alloc_zero(D3D8_INITIAL_HANDLE_TABLE_SIZE
32909987f029SAmine Khaldi * sizeof(*device->handle_table.entries))))
3291c2c66affSColin Finck {
3292c2c66affSColin Finck ERR("Failed to allocate handle table memory.\n");
3293c2c66affSColin Finck return E_OUTOFMEMORY;
3294c2c66affSColin Finck }
3295c2c66affSColin Finck device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3296c2c66affSColin Finck
3297c2c66affSColin Finck if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3298c2c66affSColin Finck
3299c2c66affSColin Finck wined3d_mutex_lock();
3300c2c66affSColin Finck hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
3301c2c66affSColin Finck &device->device_parent, &device->wined3d_device);
3302c2c66affSColin Finck if (FAILED(hr))
3303c2c66affSColin Finck {
3304c2c66affSColin Finck WARN("Failed to create wined3d device, hr %#x.\n", hr);
3305c2c66affSColin Finck wined3d_mutex_unlock();
33069987f029SAmine Khaldi heap_free(device->handle_table.entries);
3307c2c66affSColin Finck return hr;
3308c2c66affSColin Finck }
3309c2c66affSColin Finck
3310c2c66affSColin Finck if (!parameters->Windowed)
3311c2c66affSColin Finck {
3312c2c66affSColin Finck HWND device_window = parameters->hDeviceWindow;
3313c2c66affSColin Finck
3314c2c66affSColin Finck if (!focus_window)
3315c2c66affSColin Finck focus_window = device_window;
3316c2c66affSColin Finck if (FAILED(hr = wined3d_device_acquire_focus_window(device->wined3d_device, focus_window)))
3317c2c66affSColin Finck {
3318c2c66affSColin Finck ERR("Failed to acquire focus window, hr %#x.\n", hr);
3319c2c66affSColin Finck wined3d_device_decref(device->wined3d_device);
3320c2c66affSColin Finck wined3d_mutex_unlock();
33219987f029SAmine Khaldi heap_free(device->handle_table.entries);
3322c2c66affSColin Finck return hr;
3323c2c66affSColin Finck }
3324c2c66affSColin Finck
3325c2c66affSColin Finck if (!device_window)
3326c2c66affSColin Finck device_window = focus_window;
3327c2c66affSColin Finck wined3d_device_setup_fullscreen_window(device->wined3d_device, device_window,
3328c2c66affSColin Finck parameters->BackBufferWidth,
3329c2c66affSColin Finck parameters->BackBufferHeight);
3330c2c66affSColin Finck }
3331c2c66affSColin Finck
3332c2c66affSColin Finck if (flags & D3DCREATE_MULTITHREADED)
3333c2c66affSColin Finck wined3d_device_set_multithreaded(device->wined3d_device);
3334c2c66affSColin Finck
3335c2c66affSColin Finck if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, parameters))
3336c2c66affSColin Finck {
3337c2c66affSColin Finck wined3d_device_release_focus_window(device->wined3d_device);
3338c2c66affSColin Finck wined3d_device_decref(device->wined3d_device);
3339c2c66affSColin Finck wined3d_mutex_unlock();
33409987f029SAmine Khaldi heap_free(device->handle_table.entries);
3341c2c66affSColin Finck return D3DERR_INVALIDCALL;
3342c2c66affSColin Finck }
3343c2c66affSColin Finck
3344e6c95b14SAmine Khaldi if (FAILED(hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc)))
3345c2c66affSColin Finck {
3346c2c66affSColin Finck WARN("Failed to initialize 3D, hr %#x.\n", hr);
3347c2c66affSColin Finck wined3d_device_release_focus_window(device->wined3d_device);
3348c2c66affSColin Finck wined3d_device_decref(device->wined3d_device);
3349c2c66affSColin Finck wined3d_mutex_unlock();
33509987f029SAmine Khaldi heap_free(device->handle_table.entries);
3351c2c66affSColin Finck return hr;
3352c2c66affSColin Finck }
3353c2c66affSColin Finck
3354e6c95b14SAmine Khaldi wined3d_device_set_render_state(device->wined3d_device,
3355e6c95b14SAmine Khaldi WINED3D_RS_ZENABLE, !!swapchain_desc.enable_auto_depth_stencil);
3356c2c66affSColin Finck wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
3357c2c66affSColin Finck wined3d_mutex_unlock();
3358c2c66affSColin Finck
3359*81cffd76SJoachim Henze present_parameters_from_wined3d_swapchain_desc(parameters, &swapchain_desc);
3360c2c66affSColin Finck
3361c2c66affSColin Finck device->declArraySize = 16;
33629987f029SAmine Khaldi if (!(device->decls = heap_alloc(device->declArraySize * sizeof(*device->decls))))
3363c2c66affSColin Finck {
3364c2c66affSColin Finck ERR("Failed to allocate FVF vertex declaration map memory.\n");
3365c2c66affSColin Finck hr = E_OUTOFMEMORY;
3366c2c66affSColin Finck goto err;
3367c2c66affSColin Finck }
3368c2c66affSColin Finck
3369c2c66affSColin Finck wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, 0);
3370c2c66affSColin Finck device->implicit_swapchain = wined3d_swapchain_get_parent(wined3d_swapchain);
3371c2c66affSColin Finck
3372c2c66affSColin Finck device->d3d_parent = &parent->IDirect3D8_iface;
3373c2c66affSColin Finck IDirect3D8_AddRef(device->d3d_parent);
3374c2c66affSColin Finck
3375c2c66affSColin Finck return D3D_OK;
3376c2c66affSColin Finck
3377c2c66affSColin Finck err:
3378c2c66affSColin Finck wined3d_mutex_lock();
3379c2c66affSColin Finck wined3d_device_uninit_3d(device->wined3d_device);
3380c2c66affSColin Finck wined3d_device_release_focus_window(device->wined3d_device);
3381c2c66affSColin Finck wined3d_device_decref(device->wined3d_device);
3382c2c66affSColin Finck wined3d_mutex_unlock();
33839987f029SAmine Khaldi heap_free(device->handle_table.entries);
3384c2c66affSColin Finck return hr;
3385c2c66affSColin Finck }
3386