mirror of
https://github.com/gwm17/implot.git
synced 2025-04-22 00:18:49 -04:00
Standandardize backends for future implementations
This commit is contained in:
parent
27769a846f
commit
449b30b389
|
@ -24,156 +24,25 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../implot.h"
|
#if defined(IMPLOT_BACKEND_ENABLE_OPENGL3)
|
||||||
|
#include "implot_impl_opengl3.h"
|
||||||
#ifdef IMPLOT_BACKEND_ENABLE_OPENGL3
|
#elif defined(IMPLOT_BACKEND_ENABLE_METAL)
|
||||||
#define IMPLOT_BACKEND_ENABLED
|
#include "implot_impl_metal.h"
|
||||||
#define IMPLOT_BACKEND_HAS_HEATMAP
|
|
||||||
#define IMPLOT_BACKEND_HAS_COLORMAP
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ImPlot {
|
namespace ImPlot {
|
||||||
namespace Backend {
|
namespace Backend {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// [SECTION] Misc backend functions
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Struct to hold backend-related context data
|
|
||||||
*
|
|
||||||
* A backend may store in this struct any data it needs, with no constraints. A
|
|
||||||
* pointer to this struct will be stored inside ImPlot's context and can be
|
|
||||||
* accessed at any time. This pointer will be set to the returned value of @ref
|
|
||||||
* CreateContext(). All resources held by this struct must be freed inside @ref
|
|
||||||
* DestroyContext().
|
|
||||||
*/
|
|
||||||
struct ContextData;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create backend context
|
|
||||||
*
|
|
||||||
* Creates and intializes the backend context. The returned pointer will be saved
|
|
||||||
* in ImPlot's context and can be accessed later.
|
|
||||||
*/
|
|
||||||
IMPLOT_API void* CreateContext();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Destroy backend context
|
|
||||||
*
|
|
||||||
* Destroys and frees any memory or resources needed by the backend. After this
|
|
||||||
* call returns, no more calls to any backend function will be performed.
|
|
||||||
*/
|
|
||||||
IMPLOT_API void DestroyContext();
|
|
||||||
|
|
||||||
/** @brief Bust plot cache. Called from @ref ImPlot::BustPlotCache() */
|
|
||||||
IMPLOT_API void BustPlotCache();
|
|
||||||
|
|
||||||
/** @brief Bust item cache. Called from @ref ImPlot::BustItemCache() */
|
|
||||||
IMPLOT_API void BustItemCache();
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// [SECTION] Colormap functions
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Add a colormap
|
|
||||||
*
|
|
||||||
* Adds a colormap to be handled by the backend.
|
|
||||||
*
|
|
||||||
* @param keys Colors for this colormap, in RGBA format
|
|
||||||
* @param count Number of colors in this colormap
|
|
||||||
* @param qual Qualitative: whether the colormap is continuous (`false`) or
|
|
||||||
* not (`true`)
|
|
||||||
*/
|
|
||||||
IMPLOT_API void AddColormap(const ImU32* keys, int count, bool qual);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// [SECTION] Heatmap functions
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set heatmap data
|
|
||||||
*
|
|
||||||
* Sets the data of the heatmap with the given plot ID.
|
|
||||||
*
|
|
||||||
* @param plotID ID of the heatmap to update. This ID is unique, but it is not
|
|
||||||
* continuous nor always positive.
|
|
||||||
* @param values Data of the heatmap to be set.`values[0]` corresponds with the
|
|
||||||
* top-left corner of the data.
|
|
||||||
* @param rows Number of rows of this heatmap
|
|
||||||
* @param cols Number of columns of this heatmap
|
|
||||||
*/
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImS8* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const ImU8*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImU8* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const ImS16*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImS16* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const ImU16*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImU16* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const ImS32*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImS32* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const ImU32*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImU32* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const float*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const float* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const double*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const double* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const ImS64*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImS64* values, int rows, int cols);
|
|
||||||
|
|
||||||
/** @copydoc SetHeatmapData(int,const ImU64*,int,int) */
|
|
||||||
IMPLOT_API void SetHeatmapData(int plotID, const ImU64* values, int rows, int cols);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Render heatmap
|
|
||||||
*
|
|
||||||
* Renders the heatmap by submitting the appropriate commands to the current
|
|
||||||
* draw list.
|
|
||||||
*
|
|
||||||
* @param plotID ID of the heatmap to be rendered
|
|
||||||
* @param DrawList Draw list where to submit the render commands
|
|
||||||
* @param bounds_min Minimum bounds of the heatmap (without clipping)
|
|
||||||
* @param bounds_max Maximum bounds of the heatmap (without clipping)
|
|
||||||
* @param scale_min Minimum value of the heatmap
|
|
||||||
* @param scale_max Maximum value of the heatmap
|
|
||||||
* @param colormap Colormap to be used when rendering this heatmap
|
|
||||||
*
|
|
||||||
* @note There might be values greater than `scale_max` or lower than `scale_min`.
|
|
||||||
* The shader used for rendering should clamp this values appropriately.
|
|
||||||
*/
|
|
||||||
IMPLOT_API void RenderHeatmap(
|
|
||||||
int plotID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max,
|
|
||||||
float scale_min, float scale_max, ImPlotColormap colormap);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ImPlot {
|
|
||||||
namespace Backend {
|
|
||||||
|
|
||||||
#ifndef IMPLOT_BACKEND_ENABLED
|
#ifndef IMPLOT_BACKEND_ENABLED
|
||||||
|
inline void* CreateContext() { return nullptr; }
|
||||||
|
inline void DestroyContext() {}
|
||||||
|
|
||||||
inline void* CreateContext() { return nullptr; }
|
inline void BustPlotCache() {}
|
||||||
inline void DestroyContext() {}
|
inline void BustItemCache() {}
|
||||||
|
|
||||||
inline void BustPlotCache() {}
|
|
||||||
inline void BustItemCache() {}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef IMPLOT_BACKEND_HAS_COLORMAP
|
#ifndef IMPLOT_BACKEND_HAS_COLORMAP
|
||||||
|
inline void AddColormap(const ImU32*, int, bool) {}
|
||||||
inline void AddColormap(const ImU32*, int, bool) {}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "../implot.h"
|
#include "../implot.h"
|
||||||
#include "../implot_internal.h"
|
#include "../implot_internal.h"
|
||||||
#include "implot_backend.h"
|
#include "implot_backend.h"
|
||||||
|
#include "implot_impl_opengl3.h"
|
||||||
|
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
|
@ -63,7 +64,7 @@ struct ContextData
|
||||||
|
|
||||||
ImVector<HeatmapData> HeatmapDataList; ///< Array of heatmap data
|
ImVector<HeatmapData> HeatmapDataList; ///< Array of heatmap data
|
||||||
ImVector<GLuint> ColormapIDs; ///< Texture IDs of the colormap textures
|
ImVector<GLuint> ColormapIDs; ///< Texture IDs of the colormap textures
|
||||||
ImGuiStorage PlotIDs; ///< PlotID <-> Heatmap array index table
|
ImGuiStorage ItemIDs; ///< PlotID <-> Heatmap array index table
|
||||||
|
|
||||||
ImVector<float> temp1; ///< Temporary data
|
ImVector<float> temp1; ///< Temporary data
|
||||||
ImVector<ImS32> temp2; ///< Temporary data
|
ImVector<ImS32> temp2; ///< Temporary data
|
||||||
|
@ -77,7 +78,7 @@ void* CreateContext()
|
||||||
|
|
||||||
void DestroyContext()
|
void DestroyContext()
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
for(const HeatmapData& data : Context.HeatmapDataList)
|
for(const HeatmapData& data : Context.HeatmapDataList)
|
||||||
glDeleteTextures(1, &data.HeatmapTexID);
|
glDeleteTextures(1, &data.HeatmapTexID);
|
||||||
|
@ -89,7 +90,7 @@ void DestroyContext()
|
||||||
glDeleteProgram(Context.ShaderFloat.ID);
|
glDeleteProgram(Context.ShaderFloat.ID);
|
||||||
|
|
||||||
Context.HeatmapDataList.clear();
|
Context.HeatmapDataList.clear();
|
||||||
Context.PlotIDs.Clear();
|
Context.ItemIDs.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HEATMAP_VERTEX_SHADER_CODE \
|
#define HEATMAP_VERTEX_SHADER_CODE \
|
||||||
|
@ -157,7 +158,7 @@ static void CompileShader(HeatmapShader& ShaderProgram, GLchar* VertexShaderCode
|
||||||
|
|
||||||
static void CreateHeatmapShader(const ImDrawList*, const ImDrawCmd*)
|
static void CreateHeatmapShader(const ImDrawList*, const ImDrawCmd*)
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&Context.ImGuiShader);
|
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&Context.ImGuiShader);
|
||||||
|
|
||||||
|
@ -185,10 +186,10 @@ static void CreateHeatmapShader(const ImDrawList*, const ImDrawCmd*)
|
||||||
|
|
||||||
static void RenderCallback(const ImDrawList*, const ImDrawCmd* cmd)
|
static void RenderCallback(const ImDrawList*, const ImDrawCmd* cmd)
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
int plotID = (int)(intptr_t)cmd->UserCallbackData;
|
int itemID = (int)(intptr_t)cmd->UserCallbackData;
|
||||||
int plotIdx = Context.PlotIDs.GetInt(plotID, -1);
|
int plotIdx = Context.ItemIDs.GetInt(itemID, -1);
|
||||||
HeatmapData& data = Context.HeatmapDataList[plotIdx];
|
HeatmapData& data = Context.HeatmapDataList[plotIdx];
|
||||||
|
|
||||||
// Get projection matrix of current shader
|
// Get projection matrix of current shader
|
||||||
|
@ -211,15 +212,15 @@ static void ResetState(const ImDrawList*, const ImDrawCmd*)
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
glUseProgram(Context.ImGuiShader);
|
glUseProgram(Context.ImGuiShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetTextureData(int plotID, const void* data, GLsizei rows, GLsizei cols, GLint internalFormat, GLenum format, GLenum type)
|
static void SetTextureData(int itemID, const void* data, GLsizei rows, GLsizei cols, GLint internalFormat, GLenum format, GLenum type)
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
int idx = Context.PlotIDs.GetInt(plotID, -1);
|
int idx = Context.ItemIDs.GetInt(itemID, -1);
|
||||||
GLuint texID = Context.HeatmapDataList[idx].HeatmapTexID;
|
GLuint texID = Context.HeatmapDataList[idx].HeatmapTexID;
|
||||||
Context.HeatmapDataList[idx].ShaderProgram = (type == GL_FLOAT ? &Context.ShaderFloat : &Context.ShaderInt);
|
Context.HeatmapDataList[idx].ShaderProgram = (type == GL_FLOAT ? &Context.ShaderFloat : &Context.ShaderInt);
|
||||||
|
|
||||||
|
@ -240,7 +241,7 @@ void AddColormap(const ImU32* keys, int count, bool qual)
|
||||||
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);
|
||||||
|
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
Context.ColormapIDs.push_back(textureID);
|
Context.ColormapIDs.push_back(textureID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,17 +257,17 @@ static GLuint CreateHeatmapTexture()
|
||||||
return textureID;
|
return textureID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHeatmapData(int plotID, const ImS8* values, int rows, int cols) { SetTextureData(plotID, values, rows, cols, GL_R8I, GL_RED_INTEGER, GL_BYTE); }
|
void SetHeatmapData(int itemID, const ImS8* values, int rows, int cols) { SetTextureData(itemID, values, rows, cols, GL_R8I, GL_RED_INTEGER, GL_BYTE); }
|
||||||
void SetHeatmapData(int plotID, const ImU8* values, int rows, int cols) { SetTextureData(plotID, values, rows, cols, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE); }
|
void SetHeatmapData(int itemID, const ImU8* values, int rows, int cols) { SetTextureData(itemID, values, rows, cols, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE); }
|
||||||
void SetHeatmapData(int plotID, const ImS16* values, int rows, int cols) { SetTextureData(plotID, values, rows, cols, GL_R16I, GL_RED_INTEGER, GL_SHORT); }
|
void SetHeatmapData(int itemID, const ImS16* values, int rows, int cols) { SetTextureData(itemID, values, rows, cols, GL_R16I, GL_RED_INTEGER, GL_SHORT); }
|
||||||
void SetHeatmapData(int plotID, const ImU16* values, int rows, int cols) { SetTextureData(plotID, values, rows, cols, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT); }
|
void SetHeatmapData(int itemID, const ImU16* values, int rows, int cols) { SetTextureData(itemID, values, rows, cols, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT); }
|
||||||
void SetHeatmapData(int plotID, const ImS32* values, int rows, int cols) { SetTextureData(plotID, values, rows, cols, GL_R32I, GL_RED_INTEGER, GL_INT); }
|
void SetHeatmapData(int itemID, const ImS32* values, int rows, int cols) { SetTextureData(itemID, values, rows, cols, GL_R32I, GL_RED_INTEGER, GL_INT); }
|
||||||
void SetHeatmapData(int plotID, const ImU32* values, int rows, int cols) { SetTextureData(plotID, values, rows, cols, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT); }
|
void SetHeatmapData(int itemID, const ImU32* values, int rows, int cols) { SetTextureData(itemID, values, rows, cols, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT); }
|
||||||
void SetHeatmapData(int plotID, const float* values, int rows, int cols) { SetTextureData(plotID, values, rows, cols, GL_R32F, GL_RED, GL_FLOAT); }
|
void SetHeatmapData(int itemID, const float* values, int rows, int cols) { SetTextureData(itemID, values, rows, cols, GL_R32F, GL_RED, GL_FLOAT); }
|
||||||
|
|
||||||
void SetHeatmapData(int plotID, const double* values, int rows, int cols)
|
void SetHeatmapData(int itemID, const double* values, int rows, int cols)
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
if(Context.temp1.Size < rows * cols)
|
if(Context.temp1.Size < rows * cols)
|
||||||
Context.temp1.resize(rows * cols);
|
Context.temp1.resize(rows * cols);
|
||||||
|
@ -274,12 +275,12 @@ void SetHeatmapData(int plotID, const double* values, int rows, int cols)
|
||||||
for(int i = 0; i < rows*cols; i++)
|
for(int i = 0; i < rows*cols; i++)
|
||||||
Context.temp1[i] = (float)values[i];
|
Context.temp1[i] = (float)values[i];
|
||||||
|
|
||||||
SetTextureData(plotID, Context.temp1.Data, rows, cols, GL_R32F, GL_RED, GL_FLOAT);
|
SetTextureData(itemID, Context.temp1.Data, rows, cols, GL_R32F, GL_RED, GL_FLOAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHeatmapData(int plotID, const ImS64* values, int rows, int cols)
|
void SetHeatmapData(int itemID, const ImS64* values, int rows, int cols)
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
if(Context.temp2.Size < rows * cols)
|
if(Context.temp2.Size < rows * cols)
|
||||||
Context.temp2.resize(rows * cols);
|
Context.temp2.resize(rows * cols);
|
||||||
|
@ -287,12 +288,12 @@ void SetHeatmapData(int plotID, const ImS64* values, int rows, int cols)
|
||||||
for(int i = 0; i < rows*cols; i++)
|
for(int i = 0; i < rows*cols; i++)
|
||||||
Context.temp2[i] = (ImS32)values[i];
|
Context.temp2[i] = (ImS32)values[i];
|
||||||
|
|
||||||
SetTextureData(plotID, Context.temp2.Data, rows, cols, GL_R32I, GL_RED_INTEGER, GL_INT);
|
SetTextureData(itemID, Context.temp2.Data, rows, cols, GL_R32I, GL_RED_INTEGER, GL_INT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHeatmapData(int plotID, const ImU64* values, int rows, int cols)
|
void SetHeatmapData(int itemID, const ImU64* values, int rows, int cols)
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
if(Context.temp3.Size < rows * cols)
|
if(Context.temp3.Size < rows * cols)
|
||||||
Context.temp3.resize(rows * cols);
|
Context.temp3.resize(rows * cols);
|
||||||
|
@ -300,18 +301,18 @@ void SetHeatmapData(int plotID, const ImU64* values, int rows, int cols)
|
||||||
for(int i = 0; i < rows*cols; i++)
|
for(int i = 0; i < rows*cols; i++)
|
||||||
Context.temp3[i] = (ImU32)values[i];
|
Context.temp3[i] = (ImU32)values[i];
|
||||||
|
|
||||||
SetTextureData(plotID, Context.temp3.Data, rows, cols, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT);
|
SetTextureData(itemID, Context.temp3.Data, rows, cols, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max, float scale_min, float scale_max, ImPlotColormap colormap)
|
void RenderHeatmap(int itemID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max, float scale_min, float scale_max, ImPlotColormap colormap)
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
int idx = Context.PlotIDs.GetInt(plotID, Context.HeatmapDataList.Size);
|
int idx = Context.ItemIDs.GetInt(itemID, Context.HeatmapDataList.Size);
|
||||||
|
|
||||||
if(idx == Context.HeatmapDataList.Size)
|
if(idx == Context.HeatmapDataList.Size)
|
||||||
{
|
{
|
||||||
// New entry
|
// New entry
|
||||||
Context.PlotIDs.SetInt(plotID, Context.HeatmapDataList.Size);
|
Context.ItemIDs.SetInt(itemID, Context.HeatmapDataList.Size);
|
||||||
Context.HeatmapDataList.push_back(HeatmapData());
|
Context.HeatmapDataList.push_back(HeatmapData());
|
||||||
Context.HeatmapDataList[idx].HeatmapTexID = CreateHeatmapTexture();
|
Context.HeatmapDataList[idx].HeatmapTexID = CreateHeatmapTexture();
|
||||||
}
|
}
|
||||||
|
@ -324,7 +325,7 @@ void RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bounds_min, c
|
||||||
if(Context.ShaderInt.ID == 0 || Context.ShaderFloat.ID == 0)
|
if(Context.ShaderInt.ID == 0 || Context.ShaderFloat.ID == 0)
|
||||||
DrawList.AddCallback(CreateHeatmapShader, nullptr);
|
DrawList.AddCallback(CreateHeatmapShader, nullptr);
|
||||||
|
|
||||||
DrawList.AddCallback(RenderCallback, (void*)(intptr_t)plotID);
|
DrawList.AddCallback(RenderCallback, (void*)(intptr_t)itemID);
|
||||||
DrawList.PrimReserve(6, 4);
|
DrawList.PrimReserve(6, 4);
|
||||||
DrawList.PrimRectUV(bounds_min, bounds_max, ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 0);
|
DrawList.PrimRectUV(bounds_min, bounds_max, ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 0);
|
||||||
DrawList.AddCallback(ResetState, nullptr);
|
DrawList.AddCallback(ResetState, nullptr);
|
||||||
|
@ -332,13 +333,13 @@ void RenderHeatmap(int plotID, ImDrawList& DrawList, const ImVec2& bounds_min, c
|
||||||
|
|
||||||
void BustPlotCache()
|
void BustPlotCache()
|
||||||
{
|
{
|
||||||
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
ContextData& Context = *((ContextData*)GImPlot->backendCtx);
|
||||||
|
|
||||||
for(const HeatmapData& data : Context.HeatmapDataList)
|
for(const HeatmapData& data : Context.HeatmapDataList)
|
||||||
glDeleteTextures(1, &data.HeatmapTexID);
|
glDeleteTextures(1, &data.HeatmapTexID);
|
||||||
|
|
||||||
Context.HeatmapDataList.clear();
|
Context.HeatmapDataList.clear();
|
||||||
Context.PlotIDs.Clear();
|
Context.ItemIDs.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BustItemCache() {}
|
void BustItemCache() {}
|
194
backends/implot_impl_opengl3.h
Normal file
194
backends/implot_impl_opengl3.h
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
// Copyright (c) 2021 Evan Pezent
|
||||||
|
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// ImPlot v0.10 WIP
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define IMPLOT_BACKEND_ENABLED
|
||||||
|
#define IMPLOT_BACKEND_HAS_HEATMAP
|
||||||
|
#define IMPLOT_BACKEND_HAS_COLORMAP
|
||||||
|
|
||||||
|
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_ES3) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||||
|
|
||||||
|
// Try to detect GLES on matching platforms
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "TargetConditionals.h"
|
||||||
|
#endif
|
||||||
|
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
|
||||||
|
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
||||||
|
|
||||||
|
// Otherwise try to detect supported Desktop OpenGL loaders..
|
||||||
|
#elif defined(__has_include)
|
||||||
|
#if __has_include(<GL/glew.h>)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
|
||||||
|
#elif __has_include(<glad/glad.h>)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
|
||||||
|
#elif __has_include(<glad/gl.h>)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLAD2
|
||||||
|
#elif __has_include(<GL/gl3w.h>)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
|
||||||
|
#elif __has_include(<glbinding/glbinding.h>)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING3
|
||||||
|
#elif __has_include(<glbinding/Binding.h>)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
|
||||||
|
#else
|
||||||
|
#error "Cannot detect OpenGL loader!"
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GL3W // Default to GL3W embedded in our repository
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ImPlot {
|
||||||
|
namespace Backend {
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// [SECTION] Misc backend functions
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Struct to hold backend-related context data
|
||||||
|
*
|
||||||
|
* A backend may store in this struct any data it needs, with no constraints. A
|
||||||
|
* pointer to this struct will be stored inside ImPlot's context and can be
|
||||||
|
* accessed at any time. This pointer will be set to the returned value of @ref
|
||||||
|
* CreateContext(). All resources held by this struct must be freed inside @ref
|
||||||
|
* DestroyContext().
|
||||||
|
*/
|
||||||
|
struct ContextData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create backend context
|
||||||
|
*
|
||||||
|
* Creates and intializes the backend context. The returned pointer will be saved
|
||||||
|
* in ImPlot's context and can be accessed later.
|
||||||
|
*/
|
||||||
|
IMPLOT_API void* CreateContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy backend context
|
||||||
|
*
|
||||||
|
* Destroys and frees any memory or resources needed by the backend. After this
|
||||||
|
* call returns, no more calls to any backend function can be performed.
|
||||||
|
*/
|
||||||
|
IMPLOT_API void DestroyContext();
|
||||||
|
|
||||||
|
/** @brief Bust plot cache. Called from @ref ImPlot::BustPlotCache() */
|
||||||
|
IMPLOT_API void BustPlotCache();
|
||||||
|
|
||||||
|
/** @brief Bust item cache. Called from @ref ImPlot::BustItemCache() */
|
||||||
|
IMPLOT_API void BustItemCache();
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// [SECTION] Colormap functions
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add a colormap
|
||||||
|
*
|
||||||
|
* Adds a colormap to be handled by the backend.
|
||||||
|
*
|
||||||
|
* @param keys Colors for this colormap, in RGBA format
|
||||||
|
* @param count Number of colors in this colormap
|
||||||
|
* @param qual Qualitative: whether the colormap is continuous (`false`) or
|
||||||
|
* not (`true`)
|
||||||
|
*/
|
||||||
|
IMPLOT_API void AddColormap(const ImU32* keys, int count, bool qual);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// [SECTION] Heatmap functions
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set heatmap data
|
||||||
|
*
|
||||||
|
* Sets the data of the heatmap with the given plot ID.
|
||||||
|
*
|
||||||
|
* @param itemID ID of the heatmap to update.
|
||||||
|
* @param values Data of the heatmap to be set.`values[0]` corresponds with the
|
||||||
|
* top-left corner of the data.
|
||||||
|
* @param rows Number of rows of this heatmap
|
||||||
|
* @param cols Number of columns of this heatmap
|
||||||
|
*/
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImS8* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const ImU8*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImU8* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const ImS16*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImS16* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const ImU16*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImU16* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const ImS32*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImS32* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const ImU32*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImU32* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const float*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const float* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const double*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const double* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const ImS64*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImS64* values, int rows, int cols);
|
||||||
|
|
||||||
|
/** @copydoc SetHeatmapData(int,const ImU64*,int,int) */
|
||||||
|
IMPLOT_API void SetHeatmapData(int itemID, const ImU64* values, int rows, int cols);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Render heatmap
|
||||||
|
*
|
||||||
|
* Renders the heatmap using OpenGL acceleration
|
||||||
|
*
|
||||||
|
* @param itemID ID of the heatmap to be rendered
|
||||||
|
* @param DrawList Draw list where to submit the render commands
|
||||||
|
* @param bounds_min Minimum bounds of the heatmap (without clipping)
|
||||||
|
* @param bounds_max Maximum bounds of the heatmap (without clipping)
|
||||||
|
* @param scale_min Minimum value of the heatmap
|
||||||
|
* @param scale_max Maximum value of the heatmap
|
||||||
|
* @param colormap Colormap to be used when rendering this heatmap
|
||||||
|
*
|
||||||
|
* @note There might be values greater than `scale_max` or lower than `scale_min`.
|
||||||
|
* The shader used for rendering will clamp this values.
|
||||||
|
*/
|
||||||
|
IMPLOT_API void RenderHeatmap(
|
||||||
|
int itemID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max,
|
||||||
|
float scale_min, float scale_max, ImPlotColormap colormap);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user