Commits

Alex Szpakowski committed 28a8686

Improved error messages when canvas/image creation fails because the size is too big for the system

  • Participants
  • Parent commits 1d311d7

Comments (0)

Files changed (5)

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

 
 bool Canvas::loadVolatile()
 {
+	// glTexImage2D is guaranteed to error in this case.
+	if (width > gl.getMaxTextureSize() || height > gl.getMaxTextureSize())
+		return false;
+
 	status = strategy->createFBO(fbo, img, width, height, texture_type);
 	if (status != GL_FRAMEBUFFER_COMPLETE)
 		return false;

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

 	if (texture_type == Canvas::TYPE_HDR && !Canvas::isHDRSupported())
 		throw Exception("HDR Canvases are not supported by your OpenGL implementation");
 
+	if (width > gl.getMaxTextureSize())
+		throw Exception("Cannot create canvas: width of %d pixels is too large for this system.", width);
+	else if (height > gl.getMaxTextureSize())
+		throw Exception("Cannot create canvas: height of %d pixels is too large for this system.", height);
+
 	while (GL_NO_ERROR != glGetError())
 		/* clear opengl error flag */;
 

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

 
 bool Image::loadVolatile()
 {
+	// glTexImage2D is guaranteed to throw an error in this case.
+	if (width > gl.getMaxTextureSize())
+	{
+		throw love::Exception("Cannot create image: "
+		      "width of %d pixels is too large for this system.", (int) width);
+	}
+	else if (height > gl.getMaxTextureSize())
+	{
+		throw love::Exception("Cannot create image:"
+		      "height of %d pixels is too large for this system.", (int) height);
+	}
+
 	if (isCompressed() && cdata && !hasCompressedTextureSupport(cdata->getType()))
 	{
 		const char *str;
 	case image::CompressedData::TYPE_BC5s:
 		return (GLEE_VERSION_3_0 || GLEE_ARB_texture_compression_rgtc || GLEE_EXT_texture_compression_rgtc);
 	default:
-		return false;
+		break;
+	}
 
-	}
+	return false;
 }
 
 } // opengl

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

 OpenGL::OpenGL()
 	: contextInitialized(false)
 	, maxAnisotropy(1.0f)
+	, maxTextureSize(0)
 	, state()
 {
 }
 		glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *) &state.textureUnits[0]);
 	}
 
-	// We'll need this value to clamp anisotropy.
-	if (GLEE_EXT_texture_filter_anisotropic)
-		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
-	else
-		maxAnisotropy = 1.0f;
-
+	initMaxValues();
 	createDefaultTexture();
 
 	contextInitialized = true;
 	}
 }
 
+void OpenGL::initMaxValues()
+{
+	// We'll need this value to clamp anisotropy.
+	if (GLEE_EXT_texture_filter_anisotropic)
+		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
+	else
+		maxAnisotropy = 1.0f;
+
+	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
+}
+
 void OpenGL::createDefaultTexture()
 {
 	// Set the 'default' texture (id 0) as a repeating white pixel. Otherwise,
 	return w;
 }
 
+int OpenGL::getMaxTextureSize() const
+{
+	return maxTextureSize;
+}
+
 // OpenGL class instance singleton.
 OpenGL gl;
 

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

 	 **/
 	graphics::Image::Wrap getTextureWrap();
 
+	/**
+	 * Returns the maximum supported width or height of a texture.
+	 **/
+	int getMaxTextureSize() const;
+
 private:
 
 	void initOpenGLFunctions();
+	void initMaxValues();
 	void createDefaultTexture();
 
 	bool contextInitialized;
+
 	float maxAnisotropy;
+	int maxTextureSize;
 
 	// Tracked OpenGL state.
 	struct