mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-25 15:34:36 +00:00
Retrieve ImGui with CPM.
ImGui OpenGL loader is patched, and not regenerated, because the gl3w script requires network connectivity to download the header files from Khronos at build time.
This commit is contained in:
parent
1769c2f457
commit
616e7c2eec
14
cmake/imgui-emscripten.patch
Normal file
14
cmake/imgui-emscripten.patch
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
diff '--color=auto' -ruN 72d8f61727dc878102157113d1998f86b852d20e/imconfig.h new/imconfig.h
|
||||||
|
--- 72d8f61727dc878102157113d1998f86b852d20e/imconfig.h 2024-09-27 14:28:05.568760349 +0200
|
||||||
|
+++ new/imconfig.h 2024-09-27 14:29:47.310243707 +0200
|
||||||
|
@@ -113,6 +113,10 @@
|
||||||
|
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||||
|
//#define ImDrawIdx unsigned int
|
||||||
|
|
||||||
|
+#ifdef __EMSCRIPTEN__
|
||||||
|
+#define ImDrawIdx unsigned int
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||||
|
//struct ImDrawList;
|
||||||
|
//struct ImDrawCmd;
|
76
cmake/imgui-loader.patch
Normal file
76
cmake/imgui-loader.patch
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
diff '--color=auto' -ruN e4f53010203bd9cf867b892a5cf6b192609bdb26/backends/imgui_impl_opengl3_loader.h new/backends/imgui_impl_opengl3_loader.h
|
||||||
|
--- e4f53010203bd9cf867b892a5cf6b192609bdb26/backends/imgui_impl_opengl3_loader.h 2024-09-27 15:28:48.719522293 +0200
|
||||||
|
+++ new/backends/imgui_impl_opengl3_loader.h 2024-09-27 15:49:51.695380147 +0200
|
||||||
|
@@ -10,7 +10,7 @@
|
||||||
|
// 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 INCLUDING 'imgui_impl_opengl3_loader.h'
|
||||||
|
+// 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.
|
||||||
|
@@ -179,8 +179,12 @@
|
||||||
|
#define GL_VERSION 0x1F02
|
||||||
|
#define GL_EXTENSIONS 0x1F03
|
||||||
|
#define GL_LINEAR 0x2601
|
||||||
|
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
|
||||||
|
#define GL_TEXTURE_MAG_FILTER 0x2800
|
||||||
|
#define GL_TEXTURE_MIN_FILTER 0x2801
|
||||||
|
+#define GL_TEXTURE_WRAP_S 0x2802
|
||||||
|
+#define GL_TEXTURE_WRAP_T 0x2803
|
||||||
|
+#define GL_REPEAT 0x2901
|
||||||
|
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);
|
||||||
|
@@ -231,12 +235,17 @@
|
||||||
|
GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_1 */
|
||||||
|
+#ifndef GL_VERSION_1_2
|
||||||
|
+#define GL_CLAMP_TO_EDGE 0x812F
|
||||||
|
+#endif /* GL_VERSION_1_2 */
|
||||||
|
#ifndef GL_VERSION_1_3
|
||||||
|
#define GL_TEXTURE0 0x84C0
|
||||||
|
#define GL_ACTIVE_TEXTURE 0x84E0
|
||||||
|
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
|
||||||
|
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glActiveTexture (GLenum texture);
|
||||||
|
+GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_3 */
|
||||||
|
#ifndef GL_VERSION_1_4
|
||||||
|
@@ -472,7 +481,7 @@
|
||||||
|
|
||||||
|
/* gl3w internal state */
|
||||||
|
union ImGL3WProcs {
|
||||||
|
- GL3WglProc ptr[59];
|
||||||
|
+ GL3WglProc ptr[60];
|
||||||
|
struct {
|
||||||
|
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||||
|
PFNGLATTACHSHADERPROC AttachShader;
|
||||||
|
@@ -488,6 +497,7 @@
|
||||||
|
PFNGLCLEARPROC Clear;
|
||||||
|
PFNGLCLEARCOLORPROC ClearColor;
|
||||||
|
PFNGLCOMPILESHADERPROC CompileShader;
|
||||||
|
+ PFNGLCOMPRESSEDTEXIMAGE2DPROC CompressedTexImage2D;
|
||||||
|
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||||
|
PFNGLCREATESHADERPROC CreateShader;
|
||||||
|
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
||||||
|
@@ -553,6 +563,7 @@
|
||||||
|
#define glClear imgl3wProcs.gl.Clear
|
||||||
|
#define glClearColor imgl3wProcs.gl.ClearColor
|
||||||
|
#define glCompileShader imgl3wProcs.gl.CompileShader
|
||||||
|
+#define glCompressedTexImage2D imgl3wProcs.gl.CompressedTexImage2D
|
||||||
|
#define glCreateProgram imgl3wProcs.gl.CreateProgram
|
||||||
|
#define glCreateShader imgl3wProcs.gl.CreateShader
|
||||||
|
#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
|
||||||
|
@@ -848,6 +859,7 @@
|
||||||
|
"glClear",
|
||||||
|
"glClearColor",
|
||||||
|
"glCompileShader",
|
||||||
|
+ "glCompressedTexImage2D",
|
||||||
|
"glCreateProgram",
|
||||||
|
"glCreateShader",
|
||||||
|
"glDeleteBuffers",
|
@ -143,7 +143,15 @@ target_include_directories(TracyGetOpt PUBLIC ${GETOPT_DIR})
|
|||||||
|
|
||||||
# ImGui
|
# ImGui
|
||||||
|
|
||||||
set(IMGUI_DIR "${ROOT_DIR}/imgui")
|
CPMAddPackage(
|
||||||
|
NAME ImGui
|
||||||
|
GITHUB_REPOSITORY ocornut/imgui
|
||||||
|
GIT_TAG 10fe2b67
|
||||||
|
DOWNLOAD_ONLY TRUE
|
||||||
|
PATCHES
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/imgui-emscripten.patch"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/imgui-loader.patch"
|
||||||
|
)
|
||||||
|
|
||||||
set(IMGUI_SOURCES
|
set(IMGUI_SOURCES
|
||||||
imgui_widgets.cpp
|
imgui_widgets.cpp
|
||||||
@ -152,18 +160,18 @@ set(IMGUI_SOURCES
|
|||||||
imgui.cpp
|
imgui.cpp
|
||||||
imgui_tables.cpp
|
imgui_tables.cpp
|
||||||
misc/freetype/imgui_freetype.cpp
|
misc/freetype/imgui_freetype.cpp
|
||||||
|
backends/imgui_impl_opengl3.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(TRANSFORM IMGUI_SOURCES PREPEND "${IMGUI_DIR}/")
|
list(TRANSFORM IMGUI_SOURCES PREPEND "${ImGui_SOURCE_DIR}/")
|
||||||
|
|
||||||
add_definitions(-DIMGUI_ENABLE_FREETYPE)
|
|
||||||
|
|
||||||
add_library(TracyImGui STATIC EXCLUDE_FROM_ALL ${IMGUI_SOURCES})
|
add_library(TracyImGui STATIC EXCLUDE_FROM_ALL ${IMGUI_SOURCES})
|
||||||
target_include_directories(TracyImGui PUBLIC ${IMGUI_DIR})
|
target_include_directories(TracyImGui PUBLIC ${ImGui_SOURCE_DIR})
|
||||||
target_link_libraries(TracyImGui PUBLIC TracyFreetype)
|
target_link_libraries(TracyImGui PUBLIC TracyFreetype)
|
||||||
|
target_compile_definitions(TracyImGui PRIVATE "IMGUI_ENABLE_FREETYPE")
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
target_compile_definitions(TracyImGui PUBLIC "IMGUI_DISABLE_DEBUG_TOOLS")
|
target_compile_definitions(TracyImGui PRIVATE "IMGUI_DISABLE_DEBUG_TOOLS")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# NFD
|
# NFD
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014-2024 Omar Cornut
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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 OR COPYRIGHT HOLDERS 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.
|
|
140
imgui/imconfig.h
140
imgui/imconfig.h
@ -1,140 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------
|
|
||||||
// DEAR IMGUI COMPILE-TIME OPTIONS
|
|
||||||
// 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 file 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.
|
|
||||||
// - Windows 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) // MSVC Windows: DLL export
|
|
||||||
//#define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import
|
|
||||||
//#define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden
|
|
||||||
|
|
||||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of 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 is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS.
|
|
||||||
|
|
||||||
//---- 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 ShowIDStackToolWindow() will be empty.
|
|
||||||
|
|
||||||
//---- 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_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
|
|
||||||
//#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
|
|
||||||
|
|
||||||
//---- Enable Test Engine / Automation features.
|
|
||||||
//#define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by include "imgui_te_config.h", see Test Engine for details.
|
|
||||||
|
|
||||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
|
||||||
// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included.
|
|
||||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
|
||||||
//#define IMGUI_USER_H_FILENAME "my_folder/my_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 IMGUI_USE_STB_SPRINTF is defined.
|
|
||||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
|
||||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
|
||||||
//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.
|
|
||||||
|
|
||||||
//---- 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 FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT)
|
|
||||||
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
|
|
||||||
// Only works in combination with IMGUI_ENABLE_FREETYPE.
|
|
||||||
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
|
||||||
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
|
|
||||||
//---- 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); }
|
|
||||||
*/
|
|
||||||
//---- ...Or use Dear ImGui's own very basic math operators.
|
|
||||||
//#define IMGUI_DEFINE_MATH_OPERATORS
|
|
||||||
|
|
||||||
//---- 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
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
#define ImDrawIdx unsigned int
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//---- 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 (we provide a default implementation of this in the codebase)
|
|
||||||
// (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 from anywhere (e.g. your own sources/header files)
|
|
||||||
/*
|
|
||||||
namespace ImGui
|
|
||||||
{
|
|
||||||
void MyFunction(const char* name, MyMatrix44* mtx);
|
|
||||||
}
|
|
||||||
*/
|
|
22316
imgui/imgui.cpp
22316
imgui/imgui.cpp
File diff suppressed because it is too large
Load Diff
3942
imgui/imgui.h
3942
imgui/imgui.h
File diff suppressed because it is too large
Load Diff
10646
imgui/imgui_demo.cpp
10646
imgui/imgui_demo.cpp
File diff suppressed because it is too large
Load Diff
4667
imgui/imgui_draw.cpp
4667
imgui/imgui_draw.cpp
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
10369
imgui/imgui_widgets.cpp
10369
imgui/imgui_widgets.cpp
File diff suppressed because it is too large
Load Diff
@ -1,627 +0,0 @@
|
|||||||
// [DEAR IMGUI]
|
|
||||||
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
|
||||||
// Grep for [DEAR IMGUI] to find the changes.
|
|
||||||
//
|
|
||||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
|
||||||
// Sean Barrett 2014
|
|
||||||
//
|
|
||||||
// Useful for e.g. packing rectangular textures into an atlas.
|
|
||||||
// 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
|
|
||||||
// the totally naive one in stb_truetype (which is primarily what
|
|
||||||
// this is meant to replace).
|
|
||||||
//
|
|
||||||
// Has only had a few tests run, may have issues.
|
|
||||||
//
|
|
||||||
// More docs to come.
|
|
||||||
//
|
|
||||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
|
||||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
|
||||||
//
|
|
||||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
|
||||||
//
|
|
||||||
// Please note: better rectangle packers are welcome! Please
|
|
||||||
// implement them to the same API, but with a different init
|
|
||||||
// function.
|
|
||||||
//
|
|
||||||
// Credits
|
|
||||||
//
|
|
||||||
// Library
|
|
||||||
// Sean Barrett
|
|
||||||
// Minor features
|
|
||||||
// Martins Mozeiko
|
|
||||||
// github:IntellectualKitty
|
|
||||||
//
|
|
||||||
// Bugfixes / warning fixes
|
|
||||||
// Jeremy Jaussaud
|
|
||||||
// Fabian Giesen
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// 0.99 (2019-02-07) warning fixes
|
|
||||||
// 0.11 (2017-03-03) return packing success/fail result
|
|
||||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
|
||||||
// 0.09 (2016-08-27) fix compiler warnings
|
|
||||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
|
||||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
|
||||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
|
||||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
|
||||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
|
||||||
// 0.01: initial release
|
|
||||||
//
|
|
||||||
// LICENSE
|
|
||||||
//
|
|
||||||
// See end of file for license information.
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// INCLUDE SECTION
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
|
||||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
|
||||||
|
|
||||||
#define STB_RECT_PACK_VERSION 1
|
|
||||||
|
|
||||||
#ifdef STBRP_STATIC
|
|
||||||
#define STBRP_DEF static
|
|
||||||
#else
|
|
||||||
#define STBRP_DEF extern
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct stbrp_context stbrp_context;
|
|
||||||
typedef struct stbrp_node stbrp_node;
|
|
||||||
typedef struct stbrp_rect stbrp_rect;
|
|
||||||
|
|
||||||
typedef int stbrp_coord;
|
|
||||||
|
|
||||||
#define STBRP__MAXVAL 0x7fffffff
|
|
||||||
// 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);
|
|
||||||
// Assign packed locations to rectangles. The rectangles are of type
|
|
||||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
|
||||||
// are 'num_rects' many of them.
|
|
||||||
//
|
|
||||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
|
||||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
|
||||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
|
||||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
|
||||||
// have the 'was_packed' flag set to 0.
|
|
||||||
//
|
|
||||||
// You should not try to access the 'rects' array from another thread
|
|
||||||
// while this function is running, as the function temporarily reorders
|
|
||||||
// the array while it executes.
|
|
||||||
//
|
|
||||||
// To pack into another rectangle, you need to call stbrp_init_target
|
|
||||||
// again. To continue packing into the same rectangle, you can call
|
|
||||||
// this function again. Calling this multiple times with multiple rect
|
|
||||||
// arrays will probably produce worse packing results than calling it
|
|
||||||
// a single time with the full rectangle array, but the option is
|
|
||||||
// available.
|
|
||||||
//
|
|
||||||
// The function returns 1 if all of the rectangles were successfully
|
|
||||||
// packed and 0 otherwise.
|
|
||||||
|
|
||||||
struct stbrp_rect
|
|
||||||
{
|
|
||||||
// reserved for your use:
|
|
||||||
int id;
|
|
||||||
|
|
||||||
// input:
|
|
||||||
stbrp_coord w, h;
|
|
||||||
|
|
||||||
// output:
|
|
||||||
stbrp_coord x, y;
|
|
||||||
int was_packed; // non-zero if valid packing
|
|
||||||
|
|
||||||
}; // 16 bytes, nominally
|
|
||||||
|
|
||||||
|
|
||||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
|
||||||
// Initialize a rectangle packer to:
|
|
||||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
|
||||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
|
||||||
//
|
|
||||||
// You must call this function every time you start packing into a new target.
|
|
||||||
//
|
|
||||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
|
||||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
|
||||||
// the call (or calls) finish.
|
|
||||||
//
|
|
||||||
// Note: to guarantee best results, either:
|
|
||||||
// 1. make sure 'num_nodes' >= 'width'
|
|
||||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
|
||||||
//
|
|
||||||
// If you don't do either of the above things, widths will be quantized to multiples
|
|
||||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
|
||||||
//
|
|
||||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
|
||||||
// may run out of temporary storage and be unable to pack some rectangles.
|
|
||||||
|
|
||||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
|
||||||
// Optionally call this function after init but before doing any packing to
|
|
||||||
// change the handling of the out-of-temp-memory scenario, described above.
|
|
||||||
// If you call init again, this will be reset to the default (false).
|
|
||||||
|
|
||||||
|
|
||||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
|
||||||
// Optionally select which packing heuristic the library should use. Different
|
|
||||||
// heuristics will produce better/worse results for different data sets.
|
|
||||||
// If you call init again, this will be reset to the default.
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
STBRP_HEURISTIC_Skyline_default=0,
|
|
||||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
|
||||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// the details of the following structures don't matter to you, but they must
|
|
||||||
// be visible so you can handle the memory allocations for them
|
|
||||||
|
|
||||||
struct stbrp_node
|
|
||||||
{
|
|
||||||
stbrp_coord x,y;
|
|
||||||
stbrp_node *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct stbrp_context
|
|
||||||
{
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int align;
|
|
||||||
int init_mode;
|
|
||||||
int heuristic;
|
|
||||||
int num_nodes;
|
|
||||||
stbrp_node *active_head;
|
|
||||||
stbrp_node *free_head;
|
|
||||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// IMPLEMENTATION SECTION
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
|
||||||
#ifndef STBRP_SORT
|
|
||||||
#include <stdlib.h>
|
|
||||||
#define STBRP_SORT qsort
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef STBRP_ASSERT
|
|
||||||
#include <assert.h>
|
|
||||||
#define STBRP_ASSERT assert
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define STBRP__NOTUSED(v) (void)(v)
|
|
||||||
#define STBRP__CDECL __cdecl
|
|
||||||
#else
|
|
||||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
|
||||||
#define STBRP__CDECL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
STBRP__INIT_skyline = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
|
||||||
{
|
|
||||||
switch (context->init_mode) {
|
|
||||||
case STBRP__INIT_skyline:
|
|
||||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
|
||||||
context->heuristic = heuristic;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
STBRP_ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
|
||||||
{
|
|
||||||
if (allow_out_of_mem)
|
|
||||||
// if it's ok to run out of memory, then don't bother aligning them;
|
|
||||||
// this gives better packing, but may fail due to OOM (even though
|
|
||||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
|
||||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
|
||||||
context->align = 1;
|
|
||||||
else {
|
|
||||||
// if it's not ok to run out of memory, then quantize the widths
|
|
||||||
// so that num_nodes is always enough nodes.
|
|
||||||
//
|
|
||||||
// I.e. num_nodes * align >= width
|
|
||||||
// align >= width / num_nodes
|
|
||||||
// align = ceil(width/num_nodes)
|
|
||||||
|
|
||||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0; i < num_nodes-1; ++i)
|
|
||||||
nodes[i].next = &nodes[i+1];
|
|
||||||
nodes[i].next = NULL;
|
|
||||||
context->init_mode = STBRP__INIT_skyline;
|
|
||||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
|
||||||
context->free_head = &nodes[0];
|
|
||||||
context->active_head = &context->extra[0];
|
|
||||||
context->width = width;
|
|
||||||
context->height = height;
|
|
||||||
context->num_nodes = num_nodes;
|
|
||||||
stbrp_setup_allow_out_of_mem(context, 0);
|
|
||||||
|
|
||||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
|
||||||
context->extra[0].x = 0;
|
|
||||||
context->extra[0].y = 0;
|
|
||||||
context->extra[0].next = &context->extra[1];
|
|
||||||
context->extra[1].x = (stbrp_coord) width;
|
|
||||||
context->extra[1].y = (1<<30);
|
|
||||||
context->extra[1].next = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find minimum y position if it starts at x1
|
|
||||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
|
||||||
{
|
|
||||||
stbrp_node *node = first;
|
|
||||||
int x1 = x0 + width;
|
|
||||||
int min_y, visited_width, waste_area;
|
|
||||||
|
|
||||||
STBRP__NOTUSED(c);
|
|
||||||
|
|
||||||
STBRP_ASSERT(first->x <= x0);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// skip in case we're past the node
|
|
||||||
while (node->next->x <= x0)
|
|
||||||
++node;
|
|
||||||
#else
|
|
||||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
|
||||||
#endif
|
|
||||||
|
|
||||||
STBRP_ASSERT(node->x <= x0);
|
|
||||||
|
|
||||||
min_y = 0;
|
|
||||||
waste_area = 0;
|
|
||||||
visited_width = 0;
|
|
||||||
while (node->x < x1) {
|
|
||||||
if (node->y > min_y) {
|
|
||||||
// raise min_y higher.
|
|
||||||
// we've accounted for all waste up to min_y,
|
|
||||||
// but we'll now add more waste for everything we've visted
|
|
||||||
waste_area += visited_width * (node->y - min_y);
|
|
||||||
min_y = node->y;
|
|
||||||
// the first time through, visited_width might be reduced
|
|
||||||
if (node->x < x0)
|
|
||||||
visited_width += node->next->x - x0;
|
|
||||||
else
|
|
||||||
visited_width += node->next->x - node->x;
|
|
||||||
} else {
|
|
||||||
// add waste area
|
|
||||||
int under_width = node->next->x - node->x;
|
|
||||||
if (under_width + visited_width > width)
|
|
||||||
under_width = width - visited_width;
|
|
||||||
waste_area += under_width * (min_y - node->y);
|
|
||||||
visited_width += under_width;
|
|
||||||
}
|
|
||||||
node = node->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pwaste = waste_area;
|
|
||||||
return min_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int x,y;
|
|
||||||
stbrp_node **prev_link;
|
|
||||||
} stbrp__findresult;
|
|
||||||
|
|
||||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
|
||||||
{
|
|
||||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
|
||||||
stbrp__findresult fr;
|
|
||||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
|
||||||
|
|
||||||
// align to multiple of c->align
|
|
||||||
width = (width + c->align - 1);
|
|
||||||
width -= width % c->align;
|
|
||||||
STBRP_ASSERT(width % c->align == 0);
|
|
||||||
|
|
||||||
// if it can't possibly fit, bail immediately
|
|
||||||
if (width > c->width || height > c->height) {
|
|
||||||
fr.prev_link = NULL;
|
|
||||||
fr.x = fr.y = 0;
|
|
||||||
return fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
node = c->active_head;
|
|
||||||
prev = &c->active_head;
|
|
||||||
while (node->x + width <= c->width) {
|
|
||||||
int y,waste;
|
|
||||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
|
||||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
|
||||||
// bottom left
|
|
||||||
if (y < best_y) {
|
|
||||||
best_y = y;
|
|
||||||
best = prev;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// best-fit
|
|
||||||
if (y + height <= c->height) {
|
|
||||||
// can only use it if it first vertically
|
|
||||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
|
||||||
best_y = y;
|
|
||||||
best_waste = waste;
|
|
||||||
best = prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prev = &node->next;
|
|
||||||
node = node->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
|
||||||
|
|
||||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
|
||||||
//
|
|
||||||
// e.g, if fitting
|
|
||||||
//
|
|
||||||
// ____________________
|
|
||||||
// |____________________|
|
|
||||||
//
|
|
||||||
// into
|
|
||||||
//
|
|
||||||
// | |
|
|
||||||
// | ____________|
|
|
||||||
// |____________|
|
|
||||||
//
|
|
||||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
|
||||||
//
|
|
||||||
// This makes BF take about 2x the time
|
|
||||||
|
|
||||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
|
||||||
tail = c->active_head;
|
|
||||||
node = c->active_head;
|
|
||||||
prev = &c->active_head;
|
|
||||||
// find first node that's admissible
|
|
||||||
while (tail->x < width)
|
|
||||||
tail = tail->next;
|
|
||||||
while (tail) {
|
|
||||||
int xpos = tail->x - width;
|
|
||||||
int y,waste;
|
|
||||||
STBRP_ASSERT(xpos >= 0);
|
|
||||||
// find the left position that matches this
|
|
||||||
while (node->next->x <= xpos) {
|
|
||||||
prev = &node->next;
|
|
||||||
node = node->next;
|
|
||||||
}
|
|
||||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
|
||||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
|
||||||
if (y + height <= c->height) {
|
|
||||||
if (y <= best_y) {
|
|
||||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
|
||||||
best_x = xpos;
|
|
||||||
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
|
||||||
best_y = y;
|
|
||||||
best_waste = waste;
|
|
||||||
best = prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tail = tail->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fr.prev_link = best;
|
|
||||||
fr.x = best_x;
|
|
||||||
fr.y = best_y;
|
|
||||||
return fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
|
||||||
{
|
|
||||||
// find best position according to heuristic
|
|
||||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
|
||||||
stbrp_node *node, *cur;
|
|
||||||
|
|
||||||
// bail if:
|
|
||||||
// 1. it failed
|
|
||||||
// 2. the best node doesn't fit (we don't always check this)
|
|
||||||
// 3. we're out of memory
|
|
||||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
|
||||||
res.prev_link = NULL;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// on success, create new node
|
|
||||||
node = context->free_head;
|
|
||||||
node->x = (stbrp_coord) res.x;
|
|
||||||
node->y = (stbrp_coord) (res.y + height);
|
|
||||||
|
|
||||||
context->free_head = node->next;
|
|
||||||
|
|
||||||
// insert the new node into the right starting point, and
|
|
||||||
// let 'cur' point to the remaining nodes needing to be
|
|
||||||
// stiched back in
|
|
||||||
|
|
||||||
cur = *res.prev_link;
|
|
||||||
if (cur->x < res.x) {
|
|
||||||
// preserve the existing one, so start testing with the next one
|
|
||||||
stbrp_node *next = cur->next;
|
|
||||||
cur->next = node;
|
|
||||||
cur = next;
|
|
||||||
} else {
|
|
||||||
*res.prev_link = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
// from here, traverse cur and free the nodes, until we get to one
|
|
||||||
// that shouldn't be freed
|
|
||||||
while (cur->next && cur->next->x <= res.x + width) {
|
|
||||||
stbrp_node *next = cur->next;
|
|
||||||
// move the current node to the free list
|
|
||||||
cur->next = context->free_head;
|
|
||||||
context->free_head = cur;
|
|
||||||
cur = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
// stitch the list back in
|
|
||||||
node->next = cur;
|
|
||||||
|
|
||||||
if (cur->x < res.x + width)
|
|
||||||
cur->x = (stbrp_coord) (res.x + width);
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
cur = context->active_head;
|
|
||||||
while (cur->x < context->width) {
|
|
||||||
STBRP_ASSERT(cur->x < cur->next->x);
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
STBRP_ASSERT(cur->next == NULL);
|
|
||||||
|
|
||||||
{
|
|
||||||
int count=0;
|
|
||||||
cur = context->active_head;
|
|
||||||
while (cur) {
|
|
||||||
cur = cur->next;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
cur = context->free_head;
|
|
||||||
while (cur) {
|
|
||||||
cur = cur->next;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
STBRP_ASSERT(count == context->num_nodes+2);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
|
||||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
|
||||||
if (p->h > q->h)
|
|
||||||
return -1;
|
|
||||||
if (p->h < q->h)
|
|
||||||
return 1;
|
|
||||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
|
||||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
|
||||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
|
||||||
}
|
|
||||||
|
|
||||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
|
||||||
{
|
|
||||||
int i, all_rects_packed = 1;
|
|
||||||
|
|
||||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
|
||||||
for (i=0; i < num_rects; ++i) {
|
|
||||||
rects[i].was_packed = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort according to heuristic
|
|
||||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
|
||||||
|
|
||||||
for (i=0; i < num_rects; ++i) {
|
|
||||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
|
||||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
|
||||||
} else {
|
|
||||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
|
||||||
if (fr.prev_link) {
|
|
||||||
rects[i].x = (stbrp_coord) fr.x;
|
|
||||||
rects[i].y = (stbrp_coord) fr.y;
|
|
||||||
} else {
|
|
||||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// unsort
|
|
||||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
|
||||||
|
|
||||||
// set was_packed flags and all_rects_packed status
|
|
||||||
for (i=0; i < num_rects; ++i) {
|
|
||||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
|
||||||
if (!rects[i].was_packed)
|
|
||||||
all_rects_packed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the all_rects_packed status
|
|
||||||
return all_rects_packed;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
------------------------------------------------------------------------------
|
|
||||||
This software is available under 2 licenses -- choose whichever you prefer.
|
|
||||||
------------------------------------------------------------------------------
|
|
||||||
ALTERNATIVE A - MIT License
|
|
||||||
Copyright (c) 2017 Sean Barrett
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
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 OR COPYRIGHT HOLDERS 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.
|
|
||||||
------------------------------------------------------------------------------
|
|
||||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
|
||||||
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.
|
|
||||||
------------------------------------------------------------------------------
|
|
||||||
*/
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,44 +0,0 @@
|
|||||||
# imgui_freetype
|
|
||||||
|
|
||||||
Build font atlases using FreeType instead of stb_truetype (which is the default font rasterizer).
|
|
||||||
<br>by @vuhdo, @mikesart, @ocornut.
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
|
|
||||||
1. Get latest FreeType binaries or build yourself (under Windows you may use vcpkg with `vcpkg install freetype --triplet=x64-windows`, `vcpkg integrate install`).
|
|
||||||
2. Add imgui_freetype.h/cpp alongside your project files.
|
|
||||||
3. Add `#define IMGUI_ENABLE_FREETYPE` in your [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) file
|
|
||||||
|
|
||||||
### About Gamma Correct Blending
|
|
||||||
|
|
||||||
FreeType assumes blending in linear space rather than gamma space.
|
|
||||||
See FreeType note for [FT_Render_Glyph](https://freetype.org/freetype2/docs/reference/ft2-glyph_retrieval.html#ft_render_glyph).
|
|
||||||
For correct results you need to be using sRGB and convert to linear space in the pixel shader output.
|
|
||||||
The default Dear ImGui styles will be impacted by this change (alpha values will need tweaking).
|
|
||||||
|
|
||||||
### Testbed for toying with settings (for developers)
|
|
||||||
|
|
||||||
See https://gist.github.com/ocornut/b3a9ecf13502fd818799a452969649ad
|
|
||||||
|
|
||||||
### Known issues
|
|
||||||
|
|
||||||
- Oversampling settings are ignored but also not so much necessary with the higher quality rendering.
|
|
||||||
|
|
||||||
### Comparison
|
|
||||||
|
|
||||||
Small, thin anti-aliased fonts typically benefit a lot from FreeType's hinting:
|
|
||||||
![comparing_font_rasterizers](https://user-images.githubusercontent.com/8225057/107550178-fef87f00-6bd0-11eb-8d09-e2edb2f0ccfc.gif)
|
|
||||||
|
|
||||||
### Colorful glyphs/emojis
|
|
||||||
|
|
||||||
You can use the `ImGuiFreeTypeBuilderFlags_LoadColor` flag to load certain colorful glyphs. See the
|
|
||||||
["Using Colorful Glyphs/Emojis"](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#using-colorful-glyphsemojis) section of FONTS.md.
|
|
||||||
|
|
||||||
![colored glyphs](https://user-images.githubusercontent.com/8225057/106171241-9dc4ba80-6191-11eb-8a69-ca1467b206d1.png)
|
|
||||||
|
|
||||||
### Using OpenType SVG fonts (SVGinOT)
|
|
||||||
- *SVG in Open Type* is a standard by Adobe and Mozilla for color OpenType and Open Font Format fonts. It allows font creators to embed complete SVG files within a font enabling full color and even animations.
|
|
||||||
- Popular fonts such as [twemoji](https://github.com/13rac1/twemoji-color-font) and fonts made with [scfbuild](https://github.com/13rac1/scfbuild) is SVGinOT
|
|
||||||
- Requires: [lunasvg](https://github.com/sammycage/lunasvg) v2.3.2 and above
|
|
||||||
1. Add `#define IMGUI_ENABLE_FREETYPE_LUNASVG` in your `imconfig.h`.
|
|
||||||
2. Get latest lunasvg binaries or build yourself. Under Windows you may use vcpkg with: `vcpkg install lunasvg --triplet=x64-windows`.
|
|
@ -1,951 +0,0 @@
|
|||||||
// dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder)
|
|
||||||
// (code)
|
|
||||||
|
|
||||||
// Get the latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype
|
|
||||||
// Original code by @vuhdo (Aleksei Skriabin). Improvements by @mikesart. Maintained since 2019 by @ocornut.
|
|
||||||
|
|
||||||
// CHANGELOG
|
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
|
||||||
// 2023/11/13: added support for ImFontConfig::RasterizationDensity field for scaling render density without scaling metrics.
|
|
||||||
// 2023/08/01: added support for SVG fonts, enable by using '#define IMGUI_ENABLE_FREETYPE_LUNASVG' (#6591)
|
|
||||||
// 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly.
|
|
||||||
// 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL.
|
|
||||||
// 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs.
|
|
||||||
// 2021/03/02: set 'atlas->TexPixelsUseColors = true' to help some backends with deciding of a preferred texture format.
|
|
||||||
// 2021/01/28: added support for color-layered glyphs via ImGuiFreeTypeBuilderFlags_LoadColor (require Freetype 2.10+).
|
|
||||||
// 2021/01/26: simplified integration by using '#define IMGUI_ENABLE_FREETYPE'. renamed ImGuiFreeType::XXX flags to ImGuiFreeTypeBuilderFlags_XXX for consistency with other API. removed ImGuiFreeType::BuildFontAtlas().
|
|
||||||
// 2020/06/04: fix for rare case where FT_Get_Char_Index() succeed but FT_Load_Glyph() fails.
|
|
||||||
// 2019/02/09: added RasterizerFlags::Monochrome flag to disable font anti-aliasing (combine with ::MonoHinting for best results!)
|
|
||||||
// 2019/01/15: added support for imgui allocators + added FreeType only override function SetAllocatorFunctions().
|
|
||||||
// 2019/01/10: re-factored to match big update in STB builder. fixed texture height waste. fixed redundant glyphs when merging. support for glyph padding.
|
|
||||||
// 2018/06/08: added support for ImFontConfig::GlyphMinAdvanceX, GlyphMaxAdvanceX.
|
|
||||||
// 2018/02/04: moved to main imgui repository (away from http://www.github.com/ocornut/imgui_club)
|
|
||||||
// 2018/01/22: fix for addition of ImFontAtlas::TexUvscale member.
|
|
||||||
// 2017/10/22: minor inconsequential change to match change in master (removed an unnecessary statement).
|
|
||||||
// 2017/09/26: fixes for imgui internal changes.
|
|
||||||
// 2017/08/26: cleanup, optimizations, support for ImFontConfig::RasterizerFlags, ImFontConfig::RasterizerMultiply.
|
|
||||||
// 2017/08/16: imported from https://github.com/Vuhdo/imgui_freetype into http://www.github.com/ocornut/imgui_club, updated for latest changes in ImFontAtlas, minor tweaks.
|
|
||||||
|
|
||||||
// About Gamma Correct Blending:
|
|
||||||
// - FreeType assumes blending in linear space rather than gamma space.
|
|
||||||
// - See https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph
|
|
||||||
// - For correct results you need to be using sRGB and convert to linear space in the pixel shader output.
|
|
||||||
// - The default dear imgui styles will be impacted by this change (alpha values will need tweaking).
|
|
||||||
|
|
||||||
// FIXME: cfg.OversampleH, OversampleV are not supported (but perhaps not so necessary with this rasterizer).
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_freetype.h"
|
|
||||||
#include "imgui_internal.h" // ImMin,ImMax,ImFontAtlasBuild*,
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <ft2build.h>
|
|
||||||
#include FT_FREETYPE_H // <freetype/freetype.h>
|
|
||||||
#include FT_MODULE_H // <freetype/ftmodapi.h>
|
|
||||||
#include FT_GLYPH_H // <freetype/ftglyph.h>
|
|
||||||
#include FT_SYNTHESIS_H // <freetype/ftsynth.h>
|
|
||||||
|
|
||||||
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
#include FT_OTSVG_H // <freetype/otsvg.h>
|
|
||||||
#include FT_BBOX_H // <freetype/ftbbox.h>
|
|
||||||
#include <lunasvg.h>
|
|
||||||
#if !((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12))
|
|
||||||
#error IMGUI_ENABLE_FREETYPE_LUNASVG requires FreeType version >= 2.12
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning (push)
|
|
||||||
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
|
||||||
#pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
|
|
||||||
#ifndef __clang__
|
|
||||||
#pragma GCC diagnostic ignored "-Wsubobject-linkage" // warning: 'xxxx' has a field 'xxxx' whose type uses the anonymous namespace
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Data
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Default memory allocators
|
|
||||||
static void* ImGuiFreeTypeDefaultAllocFunc(size_t size, void* user_data) { IM_UNUSED(user_data); return IM_ALLOC(size); }
|
|
||||||
static void ImGuiFreeTypeDefaultFreeFunc(void* ptr, void* user_data) { IM_UNUSED(user_data); IM_FREE(ptr); }
|
|
||||||
|
|
||||||
// Current memory allocators
|
|
||||||
static void* (*GImGuiFreeTypeAllocFunc)(size_t size, void* user_data) = ImGuiFreeTypeDefaultAllocFunc;
|
|
||||||
static void (*GImGuiFreeTypeFreeFunc)(void* ptr, void* user_data) = ImGuiFreeTypeDefaultFreeFunc;
|
|
||||||
static void* GImGuiFreeTypeAllocatorUserData = nullptr;
|
|
||||||
|
|
||||||
// Lunasvg support
|
|
||||||
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
static FT_Error ImGuiLunasvgPortInit(FT_Pointer* state);
|
|
||||||
static void ImGuiLunasvgPortFree(FT_Pointer* state);
|
|
||||||
static FT_Error ImGuiLunasvgPortRender(FT_GlyphSlot slot, FT_Pointer* _state);
|
|
||||||
static FT_Error ImGuiLunasvgPortPresetSlot(FT_GlyphSlot slot, FT_Bool cache, FT_Pointer* _state);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Code
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// Glyph metrics:
|
|
||||||
// --------------
|
|
||||||
//
|
|
||||||
// xmin xmax
|
|
||||||
// | |
|
|
||||||
// |<-------- width -------->|
|
|
||||||
// | |
|
|
||||||
// | +-------------------------+----------------- ymax
|
|
||||||
// | | ggggggggg ggggg | ^ ^
|
|
||||||
// | | g:::::::::ggg::::g | | |
|
|
||||||
// | | g:::::::::::::::::g | | |
|
|
||||||
// | | g::::::ggggg::::::gg | | |
|
|
||||||
// | | g:::::g g:::::g | | |
|
|
||||||
// offsetX -|-------->| g:::::g g:::::g | offsetY |
|
|
||||||
// | | g:::::g g:::::g | | |
|
|
||||||
// | | g::::::g g:::::g | | |
|
|
||||||
// | | g:::::::ggggg:::::g | | |
|
|
||||||
// | | g::::::::::::::::g | | height
|
|
||||||
// | | gg::::::::::::::g | | |
|
|
||||||
// baseline ---*---------|---- gggggggg::::::g-----*-------- |
|
|
||||||
// / | | g:::::g | |
|
|
||||||
// origin | | gggggg g:::::g | |
|
|
||||||
// | | g:::::gg gg:::::g | |
|
|
||||||
// | | g::::::ggg:::::::g | |
|
|
||||||
// | | gg:::::::::::::g | |
|
|
||||||
// | | ggg::::::ggg | |
|
|
||||||
// | | gggggg | v
|
|
||||||
// | +-------------------------+----------------- ymin
|
|
||||||
// | |
|
|
||||||
// |------------- advanceX ----------->|
|
|
||||||
|
|
||||||
// A structure that describe a glyph.
|
|
||||||
struct GlyphInfo
|
|
||||||
{
|
|
||||||
int Width; // Glyph's width in pixels.
|
|
||||||
int Height; // Glyph's height in pixels.
|
|
||||||
FT_Int OffsetX; // The distance from the origin ("pen position") to the left of the glyph.
|
|
||||||
FT_Int OffsetY; // The distance from the origin to the top of the glyph. This is usually a value < 0.
|
|
||||||
float AdvanceX; // The distance from the origin to the origin of the next glyph. This is usually a value > 0.
|
|
||||||
bool IsColored; // The glyph is colored
|
|
||||||
};
|
|
||||||
|
|
||||||
// Font parameters and metrics.
|
|
||||||
struct FontInfo
|
|
||||||
{
|
|
||||||
uint32_t PixelHeight; // Size this font was generated with.
|
|
||||||
float Ascender; // The pixel extents above the baseline in pixels (typically positive).
|
|
||||||
float Descender; // The extents below the baseline in pixels (typically negative).
|
|
||||||
float LineSpacing; // The baseline-to-baseline distance. Note that it usually is larger than the sum of the ascender and descender taken as absolute values. There is also no guarantee that no glyphs extend above or below subsequent baselines when using this distance. Think of it as a value the designer of the font finds appropriate.
|
|
||||||
float LineGap; // The spacing in pixels between one row's descent and the next row's ascent.
|
|
||||||
float MaxAdvanceWidth; // This field gives the maximum horizontal cursor advance for all glyphs in the font.
|
|
||||||
};
|
|
||||||
|
|
||||||
// FreeType glyph rasterizer.
|
|
||||||
// NB: No ctor/dtor, explicitly call Init()/Shutdown()
|
|
||||||
struct FreeTypeFont
|
|
||||||
{
|
|
||||||
bool InitFont(FT_Library ft_library, const ImFontConfig& cfg, unsigned int extra_user_flags); // Initialize from an external data buffer. Doesn't copy data, and you must ensure it stays valid up to this object lifetime.
|
|
||||||
void CloseFont();
|
|
||||||
void SetPixelHeight(int pixel_height); // Change font pixel size. All following calls to RasterizeGlyph() will use this size
|
|
||||||
const FT_Glyph_Metrics* LoadGlyph(uint32_t in_codepoint);
|
|
||||||
const FT_Bitmap* RenderGlyphAndGetInfo(GlyphInfo* out_glyph_info);
|
|
||||||
void BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch, unsigned char* multiply_table = nullptr);
|
|
||||||
~FreeTypeFont() { CloseFont(); }
|
|
||||||
|
|
||||||
// [Internals]
|
|
||||||
FontInfo Info; // Font descriptor of the current font.
|
|
||||||
FT_Face Face;
|
|
||||||
unsigned int UserFlags; // = ImFontConfig::RasterizerFlags
|
|
||||||
FT_Int32 LoadFlags;
|
|
||||||
FT_Render_Mode RenderMode;
|
|
||||||
float RasterizationDensity;
|
|
||||||
float InvRasterizationDensity;
|
|
||||||
};
|
|
||||||
|
|
||||||
// From SDL_ttf: Handy routines for converting from fixed point
|
|
||||||
#define FT_CEIL(X) (((X + 63) & -64) / 64)
|
|
||||||
|
|
||||||
bool FreeTypeFont::InitFont(FT_Library ft_library, const ImFontConfig& cfg, unsigned int extra_font_builder_flags)
|
|
||||||
{
|
|
||||||
FT_Error error = FT_New_Memory_Face(ft_library, (uint8_t*)cfg.FontData, (uint32_t)cfg.FontDataSize, (uint32_t)cfg.FontNo, &Face);
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
error = FT_Select_Charmap(Face, FT_ENCODING_UNICODE);
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Convert to FreeType flags (NB: Bold and Oblique are processed separately)
|
|
||||||
UserFlags = cfg.FontBuilderFlags | extra_font_builder_flags;
|
|
||||||
|
|
||||||
LoadFlags = 0;
|
|
||||||
if ((UserFlags & ImGuiFreeTypeBuilderFlags_Bitmap) == 0)
|
|
||||||
LoadFlags |= FT_LOAD_NO_BITMAP;
|
|
||||||
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_NoHinting)
|
|
||||||
LoadFlags |= FT_LOAD_NO_HINTING;
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_NoAutoHint)
|
|
||||||
LoadFlags |= FT_LOAD_NO_AUTOHINT;
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_ForceAutoHint)
|
|
||||||
LoadFlags |= FT_LOAD_FORCE_AUTOHINT;
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_LightHinting)
|
|
||||||
LoadFlags |= FT_LOAD_TARGET_LIGHT;
|
|
||||||
else if (UserFlags & ImGuiFreeTypeBuilderFlags_MonoHinting)
|
|
||||||
LoadFlags |= FT_LOAD_TARGET_MONO;
|
|
||||||
else
|
|
||||||
LoadFlags |= FT_LOAD_TARGET_NORMAL;
|
|
||||||
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_Monochrome)
|
|
||||||
RenderMode = FT_RENDER_MODE_MONO;
|
|
||||||
else
|
|
||||||
RenderMode = FT_RENDER_MODE_NORMAL;
|
|
||||||
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_LoadColor)
|
|
||||||
LoadFlags |= FT_LOAD_COLOR;
|
|
||||||
|
|
||||||
RasterizationDensity = cfg.RasterizerDensity;
|
|
||||||
InvRasterizationDensity = 1.0f / RasterizationDensity;
|
|
||||||
|
|
||||||
memset(&Info, 0, sizeof(Info));
|
|
||||||
SetPixelHeight((uint32_t)cfg.SizePixels);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FreeTypeFont::CloseFont()
|
|
||||||
{
|
|
||||||
if (Face)
|
|
||||||
{
|
|
||||||
FT_Done_Face(Face);
|
|
||||||
Face = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FreeTypeFont::SetPixelHeight(int pixel_height)
|
|
||||||
{
|
|
||||||
// Vuhdo: I'm not sure how to deal with font sizes properly. As far as I understand, currently ImGui assumes that the 'pixel_height'
|
|
||||||
// is a maximum height of an any given glyph, i.e. it's the sum of font's ascender and descender. Seems strange to me.
|
|
||||||
// NB: FT_Set_Pixel_Sizes() doesn't seem to get us the same result.
|
|
||||||
FT_Size_RequestRec req;
|
|
||||||
req.type = (UserFlags & ImGuiFreeTypeBuilderFlags_Bitmap) ? FT_SIZE_REQUEST_TYPE_NOMINAL : FT_SIZE_REQUEST_TYPE_REAL_DIM;
|
|
||||||
req.width = 0;
|
|
||||||
req.height = (uint32_t)(pixel_height * 64 * RasterizationDensity);
|
|
||||||
req.horiResolution = 0;
|
|
||||||
req.vertResolution = 0;
|
|
||||||
FT_Request_Size(Face, &req);
|
|
||||||
|
|
||||||
// Update font info
|
|
||||||
FT_Size_Metrics metrics = Face->size->metrics;
|
|
||||||
Info.PixelHeight = (uint32_t)(pixel_height * InvRasterizationDensity);
|
|
||||||
Info.Ascender = (float)FT_CEIL(metrics.ascender) * InvRasterizationDensity;
|
|
||||||
Info.Descender = (float)FT_CEIL(metrics.descender) * InvRasterizationDensity;
|
|
||||||
Info.LineSpacing = (float)FT_CEIL(metrics.height) * InvRasterizationDensity;
|
|
||||||
Info.LineGap = (float)FT_CEIL(metrics.height - metrics.ascender + metrics.descender) * InvRasterizationDensity;
|
|
||||||
Info.MaxAdvanceWidth = (float)FT_CEIL(metrics.max_advance) * InvRasterizationDensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FT_Glyph_Metrics* FreeTypeFont::LoadGlyph(uint32_t codepoint)
|
|
||||||
{
|
|
||||||
uint32_t glyph_index = FT_Get_Char_Index(Face, codepoint);
|
|
||||||
if (glyph_index == 0)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// If this crash for you: FreeType 2.11.0 has a crash bug on some bitmap/colored fonts.
|
|
||||||
// - https://gitlab.freedesktop.org/freetype/freetype/-/issues/1076
|
|
||||||
// - https://github.com/ocornut/imgui/issues/4567
|
|
||||||
// - https://github.com/ocornut/imgui/issues/4566
|
|
||||||
// You can use FreeType 2.10, or the patched version of 2.11.0 in VcPkg, or probably any upcoming FreeType version.
|
|
||||||
FT_Error error = FT_Load_Glyph(Face, glyph_index, LoadFlags);
|
|
||||||
if (error)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// Need an outline for this to work
|
|
||||||
FT_GlyphSlot slot = Face->glyph;
|
|
||||||
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP || slot->format == FT_GLYPH_FORMAT_SVG);
|
|
||||||
#else
|
|
||||||
#if ((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12))
|
|
||||||
IM_ASSERT(slot->format != FT_GLYPH_FORMAT_SVG && "The font contains SVG glyphs, you'll need to enable IMGUI_ENABLE_FREETYPE_LUNASVG in imconfig.h and install required libraries in order to use this font");
|
|
||||||
#endif
|
|
||||||
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP);
|
|
||||||
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
|
|
||||||
// Apply convenience transform (this is not picking from real "Bold"/"Italic" fonts! Merely applying FreeType helper transform. Oblique == Slanting)
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_Bold)
|
|
||||||
FT_GlyphSlot_Embolden(slot);
|
|
||||||
if (UserFlags & ImGuiFreeTypeBuilderFlags_Oblique)
|
|
||||||
{
|
|
||||||
FT_GlyphSlot_Oblique(slot);
|
|
||||||
//FT_BBox bbox;
|
|
||||||
//FT_Outline_Get_BBox(&slot->outline, &bbox);
|
|
||||||
//slot->metrics.width = bbox.xMax - bbox.xMin;
|
|
||||||
//slot->metrics.height = bbox.yMax - bbox.yMin;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &slot->metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FT_Bitmap* FreeTypeFont::RenderGlyphAndGetInfo(GlyphInfo* out_glyph_info)
|
|
||||||
{
|
|
||||||
FT_GlyphSlot slot = Face->glyph;
|
|
||||||
FT_Error error = FT_Render_Glyph(slot, RenderMode);
|
|
||||||
if (error != 0)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
FT_Bitmap* ft_bitmap = &Face->glyph->bitmap;
|
|
||||||
out_glyph_info->Width = (int)ft_bitmap->width;
|
|
||||||
out_glyph_info->Height = (int)ft_bitmap->rows;
|
|
||||||
out_glyph_info->OffsetX = Face->glyph->bitmap_left;
|
|
||||||
out_glyph_info->OffsetY = -Face->glyph->bitmap_top;
|
|
||||||
out_glyph_info->AdvanceX = (float)FT_CEIL(slot->advance.x);
|
|
||||||
out_glyph_info->IsColored = (ft_bitmap->pixel_mode == FT_PIXEL_MODE_BGRA);
|
|
||||||
|
|
||||||
return ft_bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FreeTypeFont::BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch, unsigned char* multiply_table)
|
|
||||||
{
|
|
||||||
IM_ASSERT(ft_bitmap != nullptr);
|
|
||||||
const uint32_t w = ft_bitmap->width;
|
|
||||||
const uint32_t h = ft_bitmap->rows;
|
|
||||||
const uint8_t* src = ft_bitmap->buffer;
|
|
||||||
const uint32_t src_pitch = ft_bitmap->pitch;
|
|
||||||
|
|
||||||
switch (ft_bitmap->pixel_mode)
|
|
||||||
{
|
|
||||||
case FT_PIXEL_MODE_GRAY: // Grayscale image, 1 byte per pixel.
|
|
||||||
{
|
|
||||||
if (multiply_table == nullptr)
|
|
||||||
{
|
|
||||||
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
|
||||||
for (uint32_t x = 0; x < w; x++)
|
|
||||||
dst[x] = IM_COL32(255, 255, 255, src[x]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
|
||||||
for (uint32_t x = 0; x < w; x++)
|
|
||||||
dst[x] = IM_COL32(255, 255, 255, multiply_table[src[x]]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FT_PIXEL_MODE_MONO: // Monochrome image, 1 bit per pixel. The bits in each byte are ordered from MSB to LSB.
|
|
||||||
{
|
|
||||||
uint8_t color0 = multiply_table ? multiply_table[0] : 0;
|
|
||||||
uint8_t color1 = multiply_table ? multiply_table[255] : 255;
|
|
||||||
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
|
||||||
{
|
|
||||||
uint8_t bits = 0;
|
|
||||||
const uint8_t* bits_ptr = src;
|
|
||||||
for (uint32_t x = 0; x < w; x++, bits <<= 1)
|
|
||||||
{
|
|
||||||
if ((x & 7) == 0)
|
|
||||||
bits = *bits_ptr++;
|
|
||||||
dst[x] = IM_COL32(255, 255, 255, (bits & 0x80) ? color1 : color0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FT_PIXEL_MODE_BGRA:
|
|
||||||
{
|
|
||||||
// FIXME: Converting pre-multiplied alpha to straight. Doesn't smell good.
|
|
||||||
#define DE_MULTIPLY(color, alpha) ImMin((ImU32)(255.0f * (float)color / (float)(alpha + FLT_MIN) + 0.5f), 255u)
|
|
||||||
if (multiply_table == nullptr)
|
|
||||||
{
|
|
||||||
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
|
||||||
for (uint32_t x = 0; x < w; x++)
|
|
||||||
{
|
|
||||||
uint8_t r = src[x * 4 + 2], g = src[x * 4 + 1], b = src[x * 4], a = src[x * 4 + 3];
|
|
||||||
dst[x] = IM_COL32(DE_MULTIPLY(r, a), DE_MULTIPLY(g, a), DE_MULTIPLY(b, a), a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
|
||||||
{
|
|
||||||
for (uint32_t x = 0; x < w; x++)
|
|
||||||
{
|
|
||||||
uint8_t r = src[x * 4 + 2], g = src[x * 4 + 1], b = src[x * 4], a = src[x * 4 + 3];
|
|
||||||
dst[x] = IM_COL32(multiply_table[DE_MULTIPLY(r, a)], multiply_table[DE_MULTIPLY(g, a)], multiply_table[DE_MULTIPLY(b, a)], multiply_table[a]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#undef DE_MULTIPLY
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
IM_ASSERT(0 && "FreeTypeFont::BlitGlyph(): Unknown bitmap pixel mode!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
#ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
|
|
||||||
#ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
|
||||||
#define STBRP_ASSERT(x) do { IM_ASSERT(x); } while (0)
|
|
||||||
#define STBRP_STATIC
|
|
||||||
#define STB_RECT_PACK_IMPLEMENTATION
|
|
||||||
#endif
|
|
||||||
#ifdef IMGUI_STB_RECT_PACK_FILENAME
|
|
||||||
#include IMGUI_STB_RECT_PACK_FILENAME
|
|
||||||
#else
|
|
||||||
#include "imstb_rectpack.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct ImFontBuildSrcGlyphFT
|
|
||||||
{
|
|
||||||
GlyphInfo Info;
|
|
||||||
uint32_t Codepoint;
|
|
||||||
unsigned int* BitmapData; // Point within one of the dst_tmp_bitmap_buffers[] array
|
|
||||||
|
|
||||||
ImFontBuildSrcGlyphFT() { memset((void*)this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ImFontBuildSrcDataFT
|
|
||||||
{
|
|
||||||
FreeTypeFont Font;
|
|
||||||
stbrp_rect* Rects; // Rectangle to pack. We first fill in their size and the packer will give us their position.
|
|
||||||
const ImWchar* SrcRanges; // Ranges as requested by user (user is allowed to request too much, e.g. 0x0020..0xFFFF)
|
|
||||||
int DstIndex; // Index into atlas->Fonts[] and dst_tmp_array[]
|
|
||||||
int GlyphsHighest; // Highest requested codepoint
|
|
||||||
int GlyphsCount; // Glyph count (excluding missing glyphs and glyphs already set by an earlier source font)
|
|
||||||
ImBitVector GlyphsSet; // Glyph bit map (random access, 1-bit per codepoint. This will be a maximum of 8KB)
|
|
||||||
ImVector<ImFontBuildSrcGlyphFT> GlyphsList;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Temporary data for one destination ImFont* (multiple source fonts can be merged into one destination ImFont)
|
|
||||||
struct ImFontBuildDstDataFT
|
|
||||||
{
|
|
||||||
int SrcCount; // Number of source fonts targeting this destination font.
|
|
||||||
int GlyphsHighest;
|
|
||||||
int GlyphsCount;
|
|
||||||
ImBitVector GlyphsSet; // This is used to resolve collision when multiple sources are merged into a same destination font.
|
|
||||||
};
|
|
||||||
|
|
||||||
bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, unsigned int extra_flags)
|
|
||||||
{
|
|
||||||
IM_ASSERT(atlas->ConfigData.Size > 0);
|
|
||||||
|
|
||||||
ImFontAtlasBuildInit(atlas);
|
|
||||||
|
|
||||||
// Clear atlas
|
|
||||||
atlas->TexID = 0;
|
|
||||||
atlas->TexWidth = atlas->TexHeight = 0;
|
|
||||||
atlas->TexUvScale = ImVec2(0.0f, 0.0f);
|
|
||||||
atlas->TexUvWhitePixel = ImVec2(0.0f, 0.0f);
|
|
||||||
atlas->ClearTexData();
|
|
||||||
|
|
||||||
// Temporary storage for building
|
|
||||||
bool src_load_color = false;
|
|
||||||
ImVector<ImFontBuildSrcDataFT> src_tmp_array;
|
|
||||||
ImVector<ImFontBuildDstDataFT> dst_tmp_array;
|
|
||||||
src_tmp_array.resize(atlas->ConfigData.Size);
|
|
||||||
dst_tmp_array.resize(atlas->Fonts.Size);
|
|
||||||
memset((void*)src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
|
|
||||||
memset((void*)dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
|
|
||||||
|
|
||||||
// 1. Initialize font loading structure, check font data validity
|
|
||||||
for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
|
|
||||||
ImFontConfig& cfg = atlas->ConfigData[src_i];
|
|
||||||
FreeTypeFont& font_face = src_tmp.Font;
|
|
||||||
IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas));
|
|
||||||
|
|
||||||
// Find index from cfg.DstFont (we allow the user to set cfg.DstFont. Also it makes casual debugging nicer than when storing indices)
|
|
||||||
src_tmp.DstIndex = -1;
|
|
||||||
for (int output_i = 0; output_i < atlas->Fonts.Size && src_tmp.DstIndex == -1; output_i++)
|
|
||||||
if (cfg.DstFont == atlas->Fonts[output_i])
|
|
||||||
src_tmp.DstIndex = output_i;
|
|
||||||
IM_ASSERT(src_tmp.DstIndex != -1); // cfg.DstFont not pointing within atlas->Fonts[] array?
|
|
||||||
if (src_tmp.DstIndex == -1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Load font
|
|
||||||
if (!font_face.InitFont(ft_library, cfg, extra_flags))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Measure highest codepoints
|
|
||||||
src_load_color |= (cfg.FontBuilderFlags & ImGuiFreeTypeBuilderFlags_LoadColor) != 0;
|
|
||||||
ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
|
|
||||||
src_tmp.SrcRanges = cfg.GlyphRanges ? cfg.GlyphRanges : atlas->GetGlyphRangesDefault();
|
|
||||||
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
|
|
||||||
{
|
|
||||||
// Check for valid range. This may also help detect *some* dangling pointers, because a common
|
|
||||||
// user error is to setup ImFontConfig::GlyphRanges with a pointer to data that isn't persistent,
|
|
||||||
// or to forget to zero-terminate the glyph range array.
|
|
||||||
IM_ASSERT(src_range[0] <= src_range[1] && "Invalid range: is your glyph range array persistent? it is zero-terminated?");
|
|
||||||
src_tmp.GlyphsHighest = ImMax(src_tmp.GlyphsHighest, (int)src_range[1]);
|
|
||||||
}
|
|
||||||
dst_tmp.SrcCount++;
|
|
||||||
dst_tmp.GlyphsHighest = ImMax(dst_tmp.GlyphsHighest, src_tmp.GlyphsHighest);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. For every requested codepoint, check for their presence in the font data, and handle redundancy or overlaps between source fonts to avoid unused glyphs.
|
|
||||||
int total_glyphs_count = 0;
|
|
||||||
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
|
|
||||||
ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
|
|
||||||
src_tmp.GlyphsSet.Create(src_tmp.GlyphsHighest + 1);
|
|
||||||
if (dst_tmp.GlyphsSet.Storage.empty())
|
|
||||||
dst_tmp.GlyphsSet.Create(dst_tmp.GlyphsHighest + 1);
|
|
||||||
|
|
||||||
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
|
|
||||||
for (int codepoint = src_range[0]; codepoint <= (int)src_range[1]; codepoint++)
|
|
||||||
{
|
|
||||||
if (dst_tmp.GlyphsSet.TestBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite)
|
|
||||||
continue;
|
|
||||||
uint32_t glyph_index = FT_Get_Char_Index(src_tmp.Font.Face, codepoint); // It is actually in the font? (FIXME-OPT: We are not storing the glyph_index..)
|
|
||||||
if (glyph_index == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Add to avail set/counters
|
|
||||||
src_tmp.GlyphsCount++;
|
|
||||||
dst_tmp.GlyphsCount++;
|
|
||||||
src_tmp.GlyphsSet.SetBit(codepoint);
|
|
||||||
dst_tmp.GlyphsSet.SetBit(codepoint);
|
|
||||||
total_glyphs_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Unpack our bit map into a flat list (we now have all the Unicode points that we know are requested _and_ available _and_ not overlapping another)
|
|
||||||
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
|
|
||||||
src_tmp.GlyphsList.reserve(src_tmp.GlyphsCount);
|
|
||||||
|
|
||||||
IM_ASSERT(sizeof(src_tmp.GlyphsSet.Storage.Data[0]) == sizeof(ImU32));
|
|
||||||
const ImU32* it_begin = src_tmp.GlyphsSet.Storage.begin();
|
|
||||||
const ImU32* it_end = src_tmp.GlyphsSet.Storage.end();
|
|
||||||
for (const ImU32* it = it_begin; it < it_end; it++)
|
|
||||||
if (ImU32 entries_32 = *it)
|
|
||||||
for (ImU32 bit_n = 0; bit_n < 32; bit_n++)
|
|
||||||
if (entries_32 & ((ImU32)1 << bit_n))
|
|
||||||
{
|
|
||||||
ImFontBuildSrcGlyphFT src_glyph;
|
|
||||||
src_glyph.Codepoint = (ImWchar)(((it - it_begin) << 5) + bit_n);
|
|
||||||
//src_glyph.GlyphIndex = 0; // FIXME-OPT: We had this info in the previous step and lost it..
|
|
||||||
src_tmp.GlyphsList.push_back(src_glyph);
|
|
||||||
}
|
|
||||||
src_tmp.GlyphsSet.Clear();
|
|
||||||
IM_ASSERT(src_tmp.GlyphsList.Size == src_tmp.GlyphsCount);
|
|
||||||
}
|
|
||||||
for (int dst_i = 0; dst_i < dst_tmp_array.Size; dst_i++)
|
|
||||||
dst_tmp_array[dst_i].GlyphsSet.Clear();
|
|
||||||
dst_tmp_array.clear();
|
|
||||||
|
|
||||||
// Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
|
|
||||||
// (We technically don't need to zero-clear buf_rects, but let's do it for the sake of sanity)
|
|
||||||
ImVector<stbrp_rect> buf_rects;
|
|
||||||
buf_rects.resize(total_glyphs_count);
|
|
||||||
memset(buf_rects.Data, 0, (size_t)buf_rects.size_in_bytes());
|
|
||||||
|
|
||||||
// Allocate temporary rasterization data buffers.
|
|
||||||
// We could not find a way to retrieve accurate glyph size without rendering them.
|
|
||||||
// (e.g. slot->metrics->width not always matching bitmap->width, especially considering the Oblique transform)
|
|
||||||
// We allocate in chunks of 256 KB to not waste too much extra memory ahead. Hopefully users of FreeType won't mind the temporary allocations.
|
|
||||||
const int BITMAP_BUFFERS_CHUNK_SIZE = 256 * 1024;
|
|
||||||
int buf_bitmap_current_used_bytes = 0;
|
|
||||||
ImVector<unsigned char*> buf_bitmap_buffers;
|
|
||||||
buf_bitmap_buffers.push_back((unsigned char*)IM_ALLOC(BITMAP_BUFFERS_CHUNK_SIZE));
|
|
||||||
|
|
||||||
// 4. Gather glyphs sizes so we can pack them in our virtual canvas.
|
|
||||||
// 8. Render/rasterize font characters into the texture
|
|
||||||
int total_surface = 0;
|
|
||||||
int buf_rects_out_n = 0;
|
|
||||||
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
|
|
||||||
ImFontConfig& cfg = atlas->ConfigData[src_i];
|
|
||||||
if (src_tmp.GlyphsCount == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
src_tmp.Rects = &buf_rects[buf_rects_out_n];
|
|
||||||
buf_rects_out_n += src_tmp.GlyphsCount;
|
|
||||||
|
|
||||||
// Compute multiply table if requested
|
|
||||||
const bool multiply_enabled = (cfg.RasterizerMultiply != 1.0f);
|
|
||||||
unsigned char multiply_table[256];
|
|
||||||
if (multiply_enabled)
|
|
||||||
ImFontAtlasBuildMultiplyCalcLookupTable(multiply_table, cfg.RasterizerMultiply);
|
|
||||||
|
|
||||||
// Gather the sizes of all rectangles we will need to pack
|
|
||||||
const int padding = atlas->TexGlyphPadding;
|
|
||||||
for (int glyph_i = 0; glyph_i < src_tmp.GlyphsList.Size; glyph_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcGlyphFT& src_glyph = src_tmp.GlyphsList[glyph_i];
|
|
||||||
|
|
||||||
const FT_Glyph_Metrics* metrics = src_tmp.Font.LoadGlyph(src_glyph.Codepoint);
|
|
||||||
if (metrics == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Render glyph into a bitmap (currently held by FreeType)
|
|
||||||
const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(&src_glyph.Info);
|
|
||||||
if (ft_bitmap == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Allocate new temporary chunk if needed
|
|
||||||
const int bitmap_size_in_bytes = src_glyph.Info.Width * src_glyph.Info.Height * 4;
|
|
||||||
if (buf_bitmap_current_used_bytes + bitmap_size_in_bytes > BITMAP_BUFFERS_CHUNK_SIZE)
|
|
||||||
{
|
|
||||||
buf_bitmap_current_used_bytes = 0;
|
|
||||||
buf_bitmap_buffers.push_back((unsigned char*)IM_ALLOC(BITMAP_BUFFERS_CHUNK_SIZE));
|
|
||||||
}
|
|
||||||
IM_ASSERT(buf_bitmap_current_used_bytes + bitmap_size_in_bytes <= BITMAP_BUFFERS_CHUNK_SIZE); // We could probably allocate custom-sized buffer instead.
|
|
||||||
|
|
||||||
// Blit rasterized pixels to our temporary buffer and keep a pointer to it.
|
|
||||||
src_glyph.BitmapData = (unsigned int*)(buf_bitmap_buffers.back() + buf_bitmap_current_used_bytes);
|
|
||||||
buf_bitmap_current_used_bytes += bitmap_size_in_bytes;
|
|
||||||
src_tmp.Font.BlitGlyph(ft_bitmap, src_glyph.BitmapData, src_glyph.Info.Width, multiply_enabled ? multiply_table : nullptr);
|
|
||||||
|
|
||||||
src_tmp.Rects[glyph_i].w = (stbrp_coord)(src_glyph.Info.Width + padding);
|
|
||||||
src_tmp.Rects[glyph_i].h = (stbrp_coord)(src_glyph.Info.Height + padding);
|
|
||||||
total_surface += src_tmp.Rects[glyph_i].w * src_tmp.Rects[glyph_i].h;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need a width for the skyline algorithm, any width!
|
|
||||||
// The exact width doesn't really matter much, but some API/GPU have texture size limitations and increasing width can decrease height.
|
|
||||||
// User can override TexDesiredWidth and TexGlyphPadding if they wish, otherwise we use a simple heuristic to select the width based on expected surface.
|
|
||||||
const int surface_sqrt = (int)ImSqrt((float)total_surface) + 1;
|
|
||||||
atlas->TexHeight = 0;
|
|
||||||
if (atlas->TexDesiredWidth > 0)
|
|
||||||
atlas->TexWidth = atlas->TexDesiredWidth;
|
|
||||||
else
|
|
||||||
atlas->TexWidth = (surface_sqrt >= 4096 * 0.7f) ? 4096 : (surface_sqrt >= 2048 * 0.7f) ? 2048 : (surface_sqrt >= 1024 * 0.7f) ? 1024 : 512;
|
|
||||||
|
|
||||||
// 5. Start packing
|
|
||||||
// Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values).
|
|
||||||
const int TEX_HEIGHT_MAX = 1024 * 32;
|
|
||||||
const int num_nodes_for_packing_algorithm = atlas->TexWidth - atlas->TexGlyphPadding;
|
|
||||||
ImVector<stbrp_node> pack_nodes;
|
|
||||||
pack_nodes.resize(num_nodes_for_packing_algorithm);
|
|
||||||
stbrp_context pack_context;
|
|
||||||
stbrp_init_target(&pack_context, atlas->TexWidth - atlas->TexGlyphPadding, TEX_HEIGHT_MAX - atlas->TexGlyphPadding, pack_nodes.Data, pack_nodes.Size);
|
|
||||||
ImFontAtlasBuildPackCustomRects(atlas, &pack_context);
|
|
||||||
|
|
||||||
// 6. Pack each source font. No rendering yet, we are working with rectangles in an infinitely tall texture at this point.
|
|
||||||
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
|
|
||||||
if (src_tmp.GlyphsCount == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
stbrp_pack_rects(&pack_context, src_tmp.Rects, src_tmp.GlyphsCount);
|
|
||||||
|
|
||||||
// Extend texture height and mark missing glyphs as non-packed so we won't render them.
|
|
||||||
// FIXME: We are not handling packing failure here (would happen if we got off TEX_HEIGHT_MAX or if a single if larger than TexWidth?)
|
|
||||||
for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++)
|
|
||||||
if (src_tmp.Rects[glyph_i].was_packed)
|
|
||||||
atlas->TexHeight = ImMax(atlas->TexHeight, src_tmp.Rects[glyph_i].y + src_tmp.Rects[glyph_i].h);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. Allocate texture
|
|
||||||
atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight);
|
|
||||||
atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight);
|
|
||||||
if (src_load_color)
|
|
||||||
{
|
|
||||||
size_t tex_size = (size_t)atlas->TexWidth * atlas->TexHeight * 4;
|
|
||||||
atlas->TexPixelsRGBA32 = (unsigned int*)IM_ALLOC(tex_size);
|
|
||||||
memset(atlas->TexPixelsRGBA32, 0, tex_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t tex_size = (size_t)atlas->TexWidth * atlas->TexHeight * 1;
|
|
||||||
atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(tex_size);
|
|
||||||
memset(atlas->TexPixelsAlpha8, 0, tex_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8. Copy rasterized font characters back into the main texture
|
|
||||||
// 9. Setup ImFont and glyphs for runtime
|
|
||||||
bool tex_use_colors = false;
|
|
||||||
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
|
|
||||||
if (src_tmp.GlyphsCount == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// When merging fonts with MergeMode=true:
|
|
||||||
// - We can have multiple input fonts writing into a same destination font.
|
|
||||||
// - dst_font->ConfigData is != from cfg which is our source configuration.
|
|
||||||
ImFontConfig& cfg = atlas->ConfigData[src_i];
|
|
||||||
ImFont* dst_font = cfg.DstFont;
|
|
||||||
|
|
||||||
const float ascent = src_tmp.Font.Info.Ascender;
|
|
||||||
const float descent = src_tmp.Font.Info.Descender;
|
|
||||||
ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent);
|
|
||||||
const float font_off_x = cfg.GlyphOffset.x;
|
|
||||||
const float font_off_y = cfg.GlyphOffset.y + IM_ROUND(dst_font->Ascent);
|
|
||||||
|
|
||||||
const int padding = atlas->TexGlyphPadding;
|
|
||||||
for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++)
|
|
||||||
{
|
|
||||||
ImFontBuildSrcGlyphFT& src_glyph = src_tmp.GlyphsList[glyph_i];
|
|
||||||
stbrp_rect& pack_rect = src_tmp.Rects[glyph_i];
|
|
||||||
IM_ASSERT(pack_rect.was_packed);
|
|
||||||
if (pack_rect.w == 0 && pack_rect.h == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
GlyphInfo& info = src_glyph.Info;
|
|
||||||
IM_ASSERT(info.Width + padding <= pack_rect.w);
|
|
||||||
IM_ASSERT(info.Height + padding <= pack_rect.h);
|
|
||||||
const int tx = pack_rect.x + padding;
|
|
||||||
const int ty = pack_rect.y + padding;
|
|
||||||
|
|
||||||
// Register glyph
|
|
||||||
float x0 = info.OffsetX * src_tmp.Font.InvRasterizationDensity + font_off_x;
|
|
||||||
float y0 = info.OffsetY * src_tmp.Font.InvRasterizationDensity + font_off_y;
|
|
||||||
float x1 = x0 + info.Width * src_tmp.Font.InvRasterizationDensity;
|
|
||||||
float y1 = y0 + info.Height * src_tmp.Font.InvRasterizationDensity;
|
|
||||||
float u0 = (tx) / (float)atlas->TexWidth;
|
|
||||||
float v0 = (ty) / (float)atlas->TexHeight;
|
|
||||||
float u1 = (tx + info.Width) / (float)atlas->TexWidth;
|
|
||||||
float v1 = (ty + info.Height) / (float)atlas->TexHeight;
|
|
||||||
dst_font->AddGlyph(&cfg, (ImWchar)src_glyph.Codepoint, x0, y0, x1, y1, u0, v0, u1, v1, info.AdvanceX * src_tmp.Font.InvRasterizationDensity);
|
|
||||||
|
|
||||||
ImFontGlyph* dst_glyph = &dst_font->Glyphs.back();
|
|
||||||
IM_ASSERT(dst_glyph->Codepoint == src_glyph.Codepoint);
|
|
||||||
if (src_glyph.Info.IsColored)
|
|
||||||
dst_glyph->Colored = tex_use_colors = true;
|
|
||||||
|
|
||||||
// Blit from temporary buffer to final texture
|
|
||||||
size_t blit_src_stride = (size_t)src_glyph.Info.Width;
|
|
||||||
size_t blit_dst_stride = (size_t)atlas->TexWidth;
|
|
||||||
unsigned int* blit_src = src_glyph.BitmapData;
|
|
||||||
if (atlas->TexPixelsAlpha8 != nullptr)
|
|
||||||
{
|
|
||||||
unsigned char* blit_dst = atlas->TexPixelsAlpha8 + (ty * blit_dst_stride) + tx;
|
|
||||||
for (int y = 0; y < info.Height; y++, blit_dst += blit_dst_stride, blit_src += blit_src_stride)
|
|
||||||
for (int x = 0; x < info.Width; x++)
|
|
||||||
blit_dst[x] = (unsigned char)((blit_src[x] >> IM_COL32_A_SHIFT) & 0xFF);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsigned int* blit_dst = atlas->TexPixelsRGBA32 + (ty * blit_dst_stride) + tx;
|
|
||||||
for (int y = 0; y < info.Height; y++, blit_dst += blit_dst_stride, blit_src += blit_src_stride)
|
|
||||||
for (int x = 0; x < info.Width; x++)
|
|
||||||
blit_dst[x] = blit_src[x];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
src_tmp.Rects = nullptr;
|
|
||||||
}
|
|
||||||
atlas->TexPixelsUseColors = tex_use_colors;
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
for (int buf_i = 0; buf_i < buf_bitmap_buffers.Size; buf_i++)
|
|
||||||
IM_FREE(buf_bitmap_buffers[buf_i]);
|
|
||||||
src_tmp_array.clear_destruct();
|
|
||||||
|
|
||||||
ImFontAtlasBuildFinish(atlas);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FreeType memory allocation callbacks
|
|
||||||
static void* FreeType_Alloc(FT_Memory /*memory*/, long size)
|
|
||||||
{
|
|
||||||
return GImGuiFreeTypeAllocFunc((size_t)size, GImGuiFreeTypeAllocatorUserData);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void FreeType_Free(FT_Memory /*memory*/, void* block)
|
|
||||||
{
|
|
||||||
GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void* FreeType_Realloc(FT_Memory /*memory*/, long cur_size, long new_size, void* block)
|
|
||||||
{
|
|
||||||
// Implement realloc() as we don't ask user to provide it.
|
|
||||||
if (block == nullptr)
|
|
||||||
return GImGuiFreeTypeAllocFunc((size_t)new_size, GImGuiFreeTypeAllocatorUserData);
|
|
||||||
|
|
||||||
if (new_size == 0)
|
|
||||||
{
|
|
||||||
GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_size > cur_size)
|
|
||||||
{
|
|
||||||
void* new_block = GImGuiFreeTypeAllocFunc((size_t)new_size, GImGuiFreeTypeAllocatorUserData);
|
|
||||||
memcpy(new_block, block, (size_t)cur_size);
|
|
||||||
GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
|
|
||||||
return new_block;
|
|
||||||
}
|
|
||||||
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ImFontAtlasBuildWithFreeType(ImFontAtlas* atlas)
|
|
||||||
{
|
|
||||||
// FreeType memory management: https://www.freetype.org/freetype2/docs/design/design-4.html
|
|
||||||
FT_MemoryRec_ memory_rec = {};
|
|
||||||
memory_rec.user = nullptr;
|
|
||||||
memory_rec.alloc = &FreeType_Alloc;
|
|
||||||
memory_rec.free = &FreeType_Free;
|
|
||||||
memory_rec.realloc = &FreeType_Realloc;
|
|
||||||
|
|
||||||
// https://www.freetype.org/freetype2/docs/reference/ft2-module_management.html#FT_New_Library
|
|
||||||
FT_Library ft_library;
|
|
||||||
FT_Error error = FT_New_Library(&memory_rec, &ft_library);
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// If you don't call FT_Add_Default_Modules() the rest of code may work, but FreeType won't use our custom allocator.
|
|
||||||
FT_Add_Default_Modules(ft_library);
|
|
||||||
|
|
||||||
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
// Install svg hooks for FreeType
|
|
||||||
// https://freetype.org/freetype2/docs/reference/ft2-properties.html#svg-hooks
|
|
||||||
// https://freetype.org/freetype2/docs/reference/ft2-svg_fonts.html#svg_fonts
|
|
||||||
SVG_RendererHooks hooks = { ImGuiLunasvgPortInit, ImGuiLunasvgPortFree, ImGuiLunasvgPortRender, ImGuiLunasvgPortPresetSlot };
|
|
||||||
FT_Property_Set(ft_library, "ot-svg", "svg-hooks", &hooks);
|
|
||||||
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
|
|
||||||
bool ret = ImFontAtlasBuildWithFreeTypeEx(ft_library, atlas, atlas->FontBuilderFlags);
|
|
||||||
FT_Done_Library(ft_library);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ImFontBuilderIO* ImGuiFreeType::GetBuilderForFreeType()
|
|
||||||
{
|
|
||||||
static ImFontBuilderIO io;
|
|
||||||
io.FontBuilder_Build = ImFontAtlasBuildWithFreeType;
|
|
||||||
return &io;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiFreeType::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data)
|
|
||||||
{
|
|
||||||
GImGuiFreeTypeAllocFunc = alloc_func;
|
|
||||||
GImGuiFreeTypeFreeFunc = free_func;
|
|
||||||
GImGuiFreeTypeAllocatorUserData = user_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
// For more details, see https://gitlab.freedesktop.org/freetype/freetype-demos/-/blob/master/src/rsvg-port.c
|
|
||||||
// The original code from the demo is licensed under CeCILL-C Free Software License Agreement (https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/LICENSE.TXT)
|
|
||||||
struct LunasvgPortState
|
|
||||||
{
|
|
||||||
FT_Error err = FT_Err_Ok;
|
|
||||||
lunasvg::Matrix matrix;
|
|
||||||
std::unique_ptr<lunasvg::Document> svg = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
static FT_Error ImGuiLunasvgPortInit(FT_Pointer* _state)
|
|
||||||
{
|
|
||||||
*_state = IM_NEW(LunasvgPortState)();
|
|
||||||
return FT_Err_Ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGuiLunasvgPortFree(FT_Pointer* _state)
|
|
||||||
{
|
|
||||||
IM_DELETE(*(LunasvgPortState**)_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
static FT_Error ImGuiLunasvgPortRender(FT_GlyphSlot slot, FT_Pointer* _state)
|
|
||||||
{
|
|
||||||
LunasvgPortState* state = *(LunasvgPortState**)_state;
|
|
||||||
|
|
||||||
// If there was an error while loading the svg in ImGuiLunasvgPortPresetSlot(), the renderer hook still get called, so just returns the error.
|
|
||||||
if (state->err != FT_Err_Ok)
|
|
||||||
return state->err;
|
|
||||||
|
|
||||||
// rows is height, pitch (or stride) equals to width * sizeof(int32)
|
|
||||||
lunasvg::Bitmap bitmap((uint8_t*)slot->bitmap.buffer, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.pitch);
|
|
||||||
state->svg->setMatrix(state->svg->matrix().identity()); // Reset the svg matrix to the default value
|
|
||||||
state->svg->render(bitmap, state->matrix); // state->matrix is already scaled and translated
|
|
||||||
state->err = FT_Err_Ok;
|
|
||||||
return state->err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FT_Error ImGuiLunasvgPortPresetSlot(FT_GlyphSlot slot, FT_Bool cache, FT_Pointer* _state)
|
|
||||||
{
|
|
||||||
FT_SVG_Document document = (FT_SVG_Document)slot->other;
|
|
||||||
LunasvgPortState* state = *(LunasvgPortState**)_state;
|
|
||||||
FT_Size_Metrics& metrics = document->metrics;
|
|
||||||
|
|
||||||
// This function is called twice, once in the FT_Load_Glyph() and another right before ImGuiLunasvgPortRender().
|
|
||||||
// If it's the latter, don't do anything because it's // already done in the former.
|
|
||||||
if (cache)
|
|
||||||
return state->err;
|
|
||||||
|
|
||||||
state->svg = lunasvg::Document::loadFromData((const char*)document->svg_document, document->svg_document_length);
|
|
||||||
if (state->svg == nullptr)
|
|
||||||
{
|
|
||||||
state->err = FT_Err_Invalid_SVG_Document;
|
|
||||||
return state->err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lunasvg::Box box = state->svg->box();
|
|
||||||
double scale = std::min(metrics.x_ppem / box.w, metrics.y_ppem / box.h);
|
|
||||||
double xx = (double)document->transform.xx / (1 << 16);
|
|
||||||
double xy = -(double)document->transform.xy / (1 << 16);
|
|
||||||
double yx = -(double)document->transform.yx / (1 << 16);
|
|
||||||
double yy = (double)document->transform.yy / (1 << 16);
|
|
||||||
double x0 = (double)document->delta.x / 64 * box.w / metrics.x_ppem;
|
|
||||||
double y0 = -(double)document->delta.y / 64 * box.h / metrics.y_ppem;
|
|
||||||
|
|
||||||
// Scale and transform, we don't translate the svg yet
|
|
||||||
state->matrix.identity();
|
|
||||||
state->matrix.scale(scale, scale);
|
|
||||||
state->matrix.transform(xx, xy, yx, yy, x0, y0);
|
|
||||||
state->svg->setMatrix(state->matrix);
|
|
||||||
|
|
||||||
// Pre-translate the matrix for the rendering step
|
|
||||||
state->matrix.translate(-box.x, -box.y);
|
|
||||||
|
|
||||||
// Get the box again after the transformation
|
|
||||||
box = state->svg->box();
|
|
||||||
|
|
||||||
// Calculate the bitmap size
|
|
||||||
slot->bitmap_left = FT_Int(box.x);
|
|
||||||
slot->bitmap_top = FT_Int(-box.y);
|
|
||||||
slot->bitmap.rows = (unsigned int)(ImCeil((float)box.h));
|
|
||||||
slot->bitmap.width = (unsigned int)(ImCeil((float)box.w));
|
|
||||||
slot->bitmap.pitch = slot->bitmap.width * 4;
|
|
||||||
slot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA;
|
|
||||||
|
|
||||||
// Compute all the bearings and set them correctly. The outline is scaled already, we just need to use the bounding box.
|
|
||||||
double metrics_width = box.w;
|
|
||||||
double metrics_height = box.h;
|
|
||||||
double horiBearingX = box.x;
|
|
||||||
double horiBearingY = -box.y;
|
|
||||||
double vertBearingX = slot->metrics.horiBearingX / 64.0 - slot->metrics.horiAdvance / 64.0 / 2.0;
|
|
||||||
double vertBearingY = (slot->metrics.vertAdvance / 64.0 - slot->metrics.height / 64.0) / 2.0;
|
|
||||||
slot->metrics.width = FT_Pos(IM_ROUND(metrics_width * 64.0)); // Using IM_ROUND() assume width and height are positive
|
|
||||||
slot->metrics.height = FT_Pos(IM_ROUND(metrics_height * 64.0));
|
|
||||||
slot->metrics.horiBearingX = FT_Pos(horiBearingX * 64);
|
|
||||||
slot->metrics.horiBearingY = FT_Pos(horiBearingY * 64);
|
|
||||||
slot->metrics.vertBearingX = FT_Pos(vertBearingX * 64);
|
|
||||||
slot->metrics.vertBearingY = FT_Pos(vertBearingY * 64);
|
|
||||||
|
|
||||||
if (slot->metrics.vertAdvance == 0)
|
|
||||||
slot->metrics.vertAdvance = FT_Pos(metrics_height * 1.2 * 64.0);
|
|
||||||
|
|
||||||
state->err = FT_Err_Ok;
|
|
||||||
return state->err;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // #ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning (pop)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,51 +0,0 @@
|
|||||||
// dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder)
|
|
||||||
// (headers)
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "imgui.h" // IMGUI_API
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
struct ImFontAtlas;
|
|
||||||
struct ImFontBuilderIO;
|
|
||||||
|
|
||||||
// Hinting greatly impacts visuals (and glyph sizes).
|
|
||||||
// - By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter.
|
|
||||||
// - When disabled, FreeType generates blurrier glyphs, more or less matches the stb_truetype.h
|
|
||||||
// - The Default hinting mode usually looks good, but may distort glyphs in an unusual way.
|
|
||||||
// - The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer.
|
|
||||||
// You can set those flags globaly in ImFontAtlas::FontBuilderFlags
|
|
||||||
// You can set those flags on a per font basis in ImFontConfig::FontBuilderFlags
|
|
||||||
enum ImGuiFreeTypeBuilderFlags
|
|
||||||
{
|
|
||||||
ImGuiFreeTypeBuilderFlags_NoHinting = 1 << 0, // Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes.
|
|
||||||
ImGuiFreeTypeBuilderFlags_NoAutoHint = 1 << 1, // Disable auto-hinter.
|
|
||||||
ImGuiFreeTypeBuilderFlags_ForceAutoHint = 1 << 2, // Indicates that the auto-hinter is preferred over the font's native hinter.
|
|
||||||
ImGuiFreeTypeBuilderFlags_LightHinting = 1 << 3, // A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. This preserves inter-glyph spacing in horizontal text.
|
|
||||||
ImGuiFreeTypeBuilderFlags_MonoHinting = 1 << 4, // Strong hinting algorithm that should only be used for monochrome output.
|
|
||||||
ImGuiFreeTypeBuilderFlags_Bold = 1 << 5, // Styling: Should we artificially embolden the font?
|
|
||||||
ImGuiFreeTypeBuilderFlags_Oblique = 1 << 6, // Styling: Should we slant the font, emulating italic style?
|
|
||||||
ImGuiFreeTypeBuilderFlags_Monochrome = 1 << 7, // Disable anti-aliasing. Combine this with MonoHinting for best results!
|
|
||||||
ImGuiFreeTypeBuilderFlags_LoadColor = 1 << 8, // Enable FreeType color-layered glyphs
|
|
||||||
ImGuiFreeTypeBuilderFlags_Bitmap = 1 << 9 // Enable FreeType bitmap glyphs
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace ImGuiFreeType
|
|
||||||
{
|
|
||||||
// This is automatically assigned when using '#define IMGUI_ENABLE_FREETYPE'.
|
|
||||||
// If you need to dynamically select between multiple builders:
|
|
||||||
// - you can manually assign this builder with 'atlas->FontBuilderIO = ImGuiFreeType::GetBuilderForFreeType()'
|
|
||||||
// - prefer deep-copying this into your own ImFontBuilderIO instance if you use hot-reloading that messes up static data.
|
|
||||||
IMGUI_API const ImFontBuilderIO* GetBuilderForFreeType();
|
|
||||||
|
|
||||||
// Override allocators. By default ImGuiFreeType will use IM_ALLOC()/IM_FREE()
|
|
||||||
// However, as FreeType does lots of allocations we provide a way for the user to redirect it to a separate memory heap if desired.
|
|
||||||
IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = nullptr);
|
|
||||||
|
|
||||||
// Obsolete names (will be removed soon)
|
|
||||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
|
||||||
//static inline bool BuildFontAtlas(ImFontAtlas* atlas, unsigned int flags = 0) { atlas->FontBuilderIO = GetBuilderForFreeType(); atlas->FontBuilderFlags = flags; return atlas->Build(); } // Prefer using '#define IMGUI_ENABLE_FREETYPE'
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -81,7 +81,6 @@ set(SERVER_FILES
|
|||||||
list(TRANSFORM SERVER_FILES PREPEND "src/profiler/")
|
list(TRANSFORM SERVER_FILES PREPEND "src/profiler/")
|
||||||
|
|
||||||
set(PROFILER_FILES
|
set(PROFILER_FILES
|
||||||
src/imgui/imgui_impl_opengl3.cpp
|
|
||||||
src/ConnectionHistory.cpp
|
src/ConnectionHistory.cpp
|
||||||
src/Filters.cpp
|
src/Filters.cpp
|
||||||
src/Fonts.cpp
|
src/Fonts.cpp
|
||||||
@ -151,7 +150,7 @@ elseif(EMSCRIPTEN)
|
|||||||
else()
|
else()
|
||||||
set(PROFILER_FILES ${PROFILER_FILES}
|
set(PROFILER_FILES ${PROFILER_FILES}
|
||||||
src/BackendGlfw.cpp
|
src/BackendGlfw.cpp
|
||||||
src/imgui/imgui_impl_glfw.cpp
|
${ImGui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
#include <EGL/eglext.h>
|
#include <EGL/eglext.h>
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
#include <emscripten/html5.h>
|
#include <emscripten/html5.h>
|
||||||
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
#include "imgui/imgui_impl_opengl3.h"
|
|
||||||
|
|
||||||
#include "Backend.hpp"
|
#include "Backend.hpp"
|
||||||
#include "RunQueue.hpp"
|
#include "RunQueue.hpp"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "imgui/imgui_impl_glfw.h"
|
#include <backends/imgui_impl_glfw.h>
|
||||||
#include "imgui/imgui_impl_opengl3.h"
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
#include "imgui/imgui_impl_opengl3_loader.h"
|
#include <backends/imgui_impl_opengl3_loader.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <EGL/eglext.h>
|
#include <EGL/eglext.h>
|
||||||
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
#include "imgui/imgui_impl_opengl3.h"
|
#include <backends/imgui_impl_opengl3_loader.h>
|
||||||
#include "imgui/imgui_impl_opengl3_loader.h"
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <linux/input-event-codes.h>
|
#include <linux/input-event-codes.h>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
|
#include <misc/freetype/imgui_freetype.h>
|
||||||
|
|
||||||
#include "Fonts.hpp"
|
#include "Fonts.hpp"
|
||||||
#include "misc/freetype/imgui_freetype.h"
|
|
||||||
#include "imgui/imgui_impl_opengl3.h"
|
|
||||||
#include "profiler/IconsFontAwesome6.h"
|
#include "profiler/IconsFontAwesome6.h"
|
||||||
|
|
||||||
#include "font/DroidSans.hpp"
|
#include "font/DroidSans.hpp"
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,67 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for GLFW
|
|
||||||
// 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.)
|
|
||||||
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Clipboard support.
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
|
|
||||||
// [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: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
|
||||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
|
||||||
// Issues:
|
|
||||||
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
// Learn about Dear ImGui:
|
|
||||||
// - FAQ https://dearimgui.com/faq
|
|
||||||
// - Getting Started https://dearimgui.com/getting-started
|
|
||||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
|
||||||
// - Introduction, links and more at the top of imgui.cpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
|
|
||||||
struct GLFWwindow;
|
|
||||||
struct GLFWmonitor;
|
|
||||||
|
|
||||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
|
||||||
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_InitForOther(GLFWwindow* window, bool install_callbacks);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
|
|
||||||
|
|
||||||
// Emscripten related initialization phase methods (call after ImGui_ImplGlfw_InitForOpenGL)
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* window, const char* canvas_selector);
|
|
||||||
//static inline void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector) { ImGui_ImplGlfw_InstallEmscriptenCallbacks(nullptr, canvas_selector); } } // Renamed in 1.91.0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// GLFW callbacks install
|
|
||||||
// - 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 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_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_CharCallback(GLFWwindow* window, unsigned int c);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event);
|
|
||||||
|
|
||||||
// GLFW helpers
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_Sleep(int milliseconds);
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
File diff suppressed because it is too large
Load Diff
@ -1,67 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
|
|
||||||
// - Desktop GL: 2.x 3.x 4.x
|
|
||||||
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
|
|
||||||
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
|
||||||
|
|
||||||
// About WebGL/ES:
|
|
||||||
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
|
|
||||||
// - This is done automatically on iOS, Android and Emscripten targets.
|
|
||||||
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
// Learn about Dear ImGui:
|
|
||||||
// - FAQ https://dearimgui.com/faq
|
|
||||||
// - Getting Started https://dearimgui.com/getting-started
|
|
||||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
|
||||||
// - Introduction, links and more at the top of imgui.cpp
|
|
||||||
|
|
||||||
// About GLSL version:
|
|
||||||
// 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"
|
|
||||||
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
|
|
||||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
|
||||||
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_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
|
|
||||||
// (Optional) Called by Init/NewFrame/Shutdown
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
// Configuration flags to add in your imconfig file:
|
|
||||||
//#define IMGUI_IMPL_OPENGL_ES2 // Enable ES 2 (Auto-detected on Emscripten)
|
|
||||||
//#define IMGUI_IMPL_OPENGL_ES3 // Enable ES 3 (Auto-detected on iOS/Android)
|
|
||||||
|
|
||||||
// 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 !defined(IMGUI_IMPL_OPENGL_ES2) \
|
|
||||||
&& !defined(IMGUI_IMPL_OPENGL_ES3)
|
|
||||||
|
|
||||||
// Try to detect GLES on matching platforms
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#include <TargetConditionals.h>
|
|
||||||
#endif
|
|
||||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
|
|
||||||
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
|
|
||||||
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
|
|
||||||
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
|
||||||
#else
|
|
||||||
// Otherwise imgui_impl_opengl3_loader.h will be used.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,922 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------
|
|
||||||
// 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:
|
|
||||||
// python3 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 0x0404
|
|
||||||
#define GL_BACK 0x0405
|
|
||||||
#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_LINEAR_MIPMAP_LINEAR 0x2703
|
|
||||||
#define GL_TEXTURE_MAG_FILTER 0x2800
|
|
||||||
#define GL_TEXTURE_MIN_FILTER 0x2801
|
|
||||||
#define GL_TEXTURE_WRAP_S 0x2802
|
|
||||||
#define GL_TEXTURE_WRAP_T 0x2803
|
|
||||||
#define GL_REPEAT 0x2901
|
|
||||||
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_2
|
|
||||||
#define GL_CLAMP_TO_EDGE 0x812F
|
|
||||||
#endif /* GL_VERSION_1_2 */
|
|
||||||
#ifndef GL_VERSION_1_3
|
|
||||||
#define GL_TEXTURE0 0x84C0
|
|
||||||
#define GL_ACTIVE_TEXTURE 0x84E0
|
|
||||||
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
|
|
||||||
typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
|
||||||
GLAPI void APIENTRY glActiveTexture (GLenum texture);
|
|
||||||
GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
|
|
||||||
#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 GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
|
|
||||||
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 GLboolean APIENTRY glIsProgram (GLuint program);
|
|
||||||
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_2_1
|
|
||||||
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
|
||||||
#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
|
|
||||||
#endif /* GL_VERSION_2_1 */
|
|
||||||
#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;
|
|
||||||
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
|
|
||||||
#define GL_CONTEXT_PROFILE_MASK 0x9126
|
|
||||||
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 ImGL3WProcs {
|
|
||||||
GL3WglProc ptr[60];
|
|
||||||
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;
|
|
||||||
PFNGLCOMPRESSEDTEXIMAGE2DPROC CompressedTexImage2D;
|
|
||||||
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;
|
|
||||||
PFNGLISPROGRAMPROC IsProgram;
|
|
||||||
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 ImGL3WProcs 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 glCompressedTexImage2D imgl3wProcs.gl.CompressedTexImage2D
|
|
||||||
#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 glIsProgram imgl3wProcs.gl.IsProgram
|
|
||||||
#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 GL3W_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; // OpenGL library
|
|
||||||
static void* libglx; // GLX library
|
|
||||||
static void* libegl; // EGL library
|
|
||||||
static GL3WGetProcAddressProc gl_get_proc_address;
|
|
||||||
|
|
||||||
static void close_libgl(void)
|
|
||||||
{
|
|
||||||
if (libgl) {
|
|
||||||
dlclose(libgl);
|
|
||||||
libgl = NULL;
|
|
||||||
}
|
|
||||||
if (libegl) {
|
|
||||||
dlclose(libegl);
|
|
||||||
libegl = NULL;
|
|
||||||
}
|
|
||||||
if (libglx) {
|
|
||||||
dlclose(libglx);
|
|
||||||
libglx = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int is_library_loaded(const char* name, void** lib)
|
|
||||||
{
|
|
||||||
*lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
|
|
||||||
return *lib != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int open_libs(void)
|
|
||||||
{
|
|
||||||
// On Linux we have two APIs to get process addresses: EGL and GLX.
|
|
||||||
// EGL is supported under both X11 and Wayland, whereas GLX is X11-specific.
|
|
||||||
|
|
||||||
libgl = NULL;
|
|
||||||
libegl = NULL;
|
|
||||||
libglx = NULL;
|
|
||||||
|
|
||||||
// First check what's already loaded, the windowing library might have
|
|
||||||
// already loaded either EGL or GLX and we want to use the same one.
|
|
||||||
|
|
||||||
if (is_library_loaded("libEGL.so.1", &libegl) ||
|
|
||||||
is_library_loaded("libGLX.so.0", &libglx)) {
|
|
||||||
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
if (libgl)
|
|
||||||
return GL3W_OK;
|
|
||||||
else
|
|
||||||
close_libgl();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_library_loaded("libGL.so", &libgl))
|
|
||||||
return GL3W_OK;
|
|
||||||
if (is_library_loaded("libGL.so.1", &libgl))
|
|
||||||
return GL3W_OK;
|
|
||||||
if (is_library_loaded("libGL.so.3", &libgl))
|
|
||||||
return GL3W_OK;
|
|
||||||
|
|
||||||
// Neither is already loaded, so we have to load one. Try EGL first
|
|
||||||
// because it is supported under both X11 and Wayland.
|
|
||||||
|
|
||||||
// Load OpenGL + EGL
|
|
||||||
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
libegl = dlopen("libEGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
if (libgl && libegl)
|
|
||||||
return GL3W_OK;
|
|
||||||
else
|
|
||||||
close_libgl();
|
|
||||||
|
|
||||||
// Fall back to legacy libGL, which includes GLX
|
|
||||||
// While most systems use libGL.so.1, NetBSD seems to use that libGL.so.3. See https://github.com/ocornut/imgui/issues/6983
|
|
||||||
libgl = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
if (!libgl)
|
|
||||||
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
if (!libgl)
|
|
||||||
libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
|
|
||||||
if (libgl)
|
|
||||||
return GL3W_OK;
|
|
||||||
|
|
||||||
return GL3W_ERROR_LIBRARY_OPEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int open_libgl(void)
|
|
||||||
{
|
|
||||||
int res = open_libs();
|
|
||||||
if (res)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
if (libegl)
|
|
||||||
*(void**)(&gl_get_proc_address) = dlsym(libegl, "eglGetProcAddress");
|
|
||||||
else if (libglx)
|
|
||||||
*(void**)(&gl_get_proc_address) = dlsym(libglx, "glXGetProcAddressARB");
|
|
||||||
else
|
|
||||||
*(void**)(&gl_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
|
|
||||||
|
|
||||||
if (!gl_get_proc_address) {
|
|
||||||
close_libgl();
|
|
||||||
return GL3W_ERROR_LIBRARY_OPEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GL3W_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GL3WglProc get_proc(const char* proc)
|
|
||||||
{
|
|
||||||
GL3WglProc res = NULL;
|
|
||||||
|
|
||||||
// Before EGL version 1.5, eglGetProcAddress doesn't support querying core
|
|
||||||
// functions and may return a dummy function if we try, so try to load the
|
|
||||||
// function from the GL library directly first.
|
|
||||||
if (libegl)
|
|
||||||
*(void**)(&res) = dlsym(libgl, proc);
|
|
||||||
|
|
||||||
if (!res)
|
|
||||||
res = gl_get_proc_address(proc);
|
|
||||||
|
|
||||||
if (!libegl && !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>"
|
|
||||||
if (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",
|
|
||||||
"glCompressedTexImage2D",
|
|
||||||
"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",
|
|
||||||
"glIsProgram",
|
|
||||||
"glLinkProgram",
|
|
||||||
"glPixelStorei",
|
|
||||||
"glPolygonMode",
|
|
||||||
"glReadPixels",
|
|
||||||
"glScissor",
|
|
||||||
"glShaderSource",
|
|
||||||
"glTexImage2D",
|
|
||||||
"glTexParameteri",
|
|
||||||
"glUniform1i",
|
|
||||||
"glUniformMatrix4fv",
|
|
||||||
"glUseProgram",
|
|
||||||
"glVertexAttribPointer",
|
|
||||||
"glViewport",
|
|
||||||
};
|
|
||||||
|
|
||||||
GL3W_API union ImGL3WProcs imgl3wProcs;
|
|
||||||
|
|
||||||
static void load_procs(GL3WGetProcAddressProc proc)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
|
|
||||||
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
@ -5,7 +5,7 @@
|
|||||||
# include <emscripten/html5.h>
|
# include <emscripten/html5.h>
|
||||||
# include <GLES2/gl2.h>
|
# include <GLES2/gl2.h>
|
||||||
#else
|
#else
|
||||||
# include "../profiler/src/imgui/imgui_impl_opengl3_loader.h"
|
# include <backends/imgui_impl_opengl3_loader.h>
|
||||||
#endif
|
#endif
|
||||||
#include "TracyTexture.hpp"
|
#include "TracyTexture.hpp"
|
||||||
#include "../public/common/TracyForceInline.hpp"
|
#include "../public/common/TracyForceInline.hpp"
|
||||||
|
Loading…
Reference in New Issue
Block a user