diff options
author | 2023-01-04 23:29:18 -0500 | |
---|---|---|
committer | 2023-01-04 23:29:18 -0500 | |
commit | 94b1e168b2b97b48b81f7a8f64406b0a6f64184e (patch) | |
tree | f57362a0fa01bfe8f0ad75a447c4c9e10bc15756 /3rdparty/bgfx/examples/common/imgui/imgui.cpp | |
parent | 5581eaa50a42256242f32569f59ce10d70ddd8c2 (diff) |
Revert "Update BGFX, BX and BIMG (#10750)" (#10787)
This reverts commit 5581eaa50a42256242f32569f59ce10d70ddd8c2 due to link failure on macOS.
Diffstat (limited to '3rdparty/bgfx/examples/common/imgui/imgui.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/imgui.cpp | 175 |
1 files changed, 52 insertions, 123 deletions
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp index 951c118ed76..4cf1c4f104f 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp @@ -1,6 +1,6 @@ /* * Copyright 2014-2015 Daniel Collin. All rights reserved. - * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ #include <bgfx/bgfx.h> @@ -117,6 +117,7 @@ struct OcornutImguiContext bgfx::Encoder* encoder = bgfx::begin(); + uint32_t offset = 0; for (const ImDrawCmd* cmd = drawList->CmdBuffer.begin(), *cmdEnd = drawList->CmdBuffer.end(); cmd != cmdEnd; ++cmd) { if (cmd->UserCallback) @@ -175,11 +176,13 @@ struct OcornutImguiContext encoder->setState(state); encoder->setTexture(0, s_tex, th); - encoder->setVertexBuffer(0, &tvb, cmd->VtxOffset, numVertices); - encoder->setIndexBuffer(&tib, cmd->IdxOffset, cmd->ElemCount); + encoder->setVertexBuffer(0, &tvb, 0, numVertices); + encoder->setIndexBuffer(&tib, offset, cmd->ElemCount); encoder->submit(m_viewId, program); } } + + offset += cmd->ElemCount; } bgfx::end(encoder); @@ -212,119 +215,50 @@ struct OcornutImguiContext setupStyle(true); - io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; - #if USE_ENTRY - for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii) - { - m_keyMap[ii] = ImGuiKey_None; - } - - m_keyMap[entry::Key::Esc] = ImGuiKey_Escape; - m_keyMap[entry::Key::Return] = ImGuiKey_Enter; - m_keyMap[entry::Key::Tab] = ImGuiKey_Tab; - m_keyMap[entry::Key::Space] = ImGuiKey_Space; - m_keyMap[entry::Key::Backspace] = ImGuiKey_Backspace; - m_keyMap[entry::Key::Up] = ImGuiKey_UpArrow; - m_keyMap[entry::Key::Down] = ImGuiKey_DownArrow; - m_keyMap[entry::Key::Left] = ImGuiKey_LeftArrow; - m_keyMap[entry::Key::Right] = ImGuiKey_RightArrow; - m_keyMap[entry::Key::Insert] = ImGuiKey_Insert; - m_keyMap[entry::Key::Delete] = ImGuiKey_Delete; - m_keyMap[entry::Key::Home] = ImGuiKey_Home; - m_keyMap[entry::Key::End] = ImGuiKey_End; - m_keyMap[entry::Key::PageUp] = ImGuiKey_PageUp; - m_keyMap[entry::Key::PageDown] = ImGuiKey_PageDown; - m_keyMap[entry::Key::Print] = ImGuiKey_PrintScreen; - m_keyMap[entry::Key::Plus] = ImGuiKey_Equal; - m_keyMap[entry::Key::Minus] = ImGuiKey_Minus; - m_keyMap[entry::Key::LeftBracket] = ImGuiKey_LeftBracket; - m_keyMap[entry::Key::RightBracket] = ImGuiKey_RightBracket; - m_keyMap[entry::Key::Semicolon] = ImGuiKey_Semicolon; - m_keyMap[entry::Key::Quote] = ImGuiKey_Apostrophe; - m_keyMap[entry::Key::Comma] = ImGuiKey_Comma; - m_keyMap[entry::Key::Period] = ImGuiKey_Period; - m_keyMap[entry::Key::Slash] = ImGuiKey_Slash; - m_keyMap[entry::Key::Backslash] = ImGuiKey_Backslash; - m_keyMap[entry::Key::Tilde] = ImGuiKey_GraveAccent; - m_keyMap[entry::Key::F1] = ImGuiKey_F1; - m_keyMap[entry::Key::F2] = ImGuiKey_F2; - m_keyMap[entry::Key::F3] = ImGuiKey_F3; - m_keyMap[entry::Key::F4] = ImGuiKey_F4; - m_keyMap[entry::Key::F5] = ImGuiKey_F5; - m_keyMap[entry::Key::F6] = ImGuiKey_F6; - m_keyMap[entry::Key::F7] = ImGuiKey_F7; - m_keyMap[entry::Key::F8] = ImGuiKey_F8; - m_keyMap[entry::Key::F9] = ImGuiKey_F9; - m_keyMap[entry::Key::F10] = ImGuiKey_F10; - m_keyMap[entry::Key::F11] = ImGuiKey_F11; - m_keyMap[entry::Key::F12] = ImGuiKey_F12; - m_keyMap[entry::Key::NumPad0] = ImGuiKey_Keypad0; - m_keyMap[entry::Key::NumPad1] = ImGuiKey_Keypad1; - m_keyMap[entry::Key::NumPad2] = ImGuiKey_Keypad2; - m_keyMap[entry::Key::NumPad3] = ImGuiKey_Keypad3; - m_keyMap[entry::Key::NumPad4] = ImGuiKey_Keypad4; - m_keyMap[entry::Key::NumPad5] = ImGuiKey_Keypad5; - m_keyMap[entry::Key::NumPad6] = ImGuiKey_Keypad6; - m_keyMap[entry::Key::NumPad7] = ImGuiKey_Keypad7; - m_keyMap[entry::Key::NumPad8] = ImGuiKey_Keypad8; - m_keyMap[entry::Key::NumPad9] = ImGuiKey_Keypad9; - m_keyMap[entry::Key::Key0] = ImGuiKey_0; - m_keyMap[entry::Key::Key1] = ImGuiKey_1; - m_keyMap[entry::Key::Key2] = ImGuiKey_2; - m_keyMap[entry::Key::Key3] = ImGuiKey_3; - m_keyMap[entry::Key::Key4] = ImGuiKey_4; - m_keyMap[entry::Key::Key5] = ImGuiKey_5; - m_keyMap[entry::Key::Key6] = ImGuiKey_6; - m_keyMap[entry::Key::Key7] = ImGuiKey_7; - m_keyMap[entry::Key::Key8] = ImGuiKey_8; - m_keyMap[entry::Key::Key9] = ImGuiKey_9; - m_keyMap[entry::Key::KeyA] = ImGuiKey_A; - m_keyMap[entry::Key::KeyB] = ImGuiKey_B; - m_keyMap[entry::Key::KeyC] = ImGuiKey_C; - m_keyMap[entry::Key::KeyD] = ImGuiKey_D; - m_keyMap[entry::Key::KeyE] = ImGuiKey_E; - m_keyMap[entry::Key::KeyF] = ImGuiKey_F; - m_keyMap[entry::Key::KeyG] = ImGuiKey_G; - m_keyMap[entry::Key::KeyH] = ImGuiKey_H; - m_keyMap[entry::Key::KeyI] = ImGuiKey_I; - m_keyMap[entry::Key::KeyJ] = ImGuiKey_J; - m_keyMap[entry::Key::KeyK] = ImGuiKey_K; - m_keyMap[entry::Key::KeyL] = ImGuiKey_L; - m_keyMap[entry::Key::KeyM] = ImGuiKey_M; - m_keyMap[entry::Key::KeyN] = ImGuiKey_N; - m_keyMap[entry::Key::KeyO] = ImGuiKey_O; - m_keyMap[entry::Key::KeyP] = ImGuiKey_P; - m_keyMap[entry::Key::KeyQ] = ImGuiKey_Q; - m_keyMap[entry::Key::KeyR] = ImGuiKey_R; - m_keyMap[entry::Key::KeyS] = ImGuiKey_S; - m_keyMap[entry::Key::KeyT] = ImGuiKey_T; - m_keyMap[entry::Key::KeyU] = ImGuiKey_U; - m_keyMap[entry::Key::KeyV] = ImGuiKey_V; - m_keyMap[entry::Key::KeyW] = ImGuiKey_W; - m_keyMap[entry::Key::KeyX] = ImGuiKey_X; - m_keyMap[entry::Key::KeyY] = ImGuiKey_Y; - m_keyMap[entry::Key::KeyZ] = ImGuiKey_Z; + 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_PageUp] = (int)entry::Key::PageUp; + io.KeyMap[ImGuiKey_PageDown] = (int)entry::Key::PageDown; + io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home; + io.KeyMap[ImGuiKey_End] = (int)entry::Key::End; + io.KeyMap[ImGuiKey_Insert] = (int)entry::Key::Insert; + io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete; + io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace; + io.KeyMap[ImGuiKey_Space] = (int)entry::Key::Space; + 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; io.ConfigFlags |= 0 | ImGuiConfigFlags_NavEnableGamepad | ImGuiConfigFlags_NavEnableKeyboard ; - m_keyMap[entry::Key::GamepadStart] = ImGuiKey_GamepadStart; - m_keyMap[entry::Key::GamepadBack] = ImGuiKey_GamepadBack; - m_keyMap[entry::Key::GamepadY] = ImGuiKey_GamepadFaceUp; - m_keyMap[entry::Key::GamepadA] = ImGuiKey_GamepadFaceDown; - m_keyMap[entry::Key::GamepadX] = ImGuiKey_GamepadFaceLeft; - m_keyMap[entry::Key::GamepadB] = ImGuiKey_GamepadFaceRight; - m_keyMap[entry::Key::GamepadUp] = ImGuiKey_GamepadDpadUp; - m_keyMap[entry::Key::GamepadDown] = ImGuiKey_GamepadDpadDown; - m_keyMap[entry::Key::GamepadLeft] = ImGuiKey_GamepadDpadLeft; - m_keyMap[entry::Key::GamepadRight] = ImGuiKey_GamepadDpadRight; - m_keyMap[entry::Key::GamepadShoulderL] = ImGuiKey_GamepadL1; - m_keyMap[entry::Key::GamepadShoulderR] = ImGuiKey_GamepadR1; - m_keyMap[entry::Key::GamepadThumbL] = ImGuiKey_GamepadL3; - m_keyMap[entry::Key::GamepadThumbR] = ImGuiKey_GamepadR3; + io.NavInputs[ImGuiNavInput_Activate] = (int)entry::Key::GamepadA; + io.NavInputs[ImGuiNavInput_Cancel] = (int)entry::Key::GamepadB; +// io.NavInputs[ImGuiNavInput_Input] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_Menu] = (int)entry::Key::; + io.NavInputs[ImGuiNavInput_DpadLeft] = (int)entry::Key::GamepadLeft; + io.NavInputs[ImGuiNavInput_DpadRight] = (int)entry::Key::GamepadRight; + io.NavInputs[ImGuiNavInput_DpadUp] = (int)entry::Key::GamepadUp; + io.NavInputs[ImGuiNavInput_DpadDown] = (int)entry::Key::GamepadDown; +// io.NavInputs[ImGuiNavInput_LStickLeft] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_LStickRight] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_LStickUp] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_LStickDown] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_FocusPrev] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_FocusNext] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_TweakSlow] = (int)entry::Key::; +// io.NavInputs[ImGuiNavInput_TweakFast] = (int)entry::Key::; #endif // USE_ENTRY bgfx::RendererType::Enum type = bgfx::getRendererType(); @@ -454,23 +388,21 @@ struct OcornutImguiContext const double freq = double(bx::getHPFrequency() ); io.DeltaTime = float(frameTime/freq); - io.AddMousePosEvent( (float)_mx, (float)_my); - io.AddMouseButtonEvent(ImGuiMouseButton_Left, 0 != (_button & IMGUI_MBUT_LEFT ) ); - io.AddMouseButtonEvent(ImGuiMouseButton_Right, 0 != (_button & IMGUI_MBUT_RIGHT ) ); - io.AddMouseButtonEvent(ImGuiMouseButton_Middle, 0 != (_button & IMGUI_MBUT_MIDDLE) ); - io.AddMouseWheelEvent(0.0f, (float)(_scroll - m_lastScroll) ); + 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; #if USE_ENTRY uint8_t modifiers = inputGetModifiersState(); - io.AddKeyEvent(ImGuiKey_ModShift, 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) ) ); - io.AddKeyEvent(ImGuiKey_ModCtrl, 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) ) ); - io.AddKeyEvent(ImGuiKey_ModAlt, 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) ) ); - io.AddKeyEvent(ImGuiKey_ModSuper, 0 != (modifiers & (entry::Modifier::LeftMeta | entry::Modifier::RightMeta ) ) ); + 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) { - io.AddKeyEvent(m_keyMap[ii], inputGetKeyState(entry::Key::Enum(ii) ) ); - io.SetKeyEventNativeData(m_keyMap[ii], 0, 0, ii); + io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) ); } #endif // USE_ENTRY @@ -497,9 +429,6 @@ struct OcornutImguiContext int64_t m_last; int32_t m_lastScroll; bgfx::ViewId m_viewId; -#if USE_ENTRY - ImGuiKey m_keyMap[(int)entry::Key::Count]; -#endif // USE_ENTRY }; static OcornutImguiContext s_ctx; |