1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 23:57:26 -04:00

fix max idx calculation

This commit is contained in:
epezent 2020-08-16 20:16:19 -05:00
parent 34c3829277
commit bd4036fbff

View File

@ -242,17 +242,21 @@ struct TransformerLogLog {
// RENDERERS // RENDERERS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T>
struct MaxIdx { static const unsigned int Value; };
const unsigned int MaxIdx<unsigned short>::Value = 65535;
const unsigned int MaxIdx<unsigned int>::Value = 4294967295;
/// Renders primitive shapes in bulk as efficiently as possible. /// Renders primitive shapes in bulk as efficiently as possible.
template <typename Renderer> template <typename Renderer>
inline void RenderPrimitives(Renderer renderer, ImDrawList& DrawList) { inline void RenderPrimitives(Renderer renderer, ImDrawList& DrawList) {
unsigned int prims = renderer.Prims; unsigned int prims = renderer.Prims;
unsigned int prims_culled = 0; unsigned int prims_culled = 0;
unsigned int idx = 0; unsigned int idx = 0;
static const unsigned int max_idx = (unsigned int)(ImPow(2.0f, (float)(sizeof(ImDrawIdx) * 8)) - 1);
const ImVec2 uv = DrawList._Data->TexUvWhitePixel; const ImVec2 uv = DrawList._Data->TexUvWhitePixel;
while (prims) { while (prims) {
// find how many can be reserved up to end of current draw command's limit // find how many can be reserved up to end of current draw command's limit
unsigned int cnt = (unsigned int)ImMin(prims, (max_idx - DrawList._VtxCurrentIdx) / Renderer::VtxConsumed); unsigned int cnt = ImMin(prims, (MaxIdx<ImDrawIdx>::Value - DrawList._VtxCurrentIdx) / Renderer::VtxConsumed);
// make sure at least this many elements can be rendered to avoid situations where at the end of buffer this slow path is not taken all the time // make sure at least this many elements can be rendered to avoid situations where at the end of buffer this slow path is not taken all the time
if (cnt >= ImMin(64u, prims)) { if (cnt >= ImMin(64u, prims)) {
if (prims_culled >= cnt) if (prims_culled >= cnt)
@ -268,7 +272,7 @@ inline void RenderPrimitives(Renderer renderer, ImDrawList& DrawList) {
DrawList.PrimUnreserve(prims_culled * Renderer::IdxConsumed, prims_culled * Renderer::VtxConsumed); DrawList.PrimUnreserve(prims_culled * Renderer::IdxConsumed, prims_culled * Renderer::VtxConsumed);
prims_culled = 0; prims_culled = 0;
} }
cnt = (unsigned int)ImMin(prims, (max_idx - 0/*DrawList._VtxCurrentIdx*/) / Renderer::VtxConsumed); cnt = ImMin(prims, (MaxIdx<ImDrawIdx>::Value - 0/*DrawList._VtxCurrentIdx*/) / Renderer::VtxConsumed);
DrawList.PrimReserve(cnt * Renderer::IdxConsumed, cnt * Renderer::VtxConsumed); // reserve new draw command DrawList.PrimReserve(cnt * Renderer::IdxConsumed, cnt * Renderer::VtxConsumed); // reserve new draw command
} }
prims -= cnt; prims -= cnt;