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