mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Improved error messages when canvas/image creation fails because the size is too big for the system
This commit is contained in:
@@ -704,6 +704,10 @@ Image::Wrap Canvas::getWrap() const
|
|||||||
|
|
||||||
bool Canvas::loadVolatile()
|
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);
|
status = strategy->createFBO(fbo, img, width, height, texture_type);
|
||||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -468,6 +468,11 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::TextureType texture_t
|
|||||||
if (texture_type == Canvas::TYPE_HDR && !Canvas::isHDRSupported())
|
if (texture_type == Canvas::TYPE_HDR && !Canvas::isHDRSupported())
|
||||||
throw Exception("HDR Canvases are not supported by your OpenGL implementation");
|
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())
|
while (GL_NO_ERROR != glGetError())
|
||||||
/* clear opengl error flag */;
|
/* clear opengl error flag */;
|
||||||
|
|
||||||
|
|||||||
@@ -320,6 +320,18 @@ void Image::unload()
|
|||||||
|
|
||||||
bool Image::loadVolatile()
|
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()))
|
if (isCompressed() && cdata && !hasCompressedTextureSupport(cdata->getType()))
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
@@ -614,9 +626,10 @@ bool Image::hasCompressedTextureSupport(image::CompressedData::TextureType type)
|
|||||||
case image::CompressedData::TYPE_BC5s:
|
case image::CompressedData::TYPE_BC5s:
|
||||||
return (GLEE_VERSION_3_0 || GLEE_ARB_texture_compression_rgtc || GLEE_EXT_texture_compression_rgtc);
|
return (GLEE_VERSION_3_0 || GLEE_ARB_texture_compression_rgtc || GLEE_EXT_texture_compression_rgtc);
|
||||||
default:
|
default:
|
||||||
return false;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace opengl
|
|||||||
OpenGL::OpenGL()
|
OpenGL::OpenGL()
|
||||||
: contextInitialized(false)
|
: contextInitialized(false)
|
||||||
, maxAnisotropy(1.0f)
|
, maxAnisotropy(1.0f)
|
||||||
|
, maxTextureSize(0)
|
||||||
, state()
|
, state()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -103,12 +104,7 @@ void OpenGL::initContext()
|
|||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *) &state.textureUnits[0]);
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *) &state.textureUnits[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll need this value to clamp anisotropy.
|
initMaxValues();
|
||||||
if (GLEE_EXT_texture_filter_anisotropic)
|
|
||||||
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
|
|
||||||
else
|
|
||||||
maxAnisotropy = 1.0f;
|
|
||||||
|
|
||||||
createDefaultTexture();
|
createDefaultTexture();
|
||||||
|
|
||||||
contextInitialized = true;
|
contextInitialized = true;
|
||||||
@@ -151,6 +147,17 @@ void OpenGL::initOpenGLFunctions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
void OpenGL::createDefaultTexture()
|
||||||
{
|
{
|
||||||
// Set the 'default' texture (id 0) as a repeating white pixel. Otherwise,
|
// Set the 'default' texture (id 0) as a repeating white pixel. Otherwise,
|
||||||
@@ -449,6 +456,11 @@ graphics::Image::Wrap OpenGL::getTextureWrap()
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int OpenGL::getMaxTextureSize() const
|
||||||
|
{
|
||||||
|
return maxTextureSize;
|
||||||
|
}
|
||||||
|
|
||||||
// OpenGL class instance singleton.
|
// OpenGL class instance singleton.
|
||||||
OpenGL gl;
|
OpenGL gl;
|
||||||
|
|
||||||
|
|||||||
@@ -168,13 +168,21 @@ public:
|
|||||||
**/
|
**/
|
||||||
graphics::Image::Wrap getTextureWrap();
|
graphics::Image::Wrap getTextureWrap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the maximum supported width or height of a texture.
|
||||||
|
**/
|
||||||
|
int getMaxTextureSize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initOpenGLFunctions();
|
void initOpenGLFunctions();
|
||||||
|
void initMaxValues();
|
||||||
void createDefaultTexture();
|
void createDefaultTexture();
|
||||||
|
|
||||||
bool contextInitialized;
|
bool contextInitialized;
|
||||||
|
|
||||||
float maxAnisotropy;
|
float maxAnisotropy;
|
||||||
|
int maxTextureSize;
|
||||||
|
|
||||||
// Tracked OpenGL state.
|
// Tracked OpenGL state.
|
||||||
struct
|
struct
|
||||||
|
|||||||
Reference in New Issue
Block a user