Unconditionally open a fresh console for the tests.
[wine] / dlls / d3d9 / vertexbuffer.c
1 /*
2  * IDirect3DResource9 implementation
3  *
4  * Copyright 2002-2003 Jason Edmeades
5  *                     Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "wingdi.h"
32 #include "wine/debug.h"
33
34 #include "d3d9_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37
38 /* IDirect3DVertexBuffer9 IUnknown parts follow: */
39 HRESULT WINAPI IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
40     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
41
42     if (IsEqualGUID(riid, &IID_IUnknown)
43         || IsEqualGUID(riid, &IID_IDirect3DResource9)
44         || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)) {
45         IDirect3DVertexBuffer9Impl_AddRef(iface);
46         *ppobj = This;
47         return D3D_OK;
48     }
49
50     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
51     return E_NOINTERFACE;
52 }
53
54 ULONG WINAPI IDirect3DVertexBuffer9Impl_AddRef(LPDIRECT3DVERTEXBUFFER9 iface) {
55     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
56     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
57     return ++(This->ref);
58 }
59
60 ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface) {
61     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
62     ULONG ref = --This->ref;
63     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
64     if (ref == 0) {
65         if (NULL != This->allocatedMemory) HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
66         HeapFree(GetProcessHeap(), 0, This);
67     }
68     return ref;
69 }
70
71 /* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
72 HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
73     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
74     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
75 }
76
77 HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
78     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
79     FIXME("(%p) : stub\n", This);
80     return D3D_OK;
81 }
82
83 HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
84     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
85     FIXME("(%p) : stub\n", This);
86     return D3D_OK;
87 }
88
89 HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
90     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
91     FIXME("(%p) : stub\n", This);
92     return D3D_OK;
93 }
94
95 DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
96     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
97     return IDirect3DResource9Impl_SetPriority((LPDIRECT3DRESOURCE9) This, PriorityNew);
98 }
99
100 DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
101     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
102     return IDirect3DResource9Impl_GetPriority((LPDIRECT3DRESOURCE9) This);
103 }
104
105 void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
106     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
107     FIXME("(%p) : stub\n", This);
108     return ;
109 }
110
111 D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface) {
112     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
113     return IDirect3DResource9Impl_GetType((LPDIRECT3DRESOURCE9) This);
114 }
115
116 /* IDirect3DVertexBuffer9 Interface follow: */
117 HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
118     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
119     FIXME("(%p) : stub\n", This);
120     return D3D_OK;
121 }
122
123 HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
124     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
125     FIXME("(%p) : stub\n", This);
126     return D3D_OK;
127 }
128
129 HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
130     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
131     TRACE("(%p) : copying into %p\n", This, pDesc);
132     memcpy(pDesc, &This->myDesc, sizeof(D3DVERTEXBUFFER_DESC));
133     return D3D_OK;
134 }
135
136
137 IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
138 {
139     IDirect3DVertexBuffer9Impl_QueryInterface,
140     IDirect3DVertexBuffer9Impl_AddRef,
141     IDirect3DVertexBuffer9Impl_Release,
142     IDirect3DVertexBuffer9Impl_GetDevice,
143     IDirect3DVertexBuffer9Impl_SetPrivateData,
144     IDirect3DVertexBuffer9Impl_GetPrivateData,
145     IDirect3DVertexBuffer9Impl_FreePrivateData,
146     IDirect3DVertexBuffer9Impl_SetPriority,
147     IDirect3DVertexBuffer9Impl_GetPriority,
148     IDirect3DVertexBuffer9Impl_PreLoad,
149     IDirect3DVertexBuffer9Impl_GetType,
150     IDirect3DVertexBuffer9Impl_Lock,
151     IDirect3DVertexBuffer9Impl_Unlock,
152     IDirect3DVertexBuffer9Impl_GetDesc
153 };
154
155
156 /* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
157 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9 iface, 
158                                                        UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, 
159                                                        IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
160     IDirect3DVertexBuffer9Impl *object;
161
162     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
163
164     /* Allocate the storage for the device */
165     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
166     object->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
167     object->ref = 1;
168     object->Device = This;
169
170     object->ResourceType = D3DRTYPE_VERTEXBUFFER;
171
172     object->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
173     object->myDesc.Usage = Usage;
174     object->myDesc.Pool  = Pool;
175     object->myDesc.FVF   = FVF;
176     object->myDesc.Size  = Size;
177
178     TRACE("(%p) : Size=%d, Usage=%ld, FVF=%lx, Pool=%d - Memory@%p, Iface@%p\n", This, Size, Usage, FVF, Pool, object->allocatedMemory, object);
179
180     *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
181
182     return D3D_OK;
183 }