vertexbuffer.c 7.61 KB
Newer Older
1
/*
2
 * IDirect3DVertexBuffer8 implementation
3
 *
4
 * Copyright 2005 Oliver Stieber
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20
 */

21
#include "config.h"
22 23
#include "d3d8_private.h"

24
WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25

26
/* IDirect3DVertexBuffer8 IUnknown parts follow: */
27
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
29 30

    if (IsEqualGUID(riid, &IID_IUnknown)
Raphael Junqueira's avatar
Raphael Junqueira committed
31 32
        || IsEqualGUID(riid, &IID_IDirect3DResource8)
        || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
33
        IUnknown_AddRef(iface);
34
        *ppobj = This;
H. Verbeet's avatar
H. Verbeet committed
35
        return S_OK;
36 37
    }

38 39
    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);

H. Verbeet's avatar
H. Verbeet committed
40
    *ppobj = NULL;
41 42 43
    return E_NOINTERFACE;
}

44
static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
45
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
46 47
    ULONG ref = InterlockedIncrement(&This->ref);

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

    return ref;
51 52
}

53
static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
54
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
55 56
    ULONG ref = InterlockedDecrement(&This->ref);

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

59
    if (ref == 0) {
60
        EnterCriticalSection(&d3d8_cs);
61
        IWineD3DVertexBuffer_Release(This->wineD3DVertexBuffer);
62
        LeaveCriticalSection(&d3d8_cs);
63
        IUnknown_Release(This->parentDevice);
64 65
        HeapFree(GetProcessHeap(), 0, This);
    }
66

67 68 69
    return ref;
}

70
/* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
71
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
72
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
73
    HRESULT hr;
74
    TRACE("(%p) Relay\n", This);
75

76 77 78 79
    EnterCriticalSection(&d3d8_cs);
    hr = IDirect3DResource8Impl_GetDevice((LPDIRECT3DRESOURCE8) This, ppDevice);
    LeaveCriticalSection(&d3d8_cs);
    return hr;
80 81
}

82
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
83
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
84
    HRESULT hr;
85
    TRACE("(%p) Relay\n", This);
86

87 88 89 90
    EnterCriticalSection(&d3d8_cs);
    hr = IWineD3DVertexBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
    LeaveCriticalSection(&d3d8_cs);
    return hr;
91 92
}

93
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
94
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
95
    HRESULT hr;
96 97
    TRACE("(%p) Relay\n", This);

98 99 100 101
    EnterCriticalSection(&d3d8_cs);
    hr = IWineD3DVertexBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
    LeaveCriticalSection(&d3d8_cs);
    return hr;
102
}
103

104
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
105
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
106
    HRESULT hr;
107 108
    TRACE("(%p) Relay\n", This);

109 110 111 112
    EnterCriticalSection(&d3d8_cs);
    hr = IWineD3DVertexBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
    LeaveCriticalSection(&d3d8_cs);
    return hr;
113
}
114

115
static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
116
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
117
    DWORD ret;
118 119
    TRACE("(%p) Relay\n", This);

120 121 122 123
    EnterCriticalSection(&d3d8_cs);
    ret = IWineD3DVertexBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
    LeaveCriticalSection(&d3d8_cs);
    return ret;
124
}
125

126
static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
127
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
128
    DWORD ret;
129 130
    TRACE("(%p) Relay\n", This);

131 132 133 134
    EnterCriticalSection(&d3d8_cs);
    ret = IWineD3DVertexBuffer_GetPriority(This->wineD3DVertexBuffer);
    LeaveCriticalSection(&d3d8_cs);
    return ret;
135
}
136

137
static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
138
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
139 140
    TRACE("(%p) Relay\n", This);

141 142 143
    EnterCriticalSection(&d3d8_cs);
    IWineD3DVertexBuffer_PreLoad(This->wineD3DVertexBuffer);
    LeaveCriticalSection(&d3d8_cs);
144
}
145

146
static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
147
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
148
    D3DRESOURCETYPE type;
149 150
    TRACE("(%p) Relay\n", This);

151 152 153 154
    EnterCriticalSection(&d3d8_cs);
    type = IWineD3DVertexBuffer_GetType(This->wineD3DVertexBuffer);
    LeaveCriticalSection(&d3d8_cs);
    return type;
155 156
}

157
/* IDirect3DVertexBuffer8 Interface follow: */
158
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
159
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
160
    HRESULT hr;
161 162
    TRACE("(%p) Relay\n", This);

163 164 165 166
    EnterCriticalSection(&d3d8_cs);
    hr = IWineD3DVertexBuffer_Lock(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
    LeaveCriticalSection(&d3d8_cs);
    return hr;
167
}
168

169
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
170
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
171
    HRESULT hr;
172 173
    TRACE("(%p) Relay\n", This);

174 175 176 177
    EnterCriticalSection(&d3d8_cs);
    hr = IWineD3DVertexBuffer_Unlock(This->wineD3DVertexBuffer);
    LeaveCriticalSection(&d3d8_cs);
    return hr;
178
}
179

180
static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
181
    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
182
    HRESULT hr;
183
    TRACE("(%p) Relay\n", This);
184

185 186 187 188
    EnterCriticalSection(&d3d8_cs);
    hr = IWineD3DVertexBuffer_GetDesc(This->wineD3DVertexBuffer, (WINED3DVERTEXBUFFER_DESC *) pDesc);
    LeaveCriticalSection(&d3d8_cs);
    return hr;
189 190
}

191
const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
192
{
193
    /* IUnknown */
194 195 196
    IDirect3DVertexBuffer8Impl_QueryInterface,
    IDirect3DVertexBuffer8Impl_AddRef,
    IDirect3DVertexBuffer8Impl_Release,
197
    /* IDirect3DResource8 */
198 199 200 201 202 203 204 205
    IDirect3DVertexBuffer8Impl_GetDevice,
    IDirect3DVertexBuffer8Impl_SetPrivateData,
    IDirect3DVertexBuffer8Impl_GetPrivateData,
    IDirect3DVertexBuffer8Impl_FreePrivateData,
    IDirect3DVertexBuffer8Impl_SetPriority,
    IDirect3DVertexBuffer8Impl_GetPriority,
    IDirect3DVertexBuffer8Impl_PreLoad,
    IDirect3DVertexBuffer8Impl_GetType,
206
    /* IDirect3DVertexBuffer8 */
207 208 209 210
    IDirect3DVertexBuffer8Impl_Lock,
    IDirect3DVertexBuffer8Impl_Unlock,
    IDirect3DVertexBuffer8Impl_GetDesc
};