Browse Source

Bugfix: OpenGL now respects min/max mipmap values specified in a sampler state

BearishSun 8 years ago
parent
commit
5d331c2f55

+ 4 - 4
Source/BansheeCore/RenderAPI/BsSamplerState.h

@@ -78,7 +78,7 @@ namespace bs
 		const UVWAddressingMode& getTextureAddressingMode() const { return mData.addressMode; }
 
 		/** Gets the filtering used when sampling from a texture. */
-        FilterOptions getTextureFiltering(FilterType ftpye) const;
+		FilterOptions getTextureFiltering(FilterType ftpye) const;
 
 		/**
 		 * Gets the anisotropy level. Higher anisotropy means better filtering for textures displayed on an angled slope 
@@ -133,8 +133,8 @@ namespace bs
 	 * Sim thread.
 	 */
 	class BS_CORE_EXPORT SamplerState : public IReflectable, public CoreObject
-    {
-    public:
+	{
+	public:
 		virtual ~SamplerState();
 
 		/**	Returns information about the sampler state. */
@@ -170,7 +170,7 @@ namespace bs
 		friend class SamplerStateRTTI;
 		static RTTITypeBase* getRTTIStatic();
 		RTTITypeBase* getRTTI() const override;
-    };
+	};
 
 	/** @} */
 

+ 3 - 3
Source/BansheeCore/Scene/BsTransform.h

@@ -50,19 +50,19 @@ namespace bs
 		const Vector3& scl() const { return mScale; }
 
 		/** 
-		 * Converts the provided world position to a space relative to the provided parent, as sets it as the current
+		 * Converts the provided world position to a space relative to the provided parent, and sets it as the current
 		 * transform's position. 
 		 */
 		void setWorldPosition(const Vector3& position, const Transform& parent);
 
 		/** 
-		 * Converts the provided world rotation to a space relative to the provided parent, as sets it as the current
+		 * Converts the provided world rotation to a space relative to the provided parent, and sets it as the current
 		 * transform's rotation. 
 		 */
 		void setWorldRotation(const Quaternion& rotation, const Transform& parent);
 
 		/** 
-		 * Converts the provided world scale to a space relative to the provided parent, as sets it as the current
+		 * Converts the provided world scale to a space relative to the provided parent, and sets it as the current
 		 * transform's scale. 
 		 */
 		void setWorldScale(const Vector3& scale, const Transform& parent);

+ 11 - 0
Source/BansheeGLRenderAPI/BsGLRenderAPI.cpp

@@ -585,7 +585,9 @@ namespace bs { namespace ct
 
 							setTextureAnisotropy(unit, stateProps.getTextureAnisotropy());
 							setTextureCompareMode(unit, stateProps.getComparisonFunction());
+
 							setTextureMipmapBias(unit, stateProps.getTextureMipmapBias());
+							setTextureMipmapRange(unit, stateProps.getMinimumMip(), stateProps.getMaximumMip());
 
 							const UVWAddressingMode& uvw = stateProps.getTextureAddressingMode();
 							setTextureAddressingMode(unit, uvw);
@@ -1603,6 +1605,15 @@ namespace bs { namespace ct
 		BS_CHECK_GL_ERROR();
 	}
 
+	void GLRenderAPI::setTextureMipmapRange(UINT16 unit, float min, float max)
+	{
+		glTexParameterf(mTextureInfos[unit].type, GL_TEXTURE_MIN_LOD, min);
+		BS_CHECK_GL_ERROR();
+
+		glTexParameterf(mTextureInfos[unit].type, GL_TEXTURE_MAX_LOD, max);
+		BS_CHECK_GL_ERROR();
+	}
+
 	void GLRenderAPI::setSceneBlending(BlendFactor sourceFactor, BlendFactor destFactor, BlendOperation op)
 	{
 		GLint sourceBlend = getBlendMode(sourceFactor);

+ 7 - 0
Source/BansheeGLRenderAPI/BsGLRenderAPI.h

@@ -194,6 +194,13 @@ namespace bs { namespace ct
 		 */
 		void setTextureMipmapBias(UINT16 unit, float bias);
 
+		/**
+		 * Sets a valid range for mipmaps (LOD) for a given texture unit. @p min limits the selection of the highest
+		 * resolution mipmap (lowest level), and @p max limits the selection of the lowest resolution mipmap (highest
+		 * level).
+		 */
+		void setTextureMipmapRange(UINT16 unit, float min, float max);
+
 		/**
 		 * Allows you to specify how is the texture bound to the specified texture unit filtered. Different filter types are
 		 * used for different situations like magnifying or minifying a texture.

+ 2 - 0
Source/BansheeGLRenderAPI/BsGLTextureView.cpp

@@ -63,6 +63,8 @@ namespace bs { namespace ct {
 		}
 
 #if BS_OPENGL_4_3 || BS_OPENGLES_3_1
+		GLuint originalTexture = texture->getGLID();
+
 		glGenTextures(1, &mViewID);
 		BS_CHECK_GL_ERROR();