MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Buffers::TextureBuffer Class Reference

A hybrid buffer managing both a textured quad geometry and its pixel data. More...

#include <TextureBuffer.hpp>

+ Inheritance diagram for MayaFlux::Buffers::TextureBuffer:
+ Collaboration diagram for MayaFlux::Buffers::TextureBuffer:

Classes

struct  QuadVertex
 Use custom vertex geometry instead of default quad. More...
 
struct  RenderConfig
 

Public Member Functions

 TextureBuffer (uint32_t width, uint32_t height, Portal::Graphics::ImageFormat format, const void *initial_pixel_data=nullptr)
 Create texture buffer with dimensions.
 
 ~TextureBuffer () override=default
 
void setup_processors (ProcessingToken token) override
 Setup processors with a processing token.
 
uint32_t get_width () const
 
uint32_t get_height () const
 
Portal::Graphics::ImageFormat get_format () const
 
std::shared_ptr< Core::VKImageget_texture () const
 Get GPU texture image Suitable for binding to shaders via RenderProcessor::bind_texture()
 
bool has_texture () const
 
std::shared_ptr< TextureProcessorget_texture_processor () const
 
void set_pixel_data (const void *data, size_t size)
 Replace pixel data.
 
void mark_pixels_dirty ()
 Mark pixel data as changed Use this if you modify pixel data in-place without calling set_pixel_data()
 
void set_position (float x, float y)
 Set screen position (NDC or pixel coords depending on rendering setup)
 
void set_scale (float width, float height)
 Set display size.
 
void set_rotation (float angle_radians)
 Set rotation around center.
 
glm::vec2 get_position () const
 
glm::vec2 get_scale () const
 
float get_rotation () const
 
void set_custom_vertices (const std::vector< QuadVertex > &vertices)
 
void use_default_quad ()
 Reset to default fullscreen quad Uses position and scale to generate quad geometry.
 
const std::vector< uint8_t > & get_pixel_data () const
 
void mark_texture_dirty ()
 
bool is_texture_dirty () const
 
void clear_dirty_flag ()
 
void setup_rendering (const RenderConfig &config)
 Setup rendering with RenderProcessor.
 
std::shared_ptr< RenderProcessorget_render_processor () const
 
- Public Member Functions inherited from MayaFlux::Buffers::VKBuffer
 VKBuffer (size_t size_bytes, Usage usage, Kakshya::DataModality modality)
 Construct an unregistered VKBuffer.
 
 VKBuffer ()=default
 
 ~VKBuffer () override
 Virtual destructor.
 
void clear () override
 Clear buffer contents.
 
std::vector< Kakshya::DataVariantget_data ()
 Read buffer contents as Kakshya DataVariant.
 
void set_data (const std::vector< Kakshya::DataVariant > &data)
 Write data into the buffer.
 
void resize (size_t new_size, bool preserve_data=false)
 Resize buffer and recreate GPU resources if needed.
 
size_t get_size () const
 Get current logical size in bytes.
 
void process_default () override
 Run the buffer's default processor (if set and enabled)
 
void set_default_processor (std::shared_ptr< Buffers::BufferProcessor > processor) override
 Set the buffer's default processor.
 
std::shared_ptr< Buffers::BufferProcessorget_default_processor () const override
 Get the currently attached default processor.
 
std::shared_ptr< Buffers::BufferProcessingChainget_processing_chain () override
 Access the buffer's processing chain.
 
void set_processing_chain (std::shared_ptr< Buffers::BufferProcessingChain > chain, bool force=false) override
 Replace the buffer's processing chain.
 
bool has_data_for_cycle () const override
 Checks if the buffer has data for the current processing cycle.
 
bool needs_removal () const override
 Checks if the buffer should be removed from processing chains.
 
void mark_for_processing (bool has_data) override
 Marks the buffer's data availability for the current processing cycle.
 
void mark_for_removal () override
 Marks the buffer for removal from processing chains.
 
void enforce_default_processing (bool should_process) override
 Controls whether the buffer should use default processing.
 
bool needs_default_processing () override
 Checks if the buffer should undergo default processing.
 
bool try_acquire_processing () override
 Try to acquire processing lock for this buffer.
 
void release_processing () override
 Release previously acquired processing lock.
 
bool is_processing () const override
 Query whether the buffer is currently being processed.
 
vk::Buffer & get_buffer ()
 Get VkBuffer handle (VK_NULL_HANDLE if not registered)
 
vk::DeviceSize get_size_bytes () const
 
vk::Format get_format () const
 Convert modality to a recommended VkFormat.
 
bool is_initialized () const
 Check whether Vulkan handles are present (buffer registered)
 
Kakshya::DataModality get_modality () const
 Get the buffer's semantic modality.
 
const std::vector< Kakshya::DataDimension > & get_dimensions () const
 Get the inferred data dimensions for the buffer contents.
 
void set_modality (Kakshya::DataModality modality)
 Update the semantic modality and re-infer dimensions.
 
Usage get_usage () const
 Retrieve the declared usage intent.
 
void set_buffer (vk::Buffer buffer)
 Set VkBuffer handle after backend allocation.
 
void set_memory (vk::DeviceMemory memory)
 Set device memory handle after backend allocation.
 
void set_mapped_ptr (void *ptr)
 Set mapped host pointer (for host-visible allocations)
 
void set_buffer_resources (const VKBufferResources &resources)
 Set all buffer resources at once.
 
const VKBufferResourcesget_buffer_resources ()
 Get all buffer resources at once.
 
bool is_host_visible () const
 Whether this VKBuffer should be host-visible.
 
vk::BufferUsageFlags get_usage_flags () const
 Get appropriate VkBufferUsageFlags for creation based on Usage.
 
vk::MemoryPropertyFlags get_memory_properties () const
 Get appropriate VkMemoryPropertyFlags for allocation based on Usage.
 
void * get_mapped_ptr () const
 Get mapped host pointer (nullptr if not host-visible or unmapped)
 
void mark_dirty_range (size_t offset, size_t size)
 Get device memory handle.
 
void mark_invalid_range (size_t offset, size_t size)
 Mark a range as invalid (needs download)
 
std::vector< std::pair< size_t, size_t > > get_and_clear_dirty_ranges ()
 Retrieve and clear all dirty ranges.
 
std::vector< std::pair< size_t, size_t > > get_and_clear_invalid_ranges ()
 Retrieve and clear all invalid ranges.
 
void set_pipeline_window (RenderPipelineID id, const std::shared_ptr< Core::Window > &window)
 Associate this buffer with a window for rendering.
 
std::shared_ptr< Core::Windowget_pipeline_window (RenderPipelineID id) const
 Get the window associated with this buffer.
 
bool has_render_pipeline () const
 Check if this buffer has a rendering pipeline configured.
 
std::unordered_map< RenderPipelineID, std::shared_ptr< Core::Window > > get_render_pipelines () const
 Get all render pipelines associated with this buffer.
 
void set_pipeline_command (RenderPipelineID pipeline_id, CommandBufferID cmd_id)
 Store recorded command buffer for a pipeline.
 
CommandBufferID get_pipeline_command (RenderPipelineID pipeline_id) const
 Get recorded command buffer for a pipeline.
 
void clear_pipeline_commands ()
 Clear all recorded commands (called after presentation)
 
void set_vertex_layout (const Kakshya::VertexLayout &layout)
 Set vertex layout for this buffer.
 
std::optional< Kakshya::VertexLayoutget_vertex_layout () const
 Get vertex layout if set.
 
bool has_vertex_layout () const
 Check if this buffer has vertex layout configured.
 
void clear_vertex_layout ()
 Clear vertex layout.
 
std::shared_ptr< Bufferclone_to (uint8_t dest_desc) override
 Creates a clone of this buffer for a specific channel or usage enum.
 
std::shared_ptr< VKBufferclone_to (Usage usage)
 Create a clone of this buffer with the same data and properties.
 
void force_internal_usage (bool internal) override
 Set whether this buffer is for internal engine usage.
 
bool is_internal_only () const override
 Check whether this buffer is for internal engine usage.
 
- Public Member Functions inherited from MayaFlux::Buffers::Buffer
virtual ~Buffer ()=default
 Virtual destructor for proper resource management.
 

Private Member Functions

void generate_default_quad ()
 
void generate_quad_with_transform ()
 

Static Private Member Functions

static size_t calculate_quad_vertex_size ()
 

Private Attributes

std::shared_ptr< RenderProcessorm_render_processor
 
uint32_t m_width
 
uint32_t m_height
 
Portal::Graphics::ImageFormat m_format
 
std::vector< uint8_t > m_pixel_data
 
bool m_texture_dirty = true
 
glm::vec2 m_position { 0.0F, 0.0F }
 
glm::vec2 m_scale { 1.0F, 1.0F }
 
float m_rotation { 0.0F }
 
bool m_geometry_dirty = true
 
std::vector< uint8_t > m_vertex_bytes
 
bool m_uses_custom_vertices = false
 
std::shared_ptr< Core::VKImagem_gpu_texture
 
std::shared_ptr< TextureProcessorm_texture_processor
 

Friends

class TextureProcessor
 

Additional Inherited Members

- Public Types inherited from MayaFlux::Buffers::VKBuffer
enum class  Usage : uint8_t {
  STAGING , DEVICE , COMPUTE , VERTEX ,
  INDEX , UNIFORM
}
 

Detailed Description

A hybrid buffer managing both a textured quad geometry and its pixel data.

TextureBuffer serves a dual purpose:

  1. Geometry: It acts as a VKBuffer containing vertex data for a 2D quad (Position + UVs). This geometry can be transformed (translated, scaled, rotated) or customized.
  2. Texture: It manages raw pixel data in system memory and synchronizes it with a GPU-resident VKImage via the TextureProcessor.

Unlike a raw texture resource, this class represents a "renderable sprite" or "surface". The vertex data is dynamic and updates automatically when transforms change. The pixel data can be static (loaded once) or dynamic (procedural/video), with dirty-flag tracking to minimize bus traffic.

Key Features:

  • Automatic quad generation based on dimensions.
  • Built-in 2D transform support (Position, Scale, Rotation) affecting vertex positions.
  • CPU-side pixel storage with automatic upload to GPU VKImage on change.
  • Support for custom vertex geometry (e.g., for non-rectangular sprites).

Definition at line 32 of file TextureBuffer.hpp.


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