- Revert 44301
[reactos.git] / dll / directx / wine / d3d9 / vertexshader.c
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 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DVertexShader9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
30
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
33 IDirect3DVertexShader9_AddRef(iface);
34 *ppobj = This;
35 return S_OK;
36 }
37
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39 *ppobj = NULL;
40 return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
44 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
45 ULONG ref = InterlockedIncrement(&This->ref);
46
47 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
48
49 if (ref == 1)
50 {
51 IDirect3DDevice9Ex_AddRef(This->parentDevice);
52 wined3d_mutex_lock();
53 IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
54 wined3d_mutex_unlock();
55 }
56
57 return ref;
58 }
59
60 static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
61 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
62 ULONG ref = InterlockedDecrement(&This->ref);
63
64 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
65
66 if (ref == 0) {
67 IDirect3DDevice9Ex_Release(This->parentDevice);
68 wined3d_mutex_lock();
69 IWineD3DVertexShader_Release(This->wineD3DVertexShader);
70 wined3d_mutex_unlock();
71 }
72 return ref;
73 }
74
75 /* IDirect3DVertexShader9 Interface follow: */
76 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
77 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
78 IWineD3DDevice *myDevice = NULL;
79 HRESULT hr;
80 TRACE("(%p) : Relay\n", This);
81
82 wined3d_mutex_lock();
83 hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
84 if (WINED3D_OK == hr && myDevice != NULL) {
85 hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
86 IWineD3DDevice_Release(myDevice);
87 } else {
88 *ppDevice = NULL;
89 }
90 wined3d_mutex_unlock();
91
92 TRACE("(%p) returning (%p)\n", This, *ppDevice);
93 return hr;
94 }
95
96 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
97 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
98 HRESULT hr;
99 TRACE("(%p) : Relay\n", This);
100
101 wined3d_mutex_lock();
102 hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
103 wined3d_mutex_unlock();
104
105 return hr;
106 }
107
108
109 static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
110 {
111 /* IUnknown */
112 IDirect3DVertexShader9Impl_QueryInterface,
113 IDirect3DVertexShader9Impl_AddRef,
114 IDirect3DVertexShader9Impl_Release,
115 /* IDirect3DVertexShader9 */
116 IDirect3DVertexShader9Impl_GetDevice,
117 IDirect3DVertexShader9Impl_GetFunction
118 };
119
120 static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
121 {
122 HeapFree(GetProcessHeap(), 0, parent);
123 }
124
125 static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
126 {
127 d3d9_vertexshader_wined3d_object_destroyed,
128 };
129
130 HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
131 {
132 HRESULT hr;
133
134 shader->ref = 1;
135 shader->lpVtbl = &Direct3DVertexShader9_Vtbl;
136
137 wined3d_mutex_lock();
138 hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
139 NULL /* output signature */, &shader->wineD3DVertexShader,
140 (IUnknown *)shader, &d3d9_vertexshader_wined3d_parent_ops);
141 wined3d_mutex_unlock();
142 if (FAILED(hr))
143 {
144 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
145 return hr;
146 }
147
148 shader->parentDevice = (IDirect3DDevice9Ex *)device;
149 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
150
151 return D3D_OK;
152 }
153
154 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
155 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
156 HRESULT hrc = D3D_OK;
157
158 TRACE("(%p) : Relay\n", This);
159
160 wined3d_mutex_lock();
161 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
162 wined3d_mutex_unlock();
163
164 TRACE("(%p) : returning hr(%u)\n", This, hrc);
165 return hrc;
166 }
167
168 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9** ppShader) {
169 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
170 IWineD3DVertexShader *pShader;
171 HRESULT hrc = D3D_OK;
172
173 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
174
175 wined3d_mutex_lock();
176 hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
177 if (SUCCEEDED(hrc))
178 {
179 if (pShader)
180 {
181 hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
182 IWineD3DVertexShader_Release(pShader);
183 }
184 else
185 {
186 *ppShader = NULL;
187 }
188 }
189 else
190 {
191 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
192 }
193 wined3d_mutex_unlock();
194
195 TRACE("(%p) : returning %p\n", This, *ppShader);
196 return hrc;
197 }
198
199 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
200 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
201 HRESULT hr;
202 TRACE("(%p) : Relay\n", This);
203
204 if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
205 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
206 Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
207 return D3DERR_INVALIDCALL;
208 }
209
210 wined3d_mutex_lock();
211 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
212 wined3d_mutex_unlock();
213
214 return hr;
215 }
216
217 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
218 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
219 HRESULT hr;
220
221 if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
222 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
223 Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
224 return D3DERR_INVALIDCALL;
225 }
226
227 TRACE("(%p) : Relay\n", This);
228
229 wined3d_mutex_lock();
230 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
231 wined3d_mutex_unlock();
232
233 return hr;
234 }
235
236 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
237 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
238 HRESULT hr;
239 TRACE("(%p) : Relay\n", This);
240
241 wined3d_mutex_lock();
242 hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
243 wined3d_mutex_unlock();
244
245 return hr;
246 }
247
248 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
249 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
250 HRESULT hr;
251 TRACE("(%p) : Relay\n", This);
252
253 wined3d_mutex_lock();
254 hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
255 wined3d_mutex_unlock();
256
257 return hr;
258 }
259
260 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
261 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
262 HRESULT hr;
263 TRACE("(%p) : Relay\n", This);
264
265 wined3d_mutex_lock();
266 hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
267 wined3d_mutex_unlock();
268
269 return hr;
270 }
271
272 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
273 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
274 HRESULT hr;
275 TRACE("(%p) : Relay\n", This);
276
277 wined3d_mutex_lock();
278 hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
279 wined3d_mutex_unlock();
280
281 return hr;
282 }