mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
Fixed love.graphics.newScreenshot to always read from the main framebuffer, even when a canvas is bound
This commit is contained in:
@@ -1173,8 +1173,14 @@ void Graphics::polygon(DrawMode mode, const float *coords, size_t count)
|
|||||||
|
|
||||||
love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool copyAlpha)
|
love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool copyAlpha)
|
||||||
{
|
{
|
||||||
int w = getRenderWidth();
|
// Temporarily unbind the currently active canvas (glReadPixels reads the
|
||||||
int h = getRenderHeight();
|
// active framebuffer, not the main one.)
|
||||||
|
Canvas *curcanvas = Canvas::current;
|
||||||
|
if (curcanvas)
|
||||||
|
Canvas::bindDefaultCanvas();
|
||||||
|
|
||||||
|
int w = getWidth();
|
||||||
|
int h = getHeight();
|
||||||
|
|
||||||
int row = 4*w;
|
int row = 4*w;
|
||||||
|
|
||||||
@@ -1192,6 +1198,8 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
|
|||||||
{
|
{
|
||||||
delete[] pixels;
|
delete[] pixels;
|
||||||
delete[] screenshot;
|
delete[] screenshot;
|
||||||
|
if (curcanvas)
|
||||||
|
curcanvas->startGrab(curcanvas->getAttachedCanvases());
|
||||||
throw love::Exception("Out of memory.");
|
throw love::Exception("Out of memory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1221,11 +1229,17 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
|
|||||||
catch (love::Exception &)
|
catch (love::Exception &)
|
||||||
{
|
{
|
||||||
delete[] screenshot;
|
delete[] screenshot;
|
||||||
|
if (curcanvas)
|
||||||
|
curcanvas->startGrab(curcanvas->getAttachedCanvases());
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] screenshot;
|
delete[] screenshot;
|
||||||
|
|
||||||
|
// Re-bind the active canvas, if necessary.
|
||||||
|
if (curcanvas)
|
||||||
|
curcanvas->startGrab(curcanvas->getAttachedCanvases());
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user