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 |
|
---|
37 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
---|
38 |
|
---|
39 | static 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 |
|
---|
114 | static 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 |
|
---|
142 | static 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 |
|
---|
159 | static 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 |
|
---|
165 | static 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 | **************************************************** */
|
---|
183 | static 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 |
|
---|
187 | static 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 |
|
---|
191 | static HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
|
---|
192 | return resource_free_private_data((IWineD3DResource *)iface, refguid);
|
---|
193 | }
|
---|
194 |
|
---|
195 | static DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
|
---|
196 | return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
|
---|
197 | }
|
---|
198 |
|
---|
199 | static DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
|
---|
200 | return resource_get_priority((IWineD3DResource *)iface);
|
---|
201 | }
|
---|
202 |
|
---|
203 | static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
|
---|
204 | texture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
|
---|
205 | }
|
---|
206 |
|
---|
207 | static 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 |
|
---|
225 | static WINED3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
|
---|
226 | return resource_get_type((IWineD3DResource *)iface);
|
---|
227 | }
|
---|
228 |
|
---|
229 | static 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 | ****************************************************** */
|
---|
236 | static DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
|
---|
237 | return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
|
---|
238 | }
|
---|
239 |
|
---|
240 | static DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
|
---|
241 | return basetexture_get_lod((IWineD3DBaseTexture *)iface);
|
---|
242 | }
|
---|
243 |
|
---|
244 | static DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
|
---|
245 | return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
|
---|
246 | }
|
---|
247 |
|
---|
248 | static HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
|
---|
249 | return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
|
---|
250 | }
|
---|
251 |
|
---|
252 | static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
|
---|
253 | return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
|
---|
254 | }
|
---|
255 |
|
---|
256 | static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
|
---|
257 | basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
|
---|
258 | }
|
---|
259 |
|
---|
260 | /* Internal function, No d3d mapping */
|
---|
261 | static BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
|
---|
262 | return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
|
---|
263 | }
|
---|
264 |
|
---|
265 | static BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
|
---|
266 | return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
|
---|
267 | }
|
---|
268 |
|
---|
269 | /* Context activation is done by the caller. */
|
---|
270 | static 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 |
|
---|
318 | static UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
|
---|
319 | IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
|
---|
320 | TRACE("(%p)\n", This);
|
---|
321 |
|
---|
322 | return This->target;
|
---|
323 | }
|
---|
324 |
|
---|
325 | static 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 | ******************************************* */
|
---|
335 | static 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 |
|
---|
346 | static 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 |
|
---|
363 | static 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 |
|
---|
380 | static 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 |
|
---|
395 | static 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 |
|
---|
405 | static 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 |
|
---|
441 | HRESULT 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 | {
|
---|
445 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
446 | const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
|
---|
447 | UINT pow2_width, pow2_height;
|
---|
448 | UINT tmp_w, tmp_h;
|
---|
449 | unsigned int i;
|
---|
450 | HRESULT hr;
|
---|
451 |
|
---|
452 | /* TODO: It should only be possible to create textures for formats
|
---|
453 | * that are reported as supported. */
|
---|
454 | if (WINED3DFMT_UNKNOWN >= format)
|
---|
455 | {
|
---|
456 | WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
---|
457 | return WINED3DERR_INVALIDCALL;
|
---|
458 | }
|
---|
459 |
|
---|
460 | /* Non-power2 support. */
|
---|
461 | if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
|
---|
462 | {
|
---|
463 | pow2_width = width;
|
---|
464 | pow2_height = height;
|
---|
465 | }
|
---|
466 | else
|
---|
467 | {
|
---|
468 | /* Find the nearest pow2 match. */
|
---|
469 | pow2_width = pow2_height = 1;
|
---|
470 | while (pow2_width < width) pow2_width <<= 1;
|
---|
471 | while (pow2_height < height) pow2_height <<= 1;
|
---|
472 |
|
---|
473 | if (pow2_width != width || pow2_height != height)
|
---|
474 | {
|
---|
475 | if (levels > 1)
|
---|
476 | {
|
---|
477 | WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
|
---|
478 | return WINED3DERR_INVALIDCALL;
|
---|
479 | }
|
---|
480 | levels = 1;
|
---|
481 | }
|
---|
482 | }
|
---|
483 |
|
---|
484 | /* Calculate levels for mip mapping. */
|
---|
485 | if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
---|
486 | {
|
---|
487 | if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
---|
488 | {
|
---|
489 | WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
|
---|
490 | return WINED3DERR_INVALIDCALL;
|
---|
491 | }
|
---|
492 |
|
---|
493 | if (levels > 1)
|
---|
494 | {
|
---|
495 | WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
|
---|
496 | return WINED3DERR_INVALIDCALL;
|
---|
497 | }
|
---|
498 |
|
---|
499 | levels = 1;
|
---|
500 | }
|
---|
501 | else if (!levels)
|
---|
502 | {
|
---|
503 | levels = wined3d_log2i(max(width, height)) + 1;
|
---|
504 | TRACE("Calculated levels = %u.\n", levels);
|
---|
505 | }
|
---|
506 |
|
---|
507 | texture->lpVtbl = &IWineD3DTexture_Vtbl;
|
---|
508 |
|
---|
509 | hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
|
---|
510 | device, 0, usage, format_desc, pool, parent, parent_ops);
|
---|
511 | if (FAILED(hr))
|
---|
512 | {
|
---|
513 | WARN("Failed to initialize basetexture, returning %#x.\n", hr);
|
---|
514 | return hr;
|
---|
515 | }
|
---|
516 |
|
---|
517 | /* Precalculated scaling for 'faked' non power of two texture coords.
|
---|
518 | * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
|
---|
519 | * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
|
---|
520 | * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
|
---|
521 | if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
|
---|
522 | {
|
---|
523 | texture->baseTexture.pow2Matrix[0] = 1.0f;
|
---|
524 | texture->baseTexture.pow2Matrix[5] = 1.0f;
|
---|
525 | texture->baseTexture.pow2Matrix[10] = 1.0f;
|
---|
526 | texture->baseTexture.pow2Matrix[15] = 1.0f;
|
---|
527 | texture->target = GL_TEXTURE_2D;
|
---|
528 | texture->cond_np2 = TRUE;
|
---|
529 | texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
---|
530 | }
|
---|
531 | else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
|
---|
532 | && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
|
---|
533 | && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
|
---|
534 | {
|
---|
535 | if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
|
---|
536 |
|
---|
537 | texture->baseTexture.pow2Matrix[0] = (float)width;
|
---|
538 | texture->baseTexture.pow2Matrix[5] = (float)height;
|
---|
539 | texture->baseTexture.pow2Matrix[10] = 1.0f;
|
---|
540 | texture->baseTexture.pow2Matrix[15] = 1.0f;
|
---|
541 | texture->target = GL_TEXTURE_RECTANGLE_ARB;
|
---|
542 | texture->cond_np2 = TRUE;
|
---|
543 |
|
---|
544 | if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
|
---|
545 | {
|
---|
546 | texture->baseTexture.minMipLookup = minMipLookup_noMip;
|
---|
547 | }
|
---|
548 | else
|
---|
549 | {
|
---|
550 | texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
---|
551 | }
|
---|
552 | }
|
---|
553 | else
|
---|
554 | {
|
---|
555 | if ((width != pow2_width) || (height != pow2_height))
|
---|
556 | {
|
---|
557 | texture->baseTexture.pow2Matrix_identity = FALSE;
|
---|
558 | texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
|
---|
559 | texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
|
---|
560 | }
|
---|
561 | else
|
---|
562 | {
|
---|
563 | texture->baseTexture.pow2Matrix[0] = 1.0f;
|
---|
564 | texture->baseTexture.pow2Matrix[5] = 1.0f;
|
---|
565 | }
|
---|
566 |
|
---|
567 | texture->baseTexture.pow2Matrix[10] = 1.0f;
|
---|
568 | texture->baseTexture.pow2Matrix[15] = 1.0f;
|
---|
569 | texture->target = GL_TEXTURE_2D;
|
---|
570 | texture->cond_np2 = FALSE;
|
---|
571 | }
|
---|
572 | TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
|
---|
573 |
|
---|
574 | /* Generate all the surfaces. */
|
---|
575 | tmp_w = width;
|
---|
576 | tmp_h = height;
|
---|
577 | for (i = 0; i < texture->baseTexture.levels; ++i)
|
---|
578 | {
|
---|
579 | /* Use the callback to create the texture surface. */
|
---|
580 | hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
|
---|
581 | usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
|
---|
582 | if (FAILED(hr))
|
---|
583 | {
|
---|
584 | FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
|
---|
585 | texture->surfaces[i] = NULL;
|
---|
586 | texture_cleanup(texture);
|
---|
587 | return hr;
|
---|
588 | }
|
---|
589 |
|
---|
590 | IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
|
---|
591 | TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
|
---|
592 | surface_set_texture_target(texture->surfaces[i], texture->target);
|
---|
593 | /* Calculate the next mipmap level. */
|
---|
594 | tmp_w = max(1, tmp_w >> 1);
|
---|
595 | tmp_h = max(1, tmp_h >> 1);
|
---|
596 | }
|
---|
597 | texture->baseTexture.internal_preload = texture_internal_preload;
|
---|
598 |
|
---|
599 | return WINED3D_OK;
|
---|
600 | }
|
---|