FS#133 - Add a function to make fast updates of an image's pixels from an external source

Removed sf::Image constructors that called CreateXxx or LoadXxx (there was no way to check errors)


git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1307 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-12-05 11:35:27 +00:00
parent aff5c1a47c
commit fb7470cbc3
2 changed files with 65 additions and 56 deletions

View file

@ -82,42 +82,6 @@ Resource<Image>(copy)
}
////////////////////////////////////////////////////////////
/// Construct an empty image
////////////////////////////////////////////////////////////
Image::Image(unsigned int width, unsigned int height, const Color& color) :
myWidth (0),
myHeight (0),
myTextureWidth (0),
myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false),
myPixelsFlipped (false)
{
Create(width, height, color);
}
////////////////////////////////////////////////////////////
/// Construct the image from pixels in memory
////////////////////////////////////////////////////////////
Image::Image(unsigned int width, unsigned int height, const Uint8* data) :
myWidth (0),
myHeight (0),
myTextureWidth (0),
myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false),
myPixelsFlipped (false)
{
LoadFromPixels(width, height, data);
}
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
@ -482,6 +446,47 @@ const Uint8* Image::GetPixelsPtr() const
}
////////////////////////////////////////////////////////////
/// Update the whole image from an array of pixels
////////////////////////////////////////////////////////////
void Image::UpdatePixels(const Uint8* pixels)
{
GLint previous;
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous));
// Update the texture from the array of pixels
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myWidth, myHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
myNeedArrayUpdate = true;
myNeedTextureUpdate = false;
}
////////////////////////////////////////////////////////////
/// Update a sub-rectangle of the image from an array of pixels
////////////////////////////////////////////////////////////
void Image::UpdatePixels(const Uint8* pixels, const IntRect& rectangle)
{
// Make sure that the texture is up-to-date
EnsureTextureUpdate();
GLint previous;
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous));
// Update the texture from the array of pixels
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, rectangle.Left, rectangle.Top, rectangle.GetSize().x, rectangle.GetSize().y, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
// The pixel cache is no longer up-to-date
myNeedArrayUpdate = true;
}
////////////////////////////////////////////////////////////
/// Bind the image for rendering
////////////////////////////////////////////////////////////