1 | /*
|
---|
2 | * IDirect3DVertexShader9 implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2003 Jason Edmeades
|
---|
5 | * Raphael Junqueira
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation; either
|
---|
10 | * version 2.1 of the License, or (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU Lesser General Public
|
---|
18 | * License along with this library; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*
|
---|
23 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
24 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
25 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
26 | * a choice of LGPL license versions is made available with the language indicating
|
---|
27 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
28 | * of the LGPL is applied is otherwise unspecified.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #include "config.h"
|
---|
32 | #include "d3d9_private.h"
|
---|
33 |
|
---|
34 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
35 |
|
---|
36 | /* IDirect3DVertexShader9 IUnknown parts follow: */
|
---|
37 | static HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface, REFIID riid, LPVOID* ppobj) {
|
---|
38 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
39 |
|
---|
40 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
|
---|
41 |
|
---|
42 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
43 | || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
|
---|
44 | IDirect3DVertexShader9_AddRef(iface);
|
---|
45 | *ppobj = This;
|
---|
46 | return S_OK;
|
---|
47 | }
|
---|
48 |
|
---|
49 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
50 | *ppobj = NULL;
|
---|
51 | return E_NOINTERFACE;
|
---|
52 | }
|
---|
53 |
|
---|
54 | static ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
|
---|
55 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
56 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
57 |
|
---|
58 | TRACE("%p increasing refcount to %u.\n", iface, ref);
|
---|
59 |
|
---|
60 | if (ref == 1)
|
---|
61 | {
|
---|
62 | IDirect3DDevice9Ex_AddRef(This->parentDevice);
|
---|
63 | wined3d_mutex_lock();
|
---|
64 | IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
|
---|
65 | wined3d_mutex_unlock();
|
---|
66 | }
|
---|
67 |
|
---|
68 | return ref;
|
---|
69 | }
|
---|
70 |
|
---|
71 | static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
|
---|
72 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
73 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
74 |
|
---|
75 | TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
---|
76 |
|
---|
77 | if (ref == 0) {
|
---|
78 | IDirect3DDevice9Ex *parentDevice = This->parentDevice;
|
---|
79 |
|
---|
80 | wined3d_mutex_lock();
|
---|
81 | IWineD3DVertexShader_Release(This->wineD3DVertexShader);
|
---|
82 | wined3d_mutex_unlock();
|
---|
83 |
|
---|
84 | /* Release the device last, as it may cause the device to be destroyed. */
|
---|
85 | IDirect3DDevice9Ex_Release(parentDevice);
|
---|
86 | }
|
---|
87 | return ref;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /* IDirect3DVertexShader9 Interface follow: */
|
---|
91 | static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
|
---|
92 | {
|
---|
93 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
94 |
|
---|
95 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
96 |
|
---|
97 | *device = (IDirect3DDevice9 *)This->parentDevice;
|
---|
98 | IDirect3DDevice9_AddRef(*device);
|
---|
99 |
|
---|
100 | TRACE("Returning device %p.\n", *device);
|
---|
101 |
|
---|
102 | return D3D_OK;
|
---|
103 | }
|
---|
104 |
|
---|
105 | static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
|
---|
106 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
107 | HRESULT hr;
|
---|
108 |
|
---|
109 | TRACE("iface %p, data %p, data_size %p.\n", iface, pData, pSizeOfData);
|
---|
110 |
|
---|
111 | wined3d_mutex_lock();
|
---|
112 | hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
|
---|
113 | wined3d_mutex_unlock();
|
---|
114 |
|
---|
115 | return hr;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
|
---|
120 | {
|
---|
121 | /* IUnknown */
|
---|
122 | IDirect3DVertexShader9Impl_QueryInterface,
|
---|
123 | IDirect3DVertexShader9Impl_AddRef,
|
---|
124 | IDirect3DVertexShader9Impl_Release,
|
---|
125 | /* IDirect3DVertexShader9 */
|
---|
126 | IDirect3DVertexShader9Impl_GetDevice,
|
---|
127 | IDirect3DVertexShader9Impl_GetFunction
|
---|
128 | };
|
---|
129 |
|
---|
130 | static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
|
---|
131 | {
|
---|
132 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
133 | }
|
---|
134 |
|
---|
135 | static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
|
---|
136 | {
|
---|
137 | d3d9_vertexshader_wined3d_object_destroyed,
|
---|
138 | };
|
---|
139 |
|
---|
140 | HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
|
---|
141 | {
|
---|
142 | HRESULT hr;
|
---|
143 |
|
---|
144 | shader->ref = 1;
|
---|
145 | shader->lpVtbl = &Direct3DVertexShader9_Vtbl;
|
---|
146 |
|
---|
147 | wined3d_mutex_lock();
|
---|
148 | hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
|
---|
149 | NULL /* output signature */, &shader->wineD3DVertexShader,
|
---|
150 | (IUnknown *)shader, &d3d9_vertexshader_wined3d_parent_ops);
|
---|
151 | wined3d_mutex_unlock();
|
---|
152 | if (FAILED(hr))
|
---|
153 | {
|
---|
154 | WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
|
---|
155 | return hr;
|
---|
156 | }
|
---|
157 |
|
---|
158 | shader->parentDevice = (IDirect3DDevice9Ex *)device;
|
---|
159 | IDirect3DDevice9Ex_AddRef(shader->parentDevice);
|
---|
160 |
|
---|
161 | return D3D_OK;
|
---|
162 | }
|
---|
163 |
|
---|
164 | HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
|
---|
165 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
166 | HRESULT hrc = D3D_OK;
|
---|
167 |
|
---|
168 | TRACE("iface %p, shader %p.\n", iface, pShader);
|
---|
169 |
|
---|
170 | wined3d_mutex_lock();
|
---|
171 | hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
|
---|
172 | wined3d_mutex_unlock();
|
---|
173 |
|
---|
174 | TRACE("(%p) : returning hr(%u)\n", This, hrc);
|
---|
175 | return hrc;
|
---|
176 | }
|
---|
177 |
|
---|
178 | HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9** ppShader) {
|
---|
179 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
180 | IWineD3DVertexShader *pShader;
|
---|
181 | HRESULT hrc = D3D_OK;
|
---|
182 |
|
---|
183 | TRACE("iface %p, shader %p.\n", iface, ppShader);
|
---|
184 |
|
---|
185 | wined3d_mutex_lock();
|
---|
186 | hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
|
---|
187 | if (SUCCEEDED(hrc))
|
---|
188 | {
|
---|
189 | if (pShader)
|
---|
190 | {
|
---|
191 | hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
|
---|
192 | IWineD3DVertexShader_Release(pShader);
|
---|
193 | }
|
---|
194 | else
|
---|
195 | {
|
---|
196 | *ppShader = NULL;
|
---|
197 | }
|
---|
198 | }
|
---|
199 | else
|
---|
200 | {
|
---|
201 | WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
|
---|
202 | }
|
---|
203 | wined3d_mutex_unlock();
|
---|
204 |
|
---|
205 | TRACE("(%p) : returning %p\n", This, *ppShader);
|
---|
206 | return hrc;
|
---|
207 | }
|
---|
208 |
|
---|
209 | HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
|
---|
210 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
211 | HRESULT hr;
|
---|
212 |
|
---|
213 | TRACE("iface %p, register %u, data %p, count %u.\n",
|
---|
214 | iface, Register, pConstantData, Vector4fCount);
|
---|
215 |
|
---|
216 | if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
|
---|
217 | WARN("Trying to access %u constants, but d3d9 only supports %u\n",
|
---|
218 | Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
|
---|
219 | return D3DERR_INVALIDCALL;
|
---|
220 | }
|
---|
221 |
|
---|
222 | wined3d_mutex_lock();
|
---|
223 | hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
|
---|
224 | wined3d_mutex_unlock();
|
---|
225 |
|
---|
226 | return hr;
|
---|
227 | }
|
---|
228 |
|
---|
229 | HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
|
---|
230 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
231 | HRESULT hr;
|
---|
232 |
|
---|
233 | TRACE("iface %p, register %u, data %p, count %u.\n",
|
---|
234 | iface, Register, pConstantData, Vector4fCount);
|
---|
235 |
|
---|
236 | if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
|
---|
237 | WARN("Trying to access %u constants, but d3d9 only supports %u\n",
|
---|
238 | Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
|
---|
239 | return D3DERR_INVALIDCALL;
|
---|
240 | }
|
---|
241 |
|
---|
242 | wined3d_mutex_lock();
|
---|
243 | hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
|
---|
244 | wined3d_mutex_unlock();
|
---|
245 |
|
---|
246 | return hr;
|
---|
247 | }
|
---|
248 |
|
---|
249 | HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
|
---|
250 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
251 | HRESULT hr;
|
---|
252 |
|
---|
253 | TRACE("iface %p, register %u, data %p, count %u.\n",
|
---|
254 | iface, Register, pConstantData, Vector4iCount);
|
---|
255 |
|
---|
256 | wined3d_mutex_lock();
|
---|
257 | hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
|
---|
258 | wined3d_mutex_unlock();
|
---|
259 |
|
---|
260 | return hr;
|
---|
261 | }
|
---|
262 |
|
---|
263 | HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
|
---|
264 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
265 | HRESULT hr;
|
---|
266 |
|
---|
267 | TRACE("iface %p, register %u, data %p, count %u.\n",
|
---|
268 | iface, Register, pConstantData, Vector4iCount);
|
---|
269 |
|
---|
270 | wined3d_mutex_lock();
|
---|
271 | hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
|
---|
272 | wined3d_mutex_unlock();
|
---|
273 |
|
---|
274 | return hr;
|
---|
275 | }
|
---|
276 |
|
---|
277 | HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
|
---|
278 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
279 | HRESULT hr;
|
---|
280 |
|
---|
281 | TRACE("iface %p, register %u, data %p, count %u.\n",
|
---|
282 | iface, Register, pConstantData, BoolCount);
|
---|
283 |
|
---|
284 | wined3d_mutex_lock();
|
---|
285 | hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
|
---|
286 | wined3d_mutex_unlock();
|
---|
287 |
|
---|
288 | return hr;
|
---|
289 | }
|
---|
290 |
|
---|
291 | HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
|
---|
292 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
293 | HRESULT hr;
|
---|
294 |
|
---|
295 | TRACE("iface %p, register %u, data %p, count %u.\n",
|
---|
296 | iface, Register, pConstantData, BoolCount);
|
---|
297 |
|
---|
298 | wined3d_mutex_lock();
|
---|
299 | hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
|
---|
300 | wined3d_mutex_unlock();
|
---|
301 |
|
---|
302 | return hr;
|
---|
303 | }
|
---|