Просмотр исходного кода

Removed unnecessary members in Image. SaveDDS now returns null and logs a warning on non-desktop platforms. Hopefully now buildable on linux and osx :/

Matt Benic 9 лет назад
Родитель
Сommit
19674aba22

+ 19 - 9
Source/Atomic/Resource/Image.cpp

@@ -247,9 +247,7 @@ Image::Image(Context* context) :
     components_(0),
     components_(0),
     cubemap_(false),
     cubemap_(false),
     array_(false),
     array_(false),
-    sRGB_(false),
-    pot_(false),
-    hasAlphaChannel_(false)
+    sRGB_(false)
 {
 {
 }
 }
 
 
@@ -803,8 +801,6 @@ bool Image::SetSize(int width, int height, int depth, unsigned components)
     components_ = components;
     components_ = components;
     compressedFormat_ = CF_NONE;
     compressedFormat_ = CF_NONE;
     numCompressedLevels_ = 0;
     numCompressedLevels_ = 0;
-    pot_ = IsPowerOfTwo(width_) && IsPowerOfTwo(height_);
-    hasAlphaChannel_ = components > 3;
     nextLevel_.Reset();
     nextLevel_.Reset();
 
 
     SetMemoryUse(width * height * depth * components);
     SetMemoryUse(width * height * depth * components);
@@ -1218,6 +1214,7 @@ bool Image::SaveJPG(const String& fileName, int quality) const
 
 
 bool Image::SaveDDS(const String& fileName) const
 bool Image::SaveDDS(const String& fileName) const
 {
 {
+#if defined(ATOMIC_PLATFORM_WINDOWS) || defined (ATOMIC_PLATFORM_LINUX) || defined (ATOMIC_PLATFORM_OSX)
     PROFILE(SaveImageDDS);
     PROFILE(SaveImageDDS);
 
 
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
@@ -1247,7 +1244,7 @@ bool Image::SaveDDS(const String& fileName) const
         compParams.set_flag(cCRNCompFlagDXT1AForTransparency, false);
         compParams.set_flag(cCRNCompFlagDXT1AForTransparency, false);
         compParams.set_flag(cCRNCompFlagHierarchical, true);
         compParams.set_flag(cCRNCompFlagHierarchical, true);
         compParams.m_file_type = cCRNFileTypeDDS;
         compParams.m_file_type = cCRNFileTypeDDS;
-        compParams.m_format = (hasAlphaChannel_ ? cCRNFmtDXT5 : cCRNFmtDXT1);
+        compParams.m_format = (HasAlphaChannel() ? cCRNFmtDXT5 : cCRNFmtDXT1);
 
 
         compParams.m_pImages[0][0] = (uint32_t*)data_.Get();
         compParams.m_pImages[0][0] = (uint32_t*)data_.Get();
 
 
@@ -1297,10 +1294,23 @@ bool Image::SaveDDS(const String& fileName) const
         
         
         // #623 END TODO
         // #623 END TODO
     }
     }
+#else
+    LOGWARNING("Image::SaveDDS - Unsupported on current platform");
+#endif
 
 
     return false;
     return false;
 }
 }
 
 
+bool Image::IsPOT() const
+{
+    return IsPowerOfTwo(width_) && IsPowerOfTwo(height_);
+}
+
+bool Image::HasAlphaChannel() const
+{
+    return components_ > 3;
+}
+
 Color Image::GetPixel(int x, int y) const
 Color Image::GetPixel(int x, int y) const
 {
 {
     return GetPixel(x, y, 0);
     return GetPixel(x, y, 0);
@@ -2127,10 +2137,10 @@ unsigned char* Image::GetImageData(Deserializer& source, int& width, int& height
     // #623 BEGIN TODO: Crunch expects all 4 components. This isn't ideal, but since
     // #623 BEGIN TODO: Crunch expects all 4 components. This isn't ideal, but since
     // precompressed versions should always be loaded anyway it doesn't matter.
     // precompressed versions should always be loaded anyway it doesn't matter.
     // Might need to handle differently per platform.
     // Might need to handle differently per platform.
-    components = 4;
-    return stbi_load_from_memory(buffer.Get(), dataSize, &width, &height, nullptr, components);
+        components = 4;
+        return stbi_load_from_memory(buffer.Get(), dataSize, &width, &height, nullptr, components);
     // #623 END TODO: Crunch expects all 4 components. This isn't ideal, but since
     // #623 END TODO: Crunch expects all 4 components. This isn't ideal, but since
-}
+    }
 
 
 void Image::FreeImageData(unsigned char* pixelData)
 void Image::FreeImageData(unsigned char* pixelData)
 {
 {

+ 2 - 6
Source/Atomic/Resource/Image.h

@@ -147,9 +147,9 @@ public:
     /// Whether this texture is in sRGB, only relevant for DDS.
     /// Whether this texture is in sRGB, only relevant for DDS.
     bool IsSRGB() const { return sRGB_; }
     bool IsSRGB() const { return sRGB_; }
     /// Whether this texture has power of two dimensions
     /// Whether this texture has power of two dimensions
-    bool IsPOT() const { return pot_; }
+    bool IsPOT() const;
     /// Whether this texture has an alpha channel
     /// Whether this texture has an alpha channel
-    bool HasAlphaChannel() const { return hasAlphaChannel_; }
+    bool HasAlphaChannel() const;
 
 
     /// Return a 2D pixel color.
     /// Return a 2D pixel color.
     Color GetPixel(int x, int y) const;
     Color GetPixel(int x, int y) const;
@@ -225,10 +225,6 @@ private:
     bool array_;
     bool array_;
     /// Data is sRGB.
     /// Data is sRGB.
     bool sRGB_;
     bool sRGB_;
-    /// Dimensions are power of two
-    bool pot_;
-    /// Image has alpha channel
-    bool hasAlphaChannel_;
     /// Compressed format.
     /// Compressed format.
     CompressedFormat compressedFormat_;
     CompressedFormat compressedFormat_;
     /// Pixel data.
     /// Pixel data.

+ 1 - 1
Source/ThirdParty/CMakeLists.txt

@@ -1,6 +1,5 @@
 
 
 add_subdirectory(Box2D)
 add_subdirectory(Box2D)
-add_subdirectory(crunch)
 add_subdirectory(Duktape)
 add_subdirectory(Duktape)
 add_subdirectory(FreeType)
 add_subdirectory(FreeType)
 add_subdirectory(JO)
 add_subdirectory(JO)
@@ -35,6 +34,7 @@ if (NOT IOS AND NOT ANDROID AND NOT EMSCRIPTEN)
     add_subdirectory(SQLite)
     add_subdirectory(SQLite)
     add_subdirectory(Poco)
     add_subdirectory(Poco)
     add_subdirectory(nativefiledialog)
     add_subdirectory(nativefiledialog)
+    add_subdirectory(crunch)
 endif ()
 endif ()
 
 
 if (LINUX OR APPLE AND NOT IOS)
 if (LINUX OR APPLE AND NOT IOS)

+ 11 - 0
Source/ThirdParty/crunch/CMakeLists.txt

@@ -5,11 +5,22 @@ file (GLOB CRNLIB_CPP_FILES crnlib/*.cpp)
 file (GLOB CRNLIB_H_FILES crnlib/*.h)
 file (GLOB CRNLIB_H_FILES crnlib/*.h)
 file (GLOB INC_H_FILES inc/*.h)
 file (GLOB INC_H_FILES inc/*.h)
 
 
+# Remove windows only files
+if (NOT OS_WINDOWS)
+
+    list(REMOVE_ITEM CRNLIB_CPP_FILES "crnlib/lzma_LzFindMt.cpp")
+    list(REMOVE_ITEM CRNLIB_CPP_FILES "crnlib/lzma_Threads.cpp")
+    list(REMOVE_ITEM CRNLIB_H_FILES "crnlib/lzma_LzFindMt.h")
+    list(REMOVE_ITEM CRNLIB_H_FILES "crnlib/lzma_Threads.h")
+
+endif ()
+
 set (SOURCE_FILES ${CRNLIB_CPP_FILES} ${CRNLIB_H_FILES} ${INC_H_FILES})
 set (SOURCE_FILES ${CRNLIB_CPP_FILES} ${CRNLIB_H_FILES} ${INC_H_FILES})
 
 
 # These are used to create visual studio folders.
 # These are used to create visual studio folders.
 source_group(crnlib FILES ${CRNLIB_CPP_FILES} ${CRNLIB_H_FILES})
 source_group(crnlib FILES ${CRNLIB_CPP_FILES} ${CRNLIB_H_FILES})
 source_group(inc FILES ${INC_H_FILES})
 source_group(inc FILES ${INC_H_FILES})
 
 
+
 add_library(crunch ${SOURCE_FILES})
 add_library(crunch ${SOURCE_FILES})