vertexbuffer.c 9.09 KB
Newer Older
1
/*
2
 * IDirect3DVertexBuffer9 implementation
3
 *
4
 * Copyright 2002-2004 Jason Edmeades
5 6
 * Copyright 2002-2004 Raphael Junqueira
 * Copyright 2005 Oliver Stieber
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 22 23 24 25
 */

#include "config.h"
#include "d3d9_private.h"

26
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 28

/* IDirect3DVertexBuffer9 IUnknown parts follow: */
29
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
30
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
31 32 33 34

    if (IsEqualGUID(riid, &IID_IUnknown)
        || IsEqualGUID(riid, &IID_IDirect3DResource9)
        || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)) {
35
        IUnknown_AddRef(iface);
36
        *ppobj = This;
H. Verbeet's avatar
H. Verbeet committed
37
        return S_OK;
38 39 40
    }

    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
H. Verbeet's avatar
H. Verbeet committed
41
    *ppobj = NULL;
42 43 44
    return E_NOINTERFACE;
}

45
static ULONG WINAPI IDirect3DVertexBuffer9Impl_AddRef(LPDIRECT3DVERTEXBUFFER9 iface) {
46
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
47 48
    ULONG ref = InterlockedIncrement(&This->ref);

49
    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
50 51

    return ref;
52 53
}

54
static ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface) {
55
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
56
    ULONG ref = InterlockedDecrement(&This->ref);
57

58
    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
59

60
    if (ref == 0) {
61
        EnterCriticalSection(&d3d9_cs);
62
        IWineD3DVertexBuffer_Release(This->wineD3DVertexBuffer);
63
        LeaveCriticalSection(&d3d9_cs);
64
        IUnknown_Release(This->parentDevice);
65 66 67 68 69 70
        HeapFree(GetProcessHeap(), 0, This);
    }
    return ref;
}

/* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
71
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
72
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
73
    HRESULT hr;
74
    TRACE("(%p) Relay\n", This);
75 76 77 78 79

    EnterCriticalSection(&d3d9_cs);
    hr = IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
80 81
}

82
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
83
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
84
    TRACE("(%p) Relay\n", This);
85
    return IWineD3DVertexBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
86 87
}

88
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
89
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
90
    HRESULT hr;
91
    TRACE("(%p) Relay\n", This);
92 93 94 95 96

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
97 98
}

99
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
100
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
101
    HRESULT hr;
102
    TRACE("(%p) Relay\n", This);
103 104 105 106 107

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
108 109
}

110
static DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
111
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
112
    HRESULT hr;
113
    TRACE("(%p) Relay\n", This);
114 115 116 117 118

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
119 120
}

121
static DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
122
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
123
    HRESULT hr;
124
    TRACE("(%p) Relay\n", This);
125 126 127 128 129

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexBuffer_GetPriority(This->wineD3DVertexBuffer);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
130 131
}

132
static void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
133
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
134
    TRACE("(%p) Relay\n", This);
135 136

    EnterCriticalSection(&d3d9_cs);
137
    IWineD3DVertexBuffer_PreLoad(This->wineD3DVertexBuffer);
138
    LeaveCriticalSection(&d3d9_cs);
139 140 141
    return ;
}

142
static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface) {
143
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
144
    D3DRESOURCETYPE ret;
145
    TRACE("(%p) Relay\n", This);
146 147 148 149 150

    EnterCriticalSection(&d3d9_cs);
    ret = IWineD3DVertexBuffer_GetType(This->wineD3DVertexBuffer);
    LeaveCriticalSection(&d3d9_cs);
    return ret;
151 152 153
}

/* IDirect3DVertexBuffer9 Interface follow: */
154
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
155
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
156
    HRESULT hr;
157
    TRACE("(%p) Relay\n", This);
158 159 160 161 162

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexBuffer_Lock(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
163 164
}

165
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
166
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
167
    HRESULT hr;
168
    TRACE("(%p) Relay\n", This);
169 170 171 172 173

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexBuffer_Unlock(This->wineD3DVertexBuffer);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
174 175
}

176
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
177
    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
178
    HRESULT hr;
179
    TRACE("(%p) Relay\n", This);
180 181 182 183 184

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexBuffer_GetDesc(This->wineD3DVertexBuffer, (WINED3DVERTEXBUFFER_DESC *) pDesc);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
185 186
}

187
static const IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
188
{
189
    /* IUnknown */
190 191 192
    IDirect3DVertexBuffer9Impl_QueryInterface,
    IDirect3DVertexBuffer9Impl_AddRef,
    IDirect3DVertexBuffer9Impl_Release,
193
    /* IDirect3DResource9 */
194 195 196 197 198 199 200 201
    IDirect3DVertexBuffer9Impl_GetDevice,
    IDirect3DVertexBuffer9Impl_SetPrivateData,
    IDirect3DVertexBuffer9Impl_GetPrivateData,
    IDirect3DVertexBuffer9Impl_FreePrivateData,
    IDirect3DVertexBuffer9Impl_SetPriority,
    IDirect3DVertexBuffer9Impl_GetPriority,
    IDirect3DVertexBuffer9Impl_PreLoad,
    IDirect3DVertexBuffer9Impl_GetType,
202
    /* IDirect3DVertexBuffer9 */
203 204 205 206 207 208 209
    IDirect3DVertexBuffer9Impl_Lock,
    IDirect3DVertexBuffer9Impl_Unlock,
    IDirect3DVertexBuffer9Impl_GetDesc
};


/* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
210
HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface,
211 212
                                UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool,
                                IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
213
    
214
    IDirect3DVertexBuffer9Impl *object;
215
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
216
    HRESULT hrc = D3D_OK;
217 218 219

    /* Allocate the storage for the device */
    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
220
    if (NULL == object) {
221
        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
222 223 224
        return D3DERR_OUTOFVIDEOMEMORY;
    }

225 226
    object->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
    object->ref = 1;
227
    EnterCriticalSection(&d3d9_cs);
228
    hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK, FVF, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), pSharedHandle, (IUnknown *)object);
229
    LeaveCriticalSection(&d3d9_cs);
230 231
    
    if (hrc != D3D_OK) {
232 233

        /* free up object */
234
        WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
235 236
        HeapFree(GetProcessHeap(), 0, object);
    } else {
237 238
        IUnknown_AddRef(iface);
        object->parentDevice = iface;
239
        TRACE("(%p) : Created vertex buffer %p\n", This, object);
240 241 242
        *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
    }
    return hrc;
243
}