Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Image Class Reference

GPU texture resource that can be loaded from files or raw pixel data. More...

#include <spk_image.hpp>

Inheritance diagram for spk::Image:
Inheritance graph
Collaboration diagram for spk::Image:
Collaboration graph

Classes

struct  Region
 Normalized sub-area within the texture. More...

Public Types

using Format = OpenGL::TextureObject::Format
 Pixel format accepted by the underlying texture.
using Filtering = OpenGL::TextureObject::Filtering
 Filtering modes for minification and magnification.
using Filter = OpenGL::TextureObject::Filter
 Pairing of min and mag filtering options.
using Wrap = OpenGL::TextureObject::Wrap
 Texture coordinate wrapping modes.
using Wrapper = OpenGL::TextureObject::Wrapper
 Pairing of wrap modes for the U and V axes.
using Mipmap = OpenGL::TextureObject::Mipmap
 Mipmap generation policy.
Public Types inherited from spk::OpenGL::TextureObject
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

 Image (const std::vector< uint8_t > &p_pixelsAndEncodingData, Filter p_filter=Filter{Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper=Wrapper{Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
 Builds an image from encoded pixel data already in memory.
 Image (const std::filesystem::path &p_path, Filter p_filter=Filter{Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper=Wrapper{Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
 Loads an image from disk.
Public Member Functions inherited from 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.
 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.

Static Public Member Functions

static Image fromFile (const std::filesystem::path &p_path, Filter p_filter=Filter{Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper=Wrapper{Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
 Convenience factory that loads from a file path.
static Image fromRawData (const std::vector< uint8_t > &p_pixelsAndEncodingData, Filter p_filter=Filter{Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper=Wrapper{Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
 Convenience factory that builds from encoded pixel data.

Static Public Attributes

static Region Whole = Region{.anchor = {0, 0}, .size = {1, 1}}
 Represents the entire texture area.

Protected Member Functions

void _loadFromFile (const std::filesystem::path &p_path)
 Populates the texture from an image stored on disk.
void _loadFromData (const std::vector< uint8_t > &p_pixelsAndEncodingData)
 Populates the texture from encoded bytes already in memory.
Protected Member Functions inherited from spk::OpenGL::TextureObject
void _onSynchronize () override
 Synchronizes CPU-side data with the GPU texture.

Detailed Description

GPU texture resource that can be loaded from files or raw pixel data.

See also
spk::OpenGL::TextureObject
auto image = spk::Image::fromFile("spritesheet.png");
image.activate();
static Image fromFile(const std::filesystem::path &p_path, Filter p_filter=Filter{Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper=Wrapper{Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
Convenience factory that loads from a file path.
Definition spk_image.cpp:30

Constructor & Destructor Documentation

◆ Image() [1/2]

spk::Image::Image ( const std::vector< uint8_t > & p_pixelsAndEncodingData,
Filter p_filter = Filter{Filtering::Linear, Filtering::Linear},
Wrapper p_wrapper = Wrapper{Wrap::Repeat, Wrap::Repeat},
Mipmap p_mipmap = Mipmap::Activated )

Builds an image from encoded pixel data already in memory.

Parameters
p_pixelsAndEncodingDataByte buffer containing encoded image.
p_filterMinification and magnification filtering.
p_wrapperTexture wrapping policy on each axis.
p_mipmapMipmap generation strategy.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Image() [2/2]

spk::Image::Image ( const std::filesystem::path & p_path,
Filter p_filter = Filter{Filtering::Linear, Filtering::Linear},
Wrapper p_wrapper = Wrapper{Wrap::Repeat, Wrap::Repeat},
Mipmap p_mipmap = Mipmap::Activated )

Loads an image from disk.

Parameters
p_pathPath to the encoded image file.
p_filterMinification and magnification filtering.
p_wrapperTexture wrapping policy on each axis.
p_mipmapMipmap generation strategy.
Here is the call graph for this function:

Member Function Documentation

◆ _loadFromData()

void spk::Image::_loadFromData ( const std::vector< uint8_t > & p_pixelsAndEncodingData)
protected

Populates the texture from encoded bytes already in memory.

Parameters
p_pixelsAndEncodingDataBuffer containing encoded pixel data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _loadFromFile()

void spk::Image::_loadFromFile ( const std::filesystem::path & p_path)
protected

Populates the texture from an image stored on disk.

Parameters
p_pathPath to the encoded image file.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromFile()

Image spk::Image::fromFile ( const std::filesystem::path & p_path,
Filter p_filter = Filter{Filtering::Linear, Filtering::Linear},
Wrapper p_wrapper = Wrapper{Wrap::Repeat, Wrap::Repeat},
Mipmap p_mipmap = Mipmap::Activated )
static

Convenience factory that loads from a file path.

Parameters
p_pathPath to the encoded image file.
p_filterMinification and magnification filtering.
p_wrapperTexture wrapping policy on each axis.
p_mipmapMipmap generation strategy.
Returns
Fully constructed image bound to an OpenGL texture.
Here is the call graph for this function:

◆ fromRawData()

Image spk::Image::fromRawData ( const std::vector< uint8_t > & p_pixelsAndEncodingData,
Filter p_filter = Filter{Filtering::Linear, Filtering::Linear},
Wrapper p_wrapper = Wrapper{Wrap::Repeat, Wrap::Repeat},
Mipmap p_mipmap = Mipmap::Activated )
static

Convenience factory that builds from encoded pixel data.

Parameters
p_pixelsAndEncodingDataByte buffer containing encoded image.
p_filterMinification and magnification filtering.
p_wrapperTexture wrapping policy on each axis.
p_mipmapMipmap generation strategy.
Returns
Fully constructed image bound to an OpenGL texture.
Here is the call graph for this function:

The documentation for this class was generated from the following files:
  • includes/structure/graphics/spk_image.hpp
  • srcs/structure/graphics/spk_image.cpp