VirtualBox

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

Last change on this file since 31828 was 31828, checked in by vboxsync, 14 years ago

wine: basics for shared resource handling

  • Property svn:eol-style set to native
File size: 23.5 KB
Line 
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 * Sun 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, Sun 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/* ******************************************************
234 IWineD3DTexture IWineD3DBaseTexture parts follow
235 ****************************************************** */
236static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
237 return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
238}
239
240static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
241 return basetexture_get_lod((IWineD3DBaseTexture *)iface);
242}
243
244static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
245 return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
246}
247
248static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
249 return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
250}
251
252static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
253 return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
254}
255
256static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
257 basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
258}
259
260/* Internal function, No d3d mapping */
261static BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
262 return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
263}
264
265static BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
266 return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
267}
268
269/* Context activation is done by the caller. */
270static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BOOL srgb) {
271 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
272 BOOL set_gl_texture_desc;
273 HRESULT hr;
274
275 TRACE("(%p) : relay to BaseTexture\n", This);
276
277 hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
278 if (set_gl_texture_desc && SUCCEEDED(hr)) {
279 UINT i;
280 struct gl_texture *gl_tex;
281
282 if(This->baseTexture.is_srgb) {
283 gl_tex = &This->baseTexture.texture_srgb;
284 } else {
285 gl_tex = &This->baseTexture.texture_rgb;
286 }
287
288 for (i = 0; i < This->baseTexture.levels; ++i) {
289 surface_set_texture_name(This->surfaces[i], gl_tex->name, This->baseTexture.is_srgb);
290 }
291 /* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
292 * partial driver emulation, we're dealing with a GL_TEXTURE_2D texture which has the address mode set to repeat - something
293 * that prevents us from hitting the accelerated codepath. Thus manually set the GL state. The same applies to filtering.
294 * Even if the texture has only one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW fallback on macos.
295 */
296 if(IWineD3DBaseTexture_IsCondNP2(iface)) {
297 ENTER_GL();
298 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
299 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
300 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
301 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
302 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
303 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
304 glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
305 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
306 LEAVE_GL();
307 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP;
308 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP;
309 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
310 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
311 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
312 }
313 }
314
315 return hr;
316}
317
318static UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
319 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
320 TRACE("(%p)\n", This);
321
322 return This->target;
323}
324
325static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
326 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
327 TRACE("(%p)\n", This);
328
329 return This->cond_np2;
330}
331
332/* *******************************************
333 IWineD3DTexture IWineD3DTexture parts follow
334 ******************************************* */
335static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
336 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
337
338 if (Level < This->baseTexture.levels) {
339 TRACE("(%p) Level (%d)\n", This, Level);
340 return IWineD3DSurface_GetDesc(This->surfaces[Level], pDesc);
341 }
342 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
343 return WINED3DERR_INVALIDCALL;
344}
345
346static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
347 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
348 HRESULT hr = WINED3DERR_INVALIDCALL;
349
350 if (Level < This->baseTexture.levels) {
351 *ppSurfaceLevel = This->surfaces[Level];
352 IWineD3DSurface_AddRef(This->surfaces[Level]);
353 hr = WINED3D_OK;
354 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
355 }
356 if (WINED3D_OK != hr) {
357 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
358 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
359 }
360 return hr;
361}
362
363static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, WINED3DLOCKED_RECT *pLockedRect,
364 CONST RECT *pRect, DWORD Flags) {
365 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
366 HRESULT hr = WINED3DERR_INVALIDCALL;
367
368 if (Level < This->baseTexture.levels) {
369 hr = IWineD3DSurface_LockRect(This->surfaces[Level], pLockedRect, pRect, Flags);
370 }
371 if (WINED3D_OK == hr) {
372 TRACE("(%p) Level (%d) success\n", This, Level);
373 } else {
374 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
375 }
376
377 return hr;
378}
379
380static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
381 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
382 HRESULT hr = WINED3DERR_INVALIDCALL;
383
384 if (Level < This->baseTexture.levels) {
385 hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]);
386 }
387 if ( WINED3D_OK == hr) {
388 TRACE("(%p) Level (%d) success\n", This, Level);
389 } else {
390 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
391 }
392 return hr;
393}
394
395static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
396 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
397 This->baseTexture.texture_rgb.dirty = TRUE;
398 This->baseTexture.texture_srgb.dirty = TRUE;
399 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
400 surface_add_dirty_rect(This->surfaces[0], pDirtyRect);
401
402 return WINED3D_OK;
403}
404
405static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
406{
407 /* IUnknown */
408 IWineD3DTextureImpl_QueryInterface,
409 IWineD3DTextureImpl_AddRef,
410 IWineD3DTextureImpl_Release,
411 /* IWineD3DResource */
412 IWineD3DTextureImpl_GetParent,
413 IWineD3DTextureImpl_SetPrivateData,
414 IWineD3DTextureImpl_GetPrivateData,
415 IWineD3DTextureImpl_FreePrivateData,
416 IWineD3DTextureImpl_SetPriority,
417 IWineD3DTextureImpl_GetPriority,
418 IWineD3DTextureImpl_PreLoad,
419 IWineD3DTextureImpl_UnLoad,
420 IWineD3DTextureImpl_GetType,
421 /* IWineD3DBaseTexture */
422 IWineD3DTextureImpl_SetLOD,
423 IWineD3DTextureImpl_GetLOD,
424 IWineD3DTextureImpl_GetLevelCount,
425 IWineD3DTextureImpl_SetAutoGenFilterType,
426 IWineD3DTextureImpl_GetAutoGenFilterType,
427 IWineD3DTextureImpl_GenerateMipSubLevels,
428 IWineD3DTextureImpl_SetDirty,
429 IWineD3DTextureImpl_GetDirty,
430 IWineD3DTextureImpl_BindTexture,
431 IWineD3DTextureImpl_GetTextureDimensions,
432 IWineD3DTextureImpl_IsCondNP2,
433 /* IWineD3DTexture */
434 IWineD3DTextureImpl_GetLevelDesc,
435 IWineD3DTextureImpl_GetSurfaceLevel,
436 IWineD3DTextureImpl_LockRect,
437 IWineD3DTextureImpl_UnlockRect,
438 IWineD3DTextureImpl_AddDirtyRect
439};
440
441HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
442 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
443 IUnknown *parent, const struct wined3d_parent_ops *parent_ops
444#ifdef VBOXWDDM
445 , HANDLE *shared_handle
446 , void *pvClientMem
447#endif
448 )
449{
450 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
451 const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
452 UINT pow2_width, pow2_height;
453 UINT tmp_w, tmp_h;
454 unsigned int i;
455 HRESULT hr;
456
457 /* TODO: It should only be possible to create textures for formats
458 * that are reported as supported. */
459 if (WINED3DFMT_UNKNOWN >= format)
460 {
461 WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
462 return WINED3DERR_INVALIDCALL;
463 }
464
465 /* Non-power2 support. */
466 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
467 {
468 pow2_width = width;
469 pow2_height = height;
470 }
471 else
472 {
473 /* Find the nearest pow2 match. */
474 pow2_width = pow2_height = 1;
475 while (pow2_width < width) pow2_width <<= 1;
476 while (pow2_height < height) pow2_height <<= 1;
477
478 if (pow2_width != width || pow2_height != height)
479 {
480 if (levels > 1)
481 {
482 WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
483 return WINED3DERR_INVALIDCALL;
484 }
485 levels = 1;
486 }
487 }
488
489 /* Calculate levels for mip mapping. */
490 if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
491 {
492 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
493 {
494 WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
495 return WINED3DERR_INVALIDCALL;
496 }
497
498 if (levels > 1)
499 {
500 WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
501 return WINED3DERR_INVALIDCALL;
502 }
503
504 levels = 1;
505 }
506 else if (!levels)
507 {
508 levels = wined3d_log2i(max(width, height)) + 1;
509 TRACE("Calculated levels = %u.\n", levels);
510 }
511
512 texture->lpVtbl = &IWineD3DTexture_Vtbl;
513
514 hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
515 device, 0, usage, format_desc, pool, parent, parent_ops
516#ifdef VBOXWDDM
517 , shared_handle, pvClientMem
518#endif
519 );
520 if (FAILED(hr))
521 {
522 WARN("Failed to initialize basetexture, returning %#x.\n", hr);
523 return hr;
524 }
525
526 /* Precalculated scaling for 'faked' non power of two texture coords.
527 * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
528 * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
529 * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
530 if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
531 {
532 texture->baseTexture.pow2Matrix[0] = 1.0f;
533 texture->baseTexture.pow2Matrix[5] = 1.0f;
534 texture->baseTexture.pow2Matrix[10] = 1.0f;
535 texture->baseTexture.pow2Matrix[15] = 1.0f;
536 texture->target = GL_TEXTURE_2D;
537 texture->cond_np2 = TRUE;
538 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
539 }
540 else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
541 && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
542 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
543 {
544 if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
545
546 texture->baseTexture.pow2Matrix[0] = (float)width;
547 texture->baseTexture.pow2Matrix[5] = (float)height;
548 texture->baseTexture.pow2Matrix[10] = 1.0f;
549 texture->baseTexture.pow2Matrix[15] = 1.0f;
550 texture->target = GL_TEXTURE_RECTANGLE_ARB;
551 texture->cond_np2 = TRUE;
552
553 if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
554 {
555 texture->baseTexture.minMipLookup = minMipLookup_noMip;
556 }
557 else
558 {
559 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
560 }
561 }
562 else
563 {
564 if ((width != pow2_width) || (height != pow2_height))
565 {
566 texture->baseTexture.pow2Matrix_identity = FALSE;
567 texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
568 texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
569 }
570 else
571 {
572 texture->baseTexture.pow2Matrix[0] = 1.0f;
573 texture->baseTexture.pow2Matrix[5] = 1.0f;
574 }
575
576 texture->baseTexture.pow2Matrix[10] = 1.0f;
577 texture->baseTexture.pow2Matrix[15] = 1.0f;
578 texture->target = GL_TEXTURE_2D;
579 texture->cond_np2 = FALSE;
580 }
581 TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
582
583 /* Generate all the surfaces. */
584 tmp_w = width;
585 tmp_h = height;
586 for (i = 0; i < texture->baseTexture.levels; ++i)
587 {
588#ifdef VBOXWDDM
589 /* Use the callback to create the texture surface. */
590 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
591 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]
592 , shared_handle
593 , pvClientMem);
594
595#else
596 /* Use the callback to create the texture surface. */
597 hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
598 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
599#endif
600
601 if (FAILED(hr))
602 {
603 FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
604 texture->surfaces[i] = NULL;
605 texture_cleanup(texture);
606 return hr;
607 }
608
609 IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
610 TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
611 surface_set_texture_target(texture->surfaces[i], texture->target);
612 /* Calculate the next mipmap level. */
613 tmp_w = max(1, tmp_w >> 1);
614 tmp_h = max(1, tmp_h >> 1);
615 }
616 texture->baseTexture.internal_preload = texture_internal_preload;
617
618 return WINED3D_OK;
619}
Note: See TracBrowser for help on using the repository browser.

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