فهرست منبع

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

Lasse Öörni 12 سال پیش
والد
کامیت
42093ea88c

+ 4 - 0
Docs/ScriptAPI.dox

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

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

@@ -114,11 +114,31 @@ void Texture::SetBackupTexture(Texture* texture)
     backupTexture_ = 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
 bool Texture::IsCompressed() const
 {
 {
     return format_ == D3DFMT_DXT1 || format_ == D3DFMT_DXT3 || format_ == D3DFMT_DXT5;
     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
 int Texture::GetLevelWidth(unsigned level) const
 {
 {
     if (level > levels_)
     if (level > levels_)
@@ -255,20 +275,13 @@ void Texture::LoadParameters(const XMLElement& element)
         if (name == "quality")
         if (name == "quality")
         {
         {
             if (paramElem.HasAttribute("low"))
             if (paramElem.HasAttribute("low"))
-                mipsToSkip_[QUALITY_LOW] = Max(paramElem.GetInt("low"), 0);
+                SetMipsToSkip(QUALITY_LOW, paramElem.GetInt("low"));
             if (paramElem.HasAttribute("med"))
             if (paramElem.HasAttribute("med"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("med"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("med"));
             if (paramElem.HasAttribute("medium"))
             if (paramElem.HasAttribute("medium"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("medium"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("medium"));
             if (paramElem.HasAttribute("high"))
             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")
         if (name == "srgb")

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

@@ -24,7 +24,6 @@
 
 
 #include "Color.h"
 #include "Color.h"
 #include "GPUObject.h"
 #include "GPUObject.h"
-#include "Image.h"
 #include "GraphicsDefs.h"
 #include "GraphicsDefs.h"
 #include "Resource.h"
 #include "Resource.h"
 
 
@@ -57,6 +56,8 @@ public:
     void SetSRGB(bool enable);
     void SetSRGB(bool enable);
     /// Set backup texture to use when rendering to this texture.
     /// Set backup texture to use when rendering to this texture.
     void SetBackupTexture(Texture* 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.
     /// Return texture format.
     unsigned GetFormat() const { return format_; }
     unsigned GetFormat() const { return format_; }
@@ -78,6 +79,8 @@ public:
     bool GetSRGB() const { return sRGB_; }
     bool GetSRGB() const { return sRGB_; }
     /// Return backup texture.
     /// Return backup texture.
     Texture* GetBackupTexture() const { return backupTexture_; }
     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.
     /// Return mip level width, or 0 if level does not exist.
     int GetLevelWidth(unsigned level) const;
     int GetLevelWidth(unsigned level) const;
     /// Return mip level width, or 0 if level does not exist.
     /// Return mip level width, or 0 if level does not exist.
@@ -118,7 +121,7 @@ protected:
     TextureFilterMode filterMode_;
     TextureFilterMode filterMode_;
     /// Addressing mode.
     /// Addressing mode.
     TextureAddressMode addressMode_[MAX_COORDS];
     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];
     unsigned mipsToSkip_[MAX_TEXTURE_QUALITY_LEVELS];
     /// Border color.
     /// Border color.
     Color borderColor_;
     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);
     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.
     /// 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);
     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);
     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.
     /// 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);
     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.
     /// Load one face from a stream. Return true if successful.
     bool Load(CubeMapFace face, Deserializer& source);
     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);
     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.
     /// 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;
     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()
 void Texture::SetParametersDirty()
 {
 {
     parametersDirty_ = true;
     parametersDirty_ = true;
@@ -217,6 +232,11 @@ void Texture::UpdateParameters()
     parametersDirty_ = false;
     parametersDirty_ = false;
 }
 }
 
 
+int Texture::GetMipsToSkip(int quality) const
+{
+    return (quality >= QUALITY_LOW && quality < MAX_TEXTURE_QUALITY_LEVELS) ? mipsToSkip_[quality] : 0;
+}
+
 bool Texture::IsCompressed() const
 bool Texture::IsCompressed() const
 {
 {
     #ifndef GL_ES_VERSION_2_0
     #ifndef GL_ES_VERSION_2_0
@@ -415,20 +435,13 @@ void Texture::LoadParameters(const XMLElement& elem)
         if (name == "quality")
         if (name == "quality")
         {
         {
             if (paramElem.HasAttribute("low"))
             if (paramElem.HasAttribute("low"))
-                mipsToSkip_[QUALITY_LOW] = Max(paramElem.GetInt("low"), 0);
+                SetMipsToSkip(QUALITY_LOW, paramElem.GetInt("low"));
             if (paramElem.HasAttribute("med"))
             if (paramElem.HasAttribute("med"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("med"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("med"));
             if (paramElem.HasAttribute("medium"))
             if (paramElem.HasAttribute("medium"))
-                mipsToSkip_[QUALITY_MEDIUM] = Max(paramElem.GetInt("medium"), 0);
+                SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("medium"));
             if (paramElem.HasAttribute("high"))
             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")
         if (name == "srgb")

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

@@ -22,7 +22,6 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "ArrayPtr.h"
 #include "Color.h"
 #include "Color.h"
 #include "GPUObject.h"
 #include "GPUObject.h"
 #include "GraphicsDefs.h"
 #include "GraphicsDefs.h"
@@ -45,7 +44,7 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~Texture();
     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);
     void SetNumLevels(unsigned levels);
     /// Set filtering mode.
     /// Set filtering mode.
     void SetFilterMode(TextureFilterMode filter);
     void SetFilterMode(TextureFilterMode filter);
@@ -59,6 +58,8 @@ public:
     void SetSRGB(bool enable);
     void SetSRGB(bool enable);
     /// Set backup texture to use when rendering to this texture.
     /// Set backup texture to use when rendering to this texture.
     void SetBackupTexture(Texture* 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.
     /// Dirty the parameters.
     void SetParametersDirty();
     void SetParametersDirty();
     /// Update changed parameters to OpenGL. Called by Graphics when binding the texture.
     /// Update changed parameters to OpenGL. Called by Graphics when binding the texture.
@@ -70,7 +71,7 @@ public:
     unsigned GetFormat() const { return format_; }
     unsigned GetFormat() const { return format_; }
     /// Return whether the texture format is compressed.
     /// Return whether the texture format is compressed.
     bool IsCompressed() const;
     bool IsCompressed() const;
-    /// Return number of mipmap levels.
+    /// Return number of mip levels.
     unsigned GetLevels() const { return levels_; }
     unsigned GetLevels() const { return levels_; }
     /// Return width.
     /// Return width.
     int GetWidth() const { return width_; }
     int GetWidth() const { return width_; }
@@ -90,6 +91,8 @@ public:
     bool GetSRGB() const { return sRGB_; }
     bool GetSRGB() const { return sRGB_; }
     /// Return backup texture.
     /// Return backup texture.
     Texture* GetBackupTexture() const { return backupTexture_; }
     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.
     /// Return mip level width, or 0 if level does not exist.
     int GetLevelWidth(unsigned level) const;
     int GetLevelWidth(unsigned level) const;
     /// Return mip level width, or 0 if level does not exist.
     /// Return mip level width, or 0 if level does not exist.
@@ -110,7 +113,7 @@ public:
     /// Load parameters from an XML file.
     /// Load parameters from an XML file.
     void LoadParameters(XMLFile* xml);
     void LoadParameters(XMLFile* xml);
     /// Load parameters from an XML element.
     /// 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.
     /// Return the corresponding SRGB texture format if supported. If not supported, return format unchanged.
     unsigned GetSRGBFormat(unsigned format);
     unsigned GetSRGBFormat(unsigned format);
     
     
@@ -126,9 +129,9 @@ protected:
     unsigned target_;
     unsigned target_;
     /// Texture format.
     /// Texture format.
     unsigned format_;
     unsigned format_;
-    /// Current mipmap levels.
+    /// Current mip levels.
     unsigned levels_;
     unsigned levels_;
-    /// Requested mipmap levels.
+    /// Requested mip levels.
     unsigned requestedLevels_;
     unsigned requestedLevels_;
     /// Texture width.
     /// Texture width.
     int width_;
     int width_;
@@ -142,7 +145,7 @@ protected:
     TextureFilterMode filterMode_;
     TextureFilterMode filterMode_;
     /// Addressing mode.
     /// Addressing mode.
     TextureAddressMode addressMode_[MAX_COORDS];
     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];
     unsigned mipsToSkip_[MAX_TEXTURE_QUALITY_LEVELS];
     /// Border color.
     /// Border color.
     Color borderColor_;
     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);
     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.
     /// 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);
     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);
     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.
     /// 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);
     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.
     /// Load one face from a stream. Return true if successful.
     bool Load(CubeMapFace face, Deserializer& source);
     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);
     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.
     /// 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, "bool get_sRGB() const", asMETHOD(T, GetSRGB), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_backupTexture(Texture@+)", asMETHOD(T, SetBackupTexture), 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, "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);
     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);
     FT_Done_Face(face);
-        
+    
     SetMemoryUse(GetMemoryUse() + totalTextureSize);
     SetMemoryUse(GetMemoryUse() + totalTextureSize);
     faces_[pointSize] = newFace;
     faces_[pointSize] = newFace;
     return newFace;
     return newFace;
@@ -804,6 +804,7 @@ SharedPtr<FontFace> Font::Pack(const FontFace* fontFace)
 SharedPtr<Texture> Font::LoadFaceTexture(SharedPtr<Image> image)
 SharedPtr<Texture> Font::LoadFaceTexture(SharedPtr<Image> image)
 {
 {
     Texture2D* texture = new Texture2D(context_);
     Texture2D* texture = new Texture2D(context_);
+    texture->SetMipsToSkip(QUALITY_LOW, 0); // No quality reduction
     texture->SetNumLevels(1); // No mipmaps
     texture->SetNumLevels(1); // No mipmaps
     texture->SetAddressMode(COORD_U, ADDRESS_BORDER);
     texture->SetAddressMode(COORD_U, ADDRESS_BORDER);
     texture->SetAddressMode(COORD_V, 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 SetBorderColor(const Color& color);
     void SetSRGB(bool enable);
     void SetSRGB(bool enable);
     void SetBackupTexture(Texture* texture);
     void SetBackupTexture(Texture* texture);
+    void SetMipsToSkip(int quality, int mips);
     
     
     unsigned GetFormat() const;
     unsigned GetFormat() const;
     bool IsCompressed() const;
     bool IsCompressed() const;
@@ -19,6 +20,7 @@ class Texture : public Resource
     const Color& GetBorderColor() const;
     const Color& GetBorderColor() const;
     bool GetSRGB() const;
     bool GetSRGB() const;
     Texture* GetBackupTexture() const;
     Texture* GetBackupTexture() const;
+    int GetMipsToSkip(int quality) const;
     int GetLevelWidth(unsigned level) const;
     int GetLevelWidth(unsigned level) const;
     int GetLevelHeight(unsigned level) const;
     int GetLevelHeight(unsigned level) const;
     TextureUsage GetUsage() const;
     TextureUsage GetUsage() const;