Merge branch 'update-from-surface'

This commit is contained in:
Dmitry Marakasov 2015-09-07 02:58:08 +03:00
commit 4d18ea0233
4 changed files with 55 additions and 0 deletions

View File

@ -213,4 +213,8 @@ Point Surface::GetSize() const {
return Point(surface_->w, surface_->h); return Point(surface_->w, surface_->h);
} }
Uint32 Surface::GetFormat() const {
return surface_->format->format;
}
} }

View File

@ -540,6 +540,17 @@ public:
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Point GetSize() const; Point GetSize() const;
////////////////////////////////////////////////////////////
/// \brief Get texture format
///
/// \return Surface raw format
///
/// \see http://wiki.libsdl.org/SDL_Surface
/// \see http://wiki.libsdl.org/SDL_PixelFormatEnum
///
////////////////////////////////////////////////////////////
Uint32 GetFormat() const;
}; };
} }

View File

@ -94,6 +94,24 @@ Texture& Texture::Update(const Optional<Rect>& rect, const void* pixels, int pit
return *this; return *this;
} }
Texture& Texture::Update(const Optional<Rect>& rect, Surface& surface) {
Rect real_rect = rect ? *rect : Rect(0, 0, GetWidth(), GetHeight());
real_rect.w = std::min(real_rect.w, surface.GetWidth());
real_rect.h = std::min(real_rect.h, surface.GetHeight());
if (GetFormat() == surface.GetFormat()) {
Surface::LockHandle lock = surface.Lock();
return Update(real_rect, lock.GetPixels(), lock.GetPitch());
} else {
Surface converted = surface.Convert(GetFormat());
Surface::LockHandle lock = converted.Lock();
return Update(real_rect, lock.GetPixels(), lock.GetPitch());
}
}
Texture& Texture::UpdateYUV(const Optional<Rect>& rect, const Uint8* yplane, int ypitch, const Uint8* uplane, int upitch, const Uint8* vplane, int vpitch) { Texture& Texture::UpdateYUV(const Optional<Rect>& rect, const Uint8* yplane, int ypitch, const Uint8* uplane, int upitch, const Uint8* vplane, int vpitch) {
if (SDL_UpdateYUVTexture(texture_, rect ? &*rect : nullptr, yplane, ypitch, uplane, upitch, vplane, vpitch) != 0) if (SDL_UpdateYUVTexture(texture_, rect ? &*rect : nullptr, yplane, ypitch, uplane, upitch, vplane, vpitch) != 0)
throw Exception("SDL_UpdateYUVTexture"); throw Exception("SDL_UpdateYUVTexture");

View File

@ -313,6 +313,27 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Texture& Update(const Optional<Rect>& rect, const void* pixels, int pitch); Texture& Update(const Optional<Rect>& rect, const void* pixels, int pitch);
////////////////////////////////////////////////////////////
/// \brief Update the given texture rectangle with new pixel data taken from surface
///
/// \param[in] rect Rect representing the area to update, or NullOpt to
/// update the entire texture
/// \param[in] surface Surface to take pixel data from
///
/// \note No scaling is performed in this routine, so if rect and surface
/// sizes do not match, cropping is performed as appropriate
/// \note If surface and texture pixel formats do not match, surface is
/// automatically converted to texture format
///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_UpdateTexture
///
////////////////////////////////////////////////////////////
Texture& Update(const Optional<Rect>& rect, Surface& surface);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Update the given texture rectangle with new pixel data /// \brief Update the given texture rectangle with new pixel data
/// ///
@ -402,6 +423,7 @@ public:
/// ///
/// \see http://wiki.libsdl.org/SDL_QueryTexture /// \see http://wiki.libsdl.org/SDL_QueryTexture
/// \see http://wiki.libsdl.org/SDL_QueryTexture#format /// \see http://wiki.libsdl.org/SDL_QueryTexture#format
/// \see http://wiki.libsdl.org/SDL_PixelFormatEnum
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint32 GetFormat() const; Uint32 GetFormat() const;