Rewrite RenderWindow::capture to make use of a single texture transfer instead of transferring each row of the framebuffer individually.
This commit is contained in:
parent
146f63874a
commit
043fb83cd8
@ -115,6 +115,17 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy the current contents of the window to an image
|
/// \brief Copy the current contents of the window to an image
|
||||||
///
|
///
|
||||||
|
/// \deprecated
|
||||||
|
/// Use a sf::Texture and its sf::Texture::update(const Window&)
|
||||||
|
/// function and copy its contents into an sf::Image instead.
|
||||||
|
/// \code
|
||||||
|
/// sf::Vector2u windowSize = window.getSize();
|
||||||
|
/// sf::Texture texture;
|
||||||
|
/// texture.create(windowSize.x, windowSize.y);
|
||||||
|
/// texture.update(window);
|
||||||
|
/// sf::Image screenshot = texture.copyToImage();
|
||||||
|
/// \endcode
|
||||||
|
///
|
||||||
/// This is a slow operation, whose main purpose is to make
|
/// This is a slow operation, whose main purpose is to make
|
||||||
/// screenshots of the application. If you want to update an
|
/// screenshots of the application. If you want to update an
|
||||||
/// image with the contents of the window and then use it for
|
/// image with the contents of the window and then use it for
|
||||||
@ -126,7 +137,7 @@ public:
|
|||||||
/// \return Image containing the captured contents
|
/// \return Image containing the captured contents
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Image capture() const;
|
SFML_DEPRECATED Image capture() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
#include <SFML/Graphics/GLCheck.hpp>
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
@ -78,24 +78,13 @@ Vector2u RenderWindow::getSize() const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Image RenderWindow::capture() const
|
Image RenderWindow::capture() const
|
||||||
{
|
{
|
||||||
Image image;
|
Vector2u windowSize = getSize();
|
||||||
if (setActive())
|
|
||||||
{
|
|
||||||
int width = static_cast<int>(getSize().x);
|
|
||||||
int height = static_cast<int>(getSize().y);
|
|
||||||
|
|
||||||
// copy rows one by one and flip them (OpenGL's origin is bottom while SFML's origin is top)
|
Texture texture;
|
||||||
std::vector<Uint8> pixels(width * height * 4);
|
texture.create(windowSize.x, windowSize.y);
|
||||||
for (int i = 0; i < height; ++i)
|
texture.update(*this);
|
||||||
{
|
|
||||||
Uint8* ptr = &pixels[i * width * 4];
|
|
||||||
glCheck(glReadPixels(0, height - i - 1, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
image.create(width, height, &pixels[0]);
|
return texture.copyToImage();
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user