- Add support (as far as was previously) for the VertexBuffer and
[wine] / dlls / d3d9 / cubetexture.c
1 /*
2  * IDirect3DCubeTexture9 implementation
3  *
4  * Copyright 2002-2003 Jason Edmeades
5  *                     Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
26
27 /* IDirect3DCubeTexture9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DResource9)
33         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
34         || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
35         IDirect3DCubeTexture9Impl_AddRef(iface);
36         *ppobj = This;
37         return D3D_OK;
38     }
39
40     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41     return E_NOINTERFACE;
42 }
43
44 ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
45     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
46     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
47     return ++(This->ref);
48 }
49
50 ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
51     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
52     ULONG ref = --This->ref;
53     unsigned int i, j;
54
55     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
56     if (ref == 0) {
57         for (i = 0; i < This->levels; i++) {
58           for (j = 0; j < 6; j++) { 
59             if (This->surfaces[j][i] != NULL) {
60               TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[j][i]);
61               IDirect3DSurface9Impl_Release((LPDIRECT3DSURFACE9) This->surfaces[j][i]);
62             }
63           }
64         }
65         HeapFree(GetProcessHeap(), 0, This);
66     }
67     return ref;
68 }
69
70 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
71 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
72     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
73     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
74 }
75
76 HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
77     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
78     FIXME("(%p) : stub\n", This);    
79     return D3D_OK;
80 }
81
82 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
83     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
84     FIXME("(%p) : stub\n", This);    
85     return D3D_OK;
86 }
87
88 HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
89     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
90     FIXME("(%p) : stub\n", This);    
91     return D3D_OK;
92 }
93
94 DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
95     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
96     return IDirect3DResource9Impl_SetPriority((LPDIRECT3DRESOURCE9) This, PriorityNew);
97 }
98
99 DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
100     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
101     return IDirect3DResource9Impl_GetPriority((LPDIRECT3DRESOURCE9) This);
102 }
103
104 void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
105     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
106     FIXME("(%p) : stub\n", This);    
107     return ;
108 }
109
110 D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
111     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
112     return IDirect3DResource9Impl_GetType((LPDIRECT3DRESOURCE9) This);
113 }
114
115 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
116 DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
117     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
118     return IDirect3DBaseTexture9Impl_SetLOD((LPDIRECT3DBASETEXTURE9) This, LODNew);
119 }
120
121 DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
122     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
123     return IDirect3DBaseTexture9Impl_GetLOD((LPDIRECT3DBASETEXTURE9) This);
124 }
125
126 DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
127     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
128     return IDirect3DBaseTexture9Impl_GetLevelCount((LPDIRECT3DBASETEXTURE9) This);
129 }
130
131 HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
132   IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
133     return IDirect3DBaseTexture9Impl_SetAutoGenFilterType((LPDIRECT3DBASETEXTURE9) This, FilterType);
134 }
135
136 D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
137   IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
138   return IDirect3DBaseTexture9Impl_GetAutoGenFilterType((LPDIRECT3DBASETEXTURE9) This);
139 }
140
141 void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
142   IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
143   FIXME("(%p) : stub\n", This);
144   return ;
145 }
146
147 /* IDirect3DCubeTexture9 Interface follow: */
148 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
149     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
150     if (Level < This->levels) {
151         TRACE("(%p) level (%d)\n", This, Level);
152         return IDirect3DSurface9Impl_GetDesc((LPDIRECT3DSURFACE9) This->surfaces[0][Level], pDesc);
153     } else {
154         FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
155         return D3DERR_INVALIDCALL;
156     }
157     return D3D_OK;
158 }
159
160 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
161     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
162     if (Level < This->levels) {
163         *ppCubeMapSurface = (LPDIRECT3DSURFACE9) This->surfaces[FaceType][Level];
164         IDirect3DSurface9Impl_AddRef((LPDIRECT3DSURFACE9) *ppCubeMapSurface);
165         TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
166     } else {
167         FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
168         return D3DERR_INVALIDCALL;
169     }
170     return D3D_OK;
171 }
172
173 HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
174     HRESULT hr;
175     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
176     if (Level < This->levels) {
177       /**
178        * Not dirtified while Surfaces don't notify dirtification
179        * This->Dirty = TRUE;
180        */
181       hr = IDirect3DSurface9Impl_LockRect((LPDIRECT3DSURFACE9) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
182       TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
183     } else {
184       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
185       return D3DERR_INVALIDCALL;
186     }
187     return hr;
188 }
189
190 HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
191     HRESULT hr;
192     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
193     if (Level < This->levels) {
194       hr = IDirect3DSurface9Impl_UnlockRect((LPDIRECT3DSURFACE9) This->surfaces[FaceType][Level]);
195       TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
196     } else {
197       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
198       return D3DERR_INVALIDCALL;
199     }
200     return hr;
201 }
202
203 HRESULT  WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
204     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
205     FIXME("(%p) : stub\n", This);
206     This->Dirty = TRUE;
207     return D3D_OK;
208 }
209
210
211 IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
212 {
213     IDirect3DCubeTexture9Impl_QueryInterface,
214     IDirect3DCubeTexture9Impl_AddRef,
215     IDirect3DCubeTexture9Impl_Release,
216     IDirect3DCubeTexture9Impl_GetDevice,
217     IDirect3DCubeTexture9Impl_SetPrivateData,
218     IDirect3DCubeTexture9Impl_GetPrivateData,
219     IDirect3DCubeTexture9Impl_FreePrivateData,
220     IDirect3DCubeTexture9Impl_SetPriority,
221     IDirect3DCubeTexture9Impl_GetPriority,
222     IDirect3DCubeTexture9Impl_PreLoad,
223     IDirect3DCubeTexture9Impl_GetType,
224     IDirect3DCubeTexture9Impl_SetLOD,
225     IDirect3DCubeTexture9Impl_GetLOD,
226     IDirect3DCubeTexture9Impl_GetLevelCount,
227     IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
228     IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
229     IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
230     IDirect3DCubeTexture9Impl_GetLevelDesc,
231     IDirect3DCubeTexture9Impl_GetCubeMapSurface,
232     IDirect3DCubeTexture9Impl_LockRect,
233     IDirect3DCubeTexture9Impl_UnlockRect,
234     IDirect3DCubeTexture9Impl_AddDirtyRect
235 };
236
237
238 /* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
239 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9 iface, 
240                                                         UINT EdgeLength, UINT Levels, DWORD Usage, 
241                                                         D3DFORMAT Format, D3DPOOL Pool, 
242                                                         IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
243
244     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
245     FIXME("(%p) : stub\n", This);
246     return D3D_OK;
247 }