Browse Source

Add some more graphics feature and limit queries (resolves issue #1234).

love.graphics.getSupported():
 - Added “fullnpot” field, is true everywhere except on some older mobile devices. If false, mipmapping and wrap modes other than “clamp” can’t be used on non-power-of-two sized textures.
 - Added “pixelshaderhighp” field, is true everywhere except some older mobile devices. If false, “highp” precision can’t be used in pixel shaders and love will default to “mediump” instead.

love.graphics.getSystemLimits():
- Added “anisotropy” field, gets the maximum amount of anisotropy you can specify in Texture:setFilter. love will clamp anisotropy arguments greater than this value.

--HG--
branch : minor
Alex Szpakowski 8 years ago
parent
commit
f85ee6b504

+ 3 - 0
src/modules/graphics/Graphics.cpp

@@ -258,6 +258,8 @@ StringMap<Graphics::Feature, Graphics::FEATURE_MAX_ENUM>::Entry Graphics::featur
 	{ "multicanvasformats", FEATURE_MULTI_CANVAS_FORMATS },
 	{ "multicanvasformats", FEATURE_MULTI_CANVAS_FORMATS },
 	{ "clampzero", FEATURE_CLAMP_ZERO },
 	{ "clampzero", FEATURE_CLAMP_ZERO },
 	{ "lighten", FEATURE_LIGHTEN },
 	{ "lighten", FEATURE_LIGHTEN },
+	{ "fullnpot", FEATURE_FULL_NPOT },
+	{ "pixelshaderhighp", FEATURE_PIXEL_SHADER_HIGHP },
 };
 };
 
 
 StringMap<Graphics::Feature, Graphics::FEATURE_MAX_ENUM> Graphics::features(Graphics::featureEntries, sizeof(Graphics::featureEntries));
 StringMap<Graphics::Feature, Graphics::FEATURE_MAX_ENUM> Graphics::features(Graphics::featureEntries, sizeof(Graphics::featureEntries));
@@ -268,6 +270,7 @@ StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM>::Entry Graphics::syst
 	{ "texturesize", LIMIT_TEXTURE_SIZE },
 	{ "texturesize", LIMIT_TEXTURE_SIZE },
 	{ "multicanvas", LIMIT_MULTI_CANVAS },
 	{ "multicanvas", LIMIT_MULTI_CANVAS },
 	{ "canvasmsaa",  LIMIT_CANVAS_MSAA  },
 	{ "canvasmsaa",  LIMIT_CANVAS_MSAA  },
+	{ "anisotropy",  LIMIT_ANISOTROPY   },
 };
 };
 
 
 StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM> Graphics::systemLimits(Graphics::systemLimitEntries, sizeof(Graphics::systemLimitEntries));
 StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM> Graphics::systemLimits(Graphics::systemLimitEntries, sizeof(Graphics::systemLimitEntries));

+ 3 - 0
src/modules/graphics/Graphics.h

@@ -151,6 +151,8 @@ public:
 		FEATURE_MULTI_CANVAS_FORMATS,
 		FEATURE_MULTI_CANVAS_FORMATS,
 		FEATURE_CLAMP_ZERO,
 		FEATURE_CLAMP_ZERO,
 		FEATURE_LIGHTEN,
 		FEATURE_LIGHTEN,
+		FEATURE_FULL_NPOT,
+		FEATURE_PIXEL_SHADER_HIGHP,
 		FEATURE_MAX_ENUM
 		FEATURE_MAX_ENUM
 	};
 	};
 
 
@@ -167,6 +169,7 @@ public:
 		LIMIT_TEXTURE_SIZE,
 		LIMIT_TEXTURE_SIZE,
 		LIMIT_MULTI_CANVAS,
 		LIMIT_MULTI_CANVAS,
 		LIMIT_CANVAS_MSAA,
 		LIMIT_CANVAS_MSAA,
+		LIMIT_ANISOTROPY,
 		LIMIT_MAX_ENUM
 		LIMIT_MAX_ENUM
 	};
 	};
 
 

+ 6 - 0
src/modules/graphics/opengl/Graphics.cpp

@@ -2009,6 +2009,8 @@ double Graphics::getSystemLimit(SystemLimit limittype) const
 		return (double) gl.getMaxRenderTargets();
 		return (double) gl.getMaxRenderTargets();
 	case Graphics::LIMIT_CANVAS_MSAA:
 	case Graphics::LIMIT_CANVAS_MSAA:
 		return (double) gl.getMaxRenderbufferSamples();
 		return (double) gl.getMaxRenderbufferSamples();
+	case Graphics::LIMIT_ANISOTROPY:
+		return (double) gl.getMaxAnisotropy();
 	default:
 	default:
 		return 0.0;
 		return 0.0;
 	}
 	}
@@ -2024,6 +2026,10 @@ bool Graphics::isSupported(Feature feature) const
 		return gl.isClampZeroTextureWrapSupported();
 		return gl.isClampZeroTextureWrapSupported();
 	case FEATURE_LIGHTEN:
 	case FEATURE_LIGHTEN:
 		return GLAD_VERSION_1_4 || GLAD_ES_VERSION_3_0 || GLAD_EXT_blend_minmax;
 		return GLAD_VERSION_1_4 || GLAD_ES_VERSION_3_0 || GLAD_EXT_blend_minmax;
+	case FEATURE_FULL_NPOT:
+		return GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot;
+	case FEATURE_PIXEL_SHADER_HIGHP:
+		return gl.isPixelShaderHighpSupported();
 	default:
 	default:
 		return false;
 		return false;
 	}
 	}

+ 21 - 0
src/modules/graphics/opengl/OpenGL.cpp

@@ -65,6 +65,7 @@ static void *LOVEGetProcAddress(const char *name)
 OpenGL::OpenGL()
 OpenGL::OpenGL()
 	: stats()
 	: stats()
 	, contextInitialized(false)
 	, contextInitialized(false)
+	, pixelShaderHighpSupported(false)
 	, maxAnisotropy(1.0f)
 	, maxAnisotropy(1.0f)
 	, maxTextureSize(0)
 	, maxTextureSize(0)
 	, maxRenderTargets(1)
 	, maxRenderTargets(1)
@@ -268,6 +269,16 @@ void OpenGL::initOpenGLFunctions()
 
 
 void OpenGL::initMaxValues()
 void OpenGL::initMaxValues()
 {
 {
+	if (GLAD_ES_VERSION_2_0 && !GLAD_ES_VERSION_3_0)
+	{
+		GLint range = 0;
+		GLint precision = 0;
+		glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, &range, &precision);
+		pixelShaderHighpSupported = range > 0;
+	}
+	else
+		pixelShaderHighpSupported = true;
+
 	// We'll need this value to clamp anisotropy.
 	// We'll need this value to clamp anisotropy.
 	if (GLAD_EXT_texture_filter_anisotropic)
 	if (GLAD_EXT_texture_filter_anisotropic)
 		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
 		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
@@ -715,6 +726,11 @@ bool OpenGL::isClampZeroTextureWrapSupported() const
 	return GLAD_VERSION_1_3 || GLAD_EXT_texture_border_clamp || GLAD_NV_texture_border_clamp;
 	return GLAD_VERSION_1_3 || GLAD_EXT_texture_border_clamp || GLAD_NV_texture_border_clamp;
 }
 }
 
 
+bool OpenGL::isPixelShaderHighpSupported() const
+{
+	return pixelShaderHighpSupported;
+}
+
 int OpenGL::getMaxTextureSize() const
 int OpenGL::getMaxTextureSize() const
 {
 {
 	return maxTextureSize;
 	return maxTextureSize;
@@ -740,6 +756,11 @@ float OpenGL::getMaxPointSize() const
 	return maxPointSize;
 	return maxPointSize;
 }
 }
 
 
+float OpenGL::getMaxAnisotropy() const
+{
+	return maxAnisotropy;
+}
+
 void OpenGL::updateTextureMemorySize(size_t oldsize, size_t newsize)
 void OpenGL::updateTextureMemorySize(size_t oldsize, size_t newsize)
 {
 {
 	int64 memsize = (int64) stats.textureMemory + ((int64) newsize - (int64) oldsize);
 	int64 memsize = (int64) stats.textureMemory + ((int64) newsize - (int64) oldsize);

+ 8 - 0
src/modules/graphics/opengl/OpenGL.h

@@ -383,6 +383,7 @@ public:
 	void setTextureWrap(const graphics::Texture::Wrap &w);
 	void setTextureWrap(const graphics::Texture::Wrap &w);
 
 
 	bool isClampZeroTextureWrapSupported() const;
 	bool isClampZeroTextureWrapSupported() const;
+	bool isPixelShaderHighpSupported() const;
 
 
 	/**
 	/**
 	 * Returns the maximum supported width or height of a texture.
 	 * Returns the maximum supported width or height of a texture.
@@ -409,6 +410,12 @@ public:
 	 **/
 	 **/
 	float getMaxPointSize() const;
 	float getMaxPointSize() const;
 
 
+	/**
+	 * Returns the maximum anisotropic filtering value that can be used for
+	 * Texture filtering.
+	 **/
+	float getMaxAnisotropy() const;
+
 
 
 	void updateTextureMemorySize(size_t oldsize, size_t newsize);
 	void updateTextureMemorySize(size_t oldsize, size_t newsize);
 
 
@@ -438,6 +445,7 @@ private:
 
 
 	bool contextInitialized;
 	bool contextInitialized;
 
 
+	bool pixelShaderHighpSupported;
 	float maxAnisotropy;
 	float maxAnisotropy;
 	int maxTextureSize;
 	int maxTextureSize;
 	int maxRenderTargets;
 	int maxRenderTargets;