Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::OpenGL::TextureObject Class Reference

CPU-staged 2D texture with activation and parameter controls. More...

#include <spk_texture_object.hpp>

Inheritance diagram for spk::OpenGL::TextureObject:
Inheritance graph
Collaboration diagram for spk::OpenGL::TextureObject:
Collaboration graph

Classes

struct  Filter
 Filtering modes applied on minification and magnification. More...
struct  Wrapper
 Wrapping policy along each texture axis. More...

Public Types

enum class  Format : GLenum {
  RGB = GL_RGB , RGBA = GL_RGBA , BGR = GL_BGR , BGRA = GL_BGRA ,
  GreyLevel = GL_RED , DualChannel = GL_RG , DepthComponent = GL_DEPTH_COMPONENT , DepthStencil = GL_DEPTH_STENCIL ,
  Error = GL_NONE
}
 Supported GPU pixel formats.
enum class  Filtering : GLenum { Nearest = GL_NEAREST , Linear = GL_LINEAR }
 Texture sampling algorithms for minification/magnification.
enum class  Wrap : GLenum { Repeat = GL_REPEAT , ClampToEdge = GL_CLAMP_TO_EDGE , ClampToBorder = GL_CLAMP_TO_BORDER }
 Texture coordinate wrapping strategies.
using Mipmap = spk::ActivationStatus
 Indicates whether mipmaps are active.
Public Types inherited from spk::ActivableObject
using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.

Public Member Functions

 TextureObject (Format p_format=Format::RGBA, Filter p_filter={Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper={Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
 Constructs a texture with format, filtering, and wrapping options.
 TextureObject (const TextureObject &p_other)
 Copy-constructs a texture object including CPU-side data.
TextureObjectoperator= (const TextureObject &p_other)
 Copy-assigns a texture object including CPU-side data.
 TextureObject (TextureObject &&p_other) noexcept
 Move-constructs a texture object transferring ownership.
TextureObjectoperator= (TextureObject &&p_other) noexcept
 Move-assigns a texture object transferring ownership.
void activate () const
 Activates this texture for rendering.
void deactivate () const
 Deactivates this texture after rendering.
Format format () const
 Gets the current texture format.
Filter filter () const
 Gets filtering parameters.
Wrapper wrapper () const
 Gets wrapping parameters.
Mipmap mipmap () const
 Gets mipmap activation state.
void setFormat (Format p_format)
 Sets the texture format (affects upload interpretation).
void setFiltering (Filter p_filter)
 Sets min/mag filtering together.
void setFiltering (Filtering p_minFilter, Filtering p_magFilter)
 Sets minification and magnification filters independently.
void setWrap (Wrapper p_wrapper)
 Sets wrapping for both axes.
void setWrap (Wrap p_wrapS, Wrap p_wrapT)
 Sets wrapping for each axis independently.
void setMipmap (Mipmap p_mipmap)
 Sets mipmap activation state.
spk::Vector2UInt size () const
 Returns texture dimensions.
size_t sizeAsBytes () const
 Returns CPU data size in bytes.
GLuint id () const
 Returns GL texture id, creating if needed.
void setData (const uint8_t *p_data, const spk::Vector2UInt &p_size, Format p_format=Format::RGBA)
 Uploads pixel data from raw pointer.
void setData (std::vector< uint8_t > p_data, const spk::Vector2UInt &p_size, Format p_format=Format::RGBA)
 Uploads pixel data by move.
void clearData ()
 Clears CPU data and marks for sync.
void resize (const spk::Vector2UInt &p_size)
 Resizes CPU data and marks for sync.
std::vector< uint8_t > & data ()
 Gets CPU-side pixel data.
const std::vector< uint8_t > & data () const
 Gets CPU-side pixel data.
void flip (const spk::Orientation &p_orientation)
 Flips stored pixel data along the given orientation.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
Public Member Functions inherited from spk::ActivableObject
 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.
Public Member Functions inherited from spk::SynchronizableObject
void requestSynchronization () noexcept
 Marks the object as needing synchronization.
bool needsSynchronization () const noexcept
 Checks if synchronization is pending.
void synchronize ()
 Performs synchronization if requested.
void forceSynchronization ()
 Forces synchronization regardless of current flag.

Protected Member Functions

void _onSynchronize () override
 Synchronizes CPU-side data with the GPU texture.

Detailed Description

CPU-staged 2D texture with activation and parameter controls.

Constructor & Destructor Documentation

◆ TextureObject() [1/3]

spk::OpenGL::TextureObject::TextureObject ( Format p_format = Format::RGBA,
Filter p_filter = {Filtering::Linear, Filtering::Linear},
Wrapper p_wrapper = {Wrap::Repeat, Wrap::Repeat},
Mipmap p_mipmap = Mipmap::Activated )

Constructs a texture with format, filtering, and wrapping options.

Parameters
p_formatPixel format of the texture storage.
p_filterFiltering configuration for minification and magnification.
p_wrapperWrapping modes for the S and T axes.
p_mipmapWhether mipmaps are generated and activated.
Here is the caller graph for this function:

◆ TextureObject() [2/3]

spk::OpenGL::TextureObject::TextureObject ( const TextureObject & p_other)

Copy-constructs a texture object including CPU-side data.

Parameters
p_otherSource texture.
Here is the call graph for this function:

◆ TextureObject() [3/3]

spk::OpenGL::TextureObject::TextureObject ( TextureObject && p_other)
noexcept

Move-constructs a texture object transferring ownership.

Parameters
p_otherSource texture to move from.
Here is the call graph for this function:

Member Function Documentation

◆ _onSynchronize()

void spk::OpenGL::TextureObject::_onSynchronize ( )
overrideprotectedvirtual

Synchronizes CPU-side data with the GPU texture.

Implements spk::SynchronizableObject.

◆ data() [1/2]

std::vector< uint8_t > & spk::OpenGL::TextureObject::data ( )

Gets CPU-side pixel data.

Returns
Const reference to bytes.

◆ data() [2/2]

const std::vector< uint8_t > & spk::OpenGL::TextureObject::data ( ) const

Gets CPU-side pixel data.

Returns
Const reference to bytes.

◆ filter()

TextureObject::Filter spk::OpenGL::TextureObject::filter ( ) const

Gets filtering parameters.

Returns
Active min/mag filtering pair.

◆ flip()

void spk::OpenGL::TextureObject::flip ( const spk::Orientation & p_orientation)

Flips stored pixel data along the given orientation.

Parameters
p_orientationOrientation to flip.
Here is the call graph for this function:

◆ format()

TextureObject::Format spk::OpenGL::TextureObject::format ( ) const

Gets the current texture format.

Returns
Format used to interpret stored pixels.
Here is the caller graph for this function:

◆ id()

GLuint spk::OpenGL::TextureObject::id ( ) const

Returns GL texture id, creating if needed.

Returns
OpenGL texture handle associated with this object.

◆ mipmap()

TextureObject::Mipmap spk::OpenGL::TextureObject::mipmap ( ) const

Gets mipmap activation state.

Returns
ActivationStatus indicating mipmap usage.

◆ operator=() [1/2]

TextureObject & spk::OpenGL::TextureObject::operator= ( const TextureObject & p_other)

Copy-assigns a texture object including CPU-side data.

Parameters
p_otherSource texture.
Returns
*this after assignment.
Here is the call graph for this function:

◆ operator=() [2/2]

TextureObject & spk::OpenGL::TextureObject::operator= ( TextureObject && p_other)
noexcept

Move-assigns a texture object transferring ownership.

Parameters
p_otherSource texture to move from.
Returns
*this after move assignment.
Here is the call graph for this function:

◆ resize()

void spk::OpenGL::TextureObject::resize ( const spk::Vector2UInt & p_size)

Resizes CPU data and marks for sync.

Parameters
p_sizeNew dimensions.
Here is the call graph for this function:

◆ setData() [1/2]

void spk::OpenGL::TextureObject::setData ( const uint8_t * p_data,
const spk::Vector2UInt & p_size,
Format p_format = Format::RGBA )

Uploads pixel data from raw pointer.

Parameters
p_dataSource pointer.
p_sizeDimensions.
p_formatOptional source format override.
Here is the caller graph for this function:

◆ setData() [2/2]

void spk::OpenGL::TextureObject::setData ( std::vector< uint8_t > p_data,
const spk::Vector2UInt & p_size,
Format p_format = Format::RGBA )

Uploads pixel data by move.

Parameters
p_dataPixel bytes.
p_sizeDimensions.
p_formatOptional source format override.
Here is the call graph for this function:

◆ setFiltering() [1/2]

void spk::OpenGL::TextureObject::setFiltering ( Filter p_filter)

Sets min/mag filtering together.

Parameters
p_filterFiltering pair to apply.
Here is the caller graph for this function:

◆ setFiltering() [2/2]

void spk::OpenGL::TextureObject::setFiltering ( Filtering p_minFilter,
Filtering p_magFilter )

Sets minification and magnification filters independently.

Parameters
p_minFilterFiltering used when shrinking textures.
p_magFilterFiltering used when enlarging textures.
Here is the call graph for this function:

◆ setFormat()

void spk::OpenGL::TextureObject::setFormat ( Format p_format)

Sets the texture format (affects upload interpretation).

Parameters
p_formatNew pixel format to apply.
Here is the call graph for this function:

◆ setMipmap()

void spk::OpenGL::TextureObject::setMipmap ( Mipmap p_mipmap)

Sets mipmap activation state.

Parameters
p_mipmapActivation flag.
Here is the caller graph for this function:

◆ setWrap() [1/2]

void spk::OpenGL::TextureObject::setWrap ( Wrap p_wrapS,
Wrap p_wrapT )

Sets wrapping for each axis independently.

Parameters
p_wrapSHorizontal wrapping mode.
p_wrapTVertical wrapping mode.
Here is the call graph for this function:

◆ setWrap() [2/2]

void spk::OpenGL::TextureObject::setWrap ( Wrapper p_wrapper)

Sets wrapping for both axes.

Parameters
p_wrapperWrap configuration for S and T axes.
Here is the caller graph for this function:

◆ size()

spk::Vector2UInt spk::OpenGL::TextureObject::size ( ) const

Returns texture dimensions.

Returns
Width and height of the stored pixel buffer.
Here is the caller graph for this function:

◆ sizeAsBytes()

size_t spk::OpenGL::TextureObject::sizeAsBytes ( ) const

Returns CPU data size in bytes.

Returns
Number of bytes allocated for pixel data.

◆ wrapper()

TextureObject::Wrapper spk::OpenGL::TextureObject::wrapper ( ) const

Gets wrapping parameters.

Returns
Current wrapping configuration.

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