wined3d: Add d3d7 and d3d8/9 cap flags to wined3d_types.h.
[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 D3D_OK;
43     }
44     return E_NOINTERFACE;
45 }
46
47 ULONG WINAPI IWineD3DVertexBufferImpl_AddRef(IWineD3DVertexBuffer *iface) {
48     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
49     ULONG ref = InterlockedIncrement(&This->resource.ref);
50     TRACE("(%p) : AddRef increasing from %ld\n", This, ref - 1);
51     return ref;
52 }
53
54 ULONG WINAPI IWineD3DVertexBufferImpl_Release(IWineD3DVertexBuffer *iface) {
55     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
56     ULONG ref = InterlockedDecrement(&This->resource.ref);
57     TRACE("(%p) : Releasing from %ld\n", This, ref + 1);
58     if (ref == 0) {
59         IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
60         HeapFree(GetProcessHeap(), 0, This);
61     }
62     return ref;
63 }
64
65 /* ****************************************************
66    IWineD3DVertexBuffer IWineD3DResource parts follow
67    **************************************************** */
68 HRESULT WINAPI IWineD3DVertexBufferImpl_GetDevice(IWineD3DVertexBuffer *iface, IWineD3DDevice** ppDevice) {
69     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
70 }
71
72 HRESULT WINAPI IWineD3DVertexBufferImpl_SetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
73     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
74 }
75
76 HRESULT WINAPI IWineD3DVertexBufferImpl_GetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
77     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
78 }
79
80 HRESULT WINAPI IWineD3DVertexBufferImpl_FreePrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid) {
81     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
82 }
83
84 DWORD    WINAPI        IWineD3DVertexBufferImpl_SetPriority(IWineD3DVertexBuffer *iface, DWORD PriorityNew) {
85     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
86 }
87
88 DWORD    WINAPI        IWineD3DVertexBufferImpl_GetPriority(IWineD3DVertexBuffer *iface) {
89     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
90 }
91
92 void     WINAPI        IWineD3DVertexBufferImpl_PreLoad(IWineD3DVertexBuffer *iface) {
93     return IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
94 }
95
96 D3DRESOURCETYPE WINAPI IWineD3DVertexBufferImpl_GetType(IWineD3DVertexBuffer *iface) {
97     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
98 }
99
100 HRESULT WINAPI IWineD3DVertexBufferImpl_GetParent(IWineD3DVertexBuffer *iface, IUnknown **pParent) {
101     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
102 }
103
104 /* ******************************************************
105    IWineD3DVertexBuffer IWineD3DVertexBuffer parts follow
106    ****************************************************** */
107 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Lock(IWineD3DVertexBuffer *iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
108     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
109     TRACE("(%p) : returning memory of %p (base:%p,offset:%u)\n", This, This->resource.allocatedMemory + OffsetToLock, This->resource.allocatedMemory, OffsetToLock);
110     /* TODO: check Flags compatibility with This->currentDesc.Usage (see MSDN) */
111     *ppbData = This->resource.allocatedMemory + OffsetToLock;
112     return D3D_OK;
113 }
114 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Unlock(IWineD3DVertexBuffer *iface) {
115     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
116     TRACE("(%p) : stub\n", This);
117     return D3D_OK;
118 }
119 HRESULT  WINAPI        IWineD3DVertexBufferImpl_GetDesc(IWineD3DVertexBuffer *iface, D3DVERTEXBUFFER_DESC *pDesc) {
120     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
121
122     TRACE("(%p)\n", This);
123     pDesc->Format = This->resource.format;
124     pDesc->Type   = This->resource.resourceType;
125     pDesc->Usage  = This->resource.usage;
126     pDesc->Pool   = This->resource.pool;
127     pDesc->Size   = This->resource.size;
128     pDesc->FVF    = This->fvf;
129     return D3D_OK;
130 }
131
132 const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl =
133 {
134     /* IUnknown */
135     IWineD3DVertexBufferImpl_QueryInterface,
136     IWineD3DVertexBufferImpl_AddRef,
137     IWineD3DVertexBufferImpl_Release,
138     /* IWineD3DResource */
139     IWineD3DVertexBufferImpl_GetParent,
140     IWineD3DVertexBufferImpl_GetDevice,
141     IWineD3DVertexBufferImpl_SetPrivateData,
142     IWineD3DVertexBufferImpl_GetPrivateData,
143     IWineD3DVertexBufferImpl_FreePrivateData,
144     IWineD3DVertexBufferImpl_SetPriority,
145     IWineD3DVertexBufferImpl_GetPriority,
146     IWineD3DVertexBufferImpl_PreLoad,
147     IWineD3DVertexBufferImpl_GetType,
148     /* IWineD3DVertexBuffer */
149     IWineD3DVertexBufferImpl_Lock,
150     IWineD3DVertexBufferImpl_Unlock,
151     IWineD3DVertexBufferImpl_GetDesc
152 };
153
154 BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset) {
155     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
156
157     return This->resource.allocatedMemory + iOffset;
158 }
159
160 HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface) {
161   return D3D_OK;
162 }