cubetexture.c 14.3 KB
Newer Older
1 2 3
/*
 * IDirect3DCubeTexture9 implementation
 *
4
 * Copyright 2002-2005 Jason Edmeades
5 6
 * Copyright 2002-2005 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 27
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);

28 29

/* IDirect3DCubeTexture9 IUnknown parts follow: */
30
static HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
31
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
Henri Verbeet's avatar
Henri Verbeet committed
32 33 34

    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);

35 36 37 38
    if (IsEqualGUID(riid, &IID_IUnknown)
        || IsEqualGUID(riid, &IID_IDirect3DResource9)
        || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
        || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
39
        IDirect3DCubeTexture9_AddRef(iface);
40
        *ppobj = This;
H. Verbeet's avatar
H. Verbeet committed
41
        return S_OK;
42 43 44
    }

    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
H. Verbeet's avatar
H. Verbeet committed
45
    *ppobj = NULL;
46 47 48
    return E_NOINTERFACE;
}

49
static ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
50
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
51 52
    ULONG ref = InterlockedIncrement(&This->ref);

Henri Verbeet's avatar
Henri Verbeet committed
53
    TRACE("%p increasing refcount to %u.\n", iface, ref);
54

55 56 57 58 59 60 61 62
    if (ref == 1)
    {
        IDirect3DDevice9Ex_AddRef(This->parentDevice);
        wined3d_mutex_lock();
        IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
        wined3d_mutex_unlock();
    }

63
    return ref;
64 65
}

66
static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
67
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
68
    ULONG ref = InterlockedDecrement(&This->ref);
69

Henri Verbeet's avatar
Henri Verbeet committed
70
    TRACE("%p decreasing refcount to %u.\n", iface, ref);
71

72
    if (ref == 0) {
73 74
        IDirect3DDevice9Ex *parentDevice = This->parentDevice;

75
        TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
76

77 78
        wined3d_mutex_lock();
        IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
79
        wined3d_mutex_unlock();
80 81 82

        /* Release the device last, as it may cause the device to be destroyed. */
        IDirect3DDevice9Ex_Release(parentDevice);
83 84 85 86 87
    }
    return ref;
}

/* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
88
static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
89
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
90
    IWineD3DDevice *wined3d_device;
91
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
92 93

    TRACE("iface %p, device %p.\n", iface, ppDevice);
94

95
    wined3d_mutex_lock();
96 97 98 99 100 101
    hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
    if (SUCCEEDED(hr))
    {
        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
        IWineD3DDevice_Release(wined3d_device);
    }
102 103
    wined3d_mutex_unlock();

104
    return hr;
105 106
}

107
static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
108
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
109
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
110 111 112

    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
113

114
    wined3d_mutex_lock();
115
    hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
116 117
    wined3d_mutex_unlock();

118
    return hr;
119 120
}

121
static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
122
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
123
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
124 125 126

    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
            iface, debugstr_guid(refguid), pData, pSizeOfData);
127

128
    wined3d_mutex_lock();
129
    hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
130 131
    wined3d_mutex_unlock();

132
    return hr;
133 134
}

135
static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
136
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
137
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
138 139

    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
140

141
    wined3d_mutex_lock();
142
    hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
143 144
    wined3d_mutex_unlock();

145
    return hr;
146 147
}

148
static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
149
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
150
    DWORD ret;
Henri Verbeet's avatar
Henri Verbeet committed
151 152

    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
153

154
    wined3d_mutex_lock();
155
    ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
156 157
    wined3d_mutex_unlock();

158
    return ret;
159 160
}

161
static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
162
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
163
    DWORD ret;
Henri Verbeet's avatar
Henri Verbeet committed
164 165

    TRACE("iface %p.\n", iface);
166

167
    wined3d_mutex_lock();
168
    ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
169 170
    wined3d_mutex_unlock();

171
    return ret;
172 173
}

174
static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
175
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
Henri Verbeet's avatar
Henri Verbeet committed
176 177

    TRACE("iface %p.\n", iface);
178

179
    wined3d_mutex_lock();
180
    IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
181
    wined3d_mutex_unlock();
182 183
}

184
static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
185
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
186
    D3DRESOURCETYPE ret;
Henri Verbeet's avatar
Henri Verbeet committed
187 188

    TRACE("iface %p.\n", iface);
189

190
    wined3d_mutex_lock();
191
    ret = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
192 193
    wined3d_mutex_unlock();

194
    return ret;
195 196 197
}

/* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
198
static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
199
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
200
    DWORD ret;
Henri Verbeet's avatar
Henri Verbeet committed
201 202

    TRACE("iface %p, lod %u.\n", iface, LODNew);
203

204
    wined3d_mutex_lock();
205
    ret = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
206 207
    wined3d_mutex_unlock();

208
    return ret;
209 210
}

211
static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
212
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
213
    DWORD ret;
Henri Verbeet's avatar
Henri Verbeet committed
214 215

    TRACE("iface %p.\n", iface);
216

217
    wined3d_mutex_lock();
218
    ret = IWineD3DCubeTexture_GetLOD(This->wineD3DCubeTexture);
219 220
    wined3d_mutex_unlock();

221
    return ret;
222 223
}

224
static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
225
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
226
    DWORD ret;
Henri Verbeet's avatar
Henri Verbeet committed
227 228

    TRACE("iface %p.\n", iface);
229

230
    wined3d_mutex_lock();
231
    ret = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
232 233
    wined3d_mutex_unlock();

234
    return ret;
235 236
}

237
static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
238
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
239
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
240 241

    TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
242

243
    wined3d_mutex_lock();
244
    hr = IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
245 246
    wined3d_mutex_unlock();

247
    return hr;
248 249
}

250
static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
251
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
252
    D3DTEXTUREFILTERTYPE ret;
Henri Verbeet's avatar
Henri Verbeet committed
253 254

    TRACE("iface %p.\n", iface);
255

256
    wined3d_mutex_lock();
257
    ret = (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
258 259
    wined3d_mutex_unlock();

260
    return ret;
261 262
}

263
static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
264
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
Henri Verbeet's avatar
Henri Verbeet committed
265 266

    TRACE("iface %p.\n", iface);
267

268
    wined3d_mutex_lock();
269
    IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
270
    wined3d_mutex_unlock();
271 272 273
}

/* IDirect3DCubeTexture9 Interface follow: */
274
static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
275
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
276
    WINED3DSURFACE_DESC wined3ddesc;
277
    HRESULT hr;
278

Henri Verbeet's avatar
Henri Verbeet committed
279
    TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
280

281
    wined3d_mutex_lock();
282
    hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
283
    wined3d_mutex_unlock();
284

285 286 287 288 289 290 291 292 293 294 295
    if (SUCCEEDED(hr))
    {
        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
        pDesc->Type = wined3ddesc.resource_type;
        pDesc->Usage = wined3ddesc.usage;
        pDesc->Pool = wined3ddesc.pool;
        pDesc->MultiSampleType = wined3ddesc.multisample_type;
        pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
        pDesc->Width = wined3ddesc.width;
        pDesc->Height = wined3ddesc.height;
    }
296

297
    return hr;
298 299
}

300
static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
301
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
302 303
    HRESULT hrc = D3D_OK;
    IWineD3DSurface *mySurface = NULL;
304

Henri Verbeet's avatar
Henri Verbeet committed
305
    TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, FaceType, Level, ppCubeMapSurface);
306

307
    wined3d_mutex_lock();
308
    hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
309
    if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
310 311
       IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
       IWineD3DCubeTexture_Release(mySurface);
312
    }
313 314
    wined3d_mutex_unlock();

315
    return hrc;
316 317
}

318
static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
319
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
320
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
321 322 323

    TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
            iface, FaceType, Level, pLockedRect, pRect, Flags);
324

325
    wined3d_mutex_lock();
326
    hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
327 328
    wined3d_mutex_unlock();

329
    return hr;
330 331
}

332
static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
333
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
334
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
335 336

    TRACE("iface %p, face %#x, level %u.\n", iface, FaceType, Level);
337

338
    wined3d_mutex_lock();
339
    hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
340 341
    wined3d_mutex_unlock();

342
    return hr;
343 344
}

345
static HRESULT  WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
346
    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
347
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
348 349

    TRACE("iface %p, face %#x, dirty_rect %p.\n", iface, FaceType, pDirtyRect);
350

351
    wined3d_mutex_lock();
352
    hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
353 354
    wined3d_mutex_unlock();

355
    return hr;
356 357 358
}


359
static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
360
{
361
    /* IUnknown */
362 363 364
    IDirect3DCubeTexture9Impl_QueryInterface,
    IDirect3DCubeTexture9Impl_AddRef,
    IDirect3DCubeTexture9Impl_Release,
365
    /* IDirect3DResource9 */
366 367 368 369 370 371 372 373
    IDirect3DCubeTexture9Impl_GetDevice,
    IDirect3DCubeTexture9Impl_SetPrivateData,
    IDirect3DCubeTexture9Impl_GetPrivateData,
    IDirect3DCubeTexture9Impl_FreePrivateData,
    IDirect3DCubeTexture9Impl_SetPriority,
    IDirect3DCubeTexture9Impl_GetPriority,
    IDirect3DCubeTexture9Impl_PreLoad,
    IDirect3DCubeTexture9Impl_GetType,
374
    /* IDirect3DBaseTexture9 */
375 376 377 378 379 380 381 382 383 384 385 386 387
    IDirect3DCubeTexture9Impl_SetLOD,
    IDirect3DCubeTexture9Impl_GetLOD,
    IDirect3DCubeTexture9Impl_GetLevelCount,
    IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
    IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
    IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
    IDirect3DCubeTexture9Impl_GetLevelDesc,
    IDirect3DCubeTexture9Impl_GetCubeMapSurface,
    IDirect3DCubeTexture9Impl_LockRect,
    IDirect3DCubeTexture9Impl_UnlockRect,
    IDirect3DCubeTexture9Impl_AddDirtyRect
};

388 389 390 391 392 393 394 395 396 397
static void STDMETHODCALLTYPE cubetexture_wined3d_object_destroyed(void *parent)
{
    HeapFree(GetProcessHeap(), 0, parent);
}

static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops =
{
    cubetexture_wined3d_object_destroyed,
};

398 399 400 401
HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
{
    HRESULT hr;
402

403 404
    texture->lpVtbl = &Direct3DCubeTexture9_Vtbl;
    texture->ref = 1;
405 406

    wined3d_mutex_lock();
407
    hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage,
408 409
            wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
            (IUnknown *)texture, &d3d9_cubetexture_wined3d_parent_ops);
410
    wined3d_mutex_unlock();
411 412 413 414
    if (FAILED(hr))
    {
        WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
        return hr;
415
    }
416

417 418 419 420
    texture->parentDevice = (IDirect3DDevice9Ex *)device;
    IDirect3DDevice9Ex_AddRef(texture->parentDevice);

    return D3D_OK;
421
}