libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
SDL2pp::Texture Class Reference

Image stored in the graphics card memory that can be used for fast drawing. More...

#include <SDL2pp/Texture.hh>

Classes

class  LockHandle
 SDL2pp::Texture lock. More...
 

Public Member Functions

 Texture (SDL_Texture *texture)
 Construct from existing SDL_Texture structure.
 
 Texture (Renderer &renderer, Uint32 format, int access, int w, int h)
 Create empty texture.
 
 Texture (Renderer &renderer, RWops &rwops)
 Create texture loading it via RWops.
 
 Texture (Renderer &renderer, const std::string &filename)
 Create texture loading it from file.
 
 Texture (Renderer &renderer, const Surface &surface)
 Create texture from surface.
 
virtual ~Texture ()
 Destructor.
 
 Texture (Texture &&other) noexcept
 Move constructor.
 
Textureoperator= (Texture &&other) noexcept
 Move assignment.
 
 Texture (const Texture &other)=delete
 Deleted copy constructor.
 
Textureoperator= (const Texture &other)=delete
 Deleted assignment operator.
 
SDL_Texture * Get () const
 Get pointer to managed SDL_Texture structure.
 
TextureUpdate (const Optional< Rect > &rect, const void *pixels, int pitch)
 Update the given texture rectangle with new pixel data.
 
TextureUpdate (const Optional< Rect > &rect, Surface &surface)
 Update the given texture rectangle with new pixel data taken from surface.
 
TextureUpdate (const Optional< Rect > &rect, Surface &&surface)
 Update the given texture rectangle with new pixel data taken from surface.
 
TextureUpdateYUV (const Optional< Rect > &rect, const Uint8 *yplane, int ypitch, const Uint8 *uplane, int upitch, const Uint8 *vplane, int vpitch)
 Update the given texture rectangle with new pixel data.
 
TextureSetBlendMode (SDL_BlendMode blendMode=SDL_BLENDMODE_NONE)
 Set the blend mode for a texture, used by SDL2pp::Renderer::Copy.
 
TextureSetAlphaMod (Uint8 alpha=255)
 Set an additional alpha value multiplied into render copy operations.
 
TextureSetColorMod (Uint8 r=255, Uint8 g=255, Uint8 b=255)
 Set an additional color value multiplied into render copy operations.
 
TextureSetColorAndAlphaMod (const Color &color=Color{255, 255, 255, SDL_ALPHA_OPAQUE})
 Set an additional color value multiplied into render copy operations.
 
LockHandle Lock (const Optional< Rect > &rect=NullOpt)
 Lock texture for write-only pixel access.
 
Uint32 GetFormat () const
 Get texture format.
 
int GetAccess () const
 Get texture access mode.
 
int GetWidth () const
 Get texture image width.
 
int GetHeight () const
 Get texture image height.
 
Point GetSize () const
 Get texture image size.
 
Uint8 GetAlphaMod () const
 Get the additional alpha value multiplied into render copy operations.
 
SDL_BlendMode GetBlendMode () const
 Get the blend mode used for texture copy operations.
 
void GetColorMod (Uint8 &r, Uint8 &g, Uint8 &b) const
 Get the additional color value multiplied into render copy operations.
 
Color GetColorAndAlphaMod () const
 Get the additional color value multiplied into render copy operations.
 

Detailed Description

Image stored in the graphics card memory that can be used for fast drawing.

Constructor & Destructor Documentation

◆ Texture() [1/7]

SDL2pp::Texture::Texture ( SDL_Texture *  texture)
explicit

Construct from existing SDL_Texture structure.

Parameters
[in]textureExisting SDL_Texture to manage

◆ Texture() [2/7]

SDL2pp::Texture::Texture ( Renderer renderer,
Uint32  format,
int  access,
int  w,
int  h 
)

Create empty texture.

Parameters
[in]rendererRendering context to create texture for
[in]formatOne of the enumerated values in SDL_PixelFormatEnum
[in]accessOne of the enumerated values in SDL_TextureAccess
[in]wWidth of the texture in pixels
[in]hHeight of the texture in pixels
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_CreateTexture

◆ Texture() [3/7]

SDL2pp::Texture::Texture ( Renderer renderer,
RWops rwops 
)

Create texture loading it via RWops.

Parameters
[in]rendererRendering context to create texture for
[in]rwopsRWops used to access an image file
Exceptions
SDL2pp::Exception

◆ Texture() [4/7]

SDL2pp::Texture::Texture ( Renderer renderer,
const std::string &  filename 
)

Create texture loading it from file.

Parameters
[in]rendererRendering context to create texture for
[in]filenamePath to an image file
Exceptions
SDL2pp::Exception

◆ Texture() [5/7]

SDL2pp::Texture::Texture ( Renderer renderer,
const Surface surface 
)

Create texture from surface.

Parameters
[in]rendererRendering context to create texture for
[in]surfaceSurface containing pixel data used to fill the texture
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_CreateTextureFromSurface

◆ ~Texture()

SDL2pp::Texture::~Texture ( )
virtual

◆ Texture() [6/7]

SDL2pp::Texture::Texture ( Texture &&  other)
noexcept

Move constructor.

Parameters
[in]otherSDL2pp::Texture object to move data from

◆ Texture() [7/7]

SDL2pp::Texture::Texture ( const Texture other)
delete

Deleted copy constructor.

This class is not copyable

Member Function Documentation

◆ Get()

SDL_Texture * SDL2pp::Texture::Get ( ) const

Get pointer to managed SDL_Texture structure.

Returns
Pointer to managed SDL_Texture structure

◆ GetAccess()

int SDL2pp::Texture::GetAccess ( ) const

Get texture access mode.

Returns
Texture access pattern
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_QueryTexture
http://wiki.libsdl.org/SDL_TextureAccess

◆ GetAlphaMod()

Uint8 SDL2pp::Texture::GetAlphaMod ( ) const

Get the additional alpha value multiplied into render copy operations.

Returns
Current alpha value
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_GetTextureAlphaMod

◆ GetBlendMode()

SDL_BlendMode SDL2pp::Texture::GetBlendMode ( ) const

Get the blend mode used for texture copy operations.

Returns
Current SDL_BlendMode
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_GetTextureBlendMode

◆ GetColorAndAlphaMod()

Color SDL2pp::Texture::GetColorAndAlphaMod ( ) const

Get the additional color value multiplied into render copy operations.

Returns
Color object with the values used to do render copy operations
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_GetTextureAlphaMod
http://wiki.libsdl.org/SDL_GetTextureColorMod

◆ GetColorMod()

void SDL2pp::Texture::GetColorMod ( Uint8 &  r,
Uint8 &  g,
Uint8 &  b 
) const

Get the additional color value multiplied into render copy operations.

Parameters
[out]rVariable to be filled in with the current red color value
[out]gVariable to be filled in with the current green color value
[out]bVariable to be filled in with the current blue color value
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_GetTextureColorMod

◆ GetFormat()

Uint32 SDL2pp::Texture::GetFormat ( ) const

◆ GetHeight()

int SDL2pp::Texture::GetHeight ( ) const

Get texture image height.

Returns
Texture height in pixels
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_QueryTexture

◆ GetSize()

Point SDL2pp::Texture::GetSize ( ) const

Get texture image size.

Returns
SDL2pp::Point representing texture dimensions in pixels
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_QueryTexture

◆ GetWidth()

int SDL2pp::Texture::GetWidth ( ) const

Get texture image width.

Returns
Texture width in pixels
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_QueryTexture

◆ Lock()

Texture::LockHandle SDL2pp::Texture::Lock ( const Optional< Rect > &  rect = NullOpt)

Lock texture for write-only pixel access.

Parameters
[in]rectRect representing area to lock for access (NullOpt to lock entire texture)
Returns
Lock handle used to access pixel data and to control lock lifetime
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_LockTexture

◆ operator=() [1/2]

Texture & SDL2pp::Texture::operator= ( const Texture other)
delete

Deleted assignment operator.

This class is not copyable

◆ operator=() [2/2]

Texture & SDL2pp::Texture::operator= ( Texture &&  other)
noexcept

Move assignment.

Parameters
[in]otherSDL2pp::Texture object to move data from
Returns
Reference to self

◆ SetAlphaMod()

Texture & SDL2pp::Texture::SetAlphaMod ( Uint8  alpha = 255)

Set an additional alpha value multiplied into render copy operations.

Parameters
[in]alphaSource alpha value multiplied into copy operations
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_SetTextureAlphaMod

◆ SetBlendMode()

Texture & SDL2pp::Texture::SetBlendMode ( SDL_BlendMode  blendMode = SDL_BLENDMODE_NONE)

Set the blend mode for a texture, used by SDL2pp::Renderer::Copy.

Parameters
[in]blendModeSDL_BlendMode to use for texture blending
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_SetTextureBlendMode

◆ SetColorAndAlphaMod()

Texture & SDL2pp::Texture::SetColorAndAlphaMod ( const Color color = Color{255, 255, 255, SDL_ALPHA_OPAQUE})

Set an additional color value multiplied into render copy operations.

Parameters
[in]colorColor to be used when multiplied into render copy operations
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_SetTextureAlphaMod
http://wiki.libsdl.org/SDL_SetTextureColorMod

◆ SetColorMod()

Texture & SDL2pp::Texture::SetColorMod ( Uint8  r = 255,
Uint8  g = 255,
Uint8  b = 255 
)

Set an additional color value multiplied into render copy operations.

Parameters
[in]rRed color value multiplied into copy operations
[in]gGreen color value multiplied into copy operations
[in]bBlue color value multiplied into copy operations
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_SetTextureColorMod

◆ Update() [1/3]

Texture & SDL2pp::Texture::Update ( const Optional< Rect > &  rect,
const void *  pixels,
int  pitch 
)

Update the given texture rectangle with new pixel data.

Parameters
[in]rectRect representing the area to update, or NullOpt to update the entire texture
[in]pixelsRaw pixel data
[in]pitchNumber of bytes in a row of pixel data, including padding between lines
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_UpdateTexture

◆ Update() [2/3]

Texture & SDL2pp::Texture::Update ( const Optional< Rect > &  rect,
Surface &&  surface 
)

Update the given texture rectangle with new pixel data taken from surface.

Parameters
[in]rectRect representing the area to update, or NullOpt to update the entire texture
[in]surfaceSurface 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
If surface and texture pixel formats do not match, surface is automatically converted to texture format
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_UpdateTexture

◆ Update() [3/3]

Texture & SDL2pp::Texture::Update ( const Optional< Rect > &  rect,
Surface surface 
)

Update the given texture rectangle with new pixel data taken from surface.

Parameters
[in]rectRect representing the area to update, or NullOpt to update the entire texture
[in]surfaceSurface 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
If surface and texture pixel formats do not match, surface is automatically converted to texture format
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_UpdateTexture

◆ UpdateYUV()

Texture & SDL2pp::Texture::UpdateYUV ( const Optional< Rect > &  rect,
const Uint8 *  yplane,
int  ypitch,
const Uint8 *  uplane,
int  upitch,
const Uint8 *  vplane,
int  vpitch 
)

Update the given texture rectangle with new pixel data.

Parameters
[in]rectRect representing the area to update, or NullOpt to update the entire texture
[in]yplaneRaw pixel data for the Y plane
[in]ypitchNumber of bytes between rows of pixel data for the Y plane
[in]uplaneRaw pixel data for the U plane
[in]upitchNumber of bytes between rows of pixel data for the U plane
[in]vplaneRaw pixel data for the V plane
[in]vpitchNumber of bytes between rows of pixel data for the V plane
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_UpdateYUVTexture

The documentation for this class was generated from the following files: