ntdll: Implement DVD_ReadStructure.
[wine] / dlls / d3d9 / vertexdeclaration.c
1 /*
2  * IDirect3DVertexDeclaration9 implementation
3  *
4  * Copyright 2002-2003 Raphael Junqueira
5  *                     Jason Edmeades
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DVertexDeclaration9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3DVertexDeclaration9Impl_QueryInterface(LPDIRECT3DVERTEXDECLARATION9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DVertexDeclaration9)) {
33         IUnknown_AddRef(iface);
34         *ppobj = This;
35         return D3D_OK;
36     }
37
38     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39     return E_NOINTERFACE;
40 }
41
42 ULONG WINAPI IDirect3DVertexDeclaration9Impl_AddRef(LPDIRECT3DVERTEXDECLARATION9 iface) {
43     IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
44     ULONG ref = InterlockedIncrement(&This->ref);
45
46     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
47
48     return ref;
49 }
50
51 ULONG WINAPI IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECLARATION9 iface) {
52     IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
53     ULONG ref = InterlockedDecrement(&This->ref);
54
55     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
56
57     if (ref == 0) {
58         IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration);
59         HeapFree(GetProcessHeap(), 0, This);
60     }
61     return ref;
62 }
63
64 /* IDirect3DVertexDeclaration9 Interface follow: */
65 HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDevice(LPDIRECT3DVERTEXDECLARATION9 iface, IDirect3DDevice9** ppDevice) {
66     IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
67     IWineD3DDevice *myDevice = NULL;
68     HRESULT hr = D3D_OK;
69
70     TRACE("(%p) : Relay\n", iface);
71
72     hr = IWineD3DVertexDeclaration_GetDevice(This->wineD3DVertexDeclaration, &myDevice);
73     if (hr == D3D_OK && myDevice != NULL) {
74         hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
75         IWineD3DDevice_Release(myDevice);
76     }
77     return hr;
78 }
79
80 HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDeclaration(LPDIRECT3DVERTEXDECLARATION9 iface, D3DVERTEXELEMENT9* pDecl, UINT* pNumElements) {
81     IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
82     DWORD NumElements;
83     HRESULT hr;
84     TRACE("(%p) : Relay\n", iface);
85     hr = IWineD3DVertexDeclaration_GetDeclaration(This->wineD3DVertexDeclaration, pDecl, &NumElements);
86
87     *pNumElements = NumElements;
88     return hr;
89 }
90
91 const IDirect3DVertexDeclaration9Vtbl Direct3DVertexDeclaration9_Vtbl =
92 {
93     /* IUnknown */
94     IDirect3DVertexDeclaration9Impl_QueryInterface,
95     IDirect3DVertexDeclaration9Impl_AddRef,
96     IDirect3DVertexDeclaration9Impl_Release,
97     /* IDirect3DVertexDeclaration9 */
98     IDirect3DVertexDeclaration9Impl_GetDevice,
99     IDirect3DVertexDeclaration9Impl_GetDeclaration
100 };
101
102
103 /* IDirect3DDevice9 IDirect3DVertexDeclaration9 Methods follow: */
104 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9 iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) {
105     
106     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
107     IDirect3DVertexDeclaration9Impl *object = NULL;
108     HRESULT hr = D3D_OK;
109
110     TRACE("(%p) : Relay\n", iface);
111     if (NULL == ppDecl) {
112         WARN("(%p) : Caller passed NULL As ppDecl, returning D3DERR_INVALIDCALL",This);
113         return D3DERR_INVALIDCALL;
114     }
115     /* Allocate the storage for the device */
116     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexDeclaration9Impl));
117     if (NULL == object) {
118         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
119         return D3DERR_OUTOFVIDEOMEMORY;
120     }
121
122     object->lpVtbl = &Direct3DVertexDeclaration9_Vtbl;
123     object->ref = 1;
124     hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, pVertexElements, &object->wineD3DVertexDeclaration, (IUnknown *)object);
125
126     if (FAILED(hr)) {
127
128         /* free up object */
129         FIXME("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This);
130         HeapFree(GetProcessHeap(), 0, object);
131     } else {
132         *ppDecl = (LPDIRECT3DVERTEXDECLARATION9) object;
133          TRACE("(%p) : Created vertex declatanio %p\n", This, object);
134     }
135     return hr;
136 }
137
138 HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9 iface, IDirect3DVertexDeclaration9* pDecl) {
139     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
140     IDirect3DVertexDeclaration9Impl *pDeclImpl = (IDirect3DVertexDeclaration9Impl *)pDecl;
141     HRESULT hr = D3D_OK;
142
143     TRACE("(%p) : Relay\n", iface);
144
145     hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl == NULL ? NULL : pDeclImpl->wineD3DVertexDeclaration);
146
147     return hr;
148 }
149
150 HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexDeclaration(LPDIRECT3DDEVICE9 iface, IDirect3DVertexDeclaration9** ppDecl) {
151     IDirect3DDevice9Impl* This = (IDirect3DDevice9Impl*) iface;
152     IWineD3DVertexDeclaration* pTest = NULL;
153     HRESULT hr = D3D_OK;
154
155     TRACE("(%p) : Relay+\n", iface);
156
157     if (NULL == ppDecl) {
158       return D3DERR_INVALIDCALL;
159     }
160
161     *ppDecl = NULL;
162     hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &pTest);
163     if (hr == D3D_OK && NULL != pTest) {
164         IWineD3DResource_GetParent(pTest, (IUnknown **)ppDecl);
165         IWineD3DResource_Release(pTest);
166     } else {
167         *ppDecl = NULL;
168     }
169     TRACE("(%p) : returning %p\n", This, *ppDecl);
170     return hr;
171 }