Browse Source

Merge pull request #1 from urho3d/master

Updating dev fork
NickRoyer 10 years ago
parent
commit
0302040389
2 changed files with 31 additions and 24 deletions
  1. 16 10
      CMake/Modules/FindUrho3D.cmake
  2. 15 14
      Source/Urho3D/Resource/Image.cpp

+ 16 - 10
CMake/Modules/FindUrho3D.cmake

@@ -43,11 +43,22 @@
 # For example: set URHO3D_HOME=/home/john/usr/local, if the SDK is installed using DESTDIR=/home/john and CMAKE_INSTALL_PREFIX=/usr/local
 #
 
-# If the URHO3D_LIB_TYPE build option changes then invalidate the found library cache
-if (NOT URHO3D_LIB_TYPE STREQUAL URHO3D_FOUND_LIB_TYPE)
+# Library location would be searched (based on URHO3D_HOME variable if provided and in system-wide default location)
+if (NOT URHO3D_HOME AND DEFINED ENV{URHO3D_HOME})
+    file (TO_CMAKE_PATH "$ENV{URHO3D_HOME}" URHO3D_HOME)
+endif ()
+
+# If either of the URHO3D_LIB_TYPE or URHO3D_HOME build options changes then invalidate all the caches
+set (PATH_SUFFIX Urho3D)
+if (NOT URHO3D_LIB_TYPE STREQUAL URHO3D_FOUND_LIB_TYPE OR (DEFINED URHO3D_BASE_INCLUDE_DIR AND NOT URHO3D_BASE_INCLUDE_DIR MATCHES "^${URHO3D_HOME}/include/${PATH_SUFFIX}"))
+    unset (URHO3D_BASE_INCLUDE_DIR CACHE)
     unset (URHO3D_LIBRARIES CACHE)
+    if (WIN32)
+        unset (URHO3D_LIBRARIES_DBG CACHE)
+        unset (URHO3D_DLL_REL CACHE)
+        unset (URHO3D_DLL_DBG CACHE)
+    endif ()
     set (URHO3D_FOUND_LIB_TYPE ${URHO3D_LIB_TYPE} CACHE INTERNAL "Lib type when Urho3D library was last found")
-
     # Urho3D prefers static library type by default while CMake prefers shared one, so we need to change CMake preference to agree with Urho3D
     if (NOT URHO3D_LIB_TYPE STREQUAL SHARED)
         list (REVERSE CMAKE_FIND_LIBRARY_SUFFIXES)
@@ -58,9 +69,8 @@ if (NOT URHO3D_LIB_TYPE STREQUAL URHO3D_FOUND_LIB_TYPE)
     endif ()
 endif ()
 
-set (PATH_SUFFIX Urho3D)
 if (CMAKE_PROJECT_NAME STREQUAL Urho3D AND TARGET Urho3D)
-    # Library location is already known to be in the build tree
+    # A special case where library location is already known to be in the build tree
     set (URHO3D_HOME ${CMAKE_BINARY_DIR})
     set (URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/include ${URHO3D_HOME}/include/${PATH_SUFFIX}/ThirdParty)
     if (URHO3D_PHYSICS)
@@ -75,10 +85,6 @@ if (CMAKE_PROJECT_NAME STREQUAL Urho3D AND TARGET Urho3D)
     set (URHO3D_LIBRARIES Urho3D)
     set (FOUND_MESSAGE "Found Urho3D: as CMake target")
 else ()
-    # Library location would be searched (based on URHO3D_HOME variable if provided and in system-wide default location)
-    if (NOT URHO3D_HOME AND DEFINED ENV{URHO3D_HOME})
-        file (TO_CMAKE_PATH "$ENV{URHO3D_HOME}" URHO3D_HOME)
-    endif ()
     # URHO3D_HOME variable should be an absolute path, so use a non-rooted search even when we are cross-compiling
     if (URHO3D_HOME)
         list (APPEND CMAKE_PREFIX_PATH ${URHO3D_HOME})
@@ -165,4 +171,4 @@ elseif (Urho3D_FIND_REQUIRED)
         "Use URHO3D_HOME environment variable or build option to specify the location of the build tree or SDK installation. ${NOT_FOUND_MESSAGE}")
 endif ()
 
-mark_as_advanced (URHO3D_BASE_INCLUDE_DIR URHO3D_LIBRARIES URHO3D_LIBRARIES_REL URHO3D_LIBRARIES_DBG URHO3D_DLL URHO3D_DLL_REL URHO3D_DLL_DBG URHO3D_HOME)
+mark_as_advanced (URHO3D_BASE_INCLUDE_DIR URHO3D_LIBRARIES URHO3D_LIBRARIES_DBG URHO3D_DLL_REL URHO3D_DLL_DBG URHO3D_HOME)

+ 15 - 14
Source/Urho3D/Resource/Image.cpp

@@ -371,7 +371,7 @@ bool Image::BeginLoad(Deserializer& source)
             unsigned x = ddsd.dwWidth_ / 2;
             unsigned y = ddsd.dwHeight_ / 2;
             unsigned z = ddsd.dwDepth_ / 2;
-            for (unsigned level = ddsd.dwMipMapCount_; level > 0; x /= 2, y /= 2, z /= 2, level -= 1)
+            for (unsigned level = ddsd.dwMipMapCount_; level > 1; x /= 2, y /= 2, z /= 2, --level)
             {
                 blocksWide = (Max(x, 1) + 3) / 4;
                 blocksHeight = (Max(y, 1) + 3) / 4;
@@ -385,7 +385,7 @@ bool Image::BeginLoad(Deserializer& source)
             unsigned x = ddsd.dwWidth_ / 2;
             unsigned y = ddsd.dwHeight_ / 2;
             unsigned z = ddsd.dwDepth_ / 2;
-            for (unsigned level = ddsd.dwMipMapCount_; level > 0; x /= 2, y /= 2, z /= 2, level -= 1)
+            for (unsigned level = ddsd.dwMipMapCount_; level > 1; x /= 2, y /= 2, z /= 2, --level)
                 dataSize += (ddsd.ddpfPixelFormat_.dwRGBBitCount_ / 8) * Max(x, 1) * Max(y, 1) * Max(z, 1);
         }
 
@@ -428,23 +428,24 @@ bool Image::BeginLoad(Deserializer& source)
         {
             URHO3D_PROFILE(ConvertDDSToRGBA);
 
-            SharedPtr<Image> currentImage(this);
-            while (currentImage.NotNull())
+            currentImage = this;
+
+            while (currentImage)
             {
                 unsigned sourcePixelByteSize = ddsd.ddpfPixelFormat_.dwRGBBitCount_ >> 3;
                 unsigned numPixels = dataSize / sourcePixelByteSize;
 
 #define ADJUSTSHIFT(mask, l, r) \
                 if (mask && mask >= 0x100) \
-                                { \
-                                                    while ((mask >> r) >= 0x100) \
-                        ++r; \
-                                } \
-                        else if (mask && mask < 0x80) \
-                                { \
-                                                    while ((mask << l) < 0x80) \
-                        ++l; \
-                                }
+                { \
+                    while ((mask >> r) >= 0x100) \
+                    ++r; \
+                } \
+                else if (mask && mask < 0x80) \
+                { \
+                    while ((mask << l) < 0x80) \
+                    ++l; \
+                }
 
                 unsigned rShiftL = 0, gShiftL = 0, bShiftL = 0, aShiftL = 0;
                 unsigned rShiftR = 0, gShiftR = 0, bShiftR = 0, aShiftR = 0;
@@ -458,7 +459,6 @@ bool Image::BeginLoad(Deserializer& source)
                 ADJUSTSHIFT(aMask, aShiftL, aShiftR)
                 
                 SharedArrayPtr<unsigned char> rgbaData(new unsigned char[numPixels * 4]);
-                SetMemoryUse(numPixels * 4);
 
                 switch (sourcePixelByteSize)
                 {
@@ -514,6 +514,7 @@ bool Image::BeginLoad(Deserializer& source)
 
                 // Replace with converted data
                 currentImage->data_ = rgbaData;
+                currentImage->SetMemoryUse(numPixels * 4);
                 currentImage = currentImage->GetNextSibling();
             }
         }