- Implement SetStreamSource
[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
28 /* *******************************************
29    IWineD3DVertexBuffer IUnknown parts follow
30    ******************************************* */
31 HRESULT WINAPI IWineD3DVertexBufferImpl_QueryInterface(IWineD3DVertexBuffer *iface, REFIID riid, LPVOID *ppobj)
32 {
33     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
34     WARN("(%p)->(%s,%p) should not be called\n",This,debugstr_guid(riid),ppobj);
35     return E_NOINTERFACE;
36 }
37
38 ULONG WINAPI IWineD3DVertexBufferImpl_AddRef(IWineD3DVertexBuffer *iface) {
39     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
40     TRACE("(%p) : AddRef increasing from %ld\n", This, This->resource.ref);
41     IUnknown_AddRef(This->resource.parent);
42     return InterlockedIncrement(&This->resource.ref);
43 }
44
45 ULONG WINAPI IWineD3DVertexBufferImpl_Release(IWineD3DVertexBuffer *iface) {
46     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
47     ULONG ref;
48     TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
49     ref = InterlockedDecrement(&This->resource.ref);
50     if (ref == 0) {
51         if (NULL != This->allocatedMemory) HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
52         IWineD3DDevice_Release(This->resource.wineD3DDevice);
53         HeapFree(GetProcessHeap(), 0, This);
54     } else {
55         IUnknown_Release(This->resource.parent);  /* Released the reference to the d3dx VB */
56     }
57     return ref;
58 }
59
60 /* ****************************************************
61    IWineD3DVertexBuffer IWineD3DResource parts follow
62    **************************************************** */
63 HRESULT WINAPI IWineD3DVertexBufferImpl_GetDevice(IWineD3DVertexBuffer *iface, IWineD3DDevice** ppDevice) {
64     return IWineD3DResource_GetDevice((IWineD3DResource *)iface, ppDevice);
65 }
66
67 HRESULT WINAPI IWineD3DVertexBufferImpl_SetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
68     return IWineD3DResource_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
69 }
70
71 HRESULT WINAPI IWineD3DVertexBufferImpl_GetPrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
72     return IWineD3DResource_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
73 }
74
75 HRESULT WINAPI IWineD3DVertexBufferImpl_FreePrivateData(IWineD3DVertexBuffer *iface, REFGUID refguid) {
76     return IWineD3DResource_FreePrivateData((IWineD3DResource *)iface, refguid);
77 }
78
79 DWORD    WINAPI        IWineD3DVertexBufferImpl_SetPriority(IWineD3DVertexBuffer *iface, DWORD PriorityNew) {
80     return IWineD3DResource_SetPriority((IWineD3DResource *)iface, PriorityNew);
81 }
82
83 DWORD    WINAPI        IWineD3DVertexBufferImpl_GetPriority(IWineD3DVertexBuffer *iface) {
84     return IWineD3DResource_GetPriority((IWineD3DResource *)iface);
85 }
86
87 void     WINAPI        IWineD3DVertexBufferImpl_PreLoad(IWineD3DVertexBuffer *iface) {
88     return IWineD3DResource_PreLoad((IWineD3DResource *)iface);
89 }
90
91 D3DRESOURCETYPE WINAPI IWineD3DVertexBufferImpl_GetType(IWineD3DVertexBuffer *iface) {
92     return IWineD3DResource_GetType((IWineD3DResource *)iface);
93 }
94
95 HRESULT WINAPI IWineD3DVertexBufferImpl_GetParent(IWineD3DVertexBuffer *iface, IUnknown **pParent) {
96     return IWineD3DResource_GetParent((IWineD3DResource *)iface, pParent);
97 }
98
99 /* ******************************************************
100    IWineD3DVertexBuffer IWineD3DVertexBuffer parts follow
101    ****************************************************** */
102 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Lock(IWineD3DVertexBuffer *iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
103     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
104     TRACE("(%p) : returning memory of %p (base:%p,offset:%u)\n", This, This->allocatedMemory + OffsetToLock, This->allocatedMemory, OffsetToLock);
105     /* TODO: check Flags compatibility with This->currentDesc.Usage (see MSDN) */
106     *ppbData = This->allocatedMemory + OffsetToLock;
107     return D3D_OK;
108 }
109 HRESULT  WINAPI        IWineD3DVertexBufferImpl_Unlock(IWineD3DVertexBuffer *iface) {
110     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
111     TRACE("(%p) : stub\n", This);
112     return D3D_OK;
113 }
114 HRESULT  WINAPI        IWineD3DVertexBufferImpl_GetDesc(IWineD3DVertexBuffer *iface, D3DVERTEXBUFFER_DESC *pDesc) {
115     IWineD3DVertexBufferImpl *This = (IWineD3DVertexBufferImpl *)iface;
116
117     TRACE("(%p)\n", This);
118     pDesc->Format = This->currentDesc.Format;
119     pDesc->Type   = This->currentDesc.Type;
120     pDesc->Usage  = This->currentDesc.Usage;
121     pDesc->Pool   = This->currentDesc.Pool;
122     pDesc->Size   = This->currentDesc.Size;
123     pDesc->FVF    = This->currentDesc.FVF;
124     return D3D_OK;
125 }
126
127 IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl =
128 {
129     IWineD3DVertexBufferImpl_QueryInterface,
130     IWineD3DVertexBufferImpl_AddRef,
131     IWineD3DVertexBufferImpl_Release,
132     IWineD3DVertexBufferImpl_GetParent,
133     IWineD3DVertexBufferImpl_GetDevice,
134     IWineD3DVertexBufferImpl_SetPrivateData,
135     IWineD3DVertexBufferImpl_GetPrivateData,
136     IWineD3DVertexBufferImpl_FreePrivateData,
137     IWineD3DVertexBufferImpl_SetPriority,
138     IWineD3DVertexBufferImpl_GetPriority,
139     IWineD3DVertexBufferImpl_PreLoad,
140     IWineD3DVertexBufferImpl_GetType,
141     IWineD3DVertexBufferImpl_Lock,
142     IWineD3DVertexBufferImpl_Unlock,
143     IWineD3DVertexBufferImpl_GetDesc
144 };