VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c@ 23571

Last change on this file since 23571 was 23571, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.30

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette