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 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
41 | || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
|
---|
42 | IDirect3DVertexShader9_AddRef(iface);
|
---|
43 | *ppobj = This;
|
---|
44 | return S_OK;
|
---|
45 | }
|
---|
46 |
|
---|
47 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
48 | *ppobj = NULL;
|
---|
49 | return E_NOINTERFACE;
|
---|
50 | }
|
---|
51 |
|
---|
52 | static ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
|
---|
53 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
54 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
55 |
|
---|
56 | TRACE("(%p) : AddRef from %d\n", This, ref - 1);
|
---|
57 |
|
---|
58 | return ref;
|
---|
59 | }
|
---|
60 |
|
---|
61 | static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
|
---|
62 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
63 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
64 |
|
---|
65 | TRACE("(%p) : ReleaseRef to %d\n", This, ref);
|
---|
66 |
|
---|
67 | if (ref == 0) {
|
---|
68 | EnterCriticalSection(&d3d9_cs);
|
---|
69 | IWineD3DVertexShader_Release(This->wineD3DVertexShader);
|
---|
70 | LeaveCriticalSection(&d3d9_cs);
|
---|
71 | IDirect3DDevice9Ex_Release(This->parentDevice);
|
---|
72 | HeapFree(GetProcessHeap(), 0, This);
|
---|
73 | }
|
---|
74 | return ref;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /* IDirect3DVertexShader9 Interface follow: */
|
---|
78 | static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
|
---|
79 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
80 | IWineD3DDevice *myDevice = NULL;
|
---|
81 | HRESULT hr;
|
---|
82 | TRACE("(%p) : Relay\n", This);
|
---|
83 |
|
---|
84 | EnterCriticalSection(&d3d9_cs);
|
---|
85 | hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
|
---|
86 | if (WINED3D_OK == hr && myDevice != NULL) {
|
---|
87 | hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
|
---|
88 | IWineD3DDevice_Release(myDevice);
|
---|
89 | } else {
|
---|
90 | *ppDevice = NULL;
|
---|
91 | }
|
---|
92 | LeaveCriticalSection(&d3d9_cs);
|
---|
93 | TRACE("(%p) returning (%p)\n", This, *ppDevice);
|
---|
94 | return hr;
|
---|
95 | }
|
---|
96 |
|
---|
97 | static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
|
---|
98 | IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
|
---|
99 | HRESULT hr;
|
---|
100 | TRACE("(%p) : Relay\n", This);
|
---|
101 |
|
---|
102 | EnterCriticalSection(&d3d9_cs);
|
---|
103 | hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
|
---|
104 | LeaveCriticalSection(&d3d9_cs);
|
---|
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 |
|
---|
121 | /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
|
---|
122 | HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
|
---|
123 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
124 | HRESULT hrc = D3D_OK;
|
---|
125 | IDirect3DVertexShader9Impl *object;
|
---|
126 |
|
---|
127 | /* Setup a stub object for now */
|
---|
128 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
129 | TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
|
---|
130 | if (NULL == object) {
|
---|
131 | FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
|
---|
132 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
133 | }
|
---|
134 |
|
---|
135 | object->ref = 1;
|
---|
136 | object->lpVtbl = &Direct3DVertexShader9_Vtbl;
|
---|
137 | EnterCriticalSection(&d3d9_cs);
|
---|
138 | hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, NULL /* declaration */, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
|
---|
139 | LeaveCriticalSection(&d3d9_cs);
|
---|
140 |
|
---|
141 | if (FAILED(hrc)) {
|
---|
142 |
|
---|
143 | /* free up object */
|
---|
144 | FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
|
---|
145 | HeapFree(GetProcessHeap(), 0, object);
|
---|
146 | }else{
|
---|
147 | IDirect3DDevice9Ex_AddRef(iface);
|
---|
148 | object->parentDevice = iface;
|
---|
149 | *ppShader = (IDirect3DVertexShader9 *)object;
|
---|
150 | TRACE("(%p) : Created vertex shader %p\n", This, object);
|
---|
151 | }
|
---|
152 |
|
---|
153 | TRACE("(%p) : returning %p\n", This, *ppShader);
|
---|
154 | return hrc;
|
---|
155 | }
|
---|
156 |
|
---|
157 | HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
|
---|
158 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
159 | HRESULT hrc = D3D_OK;
|
---|
160 |
|
---|
161 | TRACE("(%p) : Relay\n", This);
|
---|
162 | EnterCriticalSection(&d3d9_cs);
|
---|
163 | hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
|
---|
164 | LeaveCriticalSection(&d3d9_cs);
|
---|
165 |
|
---|
166 | TRACE("(%p) : returning hr(%u)\n", This, hrc);
|
---|
167 | return hrc;
|
---|
168 | }
|
---|
169 |
|
---|
170 | HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9** ppShader) {
|
---|
171 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
172 | IWineD3DVertexShader *pShader;
|
---|
173 | HRESULT hrc = D3D_OK;
|
---|
174 |
|
---|
175 | TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
|
---|
176 | EnterCriticalSection(&d3d9_cs);
|
---|
177 | hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
|
---|
178 | if (SUCCEEDED(hrc))
|
---|
179 | {
|
---|
180 | if (pShader)
|
---|
181 | {
|
---|
182 | hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
|
---|
183 | IWineD3DVertexShader_Release(pShader);
|
---|
184 | }
|
---|
185 | else
|
---|
186 | {
|
---|
187 | *ppShader = NULL;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | else
|
---|
191 | {
|
---|
192 | WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
|
---|
193 | }
|
---|
194 | LeaveCriticalSection(&d3d9_cs);
|
---|
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 | EnterCriticalSection(&d3d9_cs);
|
---|
211 | hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
|
---|
212 | LeaveCriticalSection(&d3d9_cs);
|
---|
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 | EnterCriticalSection(&d3d9_cs);
|
---|
228 | hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
|
---|
229 | LeaveCriticalSection(&d3d9_cs);
|
---|
230 | return hr;
|
---|
231 | }
|
---|
232 |
|
---|
233 | HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
|
---|
234 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
235 | HRESULT hr;
|
---|
236 | TRACE("(%p) : Relay\n", This);
|
---|
237 |
|
---|
238 | EnterCriticalSection(&d3d9_cs);
|
---|
239 | hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
|
---|
240 | LeaveCriticalSection(&d3d9_cs);
|
---|
241 | return hr;
|
---|
242 | }
|
---|
243 |
|
---|
244 | HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
|
---|
245 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
246 | HRESULT hr;
|
---|
247 | TRACE("(%p) : Relay\n", This);
|
---|
248 |
|
---|
249 | EnterCriticalSection(&d3d9_cs);
|
---|
250 | hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
|
---|
251 | LeaveCriticalSection(&d3d9_cs);
|
---|
252 | return hr;
|
---|
253 | }
|
---|
254 |
|
---|
255 | HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
|
---|
256 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
257 | HRESULT hr;
|
---|
258 | TRACE("(%p) : Relay\n", This);
|
---|
259 |
|
---|
260 | EnterCriticalSection(&d3d9_cs);
|
---|
261 | hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
|
---|
262 | LeaveCriticalSection(&d3d9_cs);
|
---|
263 | return hr;
|
---|
264 | }
|
---|
265 |
|
---|
266 | HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
|
---|
267 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
268 | HRESULT hr;
|
---|
269 | TRACE("(%p) : Relay\n", This);
|
---|
270 |
|
---|
271 | EnterCriticalSection(&d3d9_cs);
|
---|
272 | hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
|
---|
273 | LeaveCriticalSection(&d3d9_cs);
|
---|
274 | return hr;
|
---|
275 | }
|
---|