From 68e6ebe24cb476997b2ddfc21a5b13fb6f332fa7 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Fri, 16 Jul 2021 21:00:28 +0300 Subject: Render texture onto window on each iteration. Keep colormap in renderer so we don't pass the colormapped windows like animals. Pre-render empty window. Fixes #15. --- src/renderer.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index 05fea43..e482bb0 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -38,8 +38,11 @@ ValueToShortString(double value, int prec, const std::string& unit) } Renderer::Renderer(const Configuration& conf, const ColorMap& cmap, const ValueMap& vmap, std::size_t fft_count) - : configuration_(conf), fft_count_(fft_count) + : configuration_(conf), fft_count_(fft_count), color_map_(cmap.Copy()) { + if (color_map_ == nullptr) { + throw std::runtime_error("failed to copy color map"); + } if (fft_count == 0) { throw std::runtime_error("positive number of FFT windows required by rendere"); } @@ -436,18 +439,18 @@ Renderer::RenderFFTArea(const std::list>& history) return this->RenderFFTArea(memory); } -void -Renderer::RenderLiveFFT(const RealWindow& window, const std::vector& colors) +std::vector +Renderer::RenderLiveFFT(const RealWindow& window) { if (window.size() != this->configuration_.GetWidth()) { throw std::runtime_error("incorrect window size to be rendered"); } - if (!this->configuration_.HasLiveWindow()) { - /* noop */ - return; + throw std::runtime_error("asked to render live window for non-live configuration"); } + std::vector colors = this->color_map_->Map(window); + /* FFT live box (so we overwrite old one */ sf::RectangleShape fft_live_box(sf::Vector2f(this->configuration_.GetWidth(), this->configuration_.GetLiveFFTHeight() + 1.0f)); @@ -488,6 +491,7 @@ Renderer::RenderLiveFFT(const RealWindow& window, const std::vector& co this->canvas_.draw(reinterpret_cast(vertices.data()), vertices.size(), sf::LineStrip, this->fft_live_transform_); + return colors; } sf::Texture -- cgit v1.2.3