mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Manually merged #449.
This commit is contained in:
parent
5f1b3f2e66
commit
af2bb3874d
2 changed files with 48 additions and 66 deletions
|
@ -22,9 +22,9 @@ struct OcornutImguiContext
|
|||
{
|
||||
static void* memAlloc(size_t _size);
|
||||
static void memFree(void* _ptr);
|
||||
static void renderDrawLists(ImDrawList** const _lists, int _count);
|
||||
static void renderDrawLists(ImDrawData* draw_data);
|
||||
|
||||
void render(ImDrawList** const _lists, int _count)
|
||||
void render(ImDrawData* draw_data)
|
||||
{
|
||||
const float width = ImGui::GetIO().DisplaySize.x;
|
||||
const float height = ImGui::GetIO().DisplaySize.y;
|
||||
|
@ -35,37 +35,42 @@ struct OcornutImguiContext
|
|||
bgfx::setViewTransform(m_viewId, NULL, ortho);
|
||||
|
||||
// Render command lists
|
||||
for (int32_t ii = 0; ii < _count; ++ii)
|
||||
for (int32_t ii = 0; ii < draw_data->CmdListsCount; ++ii)
|
||||
{
|
||||
bgfx::TransientVertexBuffer tvb;
|
||||
bgfx::TransientIndexBuffer tib;
|
||||
|
||||
const ImDrawList* cmd_list = _lists[ii];
|
||||
const ImDrawVert* vtx_buffer = cmd_list->vtx_buffer.begin();
|
||||
uint32_t vtx_size = (uint32_t)cmd_list->vtx_buffer.size();
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[ii];
|
||||
uint32_t vtx_size = (uint32_t)cmd_list->VtxBuffer.size();
|
||||
uint32_t idx_size = (uint32_t)cmd_list->IdxBuffer.size();
|
||||
|
||||
if (!bgfx::checkAvailTransientVertexBuffer(vtx_size, m_decl))
|
||||
if (!bgfx::checkAvailTransientVertexBuffer(vtx_size, m_decl) || !bgfx::checkAvailTransientIndexBuffer(idx_size))
|
||||
{
|
||||
// not enough space in transient buffer just quit drawing the rest...
|
||||
break;
|
||||
}
|
||||
|
||||
bgfx::allocTransientVertexBuffer(&tvb, vtx_size, m_decl);
|
||||
bgfx::allocTransientIndexBuffer(&tib, idx_size);
|
||||
|
||||
ImDrawVert* verts = (ImDrawVert*)tvb.data;
|
||||
memcpy(verts, vtx_buffer, vtx_size * sizeof(ImDrawVert));
|
||||
memcpy(verts, cmd_list->VtxBuffer.begin(), 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();
|
||||
ImDrawIdx* indices = (ImDrawIdx*)tib.data;
|
||||
memcpy(indices, cmd_list->IdxBuffer.begin(), idx_size * sizeof(ImDrawIdx));
|
||||
|
||||
uint32_t elem_offset = 0;
|
||||
const ImDrawCmd* pcmd_begin = cmd_list->CmdBuffer.begin();
|
||||
const ImDrawCmd* pcmd_end = cmd_list->CmdBuffer.end();
|
||||
for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
|
||||
{
|
||||
if (pcmd->user_callback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
continue;
|
||||
}
|
||||
if (0 == pcmd->vtx_count)
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
elem_offset += pcmd->ElemCount;
|
||||
continue;
|
||||
}
|
||||
if (0 == pcmd->ElemCount)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -76,23 +81,24 @@ struct OcornutImguiContext
|
|||
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
|
||||
| BGFX_STATE_MSAA
|
||||
);
|
||||
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 };
|
||||
bgfx::setScissor(uint16_t(bx::fmax(pcmd->ClipRect.x, 0.0f))
|
||||
, uint16_t(bx::fmax(pcmd->ClipRect.y, 0.0f))
|
||||
, uint16_t(bx::fmin(pcmd->ClipRect.z, 65535.0f)-bx::fmax(pcmd->ClipRect.x, 0.0f))
|
||||
, uint16_t(bx::fmin(pcmd->ClipRect.w, 65535.0f)-bx::fmax(pcmd->ClipRect.y, 0.0f))
|
||||
);
|
||||
union { void* ptr; bgfx::TextureHandle handle; } texture = { pcmd->TextureId };
|
||||
|
||||
bgfx::setTexture(0, s_tex, 0 != texture.handle.idx
|
||||
? texture.handle
|
||||
: m_texture
|
||||
);
|
||||
|
||||
bgfx::setVertexBuffer(&tvb, vtx_offset, pcmd->vtx_count);
|
||||
bgfx::setVertexBuffer(&tvb, 0, vtx_size);
|
||||
bgfx::setIndexBuffer(&tib, elem_offset, pcmd->ElemCount);
|
||||
bgfx::setProgram(m_program);
|
||||
bgfx::submit(m_viewId);
|
||||
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
elem_offset += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +107,7 @@ struct OcornutImguiContext
|
|||
{
|
||||
m_viewId = 255;
|
||||
m_allocator = _allocator;
|
||||
m_lastScroll = 0;
|
||||
m_lastScroll = 0;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.RenderDrawListsFn = renderDrawLists;
|
||||
|
@ -179,11 +185,11 @@ struct OcornutImguiContext
|
|||
|
||||
io.Fonts->GetTexDataAsRGBA32(&data, &width, &height);
|
||||
|
||||
m_texture = bgfx::createTexture2D((uint16_t)width
|
||||
m_texture = bgfx::createTexture2D( (uint16_t)width
|
||||
, (uint16_t)height
|
||||
, 1
|
||||
, bgfx::TextureFormat::BGRA8
|
||||
, BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT
|
||||
, 0
|
||||
, bgfx::copy(data, width*height*4)
|
||||
);
|
||||
|
||||
|
@ -206,9 +212,9 @@ struct OcornutImguiContext
|
|||
{
|
||||
m_viewId = _viewId;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (_inputChar < 0x7f)
|
||||
if (_inputChar < 0x7f)
|
||||
{
|
||||
io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
|
||||
io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
|
||||
}
|
||||
|
||||
io.DisplaySize = ImVec2((float)_width, (float)_height);
|
||||
|
@ -246,7 +252,7 @@ struct OcornutImguiContext
|
|||
bgfx::TextureHandle m_texture;
|
||||
bgfx::UniformHandle s_tex;
|
||||
uint8_t m_viewId;
|
||||
int32_t m_lastScroll;
|
||||
int32_t m_lastScroll;
|
||||
};
|
||||
|
||||
static OcornutImguiContext s_ctx;
|
||||
|
@ -261,9 +267,9 @@ void OcornutImguiContext::memFree(void* _ptr)
|
|||
BX_FREE(s_ctx.m_allocator, _ptr);
|
||||
}
|
||||
|
||||
void OcornutImguiContext::renderDrawLists(ImDrawList** const _lists, int _count)
|
||||
void OcornutImguiContext::renderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
s_ctx.render(_lists, _count);
|
||||
s_ctx.render(draw_data);
|
||||
}
|
||||
|
||||
void IMGUI_create(const void* _data, uint32_t _size, float _fontSize, bx::AllocatorI* _allocator)
|
||||
|
|
|
@ -80,8 +80,8 @@ static inline uint32_t makeRgba(uint32_t r, uint32_t g, uint32_t b, uint32_t a =
|
|||
|
||||
struct FontInt
|
||||
{
|
||||
ImFont* m_font;
|
||||
float m_scale;
|
||||
ImFont* m_font;
|
||||
float m_scale;
|
||||
float m_fontSize;
|
||||
};
|
||||
|
||||
|
@ -236,7 +236,7 @@ public:
|
|||
virtual Scintilla::XYPOSITION WidthChar(Scintilla::Font& _font, char ch) BX_OVERRIDE
|
||||
{
|
||||
FontInt* fi = (FontInt*)_font.GetID();
|
||||
return fi->m_font->GetCharAdvance((unsigned int)ch) * fi->m_scale;
|
||||
return fi->m_font->GetCharAdvance((unsigned int)ch) * fi->m_scale;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION Ascent(Scintilla::Font& _font) BX_OVERRIDE
|
||||
|
@ -251,14 +251,14 @@ public:
|
|||
return -fi->m_font->Descent * fi->m_scale;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION InternalLeading(Scintilla::Font& /*_font*/) BX_OVERRIDE
|
||||
virtual Scintilla::XYPOSITION InternalLeading(Scintilla::Font& /*_font*/) BX_OVERRIDE
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION ExternalLeading(Scintilla::Font& /*_font*/) BX_OVERRIDE
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION Height(Scintilla::Font& _font) BX_OVERRIDE
|
||||
|
@ -633,7 +633,7 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
intptr_t command(unsigned int _msg, uintptr_t _p0 = 0, intptr_t _p1 = 0)
|
||||
intptr_t command(unsigned int _msg, uintptr_t _p0 = 0, intptr_t _p1 = 0)
|
||||
{
|
||||
return WndProc(_msg, _p0, _p1);
|
||||
}
|
||||
|
@ -741,7 +741,7 @@ public:
|
|||
ImGuiIO& io = ImGui::GetIO();
|
||||
Scintilla::Point pt = Scintilla::Point::FromInts( (int)io.MouseClickedPos[0].x, (int)io.MouseClickedPos[0].y);
|
||||
|
||||
ButtonDown(pt, (unsigned int)io.MouseDownTime[0], false, false, false);
|
||||
ButtonDown(pt, (unsigned int)io.MouseDownDuration[0], false, false, false);
|
||||
}
|
||||
|
||||
Tick();
|
||||
|
@ -854,7 +854,7 @@ namespace Scintilla
|
|||
}
|
||||
|
||||
void Font::Create(const FontParameters& fp)
|
||||
{
|
||||
{
|
||||
FontInt* newFont = (FontInt*)ImGui::MemAlloc(sizeof(FontInt) );
|
||||
fid = newFont;
|
||||
newFont->m_font = ImGui::GetIO().Fonts->Fonts[0];
|
||||
|
@ -1063,28 +1063,4 @@ namespace Scintilla
|
|||
|
||||
} // namespace Scintilla
|
||||
|
||||
ScintillaEditor* ImGuiScintilla(const char* _name, bool* _opened, const ImVec2& _size)
|
||||
{
|
||||
ScintillaEditor* sci = NULL;
|
||||
|
||||
if (ImGui::Begin(_name, _opened, _size) )
|
||||
{
|
||||
ImGuiStorage* storage = ImGui::GetStateStorage();
|
||||
|
||||
ImGuiID id = ImGui::GetID(_name);
|
||||
sci = (ScintillaEditor*)storage->GetVoidPtr(id);
|
||||
if (NULL == sci)
|
||||
{
|
||||
ImVec2 size = ImGui::GetWindowSize();
|
||||
sci = ScintillaEditor::create(size.x, size.y);
|
||||
storage->SetVoidPtr(id, (void*)sci);
|
||||
}
|
||||
|
||||
sci->draw();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
return sci;
|
||||
}
|
||||
|
||||
#endif // defined(SCI_NAMESPACE)
|
||||
|
|
Loading…
Reference in a new issue