Henri Verbeet : wined3d: Fix texture creation error handling.
Alexandre Julliard
julliard at winehq.org
Tue Jan 13 10:56:16 CST 2009
Module: wine
Branch: master
Commit: 2654a148deffa2d09107682474f79984463cd65a
URL: http://source.winehq.org/git/wine.git/?a=commit;h=2654a148deffa2d09107682474f79984463cd65a
Author: Henri Verbeet <hverbeet at codeweavers.com>
Date: Tue Jan 13 10:31:57 2009 +0100
wined3d: Fix texture creation error handling.
Doing the levels calculation before the object is created prevents leaking
resources and avoids changing baseTexture.levels after it's been initialized
by basetexture_init().
---
dlls/wined3d/device.c | 85 +++++++++++++++++++++++++++----------------------
1 files changed, 47 insertions(+), 38 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 6717fd8..8594cb7 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -802,6 +802,53 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface, U
return WINED3DERR_INVALIDCALL;
}
+ /* Non-power2 support */
+ if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO))
+ {
+ pow2Width = Width;
+ pow2Height = Height;
+ }
+ else
+ {
+ /* Find the nearest pow2 match */
+ pow2Width = pow2Height = 1;
+ while (pow2Width < Width) pow2Width <<= 1;
+ while (pow2Height < Height) pow2Height <<= 1;
+
+ if (pow2Width != Width || pow2Height != Height)
+ {
+ if (Levels > 1)
+ {
+ WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support\n");
+ return WINED3DERR_INVALIDCALL;
+ }
+ Levels = 1;
+ }
+ }
+
+ /* Calculate levels for mip mapping */
+ if (Usage & WINED3DUSAGE_AUTOGENMIPMAP)
+ {
+ if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
+ {
+ WARN("No mipmap generation support, returning D3DERR_INVALIDCALL\n");
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ if (Levels > 1)
+ {
+ WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL\n");
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ Levels = 1;
+ }
+ else if (!Levels)
+ {
+ Levels = wined3d_log2i(max(Width, Height)) + 1;
+ TRACE("Calculated levels = %d\n", Levels);
+ }
+
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
{
@@ -838,28 +885,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface, U
object->baseTexture.magLookup = magLookup_noFilter;
}
- /** Non-power2 support **/
- if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
- pow2Width = Width;
- pow2Height = Height;
- } else {
- /* Find the nearest pow2 match */
- pow2Width = pow2Height = 1;
- while (pow2Width < Width) pow2Width <<= 1;
- while (pow2Height < Height) pow2Height <<= 1;
-
- if(pow2Width != Width || pow2Height != Height) {
- if(Levels > 1) {
- WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support\n");
- HeapFree(GetProcessHeap(), 0, object);
- *ppTexture = NULL;
- return WINED3DERR_INVALIDCALL;
- } else {
- Levels = 1;
- }
- }
- }
-
/** FIXME: add support for real non-power-two if it's provided by the video card **/
/* Precalculated scaling for 'faked' non power of two texture coords.
Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
@@ -895,22 +920,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface, U
}
TRACE(" xf(%f) yf(%f)\n", object->baseTexture.pow2Matrix[0], object->baseTexture.pow2Matrix[5]);
- /* Calculate levels for mip mapping */
- if (Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
- if(!GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
- WARN("No mipmap generation support, returning D3DERR_INVALIDCALL\n");
- return WINED3DERR_INVALIDCALL;
- }
- if(Levels > 1) {
- WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL\n");
- return WINED3DERR_INVALIDCALL;
- }
- object->baseTexture.levels = 1;
- } else if (Levels == 0) {
- object->baseTexture.levels = wined3d_log2i(max(Width, Height)) + 1;
- TRACE("Calculated levels = %d\n", object->baseTexture.levels);
- }
-
/* Generate all the surfaces */
tmpW = Width;
tmpH = Height;
More information about the wine-cvs
mailing list