2 * IDirect3DVertexDeclaration9 implementation
4 * Copyright 2002-2003 Raphael Junqueira
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 /* IDirect3DVertexDeclaration9 IUnknown parts follow: */
28 HRESULT WINAPI
IDirect3DVertexDeclaration9Impl_QueryInterface(LPDIRECT3DVERTEXDECLARATION9 iface
, REFIID riid
, LPVOID
* ppobj
) {
29 IDirect3DVertexDeclaration9Impl
*This
= (IDirect3DVertexDeclaration9Impl
*)iface
;
31 if (IsEqualGUID(riid
, &IID_IUnknown
)
32 || IsEqualGUID(riid
, &IID_IDirect3DVertexDeclaration9
)) {
33 IUnknown_AddRef(iface
);
38 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
42 ULONG WINAPI
IDirect3DVertexDeclaration9Impl_AddRef(LPDIRECT3DVERTEXDECLARATION9 iface
) {
43 IDirect3DVertexDeclaration9Impl
*This
= (IDirect3DVertexDeclaration9Impl
*)iface
;
44 ULONG ref
= InterlockedIncrement(&This
->ref
);
46 TRACE("(%p) : AddRef from %ld\n", This
, ref
- 1);
51 ULONG WINAPI
IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECLARATION9 iface
) {
52 IDirect3DVertexDeclaration9Impl
*This
= (IDirect3DVertexDeclaration9Impl
*)iface
;
53 ULONG ref
= InterlockedDecrement(&This
->ref
);
55 TRACE("(%p) : ReleaseRef to %ld\n", This
, ref
);
58 IWineD3DVertexDeclaration_Release(This
->wineD3DVertexDeclaration
);
59 IUnknown_Release(This
->parentDevice
);
60 HeapFree(GetProcessHeap(), 0, This
);
65 /* IDirect3DVertexDeclaration9 Interface follow: */
66 HRESULT WINAPI
IDirect3DVertexDeclaration9Impl_GetDevice(LPDIRECT3DVERTEXDECLARATION9 iface
, IDirect3DDevice9
** ppDevice
) {
67 IDirect3DVertexDeclaration9Impl
*This
= (IDirect3DVertexDeclaration9Impl
*)iface
;
68 IWineD3DDevice
*myDevice
= NULL
;
71 TRACE("(%p) : Relay\n", iface
);
73 hr
= IWineD3DVertexDeclaration_GetDevice(This
->wineD3DVertexDeclaration
, &myDevice
);
74 if (hr
== D3D_OK
&& myDevice
!= NULL
) {
75 hr
= IWineD3DDevice_GetParent(myDevice
, (IUnknown
**)ppDevice
);
76 IWineD3DDevice_Release(myDevice
);
81 HRESULT WINAPI
IDirect3DVertexDeclaration9Impl_GetDeclaration(LPDIRECT3DVERTEXDECLARATION9 iface
, D3DVERTEXELEMENT9
* pDecl
, UINT
* pNumElements
) {
82 IDirect3DVertexDeclaration9Impl
*This
= (IDirect3DVertexDeclaration9Impl
*)iface
;
85 TRACE("(%p) : Relay\n", iface
);
86 hr
= IWineD3DVertexDeclaration_GetDeclaration(This
->wineD3DVertexDeclaration
, pDecl
, &NumElements
);
88 *pNumElements
= NumElements
;
92 const IDirect3DVertexDeclaration9Vtbl Direct3DVertexDeclaration9_Vtbl
=
95 IDirect3DVertexDeclaration9Impl_QueryInterface
,
96 IDirect3DVertexDeclaration9Impl_AddRef
,
97 IDirect3DVertexDeclaration9Impl_Release
,
98 /* IDirect3DVertexDeclaration9 */
99 IDirect3DVertexDeclaration9Impl_GetDevice
,
100 IDirect3DVertexDeclaration9Impl_GetDeclaration
104 /* IDirect3DDevice9 IDirect3DVertexDeclaration9 Methods follow: */
105 HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9 iface
, CONST D3DVERTEXELEMENT9
* pVertexElements
, IDirect3DVertexDeclaration9
** ppDecl
) {
107 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
108 IDirect3DVertexDeclaration9Impl
*object
= NULL
;
111 TRACE("(%p) : Relay\n", iface
);
112 if (NULL
== ppDecl
) {
113 WARN("(%p) : Caller passed NULL As ppDecl, returning D3DERR_INVALIDCALL",This
);
114 return D3DERR_INVALIDCALL
;
116 /* Allocate the storage for the device */
117 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DVertexDeclaration9Impl
));
118 if (NULL
== object
) {
119 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
120 return D3DERR_OUTOFVIDEOMEMORY
;
123 object
->lpVtbl
= &Direct3DVertexDeclaration9_Vtbl
;
125 hr
= IWineD3DDevice_CreateVertexDeclaration(This
->WineD3DDevice
, pVertexElements
, &object
->wineD3DVertexDeclaration
, (IUnknown
*)object
);
130 FIXME("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This
);
131 HeapFree(GetProcessHeap(), 0, object
);
133 IUnknown_AddRef(iface
);
134 object
->parentDevice
= iface
;
135 *ppDecl
= (LPDIRECT3DVERTEXDECLARATION9
) object
;
136 TRACE("(%p) : Created vertex declatanio %p\n", This
, object
);
141 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9 iface
, IDirect3DVertexDeclaration9
* pDecl
) {
142 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
143 IDirect3DVertexDeclaration9Impl
*pDeclImpl
= (IDirect3DVertexDeclaration9Impl
*)pDecl
;
146 TRACE("(%p) : Relay\n", iface
);
148 hr
= IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
, pDeclImpl
== NULL
? NULL
: pDeclImpl
->wineD3DVertexDeclaration
);
153 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexDeclaration(LPDIRECT3DDEVICE9 iface
, IDirect3DVertexDeclaration9
** ppDecl
) {
154 IDirect3DDevice9Impl
* This
= (IDirect3DDevice9Impl
*) iface
;
155 IWineD3DVertexDeclaration
* pTest
= NULL
;
158 TRACE("(%p) : Relay+\n", iface
);
160 if (NULL
== ppDecl
) {
161 return D3DERR_INVALIDCALL
;
165 hr
= IWineD3DDevice_GetVertexDeclaration(This
->WineD3DDevice
, &pTest
);
166 if (hr
== D3D_OK
&& NULL
!= pTest
) {
167 IWineD3DResource_GetParent(pTest
, (IUnknown
**)ppDecl
);
168 IWineD3DResource_Release(pTest
);
172 TRACE("(%p) : returning %p\n", This
, *ppDecl
);