Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / wined3d / cubetexture.c
bloba01dd99ee6124cb7a2594f5fe3fe8c0f508821bb
1 /*
2 * IWineD3DCubeTexture implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
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.
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.
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
23 #include "config.h"
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
29 static const GLenum cube_targets[6] = {
30 #if defined(GL_VERSION_1_3)
31 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
32 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
33 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
34 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
35 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
36 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
37 #else
38 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
39 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
40 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
41 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
42 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
43 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
44 #endif
47 /* *******************************************
48 IWineD3DCubeTexture IUnknown parts follow
49 ******************************************* */
50 HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DCubeTexture *iface, REFIID riid, LPVOID *ppobj)
52 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
53 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
54 if (IsEqualGUID(riid, &IID_IUnknown)
55 || IsEqualGUID(riid, &IID_IWineD3DResource)
56 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
57 || IsEqualGUID(riid, &IID_IWineD3DTexture)) {
58 IUnknown_AddRef(iface);
59 *ppobj = This;
60 return D3D_OK;
62 return E_NOINTERFACE;
65 ULONG WINAPI IWineD3DCubeTextureImpl_AddRef(IWineD3DCubeTexture *iface) {
66 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
67 TRACE("(%p) : AddRef increasing from %ld\n", This, This->resource.ref);
68 IUnknown_AddRef(This->resource.parent);
69 return InterlockedIncrement(&This->resource.ref);
72 ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DCubeTexture *iface) {
73 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
74 ULONG ref;
75 TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
76 ref = InterlockedDecrement(&This->resource.ref);
77 if (ref == 0) {
78 int i,j;
79 for (i = 0; i < This->baseTexture.levels; i++) {
80 for (j = 0; j < 6; j++) {
81 if (This->surfaces[j][i] != NULL) {
82 TRACE("(%p) : Releasing surface%d %d %p\n", This, j, i, This->surfaces[j][i]);
83 IWineD3DSurface_Release((IWineD3DSurface *) This->surfaces[j][i]);
87 IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *) iface);
88 HeapFree(GetProcessHeap(), 0, This);
89 } else {
90 IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx object */
92 return ref;
95 /* ****************************************************
96 IWineD3DCubeTexture IWineD3DResource parts follow
97 **************************************************** */
98 HRESULT WINAPI IWineD3DCubeTextureImpl_GetDevice(IWineD3DCubeTexture *iface, IWineD3DDevice** ppDevice) {
99 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
102 HRESULT WINAPI IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
103 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
106 HRESULT WINAPI IWineD3DCubeTextureImpl_GetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
107 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
110 HRESULT WINAPI IWineD3DCubeTextureImpl_FreePrivateData(IWineD3DCubeTexture *iface, REFGUID refguid) {
111 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
114 DWORD WINAPI IWineD3DCubeTextureImpl_SetPriority(IWineD3DCubeTexture *iface, DWORD PriorityNew) {
115 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
118 DWORD WINAPI IWineD3DCubeTextureImpl_GetPriority(IWineD3DCubeTexture *iface) {
119 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
122 void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
123 /* Override the IWineD3DResource Preload method */
124 unsigned int i,j;
125 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
127 TRACE("(%p) : About to load texture: dirtified(%d)\n", This, This->baseTexture.dirty);
129 IWineD3DCubeTexture_BindTexture(iface);
131 ENTER_GL();
132 /* If were dirty then reload the surfaces */
133 if(This->baseTexture.dirty != FALSE) {
134 for (i = 0; i < This->baseTexture.levels; i++) {
135 for (j = 0; j < 6; j++)
136 IWineD3DSurface_LoadTexture((IWineD3DSurface *) This->surfaces[j][i], cube_targets[j], i);
138 /* No longer dirty */
139 This->baseTexture.dirty = FALSE;
141 LEAVE_GL();
142 return ;
145 D3DRESOURCETYPE WINAPI IWineD3DCubeTextureImpl_GetType(IWineD3DCubeTexture *iface) {
146 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
149 HRESULT WINAPI IWineD3DCubeTextureImpl_GetParent(IWineD3DCubeTexture *iface, IUnknown **pParent) {
150 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
153 /* ******************************************************
154 IWineD3DCubeTexture IWineD3DBaseTexture parts follow
155 ****************************************************** */
156 DWORD WINAPI IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture *iface, DWORD LODNew) {
157 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
160 DWORD WINAPI IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture *iface) {
161 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
164 DWORD WINAPI IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture *iface) {
165 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
168 HRESULT WINAPI IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
169 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
172 D3DTEXTUREFILTERTYPE WINAPI IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture *iface) {
173 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
176 void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface) {
177 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
180 /* Internal function, No d3d mapping */
181 BOOL WINAPI IWineD3DCubeTextureImpl_SetDirty(IWineD3DCubeTexture *iface, BOOL dirty) {
182 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
185 /* Internal function, No d3d mapping */
186 BOOL WINAPI IWineD3DCubeTextureImpl_GetDirty(IWineD3DCubeTexture *iface) {
187 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
190 HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *iface) {
191 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
192 TRACE("(%p) : relay to BaseTexture \n", This);
193 return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
196 HRESULT WINAPI IWineD3DCubeTextureImpl_UnBindTexture(IWineD3DCubeTexture *iface) {
197 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
198 TRACE("(%p) : relay to BaseTexture \n", This);
199 return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
202 UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface){
203 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
204 TRACE("(%p) \n", This);
206 return GLTEXTURECUBEMAP;
209 /* *******************************************
210 IWineD3DCubeTexture IWineD3DCubeTexture parts follow
211 ******************************************* */
212 HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
213 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
215 if (Level < This->baseTexture.levels) {
216 TRACE("(%p) level (%d)\n", This, Level);
217 return IWineD3DSurface_GetDesc((IWineD3DSurface *) This->surfaces[0][Level], pDesc);
219 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
220 return D3DERR_INVALIDCALL;
223 HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) {
224 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
225 if (Level < This->baseTexture.levels) {
226 *ppCubeMapSurface = (IWineD3DSurface *) This->surfaces[FaceType][Level];
227 IWineD3DSurface_AddRef((IWineD3DSurface *) *ppCubeMapSurface);
228 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
229 } else {
230 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
231 return D3DERR_INVALIDCALL;
233 return D3D_OK;
236 HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
237 HRESULT hr;
238 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
240 if (Level < This->baseTexture.levels) {
241 hr = IWineD3DSurface_LockRect((IWineD3DSurface *) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
242 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
243 } else {
244 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
245 return D3DERR_INVALIDCALL;
247 return hr;
250 HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
251 HRESULT hr;
252 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
254 if (Level < This->baseTexture.levels) {
255 hr = IWineD3DSurface_UnlockRect((IWineD3DSurface *) This->surfaces[FaceType][Level]);
256 TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
257 } else {
258 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
259 return D3DERR_INVALIDCALL;
261 return hr;
264 HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
265 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
266 This->baseTexture.dirty = TRUE;
267 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
268 return IWineD3DSurface_AddDirtyRect((IWineD3DSurface *) This->surfaces[FaceType][0], pDirtyRect);
272 IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
274 /* IUnknown */
275 IWineD3DCubeTextureImpl_QueryInterface,
276 IWineD3DCubeTextureImpl_AddRef,
277 IWineD3DCubeTextureImpl_Release,
278 /* IWineD3DResource */
279 IWineD3DCubeTextureImpl_GetParent,
280 IWineD3DCubeTextureImpl_GetDevice,
281 IWineD3DCubeTextureImpl_SetPrivateData,
282 IWineD3DCubeTextureImpl_GetPrivateData,
283 IWineD3DCubeTextureImpl_FreePrivateData,
284 IWineD3DCubeTextureImpl_SetPriority,
285 IWineD3DCubeTextureImpl_GetPriority,
286 IWineD3DCubeTextureImpl_PreLoad,
287 IWineD3DCubeTextureImpl_GetType,
288 /*base texture */
289 IWineD3DCubeTextureImpl_SetLOD,
290 IWineD3DCubeTextureImpl_GetLOD,
291 IWineD3DCubeTextureImpl_GetLevelCount,
292 IWineD3DCubeTextureImpl_SetAutoGenFilterType,
293 IWineD3DCubeTextureImpl_GetAutoGenFilterType,
294 IWineD3DCubeTextureImpl_GenerateMipSubLevels,
295 IWineD3DCubeTextureImpl_SetDirty,
296 IWineD3DCubeTextureImpl_GetDirty,
297 IWineD3DCubeTextureImpl_BindTexture,
298 IWineD3DCubeTextureImpl_UnBindTexture,
299 IWineD3DCubeTextureImpl_GetTextureDimensions,
300 /* cube texture */
301 IWineD3DCubeTextureImpl_GetLevelDesc,
302 IWineD3DCubeTextureImpl_GetCubeMapSurface,
303 IWineD3DCubeTextureImpl_LockRect,
304 IWineD3DCubeTextureImpl_UnlockRect,
305 IWineD3DCubeTextureImpl_AddDirtyRect