Cleaned up some graphics code.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-06-10 15:09:33 -03:00
parent 9fe81ad922
commit 45de7cebb6
6 changed files with 81 additions and 76 deletions
-60
View File
@@ -178,66 +178,6 @@ bool Canvas::loadVolatile()
if (texture != 0)
return true;
if (!Canvas::isSupported())
throw love::Exception("Canvases are not supported by your OpenGL drivers!");
if (!Canvas::isFormatSupported(format, readable))
{
const char *fstr = "rgba8";
const char *readablestr = "";
if (readable != !isPixelFormatDepthStencil(format))
readablestr = readable ? " readable" : " non-readable";
love::getConstant(Canvas::getSizedFormat(format), fstr);
throw love::Exception("The %s%s canvas format is not supported by your OpenGL drivers.", fstr, readablestr);
}
if (getRequestedMSAA() > 1 && texType != TEXTURE_2D)
throw love::Exception("MSAA is only supported for 2D texture types.");
if (!readable && texType != TEXTURE_2D)
throw love::Exception("Non-readable pixel formats are only supported for 2D texture types.");
if (!gl.isTextureTypeSupported(texType))
{
const char *textypestr = "unknown";
Texture::getConstant(texType, textypestr);
throw love::Exception("%s textures are not supported on this system!", textypestr);
}
switch (texType)
{
case TEXTURE_2D:
if (pixelWidth > gl.getMax2DTextureSize())
throw TextureTooLargeException("width", pixelWidth);
else if (pixelHeight > gl.getMax2DTextureSize())
throw TextureTooLargeException("height", pixelHeight);
break;
case TEXTURE_VOLUME:
if (pixelWidth > gl.getMax3DTextureSize())
throw TextureTooLargeException("width", pixelWidth);
else if (pixelHeight > gl.getMax3DTextureSize())
throw TextureTooLargeException("height", pixelHeight);
else if (depth > gl.getMax3DTextureSize())
throw TextureTooLargeException("depth", depth);
break;
case TEXTURE_2D_ARRAY:
if (pixelWidth > gl.getMax2DTextureSize())
throw TextureTooLargeException("width", pixelWidth);
else if (pixelHeight > gl.getMax2DTextureSize())
throw TextureTooLargeException("height", pixelHeight);
else if (layers > gl.getMaxTextureLayers())
throw TextureTooLargeException("array layer count", layers);
break;
case TEXTURE_CUBE:
if (pixelWidth != pixelHeight)
throw love::Exception("Cubemap textures must have equal width and height.");
else if (pixelWidth > gl.getMaxCubeTextureSize())
throw TextureTooLargeException("width", pixelWidth);
break;
default:
break;
}
OpenGL::TempDebugGroup debuggroup("Canvas load");
fbo = texture = 0;
+6 -7
View File
@@ -735,7 +735,7 @@ void Graphics::clear(OptionalColorf c, OptionalInt stencil, OptionalDouble depth
if (flags != 0)
glClear(flags);
if (flags != 0 && gl.bugs.clearRequiresDriverTextureStateUpdate && Shader::current)
if (c.hasValue && gl.bugs.clearRequiresDriverTextureStateUpdate && Shader::current)
{
// This seems to be enough to fix the bug for me. Other methods I've
// tried (e.g. dummy draws) don't work in all cases.
@@ -1249,12 +1249,6 @@ void Graphics::setStencilTest()
setStencilTest(COMPARE_ALWAYS, 0);
}
void Graphics::clearStencil(int value)
{
glClearStencil(value);
glClear(GL_STENCIL_BUFFER_BIT);
}
void Graphics::setColor(Colorf c)
{
c.r = std::min(std::max(c.r, 0.0f), 1.0f);
@@ -1468,6 +1462,11 @@ bool Graphics::isSupported(Feature feature) const
}
}
bool Graphics::isTextureTypeSupported(TextureType textype) const
{
return gl.isTextureTypeSupported(textype);
}
bool Graphics::isCanvasFormatSupported(PixelFormat format) const
{
return Canvas::isFormatSupported(format);
+1 -2
View File
@@ -109,8 +109,6 @@ public:
void setStencilTest(CompareMode compare, int value) override;
void setStencilTest() override;
void clearStencil(int value) override;
void setColorMask(ColorMask mask) override;
void setBlendMode(BlendMode mode, BlendAlpha alphamode) override;
@@ -120,6 +118,7 @@ public:
void setWireframe(bool enable) override;
bool isSupported(Feature feature) const override;
bool isTextureTypeSupported(TextureType textype) const override;
double getSystemLimit(SystemLimit limittype) const override;
bool isCanvasFormatSupported(PixelFormat format) const override;
bool isCanvasFormatSupported(PixelFormat format, bool readable) const override;