- some fixes in CreateDevice init
[wine] / dlls / d3d8 / texture.c
1 /*
2  * IDirect3DTexture8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
25 #include "wine/debug.h"
26
27 #include "d3d8_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30
31 /* IDirect3DTexture8 IUnknown parts follow: */
32 HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface,REFIID riid,LPVOID *ppobj)
33 {
34     ICOM_THIS(IDirect3DTexture8Impl,iface);
35     TRACE("(%p) : QueryInterface\n", This);
36     if (IsEqualGUID(riid, &IID_IUnknown)
37         || IsEqualGUID(riid, &IID_IDirect3DResource8)
38         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
39         || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
40         IDirect3DTexture8Impl_AddRef(iface);
41         *ppobj = This;
42         return D3D_OK;
43     }
44
45     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
46     return E_NOINTERFACE;
47 }
48
49 ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
50     ICOM_THIS(IDirect3DTexture8Impl,iface);
51     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
52     return ++(This->ref);
53 }
54
55 ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
56     ICOM_THIS(IDirect3DTexture8Impl,iface);
57     ULONG ref = --This->ref;
58     int i;
59
60     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
61     if (ref == 0) {
62         for (i=0; i<This->levels; i++) {
63             if (This->surfaces[i] != NULL) {
64                 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[i]);
65                 IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) This->surfaces[i]);
66             }
67         }
68         HeapFree(GetProcessHeap(), 0, This);
69     }
70     return ref;
71 }
72
73 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
74 HRESULT  WINAPI        IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8** ppDevice) {
75     ICOM_THIS(IDirect3DTexture8Impl,iface);
76     TRACE("(%p) : returning %p\n", This, This->Device);
77     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
78     return D3D_OK;
79 }
80 HRESULT  WINAPI        IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
81     ICOM_THIS(IDirect3DTexture8Impl,iface);
82     FIXME("(%p) : stub\n", This);    return D3D_OK;
83 }
84 HRESULT  WINAPI        IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
85     ICOM_THIS(IDirect3DTexture8Impl,iface);
86     FIXME("(%p) : stub\n", This);    return D3D_OK;
87 }
88 HRESULT  WINAPI        IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
89     ICOM_THIS(IDirect3DTexture8Impl,iface);
90     FIXME("(%p) : stub\n", This);    return D3D_OK;
91 }
92 DWORD    WINAPI        IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
93     ICOM_THIS(IDirect3DTexture8Impl,iface);
94     FIXME("(%p) : stub\n", This);    return D3D_OK;
95 }
96 DWORD    WINAPI        IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
97     ICOM_THIS(IDirect3DTexture8Impl,iface);
98     FIXME("(%p) : stub\n", This);    return D3D_OK;
99 }
100 void     WINAPI        IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
101     ICOM_THIS(IDirect3DTexture8Impl,iface);
102     FIXME("(%p) : stub\n", This);
103 }
104 D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
105     ICOM_THIS(IDirect3DTexture8Impl,iface);
106     TRACE("(%p) : is %d \n", This, This->ResourceType);
107     return This->ResourceType;
108 }
109
110 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
111 DWORD    WINAPI        IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
112     ICOM_THIS(IDirect3DTexture8Impl,iface);
113     FIXME("(%p) : stub\n", This);    return D3D_OK;
114 }
115 DWORD    WINAPI        IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
116     ICOM_THIS(IDirect3DTexture8Impl,iface);
117     FIXME("(%p) : stub\n", This);    return D3D_OK;
118 }
119 DWORD    WINAPI        IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
120     ICOM_THIS(IDirect3DTexture8Impl,iface);
121     TRACE("(%p) : returning %d\n", This, This->levels);
122     return This->levels;
123 }
124
125 /* IDirect3DTexture8 */
126 HRESULT  WINAPI        IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level,D3DSURFACE_DESC* pDesc) {
127     ICOM_THIS(IDirect3DTexture8Impl,iface);
128
129     if (Level < This->levels) {
130         TRACE("(%p) Level (%d)\n", This, Level);
131         return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8)This->surfaces[Level], pDesc);
132     } else {
133         FIXME("(%p) Level (%d)\n", This, Level);
134     }
135     return D3D_OK;
136 }
137 HRESULT  WINAPI        IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level,IDirect3DSurface8** ppSurfaceLevel) {
138     ICOM_THIS(IDirect3DTexture8Impl,iface);
139     *ppSurfaceLevel = (LPDIRECT3DSURFACE8)This->surfaces[Level];
140     IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8)This->surfaces[Level]);
141     TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
142     return D3D_OK;
143 }
144 HRESULT  WINAPI        IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) {
145     ICOM_THIS(IDirect3DTexture8Impl,iface);
146     TRACE("(%p) Level (%d)\n", This, Level);
147     if (Level < This->levels) {
148         return IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8)This->surfaces[Level], pLockedRect, pRect, Flags);
149     } else {
150         FIXME("Levels seems too high?!!\n");
151     }
152     return D3D_OK;
153 }
154 HRESULT  WINAPI        IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
155     ICOM_THIS(IDirect3DTexture8Impl,iface);
156     This->Dirty = TRUE;
157     TRACE("(%p) : stub\n", This);
158     return D3D_OK;
159 }
160 HRESULT  WINAPI        IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT* pDirtyRect) {
161     ICOM_THIS(IDirect3DTexture8Impl,iface);
162     This->Dirty = TRUE;
163     FIXME("(%p) : stub\n", This);    return D3D_OK;
164 }
165
166
167 ICOM_VTABLE(IDirect3DTexture8) Direct3DTexture8_Vtbl =
168 {
169     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
170     IDirect3DTexture8Impl_QueryInterface,
171     IDirect3DTexture8Impl_AddRef,
172     IDirect3DTexture8Impl_Release,
173     IDirect3DTexture8Impl_GetDevice,
174     IDirect3DTexture8Impl_SetPrivateData,
175     IDirect3DTexture8Impl_GetPrivateData,
176     IDirect3DTexture8Impl_FreePrivateData,
177     IDirect3DTexture8Impl_SetPriority,
178     IDirect3DTexture8Impl_GetPriority,
179     IDirect3DTexture8Impl_PreLoad,
180     IDirect3DTexture8Impl_GetType,
181     IDirect3DTexture8Impl_SetLOD,
182     IDirect3DTexture8Impl_GetLOD,
183     IDirect3DTexture8Impl_GetLevelCount,
184     IDirect3DTexture8Impl_GetLevelDesc,
185     IDirect3DTexture8Impl_GetSurfaceLevel,
186     IDirect3DTexture8Impl_LockRect,
187     IDirect3DTexture8Impl_UnlockRect,
188     IDirect3DTexture8Impl_AddDirtyRect
189
190 };