mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Moved some backend-agnostic code out of the OpenGL backend of love.graphics.
--HG-- branch : minor
This commit is contained in:
@@ -89,6 +89,53 @@ int Canvas::getRequestedMSAA() const
|
|||||||
return settings.msaa;
|
return settings.msaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
love::image::ImageData *Canvas::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
||||||
|
{
|
||||||
|
if (!isReadable())
|
||||||
|
throw love::Exception("Canvas:newImageData cannot be called on non-readable Canvases.");
|
||||||
|
|
||||||
|
if (isPixelFormatDepthStencil(getPixelFormat()))
|
||||||
|
throw love::Exception("Canvas:newImageData cannot be called on Canvases with depth/stencil pixel formats.");
|
||||||
|
|
||||||
|
if (r.x < 0 || r.y < 0 || r.w <= 0 || r.h <= 0 || (r.x + r.w) > getPixelWidth(mipmap) || (r.y + r.h) > getPixelHeight(mipmap))
|
||||||
|
throw love::Exception("Invalid rectangle dimensions.");
|
||||||
|
|
||||||
|
if (slice < 0 || (texType == TEXTURE_VOLUME && slice >= getDepth(mipmap))
|
||||||
|
|| (texType == TEXTURE_2D_ARRAY && slice >= layers)
|
||||||
|
|| (texType == TEXTURE_CUBE && slice >= 6))
|
||||||
|
{
|
||||||
|
throw love::Exception("Invalid slice index.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics *gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
|
||||||
|
if (gfx != nullptr && gfx->isCanvasActive(this))
|
||||||
|
throw love::Exception("Canvas:newImageData cannot be called while that Canvas is currently active.");
|
||||||
|
|
||||||
|
PixelFormat dataformat;
|
||||||
|
switch (getPixelFormat())
|
||||||
|
{
|
||||||
|
case PIXELFORMAT_RGB10A2: // FIXME: Conversions aren't supported in GLES
|
||||||
|
dataformat = PIXELFORMAT_RGBA16;
|
||||||
|
break;
|
||||||
|
case PIXELFORMAT_R16F:
|
||||||
|
case PIXELFORMAT_RG16F:
|
||||||
|
case PIXELFORMAT_RGBA16F:
|
||||||
|
case PIXELFORMAT_RG11B10F: // FIXME: Conversions aren't supported in GLES
|
||||||
|
dataformat = PIXELFORMAT_RGBA16F;
|
||||||
|
break;
|
||||||
|
case PIXELFORMAT_R32F:
|
||||||
|
case PIXELFORMAT_RG32F:
|
||||||
|
case PIXELFORMAT_RGBA32F:
|
||||||
|
dataformat = PIXELFORMAT_RGBA32F;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dataformat = PIXELFORMAT_RGBA8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return module->newImageData(r.w, r.h, dataformat);
|
||||||
|
}
|
||||||
|
|
||||||
void Canvas::draw(Graphics *gfx, Quad *q, const Matrix4 &t)
|
void Canvas::draw(Graphics *gfx, Quad *q, const Matrix4 &t)
|
||||||
{
|
{
|
||||||
if (gfx->isCanvasActive(this))
|
if (gfx->isCanvasActive(this))
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
MipmapMode getMipmapMode() const;
|
MipmapMode getMipmapMode() const;
|
||||||
int getRequestedMSAA() const;
|
int getRequestedMSAA() const;
|
||||||
|
|
||||||
virtual love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect) = 0;
|
virtual love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect);
|
||||||
virtual void generateMipmaps() = 0;
|
virtual void generateMipmaps() = 0;
|
||||||
|
|
||||||
virtual int getMSAA() const = 0;
|
virtual int getMSAA() const = 0;
|
||||||
|
|||||||
@@ -454,49 +454,8 @@ ptrdiff_t Canvas::getHandle() const
|
|||||||
|
|
||||||
love::image::ImageData *Canvas::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
love::image::ImageData *Canvas::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
||||||
{
|
{
|
||||||
if (!isReadable())
|
love::image::ImageData *imagedata = love::graphics::Canvas::newImageData(module, slice, mipmap, r);
|
||||||
throw love::Exception("Canvas:newImageData cannot be called on non-readable Canvases.");
|
PixelFormat dataformat = imagedata->getFormat();
|
||||||
|
|
||||||
if (isPixelFormatDepthStencil(getPixelFormat()))
|
|
||||||
throw love::Exception("Canvas:newImageData cannot be called on Canvases with depth/stencil pixel formats.");
|
|
||||||
|
|
||||||
if (r.x < 0 || r.y < 0 || r.w <= 0 || r.h <= 0 || (r.x + r.w) > getPixelWidth(mipmap) || (r.y + r.h) > getPixelHeight(mipmap))
|
|
||||||
throw love::Exception("Invalid rectangle dimensions.");
|
|
||||||
|
|
||||||
if (slice < 0 || (texType == TEXTURE_VOLUME && slice >= getDepth(mipmap))
|
|
||||||
|| (texType == TEXTURE_2D_ARRAY && slice >= layers)
|
|
||||||
|| (texType == TEXTURE_CUBE && slice >= 6))
|
|
||||||
{
|
|
||||||
throw love::Exception("Invalid slice index.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Graphics *gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
|
|
||||||
if (gfx != nullptr && gfx->isCanvasActive(this))
|
|
||||||
throw love::Exception("Canvas:newImageData cannot be called while that Canvas is currently active.");
|
|
||||||
|
|
||||||
PixelFormat dataformat;
|
|
||||||
switch (getPixelFormat())
|
|
||||||
{
|
|
||||||
case PIXELFORMAT_RGB10A2: // FIXME: Conversions aren't supported in GLES
|
|
||||||
dataformat = PIXELFORMAT_RGBA16;
|
|
||||||
break;
|
|
||||||
case PIXELFORMAT_R16F:
|
|
||||||
case PIXELFORMAT_RG16F:
|
|
||||||
case PIXELFORMAT_RGBA16F:
|
|
||||||
case PIXELFORMAT_RG11B10F: // FIXME: Conversions aren't supported in GLES
|
|
||||||
dataformat = PIXELFORMAT_RGBA16F;
|
|
||||||
break;
|
|
||||||
case PIXELFORMAT_R32F:
|
|
||||||
case PIXELFORMAT_RG32F:
|
|
||||||
case PIXELFORMAT_RGBA32F:
|
|
||||||
dataformat = PIXELFORMAT_RGBA32F;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dataformat = PIXELFORMAT_RGBA8;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
love::image::ImageData *imagedata = module->newImageData(r.w, r.h, dataformat);
|
|
||||||
|
|
||||||
bool isSRGB = false;
|
bool isSRGB = false;
|
||||||
OpenGL::TextureFormat fmt = gl.convertPixelFormat(dataformat, false, isSRGB);
|
OpenGL::TextureFormat fmt = gl.convertPixelFormat(dataformat, false, isSRGB);
|
||||||
|
|||||||
Reference in New Issue
Block a user