summaryrefslogtreecommitdiff
path: root/cpp-timeplot/src/waterfall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp-timeplot/src/waterfall.cpp')
-rw-r--r--cpp-timeplot/src/waterfall.cpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/cpp-timeplot/src/waterfall.cpp b/cpp-timeplot/src/waterfall.cpp
index 9baeba6..7fa0bee 100644
--- a/cpp-timeplot/src/waterfall.cpp
+++ b/cpp-timeplot/src/waterfall.cpp
@@ -2,19 +2,24 @@
#include <cmath>
#include <algorithm>
-Waterfall::Waterfall(wgpu::Device device, float x, float y, float width, float height, const std::string& title)
- : device_(device), x_(x), y_(y), width_(width), height_(height), title_(title), showGrid_(true) {}
+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() = default;
+Waterfall::~Waterfall() {
+ if (vertexBuffer_) wgpuBufferRelease(vertexBuffer_);
+}
bool Waterfall::initialize() {
// Create vertex buffer (large enough for grid, border, and waterfall lines)
- wgpu::BufferDescriptor bufferDesc{};
+ WGPUBufferDescriptor bufferDesc = {};
+ bufferDesc.nextInChain = nullptr;
+ bufferDesc.label = {nullptr, WGPU_STRLEN};
bufferDesc.size = sizeof(Vertex) * POINTS_PER_LINE * 100;
- bufferDesc.usage = wgpu::BufferUsage::Vertex | wgpu::BufferUsage::CopyDst;
+ bufferDesc.usage = WGPUBufferUsage_Vertex | WGPUBufferUsage_CopyDst;
bufferDesc.mappedAtCreation = false;
- vertexBuffer_ = device_.createBuffer(bufferDesc);
+ vertexBuffer_ = wgpuDeviceCreateBuffer(device_, &bufferDesc);
return vertexBuffer_ != nullptr;
}
@@ -60,12 +65,12 @@ void Waterfall::update(float time) {
);
}
-void Waterfall::render(wgpu::RenderPassEncoder& pass,
- wgpu::RenderPipeline linePipeline,
- wgpu::RenderPipeline lineListPipeline,
+void Waterfall::render(WGPURenderPassEncoder pass,
+ WGPURenderPipeline linePipeline,
+ WGPURenderPipeline lineListPipeline,
int windowWidth, int windowHeight) {
// Set viewport
- pass.setViewport(
+ wgpuRenderPassEncoderSetViewport(pass,
x_ * windowWidth,
y_ * windowHeight,
width_ * windowWidth,
@@ -98,27 +103,28 @@ void Waterfall::render(wgpu::RenderPassEncoder& pass,
// Upload vertices
if (!allVertices.empty()) {
- device_.getQueue().writeBuffer(vertexBuffer_, 0, allVertices.data(),
- allVertices.size() * sizeof(Vertex));
+ WGPUQueue queue = wgpuDeviceGetQueue(device_);
+ wgpuQueueWriteBuffer(queue, vertexBuffer_, 0, allVertices.data(),
+ allVertices.size() * sizeof(Vertex));
}
// Draw border
- pass.setPipeline(lineListPipeline);
- pass.setVertexBuffer(0, vertexBuffer_, 0, allVertices.size() * sizeof(Vertex));
- pass.draw(borderVertices.size(), 1, borderOffset, 0);
+ 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) {
- pass.setPipeline(lineListPipeline);
- pass.draw(gridCount, 1, gridOffset, 0);
+ wgpuRenderPassEncoderSetPipeline(pass, lineListPipeline);
+ wgpuRenderPassEncoderDraw(pass, gridCount, 1, gridOffset, 0);
}
// Draw waterfall lines
if (!lines_.empty()) {
- pass.setPipeline(linePipeline);
+ wgpuRenderPassEncoderSetPipeline(pass, linePipeline);
for (size_t i = 0; i < lines_.size(); ++i) {
uint32_t start = linesOffset + i * POINTS_PER_LINE;
- pass.draw(POINTS_PER_LINE, 1, start, 0);
+ wgpuRenderPassEncoderDraw(pass, POINTS_PER_LINE, 1, start, 0);
}
}
}