usunięcie nieużywanej biblioteki, Debug i Release
This commit is contained in:
parent
dbf084d5b1
commit
b89c7784ca
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,26 +0,0 @@
|
|||||||
d:\studia\planeta\grk\cw 6\debug\vc143.pdb
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\vc143.idb
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\texture.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\shader_loader.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\render_utils.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\main.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\camera.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\stb_image_aug.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\soil.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\image_helper.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\image_dxt.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\box.obj
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\vc142.idb
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\vc142.pdb
|
|
||||||
d:\studia\planeta\grk\debug\planeta.pdb
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\cl.command.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\cl.items.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\cl.read.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\cl.write.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\link-cvtres.read.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\link-cvtres.write.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\link-rc.read.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\link-rc.write.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\link.command.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\link.read.1.tlog
|
|
||||||
d:\studia\planeta\grk\cw 6\debug\planeta.tlog\link.write.1.tlog
|
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project>
|
|
||||||
<ProjectOutputs>
|
|
||||||
<ProjectOutput>
|
|
||||||
<FullPath>D:\grk2024\dgrk-2023-planeta\grk\Debug\grk-cw6.exe</FullPath>
|
|
||||||
</ProjectOutput>
|
|
||||||
</ProjectOutputs>
|
|
||||||
<ContentFiles />
|
|
||||||
<SatelliteDlls />
|
|
||||||
<NonRecipeFileRefs />
|
|
||||||
</Project>
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +0,0 @@
|
|||||||
D:\STUDIA\Planeta\grk\cw 6\src\Camera.cpp;D:\STUDIA\Planeta\grk\cw 6\Debug\Camera.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\main.cpp;D:\STUDIA\Planeta\grk\cw 6\Debug\main.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\Render_Utils.cpp;D:\STUDIA\Planeta\grk\cw 6\Debug\Render_Utils.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\Shader_Loader.cpp;D:\STUDIA\Planeta\grk\cw 6\Debug\Shader_Loader.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\SOIL\image_DXT.c;D:\STUDIA\Planeta\grk\cw 6\Debug\image_DXT.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\SOIL\image_helper.c;D:\STUDIA\Planeta\grk\cw 6\Debug\image_helper.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\SOIL\SOIL.c;D:\STUDIA\Planeta\grk\cw 6\Debug\SOIL.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\SOIL\stb_image_aug.c;D:\STUDIA\Planeta\grk\cw 6\Debug\stb_image_aug.obj
|
|
||||||
D:\STUDIA\Planeta\grk\cw 6\src\Texture.cpp;D:\STUDIA\Planeta\grk\cw 6\Debug\Texture.obj
|
|
@ -1,2 +0,0 @@
|
|||||||
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.38.33130:TargetPlatformVersion=10.0.22000.0:
|
|
||||||
Debug|Win32|D:\STUDIA\Planeta\grk\|
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,41 +0,0 @@
|
|||||||
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(491,5): warning MSB8028: Katalog pośredni (Debug\) zawiera pliki udostępnione z innego projektu (grk-cw3.vcxproj, grk-cw4.vcxproj, grk-cw5.vcxproj). Może to spowodować niepoprawne zachowanie podczas oczyszczania i ponownej kompilacji.
|
|
||||||
main.cpp
|
|
||||||
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(73,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(125,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(161,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(266,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(273,52): warning C4305: "argument": obcięcie z "double" do "T"
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(277,50): warning C4305: "argument": obcięcie z "double" do "T"
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(281,49): warning C4305: "argument": obcięcie z "double" do "T"
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(285,48): warning C4305: "argument": obcięcie z "double" do "T"
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(289,48): warning C4305: "argument": obcięcie z "double" do "T"
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
D:\grk2024\dgrk-2023-planeta\grk\cw 6\src\ex_6_1.hpp(293,48): warning C4305: "argument": obcięcie z "double" do "T"
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
Box.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
|
|
||||||
LINK : warning LNK4098: domyślna biblioteka „MSVCRT” powoduje konflikt z innymi bibliotekami; użyj opcji /NODEFAULTLIB:biblioteka
|
|
||||||
grk-cw6.vcxproj -> D:\grk2024\dgrk-2023-planeta\grk\Debug\grk-cw6.exe
|
|
@ -1 +0,0 @@
|
|||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project>
|
|
||||||
<ProjectOutputs>
|
|
||||||
<ProjectOutput>
|
|
||||||
<FullPath>j:\Downloads\grk\Release\grk-cw6.exe</FullPath>
|
|
||||||
</ProjectOutput>
|
|
||||||
</ProjectOutputs>
|
|
||||||
<ContentFiles />
|
|
||||||
<SatelliteDlls />
|
|
||||||
<NonRecipeFileRefs />
|
|
||||||
</Project>
|
|
Binary file not shown.
Binary file not shown.
@ -1,41 +0,0 @@
|
|||||||
main.cpp
|
|
||||||
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition
|
|
||||||
j:\Downloads\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY'
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(95,16): warning C4305: 'initializing': truncation from 'double' to 'float'
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(138,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(142,52): warning C4305: 'argument': truncation from 'double' to 'T'
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(146,50): warning C4305: 'argument': truncation from 'double' to 'T'
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(150,49): warning C4305: 'argument': truncation from 'double' to 'T'
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(154,48): warning C4305: 'argument': truncation from 'double' to 'T'
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(158,48): warning C4305: 'argument': truncation from 'double' to 'T'
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
j:\Downloads\grk\cw 6\src\ex_6_1.hpp(162,48): warning C4305: 'argument': truncation from 'double' to 'T'
|
|
||||||
with
|
|
||||||
[
|
|
||||||
T=float
|
|
||||||
]
|
|
||||||
Generating code
|
|
||||||
0 of 502 functions ( 0.0%) were compiled, the rest were copied from previous compilation.
|
|
||||||
0 functions were new in current compilation
|
|
||||||
0 functions had inline decision re-evaluated but remain unchanged
|
|
||||||
Finished generating code
|
|
||||||
grk-cw6.vcxproj -> j:\Downloads\grk\Release\grk-cw6.exe
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
|
|
||||||
Release|Win32|j:\Downloads\grk\|
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,28 +0,0 @@
|
|||||||
# See http://editorconfig.org to read about the EditorConfig format.
|
|
||||||
# - In theory automatically supported by VS2017+ and most common IDE or text editors.
|
|
||||||
# - In practice VS2019-VS2022 stills don't trim trailing whitespaces correctly :(
|
|
||||||
# - Suggest installing this to trim whitespaces:
|
|
||||||
# GitHub https://github.com/madskristensen/TrailingWhitespace
|
|
||||||
# VS2019 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespaceVisualizer
|
|
||||||
# VS2022 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespace64
|
|
||||||
# (in spite of its name doesn't only visualize but also trims)
|
|
||||||
# - Alternative for older VS2010 to VS2015: https://marketplace.visualstudio.com/items?itemName=EditorConfigTeam.EditorConfig
|
|
||||||
|
|
||||||
# top-most EditorConfig file
|
|
||||||
root = true
|
|
||||||
|
|
||||||
# Default settings:
|
|
||||||
# Use 4 spaces as indentation
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
insert_final_newline = true
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
|
|
||||||
[imstb_*]
|
|
||||||
indent_size = 3
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
||||||
[Makefile]
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 4
|
|
30
grk/cw 6/src/imgui-master/.gitattributes
vendored
30
grk/cw 6/src/imgui-master/.gitattributes
vendored
@ -1,30 +0,0 @@
|
|||||||
* text=auto
|
|
||||||
|
|
||||||
*.c text
|
|
||||||
*.cpp text
|
|
||||||
*.h text
|
|
||||||
*.m text
|
|
||||||
*.mm text
|
|
||||||
*.md text
|
|
||||||
*.txt text
|
|
||||||
*.html text
|
|
||||||
*.bat text
|
|
||||||
*.frag text
|
|
||||||
*.vert text
|
|
||||||
*.mkb text
|
|
||||||
*.icf text
|
|
||||||
|
|
||||||
*.sln text eol=crlf
|
|
||||||
*.vcxproj text eol=crlf
|
|
||||||
*.vcxproj.filters text eol=crlf
|
|
||||||
*.natvis text eol=crlf
|
|
||||||
|
|
||||||
Makefile text eol=lf
|
|
||||||
*.sh text eol=lf
|
|
||||||
*.pbxproj text eol=lf
|
|
||||||
*.storyboard text eol=lf
|
|
||||||
*.plist text eol=lf
|
|
||||||
|
|
||||||
*.png binary
|
|
||||||
*.ttf binary
|
|
||||||
*.lib binary
|
|
@ -1 +0,0 @@
|
|||||||
custom: ['https://github.com/ocornut/imgui/wiki/Sponsors']
|
|
@ -1 +0,0 @@
|
|||||||
blank_issues_enabled: false
|
|
@ -1,90 +0,0 @@
|
|||||||
name: "Ask a question, report a bug, request a feature, etc."
|
|
||||||
description: "Ask any question, discuss best practices, report a bug, request a feature."
|
|
||||||
body:
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING or LOADING FONTS, please use [GitHub Discussions](https://github.com/ocornut/imgui/discussions)
|
|
||||||
For anything else: we are happy to use 'GitHub Issues' for many types of open-ended questions. We are encouraging 'Issues' becoming a large, centralized and cross-referenced database of Dear ImGui contents.
|
|
||||||
|
|
||||||
Be mindful that messages are being sent to the e-mail box of "Watching" users. Try to proof-read your messages before sending them. Edits are not seen by those users.
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
**Prerequisites:**
|
|
||||||
- I have read [Frequently Asked Questions](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md).
|
|
||||||
- I have read [Contributing Guidelines -> General Advices](https://github.com/ocornut/imgui/blob/master/docs/CONTRIBUTING.md#getting-started--general-advice).
|
|
||||||
- I have read [Contributing Guidelines -> How to open an Issue](https://github.com/ocornut/imgui/blob/master/docs/CONTRIBUTING.md#how-to-open-an-issue).
|
|
||||||
- I have searched [Github Issues and PR](https://github.com/ocornut/imgui/issues?q=) for discussion of similar topics.
|
|
||||||
|
|
||||||
----
|
|
||||||
- type: input
|
|
||||||
id: specs_version
|
|
||||||
attributes:
|
|
||||||
label: "Version/Branch of Dear ImGui:"
|
|
||||||
description: "(please specify if you have made substantial modifications to your copy)"
|
|
||||||
value: "Version 1.XX, Branch: XXX (master/docking/etc.)"
|
|
||||||
placeholder: "Version 1.XX, Branch: XXX (master/docking/etc.)"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: input
|
|
||||||
id: specs_backend
|
|
||||||
attributes:
|
|
||||||
label: "Back-ends:"
|
|
||||||
description: (or specify when using custom engine/back-ends)
|
|
||||||
value: "imgui_impl_XXX.cpp + imgui_impl_XXX.cpp"
|
|
||||||
placeholder: "imgui_impl_XXX.cpp + imgui_impl_XXX.cpp or n/a"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: input
|
|
||||||
id: specs_compiler_os
|
|
||||||
attributes:
|
|
||||||
label: "Compiler, OS:"
|
|
||||||
placeholder: "e.g. Windows 11 + MSVC 2022, macOS + Clang 12, Linux + GCC etc."
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
id: specs_full
|
|
||||||
attributes:
|
|
||||||
label: "Full config/build information:"
|
|
||||||
placeholder: |
|
|
||||||
(If you can run, you may go to 'Demo->Tools->About Dear ImGui->Config/Build Info' to obtain detailed information that you can paste here)
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: textarea
|
|
||||||
id: issue_description
|
|
||||||
attributes:
|
|
||||||
label: "Details:"
|
|
||||||
description: "Try to be explicit with your goals, your expectations and what you have tried. Be mindful of [The XY Problem](https://xyproblem.info). What you have in mind or in your code is not obvious to other people. People frequently discuss problems and suggest incorrect solutions without first clarifying their goals. When requesting a new feature, please describe the usage context (how you intend to use it, why you need it, etc.). If you tried something and it failed, show us what you tried. If you are reporting a bug, explain what's the bug, how does it occur, etc. If you are reporting a crash, please include a debugger callstack."
|
|
||||||
value: |
|
|
||||||
**My Issue/Question:**
|
|
||||||
|
|
||||||
XXX _(please provide as much context as possible)_
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
id: screenshots
|
|
||||||
attributes:
|
|
||||||
label: "Screenshots/Video:"
|
|
||||||
description: "Attach screenshots or gif/videos to clarify the context. They often convey useful information that is omitted by the description."
|
|
||||||
placeholder: "(You can drag files here)"
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: textarea
|
|
||||||
id: repro_code
|
|
||||||
attributes:
|
|
||||||
label: "Minimal, Complete and Verifiable Example code:"
|
|
||||||
description: "Provide an [MCVE](https://stackoverflow.com/help/mcve) to demonstrate your problem. An ideal submission includes a small piece of code that anyone can paste into one of the examples applications (examples/*/main.cpp) or the demo (imgui_demo.cpp) to understand and reproduce it. Narrowing your problem to its shortest and purest form is the easiest way to understand it, explain it and fix it. Please test your shortened code to ensure it exhibits the problem. Often while creating the MCVE you will solve the problem! Many questions that are missing a standalone verifiable example are missing the actual cause of their issue in the description, which ends up wasting everyone's time."
|
|
||||||
value: |
|
|
||||||
```cpp
|
|
||||||
// Here's some code anyone can copy and paste to reproduce your issue
|
|
||||||
ImGui::Begin("Example Bug");
|
|
||||||
MoreCodeToExplainMyIssue();
|
|
||||||
ImGui::End();
|
|
||||||
```
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Thank you for taking the time to read prerequisites, filling this template and double-checking your message and your code!
|
|
@ -1,6 +0,0 @@
|
|||||||
(Click "Preview" to turn any http URL into a clickable link)
|
|
||||||
|
|
||||||
1. PLEASE CAREFULLY READ: [Contributing Guidelines](https://github.com/ocornut/imgui/blob/master/docs/CONTRIBUTING.md)
|
|
||||||
|
|
||||||
2. Clear this template before submitting your PR.
|
|
||||||
|
|
@ -1,507 +0,0 @@
|
|||||||
name: build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
workflow_run:
|
|
||||||
# Use a workflow as a trigger of scheduled builds. Forked repositories can disable scheduled builds by disabling
|
|
||||||
# "scheduled" workflow, while maintaining ability to perform local CI builds.
|
|
||||||
workflows:
|
|
||||||
- scheduled
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- docking
|
|
||||||
types:
|
|
||||||
- requested
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
Windows:
|
|
||||||
runs-on: windows-2019
|
|
||||||
env:
|
|
||||||
VS_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\
|
|
||||||
MSBUILD_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
shell: powershell
|
|
||||||
run: |
|
|
||||||
Invoke-WebRequest -Uri "https://www.libsdl.org/release/SDL2-devel-2.26.3-VC.zip" -OutFile "SDL2-devel-2.26.3-VC.zip"
|
|
||||||
Expand-Archive -Path SDL2-devel-2.26.3-VC.zip
|
|
||||||
echo "SDL2_DIR=$(pwd)\SDL2-devel-2.26.3-VC\SDL2-2.26.3\" >>${env:GITHUB_ENV}
|
|
||||||
|
|
||||||
Invoke-WebRequest -Uri "https://github.com/ocornut/imgui/files/3789205/vulkan-sdk-1.1.121.2.zip" -OutFile vulkan-sdk-1.1.121.2.zip
|
|
||||||
Expand-Archive -Path vulkan-sdk-1.1.121.2.zip
|
|
||||||
echo "VULKAN_SDK=$(pwd)\vulkan-sdk-1.1.121.2\" >>${env:GITHUB_ENV}
|
|
||||||
|
|
||||||
- name: Fix Projects
|
|
||||||
shell: powershell
|
|
||||||
run: |
|
|
||||||
# CI workers do not supporter older Visual Studio versions. Fix projects to target newer available version.
|
|
||||||
gci -recurse -filter "*.vcxproj" | ForEach-Object {
|
|
||||||
(Get-Content $_.FullName) -Replace "<PlatformToolset>v\d{3}</PlatformToolset>","<PlatformToolset>v142</PlatformToolset>" | Set-Content -Path $_.FullName
|
|
||||||
(Get-Content $_.FullName) -Replace "<WindowsTargetPlatformVersion>[\d\.]+</WindowsTargetPlatformVersion>","<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>" | Set-Content -Path $_.FullName
|
|
||||||
}
|
|
||||||
|
|
||||||
# Not using matrix here because it would inflate job count too much. Check out and setup is done for every job and that makes build times way too long.
|
|
||||||
- name: Build example_null (extra warnings, mingw 64-bit)
|
|
||||||
run: mingw32-make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
|
||||||
|
|
||||||
- name: Build example_null (mingw 64-bit, as DLL)
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo '#ifdef _EXPORT' > example_single_file.cpp
|
|
||||||
echo '# define IMGUI_API __declspec(dllexport)' >> example_single_file.cpp
|
|
||||||
echo '#else' >> example_single_file.cpp
|
|
||||||
echo '# define IMGUI_API __declspec(dllimport)' >> example_single_file.cpp
|
|
||||||
echo '#endif' >> example_single_file.cpp
|
|
||||||
echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp
|
|
||||||
echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp
|
|
||||||
g++ -I. -Wall -Wformat -D_EXPORT -shared -o libimgui.dll -Wl,--out-implib,libimgui.a example_single_file.cpp -limm32
|
|
||||||
g++ -I. -Wall -Wformat -o example_null.exe examples/example_null/main.cpp -L. -limgui
|
|
||||||
rm -f example_null.exe libimgui.* example_single_file.*
|
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, msvc 64-bit)
|
|
||||||
shell: cmd
|
|
||||||
run: |
|
|
||||||
cd examples\example_null
|
|
||||||
call "%VS_PATH%\VC\Auxiliary\Build\vcvars64.bat"
|
|
||||||
.\build_win32.bat /W4
|
|
||||||
|
|
||||||
- name: Build example_null (single file build)
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -Wall -Wformat -o example_single_file.exe example_single_file.cpp -limm32
|
|
||||||
|
|
||||||
- name: Build example_null (with IMGUI_DISABLE_WIN32_FUNCTIONS)
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_DISABLE_WIN32_FUNCTIONS
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -Wall -Wformat -o example_single_file.exe example_single_file.cpp -limm32
|
|
||||||
|
|
||||||
- name: Build example_null (as DLL)
|
|
||||||
shell: cmd
|
|
||||||
run: |
|
|
||||||
call "%VS_PATH%\VC\Auxiliary\Build\vcvars64.bat"
|
|
||||||
|
|
||||||
echo #ifdef _EXPORT > example_single_file.cpp
|
|
||||||
echo # define IMGUI_API __declspec(dllexport) >> example_single_file.cpp
|
|
||||||
echo #else >> example_single_file.cpp
|
|
||||||
echo # define IMGUI_API __declspec(dllimport) >> example_single_file.cpp
|
|
||||||
echo #endif >> example_single_file.cpp
|
|
||||||
echo #define IMGUI_IMPLEMENTATION >> example_single_file.cpp
|
|
||||||
echo #include "misc/single_file/imgui_single_file.h" >> example_single_file.cpp
|
|
||||||
|
|
||||||
cl.exe /D_USRDLL /D_WINDLL /D_EXPORT /I. example_single_file.cpp /LD /FeImGui.dll /link
|
|
||||||
cl.exe /I. ImGui.lib /Feexample_null.exe examples/example_null/main.cpp
|
|
||||||
|
|
||||||
- name: Build Win32 example_glfw_opengl2
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
|
|
||||||
- name: Build Win32 example_glfw_opengl3
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build Win32 example_glfw_vulkan
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build Win32 example_sdl2_vulkan
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_vulkan/example_sdl2_vulkan.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build Win32 example_sdl2_opengl2
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_opengl2/example_sdl2_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build Win32 example_sdl2_opengl3
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_opengl3/example_sdl2_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
|
|
||||||
- name: Build Win32 example_sdl2_directx11
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build Win32 example_win32_directx9
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx9/example_win32_directx9.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
|
|
||||||
- name: Build Win32 example_win32_directx10
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx10/example_win32_directx10.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
|
|
||||||
- name: Build Win32 example_win32_directx11
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx11/example_win32_directx11.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_glfw_opengl2
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_glfw_opengl3
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
|
|
||||||
- name: Build x64 example_glfw_vulkan
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
|
|
||||||
- name: Build x64 example_sdl2_vulkan
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_vulkan/example_sdl2_vulkan.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_sdl2_opengl2
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_opengl2/example_sdl2_opengl2.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_sdl2_opengl3
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_opengl3/example_sdl2_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_sdl2_directx11
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
|
|
||||||
- name: Build x64 example_win32_directx9
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx9/example_win32_directx9.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_win32_directx10
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx10/example_win32_directx10.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_win32_directx11
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx11/example_win32_directx11.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build x64 example_win32_directx12
|
|
||||||
shell: cmd
|
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx12/example_win32_directx12.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
|
||||||
|
|
||||||
Linux:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libglfw3-dev libsdl2-dev gcc-multilib g++-multilib libfreetype6-dev libvulkan-dev
|
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, gcc 32-bit)
|
|
||||||
run: |
|
|
||||||
make -C examples/example_null clean
|
|
||||||
CXXFLAGS="$CXXFLAGS -m32 -Werror" make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, gcc 64-bit)
|
|
||||||
run: |
|
|
||||||
make -C examples/example_null clean
|
|
||||||
CXXFLAGS="$CXXFLAGS -m64 -Werror" make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, clang 32-bit)
|
|
||||||
run: |
|
|
||||||
make -C examples/example_null clean
|
|
||||||
CXXFLAGS="$CXXFLAGS -m32 -Werror" CXX=clang++ make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, clang 64-bit)
|
|
||||||
run: |
|
|
||||||
make -C examples/example_null clean
|
|
||||||
CXXFLAGS="$CXXFLAGS -m64 -Werror" CXX=clang++ make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, empty IM_ASSERT)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IM_ASSERT(x)
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -Wextra -Werror -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros -Wno-empty-body -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (freetype)
|
|
||||||
run: |
|
|
||||||
make -C examples/example_null clean
|
|
||||||
make -C examples/example_null WITH_FREETYPE=1
|
|
||||||
|
|
||||||
- name: Build example_null (single file build)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with ImWchar32)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_USE_WCHAR32
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with large ImDrawIdx + pointer ImTextureID)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define ImTextureID void*
|
|
||||||
#define ImDrawIdx unsigned int
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with IMGUI_DISABLE_OBSOLETE_FUNCTIONS)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with IMGUI_DISABLE_OBSOLETE_KEYIO)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_DISABLE_OBSOLETE_KEYIO
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with IMGUI_DISABLE_DEMO_WINDOWS and IMGUI_DISABLE_DEBUG_TOOLS)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_DISABLE_DEMO_WINDOWS
|
|
||||||
#define IMGUI_DISABLE_DEBUG_TOOLS
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with IMGUI_DISABLE_FILE_FUNCTIONS)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_DISABLE_FILE_FUNCTIONS
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with IMGUI_USE_BGRA_PACKED_COLOR)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_USE_BGRA_PACKED_COLOR
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (with IM_VEC2_CLASS_EXTRA and IM_VEC4_CLASS_EXTRA)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
struct MyVec2 { float x; float y; MyVec2(float x, float y) : x(x), y(y) { } };
|
|
||||||
struct MyVec4 { float x; float y; float z; float w;
|
|
||||||
MyVec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) { } };
|
|
||||||
#define IM_VEC2_CLASS_EXTRA \
|
|
||||||
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
|
||||||
operator MyVec2() const { return MyVec2(x, y); }
|
|
||||||
#define IM_VEC4_CLASS_EXTRA \
|
|
||||||
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); }
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (without c++ runtime, Clang)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#define IMGUI_DISABLE_DEMO_WINDOWS
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
clang++ -I. -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_glfw_opengl2
|
|
||||||
run: make -C examples/example_glfw_opengl2
|
|
||||||
|
|
||||||
- name: Build example_glfw_opengl3
|
|
||||||
run: make -C examples/example_glfw_opengl3
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build example_sdl2_opengl2
|
|
||||||
run: make -C examples/example_sdl2_opengl2
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build example_sdl2_opengl3
|
|
||||||
run: make -C examples/example_sdl2_opengl3
|
|
||||||
|
|
||||||
- name: Build with IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
|
||||||
run: g++ -c -I. -std=c++11 -DIMGUI_IMPL_VULKAN_NO_PROTOTYPES=1 backends/imgui_impl_vulkan.cpp
|
|
||||||
|
|
||||||
MacOS:
|
|
||||||
runs-on: macos-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: |
|
|
||||||
brew install glfw3 sdl2
|
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, clang 64-bit)
|
|
||||||
run: make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
|
||||||
|
|
||||||
- name: Build example_null (single file build)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
clang++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_null (without c++ runtime)
|
|
||||||
run: |
|
|
||||||
cat > example_single_file.cpp <<'EOF'
|
|
||||||
|
|
||||||
#define IMGUI_IMPLEMENTATION
|
|
||||||
#include "misc/single_file/imgui_single_file.h"
|
|
||||||
#include "examples/example_null/main.cpp"
|
|
||||||
|
|
||||||
EOF
|
|
||||||
clang++ -I. -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
|
|
||||||
|
|
||||||
- name: Build example_glfw_opengl2
|
|
||||||
run: make -C examples/example_glfw_opengl2
|
|
||||||
|
|
||||||
- name: Build example_glfw_opengl3
|
|
||||||
run: make -C examples/example_glfw_opengl3
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build example_glfw_metal
|
|
||||||
run: make -C examples/example_glfw_metal
|
|
||||||
|
|
||||||
- name: Build example_sdl2_metal
|
|
||||||
run: make -C examples/example_sdl2_metal
|
|
||||||
|
|
||||||
- name: Build example_sdl2_opengl2
|
|
||||||
run: make -C examples/example_sdl2_opengl2
|
|
||||||
if: github.event_name == 'workflow_run'
|
|
||||||
|
|
||||||
- name: Build example_sdl2_opengl3
|
|
||||||
run: make -C examples/example_sdl2_opengl3
|
|
||||||
|
|
||||||
- name: Build example_apple_metal
|
|
||||||
run: xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_macos
|
|
||||||
|
|
||||||
- name: Build example_apple_opengl2
|
|
||||||
run: xcodebuild -project examples/example_apple_opengl2/example_apple_opengl2.xcodeproj -target example_osx_opengl2
|
|
||||||
|
|
||||||
iOS:
|
|
||||||
runs-on: macos-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Build example_apple_metal
|
|
||||||
run: |
|
|
||||||
# Code signing is required, but we disable it because it is irrelevant for CI builds.
|
|
||||||
xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_ios CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
|
|
||||||
|
|
||||||
Emscripten:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: |
|
|
||||||
wget -q https://github.com/emscripten-core/emsdk/archive/master.tar.gz
|
|
||||||
tar -xvf master.tar.gz
|
|
||||||
emsdk-master/emsdk update
|
|
||||||
emsdk-master/emsdk install latest
|
|
||||||
emsdk-master/emsdk activate latest
|
|
||||||
|
|
||||||
- name: Build example_sdl2_opengl3 with Emscripten
|
|
||||||
run: |
|
|
||||||
pushd emsdk-master
|
|
||||||
source ./emsdk_env.sh
|
|
||||||
popd
|
|
||||||
make -C examples/example_sdl2_opengl3 -f Makefile.emscripten
|
|
||||||
|
|
||||||
- name: Build example_emscripten_wgpu
|
|
||||||
run: |
|
|
||||||
pushd emsdk-master
|
|
||||||
source ./emsdk_env.sh
|
|
||||||
popd
|
|
||||||
make -C examples/example_emscripten_wgpu
|
|
||||||
|
|
||||||
Android:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Build example_android_opengl3
|
|
||||||
run: |
|
|
||||||
cd examples/example_android_opengl3/android
|
|
||||||
gradle assembleDebug --stacktrace
|
|
@ -1,15 +0,0 @@
|
|||||||
#
|
|
||||||
# This is a dummy workflow used to trigger scheduled builds. Forked repositories most likely should disable this
|
|
||||||
# workflow to avoid daily builds of inactive repositories.
|
|
||||||
#
|
|
||||||
name: scheduled
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '0 9 * * *'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
scheduled:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: exit 0
|
|
@ -1,46 +0,0 @@
|
|||||||
name: static-analysis
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
# Perform static analysis together with build workflow. Build triggers of "build" workflow do not need to be repeated here.
|
|
||||||
workflows:
|
|
||||||
- build
|
|
||||||
types:
|
|
||||||
- requested
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
PVS-Studio:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
env:
|
|
||||||
# The Secret variable setup in GitHub must be in format: "name_or_email key", on a single line
|
|
||||||
PVS_STUDIO_LICENSE: ${{ secrets.PVS_STUDIO_LICENSE }}
|
|
||||||
run: |
|
|
||||||
if [[ "$PVS_STUDIO_LICENSE" != "" ]];
|
|
||||||
then
|
|
||||||
wget -q https://files.viva64.com/etc/pubkey.txt
|
|
||||||
sudo apt-key add pubkey.txt
|
|
||||||
sudo wget -O /etc/apt/sources.list.d/viva64.list https://files.viva64.com/etc/viva64.list
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y pvs-studio
|
|
||||||
pvs-studio-analyzer credentials -o pvs-studio.lic $PVS_STUDIO_LICENSE
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: PVS-Studio static analysis
|
|
||||||
run: |
|
|
||||||
if [[ ! -f pvs-studio.lic ]];
|
|
||||||
then
|
|
||||||
echo "PVS Studio license is missing. No analysis will be performed."
|
|
||||||
echo "If you have a PVS Studio license please create a project secret named PVS_STUDIO_LICENSE with your license."
|
|
||||||
echo "You may use a free license. More information at https://www.viva64.com/en/b/0457/"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
cd examples/example_null
|
|
||||||
pvs-studio-analyzer trace -- make WITH_EXTRA_WARNINGS=1
|
|
||||||
pvs-studio-analyzer analyze -e ../../imstb_rectpack.h -e ../../imstb_textedit.h -e ../../imstb_truetype.h -l ../../pvs-studio.lic -o pvs-studio.log
|
|
||||||
plog-converter -a 'GA:1,2;OP:1' -d V1071 -t errorfile -w pvs-studio.log
|
|
59
grk/cw 6/src/imgui-master/.gitignore
vendored
59
grk/cw 6/src/imgui-master/.gitignore
vendored
@ -1,59 +0,0 @@
|
|||||||
## OSX artifacts
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
## Dear ImGui artifacts
|
|
||||||
imgui.ini
|
|
||||||
|
|
||||||
## General build artifacts
|
|
||||||
*.o
|
|
||||||
*.obj
|
|
||||||
*.exe
|
|
||||||
examples/*/Debug/*
|
|
||||||
examples/*/Release/*
|
|
||||||
examples/*/x64/*
|
|
||||||
|
|
||||||
## Visual Studio artifacts
|
|
||||||
.vs
|
|
||||||
ipch
|
|
||||||
*.opensdf
|
|
||||||
*.log
|
|
||||||
*.pdb
|
|
||||||
*.ilk
|
|
||||||
*.user
|
|
||||||
*.sdf
|
|
||||||
*.suo
|
|
||||||
*.VC.db
|
|
||||||
*.VC.VC.opendb
|
|
||||||
|
|
||||||
## Getting files created in JSON/Schemas/Catalog/ from a VS2022 update
|
|
||||||
JSON/
|
|
||||||
|
|
||||||
## Commonly used CMake directories
|
|
||||||
build*/
|
|
||||||
|
|
||||||
## Xcode artifacts
|
|
||||||
project.xcworkspace
|
|
||||||
xcuserdata
|
|
||||||
|
|
||||||
## Emscripten artifacts
|
|
||||||
examples/*.o.tmp
|
|
||||||
examples/*.out.js
|
|
||||||
examples/*.out.wasm
|
|
||||||
examples/example_glfw_opengl3/web/*
|
|
||||||
examples/example_sdl2_opengl3/web/*
|
|
||||||
examples/example_emscripten_wgpu/web/*
|
|
||||||
|
|
||||||
## JetBrains IDE artifacts
|
|
||||||
.idea
|
|
||||||
cmake-build-*
|
|
||||||
|
|
||||||
## Unix executables from our example Makefiles
|
|
||||||
examples/example_glfw_metal/example_glfw_metal
|
|
||||||
examples/example_glfw_opengl2/example_glfw_opengl2
|
|
||||||
examples/example_glfw_opengl3/example_glfw_opengl3
|
|
||||||
examples/example_glut_opengl2/example_glut_opengl2
|
|
||||||
examples/example_null/example_null
|
|
||||||
examples/example_sdl2_metal/example_sdl2_metal
|
|
||||||
examples/example_sdl2_opengl2/example_sdl2_opengl2
|
|
||||||
examples/example_sdl2_opengl3/example_sdl2_opengl3
|
|
||||||
examples/example_sdl2_sdlrenderer/example_sdl2_sdlrenderer
|
|
@ -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,613 +0,0 @@
|
|||||||
// dear imgui: Renderer + Platform Backend for Allegro 5
|
|
||||||
// (Info: Allegro 5 is a cross-platform general purpose library for handling windows, inputs, graphics, etc.)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [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 ALLEGRO_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Clipboard support (from Allegro 5.1.12)
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// Issues:
|
|
||||||
// [ ] Renderer: The renderer is suboptimal as we need to convert vertices manually.
|
|
||||||
// [ ] Platform: Missing gamepad support.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2022-11-30: Renderer: Restoring using al_draw_indexed_prim() when Allegro version is >= 5.2.5.
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
|
|
||||||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
|
||||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
|
||||||
// 2022-01-17: Inputs: always calling io.AddKeyModsEvent() next and before key event (not in NewFrame) to fix input queue with very low framerates.
|
|
||||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
|
||||||
// 2021-12-08: Renderer: Fixed mishandling of the the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
|
|
||||||
// 2021-08-17: Calling io.AddFocusEvent() on ALLEGRO_EVENT_DISPLAY_SWITCH_OUT/ALLEGRO_EVENT_DISPLAY_SWITCH_IN events.
|
|
||||||
// 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-05-19: Renderer: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
||||||
// 2021-02-18: Change blending equation to preserve alpha in output buffer.
|
|
||||||
// 2020-08-10: Inputs: Fixed horizontal mouse wheel direction.
|
|
||||||
// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor.
|
|
||||||
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
|
|
||||||
// 2019-05-11: Inputs: Don't filter character value from ALLEGRO_EVENT_KEY_CHAR before calling AddInputCharacter().
|
|
||||||
// 2019-04-30: Renderer: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
||||||
// 2018-11-30: Platform: Added touchscreen support.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName/io.BackendRendererName so they can be displayed in the About Window.
|
|
||||||
// 2018-06-13: Platform: Added clipboard support (from Allegro 5.1.12).
|
|
||||||
// 2018-06-13: Renderer: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
|
||||||
// 2018-06-13: Renderer: Stopped using al_draw_indexed_prim() as it is buggy in Allegro's DX9 backend.
|
|
||||||
// 2018-06-13: Renderer: Backup/restore transform and clipping rectangle.
|
|
||||||
// 2018-06-11: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
|
|
||||||
// 2018-04-18: Misc: Renamed file from imgui_impl_a5.cpp to imgui_impl_allegro5.cpp.
|
|
||||||
// 2018-04-18: Misc: Added support for 32-bit vertex indices to avoid conversion at runtime. Added imconfig_allegro5.h to enforce 32-bit indices when included from imgui.h.
|
|
||||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplAllegro5_RenderDrawData() in the .h file so you can call it yourself.
|
|
||||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
|
||||||
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_allegro5.h"
|
|
||||||
#include <stdint.h> // uint64_t
|
|
||||||
#include <cstring> // memcpy
|
|
||||||
|
|
||||||
// Allegro
|
|
||||||
#include <allegro5/allegro.h>
|
|
||||||
#include <allegro5/allegro_primitives.h>
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <allegro5/allegro_windows.h>
|
|
||||||
#endif
|
|
||||||
#define ALLEGRO_HAS_CLIPBOARD (ALLEGRO_VERSION_INT >= ((5 << 24) | (1 << 16) | (12 << 8))) // Clipboard only supported from Allegro 5.1.12
|
|
||||||
#define ALLEGRO_HAS_DRAW_INDEXED_PRIM (ALLEGRO_VERSION_INT >= ((5 << 24) | (2 << 16) | ( 5 << 8))) // DX9 implementation of al_draw_indexed_prim() got fixed in Allegro 5.2.5
|
|
||||||
|
|
||||||
// Visual Studio warnings
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning (disable: 4127) // condition expression is constant
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct ImDrawVertAllegro
|
|
||||||
{
|
|
||||||
ImVec2 pos;
|
|
||||||
ImVec2 uv;
|
|
||||||
ALLEGRO_COLOR col;
|
|
||||||
};
|
|
||||||
|
|
||||||
// FIXME-OPT: Unfortunately Allegro doesn't support 32-bit packed colors so we have to convert them to 4 float as well..
|
|
||||||
// FIXME-OPT: Consider inlining al_map_rgba()?
|
|
||||||
// see https://github.com/liballeg/allegro5/blob/master/src/pixels.c#L554
|
|
||||||
// and https://github.com/liballeg/allegro5/blob/master/include/allegro5/internal/aintern_pixels.h
|
|
||||||
#define DRAW_VERT_IMGUI_TO_ALLEGRO(DST, SRC) { (DST)->pos = (SRC)->pos; (DST)->uv = (SRC)->uv; unsigned char* c = (unsigned char*)&(SRC)->col; (DST)->col = al_map_rgba(c[0], c[1], c[2], c[3]); }
|
|
||||||
|
|
||||||
// Allegro Data
|
|
||||||
struct ImGui_ImplAllegro5_Data
|
|
||||||
{
|
|
||||||
ALLEGRO_DISPLAY* Display;
|
|
||||||
ALLEGRO_BITMAP* Texture;
|
|
||||||
double Time;
|
|
||||||
ALLEGRO_MOUSE_CURSOR* MouseCursorInvisible;
|
|
||||||
ALLEGRO_VERTEX_DECL* VertexDecl;
|
|
||||||
char* ClipboardTextData;
|
|
||||||
|
|
||||||
ImVector<ImDrawVertAllegro> BufVertices;
|
|
||||||
ImVector<int> BufIndices;
|
|
||||||
|
|
||||||
ImGui_ImplAllegro5_Data() { memset((void*)this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
|
||||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
||||||
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
|
||||||
static ImGui_ImplAllegro5_Data* ImGui_ImplAllegro5_GetBackendData() { return ImGui::GetCurrentContext() ? (ImGui_ImplAllegro5_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; }
|
|
||||||
|
|
||||||
static void ImGui_ImplAllegro5_SetupRenderState(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
// Setup blending
|
|
||||||
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
|
|
||||||
|
|
||||||
// Setup orthographic projection matrix
|
|
||||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
ALLEGRO_TRANSFORM transform;
|
|
||||||
al_identity_transform(&transform);
|
|
||||||
al_use_transform(&transform);
|
|
||||||
al_orthographic_transform(&transform, L, T, 1.0f, R, B, -1.0f);
|
|
||||||
al_use_projection_transform(&transform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render function.
|
|
||||||
void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
// Avoid rendering when minimized
|
|
||||||
if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Backup Allegro state that will be modified
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
ALLEGRO_TRANSFORM last_transform = *al_get_current_transform();
|
|
||||||
ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform();
|
|
||||||
int last_clip_x, last_clip_y, last_clip_w, last_clip_h;
|
|
||||||
al_get_clipping_rectangle(&last_clip_x, &last_clip_y, &last_clip_w, &last_clip_h);
|
|
||||||
int last_blender_op, last_blender_src, last_blender_dst;
|
|
||||||
al_get_blender(&last_blender_op, &last_blender_src, &last_blender_dst);
|
|
||||||
|
|
||||||
// Setup desired render state
|
|
||||||
ImGui_ImplAllegro5_SetupRenderState(draw_data);
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
|
|
||||||
ImVector<ImDrawVertAllegro>& vertices = bd->BufVertices;
|
|
||||||
#if ALLEGRO_HAS_DRAW_INDEXED_PRIM
|
|
||||||
vertices.resize(cmd_list->VtxBuffer.Size);
|
|
||||||
for (int i = 0; i < cmd_list->VtxBuffer.Size; i++)
|
|
||||||
{
|
|
||||||
const ImDrawVert* src_v = &cmd_list->VtxBuffer[i];
|
|
||||||
ImDrawVertAllegro* dst_v = &vertices[i];
|
|
||||||
DRAW_VERT_IMGUI_TO_ALLEGRO(dst_v, src_v);
|
|
||||||
}
|
|
||||||
const int* indices = nullptr;
|
|
||||||
if (sizeof(ImDrawIdx) == 2)
|
|
||||||
{
|
|
||||||
// FIXME-OPT: Allegro doesn't support 16-bit indices.
|
|
||||||
// You can '#define ImDrawIdx int' in imconfig.h to request Dear ImGui to output 32-bit indices.
|
|
||||||
// Otherwise, we convert them from 16-bit to 32-bit at runtime here, which works perfectly but is a little wasteful.
|
|
||||||
bd->BufIndices.resize(cmd_list->IdxBuffer.Size);
|
|
||||||
for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i)
|
|
||||||
bd->BufIndices[i] = (int)cmd_list->IdxBuffer.Data[i];
|
|
||||||
indices = bd->BufIndices.Data;
|
|
||||||
}
|
|
||||||
else if (sizeof(ImDrawIdx) == 4)
|
|
||||||
{
|
|
||||||
indices = (const int*)cmd_list->IdxBuffer.Data;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Allegro's implementation of al_draw_indexed_prim() for DX9 was broken until 5.2.5. Unindex buffers ourselves while converting vertex format.
|
|
||||||
vertices.resize(cmd_list->IdxBuffer.Size);
|
|
||||||
for (int i = 0; i < cmd_list->IdxBuffer.Size; i++)
|
|
||||||
{
|
|
||||||
const ImDrawVert* src_v = &cmd_list->VtxBuffer[cmd_list->IdxBuffer[i]];
|
|
||||||
ImDrawVertAllegro* dst_v = &vertices[i];
|
|
||||||
DRAW_VERT_IMGUI_TO_ALLEGRO(dst_v, src_v);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
ImVec2 clip_off = draw_data->DisplayPos;
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
||||||
{
|
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
||||||
if (pcmd->UserCallback)
|
|
||||||
{
|
|
||||||
// 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_ImplAllegro5_SetupRenderState(draw_data);
|
|
||||||
else
|
|
||||||
pcmd->UserCallback(cmd_list, pcmd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
|
|
||||||
ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Apply scissor/clipping rectangle, Draw
|
|
||||||
ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->GetTexID();
|
|
||||||
al_set_clipping_rectangle(clip_min.x, clip_min.y, clip_max.x - clip_min.x, clip_max.y - clip_min.y);
|
|
||||||
#if ALLEGRO_HAS_DRAW_INDEXED_PRIM
|
|
||||||
al_draw_indexed_prim(&vertices[0], bd->VertexDecl, texture, &indices[pcmd->IdxOffset], pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST);
|
|
||||||
#else
|
|
||||||
al_draw_prim(&vertices[0], bd->VertexDecl, texture, pcmd->IdxOffset, pcmd->IdxOffset + pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore modified Allegro state
|
|
||||||
al_set_blender(last_blender_op, last_blender_src, last_blender_dst);
|
|
||||||
al_set_clipping_rectangle(last_clip_x, last_clip_y, last_clip_w, last_clip_h);
|
|
||||||
al_use_transform(&last_transform);
|
|
||||||
al_use_projection_transform(&last_projection_transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplAllegro5_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
// Build texture atlas
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
unsigned char* pixels;
|
|
||||||
int width, height;
|
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
|
||||||
|
|
||||||
// Create texture
|
|
||||||
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
|
||||||
int flags = al_get_new_bitmap_flags();
|
|
||||||
int fmt = al_get_new_bitmap_format();
|
|
||||||
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP | ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
|
|
||||||
al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE);
|
|
||||||
ALLEGRO_BITMAP* img = al_create_bitmap(width, height);
|
|
||||||
al_set_new_bitmap_flags(flags);
|
|
||||||
al_set_new_bitmap_format(fmt);
|
|
||||||
if (!img)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ALLEGRO_LOCKED_REGION* locked_img = al_lock_bitmap(img, al_get_bitmap_format(img), ALLEGRO_LOCK_WRITEONLY);
|
|
||||||
if (!locked_img)
|
|
||||||
{
|
|
||||||
al_destroy_bitmap(img);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
memcpy(locked_img->data, pixels, sizeof(int) * width * height);
|
|
||||||
al_unlock_bitmap(img);
|
|
||||||
|
|
||||||
// Convert software texture to hardware texture.
|
|
||||||
ALLEGRO_BITMAP* cloned_img = al_clone_bitmap(img);
|
|
||||||
al_destroy_bitmap(img);
|
|
||||||
if (!cloned_img)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Store our identifier
|
|
||||||
io.Fonts->SetTexID((ImTextureID)(intptr_t)cloned_img);
|
|
||||||
bd->Texture = cloned_img;
|
|
||||||
|
|
||||||
// Create an invisible mouse cursor
|
|
||||||
// Because al_hide_mouse_cursor() seems to mess up with the actual inputs..
|
|
||||||
ALLEGRO_BITMAP* mouse_cursor = al_create_bitmap(8, 8);
|
|
||||||
bd->MouseCursorInvisible = al_create_mouse_cursor(mouse_cursor, 0, 0);
|
|
||||||
al_destroy_bitmap(mouse_cursor);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplAllegro5_InvalidateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
if (bd->Texture)
|
|
||||||
{
|
|
||||||
io.Fonts->SetTexID(0);
|
|
||||||
al_destroy_bitmap(bd->Texture);
|
|
||||||
bd->Texture = nullptr;
|
|
||||||
}
|
|
||||||
if (bd->MouseCursorInvisible)
|
|
||||||
{
|
|
||||||
al_destroy_mouse_cursor(bd->MouseCursorInvisible);
|
|
||||||
bd->MouseCursorInvisible = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ALLEGRO_HAS_CLIPBOARD
|
|
||||||
static const char* ImGui_ImplAllegro5_GetClipboardText(void*)
|
|
||||||
{
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
if (bd->ClipboardTextData)
|
|
||||||
al_free(bd->ClipboardTextData);
|
|
||||||
bd->ClipboardTextData = al_get_clipboard_text(bd->Display);
|
|
||||||
return bd->ClipboardTextData;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplAllegro5_SetClipboardText(void*, const char* text)
|
|
||||||
{
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
al_set_clipboard_text(bd->Display, text);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static ImGuiKey ImGui_ImplAllegro5_KeyCodeToImGuiKey(int key_code)
|
|
||||||
{
|
|
||||||
switch (key_code)
|
|
||||||
{
|
|
||||||
case ALLEGRO_KEY_TAB: return ImGuiKey_Tab;
|
|
||||||
case ALLEGRO_KEY_LEFT: return ImGuiKey_LeftArrow;
|
|
||||||
case ALLEGRO_KEY_RIGHT: return ImGuiKey_RightArrow;
|
|
||||||
case ALLEGRO_KEY_UP: return ImGuiKey_UpArrow;
|
|
||||||
case ALLEGRO_KEY_DOWN: return ImGuiKey_DownArrow;
|
|
||||||
case ALLEGRO_KEY_PGUP: return ImGuiKey_PageUp;
|
|
||||||
case ALLEGRO_KEY_PGDN: return ImGuiKey_PageDown;
|
|
||||||
case ALLEGRO_KEY_HOME: return ImGuiKey_Home;
|
|
||||||
case ALLEGRO_KEY_END: return ImGuiKey_End;
|
|
||||||
case ALLEGRO_KEY_INSERT: return ImGuiKey_Insert;
|
|
||||||
case ALLEGRO_KEY_DELETE: return ImGuiKey_Delete;
|
|
||||||
case ALLEGRO_KEY_BACKSPACE: return ImGuiKey_Backspace;
|
|
||||||
case ALLEGRO_KEY_SPACE: return ImGuiKey_Space;
|
|
||||||
case ALLEGRO_KEY_ENTER: return ImGuiKey_Enter;
|
|
||||||
case ALLEGRO_KEY_ESCAPE: return ImGuiKey_Escape;
|
|
||||||
case ALLEGRO_KEY_QUOTE: return ImGuiKey_Apostrophe;
|
|
||||||
case ALLEGRO_KEY_COMMA: return ImGuiKey_Comma;
|
|
||||||
case ALLEGRO_KEY_MINUS: return ImGuiKey_Minus;
|
|
||||||
case ALLEGRO_KEY_FULLSTOP: return ImGuiKey_Period;
|
|
||||||
case ALLEGRO_KEY_SLASH: return ImGuiKey_Slash;
|
|
||||||
case ALLEGRO_KEY_SEMICOLON: return ImGuiKey_Semicolon;
|
|
||||||
case ALLEGRO_KEY_EQUALS: return ImGuiKey_Equal;
|
|
||||||
case ALLEGRO_KEY_OPENBRACE: return ImGuiKey_LeftBracket;
|
|
||||||
case ALLEGRO_KEY_BACKSLASH: return ImGuiKey_Backslash;
|
|
||||||
case ALLEGRO_KEY_CLOSEBRACE: return ImGuiKey_RightBracket;
|
|
||||||
case ALLEGRO_KEY_TILDE: return ImGuiKey_GraveAccent;
|
|
||||||
case ALLEGRO_KEY_CAPSLOCK: return ImGuiKey_CapsLock;
|
|
||||||
case ALLEGRO_KEY_SCROLLLOCK: return ImGuiKey_ScrollLock;
|
|
||||||
case ALLEGRO_KEY_NUMLOCK: return ImGuiKey_NumLock;
|
|
||||||
case ALLEGRO_KEY_PRINTSCREEN: return ImGuiKey_PrintScreen;
|
|
||||||
case ALLEGRO_KEY_PAUSE: return ImGuiKey_Pause;
|
|
||||||
case ALLEGRO_KEY_PAD_0: return ImGuiKey_Keypad0;
|
|
||||||
case ALLEGRO_KEY_PAD_1: return ImGuiKey_Keypad1;
|
|
||||||
case ALLEGRO_KEY_PAD_2: return ImGuiKey_Keypad2;
|
|
||||||
case ALLEGRO_KEY_PAD_3: return ImGuiKey_Keypad3;
|
|
||||||
case ALLEGRO_KEY_PAD_4: return ImGuiKey_Keypad4;
|
|
||||||
case ALLEGRO_KEY_PAD_5: return ImGuiKey_Keypad5;
|
|
||||||
case ALLEGRO_KEY_PAD_6: return ImGuiKey_Keypad6;
|
|
||||||
case ALLEGRO_KEY_PAD_7: return ImGuiKey_Keypad7;
|
|
||||||
case ALLEGRO_KEY_PAD_8: return ImGuiKey_Keypad8;
|
|
||||||
case ALLEGRO_KEY_PAD_9: return ImGuiKey_Keypad9;
|
|
||||||
case ALLEGRO_KEY_PAD_DELETE: return ImGuiKey_KeypadDecimal;
|
|
||||||
case ALLEGRO_KEY_PAD_SLASH: return ImGuiKey_KeypadDivide;
|
|
||||||
case ALLEGRO_KEY_PAD_ASTERISK: return ImGuiKey_KeypadMultiply;
|
|
||||||
case ALLEGRO_KEY_PAD_MINUS: return ImGuiKey_KeypadSubtract;
|
|
||||||
case ALLEGRO_KEY_PAD_PLUS: return ImGuiKey_KeypadAdd;
|
|
||||||
case ALLEGRO_KEY_PAD_ENTER: return ImGuiKey_KeypadEnter;
|
|
||||||
case ALLEGRO_KEY_PAD_EQUALS: return ImGuiKey_KeypadEqual;
|
|
||||||
case ALLEGRO_KEY_LCTRL: return ImGuiKey_LeftCtrl;
|
|
||||||
case ALLEGRO_KEY_LSHIFT: return ImGuiKey_LeftShift;
|
|
||||||
case ALLEGRO_KEY_ALT: return ImGuiKey_LeftAlt;
|
|
||||||
case ALLEGRO_KEY_LWIN: return ImGuiKey_LeftSuper;
|
|
||||||
case ALLEGRO_KEY_RCTRL: return ImGuiKey_RightCtrl;
|
|
||||||
case ALLEGRO_KEY_RSHIFT: return ImGuiKey_RightShift;
|
|
||||||
case ALLEGRO_KEY_ALTGR: return ImGuiKey_RightAlt;
|
|
||||||
case ALLEGRO_KEY_RWIN: return ImGuiKey_RightSuper;
|
|
||||||
case ALLEGRO_KEY_MENU: return ImGuiKey_Menu;
|
|
||||||
case ALLEGRO_KEY_0: return ImGuiKey_0;
|
|
||||||
case ALLEGRO_KEY_1: return ImGuiKey_1;
|
|
||||||
case ALLEGRO_KEY_2: return ImGuiKey_2;
|
|
||||||
case ALLEGRO_KEY_3: return ImGuiKey_3;
|
|
||||||
case ALLEGRO_KEY_4: return ImGuiKey_4;
|
|
||||||
case ALLEGRO_KEY_5: return ImGuiKey_5;
|
|
||||||
case ALLEGRO_KEY_6: return ImGuiKey_6;
|
|
||||||
case ALLEGRO_KEY_7: return ImGuiKey_7;
|
|
||||||
case ALLEGRO_KEY_8: return ImGuiKey_8;
|
|
||||||
case ALLEGRO_KEY_9: return ImGuiKey_9;
|
|
||||||
case ALLEGRO_KEY_A: return ImGuiKey_A;
|
|
||||||
case ALLEGRO_KEY_B: return ImGuiKey_B;
|
|
||||||
case ALLEGRO_KEY_C: return ImGuiKey_C;
|
|
||||||
case ALLEGRO_KEY_D: return ImGuiKey_D;
|
|
||||||
case ALLEGRO_KEY_E: return ImGuiKey_E;
|
|
||||||
case ALLEGRO_KEY_F: return ImGuiKey_F;
|
|
||||||
case ALLEGRO_KEY_G: return ImGuiKey_G;
|
|
||||||
case ALLEGRO_KEY_H: return ImGuiKey_H;
|
|
||||||
case ALLEGRO_KEY_I: return ImGuiKey_I;
|
|
||||||
case ALLEGRO_KEY_J: return ImGuiKey_J;
|
|
||||||
case ALLEGRO_KEY_K: return ImGuiKey_K;
|
|
||||||
case ALLEGRO_KEY_L: return ImGuiKey_L;
|
|
||||||
case ALLEGRO_KEY_M: return ImGuiKey_M;
|
|
||||||
case ALLEGRO_KEY_N: return ImGuiKey_N;
|
|
||||||
case ALLEGRO_KEY_O: return ImGuiKey_O;
|
|
||||||
case ALLEGRO_KEY_P: return ImGuiKey_P;
|
|
||||||
case ALLEGRO_KEY_Q: return ImGuiKey_Q;
|
|
||||||
case ALLEGRO_KEY_R: return ImGuiKey_R;
|
|
||||||
case ALLEGRO_KEY_S: return ImGuiKey_S;
|
|
||||||
case ALLEGRO_KEY_T: return ImGuiKey_T;
|
|
||||||
case ALLEGRO_KEY_U: return ImGuiKey_U;
|
|
||||||
case ALLEGRO_KEY_V: return ImGuiKey_V;
|
|
||||||
case ALLEGRO_KEY_W: return ImGuiKey_W;
|
|
||||||
case ALLEGRO_KEY_X: return ImGuiKey_X;
|
|
||||||
case ALLEGRO_KEY_Y: return ImGuiKey_Y;
|
|
||||||
case ALLEGRO_KEY_Z: return ImGuiKey_Z;
|
|
||||||
case ALLEGRO_KEY_F1: return ImGuiKey_F1;
|
|
||||||
case ALLEGRO_KEY_F2: return ImGuiKey_F2;
|
|
||||||
case ALLEGRO_KEY_F3: return ImGuiKey_F3;
|
|
||||||
case ALLEGRO_KEY_F4: return ImGuiKey_F4;
|
|
||||||
case ALLEGRO_KEY_F5: return ImGuiKey_F5;
|
|
||||||
case ALLEGRO_KEY_F6: return ImGuiKey_F6;
|
|
||||||
case ALLEGRO_KEY_F7: return ImGuiKey_F7;
|
|
||||||
case ALLEGRO_KEY_F8: return ImGuiKey_F8;
|
|
||||||
case ALLEGRO_KEY_F9: return ImGuiKey_F9;
|
|
||||||
case ALLEGRO_KEY_F10: return ImGuiKey_F10;
|
|
||||||
case ALLEGRO_KEY_F11: return ImGuiKey_F11;
|
|
||||||
case ALLEGRO_KEY_F12: return ImGuiKey_F12;
|
|
||||||
default: return ImGuiKey_None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplAllegro5_Data* bd = IM_NEW(ImGui_ImplAllegro5_Data)();
|
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
|
||||||
io.BackendPlatformName = io.BackendRendererName = "imgui_impl_allegro5";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
|
||||||
|
|
||||||
bd->Display = display;
|
|
||||||
|
|
||||||
// Create custom vertex declaration.
|
|
||||||
// Unfortunately Allegro doesn't support 32-bit packed colors so we have to convert them to 4 floats.
|
|
||||||
// We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion.
|
|
||||||
ALLEGRO_VERTEX_ELEMENT elems[] =
|
|
||||||
{
|
|
||||||
{ ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, offsetof(ImDrawVertAllegro, pos) },
|
|
||||||
{ ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, offsetof(ImDrawVertAllegro, uv) },
|
|
||||||
{ ALLEGRO_PRIM_COLOR_ATTR, 0, offsetof(ImDrawVertAllegro, col) },
|
|
||||||
{ 0, 0, 0 }
|
|
||||||
};
|
|
||||||
bd->VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro));
|
|
||||||
|
|
||||||
#if ALLEGRO_HAS_CLIPBOARD
|
|
||||||
io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
|
|
||||||
io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText;
|
|
||||||
io.ClipboardUserData = nullptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplAllegro5_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
|
||||||
if (bd->VertexDecl)
|
|
||||||
al_destroy_vertex_decl(bd->VertexDecl);
|
|
||||||
if (bd->ClipboardTextData)
|
|
||||||
al_free(bd->ClipboardTextData);
|
|
||||||
|
|
||||||
io.BackendPlatformName = io.BackendRendererName = nullptr;
|
|
||||||
io.BackendPlatformUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_HasMouseCursors;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ev->keyboard.modifiers seems always zero so using that...
|
|
||||||
static void ImGui_ImplAllegro5_UpdateKeyModifiers()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ALLEGRO_KEYBOARD_STATE keys;
|
|
||||||
al_get_keyboard_state(&keys);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Ctrl, al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL));
|
|
||||||
io.AddKeyEvent(ImGuiMod_Shift, al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT));
|
|
||||||
io.AddKeyEvent(ImGuiMod_Alt, al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR));
|
|
||||||
io.AddKeyEvent(ImGuiMod_Super, al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN));
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
||||||
bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* ev)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
|
|
||||||
switch (ev->type)
|
|
||||||
{
|
|
||||||
case ALLEGRO_EVENT_MOUSE_AXES:
|
|
||||||
if (ev->mouse.display == bd->Display)
|
|
||||||
{
|
|
||||||
io.AddMousePosEvent(ev->mouse.x, ev->mouse.y);
|
|
||||||
io.AddMouseWheelEvent(-ev->mouse.dw, ev->mouse.dz);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
|
|
||||||
case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
|
|
||||||
if (ev->mouse.display == bd->Display && ev->mouse.button > 0 && ev->mouse.button <= 5)
|
|
||||||
io.AddMouseButtonEvent(ev->mouse.button - 1, ev->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN);
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_TOUCH_MOVE:
|
|
||||||
if (ev->touch.display == bd->Display)
|
|
||||||
io.AddMousePosEvent(ev->touch.x, ev->touch.y);
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_TOUCH_BEGIN:
|
|
||||||
case ALLEGRO_EVENT_TOUCH_END:
|
|
||||||
case ALLEGRO_EVENT_TOUCH_CANCEL:
|
|
||||||
if (ev->touch.display == bd->Display && ev->touch.primary)
|
|
||||||
io.AddMouseButtonEvent(0, ev->type == ALLEGRO_EVENT_TOUCH_BEGIN);
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY:
|
|
||||||
if (ev->mouse.display == bd->Display)
|
|
||||||
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_KEY_CHAR:
|
|
||||||
if (ev->keyboard.display == bd->Display)
|
|
||||||
if (ev->keyboard.unichar != 0)
|
|
||||||
io.AddInputCharacter((unsigned int)ev->keyboard.unichar);
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_KEY_DOWN:
|
|
||||||
case ALLEGRO_EVENT_KEY_UP:
|
|
||||||
if (ev->keyboard.display == bd->Display)
|
|
||||||
{
|
|
||||||
ImGui_ImplAllegro5_UpdateKeyModifiers();
|
|
||||||
ImGuiKey key = ImGui_ImplAllegro5_KeyCodeToImGuiKey(ev->keyboard.keycode);
|
|
||||||
io.AddKeyEvent(key, (ev->type == ALLEGRO_EVENT_KEY_DOWN));
|
|
||||||
io.SetKeyEventNativeData(key, ev->keyboard.keycode, -1); // To support legacy indexing (<1.87 user code)
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
|
|
||||||
if (ev->display.source == bd->Display)
|
|
||||||
io.AddFocusEvent(false);
|
|
||||||
return true;
|
|
||||||
case ALLEGRO_EVENT_DISPLAY_SWITCH_IN:
|
|
||||||
if (ev->display.source == bd->Display)
|
|
||||||
{
|
|
||||||
io.AddFocusEvent(true);
|
|
||||||
#if defined(ALLEGRO_UNSTABLE)
|
|
||||||
al_clear_keyboard_state(bd->Display);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplAllegro5_UpdateMouseCursor()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
|
||||||
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
|
||||||
{
|
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
|
||||||
al_set_mouse_cursor(bd->Display, bd->MouseCursorInvisible);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ALLEGRO_SYSTEM_MOUSE_CURSOR cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT;
|
|
||||||
switch (imgui_cursor)
|
|
||||||
{
|
|
||||||
case ImGuiMouseCursor_TextInput: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_EDIT; break;
|
|
||||||
case ImGuiMouseCursor_ResizeAll: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_MOVE; break;
|
|
||||||
case ImGuiMouseCursor_ResizeNS: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_N; break;
|
|
||||||
case ImGuiMouseCursor_ResizeEW: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E; break;
|
|
||||||
case ImGuiMouseCursor_ResizeNESW: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NE; break;
|
|
||||||
case ImGuiMouseCursor_ResizeNWSE: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NW; break;
|
|
||||||
case ImGuiMouseCursor_NotAllowed: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_UNAVAILABLE; break;
|
|
||||||
}
|
|
||||||
al_set_system_mouse_cursor(bd->Display, cursor_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplAllegro5_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplAllegro5_Init()?");
|
|
||||||
|
|
||||||
if (!bd->Texture)
|
|
||||||
ImGui_ImplAllegro5_CreateDeviceObjects();
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
|
||||||
int w, h;
|
|
||||||
w = al_get_display_width(bd->Display);
|
|
||||||
h = al_get_display_height(bd->Display);
|
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
|
||||||
|
|
||||||
// Setup time step
|
|
||||||
double current_time = al_get_time();
|
|
||||||
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
|
|
||||||
bd->Time = current_time;
|
|
||||||
|
|
||||||
// Setup mouse cursor shape
|
|
||||||
ImGui_ImplAllegro5_UpdateMouseCursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,38 +0,0 @@
|
|||||||
// dear imgui: Renderer + Platform Backend for Allegro 5
|
|
||||||
// (Info: Allegro 5 is a cross-platform general purpose library for handling windows, inputs, graphics, etc.)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [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 ALLEGRO_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Clipboard support (from Allegro 5.1.12)
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// Issues:
|
|
||||||
// [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually.
|
|
||||||
// [ ] Platform: Missing gamepad support.
|
|
||||||
|
|
||||||
// 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 ALLEGRO_DISPLAY;
|
|
||||||
union ALLEGRO_EVENT;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplAllegro5_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplAllegro5_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* event);
|
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplAllegro5_CreateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,306 +0,0 @@
|
|||||||
// dear imgui: Platform Binding for Android native app
|
|
||||||
// This needs to be used along with the OpenGL 3 Renderer (imgui_impl_opengl3)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [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 AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen.
|
|
||||||
// Missing features:
|
|
||||||
// [ ] Platform: Clipboard support.
|
|
||||||
// [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [ ] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: Check if this is even possible with Android.
|
|
||||||
// Important:
|
|
||||||
// - Consider using SDL or GLFW backend on Android, which will be more full-featured than this.
|
|
||||||
// - FIXME: On-screen keyboard currently needs to be enabled by the application (see examples/ and issue #3446)
|
|
||||||
// - FIXME: Unicode character inputs needs to be passed by Dear ImGui by the application (see examples/ and issue #3446)
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
|
|
||||||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
|
||||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
|
||||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
|
||||||
// 2021-03-04: Initial version.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_android.h"
|
|
||||||
#include <time.h>
|
|
||||||
#include <android/native_window.h>
|
|
||||||
#include <android/input.h>
|
|
||||||
#include <android/keycodes.h>
|
|
||||||
#include <android/log.h>
|
|
||||||
|
|
||||||
// Android data
|
|
||||||
static double g_Time = 0.0;
|
|
||||||
static ANativeWindow* g_Window;
|
|
||||||
static char g_LogTag[] = "ImGuiExample";
|
|
||||||
|
|
||||||
static ImGuiKey ImGui_ImplAndroid_KeyCodeToImGuiKey(int32_t key_code)
|
|
||||||
{
|
|
||||||
switch (key_code)
|
|
||||||
{
|
|
||||||
case AKEYCODE_TAB: return ImGuiKey_Tab;
|
|
||||||
case AKEYCODE_DPAD_LEFT: return ImGuiKey_LeftArrow;
|
|
||||||
case AKEYCODE_DPAD_RIGHT: return ImGuiKey_RightArrow;
|
|
||||||
case AKEYCODE_DPAD_UP: return ImGuiKey_UpArrow;
|
|
||||||
case AKEYCODE_DPAD_DOWN: return ImGuiKey_DownArrow;
|
|
||||||
case AKEYCODE_PAGE_UP: return ImGuiKey_PageUp;
|
|
||||||
case AKEYCODE_PAGE_DOWN: return ImGuiKey_PageDown;
|
|
||||||
case AKEYCODE_MOVE_HOME: return ImGuiKey_Home;
|
|
||||||
case AKEYCODE_MOVE_END: return ImGuiKey_End;
|
|
||||||
case AKEYCODE_INSERT: return ImGuiKey_Insert;
|
|
||||||
case AKEYCODE_FORWARD_DEL: return ImGuiKey_Delete;
|
|
||||||
case AKEYCODE_DEL: return ImGuiKey_Backspace;
|
|
||||||
case AKEYCODE_SPACE: return ImGuiKey_Space;
|
|
||||||
case AKEYCODE_ENTER: return ImGuiKey_Enter;
|
|
||||||
case AKEYCODE_ESCAPE: return ImGuiKey_Escape;
|
|
||||||
case AKEYCODE_APOSTROPHE: return ImGuiKey_Apostrophe;
|
|
||||||
case AKEYCODE_COMMA: return ImGuiKey_Comma;
|
|
||||||
case AKEYCODE_MINUS: return ImGuiKey_Minus;
|
|
||||||
case AKEYCODE_PERIOD: return ImGuiKey_Period;
|
|
||||||
case AKEYCODE_SLASH: return ImGuiKey_Slash;
|
|
||||||
case AKEYCODE_SEMICOLON: return ImGuiKey_Semicolon;
|
|
||||||
case AKEYCODE_EQUALS: return ImGuiKey_Equal;
|
|
||||||
case AKEYCODE_LEFT_BRACKET: return ImGuiKey_LeftBracket;
|
|
||||||
case AKEYCODE_BACKSLASH: return ImGuiKey_Backslash;
|
|
||||||
case AKEYCODE_RIGHT_BRACKET: return ImGuiKey_RightBracket;
|
|
||||||
case AKEYCODE_GRAVE: return ImGuiKey_GraveAccent;
|
|
||||||
case AKEYCODE_CAPS_LOCK: return ImGuiKey_CapsLock;
|
|
||||||
case AKEYCODE_SCROLL_LOCK: return ImGuiKey_ScrollLock;
|
|
||||||
case AKEYCODE_NUM_LOCK: return ImGuiKey_NumLock;
|
|
||||||
case AKEYCODE_SYSRQ: return ImGuiKey_PrintScreen;
|
|
||||||
case AKEYCODE_BREAK: return ImGuiKey_Pause;
|
|
||||||
case AKEYCODE_NUMPAD_0: return ImGuiKey_Keypad0;
|
|
||||||
case AKEYCODE_NUMPAD_1: return ImGuiKey_Keypad1;
|
|
||||||
case AKEYCODE_NUMPAD_2: return ImGuiKey_Keypad2;
|
|
||||||
case AKEYCODE_NUMPAD_3: return ImGuiKey_Keypad3;
|
|
||||||
case AKEYCODE_NUMPAD_4: return ImGuiKey_Keypad4;
|
|
||||||
case AKEYCODE_NUMPAD_5: return ImGuiKey_Keypad5;
|
|
||||||
case AKEYCODE_NUMPAD_6: return ImGuiKey_Keypad6;
|
|
||||||
case AKEYCODE_NUMPAD_7: return ImGuiKey_Keypad7;
|
|
||||||
case AKEYCODE_NUMPAD_8: return ImGuiKey_Keypad8;
|
|
||||||
case AKEYCODE_NUMPAD_9: return ImGuiKey_Keypad9;
|
|
||||||
case AKEYCODE_NUMPAD_DOT: return ImGuiKey_KeypadDecimal;
|
|
||||||
case AKEYCODE_NUMPAD_DIVIDE: return ImGuiKey_KeypadDivide;
|
|
||||||
case AKEYCODE_NUMPAD_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
|
||||||
case AKEYCODE_NUMPAD_SUBTRACT: return ImGuiKey_KeypadSubtract;
|
|
||||||
case AKEYCODE_NUMPAD_ADD: return ImGuiKey_KeypadAdd;
|
|
||||||
case AKEYCODE_NUMPAD_ENTER: return ImGuiKey_KeypadEnter;
|
|
||||||
case AKEYCODE_NUMPAD_EQUALS: return ImGuiKey_KeypadEqual;
|
|
||||||
case AKEYCODE_CTRL_LEFT: return ImGuiKey_LeftCtrl;
|
|
||||||
case AKEYCODE_SHIFT_LEFT: return ImGuiKey_LeftShift;
|
|
||||||
case AKEYCODE_ALT_LEFT: return ImGuiKey_LeftAlt;
|
|
||||||
case AKEYCODE_META_LEFT: return ImGuiKey_LeftSuper;
|
|
||||||
case AKEYCODE_CTRL_RIGHT: return ImGuiKey_RightCtrl;
|
|
||||||
case AKEYCODE_SHIFT_RIGHT: return ImGuiKey_RightShift;
|
|
||||||
case AKEYCODE_ALT_RIGHT: return ImGuiKey_RightAlt;
|
|
||||||
case AKEYCODE_META_RIGHT: return ImGuiKey_RightSuper;
|
|
||||||
case AKEYCODE_MENU: return ImGuiKey_Menu;
|
|
||||||
case AKEYCODE_0: return ImGuiKey_0;
|
|
||||||
case AKEYCODE_1: return ImGuiKey_1;
|
|
||||||
case AKEYCODE_2: return ImGuiKey_2;
|
|
||||||
case AKEYCODE_3: return ImGuiKey_3;
|
|
||||||
case AKEYCODE_4: return ImGuiKey_4;
|
|
||||||
case AKEYCODE_5: return ImGuiKey_5;
|
|
||||||
case AKEYCODE_6: return ImGuiKey_6;
|
|
||||||
case AKEYCODE_7: return ImGuiKey_7;
|
|
||||||
case AKEYCODE_8: return ImGuiKey_8;
|
|
||||||
case AKEYCODE_9: return ImGuiKey_9;
|
|
||||||
case AKEYCODE_A: return ImGuiKey_A;
|
|
||||||
case AKEYCODE_B: return ImGuiKey_B;
|
|
||||||
case AKEYCODE_C: return ImGuiKey_C;
|
|
||||||
case AKEYCODE_D: return ImGuiKey_D;
|
|
||||||
case AKEYCODE_E: return ImGuiKey_E;
|
|
||||||
case AKEYCODE_F: return ImGuiKey_F;
|
|
||||||
case AKEYCODE_G: return ImGuiKey_G;
|
|
||||||
case AKEYCODE_H: return ImGuiKey_H;
|
|
||||||
case AKEYCODE_I: return ImGuiKey_I;
|
|
||||||
case AKEYCODE_J: return ImGuiKey_J;
|
|
||||||
case AKEYCODE_K: return ImGuiKey_K;
|
|
||||||
case AKEYCODE_L: return ImGuiKey_L;
|
|
||||||
case AKEYCODE_M: return ImGuiKey_M;
|
|
||||||
case AKEYCODE_N: return ImGuiKey_N;
|
|
||||||
case AKEYCODE_O: return ImGuiKey_O;
|
|
||||||
case AKEYCODE_P: return ImGuiKey_P;
|
|
||||||
case AKEYCODE_Q: return ImGuiKey_Q;
|
|
||||||
case AKEYCODE_R: return ImGuiKey_R;
|
|
||||||
case AKEYCODE_S: return ImGuiKey_S;
|
|
||||||
case AKEYCODE_T: return ImGuiKey_T;
|
|
||||||
case AKEYCODE_U: return ImGuiKey_U;
|
|
||||||
case AKEYCODE_V: return ImGuiKey_V;
|
|
||||||
case AKEYCODE_W: return ImGuiKey_W;
|
|
||||||
case AKEYCODE_X: return ImGuiKey_X;
|
|
||||||
case AKEYCODE_Y: return ImGuiKey_Y;
|
|
||||||
case AKEYCODE_Z: return ImGuiKey_Z;
|
|
||||||
case AKEYCODE_F1: return ImGuiKey_F1;
|
|
||||||
case AKEYCODE_F2: return ImGuiKey_F2;
|
|
||||||
case AKEYCODE_F3: return ImGuiKey_F3;
|
|
||||||
case AKEYCODE_F4: return ImGuiKey_F4;
|
|
||||||
case AKEYCODE_F5: return ImGuiKey_F5;
|
|
||||||
case AKEYCODE_F6: return ImGuiKey_F6;
|
|
||||||
case AKEYCODE_F7: return ImGuiKey_F7;
|
|
||||||
case AKEYCODE_F8: return ImGuiKey_F8;
|
|
||||||
case AKEYCODE_F9: return ImGuiKey_F9;
|
|
||||||
case AKEYCODE_F10: return ImGuiKey_F10;
|
|
||||||
case AKEYCODE_F11: return ImGuiKey_F11;
|
|
||||||
case AKEYCODE_F12: return ImGuiKey_F12;
|
|
||||||
default: return ImGuiKey_None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ImGui_ImplAndroid_HandleInputEvent(const AInputEvent* input_event)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
int32_t event_type = AInputEvent_getType(input_event);
|
|
||||||
switch (event_type)
|
|
||||||
{
|
|
||||||
case AINPUT_EVENT_TYPE_KEY:
|
|
||||||
{
|
|
||||||
int32_t event_key_code = AKeyEvent_getKeyCode(input_event);
|
|
||||||
int32_t event_scan_code = AKeyEvent_getScanCode(input_event);
|
|
||||||
int32_t event_action = AKeyEvent_getAction(input_event);
|
|
||||||
int32_t event_meta_state = AKeyEvent_getMetaState(input_event);
|
|
||||||
|
|
||||||
io.AddKeyEvent(ImGuiMod_Ctrl, (event_meta_state & AMETA_CTRL_ON) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Shift, (event_meta_state & AMETA_SHIFT_ON) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Alt, (event_meta_state & AMETA_ALT_ON) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Super, (event_meta_state & AMETA_META_ON) != 0);
|
|
||||||
|
|
||||||
switch (event_action)
|
|
||||||
{
|
|
||||||
// FIXME: AKEY_EVENT_ACTION_DOWN and AKEY_EVENT_ACTION_UP occur at once as soon as a touch pointer
|
|
||||||
// goes up from a key. We use a simple key event queue/ and process one event per key per frame in
|
|
||||||
// ImGui_ImplAndroid_NewFrame()...or consider using IO queue, if suitable: https://github.com/ocornut/imgui/issues/2787
|
|
||||||
case AKEY_EVENT_ACTION_DOWN:
|
|
||||||
case AKEY_EVENT_ACTION_UP:
|
|
||||||
{
|
|
||||||
ImGuiKey key = ImGui_ImplAndroid_KeyCodeToImGuiKey(event_key_code);
|
|
||||||
if (key != ImGuiKey_None)
|
|
||||||
{
|
|
||||||
io.AddKeyEvent(key, event_action == AKEY_EVENT_ACTION_DOWN);
|
|
||||||
io.SetKeyEventNativeData(key, event_key_code, event_scan_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AINPUT_EVENT_TYPE_MOTION:
|
|
||||||
{
|
|
||||||
int32_t event_action = AMotionEvent_getAction(input_event);
|
|
||||||
int32_t event_pointer_index = (event_action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
|
||||||
event_action &= AMOTION_EVENT_ACTION_MASK;
|
|
||||||
|
|
||||||
switch (AMotionEvent_getToolType(input_event, event_pointer_index))
|
|
||||||
{
|
|
||||||
case AMOTION_EVENT_TOOL_TYPE_MOUSE:
|
|
||||||
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
|
|
||||||
break;
|
|
||||||
case AMOTION_EVENT_TOOL_TYPE_STYLUS:
|
|
||||||
case AMOTION_EVENT_TOOL_TYPE_ERASER:
|
|
||||||
io.AddMouseSourceEvent(ImGuiMouseSource_Pen);
|
|
||||||
break;
|
|
||||||
case AMOTION_EVENT_TOOL_TYPE_FINGER:
|
|
||||||
default:
|
|
||||||
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event_action)
|
|
||||||
{
|
|
||||||
case AMOTION_EVENT_ACTION_DOWN:
|
|
||||||
case AMOTION_EVENT_ACTION_UP:
|
|
||||||
{
|
|
||||||
// Physical mouse buttons (and probably other physical devices) also invoke the actions AMOTION_EVENT_ACTION_DOWN/_UP,
|
|
||||||
// but we have to process them separately to identify the actual button pressed. This is done below via
|
|
||||||
// AMOTION_EVENT_ACTION_BUTTON_PRESS/_RELEASE. Here, we only process "FINGER" input (and "UNKNOWN", as a fallback).
|
|
||||||
int tool_type = AMotionEvent_getToolType(input_event, event_pointer_index);
|
|
||||||
if (tool_type == AMOTION_EVENT_TOOL_TYPE_FINGER || tool_type == AMOTION_EVENT_TOOL_TYPE_UNKNOWN)
|
|
||||||
{
|
|
||||||
io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
|
|
||||||
io.AddMouseButtonEvent(0, event_action == AMOTION_EVENT_ACTION_DOWN);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AMOTION_EVENT_ACTION_BUTTON_PRESS:
|
|
||||||
case AMOTION_EVENT_ACTION_BUTTON_RELEASE:
|
|
||||||
{
|
|
||||||
int32_t button_state = AMotionEvent_getButtonState(input_event);
|
|
||||||
io.AddMouseButtonEvent(0, (button_state & AMOTION_EVENT_BUTTON_PRIMARY) != 0);
|
|
||||||
io.AddMouseButtonEvent(1, (button_state & AMOTION_EVENT_BUTTON_SECONDARY) != 0);
|
|
||||||
io.AddMouseButtonEvent(2, (button_state & AMOTION_EVENT_BUTTON_TERTIARY) != 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AMOTION_EVENT_ACTION_HOVER_MOVE: // Hovering: Tool moves while NOT pressed (such as a physical mouse)
|
|
||||||
case AMOTION_EVENT_ACTION_MOVE: // Touch pointer moves while DOWN
|
|
||||||
io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
|
|
||||||
break;
|
|
||||||
case AMOTION_EVENT_ACTION_SCROLL:
|
|
||||||
io.AddMouseWheelEvent(AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_HSCROLL, event_pointer_index), AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_VSCROLL, event_pointer_index));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplAndroid_Init(ANativeWindow* window)
|
|
||||||
{
|
|
||||||
g_Window = window;
|
|
||||||
g_Time = 0.0;
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendPlatformName = "imgui_impl_android";
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplAndroid_Shutdown()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendPlatformName = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplAndroid_NewFrame()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
|
||||||
int32_t window_width = ANativeWindow_getWidth(g_Window);
|
|
||||||
int32_t window_height = ANativeWindow_getHeight(g_Window);
|
|
||||||
int display_width = window_width;
|
|
||||||
int display_height = window_height;
|
|
||||||
|
|
||||||
io.DisplaySize = ImVec2((float)window_width, (float)window_height);
|
|
||||||
if (window_width > 0 && window_height > 0)
|
|
||||||
io.DisplayFramebufferScale = ImVec2((float)display_width / window_width, (float)display_height / window_height);
|
|
||||||
|
|
||||||
// Setup time step
|
|
||||||
struct timespec current_timespec;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, ¤t_timespec);
|
|
||||||
double current_time = (double)(current_timespec.tv_sec) + (current_timespec.tv_nsec / 1000000000.0);
|
|
||||||
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f / 60.0f);
|
|
||||||
g_Time = current_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,36 +0,0 @@
|
|||||||
// dear imgui: Platform Binding for Android native app
|
|
||||||
// This needs to be used along with the OpenGL 3 Renderer (imgui_impl_opengl3)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [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 AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen.
|
|
||||||
// Missing features:
|
|
||||||
// [ ] Platform: Clipboard support.
|
|
||||||
// [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [ ] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: Check if this is even possible with Android.
|
|
||||||
// Important:
|
|
||||||
// - Consider using SDL or GLFW backend on Android, which will be more full-featured than this.
|
|
||||||
// - FIXME: On-screen keyboard currently needs to be enabled by the application (see examples/ and issue #3446)
|
|
||||||
// - FIXME: Unicode character inputs needs to be passed by Dear ImGui by the application (see examples/ and issue #3446)
|
|
||||||
|
|
||||||
// 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 ANativeWindow;
|
|
||||||
struct AInputEvent;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplAndroid_Init(ANativeWindow* window);
|
|
||||||
IMGUI_IMPL_API int32_t ImGui_ImplAndroid_HandleInputEvent(const AInputEvent* input_event);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplAndroid_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplAndroid_NewFrame();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,589 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX10
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 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-05-19: DirectX10: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
||||||
// 2021-02-18: DirectX10: Change blending equation to preserve alpha in output buffer.
|
|
||||||
// 2019-07-21: DirectX10: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData().
|
|
||||||
// 2019-05-29: DirectX10: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
||||||
// 2019-04-30: DirectX10: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
||||||
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
||||||
// 2018-07-13: DirectX10: Fixed unreleased resources in Init and Shutdown functions.
|
|
||||||
// 2018-06-08: Misc: Extracted imgui_impl_dx10.cpp/.h away from the old combined DX10+Win32 example.
|
|
||||||
// 2018-06-08: DirectX10: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
|
||||||
// 2018-04-09: Misc: Fixed erroneous call to io.Fonts->ClearInputData() + ClearTexData() that was left in DX10 example but removed in 1.47 (Nov 2015) on other backends.
|
|
||||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX10_RenderDrawData() in the .h file so you can call it yourself.
|
|
||||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
|
||||||
// 2016-05-07: DirectX10: Disabling depth-write.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_dx10.h"
|
|
||||||
|
|
||||||
// DirectX
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <d3d10_1.h>
|
|
||||||
#include <d3d10.h>
|
|
||||||
#include <d3dcompiler.h>
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// DirectX data
|
|
||||||
struct ImGui_ImplDX10_Data
|
|
||||||
{
|
|
||||||
ID3D10Device* pd3dDevice;
|
|
||||||
IDXGIFactory* pFactory;
|
|
||||||
ID3D10Buffer* pVB;
|
|
||||||
ID3D10Buffer* pIB;
|
|
||||||
ID3D10VertexShader* pVertexShader;
|
|
||||||
ID3D10InputLayout* pInputLayout;
|
|
||||||
ID3D10Buffer* pVertexConstantBuffer;
|
|
||||||
ID3D10PixelShader* pPixelShader;
|
|
||||||
ID3D10SamplerState* pFontSampler;
|
|
||||||
ID3D10ShaderResourceView* pFontTextureView;
|
|
||||||
ID3D10RasterizerState* pRasterizerState;
|
|
||||||
ID3D10BlendState* pBlendState;
|
|
||||||
ID3D10DepthStencilState* pDepthStencilState;
|
|
||||||
int VertexBufferSize;
|
|
||||||
int IndexBufferSize;
|
|
||||||
|
|
||||||
ImGui_ImplDX10_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VERTEX_CONSTANT_BUFFER_DX10
|
|
||||||
{
|
|
||||||
float mvp[4][4];
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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_ImplDX10_Data* ImGui_ImplDX10_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplDX10_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static void ImGui_ImplDX10_SetupRenderState(ImDrawData* draw_data, ID3D10Device* ctx)
|
|
||||||
{
|
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
|
||||||
|
|
||||||
// Setup viewport
|
|
||||||
D3D10_VIEWPORT vp;
|
|
||||||
memset(&vp, 0, sizeof(D3D10_VIEWPORT));
|
|
||||||
vp.Width = (UINT)draw_data->DisplaySize.x;
|
|
||||||
vp.Height = (UINT)draw_data->DisplaySize.y;
|
|
||||||
vp.MinDepth = 0.0f;
|
|
||||||
vp.MaxDepth = 1.0f;
|
|
||||||
vp.TopLeftX = vp.TopLeftY = 0;
|
|
||||||
ctx->RSSetViewports(1, &vp);
|
|
||||||
|
|
||||||
// Bind shader and vertex buffers
|
|
||||||
unsigned int stride = sizeof(ImDrawVert);
|
|
||||||
unsigned int offset = 0;
|
|
||||||
ctx->IASetInputLayout(bd->pInputLayout);
|
|
||||||
ctx->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset);
|
|
||||||
ctx->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
|
|
||||||
ctx->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
|
||||||
ctx->VSSetShader(bd->pVertexShader);
|
|
||||||
ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer);
|
|
||||||
ctx->PSSetShader(bd->pPixelShader);
|
|
||||||
ctx->PSSetSamplers(0, 1, &bd->pFontSampler);
|
|
||||||
ctx->GSSetShader(nullptr);
|
|
||||||
|
|
||||||
// Setup render state
|
|
||||||
const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
|
|
||||||
ctx->OMSetBlendState(bd->pBlendState, blend_factor, 0xffffffff);
|
|
||||||
ctx->OMSetDepthStencilState(bd->pDepthStencilState, 0);
|
|
||||||
ctx->RSSetState(bd->pRasterizerState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render function
|
|
||||||
void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
// Avoid rendering when minimized
|
|
||||||
if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
|
||||||
ID3D10Device* ctx = bd->pd3dDevice;
|
|
||||||
|
|
||||||
// Create and grow vertex/index buffers if needed
|
|
||||||
if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount)
|
|
||||||
{
|
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
|
||||||
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
|
||||||
D3D10_BUFFER_DESC desc;
|
|
||||||
memset(&desc, 0, sizeof(D3D10_BUFFER_DESC));
|
|
||||||
desc.Usage = D3D10_USAGE_DYNAMIC;
|
|
||||||
desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert);
|
|
||||||
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
|
||||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
|
||||||
desc.MiscFlags = 0;
|
|
||||||
if (ctx->CreateBuffer(&desc, nullptr, &bd->pVB) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
|
|
||||||
{
|
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
|
||||||
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
|
||||||
D3D10_BUFFER_DESC desc;
|
|
||||||
memset(&desc, 0, sizeof(D3D10_BUFFER_DESC));
|
|
||||||
desc.Usage = D3D10_USAGE_DYNAMIC;
|
|
||||||
desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx);
|
|
||||||
desc.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
|
||||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
|
||||||
if (ctx->CreateBuffer(&desc, nullptr, &bd->pIB) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy and convert all vertices into a single contiguous buffer
|
|
||||||
ImDrawVert* vtx_dst = nullptr;
|
|
||||||
ImDrawIdx* idx_dst = nullptr;
|
|
||||||
bd->pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst);
|
|
||||||
bd->pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst);
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
|
|
||||||
memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
|
||||||
vtx_dst += cmd_list->VtxBuffer.Size;
|
|
||||||
idx_dst += cmd_list->IdxBuffer.Size;
|
|
||||||
}
|
|
||||||
bd->pVB->Unmap();
|
|
||||||
bd->pIB->Unmap();
|
|
||||||
|
|
||||||
// Setup orthographic projection matrix into our constant buffer
|
|
||||||
// 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.
|
|
||||||
{
|
|
||||||
void* mapped_resource;
|
|
||||||
if (bd->pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
|
|
||||||
return;
|
|
||||||
VERTEX_CONSTANT_BUFFER_DX10* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX10*)mapped_resource;
|
|
||||||
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;
|
|
||||||
float mvp[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, 0.5f, 0.0f },
|
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
|
||||||
};
|
|
||||||
memcpy(&constant_buffer->mvp, mvp, sizeof(mvp));
|
|
||||||
bd->pVertexConstantBuffer->Unmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!)
|
|
||||||
struct BACKUP_DX10_STATE
|
|
||||||
{
|
|
||||||
UINT ScissorRectsCount, ViewportsCount;
|
|
||||||
D3D10_RECT ScissorRects[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
|
|
||||||
D3D10_VIEWPORT Viewports[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
|
|
||||||
ID3D10RasterizerState* RS;
|
|
||||||
ID3D10BlendState* BlendState;
|
|
||||||
FLOAT BlendFactor[4];
|
|
||||||
UINT SampleMask;
|
|
||||||
UINT StencilRef;
|
|
||||||
ID3D10DepthStencilState* DepthStencilState;
|
|
||||||
ID3D10ShaderResourceView* PSShaderResource;
|
|
||||||
ID3D10SamplerState* PSSampler;
|
|
||||||
ID3D10PixelShader* PS;
|
|
||||||
ID3D10VertexShader* VS;
|
|
||||||
ID3D10GeometryShader* GS;
|
|
||||||
D3D10_PRIMITIVE_TOPOLOGY PrimitiveTopology;
|
|
||||||
ID3D10Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer;
|
|
||||||
UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset;
|
|
||||||
DXGI_FORMAT IndexBufferFormat;
|
|
||||||
ID3D10InputLayout* InputLayout;
|
|
||||||
};
|
|
||||||
BACKUP_DX10_STATE old = {};
|
|
||||||
old.ScissorRectsCount = old.ViewportsCount = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
|
|
||||||
ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects);
|
|
||||||
ctx->RSGetViewports(&old.ViewportsCount, old.Viewports);
|
|
||||||
ctx->RSGetState(&old.RS);
|
|
||||||
ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask);
|
|
||||||
ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef);
|
|
||||||
ctx->PSGetShaderResources(0, 1, &old.PSShaderResource);
|
|
||||||
ctx->PSGetSamplers(0, 1, &old.PSSampler);
|
|
||||||
ctx->PSGetShader(&old.PS);
|
|
||||||
ctx->VSGetShader(&old.VS);
|
|
||||||
ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer);
|
|
||||||
ctx->GSGetShader(&old.GS);
|
|
||||||
ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology);
|
|
||||||
ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset);
|
|
||||||
ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset);
|
|
||||||
ctx->IAGetInputLayout(&old.InputLayout);
|
|
||||||
|
|
||||||
// Setup desired DX state
|
|
||||||
ImGui_ImplDX10_SetupRenderState(draw_data, ctx);
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
|
||||||
int global_vtx_offset = 0;
|
|
||||||
int global_idx_offset = 0;
|
|
||||||
ImVec2 clip_off = draw_data->DisplayPos;
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
||||||
{
|
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
||||||
if (pcmd->UserCallback)
|
|
||||||
{
|
|
||||||
// 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_ImplDX10_SetupRenderState(draw_data, ctx);
|
|
||||||
else
|
|
||||||
pcmd->UserCallback(cmd_list, pcmd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
|
|
||||||
ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Apply scissor/clipping rectangle
|
|
||||||
const D3D10_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };
|
|
||||||
ctx->RSSetScissorRects(1, &r);
|
|
||||||
|
|
||||||
// Bind texture, Draw
|
|
||||||
ID3D10ShaderResourceView* texture_srv = (ID3D10ShaderResourceView*)pcmd->GetTexID();
|
|
||||||
ctx->PSSetShaderResources(0, 1, &texture_srv);
|
|
||||||
ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
global_idx_offset += cmd_list->IdxBuffer.Size;
|
|
||||||
global_vtx_offset += cmd_list->VtxBuffer.Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore modified DX state
|
|
||||||
ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects);
|
|
||||||
ctx->RSSetViewports(old.ViewportsCount, old.Viewports);
|
|
||||||
ctx->RSSetState(old.RS); if (old.RS) old.RS->Release();
|
|
||||||
ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release();
|
|
||||||
ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release();
|
|
||||||
ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release();
|
|
||||||
ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release();
|
|
||||||
ctx->PSSetShader(old.PS); if (old.PS) old.PS->Release();
|
|
||||||
ctx->VSSetShader(old.VS); if (old.VS) old.VS->Release();
|
|
||||||
ctx->GSSetShader(old.GS); if (old.GS) old.GS->Release();
|
|
||||||
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release();
|
|
||||||
ctx->IASetPrimitiveTopology(old.PrimitiveTopology);
|
|
||||||
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release();
|
|
||||||
ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release();
|
|
||||||
ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplDX10_CreateFontsTexture()
|
|
||||||
{
|
|
||||||
// Build texture atlas
|
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
unsigned char* pixels;
|
|
||||||
int width, height;
|
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
|
||||||
|
|
||||||
// Upload texture to graphics system
|
|
||||||
{
|
|
||||||
D3D10_TEXTURE2D_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.Width = width;
|
|
||||||
desc.Height = height;
|
|
||||||
desc.MipLevels = 1;
|
|
||||||
desc.ArraySize = 1;
|
|
||||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
|
||||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
|
||||||
desc.CPUAccessFlags = 0;
|
|
||||||
|
|
||||||
ID3D10Texture2D* pTexture = nullptr;
|
|
||||||
D3D10_SUBRESOURCE_DATA subResource;
|
|
||||||
subResource.pSysMem = pixels;
|
|
||||||
subResource.SysMemPitch = desc.Width * 4;
|
|
||||||
subResource.SysMemSlicePitch = 0;
|
|
||||||
bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture);
|
|
||||||
IM_ASSERT(pTexture != nullptr);
|
|
||||||
|
|
||||||
// Create texture view
|
|
||||||
D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
|
|
||||||
ZeroMemory(&srv_desc, sizeof(srv_desc));
|
|
||||||
srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
|
|
||||||
srv_desc.Texture2D.MipLevels = desc.MipLevels;
|
|
||||||
srv_desc.Texture2D.MostDetailedMip = 0;
|
|
||||||
bd->pd3dDevice->CreateShaderResourceView(pTexture, &srv_desc, &bd->pFontTextureView);
|
|
||||||
pTexture->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store our identifier
|
|
||||||
io.Fonts->SetTexID((ImTextureID)bd->pFontTextureView);
|
|
||||||
|
|
||||||
// Create texture sampler
|
|
||||||
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
|
||||||
{
|
|
||||||
D3D10_SAMPLER_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
|
|
||||||
desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
|
|
||||||
desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
|
|
||||||
desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
|
|
||||||
desc.MipLODBias = 0.f;
|
|
||||||
desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
|
|
||||||
desc.MinLOD = 0.f;
|
|
||||||
desc.MaxLOD = 0.f;
|
|
||||||
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pFontSampler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX10_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
|
||||||
if (!bd->pd3dDevice)
|
|
||||||
return false;
|
|
||||||
if (bd->pFontSampler)
|
|
||||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
|
||||||
|
|
||||||
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
|
|
||||||
// If you would like to use this DX10 sample code but remove this dependency you can:
|
|
||||||
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution]
|
|
||||||
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
|
||||||
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
|
||||||
|
|
||||||
// Create the vertex shader
|
|
||||||
{
|
|
||||||
static const char* vertexShader =
|
|
||||||
"cbuffer vertexBuffer : register(b0) \
|
|
||||||
{\
|
|
||||||
float4x4 ProjectionMatrix; \
|
|
||||||
};\
|
|
||||||
struct VS_INPUT\
|
|
||||||
{\
|
|
||||||
float2 pos : POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
\
|
|
||||||
struct PS_INPUT\
|
|
||||||
{\
|
|
||||||
float4 pos : SV_POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
\
|
|
||||||
PS_INPUT main(VS_INPUT input)\
|
|
||||||
{\
|
|
||||||
PS_INPUT output;\
|
|
||||||
output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
|
|
||||||
output.col = input.col;\
|
|
||||||
output.uv = input.uv;\
|
|
||||||
return output;\
|
|
||||||
}";
|
|
||||||
|
|
||||||
ID3DBlob* vertexShaderBlob;
|
|
||||||
if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr)))
|
|
||||||
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
||||||
if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pVertexShader) != S_OK)
|
|
||||||
{
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the input layout
|
|
||||||
D3D10_INPUT_ELEMENT_DESC local_layout[] =
|
|
||||||
{
|
|
||||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, pos), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
|
||||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, uv), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
|
||||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)offsetof(ImDrawVert, col), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
|
||||||
};
|
|
||||||
if (bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pInputLayout) != S_OK)
|
|
||||||
{
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
|
|
||||||
// Create the constant buffer
|
|
||||||
{
|
|
||||||
D3D10_BUFFER_DESC desc;
|
|
||||||
desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX10);
|
|
||||||
desc.Usage = D3D10_USAGE_DYNAMIC;
|
|
||||||
desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
|
|
||||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
|
||||||
desc.MiscFlags = 0;
|
|
||||||
bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the pixel shader
|
|
||||||
{
|
|
||||||
static const char* pixelShader =
|
|
||||||
"struct PS_INPUT\
|
|
||||||
{\
|
|
||||||
float4 pos : SV_POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
sampler sampler0;\
|
|
||||||
Texture2D texture0;\
|
|
||||||
\
|
|
||||||
float4 main(PS_INPUT input) : SV_Target\
|
|
||||||
{\
|
|
||||||
float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \
|
|
||||||
return out_col; \
|
|
||||||
}";
|
|
||||||
|
|
||||||
ID3DBlob* pixelShaderBlob;
|
|
||||||
if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr)))
|
|
||||||
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
||||||
if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), &bd->pPixelShader) != S_OK)
|
|
||||||
{
|
|
||||||
pixelShaderBlob->Release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
pixelShaderBlob->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the blending setup
|
|
||||||
{
|
|
||||||
D3D10_BLEND_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.AlphaToCoverageEnable = false;
|
|
||||||
desc.BlendEnable[0] = true;
|
|
||||||
desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
|
|
||||||
desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
|
|
||||||
desc.BlendOp = D3D10_BLEND_OP_ADD;
|
|
||||||
desc.SrcBlendAlpha = D3D10_BLEND_ONE;
|
|
||||||
desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
|
|
||||||
desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
|
|
||||||
desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
|
|
||||||
bd->pd3dDevice->CreateBlendState(&desc, &bd->pBlendState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the rasterizer state
|
|
||||||
{
|
|
||||||
D3D10_RASTERIZER_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.FillMode = D3D10_FILL_SOLID;
|
|
||||||
desc.CullMode = D3D10_CULL_NONE;
|
|
||||||
desc.ScissorEnable = true;
|
|
||||||
desc.DepthClipEnable = true;
|
|
||||||
bd->pd3dDevice->CreateRasterizerState(&desc, &bd->pRasterizerState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create depth-stencil State
|
|
||||||
{
|
|
||||||
D3D10_DEPTH_STENCIL_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.DepthEnable = false;
|
|
||||||
desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
|
|
||||||
desc.DepthFunc = D3D10_COMPARISON_ALWAYS;
|
|
||||||
desc.StencilEnable = false;
|
|
||||||
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
|
|
||||||
desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
|
|
||||||
desc.BackFace = desc.FrontFace;
|
|
||||||
bd->pd3dDevice->CreateDepthStencilState(&desc, &bd->pDepthStencilState);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplDX10_CreateFontsTexture();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX10_InvalidateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
|
||||||
if (!bd->pd3dDevice)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; }
|
|
||||||
if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
|
||||||
if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; }
|
|
||||||
if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; }
|
|
||||||
if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; }
|
|
||||||
if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; }
|
|
||||||
if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; }
|
|
||||||
if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; }
|
|
||||||
if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; }
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX10_Init(ID3D10Device* device)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplDX10_Data* bd = IM_NEW(ImGui_ImplDX10_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_dx10";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
|
|
||||||
// Get factory from device
|
|
||||||
IDXGIDevice* pDXGIDevice = nullptr;
|
|
||||||
IDXGIAdapter* pDXGIAdapter = nullptr;
|
|
||||||
IDXGIFactory* pFactory = nullptr;
|
|
||||||
if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK)
|
|
||||||
if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK)
|
|
||||||
if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK)
|
|
||||||
{
|
|
||||||
bd->pd3dDevice = device;
|
|
||||||
bd->pFactory = pFactory;
|
|
||||||
}
|
|
||||||
if (pDXGIDevice) pDXGIDevice->Release();
|
|
||||||
if (pDXGIAdapter) pDXGIAdapter->Release();
|
|
||||||
bd->pd3dDevice->AddRef();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX10_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
|
||||||
if (bd->pFactory) { bd->pFactory->Release(); }
|
|
||||||
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX10_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX10_Init()?");
|
|
||||||
|
|
||||||
if (!bd->pFontSampler)
|
|
||||||
ImGui_ImplDX10_CreateDeviceObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,31 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX10
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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 ID3D10Device;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX10_Init(ID3D10Device* device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX10_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX10_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX10_InvalidateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX10_CreateDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,605 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX11
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 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-05-19: DirectX11: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
||||||
// 2021-02-18: DirectX11: Change blending equation to preserve alpha in output buffer.
|
|
||||||
// 2019-08-01: DirectX11: Fixed code querying the Geometry Shader state (would generally error with Debug layer enabled).
|
|
||||||
// 2019-07-21: DirectX11: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData. Clearing Hull/Domain/Compute shaders without backup/restore.
|
|
||||||
// 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
||||||
// 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
||||||
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
||||||
// 2018-08-01: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility.
|
|
||||||
// 2018-07-13: DirectX11: Fixed unreleased resources in Init and Shutdown functions.
|
|
||||||
// 2018-06-08: Misc: Extracted imgui_impl_dx11.cpp/.h away from the old combined DX11+Win32 example.
|
|
||||||
// 2018-06-08: DirectX11: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
|
||||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX11_RenderDrawData() in the .h file so you can call it yourself.
|
|
||||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
|
||||||
// 2016-05-07: DirectX11: Disabling depth-write.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_dx11.h"
|
|
||||||
|
|
||||||
// DirectX
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <d3d11.h>
|
|
||||||
#include <d3dcompiler.h>
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// DirectX11 data
|
|
||||||
struct ImGui_ImplDX11_Data
|
|
||||||
{
|
|
||||||
ID3D11Device* pd3dDevice;
|
|
||||||
ID3D11DeviceContext* pd3dDeviceContext;
|
|
||||||
IDXGIFactory* pFactory;
|
|
||||||
ID3D11Buffer* pVB;
|
|
||||||
ID3D11Buffer* pIB;
|
|
||||||
ID3D11VertexShader* pVertexShader;
|
|
||||||
ID3D11InputLayout* pInputLayout;
|
|
||||||
ID3D11Buffer* pVertexConstantBuffer;
|
|
||||||
ID3D11PixelShader* pPixelShader;
|
|
||||||
ID3D11SamplerState* pFontSampler;
|
|
||||||
ID3D11ShaderResourceView* pFontTextureView;
|
|
||||||
ID3D11RasterizerState* pRasterizerState;
|
|
||||||
ID3D11BlendState* pBlendState;
|
|
||||||
ID3D11DepthStencilState* pDepthStencilState;
|
|
||||||
int VertexBufferSize;
|
|
||||||
int IndexBufferSize;
|
|
||||||
|
|
||||||
ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VERTEX_CONSTANT_BUFFER_DX11
|
|
||||||
{
|
|
||||||
float mvp[4][4];
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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_ImplDX11_Data* ImGui_ImplDX11_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceContext* ctx)
|
|
||||||
{
|
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
|
||||||
|
|
||||||
// Setup viewport
|
|
||||||
D3D11_VIEWPORT vp;
|
|
||||||
memset(&vp, 0, sizeof(D3D11_VIEWPORT));
|
|
||||||
vp.Width = draw_data->DisplaySize.x;
|
|
||||||
vp.Height = draw_data->DisplaySize.y;
|
|
||||||
vp.MinDepth = 0.0f;
|
|
||||||
vp.MaxDepth = 1.0f;
|
|
||||||
vp.TopLeftX = vp.TopLeftY = 0;
|
|
||||||
ctx->RSSetViewports(1, &vp);
|
|
||||||
|
|
||||||
// Setup shader and vertex buffers
|
|
||||||
unsigned int stride = sizeof(ImDrawVert);
|
|
||||||
unsigned int offset = 0;
|
|
||||||
ctx->IASetInputLayout(bd->pInputLayout);
|
|
||||||
ctx->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset);
|
|
||||||
ctx->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
|
|
||||||
ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
|
||||||
ctx->VSSetShader(bd->pVertexShader, nullptr, 0);
|
|
||||||
ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer);
|
|
||||||
ctx->PSSetShader(bd->pPixelShader, nullptr, 0);
|
|
||||||
ctx->PSSetSamplers(0, 1, &bd->pFontSampler);
|
|
||||||
ctx->GSSetShader(nullptr, nullptr, 0);
|
|
||||||
ctx->HSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used..
|
|
||||||
ctx->DSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used..
|
|
||||||
ctx->CSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used..
|
|
||||||
|
|
||||||
// Setup blend state
|
|
||||||
const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
|
|
||||||
ctx->OMSetBlendState(bd->pBlendState, blend_factor, 0xffffffff);
|
|
||||||
ctx->OMSetDepthStencilState(bd->pDepthStencilState, 0);
|
|
||||||
ctx->RSSetState(bd->pRasterizerState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render function
|
|
||||||
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
// Avoid rendering when minimized
|
|
||||||
if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
|
||||||
ID3D11DeviceContext* ctx = bd->pd3dDeviceContext;
|
|
||||||
|
|
||||||
// Create and grow vertex/index buffers if needed
|
|
||||||
if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount)
|
|
||||||
{
|
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
|
||||||
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
|
||||||
D3D11_BUFFER_DESC desc;
|
|
||||||
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
|
|
||||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
||||||
desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert);
|
|
||||||
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
||||||
desc.MiscFlags = 0;
|
|
||||||
if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVB) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
|
|
||||||
{
|
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
|
||||||
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
|
||||||
D3D11_BUFFER_DESC desc;
|
|
||||||
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
|
|
||||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
||||||
desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx);
|
|
||||||
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
||||||
if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pIB) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upload vertex/index data into a single contiguous GPU buffer
|
|
||||||
D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource;
|
|
||||||
if (ctx->Map(bd->pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK)
|
|
||||||
return;
|
|
||||||
if (ctx->Map(bd->pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK)
|
|
||||||
return;
|
|
||||||
ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData;
|
|
||||||
ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData;
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
|
|
||||||
memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
|
||||||
vtx_dst += cmd_list->VtxBuffer.Size;
|
|
||||||
idx_dst += cmd_list->IdxBuffer.Size;
|
|
||||||
}
|
|
||||||
ctx->Unmap(bd->pVB, 0);
|
|
||||||
ctx->Unmap(bd->pIB, 0);
|
|
||||||
|
|
||||||
// Setup orthographic projection matrix into our constant buffer
|
|
||||||
// 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.
|
|
||||||
{
|
|
||||||
D3D11_MAPPED_SUBRESOURCE mapped_resource;
|
|
||||||
if (ctx->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
|
|
||||||
return;
|
|
||||||
VERTEX_CONSTANT_BUFFER_DX11* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX11*)mapped_resource.pData;
|
|
||||||
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;
|
|
||||||
float mvp[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, 0.5f, 0.0f },
|
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
|
||||||
};
|
|
||||||
memcpy(&constant_buffer->mvp, mvp, sizeof(mvp));
|
|
||||||
ctx->Unmap(bd->pVertexConstantBuffer, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!)
|
|
||||||
struct BACKUP_DX11_STATE
|
|
||||||
{
|
|
||||||
UINT ScissorRectsCount, ViewportsCount;
|
|
||||||
D3D11_RECT ScissorRects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
|
|
||||||
D3D11_VIEWPORT Viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
|
|
||||||
ID3D11RasterizerState* RS;
|
|
||||||
ID3D11BlendState* BlendState;
|
|
||||||
FLOAT BlendFactor[4];
|
|
||||||
UINT SampleMask;
|
|
||||||
UINT StencilRef;
|
|
||||||
ID3D11DepthStencilState* DepthStencilState;
|
|
||||||
ID3D11ShaderResourceView* PSShaderResource;
|
|
||||||
ID3D11SamplerState* PSSampler;
|
|
||||||
ID3D11PixelShader* PS;
|
|
||||||
ID3D11VertexShader* VS;
|
|
||||||
ID3D11GeometryShader* GS;
|
|
||||||
UINT PSInstancesCount, VSInstancesCount, GSInstancesCount;
|
|
||||||
ID3D11ClassInstance *PSInstances[256], *VSInstances[256], *GSInstances[256]; // 256 is max according to PSSetShader documentation
|
|
||||||
D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology;
|
|
||||||
ID3D11Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer;
|
|
||||||
UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset;
|
|
||||||
DXGI_FORMAT IndexBufferFormat;
|
|
||||||
ID3D11InputLayout* InputLayout;
|
|
||||||
};
|
|
||||||
BACKUP_DX11_STATE old = {};
|
|
||||||
old.ScissorRectsCount = old.ViewportsCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
|
|
||||||
ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects);
|
|
||||||
ctx->RSGetViewports(&old.ViewportsCount, old.Viewports);
|
|
||||||
ctx->RSGetState(&old.RS);
|
|
||||||
ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask);
|
|
||||||
ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef);
|
|
||||||
ctx->PSGetShaderResources(0, 1, &old.PSShaderResource);
|
|
||||||
ctx->PSGetSamplers(0, 1, &old.PSSampler);
|
|
||||||
old.PSInstancesCount = old.VSInstancesCount = old.GSInstancesCount = 256;
|
|
||||||
ctx->PSGetShader(&old.PS, old.PSInstances, &old.PSInstancesCount);
|
|
||||||
ctx->VSGetShader(&old.VS, old.VSInstances, &old.VSInstancesCount);
|
|
||||||
ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer);
|
|
||||||
ctx->GSGetShader(&old.GS, old.GSInstances, &old.GSInstancesCount);
|
|
||||||
|
|
||||||
ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology);
|
|
||||||
ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset);
|
|
||||||
ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset);
|
|
||||||
ctx->IAGetInputLayout(&old.InputLayout);
|
|
||||||
|
|
||||||
// Setup desired DX state
|
|
||||||
ImGui_ImplDX11_SetupRenderState(draw_data, ctx);
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
|
||||||
int global_idx_offset = 0;
|
|
||||||
int global_vtx_offset = 0;
|
|
||||||
ImVec2 clip_off = draw_data->DisplayPos;
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
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_ImplDX11_SetupRenderState(draw_data, ctx);
|
|
||||||
else
|
|
||||||
pcmd->UserCallback(cmd_list, pcmd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
|
|
||||||
ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Apply scissor/clipping rectangle
|
|
||||||
const D3D11_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };
|
|
||||||
ctx->RSSetScissorRects(1, &r);
|
|
||||||
|
|
||||||
// Bind texture, Draw
|
|
||||||
ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->GetTexID();
|
|
||||||
ctx->PSSetShaderResources(0, 1, &texture_srv);
|
|
||||||
ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
global_idx_offset += cmd_list->IdxBuffer.Size;
|
|
||||||
global_vtx_offset += cmd_list->VtxBuffer.Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore modified DX state
|
|
||||||
ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects);
|
|
||||||
ctx->RSSetViewports(old.ViewportsCount, old.Viewports);
|
|
||||||
ctx->RSSetState(old.RS); if (old.RS) old.RS->Release();
|
|
||||||
ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release();
|
|
||||||
ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release();
|
|
||||||
ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release();
|
|
||||||
ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release();
|
|
||||||
ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount); if (old.PS) old.PS->Release();
|
|
||||||
for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release();
|
|
||||||
ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release();
|
|
||||||
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release();
|
|
||||||
ctx->GSSetShader(old.GS, old.GSInstances, old.GSInstancesCount); if (old.GS) old.GS->Release();
|
|
||||||
for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release();
|
|
||||||
ctx->IASetPrimitiveTopology(old.PrimitiveTopology);
|
|
||||||
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release();
|
|
||||||
ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release();
|
|
||||||
ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplDX11_CreateFontsTexture()
|
|
||||||
{
|
|
||||||
// Build texture atlas
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
|
||||||
unsigned char* pixels;
|
|
||||||
int width, height;
|
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
|
||||||
|
|
||||||
// Upload texture to graphics system
|
|
||||||
{
|
|
||||||
D3D11_TEXTURE2D_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.Width = width;
|
|
||||||
desc.Height = height;
|
|
||||||
desc.MipLevels = 1;
|
|
||||||
desc.ArraySize = 1;
|
|
||||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
|
||||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
|
||||||
desc.CPUAccessFlags = 0;
|
|
||||||
|
|
||||||
ID3D11Texture2D* pTexture = nullptr;
|
|
||||||
D3D11_SUBRESOURCE_DATA subResource;
|
|
||||||
subResource.pSysMem = pixels;
|
|
||||||
subResource.SysMemPitch = desc.Width * 4;
|
|
||||||
subResource.SysMemSlicePitch = 0;
|
|
||||||
bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture);
|
|
||||||
IM_ASSERT(pTexture != nullptr);
|
|
||||||
|
|
||||||
// Create texture view
|
|
||||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
|
||||||
ZeroMemory(&srvDesc, sizeof(srvDesc));
|
|
||||||
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
|
||||||
srvDesc.Texture2D.MipLevels = desc.MipLevels;
|
|
||||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
|
||||||
bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &bd->pFontTextureView);
|
|
||||||
pTexture->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store our identifier
|
|
||||||
io.Fonts->SetTexID((ImTextureID)bd->pFontTextureView);
|
|
||||||
|
|
||||||
// Create texture sampler
|
|
||||||
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
|
||||||
{
|
|
||||||
D3D11_SAMPLER_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
|
||||||
desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
desc.MipLODBias = 0.f;
|
|
||||||
desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
|
||||||
desc.MinLOD = 0.f;
|
|
||||||
desc.MaxLOD = 0.f;
|
|
||||||
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pFontSampler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX11_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
|
||||||
if (!bd->pd3dDevice)
|
|
||||||
return false;
|
|
||||||
if (bd->pFontSampler)
|
|
||||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
|
||||||
|
|
||||||
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
|
|
||||||
// If you would like to use this DX11 sample code but remove this dependency you can:
|
|
||||||
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution]
|
|
||||||
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
|
||||||
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
|
||||||
|
|
||||||
// Create the vertex shader
|
|
||||||
{
|
|
||||||
static const char* vertexShader =
|
|
||||||
"cbuffer vertexBuffer : register(b0) \
|
|
||||||
{\
|
|
||||||
float4x4 ProjectionMatrix; \
|
|
||||||
};\
|
|
||||||
struct VS_INPUT\
|
|
||||||
{\
|
|
||||||
float2 pos : POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
\
|
|
||||||
struct PS_INPUT\
|
|
||||||
{\
|
|
||||||
float4 pos : SV_POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
\
|
|
||||||
PS_INPUT main(VS_INPUT input)\
|
|
||||||
{\
|
|
||||||
PS_INPUT output;\
|
|
||||||
output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
|
|
||||||
output.col = input.col;\
|
|
||||||
output.uv = input.uv;\
|
|
||||||
return output;\
|
|
||||||
}";
|
|
||||||
|
|
||||||
ID3DBlob* vertexShaderBlob;
|
|
||||||
if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr)))
|
|
||||||
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
||||||
if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK)
|
|
||||||
{
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the input layout
|
|
||||||
D3D11_INPUT_ELEMENT_DESC local_layout[] =
|
|
||||||
{
|
|
||||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
||||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
||||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)offsetof(ImDrawVert, col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
||||||
};
|
|
||||||
if (bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pInputLayout) != S_OK)
|
|
||||||
{
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
|
|
||||||
// Create the constant buffer
|
|
||||||
{
|
|
||||||
D3D11_BUFFER_DESC desc;
|
|
||||||
desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX11);
|
|
||||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
||||||
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
||||||
desc.MiscFlags = 0;
|
|
||||||
bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the pixel shader
|
|
||||||
{
|
|
||||||
static const char* pixelShader =
|
|
||||||
"struct PS_INPUT\
|
|
||||||
{\
|
|
||||||
float4 pos : SV_POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
sampler sampler0;\
|
|
||||||
Texture2D texture0;\
|
|
||||||
\
|
|
||||||
float4 main(PS_INPUT input) : SV_Target\
|
|
||||||
{\
|
|
||||||
float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \
|
|
||||||
return out_col; \
|
|
||||||
}";
|
|
||||||
|
|
||||||
ID3DBlob* pixelShaderBlob;
|
|
||||||
if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr)))
|
|
||||||
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
||||||
if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &bd->pPixelShader) != S_OK)
|
|
||||||
{
|
|
||||||
pixelShaderBlob->Release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
pixelShaderBlob->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the blending setup
|
|
||||||
{
|
|
||||||
D3D11_BLEND_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.AlphaToCoverageEnable = false;
|
|
||||||
desc.RenderTarget[0].BlendEnable = true;
|
|
||||||
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
|
||||||
desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
|
||||||
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
|
|
||||||
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
|
||||||
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
|
||||||
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
|
||||||
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
|
||||||
bd->pd3dDevice->CreateBlendState(&desc, &bd->pBlendState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the rasterizer state
|
|
||||||
{
|
|
||||||
D3D11_RASTERIZER_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.FillMode = D3D11_FILL_SOLID;
|
|
||||||
desc.CullMode = D3D11_CULL_NONE;
|
|
||||||
desc.ScissorEnable = true;
|
|
||||||
desc.DepthClipEnable = true;
|
|
||||||
bd->pd3dDevice->CreateRasterizerState(&desc, &bd->pRasterizerState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create depth-stencil State
|
|
||||||
{
|
|
||||||
D3D11_DEPTH_STENCIL_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.DepthEnable = false;
|
|
||||||
desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
|
||||||
desc.DepthFunc = D3D11_COMPARISON_ALWAYS;
|
|
||||||
desc.StencilEnable = false;
|
|
||||||
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
||||||
desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
||||||
desc.BackFace = desc.FrontFace;
|
|
||||||
bd->pd3dDevice->CreateDepthStencilState(&desc, &bd->pDepthStencilState);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplDX11_CreateFontsTexture();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX11_InvalidateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
|
||||||
if (!bd->pd3dDevice)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; }
|
|
||||||
if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied data->pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
|
||||||
if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; }
|
|
||||||
if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; }
|
|
||||||
if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; }
|
|
||||||
if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; }
|
|
||||||
if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; }
|
|
||||||
if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; }
|
|
||||||
if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; }
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplDX11_Data* bd = IM_NEW(ImGui_ImplDX11_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_dx11";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
|
|
||||||
// Get factory from device
|
|
||||||
IDXGIDevice* pDXGIDevice = nullptr;
|
|
||||||
IDXGIAdapter* pDXGIAdapter = nullptr;
|
|
||||||
IDXGIFactory* pFactory = nullptr;
|
|
||||||
|
|
||||||
if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK)
|
|
||||||
if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK)
|
|
||||||
if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK)
|
|
||||||
{
|
|
||||||
bd->pd3dDevice = device;
|
|
||||||
bd->pd3dDeviceContext = device_context;
|
|
||||||
bd->pFactory = pFactory;
|
|
||||||
}
|
|
||||||
if (pDXGIDevice) pDXGIDevice->Release();
|
|
||||||
if (pDXGIAdapter) pDXGIAdapter->Release();
|
|
||||||
bd->pd3dDevice->AddRef();
|
|
||||||
bd->pd3dDeviceContext->AddRef();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX11_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
|
||||||
if (bd->pFactory) { bd->pFactory->Release(); }
|
|
||||||
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
|
||||||
if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); }
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX11_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX11_Init()?");
|
|
||||||
|
|
||||||
if (!bd->pFontSampler)
|
|
||||||
ImGui_ImplDX11_CreateDeviceObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,32 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX11
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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 ID3D11Device;
|
|
||||||
struct ID3D11DeviceContext;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,761 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX12
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'.
|
|
||||||
// This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*.
|
|
||||||
// To build this on 32-bit systems:
|
|
||||||
// - [Solution 1] IDE/msbuild: in "Properties/C++/Preprocessor Definitions" add 'ImTextureID=ImU64' (this is what we do in the 'example_win32_direct12/example_win32_direct12.vcxproj' project file)
|
|
||||||
// - [Solution 2] IDE/msbuild: in "Properties/C++/Preprocessor Definitions" add 'IMGUI_USER_CONFIG="my_imgui_config.h"' and inside 'my_imgui_config.h' add '#define ImTextureID ImU64' and as many other options as you like.
|
|
||||||
// - [Solution 3] IDE/msbuild: edit imconfig.h and add '#define ImTextureID ImU64' (prefer solution 2 to create your own config file!)
|
|
||||||
// - [Solution 4] command-line: add '/D ImTextureID=ImU64' to your cl.exe command-line (this is what we do in the example_win32_direct12/build_win32.bat file)
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 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-05-19: DirectX12: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
||||||
// 2021-02-18: DirectX12: Change blending equation to preserve alpha in output buffer.
|
|
||||||
// 2021-01-11: DirectX12: Improve Windows 7 compatibility (for D3D12On7) by loading d3d12.dll dynamically.
|
|
||||||
// 2020-09-16: DirectX12: Avoid rendering calls with zero-sized scissor rectangle since it generates a validation layer warning.
|
|
||||||
// 2020-09-08: DirectX12: Clarified support for building on 32-bit systems by redefining ImTextureID.
|
|
||||||
// 2019-10-18: DirectX12: *BREAKING CHANGE* Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function.
|
|
||||||
// 2019-05-29: DirectX12: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
||||||
// 2019-04-30: DirectX12: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
||||||
// 2019-03-29: Misc: Various minor tidying up.
|
|
||||||
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
||||||
// 2018-06-12: DirectX12: Moved the ID3D12GraphicsCommandList* parameter from NewFrame() to RenderDrawData().
|
|
||||||
// 2018-06-08: Misc: Extracted imgui_impl_dx12.cpp/.h away from the old combined DX12+Win32 example.
|
|
||||||
// 2018-06-08: DirectX12: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle (to ease support for future multi-viewport).
|
|
||||||
// 2018-02-22: Merged into master with all Win32 code synchronized to other examples.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_dx12.h"
|
|
||||||
|
|
||||||
// DirectX
|
|
||||||
#include <d3d12.h>
|
|
||||||
#include <dxgi1_4.h>
|
|
||||||
#include <d3dcompiler.h>
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// DirectX data
|
|
||||||
struct ImGui_ImplDX12_RenderBuffers;
|
|
||||||
struct ImGui_ImplDX12_Data
|
|
||||||
{
|
|
||||||
ID3D12Device* pd3dDevice;
|
|
||||||
ID3D12RootSignature* pRootSignature;
|
|
||||||
ID3D12PipelineState* pPipelineState;
|
|
||||||
DXGI_FORMAT RTVFormat;
|
|
||||||
ID3D12Resource* pFontTextureResource;
|
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE hFontSrvCpuDescHandle;
|
|
||||||
D3D12_GPU_DESCRIPTOR_HANDLE hFontSrvGpuDescHandle;
|
|
||||||
ID3D12DescriptorHeap* pd3dSrvDescHeap;
|
|
||||||
UINT numFramesInFlight;
|
|
||||||
|
|
||||||
ImGui_ImplDX12_RenderBuffers* pFrameResources;
|
|
||||||
UINT frameIndex;
|
|
||||||
|
|
||||||
ImGui_ImplDX12_Data() { memset((void*)this, 0, sizeof(*this)); frameIndex = UINT_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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_ImplDX12_Data* ImGui_ImplDX12_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplDX12_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Buffers used during the rendering of a frame
|
|
||||||
struct ImGui_ImplDX12_RenderBuffers
|
|
||||||
{
|
|
||||||
ID3D12Resource* IndexBuffer;
|
|
||||||
ID3D12Resource* VertexBuffer;
|
|
||||||
int IndexBufferSize;
|
|
||||||
int VertexBufferSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VERTEX_CONSTANT_BUFFER_DX12
|
|
||||||
{
|
|
||||||
float mvp[4][4];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12GraphicsCommandList* ctx, ImGui_ImplDX12_RenderBuffers* fr)
|
|
||||||
{
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
||||||
|
|
||||||
// Setup orthographic projection matrix into our constant buffer
|
|
||||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
|
||||||
VERTEX_CONSTANT_BUFFER_DX12 vertex_constant_buffer;
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
float mvp[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, 0.5f, 0.0f },
|
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
|
||||||
};
|
|
||||||
memcpy(&vertex_constant_buffer.mvp, mvp, sizeof(mvp));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup viewport
|
|
||||||
D3D12_VIEWPORT vp;
|
|
||||||
memset(&vp, 0, sizeof(D3D12_VIEWPORT));
|
|
||||||
vp.Width = draw_data->DisplaySize.x;
|
|
||||||
vp.Height = draw_data->DisplaySize.y;
|
|
||||||
vp.MinDepth = 0.0f;
|
|
||||||
vp.MaxDepth = 1.0f;
|
|
||||||
vp.TopLeftX = vp.TopLeftY = 0.0f;
|
|
||||||
ctx->RSSetViewports(1, &vp);
|
|
||||||
|
|
||||||
// Bind shader and vertex buffers
|
|
||||||
unsigned int stride = sizeof(ImDrawVert);
|
|
||||||
unsigned int offset = 0;
|
|
||||||
D3D12_VERTEX_BUFFER_VIEW vbv;
|
|
||||||
memset(&vbv, 0, sizeof(D3D12_VERTEX_BUFFER_VIEW));
|
|
||||||
vbv.BufferLocation = fr->VertexBuffer->GetGPUVirtualAddress() + offset;
|
|
||||||
vbv.SizeInBytes = fr->VertexBufferSize * stride;
|
|
||||||
vbv.StrideInBytes = stride;
|
|
||||||
ctx->IASetVertexBuffers(0, 1, &vbv);
|
|
||||||
D3D12_INDEX_BUFFER_VIEW ibv;
|
|
||||||
memset(&ibv, 0, sizeof(D3D12_INDEX_BUFFER_VIEW));
|
|
||||||
ibv.BufferLocation = fr->IndexBuffer->GetGPUVirtualAddress();
|
|
||||||
ibv.SizeInBytes = fr->IndexBufferSize * sizeof(ImDrawIdx);
|
|
||||||
ibv.Format = sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
|
|
||||||
ctx->IASetIndexBuffer(&ibv);
|
|
||||||
ctx->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
|
||||||
ctx->SetPipelineState(bd->pPipelineState);
|
|
||||||
ctx->SetGraphicsRootSignature(bd->pRootSignature);
|
|
||||||
ctx->SetGraphicsRoot32BitConstants(0, 16, &vertex_constant_buffer, 0);
|
|
||||||
|
|
||||||
// Setup blend factor
|
|
||||||
const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
|
|
||||||
ctx->OMSetBlendFactor(blend_factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static inline void SafeRelease(T*& res)
|
|
||||||
{
|
|
||||||
if (res)
|
|
||||||
res->Release();
|
|
||||||
res = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render function
|
|
||||||
void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* ctx)
|
|
||||||
{
|
|
||||||
// Avoid rendering when minimized
|
|
||||||
if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// FIXME: I'm assuming that this only gets called once per frame!
|
|
||||||
// If not, we can't just re-allocate the IB or VB, we'll have to do a proper allocator.
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
||||||
bd->frameIndex = bd->frameIndex + 1;
|
|
||||||
ImGui_ImplDX12_RenderBuffers* fr = &bd->pFrameResources[bd->frameIndex % bd->numFramesInFlight];
|
|
||||||
|
|
||||||
// Create and grow vertex/index buffers if needed
|
|
||||||
if (fr->VertexBuffer == nullptr || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
|
||||||
{
|
|
||||||
SafeRelease(fr->VertexBuffer);
|
|
||||||
fr->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
|
||||||
D3D12_HEAP_PROPERTIES props;
|
|
||||||
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
|
||||||
props.Type = D3D12_HEAP_TYPE_UPLOAD;
|
|
||||||
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
|
||||||
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
|
||||||
D3D12_RESOURCE_DESC desc;
|
|
||||||
memset(&desc, 0, sizeof(D3D12_RESOURCE_DESC));
|
|
||||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
|
||||||
desc.Width = fr->VertexBufferSize * sizeof(ImDrawVert);
|
|
||||||
desc.Height = 1;
|
|
||||||
desc.DepthOrArraySize = 1;
|
|
||||||
desc.MipLevels = 1;
|
|
||||||
desc.Format = DXGI_FORMAT_UNKNOWN;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
|
||||||
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
||||||
if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&fr->VertexBuffer)) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (fr->IndexBuffer == nullptr || fr->IndexBufferSize < draw_data->TotalIdxCount)
|
|
||||||
{
|
|
||||||
SafeRelease(fr->IndexBuffer);
|
|
||||||
fr->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
|
||||||
D3D12_HEAP_PROPERTIES props;
|
|
||||||
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
|
||||||
props.Type = D3D12_HEAP_TYPE_UPLOAD;
|
|
||||||
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
|
||||||
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
|
||||||
D3D12_RESOURCE_DESC desc;
|
|
||||||
memset(&desc, 0, sizeof(D3D12_RESOURCE_DESC));
|
|
||||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
|
||||||
desc.Width = fr->IndexBufferSize * sizeof(ImDrawIdx);
|
|
||||||
desc.Height = 1;
|
|
||||||
desc.DepthOrArraySize = 1;
|
|
||||||
desc.MipLevels = 1;
|
|
||||||
desc.Format = DXGI_FORMAT_UNKNOWN;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
|
||||||
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
||||||
if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&fr->IndexBuffer)) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upload vertex/index data into a single contiguous GPU buffer
|
|
||||||
void* vtx_resource, *idx_resource;
|
|
||||||
D3D12_RANGE range;
|
|
||||||
memset(&range, 0, sizeof(D3D12_RANGE));
|
|
||||||
if (fr->VertexBuffer->Map(0, &range, &vtx_resource) != S_OK)
|
|
||||||
return;
|
|
||||||
if (fr->IndexBuffer->Map(0, &range, &idx_resource) != S_OK)
|
|
||||||
return;
|
|
||||||
ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource;
|
|
||||||
ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource;
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
|
|
||||||
memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
|
||||||
vtx_dst += cmd_list->VtxBuffer.Size;
|
|
||||||
idx_dst += cmd_list->IdxBuffer.Size;
|
|
||||||
}
|
|
||||||
fr->VertexBuffer->Unmap(0, &range);
|
|
||||||
fr->IndexBuffer->Unmap(0, &range);
|
|
||||||
|
|
||||||
// Setup desired DX state
|
|
||||||
ImGui_ImplDX12_SetupRenderState(draw_data, ctx, fr);
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
|
||||||
int global_vtx_offset = 0;
|
|
||||||
int global_idx_offset = 0;
|
|
||||||
ImVec2 clip_off = draw_data->DisplayPos;
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
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_ImplDX12_SetupRenderState(draw_data, ctx, fr);
|
|
||||||
else
|
|
||||||
pcmd->UserCallback(cmd_list, pcmd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
|
|
||||||
ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Apply Scissor/clipping rectangle, Bind texture, Draw
|
|
||||||
const D3D12_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };
|
|
||||||
D3D12_GPU_DESCRIPTOR_HANDLE texture_handle = {};
|
|
||||||
texture_handle.ptr = (UINT64)pcmd->GetTexID();
|
|
||||||
ctx->SetGraphicsRootDescriptorTable(1, texture_handle);
|
|
||||||
ctx->RSSetScissorRects(1, &r);
|
|
||||||
ctx->DrawIndexedInstanced(pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
global_idx_offset += cmd_list->IdxBuffer.Size;
|
|
||||||
global_vtx_offset += cmd_list->VtxBuffer.Size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplDX12_CreateFontsTexture()
|
|
||||||
{
|
|
||||||
// Build texture atlas
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
||||||
unsigned char* pixels;
|
|
||||||
int width, height;
|
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
|
||||||
|
|
||||||
// Upload texture to graphics system
|
|
||||||
{
|
|
||||||
D3D12_HEAP_PROPERTIES props;
|
|
||||||
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
|
||||||
props.Type = D3D12_HEAP_TYPE_DEFAULT;
|
|
||||||
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
|
||||||
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
|
||||||
|
|
||||||
D3D12_RESOURCE_DESC desc;
|
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
|
||||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
|
||||||
desc.Alignment = 0;
|
|
||||||
desc.Width = width;
|
|
||||||
desc.Height = height;
|
|
||||||
desc.DepthOrArraySize = 1;
|
|
||||||
desc.MipLevels = 1;
|
|
||||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.SampleDesc.Quality = 0;
|
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
|
||||||
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
||||||
|
|
||||||
ID3D12Resource* pTexture = nullptr;
|
|
||||||
bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc,
|
|
||||||
D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pTexture));
|
|
||||||
|
|
||||||
UINT uploadPitch = (width * 4 + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u);
|
|
||||||
UINT uploadSize = height * uploadPitch;
|
|
||||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
|
||||||
desc.Alignment = 0;
|
|
||||||
desc.Width = uploadSize;
|
|
||||||
desc.Height = 1;
|
|
||||||
desc.DepthOrArraySize = 1;
|
|
||||||
desc.MipLevels = 1;
|
|
||||||
desc.Format = DXGI_FORMAT_UNKNOWN;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.SampleDesc.Quality = 0;
|
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
|
||||||
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
||||||
|
|
||||||
props.Type = D3D12_HEAP_TYPE_UPLOAD;
|
|
||||||
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
|
||||||
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
|
||||||
|
|
||||||
ID3D12Resource* uploadBuffer = nullptr;
|
|
||||||
HRESULT hr = bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc,
|
|
||||||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&uploadBuffer));
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
void* mapped = nullptr;
|
|
||||||
D3D12_RANGE range = { 0, uploadSize };
|
|
||||||
hr = uploadBuffer->Map(0, &range, &mapped);
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
memcpy((void*) ((uintptr_t) mapped + y * uploadPitch), pixels + y * width * 4, width * 4);
|
|
||||||
uploadBuffer->Unmap(0, &range);
|
|
||||||
|
|
||||||
D3D12_TEXTURE_COPY_LOCATION srcLocation = {};
|
|
||||||
srcLocation.pResource = uploadBuffer;
|
|
||||||
srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
|
||||||
srcLocation.PlacedFootprint.Footprint.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
srcLocation.PlacedFootprint.Footprint.Width = width;
|
|
||||||
srcLocation.PlacedFootprint.Footprint.Height = height;
|
|
||||||
srcLocation.PlacedFootprint.Footprint.Depth = 1;
|
|
||||||
srcLocation.PlacedFootprint.Footprint.RowPitch = uploadPitch;
|
|
||||||
|
|
||||||
D3D12_TEXTURE_COPY_LOCATION dstLocation = {};
|
|
||||||
dstLocation.pResource = pTexture;
|
|
||||||
dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
|
||||||
dstLocation.SubresourceIndex = 0;
|
|
||||||
|
|
||||||
D3D12_RESOURCE_BARRIER barrier = {};
|
|
||||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
|
||||||
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
|
||||||
barrier.Transition.pResource = pTexture;
|
|
||||||
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
|
||||||
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
|
|
||||||
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
|
||||||
|
|
||||||
ID3D12Fence* fence = nullptr;
|
|
||||||
hr = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
HANDLE event = CreateEvent(0, 0, 0, 0);
|
|
||||||
IM_ASSERT(event != nullptr);
|
|
||||||
|
|
||||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
|
||||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
|
||||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
|
||||||
queueDesc.NodeMask = 1;
|
|
||||||
|
|
||||||
ID3D12CommandQueue* cmdQueue = nullptr;
|
|
||||||
hr = bd->pd3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&cmdQueue));
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
ID3D12CommandAllocator* cmdAlloc = nullptr;
|
|
||||||
hr = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdAlloc));
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
ID3D12GraphicsCommandList* cmdList = nullptr;
|
|
||||||
hr = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, cmdAlloc, nullptr, IID_PPV_ARGS(&cmdList));
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
cmdList->CopyTextureRegion(&dstLocation, 0, 0, 0, &srcLocation, nullptr);
|
|
||||||
cmdList->ResourceBarrier(1, &barrier);
|
|
||||||
|
|
||||||
hr = cmdList->Close();
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
cmdQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
|
|
||||||
hr = cmdQueue->Signal(fence, 1);
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
fence->SetEventOnCompletion(1, event);
|
|
||||||
WaitForSingleObject(event, INFINITE);
|
|
||||||
|
|
||||||
cmdList->Release();
|
|
||||||
cmdAlloc->Release();
|
|
||||||
cmdQueue->Release();
|
|
||||||
CloseHandle(event);
|
|
||||||
fence->Release();
|
|
||||||
uploadBuffer->Release();
|
|
||||||
|
|
||||||
// Create texture view
|
|
||||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
|
||||||
ZeroMemory(&srvDesc, sizeof(srvDesc));
|
|
||||||
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
|
||||||
srvDesc.Texture2D.MipLevels = desc.MipLevels;
|
|
||||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
|
||||||
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
|
||||||
bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, bd->hFontSrvCpuDescHandle);
|
|
||||||
SafeRelease(bd->pFontTextureResource);
|
|
||||||
bd->pFontTextureResource = pTexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store our identifier
|
|
||||||
// READ THIS IF THE STATIC_ASSERT() TRIGGERS:
|
|
||||||
// - Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'.
|
|
||||||
// - This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*.
|
|
||||||
// [Solution 1] IDE/msbuild: in "Properties/C++/Preprocessor Definitions" add 'ImTextureID=ImU64' (this is what we do in the 'example_win32_direct12/example_win32_direct12.vcxproj' project file)
|
|
||||||
// [Solution 2] IDE/msbuild: in "Properties/C++/Preprocessor Definitions" add 'IMGUI_USER_CONFIG="my_imgui_config.h"' and inside 'my_imgui_config.h' add '#define ImTextureID ImU64' and as many other options as you like.
|
|
||||||
// [Solution 3] IDE/msbuild: edit imconfig.h and add '#define ImTextureID ImU64' (prefer solution 2 to create your own config file!)
|
|
||||||
// [Solution 4] command-line: add '/D ImTextureID=ImU64' to your cl.exe command-line (this is what we do in the example_win32_direct12/build_win32.bat file)
|
|
||||||
static_assert(sizeof(ImTextureID) >= sizeof(bd->hFontSrvGpuDescHandle.ptr), "Can't pack descriptor handle into TexID, 32-bit not supported yet.");
|
|
||||||
io.Fonts->SetTexID((ImTextureID)bd->hFontSrvGpuDescHandle.ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX12_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
||||||
if (!bd || !bd->pd3dDevice)
|
|
||||||
return false;
|
|
||||||
if (bd->pPipelineState)
|
|
||||||
ImGui_ImplDX12_InvalidateDeviceObjects();
|
|
||||||
|
|
||||||
// Create the root signature
|
|
||||||
{
|
|
||||||
D3D12_DESCRIPTOR_RANGE descRange = {};
|
|
||||||
descRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
|
|
||||||
descRange.NumDescriptors = 1;
|
|
||||||
descRange.BaseShaderRegister = 0;
|
|
||||||
descRange.RegisterSpace = 0;
|
|
||||||
descRange.OffsetInDescriptorsFromTableStart = 0;
|
|
||||||
|
|
||||||
D3D12_ROOT_PARAMETER param[2] = {};
|
|
||||||
|
|
||||||
param[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
|
|
||||||
param[0].Constants.ShaderRegister = 0;
|
|
||||||
param[0].Constants.RegisterSpace = 0;
|
|
||||||
param[0].Constants.Num32BitValues = 16;
|
|
||||||
param[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX;
|
|
||||||
|
|
||||||
param[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
|
|
||||||
param[1].DescriptorTable.NumDescriptorRanges = 1;
|
|
||||||
param[1].DescriptorTable.pDescriptorRanges = &descRange;
|
|
||||||
param[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
|
|
||||||
|
|
||||||
// Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
|
|
||||||
D3D12_STATIC_SAMPLER_DESC staticSampler = {};
|
|
||||||
staticSampler.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
|
|
||||||
staticSampler.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
|
||||||
staticSampler.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
|
||||||
staticSampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
|
||||||
staticSampler.MipLODBias = 0.f;
|
|
||||||
staticSampler.MaxAnisotropy = 0;
|
|
||||||
staticSampler.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
|
||||||
staticSampler.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK;
|
|
||||||
staticSampler.MinLOD = 0.f;
|
|
||||||
staticSampler.MaxLOD = 0.f;
|
|
||||||
staticSampler.ShaderRegister = 0;
|
|
||||||
staticSampler.RegisterSpace = 0;
|
|
||||||
staticSampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
|
|
||||||
|
|
||||||
D3D12_ROOT_SIGNATURE_DESC desc = {};
|
|
||||||
desc.NumParameters = _countof(param);
|
|
||||||
desc.pParameters = param;
|
|
||||||
desc.NumStaticSamplers = 1;
|
|
||||||
desc.pStaticSamplers = &staticSampler;
|
|
||||||
desc.Flags =
|
|
||||||
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
|
|
||||||
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS |
|
|
||||||
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
|
|
||||||
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS;
|
|
||||||
|
|
||||||
// Load d3d12.dll and D3D12SerializeRootSignature() function address dynamically to facilitate using with D3D12On7.
|
|
||||||
// See if any version of d3d12.dll is already loaded in the process. If so, give preference to that.
|
|
||||||
static HINSTANCE d3d12_dll = ::GetModuleHandleA("d3d12.dll");
|
|
||||||
if (d3d12_dll == nullptr)
|
|
||||||
{
|
|
||||||
// Attempt to load d3d12.dll from local directories. This will only succeed if
|
|
||||||
// (1) the current OS is Windows 7, and
|
|
||||||
// (2) there exists a version of d3d12.dll for Windows 7 (D3D12On7) in one of the following directories.
|
|
||||||
// See https://github.com/ocornut/imgui/pull/3696 for details.
|
|
||||||
const char* localD3d12Paths[] = { ".\\d3d12.dll", ".\\d3d12on7\\d3d12.dll", ".\\12on7\\d3d12.dll" }; // A. current directory, B. used by some games, C. used in Microsoft D3D12On7 sample
|
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(localD3d12Paths); i++)
|
|
||||||
if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != nullptr)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// If failed, we are on Windows >= 10.
|
|
||||||
if (d3d12_dll == nullptr)
|
|
||||||
d3d12_dll = ::LoadLibraryA("d3d12.dll");
|
|
||||||
|
|
||||||
if (d3d12_dll == nullptr)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignatureFn = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)::GetProcAddress(d3d12_dll, "D3D12SerializeRootSignature");
|
|
||||||
if (D3D12SerializeRootSignatureFn == nullptr)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ID3DBlob* blob = nullptr;
|
|
||||||
if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr) != S_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignature));
|
|
||||||
blob->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
|
|
||||||
// If you would like to use this DX12 sample code but remove this dependency you can:
|
|
||||||
// 1) compile once, save the compiled shader blobs into a file or source code and assign them to psoDesc.VS/PS [preferred solution]
|
|
||||||
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
|
||||||
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
|
||||||
|
|
||||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc;
|
|
||||||
memset(&psoDesc, 0, sizeof(D3D12_GRAPHICS_PIPELINE_STATE_DESC));
|
|
||||||
psoDesc.NodeMask = 1;
|
|
||||||
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
|
||||||
psoDesc.pRootSignature = bd->pRootSignature;
|
|
||||||
psoDesc.SampleMask = UINT_MAX;
|
|
||||||
psoDesc.NumRenderTargets = 1;
|
|
||||||
psoDesc.RTVFormats[0] = bd->RTVFormat;
|
|
||||||
psoDesc.SampleDesc.Count = 1;
|
|
||||||
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
|
|
||||||
|
|
||||||
ID3DBlob* vertexShaderBlob;
|
|
||||||
ID3DBlob* pixelShaderBlob;
|
|
||||||
|
|
||||||
// Create the vertex shader
|
|
||||||
{
|
|
||||||
static const char* vertexShader =
|
|
||||||
"cbuffer vertexBuffer : register(b0) \
|
|
||||||
{\
|
|
||||||
float4x4 ProjectionMatrix; \
|
|
||||||
};\
|
|
||||||
struct VS_INPUT\
|
|
||||||
{\
|
|
||||||
float2 pos : POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
\
|
|
||||||
struct PS_INPUT\
|
|
||||||
{\
|
|
||||||
float4 pos : SV_POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
\
|
|
||||||
PS_INPUT main(VS_INPUT input)\
|
|
||||||
{\
|
|
||||||
PS_INPUT output;\
|
|
||||||
output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
|
|
||||||
output.col = input.col;\
|
|
||||||
output.uv = input.uv;\
|
|
||||||
return output;\
|
|
||||||
}";
|
|
||||||
|
|
||||||
if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_5_0", 0, 0, &vertexShaderBlob, nullptr)))
|
|
||||||
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
||||||
psoDesc.VS = { vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize() };
|
|
||||||
|
|
||||||
// Create the input layout
|
|
||||||
static D3D12_INPUT_ELEMENT_DESC local_layout[] =
|
|
||||||
{
|
|
||||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, pos), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
|
||||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, uv), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
|
||||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)offsetof(ImDrawVert, col), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
|
||||||
};
|
|
||||||
psoDesc.InputLayout = { local_layout, 3 };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the pixel shader
|
|
||||||
{
|
|
||||||
static const char* pixelShader =
|
|
||||||
"struct PS_INPUT\
|
|
||||||
{\
|
|
||||||
float4 pos : SV_POSITION;\
|
|
||||||
float4 col : COLOR0;\
|
|
||||||
float2 uv : TEXCOORD0;\
|
|
||||||
};\
|
|
||||||
SamplerState sampler0 : register(s0);\
|
|
||||||
Texture2D texture0 : register(t0);\
|
|
||||||
\
|
|
||||||
float4 main(PS_INPUT input) : SV_Target\
|
|
||||||
{\
|
|
||||||
float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \
|
|
||||||
return out_col; \
|
|
||||||
}";
|
|
||||||
|
|
||||||
if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_5_0", 0, 0, &pixelShaderBlob, nullptr)))
|
|
||||||
{
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
||||||
}
|
|
||||||
psoDesc.PS = { pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize() };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the blending setup
|
|
||||||
{
|
|
||||||
D3D12_BLEND_DESC& desc = psoDesc.BlendState;
|
|
||||||
desc.AlphaToCoverageEnable = false;
|
|
||||||
desc.RenderTarget[0].BlendEnable = true;
|
|
||||||
desc.RenderTarget[0].SrcBlend = D3D12_BLEND_SRC_ALPHA;
|
|
||||||
desc.RenderTarget[0].DestBlend = D3D12_BLEND_INV_SRC_ALPHA;
|
|
||||||
desc.RenderTarget[0].BlendOp = D3D12_BLEND_OP_ADD;
|
|
||||||
desc.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_ONE;
|
|
||||||
desc.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_INV_SRC_ALPHA;
|
|
||||||
desc.RenderTarget[0].BlendOpAlpha = D3D12_BLEND_OP_ADD;
|
|
||||||
desc.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the rasterizer state
|
|
||||||
{
|
|
||||||
D3D12_RASTERIZER_DESC& desc = psoDesc.RasterizerState;
|
|
||||||
desc.FillMode = D3D12_FILL_MODE_SOLID;
|
|
||||||
desc.CullMode = D3D12_CULL_MODE_NONE;
|
|
||||||
desc.FrontCounterClockwise = FALSE;
|
|
||||||
desc.DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
|
|
||||||
desc.DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
|
|
||||||
desc.SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
|
|
||||||
desc.DepthClipEnable = true;
|
|
||||||
desc.MultisampleEnable = FALSE;
|
|
||||||
desc.AntialiasedLineEnable = FALSE;
|
|
||||||
desc.ForcedSampleCount = 0;
|
|
||||||
desc.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create depth-stencil State
|
|
||||||
{
|
|
||||||
D3D12_DEPTH_STENCIL_DESC& desc = psoDesc.DepthStencilState;
|
|
||||||
desc.DepthEnable = false;
|
|
||||||
desc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
|
|
||||||
desc.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
|
||||||
desc.StencilEnable = false;
|
|
||||||
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D12_STENCIL_OP_KEEP;
|
|
||||||
desc.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
|
||||||
desc.BackFace = desc.FrontFace;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT result_pipeline_state = bd->pd3dDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&bd->pPipelineState));
|
|
||||||
vertexShaderBlob->Release();
|
|
||||||
pixelShaderBlob->Release();
|
|
||||||
if (result_pipeline_state != S_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ImGui_ImplDX12_CreateFontsTexture();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX12_InvalidateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
||||||
if (!bd || !bd->pd3dDevice)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
SafeRelease(bd->pRootSignature);
|
|
||||||
SafeRelease(bd->pPipelineState);
|
|
||||||
SafeRelease(bd->pFontTextureResource);
|
|
||||||
io.Fonts->SetTexID(0); // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
||||||
|
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
|
||||||
{
|
|
||||||
ImGui_ImplDX12_RenderBuffers* fr = &bd->pFrameResources[i];
|
|
||||||
SafeRelease(fr->IndexBuffer);
|
|
||||||
SafeRelease(fr->VertexBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
|
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplDX12_Data* bd = IM_NEW(ImGui_ImplDX12_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_dx12";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
|
|
||||||
bd->pd3dDevice = device;
|
|
||||||
bd->RTVFormat = rtv_format;
|
|
||||||
bd->hFontSrvCpuDescHandle = font_srv_cpu_desc_handle;
|
|
||||||
bd->hFontSrvGpuDescHandle = font_srv_gpu_desc_handle;
|
|
||||||
bd->pFrameResources = new ImGui_ImplDX12_RenderBuffers[num_frames_in_flight];
|
|
||||||
bd->numFramesInFlight = num_frames_in_flight;
|
|
||||||
bd->pd3dSrvDescHeap = cbv_srv_heap;
|
|
||||||
bd->frameIndex = UINT_MAX;
|
|
||||||
|
|
||||||
// Create buffers with a default size (they will later be grown as needed)
|
|
||||||
for (int i = 0; i < num_frames_in_flight; i++)
|
|
||||||
{
|
|
||||||
ImGui_ImplDX12_RenderBuffers* fr = &bd->pFrameResources[i];
|
|
||||||
fr->IndexBuffer = nullptr;
|
|
||||||
fr->VertexBuffer = nullptr;
|
|
||||||
fr->IndexBufferSize = 10000;
|
|
||||||
fr->VertexBufferSize = 5000;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX12_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// Clean up windows and device objects
|
|
||||||
ImGui_ImplDX12_InvalidateDeviceObjects();
|
|
||||||
delete[] bd->pFrameResources;
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX12_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX12_Init()?");
|
|
||||||
|
|
||||||
if (!bd->pPipelineState)
|
|
||||||
ImGui_ImplDX12_CreateDeviceObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,44 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX12
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'.
|
|
||||||
// See imgui_impl_dx12.cpp file for details.
|
|
||||||
|
|
||||||
// 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
|
|
||||||
#include <dxgiformat.h> // DXGI_FORMAT
|
|
||||||
|
|
||||||
struct ID3D12Device;
|
|
||||||
struct ID3D12DescriptorHeap;
|
|
||||||
struct ID3D12GraphicsCommandList;
|
|
||||||
struct D3D12_CPU_DESCRIPTOR_HANDLE;
|
|
||||||
struct D3D12_GPU_DESCRIPTOR_HANDLE;
|
|
||||||
|
|
||||||
// cmd_list is the command list that the implementation will use to render imgui draw lists.
|
|
||||||
// Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate
|
|
||||||
// render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle.
|
|
||||||
// font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture.
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
|
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list);
|
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,388 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX9
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 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: DirectX9: Explicitly disable texture state stages after >= 1.
|
|
||||||
// 2021-05-19: DirectX9: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
||||||
// 2021-04-23: DirectX9: Explicitly setting up more graphics states to increase compatibility with unusual non-default states.
|
|
||||||
// 2021-03-18: DirectX9: Calling IDirect3DStateBlock9::Capture() after CreateStateBlock() as a workaround for state restoring issues (see #3857).
|
|
||||||
// 2021-03-03: DirectX9: Added support for IMGUI_USE_BGRA_PACKED_COLOR in user's imconfig file.
|
|
||||||
// 2021-02-18: DirectX9: Change blending equation to preserve alpha in output buffer.
|
|
||||||
// 2019-05-29: DirectX9: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
||||||
// 2019-04-30: DirectX9: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
||||||
// 2019-03-29: Misc: Fixed erroneous assert in ImGui_ImplDX9_InvalidateDeviceObjects().
|
|
||||||
// 2019-01-16: Misc: Disabled fog before drawing UI's. Fixes issue #2288.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
||||||
// 2018-06-08: Misc: Extracted imgui_impl_dx9.cpp/.h away from the old combined DX9+Win32 example.
|
|
||||||
// 2018-06-08: DirectX9: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
|
||||||
// 2018-05-07: Render: Saving/restoring Transform because they don't seem to be included in the StateBlock. Setting shading mode to Gouraud.
|
|
||||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX9_RenderDrawData() in the .h file so you can call it yourself.
|
|
||||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_dx9.h"
|
|
||||||
|
|
||||||
// DirectX
|
|
||||||
#include <d3d9.h>
|
|
||||||
|
|
||||||
// DirectX data
|
|
||||||
struct ImGui_ImplDX9_Data
|
|
||||||
{
|
|
||||||
LPDIRECT3DDEVICE9 pd3dDevice;
|
|
||||||
LPDIRECT3DVERTEXBUFFER9 pVB;
|
|
||||||
LPDIRECT3DINDEXBUFFER9 pIB;
|
|
||||||
LPDIRECT3DTEXTURE9 FontTexture;
|
|
||||||
int VertexBufferSize;
|
|
||||||
int IndexBufferSize;
|
|
||||||
|
|
||||||
ImGui_ImplDX9_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CUSTOMVERTEX
|
|
||||||
{
|
|
||||||
float pos[3];
|
|
||||||
D3DCOLOR col;
|
|
||||||
float uv[2];
|
|
||||||
};
|
|
||||||
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
|
|
||||||
|
|
||||||
#ifdef IMGUI_USE_BGRA_PACKED_COLOR
|
|
||||||
#define IMGUI_COL_TO_DX9_ARGB(_COL) (_COL)
|
|
||||||
#else
|
|
||||||
#define IMGUI_COL_TO_DX9_ARGB(_COL) (((_COL) & 0xFF00FF00) | (((_COL) & 0xFF0000) >> 16) | (((_COL) & 0xFF) << 16))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 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_ImplDX9_Data* ImGui_ImplDX9_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplDX9_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
|
||||||
|
|
||||||
// Setup viewport
|
|
||||||
D3DVIEWPORT9 vp;
|
|
||||||
vp.X = vp.Y = 0;
|
|
||||||
vp.Width = (DWORD)draw_data->DisplaySize.x;
|
|
||||||
vp.Height = (DWORD)draw_data->DisplaySize.y;
|
|
||||||
vp.MinZ = 0.0f;
|
|
||||||
vp.MaxZ = 1.0f;
|
|
||||||
bd->pd3dDevice->SetViewport(&vp);
|
|
||||||
|
|
||||||
// Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing, shade mode (for gradient), bilinear sampling.
|
|
||||||
bd->pd3dDevice->SetPixelShader(nullptr);
|
|
||||||
bd->pd3dDevice->SetVertexShader(nullptr);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_ONE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_RANGEFOGENABLE, FALSE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, FALSE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_CLIPPING, TRUE);
|
|
||||||
bd->pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
|
||||||
bd->pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
|
||||||
bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
|
||||||
bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
|
||||||
|
|
||||||
// Setup 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.
|
|
||||||
// Being agnostic of whether <d3dx9.h> or <DirectXMath.h> can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH()
|
|
||||||
{
|
|
||||||
float L = draw_data->DisplayPos.x + 0.5f;
|
|
||||||
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x + 0.5f;
|
|
||||||
float T = draw_data->DisplayPos.y + 0.5f;
|
|
||||||
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y + 0.5f;
|
|
||||||
D3DMATRIX mat_identity = { { { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } } };
|
|
||||||
D3DMATRIX mat_projection =
|
|
||||||
{ { {
|
|
||||||
2.0f/(R-L), 0.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 2.0f/(T-B), 0.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 0.5f, 0.0f,
|
|
||||||
(L+R)/(L-R), (T+B)/(B-T), 0.5f, 1.0f
|
|
||||||
} } };
|
|
||||||
bd->pd3dDevice->SetTransform(D3DTS_WORLD, &mat_identity);
|
|
||||||
bd->pd3dDevice->SetTransform(D3DTS_VIEW, &mat_identity);
|
|
||||||
bd->pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat_projection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render function.
|
|
||||||
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
// Avoid rendering when minimized
|
|
||||||
if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Create and grow buffers if needed
|
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
|
||||||
if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount)
|
|
||||||
{
|
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
|
||||||
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
|
||||||
if (bd->pd3dDevice->CreateVertexBuffer(bd->VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &bd->pVB, nullptr) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
|
|
||||||
{
|
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
|
||||||
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
|
||||||
if (bd->pd3dDevice->CreateIndexBuffer(bd->IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &bd->pIB, nullptr) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backup the DX9 state
|
|
||||||
IDirect3DStateBlock9* d3d9_state_block = nullptr;
|
|
||||||
if (bd->pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0)
|
|
||||||
return;
|
|
||||||
if (d3d9_state_block->Capture() < 0)
|
|
||||||
{
|
|
||||||
d3d9_state_block->Release();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backup the DX9 transform (DX9 documentation suggests that it is included in the StateBlock but it doesn't appear to)
|
|
||||||
D3DMATRIX last_world, last_view, last_projection;
|
|
||||||
bd->pd3dDevice->GetTransform(D3DTS_WORLD, &last_world);
|
|
||||||
bd->pd3dDevice->GetTransform(D3DTS_VIEW, &last_view);
|
|
||||||
bd->pd3dDevice->GetTransform(D3DTS_PROJECTION, &last_projection);
|
|
||||||
|
|
||||||
// Allocate buffers
|
|
||||||
CUSTOMVERTEX* vtx_dst;
|
|
||||||
ImDrawIdx* idx_dst;
|
|
||||||
if (bd->pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
|
|
||||||
{
|
|
||||||
d3d9_state_block->Release();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (bd->pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0)
|
|
||||||
{
|
|
||||||
bd->pVB->Unlock();
|
|
||||||
d3d9_state_block->Release();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy and convert all vertices into a single contiguous buffer, convert colors to DX9 default format.
|
|
||||||
// FIXME-OPT: This is a minor waste of resource, the ideal is to use imconfig.h and
|
|
||||||
// 1) to avoid repacking colors: #define IMGUI_USE_BGRA_PACKED_COLOR
|
|
||||||
// 2) to avoid repacking vertices: #define IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT struct ImDrawVert { ImVec2 pos; float z; ImU32 col; ImVec2 uv; }
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
const ImDrawVert* vtx_src = cmd_list->VtxBuffer.Data;
|
|
||||||
for (int i = 0; i < cmd_list->VtxBuffer.Size; i++)
|
|
||||||
{
|
|
||||||
vtx_dst->pos[0] = vtx_src->pos.x;
|
|
||||||
vtx_dst->pos[1] = vtx_src->pos.y;
|
|
||||||
vtx_dst->pos[2] = 0.0f;
|
|
||||||
vtx_dst->col = IMGUI_COL_TO_DX9_ARGB(vtx_src->col);
|
|
||||||
vtx_dst->uv[0] = vtx_src->uv.x;
|
|
||||||
vtx_dst->uv[1] = vtx_src->uv.y;
|
|
||||||
vtx_dst++;
|
|
||||||
vtx_src++;
|
|
||||||
}
|
|
||||||
memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
|
||||||
idx_dst += cmd_list->IdxBuffer.Size;
|
|
||||||
}
|
|
||||||
bd->pVB->Unlock();
|
|
||||||
bd->pIB->Unlock();
|
|
||||||
bd->pd3dDevice->SetStreamSource(0, bd->pVB, 0, sizeof(CUSTOMVERTEX));
|
|
||||||
bd->pd3dDevice->SetIndices(bd->pIB);
|
|
||||||
bd->pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
|
|
||||||
|
|
||||||
// Setup desired DX state
|
|
||||||
ImGui_ImplDX9_SetupRenderState(draw_data);
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
|
||||||
int global_vtx_offset = 0;
|
|
||||||
int global_idx_offset = 0;
|
|
||||||
ImVec2 clip_off = draw_data->DisplayPos;
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
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_ImplDX9_SetupRenderState(draw_data);
|
|
||||||
else
|
|
||||||
pcmd->UserCallback(cmd_list, pcmd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
|
|
||||||
ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Apply Scissor/clipping rectangle, Bind texture, Draw
|
|
||||||
const RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };
|
|
||||||
const LPDIRECT3DTEXTURE9 texture = (LPDIRECT3DTEXTURE9)pcmd->GetTexID();
|
|
||||||
bd->pd3dDevice->SetTexture(0, texture);
|
|
||||||
bd->pd3dDevice->SetScissorRect(&r);
|
|
||||||
bd->pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, pcmd->VtxOffset + global_vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, pcmd->IdxOffset + global_idx_offset, pcmd->ElemCount / 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
global_idx_offset += cmd_list->IdxBuffer.Size;
|
|
||||||
global_vtx_offset += cmd_list->VtxBuffer.Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore the DX9 transform
|
|
||||||
bd->pd3dDevice->SetTransform(D3DTS_WORLD, &last_world);
|
|
||||||
bd->pd3dDevice->SetTransform(D3DTS_VIEW, &last_view);
|
|
||||||
bd->pd3dDevice->SetTransform(D3DTS_PROJECTION, &last_projection);
|
|
||||||
|
|
||||||
// Restore the DX9 state
|
|
||||||
d3d9_state_block->Apply();
|
|
||||||
d3d9_state_block->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplDX9_Data* bd = IM_NEW(ImGui_ImplDX9_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_dx9";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
|
|
||||||
bd->pd3dDevice = device;
|
|
||||||
bd->pd3dDevice->AddRef();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX9_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplDX9_InvalidateDeviceObjects();
|
|
||||||
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ImGui_ImplDX9_CreateFontsTexture()
|
|
||||||
{
|
|
||||||
// Build texture atlas
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
|
||||||
unsigned char* pixels;
|
|
||||||
int width, height, bytes_per_pixel;
|
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &bytes_per_pixel);
|
|
||||||
|
|
||||||
// Convert RGBA32 to BGRA32 (because RGBA32 is not well supported by DX9 devices)
|
|
||||||
#ifndef IMGUI_USE_BGRA_PACKED_COLOR
|
|
||||||
if (io.Fonts->TexPixelsUseColors)
|
|
||||||
{
|
|
||||||
ImU32* dst_start = (ImU32*)ImGui::MemAlloc((size_t)width * height * bytes_per_pixel);
|
|
||||||
for (ImU32* src = (ImU32*)pixels, *dst = dst_start, *dst_end = dst_start + (size_t)width * height; dst < dst_end; src++, dst++)
|
|
||||||
*dst = IMGUI_COL_TO_DX9_ARGB(*src);
|
|
||||||
pixels = (unsigned char*)dst_start;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Upload texture to graphics system
|
|
||||||
bd->FontTexture = nullptr;
|
|
||||||
if (bd->pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bd->FontTexture, nullptr) < 0)
|
|
||||||
return false;
|
|
||||||
D3DLOCKED_RECT tex_locked_rect;
|
|
||||||
if (bd->FontTexture->LockRect(0, &tex_locked_rect, nullptr, 0) != D3D_OK)
|
|
||||||
return false;
|
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
memcpy((unsigned char*)tex_locked_rect.pBits + (size_t)tex_locked_rect.Pitch * y, pixels + (size_t)width * bytes_per_pixel * y, (size_t)width * bytes_per_pixel);
|
|
||||||
bd->FontTexture->UnlockRect(0);
|
|
||||||
|
|
||||||
// Store our identifier
|
|
||||||
io.Fonts->SetTexID((ImTextureID)bd->FontTexture);
|
|
||||||
|
|
||||||
#ifndef IMGUI_USE_BGRA_PACKED_COLOR
|
|
||||||
if (io.Fonts->TexPixelsUseColors)
|
|
||||||
ImGui::MemFree(pixels);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplDX9_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
|
||||||
if (!bd || !bd->pd3dDevice)
|
|
||||||
return false;
|
|
||||||
if (!ImGui_ImplDX9_CreateFontsTexture())
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX9_InvalidateDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
|
||||||
if (!bd || !bd->pd3dDevice)
|
|
||||||
return;
|
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
|
||||||
if (bd->FontTexture) { bd->FontTexture->Release(); bd->FontTexture = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplDX9_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX9_Init()?");
|
|
||||||
|
|
||||||
if (!bd->FontTexture)
|
|
||||||
ImGui_ImplDX9_CreateDeviceObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,31 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for DirectX9
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. Win32)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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 IDirect3DDevice9;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,856 +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+ or GLFW 3.4+ 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+).
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2023-12-19: Emscripten: Added ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback() to register canvas selector and auto-resize GLFW window.
|
|
||||||
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys.
|
|
||||||
// 2023-07-18: Inputs: Revert ignoring mouse data on GLFW_CURSOR_DISABLED as it can be used differently. User may set ImGuiConfigFLags_NoMouse if desired. (#5625, #6609)
|
|
||||||
// 2023-06-12: Accept glfwGetTime() not returning a monotonically increasing value. This seems to happens on some Windows setup when peripherals disconnect, and is likely to also happen on browser + Emscripten. (#6491)
|
|
||||||
// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen on Windows ONLY, using a custom WndProc hook. (#2702)
|
|
||||||
// 2023-03-16: Inputs: Fixed key modifiers handling on secondary viewports (docking branch). Broken on 2023/01/04. (#6248, #6034)
|
|
||||||
// 2023-03-14: Emscripten: Avoid using glfwGetError() and glfwGetGamepadState() which are not correctly implemented in Emscripten emulation. (#6240)
|
|
||||||
// 2023-02-03: Emscripten: Registering custom low-level mouse wheel handler to get more accurate scrolling impulses on Emscripten. (#4019, #6096)
|
|
||||||
// 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty.
|
|
||||||
// 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908)
|
|
||||||
// 2022-10-18: Perform a dummy glfwGetError() read to cancel missing mouse cursors errors. Using GLFW_VERSION_COMBINED directly. (#5785)
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
|
|
||||||
// 2022-09-01: Inputs: Honor GLFW_CURSOR_DISABLED by not setting mouse position *EDIT* Reverted 2023-07-18.
|
|
||||||
// 2022-04-30: Inputs: Fixed ImGui_ImplGlfw_TranslateUntranslatedKey() for lower case letters on OSX.
|
|
||||||
// 2022-03-23: Inputs: Fixed a regression in 1.87 which resulted in keyboard modifiers events being reported incorrectly on Linux/X11.
|
|
||||||
// 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after initializing backend.
|
|
||||||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
|
||||||
// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
|
|
||||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
|
||||||
// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
|
|
||||||
// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
|
|
||||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
|
||||||
// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
|
|
||||||
// 2021-08-17: *BREAKING CHANGE*: Now using glfwSetWindowFocusCallback() to calling io.AddFocusEvent(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() and forward it to the backend via ImGui_ImplGlfw_WindowFocusCallback().
|
|
||||||
// 2021-07-29: *BREAKING CHANGE*: Now using glfwSetCursorEnterCallback(). MousePos is correctly reported when the host platform window is hovered but not focused. If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() callback and forward it to the backend via ImGui_ImplGlfw_CursorEnterCallback().
|
|
||||||
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
|
||||||
// 2020-01-17: Inputs: Disable error callback while assigning mouse cursors because some X11 setup don't have them and it generates errors.
|
|
||||||
// 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor).
|
|
||||||
// 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown.
|
|
||||||
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
|
|
||||||
// 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter().
|
|
||||||
// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
|
||||||
// 2018-11-07: Inputs: When installing our GLFW callbacks, we save user's previously installed ones - if any - and chain call them.
|
|
||||||
// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
|
|
||||||
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
|
|
||||||
// 2018-06-08: Misc: Extracted imgui_impl_glfw.cpp/.h away from the old combined GLFW+OpenGL/Vulkan examples.
|
|
||||||
// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
|
|
||||||
// 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value, passed to glfwSetCursor()).
|
|
||||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
|
||||||
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
|
|
||||||
// 2018-01-25: Inputs: Added gamepad support if ImGuiConfigFlags_NavEnableGamepad is set.
|
|
||||||
// 2018-01-25: Inputs: Honoring the io.WantSetMousePos by repositioning the mouse (when using navigation and ImGuiConfigFlags_NavMoveMouse is set).
|
|
||||||
// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
|
|
||||||
// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
|
|
||||||
// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
|
|
||||||
// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_glfw.h"
|
|
||||||
|
|
||||||
// Clang warnings with -Weverything
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
|
||||||
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// GLFW
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#undef APIENTRY
|
|
||||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
|
||||||
#include <GLFW/glfw3native.h> // for glfwGetWin32Window()
|
|
||||||
#endif
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
|
||||||
#include <GLFW/glfw3native.h> // for glfwGetCocoaWindow()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
#include <emscripten.h>
|
|
||||||
#include <emscripten/html5.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// We gather version tests as define in order to easily see which features are version-dependent.
|
|
||||||
#define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION)
|
|
||||||
#ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released?
|
|
||||||
#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_COMBINED >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR
|
|
||||||
#else
|
|
||||||
#define GLFW_HAS_NEW_CURSORS (0)
|
|
||||||
#endif
|
|
||||||
#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetGamepadState() new api
|
|
||||||
#define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName()
|
|
||||||
#define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError()
|
|
||||||
|
|
||||||
// GLFW data
|
|
||||||
enum GlfwClientApi
|
|
||||||
{
|
|
||||||
GlfwClientApi_Unknown,
|
|
||||||
GlfwClientApi_OpenGL,
|
|
||||||
GlfwClientApi_Vulkan
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ImGui_ImplGlfw_Data
|
|
||||||
{
|
|
||||||
GLFWwindow* Window;
|
|
||||||
GlfwClientApi ClientApi;
|
|
||||||
double Time;
|
|
||||||
GLFWwindow* MouseWindow;
|
|
||||||
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
|
||||||
ImVec2 LastValidMousePos;
|
|
||||||
bool InstalledCallbacks;
|
|
||||||
bool CallbacksChainForAllWindows;
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
const char* CanvasSelector;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
|
||||||
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
|
|
||||||
GLFWcursorposfun PrevUserCallbackCursorPos;
|
|
||||||
GLFWcursorenterfun PrevUserCallbackCursorEnter;
|
|
||||||
GLFWmousebuttonfun PrevUserCallbackMousebutton;
|
|
||||||
GLFWscrollfun PrevUserCallbackScroll;
|
|
||||||
GLFWkeyfun PrevUserCallbackKey;
|
|
||||||
GLFWcharfun PrevUserCallbackChar;
|
|
||||||
GLFWmonitorfun PrevUserCallbackMonitor;
|
|
||||||
#ifdef _WIN32
|
|
||||||
WNDPROC GlfwWndProc;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
|
||||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
||||||
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
|
||||||
// - Because glfwPollEvents() process all windows and some events may be called outside of it, you will need to register your own callbacks
|
|
||||||
// (passing install_callbacks=false in ImGui_ImplGlfw_InitXXX functions), set the current dear imgui context and then call our callbacks.
|
|
||||||
// - Otherwise we may need to store a GLFWWindow* -> ImGuiContext* map and handle this in the backend, adding a little bit of extra complexity to it.
|
|
||||||
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
|
||||||
static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data)
|
|
||||||
{
|
|
||||||
return glfwGetClipboardString((GLFWwindow*)user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text)
|
|
||||||
{
|
|
||||||
glfwSetClipboardString((GLFWwindow*)user_data, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key)
|
|
||||||
{
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case GLFW_KEY_TAB: return ImGuiKey_Tab;
|
|
||||||
case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow;
|
|
||||||
case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow;
|
|
||||||
case GLFW_KEY_UP: return ImGuiKey_UpArrow;
|
|
||||||
case GLFW_KEY_DOWN: return ImGuiKey_DownArrow;
|
|
||||||
case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp;
|
|
||||||
case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
|
|
||||||
case GLFW_KEY_HOME: return ImGuiKey_Home;
|
|
||||||
case GLFW_KEY_END: return ImGuiKey_End;
|
|
||||||
case GLFW_KEY_INSERT: return ImGuiKey_Insert;
|
|
||||||
case GLFW_KEY_DELETE: return ImGuiKey_Delete;
|
|
||||||
case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace;
|
|
||||||
case GLFW_KEY_SPACE: return ImGuiKey_Space;
|
|
||||||
case GLFW_KEY_ENTER: return ImGuiKey_Enter;
|
|
||||||
case GLFW_KEY_ESCAPE: return ImGuiKey_Escape;
|
|
||||||
case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe;
|
|
||||||
case GLFW_KEY_COMMA: return ImGuiKey_Comma;
|
|
||||||
case GLFW_KEY_MINUS: return ImGuiKey_Minus;
|
|
||||||
case GLFW_KEY_PERIOD: return ImGuiKey_Period;
|
|
||||||
case GLFW_KEY_SLASH: return ImGuiKey_Slash;
|
|
||||||
case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon;
|
|
||||||
case GLFW_KEY_EQUAL: return ImGuiKey_Equal;
|
|
||||||
case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket;
|
|
||||||
case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash;
|
|
||||||
case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket;
|
|
||||||
case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent;
|
|
||||||
case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock;
|
|
||||||
case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock;
|
|
||||||
case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock;
|
|
||||||
case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen;
|
|
||||||
case GLFW_KEY_PAUSE: return ImGuiKey_Pause;
|
|
||||||
case GLFW_KEY_KP_0: return ImGuiKey_Keypad0;
|
|
||||||
case GLFW_KEY_KP_1: return ImGuiKey_Keypad1;
|
|
||||||
case GLFW_KEY_KP_2: return ImGuiKey_Keypad2;
|
|
||||||
case GLFW_KEY_KP_3: return ImGuiKey_Keypad3;
|
|
||||||
case GLFW_KEY_KP_4: return ImGuiKey_Keypad4;
|
|
||||||
case GLFW_KEY_KP_5: return ImGuiKey_Keypad5;
|
|
||||||
case GLFW_KEY_KP_6: return ImGuiKey_Keypad6;
|
|
||||||
case GLFW_KEY_KP_7: return ImGuiKey_Keypad7;
|
|
||||||
case GLFW_KEY_KP_8: return ImGuiKey_Keypad8;
|
|
||||||
case GLFW_KEY_KP_9: return ImGuiKey_Keypad9;
|
|
||||||
case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal;
|
|
||||||
case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
|
||||||
case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
|
||||||
case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract;
|
|
||||||
case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd;
|
|
||||||
case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter;
|
|
||||||
case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual;
|
|
||||||
case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
|
|
||||||
case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
|
|
||||||
case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
|
|
||||||
case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper;
|
|
||||||
case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
|
|
||||||
case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl;
|
|
||||||
case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt;
|
|
||||||
case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper;
|
|
||||||
case GLFW_KEY_MENU: return ImGuiKey_Menu;
|
|
||||||
case GLFW_KEY_0: return ImGuiKey_0;
|
|
||||||
case GLFW_KEY_1: return ImGuiKey_1;
|
|
||||||
case GLFW_KEY_2: return ImGuiKey_2;
|
|
||||||
case GLFW_KEY_3: return ImGuiKey_3;
|
|
||||||
case GLFW_KEY_4: return ImGuiKey_4;
|
|
||||||
case GLFW_KEY_5: return ImGuiKey_5;
|
|
||||||
case GLFW_KEY_6: return ImGuiKey_6;
|
|
||||||
case GLFW_KEY_7: return ImGuiKey_7;
|
|
||||||
case GLFW_KEY_8: return ImGuiKey_8;
|
|
||||||
case GLFW_KEY_9: return ImGuiKey_9;
|
|
||||||
case GLFW_KEY_A: return ImGuiKey_A;
|
|
||||||
case GLFW_KEY_B: return ImGuiKey_B;
|
|
||||||
case GLFW_KEY_C: return ImGuiKey_C;
|
|
||||||
case GLFW_KEY_D: return ImGuiKey_D;
|
|
||||||
case GLFW_KEY_E: return ImGuiKey_E;
|
|
||||||
case GLFW_KEY_F: return ImGuiKey_F;
|
|
||||||
case GLFW_KEY_G: return ImGuiKey_G;
|
|
||||||
case GLFW_KEY_H: return ImGuiKey_H;
|
|
||||||
case GLFW_KEY_I: return ImGuiKey_I;
|
|
||||||
case GLFW_KEY_J: return ImGuiKey_J;
|
|
||||||
case GLFW_KEY_K: return ImGuiKey_K;
|
|
||||||
case GLFW_KEY_L: return ImGuiKey_L;
|
|
||||||
case GLFW_KEY_M: return ImGuiKey_M;
|
|
||||||
case GLFW_KEY_N: return ImGuiKey_N;
|
|
||||||
case GLFW_KEY_O: return ImGuiKey_O;
|
|
||||||
case GLFW_KEY_P: return ImGuiKey_P;
|
|
||||||
case GLFW_KEY_Q: return ImGuiKey_Q;
|
|
||||||
case GLFW_KEY_R: return ImGuiKey_R;
|
|
||||||
case GLFW_KEY_S: return ImGuiKey_S;
|
|
||||||
case GLFW_KEY_T: return ImGuiKey_T;
|
|
||||||
case GLFW_KEY_U: return ImGuiKey_U;
|
|
||||||
case GLFW_KEY_V: return ImGuiKey_V;
|
|
||||||
case GLFW_KEY_W: return ImGuiKey_W;
|
|
||||||
case GLFW_KEY_X: return ImGuiKey_X;
|
|
||||||
case GLFW_KEY_Y: return ImGuiKey_Y;
|
|
||||||
case GLFW_KEY_Z: return ImGuiKey_Z;
|
|
||||||
case GLFW_KEY_F1: return ImGuiKey_F1;
|
|
||||||
case GLFW_KEY_F2: return ImGuiKey_F2;
|
|
||||||
case GLFW_KEY_F3: return ImGuiKey_F3;
|
|
||||||
case GLFW_KEY_F4: return ImGuiKey_F4;
|
|
||||||
case GLFW_KEY_F5: return ImGuiKey_F5;
|
|
||||||
case GLFW_KEY_F6: return ImGuiKey_F6;
|
|
||||||
case GLFW_KEY_F7: return ImGuiKey_F7;
|
|
||||||
case GLFW_KEY_F8: return ImGuiKey_F8;
|
|
||||||
case GLFW_KEY_F9: return ImGuiKey_F9;
|
|
||||||
case GLFW_KEY_F10: return ImGuiKey_F10;
|
|
||||||
case GLFW_KEY_F11: return ImGuiKey_F11;
|
|
||||||
case GLFW_KEY_F12: return ImGuiKey_F12;
|
|
||||||
case GLFW_KEY_F13: return ImGuiKey_F13;
|
|
||||||
case GLFW_KEY_F14: return ImGuiKey_F14;
|
|
||||||
case GLFW_KEY_F15: return ImGuiKey_F15;
|
|
||||||
case GLFW_KEY_F16: return ImGuiKey_F16;
|
|
||||||
case GLFW_KEY_F17: return ImGuiKey_F17;
|
|
||||||
case GLFW_KEY_F18: return ImGuiKey_F18;
|
|
||||||
case GLFW_KEY_F19: return ImGuiKey_F19;
|
|
||||||
case GLFW_KEY_F20: return ImGuiKey_F20;
|
|
||||||
case GLFW_KEY_F21: return ImGuiKey_F21;
|
|
||||||
case GLFW_KEY_F22: return ImGuiKey_F22;
|
|
||||||
case GLFW_KEY_F23: return ImGuiKey_F23;
|
|
||||||
case GLFW_KEY_F24: return ImGuiKey_F24;
|
|
||||||
default: return ImGuiKey_None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// X11 does not include current pressed/released modifier key in 'mods' flags submitted by GLFW
|
|
||||||
// See https://github.com/ocornut/imgui/issues/6034 and https://github.com/glfw/glfw/issues/1630
|
|
||||||
static void ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow* window)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddKeyEvent(ImGuiMod_Ctrl, (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS));
|
|
||||||
io.AddKeyEvent(ImGuiMod_Shift, (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS));
|
|
||||||
io.AddKeyEvent(ImGuiMod_Alt, (glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS));
|
|
||||||
io.AddKeyEvent(ImGuiMod_Super, (glfwGetKey(window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ImGui_ImplGlfw_ShouldChainCallback(GLFWwindow* window)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
return bd->CallbacksChainForAllWindows ? true : (window == bd->Window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if (bd->PrevUserCallbackMousebutton != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
|
||||||
bd->PrevUserCallbackMousebutton(window, button, action, mods);
|
|
||||||
|
|
||||||
ImGui_ImplGlfw_UpdateKeyModifiers(window);
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (button >= 0 && button < ImGuiMouseButton_COUNT)
|
|
||||||
io.AddMouseButtonEvent(button, action == GLFW_PRESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if (bd->PrevUserCallbackScroll != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
|
||||||
bd->PrevUserCallbackScroll(window, xoffset, yoffset);
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
// Ignore GLFW events: will be processed in ImGui_ImplEmscripten_WheelCallback().
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
|
|
||||||
{
|
|
||||||
#if GLFW_HAS_GETKEYNAME && !defined(__EMSCRIPTEN__)
|
|
||||||
// GLFW 3.1+ attempts to "untranslate" keys, which goes the opposite of what every other framework does, making using lettered shortcuts difficult.
|
|
||||||
// (It had reasons to do so: namely GLFW is/was more likely to be used for WASD-type game controls rather than lettered shortcuts, but IHMO the 3.1 change could have been done differently)
|
|
||||||
// See https://github.com/glfw/glfw/issues/1502 for details.
|
|
||||||
// Adding a workaround to undo this (so our keys are translated->untranslated->translated, likely a lossy process).
|
|
||||||
// This won't cover edge cases but this is at least going to cover common cases.
|
|
||||||
if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL)
|
|
||||||
return key;
|
|
||||||
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
|
|
||||||
const char* key_name = glfwGetKeyName(key, scancode);
|
|
||||||
glfwSetErrorCallback(prev_error_callback);
|
|
||||||
#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908)
|
|
||||||
(void)glfwGetError(nullptr);
|
|
||||||
#endif
|
|
||||||
if (key_name && key_name[0] != 0 && key_name[1] == 0)
|
|
||||||
{
|
|
||||||
const char char_names[] = "`-=[]\\,;\'./";
|
|
||||||
const int char_keys[] = { GLFW_KEY_GRAVE_ACCENT, GLFW_KEY_MINUS, GLFW_KEY_EQUAL, GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_BACKSLASH, GLFW_KEY_COMMA, GLFW_KEY_SEMICOLON, GLFW_KEY_APOSTROPHE, GLFW_KEY_PERIOD, GLFW_KEY_SLASH, 0 };
|
|
||||||
IM_ASSERT(IM_ARRAYSIZE(char_names) == IM_ARRAYSIZE(char_keys));
|
|
||||||
if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); }
|
|
||||||
else if (key_name[0] >= 'A' && key_name[0] <= 'Z') { key = GLFW_KEY_A + (key_name[0] - 'A'); }
|
|
||||||
else if (key_name[0] >= 'a' && key_name[0] <= 'z') { key = GLFW_KEY_A + (key_name[0] - 'a'); }
|
|
||||||
else if (const char* p = strchr(char_names, key_name[0])) { key = char_keys[p - char_names]; }
|
|
||||||
}
|
|
||||||
// if (action == GLFW_PRESS) printf("key %d scancode %d name '%s'\n", key, scancode, key_name);
|
|
||||||
#else
|
|
||||||
IM_UNUSED(scancode);
|
|
||||||
#endif
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if (bd->PrevUserCallbackKey != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
|
||||||
bd->PrevUserCallbackKey(window, keycode, scancode, action, mods);
|
|
||||||
|
|
||||||
if (action != GLFW_PRESS && action != GLFW_RELEASE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGui_ImplGlfw_UpdateKeyModifiers(window);
|
|
||||||
|
|
||||||
keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode);
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGuiKey imgui_key = ImGui_ImplGlfw_KeyToImGuiKey(keycode);
|
|
||||||
io.AddKeyEvent(imgui_key, (action == GLFW_PRESS));
|
|
||||||
io.SetKeyEventNativeData(imgui_key, keycode, scancode); // To support legacy indexing (<1.87 user code)
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if (bd->PrevUserCallbackWindowFocus != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
|
||||||
bd->PrevUserCallbackWindowFocus(window, focused);
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddFocusEvent(focused != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if (bd->PrevUserCallbackCursorPos != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
|
||||||
bd->PrevUserCallbackCursorPos(window, x, y);
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddMousePosEvent((float)x, (float)y);
|
|
||||||
bd->LastValidMousePos = ImVec2((float)x, (float)y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround: X11 seems to send spurious Leave/Enter events which would make us lose our position,
|
|
||||||
// so we back it up and restore on Leave/Enter (see https://github.com/ocornut/imgui/issues/4984)
|
|
||||||
void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if (bd->PrevUserCallbackCursorEnter != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
|
||||||
bd->PrevUserCallbackCursorEnter(window, entered);
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (entered)
|
|
||||||
{
|
|
||||||
bd->MouseWindow = window;
|
|
||||||
io.AddMousePosEvent(bd->LastValidMousePos.x, bd->LastValidMousePos.y);
|
|
||||||
}
|
|
||||||
else if (!entered && bd->MouseWindow == window)
|
|
||||||
{
|
|
||||||
bd->LastValidMousePos = io.MousePos;
|
|
||||||
bd->MouseWindow = nullptr;
|
|
||||||
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if (bd->PrevUserCallbackChar != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
|
|
||||||
bd->PrevUserCallbackChar(window, c);
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddInputCharacter(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int)
|
|
||||||
{
|
|
||||||
// Unused in 'master' branch but 'docking' branch will use this, so we declare it ahead of it so if you have to install callbacks you can install this one too.
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
static EM_BOOL ImGui_ImplEmscripten_WheelCallback(int, const EmscriptenWheelEvent* ev, void*)
|
|
||||||
{
|
|
||||||
// Mimic Emscripten_HandleWheel() in SDL.
|
|
||||||
// Corresponding equivalent in GLFW JS emulation layer has incorrect quantizing preventing small values. See #6096
|
|
||||||
float multiplier = 0.0f;
|
|
||||||
if (ev->deltaMode == DOM_DELTA_PIXEL) { multiplier = 1.0f / 100.0f; } // 100 pixels make up a step.
|
|
||||||
else if (ev->deltaMode == DOM_DELTA_LINE) { multiplier = 1.0f / 3.0f; } // 3 lines make up a step.
|
|
||||||
else if (ev->deltaMode == DOM_DELTA_PAGE) { multiplier = 80.0f; } // A page makes up 80 steps.
|
|
||||||
float wheel_x = ev->deltaX * -multiplier;
|
|
||||||
float wheel_y = ev->deltaY * -multiplier;
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
|
||||||
//IMGUI_DEBUG_LOG("[Emsc] mode %d dx: %.2f, dy: %.2f, dz: %.2f --> feed %.2f %.2f\n", (int)ev->deltaMode, ev->deltaX, ev->deltaY, ev->deltaZ, wheel_x, wheel_y);
|
|
||||||
return EM_TRUE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// GLFW doesn't allow to distinguish Mouse vs TouchScreen vs Pen.
|
|
||||||
// Add support for Win32 (based on imgui_impl_win32), because we rely on _TouchScreen info to trickle inputs differently.
|
|
||||||
static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo()
|
|
||||||
{
|
|
||||||
LPARAM extra_info = ::GetMessageExtraInfo();
|
|
||||||
if ((extra_info & 0xFFFFFF80) == 0xFF515700)
|
|
||||||
return ImGuiMouseSource_Pen;
|
|
||||||
if ((extra_info & 0xFFFFFF80) == 0xFF515780)
|
|
||||||
return ImGuiMouseSource_TouchScreen;
|
|
||||||
return ImGuiMouseSource_Mouse;
|
|
||||||
}
|
|
||||||
static LRESULT CALLBACK ImGui_ImplGlfw_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
switch (msg)
|
|
||||||
{
|
|
||||||
case WM_MOUSEMOVE: case WM_NCMOUSEMOVE:
|
|
||||||
case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_LBUTTONUP:
|
|
||||||
case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_RBUTTONUP:
|
|
||||||
case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: case WM_MBUTTONUP:
|
|
||||||
case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: case WM_XBUTTONUP:
|
|
||||||
ImGui::GetIO().AddMouseSourceEvent(GetMouseSourceFromMessageExtraInfo());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return ::CallWindowProcW(bd->GlfwWndProc, hWnd, msg, wParam, lParam);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
IM_ASSERT(bd->InstalledCallbacks == false && "Callbacks already installed!");
|
|
||||||
IM_ASSERT(bd->Window == window);
|
|
||||||
|
|
||||||
bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback);
|
|
||||||
bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback);
|
|
||||||
bd->PrevUserCallbackCursorPos = glfwSetCursorPosCallback(window, ImGui_ImplGlfw_CursorPosCallback);
|
|
||||||
bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
|
|
||||||
bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
|
|
||||||
bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
|
|
||||||
bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
|
|
||||||
bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback);
|
|
||||||
bd->InstalledCallbacks = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
IM_ASSERT(bd->InstalledCallbacks == true && "Callbacks not installed!");
|
|
||||||
IM_ASSERT(bd->Window == window);
|
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(window, bd->PrevUserCallbackWindowFocus);
|
|
||||||
glfwSetCursorEnterCallback(window, bd->PrevUserCallbackCursorEnter);
|
|
||||||
glfwSetCursorPosCallback(window, bd->PrevUserCallbackCursorPos);
|
|
||||||
glfwSetMouseButtonCallback(window, bd->PrevUserCallbackMousebutton);
|
|
||||||
glfwSetScrollCallback(window, bd->PrevUserCallbackScroll);
|
|
||||||
glfwSetKeyCallback(window, bd->PrevUserCallbackKey);
|
|
||||||
glfwSetCharCallback(window, bd->PrevUserCallbackChar);
|
|
||||||
glfwSetMonitorCallback(bd->PrevUserCallbackMonitor);
|
|
||||||
bd->InstalledCallbacks = false;
|
|
||||||
bd->PrevUserCallbackWindowFocus = nullptr;
|
|
||||||
bd->PrevUserCallbackCursorEnter = nullptr;
|
|
||||||
bd->PrevUserCallbackCursorPos = nullptr;
|
|
||||||
bd->PrevUserCallbackMousebutton = nullptr;
|
|
||||||
bd->PrevUserCallbackScroll = nullptr;
|
|
||||||
bd->PrevUserCallbackKey = nullptr;
|
|
||||||
bd->PrevUserCallbackChar = nullptr;
|
|
||||||
bd->PrevUserCallbackMonitor = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set to 'true' to enable chaining installed callbacks for all windows (including secondary viewports created by backends or by user.
|
|
||||||
// This is 'false' by default meaning we only chain callbacks for the main viewport.
|
|
||||||
// We cannot set this to 'true' by default because user callbacks code may be not testing the 'window' parameter of their callback.
|
|
||||||
// If you set this to 'true' your user callback code will need to make sure you are testing the 'window' parameter.
|
|
||||||
void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
bd->CallbacksChainForAllWindows = chain_for_all_windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
|
||||||
//printf("GLFW_VERSION: %d.%d.%d (%d)", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION, GLFW_VERSION_COMBINED);
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
|
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
|
||||||
io.BackendPlatformName = "imgui_impl_glfw";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
|
||||||
|
|
||||||
bd->Window = window;
|
|
||||||
bd->Time = 0.0;
|
|
||||||
|
|
||||||
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
|
||||||
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
|
||||||
io.ClipboardUserData = bd->Window;
|
|
||||||
|
|
||||||
// Create mouse cursors
|
|
||||||
// (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
|
|
||||||
// GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
|
|
||||||
// Missing cursors will return nullptr and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
|
|
||||||
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
|
|
||||||
#if GLFW_HAS_NEW_CURSORS
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR);
|
|
||||||
#else
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
||||||
#endif
|
|
||||||
glfwSetErrorCallback(prev_error_callback);
|
|
||||||
#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908)
|
|
||||||
(void)glfwGetError(nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
|
||||||
if (install_callbacks)
|
|
||||||
ImGui_ImplGlfw_InstallCallbacks(window);
|
|
||||||
// Register Emscripten Wheel callback to workaround issue in Emscripten GLFW Emulation (#6096)
|
|
||||||
// We intentionally do not check 'if (install_callbacks)' here, as some users may set it to false and call GLFW callback themselves.
|
|
||||||
// FIXME: May break chaining in case user registered their own Emscripten callback?
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, nullptr, false, ImGui_ImplEmscripten_WheelCallback);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set platform dependent data in viewport
|
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
|
||||||
#ifdef _WIN32
|
|
||||||
main_viewport->PlatformHandleRaw = glfwGetWin32Window(bd->Window);
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window);
|
|
||||||
#else
|
|
||||||
IM_UNUSED(main_viewport);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Windows: register a WndProc hook so we can intercept some messages.
|
|
||||||
#ifdef _WIN32
|
|
||||||
bd->GlfwWndProc = (WNDPROC)::GetWindowLongPtrW((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC);
|
|
||||||
IM_ASSERT(bd->GlfwWndProc != nullptr);
|
|
||||||
::SetWindowLongPtrW((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bd->ClientApi = client_api;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks)
|
|
||||||
{
|
|
||||||
return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_OpenGL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks)
|
|
||||||
{
|
|
||||||
return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Vulkan);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks)
|
|
||||||
{
|
|
||||||
return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Unknown);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
if (bd->InstalledCallbacks)
|
|
||||||
ImGui_ImplGlfw_RestoreCallbacks(bd->Window);
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, nullptr, false, nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
|
||||||
glfwDestroyCursor(bd->MouseCursors[cursor_n]);
|
|
||||||
|
|
||||||
// Windows: register a WndProc hook so we can intercept some messages.
|
|
||||||
#ifdef _WIN32
|
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
|
||||||
::SetWindowLongPtrW((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)bd->GlfwWndProc);
|
|
||||||
bd->GlfwWndProc = nullptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
io.BackendPlatformName = nullptr;
|
|
||||||
io.BackendPlatformUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_UpdateMouseData()
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
|
|
||||||
// (those braces are here to reduce diff with multi-viewports support in 'docking' branch)
|
|
||||||
{
|
|
||||||
GLFWwindow* window = bd->Window;
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
const bool is_window_focused = true;
|
|
||||||
#else
|
|
||||||
const bool is_window_focused = glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0;
|
|
||||||
#endif
|
|
||||||
if (is_window_focused)
|
|
||||||
{
|
|
||||||
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
|
||||||
if (io.WantSetMousePos)
|
|
||||||
glfwSetCursorPos(window, (double)io.MousePos.x, (double)io.MousePos.y);
|
|
||||||
|
|
||||||
// (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured)
|
|
||||||
if (bd->MouseWindow == nullptr)
|
|
||||||
{
|
|
||||||
double mouse_x, mouse_y;
|
|
||||||
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
|
||||||
bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y);
|
|
||||||
io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_UpdateMouseCursor()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
|
||||||
// (those braces are here to reduce diff with multi-viewports support in 'docking' branch)
|
|
||||||
{
|
|
||||||
GLFWwindow* window = bd->Window;
|
|
||||||
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
|
||||||
{
|
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Show OS mouse cursor
|
|
||||||
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
|
|
||||||
glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update gamepad inputs
|
|
||||||
static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
|
|
||||||
static void ImGui_ImplGlfw_UpdateGamepads()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
|
||||||
return;
|
|
||||||
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
|
||||||
#if GLFW_HAS_GAMEPAD_API && !defined(__EMSCRIPTEN__)
|
|
||||||
GLFWgamepadstate gamepad;
|
|
||||||
if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad))
|
|
||||||
return;
|
|
||||||
#define MAP_BUTTON(KEY_NO, BUTTON_NO, _UNUSED) do { io.AddKeyEvent(KEY_NO, gamepad.buttons[BUTTON_NO] != 0); } while (0)
|
|
||||||
#define MAP_ANALOG(KEY_NO, AXIS_NO, _UNUSED, V0, V1) do { float v = gamepad.axes[AXIS_NO]; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
|
|
||||||
#else
|
|
||||||
int axes_count = 0, buttons_count = 0;
|
|
||||||
const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
|
|
||||||
const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
|
|
||||||
if (axes_count == 0 || buttons_count == 0)
|
|
||||||
return;
|
|
||||||
#define MAP_BUTTON(KEY_NO, _UNUSED, BUTTON_NO) do { io.AddKeyEvent(KEY_NO, (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS)); } while (0)
|
|
||||||
#define MAP_ANALOG(KEY_NO, _UNUSED, AXIS_NO, V0, V1) do { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
|
|
||||||
#endif
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadStart, GLFW_GAMEPAD_BUTTON_START, 7);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadBack, GLFW_GAMEPAD_BUTTON_BACK, 6);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, GLFW_GAMEPAD_BUTTON_X, 2); // Xbox X, PS Square
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceUp, GLFW_GAMEPAD_BUTTON_Y, 3); // Xbox Y, PS Triangle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, GLFW_GAMEPAD_BUTTON_DPAD_LEFT, 13);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadRight, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, 11);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadUp, GLFW_GAMEPAD_BUTTON_DPAD_UP, 10);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadDown, GLFW_GAMEPAD_BUTTON_DPAD_DOWN, 12);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadL1, GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, 4);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadR1, GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, 5);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadL2, GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, 4, -0.75f, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadR2, GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, 5, -0.75f, +1.0f);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadL3, GLFW_GAMEPAD_BUTTON_LEFT_THUMB, 8);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadR3, GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, 9);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, GLFW_GAMEPAD_AXIS_LEFT_X, 0, -0.25f, -1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickRight, GLFW_GAMEPAD_AXIS_LEFT_X, 0, +0.25f, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickUp, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, -0.25f, -1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickDown, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, +0.25f, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, -0.25f, -1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickRight, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, +0.25f, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickUp, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, -0.25f, -1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickDown, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, +0.25f, +1.0f);
|
|
||||||
#undef MAP_BUTTON
|
|
||||||
#undef MAP_ANALOG
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGlfw_NewFrame()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplGlfw_InitForXXX()?");
|
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
|
||||||
int w, h;
|
|
||||||
int display_w, display_h;
|
|
||||||
glfwGetWindowSize(bd->Window, &w, &h);
|
|
||||||
glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
|
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
|
||||||
if (w > 0 && h > 0)
|
|
||||||
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);
|
|
||||||
|
|
||||||
// Setup time step
|
|
||||||
// (Accept glfwGetTime() not returning a monotonically increasing value. Seems to happens on disconnecting peripherals and probably on VMs and Emscripten, see #6491, #6189, #6114, #3644)
|
|
||||||
double current_time = glfwGetTime();
|
|
||||||
if (current_time <= bd->Time)
|
|
||||||
current_time = bd->Time + 0.00001f;
|
|
||||||
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
|
|
||||||
bd->Time = current_time;
|
|
||||||
|
|
||||||
ImGui_ImplGlfw_UpdateMouseData();
|
|
||||||
ImGui_ImplGlfw_UpdateMouseCursor();
|
|
||||||
|
|
||||||
// Update game controllers (if enabled and available)
|
|
||||||
ImGui_ImplGlfw_UpdateGamepads();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
static EM_BOOL ImGui_ImplGlfw_OnCanvasSizeChange(int event_type, const EmscriptenUiEvent* event, void* user_data)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = (ImGui_ImplGlfw_Data*)user_data;
|
|
||||||
double canvas_width, canvas_height;
|
|
||||||
emscripten_get_element_css_size(bd->CanvasSelector, &canvas_width, &canvas_height);
|
|
||||||
glfwSetWindowSize(bd->Window, (int)canvas_width, (int)canvas_height);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static EM_BOOL ImGui_ImplEmscripten_FullscreenChangeCallback(int event_type, const EmscriptenFullscreenChangeEvent* event, void* user_data)
|
|
||||||
{
|
|
||||||
ImGui_ImplGlfw_Data* bd = (ImGui_ImplGlfw_Data*)user_data;
|
|
||||||
double canvas_width, canvas_height;
|
|
||||||
emscripten_get_element_css_size(bd->CanvasSelector, &canvas_width, &canvas_height);
|
|
||||||
glfwSetWindowSize(bd->Window, (int)canvas_width, (int)canvas_height);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'canvas_selector' is a CSS selector. The event listener is applied to the first element that matches the query.
|
|
||||||
// STRING MUST PERSIST FOR THE APPLICATION DURATION. PLEASE USE A STRING LITERAL OR ENSURE POINTER WILL STAY VALID.
|
|
||||||
void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector)
|
|
||||||
{
|
|
||||||
IM_ASSERT(canvas_selector != nullptr);
|
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplGlfw_InitForXXX()?");
|
|
||||||
|
|
||||||
bd->CanvasSelector = canvas_selector;
|
|
||||||
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, bd, false, ImGui_ImplGlfw_OnCanvasSizeChange);
|
|
||||||
emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, bd, false, ImGui_ImplEmscripten_FullscreenChangeCallback);
|
|
||||||
|
|
||||||
// Change the size of the GLFW window according to the size of the canvas
|
|
||||||
ImGui_ImplGlfw_OnCanvasSizeChange(EMSCRIPTEN_EVENT_RESIZE, {}, bd);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,58 +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.)
|
|
||||||
|
|
||||||
// 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+).
|
|
||||||
|
|
||||||
// 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,308 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for GLUT/FreeGLUT
|
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL2)
|
|
||||||
|
|
||||||
// !!! GLUT/FreeGLUT IS OBSOLETE PREHISTORIC SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!!
|
|
||||||
// !!! If someone or something is teaching you GLUT today, you are being abused. Please show some resistance. !!!
|
|
||||||
// !!! Nowadays, prefer using GLFW or SDL instead!
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Partial 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 GLUT values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// Issues:
|
|
||||||
// [ ] Platform: GLUT is unable to distinguish e.g. Backspace from CTRL+H or TAB from CTRL+I
|
|
||||||
// [ ] Platform: Missing horizontal mouse wheel support.
|
|
||||||
// [ ] Platform: Missing mouse cursor shape/visibility support.
|
|
||||||
// [ ] Platform: Missing clipboard support (not supported by Glut).
|
|
||||||
// [ ] Platform: Missing gamepad support.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2023-04-17: BREAKING: Removed call to ImGui::NewFrame() from ImGui_ImplGLUT_NewFrame(). Needs to be called from the main application loop, like with every other backends.
|
|
||||||
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
|
|
||||||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
|
||||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
|
||||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
|
||||||
// 2019-04-03: Misc: Renamed imgui_impl_freeglut.cpp/.h to imgui_impl_glut.cpp/.h.
|
|
||||||
// 2019-03-25: Misc: Made io.DeltaTime always above zero.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
|
||||||
// 2018-03-22: Added GLUT Platform binding.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_glut.h"
|
|
||||||
#define GL_SILENCE_DEPRECATION
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <GLUT/glut.h>
|
|
||||||
#else
|
|
||||||
#include <GL/freeglut.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int g_Time = 0; // Current time, in milliseconds
|
|
||||||
|
|
||||||
// Glut has 1 function for characters and one for "special keys". We map the characters in the 0..255 range and the keys above.
|
|
||||||
static ImGuiKey ImGui_ImplGLUT_KeyToImGuiKey(int key)
|
|
||||||
{
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case '\t': return ImGuiKey_Tab;
|
|
||||||
case 256 + GLUT_KEY_LEFT: return ImGuiKey_LeftArrow;
|
|
||||||
case 256 + GLUT_KEY_RIGHT: return ImGuiKey_RightArrow;
|
|
||||||
case 256 + GLUT_KEY_UP: return ImGuiKey_UpArrow;
|
|
||||||
case 256 + GLUT_KEY_DOWN: return ImGuiKey_DownArrow;
|
|
||||||
case 256 + GLUT_KEY_PAGE_UP: return ImGuiKey_PageUp;
|
|
||||||
case 256 + GLUT_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
|
|
||||||
case 256 + GLUT_KEY_HOME: return ImGuiKey_Home;
|
|
||||||
case 256 + GLUT_KEY_END: return ImGuiKey_End;
|
|
||||||
case 256 + GLUT_KEY_INSERT: return ImGuiKey_Insert;
|
|
||||||
case 127: return ImGuiKey_Delete;
|
|
||||||
case 8: return ImGuiKey_Backspace;
|
|
||||||
case ' ': return ImGuiKey_Space;
|
|
||||||
case 13: return ImGuiKey_Enter;
|
|
||||||
case 27: return ImGuiKey_Escape;
|
|
||||||
case 39: return ImGuiKey_Apostrophe;
|
|
||||||
case 44: return ImGuiKey_Comma;
|
|
||||||
case 45: return ImGuiKey_Minus;
|
|
||||||
case 46: return ImGuiKey_Period;
|
|
||||||
case 47: return ImGuiKey_Slash;
|
|
||||||
case 59: return ImGuiKey_Semicolon;
|
|
||||||
case 61: return ImGuiKey_Equal;
|
|
||||||
case 91: return ImGuiKey_LeftBracket;
|
|
||||||
case 92: return ImGuiKey_Backslash;
|
|
||||||
case 93: return ImGuiKey_RightBracket;
|
|
||||||
case 96: return ImGuiKey_GraveAccent;
|
|
||||||
//case 0: return ImGuiKey_CapsLock;
|
|
||||||
//case 0: return ImGuiKey_ScrollLock;
|
|
||||||
case 256 + 0x006D: return ImGuiKey_NumLock;
|
|
||||||
//case 0: return ImGuiKey_PrintScreen;
|
|
||||||
//case 0: return ImGuiKey_Pause;
|
|
||||||
//case '0': return ImGuiKey_Keypad0;
|
|
||||||
//case '1': return ImGuiKey_Keypad1;
|
|
||||||
//case '2': return ImGuiKey_Keypad2;
|
|
||||||
//case '3': return ImGuiKey_Keypad3;
|
|
||||||
//case '4': return ImGuiKey_Keypad4;
|
|
||||||
//case '5': return ImGuiKey_Keypad5;
|
|
||||||
//case '6': return ImGuiKey_Keypad6;
|
|
||||||
//case '7': return ImGuiKey_Keypad7;
|
|
||||||
//case '8': return ImGuiKey_Keypad8;
|
|
||||||
//case '9': return ImGuiKey_Keypad9;
|
|
||||||
//case 46: return ImGuiKey_KeypadDecimal;
|
|
||||||
//case 47: return ImGuiKey_KeypadDivide;
|
|
||||||
case 42: return ImGuiKey_KeypadMultiply;
|
|
||||||
//case 45: return ImGuiKey_KeypadSubtract;
|
|
||||||
case 43: return ImGuiKey_KeypadAdd;
|
|
||||||
//case 13: return ImGuiKey_KeypadEnter;
|
|
||||||
//case 0: return ImGuiKey_KeypadEqual;
|
|
||||||
case 256 + 0x0072: return ImGuiKey_LeftCtrl;
|
|
||||||
case 256 + 0x0070: return ImGuiKey_LeftShift;
|
|
||||||
case 256 + 0x0074: return ImGuiKey_LeftAlt;
|
|
||||||
//case 0: return ImGuiKey_LeftSuper;
|
|
||||||
case 256 + 0x0073: return ImGuiKey_RightCtrl;
|
|
||||||
case 256 + 0x0071: return ImGuiKey_RightShift;
|
|
||||||
case 256 + 0x0075: return ImGuiKey_RightAlt;
|
|
||||||
//case 0: return ImGuiKey_RightSuper;
|
|
||||||
//case 0: return ImGuiKey_Menu;
|
|
||||||
case '0': return ImGuiKey_0;
|
|
||||||
case '1': return ImGuiKey_1;
|
|
||||||
case '2': return ImGuiKey_2;
|
|
||||||
case '3': return ImGuiKey_3;
|
|
||||||
case '4': return ImGuiKey_4;
|
|
||||||
case '5': return ImGuiKey_5;
|
|
||||||
case '6': return ImGuiKey_6;
|
|
||||||
case '7': return ImGuiKey_7;
|
|
||||||
case '8': return ImGuiKey_8;
|
|
||||||
case '9': return ImGuiKey_9;
|
|
||||||
case 'A': case 'a': return ImGuiKey_A;
|
|
||||||
case 'B': case 'b': return ImGuiKey_B;
|
|
||||||
case 'C': case 'c': return ImGuiKey_C;
|
|
||||||
case 'D': case 'd': return ImGuiKey_D;
|
|
||||||
case 'E': case 'e': return ImGuiKey_E;
|
|
||||||
case 'F': case 'f': return ImGuiKey_F;
|
|
||||||
case 'G': case 'g': return ImGuiKey_G;
|
|
||||||
case 'H': case 'h': return ImGuiKey_H;
|
|
||||||
case 'I': case 'i': return ImGuiKey_I;
|
|
||||||
case 'J': case 'j': return ImGuiKey_J;
|
|
||||||
case 'K': case 'k': return ImGuiKey_K;
|
|
||||||
case 'L': case 'l': return ImGuiKey_L;
|
|
||||||
case 'M': case 'm': return ImGuiKey_M;
|
|
||||||
case 'N': case 'n': return ImGuiKey_N;
|
|
||||||
case 'O': case 'o': return ImGuiKey_O;
|
|
||||||
case 'P': case 'p': return ImGuiKey_P;
|
|
||||||
case 'Q': case 'q': return ImGuiKey_Q;
|
|
||||||
case 'R': case 'r': return ImGuiKey_R;
|
|
||||||
case 'S': case 's': return ImGuiKey_S;
|
|
||||||
case 'T': case 't': return ImGuiKey_T;
|
|
||||||
case 'U': case 'u': return ImGuiKey_U;
|
|
||||||
case 'V': case 'v': return ImGuiKey_V;
|
|
||||||
case 'W': case 'w': return ImGuiKey_W;
|
|
||||||
case 'X': case 'x': return ImGuiKey_X;
|
|
||||||
case 'Y': case 'y': return ImGuiKey_Y;
|
|
||||||
case 'Z': case 'z': return ImGuiKey_Z;
|
|
||||||
case 256 + GLUT_KEY_F1: return ImGuiKey_F1;
|
|
||||||
case 256 + GLUT_KEY_F2: return ImGuiKey_F2;
|
|
||||||
case 256 + GLUT_KEY_F3: return ImGuiKey_F3;
|
|
||||||
case 256 + GLUT_KEY_F4: return ImGuiKey_F4;
|
|
||||||
case 256 + GLUT_KEY_F5: return ImGuiKey_F5;
|
|
||||||
case 256 + GLUT_KEY_F6: return ImGuiKey_F6;
|
|
||||||
case 256 + GLUT_KEY_F7: return ImGuiKey_F7;
|
|
||||||
case 256 + GLUT_KEY_F8: return ImGuiKey_F8;
|
|
||||||
case 256 + GLUT_KEY_F9: return ImGuiKey_F9;
|
|
||||||
case 256 + GLUT_KEY_F10: return ImGuiKey_F10;
|
|
||||||
case 256 + GLUT_KEY_F11: return ImGuiKey_F11;
|
|
||||||
case 256 + GLUT_KEY_F12: return ImGuiKey_F12;
|
|
||||||
default: return ImGuiKey_None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplGLUT_Init()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
#ifdef FREEGLUT
|
|
||||||
io.BackendPlatformName = "imgui_impl_glut (freeglut)";
|
|
||||||
#else
|
|
||||||
io.BackendPlatformName = "imgui_impl_glut";
|
|
||||||
#endif
|
|
||||||
g_Time = 0;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_InstallFuncs()
|
|
||||||
{
|
|
||||||
glutReshapeFunc(ImGui_ImplGLUT_ReshapeFunc);
|
|
||||||
glutMotionFunc(ImGui_ImplGLUT_MotionFunc);
|
|
||||||
glutPassiveMotionFunc(ImGui_ImplGLUT_MotionFunc);
|
|
||||||
glutMouseFunc(ImGui_ImplGLUT_MouseFunc);
|
|
||||||
#ifdef __FREEGLUT_EXT_H__
|
|
||||||
glutMouseWheelFunc(ImGui_ImplGLUT_MouseWheelFunc);
|
|
||||||
#endif
|
|
||||||
glutKeyboardFunc(ImGui_ImplGLUT_KeyboardFunc);
|
|
||||||
glutKeyboardUpFunc(ImGui_ImplGLUT_KeyboardUpFunc);
|
|
||||||
glutSpecialFunc(ImGui_ImplGLUT_SpecialFunc);
|
|
||||||
glutSpecialUpFunc(ImGui_ImplGLUT_SpecialUpFunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_Shutdown()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendPlatformName = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_NewFrame()
|
|
||||||
{
|
|
||||||
// Setup time step
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
int current_time = glutGet(GLUT_ELAPSED_TIME);
|
|
||||||
int delta_time_ms = (current_time - g_Time);
|
|
||||||
if (delta_time_ms <= 0)
|
|
||||||
delta_time_ms = 1;
|
|
||||||
io.DeltaTime = delta_time_ms / 1000.0f;
|
|
||||||
g_Time = current_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplGLUT_UpdateKeyModifiers()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
int glut_key_mods = glutGetModifiers();
|
|
||||||
io.AddKeyEvent(ImGuiMod_Ctrl, (glut_key_mods & GLUT_ACTIVE_CTRL) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Shift, (glut_key_mods & GLUT_ACTIVE_SHIFT) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Alt, (glut_key_mods & GLUT_ACTIVE_ALT) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplGLUT_AddKeyEvent(ImGuiKey key, bool down, int native_keycode)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddKeyEvent(key, down);
|
|
||||||
io.SetKeyEventNativeData(key, native_keycode, -1); // To support legacy indexing (<1.87 user code)
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_KeyboardFunc(unsigned char c, int x, int y)
|
|
||||||
{
|
|
||||||
// Send character to imgui
|
|
||||||
//printf("char_down_func %d '%c'\n", c, c);
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (c >= 32)
|
|
||||||
io.AddInputCharacter((unsigned int)c);
|
|
||||||
|
|
||||||
ImGuiKey key = ImGui_ImplGLUT_KeyToImGuiKey(c);
|
|
||||||
ImGui_ImplGLUT_AddKeyEvent(key, true, c);
|
|
||||||
ImGui_ImplGLUT_UpdateKeyModifiers();
|
|
||||||
(void)x; (void)y; // Unused
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
|
|
||||||
{
|
|
||||||
//printf("char_up_func %d '%c'\n", c, c);
|
|
||||||
ImGuiKey key = ImGui_ImplGLUT_KeyToImGuiKey(c);
|
|
||||||
ImGui_ImplGLUT_AddKeyEvent(key, false, c);
|
|
||||||
ImGui_ImplGLUT_UpdateKeyModifiers();
|
|
||||||
(void)x; (void)y; // Unused
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_SpecialFunc(int key, int x, int y)
|
|
||||||
{
|
|
||||||
//printf("key_down_func %d\n", key);
|
|
||||||
ImGuiKey imgui_key = ImGui_ImplGLUT_KeyToImGuiKey(key + 256);
|
|
||||||
ImGui_ImplGLUT_AddKeyEvent(imgui_key, true, key + 256);
|
|
||||||
ImGui_ImplGLUT_UpdateKeyModifiers();
|
|
||||||
(void)x; (void)y; // Unused
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_SpecialUpFunc(int key, int x, int y)
|
|
||||||
{
|
|
||||||
//printf("key_up_func %d\n", key);
|
|
||||||
ImGuiKey imgui_key = ImGui_ImplGLUT_KeyToImGuiKey(key + 256);
|
|
||||||
ImGui_ImplGLUT_AddKeyEvent(imgui_key, false, key + 256);
|
|
||||||
ImGui_ImplGLUT_UpdateKeyModifiers();
|
|
||||||
(void)x; (void)y; // Unused
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_MouseFunc(int glut_button, int state, int x, int y)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddMousePosEvent((float)x, (float)y);
|
|
||||||
int button = -1;
|
|
||||||
if (glut_button == GLUT_LEFT_BUTTON) button = 0;
|
|
||||||
if (glut_button == GLUT_RIGHT_BUTTON) button = 1;
|
|
||||||
if (glut_button == GLUT_MIDDLE_BUTTON) button = 2;
|
|
||||||
if (button != -1 && (state == GLUT_DOWN || state == GLUT_UP))
|
|
||||||
io.AddMouseButtonEvent(button, state == GLUT_DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __FREEGLUT_EXT_H__
|
|
||||||
void ImGui_ImplGLUT_MouseWheelFunc(int button, int dir, int x, int y)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddMousePosEvent((float)x, (float)y);
|
|
||||||
if (dir != 0)
|
|
||||||
io.AddMouseWheelEvent(0.0f, dir > 0 ? 1.0f : -1.0f);
|
|
||||||
(void)button; // Unused
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_ReshapeFunc(int w, int h)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplGLUT_MotionFunc(int x, int y)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddMousePosEvent((float)x, (float)y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,46 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for GLUT/FreeGLUT
|
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL2)
|
|
||||||
|
|
||||||
// !!! GLUT/FreeGLUT IS OBSOLETE PREHISTORIC SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!!
|
|
||||||
// !!! If someone or something is teaching you GLUT today, you are being abused. Please show some resistance. !!!
|
|
||||||
// !!! Nowadays, prefer using GLFW or SDL instead!
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Partial 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 GLUT values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// Issues:
|
|
||||||
// [ ] Platform: GLUT is unable to distinguish e.g. Backspace from CTRL+H or TAB from CTRL+I
|
|
||||||
// [ ] Platform: Missing horizontal mouse wheel support.
|
|
||||||
// [ ] Platform: Missing mouse cursor shape/visibility support.
|
|
||||||
// [ ] Platform: Missing clipboard support (not supported by Glut).
|
|
||||||
// [ ] Platform: Missing gamepad support.
|
|
||||||
|
|
||||||
// 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
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplGLUT_Init();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_InstallFuncs();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_NewFrame();
|
|
||||||
|
|
||||||
// You can call ImGui_ImplGLUT_InstallFuncs() to get all those functions installed automatically,
|
|
||||||
// or call them yourself from your own GLUT handlers. We are using the same weird names as GLUT for consistency..
|
|
||||||
//------------------------------------ GLUT name ---------------------------------------------- Decent Name ---------
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_ReshapeFunc(int w, int h); // ~ ResizeFunc
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_MotionFunc(int x, int y); // ~ MouseMoveFunc
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_MouseFunc(int button, int state, int x, int y); // ~ MouseButtonFunc
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_MouseWheelFunc(int button, int dir, int x, int y); // ~ MouseWheelFunc
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_KeyboardFunc(unsigned char c, int x, int y); // ~ CharPressedFunc
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_KeyboardUpFunc(unsigned char c, int x, int y); // ~ CharReleasedFunc
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_SpecialFunc(int key, int x, int y); // ~ KeyPressedFunc
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplGLUT_SpecialUpFunc(int key, int x, int y); // ~ KeyReleasedFunc
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,72 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for Metal
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. OSX)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// ObjC API
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
|
|
||||||
@class MTLRenderPassDescriptor;
|
|
||||||
@protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_Init(id<MTLDevice> device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* drawData,
|
|
||||||
id<MTLCommandBuffer> commandBuffer,
|
|
||||||
id<MTLRenderCommandEncoder> commandEncoder);
|
|
||||||
|
|
||||||
// Called by Init/NewFrame/Shutdown
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(id<MTLDevice> device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// C++ API
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Enable Metal C++ binding support with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file
|
|
||||||
// More info about using Metal from C++: https://developer.apple.com/metal/cpp/
|
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_METAL_CPP
|
|
||||||
#include <Metal/Metal.hpp>
|
|
||||||
#ifndef __OBJC__
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_Init(MTL::Device* device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data,
|
|
||||||
MTL::CommandBuffer* commandBuffer,
|
|
||||||
MTL::RenderCommandEncoder* commandEncoder);
|
|
||||||
|
|
||||||
// Called by Init/NewFrame/Shutdown
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,590 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for Metal
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. OSX)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2022-08-23: Metal: Update deprecated property 'sampleCount'->'rasterSampleCount'.
|
|
||||||
// 2022-07-05: Metal: Add dispatch synchronization.
|
|
||||||
// 2022-06-30: Metal: Use __bridge for ARC based systems.
|
|
||||||
// 2022-06-01: Metal: Fixed null dereference on exit inside command buffer completion handler.
|
|
||||||
// 2022-04-27: Misc: Store backend data in a per-context struct, allowing to use this backend with multiple contexts.
|
|
||||||
// 2022-01-03: Metal: Ignore ImDrawCmd where ElemCount == 0 (very rare but can technically be manufactured by user code).
|
|
||||||
// 2021-12-30: Metal: Added Metal C++ support. Enable with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file.
|
|
||||||
// 2021-08-24: Metal: Fixed a crash when clipping rect larger than framebuffer is submitted. (#4464)
|
|
||||||
// 2021-05-19: Metal: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
||||||
// 2021-02-18: Metal: Change blending equation to preserve alpha in output buffer.
|
|
||||||
// 2021-01-25: Metal: Fixed texture storage mode when building on Mac Catalyst.
|
|
||||||
// 2019-05-29: Metal: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
||||||
// 2019-04-30: Metal: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
||||||
// 2019-02-11: Metal: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
||||||
// 2018-07-05: Metal: Added new Metal backend implementation.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_metal.h"
|
|
||||||
#import <time.h>
|
|
||||||
#import <Metal/Metal.h>
|
|
||||||
|
|
||||||
#pragma mark - Support classes
|
|
||||||
|
|
||||||
// A wrapper around a MTLBuffer object that knows the last time it was reused
|
|
||||||
@interface MetalBuffer : NSObject
|
|
||||||
@property (nonatomic, strong) id<MTLBuffer> buffer;
|
|
||||||
@property (nonatomic, assign) double lastReuseTime;
|
|
||||||
- (instancetype)initWithBuffer:(id<MTLBuffer>)buffer;
|
|
||||||
@end
|
|
||||||
|
|
||||||
// An object that encapsulates the data necessary to uniquely identify a
|
|
||||||
// render pipeline state. These are used as cache keys.
|
|
||||||
@interface FramebufferDescriptor : NSObject<NSCopying>
|
|
||||||
@property (nonatomic, assign) unsigned long sampleCount;
|
|
||||||
@property (nonatomic, assign) MTLPixelFormat colorPixelFormat;
|
|
||||||
@property (nonatomic, assign) MTLPixelFormat depthPixelFormat;
|
|
||||||
@property (nonatomic, assign) MTLPixelFormat stencilPixelFormat;
|
|
||||||
- (instancetype)initWithRenderPassDescriptor:(MTLRenderPassDescriptor*)renderPassDescriptor;
|
|
||||||
@end
|
|
||||||
|
|
||||||
// A singleton that stores long-lived objects that are needed by the Metal
|
|
||||||
// renderer backend. Stores the render pipeline state cache and the default
|
|
||||||
// font texture, and manages the reusable buffer cache.
|
|
||||||
@interface MetalContext : NSObject
|
|
||||||
@property (nonatomic, strong) id<MTLDevice> device;
|
|
||||||
@property (nonatomic, strong) id<MTLDepthStencilState> depthStencilState;
|
|
||||||
@property (nonatomic, strong) FramebufferDescriptor* framebufferDescriptor; // framebuffer descriptor for current frame; transient
|
|
||||||
@property (nonatomic, strong) NSMutableDictionary* renderPipelineStateCache; // pipeline cache; keyed on framebuffer descriptors
|
|
||||||
@property (nonatomic, strong, nullable) id<MTLTexture> fontTexture;
|
|
||||||
@property (nonatomic, strong) NSMutableArray<MetalBuffer*>* bufferCache;
|
|
||||||
@property (nonatomic, assign) double lastBufferCachePurge;
|
|
||||||
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device;
|
|
||||||
- (id<MTLRenderPipelineState>)renderPipelineStateForFramebufferDescriptor:(FramebufferDescriptor*)descriptor device:(id<MTLDevice>)device;
|
|
||||||
@end
|
|
||||||
|
|
||||||
struct ImGui_ImplMetal_Data
|
|
||||||
{
|
|
||||||
MetalContext* SharedMetalContext;
|
|
||||||
|
|
||||||
ImGui_ImplMetal_Data() { memset(this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
static ImGui_ImplMetal_Data* ImGui_ImplMetal_CreateBackendData() { return IM_NEW(ImGui_ImplMetal_Data)(); }
|
|
||||||
static ImGui_ImplMetal_Data* ImGui_ImplMetal_GetBackendData() { return ImGui::GetCurrentContext() ? (ImGui_ImplMetal_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; }
|
|
||||||
static void ImGui_ImplMetal_DestroyBackendData(){ IM_DELETE(ImGui_ImplMetal_GetBackendData()); }
|
|
||||||
|
|
||||||
static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return (CFTimeInterval)(double)(clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1e9); }
|
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_METAL_CPP
|
|
||||||
|
|
||||||
#pragma mark - Dear ImGui Metal C++ Backend API
|
|
||||||
|
|
||||||
bool ImGui_ImplMetal_Init(MTL::Device* device)
|
|
||||||
{
|
|
||||||
return ImGui_ImplMetal_Init((__bridge id<MTLDevice>)(device));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor)
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_NewFrame((__bridge MTLRenderPassDescriptor*)(renderPassDescriptor));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data,
|
|
||||||
MTL::CommandBuffer* commandBuffer,
|
|
||||||
MTL::RenderCommandEncoder* commandEncoder)
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_RenderDrawData(draw_data,
|
|
||||||
(__bridge id<MTLCommandBuffer>)(commandBuffer),
|
|
||||||
(__bridge id<MTLRenderCommandEncoder>)(commandEncoder));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device)
|
|
||||||
{
|
|
||||||
return ImGui_ImplMetal_CreateFontsTexture((__bridge id<MTLDevice>)(device));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device)
|
|
||||||
{
|
|
||||||
return ImGui_ImplMetal_CreateDeviceObjects((__bridge id<MTLDevice>)(device));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // #ifdef IMGUI_IMPL_METAL_CPP
|
|
||||||
|
|
||||||
#pragma mark - Dear ImGui Metal Backend API
|
|
||||||
|
|
||||||
bool ImGui_ImplMetal_Init(id<MTLDevice> device)
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_CreateBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_metal";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
|
|
||||||
bd->SharedMetalContext = [[MetalContext alloc] init];
|
|
||||||
bd->SharedMetalContext.device = device;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGui_ImplMetal_DestroyDeviceObjects();
|
|
||||||
ImGui_ImplMetal_DestroyBackendData();
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor)
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
IM_ASSERT(bd->SharedMetalContext != nil && "No Metal context. Did you call ImGui_ImplMetal_Init() ?");
|
|
||||||
bd->SharedMetalContext.framebufferDescriptor = [[FramebufferDescriptor alloc] initWithRenderPassDescriptor:renderPassDescriptor];
|
|
||||||
|
|
||||||
if (bd->SharedMetalContext.depthStencilState == nil)
|
|
||||||
ImGui_ImplMetal_CreateDeviceObjects(bd->SharedMetalContext.device);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplMetal_SetupRenderState(ImDrawData* drawData, id<MTLCommandBuffer> commandBuffer,
|
|
||||||
id<MTLRenderCommandEncoder> commandEncoder, id<MTLRenderPipelineState> renderPipelineState,
|
|
||||||
MetalBuffer* vertexBuffer, size_t vertexBufferOffset)
|
|
||||||
{
|
|
||||||
IM_UNUSED(commandBuffer);
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
[commandEncoder setCullMode:MTLCullModeNone];
|
|
||||||
[commandEncoder setDepthStencilState:bd->SharedMetalContext.depthStencilState];
|
|
||||||
|
|
||||||
// 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). DisplayMin is typically (0,0) for single viewport apps.
|
|
||||||
MTLViewport viewport =
|
|
||||||
{
|
|
||||||
.originX = 0.0,
|
|
||||||
.originY = 0.0,
|
|
||||||
.width = (double)(drawData->DisplaySize.x * drawData->FramebufferScale.x),
|
|
||||||
.height = (double)(drawData->DisplaySize.y * drawData->FramebufferScale.y),
|
|
||||||
.znear = 0.0,
|
|
||||||
.zfar = 1.0
|
|
||||||
};
|
|
||||||
[commandEncoder setViewport:viewport];
|
|
||||||
|
|
||||||
float L = drawData->DisplayPos.x;
|
|
||||||
float R = drawData->DisplayPos.x + drawData->DisplaySize.x;
|
|
||||||
float T = drawData->DisplayPos.y;
|
|
||||||
float B = drawData->DisplayPos.y + drawData->DisplaySize.y;
|
|
||||||
float N = (float)viewport.znear;
|
|
||||||
float F = (float)viewport.zfar;
|
|
||||||
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/(F-N), 0.0f },
|
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), N/(F-N), 1.0f },
|
|
||||||
};
|
|
||||||
[commandEncoder setVertexBytes:&ortho_projection length:sizeof(ortho_projection) atIndex:1];
|
|
||||||
|
|
||||||
[commandEncoder setRenderPipelineState:renderPipelineState];
|
|
||||||
|
|
||||||
[commandEncoder setVertexBuffer:vertexBuffer.buffer offset:0 atIndex:0];
|
|
||||||
[commandEncoder setVertexBufferOffset:vertexBufferOffset atIndex:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metal Render function.
|
|
||||||
void ImGui_ImplMetal_RenderDrawData(ImDrawData* drawData, id<MTLCommandBuffer> commandBuffer, id<MTLRenderCommandEncoder> commandEncoder)
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
MetalContext* ctx = bd->SharedMetalContext;
|
|
||||||
|
|
||||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
|
||||||
int fb_width = (int)(drawData->DisplaySize.x * drawData->FramebufferScale.x);
|
|
||||||
int fb_height = (int)(drawData->DisplaySize.y * drawData->FramebufferScale.y);
|
|
||||||
if (fb_width <= 0 || fb_height <= 0 || drawData->CmdListsCount == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Try to retrieve a render pipeline state that is compatible with the framebuffer config for this frame
|
|
||||||
// The hit rate for this cache should be very near 100%.
|
|
||||||
id<MTLRenderPipelineState> renderPipelineState = ctx.renderPipelineStateCache[ctx.framebufferDescriptor];
|
|
||||||
if (renderPipelineState == nil)
|
|
||||||
{
|
|
||||||
// No luck; make a new render pipeline state
|
|
||||||
renderPipelineState = [ctx renderPipelineStateForFramebufferDescriptor:ctx.framebufferDescriptor device:commandBuffer.device];
|
|
||||||
|
|
||||||
// Cache render pipeline state for later reuse
|
|
||||||
ctx.renderPipelineStateCache[ctx.framebufferDescriptor] = renderPipelineState;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t vertexBufferLength = (size_t)drawData->TotalVtxCount * sizeof(ImDrawVert);
|
|
||||||
size_t indexBufferLength = (size_t)drawData->TotalIdxCount * sizeof(ImDrawIdx);
|
|
||||||
MetalBuffer* vertexBuffer = [ctx dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
|
|
||||||
MetalBuffer* indexBuffer = [ctx dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
|
|
||||||
|
|
||||||
ImGui_ImplMetal_SetupRenderState(drawData, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, 0);
|
|
||||||
|
|
||||||
// Will project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_off = drawData->DisplayPos; // (0,0) unless using multi-viewports
|
|
||||||
ImVec2 clip_scale = drawData->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
size_t vertexBufferOffset = 0;
|
|
||||||
size_t indexBufferOffset = 0;
|
|
||||||
for (int n = 0; n < drawData->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = drawData->CmdLists[n];
|
|
||||||
|
|
||||||
memcpy((char*)vertexBuffer.buffer.contents + vertexBufferOffset, cmd_list->VtxBuffer.Data, (size_t)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
|
|
||||||
memcpy((char*)indexBuffer.buffer.contents + indexBufferOffset, cmd_list->IdxBuffer.Data, (size_t)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
|
||||||
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
||||||
{
|
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
||||||
if (pcmd->UserCallback)
|
|
||||||
{
|
|
||||||
// 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_ImplMetal_SetupRenderState(drawData, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, vertexBufferOffset);
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Clamp to viewport as setScissorRect() won't accept values that are off bounds
|
|
||||||
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
|
||||||
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
|
|
||||||
if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; }
|
|
||||||
if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; }
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
if (pcmd->ElemCount == 0) // drawIndexedPrimitives() validation doesn't accept this
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Apply scissor/clipping rectangle
|
|
||||||
MTLScissorRect scissorRect =
|
|
||||||
{
|
|
||||||
.x = NSUInteger(clip_min.x),
|
|
||||||
.y = NSUInteger(clip_min.y),
|
|
||||||
.width = NSUInteger(clip_max.x - clip_min.x),
|
|
||||||
.height = NSUInteger(clip_max.y - clip_min.y)
|
|
||||||
};
|
|
||||||
[commandEncoder setScissorRect:scissorRect];
|
|
||||||
|
|
||||||
// Bind texture, Draw
|
|
||||||
if (ImTextureID tex_id = pcmd->GetTexID())
|
|
||||||
[commandEncoder setFragmentTexture:(__bridge id<MTLTexture>)(tex_id) atIndex:0];
|
|
||||||
|
|
||||||
[commandEncoder setVertexBufferOffset:(vertexBufferOffset + pcmd->VtxOffset * sizeof(ImDrawVert)) atIndex:0];
|
|
||||||
[commandEncoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
|
|
||||||
indexCount:pcmd->ElemCount
|
|
||||||
indexType:sizeof(ImDrawIdx) == 2 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32
|
|
||||||
indexBuffer:indexBuffer.buffer
|
|
||||||
indexBufferOffset:indexBufferOffset + pcmd->IdxOffset * sizeof(ImDrawIdx)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vertexBufferOffset += (size_t)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
|
|
||||||
indexBufferOffset += (size_t)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx);
|
|
||||||
}
|
|
||||||
|
|
||||||
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer>)
|
|
||||||
{
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
if (bd != nullptr)
|
|
||||||
{
|
|
||||||
@synchronized(bd->SharedMetalContext.bufferCache)
|
|
||||||
{
|
|
||||||
[bd->SharedMetalContext.bufferCache addObject:vertexBuffer];
|
|
||||||
[bd->SharedMetalContext.bufferCache addObject:indexBuffer];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplMetal_CreateFontsTexture(id<MTLDevice> device)
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// We are retrieving and uploading the font atlas as a 4-channels RGBA texture here.
|
|
||||||
// In theory we could call GetTexDataAsAlpha8() and upload a 1-channel texture to save on memory access bandwidth.
|
|
||||||
// However, using a shader designed for 1-channel texture would make it less obvious to use the ImTextureID facility to render users own textures.
|
|
||||||
// You can make that change in your implementation.
|
|
||||||
unsigned char* pixels;
|
|
||||||
int width, height;
|
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
|
||||||
MTLTextureDescriptor* textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm
|
|
||||||
width:(NSUInteger)width
|
|
||||||
height:(NSUInteger)height
|
|
||||||
mipmapped:NO];
|
|
||||||
textureDescriptor.usage = MTLTextureUsageShaderRead;
|
|
||||||
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
|
|
||||||
textureDescriptor.storageMode = MTLStorageModeManaged;
|
|
||||||
#else
|
|
||||||
textureDescriptor.storageMode = MTLStorageModeShared;
|
|
||||||
#endif
|
|
||||||
id <MTLTexture> texture = [device newTextureWithDescriptor:textureDescriptor];
|
|
||||||
[texture replaceRegion:MTLRegionMake2D(0, 0, (NSUInteger)width, (NSUInteger)height) mipmapLevel:0 withBytes:pixels bytesPerRow:(NSUInteger)width * 4];
|
|
||||||
bd->SharedMetalContext.fontTexture = texture;
|
|
||||||
io.Fonts->SetTexID((__bridge void*)bd->SharedMetalContext.fontTexture); // ImTextureID == void*
|
|
||||||
|
|
||||||
return (bd->SharedMetalContext.fontTexture != nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_DestroyFontsTexture()
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
bd->SharedMetalContext.fontTexture = nil;
|
|
||||||
io.Fonts->SetTexID(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device)
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
MTLDepthStencilDescriptor* depthStencilDescriptor = [[MTLDepthStencilDescriptor alloc] init];
|
|
||||||
depthStencilDescriptor.depthWriteEnabled = NO;
|
|
||||||
depthStencilDescriptor.depthCompareFunction = MTLCompareFunctionAlways;
|
|
||||||
bd->SharedMetalContext.depthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
|
|
||||||
ImGui_ImplMetal_CreateFontsTexture(device);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_DestroyDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
ImGui_ImplMetal_DestroyFontsTexture();
|
|
||||||
[bd->SharedMetalContext.renderPipelineStateCache removeAllObjects];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - MetalBuffer implementation
|
|
||||||
|
|
||||||
@implementation MetalBuffer
|
|
||||||
- (instancetype)initWithBuffer:(id<MTLBuffer>)buffer
|
|
||||||
{
|
|
||||||
if ((self = [super init]))
|
|
||||||
{
|
|
||||||
_buffer = buffer;
|
|
||||||
_lastReuseTime = GetMachAbsoluteTimeInSeconds();
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
#pragma mark - FramebufferDescriptor implementation
|
|
||||||
|
|
||||||
@implementation FramebufferDescriptor
|
|
||||||
- (instancetype)initWithRenderPassDescriptor:(MTLRenderPassDescriptor*)renderPassDescriptor
|
|
||||||
{
|
|
||||||
if ((self = [super init]))
|
|
||||||
{
|
|
||||||
_sampleCount = renderPassDescriptor.colorAttachments[0].texture.sampleCount;
|
|
||||||
_colorPixelFormat = renderPassDescriptor.colorAttachments[0].texture.pixelFormat;
|
|
||||||
_depthPixelFormat = renderPassDescriptor.depthAttachment.texture.pixelFormat;
|
|
||||||
_stencilPixelFormat = renderPassDescriptor.stencilAttachment.texture.pixelFormat;
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (nonnull id)copyWithZone:(nullable NSZone*)zone
|
|
||||||
{
|
|
||||||
FramebufferDescriptor* copy = [[FramebufferDescriptor allocWithZone:zone] init];
|
|
||||||
copy.sampleCount = self.sampleCount;
|
|
||||||
copy.colorPixelFormat = self.colorPixelFormat;
|
|
||||||
copy.depthPixelFormat = self.depthPixelFormat;
|
|
||||||
copy.stencilPixelFormat = self.stencilPixelFormat;
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSUInteger)hash
|
|
||||||
{
|
|
||||||
NSUInteger sc = _sampleCount & 0x3;
|
|
||||||
NSUInteger cf = _colorPixelFormat & 0x3FF;
|
|
||||||
NSUInteger df = _depthPixelFormat & 0x3FF;
|
|
||||||
NSUInteger sf = _stencilPixelFormat & 0x3FF;
|
|
||||||
NSUInteger hash = (sf << 22) | (df << 12) | (cf << 2) | sc;
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)isEqual:(id)object
|
|
||||||
{
|
|
||||||
FramebufferDescriptor* other = object;
|
|
||||||
if (![other isKindOfClass:[FramebufferDescriptor class]])
|
|
||||||
return NO;
|
|
||||||
return other.sampleCount == self.sampleCount &&
|
|
||||||
other.colorPixelFormat == self.colorPixelFormat &&
|
|
||||||
other.depthPixelFormat == self.depthPixelFormat &&
|
|
||||||
other.stencilPixelFormat == self.stencilPixelFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#pragma mark - MetalContext implementation
|
|
||||||
|
|
||||||
@implementation MetalContext
|
|
||||||
- (instancetype)init
|
|
||||||
{
|
|
||||||
if ((self = [super init]))
|
|
||||||
{
|
|
||||||
self.renderPipelineStateCache = [NSMutableDictionary dictionary];
|
|
||||||
self.bufferCache = [NSMutableArray array];
|
|
||||||
_lastBufferCachePurge = GetMachAbsoluteTimeInSeconds();
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device
|
|
||||||
{
|
|
||||||
uint64_t now = GetMachAbsoluteTimeInSeconds();
|
|
||||||
|
|
||||||
@synchronized(self.bufferCache)
|
|
||||||
{
|
|
||||||
// Purge old buffers that haven't been useful for a while
|
|
||||||
if (now - self.lastBufferCachePurge > 1.0)
|
|
||||||
{
|
|
||||||
NSMutableArray* survivors = [NSMutableArray array];
|
|
||||||
for (MetalBuffer* candidate in self.bufferCache)
|
|
||||||
if (candidate.lastReuseTime > self.lastBufferCachePurge)
|
|
||||||
[survivors addObject:candidate];
|
|
||||||
self.bufferCache = [survivors mutableCopy];
|
|
||||||
self.lastBufferCachePurge = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
// See if we have a buffer we can reuse
|
|
||||||
MetalBuffer* bestCandidate = nil;
|
|
||||||
for (MetalBuffer* candidate in self.bufferCache)
|
|
||||||
if (candidate.buffer.length >= length && (bestCandidate == nil || bestCandidate.lastReuseTime > candidate.lastReuseTime))
|
|
||||||
bestCandidate = candidate;
|
|
||||||
|
|
||||||
if (bestCandidate != nil)
|
|
||||||
{
|
|
||||||
[self.bufferCache removeObject:bestCandidate];
|
|
||||||
bestCandidate.lastReuseTime = now;
|
|
||||||
return bestCandidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No luck; make a new buffer
|
|
||||||
id<MTLBuffer> backing = [device newBufferWithLength:length options:MTLResourceStorageModeShared];
|
|
||||||
return [[MetalBuffer alloc] initWithBuffer:backing];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
|
|
||||||
- (id<MTLRenderPipelineState>)renderPipelineStateForFramebufferDescriptor:(FramebufferDescriptor*)descriptor device:(id<MTLDevice>)device
|
|
||||||
{
|
|
||||||
NSError* error = nil;
|
|
||||||
|
|
||||||
NSString* shaderSource = @""
|
|
||||||
"#include <metal_stdlib>\n"
|
|
||||||
"using namespace metal;\n"
|
|
||||||
"\n"
|
|
||||||
"struct Uniforms {\n"
|
|
||||||
" float4x4 projectionMatrix;\n"
|
|
||||||
"};\n"
|
|
||||||
"\n"
|
|
||||||
"struct VertexIn {\n"
|
|
||||||
" float2 position [[attribute(0)]];\n"
|
|
||||||
" float2 texCoords [[attribute(1)]];\n"
|
|
||||||
" uchar4 color [[attribute(2)]];\n"
|
|
||||||
"};\n"
|
|
||||||
"\n"
|
|
||||||
"struct VertexOut {\n"
|
|
||||||
" float4 position [[position]];\n"
|
|
||||||
" float2 texCoords;\n"
|
|
||||||
" float4 color;\n"
|
|
||||||
"};\n"
|
|
||||||
"\n"
|
|
||||||
"vertex VertexOut vertex_main(VertexIn in [[stage_in]],\n"
|
|
||||||
" constant Uniforms &uniforms [[buffer(1)]]) {\n"
|
|
||||||
" VertexOut out;\n"
|
|
||||||
" out.position = uniforms.projectionMatrix * float4(in.position, 0, 1);\n"
|
|
||||||
" out.texCoords = in.texCoords;\n"
|
|
||||||
" out.color = float4(in.color) / float4(255.0);\n"
|
|
||||||
" return out;\n"
|
|
||||||
"}\n"
|
|
||||||
"\n"
|
|
||||||
"fragment half4 fragment_main(VertexOut in [[stage_in]],\n"
|
|
||||||
" texture2d<half, access::sample> texture [[texture(0)]]) {\n"
|
|
||||||
" constexpr sampler linearSampler(coord::normalized, min_filter::linear, mag_filter::linear, mip_filter::linear);\n"
|
|
||||||
" half4 texColor = texture.sample(linearSampler, in.texCoords);\n"
|
|
||||||
" return half4(in.color) * texColor;\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
id<MTLLibrary> library = [device newLibraryWithSource:shaderSource options:nil error:&error];
|
|
||||||
if (library == nil)
|
|
||||||
{
|
|
||||||
NSLog(@"Error: failed to create Metal library: %@", error);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
id<MTLFunction> vertexFunction = [library newFunctionWithName:@"vertex_main"];
|
|
||||||
id<MTLFunction> fragmentFunction = [library newFunctionWithName:@"fragment_main"];
|
|
||||||
|
|
||||||
if (vertexFunction == nil || fragmentFunction == nil)
|
|
||||||
{
|
|
||||||
NSLog(@"Error: failed to find Metal shader functions in library: %@", error);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
MTLVertexDescriptor* vertexDescriptor = [MTLVertexDescriptor vertexDescriptor];
|
|
||||||
vertexDescriptor.attributes[0].offset = offsetof(ImDrawVert, pos);
|
|
||||||
vertexDescriptor.attributes[0].format = MTLVertexFormatFloat2; // position
|
|
||||||
vertexDescriptor.attributes[0].bufferIndex = 0;
|
|
||||||
vertexDescriptor.attributes[1].offset = offsetof(ImDrawVert, uv);
|
|
||||||
vertexDescriptor.attributes[1].format = MTLVertexFormatFloat2; // texCoords
|
|
||||||
vertexDescriptor.attributes[1].bufferIndex = 0;
|
|
||||||
vertexDescriptor.attributes[2].offset = offsetof(ImDrawVert, col);
|
|
||||||
vertexDescriptor.attributes[2].format = MTLVertexFormatUChar4; // color
|
|
||||||
vertexDescriptor.attributes[2].bufferIndex = 0;
|
|
||||||
vertexDescriptor.layouts[0].stepRate = 1;
|
|
||||||
vertexDescriptor.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
|
|
||||||
vertexDescriptor.layouts[0].stride = sizeof(ImDrawVert);
|
|
||||||
|
|
||||||
MTLRenderPipelineDescriptor* pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
|
|
||||||
pipelineDescriptor.vertexFunction = vertexFunction;
|
|
||||||
pipelineDescriptor.fragmentFunction = fragmentFunction;
|
|
||||||
pipelineDescriptor.vertexDescriptor = vertexDescriptor;
|
|
||||||
pipelineDescriptor.rasterSampleCount = self.framebufferDescriptor.sampleCount;
|
|
||||||
pipelineDescriptor.colorAttachments[0].pixelFormat = self.framebufferDescriptor.colorPixelFormat;
|
|
||||||
pipelineDescriptor.colorAttachments[0].blendingEnabled = YES;
|
|
||||||
pipelineDescriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperationAdd;
|
|
||||||
pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
|
|
||||||
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
|
|
||||||
pipelineDescriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperationAdd;
|
|
||||||
pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorOne;
|
|
||||||
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
|
|
||||||
pipelineDescriptor.depthAttachmentPixelFormat = self.framebufferDescriptor.depthPixelFormat;
|
|
||||||
pipelineDescriptor.stencilAttachmentPixelFormat = self.framebufferDescriptor.stencilPixelFormat;
|
|
||||||
|
|
||||||
id<MTLRenderPipelineState> renderPipelineState = [device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:&error];
|
|
||||||
if (error != nil)
|
|
||||||
NSLog(@"Error: failed to create Metal pipeline state: %@", error);
|
|
||||||
|
|
||||||
return renderPipelineState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,302 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for OpenGL2 (legacy OpenGL, fixed pipeline)
|
|
||||||
// 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!
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
|
|
||||||
// **Prefer using the code in imgui_impl_opengl3.cpp**
|
|
||||||
// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read.
|
|
||||||
// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more
|
|
||||||
// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might
|
|
||||||
// confuse your GPU driver.
|
|
||||||
// The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API.
|
|
||||||
|
|
||||||
// CHANGELOG
|
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 2021-12-08: OpenGL: Fixed mishandling of the the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
|
|
||||||
// 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-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
||||||
// 2021-01-03: OpenGL: Backup, setup and restore GL_SHADE_MODEL state, disable GL_STENCIL_TEST and disable GL_NORMAL_ARRAY client state to increase compatibility with legacy OpenGL applications.
|
|
||||||
// 2020-01-23: OpenGL: Backup, setup and restore GL_TEXTURE_ENV to increase compatibility with legacy OpenGL applications.
|
|
||||||
// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
||||||
// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
||||||
// 2018-08-03: OpenGL: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications.
|
|
||||||
// 2018-06-08: Misc: Extracted imgui_impl_opengl2.cpp/.h away from the old combined GLFW/SDL+OpenGL2 examples.
|
|
||||||
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
|
||||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplOpenGL2_RenderDrawData() in the .h file so you can call it yourself.
|
|
||||||
// 2017-09-01: OpenGL: Save and restore current polygon mode.
|
|
||||||
// 2016-09-10: OpenGL: Uploading font texture as RGBA32 to increase compatibility with users shaders (not ideal).
|
|
||||||
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_opengl2.h"
|
|
||||||
#include <stdint.h> // intptr_t
|
|
||||||
|
|
||||||
// Clang/GCC warnings with -Weverything
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used
|
|
||||||
#pragma clang diagnostic ignored "-Wnonportable-system-include-path"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Include OpenGL header (without an OpenGL loader) requires a bit of fiddling
|
|
||||||
#if defined(_WIN32) && !defined(APIENTRY)
|
|
||||||
#define APIENTRY __stdcall // It is customary to use APIENTRY for OpenGL function pointer declarations on all platforms. Additionally, the Windows OpenGL header needs APIENTRY.
|
|
||||||
#endif
|
|
||||||
#if defined(_WIN32) && !defined(WINGDIAPI)
|
|
||||||
#define WINGDIAPI __declspec(dllimport) // Some Windows OpenGL headers need this
|
|
||||||
#endif
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#define GL_SILENCE_DEPRECATION
|
|
||||||
#include <OpenGL/gl.h>
|
|
||||||
#else
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct ImGui_ImplOpenGL2_Data
|
|
||||||
{
|
|
||||||
GLuint FontTexture;
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL2_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_ImplOpenGL2_Data* ImGui_ImplOpenGL2_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL2_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
bool ImGui_ImplOpenGL2_Init()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplOpenGL2_Data* bd = IM_NEW(ImGui_ImplOpenGL2_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_opengl2";
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOpenGL2_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL2_DestroyDeviceObjects();
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOpenGL2_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplOpenGL2_Init()?");
|
|
||||||
|
|
||||||
if (!bd->FontTexture)
|
|
||||||
ImGui_ImplOpenGL2_CreateDeviceObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height)
|
|
||||||
{
|
|
||||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
//glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // In order to composite our output buffer we need to preserve alpha
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_STENCIL_TEST);
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
glDisable(GL_COLOR_MATERIAL);
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
||||||
glShadeModel(GL_SMOOTH);
|
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
||||||
|
|
||||||
// If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!),
|
|
||||||
// you may need to backup/reset/restore other state, e.g. for current shader using the commented lines below.
|
|
||||||
// (DO NOT MODIFY THIS FILE! Add the code in your calling function)
|
|
||||||
// GLint last_program;
|
|
||||||
// glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
|
||||||
// glUseProgram(0);
|
|
||||||
// ImGui_ImplOpenGL2_RenderDrawData(...);
|
|
||||||
// glUseProgram(last_program)
|
|
||||||
// There are potentially many more states you could need to clear/setup that we can't access from default headers.
|
|
||||||
// e.g. glBindBuffer(GL_ARRAY_BUFFER, 0), glDisable(GL_TEXTURE_CUBE_MAP).
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
|
||||||
glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f);
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenGL2 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_ImplOpenGL2_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;
|
|
||||||
|
|
||||||
// Backup GL state
|
|
||||||
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
|
||||||
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
|
|
||||||
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
|
||||||
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
|
|
||||||
GLint last_shade_model; glGetIntegerv(GL_SHADE_MODEL, &last_shade_model);
|
|
||||||
GLint last_tex_env_mode; glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &last_tex_env_mode);
|
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
|
||||||
|
|
||||||
// Setup desired GL state
|
|
||||||
ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
|
|
||||||
|
|
||||||
// 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];
|
|
||||||
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
|
||||||
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
|
||||||
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, pos)));
|
|
||||||
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, uv)));
|
|
||||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, col)));
|
|
||||||
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
||||||
{
|
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
||||||
if (pcmd->UserCallback)
|
|
||||||
{
|
|
||||||
// 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_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
|
|
||||||
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)
|
|
||||||
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
|
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID());
|
|
||||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore modified GL state
|
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture);
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glPopMatrix();
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glPopMatrix();
|
|
||||||
glPopAttrib();
|
|
||||||
glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]);
|
|
||||||
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]);
|
|
||||||
glShadeModel(last_shade_model);
|
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_tex_env_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplOpenGL2_CreateFontsTexture()
|
|
||||||
{
|
|
||||||
// Build texture atlas
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
||||||
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;
|
|
||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
|
||||||
glGenTextures(1, &bd->FontTexture);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, bd->FontTexture);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
||||||
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
|
|
||||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOpenGL2_DestroyFontsTexture()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
||||||
if (bd->FontTexture)
|
|
||||||
{
|
|
||||||
glDeleteTextures(1, &bd->FontTexture);
|
|
||||||
io.Fonts->SetTexID(0);
|
|
||||||
bd->FontTexture = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplOpenGL2_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
return ImGui_ImplOpenGL2_CreateFontsTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOpenGL2_DestroyDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplOpenGL2_DestroyFontsTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,38 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for OpenGL2 (legacy OpenGL, fixed pipeline)
|
|
||||||
// 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!
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
|
|
||||||
// **Prefer using the code in imgui_impl_opengl3.cpp**
|
|
||||||
// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read.
|
|
||||||
// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more
|
|
||||||
// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might
|
|
||||||
// confuse your GPU driver.
|
|
||||||
// The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL2_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
|
|
||||||
// Called by Init/NewFrame/Shutdown
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateFontsTexture();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyFontsTexture();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,948 +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).
|
|
||||||
|
|
||||||
// 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-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 glPolygonMode() which GL ES and WebGL don't have.
|
|
||||||
#ifdef GL_POLYGON_MODE
|
|
||||||
#define IMGUI_IMPL_HAS_POLYGON_MODE
|
|
||||||
#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
|
|
||||||
|
|
||||||
// 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 use extension detection
|
|
||||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
|
|
||||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// [Debugging]
|
|
||||||
//#define IMGUI_IMPL_OPENGL_DEBUG
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
|
||||||
#include <stdio.h>
|
|
||||||
#define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check
|
|
||||||
#else
|
|
||||||
#define GL_CALL(_CALL) _CALL // Call without error check
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// OpenGL Data
|
|
||||||
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 HasClipOrigin;
|
|
||||||
bool UseBufferSubData;
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
|
||||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
||||||
static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only)
|
|
||||||
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
|
||||||
struct ImGui_ImplOpenGL3_VtxAttribState
|
|
||||||
{
|
|
||||||
GLint Enabled, Size, Type, Normalized, Stride;
|
|
||||||
GLvoid* Ptr;
|
|
||||||
|
|
||||||
void GetState(GLint index)
|
|
||||||
{
|
|
||||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled);
|
|
||||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size);
|
|
||||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type);
|
|
||||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized);
|
|
||||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride);
|
|
||||||
glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr);
|
|
||||||
}
|
|
||||||
void SetState(GLint index)
|
|
||||||
{
|
|
||||||
glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr);
|
|
||||||
if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
// Initialize our loader
|
|
||||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
|
||||||
if (imgl3wInit() != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_opengl3";
|
|
||||||
|
|
||||||
// Query for GL version (e.g. 320 for GL 3.2)
|
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
|
||||||
// GLES 2
|
|
||||||
bd->GlVersion = 200;
|
|
||||||
bd->GlProfileIsES2 = true;
|
|
||||||
#else
|
|
||||||
// Desktop or GLES 3
|
|
||||||
GLint major = 0;
|
|
||||||
GLint minor = 0;
|
|
||||||
glGetIntegerv(GL_MAJOR_VERSION, &major);
|
|
||||||
glGetIntegerv(GL_MINOR_VERSION, &minor);
|
|
||||||
if (major == 0 && minor == 0)
|
|
||||||
{
|
|
||||||
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
|
||||||
const char* gl_version = (const char*)glGetString(GL_VERSION);
|
|
||||||
sscanf(gl_version, "%d.%d", &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;
|
|
||||||
#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\nGlProfileIsCompat = %d\nGlProfileMask = 0x%X\nGlProfileIsES2 = %d, GlProfileIsES3 = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", bd->GlVersion, 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
|
|
||||||
|
|
||||||
// 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
|
|
||||||
bd->HasClipOrigin = (bd->GlVersion >= 450);
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
|
|
||||||
GLint num_extensions = 0;
|
|
||||||
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
|
|
||||||
for (GLint i = 0; i < num_extensions; i++)
|
|
||||||
{
|
|
||||||
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
|
||||||
if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0)
|
|
||||||
bd->HasClipOrigin = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOpenGL3_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOpenGL3_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "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_HAS_POLYGON_MODE
|
|
||||||
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_HAS_POLYGON_MODE
|
|
||||||
GLint last_polygon_mode[2]; 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_HAS_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->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_HAS_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_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_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();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,66 +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).
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
// Specific OpenGL ES versions
|
|
||||||
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
|
|
||||||
//#define IMGUI_IMPL_OPENGL_ES3 // 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,814 +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:
|
|
||||||
// python gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
|
|
||||||
//
|
|
||||||
// More info:
|
|
||||||
// https://github.com/dearimgui/gl3w_stripped
|
|
||||||
// https://github.com/ocornut/imgui/issues/4445
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file was generated with gl3w_gen.py, part of imgl3w
|
|
||||||
* (hosted at https://github.com/dearimgui/gl3w_stripped)
|
|
||||||
*
|
|
||||||
* This is free and unencumbered software released into the public domain.
|
|
||||||
*
|
|
||||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
||||||
* distribute this software, either in source code form or as a compiled
|
|
||||||
* binary, for any purpose, commercial or non-commercial, and by any
|
|
||||||
* means.
|
|
||||||
*
|
|
||||||
* In jurisdictions that recognize copyright laws, the author or authors
|
|
||||||
* of this software dedicate any and all copyright interest in the
|
|
||||||
* software to the public domain. We make this dedication for the benefit
|
|
||||||
* of the public at large and to the detriment of our heirs and
|
|
||||||
* successors. We intend this dedication to be an overt act of
|
|
||||||
* relinquishment in perpetuity of all present and future rights to this
|
|
||||||
* software under copyright law.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
||||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
||||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __gl3w_h_
|
|
||||||
#define __gl3w_h_
|
|
||||||
|
|
||||||
// Adapted from KHR/khrplatform.h to avoid including entire file.
|
|
||||||
#ifndef __khrplatform_h_
|
|
||||||
typedef float khronos_float_t;
|
|
||||||
typedef signed char khronos_int8_t;
|
|
||||||
typedef unsigned char khronos_uint8_t;
|
|
||||||
typedef signed short int khronos_int16_t;
|
|
||||||
typedef unsigned short int khronos_uint16_t;
|
|
||||||
#ifdef _WIN64
|
|
||||||
typedef signed long long int khronos_intptr_t;
|
|
||||||
typedef signed long long int khronos_ssize_t;
|
|
||||||
#else
|
|
||||||
typedef signed long int khronos_intptr_t;
|
|
||||||
typedef signed long int khronos_ssize_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(__clang__)
|
|
||||||
typedef signed __int64 khronos_int64_t;
|
|
||||||
typedef unsigned __int64 khronos_uint64_t;
|
|
||||||
#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#else
|
|
||||||
typedef signed long long khronos_int64_t;
|
|
||||||
typedef unsigned long long khronos_uint64_t;
|
|
||||||
#endif
|
|
||||||
#endif // __khrplatform_h_
|
|
||||||
|
|
||||||
#ifndef __gl_glcorearb_h_
|
|
||||||
#define __gl_glcorearb_h_ 1
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
** Copyright 2013-2020 The Khronos Group Inc.
|
|
||||||
** SPDX-License-Identifier: MIT
|
|
||||||
**
|
|
||||||
** This header is generated from the Khronos OpenGL / OpenGL ES XML
|
|
||||||
** API Registry. The current version of the Registry, generator scripts
|
|
||||||
** used to make the header, and the header can be found at
|
|
||||||
** https://github.com/KhronosGroup/OpenGL-Registry
|
|
||||||
*/
|
|
||||||
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#endif
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
#ifndef APIENTRY
|
|
||||||
#define APIENTRY
|
|
||||||
#endif
|
|
||||||
#ifndef APIENTRYP
|
|
||||||
#define APIENTRYP APIENTRY *
|
|
||||||
#endif
|
|
||||||
#ifndef GLAPI
|
|
||||||
#define GLAPI extern
|
|
||||||
#endif
|
|
||||||
/* glcorearb.h is for use with OpenGL core profile implementations.
|
|
||||||
** It should should be placed in the same directory as gl.h and
|
|
||||||
** included as <GL/glcorearb.h>.
|
|
||||||
**
|
|
||||||
** glcorearb.h includes only APIs in the latest OpenGL core profile
|
|
||||||
** implementation together with APIs in newer ARB extensions which
|
|
||||||
** can be supported by the core profile. It does not, and never will
|
|
||||||
** include functionality removed from the core profile, such as
|
|
||||||
** fixed-function vertex and fragment processing.
|
|
||||||
**
|
|
||||||
** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
|
|
||||||
** <GL/glext.h> in the same source file.
|
|
||||||
*/
|
|
||||||
/* Generated C header for:
|
|
||||||
* API: gl
|
|
||||||
* Profile: core
|
|
||||||
* Versions considered: .*
|
|
||||||
* Versions emitted: .*
|
|
||||||
* Default extensions included: glcore
|
|
||||||
* Additional extensions included: _nomatch_^
|
|
||||||
* Extensions removed: _nomatch_^
|
|
||||||
*/
|
|
||||||
#ifndef GL_VERSION_1_0
|
|
||||||
typedef void GLvoid;
|
|
||||||
typedef unsigned int GLenum;
|
|
||||||
|
|
||||||
typedef khronos_float_t GLfloat;
|
|
||||||
typedef int GLint;
|
|
||||||
typedef int GLsizei;
|
|
||||||
typedef unsigned int GLbitfield;
|
|
||||||
typedef double GLdouble;
|
|
||||||
typedef unsigned int GLuint;
|
|
||||||
typedef unsigned char GLboolean;
|
|
||||||
typedef khronos_uint8_t GLubyte;
|
|
||||||
#define GL_COLOR_BUFFER_BIT 0x00004000
|
|
||||||
#define GL_FALSE 0
|
|
||||||
#define GL_TRUE 1
|
|
||||||
#define GL_TRIANGLES 0x0004
|
|
||||||
#define GL_ONE 1
|
|
||||||
#define GL_SRC_ALPHA 0x0302
|
|
||||||
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
|
|
||||||
#define GL_FRONT 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_TEXTURE_MAG_FILTER 0x2800
|
|
||||||
#define GL_TEXTURE_MIN_FILTER 0x2801
|
|
||||||
typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
|
|
||||||
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
|
||||||
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
|
|
||||||
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
|
||||||
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
|
|
||||||
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
|
||||||
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
|
|
||||||
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
|
|
||||||
typedef void (APIENTRYP PFNGLFLUSHPROC) (void);
|
|
||||||
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
|
|
||||||
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
|
||||||
typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
|
|
||||||
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
|
|
||||||
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
|
|
||||||
typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
|
|
||||||
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
|
||||||
GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
|
|
||||||
GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
|
|
||||||
GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
|
|
||||||
GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
|
||||||
GLAPI void APIENTRY glClear (GLbitfield mask);
|
|
||||||
GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
|
||||||
GLAPI void APIENTRY glDisable (GLenum cap);
|
|
||||||
GLAPI void APIENTRY glEnable (GLenum cap);
|
|
||||||
GLAPI void APIENTRY glFlush (void);
|
|
||||||
GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
|
|
||||||
GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
|
||||||
GLAPI GLenum APIENTRY glGetError (void);
|
|
||||||
GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
|
|
||||||
GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
|
|
||||||
GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
|
|
||||||
GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
|
|
||||||
#endif
|
|
||||||
#endif /* GL_VERSION_1_0 */
|
|
||||||
#ifndef GL_VERSION_1_1
|
|
||||||
typedef khronos_float_t GLclampf;
|
|
||||||
typedef double GLclampd;
|
|
||||||
#define GL_TEXTURE_BINDING_2D 0x8069
|
|
||||||
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
|
||||||
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
|
|
||||||
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
|
|
||||||
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
|
||||||
GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
|
||||||
GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
|
|
||||||
GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
|
|
||||||
GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
|
|
||||||
#endif
|
|
||||||
#endif /* GL_VERSION_1_1 */
|
|
||||||
#ifndef GL_VERSION_1_3
|
|
||||||
#define GL_TEXTURE0 0x84C0
|
|
||||||
#define GL_ACTIVE_TEXTURE 0x84E0
|
|
||||||
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
|
||||||
GLAPI void APIENTRY glActiveTexture (GLenum texture);
|
|
||||||
#endif
|
|
||||||
#endif /* GL_VERSION_1_3 */
|
|
||||||
#ifndef GL_VERSION_1_4
|
|
||||||
#define GL_BLEND_DST_RGB 0x80C8
|
|
||||||
#define GL_BLEND_SRC_RGB 0x80C9
|
|
||||||
#define GL_BLEND_DST_ALPHA 0x80CA
|
|
||||||
#define GL_BLEND_SRC_ALPHA 0x80CB
|
|
||||||
#define GL_FUNC_ADD 0x8006
|
|
||||||
typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
|
||||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
|
||||||
GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
|
||||||
GLAPI void APIENTRY glBlendEquation (GLenum mode);
|
|
||||||
#endif
|
|
||||||
#endif /* GL_VERSION_1_4 */
|
|
||||||
#ifndef GL_VERSION_1_5
|
|
||||||
typedef khronos_ssize_t GLsizeiptr;
|
|
||||||
typedef khronos_intptr_t GLintptr;
|
|
||||||
#define GL_ARRAY_BUFFER 0x8892
|
|
||||||
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
|
|
||||||
#define GL_ARRAY_BUFFER_BINDING 0x8894
|
|
||||||
#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
|
|
||||||
#define GL_STREAM_DRAW 0x88E0
|
|
||||||
typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
|
|
||||||
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
|
|
||||||
typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
|
|
||||||
typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
|
||||||
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
|
||||||
#ifdef GL_GLEXT_PROTOTYPES
|
|
||||||
GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
|
|
||||||
GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
|
|
||||||
GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
|
|
||||||
GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
|
||||||
GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
|
||||||
#endif
|
|
||||||
#endif /* GL_VERSION_1_5 */
|
|
||||||
#ifndef GL_VERSION_2_0
|
|
||||||
typedef char GLchar;
|
|
||||||
typedef khronos_int16_t GLshort;
|
|
||||||
typedef khronos_int8_t GLbyte;
|
|
||||||
typedef khronos_uint16_t GLushort;
|
|
||||||
#define GL_BLEND_EQUATION_RGB 0x8009
|
|
||||||
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
|
|
||||||
#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
|
|
||||||
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
|
|
||||||
#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
|
|
||||||
#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
|
|
||||||
#define GL_BLEND_EQUATION_ALPHA 0x883D
|
|
||||||
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
|
|
||||||
#define GL_FRAGMENT_SHADER 0x8B30
|
|
||||||
#define GL_VERTEX_SHADER 0x8B31
|
|
||||||
#define GL_COMPILE_STATUS 0x8B81
|
|
||||||
#define GL_LINK_STATUS 0x8B82
|
|
||||||
#define GL_INFO_LOG_LENGTH 0x8B84
|
|
||||||
#define GL_CURRENT_PROGRAM 0x8B8D
|
|
||||||
#define GL_UPPER_LEFT 0x8CA2
|
|
||||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
|
|
||||||
typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
|
|
||||||
typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
|
|
||||||
typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
|
|
||||||
typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
|
|
||||||
typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
|
|
||||||
typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
|
|
||||||
typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
|
|
||||||
typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
|
||||||
typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
|
||||||
typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
|
|
||||||
typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
|
|
||||||
typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
|
||||||
typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
|
|
||||||
typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
|
||||||
typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
|
|
||||||
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
|
|
||||||
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
|
|
||||||
typedef 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_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[59];
|
|
||||||
struct {
|
|
||||||
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
|
||||||
PFNGLATTACHSHADERPROC AttachShader;
|
|
||||||
PFNGLBINDBUFFERPROC BindBuffer;
|
|
||||||
PFNGLBINDSAMPLERPROC BindSampler;
|
|
||||||
PFNGLBINDTEXTUREPROC BindTexture;
|
|
||||||
PFNGLBINDVERTEXARRAYPROC BindVertexArray;
|
|
||||||
PFNGLBLENDEQUATIONPROC BlendEquation;
|
|
||||||
PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
|
|
||||||
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
|
|
||||||
PFNGLBUFFERDATAPROC BufferData;
|
|
||||||
PFNGLBUFFERSUBDATAPROC BufferSubData;
|
|
||||||
PFNGLCLEARPROC Clear;
|
|
||||||
PFNGLCLEARCOLORPROC ClearColor;
|
|
||||||
PFNGLCOMPILESHADERPROC CompileShader;
|
|
||||||
PFNGLCREATEPROGRAMPROC CreateProgram;
|
|
||||||
PFNGLCREATESHADERPROC CreateShader;
|
|
||||||
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
|
||||||
PFNGLDELETEPROGRAMPROC DeleteProgram;
|
|
||||||
PFNGLDELETESHADERPROC DeleteShader;
|
|
||||||
PFNGLDELETETEXTURESPROC DeleteTextures;
|
|
||||||
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
|
|
||||||
PFNGLDETACHSHADERPROC DetachShader;
|
|
||||||
PFNGLDISABLEPROC Disable;
|
|
||||||
PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
|
|
||||||
PFNGLDRAWELEMENTSPROC DrawElements;
|
|
||||||
PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
|
|
||||||
PFNGLENABLEPROC Enable;
|
|
||||||
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
|
|
||||||
PFNGLFLUSHPROC Flush;
|
|
||||||
PFNGLGENBUFFERSPROC GenBuffers;
|
|
||||||
PFNGLGENTEXTURESPROC GenTextures;
|
|
||||||
PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
|
|
||||||
PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
|
|
||||||
PFNGLGETERRORPROC GetError;
|
|
||||||
PFNGLGETINTEGERVPROC GetIntegerv;
|
|
||||||
PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
|
|
||||||
PFNGLGETPROGRAMIVPROC GetProgramiv;
|
|
||||||
PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
|
|
||||||
PFNGLGETSHADERIVPROC GetShaderiv;
|
|
||||||
PFNGLGETSTRINGPROC GetString;
|
|
||||||
PFNGLGETSTRINGIPROC GetStringi;
|
|
||||||
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
|
|
||||||
PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
|
|
||||||
PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
|
|
||||||
PFNGLISENABLEDPROC IsEnabled;
|
|
||||||
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 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;
|
|
||||||
static GL3WglProc (*glx_get_proc_address)(const GLubyte *);
|
|
||||||
|
|
||||||
static int open_libgl(void)
|
|
||||||
{
|
|
||||||
// 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_ERROR_LIBRARY_OPEN;
|
|
||||||
*(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
|
|
||||||
return GL3W_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void close_libgl(void) { dlclose(libgl); }
|
|
||||||
|
|
||||||
static GL3WglProc get_proc(const char *proc)
|
|
||||||
{
|
|
||||||
GL3WglProc res;
|
|
||||||
res = glx_get_proc_address((const GLubyte *)proc);
|
|
||||||
if (!res)
|
|
||||||
*(void **)(&res) = dlsym(libgl, proc);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static struct { int major, minor; } version;
|
|
||||||
|
|
||||||
static int parse_version(void)
|
|
||||||
{
|
|
||||||
if (!glGetIntegerv)
|
|
||||||
return GL3W_ERROR_INIT;
|
|
||||||
glGetIntegerv(GL_MAJOR_VERSION, &version.major);
|
|
||||||
glGetIntegerv(GL_MINOR_VERSION, &version.minor);
|
|
||||||
if (version.major == 0 && version.minor == 0)
|
|
||||||
{
|
|
||||||
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
|
||||||
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",
|
|
||||||
"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
|
|
@ -1,51 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for OSX / Cocoa
|
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..)
|
|
||||||
// - Not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac.
|
|
||||||
// - Requires linking with the GameController framework ("-framework GameController").
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/Pen.
|
|
||||||
// [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 kVK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this backend).
|
|
||||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [X] Platform: IME support.
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
|
|
||||||
@class NSEvent;
|
|
||||||
@class NSView;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOSX_Init(NSView* _Nonnull view);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView* _Nullable view);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// C++ API
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_METAL_CPP_EXTENSIONS
|
|
||||||
// #include <AppKit/AppKit.hpp>
|
|
||||||
#ifndef __OBJC__
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOSX_Init(void* _Nonnull view);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(void* _Nullable view);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,812 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for OSX / Cocoa
|
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..)
|
|
||||||
// - Not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac.
|
|
||||||
// - Requires linking with the GameController framework ("-framework GameController").
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/Pen.
|
|
||||||
// [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 kVK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this backend).
|
|
||||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [X] Platform: IME support.
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
#import "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#import "imgui_impl_osx.h"
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import <Carbon/Carbon.h>
|
|
||||||
#import <GameController/GameController.h>
|
|
||||||
#import <time.h>
|
|
||||||
|
|
||||||
// CHANGELOG
|
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
|
||||||
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F20 function keys. Stopped mapping F13 into PrintScreen.
|
|
||||||
// 2023-04-09: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_Pen.
|
|
||||||
// 2023-02-01: Fixed scroll wheel scaling for devices emitting events with hasPreciseScrollingDeltas==false (e.g. non-Apple mices).
|
|
||||||
// 2022-11-02: Fixed mouse coordinates before clicking the host window.
|
|
||||||
// 2022-10-06: Fixed mouse inputs on flipped views.
|
|
||||||
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
|
|
||||||
// 2022-05-03: Inputs: Removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend automatically handling event capture.
|
|
||||||
// 2022-04-27: Misc: Store backend data in a per-context struct, allowing to use this backend with multiple contexts.
|
|
||||||
// 2022-03-22: Inputs: Monitor NSKeyUp events to catch missing keyUp for key when user press Cmd + key
|
|
||||||
// 2022-02-07: Inputs: Forward keyDown/keyUp events to OS when unused by dear imgui.
|
|
||||||
// 2022-01-31: Fixed building with old Xcode versions that are missing gamepad features.
|
|
||||||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
|
||||||
// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
|
|
||||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
|
||||||
// 2022-01-12: Inputs: Added basic Platform IME support, hooking the io.SetPlatformImeDataFn() function.
|
|
||||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
|
||||||
// 2021-12-13: *BREAKING CHANGE* Add NSView parameter to ImGui_ImplOSX_Init(). Generally fix keyboard support. Using kVK_* codes for keyboard keys.
|
|
||||||
// 2021-12-13: Add game controller support.
|
|
||||||
// 2021-09-21: Use mach_absolute_time as CFAbsoluteTimeGetCurrent can jump backwards.
|
|
||||||
// 2021-08-17: Calling io.AddFocusEvent() on NSApplicationDidBecomeActiveNotification/NSApplicationDidResignActiveNotification events.
|
|
||||||
// 2021-06-23: Inputs: Added a fix for shortcuts using CTRL key instead of CMD key.
|
|
||||||
// 2021-04-19: Inputs: Added a fix for keys remaining stuck in pressed state when CMD-tabbing into different application.
|
|
||||||
// 2021-01-27: Inputs: Added a fix for mouse position not being reported when mouse buttons other than left one are down.
|
|
||||||
// 2020-10-28: Inputs: Added a fix for handling keypad-enter key.
|
|
||||||
// 2020-05-25: Inputs: Added a fix for missing trackpad clicks when done with "soft tap".
|
|
||||||
// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor.
|
|
||||||
// 2019-10-11: Inputs: Fix using Backspace key.
|
|
||||||
// 2019-07-21: Re-added clipboard handlers as they are not enabled by default in core imgui.cpp (reverted 2019-05-18 change).
|
|
||||||
// 2019-05-28: Inputs: Added mouse cursor shape and visibility support.
|
|
||||||
// 2019-05-18: Misc: Removed clipboard handlers as they are now supported by core imgui.cpp.
|
|
||||||
// 2019-05-11: Inputs: Don't filter character values before calling AddInputCharacter() apart from 0xF700..0xFFFF range.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
|
||||||
// 2018-07-07: Initial version.
|
|
||||||
|
|
||||||
#define APPLE_HAS_BUTTON_OPTIONS (__IPHONE_OS_VERSION_MIN_REQUIRED >= 130000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500 || __TV_OS_VERSION_MIN_REQUIRED >= 130000)
|
|
||||||
#define APPLE_HAS_CONTROLLER (__IPHONE_OS_VERSION_MIN_REQUIRED >= 140000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000 || __TV_OS_VERSION_MIN_REQUIRED >= 140000)
|
|
||||||
#define APPLE_HAS_THUMBSTICKS (__IPHONE_OS_VERSION_MIN_REQUIRED >= 120100 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101401 || __TV_OS_VERSION_MIN_REQUIRED >= 120100)
|
|
||||||
|
|
||||||
@class ImGuiObserver;
|
|
||||||
@class KeyEventResponder;
|
|
||||||
|
|
||||||
// Data
|
|
||||||
struct ImGui_ImplOSX_Data
|
|
||||||
{
|
|
||||||
CFTimeInterval Time;
|
|
||||||
NSCursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
|
||||||
bool MouseCursorHidden;
|
|
||||||
ImGuiObserver* Observer;
|
|
||||||
KeyEventResponder* KeyEventResponder;
|
|
||||||
NSTextInputContext* InputContext;
|
|
||||||
id Monitor;
|
|
||||||
|
|
||||||
ImGui_ImplOSX_Data() { memset(this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
static ImGui_ImplOSX_Data* ImGui_ImplOSX_CreateBackendData() { return IM_NEW(ImGui_ImplOSX_Data)(); }
|
|
||||||
static ImGui_ImplOSX_Data* ImGui_ImplOSX_GetBackendData() { return (ImGui_ImplOSX_Data*)ImGui::GetIO().BackendPlatformUserData; }
|
|
||||||
static void ImGui_ImplOSX_DestroyBackendData() { IM_DELETE(ImGui_ImplOSX_GetBackendData()); }
|
|
||||||
|
|
||||||
static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return (CFTimeInterval)(double)(clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1e9); }
|
|
||||||
|
|
||||||
// Forward Declarations
|
|
||||||
static void ImGui_ImplOSX_AddTrackingArea(NSView* _Nonnull view);
|
|
||||||
static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view);
|
|
||||||
|
|
||||||
// Undocumented methods for creating cursors.
|
|
||||||
@interface NSCursor()
|
|
||||||
+ (id)_windowResizeNorthWestSouthEastCursor;
|
|
||||||
+ (id)_windowResizeNorthEastSouthWestCursor;
|
|
||||||
+ (id)_windowResizeNorthSouthCursor;
|
|
||||||
+ (id)_windowResizeEastWestCursor;
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**
|
|
||||||
KeyEventResponder implements the NSTextInputClient protocol as is required by the macOS text input manager.
|
|
||||||
|
|
||||||
The macOS text input manager is invoked by calling the interpretKeyEvents method from the keyDown method.
|
|
||||||
Keyboard events are then evaluated by the macOS input manager and valid text input is passed back via the
|
|
||||||
insertText:replacementRange method.
|
|
||||||
|
|
||||||
This is the same approach employed by other cross-platform libraries such as SDL2:
|
|
||||||
https://github.com/spurious/SDL-mirror/blob/e17aacbd09e65a4fd1e166621e011e581fb017a8/src/video/cocoa/SDL_cocoakeyboard.m#L53
|
|
||||||
and GLFW:
|
|
||||||
https://github.com/glfw/glfw/blob/b55a517ae0c7b5127dffa79a64f5406021bf9076/src/cocoa_window.m#L722-L723
|
|
||||||
*/
|
|
||||||
@interface KeyEventResponder: NSView<NSTextInputClient>
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation KeyEventResponder
|
|
||||||
{
|
|
||||||
float _posX;
|
|
||||||
float _posY;
|
|
||||||
NSRect _imeRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Public
|
|
||||||
|
|
||||||
- (void)setImePosX:(float)posX imePosY:(float)posY
|
|
||||||
{
|
|
||||||
_posX = posX;
|
|
||||||
_posY = posY;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)updateImePosWithView:(NSView *)view
|
|
||||||
{
|
|
||||||
NSWindow *window = view.window;
|
|
||||||
if (!window)
|
|
||||||
return;
|
|
||||||
NSRect contentRect = [window contentRectForFrameRect:window.frame];
|
|
||||||
NSRect rect = NSMakeRect(_posX, contentRect.size.height - _posY, 0, 0);
|
|
||||||
_imeRect = [window convertRectToScreen:rect];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)viewDidMoveToWindow
|
|
||||||
{
|
|
||||||
// Ensure self is a first responder to receive the input events.
|
|
||||||
[self.window makeFirstResponder:self];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)keyDown:(NSEvent*)event
|
|
||||||
{
|
|
||||||
if (!ImGui_ImplOSX_HandleEvent(event, self))
|
|
||||||
[super keyDown:event];
|
|
||||||
|
|
||||||
// Call to the macOS input manager system.
|
|
||||||
[self interpretKeyEvents:@[event]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)keyUp:(NSEvent*)event
|
|
||||||
{
|
|
||||||
if (!ImGui_ImplOSX_HandleEvent(event, self))
|
|
||||||
[super keyUp:event];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
NSString* characters;
|
|
||||||
if ([aString isKindOfClass:[NSAttributedString class]])
|
|
||||||
characters = [aString string];
|
|
||||||
else
|
|
||||||
characters = (NSString*)aString;
|
|
||||||
|
|
||||||
io.AddInputCharactersUTF8(characters.UTF8String);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)acceptsFirstResponder
|
|
||||||
{
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)doCommandBySelector:(SEL)myselector
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (nullable NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange
|
|
||||||
{
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSUInteger)characterIndexForPoint:(NSPoint)point
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange
|
|
||||||
{
|
|
||||||
return _imeRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)hasMarkedText
|
|
||||||
{
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSRange)markedRange
|
|
||||||
{
|
|
||||||
return NSMakeRange(NSNotFound, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSRange)selectedRange
|
|
||||||
{
|
|
||||||
return NSMakeRange(NSNotFound, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setMarkedText:(nonnull id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)unmarkText
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (nonnull NSArray<NSAttributedStringKey>*)validAttributesForMarkedText
|
|
||||||
{
|
|
||||||
return @[];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface ImGuiObserver : NSObject
|
|
||||||
|
|
||||||
- (void)onApplicationBecomeActive:(NSNotification*)aNotification;
|
|
||||||
- (void)onApplicationBecomeInactive:(NSNotification*)aNotification;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation ImGuiObserver
|
|
||||||
|
|
||||||
- (void)onApplicationBecomeActive:(NSNotification*)aNotification
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddFocusEvent(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)onApplicationBecomeInactive:(NSNotification*)aNotification
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddFocusEvent(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static ImGuiKey ImGui_ImplOSX_KeyCodeToImGuiKey(int key_code)
|
|
||||||
{
|
|
||||||
switch (key_code)
|
|
||||||
{
|
|
||||||
case kVK_ANSI_A: return ImGuiKey_A;
|
|
||||||
case kVK_ANSI_S: return ImGuiKey_S;
|
|
||||||
case kVK_ANSI_D: return ImGuiKey_D;
|
|
||||||
case kVK_ANSI_F: return ImGuiKey_F;
|
|
||||||
case kVK_ANSI_H: return ImGuiKey_H;
|
|
||||||
case kVK_ANSI_G: return ImGuiKey_G;
|
|
||||||
case kVK_ANSI_Z: return ImGuiKey_Z;
|
|
||||||
case kVK_ANSI_X: return ImGuiKey_X;
|
|
||||||
case kVK_ANSI_C: return ImGuiKey_C;
|
|
||||||
case kVK_ANSI_V: return ImGuiKey_V;
|
|
||||||
case kVK_ANSI_B: return ImGuiKey_B;
|
|
||||||
case kVK_ANSI_Q: return ImGuiKey_Q;
|
|
||||||
case kVK_ANSI_W: return ImGuiKey_W;
|
|
||||||
case kVK_ANSI_E: return ImGuiKey_E;
|
|
||||||
case kVK_ANSI_R: return ImGuiKey_R;
|
|
||||||
case kVK_ANSI_Y: return ImGuiKey_Y;
|
|
||||||
case kVK_ANSI_T: return ImGuiKey_T;
|
|
||||||
case kVK_ANSI_1: return ImGuiKey_1;
|
|
||||||
case kVK_ANSI_2: return ImGuiKey_2;
|
|
||||||
case kVK_ANSI_3: return ImGuiKey_3;
|
|
||||||
case kVK_ANSI_4: return ImGuiKey_4;
|
|
||||||
case kVK_ANSI_6: return ImGuiKey_6;
|
|
||||||
case kVK_ANSI_5: return ImGuiKey_5;
|
|
||||||
case kVK_ANSI_Equal: return ImGuiKey_Equal;
|
|
||||||
case kVK_ANSI_9: return ImGuiKey_9;
|
|
||||||
case kVK_ANSI_7: return ImGuiKey_7;
|
|
||||||
case kVK_ANSI_Minus: return ImGuiKey_Minus;
|
|
||||||
case kVK_ANSI_8: return ImGuiKey_8;
|
|
||||||
case kVK_ANSI_0: return ImGuiKey_0;
|
|
||||||
case kVK_ANSI_RightBracket: return ImGuiKey_RightBracket;
|
|
||||||
case kVK_ANSI_O: return ImGuiKey_O;
|
|
||||||
case kVK_ANSI_U: return ImGuiKey_U;
|
|
||||||
case kVK_ANSI_LeftBracket: return ImGuiKey_LeftBracket;
|
|
||||||
case kVK_ANSI_I: return ImGuiKey_I;
|
|
||||||
case kVK_ANSI_P: return ImGuiKey_P;
|
|
||||||
case kVK_ANSI_L: return ImGuiKey_L;
|
|
||||||
case kVK_ANSI_J: return ImGuiKey_J;
|
|
||||||
case kVK_ANSI_Quote: return ImGuiKey_Apostrophe;
|
|
||||||
case kVK_ANSI_K: return ImGuiKey_K;
|
|
||||||
case kVK_ANSI_Semicolon: return ImGuiKey_Semicolon;
|
|
||||||
case kVK_ANSI_Backslash: return ImGuiKey_Backslash;
|
|
||||||
case kVK_ANSI_Comma: return ImGuiKey_Comma;
|
|
||||||
case kVK_ANSI_Slash: return ImGuiKey_Slash;
|
|
||||||
case kVK_ANSI_N: return ImGuiKey_N;
|
|
||||||
case kVK_ANSI_M: return ImGuiKey_M;
|
|
||||||
case kVK_ANSI_Period: return ImGuiKey_Period;
|
|
||||||
case kVK_ANSI_Grave: return ImGuiKey_GraveAccent;
|
|
||||||
case kVK_ANSI_KeypadDecimal: return ImGuiKey_KeypadDecimal;
|
|
||||||
case kVK_ANSI_KeypadMultiply: return ImGuiKey_KeypadMultiply;
|
|
||||||
case kVK_ANSI_KeypadPlus: return ImGuiKey_KeypadAdd;
|
|
||||||
case kVK_ANSI_KeypadClear: return ImGuiKey_NumLock;
|
|
||||||
case kVK_ANSI_KeypadDivide: return ImGuiKey_KeypadDivide;
|
|
||||||
case kVK_ANSI_KeypadEnter: return ImGuiKey_KeypadEnter;
|
|
||||||
case kVK_ANSI_KeypadMinus: return ImGuiKey_KeypadSubtract;
|
|
||||||
case kVK_ANSI_KeypadEquals: return ImGuiKey_KeypadEqual;
|
|
||||||
case kVK_ANSI_Keypad0: return ImGuiKey_Keypad0;
|
|
||||||
case kVK_ANSI_Keypad1: return ImGuiKey_Keypad1;
|
|
||||||
case kVK_ANSI_Keypad2: return ImGuiKey_Keypad2;
|
|
||||||
case kVK_ANSI_Keypad3: return ImGuiKey_Keypad3;
|
|
||||||
case kVK_ANSI_Keypad4: return ImGuiKey_Keypad4;
|
|
||||||
case kVK_ANSI_Keypad5: return ImGuiKey_Keypad5;
|
|
||||||
case kVK_ANSI_Keypad6: return ImGuiKey_Keypad6;
|
|
||||||
case kVK_ANSI_Keypad7: return ImGuiKey_Keypad7;
|
|
||||||
case kVK_ANSI_Keypad8: return ImGuiKey_Keypad8;
|
|
||||||
case kVK_ANSI_Keypad9: return ImGuiKey_Keypad9;
|
|
||||||
case kVK_Return: return ImGuiKey_Enter;
|
|
||||||
case kVK_Tab: return ImGuiKey_Tab;
|
|
||||||
case kVK_Space: return ImGuiKey_Space;
|
|
||||||
case kVK_Delete: return ImGuiKey_Backspace;
|
|
||||||
case kVK_Escape: return ImGuiKey_Escape;
|
|
||||||
case kVK_CapsLock: return ImGuiKey_CapsLock;
|
|
||||||
case kVK_Control: return ImGuiKey_LeftCtrl;
|
|
||||||
case kVK_Shift: return ImGuiKey_LeftShift;
|
|
||||||
case kVK_Option: return ImGuiKey_LeftAlt;
|
|
||||||
case kVK_Command: return ImGuiKey_LeftSuper;
|
|
||||||
case kVK_RightControl: return ImGuiKey_RightCtrl;
|
|
||||||
case kVK_RightShift: return ImGuiKey_RightShift;
|
|
||||||
case kVK_RightOption: return ImGuiKey_RightAlt;
|
|
||||||
case kVK_RightCommand: return ImGuiKey_RightSuper;
|
|
||||||
// case kVK_Function: return ImGuiKey_;
|
|
||||||
// case kVK_VolumeUp: return ImGuiKey_;
|
|
||||||
// case kVK_VolumeDown: return ImGuiKey_;
|
|
||||||
// case kVK_Mute: return ImGuiKey_;
|
|
||||||
case kVK_F1: return ImGuiKey_F1;
|
|
||||||
case kVK_F2: return ImGuiKey_F2;
|
|
||||||
case kVK_F3: return ImGuiKey_F3;
|
|
||||||
case kVK_F4: return ImGuiKey_F4;
|
|
||||||
case kVK_F5: return ImGuiKey_F5;
|
|
||||||
case kVK_F6: return ImGuiKey_F6;
|
|
||||||
case kVK_F7: return ImGuiKey_F7;
|
|
||||||
case kVK_F8: return ImGuiKey_F8;
|
|
||||||
case kVK_F9: return ImGuiKey_F9;
|
|
||||||
case kVK_F10: return ImGuiKey_F10;
|
|
||||||
case kVK_F11: return ImGuiKey_F11;
|
|
||||||
case kVK_F12: return ImGuiKey_F12;
|
|
||||||
case kVK_F13: return ImGuiKey_F13;
|
|
||||||
case kVK_F14: return ImGuiKey_F14;
|
|
||||||
case kVK_F15: return ImGuiKey_F15;
|
|
||||||
case kVK_F16: return ImGuiKey_F16;
|
|
||||||
case kVK_F17: return ImGuiKey_F17;
|
|
||||||
case kVK_F18: return ImGuiKey_F18;
|
|
||||||
case kVK_F19: return ImGuiKey_F19;
|
|
||||||
case kVK_F20: return ImGuiKey_F20;
|
|
||||||
case 0x6E: return ImGuiKey_Menu;
|
|
||||||
case kVK_Help: return ImGuiKey_Insert;
|
|
||||||
case kVK_Home: return ImGuiKey_Home;
|
|
||||||
case kVK_PageUp: return ImGuiKey_PageUp;
|
|
||||||
case kVK_ForwardDelete: return ImGuiKey_Delete;
|
|
||||||
case kVK_End: return ImGuiKey_End;
|
|
||||||
case kVK_PageDown: return ImGuiKey_PageDown;
|
|
||||||
case kVK_LeftArrow: return ImGuiKey_LeftArrow;
|
|
||||||
case kVK_RightArrow: return ImGuiKey_RightArrow;
|
|
||||||
case kVK_DownArrow: return ImGuiKey_DownArrow;
|
|
||||||
case kVK_UpArrow: return ImGuiKey_UpArrow;
|
|
||||||
default: return ImGuiKey_None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_METAL_CPP_EXTENSIONS
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplOSX_Init(void* _Nonnull view) {
|
|
||||||
return ImGui_ImplOSX_Init((__bridge NSView*)(view));
|
|
||||||
}
|
|
||||||
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(void* _Nullable view) {
|
|
||||||
return ImGui_ImplOSX_NewFrame((__bridge NSView*)(view));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
bool ImGui_ImplOSX_Init(NSView* view)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_CreateBackendData();
|
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
|
||||||
//io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
|
||||||
io.BackendPlatformName = "imgui_impl_osx";
|
|
||||||
|
|
||||||
bd->Observer = [ImGuiObserver new];
|
|
||||||
|
|
||||||
// Load cursors. Some of them are undocumented.
|
|
||||||
bd->MouseCursorHidden = false;
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = [NSCursor arrowCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = [NSCursor IBeamCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = [NSCursor closedHandCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Hand] = [NSCursor pointingHandCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = [NSCursor operationNotAllowedCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = [NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)] ? [NSCursor _windowResizeNorthSouthCursor] : [NSCursor resizeUpDownCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = [NSCursor respondsToSelector:@selector(_windowResizeEastWestCursor)] ? [NSCursor _windowResizeEastWestCursor] : [NSCursor resizeLeftRightCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = [NSCursor respondsToSelector:@selector(_windowResizeNorthEastSouthWestCursor)] ? [NSCursor _windowResizeNorthEastSouthWestCursor] : [NSCursor closedHandCursor];
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = [NSCursor respondsToSelector:@selector(_windowResizeNorthWestSouthEastCursor)] ? [NSCursor _windowResizeNorthWestSouthEastCursor] : [NSCursor closedHandCursor];
|
|
||||||
|
|
||||||
// Note that imgui.cpp also include default OSX clipboard handlers which can be enabled
|
|
||||||
// by adding '#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS' in imconfig.h and adding '-framework ApplicationServices' to your linker command-line.
|
|
||||||
// Since we are already in ObjC land here, it is easy for us to add a clipboard handler using the NSPasteboard api.
|
|
||||||
io.SetClipboardTextFn = [](void*, const char* str) -> void
|
|
||||||
{
|
|
||||||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
|
||||||
[pasteboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
|
|
||||||
[pasteboard setString:[NSString stringWithUTF8String:str] forType:NSPasteboardTypeString];
|
|
||||||
};
|
|
||||||
|
|
||||||
io.GetClipboardTextFn = [](void*) -> const char*
|
|
||||||
{
|
|
||||||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
|
||||||
NSString* available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:NSPasteboardTypeString]];
|
|
||||||
if (![available isEqualToString:NSPasteboardTypeString])
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
NSString* string = [pasteboard stringForType:NSPasteboardTypeString];
|
|
||||||
if (string == nil)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
const char* string_c = (const char*)[string UTF8String];
|
|
||||||
size_t string_len = strlen(string_c);
|
|
||||||
static ImVector<char> s_clipboard;
|
|
||||||
s_clipboard.resize((int)string_len + 1);
|
|
||||||
strcpy(s_clipboard.Data, string_c);
|
|
||||||
return s_clipboard.Data;
|
|
||||||
};
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:bd->Observer
|
|
||||||
selector:@selector(onApplicationBecomeActive:)
|
|
||||||
name:NSApplicationDidBecomeActiveNotification
|
|
||||||
object:nil];
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:bd->Observer
|
|
||||||
selector:@selector(onApplicationBecomeInactive:)
|
|
||||||
name:NSApplicationDidResignActiveNotification
|
|
||||||
object:nil];
|
|
||||||
|
|
||||||
// Add the NSTextInputClient to the view hierarchy,
|
|
||||||
// to receive keyboard events and translate them to input text.
|
|
||||||
bd->KeyEventResponder = [[KeyEventResponder alloc] initWithFrame:NSZeroRect];
|
|
||||||
bd->InputContext = [[NSTextInputContext alloc] initWithClient:bd->KeyEventResponder];
|
|
||||||
[view addSubview:bd->KeyEventResponder];
|
|
||||||
ImGui_ImplOSX_AddTrackingArea(view);
|
|
||||||
|
|
||||||
io.SetPlatformImeDataFn = [](ImGuiViewport* viewport, ImGuiPlatformImeData* data) -> void
|
|
||||||
{
|
|
||||||
ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData();
|
|
||||||
if (data->WantVisible)
|
|
||||||
{
|
|
||||||
[bd->InputContext activate];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[bd->InputContext discardMarkedText];
|
|
||||||
[bd->InputContext invalidateCharacterCoordinates];
|
|
||||||
[bd->InputContext deactivate];
|
|
||||||
}
|
|
||||||
[bd->KeyEventResponder setImePosX:data->InputPos.x imePosY:data->InputPos.y + data->InputLineHeight];
|
|
||||||
};
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOSX_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
|
||||||
|
|
||||||
bd->Observer = nullptr;
|
|
||||||
if (bd->Monitor != nullptr)
|
|
||||||
{
|
|
||||||
[NSEvent removeMonitor:bd->Monitor];
|
|
||||||
bd->Monitor = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplOSX_DestroyBackendData();
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendPlatformName = nullptr;
|
|
||||||
io.BackendPlatformUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasGamepad);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplOSX_UpdateMouseCursor()
|
|
||||||
{
|
|
||||||
ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
|
||||||
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
|
||||||
{
|
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
|
||||||
if (!bd->MouseCursorHidden)
|
|
||||||
{
|
|
||||||
bd->MouseCursorHidden = true;
|
|
||||||
[NSCursor hide];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSCursor* desired = bd->MouseCursors[imgui_cursor] ?: bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
|
||||||
// -[NSCursor set] generates measureable overhead if called unconditionally.
|
|
||||||
if (desired != NSCursor.currentCursor)
|
|
||||||
{
|
|
||||||
[desired set];
|
|
||||||
}
|
|
||||||
if (bd->MouseCursorHidden)
|
|
||||||
{
|
|
||||||
bd->MouseCursorHidden = false;
|
|
||||||
[NSCursor unhide];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplOSX_UpdateGamepads()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
|
||||||
return;
|
|
||||||
|
|
||||||
#if APPLE_HAS_CONTROLLER
|
|
||||||
GCController* controller = GCController.current;
|
|
||||||
#else
|
|
||||||
GCController* controller = GCController.controllers.firstObject;
|
|
||||||
#endif
|
|
||||||
if (controller == nil || controller.extendedGamepad == nil)
|
|
||||||
{
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GCExtendedGamepad* gp = controller.extendedGamepad;
|
|
||||||
|
|
||||||
// Update gamepad inputs
|
|
||||||
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
|
|
||||||
#define MAP_BUTTON(KEY_NO, BUTTON_NAME) { io.AddKeyEvent(KEY_NO, gp.BUTTON_NAME.isPressed); }
|
|
||||||
#define MAP_ANALOG(KEY_NO, AXIS_NAME, V0, V1) { float vn = (float)(gp.AXIS_NAME.value - V0) / (float)(V1 - V0); vn = IM_SATURATE(vn); io.AddKeyAnalogEvent(KEY_NO, vn > 0.1f, vn); }
|
|
||||||
const float thumb_dead_zone = 0.0f;
|
|
||||||
|
|
||||||
#if APPLE_HAS_BUTTON_OPTIONS
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadBack, buttonOptions);
|
|
||||||
#endif
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, buttonX); // Xbox X, PS Square
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceRight, buttonB); // Xbox B, PS Circle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceUp, buttonY); // Xbox Y, PS Triangle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceDown, buttonA); // Xbox A, PS Cross
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, dpad.left);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadRight, dpad.right);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadUp, dpad.up);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadDown, dpad.down);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadL1, leftShoulder, 0.0f, 1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadR1, rightShoulder, 0.0f, 1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadL2, leftTrigger, 0.0f, 1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadR2, rightTrigger, 0.0f, 1.0f);
|
|
||||||
#if APPLE_HAS_THUMBSTICKS
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadL3, leftThumbstickButton);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadR3, rightThumbstickButton);
|
|
||||||
#endif
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, leftThumbstick.xAxis, -thumb_dead_zone, -1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickRight, leftThumbstick.xAxis, +thumb_dead_zone, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickUp, leftThumbstick.yAxis, +thumb_dead_zone, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickDown, leftThumbstick.yAxis, -thumb_dead_zone, -1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, rightThumbstick.xAxis, -thumb_dead_zone, -1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickRight, rightThumbstick.xAxis, +thumb_dead_zone, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickUp, rightThumbstick.yAxis, +thumb_dead_zone, +1.0f);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickDown, rightThumbstick.yAxis, -thumb_dead_zone, -1.0f);
|
|
||||||
#undef MAP_BUTTON
|
|
||||||
#undef MAP_ANALOG
|
|
||||||
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplOSX_UpdateImePosWithView(NSView* view)
|
|
||||||
{
|
|
||||||
ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (io.WantTextInput)
|
|
||||||
[bd->KeyEventResponder updateImePosWithView:view];
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOSX_NewFrame(NSView* view)
|
|
||||||
{
|
|
||||||
ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// Setup display size
|
|
||||||
if (view)
|
|
||||||
{
|
|
||||||
const float dpi = (float)[view.window backingScaleFactor];
|
|
||||||
io.DisplaySize = ImVec2((float)view.bounds.size.width, (float)view.bounds.size.height);
|
|
||||||
io.DisplayFramebufferScale = ImVec2(dpi, dpi);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup time step
|
|
||||||
if (bd->Time == 0.0)
|
|
||||||
bd->Time = GetMachAbsoluteTimeInSeconds();
|
|
||||||
|
|
||||||
double current_time = GetMachAbsoluteTimeInSeconds();
|
|
||||||
io.DeltaTime = (float)(current_time - bd->Time);
|
|
||||||
bd->Time = current_time;
|
|
||||||
|
|
||||||
ImGui_ImplOSX_UpdateMouseCursor();
|
|
||||||
ImGui_ImplOSX_UpdateGamepads();
|
|
||||||
ImGui_ImplOSX_UpdateImePosWithView(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must only be called for a mouse event, otherwise an exception occurs
|
|
||||||
// (Note that NSEventTypeScrollWheel is considered "other input". Oddly enough an exception does not occur with it, but the value will sometimes be wrong!)
|
|
||||||
static ImGuiMouseSource GetMouseSource(NSEvent* event)
|
|
||||||
{
|
|
||||||
switch (event.subtype)
|
|
||||||
{
|
|
||||||
case NSEventSubtypeTabletPoint:
|
|
||||||
return ImGuiMouseSource_Pen;
|
|
||||||
// macOS considers input from relative touch devices (like the trackpad or Apple Magic Mouse) to be touch input.
|
|
||||||
// This doesn't really make sense for Dear ImGui, which expects absolute touch devices only.
|
|
||||||
// There does not seem to be a simple way to disambiguate things here so we consider NSEventSubtypeTouch events to always come from mice.
|
|
||||||
// See https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html#//apple_ref/doc/uid/10000060i-CH13-SW24
|
|
||||||
//case NSEventSubtypeTouch:
|
|
||||||
// return ImGuiMouseSource_TouchScreen;
|
|
||||||
case NSEventSubtypeMouseEvent:
|
|
||||||
default:
|
|
||||||
return ImGuiMouseSource_Mouse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
if (event.type == NSEventTypeLeftMouseDown || event.type == NSEventTypeRightMouseDown || event.type == NSEventTypeOtherMouseDown)
|
|
||||||
{
|
|
||||||
int button = (int)[event buttonNumber];
|
|
||||||
if (button >= 0 && button < ImGuiMouseButton_COUNT)
|
|
||||||
{
|
|
||||||
io.AddMouseSourceEvent(GetMouseSource(event));
|
|
||||||
io.AddMouseButtonEvent(button, true);
|
|
||||||
}
|
|
||||||
return io.WantCaptureMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == NSEventTypeLeftMouseUp || event.type == NSEventTypeRightMouseUp || event.type == NSEventTypeOtherMouseUp)
|
|
||||||
{
|
|
||||||
int button = (int)[event buttonNumber];
|
|
||||||
if (button >= 0 && button < ImGuiMouseButton_COUNT)
|
|
||||||
{
|
|
||||||
io.AddMouseSourceEvent(GetMouseSource(event));
|
|
||||||
io.AddMouseButtonEvent(button, false);
|
|
||||||
}
|
|
||||||
return io.WantCaptureMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == NSEventTypeMouseMoved || event.type == NSEventTypeLeftMouseDragged || event.type == NSEventTypeRightMouseDragged || event.type == NSEventTypeOtherMouseDragged)
|
|
||||||
{
|
|
||||||
NSPoint mousePoint = event.locationInWindow;
|
|
||||||
if (event.window == nil)
|
|
||||||
mousePoint = [[view window] convertPointFromScreen:mousePoint];
|
|
||||||
mousePoint = [view convertPoint:mousePoint fromView:nil];
|
|
||||||
if ([view isFlipped])
|
|
||||||
mousePoint = NSMakePoint(mousePoint.x, mousePoint.y);
|
|
||||||
else
|
|
||||||
mousePoint = NSMakePoint(mousePoint.x, view.bounds.size.height - mousePoint.y);
|
|
||||||
io.AddMouseSourceEvent(GetMouseSource(event));
|
|
||||||
io.AddMousePosEvent((float)mousePoint.x, (float)mousePoint.y);
|
|
||||||
return io.WantCaptureMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == NSEventTypeScrollWheel)
|
|
||||||
{
|
|
||||||
// Ignore canceled events.
|
|
||||||
//
|
|
||||||
// From macOS 12.1, scrolling with two fingers and then decelerating
|
|
||||||
// by tapping two fingers results in two events appearing:
|
|
||||||
//
|
|
||||||
// 1. A scroll wheel NSEvent, with a phase == NSEventPhaseMayBegin, when the user taps
|
|
||||||
// two fingers to decelerate or stop the scroll events.
|
|
||||||
//
|
|
||||||
// 2. A scroll wheel NSEvent, with a phase == NSEventPhaseCancelled, when the user releases the
|
|
||||||
// two-finger tap. It is this event that sometimes contains large values for scrollingDeltaX and
|
|
||||||
// scrollingDeltaY. When these are added to the current x and y positions of the scrolling view,
|
|
||||||
// it appears to jump up or down. It can be observed in Preview, various JetBrains IDEs and here.
|
|
||||||
if (event.phase == NSEventPhaseCancelled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
double wheel_dx = 0.0;
|
|
||||||
double wheel_dy = 0.0;
|
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
|
||||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
|
||||||
{
|
|
||||||
wheel_dx = [event scrollingDeltaX];
|
|
||||||
wheel_dy = [event scrollingDeltaY];
|
|
||||||
if ([event hasPreciseScrollingDeltas])
|
|
||||||
{
|
|
||||||
wheel_dx *= 0.01;
|
|
||||||
wheel_dy *= 0.01;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif // MAC_OS_X_VERSION_MAX_ALLOWED
|
|
||||||
{
|
|
||||||
wheel_dx = [event deltaX] * 0.1;
|
|
||||||
wheel_dy = [event deltaY] * 0.1;
|
|
||||||
}
|
|
||||||
if (wheel_dx != 0.0 || wheel_dy != 0.0)
|
|
||||||
io.AddMouseWheelEvent((float)wheel_dx, (float)wheel_dy);
|
|
||||||
|
|
||||||
return io.WantCaptureMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == NSEventTypeKeyDown || event.type == NSEventTypeKeyUp)
|
|
||||||
{
|
|
||||||
if ([event isARepeat])
|
|
||||||
return io.WantCaptureKeyboard;
|
|
||||||
|
|
||||||
int key_code = (int)[event keyCode];
|
|
||||||
ImGuiKey key = ImGui_ImplOSX_KeyCodeToImGuiKey(key_code);
|
|
||||||
io.AddKeyEvent(key, event.type == NSEventTypeKeyDown);
|
|
||||||
io.SetKeyEventNativeData(key, key_code, -1); // To support legacy indexing (<1.87 user code)
|
|
||||||
|
|
||||||
return io.WantCaptureKeyboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == NSEventTypeFlagsChanged)
|
|
||||||
{
|
|
||||||
unsigned short key_code = [event keyCode];
|
|
||||||
NSEventModifierFlags modifier_flags = [event modifierFlags];
|
|
||||||
|
|
||||||
io.AddKeyEvent(ImGuiMod_Shift, (modifier_flags & NSEventModifierFlagShift) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Ctrl, (modifier_flags & NSEventModifierFlagControl) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Alt, (modifier_flags & NSEventModifierFlagOption) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Super, (modifier_flags & NSEventModifierFlagCommand) != 0);
|
|
||||||
|
|
||||||
ImGuiKey key = ImGui_ImplOSX_KeyCodeToImGuiKey(key_code);
|
|
||||||
if (key != ImGuiKey_None)
|
|
||||||
{
|
|
||||||
// macOS does not generate down/up event for modifiers. We're trying
|
|
||||||
// to use hardware dependent masks to extract that information.
|
|
||||||
// 'imgui_mask' is left as a fallback.
|
|
||||||
NSEventModifierFlags mask = 0;
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case ImGuiKey_LeftCtrl: mask = 0x0001; break;
|
|
||||||
case ImGuiKey_RightCtrl: mask = 0x2000; break;
|
|
||||||
case ImGuiKey_LeftShift: mask = 0x0002; break;
|
|
||||||
case ImGuiKey_RightShift: mask = 0x0004; break;
|
|
||||||
case ImGuiKey_LeftSuper: mask = 0x0008; break;
|
|
||||||
case ImGuiKey_RightSuper: mask = 0x0010; break;
|
|
||||||
case ImGuiKey_LeftAlt: mask = 0x0020; break;
|
|
||||||
case ImGuiKey_RightAlt: mask = 0x0040; break;
|
|
||||||
default:
|
|
||||||
return io.WantCaptureKeyboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSEventModifierFlags modifier_flags = [event modifierFlags];
|
|
||||||
io.AddKeyEvent(key, (modifier_flags & mask) != 0);
|
|
||||||
io.SetKeyEventNativeData(key, key_code, -1); // To support legacy indexing (<1.87 user code)
|
|
||||||
}
|
|
||||||
|
|
||||||
return io.WantCaptureKeyboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplOSX_AddTrackingArea(NSView* _Nonnull view)
|
|
||||||
{
|
|
||||||
// If we want to receive key events, we either need to be in the responder chain of the key view,
|
|
||||||
// or else we can install a local monitor. The consequence of this heavy-handed approach is that
|
|
||||||
// we receive events for all controls, not just Dear ImGui widgets. If we had native controls in our
|
|
||||||
// window, we'd want to be much more careful than just ingesting the complete event stream.
|
|
||||||
// To match the behavior of other backends, we pass every event down to the OS.
|
|
||||||
ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData();
|
|
||||||
if (bd->Monitor)
|
|
||||||
return;
|
|
||||||
NSEventMask eventMask = 0;
|
|
||||||
eventMask |= NSEventMaskMouseMoved | NSEventMaskScrollWheel;
|
|
||||||
eventMask |= NSEventMaskLeftMouseDown | NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged;
|
|
||||||
eventMask |= NSEventMaskRightMouseDown | NSEventMaskRightMouseUp | NSEventMaskRightMouseDragged;
|
|
||||||
eventMask |= NSEventMaskOtherMouseDown | NSEventMaskOtherMouseUp | NSEventMaskOtherMouseDragged;
|
|
||||||
eventMask |= NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged;
|
|
||||||
bd->Monitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask
|
|
||||||
handler:^NSEvent* _Nullable(NSEvent* event)
|
|
||||||
{
|
|
||||||
ImGui_ImplOSX_HandleEvent(event, view);
|
|
||||||
return event;
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,674 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for SDL2
|
|
||||||
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
|
|
||||||
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
|
||||||
// (Prefer SDL 2.0.5+ for full feature support.)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Clipboard support.
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
|
||||||
// [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 SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// [X] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
|
||||||
// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306)
|
|
||||||
// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702)
|
|
||||||
// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644)
|
|
||||||
// 2023-02-07: Implement IME handler (io.SetPlatformImeDataFn will call SDL_SetTextInputRect()/SDL_StartTextInput()).
|
|
||||||
// 2023-02-07: *BREAKING CHANGE* Renamed this backend file from imgui_impl_sdl.cpp/.h to imgui_impl_sdl2.cpp/.h in prevision for the future release of SDL3.
|
|
||||||
// 2023-02-02: Avoid calling SDL_SetCursor() when cursor has not changed, as the function is surprisingly costly on Mac with latest SDL (may be fixed in next SDL version).
|
|
||||||
// 2023-02-02: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data for smooth scrolling + Scaling X value on Emscripten (bug?). (#4019, #6096)
|
|
||||||
// 2023-02-02: Removed SDL_MOUSEWHEEL value clamping, as values seem correct in latest Emscripten. (#4019)
|
|
||||||
// 2023-02-01: Flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463)
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 2022-09-26: Inputs: Disable SDL 2.0.22 new "auto capture" (SDL_HINT_MOUSE_AUTO_CAPTURE) which prevents drag and drop across windows for multi-viewport support + don't capture when drag and dropping. (#5710)
|
|
||||||
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
|
|
||||||
// 2022-03-22: Inputs: Fix mouse position issues when dragging outside of boundaries. SDL_CaptureMouse() erroneously still gives out LEAVE events when hovering OS decorations.
|
|
||||||
// 2022-03-22: Inputs: Added support for extra mouse buttons (SDL_BUTTON_X1/SDL_BUTTON_X2).
|
|
||||||
// 2022-02-04: Added SDL_Renderer* parameter to ImGui_ImplSDL2_InitForSDLRenderer(), so we can use SDL_GetRendererOutputSize() instead of SDL_GL_GetDrawableSize() when bound to a SDL_Renderer.
|
|
||||||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
|
||||||
// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
|
|
||||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
|
||||||
// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
|
|
||||||
// 2022-01-12: Update mouse inputs using SDL_MOUSEMOTION/SDL_WINDOWEVENT_LEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
|
|
||||||
// 2022-01-12: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
|
|
||||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
|
||||||
// 2021-08-17: Calling io.AddFocusEvent() on SDL_WINDOWEVENT_FOCUS_GAINED/SDL_WINDOWEVENT_FOCUS_LOST.
|
|
||||||
// 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using SDL_GetMouseFocus() + SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, requires SDL 2.0.5+)
|
|
||||||
// 2021-06-29: *BREAKING CHANGE* Removed 'SDL_Window* window' parameter to ImGui_ImplSDL2_NewFrame() which was unnecessary.
|
|
||||||
// 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-03-22: Rework global mouse pos availability check listing supported platforms explicitly, effectively fixing mouse access on Raspberry Pi. (#2837, #3950)
|
|
||||||
// 2020-05-25: Misc: Report a zero display-size when window is minimized, to be consistent with other backends.
|
|
||||||
// 2020-02-20: Inputs: Fixed mapping for ImGuiKey_KeyPadEnter (using SDL_SCANCODE_KP_ENTER instead of SDL_SCANCODE_RETURN2).
|
|
||||||
// 2019-12-17: Inputs: On Wayland, use SDL_GetMouseState (because there is no global mouse state).
|
|
||||||
// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor.
|
|
||||||
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
|
|
||||||
// 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
|
|
||||||
// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
|
|
||||||
// 2018-12-21: Inputs: Workaround for Android/iOS which don't seem to handle focus related calls.
|
|
||||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
|
||||||
// 2018-11-14: Changed the signature of ImGui_ImplSDL2_ProcessEvent() to take a 'const SDL_Event*'.
|
|
||||||
// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
|
|
||||||
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
|
|
||||||
// 2018-06-08: Misc: Extracted imgui_impl_sdl.cpp/.h away from the old combined SDL2+OpenGL/Vulkan examples.
|
|
||||||
// 2018-06-08: Misc: ImGui_ImplSDL2_InitForOpenGL() now takes a SDL_GLContext parameter.
|
|
||||||
// 2018-05-09: Misc: Fixed clipboard paste memory leak (we didn't call SDL_FreeMemory on the data returned by SDL_GetClipboardText).
|
|
||||||
// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
|
|
||||||
// 2018-02-16: Inputs: Added support for mouse cursors, honoring ImGui::GetMouseCursor() value.
|
|
||||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
|
||||||
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
|
|
||||||
// 2018-02-05: Misc: Using SDL_GetPerformanceCounter() instead of SDL_GetTicks() to be able to handle very high framerate (1000+ FPS).
|
|
||||||
// 2018-02-05: Inputs: Keyboard mapping is using scancodes everywhere instead of a confusing mixture of keycodes and scancodes.
|
|
||||||
// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
|
|
||||||
// 2018-01-19: Inputs: When available (SDL 2.0.4+) using SDL_CaptureMouse() to retrieve coordinates outside of client area when dragging. Otherwise (SDL 2.0.3 and before) testing for SDL_WINDOW_INPUT_FOCUS instead of SDL_WINDOW_MOUSE_FOCUS.
|
|
||||||
// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
|
|
||||||
// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
|
|
||||||
// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_sdl2.h"
|
|
||||||
|
|
||||||
// Clang warnings with -Weverything
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SDL
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <SDL_syswm.h>
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#include <TargetConditionals.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
|
|
||||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
|
|
||||||
#else
|
|
||||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
|
||||||
#endif
|
|
||||||
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
|
|
||||||
|
|
||||||
// SDL Data
|
|
||||||
struct ImGui_ImplSDL2_Data
|
|
||||||
{
|
|
||||||
SDL_Window* Window;
|
|
||||||
SDL_Renderer* Renderer;
|
|
||||||
Uint64 Time;
|
|
||||||
Uint32 MouseWindowID;
|
|
||||||
int MouseButtonsDown;
|
|
||||||
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
|
||||||
SDL_Cursor* LastMouseCursor;
|
|
||||||
int PendingMouseLeaveFrame;
|
|
||||||
char* ClipboardTextData;
|
|
||||||
bool MouseCanUseGlobalState;
|
|
||||||
|
|
||||||
ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
|
||||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
||||||
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
|
||||||
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
|
||||||
static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static const char* ImGui_ImplSDL2_GetClipboardText(void*)
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
|
||||||
if (bd->ClipboardTextData)
|
|
||||||
SDL_free(bd->ClipboardTextData);
|
|
||||||
bd->ClipboardTextData = SDL_GetClipboardText();
|
|
||||||
return bd->ClipboardTextData;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text)
|
|
||||||
{
|
|
||||||
SDL_SetClipboardText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: native IME will only display if user calls SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1") _before_ SDL_CreateWindow().
|
|
||||||
static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeData* data)
|
|
||||||
{
|
|
||||||
if (data->WantVisible)
|
|
||||||
{
|
|
||||||
SDL_Rect r;
|
|
||||||
r.x = (int)data->InputPos.x;
|
|
||||||
r.y = (int)data->InputPos.y;
|
|
||||||
r.w = 1;
|
|
||||||
r.h = (int)data->InputLineHeight;
|
|
||||||
SDL_SetTextInputRect(&r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
|
|
||||||
{
|
|
||||||
switch (keycode)
|
|
||||||
{
|
|
||||||
case SDLK_TAB: return ImGuiKey_Tab;
|
|
||||||
case SDLK_LEFT: return ImGuiKey_LeftArrow;
|
|
||||||
case SDLK_RIGHT: return ImGuiKey_RightArrow;
|
|
||||||
case SDLK_UP: return ImGuiKey_UpArrow;
|
|
||||||
case SDLK_DOWN: return ImGuiKey_DownArrow;
|
|
||||||
case SDLK_PAGEUP: return ImGuiKey_PageUp;
|
|
||||||
case SDLK_PAGEDOWN: return ImGuiKey_PageDown;
|
|
||||||
case SDLK_HOME: return ImGuiKey_Home;
|
|
||||||
case SDLK_END: return ImGuiKey_End;
|
|
||||||
case SDLK_INSERT: return ImGuiKey_Insert;
|
|
||||||
case SDLK_DELETE: return ImGuiKey_Delete;
|
|
||||||
case SDLK_BACKSPACE: return ImGuiKey_Backspace;
|
|
||||||
case SDLK_SPACE: return ImGuiKey_Space;
|
|
||||||
case SDLK_RETURN: return ImGuiKey_Enter;
|
|
||||||
case SDLK_ESCAPE: return ImGuiKey_Escape;
|
|
||||||
case SDLK_QUOTE: return ImGuiKey_Apostrophe;
|
|
||||||
case SDLK_COMMA: return ImGuiKey_Comma;
|
|
||||||
case SDLK_MINUS: return ImGuiKey_Minus;
|
|
||||||
case SDLK_PERIOD: return ImGuiKey_Period;
|
|
||||||
case SDLK_SLASH: return ImGuiKey_Slash;
|
|
||||||
case SDLK_SEMICOLON: return ImGuiKey_Semicolon;
|
|
||||||
case SDLK_EQUALS: return ImGuiKey_Equal;
|
|
||||||
case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
|
||||||
case SDLK_BACKSLASH: return ImGuiKey_Backslash;
|
|
||||||
case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
|
||||||
case SDLK_BACKQUOTE: return ImGuiKey_GraveAccent;
|
|
||||||
case SDLK_CAPSLOCK: return ImGuiKey_CapsLock;
|
|
||||||
case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock;
|
|
||||||
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
|
|
||||||
case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
|
|
||||||
case SDLK_PAUSE: return ImGuiKey_Pause;
|
|
||||||
case SDLK_KP_0: return ImGuiKey_Keypad0;
|
|
||||||
case SDLK_KP_1: return ImGuiKey_Keypad1;
|
|
||||||
case SDLK_KP_2: return ImGuiKey_Keypad2;
|
|
||||||
case SDLK_KP_3: return ImGuiKey_Keypad3;
|
|
||||||
case SDLK_KP_4: return ImGuiKey_Keypad4;
|
|
||||||
case SDLK_KP_5: return ImGuiKey_Keypad5;
|
|
||||||
case SDLK_KP_6: return ImGuiKey_Keypad6;
|
|
||||||
case SDLK_KP_7: return ImGuiKey_Keypad7;
|
|
||||||
case SDLK_KP_8: return ImGuiKey_Keypad8;
|
|
||||||
case SDLK_KP_9: return ImGuiKey_Keypad9;
|
|
||||||
case SDLK_KP_PERIOD: return ImGuiKey_KeypadDecimal;
|
|
||||||
case SDLK_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
|
||||||
case SDLK_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
|
||||||
case SDLK_KP_MINUS: return ImGuiKey_KeypadSubtract;
|
|
||||||
case SDLK_KP_PLUS: return ImGuiKey_KeypadAdd;
|
|
||||||
case SDLK_KP_ENTER: return ImGuiKey_KeypadEnter;
|
|
||||||
case SDLK_KP_EQUALS: return ImGuiKey_KeypadEqual;
|
|
||||||
case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
|
|
||||||
case SDLK_LSHIFT: return ImGuiKey_LeftShift;
|
|
||||||
case SDLK_LALT: return ImGuiKey_LeftAlt;
|
|
||||||
case SDLK_LGUI: return ImGuiKey_LeftSuper;
|
|
||||||
case SDLK_RCTRL: return ImGuiKey_RightCtrl;
|
|
||||||
case SDLK_RSHIFT: return ImGuiKey_RightShift;
|
|
||||||
case SDLK_RALT: return ImGuiKey_RightAlt;
|
|
||||||
case SDLK_RGUI: return ImGuiKey_RightSuper;
|
|
||||||
case SDLK_APPLICATION: return ImGuiKey_Menu;
|
|
||||||
case SDLK_0: return ImGuiKey_0;
|
|
||||||
case SDLK_1: return ImGuiKey_1;
|
|
||||||
case SDLK_2: return ImGuiKey_2;
|
|
||||||
case SDLK_3: return ImGuiKey_3;
|
|
||||||
case SDLK_4: return ImGuiKey_4;
|
|
||||||
case SDLK_5: return ImGuiKey_5;
|
|
||||||
case SDLK_6: return ImGuiKey_6;
|
|
||||||
case SDLK_7: return ImGuiKey_7;
|
|
||||||
case SDLK_8: return ImGuiKey_8;
|
|
||||||
case SDLK_9: return ImGuiKey_9;
|
|
||||||
case SDLK_a: return ImGuiKey_A;
|
|
||||||
case SDLK_b: return ImGuiKey_B;
|
|
||||||
case SDLK_c: return ImGuiKey_C;
|
|
||||||
case SDLK_d: return ImGuiKey_D;
|
|
||||||
case SDLK_e: return ImGuiKey_E;
|
|
||||||
case SDLK_f: return ImGuiKey_F;
|
|
||||||
case SDLK_g: return ImGuiKey_G;
|
|
||||||
case SDLK_h: return ImGuiKey_H;
|
|
||||||
case SDLK_i: return ImGuiKey_I;
|
|
||||||
case SDLK_j: return ImGuiKey_J;
|
|
||||||
case SDLK_k: return ImGuiKey_K;
|
|
||||||
case SDLK_l: return ImGuiKey_L;
|
|
||||||
case SDLK_m: return ImGuiKey_M;
|
|
||||||
case SDLK_n: return ImGuiKey_N;
|
|
||||||
case SDLK_o: return ImGuiKey_O;
|
|
||||||
case SDLK_p: return ImGuiKey_P;
|
|
||||||
case SDLK_q: return ImGuiKey_Q;
|
|
||||||
case SDLK_r: return ImGuiKey_R;
|
|
||||||
case SDLK_s: return ImGuiKey_S;
|
|
||||||
case SDLK_t: return ImGuiKey_T;
|
|
||||||
case SDLK_u: return ImGuiKey_U;
|
|
||||||
case SDLK_v: return ImGuiKey_V;
|
|
||||||
case SDLK_w: return ImGuiKey_W;
|
|
||||||
case SDLK_x: return ImGuiKey_X;
|
|
||||||
case SDLK_y: return ImGuiKey_Y;
|
|
||||||
case SDLK_z: return ImGuiKey_Z;
|
|
||||||
case SDLK_F1: return ImGuiKey_F1;
|
|
||||||
case SDLK_F2: return ImGuiKey_F2;
|
|
||||||
case SDLK_F3: return ImGuiKey_F3;
|
|
||||||
case SDLK_F4: return ImGuiKey_F4;
|
|
||||||
case SDLK_F5: return ImGuiKey_F5;
|
|
||||||
case SDLK_F6: return ImGuiKey_F6;
|
|
||||||
case SDLK_F7: return ImGuiKey_F7;
|
|
||||||
case SDLK_F8: return ImGuiKey_F8;
|
|
||||||
case SDLK_F9: return ImGuiKey_F9;
|
|
||||||
case SDLK_F10: return ImGuiKey_F10;
|
|
||||||
case SDLK_F11: return ImGuiKey_F11;
|
|
||||||
case SDLK_F12: return ImGuiKey_F12;
|
|
||||||
case SDLK_F13: return ImGuiKey_F13;
|
|
||||||
case SDLK_F14: return ImGuiKey_F14;
|
|
||||||
case SDLK_F15: return ImGuiKey_F15;
|
|
||||||
case SDLK_F16: return ImGuiKey_F16;
|
|
||||||
case SDLK_F17: return ImGuiKey_F17;
|
|
||||||
case SDLK_F18: return ImGuiKey_F18;
|
|
||||||
case SDLK_F19: return ImGuiKey_F19;
|
|
||||||
case SDLK_F20: return ImGuiKey_F20;
|
|
||||||
case SDLK_F21: return ImGuiKey_F21;
|
|
||||||
case SDLK_F22: return ImGuiKey_F22;
|
|
||||||
case SDLK_F23: return ImGuiKey_F23;
|
|
||||||
case SDLK_F24: return ImGuiKey_F24;
|
|
||||||
case SDLK_AC_BACK: return ImGuiKey_AppBack;
|
|
||||||
case SDLK_AC_FORWARD: return ImGuiKey_AppForward;
|
|
||||||
}
|
|
||||||
return ImGuiKey_None;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & KMOD_CTRL) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & KMOD_SHIFT) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & KMOD_ALT) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & KMOD_GUI) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
||||||
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
|
||||||
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
|
||||||
|
|
||||||
switch (event->type)
|
|
||||||
{
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
{
|
|
||||||
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
|
||||||
io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
|
||||||
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_MOUSEWHEEL:
|
|
||||||
{
|
|
||||||
//IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
|
|
||||||
#if SDL_VERSION_ATLEAST(2,0,18) // If this fails to compile on Emscripten: update to latest Emscripten!
|
|
||||||
float wheel_x = -event->wheel.preciseX;
|
|
||||||
float wheel_y = event->wheel.preciseY;
|
|
||||||
#else
|
|
||||||
float wheel_x = -(float)event->wheel.x;
|
|
||||||
float wheel_y = (float)event->wheel.y;
|
|
||||||
#endif
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
wheel_x /= 100.0f;
|
|
||||||
#endif
|
|
||||||
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
|
||||||
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
{
|
|
||||||
int mouse_button = -1;
|
|
||||||
if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
|
|
||||||
if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; }
|
|
||||||
if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; }
|
|
||||||
if (event->button.button == SDL_BUTTON_X1) { mouse_button = 3; }
|
|
||||||
if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; }
|
|
||||||
if (mouse_button == -1)
|
|
||||||
break;
|
|
||||||
io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
|
||||||
io.AddMouseButtonEvent(mouse_button, (event->type == SDL_MOUSEBUTTONDOWN));
|
|
||||||
bd->MouseButtonsDown = (event->type == SDL_MOUSEBUTTONDOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_TEXTINPUT:
|
|
||||||
{
|
|
||||||
io.AddInputCharactersUTF8(event->text.text);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
case SDL_KEYUP:
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL2_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
|
|
||||||
ImGuiKey key = ImGui_ImplSDL2_KeycodeToImGuiKey(event->key.keysym.sym);
|
|
||||||
io.AddKeyEvent(key, (event->type == SDL_KEYDOWN));
|
|
||||||
io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
{
|
|
||||||
// - When capturing mouse, SDL will send a bunch of conflicting LEAVE/ENTER event on every mouse move, but the final ENTER tends to be right.
|
|
||||||
// - However we won't get a correct LEAVE event for a captured window.
|
|
||||||
// - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
|
|
||||||
// causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why
|
|
||||||
// we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details.
|
|
||||||
Uint8 window_event = event->window.event;
|
|
||||||
if (window_event == SDL_WINDOWEVENT_ENTER)
|
|
||||||
{
|
|
||||||
bd->MouseWindowID = event->window.windowID;
|
|
||||||
bd->PendingMouseLeaveFrame = 0;
|
|
||||||
}
|
|
||||||
if (window_event == SDL_WINDOWEVENT_LEAVE)
|
|
||||||
bd->PendingMouseLeaveFrame = ImGui::GetFrameCount() + 1;
|
|
||||||
if (window_event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
|
||||||
io.AddFocusEvent(true);
|
|
||||||
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
|
||||||
io.AddFocusEvent(false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
|
||||||
|
|
||||||
// Check and store if we are on a SDL backend that supports global mouse position
|
|
||||||
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
|
||||||
bool mouse_can_use_global_state = false;
|
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
|
||||||
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
|
||||||
const char* global_mouse_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
|
||||||
for (int n = 0; n < IM_ARRAYSIZE(global_mouse_whitelist); n++)
|
|
||||||
if (strncmp(sdl_backend, global_mouse_whitelist[n], strlen(global_mouse_whitelist[n])) == 0)
|
|
||||||
mouse_can_use_global_state = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplSDL2_Data* bd = IM_NEW(ImGui_ImplSDL2_Data)();
|
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
|
||||||
io.BackendPlatformName = "imgui_impl_sdl2";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
|
||||||
|
|
||||||
bd->Window = window;
|
|
||||||
bd->Renderer = renderer;
|
|
||||||
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
|
|
||||||
|
|
||||||
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
|
|
||||||
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
|
|
||||||
io.ClipboardUserData = nullptr;
|
|
||||||
io.SetPlatformImeDataFn = ImGui_ImplSDL2_SetPlatformImeData;
|
|
||||||
|
|
||||||
// Load mouse cursors
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
|
|
||||||
|
|
||||||
// Set platform dependent data in viewport
|
|
||||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
|
||||||
main_viewport->PlatformHandleRaw = nullptr;
|
|
||||||
SDL_SysWMinfo info;
|
|
||||||
SDL_VERSION(&info.version);
|
|
||||||
if (SDL_GetWindowWMInfo(window, &info))
|
|
||||||
{
|
|
||||||
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
|
|
||||||
main_viewport->PlatformHandleRaw = (void*)info.info.win.window;
|
|
||||||
#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
|
|
||||||
main_viewport->PlatformHandleRaw = (void*)info.info.cocoa.window;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
|
|
||||||
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
|
|
||||||
// (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
|
|
||||||
// It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
|
|
||||||
// you can ignore SDL_MOUSEBUTTONDOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED)
|
|
||||||
#ifdef SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
|
|
||||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
|
||||||
// IMPORTANT: This is used at the time of SDL_CreateWindow() so this will only affects secondary windows, if any.
|
|
||||||
// For the main window to be affected, your application needs to call this manually before calling SDL_CreateWindow().
|
|
||||||
#ifdef SDL_HINT_IME_SHOW_UI
|
|
||||||
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710)
|
|
||||||
#ifdef SDL_HINT_MOUSE_AUTO_CAPTURE
|
|
||||||
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
|
|
||||||
{
|
|
||||||
IM_UNUSED(sdl_gl_context); // Viewport branch will need this.
|
|
||||||
return ImGui_ImplSDL2_Init(window, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
|
|
||||||
{
|
|
||||||
#if !SDL_HAS_VULKAN
|
|
||||||
IM_ASSERT(0 && "Unsupported");
|
|
||||||
#endif
|
|
||||||
return ImGui_ImplSDL2_Init(window, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
|
|
||||||
{
|
|
||||||
#if !defined(_WIN32)
|
|
||||||
IM_ASSERT(0 && "Unsupported");
|
|
||||||
#endif
|
|
||||||
return ImGui_ImplSDL2_Init(window, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window)
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDL2_Init(window, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDL2_Init(window, renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL2_InitForOther(SDL_Window* window)
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDL2_Init(window, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDL2_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
if (bd->ClipboardTextData)
|
|
||||||
SDL_free(bd->ClipboardTextData);
|
|
||||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
|
||||||
SDL_FreeCursor(bd->MouseCursors[cursor_n]);
|
|
||||||
bd->LastMouseCursor = nullptr;
|
|
||||||
|
|
||||||
io.BackendPlatformName = nullptr;
|
|
||||||
io.BackendPlatformUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_UpdateMouseData()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below)
|
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
|
||||||
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside
|
|
||||||
SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE);
|
|
||||||
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
|
||||||
const bool is_app_focused = (bd->Window == focused_window);
|
|
||||||
#else
|
|
||||||
const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only
|
|
||||||
#endif
|
|
||||||
if (is_app_focused)
|
|
||||||
{
|
|
||||||
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
|
||||||
if (io.WantSetMousePos)
|
|
||||||
SDL_WarpMouseInWindow(bd->Window, (int)io.MousePos.x, (int)io.MousePos.y);
|
|
||||||
|
|
||||||
// (Optional) Fallback to provide mouse position when focused (SDL_MOUSEMOTION already provides this when hovered or captured)
|
|
||||||
if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0)
|
|
||||||
{
|
|
||||||
int window_x, window_y, mouse_x_global, mouse_y_global;
|
|
||||||
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
|
|
||||||
SDL_GetWindowPosition(bd->Window, &window_x, &window_y);
|
|
||||||
io.AddMousePosEvent((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_UpdateMouseCursor()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
|
||||||
return;
|
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
|
||||||
|
|
||||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
|
||||||
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
|
||||||
{
|
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
|
||||||
SDL_ShowCursor(SDL_FALSE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Show OS mouse cursor
|
|
||||||
SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
|
||||||
if (bd->LastMouseCursor != expected_cursor)
|
|
||||||
{
|
|
||||||
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
|
||||||
bd->LastMouseCursor = expected_cursor;
|
|
||||||
}
|
|
||||||
SDL_ShowCursor(SDL_TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_UpdateGamepads()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Get gamepad
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
|
||||||
SDL_GameController* game_controller = SDL_GameControllerOpen(0);
|
|
||||||
if (!game_controller)
|
|
||||||
return;
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
|
||||||
|
|
||||||
// Update gamepad inputs
|
|
||||||
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
|
|
||||||
#define MAP_BUTTON(KEY_NO, BUTTON_NO) { io.AddKeyEvent(KEY_NO, SDL_GameControllerGetButton(game_controller, BUTTON_NO) != 0); }
|
|
||||||
#define MAP_ANALOG(KEY_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GameControllerGetAxis(game_controller, AXIS_NO) - V0) / (float)(V1 - V0); vn = IM_SATURATE(vn); io.AddKeyAnalogEvent(KEY_NO, vn > 0.1f, vn); }
|
|
||||||
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadStart, SDL_CONTROLLER_BUTTON_START);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadBack, SDL_CONTROLLER_BUTTON_BACK);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, SDL_CONTROLLER_BUTTON_X); // Xbox X, PS Square
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceRight, SDL_CONTROLLER_BUTTON_B); // Xbox B, PS Circle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceUp, SDL_CONTROLLER_BUTTON_Y); // Xbox Y, PS Triangle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceDown, SDL_CONTROLLER_BUTTON_A); // Xbox A, PS Cross
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadL1, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadR1, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadL2, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 0.0f, 32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadR2, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 0.0f, 32767);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadL3, SDL_CONTROLLER_BUTTON_LEFTSTICK);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadR3, SDL_CONTROLLER_BUTTON_RIGHTSTICK);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, SDL_CONTROLLER_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickRight, SDL_CONTROLLER_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickUp, SDL_CONTROLLER_AXIS_RIGHTY, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickDown, SDL_CONTROLLER_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
|
||||||
#undef MAP_BUTTON
|
|
||||||
#undef MAP_ANALOG
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDL2_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDL2_Init()?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
|
||||||
int w, h;
|
|
||||||
int display_w, display_h;
|
|
||||||
SDL_GetWindowSize(bd->Window, &w, &h);
|
|
||||||
if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_MINIMIZED)
|
|
||||||
w = h = 0;
|
|
||||||
if (bd->Renderer != nullptr)
|
|
||||||
SDL_GetRendererOutputSize(bd->Renderer, &display_w, &display_h);
|
|
||||||
else
|
|
||||||
SDL_GL_GetDrawableSize(bd->Window, &display_w, &display_h);
|
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
|
||||||
if (w > 0 && h > 0)
|
|
||||||
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
|
||||||
|
|
||||||
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
|
|
||||||
// (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)
|
|
||||||
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
|
||||||
Uint64 current_time = SDL_GetPerformanceCounter();
|
|
||||||
if (current_time <= bd->Time)
|
|
||||||
current_time = bd->Time + 1;
|
|
||||||
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
|
||||||
bd->Time = current_time;
|
|
||||||
|
|
||||||
if (bd->PendingMouseLeaveFrame && bd->PendingMouseLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
|
||||||
{
|
|
||||||
bd->MouseWindowID = 0;
|
|
||||||
bd->PendingMouseLeaveFrame = 0;
|
|
||||||
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplSDL2_UpdateMouseData();
|
|
||||||
ImGui_ImplSDL2_UpdateMouseCursor();
|
|
||||||
|
|
||||||
// Update game controllers (if enabled and available)
|
|
||||||
ImGui_ImplSDL2_UpdateGamepads();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,43 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for SDL2
|
|
||||||
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
|
|
||||||
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Clipboard support.
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
|
||||||
// [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 SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// [X] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
|
||||||
|
|
||||||
// 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 SDL_Window;
|
|
||||||
struct SDL_Renderer;
|
|
||||||
typedef union SDL_Event SDL_Event;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOther(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
|
|
||||||
|
|
||||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
|
||||||
static inline void ImGui_ImplSDL2_NewFrame(SDL_Window*) { ImGui_ImplSDL2_NewFrame(); } // 1.84: removed unnecessary parameter
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,618 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for SDL3 (*EXPERIMENTAL*)
|
|
||||||
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
|
|
||||||
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
|
||||||
// (IMPORTANT: SDL 3.0.0 is NOT YET RELEASED. IT IS POSSIBLE THAT ITS SPECS/API WILL CHANGE BEFORE RELEASE)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Clipboard support.
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
|
||||||
// [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 SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// Missing features:
|
|
||||||
// [x] Platform: Basic IME support. Position somehow broken in SDL3 + app needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// 2023-11-13: Updated for recent SDL3 API changes.
|
|
||||||
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
|
||||||
// 2023-05-04: Fixed build on Emscripten/iOS/Android. (#6391)
|
|
||||||
// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306)
|
|
||||||
// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702)
|
|
||||||
// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644)
|
|
||||||
// 2023-02-07: Forked "imgui_impl_sdl2" into "imgui_impl_sdl3". Removed version checks for old feature. Refer to imgui_impl_sdl2.cpp for older changelog.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_sdl3.h"
|
|
||||||
|
|
||||||
// Clang warnings with -Weverything
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SDL
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#include <TargetConditionals.h>
|
|
||||||
#endif
|
|
||||||
#ifdef _WIN32
|
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#endif
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
|
|
||||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
|
|
||||||
#else
|
|
||||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SDL Data
|
|
||||||
struct ImGui_ImplSDL3_Data
|
|
||||||
{
|
|
||||||
SDL_Window* Window;
|
|
||||||
SDL_Renderer* Renderer;
|
|
||||||
Uint64 Time;
|
|
||||||
Uint32 MouseWindowID;
|
|
||||||
int MouseButtonsDown;
|
|
||||||
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
|
||||||
SDL_Cursor* LastMouseCursor;
|
|
||||||
int PendingMouseLeaveFrame;
|
|
||||||
char* ClipboardTextData;
|
|
||||||
bool MouseCanUseGlobalState;
|
|
||||||
|
|
||||||
ImGui_ImplSDL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
|
||||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
||||||
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
|
||||||
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
|
||||||
static ImGui_ImplSDL3_Data* ImGui_ImplSDL3_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL3_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
static const char* ImGui_ImplSDL3_GetClipboardText(void*)
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
|
||||||
if (bd->ClipboardTextData)
|
|
||||||
SDL_free(bd->ClipboardTextData);
|
|
||||||
bd->ClipboardTextData = SDL_GetClipboardText();
|
|
||||||
return bd->ClipboardTextData;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_SetClipboardText(void*, const char* text)
|
|
||||||
{
|
|
||||||
SDL_SetClipboardText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeData* data)
|
|
||||||
{
|
|
||||||
if (data->WantVisible)
|
|
||||||
{
|
|
||||||
SDL_Rect r;
|
|
||||||
r.x = (int)data->InputPos.x;
|
|
||||||
r.y = (int)data->InputPos.y;
|
|
||||||
r.w = 1;
|
|
||||||
r.h = (int)data->InputLineHeight;
|
|
||||||
SDL_SetTextInputRect(&r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode)
|
|
||||||
{
|
|
||||||
switch (keycode)
|
|
||||||
{
|
|
||||||
case SDLK_TAB: return ImGuiKey_Tab;
|
|
||||||
case SDLK_LEFT: return ImGuiKey_LeftArrow;
|
|
||||||
case SDLK_RIGHT: return ImGuiKey_RightArrow;
|
|
||||||
case SDLK_UP: return ImGuiKey_UpArrow;
|
|
||||||
case SDLK_DOWN: return ImGuiKey_DownArrow;
|
|
||||||
case SDLK_PAGEUP: return ImGuiKey_PageUp;
|
|
||||||
case SDLK_PAGEDOWN: return ImGuiKey_PageDown;
|
|
||||||
case SDLK_HOME: return ImGuiKey_Home;
|
|
||||||
case SDLK_END: return ImGuiKey_End;
|
|
||||||
case SDLK_INSERT: return ImGuiKey_Insert;
|
|
||||||
case SDLK_DELETE: return ImGuiKey_Delete;
|
|
||||||
case SDLK_BACKSPACE: return ImGuiKey_Backspace;
|
|
||||||
case SDLK_SPACE: return ImGuiKey_Space;
|
|
||||||
case SDLK_RETURN: return ImGuiKey_Enter;
|
|
||||||
case SDLK_ESCAPE: return ImGuiKey_Escape;
|
|
||||||
case SDLK_QUOTE: return ImGuiKey_Apostrophe;
|
|
||||||
case SDLK_COMMA: return ImGuiKey_Comma;
|
|
||||||
case SDLK_MINUS: return ImGuiKey_Minus;
|
|
||||||
case SDLK_PERIOD: return ImGuiKey_Period;
|
|
||||||
case SDLK_SLASH: return ImGuiKey_Slash;
|
|
||||||
case SDLK_SEMICOLON: return ImGuiKey_Semicolon;
|
|
||||||
case SDLK_EQUALS: return ImGuiKey_Equal;
|
|
||||||
case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
|
||||||
case SDLK_BACKSLASH: return ImGuiKey_Backslash;
|
|
||||||
case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
|
||||||
case SDLK_BACKQUOTE: return ImGuiKey_GraveAccent;
|
|
||||||
case SDLK_CAPSLOCK: return ImGuiKey_CapsLock;
|
|
||||||
case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock;
|
|
||||||
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
|
|
||||||
case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
|
|
||||||
case SDLK_PAUSE: return ImGuiKey_Pause;
|
|
||||||
case SDLK_KP_0: return ImGuiKey_Keypad0;
|
|
||||||
case SDLK_KP_1: return ImGuiKey_Keypad1;
|
|
||||||
case SDLK_KP_2: return ImGuiKey_Keypad2;
|
|
||||||
case SDLK_KP_3: return ImGuiKey_Keypad3;
|
|
||||||
case SDLK_KP_4: return ImGuiKey_Keypad4;
|
|
||||||
case SDLK_KP_5: return ImGuiKey_Keypad5;
|
|
||||||
case SDLK_KP_6: return ImGuiKey_Keypad6;
|
|
||||||
case SDLK_KP_7: return ImGuiKey_Keypad7;
|
|
||||||
case SDLK_KP_8: return ImGuiKey_Keypad8;
|
|
||||||
case SDLK_KP_9: return ImGuiKey_Keypad9;
|
|
||||||
case SDLK_KP_PERIOD: return ImGuiKey_KeypadDecimal;
|
|
||||||
case SDLK_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
|
||||||
case SDLK_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
|
||||||
case SDLK_KP_MINUS: return ImGuiKey_KeypadSubtract;
|
|
||||||
case SDLK_KP_PLUS: return ImGuiKey_KeypadAdd;
|
|
||||||
case SDLK_KP_ENTER: return ImGuiKey_KeypadEnter;
|
|
||||||
case SDLK_KP_EQUALS: return ImGuiKey_KeypadEqual;
|
|
||||||
case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
|
|
||||||
case SDLK_LSHIFT: return ImGuiKey_LeftShift;
|
|
||||||
case SDLK_LALT: return ImGuiKey_LeftAlt;
|
|
||||||
case SDLK_LGUI: return ImGuiKey_LeftSuper;
|
|
||||||
case SDLK_RCTRL: return ImGuiKey_RightCtrl;
|
|
||||||
case SDLK_RSHIFT: return ImGuiKey_RightShift;
|
|
||||||
case SDLK_RALT: return ImGuiKey_RightAlt;
|
|
||||||
case SDLK_RGUI: return ImGuiKey_RightSuper;
|
|
||||||
case SDLK_APPLICATION: return ImGuiKey_Menu;
|
|
||||||
case SDLK_0: return ImGuiKey_0;
|
|
||||||
case SDLK_1: return ImGuiKey_1;
|
|
||||||
case SDLK_2: return ImGuiKey_2;
|
|
||||||
case SDLK_3: return ImGuiKey_3;
|
|
||||||
case SDLK_4: return ImGuiKey_4;
|
|
||||||
case SDLK_5: return ImGuiKey_5;
|
|
||||||
case SDLK_6: return ImGuiKey_6;
|
|
||||||
case SDLK_7: return ImGuiKey_7;
|
|
||||||
case SDLK_8: return ImGuiKey_8;
|
|
||||||
case SDLK_9: return ImGuiKey_9;
|
|
||||||
case SDLK_a: return ImGuiKey_A;
|
|
||||||
case SDLK_b: return ImGuiKey_B;
|
|
||||||
case SDLK_c: return ImGuiKey_C;
|
|
||||||
case SDLK_d: return ImGuiKey_D;
|
|
||||||
case SDLK_e: return ImGuiKey_E;
|
|
||||||
case SDLK_f: return ImGuiKey_F;
|
|
||||||
case SDLK_g: return ImGuiKey_G;
|
|
||||||
case SDLK_h: return ImGuiKey_H;
|
|
||||||
case SDLK_i: return ImGuiKey_I;
|
|
||||||
case SDLK_j: return ImGuiKey_J;
|
|
||||||
case SDLK_k: return ImGuiKey_K;
|
|
||||||
case SDLK_l: return ImGuiKey_L;
|
|
||||||
case SDLK_m: return ImGuiKey_M;
|
|
||||||
case SDLK_n: return ImGuiKey_N;
|
|
||||||
case SDLK_o: return ImGuiKey_O;
|
|
||||||
case SDLK_p: return ImGuiKey_P;
|
|
||||||
case SDLK_q: return ImGuiKey_Q;
|
|
||||||
case SDLK_r: return ImGuiKey_R;
|
|
||||||
case SDLK_s: return ImGuiKey_S;
|
|
||||||
case SDLK_t: return ImGuiKey_T;
|
|
||||||
case SDLK_u: return ImGuiKey_U;
|
|
||||||
case SDLK_v: return ImGuiKey_V;
|
|
||||||
case SDLK_w: return ImGuiKey_W;
|
|
||||||
case SDLK_x: return ImGuiKey_X;
|
|
||||||
case SDLK_y: return ImGuiKey_Y;
|
|
||||||
case SDLK_z: return ImGuiKey_Z;
|
|
||||||
case SDLK_F1: return ImGuiKey_F1;
|
|
||||||
case SDLK_F2: return ImGuiKey_F2;
|
|
||||||
case SDLK_F3: return ImGuiKey_F3;
|
|
||||||
case SDLK_F4: return ImGuiKey_F4;
|
|
||||||
case SDLK_F5: return ImGuiKey_F5;
|
|
||||||
case SDLK_F6: return ImGuiKey_F6;
|
|
||||||
case SDLK_F7: return ImGuiKey_F7;
|
|
||||||
case SDLK_F8: return ImGuiKey_F8;
|
|
||||||
case SDLK_F9: return ImGuiKey_F9;
|
|
||||||
case SDLK_F10: return ImGuiKey_F10;
|
|
||||||
case SDLK_F11: return ImGuiKey_F11;
|
|
||||||
case SDLK_F12: return ImGuiKey_F12;
|
|
||||||
case SDLK_F13: return ImGuiKey_F13;
|
|
||||||
case SDLK_F14: return ImGuiKey_F14;
|
|
||||||
case SDLK_F15: return ImGuiKey_F15;
|
|
||||||
case SDLK_F16: return ImGuiKey_F16;
|
|
||||||
case SDLK_F17: return ImGuiKey_F17;
|
|
||||||
case SDLK_F18: return ImGuiKey_F18;
|
|
||||||
case SDLK_F19: return ImGuiKey_F19;
|
|
||||||
case SDLK_F20: return ImGuiKey_F20;
|
|
||||||
case SDLK_F21: return ImGuiKey_F21;
|
|
||||||
case SDLK_F22: return ImGuiKey_F22;
|
|
||||||
case SDLK_F23: return ImGuiKey_F23;
|
|
||||||
case SDLK_F24: return ImGuiKey_F24;
|
|
||||||
case SDLK_AC_BACK: return ImGuiKey_AppBack;
|
|
||||||
case SDLK_AC_FORWARD: return ImGuiKey_AppForward;
|
|
||||||
}
|
|
||||||
return ImGuiKey_None;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & SDL_KMOD_CTRL) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & SDL_KMOD_SHIFT) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & SDL_KMOD_ALT) != 0);
|
|
||||||
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
||||||
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
|
||||||
bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
|
||||||
|
|
||||||
switch (event->type)
|
|
||||||
{
|
|
||||||
case SDL_EVENT_MOUSE_MOTION:
|
|
||||||
{
|
|
||||||
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
|
||||||
io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
|
||||||
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_EVENT_MOUSE_WHEEL:
|
|
||||||
{
|
|
||||||
//IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
|
|
||||||
float wheel_x = -event->wheel.x;
|
|
||||||
float wheel_y = event->wheel.y;
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
wheel_x /= 100.0f;
|
|
||||||
#endif
|
|
||||||
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
|
||||||
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
|
||||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
|
||||||
{
|
|
||||||
int mouse_button = -1;
|
|
||||||
if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
|
|
||||||
if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; }
|
|
||||||
if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; }
|
|
||||||
if (event->button.button == SDL_BUTTON_X1) { mouse_button = 3; }
|
|
||||||
if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; }
|
|
||||||
if (mouse_button == -1)
|
|
||||||
break;
|
|
||||||
io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
|
||||||
io.AddMouseButtonEvent(mouse_button, (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN));
|
|
||||||
bd->MouseButtonsDown = (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_EVENT_TEXT_INPUT:
|
|
||||||
{
|
|
||||||
io.AddInputCharactersUTF8(event->text.text);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_EVENT_KEY_DOWN:
|
|
||||||
case SDL_EVENT_KEY_UP:
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL3_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
|
|
||||||
ImGuiKey key = ImGui_ImplSDL3_KeycodeToImGuiKey(event->key.keysym.sym);
|
|
||||||
io.AddKeyEvent(key, (event->type == SDL_EVENT_KEY_DOWN));
|
|
||||||
io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_EVENT_WINDOW_MOUSE_ENTER:
|
|
||||||
{
|
|
||||||
bd->MouseWindowID = event->window.windowID;
|
|
||||||
bd->PendingMouseLeaveFrame = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
|
|
||||||
// causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why
|
|
||||||
// we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details.
|
|
||||||
// FIXME: Unconfirmed whether this is still needed with SDL3.
|
|
||||||
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
|
|
||||||
{
|
|
||||||
bd->PendingMouseLeaveFrame = ImGui::GetFrameCount() + 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
|
||||||
io.AddFocusEvent(true);
|
|
||||||
return true;
|
|
||||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
|
||||||
io.AddFocusEvent(false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_SetupPlatformHandles(ImGuiViewport* viewport, SDL_Window* window)
|
|
||||||
{
|
|
||||||
IM_UNUSED(window);
|
|
||||||
viewport->PlatformHandleRaw = nullptr;
|
|
||||||
#if defined(__WIN32__) && !defined(__WINRT__)
|
|
||||||
viewport->PlatformHandleRaw = (HWND)SDL_GetProperty(SDL_GetWindowProperties(window), "SDL.window.win32.hwnd", nullptr);
|
|
||||||
#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
|
|
||||||
viewport->PlatformHandleRaw = (void*)SDL_GetProperty(SDL_GetWindowProperties(window), "SDL.window.cocoa.window", nullptr);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
|
||||||
IM_UNUSED(sdl_gl_context); // Unused in this branch
|
|
||||||
|
|
||||||
// Check and store if we are on a SDL backend that supports global mouse position
|
|
||||||
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
|
||||||
bool mouse_can_use_global_state = false;
|
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
|
||||||
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
|
||||||
const char* global_mouse_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
|
||||||
for (int n = 0; n < IM_ARRAYSIZE(global_mouse_whitelist); n++)
|
|
||||||
if (strncmp(sdl_backend, global_mouse_whitelist[n], strlen(global_mouse_whitelist[n])) == 0)
|
|
||||||
mouse_can_use_global_state = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplSDL3_Data* bd = IM_NEW(ImGui_ImplSDL3_Data)();
|
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
|
||||||
io.BackendPlatformName = "imgui_impl_sdl3";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
|
||||||
|
|
||||||
bd->Window = window;
|
|
||||||
bd->Renderer = renderer;
|
|
||||||
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
|
|
||||||
|
|
||||||
io.SetClipboardTextFn = ImGui_ImplSDL3_SetClipboardText;
|
|
||||||
io.GetClipboardTextFn = ImGui_ImplSDL3_GetClipboardText;
|
|
||||||
io.ClipboardUserData = nullptr;
|
|
||||||
io.SetPlatformImeDataFn = ImGui_ImplSDL3_SetPlatformImeData;
|
|
||||||
|
|
||||||
// Load mouse cursors
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
|
|
||||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
|
|
||||||
|
|
||||||
// Set platform dependent data in viewport
|
|
||||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
|
||||||
ImGui_ImplSDL3_SetupPlatformHandles(main_viewport, window);
|
|
||||||
|
|
||||||
// From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
|
|
||||||
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
|
|
||||||
// (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
|
|
||||||
// It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
|
|
||||||
// you can ignore SDL_EVENT_MOUSE_BUTTON_DOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED)
|
|
||||||
#ifdef SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
|
|
||||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710)
|
|
||||||
#ifdef SDL_HINT_MOUSE_AUTO_CAPTURE
|
|
||||||
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
|
|
||||||
{
|
|
||||||
IM_UNUSED(sdl_gl_context); // Viewport branch will need this.
|
|
||||||
return ImGui_ImplSDL3_Init(window, nullptr, sdl_gl_context);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window)
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window)
|
|
||||||
{
|
|
||||||
#if !defined(_WIN32)
|
|
||||||
IM_ASSERT(0 && "Unsupported");
|
|
||||||
#endif
|
|
||||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window)
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDL3_Init(window, renderer, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDL3_InitForOther(SDL_Window* window)
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDL3_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
if (bd->ClipboardTextData)
|
|
||||||
SDL_free(bd->ClipboardTextData);
|
|
||||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
|
||||||
SDL_DestroyCursor(bd->MouseCursors[cursor_n]);
|
|
||||||
bd->LastMouseCursor = nullptr;
|
|
||||||
|
|
||||||
io.BackendPlatformName = nullptr;
|
|
||||||
io.BackendPlatformUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_UpdateMouseData()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below)
|
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
|
||||||
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside
|
|
||||||
SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE);
|
|
||||||
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
|
||||||
const bool is_app_focused = (bd->Window == focused_window);
|
|
||||||
#else
|
|
||||||
SDL_Window* focused_window = bd->Window;
|
|
||||||
const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only
|
|
||||||
#endif
|
|
||||||
if (is_app_focused)
|
|
||||||
{
|
|
||||||
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
|
||||||
if (io.WantSetMousePos)
|
|
||||||
SDL_WarpMouseInWindow(bd->Window, io.MousePos.x, io.MousePos.y);
|
|
||||||
|
|
||||||
// (Optional) Fallback to provide mouse position when focused (SDL_EVENT_MOUSE_MOTION already provides this when hovered or captured)
|
|
||||||
if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0)
|
|
||||||
{
|
|
||||||
// Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
|
|
||||||
float mouse_x_global, mouse_y_global;
|
|
||||||
int window_x, window_y;
|
|
||||||
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
|
|
||||||
SDL_GetWindowPosition(focused_window, &window_x, &window_y);
|
|
||||||
io.AddMousePosEvent(mouse_x_global - window_x, mouse_y_global - window_y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_UpdateMouseCursor()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
|
||||||
return;
|
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
|
||||||
|
|
||||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
|
||||||
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
|
||||||
{
|
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
|
||||||
SDL_HideCursor();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Show OS mouse cursor
|
|
||||||
SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
|
||||||
if (bd->LastMouseCursor != expected_cursor)
|
|
||||||
{
|
|
||||||
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
|
||||||
bd->LastMouseCursor = expected_cursor;
|
|
||||||
}
|
|
||||||
SDL_ShowCursor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_UpdateGamepads()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Get gamepad
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
|
||||||
SDL_Gamepad* gamepad = SDL_OpenGamepad(0);
|
|
||||||
if (!gamepad)
|
|
||||||
return;
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
|
||||||
|
|
||||||
// Update gamepad inputs
|
|
||||||
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
|
|
||||||
#define MAP_BUTTON(KEY_NO, BUTTON_NO) { io.AddKeyEvent(KEY_NO, SDL_GetGamepadButton(gamepad, BUTTON_NO) != 0); }
|
|
||||||
#define MAP_ANALOG(KEY_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GetGamepadAxis(gamepad, AXIS_NO) - V0) / (float)(V1 - V0); vn = IM_SATURATE(vn); io.AddKeyAnalogEvent(KEY_NO, vn > 0.1f, vn); }
|
|
||||||
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadStart, SDL_GAMEPAD_BUTTON_START);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadBack, SDL_GAMEPAD_BUTTON_BACK);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, SDL_GAMEPAD_BUTTON_WEST); // Xbox X, PS Square
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceRight, SDL_GAMEPAD_BUTTON_EAST); // Xbox B, PS Circle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceUp, SDL_GAMEPAD_BUTTON_NORTH); // Xbox Y, PS Triangle
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadFaceDown, SDL_GAMEPAD_BUTTON_SOUTH); // Xbox A, PS Cross
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadRight, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadUp, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadDpadDown, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadL1, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadR1, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadL2, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, 0.0f, 32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadR2, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, 0.0f, 32767);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadL3, SDL_GAMEPAD_BUTTON_LEFT_STICK);
|
|
||||||
MAP_BUTTON(ImGuiKey_GamepadR3, SDL_GAMEPAD_BUTTON_RIGHT_STICK);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, SDL_GAMEPAD_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickRight, SDL_GAMEPAD_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickUp, SDL_GAMEPAD_AXIS_LEFTY, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadLStickDown, SDL_GAMEPAD_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, SDL_GAMEPAD_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickRight, SDL_GAMEPAD_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickUp, SDL_GAMEPAD_AXIS_RIGHTY, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiKey_GamepadRStickDown, SDL_GAMEPAD_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
|
||||||
#undef MAP_BUTTON
|
|
||||||
#undef MAP_ANALOG
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDL3_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDL3_Init()?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
|
||||||
int w, h;
|
|
||||||
int display_w, display_h;
|
|
||||||
SDL_GetWindowSize(bd->Window, &w, &h);
|
|
||||||
if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_MINIMIZED)
|
|
||||||
w = h = 0;
|
|
||||||
SDL_GetWindowSizeInPixels(bd->Window, &display_w, &display_h);
|
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
|
||||||
if (w > 0 && h > 0)
|
|
||||||
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
|
||||||
|
|
||||||
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
|
|
||||||
// (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)
|
|
||||||
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
|
||||||
Uint64 current_time = SDL_GetPerformanceCounter();
|
|
||||||
if (current_time <= bd->Time)
|
|
||||||
current_time = bd->Time + 1;
|
|
||||||
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
|
||||||
bd->Time = current_time;
|
|
||||||
|
|
||||||
if (bd->PendingMouseLeaveFrame && bd->PendingMouseLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
|
||||||
{
|
|
||||||
bd->MouseWindowID = 0;
|
|
||||||
bd->PendingMouseLeaveFrame = 0;
|
|
||||||
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplSDL3_UpdateMouseData();
|
|
||||||
ImGui_ImplSDL3_UpdateMouseCursor();
|
|
||||||
|
|
||||||
// Update game controllers (if enabled and available)
|
|
||||||
ImGui_ImplSDL3_UpdateGamepads();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,41 +0,0 @@
|
|||||||
// dear imgui: Platform Backend for SDL3 (*EXPERIMENTAL*)
|
|
||||||
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
|
|
||||||
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
|
||||||
// (IMPORTANT: SDL 3.0.0 is NOT YET RELEASED. IT IS POSSIBLE THAT ITS SPECS/API WILL CHANGE BEFORE RELEASE)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Platform: Clipboard support.
|
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
|
||||||
// [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 SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
|
||||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
|
||||||
// Missing features:
|
|
||||||
// [x] Platform: Basic IME support. Position somehow broken in SDL3 + app needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
|
||||||
|
|
||||||
// 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 SDL_Window;
|
|
||||||
struct SDL_Renderer;
|
|
||||||
typedef union SDL_Event SDL_Event;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOther(SDL_Window* window);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL3_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL3_NewFrame();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event);
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,266 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for SDL_Renderer for SDL2
|
|
||||||
// (Requires: SDL 2.0.17+)
|
|
||||||
|
|
||||||
// Note how SDL_Renderer is an _optional_ component of SDL2.
|
|
||||||
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX.
|
|
||||||
// If your application will want to render any non trivial amount of graphics other than UI,
|
|
||||||
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and
|
|
||||||
// it might be difficult to step out of those boundaries.
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// You can copy and 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
|
|
||||||
// 2023-05-30: Renamed imgui_impl_sdlrenderer.h/.cpp to imgui_impl_sdlrenderer2.h/.cpp to accommodate for upcoming SDL3.
|
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
||||||
// 2021-12-21: Update SDL_RenderGeometryRaw() format to work with SDL 2.0.19.
|
|
||||||
// 2021-12-03: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
||||||
// 2021-10-06: Backup and restore modified ClipRect/Viewport.
|
|
||||||
// 2021-09-21: Initial version.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_sdlrenderer2.h"
|
|
||||||
#include <stdint.h> // intptr_t
|
|
||||||
|
|
||||||
// Clang warnings with -Weverything
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SDL
|
|
||||||
#include <SDL.h>
|
|
||||||
#if !SDL_VERSION_ATLEAST(2,0,17)
|
|
||||||
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SDL_Renderer data
|
|
||||||
struct ImGui_ImplSDLRenderer2_Data
|
|
||||||
{
|
|
||||||
SDL_Renderer* SDLRenderer;
|
|
||||||
SDL_Texture* FontTexture;
|
|
||||||
ImGui_ImplSDLRenderer2_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_ImplSDLRenderer2_Data* ImGui_ImplSDLRenderer2_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer2_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
IM_ASSERT(renderer != nullptr && "SDL_Renderer not initialized!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplSDLRenderer2_Data* bd = IM_NEW(ImGui_ImplSDLRenderer2_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_sdlrenderer2";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
|
|
||||||
bd->SDLRenderer = renderer;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer2_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDLRenderer2_SetupRenderState()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
|
||||||
|
|
||||||
// Clear out any viewports and cliprect set by the user
|
|
||||||
// FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process.
|
|
||||||
SDL_RenderSetViewport(bd->SDLRenderer, nullptr);
|
|
||||||
SDL_RenderSetClipRect(bd->SDLRenderer, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer2_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDLRenderer2_Init()?");
|
|
||||||
|
|
||||||
if (!bd->FontTexture)
|
|
||||||
ImGui_ImplSDLRenderer2_CreateDeviceObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
|
||||||
|
|
||||||
// If there's a scale factor set by the user, use that instead
|
|
||||||
// If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass
|
|
||||||
// to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here.
|
|
||||||
float rsx = 1.0f;
|
|
||||||
float rsy = 1.0f;
|
|
||||||
SDL_RenderGetScale(bd->SDLRenderer, &rsx, &rsy);
|
|
||||||
ImVec2 render_scale;
|
|
||||||
render_scale.x = (rsx == 1.0f) ? draw_data->FramebufferScale.x : 1.0f;
|
|
||||||
render_scale.y = (rsy == 1.0f) ? draw_data->FramebufferScale.y : 1.0f;
|
|
||||||
|
|
||||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
|
||||||
int fb_width = (int)(draw_data->DisplaySize.x * render_scale.x);
|
|
||||||
int fb_height = (int)(draw_data->DisplaySize.y * render_scale.y);
|
|
||||||
if (fb_width == 0 || fb_height == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Backup SDL_Renderer state that will be modified to restore it afterwards
|
|
||||||
struct BackupSDLRendererState
|
|
||||||
{
|
|
||||||
SDL_Rect Viewport;
|
|
||||||
bool ClipEnabled;
|
|
||||||
SDL_Rect ClipRect;
|
|
||||||
};
|
|
||||||
BackupSDLRendererState old = {};
|
|
||||||
old.ClipEnabled = SDL_RenderIsClipEnabled(bd->SDLRenderer) == SDL_TRUE;
|
|
||||||
SDL_RenderGetViewport(bd->SDLRenderer, &old.Viewport);
|
|
||||||
SDL_RenderGetClipRect(bd->SDLRenderer, &old.ClipRect);
|
|
||||||
|
|
||||||
// Will project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
|
||||||
ImVec2 clip_scale = render_scale;
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
ImGui_ImplSDLRenderer2_SetupRenderState();
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
|
||||||
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
|
||||||
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
||||||
{
|
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
||||||
if (pcmd->UserCallback)
|
|
||||||
{
|
|
||||||
// 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_ImplSDLRenderer2_SetupRenderState();
|
|
||||||
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_min.x < 0.0f) { clip_min.x = 0.0f; }
|
|
||||||
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
|
|
||||||
if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; }
|
|
||||||
if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; }
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) };
|
|
||||||
SDL_RenderSetClipRect(bd->SDLRenderer, &r);
|
|
||||||
|
|
||||||
const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, pos));
|
|
||||||
const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, uv));
|
|
||||||
#if SDL_VERSION_ATLEAST(2,0,19)
|
|
||||||
const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, col)); // SDL 2.0.19+
|
|
||||||
#else
|
|
||||||
const int* color = (const int*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, col)); // SDL 2.0.17 and 2.0.18
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Bind texture, Draw
|
|
||||||
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
|
||||||
SDL_RenderGeometryRaw(bd->SDLRenderer, tex,
|
|
||||||
xy, (int)sizeof(ImDrawVert),
|
|
||||||
color, (int)sizeof(ImDrawVert),
|
|
||||||
uv, (int)sizeof(ImDrawVert),
|
|
||||||
cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
|
|
||||||
idx_buffer + pcmd->IdxOffset, pcmd->ElemCount, sizeof(ImDrawIdx));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore modified SDL_Renderer state
|
|
||||||
SDL_RenderSetViewport(bd->SDLRenderer, &old.Viewport);
|
|
||||||
SDL_RenderSetClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called by Init/NewFrame/Shutdown
|
|
||||||
bool ImGui_ImplSDLRenderer2_CreateFontsTexture()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_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)
|
|
||||||
bd->FontTexture = SDL_CreateTexture(bd->SDLRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height);
|
|
||||||
if (bd->FontTexture == nullptr)
|
|
||||||
{
|
|
||||||
SDL_Log("error creating texture");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
SDL_UpdateTexture(bd->FontTexture, nullptr, pixels, 4 * width);
|
|
||||||
SDL_SetTextureBlendMode(bd->FontTexture, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetTextureScaleMode(bd->FontTexture, SDL_ScaleModeLinear);
|
|
||||||
|
|
||||||
// Store our identifier
|
|
||||||
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer2_DestroyFontsTexture()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
|
||||||
if (bd->FontTexture)
|
|
||||||
{
|
|
||||||
io.Fonts->SetTexID(0);
|
|
||||||
SDL_DestroyTexture(bd->FontTexture);
|
|
||||||
bd->FontTexture = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDLRenderer2_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDLRenderer2_CreateFontsTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer2_DestroyDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer2_DestroyFontsTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,39 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for SDL_Renderer for SDL2
|
|
||||||
// (Requires: SDL 2.0.17+)
|
|
||||||
|
|
||||||
// Note how SDL_Renderer is an _optional_ component of SDL2.
|
|
||||||
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX.
|
|
||||||
// If your application will want to render any non trivial amount of graphics other than UI,
|
|
||||||
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and
|
|
||||||
// it might be difficult to step out of those boundaries.
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// 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
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
|
|
||||||
struct SDL_Renderer;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
|
|
||||||
// Called by Init/NewFrame/Shutdown
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateFontsTexture();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyFontsTexture();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,261 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for SDL_Renderer for SDL3
|
|
||||||
// (Requires: SDL 3.0.0+)
|
|
||||||
|
|
||||||
// Note how SDL_Renderer is an _optional_ component of SDL3.
|
|
||||||
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX.
|
|
||||||
// If your application will want to render any non trivial amount of graphics other than UI,
|
|
||||||
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and
|
|
||||||
// it might be difficult to step out of those boundaries.
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// You can copy and 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
|
|
||||||
// 2023-05-30: Initial version.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui_impl_sdlrenderer3.h"
|
|
||||||
#include <stdint.h> // intptr_t
|
|
||||||
|
|
||||||
// Clang warnings with -Weverything
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SDL
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#if !SDL_VERSION_ATLEAST(3,0,0)
|
|
||||||
#error This backend requires SDL 3.0.0+
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SDL_Renderer data
|
|
||||||
struct ImGui_ImplSDLRenderer3_Data
|
|
||||||
{
|
|
||||||
SDL_Renderer* SDLRenderer;
|
|
||||||
SDL_Texture* FontTexture;
|
|
||||||
ImGui_ImplSDLRenderer3_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_ImplSDLRenderer3_Data* ImGui_ImplSDLRenderer3_GetBackendData()
|
|
||||||
{
|
|
||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
IM_ASSERT(renderer != nullptr && "SDL_Renderer not initialized!");
|
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = IM_NEW(ImGui_ImplSDLRenderer3_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_sdlrenderer3";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
|
|
||||||
bd->SDLRenderer = renderer;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer3_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
ImGui_ImplSDLRenderer3_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDLRenderer3_SetupRenderState()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
||||||
|
|
||||||
// Clear out any viewports and cliprect set by the user
|
|
||||||
// FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process.
|
|
||||||
SDL_SetRenderViewport(bd->SDLRenderer, nullptr);
|
|
||||||
SDL_SetRenderClipRect(bd->SDLRenderer, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer3_NewFrame()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDLRenderer3_Init()?");
|
|
||||||
|
|
||||||
if (!bd->FontTexture)
|
|
||||||
ImGui_ImplSDLRenderer3_CreateDeviceObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data)
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
||||||
|
|
||||||
// If there's a scale factor set by the user, use that instead
|
|
||||||
// If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass
|
|
||||||
// to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here.
|
|
||||||
float rsx = 1.0f;
|
|
||||||
float rsy = 1.0f;
|
|
||||||
SDL_GetRenderScale(bd->SDLRenderer, &rsx, &rsy);
|
|
||||||
ImVec2 render_scale;
|
|
||||||
render_scale.x = (rsx == 1.0f) ? draw_data->FramebufferScale.x : 1.0f;
|
|
||||||
render_scale.y = (rsy == 1.0f) ? draw_data->FramebufferScale.y : 1.0f;
|
|
||||||
|
|
||||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
|
||||||
int fb_width = (int)(draw_data->DisplaySize.x * render_scale.x);
|
|
||||||
int fb_height = (int)(draw_data->DisplaySize.y * render_scale.y);
|
|
||||||
if (fb_width == 0 || fb_height == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Backup SDL_Renderer state that will be modified to restore it afterwards
|
|
||||||
struct BackupSDLRendererState
|
|
||||||
{
|
|
||||||
SDL_Rect Viewport;
|
|
||||||
bool ClipEnabled;
|
|
||||||
SDL_Rect ClipRect;
|
|
||||||
};
|
|
||||||
BackupSDLRendererState old = {};
|
|
||||||
old.ClipEnabled = SDL_RenderClipEnabled(bd->SDLRenderer) == SDL_TRUE;
|
|
||||||
SDL_GetRenderViewport(bd->SDLRenderer, &old.Viewport);
|
|
||||||
SDL_GetRenderClipRect(bd->SDLRenderer, &old.ClipRect);
|
|
||||||
|
|
||||||
// Will project scissor/clipping rectangles into framebuffer space
|
|
||||||
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
|
||||||
ImVec2 clip_scale = render_scale;
|
|
||||||
|
|
||||||
// Render command lists
|
|
||||||
ImGui_ImplSDLRenderer3_SetupRenderState();
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
||||||
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
|
||||||
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
|
||||||
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
||||||
{
|
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
||||||
if (pcmd->UserCallback)
|
|
||||||
{
|
|
||||||
// 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_ImplSDLRenderer3_SetupRenderState();
|
|
||||||
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_min.x < 0.0f) { clip_min.x = 0.0f; }
|
|
||||||
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
|
|
||||||
if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; }
|
|
||||||
if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; }
|
|
||||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) };
|
|
||||||
SDL_SetRenderClipRect(bd->SDLRenderer, &r);
|
|
||||||
|
|
||||||
const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, pos));
|
|
||||||
const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, uv));
|
|
||||||
#if SDL_VERSION_ATLEAST(2,0,19)
|
|
||||||
const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, col)); // SDL 2.0.19+
|
|
||||||
#else
|
|
||||||
const int* color = (const int*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, col)); // SDL 2.0.17 and 2.0.18
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Bind texture, Draw
|
|
||||||
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
|
||||||
SDL_RenderGeometryRaw(bd->SDLRenderer, tex,
|
|
||||||
xy, (int)sizeof(ImDrawVert),
|
|
||||||
color, (int)sizeof(ImDrawVert),
|
|
||||||
uv, (int)sizeof(ImDrawVert),
|
|
||||||
cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
|
|
||||||
idx_buffer + pcmd->IdxOffset, pcmd->ElemCount, sizeof(ImDrawIdx));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore modified SDL_Renderer state
|
|
||||||
SDL_SetRenderViewport(bd->SDLRenderer, &old.Viewport);
|
|
||||||
SDL_SetRenderClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called by Init/NewFrame/Shutdown
|
|
||||||
bool ImGui_ImplSDLRenderer3_CreateFontsTexture()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_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)
|
|
||||||
bd->FontTexture = SDL_CreateTexture(bd->SDLRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height);
|
|
||||||
if (bd->FontTexture == nullptr)
|
|
||||||
{
|
|
||||||
SDL_Log("error creating texture");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
SDL_UpdateTexture(bd->FontTexture, nullptr, pixels, 4 * width);
|
|
||||||
SDL_SetTextureBlendMode(bd->FontTexture, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetTextureScaleMode(bd->FontTexture, SDL_SCALEMODE_LINEAR);
|
|
||||||
|
|
||||||
// Store our identifier
|
|
||||||
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer3_DestroyFontsTexture()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
||||||
if (bd->FontTexture)
|
|
||||||
{
|
|
||||||
io.Fonts->SetTexID(0);
|
|
||||||
SDL_DestroyTexture(bd->FontTexture);
|
|
||||||
bd->FontTexture = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGui_ImplSDLRenderer3_CreateDeviceObjects()
|
|
||||||
{
|
|
||||||
return ImGui_ImplSDLRenderer3_CreateFontsTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer3_DestroyDeviceObjects()
|
|
||||||
{
|
|
||||||
ImGui_ImplSDLRenderer3_DestroyFontsTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
@ -1,39 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for SDL_Renderer for SDL3
|
|
||||||
// (Requires: SDL 3.0.0+)
|
|
||||||
|
|
||||||
// Note how SDL_Renderer is an _optional_ component of SDL3.
|
|
||||||
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX.
|
|
||||||
// If your application will want to render any non trivial amount of graphics other than UI,
|
|
||||||
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and
|
|
||||||
// it might be difficult to step out of those boundaries.
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// You can copy and 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 SDL_Renderer;
|
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data);
|
|
||||||
|
|
||||||
// Called by Init/NewFrame/Shutdown
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_CreateFontsTexture();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_DestroyFontsTexture();
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_CreateDeviceObjects();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_DestroyDeviceObjects();
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
File diff suppressed because it is too large
Load Diff
@ -1,170 +0,0 @@
|
|||||||
// dear imgui: Renderer Backend for Vulkan
|
|
||||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
|
||||||
|
|
||||||
// Implemented features:
|
|
||||||
// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions.
|
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
||||||
|
|
||||||
// Important: on 32-bit systems, user texture binding is only supported if your imconfig file has '#define ImTextureID ImU64'.
|
|
||||||
// See imgui_impl_vulkan.cpp file for details.
|
|
||||||
|
|
||||||
// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
|
|
||||||
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
|
|
||||||
// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
|
|
||||||
// You will use those if you want to use this rendering backend in your engine/app.
|
|
||||||
// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
|
|
||||||
// the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
|
|
||||||
// Read comments in imgui_impl_vulkan.h.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#ifndef IMGUI_DISABLE
|
|
||||||
#include "imgui.h" // IMGUI_IMPL_API
|
|
||||||
|
|
||||||
// [Configuration] in order to use a custom Vulkan function loader:
|
|
||||||
// (1) You'll need to disable default Vulkan function prototypes.
|
|
||||||
// We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag.
|
|
||||||
// In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit:
|
|
||||||
// - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file
|
|
||||||
// - Or as a compilation flag in your build system
|
|
||||||
// - Or uncomment here (not recommended because you'd be modifying imgui sources!)
|
|
||||||
// - Do not simply add it in a .cpp file!
|
|
||||||
// (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function.
|
|
||||||
// If you have no idea what this is, leave it alone!
|
|
||||||
//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
|
||||||
|
|
||||||
// Vulkan includes
|
|
||||||
#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
|
|
||||||
#define VK_NO_PROTOTYPES
|
|
||||||
#endif
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
// Initialization data, for ImGui_ImplVulkan_Init()
|
|
||||||
// [Please zero-clear before use!]
|
|
||||||
struct ImGui_ImplVulkan_InitInfo
|
|
||||||
{
|
|
||||||
VkInstance Instance;
|
|
||||||
VkPhysicalDevice PhysicalDevice;
|
|
||||||
VkDevice Device;
|
|
||||||
uint32_t QueueFamily;
|
|
||||||
VkQueue Queue;
|
|
||||||
VkPipelineCache PipelineCache;
|
|
||||||
VkDescriptorPool DescriptorPool;
|
|
||||||
uint32_t Subpass;
|
|
||||||
uint32_t MinImageCount; // >= 2
|
|
||||||
uint32_t ImageCount; // >= MinImageCount
|
|
||||||
VkSampleCountFlagBits MSAASamples; // >= VK_SAMPLE_COUNT_1_BIT (0 -> default to VK_SAMPLE_COUNT_1_BIT)
|
|
||||||
|
|
||||||
// Dynamic Rendering (Optional)
|
|
||||||
bool UseDynamicRendering; // Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3.
|
|
||||||
VkFormat ColorAttachmentFormat; // Required for dynamic rendering
|
|
||||||
|
|
||||||
// Allocation, Debugging
|
|
||||||
const VkAllocationCallbacks* Allocator;
|
|
||||||
void (*CheckVkResultFn)(VkResult err);
|
|
||||||
VkDeviceSize MinAllocationSize; // Minimum allocation size. Set to 1024*1024 to satisfy zealous best practices validation layer and waste a little memory.
|
|
||||||
};
|
|
||||||
|
|
||||||
// Called by user code
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE);
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontsTexture();
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
|
|
||||||
|
|
||||||
// Register a texture (VkDescriptorSet == ImTextureID)
|
|
||||||
// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem
|
|
||||||
// Please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions.
|
|
||||||
IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set);
|
|
||||||
|
|
||||||
// Optional: load Vulkan functions with a custom function loader
|
|
||||||
// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Internal / Miscellaneous Vulkan Helpers
|
|
||||||
// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.)
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// You probably do NOT need to use or care about those functions.
|
|
||||||
// Those functions only exist because:
|
|
||||||
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
|
||||||
// 2) the multi-viewport / platform window implementation needs them internally.
|
|
||||||
// Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
|
|
||||||
// but it is too much code to duplicate everywhere so we exceptionally expose them.
|
|
||||||
//
|
|
||||||
// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
|
|
||||||
// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
|
|
||||||
// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
struct ImGui_ImplVulkanH_Frame;
|
|
||||||
struct ImGui_ImplVulkanH_Window;
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator);
|
|
||||||
IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
|
|
||||||
IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
|
|
||||||
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
|
||||||
|
|
||||||
// Helper structure to hold the data needed by one rendering frame
|
|
||||||
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
|
||||||
// [Please zero-clear before use!]
|
|
||||||
struct ImGui_ImplVulkanH_Frame
|
|
||||||
{
|
|
||||||
VkCommandPool CommandPool;
|
|
||||||
VkCommandBuffer CommandBuffer;
|
|
||||||
VkFence Fence;
|
|
||||||
VkImage Backbuffer;
|
|
||||||
VkImageView BackbufferView;
|
|
||||||
VkFramebuffer Framebuffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ImGui_ImplVulkanH_FrameSemaphores
|
|
||||||
{
|
|
||||||
VkSemaphore ImageAcquiredSemaphore;
|
|
||||||
VkSemaphore RenderCompleteSemaphore;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper structure to hold the data needed by one rendering context into one OS window
|
|
||||||
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
|
||||||
struct ImGui_ImplVulkanH_Window
|
|
||||||
{
|
|
||||||
int Width;
|
|
||||||
int Height;
|
|
||||||
VkSwapchainKHR Swapchain;
|
|
||||||
VkSurfaceKHR Surface;
|
|
||||||
VkSurfaceFormatKHR SurfaceFormat;
|
|
||||||
VkPresentModeKHR PresentMode;
|
|
||||||
VkRenderPass RenderPass;
|
|
||||||
VkPipeline Pipeline; // The window pipeline may uses a different VkRenderPass than the one passed in ImGui_ImplVulkan_InitInfo
|
|
||||||
bool UseDynamicRendering;
|
|
||||||
bool ClearEnable;
|
|
||||||
VkClearValue ClearValue;
|
|
||||||
uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
|
|
||||||
uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
|
|
||||||
uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
|
|
||||||
ImGui_ImplVulkanH_Frame* Frames;
|
|
||||||
ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores;
|
|
||||||
|
|
||||||
ImGui_ImplVulkanH_Window()
|
|
||||||
{
|
|
||||||
memset((void*)this, 0, sizeof(*this));
|
|
||||||
PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this.
|
|
||||||
ClearEnable = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user