cubetexture.c 12.6 KB
Newer Older
1 2 3
/*
 * IDirect3DCubeTexture8 implementation
 *
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

/* IDirect3DCubeTexture8 IUnknown parts follow: */
27
static HRESULT WINAPI IDirect3DCubeTexture8Impl_QueryInterface(LPDIRECT3DCUBETEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
Henri Verbeet's avatar
Henri Verbeet committed
29 30 31

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

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

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

46
static ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
47
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
48 49
    ULONG ref = InterlockedIncrement(&This->ref);

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

52 53 54 55 56 57 58 59
    if (ref == 1)
    {
        IUnknown_AddRef(This->parentDevice);
        wined3d_mutex_lock();
        IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
        wined3d_mutex_unlock();
    }

60
    return ref;
61 62
}

63
static ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
64
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
65
    ULONG ref = InterlockedDecrement(&This->ref);
66

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

69
    if (ref == 0) {
70 71
        IDirect3DDevice8 *parentDevice = This->parentDevice;

72
        TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
73 74

        wined3d_mutex_lock();
75
        IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
76
        wined3d_mutex_unlock();
77 78 79

        /* Release the device last, as it may cause the device to be destroyed. */
        IDirect3DDevice8_Release(parentDevice);
80 81 82 83
    }
    return ref;
}

84
/* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
85 86
static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8 *iface, IDirect3DDevice8 **device)
{
87
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
Henri Verbeet's avatar
Henri Verbeet committed
88

89
    TRACE("iface %p, device %p.\n", iface, device);
90

91 92 93 94
    *device = (IDirect3DDevice8 *)This->parentDevice;
    IDirect3DDevice8_AddRef(*device);

    TRACE("Returning device %p.\n", *device);
95

96
    return D3D_OK;
97
}
98

99
static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
100
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
101
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
102 103 104

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

106
    wined3d_mutex_lock();
107
    hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
108 109
    wined3d_mutex_unlock();

110
    return hr;
111
}
112

113
static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
114
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
115
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
116 117 118

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

120
    wined3d_mutex_lock();
121
    hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
122 123
    wined3d_mutex_unlock();

124
    return hr;
125
}
126

127
static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
128
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
129
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
130 131

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

133
    wined3d_mutex_lock();
134
    hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
135 136
    wined3d_mutex_unlock();

137
    return hr;
138
}
139

140
static DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
141
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
142
    DWORD ret;
Henri Verbeet's avatar
Henri Verbeet committed
143 144

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

146
    wined3d_mutex_lock();
147
    ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
148 149
    wined3d_mutex_unlock();

150
    return ret;
151
}
152

153
static DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
154
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
155
    DWORD ret;
Henri Verbeet's avatar
Henri Verbeet committed
156 157

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

159
    wined3d_mutex_lock();
160
    ret =  IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
161 162
    wined3d_mutex_unlock();

163
    return ret;
164
}
165

166
static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
167
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
Henri Verbeet's avatar
Henri Verbeet committed
168 169

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

171
    wined3d_mutex_lock();
172
    IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
173
    wined3d_mutex_unlock();
174 175
}

176
static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
177
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
178
    D3DRESOURCETYPE type;
Henri Verbeet's avatar
Henri Verbeet committed
179 180

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

182
    wined3d_mutex_lock();
183
    type = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
184 185
    wined3d_mutex_unlock();

186
    return type;
187 188
}

189
/* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
190
static DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
191
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
192
    DWORD lod;
Henri Verbeet's avatar
Henri Verbeet committed
193 194

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

196
    wined3d_mutex_lock();
197
    lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
198 199
    wined3d_mutex_unlock();

200
    return lod;
201
}
202

203
static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
204
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
205
    DWORD lod;
Henri Verbeet's avatar
Henri Verbeet committed
206 207

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

209
    wined3d_mutex_lock();
210
    lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
211 212
    wined3d_mutex_unlock();

213
    return lod;
214 215
}

216
static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
217
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
218
    DWORD cnt;
Henri Verbeet's avatar
Henri Verbeet committed
219 220

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

222
    wined3d_mutex_lock();
223
    cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
224 225
    wined3d_mutex_unlock();

226
    return cnt;
227 228
}

229
/* IDirect3DCubeTexture8 Interface follow: */
230
static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
231
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
232
    HRESULT hr;
233 234
    WINED3DSURFACE_DESC    wined3ddesc;

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

237
    wined3d_mutex_lock();
238
    hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
239
    wined3d_mutex_unlock();
240

241 242 243 244 245 246 247 248 249 250 251
    if (SUCCEEDED(hr))
    {
        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
        pDesc->Type = wined3ddesc.resource_type;
        pDesc->Usage = wined3ddesc.usage;
        pDesc->Pool = wined3ddesc.pool;
        pDesc->Size = wined3ddesc.size;
        pDesc->MultiSampleType = wined3ddesc.multisample_type;
        pDesc->Width = wined3ddesc.width;
        pDesc->Height = wined3ddesc.height;
    }
252

253
    return hr;
254
}
255

256
static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface) {
257
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
258 259 260
    HRESULT hrc = D3D_OK;
    IWineD3DSurface *mySurface = NULL;

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

263
    wined3d_mutex_lock();
264
    hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
265 266 267
    if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
       IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
       IWineD3DCubeTexture_Release(mySurface);
268
    }
269 270
    wined3d_mutex_unlock();

271
    return hrc;
272
}
273

274
static HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT *pRect, DWORD Flags) {
275
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
276
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
277 278 279

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

281
    wined3d_mutex_lock();
282
    hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
283 284
    wined3d_mutex_unlock();

285
    return hr;
286
}
287

288
static HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
289
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
290
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
291 292

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

294
    wined3d_mutex_lock();
295
    hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
296 297
    wined3d_mutex_unlock();

298
    return hr;
299
}
300

301
static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT *pDirtyRect) {
302
    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
303
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
304 305

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

307
    wined3d_mutex_lock();
308
    hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
309 310
    wined3d_mutex_unlock();

311
    return hr;
312 313
}

314
static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
315
{
316
    /* IUnknown */
317 318 319
    IDirect3DCubeTexture8Impl_QueryInterface,
    IDirect3DCubeTexture8Impl_AddRef,
    IDirect3DCubeTexture8Impl_Release,
320
    /* IDirect3DResource8 */
321 322 323 324 325 326 327 328
    IDirect3DCubeTexture8Impl_GetDevice,
    IDirect3DCubeTexture8Impl_SetPrivateData,
    IDirect3DCubeTexture8Impl_GetPrivateData,
    IDirect3DCubeTexture8Impl_FreePrivateData,
    IDirect3DCubeTexture8Impl_SetPriority,
    IDirect3DCubeTexture8Impl_GetPriority,
    IDirect3DCubeTexture8Impl_PreLoad,
    IDirect3DCubeTexture8Impl_GetType,
329
    /* IDirect3DBaseTexture8 */
330 331 332
    IDirect3DCubeTexture8Impl_SetLOD,
    IDirect3DCubeTexture8Impl_GetLOD,
    IDirect3DCubeTexture8Impl_GetLevelCount,
333
    /* IDirect3DCubeTexture8 */
334 335 336 337 338 339
    IDirect3DCubeTexture8Impl_GetLevelDesc,
    IDirect3DCubeTexture8Impl_GetCubeMapSurface,
    IDirect3DCubeTexture8Impl_LockRect,
    IDirect3DCubeTexture8Impl_UnlockRect,
    IDirect3DCubeTexture8Impl_AddDirtyRect
};
340

341 342 343 344 345 346 347 348 349 350
static void STDMETHODCALLTYPE d3d8_cubetexture_wined3d_object_destroyed(void *parent)
{
    HeapFree(GetProcessHeap(), 0, parent);
}

static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops =
{
    d3d8_cubetexture_wined3d_object_destroyed,
};

351 352 353 354 355 356 357 358 359 360
HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
{
    HRESULT hr;

    texture->lpVtbl = &Direct3DCubeTexture8_Vtbl;
    texture->ref = 1;

    wined3d_mutex_lock();
    hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage & WINED3DUSAGE_MASK,
361 362
            wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
            (IUnknown *)texture, &d3d8_cubetexture_wined3d_parent_ops);
363 364 365 366 367 368 369 370 371 372 373 374
    wined3d_mutex_unlock();
    if (FAILED(hr))
    {
        WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
        return hr;
    }

    texture->parentDevice = (IDirect3DDevice8 *)device;
    IDirect3DDevice8_AddRef(texture->parentDevice);

    return D3D_OK;
}