2 * IDirect3DTexture9 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
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 /* IDirect3DTexture9 IUnknown parts follow: */
29 HRESULT WINAPI IDirect3DTexture9Impl_QueryInterface(LPDIRECT3DTEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
30 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource9)
34 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
35 || IsEqualGUID(riid, &IID_IDirect3DTexture9)) {
36 IUnknown_AddRef(iface);
41 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
45 ULONG WINAPI IDirect3DTexture9Impl_AddRef(LPDIRECT3DTEXTURE9 iface) {
46 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
54 ULONG WINAPI IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface) {
55 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
56 ULONG ref = InterlockedDecrement(&This->ref);
58 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
61 IWineD3DTexture_Release(This->wineD3DTexture);
62 HeapFree(GetProcessHeap(), 0, This);
67 /* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
68 HRESULT WINAPI IDirect3DTexture9Impl_GetDevice(LPDIRECT3DTEXTURE9 iface, IDirect3DDevice9** ppDevice) {
69 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
70 TRACE("(%p) Relay\n", This);
71 return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
74 HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
75 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
76 TRACE("(%p) Relay\n", This);
77 return IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
80 HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
81 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
82 TRACE("(%p) Relay\n", This);
83 return IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
86 HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid) {
87 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
88 TRACE("(%p) Relay\n", This);
89 return IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
92 DWORD WINAPI IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface, DWORD PriorityNew) {
93 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
94 TRACE("(%p) Relay\n", This);
95 return IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
98 DWORD WINAPI IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface) {
99 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
100 TRACE("(%p) Relay\n", This);
101 return IWineD3DTexture_GetPriority(This->wineD3DTexture);
104 void WINAPI IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface) {
105 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
106 TRACE("(%p) Relay\n", This);
107 return IWineD3DTexture_PreLoad(This->wineD3DTexture);
110 D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface) {
111 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
112 TRACE("(%p) Relay\n", This);
113 return IWineD3DTexture_GetType(This->wineD3DTexture);
116 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
117 DWORD WINAPI IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface, DWORD LODNew) {
118 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
119 TRACE("(%p) Relay\n", This);
120 return IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
123 DWORD WINAPI IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface) {
124 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
125 TRACE("(%p) Relay\n", This);
126 return IWineD3DTexture_GetLOD(This->wineD3DTexture);
129 DWORD WINAPI IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface) {
130 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
131 TRACE("(%p) Relay\n", This);
132 return IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
135 HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
136 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
137 TRACE("(%p) Relay\n", This);
138 return IWineD3DTexture_SetAutoGenFilterType(This->wineD3DTexture, FilterType);
141 D3DTEXTUREFILTERTYPE WINAPI IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface) {
142 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
143 TRACE("(%p) Relay\n", This);
144 return IWineD3DTexture_GetAutoGenFilterType(This->wineD3DTexture);
147 void WINAPI IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) {
148 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
149 TRACE("(%p) Relay\n", This);
150 return IWineD3DTexture_GenerateMipSubLevels(This->wineD3DTexture);
153 /* IDirect3DTexture9 Interface follow: */
154 HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
155 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
157 WINED3DSURFACE_DESC wined3ddesc;
159 TRACE("(%p) Relay\n", This);
161 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
162 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
163 wined3ddesc.Type = &pDesc->Type;
164 wined3ddesc.Usage = &pDesc->Usage;
165 wined3ddesc.Pool = &pDesc->Pool;
166 wined3ddesc.Size = &tmpInt; /* required for d3d8 */
167 wined3ddesc.MultiSampleType = &pDesc->MultiSampleType;
168 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
169 wined3ddesc.Width = &pDesc->Width;
170 wined3ddesc.Height = &pDesc->Height;
172 return IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
175 HRESULT WINAPI IDirect3DTexture9Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
176 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
177 HRESULT hrc = D3D_OK;
178 IWineD3DSurface *mySurface = NULL;
180 TRACE("(%p) Relay\n", This);
181 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
182 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
183 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
184 IWineD3DSurface_Release(mySurface);
189 HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
190 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
191 TRACE("(%p) Relay\n", This);
192 return IWineD3DTexture_LockRect(This->wineD3DTexture, Level, pLockedRect, pRect, Flags);
195 HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
196 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
197 TRACE("(%p) Relay\n", This);
198 return IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
201 HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
202 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
203 TRACE("(%p) Relay\n", This);
204 return IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
207 const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl =
209 IDirect3DTexture9Impl_QueryInterface,
210 IDirect3DTexture9Impl_AddRef,
211 IDirect3DTexture9Impl_Release,
212 IDirect3DTexture9Impl_GetDevice,
213 IDirect3DTexture9Impl_SetPrivateData,
214 IDirect3DTexture9Impl_GetPrivateData,
215 IDirect3DTexture9Impl_FreePrivateData,
216 IDirect3DTexture9Impl_SetPriority,
217 IDirect3DTexture9Impl_GetPriority,
218 IDirect3DTexture9Impl_PreLoad,
219 IDirect3DTexture9Impl_GetType,
221 IDirect3DTexture9Impl_SetLOD,
222 IDirect3DTexture9Impl_GetLOD,
223 IDirect3DTexture9Impl_GetLevelCount,
224 IDirect3DTexture9Impl_SetAutoGenFilterType,
225 IDirect3DTexture9Impl_GetAutoGenFilterType,
226 IDirect3DTexture9Impl_GenerateMipSubLevels,
227 IDirect3DTexture9Impl_GetLevelDesc,
228 IDirect3DTexture9Impl_GetSurfaceLevel,
229 IDirect3DTexture9Impl_LockRect,
230 IDirect3DTexture9Impl_UnlockRect,
231 IDirect3DTexture9Impl_AddDirtyRect
235 /* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
236 HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
237 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
238 IDirect3DTexture9Impl *object;
239 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
240 HRESULT hrc = D3D_OK;
242 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%ld), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
244 /* Allocate the storage for the device */
245 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture9Impl));
247 if (NULL == object) {
248 FIXME("Allocation of memory failed\n");
250 return D3DERR_OUTOFVIDEOMEMORY;
253 object->lpVtbl = &Direct3DTexture9_Vtbl;
255 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage,
256 (WINED3DFORMAT)Format, Pool, &object->wineD3DTexture, pSharedHandle, (IUnknown *)object, D3D9CB_CreateSurface);
260 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
261 HeapFree(GetProcessHeap(), 0, object);
264 *ppTexture= (LPDIRECT3DTEXTURE9) object;
267 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);