2 * Copyright (c) 2002 Lionel ULMER
4 * This file contains the implementation of Direct3DVertexBuffer COM object
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.
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.
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
27 #include "wine/debug.h"
29 #include "d3d_private.h"
30 #include "mesa_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
35 Main_IDirect3DVertexBufferImpl_7_1T_QueryInterface(LPDIRECT3DVERTEXBUFFER7 iface,
39 ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
40 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
42 /* By default, set the object pointer to NULL */
45 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
46 IDirect3DVertexBuffer7_AddRef(ICOM_INTERFACE(This,IDirect3DVertexBuffer7));
48 TRACE(" Creating IUnknown interface at %p.\n", *obp);
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);
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);
63 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
64 return OLE_E_ENUM_NOMORE;
68 Main_IDirect3DVertexBufferImpl_7_1T_AddRef(LPDIRECT3DVERTEXBUFFER7 iface)
70 ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
71 TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
76 Main_IDirect3DVertexBufferImpl_7_1T_Release(LPDIRECT3DVERTEXBUFFER7 iface)
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);
89 Main_IDirect3DVertexBufferImpl_7_1T_Lock(LPDIRECT3DVERTEXBUFFER7 iface,
94 ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
95 TRACE("(%p/%p)->(%08lx,%p,%p)\n", This, iface, dwFlags, lplpData, lpdwSize);
97 if (TRACE_ON(ddraw)) {
98 TRACE(" lock flags : ");
99 DDRAW_dump_lockflag(dwFlags);
102 if (lpdwSize != NULL) *lpdwSize = This->vertex_buffer_size;
103 *lplpData = This->vertices;
109 Main_IDirect3DVertexBufferImpl_7_1T_Unlock(LPDIRECT3DVERTEXBUFFER7 iface)
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 :-) */
118 Main_IDirect3DVertexBufferImpl_7_ProcessVertices(LPDIRECT3DVERTEXBUFFER7 iface,
122 LPDIRECT3DVERTEXBUFFER7 lpSrcBuffer,
124 LPDIRECT3DDEVICE7 lpD3DDevice,
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);
133 Main_IDirect3DVertexBufferImpl_7_1T_GetVertexBufferDesc(LPDIRECT3DVERTEXBUFFER7 iface,
134 LPD3DVERTEXBUFFERDESC lpD3DVertexBufferDesc)
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);
145 Main_IDirect3DVertexBufferImpl_7_Optimize(LPDIRECT3DVERTEXBUFFER7 iface,
146 LPDIRECT3DDEVICE7 lpD3DDevice,
149 ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
150 FIXME("(%p/%p)->(%p,%08lx): stub!\n", This, iface, lpD3DDevice, dwFlags);
155 Main_IDirect3DVertexBufferImpl_7_ProcessVerticesStrided(LPDIRECT3DVERTEXBUFFER7 iface,
159 LPD3DDRAWPRIMITIVESTRIDEDDATA lpStrideData,
160 DWORD dwVertexTypeDesc,
161 LPDIRECT3DDEVICE7 lpD3DDevice,
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);
170 Main_IDirect3DVertexBufferImpl_1_ProcessVertices(LPDIRECT3DVERTEXBUFFER iface,
174 LPDIRECT3DVERTEXBUFFER lpSrcBuffer,
176 LPDIRECT3DDEVICE3 lpD3DDevice,
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);
185 Main_IDirect3DVertexBufferImpl_1_Optimize(LPDIRECT3DVERTEXBUFFER iface,
186 LPDIRECT3DDEVICE3 lpD3DDevice,
189 ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, iface);
190 FIXME("(%p/%p)->(%p,%08lx): stub!\n", This, iface, lpD3DDevice, dwFlags);
195 Thunk_IDirect3DVertexBufferImpl_1_QueryInterface(LPDIRECT3DVERTEXBUFFER iface,
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),
206 Thunk_IDirect3DVertexBufferImpl_1_AddRef(LPDIRECT3DVERTEXBUFFER iface)
208 TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
209 return IDirect3DVertexBuffer7_AddRef(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
213 Thunk_IDirect3DVertexBufferImpl_1_Release(LPDIRECT3DVERTEXBUFFER iface)
215 TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
216 return IDirect3DVertexBuffer7_Release(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
220 Thunk_IDirect3DVertexBufferImpl_1_Lock(LPDIRECT3DVERTEXBUFFER iface,
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),
233 Thunk_IDirect3DVertexBufferImpl_1_Unlock(LPDIRECT3DVERTEXBUFFER iface)
235 TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
236 return IDirect3DVertexBuffer7_Unlock(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
240 Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc(LPDIRECT3DVERTEXBUFFER iface,
241 LPD3DVERTEXBUFFERDESC lpD3DVertexBufferDesc)
243 TRACE("(%p)->(%p) thunking to IDirect3DVertexBuffer7 interface.\n", iface, lpD3DVertexBufferDesc);
244 return IDirect3DVertexBuffer7_GetVertexBufferDesc(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
245 lpD3DVertexBufferDesc);
248 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
249 # define XCAST(fun) (typeof(VTABLE_IDirect3DVertexBuffer7.fun))
251 # define XCAST(fun) (void*)
254 ICOM_VTABLE(IDirect3DVertexBuffer7) VTABLE_IDirect3DVertexBuffer7 =
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
268 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
273 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
274 # define XCAST(fun) (typeof(VTABLE_IDirect3DVertexBuffer.fun))
276 # define XCAST(fun) (void*)
279 ICOM_VTABLE(IDirect3DVertexBuffer) VTABLE_IDirect3DVertexBuffer =
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
292 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
296 HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirect3DImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags)
298 IDirect3DVertexBufferImpl *object;
299 static const flag_info flags[] = {
300 FE(D3DVBCAPS_OPTIMIZED),
301 FE(D3DVBCAPS_SYSTEMMEMORY),
302 FE(D3DVBCAPS_WRITEONLY)
305 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBufferImpl));
306 if (object == NULL) return DDERR_OUTOFMEMORY;
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);
314 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer, VTABLE_IDirect3DVertexBuffer);
315 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer7, VTABLE_IDirect3DVertexBuffer7);
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);