Jelajahi Sumber

Allow programmatic control of the mip reduction settings of Texture.
Fixed fonts loading incorrectly when texture quality is not at maximum.

Lasse Öörni 12 tahun lalu
induk
melakukan
42093ea88c

+ 4 - 0
Docs/ScriptAPI.dox

@@ -1910,6 +1910,7 @@ Properties:<br>
 - Color borderColor
 - bool sRGB
 - Texture@ backupTexture
+- int[] mipsToSkip
 - bool dataLost (readonly)
 
 
@@ -1981,6 +1982,7 @@ Properties:<br>
 - Color borderColor
 - bool sRGB
 - Texture@ backupTexture
+- int[] mipsToSkip
 - bool dataLost (readonly)
 - RenderSurface@ renderSurface (readonly)
 
@@ -2018,6 +2020,7 @@ Properties:<br>
 - Color borderColor
 - bool sRGB
 - Texture@ backupTexture
+- int[] mipsToSkip
 - bool dataLost (readonly)
 - RenderSurface@[] renderSurfaces (readonly)
 
@@ -5841,6 +5844,7 @@ Properties:<br>
 - float angularRestThreshold
 - float angularDamping
 - float friction
+- float rollingFriction
 - float restitution
 - float contactProcessingThreshold
 - float ccdRadius

+ 24 - 11
Source/Engine/Graphics/Direct3D9/D3D9Texture.cpp

@@ -114,11 +114,31 @@ void Texture::SetBackupTexture(Texture* texture)
     backupTexture_ = texture;
 }
 
+void Texture::SetMipsToSkip(int quality, int mips)
+{
+    if (quality >= QUALITY_LOW && quality < MAX_TEXTURE_QUALITY_LEVELS)
+    {
+        mipsToSkip_[quality] = mips;
+        
+        // Make sure a higher quality level does not actually skip more mips
+        for (int i = 1; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
+        {
+            if (mipsToSkip_[i] > mipsToSkip_[i - 1])
+                mipsToSkip_[i] = mipsToSkip_[i - 1];
+        }
+    }
+}
+
 bool Texture::IsCompressed() const
 {
     return format_ == D3DFMT_DXT1 || format_ == D3DFMT_DXT3 || format_ == D3DFMT_DXT5;
 }
 
+int Texture::GetMipsToSkip(int quality) const
+{
+    return (quality >= QUALITY_LOW && quality < MAX_TEXTURE_QUALITY_LEVELS) ? mipsToSkip_[quality] : 0;
+}
+
 int Texture::GetLevelWidth(unsigned level) const
 {
     if (level > levels_)
@@ -255,20 +275,13 @@ void Texture::LoadParameters(const XMLElement& element)
         if (name == "quality")
         {
             if (paramElem.HasAttribute("low"))
-                mipsToSkip_[QUALITY_LOW] = Max(paramElem.GetInt("low"), 0);
+                SetMipsToSkip(QUALITY_LOW, paramElem.GetInt("low"));
             if (paramElem.HasAttribute("med"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("med"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("med"));
             if (paramElem.HasAttribute("medium"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("medium"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("medium"));
             if (paramElem.HasAttribute("high"))
-                mipsToSkip_[QUALITY_HIGH] = Max(paramElem.GetInt("high"), 0);
-            
-            // Make sure a higher quality level does not actually skip more mips
-            for (int i = 1; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
-            {
-                if (mipsToSkip_[i] > mipsToSkip_[i - 1])
-                    mipsToSkip_[i] = mipsToSkip_[i - 1];
-            }
+                SetMipsToSkip(QUALITY_HIGH, paramElem.GetInt("high"));
         }
 
         if (name == "srgb")

+ 5 - 2
Source/Engine/Graphics/Direct3D9/D3D9Texture.h

@@ -24,7 +24,6 @@
 
 #include "Color.h"
 #include "GPUObject.h"
-#include "Image.h"
 #include "GraphicsDefs.h"
 #include "Resource.h"
 
@@ -57,6 +56,8 @@ public:
     void SetSRGB(bool enable);
     /// Set backup texture to use when rendering to this texture.
     void SetBackupTexture(Texture* texture);
+    /// Set mip levels to skip on a quality setting when loading. Ensures higher quality levels do not skip more.
+    void SetMipsToSkip(int quality, int mips);
     
     /// Return texture format.
     unsigned GetFormat() const { return format_; }
@@ -78,6 +79,8 @@ public:
     bool GetSRGB() const { return sRGB_; }
     /// Return backup texture.
     Texture* GetBackupTexture() const { return backupTexture_; }
+    /// Return mip levels to skip on a quality setting when loading.
+    int GetMipsToSkip(int quality) const;
     /// Return mip level width, or 0 if level does not exist.
     int GetLevelWidth(unsigned level) const;
     /// Return mip level width, or 0 if level does not exist.
@@ -118,7 +121,7 @@ protected:
     TextureFilterMode filterMode_;
     /// Addressing mode.
     TextureAddressMode addressMode_[MAX_COORDS];
-    /// Mipmaps to skip when loading.
+    /// Mip levels to skip when loading per texture quality setting.
     unsigned mipsToSkip_[MAX_TEXTURE_QUALITY_LEVELS];
     /// Border color.
     Color borderColor_;

+ 1 - 1
Source/Engine/Graphics/Direct3D9/D3D9Texture2D.h

@@ -57,7 +57,7 @@ public:
     bool SetSize(int width, int height, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a mip level. Return true if successful.
     bool SetData(unsigned level, int x, int y, int width, int height, const void* data);
-    /// Load from an image. Return true if successful.
+    /// Load from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool Load(SharedPtr<Image> image, bool useAlpha = false);
     
     /// Get data from a mip level. The destination buffer must be big enough. Return true if successful.

+ 1 - 1
Source/Engine/Graphics/Direct3D9/D3D9TextureCube.h

@@ -60,7 +60,7 @@ public:
     bool SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data);
     /// Load one face from a stream. Return true if successful.
     bool Load(CubeMapFace face, Deserializer& source);
-    /// Load one face from an image. Return true if successful.
+    /// Load one face from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool Load(CubeMapFace face, SharedPtr<Image> image, bool useAlpha = false);
     
     /// Get data from a face's mip level. The destination buffer must be big enough. Return true if successful.

+ 24 - 11
Source/Engine/Graphics/OpenGL/OGLTexture.cpp

@@ -144,6 +144,21 @@ void Texture::SetBackupTexture(Texture* texture)
     backupTexture_ = texture;
 }
 
+void Texture::SetMipsToSkip(int quality, int mips)
+{
+    if (quality >= QUALITY_LOW && quality < MAX_TEXTURE_QUALITY_LEVELS)
+    {
+        mipsToSkip_[quality] = mips;
+        
+        // Make sure a higher quality level does not actually skip more mips
+        for (int i = 1; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
+        {
+            if (mipsToSkip_[i] > mipsToSkip_[i - 1])
+                mipsToSkip_[i] = mipsToSkip_[i - 1];
+        }
+    }
+}
+
 void Texture::SetParametersDirty()
 {
     parametersDirty_ = true;
@@ -217,6 +232,11 @@ void Texture::UpdateParameters()
     parametersDirty_ = false;
 }
 
+int Texture::GetMipsToSkip(int quality) const
+{
+    return (quality >= QUALITY_LOW && quality < MAX_TEXTURE_QUALITY_LEVELS) ? mipsToSkip_[quality] : 0;
+}
+
 bool Texture::IsCompressed() const
 {
     #ifndef GL_ES_VERSION_2_0
@@ -415,20 +435,13 @@ void Texture::LoadParameters(const XMLElement& elem)
         if (name == "quality")
         {
             if (paramElem.HasAttribute("low"))
-                mipsToSkip_[QUALITY_LOW] = Max(paramElem.GetInt("low"), 0);
+                SetMipsToSkip(QUALITY_LOW, paramElem.GetInt("low"));
             if (paramElem.HasAttribute("med"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("med"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("med"));
             if (paramElem.HasAttribute("medium"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("medium"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("medium"));
             if (paramElem.HasAttribute("high"))
-                mipsToSkip_[QUALITY_HIGH] = Max(paramElem.GetInt("high"), 0);
-            
-            // Make sure a higher quality level does not actually skip more mips
-            for (int i = 1; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
-            {
-                if (mipsToSkip_[i] > mipsToSkip_[i - 1])
-                    mipsToSkip_[i] = mipsToSkip_[i - 1];
-            }
+                SetMipsToSkip(QUALITY_HIGH, paramElem.GetInt("high"));
         }
         
         if (name == "srgb")

+ 10 - 7
Source/Engine/Graphics/OpenGL/OGLTexture.h

@@ -22,7 +22,6 @@
 
 #pragma once
 
-#include "ArrayPtr.h"
 #include "Color.h"
 #include "GPUObject.h"
 #include "GraphicsDefs.h"
@@ -45,7 +44,7 @@ public:
     /// Destruct.
     virtual ~Texture();
     
-    /// Set number of requested mipmap levels. Needs to be called before setting size.
+    /// Set number of requested mip levels. Needs to be called before setting size.
     void SetNumLevels(unsigned levels);
     /// Set filtering mode.
     void SetFilterMode(TextureFilterMode filter);
@@ -59,6 +58,8 @@ public:
     void SetSRGB(bool enable);
     /// Set backup texture to use when rendering to this texture.
     void SetBackupTexture(Texture* texture);
+    /// Set mip levels to skip on a quality setting when loading. Ensures higher quality levels do not skip more.
+    void SetMipsToSkip(int quality, int mips);
     /// Dirty the parameters.
     void SetParametersDirty();
     /// Update changed parameters to OpenGL. Called by Graphics when binding the texture.
@@ -70,7 +71,7 @@ public:
     unsigned GetFormat() const { return format_; }
     /// Return whether the texture format is compressed.
     bool IsCompressed() const;
-    /// Return number of mipmap levels.
+    /// Return number of mip levels.
     unsigned GetLevels() const { return levels_; }
     /// Return width.
     int GetWidth() const { return width_; }
@@ -90,6 +91,8 @@ public:
     bool GetSRGB() const { return sRGB_; }
     /// Return backup texture.
     Texture* GetBackupTexture() const { return backupTexture_; }
+    /// Return mip levels to skip on a quality setting when loading.
+    int GetMipsToSkip(int quality) const;
     /// Return mip level width, or 0 if level does not exist.
     int GetLevelWidth(unsigned level) const;
     /// Return mip level width, or 0 if level does not exist.
@@ -110,7 +113,7 @@ public:
     /// Load parameters from an XML file.
     void LoadParameters(XMLFile* xml);
     /// Load parameters from an XML element.
-    void LoadParameters(const XMLElement& elem);
+    void LoadParameters(const XMLElement& element);
     /// Return the corresponding SRGB texture format if supported. If not supported, return format unchanged.
     unsigned GetSRGBFormat(unsigned format);
     
@@ -126,9 +129,9 @@ protected:
     unsigned target_;
     /// Texture format.
     unsigned format_;
-    /// Current mipmap levels.
+    /// Current mip levels.
     unsigned levels_;
-    /// Requested mipmap levels.
+    /// Requested mip levels.
     unsigned requestedLevels_;
     /// Texture width.
     int width_;
@@ -142,7 +145,7 @@ protected:
     TextureFilterMode filterMode_;
     /// Addressing mode.
     TextureAddressMode addressMode_[MAX_COORDS];
-    /// Mipmaps to skip when loading.
+    /// Mip levels to skip when loading per texture quality setting.
     unsigned mipsToSkip_[MAX_TEXTURE_QUALITY_LEVELS];
     /// Border color.
     Color borderColor_;

+ 1 - 1
Source/Engine/Graphics/OpenGL/OGLTexture2D.h

@@ -56,7 +56,7 @@ public:
     bool SetSize(int width, int height, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a mip level. Return true if successful.
     bool SetData(unsigned level, int x, int y, int width, int height, const void* data);
-    /// Load from an image. Return true if successful.
+    /// Load from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool Load(SharedPtr<Image> image, bool useAlpha = false);
     
     /// Get data from a mip level. The destination buffer must be big enough. Return true if successful.

+ 1 - 1
Source/Engine/Graphics/OpenGL/OGLTextureCube.h

@@ -60,7 +60,7 @@ public:
     bool SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data);
     /// Load one face from a stream. Return true if successful.
     bool Load(CubeMapFace face, Deserializer& source);
-    /// Load one face from an image. Return true if successful.
+    /// Load one face from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool Load(CubeMapFace face, SharedPtr<Image> image, bool useAlpha = false);
     
     /// Get data from a face's mip level. The destination buffer must be big enough. Return true if successful.

+ 2 - 0
Source/Engine/Script/APITemplates.h

@@ -723,6 +723,8 @@ template <class T> void RegisterTexture(asIScriptEngine* engine, const char* cla
     engine->RegisterObjectMethod(className, "bool get_sRGB() const", asMETHOD(T, GetSRGB), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_backupTexture(Texture@+)", asMETHOD(T, SetBackupTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Texture@+ get_backupTexture() const", asMETHOD(T, GetBackupTexture), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_mipsToSkip(int, int)", asMETHOD(T, SetMipsToSkip), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_mipsToSkip(int) const", asMETHOD(T, GetMipsToSkip), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_dataLost() const", asMETHODPR(T, IsDataLost, () const, bool), asCALL_THISCALL);
 }
 

+ 2 - 1
Source/Engine/UI/Font.cpp

@@ -558,7 +558,7 @@ const FontFace* Font::GetFaceTTF(int pointSize)
     }
     
     FT_Done_Face(face);
-        
+    
     SetMemoryUse(GetMemoryUse() + totalTextureSize);
     faces_[pointSize] = newFace;
     return newFace;
@@ -804,6 +804,7 @@ SharedPtr<FontFace> Font::Pack(const FontFace* fontFace)
 SharedPtr<Texture> Font::LoadFaceTexture(SharedPtr<Image> image)
 {
     Texture2D* texture = new Texture2D(context_);
+    texture->SetMipsToSkip(QUALITY_LOW, 0); // No quality reduction
     texture->SetNumLevels(1); // No mipmaps
     texture->SetAddressMode(COORD_U, ADDRESS_BORDER);
     texture->SetAddressMode(COORD_V, ADDRESS_BORDER),

+ 2 - 0
Source/Extras/LuaScript/pkgs/Graphics/Texture.pkg

@@ -8,6 +8,7 @@ class Texture : public Resource
     void SetBorderColor(const Color& color);
     void SetSRGB(bool enable);
     void SetBackupTexture(Texture* texture);
+    void SetMipsToSkip(int quality, int mips);
     
     unsigned GetFormat() const;
     bool IsCompressed() const;
@@ -19,6 +20,7 @@ class Texture : public Resource
     const Color& GetBorderColor() const;
     bool GetSRGB() const;
     Texture* GetBackupTexture() const;
+    int GetMipsToSkip(int quality) const;
     int GetLevelWidth(unsigned level) const;
     int GetLevelHeight(unsigned level) const;
     TextureUsage GetUsage() const;