mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
Add sync and async texture and buffer readback APIs.
- Add imagedata = love.graphics.readbackTexture(texture, [slice, mipmap, x, y, w, h, [dest, destx, desty]]). - Add readback = love.graphics.readbackTextureAsync(texture, [slice, mipmap, x, y, w, h, [dest, destx, desty]]). - Add bytedata = love.graphics.readbackBuffer(buffer, [offset, size, [dest, destoffset]]). - Add readback = ove.graphics.readbackBufferAsync(buffer, [offset, size, [dest, destoffset]]). - Deprecate Texture:newImageData. The async variants return a new GraphicsReadback object. It has the following methods: - isComplete() - hasError() - wait() - getBufferData() - getImageData() - update() (called automatically every frame by love, not normally needed). Support notes: - readbackBuffer and readbackBufferAsync require buffer copying support. - readbackTexture with a render target (canvas) is always supported. readbackTexture with a non-render-target requires copy-texture-to-buffer support. - readbackTextureAsync with a render target requires copy-render-target-to-buffer support. readbackTextureAsync with a non-render-target requires copy-texture-to-buffer support.
This commit is contained in:
@@ -563,47 +563,6 @@ void Texture::generateMipmaps()
|
||||
generateMipmapsInternal();
|
||||
}
|
||||
|
||||
love::image::ImageData *Texture::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
||||
{
|
||||
if (!isReadable())
|
||||
throw love::Exception("Texture:newImageData cannot be called on non-readable Textures.");
|
||||
|
||||
if (!isRenderTarget())
|
||||
throw love::Exception("Texture:newImageData can only be called on render target Textures.");
|
||||
|
||||
if (isPixelFormatDepthStencil(getPixelFormat()))
|
||||
throw love::Exception("Texture:newImageData cannot be called on Textures 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->isRenderTargetActive(this))
|
||||
throw love::Exception("Texture:newImageData cannot be called while that Texture is an active render target.");
|
||||
|
||||
PixelFormat dataformat = getLinearPixelFormat(getPixelFormat());
|
||||
|
||||
if (!image::ImageData::validPixelFormat(dataformat))
|
||||
{
|
||||
const char *formatname = "unknown";
|
||||
love::getConstant(dataformat, formatname);
|
||||
throw love::Exception("ImageData with the '%s' pixel format is not supported.", formatname);
|
||||
}
|
||||
|
||||
auto imagedata = module->newImageData(r.w, r.h, dataformat);
|
||||
|
||||
readbackImageData(imagedata, slice, mipmap, r);
|
||||
|
||||
return imagedata;
|
||||
}
|
||||
|
||||
TextureType Texture::getTextureType() const
|
||||
{
|
||||
return texType;
|
||||
|
||||
Reference in New Issue
Block a user