Implemented guids for wined3d.
[wine] / dlls / wined3d / vertexbuffer.c
1 /*
2  * IWineD3DVertexBuffer Implementation
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  * Copyright 2003-2004 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_IWineD3DResource)
38         || IsEqualGUID(riid, &IID_IWineD3DVertexBuffer)){
39         IUnknown_AddRef(iface);
40         *ppobj = This;
41         return D3D_OK;
42     }
43     return E_NOINTERFACE;
44 }
45
46 ULONG WINAPI IWineD3DVertexBufferImpl_AddRef(IWineD3DVertexBuffer *iface) {
47     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
48     ULONG ref = InterlockedIncrement(&This->resource.ref);
49     TRACE("(%p) : AddRef increasing from %ld\n", This, ref - 1);
50     IUnknown_AddRef(This->resource.parent);
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         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
60         IWineD3DDevice_Release((IWineD3DDevice *)This->resource.wineD3DDevice);
61         HeapFree(GetProcessHeap(), 0, This);
62     } else {
63         IUnknown_Release(This->resource.parent);  /* Released the reference to the d3dx object */
64     }
65     return ref;
66 }
67
68 /* ****************************************************
69    IWineD3DVertexBuffer IWineD3DResource parts follow
70    **************************************************** */
71 HRESULT WINAPI IWineD3DVertexBufferImpl_GetDevice(IWineD3DVertexBuffer *iface, IWineD3DDevice** ppDevice) {
72     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
73 }
74
75 HRESULT WINAPI IWineD3DVertexBufferImpl_SetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
76     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
77 }
78
79 HRESULT WINAPI IWineD3DVertexBufferImpl_GetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
80     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
81 }
82
83 HRESULT WINAPI IWineD3DVertexBufferImpl_FreePrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid) {
84     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
85 }
86
87 DWORD    WINAPI        IWineD3DVertexBufferImpl_SetPriority(IWineD3DVertexBuffer *iface, DWORD PriorityNew) {
88     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
89 }
90
91 DWORD    WINAPI        IWineD3DVertexBufferImpl_GetPriority(IWineD3DVertexBuffer *iface) {
92     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
93 }
94
95 void     WINAPI        IWineD3DVertexBufferImpl_PreLoad(IWineD3DVertexBuffer *iface) {
96     return IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
97 }
98
99 D3DRESOURCETYPE WINAPI IWineD3DVertexBufferImpl_GetType(IWineD3DVertexBuffer *iface) {
100     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
101 }
102
103 HRESULT WINAPI IWineD3DVertexBufferImpl_GetParent(IWineD3DVertexBuffer *iface, IUnknown **pParent) {
104     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
105 }
106
107 /* ******************************************************
108    IWineD3DVertexBuffer IWineD3DVertexBuffer parts follow
109    ****************************************************** */
110 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Lock(IWineD3DVertexBuffer *iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
111     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
112     TRACE("(%p) : returning memory of %p (base:%p,offset:%u)\n", This, This->allocatedMemory + OffsetToLock, This->allocatedMemory, OffsetToLock);
113     /* TODO: check Flags compatibility with This->currentDesc.Usage (see MSDN) */
114     *ppbData = This->allocatedMemory + OffsetToLock;
115     return D3D_OK;
116 }
117 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Unlock(IWineD3DVertexBuffer *iface) {
118     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
119     TRACE("(%p) : stub\n", This);
120     return D3D_OK;
121 }
122 HRESULT  WINAPI        IWineD3DVertexBufferImpl_GetDesc(IWineD3DVertexBuffer *iface, D3DVERTEXBUFFER_DESC *pDesc) {
123     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
124
125     TRACE("(%p)\n", This);
126     pDesc->Format = This->currentDesc.Format;
127     pDesc->Type   = This->resource.resourceType;
128     pDesc->Usage  = This->currentDesc.Usage;
129     pDesc->Pool   = This->currentDesc.Pool;
130     pDesc->Size   = This->currentDesc.Size;
131     pDesc->FVF    = This->currentDesc.FVF;
132     return D3D_OK;
133 }
134
135 IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl =
136 {
137     IWineD3DVertexBufferImpl_QueryInterface,
138     IWineD3DVertexBufferImpl_AddRef,
139     IWineD3DVertexBufferImpl_Release,
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     IWineD3DVertexBufferImpl_Lock,
150     IWineD3DVertexBufferImpl_Unlock,
151     IWineD3DVertexBufferImpl_GetDesc
152 };