2016-08-29 22:31:11 +02:00
|
|
|
|
/*
|
2018-02-03 17:39:28 +01:00
|
|
|
|
* Copyright 2014-2015 Daniel Collin. All rights reserved.
|
2016-08-29 22:31:11 +02:00
|
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
#include <bgfx/bgfx.h>
|
|
|
|
|
#include <bgfx/embedded_shader.h>
|
|
|
|
|
#include <bx/allocator.h>
|
|
|
|
|
#include <bx/math.h>
|
|
|
|
|
#include <bx/timer.h>
|
|
|
|
|
#include <ocornut-imgui/imgui.h>
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
|
|
#include "imgui.h"
|
2017-04-11 08:16:10 +02:00
|
|
|
|
#include "../bgfx_utils.h"
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
#ifndef USE_ENTRY
|
|
|
|
|
# if defined(SCI_NAMESPACE)
|
|
|
|
|
# define USE_ENTRY 1
|
|
|
|
|
# else
|
|
|
|
|
# define USE_ENTRY 0
|
|
|
|
|
# endif // defined(SCI_NAMESPACE)
|
|
|
|
|
#endif // USE_ENTRY
|
|
|
|
|
|
|
|
|
|
#if USE_ENTRY
|
|
|
|
|
# include "../entry/entry.h"
|
|
|
|
|
#endif // USE_ENTRY
|
|
|
|
|
|
|
|
|
|
#if defined(SCI_NAMESPACE)
|
|
|
|
|
# include "../entry/input.h"
|
|
|
|
|
# include "scintilla.h"
|
|
|
|
|
#endif // defined(SCI_NAMESPACE)
|
|
|
|
|
|
|
|
|
|
#include "vs_ocornut_imgui.bin.h"
|
|
|
|
|
#include "fs_ocornut_imgui.bin.h"
|
2016-08-29 22:31:11 +02:00
|
|
|
|
#include "vs_imgui_image.bin.h"
|
|
|
|
|
#include "fs_imgui_image.bin.h"
|
2018-02-03 17:39:28 +01:00
|
|
|
|
|
|
|
|
|
#include "roboto_regular.ttf.h"
|
|
|
|
|
#include "robotomono_regular.ttf.h"
|
|
|
|
|
#include "icons_kenney.ttf.h"
|
|
|
|
|
#include "icons_font_awesome.ttf.h"
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
|
static const bgfx::EmbeddedShader s_embeddedShaders[] =
|
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_ocornut_imgui),
|
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_ocornut_imgui),
|
2017-04-11 08:16:10 +02:00
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_imgui_image),
|
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_imgui_image),
|
|
|
|
|
|
|
|
|
|
BGFX_EMBEDDED_SHADER_END()
|
|
|
|
|
};
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
struct FontRangeMerge
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const void* data;
|
|
|
|
|
size_t size;
|
|
|
|
|
ImWchar ranges[3];
|
|
|
|
|
};
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
static FontRangeMerge s_fontRangeMerge[] =
|
|
|
|
|
{
|
|
|
|
|
{ s_iconsKenneyTtf, sizeof(s_iconsKenneyTtf), { ICON_MIN_KI, ICON_MAX_KI, 0 } },
|
|
|
|
|
{ s_iconsFontAwesomeTtf, sizeof(s_iconsFontAwesomeTtf), { ICON_MIN_FA, ICON_MAX_FA, 0 } },
|
|
|
|
|
};
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
static void* memAlloc(size_t _size);
|
|
|
|
|
static void memFree(void* _ptr);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
struct OcornutImguiContext
|
|
|
|
|
{
|
|
|
|
|
static void renderDrawLists(ImDrawData* _drawData);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void render(ImDrawData* _drawData)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
const float width = io.DisplaySize.x;
|
|
|
|
|
const float height = io.DisplaySize.y;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bgfx::setViewName(m_viewId, "ImGui");
|
|
|
|
|
bgfx::setViewMode(m_viewId, bgfx::ViewMode::Sequential);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const bgfx::HMD* hmd = bgfx::getHMD();
|
|
|
|
|
const bgfx::Caps* caps = bgfx::getCaps();
|
|
|
|
|
if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) )
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
float proj[16];
|
|
|
|
|
bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
static float time = 0.0f;
|
|
|
|
|
time += 0.05f;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const float dist = 10.0f;
|
|
|
|
|
const float offset0 = -proj[8] + (hmd->eye[0].viewOffset[0] / dist * proj[0]);
|
|
|
|
|
const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
float ortho[2][16];
|
|
|
|
|
const float viewOffset = width/4.0f;
|
|
|
|
|
const float viewWidth = width/2.0f;
|
|
|
|
|
bx::mtxOrtho(ortho[0], viewOffset, viewOffset + viewWidth, height, 0.0f, 0.0f, 1000.0f, offset0, caps->homogeneousDepth);
|
|
|
|
|
bx::mtxOrtho(ortho[1], viewOffset, viewOffset + viewWidth, height, 0.0f, 0.0f, 1000.0f, offset1, caps->homogeneousDepth);
|
|
|
|
|
bgfx::setViewTransform(m_viewId, NULL, ortho[0], BGFX_VIEW_STEREO, ortho[1]);
|
|
|
|
|
bgfx::setViewRect(m_viewId, 0, 0, hmd->width, hmd->height);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
2018-02-03 17:39:28 +01:00
|
|
|
|
else
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
float ortho[16];
|
|
|
|
|
bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
|
|
|
|
|
bgfx::setViewTransform(m_viewId, NULL, ortho);
|
|
|
|
|
bgfx::setViewRect(m_viewId, 0, 0, uint16_t(width), uint16_t(height) );
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
// Render command lists
|
|
|
|
|
for (int32_t ii = 0, num = _drawData->CmdListsCount; ii < num; ++ii)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bgfx::TransientVertexBuffer tvb;
|
|
|
|
|
bgfx::TransientIndexBuffer tib;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const ImDrawList* drawList = _drawData->CmdLists[ii];
|
|
|
|
|
uint32_t numVertices = (uint32_t)drawList->VtxBuffer.size();
|
|
|
|
|
uint32_t numIndices = (uint32_t)drawList->IdxBuffer.size();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
if (!checkAvailTransientBuffers(numVertices, m_decl, numIndices) )
|
|
|
|
|
{
|
|
|
|
|
// not enough space in transient buffer just quit drawing the rest...
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bgfx::allocTransientVertexBuffer(&tvb, numVertices, m_decl);
|
|
|
|
|
bgfx::allocTransientIndexBuffer(&tib, numIndices);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImDrawVert* verts = (ImDrawVert*)tvb.data;
|
|
|
|
|
bx::memCopy(verts, drawList->VtxBuffer.begin(), numVertices * sizeof(ImDrawVert) );
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImDrawIdx* indices = (ImDrawIdx*)tib.data;
|
|
|
|
|
bx::memCopy(indices, drawList->IdxBuffer.begin(), numIndices * sizeof(ImDrawIdx) );
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
for (const ImDrawCmd* cmd = drawList->CmdBuffer.begin(), *cmdEnd = drawList->CmdBuffer.end(); cmd != cmdEnd; ++cmd)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
if (cmd->UserCallback)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
cmd->UserCallback(drawList, cmd);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
2018-02-03 17:39:28 +01:00
|
|
|
|
else if (0 != cmd->ElemCount)
|
|
|
|
|
{
|
|
|
|
|
uint64_t state = 0
|
|
|
|
|
| BGFX_STATE_RGB_WRITE
|
|
|
|
|
| BGFX_STATE_ALPHA_WRITE
|
|
|
|
|
| BGFX_STATE_MSAA
|
|
|
|
|
;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bgfx::TextureHandle th = m_texture;
|
|
|
|
|
bgfx::ProgramHandle program = m_program;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
if (NULL != cmd->TextureId)
|
|
|
|
|
{
|
|
|
|
|
union { ImTextureID ptr; struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; } texture = { cmd->TextureId };
|
|
|
|
|
state |= 0 != (IMGUI_FLAGS_ALPHA_BLEND & texture.s.flags)
|
|
|
|
|
? BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
|
|
|
|
|
: BGFX_STATE_NONE
|
|
|
|
|
;
|
|
|
|
|
th = texture.s.handle;
|
|
|
|
|
if (0 != texture.s.mip)
|
|
|
|
|
{
|
|
|
|
|
const float lodEnabled[4] = { float(texture.s.mip), 1.0f, 0.0f, 0.0f };
|
|
|
|
|
bgfx::setUniform(u_imageLodEnabled, lodEnabled);
|
|
|
|
|
program = m_imageProgram;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
state |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const uint16_t xx = uint16_t(bx::max(cmd->ClipRect.x, 0.0f) );
|
|
|
|
|
const uint16_t yy = uint16_t(bx::max(cmd->ClipRect.y, 0.0f) );
|
|
|
|
|
bgfx::setScissor(xx, yy
|
|
|
|
|
, uint16_t(bx::min(cmd->ClipRect.z, 65535.0f)-xx)
|
|
|
|
|
, uint16_t(bx::min(cmd->ClipRect.w, 65535.0f)-yy)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
bgfx::setState(state);
|
|
|
|
|
bgfx::setTexture(0, s_tex, th);
|
|
|
|
|
bgfx::setVertexBuffer(0, &tvb, 0, numVertices);
|
|
|
|
|
bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount);
|
|
|
|
|
bgfx::submit(cmd->ViewId, program);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
offset += cmd->ElemCount;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void create(float _fontSize, bx::AllocatorI* _allocator)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
|
|
|
|
m_allocator = _allocator;
|
|
|
|
|
|
|
|
|
|
if (NULL == _allocator)
|
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
static bx::DefaultAllocator allocator;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
m_allocator = &allocator;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
m_viewId = 255;
|
|
|
|
|
m_lastScroll = 0;
|
|
|
|
|
m_last = bx::getHPCounter();
|
|
|
|
|
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
io.RenderDrawListsFn = renderDrawLists;
|
|
|
|
|
io.MemAllocFn = memAlloc;
|
|
|
|
|
io.MemFreeFn = memFree;
|
|
|
|
|
|
|
|
|
|
io.DisplaySize = ImVec2(1280.0f, 720.0f);
|
|
|
|
|
io.DeltaTime = 1.0f / 60.0f;
|
|
|
|
|
io.IniFilename = NULL;
|
|
|
|
|
|
|
|
|
|
setupStyle(true);
|
|
|
|
|
|
|
|
|
|
#if defined(SCI_NAMESPACE)
|
|
|
|
|
io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab;
|
|
|
|
|
io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left;
|
|
|
|
|
io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right;
|
|
|
|
|
io.KeyMap[ImGuiKey_UpArrow] = (int)entry::Key::Up;
|
|
|
|
|
io.KeyMap[ImGuiKey_DownArrow] = (int)entry::Key::Down;
|
|
|
|
|
io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home;
|
|
|
|
|
io.KeyMap[ImGuiKey_End] = (int)entry::Key::End;
|
|
|
|
|
io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete;
|
|
|
|
|
io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace;
|
|
|
|
|
io.KeyMap[ImGuiKey_Enter] = (int)entry::Key::Return;
|
|
|
|
|
io.KeyMap[ImGuiKey_Escape] = (int)entry::Key::Esc;
|
|
|
|
|
io.KeyMap[ImGuiKey_A] = (int)entry::Key::KeyA;
|
|
|
|
|
io.KeyMap[ImGuiKey_C] = (int)entry::Key::KeyC;
|
|
|
|
|
io.KeyMap[ImGuiKey_V] = (int)entry::Key::KeyV;
|
|
|
|
|
io.KeyMap[ImGuiKey_X] = (int)entry::Key::KeyX;
|
|
|
|
|
io.KeyMap[ImGuiKey_Y] = (int)entry::Key::KeyY;
|
|
|
|
|
io.KeyMap[ImGuiKey_Z] = (int)entry::Key::KeyZ;
|
|
|
|
|
#endif // defined(SCI_NAMESPACE)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bgfx::RendererType::Enum type = bgfx::getRendererType();
|
|
|
|
|
m_program = bgfx::createProgram(
|
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_ocornut_imgui")
|
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_ocornut_imgui")
|
|
|
|
|
, true
|
|
|
|
|
);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
|
|
u_imageLodEnabled = bgfx::createUniform("u_imageLodEnabled", bgfx::UniformType::Vec4);
|
2018-02-03 17:39:28 +01:00
|
|
|
|
m_imageProgram = bgfx::createProgram(
|
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_imgui_image")
|
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_imgui_image")
|
|
|
|
|
, true
|
|
|
|
|
);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
m_decl
|
|
|
|
|
.begin()
|
|
|
|
|
.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
|
|
|
|
|
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
|
|
|
|
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
|
|
|
|
.end();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
s_tex = bgfx::createUniform("s_tex", bgfx::UniformType::Int1);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
uint8_t* data;
|
|
|
|
|
int32_t width;
|
|
|
|
|
int32_t height;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImFontConfig config;
|
|
|
|
|
config.FontDataOwnedByAtlas = false;
|
|
|
|
|
config.MergeMode = false;
|
|
|
|
|
// config.MergeGlyphCenterV = true;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const ImWchar* ranges = io.Fonts->GetGlyphRangesCyrillic();
|
|
|
|
|
m_font[ImGui::Font::Regular] = io.Fonts->AddFontFromMemoryTTF( (void*)s_robotoRegularTtf, sizeof(s_robotoRegularTtf), _fontSize, &config, ranges);
|
|
|
|
|
m_font[ImGui::Font::Mono ] = io.Fonts->AddFontFromMemoryTTF( (void*)s_robotoMonoRegularTtf, sizeof(s_robotoMonoRegularTtf), _fontSize-3.0f, &config, ranges);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
config.MergeMode = true;
|
|
|
|
|
config.DstFont = m_font[ImGui::Font::Regular];
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(s_fontRangeMerge); ++ii)
|
|
|
|
|
{
|
|
|
|
|
const FontRangeMerge& frm = s_fontRangeMerge[ii];
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
io.Fonts->AddFontFromMemoryTTF( (void*)frm.data
|
|
|
|
|
, (int)frm.size
|
|
|
|
|
, _fontSize-3.0f
|
|
|
|
|
, &config
|
|
|
|
|
, frm.ranges
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
io.Fonts->GetTexDataAsRGBA32(&data, &width, &height);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
m_texture = bgfx::createTexture2D(
|
|
|
|
|
(uint16_t)width
|
|
|
|
|
, (uint16_t)height
|
|
|
|
|
, false
|
|
|
|
|
, 1
|
|
|
|
|
, bgfx::TextureFormat::BGRA8
|
|
|
|
|
, 0
|
|
|
|
|
, bgfx::copy(data, width*height*4)
|
|
|
|
|
);
|
2018-02-03 17:41:07 +01:00
|
|
|
|
|
2018-02-03 22:46:15 +01:00
|
|
|
|
// bgfxmod(martin): disable imgui docking shipped by bgfx
|
|
|
|
|
// ImGui::InitDockContext();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void destroy()
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 22:46:15 +01:00
|
|
|
|
// bgfxmod(martin): disable imgui docking shipped by bgfx
|
|
|
|
|
// ImGui::ShutdownDockContext();
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImGui::Shutdown();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bgfx::destroy(s_tex);
|
|
|
|
|
bgfx::destroy(m_texture);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bgfx::destroy(u_imageLodEnabled);
|
|
|
|
|
bgfx::destroy(m_imageProgram);
|
|
|
|
|
bgfx::destroy(m_program);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
m_allocator = NULL;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void setupStyle(bool _dark)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
// Doug Binks' darl color scheme
|
|
|
|
|
// https://gist.github.com/dougbinks/8089b4bbaccaaf6fa204236978d165a9
|
|
|
|
|
ImGuiStyle& style = ImGui::GetStyle();
|
|
|
|
|
if (_dark)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImGui::StyleColorsDark(&style);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
2018-02-03 17:39:28 +01:00
|
|
|
|
else
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImGui::StyleColorsLight(&style);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
style.FrameRounding = 4.0f;
|
|
|
|
|
style.WindowBorderSize = 0.0f;
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void beginFrame(
|
|
|
|
|
int32_t _mx
|
|
|
|
|
, int32_t _my
|
|
|
|
|
, uint8_t _button
|
|
|
|
|
, int32_t _scroll
|
|
|
|
|
, int _width
|
|
|
|
|
, int _height
|
|
|
|
|
, char _inputChar
|
|
|
|
|
, bgfx::ViewId _viewId
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
m_viewId = _viewId;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
if (_inputChar < 0x7f)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
io.DisplaySize = ImVec2( (float)_width, (float)_height);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
const int64_t now = bx::getHPCounter();
|
|
|
|
|
const int64_t frameTime = now - m_last;
|
|
|
|
|
m_last = now;
|
|
|
|
|
const double freq = double(bx::getHPFrequency() );
|
|
|
|
|
io.DeltaTime = float(frameTime/freq);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
io.MousePos = ImVec2( (float)_mx, (float)_my);
|
|
|
|
|
io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
|
|
|
|
|
io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT);
|
|
|
|
|
io.MouseDown[2] = 0 != (_button & IMGUI_MBUT_MIDDLE);
|
|
|
|
|
io.MouseWheel = (float)(_scroll - m_lastScroll);
|
|
|
|
|
m_lastScroll = _scroll;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
#if defined(SCI_NAMESPACE)
|
|
|
|
|
uint8_t modifiers = inputGetModifiersState();
|
|
|
|
|
io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
|
|
|
|
|
io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) );
|
|
|
|
|
io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) );
|
|
|
|
|
for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) );
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
2018-02-03 17:39:28 +01:00
|
|
|
|
#endif // defined(SCI_NAMESPACE)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)_viewId);
|
|
|
|
|
|
|
|
|
|
ImGuizmo::BeginFrame();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void endFrame()
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
ImGui::PopStyleVar(1);
|
|
|
|
|
ImGui::Render();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
bx::AllocatorI* m_allocator;
|
|
|
|
|
bgfx::VertexDecl m_decl;
|
|
|
|
|
bgfx::ProgramHandle m_program;
|
|
|
|
|
bgfx::ProgramHandle m_imageProgram;
|
|
|
|
|
bgfx::TextureHandle m_texture;
|
|
|
|
|
bgfx::UniformHandle s_tex;
|
|
|
|
|
bgfx::UniformHandle u_imageLodEnabled;
|
|
|
|
|
ImFont* m_font[ImGui::Font::Count];
|
|
|
|
|
int64_t m_last;
|
|
|
|
|
int32_t m_lastScroll;
|
|
|
|
|
bgfx::ViewId m_viewId;
|
|
|
|
|
};
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
static OcornutImguiContext s_ctx;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
static void* memAlloc(size_t _size)
|
|
|
|
|
{
|
|
|
|
|
return BX_ALLOC(s_ctx.m_allocator, _size);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
static void memFree(void* _ptr)
|
|
|
|
|
{
|
|
|
|
|
BX_FREE(s_ctx.m_allocator, _ptr);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void OcornutImguiContext::renderDrawLists(ImDrawData* _drawData)
|
|
|
|
|
{
|
|
|
|
|
s_ctx.render(_drawData);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void imguiCreate(float _fontSize, bx::AllocatorI* _allocator)
|
|
|
|
|
{
|
|
|
|
|
s_ctx.create(_fontSize, _allocator);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void imguiDestroy()
|
|
|
|
|
{
|
|
|
|
|
s_ctx.destroy();
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar, bgfx::ViewId _viewId)
|
|
|
|
|
{
|
|
|
|
|
s_ctx.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _viewId);
|
|
|
|
|
}
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
|
|
void imguiEndFrame()
|
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
s_ctx.endFrame();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
namespace ImGui
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
void PushFont(Font::Enum _font)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
|
PushFont(s_ctx.m_font[_font]);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
}
|
2018-02-03 17:39:28 +01:00
|
|
|
|
} // namespace ImGui
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4505); // error C4505: '' : unreferenced local function has been removed
|
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wunused-function"); // warning: ‘int rect_width_compare(const void*, const void*)’ defined but not used
|
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_PUSH();
|
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunknown-pragmas")
|
|
|
|
|
//BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wunused-but-set-variable"); // warning: variable ‘L1’ set but not used
|
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wtype-limits"); // warning: comparison is always true due to limited range of data type
|
|
|
|
|
#define STBTT_malloc(_size, _userData) memAlloc(_size)
|
|
|
|
|
#define STBTT_free(_ptr, _userData) memFree(_ptr)
|
|
|
|
|
#define STB_RECT_PACK_IMPLEMENTATION
|
|
|
|
|
#include <stb/stb_rect_pack.h>
|
|
|
|
|
#define STB_TRUETYPE_IMPLEMENTATION
|
|
|
|
|
#include <stb/stb_truetype.h>
|
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_POP();
|