- removed some useless WARNs
[wine] / dlls / ddraw / d3dvertexbuffer.c
1 /* Direct3D Viewport
2  * Copyright (c) 2002 Lionel ULMER
3  *
4  * This file contains the implementation of Direct3DVertexBuffer COM object
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 #include "windef.h"
23 #include "winerror.h"
24 #include "objbase.h"
25 #include "ddraw.h"
26 #include "d3d.h"
27 #include "wine/debug.h"
28
29 #include "d3d_private.h"
30 #include "mesa_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
33
34 HRESULT WINAPI
35 Main_IDirect3DVertexBufferImpl_7_1T_QueryInterface(LPDIRECT3DVERTEXBUFFER7 iface,
36                                                    REFIID riid,
37                                                    LPVOID* obp)
38 {
39     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
40     TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
41
42     /* By default, set the object pointer to NULL */
43     *obp = NULL;
44       
45     if ( IsEqualGUID( &IID_IUnknown,  riid ) ) {
46         IDirect3DVertexBuffer7_AddRef(ICOM_INTERFACE(This,IDirect3DVertexBuffer7));
47         *obp = iface;
48         TRACE("  Creating IUnknown interface at %p.\n", *obp);
49         return S_OK;
50     }
51     if ( IsEqualGUID( &IID_IDirect3DVertexBuffer, riid ) ) {
52         IDirect3DVertexBuffer7_AddRef(ICOM_INTERFACE(This,IDirect3DVertexBuffer7));
53         *obp = ICOM_INTERFACE(This, IDirect3DVertexBuffer);
54         TRACE("  Creating IDirect3DVertexBuffer interface %p\n", *obp);
55         return S_OK;
56     }
57     if ( IsEqualGUID( &IID_IDirect3DVertexBuffer7, riid ) ) {
58         IDirect3DVertexBuffer7_AddRef(ICOM_INTERFACE(This,IDirect3DVertexBuffer7));
59         *obp = ICOM_INTERFACE(This, IDirect3DVertexBuffer7);
60         TRACE("  Creating IDirect3DVertexBuffer7 interface %p\n", *obp);
61         return S_OK;
62     }
63     FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
64     return OLE_E_ENUM_NOMORE;
65 }
66
67 ULONG WINAPI
68 Main_IDirect3DVertexBufferImpl_7_1T_AddRef(LPDIRECT3DVERTEXBUFFER7 iface)
69 {
70     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
71     TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
72     return ++(This->ref);
73 }
74
75 ULONG WINAPI
76 Main_IDirect3DVertexBufferImpl_7_1T_Release(LPDIRECT3DVERTEXBUFFER7 iface)
77 {
78     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
79     TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
80     if (--(This->ref) == 0) {
81         HeapFree(GetProcessHeap(), 0, This->vertices);
82         HeapFree(GetProcessHeap(), 0, This);
83         return 0;
84     }
85     return This->ref;
86 }
87
88 HRESULT WINAPI
89 Main_IDirect3DVertexBufferImpl_7_1T_Lock(LPDIRECT3DVERTEXBUFFER7 iface,
90                                          DWORD dwFlags,
91                                          LPVOID* lplpData,
92                                          LPDWORD lpdwSize)
93 {
94     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
95     TRACE("(%p/%p)->(%08lx,%p,%p)\n", This, iface, dwFlags, lplpData, lpdwSize);
96
97     if (TRACE_ON(ddraw)) {
98         TRACE(" lock flags : ");
99         DDRAW_dump_lockflag(dwFlags);
100     }
101     
102     if (lpdwSize != NULL) *lpdwSize = This->vertex_buffer_size;
103     *lplpData = This->vertices;
104     
105     return DD_OK;
106 }
107
108 HRESULT WINAPI
109 Main_IDirect3DVertexBufferImpl_7_1T_Unlock(LPDIRECT3DVERTEXBUFFER7 iface)
110 {
111     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
112     TRACE("(%p/%p)->()\n", This, iface);
113     /* Nothing to do here for now. Maybe some optimizations if ever we want to do some :-) */
114     return DD_OK;
115 }
116
117 HRESULT WINAPI
118 Main_IDirect3DVertexBufferImpl_7_ProcessVertices(LPDIRECT3DVERTEXBUFFER7 iface,
119                                                  DWORD dwVertexOp,
120                                                  DWORD dwDestIndex,
121                                                  DWORD dwCount,
122                                                  LPDIRECT3DVERTEXBUFFER7 lpSrcBuffer,
123                                                  DWORD dwSrcIndex,
124                                                  LPDIRECT3DDEVICE7 lpD3DDevice,
125                                                  DWORD dwFlags)
126 {
127     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
128     FIXME("(%p/%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx): stub!\n", This, iface, dwVertexOp, dwDestIndex, dwCount, lpSrcBuffer, dwSrcIndex, lpD3DDevice, dwFlags);    
129     return DD_OK;
130 }
131
132 HRESULT WINAPI
133 Main_IDirect3DVertexBufferImpl_7_1T_GetVertexBufferDesc(LPDIRECT3DVERTEXBUFFER7 iface,
134                                                         LPD3DVERTEXBUFFERDESC lpD3DVertexBufferDesc)
135 {
136     DWORD size;
137     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
138     TRACE("(%p/%p)->(%p)\n", This, iface, lpD3DVertexBufferDesc);
139     size = (lpD3DVertexBufferDesc->dwSize < This->desc.dwSize) ? lpD3DVertexBufferDesc->dwSize : This->desc.dwSize;
140     memcpy(lpD3DVertexBufferDesc,&This->desc,size);
141     return DD_OK;
142 }
143
144 HRESULT WINAPI
145 Main_IDirect3DVertexBufferImpl_7_Optimize(LPDIRECT3DVERTEXBUFFER7 iface,
146                                           LPDIRECT3DDEVICE7 lpD3DDevice,
147                                           DWORD dwFlags)
148 {
149     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
150     FIXME("(%p/%p)->(%p,%08lx): stub!\n", This, iface, lpD3DDevice, dwFlags);
151     return DD_OK;
152 }
153
154 HRESULT WINAPI
155 Main_IDirect3DVertexBufferImpl_7_ProcessVerticesStrided(LPDIRECT3DVERTEXBUFFER7 iface,
156                                                         DWORD dwVertexOp,
157                                                         DWORD dwDestIndex,
158                                                         DWORD dwCount,
159                                                         LPD3DDRAWPRIMITIVESTRIDEDDATA lpStrideData,
160                                                         DWORD dwVertexTypeDesc,
161                                                         LPDIRECT3DDEVICE7 lpD3DDevice,
162                                                         DWORD dwFlags)
163 {
164     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
165     FIXME("(%p/%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx): stub!\n", This, iface, dwVertexOp, dwDestIndex, dwCount, lpStrideData, dwVertexTypeDesc, lpD3DDevice, dwFlags);
166     return DD_OK;
167 }
168
169 HRESULT WINAPI
170 Main_IDirect3DVertexBufferImpl_1_ProcessVertices(LPDIRECT3DVERTEXBUFFER iface,
171                                                  DWORD dwVertexOp,
172                                                  DWORD dwDestIndex,
173                                                  DWORD dwCount,
174                                                  LPDIRECT3DVERTEXBUFFER lpSrcBuffer,
175                                                  DWORD dwSrcIndex,
176                                                  LPDIRECT3DDEVICE3 lpD3DDevice,
177                                                  DWORD dwFlags)
178 {
179     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, iface);
180     FIXME("(%p/%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx): stub!\n", This, iface, dwVertexOp, dwDestIndex, dwCount, lpSrcBuffer, dwSrcIndex, lpD3DDevice, dwFlags);
181     return DD_OK;
182 }
183
184 HRESULT WINAPI
185 Main_IDirect3DVertexBufferImpl_1_Optimize(LPDIRECT3DVERTEXBUFFER iface,
186                                           LPDIRECT3DDEVICE3 lpD3DDevice,
187                                           DWORD dwFlags)
188 {
189     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, iface);
190     FIXME("(%p/%p)->(%p,%08lx): stub!\n", This, iface, lpD3DDevice, dwFlags);
191     return DD_OK;
192 }
193
194 HRESULT WINAPI
195 Thunk_IDirect3DVertexBufferImpl_1_QueryInterface(LPDIRECT3DVERTEXBUFFER iface,
196                                                  REFIID riid,
197                                                  LPVOID* obp)
198 {
199     TRACE("(%p)->(%s,%p) thunking to IDirect3DVertexBuffer7 interface.\n", iface, debugstr_guid(riid), obp);
200     return IDirect3DVertexBuffer7_QueryInterface(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
201                                                  riid,
202                                                  obp);
203 }
204
205 ULONG WINAPI
206 Thunk_IDirect3DVertexBufferImpl_1_AddRef(LPDIRECT3DVERTEXBUFFER iface)
207 {
208     TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
209     return IDirect3DVertexBuffer7_AddRef(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
210 }
211
212 ULONG WINAPI
213 Thunk_IDirect3DVertexBufferImpl_1_Release(LPDIRECT3DVERTEXBUFFER iface)
214 {
215     TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
216     return IDirect3DVertexBuffer7_Release(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
217 }
218
219 HRESULT WINAPI
220 Thunk_IDirect3DVertexBufferImpl_1_Lock(LPDIRECT3DVERTEXBUFFER iface,
221                                        DWORD dwFlags,
222                                        LPVOID* lplpData,
223                                        LPDWORD lpdwSize)
224 {
225     TRACE("(%p)->(%08lx,%p,%p) thunking to IDirect3DVertexBuffer7 interface.\n", iface, dwFlags, lplpData, lpdwSize);
226     return IDirect3DVertexBuffer7_Lock(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
227                                        dwFlags,
228                                        lplpData,
229                                        lpdwSize);
230 }
231
232 HRESULT WINAPI
233 Thunk_IDirect3DVertexBufferImpl_1_Unlock(LPDIRECT3DVERTEXBUFFER iface)
234 {
235     TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
236     return IDirect3DVertexBuffer7_Unlock(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
237 }
238
239 HRESULT WINAPI
240 Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc(LPDIRECT3DVERTEXBUFFER iface,
241                                                       LPD3DVERTEXBUFFERDESC lpD3DVertexBufferDesc)
242 {
243     TRACE("(%p)->(%p) thunking to IDirect3DVertexBuffer7 interface.\n", iface, lpD3DVertexBufferDesc);
244     return IDirect3DVertexBuffer7_GetVertexBufferDesc(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
245                                                       lpD3DVertexBufferDesc);
246 }
247
248 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
249 # define XCAST(fun)     (typeof(VTABLE_IDirect3DVertexBuffer7.fun))
250 #else
251 # define XCAST(fun)     (void*)
252 #endif
253
254 ICOM_VTABLE(IDirect3DVertexBuffer7) VTABLE_IDirect3DVertexBuffer7 =
255 {
256     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
257     XCAST(QueryInterface) Main_IDirect3DVertexBufferImpl_7_1T_QueryInterface,
258     XCAST(AddRef) Main_IDirect3DVertexBufferImpl_7_1T_AddRef,
259     XCAST(Release) Main_IDirect3DVertexBufferImpl_7_1T_Release,
260     XCAST(Lock) Main_IDirect3DVertexBufferImpl_7_1T_Lock,
261     XCAST(Unlock) Main_IDirect3DVertexBufferImpl_7_1T_Unlock,
262     XCAST(ProcessVertices) Main_IDirect3DVertexBufferImpl_7_ProcessVertices,
263     XCAST(GetVertexBufferDesc) Main_IDirect3DVertexBufferImpl_7_1T_GetVertexBufferDesc,
264     XCAST(Optimize) Main_IDirect3DVertexBufferImpl_7_Optimize,
265     XCAST(ProcessVerticesStrided) Main_IDirect3DVertexBufferImpl_7_ProcessVerticesStrided
266 };
267
268 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
269 #undef XCAST
270 #endif
271
272
273 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
274 # define XCAST(fun)     (typeof(VTABLE_IDirect3DVertexBuffer.fun))
275 #else
276 # define XCAST(fun)     (void*)
277 #endif
278
279 ICOM_VTABLE(IDirect3DVertexBuffer) VTABLE_IDirect3DVertexBuffer =
280 {
281     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
282     XCAST(QueryInterface) Thunk_IDirect3DVertexBufferImpl_1_QueryInterface,
283     XCAST(AddRef) Thunk_IDirect3DVertexBufferImpl_1_AddRef,
284     XCAST(Release) Thunk_IDirect3DVertexBufferImpl_1_Release,
285     XCAST(Lock) Thunk_IDirect3DVertexBufferImpl_1_Lock,
286     XCAST(Unlock) Thunk_IDirect3DVertexBufferImpl_1_Unlock,
287     XCAST(ProcessVertices) Main_IDirect3DVertexBufferImpl_1_ProcessVertices,
288     XCAST(GetVertexBufferDesc) Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc,
289     XCAST(Optimize) Main_IDirect3DVertexBufferImpl_1_Optimize
290 };
291
292 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
293 #undef XCAST
294 #endif
295
296 HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirect3DImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags)
297 {
298     IDirect3DVertexBufferImpl *object;
299     static const flag_info flags[] = {
300         FE(D3DVBCAPS_OPTIMIZED),
301         FE(D3DVBCAPS_SYSTEMMEMORY),
302         FE(D3DVBCAPS_WRITEONLY)
303     };
304
305     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBufferImpl));
306     if (object == NULL) return DDERR_OUTOFMEMORY;
307
308     object->ref = 1;
309     object->d3d = d3d;
310     object->desc = *lpD3DVertBufDesc;
311     object->vertex_buffer_size = get_flexible_vertex_size(lpD3DVertBufDesc->dwFVF, NULL) * lpD3DVertBufDesc->dwNumVertices;
312     object->vertices = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->vertex_buffer_size);
313     
314     ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer,  VTABLE_IDirect3DVertexBuffer);
315     ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer7, VTABLE_IDirect3DVertexBuffer7);
316
317     *obj = object;
318
319     if (TRACE_ON(ddraw)) {
320         TRACE(" creating implementation at %p with description : \n", *obj);
321         TRACE("  flags        : "); DDRAW_dump_flags_(lpD3DVertBufDesc->dwCaps, flags, sizeof(flags)/sizeof(flags[0]), TRUE);
322         TRACE("  vertex type  : "); dump_flexible_vertex(lpD3DVertBufDesc->dwFVF);
323         TRACE("  num vertices : %ld\n", lpD3DVertBufDesc->dwNumVertices);
324     }
325     
326     
327     return D3D_OK;
328 }