Update copyright info for the new year.
[wine] / dlls / d3d8 / indexbuffer.c
1 /*
2  * IDirect3DIndexBuffer8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "wine/debug.h"
30
31 #include "d3d8_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34
35 /* IDirect3DIndexBuffer8 IUnknown parts follow: */
36 HRESULT WINAPI IDirect3DIndexBuffer8Impl_QueryInterface(LPDIRECT3DINDEXBUFFER8 iface,REFIID riid,LPVOID *ppobj)
37 {
38     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
39
40     if (IsEqualGUID(riid, &IID_IUnknown)
41         || IsEqualGUID(riid, &IID_IDirect3DResource8)
42         || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)) {
43         IDirect3DIndexBuffer8Impl_AddRef(iface);
44         *ppobj = This;
45         return D3D_OK;
46     }
47
48     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
49     return E_NOINTERFACE;
50 }
51
52 ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRef(LPDIRECT3DINDEXBUFFER8 iface) {
53     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
54     ULONG ref = InterlockedIncrement(&This->ref);
55
56     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
57
58     return ref;
59 }
60
61 ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 iface) {
62     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
63     ULONG ref = InterlockedDecrement(&This->ref);
64
65     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
66
67     if (ref == 0 && 0 == This->refInt) {
68         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
69         HeapFree(GetProcessHeap(), 0, This);
70     } else if (0 == ref) {
71       WARN("(%p) : The application failed to set indicies NULL before releasing the index buffer, leak\n", This);
72     }
73
74     return ref;
75 }
76
77
78 ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRefInt(LPDIRECT3DINDEXBUFFER8 iface) {
79     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
80     ULONG refInt = InterlockedIncrement(&This->refInt);
81
82     TRACE("(%p) : AddRefInt from %ld\n", This, refInt - 1);
83
84     return refInt;
85 }
86
87 ULONG WINAPI IDirect3DIndexBuffer8Impl_ReleaseInt(LPDIRECT3DINDEXBUFFER8 iface) {
88     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
89     ULONG refInt = InterlockedDecrement(&This->refInt);
90
91     TRACE("(%p) : ReleaseRefInt to %ld\n", This, refInt);
92
93     if (0 == This->ref && 0 == refInt) {
94         WARN("(%p) : Cleaning up after the calling application failed to release the indicies properly\n", This);
95         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
96         HeapFree(GetProcessHeap(), 0, This);
97     }
98
99     return refInt;
100 }
101
102
103 /* IDirect3DResource Interface follow: */
104 HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8** ppDevice) {
105     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
106     TRACE("(%p) : returning %p\n", This, This->Device);
107     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
108     IDirect3DDevice8Impl_AddRef(*ppDevice);
109     return D3D_OK;
110 }
111 HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
112     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
113     FIXME("(%p) : stub\n", This);    return D3D_OK;
114 }
115 HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
116     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
117     FIXME("(%p) : stub\n", This);    return D3D_OK;
118 }
119 HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid) {
120     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
121     FIXME("(%p) : stub\n", This);    return D3D_OK;
122 }
123 DWORD    WINAPI        IDirect3DIndexBuffer8Impl_SetPriority(LPDIRECT3DINDEXBUFFER8 iface, DWORD PriorityNew) {
124     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
125     FIXME("(%p) : stub\n", This);    return D3D_OK;
126 }
127 DWORD    WINAPI        IDirect3DIndexBuffer8Impl_GetPriority(LPDIRECT3DINDEXBUFFER8 iface) {
128     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
129     FIXME("(%p) : stub\n", This);    return D3D_OK;
130 }
131 void     WINAPI        IDirect3DIndexBuffer8Impl_PreLoad(LPDIRECT3DINDEXBUFFER8 iface) {
132     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
133     FIXME("(%p) : stub\n", This);
134 }
135 D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer8Impl_GetType(LPDIRECT3DINDEXBUFFER8 iface) {
136     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
137     TRACE("(%p) : returning %d\n", This, This->ResourceType);
138     return This->ResourceType;
139 }
140
141 /* IDirect3DIndexBuffer8 */
142 HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_Lock(LPDIRECT3DINDEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
143     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
144     TRACE("(%p) : no locking yet, offset %d, size %d, Flags=%lx\n", This, OffsetToLock, SizeToLock, Flags);
145     *ppbData = (BYTE *)This->allocatedMemory + OffsetToLock;
146     return D3D_OK;
147 }
148
149 HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_Unlock(LPDIRECT3DINDEXBUFFER8 iface) {
150     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
151     TRACE("(%p) : stub\n", This);
152     return D3D_OK;
153 }
154 HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_GetDesc(LPDIRECT3DINDEXBUFFER8 iface, D3DINDEXBUFFER_DESC *pDesc) {
155     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
156
157     TRACE("(%p) : copying into %p\n", This, pDesc);
158     memcpy(pDesc, &This->currentDesc, sizeof(D3DINDEXBUFFER_DESC));
159     return D3D_OK;
160 }
161
162 const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
163 {
164     IDirect3DIndexBuffer8Impl_QueryInterface,
165     IDirect3DIndexBuffer8Impl_AddRef,
166     IDirect3DIndexBuffer8Impl_Release,
167     IDirect3DIndexBuffer8Impl_GetDevice,
168     IDirect3DIndexBuffer8Impl_SetPrivateData,
169     IDirect3DIndexBuffer8Impl_GetPrivateData,
170     IDirect3DIndexBuffer8Impl_FreePrivateData,
171     IDirect3DIndexBuffer8Impl_SetPriority,
172     IDirect3DIndexBuffer8Impl_GetPriority,
173     IDirect3DIndexBuffer8Impl_PreLoad,
174     IDirect3DIndexBuffer8Impl_GetType,
175     IDirect3DIndexBuffer8Impl_Lock,
176     IDirect3DIndexBuffer8Impl_Unlock,
177     IDirect3DIndexBuffer8Impl_GetDesc
178 };