wined3d: Add WINED3DBOX to wined3d_types.h.
[wine] / dlls / d3d9 / indexbuffer.c
1 /*
2  * IDirect3DIndexBuffer9 implementation
3  *
4  * Copyright 2002-2004 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., 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 /* IDirect3DIndexBuffer9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DResource9)
33         || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
34         IUnknown_AddRef(iface);
35         *ppobj = This;
36         return D3D_OK;
37     }
38
39     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
40     return E_NOINTERFACE;
41 }
42
43 ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
44     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
48
49     return ref;
50 }
51
52 ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
53     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
57
58     if (ref == 0) {
59         IWineD3DIndexBuffer_Release(This->wineD3DIndexBuffer);
60         HeapFree(GetProcessHeap(), 0, This);
61     }
62     return ref;
63 }
64
65 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
66 HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
67     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
68     TRACE("(%p) Relay\n", This);
69     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
70 }
71
72 HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
73     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
74     TRACE("(%p) Relay\n", This);
75     return IWineD3DIndexBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
76 }
77
78 HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
79     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
80     TRACE("(%p) Relay\n", This);
81     return IWineD3DIndexBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
82 }
83
84 HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
85     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
86     TRACE("(%p) Relay\n", This);
87     return IWineD3DIndexBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
88 }
89
90 DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
91     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
92     TRACE("(%p) Relay\n", This);
93     return IWineD3DIndexBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
94 }
95
96 DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
97     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
98     TRACE("(%p) Relay\n", This);
99     return IWineD3DIndexBuffer_GetPriority(This->wineD3DIndexBuffer);
100 }
101
102 void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
103     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
104     TRACE("(%p) Relay\n", This);
105     return IWineD3DIndexBuffer_PreLoad(This->wineD3DIndexBuffer);
106 }
107
108 D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
109     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
110     TRACE("(%p) Relay\n", This);
111     return IWineD3DIndexBuffer_GetType(This->wineD3DIndexBuffer);
112 }
113
114 /* IDirect3DIndexBuffer9 Interface follow: */
115 HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
116     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
117     TRACE("(%p) Relay\n", This);
118     return IWineD3DIndexBuffer_Lock(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
119 }
120
121 HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
122     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
123     TRACE("(%p) Relay\n", This);
124     return IWineD3DIndexBuffer_Unlock(This->wineD3DIndexBuffer);
125 }
126
127 HRESULT  WINAPI        IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
128     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
129     TRACE("(%p) Relay\n", This);
130     return IWineD3DIndexBuffer_GetDesc(This->wineD3DIndexBuffer, (WINED3DINDEXBUFFER_DESC *) pDesc);
131 }
132
133
134 const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
135 {
136     /* IUnknown */
137     IDirect3DIndexBuffer9Impl_QueryInterface,
138     IDirect3DIndexBuffer9Impl_AddRef,
139     IDirect3DIndexBuffer9Impl_Release,
140     /* IDirect3DResource9 */
141     IDirect3DIndexBuffer9Impl_GetDevice,
142     IDirect3DIndexBuffer9Impl_SetPrivateData,
143     IDirect3DIndexBuffer9Impl_GetPrivateData,
144     IDirect3DIndexBuffer9Impl_FreePrivateData,
145     IDirect3DIndexBuffer9Impl_SetPriority,
146     IDirect3DIndexBuffer9Impl_GetPriority,
147     IDirect3DIndexBuffer9Impl_PreLoad,
148     IDirect3DIndexBuffer9Impl_GetType,
149     /* IDirect3DIndexBuffer9 */
150     IDirect3DIndexBuffer9Impl_Lock,
151     IDirect3DIndexBuffer9Impl_Unlock,
152     IDirect3DIndexBuffer9Impl_GetDesc
153 };
154
155
156 /* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
157 HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9 iface, 
158                               UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
159                               IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) {
160     
161     IDirect3DIndexBuffer9Impl *object;
162     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
163     HRESULT hrc = D3D_OK;
164     
165     TRACE("(%p) Relay\n", This);
166     /* Allocate the storage for the device */
167     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
168     if (NULL == object) {
169         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
170         return D3DERR_OUTOFVIDEOMEMORY;
171     }
172
173     object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
174     object->ref = 1;
175     TRACE("Calling wined3d create index buffer\n");
176     hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage, Format, (WINED3DPOOL) Pool, &object->wineD3DIndexBuffer, pSharedHandle, (IUnknown *)object);
177     if (hrc != D3D_OK) {
178
179         /* free up object */
180         FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
181         HeapFree(GetProcessHeap(), 0, object);
182     } else {
183         *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
184         TRACE("(%p) : Created index buffer %p\n", This, object);
185     }
186     return hrc;
187 }