MayaFlux 0.3.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
22
23 m_pixel_data_dirty = true;
24
26 "Created TextureNode {}x{}", width, height);
27}
28
29void TextureNode::set_pixel(uint32_t x, uint32_t y, float r, float g, float b, float a)
30{
31 if (x >= m_width || y >= m_height) {
32 return;
33 }
34
35 size_t idx = (static_cast<size_t>(y) * m_width + x) * 4;
36 m_pixel_buffer[idx + 0] = r;
37 m_pixel_buffer[idx + 1] = g;
38 m_pixel_buffer[idx + 2] = b;
39 m_pixel_buffer[idx + 3] = a;
40
41 m_pixel_data_dirty = true;
42}
43
44[[nodiscard]] std::array<float, 4> TextureNode::get_pixel(uint32_t x, uint32_t y) const
45{
46 if (x >= m_width || y >= m_height) {
47 return { 0.0F, 0.0F, 0.0F, 0.0F };
48 }
49
50 size_t idx = (static_cast<size_t>(y) * m_width + x) * 4;
51 return {
52 m_pixel_buffer[idx + 0],
53 m_pixel_buffer[idx + 1],
54 m_pixel_buffer[idx + 2],
55 m_pixel_buffer[idx + 3]
56 };
57}
58
59void TextureNode::fill(float r, float g, float b, float a)
60{
61 for (uint32_t y = 0; y < m_height; y++) {
62 for (uint32_t x = 0; x < m_width; x++) {
63 set_pixel(x, y, r, g, b, a);
64 }
65 }
66
67 m_pixel_data_dirty = true;
68}
69
71{
72 std::ranges::fill(m_pixel_buffer, 0.0F);
73 m_pixel_data_dirty = true;
74}
75
84
86{
87 if (!m_saved_pixel_buffer.empty()) {
90
92 "TextureNode: restored state ({} pixels)", m_pixel_buffer.size());
93 } else {
95 "TextureNode: no saved state to restore");
96 }
97}
98
100{
101 m_context.value = value;
104 m_context.m_gpu_data = std::span<const float>(m_pixel_buffer.data(), m_pixel_buffer.size());
105}
106
111
112} // namespace MayaFlux::Nodes::GpuSync
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
size_t a
size_t b
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
uint8_t m_node_capability
Bitmask of capabilities declared by this node.
Definition Node.hpp:433
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
@ VECTOR
Context also implements GpuVectorData.
Definition NodeSpec.hpp:106