MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextureNode.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "GpuSync.hpp"
4
6
7/**
8 * @class TextureNode
9 * @brief Base class for texture-generating nodes
10 *
11 * Provides common functionality for managing texture dimensions and pixel data
12 * in RGBA float format. Derived classes implement compute_frame() to define
13 * specific texture generation or processing algorithms.
14 *
15 * Texture data is stored as a flat array in row-major order:
16 * [R0,G0,B0,A0, R1,G1,B1,A1, ..., Rn,Gn,Bn,An]
17 */
18class MAYAFLUX_API TextureNode : public GpuSync {
19protected:
20 uint32_t m_width;
21 uint32_t m_height;
22 std::vector<float> m_pixel_buffer; // RGBA format
23
24 /**
25 * @brief Flag: pixel data changed since last GPU upload
26 *
27 * Set to true whenever compute_frame() modifies m_pixel_buffer.
28 * Kakshya binding system checks this before staging texture upload.
29 * Cleared by Kakshya after successful GPU transfer.
30 */
31 bool m_pixel_data_dirty { true };
32
33public:
34 TextureNode(uint32_t width, uint32_t height);
35
36 /**
37 * @brief Get pixel buffer
38 * @return Span of pixel data in RGBA format
39 */
40 [[nodiscard]] std::span<const float> get_pixel_buffer() const { return m_pixel_buffer; }
41
42 [[nodiscard]] uint32_t get_width() const { return m_width; }
43 [[nodiscard]] uint32_t get_height() const { return m_height; }
44
45 /**
46 * @brief Get total number of pixels
47 * @return width * height
48 */
49 [[nodiscard]] size_t get_pixel_count() const
50 {
51 return static_cast<size_t>(m_width) * static_cast<size_t>(m_height);
52 }
53
54 /**
55 * @brief Get buffer size in bytes
56 * @return Total size of pixel buffer
57 */
58 [[nodiscard]] size_t get_buffer_size() const
59 {
60 return m_pixel_buffer.size() * sizeof(float);
61 }
62
63 /**
64 * @brief Check if pixel data changed since last GPU sync
65 * @return True if m_pixel_buffer has been modified
66 *
67 * For textures, this is simple: did compute_frame() modify pixels?
68 * The binding processor checks this to decide whether to upload to GPU.
69 */
70 [[nodiscard]] bool needs_gpu_update() const override
71 {
72 return m_pixel_data_dirty;
73 }
74
75 /**
76 * @brief Clear the dirty flag after GPU upload completes
77 *
78 * Called by Kakshya's TextureBindingProcessor after it stages the
79 * pixel data into a GPU transfer buffer and submits the command.
80 */
81 void clear_gpu_update_flag() override
82 {
83 m_pixel_data_dirty = false;
84 }
85
86protected:
87 /**
88 * @brief Set pixel color at (x, y)
89 * @param x X coordinate
90 * @param y Y coordinate
91 * @param r Red channel [0, 1]
92 * @param g Green channel [0, 1]
93 * @param b Blue channel [0, 1]
94 * @param a Alpha channel [0, 1] (default: 1.0)
95 */
96 void set_pixel(uint32_t x, uint32_t y, float r, float g, float b, float a = 1.0F);
97
98 /**
99 * @brief Get pixel color at (x, y)
100 * @param x X coordinate
101 * @param y Y coordinate
102 * @return RGBA values as array [r, g, b, a]
103 */
104 [[nodiscard]] std::array<float, 4> get_pixel(uint32_t x, uint32_t y) const;
105
106 /**
107 * @brief Fill entire texture with solid color
108 * @param r Red channel
109 * @param g Green channel
110 * @param b Blue channel
111 * @param a Alpha channel (default: 1.0)
112 */
113 void fill(float r, float g, float b, float a = 1.0F);
114
115 /**
116 * @brief Clear texture to black
117 */
118 void clear();
119};
120
121} // namespace MayaFlux::Nodes
void clear_gpu_update_flag() override
Clear the dirty flag after GPU upload completes.
std::span< const float > get_pixel_buffer() const
Get pixel buffer.
bool needs_gpu_update() const override
Check if pixel data changed since last GPU sync.
size_t get_pixel_count() const
Get total number of pixels.
size_t get_buffer_size() const
Get buffer size in bytes.
Base class for texture-generating nodes.