1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2025-04-22 08:18:50 -04:00

Add BustPlotCache() and other small changes

This commit is contained in:
marcizhu 2021-06-20 21:19:48 +02:00
parent ead05a20a7
commit 7b840d1a44
No known key found for this signature in database
GPG Key ID: 2D8FA5B173E88095
3 changed files with 27 additions and 14 deletions

View File

@ -54,6 +54,7 @@ struct OpenGLContextData
GLuint g_AttribLocationImGuiProjection = 0; ///< Attribute location for the projection matrix uniform (ImGui default shader) GLuint g_AttribLocationImGuiProjection = 0; ///< Attribute location for the projection matrix uniform (ImGui default shader)
ImVector<HeatmapData> HeatmapDataList; ///< Array of heatmap data ImVector<HeatmapData> HeatmapDataList; ///< Array of heatmap data
ImVector<GLuint> ColormapIDs; ///< Texture IDs of the colormap textures
ImGuiStorage PlotIDs; ///< PlotID <-> Heatmap array index table ImGuiStorage PlotIDs; ///< PlotID <-> Heatmap array index table
}; };
@ -178,17 +179,19 @@ static void SetTextureData(int plotID, const void* data, GLsizei rows, GLsizei c
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cols, rows, 0, GL_RED, type, data); glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cols, rows, 0, GL_RED, type, data);
} }
void OpenGL3_AddColormap(int* texID, const ImU32* keys, int count, bool qual) void OpenGL3_AddColormap(const ImU32* keys, int count, bool qual)
{ {
GLuint* colormapID = (GLuint*)texID; GLuint texID;
glGenTextures(1, colormapID); glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_1D, *colormapID); glBindTexture(GL_TEXTURE_1D, texID);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, count, 0, GL_RGBA, GL_UNSIGNED_BYTE, keys); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, count, 0, GL_RGBA, GL_UNSIGNED_BYTE, keys);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, qual ? GL_NEAREST : GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, qual ? GL_NEAREST : GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, qual ? GL_NEAREST : GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, qual ? GL_NEAREST : GL_LINEAR);
glBindTexture(GL_TEXTURE_1D, 0); glBindTexture(GL_TEXTURE_1D, 0);
Context.ColormapIDs.push_back(texID);
} }
static GLuint CreateHeatmapTexture() static GLuint CreateHeatmapTexture()
@ -249,7 +252,6 @@ void OpenGL3_SetHeatmapData(int plotID, const ImU64* values, int rows, int cols)
void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max, float scale_min, float scale_max, ImPlotColormap colormap) void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max, float scale_min, float scale_max, ImPlotColormap colormap)
{ {
ImPlotContext& gp = *GImPlot;
int idx = Context.PlotIDs.GetInt(plotID, -1); int idx = Context.PlotIDs.GetInt(plotID, -1);
if(idx < 0) if(idx < 0)
@ -257,7 +259,7 @@ void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bound
// New entry // New entry
HeatmapData data; HeatmapData data;
data.HeatmapTexID = CreateHeatmapTexture(); data.HeatmapTexID = CreateHeatmapTexture();
data.ColormapTexID = gp.ColormapData.TextureIDs[colormap]; data.ColormapTexID = Context.ColormapIDs[colormap];
data.MinValue = scale_min; data.MinValue = scale_min;
data.MaxValue = scale_max; data.MaxValue = scale_max;
@ -267,7 +269,7 @@ void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bound
else else
{ {
HeatmapData& data = Context.HeatmapDataList[idx]; HeatmapData& data = Context.HeatmapDataList[idx];
data.ColormapTexID = gp.ColormapData.TextureIDs[colormap]; data.ColormapTexID = Context.ColormapIDs[colormap];
data.MinValue = scale_min; data.MinValue = scale_min;
data.MaxValue = scale_max; data.MaxValue = scale_max;
} }
@ -284,6 +286,9 @@ void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bound
void OpenGL3_BustPlotCache() void OpenGL3_BustPlotCache()
{ {
for(const HeatmapData& data : Context.HeatmapDataList)
glDeleteTextures(1, &data.HeatmapTexID);
Context.HeatmapDataList.clear(); Context.HeatmapDataList.clear();
Context.PlotIDs.Clear(); Context.PlotIDs.Clear();
} }

View File

@ -88,6 +88,16 @@ You can read releases logs https://github.com/epezent/implot/releases for more d
#define GetBufSize GetSize // A little bit ugly since 'GetBufSize' could technically be used elsewhere (but currently isn't). Could use a proxy define if needed. #define GetBufSize GetSize // A little bit ugly since 'GetBufSize' could technically be used elsewhere (but currently isn't). Could use a proxy define if needed.
#endif #endif
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
namespace ImPlot {
namespace Backends {
void OpenGL3_BustPlotCache();
}
}
#endif
// Global plot context // Global plot context
ImPlotContext* GImPlot = NULL; ImPlotContext* GImPlot = NULL;
@ -435,7 +445,6 @@ void Initialize(ImPlotContext* ctx) {
IMPLOT_APPEND_CMAP(PiYG, false); IMPLOT_APPEND_CMAP(PiYG, false);
IMPLOT_APPEND_CMAP(Spectral, false); IMPLOT_APPEND_CMAP(Spectral, false);
IMPLOT_APPEND_CMAP(Greys, false); IMPLOT_APPEND_CMAP(Greys, false);
} }
void Reset(ImPlotContext* ctx) { void Reset(ImPlotContext* ctx) {
@ -489,6 +498,9 @@ ImPlotPlot* GetCurrentPlot() {
void BustPlotCache() { void BustPlotCache() {
GImPlot->Plots.Clear(); GImPlot->Plots.Clear();
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
Backends::OpenGL3_BustPlotCache();
#endif
} }
void PushLinkedAxis(ImPlotAxis& axis) { void PushLinkedAxis(ImPlotAxis& axis) {

View File

@ -46,7 +46,7 @@
namespace ImPlot { namespace ImPlot {
namespace Backends { namespace Backends {
void OpenGL3_AddColormap(int* texID, const ImU32* keys, int count, bool qual); void OpenGL3_AddColormap(const ImU32* keys, int count, bool qual);
} }
} }
@ -368,9 +368,6 @@ struct ImPlotColormapData {
ImVector<bool> Quals; ImVector<bool> Quals;
ImGuiStorage Map; ImGuiStorage Map;
int Count; int Count;
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
ImVector<int> TextureIDs;
#endif
ImPlotColormapData() { Count = 0; } ImPlotColormapData() { Count = 0; }
@ -390,8 +387,7 @@ struct ImPlotColormapData {
Map.SetInt(id,idx); Map.SetInt(id,idx);
_AppendTable(idx); _AppendTable(idx);
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION #ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
TextureIDs.push_back(0); ImPlot::Backends::OpenGL3_AddColormap(keys, count, qual);
ImPlot::Backends::OpenGL3_AddColormap(&TextureIDs[idx], keys, count, qual);
#endif #endif
return idx; return idx;
} }