From 541521fe6984b0744eabcb56a7b15bd95f671a99 Mon Sep 17 00:00:00 2001 From: marcizhu Date: Wed, 23 Jun 2021 11:43:12 +0200 Subject: [PATCH] Misc changes - Rename implot_gpu.h -> implot_backend.h - Rename IMPLOT_ENABLE_OPENGL3_ACCELERATION -> IMPLOT_BACKEND_ENABLE_OPENGL3 - Use gp.CurrentItem->ID over gp.CurrentPlot->ID - Add flags for different features supported by backends --- backends/{implot_gpu.h => implot_backend.h} | 22 +++++++++++++++++---- backends/implot_opengl3.cpp | 4 ++-- implot_internal.h | 2 +- implot_items.cpp | 10 +++++----- 4 files changed, 26 insertions(+), 12 deletions(-) rename backends/{implot_gpu.h => implot_backend.h} (95%) diff --git a/backends/implot_gpu.h b/backends/implot_backend.h similarity index 95% rename from backends/implot_gpu.h rename to backends/implot_backend.h index e5d9477..952d317 100644 --- a/backends/implot_gpu.h +++ b/backends/implot_backend.h @@ -26,6 +26,12 @@ #include "../implot.h" +#ifdef IMPLOT_BACKEND_ENABLE_OPENGL3 + #define IMPLOT_BACKEND_ENABLED + #define IMPLOT_BACKEND_HAS_HEATMAP + #define IMPLOT_BACKEND_HAS_COLORMAP +#endif + namespace ImPlot { namespace Backend { @@ -136,19 +142,27 @@ IMPLOT_API void BustPlotCache(); /** @brief Bust item cache. Called from @ref ImPlot::BustItemCache() */ IMPLOT_API void BustItemCache(); +} +} -#if !defined(IMPLOT_ENABLE_OPENGL3_ACCELERATION) +namespace ImPlot { +namespace Backend { + +#ifndef IMPLOT_BACKEND_ENABLED -// Dummy implementation for backend functions inline void* CreateContext() { return nullptr; } inline void DestroyContext() {} -inline void AddColormap(const ImU32*, int, bool) {} - inline void BustPlotCache() {} inline void BustItemCache() {} #endif +#ifndef IMPLOT_BACKEND_HAS_COLORMAP + +inline void AddColormap(const ImU32*, int, bool) {} + +#endif + } } diff --git a/backends/implot_opengl3.cpp b/backends/implot_opengl3.cpp index e29ed65..0db06f7 100644 --- a/backends/implot_opengl3.cpp +++ b/backends/implot_opengl3.cpp @@ -1,8 +1,8 @@ -#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION +#ifdef IMPLOT_BACKEND_ENABLE_OPENGL3 #include "../implot.h" #include "../implot_internal.h" -#include "implot_gpu.h" +#include "implot_backend.h" #if defined(IMGUI_IMPL_OPENGL_ES2) #include diff --git a/implot_internal.h b/implot_internal.h index 866148f..9dea114 100644 --- a/implot_internal.h +++ b/implot_internal.h @@ -37,7 +37,7 @@ #include #include "imgui_internal.h" -#include "backends/implot_gpu.h" +#include "backends/implot_backend.h" #ifndef IMPLOT_VERSION #error Must include implot.h before implot_internal.h diff --git a/implot_items.cpp b/implot_items.cpp index 0cf8d28..1c18f9d 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -24,7 +24,7 @@ #include "implot.h" #include "implot_internal.h" -#include "backends/implot_gpu.h" +#include "backends/implot_backend.h" #ifdef _MSC_VER #define sprintf sprintf_s @@ -1892,13 +1892,13 @@ void RenderHeatmap(Transformer transformer, ImDrawList& DrawList, const T* value } const double yref = reverse_y ? bounds_max.y : bounds_min.y; const double ydir = reverse_y ? -1 : 1; -#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION - // NOTE: Order is important! +#ifdef IMPLOT_BACKEND_HAS_HEATMAP ImVec2 bmin = transformer(bounds_min); ImVec2 bmax = transformer(bounds_max); - Backend::RenderHeatmap(gp.CurrentPlot->ID, DrawList, bmin, bmax, scale_min, scale_max, gp.Style.Colormap); - Backend::SetHeatmapData(gp.CurrentPlot->ID, values, rows, cols); + // NOTE: Order is important! + Backend::RenderHeatmap(gp.CurrentItem->ID, DrawList, bmin, bmax, scale_min, scale_max, gp.Style.Colormap); + Backend::SetHeatmapData(gp.CurrentItem->ID, values, rows, cols); #else GetterHeatmap getter(values, rows, cols, scale_min, scale_max, (bounds_max.x - bounds_min.x) / cols, (bounds_max.y - bounds_min.y) / rows, bounds_min.x, yref, ydir); switch (GetCurrentScale()) {