SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::TextureLock Class Reference

Lock a portion of the texture for write-only pixel access. More...

Public Member Functions

 TextureLock (TextureRef resource, OptionalRef< const RectRaw > rect, void **pixels, int *pitch)
 Lock a portion of the texture for write-only pixel access. More...
 
 TextureLock (const TextureLock &other)=delete
 Copy constructor.
 
constexpr TextureLock (TextureLock &&other) noexcept
 Move constructor.
 
 ~TextureLock ()
 Unlock a texture, uploading the changes to video memory, if needed. More...
 
TextureLockoperator= (const TextureLock &other)=delete
 
TextureLockoperator= (TextureLock &&other) noexcept
 Assignment operator.
 
constexpr operator bool () const
 True if not locked.
 
void reset ()
 Unlock a texture, uploading the changes to video memory, if needed. More...
 
TextureRef get ()
 Get the reference to locked resource.
 
void release ()
 Releases the lock without unlocking.
 

Detailed Description

As an optimization, the pixels made available for editing don't necessarily contain the old texture data. This is a write-only operation, and if you need to keep a copy of the texture data you should do that at the application level.

You must use Texture.Unlock() to unlock the pixels and apply any changes.

Parameters
texturethe texture to lock for access, which was created with TEXTUREACCESS_STREAMING.
rectan Rect structure representing the area to lock for access; nullptr to lock the entire texture.
pixelsthis is filled in with a pointer to the locked pixels, appropriately offset by the locked area.
pitchthis is filled in with the pitch of the locked pixels; the pitch is the length of one row in bytes.
Returns
true on success or false if the texture is not valid or was not created with TEXTUREACCESS_STREAMING; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Texture.LockToSurface
Texture.Unlock

Constructor & Destructor Documentation

◆ ~TextureLock()

SDL::TextureLock::~TextureLock ( )
inline

Warning: Please note that Texture.Lock() is intended to be write-only; it will not guarantee the previous contents of the texture will be provided. You must fully initialize any area of a texture that you lock before unlocking it, as the pixels might otherwise be uninitialized memory.

Which is to say: locking and immediately unlocking a texture can result in corrupted textures, depending on the renderer in use.

Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Texture.Lock

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