summaryrefslogtreecommitdiff
path: root/cpp-timeplot
diff options
context:
space:
mode:
authorgrothedev <grothedev@gmail.com>2026-05-29 21:34:16 -0400
committergrothedev <grothedev@gmail.com>2026-05-29 21:34:16 -0400
commit27dc5849c3eaf4824d79938e7077abdbe2c82e24 (patch)
tree4a6e963d291132ad6f5a22841ea2404b60949366 /cpp-timeplot
parent73d75835e18a33c7f6c1b09bbcef93b16a7a9bfa (diff)
updates from claude. need to review. archiving rust and cpp stuff, going completely TS
Diffstat (limited to 'cpp-timeplot')
-rw-r--r--cpp-timeplot/CMakeLists.txt86
-rw-r--r--cpp-timeplot/README.md32
-rw-r--r--cpp-timeplot/shaders/waterfall.wgsl22
-rw-r--r--cpp-timeplot/src/main.cpp210
-rw-r--r--cpp-timeplot/src/renderer.cpp249
-rw-r--r--cpp-timeplot/src/renderer.h35
-rw-r--r--cpp-timeplot/src/waterfall.cpp170
-rw-r--r--cpp-timeplot/src/waterfall.h39
-rw-r--r--cpp-timeplot/src/webgpu_impl.cpp2
9 files changed, 0 insertions, 845 deletions
diff --git a/cpp-timeplot/CMakeLists.txt b/cpp-timeplot/CMakeLists.txt
deleted file mode 100644
index 5ae12be..0000000
--- a/cpp-timeplot/CMakeLists.txt
+++ /dev/null
@@ -1,86 +0,0 @@
-cmake_minimum_required(VERSION 3.20)
-project(timeplot-cpp VERSION 0.1.0)
-
-set(CMAKE_CXX_STANDARD 20)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-
-# Find dependencies
-find_package(PkgConfig REQUIRED)
-
-# GLFW for windowing
-pkg_check_modules(GLFW REQUIRED glfw3)
-
-# Use precompiled Dawn from Chromium
-option(USE_SYSTEM_DAWN "Use system-installed Dawn" OFF)
-
-if(USE_SYSTEM_DAWN)
- find_package(dawn REQUIRED)
-else()
- # Download precompiled Dawn binaries
- message(STATUS "Downloading precompiled Dawn...")
-
- set(DAWN_VERSION "6536")
- set(DAWN_DIR "${CMAKE_BINARY_DIR}/dawn-prebuilt")
-
- if(NOT EXISTS "${DAWN_DIR}")
- # Try to download from a prebuilt source
- # Note: Dawn doesn't officially provide prebuilt binaries, so we'll build once and cache
- # For now, let's use webgpu-distribution which provides prebuilt headers
- include(FetchContent)
-
- # Fetch webgpu-distribution (lighter than full Dawn)
- FetchContent_Declare(
- webgpu-distribution
- GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution
- GIT_TAG main
- GIT_SHALLOW TRUE
- )
-
- FetchContent_MakeAvailable(webgpu-distribution)
-
- set(WEBGPU_BACKEND "WGPU" CACHE STRING "Backend to use")
-
- # Fetch webgpu-hpp (C++ wrapper)
- FetchContent_Declare(
- webgpu-hpp
- GIT_REPOSITORY https://github.com/eliemichel/WebGPU-Cpp
- GIT_TAG main
- GIT_SHALLOW TRUE
- )
- FetchContent_MakeAvailable(webgpu-hpp)
-
- # Fetch glfw3webgpu (GLFW-WebGPU integration)
- FetchContent_Declare(
- glfw3webgpu
- GIT_REPOSITORY https://github.com/eliemichel/glfw3webgpu
- GIT_TAG main
- GIT_SHALLOW TRUE
- )
- FetchContent_MakeAvailable(glfw3webgpu)
- endif()
-endif()
-
-# Source files
-set(SOURCES
- src/main.cpp
- src/renderer.cpp
- src/waterfall.cpp
-)
-
-add_executable(timeplot ${SOURCES})
-
-target_include_directories(timeplot PRIVATE
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- ${GLFW_INCLUDE_DIRS}
-)
-
-target_link_libraries(timeplot PRIVATE
- ${GLFW_LIBRARIES}
- webgpu
- glfw3webgpu
-)
-
-# Copy shaders to build directory
-file(GLOB SHADERS "${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.wgsl")
-file(COPY ${SHADERS} DESTINATION ${CMAKE_BINARY_DIR}/shaders)
diff --git a/cpp-timeplot/README.md b/cpp-timeplot/README.md
deleted file mode 100644
index 2700f9f..0000000
--- a/cpp-timeplot/README.md
+++ /dev/null
@@ -1,32 +0,0 @@
-# TimePlot C++ Implementation
-
-WebGPU-based waterfall plot renderer using Dawn and GLFW.
-
-## Dependencies
-
-- CMake 3.20+
-- C++20 compiler
-- GLFW3
-- Dawn (fetched automatically by CMake)
-
-## Build
-
-```bash
-mkdir build && cd build
-cmake ..
-make -j$(nproc)
-./timeplot
-```
-
-## Controls
-
-- `G` - Toggle grid visibility
-- `ESC` - Exit application
-
-## Features
-
-- Multi-threaded GPU rendering via Vulkan/WebGPU
-- Multiple graph views (side-by-side)
-- Animated waterfall plots
-- Grid lines and borders
-- Real-time data visualization
diff --git a/cpp-timeplot/shaders/waterfall.wgsl b/cpp-timeplot/shaders/waterfall.wgsl
deleted file mode 100644
index 6655301..0000000
--- a/cpp-timeplot/shaders/waterfall.wgsl
+++ /dev/null
@@ -1,22 +0,0 @@
-struct VertexInput {
- @location(0) position: vec2<f32>,
- @location(1) color: vec3<f32>,
-}
-
-struct VertexOutput {
- @builtin(position) clip_position: vec4<f32>,
- @location(0) color: vec3<f32>,
-}
-
-@vertex
-fn vs_main(in: VertexInput) -> VertexOutput {
- var out: VertexOutput;
- out.clip_position = vec4<f32>(in.position, 0.0, 1.0);
- out.color = in.color;
- return out;
-}
-
-@fragment
-fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
- return vec4<f32>(in.color, 1.0);
-}
diff --git a/cpp-timeplot/src/main.cpp b/cpp-timeplot/src/main.cpp
deleted file mode 100644
index 35ae051..0000000
--- a/cpp-timeplot/src/main.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-#include <GLFW/glfw3.h>
-#include <webgpu/webgpu.h>
-#include <glfw3webgpu.h>
-#include <iostream>
-#include <memory>
-#include <cstdlib>
-
-#include "renderer.h"
-
-constexpr int WINDOW_WIDTH = 1280;
-constexpr int WINDOW_HEIGHT = 720;
-
-class Application {
-public:
- Application() : window_(nullptr), instance_(nullptr), device_(nullptr),
- surface_(nullptr), adapter_(nullptr) {}
-
- ~Application() {
- cleanup();
- }
-
- bool initialize() {
- if (!glfwInit()) {
- std::cerr << "Failed to initialize GLFW" << std::endl;
- return false;
- }
-
- glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
- glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
-
- window_ = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT,
- "TimePlot - C++ WebGPU", nullptr, nullptr);
- if (!window_) {
- std::cerr << "Failed to create window" << std::endl;
- return false;
- }
-
- glfwSetWindowUserPointer(window_, this);
- glfwSetKeyCallback(window_, keyCallback);
- glfwSetFramebufferSizeCallback(window_, resizeCallback);
-
- if (!initWebGPU()) {
- return false;
- }
-
- renderer_ = std::make_unique<Renderer>(device_, surface_, WINDOW_WIDTH, WINDOW_HEIGHT);
- if (!renderer_->initialize()) {
- std::cerr << "Failed to initialize renderer" << std::endl;
- return false;
- }
-
- return true;
- }
-
- void run() {
- while (!glfwWindowShouldClose(window_)) {
- glfwPollEvents();
-
- renderer_->update();
- renderer_->render();
- }
- }
-
-private:
- static void onAdapterRequestEnded(WGPURequestAdapterStatus status, WGPUAdapter adapter,
- WGPUStringView message, void* userdata1, void* userdata2) {
- if (status == WGPURequestAdapterStatus_Success) {
- *static_cast<WGPUAdapter*>(userdata1) = adapter;
- } else {
- std::cerr << "Failed to get adapter: " << std::string(message.data, message.length) << std::endl;
- }
- }
-
- static void onDeviceRequestEnded(WGPURequestDeviceStatus status, WGPUDevice device,
- WGPUStringView message, void* userdata1, void* userdata2) {
- if (status == WGPURequestDeviceStatus_Success) {
- *static_cast<WGPUDevice*>(userdata1) = device;
- } else {
- std::cerr << "Failed to get device: " << std::string(message.data, message.length) << std::endl;
- }
- }
-
- bool initWebGPU() {
- // Create instance
- WGPUInstanceDescriptor instanceDesc = {};
- instanceDesc.nextInChain = nullptr;
-
- instance_ = wgpuCreateInstance(&instanceDesc);
- if (!instance_) {
- std::cerr << "Failed to create WebGPU instance" << std::endl;
- return false;
- }
-
- // Create surface from GLFW window
- surface_ = glfwCreateWindowWGPUSurface(instance_, window_);
- if (!surface_) {
- std::cerr << "Failed to create surface" << std::endl;
- return false;
- }
-
- // Request adapter with callback
- WGPURequestAdapterOptions adapterOpts = {};
- adapterOpts.nextInChain = nullptr;
- adapterOpts.compatibleSurface = surface_;
- adapterOpts.powerPreference = WGPUPowerPreference_HighPerformance;
-
- WGPURequestAdapterCallbackInfo adapterCallbackInfo = {};
- adapterCallbackInfo.mode = WGPUCallbackMode_AllowSpontaneous;
- adapterCallbackInfo.callback = onAdapterRequestEnded;
- adapterCallbackInfo.userdata1 = &adapter_;
- adapterCallbackInfo.userdata2 = nullptr;
-
- wgpuInstanceRequestAdapter(instance_, &adapterOpts, adapterCallbackInfo);
-
- // Process events until adapter is ready
- while (!adapter_) {
- wgpuInstanceProcessEvents(instance_);
- }
-
- // Request device with callback
- WGPUDeviceDescriptor deviceDesc = {};
- deviceDesc.nextInChain = nullptr;
- deviceDesc.label = {nullptr, WGPU_STRLEN};
- deviceDesc.requiredFeatureCount = 0;
- deviceDesc.requiredLimits = nullptr;
- deviceDesc.defaultQueue.nextInChain = nullptr;
- deviceDesc.defaultQueue.label = {nullptr, WGPU_STRLEN};
- deviceDesc.deviceLostCallbackInfo.nextInChain = nullptr;
- deviceDesc.deviceLostCallbackInfo.mode = WGPUCallbackMode_AllowSpontaneous;
- deviceDesc.deviceLostCallbackInfo.callback = nullptr;
- deviceDesc.uncapturedErrorCallbackInfo.nextInChain = nullptr;
- deviceDesc.uncapturedErrorCallbackInfo.callback = nullptr;
-
- WGPURequestDeviceCallbackInfo deviceCallbackInfo = {};
- deviceCallbackInfo.mode = WGPUCallbackMode_AllowSpontaneous;
- deviceCallbackInfo.callback = onDeviceRequestEnded;
- deviceCallbackInfo.userdata1 = &device_;
- deviceCallbackInfo.userdata2 = nullptr;
-
- wgpuAdapterRequestDevice(adapter_, &deviceDesc, deviceCallbackInfo);
-
- // Process events until device is ready
- while (!device_) {
- wgpuInstanceProcessEvents(instance_);
- }
-
- return true;
- }
-
- void cleanup() {
- renderer_.reset();
-
- if (device_) {
- wgpuDeviceRelease(device_);
- device_ = nullptr;
- }
- if (adapter_) {
- wgpuAdapterRelease(adapter_);
- adapter_ = nullptr;
- }
- if (surface_) {
- wgpuSurfaceRelease(surface_);
- surface_ = nullptr;
- }
- if (instance_) {
- wgpuInstanceRelease(instance_);
- instance_ = nullptr;
- }
-
- if (window_) {
- glfwDestroyWindow(window_);
- window_ = nullptr;
- }
- glfwTerminate();
- }
-
- static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
- auto* app = static_cast<Application*>(glfwGetWindowUserPointer(window));
- if (action == GLFW_PRESS) {
- if (key == GLFW_KEY_ESCAPE) {
- glfwSetWindowShouldClose(window, GLFW_TRUE);
- } else if (key == GLFW_KEY_G) {
- app->renderer_->toggleGrid();
- }
- }
- }
-
- static void resizeCallback(GLFWwindow* window, int width, int height) {
- auto* app = static_cast<Application*>(glfwGetWindowUserPointer(window));
- app->renderer_->resize(width, height);
- }
-
- GLFWwindow* window_;
- WGPUInstance instance_;
- WGPUAdapter adapter_;
- WGPUDevice device_;
- WGPUSurface surface_;
- std::unique_ptr<Renderer> renderer_;
-};
-
-int main() {
- Application app;
-
- if (!app.initialize()) {
- return EXIT_FAILURE;
- }
-
- app.run();
- return EXIT_SUCCESS;
-}
diff --git a/cpp-timeplot/src/renderer.cpp b/cpp-timeplot/src/renderer.cpp
deleted file mode 100644
index b65ed46..0000000
--- a/cpp-timeplot/src/renderer.cpp
+++ /dev/null
@@ -1,249 +0,0 @@
-#include "renderer.h"
-#include "waterfall.h"
-#include <fstream>
-#include <sstream>
-#include <iostream>
-
-Renderer::Renderer(WGPUDevice device, WGPUSurface surface, int width, int height)
- : device_(device), surface_(surface), width_(width), height_(height), time_(0.0f),
- surfaceFormat_(WGPUTextureFormat_BGRA8Unorm), linePipeline_(nullptr), lineListPipeline_(nullptr) {}
-
-Renderer::~Renderer() {
- if (linePipeline_) wgpuRenderPipelineRelease(linePipeline_);
- if (lineListPipeline_) wgpuRenderPipelineRelease(lineListPipeline_);
-}
-
-bool Renderer::initialize() {
- configureSurface();
- createPipelines();
-
- // Create two waterfall views side-by-side
- waterfalls_.push_back(std::make_unique<Waterfall>(
- device_, 0.0f, 0.1f, 0.5f, 0.9f, "Frequency vs Time"));
- waterfalls_.push_back(std::make_unique<Waterfall>(
- device_, 0.5f, 0.1f, 0.5f, 0.9f, "Position vs Time"));
-
- for (auto& waterfall : waterfalls_) {
- if (!waterfall->initialize()) {
- return false;
- }
- }
-
- return true;
-}
-
-void Renderer::configureSurface() {
- WGPUSurfaceConfiguration config = {};
- config.nextInChain = nullptr;
- config.device = device_;
- config.format = surfaceFormat_;
- config.usage = WGPUTextureUsage_RenderAttachment;
- config.width = width_;
- config.height = height_;
- config.presentMode = WGPUPresentMode_Fifo;
- config.alphaMode = WGPUCompositeAlphaMode_Auto;
- config.viewFormatCount = 0;
- config.viewFormats = nullptr;
-
- wgpuSurfaceConfigure(surface_, &config);
-}
-
-void Renderer::createPipelines() {
- // Load shader
- std::ifstream shaderFile("shaders/waterfall.wgsl");
- std::stringstream buffer;
- buffer << shaderFile.rdbuf();
- std::string shaderCode = buffer.str();
-
- WGPUShaderSourceWGSL wgslSource = {};
- wgslSource.chain.sType = WGPUSType_ShaderSourceWGSL;
- wgslSource.chain.next = nullptr;
- wgslSource.code = {shaderCode.c_str(), shaderCode.length()};
-
- WGPUShaderModuleDescriptor shaderDesc = {};
- shaderDesc.nextInChain = &wgslSource.chain;
- shaderDesc.label = {nullptr, WGPU_STRLEN};
-
- WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device_, &shaderDesc);
-
- // Vertex buffer layout
- WGPUVertexAttribute attributes[2] = {};
- attributes[0].format = WGPUVertexFormat_Float32x2;
- attributes[0].offset = 0;
- attributes[0].shaderLocation = 0;
-
- attributes[1].format = WGPUVertexFormat_Float32x3;
- attributes[1].offset = 2 * sizeof(float);
- attributes[1].shaderLocation = 1;
-
- WGPUVertexBufferLayout vertexBufferLayout = {};
- vertexBufferLayout.arrayStride = 5 * sizeof(float);
- vertexBufferLayout.stepMode = WGPUVertexStepMode_Vertex;
- vertexBufferLayout.attributeCount = 2;
- vertexBufferLayout.attributes = attributes;
-
- // Pipeline layout
- WGPUPipelineLayoutDescriptor layoutDesc = {};
- layoutDesc.nextInChain = nullptr;
- layoutDesc.label = {nullptr, WGPU_STRLEN};
- layoutDesc.bindGroupLayoutCount = 0;
- layoutDesc.bindGroupLayouts = nullptr;
-
- WGPUPipelineLayout pipelineLayout = wgpuDeviceCreatePipelineLayout(device_, &layoutDesc);
-
- // Color target
- WGPUBlendState blend = {};
- blend.color.operation = WGPUBlendOperation_Add;
- blend.color.srcFactor = WGPUBlendFactor_One;
- blend.color.dstFactor = WGPUBlendFactor_Zero;
- blend.alpha.operation = WGPUBlendOperation_Add;
- blend.alpha.srcFactor = WGPUBlendFactor_One;
- blend.alpha.dstFactor = WGPUBlendFactor_Zero;
-
- WGPUColorTargetState colorTarget = {};
- colorTarget.nextInChain = nullptr;
- colorTarget.format = surfaceFormat_;
- colorTarget.blend = &blend;
- colorTarget.writeMask = WGPUColorWriteMask_All;
-
- WGPUFragmentState fragmentState = {};
- fragmentState.nextInChain = nullptr;
- fragmentState.module = shader;
- fragmentState.entryPoint = {"fs_main", 7};
- fragmentState.constantCount = 0;
- fragmentState.constants = nullptr;
- fragmentState.targetCount = 1;
- fragmentState.targets = &colorTarget;
-
- // Line strip pipeline
- WGPURenderPipelineDescriptor pipelineDesc = {};
- pipelineDesc.nextInChain = nullptr;
- pipelineDesc.label = {nullptr, WGPU_STRLEN};
- pipelineDesc.layout = pipelineLayout;
-
- pipelineDesc.vertex.nextInChain = nullptr;
- pipelineDesc.vertex.module = shader;
- pipelineDesc.vertex.entryPoint = {"vs_main", 7};
- pipelineDesc.vertex.constantCount = 0;
- pipelineDesc.vertex.constants = nullptr;
- pipelineDesc.vertex.bufferCount = 1;
- pipelineDesc.vertex.buffers = &vertexBufferLayout;
-
- pipelineDesc.primitive.nextInChain = nullptr;
- pipelineDesc.primitive.topology = WGPUPrimitiveTopology_LineStrip;
- pipelineDesc.primitive.stripIndexFormat = WGPUIndexFormat_Undefined;
- pipelineDesc.primitive.frontFace = WGPUFrontFace_CCW;
- pipelineDesc.primitive.cullMode = WGPUCullMode_None;
-
- pipelineDesc.depthStencil = nullptr;
- pipelineDesc.multisample.nextInChain = nullptr;
- pipelineDesc.multisample.count = 1;
- pipelineDesc.multisample.mask = ~0u;
- pipelineDesc.multisample.alphaToCoverageEnabled = false;
-
- pipelineDesc.fragment = &fragmentState;
-
- linePipeline_ = wgpuDeviceCreateRenderPipeline(device_, &pipelineDesc);
-
- // Line list pipeline for grid
- pipelineDesc.primitive.topology = WGPUPrimitiveTopology_LineList;
- lineListPipeline_ = wgpuDeviceCreateRenderPipeline(device_, &pipelineDesc);
-
- // Cleanup
- wgpuPipelineLayoutRelease(pipelineLayout);
- wgpuShaderModuleRelease(shader);
-}
-
-void Renderer::update() {
- time_ += 0.016f; // ~60fps
-
- for (auto& waterfall : waterfalls_) {
- waterfall->update(time_);
- }
-}
-
-void Renderer::render() {
- WGPUSurfaceTexture surfaceTexture;
- wgpuSurfaceGetCurrentTexture(surface_, &surfaceTexture);
-
- if (surfaceTexture.status != WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal &&
- surfaceTexture.status != WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal) {
- std::cerr << "Failed to get surface texture" << std::endl;
- return;
- }
-
- WGPUTextureViewDescriptor viewDesc = {};
- viewDesc.nextInChain = nullptr;
- viewDesc.label = {nullptr, WGPU_STRLEN};
- viewDesc.format = surfaceFormat_;
- viewDesc.dimension = WGPUTextureViewDimension_2D;
- viewDesc.baseMipLevel = 0;
- viewDesc.mipLevelCount = 1;
- viewDesc.baseArrayLayer = 0;
- viewDesc.arrayLayerCount = 1;
- viewDesc.aspect = WGPUTextureAspect_All;
-
- WGPUTextureView textureView = wgpuTextureCreateView(surfaceTexture.texture, &viewDesc);
-
- WGPUCommandEncoderDescriptor encoderDesc = {};
- encoderDesc.nextInChain = nullptr;
- encoderDesc.label = {nullptr, WGPU_STRLEN};
-
- WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device_, &encoderDesc);
-
- WGPURenderPassColorAttachment colorAttachment = {};
- colorAttachment.nextInChain = nullptr;
- colorAttachment.view = textureView;
- colorAttachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
- colorAttachment.resolveTarget = nullptr;
- colorAttachment.loadOp = WGPULoadOp_Clear;
- colorAttachment.storeOp = WGPUStoreOp_Store;
- colorAttachment.clearValue = {0.1, 0.1, 0.15, 1.0};
-
- WGPURenderPassDescriptor renderPassDesc = {};
- renderPassDesc.nextInChain = nullptr;
- renderPassDesc.label = {nullptr, WGPU_STRLEN};
- renderPassDesc.colorAttachmentCount = 1;
- renderPassDesc.colorAttachments = &colorAttachment;
- renderPassDesc.depthStencilAttachment = nullptr;
- renderPassDesc.occlusionQuerySet = nullptr;
- renderPassDesc.timestampWrites = nullptr;
-
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &renderPassDesc);
-
- for (auto& waterfall : waterfalls_) {
- waterfall->render(pass, linePipeline_, lineListPipeline_, width_, height_);
- }
-
- wgpuRenderPassEncoderEnd(pass);
-
- WGPUCommandBufferDescriptor cmdBufferDesc = {};
- cmdBufferDesc.nextInChain = nullptr;
- cmdBufferDesc.label = {nullptr, WGPU_STRLEN};
-
- WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, &cmdBufferDesc);
-
- WGPUQueue queue = wgpuDeviceGetQueue(device_);
- wgpuQueueSubmit(queue, 1, &commands);
- wgpuSurfacePresent(surface_);
-
- // Cleanup
- wgpuCommandBufferRelease(commands);
- wgpuCommandEncoderRelease(encoder);
- wgpuRenderPassEncoderRelease(pass);
- wgpuTextureViewRelease(textureView);
-}
-
-void Renderer::resize(int width, int height) {
- if (width > 0 && height > 0) {
- width_ = width;
- height_ = height;
- configureSurface();
- }
-}
-
-void Renderer::toggleGrid() {
- for (auto& waterfall : waterfalls_) {
- waterfall->toggleGrid();
- }
-}
diff --git a/cpp-timeplot/src/renderer.h b/cpp-timeplot/src/renderer.h
deleted file mode 100644
index 0656cdc..0000000
--- a/cpp-timeplot/src/renderer.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#pragma once
-
-#include <webgpu/webgpu.h>
-#include <vector>
-#include <memory>
-
-class Waterfall;
-
-class Renderer {
-public:
- Renderer(WGPUDevice device, WGPUSurface surface, int width, int height);
- ~Renderer();
-
- bool initialize();
- void update();
- void render();
- void resize(int width, int height);
- void toggleGrid();
-
-private:
- void configureSurface();
- void createPipelines();
-
- WGPUDevice device_;
- WGPUSurface surface_;
- WGPUTextureFormat surfaceFormat_;
- WGPURenderPipeline linePipeline_;
- WGPURenderPipeline lineListPipeline_;
-
- int width_;
- int height_;
- float time_;
-
- std::vector<std::unique_ptr<Waterfall>> waterfalls_;
-};
diff --git a/cpp-timeplot/src/waterfall.cpp b/cpp-timeplot/src/waterfall.cpp
deleted file mode 100644
index 7fa0bee..0000000
--- a/cpp-timeplot/src/waterfall.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-#include "waterfall.h"
-#include <cmath>
-#include <algorithm>
-
-Waterfall::Waterfall(WGPUDevice device, float x, float y, float width, float height, const std::string& title)
- : device_(device), vertexBuffer_(nullptr), x_(x), y_(y), width_(width), height_(height),
- title_(title), showGrid_(true) {}
-
-Waterfall::~Waterfall() {
- if (vertexBuffer_) wgpuBufferRelease(vertexBuffer_);
-}
-
-bool Waterfall::initialize() {
- // Create vertex buffer (large enough for grid, border, and waterfall lines)
- WGPUBufferDescriptor bufferDesc = {};
- bufferDesc.nextInChain = nullptr;
- bufferDesc.label = {nullptr, WGPU_STRLEN};
- bufferDesc.size = sizeof(Vertex) * POINTS_PER_LINE * 100;
- bufferDesc.usage = WGPUBufferUsage_Vertex | WGPUBufferUsage_CopyDst;
- bufferDesc.mappedAtCreation = false;
-
- vertexBuffer_ = wgpuDeviceCreateBuffer(device_, &bufferDesc);
- return vertexBuffer_ != nullptr;
-}
-
-void Waterfall::update(float time) {
- // Add new line every 10 frames
- if (static_cast<int>(time * 60.0f) % 10 == 0 && lines_.size() < MAX_LINES) {
- std::vector<Vertex> line;
- float phase = time;
- float freq = 2.0f + std::sin(time * 0.5f) * 1.0f;
-
- for (int i = 0; i < POINTS_PER_LINE; ++i) {
- float x = (static_cast<float>(i) / POINTS_PER_LINE) * 2.0f - 1.0f;
- float y = std::sin(static_cast<float>(i) * 0.1f * freq + phase) * 0.3f;
-
- float hue = std::fmod(time * 0.1f, 1.0f);
- Vertex v{
- {x, y},
- {
- std::abs(std::sin(hue * 6.0f)),
- std::abs(std::sin((hue + 0.33f) * 6.0f)),
- std::abs(std::sin((hue + 0.66f) * 6.0f))
- }
- };
- line.push_back(v);
- }
- lines_.push_back(line);
- }
-
- // Scroll lines down
- for (auto& line : lines_) {
- for (auto& vertex : line) {
- vertex.position[1] -= 0.01f;
- }
- }
-
- // Remove lines that scrolled off screen
- lines_.erase(
- std::remove_if(lines_.begin(), lines_.end(),
- [](const std::vector<Vertex>& line) {
- return !line.empty() && line[0].position[1] < -1.1f;
- }),
- lines_.end()
- );
-}
-
-void Waterfall::render(WGPURenderPassEncoder pass,
- WGPURenderPipeline linePipeline,
- WGPURenderPipeline lineListPipeline,
- int windowWidth, int windowHeight) {
- // Set viewport
- wgpuRenderPassEncoderSetViewport(pass,
- x_ * windowWidth,
- y_ * windowHeight,
- width_ * windowWidth,
- height_ * windowHeight,
- 0.0f, 1.0f
- );
-
- // Collect all vertices
- std::vector<Vertex> allVertices;
-
- // Border
- auto borderVertices = generateBorder();
- size_t borderOffset = allVertices.size();
- allVertices.insert(allVertices.end(), borderVertices.begin(), borderVertices.end());
-
- // Grid
- size_t gridOffset = allVertices.size();
- size_t gridCount = 0;
- if (showGrid_) {
- auto gridVertices = generateGridLines();
- gridCount = gridVertices.size();
- allVertices.insert(allVertices.end(), gridVertices.begin(), gridVertices.end());
- }
-
- // Waterfall lines
- size_t linesOffset = allVertices.size();
- for (const auto& line : lines_) {
- allVertices.insert(allVertices.end(), line.begin(), line.end());
- }
-
- // Upload vertices
- if (!allVertices.empty()) {
- WGPUQueue queue = wgpuDeviceGetQueue(device_);
- wgpuQueueWriteBuffer(queue, vertexBuffer_, 0, allVertices.data(),
- allVertices.size() * sizeof(Vertex));
- }
-
- // Draw border
- wgpuRenderPassEncoderSetPipeline(pass, lineListPipeline);
- wgpuRenderPassEncoderSetVertexBuffer(pass, 0, vertexBuffer_, 0, allVertices.size() * sizeof(Vertex));
- wgpuRenderPassEncoderDraw(pass, borderVertices.size(), 1, borderOffset, 0);
-
- // Draw grid
- if (showGrid_ && gridCount > 0) {
- wgpuRenderPassEncoderSetPipeline(pass, lineListPipeline);
- wgpuRenderPassEncoderDraw(pass, gridCount, 1, gridOffset, 0);
- }
-
- // Draw waterfall lines
- if (!lines_.empty()) {
- wgpuRenderPassEncoderSetPipeline(pass, linePipeline);
- for (size_t i = 0; i < lines_.size(); ++i) {
- uint32_t start = linesOffset + i * POINTS_PER_LINE;
- wgpuRenderPassEncoderDraw(pass, POINTS_PER_LINE, 1, start, 0);
- }
- }
-}
-
-void Waterfall::toggleGrid() {
- showGrid_ = !showGrid_;
-}
-
-std::vector<Vertex> Waterfall::generateGridLines() {
- std::vector<Vertex> vertices;
- float gridColor[3] = {0.3f, 0.7f, 0.9f};
-
- // Vertical lines
- for (int i = 0; i <= 10; ++i) {
- float x = -1.0f + (static_cast<float>(i) / 10.0f) * 2.0f;
- vertices.push_back({{x, -1.0f}, {gridColor[0], gridColor[1], gridColor[2]}});
- vertices.push_back({{x, 1.0f}, {gridColor[0], gridColor[1], gridColor[2]}});
- }
-
- // Horizontal lines
- for (int i = 0; i <= 10; ++i) {
- float y = -1.0f + (static_cast<float>(i) / 10.0f) * 2.0f;
- vertices.push_back({{-1.0f, y}, {gridColor[0], gridColor[1], gridColor[2]}});
- vertices.push_back({{1.0f, y}, {gridColor[0], gridColor[1], gridColor[2]}});
- }
-
- return vertices;
-}
-
-std::vector<Vertex> Waterfall::generateBorder() {
- float borderColor[3] = {0.6f, 0.7f, 0.7f};
-
- return {
- {{-1.0f, 1.0f}, {borderColor[0], borderColor[1], borderColor[2]}},
- {{1.0f, 1.0f}, {borderColor[0], borderColor[1], borderColor[2]}},
- {{1.0f, 1.0f}, {borderColor[0], borderColor[1], borderColor[2]}},
- {{1.0f, -1.0f}, {borderColor[0], borderColor[1], borderColor[2]}},
- {{1.0f, -1.0f}, {borderColor[0], borderColor[1], borderColor[2]}},
- {{-1.0f, -1.0f}, {borderColor[0], borderColor[1], borderColor[2]}},
- {{-1.0f, -1.0f}, {borderColor[0], borderColor[1], borderColor[2]}},
- {{-1.0f, 1.0f}, {borderColor[0], borderColor[1], borderColor[2]}}
- };
-}
diff --git a/cpp-timeplot/src/waterfall.h b/cpp-timeplot/src/waterfall.h
deleted file mode 100644
index 454caf8..0000000
--- a/cpp-timeplot/src/waterfall.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include <webgpu/webgpu.h>
-#include <vector>
-#include <string>
-
-struct Vertex {
- float position[2];
- float color[3];
-};
-
-class Waterfall {
-public:
- Waterfall(WGPUDevice device, float x, float y, float width, float height, const std::string& title);
- ~Waterfall();
-
- bool initialize();
- void update(float time);
- void render(WGPURenderPassEncoder pass,
- WGPURenderPipeline linePipeline,
- WGPURenderPipeline lineListPipeline,
- int windowWidth, int windowHeight);
- void toggleGrid();
-
-private:
- std::vector<Vertex> generateGridLines();
- std::vector<Vertex> generateBorder();
-
- WGPUDevice device_;
- WGPUBuffer vertexBuffer_;
-
- float x_, y_, width_, height_;
- std::string title_;
- bool showGrid_;
-
- std::vector<std::vector<Vertex>> lines_;
- static constexpr int MAX_LINES = 50;
- static constexpr int POINTS_PER_LINE = 100;
-};
diff --git a/cpp-timeplot/src/webgpu_impl.cpp b/cpp-timeplot/src/webgpu_impl.cpp
deleted file mode 100644
index e0f099b..0000000
--- a/cpp-timeplot/src/webgpu_impl.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-#define WGPU_CPP_IMPLEMENTATION
-#include <webgpu/webgpu.hpp>