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

SDL2pp::Texture lock. More...

#include <SDL2pp/Texture.hh>

Public Member Functions

 LockHandle ()
 Create no-op lock.
 
 ~LockHandle ()
 Destructor.
 
 LockHandle (LockHandle &&other) noexcept
 Move constructor.
 
LockHandleoperator= (LockHandle &&other) noexcept
 Move assignment operator.
 
 LockHandle (const LockHandle &other)=delete
 Deleted copy constructor.
 
LockHandleoperator= (const LockHandle &other)=delete
 Deleted assignment operator.
 
void * GetPixels () const
 Get pointer to raw pixel data of locked region.
 
int GetPitch () const
 Get pitch of locked pixel data.
 

Friends

class Texture
 

Detailed Description

SDL2pp::Texture lock.

Textures with SDL_TEXTUREACCESS_STREAMING access mode may be locked, which provides (writeonly) access to their raw pixel data. This may be used to update texture contents.

This class represents the lock and controls its lifetime as the lock is released as soon as LockHandle is destroyed.

Usage example:

{
SDL2pp::Texture tex(SDL_PIXELFORMAT_RGB24,
SDL_TEXTUREACCESS_STREAMING,
256, 256);
{
// Lock the whole texture
SDL2pp::Texture::LockHandle lock = tex.Lock();
unsigned char* start = static_cast<unsigned char*>(lock.GetPixels());
// note that we use lock.GetPitch(), not tex.GetWidth() here
// as texture may have different dimensions in memory
unsigned char* end = start + tex.GetHeight() * lock.GetPitch();
// fill the texture white
std::fill(start, end, 255);
}
// At this point lock is released
}
SDL2pp::Texture lock.
Definition: Texture.hh:96
int GetPitch() const
Get pitch of locked pixel data.
Definition: TextureLock.cc:72
void * GetPixels() const
Get pointer to raw pixel data of locked region.
Definition: TextureLock.cc:68
Image stored in the graphics card memory that can be used for fast drawing.
Definition: Texture.hh:53

Constructor & Destructor Documentation

◆ LockHandle() [1/3]

SDL2pp::Texture::LockHandle::LockHandle ( )

Create no-op lock.

This may be initialized with real lock later via move assignment

◆ ~LockHandle()

SDL2pp::Texture::LockHandle::~LockHandle ( )

Destructor.

Releases the lock

See also
http://wiki.libsdl.org/SDL_UnlockTexture

◆ LockHandle() [2/3]

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

Move constructor.

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

◆ LockHandle() [3/3]

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

Deleted copy constructor.

This class is not copyable

Member Function Documentation

◆ GetPitch()

int SDL2pp::Texture::LockHandle::GetPitch ( ) const

Get pitch of locked pixel data.

Returns
Number of bytes in a row of pixel data, including padding between lines

◆ GetPixels()

void * SDL2pp::Texture::LockHandle::GetPixels ( ) const

Get pointer to raw pixel data of locked region.

Returns
Pointer to raw pixel data of locked region

◆ operator=() [1/2]

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

Deleted assignment operator.

This class is not copyable

◆ operator=() [2/2]

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

Move assignment operator.

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

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