Use strdup, implement MsiDatabaseImportA.
[wine] / dlls / d3d8 / texture.c
1 /*
2  * IDirect3DTexture8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "wine/debug.h"
30
31 #include "d3d8_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34
35 /* IDirect3DTexture8 IUnknown parts follow: */
36 HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj)
37 {
38     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
39     TRACE("(%p) : QueryInterface for %s\n", This, debugstr_guid(riid));
40     if (IsEqualGUID(riid, &IID_IUnknown)
41         || IsEqualGUID(riid, &IID_IDirect3DResource8)
42         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
43         || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
44         IDirect3DTexture8Impl_AddRef(iface);
45         *ppobj = This;
46         return D3D_OK;
47     }
48
49     WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
50     return E_NOINTERFACE;
51 }
52
53 ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
54     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
55     ULONG ref = InterlockedIncrement(&This->ref);
56
57     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
58
59     return ref;
60 }
61
62 ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
63     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
64     ULONG ref = InterlockedDecrement(&This->ref);
65     unsigned int i;
66
67     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
68
69     if (ref == 0) {
70         for (i = 0; i < This->levels; i++) {
71             if (This->surfaces[i] != NULL) {
72                 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[i]);
73                 IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) This->surfaces[i]);
74             }
75         }
76         HeapFree(GetProcessHeap(), 0, This);
77     }
78     return ref;
79 }
80
81 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
82 HRESULT  WINAPI        IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8** ppDevice) {
83     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
84     TRACE("(%p) : returning %p\n", This, This->Device);
85     *ppDevice = (LPDIRECT3DDEVICE8) This->Device; 
86     /**
87      * Note  Calling this method will increase the internal reference count 
88      * on the IDirect3DDevice8 interface. 
89      */
90     IDirect3DDevice8Impl_AddRef(*ppDevice);
91     return D3D_OK;
92 }
93 HRESULT  WINAPI        IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
94     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
95     FIXME("(%p) : stub\n", This);    return D3D_OK;
96 }
97 HRESULT  WINAPI        IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
98     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
99     FIXME("(%p) : stub\n", This);    return D3D_OK;
100 }
101 HRESULT  WINAPI        IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
102     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
103     FIXME("(%p) : stub\n", This);    return D3D_OK;
104 }
105 DWORD    WINAPI        IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
106     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
107     FIXME("(%p) : stub\n", This);
108     return 0;
109 }
110 DWORD    WINAPI        IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
111     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
112     FIXME("(%p) : stub\n", This);
113     return 0;
114 }
115 void     WINAPI        IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
116     unsigned int i;
117     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
118     TRACE("(%p) : About to load texture\n", This);
119
120     ENTER_GL();
121
122     for (i = 0; i < This->levels; i++) {
123       if (i == 0 && This->surfaces[i]->textureName != 0 && This->Dirty == FALSE) {
124         glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
125         checkGLcall("glBindTexture");
126         TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
127         /* No need to walk through all mip-map levels, since already all assigned */
128         i = This->levels;
129
130       } else {
131         if (i == 0) {
132           if (This->surfaces[i]->textureName == 0) {
133             glGenTextures(1, &This->surfaces[i]->textureName);
134             checkGLcall("glGenTextures");
135             TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
136           }
137           
138           glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
139           checkGLcall("glBindTexture");
140         }
141         IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8) This->surfaces[i], GL_TEXTURE_2D, i); 
142       }
143     }
144
145     /* No longer dirty */
146     This->Dirty = FALSE;
147
148     /* Always need to reset the number of mipmap levels when rebinding as it is
149        a property of the active texture unit, and another texture may have set it
150        to a different value                                                       */
151     TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);   
152     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels - 1);
153     checkGLcall("glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels)");
154
155     LEAVE_GL();
156
157     return ;
158 }
159 D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
160     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
161     TRACE("(%p) : is %d \n", This, This->ResourceType);
162     return This->ResourceType;
163 }
164
165 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
166 DWORD    WINAPI        IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
167     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
168     FIXME("(%p) : stub\n", This);
169     return 0;
170 }
171 DWORD    WINAPI        IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
172     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
173     FIXME("(%p) : stub\n", This);
174     return 0;
175 }
176 DWORD    WINAPI        IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
177     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
178     TRACE("(%p) : returning %d\n", This, This->levels);
179     return This->levels;
180 }
181
182 /* IDirect3DTexture8 */
183 HRESULT  WINAPI        IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
184     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
185
186     if (Level < This->levels) {
187         TRACE("(%p) Level (%d)\n", This, Level);
188         return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8) This->surfaces[Level], pDesc);
189     }
190     FIXME("Levels seems too high?!!\n");
191     return D3DERR_INVALIDCALL;
192 }
193 HRESULT  WINAPI        IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8** ppSurfaceLevel) {
194     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
195     *ppSurfaceLevel = (LPDIRECT3DSURFACE8)This->surfaces[Level];
196     IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) This->surfaces[Level]);
197     TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
198     return D3D_OK;
199 }
200 HRESULT  WINAPI        IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) {
201     HRESULT hr;
202     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
203     TRACE("(%p) Level (%d)\n", This, Level);
204     if (Level < This->levels) {
205         /**
206          * Not dirtified while Surfaces don't notify dirtification
207          * This->Dirty = TRUE;
208          */
209         hr = IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->surfaces[Level], pLockedRect, pRect, Flags);
210         TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
211     } else {
212         FIXME("Levels seems too high?!!\n");
213         return D3DERR_INVALIDCALL;
214     }
215     return hr;
216 }
217 HRESULT  WINAPI        IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
218     HRESULT hr;
219     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
220     TRACE("(%p) Level (%d)\n", This, Level);
221     if (Level < This->levels) {
222         hr = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) This->surfaces[Level]);
223         TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
224     } else {
225         FIXME("Levels seems too high?!!\n");
226         return D3DERR_INVALIDCALL;
227     }
228     return hr;
229 }
230 HRESULT  WINAPI        IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT* pDirtyRect) {
231     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
232     This->Dirty = TRUE;
233     TRACE("(%p) : dirtyfication of surface Level (0)\n", This);    
234     return IDirect3DSurface8Impl_AddDirtyRect((LPDIRECT3DSURFACE8) This->surfaces[0], pDirtyRect);
235 }
236
237
238 IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
239 {
240     IDirect3DTexture8Impl_QueryInterface,
241     IDirect3DTexture8Impl_AddRef,
242     IDirect3DTexture8Impl_Release,
243     IDirect3DTexture8Impl_GetDevice,
244     IDirect3DTexture8Impl_SetPrivateData,
245     IDirect3DTexture8Impl_GetPrivateData,
246     IDirect3DTexture8Impl_FreePrivateData,
247     IDirect3DTexture8Impl_SetPriority,
248     IDirect3DTexture8Impl_GetPriority,
249     IDirect3DTexture8Impl_PreLoad,
250     IDirect3DTexture8Impl_GetType,
251     IDirect3DTexture8Impl_SetLOD,
252     IDirect3DTexture8Impl_GetLOD,
253     IDirect3DTexture8Impl_GetLevelCount,
254     IDirect3DTexture8Impl_GetLevelDesc,
255     IDirect3DTexture8Impl_GetSurfaceLevel,
256     IDirect3DTexture8Impl_LockRect,
257     IDirect3DTexture8Impl_UnlockRect,
258     IDirect3DTexture8Impl_AddDirtyRect
259
260 };