VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c@ 39150

最後變更 在這個檔案從39150是 38982,由 vboxsync 提交於 13 年 前

wddm: proper ie rendering under win8 (shared resource open & destroy fixes, zero-init resources on creaate, etc.)

  • 屬性 svn:eol-style 設為 native
檔案大小: 26.0 KB
 
1/*
2 * IWineD3DTexture 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
37WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
38
39static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
40{
41 /* Override the IWineD3DResource PreLoad method. */
42 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
43 IWineD3DDeviceImpl *device = This->resource.device;
44 struct wined3d_context *context = NULL;
45 unsigned int i;
46 BOOL srgb_mode;
47 BOOL *dirty;
48
49 TRACE("(%p) : About to load texture.\n", This);
50
51 switch (srgb)
52 {
53 case SRGB_RGB:
54 srgb_mode = FALSE;
55 break;
56
57 case SRGB_BOTH:
58 texture_internal_preload(iface, SRGB_RGB);
59 /* Fallthrough */
60
61 case SRGB_SRGB:
62 srgb_mode = TRUE;
63 break;
64
65 default:
66 srgb_mode = This->baseTexture.is_srgb;
67 break;
68 }
69 dirty = srgb_mode ? &This->baseTexture.texture_srgb.dirty : &This->baseTexture.texture_rgb.dirty;
70
71 if (!device->isInDraw)
72 {
73 /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture,
74 * thus no danger of recursive calls. */
75 context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
76 }
77
78 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
79 || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
80 {
81 for (i = 0; i < This->baseTexture.levels; ++i)
82 {
83 if (palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[i]))
84 {
85 TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
86 /* TODO: This is not necessarily needed with hw palettized texture support. */
87 IWineD3DSurface_LoadLocation(This->surfaces[i], SFLAG_INSYSMEM, NULL);
88 /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
89 IWineD3DSurface_ModifyLocation(This->surfaces[i], SFLAG_INTEXTURE, FALSE);
90 }
91 }
92 }
93
94 /* If the texture is marked dirty or the srgb sampler setting has changed
95 * since the last load then reload the surfaces. */
96 if (*dirty)
97 {
98 for (i = 0; i < This->baseTexture.levels; ++i)
99 {
100 IWineD3DSurface_LoadTexture(This->surfaces[i], srgb_mode);
101 }
102 }
103 else
104 {
105 TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
106 }
107
108 if (context) context_release(context);
109
110 /* No longer dirty. */
111 *dirty = FALSE;
112}
113
114static void texture_cleanup(IWineD3DTextureImpl *This)
115{
116 unsigned int i;
117
118 TRACE("(%p) : Cleaning up\n", This);
119
120 for (i = 0; i < This->baseTexture.levels; ++i)
121 {
122 if (This->surfaces[i])
123 {
124 /* Clean out the texture name we gave to the surface so that the
125 * surface doesn't try and release it */
126 surface_set_texture_name(This->surfaces[i], 0, TRUE);
127 surface_set_texture_name(This->surfaces[i], 0, FALSE);
128 surface_set_texture_target(This->surfaces[i], 0);
129 IWineD3DSurface_SetContainer(This->surfaces[i], 0);
130 IWineD3DSurface_Release(This->surfaces[i]);
131 }
132 }
133
134 TRACE("(%p) : Cleaning up base texture\n", This);
135 basetexture_cleanup((IWineD3DBaseTexture *)This);
136}
137
138/* *******************************************
139 IWineD3DTexture IUnknown parts follow
140 ******************************************* */
141
142static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
143{
144 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
145 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
146 if (IsEqualGUID(riid, &IID_IUnknown)
147 || IsEqualGUID(riid, &IID_IWineD3DBase)
148 || IsEqualGUID(riid, &IID_IWineD3DResource)
149 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
150 || IsEqualGUID(riid, &IID_IWineD3DTexture)){
151 IUnknown_AddRef(iface);
152 *ppobj = This;
153 return WINED3D_OK;
154 }
155 *ppobj = NULL;
156 return E_NOINTERFACE;
157}
158
159static ULONG WINAPI IWineD3DTextureImpl_AddRef(IWineD3DTexture *iface) {
160 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
161 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
162 return InterlockedIncrement(&This->resource.ref);
163}
164
165static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
166 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
167 ULONG ref;
168 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
169 ref = InterlockedDecrement(&This->resource.ref);
170 if (!ref)
171 {
172 texture_cleanup(This);
173 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
174 HeapFree(GetProcessHeap(), 0, This);
175 }
176 return ref;
177}
178
179
180/* ****************************************************
181 IWineD3DTexture IWineD3DResource parts follow
182 **************************************************** */
183static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
184 return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
185}
186
187static HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
188 return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
189}
190
191static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
192 return resource_free_private_data((IWineD3DResource *)iface, refguid);
193}
194
195static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
196 return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
197}
198
199static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
200 return resource_get_priority((IWineD3DResource *)iface);
201}
202
203static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
204 texture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
205}
206
207static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
208 unsigned int i;
209 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
210 TRACE("(%p)\n", This);
211
212 /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
213 * surface before, this one will be a NOP and vice versa. Unloading an unloaded
214 * surface is fine
215 */
216 for (i = 0; i < This->baseTexture.levels; i++) {
217 IWineD3DSurface_UnLoad(This->surfaces[i]);
218 surface_set_texture_name(This->surfaces[i], 0, FALSE); /* Delete rgb name */
219 surface_set_texture_name(This->surfaces[i], 0, TRUE); /* delete srgb name */
220 }
221
222 basetexture_unload((IWineD3DBaseTexture *)iface);
223}
224
225static WINED3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
226 return resource_get_type((IWineD3DResource *)iface);
227}
228
229static HRESULT WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface, IUnknown **pParent) {
230 return resource_get_parent((IWineD3DResource *)iface, pParent);
231}
232
233#ifdef VBOX_WITH_WDDM
234static HRESULT WINAPI IWineD3DTextureImpl_SetDontDeleteGl(IWineD3DTexture *iface) {
235 IWineD3DTextureImpl *This = (IWineD3DTextureImpl*)iface;
236 HRESULT hr = IWineD3DResourceImpl_SetDontDeleteGl((IWineD3DResource*)iface);
237 unsigned int i;
238
239 if (FAILED(hr))
240 {
241 ERR("IWineD3DResource_SetDontDeleteGl failed");
242 return hr;
243 }
244
245 for (i = 0; i < This->baseTexture.levels; ++i)
246 {
247 if (This->surfaces[i])
248 {
249 HRESULT tmpHr = IWineD3DResource_SetDontDeleteGl((IWineD3DResource*)This->surfaces[i]);
250 Assert(tmpHr == S_OK);
251 }
252 }
253
254 return WINED3D_OK;
255}
256#endif
257
258/* ******************************************************
259 IWineD3DTexture IWineD3DBaseTexture parts follow
260 ****************************************************** */
261static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
262 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
263}
264
265static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
266 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
267}
268
269static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
270 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
271}
272
273static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
274 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
275}
276
277static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
278 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
279}
280
281static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
282 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
283}
284
285/* Internal function, No d3d mapping */
286static BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
287 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
288}
289
290static BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
291 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
292}
293
294/* Context activation is done by the caller. */
295static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BOOL srgb) {
296 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
297 BOOL set_gl_texture_desc;
298 HRESULT hr;
299
300 TRACE("(%p) : relay to BaseTexture\n", This);
301
302 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
303 if (set_gl_texture_desc && SUCCEEDED(hr)) {
304 UINT i;
305 struct gl_texture *gl_tex;
306
307 if(This->baseTexture.is_srgb) {
308 gl_tex = &This->baseTexture.texture_srgb;
309 } else {
310 gl_tex = &This->baseTexture.texture_rgb;
311 }
312
313 for (i = 0; i < This->baseTexture.levels; ++i) {
314 surface_set_texture_name(This->surfaces[i], gl_tex->name, This->baseTexture.is_srgb);
315 }
316
317 /* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
318 * partial driver emulation, we're dealing with a GL_TEXTURE_2D texture which has the address mode set to repeat - something
319 * that prevents us from hitting the accelerated codepath. Thus manually set the GL state. The same applies to filtering.
320 * Even if the texture has only one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW fallback on macos.
321 */
322 if(IWineD3DBaseTexture_IsCondNP2(iface)) {
323#ifdef VBOX_WITH_WDDM
324 if (!VBOXSHRC_IS_SHARED_OPENED(This))
325#endif
326 {
327 ENTER_GL();
328 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
329 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
330 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
331 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
332 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
333 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
334 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
335 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
336 LEAVE_GL();
337 }
338 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
339 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
340 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
341 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
342 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
343 }
344 }
345
346 return hr;
347}
348
349static UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
350 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
351 TRACE("(%p)\n", This);
352
353 return This->target;
354}
355
356static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
357 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
358 TRACE("(%p)\n", This);
359
360 return This->cond_np2;
361}
362
363/* *******************************************
364 IWineD3DTexture IWineD3DTexture parts follow
365 ******************************************* */
366static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
367 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
368
369 if (Level < This->baseTexture.levels) {
370 TRACE("(%p) Level (%d)\n", This, Level);
371 return IWineD3DSurface_GetDesc(This->surfaces[Level], pDesc);
372 }
373 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
374 return WINED3DERR_INVALIDCALL;
375}
376
377static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
378 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
379 HRESULT hr = WINED3DERR_INVALIDCALL;
380
381 if (Level < This->baseTexture.levels) {
382 *ppSurfaceLevel = This->surfaces[Level];
383 IWineD3DSurface_AddRef(This->surfaces[Level]);
384 hr = WINED3D_OK;
385 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
386 }
387 if (WINED3D_OK != hr) {
388 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
389 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
390 }
391 return hr;
392}
393
394static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, WINED3DLOCKED_RECT *pLockedRect,
395 CONST RECT *pRect, DWORD Flags) {
396 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
397 HRESULT hr = WINED3DERR_INVALIDCALL;
398
399 if (Level < This->baseTexture.levels) {
400 hr = IWineD3DSurface_LockRect(This->surfaces[Level], pLockedRect, pRect, Flags);
401 }
402 if (WINED3D_OK == hr) {
403 TRACE("(%p) Level (%d) success\n", This, Level);
404 } else {
405 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
406 }
407
408 return hr;
409}
410
411static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
412 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
413 HRESULT hr = WINED3DERR_INVALIDCALL;
414
415 if (Level < This->baseTexture.levels) {
416 hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]);
417 }
418 if ( WINED3D_OK == hr) {
419 TRACE("(%p) Level (%d) success\n", This, Level);
420 } else {
421 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
422 }
423 return hr;
424}
425
426static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
427 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
428 This->baseTexture.texture_rgb.dirty = TRUE;
429 This->baseTexture.texture_srgb.dirty = TRUE;
430 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
431 surface_add_dirty_rect(This->surfaces[0], pDirtyRect);
432
433 return WINED3D_OK;
434}
435
436static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
437{
438 /* IUnknown */
439 IWineD3DTextureImpl_QueryInterface,
440 IWineD3DTextureImpl_AddRef,
441 IWineD3DTextureImpl_Release,
442 /* IWineD3DResource */
443 IWineD3DTextureImpl_GetParent,
444 IWineD3DTextureImpl_SetPrivateData,
445 IWineD3DTextureImpl_GetPrivateData,
446 IWineD3DTextureImpl_FreePrivateData,
447 IWineD3DTextureImpl_SetPriority,
448 IWineD3DTextureImpl_GetPriority,
449 IWineD3DTextureImpl_PreLoad,
450 IWineD3DTextureImpl_UnLoad,
451 IWineD3DTextureImpl_GetType,
452#ifdef VBOX_WITH_WDDM
453 IWineD3DTextureImpl_SetDontDeleteGl,
454#endif
455 /* IWineD3DBaseTexture */
456 IWineD3DTextureImpl_SetLOD,
457 IWineD3DTextureImpl_GetLOD,
458 IWineD3DTextureImpl_GetLevelCount,
459 IWineD3DTextureImpl_SetAutoGenFilterType,
460 IWineD3DTextureImpl_GetAutoGenFilterType,
461 IWineD3DTextureImpl_GenerateMipSubLevels,
462 IWineD3DTextureImpl_SetDirty,
463 IWineD3DTextureImpl_GetDirty,
464 IWineD3DTextureImpl_BindTexture,
465 IWineD3DTextureImpl_GetTextureDimensions,
466 IWineD3DTextureImpl_IsCondNP2,
467 /* IWineD3DTexture */
468 IWineD3DTextureImpl_GetLevelDesc,
469 IWineD3DTextureImpl_GetSurfaceLevel,
470 IWineD3DTextureImpl_LockRect,
471 IWineD3DTextureImpl_UnlockRect,
472 IWineD3DTextureImpl_AddDirtyRect
473};
474
475HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
476 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
477 IUnknown *parent, const struct wined3d_parent_ops *parent_ops
478#ifdef VBOX_WITH_WDDM
479 , HANDLE *shared_handle
480 , void **pavClientMem
481#endif
482 )
483{
484 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
485 const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
486 UINT pow2_width, pow2_height;
487 UINT tmp_w, tmp_h;
488 unsigned int i;
489 HRESULT hr;
490
491 /* TODO: It should only be possible to create textures for formats
492 * that are reported as supported. */
493 if (WINED3DFMT_UNKNOWN >= format)
494 {
495 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
496 return WINED3DERR_INVALIDCALL;
497 }
498
499 /* Non-power2 support. */
500 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
501 {
502 pow2_width = width;
503 pow2_height = height;
504 }
505 else
506 {
507 /* Find the nearest pow2 match. */
508 pow2_width = pow2_height = 1;
509 while (pow2_width < width) pow2_width <<= 1;
510 while (pow2_height < height) pow2_height <<= 1;
511
512 if (pow2_width != width || pow2_height != height)
513 {
514 if (levels > 1)
515 {
516 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
517 return WINED3DERR_INVALIDCALL;
518 }
519 levels = 1;
520 }
521 }
522
523 /* Calculate levels for mip mapping. */
524 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
525 {
526 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
527 {
528 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
529 return WINED3DERR_INVALIDCALL;
530 }
531
532 if (levels > 1)
533 {
534 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
535 return WINED3DERR_INVALIDCALL;
536 }
537
538 levels = 1;
539 }
540 else if (!levels)
541 {
542 levels = wined3d_log2i(max(width, height)) + 1;
543 TRACE("Calculated levels = %u.\n", levels);
544 }
545
546 texture->lpVtbl = &IWineD3DTexture_Vtbl;
547
548 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
549 device, 0, usage, format_desc, pool, parent, parent_ops
550#ifdef VBOX_WITH_WDDM
551 , shared_handle, pavClientMem
552#endif
553 );
554 if (FAILED(hr))
555 {
556 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
557 return hr;
558 }
559
560 /* Precalculated scaling for 'faked' non power of two texture coords.
561 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
562 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
563 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
564 if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
565 {
566 texture->baseTexture.pow2Matrix[0] = 1.0f;
567 texture->baseTexture.pow2Matrix[5] = 1.0f;
568 texture->baseTexture.pow2Matrix[10] = 1.0f;
569 texture->baseTexture.pow2Matrix[15] = 1.0f;
570 texture->target = GL_TEXTURE_2D;
571 texture->cond_np2 = TRUE;
572 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
573 }
574 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
575 && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
576 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
577 {
578 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
579
580 texture->baseTexture.pow2Matrix[0] = (float)width;
581 texture->baseTexture.pow2Matrix[5] = (float)height;
582 texture->baseTexture.pow2Matrix[10] = 1.0f;
583 texture->baseTexture.pow2Matrix[15] = 1.0f;
584 texture->target = GL_TEXTURE_RECTANGLE_ARB;
585 texture->cond_np2 = TRUE;
586
587 if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
588 {
589 texture->baseTexture.minMipLookup = minMipLookup_noMip;
590 }
591 else
592 {
593 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
594 }
595 }
596 else
597 {
598 if ((width != pow2_width) || (height != pow2_height))
599 {
600 texture->baseTexture.pow2Matrix_identity = FALSE;
601 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
602 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
603 }
604 else
605 {
606 texture->baseTexture.pow2Matrix[0] = 1.0f;
607 texture->baseTexture.pow2Matrix[5] = 1.0f;
608 }
609
610 texture->baseTexture.pow2Matrix[10] = 1.0f;
611 texture->baseTexture.pow2Matrix[15] = 1.0f;
612 texture->target = GL_TEXTURE_2D;
613 texture->cond_np2 = FALSE;
614 }
615 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
616
617 /* Generate all the surfaces. */
618 tmp_w = width;
619 tmp_h = height;
620 for (i = 0; i < texture->baseTexture.levels; ++i)
621 {
622#ifdef VBOX_WITH_WDDM
623 /* Use the callback to create the texture surface. */
624 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
625 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]
626 , NULL /* <- we first create a surface in an everage "non-shared" fashion and initialize its share properties later (see below)
627 * this is done this way because the surface does not have its parent (texture) setup properly
628 * thus we can not initialize texture at this stage */
629 , pavClientMem ? pavClientMem[i] : NULL);
630
631#else
632 /* Use the callback to create the texture surface. */
633 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
634 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
635#endif
636
637 if (FAILED(hr))
638 {
639 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
640 texture->surfaces[i] = NULL;
641 texture_cleanup(texture);
642 return hr;
643 }
644
645 IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
646 TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
647 surface_set_texture_target(texture->surfaces[i], texture->target);
648 /* Calculate the next mipmap level. */
649 tmp_w = max(1, tmp_w >> 1);
650 tmp_h = max(1, tmp_h >> 1);
651 }
652 texture->baseTexture.internal_preload = texture_internal_preload;
653
654#ifdef VBOX_WITH_WDDM
655 if (VBOXSHRC_IS_SHARED(texture))
656 {
657 Assert(shared_handle);
658 for (i = 0; i < texture->baseTexture.levels; ++i)
659 {
660 VBOXSHRC_COPY_SHAREDATA((IWineD3DSurfaceImpl*)texture->surfaces[i], texture);
661 }
662#ifdef DEBUG
663 for (i = 0; i < texture->baseTexture.levels; ++i)
664 {
665 Assert(!((IWineD3DSurfaceImpl*)texture->surfaces[i])->texture_name);
666 }
667#endif
668 for (i = 0; i < texture->baseTexture.levels; ++i)
669 {
670 if (!VBOXSHRC_IS_SHARED_OPENED(texture))
671 {
672 IWineD3DSurface_LoadLocation(texture->surfaces[i], SFLAG_INTEXTURE, NULL);
673 Assert(!(*shared_handle));
674 *shared_handle = VBOXSHRC_GET_SHAREHANDLE(texture);
675 }
676 else
677 {
678 surface_setup_location_onopen((IWineD3DSurfaceImpl*)texture->surfaces[i]);
679 Assert(*shared_handle);
680 Assert(*shared_handle == VBOXSHRC_GET_SHAREHANDLE(texture));
681 }
682 }
683#ifdef DEBUG
684 for (i = 0; i < texture->baseTexture.levels; ++i)
685 {
686 Assert((GLuint)(*shared_handle) == ((IWineD3DSurfaceImpl*)texture->surfaces[i])->texture_name);
687 }
688#endif
689 }
690 else
691 {
692 Assert(!shared_handle);
693 }
694#endif
695
696 return WINED3D_OK;
697}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette