Fixed buffer overflow.
[wine/multimedia.git] / dlls / d3d9 / cubetexture.c
blob9d02edaae2eae9a2d737046d6393524e3aca4861
1 /*
2 * IDirect3DCubeTexture9 implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
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.
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.
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
22 #include "config.h"
24 #include <stdarg.h>
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "wingdi.h"
32 #include "wine/debug.h"
34 #include "d3d9_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
38 /* IDirect3DCubeTexture9 IUnknown parts follow: */
39 HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
40 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
42 if (IsEqualGUID(riid, &IID_IUnknown)
43 || IsEqualGUID(riid, &IID_IDirect3DResource9)
44 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
45 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
46 IDirect3DCubeTexture9Impl_AddRef(iface);
47 *ppobj = This;
48 return D3D_OK;
51 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
52 return E_NOINTERFACE;
55 ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
56 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
57 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
58 return ++(This->ref);
61 ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
62 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
63 ULONG ref = --This->ref;
64 int i;
65 int j;
67 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
68 if (ref == 0) {
69 for (i = 0; i < This->levels; i++) {
70 for (j = 0; j < 6; j++) {
71 if (This->surfaces[j][i] != NULL) {
72 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[j][i]);
73 IDirect3DSurface9Impl_Release((LPDIRECT3DSURFACE9) This->surfaces[j][i]);
77 HeapFree(GetProcessHeap(), 0, This);
79 return ref;
82 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
83 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
84 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
85 return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
88 HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
89 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
90 FIXME("(%p) : stub\n", This);
91 return D3D_OK;
94 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
95 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
96 FIXME("(%p) : stub\n", This);
97 return D3D_OK;
100 HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
101 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
102 FIXME("(%p) : stub\n", This);
103 return D3D_OK;
106 DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
107 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
108 return IDirect3DResource9Impl_SetPriority((LPDIRECT3DRESOURCE9) This, PriorityNew);
111 DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
112 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
113 return IDirect3DResource9Impl_GetPriority((LPDIRECT3DRESOURCE9) This);
116 void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
117 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
118 FIXME("(%p) : stub\n", This);
119 return ;
122 D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
123 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
124 return IDirect3DResource9Impl_GetType((LPDIRECT3DRESOURCE9) This);
127 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
128 DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
129 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
130 return IDirect3DBaseTexture9Impl_SetLOD((LPDIRECT3DBASETEXTURE9) This, LODNew);
133 DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
134 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
135 return IDirect3DBaseTexture9Impl_GetLOD((LPDIRECT3DBASETEXTURE9) This);
138 DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
139 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
140 return IDirect3DBaseTexture9Impl_GetLevelCount((LPDIRECT3DBASETEXTURE9) This);
143 HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
144 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
145 return IDirect3DBaseTexture9Impl_SetAutoGenFilterType((LPDIRECT3DBASETEXTURE9) This, FilterType);
148 D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
149 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
150 return IDirect3DBaseTexture9Impl_GetAutoGenFilterType((LPDIRECT3DBASETEXTURE9) This);
153 void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
154 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
155 FIXME("(%p) : stub\n", This);
156 return ;
159 /* IDirect3DCubeTexture9 Interface follow: */
160 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
161 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
162 if (Level < This->levels) {
163 TRACE("(%p) level (%d)\n", This, Level);
164 return IDirect3DSurface9Impl_GetDesc((LPDIRECT3DSURFACE9) This->surfaces[0][Level], pDesc);
165 } else {
166 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
167 return D3DERR_INVALIDCALL;
169 return D3D_OK;
172 HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
173 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
174 if (Level < This->levels) {
175 *ppCubeMapSurface = (LPDIRECT3DSURFACE9) This->surfaces[FaceType][Level];
176 IDirect3DSurface9Impl_AddRef((LPDIRECT3DSURFACE9) *ppCubeMapSurface);
177 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
178 } else {
179 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
180 return D3DERR_INVALIDCALL;
182 return D3D_OK;
185 HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
186 HRESULT hr;
187 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
188 if (Level < This->levels) {
190 * Not dirtified while Surfaces don't notify dirtification
191 * This->Dirty = TRUE;
193 hr = IDirect3DSurface9Impl_LockRect((LPDIRECT3DSURFACE9) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
194 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
195 } else {
196 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
197 return D3DERR_INVALIDCALL;
199 return hr;
202 HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
203 HRESULT hr;
204 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
205 if (Level < This->levels) {
206 hr = IDirect3DSurface9Impl_UnlockRect((LPDIRECT3DSURFACE9) This->surfaces[FaceType][Level]);
207 TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
208 } else {
209 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
210 return D3DERR_INVALIDCALL;
212 return hr;
215 HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
216 ICOM_THIS(IDirect3DCubeTexture9Impl,iface);
217 FIXME("(%p) : stub\n", This);
218 This->Dirty = TRUE;
219 return D3D_OK;
223 ICOM_VTABLE(IDirect3DCubeTexture9) Direct3DCubeTexture9_Vtbl =
225 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
226 IDirect3DCubeTexture9Impl_QueryInterface,
227 IDirect3DCubeTexture9Impl_AddRef,
228 IDirect3DCubeTexture9Impl_Release,
229 IDirect3DCubeTexture9Impl_GetDevice,
230 IDirect3DCubeTexture9Impl_SetPrivateData,
231 IDirect3DCubeTexture9Impl_GetPrivateData,
232 IDirect3DCubeTexture9Impl_FreePrivateData,
233 IDirect3DCubeTexture9Impl_SetPriority,
234 IDirect3DCubeTexture9Impl_GetPriority,
235 IDirect3DCubeTexture9Impl_PreLoad,
236 IDirect3DCubeTexture9Impl_GetType,
237 IDirect3DCubeTexture9Impl_SetLOD,
238 IDirect3DCubeTexture9Impl_GetLOD,
239 IDirect3DCubeTexture9Impl_GetLevelCount,
240 IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
241 IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
242 IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
243 IDirect3DCubeTexture9Impl_GetLevelDesc,
244 IDirect3DCubeTexture9Impl_GetCubeMapSurface,
245 IDirect3DCubeTexture9Impl_LockRect,
246 IDirect3DCubeTexture9Impl_UnlockRect,
247 IDirect3DCubeTexture9Impl_AddDirtyRect
251 /* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
252 HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9 iface,
253 UINT EdgeLength, UINT Levels, DWORD Usage,
254 D3DFORMAT Format, D3DPOOL Pool,
255 IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
257 ICOM_THIS(IDirect3DDevice9Impl,iface);
258 FIXME("(%p) : stub\n", This);
259 return D3D_OK;