Sync ddraw, d3d8 and d3d9 + wined3d to wine 1.1.28
[reactos.git] / reactos / 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 return ref;
50 }
51
52 static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
53 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
54 ULONG ref = InterlockedDecrement(&This->ref);
55
56 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
57
58 if (ref == 0) {
59 wined3d_mutex_lock();
60 IWineD3DVertexShader_Release(This->wineD3DVertexShader);
61 wined3d_mutex_unlock();
62
63 IDirect3DDevice9Ex_Release(This->parentDevice);
64 HeapFree(GetProcessHeap(), 0, This);
65 }
66 return ref;
67 }
68
69 /* IDirect3DVertexShader9 Interface follow: */
70 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
71 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
72 IWineD3DDevice *myDevice = NULL;
73 HRESULT hr;
74 TRACE("(%p) : Relay\n", This);
75
76 wined3d_mutex_lock();
77 hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
78 if (WINED3D_OK == hr && myDevice != NULL) {
79 hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
80 IWineD3DDevice_Release(myDevice);
81 } else {
82 *ppDevice = NULL;
83 }
84 wined3d_mutex_unlock();
85
86 TRACE("(%p) returning (%p)\n", This, *ppDevice);
87 return hr;
88 }
89
90 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
91 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
92 HRESULT hr;
93 TRACE("(%p) : Relay\n", This);
94
95 wined3d_mutex_lock();
96 hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
97 wined3d_mutex_unlock();
98
99 return hr;
100 }
101
102
103 static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
104 {
105 /* IUnknown */
106 IDirect3DVertexShader9Impl_QueryInterface,
107 IDirect3DVertexShader9Impl_AddRef,
108 IDirect3DVertexShader9Impl_Release,
109 /* IDirect3DVertexShader9 */
110 IDirect3DVertexShader9Impl_GetDevice,
111 IDirect3DVertexShader9Impl_GetFunction
112 };
113
114
115 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
116 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
117 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
118 HRESULT hrc = D3D_OK;
119 IDirect3DVertexShader9Impl *object;
120
121 /* Setup a stub object for now */
122 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
123 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
124 if (NULL == object) {
125 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
126 return D3DERR_OUTOFVIDEOMEMORY;
127 }
128
129 object->ref = 1;
130 object->lpVtbl = &Direct3DVertexShader9_Vtbl;
131
132 wined3d_mutex_lock();
133 hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
134 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
135 wined3d_mutex_unlock();
136
137 if (FAILED(hrc)) {
138
139 /* free up object */
140 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
141 HeapFree(GetProcessHeap(), 0, object);
142 }else{
143 IDirect3DDevice9Ex_AddRef(iface);
144 object->parentDevice = iface;
145 *ppShader = (IDirect3DVertexShader9 *)object;
146 TRACE("(%p) : Created vertex shader %p\n", This, object);
147 }
148
149 TRACE("(%p) : returning %p\n", This, *ppShader);
150 return hrc;
151 }
152
153 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
154 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
155 HRESULT hrc = D3D_OK;
156
157 TRACE("(%p) : Relay\n", This);
158
159 wined3d_mutex_lock();
160 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
161 wined3d_mutex_unlock();
162
163 TRACE("(%p) : returning hr(%u)\n", This, hrc);
164 return hrc;
165 }
166
167 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9** ppShader) {
168 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
169 IWineD3DVertexShader *pShader;
170 HRESULT hrc = D3D_OK;
171
172 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
173
174 wined3d_mutex_lock();
175 hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
176 if (SUCCEEDED(hrc))
177 {
178 if (pShader)
179 {
180 hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
181 IWineD3DVertexShader_Release(pShader);
182 }
183 else
184 {
185 *ppShader = NULL;
186 }
187 }
188 else
189 {
190 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
191 }
192 wined3d_mutex_unlock();
193
194 TRACE("(%p) : returning %p\n", This, *ppShader);
195 return hrc;
196 }
197
198 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
199 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
200 HRESULT hr;
201 TRACE("(%p) : Relay\n", This);
202
203 if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
204 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
205 Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
206 return D3DERR_INVALIDCALL;
207 }
208
209 wined3d_mutex_lock();
210 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
211 wined3d_mutex_unlock();
212
213 return hr;
214 }
215
216 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
217 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
218 HRESULT hr;
219
220 if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
221 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
222 Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
223 return D3DERR_INVALIDCALL;
224 }
225
226 TRACE("(%p) : Relay\n", This);
227
228 wined3d_mutex_lock();
229 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
230 wined3d_mutex_unlock();
231
232 return hr;
233 }
234
235 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
236 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
237 HRESULT hr;
238 TRACE("(%p) : Relay\n", This);
239
240 wined3d_mutex_lock();
241 hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
242 wined3d_mutex_unlock();
243
244 return hr;
245 }
246
247 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
248 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
249 HRESULT hr;
250 TRACE("(%p) : Relay\n", This);
251
252 wined3d_mutex_lock();
253 hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
254 wined3d_mutex_unlock();
255
256 return hr;
257 }
258
259 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
260 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
261 HRESULT hr;
262 TRACE("(%p) : Relay\n", This);
263
264 wined3d_mutex_lock();
265 hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
266 wined3d_mutex_unlock();
267
268 return hr;
269 }
270
271 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
272 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
273 HRESULT hr;
274 TRACE("(%p) : Relay\n", This);
275
276 wined3d_mutex_lock();
277 hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
278 wined3d_mutex_unlock();
279
280 return hr;
281 }