winsock: Implement getnameinfo.
[wine] / dlls / d3d9 / cubetexture.c
1 /*
2  * IDirect3DCubeTexture9 implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  * Copyright 2002-2005 Raphael Junqueira
6  * Copyright 2005 Oliver Stieber
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28
29 /* IDirect3DCubeTexture9 IUnknown parts follow: */
30 HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
31     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
32     if (IsEqualGUID(riid, &IID_IUnknown)
33         || IsEqualGUID(riid, &IID_IDirect3DResource9)
34         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
35         || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
36         IUnknown_AddRef(iface);
37         *ppobj = This;
38         return D3D_OK;
39     }
40
41     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42     return E_NOINTERFACE;
43 }
44
45 ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
46     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
47     ULONG ref = InterlockedIncrement(&This->ref);
48
49     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
50
51     return ref;
52 }
53
54 ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
55     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
56     ULONG ref = InterlockedDecrement(&This->ref);
57
58     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
59
60     if (ref == 0) {
61         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
62         IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
63         HeapFree(GetProcessHeap(), 0, This);
64     }
65     return ref;
66 }
67
68 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
69 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
70     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
71     TRACE("(%p) Relay\n" , This);
72     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
73 }
74
75 HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
76     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
77     TRACE("(%p) Relay\n", This);
78     return IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
79 }
80
81 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
82     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
83     TRACE("(%p) Relay\n", This);
84     return IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
85 }
86
87 HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
88     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
89     TRACE("(%p) Relay\n", This);
90     return IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
91 }
92
93 DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
94     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
95     TRACE("(%p) Relay\n", This);
96     return IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
97 }
98
99 DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
100     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
101     TRACE("(%p) Relay\n", This);
102     return IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
103 }
104
105 void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
106     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
107     TRACE("(%p) Relay\n", This);
108     return IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
109 }
110
111 D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
112     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
113     TRACE("(%p) Relay\n", This);
114     return IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
115 }
116
117 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
118 DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
119     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
120     TRACE("(%p) Relay\n", This);
121     return IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
122 }
123
124 DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
125     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
126     TRACE("(%p) Relay\n", This);
127     return IDirect3DBaseTexture9Impl_GetLOD((LPDIRECT3DBASETEXTURE9) This);
128 }
129
130 DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
131     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
132     TRACE("(%p) Relay\n", This);
133     return IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
134 }
135
136 HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
137     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
138     TRACE("(%p) Relay\n", This);
139     return IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, FilterType);
140 }
141
142 D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
143     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
144     TRACE("(%p) Relay\n", This);
145     return IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
146 }
147
148 void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
149     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
150     TRACE("(%p) Relay\n", This);
151     return IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
152 }
153
154 /* IDirect3DCubeTexture9 Interface follow: */
155 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
156     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
157     WINED3DSURFACE_DESC    wined3ddesc;
158     UINT                   tmpInt = -1;
159
160     TRACE("(%p) Relay\n", This);
161
162     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
163     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
164     wined3ddesc.Type                = &pDesc->Type;
165     wined3ddesc.Usage               = &pDesc->Usage;
166     wined3ddesc.Pool                = &pDesc->Pool;
167     wined3ddesc.Size                = &tmpInt;
168     wined3ddesc.MultiSampleType     = &pDesc->MultiSampleType;
169     wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
170     wined3ddesc.Width               = &pDesc->Width;
171     wined3ddesc.Height              = &pDesc->Height;
172
173     return IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
174 }
175
176 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
177     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
178     HRESULT hrc = D3D_OK;
179     IWineD3DSurface *mySurface = NULL;
180
181     TRACE("(%p) Relay\n", This);
182
183     hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, FaceType, Level, &mySurface);
184     if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
185        IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
186        IWineD3DCubeTexture_Release(mySurface);
187     }
188     return hrc;
189 }
190
191 HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
192     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
193     TRACE("(%p) Relay\n", This);
194     return IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, FaceType, Level, pLockedRect, pRect, Flags);
195 }
196
197 HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
198     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
199     TRACE("(%p) Relay\n", This);
200     return IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, FaceType, Level);
201 }
202
203 HRESULT  WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
204     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
205     TRACE("(%p) Relay\n", This);
206     return IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, FaceType, pDirtyRect);
207 }
208
209
210 const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
211 {
212     /* IUnknown */
213     IDirect3DCubeTexture9Impl_QueryInterface,
214     IDirect3DCubeTexture9Impl_AddRef,
215     IDirect3DCubeTexture9Impl_Release,
216     /* IDirect3DResource9 */
217     IDirect3DCubeTexture9Impl_GetDevice,
218     IDirect3DCubeTexture9Impl_SetPrivateData,
219     IDirect3DCubeTexture9Impl_GetPrivateData,
220     IDirect3DCubeTexture9Impl_FreePrivateData,
221     IDirect3DCubeTexture9Impl_SetPriority,
222     IDirect3DCubeTexture9Impl_GetPriority,
223     IDirect3DCubeTexture9Impl_PreLoad,
224     IDirect3DCubeTexture9Impl_GetType,
225     /* IDirect3DBaseTexture9 */
226     IDirect3DCubeTexture9Impl_SetLOD,
227     IDirect3DCubeTexture9Impl_GetLOD,
228     IDirect3DCubeTexture9Impl_GetLevelCount,
229     IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
230     IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
231     IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
232     IDirect3DCubeTexture9Impl_GetLevelDesc,
233     IDirect3DCubeTexture9Impl_GetCubeMapSurface,
234     IDirect3DCubeTexture9Impl_LockRect,
235     IDirect3DCubeTexture9Impl_UnlockRect,
236     IDirect3DCubeTexture9Impl_AddDirtyRect
237 };
238
239
240
241
242 /* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
243 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9 iface,
244                                                         UINT EdgeLength, UINT Levels, DWORD Usage,
245                                                         D3DFORMAT Format, D3DPOOL Pool,
246                                                         IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
247
248     IDirect3DCubeTexture9Impl *object;
249     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
250     HRESULT hr = D3D_OK;
251
252     TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%ld) fmt(%u), Pool(%d)  Shared(%p)" , This, EdgeLength, Levels, Usage, Format, Pool, pSharedHandle);
253
254     /* Allocate the storage for the device */
255     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
256
257     if (NULL == object) {
258         FIXME("(%p) allocation of CubeTexture failed\n", This);
259         return D3DERR_OUTOFVIDEOMEMORY;
260     }
261     object->lpVtbl = &Direct3DCubeTexture9_Vtbl;
262     object->ref = 1;
263     hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage,
264                                  (WINED3DFORMAT)Format, Pool, &object->wineD3DCubeTexture, pSharedHandle, (IUnknown*)object,
265                                  D3D9CB_CreateSurface);
266
267     if (hr != D3D_OK){
268
269         /* free up object */
270         FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
271         HeapFree(GetProcessHeap(), 0, object);
272     } else {
273         *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
274         TRACE("(%p) : Created cube texture %p\n", This, object);
275     }
276
277     TRACE("(%p) returning %p\n",This, *ppCubeTexture);
278     return hr;
279 }