3 * Copyright 2002 Raphael Junqueira
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
29 #include "d3dx9_36_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
33 /* ID3DXBuffer IUnknown parts follow: */
34 static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(LPD3DXBUFFER iface, REFIID riid, LPVOID* ppobj)
36 ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_ID3DXBuffer))
41 IUnknown_AddRef(iface);
46 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
50 static ULONG WINAPI ID3DXBufferImpl_AddRef(LPD3DXBUFFER iface)
52 ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
53 ULONG ref = InterlockedIncrement(&This->ref);
55 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
60 static ULONG WINAPI ID3DXBufferImpl_Release(LPD3DXBUFFER iface)
62 ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
63 ULONG ref = InterlockedDecrement(&This->ref);
65 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
69 HeapFree(GetProcessHeap(), 0, This->buffer);
70 HeapFree(GetProcessHeap(), 0, This);
75 /* ID3DXBuffer Interface follow: */
76 static LPVOID WINAPI ID3DXBufferImpl_GetBufferPointer(LPD3DXBUFFER iface)
78 ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
82 static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(LPD3DXBUFFER iface)
84 ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
85 return This->bufferSize;
88 const ID3DXBufferVtbl D3DXBuffer_Vtbl =
90 ID3DXBufferImpl_QueryInterface,
91 ID3DXBufferImpl_AddRef,
92 ID3DXBufferImpl_Release,
93 ID3DXBufferImpl_GetBufferPointer,
94 ID3DXBufferImpl_GetBufferSize
97 HRESULT WINAPI D3DXCreateBuffer(DWORD NumBytes, LPD3DXBUFFER* ppBuffer)
99 ID3DXBufferImpl *object;
101 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXBufferImpl));
105 return E_OUTOFMEMORY;
107 object->lpVtbl = &D3DXBuffer_Vtbl;
109 object->bufferSize = NumBytes;
110 object->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, NumBytes);
111 if (object->buffer == NULL)
113 HeapFree(GetProcessHeap(), 0, object);
115 return E_OUTOFMEMORY;
118 *ppBuffer = (LPD3DXBUFFER)object;