Copy the parser and cross compiler from d3d8 and update everything to
[wine] / dlls / d3d8 / vertexbuffer.c
1 /*
2  * IDirect3DResource8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "wine/debug.h"
30
31 #include "d3d8_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34
35 /* IDirect3DResource IUnknown parts follow: */
36 HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj)
37 {
38     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
39
40     if (IsEqualGUID(riid, &IID_IUnknown)
41         || IsEqualGUID(riid, &IID_IDirect3DResource8)
42         || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
43         IDirect3DVertexBuffer8Impl_AddRef(iface);
44         *ppobj = This;
45         return D3D_OK;
46     }
47
48     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
49     return E_NOINTERFACE;
50 }
51
52 ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
53     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
54     ULONG ref = InterlockedIncrement(&This->ref);
55
56     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
57
58     return ref;
59 }
60
61 ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
62     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
63     ULONG ref = InterlockedDecrement(&This->ref);
64
65     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
66
67     if (ref == 0) {
68         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
69         HeapFree(GetProcessHeap(), 0, This);
70     }
71     return ref;
72 }
73
74 /* IDirect3DResource Interface follow: */
75 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8** ppDevice) {
76     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
77     TRACE("(%p) : returning %p\n", This, This->Device);
78     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
79     IDirect3DDevice8Impl_AddRef(*ppDevice);
80     return D3D_OK;
81 }
82 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
83     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
84     FIXME("(%p) : stub\n", This);    return D3D_OK;
85 }
86 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
87     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
88     FIXME("(%p) : stub\n", This);    return D3D_OK;
89 }
90 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
91     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
92     FIXME("(%p) : stub\n", This);    return D3D_OK;
93 }
94 DWORD    WINAPI        IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
95     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
96     FIXME("(%p) : stub\n", This);    return D3D_OK;
97 }
98 DWORD    WINAPI        IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
99     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
100     FIXME("(%p) : stub\n", This);    return D3D_OK;
101 }
102 void     WINAPI        IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
103     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
104     FIXME("(%p) : stub\n", This);
105 }
106 D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
107     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
108     TRACE("(%p) : returning %d\n", This, This->ResourceType);
109     return This->ResourceType;
110 }
111
112 /* IDirect3DVertexBuffer8 */
113 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
114     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
115     TRACE("(%p) : returning memory of %p (base:%p,offset:%u)\n", This, This->allocatedMemory + OffsetToLock, This->allocatedMemory, OffsetToLock);
116     /* TODO: check Flags compatibility with This->currentDesc.Usage (see MSDN) */
117     *ppbData = This->allocatedMemory + OffsetToLock;
118     return D3D_OK;
119 }
120 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
121     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
122     TRACE("(%p) : stub\n", This);
123     return D3D_OK;
124 }
125 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
126     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
127
128     TRACE("(%p)\n", This);
129     pDesc->Format = This->currentDesc.Format;
130     pDesc->Type   = This->currentDesc.Type;
131     pDesc->Usage  = This->currentDesc.Usage;
132     pDesc->Pool   = This->currentDesc.Pool;
133     pDesc->Size   = This->currentDesc.Size;
134     pDesc->FVF    = This->currentDesc.FVF;
135     return D3D_OK;
136 }
137
138 const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
139 {
140     IDirect3DVertexBuffer8Impl_QueryInterface,
141     IDirect3DVertexBuffer8Impl_AddRef,
142     IDirect3DVertexBuffer8Impl_Release,
143     IDirect3DVertexBuffer8Impl_GetDevice,
144     IDirect3DVertexBuffer8Impl_SetPrivateData,
145     IDirect3DVertexBuffer8Impl_GetPrivateData,
146     IDirect3DVertexBuffer8Impl_FreePrivateData,
147     IDirect3DVertexBuffer8Impl_SetPriority,
148     IDirect3DVertexBuffer8Impl_GetPriority,
149     IDirect3DVertexBuffer8Impl_PreLoad,
150     IDirect3DVertexBuffer8Impl_GetType,
151     IDirect3DVertexBuffer8Impl_Lock,
152     IDirect3DVertexBuffer8Impl_Unlock,
153     IDirect3DVertexBuffer8Impl_GetDesc
154 };