mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Add optional ‘readable’ boolean field to the table passed into love.graphics.newCanvas. Added new variant of love.graphics.getCanvasFormats which takes a ‘readable’ boolean.
--HG-- branch : minor
This commit is contained in:
@@ -165,7 +165,11 @@ Canvas::Canvas(const Settings &settings)
|
||||
throw love::Exception("MSAA is only supported for Canvases with the 2D texture type.");
|
||||
|
||||
format = getSizedFormat(settings.format);
|
||||
readable = !isPixelFormatDepthStencil(format);
|
||||
|
||||
if (settings.readable.set)
|
||||
readable = settings.readable.value;
|
||||
else
|
||||
readable = !isPixelFormatDepthStencil(format);
|
||||
|
||||
initQuad();
|
||||
loadVolatile();
|
||||
@@ -187,7 +191,7 @@ bool Canvas::loadVolatile()
|
||||
if (!Canvas::isSupported())
|
||||
throw love::Exception("Canvases are not supported by your OpenGL drivers!");
|
||||
|
||||
if (!Canvas::isFormatSupported(format))
|
||||
if (!Canvas::isFormatSupported(format, readable))
|
||||
{
|
||||
const char *fstr = "rgba8";
|
||||
love::getConstant(Canvas::getSizedFormat(format), fstr);
|
||||
@@ -488,6 +492,11 @@ Canvas::SupportedFormat Canvas::supportedFormats[] = {};
|
||||
Canvas::SupportedFormat Canvas::checkedFormats[] = {};
|
||||
|
||||
bool Canvas::isFormatSupported(PixelFormat format)
|
||||
{
|
||||
return isFormatSupported(format, !isPixelFormatDepthStencil(format));
|
||||
}
|
||||
|
||||
bool Canvas::isFormatSupported(PixelFormat format, bool readable)
|
||||
{
|
||||
if (!isSupported())
|
||||
return false;
|
||||
@@ -498,9 +507,6 @@ bool Canvas::isFormatSupported(PixelFormat format)
|
||||
bool supported = true;
|
||||
format = getSizedFormat(format);
|
||||
|
||||
bool depthstencil = isPixelFormatDepthStencil(format);
|
||||
bool readable = !depthstencil;
|
||||
|
||||
if (!OpenGL::isPixelFormatSupported(format, true, readable, false))
|
||||
return false;
|
||||
|
||||
@@ -525,7 +531,7 @@ bool Canvas::isFormatSupported(PixelFormat format)
|
||||
|
||||
// Make sure at least something is bound to a color attachment. I believe
|
||||
// this is required on ES2 but I'm not positive.
|
||||
if (depthstencil)
|
||||
if (isPixelFormatDepthStencil(format))
|
||||
gl.framebufferTexture(GL_COLOR_ATTACHMENT0, TEXTURE_2D, gl.getDefaultTexture(TEXTURE_2D), 0, 0, 0);
|
||||
|
||||
if (readable)
|
||||
|
||||
@@ -82,6 +82,7 @@ public:
|
||||
static PixelFormat getSizedFormat(PixelFormat format);
|
||||
static bool isSupported();
|
||||
static bool isMultiFormatMultiCanvasSupported();
|
||||
static bool isFormatSupported(PixelFormat format, bool readable);
|
||||
static bool isFormatSupported(PixelFormat format);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1487,6 +1487,11 @@ bool Graphics::isCanvasFormatSupported(PixelFormat format) const
|
||||
return Canvas::isFormatSupported(format);
|
||||
}
|
||||
|
||||
bool Graphics::isCanvasFormatSupported(PixelFormat format, bool readable) const
|
||||
{
|
||||
return Canvas::isFormatSupported(format, readable);
|
||||
}
|
||||
|
||||
bool Graphics::isImageFormatSupported(PixelFormat format) const
|
||||
{
|
||||
return Image::isFormatSupported(format);
|
||||
|
||||
@@ -122,6 +122,7 @@ public:
|
||||
bool isSupported(Feature feature) const override;
|
||||
double getSystemLimit(SystemLimit limittype) const override;
|
||||
bool isCanvasFormatSupported(PixelFormat format) const override;
|
||||
bool isCanvasFormatSupported(PixelFormat format, bool readable) const override;
|
||||
bool isImageFormatSupported(PixelFormat format) const override;
|
||||
Renderer getRenderer() const override;
|
||||
RendererInfo getRendererInfo() const override;
|
||||
|
||||
@@ -1635,17 +1635,32 @@ bool OpenGL::isPixelFormatSupported(PixelFormat pixelformat, bool rendertarget,
|
||||
return rendertarget && !readable;
|
||||
|
||||
case PIXELFORMAT_DEPTH16:
|
||||
return rendertarget && !readable;
|
||||
if (!rendertarget)
|
||||
return false;
|
||||
else if (readable)
|
||||
return GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || GLAD_OES_depth_texture;
|
||||
else
|
||||
return true;
|
||||
|
||||
case PIXELFORMAT_DEPTH24:
|
||||
return rendertarget && !readable && (GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || GLAD_OES_depth24 || GLAD_OES_packed_depth_stencil);
|
||||
if (!rendertarget)
|
||||
return false;
|
||||
else if (readable)
|
||||
return GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || (GLAD_OES_depth_texture && (GLAD_OES_depth24 || GLAD_OES_depth_texture));
|
||||
else
|
||||
return GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || GLAD_OES_depth24 || GLAD_OES_depth_texture;
|
||||
|
||||
case PIXELFORMAT_DEPTH24_STENCIL8:
|
||||
return rendertarget && !readable && (GLAD_VERSION_3_0 || GLAD_ES_VERSION_3_0 || GLAD_EXT_packed_depth_stencil || GLAD_OES_packed_depth_stencil);
|
||||
if (!rendertarget)
|
||||
return false;
|
||||
else if (readable)
|
||||
return GLAD_VERSION_3_0 || GLAD_ES_VERSION_3_0 || GLAD_EXT_packed_depth_stencil || (GLAD_OES_depth_texture && GLAD_OES_packed_depth_stencil);
|
||||
else
|
||||
return GLAD_VERSION_3_0 || GLAD_ES_VERSION_3_0 || GLAD_EXT_packed_depth_stencil || GLAD_OES_packed_depth_stencil;
|
||||
|
||||
case PIXELFORMAT_DEPTH32F:
|
||||
case PIXELFORMAT_DEPTH32F_STENCIL8:
|
||||
return rendertarget && !readable && (GLAD_VERSION_3_0 || GLAD_ES_VERSION_3_0 || GLAD_ARB_depth_buffer_float);
|
||||
return rendertarget && (GLAD_VERSION_3_0 || GLAD_ES_VERSION_3_0 || GLAD_ARB_depth_buffer_float);
|
||||
|
||||
case PIXELFORMAT_DXT1:
|
||||
return GLAD_EXT_texture_compression_s3tc || GLAD_EXT_texture_compression_dxt1;
|
||||
|
||||
Reference in New Issue
Block a user