From 4f19cdc436f60450d0f2c998d081501d74bcad68 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 9 Jun 2015 15:31:53 -0600 Subject: [PATCH] Fixes for ocornut-imgui integration, handling negative scissor inputs, removed unnecessary vertex count calculation --- examples/common/imgui/ocornut_imgui.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index eb868842..c38c0dd9 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -35,17 +35,10 @@ struct OcornutImguiContext { bgfx::TransientVertexBuffer tvb; - uint32_t vtx_size = 0; const ImDrawList* cmd_list = _lists[ii]; const ImDrawVert* vtx_buffer = cmd_list->vtx_buffer.begin(); - - const ImDrawCmd* pcmd_begin = cmd_list->commands.begin(); - const ImDrawCmd* pcmd_end = cmd_list->commands.end(); - for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++) - { - vtx_size += (uint32_t)pcmd->vtx_count; - } + uint32_t vtx_size = (uint32_t)cmd_list->vtx_buffer.size(); if (!bgfx::checkAvailTransientVertexBuffer(vtx_size, m_decl)) { @@ -59,6 +52,8 @@ struct OcornutImguiContext memcpy(verts, vtx_buffer, vtx_size * sizeof(ImDrawVert)); uint32_t vtx_offset = 0; + const ImDrawCmd* pcmd_begin = cmd_list->commands.begin(); + const ImDrawCmd* pcmd_end = cmd_list->commands.end(); for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++) { if (0 == pcmd->vtx_count) @@ -72,10 +67,10 @@ struct OcornutImguiContext | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) | BGFX_STATE_MSAA ); - bgfx::setScissor(uint16_t(pcmd->clip_rect.x) - , uint16_t(pcmd->clip_rect.y) - , uint16_t(pcmd->clip_rect.z-pcmd->clip_rect.x) - , uint16_t(pcmd->clip_rect.w-pcmd->clip_rect.y) + bgfx::setScissor(uint16_t(bx::fmax(pcmd->clip_rect.x, 0.0f)) + , uint16_t(bx::fmax(pcmd->clip_rect.y, 0.0f)) + , uint16_t(bx::fmin(pcmd->clip_rect.z, 65535.0f)-bx::fmax(pcmd->clip_rect.x, 0.0f)) + , uint16_t(bx::fmin(pcmd->clip_rect.w, 65535.0f)-bx::fmax(pcmd->clip_rect.y, 0.0f)) ); union { void* ptr; bgfx::TextureHandle handle; } texture = { pcmd->texture_id };