MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextureNode.cpp
Go to the documentation of this file.
1#include "TextureNode.hpp"
2
4
6
7TextureNode::TextureNode(uint32_t width, uint32_t height)
8 : m_width(width)
9 , m_height(height)
10 , m_pixel_buffer(static_cast<size_t>(width) * static_cast<size_t>(height) * 4)
11{
12 if (width == 0 || height == 0) {
13 error<std::invalid_argument>(
16 std::source_location::current(),
17 "Cannot create TextureNode with zero dimensions ({} x {})",
18 width, height);
19 }
20
21 m_pixel_data_dirty = true;
22
24 "Created TextureNode {}x{}", width, height);
25}
26
27void TextureNode::set_pixel(uint32_t x, uint32_t y, float r, float g, float b, float a)
28{
29 if (x >= m_width || y >= m_height) {
30 return;
31 }
32
33 size_t idx = (static_cast<size_t>(y) * m_width + x) * 4;
34 m_pixel_buffer[idx + 0] = r;
35 m_pixel_buffer[idx + 1] = g;
36 m_pixel_buffer[idx + 2] = b;
37 m_pixel_buffer[idx + 3] = a;
38
39 m_pixel_data_dirty = true;
40}
41
42[[nodiscard]] std::array<float, 4> TextureNode::get_pixel(uint32_t x, uint32_t y) const
43{
44 if (x >= m_width || y >= m_height) {
45 return { 0.0F, 0.0F, 0.0F, 0.0F };
46 }
47
48 size_t idx = (static_cast<size_t>(y) * m_width + x) * 4;
49 return {
50 m_pixel_buffer[idx + 0],
51 m_pixel_buffer[idx + 1],
52 m_pixel_buffer[idx + 2],
53 m_pixel_buffer[idx + 3]
54 };
55}
56
57void TextureNode::fill(float r, float g, float b, float a)
58{
59 for (uint32_t y = 0; y < m_height; y++) {
60 for (uint32_t x = 0; x < m_width; x++) {
61 set_pixel(x, y, r, g, b, a);
62 }
63 }
64
65 m_pixel_data_dirty = true;
66}
67
69{
70 std::ranges::fill(m_pixel_buffer, 0.0F);
71 m_pixel_data_dirty = true;
72}
73
82
84{
85 if (!m_saved_pixel_buffer.empty()) {
88
90 "TextureNode: restored state ({} pixels)", m_pixel_buffer.size());
91 } else {
93 "TextureNode: no saved state to restore");
94 }
95}
96
98{
99 m_context.value = value;
102 m_context.m_gpu_data = std::span<const float>(m_pixel_buffer.data(), m_pixel_buffer.size());
103}
104
109
110} // namespace MayaFlux::Nodes::GpuSync
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
bool m_pixel_data_dirty
Flag: pixel data changed since last GPU upload.
NodeContext & get_last_context() override
Get the last created context object.
std::array< float, 4 > get_pixel(uint32_t x, uint32_t y) const
Get pixel color at (x, y)
std::vector< float > m_saved_pixel_buffer
void restore_state() override
Restore saved pixel state.
TextureNode(uint32_t width, uint32_t height)
void update_context(double value) override
Updates the context object with the current node state.
void clear()
Clear texture to black.
void fill(float r, float g, float b, float a=1.0F)
Fill entire texture with solid color.
void set_pixel(uint32_t x, uint32_t y, float r, float g, float b, float a=1.0F)
Set pixel color at (x, y)
void save_state() override
Save current pixel state.
std::span< const float > m_gpu_data
double value
Current sample value.
Definition Node.hpp:40
Base context class for node callbacks.
Definition Node.hpp:30
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.