mirror of
https://github.com/gwm17/implot.git
synced 2025-01-30 19:08:51 -05:00
Add BustPlotCache() and other small changes
This commit is contained in:
parent
ead05a20a7
commit
7b840d1a44
|
@ -54,6 +54,7 @@ struct OpenGLContextData
|
|||
GLuint g_AttribLocationImGuiProjection = 0; ///< Attribute location for the projection matrix uniform (ImGui default shader)
|
||||
|
||||
ImVector<HeatmapData> HeatmapDataList; ///< Array of heatmap data
|
||||
ImVector<GLuint> ColormapIDs; ///< Texture IDs of the colormap textures
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
glGenTextures(1, colormapID);
|
||||
glBindTexture(GL_TEXTURE_1D, *colormapID);
|
||||
GLuint texID;
|
||||
glGenTextures(1, &texID);
|
||||
glBindTexture(GL_TEXTURE_1D, texID);
|
||||
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_T, GL_CLAMP_TO_EDGE);
|
||||
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);
|
||||
glBindTexture(GL_TEXTURE_1D, 0);
|
||||
|
||||
Context.ColormapIDs.push_back(texID);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ImPlotContext& gp = *GImPlot;
|
||||
int idx = Context.PlotIDs.GetInt(plotID, -1);
|
||||
|
||||
if(idx < 0)
|
||||
|
@ -257,7 +259,7 @@ void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bound
|
|||
// New entry
|
||||
HeatmapData data;
|
||||
data.HeatmapTexID = CreateHeatmapTexture();
|
||||
data.ColormapTexID = gp.ColormapData.TextureIDs[colormap];
|
||||
data.ColormapTexID = Context.ColormapIDs[colormap];
|
||||
data.MinValue = scale_min;
|
||||
data.MaxValue = scale_max;
|
||||
|
||||
|
@ -267,7 +269,7 @@ void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bound
|
|||
else
|
||||
{
|
||||
HeatmapData& data = Context.HeatmapDataList[idx];
|
||||
data.ColormapTexID = gp.ColormapData.TextureIDs[colormap];
|
||||
data.ColormapTexID = Context.ColormapIDs[colormap];
|
||||
data.MinValue = scale_min;
|
||||
data.MaxValue = scale_max;
|
||||
}
|
||||
|
@ -284,6 +286,9 @@ void OpenGL3_RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bound
|
|||
|
||||
void OpenGL3_BustPlotCache()
|
||||
{
|
||||
for(const HeatmapData& data : Context.HeatmapDataList)
|
||||
glDeleteTextures(1, &data.HeatmapTexID);
|
||||
|
||||
Context.HeatmapDataList.clear();
|
||||
Context.PlotIDs.Clear();
|
||||
}
|
||||
|
|
14
implot.cpp
14
implot.cpp
|
@ -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.
|
||||
#endif
|
||||
|
||||
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
|
||||
namespace ImPlot {
|
||||
namespace Backends {
|
||||
|
||||
void OpenGL3_BustPlotCache();
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Global plot context
|
||||
ImPlotContext* GImPlot = NULL;
|
||||
|
||||
|
@ -435,7 +445,6 @@ void Initialize(ImPlotContext* ctx) {
|
|||
IMPLOT_APPEND_CMAP(PiYG, false);
|
||||
IMPLOT_APPEND_CMAP(Spectral, false);
|
||||
IMPLOT_APPEND_CMAP(Greys, false);
|
||||
|
||||
}
|
||||
|
||||
void Reset(ImPlotContext* ctx) {
|
||||
|
@ -489,6 +498,9 @@ ImPlotPlot* GetCurrentPlot() {
|
|||
|
||||
void BustPlotCache() {
|
||||
GImPlot->Plots.Clear();
|
||||
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
|
||||
Backends::OpenGL3_BustPlotCache();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PushLinkedAxis(ImPlotAxis& axis) {
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
namespace ImPlot {
|
||||
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;
|
||||
ImGuiStorage Map;
|
||||
int Count;
|
||||
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
|
||||
ImVector<int> TextureIDs;
|
||||
#endif
|
||||
|
||||
ImPlotColormapData() { Count = 0; }
|
||||
|
||||
|
@ -390,8 +387,7 @@ struct ImPlotColormapData {
|
|||
Map.SetInt(id,idx);
|
||||
_AppendTable(idx);
|
||||
#ifdef IMPLOT_ENABLE_OPENGL3_ACCELERATION
|
||||
TextureIDs.push_back(0);
|
||||
ImPlot::Backends::OpenGL3_AddColormap(&TextureIDs[idx], keys, count, qual);
|
||||
ImPlot::Backends::OpenGL3_AddColormap(keys, count, qual);
|
||||
#endif
|
||||
return idx;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user