mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-12-23 03:11:49 +01:00
Update to Dear ImGui v1.89.3
This commit is contained in:
parent
38f9bde54b
commit
a49a56197b
@ -7,7 +7,9 @@ AlignConsecutiveAssignments: true
|
|||||||
AlignConsecutiveDeclarations: false
|
AlignConsecutiveDeclarations: false
|
||||||
AlignEscapedNewlinesLeft: false
|
AlignEscapedNewlinesLeft: false
|
||||||
AlignOperands: true
|
AlignOperands: true
|
||||||
AlignTrailingComments: true
|
AlignTrailingComments:
|
||||||
|
Kind: Always
|
||||||
|
OverEmptyLines: 0
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortBlocksOnASingleLine: false
|
AllowShortBlocksOnASingleLine: false
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
6
Makefile
6
Makefile
@ -18,12 +18,11 @@ all-classic: nds 3dsx-classic nro-classic linux
|
|||||||
|
|
||||||
format:
|
format:
|
||||||
@clang-format -style=file -i $(filter-out \
|
@clang-format -style=file -i $(filter-out \
|
||||||
|
include/imconfig.h \
|
||||||
include/imgui.h \
|
include/imgui.h \
|
||||||
source/imgui/imgui.cpp \
|
source/imgui/imgui.cpp \
|
||||||
source/imgui/imgui_demo.cpp \
|
|
||||||
source/imgui/imgui_draw.cpp \
|
source/imgui/imgui_draw.cpp \
|
||||||
source/imgui/imgui_internal.h \
|
source/imgui/imgui_internal.h \
|
||||||
source/imgui/imgui_internal.h, \
|
|
||||||
source/imgui/imgui_tables.cpp \
|
source/imgui/imgui_tables.cpp \
|
||||||
source/imgui/imgui_widgets.cpp \
|
source/imgui/imgui_widgets.cpp \
|
||||||
source/imgui/imstb_rectpack.h \
|
source/imgui/imstb_rectpack.h \
|
||||||
@ -36,7 +35,8 @@ format:
|
|||||||
source/linux/imgui_impl_glfw.h \
|
source/linux/imgui_impl_glfw.h \
|
||||||
source/linux/imgui_impl_opengl3.cpp \
|
source/linux/imgui_impl_opengl3.cpp \
|
||||||
source/linux/imgui_impl_opengl3.h \
|
source/linux/imgui_impl_opengl3.h \
|
||||||
$(shell find source include -type f -name \*.c -o -name \*.cpp -o -name \*.h))
|
source/linux/imgui_impl_opengl3_loader.h \
|
||||||
|
, $(shell find source include -type f -name \*.c -o -name \*.cpp -o -name \*.h))
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@$(MAKE) -f Makefile.nds clean
|
@$(MAKE) -f Makefile.nds clean
|
||||||
|
@ -52,7 +52,7 @@ RSF_FILE := meta/ftpd-classic-cia.rsf
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
APP_DESCRIPTION := v$(VERSION)
|
APP_DESCRIPTION := v$(VERSION)
|
||||||
APP_AUTHOR := (c) 2022 Michael Theall, Dave Murphy, TuxSH
|
APP_AUTHOR := (c) 2023 Michael Theall, Dave Murphy, TuxSH
|
||||||
|
|
||||||
ICON := meta/icon.png
|
ICON := meta/icon.png
|
||||||
BNR_IMAGE := meta/banner.png
|
BNR_IMAGE := meta/banner.png
|
||||||
@ -70,7 +70,6 @@ CFLAGS := -g -Wall $(OPTIMIZE) -mword-relocations \
|
|||||||
|
|
||||||
CFLAGS += $(INCLUDE) -DARM11 -D__3DS__ \
|
CFLAGS += $(INCLUDE) -DARM11 -D__3DS__ \
|
||||||
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
||||||
-DIMGUI_DISABLE_INCLUDE_IMCONFIG_H=1 \
|
|
||||||
-DNO_IPV6 -DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\"" \
|
-DNO_IPV6 -DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\"" \
|
||||||
-DANTI_ALIAS=1 \
|
-DANTI_ALIAS=1 \
|
||||||
`curl-config --cflags`
|
`curl-config --cflags`
|
||||||
|
@ -10,8 +10,6 @@ OXXFILES := $(patsubst source/%,$(BUILD)/%,$(CXXFILES:.cpp=.cpp.o))
|
|||||||
CPPFLAGS := -g -Wall -pthread -Iinclude -Isource/linux \
|
CPPFLAGS := -g -Wall -pthread -Iinclude -Isource/linux \
|
||||||
`pkg-config --cflags gl glfw3` \
|
`pkg-config --cflags gl glfw3` \
|
||||||
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
||||||
-DIMGUI_DISABLE_INCLUDE_IMCONFIG_H=1 \
|
|
||||||
-DIMGUI_IMPL_OPENGL_LOADER_GLAD=1 \
|
|
||||||
-DFTPDCONFIG="\"ftpd.cfg\"" \
|
-DFTPDCONFIG="\"ftpd.cfg\"" \
|
||||||
`curl-config --cflags`
|
`curl-config --cflags`
|
||||||
CFLAGS := $(CPPFLAGS)
|
CFLAGS := $(CPPFLAGS)
|
||||||
|
@ -35,7 +35,7 @@ NITRO :=
|
|||||||
# These set the information text in the nds file
|
# These set the information text in the nds file
|
||||||
GAME_TITLE := ftpd classic
|
GAME_TITLE := ftpd classic
|
||||||
GAME_SUBTITLE1 := v$(VERSION)
|
GAME_SUBTITLE1 := v$(VERSION)
|
||||||
GAME_SUBTITLE2 := (c) 2022 mtheall
|
GAME_SUBTITLE2 := (c) 2023 mtheall
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# options for code generation
|
# options for code generation
|
||||||
@ -46,7 +46,6 @@ ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
|
|||||||
CFLAGS := -g -Wall $(OPTIMIZE) \
|
CFLAGS := -g -Wall $(OPTIMIZE) \
|
||||||
$(ARCH) $(INCLUDE) -DARM9 -DNDS \
|
$(ARCH) $(INCLUDE) -DARM9 -DNDS \
|
||||||
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
||||||
-DIMGUI_DISABLE_INCLUDE_IMCONFIG_H=1 \
|
|
||||||
-DNO_IPV6 -DCLASSIC -DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\""
|
-DNO_IPV6 -DCLASSIC -DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\""
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++2a
|
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++2a
|
||||||
ASFLAGS := -g $(ARCH)
|
ASFLAGS := -g $(ARCH)
|
||||||
|
@ -37,7 +37,7 @@ include $(DEVKITPRO)/libnx/switch_rules
|
|||||||
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
|
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
|
||||||
# NACP building is skipped as well.
|
# NACP building is skipped as well.
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
APP_AUTHOR := (c) 2022 Michael Theall, Dave Murphy, TuxSH
|
APP_AUTHOR := (c) 2023 Michael Theall, Dave Murphy, TuxSH
|
||||||
ICON := meta/ftpd.jpg
|
ICON := meta/ftpd.jpg
|
||||||
APP_VERSION := $(VERSION)
|
APP_VERSION := $(VERSION)
|
||||||
|
|
||||||
@ -73,7 +73,6 @@ CFLAGS := -g -Wall -Wno-narrowing $(OPTIMIZE) \
|
|||||||
|
|
||||||
CFLAGS += $(INCLUDE) -D__SWITCH__ \
|
CFLAGS += $(INCLUDE) -D__SWITCH__ \
|
||||||
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
|
||||||
-DIMGUI_DISABLE_INCLUDE_IMCONFIG_H=1 \
|
|
||||||
-DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\"" \
|
-DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\"" \
|
||||||
`$(PREFIX)pkg-config --cflags libzstd` \
|
`$(PREFIX)pkg-config --cflags libzstd` \
|
||||||
`curl-config --cflags`
|
`curl-config --cflags`
|
||||||
|
120
include/imconfig.h
Normal file
120
include/imconfig.h
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
|
||||||
|
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||||
|
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||||
|
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||||
|
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||||
|
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||||
|
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//---- Define assertion handler. Defaults to calling assert().
|
||||||
|
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||||
|
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||||
|
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||||
|
|
||||||
|
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||||
|
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||||
|
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||||
|
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||||
|
//#define IMGUI_API __declspec( dllexport )
|
||||||
|
//#define IMGUI_API __declspec( dllimport )
|
||||||
|
|
||||||
|
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
|
||||||
|
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
|
||||||
|
|
||||||
|
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||||||
|
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
|
||||||
|
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||||
|
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
|
||||||
|
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).
|
||||||
|
|
||||||
|
//---- Don't implement some functions to reduce linkage requirements.
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||||
|
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
|
||||||
|
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||||
|
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||||
|
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||||
|
|
||||||
|
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||||
|
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||||
|
|
||||||
|
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||||
|
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||||
|
|
||||||
|
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||||
|
//#define IMGUI_USE_WCHAR32
|
||||||
|
|
||||||
|
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||||
|
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||||
|
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||||
|
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||||
|
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled
|
||||||
|
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
|
||||||
|
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||||
|
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
|
||||||
|
//#define IMGUI_USE_STB_SPRINTF
|
||||||
|
|
||||||
|
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||||
|
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||||
|
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE
|
||||||
|
|
||||||
|
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||||
|
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||||
|
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||||
|
|
||||||
|
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||||
|
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||||
|
/*
|
||||||
|
#define IM_VEC2_CLASS_EXTRA \
|
||||||
|
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
|
||||||
|
operator MyVec2() const { return MyVec2(x,y); }
|
||||||
|
|
||||||
|
#define IM_VEC4_CLASS_EXTRA \
|
||||||
|
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
|
||||||
|
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||||
|
*/
|
||||||
|
|
||||||
|
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||||
|
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||||
|
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||||
|
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||||
|
//#define ImDrawIdx unsigned int
|
||||||
|
|
||||||
|
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||||
|
//struct ImDrawList;
|
||||||
|
//struct ImDrawCmd;
|
||||||
|
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||||
|
//#define ImDrawCallback MyImDrawCallback
|
||||||
|
|
||||||
|
//---- Debug Tools: Macro to break in Debugger
|
||||||
|
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||||
|
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||||
|
//#define IM_DEBUG_BREAK __debugbreak()
|
||||||
|
|
||||||
|
//---- Debug Tools: Enable slower asserts
|
||||||
|
//#define IMGUI_DEBUG_PARANOID
|
||||||
|
|
||||||
|
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||||
|
/*
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
void MyFunction(const char* name, const MyMatrix44& v);
|
||||||
|
}
|
||||||
|
*/
|
1132
include/imgui.h
1132
include/imgui.h
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
|||||||
//
|
//
|
||||||
// The MIT License (MIT)
|
// The MIT License (MIT)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2020 Michael Theall
|
// Copyright (C) 2023 Michael Theall
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -397,6 +397,9 @@ void imgui::citro3d::init ()
|
|||||||
|
|
||||||
// build lookup table
|
// build lookup table
|
||||||
imFont->BuildLookupTable ();
|
imFont->BuildLookupTable ();
|
||||||
|
|
||||||
|
// tell imgui it is ready
|
||||||
|
atlas->TexReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void imgui::citro3d::exit ()
|
void imgui::citro3d::exit ()
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
//
|
//
|
||||||
// The MIT License (MIT)
|
// The MIT License (MIT)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2020 Michael Theall
|
// Copyright (C) 2023 Michael Theall
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -42,6 +42,9 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
#undef keysDown
|
||||||
|
#undef keysUp
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/// \brief Clipboard
|
/// \brief Clipboard
|
||||||
@ -72,7 +75,7 @@ void updateTouch (ImGuiIO &io_)
|
|||||||
if (hidKeysUp () & KEY_TOUCH)
|
if (hidKeysUp () & KEY_TOUCH)
|
||||||
{
|
{
|
||||||
// keep mouse position for one frame for release event
|
// keep mouse position for one frame for release event
|
||||||
io_.MouseDown[0] = false;
|
io_.AddMouseButtonEvent (0, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +83,8 @@ void updateTouch (ImGuiIO &io_)
|
|||||||
if (!(hidKeysHeld () & KEY_TOUCH))
|
if (!(hidKeysHeld () & KEY_TOUCH))
|
||||||
{
|
{
|
||||||
// set mouse cursor off-screen
|
// set mouse cursor off-screen
|
||||||
io_.MousePos = ImVec2 (-10.0f, -10.0f);
|
io_.AddMousePosEvent (-10.0f, -10.0f);
|
||||||
io_.MouseDown[0] = false;
|
io_.AddMouseButtonEvent (0, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,59 +93,59 @@ void updateTouch (ImGuiIO &io_)
|
|||||||
hidTouchRead (&pos);
|
hidTouchRead (&pos);
|
||||||
|
|
||||||
// transform to bottom-screen space
|
// transform to bottom-screen space
|
||||||
io_.MousePos = ImVec2 (pos.px + 40.0f, pos.py + 240.0f);
|
io_.AddMousePosEvent (pos.px + 40.0f, pos.py + 240.0f);
|
||||||
io_.MouseDown[0] = true;
|
io_.AddMouseButtonEvent (0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Update gamepad inputs
|
/// \brief Update gamepad inputs
|
||||||
/// \param io_ ImGui IO
|
/// \param io_ ImGui IO
|
||||||
void updateGamepads (ImGuiIO &io_)
|
void updateGamepads (ImGuiIO &io_)
|
||||||
{
|
{
|
||||||
// clear navigation inputs
|
|
||||||
std::memset (io_.NavInputs, 0, sizeof (io_.NavInputs));
|
|
||||||
|
|
||||||
auto const buttonMapping = {
|
auto const buttonMapping = {
|
||||||
std::make_pair (KEY_A, ImGuiNavInput_Activate),
|
// clang-format off
|
||||||
std::make_pair (KEY_B, ImGuiNavInput_Cancel),
|
std::make_pair (KEY_A, ImGuiKey_GamepadFaceDown), // A and B are swapped
|
||||||
std::make_pair (KEY_X, ImGuiNavInput_Input),
|
std::make_pair (KEY_B, ImGuiKey_GamepadFaceRight), // this is more intuitive
|
||||||
std::make_pair (KEY_Y, ImGuiNavInput_Menu),
|
std::make_pair (KEY_X, ImGuiKey_GamepadFaceUp),
|
||||||
std::make_pair (KEY_L, ImGuiNavInput_FocusPrev),
|
std::make_pair (KEY_Y, ImGuiKey_GamepadFaceLeft),
|
||||||
std::make_pair (KEY_L, ImGuiNavInput_TweakSlow),
|
std::make_pair (KEY_L, ImGuiKey_GamepadL1),
|
||||||
std::make_pair (KEY_ZL, ImGuiNavInput_FocusPrev),
|
std::make_pair (KEY_ZL, ImGuiKey_GamepadL1),
|
||||||
std::make_pair (KEY_ZL, ImGuiNavInput_TweakSlow),
|
std::make_pair (KEY_R, ImGuiKey_GamepadR1),
|
||||||
std::make_pair (KEY_R, ImGuiNavInput_FocusNext),
|
std::make_pair (KEY_ZR, ImGuiKey_GamepadR1),
|
||||||
std::make_pair (KEY_R, ImGuiNavInput_TweakFast),
|
std::make_pair (KEY_DUP, ImGuiKey_GamepadDpadUp),
|
||||||
std::make_pair (KEY_ZR, ImGuiNavInput_FocusNext),
|
std::make_pair (KEY_DRIGHT, ImGuiKey_GamepadDpadRight),
|
||||||
std::make_pair (KEY_ZR, ImGuiNavInput_TweakFast),
|
std::make_pair (KEY_DDOWN, ImGuiKey_GamepadDpadDown),
|
||||||
std::make_pair (KEY_DUP, ImGuiNavInput_DpadUp),
|
std::make_pair (KEY_DLEFT, ImGuiKey_GamepadDpadLeft),
|
||||||
std::make_pair (KEY_DRIGHT, ImGuiNavInput_DpadRight),
|
// clang-format on
|
||||||
std::make_pair (KEY_DDOWN, ImGuiNavInput_DpadDown),
|
|
||||||
std::make_pair (KEY_DLEFT, ImGuiNavInput_DpadLeft),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// read buttons from 3DS
|
// read buttons from 3DS
|
||||||
auto const keys = hidKeysHeld ();
|
auto const keysDown = hidKeysDown ();
|
||||||
|
auto const keysUp = hidKeysUp ();
|
||||||
for (auto const &[in, out] : buttonMapping)
|
for (auto const &[in, out] : buttonMapping)
|
||||||
{
|
{
|
||||||
if (keys & in)
|
if (keysUp & in)
|
||||||
io_.NavInputs[out] = 1.0f;
|
io_.AddKeyEvent (out, false);
|
||||||
|
else if (keysDown & in)
|
||||||
|
io_.AddKeyEvent (out, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update joystick
|
// update joystick
|
||||||
circlePosition cpad;
|
circlePosition cpad;
|
||||||
auto const analogMapping = {
|
auto const analogMapping = {
|
||||||
std::make_tuple (std::ref (cpad.dx), ImGuiNavInput_LStickLeft, -0.3f, -0.9f),
|
// clang-format off
|
||||||
std::make_tuple (std::ref (cpad.dx), ImGuiNavInput_LStickRight, +0.3f, +0.9f),
|
std::make_tuple (std::ref (cpad.dx), ImGuiKey_GamepadLStickLeft, -0.3f, -0.9f),
|
||||||
std::make_tuple (std::ref (cpad.dy), ImGuiNavInput_LStickUp, +0.3f, +0.9f),
|
std::make_tuple (std::ref (cpad.dx), ImGuiKey_GamepadLStickRight, +0.3f, +0.9f),
|
||||||
std::make_tuple (std::ref (cpad.dy), ImGuiNavInput_LStickDown, -0.3f, -0.9f),
|
std::make_tuple (std::ref (cpad.dy), ImGuiKey_GamepadLStickUp, +0.3f, +0.9f),
|
||||||
|
std::make_tuple (std::ref (cpad.dy), ImGuiKey_GamepadLStickDown, -0.3f, -0.9f),
|
||||||
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
// read left joystick from circle pad
|
// read left joystick from circle pad
|
||||||
hidCircleRead (&cpad);
|
hidCircleRead (&cpad);
|
||||||
for (auto const &[in, out, min, max] : analogMapping)
|
for (auto const &[in, out, min, max] : analogMapping)
|
||||||
{
|
{
|
||||||
auto const value = in / static_cast<float> (0x9C);
|
auto const value = std::clamp ((in / 156.0f - min) / (max - min), 0.0f, 1.0f);
|
||||||
io_.NavInputs[out] = std::clamp ((value - min) / (max - min), 0.0f, 1.0f);
|
io_.AddKeyAnalogEvent (out, value > 0.1f, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
|
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
|
||||||
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
|
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
|
||||||
//
|
//
|
||||||
// Copyright (C) 2022 Michael Theall
|
// Copyright (C) 2023 Michael Theall
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@ -215,7 +215,7 @@ void startNetwork ()
|
|||||||
aptSetSleepAllowed (false);
|
aptSetSleepAllowed (false);
|
||||||
|
|
||||||
Result res;
|
Result res;
|
||||||
if (R_FAILED (res = NDMU_EnterExclusiveState(NDM_EXCLUSIVE_STATE_INFRASTRUCTURE)))
|
if (R_FAILED (res = NDMU_EnterExclusiveState (NDM_EXCLUSIVE_STATE_INFRASTRUCTURE)))
|
||||||
error ("Failed to enter exclusive NDM state: 0x%lx\n", res);
|
error ("Failed to enter exclusive NDM state: 0x%lx\n", res);
|
||||||
else if (R_FAILED (res = NDMU_LockState ()))
|
else if (R_FAILED (res = NDMU_LockState ()))
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
|
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
|
||||||
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
|
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
|
||||||
//
|
//
|
||||||
// Copyright (C) 2022 Michael Theall
|
// Copyright (C) 2023 Michael Theall
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@ -52,7 +52,7 @@ using namespace std::chrono_literals;
|
|||||||
#define LOCKED(x) \
|
#define LOCKED(x) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
auto const lock = std::scoped_lock (m_lock); \
|
auto const lock = std::scoped_lock (m_lock); \
|
||||||
x; \
|
x; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
@ -84,7 +84,8 @@ std::string printable (char *const data_, std::size_t const size_)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
char buffer[5];
|
char buffer[5];
|
||||||
std::snprintf (buffer, sizeof (buffer), "%%%02u", static_cast<unsigned char> (data_[i]));
|
std::snprintf (
|
||||||
|
buffer, sizeof (buffer), "%%%02u", static_cast<unsigned char> (data_[i]));
|
||||||
result += buffer;
|
result += buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +93,11 @@ std::string printable (char *const data_, std::size_t const size_)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int curlDebug (CURL *const handle_, curl_infotype const type_, char *const data_, std::size_t const size_, void *const user_)
|
int curlDebug (CURL *const handle_,
|
||||||
|
curl_infotype const type_,
|
||||||
|
char *const data_,
|
||||||
|
std::size_t const size_,
|
||||||
|
void *const user_)
|
||||||
{
|
{
|
||||||
(void)user_;
|
(void)user_;
|
||||||
|
|
||||||
@ -136,14 +141,16 @@ int curlDebug (CURL *const handle_, curl_infotype const type_, char *const data_
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::size_t curlCallback (void *const contents_, std::size_t const size_, std::size_t const count_, void *const user_)
|
std::size_t curlCallback (void *const contents_,
|
||||||
|
std::size_t const size_,
|
||||||
|
std::size_t const count_,
|
||||||
|
void *const user_)
|
||||||
{
|
{
|
||||||
|
|
||||||
auto const total = size_ * count_;
|
auto const total = size_ * count_;
|
||||||
auto const start = static_cast<char*> (contents_);
|
auto const start = static_cast<char *> (contents_);
|
||||||
auto const end = start + total;
|
auto const end = start + total;
|
||||||
|
|
||||||
auto &result = *static_cast<std::string*> (user_);
|
auto &result = *static_cast<std::string *> (user_);
|
||||||
result.insert (std::end (result), start, end);
|
result.insert (std::end (result), start, end);
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
@ -462,7 +469,7 @@ void FtpServer::showMenu ()
|
|||||||
|
|
||||||
// set headers
|
// set headers
|
||||||
static char contentType[] = "Content-Type: multipart/form-data";
|
static char contentType[] = "Content-Type: multipart/form-data";
|
||||||
static curl_slist const headers = { contentType, nullptr };
|
static curl_slist const headers = {contentType, nullptr};
|
||||||
curl_easy_setopt (handle, CURLOPT_URL, "https://hastebin.com/documents");
|
curl_easy_setopt (handle, CURLOPT_URL, "https://hastebin.com/documents");
|
||||||
curl_easy_setopt (handle, CURLOPT_HTTPHEADER, &headers);
|
curl_easy_setopt (handle, CURLOPT_HTTPHEADER, &headers);
|
||||||
|
|
||||||
@ -705,7 +712,7 @@ void FtpServer::showAbout ()
|
|||||||
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize))
|
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize))
|
||||||
{
|
{
|
||||||
ImGui::TextUnformatted (STATUS_STRING);
|
ImGui::TextUnformatted (STATUS_STRING);
|
||||||
ImGui::TextWrapped ("Copyright © 2021 Michael Theall, Dave Murphy, TuxSH");
|
ImGui::TextWrapped ("Copyright © 2023 Michael Theall, Dave Murphy, TuxSH");
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::Text ("Platform: %s", io.BackendPlatformName);
|
ImGui::Text ("Platform: %s", io.BackendPlatformName);
|
||||||
ImGui::Text ("Renderer: %s", io.BackendRendererName);
|
ImGui::Text ("Renderer: %s", io.BackendRendererName);
|
||||||
@ -719,9 +726,9 @@ void FtpServer::showAbout ()
|
|||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
if (ImGui::TreeNode (g_dearImGuiVersion))
|
if (ImGui::TreeNode (g_dearImGuiVersion))
|
||||||
{
|
{
|
||||||
ImGui::TextWrapped (g_dearImGuiCopyright);
|
ImGui::TextWrapped ("%s", g_dearImGuiCopyright);
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::TextWrapped (g_mitLicense);
|
ImGui::TextWrapped ("%s", g_mitLicense);
|
||||||
ImGui::TreePop ();
|
ImGui::TreePop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,50 +736,50 @@ void FtpServer::showAbout ()
|
|||||||
#elif defined(__3DS__)
|
#elif defined(__3DS__)
|
||||||
if (ImGui::TreeNode (g_libctruVersion))
|
if (ImGui::TreeNode (g_libctruVersion))
|
||||||
{
|
{
|
||||||
ImGui::TextWrapped (g_zlibLicense);
|
ImGui::TextWrapped ("%s", g_zlibLicense);
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::TextWrapped (g_zlibLicense);
|
ImGui::TextWrapped ("%s", g_zlibLicense);
|
||||||
ImGui::TreePop ();
|
ImGui::TreePop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::TreeNode (g_citro3dVersion))
|
if (ImGui::TreeNode (g_citro3dVersion))
|
||||||
{
|
{
|
||||||
ImGui::TextWrapped (g_citro3dCopyright);
|
ImGui::TextWrapped ("%s", g_citro3dCopyright);
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::TextWrapped (g_zlibLicense);
|
ImGui::TextWrapped ("%s", g_zlibLicense);
|
||||||
ImGui::TreePop ();
|
ImGui::TreePop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__SWITCH__)
|
#elif defined(__SWITCH__)
|
||||||
if (ImGui::TreeNode (g_libnxVersion))
|
if (ImGui::TreeNode (g_libnxVersion))
|
||||||
{
|
{
|
||||||
ImGui::TextWrapped (g_libnxCopyright);
|
ImGui::TextWrapped ("%s", g_libnxCopyright);
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::TextWrapped (g_libnxLicense);
|
ImGui::TextWrapped ("%s", g_libnxLicense);
|
||||||
ImGui::TreePop ();
|
ImGui::TreePop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::TreeNode (g_deko3dVersion))
|
if (ImGui::TreeNode (g_deko3dVersion))
|
||||||
{
|
{
|
||||||
ImGui::TextWrapped (g_deko3dCopyright);
|
ImGui::TextWrapped ("%s", g_deko3dCopyright);
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::TextWrapped (g_zlibLicense);
|
ImGui::TextWrapped ("%s", g_zlibLicense);
|
||||||
ImGui::TreePop ();
|
ImGui::TreePop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::TreeNode (g_zstdVersion))
|
if (ImGui::TreeNode (g_zstdVersion))
|
||||||
{
|
{
|
||||||
ImGui::TextWrapped (g_zstdCopyright);
|
ImGui::TextWrapped ("%s", g_zstdCopyright);
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::TextWrapped (g_bsdLicense);
|
ImGui::TextWrapped ("%s", g_bsdLicense);
|
||||||
ImGui::TreePop ();
|
ImGui::TreePop ();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (ImGui::TreeNode (g_glfwVersion))
|
if (ImGui::TreeNode (g_glfwVersion))
|
||||||
{
|
{
|
||||||
ImGui::TextWrapped (g_glfwCopyright);
|
ImGui::TextWrapped ("%s", g_glfwCopyright);
|
||||||
ImGui::Separator ();
|
ImGui::Separator ();
|
||||||
ImGui::TextWrapped (g_zlibLicense);
|
ImGui::TextWrapped ("%s", g_zlibLicense);
|
||||||
ImGui::TreePop ();
|
ImGui::TreePop ();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -815,7 +822,7 @@ void FtpServer::loop ()
|
|||||||
auto const lock = std::scoped_lock (m_lock);
|
auto const lock = std::scoped_lock (m_lock);
|
||||||
if (m_uploadLogCurl.load (std::memory_order_relaxed))
|
if (m_uploadLogCurl.load (std::memory_order_relaxed))
|
||||||
{
|
{
|
||||||
int busy = 0;
|
int busy = 0;
|
||||||
auto const mc = curl_multi_perform (m_uploadLogCurlM, &busy);
|
auto const mc = curl_multi_perform (m_uploadLogCurlM, &busy);
|
||||||
if (mc != CURLM_OK)
|
if (mc != CURLM_OK)
|
||||||
{
|
{
|
||||||
@ -829,7 +836,7 @@ void FtpServer::loop ()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
auto const msg = curl_multi_info_read (m_uploadLogCurlM, &count);
|
auto const msg = curl_multi_info_read (m_uploadLogCurlM, &count);
|
||||||
if (msg && msg->msg == CURLMSG_DONE && msg->easy_handle == m_uploadLogCurl)
|
if (msg && msg->msg == CURLMSG_DONE && msg->easy_handle == m_uploadLogCurl)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ using namespace std::chrono_literals;
|
|||||||
#define LOCKED(x) \
|
#define LOCKED(x) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
auto const lock = std::scoped_lock (m_lock); \
|
auto const lock = std::scoped_lock (m_lock); \
|
||||||
x; \
|
x; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,19 @@
|
|||||||
// [DEAR IMGUI]
|
// [DEAR IMGUI]
|
||||||
// This is a slightly modified version of stb_rect_pack.h 1.00.
|
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||||
// Those changes would need to be pushed into nothings/stb:
|
|
||||||
// - Added STBRP__CDECL
|
|
||||||
// Grep for [DEAR IMGUI] to find the changes.
|
// Grep for [DEAR IMGUI] to find the changes.
|
||||||
|
//
|
||||||
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
|
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||||
// Sean Barrett 2014
|
// Sean Barrett 2014
|
||||||
//
|
//
|
||||||
// Useful for e.g. packing rectangular textures into an atlas.
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
// Does not do rotation.
|
// Does not do rotation.
|
||||||
//
|
//
|
||||||
|
// Before #including,
|
||||||
|
//
|
||||||
|
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
//
|
||||||
|
// in the file that you want to have the implementation.
|
||||||
|
//
|
||||||
// Not necessarily the awesomest packing method, but better than
|
// Not necessarily the awesomest packing method, but better than
|
||||||
// the totally naive one in stb_truetype (which is primarily what
|
// the totally naive one in stb_truetype (which is primarily what
|
||||||
// this is meant to replace).
|
// this is meant to replace).
|
||||||
@ -41,6 +45,7 @@
|
|||||||
//
|
//
|
||||||
// Version history:
|
// Version history:
|
||||||
//
|
//
|
||||||
|
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||||
// 0.99 (2019-02-07) warning fixes
|
// 0.99 (2019-02-07) warning fixes
|
||||||
// 0.11 (2017-03-03) return packing success/fail result
|
// 0.11 (2017-03-03) return packing success/fail result
|
||||||
@ -81,11 +86,10 @@ typedef struct stbrp_context stbrp_context;
|
|||||||
typedef struct stbrp_node stbrp_node;
|
typedef struct stbrp_node stbrp_node;
|
||||||
typedef struct stbrp_rect stbrp_rect;
|
typedef struct stbrp_rect stbrp_rect;
|
||||||
|
|
||||||
#ifdef STBRP_LARGE_RECTS
|
|
||||||
typedef int stbrp_coord;
|
typedef int stbrp_coord;
|
||||||
#else
|
|
||||||
typedef unsigned short stbrp_coord;
|
#define STBRP__MAXVAL 0x7fffffff
|
||||||
#endif
|
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||||
|
|
||||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||||
// Assign packed locations to rectangles. The rectangles are of type
|
// Assign packed locations to rectangles. The rectangles are of type
|
||||||
@ -213,10 +217,9 @@ struct stbrp_context
|
|||||||
#define STBRP_ASSERT assert
|
#define STBRP_ASSERT assert
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// [DEAR IMGUI] Added STBRP__CDECL
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define STBRP__NOTUSED(v) (void)(v)
|
#define STBRP__NOTUSED(v) (void)(v)
|
||||||
#define STBRP__CDECL __cdecl
|
#define STBRP__CDECL __cdecl
|
||||||
#else
|
#else
|
||||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||||
#define STBRP__CDECL
|
#define STBRP__CDECL
|
||||||
@ -262,9 +265,6 @@ STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_ou
|
|||||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
#ifndef STBRP_LARGE_RECTS
|
|
||||||
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i=0; i < num_nodes-1; ++i)
|
for (i=0; i < num_nodes-1; ++i)
|
||||||
nodes[i].next = &nodes[i+1];
|
nodes[i].next = &nodes[i+1];
|
||||||
@ -283,11 +283,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
|
|||||||
context->extra[0].y = 0;
|
context->extra[0].y = 0;
|
||||||
context->extra[0].next = &context->extra[1];
|
context->extra[0].next = &context->extra[1];
|
||||||
context->extra[1].x = (stbrp_coord) width;
|
context->extra[1].x = (stbrp_coord) width;
|
||||||
#ifdef STBRP_LARGE_RECTS
|
|
||||||
context->extra[1].y = (1<<30);
|
context->extra[1].y = (1<<30);
|
||||||
#else
|
|
||||||
context->extra[1].y = 65535;
|
|
||||||
#endif
|
|
||||||
context->extra[1].next = NULL;
|
context->extra[1].next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,7 +429,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
|
|||||||
if (y <= best_y) {
|
if (y <= best_y) {
|
||||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||||
best_x = xpos;
|
best_x = xpos;
|
||||||
STBRP_ASSERT(y <= best_y);
|
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||||
best_y = y;
|
best_y = y;
|
||||||
best_waste = waste;
|
best_waste = waste;
|
||||||
best = prev;
|
best = prev;
|
||||||
@ -529,7 +525,6 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [DEAR IMGUI] Added STBRP__CDECL
|
|
||||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
@ -541,7 +536,6 @@ static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
|||||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [DEAR IMGUI] Added STBRP__CDECL
|
|
||||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
@ -549,12 +543,6 @@ static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
|||||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef STBRP_LARGE_RECTS
|
|
||||||
#define STBRP__MAXVAL 0xffffffff
|
|
||||||
#else
|
|
||||||
#define STBRP__MAXVAL 0xffff
|
|
||||||
#endif
|
|
||||||
|
|
||||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||||
{
|
{
|
||||||
int i, all_rects_packed = 1;
|
int i, all_rects_packed = 1;
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
// [DEAR IMGUI]
|
// [DEAR IMGUI]
|
||||||
// This is a slightly modified version of stb_textedit.h 1.13.
|
// This is a slightly modified version of stb_textedit.h 1.14.
|
||||||
// Those changes would need to be pushed into nothings/stb:
|
// Those changes would need to be pushed into nothings/stb:
|
||||||
// - Fix in stb_textedit_discard_redo (see https://github.com/nothings/stb/issues/321)
|
// - Fix in stb_textedit_discard_redo (see https://github.com/nothings/stb/issues/321)
|
||||||
|
// - Fix in stb_textedit_find_charpos to handle last line (see https://github.com/ocornut/imgui/issues/6000)
|
||||||
// Grep for [DEAR IMGUI] to find the changes.
|
// Grep for [DEAR IMGUI] to find the changes.
|
||||||
|
|
||||||
// stb_textedit.h - v1.13 - public domain - Sean Barrett
|
// stb_textedit.h - v1.14 - public domain - Sean Barrett
|
||||||
// Development of this library was sponsored by RAD Game Tools
|
// Development of this library was sponsored by RAD Game Tools
|
||||||
//
|
//
|
||||||
// This C header file implements the guts of a multi-line text-editing
|
// This C header file implements the guts of a multi-line text-editing
|
||||||
@ -35,6 +36,7 @@
|
|||||||
//
|
//
|
||||||
// VERSION HISTORY
|
// VERSION HISTORY
|
||||||
//
|
//
|
||||||
|
// 1.14 (2021-07-11) page up/down, various fixes
|
||||||
// 1.13 (2019-02-07) fix bug in undo size management
|
// 1.13 (2019-02-07) fix bug in undo size management
|
||||||
// 1.12 (2018-01-29) user can change STB_TEXTEDIT_KEYTYPE, fix redo to avoid crash
|
// 1.12 (2018-01-29) user can change STB_TEXTEDIT_KEYTYPE, fix redo to avoid crash
|
||||||
// 1.11 (2017-03-03) fix HOME on last line, dragging off single-line textfield
|
// 1.11 (2017-03-03) fix HOME on last line, dragging off single-line textfield
|
||||||
@ -58,6 +60,7 @@
|
|||||||
// Ulf Winklemann: move-by-word in 1.1
|
// Ulf Winklemann: move-by-word in 1.1
|
||||||
// Fabian Giesen: secondary key inputs in 1.5
|
// Fabian Giesen: secondary key inputs in 1.5
|
||||||
// Martins Mozeiko: STB_TEXTEDIT_memmove in 1.6
|
// Martins Mozeiko: STB_TEXTEDIT_memmove in 1.6
|
||||||
|
// Louis Schnellbach: page up/down in 1.14
|
||||||
//
|
//
|
||||||
// Bugfixes:
|
// Bugfixes:
|
||||||
// Scott Graham
|
// Scott Graham
|
||||||
@ -93,8 +96,8 @@
|
|||||||
// moderate sizes. The undo system does no memory allocations, so
|
// moderate sizes. The undo system does no memory allocations, so
|
||||||
// it grows STB_TexteditState by the worst-case storage which is (in bytes):
|
// it grows STB_TexteditState by the worst-case storage which is (in bytes):
|
||||||
//
|
//
|
||||||
// [4 + 3 * sizeof(STB_TEXTEDIT_POSITIONTYPE)] * STB_TEXTEDIT_UNDOSTATE_COUNT
|
// [4 + 3 * sizeof(STB_TEXTEDIT_POSITIONTYPE)] * STB_TEXTEDIT_UNDOSTATECOUNT
|
||||||
// + sizeof(STB_TEXTEDIT_CHARTYPE) * STB_TEXTEDIT_UNDOCHAR_COUNT
|
// + sizeof(STB_TEXTEDIT_CHARTYPE) * STB_TEXTEDIT_UNDOCHARCOUNT
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Implementation mode:
|
// Implementation mode:
|
||||||
@ -522,29 +525,14 @@ static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *s
|
|||||||
int z = STB_TEXTEDIT_STRINGLEN(str);
|
int z = STB_TEXTEDIT_STRINGLEN(str);
|
||||||
int i=0, first;
|
int i=0, first;
|
||||||
|
|
||||||
if (n == z) {
|
if (n == z && single_line) {
|
||||||
// if it's at the end, then find the last line -- simpler than trying to
|
// special case if it's at the end (may not be needed?)
|
||||||
// explicitly handle this case in the regular code
|
STB_TEXTEDIT_LAYOUTROW(&r, str, 0);
|
||||||
if (single_line) {
|
find->y = 0;
|
||||||
STB_TEXTEDIT_LAYOUTROW(&r, str, 0);
|
find->first_char = 0;
|
||||||
find->y = 0;
|
find->length = z;
|
||||||
find->first_char = 0;
|
find->height = r.ymax - r.ymin;
|
||||||
find->length = z;
|
find->x = r.x1;
|
||||||
find->height = r.ymax - r.ymin;
|
|
||||||
find->x = r.x1;
|
|
||||||
} else {
|
|
||||||
find->y = 0;
|
|
||||||
find->x = 0;
|
|
||||||
find->height = 1;
|
|
||||||
while (i < z) {
|
|
||||||
STB_TEXTEDIT_LAYOUTROW(&r, str, i);
|
|
||||||
prev_start = i;
|
|
||||||
i += r.num_chars;
|
|
||||||
}
|
|
||||||
find->first_char = i;
|
|
||||||
find->length = 0;
|
|
||||||
find->prev_first = prev_start;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,9 +543,13 @@ static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *s
|
|||||||
STB_TEXTEDIT_LAYOUTROW(&r, str, i);
|
STB_TEXTEDIT_LAYOUTROW(&r, str, i);
|
||||||
if (n < i + r.num_chars)
|
if (n < i + r.num_chars)
|
||||||
break;
|
break;
|
||||||
|
if (i + r.num_chars == z && z > 0 && STB_TEXTEDIT_GETCHAR(str, z - 1) != STB_TEXTEDIT_NEWLINE) // [DEAR IMGUI] special handling for last line
|
||||||
|
break; // [DEAR IMGUI]
|
||||||
prev_start = i;
|
prev_start = i;
|
||||||
i += r.num_chars;
|
i += r.num_chars;
|
||||||
find->y += r.baseline_y_delta;
|
find->y += r.baseline_y_delta;
|
||||||
|
if (i == z) // [DEAR IMGUI]
|
||||||
|
break; // [DEAR IMGUI]
|
||||||
}
|
}
|
||||||
|
|
||||||
find->first_char = first = i;
|
find->first_char = first = i;
|
||||||
@ -716,9 +708,7 @@ static int stb_textedit_paste_internal(STB_TEXTEDIT_STRING *str, STB_TexteditSta
|
|||||||
state->has_preferred_x = 0;
|
state->has_preferred_x = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// remove the undo since we didn't actually insert the characters
|
// note: paste failure will leave deleted selection, may be restored with an undo (see https://github.com/nothings/stb/issues/734 for details)
|
||||||
if (state->undostate.undo_point)
|
|
||||||
--state->undostate.undo_point;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
|||||||
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
|
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
|
||||||
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
|
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021 Michael Theall
|
// Copyright (C) 2023 Michael Theall
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@ -31,7 +31,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
char const *const g_dearImGuiVersion = "Dear ImGui " IMGUI_VERSION;
|
char const *const g_dearImGuiVersion = "Dear ImGui " IMGUI_VERSION;
|
||||||
char const *const g_dearImGuiCopyright = "Copyright (C) 2014-2021 Omar Cornut";
|
char const *const g_dearImGuiCopyright = "Copyright (C) 2014-2023 Omar Cornut";
|
||||||
|
|
||||||
char const *const g_mitLicense =
|
char const *const g_mitLicense =
|
||||||
"The MIT License (MIT)\n"
|
"The MIT License (MIT)\n"
|
||||||
|
@ -1,20 +1,41 @@
|
|||||||
// dear imgui: Platform Backend for GLFW
|
// dear imgui: Platform Backend for GLFW
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
||||||
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||||
// (Requires: GLFW 3.1+)
|
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ or GLFW 3.4+ for full feature support.)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Platform: Clipboard support.
|
// [X] Platform: Clipboard support.
|
||||||
|
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
||||||
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
||||||
// [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE).
|
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2023-02-03: Emscripten: Registering custom low-level mouse wheel handler to get more accurate scrolling impulses on Emscripten. (#4019, #6096)
|
||||||
|
// 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty.
|
||||||
|
// 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908)
|
||||||
|
// 2022-10-18: Perform a dummy glfwGetError() read to cancel missing mouse cursors errors. Using GLFW_VERSION_COMBINED directly. (#5785)
|
||||||
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
||||||
|
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
|
||||||
|
// 2022-09-01: Inputs: Honor GLFW_CURSOR_DISABLED by not setting mouse position.
|
||||||
|
// 2022-04-30: Inputs: Fixed ImGui_ImplGlfw_TranslateUntranslatedKey() for lower case letters on OSX.
|
||||||
|
// 2022-03-23: Inputs: Fixed a regression in 1.87 which resulted in keyboard modifiers events being reported incorrectly on Linux/X11.
|
||||||
|
// 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after initializing backend.
|
||||||
|
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
||||||
|
// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
|
||||||
|
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
||||||
|
// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
|
||||||
|
// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
|
||||||
|
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
||||||
|
// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
|
||||||
|
// 2021-08-17: *BREAKING CHANGE*: Now using glfwSetWindowFocusCallback() to calling io.AddFocusEvent(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() and forward it to the backend via ImGui_ImplGlfw_WindowFocusCallback().
|
||||||
|
// 2021-07-29: *BREAKING CHANGE*: Now using glfwSetCursorEnterCallback(). MousePos is correctly reported when the host platform window is hovered but not focused. If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() callback and forward it to the backend via ImGui_ImplGlfw_CursorEnterCallback().
|
||||||
|
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
||||||
// 2020-01-17: Inputs: Disable error callback while assigning mouse cursors because some X11 setup don't have them and it generates errors.
|
// 2020-01-17: Inputs: Disable error callback while assigning mouse cursors because some X11 setup don't have them and it generates errors.
|
||||||
// 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor).
|
// 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor).
|
||||||
// 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown.
|
// 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown.
|
||||||
@ -40,44 +61,86 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
|
|
||||||
|
// Clang warnings with -Weverything
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||||
|
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
||||||
|
#endif
|
||||||
|
|
||||||
// GLFW
|
// GLFW
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#undef APIENTRY
|
#undef APIENTRY
|
||||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
#include <GLFW/glfw3native.h> // for glfwGetWin32Window
|
#include <GLFW/glfw3native.h> // for glfwGetWin32Window()
|
||||||
#endif
|
#endif
|
||||||
#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ GLFW_FLOATING
|
#ifdef __APPLE__
|
||||||
#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_HOVERED
|
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||||
#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity
|
#include <GLFW/glfw3native.h> // for glfwGetCocoaWindow()
|
||||||
#define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorContentScale
|
|
||||||
#define GLFW_HAS_VULKAN (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwCreateWindowSurface
|
|
||||||
#ifdef GLFW_RESIZE_NESW_CURSOR // let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released?
|
|
||||||
#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR
|
|
||||||
#else
|
|
||||||
#define GLFW_HAS_NEW_CURSORS (0)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Data
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten.h>
|
||||||
|
#include <emscripten/html5.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// We gather version tests as define in order to easily see which features are version-dependent.
|
||||||
|
#define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION)
|
||||||
|
#ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released?
|
||||||
|
#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_COMBINED >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR
|
||||||
|
#else
|
||||||
|
#define GLFW_HAS_NEW_CURSORS (0)
|
||||||
|
#endif
|
||||||
|
#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetGamepadState() new api
|
||||||
|
#define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName()
|
||||||
|
|
||||||
|
// GLFW data
|
||||||
enum GlfwClientApi
|
enum GlfwClientApi
|
||||||
{
|
{
|
||||||
GlfwClientApi_Unknown,
|
GlfwClientApi_Unknown,
|
||||||
GlfwClientApi_OpenGL,
|
GlfwClientApi_OpenGL,
|
||||||
GlfwClientApi_Vulkan
|
GlfwClientApi_Vulkan
|
||||||
};
|
};
|
||||||
static GLFWwindow* g_Window = NULL; // Main window
|
|
||||||
static GlfwClientApi g_ClientApi = GlfwClientApi_Unknown;
|
|
||||||
static double g_Time = 0.0;
|
|
||||||
static bool g_MouseJustPressed[ImGuiMouseButton_COUNT] = {};
|
|
||||||
static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {};
|
|
||||||
static bool g_InstalledCallbacks = false;
|
|
||||||
|
|
||||||
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
struct ImGui_ImplGlfw_Data
|
||||||
static GLFWmousebuttonfun g_PrevUserCallbackMousebutton = NULL;
|
{
|
||||||
static GLFWscrollfun g_PrevUserCallbackScroll = NULL;
|
GLFWwindow* Window;
|
||||||
static GLFWkeyfun g_PrevUserCallbackKey = NULL;
|
GlfwClientApi ClientApi;
|
||||||
static GLFWcharfun g_PrevUserCallbackChar = NULL;
|
double Time;
|
||||||
|
GLFWwindow* MouseWindow;
|
||||||
|
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||||||
|
ImVec2 LastValidMousePos;
|
||||||
|
bool InstalledCallbacks;
|
||||||
|
bool CallbacksChainForAllWindows;
|
||||||
|
|
||||||
|
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
||||||
|
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
|
||||||
|
GLFWcursorposfun PrevUserCallbackCursorPos;
|
||||||
|
GLFWcursorenterfun PrevUserCallbackCursorEnter;
|
||||||
|
GLFWmousebuttonfun PrevUserCallbackMousebutton;
|
||||||
|
GLFWscrollfun PrevUserCallbackScroll;
|
||||||
|
GLFWkeyfun PrevUserCallbackKey;
|
||||||
|
GLFWcharfun PrevUserCallbackChar;
|
||||||
|
GLFWmonitorfun PrevUserCallbackMonitor;
|
||||||
|
|
||||||
|
ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
||||||
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||||
|
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
||||||
|
// - Because glfwPollEvents() process all windows and some events may be called outside of it, you will need to register your own callbacks
|
||||||
|
// (passing install_callbacks=false in ImGui_ImplGlfw_InitXXX functions), set the current dear imgui context and then call our callbacks.
|
||||||
|
// - Otherwise we may need to store a GLFWWindow* -> ImGuiContext* map and handle this in the backend, adding a little bit of extra complexity to it.
|
||||||
|
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
||||||
|
static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData()
|
||||||
|
{
|
||||||
|
return ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Functions
|
||||||
static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data)
|
static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data)
|
||||||
{
|
{
|
||||||
return glfwGetClipboardString((GLFWwindow*)user_data);
|
return glfwGetClipboardString((GLFWwindow*)user_data);
|
||||||
@ -88,139 +151,416 @@ static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text)
|
|||||||
glfwSetClipboardString((GLFWwindow*)user_data, text);
|
glfwSetClipboardString((GLFWwindow*)user_data, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case GLFW_KEY_TAB: return ImGuiKey_Tab;
|
||||||
|
case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow;
|
||||||
|
case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow;
|
||||||
|
case GLFW_KEY_UP: return ImGuiKey_UpArrow;
|
||||||
|
case GLFW_KEY_DOWN: return ImGuiKey_DownArrow;
|
||||||
|
case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp;
|
||||||
|
case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
|
||||||
|
case GLFW_KEY_HOME: return ImGuiKey_Home;
|
||||||
|
case GLFW_KEY_END: return ImGuiKey_End;
|
||||||
|
case GLFW_KEY_INSERT: return ImGuiKey_Insert;
|
||||||
|
case GLFW_KEY_DELETE: return ImGuiKey_Delete;
|
||||||
|
case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace;
|
||||||
|
case GLFW_KEY_SPACE: return ImGuiKey_Space;
|
||||||
|
case GLFW_KEY_ENTER: return ImGuiKey_Enter;
|
||||||
|
case GLFW_KEY_ESCAPE: return ImGuiKey_Escape;
|
||||||
|
case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||||
|
case GLFW_KEY_COMMA: return ImGuiKey_Comma;
|
||||||
|
case GLFW_KEY_MINUS: return ImGuiKey_Minus;
|
||||||
|
case GLFW_KEY_PERIOD: return ImGuiKey_Period;
|
||||||
|
case GLFW_KEY_SLASH: return ImGuiKey_Slash;
|
||||||
|
case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon;
|
||||||
|
case GLFW_KEY_EQUAL: return ImGuiKey_Equal;
|
||||||
|
case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket;
|
||||||
|
case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash;
|
||||||
|
case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket;
|
||||||
|
case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent;
|
||||||
|
case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock;
|
||||||
|
case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock;
|
||||||
|
case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock;
|
||||||
|
case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen;
|
||||||
|
case GLFW_KEY_PAUSE: return ImGuiKey_Pause;
|
||||||
|
case GLFW_KEY_KP_0: return ImGuiKey_Keypad0;
|
||||||
|
case GLFW_KEY_KP_1: return ImGuiKey_Keypad1;
|
||||||
|
case GLFW_KEY_KP_2: return ImGuiKey_Keypad2;
|
||||||
|
case GLFW_KEY_KP_3: return ImGuiKey_Keypad3;
|
||||||
|
case GLFW_KEY_KP_4: return ImGuiKey_Keypad4;
|
||||||
|
case GLFW_KEY_KP_5: return ImGuiKey_Keypad5;
|
||||||
|
case GLFW_KEY_KP_6: return ImGuiKey_Keypad6;
|
||||||
|
case GLFW_KEY_KP_7: return ImGuiKey_Keypad7;
|
||||||
|
case GLFW_KEY_KP_8: return ImGuiKey_Keypad8;
|
||||||
|
case GLFW_KEY_KP_9: return ImGuiKey_Keypad9;
|
||||||
|
case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal;
|
||||||
|
case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
||||||
|
case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
||||||
|
case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract;
|
||||||
|
case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd;
|
||||||
|
case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter;
|
||||||
|
case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual;
|
||||||
|
case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
|
||||||
|
case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
|
||||||
|
case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
|
||||||
|
case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper;
|
||||||
|
case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
|
||||||
|
case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl;
|
||||||
|
case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt;
|
||||||
|
case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper;
|
||||||
|
case GLFW_KEY_MENU: return ImGuiKey_Menu;
|
||||||
|
case GLFW_KEY_0: return ImGuiKey_0;
|
||||||
|
case GLFW_KEY_1: return ImGuiKey_1;
|
||||||
|
case GLFW_KEY_2: return ImGuiKey_2;
|
||||||
|
case GLFW_KEY_3: return ImGuiKey_3;
|
||||||
|
case GLFW_KEY_4: return ImGuiKey_4;
|
||||||
|
case GLFW_KEY_5: return ImGuiKey_5;
|
||||||
|
case GLFW_KEY_6: return ImGuiKey_6;
|
||||||
|
case GLFW_KEY_7: return ImGuiKey_7;
|
||||||
|
case GLFW_KEY_8: return ImGuiKey_8;
|
||||||
|
case GLFW_KEY_9: return ImGuiKey_9;
|
||||||
|
case GLFW_KEY_A: return ImGuiKey_A;
|
||||||
|
case GLFW_KEY_B: return ImGuiKey_B;
|
||||||
|
case GLFW_KEY_C: return ImGuiKey_C;
|
||||||
|
case GLFW_KEY_D: return ImGuiKey_D;
|
||||||
|
case GLFW_KEY_E: return ImGuiKey_E;
|
||||||
|
case GLFW_KEY_F: return ImGuiKey_F;
|
||||||
|
case GLFW_KEY_G: return ImGuiKey_G;
|
||||||
|
case GLFW_KEY_H: return ImGuiKey_H;
|
||||||
|
case GLFW_KEY_I: return ImGuiKey_I;
|
||||||
|
case GLFW_KEY_J: return ImGuiKey_J;
|
||||||
|
case GLFW_KEY_K: return ImGuiKey_K;
|
||||||
|
case GLFW_KEY_L: return ImGuiKey_L;
|
||||||
|
case GLFW_KEY_M: return ImGuiKey_M;
|
||||||
|
case GLFW_KEY_N: return ImGuiKey_N;
|
||||||
|
case GLFW_KEY_O: return ImGuiKey_O;
|
||||||
|
case GLFW_KEY_P: return ImGuiKey_P;
|
||||||
|
case GLFW_KEY_Q: return ImGuiKey_Q;
|
||||||
|
case GLFW_KEY_R: return ImGuiKey_R;
|
||||||
|
case GLFW_KEY_S: return ImGuiKey_S;
|
||||||
|
case GLFW_KEY_T: return ImGuiKey_T;
|
||||||
|
case GLFW_KEY_U: return ImGuiKey_U;
|
||||||
|
case GLFW_KEY_V: return ImGuiKey_V;
|
||||||
|
case GLFW_KEY_W: return ImGuiKey_W;
|
||||||
|
case GLFW_KEY_X: return ImGuiKey_X;
|
||||||
|
case GLFW_KEY_Y: return ImGuiKey_Y;
|
||||||
|
case GLFW_KEY_Z: return ImGuiKey_Z;
|
||||||
|
case GLFW_KEY_F1: return ImGuiKey_F1;
|
||||||
|
case GLFW_KEY_F2: return ImGuiKey_F2;
|
||||||
|
case GLFW_KEY_F3: return ImGuiKey_F3;
|
||||||
|
case GLFW_KEY_F4: return ImGuiKey_F4;
|
||||||
|
case GLFW_KEY_F5: return ImGuiKey_F5;
|
||||||
|
case GLFW_KEY_F6: return ImGuiKey_F6;
|
||||||
|
case GLFW_KEY_F7: return ImGuiKey_F7;
|
||||||
|
case GLFW_KEY_F8: return ImGuiKey_F8;
|
||||||
|
case GLFW_KEY_F9: return ImGuiKey_F9;
|
||||||
|
case GLFW_KEY_F10: return ImGuiKey_F10;
|
||||||
|
case GLFW_KEY_F11: return ImGuiKey_F11;
|
||||||
|
case GLFW_KEY_F12: return ImGuiKey_F12;
|
||||||
|
default: return ImGuiKey_None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// X11 does not include current pressed/released modifier key in 'mods' flags submitted by GLFW
|
||||||
|
// See https://github.com/ocornut/imgui/issues/6034 and https://github.com/glfw/glfw/issues/1630
|
||||||
|
static void ImGui_ImplGlfw_UpdateKeyModifiers()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
io.AddKeyEvent(ImGuiMod_Ctrl, (glfwGetKey(bd->Window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS));
|
||||||
|
io.AddKeyEvent(ImGuiMod_Shift, (glfwGetKey(bd->Window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS));
|
||||||
|
io.AddKeyEvent(ImGuiMod_Alt, (glfwGetKey(bd->Window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS));
|
||||||
|
io.AddKeyEvent(ImGuiMod_Super, (glfwGetKey(bd->Window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplGlfw_ShouldChainCallback(GLFWwindow* window)
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
return bd->CallbacksChainForAllWindows ? true : (window == bd->Window);
|
||||||
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
if (g_PrevUserCallbackMousebutton != NULL)
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
g_PrevUserCallbackMousebutton(window, button, action, mods);
|
if (bd->PrevUserCallbackMousebutton != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
||||||
|
bd->PrevUserCallbackMousebutton(window, button, action, mods);
|
||||||
|
|
||||||
if (action == GLFW_PRESS && button >= 0 && button < IM_ARRAYSIZE(g_MouseJustPressed))
|
ImGui_ImplGlfw_UpdateKeyModifiers();
|
||||||
g_MouseJustPressed[button] = true;
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (button >= 0 && button < ImGuiMouseButton_COUNT)
|
||||||
|
io.AddMouseButtonEvent(button, action == GLFW_PRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
if (g_PrevUserCallbackScroll != NULL)
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
g_PrevUserCallbackScroll(window, xoffset, yoffset);
|
if (bd->PrevUserCallbackScroll != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
||||||
|
bd->PrevUserCallbackScroll(window, xoffset, yoffset);
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
// Ignore GLFW events: will be processed in ImGui_ImplEmscripten_WheelCallback().
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.MouseWheelH += (float)xoffset;
|
io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
|
||||||
io.MouseWheel += (float)yoffset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
|
||||||
{
|
{
|
||||||
if (g_PrevUserCallbackKey != NULL)
|
#if GLFW_HAS_GETKEYNAME && !defined(__EMSCRIPTEN__)
|
||||||
g_PrevUserCallbackKey(window, key, scancode, action, mods);
|
// GLFW 3.1+ attempts to "untranslate" keys, which goes the opposite of what every other framework does, making using lettered shortcuts difficult.
|
||||||
|
// (It had reasons to do so: namely GLFW is/was more likely to be used for WASD-type game controls rather than lettered shortcuts, but IHMO the 3.1 change could have been done differently)
|
||||||
|
// See https://github.com/glfw/glfw/issues/1502 for details.
|
||||||
|
// Adding a workaround to undo this (so our keys are translated->untranslated->translated, likely a lossy process).
|
||||||
|
// This won't cover edge cases but this is at least going to cover common cases.
|
||||||
|
if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL)
|
||||||
|
return key;
|
||||||
|
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
|
||||||
|
const char* key_name = glfwGetKeyName(key, scancode);
|
||||||
|
glfwSetErrorCallback(prev_error_callback);
|
||||||
|
#if (GLFW_VERSION_COMBINED >= 3300) // Eat errors (see #5908)
|
||||||
|
(void)glfwGetError(NULL);
|
||||||
|
#endif
|
||||||
|
if (key_name && key_name[0] != 0 && key_name[1] == 0)
|
||||||
|
{
|
||||||
|
const char char_names[] = "`-=[]\\,;\'./";
|
||||||
|
const int char_keys[] = { GLFW_KEY_GRAVE_ACCENT, GLFW_KEY_MINUS, GLFW_KEY_EQUAL, GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_BACKSLASH, GLFW_KEY_COMMA, GLFW_KEY_SEMICOLON, GLFW_KEY_APOSTROPHE, GLFW_KEY_PERIOD, GLFW_KEY_SLASH, 0 };
|
||||||
|
IM_ASSERT(IM_ARRAYSIZE(char_names) == IM_ARRAYSIZE(char_keys));
|
||||||
|
if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); }
|
||||||
|
else if (key_name[0] >= 'A' && key_name[0] <= 'Z') { key = GLFW_KEY_A + (key_name[0] - 'A'); }
|
||||||
|
else if (key_name[0] >= 'a' && key_name[0] <= 'z') { key = GLFW_KEY_A + (key_name[0] - 'a'); }
|
||||||
|
else if (const char* p = strchr(char_names, key_name[0])) { key = char_keys[p - char_names]; }
|
||||||
|
}
|
||||||
|
// if (action == GLFW_PRESS) printf("key %d scancode %d name '%s'\n", key, scancode, key_name);
|
||||||
|
#else
|
||||||
|
IM_UNUSED(scancode);
|
||||||
|
#endif
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
if (bd->PrevUserCallbackKey != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
||||||
|
bd->PrevUserCallbackKey(window, keycode, scancode, action, mods);
|
||||||
|
|
||||||
|
if (action != GLFW_PRESS && action != GLFW_RELEASE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ImGui_ImplGlfw_UpdateKeyModifiers();
|
||||||
|
|
||||||
|
keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode);
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
if (key >= 0 && key < IM_ARRAYSIZE(io.KeysDown))
|
ImGuiKey imgui_key = ImGui_ImplGlfw_KeyToImGuiKey(keycode);
|
||||||
{
|
io.AddKeyEvent(imgui_key, (action == GLFW_PRESS));
|
||||||
if (action == GLFW_PRESS)
|
io.SetKeyEventNativeData(imgui_key, keycode, scancode); // To support legacy indexing (<1.87 user code)
|
||||||
io.KeysDown[key] = true;
|
}
|
||||||
if (action == GLFW_RELEASE)
|
|
||||||
io.KeysDown[key] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modifiers are not reliable across systems
|
void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
|
||||||
io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL];
|
{
|
||||||
io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT];
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT];
|
if (bd->PrevUserCallbackWindowFocus != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
||||||
#ifdef _WIN32
|
bd->PrevUserCallbackWindowFocus(window, focused);
|
||||||
io.KeySuper = false;
|
|
||||||
#else
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
|
io.AddFocusEvent(focused != 0);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
if (bd->PrevUserCallbackCursorPos != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
||||||
|
bd->PrevUserCallbackCursorPos(window, x, y);
|
||||||
|
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.AddMousePosEvent((float)x, (float)y);
|
||||||
|
bd->LastValidMousePos = ImVec2((float)x, (float)y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Workaround: X11 seems to send spurious Leave/Enter events which would make us lose our position,
|
||||||
|
// so we back it up and restore on Leave/Enter (see https://github.com/ocornut/imgui/issues/4984)
|
||||||
|
void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
if (bd->PrevUserCallbackCursorEnter != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
||||||
|
bd->PrevUserCallbackCursorEnter(window, entered);
|
||||||
|
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (entered)
|
||||||
|
{
|
||||||
|
bd->MouseWindow = window;
|
||||||
|
io.AddMousePosEvent(bd->LastValidMousePos.x, bd->LastValidMousePos.y);
|
||||||
|
}
|
||||||
|
else if (!entered && bd->MouseWindow == window)
|
||||||
|
{
|
||||||
|
bd->LastValidMousePos = io.MousePos;
|
||||||
|
bd->MouseWindow = nullptr;
|
||||||
|
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
|
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
|
||||||
{
|
{
|
||||||
if (g_PrevUserCallbackChar != NULL)
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
g_PrevUserCallbackChar(window, c);
|
if (bd->PrevUserCallbackChar != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
||||||
|
bd->PrevUserCallbackChar(window, c);
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.AddInputCharacter(c);
|
io.AddInputCharacter(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int)
|
||||||
|
{
|
||||||
|
// Unused in 'master' branch but 'docking' branch will use this, so we declare it ahead of it so if you have to install callbacks you can install this one too.
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
static EM_BOOL ImGui_ImplEmscripten_WheelCallback(int, const EmscriptenWheelEvent* ev, void*)
|
||||||
|
{
|
||||||
|
// Mimic Emscripten_HandleWheel() in SDL.
|
||||||
|
// Corresponding equivalent in GLFW JS emulation layer has incorrect quantizing preventing small values. See #6096
|
||||||
|
float multiplier = 0.0f;
|
||||||
|
if (ev->deltaMode == DOM_DELTA_PIXEL) { multiplier = 1.0f / 100.0f; } // 100 pixels make up a step.
|
||||||
|
else if (ev->deltaMode == DOM_DELTA_LINE) { multiplier = 1.0f / 3.0f; } // 3 lines make up a step.
|
||||||
|
else if (ev->deltaMode == DOM_DELTA_PAGE) { multiplier = 80.0f; } // A page makes up 80 steps.
|
||||||
|
float wheel_x = ev->deltaX * -multiplier;
|
||||||
|
float wheel_y = ev->deltaY * -multiplier;
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
||||||
|
//IMGUI_DEBUG_LOG("[Emsc] mode %d dx: %.2f, dy: %.2f, dz: %.2f --> feed %.2f %.2f\n", (int)ev->deltaMode, ev->deltaX, ev->deltaY, ev->deltaZ, wheel_x, wheel_y);
|
||||||
|
return EM_TRUE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
IM_ASSERT(bd->InstalledCallbacks == false && "Callbacks already installed!");
|
||||||
|
IM_ASSERT(bd->Window == window);
|
||||||
|
|
||||||
|
bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback);
|
||||||
|
bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback);
|
||||||
|
bd->PrevUserCallbackCursorPos = glfwSetCursorPosCallback(window, ImGui_ImplGlfw_CursorPosCallback);
|
||||||
|
bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
|
||||||
|
bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
|
||||||
|
bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
|
||||||
|
bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
|
||||||
|
bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback);
|
||||||
|
bd->InstalledCallbacks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window)
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
IM_ASSERT(bd->InstalledCallbacks == true && "Callbacks not installed!");
|
||||||
|
IM_ASSERT(bd->Window == window);
|
||||||
|
|
||||||
|
glfwSetWindowFocusCallback(window, bd->PrevUserCallbackWindowFocus);
|
||||||
|
glfwSetCursorEnterCallback(window, bd->PrevUserCallbackCursorEnter);
|
||||||
|
glfwSetCursorPosCallback(window, bd->PrevUserCallbackCursorPos);
|
||||||
|
glfwSetMouseButtonCallback(window, bd->PrevUserCallbackMousebutton);
|
||||||
|
glfwSetScrollCallback(window, bd->PrevUserCallbackScroll);
|
||||||
|
glfwSetKeyCallback(window, bd->PrevUserCallbackKey);
|
||||||
|
glfwSetCharCallback(window, bd->PrevUserCallbackChar);
|
||||||
|
glfwSetMonitorCallback(bd->PrevUserCallbackMonitor);
|
||||||
|
bd->InstalledCallbacks = false;
|
||||||
|
bd->PrevUserCallbackWindowFocus = nullptr;
|
||||||
|
bd->PrevUserCallbackCursorEnter = nullptr;
|
||||||
|
bd->PrevUserCallbackCursorPos = nullptr;
|
||||||
|
bd->PrevUserCallbackMousebutton = nullptr;
|
||||||
|
bd->PrevUserCallbackScroll = nullptr;
|
||||||
|
bd->PrevUserCallbackKey = nullptr;
|
||||||
|
bd->PrevUserCallbackChar = nullptr;
|
||||||
|
bd->PrevUserCallbackMonitor = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set to 'true' to enable chaining installed callbacks for all windows (including secondary viewports created by backends or by user.
|
||||||
|
// This is 'false' by default meaning we only chain callbacks for the main viewport.
|
||||||
|
// We cannot set this to 'true' by default because user callbacks code may be not testing the 'window' parameter of their callback.
|
||||||
|
// If you set this to 'true' your user callback code will need to make sure you are testing the 'window' parameter.
|
||||||
|
void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows)
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
bd->CallbacksChainForAllWindows = chain_for_all_windows;
|
||||||
|
}
|
||||||
|
|
||||||
static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
|
static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
|
||||||
{
|
{
|
||||||
g_Window = window;
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
g_Time = 0.0;
|
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
||||||
|
//printf("GLFW_VERSION: %d.%d.%d (%d)", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION, GLFW_VERSION_COMBINED);
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
// Setup backend capabilities flags
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
|
||||||
|
io.BackendPlatformUserData = (void*)bd;
|
||||||
|
io.BackendPlatformName = "imgui_impl_glfw";
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||||
io.BackendPlatformName = "imgui_impl_glfw";
|
|
||||||
|
|
||||||
// Keyboard mapping. Dear ImGui will use those indices to peek into the io.KeysDown[] array.
|
bd->Window = window;
|
||||||
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB;
|
bd->Time = 0.0;
|
||||||
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
|
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
|
||||||
io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
|
|
||||||
io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP;
|
|
||||||
io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN;
|
|
||||||
io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
|
|
||||||
io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
|
|
||||||
io.KeyMap[ImGuiKey_Insert] = GLFW_KEY_INSERT;
|
|
||||||
io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
|
|
||||||
io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
|
|
||||||
io.KeyMap[ImGuiKey_Space] = GLFW_KEY_SPACE;
|
|
||||||
io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
|
|
||||||
io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
|
|
||||||
io.KeyMap[ImGuiKey_KeyPadEnter] = GLFW_KEY_KP_ENTER;
|
|
||||||
io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
|
|
||||||
io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
|
|
||||||
io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
|
|
||||||
io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
|
|
||||||
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
|
||||||
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
|
||||||
|
|
||||||
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
||||||
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
||||||
io.ClipboardUserData = g_Window;
|
io.ClipboardUserData = bd->Window;
|
||||||
#if defined(_WIN32)
|
|
||||||
io.ImeWindowHandle = (void*)glfwGetWin32Window(g_Window);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Create mouse cursors
|
// Create mouse cursors
|
||||||
// (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
|
// (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
|
||||||
// GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
|
// GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
|
||||||
// Missing cursors will return NULL and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
|
// Missing cursors will return nullptr and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
|
||||||
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(NULL);
|
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
|
||||||
g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
|
||||||
#if GLFW_HAS_NEW_CURSORS
|
#if GLFW_HAS_NEW_CURSORS
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR);
|
||||||
#else
|
#else
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
g_MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
#endif
|
#endif
|
||||||
glfwSetErrorCallback(prev_error_callback);
|
glfwSetErrorCallback(prev_error_callback);
|
||||||
|
#if (GLFW_VERSION_COMBINED >= 3300) // Eat errors (see #5785)
|
||||||
|
(void)glfwGetError(NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
||||||
g_PrevUserCallbackMousebutton = NULL;
|
|
||||||
g_PrevUserCallbackScroll = NULL;
|
|
||||||
g_PrevUserCallbackKey = NULL;
|
|
||||||
g_PrevUserCallbackChar = NULL;
|
|
||||||
if (install_callbacks)
|
if (install_callbacks)
|
||||||
{
|
ImGui_ImplGlfw_InstallCallbacks(window);
|
||||||
g_InstalledCallbacks = true;
|
// Register Emscripten Wheel callback to workaround issue in Emscripten GLFW Emulation (#6096)
|
||||||
g_PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
|
// We intentionally do not check 'if (install_callbacks)' here, as some users may set it to false and call GLFW callback themselves.
|
||||||
g_PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
|
// FIXME: May break chaining in case user registered their own Emscripten callback?
|
||||||
g_PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
|
#ifdef __EMSCRIPTEN__
|
||||||
g_PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
|
emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, false, ImGui_ImplEmscripten_WheelCallback);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
g_ClientApi = client_api;
|
// Set platform dependent data in viewport
|
||||||
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
|
#ifdef _WIN32
|
||||||
|
main_viewport->PlatformHandleRaw = glfwGetWin32Window(bd->Window);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window);
|
||||||
|
#else
|
||||||
|
IM_UNUSED(main_viewport);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bd->ClientApi = client_api;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,53 +581,55 @@ bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks)
|
|||||||
|
|
||||||
void ImGui_ImplGlfw_Shutdown()
|
void ImGui_ImplGlfw_Shutdown()
|
||||||
{
|
{
|
||||||
if (g_InstalledCallbacks)
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
{
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
glfwSetMouseButtonCallback(g_Window, g_PrevUserCallbackMousebutton);
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
glfwSetScrollCallback(g_Window, g_PrevUserCallbackScroll);
|
|
||||||
glfwSetKeyCallback(g_Window, g_PrevUserCallbackKey);
|
if (bd->InstalledCallbacks)
|
||||||
glfwSetCharCallback(g_Window, g_PrevUserCallbackChar);
|
ImGui_ImplGlfw_RestoreCallbacks(bd->Window);
|
||||||
g_InstalledCallbacks = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||||
{
|
glfwDestroyCursor(bd->MouseCursors[cursor_n]);
|
||||||
glfwDestroyCursor(g_MouseCursors[cursor_n]);
|
|
||||||
g_MouseCursors[cursor_n] = NULL;
|
io.BackendPlatformName = nullptr;
|
||||||
}
|
io.BackendPlatformUserData = nullptr;
|
||||||
g_ClientApi = GlfwClientApi_Unknown;
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
|
static void ImGui_ImplGlfw_UpdateMouseData()
|
||||||
{
|
{
|
||||||
// Update buttons
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
|
|
||||||
|
if (glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||||
{
|
{
|
||||||
// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||||||
io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0;
|
return;
|
||||||
g_MouseJustPressed[i] = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update mouse position
|
// (those braces are here to reduce diff with multi-viewports support in 'docking' branch)
|
||||||
const ImVec2 mouse_pos_backup = io.MousePos;
|
|
||||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
const bool focused = true; // Emscripten
|
|
||||||
#else
|
|
||||||
const bool focused = glfwGetWindowAttrib(g_Window, GLFW_FOCUSED) != 0;
|
|
||||||
#endif
|
|
||||||
if (focused)
|
|
||||||
{
|
{
|
||||||
if (io.WantSetMousePos)
|
GLFWwindow* window = bd->Window;
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
const bool is_window_focused = true;
|
||||||
|
#else
|
||||||
|
const bool is_window_focused = glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0;
|
||||||
|
#endif
|
||||||
|
if (is_window_focused)
|
||||||
{
|
{
|
||||||
glfwSetCursorPos(g_Window, (double)mouse_pos_backup.x, (double)mouse_pos_backup.y);
|
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
||||||
}
|
if (io.WantSetMousePos)
|
||||||
else
|
glfwSetCursorPos(window, (double)io.MousePos.x, (double)io.MousePos.y);
|
||||||
{
|
|
||||||
double mouse_x, mouse_y;
|
// (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured)
|
||||||
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
|
if (bd->MouseWindow == nullptr)
|
||||||
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y);
|
{
|
||||||
|
double mouse_x, mouse_y;
|
||||||
|
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
||||||
|
bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y);
|
||||||
|
io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,83 +637,109 @@ static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
|
|||||||
static void ImGui_ImplGlfw_UpdateMouseCursor()
|
static void ImGui_ImplGlfw_UpdateMouseCursor()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(g_Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||||
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
// (those braces are here to reduce diff with multi-viewports support in 'docking' branch)
|
||||||
{
|
{
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
GLFWwindow* window = bd->Window;
|
||||||
glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
||||||
}
|
{
|
||||||
else
|
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||||
{
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
// Show OS mouse cursor
|
}
|
||||||
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
|
else
|
||||||
glfwSetCursor(g_Window, g_MouseCursors[imgui_cursor] ? g_MouseCursors[imgui_cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
|
{
|
||||||
glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
// Show OS mouse cursor
|
||||||
|
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
|
||||||
|
glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update gamepad inputs
|
||||||
|
static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
|
||||||
static void ImGui_ImplGlfw_UpdateGamepads()
|
static void ImGui_ImplGlfw_UpdateGamepads()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Update gamepad inputs
|
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||||
#define MAP_BUTTON(NAV_NO, BUTTON_NO) { if (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS) io.NavInputs[NAV_NO] = 1.0f; }
|
#if GLFW_HAS_GAMEPAD_API
|
||||||
#define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); if (v > 1.0f) v = 1.0f; if (io.NavInputs[NAV_NO] < v) io.NavInputs[NAV_NO] = v; }
|
GLFWgamepadstate gamepad;
|
||||||
|
if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad))
|
||||||
|
return;
|
||||||
|
#define MAP_BUTTON(KEY_NO, BUTTON_NO, _UNUSED) do { io.AddKeyEvent(KEY_NO, gamepad.buttons[BUTTON_NO] != 0); } while (0)
|
||||||
|
#define MAP_ANALOG(KEY_NO, AXIS_NO, _UNUSED, V0, V1) do { float v = gamepad.axes[AXIS_NO]; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
|
||||||
|
#else
|
||||||
int axes_count = 0, buttons_count = 0;
|
int axes_count = 0, buttons_count = 0;
|
||||||
const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
|
const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
|
||||||
const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
|
const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
|
||||||
MAP_BUTTON(ImGuiNavInput_Activate, 0); // Cross / A
|
if (axes_count == 0 || buttons_count == 0)
|
||||||
MAP_BUTTON(ImGuiNavInput_Cancel, 1); // Circle / B
|
return;
|
||||||
MAP_BUTTON(ImGuiNavInput_Menu, 2); // Square / X
|
#define MAP_BUTTON(KEY_NO, _UNUSED, BUTTON_NO) do { io.AddKeyEvent(KEY_NO, (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS)); } while (0)
|
||||||
MAP_BUTTON(ImGuiNavInput_Input, 3); // Triangle / Y
|
#define MAP_ANALOG(KEY_NO, _UNUSED, AXIS_NO, V0, V1) do { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadLeft, 13); // D-Pad Left
|
#endif
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadRight, 11); // D-Pad Right
|
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadUp, 10); // D-Pad Up
|
MAP_BUTTON(ImGuiKey_GamepadStart, GLFW_GAMEPAD_BUTTON_START, 7);
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadDown, 12); // D-Pad Down
|
MAP_BUTTON(ImGuiKey_GamepadBack, GLFW_GAMEPAD_BUTTON_BACK, 6);
|
||||||
MAP_BUTTON(ImGuiNavInput_FocusPrev, 4); // L1 / LB
|
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, GLFW_GAMEPAD_BUTTON_X, 2); // Xbox X, PS Square
|
||||||
MAP_BUTTON(ImGuiNavInput_FocusNext, 5); // R1 / RB
|
MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle
|
||||||
MAP_BUTTON(ImGuiNavInput_TweakSlow, 4); // L1 / LB
|
MAP_BUTTON(ImGuiKey_GamepadFaceUp, GLFW_GAMEPAD_BUTTON_Y, 3); // Xbox Y, PS Triangle
|
||||||
MAP_BUTTON(ImGuiNavInput_TweakFast, 5); // R1 / RB
|
MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickLeft, 0, -0.3f, -0.9f);
|
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, GLFW_GAMEPAD_BUTTON_DPAD_LEFT, 13);
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickRight,0, +0.3f, +0.9f);
|
MAP_BUTTON(ImGuiKey_GamepadDpadRight, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, 11);
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickUp, 1, +0.3f, +0.9f);
|
MAP_BUTTON(ImGuiKey_GamepadDpadUp, GLFW_GAMEPAD_BUTTON_DPAD_UP, 10);
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickDown, 1, -0.3f, -0.9f);
|
MAP_BUTTON(ImGuiKey_GamepadDpadDown, GLFW_GAMEPAD_BUTTON_DPAD_DOWN, 12);
|
||||||
|
MAP_BUTTON(ImGuiKey_GamepadL1, GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, 4);
|
||||||
|
MAP_BUTTON(ImGuiKey_GamepadR1, GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, 5);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadL2, GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, 4, -0.75f, +1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadR2, GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, 5, -0.75f, +1.0f);
|
||||||
|
MAP_BUTTON(ImGuiKey_GamepadL3, GLFW_GAMEPAD_BUTTON_LEFT_THUMB, 8);
|
||||||
|
MAP_BUTTON(ImGuiKey_GamepadR3, GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, 9);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, GLFW_GAMEPAD_AXIS_LEFT_X, 0, -0.25f, -1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadLStickRight, GLFW_GAMEPAD_AXIS_LEFT_X, 0, +0.25f, +1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadLStickUp, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, -0.25f, -1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadLStickDown, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, +0.25f, +1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, -0.25f, -1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadRStickRight, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, +0.25f, +1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadRStickUp, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, -0.25f, -1.0f);
|
||||||
|
MAP_ANALOG(ImGuiKey_GamepadRStickDown, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, +0.25f, +1.0f);
|
||||||
#undef MAP_BUTTON
|
#undef MAP_BUTTON
|
||||||
#undef MAP_ANALOG
|
#undef MAP_ANALOG
|
||||||
if (axes_count > 0 && buttons_count > 0)
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
|
||||||
else
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfw_NewFrame()
|
void ImGui_ImplGlfw_NewFrame()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer backend. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplOpenGL3_NewFrame().");
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplGlfw_InitForXXX()?");
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
// Setup display size (every frame to accommodate for window resizing)
|
||||||
int w, h;
|
int w, h;
|
||||||
int display_w, display_h;
|
int display_w, display_h;
|
||||||
glfwGetWindowSize(g_Window, &w, &h);
|
glfwGetWindowSize(bd->Window, &w, &h);
|
||||||
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||||
if (w > 0 && h > 0)
|
if (w > 0 && h > 0)
|
||||||
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);
|
||||||
|
|
||||||
// Setup time step
|
// Setup time step
|
||||||
double current_time = glfwGetTime();
|
double current_time = glfwGetTime();
|
||||||
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f / 60.0f);
|
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
|
||||||
g_Time = current_time;
|
bd->Time = current_time;
|
||||||
|
|
||||||
ImGui_ImplGlfw_UpdateMousePosAndButtons();
|
ImGui_ImplGlfw_UpdateMouseData();
|
||||||
ImGui_ImplGlfw_UpdateMouseCursor();
|
ImGui_ImplGlfw_UpdateMouseCursor();
|
||||||
|
|
||||||
// Update game controllers (if enabled and available)
|
// Update game controllers (if enabled and available)
|
||||||
ImGui_ImplGlfw_UpdateGamepads();
|
ImGui_ImplGlfw_UpdateGamepads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
@ -4,22 +4,20 @@
|
|||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Platform: Clipboard support.
|
// [X] Platform: Clipboard support.
|
||||||
|
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
||||||
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||||
// [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW.
|
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
||||||
// [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE).
|
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||||
|
|
||||||
// About GLSL version:
|
|
||||||
// The 'glsl_version' initialization parameter defaults to "#version 150" if NULL.
|
|
||||||
// Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure!
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
|
struct GLFWmonitor;
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks);
|
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks);
|
||||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
|
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
|
||||||
@ -27,10 +25,22 @@ IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool ins
|
|||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
|
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
|
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
|
||||||
|
|
||||||
// GLFW callbacks
|
// GLFW callbacks install
|
||||||
// - When calling Init with 'install_callbacks=true': GLFW callbacks will be installed for you. They will call user's previously installed callbacks, if any.
|
// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
|
||||||
// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call those function yourself from your own GLFW callbacks.
|
// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
|
||||||
|
|
||||||
|
// GFLW callbacks options:
|
||||||
|
// - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user)
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows);
|
||||||
|
|
||||||
|
// GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks)
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
|
IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event);
|
||||||
|
@ -5,14 +5,27 @@
|
|||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
||||||
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices.
|
// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2022-11-09: OpenGL: Reverted use of glBufferSubData(), too many corruptions issues + old issues seemingly can't be reproed with Intel drivers nowadays (revert 2021-12-15 and 2022-05-23 changes).
|
||||||
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
||||||
|
// 2022-09-27: OpenGL: Added ability to '#define IMGUI_IMPL_OPENGL_DEBUG'.
|
||||||
|
// 2022-05-23: OpenGL: Reworking 2021-12-15 "Using buffer orphaning" so it only happens on Intel GPU, seems to cause problems otherwise. (#4468, #4825, #4832, #5127).
|
||||||
|
// 2022-05-13: OpenGL: Fix state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states.
|
||||||
|
// 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers.
|
||||||
|
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
|
||||||
|
// 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader.
|
||||||
|
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
||||||
|
// 2021-06-25: OpenGL: Use OES_vertex_array extension on Emscripten + backup/restore current state.
|
||||||
|
// 2021-06-21: OpenGL: Destroy individual vertex/fragment shader objects right after they are linked into the main shader.
|
||||||
|
// 2021-05-24: OpenGL: Access GL_CLIP_ORIGIN when "GL_ARB_clip_control" extension is detected, inside of just OpenGL 4.5 version.
|
||||||
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
||||||
// 2021-04-06: OpenGL: Don't try to read GL_CLIP_ORIGIN unless we're OpenGL 4.5 or greater.
|
// 2021-04-06: OpenGL: Don't try to read GL_CLIP_ORIGIN unless we're OpenGL 4.5 or greater.
|
||||||
// 2021-02-18: OpenGL: Change blending equation to preserve alpha in output buffer.
|
// 2021-02-18: OpenGL: Change blending equation to preserve alpha in output buffer.
|
||||||
@ -46,7 +59,7 @@
|
|||||||
// 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
|
// 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
|
||||||
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
||||||
// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
|
// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
|
||||||
// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a NULL pointer.
|
// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a nullptr pointer.
|
||||||
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
|
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
|
||||||
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
|
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
|
||||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
|
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
|
||||||
@ -87,46 +100,68 @@
|
|||||||
#else
|
#else
|
||||||
#include <stdint.h> // intptr_t
|
#include <stdint.h> // intptr_t
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <TargetConditionals.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Clang warnings with -Weverything
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||||
|
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
||||||
|
#endif
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
|
||||||
|
#pragma GCC diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx'
|
||||||
|
#pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types
|
||||||
|
#endif
|
||||||
|
|
||||||
// GL includes
|
// GL includes
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
#include <GLES2/gl2.h>
|
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
||||||
|
#include <OpenGLES/ES2/gl.h> // Use GL ES 2
|
||||||
|
#else
|
||||||
|
#include <GLES2/gl2.h> // Use GL ES 2
|
||||||
|
#endif
|
||||||
|
#if defined(__EMSCRIPTEN__)
|
||||||
|
#ifndef GL_GLEXT_PROTOTYPES
|
||||||
|
#define GL_GLEXT_PROTOTYPES
|
||||||
|
#endif
|
||||||
|
#include <GLES2/gl2ext.h>
|
||||||
|
#endif
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
||||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
||||||
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
|
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
|
||||||
#else
|
#else
|
||||||
#include <GLES3/gl3.h> // Use GL ES 3
|
#include <GLES3/gl3.h> // Use GL ES 3
|
||||||
#endif
|
#endif
|
||||||
#else
|
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||||
// About Desktop OpenGL function loaders:
|
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
|
||||||
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
|
// Helper libraries are often used for this purpose! Here we are using our own minimal custom loader based on gl3w.
|
||||||
// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
|
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
|
||||||
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
|
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
|
||||||
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
|
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
|
||||||
#include <GL/gl3w.h> // Needs to be initialized with gl3wInit() in user's code
|
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
|
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
|
||||||
#include <GL/glew.h> // Needs to be initialized with glewInit() in user's code.
|
#define IMGL3W_IMPL
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
#include "imgui_impl_opengl3_loader.h"
|
||||||
#include <glad/glad.h> // Needs to be initialized with gladLoadGL() in user's code.
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2)
|
|
||||||
#include <glad/gl.h> // Needs to be initialized with gladLoadGL(...) or gladLoaderLoadGL() in user's code.
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
|
|
||||||
#ifndef GLFW_INCLUDE_NONE
|
|
||||||
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
|
|
||||||
#endif
|
#endif
|
||||||
#include <glbinding/Binding.h> // Needs to be initialized with glbinding::Binding::initialize() in user's code.
|
|
||||||
#include <glbinding/gl/gl.h>
|
// Vertex arrays are not supported on ES2/WebGL1 unless Emscripten which uses an extension
|
||||||
using namespace gl;
|
#ifndef IMGUI_IMPL_OPENGL_ES2
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
|
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
#ifndef GLFW_INCLUDE_NONE
|
#elif defined(__EMSCRIPTEN__)
|
||||||
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
|
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
#endif
|
#define glBindVertexArray glBindVertexArrayOES
|
||||||
#include <glbinding/glbinding.h>// Needs to be initialized with glbinding::initialize() in user's code.
|
#define glGenVertexArrays glGenVertexArraysOES
|
||||||
#include <glbinding/gl/gl.h>
|
#define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||||
using namespace gl;
|
#define GL_VERTEX_ARRAY_BINDING GL_VERTEX_ARRAY_BINDING_OES
|
||||||
#else
|
|
||||||
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Desktop GL 2.0+ has glPolygonMode() which GL ES and WebGL don't have.
|
||||||
|
#ifdef GL_POLYGON_MODE
|
||||||
|
#define IMGUI_IMPL_HAS_POLYGON_MODE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
|
// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
|
||||||
@ -144,18 +179,92 @@ using namespace gl;
|
|||||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
#define IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Desktop GL use extension detection
|
||||||
|
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
|
||||||
|
#define IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// [Debugging]
|
||||||
|
//#define IMGUI_IMPL_OPENGL_DEBUG
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
#define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check
|
||||||
|
#else
|
||||||
|
#define GL_CALL(_CALL) _CALL // Call without error check
|
||||||
|
#endif
|
||||||
|
|
||||||
// OpenGL Data
|
// OpenGL Data
|
||||||
static GLuint g_GlVersion = 0; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2)
|
struct ImGui_ImplOpenGL3_Data
|
||||||
static char g_GlslVersionString[32] = ""; // Specified by user or detected based on compile time GL settings.
|
{
|
||||||
static GLuint g_FontTexture = 0;
|
GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2)
|
||||||
static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings.
|
||||||
static GLint g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; // Uniforms location
|
GLuint FontTexture;
|
||||||
static GLuint g_AttribLocationVtxPos = 0, g_AttribLocationVtxUV = 0, g_AttribLocationVtxColor = 0; // Vertex attributes location
|
GLuint ShaderHandle;
|
||||||
static unsigned int g_VboHandle = 0, g_ElementsHandle = 0;
|
GLint AttribLocationTex; // Uniforms location
|
||||||
|
GLint AttribLocationProjMtx;
|
||||||
|
GLuint AttribLocationVtxPos; // Vertex attributes location
|
||||||
|
GLuint AttribLocationVtxUV;
|
||||||
|
GLuint AttribLocationVtxColor;
|
||||||
|
unsigned int VboHandle, ElementsHandle;
|
||||||
|
GLsizeiptr VertexBufferSize;
|
||||||
|
GLsizeiptr IndexBufferSize;
|
||||||
|
bool HasClipOrigin;
|
||||||
|
bool UseBufferSubData;
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
||||||
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||||
|
static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData()
|
||||||
|
{
|
||||||
|
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only)
|
||||||
|
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
|
struct ImGui_ImplOpenGL3_VtxAttribState
|
||||||
|
{
|
||||||
|
GLint Enabled, Size, Type, Normalized, Stride;
|
||||||
|
GLvoid* Ptr;
|
||||||
|
|
||||||
|
void GetState(GLint index)
|
||||||
|
{
|
||||||
|
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled);
|
||||||
|
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size);
|
||||||
|
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type);
|
||||||
|
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized);
|
||||||
|
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride);
|
||||||
|
glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr);
|
||||||
|
}
|
||||||
|
void SetState(GLint index)
|
||||||
|
{
|
||||||
|
glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr);
|
||||||
|
if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
||||||
{
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||||
|
|
||||||
|
// Initialize our loader
|
||||||
|
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||||
|
if (imgl3wInit() != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Setup backend capabilities flags
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
|
||||||
|
io.BackendRendererUserData = (void*)bd;
|
||||||
|
io.BackendRendererName = "imgui_impl_opengl3";
|
||||||
|
|
||||||
// Query for GL version (e.g. 320 for GL 3.2)
|
// Query for GL version (e.g. 320 for GL 3.2)
|
||||||
#if !defined(IMGUI_IMPL_OPENGL_ES2)
|
#if !defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
GLint major = 0;
|
GLint major = 0;
|
||||||
@ -168,85 +277,94 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
|||||||
const char* gl_version = (const char*)glGetString(GL_VERSION);
|
const char* gl_version = (const char*)glGetString(GL_VERSION);
|
||||||
sscanf(gl_version, "%d.%d", &major, &minor);
|
sscanf(gl_version, "%d.%d", &major, &minor);
|
||||||
}
|
}
|
||||||
g_GlVersion = (GLuint)(major * 100 + minor * 10);
|
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
|
||||||
|
|
||||||
|
bd->UseBufferSubData = false;
|
||||||
|
/*
|
||||||
|
// Query vendor to enable glBufferSubData kludge
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
|
||||||
|
if (strncmp(vendor, "Intel", 5) == 0)
|
||||||
|
bd->UseBufferSubData = true;
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
#else
|
#else
|
||||||
g_GlVersion = 200; // GLES 2
|
bd->GlVersion = 200; // GLES 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
||||||
|
printf("GL_MAJOR_VERSION = %d\nGL_MINOR_VERSION = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", major, minor, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendRendererName = "imgui_impl_opengl3";
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||||
if (g_GlVersion >= 320)
|
if (bd->GlVersion >= 320)
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Store GLSL version string so we can refer to it later in case we recreate shaders.
|
// Store GLSL version string so we can refer to it later in case we recreate shaders.
|
||||||
// Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure.
|
// Note: GLSL version is NOT the same as GL version. Leave this to nullptr if unsure.
|
||||||
|
if (glsl_version == nullptr)
|
||||||
|
{
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
if (glsl_version == NULL)
|
|
||||||
glsl_version = "#version 100";
|
glsl_version = "#version 100";
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
||||||
if (glsl_version == NULL)
|
|
||||||
glsl_version = "#version 300 es";
|
glsl_version = "#version 300 es";
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
if (glsl_version == NULL)
|
|
||||||
glsl_version = "#version 150";
|
glsl_version = "#version 150";
|
||||||
#else
|
#else
|
||||||
if (glsl_version == NULL)
|
|
||||||
glsl_version = "#version 130";
|
glsl_version = "#version 130";
|
||||||
#endif
|
#endif
|
||||||
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersionString));
|
}
|
||||||
strcpy(g_GlslVersionString, glsl_version);
|
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(bd->GlslVersionString));
|
||||||
strcat(g_GlslVersionString, "\n");
|
strcpy(bd->GlslVersionString, glsl_version);
|
||||||
|
strcat(bd->GlslVersionString, "\n");
|
||||||
// Debugging construct to make it easily visible in the IDE and debugger which GL loader has been selected.
|
|
||||||
// The code actually never uses the 'gl_loader' variable! It is only here so you can read it!
|
|
||||||
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
|
|
||||||
// you are likely to get a crash below.
|
|
||||||
// You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
|
|
||||||
const char* gl_loader = "Unknown";
|
|
||||||
IM_UNUSED(gl_loader);
|
|
||||||
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
|
|
||||||
gl_loader = "GL3W";
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
|
|
||||||
gl_loader = "GLEW";
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
|
||||||
gl_loader = "GLAD";
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2)
|
|
||||||
gl_loader = "GLAD2";
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
|
|
||||||
gl_loader = "glbinding2";
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
|
|
||||||
gl_loader = "glbinding3";
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
|
||||||
gl_loader = "custom";
|
|
||||||
#else
|
|
||||||
gl_loader = "none";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Make an arbitrary GL call (we don't actually need the result)
|
// Make an arbitrary GL call (we don't actually need the result)
|
||||||
// IF YOU GET A CRASH HERE: it probably means that you haven't initialized the OpenGL function loader used by this code.
|
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
|
||||||
// Desktop OpenGL 3/4 need a function loader. See the IMGUI_IMPL_OPENGL_LOADER_xxx explanation above.
|
|
||||||
GLint current_texture;
|
GLint current_texture;
|
||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
||||||
|
|
||||||
|
// Detect extensions we support
|
||||||
|
bd->HasClipOrigin = (bd->GlVersion >= 450);
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
|
||||||
|
GLint num_extensions = 0;
|
||||||
|
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
|
||||||
|
for (GLint i = 0; i < num_extensions; i++)
|
||||||
|
{
|
||||||
|
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||||
|
if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0)
|
||||||
|
bd->HasClipOrigin = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplOpenGL3_Shutdown()
|
void ImGui_ImplOpenGL3_Shutdown()
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplOpenGL3_NewFrame()
|
void ImGui_ImplOpenGL3_NewFrame()
|
||||||
{
|
{
|
||||||
if (!g_ShaderHandle)
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplOpenGL3_Init()?");
|
||||||
|
|
||||||
|
if (!bd->ShaderHandle)
|
||||||
ImGui_ImplOpenGL3_CreateDeviceObjects();
|
ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
|
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
|
||||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendEquation(GL_FUNC_ADD);
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
@ -256,17 +374,17 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
|
|||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||||
if (g_GlVersion >= 310)
|
if (bd->GlVersion >= 310)
|
||||||
glDisable(GL_PRIMITIVE_RESTART);
|
glDisable(GL_PRIMITIVE_RESTART);
|
||||||
#endif
|
#endif
|
||||||
#ifdef GL_POLYGON_MODE
|
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
|
// Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
|
||||||
#if defined(GL_CLIP_ORIGIN)
|
#if defined(GL_CLIP_ORIGIN)
|
||||||
bool clip_origin_lower_left = true;
|
bool clip_origin_lower_left = true;
|
||||||
if (g_GlVersion >= 450)
|
if (bd->HasClipOrigin)
|
||||||
{
|
{
|
||||||
GLenum current_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)¤t_clip_origin);
|
GLenum current_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)¤t_clip_origin);
|
||||||
if (current_clip_origin == GL_UPPER_LEFT)
|
if (current_clip_origin == GL_UPPER_LEFT)
|
||||||
@ -276,7 +394,7 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
|
|||||||
|
|
||||||
// Setup viewport, orthographic projection matrix
|
// Setup viewport, orthographic projection matrix
|
||||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
||||||
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
GL_CALL(glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
|
||||||
float L = draw_data->DisplayPos.x;
|
float L = draw_data->DisplayPos.x;
|
||||||
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
||||||
float T = draw_data->DisplayPos.y;
|
float T = draw_data->DisplayPos.y;
|
||||||
@ -291,29 +409,29 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
|
|||||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
|
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
|
||||||
};
|
};
|
||||||
glUseProgram(g_ShaderHandle);
|
glUseProgram(bd->ShaderHandle);
|
||||||
glUniform1i(g_AttribLocationTex, 0);
|
glUniform1i(bd->AttribLocationTex, 0);
|
||||||
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
if (g_GlVersion >= 330)
|
if (bd->GlVersion >= 330)
|
||||||
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
|
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(void)vertex_array_object;
|
(void)vertex_array_object;
|
||||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
glBindVertexArray(vertex_array_object);
|
glBindVertexArray(vertex_array_object);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Bind vertex/index buffers and setup attributes for ImDrawVert
|
// Bind vertex/index buffers and setup attributes for ImDrawVert
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, bd->VboHandle));
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
|
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bd->ElementsHandle));
|
||||||
glEnableVertexAttribArray(g_AttribLocationVtxPos);
|
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxPos));
|
||||||
glEnableVertexAttribArray(g_AttribLocationVtxUV);
|
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxUV));
|
||||||
glEnableVertexAttribArray(g_AttribLocationVtxColor);
|
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxColor));
|
||||||
glVertexAttribPointer(g_AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos));
|
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)));
|
||||||
glVertexAttribPointer(g_AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv));
|
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)));
|
||||||
glVertexAttribPointer(g_AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col));
|
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenGL3 Render function.
|
// OpenGL3 Render function.
|
||||||
@ -327,19 +445,28 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (fb_width <= 0 || fb_height <= 0)
|
if (fb_width <= 0 || fb_height <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
|
||||||
// Backup GL state
|
// Backup GL state
|
||||||
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
|
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program);
|
GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program);
|
||||||
GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture);
|
GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture);
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
GLuint last_sampler; if (g_GlVersion >= 330) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; }
|
GLuint last_sampler; if (bd->GlVersion >= 330) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; }
|
||||||
#endif
|
#endif
|
||||||
GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer);
|
GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer);
|
||||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
|
// This is part of VAO on OpenGL 3.0+ and OpenGL ES 3.0+.
|
||||||
|
GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
|
||||||
|
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_pos; last_vtx_attrib_state_pos.GetState(bd->AttribLocationVtxPos);
|
||||||
|
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_uv; last_vtx_attrib_state_uv.GetState(bd->AttribLocationVtxUV);
|
||||||
|
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_color; last_vtx_attrib_state_color.GetState(bd->AttribLocationVtxColor);
|
||||||
|
#endif
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object);
|
GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object);
|
||||||
#endif
|
#endif
|
||||||
#ifdef GL_POLYGON_MODE
|
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
|
||||||
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
|
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
|
||||||
#endif
|
#endif
|
||||||
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||||
@ -356,15 +483,15 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
GLboolean last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST);
|
GLboolean last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST);
|
||||||
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||||
GLboolean last_enable_primitive_restart = (g_GlVersion >= 310) ? glIsEnabled(GL_PRIMITIVE_RESTART) : GL_FALSE;
|
GLboolean last_enable_primitive_restart = (bd->GlVersion >= 310) ? glIsEnabled(GL_PRIMITIVE_RESTART) : GL_FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Setup desired GL state
|
// Setup desired GL state
|
||||||
// Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
|
// Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
|
||||||
// The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
|
// The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
|
||||||
GLuint vertex_array_object = 0;
|
GLuint vertex_array_object = 0;
|
||||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
glGenVertexArrays(1, &vertex_array_object);
|
GL_CALL(glGenVertexArrays(1, &vertex_array_object));
|
||||||
#endif
|
#endif
|
||||||
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
||||||
|
|
||||||
@ -378,13 +505,40 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
|
|
||||||
// Upload vertex/index buffers
|
// Upload vertex/index buffers
|
||||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
|
// - OpenGL drivers are in a very sorry state nowadays....
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW);
|
// During 2021 we attempted to switch from glBufferData() to orphaning+glBufferSubData() following reports
|
||||||
|
// of leaks on Intel GPU when using multi-viewports on Windows.
|
||||||
|
// - After this we kept hearing of various display corruptions issues. We started disabling on non-Intel GPU, but issues still got reported on Intel.
|
||||||
|
// - We are now back to using exclusively glBufferData(). So bd->UseBufferSubData IS ALWAYS FALSE in this code.
|
||||||
|
// We are keeping the old code path for a while in case people finding new issues may want to test the bd->UseBufferSubData path.
|
||||||
|
// - See https://github.com/ocornut/imgui/issues/4468 and please report any corruption issues.
|
||||||
|
const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
|
||||||
|
const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
|
||||||
|
if (bd->UseBufferSubData)
|
||||||
|
{
|
||||||
|
if (bd->VertexBufferSize < vtx_buffer_size)
|
||||||
|
{
|
||||||
|
bd->VertexBufferSize = vtx_buffer_size;
|
||||||
|
GL_CALL(glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, nullptr, GL_STREAM_DRAW));
|
||||||
|
}
|
||||||
|
if (bd->IndexBufferSize < idx_buffer_size)
|
||||||
|
{
|
||||||
|
bd->IndexBufferSize = idx_buffer_size;
|
||||||
|
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, nullptr, GL_STREAM_DRAW));
|
||||||
|
}
|
||||||
|
GL_CALL(glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data));
|
||||||
|
GL_CALL(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GL_CALL(glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW));
|
||||||
|
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW));
|
||||||
|
}
|
||||||
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
||||||
{
|
{
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||||
if (pcmd->UserCallback != NULL)
|
if (pcmd->UserCallback != nullptr)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
||||||
@ -396,47 +550,49 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Project scissor/clipping rectangles into framebuffer space
|
// Project scissor/clipping rectangles into framebuffer space
|
||||||
ImVec4 clip_rect;
|
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
||||||
clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
|
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
||||||
clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||||
clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
|
continue;
|
||||||
clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
|
|
||||||
|
|
||||||
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
|
// Apply scissor/clipping rectangle (Y is inverted in OpenGL)
|
||||||
{
|
GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
|
||||||
// Apply scissor/clipping rectangle
|
|
||||||
glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y));
|
|
||||||
|
|
||||||
// Bind texture, Draw
|
// Bind texture, Draw
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID());
|
GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||||
if (g_GlVersion >= 320)
|
if (bd->GlVersion >= 320)
|
||||||
glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset);
|
GL_CALL(glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset));
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)));
|
GL_CALL(glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the temporary VAO
|
// Destroy the temporary VAO
|
||||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
glDeleteVertexArrays(1, &vertex_array_object);
|
GL_CALL(glDeleteVertexArrays(1, &vertex_array_object));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Restore modified GL state
|
// Restore modified GL state
|
||||||
glUseProgram(last_program);
|
glUseProgram(last_program);
|
||||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
if (g_GlVersion >= 330)
|
if (bd->GlVersion >= 330)
|
||||||
glBindSampler(0, last_sampler);
|
glBindSampler(0, last_sampler);
|
||||||
#endif
|
#endif
|
||||||
glActiveTexture(last_active_texture);
|
glActiveTexture(last_active_texture);
|
||||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
glBindVertexArray(last_vertex_array_object);
|
glBindVertexArray(last_vertex_array_object);
|
||||||
#endif
|
#endif
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||||
|
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
|
||||||
|
last_vtx_attrib_state_pos.SetState(bd->AttribLocationVtxPos);
|
||||||
|
last_vtx_attrib_state_uv.SetState(bd->AttribLocationVtxUV);
|
||||||
|
last_vtx_attrib_state_color.SetState(bd->AttribLocationVtxColor);
|
||||||
|
#endif
|
||||||
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
|
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
|
||||||
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
|
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
|
||||||
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
|
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
|
||||||
@ -445,69 +601,75 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (last_enable_stencil_test) glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);
|
if (last_enable_stencil_test) glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);
|
||||||
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
|
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||||
if (g_GlVersion >= 310) { if (last_enable_primitive_restart) glEnable(GL_PRIMITIVE_RESTART); else glDisable(GL_PRIMITIVE_RESTART); }
|
if (bd->GlVersion >= 310) { if (last_enable_primitive_restart) glEnable(GL_PRIMITIVE_RESTART); else glDisable(GL_PRIMITIVE_RESTART); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GL_POLYGON_MODE
|
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
|
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
|
||||||
#endif
|
#endif
|
||||||
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||||
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
|
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
|
||||||
|
(void)bd; // Not all compilation paths use this
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplOpenGL3_CreateFontsTexture()
|
bool ImGui_ImplOpenGL3_CreateFontsTexture()
|
||||||
{
|
{
|
||||||
// Build texture atlas
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
|
||||||
|
// Build texture atlas
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
int width, height;
|
int width, height;
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
||||||
|
|
||||||
// Upload texture to graphics system
|
// Upload texture to graphics system
|
||||||
|
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
||||||
GLint last_texture;
|
GLint last_texture;
|
||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
|
||||||
glGenTextures(1, &g_FontTexture);
|
GL_CALL(glGenTextures(1, &bd->FontTexture));
|
||||||
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
GL_CALL(glBindTexture(GL_TEXTURE_2D, bd->FontTexture));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||||
#ifdef GL_UNPACK_ROW_LENGTH
|
#ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
|
||||||
#endif
|
#endif
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||||
|
|
||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts->SetTexID((ImTextureID)(intptr_t)g_FontTexture);
|
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
|
||||||
|
|
||||||
// Restore state
|
// Restore state
|
||||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplOpenGL3_DestroyFontsTexture()
|
void ImGui_ImplOpenGL3_DestroyFontsTexture()
|
||||||
{
|
{
|
||||||
if (g_FontTexture)
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
if (bd->FontTexture)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
glDeleteTextures(1, &bd->FontTexture);
|
||||||
glDeleteTextures(1, &g_FontTexture);
|
|
||||||
io.Fonts->SetTexID(0);
|
io.Fonts->SetTexID(0);
|
||||||
g_FontTexture = 0;
|
bd->FontTexture = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
|
// If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
|
||||||
static bool CheckShader(GLuint handle, const char* desc)
|
static bool CheckShader(GLuint handle, const char* desc)
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
GLint status = 0, log_length = 0;
|
GLint status = 0, log_length = 0;
|
||||||
glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
|
glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
|
||||||
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||||
if ((GLboolean)status == GL_FALSE)
|
if ((GLboolean)status == GL_FALSE)
|
||||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s!\n", desc);
|
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s! With GLSL: %s\n", desc, bd->GlslVersionString);
|
||||||
if (log_length > 1)
|
if (log_length > 1)
|
||||||
{
|
{
|
||||||
ImVector<char> buf;
|
ImVector<char> buf;
|
||||||
buf.resize((int)(log_length + 1));
|
buf.resize((int)(log_length + 1));
|
||||||
glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
|
glGetShaderInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
|
||||||
fprintf(stderr, "%s\n", buf.begin());
|
fprintf(stderr, "%s\n", buf.begin());
|
||||||
}
|
}
|
||||||
return (GLboolean)status == GL_TRUE;
|
return (GLboolean)status == GL_TRUE;
|
||||||
@ -516,16 +678,17 @@ static bool CheckShader(GLuint handle, const char* desc)
|
|||||||
// If you get an error please report on GitHub. You may try different GL context version or GLSL version.
|
// If you get an error please report on GitHub. You may try different GL context version or GLSL version.
|
||||||
static bool CheckProgram(GLuint handle, const char* desc)
|
static bool CheckProgram(GLuint handle, const char* desc)
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
GLint status = 0, log_length = 0;
|
GLint status = 0, log_length = 0;
|
||||||
glGetProgramiv(handle, GL_LINK_STATUS, &status);
|
glGetProgramiv(handle, GL_LINK_STATUS, &status);
|
||||||
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||||
if ((GLboolean)status == GL_FALSE)
|
if ((GLboolean)status == GL_FALSE)
|
||||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc, g_GlslVersionString);
|
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! With GLSL %s\n", desc, bd->GlslVersionString);
|
||||||
if (log_length > 1)
|
if (log_length > 1)
|
||||||
{
|
{
|
||||||
ImVector<char> buf;
|
ImVector<char> buf;
|
||||||
buf.resize((int)(log_length + 1));
|
buf.resize((int)(log_length + 1));
|
||||||
glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
|
glGetProgramInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
|
||||||
fprintf(stderr, "%s\n", buf.begin());
|
fprintf(stderr, "%s\n", buf.begin());
|
||||||
}
|
}
|
||||||
return (GLboolean)status == GL_TRUE;
|
return (GLboolean)status == GL_TRUE;
|
||||||
@ -533,18 +696,20 @@ static bool CheckProgram(GLuint handle, const char* desc)
|
|||||||
|
|
||||||
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
|
||||||
// Backup GL state
|
// Backup GL state
|
||||||
GLint last_texture, last_array_buffer;
|
GLint last_texture, last_array_buffer;
|
||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
GLint last_vertex_array;
|
GLint last_vertex_array;
|
||||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Parse GLSL version string
|
// Parse GLSL version string
|
||||||
int glsl_version = 130;
|
int glsl_version = 130;
|
||||||
sscanf(g_GlslVersionString, "#version %d", &glsl_version);
|
sscanf(bd->GlslVersionString, "#version %d", &glsl_version);
|
||||||
|
|
||||||
const GLchar* vertex_shader_glsl_120 =
|
const GLchar* vertex_shader_glsl_120 =
|
||||||
"uniform mat4 ProjMtx;\n"
|
"uniform mat4 ProjMtx;\n"
|
||||||
@ -575,7 +740,7 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
|||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
const GLchar* vertex_shader_glsl_300_es =
|
const GLchar* vertex_shader_glsl_300_es =
|
||||||
"precision mediump float;\n"
|
"precision highp float;\n"
|
||||||
"layout (location = 0) in vec2 Position;\n"
|
"layout (location = 0) in vec2 Position;\n"
|
||||||
"layout (location = 1) in vec2 UV;\n"
|
"layout (location = 1) in vec2 UV;\n"
|
||||||
"layout (location = 2) in vec4 Color;\n"
|
"layout (location = 2) in vec4 Color;\n"
|
||||||
@ -647,8 +812,8 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
|||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
// Select shaders matching our GLSL versions
|
// Select shaders matching our GLSL versions
|
||||||
const GLchar* vertex_shader = NULL;
|
const GLchar* vertex_shader = nullptr;
|
||||||
const GLchar* fragment_shader = NULL;
|
const GLchar* fragment_shader = nullptr;
|
||||||
if (glsl_version < 130)
|
if (glsl_version < 130)
|
||||||
{
|
{
|
||||||
vertex_shader = vertex_shader_glsl_120;
|
vertex_shader = vertex_shader_glsl_120;
|
||||||
@ -671,40 +836,46 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create shaders
|
// Create shaders
|
||||||
const GLchar* vertex_shader_with_version[2] = { g_GlslVersionString, vertex_shader };
|
const GLchar* vertex_shader_with_version[2] = { bd->GlslVersionString, vertex_shader };
|
||||||
g_VertHandle = glCreateShader(GL_VERTEX_SHADER);
|
GLuint vert_handle = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(g_VertHandle, 2, vertex_shader_with_version, NULL);
|
glShaderSource(vert_handle, 2, vertex_shader_with_version, nullptr);
|
||||||
glCompileShader(g_VertHandle);
|
glCompileShader(vert_handle);
|
||||||
CheckShader(g_VertHandle, "vertex shader");
|
CheckShader(vert_handle, "vertex shader");
|
||||||
|
|
||||||
const GLchar* fragment_shader_with_version[2] = { g_GlslVersionString, fragment_shader };
|
const GLchar* fragment_shader_with_version[2] = { bd->GlslVersionString, fragment_shader };
|
||||||
g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER);
|
GLuint frag_handle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(g_FragHandle, 2, fragment_shader_with_version, NULL);
|
glShaderSource(frag_handle, 2, fragment_shader_with_version, nullptr);
|
||||||
glCompileShader(g_FragHandle);
|
glCompileShader(frag_handle);
|
||||||
CheckShader(g_FragHandle, "fragment shader");
|
CheckShader(frag_handle, "fragment shader");
|
||||||
|
|
||||||
g_ShaderHandle = glCreateProgram();
|
// Link
|
||||||
glAttachShader(g_ShaderHandle, g_VertHandle);
|
bd->ShaderHandle = glCreateProgram();
|
||||||
glAttachShader(g_ShaderHandle, g_FragHandle);
|
glAttachShader(bd->ShaderHandle, vert_handle);
|
||||||
glLinkProgram(g_ShaderHandle);
|
glAttachShader(bd->ShaderHandle, frag_handle);
|
||||||
CheckProgram(g_ShaderHandle, "shader program");
|
glLinkProgram(bd->ShaderHandle);
|
||||||
|
CheckProgram(bd->ShaderHandle, "shader program");
|
||||||
|
|
||||||
g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture");
|
glDetachShader(bd->ShaderHandle, vert_handle);
|
||||||
g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx");
|
glDetachShader(bd->ShaderHandle, frag_handle);
|
||||||
g_AttribLocationVtxPos = (GLuint)glGetAttribLocation(g_ShaderHandle, "Position");
|
glDeleteShader(vert_handle);
|
||||||
g_AttribLocationVtxUV = (GLuint)glGetAttribLocation(g_ShaderHandle, "UV");
|
glDeleteShader(frag_handle);
|
||||||
g_AttribLocationVtxColor = (GLuint)glGetAttribLocation(g_ShaderHandle, "Color");
|
|
||||||
|
bd->AttribLocationTex = glGetUniformLocation(bd->ShaderHandle, "Texture");
|
||||||
|
bd->AttribLocationProjMtx = glGetUniformLocation(bd->ShaderHandle, "ProjMtx");
|
||||||
|
bd->AttribLocationVtxPos = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Position");
|
||||||
|
bd->AttribLocationVtxUV = (GLuint)glGetAttribLocation(bd->ShaderHandle, "UV");
|
||||||
|
bd->AttribLocationVtxColor = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Color");
|
||||||
|
|
||||||
// Create buffers
|
// Create buffers
|
||||||
glGenBuffers(1, &g_VboHandle);
|
glGenBuffers(1, &bd->VboHandle);
|
||||||
glGenBuffers(1, &g_ElementsHandle);
|
glGenBuffers(1, &bd->ElementsHandle);
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||||
|
|
||||||
// Restore modified GL state
|
// Restore modified GL state
|
||||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
glBindVertexArray(last_vertex_array);
|
glBindVertexArray(last_vertex_array);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -713,13 +884,16 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
|||||||
|
|
||||||
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
||||||
{
|
{
|
||||||
if (g_VboHandle) { glDeleteBuffers(1, &g_VboHandle); g_VboHandle = 0; }
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
if (g_ElementsHandle) { glDeleteBuffers(1, &g_ElementsHandle); g_ElementsHandle = 0; }
|
if (bd->VboHandle) { glDeleteBuffers(1, &bd->VboHandle); bd->VboHandle = 0; }
|
||||||
if (g_ShaderHandle && g_VertHandle) { glDetachShader(g_ShaderHandle, g_VertHandle); }
|
if (bd->ElementsHandle) { glDeleteBuffers(1, &bd->ElementsHandle); bd->ElementsHandle = 0; }
|
||||||
if (g_ShaderHandle && g_FragHandle) { glDetachShader(g_ShaderHandle, g_FragHandle); }
|
if (bd->ShaderHandle) { glDeleteProgram(bd->ShaderHandle); bd->ShaderHandle = 0; }
|
||||||
if (g_VertHandle) { glDeleteShader(g_VertHandle); g_VertHandle = 0; }
|
|
||||||
if (g_FragHandle) { glDeleteShader(g_FragHandle); g_FragHandle = 0; }
|
|
||||||
if (g_ShaderHandle) { glDeleteProgram(g_ShaderHandle); g_ShaderHandle = 0; }
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
@ -5,19 +5,15 @@
|
|||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
||||||
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices.
|
// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||||
|
|
||||||
// About Desktop OpenGL function loaders:
|
|
||||||
// Modern Desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
|
|
||||||
// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
|
|
||||||
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
|
|
||||||
|
|
||||||
// About GLSL version:
|
// About GLSL version:
|
||||||
// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
|
// The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string.
|
||||||
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
|
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
|
||||||
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
|
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
|
||||||
|
|
||||||
@ -25,7 +21,7 @@
|
|||||||
#include "imgui.h" // IMGUI_IMPL_API
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
|
||||||
// Backend API
|
// Backend API
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
|
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
|
||||||
@ -40,48 +36,20 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
|||||||
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
|
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
|
||||||
//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
|
//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
|
||||||
|
|
||||||
// Attempt to auto-detect the default Desktop GL loader based on available header files.
|
// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
|
||||||
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
|
|
||||||
// you are likely to get a crash in ImGui_ImplOpenGL3_Init().
|
|
||||||
// You can explicitly select a loader by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
|
|
||||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
|
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_ES3) \
|
&& !defined(IMGUI_IMPL_OPENGL_ES3)
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \
|
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
|
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
|
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2) \
|
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) \
|
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) \
|
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
|
||||||
|
|
||||||
// Try to detect GLES on matching platforms
|
// Try to detect GLES on matching platforms
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include "TargetConditionals.h"
|
#include <TargetConditionals.h>
|
||||||
#endif
|
#endif
|
||||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
|
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
|
||||||
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
|
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
|
||||||
#elif defined(__EMSCRIPTEN__)
|
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
|
||||||
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
||||||
|
|
||||||
// Otherwise try to detect supported Desktop OpenGL loaders..
|
|
||||||
#elif defined(__has_include)
|
|
||||||
#if __has_include(<GL/glew.h>)
|
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
|
|
||||||
#elif __has_include(<glad/glad.h>)
|
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
|
|
||||||
#elif __has_include(<glad/gl.h>)
|
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GLAD2
|
|
||||||
#elif __has_include(<GL/gl3w.h>)
|
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
|
|
||||||
#elif __has_include(<glbinding/glbinding.h>)
|
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING3
|
|
||||||
#elif __has_include(<glbinding/Binding.h>)
|
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
|
|
||||||
#else
|
#else
|
||||||
#error "Cannot detect OpenGL loader!"
|
// Otherwise imgui_impl_opengl3_loader.h will be used.
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GL3W // Default to GL3W embedded in our repository
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
800
source/linux/imgui_impl_opengl3_loader.h
Normal file
800
source/linux/imgui_impl_opengl3_loader.h
Normal file
@ -0,0 +1,800 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// About imgui_impl_opengl3_loader.h:
|
||||||
|
//
|
||||||
|
// We embed our own OpenGL loader to not require user to provide their own or to have to use ours,
|
||||||
|
// which proved to be endless problems for users.
|
||||||
|
// Our loader is custom-generated, based on gl3w but automatically filtered to only include
|
||||||
|
// enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small.
|
||||||
|
//
|
||||||
|
// YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY.
|
||||||
|
// THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE.
|
||||||
|
//
|
||||||
|
// IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions):
|
||||||
|
// IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCUDING 'imgui_impl_opengl3_loader.h'
|
||||||
|
// IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER.
|
||||||
|
// (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS)
|
||||||
|
// YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT.
|
||||||
|
// BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp
|
||||||
|
// WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT.
|
||||||
|
//
|
||||||
|
// Regenerate with:
|
||||||
|
// python gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
|
||||||
|
//
|
||||||
|
// More info:
|
||||||
|
// https://github.com/dearimgui/gl3w_stripped
|
||||||
|
// https://github.com/ocornut/imgui/issues/4445
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file was generated with gl3w_gen.py, part of imgl3w
|
||||||
|
* (hosted at https://github.com/dearimgui/gl3w_stripped)
|
||||||
|
*
|
||||||
|
* This is free and unencumbered software released into the public domain.
|
||||||
|
*
|
||||||
|
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
* distribute this software, either in source code form or as a compiled
|
||||||
|
* binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
* means.
|
||||||
|
*
|
||||||
|
* In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
* of this software dedicate any and all copyright interest in the
|
||||||
|
* software to the public domain. We make this dedication for the benefit
|
||||||
|
* of the public at large and to the detriment of our heirs and
|
||||||
|
* successors. We intend this dedication to be an overt act of
|
||||||
|
* relinquishment in perpetuity of all present and future rights to this
|
||||||
|
* software under copyright law.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __gl3w_h_
|
||||||
|
#define __gl3w_h_
|
||||||
|
|
||||||
|
// Adapted from KHR/khrplatform.h to avoid including entire file.
|
||||||
|
#ifndef __khrplatform_h_
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
#ifdef _WIN64
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
typedef signed __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef signed long long khronos_int64_t;
|
||||||
|
typedef unsigned long long khronos_uint64_t;
|
||||||
|
#endif
|
||||||
|
#endif // __khrplatform_h_
|
||||||
|
|
||||||
|
#ifndef __gl_glcorearb_h_
|
||||||
|
#define __gl_glcorearb_h_ 1
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
** Copyright 2013-2020 The Khronos Group Inc.
|
||||||
|
** SPDX-License-Identifier: MIT
|
||||||
|
**
|
||||||
|
** This header is generated from the Khronos OpenGL / OpenGL ES XML
|
||||||
|
** API Registry. The current version of the Registry, generator scripts
|
||||||
|
** used to make the header, and the header can be found at
|
||||||
|
** https://github.com/KhronosGroup/OpenGL-Registry
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
#ifndef APIENTRY
|
||||||
|
#define APIENTRY
|
||||||
|
#endif
|
||||||
|
#ifndef APIENTRYP
|
||||||
|
#define APIENTRYP APIENTRY *
|
||||||
|
#endif
|
||||||
|
#ifndef GLAPI
|
||||||
|
#define GLAPI extern
|
||||||
|
#endif
|
||||||
|
/* glcorearb.h is for use with OpenGL core profile implementations.
|
||||||
|
** It should should be placed in the same directory as gl.h and
|
||||||
|
** included as <GL/glcorearb.h>.
|
||||||
|
**
|
||||||
|
** glcorearb.h includes only APIs in the latest OpenGL core profile
|
||||||
|
** implementation together with APIs in newer ARB extensions which
|
||||||
|
** can be supported by the core profile. It does not, and never will
|
||||||
|
** include functionality removed from the core profile, such as
|
||||||
|
** fixed-function vertex and fragment processing.
|
||||||
|
**
|
||||||
|
** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
|
||||||
|
** <GL/glext.h> in the same source file.
|
||||||
|
*/
|
||||||
|
/* Generated C header for:
|
||||||
|
* API: gl
|
||||||
|
* Profile: core
|
||||||
|
* Versions considered: .*
|
||||||
|
* Versions emitted: .*
|
||||||
|
* Default extensions included: glcore
|
||||||
|
* Additional extensions included: _nomatch_^
|
||||||
|
* Extensions removed: _nomatch_^
|
||||||
|
*/
|
||||||
|
#ifndef GL_VERSION_1_0
|
||||||
|
typedef void GLvoid;
|
||||||
|
typedef unsigned int GLenum;
|
||||||
|
|
||||||
|
typedef khronos_float_t GLfloat;
|
||||||
|
typedef int GLint;
|
||||||
|
typedef int GLsizei;
|
||||||
|
typedef unsigned int GLbitfield;
|
||||||
|
typedef double GLdouble;
|
||||||
|
typedef unsigned int GLuint;
|
||||||
|
typedef unsigned char GLboolean;
|
||||||
|
typedef khronos_uint8_t GLubyte;
|
||||||
|
#define GL_COLOR_BUFFER_BIT 0x00004000
|
||||||
|
#define GL_FALSE 0
|
||||||
|
#define GL_TRUE 1
|
||||||
|
#define GL_TRIANGLES 0x0004
|
||||||
|
#define GL_ONE 1
|
||||||
|
#define GL_SRC_ALPHA 0x0302
|
||||||
|
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
|
||||||
|
#define GL_FRONT_AND_BACK 0x0408
|
||||||
|
#define GL_POLYGON_MODE 0x0B40
|
||||||
|
#define GL_CULL_FACE 0x0B44
|
||||||
|
#define GL_DEPTH_TEST 0x0B71
|
||||||
|
#define GL_STENCIL_TEST 0x0B90
|
||||||
|
#define GL_VIEWPORT 0x0BA2
|
||||||
|
#define GL_BLEND 0x0BE2
|
||||||
|
#define GL_SCISSOR_BOX 0x0C10
|
||||||
|
#define GL_SCISSOR_TEST 0x0C11
|
||||||
|
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
||||||
|
#define GL_PACK_ALIGNMENT 0x0D05
|
||||||
|
#define GL_TEXTURE_2D 0x0DE1
|
||||||
|
#define GL_UNSIGNED_BYTE 0x1401
|
||||||
|
#define GL_UNSIGNED_SHORT 0x1403
|
||||||
|
#define GL_UNSIGNED_INT 0x1405
|
||||||
|
#define GL_FLOAT 0x1406
|
||||||
|
#define GL_RGBA 0x1908
|
||||||
|
#define GL_FILL 0x1B02
|
||||||
|
#define GL_VENDOR 0x1F00
|
||||||
|
#define GL_RENDERER 0x1F01
|
||||||
|
#define GL_VERSION 0x1F02
|
||||||
|
#define GL_EXTENSIONS 0x1F03
|
||||||
|
#define GL_LINEAR 0x2601
|
||||||
|
#define GL_TEXTURE_MAG_FILTER 0x2800
|
||||||
|
#define GL_TEXTURE_MIN_FILTER 0x2801
|
||||||
|
typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
|
||||||
|
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
|
||||||
|
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||||
|
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
|
||||||
|
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||||
|
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
|
||||||
|
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
|
||||||
|
typedef void (APIENTRYP PFNGLFLUSHPROC) (void);
|
||||||
|
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
|
||||||
|
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||||
|
typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
|
||||||
|
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
|
||||||
|
typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
|
||||||
|
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
|
||||||
|
GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
|
||||||
|
GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||||
|
GLAPI void APIENTRY glClear (GLbitfield mask);
|
||||||
|
GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||||
|
GLAPI void APIENTRY glDisable (GLenum cap);
|
||||||
|
GLAPI void APIENTRY glEnable (GLenum cap);
|
||||||
|
GLAPI void APIENTRY glFlush (void);
|
||||||
|
GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
|
||||||
|
GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||||
|
GLAPI GLenum APIENTRY glGetError (void);
|
||||||
|
GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
|
||||||
|
GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
|
||||||
|
GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
|
||||||
|
GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_0 */
|
||||||
|
#ifndef GL_VERSION_1_1
|
||||||
|
typedef khronos_float_t GLclampf;
|
||||||
|
typedef double GLclampd;
|
||||||
|
#define GL_TEXTURE_BINDING_2D 0x8069
|
||||||
|
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||||
|
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
|
||||||
|
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||||
|
GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
|
||||||
|
GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
|
||||||
|
GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_1 */
|
||||||
|
#ifndef GL_VERSION_1_3
|
||||||
|
#define GL_TEXTURE0 0x84C0
|
||||||
|
#define GL_ACTIVE_TEXTURE 0x84E0
|
||||||
|
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glActiveTexture (GLenum texture);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_3 */
|
||||||
|
#ifndef GL_VERSION_1_4
|
||||||
|
#define GL_BLEND_DST_RGB 0x80C8
|
||||||
|
#define GL_BLEND_SRC_RGB 0x80C9
|
||||||
|
#define GL_BLEND_DST_ALPHA 0x80CA
|
||||||
|
#define GL_BLEND_SRC_ALPHA 0x80CB
|
||||||
|
#define GL_FUNC_ADD 0x8006
|
||||||
|
typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||||
|
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||||
|
GLAPI void APIENTRY glBlendEquation (GLenum mode);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_4 */
|
||||||
|
#ifndef GL_VERSION_1_5
|
||||||
|
typedef khronos_ssize_t GLsizeiptr;
|
||||||
|
typedef khronos_intptr_t GLintptr;
|
||||||
|
#define GL_ARRAY_BUFFER 0x8892
|
||||||
|
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
|
||||||
|
#define GL_ARRAY_BUFFER_BINDING 0x8894
|
||||||
|
#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
|
||||||
|
#define GL_STREAM_DRAW 0x88E0
|
||||||
|
typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
|
||||||
|
typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
|
||||||
|
typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||||
|
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
|
||||||
|
GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
|
||||||
|
GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
|
||||||
|
GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||||
|
GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_5 */
|
||||||
|
#ifndef GL_VERSION_2_0
|
||||||
|
typedef char GLchar;
|
||||||
|
typedef khronos_int16_t GLshort;
|
||||||
|
typedef khronos_int8_t GLbyte;
|
||||||
|
typedef khronos_uint16_t GLushort;
|
||||||
|
#define GL_BLEND_EQUATION_RGB 0x8009
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
|
||||||
|
#define GL_BLEND_EQUATION_ALPHA 0x883D
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
|
||||||
|
#define GL_FRAGMENT_SHADER 0x8B30
|
||||||
|
#define GL_VERTEX_SHADER 0x8B31
|
||||||
|
#define GL_COMPILE_STATUS 0x8B81
|
||||||
|
#define GL_LINK_STATUS 0x8B82
|
||||||
|
#define GL_INFO_LOG_LENGTH 0x8B84
|
||||||
|
#define GL_CURRENT_PROGRAM 0x8B8D
|
||||||
|
#define GL_UPPER_LEFT 0x8CA2
|
||||||
|
typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
|
||||||
|
typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
|
||||||
|
typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
|
||||||
|
typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
|
||||||
|
typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
|
||||||
|
typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
|
||||||
|
typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||||
|
typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||||
|
typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||||
|
typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
|
||||||
|
typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
|
||||||
|
typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||||
|
typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
|
||||||
|
typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
|
||||||
|
typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||||
|
typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
|
||||||
|
GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
|
||||||
|
GLAPI void APIENTRY glCompileShader (GLuint shader);
|
||||||
|
GLAPI GLuint APIENTRY glCreateProgram (void);
|
||||||
|
GLAPI GLuint APIENTRY glCreateShader (GLenum type);
|
||||||
|
GLAPI void APIENTRY glDeleteProgram (GLuint program);
|
||||||
|
GLAPI void APIENTRY glDeleteShader (GLuint shader);
|
||||||
|
GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
|
||||||
|
GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
|
||||||
|
GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
|
||||||
|
GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
|
||||||
|
GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
|
||||||
|
GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
|
||||||
|
GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
|
||||||
|
GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
|
||||||
|
GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
|
||||||
|
GLAPI void APIENTRY glLinkProgram (GLuint program);
|
||||||
|
GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||||
|
GLAPI void APIENTRY glUseProgram (GLuint program);
|
||||||
|
GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
|
||||||
|
GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||||
|
GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_2_0 */
|
||||||
|
#ifndef GL_VERSION_3_0
|
||||||
|
typedef khronos_uint16_t GLhalf;
|
||||||
|
#define GL_MAJOR_VERSION 0x821B
|
||||||
|
#define GL_MINOR_VERSION 0x821C
|
||||||
|
#define GL_NUM_EXTENSIONS 0x821D
|
||||||
|
#define GL_FRAMEBUFFER_SRGB 0x8DB9
|
||||||
|
#define GL_VERTEX_ARRAY_BINDING 0x85B5
|
||||||
|
typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
|
||||||
|
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
|
||||||
|
typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
|
||||||
|
typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
|
||||||
|
GLAPI void APIENTRY glBindVertexArray (GLuint array);
|
||||||
|
GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
|
||||||
|
GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_3_0 */
|
||||||
|
#ifndef GL_VERSION_3_1
|
||||||
|
#define GL_VERSION_3_1 1
|
||||||
|
#define GL_PRIMITIVE_RESTART 0x8F9D
|
||||||
|
#endif /* GL_VERSION_3_1 */
|
||||||
|
#ifndef GL_VERSION_3_2
|
||||||
|
#define GL_VERSION_3_2 1
|
||||||
|
typedef struct __GLsync *GLsync;
|
||||||
|
typedef khronos_uint64_t GLuint64;
|
||||||
|
typedef khronos_int64_t GLint64;
|
||||||
|
typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_3_2 */
|
||||||
|
#ifndef GL_VERSION_3_3
|
||||||
|
#define GL_VERSION_3_3 1
|
||||||
|
#define GL_SAMPLER_BINDING 0x8919
|
||||||
|
typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_3_3 */
|
||||||
|
#ifndef GL_VERSION_4_1
|
||||||
|
typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
|
||||||
|
typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
|
||||||
|
#endif /* GL_VERSION_4_1 */
|
||||||
|
#ifndef GL_VERSION_4_3
|
||||||
|
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||||
|
#endif /* GL_VERSION_4_3 */
|
||||||
|
#ifndef GL_VERSION_4_5
|
||||||
|
#define GL_CLIP_ORIGIN 0x935C
|
||||||
|
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
|
||||||
|
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
|
||||||
|
#endif /* GL_VERSION_4_5 */
|
||||||
|
#ifndef GL_ARB_bindless_texture
|
||||||
|
typedef khronos_uint64_t GLuint64EXT;
|
||||||
|
#endif /* GL_ARB_bindless_texture */
|
||||||
|
#ifndef GL_ARB_cl_event
|
||||||
|
struct _cl_context;
|
||||||
|
struct _cl_event;
|
||||||
|
#endif /* GL_ARB_cl_event */
|
||||||
|
#ifndef GL_ARB_clip_control
|
||||||
|
#define GL_ARB_clip_control 1
|
||||||
|
#endif /* GL_ARB_clip_control */
|
||||||
|
#ifndef GL_ARB_debug_output
|
||||||
|
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||||
|
#endif /* GL_ARB_debug_output */
|
||||||
|
#ifndef GL_EXT_EGL_image_storage
|
||||||
|
typedef void *GLeglImageOES;
|
||||||
|
#endif /* GL_EXT_EGL_image_storage */
|
||||||
|
#ifndef GL_EXT_direct_state_access
|
||||||
|
typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
|
||||||
|
#endif /* GL_EXT_direct_state_access */
|
||||||
|
#ifndef GL_NV_draw_vulkan_image
|
||||||
|
typedef void (APIENTRY *GLVULKANPROCNV)(void);
|
||||||
|
#endif /* GL_NV_draw_vulkan_image */
|
||||||
|
#ifndef GL_NV_gpu_shader5
|
||||||
|
typedef khronos_int64_t GLint64EXT;
|
||||||
|
#endif /* GL_NV_gpu_shader5 */
|
||||||
|
#ifndef GL_NV_vertex_buffer_unified_memory
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
|
||||||
|
#endif /* GL_NV_vertex_buffer_unified_memory */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef GL3W_API
|
||||||
|
#define GL3W_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __gl_h_
|
||||||
|
#define __gl_h_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define GL3W_OK 0
|
||||||
|
#define GL3W_ERROR_INIT -1
|
||||||
|
#define GL3W_ERROR_LIBRARY_OPEN -2
|
||||||
|
#define GL3W_ERROR_OPENGL_VERSION -3
|
||||||
|
|
||||||
|
typedef void (*GL3WglProc)(void);
|
||||||
|
typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
|
||||||
|
|
||||||
|
/* gl3w api */
|
||||||
|
GL3W_API int imgl3wInit(void);
|
||||||
|
GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
|
||||||
|
GL3W_API int imgl3wIsSupported(int major, int minor);
|
||||||
|
GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
|
||||||
|
|
||||||
|
/* gl3w internal state */
|
||||||
|
union GL3WProcs {
|
||||||
|
GL3WglProc ptr[58];
|
||||||
|
struct {
|
||||||
|
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||||
|
PFNGLATTACHSHADERPROC AttachShader;
|
||||||
|
PFNGLBINDBUFFERPROC BindBuffer;
|
||||||
|
PFNGLBINDSAMPLERPROC BindSampler;
|
||||||
|
PFNGLBINDTEXTUREPROC BindTexture;
|
||||||
|
PFNGLBINDVERTEXARRAYPROC BindVertexArray;
|
||||||
|
PFNGLBLENDEQUATIONPROC BlendEquation;
|
||||||
|
PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
|
||||||
|
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
|
||||||
|
PFNGLBUFFERDATAPROC BufferData;
|
||||||
|
PFNGLBUFFERSUBDATAPROC BufferSubData;
|
||||||
|
PFNGLCLEARPROC Clear;
|
||||||
|
PFNGLCLEARCOLORPROC ClearColor;
|
||||||
|
PFNGLCOMPILESHADERPROC CompileShader;
|
||||||
|
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||||
|
PFNGLCREATESHADERPROC CreateShader;
|
||||||
|
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
||||||
|
PFNGLDELETEPROGRAMPROC DeleteProgram;
|
||||||
|
PFNGLDELETESHADERPROC DeleteShader;
|
||||||
|
PFNGLDELETETEXTURESPROC DeleteTextures;
|
||||||
|
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
|
||||||
|
PFNGLDETACHSHADERPROC DetachShader;
|
||||||
|
PFNGLDISABLEPROC Disable;
|
||||||
|
PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
|
||||||
|
PFNGLDRAWELEMENTSPROC DrawElements;
|
||||||
|
PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
|
||||||
|
PFNGLENABLEPROC Enable;
|
||||||
|
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
|
||||||
|
PFNGLFLUSHPROC Flush;
|
||||||
|
PFNGLGENBUFFERSPROC GenBuffers;
|
||||||
|
PFNGLGENTEXTURESPROC GenTextures;
|
||||||
|
PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
|
||||||
|
PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
|
||||||
|
PFNGLGETERRORPROC GetError;
|
||||||
|
PFNGLGETINTEGERVPROC GetIntegerv;
|
||||||
|
PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
|
||||||
|
PFNGLGETPROGRAMIVPROC GetProgramiv;
|
||||||
|
PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
|
||||||
|
PFNGLGETSHADERIVPROC GetShaderiv;
|
||||||
|
PFNGLGETSTRINGPROC GetString;
|
||||||
|
PFNGLGETSTRINGIPROC GetStringi;
|
||||||
|
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
|
||||||
|
PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
|
||||||
|
PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
|
||||||
|
PFNGLISENABLEDPROC IsEnabled;
|
||||||
|
PFNGLLINKPROGRAMPROC LinkProgram;
|
||||||
|
PFNGLPIXELSTOREIPROC PixelStorei;
|
||||||
|
PFNGLPOLYGONMODEPROC PolygonMode;
|
||||||
|
PFNGLREADPIXELSPROC ReadPixels;
|
||||||
|
PFNGLSCISSORPROC Scissor;
|
||||||
|
PFNGLSHADERSOURCEPROC ShaderSource;
|
||||||
|
PFNGLTEXIMAGE2DPROC TexImage2D;
|
||||||
|
PFNGLTEXPARAMETERIPROC TexParameteri;
|
||||||
|
PFNGLUNIFORM1IPROC Uniform1i;
|
||||||
|
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
|
||||||
|
PFNGLUSEPROGRAMPROC UseProgram;
|
||||||
|
PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
|
||||||
|
PFNGLVIEWPORTPROC Viewport;
|
||||||
|
} gl;
|
||||||
|
};
|
||||||
|
|
||||||
|
GL3W_API extern union GL3WProcs imgl3wProcs;
|
||||||
|
|
||||||
|
/* OpenGL functions */
|
||||||
|
#define glActiveTexture imgl3wProcs.gl.ActiveTexture
|
||||||
|
#define glAttachShader imgl3wProcs.gl.AttachShader
|
||||||
|
#define glBindBuffer imgl3wProcs.gl.BindBuffer
|
||||||
|
#define glBindSampler imgl3wProcs.gl.BindSampler
|
||||||
|
#define glBindTexture imgl3wProcs.gl.BindTexture
|
||||||
|
#define glBindVertexArray imgl3wProcs.gl.BindVertexArray
|
||||||
|
#define glBlendEquation imgl3wProcs.gl.BlendEquation
|
||||||
|
#define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate
|
||||||
|
#define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate
|
||||||
|
#define glBufferData imgl3wProcs.gl.BufferData
|
||||||
|
#define glBufferSubData imgl3wProcs.gl.BufferSubData
|
||||||
|
#define glClear imgl3wProcs.gl.Clear
|
||||||
|
#define glClearColor imgl3wProcs.gl.ClearColor
|
||||||
|
#define glCompileShader imgl3wProcs.gl.CompileShader
|
||||||
|
#define glCreateProgram imgl3wProcs.gl.CreateProgram
|
||||||
|
#define glCreateShader imgl3wProcs.gl.CreateShader
|
||||||
|
#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
|
||||||
|
#define glDeleteProgram imgl3wProcs.gl.DeleteProgram
|
||||||
|
#define glDeleteShader imgl3wProcs.gl.DeleteShader
|
||||||
|
#define glDeleteTextures imgl3wProcs.gl.DeleteTextures
|
||||||
|
#define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays
|
||||||
|
#define glDetachShader imgl3wProcs.gl.DetachShader
|
||||||
|
#define glDisable imgl3wProcs.gl.Disable
|
||||||
|
#define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray
|
||||||
|
#define glDrawElements imgl3wProcs.gl.DrawElements
|
||||||
|
#define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex
|
||||||
|
#define glEnable imgl3wProcs.gl.Enable
|
||||||
|
#define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray
|
||||||
|
#define glFlush imgl3wProcs.gl.Flush
|
||||||
|
#define glGenBuffers imgl3wProcs.gl.GenBuffers
|
||||||
|
#define glGenTextures imgl3wProcs.gl.GenTextures
|
||||||
|
#define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays
|
||||||
|
#define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation
|
||||||
|
#define glGetError imgl3wProcs.gl.GetError
|
||||||
|
#define glGetIntegerv imgl3wProcs.gl.GetIntegerv
|
||||||
|
#define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog
|
||||||
|
#define glGetProgramiv imgl3wProcs.gl.GetProgramiv
|
||||||
|
#define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog
|
||||||
|
#define glGetShaderiv imgl3wProcs.gl.GetShaderiv
|
||||||
|
#define glGetString imgl3wProcs.gl.GetString
|
||||||
|
#define glGetStringi imgl3wProcs.gl.GetStringi
|
||||||
|
#define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation
|
||||||
|
#define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv
|
||||||
|
#define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv
|
||||||
|
#define glIsEnabled imgl3wProcs.gl.IsEnabled
|
||||||
|
#define glLinkProgram imgl3wProcs.gl.LinkProgram
|
||||||
|
#define glPixelStorei imgl3wProcs.gl.PixelStorei
|
||||||
|
#define glPolygonMode imgl3wProcs.gl.PolygonMode
|
||||||
|
#define glReadPixels imgl3wProcs.gl.ReadPixels
|
||||||
|
#define glScissor imgl3wProcs.gl.Scissor
|
||||||
|
#define glShaderSource imgl3wProcs.gl.ShaderSource
|
||||||
|
#define glTexImage2D imgl3wProcs.gl.TexImage2D
|
||||||
|
#define glTexParameteri imgl3wProcs.gl.TexParameteri
|
||||||
|
#define glUniform1i imgl3wProcs.gl.Uniform1i
|
||||||
|
#define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv
|
||||||
|
#define glUseProgram imgl3wProcs.gl.UseProgram
|
||||||
|
#define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer
|
||||||
|
#define glViewport imgl3wProcs.gl.Viewport
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IMGL3W_IMPL
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static HMODULE libgl;
|
||||||
|
typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
|
||||||
|
static GL3WglGetProcAddr wgl_get_proc_address;
|
||||||
|
|
||||||
|
static int open_libgl(void)
|
||||||
|
{
|
||||||
|
libgl = LoadLibraryA("opengl32.dll");
|
||||||
|
if (!libgl)
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_libgl(void) { FreeLibrary(libgl); }
|
||||||
|
static GL3WglProc get_proc(const char *proc)
|
||||||
|
{
|
||||||
|
GL3WglProc res;
|
||||||
|
res = (GL3WglProc)wgl_get_proc_address(proc);
|
||||||
|
if (!res)
|
||||||
|
res = (GL3WglProc)GetProcAddress(libgl, proc);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
static void *libgl;
|
||||||
|
static int open_libgl(void)
|
||||||
|
{
|
||||||
|
libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!libgl)
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_libgl(void) { dlclose(libgl); }
|
||||||
|
|
||||||
|
static GL3WglProc get_proc(const char *proc)
|
||||||
|
{
|
||||||
|
GL3WglProc res;
|
||||||
|
*(void **)(&res) = dlsym(libgl, proc);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
static void *libgl;
|
||||||
|
static GL3WglProc (*glx_get_proc_address)(const GLubyte *);
|
||||||
|
|
||||||
|
static int open_libgl(void)
|
||||||
|
{
|
||||||
|
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!libgl)
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
*(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_libgl(void) { dlclose(libgl); }
|
||||||
|
|
||||||
|
static GL3WglProc get_proc(const char *proc)
|
||||||
|
{
|
||||||
|
GL3WglProc res;
|
||||||
|
res = glx_get_proc_address((const GLubyte *)proc);
|
||||||
|
if (!res)
|
||||||
|
*(void **)(&res) = dlsym(libgl, proc);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static struct { int major, minor; } version;
|
||||||
|
|
||||||
|
static int parse_version(void)
|
||||||
|
{
|
||||||
|
if (!glGetIntegerv)
|
||||||
|
return GL3W_ERROR_INIT;
|
||||||
|
glGetIntegerv(GL_MAJOR_VERSION, &version.major);
|
||||||
|
glGetIntegerv(GL_MINOR_VERSION, &version.minor);
|
||||||
|
if (version.major == 0 && version.minor == 0)
|
||||||
|
{
|
||||||
|
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||||
|
const char* gl_version = (const char*)glGetString(GL_VERSION);
|
||||||
|
sscanf(gl_version, "%d.%d", &version.major, &version.minor);
|
||||||
|
}
|
||||||
|
if (version.major < 2)
|
||||||
|
return GL3W_ERROR_OPENGL_VERSION;
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void load_procs(GL3WGetProcAddressProc proc);
|
||||||
|
|
||||||
|
int imgl3wInit(void)
|
||||||
|
{
|
||||||
|
int res = open_libgl();
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
atexit(close_libgl);
|
||||||
|
return imgl3wInit2(get_proc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int imgl3wInit2(GL3WGetProcAddressProc proc)
|
||||||
|
{
|
||||||
|
load_procs(proc);
|
||||||
|
return parse_version();
|
||||||
|
}
|
||||||
|
|
||||||
|
int imgl3wIsSupported(int major, int minor)
|
||||||
|
{
|
||||||
|
if (major < 2)
|
||||||
|
return 0;
|
||||||
|
if (version.major == major)
|
||||||
|
return version.minor >= minor;
|
||||||
|
return version.major >= major;
|
||||||
|
}
|
||||||
|
|
||||||
|
GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
|
||||||
|
|
||||||
|
static const char *proc_names[] = {
|
||||||
|
"glActiveTexture",
|
||||||
|
"glAttachShader",
|
||||||
|
"glBindBuffer",
|
||||||
|
"glBindSampler",
|
||||||
|
"glBindTexture",
|
||||||
|
"glBindVertexArray",
|
||||||
|
"glBlendEquation",
|
||||||
|
"glBlendEquationSeparate",
|
||||||
|
"glBlendFuncSeparate",
|
||||||
|
"glBufferData",
|
||||||
|
"glBufferSubData",
|
||||||
|
"glClear",
|
||||||
|
"glClearColor",
|
||||||
|
"glCompileShader",
|
||||||
|
"glCreateProgram",
|
||||||
|
"glCreateShader",
|
||||||
|
"glDeleteBuffers",
|
||||||
|
"glDeleteProgram",
|
||||||
|
"glDeleteShader",
|
||||||
|
"glDeleteTextures",
|
||||||
|
"glDeleteVertexArrays",
|
||||||
|
"glDetachShader",
|
||||||
|
"glDisable",
|
||||||
|
"glDisableVertexAttribArray",
|
||||||
|
"glDrawElements",
|
||||||
|
"glDrawElementsBaseVertex",
|
||||||
|
"glEnable",
|
||||||
|
"glEnableVertexAttribArray",
|
||||||
|
"glFlush",
|
||||||
|
"glGenBuffers",
|
||||||
|
"glGenTextures",
|
||||||
|
"glGenVertexArrays",
|
||||||
|
"glGetAttribLocation",
|
||||||
|
"glGetError",
|
||||||
|
"glGetIntegerv",
|
||||||
|
"glGetProgramInfoLog",
|
||||||
|
"glGetProgramiv",
|
||||||
|
"glGetShaderInfoLog",
|
||||||
|
"glGetShaderiv",
|
||||||
|
"glGetString",
|
||||||
|
"glGetStringi",
|
||||||
|
"glGetUniformLocation",
|
||||||
|
"glGetVertexAttribPointerv",
|
||||||
|
"glGetVertexAttribiv",
|
||||||
|
"glIsEnabled",
|
||||||
|
"glLinkProgram",
|
||||||
|
"glPixelStorei",
|
||||||
|
"glPolygonMode",
|
||||||
|
"glReadPixels",
|
||||||
|
"glScissor",
|
||||||
|
"glShaderSource",
|
||||||
|
"glTexImage2D",
|
||||||
|
"glTexParameteri",
|
||||||
|
"glUniform1i",
|
||||||
|
"glUniformMatrix4fv",
|
||||||
|
"glUseProgram",
|
||||||
|
"glVertexAttribPointer",
|
||||||
|
"glViewport",
|
||||||
|
};
|
||||||
|
|
||||||
|
GL3W_API union GL3WProcs imgl3wProcs;
|
||||||
|
|
||||||
|
static void load_procs(GL3WGetProcAddressProc proc)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < ARRAY_SIZE(proc_names); i++)
|
||||||
|
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
@ -71,9 +71,11 @@ void logCallback (GLenum const source_,
|
|||||||
GLchar const *const message_,
|
GLchar const *const message_,
|
||||||
void const *const userParam_)
|
void const *const userParam_)
|
||||||
{
|
{
|
||||||
|
if (id_ == 131185)
|
||||||
|
return;
|
||||||
|
|
||||||
(void)source_;
|
(void)source_;
|
||||||
(void)type_;
|
(void)type_;
|
||||||
(void)id_;
|
|
||||||
(void)severity_;
|
(void)severity_;
|
||||||
(void)length_;
|
(void)length_;
|
||||||
(void)userParam_;
|
(void)userParam_;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
//
|
//
|
||||||
// The MIT License (MIT)
|
// The MIT License (MIT)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021 Michael Theall
|
// Copyright (C) 2023 Michael Theall
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -38,6 +38,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
@ -1156,6 +1157,144 @@ ImWchar const nxFontRanges[] = {
|
|||||||
0xe130, 0xe13c, 0xe140, 0xe14d, 0xe150, 0xe153, 0xf929, 0xf929,
|
0xe130, 0xe13c, 0xe140, 0xe14d, 0xe150, 0xe153, 0xf929, 0xf929,
|
||||||
0xf9dc, 0xf9dc, 0xfa0e, 0xfa2d, 0xfb01, 0xfb02, 0xfe30, 0xfe33,
|
0xf9dc, 0xf9dc, 0xfa0e, 0xfa2d, 0xfb01, 0xfb02, 0xfe30, 0xfe33,
|
||||||
0xfe35, 0xfe44, 0xff01, 0xff5e, 0xff61, 0xff9f, 0xffe0, 0xffe6,
|
0xfe35, 0xfe44, 0xff01, 0xff5e, 0xff61, 0xff9f, 0xffe0, 0xffe6,
|
||||||
|
0x0000, 0x0000,
|
||||||
|
// clang-format on
|
||||||
|
};
|
||||||
|
|
||||||
|
std::map<HidKeyboardKey, ImGuiKey> const s_keyMap = {
|
||||||
|
// clang-format off
|
||||||
|
{ HidKeyboardKey_A, ImGuiKey_A },
|
||||||
|
{ HidKeyboardKey_B, ImGuiKey_B },
|
||||||
|
{ HidKeyboardKey_C, ImGuiKey_C },
|
||||||
|
{ HidKeyboardKey_D, ImGuiKey_D },
|
||||||
|
{ HidKeyboardKey_E, ImGuiKey_E },
|
||||||
|
{ HidKeyboardKey_F, ImGuiKey_F },
|
||||||
|
{ HidKeyboardKey_G, ImGuiKey_G },
|
||||||
|
{ HidKeyboardKey_H, ImGuiKey_H },
|
||||||
|
{ HidKeyboardKey_I, ImGuiKey_I },
|
||||||
|
{ HidKeyboardKey_J, ImGuiKey_J },
|
||||||
|
{ HidKeyboardKey_K, ImGuiKey_K },
|
||||||
|
{ HidKeyboardKey_L, ImGuiKey_L },
|
||||||
|
{ HidKeyboardKey_M, ImGuiKey_M },
|
||||||
|
{ HidKeyboardKey_N, ImGuiKey_N },
|
||||||
|
{ HidKeyboardKey_O, ImGuiKey_O },
|
||||||
|
{ HidKeyboardKey_P, ImGuiKey_P },
|
||||||
|
{ HidKeyboardKey_Q, ImGuiKey_Q },
|
||||||
|
{ HidKeyboardKey_R, ImGuiKey_R },
|
||||||
|
{ HidKeyboardKey_S, ImGuiKey_S },
|
||||||
|
{ HidKeyboardKey_T, ImGuiKey_T },
|
||||||
|
{ HidKeyboardKey_U, ImGuiKey_U },
|
||||||
|
{ HidKeyboardKey_V, ImGuiKey_V },
|
||||||
|
{ HidKeyboardKey_W, ImGuiKey_W },
|
||||||
|
{ HidKeyboardKey_X, ImGuiKey_X },
|
||||||
|
{ HidKeyboardKey_Y, ImGuiKey_Y },
|
||||||
|
{ HidKeyboardKey_Z, ImGuiKey_Z },
|
||||||
|
{ HidKeyboardKey_D1, ImGuiKey_1 },
|
||||||
|
{ HidKeyboardKey_D2, ImGuiKey_2 },
|
||||||
|
{ HidKeyboardKey_D3, ImGuiKey_3 },
|
||||||
|
{ HidKeyboardKey_D4, ImGuiKey_4 },
|
||||||
|
{ HidKeyboardKey_D5, ImGuiKey_5 },
|
||||||
|
{ HidKeyboardKey_D6, ImGuiKey_6 },
|
||||||
|
{ HidKeyboardKey_D7, ImGuiKey_7 },
|
||||||
|
{ HidKeyboardKey_D8, ImGuiKey_8 },
|
||||||
|
{ HidKeyboardKey_D9, ImGuiKey_9 },
|
||||||
|
{ HidKeyboardKey_D0, ImGuiKey_0 },
|
||||||
|
{ HidKeyboardKey_Return, ImGuiKey_Enter },
|
||||||
|
{ HidKeyboardKey_Escape, ImGuiKey_Escape },
|
||||||
|
{ HidKeyboardKey_Backspace, ImGuiKey_Backspace },
|
||||||
|
{ HidKeyboardKey_Tab, ImGuiKey_Tab },
|
||||||
|
{ HidKeyboardKey_Space, ImGuiKey_Space },
|
||||||
|
{ HidKeyboardKey_Minus, ImGuiKey_Minus },
|
||||||
|
{ HidKeyboardKey_OpenBracket, ImGuiKey_LeftBracket },
|
||||||
|
{ HidKeyboardKey_CloseBracket, ImGuiKey_RightBracket },
|
||||||
|
{ HidKeyboardKey_Semicolon, ImGuiKey_Semicolon },
|
||||||
|
{ HidKeyboardKey_Quote, ImGuiKey_Apostrophe },
|
||||||
|
{ HidKeyboardKey_Backquote, ImGuiKey_GraveAccent },
|
||||||
|
{ HidKeyboardKey_Comma, ImGuiKey_Comma },
|
||||||
|
{ HidKeyboardKey_Period, ImGuiKey_Period },
|
||||||
|
{ HidKeyboardKey_Slash, ImGuiKey_Slash },
|
||||||
|
{ HidKeyboardKey_CapsLock, ImGuiKey_CapsLock },
|
||||||
|
{ HidKeyboardKey_F1, ImGuiKey_F1 },
|
||||||
|
{ HidKeyboardKey_F2, ImGuiKey_F2 },
|
||||||
|
{ HidKeyboardKey_F3, ImGuiKey_F3 },
|
||||||
|
{ HidKeyboardKey_F4, ImGuiKey_F4 },
|
||||||
|
{ HidKeyboardKey_F5, ImGuiKey_F5 },
|
||||||
|
{ HidKeyboardKey_F6, ImGuiKey_F6 },
|
||||||
|
{ HidKeyboardKey_F7, ImGuiKey_F7 },
|
||||||
|
{ HidKeyboardKey_F8, ImGuiKey_F8 },
|
||||||
|
{ HidKeyboardKey_F9, ImGuiKey_F9 },
|
||||||
|
{ HidKeyboardKey_F10, ImGuiKey_F10 },
|
||||||
|
{ HidKeyboardKey_F11, ImGuiKey_F11 },
|
||||||
|
{ HidKeyboardKey_F12, ImGuiKey_F12 },
|
||||||
|
{ HidKeyboardKey_PrintScreen, ImGuiKey_PrintScreen },
|
||||||
|
{ HidKeyboardKey_ScrollLock, ImGuiKey_ScrollLock },
|
||||||
|
{ HidKeyboardKey_Pause, ImGuiKey_Pause },
|
||||||
|
{ HidKeyboardKey_Insert, ImGuiKey_Insert },
|
||||||
|
{ HidKeyboardKey_Home, ImGuiKey_Home },
|
||||||
|
{ HidKeyboardKey_PageUp, ImGuiKey_PageUp },
|
||||||
|
{ HidKeyboardKey_Delete, ImGuiKey_Delete },
|
||||||
|
{ HidKeyboardKey_End, ImGuiKey_End },
|
||||||
|
{ HidKeyboardKey_PageDown, ImGuiKey_PageDown },
|
||||||
|
{ HidKeyboardKey_RightArrow, ImGuiKey_RightArrow },
|
||||||
|
{ HidKeyboardKey_LeftArrow, ImGuiKey_LeftArrow },
|
||||||
|
{ HidKeyboardKey_DownArrow, ImGuiKey_DownArrow },
|
||||||
|
{ HidKeyboardKey_UpArrow, ImGuiKey_UpArrow },
|
||||||
|
{ HidKeyboardKey_NumLock, ImGuiKey_NumLock },
|
||||||
|
{ HidKeyboardKey_NumPadDivide, ImGuiKey_KeypadDivide },
|
||||||
|
{ HidKeyboardKey_NumPadMultiply, ImGuiKey_KeypadMultiply },
|
||||||
|
{ HidKeyboardKey_NumPadSubtract, ImGuiKey_KeypadSubtract },
|
||||||
|
{ HidKeyboardKey_NumPadAdd, ImGuiKey_KeypadAdd },
|
||||||
|
{ HidKeyboardKey_NumPadEnter, ImGuiKey_KeypadEnter },
|
||||||
|
{ HidKeyboardKey_NumPad1, ImGuiKey_Keypad1 },
|
||||||
|
{ HidKeyboardKey_NumPad2, ImGuiKey_Keypad2 },
|
||||||
|
{ HidKeyboardKey_NumPad3, ImGuiKey_Keypad3 },
|
||||||
|
{ HidKeyboardKey_NumPad4, ImGuiKey_Keypad4 },
|
||||||
|
{ HidKeyboardKey_NumPad5, ImGuiKey_Keypad5 },
|
||||||
|
{ HidKeyboardKey_NumPad6, ImGuiKey_Keypad6 },
|
||||||
|
{ HidKeyboardKey_NumPad7, ImGuiKey_Keypad7 },
|
||||||
|
{ HidKeyboardKey_NumPad8, ImGuiKey_Keypad8 },
|
||||||
|
{ HidKeyboardKey_NumPad9, ImGuiKey_Keypad9 },
|
||||||
|
{ HidKeyboardKey_NumPad0, ImGuiKey_Keypad0 },
|
||||||
|
{ HidKeyboardKey_NumPadDot, ImGuiKey_KeypadDecimal },
|
||||||
|
{ HidKeyboardKey_Backslash, ImGuiKey_Backslash },
|
||||||
|
{ HidKeyboardKey_NumPadEquals, ImGuiKey_KeypadEqual },
|
||||||
|
{ HidKeyboardKey_LeftControl, ImGuiKey_LeftCtrl },
|
||||||
|
{ HidKeyboardKey_LeftShift, ImGuiKey_LeftShift },
|
||||||
|
{ HidKeyboardKey_LeftAlt, ImGuiKey_LeftAlt },
|
||||||
|
{ HidKeyboardKey_LeftGui, ImGuiKey_LeftSuper },
|
||||||
|
{ HidKeyboardKey_RightControl, ImGuiKey_RightCtrl },
|
||||||
|
{ HidKeyboardKey_RightShift, ImGuiKey_RightShift },
|
||||||
|
{ HidKeyboardKey_RightAlt, ImGuiKey_RightAlt },
|
||||||
|
{ HidKeyboardKey_RightGui, ImGuiKey_RightSuper },
|
||||||
|
//{ HidKeyboardKey_Plus, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Pipe, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Tilde, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Application, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Power, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F13, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F14, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F15, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F16, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F17, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F18, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F19, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F20, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F21, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F22, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F23, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_F24, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_NumPadComma, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Ro, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_KatakanaHiragana, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Yen, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Henkan, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Muhenkan, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_NumPadCommaPc98, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_HangulEnglish, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Hanja, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Katakana, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_Hiragana, ImGuiKey_ },
|
||||||
|
//{ HidKeyboardKey_ZenkakuHankaku, ImGuiKey_ },
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1242,13 +1381,24 @@ void moveMouse (ImGuiIO &io_, ImVec2 const &pos_, bool const force_ = false)
|
|||||||
/// \param io_ ImGui IO
|
/// \param io_ ImGui IO
|
||||||
void updateMouseButtons (HidMouseState const &mouseState_, ImGuiIO &io_)
|
void updateMouseButtons (HidMouseState const &mouseState_, ImGuiIO &io_)
|
||||||
{
|
{
|
||||||
|
static HidMouseState prevMouseState;
|
||||||
|
|
||||||
|
auto const diff = prevMouseState.buttons ^ mouseState_.buttons;
|
||||||
|
|
||||||
|
prevMouseState = mouseState_;
|
||||||
|
|
||||||
// read mouse buttons
|
// read mouse buttons
|
||||||
for (std::size_t i = 0; i < IM_ARRAYSIZE (io_.MouseDown); ++i)
|
for (std::size_t i = 0;
|
||||||
|
i < IM_ARRAYSIZE (io_.MouseDown) && i < sizeof (HidMouseState::buttons) * CHAR_BIT;
|
||||||
|
++i)
|
||||||
{
|
{
|
||||||
io_.MouseDown[i] = mouseState_.buttons & BIT (i);
|
if (!(diff & BIT (i)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
io_.AddMouseButtonEvent (i, mouseState_.buttons & BIT (i));
|
||||||
|
|
||||||
// force mouse cursor to show on click
|
// force mouse cursor to show on click
|
||||||
if (io_.MouseDown[i])
|
if (mouseState_.buttons & BIT (i))
|
||||||
moveMouse (io_, s_mousePos, true);
|
moveMouse (io_, s_mousePos, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1258,15 +1408,8 @@ void updateMouseButtons (HidMouseState const &mouseState_, ImGuiIO &io_)
|
|||||||
/// \param io_ ImGui IO
|
/// \param io_ ImGui IO
|
||||||
void updateMousePos (HidMouseState const &mouseState_, ImGuiIO &io_)
|
void updateMousePos (HidMouseState const &mouseState_, ImGuiIO &io_)
|
||||||
{
|
{
|
||||||
if (mouseState_.wheel_delta_x > 0)
|
if (mouseState_.wheel_delta_x || mouseState_.wheel_delta_y)
|
||||||
io_.MouseWheel += 1;
|
io_.AddMouseWheelEvent (mouseState_.wheel_delta_x, mouseState_.wheel_delta_y);
|
||||||
else if (mouseState_.wheel_delta_x < 0)
|
|
||||||
io_.MouseWheel -= 1;
|
|
||||||
|
|
||||||
if (mouseState_.wheel_delta_y > 0)
|
|
||||||
io_.MouseWheelH += 1;
|
|
||||||
else if (mouseState_.wheel_delta_y < 0)
|
|
||||||
io_.MouseWheelH -= 1;
|
|
||||||
|
|
||||||
moveMouse (io_,
|
moveMouse (io_,
|
||||||
ImVec2 (
|
ImVec2 (
|
||||||
@ -1278,13 +1421,21 @@ void updateMousePos (HidMouseState const &mouseState_, ImGuiIO &io_)
|
|||||||
/// \param io_ ImGui IO
|
/// \param io_ ImGui IO
|
||||||
void updateTouch (HidTouchScreenState const &touchState_, ImGuiIO &io_)
|
void updateTouch (HidTouchScreenState const &touchState_, ImGuiIO &io_)
|
||||||
{
|
{
|
||||||
|
static HidTouchScreenState prevTouchState;
|
||||||
|
|
||||||
|
if (prevTouchState.count > 0 && touchState_.count < 1)
|
||||||
|
io_.AddMouseButtonEvent (0, false);
|
||||||
|
else if (prevTouchState.count < 1 && touchState_.count > 0)
|
||||||
|
io_.AddMouseButtonEvent (0, true);
|
||||||
|
|
||||||
|
prevTouchState = touchState_;
|
||||||
|
|
||||||
if (touchState_.count < 1)
|
if (touchState_.count < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// set mouse position to touch point; force hide mouse cursor
|
// set mouse position to touch point; force hide mouse cursor
|
||||||
moveMouse (io_, ImVec2 (touchState_.touches[0].x, touchState_.touches[0].y));
|
moveMouse (io_, ImVec2 (touchState_.touches[0].x, touchState_.touches[0].y));
|
||||||
io_.MouseDown[0] = true;
|
s_showMouse = false;
|
||||||
s_showMouse = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Update gamepad inputs
|
/// \brief Update gamepad inputs
|
||||||
@ -1296,54 +1447,61 @@ void updateGamepads (PadState const &padState_, ImGuiIO &io_)
|
|||||||
std::memset (io_.NavInputs, 0, sizeof (io_.NavInputs));
|
std::memset (io_.NavInputs, 0, sizeof (io_.NavInputs));
|
||||||
|
|
||||||
auto const buttonMapping = {
|
auto const buttonMapping = {
|
||||||
std::make_pair (HidNpadButton_A, ImGuiNavInput_Activate),
|
// clang-format off
|
||||||
std::make_pair (HidNpadButton_B, ImGuiNavInput_Cancel),
|
std::make_pair (HidNpadButton_A, ImGuiKey_GamepadFaceDown), // A and B are swapped
|
||||||
std::make_pair (HidNpadButton_X, ImGuiNavInput_Input),
|
std::make_pair (HidNpadButton_B, ImGuiKey_GamepadFaceRight), // this is more intuitive
|
||||||
std::make_pair (HidNpadButton_Y, ImGuiNavInput_Menu),
|
std::make_pair (HidNpadButton_X, ImGuiKey_GamepadFaceUp),
|
||||||
std::make_pair (HidNpadButton_L, ImGuiNavInput_FocusPrev),
|
std::make_pair (HidNpadButton_Y, ImGuiKey_GamepadFaceLeft),
|
||||||
std::make_pair (HidNpadButton_L, ImGuiNavInput_TweakSlow),
|
std::make_pair (HidNpadButton_L, ImGuiKey_GamepadL1),
|
||||||
std::make_pair (HidNpadButton_R, ImGuiNavInput_FocusNext),
|
std::make_pair (HidNpadButton_R, ImGuiKey_GamepadR1),
|
||||||
std::make_pair (HidNpadButton_R, ImGuiNavInput_TweakFast),
|
std::make_pair (HidNpadButton_Up, ImGuiKey_GamepadDpadUp),
|
||||||
std::make_pair (HidNpadButton_Up, ImGuiNavInput_DpadUp),
|
std::make_pair (HidNpadButton_Right, ImGuiKey_GamepadDpadRight),
|
||||||
std::make_pair (HidNpadButton_Right, ImGuiNavInput_DpadRight),
|
std::make_pair (HidNpadButton_Down, ImGuiKey_GamepadDpadDown),
|
||||||
std::make_pair (HidNpadButton_Down, ImGuiNavInput_DpadDown),
|
std::make_pair (HidNpadButton_Left, ImGuiKey_GamepadDpadLeft),
|
||||||
std::make_pair (HidNpadButton_Left, ImGuiNavInput_DpadLeft),
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
// read buttons from primary controller
|
// read buttons from primary controller
|
||||||
auto const keys = padGetButtons (&padState_);
|
auto const keys = padGetButtons (&padState_);
|
||||||
|
auto const keysDown = padGetButtonsDown (&padState_);
|
||||||
|
auto const keysUp = padGetButtonsUp (&padState_);
|
||||||
for (auto const &[in, out] : buttonMapping)
|
for (auto const &[in, out] : buttonMapping)
|
||||||
{
|
{
|
||||||
if (keys & in)
|
if (keysUp & in)
|
||||||
io_.NavInputs[out] = 1.0f;
|
io_.AddKeyEvent (out, false);
|
||||||
|
else if (keysDown & in)
|
||||||
|
io_.AddKeyEvent (out, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use ZR/ZL as left-click/right-click, respectively
|
// use ZR/ZL as left-click/right-click, respectively
|
||||||
if (keys & HidNpadButton_ZR)
|
if ((keysDown | keysUp) & HidNpadButton_ZR)
|
||||||
{
|
{
|
||||||
io_.MouseDown[0] = true;
|
io_.AddMouseButtonEvent (0, keysDown & HidNpadButton_ZR);
|
||||||
moveMouse (io_, s_mousePos, true);
|
moveMouse (io_, s_mousePos, true);
|
||||||
}
|
}
|
||||||
if (keys & HidNpadButton_ZL)
|
if ((keysDown | keysUp) & HidNpadButton_ZL)
|
||||||
{
|
{
|
||||||
io_.MouseDown[1] = true;
|
io_.AddMouseButtonEvent (1, keysDown & HidNpadButton_ZL);
|
||||||
moveMouse (io_, s_mousePos, true);
|
moveMouse (io_, s_mousePos, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update joystick
|
// update joystick
|
||||||
auto const jsLeft = padGetStickPos (&padState_, 0);
|
auto const jsLeft = padGetStickPos (&padState_, 0);
|
||||||
|
|
||||||
auto const analogMapping = {
|
auto const analogMapping = {
|
||||||
std::make_tuple (std::ref (jsLeft.x), ImGuiNavInput_LStickLeft, -0.3f, -0.9f),
|
// clang-format off
|
||||||
std::make_tuple (std::ref (jsLeft.x), ImGuiNavInput_LStickRight, +0.3f, +0.9f),
|
std::make_tuple (std::ref (jsLeft.x), ImGuiKey_GamepadLStickLeft, -0.3f, -0.9f),
|
||||||
std::make_tuple (std::ref (jsLeft.y), ImGuiNavInput_LStickUp, +0.3f, +0.9f),
|
std::make_tuple (std::ref (jsLeft.x), ImGuiKey_GamepadLStickRight, +0.3f, +0.9f),
|
||||||
std::make_tuple (std::ref (jsLeft.y), ImGuiNavInput_LStickDown, -0.3f, -0.9f),
|
std::make_tuple (std::ref (jsLeft.y), ImGuiKey_GamepadLStickUp, +0.3f, +0.9f),
|
||||||
|
std::make_tuple (std::ref (jsLeft.y), ImGuiKey_GamepadLStickDown, -0.3f, -0.9f),
|
||||||
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
// read left joystick from primary controller
|
// read left joystick from primary controller
|
||||||
for (auto const &[in, out, min, max] : analogMapping)
|
for (auto const &[in, out, min, max] : analogMapping)
|
||||||
{
|
{
|
||||||
auto const value = in / static_cast<float> (JOYSTICK_MAX);
|
auto const value = std::clamp ((in / JOYSTICK_MAX - min) / (max - min), 0.0f, 1.0f);
|
||||||
io_.NavInputs[out] = std::clamp ((value - min) / (max - min), 0.0f, 1.0f);
|
io_.AddKeyAnalogEvent (out, value > 0.1f, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use right stick as mouse
|
// use right stick as mouse
|
||||||
@ -1366,13 +1524,36 @@ void updateGamepads (PadState const &padState_, ImGuiIO &io_)
|
|||||||
/// \param io_ ImGui IO
|
/// \param io_ ImGui IO
|
||||||
void updateKeyboard (HidKeyboardState const &kbState_, ImGuiIO &io_)
|
void updateKeyboard (HidKeyboardState const &kbState_, ImGuiIO &io_)
|
||||||
{
|
{
|
||||||
io_.KeyCtrl = kbState_.modifiers & HidKeyboardModifier_Control;
|
static HidKeyboardState prevKbState;
|
||||||
io_.KeyShift = kbState_.modifiers & HidKeyboardModifier_Shift;
|
|
||||||
io_.KeyAlt = kbState_.modifiers & (HidKeyboardModifier_LeftAlt | HidKeyboardModifier_RightAlt);
|
|
||||||
io_.KeySuper = kbState_.modifiers & HidKeyboardModifier_Gui;
|
|
||||||
|
|
||||||
for (int i = 0; i < 256; ++i)
|
auto const modDiff = prevKbState.modifiers ^ kbState_.modifiers;
|
||||||
io_.KeysDown[i] = kbState_.keys[i / 64] & (1ul << (i % 64));
|
|
||||||
|
if (modDiff & HidKeyboardModifier_Control)
|
||||||
|
io_.AddKeyEvent (ImGuiMod_Ctrl, kbState_.modifiers & HidKeyboardModifier_Control);
|
||||||
|
|
||||||
|
if (modDiff & HidKeyboardModifier_Shift)
|
||||||
|
io_.AddKeyEvent (ImGuiMod_Shift, kbState_.modifiers & HidKeyboardModifier_Shift);
|
||||||
|
|
||||||
|
if (modDiff & (HidKeyboardModifier_LeftAlt | HidKeyboardModifier_RightAlt))
|
||||||
|
io_.AddKeyEvent (ImGuiMod_Alt,
|
||||||
|
kbState_.modifiers & (HidKeyboardModifier_LeftAlt | HidKeyboardModifier_RightAlt));
|
||||||
|
|
||||||
|
if (modDiff & HidKeyboardModifier_Gui)
|
||||||
|
io_.AddKeyEvent (ImGuiMod_Super, kbState_.modifiers & HidKeyboardModifier_Gui);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < sizeof (HidKeyboardState::keys) * CHAR_BIT; ++i)
|
||||||
|
{
|
||||||
|
auto const key = static_cast<HidKeyboardKey> (i);
|
||||||
|
|
||||||
|
auto const it = s_keyMap.find (key);
|
||||||
|
if (it == std::end (s_keyMap))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (hidKeyboardStateGetKey (&prevKbState, key) != hidKeyboardStateGetKey (&kbState_, key))
|
||||||
|
io_.AddKeyEvent (it->second, hidKeyboardStateGetKey (&kbState_, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
prevKbState = kbState_;
|
||||||
|
|
||||||
static enum {
|
static enum {
|
||||||
INACTIVE,
|
INACTIVE,
|
||||||
@ -1474,30 +1655,6 @@ bool imgui::nx::init ()
|
|||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||||
io.BackendPlatformName = "Switch";
|
io.BackendPlatformName = "Switch";
|
||||||
|
|
||||||
// keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array.
|
|
||||||
io.KeyMap[ImGuiKey_Tab] = HidKeyboardKey_Tab;
|
|
||||||
io.KeyMap[ImGuiKey_LeftArrow] = HidKeyboardKey_LeftArrow;
|
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = HidKeyboardKey_RightArrow;
|
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = HidKeyboardKey_UpArrow;
|
|
||||||
io.KeyMap[ImGuiKey_DownArrow] = HidKeyboardKey_DownArrow;
|
|
||||||
io.KeyMap[ImGuiKey_PageUp] = HidKeyboardKey_PageUp;
|
|
||||||
io.KeyMap[ImGuiKey_PageDown] = HidKeyboardKey_PageDown;
|
|
||||||
io.KeyMap[ImGuiKey_Home] = HidKeyboardKey_Home;
|
|
||||||
io.KeyMap[ImGuiKey_End] = HidKeyboardKey_End;
|
|
||||||
io.KeyMap[ImGuiKey_Insert] = HidKeyboardKey_Insert;
|
|
||||||
io.KeyMap[ImGuiKey_Delete] = HidKeyboardKey_Delete;
|
|
||||||
io.KeyMap[ImGuiKey_Backspace] = HidKeyboardKey_Backspace;
|
|
||||||
io.KeyMap[ImGuiKey_Space] = HidKeyboardKey_Space;
|
|
||||||
io.KeyMap[ImGuiKey_Enter] = HidKeyboardKey_Return;
|
|
||||||
io.KeyMap[ImGuiKey_Escape] = HidKeyboardKey_Escape;
|
|
||||||
io.KeyMap[ImGuiKey_KeyPadEnter] = HidKeyboardKey_NumPadEnter;
|
|
||||||
io.KeyMap[ImGuiKey_A] = HidKeyboardKey_A;
|
|
||||||
io.KeyMap[ImGuiKey_C] = HidKeyboardKey_C;
|
|
||||||
io.KeyMap[ImGuiKey_V] = HidKeyboardKey_V;
|
|
||||||
io.KeyMap[ImGuiKey_X] = HidKeyboardKey_X;
|
|
||||||
io.KeyMap[ImGuiKey_Y] = HidKeyboardKey_Y;
|
|
||||||
io.KeyMap[ImGuiKey_Z] = HidKeyboardKey_Z;
|
|
||||||
|
|
||||||
// initially disable mouse cursor
|
// initially disable mouse cursor
|
||||||
io.MouseDrawCursor = false;
|
io.MouseDrawCursor = false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user