2 * IDirect3DVertexShader9 implementation
4 * Copyright 2002-2003 Jason Edmeades
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.
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.
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
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
27 /* IDirect3DVertexShader9 IUnknown parts follow: */
28 static HRESULT WINAPI
IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface
, REFIID riid
, LPVOID
* ppobj
) {
29 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
31 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
33 if (IsEqualGUID(riid
, &IID_IUnknown
)
34 || IsEqualGUID(riid
, &IID_IDirect3DVertexShader9
)) {
35 IDirect3DVertexShader9_AddRef(iface
);
40 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
45 static ULONG WINAPI
IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface
) {
46 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
47 ULONG ref
= InterlockedIncrement(&This
->ref
);
49 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
53 IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
55 IWineD3DVertexShader_AddRef(This
->wineD3DVertexShader
);
56 wined3d_mutex_unlock();
62 static ULONG WINAPI
IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface
) {
63 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
64 ULONG ref
= InterlockedDecrement(&This
->ref
);
66 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
69 IDirect3DDevice9Ex
*parentDevice
= This
->parentDevice
;
72 IWineD3DVertexShader_Release(This
->wineD3DVertexShader
);
73 wined3d_mutex_unlock();
75 /* Release the device last, as it may cause the device to be destroyed. */
76 IDirect3DDevice9Ex_Release(parentDevice
);
81 /* IDirect3DVertexShader9 Interface follow: */
82 static HRESULT WINAPI
IDirect3DVertexShader9Impl_GetDevice(IDirect3DVertexShader9
*iface
, IDirect3DDevice9
**device
)
84 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
86 TRACE("iface %p, device %p.\n", iface
, device
);
88 *device
= (IDirect3DDevice9
*)This
->parentDevice
;
89 IDirect3DDevice9_AddRef(*device
);
91 TRACE("Returning device %p.\n", *device
);
96 static HRESULT WINAPI
IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface
, VOID
* pData
, UINT
* pSizeOfData
) {
97 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
100 TRACE("iface %p, data %p, data_size %p.\n", iface
, pData
, pSizeOfData
);
102 wined3d_mutex_lock();
103 hr
= IWineD3DVertexShader_GetFunction(This
->wineD3DVertexShader
, pData
, pSizeOfData
);
104 wined3d_mutex_unlock();
110 static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl
=
113 IDirect3DVertexShader9Impl_QueryInterface
,
114 IDirect3DVertexShader9Impl_AddRef
,
115 IDirect3DVertexShader9Impl_Release
,
116 /* IDirect3DVertexShader9 */
117 IDirect3DVertexShader9Impl_GetDevice
,
118 IDirect3DVertexShader9Impl_GetFunction
121 static void STDMETHODCALLTYPE
d3d9_vertexshader_wined3d_object_destroyed(void *parent
)
123 HeapFree(GetProcessHeap(), 0, parent
);
126 static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops
=
128 d3d9_vertexshader_wined3d_object_destroyed
,
131 HRESULT
vertexshader_init(IDirect3DVertexShader9Impl
*shader
, IDirect3DDevice9Impl
*device
, const DWORD
*byte_code
)
136 shader
->lpVtbl
= &Direct3DVertexShader9_Vtbl
;
138 wined3d_mutex_lock();
139 hr
= IWineD3DDevice_CreateVertexShader(device
->WineD3DDevice
, byte_code
,
140 NULL
/* output signature */, &shader
->wineD3DVertexShader
,
141 (IUnknown
*)shader
, &d3d9_vertexshader_wined3d_parent_ops
);
142 wined3d_mutex_unlock();
145 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr
);
149 shader
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
150 IDirect3DDevice9Ex_AddRef(shader
->parentDevice
);
155 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface
, IDirect3DVertexShader9
* pShader
) {
156 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
157 HRESULT hrc
= D3D_OK
;
159 TRACE("iface %p, shader %p.\n", iface
, pShader
);
161 wined3d_mutex_lock();
162 hrc
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, pShader
==NULL
?NULL
:((IDirect3DVertexShader9Impl
*)pShader
)->wineD3DVertexShader
);
163 wined3d_mutex_unlock();
165 TRACE("(%p) : returning hr(%u)\n", This
, hrc
);
169 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface
, IDirect3DVertexShader9
** ppShader
) {
170 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
171 IWineD3DVertexShader
*pShader
;
172 HRESULT hrc
= D3D_OK
;
174 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
176 wined3d_mutex_lock();
177 hrc
= IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
, &pShader
);
182 hrc
= IWineD3DVertexShader_GetParent(pShader
, (IUnknown
**)ppShader
);
183 IWineD3DVertexShader_Release(pShader
);
192 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This
, hrc
, This
->WineD3DDevice
);
194 wined3d_mutex_unlock();
196 TRACE("(%p) : returning %p\n", This
, *ppShader
);
200 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface
, UINT Register
, CONST
float* pConstantData
, UINT Vector4fCount
) {
201 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
204 TRACE("iface %p, register %u, data %p, count %u.\n",
205 iface
, Register
, pConstantData
, Vector4fCount
);
207 if(Register
+ Vector4fCount
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
) {
208 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
209 Register
+ Vector4fCount
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
210 return D3DERR_INVALIDCALL
;
213 wined3d_mutex_lock();
214 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, Vector4fCount
);
215 wined3d_mutex_unlock();
220 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface
, UINT Register
, float* pConstantData
, UINT Vector4fCount
) {
221 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
224 TRACE("iface %p, register %u, data %p, count %u.\n",
225 iface
, Register
, pConstantData
, Vector4fCount
);
227 if(Register
+ Vector4fCount
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
) {
228 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
229 Register
+ Vector4fCount
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
230 return D3DERR_INVALIDCALL
;
233 wined3d_mutex_lock();
234 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, Vector4fCount
);
235 wined3d_mutex_unlock();
240 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface
, UINT Register
, CONST
int* pConstantData
, UINT Vector4iCount
) {
241 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
244 TRACE("iface %p, register %u, data %p, count %u.\n",
245 iface
, Register
, pConstantData
, Vector4iCount
);
247 wined3d_mutex_lock();
248 hr
= IWineD3DDevice_SetVertexShaderConstantI(This
->WineD3DDevice
, Register
, pConstantData
, Vector4iCount
);
249 wined3d_mutex_unlock();
254 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface
, UINT Register
, int* pConstantData
, UINT Vector4iCount
) {
255 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
258 TRACE("iface %p, register %u, data %p, count %u.\n",
259 iface
, Register
, pConstantData
, Vector4iCount
);
261 wined3d_mutex_lock();
262 hr
= IWineD3DDevice_GetVertexShaderConstantI(This
->WineD3DDevice
, Register
, pConstantData
, Vector4iCount
);
263 wined3d_mutex_unlock();
268 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface
, UINT Register
, CONST BOOL
* pConstantData
, UINT BoolCount
) {
269 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
272 TRACE("iface %p, register %u, data %p, count %u.\n",
273 iface
, Register
, pConstantData
, BoolCount
);
275 wined3d_mutex_lock();
276 hr
= IWineD3DDevice_SetVertexShaderConstantB(This
->WineD3DDevice
, Register
, pConstantData
, BoolCount
);
277 wined3d_mutex_unlock();
282 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface
, UINT Register
, BOOL
* pConstantData
, UINT BoolCount
) {
283 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
286 TRACE("iface %p, register %u, data %p, count %u.\n",
287 iface
, Register
, pConstantData
, BoolCount
);
289 wined3d_mutex_lock();
290 hr
= IWineD3DDevice_GetVertexShaderConstantB(This
->WineD3DDevice
, Register
, pConstantData
, BoolCount
);
291 wined3d_mutex_unlock();