1 | /*
|
---|
2 | * IWineD3DCubeTexture implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2005 Jason Edmeades
|
---|
5 | * Copyright 2002-2005 Raphael Junqueira
|
---|
6 | * Copyright 2005 Oliver Stieber
|
---|
7 | * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
---|
8 | * Copyright 2009 Henri Verbeet for CodeWeavers
|
---|
9 | *
|
---|
10 | * This library is free software; you can redistribute it and/or
|
---|
11 | * modify it under the terms of the GNU Lesser General Public
|
---|
12 | * License as published by the Free Software Foundation; either
|
---|
13 | * version 2.1 of the License, or (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This library is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | * Lesser General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU Lesser General Public
|
---|
21 | * License along with this library; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
23 | */
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
27 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
28 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
29 | * a choice of LGPL license versions is made available with the language indicating
|
---|
30 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
31 | * of the LGPL is applied is otherwise unspecified.
|
---|
32 | */
|
---|
33 |
|
---|
34 | #include "config.h"
|
---|
35 | #include "wined3d_private.h"
|
---|
36 |
|
---|
37 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
---|
38 |
|
---|
39 | static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
|
---|
40 | {
|
---|
41 | /* Override the IWineD3DResource Preload method. */
|
---|
42 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
43 | IWineD3DDeviceImpl *device = This->resource.device;
|
---|
44 | struct wined3d_context *context = NULL;
|
---|
45 | unsigned int i, j;
|
---|
46 | BOOL srgb_mode;
|
---|
47 | BOOL *dirty;
|
---|
48 |
|
---|
49 | switch (srgb)
|
---|
50 | {
|
---|
51 | case SRGB_RGB:
|
---|
52 | srgb_mode = FALSE;
|
---|
53 | break;
|
---|
54 |
|
---|
55 | case SRGB_BOTH:
|
---|
56 | cubetexture_internal_preload(iface, SRGB_RGB);
|
---|
57 | /* Fallthrough */
|
---|
58 |
|
---|
59 | case SRGB_SRGB:
|
---|
60 | srgb_mode = TRUE;
|
---|
61 | break;
|
---|
62 |
|
---|
63 | default:
|
---|
64 | srgb_mode = This->baseTexture.is_srgb;
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | dirty = srgb_mode ? &This->baseTexture.texture_srgb.dirty : &This->baseTexture.texture_rgb.dirty;
|
---|
68 |
|
---|
69 | TRACE("(%p) : About to load texture: dirtified(%u).\n", This, *dirty);
|
---|
70 |
|
---|
71 | /* We only have to activate a context for gl when we're not drawing.
|
---|
72 | * In most cases PreLoad will be called during draw and a context was
|
---|
73 | * activated at the beginning of drawPrimitive. */
|
---|
74 | if (!device->isInDraw)
|
---|
75 | {
|
---|
76 | /* No danger of recursive calls, context_acquire() sets isInDraw to true
|
---|
77 | * when loading offscreen render targets into their texture. */
|
---|
78 | context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
|
---|
82 | || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
|
---|
83 | {
|
---|
84 | for (i = 0; i < This->baseTexture.levels; ++i)
|
---|
85 | {
|
---|
86 | for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j)
|
---|
87 | {
|
---|
88 | if (palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[j][i]))
|
---|
89 | {
|
---|
90 | TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
|
---|
91 | /* TODO: This is not necessarily needed with hw palettized texture support. */
|
---|
92 | IWineD3DSurface_LoadLocation(This->surfaces[j][i], SFLAG_INSYSMEM, NULL);
|
---|
93 | /* Make sure the texture is reloaded because of the palette change,
|
---|
94 | * this kills performance though :( */
|
---|
95 | IWineD3DSurface_ModifyLocation(This->surfaces[j][i], SFLAG_INTEXTURE, FALSE);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* If the texture is marked dirty or the srgb sampler setting has changed
|
---|
102 | * since the last load then reload the surfaces. */
|
---|
103 | if (*dirty)
|
---|
104 | {
|
---|
105 | for (i = 0; i < This->baseTexture.levels; ++i)
|
---|
106 | {
|
---|
107 | for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j)
|
---|
108 | {
|
---|
109 | IWineD3DSurface_LoadTexture(This->surfaces[j][i], srgb_mode);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 | else
|
---|
114 | {
|
---|
115 | TRACE("(%p) Texture not dirty, nothing to do.\n" , iface);
|
---|
116 | }
|
---|
117 |
|
---|
118 | /* No longer dirty. */
|
---|
119 | *dirty = FALSE;
|
---|
120 |
|
---|
121 | if (context) context_release(context);
|
---|
122 | }
|
---|
123 |
|
---|
124 | static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This)
|
---|
125 | {
|
---|
126 | unsigned int i, j;
|
---|
127 |
|
---|
128 | TRACE("(%p) : Cleaning up.\n", This);
|
---|
129 |
|
---|
130 | for (i = 0; i < This->baseTexture.levels; ++i)
|
---|
131 | {
|
---|
132 | for (j = 0; j < 6; ++j)
|
---|
133 | {
|
---|
134 | IWineD3DSurface *surface = This->surfaces[j][i];
|
---|
135 |
|
---|
136 | if (surface)
|
---|
137 | {
|
---|
138 | /* Clean out the texture name we gave to the surface so that the
|
---|
139 | * surface doesn't try and release it. */
|
---|
140 | surface_set_texture_name(surface, 0, TRUE);
|
---|
141 | surface_set_texture_name(surface, 0, FALSE);
|
---|
142 | surface_set_texture_target(surface, 0);
|
---|
143 | IWineD3DSurface_SetContainer(surface, NULL);
|
---|
144 | IWineD3DSurface_Release(surface);
|
---|
145 | }
|
---|
146 | }
|
---|
147 | }
|
---|
148 | basetexture_cleanup((IWineD3DBaseTexture *)This);
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* *******************************************
|
---|
152 | IWineD3DCubeTexture IUnknown parts follow
|
---|
153 | ******************************************* */
|
---|
154 |
|
---|
155 | static HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DCubeTexture *iface, REFIID riid, LPVOID *ppobj)
|
---|
156 | {
|
---|
157 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
158 | TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
---|
159 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
160 | || IsEqualGUID(riid, &IID_IWineD3DBase)
|
---|
161 | || IsEqualGUID(riid, &IID_IWineD3DResource)
|
---|
162 | || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
|
---|
163 | || IsEqualGUID(riid, &IID_IWineD3DCubeTexture)) {
|
---|
164 | IUnknown_AddRef(iface);
|
---|
165 | *ppobj = This;
|
---|
166 | return S_OK;
|
---|
167 | }
|
---|
168 | *ppobj = NULL;
|
---|
169 | return E_NOINTERFACE;
|
---|
170 | }
|
---|
171 |
|
---|
172 | static ULONG WINAPI IWineD3DCubeTextureImpl_AddRef(IWineD3DCubeTexture *iface) {
|
---|
173 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
174 | TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
|
---|
175 | return InterlockedIncrement(&This->resource.ref);
|
---|
176 | }
|
---|
177 |
|
---|
178 | static ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DCubeTexture *iface) {
|
---|
179 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
180 | ULONG ref;
|
---|
181 | TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
|
---|
182 | ref = InterlockedDecrement(&This->resource.ref);
|
---|
183 | if (!ref)
|
---|
184 | {
|
---|
185 | cubetexture_cleanup(This);
|
---|
186 | This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
|
---|
187 | HeapFree(GetProcessHeap(), 0, This);
|
---|
188 | }
|
---|
189 | return ref;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /* ****************************************************
|
---|
193 | IWineD3DCubeTexture IWineD3DResource parts follow
|
---|
194 | **************************************************** */
|
---|
195 | static HRESULT WINAPI IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
196 | return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
|
---|
197 | }
|
---|
198 |
|
---|
199 | static HRESULT WINAPI IWineD3DCubeTextureImpl_GetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
200 | return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
|
---|
201 | }
|
---|
202 |
|
---|
203 | static HRESULT WINAPI IWineD3DCubeTextureImpl_FreePrivateData(IWineD3DCubeTexture *iface, REFGUID refguid) {
|
---|
204 | return resource_free_private_data((IWineD3DResource *)iface, refguid);
|
---|
205 | }
|
---|
206 |
|
---|
207 | static DWORD WINAPI IWineD3DCubeTextureImpl_SetPriority(IWineD3DCubeTexture *iface, DWORD PriorityNew) {
|
---|
208 | return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
|
---|
209 | }
|
---|
210 |
|
---|
211 | static DWORD WINAPI IWineD3DCubeTextureImpl_GetPriority(IWineD3DCubeTexture *iface) {
|
---|
212 | return resource_get_priority((IWineD3DResource *)iface);
|
---|
213 | }
|
---|
214 |
|
---|
215 | static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
|
---|
216 | cubetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
|
---|
217 | }
|
---|
218 |
|
---|
219 | static void WINAPI IWineD3DCubeTextureImpl_UnLoad(IWineD3DCubeTexture *iface) {
|
---|
220 | unsigned int i, j;
|
---|
221 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
222 | TRACE("(%p)\n", This);
|
---|
223 |
|
---|
224 | /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
|
---|
225 | * surface before, this one will be a NOP and vice versa. Unloading an unloaded
|
---|
226 | * surface is fine
|
---|
227 | */
|
---|
228 | for (i = 0; i < This->baseTexture.levels; i++) {
|
---|
229 | for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) {
|
---|
230 | IWineD3DSurface_UnLoad(This->surfaces[j][i]);
|
---|
231 | surface_set_texture_name(This->surfaces[j][i], 0, TRUE);
|
---|
232 | surface_set_texture_name(This->surfaces[j][i], 0, FALSE);
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | basetexture_unload((IWineD3DBaseTexture *)iface);
|
---|
237 | }
|
---|
238 |
|
---|
239 | static WINED3DRESOURCETYPE WINAPI IWineD3DCubeTextureImpl_GetType(IWineD3DCubeTexture *iface) {
|
---|
240 | return resource_get_type((IWineD3DResource *)iface);
|
---|
241 | }
|
---|
242 |
|
---|
243 | static HRESULT WINAPI IWineD3DCubeTextureImpl_GetParent(IWineD3DCubeTexture *iface, IUnknown **pParent) {
|
---|
244 | return resource_get_parent((IWineD3DResource *)iface, pParent);
|
---|
245 | }
|
---|
246 |
|
---|
247 | /* ******************************************************
|
---|
248 | IWineD3DCubeTexture IWineD3DBaseTexture parts follow
|
---|
249 | ****************************************************** */
|
---|
250 | static DWORD WINAPI IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture *iface, DWORD LODNew) {
|
---|
251 | return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
|
---|
252 | }
|
---|
253 |
|
---|
254 | static DWORD WINAPI IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture *iface) {
|
---|
255 | return basetexture_get_lod((IWineD3DBaseTexture *)iface);
|
---|
256 | }
|
---|
257 |
|
---|
258 | static DWORD WINAPI IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture *iface) {
|
---|
259 | return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
|
---|
260 | }
|
---|
261 |
|
---|
262 | static HRESULT WINAPI IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
|
---|
263 | return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
|
---|
264 | }
|
---|
265 |
|
---|
266 | static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture *iface) {
|
---|
267 | return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
|
---|
268 | }
|
---|
269 |
|
---|
270 | static void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface) {
|
---|
271 | basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
|
---|
272 | }
|
---|
273 |
|
---|
274 | /* Internal function, No d3d mapping */
|
---|
275 | static BOOL WINAPI IWineD3DCubeTextureImpl_SetDirty(IWineD3DCubeTexture *iface, BOOL dirty) {
|
---|
276 | return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
|
---|
277 | }
|
---|
278 |
|
---|
279 | /* Internal function, No d3d mapping */
|
---|
280 | static BOOL WINAPI IWineD3DCubeTextureImpl_GetDirty(IWineD3DCubeTexture *iface) {
|
---|
281 | return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
|
---|
282 | }
|
---|
283 |
|
---|
284 | /* Context activation is done by the caller. */
|
---|
285 | static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *iface, BOOL srgb) {
|
---|
286 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
287 | BOOL set_gl_texture_desc;
|
---|
288 | HRESULT hr;
|
---|
289 |
|
---|
290 | TRACE("(%p) : relay to BaseTexture\n", This);
|
---|
291 |
|
---|
292 | hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
|
---|
293 | if (set_gl_texture_desc && SUCCEEDED(hr)) {
|
---|
294 | UINT i, j;
|
---|
295 | for (i = 0; i < This->baseTexture.levels; ++i) {
|
---|
296 | for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) {
|
---|
297 | if(This->baseTexture.is_srgb) {
|
---|
298 | surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_srgb.name, TRUE);
|
---|
299 | } else {
|
---|
300 | surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_rgb.name, FALSE);
|
---|
301 | }
|
---|
302 | }
|
---|
303 | }
|
---|
304 | }
|
---|
305 |
|
---|
306 | return hr;
|
---|
307 | }
|
---|
308 |
|
---|
309 | static UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface)
|
---|
310 | {
|
---|
311 | TRACE("iface %p.\n", iface);
|
---|
312 |
|
---|
313 | return GL_TEXTURE_CUBE_MAP_ARB;
|
---|
314 | }
|
---|
315 |
|
---|
316 | static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface)
|
---|
317 | {
|
---|
318 | TRACE("iface %p.\n", iface);
|
---|
319 |
|
---|
320 | return FALSE;
|
---|
321 | }
|
---|
322 |
|
---|
323 | /* *******************************************
|
---|
324 | IWineD3DCubeTexture IWineD3DCubeTexture parts follow
|
---|
325 | ******************************************* */
|
---|
326 | static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
|
---|
327 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
328 |
|
---|
329 | if (Level < This->baseTexture.levels) {
|
---|
330 | TRACE("(%p) level (%d)\n", This, Level);
|
---|
331 | return IWineD3DSurface_GetDesc(This->surfaces[0][Level], pDesc);
|
---|
332 | }
|
---|
333 | WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
|
---|
334 | return WINED3DERR_INVALIDCALL;
|
---|
335 | }
|
---|
336 |
|
---|
337 | static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) {
|
---|
338 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
339 | HRESULT hr = WINED3DERR_INVALIDCALL;
|
---|
340 |
|
---|
341 | if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
|
---|
342 | *ppCubeMapSurface = This->surfaces[FaceType][Level];
|
---|
343 | IWineD3DSurface_AddRef(*ppCubeMapSurface);
|
---|
344 |
|
---|
345 | hr = WINED3D_OK;
|
---|
346 | }
|
---|
347 | if (WINED3D_OK == hr) {
|
---|
348 | TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p\n", This, FaceType, Level, This->surfaces[FaceType][Level]);
|
---|
349 | } else {
|
---|
350 | WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
|
---|
351 | }
|
---|
352 |
|
---|
353 | return hr;
|
---|
354 | }
|
---|
355 |
|
---|
356 | static HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
|
---|
357 | HRESULT hr = WINED3DERR_INVALIDCALL;
|
---|
358 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
359 |
|
---|
360 | if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
|
---|
361 | hr = IWineD3DSurface_LockRect(This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
|
---|
362 | }
|
---|
363 |
|
---|
364 | if (WINED3D_OK == hr) {
|
---|
365 | TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%u)\n", This, FaceType, Level, pLockedRect->pBits, hr);
|
---|
366 | } else {
|
---|
367 | WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
|
---|
368 | }
|
---|
369 |
|
---|
370 | return hr;
|
---|
371 | }
|
---|
372 |
|
---|
373 | static HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level) {
|
---|
374 | HRESULT hr = WINED3DERR_INVALIDCALL;
|
---|
375 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
376 |
|
---|
377 | if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
|
---|
378 | hr = IWineD3DSurface_UnlockRect(This->surfaces[FaceType][Level]);
|
---|
379 | }
|
---|
380 |
|
---|
381 | if (WINED3D_OK == hr) {
|
---|
382 | TRACE("(%p) -> faceType(%d) level(%d) success(%u)\n", This, FaceType, Level, hr);
|
---|
383 | } else {
|
---|
384 | WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType);
|
---|
385 | }
|
---|
386 | return hr;
|
---|
387 | }
|
---|
388 |
|
---|
389 | static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
|
---|
390 | HRESULT hr = WINED3DERR_INVALIDCALL;
|
---|
391 | IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
|
---|
392 | This->baseTexture.texture_rgb.dirty = TRUE;
|
---|
393 | This->baseTexture.texture_srgb.dirty = TRUE;
|
---|
394 | TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
|
---|
395 | if (FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
|
---|
396 | surface_add_dirty_rect(This->surfaces[FaceType][0], pDirtyRect);
|
---|
397 | hr = WINED3D_OK;
|
---|
398 | } else {
|
---|
399 | WARN("(%p) overflow FaceType(%d)\n", This, FaceType);
|
---|
400 | }
|
---|
401 | return hr;
|
---|
402 | }
|
---|
403 |
|
---|
404 | static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
|
---|
405 | {
|
---|
406 | /* IUnknown */
|
---|
407 | IWineD3DCubeTextureImpl_QueryInterface,
|
---|
408 | IWineD3DCubeTextureImpl_AddRef,
|
---|
409 | IWineD3DCubeTextureImpl_Release,
|
---|
410 | /* IWineD3DResource */
|
---|
411 | IWineD3DCubeTextureImpl_GetParent,
|
---|
412 | IWineD3DCubeTextureImpl_SetPrivateData,
|
---|
413 | IWineD3DCubeTextureImpl_GetPrivateData,
|
---|
414 | IWineD3DCubeTextureImpl_FreePrivateData,
|
---|
415 | IWineD3DCubeTextureImpl_SetPriority,
|
---|
416 | IWineD3DCubeTextureImpl_GetPriority,
|
---|
417 | IWineD3DCubeTextureImpl_PreLoad,
|
---|
418 | IWineD3DCubeTextureImpl_UnLoad,
|
---|
419 | IWineD3DCubeTextureImpl_GetType,
|
---|
420 | /* IWineD3DBaseTexture */
|
---|
421 | IWineD3DCubeTextureImpl_SetLOD,
|
---|
422 | IWineD3DCubeTextureImpl_GetLOD,
|
---|
423 | IWineD3DCubeTextureImpl_GetLevelCount,
|
---|
424 | IWineD3DCubeTextureImpl_SetAutoGenFilterType,
|
---|
425 | IWineD3DCubeTextureImpl_GetAutoGenFilterType,
|
---|
426 | IWineD3DCubeTextureImpl_GenerateMipSubLevels,
|
---|
427 | IWineD3DCubeTextureImpl_SetDirty,
|
---|
428 | IWineD3DCubeTextureImpl_GetDirty,
|
---|
429 | IWineD3DCubeTextureImpl_BindTexture,
|
---|
430 | IWineD3DCubeTextureImpl_GetTextureDimensions,
|
---|
431 | IWineD3DCubeTextureImpl_IsCondNP2,
|
---|
432 | /* IWineD3DCubeTexture */
|
---|
433 | IWineD3DCubeTextureImpl_GetLevelDesc,
|
---|
434 | IWineD3DCubeTextureImpl_GetCubeMapSurface,
|
---|
435 | IWineD3DCubeTextureImpl_LockRect,
|
---|
436 | IWineD3DCubeTextureImpl_UnlockRect,
|
---|
437 | IWineD3DCubeTextureImpl_AddDirtyRect
|
---|
438 | };
|
---|
439 |
|
---|
440 | HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
|
---|
441 | IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
|
---|
442 | IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
|
---|
443 | {
|
---|
444 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
445 | const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
|
---|
446 | UINT pow2_edge_length;
|
---|
447 | unsigned int i, j;
|
---|
448 | UINT tmp_w;
|
---|
449 | HRESULT hr;
|
---|
450 |
|
---|
451 | /* TODO: It should only be possible to create textures for formats
|
---|
452 | * that are reported as supported. */
|
---|
453 | if (WINED3DFMT_UNKNOWN >= format)
|
---|
454 | {
|
---|
455 | WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
---|
456 | return WINED3DERR_INVALIDCALL;
|
---|
457 | }
|
---|
458 |
|
---|
459 | if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3DPOOL_SCRATCH)
|
---|
460 | {
|
---|
461 | WARN("(%p) : Tried to create not supported cube texture.\n", texture);
|
---|
462 | return WINED3DERR_INVALIDCALL;
|
---|
463 | }
|
---|
464 |
|
---|
465 | /* Calculate levels for mip mapping */
|
---|
466 | if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
---|
467 | {
|
---|
468 | if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
---|
469 | {
|
---|
470 | WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
|
---|
471 | return WINED3DERR_INVALIDCALL;
|
---|
472 | }
|
---|
473 |
|
---|
474 | if (levels > 1)
|
---|
475 | {
|
---|
476 | WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
---|
477 | return WINED3DERR_INVALIDCALL;
|
---|
478 | }
|
---|
479 |
|
---|
480 | levels = 1;
|
---|
481 | }
|
---|
482 | else if (!levels)
|
---|
483 | {
|
---|
484 | levels = wined3d_log2i(edge_length) + 1;
|
---|
485 | TRACE("Calculated levels = %u.\n", levels);
|
---|
486 | }
|
---|
487 |
|
---|
488 | texture->lpVtbl = &IWineD3DCubeTexture_Vtbl;
|
---|
489 |
|
---|
490 | hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_CUBETEXTURE,
|
---|
491 | device, 0, usage, format_desc, pool, parent, parent_ops
|
---|
492 | #ifdef VBOX_WITH_WDDM
|
---|
493 | , NULL
|
---|
494 | , NULL
|
---|
495 | #endif
|
---|
496 | );
|
---|
497 | if (FAILED(hr))
|
---|
498 | {
|
---|
499 | WARN("Failed to initialize basetexture, returning %#x\n", hr);
|
---|
500 | return hr;
|
---|
501 | }
|
---|
502 |
|
---|
503 | /* Find the nearest pow2 match. */
|
---|
504 | pow2_edge_length = 1;
|
---|
505 | while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
|
---|
506 |
|
---|
507 | if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || (edge_length == pow2_edge_length))
|
---|
508 | {
|
---|
509 | /* Precalculated scaling for 'faked' non power of two texture coords. */
|
---|
510 | texture->baseTexture.pow2Matrix[0] = 1.0f;
|
---|
511 | texture->baseTexture.pow2Matrix[5] = 1.0f;
|
---|
512 | texture->baseTexture.pow2Matrix[10] = 1.0f;
|
---|
513 | texture->baseTexture.pow2Matrix[15] = 1.0f;
|
---|
514 | }
|
---|
515 | else
|
---|
516 | {
|
---|
517 | /* Precalculated scaling for 'faked' non power of two texture coords. */
|
---|
518 | texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
|
---|
519 | texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
|
---|
520 | texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
|
---|
521 | texture->baseTexture.pow2Matrix[15] = 1.0f;
|
---|
522 | texture->baseTexture.pow2Matrix_identity = FALSE;
|
---|
523 | }
|
---|
524 |
|
---|
525 | /* Generate all the surfaces. */
|
---|
526 | tmp_w = edge_length;
|
---|
527 | for (i = 0; i < texture->baseTexture.levels; ++i)
|
---|
528 | {
|
---|
529 | /* Create the 6 faces. */
|
---|
530 | for (j = 0; j < 6; ++j)
|
---|
531 | {
|
---|
532 | static const GLenum cube_targets[6] =
|
---|
533 | {
|
---|
534 | GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
|
---|
535 | GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
|
---|
536 | GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
|
---|
537 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
|
---|
538 | GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
|
---|
539 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
|
---|
540 | };
|
---|
541 |
|
---|
542 | #ifdef VBOX_WITH_WDDM
|
---|
543 | hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
|
---|
544 | format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
|
---|
545 | , NULL, NULL /* <- no need this info here */
|
---|
546 | );
|
---|
547 | #else
|
---|
548 | hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
|
---|
549 | format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
|
---|
550 | );
|
---|
551 | #endif
|
---|
552 | if (FAILED(hr))
|
---|
553 | {
|
---|
554 | FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
|
---|
555 | texture->surfaces[j][i] = NULL;
|
---|
556 | cubetexture_cleanup(texture);
|
---|
557 | return hr;
|
---|
558 | }
|
---|
559 |
|
---|
560 | IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture);
|
---|
561 | TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]);
|
---|
562 | surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]);
|
---|
563 | }
|
---|
564 | tmp_w = max(1, tmp_w >> 1);
|
---|
565 | }
|
---|
566 | texture->baseTexture.internal_preload = cubetexture_internal_preload;
|
---|
567 |
|
---|
568 | return WINED3D_OK;
|
---|
569 | }
|
---|