Commits

Alex Szpakowski  committed cf03271

Added love.graphics.getSystemLimit (resolves issue #840). Deprecated love.graphics.getMaxPointSize.

love.graphics.getSystemLimit currently accepts these enum strings: “pointsize”, “texturesize”, “multicanvas”, and “canvasfsaa”.

  • Participants
  • Parent commits 2332160

Comments (0)

Files changed (9)

File src/modules/graphics/Graphics.cpp

 	return rendererInfo.find(in, out);
 }
 
+bool Graphics::getConstant(const char *in, SystemLimit &out)
+{
+	return systemLimits.find(in, out);
+}
+
+bool Graphics::getConstant(SystemLimit in, const char *&out)
+{
+	return systemLimits.find(in, out);
+}
+
 StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
 {
 	{ "line", Graphics::DRAW_LINE },
 
 StringMap<Graphics::RendererInfo, Graphics::RENDERER_INFO_MAX_ENUM> Graphics::rendererInfo(Graphics::rendererInfoEntries, sizeof(Graphics::rendererInfoEntries));
 
+StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM>::Entry Graphics::systemLimitEntries[] =
+{
+	{"pointsize", Graphics::LIMIT_POINT_SIZE},
+	{"texturesize", Graphics::LIMIT_TEXTURE_SIZE},
+	{"multicanvas", Graphics::LIMIT_MULTI_CANVAS},
+	{"canvasfsaa", Graphics::LIMIT_CANVAS_FSAA},
+};
+
+StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM> Graphics::systemLimits(Graphics::systemLimitEntries, sizeof(Graphics::systemLimitEntries));
+
 } // graphics
 } // love

File src/modules/graphics/Graphics.h

 		RENDERER_INFO_MAX_ENUM
 	};
 
+	enum SystemLimit
+	{
+		LIMIT_POINT_SIZE,
+		LIMIT_TEXTURE_SIZE,
+		LIMIT_MULTI_CANVAS,
+		LIMIT_CANVAS_FSAA,
+		LIMIT_MAX_ENUM
+	};
+
 	virtual ~Graphics();
 
 	/**
 	static bool getConstant(const char *in, RendererInfo &out);
 	static bool getConstant(RendererInfo in, const char *&out);
 
+	static bool getConstant(const char *in, SystemLimit &out);
+	static bool getConstant(SystemLimit in, const char *&out);
+
 private:
 
 	static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
 	static StringMap<RendererInfo, RENDERER_INFO_MAX_ENUM>::Entry rendererInfoEntries[];
 	static StringMap<RendererInfo, RENDERER_INFO_MAX_ENUM> rendererInfo;
 
+	static StringMap<SystemLimit, LIMIT_MAX_ENUM>::Entry systemLimitEntries[];
+	static StringMap<SystemLimit, LIMIT_MAX_ENUM> systemLimits;
+
 }; // Graphics
 
 } // graphics

File src/modules/graphics/opengl/Canvas.cpp

 
 bool Canvas::isMultiCanvasSupported()
 {
-	if (!(isSupported() && (GLEE_VERSION_2_0 || GLEE_ARB_draw_buffers)))
-		return false;
-
-	if (maxFBOColorAttachments == 0 || maxDrawBuffers == 0)
-	{
-		glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxFBOColorAttachments);
-		glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
-	}
-
-	// system must support at least 4 simultanious active canvases
-	return maxFBOColorAttachments >= 4 && maxDrawBuffers >= 4;
+	// system must support at least 4 simultanious active canvases.
+	return gl.getMaxRenderTargets() >= 4;
 }
 
 void Canvas::bindDefaultCanvas()

File src/modules/graphics/opengl/Graphics.cpp

 	glDisable(GL_STENCIL_TEST);
 }
 
-int Graphics::getMaxTextureSize() const
-{
-	return gl.getMaxTextureSize();
-}
-
 Image *Graphics::newImage(love::image::ImageData *data)
 {
 	// Create the image.
 		return POINT_ROUGH;
 }
 
-int Graphics::getMaxPointSize() const
-{
-	GLint max;
-	glGetIntegerv(GL_POINT_SIZE_MAX, &max);
-	return (int)max;
-}
-
 void Graphics::print(const std::string &str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {
 	if (currentFont != nullptr)
 	return std::string(infostr);
 }
 
+double Graphics::getSystemLimit(SystemLimit limittype) const
+{
+	double limit = 0.0;
+
+	switch (limittype)
+	{
+	case Graphics::LIMIT_POINT_SIZE:
+		{
+			GLfloat limits[2];
+			glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, limits);
+			limit = limits[1];
+		}
+		break;
+	case Graphics::LIMIT_TEXTURE_SIZE:
+		limit = (double) gl.getMaxTextureSize();
+		break;
+	case Graphics::LIMIT_MULTI_CANVAS:
+		limit = (double) gl.getMaxRenderTargets();
+		break;
+	case Graphics::LIMIT_CANVAS_FSAA:
+		if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object
+			|| GLEE_EXT_framebuffer_multisample)
+		{
+			GLint intlimit = 0;
+			glGetIntegerv(GL_MAX_SAMPLES, &intlimit);
+			limit = (double) intlimit;
+		}
+		break;
+	default:
+		break;
+	}
+
+	return limit;
+}
+
 void Graphics::push()
 {
 	if (userMatrices == matrixLimit)

File src/modules/graphics/opengl/Graphics.h

 	void discardStencil();
 
 	/**
-	 * Gets the maximum supported width or height of Textures on this system.
-	 **/
-	int getMaxTextureSize() const;
-
-	/**
 	 * Creates an Image object with padding and/or optimization.
 	 **/
 	Image *newImage(love::image::ImageData *data);
 	PointStyle getPointStyle() const;
 
 	/**
-	 * Gets the maximum point size supported.
-	 * This may vary from computer to computer.
-	 **/
-	int getMaxPointSize() const;
-
-	/**
 	 * Draws text at the specified coordinates, with rotation and
 	 * scaling along both axes.
 	 * @param x The x-coordinate.
 	 **/
 	std::string getRendererInfo(Graphics::RendererInfo infotype) const;
 
+	/**
+	 * Gets the system-dependent numeric limit for the specified parameter.
+	 **/
+	double getSystemLimit(SystemLimit limittype) const;
+
 	void push();
 	void pop();
 	void rotate(float r);

File src/modules/graphics/opengl/OpenGL.cpp

 	: contextInitialized(false)
 	, maxAnisotropy(1.0f)
 	, maxTextureSize(0)
+	, maxRenderTargets(0)
 	, vendor(VENDOR_UNKNOWN)
 	, state()
 {
 		maxAnisotropy = 1.0f;
 
 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
+
+	if (Canvas::isSupported() && (GLEE_VERSION_2_0 || GLEE_ARB_draw_buffers))
+	{
+		int maxattachments = 0;
+		glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxattachments);
+
+		int maxdrawbuffers = 0;
+		glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxdrawbuffers);
+
+		maxRenderTargets = std::min(maxattachments, maxdrawbuffers);
+	}
+	else
+		maxRenderTargets = 0;
 }
 
 void OpenGL::createDefaultTexture()
 	return maxTextureSize;
 }
 
+int OpenGL::getMaxRenderTargets() const
+{
+	return maxRenderTargets;
+}
+
 OpenGL::Vendor OpenGL::getVendor() const
 {
 	return vendor;

File src/modules/graphics/opengl/OpenGL.h

 	int getMaxTextureSize() const;
 
 	/**
+	 * Returns the maximum supported number of simultaneous render targets.
+	 **/
+	int getMaxRenderTargets() const;
+
+	/**
 	 * Get the GPU vendor of this OpenGL context.
 	 **/
 	Vendor getVendor() const;
 
 	float maxAnisotropy;
 	int maxTextureSize;
+	int maxRenderTargets;
 
 	Vendor vendor;
 

File src/modules/graphics/opengl/wrap_Graphics.cpp

 
 int w_getMaxTextureSize(lua_State *L)
 {
-	lua_pushinteger(L, instance->getMaxTextureSize());
+	lua_pushinteger(L, instance->getSystemLimit(Graphics::LIMIT_TEXTURE_SIZE));
 	return 1;
 }
 
 
 int w_getMaxPointSize(lua_State *L)
 {
-	lua_pushnumber(L, instance->getMaxPointSize());
+	lua_pushnumber(L, instance->getSystemLimit(Graphics::LIMIT_POINT_SIZE));
 	return 1;
 }
 
 	return 4;
 }
 
+int w_getSystemLimit(lua_State *L)
+{
+	const char *limitstr = luaL_checkstring(L, 1);
+	Graphics::SystemLimit limittype;
+
+	if (!Graphics::getConstant(limitstr, limittype))
+		return luaL_error(L, "Invalid system limit type: %s", limitstr);
+
+	lua_pushnumber(L, instance->getSystemLimit(limittype));
+	return 1;
+}
+
 int w_draw(lua_State *L)
 {
 	Drawable *drawable = nullptr;
 	{ "setPointStyle", w_setPointStyle },
 	{ "getPointSize", w_getPointSize },
 	{ "getPointStyle", w_getPointStyle },
-	{ "getMaxPointSize", w_getMaxPointSize },
-	{ "getMaxTextureSize", w_getMaxTextureSize },
 	{ "newScreenshot", w_newScreenshot },
 	{ "setCanvas", w_setCanvas },
 	{ "getCanvas", w_getCanvas },
 
 	{ "isSupported", w_isSupported },
 	{ "getRendererInfo", w_getRendererInfo },
+	{ "getSystemLimit", w_getSystemLimit },
 
 	{ "draw", w_draw },
 
 
 	// Deprecated since 0.9.1.
 	{ "getMaxImageSize", w_getMaxTextureSize },
+	{ "getMaxPointSize", w_getMaxPointSize },
 
 	{ 0, 0 }
 };

File src/modules/graphics/opengl/wrap_Graphics.h

 int w_getShader(lua_State *L);
 int w_isSupported(lua_State *L);
 int w_getRendererInfo(lua_State *L);
+int w_getSystemLimit(lua_State *L);
 int w_draw(lua_State *L);
 int w_print(lua_State *L);
 int w_printf(lua_State *L);