wined3d: QueryInterface corrections.
[wine] / dlls / wined3d / vertexbuffer.c
1 /*
2  * IWineD3DVertexBuffer Implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  *                     Raphael Junqueira
6  * Copyright 2004 Christian Costa
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "wined3d_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
28
29 /* *******************************************
30    IWineD3DVertexBuffer IUnknown parts follow
31    ******************************************* */
32 HRESULT WINAPI IWineD3DVertexBufferImpl_QueryInterface(IWineD3DVertexBuffer *iface, REFIID riid, LPVOID *ppobj)
33 {
34     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
35     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
36     if (IsEqualGUID(riid, &IID_IUnknown)
37         || IsEqualGUID(riid, &IID_IWineD3DBase)
38         || IsEqualGUID(riid, &IID_IWineD3DResource)
39         || IsEqualGUID(riid, &IID_IWineD3DVertexBuffer)){
40         IUnknown_AddRef(iface);
41         *ppobj = This;
42         return S_OK;
43     }
44     *ppobj = NULL;
45     return E_NOINTERFACE;
46 }
47
48 ULONG WINAPI IWineD3DVertexBufferImpl_AddRef(IWineD3DVertexBuffer *iface) {
49     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
50     ULONG ref = InterlockedIncrement(&This->resource.ref);
51     TRACE("(%p) : AddRef increasing from %ld\n", This, ref - 1);
52     return ref;
53 }
54
55 ULONG WINAPI IWineD3DVertexBufferImpl_Release(IWineD3DVertexBuffer *iface) {
56     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
57     ULONG ref = InterlockedDecrement(&This->resource.ref);
58     TRACE("(%p) : Releasing from %ld\n", This, ref + 1);
59     if (ref == 0) {
60         IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
61         HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* ****************************************************
67    IWineD3DVertexBuffer IWineD3DResource parts follow
68    **************************************************** */
69 HRESULT WINAPI IWineD3DVertexBufferImpl_GetDevice(IWineD3DVertexBuffer *iface, IWineD3DDevice** ppDevice) {
70     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
71 }
72
73 HRESULT WINAPI IWineD3DVertexBufferImpl_SetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
74     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
75 }
76
77 HRESULT WINAPI IWineD3DVertexBufferImpl_GetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
78     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
79 }
80
81 HRESULT WINAPI IWineD3DVertexBufferImpl_FreePrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid) {
82     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
83 }
84
85 DWORD    WINAPI        IWineD3DVertexBufferImpl_SetPriority(IWineD3DVertexBuffer *iface, DWORD PriorityNew) {
86     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
87 }
88
89 DWORD    WINAPI        IWineD3DVertexBufferImpl_GetPriority(IWineD3DVertexBuffer *iface) {
90     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
91 }
92
93 void     WINAPI        IWineD3DVertexBufferImpl_PreLoad(IWineD3DVertexBuffer *iface) {
94     return IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
95 }
96
97 WINED3DRESOURCETYPE WINAPI IWineD3DVertexBufferImpl_GetType(IWineD3DVertexBuffer *iface) {
98     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
99 }
100
101 HRESULT WINAPI IWineD3DVertexBufferImpl_GetParent(IWineD3DVertexBuffer *iface, IUnknown **pParent) {
102     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
103 }
104
105 /* ******************************************************
106    IWineD3DVertexBuffer IWineD3DVertexBuffer parts follow
107    ****************************************************** */
108 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Lock(IWineD3DVertexBuffer *iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
109     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
110     TRACE("(%p) : returning memory of %p (base:%p,offset:%u)\n", This, This->resource.allocatedMemory + OffsetToLock, This->resource.allocatedMemory, OffsetToLock);
111     /* TODO: check Flags compatibility with This->currentDesc.Usage (see MSDN) */
112     *ppbData = This->resource.allocatedMemory + OffsetToLock;
113     return WINED3D_OK;
114 }
115 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Unlock(IWineD3DVertexBuffer *iface) {
116     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
117     TRACE("(%p) : stub\n", This);
118     return WINED3D_OK;
119 }
120 HRESULT  WINAPI        IWineD3DVertexBufferImpl_GetDesc(IWineD3DVertexBuffer *iface, WINED3DVERTEXBUFFER_DESC *pDesc) {
121     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
122
123     TRACE("(%p)\n", This);
124     pDesc->Format = This->resource.format;
125     pDesc->Type   = This->resource.resourceType;
126     pDesc->Usage  = This->resource.usage;
127     pDesc->Pool   = This->resource.pool;
128     pDesc->Size   = This->resource.size;
129     pDesc->FVF    = This->fvf;
130     return WINED3D_OK;
131 }
132
133 const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl =
134 {
135     /* IUnknown */
136     IWineD3DVertexBufferImpl_QueryInterface,
137     IWineD3DVertexBufferImpl_AddRef,
138     IWineD3DVertexBufferImpl_Release,
139     /* IWineD3DResource */
140     IWineD3DVertexBufferImpl_GetParent,
141     IWineD3DVertexBufferImpl_GetDevice,
142     IWineD3DVertexBufferImpl_SetPrivateData,
143     IWineD3DVertexBufferImpl_GetPrivateData,
144     IWineD3DVertexBufferImpl_FreePrivateData,
145     IWineD3DVertexBufferImpl_SetPriority,
146     IWineD3DVertexBufferImpl_GetPriority,
147     IWineD3DVertexBufferImpl_PreLoad,
148     IWineD3DVertexBufferImpl_GetType,
149     /* IWineD3DVertexBuffer */
150     IWineD3DVertexBufferImpl_Lock,
151     IWineD3DVertexBufferImpl_Unlock,
152     IWineD3DVertexBufferImpl_GetDesc
153 };
154
155 BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset) {
156     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
157
158     return This->resource.allocatedMemory + iOffset;
159 }
160
161 HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface) {
162   return WINED3D_OK;
163 }