15 if (initial_capacity > 0) {
24 "Cannot resize vertex buffer: stride is 0. Call set_vertex_stride() first");
28 size_t new_size_bytes =
static_cast<size_t>(vertex_count) *
m_vertex_stride;
44 "GeometryWriterNode: Resized vertex buffer to {} vertices ({} bytes total)",
45 vertex_count, new_size_bytes *
sizeof(
float));
50 if (!data || size_bytes == 0) {
52 "Cannot set vertex data: null data or zero size");
58 "Cannot set vertex data: stride is 0");
62 auto expected_vertex_count =
static_cast<uint32_t
>(size_bytes /
m_vertex_stride);
66 "Vertex data size {} is not multiple of stride {}",
70 size_t required_floats = size_bytes /
sizeof(float);
81 "GeometryWriterNode: Set vertex data ({} vertices, {} bytes)",
87 if (!data || size_bytes == 0) {
89 "Cannot set vertex: null data or zero size");
95 "Cannot set vertex: stride is 0");
101 "Vertex index {} out of range (count: {})",
108 "Vertex data size {} exceeds stride {}; truncating",
113 size_t offset_floats = (
static_cast<size_t>(vertex_index) *
m_vertex_stride) /
sizeof(float);
116 reinterpret_cast<uint8_t*
>(
m_vertex_buffer.data()) + (offset_floats *
sizeof(
float)),
121 "GeometryWriterNode: Set vertex {} ({} bytes)", vertex_index, size_bytes);
145 "Vertex index {} out of range (count: {})",
150 size_t offset_floats = (
static_cast<size_t>(vertex_index) *
m_vertex_stride) /
sizeof(float);
176 return std::vector<double>(num_samples, 0.0);
190 "GeometryWriterNode: Saved state ({} vertices, {} bytes)",
198 "GeometryWriterNode: No saved state to restore");
210 "GeometryWriterNode: Restored state ({} vertices, {} bytes)",
229#ifdef MAYAFLUX_PLATFORM_MACOS
230std::vector<LineVertex> GeometryWriterNode::expand_lines_to_triangles(
231 const std::vector<LineVertex>& line_segment)
233 if (line_segment.size() < 2) {
237 std::vector<LineVertex> triangles;
238 triangles.reserve((line_segment.size() - 1) * 6);
240 for (
size_t i = 0; i + 1 < line_segment.size(); ++i) {
241 const auto& v0 = line_segment[i];
242 const auto& v1 = line_segment[i + 1];
244 glm::vec2 p0_2d = glm::vec2(v0.position.x, v0.position.y);
245 glm::vec2 p1_2d = glm::vec2(v1.position.x, v1.position.y);
247 glm::vec2 dir = p1_2d - p0_2d;
248 float len = glm::length(dir);
255 glm::vec2 normal = glm::vec2(-dir.y, dir.x);
257 float t0 = v0.thickness * 0.005F;
258 float t1 = v1.thickness * 0.005F;
260 glm::vec3 p0_top = glm::vec3(p0_2d + normal * t0, v0.position.z);
261 glm::vec3 p0_bot = glm::vec3(p0_2d - normal * t0, v0.position.z);
262 glm::vec3 p1_top = glm::vec3(p1_2d + normal * t1, v1.position.z);
263 glm::vec3 p1_bot = glm::vec3(p1_2d - normal * t1, v1.position.z);
265 triangles.push_back({ p0_top, v0.color, v0.thickness,
266 glm::vec2(0.0F, 0.0F) });
267 triangles.push_back({ p0_bot, v0.color, v0.thickness,
268 glm::vec2(0.0F, 1.0F) });
269 triangles.push_back({ p1_top, v1.color, v1.thickness,
270 glm::vec2(1.0F, 0.0F) });
272 triangles.push_back({ p0_bot, v0.color, v0.thickness,
273 glm::vec2(0.0F, 1.0F) });
274 triangles.push_back({ p1_bot, v1.color, v1.thickness,
275 glm::vec2(1.0F, 1.0F) });
276 triangles.push_back({ p1_top, v1.color, v1.thickness,
277 glm::vec2(1.0F, 0.0F) });
#define MF_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::span< const uint8_t > m_gpu_data
GeometryWriterNode(uint32_t initial_capacity=1024)
Constructor.
void save_state() override
Save current geometry state.
std::span< const uint8_t > get_vertex(uint32_t vertex_index) const
Get a single vertex by index.
void restore_state() override
Restore saved geometry state.
std::vector< uint8_t > m_vertex_buffer
Vertex data buffer (flat array of bytes)
bool m_vertex_data_dirty
Flag: vertex data or layout changed since last GPU upload.
GeometryContext m_context
void clear()
Clear vertex buffer and reset count.
size_t get_vertex_buffer_size_bytes() const
Get vertex buffer size in bytes.
std::optional< GeometryState > m_saved_state
std::vector< double > process_batch(unsigned int num_samples) override
Process batch for geometry generation.
void clear_and_resize(uint32_t vertex_count)
Clear vertex buffer and resize to specified count.
size_t m_vertex_stride
Bytes per vertex (stride for vertex buffer binding)
std::optional< Kakshya::VertexLayout > m_vertex_layout
Cached vertex layout for descriptor binding.
NodeContext & get_last_context() override
Retrieves the last created context object.
void set_vertex_data(const void *data, size_t size_bytes)
Copy raw vertex data into buffer.
void resize_vertex_buffer(uint32_t vertex_count, bool preserve_data=false)
Resize vertex buffer to hold specified number of vertices.
void set_vertex_stride(size_t stride)
Set vertex stride (bytes per vertex)
bool m_needs_layout_update
Flag indicating if layout needs update.
void update_context(double value) override
Updates the context object with the current node state.
uint32_t m_vertex_count
Number of vertices in buffer.
void set_vertex(uint32_t vertex_index, const void *data, size_t size_bytes)
Set a single vertex by index.
virtual void compute_frame()=0
Compute GPU data for this frame.
double value
Current sample value.
Base context class for node callbacks.
uint8_t m_node_capability
Bitmask of capabilities declared by this node.
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
@ STRUCTURED
Context also implements GpuStructuredData.
std::vector< uint8_t > vertex_buffer
std::optional< Kakshya::VertexLayout > vertex_layout