MayaFlux 0.1.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} // namespace MayaFlux::Nodes
#define MF_DEBUG(comp, ctx,...)
bool m_pixel_data_dirty
Flag: pixel data changed since last GPU upload.
std::array< float, 4 > get_pixel(uint32_t x, uint32_t y) const
Get pixel color at (x, y)
TextureNode(uint32_t width, uint32_t height)
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)
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.