update tracy from 11.0 to 13.1 and fix build with tracy enabled
This commit is contained in:
parent
7fa5294e02
commit
2adf75973a
@ -1,18 +1,35 @@
|
||||
# Empirical format config, based on observed style guide
|
||||
# Use this only as an help to fit the surrounding code style - don't reformat whole files at once
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
BasedOnStyle: Microsoft
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakBeforeBraces: Allman
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
# AllowShortEnumsOnASingleLine: true # Broken for some reason, even in last versions of clang-format... So don't use it or it may change formating in the future.
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 120
|
||||
SpaceAfterTemplateKeyword: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
# Allman seems to break lambda formatting for some reason with `ColumnLimit: 0`. See https://github.com/llvm/llvm-project/issues/50275
|
||||
# Even though it is supposed to have been fixed, issue still remains in 20.1.8. (and is very much present in 18.x which is the one shipped by VS2022 and VSCord clangd as of 2025-07-27)
|
||||
# Things work fine with `BasedOnStyle: Microsoft` so use that instead
|
||||
#BreakBeforeBraces: Allman
|
||||
ColumnLimit: 0
|
||||
# We'd like to use LeftWithLastLine but it's only available in >=19.x
|
||||
#AlignEscapedNewlines: LeftWithLastLine
|
||||
AlignEscapedNewlines: Left
|
||||
FixNamespaceComments: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentAccessModifiers: false
|
||||
AccessModifierOffset: -4
|
||||
LambdaBodyIndentation: OuterScope
|
||||
PPIndentWidth: 2
|
||||
IndentWidth: 4
|
||||
PointerAlignment: Left
|
||||
SpaceBeforeParens: Never
|
||||
SpacesInParentheses: true
|
||||
TabWidth: 4
|
||||
AlignTrailingComments:
|
||||
Kind: Leave
|
||||
|
||||
@ -20,24 +20,27 @@ Checks:
|
||||
-google-readability-namespace-comments,
|
||||
-misc-confusable-identifiers,
|
||||
-misc-no-recursion,
|
||||
-misc-use-internal-linkage,
|
||||
-modernize-avoid-c-arrays,
|
||||
-modernize-deprecated-headers,
|
||||
-modernize-use-default-member-init,
|
||||
-modernize-use-designated-initializers,
|
||||
-modernize-use-trailing-return-type,
|
||||
-performance-no-int-to-ptr,
|
||||
-readability-braces-around-statements,
|
||||
-readability-else-after-return,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-function-size,
|
||||
-readability-identifier-length,
|
||||
-readability-implicit-bool-conversion,
|
||||
-readability-isolate-declaration,
|
||||
-readability-magic-numbers,
|
||||
-readability-math-missing-parentheses,
|
||||
-readability-qualified-auto,
|
||||
-readability-uppercase-literal-suffix
|
||||
'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
AnalyzeTemporaryDtors: false
|
||||
FormatStyle: none
|
||||
CheckOptions:
|
||||
llvm-else-after-return.WarnOnConditionVariables: 'false'
|
||||
|
||||
9
libs/tracy/.github/workflows/build.yml
vendored
9
libs/tracy/.github/workflows/build.yml
vendored
@ -6,11 +6,14 @@ on:
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm-cache
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ windows-latest, macos-latest ]
|
||||
os: [ windows-latest, macos-15 ]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
continue-on-error: true
|
||||
@ -27,9 +30,11 @@ jobs:
|
||||
- if: startsWith(matrix.os, 'macos')
|
||||
name: Install macos dependencies
|
||||
run: brew install pkg-config glfw meson
|
||||
- name: Trust git repo
|
||||
run: git config --global --add safe.directory '*'
|
||||
- name: Profiler GUI
|
||||
run: |
|
||||
cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release
|
||||
cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release -DGIT_REV=${{ github.sha }}
|
||||
cmake --build profiler/build --parallel --config Release
|
||||
- name: Update utility
|
||||
run: |
|
||||
|
||||
63
libs/tracy/.github/workflows/emscripten.yml
vendored
Normal file
63
libs/tracy/.github/workflows/emscripten.yml
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
name: emscripten
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm-cache
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container: archlinux:base-devel
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: pacman -Syu --noconfirm && pacman -S --noconfirm --needed cmake git unzip python ninja zstd
|
||||
- name: Setup emscripten
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: 4.0.10
|
||||
- name: Trust git repo
|
||||
run: git config --global --add safe.directory '*'
|
||||
- uses: actions/checkout@v4
|
||||
- name: Profiler GUI
|
||||
run: |
|
||||
cmake -G Ninja -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=MinSizeRel -DGIT_REV=${{ github.sha }} -DCMAKE_TOOLCHAIN_FILE=${{env.EMSDK}}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
|
||||
cmake --build profiler/build --parallel
|
||||
- name: Compress artifacts
|
||||
run: |
|
||||
zstd -18 profiler/build/tracy-profiler.js profiler/build/tracy-profiler.wasm
|
||||
gzip -9 profiler/build/tracy-profiler.js profiler/build/tracy-profiler.wasm
|
||||
- name: Find Artifacts
|
||||
id: find_artifacts
|
||||
run: |
|
||||
mkdir -p bin
|
||||
cp profiler/build/index.html bin
|
||||
cp profiler/build/favicon.svg bin
|
||||
cp profiler/build/tracy-profiler.data bin
|
||||
cp profiler/build/tracy-profiler.js.gz bin
|
||||
cp profiler/build/tracy-profiler.js.zst bin
|
||||
cp profiler/build/tracy-profiler.wasm.gz bin
|
||||
cp profiler/build/tracy-profiler.wasm.zst bin
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: emscripten
|
||||
path: bin
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: github.ref == 'refs/heads/master'
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
- uses: wlixcc/SFTP-Deploy-Action@v1.2.4
|
||||
with:
|
||||
username: ${{ secrets.USERNAME }}
|
||||
server: ${{ secrets.SERVER }}
|
||||
port: ${{ secrets.PORT }}
|
||||
ssh_private_key: ${{ secrets.PRIVATE_KEY }}
|
||||
local_path: './emscripten/*'
|
||||
remote_path: ${{ secrets.REMOTE_PATH }}
|
||||
sftp_only: true
|
||||
3
libs/tracy/.github/workflows/latex.yml
vendored
3
libs/tracy/.github/workflows/latex.yml
vendored
@ -13,9 +13,6 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Fix stupidity
|
||||
run: |
|
||||
cp LICENSE LICENSE.
|
||||
- name: Compile LaTeX
|
||||
uses: xu-cheng/latex-action@v3
|
||||
with:
|
||||
|
||||
9
libs/tracy/.github/workflows/linux.yml
vendored
9
libs/tracy/.github/workflows/linux.yml
vendored
@ -6,17 +6,22 @@ on:
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm-cache
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container: archlinux:base-devel
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: pacman -Syu --noconfirm && pacman -S --noconfirm --needed freetype2 tbb debuginfod wayland dbus libxkbcommon libglvnd meson cmake git wayland-protocols nodejs
|
||||
run: pacman -Syu --noconfirm && pacman -S --noconfirm --needed freetype2 debuginfod wayland dbus libxkbcommon libglvnd meson cmake git wayland-protocols nodejs
|
||||
- name: Trust git repo
|
||||
run: git config --global --add safe.directory '*'
|
||||
- uses: actions/checkout@v4
|
||||
- name: Profiler GUI
|
||||
run: |
|
||||
cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release
|
||||
cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release -DGIT_REV=${{ github.sha }}
|
||||
cmake --build profiler/build --parallel
|
||||
- name: Update utility
|
||||
run: |
|
||||
|
||||
3
libs/tracy/.gitignore
vendored
3
libs/tracy/.gitignore
vendored
@ -34,3 +34,6 @@ compile_commands.json
|
||||
profiler/build/wasm/Tracy-release.*
|
||||
profiler/build/wasm/Tracy-debug.*
|
||||
profiler/build/wasm/embed.tracy
|
||||
examples/ToyPathTracer/Windows/TestCpu
|
||||
examples/ToyPathTracer/Windows/x64
|
||||
*.user
|
||||
|
||||
2
libs/tracy/.mailmap
Normal file
2
libs/tracy/.mailmap
Normal file
@ -0,0 +1,2 @@
|
||||
<wolf@nereid.pl> <wolf.pld@gmail.com>
|
||||
<wolf@nereid.pl> <bartosz.taudul@game-lion.com>
|
||||
3
libs/tracy/.vscode/launch.json
vendored
3
libs/tracy/.vscode/launch.json
vendored
@ -7,8 +7,7 @@
|
||||
"request": "launch",
|
||||
"program": "${command:cmake.launchTargetPath}",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"terminal": "console"
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -8,34 +8,73 @@ project(Tracy LANGUAGES CXX VERSION ${TRACY_VERSION_STRING})
|
||||
file(GENERATE OUTPUT .gitignore CONTENT "*")
|
||||
|
||||
if(${BUILD_SHARED_LIBS})
|
||||
set(DEFAULT_STATIC OFF)
|
||||
set(DEFAULT_STATIC OFF)
|
||||
else()
|
||||
set(DEFAULT_STATIC ON)
|
||||
set(DEFAULT_STATIC ON)
|
||||
endif()
|
||||
|
||||
option(TRACY_STATIC "Whether to build Tracy as a static library" ${DEFAULT_STATIC})
|
||||
option(TRACY_Fortran "Build Fortran bindings" OFF)
|
||||
option(TRACY_LTO "Enable Link-Time optimization" OFF)
|
||||
|
||||
if(TRACY_Fortran)
|
||||
enable_language(Fortran)
|
||||
set(CMAKE_Fortran_VERSION 2003)
|
||||
endif()
|
||||
|
||||
if(TRACY_LTO OR CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT LTO_SUPPORTED)
|
||||
if(NOT LTO_SUPPORTED)
|
||||
message(WARNING "LTO is not supported!")
|
||||
endif()
|
||||
else()
|
||||
set(LTO_SUPPORTED OFF)
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(rocprofiler-sdk PATHS "/opt/rocm/lib/cmake")
|
||||
|
||||
set(TRACY_PUBLIC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/public)
|
||||
|
||||
if(TRACY_STATIC)
|
||||
set(TRACY_VISIBILITY "STATIC")
|
||||
if(LTO_SUPPORTED)
|
||||
set(TRACY_VISIBILITY "OBJECT")
|
||||
elseif(TRACY_STATIC)
|
||||
set(TRACY_VISIBILITY "STATIC")
|
||||
else()
|
||||
set(TRACY_VISIBILITY "SHARED")
|
||||
set(TRACY_VISIBILITY "SHARED")
|
||||
endif()
|
||||
|
||||
add_library(TracyClient ${TRACY_VISIBILITY} "${TRACY_PUBLIC_DIR}/TracyClient.cpp")
|
||||
target_compile_features(TracyClient PUBLIC cxx_std_11)
|
||||
set_target_properties(TracyClient PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
|
||||
target_include_directories(TracyClient SYSTEM PUBLIC
|
||||
$<BUILD_INTERFACE:${TRACY_PUBLIC_DIR}>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
$<INSTALL_INTERFACE:include/tracy>)
|
||||
target_link_libraries(
|
||||
TracyClient
|
||||
PUBLIC
|
||||
Threads::Threads
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
if(rocprofiler-sdk_FOUND)
|
||||
target_compile_definitions(TracyClient PUBLIC TRACY_ROCPROF)
|
||||
target_link_libraries(TracyClient PUBLIC rocprofiler-sdk::rocprofiler-sdk)
|
||||
endif()
|
||||
|
||||
if(TRACY_Fortran)
|
||||
add_library(TracyClientF90 ${TRACY_VISIBILITY} "${TRACY_PUBLIC_DIR}/TracyClient.F90")
|
||||
target_include_directories(TracyClientF90 PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:include/tracy>)
|
||||
target_link_libraries(
|
||||
TracyClientF90
|
||||
PUBLIC
|
||||
TracyClient
|
||||
)
|
||||
set_target_properties(TracyClientF90 PROPERTIES Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
|
||||
endif()
|
||||
|
||||
# Public dependency on some libraries required when using Mingw
|
||||
if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU|Clang")
|
||||
@ -54,7 +93,17 @@ if(TRACY_LIBUNWIND_BACKTRACE)
|
||||
target_link_libraries(TracyClient INTERFACE ${unwind_LINK_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(TRACY_DEBUGINFOD)
|
||||
include(FindPkgConfig)
|
||||
pkg_check_modules(debuginfod REQUIRED libdebuginfod)
|
||||
target_include_directories(TracyClient INTERFACE ${debuginfod_INCLUDE_DIRS})
|
||||
target_link_libraries(TracyClient INTERFACE ${debuginfod_LINK_LIBRARIES})
|
||||
endif()
|
||||
|
||||
add_library(Tracy::TracyClient ALIAS TracyClient)
|
||||
if(TRACY_Fortran)
|
||||
add_library(Tracy::TracyClient_Fortran ALIAS TracyClientF90)
|
||||
endif()
|
||||
|
||||
macro(set_option option help value)
|
||||
option(${option} ${help} ${value})
|
||||
@ -91,12 +140,23 @@ set_option(TRACY_TIMER_FALLBACK "Use lower resolution timers" OFF)
|
||||
set_option(TRACY_LIBUNWIND_BACKTRACE "Use libunwind backtracing where supported" OFF)
|
||||
set_option(TRACY_SYMBOL_OFFLINE_RESOLVE "Instead of full runtime symbol resolution, only resolve the image path and offset to enable offline symbol resolution" OFF)
|
||||
set_option(TRACY_LIBBACKTRACE_ELF_DYNLOAD_SUPPORT "Enable libbacktrace to support dynamically loaded elfs in symbol resolution resolution after the first symbol resolve operation" OFF)
|
||||
set_option(TRACY_DEBUGINFOD "Enable debuginfod support" OFF)
|
||||
set_option(TRACY_IGNORE_MEMORY_FAULTS "Ignore instrumentation errors from memory free events that do not have a matching allocation" OFF)
|
||||
|
||||
# advanced
|
||||
set_option(TRACY_VERBOSE "[advanced] Verbose output from the profiler" OFF)
|
||||
mark_as_advanced(TRACY_VERBOSE)
|
||||
set_option(TRACY_DEMANGLE "[advanced] Don't use default demangling function - You'll need to provide your own" OFF)
|
||||
mark_as_advanced(TRACY_DEMANGLE)
|
||||
if(rocprofiler-sdk_FOUND)
|
||||
set_option(TRACY_ROCPROF_CALIBRATION "[advanced] Use continuous calibration of the Rocprof GPU time." OFF)
|
||||
mark_as_advanced(TRACY_ROCPROF_CALIBRATION)
|
||||
endif()
|
||||
|
||||
# handle incompatible combinations
|
||||
if(TRACY_MANUAL_LIFETIME AND NOT TRACY_DELAYED_INIT)
|
||||
message(FATAL_ERROR "TRACY_MANUAL_LIFETIME can not be activated with disabled TRACY_DELAYED_INIT")
|
||||
endif()
|
||||
|
||||
if(NOT TRACY_STATIC)
|
||||
target_compile_definitions(TracyClient PRIVATE TRACY_EXPORTS)
|
||||
@ -107,13 +167,18 @@ include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set_target_properties(TracyClient PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
if(TRACY_Fortran)
|
||||
set_target_properties(TracyClientF90 PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
endif()
|
||||
|
||||
set(tracy_includes
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyC.h
|
||||
${TRACY_PUBLIC_DIR}/tracy/Tracy.hpp
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyCUDA.hpp
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyD3D11.hpp
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyD3D12.hpp
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyLua.hpp
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyMetal.hmm
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyOpenCL.hpp
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyOpenGL.hpp
|
||||
${TRACY_PUBLIC_DIR}/tracy/TracyVulkan.hpp)
|
||||
@ -154,35 +219,58 @@ set(common_includes
|
||||
${TRACY_PUBLIC_DIR}/common/TracySocket.hpp
|
||||
${TRACY_PUBLIC_DIR}/common/TracyStackFrames.hpp
|
||||
${TRACY_PUBLIC_DIR}/common/TracySystem.hpp
|
||||
${TRACY_PUBLIC_DIR}/common/TracyUwp.hpp
|
||||
${TRACY_PUBLIC_DIR}/common/TracyWinFamily.hpp
|
||||
${TRACY_PUBLIC_DIR}/common/TracyYield.hpp)
|
||||
|
||||
install(TARGETS TracyClient
|
||||
EXPORT TracyConfig
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/$<IF:$<CONFIG:Release>,,$<CONFIG>>
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/$<IF:$<CONFIG:Release>,,$<CONFIG>>
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/$<IF:$<CONFIG:Release>,,$<CONFIG>>
|
||||
COMPONENT lib)
|
||||
if(TRACY_Fortran)
|
||||
install(TARGETS TracyClientF90
|
||||
EXPORT TracyConfig
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/$<IF:$<CONFIG:Release>,,$<CONFIG>>
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/$<IF:$<CONFIG:Release>,,$<CONFIG>>
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/$<IF:$<CONFIG:Release>,,$<CONFIG>>
|
||||
COMPONENT lib)
|
||||
endif()
|
||||
# Export targets to build tree root
|
||||
export(TARGETS TracyClient
|
||||
NAMESPACE Tracy::
|
||||
FILE ${CMAKE_BINARY_DIR}/TracyTargets.cmake)
|
||||
if(TRACY_Fortran)
|
||||
export(TARGETS TracyClientF90
|
||||
NAMESPACE Tracy::
|
||||
APPEND
|
||||
FILE ${CMAKE_BINARY_DIR}/TracyTargets.cmake)
|
||||
endif()
|
||||
install(FILES ${tracy_includes}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tracy)
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tracy/tracy)
|
||||
install(FILES ${client_includes}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/client)
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tracy/client)
|
||||
install(FILES ${common_includes}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/common)
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tracy/common)
|
||||
if(TRACY_Fortran)
|
||||
if(${CMAKE_Fortran_COMPILER_ID} MATCHES "Cray")
|
||||
install(FILES ${PROJECT_BINARY_DIR}/TRACY.mod
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tracy)
|
||||
else()
|
||||
install(FILES ${PROJECT_BINARY_DIR}/tracy.mod
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tracy)
|
||||
endif()
|
||||
endif()
|
||||
install(EXPORT TracyConfig
|
||||
NAMESPACE Tracy::
|
||||
FILE TracyTargets.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Tracy)
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/TracyConfig.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Tracy)
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TracyConfig.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Tracy)
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
|
||||
option(TRACY_CLIENT_PYTHON "Whether to build Tracy python client library" OFF)
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
Tracy Profiler (https://github.com/wolfpld/tracy) is licensed under the
|
||||
3-clause BSD license.
|
||||
|
||||
Copyright (c) 2017-2024, Bartosz Taudul <wolf@nereid.pl>
|
||||
Copyright (c) 2017-2025, Bartosz Taudul <wolf@nereid.pl>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
159
libs/tracy/NEWS
159
libs/tracy/NEWS
@ -2,6 +2,165 @@ Note: There is no guarantee that version mismatched client and server will
|
||||
be able to talk with each other. Network protocol breakages won't be listed
|
||||
here.
|
||||
|
||||
v0.13.1 (2025-12-11)
|
||||
--------------------
|
||||
|
||||
- Fixed parsing of extended model and family of x86 CPUID.
|
||||
- Fixed memory corruption when a "long" user name was used on Android.
|
||||
- Fixed wrong function signature when TRACY_DEBUGINFOD was enabled.
|
||||
- Mount list is now read using proper API instead of processing /proc/mounts.
|
||||
- Fixed shadow warning supression not being enabled on gcc.
|
||||
- Silently ignore lost ETW Vsync events instead of asserting.
|
||||
- Worked around few cases where old macOS machines do not support C++20
|
||||
properly. Thanks Tim Apple!
|
||||
- Added truncated mean parameter to csvexport.
|
||||
- Added experimental viewer for the user manual.
|
||||
- Memory free faults can be now ignored with the TRACY_IGNORE_MEMORY_FAULTS
|
||||
option.
|
||||
- Fixed race condition during profiler shutdown.
|
||||
|
||||
|
||||
v0.13.0 (2025-11-11)
|
||||
--------------------
|
||||
|
||||
- Added optional LLM integration.
|
||||
- Can be completely disabled in options.
|
||||
- Requires you to provide a local LLM service.
|
||||
- Can be used to retrieve information from the user manual.
|
||||
- Can answer queries about application call stacks, assembly code, other
|
||||
general questions.
|
||||
- Will refer to network resources to obtain information.
|
||||
- The required setup is detailed in the user manual.
|
||||
- Added support for Microsoft Game Development Kit (GDK).
|
||||
- Added support for ROCm / Rocprof.
|
||||
- Default values for certain settings can be now saved in the options
|
||||
window.
|
||||
- The display height of any timeline thread can be limited with a thread
|
||||
cropper widget at the left border of the screen.
|
||||
- System tracing is now stopped when the profiled program wants to exit.
|
||||
- System tracing can be now enabled and disabled by the profile program.
|
||||
- Added support for host query reset when collecting Vulkan traces.
|
||||
- The find zone statistics now also show P99 and P99.9.
|
||||
- Timeline for a thread will no longer hide if there are no zones to show,
|
||||
but samples are visible.
|
||||
- Fixed problems with Wayland integration.
|
||||
- Proper order of operations is now ensured during initialization.
|
||||
- The window size calculations for fractional scaling are now done
|
||||
correctly.
|
||||
- The Linux tracefs mount path is now properly detected, instead of relying
|
||||
on a hardcoded value.
|
||||
- Fixed LockMark macro expansion.
|
||||
- Fixed invalid reported fiber enter time.
|
||||
- Properly handle fiber enter and leave events in the on demand mode.
|
||||
- Removed calibration of queue delay time. It served no real purpose.
|
||||
- Various improvements have been made to speed up symbol and executable
|
||||
image queries.
|
||||
- Exposed internal mutex variable in Lockable and SharedLockable.
|
||||
- Fixed problems with Linux systems that do not use glibc.
|
||||
- Fixed edge case that could corrupt rpmalloc state in the profiled
|
||||
application.
|
||||
- Extended ZoneNameF macro with compiler checks for proper printf args.
|
||||
- Warnings about variable redefinition by nested zone macros are now
|
||||
supressed by default. The old behavior can be restored by adding the
|
||||
TRACY_ALLOW_SHADOW_WARNING define during compilation of your program.
|
||||
- Fixed window icon and dock integration on macOS.
|
||||
- Fixed edge case with symbols thread not behaving as expected when on
|
||||
demand mode was used and a rapid reconnection was made.
|
||||
- Properly defer GPU context events in serial C API.
|
||||
|
||||
|
||||
v0.12.2 (2025-06-25)
|
||||
--------------------
|
||||
|
||||
- Fixed builds made out of git checkout directory.
|
||||
- Added range limits for flame graph.
|
||||
- Fixed wayland include paths for distros that use non-standard package
|
||||
layouts.
|
||||
- Workarounded MinGW build problems. Safe symbol retrieval is not available
|
||||
on this platform.
|
||||
- Fixed Lua bindings when TRACY_NO_CALLSTACK is defined.
|
||||
|
||||
|
||||
v0.12.1 (2025-06-07)
|
||||
--------------------
|
||||
|
||||
- Fixed window size calculation on macOS, most notably enabling the vertical
|
||||
timeline scroll bar.
|
||||
- Made debug builds of the GUI profiler work with broken Apple compiler.
|
||||
- Fixed profiler compilation when build directory is outside the source
|
||||
directory.
|
||||
- Set proper include path when using CMake integration.
|
||||
- Added the Tracy Metal and CUDA headers to CMake install configuration.
|
||||
- Documented flame graphs.
|
||||
|
||||
|
||||
v0.12.0 (2025-05-30)
|
||||
--------------------
|
||||
|
||||
- Enabled workaround for MSVC runtime library SNAFU, which manifested with
|
||||
the profiler executables crashing at startup inside mutex code.
|
||||
- CPU topology data now includes CPU die information.
|
||||
- Clients running under Wine will now report that in the trace info.
|
||||
- Added flame graph.
|
||||
- The Git ref information for the build is now included in the about dialog.
|
||||
- Added support for clipboard copy and paste on Wayland.
|
||||
- The welcome dialog client address entry field will now trim the entered
|
||||
address, so that stray spaces at the start and the end are removed. This
|
||||
should reduce the amount of user precision required when copy pasting the
|
||||
address from somewhere else.
|
||||
- GPU profiling is now available with Metal and CUDA.
|
||||
- Profiling zones can now optionally inherit their parent color.
|
||||
- It is no longer needed to have up-to-date copy of wayland-protocols
|
||||
installed. CMake will download the required version from GitHub.
|
||||
- Added option to show the top inline in symbol statistics list in stead of
|
||||
the symbol name.
|
||||
- Parallel sorting is now performed with PPQSort (which removes potential
|
||||
dependency on TBB).
|
||||
- Added CMake option TRACY_DEBUGINFOD to enable use of libdebuginfod to
|
||||
retrieve symbols on Linux clients.
|
||||
- Added a "custom" label as an option to select for GPU context type.
|
||||
- Symbol code retrieval is now protected against reading no longer available
|
||||
memory.
|
||||
- Clicking on a symbol in the symbol statistics list will now open a popup
|
||||
with two options. This change intends to make the useful but quite hidden
|
||||
disassembly view more discoverable.
|
||||
- "View symbol" shows the symbol code disassembly. It was previously
|
||||
available by right-click on the source file name.
|
||||
- "Sample entry stacks" shows the list window that was previously
|
||||
opened when the symbol entry was clicked.
|
||||
- Plots are now extended to the end of the trace, instead of ending at the
|
||||
last data point.
|
||||
- Added TracyMemoryDiscard macros to mark that all allocations made in a
|
||||
certain memory pool were freed. This enables better support for arena
|
||||
allocators.
|
||||
- It is now possible to fine-tune horizontal and vertical mouse wheel scroll
|
||||
sensitivity.
|
||||
- Added p75 and p90 percentiles in the Find zone window.
|
||||
- Zone info window will now display (approximate) wall-clock time of when
|
||||
the zone appeared, in addition to the previously displayed time from the
|
||||
start of the program.
|
||||
- Zone values passed via ZoneValue macro will be now also displayed in hex.
|
||||
- The csvexport utility can now export:
|
||||
- plots,
|
||||
- GPU zones,
|
||||
- zone text.
|
||||
- Fortran integration is now available.
|
||||
- Added TRACY_LTO CMake option to enable Link-Time Optimizations.
|
||||
- Executable image names will now be shortened to just the file name. The
|
||||
full path is available as a tooltip. Shortening can be disabled with a
|
||||
"scissors" checkbox.
|
||||
- Entry stacks can be now also viewed via a button in the symbol view.
|
||||
- On Wayland the application icon is now set even without the desktop file.
|
||||
- Lua code can be now automatically instrumented via a hook.
|
||||
- User text set in zone can be now copied to clipboard.
|
||||
- The LockMark() macro is now less strict about what object you can pass
|
||||
to it. It is now possible to pass members, e.g. LockMark(obj.mutex).
|
||||
- The profiler application now adapts to per-monitor DPI on Windows.
|
||||
- It is now possible to save the UI scale of the profiler (needs to be
|
||||
enabled in settings).
|
||||
- Added thread wakeup visualization.
|
||||
|
||||
|
||||
v0.11.1 (2024-08-22)
|
||||
--------------------
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
### A real time, nanosecond resolution, remote telemetry, hybrid frame and sampling profiler for games and other applications.
|
||||
|
||||
Tracy supports profiling CPU (Direct support is provided for C, C++, Lua and Python integration. At the same time, third-party bindings to many other languages exist on the internet, such as [Rust](https://github.com/nagisa/rust_tracy_client), [Zig](https://github.com/nektro/zig-tracy), [C#](https://github.com/clibequilibrium/Tracy-CSharp), [OCaml](https://github.com/imandra-ai/ocaml-tracy), [Odin](https://github.com/oskarnp/odin-tracy), etc.), GPU (All major graphic APIs: OpenGL, Vulkan, Direct3D 11/12, OpenCL.), memory allocations, locks, context switches, automatically attribute screenshots to captured frames, and much more.
|
||||
Tracy supports profiling CPU (Direct support is provided for C, C++, Lua, Python and Fortran integration. At the same time, third-party bindings to many other languages exist on the internet, such as [Rust](https://github.com/nagisa/rust_tracy_client), [Zig](https://github.com/tealsnow/zig-tracy), [C#](https://github.com/clibequilibrium/Tracy-CSharp), [OCaml](https://github.com/imandra-ai/ocaml-tracy), [Odin](https://github.com/oskarnp/odin-tracy), etc.), GPU (All major graphic APIs: OpenGL, Vulkan, Direct3D 11/12, Metal, OpenCL, CUDA.), memory allocations, locks, context switches, automatically attribute screenshots to captured frames, and much more.
|
||||
|
||||
- [Documentation](https://github.com/wolfpld/tracy/releases/latest/download/tracy.pdf) for usage and build process instructions
|
||||
- [Releases](https://github.com/wolfpld/tracy/releases) containing the documentation (`tracy.pdf`) and compiled Windows x64 binaries (`Tracy-<version>.7z`) as assets
|
||||
|
||||
@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
option(NO_ISA_EXTENSIONS "Disable ISA extensions (don't pass -march=native or -mcpu=native to the compiler)" OFF)
|
||||
option(NO_STATISTICS "Disable calculation of statistics" ON)
|
||||
option(NO_PARALLEL_STL "Disable parallel STL" OFF)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/version.cmake)
|
||||
|
||||
@ -25,3 +24,5 @@ set(PROGRAM_FILES
|
||||
add_executable(${PROJECT_NAME} ${PROGRAM_FILES} ${COMMON_FILES} ${SERVER_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyGetOpt)
|
||||
set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
@ -185,7 +185,7 @@ int main( int argc, char** argv )
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
||||
}
|
||||
printf( "\nQueue delay: %s\nTimer resolution: %s\n", tracy::TimeToString( worker.GetDelay() ), tracy::TimeToString( worker.GetResolution() ) );
|
||||
printf( "\nTimer resolution: %s\n", tracy::TimeToString( worker.GetResolution() ) );
|
||||
|
||||
#ifdef _WIN32
|
||||
signal( SIGINT, SigInt );
|
||||
|
||||
@ -154,7 +154,7 @@ set(CPM_DRY_RUN
|
||||
if(DEFINED ENV{CPM_SOURCE_CACHE})
|
||||
set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
|
||||
else()
|
||||
set(CPM_SOURCE_CACHE_DEFAULT OFF)
|
||||
set(CPM_SOURCE_CACHE_DEFAULT ${CMAKE_CURRENT_BINARY_DIR}/.cpm-cache)
|
||||
endif()
|
||||
|
||||
set(CPM_SOURCE_CACHE
|
||||
|
||||
@ -3,19 +3,16 @@ if (NOT NO_ISA_EXTENSIONS)
|
||||
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
|
||||
CHECK_CXX_COMPILER_FLAG("-mcpu=native" COMPILER_SUPPORTS_MCPU_NATIVE)
|
||||
if(COMPILER_SUPPORTS_MARCH_NATIVE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=native")
|
||||
add_compile_options(-mcpu=native)
|
||||
endif()
|
||||
else()
|
||||
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
|
||||
if(COMPILER_SUPPORTS_MARCH_NATIVE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
|
||||
add_compile_options(-march=native)
|
||||
endif()
|
||||
endif()
|
||||
if(WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2")
|
||||
add_compile_options(/arch:AVX2)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -25,32 +22,47 @@ else()
|
||||
set(USE_WAYLAND OFF)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15")
|
||||
message(FATAL_ERROR "Apple Clang 15 or newer is required.")
|
||||
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "16")
|
||||
# AppleClang 15 has issues with to_chars in <chrono> if target is too old
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-mmacosx-version-min=13.3>)
|
||||
endif()
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fexperimental-library>)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
|
||||
add_compile_options(/MP)
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
add_compile_options(-pthread -DIMGUI_IMPL_OPENGL_ES2)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT EMSCRIPTEN)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
add_compile_options(-pthread)
|
||||
add_link_options(-pthread)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT EMSCRIPTEN)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
find_program(MOLD_LINKER mold)
|
||||
if(MOLD_LINKER)
|
||||
set(CMAKE_LINKER_TYPE "MOLD")
|
||||
endif()
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-eliminate-unused-debug-types")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-eliminate-unused-debug-types")
|
||||
add_compile_options(-fno-eliminate-unused-debug-types)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_program(CCACHE ccache)
|
||||
if(CCACHE)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
||||
endif()
|
||||
|
||||
file(GENERATE OUTPUT .gitignore CONTENT "*")
|
||||
|
||||
set(CMAKE_COLOR_DIAGNOSTICS ON)
|
||||
|
||||
12
libs/tracy/cmake/gl3w-extra-symbols.patch
Normal file
12
libs/tracy/cmake/gl3w-extra-symbols.patch
Normal file
@ -0,0 +1,12 @@
|
||||
diff --git a/extra_symbols.txt b/extra_symbols.txt
|
||||
index b95bb58..6b8f616 100644
|
||||
--- a/extra_symbols.txt
|
||||
+++ b/extra_symbols.txt
|
||||
@@ -1,3 +1,7 @@
|
||||
+glCompressedTexImage2D
|
||||
+GL_LINEAR_MIPMAP_LINEAR
|
||||
+GL_TEXTURE_WRAP_S
|
||||
+GL_TEXTURE_WRAP_T
|
||||
glReadPixels
|
||||
glClearColor
|
||||
glClear
|
||||
14
libs/tracy/cmake/imgui-emscripten.patch
Normal file
14
libs/tracy/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;
|
||||
56
libs/tracy/cmake/imgui-loader.patch
Normal file
56
libs/tracy/cmake/imgui-loader.patch
Normal file
@ -0,0 +1,56 @@
|
||||
diff --git i/backends/imgui_impl_opengl3_loader.h w/backends/imgui_impl_opengl3_loader.h
|
||||
index 4ca0536..a1ff572 100644
|
||||
--- i/backends/imgui_impl_opengl3_loader.h
|
||||
+++ w/backends/imgui_impl_opengl3_loader.h
|
||||
@@ -180,6 +180,7 @@ typedef khronos_uint8_t GLubyte;
|
||||
#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
|
||||
@@ -244,8 +245,10 @@ GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
|
||||
#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
|
||||
@@ -481,7 +484,7 @@ GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
|
||||
|
||||
/* gl3w internal state */
|
||||
union ImGL3WProcs {
|
||||
- GL3WglProc ptr[63];
|
||||
+ GL3WglProc ptr[64];
|
||||
struct {
|
||||
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||
PFNGLATTACHSHADERPROC AttachShader;
|
||||
@@ -497,6 +500,7 @@ union ImGL3WProcs {
|
||||
PFNGLCLEARPROC Clear;
|
||||
PFNGLCLEARCOLORPROC ClearColor;
|
||||
PFNGLCOMPILESHADERPROC CompileShader;
|
||||
+ PFNGLCOMPRESSEDTEXIMAGE2DPROC CompressedTexImage2D;
|
||||
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||
PFNGLCREATESHADERPROC CreateShader;
|
||||
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
||||
@@ -563,6 +567,7 @@ GL3W_API extern union ImGL3WProcs imgl3wProcs;
|
||||
#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
|
||||
@@ -859,6 +864,7 @@ static const char *proc_names[] = {
|
||||
"glClear",
|
||||
"glClearColor",
|
||||
"glCompileShader",
|
||||
+ "glCompressedTexImage2D",
|
||||
"glCreateProgram",
|
||||
"glCreateShader",
|
||||
"glDeleteBuffers",
|
||||
14
libs/tracy/cmake/ppqsort-nodebug.patch
Normal file
14
libs/tracy/cmake/ppqsort-nodebug.patch
Normal file
@ -0,0 +1,14 @@
|
||||
diff --git i/include/ppqsort/parameters.h w/include/ppqsort/parameters.h
|
||||
index 115c3a1..3f4b669 100644
|
||||
--- i/include/ppqsort/parameters.h
|
||||
+++ w/include/ppqsort/parameters.h
|
||||
@@ -3,7 +3,8 @@
|
||||
#include <bit>
|
||||
#include <execution>
|
||||
|
||||
-#ifndef NDEBUG
|
||||
+//#ifndef NDEBUG
|
||||
+#if 0
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <syncstream>
|
||||
@ -27,13 +27,9 @@ set(TRACY_SERVER_SOURCES
|
||||
list(TRANSFORM TRACY_SERVER_SOURCES PREPEND "${TRACY_SERVER_DIR}/")
|
||||
|
||||
|
||||
add_library(TracyServer STATIC ${TRACY_COMMON_SOURCES} ${TRACY_SERVER_SOURCES})
|
||||
add_library(TracyServer STATIC EXCLUDE_FROM_ALL ${TRACY_COMMON_SOURCES} ${TRACY_SERVER_SOURCES})
|
||||
target_include_directories(TracyServer PUBLIC ${TRACY_COMMON_DIR} ${TRACY_SERVER_DIR})
|
||||
target_link_libraries(TracyServer PUBLIC TracyCapstone TracyZstd)
|
||||
target_link_libraries(TracyServer PUBLIC TracyCapstone libzstd PPQSort::PPQSort)
|
||||
if(NO_STATISTICS)
|
||||
target_compile_definitions(TracyServer PUBLIC TRACY_NO_STATISTICS)
|
||||
endif()
|
||||
|
||||
if(NOT NO_PARALLEL_STL AND UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
target_link_libraries(TracyServer PRIVATE TracyTbb)
|
||||
endif()
|
||||
|
||||
39
libs/tracy/cmake/tidy-cmake.patch
Normal file
39
libs/tracy/cmake/tidy-cmake.patch
Normal file
@ -0,0 +1,39 @@
|
||||
diff --git i/CMakeLists.txt w/CMakeLists.txt
|
||||
index 8efec25..c1d101e 100644
|
||||
--- i/CMakeLists.txt
|
||||
+++ w/CMakeLists.txt
|
||||
@@ -17,7 +17,7 @@
|
||||
# @date Consult git log.
|
||||
##############################################################################
|
||||
|
||||
-cmake_minimum_required (VERSION 2.8.12)
|
||||
+cmake_minimum_required (VERSION 3.10)
|
||||
|
||||
set(LIB_NAME tidy)
|
||||
set(LIBTIDY_DESCRIPTION "${LIB_NAME} - HTML syntax checker")
|
||||
@@ -528,6 +528,7 @@ if (UNIX AND SUPPORT_CONSOLE_APP)
|
||||
|
||||
# Run the built EXE to generate xml output .
|
||||
add_custom_command(
|
||||
+ POST_BUILD
|
||||
TARGET man
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME} -xml-help > ${TIDYHELP}
|
||||
COMMENT "Generate ${TIDYHELP}"
|
||||
@@ -536,6 +537,7 @@ if (UNIX AND SUPPORT_CONSOLE_APP)
|
||||
|
||||
# Run the built EXE to generate more xml output.
|
||||
add_custom_command(
|
||||
+ POST_BUILD
|
||||
TARGET man
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME} -xml-config > ${TIDYCONFIG}
|
||||
COMMENT "Generate ${TIDYCONFIG}"
|
||||
@@ -544,8 +546,8 @@ if (UNIX AND SUPPORT_CONSOLE_APP)
|
||||
|
||||
# Run xsltproc to generate the install files.
|
||||
add_custom_command(
|
||||
+ POST_BUILD
|
||||
TARGET man
|
||||
- DEPENDS ${TIDYHELP}
|
||||
COMMAND xsltproc ARGS ${TIDY1XSL} ${TIDYHELP} > ${CMAKE_CURRENT_BINARY_DIR}/${TIDY_MANFILE}
|
||||
COMMENT "Generate ${TIDY_MANFILE}"
|
||||
VERBATIM
|
||||
@ -11,6 +11,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)
|
||||
option(DOWNLOAD_CAPSTONE "Force download capstone" ON)
|
||||
option(DOWNLOAD_GLFW "Force download glfw" OFF)
|
||||
option(DOWNLOAD_FREETYPE "Force download freetype" OFF)
|
||||
option(DOWNLOAD_LIBCURL "Force download libcURL" OFF)
|
||||
option(DOWNLOAD_PUGIXML "Force download pugixml" OFF)
|
||||
|
||||
# capstone
|
||||
|
||||
@ -24,11 +26,36 @@ else()
|
||||
CPMAddPackage(
|
||||
NAME capstone
|
||||
GITHUB_REPOSITORY capstone-engine/capstone
|
||||
GIT_TAG 5.0.3
|
||||
GIT_TAG 6.0.0-Alpha5
|
||||
OPTIONS
|
||||
"CAPSTONE_X86_ATT_DISABLE ON"
|
||||
"CAPSTONE_ALPHA_SUPPORT OFF"
|
||||
"CAPSTONE_ARC_SUPPORT OFF"
|
||||
"CAPSTONE_HPPA_SUPPORT OFF"
|
||||
"CAPSTONE_LOONGARCH_SUPPORT OFF"
|
||||
"CAPSTONE_M680X_SUPPORT OFF"
|
||||
"CAPSTONE_M68K_SUPPORT OFF"
|
||||
"CAPSTONE_MIPS_SUPPORT OFF"
|
||||
"CAPSTONE_MOS65XX_SUPPORT OFF"
|
||||
"CAPSTONE_PPC_SUPPORT OFF"
|
||||
"CAPSTONE_SPARC_SUPPORT OFF"
|
||||
"CAPSTONE_SYSTEMZ_SUPPORT OFF"
|
||||
"CAPSTONE_XCORE_SUPPORT OFF"
|
||||
"CAPSTONE_TRICORE_SUPPORT OFF"
|
||||
"CAPSTONE_TMS320C64X_SUPPORT OFF"
|
||||
"CAPSTONE_M680X_SUPPORT OFF"
|
||||
"CAPSTONE_EVM_SUPPORT OFF"
|
||||
"CAPSTONE_WASM_SUPPORT OFF"
|
||||
"CAPSTONE_BPF_SUPPORT OFF"
|
||||
"CAPSTONE_RISCV_SUPPORT OFF"
|
||||
"CAPSTONE_SH_SUPPORT OFF"
|
||||
"CAPSTONE_XTENSA_SUPPORT OFF"
|
||||
"CAPSTONE_BUILD_MACOS_THIN ON"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
add_library(TracyCapstone INTERFACE)
|
||||
target_include_directories(TracyCapstone INTERFACE ${capstone_SOURCE_DIR}/include/capstone)
|
||||
target_link_libraries(TracyCapstone INTERFACE capstone)
|
||||
target_link_libraries(TracyCapstone INTERFACE capstone_static)
|
||||
endif()
|
||||
|
||||
# GLFW
|
||||
@ -49,6 +76,7 @@ if(NOT USE_WAYLAND AND NOT EMSCRIPTEN)
|
||||
"GLFW_BUILD_TESTS OFF"
|
||||
"GLFW_BUILD_DOCS OFF"
|
||||
"GLFW_INSTALL OFF"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
add_library(TracyGlfw3 INTERFACE)
|
||||
target_link_libraries(TracyGlfw3 INTERFACE glfw)
|
||||
@ -66,60 +94,28 @@ else()
|
||||
CPMAddPackage(
|
||||
NAME freetype
|
||||
GITHUB_REPOSITORY freetype/freetype
|
||||
GIT_TAG VER-2-13-2
|
||||
GIT_TAG VER-2-14-1
|
||||
OPTIONS
|
||||
"FT_DISABLE_HARFBUZZ ON"
|
||||
"FT_WITH_HARFBUZZ OFF"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
add_library(TracyFreetype INTERFACE)
|
||||
target_link_libraries(TracyFreetype INTERFACE freetype)
|
||||
endif()
|
||||
|
||||
# zstd
|
||||
# Zstd
|
||||
|
||||
set(ZSTD_DIR "${ROOT_DIR}/zstd")
|
||||
|
||||
set(ZSTD_SOURCES
|
||||
decompress/zstd_ddict.c
|
||||
decompress/zstd_decompress_block.c
|
||||
decompress/huf_decompress.c
|
||||
decompress/zstd_decompress.c
|
||||
common/zstd_common.c
|
||||
common/error_private.c
|
||||
common/xxhash.c
|
||||
common/entropy_common.c
|
||||
common/debug.c
|
||||
common/threading.c
|
||||
common/pool.c
|
||||
common/fse_decompress.c
|
||||
compress/zstd_ldm.c
|
||||
compress/zstd_compress_superblock.c
|
||||
compress/zstd_opt.c
|
||||
compress/zstd_compress_sequences.c
|
||||
compress/fse_compress.c
|
||||
compress/zstd_double_fast.c
|
||||
compress/zstd_compress.c
|
||||
compress/zstd_compress_literals.c
|
||||
compress/hist.c
|
||||
compress/zstdmt_compress.c
|
||||
compress/zstd_lazy.c
|
||||
compress/huf_compress.c
|
||||
compress/zstd_fast.c
|
||||
dictBuilder/zdict.c
|
||||
dictBuilder/cover.c
|
||||
dictBuilder/divsufsort.c
|
||||
dictBuilder/fastcover.c
|
||||
CPMAddPackage(
|
||||
NAME zstd
|
||||
GITHUB_REPOSITORY facebook/zstd
|
||||
GIT_TAG v1.5.7
|
||||
OPTIONS
|
||||
"ZSTD_BUILD_SHARED OFF"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
SOURCE_SUBDIR build/cmake
|
||||
)
|
||||
|
||||
list(TRANSFORM ZSTD_SOURCES PREPEND "${ZSTD_DIR}/")
|
||||
|
||||
set_property(SOURCE ${ZSTD_DIR}/decompress/huf_decompress_amd64.S APPEND PROPERTY COMPILE_OPTIONS "-x" "assembler-with-cpp")
|
||||
|
||||
add_library(TracyZstd STATIC ${ZSTD_SOURCES})
|
||||
target_include_directories(TracyZstd PUBLIC ${ZSTD_DIR})
|
||||
target_compile_definitions(TracyZstd PRIVATE ZSTD_DISABLE_ASM)
|
||||
|
||||
|
||||
# Diff Template Library
|
||||
|
||||
set(DTL_DIR "${ROOT_DIR}/dtl")
|
||||
@ -128,19 +124,25 @@ add_library(TracyDtl INTERFACE)
|
||||
target_sources(TracyDtl INTERFACE ${DTL_HEADERS})
|
||||
target_include_directories(TracyDtl INTERFACE ${DTL_DIR})
|
||||
|
||||
|
||||
# Get Opt
|
||||
|
||||
set(GETOPT_DIR "${ROOT_DIR}/getopt")
|
||||
set(GETOPT_SOURCES ${GETOPT_DIR}/getopt.c)
|
||||
set(GETOPT_HEADERS ${GETOPT_DIR}/getopt.h)
|
||||
add_library(TracyGetOpt STATIC ${GETOPT_SOURCES} ${GETOPT_HEADERS})
|
||||
add_library(TracyGetOpt STATIC EXCLUDE_FROM_ALL ${GETOPT_SOURCES} ${GETOPT_HEADERS})
|
||||
target_include_directories(TracyGetOpt PUBLIC ${GETOPT_DIR})
|
||||
|
||||
|
||||
# ImGui
|
||||
|
||||
set(IMGUI_DIR "${ROOT_DIR}/imgui")
|
||||
CPMAddPackage(
|
||||
NAME ImGui
|
||||
GITHUB_REPOSITORY ocornut/imgui
|
||||
GIT_TAG v1.92.5-docking
|
||||
DOWNLOAD_ONLY TRUE
|
||||
PATCHES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/imgui-emscripten.patch"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/imgui-loader.patch"
|
||||
)
|
||||
|
||||
set(IMGUI_SOURCES
|
||||
imgui_widgets.cpp
|
||||
@ -149,90 +151,152 @@ set(IMGUI_SOURCES
|
||||
imgui.cpp
|
||||
imgui_tables.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 ${IMGUI_SOURCES})
|
||||
target_include_directories(TracyImGui PUBLIC ${IMGUI_DIR})
|
||||
add_library(TracyImGui STATIC EXCLUDE_FROM_ALL ${IMGUI_SOURCES})
|
||||
target_include_directories(TracyImGui PUBLIC ${ImGui_SOURCE_DIR})
|
||||
target_link_libraries(TracyImGui PUBLIC TracyFreetype)
|
||||
target_compile_definitions(TracyImGui PRIVATE "IMGUI_ENABLE_FREETYPE")
|
||||
#target_compile_definitions(TracyImGui PUBLIC "IMGUI_DISABLE_OBSOLETE_FUNCTIONS")
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LEGACY)
|
||||
find_package(X11 REQUIRED)
|
||||
target_link_libraries(TracyImGui PUBLIC ${X11_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_compile_definitions(TracyImGui PRIVATE "IMGUI_DISABLE_DEBUG_TOOLS" "IMGUI_DISABLE_DEMO_WINDOWS")
|
||||
endif()
|
||||
|
||||
# NFD
|
||||
|
||||
if (NOT NO_FILESELECTOR AND NOT EMSCRIPTEN)
|
||||
set(NFD_DIR "${ROOT_DIR}/nfd")
|
||||
|
||||
if (WIN32)
|
||||
set(NFD_SOURCES "${NFD_DIR}/nfd_win.cpp")
|
||||
elseif (APPLE)
|
||||
set(NFD_SOURCES "${NFD_DIR}/nfd_cocoa.m")
|
||||
if(NOT NO_FILESELECTOR AND NOT EMSCRIPTEN)
|
||||
if(GTK_FILESELECTOR)
|
||||
set(NFD_PORTAL OFF)
|
||||
else()
|
||||
if (GTK_FILESELECTOR)
|
||||
set(NFD_SOURCES "${NFD_DIR}/nfd_gtk.cpp")
|
||||
else()
|
||||
set(NFD_SOURCES "${NFD_DIR}/nfd_portal.cpp")
|
||||
endif()
|
||||
set(NFD_PORTAL ON)
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE NFD_HEADERS CONFIGURE_DEPENDS RELATIVE ${NFD_DIR} "*.h")
|
||||
add_library(TracyNfd STATIC ${NFD_SOURCES} ${NFD_HEADERS})
|
||||
target_include_directories(TracyNfd PUBLIC ${NFD_DIR})
|
||||
|
||||
if (APPLE)
|
||||
find_library(APPKIT_LIBRARY AppKit)
|
||||
find_library(UNIFORMTYPEIDENTIFIERS_LIBRARY UniformTypeIdentifiers)
|
||||
target_link_libraries(TracyNfd PUBLIC ${APPKIT_LIBRARY} ${UNIFORMTYPEIDENTIFIERS_LIBRARY})
|
||||
elseif (UNIX)
|
||||
if (GTK_FILESELECTOR)
|
||||
pkg_check_modules(GTK3 gtk+-3.0)
|
||||
if (NOT GTK3_FOUND)
|
||||
message(FATAL_ERROR "GTK3 not found. Please install it or set TRACY_GTK_FILESELECTOR to OFF.")
|
||||
endif()
|
||||
add_library(TracyGtk3 INTERFACE)
|
||||
target_include_directories(TracyGtk3 INTERFACE ${GTK3_INCLUDE_DIRS})
|
||||
target_link_libraries(TracyGtk3 INTERFACE ${GTK3_LINK_LIBRARIES})
|
||||
target_link_libraries(TracyNfd PUBLIC TracyGtk3)
|
||||
else()
|
||||
pkg_check_modules(DBUS dbus-1)
|
||||
if (NOT DBUS_FOUND)
|
||||
message(FATAL_ERROR "D-Bus not found. Please install it or set TRACY_GTK_FILESELECTOR to ON.")
|
||||
endif()
|
||||
add_library(TracyDbus INTERFACE)
|
||||
target_include_directories(TracyDbus INTERFACE ${DBUS_INCLUDE_DIRS})
|
||||
target_link_libraries(TracyDbus INTERFACE ${DBUS_LINK_LIBRARIES})
|
||||
target_link_libraries(TracyNfd PUBLIC TracyDbus)
|
||||
endif()
|
||||
endif()
|
||||
CPMAddPackage(
|
||||
NAME nfd
|
||||
GITHUB_REPOSITORY btzy/nativefiledialog-extended
|
||||
GIT_TAG v1.2.1
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
OPTIONS
|
||||
"NFD_PORTAL ${NFD_PORTAL}"
|
||||
)
|
||||
endif()
|
||||
|
||||
# TBB
|
||||
if (NO_PARALLEL_STL)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_PARALLEL_SORT")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_PARALLEL_SORT")
|
||||
else()
|
||||
if (UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
# Tracy does not use TBB directly, but the implementation of parallel algorithms
|
||||
# in some versions of libstdc++ depends on TBB. When it does, you must
|
||||
# explicitly link against -ltbb.
|
||||
#
|
||||
# Some distributions have pgk-config files for TBB, others don't.
|
||||
# PPQSort
|
||||
|
||||
pkg_check_modules(TBB tbb)
|
||||
if (TBB_FOUND)
|
||||
add_library(TracyTbb INTERFACE)
|
||||
target_include_directories(TracyTbb INTERFACE ${TBB_INCLUDE_DIRS})
|
||||
target_link_libraries(TracyTbb INTERFACE ${TBB_LINK_LIBRARIES})
|
||||
else()
|
||||
CPMAddPackage(
|
||||
NAME tbb
|
||||
GITHUB_REPOSITORY oneapi-src/oneTBB
|
||||
GIT_TAG v2021.12.0-rc2
|
||||
OPTIONS "TBB_TEST OFF"
|
||||
)
|
||||
add_library(TracyTbb INTERFACE)
|
||||
target_link_libraries(TracyTbb INTERFACE tbb)
|
||||
endif()
|
||||
CPMAddPackage(
|
||||
NAME PPQSort
|
||||
GITHUB_REPOSITORY GabTux/PPQSort
|
||||
VERSION 1.0.6
|
||||
PATCHES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/ppqsort-nodebug.patch"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
|
||||
# json
|
||||
|
||||
CPMAddPackage(
|
||||
NAME json
|
||||
GITHUB_REPOSITORY nlohmann/json
|
||||
GIT_TAG v3.12.0
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
|
||||
# md4c
|
||||
|
||||
CPMAddPackage(
|
||||
NAME md4c
|
||||
GITHUB_REPOSITORY mity/md4c
|
||||
GIT_TAG release-0.5.2
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
|
||||
# base64
|
||||
|
||||
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
CPMAddPackage(
|
||||
NAME base64
|
||||
GITHUB_REPOSITORY aklomp/base64
|
||||
GIT_TAG v0.5.2
|
||||
OPTIONS
|
||||
"BASE64_BUILD_CLI OFF"
|
||||
"BASE64_WITH_OpenMP OFF"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})
|
||||
|
||||
# tidy
|
||||
|
||||
CPMAddPackage(
|
||||
NAME tidy
|
||||
GITHUB_REPOSITORY htacg/tidy-html5
|
||||
GIT_TAG 5.8.0
|
||||
PATCHES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/tidy-cmake.patch"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
|
||||
# usearch
|
||||
|
||||
CPMAddPackage(
|
||||
NAME usearch
|
||||
GITHUB_REPOSITORY unum-cloud/usearch
|
||||
GIT_TAG v2.21.3
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
|
||||
# pugixml
|
||||
|
||||
pkg_check_modules(PUGIXML pugixml)
|
||||
if (PUGIXML_FOUND AND NOT DOWNLOAD_PUGIXML)
|
||||
add_library(TracyPugixml INTERFACE)
|
||||
target_include_directories(TracyPugixml INTERFACE ${PUGIXML_INCLUDE_DIRS})
|
||||
target_link_libraries(TracyPugixml INTERFACE ${PUGIXML_LINK_LIBRARIES})
|
||||
else()
|
||||
CPMAddPackage(
|
||||
NAME pugixml
|
||||
GITHUB_REPOSITORY zeux/pugixml
|
||||
GIT_TAG v1.15
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
add_library(TracyPugixml INTERFACE)
|
||||
target_link_libraries(TracyPugixml INTERFACE pugixml)
|
||||
endif()
|
||||
|
||||
# libcurl
|
||||
|
||||
pkg_check_modules(LIBCURL libcurl>=7.87.0)
|
||||
if (LIBCURL_FOUND AND NOT DOWNLOAD_LIBCURL)
|
||||
add_library(TracyLibcurl INTERFACE)
|
||||
target_include_directories(TracyLibcurl INTERFACE ${LIBCURL_INCLUDE_DIRS})
|
||||
target_link_libraries(TracyLibcurl INTERFACE ${LIBCURL_LINK_LIBRARIES})
|
||||
else()
|
||||
CPMAddPackage(
|
||||
NAME libcurl
|
||||
GITHUB_REPOSITORY curl/curl
|
||||
GIT_TAG curl-8_17_0
|
||||
OPTIONS
|
||||
"BUILD_STATIC_LIBS ON"
|
||||
"BUILD_SHARED_LIBS OFF"
|
||||
"HTTP_ONLY ON"
|
||||
"CURL_ZSTD OFF"
|
||||
"CURL_USE_LIBPSL OFF"
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
add_library(TracyLibcurl INTERFACE)
|
||||
target_link_libraries(TracyLibcurl INTERFACE libcurl_static)
|
||||
target_include_directories(TracyLibcurl INTERFACE ${libcurl_SOURCE_DIR}/include)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
option(NO_ISA_EXTENSIONS "Disable ISA extensions (don't pass -march=native or -mcpu=native to the compiler)" OFF)
|
||||
option(NO_PARALLEL_STL "Disable parallel STL" OFF)
|
||||
|
||||
set(NO_STATISTICS OFF)
|
||||
|
||||
@ -26,3 +25,5 @@ set(PROGRAM_FILES
|
||||
add_executable(${PROJECT_NAME} ${PROGRAM_FILES} ${COMMON_FILES} ${SERVER_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyGetOpt)
|
||||
set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
@ -23,13 +23,16 @@ void print_usage_exit(int e)
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, " extract [OPTION...] <trace file>\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " -h, --help Print usage\n");
|
||||
fprintf(stderr, " -f, --filter arg Filter zone names (default: "")\n");
|
||||
fprintf(stderr, " -s, --sep arg CSV separator (default: ,)\n");
|
||||
fprintf(stderr, " -c, --case Case sensitive filtering\n");
|
||||
fprintf(stderr, " -e, --self Get self times\n");
|
||||
fprintf(stderr, " -u, --unwrap Report each zone event\n");
|
||||
fprintf(stderr, " -m, --messages Report only messages\n");
|
||||
fprintf(stderr, " -h, --help Print usage\n");
|
||||
fprintf(stderr, " -f, --filter arg Filter zone names (default: "")\n");
|
||||
fprintf(stderr, " -s, --sep arg CSV separator (default: ,)\n");
|
||||
fprintf(stderr, " -c, --case Case sensitive filtering\n");
|
||||
fprintf(stderr, " -e, --self Get self times\n");
|
||||
fprintf(stderr, " -u, --unwrap Report each cpu zone event\n");
|
||||
fprintf(stderr, " -g, --gpu Report each gpu zone event\n" );
|
||||
fprintf(stderr, " -m, --messages Report only messages\n");
|
||||
fprintf(stderr, " -p, --plot Report plot data (only with -u)\n");
|
||||
fprintf(stderr, " -t, --truncated_mean arg Report truncated mean (arg is the percentile. Default is 90)\n");
|
||||
|
||||
exit(e);
|
||||
}
|
||||
@ -41,7 +44,10 @@ struct Args {
|
||||
bool case_sensitive;
|
||||
bool self_time;
|
||||
bool unwrap;
|
||||
bool show_gpu;
|
||||
bool unwrapMessages;
|
||||
bool plot;
|
||||
int truncated_mean_percentile;
|
||||
};
|
||||
|
||||
Args parse_args(int argc, char** argv)
|
||||
@ -51,7 +57,7 @@ Args parse_args(int argc, char** argv)
|
||||
print_usage_exit(1);
|
||||
}
|
||||
|
||||
Args args = { "", ",", "", false, false, false, false };
|
||||
Args args = { "", ",", "", false, false, false, false, false, false, 0};
|
||||
|
||||
struct option long_opts[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
@ -60,12 +66,15 @@ Args parse_args(int argc, char** argv)
|
||||
{ "case", no_argument, NULL, 'c' },
|
||||
{ "self", no_argument, NULL, 'e' },
|
||||
{ "unwrap", no_argument, NULL, 'u' },
|
||||
{ "gpu", no_argument, NULL, 'g' },
|
||||
{ "messages", no_argument, NULL, 'm' },
|
||||
{ "plot", no_argument, NULL, 'p' },
|
||||
{ "truncated_mean", optional_argument, NULL, 't' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "hf:s:ceum", long_opts, NULL)) != -1)
|
||||
while ((c = getopt_long(argc, argv, "hf:s:ceugmp", long_opts, NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
@ -87,9 +96,18 @@ Args parse_args(int argc, char** argv)
|
||||
case 'u':
|
||||
args.unwrap = true;
|
||||
break;
|
||||
case 'g':
|
||||
args.show_gpu = true;
|
||||
break;
|
||||
case 'm':
|
||||
args.unwrapMessages = true;
|
||||
break;
|
||||
case 'p':
|
||||
args.plot = true;
|
||||
break;
|
||||
case 't':
|
||||
args.truncated_mean_percentile = std::clamp<int>(optarg ? std::atoi(optarg) : 90, 1, 99);
|
||||
break;
|
||||
default:
|
||||
print_usage_exit(1);
|
||||
break;
|
||||
@ -151,6 +169,53 @@ std::string join(const T& v, const char* sep) {
|
||||
return s.str();
|
||||
}
|
||||
|
||||
// Returns {pN, truncated_mean}
|
||||
std::pair<int64_t, int64_t> percentile_and_truncated_mean(std::vector<int64_t>& data, const double p)
|
||||
{
|
||||
assert(p >= 0.0 && p <= 1.0);
|
||||
|
||||
if (data.empty()) {
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
std::sort(data.begin(), data.end());
|
||||
|
||||
const std::size_t n = data.size();
|
||||
const double idx = p * (static_cast<double>(n) - 1.0);
|
||||
const std::size_t idxLow = static_cast<std::size_t>(std::floor(idx));
|
||||
const std::size_t idxHigh = std::min(idxLow + 1, n - 1);
|
||||
const double frac = idx - static_cast<double>(idxLow);
|
||||
|
||||
const double low = static_cast<double>(data[idxLow]);
|
||||
const double high = static_cast<double>(data[idxHigh]);
|
||||
|
||||
// percentile value
|
||||
const double pval_double = low + (high - low) * frac;
|
||||
const int64_t pval_int = static_cast<int64_t>(std::llround(pval_double));
|
||||
|
||||
// Compute truncated mean: average of all values <= pval_double
|
||||
int64_t sum = 0;
|
||||
std::size_t count = 0;
|
||||
for (std::size_t i = 0; i < n; ++i) {
|
||||
if (static_cast<double>(data[i]) <= pval_double) {
|
||||
sum += data[i];
|
||||
++count;
|
||||
} else {
|
||||
break; // sorted, so we can stop once we hit > pval_double
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
// should not happen for p in [0,1] unless data empty, but keep defensive behaviour
|
||||
return {pval_int, 0};
|
||||
}
|
||||
|
||||
const int64_t truncated_mean = sum / count;
|
||||
|
||||
return {pval_int, truncated_mean};
|
||||
}
|
||||
|
||||
|
||||
// From TracyView.cpp
|
||||
int64_t GetZoneChildTimeFast(
|
||||
const tracy::Worker& worker,
|
||||
@ -241,6 +306,68 @@ int main(int argc, char** argv)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
|
||||
if (args.show_gpu)
|
||||
{
|
||||
auto& gpu_slz = worker.GetGpuSourceLocationZones();
|
||||
tracy::Vector<decltype( gpu_slz.begin() )> gpu_slz_selected;
|
||||
gpu_slz_selected.reserve( gpu_slz.size() );
|
||||
|
||||
uint32_t total_cnt = 0;
|
||||
for (auto it = gpu_slz.begin(); it != gpu_slz.end(); ++it)
|
||||
{
|
||||
if (it->second.total != 0)
|
||||
{
|
||||
++total_cnt;
|
||||
if (args.filter[0] == '\0')
|
||||
{
|
||||
gpu_slz_selected.push_back_no_space_check( it );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto name = get_name( it->first, worker );
|
||||
if (is_substring( args.filter, name, args.case_sensitive))
|
||||
{
|
||||
gpu_slz_selected.push_back_no_space_check( it );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const char*> columns;
|
||||
columns = {"name", "src_file", "Time from start of program", "GPU execution time"};
|
||||
|
||||
std::string header = join(columns, args.separator);
|
||||
printf("%s\n", header.data());
|
||||
|
||||
const auto last_time = worker.GetLastTime();
|
||||
for (auto& it : gpu_slz_selected)
|
||||
{
|
||||
std::vector<std::string> values( columns.size() );
|
||||
|
||||
values[0] = get_name( it->first, worker );
|
||||
|
||||
const auto& srcloc = worker.GetSourceLocation( it->first );
|
||||
values[1] = worker.GetString( srcloc.file );
|
||||
|
||||
const auto& zone_data = it->second;
|
||||
for (const auto& zone_thread_data : zone_data.zones)
|
||||
{
|
||||
tracy::GpuEvent* gpu_event = zone_thread_data.Zone();
|
||||
const auto start = gpu_event->GpuStart();
|
||||
const auto end = gpu_event->GpuEnd();
|
||||
|
||||
values[2] = std::to_string( start );
|
||||
|
||||
auto timespan = end - start;
|
||||
values[3] = std::to_string( timespan );
|
||||
|
||||
std::string row = join( values, args.separator );
|
||||
printf( "%s\n", row.data() );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto& slz = worker.GetSourceLocationZones();
|
||||
tracy::Vector<decltype(slz.begin())> slz_selected;
|
||||
slz_selected.reserve(slz.size());
|
||||
@ -270,7 +397,7 @@ int main(int argc, char** argv)
|
||||
if (args.unwrap)
|
||||
{
|
||||
columns = {
|
||||
"name", "src_file", "src_line", "ns_since_start", "exec_time_ns", "thread"
|
||||
"name", "src_file", "src_line", "ns_since_start", "exec_time_ns", "thread", "value"
|
||||
};
|
||||
}
|
||||
else
|
||||
@ -279,6 +406,12 @@ int main(int argc, char** argv)
|
||||
"name", "src_file", "src_line", "total_ns", "total_perc",
|
||||
"counts", "mean_ns", "min_ns", "max_ns", "std_ns"
|
||||
};
|
||||
|
||||
if(args.truncated_mean_percentile)
|
||||
{
|
||||
columns.push_back("percentile_ns");
|
||||
columns.push_back("truncated_mean_ns");
|
||||
}
|
||||
}
|
||||
std::string header = join(columns, args.separator);
|
||||
printf("%s\n", header.data());
|
||||
@ -313,6 +446,12 @@ int main(int argc, char** argv)
|
||||
}
|
||||
values[4] = std::to_string(timespan);
|
||||
values[5] = std::to_string(tId);
|
||||
if (worker.HasZoneExtra(*zone_event)) {
|
||||
const auto& text = worker.GetZoneExtra(*zone_event).text;
|
||||
if (text.Active()) {
|
||||
values[6] = worker.GetString(text);
|
||||
}
|
||||
}
|
||||
|
||||
std::string row = join(values, args.separator);
|
||||
printf("%s\n", row.data());
|
||||
@ -324,10 +463,11 @@ int main(int argc, char** argv)
|
||||
values[3] = std::to_string(time);
|
||||
values[4] = std::to_string(100. * time / last_time);
|
||||
|
||||
values[5] = std::to_string(zone_data.zones.size());
|
||||
const auto sz = zone_data.zones.size();
|
||||
values[5] = std::to_string(sz);
|
||||
|
||||
const auto avg = time / sz;
|
||||
|
||||
const auto avg = (args.self_time ? zone_data.selfTotal : zone_data.total)
|
||||
/ zone_data.zones.size();
|
||||
values[6] = std::to_string(avg);
|
||||
|
||||
const auto tmin = args.self_time ? zone_data.selfMin : zone_data.min;
|
||||
@ -335,7 +475,6 @@ int main(int argc, char** argv)
|
||||
values[7] = std::to_string(tmin);
|
||||
values[8] = std::to_string(tmax);
|
||||
|
||||
const auto sz = zone_data.zones.size();
|
||||
const auto ss = zone_data.sumSq
|
||||
- 2. * zone_data.total * avg
|
||||
+ avg * avg * sz;
|
||||
@ -344,10 +483,49 @@ int main(int argc, char** argv)
|
||||
std = sqrt(ss / (sz - 1));
|
||||
values[9] = std::to_string(std);
|
||||
|
||||
if(args.truncated_mean_percentile)
|
||||
{
|
||||
std::vector<int64_t> samples;
|
||||
samples.reserve( zone_data.zones.size() );
|
||||
for(const auto& zone_thread_data : zone_data.zones)
|
||||
{
|
||||
const auto zone_event = zone_thread_data.Zone();
|
||||
auto timespan = zone_event->End() - zone_event->Start();
|
||||
if(args.self_time)
|
||||
timespan -= GetZoneChildTimeFast( worker, *zone_event );
|
||||
samples.push_back( timespan );
|
||||
}
|
||||
|
||||
std::pair<int64_t, int64_t> pN = percentile_and_truncated_mean(samples, args.truncated_mean_percentile / 100.0);
|
||||
values[10] = std::to_string(pN.first);
|
||||
values[11] = std::to_string(pN.second);
|
||||
}
|
||||
|
||||
std::string row = join(values, args.separator);
|
||||
printf("%s\n", row.data());
|
||||
}
|
||||
}
|
||||
|
||||
if(args.plot && args.unwrap)
|
||||
{
|
||||
auto& plots = worker.GetPlots();
|
||||
for(const auto& plot : plots)
|
||||
{
|
||||
std::vector<std::string> values(columns.size());
|
||||
values[0] = worker.GetString(plot->name);
|
||||
|
||||
for(const auto& val : plot->data)
|
||||
{
|
||||
if (args.unwrap)
|
||||
{
|
||||
values[3] = std::to_string(val.time.Val());
|
||||
values[6] = std::to_string(val.val);
|
||||
}
|
||||
std::string row = join(values, args.separator);
|
||||
printf("%s\n", row.data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <math.h>
|
||||
|
||||
#include <CL/cl.h>
|
||||
|
||||
|
||||
@ -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.
|
||||
@ -1,135 +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.
|
||||
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||
//#define IMGUI_API __declspec( dllexport )
|
||||
//#define IMGUI_API __declspec( dllimport )
|
||||
|
||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to 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_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
// 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);
|
||||
}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
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:
|
||||

|
||||
|
||||
### 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.
|
||||
|
||||

|
||||
|
||||
### 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,950 +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) (ImU32)(255.0f * (float)color / (float)alpha + 0.5f)
|
||||
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.
|
||||
IM_ASSERT(src_range[0] <= src_range[1]);
|
||||
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
|
||||
@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
option(NO_ISA_EXTENSIONS "Disable ISA extensions (don't pass -march=native or -mcpu=native to the compiler)" OFF)
|
||||
option(NO_STATISTICS "Disable calculation of statistics" ON)
|
||||
option(NO_PARALLEL_STL "Disable parallel STL" OFF)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/version.cmake)
|
||||
|
||||
@ -21,7 +20,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/../cmake/server.cmake)
|
||||
add_executable(tracy-import-chrome
|
||||
src/import-chrome.cpp
|
||||
)
|
||||
target_link_libraries(tracy-import-chrome PRIVATE TracyServer)
|
||||
target_link_libraries(tracy-import-chrome PRIVATE TracyServer nlohmann_json::nlohmann_json)
|
||||
|
||||
add_executable(tracy-import-fuchsia
|
||||
src/import-fuchsia.cpp
|
||||
|
||||
@ -3,13 +3,14 @@
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unordered_map>
|
||||
#include <zstd.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define stat64 _stat64
|
||||
@ -18,12 +19,9 @@
|
||||
# define stat64 stat
|
||||
#endif
|
||||
|
||||
#include "json.hpp"
|
||||
|
||||
#include "../../server/TracyFileWrite.hpp"
|
||||
#include "../../server/TracyMmap.hpp"
|
||||
#include "../../server/TracyWorker.hpp"
|
||||
#include "../../zstd/zstd.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@ -15,10 +15,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <zstd.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define stat64 _stat64
|
||||
@ -30,7 +30,6 @@
|
||||
#include "../../server/TracyFileWrite.hpp"
|
||||
#include "../../server/TracyMmap.hpp"
|
||||
#include "../../server/TracyWorker.hpp"
|
||||
#include "../../zstd/zstd.h"
|
||||
|
||||
void Usage() {
|
||||
printf("Usage: import-fuchsia input.json output.tracy\n\n");
|
||||
@ -189,6 +188,12 @@ std::pair<bool, Record> read_next_record(std::vector<uint8_t> const &input, size
|
||||
CHECK_BOUND(offset + 8*len_word);
|
||||
|
||||
Record r{(uint64_t *)&input[offset], len_word, header};
|
||||
|
||||
if (len_word == 0) {
|
||||
fprintf(stderr, "warning: invalid record with length=0 at offset %" PRIu64 "\n", offset); \
|
||||
return std::make_pair(false,Record{}); \
|
||||
}
|
||||
|
||||
offset += 8 * len_word;
|
||||
return std::make_pair(true, r);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,17 +0,0 @@
|
||||
all: release
|
||||
|
||||
debug:
|
||||
@$(MAKE) -f debug.mk all
|
||||
|
||||
release:
|
||||
@$(MAKE) -f release.mk all
|
||||
|
||||
clean:
|
||||
@$(MAKE) -f build.mk clean
|
||||
rm -f libtracy-*.so
|
||||
|
||||
db: clean
|
||||
@bear -- $(MAKE) -f debug.mk all
|
||||
@mv -f compile_commands.json ../../
|
||||
|
||||
.PHONY: all clean debug release db
|
||||
@ -1,12 +0,0 @@
|
||||
CFLAGS +=
|
||||
CXXFLAGS := $(CFLAGS) -std=c++11 -fpic
|
||||
DEFINES += -DTRACY_ENABLE
|
||||
INCLUDES :=
|
||||
LIBS := -lpthread -ldl
|
||||
PROJECT := libtracy
|
||||
IMAGE := $(PROJECT)-$(BUILD).so
|
||||
SHARED_LIBRARY := yes
|
||||
|
||||
SRC := ../../public/TracyClient.cpp
|
||||
|
||||
include ../../common/unix.mk
|
||||
@ -1,13 +0,0 @@
|
||||
ARCH := $(shell uname -m)
|
||||
|
||||
CFLAGS := -g3 -Wall
|
||||
DEFINES := -DDEBUG
|
||||
BUILD := debug
|
||||
|
||||
ifndef TRACY_NO_ISA_EXTENSIONS
|
||||
ifeq ($(ARCH),x86_64)
|
||||
CFLAGS += -msse4.1
|
||||
endif
|
||||
endif
|
||||
|
||||
include build.mk
|
||||
@ -1,13 +0,0 @@
|
||||
ARCH := $(shell uname -m)
|
||||
|
||||
CFLAGS := -O3 -s
|
||||
DEFINES := -DNDEBUG
|
||||
BUILD := release
|
||||
|
||||
ifndef TRACY_NO_ISA_EXTENSIONS
|
||||
ifeq ($(ARCH),x86_64)
|
||||
CFLAGS += -msse4.1
|
||||
endif
|
||||
endif
|
||||
|
||||
include build.mk
|
||||
@ -1,25 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30907.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TracyProfiler", "TracyProfiler.vcxproj", "{C5B825D3-F140-45AB-8A47-B740E56631FB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Release|x64 = Release|x64
|
||||
ReleaseOnDemand|x64 = ReleaseOnDemand|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C5B825D3-F140-45AB-8A47-B740E56631FB}.Release|x64.ActiveCfg = Release|x64
|
||||
{C5B825D3-F140-45AB-8A47-B740E56631FB}.Release|x64.Build.0 = Release|x64
|
||||
{C5B825D3-F140-45AB-8A47-B740E56631FB}.ReleaseOnDemand|x64.ActiveCfg = ReleaseOnDemand|x64
|
||||
{C5B825D3-F140-45AB-8A47-B740E56631FB}.ReleaseOnDemand|x64.Build.0 = ReleaseOnDemand|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E739AC0A-0937-46D7-8807-1EE95CEB576D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@ -1,229 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ReleaseOnDemand|Win32">
|
||||
<Configuration>ReleaseOnDemand</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ReleaseOnDemand|x64">
|
||||
<Configuration>ReleaseOnDemand</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\public\TracyClient.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{C5B825D3-F140-45AB-8A47-B740E56631FB}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>TracyProfiler</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>TRACY_ENABLE;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOnDemand|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>TRACY_ON_DEMAND;TRACY_ENABLE;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\public\TracyClient.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
5
libs/tracy/manual/filter.lua
Normal file
5
libs/tracy/manual/filter.lua
Normal file
@ -0,0 +1,5 @@
|
||||
function Link(el)
|
||||
el.attributes['reference-type'] = nil
|
||||
el.attributes['reference'] = nil
|
||||
return el
|
||||
end
|
||||
26
libs/tracy/manual/latex2md.sh
Normal file
26
libs/tracy/manual/latex2md.sh
Normal file
@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
cp -f tracy.tex _tmp.tex
|
||||
sed -i -e 's@\\menu\[,\]@@g' _tmp.tex
|
||||
sed -i -e 's@\\keys@@g' _tmp.tex
|
||||
sed -i -e 's@\\ctrl@Ctrl@g' _tmp.tex
|
||||
sed -i -e 's@\\shift@Shift@g' _tmp.tex
|
||||
sed -i -e 's@\\Alt@Alt@g' _tmp.tex
|
||||
sed -i -e 's@\\del@Delete@g' _tmp.tex
|
||||
sed -i -e 's@\\fa\([a-zA-Z]*\)@(\1~icon)@g' _tmp.tex
|
||||
sed -i -e 's@\\LMB{}~@@g' _tmp.tex
|
||||
sed -i -e 's@\\MMB{}~@@g' _tmp.tex
|
||||
sed -i -e 's@\\RMB{}~@@g' _tmp.tex
|
||||
sed -i -e 's@\\Scroll{}~@@g' _tmp.tex
|
||||
|
||||
sed -i -e 's@\\nameref{quicklook}@A quick look at Tracy Profiler@g' _tmp.tex
|
||||
sed -i -e 's@\\nameref{firststeps}@First steps@g' _tmp.tex
|
||||
sed -i -e 's@\\nameref{client}@Client markup@g' _tmp.tex
|
||||
sed -i -e 's@\\nameref{capturing}@Capturing the data@g' _tmp.tex
|
||||
sed -i -e 's@\\nameref{analyzingdata}@Analyzing captured data@g' _tmp.tex
|
||||
sed -i -e 's@\\nameref{csvexport}@Exporting zone statistics to CSV@g' _tmp.tex
|
||||
sed -i -e 's@\\nameref{importingdata}@Importing external profiling data@g' _tmp.tex
|
||||
sed -i -e 's@\\nameref{configurationfiles}@Configuration files@g' _tmp.tex
|
||||
|
||||
pandoc --wrap=none --reference-location=block --number-sections -L filter.lua -s _tmp.tex -o tracy.md
|
||||
rm -f _tmp.tex
|
||||
4266
libs/tracy/manual/tracy.md
Normal file
4266
libs/tracy/manual/tracy.md
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
project('tracy', ['cpp'], version: '0.11.0', meson_version: '>=1.1.0')
|
||||
project('tracy', ['cpp'], version: '0.13.1', meson_version: '>=1.3.0', default_options : ['cpp_std=c++11'])
|
||||
|
||||
# internal compiler flags
|
||||
tracy_compile_args = []
|
||||
@ -17,8 +17,8 @@ if get_option('on_demand')
|
||||
tracy_common_args += ['-DTRACY_ON_DEMAND']
|
||||
endif
|
||||
|
||||
if get_option('callstack')
|
||||
tracy_common_args += ['-DTRACY_CALLSTACK']
|
||||
if get_option('callstack') > 0
|
||||
tracy_common_args += ['-DTRACY_CALLSTACK='+get_option('callstack').to_string()]
|
||||
endif
|
||||
|
||||
if get_option('no_callstack')
|
||||
@ -119,6 +119,10 @@ if get_option('debuginfod')
|
||||
tracy_public_deps += dependency('libdebuginfod')
|
||||
endif
|
||||
|
||||
if get_option('ignore_memory_faults')
|
||||
tracy_common_args += ['-DTRACY_IGNORE_MEMORY_FAULTS']
|
||||
endif
|
||||
|
||||
tracy_shared_libs = get_option('default_library') == 'shared'
|
||||
|
||||
if tracy_shared_libs
|
||||
@ -132,6 +136,7 @@ endif
|
||||
includes = [
|
||||
'public/tracy/TracyC.h',
|
||||
'public/tracy/Tracy.hpp',
|
||||
'public/tracy/TracyCUDA.hpp',
|
||||
'public/tracy/TracyD3D11.hpp',
|
||||
'public/tracy/TracyD3D12.hpp',
|
||||
'public/tracy/TracyLua.hpp',
|
||||
@ -150,6 +155,7 @@ client_includes = [
|
||||
'public/client/TracyDebug.hpp',
|
||||
'public/client/TracyDxt1.hpp',
|
||||
'public/client/TracyFastVector.hpp',
|
||||
'public/client/TracyKCore.hpp',
|
||||
'public/client/TracyLock.hpp',
|
||||
'public/client/TracyProfiler.hpp',
|
||||
'public/client/TracyRingBuffer.hpp',
|
||||
@ -175,7 +181,7 @@ common_includes = [
|
||||
'public/common/TracySocket.hpp',
|
||||
'public/common/TracyStackFrames.hpp',
|
||||
'public/common/TracySystem.hpp',
|
||||
'public/common/TracyUwp.hpp',
|
||||
'public/common/TracyWinFamily.hpp',
|
||||
'public/common/TracyYield.hpp'
|
||||
]
|
||||
|
||||
@ -189,8 +195,9 @@ tracy_public_include_dirs = include_directories('public')
|
||||
|
||||
compiler = meson.get_compiler('cpp')
|
||||
override_options = []
|
||||
if compiler.get_id() != 'msvc' and compiler.get_id() != 'clang-cl'
|
||||
override_options += 'cpp_std=c++11'
|
||||
# MSVC c++ lib does not work properly with C++11 and compilation may fail
|
||||
if compiler.has_define('_MSC_VER') and get_option('cpp_std') == 'c++11'
|
||||
override_options += 'cpp_std=c++14'
|
||||
endif
|
||||
|
||||
tracy_compile_args += tracy_common_args
|
||||
@ -204,9 +211,9 @@ tracy = library('tracy', tracy_src, tracy_header_files,
|
||||
override_options : override_options,
|
||||
install : true)
|
||||
|
||||
install_headers(includes, subdir : 'tracy')
|
||||
install_headers(common_includes, subdir : 'common')
|
||||
install_headers(client_includes, subdir : 'client')
|
||||
install_headers(includes, subdir : 'tracy/tracy')
|
||||
install_headers(common_includes, subdir : 'tracy/common')
|
||||
install_headers(client_includes, subdir : 'tracy/client')
|
||||
|
||||
tracy_dep_compile_args = tracy_common_args
|
||||
|
||||
@ -217,7 +224,8 @@ endif
|
||||
pkg = import('pkgconfig')
|
||||
pkg.generate(tracy,
|
||||
extra_cflags : tracy_dep_compile_args,
|
||||
requires : tracy_public_deps)
|
||||
requires : tracy_public_deps,
|
||||
libraries: [tracy])
|
||||
|
||||
tracy_dep = declare_dependency(
|
||||
compile_args : tracy_dep_compile_args,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
option('tracy_enable', type : 'boolean', value : true, description : 'Enable profiling', yield: true)
|
||||
option('on_demand', type : 'boolean', value : false, description : 'On-demand profiling')
|
||||
option('callstack', type : 'boolean', value : false, description : 'Enfore callstack collection for tracy regions')
|
||||
option('callstack', type : 'integer', value : 0, description : 'Enforce callstack collection for tracy zones x frames deep')
|
||||
option('no_callstack', type : 'boolean', value : false, description : 'Disable all callstack related functionality')
|
||||
option('no_callstack_inlines', type : 'boolean', value : false, description : 'Disables the inline functions in callstacks')
|
||||
option('only_localhost', type : 'boolean', value : false, description : 'Only listen on the localhost interface')
|
||||
@ -24,4 +24,5 @@ option('manual_lifetime', type : 'boolean', value : false, description : 'Enable
|
||||
option('fibers', type : 'boolean', value : false, description : 'Enable fibers support')
|
||||
option('no_crash_handler', type : 'boolean', value : false, description : 'Disable crash handling')
|
||||
option('verbose', type : 'boolean', value : false, description : 'Enable verbose logging')
|
||||
option('debuginfod', type : 'boolean', value : false, description : 'Enable debuginfod support')
|
||||
option('debuginfod', type : 'boolean', value : false, description : 'Enable debuginfod support')
|
||||
option('ignore_memory_faults', type : 'boolean', value : false, description : 'Ignore instrumentation errors from memory free events that do not have a matching allocation')
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
@ -1,299 +0,0 @@
|
||||
/*
|
||||
Native File Dialog Extended
|
||||
Repository: https://github.com/btzy/nativefiledialog-extended
|
||||
License: Zlib
|
||||
Authors: Bernard Teo, Michael Labbe
|
||||
|
||||
This header contains the functions that can be called by user code.
|
||||
*/
|
||||
|
||||
#ifndef _NFD_H
|
||||
#define _NFD_H
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(NFD_EXPORT)
|
||||
#define NFD_API __declspec(dllexport)
|
||||
#elif defined(NFD_SHARED)
|
||||
#define NFD_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#if defined(NFD_EXPORT) || defined(NFD_SHARED)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define NFD_API __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifndef NFD_API
|
||||
#define NFD_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
/* denotes UTF-16 char */
|
||||
typedef wchar_t nfdnchar_t;
|
||||
#else
|
||||
/* denotes UTF-8 char */
|
||||
typedef char nfdnchar_t;
|
||||
#endif // _WIN32
|
||||
|
||||
/* opaque data structure -- see NFD_PathSet_* */
|
||||
typedef void nfdpathset_t;
|
||||
#ifndef NFD_PORTAL
|
||||
typedef struct {
|
||||
void* ptr;
|
||||
} nfdpathsetenum_t;
|
||||
#else
|
||||
typedef struct {
|
||||
void* d1;
|
||||
void* d2;
|
||||
unsigned int d3;
|
||||
int d4;
|
||||
int d5;
|
||||
int d6;
|
||||
int d7;
|
||||
int d8;
|
||||
int d9;
|
||||
int d10;
|
||||
int d11;
|
||||
int p1;
|
||||
void* p2;
|
||||
void* p3;
|
||||
} nfdpathsetenum_t;
|
||||
#endif
|
||||
|
||||
typedef unsigned int nfdfiltersize_t;
|
||||
|
||||
typedef enum {
|
||||
NFD_ERROR, /* programmatic error */
|
||||
NFD_OKAY, /* user pressed okay, or successful return */
|
||||
NFD_CANCEL /* user pressed cancel */
|
||||
} nfdresult_t;
|
||||
|
||||
typedef struct {
|
||||
const nfdnchar_t* name;
|
||||
const nfdnchar_t* spec;
|
||||
} nfdnfilteritem_t;
|
||||
|
||||
/* free a file path that was returned by the dialogs */
|
||||
/* Note: use NFD_PathSet_FreePath to free path from pathset instead of this function */
|
||||
NFD_API void NFD_FreePathN(nfdnchar_t* filePath);
|
||||
|
||||
/* initialize NFD - call this for every thread that might use NFD, before calling any other NFD
|
||||
* functions on that thread */
|
||||
NFD_API nfdresult_t NFD_Init(void);
|
||||
|
||||
/* call this to de-initialize NFD, if NFD_Init returned NFD_OKAY */
|
||||
NFD_API void NFD_Quit(void);
|
||||
|
||||
/* single file open dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns
|
||||
* NFD_OKAY */
|
||||
/* If filterCount is zero, filterList is ignored (you can use NULL) */
|
||||
/* If defaultPath is NULL, the operating system will decide */
|
||||
NFD_API nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath);
|
||||
|
||||
/* multiple file open dialog */
|
||||
/* It is the caller's responsibility to free `outPaths` via NFD_PathSet_Free() if this function
|
||||
* returns NFD_OKAY */
|
||||
/* If filterCount is zero, filterList is ignored (you can use NULL) */
|
||||
/* If defaultPath is NULL, the operating system will decide */
|
||||
NFD_API nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath);
|
||||
|
||||
/* save dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns
|
||||
* NFD_OKAY */
|
||||
/* If filterCount is zero, filterList is ignored (you can use NULL) */
|
||||
/* If defaultPath is NULL, the operating system will decide */
|
||||
NFD_API nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath,
|
||||
const nfdnchar_t* defaultName);
|
||||
|
||||
/* select folder dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns
|
||||
* NFD_OKAY */
|
||||
/* If defaultPath is NULL, the operating system will decide */
|
||||
NFD_API nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath);
|
||||
|
||||
/* Get last error -- set when nfdresult_t returns NFD_ERROR */
|
||||
/* Returns the last error that was set, or NULL if there is no error. */
|
||||
/* The memory is owned by NFD and should not be freed by user code. */
|
||||
/* This is *always* ASCII printable characters, so it can be interpreted as UTF-8 without any
|
||||
* conversion. */
|
||||
NFD_API const char* NFD_GetError(void);
|
||||
/* clear the error */
|
||||
NFD_API void NFD_ClearError(void);
|
||||
|
||||
/* path set operations */
|
||||
#ifdef _WIN32
|
||||
typedef unsigned long nfdpathsetsize_t;
|
||||
#elif __APPLE__
|
||||
typedef unsigned long nfdpathsetsize_t;
|
||||
#else
|
||||
typedef unsigned int nfdpathsetsize_t;
|
||||
#endif // _WIN32, __APPLE__
|
||||
|
||||
/* Gets the number of entries stored in pathSet */
|
||||
/* note that some paths might be invalid (NFD_ERROR will be returned by NFD_PathSet_GetPath), so we
|
||||
* might not actually have this number of usable paths */
|
||||
NFD_API nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count);
|
||||
/* Gets the UTF-8 path at offset index */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_PathSet_FreePathN() if this function
|
||||
* returns NFD_OKAY */
|
||||
NFD_API nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet,
|
||||
nfdpathsetsize_t index,
|
||||
nfdnchar_t** outPath);
|
||||
/* Free the path gotten by NFD_PathSet_GetPathN */
|
||||
#ifdef _WIN32
|
||||
#define NFD_PathSet_FreePathN NFD_FreePathN
|
||||
#elif __APPLE__
|
||||
#define NFD_PathSet_FreePathN NFD_FreePathN
|
||||
#else
|
||||
NFD_API void NFD_PathSet_FreePathN(const nfdnchar_t* filePath);
|
||||
#endif // _WIN32, __APPLE__
|
||||
|
||||
/* Gets an enumerator of the path set. */
|
||||
/* It is the caller's responsibility to free `enumerator` via NFD_PathSet_FreeEnum() if this
|
||||
* function returns NFD_OKAY, and it should be freed before freeing the pathset. */
|
||||
NFD_API nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet,
|
||||
nfdpathsetenum_t* outEnumerator);
|
||||
/* Frees an enumerator of the path set. */
|
||||
NFD_API void NFD_PathSet_FreeEnum(nfdpathsetenum_t* enumerator);
|
||||
/* Gets the next item from the path set enumerator.
|
||||
* If there are no more items, then *outPaths will be set to NULL. */
|
||||
/* It is the caller's responsibility to free `*outPath` via NFD_PathSet_FreePath() if this
|
||||
* function returns NFD_OKAY and `*outPath` is not null */
|
||||
NFD_API nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath);
|
||||
|
||||
/* Free the pathSet */
|
||||
NFD_API void NFD_PathSet_Free(const nfdpathset_t* pathSet);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* say that the U8 versions of functions are not just #defined to be the native versions */
|
||||
#define NFD_DIFFERENT_NATIVE_FUNCTIONS
|
||||
|
||||
typedef char nfdu8char_t;
|
||||
|
||||
typedef struct {
|
||||
const nfdu8char_t* name;
|
||||
const nfdu8char_t* spec;
|
||||
} nfdu8filteritem_t;
|
||||
|
||||
/* UTF-8 compatibility functions */
|
||||
|
||||
/* free a file path that was returned */
|
||||
NFD_API void NFD_FreePathU8(nfdu8char_t* outPath);
|
||||
|
||||
/* single file open dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns
|
||||
* NFD_OKAY */
|
||||
NFD_API nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath,
|
||||
const nfdu8filteritem_t* filterList,
|
||||
nfdfiltersize_t count,
|
||||
const nfdu8char_t* defaultPath);
|
||||
|
||||
/* multiple file open dialog */
|
||||
/* It is the caller's responsibility to free `outPaths` via NFD_PathSet_Free() if this function
|
||||
* returns NFD_OKAY */
|
||||
NFD_API nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths,
|
||||
const nfdu8filteritem_t* filterList,
|
||||
nfdfiltersize_t count,
|
||||
const nfdu8char_t* defaultPath);
|
||||
|
||||
/* save dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns
|
||||
* NFD_OKAY */
|
||||
NFD_API nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath,
|
||||
const nfdu8filteritem_t* filterList,
|
||||
nfdfiltersize_t count,
|
||||
const nfdu8char_t* defaultPath,
|
||||
const nfdu8char_t* defaultName);
|
||||
|
||||
/* select folder dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns
|
||||
* NFD_OKAY */
|
||||
NFD_API nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath);
|
||||
|
||||
/* Get the UTF-8 path at offset index */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns
|
||||
* NFD_OKAY */
|
||||
NFD_API nfdresult_t NFD_PathSet_GetPathU8(const nfdpathset_t* pathSet,
|
||||
nfdpathsetsize_t index,
|
||||
nfdu8char_t** outPath);
|
||||
|
||||
/* Gets the next item from the path set enumerator.
|
||||
* If there are no more items, then *outPaths will be set to NULL. */
|
||||
/* It is the caller's responsibility to free `*outPath` via NFD_PathSet_FreePathU8() if this
|
||||
* function returns NFD_OKAY and `*outPath` is not null */
|
||||
NFD_API nfdresult_t NFD_PathSet_EnumNextU8(nfdpathsetenum_t* enumerator, nfdu8char_t** outPath);
|
||||
|
||||
#define NFD_PathSet_FreePathU8 NFD_FreePathU8
|
||||
|
||||
#ifdef NFD_NATIVE
|
||||
typedef nfdnchar_t nfdchar_t;
|
||||
typedef nfdnfilteritem_t nfdfilteritem_t;
|
||||
#define NFD_FreePath NFD_FreePathN
|
||||
#define NFD_OpenDialog NFD_OpenDialogN
|
||||
#define NFD_OpenDialogMultiple NFD_OpenDialogMultipleN
|
||||
#define NFD_SaveDialog NFD_SaveDialogN
|
||||
#define NFD_PickFolder NFD_PickFolderN
|
||||
#define NFD_PathSet_GetPath NFD_PathSet_GetPathN
|
||||
#define NFD_PathSet_FreePath NFD_PathSet_FreePathN
|
||||
#define NFD_PathSet_EnumNext NFD_PathSet_EnumNextN
|
||||
#else
|
||||
typedef nfdu8char_t nfdchar_t;
|
||||
typedef nfdu8filteritem_t nfdfilteritem_t;
|
||||
#define NFD_FreePath NFD_FreePathU8
|
||||
#define NFD_OpenDialog NFD_OpenDialogU8
|
||||
#define NFD_OpenDialogMultiple NFD_OpenDialogMultipleU8
|
||||
#define NFD_SaveDialog NFD_SaveDialogU8
|
||||
#define NFD_PickFolder NFD_PickFolderU8
|
||||
#define NFD_PathSet_GetPath NFD_PathSet_GetPathU8
|
||||
#define NFD_PathSet_FreePath NFD_PathSet_FreePathU8
|
||||
#define NFD_PathSet_EnumNext NFD_PathSet_EnumNextU8
|
||||
#endif // NFD_NATIVE
|
||||
|
||||
#else // _WIN32
|
||||
|
||||
/* the native charset is already UTF-8 */
|
||||
typedef nfdnchar_t nfdchar_t;
|
||||
typedef nfdnfilteritem_t nfdfilteritem_t;
|
||||
#define NFD_FreePath NFD_FreePathN
|
||||
#define NFD_OpenDialog NFD_OpenDialogN
|
||||
#define NFD_OpenDialogMultiple NFD_OpenDialogMultipleN
|
||||
#define NFD_SaveDialog NFD_SaveDialogN
|
||||
#define NFD_PickFolder NFD_PickFolderN
|
||||
#define NFD_PathSet_GetPath NFD_PathSet_GetPathN
|
||||
#define NFD_PathSet_FreePath NFD_PathSet_FreePathN
|
||||
#define NFD_PathSet_EnumNext NFD_PathSet_EnumNextN
|
||||
typedef nfdnchar_t nfdu8char_t;
|
||||
typedef nfdnfilteritem_t nfdu8filteritem_t;
|
||||
#define NFD_FreePathU8 NFD_FreePathN
|
||||
#define NFD_OpenDialogU8 NFD_OpenDialogN
|
||||
#define NFD_OpenDialogMultipleU8 NFD_OpenDialogMultipleN
|
||||
#define NFD_SaveDialogU8 NFD_SaveDialogN
|
||||
#define NFD_PickFolderU8 NFD_PickFolderN
|
||||
#define NFD_PathSet_GetPathU8 NFD_PathSet_GetPathN
|
||||
#define NFD_PathSet_FreePathU8 NFD_PathSet_FreePathN
|
||||
#define NFD_PathSet_EnumNextU8 NFD_PathSet_EnumNextN
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // _NFD_H
|
||||
@ -1,391 +0,0 @@
|
||||
/*
|
||||
Native File Dialog Extended
|
||||
Repository: https://github.com/btzy/nativefiledialog-extended
|
||||
License: Zlib
|
||||
Authors: Bernard Teo, Michael Labbe
|
||||
*/
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <Availability.h>
|
||||
#include "nfd.h"
|
||||
|
||||
// MacOS is deprecating the allowedFileTypes property in favour of allowedContentTypes, so we have
|
||||
// to introduce this breaking change. Define NFD_MACOS_ALLOWEDCONTENTTYPES to 1 to have it set the
|
||||
// allowedContentTypes property of the SavePanel or OpenPanel. Define
|
||||
// NFD_MACOS_ALLOWEDCONTENTTYPES to 0 to have it set the allowedFileTypes property of the SavePanel
|
||||
// or OpenPanel. If NFD_MACOS_ALLOWEDCONTENTTYPES is undefined, then it will set it to 1 if
|
||||
// __MAC_OS_X_VERSION_MIN_REQUIRED >= 11.0, and 0 otherwise.
|
||||
#if !defined(NFD_MACOS_ALLOWEDCONTENTTYPES)
|
||||
#if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || !defined(__MAC_11_0) || \
|
||||
__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_11_0
|
||||
#define NFD_MACOS_ALLOWEDCONTENTTYPES 0
|
||||
#else
|
||||
#define NFD_MACOS_ALLOWEDCONTENTTYPES 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if NFD_MACOS_ALLOWEDCONTENTTYPES == 1
|
||||
#include <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
||||
#endif
|
||||
|
||||
static const char* g_errorstr = NULL;
|
||||
|
||||
static void NFDi_SetError(const char* msg) {
|
||||
g_errorstr = msg;
|
||||
}
|
||||
|
||||
static void* NFDi_Malloc(size_t bytes) {
|
||||
void* ptr = malloc(bytes);
|
||||
if (!ptr) NFDi_SetError("NFDi_Malloc failed.");
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void NFDi_Free(void* ptr) {
|
||||
assert(ptr);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#if NFD_MACOS_ALLOWEDCONTENTTYPES == 1
|
||||
// Returns an NSArray of UTType representing the content types.
|
||||
static NSArray* BuildAllowedContentTypes(const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount) {
|
||||
NSMutableArray* buildFilterList = [[NSMutableArray alloc] init];
|
||||
|
||||
for (nfdfiltersize_t filterIndex = 0; filterIndex != filterCount; ++filterIndex) {
|
||||
// this is the spec to parse (we don't use the friendly name on OS X)
|
||||
const nfdnchar_t* filterSpec = filterList[filterIndex].spec;
|
||||
|
||||
const nfdnchar_t* p_currentFilterBegin = filterSpec;
|
||||
for (const nfdnchar_t* p_filterSpec = filterSpec; *p_filterSpec; ++p_filterSpec) {
|
||||
if (*p_filterSpec == ',') {
|
||||
// add the extension to the array
|
||||
NSString* filterStr = [[NSString alloc]
|
||||
initWithBytes:(const void*)p_currentFilterBegin
|
||||
length:(sizeof(nfdnchar_t) * (p_filterSpec - p_currentFilterBegin))
|
||||
encoding:NSUTF8StringEncoding];
|
||||
UTType* filterType = [UTType typeWithFilenameExtension:filterStr
|
||||
conformingToType:UTTypeData];
|
||||
[filterStr release];
|
||||
if (filterType) [buildFilterList addObject:filterType];
|
||||
p_currentFilterBegin = p_filterSpec + 1;
|
||||
}
|
||||
}
|
||||
// add the extension to the array
|
||||
NSString* filterStr = [[NSString alloc] initWithUTF8String:p_currentFilterBegin];
|
||||
UTType* filterType = [UTType typeWithFilenameExtension:filterStr
|
||||
conformingToType:UTTypeData];
|
||||
[filterStr release];
|
||||
if (filterType) [buildFilterList addObject:filterType];
|
||||
}
|
||||
|
||||
NSArray* returnArray = [NSArray arrayWithArray:buildFilterList];
|
||||
|
||||
[buildFilterList release];
|
||||
|
||||
assert([returnArray count] != 0);
|
||||
|
||||
return returnArray;
|
||||
}
|
||||
#else
|
||||
// Returns an NSArray of NSString representing the file types.
|
||||
static NSArray* BuildAllowedFileTypes(const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount) {
|
||||
NSMutableArray* buildFilterList = [[NSMutableArray alloc] init];
|
||||
|
||||
for (nfdfiltersize_t filterIndex = 0; filterIndex != filterCount; ++filterIndex) {
|
||||
// this is the spec to parse (we don't use the friendly name on OS X)
|
||||
const nfdnchar_t* filterSpec = filterList[filterIndex].spec;
|
||||
|
||||
const nfdnchar_t* p_currentFilterBegin = filterSpec;
|
||||
for (const nfdnchar_t* p_filterSpec = filterSpec; *p_filterSpec; ++p_filterSpec) {
|
||||
if (*p_filterSpec == ',') {
|
||||
// add the extension to the array
|
||||
NSString* filterStr = [[[NSString alloc]
|
||||
initWithBytes:(const void*)p_currentFilterBegin
|
||||
length:(sizeof(nfdnchar_t) * (p_filterSpec - p_currentFilterBegin))
|
||||
encoding:NSUTF8StringEncoding] autorelease];
|
||||
[buildFilterList addObject:filterStr];
|
||||
p_currentFilterBegin = p_filterSpec + 1;
|
||||
}
|
||||
}
|
||||
// add the extension to the array
|
||||
NSString* filterStr = [NSString stringWithUTF8String:p_currentFilterBegin];
|
||||
[buildFilterList addObject:filterStr];
|
||||
}
|
||||
|
||||
NSArray* returnArray = [NSArray arrayWithArray:buildFilterList];
|
||||
|
||||
[buildFilterList release];
|
||||
|
||||
assert([returnArray count] != 0);
|
||||
|
||||
return returnArray;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void AddFilterListToDialog(NSSavePanel* dialog,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount) {
|
||||
// note: NSOpenPanel inherits from NSSavePanel.
|
||||
|
||||
if (!filterCount) return;
|
||||
|
||||
assert(filterList);
|
||||
|
||||
// Make NSArray of file types and set it on the dialog
|
||||
// We use setAllowedFileTypes or setAllowedContentTypes depending on the deployment target
|
||||
#if NFD_MACOS_ALLOWEDCONTENTTYPES == 1
|
||||
NSArray* allowedContentTypes = BuildAllowedContentTypes(filterList, filterCount);
|
||||
[dialog setAllowedContentTypes:allowedContentTypes];
|
||||
#else
|
||||
NSArray* allowedFileTypes = BuildAllowedFileTypes(filterList, filterCount);
|
||||
[dialog setAllowedFileTypes:allowedFileTypes];
|
||||
#endif
|
||||
}
|
||||
|
||||
static void SetDefaultPath(NSSavePanel* dialog, const nfdnchar_t* defaultPath) {
|
||||
if (!defaultPath || !*defaultPath) return;
|
||||
|
||||
NSString* defaultPathString = [NSString stringWithUTF8String:defaultPath];
|
||||
NSURL* url = [NSURL fileURLWithPath:defaultPathString isDirectory:YES];
|
||||
[dialog setDirectoryURL:url];
|
||||
}
|
||||
|
||||
static void SetDefaultName(NSSavePanel* dialog, const nfdnchar_t* defaultName) {
|
||||
if (!defaultName || !*defaultName) return;
|
||||
|
||||
NSString* defaultNameString = [NSString stringWithUTF8String:defaultName];
|
||||
[dialog setNameFieldStringValue:defaultNameString];
|
||||
}
|
||||
|
||||
static nfdresult_t CopyUtf8String(const char* utf8Str, nfdnchar_t** out) {
|
||||
// byte count, not char count
|
||||
size_t len = strlen(utf8Str);
|
||||
|
||||
// Too bad we have to use additional memory for all the result paths,
|
||||
// because we cannot reconstitute an NSString from a char* to release it properly.
|
||||
*out = (nfdnchar_t*)NFDi_Malloc(len + 1);
|
||||
if (*out) {
|
||||
strcpy(*out, utf8Str);
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
/* public */
|
||||
|
||||
const char* NFD_GetError(void) {
|
||||
return g_errorstr;
|
||||
}
|
||||
|
||||
void NFD_ClearError(void) {
|
||||
NFDi_SetError(NULL);
|
||||
}
|
||||
|
||||
void NFD_FreePathN(nfdnchar_t* filePath) {
|
||||
NFDi_Free((void*)filePath);
|
||||
}
|
||||
|
||||
static NSApplicationActivationPolicy old_app_policy;
|
||||
|
||||
nfdresult_t NFD_Init(void) {
|
||||
NSApplication* app = [NSApplication sharedApplication];
|
||||
old_app_policy = [app activationPolicy];
|
||||
if (old_app_policy == NSApplicationActivationPolicyProhibited) {
|
||||
if (![app setActivationPolicy:NSApplicationActivationPolicyAccessory]) {
|
||||
NFDi_SetError("Failed to set activation policy.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
/* call this to de-initialize NFD, if NFD_Init returned NFD_OKAY */
|
||||
void NFD_Quit(void) {
|
||||
[[NSApplication sharedApplication] setActivationPolicy:old_app_policy];
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath) {
|
||||
nfdresult_t result = NFD_CANCEL;
|
||||
@autoreleasepool {
|
||||
NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow];
|
||||
|
||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||
[dialog setAllowsMultipleSelection:NO];
|
||||
|
||||
// Build the filter list
|
||||
AddFilterListToDialog(dialog, filterList, filterCount);
|
||||
|
||||
// Set the starting directory
|
||||
SetDefaultPath(dialog, defaultPath);
|
||||
|
||||
if ([dialog runModal] == NSModalResponseOK) {
|
||||
const NSURL* url = [dialog URL];
|
||||
const char* utf8Path = [[url path] UTF8String];
|
||||
result = CopyUtf8String(utf8Path, outPath);
|
||||
}
|
||||
|
||||
// return focus to the key window (i.e. main window)
|
||||
[keyWindow makeKeyAndOrderFront:nil];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath) {
|
||||
nfdresult_t result = NFD_CANCEL;
|
||||
@autoreleasepool {
|
||||
NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow];
|
||||
|
||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||
[dialog setAllowsMultipleSelection:YES];
|
||||
|
||||
// Build the filter list
|
||||
AddFilterListToDialog(dialog, filterList, filterCount);
|
||||
|
||||
// Set the starting directory
|
||||
SetDefaultPath(dialog, defaultPath);
|
||||
|
||||
if ([dialog runModal] == NSModalResponseOK) {
|
||||
const NSArray* urls = [dialog URLs];
|
||||
|
||||
if ([urls count] > 0) {
|
||||
// have at least one URL, we return this NSArray
|
||||
[urls retain];
|
||||
*outPaths = (const nfdpathset_t*)urls;
|
||||
result = NFD_OKAY;
|
||||
}
|
||||
}
|
||||
|
||||
// return focus to the key window (i.e. main window)
|
||||
[keyWindow makeKeyAndOrderFront:nil];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath,
|
||||
const nfdnchar_t* defaultName) {
|
||||
nfdresult_t result = NFD_CANCEL;
|
||||
@autoreleasepool {
|
||||
NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow];
|
||||
|
||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||
[dialog setExtensionHidden:NO];
|
||||
// allow other file types, to give the user an escape hatch since you can't select "*.*" on
|
||||
// Mac
|
||||
[dialog setAllowsOtherFileTypes:TRUE];
|
||||
|
||||
// Build the filter list
|
||||
AddFilterListToDialog(dialog, filterList, filterCount);
|
||||
|
||||
// Set the starting directory
|
||||
SetDefaultPath(dialog, defaultPath);
|
||||
|
||||
// Set the default file name
|
||||
SetDefaultName(dialog, defaultName);
|
||||
|
||||
if ([dialog runModal] == NSModalResponseOK) {
|
||||
const NSURL* url = [dialog URL];
|
||||
const char* utf8Path = [[url path] UTF8String];
|
||||
result = CopyUtf8String(utf8Path, outPath);
|
||||
}
|
||||
|
||||
// return focus to the key window (i.e. main window)
|
||||
[keyWindow makeKeyAndOrderFront:nil];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) {
|
||||
nfdresult_t result = NFD_CANCEL;
|
||||
@autoreleasepool {
|
||||
NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow];
|
||||
|
||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||
[dialog setAllowsMultipleSelection:NO];
|
||||
[dialog setCanChooseDirectories:YES];
|
||||
[dialog setCanCreateDirectories:YES];
|
||||
[dialog setCanChooseFiles:NO];
|
||||
|
||||
// Set the starting directory
|
||||
SetDefaultPath(dialog, defaultPath);
|
||||
|
||||
if ([dialog runModal] == NSModalResponseOK) {
|
||||
const NSURL* url = [dialog URL];
|
||||
const char* utf8Path = [[url path] UTF8String];
|
||||
result = CopyUtf8String(utf8Path, outPath);
|
||||
}
|
||||
|
||||
// return focus to the key window (i.e. main window)
|
||||
[keyWindow makeKeyAndOrderFront:nil];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count) {
|
||||
const NSArray* urls = (const NSArray*)pathSet;
|
||||
*count = [urls count];
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet,
|
||||
nfdpathsetsize_t index,
|
||||
nfdnchar_t** outPath) {
|
||||
const NSArray* urls = (const NSArray*)pathSet;
|
||||
|
||||
@autoreleasepool {
|
||||
// autoreleasepool needed because UTF8String method might use the pool
|
||||
const NSURL* url = [urls objectAtIndex:index];
|
||||
const char* utf8Path = [[url path] UTF8String];
|
||||
return CopyUtf8String(utf8Path, outPath);
|
||||
}
|
||||
}
|
||||
|
||||
void NFD_PathSet_Free(const nfdpathset_t* pathSet) {
|
||||
const NSArray* urls = (const NSArray*)pathSet;
|
||||
[urls release];
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, nfdpathsetenum_t* outEnumerator) {
|
||||
const NSArray* urls = (const NSArray*)pathSet;
|
||||
|
||||
@autoreleasepool {
|
||||
// autoreleasepool needed because NSEnumerator uses it
|
||||
NSEnumerator* enumerator = [urls objectEnumerator];
|
||||
[enumerator retain];
|
||||
outEnumerator->ptr = (void*)enumerator;
|
||||
}
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
void NFD_PathSet_FreeEnum(nfdpathsetenum_t* enumerator) {
|
||||
NSEnumerator* real_enum = (NSEnumerator*)enumerator->ptr;
|
||||
[real_enum release];
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath) {
|
||||
NSEnumerator* real_enum = (NSEnumerator*)enumerator->ptr;
|
||||
|
||||
@autoreleasepool {
|
||||
// autoreleasepool needed because NSURL uses it
|
||||
const NSURL* url = [real_enum nextObject];
|
||||
if (url) {
|
||||
const char* utf8Path = [[url path] UTF8String];
|
||||
return CopyUtf8String(utf8Path, outPath);
|
||||
} else {
|
||||
*outPath = NULL;
|
||||
return NFD_OKAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,631 +0,0 @@
|
||||
/*
|
||||
Native File Dialog Extended
|
||||
Repository: https://github.com/btzy/nativefiledialog-extended
|
||||
License: Zlib
|
||||
Authors: Bernard Teo, Michael Labbe
|
||||
|
||||
Note: We do not check for malloc failure on Linux - Linux overcommits memory!
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <gtk/gtk.h>
|
||||
#if defined(GDK_WINDOWING_X11)
|
||||
#include <gdk/gdkx.h>
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nfd.h"
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
struct Free_Guard {
|
||||
T* data;
|
||||
Free_Guard(T* freeable) noexcept : data(freeable) {}
|
||||
~Free_Guard() { NFDi_Free(data); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct FreeCheck_Guard {
|
||||
T* data;
|
||||
FreeCheck_Guard(T* freeable = nullptr) noexcept : data(freeable) {}
|
||||
~FreeCheck_Guard() {
|
||||
if (data) NFDi_Free(data);
|
||||
}
|
||||
};
|
||||
|
||||
/* current error */
|
||||
const char* g_errorstr = nullptr;
|
||||
|
||||
void NFDi_SetError(const char* msg) {
|
||||
g_errorstr = msg;
|
||||
}
|
||||
|
||||
template <typename T = void>
|
||||
T* NFDi_Malloc(size_t bytes) {
|
||||
void* ptr = malloc(bytes);
|
||||
if (!ptr) NFDi_SetError("NFDi_Malloc failed.");
|
||||
|
||||
return static_cast<T*>(ptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void NFDi_Free(T* ptr) {
|
||||
assert(ptr);
|
||||
free(static_cast<void*>(ptr));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* copy(const T* begin, const T* end, T* out) {
|
||||
for (; begin != end; ++begin) {
|
||||
*out++ = *begin;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Does not own the filter and extension.
|
||||
struct Pair_GtkFileFilter_FileExtension {
|
||||
GtkFileFilter* filter;
|
||||
const nfdnchar_t* extensionBegin;
|
||||
const nfdnchar_t* extensionEnd;
|
||||
};
|
||||
|
||||
struct ButtonClickedArgs {
|
||||
Pair_GtkFileFilter_FileExtension* map;
|
||||
GtkFileChooser* chooser;
|
||||
};
|
||||
|
||||
void AddFiltersToDialog(GtkFileChooser* chooser,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount) {
|
||||
if (filterCount) {
|
||||
assert(filterList);
|
||||
|
||||
// we have filters to add ... format and add them
|
||||
|
||||
for (nfdfiltersize_t index = 0; index != filterCount; ++index) {
|
||||
GtkFileFilter* filter = gtk_file_filter_new();
|
||||
|
||||
// count number of file extensions
|
||||
size_t sep = 1;
|
||||
for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) {
|
||||
if (*p_spec == L',') {
|
||||
++sep;
|
||||
}
|
||||
}
|
||||
|
||||
// friendly name conversions: "png,jpg" -> "Image files
|
||||
// (png, jpg)"
|
||||
|
||||
// calculate space needed (including the trailing '\0')
|
||||
size_t nameSize =
|
||||
sep + strlen(filterList[index].spec) + 3 + strlen(filterList[index].name);
|
||||
|
||||
// malloc the required memory
|
||||
nfdnchar_t* nameBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) * nameSize);
|
||||
|
||||
nfdnchar_t* p_nameBuf = nameBuf;
|
||||
for (const nfdnchar_t* p_filterName = filterList[index].name; *p_filterName;
|
||||
++p_filterName) {
|
||||
*p_nameBuf++ = *p_filterName;
|
||||
}
|
||||
*p_nameBuf++ = ' ';
|
||||
*p_nameBuf++ = '(';
|
||||
const nfdnchar_t* p_extensionStart = filterList[index].spec;
|
||||
for (const nfdnchar_t* p_spec = filterList[index].spec; true; ++p_spec) {
|
||||
if (*p_spec == ',' || !*p_spec) {
|
||||
if (*p_spec == ',') {
|
||||
*p_nameBuf++ = ',';
|
||||
*p_nameBuf++ = ' ';
|
||||
}
|
||||
|
||||
// +1 for the trailing '\0'
|
||||
nfdnchar_t* extnBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) *
|
||||
(p_spec - p_extensionStart + 3));
|
||||
nfdnchar_t* p_extnBufEnd = extnBuf;
|
||||
*p_extnBufEnd++ = '*';
|
||||
*p_extnBufEnd++ = '.';
|
||||
p_extnBufEnd = copy(p_extensionStart, p_spec, p_extnBufEnd);
|
||||
*p_extnBufEnd++ = '\0';
|
||||
assert((size_t)(p_extnBufEnd - extnBuf) ==
|
||||
sizeof(nfdnchar_t) * (p_spec - p_extensionStart + 3));
|
||||
gtk_file_filter_add_pattern(filter, extnBuf);
|
||||
NFDi_Free(extnBuf);
|
||||
|
||||
if (*p_spec) {
|
||||
// update the extension start point
|
||||
p_extensionStart = p_spec + 1;
|
||||
} else {
|
||||
// reached the '\0' character
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*p_nameBuf++ = *p_spec;
|
||||
}
|
||||
}
|
||||
*p_nameBuf++ = ')';
|
||||
*p_nameBuf++ = '\0';
|
||||
assert((size_t)(p_nameBuf - nameBuf) == sizeof(nfdnchar_t) * nameSize);
|
||||
|
||||
// add to the filter
|
||||
gtk_file_filter_set_name(filter, nameBuf);
|
||||
|
||||
// free the memory
|
||||
NFDi_Free(nameBuf);
|
||||
|
||||
// add filter to chooser
|
||||
gtk_file_chooser_add_filter(chooser, filter);
|
||||
}
|
||||
}
|
||||
|
||||
/* always append a wildcard option to the end*/
|
||||
|
||||
GtkFileFilter* filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter, "All files");
|
||||
gtk_file_filter_add_pattern(filter, "*");
|
||||
gtk_file_chooser_add_filter(chooser, filter);
|
||||
}
|
||||
|
||||
// returns null-terminated map (trailing .filter is null)
|
||||
Pair_GtkFileFilter_FileExtension* AddFiltersToDialogWithMap(GtkFileChooser* chooser,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount) {
|
||||
Pair_GtkFileFilter_FileExtension* map = NFDi_Malloc<Pair_GtkFileFilter_FileExtension>(
|
||||
sizeof(Pair_GtkFileFilter_FileExtension) * (filterCount + 1));
|
||||
|
||||
if (filterCount) {
|
||||
assert(filterList);
|
||||
|
||||
// we have filters to add ... format and add them
|
||||
|
||||
for (nfdfiltersize_t index = 0; index != filterCount; ++index) {
|
||||
GtkFileFilter* filter = gtk_file_filter_new();
|
||||
|
||||
// store filter in map
|
||||
map[index].filter = filter;
|
||||
map[index].extensionBegin = filterList[index].spec;
|
||||
map[index].extensionEnd = nullptr;
|
||||
|
||||
// count number of file extensions
|
||||
size_t sep = 1;
|
||||
for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) {
|
||||
if (*p_spec == L',') {
|
||||
++sep;
|
||||
}
|
||||
}
|
||||
|
||||
// friendly name conversions: "png,jpg" -> "Image files
|
||||
// (png, jpg)"
|
||||
|
||||
// calculate space needed (including the trailing '\0')
|
||||
size_t nameSize =
|
||||
sep + strlen(filterList[index].spec) + 3 + strlen(filterList[index].name);
|
||||
|
||||
// malloc the required memory
|
||||
nfdnchar_t* nameBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) * nameSize);
|
||||
|
||||
nfdnchar_t* p_nameBuf = nameBuf;
|
||||
for (const nfdnchar_t* p_filterName = filterList[index].name; *p_filterName;
|
||||
++p_filterName) {
|
||||
*p_nameBuf++ = *p_filterName;
|
||||
}
|
||||
*p_nameBuf++ = ' ';
|
||||
*p_nameBuf++ = '(';
|
||||
const nfdnchar_t* p_extensionStart = filterList[index].spec;
|
||||
for (const nfdnchar_t* p_spec = filterList[index].spec; true; ++p_spec) {
|
||||
if (*p_spec == ',' || !*p_spec) {
|
||||
if (*p_spec == ',') {
|
||||
*p_nameBuf++ = ',';
|
||||
*p_nameBuf++ = ' ';
|
||||
}
|
||||
|
||||
// +1 for the trailing '\0'
|
||||
nfdnchar_t* extnBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) *
|
||||
(p_spec - p_extensionStart + 3));
|
||||
nfdnchar_t* p_extnBufEnd = extnBuf;
|
||||
*p_extnBufEnd++ = '*';
|
||||
*p_extnBufEnd++ = '.';
|
||||
p_extnBufEnd = copy(p_extensionStart, p_spec, p_extnBufEnd);
|
||||
*p_extnBufEnd++ = '\0';
|
||||
assert((size_t)(p_extnBufEnd - extnBuf) ==
|
||||
sizeof(nfdnchar_t) * (p_spec - p_extensionStart + 3));
|
||||
gtk_file_filter_add_pattern(filter, extnBuf);
|
||||
NFDi_Free(extnBuf);
|
||||
|
||||
// store current pointer in map (if it's
|
||||
// the first one)
|
||||
if (map[index].extensionEnd == nullptr) {
|
||||
map[index].extensionEnd = p_spec;
|
||||
}
|
||||
|
||||
if (*p_spec) {
|
||||
// update the extension start point
|
||||
p_extensionStart = p_spec + 1;
|
||||
} else {
|
||||
// reached the '\0' character
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*p_nameBuf++ = *p_spec;
|
||||
}
|
||||
}
|
||||
*p_nameBuf++ = ')';
|
||||
*p_nameBuf++ = '\0';
|
||||
assert((size_t)(p_nameBuf - nameBuf) == sizeof(nfdnchar_t) * nameSize);
|
||||
|
||||
// add to the filter
|
||||
gtk_file_filter_set_name(filter, nameBuf);
|
||||
|
||||
// free the memory
|
||||
NFDi_Free(nameBuf);
|
||||
|
||||
// add filter to chooser
|
||||
gtk_file_chooser_add_filter(chooser, filter);
|
||||
}
|
||||
}
|
||||
// set trailing map index to null
|
||||
map[filterCount].filter = nullptr;
|
||||
|
||||
/* always append a wildcard option to the end*/
|
||||
GtkFileFilter* filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter, "All files");
|
||||
gtk_file_filter_add_pattern(filter, "*");
|
||||
gtk_file_chooser_add_filter(chooser, filter);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void SetDefaultPath(GtkFileChooser* chooser, const char* defaultPath) {
|
||||
if (!defaultPath || !*defaultPath) return;
|
||||
|
||||
/* GTK+ manual recommends not specifically setting the default path.
|
||||
We do it anyway in order to be consistent across platforms.
|
||||
|
||||
If consistency with the native OS is preferred, this is the line
|
||||
to comment out. -ml */
|
||||
gtk_file_chooser_set_current_folder(chooser, defaultPath);
|
||||
}
|
||||
|
||||
void SetDefaultName(GtkFileChooser* chooser, const char* defaultName) {
|
||||
if (!defaultName || !*defaultName) return;
|
||||
|
||||
gtk_file_chooser_set_current_name(chooser, defaultName);
|
||||
}
|
||||
|
||||
void WaitForCleanup() {
|
||||
while (gtk_events_pending()) gtk_main_iteration();
|
||||
}
|
||||
|
||||
struct Widget_Guard {
|
||||
GtkWidget* data;
|
||||
Widget_Guard(GtkWidget* widget) : data(widget) {}
|
||||
~Widget_Guard() {
|
||||
WaitForCleanup();
|
||||
gtk_widget_destroy(data);
|
||||
WaitForCleanup();
|
||||
}
|
||||
};
|
||||
|
||||
void FileActivatedSignalHandler(GtkButton* saveButton, void* userdata) {
|
||||
(void)saveButton; // silence the unused arg warning
|
||||
|
||||
ButtonClickedArgs* args = static_cast<ButtonClickedArgs*>(userdata);
|
||||
GtkFileChooser* chooser = args->chooser;
|
||||
char* currentFileName = gtk_file_chooser_get_current_name(chooser);
|
||||
if (*currentFileName) { // string is not empty
|
||||
|
||||
// find a '.' in the file name
|
||||
const char* p_period = currentFileName;
|
||||
for (; *p_period; ++p_period) {
|
||||
if (*p_period == '.') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*p_period) { // there is no '.', so append the default extension
|
||||
Pair_GtkFileFilter_FileExtension* filterMap =
|
||||
static_cast<Pair_GtkFileFilter_FileExtension*>(args->map);
|
||||
GtkFileFilter* currentFilter = gtk_file_chooser_get_filter(chooser);
|
||||
if (currentFilter) {
|
||||
for (; filterMap->filter; ++filterMap) {
|
||||
if (filterMap->filter == currentFilter) break;
|
||||
}
|
||||
}
|
||||
if (filterMap->filter) {
|
||||
// memory for appended string (including '.' and
|
||||
// trailing '\0')
|
||||
char* appendedFileName = NFDi_Malloc<char>(
|
||||
sizeof(char) * ((p_period - currentFileName) +
|
||||
(filterMap->extensionEnd - filterMap->extensionBegin) + 2));
|
||||
char* p_fileName = copy(currentFileName, p_period, appendedFileName);
|
||||
*p_fileName++ = '.';
|
||||
p_fileName = copy(filterMap->extensionBegin, filterMap->extensionEnd, p_fileName);
|
||||
*p_fileName++ = '\0';
|
||||
|
||||
assert(p_fileName - appendedFileName ==
|
||||
(p_period - currentFileName) +
|
||||
(filterMap->extensionEnd - filterMap->extensionBegin) + 2);
|
||||
|
||||
// set the appended file name
|
||||
gtk_file_chooser_set_current_name(chooser, appendedFileName);
|
||||
|
||||
// free the memory
|
||||
NFDi_Free(appendedFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free the memory
|
||||
g_free(currentFileName);
|
||||
}
|
||||
|
||||
// wrapper for gtk_dialog_run() that brings the dialog to the front
|
||||
// see issues at:
|
||||
// https://github.com/btzy/nativefiledialog-extended/issues/31
|
||||
// https://github.com/mlabbe/nativefiledialog/pull/92
|
||||
// https://github.com/guillaumechereau/noc/pull/11
|
||||
gint RunDialogWithFocus(GtkDialog* dialog) {
|
||||
#if defined(GDK_WINDOWING_X11)
|
||||
gtk_widget_show_all(GTK_WIDGET(dialog)); // show the dialog so that it gets a display
|
||||
if (GDK_IS_X11_DISPLAY(gtk_widget_get_display(GTK_WIDGET(dialog)))) {
|
||||
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(dialog));
|
||||
gdk_window_set_events(
|
||||
window,
|
||||
static_cast<GdkEventMask>(gdk_window_get_events(window) | GDK_PROPERTY_CHANGE_MASK));
|
||||
gtk_window_present_with_time(GTK_WINDOW(dialog), gdk_x11_get_server_time(window));
|
||||
}
|
||||
#endif
|
||||
return gtk_dialog_run(dialog);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char* NFD_GetError(void) {
|
||||
return g_errorstr;
|
||||
}
|
||||
|
||||
void NFD_ClearError(void) {
|
||||
NFDi_SetError(nullptr);
|
||||
}
|
||||
|
||||
/* public */
|
||||
|
||||
nfdresult_t NFD_Init(void) {
|
||||
// Init GTK
|
||||
if (!gtk_init_check(NULL, NULL)) {
|
||||
NFDi_SetError("Failed to initialize GTK+ with gtk_init_check.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
return NFD_OKAY;
|
||||
}
|
||||
void NFD_Quit(void) {
|
||||
// do nothing, GTK cannot be de-initialized
|
||||
}
|
||||
|
||||
void NFD_FreePathN(nfdnchar_t* filePath) {
|
||||
assert(filePath);
|
||||
g_free(filePath);
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath) {
|
||||
GtkWidget* widget = gtk_file_chooser_dialog_new("Open File",
|
||||
nullptr,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Open",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
nullptr);
|
||||
|
||||
// guard to destroy the widget when returning from this function
|
||||
Widget_Guard widgetGuard(widget);
|
||||
|
||||
/* Build the filter list */
|
||||
AddFiltersToDialog(GTK_FILE_CHOOSER(widget), filterList, filterCount);
|
||||
|
||||
/* Set the default path */
|
||||
SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath);
|
||||
|
||||
if (RunDialogWithFocus(GTK_DIALOG(widget)) == GTK_RESPONSE_ACCEPT) {
|
||||
// write out the file name
|
||||
*outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
|
||||
|
||||
return NFD_OKAY;
|
||||
} else {
|
||||
return NFD_CANCEL;
|
||||
}
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath) {
|
||||
GtkWidget* widget = gtk_file_chooser_dialog_new("Open Files",
|
||||
nullptr,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Open",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
nullptr);
|
||||
|
||||
// guard to destroy the widget when returning from this function
|
||||
Widget_Guard widgetGuard(widget);
|
||||
|
||||
// set select multiple
|
||||
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(widget), TRUE);
|
||||
|
||||
/* Build the filter list */
|
||||
AddFiltersToDialog(GTK_FILE_CHOOSER(widget), filterList, filterCount);
|
||||
|
||||
/* Set the default path */
|
||||
SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath);
|
||||
|
||||
if (RunDialogWithFocus(GTK_DIALOG(widget)) == GTK_RESPONSE_ACCEPT) {
|
||||
// write out the file name
|
||||
GSList* fileList = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(widget));
|
||||
|
||||
*outPaths = static_cast<void*>(fileList);
|
||||
return NFD_OKAY;
|
||||
} else {
|
||||
return NFD_CANCEL;
|
||||
}
|
||||
}
|
||||
|
||||
nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath,
|
||||
const nfdnchar_t* defaultName) {
|
||||
GtkWidget* widget = gtk_file_chooser_dialog_new("Save File",
|
||||
nullptr,
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
nullptr);
|
||||
|
||||
// guard to destroy the widget when returning from this function
|
||||
Widget_Guard widgetGuard(widget);
|
||||
|
||||
GtkWidget* saveButton = gtk_dialog_add_button(GTK_DIALOG(widget), "_Save", GTK_RESPONSE_ACCEPT);
|
||||
|
||||
// Prompt on overwrite
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widget), TRUE);
|
||||
|
||||
/* Build the filter list */
|
||||
ButtonClickedArgs buttonClickedArgs;
|
||||
buttonClickedArgs.chooser = GTK_FILE_CHOOSER(widget);
|
||||
buttonClickedArgs.map =
|
||||
AddFiltersToDialogWithMap(GTK_FILE_CHOOSER(widget), filterList, filterCount);
|
||||
|
||||
/* Set the default path */
|
||||
SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath);
|
||||
|
||||
/* Set the default file name */
|
||||
SetDefaultName(GTK_FILE_CHOOSER(widget), defaultName);
|
||||
|
||||
/* set the handler to add file extension */
|
||||
gulong handlerID = g_signal_connect(G_OBJECT(saveButton),
|
||||
"pressed",
|
||||
G_CALLBACK(FileActivatedSignalHandler),
|
||||
static_cast<void*>(&buttonClickedArgs));
|
||||
|
||||
/* invoke the dialog (blocks until dialog is closed) */
|
||||
gint result = RunDialogWithFocus(GTK_DIALOG(widget));
|
||||
/* unset the handler */
|
||||
g_signal_handler_disconnect(G_OBJECT(saveButton), handlerID);
|
||||
|
||||
/* free the filter map */
|
||||
NFDi_Free(buttonClickedArgs.map);
|
||||
|
||||
if (result == GTK_RESPONSE_ACCEPT) {
|
||||
// write out the file name
|
||||
*outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
|
||||
|
||||
return NFD_OKAY;
|
||||
} else {
|
||||
return NFD_CANCEL;
|
||||
}
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) {
|
||||
GtkWidget* widget = gtk_file_chooser_dialog_new("Select folder",
|
||||
nullptr,
|
||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Select",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
nullptr);
|
||||
|
||||
// guard to destroy the widget when returning from this function
|
||||
Widget_Guard widgetGuard(widget);
|
||||
|
||||
/* Set the default path */
|
||||
SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath);
|
||||
|
||||
if (RunDialogWithFocus(GTK_DIALOG(widget)) == GTK_RESPONSE_ACCEPT) {
|
||||
// write out the file name
|
||||
*outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
|
||||
|
||||
return NFD_OKAY;
|
||||
} else {
|
||||
return NFD_CANCEL;
|
||||
}
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count) {
|
||||
assert(pathSet);
|
||||
// const_cast because methods on GSList aren't const, but it should act
|
||||
// like const to the caller
|
||||
GSList* fileList = const_cast<GSList*>(static_cast<const GSList*>(pathSet));
|
||||
|
||||
*count = g_slist_length(fileList);
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet,
|
||||
nfdpathsetsize_t index,
|
||||
nfdnchar_t** outPath) {
|
||||
assert(pathSet);
|
||||
// const_cast because methods on GSList aren't const, but it should act
|
||||
// like const to the caller
|
||||
GSList* fileList = const_cast<GSList*>(static_cast<const GSList*>(pathSet));
|
||||
|
||||
// Note: this takes linear time... but should be good enough
|
||||
*outPath = static_cast<nfdnchar_t*>(g_slist_nth_data(fileList, index));
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
void NFD_PathSet_FreePathN(const nfdnchar_t* filePath) {
|
||||
assert(filePath);
|
||||
(void)filePath; // prevent warning in release build
|
||||
// no-op, because NFD_PathSet_Free does the freeing for us
|
||||
}
|
||||
|
||||
void NFD_PathSet_Free(const nfdpathset_t* pathSet) {
|
||||
assert(pathSet);
|
||||
// const_cast because methods on GSList aren't const, but it should act
|
||||
// like const to the caller
|
||||
GSList* fileList = const_cast<GSList*>(static_cast<const GSList*>(pathSet));
|
||||
|
||||
// free all the nodes
|
||||
for (GSList* node = fileList; node; node = node->next) {
|
||||
assert(node->data);
|
||||
g_free(node->data);
|
||||
}
|
||||
|
||||
// free the path set memory
|
||||
g_slist_free(fileList);
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, nfdpathsetenum_t* outEnumerator) {
|
||||
// The pathset (GSList) is already a linked list, so the enumeration is itself
|
||||
outEnumerator->ptr = const_cast<void*>(pathSet);
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
void NFD_PathSet_FreeEnum(nfdpathsetenum_t*) {
|
||||
// Do nothing, because the enumeration is the pathset itself
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath) {
|
||||
const GSList* fileList = static_cast<const GSList*>(enumerator->ptr);
|
||||
|
||||
if (fileList) {
|
||||
*outPath = static_cast<nfdnchar_t*>(fileList->data);
|
||||
enumerator->ptr = static_cast<void*>(fileList->next);
|
||||
} else {
|
||||
*outPath = nullptr;
|
||||
}
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,969 +0,0 @@
|
||||
/*
|
||||
Native File Dialog Extended
|
||||
Repository: https://github.com/btzy/nativefiledialog-extended
|
||||
License: Zlib
|
||||
Author: Bernard Teo
|
||||
*/
|
||||
|
||||
/* only locally define UNICODE in this compilation unit */
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
// Explicitly setting NTDDI version, this is necessary for the MinGW compiler
|
||||
#define NTDDI_VERSION NTDDI_VISTA
|
||||
#define _WIN32_WINNT _WIN32_WINNT_VISTA
|
||||
#endif
|
||||
|
||||
#if _MSC_VER
|
||||
// see
|
||||
// https://developercommunity.visualstudio.com/content/problem/185399/error-c2760-in-combaseapih-with-windows-sdk-81-and.html
|
||||
struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error: 'identifier' was
|
||||
// unexpected here" when using /permissive-
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <shobjidl.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <windows.h>
|
||||
#include "nfd.h"
|
||||
|
||||
namespace {
|
||||
|
||||
/* current error */
|
||||
const char* g_errorstr = nullptr;
|
||||
|
||||
void NFDi_SetError(const char* msg) {
|
||||
g_errorstr = msg;
|
||||
}
|
||||
|
||||
template <typename T = void>
|
||||
T* NFDi_Malloc(size_t bytes) {
|
||||
void* ptr = malloc(bytes);
|
||||
if (!ptr) NFDi_SetError("NFDi_Malloc failed.");
|
||||
|
||||
return static_cast<T*>(ptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void NFDi_Free(T* ptr) {
|
||||
assert(ptr);
|
||||
free(static_cast<void*>(ptr));
|
||||
}
|
||||
|
||||
/* guard objects */
|
||||
template <typename T>
|
||||
struct Release_Guard {
|
||||
T* data;
|
||||
Release_Guard(T* releasable) noexcept : data(releasable) {}
|
||||
~Release_Guard() { data->Release(); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Free_Guard {
|
||||
T* data;
|
||||
Free_Guard(T* freeable) noexcept : data(freeable) {}
|
||||
~Free_Guard() { NFDi_Free(data); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct FreeCheck_Guard {
|
||||
T* data;
|
||||
FreeCheck_Guard(T* freeable = nullptr) noexcept : data(freeable) {}
|
||||
~FreeCheck_Guard() {
|
||||
if (data) NFDi_Free(data);
|
||||
}
|
||||
};
|
||||
|
||||
/* helper functions */
|
||||
nfdresult_t AddFiltersToDialog(::IFileDialog* fileOpenDialog,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount) {
|
||||
/* filterCount plus 1 because we hardcode the *.* wildcard after the while loop */
|
||||
COMDLG_FILTERSPEC* specList =
|
||||
NFDi_Malloc<COMDLG_FILTERSPEC>(sizeof(COMDLG_FILTERSPEC) * (filterCount + 1));
|
||||
if (!specList) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
/* ad-hoc RAII object to free memory when destructing */
|
||||
struct COMDLG_FILTERSPEC_Guard {
|
||||
COMDLG_FILTERSPEC* _specList;
|
||||
nfdfiltersize_t index;
|
||||
COMDLG_FILTERSPEC_Guard(COMDLG_FILTERSPEC* specList) noexcept
|
||||
: _specList(specList), index(0) {}
|
||||
~COMDLG_FILTERSPEC_Guard() {
|
||||
for (--index; index != static_cast<nfdfiltersize_t>(-1); --index) {
|
||||
NFDi_Free(const_cast<nfdnchar_t*>(_specList[index].pszSpec));
|
||||
}
|
||||
NFDi_Free(_specList);
|
||||
}
|
||||
};
|
||||
|
||||
COMDLG_FILTERSPEC_Guard specListGuard(specList);
|
||||
|
||||
if (filterCount) {
|
||||
assert(filterList);
|
||||
|
||||
// we have filters to add ... format and add them
|
||||
|
||||
// use the index that comes from the RAII object (instead of making a copy), so the RAII
|
||||
// object will know which memory to free
|
||||
nfdfiltersize_t& index = specListGuard.index;
|
||||
|
||||
for (; index != filterCount; ++index) {
|
||||
// set the friendly name of this filter
|
||||
specList[index].pszName = filterList[index].name;
|
||||
|
||||
// set the specification of this filter...
|
||||
|
||||
// count number of file extensions
|
||||
size_t sep = 1;
|
||||
for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) {
|
||||
if (*p_spec == L',') {
|
||||
++sep;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate space needed (including the trailing '\0')
|
||||
size_t specSize = sep * 2 + wcslen(filterList[index].spec) + 1;
|
||||
|
||||
// malloc the required memory and populate it
|
||||
nfdnchar_t* specBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) * specSize);
|
||||
|
||||
if (!specBuf) {
|
||||
// automatic freeing of memory via COMDLG_FILTERSPEC_Guard
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// convert "png,jpg" to "*.png;*.jpg" as required by Windows ...
|
||||
nfdnchar_t* p_specBuf = specBuf;
|
||||
*p_specBuf++ = L'*';
|
||||
*p_specBuf++ = L'.';
|
||||
for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) {
|
||||
if (*p_spec == L',') {
|
||||
*p_specBuf++ = L';';
|
||||
*p_specBuf++ = L'*';
|
||||
*p_specBuf++ = L'.';
|
||||
} else {
|
||||
*p_specBuf++ = *p_spec;
|
||||
}
|
||||
}
|
||||
*p_specBuf++ = L'\0';
|
||||
|
||||
// assert that we had allocated exactly the correct amount of memory that we used
|
||||
assert(static_cast<size_t>(p_specBuf - specBuf) == specSize);
|
||||
|
||||
// save the buffer to the guard object
|
||||
specList[index].pszSpec = specBuf;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add wildcard */
|
||||
specList[filterCount].pszName = L"All files";
|
||||
specList[filterCount].pszSpec = L"*.*";
|
||||
|
||||
// add the filter to the dialog
|
||||
if (!SUCCEEDED(fileOpenDialog->SetFileTypes(filterCount + 1, specList))) {
|
||||
NFDi_SetError("Failed to set the allowable file types for the drop-down menu.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// automatic freeing of memory via COMDLG_FILTERSPEC_Guard
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
/* call after AddFiltersToDialog */
|
||||
nfdresult_t SetDefaultExtension(::IFileDialog* fileOpenDialog,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount) {
|
||||
// if there are no filters, then don't set default extensions
|
||||
if (!filterCount) {
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
assert(filterList);
|
||||
|
||||
// set the first item as the default index, and set the default extension
|
||||
if (!SUCCEEDED(fileOpenDialog->SetFileTypeIndex(1))) {
|
||||
NFDi_SetError("Failed to set the selected file type index.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// set the first item as the default file extension
|
||||
const nfdnchar_t* p_spec = filterList[0].spec;
|
||||
for (; *p_spec; ++p_spec) {
|
||||
if (*p_spec == ',') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*p_spec) {
|
||||
// multiple file extensions for this type (need to allocate memory)
|
||||
size_t numChars = p_spec - filterList[0].spec;
|
||||
// allocate one more char space for the '\0'
|
||||
nfdnchar_t* extnBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) * (numChars + 1));
|
||||
if (!extnBuf) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
Free_Guard<nfdnchar_t> extnBufGuard(extnBuf);
|
||||
|
||||
// copy the extension
|
||||
for (size_t i = 0; i != numChars; ++i) {
|
||||
extnBuf[i] = filterList[0].spec[i];
|
||||
}
|
||||
// pad with trailing '\0'
|
||||
extnBuf[numChars] = L'\0';
|
||||
|
||||
if (!SUCCEEDED(fileOpenDialog->SetDefaultExtension(extnBuf))) {
|
||||
NFDi_SetError("Failed to set default extension.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
} else {
|
||||
// single file extension for this type (no need to allocate memory)
|
||||
if (!SUCCEEDED(fileOpenDialog->SetDefaultExtension(filterList[0].spec))) {
|
||||
NFDi_SetError("Failed to set default extension.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) {
|
||||
if (!defaultPath || !*defaultPath) return NFD_OKAY;
|
||||
|
||||
IShellItem* folder;
|
||||
HRESULT result = SHCreateItemFromParsingName(defaultPath, nullptr, IID_PPV_ARGS(&folder));
|
||||
|
||||
// Valid non results.
|
||||
if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
||||
result == HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE)) {
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Failed to create ShellItem for setting the default path.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
Release_Guard<IShellItem> folderGuard(folder);
|
||||
|
||||
// SetDefaultFolder() might use another recently used folder if available, so the user doesn't
|
||||
// need to keep navigating back to the default folder (recommended by Windows). change to
|
||||
// SetFolder() if you always want to use the default folder
|
||||
if (!SUCCEEDED(dialog->SetDefaultFolder(folder))) {
|
||||
NFDi_SetError("Failed to set default path.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t SetDefaultName(IFileDialog* dialog, const nfdnchar_t* defaultName) {
|
||||
if (!defaultName || !*defaultName) return NFD_OKAY;
|
||||
|
||||
if (!SUCCEEDED(dialog->SetFileName(defaultName))) {
|
||||
NFDi_SetError("Failed to set default file name.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t AddOptions(IFileDialog* dialog, FILEOPENDIALOGOPTIONS options) {
|
||||
FILEOPENDIALOGOPTIONS existingOptions;
|
||||
if (!SUCCEEDED(dialog->GetOptions(&existingOptions))) {
|
||||
NFDi_SetError("Failed to get options.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
if (!SUCCEEDED(dialog->SetOptions(existingOptions | options))) {
|
||||
NFDi_SetError("Failed to set options.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
return NFD_OKAY;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
const char* NFD_GetError(void) {
|
||||
return g_errorstr;
|
||||
}
|
||||
|
||||
void NFD_ClearError(void) {
|
||||
NFDi_SetError(nullptr);
|
||||
}
|
||||
|
||||
/* public */
|
||||
|
||||
namespace {
|
||||
// The user might have initialized with COINIT_MULTITHREADED before,
|
||||
// in which case we will fail to do CoInitializeEx(), but file dialogs will still work.
|
||||
// See https://github.com/mlabbe/nativefiledialog/issues/72 for more information.
|
||||
bool needs_uninitialize;
|
||||
} // namespace
|
||||
|
||||
nfdresult_t NFD_Init(void) {
|
||||
// Init COM library.
|
||||
HRESULT result =
|
||||
::CoInitializeEx(nullptr, ::COINIT_APARTMENTTHREADED | ::COINIT_DISABLE_OLE1DDE);
|
||||
|
||||
if (SUCCEEDED(result)) {
|
||||
needs_uninitialize = true;
|
||||
return NFD_OKAY;
|
||||
} else if (result == RPC_E_CHANGED_MODE) {
|
||||
// If this happens, the user already initialized COM using COINIT_MULTITHREADED,
|
||||
// so COM will still work, but we shouldn't uninitialize it later.
|
||||
needs_uninitialize = false;
|
||||
return NFD_OKAY;
|
||||
} else {
|
||||
NFDi_SetError("Failed to initialize COM.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
void NFD_Quit(void) {
|
||||
if (needs_uninitialize) ::CoUninitialize();
|
||||
}
|
||||
|
||||
void NFD_FreePathN(nfdnchar_t* filePath) {
|
||||
assert(filePath);
|
||||
::CoTaskMemFree(filePath);
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath) {
|
||||
::IFileOpenDialog* fileOpenDialog;
|
||||
|
||||
// Create dialog
|
||||
HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog,
|
||||
nullptr,
|
||||
CLSCTX_ALL,
|
||||
::IID_IFileOpenDialog,
|
||||
reinterpret_cast<void**>(&fileOpenDialog));
|
||||
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not create dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// make sure we remember to free the dialog
|
||||
Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog);
|
||||
|
||||
// Build the filter list
|
||||
if (!AddFiltersToDialog(fileOpenDialog, filterList, filterCount)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set auto-completed default extension
|
||||
if (!SetDefaultExtension(fileOpenDialog, filterList, filterCount)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set the default path
|
||||
if (!SetDefaultPath(fileOpenDialog, defaultPath)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Only show file system items
|
||||
if (!AddOptions(fileOpenDialog, ::FOS_FORCEFILESYSTEM)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Show the dialog.
|
||||
result = fileOpenDialog->Show(nullptr);
|
||||
if (SUCCEEDED(result)) {
|
||||
// Get the file name
|
||||
::IShellItem* psiResult;
|
||||
result = fileOpenDialog->GetResult(&psiResult);
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not get shell item from dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
Release_Guard<::IShellItem> psiResultGuard(psiResult);
|
||||
|
||||
nfdnchar_t* filePath;
|
||||
result = psiResult->GetDisplayName(::SIGDN_FILESYSPATH, &filePath);
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not get file path from shell item returned by dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
*outPath = filePath;
|
||||
|
||||
return NFD_OKAY;
|
||||
} else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
||||
return NFD_CANCEL;
|
||||
} else {
|
||||
NFDi_SetError("File dialog box show failed.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath) {
|
||||
::IFileOpenDialog* fileOpenDialog(nullptr);
|
||||
|
||||
// Create dialog
|
||||
HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog,
|
||||
nullptr,
|
||||
CLSCTX_ALL,
|
||||
::IID_IFileOpenDialog,
|
||||
reinterpret_cast<void**>(&fileOpenDialog));
|
||||
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not create dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// make sure we remember to free the dialog
|
||||
Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog);
|
||||
|
||||
// Build the filter list
|
||||
if (!AddFiltersToDialog(fileOpenDialog, filterList, filterCount)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set auto-completed default extension
|
||||
if (!SetDefaultExtension(fileOpenDialog, filterList, filterCount)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set the default path
|
||||
if (!SetDefaultPath(fileOpenDialog, defaultPath)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set a flag for multiple options and file system items only
|
||||
if (!AddOptions(fileOpenDialog, ::FOS_FORCEFILESYSTEM | ::FOS_ALLOWMULTISELECT)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Show the dialog.
|
||||
result = fileOpenDialog->Show(nullptr);
|
||||
if (SUCCEEDED(result)) {
|
||||
::IShellItemArray* shellItems;
|
||||
result = fileOpenDialog->GetResults(&shellItems);
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not get shell items.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// save the path set to the output
|
||||
*outPaths = static_cast<void*>(shellItems);
|
||||
|
||||
return NFD_OKAY;
|
||||
} else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
||||
return NFD_CANCEL;
|
||||
} else {
|
||||
NFDi_SetError("File dialog box show failed.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath,
|
||||
const nfdnfilteritem_t* filterList,
|
||||
nfdfiltersize_t filterCount,
|
||||
const nfdnchar_t* defaultPath,
|
||||
const nfdnchar_t* defaultName) {
|
||||
::IFileSaveDialog* fileSaveDialog;
|
||||
|
||||
// Create dialog
|
||||
HRESULT result = ::CoCreateInstance(::CLSID_FileSaveDialog,
|
||||
nullptr,
|
||||
CLSCTX_ALL,
|
||||
::IID_IFileSaveDialog,
|
||||
reinterpret_cast<void**>(&fileSaveDialog));
|
||||
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not create dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// make sure we remember to free the dialog
|
||||
Release_Guard<::IFileSaveDialog> fileSaveDialogGuard(fileSaveDialog);
|
||||
|
||||
// Build the filter list
|
||||
if (!AddFiltersToDialog(fileSaveDialog, filterList, filterCount)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set default extension
|
||||
if (!SetDefaultExtension(fileSaveDialog, filterList, filterCount)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set the default path
|
||||
if (!SetDefaultPath(fileSaveDialog, defaultPath)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Set the default name
|
||||
if (!SetDefaultName(fileSaveDialog, defaultName)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Only show file system items
|
||||
if (!AddOptions(fileSaveDialog, ::FOS_FORCEFILESYSTEM)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Show the dialog.
|
||||
result = fileSaveDialog->Show(nullptr);
|
||||
if (SUCCEEDED(result)) {
|
||||
// Get the file name
|
||||
::IShellItem* psiResult;
|
||||
result = fileSaveDialog->GetResult(&psiResult);
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not get shell item from dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
Release_Guard<::IShellItem> psiResultGuard(psiResult);
|
||||
|
||||
nfdnchar_t* filePath;
|
||||
result = psiResult->GetDisplayName(::SIGDN_FILESYSPATH, &filePath);
|
||||
if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("Could not get file path from shell item returned by dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
*outPath = filePath;
|
||||
|
||||
return NFD_OKAY;
|
||||
} else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
||||
return NFD_CANCEL;
|
||||
} else {
|
||||
NFDi_SetError("File dialog box show failed.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) {
|
||||
::IFileOpenDialog* fileOpenDialog;
|
||||
|
||||
// Create dialog
|
||||
if (!SUCCEEDED(::CoCreateInstance(::CLSID_FileOpenDialog,
|
||||
nullptr,
|
||||
CLSCTX_ALL,
|
||||
::IID_IFileOpenDialog,
|
||||
reinterpret_cast<void**>(&fileOpenDialog)))) {
|
||||
NFDi_SetError("Could not create dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog);
|
||||
|
||||
// Set the default path
|
||||
if (!SetDefaultPath(fileOpenDialog, defaultPath)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Only show items that are folders and on the file system
|
||||
if (!AddOptions(fileOpenDialog, ::FOS_FORCEFILESYSTEM | ::FOS_PICKFOLDERS)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Show the dialog to the user
|
||||
const HRESULT result = fileOpenDialog->Show(nullptr);
|
||||
if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
||||
return NFD_CANCEL;
|
||||
} else if (!SUCCEEDED(result)) {
|
||||
NFDi_SetError("File dialog box show failed.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// Get the shell item result
|
||||
::IShellItem* psiResult;
|
||||
if (!SUCCEEDED(fileOpenDialog->GetResult(&psiResult))) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
Release_Guard<::IShellItem> psiResultGuard(psiResult);
|
||||
|
||||
// Finally get the path
|
||||
nfdnchar_t* filePath;
|
||||
// Why are we not using SIGDN_FILESYSPATH?
|
||||
if (!SUCCEEDED(psiResult->GetDisplayName(::SIGDN_DESKTOPABSOLUTEPARSING, &filePath))) {
|
||||
NFDi_SetError("Could not get file path from shell item returned by dialog.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
*outPath = filePath;
|
||||
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count) {
|
||||
assert(pathSet);
|
||||
// const_cast because methods on IShellItemArray aren't const, but it should act like const to
|
||||
// the caller
|
||||
::IShellItemArray* psiaPathSet =
|
||||
const_cast<::IShellItemArray*>(static_cast<const ::IShellItemArray*>(pathSet));
|
||||
|
||||
DWORD numPaths;
|
||||
if (!SUCCEEDED(psiaPathSet->GetCount(&numPaths))) {
|
||||
NFDi_SetError("Could not get path count.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
*count = numPaths;
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet,
|
||||
nfdpathsetsize_t index,
|
||||
nfdnchar_t** outPath) {
|
||||
assert(pathSet);
|
||||
// const_cast because methods on IShellItemArray aren't const, but it should act like const to
|
||||
// the caller
|
||||
::IShellItemArray* psiaPathSet =
|
||||
const_cast<::IShellItemArray*>(static_cast<const ::IShellItemArray*>(pathSet));
|
||||
|
||||
::IShellItem* psiPath;
|
||||
if (!SUCCEEDED(psiaPathSet->GetItemAt(index, &psiPath))) {
|
||||
NFDi_SetError("Could not get shell item.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
Release_Guard<::IShellItem> psiPathGuard(psiPath);
|
||||
|
||||
nfdnchar_t* name;
|
||||
if (!SUCCEEDED(psiPath->GetDisplayName(::SIGDN_FILESYSPATH, &name))) {
|
||||
NFDi_SetError("Could not get file path from shell item.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
*outPath = name;
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, nfdpathsetenum_t* outEnumerator) {
|
||||
assert(pathSet);
|
||||
// const_cast because methods on IShellItemArray aren't const, but it should act like const to
|
||||
// the caller
|
||||
::IShellItemArray* psiaPathSet =
|
||||
const_cast<::IShellItemArray*>(static_cast<const ::IShellItemArray*>(pathSet));
|
||||
|
||||
::IEnumShellItems* pesiPaths;
|
||||
if (!SUCCEEDED(psiaPathSet->EnumItems(&pesiPaths))) {
|
||||
NFDi_SetError("Could not get enumerator.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
outEnumerator->ptr = static_cast<void*>(pesiPaths);
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
void NFD_PathSet_FreeEnum(nfdpathsetenum_t* enumerator) {
|
||||
assert(enumerator->ptr);
|
||||
|
||||
::IEnumShellItems* pesiPaths = static_cast<::IEnumShellItems*>(enumerator->ptr);
|
||||
|
||||
// free the enumerator memory
|
||||
pesiPaths->Release();
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath) {
|
||||
assert(enumerator->ptr);
|
||||
|
||||
::IEnumShellItems* pesiPaths = static_cast<::IEnumShellItems*>(enumerator->ptr);
|
||||
|
||||
::IShellItem* psiPath;
|
||||
HRESULT res = pesiPaths->Next(1, &psiPath, NULL);
|
||||
if (!SUCCEEDED(res)) {
|
||||
NFDi_SetError("Could not get next item of enumerator.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
if (res != S_OK) {
|
||||
*outPath = nullptr;
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
Release_Guard<::IShellItem> psiPathGuard(psiPath);
|
||||
|
||||
nfdnchar_t* name;
|
||||
if (!SUCCEEDED(psiPath->GetDisplayName(::SIGDN_FILESYSPATH, &name))) {
|
||||
NFDi_SetError("Could not get file path from shell item.");
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
*outPath = name;
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
void NFD_PathSet_Free(const nfdpathset_t* pathSet) {
|
||||
assert(pathSet);
|
||||
// const_cast because methods on IShellItemArray aren't const, but it should act like const to
|
||||
// the caller
|
||||
::IShellItemArray* psiaPathSet =
|
||||
const_cast<::IShellItemArray*>(static_cast<const ::IShellItemArray*>(pathSet));
|
||||
|
||||
// free the path set memory
|
||||
psiaPathSet->Release();
|
||||
}
|
||||
|
||||
namespace {
|
||||
// allocs the space in outStr -- call NFDi_Free()
|
||||
nfdresult_t CopyCharToWChar(const nfdu8char_t* inStr, nfdnchar_t*& outStr) {
|
||||
int charsNeeded = MultiByteToWideChar(CP_UTF8, 0, inStr, -1, nullptr, 0);
|
||||
assert(charsNeeded);
|
||||
|
||||
nfdnchar_t* tmp_outStr = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) * charsNeeded);
|
||||
if (!tmp_outStr) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
int ret = MultiByteToWideChar(CP_UTF8, 0, inStr, -1, tmp_outStr, charsNeeded);
|
||||
assert(ret && ret == charsNeeded);
|
||||
(void)ret; // prevent warning in release build
|
||||
outStr = tmp_outStr;
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
// allocs the space in outPath -- call NFDi_Free()
|
||||
nfdresult_t CopyWCharToNFDChar(const nfdnchar_t* inStr, nfdu8char_t*& outStr) {
|
||||
int bytesNeeded = WideCharToMultiByte(CP_UTF8, 0, inStr, -1, nullptr, 0, nullptr, nullptr);
|
||||
assert(bytesNeeded);
|
||||
|
||||
nfdu8char_t* tmp_outStr = NFDi_Malloc<nfdu8char_t>(sizeof(nfdu8char_t) * bytesNeeded);
|
||||
if (!tmp_outStr) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
int ret = WideCharToMultiByte(CP_UTF8, 0, inStr, -1, tmp_outStr, bytesNeeded, nullptr, nullptr);
|
||||
assert(ret && ret == bytesNeeded);
|
||||
(void)ret; // prevent warning in release build
|
||||
outStr = tmp_outStr;
|
||||
return NFD_OKAY;
|
||||
}
|
||||
|
||||
struct FilterItem_Guard {
|
||||
nfdnfilteritem_t* data;
|
||||
nfdfiltersize_t index;
|
||||
FilterItem_Guard() noexcept : data(nullptr), index(0) {}
|
||||
~FilterItem_Guard() {
|
||||
assert(data || index == 0);
|
||||
for (--index; index != static_cast<nfdfiltersize_t>(-1); --index) {
|
||||
NFDi_Free(const_cast<nfdnchar_t*>(data[index].spec));
|
||||
NFDi_Free(const_cast<nfdnchar_t*>(data[index].name));
|
||||
}
|
||||
if (data) NFDi_Free(data);
|
||||
}
|
||||
};
|
||||
|
||||
nfdresult_t CopyFilterItem(const nfdu8filteritem_t* filterList,
|
||||
nfdfiltersize_t count,
|
||||
FilterItem_Guard& filterItemsNGuard) {
|
||||
if (count) {
|
||||
nfdnfilteritem_t*& filterItemsN = filterItemsNGuard.data;
|
||||
filterItemsN = NFDi_Malloc<nfdnfilteritem_t>(sizeof(nfdnfilteritem_t) * count);
|
||||
if (!filterItemsN) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
nfdfiltersize_t& index = filterItemsNGuard.index;
|
||||
for (; index != count; ++index) {
|
||||
nfdresult_t res = CopyCharToWChar(filterList[index].name,
|
||||
const_cast<nfdnchar_t*&>(filterItemsN[index].name));
|
||||
if (!res) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
res = CopyCharToWChar(filterList[index].spec,
|
||||
const_cast<nfdnchar_t*&>(filterItemsN[index].spec));
|
||||
if (!res) {
|
||||
// remember to free the name, because we also created it (and it won't be protected
|
||||
// by the guard, because we have not incremented the index)
|
||||
NFDi_Free(const_cast<nfdnchar_t*>(filterItemsN[index].name));
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NFD_OKAY;
|
||||
}
|
||||
nfdresult_t ConvertU8ToNative(const nfdu8char_t* u8Text, FreeCheck_Guard<nfdnchar_t>& nativeText) {
|
||||
if (u8Text) {
|
||||
nfdresult_t res = CopyCharToWChar(u8Text, nativeText.data);
|
||||
if (!res) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
}
|
||||
return NFD_OKAY;
|
||||
}
|
||||
void NormalizePathSeparator(nfdnchar_t* path) {
|
||||
if (path) {
|
||||
for (; *path; ++path) {
|
||||
if (*path == L'/') *path = L'\\';
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void NFD_FreePathU8(nfdu8char_t* outPath) {
|
||||
NFDi_Free(outPath);
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath,
|
||||
const nfdu8filteritem_t* filterList,
|
||||
nfdfiltersize_t count,
|
||||
const nfdu8char_t* defaultPath) {
|
||||
// populate the real nfdnfilteritem_t
|
||||
FilterItem_Guard filterItemsNGuard;
|
||||
if (!CopyFilterItem(filterList, count, filterItemsNGuard)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// convert and normalize the default path, but only if it is not nullptr
|
||||
FreeCheck_Guard<nfdnchar_t> defaultPathNGuard;
|
||||
ConvertU8ToNative(defaultPath, defaultPathNGuard);
|
||||
NormalizePathSeparator(defaultPathNGuard.data);
|
||||
|
||||
// call the native function
|
||||
nfdnchar_t* outPathN;
|
||||
nfdresult_t res =
|
||||
NFD_OpenDialogN(&outPathN, filterItemsNGuard.data, count, defaultPathNGuard.data);
|
||||
|
||||
if (res != NFD_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// convert the outPath to UTF-8
|
||||
res = CopyWCharToNFDChar(outPathN, *outPath);
|
||||
|
||||
// free the native out path, and return the result
|
||||
NFD_FreePathN(outPathN);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* multiple file open dialog */
|
||||
/* It is the caller's responsibility to free `outPaths` via NFD_PathSet_Free() if this function
|
||||
* returns NFD_OKAY */
|
||||
nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths,
|
||||
const nfdu8filteritem_t* filterList,
|
||||
nfdfiltersize_t count,
|
||||
const nfdu8char_t* defaultPath) {
|
||||
// populate the real nfdnfilteritem_t
|
||||
FilterItem_Guard filterItemsNGuard;
|
||||
if (!CopyFilterItem(filterList, count, filterItemsNGuard)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// convert and normalize the default path, but only if it is not nullptr
|
||||
FreeCheck_Guard<nfdnchar_t> defaultPathNGuard;
|
||||
ConvertU8ToNative(defaultPath, defaultPathNGuard);
|
||||
NormalizePathSeparator(defaultPathNGuard.data);
|
||||
|
||||
// call the native function
|
||||
return NFD_OpenDialogMultipleN(outPaths, filterItemsNGuard.data, count, defaultPathNGuard.data);
|
||||
}
|
||||
|
||||
/* save dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns
|
||||
* NFD_OKAY */
|
||||
nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath,
|
||||
const nfdu8filteritem_t* filterList,
|
||||
nfdfiltersize_t count,
|
||||
const nfdu8char_t* defaultPath,
|
||||
const nfdu8char_t* defaultName) {
|
||||
// populate the real nfdnfilteritem_t
|
||||
FilterItem_Guard filterItemsNGuard;
|
||||
if (!CopyFilterItem(filterList, count, filterItemsNGuard)) {
|
||||
return NFD_ERROR;
|
||||
}
|
||||
|
||||
// convert and normalize the default path, but only if it is not nullptr
|
||||
FreeCheck_Guard<nfdnchar_t> defaultPathNGuard;
|
||||
ConvertU8ToNative(defaultPath, defaultPathNGuard);
|
||||
NormalizePathSeparator(defaultPathNGuard.data);
|
||||
|
||||
// convert the default name, but only if it is not nullptr
|
||||
FreeCheck_Guard<nfdnchar_t> defaultNameNGuard;
|
||||
ConvertU8ToNative(defaultName, defaultNameNGuard);
|
||||
|
||||
// call the native function
|
||||
nfdnchar_t* outPathN;
|
||||
nfdresult_t res = NFD_SaveDialogN(
|
||||
&outPathN, filterItemsNGuard.data, count, defaultPathNGuard.data, defaultNameNGuard.data);
|
||||
|
||||
if (res != NFD_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// convert the outPath to UTF-8
|
||||
res = CopyWCharToNFDChar(outPathN, *outPath);
|
||||
|
||||
// free the native out path, and return the result
|
||||
NFD_FreePathN(outPathN);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* select folder dialog */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns
|
||||
* NFD_OKAY */
|
||||
nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) {
|
||||
// convert and normalize the default path, but only if it is not nullptr
|
||||
FreeCheck_Guard<nfdnchar_t> defaultPathNGuard;
|
||||
ConvertU8ToNative(defaultPath, defaultPathNGuard);
|
||||
NormalizePathSeparator(defaultPathNGuard.data);
|
||||
|
||||
// call the native function
|
||||
nfdnchar_t* outPathN;
|
||||
nfdresult_t res = NFD_PickFolderN(&outPathN, defaultPathNGuard.data);
|
||||
|
||||
if (res != NFD_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// convert the outPath to UTF-8
|
||||
res = CopyWCharToNFDChar(outPathN, *outPath);
|
||||
|
||||
// free the native out path, and return the result
|
||||
NFD_FreePathN(outPathN);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Get the UTF-8 path at offset index */
|
||||
/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns
|
||||
* NFD_OKAY */
|
||||
nfdresult_t NFD_PathSet_GetPathU8(const nfdpathset_t* pathSet,
|
||||
nfdpathsetsize_t index,
|
||||
nfdu8char_t** outPath) {
|
||||
// call the native function
|
||||
nfdnchar_t* outPathN;
|
||||
nfdresult_t res = NFD_PathSet_GetPathN(pathSet, index, &outPathN);
|
||||
|
||||
if (res != NFD_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// convert the outPath to UTF-8
|
||||
res = CopyWCharToNFDChar(outPathN, *outPath);
|
||||
|
||||
// free the native out path, and return the result
|
||||
NFD_FreePathN(outPathN);
|
||||
return res;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_PathSet_EnumNextU8(nfdpathsetenum_t* enumerator, nfdu8char_t** outPath) {
|
||||
// call the native function
|
||||
nfdnchar_t* outPathN;
|
||||
nfdresult_t res = NFD_PathSet_EnumNextN(enumerator, &outPathN);
|
||||
|
||||
if (res != NFD_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (outPathN) {
|
||||
// convert the outPath to UTF-8
|
||||
res = CopyWCharToNFDChar(outPathN, *outPath);
|
||||
|
||||
// free the native out path, and return the result
|
||||
NFD_FreePathN(outPathN);
|
||||
} else {
|
||||
*outPath = nullptr;
|
||||
res = NFD_OKAY;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
|
||||
option(NO_FILESELECTOR "Disable the file selector" OFF)
|
||||
option(GTK_FILESELECTOR "Use the GTK file selector on Linux instead of the xdg-portal one" OFF)
|
||||
@ -6,7 +6,7 @@ option(LEGACY "Instead of Wayland, use the legacy X11 backend on Linux" OFF)
|
||||
option(NO_ISA_EXTENSIONS "Disable ISA extensions (don't pass -march=native or -mcpu=native to the compiler)" OFF)
|
||||
option(NO_STATISTICS "Disable calculation of statistics" OFF)
|
||||
option(SELF_PROFILE "Enable self-profiling" OFF)
|
||||
option(NO_PARALLEL_STL "Disable parallel STL" OFF)
|
||||
option(SANITIZE "Sanitizer parameters" OFF)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/version.cmake)
|
||||
|
||||
@ -18,19 +18,56 @@ project(
|
||||
VERSION ${TRACY_VERSION_STRING}
|
||||
)
|
||||
|
||||
if(SELF_PROFILE)
|
||||
add_definitions(-DTRACY_ENABLE)
|
||||
add_compile_options(-g -O3 -fno-omit-frame-pointer)
|
||||
endif()
|
||||
|
||||
if(SANITIZE)
|
||||
add_compile_options(-fsanitize=${SANITIZE} -fno-omit-frame-pointer)
|
||||
add_link_options(-fsanitize=${SANITIZE} -fno-omit-frame-pointer)
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/config.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/vendor.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/server.cmake)
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(embed
|
||||
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/helpers
|
||||
CMAKE_ARGS
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT data
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory data
|
||||
)
|
||||
|
||||
function(Embed LIST NAME FILE)
|
||||
add_custom_command(
|
||||
OUTPUT data/${NAME}.cpp data/${NAME}.hpp
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/embed ${NAME} ${CMAKE_CURRENT_LIST_DIR}/${FILE} data/${NAME}
|
||||
DEPENDS data embed ${CMAKE_CURRENT_LIST_DIR}/${FILE}
|
||||
)
|
||||
list(APPEND ${LIST} data/${NAME}.cpp)
|
||||
return(PROPAGATE ${LIST})
|
||||
endfunction()
|
||||
|
||||
set(SERVER_FILES
|
||||
TracyAchievementData.cpp
|
||||
TracyAchievements.cpp
|
||||
TracyBadVersion.cpp
|
||||
TracyColor.cpp
|
||||
TracyConfig.cpp
|
||||
TracyEmbed.cpp
|
||||
TracyEventDebug.cpp
|
||||
TracyFileselector.cpp
|
||||
TracyFilesystem.cpp
|
||||
TracyImGui.cpp
|
||||
TracyManualData.cpp
|
||||
TracyMarkdown.cpp
|
||||
TracyMicroArchitecture.cpp
|
||||
TracyMouse.cpp
|
||||
TracyProtoHistory.cpp
|
||||
@ -55,11 +92,13 @@ set(SERVER_FILES
|
||||
TracyView_ContextSwitch.cpp
|
||||
TracyView_CpuData.cpp
|
||||
TracyView_FindZone.cpp
|
||||
TracyView_FlameGraph.cpp
|
||||
TracyView_FrameOverview.cpp
|
||||
TracyView_FrameTimeline.cpp
|
||||
TracyView_FrameTree.cpp
|
||||
TracyView_GpuTimeline.cpp
|
||||
TracyView_Locks.cpp
|
||||
TracyView_Manual.cpp
|
||||
TracyView_Memory.cpp
|
||||
TracyView_Messages.cpp
|
||||
TracyView_Navigation.cpp
|
||||
@ -78,10 +117,19 @@ set(SERVER_FILES
|
||||
TracyWeb.cpp
|
||||
)
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
list(APPEND SERVER_FILES
|
||||
TracyLlm.cpp
|
||||
TracyLlmApi.cpp
|
||||
TracyLlmChat.cpp
|
||||
TracyLlmEmbeddings.cpp
|
||||
TracyLlmTools.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
list(TRANSFORM SERVER_FILES PREPEND "src/profiler/")
|
||||
|
||||
set(PROFILER_FILES
|
||||
src/imgui/imgui_impl_opengl3.cpp
|
||||
src/ConnectionHistory.cpp
|
||||
src/Filters.cpp
|
||||
src/Fonts.cpp
|
||||
@ -97,12 +145,22 @@ set(PROFILER_FILES
|
||||
src/winmainArchDiscovery.cpp
|
||||
)
|
||||
|
||||
set(INCLUDES "")
|
||||
Embed(PROFILER_FILES SystemPrompt src/llm/system.prompt.md)
|
||||
Embed(PROFILER_FILES SystemReminder src/llm/system.reminder.md)
|
||||
Embed(PROFILER_FILES FontFixed src/font/FiraCode-Retina.ttf)
|
||||
Embed(PROFILER_FILES FontIcons src/font/Font\ Awesome\ 6\ Free-Solid-900.otf)
|
||||
Embed(PROFILER_FILES FontNormal src/font/Roboto-Regular.ttf)
|
||||
Embed(PROFILER_FILES FontBold src/font/Roboto-Bold.ttf)
|
||||
Embed(PROFILER_FILES FontItalic src/font/Roboto-Italic.ttf)
|
||||
Embed(PROFILER_FILES FontBoldItalic src/font/Roboto-BoldItalic.ttf)
|
||||
Embed(PROFILER_FILES Manual ../manual/tracy.md)
|
||||
|
||||
set(INCLUDES "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
set(LIBS "")
|
||||
|
||||
if(USE_WAYLAND)
|
||||
pkg_check_modules(WAYLAND REQUIRED egl wayland-egl wayland-cursor xkbcommon)
|
||||
set(INCLUDES "${INCLUDES};${CMAKE_CURRENT_BINARY_DIR}")
|
||||
set(INCLUDES "${INCLUDES};${WAYLAND_INCLUDE_DIRS}")
|
||||
set(LIBS "${LIBS};${WAYLAND_LIBRARIES}")
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
src/BackendWayland.cpp
|
||||
@ -110,41 +168,53 @@ if(USE_WAYLAND)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/FindWaylandScanner.cmake)
|
||||
|
||||
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
|
||||
pkg_get_variable(WAYLAND_PROTOCOLS_PKGDATADIR wayland-protocols pkgdatadir)
|
||||
CPMAddPackage(
|
||||
NAME wayland-protocols
|
||||
GIT_REPOSITORY https://gitlab.freedesktop.org/wayland/wayland-protocols.git
|
||||
GIT_TAG 1.37
|
||||
DOWNLOAD_ONLY YES
|
||||
)
|
||||
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/xdg-shell/xdg-shell.xml
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/stable/xdg-shell/xdg-shell.xml
|
||||
BASENAME xdg-shell
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/staging/xdg-activation/xdg-activation-v1.xml
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/staging/xdg-activation/xdg-activation-v1.xml
|
||||
BASENAME xdg-activation
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
|
||||
BASENAME xdg-decoration
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/staging/fractional-scale/fractional-scale-v1.xml
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/staging/fractional-scale/fractional-scale-v1.xml
|
||||
BASENAME fractional-scale
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/viewporter/viewporter.xml
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/stable/viewporter/viewporter.xml
|
||||
BASENAME viewporter
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/staging/cursor-shape/cursor-shape-v1.xml
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/staging/cursor-shape/cursor-shape-v1.xml
|
||||
BASENAME cursor-shape
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/tablet/tablet-unstable-v2.xml
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/unstable/tablet/tablet-unstable-v2.xml
|
||||
BASENAME tablet
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${wayland-protocols_SOURCE_DIR}/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml
|
||||
BASENAME xdg-toplevel-icon
|
||||
)
|
||||
elseif(EMSCRIPTEN)
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
src/BackendEmscripten.cpp
|
||||
)
|
||||
else()
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
src/BackendGlfw.cpp
|
||||
src/imgui/imgui_impl_glfw.cpp
|
||||
${ImGui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -152,9 +222,6 @@ include_directories(${INCLUDES})
|
||||
link_libraries(${LIBS})
|
||||
|
||||
if(SELF_PROFILE)
|
||||
add_definitions(-DTRACY_ENABLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -fno-omit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 -fno-omit-frame-pointer")
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
../public/TracyClient.cpp
|
||||
)
|
||||
@ -171,20 +238,72 @@ else()
|
||||
add_executable(${PROJECT_NAME} ${PROFILER_FILES} ${COMMON_FILES} ${SERVER_FILES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyImGui)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
TracyServer
|
||||
TracyImGui
|
||||
Threads::Threads
|
||||
nlohmann_json::nlohmann_json
|
||||
md4c
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${tidy_SOURCE_DIR}/include
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${md4c_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyNfd)
|
||||
if (NOT USE_WAYLAND)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
TracyLibcurl
|
||||
base64
|
||||
tidy-static
|
||||
TracyPugixml
|
||||
usearch
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED GIT_REV)
|
||||
set(GIT_REV "HEAD")
|
||||
endif()
|
||||
|
||||
find_package(Git)
|
||||
if(Git_FOUND)
|
||||
add_custom_target(git-ref
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#pragma once" > GitRef.hpp.tmp
|
||||
COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} log -1 "--format=namespace tracy { static inline const char* GitRef = %x22%h%x22; }" ${GIT_REV} >> GitRef.hpp.tmp || echo "namespace tracy { static inline const char* GitRef = \"unknown\"; }" >> GitRef.hpp.tmp
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different GitRef.hpp.tmp GitRef.hpp
|
||||
BYPRODUCTS GitRef.hpp GitRef.hpp.tmp
|
||||
VERBATIM
|
||||
)
|
||||
add_dependencies(${PROJECT_NAME} git-ref)
|
||||
else()
|
||||
message(WARNING "git not found, using 'unknown' as git ref.")
|
||||
add_custom_command(
|
||||
OUTPUT GitRef.hpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#pragma once" > GitRef.hpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "namespace tracy { static inline const char* GitRef = \"unknown\"; }" >> GitRef.hpp
|
||||
VERBATIM
|
||||
)
|
||||
target_sources(${PROJECT_NAME} PUBLIC GitRef.hpp)
|
||||
endif()
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
if(NOT NO_FILESELECTOR)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE nfd::nfd)
|
||||
endif()
|
||||
if(NOT USE_WAYLAND)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyGlfw3)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_FLAGS "-sUSE_FREETYPE=1 -pthread -DIMGUI_IMPL_OPENGL_ES2")
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY LINK_FLAGS "-sASSERTIONS=0 -sUSE_GLFW=3 -sINITIAL_MEMORY=384mb -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=4gb -sWASM_BIGINT=1 -sPTHREAD_POOL_SIZE=4 -sEXPORTED_FUNCTIONS=_main,_nativeResize,_nativeOpenFile -sEXPORTED_RUNTIME_METHODS=ccall -sENVIRONMENT=web,worker --preload-file embed.tracy")
|
||||
target_link_options(${PROJECT_NAME} PRIVATE -pthread -sASSERTIONS=0 -sINITIAL_MEMORY=384mb -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=4gb -sSTACK_SIZE=1048576 -sWASM_BIGINT=1 -sPTHREAD_POOL_SIZE=8 -sEXPORTED_FUNCTIONS=_main,_nativeOpenFile -sEXPORTED_RUNTIME_METHODS=ccall -sENVIRONMENT=web,worker --preload-file embed.tracy)
|
||||
|
||||
file(DOWNLOAD https://share.nereid.pl/i/embed.tracy ${CMAKE_CURRENT_BINARY_DIR}/embed.tracy EXPECTED_MD5 ca0fa4f01e7b8ca5581daa16b16c768d)
|
||||
file(COPY ${CMAKE_CURRENT_LIST_DIR}/wasm/index.html DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file(COPY ${CMAKE_CURRENT_LIST_DIR}/wasm/httpd.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file(COPY_FILE ${CMAKE_CURRENT_LIST_DIR}/../icon/icon.svg ${CMAKE_CURRENT_BINARY_DIR}/favicon.svg)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
13
libs/tracy/profiler/helpers/CMakeLists.txt
Normal file
13
libs/tracy/profiler/helpers/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
project(helpers LANGUAGES CXX)
|
||||
|
||||
add_executable(embed
|
||||
../../public/common/tracy_lz4.cpp
|
||||
../../public/common/tracy_lz4hc.cpp
|
||||
embed.cpp
|
||||
)
|
||||
|
||||
install(TARGETS embed DESTINATION .)
|
||||
76
libs/tracy/profiler/helpers/embed.cpp
Normal file
76
libs/tracy/profiler/helpers/embed.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "../../public/common/tracy_lz4hc.hpp"
|
||||
|
||||
static void Usage()
|
||||
{
|
||||
fprintf( stderr, "Usage: embed <objectName> <source> <destination>\n" );
|
||||
fprintf( stderr, " destination should be without extension, will create cpp, hpp pair\n" );
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
if( argc < 4 )
|
||||
{
|
||||
Usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* objectName = argv[1];
|
||||
const char* source = argv[2];
|
||||
const char* destination = argv[3];
|
||||
|
||||
FILE* src = fopen( source, "rb" );
|
||||
if( !src )
|
||||
{
|
||||
fprintf( stderr, "Failed to open source file %s\n", source );
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t sz;
|
||||
fseek( src, 0, SEEK_END );
|
||||
sz = ftell( src );
|
||||
fseek( src, 0, SEEK_SET );
|
||||
|
||||
auto data = new uint8_t[sz];
|
||||
fread( data, 1, sz, src );
|
||||
fclose( src );
|
||||
|
||||
const auto lz4szMax = tracy::LZ4_compressBound( sz );
|
||||
auto lz4data = new uint8_t[lz4szMax];
|
||||
const auto lz4sz = tracy::LZ4_compress_HC( (const char*)data, (char*)lz4data, sz, lz4szMax, 6 );
|
||||
delete[] data;
|
||||
|
||||
FILE* hdr = fopen( ( std::string(destination) + ".hpp" ).c_str(), "wb" );
|
||||
fprintf( hdr, "// This file is generated by embed tool, do not modify\n" );
|
||||
fprintf( hdr, "// Source: %s\n\n", source );
|
||||
fprintf( hdr, "#pragma once\n\n" );
|
||||
fprintf( hdr, "#include <stddef.h>\n" );
|
||||
fprintf( hdr, "#include <stdint.h>\n\n" );
|
||||
fprintf( hdr, "namespace Embed\n{\n" );
|
||||
fprintf( hdr, "constexpr size_t %sSize = %zu;\n", objectName, sz );
|
||||
fprintf( hdr, "constexpr size_t %sLz4Size = %i;\n", objectName, lz4sz );
|
||||
fprintf( hdr, "extern const uint8_t %sData[];\n", objectName );
|
||||
fprintf( hdr, "}\n" );
|
||||
fclose( hdr );
|
||||
|
||||
FILE* cpp = fopen( ( std::string(destination) + ".cpp" ).c_str(), "wb" );
|
||||
fprintf( cpp, "// This file is generated by embed tool, do not modify\n" );
|
||||
fprintf( cpp, "// Source: %s\n\n", source );
|
||||
fprintf( cpp, "#include \"%s.hpp\"\n\n", destination );
|
||||
fprintf( cpp, "namespace Embed\n{\n" );
|
||||
fprintf( cpp, "const uint8_t %sData[] =\n", objectName );
|
||||
fprintf( cpp, "{\n" );
|
||||
for( size_t i=0; i<lz4sz; i++ )
|
||||
{
|
||||
fprintf( cpp, "%d,", lz4data[i] );
|
||||
}
|
||||
fprintf( cpp, "};\n" );
|
||||
fprintf( cpp, "}\n" );
|
||||
|
||||
fclose( cpp );
|
||||
delete[] lz4data;
|
||||
return 0;
|
||||
}
|
||||
341
libs/tracy/profiler/src/BackendEmscripten.cpp
Normal file
341
libs/tracy/profiler/src/BackendEmscripten.cpp
Normal file
@ -0,0 +1,341 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <emscripten/html5.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
|
||||
#include "Backend.hpp"
|
||||
#include "RunQueue.hpp"
|
||||
#include "profiler/TracyImGui.hpp"
|
||||
|
||||
static std::function<void()> s_redraw;
|
||||
static std::function<void(float)> s_scaleChanged;
|
||||
static std::function<int(void)> s_isBusy;
|
||||
static RunQueue* s_mainThreadTasks;
|
||||
|
||||
static EGLDisplay s_eglDpy;
|
||||
static EGLContext s_eglCtx;
|
||||
static EGLSurface s_eglSurf;
|
||||
|
||||
static float s_prevScale = -1;
|
||||
static int s_width, s_height;
|
||||
static uint64_t s_time;
|
||||
static const char* s_prevCursor = nullptr;
|
||||
|
||||
static ImGuiKey TranslateKeyCode( const char* code )
|
||||
{
|
||||
if( strcmp( code, "Backquote" ) == 0 ) return ImGuiKey_GraveAccent;
|
||||
if( strcmp( code, "Backslash" ) == 0 ) return ImGuiKey_Backslash;
|
||||
if( strcmp( code, "BracketLeft" ) == 0 ) return ImGuiKey_LeftBracket;
|
||||
if( strcmp( code, "BracketRight" ) == 0 ) return ImGuiKey_RightBracket;
|
||||
if( strcmp( code, "Comma" ) == 0 ) return ImGuiKey_Comma;
|
||||
if( strcmp( code, "Digit0" ) == 0 ) return ImGuiKey_0;
|
||||
if( strcmp( code, "Digit1" ) == 0 ) return ImGuiKey_1;
|
||||
if( strcmp( code, "Digit2" ) == 0 ) return ImGuiKey_2;
|
||||
if( strcmp( code, "Digit3" ) == 0 ) return ImGuiKey_3;
|
||||
if( strcmp( code, "Digit4" ) == 0 ) return ImGuiKey_4;
|
||||
if( strcmp( code, "Digit5" ) == 0 ) return ImGuiKey_5;
|
||||
if( strcmp( code, "Digit6" ) == 0 ) return ImGuiKey_6;
|
||||
if( strcmp( code, "Digit7" ) == 0 ) return ImGuiKey_7;
|
||||
if( strcmp( code, "Digit8" ) == 0 ) return ImGuiKey_8;
|
||||
if( strcmp( code, "Digit9" ) == 0 ) return ImGuiKey_9;
|
||||
if( strcmp( code, "Equal" ) == 0 ) return ImGuiKey_Equal;
|
||||
if( strcmp( code, "IntlBackslash" ) == 0 ) return ImGuiKey_Backslash;
|
||||
if( strcmp( code, "IntlRo" ) == 0 ) return ImGuiKey_Backslash;
|
||||
if( strcmp( code, "IntlYen" ) == 0 ) return ImGuiKey_Backslash;
|
||||
if( strcmp( code, "KeyA" ) == 0 ) return ImGuiKey_A;
|
||||
if( strcmp( code, "KeyB" ) == 0 ) return ImGuiKey_B;
|
||||
if( strcmp( code, "KeyC" ) == 0 ) return ImGuiKey_C;
|
||||
if( strcmp( code, "KeyD" ) == 0 ) return ImGuiKey_D;
|
||||
if( strcmp( code, "KeyE" ) == 0 ) return ImGuiKey_E;
|
||||
if( strcmp( code, "KeyF" ) == 0 ) return ImGuiKey_F;
|
||||
if( strcmp( code, "KeyG" ) == 0 ) return ImGuiKey_G;
|
||||
if( strcmp( code, "KeyH" ) == 0 ) return ImGuiKey_H;
|
||||
if( strcmp( code, "KeyI" ) == 0 ) return ImGuiKey_I;
|
||||
if( strcmp( code, "KeyJ" ) == 0 ) return ImGuiKey_J;
|
||||
if( strcmp( code, "KeyK" ) == 0 ) return ImGuiKey_K;
|
||||
if( strcmp( code, "KeyL" ) == 0 ) return ImGuiKey_L;
|
||||
if( strcmp( code, "KeyM" ) == 0 ) return ImGuiKey_M;
|
||||
if( strcmp( code, "KeyN" ) == 0 ) return ImGuiKey_N;
|
||||
if( strcmp( code, "KeyO" ) == 0 ) return ImGuiKey_O;
|
||||
if( strcmp( code, "KeyP" ) == 0 ) return ImGuiKey_P;
|
||||
if( strcmp( code, "KeyQ" ) == 0 ) return ImGuiKey_Q;
|
||||
if( strcmp( code, "KeyR" ) == 0 ) return ImGuiKey_R;
|
||||
if( strcmp( code, "KeyS" ) == 0 ) return ImGuiKey_S;
|
||||
if( strcmp( code, "KeyT" ) == 0 ) return ImGuiKey_T;
|
||||
if( strcmp( code, "KeyU" ) == 0 ) return ImGuiKey_U;
|
||||
if( strcmp( code, "KeyV" ) == 0 ) return ImGuiKey_V;
|
||||
if( strcmp( code, "KeyW" ) == 0 ) return ImGuiKey_W;
|
||||
if( strcmp( code, "KeyX" ) == 0 ) return ImGuiKey_X;
|
||||
if( strcmp( code, "KeyY" ) == 0 ) return ImGuiKey_Y;
|
||||
if( strcmp( code, "KeyZ" ) == 0 ) return ImGuiKey_Z;
|
||||
if( strcmp( code, "Minus" ) == 0 ) return ImGuiKey_Minus;
|
||||
if( strcmp( code, "Period" ) == 0 ) return ImGuiKey_Period;
|
||||
if( strcmp( code, "Quote" ) == 0 ) return ImGuiKey_Apostrophe;
|
||||
if( strcmp( code, "Semicolon" ) == 0 ) return ImGuiKey_Semicolon;
|
||||
if( strcmp( code, "Slash" ) == 0 ) return ImGuiKey_Slash;
|
||||
if( strcmp( code, "AltLeft" ) == 0 ) return ImGuiKey_LeftAlt;
|
||||
if( strcmp( code, "AltRight" ) == 0 ) return ImGuiKey_RightAlt;
|
||||
if( strcmp( code, "Backspace" ) == 0 ) return ImGuiKey_Backspace;
|
||||
if( strcmp( code, "CapsLock" ) == 0 ) return ImGuiKey_CapsLock;
|
||||
if( strcmp( code, "ContextMenu" ) == 0 ) return ImGuiKey_Menu;
|
||||
if( strcmp( code, "ControlLeft" ) == 0 ) return ImGuiKey_LeftCtrl;
|
||||
if( strcmp( code, "ControlRight" ) == 0 ) return ImGuiKey_RightCtrl;
|
||||
if( strcmp( code, "Enter" ) == 0 ) return ImGuiKey_Enter;
|
||||
if( strcmp( code, "MetaLeft" ) == 0 ) return ImGuiKey_LeftSuper;
|
||||
if( strcmp( code, "MetaRight" ) == 0 ) return ImGuiKey_RightSuper;
|
||||
if( strcmp( code, "ShiftLeft" ) == 0 ) return ImGuiKey_LeftShift;
|
||||
if( strcmp( code, "ShiftRight" ) == 0 ) return ImGuiKey_RightShift;
|
||||
if( strcmp( code, "Space" ) == 0 ) return ImGuiKey_Space;
|
||||
if( strcmp( code, "Tab" ) == 0 ) return ImGuiKey_Tab;
|
||||
if( strcmp( code, "Delete" ) == 0 ) return ImGuiKey_Delete;
|
||||
if( strcmp( code, "End" ) == 0 ) return ImGuiKey_End;
|
||||
if( strcmp( code, "Home" ) == 0 ) return ImGuiKey_Home;
|
||||
if( strcmp( code, "Insert" ) == 0 ) return ImGuiKey_Insert;
|
||||
if( strcmp( code, "PageDown" ) == 0 ) return ImGuiKey_PageDown;
|
||||
if( strcmp( code, "PageUp" ) == 0 ) return ImGuiKey_PageUp;
|
||||
if( strcmp( code, "ArrowDown" ) == 0 ) return ImGuiKey_DownArrow;
|
||||
if( strcmp( code, "ArrowLeft" ) == 0 ) return ImGuiKey_LeftArrow;
|
||||
if( strcmp( code, "ArrowRight" ) == 0 ) return ImGuiKey_RightArrow;
|
||||
if( strcmp( code, "ArrowUp" ) == 0 ) return ImGuiKey_UpArrow;
|
||||
if( strcmp( code, "NumLock" ) == 0 ) return ImGuiKey_NumLock;
|
||||
if( strcmp( code, "Numpad0" ) == 0 ) return ImGuiKey_Keypad0;
|
||||
if( strcmp( code, "Numpad1" ) == 0 ) return ImGuiKey_Keypad1;
|
||||
if( strcmp( code, "Numpad2" ) == 0 ) return ImGuiKey_Keypad2;
|
||||
if( strcmp( code, "Numpad3" ) == 0 ) return ImGuiKey_Keypad3;
|
||||
if( strcmp( code, "Numpad4" ) == 0 ) return ImGuiKey_Keypad4;
|
||||
if( strcmp( code, "Numpad5" ) == 0 ) return ImGuiKey_Keypad5;
|
||||
if( strcmp( code, "Numpad6" ) == 0 ) return ImGuiKey_Keypad6;
|
||||
if( strcmp( code, "Numpad7" ) == 0 ) return ImGuiKey_Keypad7;
|
||||
if( strcmp( code, "Numpad8" ) == 0 ) return ImGuiKey_Keypad8;
|
||||
if( strcmp( code, "Numpad9" ) == 0 ) return ImGuiKey_Keypad9;
|
||||
if( strcmp( code, "NumpadAdd" ) == 0 ) return ImGuiKey_KeypadAdd;
|
||||
if( strcmp( code, "NumpadBackspace" ) == 0 ) return ImGuiKey_Backspace;
|
||||
if( strcmp( code, "NumpadComma" ) == 0 ) return ImGuiKey_KeypadDecimal;
|
||||
if( strcmp( code, "NumpadDecimal" ) == 0 ) return ImGuiKey_KeypadDecimal;
|
||||
if( strcmp( code, "NumpadDivide" ) == 0 ) return ImGuiKey_KeypadDivide;
|
||||
if( strcmp( code, "NumpadEnter" ) == 0 ) return ImGuiKey_KeypadEnter;
|
||||
if( strcmp( code, "NumpadEqual" ) == 0 ) return ImGuiKey_KeypadEqual;
|
||||
if( strcmp( code, "NumpadMultiply" ) == 0 ) return ImGuiKey_KeypadMultiply;
|
||||
if( strcmp( code, "NumpadSubtract" ) == 0 ) return ImGuiKey_KeypadSubtract;
|
||||
if( strcmp( code, "Escape" ) == 0 ) return ImGuiKey_Escape;
|
||||
if( strcmp( code, "F1" ) == 0 ) return ImGuiKey_F1;
|
||||
if( strcmp( code, "F2" ) == 0 ) return ImGuiKey_F2;
|
||||
if( strcmp( code, "F3" ) == 0 ) return ImGuiKey_F3;
|
||||
if( strcmp( code, "F4" ) == 0 ) return ImGuiKey_F4;
|
||||
if( strcmp( code, "F5" ) == 0 ) return ImGuiKey_F5;
|
||||
if( strcmp( code, "F6" ) == 0 ) return ImGuiKey_F6;
|
||||
if( strcmp( code, "F7" ) == 0 ) return ImGuiKey_F7;
|
||||
if( strcmp( code, "F8" ) == 0 ) return ImGuiKey_F8;
|
||||
if( strcmp( code, "F9" ) == 0 ) return ImGuiKey_F9;
|
||||
if( strcmp( code, "F10" ) == 0 ) return ImGuiKey_F10;
|
||||
// F11 is browser fullscreen, F12 is browser dev tools, omitting them
|
||||
if( strcmp( code, "ScrollLock" ) == 0 ) return ImGuiKey_ScrollLock;
|
||||
if( strcmp( code, "Pause" ) == 0 ) return ImGuiKey_Pause;
|
||||
return ImGuiKey_None;
|
||||
}
|
||||
|
||||
Backend::Backend( const char* title, const std::function<void()>& redraw, const std::function<void(float)>& scaleChanged, const std::function<int(void)>& isBusy, RunQueue* mainThreadTasks )
|
||||
{
|
||||
constexpr EGLint eglConfigAttrib[] = {
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
s_eglDpy = eglGetDisplay( EGL_DEFAULT_DISPLAY );
|
||||
EGLBoolean res;
|
||||
res = eglInitialize( s_eglDpy, nullptr, nullptr );
|
||||
if( res != EGL_TRUE ) { fprintf( stderr, "Cannot initialize EGL!\n" ); exit( 1 ); }
|
||||
|
||||
EGLint count;
|
||||
EGLConfig eglConfig;
|
||||
res = eglChooseConfig( s_eglDpy, eglConfigAttrib, &eglConfig, 1, &count );
|
||||
if( res != EGL_TRUE || count != 1 ) { fprintf( stderr, "No suitable EGL config found!\n" ); exit( 1 ); }
|
||||
|
||||
s_eglSurf = eglCreateWindowSurface( s_eglDpy, eglConfig, 0, nullptr );
|
||||
|
||||
constexpr EGLint eglCtxAttrib[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
s_eglCtx = eglCreateContext( s_eglDpy, eglConfig, EGL_NO_CONTEXT, eglCtxAttrib );
|
||||
if( !s_eglCtx ) { fprintf( stderr, "Cannot create OpenGL 3.2 Core Profile context!\n" ); exit( 1 ); }
|
||||
res = eglMakeCurrent( s_eglDpy, s_eglSurf, s_eglSurf, s_eglCtx );
|
||||
if( res != EGL_TRUE ) { fprintf( stderr, "Cannot make EGL context current!\n" ); exit( 1 ); }
|
||||
|
||||
ImGui_ImplOpenGL3_Init( "#version 100" );
|
||||
|
||||
EM_ASM( document.title = UTF8ToString($0), title );
|
||||
|
||||
s_redraw = redraw;
|
||||
s_scaleChanged = scaleChanged;
|
||||
s_isBusy = isBusy;
|
||||
s_mainThreadTasks = mainThreadTasks;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.BackendPlatformName = "wasm (tracy profiler)";
|
||||
|
||||
emscripten_set_mousedown_callback( "#canvas", nullptr, EM_TRUE, []( int, const EmscriptenMouseEvent* e, void* ) -> EM_BOOL {
|
||||
ImGui::GetIO().AddMouseButtonEvent( e->button == 0 ? 0 : 3 - e->button, true );
|
||||
tracy::s_wasActive = true;
|
||||
return EM_TRUE;
|
||||
} );
|
||||
emscripten_set_mouseup_callback( "#canvas", nullptr, EM_TRUE, []( int, const EmscriptenMouseEvent* e, void* ) -> EM_BOOL {
|
||||
ImGui::GetIO().AddMouseButtonEvent( e->button == 0 ? 0 : 3 - e->button, false );
|
||||
tracy::s_wasActive = true;
|
||||
return EM_TRUE;
|
||||
} );
|
||||
emscripten_set_mousemove_callback( "#canvas", nullptr, EM_TRUE, []( int, const EmscriptenMouseEvent* e, void* ) -> EM_BOOL {
|
||||
const auto scale = EM_ASM_DOUBLE( { return window.devicePixelRatio; } );
|
||||
ImGui::GetIO().AddMousePosEvent( e->targetX * scale, e->targetY * scale );
|
||||
tracy::s_wasActive = true;
|
||||
return EM_TRUE;
|
||||
} );
|
||||
emscripten_set_mouseleave_callback( "#canvas", nullptr, EM_TRUE, []( int, const EmscriptenMouseEvent*, void* ) -> EM_BOOL {
|
||||
ImGui::GetIO().AddFocusEvent( false );
|
||||
tracy::s_wasActive = true;
|
||||
return EM_TRUE;
|
||||
} );
|
||||
emscripten_set_mouseenter_callback( "#canvas", nullptr, EM_TRUE, []( int, const EmscriptenMouseEvent*, void* ) -> EM_BOOL {
|
||||
ImGui::GetIO().AddFocusEvent( true );
|
||||
tracy::s_wasActive = true;
|
||||
return EM_TRUE;
|
||||
} );
|
||||
emscripten_set_wheel_callback( "#canvas", nullptr, EM_TRUE, []( int, const EmscriptenWheelEvent* e, void* ) -> EM_BOOL {
|
||||
ImGui::GetIO().AddMouseWheelEvent( e->deltaX * -0.05, e->deltaY * -0.05 );
|
||||
tracy::s_wasActive = true;
|
||||
return EM_TRUE;
|
||||
} );
|
||||
emscripten_set_keydown_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, EM_TRUE, [] ( int, const EmscriptenKeyboardEvent* e, void* ) -> EM_BOOL {
|
||||
const auto code = TranslateKeyCode( e->code );
|
||||
if( code == ImGuiKey_None ) return EM_FALSE;
|
||||
ImGui::GetIO().AddKeyEvent( code, true );
|
||||
if( e->key[0] && !e->key[1] ) ImGui::GetIO().AddInputCharacter( *e->key );
|
||||
return EM_TRUE;
|
||||
} );
|
||||
emscripten_set_keyup_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, EM_TRUE, [] ( int, const EmscriptenKeyboardEvent* e, void* ) -> EM_BOOL {
|
||||
const auto code = TranslateKeyCode( e->code );
|
||||
if( code == ImGuiKey_None ) return EM_FALSE;
|
||||
ImGui::GetIO().AddKeyEvent( code, false );
|
||||
return EM_TRUE;
|
||||
} );
|
||||
|
||||
s_time = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
}
|
||||
|
||||
Backend::~Backend()
|
||||
{
|
||||
}
|
||||
|
||||
void Backend::Show()
|
||||
{
|
||||
}
|
||||
|
||||
void Backend::Run()
|
||||
{
|
||||
emscripten_set_main_loop( []() {
|
||||
s_redraw();
|
||||
s_mainThreadTasks->Run();
|
||||
}, 0, 1 );
|
||||
}
|
||||
|
||||
void Backend::Attention()
|
||||
{
|
||||
}
|
||||
|
||||
void Backend::NewFrame( int& w, int& h )
|
||||
{
|
||||
const auto scale = GetDpiScale();
|
||||
if( scale != s_prevScale )
|
||||
{
|
||||
s_prevScale = scale;
|
||||
s_scaleChanged( scale );
|
||||
}
|
||||
|
||||
w = EM_ASM_INT( { return window.innerWidth; } ) * scale;
|
||||
h = EM_ASM_INT( { return window.innerHeight; } ) * scale;
|
||||
|
||||
if( s_width != w || s_height != h )
|
||||
{
|
||||
EM_ASM( Module.canvas.style.width = window.innerWidth + 'px'; Module.canvas.style.height = window.innerHeight + 'px' );
|
||||
EM_ASM( Module.canvas.width = $0; Module.canvas.height = $1, w, h );
|
||||
|
||||
s_width = w;
|
||||
s_height = h;
|
||||
|
||||
glViewport( 0, 0, s_width, s_height );
|
||||
tracy::s_wasActive = true;
|
||||
}
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DisplaySize = ImVec2( w, h );
|
||||
io.DisplayFramebufferScale = ImVec2( 1, 1 );
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
||||
ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
|
||||
const char* cursorName;
|
||||
switch( cursor )
|
||||
{
|
||||
case ImGuiMouseCursor_None: cursorName = "none"; break;
|
||||
case ImGuiMouseCursor_Arrow:
|
||||
switch( s_isBusy() )
|
||||
{
|
||||
default:
|
||||
case 0: cursorName = "default"; break;
|
||||
case 1: cursorName = "progress"; break;
|
||||
case 2: cursorName = "wait"; break;
|
||||
}
|
||||
break;
|
||||
case ImGuiMouseCursor_TextInput: cursorName = "text"; break;
|
||||
case ImGuiMouseCursor_ResizeAll: cursorName = "move"; break;
|
||||
case ImGuiMouseCursor_ResizeNS: cursorName = "ns-resize"; break;
|
||||
case ImGuiMouseCursor_ResizeEW: cursorName = "ew-resize"; break;
|
||||
case ImGuiMouseCursor_ResizeNESW: cursorName = "nesw-resize"; break;
|
||||
case ImGuiMouseCursor_ResizeNWSE: cursorName = "nwse-resize"; break;
|
||||
case ImGuiMouseCursor_Hand: cursorName = "pointer"; break;
|
||||
case ImGuiMouseCursor_NotAllowed: cursorName = "not-allowed"; break;
|
||||
default: cursorName = "auto"; break;
|
||||
};
|
||||
if( s_prevCursor != cursorName )
|
||||
{
|
||||
s_prevCursor = cursorName;
|
||||
EM_ASM_INT( { document.getElementById('canvas').style.cursor = UTF8ToString($0); }, cursorName );
|
||||
}
|
||||
|
||||
uint64_t time = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
io.DeltaTime = std::min( 0.1f, ( time - s_time ) / 1000000.f );
|
||||
s_time = time;
|
||||
}
|
||||
|
||||
void Backend::EndFrame()
|
||||
{
|
||||
const ImVec4 clear_color = ImColor( 20, 20, 17 );
|
||||
|
||||
ImGui::Render();
|
||||
glClearColor( clear_color.x, clear_color.y, clear_color.z, clear_color.w );
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
ImGui_ImplOpenGL3_RenderDrawData( ImGui::GetDrawData() );
|
||||
}
|
||||
|
||||
void Backend::SetIcon( uint8_t* data, int w, int h )
|
||||
{
|
||||
}
|
||||
|
||||
void Backend::SetTitle( const char* title )
|
||||
{
|
||||
EM_ASM( document.title = UTF8ToString($0), title );
|
||||
}
|
||||
|
||||
float Backend::GetDpiScale()
|
||||
{
|
||||
return EM_ASM_DOUBLE( { return window.devicePixelRatio; } );
|
||||
}
|
||||
@ -1,11 +1,6 @@
|
||||
#include "imgui/imgui_impl_glfw.h"
|
||||
#include "imgui/imgui_impl_opengl3.h"
|
||||
#ifdef __EMSCRIPTEN__
|
||||
# include <GLES2/gl2.h>
|
||||
# include <emscripten/html5.h>
|
||||
#else
|
||||
# include "imgui/imgui_impl_opengl3_loader.h"
|
||||
#endif
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <backends/imgui_impl_opengl3_loader.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <GLFW/glfw3.h>
|
||||
@ -19,14 +14,65 @@
|
||||
#include "Backend.hpp"
|
||||
#include "RunQueue.hpp"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <objc/objc.h>
|
||||
#include <objc/message.h>
|
||||
#include <objc/runtime.h>
|
||||
#include "icon.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
static GLFWwindow* s_window;
|
||||
static std::function<void()> s_redraw;
|
||||
static std::function<void(float)> s_scaleChanged;
|
||||
static RunQueue* s_mainThreadTasks;
|
||||
static WindowPosition* s_winPos;
|
||||
static bool s_iconified;
|
||||
static float s_prevScale = -1;
|
||||
|
||||
extern tracy::Config s_config;
|
||||
#ifdef __APPLE__
|
||||
typedef long NSInteger;
|
||||
typedef unsigned long NSUInteger;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
static void EnsureMacAppRegistration()
|
||||
{
|
||||
static bool initialized = false;
|
||||
if( initialized ) return;
|
||||
initialized = true;
|
||||
|
||||
id pool = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSAutoreleasePool"), sel_getUid("alloc"));
|
||||
pool = ((id (*)(id, SEL))objc_msgSend)(pool, sel_getUid("init"));
|
||||
|
||||
id app = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSApplication"), sel_getUid("sharedApplication"));
|
||||
((void (*)(id, SEL, NSInteger))objc_msgSend)(app, sel_getUid("setActivationPolicy:"), (NSInteger)0);
|
||||
((void (*)(id, SEL, BOOL))objc_msgSend)(app, sel_getUid("activateIgnoringOtherApps:"), (BOOL)1);
|
||||
|
||||
((void (*)(id, SEL))objc_msgSend)(pool, sel_getUid("release"));
|
||||
}
|
||||
|
||||
static void SetMacAppIcon()
|
||||
{
|
||||
id pool = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSAutoreleasePool"), sel_getUid("alloc"));
|
||||
pool = ((id (*)(id, SEL))objc_msgSend)(pool, sel_getUid("init"));
|
||||
|
||||
id data = ((id (*)(Class, SEL, const void*, NSUInteger))objc_msgSend)((Class)objc_getClass("NSData"), sel_getUid("dataWithBytes:length:"), (const void*)Icon_data, (NSUInteger)Icon_size);
|
||||
id image = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSImage"), sel_getUid("alloc"));
|
||||
image = ((id (*)(id, SEL, id))objc_msgSend)(image, sel_getUid("initWithData:"), data);
|
||||
if( image )
|
||||
{
|
||||
id app = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSApplication"), sel_getUid("sharedApplication"));
|
||||
((void (*)(id, SEL, id))objc_msgSend)(app, sel_getUid("setApplicationIconImage:"), image);
|
||||
((void (*)(id, SEL))objc_msgSend)(image, sel_getUid("release"));
|
||||
}
|
||||
|
||||
((void (*)(id, SEL))objc_msgSend)(pool, sel_getUid("release"));
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void glfw_error_callback( int error, const char* description )
|
||||
@ -83,6 +129,9 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
|
||||
# if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4 )
|
||||
glfwWindowHint( GLFW_WIN32_KEYBOARD_MENU, 1 );
|
||||
# endif
|
||||
# if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 )
|
||||
glfwWindowHint( GLFW_SCALE_TO_MONITOR, 1 );
|
||||
# endif
|
||||
#endif
|
||||
s_window = glfwCreateWindow( m_winPos.w, m_winPos.h, title, NULL, NULL );
|
||||
if( !s_window ) exit( 1 );
|
||||
@ -97,13 +146,10 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
|
||||
glfwSetWindowRefreshCallback( s_window, []( GLFWwindow* ) { tracy::s_wasActive = true; s_redraw(); } );
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL( s_window, true );
|
||||
#ifdef __EMSCRIPTEN__
|
||||
ImGui_ImplOpenGL3_Init( "#version 100" );
|
||||
#else
|
||||
ImGui_ImplOpenGL3_Init( "#version 150" );
|
||||
#endif
|
||||
|
||||
s_redraw = redraw;
|
||||
s_scaleChanged = scaleChanged;
|
||||
s_mainThreadTasks = mainThreadTasks;
|
||||
s_winPos = &m_winPos;
|
||||
s_iconified = false;
|
||||
@ -114,6 +160,10 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
|
||||
glfwSetWindowMaximizeCallback( s_window, glfw_window_maximize_callback );
|
||||
#endif
|
||||
glfwSetWindowIconifyCallback( s_window, glfw_window_iconify_callback );
|
||||
|
||||
#ifdef __APPLE__
|
||||
EnsureMacAppRegistration();
|
||||
#endif
|
||||
}
|
||||
|
||||
Backend::~Backend()
|
||||
@ -133,13 +183,6 @@ void Backend::Show()
|
||||
|
||||
void Backend::Run()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop( []() {
|
||||
glfwPollEvents();
|
||||
s_redraw();
|
||||
s_mainThreadTasks->Run();
|
||||
}, 0, 1 );
|
||||
#else
|
||||
while( !glfwWindowShouldClose( s_window ) )
|
||||
{
|
||||
if( s_iconified )
|
||||
@ -150,11 +193,10 @@ void Backend::Run()
|
||||
{
|
||||
glfwPollEvents();
|
||||
s_redraw();
|
||||
if( s_config.focusLostLimit && !glfwGetWindowAttrib( s_window, GLFW_FOCUSED ) ) std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
|
||||
if( tracy::s_config.focusLostLimit && !glfwGetWindowAttrib( s_window, GLFW_FOCUSED ) ) std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
|
||||
s_mainThreadTasks->Run();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::Attention()
|
||||
@ -169,7 +211,18 @@ void Backend::Attention()
|
||||
|
||||
void Backend::NewFrame( int& w, int& h )
|
||||
{
|
||||
const auto scale = GetDpiScale();
|
||||
if( scale != s_prevScale )
|
||||
{
|
||||
s_prevScale = scale;
|
||||
s_scaleChanged( scale );
|
||||
}
|
||||
|
||||
glfwGetFramebufferSize( s_window, &w, &h );
|
||||
#if defined( __APPLE__ )
|
||||
w = static_cast<int>( w / scale );
|
||||
h = static_cast<int>( h / scale );
|
||||
#endif
|
||||
m_w = w;
|
||||
m_h = h;
|
||||
|
||||
@ -192,11 +245,16 @@ void Backend::EndFrame()
|
||||
|
||||
void Backend::SetIcon( uint8_t* data, int w, int h )
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
EnsureMacAppRegistration();
|
||||
SetMacAppIcon();
|
||||
#else
|
||||
GLFWimage icon;
|
||||
icon.width = w;
|
||||
icon.height = h;
|
||||
icon.pixels = data;
|
||||
glfwSetWindowIcon( s_window, 1, &icon );
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::SetTitle( const char* title )
|
||||
@ -206,25 +264,11 @@ void Backend::SetTitle( const char* title )
|
||||
|
||||
float Backend::GetDpiScale()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
return EM_ASM_DOUBLE( { return window.devicePixelRatio; } );
|
||||
#elif GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 )
|
||||
auto monitor = glfwGetWindowMonitor( s_window );
|
||||
if( !monitor ) monitor = glfwGetPrimaryMonitor();
|
||||
if( monitor )
|
||||
{
|
||||
float x, y;
|
||||
glfwGetMonitorContentScale( monitor, &x, &y );
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
#if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 )
|
||||
float x, y;
|
||||
glfwGetWindowContentScale( s_window, &x, &y );
|
||||
return x;
|
||||
#else
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
extern "C" int nativeResize( int width, int height )
|
||||
{
|
||||
glfwSetWindowSize( s_window, width, height );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "imgui/imgui_impl_opengl3.h"
|
||||
#include "imgui/imgui_impl_opengl3_loader.h"
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <backends/imgui_impl_opengl3_loader.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <linux/input-event-codes.h>
|
||||
#include <memory>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
@ -25,8 +25,10 @@
|
||||
#include "wayland-fractional-scale-client-protocol.h"
|
||||
#include "wayland-viewporter-client-protocol.h"
|
||||
#include "wayland-cursor-shape-client-protocol.h"
|
||||
#include "wayland-xdg-toplevel-icon-client-protocol.h"
|
||||
|
||||
#include "profiler/TracyImGui.hpp"
|
||||
#include "stb_image_resize.h"
|
||||
|
||||
#include "Backend.hpp"
|
||||
#include "RunQueue.hpp"
|
||||
@ -205,6 +207,18 @@ static xkb_mod_index_t s_xkbCtrl, s_xkbAlt, s_xkbShift, s_xkbSuper;
|
||||
static wp_cursor_shape_device_v1_shape s_mouseCursor;
|
||||
static uint32_t s_mouseCursorSerial;
|
||||
static bool s_hasFocus = false;
|
||||
static struct wl_data_device_manager* s_dataDevMgr;
|
||||
static struct wl_data_device* s_dataDev;
|
||||
static struct wl_data_source* s_dataSource;
|
||||
static uint32_t s_dataSerial;
|
||||
static std::string s_clipboard, s_clipboardIncoming;
|
||||
static struct wl_data_offer* s_dataOffer;
|
||||
static struct wl_data_offer* s_newDataOffer;
|
||||
static bool s_newDataOfferValid;
|
||||
static struct xdg_toplevel_icon_manager_v1* s_iconMgr;
|
||||
static std::vector<int> s_iconSizes;
|
||||
static int s_keyRepeatRate = 0;
|
||||
static int s_keyRepeatDelay = 0;
|
||||
|
||||
struct Output
|
||||
{
|
||||
@ -214,7 +228,7 @@ struct Output
|
||||
};
|
||||
static std::unordered_map<uint32_t, std::unique_ptr<Output>> s_output;
|
||||
static int s_maxScale = 120;
|
||||
static int s_prevScale = 120;
|
||||
static int s_prevScale = -1;
|
||||
|
||||
static bool s_running = true;
|
||||
static int s_width, s_height;
|
||||
@ -225,7 +239,15 @@ static uint64_t s_time;
|
||||
static wl_fixed_t s_wheelAxisX, s_wheelAxisY;
|
||||
static bool s_wheel;
|
||||
|
||||
extern tracy::Config s_config;
|
||||
struct KeyRepeat
|
||||
{
|
||||
bool active;
|
||||
bool first;
|
||||
ImGuiKey key;
|
||||
char txt[8];
|
||||
uint64_t time;
|
||||
};
|
||||
static KeyRepeat s_keyRepeat;
|
||||
|
||||
|
||||
static void RecomputeScale()
|
||||
@ -233,7 +255,7 @@ static void RecomputeScale()
|
||||
if( s_fracSurf ) return;
|
||||
|
||||
// On wl_compositor >= 6 the scale is sent explicitly via wl_surface.preferred_buffer_scale.
|
||||
if ( s_comp_version >= 6 ) return;
|
||||
if( s_comp_version >= 6 ) return;
|
||||
|
||||
int max = 1;
|
||||
for( auto& out : s_output )
|
||||
@ -391,6 +413,12 @@ static void KeyboardEnter( void*, struct wl_keyboard* kbd, uint32_t serial, stru
|
||||
|
||||
static void KeyboardLeave( void*, struct wl_keyboard* kbd, uint32_t serial, struct wl_surface* surf )
|
||||
{
|
||||
if( s_dataOffer )
|
||||
{
|
||||
wl_data_offer_destroy( s_dataOffer );
|
||||
s_dataOffer = nullptr;
|
||||
}
|
||||
|
||||
ImGui::GetIO().AddFocusEvent( false );
|
||||
s_hasFocus = false;
|
||||
}
|
||||
@ -418,6 +446,12 @@ static void KeyboardKey( void*, struct wl_keyboard* kbd, uint32_t serial, uint32
|
||||
if( key < ( sizeof( s_keyTable ) / sizeof( *s_keyTable ) ) )
|
||||
{
|
||||
io.AddKeyEvent( s_keyTable[key], state == WL_KEYBOARD_KEY_STATE_PRESSED );
|
||||
|
||||
*s_keyRepeat.txt = 0;
|
||||
s_keyRepeat.key = s_keyTable[key];
|
||||
s_keyRepeat.active = true;
|
||||
s_keyRepeat.first = true;
|
||||
s_keyRepeat.time = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
}
|
||||
|
||||
if( state == WL_KEYBOARD_KEY_STATE_PRESSED )
|
||||
@ -430,8 +464,18 @@ static void KeyboardKey( void*, struct wl_keyboard* kbd, uint32_t serial, uint32
|
||||
if( xkb_keysym_to_utf8( sym, txt, sizeof( txt ) ) > 0 )
|
||||
{
|
||||
ImGui::GetIO().AddInputCharactersUTF8( txt );
|
||||
|
||||
memcpy( s_keyRepeat.txt, txt, sizeof( s_keyRepeat.txt ) );
|
||||
s_keyRepeat.active = true;
|
||||
s_keyRepeat.first = true;
|
||||
s_keyRepeat.time = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
}
|
||||
}
|
||||
s_dataSerial = serial;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_keyRepeat.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -449,6 +493,8 @@ static void KeyboardModifiers( void*, struct wl_keyboard* kbd, uint32_t serial,
|
||||
|
||||
static void KeyboardRepeatInfo( void*, struct wl_keyboard* kbd, int32_t rate, int32_t delay )
|
||||
{
|
||||
s_keyRepeatRate = 1000000 / rate;
|
||||
s_keyRepeatDelay = delay * 1000;
|
||||
}
|
||||
|
||||
constexpr struct wl_keyboard_listener keyboardListener = {
|
||||
@ -551,6 +597,21 @@ constexpr struct zxdg_toplevel_decoration_v1_listener decorationListener = {
|
||||
};
|
||||
|
||||
|
||||
static void IconMgrSize( void*, struct xdg_toplevel_icon_manager_v1*, int32_t size )
|
||||
{
|
||||
s_iconSizes.push_back( size );
|
||||
}
|
||||
|
||||
static void IconMgrDone( void*, struct xdg_toplevel_icon_manager_v1* )
|
||||
{
|
||||
}
|
||||
|
||||
constexpr struct xdg_toplevel_icon_manager_v1_listener iconMgrListener = {
|
||||
.icon_size = IconMgrSize,
|
||||
.done = IconMgrDone
|
||||
};
|
||||
|
||||
|
||||
static void RegistryGlobal( void*, struct wl_registry* reg, uint32_t name, const char* interface, uint32_t version )
|
||||
{
|
||||
if( strcmp( interface, wl_compositor_interface.name ) == 0 )
|
||||
@ -600,6 +661,15 @@ static void RegistryGlobal( void*, struct wl_registry* reg, uint32_t name, const
|
||||
s_cursorShape = (wp_cursor_shape_manager_v1*)wl_registry_bind( reg, name, &wp_cursor_shape_manager_v1_interface, 1 );
|
||||
if( s_pointer ) s_cursorShapeDev = wp_cursor_shape_manager_v1_get_pointer( s_cursorShape, s_pointer );
|
||||
}
|
||||
else if( strcmp( interface, wl_data_device_manager_interface.name ) == 0 )
|
||||
{
|
||||
s_dataDevMgr = (wl_data_device_manager*)wl_registry_bind( reg, name, &wl_data_device_manager_interface, 2 );
|
||||
}
|
||||
else if( strcmp( interface, xdg_toplevel_icon_manager_v1_interface.name ) == 0 )
|
||||
{
|
||||
s_iconMgr = (xdg_toplevel_icon_manager_v1*)wl_registry_bind( reg, name, &xdg_toplevel_icon_manager_v1_interface, 1 );
|
||||
xdg_toplevel_icon_manager_v1_add_listener( s_iconMgr, &iconMgrListener, nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
static void RegistryGlobalRemove( void*, struct wl_registry* reg, uint32_t name )
|
||||
@ -617,10 +687,13 @@ constexpr struct wl_registry_listener registryListener = {
|
||||
};
|
||||
|
||||
|
||||
static bool s_configureAcked = false;
|
||||
|
||||
static void XdgSurfaceConfigure( void*, struct xdg_surface* surf, uint32_t serial )
|
||||
{
|
||||
tracy::s_wasActive = true;
|
||||
xdg_surface_ack_configure( surf, serial );
|
||||
s_configureAcked = true;
|
||||
}
|
||||
|
||||
constexpr struct xdg_surface_listener xdgSurfaceListener = {
|
||||
@ -698,8 +771,10 @@ static void SurfacePreferredBufferTransform( void*, struct wl_surface* surface,
|
||||
constexpr struct wl_surface_listener surfaceListener = {
|
||||
.enter = SurfaceEnter,
|
||||
.leave = SurfaceLeave,
|
||||
#ifdef WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION
|
||||
.preferred_buffer_scale = SurfacePreferredBufferScale,
|
||||
.preferred_buffer_transform = SurfacePreferredBufferTransform
|
||||
#endif
|
||||
};
|
||||
|
||||
static void FractionalPreferredScale( void*, struct wp_fractional_scale_v1* frac, uint32_t scale )
|
||||
@ -713,6 +788,126 @@ constexpr struct wp_fractional_scale_v1_listener fractionalListener = {
|
||||
};
|
||||
|
||||
|
||||
static void DataOfferOffer( void*, struct wl_data_offer* offer, const char* mimeType )
|
||||
{
|
||||
assert( s_newDataOffer == offer );
|
||||
|
||||
if( strcmp( mimeType, "text/plain" ) == 0 )
|
||||
{
|
||||
wl_data_offer_accept( offer, 0, mimeType );
|
||||
s_newDataOfferValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
wl_data_offer_accept( offer, 0, nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
static void DataOfferSourceActions( void*, struct wl_data_offer* offer, uint32_t sourceActions )
|
||||
{
|
||||
}
|
||||
|
||||
static void DataOfferAction( void*, struct wl_data_offer* offer, uint32_t dndAction )
|
||||
{
|
||||
}
|
||||
|
||||
constexpr struct wl_data_offer_listener dataOfferListener = {
|
||||
.offer = DataOfferOffer,
|
||||
.source_actions = DataOfferSourceActions,
|
||||
.action = DataOfferAction
|
||||
};
|
||||
|
||||
|
||||
static void DataDeviceDataOffer( void*, struct wl_data_device* dataDevice, struct wl_data_offer* offer )
|
||||
{
|
||||
s_newDataOffer = offer;
|
||||
wl_data_offer_add_listener( offer, &dataOfferListener, nullptr );
|
||||
s_newDataOfferValid = false;
|
||||
}
|
||||
|
||||
static void DataDeviceEnter( void*, struct wl_data_device* dataDevice, uint32_t serial, struct wl_surface* surface, wl_fixed_t x, wl_fixed_t y, struct wl_data_offer* offer )
|
||||
{
|
||||
if( s_newDataOffer )
|
||||
{
|
||||
wl_data_offer_destroy( s_newDataOffer );
|
||||
s_newDataOffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void DataDeviceLeave( void*, struct wl_data_device* dataDevice )
|
||||
{
|
||||
}
|
||||
|
||||
static void DataDeviceMotion( void*, struct wl_data_device* dataDevice, uint32_t time, wl_fixed_t x, wl_fixed_t y )
|
||||
{
|
||||
}
|
||||
|
||||
static void DataDeviceSelection( void*, struct wl_data_device* dataDevice, struct wl_data_offer* offer )
|
||||
{
|
||||
if( s_dataOffer ) wl_data_offer_destroy( s_dataOffer );
|
||||
if( offer )
|
||||
{
|
||||
if( s_newDataOfferValid )
|
||||
{
|
||||
s_dataOffer = s_newDataOffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( s_newDataOffer ) wl_data_offer_destroy( s_newDataOffer );
|
||||
s_dataOffer = nullptr;
|
||||
}
|
||||
s_newDataOffer = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_dataOffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr struct wl_data_device_listener dataDeviceListener = {
|
||||
.data_offer = DataDeviceDataOffer,
|
||||
.enter = DataDeviceEnter,
|
||||
.leave = DataDeviceLeave,
|
||||
.motion = DataDeviceMotion,
|
||||
.selection = DataDeviceSelection
|
||||
};
|
||||
|
||||
|
||||
void DataSourceTarget( void*, struct wl_data_source* dataSource, const char* mimeType )
|
||||
{
|
||||
}
|
||||
|
||||
void DataSourceSend( void*, struct wl_data_source* dataSource, const char* mimeType, int32_t fd )
|
||||
{
|
||||
if( !s_clipboard.empty() )
|
||||
{
|
||||
auto len = s_clipboard.size();
|
||||
auto ptr = s_clipboard.data();
|
||||
while( len > 0 )
|
||||
{
|
||||
auto sz = write( fd, ptr, len );
|
||||
if( sz < 0 ) break;
|
||||
len -= sz;
|
||||
ptr += sz;
|
||||
}
|
||||
}
|
||||
close( fd );
|
||||
}
|
||||
|
||||
void DataSourceCancelled( void*, struct wl_data_source* dataSource )
|
||||
{
|
||||
s_clipboard.clear();
|
||||
wl_data_source_destroy( s_dataSource );
|
||||
s_dataSource = nullptr;
|
||||
}
|
||||
|
||||
constexpr struct wl_data_source_listener dataSourceListener = {
|
||||
.target = DataSourceTarget,
|
||||
.send = DataSourceSend,
|
||||
.cancelled = DataSourceCancelled
|
||||
};
|
||||
|
||||
|
||||
static void SetupCursor()
|
||||
{
|
||||
if( s_cursorShape ) return;
|
||||
@ -736,6 +931,39 @@ static void SetupCursor()
|
||||
s_cursorY = cursor->images[0]->hotspot_y * 120 / s_maxScale;
|
||||
}
|
||||
|
||||
static void SetClipboard( ImGuiContext*, const char* text )
|
||||
{
|
||||
s_clipboard = text;
|
||||
|
||||
if( s_dataSource ) wl_data_source_destroy( s_dataSource );
|
||||
s_dataSource = wl_data_device_manager_create_data_source( s_dataDevMgr );
|
||||
wl_data_source_add_listener( s_dataSource, &dataSourceListener, nullptr );
|
||||
wl_data_source_offer( s_dataSource, "text/plain" );
|
||||
wl_data_device_set_selection( s_dataDev, s_dataSource, s_dataSerial );
|
||||
}
|
||||
|
||||
static const char* GetClipboard( ImGuiContext* )
|
||||
{
|
||||
if( !s_dataOffer ) return nullptr;
|
||||
int fd[2];
|
||||
if( pipe( fd ) != 0 ) return nullptr;
|
||||
wl_data_offer_receive( s_dataOffer, "text/plain", fd[1] );
|
||||
close( fd[1] );
|
||||
wl_display_roundtrip( s_dpy );
|
||||
|
||||
s_clipboardIncoming.clear();
|
||||
char buf[4096];
|
||||
while( true )
|
||||
{
|
||||
auto len = read( fd[0], buf, sizeof( buf ) );
|
||||
if( len <= 0 ) break;
|
||||
s_clipboardIncoming.append( buf, len );
|
||||
}
|
||||
|
||||
close( fd[0] );
|
||||
return s_clipboardIncoming.c_str();
|
||||
}
|
||||
|
||||
Backend::Backend( const char* title, const std::function<void()>& redraw, const std::function<void(float)>& scaleChanged, const std::function<int(void)>& isBusy, RunQueue* mainThreadTasks )
|
||||
{
|
||||
s_redraw = redraw;
|
||||
@ -761,7 +989,6 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
|
||||
|
||||
s_surf = wl_compositor_create_surface( s_comp );
|
||||
wl_surface_add_listener( s_surf, &surfaceListener, nullptr );
|
||||
s_eglWin = wl_egl_window_create( s_surf, m_winPos.w, m_winPos.h );
|
||||
s_xdgSurf = xdg_wm_base_get_xdg_surface( s_wm, s_surf );
|
||||
xdg_surface_add_listener( s_xdgSurf, &xdgSurfaceListener, nullptr );
|
||||
|
||||
@ -796,6 +1023,15 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
|
||||
res = eglBindAPI( EGL_OPENGL_API );
|
||||
if( res != EGL_TRUE ) { fprintf( stderr, "Cannot use OpenGL through EGL!\n" ); exit( 1 ); }
|
||||
|
||||
wl_display_roundtrip( s_dpy );
|
||||
s_toplevel = xdg_surface_get_toplevel( s_xdgSurf );
|
||||
xdg_toplevel_add_listener( s_toplevel, &toplevelListener, nullptr );
|
||||
xdg_toplevel_set_title( s_toplevel, title );
|
||||
xdg_toplevel_set_app_id( s_toplevel, "tracy" );
|
||||
wl_surface_commit( s_surf );
|
||||
while( !s_configureAcked ) wl_display_roundtrip( s_dpy );
|
||||
|
||||
s_eglWin = wl_egl_window_create( s_surf, int( round( s_width * s_maxScale / 120.f ) ), int( round( s_height * s_maxScale / 120.f ) ) );
|
||||
s_eglSurf = eglCreatePlatformWindowSurface( s_eglDpy, eglConfig, s_eglWin, nullptr );
|
||||
|
||||
constexpr EGLint eglCtxAttrib[] = {
|
||||
@ -812,11 +1048,15 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
|
||||
|
||||
ImGui_ImplOpenGL3_Init( "#version 150" );
|
||||
|
||||
wl_display_roundtrip( s_dpy );
|
||||
s_toplevel = xdg_surface_get_toplevel( s_xdgSurf );
|
||||
xdg_toplevel_add_listener( s_toplevel, &toplevelListener, nullptr );
|
||||
xdg_toplevel_set_title( s_toplevel, title );
|
||||
xdg_toplevel_set_app_id( s_toplevel, "tracy" );
|
||||
if( s_activation )
|
||||
{
|
||||
const char* token = getenv( "XDG_ACTIVATION_TOKEN" );
|
||||
if( token )
|
||||
{
|
||||
xdg_activation_v1_activate( s_activation, token, s_surf );
|
||||
unsetenv( "XDG_ACTIVATION_TOKEN" );
|
||||
}
|
||||
}
|
||||
|
||||
if( s_decoration )
|
||||
{
|
||||
@ -828,6 +1068,17 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.BackendPlatformName = "wayland (tracy profiler)";
|
||||
|
||||
if( s_dataDevMgr )
|
||||
{
|
||||
s_dataDev = wl_data_device_manager_get_data_device( s_dataDevMgr, s_seat );
|
||||
wl_data_device_add_listener( s_dataDev, &dataDeviceListener, nullptr );
|
||||
|
||||
auto& platform = ImGui::GetPlatformIO();
|
||||
platform.Platform_SetClipboardTextFn = SetClipboard;
|
||||
platform.Platform_GetClipboardTextFn = GetClipboard;
|
||||
}
|
||||
|
||||
s_time = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
}
|
||||
|
||||
@ -835,6 +1086,11 @@ Backend::~Backend()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
|
||||
if( s_iconMgr ) xdg_toplevel_icon_manager_v1_destroy( s_iconMgr );
|
||||
if( s_dataOffer ) wl_data_offer_destroy( s_dataOffer );
|
||||
if( s_dataSource ) wl_data_source_destroy( s_dataSource );
|
||||
if( s_dataDev ) wl_data_device_destroy( s_dataDev );
|
||||
if( s_dataDevMgr ) wl_data_device_manager_destroy( s_dataDevMgr );
|
||||
if( s_cursorShapeDev ) wp_cursor_shape_device_v1_destroy( s_cursorShapeDev );
|
||||
if( s_cursorShape ) wp_cursor_shape_manager_v1_destroy( s_cursorShape );
|
||||
if( s_viewport ) wp_viewport_destroy( s_viewport );
|
||||
@ -878,9 +1134,10 @@ void Backend::Show()
|
||||
|
||||
void Backend::Run()
|
||||
{
|
||||
while( s_running && wl_display_dispatch( s_dpy ) != -1 )
|
||||
timespec zero = {};
|
||||
while( s_running && wl_display_dispatch_timeout( s_dpy, &zero ) != -1 )
|
||||
{
|
||||
if( s_config.focusLostLimit && !s_hasFocus ) std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
|
||||
if( tracy::s_config.focusLostLimit && !s_hasFocus ) std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
|
||||
s_redraw();
|
||||
s_mainThreadTasks->Run();
|
||||
}
|
||||
@ -915,12 +1172,8 @@ void Backend::NewFrame( int& w, int& h )
|
||||
{
|
||||
s_prevWidth = s_width;
|
||||
s_prevHeight = s_height;
|
||||
wl_egl_window_resize( s_eglWin, s_width * s_maxScale / 120, s_height * s_maxScale / 120, 0, 0 );
|
||||
if( s_fracSurf )
|
||||
{
|
||||
wp_viewport_set_source( s_viewport, 0, 0, wl_fixed_from_double( s_width * s_maxScale / 120. ), wl_fixed_from_double( s_height * s_maxScale / 120. ) );
|
||||
wp_viewport_set_destination( s_viewport, s_width, s_height );
|
||||
}
|
||||
wl_egl_window_resize( s_eglWin, int( round( s_width * s_maxScale / 120.f ) ), int( round( s_height * s_maxScale / 120.f ) ), 0, 0 );
|
||||
if( s_fracSurf ) wp_viewport_set_destination( s_viewport, s_width, s_height );
|
||||
}
|
||||
|
||||
if( s_prevScale != s_maxScale )
|
||||
@ -938,8 +1191,8 @@ void Backend::NewFrame( int& w, int& h )
|
||||
m_winPos.h = s_height;
|
||||
}
|
||||
|
||||
w = s_width * s_maxScale / 120;
|
||||
h = s_height * s_maxScale / 120;
|
||||
w = int( round ( s_width * s_maxScale / 120.f ) );
|
||||
h = int( round ( s_height * s_maxScale / 120.f ) );
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DisplaySize = ImVec2( w, h );
|
||||
@ -951,6 +1204,26 @@ void Backend::NewFrame( int& w, int& h )
|
||||
io.DeltaTime = std::min( 0.1f, ( time - s_time ) / 1000000.f );
|
||||
s_time = time;
|
||||
|
||||
if( s_keyRepeat.active )
|
||||
{
|
||||
tracy::s_wasActive = true;
|
||||
const auto delta = s_time - s_keyRepeat.time;
|
||||
if( ( s_keyRepeat.first && delta >= s_keyRepeatDelay ) ||
|
||||
( !s_keyRepeat.first && delta >= s_keyRepeatRate ) )
|
||||
{
|
||||
s_keyRepeat.first = false;
|
||||
s_keyRepeat.time = s_time;
|
||||
if( *s_keyRepeat.txt )
|
||||
{
|
||||
ImGui::GetIO().AddInputCharactersUTF8( s_keyRepeat.txt );
|
||||
}
|
||||
else
|
||||
{
|
||||
io.AddKeyEvent( s_keyRepeat.key, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( s_cursorShapeDev )
|
||||
{
|
||||
ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
|
||||
@ -994,7 +1267,11 @@ void Backend::NewFrame( int& w, int& h )
|
||||
case ImGuiMouseCursor_NotAllowed:
|
||||
shape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NOT_ALLOWED;
|
||||
break;
|
||||
case ImGuiMouseCursor_Hand:
|
||||
shape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER;
|
||||
break;
|
||||
default:
|
||||
shape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT;
|
||||
break;
|
||||
};
|
||||
|
||||
@ -1018,7 +1295,7 @@ void Backend::EndFrame()
|
||||
const ImVec4 clear_color = ImColor( 20, 20, 17 );
|
||||
|
||||
ImGui::Render();
|
||||
glViewport( 0, 0, s_width * s_maxScale / 120, s_height * s_maxScale / 120 );
|
||||
glViewport( 0, 0, GLsizei( round( s_width * s_maxScale / 120.f ) ), GLsizei( round ( s_height * s_maxScale / 120.f ) ) );
|
||||
glClearColor( clear_color.x, clear_color.y, clear_color.z, clear_color.w );
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
ImGui_ImplOpenGL3_RenderDrawData( ImGui::GetDrawData() );
|
||||
@ -1028,6 +1305,62 @@ void Backend::EndFrame()
|
||||
|
||||
void Backend::SetIcon( uint8_t* data, int w, int h )
|
||||
{
|
||||
if( !s_iconMgr ) return;
|
||||
if( s_iconSizes.empty() ) return;
|
||||
|
||||
size_t size = 0;
|
||||
for( auto sz : s_iconSizes )
|
||||
{
|
||||
size += sz * sz;
|
||||
}
|
||||
size *= 4;
|
||||
|
||||
auto path = getenv( "XDG_RUNTIME_DIR" );
|
||||
if( !path ) return;
|
||||
|
||||
std::string shmPath = path;
|
||||
shmPath += "/tracy_icon-XXXXXX";
|
||||
int fd = mkstemp( shmPath.data() );
|
||||
if( fd < 0 ) return;
|
||||
unlink( shmPath.data() );
|
||||
ftruncate( fd, size );
|
||||
auto membuf = (char*)mmap( nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
|
||||
if( membuf == MAP_FAILED )
|
||||
{
|
||||
close( fd );
|
||||
return;
|
||||
}
|
||||
|
||||
auto pool = wl_shm_create_pool( s_shm, fd, size );
|
||||
close( fd );
|
||||
auto icon = xdg_toplevel_icon_manager_v1_create_icon( s_iconMgr );
|
||||
|
||||
auto rgb = new uint32_t[w * h];
|
||||
auto bgr = (uint32_t*)data;
|
||||
for( int i=0; i<w*h; i++ )
|
||||
{
|
||||
rgb[i] = ( bgr[i] & 0xff00ff00 ) | ( ( bgr[i] & 0xff ) << 16 ) | ( ( bgr[i] >> 16 ) & 0xff );
|
||||
}
|
||||
|
||||
std::vector<wl_buffer*> bufs;
|
||||
int32_t offset = 0;
|
||||
for( auto sz : s_iconSizes )
|
||||
{
|
||||
auto buffer = wl_shm_pool_create_buffer( pool, offset, sz, sz, sz * 4, WL_SHM_FORMAT_ARGB8888 );
|
||||
bufs.push_back( buffer );
|
||||
|
||||
auto ptr = membuf + offset;
|
||||
offset += sz * sz * 4;
|
||||
|
||||
stbir_resize_uint8( (uint8_t*)rgb, w, h, 0, (uint8_t*)ptr, sz, sz, 0, 4 );
|
||||
xdg_toplevel_icon_v1_add_buffer( icon, buffer, sz );
|
||||
}
|
||||
|
||||
xdg_toplevel_icon_manager_v1_set_icon( s_iconMgr, s_toplevel, icon );
|
||||
xdg_toplevel_icon_v1_destroy( icon );
|
||||
for( auto buf : bufs ) wl_buffer_destroy( buf );
|
||||
munmap( membuf, size );
|
||||
wl_shm_pool_destroy( pool );
|
||||
}
|
||||
|
||||
void Backend::SetTitle( const char* title )
|
||||
|
||||
@ -65,17 +65,16 @@ void ConnectionHistory::Rebuild()
|
||||
std::swap( m_connHistVec, vec );
|
||||
}
|
||||
|
||||
void ConnectionHistory::Count( const char* name )
|
||||
void ConnectionHistory::Count( const std::string& name )
|
||||
{
|
||||
std::string addr( name );
|
||||
auto it = m_connHistMap.find( addr );
|
||||
auto it = m_connHistMap.find( name );
|
||||
if( it != m_connHistMap.end() )
|
||||
{
|
||||
it->second++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_connHistMap.emplace( std::move( addr ), 1 );
|
||||
m_connHistMap.emplace( name, 1 );
|
||||
}
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ public:
|
||||
|
||||
const std::string& Name( size_t idx ) const { return m_connHistVec[idx]->first; }
|
||||
|
||||
void Count( const char* name );
|
||||
void Count( const std::string& name );
|
||||
void Erase( size_t idx );
|
||||
|
||||
bool empty() const { return m_connHistVec.empty(); }
|
||||
|
||||
@ -1,59 +1,64 @@
|
||||
#include <imgui.h>
|
||||
#include <math.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <misc/freetype/imgui_freetype.h>
|
||||
|
||||
#include "Fonts.hpp"
|
||||
#include "misc/freetype/imgui_freetype.h"
|
||||
#include "imgui/imgui_impl_opengl3.h"
|
||||
#include "profiler/IconsFontAwesome6.h"
|
||||
#include "profiler/TracyEmbed.hpp"
|
||||
|
||||
#include "font/DroidSans.hpp"
|
||||
#include "font/FiraCodeRetina.hpp"
|
||||
#include "font/FontAwesomeSolid.hpp"
|
||||
#include "data/FontFixed.hpp"
|
||||
#include "data/FontIcons.hpp"
|
||||
#include "data/FontNormal.hpp"
|
||||
#include "data/FontBold.hpp"
|
||||
#include "data/FontBoldItalic.hpp"
|
||||
#include "data/FontItalic.hpp"
|
||||
|
||||
ImFont* s_bigFont;
|
||||
ImFont* s_smallFont;
|
||||
ImFont* s_fixedWidth;
|
||||
FontData g_fonts;
|
||||
|
||||
float FontNormal, FontSmall, FontBig;
|
||||
|
||||
void LoadFonts( float scale )
|
||||
{
|
||||
static const ImWchar rangesBasic[] = {
|
||||
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
||||
0x03BC, 0x03BC, // micro
|
||||
0x03C3, 0x03C3, // small sigma
|
||||
0x2013, 0x2013, // en dash
|
||||
0x2026, 0x2026, // ellipsis
|
||||
0x2264, 0x2264, // less-than or equal to
|
||||
0,
|
||||
};
|
||||
static const ImWchar rangesIcons[] = {
|
||||
ICON_MIN_FA, ICON_MAX_FA,
|
||||
0
|
||||
};
|
||||
static const ImWchar rangesFixed[] = {
|
||||
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
||||
0x2026, 0x2026, // ellipsis
|
||||
0
|
||||
};
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImFontConfig configBasic;
|
||||
configBasic.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting;
|
||||
configBasic.FontLoaderFlags = ImGuiFreeTypeLoaderFlags_LightHinting;
|
||||
configBasic.FontDataOwnedByAtlas = false;
|
||||
ImFontConfig configMerge;
|
||||
configMerge.MergeMode = true;
|
||||
configMerge.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting;
|
||||
configMerge.FontLoaderFlags = ImGuiFreeTypeLoaderFlags_LightHinting;
|
||||
configMerge.FontDataOwnedByAtlas = false;
|
||||
ImFontConfig configFixed;
|
||||
configFixed.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting;
|
||||
configFixed.GlyphExtraSpacing.x = -1;
|
||||
configFixed.FontLoaderFlags = ImGuiFreeTypeLoaderFlags_LightHinting;
|
||||
configFixed.GlyphExtraAdvanceX = -1;
|
||||
configFixed.FontDataOwnedByAtlas = false;
|
||||
|
||||
auto fontFixed = Unembed( FontFixed );
|
||||
auto fontIcons = Unembed( FontIcons );
|
||||
auto fontNormal = Unembed( FontNormal );
|
||||
auto fontBold = Unembed( FontBold );
|
||||
auto fontBoldItalic = Unembed( FontBoldItalic );
|
||||
auto fontItalic = Unembed( FontItalic );
|
||||
|
||||
io.Fonts->Clear();
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 15.0f * scale ), &configBasic, rangesBasic );
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 14.0f * scale ), &configMerge, rangesIcons );
|
||||
s_fixedWidth = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FiraCodeRetina_compressed_data, tracy::FiraCodeRetina_compressed_size, round( 15.0f * scale ), &configFixed, rangesFixed );
|
||||
s_bigFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 21.0f * scale ), &configBasic );
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 20.0f * scale ), &configMerge, rangesIcons );
|
||||
s_smallFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 10.0f * scale ), &configBasic );
|
||||
|
||||
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
g_fonts.normal = io.Fonts->AddFontFromMemoryTTF( (void*)fontNormal->data(), fontNormal->size(), round( 15.0f * scale ), &configBasic );
|
||||
io.Fonts->AddFontFromMemoryTTF( (void*)fontIcons->data(), fontIcons->size(), round( 14.0f * scale ), &configMerge );
|
||||
|
||||
g_fonts.mono = io.Fonts->AddFontFromMemoryTTF( (void*)fontFixed->data(), fontFixed->size(), round( 15.0f * scale ), &configFixed );
|
||||
io.Fonts->AddFontFromMemoryTTF( (void*)fontIcons->data(), fontIcons->size(), round( 14.0f * scale ), &configMerge );
|
||||
|
||||
g_fonts.bold = io.Fonts->AddFontFromMemoryTTF( (void*)fontBold->data(), fontBold->size(), round( 15.0f * scale ), &configBasic );
|
||||
io.Fonts->AddFontFromMemoryTTF( (void*)fontIcons->data(), fontIcons->size(), round( 14.0f * scale ), &configMerge );
|
||||
|
||||
g_fonts.boldItalic = io.Fonts->AddFontFromMemoryTTF( (void*)fontBoldItalic->data(), fontBoldItalic->size(), round( 15.0f * scale ), &configBasic );
|
||||
io.Fonts->AddFontFromMemoryTTF( (void*)fontIcons->data(), fontIcons->size(), round( 14.0f * scale ), &configMerge );
|
||||
|
||||
g_fonts.italic = io.Fonts->AddFontFromMemoryTTF( (void*)fontItalic->data(), fontItalic->size(), round( 15.0f * scale ), &configBasic );
|
||||
io.Fonts->AddFontFromMemoryTTF( (void*)fontIcons->data(), fontIcons->size(), round( 14.0f * scale ), &configMerge );
|
||||
|
||||
FontNormal = round( scale * 15.f );
|
||||
FontSmall = round( scale * 15 * 2.f / 3.f );
|
||||
FontBig = round( scale * 15 * 1.4f );
|
||||
}
|
||||
|
||||
@ -3,9 +3,17 @@
|
||||
|
||||
struct ImFont;
|
||||
|
||||
extern ImFont* s_bigFont;
|
||||
extern ImFont* s_smallFont;
|
||||
extern ImFont* s_fixedWidth;
|
||||
struct FontData
|
||||
{
|
||||
ImFont* normal;
|
||||
ImFont* mono;
|
||||
ImFont* bold;
|
||||
ImFont* boldItalic;
|
||||
ImFont* italic;
|
||||
};
|
||||
|
||||
extern FontData g_fonts;
|
||||
extern float FontNormal, FontSmall, FontBig;
|
||||
|
||||
void LoadFonts( float scale );
|
||||
|
||||
|
||||
@ -5,11 +5,14 @@
|
||||
|
||||
#include "../public/common/TracySocket.hpp"
|
||||
#include "../public/common/TracyVersion.hpp"
|
||||
#include "GitRef.hpp"
|
||||
#include "HttpRequest.hpp"
|
||||
|
||||
#if defined _WIN32
|
||||
# include <windows.h>
|
||||
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
|
||||
extern "C" typedef char* (WINAPI *t_WineGetVersion)();
|
||||
extern "C" typedef char* (WINAPI *t_WineGetBuildId)();
|
||||
#elif defined __linux__
|
||||
# include <sys/utsname.h>
|
||||
#elif defined __APPLE__
|
||||
@ -39,7 +42,16 @@ static const char* GetOsInfo()
|
||||
# ifdef __MINGW32__
|
||||
sprintf( buf, "Windows %i.%i.%i (MingW)", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber );
|
||||
# else
|
||||
sprintf( buf, "Windows %i.%i.%i", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
|
||||
auto WineGetVersion = (t_WineGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "wine_get_version" );
|
||||
auto WineGetBuildId = (t_WineGetBuildId)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "wine_get_build_id" );
|
||||
if( WineGetVersion && WineGetBuildId )
|
||||
{
|
||||
sprintf( buf, "Windows %i.%i.%i (Wine %s [%s])", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, WineGetVersion(), WineGetBuildId() );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( buf, "Windows %i.%i.%i", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
|
||||
}
|
||||
# endif
|
||||
}
|
||||
#elif defined __linux__
|
||||
@ -79,7 +91,7 @@ void HttpRequest( const char* server, const char* resource, int port, const std:
|
||||
tracy::Socket sock;
|
||||
if( !sock.ConnectBlocking( server, port ) ) return;
|
||||
char request[4096];
|
||||
const auto len = sprintf( request, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Tracy Profiler %i.%i.%i (%s)\r\nConnection: close\r\nCache-Control: no-cache, no-store, must-revalidate\r\n\r\n", resource, server, tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch, GetOsInfo() );
|
||||
const auto len = sprintf( request, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Tracy Profiler %i.%i.%i (%s) [%s]\r\nConnection: close\r\nCache-Control: no-cache, no-store, must-revalidate\r\n\r\n", resource, server, tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch, GetOsInfo(), tracy::GitRef );
|
||||
sock.Send( request, len );
|
||||
char response[4096];
|
||||
const auto sz = sock.ReadUpTo( response, 4096 );
|
||||
|
||||
@ -11,6 +11,7 @@ ImGuiTracyContext::ImGuiTracyContext()
|
||||
io.IniFilename = m_iniFilename.c_str();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigInputTextCursorBlink = false;
|
||||
io.ConfigScrollbarScrollByPage = false;
|
||||
}
|
||||
|
||||
ImGuiTracyContext::~ImGuiTracyContext()
|
||||
|
||||
@ -14,22 +14,28 @@
|
||||
ResolvService::ResolvService( uint16_t port )
|
||||
: m_exit( false )
|
||||
, m_port( port )
|
||||
#ifndef __EMSCRIPTEN__
|
||||
, m_thread( [this] { Worker(); } )
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
ResolvService::~ResolvService()
|
||||
{
|
||||
#ifndef __EMSCRIPTEN__
|
||||
m_exit.store( true, std::memory_order_relaxed );
|
||||
m_cv.notify_one();
|
||||
m_thread.join();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ResolvService::Query( uint32_t ip, const std::function<void(std::string&&)>& callback )
|
||||
{
|
||||
#ifndef __EMSCRIPTEN__
|
||||
std::lock_guard<std::mutex> lock( m_lock );
|
||||
m_queue.emplace_back( QueueItem { ip, callback } );
|
||||
m_cv.notify_one();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ResolvService::Worker()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
BIN
libs/tracy/profiler/src/font/FiraCode-Retina.ttf
Normal file
BIN
libs/tracy/profiler/src/font/FiraCode-Retina.ttf
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
libs/tracy/profiler/src/font/Font Awesome 6 Free-Solid-900.otf
Normal file
BIN
libs/tracy/profiler/src/font/Font Awesome 6 Free-Solid-900.otf
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
libs/tracy/profiler/src/font/Roboto-Bold.ttf
Normal file
BIN
libs/tracy/profiler/src/font/Roboto-Bold.ttf
Normal file
Binary file not shown.
BIN
libs/tracy/profiler/src/font/Roboto-BoldItalic.ttf
Normal file
BIN
libs/tracy/profiler/src/font/Roboto-BoldItalic.ttf
Normal file
Binary file not shown.
BIN
libs/tracy/profiler/src/font/Roboto-Italic.ttf
Normal file
BIN
libs/tracy/profiler/src/font/Roboto-Italic.ttf
Normal file
Binary file not shown.
BIN
libs/tracy/profiler/src/font/Roboto-Regular.ttf
Normal file
BIN
libs/tracy/profiler/src/font/Roboto-Regular.ttf
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1,62 +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;
|
||||
|
||||
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
|
||||
#ifdef __EMSCRIPTEN__
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector);
|
||||
#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);
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
@ -1,996 +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
|
||||
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 2024-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||
// 2024-05-07: OpenGL: Update loader for Linux to support EGL/GLVND. (#7562)
|
||||
// 2024-04-16: OpenGL: Detect ES3 contexts on desktop based on version string, to e.g. avoid calling glPolygonMode() on them. (#7447)
|
||||
// 2024-01-09: OpenGL: Update GL3W based imgui_impl_opengl3_loader.h to load "libGL.so" and variants, fixing regression on distros missing a symlink.
|
||||
// 2023-11-08: OpenGL: Update GL3W based imgui_impl_opengl3_loader.h to load "libGL.so" instead of "libGL.so.1", accommodating for NetBSD systems having only "libGL.so.3" available. (#6983)
|
||||
// 2023-10-05: OpenGL: Rename symbols in our internal loader so that LTO compilation with another copy of gl3w is possible. (#6875, #6668, #4445)
|
||||
// 2023-06-20: OpenGL: Fixed erroneous use glGetIntegerv(GL_CONTEXT_PROFILE_MASK) on contexts lower than 3.2. (#6539, #6333)
|
||||
// 2023-05-09: OpenGL: Support for glBindSampler() backup/restore on ES3. (#6375)
|
||||
// 2023-04-18: OpenGL: Restore front and back polygon mode separately when supported by context. (#6333)
|
||||
// 2023-03-23: OpenGL: Properly restoring "no shader program bound" if it was the case prior to running the rendering function. (#6267, #6220, #6224)
|
||||
// 2023-03-15: OpenGL: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530)
|
||||
// 2023-03-06: OpenGL: Fixed restoration of a potentially deleted OpenGL program, by calling glIsProgram(). (#6220, #6224)
|
||||
// 2022-11-09: OpenGL: Reverted use of glBufferSubData(), too many corruptions issues + old issues seemingly can't be reproed with Intel drivers nowadays (revert 2021-12-15 and 2022-05-23 changes).
|
||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
||||
// 2022-09-27: OpenGL: Added ability to '#define IMGUI_IMPL_OPENGL_DEBUG'.
|
||||
// 2022-05-23: OpenGL: Reworking 2021-12-15 "Using buffer orphaning" so it only happens on Intel GPU, seems to cause problems otherwise. (#4468, #4825, #4832, #5127).
|
||||
// 2022-05-13: OpenGL: Fixed state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states.
|
||||
// 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers.
|
||||
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
|
||||
// 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader.
|
||||
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
||||
// 2021-06-25: OpenGL: Use OES_vertex_array extension on Emscripten + backup/restore current state.
|
||||
// 2021-06-21: OpenGL: Destroy individual vertex/fragment shader objects right after they are linked into the main shader.
|
||||
// 2021-05-24: OpenGL: Access GL_CLIP_ORIGIN when "GL_ARB_clip_control" extension is detected, inside of just OpenGL 4.5 version.
|
||||
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
||||
// 2021-04-06: OpenGL: Don't try to read GL_CLIP_ORIGIN unless we're OpenGL 4.5 or greater.
|
||||
// 2021-02-18: OpenGL: Change blending equation to preserve alpha in output buffer.
|
||||
// 2021-01-03: OpenGL: Backup, setup and restore GL_STENCIL_TEST state.
|
||||
// 2020-10-23: OpenGL: Backup, setup and restore GL_PRIMITIVE_RESTART state.
|
||||
// 2020-10-15: OpenGL: Use glGetString(GL_VERSION) instead of glGetIntegerv(GL_MAJOR_VERSION, ...) when the later returns zero (e.g. Desktop GL 2.x)
|
||||
// 2020-09-17: OpenGL: Fix to avoid compiling/calling glBindSampler() on ES or pre 3.3 context which have the defines set by a loader.
|
||||
// 2020-07-10: OpenGL: Added support for glad2 OpenGL loader.
|
||||
// 2020-05-08: OpenGL: Made default GLSL version 150 (instead of 130) on OSX.
|
||||
// 2020-04-21: OpenGL: Fixed handling of glClipControl(GL_UPPER_LEFT) by inverting projection matrix.
|
||||
// 2020-04-12: OpenGL: Fixed context version check mistakenly testing for 4.0+ instead of 3.2+ to enable ImGuiBackendFlags_RendererHasVtxOffset.
|
||||
// 2020-03-24: OpenGL: Added support for glbinding 2.x OpenGL loader.
|
||||
// 2020-01-07: OpenGL: Added support for glbinding 3.x OpenGL loader.
|
||||
// 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders.
|
||||
// 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility.
|
||||
// 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call.
|
||||
// 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
||||
// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
||||
// 2019-03-29: OpenGL: Not calling glBindBuffer more than necessary in the render loop.
|
||||
// 2019-03-15: OpenGL: Added a GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized GL function loaders early.
|
||||
// 2019-03-03: OpenGL: Fix support for ES 2.0 (WebGL 1.0).
|
||||
// 2019-02-20: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN even if defined by the headers/loader.
|
||||
// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
|
||||
// 2019-02-01: OpenGL: Using GLSL 410 shaders for any version over 410 (e.g. 430, 450).
|
||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
||||
// 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT) / GL_CLIP_ORIGIN.
|
||||
// 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used.
|
||||
// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES".
|
||||
// 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation.
|
||||
// 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link.
|
||||
// 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
|
||||
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
||||
// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
|
||||
// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a nullptr pointer.
|
||||
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
|
||||
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
|
||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
|
||||
// 2018-01-07: OpenGL: Changed GLSL shader version from 330 to 150.
|
||||
// 2017-09-01: OpenGL: Save and restore current bound sampler. Save and restore current polygon mode.
|
||||
// 2017-05-01: OpenGL: Fixed save and restore of current blend func state.
|
||||
// 2017-05-01: OpenGL: Fixed save and restore of current GL_ACTIVE_TEXTURE.
|
||||
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
|
||||
// 2016-07-29: OpenGL: Explicitly setting GL_UNPACK_ROW_LENGTH to reduce issues because SDL changes it. (#752)
|
||||
|
||||
//----------------------------------------
|
||||
// OpenGL GLSL GLSL
|
||||
// version version string
|
||||
//----------------------------------------
|
||||
// 2.0 110 "#version 110"
|
||||
// 2.1 120 "#version 120"
|
||||
// 3.0 130 "#version 130"
|
||||
// 3.1 140 "#version 140"
|
||||
// 3.2 150 "#version 150"
|
||||
// 3.3 330 "#version 330 core"
|
||||
// 4.0 400 "#version 400 core"
|
||||
// 4.1 410 "#version 410 core"
|
||||
// 4.2 420 "#version 410 core"
|
||||
// 4.3 430 "#version 430 core"
|
||||
// ES 2.0 100 "#version 100" = WebGL 1.0
|
||||
// ES 3.0 300 "#version 300 es" = WebGL 2.0
|
||||
//----------------------------------------
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "imgui.h"
|
||||
#ifndef IMGUI_DISABLE
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h> // intptr_t
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
// Clang/GCC warnings with -Weverything
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
||||
#pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used
|
||||
#pragma clang diagnostic ignored "-Wnonportable-system-include-path"
|
||||
#pragma clang diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader)
|
||||
#endif
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
|
||||
#pragma GCC diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx'
|
||||
#pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader)
|
||||
#endif
|
||||
|
||||
// GL includes
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
||||
#include <OpenGLES/ES2/gl.h> // Use GL ES 2
|
||||
#else
|
||||
#include <GLES2/gl2.h> // Use GL ES 2
|
||||
#endif
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#ifndef GL_GLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#endif
|
||||
#include <GLES2/gl2ext.h>
|
||||
#endif
|
||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
||||
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
|
||||
#else
|
||||
#include <GLES3/gl3.h> // Use GL ES 3
|
||||
#endif
|
||||
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
|
||||
// Helper libraries are often used for this purpose! Here we are using our own minimal custom loader based on gl3w.
|
||||
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
|
||||
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
|
||||
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
|
||||
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
|
||||
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
|
||||
#define IMGL3W_IMPL
|
||||
#include "imgui_impl_opengl3_loader.h"
|
||||
#endif
|
||||
|
||||
// Vertex arrays are not supported on ES2/WebGL1 unless Emscripten which uses an extension
|
||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
||||
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
#define glBindVertexArray glBindVertexArrayOES
|
||||
#define glGenVertexArrays glGenVertexArraysOES
|
||||
#define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||
#define GL_VERTEX_ARRAY_BINDING GL_VERTEX_ARRAY_BINDING_OES
|
||||
#endif
|
||||
|
||||
// Desktop GL 2.0+ has extension and glPolygonMode() which GL ES and WebGL don't have..
|
||||
// A desktop ES context can technically compile fine with our loader, so we also perform a runtime checks
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
#define IMGUI_IMPL_OPENGL_HAS_EXTENSIONS // has glGetIntegerv(GL_NUM_EXTENSIONS)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE // may have glPolygonMode()
|
||||
#endif
|
||||
|
||||
// Desktop GL 2.1+ and GL ES 3.0+ have glBindBuffer() with GL_PIXEL_UNPACK_BUFFER target.
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_BUFFER_PIXEL_UNPACK
|
||||
#endif
|
||||
|
||||
// Desktop GL 3.1+ has GL_PRIMITIVE_RESTART state
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_1)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
#endif
|
||||
|
||||
// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_2)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||
#endif
|
||||
|
||||
// Desktop GL 3.3+ and GL ES 3.0+ have glBindSampler()
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && (defined(IMGUI_IMPL_OPENGL_ES3) || defined(GL_VERSION_3_3))
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
#endif
|
||||
|
||||
// [Debugging]
|
||||
//#define IMGUI_IMPL_OPENGL_DEBUG
|
||||
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
||||
#include <stdio.h>
|
||||
#define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check
|
||||
#else
|
||||
#define GL_CALL(_CALL) _CALL // Call without error check
|
||||
#endif
|
||||
|
||||
// OpenGL Data
|
||||
struct ImGui_ImplOpenGL3_Data
|
||||
{
|
||||
GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2)
|
||||
char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings.
|
||||
bool GlProfileIsES2;
|
||||
bool GlProfileIsES3;
|
||||
bool GlProfileIsCompat;
|
||||
GLint GlProfileMask;
|
||||
GLuint FontTexture;
|
||||
GLuint ShaderHandle;
|
||||
GLint AttribLocationTex; // Uniforms location
|
||||
GLint AttribLocationProjMtx;
|
||||
GLuint AttribLocationVtxPos; // Vertex attributes location
|
||||
GLuint AttribLocationVtxUV;
|
||||
GLuint AttribLocationVtxColor;
|
||||
unsigned int VboHandle, ElementsHandle;
|
||||
GLsizeiptr VertexBufferSize;
|
||||
GLsizeiptr IndexBufferSize;
|
||||
bool HasPolygonMode;
|
||||
bool HasClipOrigin;
|
||||
bool UseBufferSubData;
|
||||
|
||||
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||
static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData()
|
||||
{
|
||||
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
||||
}
|
||||
|
||||
// Forward Declarations
|
||||
static void ImGui_ImplOpenGL3_InitPlatformInterface();
|
||||
static void ImGui_ImplOpenGL3_ShutdownPlatformInterface();
|
||||
|
||||
// OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only)
|
||||
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
struct ImGui_ImplOpenGL3_VtxAttribState
|
||||
{
|
||||
GLint Enabled, Size, Type, Normalized, Stride;
|
||||
GLvoid* Ptr;
|
||||
|
||||
void GetState(GLint index)
|
||||
{
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride);
|
||||
glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr);
|
||||
}
|
||||
void SetState(GLint index)
|
||||
{
|
||||
glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr);
|
||||
if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// Functions
|
||||
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
IMGUI_CHECKVERSION();
|
||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||
|
||||
// Initialize our loader
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||
if (imgl3wInit() != 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup backend capabilities flags
|
||||
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
|
||||
io.BackendRendererUserData = (void*)bd;
|
||||
io.BackendRendererName = "imgui_impl_opengl3";
|
||||
|
||||
// Query for GL version (e.g. 320 for GL 3.2)
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
// GLES 2
|
||||
bd->GlVersion = 200;
|
||||
bd->GlProfileIsES2 = true;
|
||||
#else
|
||||
// Desktop or GLES 3
|
||||
const char* gl_version_str = (const char*)glGetString(GL_VERSION);
|
||||
GLint major = 0;
|
||||
GLint minor = 0;
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &minor);
|
||||
if (major == 0 && minor == 0)
|
||||
sscanf(gl_version_str, "%d.%d", &major, &minor); // Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
|
||||
#if defined(GL_CONTEXT_PROFILE_MASK)
|
||||
if (bd->GlVersion >= 320)
|
||||
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask);
|
||||
bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
|
||||
#endif
|
||||
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
bd->GlProfileIsES3 = true;
|
||||
#else
|
||||
if (strncmp(gl_version_str, "OpenGL ES 3", 11) == 0)
|
||||
bd->GlProfileIsES3 = true;
|
||||
#endif
|
||||
|
||||
bd->UseBufferSubData = false;
|
||||
/*
|
||||
// Query vendor to enable glBufferSubData kludge
|
||||
#ifdef _WIN32
|
||||
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
|
||||
if (strncmp(vendor, "Intel", 5) == 0)
|
||||
bd->UseBufferSubData = true;
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
||||
printf("GlVersion = %d, \"%s\"\nGlProfileIsCompat = %d\nGlProfileMask = 0x%X\nGlProfileIsES2 = %d, GlProfileIsES3 = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", bd->GlVersion, gl_version_str, bd->GlProfileIsCompat, bd->GlProfileMask, bd->GlProfileIsES2, bd->GlProfileIsES3, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG]
|
||||
#endif
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||
if (bd->GlVersion >= 320)
|
||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||
#endif
|
||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||
|
||||
// Store GLSL version string so we can refer to it later in case we recreate shaders.
|
||||
// Note: GLSL version is NOT the same as GL version. Leave this to nullptr if unsure.
|
||||
if (glsl_version == nullptr)
|
||||
{
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
glsl_version = "#version 100";
|
||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
glsl_version = "#version 300 es";
|
||||
#elif defined(__APPLE__)
|
||||
glsl_version = "#version 150";
|
||||
#else
|
||||
glsl_version = "#version 130";
|
||||
#endif
|
||||
}
|
||||
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(bd->GlslVersionString));
|
||||
strcpy(bd->GlslVersionString, glsl_version);
|
||||
strcat(bd->GlslVersionString, "\n");
|
||||
|
||||
// Make an arbitrary GL call (we don't actually need the result)
|
||||
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
|
||||
GLint current_texture;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
||||
|
||||
// Detect extensions we support
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
bd->HasPolygonMode = (!bd->GlProfileIsES2 && !bd->GlProfileIsES3);
|
||||
#endif
|
||||
bd->HasClipOrigin = (bd->GlVersion >= 450);
|
||||
#ifdef IMGUI_IMPL_OPENGL_HAS_EXTENSIONS
|
||||
GLint num_extensions = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
|
||||
for (GLint i = 0; i < num_extensions; i++)
|
||||
{
|
||||
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||
if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0)
|
||||
bd->HasClipOrigin = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
ImGui_ImplOpenGL3_InitPlatformInterface();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_Shutdown()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImGui_ImplOpenGL3_ShutdownPlatformInterface();
|
||||
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||
io.BackendRendererName = nullptr;
|
||||
io.BackendRendererUserData = nullptr;
|
||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports);
|
||||
IM_DELETE(bd);
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_NewFrame()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplOpenGL3_Init()?");
|
||||
|
||||
if (!bd->ShaderHandle)
|
||||
ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||
}
|
||||
|
||||
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
if (bd->GlVersion >= 310)
|
||||
glDisable(GL_PRIMITIVE_RESTART);
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
if (bd->HasPolygonMode)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
#endif
|
||||
|
||||
// Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
|
||||
#if defined(GL_CLIP_ORIGIN)
|
||||
bool clip_origin_lower_left = true;
|
||||
if (bd->HasClipOrigin)
|
||||
{
|
||||
GLenum current_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)¤t_clip_origin);
|
||||
if (current_clip_origin == GL_UPPER_LEFT)
|
||||
clip_origin_lower_left = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup viewport, orthographic projection matrix
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
||||
GL_CALL(glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
|
||||
float L = draw_data->DisplayPos.x;
|
||||
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
||||
float T = draw_data->DisplayPos.y;
|
||||
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
||||
#if defined(GL_CLIP_ORIGIN)
|
||||
if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
|
||||
#endif
|
||||
const float ortho_projection[4][4] =
|
||||
{
|
||||
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
|
||||
};
|
||||
glUseProgram(bd->ShaderHandle);
|
||||
glUniform1i(bd->AttribLocationTex, 0);
|
||||
glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
if (bd->GlVersion >= 330 || bd->GlProfileIsES3)
|
||||
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 and GL ES 3.0 may set that otherwise.
|
||||
#endif
|
||||
|
||||
(void)vertex_array_object;
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindVertexArray(vertex_array_object);
|
||||
#endif
|
||||
|
||||
// Bind vertex/index buffers and setup attributes for ImDrawVert
|
||||
GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, bd->VboHandle));
|
||||
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bd->ElementsHandle));
|
||||
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxPos));
|
||||
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxUV));
|
||||
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxColor));
|
||||
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, pos)));
|
||||
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, uv)));
|
||||
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, col)));
|
||||
}
|
||||
|
||||
// OpenGL3 Render function.
|
||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly.
|
||||
// This is in order to be able to run within an OpenGL engine that doesn't do so.
|
||||
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
|
||||
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
|
||||
if (fb_width <= 0 || fb_height <= 0)
|
||||
return;
|
||||
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Backup GL state
|
||||
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program);
|
||||
GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
GLuint last_sampler; if (bd->GlVersion >= 330 || bd->GlProfileIsES3) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; }
|
||||
#endif
|
||||
GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer);
|
||||
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
// This is part of VAO on OpenGL 3.0+ and OpenGL ES 3.0+.
|
||||
GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
|
||||
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_pos; last_vtx_attrib_state_pos.GetState(bd->AttribLocationVtxPos);
|
||||
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_uv; last_vtx_attrib_state_uv.GetState(bd->AttribLocationVtxUV);
|
||||
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_color; last_vtx_attrib_state_color.GetState(bd->AttribLocationVtxColor);
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object);
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
GLint last_polygon_mode[2]; if (bd->HasPolygonMode) { glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); }
|
||||
#endif
|
||||
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
|
||||
GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb);
|
||||
GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb);
|
||||
GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha);
|
||||
GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha);
|
||||
GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb);
|
||||
GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha);
|
||||
GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
|
||||
GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||
GLboolean last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST);
|
||||
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
GLboolean last_enable_primitive_restart = (bd->GlVersion >= 310) ? glIsEnabled(GL_PRIMITIVE_RESTART) : GL_FALSE;
|
||||
#endif
|
||||
|
||||
// Setup desired GL state
|
||||
// Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
|
||||
// The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
|
||||
GLuint vertex_array_object = 0;
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GL_CALL(glGenVertexArrays(1, &vertex_array_object));
|
||||
#endif
|
||||
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
||||
|
||||
// Will project scissor/clipping rectangles into framebuffer space
|
||||
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
||||
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
|
||||
|
||||
// Render command lists
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
|
||||
// Upload vertex/index buffers
|
||||
// - OpenGL drivers are in a very sorry state nowadays....
|
||||
// During 2021 we attempted to switch from glBufferData() to orphaning+glBufferSubData() following reports
|
||||
// of leaks on Intel GPU when using multi-viewports on Windows.
|
||||
// - After this we kept hearing of various display corruptions issues. We started disabling on non-Intel GPU, but issues still got reported on Intel.
|
||||
// - We are now back to using exclusively glBufferData(). So bd->UseBufferSubData IS ALWAYS FALSE in this code.
|
||||
// We are keeping the old code path for a while in case people finding new issues may want to test the bd->UseBufferSubData path.
|
||||
// - See https://github.com/ocornut/imgui/issues/4468 and please report any corruption issues.
|
||||
const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
|
||||
const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
|
||||
if (bd->UseBufferSubData)
|
||||
{
|
||||
if (bd->VertexBufferSize < vtx_buffer_size)
|
||||
{
|
||||
bd->VertexBufferSize = vtx_buffer_size;
|
||||
GL_CALL(glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, nullptr, GL_STREAM_DRAW));
|
||||
}
|
||||
if (bd->IndexBufferSize < idx_buffer_size)
|
||||
{
|
||||
bd->IndexBufferSize = idx_buffer_size;
|
||||
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, nullptr, GL_STREAM_DRAW));
|
||||
}
|
||||
GL_CALL(glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data));
|
||||
GL_CALL(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data));
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CALL(glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW));
|
||||
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW));
|
||||
}
|
||||
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback != nullptr)
|
||||
{
|
||||
// User callback, registered via ImDrawList::AddCallback()
|
||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
||||
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
||||
else
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Project scissor/clipping rectangles into framebuffer space
|
||||
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
||||
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||
continue;
|
||||
|
||||
// Apply scissor/clipping rectangle (Y is inverted in OpenGL)
|
||||
GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
|
||||
|
||||
// Bind texture, Draw
|
||||
GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||
if (bd->GlVersion >= 320)
|
||||
GL_CALL(glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset));
|
||||
else
|
||||
#endif
|
||||
GL_CALL(glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the temporary VAO
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GL_CALL(glDeleteVertexArrays(1, &vertex_array_object));
|
||||
#endif
|
||||
|
||||
// Restore modified GL state
|
||||
// This "glIsProgram()" check is required because if the program is "pending deletion" at the time of binding backup, it will have been deleted by now and will cause an OpenGL error. See #6220.
|
||||
if (last_program == 0 || glIsProgram(last_program)) glUseProgram(last_program);
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
if (bd->GlVersion >= 330 || bd->GlProfileIsES3)
|
||||
glBindSampler(0, last_sampler);
|
||||
#endif
|
||||
glActiveTexture(last_active_texture);
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindVertexArray(last_vertex_array_object);
|
||||
#endif
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
|
||||
last_vtx_attrib_state_pos.SetState(bd->AttribLocationVtxPos);
|
||||
last_vtx_attrib_state_uv.SetState(bd->AttribLocationVtxUV);
|
||||
last_vtx_attrib_state_color.SetState(bd->AttribLocationVtxColor);
|
||||
#endif
|
||||
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
|
||||
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
|
||||
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
|
||||
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
|
||||
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
|
||||
if (last_enable_stencil_test) glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);
|
||||
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
if (bd->GlVersion >= 310) { if (last_enable_primitive_restart) glEnable(GL_PRIMITIVE_RESTART); else glDisable(GL_PRIMITIVE_RESTART); }
|
||||
#endif
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
// Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons
|
||||
if (bd->HasPolygonMode) { if (bd->GlVersion <= 310 || bd->GlProfileIsCompat) { glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); } else { glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); } }
|
||||
#endif // IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
|
||||
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
|
||||
(void)bd; // Not all compilation paths use this
|
||||
}
|
||||
|
||||
bool ImGui_ImplOpenGL3_CreateFontsTexture()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Build texture atlas
|
||||
unsigned char* pixels;
|
||||
int width, height;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
||||
|
||||
// Upload texture to graphics system
|
||||
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
||||
GLint last_texture;
|
||||
GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
|
||||
GL_CALL(glGenTextures(1, &bd->FontTexture));
|
||||
GL_CALL(glBindTexture(GL_TEXTURE_2D, bd->FontTexture));
|
||||
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
#ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
|
||||
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
|
||||
#endif
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
|
||||
// Store our identifier
|
||||
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
|
||||
|
||||
// Restore state
|
||||
GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_DestroyFontsTexture()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
if (bd->FontTexture)
|
||||
{
|
||||
glDeleteTextures(1, &bd->FontTexture);
|
||||
io.Fonts->SetTexID(0);
|
||||
bd->FontTexture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
|
||||
static bool CheckShader(GLuint handle, const char* desc)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
GLint status = 0, log_length = 0;
|
||||
glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
|
||||
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if ((GLboolean)status == GL_FALSE)
|
||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s! With GLSL: %s\n", desc, bd->GlslVersionString);
|
||||
if (log_length > 1)
|
||||
{
|
||||
ImVector<char> buf;
|
||||
buf.resize((int)(log_length + 1));
|
||||
glGetShaderInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
|
||||
fprintf(stderr, "%s\n", buf.begin());
|
||||
}
|
||||
return (GLboolean)status == GL_TRUE;
|
||||
}
|
||||
|
||||
// If you get an error please report on GitHub. You may try different GL context version or GLSL version.
|
||||
static bool CheckProgram(GLuint handle, const char* desc)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
GLint status = 0, log_length = 0;
|
||||
glGetProgramiv(handle, GL_LINK_STATUS, &status);
|
||||
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if ((GLboolean)status == GL_FALSE)
|
||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! With GLSL %s\n", desc, bd->GlslVersionString);
|
||||
if (log_length > 1)
|
||||
{
|
||||
ImVector<char> buf;
|
||||
buf.resize((int)(log_length + 1));
|
||||
glGetProgramInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
|
||||
fprintf(stderr, "%s\n", buf.begin());
|
||||
}
|
||||
return (GLboolean)status == GL_TRUE;
|
||||
}
|
||||
|
||||
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Backup GL state
|
||||
GLint last_texture, last_array_buffer;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_BUFFER_PIXEL_UNPACK
|
||||
GLint last_pixel_unpack_buffer = 0;
|
||||
if (bd->GlVersion >= 210) { glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &last_pixel_unpack_buffer); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); }
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GLint last_vertex_array;
|
||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||
#endif
|
||||
|
||||
// Parse GLSL version string
|
||||
int glsl_version = 130;
|
||||
sscanf(bd->GlslVersionString, "#version %d", &glsl_version);
|
||||
|
||||
const GLchar* vertex_shader_glsl_120 =
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"attribute vec2 Position;\n"
|
||||
"attribute vec2 UV;\n"
|
||||
"attribute vec4 Color;\n"
|
||||
"varying vec2 Frag_UV;\n"
|
||||
"varying vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_130 =
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"in vec2 Position;\n"
|
||||
"in vec2 UV;\n"
|
||||
"in vec4 Color;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_300_es =
|
||||
"precision highp float;\n"
|
||||
"layout (location = 0) in vec2 Position;\n"
|
||||
"layout (location = 1) in vec2 UV;\n"
|
||||
"layout (location = 2) in vec4 Color;\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_410_core =
|
||||
"layout (location = 0) in vec2 Position;\n"
|
||||
"layout (location = 1) in vec2 UV;\n"
|
||||
"layout (location = 2) in vec4 Color;\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_120 =
|
||||
"#ifdef GL_ES\n"
|
||||
" precision mediump float;\n"
|
||||
"#endif\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"varying vec2 Frag_UV;\n"
|
||||
"varying vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_130 =
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_300_es =
|
||||
"precision mediump float;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"layout (location = 0) out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_410_core =
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"layout (location = 0) out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
// Select shaders matching our GLSL versions
|
||||
const GLchar* vertex_shader = nullptr;
|
||||
const GLchar* fragment_shader = nullptr;
|
||||
if (glsl_version < 130)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_120;
|
||||
fragment_shader = fragment_shader_glsl_120;
|
||||
}
|
||||
else if (glsl_version >= 410)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_410_core;
|
||||
fragment_shader = fragment_shader_glsl_410_core;
|
||||
}
|
||||
else if (glsl_version == 300)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_300_es;
|
||||
fragment_shader = fragment_shader_glsl_300_es;
|
||||
}
|
||||
else
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_130;
|
||||
fragment_shader = fragment_shader_glsl_130;
|
||||
}
|
||||
|
||||
// Create shaders
|
||||
const GLchar* vertex_shader_with_version[2] = { bd->GlslVersionString, vertex_shader };
|
||||
GLuint vert_handle = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vert_handle, 2, vertex_shader_with_version, nullptr);
|
||||
glCompileShader(vert_handle);
|
||||
CheckShader(vert_handle, "vertex shader");
|
||||
|
||||
const GLchar* fragment_shader_with_version[2] = { bd->GlslVersionString, fragment_shader };
|
||||
GLuint frag_handle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(frag_handle, 2, fragment_shader_with_version, nullptr);
|
||||
glCompileShader(frag_handle);
|
||||
CheckShader(frag_handle, "fragment shader");
|
||||
|
||||
// Link
|
||||
bd->ShaderHandle = glCreateProgram();
|
||||
glAttachShader(bd->ShaderHandle, vert_handle);
|
||||
glAttachShader(bd->ShaderHandle, frag_handle);
|
||||
glLinkProgram(bd->ShaderHandle);
|
||||
CheckProgram(bd->ShaderHandle, "shader program");
|
||||
|
||||
glDetachShader(bd->ShaderHandle, vert_handle);
|
||||
glDetachShader(bd->ShaderHandle, frag_handle);
|
||||
glDeleteShader(vert_handle);
|
||||
glDeleteShader(frag_handle);
|
||||
|
||||
bd->AttribLocationTex = glGetUniformLocation(bd->ShaderHandle, "Texture");
|
||||
bd->AttribLocationProjMtx = glGetUniformLocation(bd->ShaderHandle, "ProjMtx");
|
||||
bd->AttribLocationVtxPos = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Position");
|
||||
bd->AttribLocationVtxUV = (GLuint)glGetAttribLocation(bd->ShaderHandle, "UV");
|
||||
bd->AttribLocationVtxColor = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Color");
|
||||
|
||||
// Create buffers
|
||||
glGenBuffers(1, &bd->VboHandle);
|
||||
glGenBuffers(1, &bd->ElementsHandle);
|
||||
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
|
||||
// Restore modified GL state
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_BUFFER_PIXEL_UNPACK
|
||||
if (bd->GlVersion >= 210) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, last_pixel_unpack_buffer); }
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindVertexArray(last_vertex_array);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
if (bd->VboHandle) { glDeleteBuffers(1, &bd->VboHandle); bd->VboHandle = 0; }
|
||||
if (bd->ElementsHandle) { glDeleteBuffers(1, &bd->ElementsHandle); bd->ElementsHandle = 0; }
|
||||
if (bd->ShaderHandle) { glDeleteProgram(bd->ShaderHandle); bd->ShaderHandle = 0; }
|
||||
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
||||
// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
|
||||
// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
static void ImGui_ImplOpenGL3_RenderWindow(ImGuiViewport* viewport, void*)
|
||||
{
|
||||
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
||||
{
|
||||
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
ImGui_ImplOpenGL3_RenderDrawData(viewport->DrawData);
|
||||
}
|
||||
|
||||
static void ImGui_ImplOpenGL3_InitPlatformInterface()
|
||||
{
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
platform_io.Renderer_RenderWindow = ImGui_ImplOpenGL3_RenderWindow;
|
||||
}
|
||||
|
||||
static void ImGui_ImplOpenGL3_ShutdownPlatformInterface()
|
||||
{
|
||||
ImGui::DestroyPlatformWindows();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
@ -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
|
||||
|
||||
// Backend API
|
||||
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
|
||||
217
libs/tracy/profiler/src/llm/system.prompt.md
Normal file
217
libs/tracy/profiler/src/llm/system.prompt.md
Normal file
@ -0,0 +1,217 @@
|
||||
You are a language model, designed to provide precise answers based on available tools and your knowledge. Your operation must strictly adhere to the instructions below.
|
||||
|
||||
|
||||
# Core Principles:
|
||||
|
||||
1. *Never guess or invent information.* If you do not have the necessary data, use the available tools to gather it.
|
||||
2. Always protect privacy of the user.
|
||||
3. If the tools return no data or you still lack the required information after using the tools, attempt to answer using your internal knowledge, while clearly informing the user that the response might be incorrect, invalid, or wrong, and that the tools returned no data.
|
||||
4. *Never ask the user* for permission to use tools or perform further queries. You *MUST* conduct the entire information retrieval process independently, and *ONLY THEN* reply to the user.
|
||||
5. *Language Consistency:* If the user's query is in a language other than English, you MUST translate *all* tool output and internally generated responses into the user's query language *before* formulating your final response. Your final response to the user must always be in the language they used. Do not output information in any other language.
|
||||
6. Prioritize information obtained via tools (from `<tool_output>`) over your internal knowledge when constructing your response. Treat tool outputs as the leading source of information, but be aware that they may contain irrelevant details, inconsistencies, or inaccuracies. Critically evaluate all tool outputs: check for relevance to the user's query, cross-reference information across different tool outputs, and assess consistency with your internal knowledge. If multiple tool outputs provide conflicting but equally plausible information, you may state the different findings or, if possible, explain the discrepancy if it leads to a clearer answer. Avoid presenting information as definitively true if its source is uncertain.
|
||||
|
||||
|
||||
# Thinking Process and Tool Usage:
|
||||
|
||||
Your operation process will be strictly structured using `<think>` and `<tool>` tags.
|
||||
|
||||
1. *Thinking Process (`<think>`):*
|
||||
- Always start with a `<think>` block.
|
||||
- This block is for planning, analyzing the user's query, deciding which tools are needed (if any), processing results from `<tool_output>`, and formulating the structure of the response.
|
||||
- You must analyse the question or any attachments provided by the user to decide which tools you can use.
|
||||
- The tag name MUST be exactly `think`.
|
||||
|
||||
2. *Tool Usage (`<tool>`):*
|
||||
- If, in the `<think>` block, you decide you need to use a tool, the next block generated *MUST* be a `<tool>` block.
|
||||
- The tag name MUST be exactly `tool`.
|
||||
- There can be ONLY ONE tool call in the `<tool>` block.
|
||||
- Only ONE tool call is permitted PER TURN.
|
||||
- *After generating a `<tool>` block, you MUST END YOUR RESPONSE FOR THIS TURN.* Do not generate any other text or tags after the `<tool>` block. The system will process this tool call and provide you with the result in the next step.
|
||||
- The tool name and its parameters (if applicable) must be passed as a json data. For example:
|
||||
<think>
|
||||
The user is asking about the weather in San Francisco. I need to use the weather checking tool. The tool name is 'check_weather', the parameter is the city name.
|
||||
</think>
|
||||
<tool>
|
||||
{"tool": "check_weather", "city": "San Francisco"}
|
||||
</tool>
|
||||
|
||||
3. *Tool Output (`<tool_output>`):*
|
||||
- After the system executes the tool call from the `<tool>` block, you will receive the result in an `<tool_output>` block.
|
||||
- *You MUST process this result in the subsequent `<think>` block.* Analyze the data received. Based on it, decide if further tool calls are necessary or if you have enough information to answer the user.
|
||||
- *Never show the user the raw text from `<tool_output>`*. All processing happens internally within the `<think>` block.
|
||||
|
||||
|
||||
# Available Tools:
|
||||
|
||||
These are the tools you can use. *You have no access to any other tools or means to search the web outside of these.*
|
||||
|
||||
```json
|
||||
{
|
||||
"tool": "search_wikipedia",
|
||||
"description": "Search the Wikipedia with given query. The `key` field in the response is the Wikipedia page name.",
|
||||
"network": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "query",
|
||||
"description": "The search terms in the language matching the second parameter."
|
||||
},
|
||||
{
|
||||
"name": "language",
|
||||
"description": "Language code matching the search query. For example, `en` for English or `pl` for Polish."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tool": "get_wikipedia",
|
||||
"description": "Retrieve the Wikipedia article on given subject. The response may be trimmed.",
|
||||
"network": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "page",
|
||||
"description": "The `key` field from the search response, specifying the topic you want to retrieve.",
|
||||
},
|
||||
{
|
||||
"name": "language",
|
||||
"description": "Language code."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tool": "get_dictionary",
|
||||
"description": "Retrieve description of a word from dictionary.",
|
||||
"network": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "word",
|
||||
"description": "Word to describe."
|
||||
},
|
||||
{
|
||||
"name": "language",
|
||||
"description": "Language code."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tool": "search_web",
|
||||
"description": "Search the web with given query.",
|
||||
"network": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "query",
|
||||
"description": "Search query."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tool": "get_webpage",
|
||||
"description": "Download web page at given URL.",
|
||||
"network": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "url",
|
||||
"description": "Web page to download."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tool": "user_manual",
|
||||
"description": "Search the Tracy Profiler user manual with given query.",
|
||||
"local": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "query",
|
||||
"description": "Verbose search query in English language."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tool": "source_file",
|
||||
"description": "Retrieve the source file contents.",
|
||||
"local": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "file",
|
||||
"description": "Path to the file."
|
||||
},
|
||||
{
|
||||
"name": "line",
|
||||
"description": "Line number that should be retrieved (as large files may be not available completely)."
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Tools marked as `local` operate privately and are always safe to use. Tools marked as `network` send data over the internet and may affect user's privacy.
|
||||
|
||||
|
||||
# Tool Usage and Knowledge Strategy:
|
||||
|
||||
1. *Source Priority:*
|
||||
- For questions related to Tracy Profiler always refer to the `user_manual`. Do not use this tool to research user's program.
|
||||
- If the user's question explicitly asks about source code in user's program (for example, a callstack provided as an attachment), use the `source_file` tool to retrieve the content of specified files.
|
||||
- For other factual queries, start by checking Wikipedia. If Wikipedia doesn't provide enough information, or if the topic is new or highly specialized, then perform a `search_web` query.
|
||||
2. *Internal Knowledge vs. Tools:* Always assume your internal knowledge is incomplete or outdated compared to information from tools. *You MUST use tools* to get the latest and most accurate data on subjects covered by their scope (e.g. facts likely on Wikipedia or the web). Output from previous tool invocations must be always considered.
|
||||
3. *Efficient Tool Use:* Before using a tool you MUST check if previous tool calls already contain the tool and parameters you want to call. If they do, you are forbidden from calling the tool a second time. You must use the tool output you already have.
|
||||
4. *Tool Output Completness:* Some tools will return snippets or summaries of the information, which can only be used in limited conditions. You MUST use these summaries to decide which tool to call next to get complete data.
|
||||
5. *Mandatory Content Retrieval:* Some tool outputs (e.g. `search_wikipedia` or `search_web`) provide only summaries or snippets. These are *never* sufficient for formulating a final answer. Their sole purpose is to identify the most promising page or URL. You MUST always follow a successful search with a corresponding tool call (e.g., `get_wikipedia` or `get_webpage`) to retrieve the full content before attempting to answer the user's query. Do not answer based on search snippets alone. The only exception is if the search returns no relevant results.
|
||||
|
||||
|
||||
# Final Response to the User:
|
||||
|
||||
1. Once you have gathered all necessary information using the `<think>`, `<tool>`, and `<tool_output>` processing cycle, *generate the final response FOR THE USER.*
|
||||
2. This final response *MUST* be *OUTSIDE* of the `<think>` and `<tool>` tags.
|
||||
3. The user shouldn't know you are "using tools". Use a natural language, such as "the Wikipedia states that..." or "the web search results indicate that...". The user should not be aware of the tool usage process.
|
||||
4. Provide responses *strictly in the language the user used* in their query.
|
||||
|
||||
|
||||
# Summary of Communication Structure:
|
||||
|
||||
Each of your responses (or part of a response, if it requires a tool call) should start with a `<think>` block, followed by either a `<tool>` block (if further information is needed) or directly the final response to the user (if you have all information).
|
||||
|
||||
**Example Cycle (Not visible to the user):**
|
||||
User: "What is the capital of Poland?"
|
||||
Model:
|
||||
<think>
|
||||
The user is asking for the capital of Poland, in English language. This is a standard fact, but instructions say to use tools for facts. I should search Wikipedia. I need search_wikipedia for "capital of Poland" in language "en" to find the key.
|
||||
</think>
|
||||
<tool>
|
||||
{"tool": "search_wikipedia", "query": "capital of Poland", "language": "en"}
|
||||
</tool>
|
||||
|
||||
System returns `<tool_output>` with the key for the article about Warsaw.
|
||||
Model (New Turn):
|
||||
<think>
|
||||
I retrieved the key for the capital of Poland article ("Warsaw"). Now I need to retrieve that article using get_wikipedia. The key is "Warsaw", language is "en".
|
||||
</think>
|
||||
<tool>
|
||||
{"tool": "get_wikipedia", "page": "Warsaw", "language": "en"}
|
||||
</tool>
|
||||
|
||||
System returns `<tool_output>` with the content of the Warsaw article, stating it is the capital.
|
||||
Model (New Turn):
|
||||
<think>
|
||||
I downloaded the content of the Warsaw article. It confirms that Warsaw is the capital of Poland. I have all the necessary information. I can provide the answer in user's language, which is English.
|
||||
</think>
|
||||
The capital of Poland is Warsaw.
|
||||
|
||||
*The user only sees:* "The capital of Poland is Warsaw."
|
||||
|
||||
|
||||
# Attachments
|
||||
|
||||
The user may provide various types of attachments for you to process. These attachments come from the users's program. When you process *attachments* using *tools that access a network*, you must adhere to the following privacy protection rules. The rules *do not* apply in other circumstances, such as in conversation with the user, when using local tools, or when getting data for things unrelated to the user's program.
|
||||
|
||||
- Protect Private Information: Do not use any project, class, function, code snippets, or file names in *network tool* queries when the source is located in a user's private directory.
|
||||
- Publicly Available Files: This restriction does not apply to files that are in publicly accessible locations.
|
||||
- Tool Use: The `source_file` tool preserves user privacy and can be used regardless of the source file location.
|
||||
|
||||
|
||||
# Context of operation
|
||||
|
||||
You operate in context of Tracy Profiler, a C++ profiler for games and other applications. The profiler uses various methods to measure how the user's program behaves and measures the program's run-time performance characteristics. As such, there are various types of questions the user may ask you, and you must properly classify each question in order to give the best possible answer:
|
||||
|
||||
- The user may ask you about things related to Tracy Profiler. In this case you should primarily focus on the `user_manual` tool, which provides information about the profiler. When refering to specific terms in the profiler UI, use the original English names.
|
||||
- The user may attach information from the program they are profiling and ask you about it. Since this would be mostly private data, you should focus on the `source_file` tool, which will give you context about specific source locations referenced in the attachment. You may need to put more emphasis on your internal knowledge when answering these kind of questions. Use of other tools should be limited to cases where it's obvious they will be useful. For example, you may want to search the web about the zlib library if the code uses it, or, you may retrieve a web page referenced in the source code comments.
|
||||
- The user may also ask general question not related either to the profiler or the program they are profiling. In this case answer freely, and use any tool you feel necessary.
|
||||
|
||||
If the user thanks you for your help, ask them to consider making a donation at https://github.com/sponsors/wolfpld.
|
||||
5
libs/tracy/profiler/src/llm/system.reminder.md
Normal file
5
libs/tracy/profiler/src/llm/system.reminder.md
Normal file
@ -0,0 +1,5 @@
|
||||
Remember your core principles:
|
||||
1. Protect user's privacy.
|
||||
2. Always prioritize tools for factual information.
|
||||
3. Your internal knowledge is strictly secondary and a last resort.
|
||||
4. Respond strictly in the user's language.
|
||||
@ -26,8 +26,6 @@
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include "stb_image_resize.h"
|
||||
|
||||
#include "ini.h"
|
||||
|
||||
#include "../../public/common/TracyProtocol.hpp"
|
||||
#include "../../public/common/TracyVersion.hpp"
|
||||
#include "profiler/TracyAchievements.hpp"
|
||||
@ -35,9 +33,9 @@
|
||||
#include "profiler/TracyConfig.hpp"
|
||||
#include "profiler/TracyFileselector.hpp"
|
||||
#include "profiler/TracyImGui.hpp"
|
||||
#include "profiler/TracyMarkdown.hpp"
|
||||
#include "profiler/TracyMouse.hpp"
|
||||
#include "profiler/TracyProtoHistory.hpp"
|
||||
#include "profiler/TracyStorage.hpp"
|
||||
#include "profiler/TracyTexture.hpp"
|
||||
#include "profiler/TracyView.hpp"
|
||||
#include "profiler/TracyWeb.hpp"
|
||||
@ -68,6 +66,8 @@
|
||||
#include "ResolvService.hpp"
|
||||
#include "RunQueue.hpp"
|
||||
|
||||
#include "GitRef.hpp"
|
||||
|
||||
|
||||
struct ClientData
|
||||
{
|
||||
@ -97,9 +97,8 @@ static char addr[1024] = { "127.0.0.1" };
|
||||
static ConnectionHistory* connHist;
|
||||
static std::atomic<ViewShutdown> viewShutdown { ViewShutdown::False };
|
||||
static double animTime = 0;
|
||||
static float dpiScale = 1.f;
|
||||
static float dpiScale = -1.f;
|
||||
static bool dpiScaleOverriddenFromEnv = false;
|
||||
static float userScale = 1.f;
|
||||
static float prevScale = 1.f;
|
||||
static int dpiChanged = 0;
|
||||
static bool dpiFirstSetup = true;
|
||||
@ -110,16 +109,15 @@ static bool showReleaseNotes = false;
|
||||
static std::string releaseNotes;
|
||||
static uint8_t* iconPx;
|
||||
static int iconX, iconY;
|
||||
static void* iconTex;
|
||||
static ImTextureID iconTex;
|
||||
static int iconTexSz;
|
||||
static uint8_t* zigzagPx[6];
|
||||
static int zigzagX[6], zigzagY[6];
|
||||
void* zigzagTex;
|
||||
ImTextureID zigzagTex;
|
||||
static Backend* bptr;
|
||||
static bool s_customTitle = false;
|
||||
static bool s_isElevated = false;
|
||||
static size_t s_totalMem = tracy::GetPhysicalMemorySize();
|
||||
tracy::Config s_config;
|
||||
tracy::AchievementsMgr* s_achievements;
|
||||
static const tracy::data::AchievementItem* s_achievementItem = nullptr;
|
||||
static bool s_switchAchievementCategory = false;
|
||||
@ -160,19 +158,15 @@ static void ScaleWindow(ImGuiWindow* window, float scale)
|
||||
|
||||
static void SetupDPIScale()
|
||||
{
|
||||
auto scale = dpiScale * userScale;
|
||||
auto scale = dpiScale * tracy::s_config.userScale;
|
||||
|
||||
if( !dpiFirstSetup && prevScale == scale ) return;
|
||||
dpiFirstSetup = false;
|
||||
dpiChanged = 2;
|
||||
|
||||
LoadFonts( scale );
|
||||
if( view ) view->UpdateFont( s_fixedWidth, s_smallFont, s_bigFont );
|
||||
|
||||
#ifdef __APPLE__
|
||||
// No need to upscale the style on macOS, but we need to downscale the fonts.
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.FontGlobalScale = 1.0f / dpiScale;
|
||||
scale = 1.0f;
|
||||
#endif
|
||||
|
||||
@ -186,6 +180,7 @@ static void SetupDPIScale()
|
||||
style.Colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f);
|
||||
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
||||
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.45f);
|
||||
style.Colors[ImGuiCol_TitleBgCollapsed] = style.Colors[ImGuiCol_TitleBg];
|
||||
style.ScaleAllSizes( scale );
|
||||
|
||||
const auto ty = int( 80 * scale );
|
||||
@ -201,12 +196,6 @@ static void SetupDPIScale()
|
||||
for( auto& w : ctx->Windows ) ScaleWindow( w, ratio );
|
||||
}
|
||||
|
||||
static void SetupScaleCallback( float scale )
|
||||
{
|
||||
userScale = scale;
|
||||
RunOnMainThread( []{ SetupDPIScale(); }, true );
|
||||
}
|
||||
|
||||
static int IsBusy()
|
||||
{
|
||||
if( loadThread.joinable() ) return 2;
|
||||
@ -214,59 +203,17 @@ static int IsBusy()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void LoadConfig()
|
||||
static void SetupScaleCallback( float scale )
|
||||
{
|
||||
const auto fn = tracy::GetSavePath( "tracy.ini" );
|
||||
auto ini = ini_load( fn );
|
||||
if( !ini ) return;
|
||||
|
||||
int v;
|
||||
if( ini_sget( ini, "core", "threadedRendering", "%d", &v ) ) s_config.threadedRendering = v;
|
||||
if( ini_sget( ini, "core", "focusLostLimit", "%d", &v ) ) s_config.focusLostLimit = v;
|
||||
if( ini_sget( ini, "timeline", "targetFps", "%d", &v ) && v >= 1 && v < 10000 ) s_config.targetFps = v;
|
||||
if( ini_sget( ini, "timeline", "dynamicColors", "%d", &v ) ) s_config.dynamicColors = v;
|
||||
if( ini_sget( ini, "timeline", "forceColors", "%d", &v ) ) s_config.forceColors = v;
|
||||
if( ini_sget( ini, "timeline", "shortenName", "%d", &v ) ) s_config.shortenName = v;
|
||||
if( ini_sget( ini, "memory", "limit", "%d", &v ) ) s_config.memoryLimit = v;
|
||||
if( ini_sget( ini, "memory", "percent", "%d", &v ) && v >= 1 && v < 1000 ) s_config.memoryLimitPercent = v;
|
||||
if( ini_sget( ini, "achievements", "enabled", "%d", &v ) ) s_config.achievements = v;
|
||||
if( ini_sget( ini, "achievements", "asked", "%d", &v ) ) s_config.achievementsAsked = v;
|
||||
|
||||
ini_free( ini );
|
||||
}
|
||||
|
||||
static bool SaveConfig()
|
||||
{
|
||||
const auto fn = tracy::GetSavePath( "tracy.ini" );
|
||||
FILE* f = fopen( fn, "wb" );
|
||||
if( !f ) return false;
|
||||
|
||||
fprintf( f, "[core]\n" );
|
||||
fprintf( f, "threadedRendering = %i\n", (int)s_config.threadedRendering );
|
||||
fprintf( f, "focusLostLimit = %i\n", (int)s_config.focusLostLimit );
|
||||
|
||||
fprintf( f, "\n[timeline]\n" );
|
||||
fprintf( f, "targetFps = %i\n", s_config.targetFps );
|
||||
fprintf( f, "dynamicColors = %i\n", s_config.dynamicColors );
|
||||
fprintf( f, "forceColors = %i\n", (int)s_config.forceColors );
|
||||
fprintf( f, "shortenName = %i\n", s_config.shortenName );
|
||||
|
||||
fprintf( f, "\n[memory]\n" );
|
||||
fprintf( f, "limit = %i\n", (int)s_config.memoryLimit );
|
||||
fprintf( f, "percent = %i\n", s_config.memoryLimitPercent );
|
||||
|
||||
fprintf( f, "\n[achievements]\n" );
|
||||
fprintf( f, "enabled = %i\n", (int)s_config.achievements );
|
||||
fprintf( f, "asked = %i\n", (int)s_config.achievementsAsked );
|
||||
|
||||
fclose( f );
|
||||
return true;
|
||||
tracy::s_config.userScale = scale;
|
||||
if ( tracy::s_config.saveUserScale ) tracy::SaveConfig();
|
||||
RunOnMainThread( []{ SetupDPIScale(); }, true );
|
||||
}
|
||||
|
||||
static void ScaleChanged( float scale )
|
||||
{
|
||||
if ( dpiScaleOverriddenFromEnv ) return;
|
||||
if ( dpiScale == scale ) return;
|
||||
if( dpiScaleOverriddenFromEnv ) return;
|
||||
if( dpiScale == scale ) return;
|
||||
|
||||
dpiScale = scale;
|
||||
SetupDPIScale();
|
||||
@ -371,7 +318,7 @@ int main( int argc, char** argv )
|
||||
zigzagPx[5] = stbi_load_from_memory( (const stbi_uc*)ZigZag01_data, ZigZag01_size, &zigzagX[5], &zigzagY[5], nullptr, 4 );
|
||||
} );
|
||||
|
||||
LoadConfig();
|
||||
tracy::LoadConfig();
|
||||
|
||||
ImGuiTracyContext imguiContext;
|
||||
Backend backend( title, DrawContents, ScaleChanged, IsBusy, &mainThreadTasks );
|
||||
@ -382,7 +329,6 @@ int main( int argc, char** argv )
|
||||
backend.SetIcon( iconPx, iconX, iconY );
|
||||
bptr = &backend;
|
||||
|
||||
dpiScale = backend.GetDpiScale();
|
||||
const auto envDpiScale = getenv( "TRACY_DPI_SCALE" );
|
||||
if( envDpiScale )
|
||||
{
|
||||
@ -391,24 +337,23 @@ int main( int argc, char** argv )
|
||||
{
|
||||
dpiScale = cnv;
|
||||
dpiScaleOverriddenFromEnv = true;
|
||||
SetupDPIScale();
|
||||
}
|
||||
}
|
||||
|
||||
s_achievements->Achieve( "achievementsIntro" );
|
||||
|
||||
SetupDPIScale();
|
||||
|
||||
tracy::UpdateTextureRGBAMips( zigzagTex, (void**)zigzagPx, zigzagX, zigzagY, 6 );
|
||||
for( auto& v : zigzagPx ) free( v );
|
||||
|
||||
if( initFileOpen )
|
||||
{
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, *initFileOpen, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, *initFileOpen, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements );
|
||||
initFileOpen.reset();
|
||||
}
|
||||
else if( connectTo )
|
||||
{
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, connectTo, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, connectTo, port, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements );
|
||||
}
|
||||
|
||||
tracy::Fileselector::Init();
|
||||
@ -580,7 +525,7 @@ static void UpdateBroadcastClients()
|
||||
static void TextComment( const char* str )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::PushFont( s_smallFont );
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::AlignTextToFramePadding();
|
||||
tracy::TextDisabledUnformatted( str );
|
||||
ImGui::PopFont();
|
||||
@ -639,7 +584,7 @@ static void DrawContents()
|
||||
int display_w, display_h;
|
||||
bptr->NewFrame( display_w, display_h );
|
||||
|
||||
const bool achievementsAttention = s_config.achievements ? s_achievements->NeedsAttention() : false;
|
||||
const bool achievementsAttention = tracy::s_config.achievements ? s_achievements->NeedsAttention() : false;
|
||||
|
||||
static int activeFrames = 3;
|
||||
if( tracy::WasActive() || !clients.empty() || ( view && view->WasActive() ) || achievementsAttention )
|
||||
@ -691,15 +636,15 @@ static void DrawContents()
|
||||
|
||||
auto& style = ImGui::GetStyle();
|
||||
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.129f, 0.137f, 0.11f, 1.f );
|
||||
ImGui::Begin( "Get started", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse );
|
||||
ImGui::Begin( "Get started", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings );
|
||||
char buf[128];
|
||||
sprintf( buf, "Tracy Profiler %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch );
|
||||
ImGui::PushFont( s_bigFont );
|
||||
ImGui::PushFont( g_fonts.bold, FontNormal * 1.6f );
|
||||
tracy::TextCentered( buf );
|
||||
ImGui::PopFont();
|
||||
if( dpiChanged == 0 )
|
||||
{
|
||||
ImGui::SameLine( ImGui::GetWindowContentRegionMax().x - ImGui::CalcTextSize( ICON_FA_WRENCH ).x - ImGui::GetStyle().FramePadding.x * 2 );
|
||||
ImGui::SameLine( ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize( ICON_FA_WRENCH ).x );
|
||||
if( ImGui::Button( ICON_FA_WRENCH ) )
|
||||
{
|
||||
ImGui::OpenPopup( "About Tracy" );
|
||||
@ -710,9 +655,32 @@ static void DrawContents()
|
||||
{
|
||||
tracy::ImageCentered( iconTex, ImVec2( iconTexSz, iconTexSz ) );
|
||||
ImGui::Spacing();
|
||||
ImGui::PushFont( s_bigFont );
|
||||
ImGui::PushFont( g_fonts.bold, FontNormal * 2.f );
|
||||
tracy::TextCentered( buf );
|
||||
ImGui::Spacing();
|
||||
ImGui::PopFont();
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
tracy::TextCentered( tracy::GitRef );
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopFont();
|
||||
if( ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted( "Click to copy git reference to clipboard" );
|
||||
ImGui::EndTooltip();
|
||||
if( ImGui::IsItemClicked() )
|
||||
{
|
||||
ImGui::SetClipboardText( tracy::GitRef );
|
||||
}
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.f, 0.5f, 0.5f, 1.f ) );
|
||||
tracy::TextCentered( "Debug build" );
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopFont();
|
||||
#endif
|
||||
ImGui::Spacing();
|
||||
ImGui::TextUnformatted( "A real time, nanosecond resolution, remote telemetry, hybrid\nframe and sampling profiler for games and other applications." );
|
||||
ImGui::Spacing();
|
||||
@ -729,67 +697,80 @@ static void DrawContents()
|
||||
|
||||
ImGui::TextUnformatted( "Threaded rendering" );
|
||||
ImGui::Indent();
|
||||
if( ImGui::RadioButton( "Enabled", s_config.threadedRendering ) ) { s_config.threadedRendering = true; SaveConfig(); }
|
||||
if( ImGui::RadioButton( "Enabled", tracy::s_config.threadedRendering ) ) { tracy::s_config.threadedRendering = true; tracy::SaveConfig(); }
|
||||
ImGui::SameLine();
|
||||
tracy::DrawHelpMarker( "Uses multiple CPU cores for rendering. May affect performance of the profiled application when running on the same machine." );
|
||||
if( ImGui::RadioButton( "Disabled", !s_config.threadedRendering ) ) { s_config.threadedRendering = false; SaveConfig(); }
|
||||
if( ImGui::RadioButton( "Disabled", !tracy::s_config.threadedRendering ) ) { tracy::s_config.threadedRendering = false; tracy::SaveConfig(); }
|
||||
ImGui::SameLine();
|
||||
tracy::DrawHelpMarker( "Restricts rendering to a single CPU core. Can reduce profiler frame rate." );
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::Spacing();
|
||||
if( ImGui::Checkbox( "Reduce render rate when focus is lost", &s_config.focusLostLimit ) ) SaveConfig();
|
||||
if( ImGui::Checkbox( "Reduce render rate when focus is lost", &tracy::s_config.focusLostLimit ) ) tracy::SaveConfig();
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::TextUnformatted( "Target FPS" );
|
||||
ImGui::SameLine();
|
||||
tracy::DrawHelpMarker( "The default target frame rate for your application. Frames displayed in the frame time graph will be colored accordingly if they are within the target frame rate. This can be adjusted later for each individual trace." );
|
||||
ImGui::SameLine();
|
||||
int tmp = s_config.targetFps;
|
||||
int tmp = tracy::s_config.targetFps;
|
||||
ImGui::SetNextItemWidth( 90 * dpiScale );
|
||||
if( ImGui::InputInt( "##targetfps", &tmp ) ) { s_config.targetFps = std::clamp( tmp, 1, 9999 ); SaveConfig(); }
|
||||
if( ImGui::InputInt( "##targetfps", &tmp ) ) { tracy::s_config.targetFps = std::clamp( tmp, 1, 9999 ); tracy::SaveConfig(); }
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::TextUnformatted( ICON_FA_PALETTE " Zone colors" );
|
||||
ImGui::SameLine();
|
||||
tracy::SmallCheckbox( "Ignore custom", &s_config.forceColors );
|
||||
tracy::SmallCheckbox( "Ignore custom", &tracy::s_config.forceColors );
|
||||
ImGui::Indent();
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
|
||||
ImGui::RadioButton( "Static", &s_config.dynamicColors, 0 );
|
||||
ImGui::RadioButton( "Thread dynamic", &s_config.dynamicColors, 1 );
|
||||
ImGui::RadioButton( "Source location dynamic", &s_config.dynamicColors, 2 );
|
||||
ImGui::RadioButton( "Static", &tracy::s_config.dynamicColors, 0 );
|
||||
ImGui::RadioButton( "Thread dynamic", &tracy::s_config.dynamicColors, 1 );
|
||||
ImGui::RadioButton( "Source location dynamic", &tracy::s_config.dynamicColors, 2 );
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Unindent();
|
||||
ImGui::TextUnformatted( ICON_FA_RULER_HORIZONTAL " Zone name shortening" );
|
||||
ImGui::Indent();
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
|
||||
ImGui::RadioButton( "Disabled", &s_config.shortenName, (uint8_t)tracy::ShortenName::Never );
|
||||
ImGui::RadioButton( "Minimal length", &s_config.shortenName, (uint8_t)tracy::ShortenName::Always );
|
||||
ImGui::RadioButton( "Only normalize", &s_config.shortenName, (uint8_t)tracy::ShortenName::OnlyNormalize );
|
||||
ImGui::RadioButton( "As needed", &s_config.shortenName, (uint8_t)tracy::ShortenName::NoSpace );
|
||||
ImGui::RadioButton( "As needed + normalize", &s_config.shortenName, (uint8_t)tracy::ShortenName::NoSpaceAndNormalize );
|
||||
ImGui::RadioButton( "Disabled##zns", &tracy::s_config.shortenName, (uint8_t)tracy::ShortenName::Never );
|
||||
ImGui::RadioButton( "Minimal length", &tracy::s_config.shortenName, (uint8_t)tracy::ShortenName::Always );
|
||||
ImGui::RadioButton( "Only normalize", &tracy::s_config.shortenName, (uint8_t)tracy::ShortenName::OnlyNormalize );
|
||||
ImGui::RadioButton( "As needed", &tracy::s_config.shortenName, (uint8_t)tracy::ShortenName::NoSpace );
|
||||
ImGui::RadioButton( "As needed + normalize", &tracy::s_config.shortenName, (uint8_t)tracy::ShortenName::NoSpaceAndNormalize );
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::TextUnformatted( "Scroll multipliers" );
|
||||
ImGui::SameLine();
|
||||
tracy::DrawHelpMarker( "The multipliers to the amount to scroll by horizontally and vertically. This is used in the timeline and setting this value can help compensate for scroll wheel sensitivity." );
|
||||
ImGui::SameLine();
|
||||
double tmpScroll = tracy::s_config.horizontalScrollMultiplier;
|
||||
ImGui::SetNextItemWidth( 45 * dpiScale );
|
||||
if( ImGui::InputDouble( "##horizontalscrollmultiplier", &tmpScroll ) ) { tracy::s_config.horizontalScrollMultiplier = std::max( tmpScroll, 0.01 ); tracy::SaveConfig(); }
|
||||
tmpScroll = tracy::s_config.verticalScrollMultiplier;
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth( 45 * dpiScale );
|
||||
if( ImGui::InputDouble( "##verticalscrollmultiplier", &tmpScroll ) ) { tracy::s_config.verticalScrollMultiplier = std::max( tmpScroll, 0.01 ); tracy::SaveConfig(); }
|
||||
|
||||
if( s_totalMem == 0 )
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
s_config.memoryLimit = false;
|
||||
tracy::s_config.memoryLimit = false;
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
if( ImGui::Checkbox( "Memory limit", &s_config.memoryLimit ) ) SaveConfig();
|
||||
if( ImGui::Checkbox( "Memory limit", &tracy::s_config.memoryLimit ) ) tracy::SaveConfig();
|
||||
ImGui::SameLine();
|
||||
tracy::DrawHelpMarker( "When enabled, profiler will stop recording data when memory usage exceeds the specified percentage of available memory. Values greater than 100% will rely on swap. You need to make sure that memory is actually available." );
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth( 70 * dpiScale );
|
||||
if( ImGui::InputInt( "##memorylimit", &s_config.memoryLimitPercent ) ) { s_config.memoryLimitPercent = std::clamp( s_config.memoryLimitPercent, 1, 999 ); SaveConfig(); }
|
||||
if( ImGui::InputInt( "##memorylimit", &tracy::s_config.memoryLimitPercent ) ) { tracy::s_config.memoryLimitPercent = std::clamp( tracy::s_config.memoryLimitPercent, 1, 999 ); tracy::SaveConfig(); }
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( "%" );
|
||||
if( s_totalMem != 0 )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", tracy::MemSizeToString( s_totalMem * s_config.memoryLimitPercent / 100 ) );
|
||||
ImGui::TextDisabled( "(%s)", tracy::MemSizeToString( s_totalMem * tracy::s_config.memoryLimitPercent / 100 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -797,13 +778,19 @@ static void DrawContents()
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
if( ImGui::Checkbox( "Enable achievements", &s_config.achievements ) ) SaveConfig();
|
||||
if( ImGui::Checkbox( "Enable achievements", &tracy::s_config.achievements ) ) tracy::SaveConfig();
|
||||
ImGui::Spacing();
|
||||
if( ImGui::Checkbox( "Save UI scale", &tracy::s_config.saveUserScale) ) tracy::SaveConfig();
|
||||
#ifndef __EMSCRIPTEN__
|
||||
ImGui::Spacing();
|
||||
if( ImGui::Checkbox( "Enable Tracy Assist", &tracy::s_config.llm ) ) tracy::SaveConfig();
|
||||
#endif
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::Separator();
|
||||
ImGui::PushFont( s_smallFont );
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
tracy::TextFocused( "Protocol version", tracy::RealToString( tracy::ProtocolVersion ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::SeparatorEx( ImGuiSeparatorFlags_Vertical );
|
||||
@ -908,13 +895,15 @@ static void DrawContents()
|
||||
if( s_isElevated )
|
||||
{
|
||||
ImGui::Separator();
|
||||
ImGui::TextColored( ImVec4( 1, 0.25f, 0.25f, 1 ), ICON_FA_TRIANGLE_EXCLAMATION " Profiler has elevated privileges! " ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::PushFont( s_smallFont );
|
||||
ImGui::TextColored( ImVec4( 1, 0.25f, 0.25f, 1 ), "You are running the profiler interface with admin privileges. This is" );
|
||||
ImGui::TextColored( ImVec4( 1, 0.25f, 0.25f, 1 ), "most likely a mistake, as there is no reason to do so. Instead, you" );
|
||||
ImGui::TextColored( ImVec4( 1, 0.25f, 0.25f, 1 ), "probably wanted to run the client (the application you are profiling)" );
|
||||
ImGui::TextColored( ImVec4( 1, 0.25f, 0.25f, 1 ), "with elevated privileges." );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.f, 0.25f, 0.25f, 1.f ) );
|
||||
tracy::TextCentered( ICON_FA_TRIANGLE_EXCLAMATION " Profiler has elevated privileges! " ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
tracy::TextCentered( "You are running the profiler interface with admin privileges. This is" );
|
||||
tracy::TextCentered( "most likely a mistake, as there is no reason to do so. Instead, you" );
|
||||
tracy::TextCentered( "probably wanted to run the client (the application you are profiling)" );
|
||||
tracy::TextCentered( "with elevated privileges." );
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
ImGui::Separator();
|
||||
ImGui::TextUnformatted( "Client address" );
|
||||
@ -934,7 +923,7 @@ static void DrawContents()
|
||||
{
|
||||
memcpy( addr, str.c_str(), str.size() + 1 );
|
||||
}
|
||||
if( ImGui::IsItemHovered() && ImGui::IsKeyPressed( ImGui::GetKeyIndex( ImGuiKey_Delete ), false ) )
|
||||
if( ImGui::IsItemHovered() && ImGui::IsKeyPressed( ImGuiKey_Delete, false ) )
|
||||
{
|
||||
idxRemove = (int)i;
|
||||
}
|
||||
@ -946,26 +935,42 @@ static void DrawContents()
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
ImGui::BeginDisabled();
|
||||
#endif
|
||||
connectClicked |= ImGui::Button( ICON_FA_WIFI " Connect" );
|
||||
#ifdef __EMSCRIPTEN__
|
||||
ImGui::EndDisabled();
|
||||
connectClicked = false;
|
||||
#endif
|
||||
if( connectClicked && *addr && !loadThread.joinable() )
|
||||
{
|
||||
connHist->Count( addr );
|
||||
auto aptr = addr;
|
||||
while( *aptr == ' ' || *aptr == '\t' ) aptr++;
|
||||
auto aend = aptr;
|
||||
while( *aend && *aend != ' ' && *aend != '\t' ) aend++;
|
||||
|
||||
const auto addrLen = strlen( addr );
|
||||
auto ptr = addr + addrLen - 1;
|
||||
while( ptr > addr && *ptr != ':' ) ptr--;
|
||||
if( *ptr == ':' )
|
||||
if( aptr != aend )
|
||||
{
|
||||
std::string addrPart = std::string( addr, ptr );
|
||||
uint16_t portPart = (uint16_t)atoi( ptr+1 );
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
|
||||
}
|
||||
else
|
||||
{
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, addr, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
|
||||
std::string address( aptr, aend );
|
||||
connHist->Count( address );
|
||||
|
||||
auto adata = address.data();
|
||||
auto ptr = adata + address.size() - 1;
|
||||
while( ptr > adata && *ptr != ':' ) ptr--;
|
||||
if( *ptr == ':' )
|
||||
{
|
||||
std::string addrPart = std::string( adata, ptr );
|
||||
uint16_t portPart = (uint16_t)atoi( ptr+1 );
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, addrPart.c_str(), portPart, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements );
|
||||
}
|
||||
else
|
||||
{
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, address.c_str(), port, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( s_config.memoryLimit )
|
||||
if( tracy::s_config.memoryLimit )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
tracy::TextColoredUnformatted( 0xFF00FFFF, ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
@ -985,7 +990,7 @@ static void DrawContents()
|
||||
loadThread = std::thread( [f] {
|
||||
try
|
||||
{
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, *f, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, *f, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements );
|
||||
}
|
||||
catch( const tracy::UnsupportedVersion& e )
|
||||
{
|
||||
@ -1020,7 +1025,7 @@ static void DrawContents()
|
||||
if( badVer.state != tracy::BadVersionState::Ok )
|
||||
{
|
||||
if( loadThread.joinable() ) { loadThread.join(); }
|
||||
tracy::BadVersion( badVer, s_bigFont );
|
||||
tracy::BadVersion( badVer );
|
||||
}
|
||||
|
||||
if( !clients.empty() )
|
||||
@ -1118,7 +1123,7 @@ static void DrawContents()
|
||||
}
|
||||
if( selected && !loadThread.joinable() )
|
||||
{
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, v.second.address.c_str(), v.second.port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, v.second.address.c_str(), v.second.port, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements );
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll;
|
||||
@ -1169,7 +1174,7 @@ static void DrawContents()
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushFont( s_fixedWidth );
|
||||
ImGui::PushFont( g_fonts.mono, FontNormal );
|
||||
ImGui::TextUnformatted( releaseNotes.c_str() );
|
||||
ImGui::PopFont();
|
||||
}
|
||||
@ -1208,10 +1213,12 @@ static void DrawContents()
|
||||
{
|
||||
ImGui::OpenPopup( "Loading trace..." );
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Loading trace...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
if( ImGui::BeginPopupModal( "Loading trace...", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings) )
|
||||
{
|
||||
ImGui::PushFont( s_bigFont );
|
||||
ImGui::PushFont( g_fonts.normal, FontNormal * 2.f );
|
||||
ImGui::Spacing();
|
||||
tracy::TextCentered( ICON_FA_HOURGLASS_HALF );
|
||||
ImGui::Spacing();
|
||||
ImGui::PopFont();
|
||||
|
||||
animTime += ImGui::GetIO().DeltaTime;
|
||||
@ -1287,7 +1294,7 @@ static void DrawContents()
|
||||
viewShutdown.store( ViewShutdown::False, std::memory_order_relaxed );
|
||||
if( reconnect )
|
||||
{
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, reconnectAddr.c_str(), reconnectPort, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
|
||||
view = std::make_unique<tracy::View>( RunOnMainThread, reconnectAddr.c_str(), reconnectPort, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1296,8 +1303,10 @@ static void DrawContents()
|
||||
if( ImGui::BeginPopupModal( "Capture cleanup...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
if( viewShutdown.load( std::memory_order_relaxed ) != ViewShutdown::True ) ImGui::CloseCurrentPopup();
|
||||
ImGui::PushFont( s_bigFont );
|
||||
ImGui::PushFont( g_fonts.normal, FontNormal * 2.f );
|
||||
ImGui::Spacing();
|
||||
tracy::TextCentered( ICON_FA_BROOM );
|
||||
ImGui::Spacing();
|
||||
ImGui::PopFont();
|
||||
animTime += ImGui::GetIO().DeltaTime;
|
||||
tracy::DrawWaitingDots( animTime );
|
||||
@ -1316,47 +1325,54 @@ static void DrawContents()
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if( !s_config.achievementsAsked )
|
||||
if( !tracy::s_config.achievementsAsked )
|
||||
{
|
||||
s_config.achievementsAsked = true;
|
||||
tracy::s_config.achievementsAsked = true;
|
||||
ImGui::OpenPopup( ICON_FA_STAR " Achievements" );
|
||||
}
|
||||
#endif
|
||||
|
||||
ImGui::SetNextWindowSize( ImVec2( 325 * dpiScale, 0 ) );
|
||||
if( ImGui::BeginPopupModal( ICON_FA_STAR " Achievements", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::TextUnformatted( "Tracy Profiler is a complex tool with many features. It" );
|
||||
ImGui::TextUnformatted( "can be difficult to discover all of them on your own." );
|
||||
ImGui::TextUnformatted( "The Achievements system will guide you through the" );
|
||||
ImGui::TextUnformatted( "main features and teach you how to use them in an" );
|
||||
ImGui::TextUnformatted( "easy-to-handle manner." );
|
||||
ImGui::Separator();
|
||||
ImGui::TextUnformatted( "Would you like to enable achievements?" );
|
||||
ImGui::PushFont( s_smallFont );
|
||||
constexpr const char* text = R"(
|
||||
**Tracy Profiler** is a complex tool with many features. It can be difficult to discover all of them on your own.
|
||||
|
||||
The *Achievements* system will guide you through the main features and teach you how to use them in an easy-to-handle manner. You can use this system as a **tutorial** to learn how to use Tracy Profiler.
|
||||
|
||||
---
|
||||
|
||||
Would you like to enable achievements?
|
||||
)";
|
||||
|
||||
tracy::Markdown md;
|
||||
md.Print( text, strlen( text ) );
|
||||
ImGui::Spacing();
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
tracy::TextDisabledUnformatted( "You can change this setting later in the global settings." );
|
||||
ImGui::PopFont();
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( "Yes" ) )
|
||||
{
|
||||
s_config.achievements = true;
|
||||
SaveConfig();
|
||||
tracy::s_config.achievements = true;
|
||||
tracy::SaveConfig();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( "No" ) )
|
||||
{
|
||||
s_config.achievements = false;
|
||||
SaveConfig();
|
||||
tracy::s_config.achievements = false;
|
||||
tracy::SaveConfig();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if( s_config.achievements )
|
||||
if( tracy::s_config.achievements )
|
||||
{
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 16 * dpiScale );
|
||||
|
||||
ImGui::PushFont( s_bigFont );
|
||||
ImGui::PushFont( g_fonts.normal, FontBig );
|
||||
const auto starSize = ImGui::CalcTextSize( ICON_FA_STAR );
|
||||
ImGui::PopFont();
|
||||
|
||||
@ -1433,7 +1449,7 @@ static void DrawContents()
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::PushFont( s_bigFont );
|
||||
ImGui::PushFont( g_fonts.normal, FontBig );
|
||||
tracy::TextColoredUnformatted( color, ICON_FA_STAR );
|
||||
ImGui::PopFont();
|
||||
|
||||
@ -1444,7 +1460,7 @@ static void DrawContents()
|
||||
const auto th = ImGui::GetTextLineHeight();
|
||||
ImGui::SetCursorPosY( cursor.y - th * 0.175f );
|
||||
ImGui::TextUnformatted( aItem->name );
|
||||
ImGui::PushFont( s_smallFont );
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::SetCursorPos( cursor + ImVec2( starSize.x + ImGui::GetStyle().ItemSpacing.x, th ) );
|
||||
tracy::TextDisabledUnformatted( "Click to open" );
|
||||
ImGui::PopFont();
|
||||
@ -1504,11 +1520,7 @@ static void DrawContents()
|
||||
ImGui::SetColumnWidth( 0, 300 * dpiScale );
|
||||
DrawAchievements( c->items );
|
||||
ImGui::NextColumn();
|
||||
if( s_achievementItem )
|
||||
{
|
||||
const tracy::data::ctx ctx = { s_bigFont, s_smallFont, s_fixedWidth };
|
||||
s_achievementItem->description( ctx );
|
||||
}
|
||||
if( s_achievementItem ) s_achievementItem->description();
|
||||
ImGui::EndColumns();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
@ -3,15 +3,16 @@
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracySourceContents.hpp"
|
||||
#include "TracyWeb.hpp"
|
||||
#include "../Fonts.hpp"
|
||||
|
||||
namespace tracy::data
|
||||
{
|
||||
|
||||
AchievementItem ai_samplingIntro = { "samplingIntro", "Sampling program execution", [](const ctx& c){
|
||||
AchievementItem ai_samplingIntro = { "samplingIntro", "Sampling program execution", [](){
|
||||
ImGui::TextWrapped( "Sampling program execution is a great way to find out where the hot spots are in your program. It can be used to find out which functions take the most time, or which lines of code are executed the most often." );
|
||||
ImGui::TextWrapped( "While instrumentation requires changes to your code, sampling does not. However, because of the way it works, the results are coarser and it's not possible to know when functions are called or when they return." );
|
||||
ImGui::TextWrapped( "Sampling is automatic on Linux. On Windows, you must run the profiled application as an administrator for it to work." );
|
||||
ImGui::PushFont( c.small );
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::TextWrapped( "Depending on your system configuration, some additional steps may be required. Please refer to the user manual for more information." );
|
||||
ImGui::PopStyleColor();
|
||||
@ -22,11 +23,11 @@ AchievementItem* ac_samplingItems[] = { &ai_samplingIntro, nullptr };
|
||||
AchievementCategory ac_sampling = { "sampling", "Sampling", ac_samplingItems };
|
||||
|
||||
|
||||
AchievementItem ai_100million = { "100million", "It's over 100 million!", [](const ctx& c){
|
||||
AchievementItem ai_100million = { "100million", "It's over 100 million!", [](){
|
||||
ImGui::TextWrapped( "Tracy can handle a lot of data. How about 100 million zones in a single trace? Add a lot of zones to your program and see how it handles it!" );
|
||||
ImGui::TextWrapped( "Capturing a long-running profile trace is easy. Need to profile an hour of your program execution? You can do it." );
|
||||
ImGui::TextWrapped( "Note that it doesn't make much sense to instrument every little function you might have. The cost of the instrumentation itself will be higher than the cost of the function in such a case." );
|
||||
ImGui::PushFont( c.small );
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::TextWrapped( "Keep in mind that the more zones you have, the more memory and CPU time the profiler will use. Be careful not to run out of memory." );
|
||||
ImGui::TextWrapped( "To capture 100 million zones, you will need approximately 4 GB of RAM." );
|
||||
@ -34,12 +35,12 @@ AchievementItem ai_100million = { "100million", "It's over 100 million!", [](con
|
||||
ImGui::PopFont();
|
||||
} };
|
||||
|
||||
AchievementItem ai_instrumentationStatistics = { "instrumentationStatistics", "Show me the stats!", [](const ctx&){
|
||||
AchievementItem ai_instrumentationStatistics = { "instrumentationStatistics", "Show me the stats!", [](){
|
||||
ImGui::TextWrapped( "Once you have instrumented your application, you can view the statistics for each zone in the timeline. This allows you to see how much time is spent in each zone and how many times it is called." );
|
||||
ImGui::TextWrapped( "To view the statistics, click on the \"" ICON_FA_ARROW_UP_WIDE_SHORT " Statistics\" button on the top bar. This will open a new window with a list of all zones in the trace." );
|
||||
} };
|
||||
|
||||
AchievementItem ai_findZone = { "findZone", "Find some zones", [](const ctx&){
|
||||
AchievementItem ai_findZone = { "findZone", "Find some zones", [](){
|
||||
ImGui::TextWrapped( "You can search for zones in the trace by opening the search window with the \"" ICON_FA_MAGNIFYING_GLASS " Find zone\" button on the top bar. It will ask you for the zone name, which in most cases will be the function name in the code." );
|
||||
ImGui::TextWrapped( "The search may find more than one zone with the same name. A list of all the zones found is displayed, and you can select any of them." );
|
||||
ImGui::TextWrapped( "Alternatively, you can open the Statistics window and click an entry there. This will open the Find zone window as if you had searched for that zone." );
|
||||
@ -54,7 +55,7 @@ AchievementItem* ac_instrumentationIntroItems[] = {
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_instrumentationIntro = { "instrumentationIntro", "Instrumentating your application", [](const ctx& c){
|
||||
AchievementItem ai_instrumentationIntro = { "instrumentationIntro", "Instrumentating your application", [](){
|
||||
constexpr const char* src = R"(#include "Tracy.hpp"
|
||||
|
||||
void SomeFunction()
|
||||
@ -69,11 +70,11 @@ void SomeFunction()
|
||||
|
||||
ImGui::TextWrapped( "Instrumentation is a powerful feature that allows you to see the exact runtime of each call to the selected set of functions. The downside is that it takes a bit of manual work to get it set up." );
|
||||
ImGui::TextWrapped( "To get started, open a source file and include the Tracy.hpp header. This will give you access to a variety of macros provided by Tracy. Next, add the ZoneScoped macro to the beginning of one of your functions, like this:" );
|
||||
ImGui::PushFont( c.fixed );
|
||||
ImGui::PushFont( g_fonts.mono, FontNormal );
|
||||
PrintSource( sc.get() );
|
||||
ImGui::PopFont();
|
||||
ImGui::TextWrapped( "Now, when you profile your application, you will see a new zone appear on the timeline for each call to the function. This allows you to see how much time is spent in each call and how many times the function is called." );
|
||||
ImGui::PushFont( c.small );
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::TextWrapped( "Note: The ZoneScoped macro is just one of the many macros provided by Tracy. See the documentation for more information." );
|
||||
ImGui::TextWrapped( "The above description applies to C++ code, but things are done similarly in other programming languages. Refer to the documentation for your language for more information." );
|
||||
@ -81,7 +82,7 @@ void SomeFunction()
|
||||
ImGui::PopFont();
|
||||
}, ac_instrumentationIntroItems };
|
||||
|
||||
AchievementItem ai_frameImages = { "frameImages", "A picture is worth a thousand words", [](const ctx&){
|
||||
AchievementItem ai_frameImages = { "frameImages", "A picture is worth a thousand words", [](){
|
||||
ImGui::TextWrapped( "Tracy allows you to add context to each frame, by attaching a screenshot. You can do this with the FrameImage macro." );
|
||||
ImGui::TextWrapped( "You will have to do the screen capture and resizing yourself, which can be a bit complicated. The manual provides a sample code that shows how to do this in a performant way." );
|
||||
ImGui::TextWrapped( "The frame images are displayed in the context of a frame, for example, when you hover over the frame in the timeline or in the frame graph at the top of the screen." );
|
||||
@ -94,7 +95,7 @@ AchievementItem* ac_instrumentFramesItems[] = {
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_instrumentFrames = { "instrumentFrames", "Instrumenting frames", [](const ctx& c){
|
||||
AchievementItem ai_instrumentFrames = { "instrumentFrames", "Instrumenting frames", [](){
|
||||
constexpr const char* src = R"(#include "Tracy.hpp"
|
||||
|
||||
void Render()
|
||||
@ -110,7 +111,7 @@ void Render()
|
||||
|
||||
ImGui::TextWrapped( "In addition to instrumenting functions, you can also instrument frames. This allows you to see how much time is spent in each frame of your application." );
|
||||
ImGui::TextWrapped( "To instrument frames, you need to add the FrameMark macro at the beginning of each frame. This can be done in the main loop of your application, or in a separate function that is called at the beginning of each frame." );
|
||||
ImGui::PushFont( c.fixed );
|
||||
ImGui::PushFont( g_fonts.mono, FontNormal );
|
||||
PrintSource( sc.get() );
|
||||
ImGui::PopFont();
|
||||
ImGui::TextWrapped( "When you profile your application, you will see a new frame appear on the timeline each time the FrameMark macro is called. This allows you to see how much time is spent in each frame and how many frames are rendered per second." );
|
||||
@ -122,11 +123,11 @@ AchievementItem* ac_instrumentationItems[] = { &ai_instrumentationIntro, &ai_ins
|
||||
AchievementCategory ac_instrumentation = { "instrumentation", "Instrumentation", ac_instrumentationItems };
|
||||
|
||||
|
||||
AchievementItem ai_loadTrace = { "loadTrace", "Load a trace", [](const ctx&){
|
||||
AchievementItem ai_loadTrace = { "loadTrace", "Load a trace", [](){
|
||||
ImGui::TextWrapped( "You can open a previously saved trace file (or one received from a friend) with the \"" ICON_FA_FOLDER_OPEN " Open saved trace\" button on the welcome screen." );
|
||||
} };
|
||||
|
||||
AchievementItem ai_saveTrace = { "saveTrace", "Save a trace", [](const ctx&){
|
||||
AchievementItem ai_saveTrace = { "saveTrace", "Save a trace", [](){
|
||||
ImGui::TextWrapped( "Now that you have traced your application (or are in the process of doing so), you can save it to disk for future reference. You can do this by clicking on the " ICON_FA_WIFI " icon in the top left corner of the screen and then clicking on the \"" ICON_FA_FLOPPY_DISK " Save trace\" button." );
|
||||
ImGui::TextWrapped( "Keeping old traces on hand can be beneficial, as you can compare the performance of your optimizations with what you had before." );
|
||||
ImGui::TextWrapped( "You can also share the trace with your friends or co-workers by sending them the trace file." );
|
||||
@ -151,7 +152,7 @@ AchievementItem* ac_connectToServerUnlock[] = {
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_connectToServer = { "connectToClient", "First profiling session", [](const ctx&){
|
||||
AchievementItem ai_connectToServer = { "connectToClient", "First profiling session", [](){
|
||||
ImGui::TextWrapped( "Let's start our adventure by instrumenting your application and connecting it to the profiler. Here's a quick refresher:" );
|
||||
ImGui::TextWrapped( " 1. Integrate Tracy Profiler into your application. This can be done using CMake, Meson, or simply by adding the source files to your project." );
|
||||
ImGui::TextWrapped( " 2. Make sure that TracyClient.cpp (or the Tracy library) is included in your build." );
|
||||
@ -164,7 +165,7 @@ AchievementItem ai_connectToServer = { "connectToClient", "First profiling sessi
|
||||
}
|
||||
}, ac_connectToServerItems, ac_connectToServerUnlock };
|
||||
|
||||
AchievementItem ai_globalSettings = { "globalSettings", "Global settings", [](const ctx&){
|
||||
AchievementItem ai_globalSettings = { "globalSettings", "Global settings", [](){
|
||||
ImGui::TextWrapped( "Tracy has a variety of settings that can be adjusted to suit your needs. These settings can be found by clicking on the " ICON_FA_WRENCH " icon on the welcome screen. This will open the about window, where you can expand the \"" ICON_FA_TOOLBOX " Global settings\" menu." );
|
||||
ImGui::TextWrapped( "The settings are saved between sessions, so you only need to set them once." );
|
||||
} };
|
||||
@ -175,7 +176,7 @@ AchievementItem* ac_achievementsIntroItems[] = {
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_achievementsIntro = { "achievementsIntro", "Click here to discover achievements!", [](const ctx&){
|
||||
AchievementItem ai_achievementsIntro = { "achievementsIntro", "Click here to discover achievements!", [](){
|
||||
ImGui::TextWrapped( "Clicking on the " ICON_FA_STAR " button opens the Achievements List. Here you can see the tasks to be completed along with a short description of what needs to be done." );
|
||||
ImGui::TextWrapped( "As you complete each Achievement, new Achievements will appear, so be sure to keep checking the list for new ones!" );
|
||||
ImGui::TextWrapped( "To make the new things easier to spot, the Achievements List will show a marker next to them. The achievements " ICON_FA_STAR " button will glow yellow when there are new things to see." );
|
||||
|
||||
@ -16,18 +16,11 @@ namespace tracy
|
||||
namespace data
|
||||
{
|
||||
|
||||
struct ctx
|
||||
{
|
||||
ImFont* big;
|
||||
ImFont* small;
|
||||
ImFont* fixed;
|
||||
};
|
||||
|
||||
struct AchievementItem
|
||||
{
|
||||
const char* id;
|
||||
const char* name;
|
||||
void(*description)(const ctx&);
|
||||
void(*description)();
|
||||
AchievementItem** items;
|
||||
AchievementItem** unlocks;
|
||||
bool keepOpen;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "../Fonts.hpp"
|
||||
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "TracyBadVersion.hpp"
|
||||
@ -13,7 +14,7 @@ namespace tracy
|
||||
namespace detail
|
||||
{
|
||||
|
||||
void BadVersionImpl( BadVersionState& badVer, ImFont* big )
|
||||
void BadVersionImpl( BadVersionState& badVer )
|
||||
{
|
||||
assert( badVer.state != BadVersionState::Ok );
|
||||
|
||||
@ -40,7 +41,7 @@ void BadVersionImpl( BadVersionState& badVer, ImFont* big )
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Bad file", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
ImGui::PushFont( g_fonts.normal, FontBig );
|
||||
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "The file you are trying to open is not a Tracy dump." );
|
||||
@ -54,7 +55,7 @@ void BadVersionImpl( BadVersionState& badVer, ImFont* big )
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "File read error", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
ImGui::PushFont( g_fonts.normal, FontBig );
|
||||
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "The file you are trying to open cannot be mapped to memory." );
|
||||
@ -68,7 +69,7 @@ void BadVersionImpl( BadVersionState& badVer, ImFont* big )
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Unsupported file version", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
ImGui::PushFont( g_fonts.normal, FontBig );
|
||||
TextCentered( ICON_FA_CLOUD_ARROW_DOWN );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "The file you are trying to open is unsupported.\nYou should update to Tracy %i.%i.%i or newer and try again.", badVer.version >> 16, ( badVer.version >> 8 ) & 0xFF, badVer.version & 0xFF );
|
||||
@ -89,7 +90,7 @@ void BadVersionImpl( BadVersionState& badVer, ImFont* big )
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Legacy file version", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
ImGui::PushFont( g_fonts.normal, FontBig );
|
||||
TextCentered( ICON_FA_GHOST );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "You are trying to open a file which was created by legacy version %i.%i.%i.\nUse the update utility from an older version of the profiler to convert the file to a supported version.", badVer.version >> 16, ( badVer.version >> 8 ) & 0xFF, badVer.version & 0xFF );
|
||||
@ -103,7 +104,7 @@ void BadVersionImpl( BadVersionState& badVer, ImFont* big )
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Trace load failure", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
ImGui::PushFont( g_fonts.normal, FontBig );
|
||||
TextCentered( ICON_FA_BOMB );
|
||||
ImGui::PopFont();
|
||||
ImGui::TextUnformatted( "The file you are trying to open is corrupted." );
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
|
||||
struct ImFont;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
@ -29,10 +27,10 @@ struct BadVersionState
|
||||
|
||||
namespace detail
|
||||
{
|
||||
void BadVersionImpl( BadVersionState& badVer, ImFont* big );
|
||||
void BadVersionImpl( BadVersionState& badVer );
|
||||
}
|
||||
|
||||
tracy_force_inline void BadVersion( BadVersionState& badVer, ImFont* big ) { if( badVer.state != BadVersionState::Ok ) detail::BadVersionImpl( badVer, big ); }
|
||||
tracy_force_inline void BadVersion( BadVersionState& badVer ) { if( badVer.state != BadVersionState::Ok ) detail::BadVersionImpl( badVer ); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,14 @@ static tracy_force_inline uint32_t HighlightColor( uint32_t color )
|
||||
( std::min<int>( 0xFF, ( ( ( color & 0x000000FF ) ) + V ) ) );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint32_t DarkenColorSlightly( uint32_t color )
|
||||
{
|
||||
return 0xFF000000 |
|
||||
( ( ( ( color & 0x00FF0000 ) >> 16 ) * 4 / 5 ) << 16 ) |
|
||||
( ( ( ( color & 0x0000FF00 ) >> 8 ) * 4 / 5 ) << 8 ) |
|
||||
( ( ( ( color & 0x000000FF ) ) * 4 / 5 ) );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint32_t DarkenColor( uint32_t color )
|
||||
{
|
||||
return 0xFF000000 |
|
||||
@ -28,6 +36,14 @@ static tracy_force_inline uint32_t DarkenColor( uint32_t color )
|
||||
( ( ( ( color & 0x000000FF ) ) * 2 / 3 ) );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint32_t DarkenColorHalf( uint32_t color )
|
||||
{
|
||||
return 0xFF000000 |
|
||||
( ( ( ( color & 0x00FF0000 ) >> 16 ) / 2 ) << 16 ) |
|
||||
( ( ( ( color & 0x0000FF00 ) >> 8 ) / 2 ) << 8 ) |
|
||||
( ( ( ( color & 0x000000FF ) ) / 2 ) );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint32_t DarkenColorMore( uint32_t color )
|
||||
{
|
||||
return 0xFF000000 |
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user