mirror of
https://github.com/ocornut/imgui.git
synced 2026-07-06 17:45:24 +00:00
Compare commits
773 Commits
v1.92.3-do
...
docking
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4be08b1ecf | ||
|
|
d098bf9657 | ||
|
|
5c2160ac85 | ||
|
|
5fb77dfde1 | ||
|
|
f7e8343ee9 | ||
|
|
7d43c74b59 | ||
|
|
8fc25800e0 | ||
|
|
6824e2c2e4 | ||
|
|
e9ea19086b | ||
|
|
caddd26fb9 | ||
|
|
fc6395365d | ||
|
|
93dd4c1567 | ||
|
|
279d04f7a3 | ||
|
|
0edad6d097 | ||
|
|
e408733ecc | ||
|
|
9e6c0416fe | ||
|
|
c66d9a8190 | ||
|
|
76f5be2749 | ||
|
|
5098ce161d | ||
|
|
60fbdbb8d8 | ||
|
|
ac6f9683b5 | ||
|
|
1c1241136a | ||
|
|
0e355af09e | ||
|
|
26432cfdc6 | ||
|
|
be374fa598 | ||
|
|
64a3e726a8 | ||
|
|
e74453760b | ||
|
|
ec69495ca8 | ||
|
|
b522576054 | ||
|
|
570c0e03b7 | ||
|
|
b9cf21733d | ||
|
|
7930405c73 | ||
|
|
f2fcdfe97f | ||
|
|
2f94e7dc13 | ||
|
|
b2377d616d | ||
|
|
d15966ff6c | ||
|
|
9a5c070308 | ||
|
|
73a6610e81 | ||
|
|
7aaf10f15b | ||
|
|
13fc81fc82 | ||
|
|
2064059a7f | ||
|
|
b47a3898b4 | ||
|
|
036bf939b6 | ||
|
|
1ba29f2bec | ||
|
|
138c0e6c7d | ||
|
|
b46a37eac9 | ||
|
|
e6147a3993 | ||
|
|
721da6a34c | ||
|
|
360183924b | ||
|
|
2aaa6d8173 | ||
|
|
3240201de2 | ||
|
|
94a3dcc5fa | ||
|
|
fea6f4603a | ||
|
|
d43c3f929c | ||
|
|
36ea9728d1 | ||
|
|
2e0f949039 | ||
|
|
924f57181b | ||
|
|
e5ff2d07d7 | ||
|
|
b10137f92f | ||
|
|
aa377352ef | ||
|
|
4312c4399f | ||
|
|
f1dd18b75c | ||
|
|
5220a3f48d | ||
|
|
2af6dd9694 | ||
|
|
6acba3b47d | ||
|
|
fc5e2f28fe | ||
|
|
7950c96f0e | ||
|
|
14278db024 | ||
|
|
c4eaac6d48 | ||
|
|
5a42cddcd2 | ||
|
|
995e4a65ff | ||
|
|
a054a016e2 | ||
|
|
045a0907f4 | ||
|
|
5aa0393a15 | ||
|
|
f241419b78 | ||
|
|
00abd2c325 | ||
|
|
3495e329f3 | ||
|
|
3b99fc4883 | ||
|
|
70f02b0558 | ||
|
|
cac16b0d16 | ||
|
|
1d33ea939f | ||
|
|
75f985998b | ||
|
|
12b7977555 | ||
|
|
4cb21e4a1e | ||
|
|
33bb693b4c | ||
|
|
783eba926f | ||
|
|
ac07da2b5b | ||
|
|
243097ca8f | ||
|
|
fbcf95193f | ||
|
|
24a80f74a4 | ||
|
|
904b663184 | ||
|
|
3e7b79aa17 | ||
|
|
e41d691da1 | ||
|
|
93e396ffb7 | ||
|
|
068e055510 | ||
|
|
5a76f2adf1 | ||
|
|
db161b84c9 | ||
|
|
4088a4f40c | ||
|
|
46a050fff2 | ||
|
|
c7767926ce | ||
|
|
310c719a1f | ||
|
|
b2546a5c93 | ||
|
|
e0f5f9a14c | ||
|
|
b61e56346a | ||
|
|
8936b58fe2 | ||
|
|
eebaddd340 | ||
|
|
73afb6b6e6 | ||
|
|
b8f6c51af7 | ||
|
|
4ac473b2c7 | ||
|
|
ac1f57ba0c | ||
|
|
821a396556 | ||
|
|
2b31f65167 | ||
|
|
b58836f287 | ||
|
|
bca5a69928 | ||
|
|
eb453f2be6 | ||
|
|
56b37bf93c | ||
|
|
0eae77f783 | ||
|
|
02ccd9f348 | ||
|
|
163b8670c8 | ||
|
|
c51f1a6e47 | ||
|
|
a70b97ee48 | ||
|
|
6df50a0667 | ||
|
|
976c5c0f3a | ||
|
|
310f3c8370 | ||
|
|
dc5c6b3688 | ||
|
|
691b89baae | ||
|
|
c0b693b1d4 | ||
|
|
865a6dfa59 | ||
|
|
dee9b15bbe | ||
|
|
d1a8995634 | ||
|
|
ab36fbaf48 | ||
|
|
ed9d1e7427 | ||
|
|
e3033c3975 | ||
|
|
417f5ed66d | ||
|
|
10c378cdfc | ||
|
|
db23a78c60 | ||
|
|
bda49826cf | ||
|
|
a31071573b | ||
|
|
6b05f711fd | ||
|
|
86ebb3bc11 | ||
|
|
7e7f3adb80 | ||
|
|
dfe6f9ebca | ||
|
|
37952fb3b8 | ||
|
|
0a811e8ea1 | ||
|
|
82f46a73f8 | ||
|
|
a6a16cf8a2 | ||
|
|
e887098740 | ||
|
|
f934719fbf | ||
|
|
ce3fe4078a | ||
|
|
f2f843c113 | ||
|
|
adc0027912 | ||
|
|
dee5bf3ec3 | ||
|
|
ac06ad7b48 | ||
|
|
4739af2d51 | ||
|
|
b065713cec | ||
|
|
fb308c14ce | ||
|
|
ac261203a5 | ||
|
|
0453ae96e8 | ||
|
|
a5fd597be3 | ||
|
|
382b99c334 | ||
|
|
2d131ef5b7 | ||
|
|
a1e05521e9 | ||
|
|
6b61e60e22 | ||
|
|
d7b40ab9a9 | ||
|
|
ac88294b4a | ||
|
|
ea1c04f7ab | ||
|
|
cdb046ac3f | ||
|
|
97939e6837 | ||
|
|
c91b03060d | ||
|
|
a2eb6d99ed | ||
|
|
a2916923a1 | ||
|
|
2cbdb7a337 | ||
|
|
d4783bd553 | ||
|
|
329c5a6b3b | ||
|
|
ce855cada2 | ||
|
|
39e7bf5a08 | ||
|
|
0e318a5182 | ||
|
|
19753a30d8 | ||
|
|
6fb74f38af | ||
|
|
4b80d409e7 | ||
|
|
ed4dd679f1 | ||
|
|
3cd8683061 | ||
|
|
bbd0af7256 | ||
|
|
f83a378d62 | ||
|
|
84b4b35902 | ||
|
|
2dc64f99bc | ||
|
|
5da7eb0a84 | ||
|
|
d55608a5bb | ||
|
|
f678c91617 | ||
|
|
6ce4b44547 | ||
|
|
f08b33fd0c | ||
|
|
b444694b3d | ||
|
|
24677c561e | ||
|
|
01a4ad3a50 | ||
|
|
f4ed421a88 | ||
|
|
11de9df44c | ||
|
|
c2565fe642 | ||
|
|
95bd1577d6 | ||
|
|
bbcc83e999 | ||
|
|
dd17495a42 | ||
|
|
1870a779e1 | ||
|
|
a9bd173d89 | ||
|
|
bccec3eabc | ||
|
|
d946c6932b | ||
|
|
4d38508c6b | ||
|
|
c0e6580b62 | ||
|
|
6985925244 | ||
|
|
7cb0baeb77 | ||
|
|
49df3116bc | ||
|
|
03a0b00a34 | ||
|
|
4a61188322 | ||
|
|
f5f6ca07be | ||
|
|
b1bcb12a62 | ||
|
|
dac07199cf | ||
|
|
45866bea47 | ||
|
|
65ebca8157 | ||
|
|
9e9fdc97bb | ||
|
|
02e9b8cacd | ||
|
|
fc5e421cb9 | ||
|
|
39d1be05e8 | ||
|
|
b7bdea3215 | ||
|
|
757fd2f57b | ||
|
|
bf10275aa7 | ||
|
|
0867f6113a | ||
|
|
836278db6c | ||
|
|
505bc9a312 | ||
|
|
07acc8bc87 | ||
|
|
6603cdef98 | ||
|
|
9df0d38d45 | ||
|
|
2ac782fbed | ||
|
|
9fedea83f0 | ||
|
|
ed4cffece7 | ||
|
|
7be8076e9b | ||
|
|
587c4cb87b | ||
|
|
aab17456a7 | ||
|
|
fe5c5298a6 | ||
|
|
3c78afbbbb | ||
|
|
64f88934a7 | ||
|
|
54a865e472 | ||
|
|
b003a85143 | ||
|
|
689f837afa | ||
|
|
97075fae4b | ||
|
|
bd3c925680 | ||
|
|
b62cf3894b | ||
|
|
148bd34a7e | ||
|
|
e9eb04ea95 | ||
|
|
8d8892ce0e | ||
|
|
ed2e5dd0f0 | ||
|
|
59183cf782 | ||
|
|
59780020f6 | ||
|
|
0b82487fed | ||
|
|
51f590a2a8 | ||
|
|
6c754ed2cb | ||
|
|
79411a0405 | ||
|
|
6b1776a7d2 | ||
|
|
38f5e5a0b8 | ||
|
|
697b6886e3 | ||
|
|
8314fc3e5a | ||
|
|
50b488765f | ||
|
|
e05bd9deb9 | ||
|
|
4af77622d9 | ||
|
|
2315b9f33d | ||
|
|
04dfcd838b | ||
|
|
2d957152e4 | ||
|
|
325563a982 | ||
|
|
763db046fa | ||
|
|
3a26b640b2 | ||
|
|
386ce49c58 | ||
|
|
b2c3e37d55 | ||
|
|
9700846bb3 | ||
|
|
0b4967992a | ||
|
|
20d8bcb600 | ||
|
|
358d3912c9 | ||
|
|
4d1ba782ee | ||
|
|
0500e546b5 | ||
|
|
7fc3092870 | ||
|
|
b724f940d6 | ||
|
|
4252275c64 | ||
|
|
6abe65aac6 | ||
|
|
f4c2f50896 | ||
|
|
27cacb0e30 | ||
|
|
709be8c495 | ||
|
|
994ca12b29 | ||
|
|
6464276b62 | ||
|
|
16772365e2 | ||
|
|
8957b3df03 | ||
|
|
60d7fb207e | ||
|
|
4a2e3cce69 | ||
|
|
fd752d8357 | ||
|
|
d02c645e38 | ||
|
|
49ee151ed6 | ||
|
|
b76ab6232d | ||
|
|
6dbda97fee | ||
|
|
90743d3112 | ||
|
|
14a500a476 | ||
|
|
6cc99a6e2b | ||
|
|
a103826154 | ||
|
|
0db591935f | ||
|
|
80f8298769 | ||
|
|
1fbab15c0a | ||
|
|
7546f1eb16 | ||
|
|
5220c14f4b | ||
|
|
8f63c3691d | ||
|
|
378cb85bf0 | ||
|
|
5aa7d61139 | ||
|
|
03a9946a14 | ||
|
|
decb5cdf10 | ||
|
|
5dd56d4bb5 | ||
|
|
512982d0d2 | ||
|
|
9e6b888626 | ||
|
|
83fa0ae263 | ||
|
|
e92820db2a | ||
|
|
6f8bdb7bf7 | ||
|
|
aeaaee8090 | ||
|
|
ca166c0e5f | ||
|
|
41765fbda7 | ||
|
|
ba84d2d372 | ||
|
|
11acd9f5cb | ||
|
|
238651ffa3 | ||
|
|
14e0c70f88 | ||
|
|
ef022c5e0a | ||
|
|
c40226e9de | ||
|
|
650eca386e | ||
|
|
934c6a5f5e | ||
|
|
848da73a81 | ||
|
|
8a15a1064d | ||
|
|
dd5c604768 | ||
|
|
2b415e642b | ||
|
|
68a91d3060 | ||
|
|
0666da6a72 | ||
|
|
7dec6b6de8 | ||
|
|
33dfa7f834 | ||
|
|
46f0e2e247 | ||
|
|
f6e0953b38 | ||
|
|
14b4d8a625 | ||
|
|
dbee23e09c | ||
|
|
2000008b47 | ||
|
|
352a7f101a | ||
|
|
37b7a7a9df | ||
|
|
b5ccee78b6 | ||
|
|
221bac8b06 | ||
|
|
05481194b6 | ||
|
|
e8281fdf1a | ||
|
|
f7fbe5bd91 | ||
|
|
c234426f89 | ||
|
|
3fecb234c8 | ||
|
|
ad769352ea | ||
|
|
0653a0d42a | ||
|
|
635a5c0a12 | ||
|
|
b8a1f74fd9 | ||
|
|
6ded5230d0 | ||
|
|
2a1b69f057 | ||
|
|
e118ea06e0 | ||
|
|
f921abe7e7 | ||
|
|
7609963448 | ||
|
|
d763944e9e | ||
|
|
ff673d31df | ||
|
|
acdaaef625 | ||
|
|
3d79353e45 | ||
|
|
fbe973a8d0 | ||
|
|
eaa32bb787 | ||
|
|
9f2b3bcf7a | ||
|
|
3fb22b836b | ||
|
|
041cdddf35 | ||
|
|
a8bf659143 | ||
|
|
9c33672e5c | ||
|
|
42f28ba305 | ||
|
|
291787bcac | ||
|
|
d67c66c437 | ||
|
|
7b365fa6b4 | ||
|
|
87262dd07a | ||
|
|
8ed10d538e | ||
|
|
943fcc4f10 | ||
|
|
9f30044333 | ||
|
|
fd9873a5c2 | ||
|
|
c71b2a1fe6 | ||
|
|
5fe48b6a0e | ||
|
|
1bcc23ef12 | ||
|
|
524f01d248 | ||
|
|
226f62fa8f | ||
|
|
ea83628438 | ||
|
|
76860017d5 | ||
|
|
4b8e41cffb | ||
|
|
a9ca61a7ce | ||
|
|
913a3c6056 | ||
|
|
921842e8a1 | ||
|
|
7a49ad6f5a | ||
|
|
f58378711f | ||
|
|
10ebda0b5e | ||
|
|
91ce8ccdbc | ||
|
|
d6d5580099 | ||
|
|
a6598f6fdb | ||
|
|
5166bec5d8 | ||
|
|
6cc7787c77 | ||
|
|
960aff24fc | ||
|
|
8306e32495 | ||
|
|
63e9fbc265 | ||
|
|
814c6a194b | ||
|
|
ab6c9d9b12 | ||
|
|
d12b1a938e | ||
|
|
c91bcea7a8 | ||
|
|
c6e54c7ab5 | ||
|
|
be2cfc26c9 | ||
|
|
08c777aeaa | ||
|
|
2a08c87b8c | ||
|
|
d1cf58e590 | ||
|
|
e1217227b2 | ||
|
|
7250fbde2e | ||
|
|
a117055b6b | ||
|
|
b015acc464 | ||
|
|
3050f653cb | ||
|
|
fb06d32844 | ||
|
|
66bb8add73 | ||
|
|
3aba95060e | ||
|
|
cb3b7ff4fb | ||
|
|
d448045669 | ||
|
|
f21307e5c9 | ||
|
|
42b7704b70 | ||
|
|
3803203d47 | ||
|
|
8c0b410371 | ||
|
|
8b86c939c7 | ||
|
|
b933599f00 | ||
|
|
12223cc3e9 | ||
|
|
ea122de913 | ||
|
|
14dfd5bf6b | ||
|
|
5dde06b327 | ||
|
|
f89ef40cb2 | ||
|
|
c389a9528f | ||
|
|
9eebd37b59 | ||
|
|
7038e71ae2 | ||
|
|
21d3299e58 | ||
|
|
d7598aa84f | ||
|
|
5b5d5b049d | ||
|
|
66e08b6575 | ||
|
|
9a6eb0ab25 | ||
|
|
a1dfaf4869 | ||
|
|
7143d711bf | ||
|
|
0d08927dae | ||
|
|
791ad9b82d | ||
|
|
f64c7c37ef | ||
|
|
d1c5a66557 | ||
|
|
f5384544cb | ||
|
|
fedf227ea4 | ||
|
|
7a02f4b545 | ||
|
|
ca9b7b4071 | ||
|
|
1566c96ccd | ||
|
|
3389dfd9dd | ||
|
|
84a9d532b6 | ||
|
|
ca46e5d959 | ||
|
|
9ce41a92c3 | ||
|
|
43a90adc61 | ||
|
|
8103582b65 | ||
|
|
cab7088c85 | ||
|
|
7b3ad4a282 | ||
|
|
4ce188def8 | ||
|
|
b467a0466c | ||
|
|
69a501df6e | ||
|
|
1dc1964d5b | ||
|
|
f106ccd5fa | ||
|
|
01a4cff8f9 | ||
|
|
00dfb3c896 | ||
|
|
25158fe33b | ||
|
|
960921f03a | ||
|
|
922a11f084 | ||
|
|
396b33d0d0 | ||
|
|
b7b8f52437 | ||
|
|
05581da183 | ||
|
|
f006400f05 | ||
|
|
cde6ad3967 | ||
|
|
73dd0e869d | ||
|
|
55ad3b4abd | ||
|
|
d1de937c31 | ||
|
|
d365417e8b | ||
|
|
0ff810038d | ||
|
|
9055c9ed22 | ||
|
|
d87650dffb | ||
|
|
0a4783309d | ||
|
|
26f7b2f5aa | ||
|
|
a5dffbec38 | ||
|
|
22ffa3d6d3 | ||
|
|
683f9160b9 | ||
|
|
4e7c05504a | ||
|
|
99bca397d8 | ||
|
|
dc48a7c88e | ||
|
|
9ca7ea00c8 | ||
|
|
4dac00ca0c | ||
|
|
fc89c61089 | ||
|
|
1e7d2adc29 | ||
|
|
bd6f48fe20 | ||
|
|
0d2dd30ee9 | ||
|
|
9971251574 | ||
|
|
a07b2828ce | ||
|
|
9a4fd69f6d | ||
|
|
cf64b7fa72 | ||
|
|
a726bded11 | ||
|
|
7f78f52243 | ||
|
|
60f8b0733c | ||
|
|
6327b63064 | ||
|
|
fa4b47c5e2 | ||
|
|
a7ecbcdeba | ||
|
|
ded52c71d9 | ||
|
|
9d4fafa671 | ||
|
|
8e67fe13a5 | ||
|
|
e2c49530cb | ||
|
|
fee06a92ea | ||
|
|
d71091a957 | ||
|
|
d1e262ad55 | ||
|
|
6e0ee6ff03 | ||
|
|
42e91c3155 | ||
|
|
d27dce58cd | ||
|
|
87b193399e | ||
|
|
962cc2381d | ||
|
|
bfe137893a | ||
|
|
620a33dd85 | ||
|
|
47766ca403 | ||
|
|
7c6febed66 | ||
|
|
1a62292ac0 | ||
|
|
2026e3db88 | ||
|
|
3ff8c466bf | ||
|
|
1f54665799 | ||
|
|
ae873b1e0d | ||
|
|
9c75ef5a61 | ||
|
|
c36162fc6c | ||
|
|
f0699effed | ||
|
|
75db81cf08 | ||
|
|
fd887f5241 | ||
|
|
285e3042ba | ||
|
|
772cbfd014 | ||
|
|
d981b33dd0 | ||
|
|
e768f91dc2 | ||
|
|
3fef0d553d | ||
|
|
3a45bae9dc | ||
|
|
98636f4a23 | ||
|
|
5f82275ba1 | ||
|
|
136d067eed | ||
|
|
324cea1f41 | ||
|
|
ee48fad09d | ||
|
|
3912b3d9a9 | ||
|
|
6d910d5487 | ||
|
|
26ff93dadc | ||
|
|
a484fd2b56 | ||
|
|
8ff7f35eec | ||
|
|
e8448d0494 | ||
|
|
4ab86e1d61 | ||
|
|
0faa0dba15 | ||
|
|
db6b8e0fb3 | ||
|
|
1f16ca5e5c | ||
|
|
b4a3d423e0 | ||
|
|
68894d4149 | ||
|
|
eae6e96287 | ||
|
|
5e462eb29b | ||
|
|
23bd697f05 | ||
|
|
37f9153105 | ||
|
|
81e01ddebe | ||
|
|
405c802607 | ||
|
|
91b5256c57 | ||
|
|
6ae32c696a | ||
|
|
9afc62d087 | ||
|
|
93eb459ae1 | ||
|
|
c3835de38a | ||
|
|
52caa2f38a | ||
|
|
04af1a3917 | ||
|
|
e1f9b8b3a7 | ||
|
|
cfb48969af | ||
|
|
0cf5b93a0a | ||
|
|
d99baf332c | ||
|
|
7e919a543c | ||
|
|
eb19a77848 | ||
|
|
219ba3b617 | ||
|
|
ae1d278f3a | ||
|
|
b885382a63 | ||
|
|
9e15ebb402 | ||
|
|
4fa59df9fa | ||
|
|
f145b0cffd | ||
|
|
a6645e1007 | ||
|
|
c254db7637 | ||
|
|
5a0c67c4b8 | ||
|
|
ec6219752d | ||
|
|
d246850787 | ||
|
|
e60e5bff63 | ||
|
|
873fe34b31 | ||
|
|
e3979c2098 | ||
|
|
707ddd54b6 | ||
|
|
68a44776bd | ||
|
|
613cfaf0b4 | ||
|
|
891dd2d31e | ||
|
|
d4c156a0f0 | ||
|
|
de917ebb95 | ||
|
|
501e0adcdb | ||
|
|
a2544f9496 | ||
|
|
b51f6e073c | ||
|
|
52e9d94f93 | ||
|
|
fc262355ca | ||
|
|
7537ba2b44 | ||
|
|
86daa8930e | ||
|
|
3109131a88 | ||
|
|
635eb1d8e9 | ||
|
|
bd0e2036e0 | ||
|
|
b0d3c3a674 | ||
|
|
dacd080639 | ||
|
|
8e2e87d638 | ||
|
|
e389502ffb | ||
|
|
1c3a60047c | ||
|
|
62162747e7 | ||
|
|
189d8c9d9c | ||
|
|
f45adb995c | ||
|
|
7954d6782e | ||
|
|
59db6ceeb1 | ||
|
|
a0bfbe4d8f | ||
|
|
42015f7194 | ||
|
|
e674f57bb6 | ||
|
|
ff45cb5929 | ||
|
|
1897248bda | ||
|
|
051a31594f | ||
|
|
dc6e0f4b9e | ||
|
|
df3f2fff88 | ||
|
|
8e5e79054e | ||
|
|
3cc8b470a6 | ||
|
|
f1becf7e4b | ||
|
|
a3546b52f8 | ||
|
|
823ccc274e | ||
|
|
ff672b2db3 | ||
|
|
778aed9966 | ||
|
|
c5b2a848fa | ||
|
|
d0e3b1d4e2 | ||
|
|
505ff536f9 | ||
|
|
db577cd445 | ||
|
|
1d942eb6c9 | ||
|
|
149587b85b | ||
|
|
670a92723a | ||
|
|
130c3e6b75 | ||
|
|
3c578fa87e | ||
|
|
8df962a6ed | ||
|
|
2a194e21a0 | ||
|
|
9753c741b9 | ||
|
|
7c483a0eba | ||
|
|
0ba9fedf1a | ||
|
|
2c54b15a5f | ||
|
|
2a229c8cb8 | ||
|
|
40f9e4e8e2 | ||
|
|
245e12cca7 | ||
|
|
8019d39545 | ||
|
|
a1632c6116 | ||
|
|
95e047244e | ||
|
|
c72d0b2cbb | ||
|
|
e6125361f9 | ||
|
|
b7e45b3a48 | ||
|
|
6add99f8d2 | ||
|
|
750c5d2a61 | ||
|
|
e571ccf3f4 | ||
|
|
05531f898e | ||
|
|
b8573a7e33 | ||
|
|
bc5da9b367 | ||
|
|
b3dab0a406 | ||
|
|
2a022d997b | ||
|
|
5870b979a8 | ||
|
|
a47064966b | ||
|
|
bdb8243602 | ||
|
|
b46f099a3f | ||
|
|
63bfad401f | ||
|
|
e11b7a0414 | ||
|
|
28dabdcb9e | ||
|
|
065f9e0269 | ||
|
|
4b1f5aba80 | ||
|
|
71447b94fb | ||
|
|
3dc511c71d | ||
|
|
36de604a5b | ||
|
|
aa9f6db698 | ||
|
|
2a5e9a15e4 | ||
|
|
d7fec5e1d3 | ||
|
|
7d8d587bc0 | ||
|
|
e1b27ce51e | ||
|
|
e7d2d636af | ||
|
|
9a5d5c45f5 | ||
|
|
25e5baf5f0 | ||
|
|
c8db91b7b4 | ||
|
|
94ed5b1408 | ||
|
|
702cc9993a | ||
|
|
96ad003000 | ||
|
|
28ed29078b | ||
|
|
2c49902159 | ||
|
|
f9571ce4d3 | ||
|
|
bad5ee167b | ||
|
|
b6e277980f | ||
|
|
878c863af4 | ||
|
|
9be4f150ef | ||
|
|
8d9c903919 | ||
|
|
00251c8921 | ||
|
|
8de97d14d8 | ||
|
|
5af650fc6d | ||
|
|
2b770a029b | ||
|
|
bee2720faa | ||
|
|
cab82d9c76 | ||
|
|
fd0873c61f | ||
|
|
ee3d16f150 | ||
|
|
4b858cf5d1 | ||
|
|
09e15e8c9d | ||
|
|
2128e2f44b | ||
|
|
8f3f428228 | ||
|
|
f6754fd812 | ||
|
|
27a9374ef3 | ||
|
|
1cdec11e24 | ||
|
|
3ac624b795 | ||
|
|
a97b0c32ab | ||
|
|
bcf722e637 | ||
|
|
a0a6639fb5 | ||
|
|
0f7f6284d7 | ||
|
|
8c22b8aef6 | ||
|
|
fc4105c8a8 | ||
|
|
ea564a6a5e | ||
|
|
9809b0b061 | ||
|
|
b987970870 | ||
|
|
6fd4cf8e49 | ||
|
|
3563f1e270 | ||
|
|
e7aa0dec5b | ||
|
|
50a8bb2711 | ||
|
|
a3d6e82dbd | ||
|
|
b4514ce64a | ||
|
|
3dafd9e898 | ||
|
|
5cd83e689e | ||
|
|
bd9a37bc60 | ||
|
|
778aadca65 | ||
|
|
1aa91ac426 | ||
|
|
5ce903af6e | ||
|
|
bab3ebec14 | ||
|
|
3ff195f702 | ||
|
|
e459e5bf0a | ||
|
|
217bc445ff | ||
|
|
1f020e526a | ||
|
|
bad3c14ff6 | ||
|
|
1c87024840 | ||
|
|
e4e3c2cc23 | ||
|
|
f3e85310e7 | ||
|
|
3470e6112b | ||
|
|
e312b99296 | ||
|
|
cc0a6690bf | ||
|
|
5fe962216a | ||
|
|
01686c6294 | ||
|
|
bf2e0b2c6f | ||
|
|
3d937beb62 | ||
|
|
15c88c4941 | ||
|
|
cee40f8af9 | ||
|
|
940627d008 | ||
|
|
28837ec642 | ||
|
|
719ea9c228 | ||
|
|
e285ecca09 | ||
|
|
f61a7ef222 | ||
|
|
e06b5dfe12 | ||
|
|
e1aea42e45 | ||
|
|
82e9a5e47d | ||
|
|
5f6eaa5278 | ||
|
|
8a0888c763 | ||
|
|
e639ff392c | ||
|
|
d701ffb478 | ||
|
|
a00e517a81 | ||
|
|
8868ad67e4 | ||
|
|
301e652376 | ||
|
|
5a66d8fd57 | ||
|
|
a1c0836bec | ||
|
|
dfe308bc53 | ||
|
|
dc0198a7e4 | ||
|
|
ef6fe2ecee | ||
|
|
46e6382b69 | ||
|
|
087fbf08f6 | ||
|
|
1ad9de5aae | ||
|
|
aa9476a38a | ||
|
|
d4f722d5b2 | ||
|
|
3dd51651e3 | ||
|
|
16b2d20115 | ||
|
|
8ccff82153 | ||
|
|
0e7cd694eb | ||
|
|
03f3c8d385 | ||
|
|
bf75bfec48 |
6
.github/pull_request_template.md
vendored
6
.github/pull_request_template.md
vendored
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
1. PLEASE CAREFULLY READ: [Contributing Guidelines](https://github.com/ocornut/imgui/blob/master/docs/CONTRIBUTING.md)
|
1. PLEASE CAREFULLY READ: [Contributing Guidelines](https://github.com/ocornut/imgui/blob/master/docs/CONTRIBUTING.md)
|
||||||
|
|
||||||
2. Make sure you're using a special branch just for this pull request. (Sometimes people unknowingly use a default branch, then later update that branch, which updates the pull request with the other changes if it hasn't been merged yet.)
|
2. **Make sure you're using a special branch just for this pull request**. (In git, 1 PR = 1 branch. If you update the branch the PR will be updated.)
|
||||||
|
|
||||||
3. Clear this template before submitting your PR.
|
3. Consider running the [imgui_test_suite](https://github.com/ocornut/imgui_test_engine) or adding new tests to test for expected behaviors.
|
||||||
|
|
||||||
|
4. Clear this template before submitting your PR.
|
||||||
|
|
||||||
|
|||||||
278
.github/workflows/build.yml
vendored
278
.github/workflows/build.yml
vendored
@@ -16,14 +16,24 @@ on:
|
|||||||
- requested
|
- requested
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Windows:
|
Build-Windows:
|
||||||
runs-on: windows-2025
|
runs-on: windows-2025
|
||||||
env:
|
name: Build - Windows
|
||||||
VS_PATH: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\
|
|
||||||
MSBUILD_PATH: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
|
env:
|
||||||
|
VS_PATH: C:\Program Files\Microsoft Visual Studio\18\Enterprise
|
||||||
|
MSBUILD_PATH: C:\Program Files\Microsoft Visual Studio\18\Enterprise\MSBuild\Current\Bin\
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
path: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
|
# The VulkanSDK libs for Windows is manually generated using build_windows_vulkan_libs.ps1 + attached to issue #8925.
|
||||||
|
# (we have a .yml workflow in commit history if it becomes ever useful to create this on CI too)
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
@@ -35,20 +45,9 @@ jobs:
|
|||||||
Expand-Archive -Path SDL3-devel-3.2.18-VC.zip
|
Expand-Archive -Path SDL3-devel-3.2.18-VC.zip
|
||||||
echo "SDL3_DIR=$(pwd)\SDL3-devel-3.2.18-VC\SDL3-3.2.18\" >>${env:GITHUB_ENV}
|
echo "SDL3_DIR=$(pwd)\SDL3-devel-3.2.18-VC\SDL3-3.2.18\" >>${env:GITHUB_ENV}
|
||||||
|
|
||||||
# VulkanSDK (retrieve minimal bits of the SDK from git)
|
Invoke-WebRequest -Uri "https://github.com/user-attachments/files/22464296/vulkan_windows_libs_1.4.326.zip" -OutFile vulkan_windows_libs_1.4.326.zip
|
||||||
$vulkanVersion = "1.4.326"
|
Expand-Archive -Path vulkan_windows_libs_1.4.326.zip
|
||||||
# 1. Get the vulkan headers, we will treat that folder as the sdk folder to avoid having to copy headers around
|
echo "VULKAN_SDK=$(pwd)\vulkan_windows_libs_1.4.326\" >>${env:GITHUB_ENV}
|
||||||
Invoke-WebRequest -Uri "https://github.com/KhronosGroup/Vulkan-Headers/archive/refs/tags/v$($vulkanVersion).zip" -OutFile Vulkan-Headers-$($vulkanVersion).zip
|
|
||||||
Expand-Archive -Path Vulkan-Headers-$($vulkanVersion).zip
|
|
||||||
echo "VULKAN_SDK=$(pwd)\Vulkan-Headers-$($vulkanVersion)\Vulkan-Headers-$($vulkanVersion)" >>${env:GITHUB_ENV}
|
|
||||||
# 2. Get and build the vulkan loader source code (UPDATE_DEPS=On will make it automatically fetch its dependencies)
|
|
||||||
Invoke-WebRequest -Uri "https://github.com/KhronosGroup/Vulkan-Loader/archive/refs/tags/v$($vulkanVersion).zip" -OutFile Vulkan-Loader-$($vulkanVersion).zip
|
|
||||||
Expand-Archive -Path Vulkan-Loader-$($vulkanVersion).zip
|
|
||||||
cmake -S Vulkan-Loader-$($vulkanVersion)\Vulkan-Loader-$($vulkanVersion) -B VulkanLoader-build -D UPDATE_DEPS=On
|
|
||||||
cmake --build VulkanLoader-build
|
|
||||||
# 3. Copy the built lib/dll to the expected place
|
|
||||||
mkdir Vulkan-Headers-$($vulkanVersion)\Vulkan-Headers-$($vulkanVersion)\Lib
|
|
||||||
copy VulkanLoader-build\loader\Debug\vulkan-1.* Vulkan-Headers-$($vulkanVersion)\Vulkan-Headers-$($vulkanVersion)\Lib\
|
|
||||||
|
|
||||||
- name: Fix Projects
|
- name: Fix Projects
|
||||||
shell: powershell
|
shell: powershell
|
||||||
@@ -70,7 +69,7 @@ jobs:
|
|||||||
echo '#define IMGUI_IMPLEMENTATION' >> 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
|
echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp
|
||||||
g++ -I. -Wall -Wformat -shared -o libimgui.dll -Wl,--out-implib,libimgui.a example_single_file.cpp -limm32
|
g++ -I. -Wall -Wformat -shared -o libimgui.dll -Wl,--out-implib,libimgui.a example_single_file.cpp -limm32
|
||||||
g++ -I. -Wall -Wformat -DIMGUI_API='__declspec(dllimport)' -o example_null.exe examples/example_null/main.cpp -L. -limgui
|
g++ -I. -Wall -Wformat -DIMGUI_API='__declspec(dllimport)' -DIMGUI_IMPL_API= -o example_null.exe examples/example_null/main.cpp -L. -limgui
|
||||||
rm -f example_null.exe libimgui.* example_single_file.*
|
rm -f example_null.exe libimgui.* example_single_file.*
|
||||||
|
|
||||||
- name: Build example_null (extra warnings, msvc 64-bit)
|
- name: Build example_null (extra warnings, msvc 64-bit)
|
||||||
@@ -115,9 +114,9 @@ jobs:
|
|||||||
echo #include "misc/single_file/imgui_single_file.h" >> example_single_file.cpp
|
echo #include "misc/single_file/imgui_single_file.h" >> example_single_file.cpp
|
||||||
|
|
||||||
cl.exe /D_USRDLL /D_WINDLL /I. example_single_file.cpp /LD /FeImGui.dll /link
|
cl.exe /D_USRDLL /D_WINDLL /I. example_single_file.cpp /LD /FeImGui.dll /link
|
||||||
cl.exe /DIMGUI_API=__declspec(dllimport) /I. ImGui.lib /Feexample_null.exe examples/example_null/main.cpp
|
cl.exe /DIMGUI_API=__declspec(dllimport) -DIMGUI_IMPL_API= /I. ImGui.lib /Feexample_null.exe examples/example_null/main.cpp
|
||||||
|
|
||||||
# Win64 examples are more frequently compilted than the Win32 examples.
|
# Win64 examples are more frequently compiled than the Win32 examples.
|
||||||
# More of the Win32 examples requires 'workflow_run' to reduce waste.
|
# More of the Win32 examples requires 'workflow_run' to reduce waste.
|
||||||
- name: Build Win32 example_glfw_opengl2
|
- name: Build Win32 example_glfw_opengl2
|
||||||
shell: cmd
|
shell: cmd
|
||||||
@@ -161,6 +160,7 @@ jobs:
|
|||||||
- name: Build Win32 example_sdl3_opengl3
|
- name: Build Win32 example_sdl3_opengl3
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl3_opengl3/example_sdl3_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl3_opengl3/example_sdl3_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release'
|
||||||
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build Win32 example_sdl3_sdlgpu3
|
- name: Build Win32 example_sdl3_sdlgpu3
|
||||||
shell: cmd
|
shell: cmd
|
||||||
@@ -201,6 +201,7 @@ jobs:
|
|||||||
- name: Build Win64 example_glfw_opengl3
|
- name: Build Win64 example_glfw_opengl3
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
||||||
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build Win64 example_glfw_vulkan
|
- name: Build Win64 example_glfw_vulkan
|
||||||
shell: cmd
|
shell: cmd
|
||||||
@@ -229,6 +230,7 @@ jobs:
|
|||||||
- name: Build Win64 example_sdl2_directx11
|
- name: Build Win64 example_sdl2_directx11
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
||||||
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build Win64 example_sdl3_opengl3
|
- name: Build Win64 example_sdl3_opengl3
|
||||||
shell: cmd
|
shell: cmd
|
||||||
@@ -266,10 +268,18 @@ jobs:
|
|||||||
shell: cmd
|
shell: cmd
|
||||||
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx12/example_win32_directx12.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx12/example_win32_directx12.vcxproj /p:Platform=x64 /p:Configuration=Release'
|
||||||
|
|
||||||
Linux:
|
Build-Linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
name: Build - Linux
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
path: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
@@ -336,7 +346,7 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
||||||
|
|
||||||
- name: Build example_null (with large ImDrawIdx + pointer ImTextureID)
|
- name: Build example_null (with large ImDrawIdx + custom ImTextureID)
|
||||||
run: |
|
run: |
|
||||||
cat > example_single_file.cpp <<'EOF'
|
cat > example_single_file.cpp <<'EOF'
|
||||||
|
|
||||||
@@ -349,6 +359,21 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
||||||
|
|
||||||
|
cat > example_single_file.cpp <<'EOF'
|
||||||
|
|
||||||
|
// Test build ImTextureID defined as a struct
|
||||||
|
struct SomeType { int a = 0; int b = 0; };
|
||||||
|
#define ImTextureID SomeType
|
||||||
|
#define ImTextureID_Invalid SomeType()
|
||||||
|
inline bool operator==(const SomeType& lhs, const SomeType& rhs) { return lhs.a == rhs.a && lhs.b == rhs.b; }
|
||||||
|
inline bool operator!=(const SomeType& lhs, const SomeType& rhs) { return lhs.a != rhs.a || lhs.b != rhs.b; }
|
||||||
|
#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)
|
- name: Build example_null (with IMGUI_DISABLE_OBSOLETE_FUNCTIONS)
|
||||||
run: |
|
run: |
|
||||||
cat > example_single_file.cpp <<'EOF'
|
cat > example_single_file.cpp <<'EOF'
|
||||||
@@ -483,10 +508,18 @@ jobs:
|
|||||||
- name: Build with IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
- 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
|
run: g++ -c -I. -std=c++11 -DIMGUI_IMPL_VULKAN_NO_PROTOTYPES=1 backends/imgui_impl_vulkan.cpp
|
||||||
|
|
||||||
MacOS:
|
Build-MacOS:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
|
name: Build - MacOS
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
path: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
@@ -495,7 +528,7 @@ jobs:
|
|||||||
- name: Build example_null (extra warnings, clang 64-bit)
|
- name: Build example_null (extra warnings, clang 64-bit)
|
||||||
run: make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
run: make -C examples/example_null WITH_EXTRA_WARNINGS=1
|
||||||
|
|
||||||
- name: Build example_null (single file build)
|
- name: Build macOS example_null (single file build)
|
||||||
run: |
|
run: |
|
||||||
cat > example_single_file.cpp <<'EOF'
|
cat > example_single_file.cpp <<'EOF'
|
||||||
|
|
||||||
@@ -506,7 +539,7 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
clang++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
clang++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
|
||||||
|
|
||||||
- name: Build example_null (single file build, c++20)
|
- name: Build macOS example_null (single file build, c++20)
|
||||||
run: |
|
run: |
|
||||||
cat > example_single_file.cpp <<'EOF'
|
cat > example_single_file.cpp <<'EOF'
|
||||||
|
|
||||||
@@ -517,7 +550,7 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
clang++ -I. -std=c++20 -Wall -Wformat -o example_single_file example_single_file.cpp
|
clang++ -I. -std=c++20 -Wall -Wformat -o example_single_file example_single_file.cpp
|
||||||
|
|
||||||
- name: Build example_null (without c++ runtime)
|
- name: Build macOS example_null (without c++ runtime)
|
||||||
run: |
|
run: |
|
||||||
cat > example_single_file.cpp <<'EOF'
|
cat > example_single_file.cpp <<'EOF'
|
||||||
|
|
||||||
@@ -528,49 +561,60 @@ jobs:
|
|||||||
EOF
|
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
|
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
|
- name: Build macOS example_glfw_opengl2
|
||||||
run: make -C examples/example_glfw_opengl2
|
run: make -C examples/example_glfw_opengl2
|
||||||
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build example_glfw_opengl3
|
- name: Build macOS example_glfw_opengl3
|
||||||
run: make -C examples/example_glfw_opengl3
|
run: make -C examples/example_glfw_opengl3
|
||||||
if: github.event_name == 'workflow_run'
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build example_glfw_metal
|
- name: Build macOS example_glfw_metal
|
||||||
run: make -C examples/example_glfw_metal
|
run: make -C examples/example_glfw_metal
|
||||||
|
|
||||||
- name: Build example_sdl2_metal
|
- name: Build macOS example_sdl2_metal
|
||||||
run: make -C examples/example_sdl2_metal
|
run: make -C examples/example_sdl2_metal
|
||||||
|
|
||||||
- name: Build example_sdl2_opengl2
|
- name: Build macOS example_sdl3_metal4
|
||||||
|
run: make -C examples/example_sdl3_metal4
|
||||||
|
|
||||||
|
- name: Build macOS example_sdl2_opengl2
|
||||||
run: make -C examples/example_sdl2_opengl2
|
run: make -C examples/example_sdl2_opengl2
|
||||||
if: github.event_name == 'workflow_run'
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build example_sdl2_opengl3
|
- name: Build macOS example_sdl2_opengl3
|
||||||
run: make -C examples/example_sdl2_opengl3
|
run: make -C examples/example_sdl2_opengl3
|
||||||
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build example_sdl3_opengl3
|
- name: Build macOS example_sdl3_opengl3
|
||||||
run: make -C examples/example_sdl3_opengl3
|
run: make -C examples/example_sdl3_opengl3
|
||||||
|
|
||||||
- name: Build example_apple_metal
|
- name: Build macOS example_apple_metal
|
||||||
run: xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_macos
|
run: xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_macos
|
||||||
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
- name: Build example_apple_opengl2
|
- name: Build macOS example_apple_opengl2
|
||||||
run: xcodebuild -project examples/example_apple_opengl2/example_apple_opengl2.xcodeproj -target example_osx_opengl2
|
run: xcodebuild -project examples/example_apple_opengl2/example_apple_opengl2.xcodeproj -target example_osx_opengl2
|
||||||
|
if: github.event_name == 'workflow_run'
|
||||||
|
|
||||||
iOS:
|
Build-iOS:
|
||||||
runs-on: macos-14
|
runs-on: macos-14
|
||||||
|
name: Build - iOS
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Build example_apple_metal
|
- name: Build example_apple_metal
|
||||||
run: |
|
run: |
|
||||||
# Code signing is required, but we disable it because it is irrelevant for CI builds.
|
# 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
|
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:
|
Build-Emscripten:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
name: Build - Emscripten
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
@@ -608,12 +652,152 @@ jobs:
|
|||||||
emcmake cmake -B build -DCMAKE_BUILD_TYPE=Release examples/example_glfw_wgpu
|
emcmake cmake -B build -DCMAKE_BUILD_TYPE=Release examples/example_glfw_wgpu
|
||||||
cmake --build build
|
cmake --build build
|
||||||
|
|
||||||
Android:
|
Build-Android:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
name: Build - Android
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
|
steps:
|
||||||
|
#- name: Setup Gradle
|
||||||
|
# uses: gradle/actions/setup-gradle@v6
|
||||||
|
# with:
|
||||||
|
# gradle-version: '8.14.5'
|
||||||
|
|
||||||
|
- uses: actions/checkout@v6
|
||||||
- name: Build example_android_opengl3
|
- name: Build example_android_opengl3
|
||||||
run: |
|
run: |
|
||||||
cd examples/example_android_opengl3/android
|
cd examples/example_android_opengl3/android
|
||||||
gradle assembleDebug --stacktrace
|
gradle assembleDebug --stacktrace
|
||||||
|
|
||||||
|
Test-Windows:
|
||||||
|
runs-on: windows-2025
|
||||||
|
name: Test - Windows
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
|
env:
|
||||||
|
MSBUILD_PATH: C:\Program Files\Microsoft Visual Studio\18\Enterprise\MSBuild\Current\Bin\
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
path: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
repository: ocornut/imgui_test_engine
|
||||||
|
path: ${{ github.workspace }}/imgui_test_engine
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Fix Tests Projects
|
||||||
|
shell: powershell
|
||||||
|
working-directory: ${{ github.workspace }}/imgui_test_engine
|
||||||
|
run: |
|
||||||
|
# WARNING: This will need updating if toolset/sdk change in project files!
|
||||||
|
gci -recurse -filter "*.vcxproj" | ForEach-Object {
|
||||||
|
# Fix SDK and toolset for most samples.
|
||||||
|
(Get-Content $_.FullName) -Replace "<PlatformToolset>v110</PlatformToolset>","<PlatformToolset>v142</PlatformToolset>" | Set-Content -Path $_.FullName
|
||||||
|
(Get-Content $_.FullName) -Replace "<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>","<WindowsTargetPlatformVersion>10.0.20348.0</WindowsTargetPlatformVersion>" | Set-Content -Path $_.FullName
|
||||||
|
# Fix SDK and toolset for samples that require newer SDK/toolset. At the moment it is only dx12.
|
||||||
|
(Get-Content $_.FullName) -Replace "<PlatformToolset>v140</PlatformToolset>","<PlatformToolset>v142</PlatformToolset>" | Set-Content -Path $_.FullName
|
||||||
|
(Get-Content $_.FullName) -Replace "<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>","<WindowsTargetPlatformVersion>10.0.20348.0</WindowsTargetPlatformVersion>" | Set-Content -Path $_.FullName
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Build Tests
|
||||||
|
shell: cmd
|
||||||
|
working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
run: '"%MSBUILD_PATH%\MSBuild.exe" imgui_test_suite.vcxproj /p:Platform=x64 /p:Configuration=Release /p:ClFlags=/WX -maxcpucount:%NUMBER_OF_PROCESSORS%'
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
run: Release/imgui_test_suite.exe -nogui -nopause -v2 -ve4 tests
|
||||||
|
|
||||||
|
- name: Check for Docking
|
||||||
|
id: check_docking
|
||||||
|
shell: bash
|
||||||
|
working-directory: ${{ github.workspace }}/imgui
|
||||||
|
run: echo "has_dock=$(grep -q "#define IMGUI_HAS_DOCK" imgui.h && echo true || echo false)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Run Viewport Tests
|
||||||
|
if: steps.check_docking.outputs.has_dock == 'true'
|
||||||
|
working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
run: Release/imgui_test_suite.exe -nogui -nopause -v2 -ve4 -viewport-mock viewport
|
||||||
|
|
||||||
|
Test-Linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Test - Linux
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
path: ${{ github.workspace }}/imgui
|
||||||
|
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
repository: ocornut/imgui_test_engine
|
||||||
|
path: ${{ github.workspace }}/imgui_test_engine
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Build Tests
|
||||||
|
working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
run: make -j$(nproc)
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
run: ./imgui_test_suite -nogui -nopause -v2 -ve4 tests
|
||||||
|
|
||||||
|
- name: Check for Docking
|
||||||
|
id: check_docking
|
||||||
|
working-directory: ${{ github.workspace }}/imgui
|
||||||
|
run: echo "has_dock=$(grep -q "#define IMGUI_HAS_DOCK" imgui.h && echo true || echo false)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Run Viewport Tests
|
||||||
|
if: steps.check_docking.outputs.has_dock == 'true'
|
||||||
|
working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
run: ./imgui_test_suite -nogui -nopause -v2 -ve4 -viewport-mock viewport
|
||||||
|
|
||||||
|
# Test-MacOS:
|
||||||
|
# runs-on: macos-latest
|
||||||
|
# name: Test - MacOS
|
||||||
|
#
|
||||||
|
# defaults:
|
||||||
|
# run:
|
||||||
|
# working-directory: ${{ github.workspace }}/imgui
|
||||||
|
#
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v6
|
||||||
|
# with:
|
||||||
|
# path: ${{ github.workspace }}/imgui
|
||||||
|
#
|
||||||
|
# - uses: actions/checkout@v6
|
||||||
|
# with:
|
||||||
|
# fetch-depth: 1
|
||||||
|
# repository: ocornut/imgui_test_engine
|
||||||
|
# path: ${{ github.workspace }}/imgui_test_engine
|
||||||
|
# submodules: true
|
||||||
|
#
|
||||||
|
# - name: Build Tests
|
||||||
|
# working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
# run: make -j$(nproc)
|
||||||
|
#
|
||||||
|
# - name: Run Tests
|
||||||
|
# working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
# run: ./imgui_test_suite -nogui -nopause -v2 -ve4 tests
|
||||||
|
#
|
||||||
|
# - name: Check for Docking
|
||||||
|
# id: check_docking
|
||||||
|
# working-directory: ${{ github.workspace }}/imgui
|
||||||
|
# run: echo "has_dock=$(grep -q "#define IMGUI_HAS_DOCK" imgui.h && echo true || echo false)" >> $GITHUB_OUTPUT
|
||||||
|
#
|
||||||
|
# - name: Run Viewport Tests
|
||||||
|
# if: steps.check_docking.outputs.has_dock == 'true'
|
||||||
|
# working-directory: ${{ github.workspace }}/imgui_test_engine/imgui_test_suite
|
||||||
|
# run: ./imgui_test_suite -nogui -nopause -v2 -ve4 -viewport-mock viewport
|
||||||
|
|||||||
38
.github/workflows/build_windows_vulkan_libs.ps1
vendored
Normal file
38
.github/workflows/build_windows_vulkan_libs.ps1
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# This is current meant to be run manually, occasionally:
|
||||||
|
# - Run then zip the contents of vulkanArtifact/ into e.g. vulkan_windows_libs_1.4.326
|
||||||
|
# - Upload as an attachment to https://github.com/ocornut/imgui/pull/8925 then change filename in build.yml
|
||||||
|
# - There is a build_windows_vulkan_libs.yml in commit history that we removed thinking this is run so rarely we don't need to pollute CI UI with it.
|
||||||
|
|
||||||
|
# Set default vulkan version if none provided
|
||||||
|
if (-not $env:VULKAN_TAG) { $env:VULKAN_TAG = "1.4.326" }
|
||||||
|
|
||||||
|
# Create output folder
|
||||||
|
mkdir vulkanArtifact
|
||||||
|
|
||||||
|
# Download Vulkan Headers
|
||||||
|
|
||||||
|
Invoke-WebRequest -Uri "https://github.com/KhronosGroup/Vulkan-Headers/archive/refs/tags/v$($env:VULKAN_TAG).zip" -OutFile Vulkan-Headers-$($env:VULKAN_TAG).zip
|
||||||
|
Expand-Archive -Path Vulkan-Headers-$($env:VULKAN_TAG).zip
|
||||||
|
|
||||||
|
# Copy Vulkan Headers to artifact folder
|
||||||
|
|
||||||
|
cp -R Vulkan-Headers-$($env:VULKAN_TAG)\Vulkan-Headers-$($env:VULKAN_TAG)\include vulkanArtifact\Include
|
||||||
|
|
||||||
|
# Download Vulkan Loader
|
||||||
|
|
||||||
|
Invoke-WebRequest -Uri "https://github.com/KhronosGroup/Vulkan-Loader/archive/refs/tags/v$($env:VULKAN_TAG).zip" -OutFile Vulkan-Loader-$($env:VULKAN_TAG).zip
|
||||||
|
Expand-Archive -Path Vulkan-Loader-$($env:VULKAN_TAG).zip
|
||||||
|
|
||||||
|
# Build Vulkan Loader x64
|
||||||
|
|
||||||
|
cmake -S Vulkan-Loader-$($env:VULKAN_TAG)\Vulkan-Loader-$($env:VULKAN_TAG) -B VulkanLoader-build64 -D UPDATE_DEPS=On -A x64
|
||||||
|
cmake --build VulkanLoader-build64
|
||||||
|
mkdir vulkanArtifact\Lib
|
||||||
|
copy VulkanLoader-build64\loader\Debug\vulkan-1.lib vulkanArtifact\Lib
|
||||||
|
|
||||||
|
# Build Vulkan Loader win32
|
||||||
|
|
||||||
|
cmake -S Vulkan-Loader-$($env:VULKAN_TAG)\Vulkan-Loader-$($env:VULKAN_TAG) -B VulkanLoader-build32 -D UPDATE_DEPS=On -A Win32
|
||||||
|
cmake --build VulkanLoader-build32
|
||||||
|
mkdir vulkanArtifact\Lib32
|
||||||
|
copy VulkanLoader-build32\loader\Debug\vulkan-1.lib vulkanArtifact\Lib32
|
||||||
8
.github/workflows/static-analysis.yml
vendored
8
.github/workflows/static-analysis.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
|||||||
PVS-Studio:
|
PVS-Studio:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
@@ -23,9 +23,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
if [[ "$PVS_STUDIO_LICENSE" != "" ]];
|
if [[ "$PVS_STUDIO_LICENSE" != "" ]];
|
||||||
then
|
then
|
||||||
wget -q https://files.viva64.com/etc/pubkey.txt
|
wget -q https://files.pvs-studio.com/etc/pubkey.txt
|
||||||
sudo apt-key add 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 wget -O /etc/apt/sources.list.d/viva64.list https://files.pvs-studio.com/etc/viva64.list
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y pvs-studio
|
sudo apt-get install -y pvs-studio
|
||||||
pvs-studio-analyzer credentials -o pvs-studio.lic $PVS_STUDIO_LICENSE
|
pvs-studio-analyzer credentials -o pvs-studio.lic $PVS_STUDIO_LICENSE
|
||||||
@@ -42,5 +42,5 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
cd examples/example_null
|
cd examples/example_null
|
||||||
pvs-studio-analyzer trace -- make WITH_EXTRA_WARNINGS=1
|
pvs-studio-analyzer trace -- make WITH_EXTRA_WARNINGS=1
|
||||||
pvs-studio-analyzer analyze --disableLicenseExpirationCheck -e ../../imstb_rectpack.h -e ../../imstb_textedit.h -e ../../imstb_truetype.h -l ../../pvs-studio.lic -o pvs-studio.log
|
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
|
plog-converter -a 'GA:1,2;OP:1' -d V1071 -t errorfile -w pvs-studio.log
|
||||||
|
|||||||
12
.gitignore
vendored
12
.gitignore
vendored
@@ -1,5 +1,7 @@
|
|||||||
## OSX artifacts
|
## Misc artifacts
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.claude
|
||||||
|
.vscode
|
||||||
|
|
||||||
## Dear ImGui artifacts
|
## Dear ImGui artifacts
|
||||||
imgui.ini
|
imgui.ini
|
||||||
@@ -12,6 +14,7 @@ imgui*.ini
|
|||||||
examples/*/Debug/*
|
examples/*/Debug/*
|
||||||
examples/*/Release/*
|
examples/*/Release/*
|
||||||
examples/*/x64/*
|
examples/*/x64/*
|
||||||
|
examples/*.tmp
|
||||||
|
|
||||||
## Visual Studio artifacts
|
## Visual Studio artifacts
|
||||||
.vs
|
.vs
|
||||||
@@ -46,14 +49,14 @@ examples/example_glfw_opengl3/web/*
|
|||||||
examples/example_glfw_wgpu/web/*
|
examples/example_glfw_wgpu/web/*
|
||||||
examples/example_glfw_wgpu/external/*
|
examples/example_glfw_wgpu/external/*
|
||||||
examples/example_sdl2_opengl3/web/*
|
examples/example_sdl2_opengl3/web/*
|
||||||
|
examples/example_sdl2_wgpu/web/*
|
||||||
|
examples/example_sdl3_opengl3/web/*
|
||||||
|
examples/example_sdl3_wgpu/web/*
|
||||||
|
|
||||||
## JetBrains IDE artifacts
|
## JetBrains IDE artifacts
|
||||||
.idea
|
.idea
|
||||||
cmake-build-*
|
cmake-build-*
|
||||||
|
|
||||||
## VS code artifacts
|
|
||||||
.vscode
|
|
||||||
|
|
||||||
## Unix executables from our example Makefiles
|
## Unix executables from our example Makefiles
|
||||||
examples/example_apple_metal/example_apple_metal
|
examples/example_apple_metal/example_apple_metal
|
||||||
examples/example_apple_opengl2/example_apple_opengl2
|
examples/example_apple_opengl2/example_apple_opengl2
|
||||||
@@ -69,6 +72,7 @@ examples/example_sdl2_opengl3/example_sdl2_opengl3
|
|||||||
examples/example_sdl2_sdlrenderer2/example_sdl2_sdlrenderer2
|
examples/example_sdl2_sdlrenderer2/example_sdl2_sdlrenderer2
|
||||||
examples/example_sdl2_vulkan/example_sdl2_vulkan
|
examples/example_sdl2_vulkan/example_sdl2_vulkan
|
||||||
examples/example_sdl3_metal/example_sdl3_metal
|
examples/example_sdl3_metal/example_sdl3_metal
|
||||||
|
examples/example_sdl3_metal4/example_sdl3_metal4
|
||||||
examples/example_sdl3_opengl3/example_sdl3_opengl3
|
examples/example_sdl3_opengl3/example_sdl3_opengl3
|
||||||
examples/example_sdl3_sdlgpu3/example_sdl3_sdlgpu3
|
examples/example_sdl3_sdlgpu3/example_sdl3_sdlgpu3
|
||||||
examples/example_sdl3_sdlrenderer3/example_sdl3_sdlrenderer3
|
examples/example_sdl3_sdlrenderer3/example_sdl3_sdlrenderer3
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2025 Omar Cornut
|
Copyright (c) 2014-2026 Omar Cornut
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually.
|
// [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually.
|
||||||
|
// [ ] Renderer: Missing support for DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest callbacks: Allegro5 cannot enable/disable LINEAR bitmap flags after creation.
|
||||||
// [ ] Platform: Missing gamepad support.
|
// [ ] Platform: Missing gamepad support.
|
||||||
// [ ] Renderer: Multi-viewport support (multiple windows).
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState (others cannot be supported by Allegro5). (#9378)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() and platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
// 2025-08-12: Inputs: fixed missing support for ImGuiKey_PrintScreen under Windows, as raw Allegro 5 does not receive it.
|
// 2025-08-12: Inputs: fixed missing support for ImGuiKey_PrintScreen under Windows, as raw Allegro 5 does not receive it.
|
||||||
// 2025-08-12: Added ImGui_ImplAllegro5_SetDisplay() function to change current ALLEGRO_DISPLAY, as Allegro applications often need to do that.
|
// 2025-08-12: Added ImGui_ImplAllegro5_SetDisplay() function to change current ALLEGRO_DISPLAY, as Allegro applications often need to do that.
|
||||||
// 2025-07-07: Fixed texture update broken on some platforms where ALLEGRO_LOCK_WRITEONLY needed all texels to be rewritten.
|
// 2025-07-07: Fixed texture update broken on some platforms where ALLEGRO_LOCK_WRITEONLY needed all texels to be rewritten.
|
||||||
@@ -136,7 +139,10 @@ static void ImGui_ImplAllegro5_SetupRenderState(ImDrawData* draw_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render function.
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplAllegro5_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
|
||||||
|
// Render function
|
||||||
void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
|
void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
// Avoid rendering when minimized
|
// Avoid rendering when minimized
|
||||||
@@ -152,6 +158,7 @@ void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
|
|||||||
|
|
||||||
// Backup Allegro state that will be modified
|
// Backup Allegro state that will be modified
|
||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
ALLEGRO_TRANSFORM last_transform = *al_get_current_transform();
|
ALLEGRO_TRANSFORM last_transform = *al_get_current_transform();
|
||||||
ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform();
|
ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform();
|
||||||
int last_clip_x, last_clip_y, last_clip_w, last_clip_h;
|
int last_clip_x, last_clip_y, last_clip_w, last_clip_h;
|
||||||
@@ -208,8 +215,7 @@ void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (pcmd->UserCallback)
|
if (pcmd->UserCallback)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplAllegro5_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplAllegro5_SetupRenderState(draw_data);
|
ImGui_ImplAllegro5_SetupRenderState(draw_data);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -486,11 +492,12 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
|
|||||||
|
|
||||||
ImGui_ImplAllegro5_SetDisplay(display);
|
ImGui_ImplAllegro5_SetDisplay(display);
|
||||||
|
|
||||||
#if ALLEGRO_HAS_CLIPBOARD
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
#if ALLEGRO_HAS_CLIPBOARD
|
||||||
platform_io.Platform_SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
|
platform_io.Platform_SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
|
||||||
platform_io.Platform_GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText;
|
platform_io.Platform_GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText;
|
||||||
#endif
|
#endif
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplAllegro5_DrawCallback_ResetRenderState;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -500,6 +507,7 @@ void ImGui_ImplAllegro5_Shutdown()
|
|||||||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
||||||
if (bd->VertexDecl)
|
if (bd->VertexDecl)
|
||||||
@@ -510,6 +518,8 @@ void ImGui_ImplAllegro5_Shutdown()
|
|||||||
io.BackendPlatformName = io.BackendRendererName = nullptr;
|
io.BackendPlatformName = io.BackendRendererName = nullptr;
|
||||||
io.BackendPlatformUserData = nullptr;
|
io.BackendPlatformUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_RendererHasTextures);
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_RendererHasTextures);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,7 +531,7 @@ void ImGui_ImplAllegro5_SetDisplay(ALLEGRO_DISPLAY* display)
|
|||||||
if (bd->VertexDecl)
|
if (bd->VertexDecl)
|
||||||
{
|
{
|
||||||
al_destroy_vertex_decl(bd->VertexDecl);
|
al_destroy_vertex_decl(bd->VertexDecl);
|
||||||
bd->VertexDecl = NULL;
|
bd->VertexDecl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bd->Display && !bd->VertexDecl)
|
if (bd->Display && !bd->VertexDecl)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually.
|
// [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually.
|
||||||
|
// [ ] Renderer: Missing support for DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest callbacks: Allegro5 cannot enable/disable LINEAR bitmap flags after creation.
|
||||||
// [ ] Platform: Missing gamepad support.
|
// [ ] Platform: Missing gamepad support.
|
||||||
// [ ] Renderer: Multi-viewport support (multiple windows).
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ IMGUI_IMPL_API void ImGui_ImplAllegro5_SetDisplay(ALLEGRO_DISPLAY* display);
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplAllegro5_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplAllegro5_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplAllegro5_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplAllegro5_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-23: DirectX10: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. Obsoleting samplers from ImGui_ImplDX10_RenderState. (#9378)
|
||||||
|
// 2026-01-19: DirectX10: Added 'SamplerNearest' in ImGui_ImplDX10_RenderState. Renamed 'SamplerDefault' to 'SamplerLinear'.
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-11: DirectX10: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
// 2025-06-11: DirectX10: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
||||||
// 2025-05-07: DirectX10: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
// 2025-05-07: DirectX10: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
||||||
// 2025-01-06: DirectX10: Expose selected render state in ImGui_ImplDX10_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
// 2025-01-06: DirectX10: Expose selected render state in ImGui_ImplDX10_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
||||||
@@ -76,6 +79,7 @@ struct ImGui_ImplDX10_Data
|
|||||||
ID3D10Buffer* pVertexConstantBuffer;
|
ID3D10Buffer* pVertexConstantBuffer;
|
||||||
ID3D10PixelShader* pPixelShader;
|
ID3D10PixelShader* pPixelShader;
|
||||||
ID3D10SamplerState* pTexSamplerLinear;
|
ID3D10SamplerState* pTexSamplerLinear;
|
||||||
|
ID3D10SamplerState* pTexSamplerNearest;
|
||||||
ID3D10RasterizerState* pRasterizerState;
|
ID3D10RasterizerState* pRasterizerState;
|
||||||
ID3D10BlendState* pBlendState;
|
ID3D10BlendState* pBlendState;
|
||||||
ID3D10DepthStencilState* pDepthStencilState;
|
ID3D10DepthStencilState* pDepthStencilState;
|
||||||
@@ -156,6 +160,11 @@ static void ImGui_ImplDX10_SetupRenderState(ImDrawData* draw_data, ID3D10Device*
|
|||||||
device->RSSetState(bd->pRasterizerState);
|
device->RSSetState(bd->pRasterizerState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplDX10_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplDX10_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData(); bd->pd3dDevice->PSSetSamplers(0, 1, &bd->pTexSamplerLinear); }
|
||||||
|
static void ImGui_ImplDX10_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData(); bd->pd3dDevice->PSSetSamplers(0, 1, &bd->pTexSamplerNearest); }
|
||||||
|
|
||||||
// Render function
|
// Render function
|
||||||
void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
@@ -180,7 +189,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||||||
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||||
D3D10_BUFFER_DESC desc = {};
|
D3D10_BUFFER_DESC desc = {};
|
||||||
desc.Usage = D3D10_USAGE_DYNAMIC;
|
desc.Usage = D3D10_USAGE_DYNAMIC;
|
||||||
desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert);
|
desc.ByteWidth = (UINT)bd->VertexBufferSize * sizeof(ImDrawVert);
|
||||||
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||||
desc.MiscFlags = 0;
|
desc.MiscFlags = 0;
|
||||||
@@ -194,7 +203,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||||||
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||||
D3D10_BUFFER_DESC desc = {};
|
D3D10_BUFFER_DESC desc = {};
|
||||||
desc.Usage = D3D10_USAGE_DYNAMIC;
|
desc.Usage = D3D10_USAGE_DYNAMIC;
|
||||||
desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx);
|
desc.ByteWidth = (UINT)bd->IndexBufferSize * sizeof(ImDrawIdx);
|
||||||
desc.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
desc.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||||
if (device->CreateBuffer(&desc, nullptr, &bd->pIB) < 0)
|
if (device->CreateBuffer(&desc, nullptr, &bd->pIB) < 0)
|
||||||
@@ -263,7 +272,6 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
ImGui_ImplDX10_RenderState render_state;
|
ImGui_ImplDX10_RenderState render_state;
|
||||||
render_state.Device = bd->pd3dDevice;
|
render_state.Device = bd->pd3dDevice;
|
||||||
render_state.SamplerDefault = bd->pTexSamplerLinear;
|
|
||||||
render_state.VertexConstantBuffer = bd->pVertexConstantBuffer;
|
render_state.VertexConstantBuffer = bd->pVertexConstantBuffer;
|
||||||
platform_io.Renderer_RenderState = &render_state;
|
platform_io.Renderer_RenderState = &render_state;
|
||||||
|
|
||||||
@@ -281,8 +289,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (pcmd->UserCallback != nullptr)
|
if (pcmd->UserCallback != nullptr)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplDX10_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplDX10_SetupRenderState(draw_data, device);
|
ImGui_ImplDX10_SetupRenderState(draw_data, device);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -330,18 +337,18 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||||||
|
|
||||||
static void ImGui_ImplDX10_DestroyTexture(ImTextureData* tex)
|
static void ImGui_ImplDX10_DestroyTexture(ImTextureData* tex)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_Texture* backend_tex = (ImGui_ImplDX10_Texture*)tex->BackendUserData;
|
if (ImGui_ImplDX10_Texture* backend_tex = (ImGui_ImplDX10_Texture*)tex->BackendUserData)
|
||||||
if (backend_tex == nullptr)
|
{
|
||||||
return;
|
IM_ASSERT(backend_tex->pTextureView == (ID3D10ShaderResourceView*)(intptr_t)tex->TexID);
|
||||||
IM_ASSERT(backend_tex->pTextureView == (ID3D10ShaderResourceView*)(intptr_t)tex->TexID);
|
backend_tex->pTextureView->Release();
|
||||||
backend_tex->pTexture->Release();
|
backend_tex->pTexture->Release();
|
||||||
backend_tex->pTextureView->Release();
|
IM_DELETE(backend_tex);
|
||||||
IM_DELETE(backend_tex);
|
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
tex->BackendUserData = nullptr;
|
||||||
|
}
|
||||||
tex->SetStatus(ImTextureStatus_Destroyed);
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
tex->BackendUserData = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX10_UpdateTexture(ImTextureData* tex)
|
void ImGui_ImplDX10_UpdateTexture(ImTextureData* tex)
|
||||||
@@ -570,6 +577,8 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
|||||||
desc.MinLOD = 0.f;
|
desc.MinLOD = 0.f;
|
||||||
desc.MaxLOD = 0.f;
|
desc.MaxLOD = 0.f;
|
||||||
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerLinear);
|
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerLinear);
|
||||||
|
desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
|
||||||
|
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerNearest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -586,6 +595,7 @@ void ImGui_ImplDX10_InvalidateDeviceObjects()
|
|||||||
if (tex->RefCount == 1)
|
if (tex->RefCount == 1)
|
||||||
ImGui_ImplDX10_DestroyTexture(tex);
|
ImGui_ImplDX10_DestroyTexture(tex);
|
||||||
if (bd->pTexSamplerLinear) { bd->pTexSamplerLinear->Release(); bd->pTexSamplerLinear = nullptr; }
|
if (bd->pTexSamplerLinear) { bd->pTexSamplerLinear->Release(); bd->pTexSamplerLinear = nullptr; }
|
||||||
|
if (bd->pTexSamplerNearest) { bd->pTexSamplerNearest->Release(); bd->pTexSamplerNearest = nullptr; }
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
||||||
if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; }
|
if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; }
|
||||||
@@ -613,6 +623,9 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device)
|
|||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplDX10_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplDX10_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplDX10_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
// Get factory from device
|
// Get factory from device
|
||||||
IDXGIDevice* pDXGIDevice = nullptr;
|
IDXGIDevice* pDXGIDevice = nullptr;
|
||||||
@@ -639,14 +652,17 @@ void ImGui_ImplDX10_Shutdown()
|
|||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplDX10_ShutdownMultiViewportSupport();
|
ImGui_ImplDX10_ShutdownMultiViewportSupport();
|
||||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||||
if (bd->pFactory) { bd->pFactory->Release(); }
|
if (bd->pFactory) { bd->pFactory->Release(); }
|
||||||
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
||||||
|
|
||||||
io.BackendRendererName = nullptr;
|
io.BackendRendererName = nullptr;
|
||||||
io.BackendRendererUserData = nullptr;
|
io.BackendRendererUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,6 +720,7 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
IM_ASSERT(vd->SwapChain == nullptr && vd->RTView == nullptr);
|
IM_ASSERT(vd->SwapChain == nullptr && vd->RTView == nullptr);
|
||||||
bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain);
|
bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain);
|
||||||
|
bd->pFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES); // Disable e.g. Alt+Enter
|
||||||
|
|
||||||
// Create the render target
|
// Create the render target
|
||||||
if (vd->SwapChain)
|
if (vd->SwapChain)
|
||||||
@@ -765,7 +782,8 @@ static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport, void*)
|
|||||||
static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
|
ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
|
||||||
vd->SwapChain->Present(0, 0); // Present without vsync
|
if (vd->SwapChain)
|
||||||
|
vd->SwapChain->Present(0, 0); // Present without vsync
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX10_InitMultiViewportSupport()
|
void ImGui_ImplDX10_InitMultiViewportSupport()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ IMGUI_IMPL_API void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data);
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplDX10_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplDX10_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX10_InvalidateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX10_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplDX10_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
@@ -42,8 +42,9 @@ IMGUI_IMPL_API void ImGui_ImplDX10_UpdateTexture(ImTextureData* tex);
|
|||||||
struct ImGui_ImplDX10_RenderState
|
struct ImGui_ImplDX10_RenderState
|
||||||
{
|
{
|
||||||
ID3D10Device* Device;
|
ID3D10Device* Device;
|
||||||
ID3D10SamplerState* SamplerDefault;
|
|
||||||
ID3D10Buffer* VertexConstantBuffer;
|
ID3D10Buffer* VertexConstantBuffer;
|
||||||
|
//ID3D10SamplerState* SamplerLinear; // Use ImDrawList::AddCallback(ImGui::GetPlatform().DrawCallback_SetSamplerLinear)
|
||||||
|
//ID3D10SamplerState* SamplerNearest; // Use ImDrawList::AddCallback(ImGui::GetPlatform().DrawCallback_SetSamplerNearest)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -18,7 +18,10 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-23: DirectX11: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. Obsoleting samplers from ImGui_ImplDX11_RenderState. (#9378)
|
||||||
|
// 2026-01-19: DirectX11: Added 'SamplerNearest' in ImGui_ImplDX11_RenderState. Renamed 'SamplerDefault' to 'SamplerLinear'.
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-11: DirectX11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
// 2025-06-11: DirectX11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
||||||
// 2025-05-07: DirectX11: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
// 2025-05-07: DirectX11: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
||||||
// 2025-02-24: [Docking] Added undocumented ImGui_ImplDX11_SetSwapChainDescs() to configure swap chain creation for secondary viewports.
|
// 2025-02-24: [Docking] Added undocumented ImGui_ImplDX11_SetSwapChainDescs() to configure swap chain creation for secondary viewports.
|
||||||
@@ -80,11 +83,13 @@ struct ImGui_ImplDX11_Data
|
|||||||
ID3D11Buffer* pVertexConstantBuffer;
|
ID3D11Buffer* pVertexConstantBuffer;
|
||||||
ID3D11PixelShader* pPixelShader;
|
ID3D11PixelShader* pPixelShader;
|
||||||
ID3D11SamplerState* pTexSamplerLinear;
|
ID3D11SamplerState* pTexSamplerLinear;
|
||||||
|
ID3D11SamplerState* pTexSamplerNearest;
|
||||||
ID3D11RasterizerState* pRasterizerState;
|
ID3D11RasterizerState* pRasterizerState;
|
||||||
ID3D11BlendState* pBlendState;
|
ID3D11BlendState* pBlendState;
|
||||||
ID3D11DepthStencilState* pDepthStencilState;
|
ID3D11DepthStencilState* pDepthStencilState;
|
||||||
int VertexBufferSize;
|
int VertexBufferSize;
|
||||||
int IndexBufferSize;
|
int IndexBufferSize;
|
||||||
|
ImGui_ImplDX11_RenderState* RenderState; // == (ImGui_ImplDX11_RenderState*)ImGui::GetPlatformIO().Renderer_RenderState during rendering.
|
||||||
ImVector<DXGI_SWAP_CHAIN_DESC> SwapChainDescsForViewports;
|
ImVector<DXGI_SWAP_CHAIN_DESC> SwapChainDescsForViewports;
|
||||||
|
|
||||||
ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
|
ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
|
||||||
@@ -164,6 +169,11 @@ static void ImGui_ImplDX11_SetupRenderState(const ImDrawData* draw_data, ID3D11D
|
|||||||
device_ctx->RSSetState(bd->pRasterizerState);
|
device_ctx->RSSetState(bd->pRasterizerState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplDX11_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplDX11_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); bd->RenderState->DeviceContext->PSSetSamplers(0, 1, &bd->pTexSamplerLinear); }
|
||||||
|
static void ImGui_ImplDX11_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); bd->RenderState->DeviceContext->PSSetSamplers(0, 1, &bd->pTexSamplerNearest); }
|
||||||
|
|
||||||
// Render function
|
// Render function
|
||||||
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
@@ -188,7 +198,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||||||
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||||
D3D11_BUFFER_DESC desc = {};
|
D3D11_BUFFER_DESC desc = {};
|
||||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||||
desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert);
|
desc.ByteWidth = (UINT)bd->VertexBufferSize * sizeof(ImDrawVert);
|
||||||
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
desc.MiscFlags = 0;
|
desc.MiscFlags = 0;
|
||||||
@@ -201,7 +211,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||||||
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||||
D3D11_BUFFER_DESC desc = {};
|
D3D11_BUFFER_DESC desc = {};
|
||||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||||
desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx);
|
desc.ByteWidth = (UINT)bd->IndexBufferSize * sizeof(ImDrawIdx);
|
||||||
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pIB) < 0)
|
if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pIB) < 0)
|
||||||
@@ -279,9 +289,8 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||||||
ImGui_ImplDX11_RenderState render_state;
|
ImGui_ImplDX11_RenderState render_state;
|
||||||
render_state.Device = bd->pd3dDevice;
|
render_state.Device = bd->pd3dDevice;
|
||||||
render_state.DeviceContext = bd->pd3dDeviceContext;
|
render_state.DeviceContext = bd->pd3dDeviceContext;
|
||||||
render_state.SamplerDefault = bd->pTexSamplerLinear;
|
|
||||||
render_state.VertexConstantBuffer = bd->pVertexConstantBuffer;
|
render_state.VertexConstantBuffer = bd->pVertexConstantBuffer;
|
||||||
platform_io.Renderer_RenderState = &render_state;
|
platform_io.Renderer_RenderState = bd->RenderState = &render_state;
|
||||||
|
|
||||||
// Render command lists
|
// Render command lists
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
||||||
@@ -297,8 +306,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (pcmd->UserCallback != nullptr)
|
if (pcmd->UserCallback != nullptr)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplDX11_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplDX11_SetupRenderState(draw_data, device);
|
ImGui_ImplDX11_SetupRenderState(draw_data, device);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -324,7 +332,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||||||
global_idx_offset += draw_list->IdxBuffer.Size;
|
global_idx_offset += draw_list->IdxBuffer.Size;
|
||||||
global_vtx_offset += draw_list->VtxBuffer.Size;
|
global_vtx_offset += draw_list->VtxBuffer.Size;
|
||||||
}
|
}
|
||||||
platform_io.Renderer_RenderState = nullptr;
|
platform_io.Renderer_RenderState = bd->RenderState = nullptr;
|
||||||
|
|
||||||
// Restore modified DX state
|
// Restore modified DX state
|
||||||
device->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects);
|
device->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects);
|
||||||
@@ -348,18 +356,18 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||||||
|
|
||||||
static void ImGui_ImplDX11_DestroyTexture(ImTextureData* tex)
|
static void ImGui_ImplDX11_DestroyTexture(ImTextureData* tex)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_Texture* backend_tex = (ImGui_ImplDX11_Texture*)tex->BackendUserData;
|
if (ImGui_ImplDX11_Texture* backend_tex = (ImGui_ImplDX11_Texture*)tex->BackendUserData)
|
||||||
if (backend_tex == nullptr)
|
{
|
||||||
return;
|
IM_ASSERT(backend_tex->pTextureView == (ID3D11ShaderResourceView*)(intptr_t)tex->TexID);
|
||||||
IM_ASSERT(backend_tex->pTextureView == (ID3D11ShaderResourceView*)(intptr_t)tex->TexID);
|
backend_tex->pTextureView->Release();
|
||||||
backend_tex->pTextureView->Release();
|
backend_tex->pTexture->Release();
|
||||||
backend_tex->pTexture->Release();
|
IM_DELETE(backend_tex);
|
||||||
IM_DELETE(backend_tex);
|
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
tex->BackendUserData = nullptr;
|
||||||
|
}
|
||||||
tex->SetStatus(ImTextureStatus_Destroyed);
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
tex->BackendUserData = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX11_UpdateTexture(ImTextureData* tex)
|
void ImGui_ImplDX11_UpdateTexture(ImTextureData* tex)
|
||||||
@@ -587,6 +595,8 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||||||
desc.MinLOD = 0.f;
|
desc.MinLOD = 0.f;
|
||||||
desc.MaxLOD = 0.f;
|
desc.MaxLOD = 0.f;
|
||||||
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerLinear);
|
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerLinear);
|
||||||
|
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||||
|
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerNearest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -603,7 +613,8 @@ void ImGui_ImplDX11_InvalidateDeviceObjects()
|
|||||||
if (tex->RefCount == 1)
|
if (tex->RefCount == 1)
|
||||||
ImGui_ImplDX11_DestroyTexture(tex);
|
ImGui_ImplDX11_DestroyTexture(tex);
|
||||||
|
|
||||||
if (bd->pTexSamplerLinear) { bd->pTexSamplerLinear->Release(); bd->pTexSamplerLinear = nullptr; }
|
if (bd->pTexSamplerLinear) { bd->pTexSamplerLinear->Release(); bd->pTexSamplerLinear = nullptr; }
|
||||||
|
if (bd->pTexSamplerNearest) { bd->pTexSamplerNearest->Release(); bd->pTexSamplerNearest = nullptr; }
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
||||||
if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; }
|
if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; }
|
||||||
@@ -631,6 +642,9 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
|
|||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplDX11_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplDX11_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplDX11_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
// Get factory from device
|
// Get factory from device
|
||||||
IDXGIDevice* pDXGIDevice = nullptr;
|
IDXGIDevice* pDXGIDevice = nullptr;
|
||||||
@@ -660,15 +674,18 @@ void ImGui_ImplDX11_Shutdown()
|
|||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplDX11_ShutdownMultiViewportSupport();
|
ImGui_ImplDX11_ShutdownMultiViewportSupport();
|
||||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||||
if (bd->pFactory) { bd->pFactory->Release(); }
|
if (bd->pFactory) { bd->pFactory->Release(); }
|
||||||
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
||||||
if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); }
|
if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); }
|
||||||
|
|
||||||
io.BackendRendererName = nullptr;
|
io.BackendRendererName = nullptr;
|
||||||
io.BackendRendererUserData = nullptr;
|
io.BackendRendererUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,6 +751,7 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
|
bd->pFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES); // Disable e.g. Alt+Enter
|
||||||
|
|
||||||
// Create the render target
|
// Create the render target
|
||||||
if (vd->SwapChain != nullptr)
|
if (vd->SwapChain != nullptr)
|
||||||
@@ -795,7 +813,8 @@ static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport, void*)
|
|||||||
static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData;
|
ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData;
|
||||||
vd->SwapChain->Present(0, 0); // Present without vsync
|
if (vd->SwapChain)
|
||||||
|
vd->SwapChain->Present(0, 0); // Present without vsync
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX11_InitMultiViewportSupport()
|
static void ImGui_ImplDX11_InitMultiViewportSupport()
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data);
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX11_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplDX11_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
@@ -45,8 +45,9 @@ struct ImGui_ImplDX11_RenderState
|
|||||||
{
|
{
|
||||||
ID3D11Device* Device;
|
ID3D11Device* Device;
|
||||||
ID3D11DeviceContext* DeviceContext;
|
ID3D11DeviceContext* DeviceContext;
|
||||||
ID3D11SamplerState* SamplerDefault;
|
|
||||||
ID3D11Buffer* VertexConstantBuffer;
|
ID3D11Buffer* VertexConstantBuffer;
|
||||||
|
//ID3D11SamplerState* SamplerLinear; // Use ImDrawList::AddCallback(ImGui::GetPlatform().DrawCallback_SetSamplerLinear)
|
||||||
|
//ID3D11SamplerState* SamplerNearest; // Use ImDrawList::AddCallback(ImGui::GetPlatform().DrawCallback_SetSamplerNearest)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -22,7 +22,14 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. (#9378)
|
||||||
|
// 2025-10-23: [Docking] DirectX12: Fixed an issue in synchronization logic improving rendering throughput for secondary viewports. (#8961, #9025)
|
||||||
|
// 2025-10-11: DirectX12: Reuse texture upload buffer and grow it only when necessary. (#9002)
|
||||||
|
// 2025-09-29: DirectX12: Rework synchronization logic. (#8961)
|
||||||
|
// 2025-09-29: DirectX12: Enable swapchain tearing to eliminate viewports framerate throttling. (#8965)
|
||||||
|
// 2025-09-29: DirectX12: Reuse a command list and allocator for texture uploads instead of recreating them each time. (#8963)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-19: Fixed build on MinGW. (#8702, #4594)
|
// 2025-06-19: Fixed build on MinGW. (#8702, #4594)
|
||||||
// 2025-06-11: DirectX12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
// 2025-06-11: DirectX12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
||||||
// 2025-05-07: DirectX12: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
// 2025-05-07: DirectX12: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
||||||
@@ -59,7 +66,7 @@
|
|||||||
|
|
||||||
// DirectX
|
// DirectX
|
||||||
#include <d3d12.h>
|
#include <d3d12.h>
|
||||||
#include <dxgi1_4.h>
|
#include <dxgi1_5.h>
|
||||||
#include <d3dcompiler.h>
|
#include <d3dcompiler.h>
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
||||||
@@ -89,21 +96,32 @@ struct ImGui_ImplDX12_Texture
|
|||||||
struct ImGui_ImplDX12_Data
|
struct ImGui_ImplDX12_Data
|
||||||
{
|
{
|
||||||
ImGui_ImplDX12_InitInfo InitInfo;
|
ImGui_ImplDX12_InitInfo InitInfo;
|
||||||
|
ImGui_ImplDX12_RenderState* RenderState;
|
||||||
|
|
||||||
|
IDXGIFactory5* pdxgiFactory;
|
||||||
ID3D12Device* pd3dDevice;
|
ID3D12Device* pd3dDevice;
|
||||||
ID3D12RootSignature* pRootSignature;
|
ID3D12RootSignature* pRootSignatureLinear;
|
||||||
ID3D12PipelineState* pPipelineState;
|
ID3D12RootSignature* pRootSignatureNearest;
|
||||||
|
ID3D12PipelineState* pPipelineStateLinear;
|
||||||
|
ID3D12PipelineState* pPipelineStateNearest;
|
||||||
ID3D12CommandQueue* pCommandQueue;
|
ID3D12CommandQueue* pCommandQueue;
|
||||||
bool commandQueueOwned;
|
bool commandQueueOwned;
|
||||||
DXGI_FORMAT RTVFormat;
|
DXGI_FORMAT RTVFormat;
|
||||||
DXGI_FORMAT DSVFormat;
|
DXGI_FORMAT DSVFormat;
|
||||||
ID3D12DescriptorHeap* pd3dSrvDescHeap;
|
ID3D12DescriptorHeap* pd3dSrvDescHeap;
|
||||||
|
ID3D12Fence* Fence;
|
||||||
|
UINT64 FenceLastSignaledValue;
|
||||||
|
HANDLE FenceEvent;
|
||||||
UINT numFramesInFlight;
|
UINT numFramesInFlight;
|
||||||
|
bool tearingSupport;
|
||||||
ImGui_ImplDX12_RenderBuffers* pFrameResources;
|
|
||||||
UINT frameIndex;
|
|
||||||
|
|
||||||
bool LegacySingleDescriptorUsed;
|
bool LegacySingleDescriptorUsed;
|
||||||
|
|
||||||
|
ID3D12CommandAllocator* pTexCmdAllocator;
|
||||||
|
ID3D12GraphicsCommandList* pTexCmdList;
|
||||||
|
ID3D12Resource* pTexUploadBuffer;
|
||||||
|
UINT pTexUploadBufferSize;
|
||||||
|
void* pTexUploadBufferMapped;
|
||||||
|
|
||||||
ImGui_ImplDX12_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplDX12_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,6 +144,7 @@ struct ImGui_ImplDX12_RenderBuffers
|
|||||||
// Buffers used for secondary viewports created by the multi-viewports systems
|
// Buffers used for secondary viewports created by the multi-viewports systems
|
||||||
struct ImGui_ImplDX12_FrameContext
|
struct ImGui_ImplDX12_FrameContext
|
||||||
{
|
{
|
||||||
|
UINT64 FenceValue;
|
||||||
ID3D12CommandAllocator* CommandAllocator;
|
ID3D12CommandAllocator* CommandAllocator;
|
||||||
ID3D12Resource* RenderTarget;
|
ID3D12Resource* RenderTarget;
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetCpuDescriptors;
|
D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetCpuDescriptors;
|
||||||
@@ -141,9 +160,7 @@ struct ImGui_ImplDX12_ViewportData
|
|||||||
ID3D12GraphicsCommandList* CommandList;
|
ID3D12GraphicsCommandList* CommandList;
|
||||||
ID3D12DescriptorHeap* RtvDescHeap;
|
ID3D12DescriptorHeap* RtvDescHeap;
|
||||||
IDXGISwapChain3* SwapChain;
|
IDXGISwapChain3* SwapChain;
|
||||||
ID3D12Fence* Fence;
|
HANDLE SwapChainWaitableObject;
|
||||||
UINT64 FenceSignaledValue;
|
|
||||||
HANDLE FenceEvent;
|
|
||||||
UINT NumFramesInFlight;
|
UINT NumFramesInFlight;
|
||||||
ImGui_ImplDX12_FrameContext* FrameCtx;
|
ImGui_ImplDX12_FrameContext* FrameCtx;
|
||||||
|
|
||||||
@@ -157,16 +174,15 @@ struct ImGui_ImplDX12_ViewportData
|
|||||||
CommandList = nullptr;
|
CommandList = nullptr;
|
||||||
RtvDescHeap = nullptr;
|
RtvDescHeap = nullptr;
|
||||||
SwapChain = nullptr;
|
SwapChain = nullptr;
|
||||||
Fence = nullptr;
|
SwapChainWaitableObject = nullptr;
|
||||||
FenceSignaledValue = 0;
|
|
||||||
FenceEvent = nullptr;
|
|
||||||
NumFramesInFlight = num_frames_in_flight;
|
NumFramesInFlight = num_frames_in_flight;
|
||||||
FrameCtx = new ImGui_ImplDX12_FrameContext[NumFramesInFlight];
|
FrameCtx = new ImGui_ImplDX12_FrameContext[NumFramesInFlight];
|
||||||
FrameIndex = UINT_MAX;
|
FrameIndex = 0;
|
||||||
FrameRenderBuffers = new ImGui_ImplDX12_RenderBuffers[NumFramesInFlight];
|
FrameRenderBuffers = new ImGui_ImplDX12_RenderBuffers[NumFramesInFlight];
|
||||||
|
|
||||||
for (UINT i = 0; i < NumFramesInFlight; ++i)
|
for (UINT i = 0; i < NumFramesInFlight; ++i)
|
||||||
{
|
{
|
||||||
|
FrameCtx[i].FenceValue = 0;
|
||||||
FrameCtx[i].CommandAllocator = nullptr;
|
FrameCtx[i].CommandAllocator = nullptr;
|
||||||
FrameCtx[i].RenderTarget = nullptr;
|
FrameCtx[i].RenderTarget = nullptr;
|
||||||
|
|
||||||
@@ -182,8 +198,7 @@ struct ImGui_ImplDX12_ViewportData
|
|||||||
IM_ASSERT(CommandQueue == nullptr && CommandList == nullptr);
|
IM_ASSERT(CommandQueue == nullptr && CommandList == nullptr);
|
||||||
IM_ASSERT(RtvDescHeap == nullptr);
|
IM_ASSERT(RtvDescHeap == nullptr);
|
||||||
IM_ASSERT(SwapChain == nullptr);
|
IM_ASSERT(SwapChain == nullptr);
|
||||||
IM_ASSERT(Fence == nullptr);
|
IM_ASSERT(SwapChainWaitableObject == nullptr);
|
||||||
IM_ASSERT(FenceEvent == nullptr);
|
|
||||||
|
|
||||||
for (UINT i = 0; i < NumFramesInFlight; ++i)
|
for (UINT i = 0; i < NumFramesInFlight; ++i)
|
||||||
{
|
{
|
||||||
@@ -202,14 +217,26 @@ struct VERTEX_CONSTANT_BUFFER_DX12
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
static void ImGui_ImplDX12_InitPlatformInterface();
|
static void ImGui_ImplDX12_InitMultiViewportSupport();
|
||||||
static void ImGui_ImplDX12_ShutdownPlatformInterface();
|
static void ImGui_ImplDX12_ShutdownMultiViewportSupport();
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12GraphicsCommandList* command_list, ImGui_ImplDX12_RenderBuffers* fr)
|
static void ImGui_ImplDX12_SetupSamplerLinear(ID3D12GraphicsCommandList* command_list)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
|
command_list->SetPipelineState(bd->pPipelineStateLinear);
|
||||||
|
command_list->SetGraphicsRootSignature(bd->pRootSignatureLinear);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplDX12_SetupSamplerNearest(ID3D12GraphicsCommandList* command_list)
|
||||||
|
{
|
||||||
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
|
command_list->SetPipelineState(bd->pPipelineStateNearest);
|
||||||
|
command_list->SetGraphicsRootSignature(bd->pRootSignatureNearest);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12GraphicsCommandList* command_list, ImGui_ImplDX12_RenderBuffers* fr)
|
||||||
|
{
|
||||||
// Setup orthographic projection matrix into our constant buffer
|
// 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).
|
// 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;
|
VERTEX_CONSTANT_BUFFER_DX12 vertex_constant_buffer;
|
||||||
@@ -247,12 +274,11 @@ static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12Graphic
|
|||||||
command_list->IASetVertexBuffers(0, 1, &vbv);
|
command_list->IASetVertexBuffers(0, 1, &vbv);
|
||||||
D3D12_INDEX_BUFFER_VIEW ibv = {};
|
D3D12_INDEX_BUFFER_VIEW ibv = {};
|
||||||
ibv.BufferLocation = fr->IndexBuffer->GetGPUVirtualAddress();
|
ibv.BufferLocation = fr->IndexBuffer->GetGPUVirtualAddress();
|
||||||
ibv.SizeInBytes = fr->IndexBufferSize * sizeof(ImDrawIdx);
|
ibv.SizeInBytes = (UINT)fr->IndexBufferSize * sizeof(ImDrawIdx);
|
||||||
ibv.Format = sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
|
ibv.Format = sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
|
||||||
command_list->IASetIndexBuffer(&ibv);
|
command_list->IASetIndexBuffer(&ibv);
|
||||||
command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
command_list->SetPipelineState(bd->pPipelineState);
|
ImGui_ImplDX12_SetupSamplerLinear(command_list);
|
||||||
command_list->SetGraphicsRootSignature(bd->pRootSignature);
|
|
||||||
command_list->SetGraphicsRoot32BitConstants(0, 16, &vertex_constant_buffer, 0);
|
command_list->SetGraphicsRoot32BitConstants(0, 16, &vertex_constant_buffer, 0);
|
||||||
|
|
||||||
// Setup blend factor
|
// Setup blend factor
|
||||||
@@ -268,6 +294,11 @@ static inline void SafeRelease(T*& res)
|
|||||||
res = nullptr;
|
res = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplDX12_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplDX12_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); ImGui_ImplDX12_SetupSamplerLinear(bd->RenderState->CommandList); }
|
||||||
|
static void ImGui_ImplDX12_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); ImGui_ImplDX12_SetupSamplerNearest(bd->RenderState->CommandList); }
|
||||||
|
|
||||||
// Render function
|
// Render function
|
||||||
void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* command_list)
|
void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* command_list)
|
||||||
{
|
{
|
||||||
@@ -285,8 +316,8 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|||||||
// FIXME: We are assuming that this only gets called once per frame!
|
// FIXME: We are assuming that this only gets called once per frame!
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)draw_data->OwnerViewport->RendererUserData;
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)draw_data->OwnerViewport->RendererUserData;
|
||||||
vd->FrameIndex++;
|
|
||||||
ImGui_ImplDX12_RenderBuffers* fr = &vd->FrameRenderBuffers[vd->FrameIndex % bd->numFramesInFlight];
|
ImGui_ImplDX12_RenderBuffers* fr = &vd->FrameRenderBuffers[vd->FrameIndex % bd->numFramesInFlight];
|
||||||
|
vd->FrameIndex++;
|
||||||
|
|
||||||
// Create and grow vertex/index buffers if needed
|
// Create and grow vertex/index buffers if needed
|
||||||
if (fr->VertexBuffer == nullptr || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
if (fr->VertexBuffer == nullptr || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
||||||
@@ -366,7 +397,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|||||||
ImGui_ImplDX12_RenderState render_state;
|
ImGui_ImplDX12_RenderState render_state;
|
||||||
render_state.Device = bd->pd3dDevice;
|
render_state.Device = bd->pd3dDevice;
|
||||||
render_state.CommandList = command_list;
|
render_state.CommandList = command_list;
|
||||||
platform_io.Renderer_RenderState = &render_state;
|
platform_io.Renderer_RenderState = bd->RenderState = &render_state;
|
||||||
|
|
||||||
// Render command lists
|
// Render command lists
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
||||||
@@ -383,7 +414,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
if (pcmd->UserCallback == ImGui_ImplDX12_DrawCallback_ResetRenderState)
|
||||||
ImGui_ImplDX12_SetupRenderState(draw_data, command_list, fr);
|
ImGui_ImplDX12_SetupRenderState(draw_data, command_list, fr);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -410,26 +441,26 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|||||||
global_idx_offset += draw_list->IdxBuffer.Size;
|
global_idx_offset += draw_list->IdxBuffer.Size;
|
||||||
global_vtx_offset += draw_list->VtxBuffer.Size;
|
global_vtx_offset += draw_list->VtxBuffer.Size;
|
||||||
}
|
}
|
||||||
platform_io.Renderer_RenderState = nullptr;
|
platform_io.Renderer_RenderState = bd->RenderState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX12_DestroyTexture(ImTextureData* tex)
|
static void ImGui_ImplDX12_DestroyTexture(ImTextureData* tex)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX12_Texture* backend_tex = (ImGui_ImplDX12_Texture*)tex->BackendUserData;
|
if (ImGui_ImplDX12_Texture* backend_tex = (ImGui_ImplDX12_Texture*)tex->BackendUserData)
|
||||||
if (backend_tex == nullptr)
|
{
|
||||||
return;
|
IM_ASSERT(backend_tex->hFontSrvGpuDescHandle.ptr == (UINT64)tex->TexID);
|
||||||
IM_ASSERT(backend_tex->hFontSrvGpuDescHandle.ptr == (UINT64)tex->TexID);
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
bd->InitInfo.SrvDescriptorFreeFn(&bd->InitInfo, backend_tex->hFontSrvCpuDescHandle, backend_tex->hFontSrvGpuDescHandle);
|
||||||
bd->InitInfo.SrvDescriptorFreeFn(&bd->InitInfo, backend_tex->hFontSrvCpuDescHandle, backend_tex->hFontSrvGpuDescHandle);
|
SafeRelease(backend_tex->pTextureResource);
|
||||||
SafeRelease(backend_tex->pTextureResource);
|
backend_tex->hFontSrvCpuDescHandle.ptr = 0;
|
||||||
backend_tex->hFontSrvCpuDescHandle.ptr = 0;
|
backend_tex->hFontSrvGpuDescHandle.ptr = 0;
|
||||||
backend_tex->hFontSrvGpuDescHandle.ptr = 0;
|
IM_DELETE(backend_tex);
|
||||||
IM_DELETE(backend_tex);
|
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
tex->BackendUserData = nullptr;
|
||||||
|
}
|
||||||
tex->SetStatus(ImTextureStatus_Destroyed);
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
tex->BackendUserData = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX12_UpdateTexture(ImTextureData* tex)
|
void ImGui_ImplDX12_UpdateTexture(ImTextureData* tex)
|
||||||
@@ -508,58 +539,53 @@ void ImGui_ImplDX12_UpdateTexture(ImTextureData* tex)
|
|||||||
UINT upload_pitch_dst = (upload_pitch_src + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u);
|
UINT upload_pitch_dst = (upload_pitch_src + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u);
|
||||||
UINT upload_size = upload_pitch_dst * upload_h;
|
UINT upload_size = upload_pitch_dst * upload_h;
|
||||||
|
|
||||||
D3D12_RESOURCE_DESC desc;
|
if (bd->pTexUploadBuffer == nullptr || upload_size > bd->pTexUploadBufferSize)
|
||||||
ZeroMemory(&desc, sizeof(desc));
|
{
|
||||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
if (bd->pTexUploadBufferMapped)
|
||||||
desc.Alignment = 0;
|
{
|
||||||
desc.Width = upload_size;
|
D3D12_RANGE range = { 0, bd->pTexUploadBufferSize };
|
||||||
desc.Height = 1;
|
bd->pTexUploadBuffer->Unmap(0, &range);
|
||||||
desc.DepthOrArraySize = 1;
|
bd->pTexUploadBufferMapped = nullptr;
|
||||||
desc.MipLevels = 1;
|
}
|
||||||
desc.Format = DXGI_FORMAT_UNKNOWN;
|
SafeRelease(bd->pTexUploadBuffer);
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.SampleDesc.Quality = 0;
|
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
|
||||||
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES props;
|
D3D12_RESOURCE_DESC desc;
|
||||||
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
ZeroMemory(&desc, sizeof(desc));
|
||||||
props.Type = D3D12_HEAP_TYPE_UPLOAD;
|
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||||
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
desc.Alignment = 0;
|
||||||
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
desc.Width = upload_size;
|
||||||
|
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;
|
||||||
|
|
||||||
// FIXME-OPT: Can upload buffer be reused?
|
D3D12_HEAP_PROPERTIES props;
|
||||||
ID3D12Resource* uploadBuffer = nullptr;
|
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
||||||
HRESULT hr = bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc,
|
props.Type = D3D12_HEAP_TYPE_UPLOAD;
|
||||||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&uploadBuffer));
|
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||||
|
|
||||||
// Create temporary command list and execute immediately
|
HRESULT hr = bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc,
|
||||||
ID3D12Fence* fence = nullptr;
|
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&bd->pTexUploadBuffer));
|
||||||
hr = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
HANDLE event = ::CreateEvent(0, 0, 0, 0);
|
D3D12_RANGE range = {0, upload_size};
|
||||||
IM_ASSERT(event != nullptr);
|
hr = bd->pTexUploadBuffer->Map(0, &range, &bd->pTexUploadBufferMapped);
|
||||||
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
|
bd->pTexUploadBufferSize = upload_size;
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME-OPT: Create once and reuse?
|
bd->pTexCmdAllocator->Reset();
|
||||||
ID3D12CommandAllocator* cmdAlloc = nullptr;
|
bd->pTexCmdList->Reset(bd->pTexCmdAllocator, nullptr);
|
||||||
hr = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdAlloc));
|
ID3D12GraphicsCommandList* cmdList = bd->pTexCmdList;
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
// FIXME-OPT: Can be use the one from user? (pass ID3D12GraphicsCommandList* to ImGui_ImplDX12_UpdateTextures)
|
|
||||||
ID3D12GraphicsCommandList* cmdList = nullptr;
|
|
||||||
hr = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, cmdAlloc, nullptr, IID_PPV_ARGS(&cmdList));
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
|
|
||||||
// Copy to upload buffer
|
// Copy to upload buffer
|
||||||
void* mapped = nullptr;
|
|
||||||
D3D12_RANGE range = { 0, upload_size };
|
|
||||||
hr = uploadBuffer->Map(0, &range, &mapped);
|
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
|
||||||
for (int y = 0; y < upload_h; y++)
|
for (int y = 0; y < upload_h; y++)
|
||||||
memcpy((void*)((uintptr_t)mapped + y * upload_pitch_dst), tex->GetPixelsAt(upload_x, upload_y + y), upload_pitch_src);
|
memcpy((void*)((uintptr_t)bd->pTexUploadBufferMapped + y * upload_pitch_dst), tex->GetPixelsAt(upload_x, upload_y + y), upload_pitch_src);
|
||||||
uploadBuffer->Unmap(0, &range);
|
|
||||||
|
|
||||||
if (need_barrier_before_copy)
|
if (need_barrier_before_copy)
|
||||||
{
|
{
|
||||||
@@ -576,7 +602,7 @@ void ImGui_ImplDX12_UpdateTexture(ImTextureData* tex)
|
|||||||
D3D12_TEXTURE_COPY_LOCATION srcLocation = {};
|
D3D12_TEXTURE_COPY_LOCATION srcLocation = {};
|
||||||
D3D12_TEXTURE_COPY_LOCATION dstLocation = {};
|
D3D12_TEXTURE_COPY_LOCATION dstLocation = {};
|
||||||
{
|
{
|
||||||
srcLocation.pResource = uploadBuffer;
|
srcLocation.pResource = bd->pTexUploadBuffer;
|
||||||
srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
||||||
srcLocation.PlacedFootprint.Footprint.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
srcLocation.PlacedFootprint.Footprint.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
srcLocation.PlacedFootprint.Footprint.Width = upload_w;
|
srcLocation.PlacedFootprint.Footprint.Width = upload_w;
|
||||||
@@ -600,26 +626,20 @@ void ImGui_ImplDX12_UpdateTexture(ImTextureData* tex)
|
|||||||
cmdList->ResourceBarrier(1, &barrier);
|
cmdList->ResourceBarrier(1, &barrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = cmdList->Close();
|
HRESULT hr = cmdList->Close();
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
|
|
||||||
ID3D12CommandQueue* cmdQueue = bd->pCommandQueue;
|
ID3D12CommandQueue* cmdQueue = bd->pCommandQueue;
|
||||||
cmdQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
|
cmdQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
|
||||||
hr = cmdQueue->Signal(fence, 1);
|
hr = cmdQueue->Signal(bd->Fence, ++bd->FenceLastSignaledValue);
|
||||||
IM_ASSERT(SUCCEEDED(hr));
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
|
|
||||||
// FIXME-OPT: Suboptimal?
|
// FIXME-OPT: Suboptimal?
|
||||||
// - To remove this may need to create NumFramesInFlight x ImGui_ImplDX12_FrameContext in backend data (mimick docking version)
|
// - To remove this may need to create NumFramesInFlight x ImGui_ImplDX12_FrameContext in backend data (mimick docking version)
|
||||||
// - Store per-frame in flight: upload buffer?
|
// - Store per-frame in flight: upload buffer?
|
||||||
// - Where do cmdList and cmdAlloc fit?
|
// - Where do cmdList and cmdAlloc fit?
|
||||||
fence->SetEventOnCompletion(1, event);
|
bd->Fence->SetEventOnCompletion(bd->FenceLastSignaledValue, bd->FenceEvent);
|
||||||
::WaitForSingleObject(event, INFINITE);
|
::WaitForSingleObject(bd->FenceEvent, INFINITE);
|
||||||
|
|
||||||
cmdList->Release();
|
|
||||||
cmdAlloc->Release();
|
|
||||||
::CloseHandle(event);
|
|
||||||
fence->Release();
|
|
||||||
uploadBuffer->Release();
|
|
||||||
tex->SetStatus(ImTextureStatus_OK);
|
tex->SetStatus(ImTextureStatus_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,9 +652,16 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
if (!bd || !bd->pd3dDevice)
|
if (!bd || !bd->pd3dDevice)
|
||||||
return false;
|
return false;
|
||||||
if (bd->pPipelineState)
|
if (bd->pPipelineStateLinear)
|
||||||
ImGui_ImplDX12_InvalidateDeviceObjects();
|
ImGui_ImplDX12_InvalidateDeviceObjects();
|
||||||
|
|
||||||
|
HRESULT hr = ::CreateDXGIFactory1(IID_PPV_ARGS(&bd->pdxgiFactory));
|
||||||
|
IM_ASSERT(hr == S_OK);
|
||||||
|
|
||||||
|
BOOL allow_tearing = FALSE;
|
||||||
|
bd->pdxgiFactory->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allow_tearing, sizeof(allow_tearing));
|
||||||
|
bd->tearingSupport = (allow_tearing == TRUE);
|
||||||
|
|
||||||
// Create the root signature
|
// Create the root signature
|
||||||
{
|
{
|
||||||
D3D12_DESCRIPTOR_RANGE descRange = {};
|
D3D12_DESCRIPTOR_RANGE descRange = {};
|
||||||
@@ -694,7 +721,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|||||||
// (2) there exists a version of d3d12.dll for Windows 7 (D3D12On7) in one of the following directories.
|
// (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.
|
// 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
|
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++)
|
for (int i = 0; i < IM_COUNTOF(localD3d12Paths); i++)
|
||||||
if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != nullptr)
|
if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != nullptr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -714,7 +741,15 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|||||||
if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr) != S_OK)
|
if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr) != S_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignature));
|
bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignatureLinear));
|
||||||
|
blob->Release();
|
||||||
|
|
||||||
|
// Nearest sampler
|
||||||
|
staticSampler[0].Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
||||||
|
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->pRootSignatureNearest));
|
||||||
blob->Release();
|
blob->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -727,7 +762,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|||||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
|
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
|
||||||
psoDesc.NodeMask = 1;
|
psoDesc.NodeMask = 1;
|
||||||
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
||||||
psoDesc.pRootSignature = bd->pRootSignature;
|
psoDesc.pRootSignature = bd->pRootSignatureLinear;
|
||||||
psoDesc.SampleMask = UINT_MAX;
|
psoDesc.SampleMask = UINT_MAX;
|
||||||
psoDesc.NumRenderTargets = 1;
|
psoDesc.NumRenderTargets = 1;
|
||||||
psoDesc.RTVFormats[0] = bd->RTVFormat;
|
psoDesc.RTVFormats[0] = bd->RTVFormat;
|
||||||
@@ -850,12 +885,36 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|||||||
desc.BackFace = desc.FrontFace;
|
desc.BackFace = desc.FrontFace;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT result_pipeline_state = bd->pd3dDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&bd->pPipelineState));
|
HRESULT result_pipeline_state = bd->pd3dDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&bd->pPipelineStateLinear));
|
||||||
|
if (result_pipeline_state != S_OK)
|
||||||
|
{
|
||||||
|
vertexShaderBlob->Release();
|
||||||
|
pixelShaderBlob->Release();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
psoDesc.pRootSignature = bd->pRootSignatureNearest;
|
||||||
|
|
||||||
|
result_pipeline_state = bd->pd3dDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&bd->pPipelineStateNearest));
|
||||||
vertexShaderBlob->Release();
|
vertexShaderBlob->Release();
|
||||||
pixelShaderBlob->Release();
|
pixelShaderBlob->Release();
|
||||||
if (result_pipeline_state != S_OK)
|
if (result_pipeline_state != S_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Create command allocator and command list for ImGui_ImplDX12_UpdateTexture()
|
||||||
|
hr = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&bd->pTexCmdAllocator));
|
||||||
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
|
hr = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, bd->pTexCmdAllocator, nullptr, IID_PPV_ARGS(&bd->pTexCmdList));
|
||||||
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
|
hr = bd->pTexCmdList->Close();
|
||||||
|
IM_ASSERT(SUCCEEDED(hr));
|
||||||
|
|
||||||
|
// Create fence.
|
||||||
|
hr = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&bd->Fence));
|
||||||
|
IM_ASSERT(hr == S_OK);
|
||||||
|
bd->FenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||||
|
IM_ASSERT(bd->FenceEvent != nullptr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,11 +931,27 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
|
|||||||
if (!bd || !bd->pd3dDevice)
|
if (!bd || !bd->pd3dDevice)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
SafeRelease(bd->pdxgiFactory);
|
||||||
if (bd->commandQueueOwned)
|
if (bd->commandQueueOwned)
|
||||||
SafeRelease(bd->pCommandQueue);
|
SafeRelease(bd->pCommandQueue);
|
||||||
bd->commandQueueOwned = false;
|
bd->commandQueueOwned = false;
|
||||||
SafeRelease(bd->pRootSignature);
|
SafeRelease(bd->pRootSignatureLinear);
|
||||||
SafeRelease(bd->pPipelineState);
|
SafeRelease(bd->pRootSignatureNearest);
|
||||||
|
SafeRelease(bd->pPipelineStateLinear);
|
||||||
|
SafeRelease(bd->pPipelineStateNearest);
|
||||||
|
|
||||||
|
if (bd->pTexUploadBufferMapped)
|
||||||
|
{
|
||||||
|
D3D12_RANGE range = { 0, bd->pTexUploadBufferSize };
|
||||||
|
bd->pTexUploadBuffer->Unmap(0, &range);
|
||||||
|
bd->pTexUploadBufferMapped = nullptr;
|
||||||
|
}
|
||||||
|
SafeRelease(bd->pTexUploadBuffer);
|
||||||
|
SafeRelease(bd->pTexCmdList);
|
||||||
|
SafeRelease(bd->pTexCmdAllocator);
|
||||||
|
SafeRelease(bd->Fence);
|
||||||
|
CloseHandle(bd->FenceEvent);
|
||||||
|
bd->FenceEvent = nullptr;
|
||||||
|
|
||||||
// Destroy all textures
|
// Destroy all textures
|
||||||
for (ImTextureData* tex : ImGui::GetPlatformIO().Textures)
|
for (ImTextureData* tex : ImGui::GetPlatformIO().Textures)
|
||||||
@@ -918,12 +993,13 @@ bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* init_info)
|
|||||||
init_info = &bd->InitInfo;
|
init_info = &bd->InitInfo;
|
||||||
|
|
||||||
bd->pd3dDevice = init_info->Device;
|
bd->pd3dDevice = init_info->Device;
|
||||||
IM_ASSERT(init_info->CommandQueue != NULL);
|
IM_ASSERT(init_info->CommandQueue != nullptr);
|
||||||
bd->pCommandQueue = init_info->CommandQueue;
|
bd->pCommandQueue = init_info->CommandQueue;
|
||||||
bd->RTVFormat = init_info->RTVFormat;
|
bd->RTVFormat = init_info->RTVFormat;
|
||||||
bd->DSVFormat = init_info->DSVFormat;
|
bd->DSVFormat = init_info->DSVFormat;
|
||||||
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
||||||
bd->pd3dSrvDescHeap = init_info->SrvDescriptorHeap;
|
bd->pd3dSrvDescHeap = init_info->SrvDescriptorHeap;
|
||||||
|
bd->tearingSupport = false;
|
||||||
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
io.BackendRendererUserData = (void*)bd;
|
||||||
io.BackendRendererName = "imgui_impl_dx12";
|
io.BackendRendererName = "imgui_impl_dx12";
|
||||||
@@ -932,13 +1008,18 @@ bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* init_info)
|
|||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||||
|
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
ImGui_ImplDX12_InitPlatformInterface();
|
ImGui_ImplDX12_InitMultiViewportSupport();
|
||||||
|
|
||||||
// Create a dummy ImGui_ImplDX12_ViewportData holder for the main viewport,
|
// Create a dummy ImGui_ImplDX12_ViewportData holder for the main viewport,
|
||||||
// Since this is created and managed by the application, we will only use the ->Resources[] fields.
|
// Since this is created and managed by the application, we will only use the ->Resources[] fields.
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
main_viewport->RendererUserData = IM_NEW(ImGui_ImplDX12_ViewportData)(bd->numFramesInFlight);
|
main_viewport->RendererUserData = IM_NEW(ImGui_ImplDX12_ViewportData)(bd->numFramesInFlight);
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplDX12_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplDX12_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplDX12_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
if (init_info->SrvDescriptorAllocFn == nullptr)
|
if (init_info->SrvDescriptorAllocFn == nullptr)
|
||||||
ImGui_ImplDX12_InitLegacySingleDescriptorMode(init_info);
|
ImGui_ImplDX12_InitLegacySingleDescriptorMode(init_info);
|
||||||
@@ -971,6 +1052,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
|||||||
bool ret = ImGui_ImplDX12_Init(&init_info);
|
bool ret = ImGui_ImplDX12_Init(&init_info);
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
bd->commandQueueOwned = true;
|
bd->commandQueueOwned = true;
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasTextures; // Using legacy ImGui_ImplDX12_Init() call with 1 SRV descriptor we cannot support multiple textures.
|
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasTextures; // Using legacy ImGui_ImplDX12_Init() call with 1 SRV descriptor we cannot support multiple textures.
|
||||||
|
|
||||||
@@ -983,6 +1065,7 @@ void ImGui_ImplDX12_Shutdown()
|
|||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
// Manually delete main viewport render resources in-case we haven't initialized for viewports
|
// Manually delete main viewport render resources in-case we haven't initialized for viewports
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
@@ -995,13 +1078,13 @@ void ImGui_ImplDX12_Shutdown()
|
|||||||
main_viewport->RendererUserData = nullptr;
|
main_viewport->RendererUserData = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up windows and device objects
|
ImGui_ImplDX12_ShutdownMultiViewportSupport();
|
||||||
ImGui_ImplDX12_ShutdownPlatformInterface();
|
|
||||||
ImGui_ImplDX12_InvalidateDeviceObjects();
|
ImGui_ImplDX12_InvalidateDeviceObjects();
|
||||||
|
|
||||||
io.BackendRendererName = nullptr;
|
io.BackendRendererName = nullptr;
|
||||||
io.BackendRendererUserData = nullptr;
|
io.BackendRendererUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1010,7 +1093,7 @@ void ImGui_ImplDX12_NewFrame()
|
|||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplDX12_Init()?");
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplDX12_Init()?");
|
||||||
|
|
||||||
if (!bd->pPipelineState)
|
if (!bd->pPipelineStateLinear)
|
||||||
if (!ImGui_ImplDX12_CreateDeviceObjects())
|
if (!ImGui_ImplDX12_CreateDeviceObjects())
|
||||||
IM_ASSERT(0 && "ImGui_ImplDX12_CreateDeviceObjects() failed!");
|
IM_ASSERT(0 && "ImGui_ImplDX12_CreateDeviceObjects() failed!");
|
||||||
}
|
}
|
||||||
@@ -1032,18 +1115,12 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
|
HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
|
||||||
IM_ASSERT(hwnd != 0);
|
IM_ASSERT(hwnd != 0);
|
||||||
|
|
||||||
vd->FrameIndex = UINT_MAX;
|
// Use shared command queue from init info
|
||||||
|
vd->FrameIndex = 0;
|
||||||
// Create command queue.
|
vd->CommandQueue = bd->pCommandQueue;
|
||||||
D3D12_COMMAND_QUEUE_DESC queue_desc = {};
|
|
||||||
queue_desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
|
||||||
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
|
||||||
|
|
||||||
HRESULT res = S_OK;
|
|
||||||
res = bd->pd3dDevice->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&vd->CommandQueue));
|
|
||||||
IM_ASSERT(res == S_OK);
|
|
||||||
|
|
||||||
// Create command allocator.
|
// Create command allocator.
|
||||||
|
HRESULT res = S_OK;
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; ++i)
|
for (UINT i = 0; i < bd->numFramesInFlight; ++i)
|
||||||
{
|
{
|
||||||
res = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&vd->FrameCtx[i].CommandAllocator));
|
res = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&vd->FrameCtx[i].CommandAllocator));
|
||||||
@@ -1055,13 +1132,6 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
vd->CommandList->Close();
|
vd->CommandList->Close();
|
||||||
|
|
||||||
// Create fence.
|
|
||||||
res = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&vd->Fence));
|
|
||||||
IM_ASSERT(res == S_OK);
|
|
||||||
|
|
||||||
vd->FenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
|
||||||
IM_ASSERT(vd->FenceEvent != nullptr);
|
|
||||||
|
|
||||||
// Create swap chain
|
// Create swap chain
|
||||||
// FIXME-VIEWPORT: May want to copy/inherit swap chain settings from the user/application.
|
// FIXME-VIEWPORT: May want to copy/inherit swap chain settings from the user/application.
|
||||||
DXGI_SWAP_CHAIN_DESC1 sd1;
|
DXGI_SWAP_CHAIN_DESC1 sd1;
|
||||||
@@ -1077,23 +1147,23 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
sd1.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
|
sd1.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
|
||||||
sd1.Scaling = DXGI_SCALING_NONE;
|
sd1.Scaling = DXGI_SCALING_NONE;
|
||||||
sd1.Stereo = FALSE;
|
sd1.Stereo = FALSE;
|
||||||
|
sd1.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
|
||||||
|
|
||||||
IDXGIFactory4* dxgi_factory = nullptr;
|
if (bd->tearingSupport)
|
||||||
res = ::CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory));
|
sd1.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
|
||||||
IM_ASSERT(res == S_OK);
|
|
||||||
|
|
||||||
IDXGISwapChain1* swap_chain = nullptr;
|
IDXGISwapChain1* swap_chain = nullptr;
|
||||||
res = dxgi_factory->CreateSwapChainForHwnd(vd->CommandQueue, hwnd, &sd1, nullptr, nullptr, &swap_chain);
|
res = bd->pdxgiFactory->CreateSwapChainForHwnd(vd->CommandQueue, hwnd, &sd1, nullptr, nullptr, &swap_chain);
|
||||||
|
IM_ASSERT(res == S_OK);
|
||||||
|
res = bd->pdxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES); // Disable e.g. Alt+Enter
|
||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
|
|
||||||
dxgi_factory->Release();
|
|
||||||
|
|
||||||
// Or swapChain.As(&mSwapChain)
|
// Or swapChain.As(&mSwapChain)
|
||||||
IM_ASSERT(vd->SwapChain == nullptr);
|
IM_ASSERT(vd->SwapChain == nullptr);
|
||||||
swap_chain->QueryInterface(IID_PPV_ARGS(&vd->SwapChain));
|
swap_chain->QueryInterface(IID_PPV_ARGS(&vd->SwapChain));
|
||||||
swap_chain->Release();
|
swap_chain->Release();
|
||||||
|
|
||||||
// Create the render targets
|
// Create the render targets and waitable object
|
||||||
if (vd->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||||
@@ -1121,6 +1191,10 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
bd->pd3dDevice->CreateRenderTargetView(back_buffer, nullptr, vd->FrameCtx[i].RenderTargetCpuDescriptors);
|
bd->pd3dDevice->CreateRenderTargetView(back_buffer, nullptr, vd->FrameCtx[i].RenderTargetCpuDescriptors);
|
||||||
vd->FrameCtx[i].RenderTarget = back_buffer;
|
vd->FrameCtx[i].RenderTarget = back_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hr = vd->SwapChain->SetMaximumFrameLatency(bd->numFramesInFlight);
|
||||||
|
IM_ASSERT(hr == S_OK);
|
||||||
|
vd->SwapChainWaitableObject = vd->SwapChain->GetFrameLatencyWaitableObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
@@ -1129,16 +1203,31 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
static void ImGui_WaitForPendingOperations(ImGui_ImplDX12_ViewportData* vd)
|
static void ImGui_WaitForPendingOperations(ImGui_ImplDX12_ViewportData* vd)
|
||||||
{
|
{
|
||||||
HRESULT hr = S_FALSE;
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
if (vd && vd->CommandQueue && vd->Fence && vd->FenceEvent)
|
HRESULT hr = vd->CommandQueue->Signal(bd->Fence, ++bd->FenceLastSignaledValue);
|
||||||
|
IM_ASSERT(hr == S_OK);
|
||||||
|
|
||||||
|
hr = bd->Fence->SetEventOnCompletion(bd->FenceLastSignaledValue, bd->FenceEvent);
|
||||||
|
IM_ASSERT(hr == S_OK);
|
||||||
|
::WaitForSingleObject(bd->FenceEvent, INFINITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImGui_ImplDX12_FrameContext* ImGui_WaitForNextFrameContext(ImGui_ImplDX12_ViewportData* vd)
|
||||||
|
{
|
||||||
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
|
ImGui_ImplDX12_FrameContext* frame_context = &vd->FrameCtx[vd->FrameIndex % vd->NumFramesInFlight];
|
||||||
|
if (bd->Fence->GetCompletedValue() < frame_context->FenceValue)
|
||||||
{
|
{
|
||||||
hr = vd->CommandQueue->Signal(vd->Fence, ++vd->FenceSignaledValue);
|
HRESULT hr = bd->Fence->SetEventOnCompletion(frame_context->FenceValue, bd->FenceEvent);
|
||||||
IM_ASSERT(hr == S_OK);
|
IM_ASSERT(hr == S_OK);
|
||||||
::WaitForSingleObject(vd->FenceEvent, 0); // Reset any forgotten waits
|
HANDLE waitableObjects[] = { vd->SwapChainWaitableObject, bd->FenceEvent };
|
||||||
hr = vd->Fence->SetEventOnCompletion(vd->FenceSignaledValue, vd->FenceEvent);
|
::WaitForMultipleObjects(2, waitableObjects, TRUE, INFINITE);
|
||||||
IM_ASSERT(hr == S_OK);
|
|
||||||
::WaitForSingleObject(vd->FenceEvent, INFINITE);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
::WaitForSingleObject(vd->SwapChainWaitableObject, INFINITE);
|
||||||
|
}
|
||||||
|
return frame_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport)
|
||||||
@@ -1149,13 +1238,12 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
{
|
{
|
||||||
ImGui_WaitForPendingOperations(vd);
|
ImGui_WaitForPendingOperations(vd);
|
||||||
|
|
||||||
SafeRelease(vd->CommandQueue);
|
vd->CommandQueue = nullptr;
|
||||||
|
::CloseHandle(vd->SwapChainWaitableObject);
|
||||||
|
vd->SwapChainWaitableObject = nullptr;
|
||||||
SafeRelease(vd->CommandList);
|
SafeRelease(vd->CommandList);
|
||||||
SafeRelease(vd->SwapChain);
|
SafeRelease(vd->SwapChain);
|
||||||
SafeRelease(vd->RtvDescHeap);
|
SafeRelease(vd->RtvDescHeap);
|
||||||
SafeRelease(vd->Fence);
|
|
||||||
::CloseHandle(vd->FenceEvent);
|
|
||||||
vd->FenceEvent = nullptr;
|
|
||||||
|
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
{
|
{
|
||||||
@@ -1181,7 +1269,9 @@ static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|||||||
if (vd->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
ID3D12Resource* back_buffer = nullptr;
|
ID3D12Resource* back_buffer = nullptr;
|
||||||
vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
|
DXGI_SWAP_CHAIN_DESC1 desc = {};
|
||||||
|
vd->SwapChain->GetDesc1(&desc);
|
||||||
|
vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, desc.Format, desc.Flags);
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
{
|
{
|
||||||
vd->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer));
|
vd->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer));
|
||||||
@@ -1196,7 +1286,7 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*)
|
|||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData;
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData;
|
||||||
|
|
||||||
ImGui_ImplDX12_FrameContext* frame_context = &vd->FrameCtx[vd->FrameIndex % bd->numFramesInFlight];
|
ImGui_ImplDX12_FrameContext* frame_context = ImGui_WaitForNextFrameContext(vd);
|
||||||
UINT back_buffer_idx = vd->SwapChain->GetCurrentBackBufferIndex();
|
UINT back_buffer_idx = vd->SwapChain->GetCurrentBackBufferIndex();
|
||||||
|
|
||||||
const ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
const ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
@@ -1226,21 +1316,22 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*)
|
|||||||
cmd_list->ResourceBarrier(1, &barrier);
|
cmd_list->ResourceBarrier(1, &barrier);
|
||||||
cmd_list->Close();
|
cmd_list->Close();
|
||||||
|
|
||||||
vd->CommandQueue->Wait(vd->Fence, vd->FenceSignaledValue);
|
|
||||||
vd->CommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmd_list);
|
vd->CommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmd_list);
|
||||||
vd->CommandQueue->Signal(vd->Fence, ++vd->FenceSignaledValue);
|
|
||||||
|
HRESULT hr = vd->CommandQueue->Signal(bd->Fence, ++bd->FenceLastSignaledValue);
|
||||||
|
IM_ASSERT(hr == S_OK);
|
||||||
|
frame_context->FenceValue = bd->FenceLastSignaledValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData;
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData;
|
||||||
|
|
||||||
vd->SwapChain->Present(0, 0);
|
vd->SwapChain->Present(0, bd->tearingSupport ? DXGI_PRESENT_ALLOW_TEARING : 0);
|
||||||
while (vd->Fence->GetCompletedValue() < vd->FenceSignaledValue)
|
|
||||||
::SwitchToThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX12_InitPlatformInterface()
|
void ImGui_ImplDX12_InitMultiViewportSupport()
|
||||||
{
|
{
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
platform_io.Renderer_CreateWindow = ImGui_ImplDX12_CreateWindow;
|
platform_io.Renderer_CreateWindow = ImGui_ImplDX12_CreateWindow;
|
||||||
@@ -1250,7 +1341,7 @@ void ImGui_ImplDX12_InitPlatformInterface()
|
|||||||
platform_io.Renderer_SwapBuffers = ImGui_ImplDX12_SwapBuffers;
|
platform_io.Renderer_SwapBuffers = ImGui_ImplDX12_SwapBuffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX12_ShutdownPlatformInterface()
|
void ImGui_ImplDX12_ShutdownMultiViewportSupport()
|
||||||
{
|
{
|
||||||
ImGui::DestroyPlatformWindows();
|
ImGui::DestroyPlatformWindows();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
#include <dxgiformat.h> // DXGI_FORMAT
|
#include <dxgiformat.h> // DXGI_FORMAT
|
||||||
#include <d3d12.h> // D3D12_CPU_DESCRIPTOR_HANDLE
|
#include <d3d12.h> // D3D12_CPU_DESCRIPTOR_HANDLE
|
||||||
|
|
||||||
|
// 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
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialization data, for ImGui_ImplDX12_Init()
|
// Initialization data, for ImGui_ImplDX12_Init()
|
||||||
struct ImGui_ImplDX12_InitInfo
|
struct ImGui_ImplDX12_InitInfo
|
||||||
{
|
{
|
||||||
@@ -65,7 +71,7 @@ IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX12_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplDX12_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
@@ -77,4 +83,8 @@ struct ImGui_ImplDX12_RenderState
|
|||||||
ID3D12GraphicsCommandList* CommandList;
|
ID3D12GraphicsCommandList* CommandList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -18,7 +18,10 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. (#9378)
|
||||||
|
// 2026-03-19: Fixed issue in ImGui_ImplDX9_UpdateTexture() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295, #9310)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-11: DirectX9: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
// 2025-06-11: DirectX9: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
||||||
// 2024-10-07: DirectX9: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
// 2024-10-07: DirectX9: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
||||||
// 2024-02-12: DirectX9: Using RGBA format when supported by the driver to avoid CPU side conversion. (#6575)
|
// 2024-02-12: DirectX9: Using RGBA format when supported by the driver to avoid CPU side conversion. (#6575)
|
||||||
@@ -168,6 +171,11 @@ static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplDX9_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplDX9_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData(); bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); }
|
||||||
|
static void ImGui_ImplDX9_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData(); bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); }
|
||||||
|
|
||||||
// Render function.
|
// Render function.
|
||||||
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
@@ -190,14 +198,14 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
|||||||
{
|
{
|
||||||
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
|
||||||
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||||
if (device->CreateVertexBuffer(bd->VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &bd->pVB, nullptr) < 0)
|
if (device->CreateVertexBuffer((UINT)bd->VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &bd->pVB, nullptr) < 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
|
if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
|
||||||
{
|
{
|
||||||
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
|
||||||
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||||
if (device->CreateIndexBuffer(bd->IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &bd->pIB, nullptr) < 0)
|
if (device->CreateIndexBuffer((UINT)bd->IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &bd->pIB, nullptr) < 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,8 +283,7 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (pcmd->UserCallback != nullptr)
|
if (pcmd->UserCallback != nullptr)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplDX9_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplDX9_SetupRenderState(draw_data);
|
ImGui_ImplDX9_SetupRenderState(draw_data);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -336,47 +343,6 @@ static bool ImGui_ImplDX9_CheckFormatSupport(LPDIRECT3DDEVICE9 pDevice, D3DFORMA
|
|||||||
return support;
|
return support;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
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.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
|
||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
|
||||||
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = 4096;
|
|
||||||
|
|
||||||
bd->pd3dDevice = device;
|
|
||||||
bd->pd3dDevice->AddRef();
|
|
||||||
bd->HasRgbaSupport = ImGui_ImplDX9_CheckFormatSupport(bd->pd3dDevice, D3DFMT_A8B8G8R8);
|
|
||||||
|
|
||||||
ImGui_ImplDX9_InitMultiViewportSupport();
|
|
||||||
|
|
||||||
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_ShutdownMultiViewportSupport();
|
|
||||||
ImGui_ImplDX9_InvalidateDeviceObjects();
|
|
||||||
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert RGBA32 to BGRA32 (because RGBA32 is not well supported by DX9 devices)
|
// Convert RGBA32 to BGRA32 (because RGBA32 is not well supported by DX9 devices)
|
||||||
static void ImGui_ImplDX9_CopyTextureRegion(bool tex_use_colors, const ImU32* src, int src_pitch, ImU32* dst, int dst_pitch, int w, int h)
|
static void ImGui_ImplDX9_CopyTextureRegion(bool tex_use_colors, const ImU32* src, int src_pitch, ImU32* dst, int dst_pitch, int w, int h)
|
||||||
{
|
{
|
||||||
@@ -444,14 +410,15 @@ void ImGui_ImplDX9_UpdateTexture(ImTextureData* tex)
|
|||||||
}
|
}
|
||||||
else if (tex->Status == ImTextureStatus_WantDestroy)
|
else if (tex->Status == ImTextureStatus_WantDestroy)
|
||||||
{
|
{
|
||||||
LPDIRECT3DTEXTURE9 backend_tex = (LPDIRECT3DTEXTURE9)tex->TexID;
|
if (tex->TexID != ImTextureID_Invalid)
|
||||||
if (backend_tex == nullptr)
|
if (LPDIRECT3DTEXTURE9 backend_tex = (LPDIRECT3DTEXTURE9)tex->TexID)
|
||||||
return;
|
{
|
||||||
IM_ASSERT(tex->TexID == (ImTextureID)(intptr_t)backend_tex);
|
IM_ASSERT(tex->TexID == (ImTextureID)(intptr_t)backend_tex);
|
||||||
backend_tex->Release();
|
backend_tex->Release();
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
}
|
||||||
tex->SetStatus(ImTextureStatus_Destroyed);
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,6 +457,53 @@ void ImGui_ImplDX9_NewFrame()
|
|||||||
IM_UNUSED(bd);
|
IM_UNUSED(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
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.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = 4096;
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplDX9_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplDX9_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplDX9_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
|
bd->pd3dDevice = device;
|
||||||
|
bd->pd3dDevice->AddRef();
|
||||||
|
bd->HasRgbaSupport = ImGui_ImplDX9_CheckFormatSupport(bd->pd3dDevice, D3DFMT_A8B8G8R8);
|
||||||
|
|
||||||
|
ImGui_ImplDX9_InitMultiViewportSupport();
|
||||||
|
|
||||||
|
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();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplDX9_ShutdownMultiViewportSupport();
|
||||||
|
ImGui_ImplDX9_InvalidateDeviceObjects();
|
||||||
|
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
||||||
// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
|
// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplDX9_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
// dear imgui: Platform Backend for GLFW
|
// dear imgui: Platform Backend for GLFW
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
||||||
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||||
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ or GLFW 3.4+ for full feature support.)
|
// (Requires: GLFW 3.0+. Prefer GLFW 3.3+/3.4+ for full feature support.)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Platform: Clipboard support.
|
// [X] Platform: Clipboard support.
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
|
// [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 are obsolete since 1.87 and not supported since 1.91.5]
|
// [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 are obsolete since 1.87 and not supported since 1.91.5]
|
||||||
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||||
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors) with GLFW 3.1+. Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// [X] Multiple Dear ImGui contexts support.
|
// [X] Multiple Dear ImGui contexts support.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Touch events are only correctly identified as Touch on Windows. This create issues with some interactions. GLFW doesn't provide a way to identify touch inputs from mouse inputs, we cannot call io.AddMouseSourceEvent() to identify the source. We provide a Windows-specific workaround.
|
// [ ] Platform: Touch events are only correctly identified as Touch on Windows. This create issues with some interactions. GLFW doesn't provide a way to identify touch inputs from mouse inputs, we cannot call io.AddMouseSourceEvent() to identify the source. We provide a Windows-specific workaround.
|
||||||
// [ ] Missing ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress cursors.
|
// [ ] Platform: Missing ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress cursors.
|
||||||
// [ ] Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
// [ ] Platform: Multi-viewport: Missing ImGuiBackendFlags_HasParentViewport support. The viewport->ParentViewportID field is ignored, and therefore io.ConfigViewportsNoDefaultParent has no effect either.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -31,7 +31,16 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-21: Added a Win32-specific implementation of ImGui_ImplGlfw_GetContentScaleXXXX functions for legacy GLFW 3.2.
|
||||||
|
// 2026-03-25: Mouse cursor is properly restored if changed by user app/code while using glfwSetInputMode(..., GLFW_CURSOR_DISABLED) or ImGuiConfigFlags_NoMouseCursorChange. Amend change from 2025-12-10.
|
||||||
|
// 2026-02-10: Try to set IMGUI_IMPL_GLFW_DISABLE_X11 / IMGUI_IMPL_GLFW_DISABLE_WAYLAND automatically if corresponding headers are not accessible. (#9225)
|
||||||
|
// 2026-01-25: [Docking] Improve workarounds for cases where GLFW is unable to provide any reliable monitor info. Preserve existing monitor list when none of the new one is valid. (#9195, #7902, #5683)
|
||||||
|
// 2026-01-18: [Docking] Dynamically load X11 functions to avoid -lx11 linking requirement introduced on 2025-09-10.
|
||||||
|
// 2025-12-12: Added IMGUI_IMPL_GLFW_DISABLE_X11 / IMGUI_IMPL_GLFW_DISABLE_WAYLAND to forcefully disable either.
|
||||||
|
// 2025-12-10: Avoid repeated glfwSetCursor()/glfwSetInputMode() calls when unnecessary. Lowers overhead for very high framerates (e.g. 10k+ FPS).
|
||||||
|
// 2025-11-06: Lower minimum requirement to GLFW 3.0. Though a recent version e.g GLFW 3.4 is highly recommended.
|
||||||
|
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
// 2025-09-15: Content Scales are always reported as 1.0 on Wayland. FramebufferScale are always reported as 1.0 on X11. (#8920, #8921)
|
// 2025-09-15: Content Scales are always reported as 1.0 on Wayland. FramebufferScale are always reported as 1.0 on X11. (#8920, #8921)
|
||||||
// 2025-09-10: [Docking] Improve multi-viewport behavior in tiling WMs on X11 via the ImGui_ImplGlfw_SetWindowFloating() function. Note: using GLFW backend on Linux/BSD etc. requires linking with -lX11. (#8884, #8474, #8289)
|
// 2025-09-10: [Docking] Improve multi-viewport behavior in tiling WMs on X11 via the ImGui_ImplGlfw_SetWindowFloating() function. Note: using GLFW backend on Linux/BSD etc. requires linking with -lX11. (#8884, #8474, #8289)
|
||||||
// 2025-07-08: Made ImGui_ImplGlfw_GetContentScaleForWindow(), ImGui_ImplGlfw_GetContentScaleForMonitor() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
|
// 2025-07-08: Made ImGui_ImplGlfw_GetContentScaleForWindow(), ImGui_ImplGlfw_GetContentScaleForMonitor() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
|
||||||
@@ -108,13 +117,34 @@
|
|||||||
// Clang warnings with -Weverything
|
// Clang warnings with -Weverything
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
#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 "-Wsign-conversion" // warning: implicit conversion changes signedness
|
||||||
|
#pragma clang diagnostic ignored "-Wexit-time-destructors" // warning: declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
|
||||||
|
#pragma clang diagnostic ignored "-Wglobal-constructors" // warning: declaration requires a global destructor // similar to above, not sure what the exact difference is.
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
#pragma GCC diagnostic ignored "-Wfloat-equal" // warning: comparing floating-point with '==' or '!=' is unsafe
|
#pragma GCC diagnostic ignored "-Wfloat-equal" // warning: comparing floating-point with '==' or '!=' is unsafe
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__has_include)
|
||||||
|
#if !__has_include(<X11/Xlib.h>) || !__has_include(<X11/extensions/Xrandr.h>)
|
||||||
|
#define IMGUI_IMPL_GLFW_DISABLE_X11
|
||||||
|
#endif
|
||||||
|
#if !__has_include(<wayland-client.h>)
|
||||||
|
#define IMGUI_IMPL_GLFW_DISABLE_WAYLAND
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// GLFW
|
// GLFW
|
||||||
|
#if !defined(IMGUI_IMPL_GLFW_DISABLE_X11) && (defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__))
|
||||||
|
#define GLFW_HAS_X11 1
|
||||||
|
#else
|
||||||
|
#define GLFW_HAS_X11 0
|
||||||
|
#endif
|
||||||
|
#if !defined(IMGUI_IMPL_GLFW_DISABLE_WAYLAND) && (defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__))
|
||||||
|
#define GLFW_HAS_WAYLAND 1
|
||||||
|
#else
|
||||||
|
#define GLFW_HAS_WAYLAND 0
|
||||||
|
#endif
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#undef APIENTRY
|
#undef APIENTRY
|
||||||
@@ -127,13 +157,11 @@
|
|||||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||||
#endif
|
#endif
|
||||||
#include <GLFW/glfw3native.h>
|
#include <GLFW/glfw3native.h>
|
||||||
#elif !defined(__EMSCRIPTEN__)
|
#elif GLFW_HAS_X11
|
||||||
#ifndef GLFW_EXPOSE_NATIVE_X11 // for glfwGetX11Window() on Freedesktop (Linux, BSD, etc.)
|
#ifndef GLFW_EXPOSE_NATIVE_X11 // for glfwGetX11Display(), glfwGetX11Window() on Freedesktop (Linux, BSD, etc.)
|
||||||
#define GLFW_EXPOSE_NATIVE_X11
|
#define GLFW_EXPOSE_NATIVE_X11
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
#endif
|
#include <dlfcn.h> // for dlopen()
|
||||||
#ifndef GLFW_EXPOSE_NATIVE_WAYLAND
|
|
||||||
#define GLFW_EXPOSE_NATIVE_WAYLAND
|
|
||||||
#endif
|
#endif
|
||||||
#include <GLFW/glfw3native.h>
|
#include <GLFW/glfw3native.h>
|
||||||
#undef Status // X11 headers are leaking this.
|
#undef Status // X11 headers are leaking this.
|
||||||
@@ -156,6 +184,7 @@
|
|||||||
|
|
||||||
// We gather version tests as define in order to easily see which features are version-dependent.
|
// 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)
|
#define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION)
|
||||||
|
#define GLFW_HAS_CREATECURSOR (GLFW_VERSION_COMBINED >= 3100) // 3.1+ glfwCreateCursor()
|
||||||
#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_COMBINED >= 3200) // 3.2+ GLFW_FLOATING
|
#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_COMBINED >= 3200) // 3.2+ GLFW_FLOATING
|
||||||
#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_COMBINED >= 3300) // 3.3+ GLFW_HOVERED
|
#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_COMBINED >= 3300) // 3.3+ GLFW_HOVERED
|
||||||
#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwSetWindowOpacity
|
#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwSetWindowOpacity
|
||||||
@@ -183,11 +212,6 @@
|
|||||||
#define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName()
|
#define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName()
|
||||||
#define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError()
|
#define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError()
|
||||||
#define GLFW_HAS_GETPLATFORM (GLFW_VERSION_COMBINED >= 3400) // 3.4+ glfwGetPlatform()
|
#define GLFW_HAS_GETPLATFORM (GLFW_VERSION_COMBINED >= 3400) // 3.4+ glfwGetPlatform()
|
||||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
|
||||||
#define GLFW_HAS_X11_OR_WAYLAND 1
|
|
||||||
#else
|
|
||||||
#define GLFW_HAS_X11_OR_WAYLAND 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Map GLFWWindow* to ImGuiContext*.
|
// Map GLFWWindow* to ImGuiContext*.
|
||||||
// - Would be simpler if we could use glfwSetWindowUserPointer()/glfwGetWindowUserPointer(), but this is a single and shared resource.
|
// - Would be simpler if we could use glfwSetWindowUserPointer()/glfwGetWindowUserPointer(), but this is a single and shared resource.
|
||||||
@@ -196,7 +220,7 @@
|
|||||||
struct ImGui_ImplGlfw_WindowToContext { GLFWwindow* Window; ImGuiContext* Context; };
|
struct ImGui_ImplGlfw_WindowToContext { GLFWwindow* Window; ImGuiContext* Context; };
|
||||||
static ImVector<ImGui_ImplGlfw_WindowToContext> g_ContextMap;
|
static ImVector<ImGui_ImplGlfw_WindowToContext> g_ContextMap;
|
||||||
static void ImGui_ImplGlfw_ContextMap_Add(GLFWwindow* window, ImGuiContext* ctx) { g_ContextMap.push_back(ImGui_ImplGlfw_WindowToContext{ window, ctx }); }
|
static void ImGui_ImplGlfw_ContextMap_Add(GLFWwindow* window, ImGuiContext* ctx) { g_ContextMap.push_back(ImGui_ImplGlfw_WindowToContext{ window, ctx }); }
|
||||||
static void ImGui_ImplGlfw_ContextMap_Remove(GLFWwindow* window) { for (ImGui_ImplGlfw_WindowToContext& entry : g_ContextMap) if (entry.Window == window) { g_ContextMap.erase_unsorted(&entry); return; } }
|
static void ImGui_ImplGlfw_ContextMap_Remove(GLFWwindow* window) { for (ImGui_ImplGlfw_WindowToContext& entry : g_ContextMap) if (entry.Window == window) { g_ContextMap.erase_unsorted(&entry); if (g_ContextMap.empty()) g_ContextMap.clear(); return; } }
|
||||||
static ImGuiContext* ImGui_ImplGlfw_ContextMap_Get(GLFWwindow* window) { for (ImGui_ImplGlfw_WindowToContext& entry : g_ContextMap) if (entry.Window == window) return entry.Context; return nullptr; }
|
static ImGuiContext* ImGui_ImplGlfw_ContextMap_Get(GLFWwindow* window) { for (ImGui_ImplGlfw_WindowToContext& entry : g_ContextMap) if (entry.Window == window) return entry.Context; return nullptr; }
|
||||||
|
|
||||||
enum GlfwClientApi
|
enum GlfwClientApi
|
||||||
@@ -206,6 +230,13 @@ enum GlfwClientApi
|
|||||||
GlfwClientApi_Unknown, // Anything else fits here.
|
GlfwClientApi_Unknown, // Anything else fits here.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if GLFW_HAS_X11
|
||||||
|
typedef Atom (*PFN_XInternAtom)(Display*, const char* ,Bool);
|
||||||
|
typedef int (*PFN_XChangeProperty)(Display*, Window, Atom, Atom, int, int, const unsigned char*, int);
|
||||||
|
typedef int (*PFN_XChangeWindowAttributes)(Display*, Window, unsigned long, XSetWindowAttributes*);
|
||||||
|
typedef int (*PFN_XFlush)(Display*);
|
||||||
|
#endif
|
||||||
|
|
||||||
// GLFW data
|
// GLFW data
|
||||||
struct ImGui_ImplGlfw_Data
|
struct ImGui_ImplGlfw_Data
|
||||||
{
|
{
|
||||||
@@ -214,7 +245,10 @@ struct ImGui_ImplGlfw_Data
|
|||||||
GlfwClientApi ClientApi;
|
GlfwClientApi ClientApi;
|
||||||
double Time;
|
double Time;
|
||||||
GLFWwindow* MouseWindow;
|
GLFWwindow* MouseWindow;
|
||||||
|
#if GLFW_HAS_CREATECURSOR
|
||||||
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||||||
|
GLFWcursor* LastMouseCursor;
|
||||||
|
#endif
|
||||||
bool MouseIgnoreButtonUpWaitForFocusLoss;
|
bool MouseIgnoreButtonUpWaitForFocusLoss;
|
||||||
bool MouseIgnoreButtonUp;
|
bool MouseIgnoreButtonUp;
|
||||||
ImVec2 LastValidMousePos;
|
ImVec2 LastValidMousePos;
|
||||||
@@ -222,7 +256,7 @@ struct ImGui_ImplGlfw_Data
|
|||||||
bool IsWayland;
|
bool IsWayland;
|
||||||
bool InstalledCallbacks;
|
bool InstalledCallbacks;
|
||||||
bool CallbacksChainForAllWindows;
|
bool CallbacksChainForAllWindows;
|
||||||
char BackendPlatformName[32];
|
char BackendPlatformName[40];
|
||||||
#ifdef EMSCRIPTEN_USE_EMBEDDED_GLFW3
|
#ifdef EMSCRIPTEN_USE_EMBEDDED_GLFW3
|
||||||
const char* CanvasSelector;
|
const char* CanvasSelector;
|
||||||
#endif
|
#endif
|
||||||
@@ -240,6 +274,15 @@ struct ImGui_ImplGlfw_Data
|
|||||||
WNDPROC PrevWndProc;
|
WNDPROC PrevWndProc;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GLFW_HAS_X11
|
||||||
|
// Module and function pointers loaded at initialization to avoid linking statically with X11.
|
||||||
|
void* X11Module;
|
||||||
|
PFN_XInternAtom XInternAtom;
|
||||||
|
PFN_XChangeProperty XChangeProperty;
|
||||||
|
PFN_XChangeWindowAttributes XChangeWindowAttributes;
|
||||||
|
PFN_XFlush XFlush;
|
||||||
|
#endif
|
||||||
|
|
||||||
ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -271,16 +314,16 @@ static void ImGui_ImplGlfw_ShutdownMultiViewportSupport();
|
|||||||
// Functions
|
// Functions
|
||||||
static bool ImGui_ImplGlfw_IsWayland()
|
static bool ImGui_ImplGlfw_IsWayland()
|
||||||
{
|
{
|
||||||
#if !GLFW_HAS_X11_OR_WAYLAND
|
#if !GLFW_HAS_WAYLAND
|
||||||
return false;
|
return false;
|
||||||
#elif GLFW_HAS_GETPLATFORM
|
#elif GLFW_HAS_GETPLATFORM
|
||||||
return glfwGetPlatform() == GLFW_PLATFORM_WAYLAND;
|
return glfwGetPlatform() == GLFW_PLATFORM_WAYLAND;
|
||||||
#else
|
#else
|
||||||
const char* version = glfwGetVersionString();
|
const char* version = glfwGetVersionString();
|
||||||
if (strstr(version, "Wayland") == NULL) // e.g. Ubuntu 22.04 ships with GLFW 3.3.6 compiled without Wayland
|
if (strstr(version, "Wayland") == nullptr) // e.g. Ubuntu 22.04 ships with GLFW 3.3.6 compiled without Wayland
|
||||||
return false;
|
return false;
|
||||||
#ifdef GLFW_EXPOSE_NATIVE_X11
|
#ifdef GLFW_EXPOSE_NATIVE_X11
|
||||||
if (glfwGetX11Display() != NULL)
|
if (glfwGetX11Display() != nullptr)
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
@@ -484,7 +527,7 @@ static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
|
|||||||
{
|
{
|
||||||
const char char_names[] = "`-=[]\\,;\'./";
|
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 };
|
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));
|
IM_ASSERT(IM_COUNTOF(char_names) == IM_COUNTOF(char_keys));
|
||||||
if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); }
|
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 (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'); }
|
||||||
@@ -509,7 +552,7 @@ void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, i
|
|||||||
ImGuiIO& io = ImGui::GetIO(bd->Context);
|
ImGuiIO& io = ImGui::GetIO(bd->Context);
|
||||||
ImGui_ImplGlfw_UpdateKeyModifiers(io, window);
|
ImGui_ImplGlfw_UpdateKeyModifiers(io, window);
|
||||||
|
|
||||||
if (keycode >= 0 && keycode < IM_ARRAYSIZE(bd->KeyOwnerWindows))
|
if (keycode >= 0 && keycode < IM_COUNTOF(bd->KeyOwnerWindows))
|
||||||
bd->KeyOwnerWindows[keycode] = (action == GLFW_PRESS) ? window : nullptr;
|
bd->KeyOwnerWindows[keycode] = (action == GLFW_PRESS) ? window : nullptr;
|
||||||
|
|
||||||
keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode);
|
keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode);
|
||||||
@@ -680,10 +723,18 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
|
|||||||
|
|
||||||
// Setup backend capabilities flags
|
// Setup backend capabilities flags
|
||||||
ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
|
ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
|
||||||
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_glfw (%d)", GLFW_VERSION_COMBINED);
|
bd->Context = ImGui::GetCurrentContext();
|
||||||
|
bd->Window = window;
|
||||||
|
bd->Time = 0.0;
|
||||||
|
bd->IsWayland = ImGui_ImplGlfw_IsWayland();
|
||||||
|
ImGui_ImplGlfw_ContextMap_Add(window, bd->Context);
|
||||||
|
|
||||||
|
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_glfw (%d)%s", GLFW_VERSION_COMBINED, bd->IsWayland ? " (Wayland)" : "");
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
io.BackendPlatformUserData = (void*)bd;
|
||||||
io.BackendPlatformName = bd->BackendPlatformName;
|
io.BackendPlatformName = bd->BackendPlatformName;
|
||||||
|
#if GLFW_HAS_CREATECURSOR
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
|
#endif
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||||
|
|
||||||
bool has_viewports = false;
|
bool has_viewports = false;
|
||||||
@@ -700,12 +751,6 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
|
|||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bd->Context = ImGui::GetCurrentContext();
|
|
||||||
bd->Window = window;
|
|
||||||
bd->Time = 0.0;
|
|
||||||
bd->IsWayland = ImGui_ImplGlfw_IsWayland();
|
|
||||||
ImGui_ImplGlfw_ContextMap_Add(window, bd->Context);
|
|
||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
#if GLFW_VERSION_COMBINED < 3300
|
#if GLFW_VERSION_COMBINED < 3300
|
||||||
platform_io.Platform_SetClipboardTextFn = [](ImGuiContext*, const char* text) { glfwSetClipboardString(ImGui_ImplGlfw_GetBackendData()->Window, text); };
|
platform_io.Platform_SetClipboardTextFn = [](ImGuiContext*, const char* text) { glfwSetClipboardString(ImGui_ImplGlfw_GetBackendData()->Window, text); };
|
||||||
@@ -723,6 +768,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
|
|||||||
// (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
|
// (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
|
||||||
// GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
|
// GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
|
||||||
// Missing cursors will return nullptr and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
|
// Missing cursors will return nullptr and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
|
||||||
|
#if GLFW_HAS_CREATECURSOR
|
||||||
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
|
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
|
||||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
||||||
@@ -741,6 +787,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
|
|||||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
#endif
|
#endif
|
||||||
glfwSetErrorCallback(prev_error_callback);
|
glfwSetErrorCallback(prev_error_callback);
|
||||||
|
#endif
|
||||||
#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908)
|
#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908)
|
||||||
(void)glfwGetError(nullptr);
|
(void)glfwGetError(nullptr);
|
||||||
#endif
|
#endif
|
||||||
@@ -776,6 +823,26 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
|
|||||||
::SetWindowLongPtrW((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc);
|
::SetWindowLongPtrW((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GLFW_HAS_X11
|
||||||
|
if (!bd->IsWayland)
|
||||||
|
{
|
||||||
|
// Load X11 module dynamically. Copied from the way that GLFW does it in x11_init.c
|
||||||
|
#if defined(__CYGWIN__)
|
||||||
|
const char* x11_module_path = "libX11-6.so";
|
||||||
|
#elif defined(__OpenBSD__) || defined(__NetBSD__)
|
||||||
|
const char* x11_module_path = "libX11.so";
|
||||||
|
#else
|
||||||
|
const char* x11_module_path = "libX11.so.6";
|
||||||
|
#endif
|
||||||
|
bd->X11Module = dlopen(x11_module_path, RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
bd->XInternAtom = (PFN_XInternAtom)dlsym(bd->X11Module, "XInternAtom");
|
||||||
|
bd->XChangeProperty = (PFN_XChangeProperty)dlsym(bd->X11Module, "XChangeProperty");
|
||||||
|
bd->XChangeWindowAttributes = (PFN_XChangeWindowAttributes)dlsym(bd->X11Module, "XChangeWindowAttributes");
|
||||||
|
bd->XFlush = (PFN_XFlush)dlsym(bd->X11Module, "XFlush");
|
||||||
|
IM_ASSERT(bd->XInternAtom != nullptr && bd->XChangeProperty != nullptr && bd->XChangeWindowAttributes != nullptr && bd->XFlush != nullptr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Emscripten: the same application can run on various platforms, so we detect the Apple platform at runtime
|
// Emscripten: the same application can run on various platforms, so we detect the Apple platform at runtime
|
||||||
// to override io.ConfigMacOSXBehaviors from its default (which is always false in Emscripten).
|
// to override io.ConfigMacOSXBehaviors from its default (which is always false in Emscripten).
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
@@ -816,20 +883,21 @@ void ImGui_ImplGlfw_Shutdown()
|
|||||||
{
|
{
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplGlfw_ShutdownMultiViewportSupport();
|
ImGui_ImplGlfw_ShutdownMultiViewportSupport();
|
||||||
|
|
||||||
if (bd->InstalledCallbacks)
|
if (bd->InstalledCallbacks)
|
||||||
ImGui_ImplGlfw_RestoreCallbacks(bd->Window);
|
ImGui_ImplGlfw_RestoreCallbacks(bd->Window);
|
||||||
#ifdef EMSCRIPTEN_USE_EMBEDDED_GLFW3
|
#ifdef EMSCRIPTEN_USE_EMBEDDED_GLFW3
|
||||||
if (bd->CanvasSelector)
|
if (bd->CanvasSelector)
|
||||||
emscripten_set_wheel_callback(bd->CanvasSelector, nullptr, false, nullptr);
|
emscripten_set_wheel_callback(bd->CanvasSelector, nullptr, false, nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
#if GLFW_HAS_CREATECURSOR
|
||||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||||
glfwDestroyCursor(bd->MouseCursors[cursor_n]);
|
glfwDestroyCursor(bd->MouseCursors[cursor_n]);
|
||||||
|
#endif
|
||||||
// Windows: restore our WndProc hook
|
// Windows: restore our WndProc hook
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
@@ -838,9 +906,15 @@ void ImGui_ImplGlfw_Shutdown()
|
|||||||
bd->PrevWndProc = nullptr;
|
bd->PrevWndProc = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GLFW_HAS_X11
|
||||||
|
if (bd->X11Module != nullptr)
|
||||||
|
dlclose(bd->X11Module);
|
||||||
|
#endif
|
||||||
|
|
||||||
io.BackendPlatformName = nullptr;
|
io.BackendPlatformName = nullptr;
|
||||||
io.BackendPlatformUserData = nullptr;
|
io.BackendPlatformUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
ImGui_ImplGlfw_ContextMap_Remove(bd->Window);
|
ImGui_ImplGlfw_ContextMap_Remove(bd->Window);
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
@@ -921,7 +995,10 @@ static void ImGui_ImplGlfw_UpdateMouseCursor()
|
|||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||||
|
{
|
||||||
|
bd->LastMouseCursor = nullptr; // Invalidate so that if user changes underlying cursor we will update it next time we can.
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
@@ -930,14 +1007,25 @@ static void ImGui_ImplGlfw_UpdateMouseCursor()
|
|||||||
GLFWwindow* window = (GLFWwindow*)platform_io.Viewports[n]->PlatformHandle;
|
GLFWwindow* window = (GLFWwindow*)platform_io.Viewports[n]->PlatformHandle;
|
||||||
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
||||||
{
|
{
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
if (bd->LastMouseCursor != nullptr)
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
{
|
||||||
|
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
|
bd->LastMouseCursor = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Show OS mouse cursor
|
// Show OS mouse cursor
|
||||||
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
|
// 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]);
|
#if GLFW_HAS_CREATECURSOR
|
||||||
|
GLFWcursor* cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
||||||
|
if (bd->LastMouseCursor != cursor)
|
||||||
|
{
|
||||||
|
glfwSetCursor(window, cursor);
|
||||||
|
bd->LastMouseCursor = cursor;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -999,13 +1087,10 @@ static void ImGui_ImplGlfw_UpdateGamepads()
|
|||||||
static void ImGui_ImplGlfw_UpdateMonitors()
|
static void ImGui_ImplGlfw_UpdateMonitors()
|
||||||
{
|
{
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
int monitors_count = 0;
|
int monitors_count = 0;
|
||||||
GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count);
|
GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count);
|
||||||
if (monitors_count == 0) // Preserve existing monitor list if there are none. Happens on macOS sleeping (#5683)
|
|
||||||
return;
|
|
||||||
|
|
||||||
platform_io.Monitors.resize(0);
|
bool updated_monitors = false;
|
||||||
for (int n = 0; n < monitors_count; n++)
|
for (int n = 0; n < monitors_count; n++)
|
||||||
{
|
{
|
||||||
ImGuiPlatformMonitor monitor;
|
ImGuiPlatformMonitor monitor;
|
||||||
@@ -1014,6 +1099,8 @@ static void ImGui_ImplGlfw_UpdateMonitors()
|
|||||||
const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]);
|
const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]);
|
||||||
if (vid_mode == nullptr)
|
if (vid_mode == nullptr)
|
||||||
continue; // Failed to get Video mode (e.g. Emscripten does not support this function)
|
continue; // Failed to get Video mode (e.g. Emscripten does not support this function)
|
||||||
|
if (vid_mode->width <= 0 || vid_mode->height <= 0)
|
||||||
|
continue; // Failed to query suitable monitor info (#9195)
|
||||||
monitor.MainPos = monitor.WorkPos = ImVec2((float)x, (float)y);
|
monitor.MainPos = monitor.WorkPos = ImVec2((float)x, (float)y);
|
||||||
monitor.MainSize = monitor.WorkSize = ImVec2((float)vid_mode->width, (float)vid_mode->height);
|
monitor.MainSize = monitor.WorkSize = ImVec2((float)vid_mode->width, (float)vid_mode->height);
|
||||||
#if GLFW_HAS_MONITOR_WORK_AREA
|
#if GLFW_HAS_MONITOR_WORK_AREA
|
||||||
@@ -1027,19 +1114,35 @@ static void ImGui_ImplGlfw_UpdateMonitors()
|
|||||||
#endif
|
#endif
|
||||||
float scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfw_monitors[n]);
|
float scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfw_monitors[n]);
|
||||||
if (scale == 0.0f)
|
if (scale == 0.0f)
|
||||||
continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902.
|
continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0 (#7902)
|
||||||
monitor.DpiScale = scale;
|
monitor.DpiScale = scale;
|
||||||
monitor.PlatformHandle = (void*)glfw_monitors[n]; // [...] GLFW doc states: "guaranteed to be valid only until the monitor configuration changes"
|
monitor.PlatformHandle = (void*)glfw_monitors[n]; // [...] GLFW doc states: "guaranteed to be valid only until the monitor configuration changes"
|
||||||
|
|
||||||
|
// Preserve existing monitor list until a valid one is added.
|
||||||
|
// Happens on macOS sleeping (#5683) and seemingly occasionally on Windows (#9195)
|
||||||
|
if (!updated_monitors)
|
||||||
|
platform_io.Monitors.resize(0);
|
||||||
|
updated_monitors = true;
|
||||||
platform_io.Monitors.push_back(monitor);
|
platform_io.Monitors.push_back(monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For GFLW 3.2 + Windows: include a simplified non-monitor aware version of ImGui_ImplWin32_GetDpiScaleForMonitor().
|
||||||
|
// This is merely a band-aid to make using GLFW 3.2 a little bit nicer, but prefer to use GLFW 3.3+ or the full correct functions from the Win32 backend.
|
||||||
|
#if !GLFW_HAS_PER_MONITOR_DPI && defined(_WIN32) && !defined(NOGDI)
|
||||||
|
static float ImGui_ImplWin32_GetLegacyDpiScale() { const HDC dc = ::GetDC(nullptr); UINT xdpi = ::GetDeviceCaps(dc, LOGPIXELSX); ::ReleaseDC(nullptr, dc); return (float)xdpi / 96.0f; }
|
||||||
|
static void glfwGetWindowContentScale(GLFWwindow*, float* x_scale, float* y_scale) { *x_scale = *y_scale = ImGui_ImplWin32_GetLegacyDpiScale(); }
|
||||||
|
static void glfwGetMonitorContentScale(GLFWmonitor*, float* x_scale, float* y_scale) { *x_scale = *y_scale = ImGui_ImplWin32_GetLegacyDpiScale(); }
|
||||||
|
#undef GLFW_HAS_PER_MONITOR_DPI
|
||||||
|
#define GLFW_HAS_PER_MONITOR_DPI 1
|
||||||
|
#endif
|
||||||
|
|
||||||
// - On Windows the process needs to be marked DPI-aware!! SDL2 doesn't do it by default. You can call ::SetProcessDPIAware() or call ImGui_ImplWin32_EnableDpiAwareness() from Win32 backend.
|
// - On Windows the process needs to be marked DPI-aware!! SDL2 doesn't do it by default. You can call ::SetProcessDPIAware() or call ImGui_ImplWin32_EnableDpiAwareness() from Win32 backend.
|
||||||
// - Apple platforms use FramebufferScale so we always return 1.0f.
|
// - Apple platforms use FramebufferScale so we always return 1.0f.
|
||||||
// - Some accessibility applications are declaring virtual monitors with a DPI of 0.0f, see #7902. We preserve this value for caller to handle.
|
// - Some accessibility applications are declaring virtual monitors with a DPI of 0.0f, see #7902. We preserve this value for caller to handle.
|
||||||
float ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window)
|
float ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
#if GLFW_HAS_X11_OR_WAYLAND
|
#if GLFW_HAS_WAYLAND
|
||||||
if (ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(window))
|
if (ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(window))
|
||||||
if (bd->IsWayland)
|
if (bd->IsWayland)
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
@@ -1056,7 +1159,7 @@ float ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window)
|
|||||||
|
|
||||||
float ImGui_ImplGlfw_GetContentScaleForMonitor(GLFWmonitor* monitor)
|
float ImGui_ImplGlfw_GetContentScaleForMonitor(GLFWmonitor* monitor)
|
||||||
{
|
{
|
||||||
#if GLFW_HAS_X11_OR_WAYLAND
|
#if GLFW_HAS_WAYLAND
|
||||||
if (ImGui_ImplGlfw_IsWayland()) // We can't access our bd->IsWayland cache for a monitor.
|
if (ImGui_ImplGlfw_IsWayland()) // We can't access our bd->IsWayland cache for a monitor.
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
#endif
|
#endif
|
||||||
@@ -1076,9 +1179,9 @@ static void ImGui_ImplGlfw_GetWindowSizeAndFramebufferScale(GLFWwindow* window,
|
|||||||
int display_w, display_h;
|
int display_w, display_h;
|
||||||
glfwGetWindowSize(window, &w, &h);
|
glfwGetWindowSize(window, &w, &h);
|
||||||
glfwGetFramebufferSize(window, &display_w, &display_h);
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||||
float fb_scale_x = (w > 0) ? (float)display_w / w : 1.0f;
|
float fb_scale_x = (w > 0) ? (float)display_w / (float)w : 1.0f;
|
||||||
float fb_scale_y = (h > 0) ? (float)display_h / h : 1.0f;
|
float fb_scale_y = (h > 0) ? (float)display_h / (float)h : 1.0f;
|
||||||
#if GLFW_HAS_X11_OR_WAYLAND
|
#if GLFW_HAS_WAYLAND
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(window);
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(window);
|
||||||
if (!bd->IsWayland)
|
if (!bd->IsWayland)
|
||||||
fb_scale_x = fb_scale_y = 1.0f;
|
fb_scale_x = fb_scale_y = 1.0f;
|
||||||
@@ -1103,7 +1206,7 @@ void ImGui_ImplGlfw_NewFrame()
|
|||||||
// (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)
|
// (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();
|
double current_time = glfwGetTime();
|
||||||
if (current_time <= bd->Time)
|
if (current_time <= bd->Time)
|
||||||
current_time = bd->Time + 0.00001f;
|
current_time = bd->Time + 0.00001;
|
||||||
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
|
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
|
||||||
bd->Time = current_time;
|
bd->Time = current_time;
|
||||||
|
|
||||||
@@ -1243,20 +1346,20 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
|
|||||||
|
|
||||||
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__EMSCRIPTEN__) && GLFW_HAS_GETPLATFORM
|
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__EMSCRIPTEN__) && GLFW_HAS_GETPLATFORM
|
||||||
#define IMGUI_GLFW_HAS_SETWINDOWFLOATING
|
#define IMGUI_GLFW_HAS_SETWINDOWFLOATING
|
||||||
static void ImGui_ImplGlfw_SetWindowFloating(GLFWwindow* window)
|
static void ImGui_ImplGlfw_SetWindowFloating(ImGui_ImplGlfw_Data* bd, GLFWwindow* window)
|
||||||
{
|
{
|
||||||
#ifdef GLFW_EXPOSE_NATIVE_X11
|
#ifdef GLFW_EXPOSE_NATIVE_X11
|
||||||
if (glfwGetPlatform() == GLFW_PLATFORM_X11)
|
if (glfwGetPlatform() == GLFW_PLATFORM_X11)
|
||||||
{
|
{
|
||||||
Display* display = glfwGetX11Display();
|
Display* display = glfwGetX11Display();
|
||||||
Window xwindow = glfwGetX11Window(window);
|
Window xwindow = glfwGetX11Window(window);
|
||||||
Atom wm_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
|
Atom wm_type = bd->XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
|
||||||
Atom wm_type_dialog = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
Atom wm_type_dialog = bd->XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
||||||
XChangeProperty(display, xwindow, wm_type, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wm_type_dialog, 1);
|
bd->XChangeProperty(display, xwindow, wm_type, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wm_type_dialog, 1);
|
||||||
XSetWindowAttributes attrs;
|
XSetWindowAttributes attrs;
|
||||||
attrs.override_redirect = False;
|
attrs.override_redirect = False;
|
||||||
XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &attrs);
|
bd->XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &attrs);
|
||||||
XFlush(display);
|
bd->XFlush(display);
|
||||||
}
|
}
|
||||||
#endif // GLFW_EXPOSE_NATIVE_X11
|
#endif // GLFW_EXPOSE_NATIVE_X11
|
||||||
#ifdef GLFW_EXPOSE_NATIVE_WAYLAND
|
#ifdef GLFW_EXPOSE_NATIVE_WAYLAND
|
||||||
@@ -1293,7 +1396,7 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
|
|||||||
ImGui_ImplGlfw_ContextMap_Add(vd->Window, bd->Context);
|
ImGui_ImplGlfw_ContextMap_Add(vd->Window, bd->Context);
|
||||||
viewport->PlatformHandle = (void*)vd->Window;
|
viewport->PlatformHandle = (void*)vd->Window;
|
||||||
#ifdef IMGUI_GLFW_HAS_SETWINDOWFLOATING
|
#ifdef IMGUI_GLFW_HAS_SETWINDOWFLOATING
|
||||||
ImGui_ImplGlfw_SetWindowFloating(vd->Window);
|
ImGui_ImplGlfw_SetWindowFloating(bd, vd->Window);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
viewport->PlatformHandleRaw = glfwGetWin32Window(vd->Window);
|
viewport->PlatformHandleRaw = glfwGetWin32Window(vd->Window);
|
||||||
@@ -1335,7 +1438,7 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
// Release any keys that were pressed in the window being destroyed and are still held down,
|
// Release any keys that were pressed in the window being destroyed and are still held down,
|
||||||
// because we will not receive any release events after window is destroyed.
|
// because we will not receive any release events after window is destroyed.
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(bd->KeyOwnerWindows); i++)
|
for (int i = 0; i < IM_COUNTOF(bd->KeyOwnerWindows); i++)
|
||||||
if (bd->KeyOwnerWindows[i] == vd->Window)
|
if (bd->KeyOwnerWindows[i] == vd->Window)
|
||||||
ImGui_ImplGlfw_KeyCallback(vd->Window, i, 0, GLFW_RELEASE, 0); // Later params are only used for main viewport, on which this function is never called.
|
ImGui_ImplGlfw_KeyCallback(vd->Window, i, 0, GLFW_RELEASE, 0); // Later params are only used for main viewport, on which this function is never called.
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
// dear imgui: Platform Backend for GLFW
|
// dear imgui: Platform Backend for GLFW
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
||||||
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||||
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.)
|
// (Requires: GLFW 3.0+. Prefer GLFW 3.3+/3.4+ for full feature support.)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Platform: Clipboard support.
|
// [X] Platform: Clipboard support.
|
||||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
|
// [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 are obsolete since 1.87 and not supported since 1.91.5]
|
// [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 are obsolete since 1.87 and not supported since 1.91.5]
|
||||||
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||||
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors) with GLFW 3.1+. Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// [X] Multiple Dear ImGui contexts support.
|
// [X] Multiple Dear ImGui contexts support.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Touch events are only correctly identified as Touch on Windows. This create issues with some interactions. GLFW doesn't provide a way to identify touch inputs from mouse inputs, we cannot call io.AddMouseSourceEvent() to identify the source. We provide a Windows-specific workaround.
|
// [ ] Platform: Touch events are only correctly identified as Touch on Windows. This create issues with some interactions. GLFW doesn't provide a way to identify touch inputs from mouse inputs, we cannot call io.AddMouseSourceEvent() to identify the source. We provide a Windows-specific workaround.
|
||||||
// [ ] Missing ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress cursors.
|
// [ ] Platform: Missing ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress cursors.
|
||||||
// [ ] Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
// [ ] Platform: Multi-viewport: Missing ImGuiBackendFlags_HasParentViewport support. The viewport->ParentViewportID field is ignored, and therefore io.ConfigViewportsNoDefaultParent has no effect either.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -50,7 +50,7 @@ IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* wi
|
|||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
|
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
|
||||||
IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
|
IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
|
||||||
|
|
||||||
// GFLW callbacks options:
|
// GLFW callbacks options:
|
||||||
// - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user)
|
// - 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);
|
IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows);
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* drawData,
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device);
|
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device);
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -68,7 +68,7 @@ IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data,
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device);
|
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device);
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,7 +17,13 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Metal: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Metal: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-28: Added support for standard draw callbacks (in platform_io): DrawCallback_SetSamplerLinear and DrawCallback_SetSamplerNearest. (#9378, #9381)
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState (others are not yet supported). (#9378)
|
||||||
|
// 2026-04-14: Metal: use a dedicated bufferCacheLock to avoid crashing when bufferCache is replaced by a new object while being used for @synchronize(). (#9367)
|
||||||
|
// 2026-04-03: Metal: avoid redundant vertex buffer bind in SetupRenderState. (#9343)
|
||||||
|
// 2026-03-19: Fixed issue in ImGui_ImplMetal_RenderDrawData() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295, #9310)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplMetal_CreateFontsTexture() and ImGui_ImplMetal_DestroyFontsTexture().
|
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplMetal_CreateFontsTexture() and ImGui_ImplMetal_DestroyFontsTexture().
|
||||||
// 2025-02-03: Metal: Crash fix. (#8367)
|
// 2025-02-03: Metal: Crash fix. (#8367)
|
||||||
// 2025-01-08: Metal: Fixed memory leaks when using metal-cpp (#8276, #8166) or when using multiple contexts (#7419).
|
// 2025-01-08: Metal: Fixed memory leaks when using metal-cpp (#8276, #8166) or when using multiple contexts (#7419).
|
||||||
@@ -80,9 +86,12 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows();
|
|||||||
@interface MetalContext : NSObject
|
@interface MetalContext : NSObject
|
||||||
@property (nonatomic, strong) id<MTLDevice> device;
|
@property (nonatomic, strong) id<MTLDevice> device;
|
||||||
@property (nonatomic, strong) id<MTLDepthStencilState> depthStencilState;
|
@property (nonatomic, strong) id<MTLDepthStencilState> depthStencilState;
|
||||||
|
@property (nonatomic, strong) id<MTLSamplerState> samplerStateLinear;
|
||||||
|
@property (nonatomic, strong) id<MTLSamplerState> samplerStateNearest;
|
||||||
@property (nonatomic, strong) FramebufferDescriptor* framebufferDescriptor; // framebuffer descriptor for current frame; transient
|
@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) NSMutableDictionary* renderPipelineStateCache; // pipeline cache; keyed on framebuffer descriptors
|
||||||
@property (nonatomic, strong) NSMutableArray<MetalBuffer*>* bufferCache;
|
@property (nonatomic, strong) NSMutableArray<MetalBuffer*>* bufferCache;
|
||||||
|
@property (nonatomic, strong) NSObject* bufferCacheLock;
|
||||||
@property (nonatomic, assign) double lastBufferCachePurge;
|
@property (nonatomic, assign) double lastBufferCachePurge;
|
||||||
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device;
|
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device;
|
||||||
- (id<MTLRenderPipelineState>)renderPipelineStateForFramebufferDescriptor:(FramebufferDescriptor*)descriptor device:(id<MTLDevice>)device;
|
- (id<MTLRenderPipelineState>)renderPipelineStateForFramebufferDescriptor:(FramebufferDescriptor*)descriptor device:(id<MTLDevice>)device;
|
||||||
@@ -91,6 +100,7 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows();
|
|||||||
struct ImGui_ImplMetal_Data
|
struct ImGui_ImplMetal_Data
|
||||||
{
|
{
|
||||||
MetalContext* SharedMetalContext;
|
MetalContext* SharedMetalContext;
|
||||||
|
id<MTLRenderCommandEncoder> RenderCommandEncoder;
|
||||||
|
|
||||||
ImGui_ImplMetal_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplMetal_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
};
|
};
|
||||||
@@ -133,42 +143,6 @@ bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device)
|
|||||||
|
|
||||||
#pragma mark - Dear ImGui Metal Backend API
|
#pragma mark - Dear ImGui Metal Backend API
|
||||||
|
|
||||||
bool ImGui_ImplMetal_Init(id<MTLDevice> device)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
ImGui_ImplMetal_Data* bd = IM_NEW(ImGui_ImplMetal_Data)();
|
|
||||||
io.BackendRendererUserData = (void*)bd;
|
|
||||||
io.BackendRendererName = "imgui_impl_metal";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
|
||||||
|
|
||||||
bd->SharedMetalContext = [[MetalContext alloc] init];
|
|
||||||
bd->SharedMetalContext.device = device;
|
|
||||||
|
|
||||||
ImGui_ImplMetal_InitMultiViewportSupport();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_Shutdown()
|
|
||||||
{
|
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
|
||||||
IM_UNUSED(bd);
|
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
||||||
ImGui_ImplMetal_ShutdownMultiViewportSupport();
|
|
||||||
ImGui_ImplMetal_DestroyDeviceObjects();
|
|
||||||
ImGui_ImplMetal_DestroyBackendData();
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor)
|
void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor)
|
||||||
{
|
{
|
||||||
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
||||||
@@ -221,11 +195,16 @@ static void ImGui_ImplMetal_SetupRenderState(ImDrawData* draw_data, id<MTLComman
|
|||||||
[commandEncoder setVertexBytes:&ortho_projection length:sizeof(ortho_projection) atIndex:1];
|
[commandEncoder setVertexBytes:&ortho_projection length:sizeof(ortho_projection) atIndex:1];
|
||||||
|
|
||||||
[commandEncoder setRenderPipelineState:renderPipelineState];
|
[commandEncoder setRenderPipelineState:renderPipelineState];
|
||||||
|
[commandEncoder setFragmentSamplerState:bd->SharedMetalContext.samplerStateLinear atIndex:0];
|
||||||
|
|
||||||
[commandEncoder setVertexBuffer:vertexBuffer.buffer offset:0 atIndex:0];
|
[commandEncoder setVertexBuffer:vertexBuffer.buffer offset:vertexBufferOffset atIndex:0];
|
||||||
[commandEncoder setVertexBufferOffset:vertexBufferOffset atIndex:0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplMetal_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplMetal_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData(); [bd->RenderCommandEncoder setFragmentSamplerState:bd->SharedMetalContext.samplerStateLinear atIndex:0]; }
|
||||||
|
static void ImGui_ImplMetal_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData(); [bd->RenderCommandEncoder setFragmentSamplerState:bd->SharedMetalContext.samplerStateNearest atIndex:0]; }
|
||||||
|
|
||||||
// Metal Render function.
|
// Metal Render function.
|
||||||
void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, id<MTLCommandBuffer> commandBuffer, id<MTLRenderCommandEncoder> commandEncoder)
|
void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, id<MTLCommandBuffer> commandBuffer, id<MTLRenderCommandEncoder> commandEncoder)
|
||||||
{
|
{
|
||||||
@@ -262,6 +241,7 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, id<MTLCommandBuffer>
|
|||||||
MetalBuffer* vertexBuffer = [ctx dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
|
MetalBuffer* vertexBuffer = [ctx dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
|
||||||
MetalBuffer* indexBuffer = [ctx dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
|
MetalBuffer* indexBuffer = [ctx dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
|
||||||
|
|
||||||
|
bd->RenderCommandEncoder = commandEncoder;
|
||||||
ImGui_ImplMetal_SetupRenderState(draw_data, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, 0);
|
ImGui_ImplMetal_SetupRenderState(draw_data, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, 0);
|
||||||
|
|
||||||
// Will project scissor/clipping rectangles into framebuffer space
|
// Will project scissor/clipping rectangles into framebuffer space
|
||||||
@@ -282,8 +262,7 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, id<MTLCommandBuffer>
|
|||||||
if (pcmd->UserCallback)
|
if (pcmd->UserCallback)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplMetal_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplMetal_SetupRenderState(draw_data, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, vertexBufferOffset);
|
ImGui_ImplMetal_SetupRenderState(draw_data, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, vertexBufferOffset);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -297,8 +276,8 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, id<MTLCommandBuffer>
|
|||||||
// Clamp to viewport as setScissorRect() won't accept values that are off bounds
|
// 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.x < 0.0f) { clip_min.x = 0.0f; }
|
||||||
if (clip_min.y < 0.0f) { clip_min.y = 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.x > (float)fb_width) { clip_max.x = (float)fb_width; }
|
||||||
if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; }
|
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)
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||||
continue;
|
continue;
|
||||||
if (pcmd->ElemCount == 0) // drawIndexedPrimitives() validation doesn't accept this
|
if (pcmd->ElemCount == 0) // drawIndexedPrimitives() validation doesn't accept this
|
||||||
@@ -315,7 +294,8 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, id<MTLCommandBuffer>
|
|||||||
[commandEncoder setScissorRect:scissorRect];
|
[commandEncoder setScissorRect:scissorRect];
|
||||||
|
|
||||||
// Bind texture, Draw
|
// Bind texture, Draw
|
||||||
if (ImTextureID tex_id = pcmd->GetTexID())
|
ImTextureID tex_id = pcmd->GetTexID();
|
||||||
|
if (tex_id != ImTextureID_Invalid)
|
||||||
[commandEncoder setFragmentTexture:(__bridge id<MTLTexture>)(void*)(intptr_t)(tex_id) atIndex:0];
|
[commandEncoder setFragmentTexture:(__bridge id<MTLTexture>)(void*)(intptr_t)(tex_id) atIndex:0];
|
||||||
|
|
||||||
[commandEncoder setVertexBufferOffset:(vertexBufferOffset + pcmd->VtxOffset * sizeof(ImDrawVert)) atIndex:0];
|
[commandEncoder setVertexBufferOffset:(vertexBufferOffset + pcmd->VtxOffset * sizeof(ImDrawVert)) atIndex:0];
|
||||||
@@ -334,28 +314,27 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, id<MTLCommandBuffer>
|
|||||||
MetalContext* sharedMetalContext = bd->SharedMetalContext;
|
MetalContext* sharedMetalContext = bd->SharedMetalContext;
|
||||||
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer>)
|
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer>)
|
||||||
{
|
{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
@synchronized(sharedMetalContext.bufferCacheLock)
|
||||||
@synchronized(sharedMetalContext.bufferCache)
|
{
|
||||||
{
|
[sharedMetalContext.bufferCache addObject:vertexBuffer];
|
||||||
[sharedMetalContext.bufferCache addObject:vertexBuffer];
|
[sharedMetalContext.bufferCache addObject:indexBuffer];
|
||||||
[sharedMetalContext.bufferCache addObject:indexBuffer];
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}];
|
}];
|
||||||
|
bd->RenderCommandEncoder = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplMetal_DestroyTexture(ImTextureData* tex)
|
static void ImGui_ImplMetal_DestroyTexture(ImTextureData* tex)
|
||||||
{
|
{
|
||||||
MetalTexture* backend_tex = (__bridge_transfer MetalTexture*)(tex->BackendUserData);
|
if (MetalTexture* backend_tex = (__bridge_transfer MetalTexture*)(tex->BackendUserData))
|
||||||
if (backend_tex == nullptr)
|
{
|
||||||
return;
|
IM_ASSERT(backend_tex.metalTexture == (__bridge id<MTLTexture>)(void*)(intptr_t)tex->TexID);
|
||||||
IM_ASSERT(backend_tex.metalTexture == (__bridge id<MTLTexture>)(void*)(intptr_t)tex->TexID);
|
backend_tex.metalTexture = nil;
|
||||||
backend_tex.metalTexture = nil;
|
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
tex->BackendUserData = nullptr;
|
||||||
|
}
|
||||||
tex->SetStatus(ImTextureStatus_Destroyed);
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
tex->BackendUserData = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex)
|
void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex)
|
||||||
@@ -418,8 +397,19 @@ bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device)
|
|||||||
depthStencilDescriptor.depthWriteEnabled = NO;
|
depthStencilDescriptor.depthWriteEnabled = NO;
|
||||||
depthStencilDescriptor.depthCompareFunction = MTLCompareFunctionAlways;
|
depthStencilDescriptor.depthCompareFunction = MTLCompareFunctionAlways;
|
||||||
bd->SharedMetalContext.depthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
|
bd->SharedMetalContext.depthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
|
||||||
|
MTLSamplerDescriptor* samplerDescriptor = [[MTLSamplerDescriptor alloc] init];
|
||||||
|
samplerDescriptor.minFilter = MTLSamplerMinMagFilterLinear;
|
||||||
|
samplerDescriptor.magFilter = MTLSamplerMinMagFilterLinear;
|
||||||
|
samplerDescriptor.mipFilter = MTLSamplerMipFilterLinear;
|
||||||
|
bd->SharedMetalContext.samplerStateLinear = [device newSamplerStateWithDescriptor:samplerDescriptor];
|
||||||
|
samplerDescriptor.minFilter = MTLSamplerMinMagFilterNearest;
|
||||||
|
samplerDescriptor.magFilter = MTLSamplerMinMagFilterNearest;
|
||||||
|
samplerDescriptor.mipFilter = MTLSamplerMipFilterNearest;
|
||||||
|
bd->SharedMetalContext.samplerStateNearest = [device newSamplerStateWithDescriptor:samplerDescriptor];
|
||||||
|
|
||||||
ImGui_ImplMetal_CreateDeviceObjectsForPlatformWindows();
|
ImGui_ImplMetal_CreateDeviceObjectsForPlatformWindows();
|
||||||
#ifdef IMGUI_IMPL_METAL_CPP
|
#ifdef IMGUI_IMPL_METAL_CPP
|
||||||
|
[samplerDescriptor release];
|
||||||
[depthStencilDescriptor release];
|
[depthStencilDescriptor release];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -437,6 +427,52 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
|
|||||||
|
|
||||||
ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows();
|
ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows();
|
||||||
[bd->SharedMetalContext.renderPipelineStateCache removeAllObjects];
|
[bd->SharedMetalContext.renderPipelineStateCache removeAllObjects];
|
||||||
|
bd->SharedMetalContext.samplerStateLinear = nil;
|
||||||
|
bd->SharedMetalContext.samplerStateNearest = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplMetal_Init(id<MTLDevice> device)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||||
|
|
||||||
|
ImGui_ImplMetal_Data* bd = IM_NEW(ImGui_ImplMetal_Data)();
|
||||||
|
io.BackendRendererUserData = (void*)bd;
|
||||||
|
io.BackendRendererName = "imgui_impl_metal";
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplMetal_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplMetal_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplMetal_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
|
bd->SharedMetalContext = [[MetalContext alloc] init];
|
||||||
|
bd->SharedMetalContext.device = device;
|
||||||
|
|
||||||
|
ImGui_ImplMetal_InitMultiViewportSupport();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplMetal_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
|
||||||
|
IM_UNUSED(bd);
|
||||||
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplMetal_ShutdownMultiViewportSupport();
|
||||||
|
ImGui_ImplMetal_DestroyDeviceObjects();
|
||||||
|
ImGui_ImplMetal_DestroyBackendData();
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Multi-viewport support
|
#pragma mark - Multi-viewport support
|
||||||
@@ -666,6 +702,7 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows()
|
|||||||
{
|
{
|
||||||
self.renderPipelineStateCache = [NSMutableDictionary dictionary];
|
self.renderPipelineStateCache = [NSMutableDictionary dictionary];
|
||||||
self.bufferCache = [NSMutableArray array];
|
self.bufferCache = [NSMutableArray array];
|
||||||
|
self.bufferCacheLock = [[NSObject alloc] init];
|
||||||
_lastBufferCachePurge = GetMachAbsoluteTimeInSeconds();
|
_lastBufferCachePurge = GetMachAbsoluteTimeInSeconds();
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@@ -673,9 +710,9 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows()
|
|||||||
|
|
||||||
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device
|
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device
|
||||||
{
|
{
|
||||||
uint64_t now = GetMachAbsoluteTimeInSeconds();
|
double now = GetMachAbsoluteTimeInSeconds();
|
||||||
|
|
||||||
@synchronized(self.bufferCache)
|
@synchronized(self.bufferCacheLock)
|
||||||
{
|
{
|
||||||
// Purge old buffers that haven't been useful for a while
|
// Purge old buffers that haven't been useful for a while
|
||||||
if (now - self.lastBufferCachePurge > 1.0)
|
if (now - self.lastBufferCachePurge > 1.0)
|
||||||
@@ -742,9 +779,9 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows()
|
|||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment half4 fragment_main(VertexOut in [[stage_in]],\n"
|
"fragment half4 fragment_main(VertexOut in [[stage_in]],\n"
|
||||||
" texture2d<half, access::sample> texture [[texture(0)]]) {\n"
|
" texture2d<half, access::sample> texture [[texture(0)]],\n"
|
||||||
" constexpr sampler linearSampler(coord::normalized, min_filter::linear, mag_filter::linear, mip_filter::linear);\n"
|
" sampler textureSampler [[sampler(0)]]) {\n"
|
||||||
" half4 texColor = texture.sample(linearSampler, in.texCoords);\n"
|
" half4 texColor = texture.sample(textureSampler, in.texCoords);\n"
|
||||||
" return half4(in.color) * texColor;\n"
|
" return half4(in.color) * texColor;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
|||||||
58
backends/imgui_impl_metal4.h
Normal file
58
backends/imgui_impl_metal4.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// dear imgui: Renderer Backend for Metal 4
|
||||||
|
// This needs to be used along with a Platform Backend (e.g. OSX)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Renderer: User texture binding. Use 'MTLTexture.gpuResourceID' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef!
|
||||||
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
|
// Missing features or Issues:
|
||||||
|
// [ ] Metal-cpp support.
|
||||||
|
// [ ] Texture view pool support? Reevaluate which type to use for ImtextureID.
|
||||||
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// ObjC API
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
|
|
||||||
|
@class MTL4RenderPassDescriptor;
|
||||||
|
@protocol MTLDevice, MTL4CommandBuffer, MTL4RenderCommandEncoder, MTL4CommandQueue;
|
||||||
|
|
||||||
|
// framesInFlight must match the number of frames your application keeps in flight (e.g. the size of your own
|
||||||
|
// command buffer/allocator ring). The backend uses it to size its own per-frame-in-flight resources (constant
|
||||||
|
// buffer, vertex/index buffer cache) so the CPU never overwrites a slot the GPU may still be reading.
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplMetal4_Init(id<MTLDevice> device, id<MTL4CommandQueue> commandQueue, int framesInFlight);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplMetal4_Shutdown();
|
||||||
|
// frameInFlightIndex must match the slot you use to index your own per-frame-in-flight resources
|
||||||
|
// (e.g. the same index used to pick your command buffer/allocator), and must be < framesInFlight passed to Init().
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplMetal4_NewFrame(MTL4RenderPassDescriptor* renderPassDescriptor, int frameInFlightIndex);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplMetal4_RenderDrawData(ImDrawData* drawData,
|
||||||
|
id<MTL4CommandBuffer> commandBuffer,
|
||||||
|
id<MTL4RenderCommandEncoder> commandEncoder);
|
||||||
|
|
||||||
|
// Called by Init/NewFrame/Shutdown
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplMetal4_CreateDeviceObjects(id<MTLDevice> device);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplMetal4_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplMetal4_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
708
backends/imgui_impl_metal4.mm
Normal file
708
backends/imgui_impl_metal4.mm
Normal file
@@ -0,0 +1,708 @@
|
|||||||
|
// dear imgui: Renderer Backend for Metal 4
|
||||||
|
// This needs to be used along with a Platform Backend (e.g. OSX)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Renderer: User texture binding. Use 'MTLTexture' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef!
|
||||||
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
|
// Missing features or Issues:
|
||||||
|
// [ ] Metal-cpp support.
|
||||||
|
// [ ] Texture view pool support? Reevaluate which type to use for ImtextureID.
|
||||||
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
// 2026-07-02: Metal 4: Added new Metal 4 backend implementation. (#9458)
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include "imgui_impl_metal4.h"
|
||||||
|
#import <time.h>
|
||||||
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
|
#pragma mark - Support classes and structs
|
||||||
|
|
||||||
|
struct ImGui_Metal4_ConstantData
|
||||||
|
{
|
||||||
|
float ModelViewProjectionMatrix[4][4];
|
||||||
|
};
|
||||||
|
|
||||||
|
@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:(MTL4RenderPassDescriptor*)renderPassDescriptor;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MetalTexture : NSObject
|
||||||
|
@property (nonatomic, strong) id<MTLTexture> metalTexture;
|
||||||
|
- (instancetype)initWithTexture:(id<MTLTexture>)metalTexture;
|
||||||
|
@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<MTL4CommandQueue> commandQueue;
|
||||||
|
@property (nonatomic, strong) id<MTLDepthStencilState> depthStencilState;
|
||||||
|
@property (nonatomic, strong) id<MTL4ArgumentTable> argumentTable;
|
||||||
|
@property (nonatomic, strong) id<MTLSamplerState> samplerStateLinear;
|
||||||
|
@property (nonatomic, strong) id<MTLSamplerState> samplerStateNearest;
|
||||||
|
@property (nonatomic, strong) id<MTLResidencySet> residencySet;
|
||||||
|
@property (nonatomic, strong) FramebufferDescriptor* framebufferDescriptor;
|
||||||
|
@property (nonatomic, strong) NSMutableDictionary* renderPipelineStateCache;
|
||||||
|
@property (nonatomic, assign) NSUInteger framesInFlight;
|
||||||
|
@property (nonatomic, assign) NSUInteger currentFrameSlot;
|
||||||
|
@property (nonatomic, strong) NSArray<id<MTLBuffer>>* constantBuffers;
|
||||||
|
@property (nonatomic, assign) ImGui_Metal4_ConstantData** constantBufferContentsArray;
|
||||||
|
@property (nonatomic, strong) NSMutableArray<NSMutableArray<MetalBuffer*>*>* bufferCaches;
|
||||||
|
@property (nonatomic, strong) NSObject* bufferCacheLock;
|
||||||
|
@property (nonatomic, assign) double lastBufferCachePurge;
|
||||||
|
- (id<MTLBuffer>)currentConstantBuffer;
|
||||||
|
- (ImGui_Metal4_ConstantData*)currentConstantBufferContents;
|
||||||
|
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device;
|
||||||
|
- (id<MTLRenderPipelineState>)renderPipelineStateForFramebufferDescriptor:(FramebufferDescriptor*)descriptor device:(id<MTLDevice>)device;
|
||||||
|
@end
|
||||||
|
|
||||||
|
struct ImGui_ImplMetal4_Data
|
||||||
|
{
|
||||||
|
MetalContext* SharedMetalContext;
|
||||||
|
id<MTL4RenderCommandEncoder> RenderCommandEncoder;
|
||||||
|
|
||||||
|
ImGui_ImplMetal4_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
static ImGui_ImplMetal4_Data* ImGui_ImplMetal4_GetBackendData() { return ImGui::GetCurrentContext() ? (ImGui_ImplMetal4_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; }
|
||||||
|
static void ImGui_ImplMetal4_DestroyBackendData(){ IM_DELETE(ImGui_ImplMetal4_GetBackendData()); }
|
||||||
|
|
||||||
|
static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return (CFTimeInterval)(double)(clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1e9); }
|
||||||
|
|
||||||
|
#pragma mark - Dear ImGui Metal Backend API
|
||||||
|
|
||||||
|
void ImGui_ImplMetal4_NewFrame(MTL4RenderPassDescriptor* renderPassDescriptor, int frameInFlightIndex)
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nil && "Context or backend not initialized! Did you call ImGui_ImplMetal4_Init()?");
|
||||||
|
IM_ASSERT(frameInFlightIndex < bd->SharedMetalContext.framesInFlight && "frameInFlightIndex out of range! See framesInFlight passed to ImGui_ImplMetal4_Init().");
|
||||||
|
#ifdef IMGUI_IMPL_METAL_CPP
|
||||||
|
bd->SharedMetalContext.framebufferDescriptor = [[[FramebufferDescriptor alloc] initWithRenderPassDescriptor:renderPassDescriptor]autorelease];
|
||||||
|
#else
|
||||||
|
bd->SharedMetalContext.framebufferDescriptor = [[FramebufferDescriptor alloc] initWithRenderPassDescriptor:renderPassDescriptor];
|
||||||
|
#endif
|
||||||
|
bd->SharedMetalContext.currentFrameSlot = (NSUInteger)frameInFlightIndex;
|
||||||
|
if (bd->SharedMetalContext.depthStencilState == nil)
|
||||||
|
ImGui_ImplMetal4_CreateDeviceObjects(bd->SharedMetalContext.device);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplMetal4_SetupRenderState(ImDrawData* draw_data, id<MTL4CommandBuffer> commandBuffer,
|
||||||
|
id<MTL4RenderCommandEncoder> commandEncoder, id<MTLRenderPipelineState> renderPipelineState,
|
||||||
|
MetalBuffer* vertexBuffer, size_t vertexBufferOffset)
|
||||||
|
{
|
||||||
|
IM_UNUSED(commandBuffer);
|
||||||
|
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_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)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x),
|
||||||
|
.height = (double)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y),
|
||||||
|
.znear = 0.0,
|
||||||
|
.zfar = 1.0
|
||||||
|
};
|
||||||
|
[commandEncoder setViewport:viewport];
|
||||||
|
|
||||||
|
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 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 },
|
||||||
|
};
|
||||||
|
ImGui_Metal4_ConstantData* constantBufferContents = [bd->SharedMetalContext currentConstantBufferContents];
|
||||||
|
memcpy(constantBufferContents->ModelViewProjectionMatrix, ortho_projection, sizeof(ortho_projection));
|
||||||
|
|
||||||
|
id<MTL4ArgumentTable> argumentTable = bd->SharedMetalContext.argumentTable;
|
||||||
|
[argumentTable setAddress:[bd->SharedMetalContext currentConstantBuffer].gpuAddress atIndex:1];
|
||||||
|
[argumentTable setAddress:(vertexBuffer.buffer.gpuAddress + vertexBufferOffset) attributeStride:sizeof(ImDrawVert) atIndex:0];
|
||||||
|
[argumentTable setSamplerState:bd->SharedMetalContext.samplerStateLinear.gpuResourceID atIndex:0];
|
||||||
|
[commandEncoder setArgumentTable:argumentTable atStages:MTLRenderStageVertex | MTLRenderStageFragment];
|
||||||
|
[commandEncoder setRenderPipelineState:renderPipelineState];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplMetal4_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplMetal4_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData(); [bd->SharedMetalContext.argumentTable setSamplerState:bd->SharedMetalContext.samplerStateLinear.gpuResourceID atIndex:0]; }
|
||||||
|
static void ImGui_ImplMetal4_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData(); [bd->SharedMetalContext.argumentTable setSamplerState:bd->SharedMetalContext.samplerStateNearest.gpuResourceID atIndex:0]; }
|
||||||
|
|
||||||
|
void ImGui_ImplMetal4_RenderDrawData(ImDrawData* draw_data, id<MTL4CommandBuffer> commandBuffer, id<MTL4RenderCommandEncoder> commandEncoder)
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData();
|
||||||
|
MetalContext* ctx = bd->SharedMetalContext;
|
||||||
|
|
||||||
|
// 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 || draw_data->CmdLists.Size == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Catch up with texture updates. Most of the times, the list will have 1 element with an OK status, aka nothing to do.
|
||||||
|
// (This almost always points to ImGui::GetPlatformIO().Textures[] but is part of ImDrawData to allow overriding or disabling texture updates).
|
||||||
|
if (draw_data->Textures != nullptr)
|
||||||
|
for (ImTextureData* tex : *draw_data->Textures)
|
||||||
|
if (tex->Status != ImTextureStatus_OK)
|
||||||
|
ImGui_ImplMetal4_UpdateTexture(tex);
|
||||||
|
|
||||||
|
// 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)draw_data->TotalVtxCount * sizeof(ImDrawVert);
|
||||||
|
size_t indexBufferLength = (size_t)draw_data->TotalIdxCount * sizeof(ImDrawIdx);
|
||||||
|
MetalBuffer* vertexBuffer = [ctx dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
|
||||||
|
MetalBuffer* indexBuffer = [ctx dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
|
||||||
|
|
||||||
|
bd->RenderCommandEncoder = commandEncoder;
|
||||||
|
ImGui_ImplMetal4_SetupRenderState(draw_data, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, 0);
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// Before rendering command lists, commit residency set
|
||||||
|
[bd->SharedMetalContext.residencySet commit];
|
||||||
|
|
||||||
|
// Render command lists
|
||||||
|
size_t vertexBufferOffset = 0;
|
||||||
|
size_t indexBufferOffset = 0;
|
||||||
|
for (const ImDrawList* draw_list : draw_data->CmdLists)
|
||||||
|
{
|
||||||
|
memcpy((char*)vertexBuffer.buffer.contents + vertexBufferOffset, draw_list->VtxBuffer.Data, (size_t)draw_list->VtxBuffer.Size * sizeof(ImDrawVert));
|
||||||
|
memcpy((char*)indexBuffer.buffer.contents + indexBufferOffset, draw_list->IdxBuffer.Data, (size_t)draw_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
||||||
|
|
||||||
|
for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++)
|
||||||
|
{
|
||||||
|
const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
|
||||||
|
if (pcmd->UserCallback)
|
||||||
|
{
|
||||||
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
|
if (pcmd->UserCallback == ImGui_ImplMetal4_DrawCallback_ResetRenderState)
|
||||||
|
ImGui_ImplMetal4_SetupRenderState(draw_data, commandBuffer, commandEncoder, renderPipelineState, vertexBuffer, vertexBufferOffset);
|
||||||
|
else
|
||||||
|
pcmd->UserCallback(draw_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 > (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;
|
||||||
|
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
|
||||||
|
ImTextureID tex_id = pcmd->GetTexID();
|
||||||
|
if (tex_id != ImTextureID_Invalid)
|
||||||
|
{
|
||||||
|
id<MTLTexture> texture = (__bridge id<MTLTexture>)(void*)(intptr_t)tex_id;
|
||||||
|
[bd->SharedMetalContext.argumentTable setTexture:texture.gpuResourceID atIndex:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
[bd->SharedMetalContext.argumentTable setAddress:(vertexBuffer.buffer.gpuAddress + vertexBufferOffset + (pcmd->VtxOffset * sizeof(ImDrawVert))) attributeStride:sizeof(ImDrawVert) atIndex:0];
|
||||||
|
|
||||||
|
size_t indexBufferCmdOffset = indexBufferOffset + (pcmd->IdxOffset * sizeof(ImDrawIdx));
|
||||||
|
[commandEncoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
|
||||||
|
indexCount:pcmd->ElemCount
|
||||||
|
indexType:sizeof(ImDrawIdx) == 2 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32
|
||||||
|
indexBuffer:indexBuffer.buffer.gpuAddress + indexBufferCmdOffset
|
||||||
|
indexBufferLength:indexBuffer.buffer.length - indexBufferCmdOffset];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vertexBufferOffset += (size_t)draw_list->VtxBuffer.Size * sizeof(ImDrawVert);
|
||||||
|
indexBufferOffset += (size_t)draw_list->IdxBuffer.Size * sizeof(ImDrawIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
MetalContext* sharedMetalContext = bd->SharedMetalContext;
|
||||||
|
@synchronized(sharedMetalContext.bufferCacheLock)
|
||||||
|
{
|
||||||
|
NSMutableArray<MetalBuffer*>* slotCache = sharedMetalContext.bufferCaches[sharedMetalContext.currentFrameSlot];
|
||||||
|
[slotCache addObject:vertexBuffer];
|
||||||
|
[slotCache addObject:indexBuffer];
|
||||||
|
}
|
||||||
|
bd->RenderCommandEncoder = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplMetal4_DestroyTexture(ImTextureData* tex)
|
||||||
|
{
|
||||||
|
if (MetalTexture* backend_tex = (__bridge_transfer MetalTexture*)(tex->BackendUserData))
|
||||||
|
{
|
||||||
|
IM_ASSERT(backend_tex.metalTexture == (__bridge id<MTLTexture>)(void*)(intptr_t)tex->TexID);
|
||||||
|
backend_tex.metalTexture = nil;
|
||||||
|
|
||||||
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
tex->BackendUserData = nullptr;
|
||||||
|
}
|
||||||
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplMetal4_UpdateTexture(ImTextureData* tex)
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData();
|
||||||
|
if (tex->Status == ImTextureStatus_WantCreate)
|
||||||
|
{
|
||||||
|
// Create and upload new texture to graphics system
|
||||||
|
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
||||||
|
IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr);
|
||||||
|
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
MTLTextureDescriptor* textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm
|
||||||
|
width:(NSUInteger)tex->Width
|
||||||
|
height:(NSUInteger)tex->Height
|
||||||
|
mipmapped:NO];
|
||||||
|
textureDescriptor.usage = MTLTextureUsageShaderRead;
|
||||||
|
textureDescriptor.storageMode = MTLStorageModeShared;
|
||||||
|
|
||||||
|
id <MTLTexture> texture = [bd->SharedMetalContext.device newTextureWithDescriptor:textureDescriptor];
|
||||||
|
[bd->SharedMetalContext.residencySet addAllocation:texture];
|
||||||
|
[texture replaceRegion:MTLRegionMake2D(0, 0, (NSUInteger)tex->Width, (NSUInteger)tex->Height) mipmapLevel:0 withBytes:tex->Pixels bytesPerRow:(NSUInteger)tex->Width * 4];
|
||||||
|
MetalTexture* backend_tex = [[MetalTexture alloc] initWithTexture:texture];
|
||||||
|
|
||||||
|
// Store identifiers
|
||||||
|
tex->SetTexID((ImTextureID)(intptr_t)texture);
|
||||||
|
tex->SetStatus(ImTextureStatus_OK);
|
||||||
|
tex->BackendUserData = (__bridge_retained void*)(backend_tex);
|
||||||
|
}
|
||||||
|
else if (tex->Status == ImTextureStatus_WantUpdates)
|
||||||
|
{
|
||||||
|
// Update selected blocks. We only ever write to textures regions which have never been used before!
|
||||||
|
// This backend choose to use tex->Updates[] but you can use tex->UpdateRect to upload a single region.
|
||||||
|
MetalTexture* backend_tex = (__bridge MetalTexture*)(tex->BackendUserData);
|
||||||
|
for (ImTextureRect& r : tex->Updates)
|
||||||
|
{
|
||||||
|
[backend_tex.metalTexture replaceRegion:MTLRegionMake2D((NSUInteger)r.x, (NSUInteger)r.y, (NSUInteger)r.w, (NSUInteger)r.h)
|
||||||
|
mipmapLevel:0
|
||||||
|
withBytes:tex->GetPixelsAt(r.x, r.y)
|
||||||
|
bytesPerRow:(NSUInteger)tex->Width * 4];
|
||||||
|
}
|
||||||
|
tex->SetStatus(ImTextureStatus_OK);
|
||||||
|
}
|
||||||
|
else if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0)
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal4_DestroyTexture(tex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplMetal4_CreateDeviceObjects(id<MTLDevice> device)
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData();
|
||||||
|
|
||||||
|
MTLResidencySetDescriptor* residencySetDescriptor = [[MTLResidencySetDescriptor alloc] init];
|
||||||
|
residencySetDescriptor.initialCapacity = 1000;
|
||||||
|
|
||||||
|
NSError* error = nil;
|
||||||
|
bd->SharedMetalContext.residencySet = [device newResidencySetWithDescriptor:residencySetDescriptor error:&error];
|
||||||
|
IM_ASSERT(bd->SharedMetalContext.residencySet != nil && error == nil);
|
||||||
|
|
||||||
|
[bd->SharedMetalContext.commandQueue addResidencySet:bd->SharedMetalContext.residencySet];
|
||||||
|
|
||||||
|
MTLDepthStencilDescriptor* depthStencilDescriptor = [[MTLDepthStencilDescriptor alloc] init];
|
||||||
|
depthStencilDescriptor.depthWriteEnabled = NO;
|
||||||
|
depthStencilDescriptor.depthCompareFunction = MTLCompareFunctionAlways;
|
||||||
|
bd->SharedMetalContext.depthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
|
||||||
|
MTLSamplerDescriptor* samplerDescriptor = [[MTLSamplerDescriptor alloc] init];
|
||||||
|
samplerDescriptor.supportArgumentBuffers = YES;
|
||||||
|
samplerDescriptor.minFilter = MTLSamplerMinMagFilterLinear;
|
||||||
|
samplerDescriptor.magFilter = MTLSamplerMinMagFilterLinear;
|
||||||
|
samplerDescriptor.mipFilter = MTLSamplerMipFilterLinear;
|
||||||
|
bd->SharedMetalContext.samplerStateLinear = [device newSamplerStateWithDescriptor:samplerDescriptor];
|
||||||
|
samplerDescriptor.minFilter = MTLSamplerMinMagFilterNearest;
|
||||||
|
samplerDescriptor.magFilter = MTLSamplerMinMagFilterNearest;
|
||||||
|
samplerDescriptor.mipFilter = MTLSamplerMipFilterNearest;
|
||||||
|
bd->SharedMetalContext.samplerStateNearest = [device newSamplerStateWithDescriptor:samplerDescriptor];
|
||||||
|
|
||||||
|
NSMutableArray<id<MTLBuffer>>* constantBuffers = [NSMutableArray array];
|
||||||
|
ImGui_Metal4_ConstantData** constantBufferContentsArray = (ImGui_Metal4_ConstantData**)malloc(sizeof(ImGui_Metal4_ConstantData*) * bd->SharedMetalContext.framesInFlight);
|
||||||
|
for (NSUInteger i = 0; i < bd->SharedMetalContext.framesInFlight; i++)
|
||||||
|
{
|
||||||
|
id<MTLBuffer> constantBuffer = [device newBufferWithLength:sizeof(ImGui_Metal4_ConstantData) options:MTLResourceStorageModeShared];
|
||||||
|
[constantBuffers addObject:constantBuffer];
|
||||||
|
constantBufferContentsArray[i] = (ImGui_Metal4_ConstantData*)constantBuffer.contents;
|
||||||
|
[bd->SharedMetalContext.residencySet addAllocation:constantBuffer];
|
||||||
|
}
|
||||||
|
bd->SharedMetalContext.constantBuffers = constantBuffers;
|
||||||
|
bd->SharedMetalContext.constantBufferContentsArray = constantBufferContentsArray;
|
||||||
|
|
||||||
|
MTL4ArgumentTableDescriptor* argumentTableDescriptor = [[MTL4ArgumentTableDescriptor alloc] init];
|
||||||
|
argumentTableDescriptor.maxBufferBindCount = 8;
|
||||||
|
argumentTableDescriptor.maxTextureBindCount = 8;
|
||||||
|
argumentTableDescriptor.maxSamplerStateBindCount = 8;
|
||||||
|
argumentTableDescriptor.supportAttributeStrides = YES; // required: vertex buffer is bound via setAddress:stride:atIndex: for stage_in fetch
|
||||||
|
|
||||||
|
bd->SharedMetalContext.argumentTable = [device newArgumentTableWithDescriptor:argumentTableDescriptor error:&error];
|
||||||
|
IM_ASSERT(bd->SharedMetalContext.argumentTable != nil && error == nil);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplMetal4_DestroyDeviceObjects()
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData();
|
||||||
|
|
||||||
|
// Destroy all textures
|
||||||
|
for (ImTextureData* tex : ImGui::GetPlatformIO().Textures)
|
||||||
|
if (tex->RefCount == 1)
|
||||||
|
ImGui_ImplMetal4_DestroyTexture(tex);
|
||||||
|
|
||||||
|
[bd->SharedMetalContext.renderPipelineStateCache removeAllObjects];
|
||||||
|
bd->SharedMetalContext.samplerStateLinear = nil;
|
||||||
|
bd->SharedMetalContext.samplerStateNearest = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplMetal4_Init(id<MTLDevice> device, id<MTL4CommandQueue> commandQueue, int framesInFlight)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||||
|
IM_ASSERT(framesInFlight > 0 && "framesInFlight must be at least 1!");
|
||||||
|
|
||||||
|
ImGui_ImplMetal4_Data* bd = IM_NEW(ImGui_ImplMetal4_Data)();
|
||||||
|
io.BackendRendererUserData = (void*)bd;
|
||||||
|
io.BackendRendererName = "imgui_impl_metal4";
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplMetal4_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplMetal4_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplMetal4_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
|
bd->SharedMetalContext = [[MetalContext alloc] init];
|
||||||
|
bd->SharedMetalContext.device = device;
|
||||||
|
bd->SharedMetalContext.commandQueue = commandQueue;
|
||||||
|
bd->SharedMetalContext.framesInFlight = (NSUInteger)framesInFlight;
|
||||||
|
NSMutableArray<NSMutableArray<MetalBuffer*>*>* bufferCaches = [NSMutableArray array];
|
||||||
|
for (NSUInteger i = 0; i < framesInFlight; i++)
|
||||||
|
[bufferCaches addObject:[NSMutableArray array]];
|
||||||
|
bd->SharedMetalContext.bufferCaches = bufferCaches;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplMetal4_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData();
|
||||||
|
IM_UNUSED(bd);
|
||||||
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplMetal4_DestroyDeviceObjects();
|
||||||
|
ImGui_ImplMetal4_DestroyBackendData();
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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:(MTL4RenderPassDescriptor*)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 - MetalTexture implementation
|
||||||
|
|
||||||
|
@implementation MetalTexture
|
||||||
|
- (instancetype)initWithTexture:(id<MTLTexture>)metalTexture
|
||||||
|
{
|
||||||
|
if ((self = [super init]))
|
||||||
|
self.metalTexture = metalTexture;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
#pragma mark - MetalContext implementation
|
||||||
|
|
||||||
|
@implementation MetalContext
|
||||||
|
- (instancetype)init
|
||||||
|
{
|
||||||
|
if ((self = [super init]))
|
||||||
|
{
|
||||||
|
self.renderPipelineStateCache = [NSMutableDictionary dictionary];
|
||||||
|
self.bufferCacheLock = [[NSObject alloc] init];
|
||||||
|
_lastBufferCachePurge = GetMachAbsoluteTimeInSeconds();
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
free(_constantBufferContentsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id<MTLBuffer>)currentConstantBuffer
|
||||||
|
{
|
||||||
|
return self.constantBuffers[self.currentFrameSlot];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ImGui_Metal4_ConstantData*)currentConstantBufferContents
|
||||||
|
{
|
||||||
|
return self.constantBufferContentsArray[self.currentFrameSlot];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MetalBuffer*)dequeueReusableBufferOfLength:(NSUInteger)length device:(id<MTLDevice>)device
|
||||||
|
{
|
||||||
|
double now = GetMachAbsoluteTimeInSeconds();
|
||||||
|
NSMutableArray<MetalBuffer*>* slotCache = self.bufferCaches[self.currentFrameSlot];
|
||||||
|
|
||||||
|
@synchronized(self.bufferCacheLock)
|
||||||
|
{
|
||||||
|
// Purge old buffers that haven't been useful for a while
|
||||||
|
if (now - self.lastBufferCachePurge > 1.0)
|
||||||
|
{
|
||||||
|
for (NSMutableArray<MetalBuffer*>* cache in self.bufferCaches)
|
||||||
|
{
|
||||||
|
NSMutableArray* survivors = [NSMutableArray array];
|
||||||
|
for (MetalBuffer* candidate in cache)
|
||||||
|
if (candidate.lastReuseTime > self.lastBufferCachePurge)
|
||||||
|
[survivors addObject:candidate];
|
||||||
|
[cache setArray:survivors];
|
||||||
|
}
|
||||||
|
self.lastBufferCachePurge = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if we have a buffer we can reuse, from this frame-in-flight slot's own cache
|
||||||
|
MetalBuffer* bestCandidate = nil;
|
||||||
|
for (MetalBuffer* candidate in slotCache)
|
||||||
|
if (candidate.buffer.length >= length && (bestCandidate == nil || bestCandidate.lastReuseTime > candidate.lastReuseTime))
|
||||||
|
bestCandidate = candidate;
|
||||||
|
|
||||||
|
if (bestCandidate != nil)
|
||||||
|
{
|
||||||
|
[slotCache removeObject:bestCandidate];
|
||||||
|
bestCandidate.lastReuseTime = now;
|
||||||
|
return bestCandidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No luck; make a new buffer
|
||||||
|
id<MTLBuffer> backing = [device newBufferWithLength:length options:MTLResourceStorageModeShared];
|
||||||
|
[self.residencySet addAllocation:backing];
|
||||||
|
return [[MetalBuffer alloc] initWithBuffer:backing];
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* shaderCode = R"(
|
||||||
|
#include <metal_stdlib>
|
||||||
|
using namespace metal;
|
||||||
|
|
||||||
|
struct Uniforms {
|
||||||
|
float4x4 projectionMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexIn {
|
||||||
|
float2 position [[attribute(0)]];
|
||||||
|
float2 texCoords [[attribute(1)]];
|
||||||
|
uchar4 color [[attribute(2)]];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexOut {
|
||||||
|
float4 position [[position]];
|
||||||
|
float2 texCoords;
|
||||||
|
float4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex VertexOut vertex_main(VertexIn in [[stage_in]],
|
||||||
|
constant Uniforms &uniforms [[buffer(1)]])
|
||||||
|
{
|
||||||
|
VertexOut out;
|
||||||
|
out.position = uniforms.projectionMatrix * float4(in.position, 0, 1);
|
||||||
|
out.texCoords = in.texCoords;
|
||||||
|
out.color = float4(in.color) / float4(255.0);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment half4 fragment_main(VertexOut in [[stage_in]],
|
||||||
|
texture2d<half, access::sample> texture [[texture(0)]],
|
||||||
|
sampler textureSampler [[sampler(0)]])
|
||||||
|
{
|
||||||
|
half4 texColor = texture.sample(textureSampler, in.texCoords);
|
||||||
|
return half4(in.color) * texColor;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
- (id<MTLRenderPipelineState>)renderPipelineStateForFramebufferDescriptor:(FramebufferDescriptor*)descriptor device:(id<MTLDevice>)device
|
||||||
|
{
|
||||||
|
NSError* error = nil;
|
||||||
|
|
||||||
|
id<MTLLibrary> library = [device newLibraryWithSource:[NSString stringWithUTF8String:shaderCode] 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
|
||||||
102
backends/imgui_impl_null.cpp
Normal file
102
backends/imgui_impl_null.cpp
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
// dear imgui: Null Platform+Renderer Backends
|
||||||
|
// This is designed if you need to use a blind Dear Imgui context with no input and no output.
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
// 2025-11-17: Initial version.
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include "imgui_impl_null.h"
|
||||||
|
|
||||||
|
// Clang/GCC warnings with -Weverything
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplNull_Init()
|
||||||
|
{
|
||||||
|
ImGui_ImplNullPlatform_Init();
|
||||||
|
ImGui_ImplNullRender_Init();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNull_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplNullRender_Shutdown();
|
||||||
|
ImGui_ImplNullPlatform_Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNull_NewFrame()
|
||||||
|
{
|
||||||
|
ImGui_ImplNullPlatform_NewFrame();
|
||||||
|
ImGui_ImplNullRender_NewFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplNullPlatform_Init()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullPlatform_Shutdown()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.BackendFlags &= ~ImGuiBackendFlags_HasMouseCursors;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullPlatform_NewFrame()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.DisplaySize = ImVec2(1920, 1080);
|
||||||
|
io.DeltaTime = 1.0f / 60.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplNullRender_Init()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullRender_Shutdown()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
||||||
|
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasTextures;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullRender_NewFrame()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplNullRender_UpdateTexture(ImTextureData* tex)
|
||||||
|
{
|
||||||
|
if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantDestroy)
|
||||||
|
tex->SetStatus(ImTextureStatus_OK);
|
||||||
|
if (tex->Status == ImTextureStatus_WantDestroy)
|
||||||
|
{
|
||||||
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullRender_RenderDrawData(ImDrawData* draw_data)
|
||||||
|
{
|
||||||
|
if (draw_data->Textures != nullptr)
|
||||||
|
for (ImTextureData* tex : *draw_data->Textures)
|
||||||
|
if (tex->Status != ImTextureStatus_OK)
|
||||||
|
ImGui_ImplNullRender_UpdateTexture(tex);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
34
backends/imgui_impl_null.h
Normal file
34
backends/imgui_impl_null.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// dear imgui: Null Platform+Renderer Backends
|
||||||
|
// This is designed if you need to use a blind Dear Imgui context with no input and no output.
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
|
||||||
|
// Null = NullPlatform + NullRender
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplNull_Init();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNull_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNull_NewFrame();
|
||||||
|
|
||||||
|
// Null platform only (single screen, fixed timestep, no inputs)
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplNullPlatform_Init();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullPlatform_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullPlatform_NewFrame();
|
||||||
|
|
||||||
|
// Null renderer only (no output)
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplNullRender_Init();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullRender_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullRender_NewFrame();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplNullRender_RenderDrawData(ImDrawData* draw_data);
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
// [ ] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [ ] Renderer: Use of DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest is emulated by poking to glTexParameter(), as legacy OpenGL doesn't have glBindSampler().
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -26,7 +27,10 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-23: OpenGL: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. (#9378)
|
||||||
|
// 2026-03-12: OpenGL: Fixed invalid assert in ImGui_ImplOpenGL3_UpdateTexture() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-07-15: OpenGL: Set GL_UNPACK_ALIGNMENT to 1 before updating textures. (#8802)
|
// 2025-07-15: OpenGL: Set GL_UNPACK_ALIGNMENT to 1 before updating textures. (#8802)
|
||||||
// 2025-06-11: OpenGL: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplOpenGL2_CreateFontsTexture() and ImGui_ImplOpenGL2_DestroyFontsTexture().
|
// 2025-06-11: OpenGL: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplOpenGL2_CreateFontsTexture() and ImGui_ImplOpenGL2_DestroyFontsTexture().
|
||||||
// 2024-10-07: OpenGL: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
// 2024-10-07: OpenGL: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
||||||
@@ -86,6 +90,9 @@
|
|||||||
// OpenGL data
|
// OpenGL data
|
||||||
struct ImGui_ImplOpenGL2_Data
|
struct ImGui_ImplOpenGL2_Data
|
||||||
{
|
{
|
||||||
|
bool UseTexParameterToSetSampler;
|
||||||
|
GLuint NextSampler;
|
||||||
|
|
||||||
ImGui_ImplOpenGL2_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplOpenGL2_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,38 +108,6 @@ static void ImGui_ImplOpenGL2_InitMultiViewportSupport();
|
|||||||
static void ImGui_ImplOpenGL2_ShutdownMultiViewportSupport();
|
static void ImGui_ImplOpenGL2_ShutdownMultiViewportSupport();
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
bool ImGui_ImplOpenGL2_Init()
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
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";
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL2_InitMultiViewportSupport();
|
|
||||||
|
|
||||||
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_ShutdownMultiViewportSupport();
|
|
||||||
ImGui_ImplOpenGL2_DestroyDeviceObjects();
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplOpenGL2_NewFrame()
|
void ImGui_ImplOpenGL2_NewFrame()
|
||||||
{
|
{
|
||||||
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
||||||
@@ -143,6 +118,7 @@ void ImGui_ImplOpenGL2_NewFrame()
|
|||||||
static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height)
|
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.
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
|
||||||
|
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
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
|
//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
|
||||||
@@ -160,6 +136,7 @@ static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_wid
|
|||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
|
bd->NextSampler = GL_LINEAR;
|
||||||
|
|
||||||
// If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!),
|
// 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.
|
// you may need to backup/reset/restore other state, e.g. for current shader using the commented lines below.
|
||||||
@@ -184,12 +161,18 @@ static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_wid
|
|||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplOpenGL2_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplOpenGL2_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData(); bd->UseTexParameterToSetSampler = true; bd->NextSampler = GL_LINEAR; }
|
||||||
|
static void ImGui_ImplOpenGL2_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData(); bd->UseTexParameterToSetSampler = true; bd->NextSampler = GL_NEAREST; }
|
||||||
|
|
||||||
// OpenGL2 Render function.
|
// OpenGL2 Render function.
|
||||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly.
|
// 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.
|
// 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)
|
void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||||
|
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
||||||
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
|
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
|
||||||
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
|
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
|
||||||
if (fb_width == 0 || fb_height == 0)
|
if (fb_width == 0 || fb_height == 0)
|
||||||
@@ -233,8 +216,7 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (pcmd->UserCallback)
|
if (pcmd->UserCallback)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplOpenGL2_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
|
ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -251,7 +233,17 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
|
|||||||
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));
|
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
|
// Bind texture, Draw
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID());
|
GLuint pcmd_texture = (GLuint)(intptr_t)pcmd->GetTexID();
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pcmd_texture);
|
||||||
|
|
||||||
|
// Emulate sampler change (even though it is technically part of texture data)
|
||||||
|
// As a sort of hack/workaround, we only start writing using glTextParameter() if sampler is ever changed explicitly.
|
||||||
|
if (bd->UseTexParameterToSetSampler)
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, bd->NextSampler);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, bd->NextSampler);
|
||||||
|
}
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset);
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,7 +272,7 @@ void ImGui_ImplOpenGL2_UpdateTexture(ImTextureData* tex)
|
|||||||
{
|
{
|
||||||
// Create and upload new texture to graphics system
|
// Create and upload new texture to graphics system
|
||||||
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
||||||
IM_ASSERT(tex->TexID == 0 && tex->BackendUserData == nullptr);
|
IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr);
|
||||||
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
||||||
const void* pixels = tex->GetPixels();
|
const void* pixels = tex->GetPixels();
|
||||||
GLuint gl_texture_id = 0;
|
GLuint gl_texture_id = 0;
|
||||||
@@ -349,6 +341,45 @@ void ImGui_ImplOpenGL2_DestroyDeviceObjects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplOpenGL2_Init()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
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";
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL2_InitMultiViewportSupport();
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplOpenGL2_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplOpenGL2_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplOpenGL2_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
|
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();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL2_ShutdownMultiViewportSupport();
|
||||||
|
ImGui_ImplOpenGL2_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
// [ ] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [ ] Renderer: Use of DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest is emulated by poking to glTexParameter(), as legacy OpenGL doesn't have glBindSampler().
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -38,7 +39,7 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data);
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL2_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplOpenGL2_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -24,7 +24,14 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-06-17: OpenGL: Expose selected render state in ImGui_ImplOpenGL3_RenderState, Allowing to dynamically select between use of glBindSampler() and glTexParameter(). You can access in 'void* platform_io.Renderer_RenderState' during rendering.
|
||||||
|
// 2026-06-03: OpenGL: GLSL version detection assume GLSL 410 when GL context is 4.1. Fixes an issue running on macOS with Wine. (#9427, #6577)
|
||||||
|
// 2026-04-23: OpenGL: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. (#9378)
|
||||||
|
// (Breaking): this change prioritize using glBindSampler() when available, which would override glTexParameter() settings you may have set on custom textures.
|
||||||
|
// 2026-03-12: OpenGL: Fixed invalid assert in ImGui_ImplOpenGL3_UpdateTexture() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295)
|
||||||
|
// 2025-12-11: OpenGL: Fixed embedded loader multiple init/shutdown cycles broken on some platforms. (#8792, #9112)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-07-22: OpenGL: Add and call embedded loader shutdown during ImGui_ImplOpenGL3_Shutdown() to facilitate multiple init/shutdown cycles in same process. (#8792)
|
// 2025-07-22: OpenGL: Add and call embedded loader shutdown during ImGui_ImplOpenGL3_Shutdown() to facilitate multiple init/shutdown cycles in same process. (#8792)
|
||||||
// 2025-07-15: OpenGL: Set GL_UNPACK_ALIGNMENT to 1 before updating textures (#8802) + restore non-WebGL/ES update path that doesn't require a CPU-side copy.
|
// 2025-07-15: OpenGL: Set GL_UNPACK_ALIGNMENT to 1 before updating textures (#8802) + restore non-WebGL/ES update path that doesn't require a CPU-side copy.
|
||||||
// 2025-06-11: OpenGL: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplOpenGL3_CreateFontsTexture() and ImGui_ImplOpenGL3_DestroyFontsTexture().
|
// 2025-06-11: OpenGL: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplOpenGL3_CreateFontsTexture() and ImGui_ImplOpenGL3_DestroyFontsTexture().
|
||||||
@@ -41,7 +48,7 @@
|
|||||||
// 2023-05-09: OpenGL: Support for glBindSampler() backup/restore on ES3. (#6375)
|
// 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-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-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-15: OpenGL: Fixed GL loader crash when GL_VERSION returns nullptr. (#6154, #4445, #3530)
|
||||||
// 2023-03-06: OpenGL: Fixed restoration of a potentially deleted OpenGL program, by calling glIsProgram(). (#6220, #6224)
|
// 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-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-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
||||||
@@ -251,6 +258,10 @@ struct ImGui_ImplOpenGL3_Data
|
|||||||
bool HasBindSampler;
|
bool HasBindSampler;
|
||||||
bool HasClipOrigin;
|
bool HasClipOrigin;
|
||||||
bool UseBufferSubData;
|
bool UseBufferSubData;
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
|
GLuint TexSamplers[2]; // Used if HasBindSimpler. (0=linear, 1=nearest)
|
||||||
|
#endif
|
||||||
|
|
||||||
ImVector<char> TempBuffer;
|
ImVector<char> TempBuffer;
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
@@ -295,7 +306,8 @@ struct ImGui_ImplOpenGL3_VtxAttribState
|
|||||||
bool ImGui_ImplOpenGL3_InitLoader();
|
bool ImGui_ImplOpenGL3_InitLoader();
|
||||||
bool ImGui_ImplOpenGL3_InitLoader()
|
bool ImGui_ImplOpenGL3_InitLoader()
|
||||||
{
|
{
|
||||||
// Initialize our loader
|
// Lazily initialize our loader if not already done
|
||||||
|
// (to facilitate handling multiple DLL boundaries and multiple context shutdowns we call this from all main entry points)
|
||||||
#ifdef IMGUI_IMPL_OPENGL_LOADER_IMGL3W
|
#ifdef IMGUI_IMPL_OPENGL_LOADER_IMGL3W
|
||||||
if (glGetIntegerv == nullptr && imgl3wInit() != 0)
|
if (glGetIntegerv == nullptr && imgl3wInit() != 0)
|
||||||
{
|
{
|
||||||
@@ -306,156 +318,26 @@ bool ImGui_ImplOpenGL3_InitLoader()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
static void ImGui_ImplOpenGL3_ShutdownLoader()
|
||||||
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
||||||
|
|
||||||
// Initialize loader
|
|
||||||
if (!ImGui_ImplOpenGL3_InitLoader())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
const char* gl_version_str = (const char*)glGetString(GL_VERSION);
|
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
|
||||||
// GLES 2
|
|
||||||
bd->GlVersion = 200;
|
|
||||||
bd->GlProfileIsES2 = true;
|
|
||||||
IM_UNUSED(gl_version_str);
|
|
||||||
#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)
|
|
||||||
sscanf(gl_version_str, "%d.%d", &major, &minor); // Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
|
||||||
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
|
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &bd->MaxTextureSize);
|
|
||||||
|
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES3)
|
|
||||||
bd->GlProfileIsES3 = true;
|
|
||||||
#else
|
|
||||||
if (strncmp(gl_version_str, "OpenGL ES 3", 11) == 0)
|
|
||||||
bd->GlProfileIsES3 = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(GL_CONTEXT_PROFILE_MASK)
|
|
||||||
if (!bd->GlProfileIsES3 && bd->GlVersion >= 320)
|
|
||||||
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask);
|
|
||||||
bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bd->UseBufferSubData = false;
|
|
||||||
/*
|
|
||||||
// Query vendor to enable glBufferSubData kludge
|
|
||||||
#ifdef _WIN32
|
|
||||||
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
|
|
||||||
if (strncmp(vendor, "Intel", 5) == 0)
|
|
||||||
bd->UseBufferSubData = true;
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
|
||||||
printf("GlVersion = %d, \"%s\"\nGlProfileIsCompat = %d\nGlProfileMask = 0x%X\nGlProfileIsES2/IsEs3 = %d/%d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", bd->GlVersion, gl_version_str, bd->GlProfileIsCompat, bd->GlProfileMask, bd->GlProfileIsES2, bd->GlProfileIsES3, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG]
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
|
||||||
if (bd->GlVersion >= 320)
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
||||||
#endif
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
|
||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
|
||||||
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = (int)bd->MaxTextureSize;
|
|
||||||
|
|
||||||
// Store GLSL version string so we can refer to it later in case we recreate shaders.
|
|
||||||
// Note: GLSL version is NOT the same as GL version. Leave this to nullptr if unsure.
|
|
||||||
if (glsl_version == nullptr)
|
|
||||||
{
|
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
|
||||||
glsl_version = "#version 100";
|
|
||||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
|
||||||
glsl_version = "#version 300 es";
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
glsl_version = "#version 150";
|
|
||||||
#else
|
|
||||||
glsl_version = "#version 130";
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(bd->GlslVersionString));
|
|
||||||
strcpy(bd->GlslVersionString, glsl_version);
|
|
||||||
strcat(bd->GlslVersionString, "\n");
|
|
||||||
|
|
||||||
// Make an arbitrary GL call (we don't actually need the result)
|
|
||||||
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
|
|
||||||
GLint current_texture;
|
|
||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
|
||||||
|
|
||||||
// Detect extensions we support
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
|
||||||
bd->HasPolygonMode = (!bd->GlProfileIsES2 && !bd->GlProfileIsES3);
|
|
||||||
#endif
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
|
||||||
bd->HasBindSampler = (bd->GlVersion >= 330 || bd->GlProfileIsES3);
|
|
||||||
#endif
|
|
||||||
bd->HasClipOrigin = (bd->GlVersion >= 450);
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_HAS_EXTENSIONS
|
|
||||||
GLint num_extensions = 0;
|
|
||||||
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
|
|
||||||
for (GLint i = 0; i < num_extensions; i++)
|
|
||||||
{
|
|
||||||
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
|
||||||
if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0)
|
|
||||||
bd->HasClipOrigin = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_InitMultiViewportSupport();
|
|
||||||
|
|
||||||
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_ShutdownMultiViewportSupport();
|
|
||||||
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
|
||||||
io.BackendRendererName = nullptr;
|
|
||||||
io.BackendRendererUserData = nullptr;
|
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_LOADER_IMGL3W
|
#ifdef IMGUI_IMPL_OPENGL_LOADER_IMGL3W
|
||||||
imgl3wShutdown();
|
imgl3wShutdown();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Functions
|
||||||
void ImGui_ImplOpenGL3_NewFrame()
|
void ImGui_ImplOpenGL3_NewFrame()
|
||||||
{
|
{
|
||||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplOpenGL3_Init()?");
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplOpenGL3_Init()?");
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_InitLoader(); // Lazily init loader if not already done for e.g. DLL boundaries.
|
ImGui_ImplOpenGL3_InitLoader();
|
||||||
|
|
||||||
if (!bd->ShaderHandle)
|
if (!bd->ShaderHandle)
|
||||||
if (!ImGui_ImplOpenGL3_CreateDeviceObjects())
|
if (!ImGui_ImplOpenGL3_CreateDeviceObjects())
|
||||||
IM_ASSERT(0 && "ImGui_ImplOpenGL3_CreateDeviceObjects() failed!");
|
IM_ASSERT(0 && "ImGui_ImplOpenGL3_CreateDeviceObjects() failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
|
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, ImGui_ImplOpenGL3_RenderState* render_state, int fb_width, int fb_height, GLuint vertex_array_object)
|
||||||
{
|
{
|
||||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
|
||||||
@@ -509,8 +391,11 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
|
|||||||
glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
if (bd->HasBindSampler)
|
if (render_state->UseBindSampler)
|
||||||
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 and GL ES 3.0 may set that otherwise.
|
{
|
||||||
|
render_state->CurrentSampler = bd->TexSamplers[0];
|
||||||
|
glBindSampler(0, render_state->CurrentSampler); // We use combined texture/sampler state. Applications using GL 3.3 and GL ES 3.0 may set that otherwise.
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(void)vertex_array_object;
|
(void)vertex_array_object;
|
||||||
@@ -529,6 +414,45 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
|
|||||||
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, col)));
|
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, col)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplOpenGL3_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplOpenGL3_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*)
|
||||||
|
{
|
||||||
|
ImGui_ImplOpenGL3_RenderState* render_state = ImGui_ImplOpenGL3_GetRenderState();
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
if (bd->HasBindSampler)
|
||||||
|
{
|
||||||
|
render_state->CurrentSampler = bd->TexSamplers[0];
|
||||||
|
render_state->UseTexParameterFilter = false;
|
||||||
|
glBindSampler(0, render_state->CurrentSampler);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
render_state->UseTexParameterFilter = true;
|
||||||
|
render_state->CurrentTexParameterFilter = GL_LINEAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void ImGui_ImplOpenGL3_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*)
|
||||||
|
{
|
||||||
|
ImGui_ImplOpenGL3_RenderState* render_state = ImGui_ImplOpenGL3_GetRenderState();
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
if (bd->HasBindSampler)
|
||||||
|
{
|
||||||
|
render_state->CurrentSampler = bd->TexSamplers[1];
|
||||||
|
render_state->UseTexParameterFilter = false;
|
||||||
|
glBindSampler(0, render_state->CurrentSampler);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
render_state->UseTexParameterFilter = true;
|
||||||
|
render_state->CurrentTexParameterFilter = GL_NEAREST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// OpenGL3 Render function.
|
// OpenGL3 Render function.
|
||||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly.
|
// 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.
|
// This is in order to be able to run within an OpenGL engine that doesn't do so.
|
||||||
@@ -540,7 +464,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (fb_width <= 0 || fb_height <= 0)
|
if (fb_width <= 0 || fb_height <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_InitLoader(); // Lazily init loader if not already done for e.g. DLL boundaries.
|
ImGui_ImplOpenGL3_InitLoader();
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
|
||||||
@@ -597,7 +521,17 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
GL_CALL(glGenVertexArrays(1, &vertex_array_object));
|
GL_CALL(glGenVertexArrays(1, &vertex_array_object));
|
||||||
#endif
|
#endif
|
||||||
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
|
||||||
|
// Setup render state structure (for callbacks and custom texture bindings)
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
ImGui_ImplOpenGL3_RenderState render_state;
|
||||||
|
render_state.UseBindSampler = bd->HasBindSampler;
|
||||||
|
render_state.UseTexParameterFilter = false;
|
||||||
|
render_state.CurrentSampler = 0;
|
||||||
|
render_state.CurrentTexParameterFilter = 0;
|
||||||
|
platform_io.Renderer_RenderState = &render_state;
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_SetupRenderState(draw_data, &render_state, fb_width, fb_height, vertex_array_object);
|
||||||
|
|
||||||
// Will project scissor/clipping rectangles into framebuffer space
|
// Will project scissor/clipping rectangles into framebuffer space
|
||||||
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
||||||
@@ -643,9 +577,8 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
if (pcmd->UserCallback != nullptr)
|
if (pcmd->UserCallback != nullptr)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplOpenGL3_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
ImGui_ImplOpenGL3_SetupRenderState(draw_data, &render_state, fb_width, fb_height, vertex_array_object);
|
||||||
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
}
|
}
|
||||||
@@ -662,6 +595,15 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
|
|
||||||
// Bind texture, Draw
|
// Bind texture, Draw
|
||||||
GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
|
GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
|
||||||
|
|
||||||
|
// Emulate sampler change (even though it is technically part of texture data)
|
||||||
|
// As a sort of hack/workaround, we only start writing using glTexParameter() if sampler is ever changed explicitly.
|
||||||
|
if (render_state.UseTexParameterFilter)
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, render_state.CurrentTexParameterFilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, render_state.CurrentTexParameterFilter);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||||
if (bd->GlVersion >= 320)
|
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));
|
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));
|
||||||
@@ -671,6 +613,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
platform_io.Renderer_RenderState = nullptr;
|
||||||
|
|
||||||
// Destroy the temporary VAO
|
// Destroy the temporary VAO
|
||||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||||
@@ -744,7 +687,7 @@ void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex)
|
|||||||
{
|
{
|
||||||
// Create and upload new texture to graphics system
|
// Create and upload new texture to graphics system
|
||||||
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
||||||
IM_ASSERT(tex->TexID == 0 && tex->BackendUserData == nullptr);
|
IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr);
|
||||||
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
||||||
const void* pixels = tex->GetPixels();
|
const void* pixels = tex->GetPixels();
|
||||||
GLuint gl_texture_id = 0;
|
GLuint gl_texture_id = 0;
|
||||||
@@ -843,6 +786,7 @@ static bool CheckProgram(GLuint handle, const char* desc)
|
|||||||
|
|
||||||
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_InitLoader();
|
||||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
|
||||||
// Backup GL state
|
// Backup GL state
|
||||||
@@ -1026,6 +970,20 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
|||||||
glGenBuffers(1, &bd->VboHandle);
|
glGenBuffers(1, &bd->VboHandle);
|
||||||
glGenBuffers(1, &bd->ElementsHandle);
|
glGenBuffers(1, &bd->ElementsHandle);
|
||||||
|
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
|
if (bd->HasBindSampler)
|
||||||
|
{
|
||||||
|
glGenSamplers(2, &bd->TexSamplers[0]);
|
||||||
|
for (int sampler_n = 0; sampler_n < 2; sampler_n++)
|
||||||
|
{
|
||||||
|
GL_CALL(glSamplerParameteri(bd->TexSamplers[sampler_n], GL_TEXTURE_MIN_FILTER, (sampler_n == 0) ? GL_LINEAR : GL_NEAREST));
|
||||||
|
GL_CALL(glSamplerParameteri(bd->TexSamplers[sampler_n], GL_TEXTURE_MAG_FILTER, (sampler_n == 0) ? GL_LINEAR : GL_NEAREST));
|
||||||
|
GL_CALL(glSamplerParameteri(bd->TexSamplers[sampler_n], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
|
||||||
|
GL_CALL(glSamplerParameteri(bd->TexSamplers[sampler_n], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Restore modified GL state
|
// Restore modified GL state
|
||||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||||
@@ -1041,7 +999,11 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
|||||||
|
|
||||||
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_InitLoader();
|
||||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
|
if (bd->TexSamplers[0]) { glDeleteSamplers(2, &bd->TexSamplers[0]); bd->TexSamplers[0] = bd->TexSamplers[1] = 0; }
|
||||||
|
#endif
|
||||||
if (bd->VboHandle) { glDeleteBuffers(1, &bd->VboHandle); bd->VboHandle = 0; }
|
if (bd->VboHandle) { glDeleteBuffers(1, &bd->VboHandle); bd->VboHandle = 0; }
|
||||||
if (bd->ElementsHandle) { glDeleteBuffers(1, &bd->ElementsHandle); bd->ElementsHandle = 0; }
|
if (bd->ElementsHandle) { glDeleteBuffers(1, &bd->ElementsHandle); bd->ElementsHandle = 0; }
|
||||||
if (bd->ShaderHandle) { glDeleteProgram(bd->ShaderHandle); bd->ShaderHandle = 0; }
|
if (bd->ShaderHandle) { glDeleteProgram(bd->ShaderHandle); bd->ShaderHandle = 0; }
|
||||||
@@ -1052,6 +1014,149 @@ void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
|||||||
ImGui_ImplOpenGL3_DestroyTexture(tex);
|
ImGui_ImplOpenGL3_DestroyTexture(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||||
|
|
||||||
|
// Initialize loader
|
||||||
|
if (!ImGui_ImplOpenGL3_InitLoader())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
const char* gl_version_str = (const char*)glGetString(GL_VERSION);
|
||||||
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
|
// GLES 2
|
||||||
|
bd->GlVersion = 200;
|
||||||
|
bd->GlProfileIsES2 = true;
|
||||||
|
IM_UNUSED(gl_version_str);
|
||||||
|
#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)
|
||||||
|
sscanf(gl_version_str, "%d.%d", &major, &minor); // Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||||
|
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
|
||||||
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &bd->MaxTextureSize);
|
||||||
|
|
||||||
|
#if defined(IMGUI_IMPL_OPENGL_ES3)
|
||||||
|
bd->GlProfileIsES3 = true;
|
||||||
|
#else
|
||||||
|
if (strncmp(gl_version_str, "OpenGL ES 3", 11) == 0)
|
||||||
|
bd->GlProfileIsES3 = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(GL_CONTEXT_PROFILE_MASK)
|
||||||
|
if (!bd->GlProfileIsES3 && bd->GlVersion >= 320)
|
||||||
|
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask);
|
||||||
|
bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bd->UseBufferSubData = false;
|
||||||
|
/*
|
||||||
|
// Query vendor to enable glBufferSubData kludge
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
|
||||||
|
if (strncmp(vendor, "Intel", 5) == 0)
|
||||||
|
bd->UseBufferSubData = true;
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
||||||
|
printf("GlVersion = %d, \"%s\"\nGlProfileIsCompat = %d\nGlProfileMask = 0x%X\nGlProfileIsES2/IsEs3 = %d/%d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", bd->GlVersion, gl_version_str, bd->GlProfileIsCompat, bd->GlProfileMask, bd->GlProfileIsES2, bd->GlProfileIsES3, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||||
|
if (bd->GlVersion >= 320)
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||||
|
#endif
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = (int)bd->MaxTextureSize;
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplOpenGL3_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplOpenGL3_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplOpenGL3_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if (bd->GlVersion >= 410)
|
||||||
|
glsl_version = "#version 410";
|
||||||
|
else
|
||||||
|
glsl_version = "#version 130";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_COUNTOF(bd->GlslVersionString));
|
||||||
|
strcpy(bd->GlslVersionString, glsl_version);
|
||||||
|
strcat(bd->GlslVersionString, "\n");
|
||||||
|
|
||||||
|
// Make an arbitrary GL call (we don't actually need the result)
|
||||||
|
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
|
||||||
|
GLint current_texture;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
||||||
|
|
||||||
|
// Detect extensions we support
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||||
|
bd->HasPolygonMode = (!bd->GlProfileIsES2 && !bd->GlProfileIsES3);
|
||||||
|
#endif
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||||
|
bd->HasBindSampler = (bd->GlVersion >= 330 || bd->GlProfileIsES3);
|
||||||
|
#endif
|
||||||
|
bd->HasClipOrigin = (bd->GlVersion >= 450);
|
||||||
|
#ifdef IMGUI_IMPL_OPENGL_HAS_EXTENSIONS
|
||||||
|
GLint num_extensions = 0;
|
||||||
|
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
|
||||||
|
for (GLint i = 0; i < num_extensions; i++)
|
||||||
|
{
|
||||||
|
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||||
|
if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0)
|
||||||
|
bd->HasClipOrigin = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_InitMultiViewportSupport();
|
||||||
|
|
||||||
|
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();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_ShutdownMultiViewportSupport();
|
||||||
|
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_ShutdownLoader();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
||||||
// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
|
// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// Configuration flags to add in your imconfig file:
|
// Configuration flags to add in your imconfig file:
|
||||||
@@ -66,4 +66,17 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
|
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplOpenGL3_RenderDrawData() call.
|
||||||
|
// (Please open an issue if you feel you need access to more data)
|
||||||
|
struct ImGui_ImplOpenGL3_RenderState
|
||||||
|
{
|
||||||
|
bool UseBindSampler;
|
||||||
|
bool UseTexParameterFilter;
|
||||||
|
unsigned int CurrentSampler; // (GLuint) Used if UseBindSampler == true, otherwise always 0
|
||||||
|
unsigned int CurrentTexParameterFilter; // (GLuint) Used if UseTexParameterToSetSampler == true
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline ImGui_ImplOpenGL3_RenderState* ImGui_ImplOpenGL3_GetRenderState() { return (ImGui_ImplOpenGL3_RenderState*)ImGui::GetPlatformIO().Renderer_RenderState; }
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -714,7 +714,11 @@ static void close_libgl(void)
|
|||||||
|
|
||||||
static int is_library_loaded(const char* name, void** lib)
|
static int is_library_loaded(const char* name, void** lib)
|
||||||
{
|
{
|
||||||
|
#if defined(__HAIKU__)
|
||||||
|
*lib = NULL; // no support for RTLD_NOLOAD on Haiku.
|
||||||
|
#else
|
||||||
*lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
|
*lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
|
||||||
|
#endif
|
||||||
return *lib != NULL;
|
return *lib != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -832,6 +836,7 @@ static int parse_version(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void load_procs(GL3WGetProcAddressProc proc);
|
static void load_procs(GL3WGetProcAddressProc proc);
|
||||||
|
static void clear_procs();
|
||||||
|
|
||||||
int imgl3wInit(void)
|
int imgl3wInit(void)
|
||||||
{
|
{
|
||||||
@@ -851,6 +856,7 @@ int imgl3wInit2(GL3WGetProcAddressProc proc)
|
|||||||
void imgl3wShutdown(void)
|
void imgl3wShutdown(void)
|
||||||
{
|
{
|
||||||
close_libgl();
|
close_libgl();
|
||||||
|
clear_procs();
|
||||||
}
|
}
|
||||||
|
|
||||||
int imgl3wIsSupported(int major, int minor)
|
int imgl3wIsSupported(int major, int minor)
|
||||||
@@ -939,6 +945,13 @@ static void load_procs(GL3WGetProcAddressProc proc)
|
|||||||
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clear_procs()
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
|
||||||
|
imgl3wProcs.ptr[i] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
// [X] Platform: IME support.
|
// [X] Platform: IME support.
|
||||||
// [x] Platform: Multi-viewport / platform windows.
|
// [x] Platform: Multi-viewport / platform windows.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Multi-viewport: Window size not correctly reported when enabling io.ConfigViewportsNoDecoration
|
// [ ] Platform: Multi-viewport: Window size not correctly reported when enabling io.ConfigViewportsNoDecoration
|
||||||
// [ ] Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
// [ ] Platform: Multi-viewport: Missing ImGuiBackendFlags_HasParentViewport support. The viewport->ParentViewportID field is ignored, and therefore io.ConfigViewportsNoDefaultParent has no effect either.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
// [X] Platform: IME support.
|
// [X] Platform: IME support.
|
||||||
// [x] Platform: Multi-viewport / platform windows.
|
// [x] Platform: Multi-viewport / platform windows.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Multi-viewport: Window size not correctly reported when enabling io.ConfigViewportsNoDecoration
|
// [ ] Platform: Multi-viewport: Window size not correctly reported when enabling io.ConfigViewportsNoDecoration
|
||||||
// [ ] Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
// [ ] Platform: Multi-viewport: Missing ImGuiBackendFlags_HasParentViewport support. The viewport->ParentViewportID field is ignored, and therefore io.ConfigViewportsNoDefaultParent has no effect either.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
// 2025-07-08: [Docking] Fixed multi-viewport handling broken on 2025-06-02. (#8644, #8777)
|
// 2025-07-08: [Docking] Fixed multi-viewport handling broken on 2025-06-02. (#8644, #8777)
|
||||||
// 2025-06-27: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
|
// 2025-06-27: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
|
||||||
// 2025-06-12: ImGui_ImplOSX_HandleEvent() only process event for window containing our view. (#8644)
|
// 2025-06-12: ImGui_ImplOSX_HandleEvent() only process event for window containing our view. (#8644)
|
||||||
@@ -550,9 +551,12 @@ void ImGui_ImplOSX_Shutdown()
|
|||||||
ImGui_ImplOSX_ShutdownMultiViewportSupport();
|
ImGui_ImplOSX_ShutdownMultiViewportSupport();
|
||||||
ImGui_ImplOSX_DestroyBackendData();
|
ImGui_ImplOSX_DestroyBackendData();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
io.BackendPlatformName = nullptr;
|
io.BackendPlatformName = nullptr;
|
||||||
io.BackendPlatformUserData = nullptr;
|
io.BackendPlatformUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports);
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports);
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplOSX_UpdateMouseCursor()
|
static void ImGui_ImplOSX_UpdateMouseCursor()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
|
// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
|
||||||
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
// [ ] Platform: Multi-viewport: Missing ImGuiBackendFlags_HasParentViewport support. The viewport->ParentViewportID field is ignored, and therefore io.ConfigViewportsNoDefaultParent has no effect either.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -25,7 +25,13 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-16: Made ImGui_ImplSDL2_GetContentScaleForWindow(), ImGui_ImplSDL2_GetContentScaleForDisplay() helpers return a minimum of 1.0f, as some Linux setup seems to report <1.0f value and this breaks scaling border size. (#9369)
|
||||||
|
// 2026-03-09: [Docking] Fixed an issue dated 2025/04/09 (1.92 WIP) where a refactor+merge caused ImGuiBackendFlags_HasMouseHoveredViewport to never be set, causing foreign windows to be ignored when deciding of hovered viewport. (#9284)
|
||||||
|
// 2026-02-13: Inputs: systems other than X11 are back to starting mouse capture on mouse down (reverts 2025-02-26 change). Only X11 requires waiting for a drag by default (not ideal, but a better default for X11 users). Added ImGui_ImplSDL2_SetMouseCaptureMode() for X11 debugger users. (#3650, #6410, #9235)
|
||||||
|
// 2026-01-15: Changed GetClipboardText() handler to return nullptr on error aka clipboard contents is not text. Consistent with other backends. (#9168)
|
||||||
|
// 2025-09-24: Skip using the SDL_GetGlobalMouseState() state when one of our window is hovered, as the SDL_MOUSEMOTION data is reliable. Fix macOS notch mouse coordinates issue in fullscreen mode + better perf on X11. (#7919, #7786)
|
||||||
|
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
// 2025-09-15: Content Scales are always reported as 1.0 on Wayland. (#8921)
|
// 2025-09-15: Content Scales are always reported as 1.0 on Wayland. (#8921)
|
||||||
// 2025-07-08: Made ImGui_ImplSDL2_GetContentScaleForWindow(), ImGui_ImplSDL2_GetContentScaleForDisplay() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
|
// 2025-07-08: Made ImGui_ImplSDL2_GetContentScaleForWindow(), ImGui_ImplSDL2_GetContentScaleForDisplay() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
|
||||||
// 2025-06-11: Added ImGui_ImplSDL2_GetContentScaleForWindow(SDL_Window* window) and ImGui_ImplSDL2_GetContentScaleForDisplay(int display_index) helper to facilitate making DPI-aware apps.
|
// 2025-06-11: Added ImGui_ImplSDL2_GetContentScaleForWindow(SDL_Window* window) and ImGui_ImplSDL2_GetContentScaleForDisplay(int display_index) helper to facilitate making DPI-aware apps.
|
||||||
@@ -34,7 +40,7 @@
|
|||||||
// 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561)
|
// 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561)
|
||||||
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
|
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
|
||||||
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
||||||
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g.Linux debuggers not claiming capture back. (#6410, #3650)
|
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g. Linux debuggers not claiming capture back. (#6410, #3650)
|
||||||
// 2025-02-25: [Docking] Revert to use SDL_GetDisplayBounds() for WorkPos/WorkRect if SDL_GetDisplayUsableBounds() failed.
|
// 2025-02-25: [Docking] Revert to use SDL_GetDisplayBounds() for WorkPos/WorkRect if SDL_GetDisplayUsableBounds() failed.
|
||||||
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
|
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
|
||||||
// 2025-02-21: [Docking] Update monitors and work areas information every frame, as the later may change regardless of monitor changes. (#8415)
|
// 2025-02-21: [Docking] Update monitors and work areas information every frame, as the later may change regardless of monitor changes. (#8415)
|
||||||
@@ -159,8 +165,9 @@ struct ImGui_ImplSDL2_Data
|
|||||||
SDL_Renderer* Renderer;
|
SDL_Renderer* Renderer;
|
||||||
Uint64 Time;
|
Uint64 Time;
|
||||||
char* ClipboardTextData;
|
char* ClipboardTextData;
|
||||||
char BackendPlatformName[48];
|
char BackendPlatformName[64];
|
||||||
bool UseVulkan;
|
bool IsWayland;
|
||||||
|
bool IsVulkan;
|
||||||
bool WantUpdateMonitors;
|
bool WantUpdateMonitors;
|
||||||
|
|
||||||
// Mouse handling
|
// Mouse handling
|
||||||
@@ -170,8 +177,8 @@ struct ImGui_ImplSDL2_Data
|
|||||||
SDL_Cursor* MouseLastCursor;
|
SDL_Cursor* MouseLastCursor;
|
||||||
int MouseLastLeaveFrame;
|
int MouseLastLeaveFrame;
|
||||||
bool MouseCanUseGlobalState;
|
bool MouseCanUseGlobalState;
|
||||||
bool MouseCanUseCapture;
|
|
||||||
bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state.
|
bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state.
|
||||||
|
ImGui_ImplSDL2_MouseCaptureMode MouseCaptureMode;
|
||||||
|
|
||||||
// Gamepad handling
|
// Gamepad handling
|
||||||
ImVector<SDL_GameController*> Gamepads;
|
ImVector<SDL_GameController*> Gamepads;
|
||||||
@@ -201,7 +208,10 @@ static const char* ImGui_ImplSDL2_GetClipboardText(ImGuiContext*)
|
|||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||||
if (bd->ClipboardTextData)
|
if (bd->ClipboardTextData)
|
||||||
SDL_free(bd->ClipboardTextData);
|
SDL_free(bd->ClipboardTextData);
|
||||||
bd->ClipboardTextData = SDL_GetClipboardText();
|
if (SDL_HasClipboardText())
|
||||||
|
bd->ClipboardTextData = SDL_GetClipboardText();
|
||||||
|
else
|
||||||
|
bd->ClipboardTextData = nullptr;
|
||||||
return bd->ClipboardTextData;
|
return bd->ClipboardTextData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +227,7 @@ static void ImGui_ImplSDL2_PlatformSetImeData(ImGuiContext*, ImGuiViewport* view
|
|||||||
{
|
{
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
r.x = (int)(data->InputPos.x - viewport->Pos.x);
|
r.x = (int)(data->InputPos.x - viewport->Pos.x);
|
||||||
r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight);
|
r.y = (int)(data->InputPos.y - viewport->Pos.y);
|
||||||
r.w = 1;
|
r.w = 1;
|
||||||
r.h = (int)data->InputLineHeight;
|
r.h = (int)data->InputLineHeight;
|
||||||
SDL_SetTextInputRect(&r);
|
SDL_SetTextInputRect(&r);
|
||||||
@@ -542,11 +552,12 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void
|
|||||||
SDL_version ver_runtime;
|
SDL_version ver_runtime;
|
||||||
SDL_VERSION(&ver_compiled);
|
SDL_VERSION(&ver_compiled);
|
||||||
SDL_GetVersion(&ver_runtime);
|
SDL_GetVersion(&ver_runtime);
|
||||||
|
const char* sdl_video_driver = SDL_GetCurrentVideoDriver();
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
// Setup backend capabilities flags
|
||||||
ImGui_ImplSDL2_Data* bd = IM_NEW(ImGui_ImplSDL2_Data)();
|
ImGui_ImplSDL2_Data* bd = IM_NEW(ImGui_ImplSDL2_Data)();
|
||||||
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_sdl2 (%u.%u.%u, %u.%u.%u)",
|
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_sdl2 (%u.%u.%u, %u.%u.%u) (%s)",
|
||||||
ver_compiled.major, ver_compiled.minor, ver_compiled.patch, ver_runtime.major, ver_runtime.minor, ver_runtime.patch);
|
ver_compiled.major, ver_compiled.minor, ver_compiled.patch, ver_runtime.major, ver_runtime.minor, ver_runtime.patch, sdl_video_driver);
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
io.BackendPlatformUserData = (void*)bd;
|
||||||
io.BackendPlatformName = bd->BackendPlatformName;
|
io.BackendPlatformName = bd->BackendPlatformName;
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
@@ -556,6 +567,23 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void
|
|||||||
bd->Window = window;
|
bd->Window = window;
|
||||||
bd->WindowID = SDL_GetWindowID(window);
|
bd->WindowID = SDL_GetWindowID(window);
|
||||||
bd->Renderer = renderer;
|
bd->Renderer = renderer;
|
||||||
|
bd->IsWayland = strcmp(sdl_video_driver, "Wayland") == 0;
|
||||||
|
|
||||||
|
// Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse()
|
||||||
|
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
||||||
|
bd->MouseCanUseGlobalState = false;
|
||||||
|
bd->MouseCaptureMode = ImGui_ImplSDL2_MouseCaptureMode_Disabled;
|
||||||
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
|
const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
||||||
|
for (const char* item : capture_and_global_state_whitelist)
|
||||||
|
if (strncmp(sdl_video_driver, item, strlen(item)) == 0)
|
||||||
|
{
|
||||||
|
bd->MouseCanUseGlobalState = true;
|
||||||
|
bd->MouseCaptureMode = (strcmp(item, "x11") == 0) ? ImGui_ImplSDL2_MouseCaptureMode_EnabledAfterDrag : ImGui_ImplSDL2_MouseCaptureMode_Enabled;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (bd->MouseCanUseGlobalState)
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
|
||||||
|
|
||||||
// SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960)
|
// SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960)
|
||||||
// We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame.
|
// We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame.
|
||||||
@@ -565,20 +593,6 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void
|
|||||||
bd->MouseCanReportHoveredViewport = false;
|
bd->MouseCanReportHoveredViewport = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse()
|
|
||||||
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
|
||||||
bd->MouseCanUseGlobalState = false;
|
|
||||||
bd->MouseCanUseCapture = false;
|
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
|
||||||
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
|
||||||
const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
|
||||||
for (const char* item : capture_and_global_state_whitelist)
|
|
||||||
if (strncmp(sdl_backend, item, strlen(item)) == 0)
|
|
||||||
bd->MouseCanUseGlobalState = bd->MouseCanUseCapture = true;
|
|
||||||
#endif
|
|
||||||
if (bd->MouseCanUseGlobalState)
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
|
|
||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
|
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
|
||||||
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
|
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
|
||||||
@@ -668,7 +682,7 @@ bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
|
|||||||
if (!ImGui_ImplSDL2_Init(window, nullptr, nullptr))
|
if (!ImGui_ImplSDL2_Init(window, nullptr, nullptr))
|
||||||
return false;
|
return false;
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||||
bd->UseVulkan = true;
|
bd->IsVulkan = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -702,9 +716,9 @@ void ImGui_ImplSDL2_Shutdown()
|
|||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplSDL2_ShutdownMultiViewportSupport();
|
ImGui_ImplSDL2_ShutdownMultiViewportSupport();
|
||||||
|
|
||||||
if (bd->ClipboardTextData)
|
if (bd->ClipboardTextData)
|
||||||
SDL_free(bd->ClipboardTextData);
|
SDL_free(bd->ClipboardTextData);
|
||||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||||
@@ -714,10 +728,19 @@ void ImGui_ImplSDL2_Shutdown()
|
|||||||
io.BackendPlatformName = nullptr;
|
io.BackendPlatformName = nullptr;
|
||||||
io.BackendPlatformUserData = nullptr;
|
io.BackendPlatformUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This code is incredibly messy because some of the functions we need for full viewport support are not available in SDL < 2.0.4.
|
void ImGui_ImplSDL2_SetMouseCaptureMode(ImGui_ImplSDL2_MouseCaptureMode mode)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||||
|
if (mode == ImGui_ImplSDL2_MouseCaptureMode_Disabled && bd->MouseCaptureMode != ImGui_ImplSDL2_MouseCaptureMode_Disabled)
|
||||||
|
SDL_CaptureMouse(SDL_FALSE);
|
||||||
|
bd->MouseCaptureMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This code is rather messy because some of the functions we need for full viewport support are not available in SDL < 2.0.4.
|
||||||
static void ImGui_ImplSDL2_UpdateMouseData()
|
static void ImGui_ImplSDL2_UpdateMouseData()
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||||
@@ -726,8 +749,12 @@ static void ImGui_ImplSDL2_UpdateMouseData()
|
|||||||
// We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below)
|
// We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below)
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
|
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
|
||||||
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue we wait until mouse has moved to begin capture.
|
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue on X11 we we wait until mouse has moved to begin capture.
|
||||||
if (bd->MouseCanUseCapture)
|
if (bd->MouseCaptureMode == ImGui_ImplSDL2_MouseCaptureMode_Enabled)
|
||||||
|
{
|
||||||
|
SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE);
|
||||||
|
}
|
||||||
|
else if (bd->MouseCaptureMode == ImGui_ImplSDL2_MouseCaptureMode_EnabledAfterDrag)
|
||||||
{
|
{
|
||||||
bool want_capture = false;
|
bool want_capture = false;
|
||||||
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
|
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
|
||||||
@@ -756,13 +783,16 @@ static void ImGui_ImplSDL2_UpdateMouseData()
|
|||||||
SDL_WarpMouseInWindow(bd->Window, (int)io.MousePos.x, (int)io.MousePos.y);
|
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)
|
// (Optional) Fallback to provide unclamped mouse position when focused but not hovered (SDL_MOUSEMOTION already provides this when hovered or captured)
|
||||||
|
// Note that SDL_GetGlobalMouseState() is in theory slow on X11, but this only runs on rather specific cases. If a problem we may provide a way to opt-out this feature.
|
||||||
|
SDL_Window* hovered_window = SDL_GetMouseFocus();
|
||||||
const bool is_relative_mouse_mode = SDL_GetRelativeMouseMode() != 0;
|
const bool is_relative_mouse_mode = SDL_GetRelativeMouseMode() != 0;
|
||||||
if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0 && !is_relative_mouse_mode)
|
if (hovered_window == nullptr && bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0 && !is_relative_mouse_mode)
|
||||||
{
|
{
|
||||||
// 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)
|
// 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)
|
||||||
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
|
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
|
||||||
int mouse_x, mouse_y, window_x, window_y;
|
int mouse_x, mouse_y;
|
||||||
|
int window_x, window_y;
|
||||||
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
||||||
if (!(io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable))
|
if (!(io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable))
|
||||||
{
|
{
|
||||||
@@ -824,6 +854,7 @@ float ImGui_ImplSDL2_GetContentScaleForWindow(SDL_Window* window)
|
|||||||
return ImGui_ImplSDL2_GetContentScaleForDisplay(SDL_GetWindowDisplayIndex(window));
|
return ImGui_ImplSDL2_GetContentScaleForDisplay(SDL_GetWindowDisplayIndex(window));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SDL_GetDisplayDPI() seems rather unreliable on Linux.
|
||||||
float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_index)
|
float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_index)
|
||||||
{
|
{
|
||||||
const char* sdl_driver = SDL_GetCurrentVideoDriver();
|
const char* sdl_driver = SDL_GetCurrentVideoDriver();
|
||||||
@@ -833,7 +864,11 @@ float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_index)
|
|||||||
#if !defined(__APPLE__) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
|
#if !defined(__APPLE__) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
|
||||||
float dpi = 0.0f;
|
float dpi = 0.0f;
|
||||||
if (SDL_GetDisplayDPI(display_index, &dpi, nullptr, nullptr) == 0)
|
if (SDL_GetDisplayDPI(display_index, &dpi, nullptr, nullptr) == 0)
|
||||||
|
{
|
||||||
|
if (dpi < 96.0f)
|
||||||
|
dpi = 96.0f;
|
||||||
return dpi / 96.0f;
|
return dpi / 96.0f;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
IM_UNUSED(display_index);
|
IM_UNUSED(display_index);
|
||||||
@@ -992,7 +1027,7 @@ static void ImGui_ImplSDL2_GetWindowSizeAndFramebufferScale(SDL_Window* window,
|
|||||||
if (out_size != nullptr)
|
if (out_size != nullptr)
|
||||||
*out_size = ImVec2((float)w, (float)h);
|
*out_size = ImVec2((float)w, (float)h);
|
||||||
if (out_framebuffer_scale != nullptr)
|
if (out_framebuffer_scale != nullptr)
|
||||||
*out_framebuffer_scale = (w > 0 && h > 0) ? ImVec2((float)display_w / w, (float)display_h / h) : ImVec2(1.0f, 1.0f);
|
*out_framebuffer_scale = (w > 0 && h > 0) ? ImVec2((float)display_w / (float)w, (float)display_h / (float)h) : ImVec2(1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplSDL2_NewFrame()
|
void ImGui_ImplSDL2_NewFrame()
|
||||||
@@ -1017,7 +1052,7 @@ void ImGui_ImplSDL2_NewFrame()
|
|||||||
Uint64 current_time = SDL_GetPerformanceCounter();
|
Uint64 current_time = SDL_GetPerformanceCounter();
|
||||||
if (current_time <= bd->Time)
|
if (current_time <= bd->Time)
|
||||||
current_time = bd->Time + 1;
|
current_time = bd->Time + 1;
|
||||||
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / (double)frequency) : (float)(1.0f / 60.0f);
|
||||||
bd->Time = current_time;
|
bd->Time = current_time;
|
||||||
|
|
||||||
if (bd->MouseLastLeaveFrame && bd->MouseLastLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
if (bd->MouseLastLeaveFrame && bd->MouseLastLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
||||||
@@ -1079,7 +1114,7 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Uint32 sdl_flags = 0;
|
Uint32 sdl_flags = 0;
|
||||||
sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (bd->UseVulkan ? SDL_WINDOW_VULKAN : 0);
|
sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (bd->IsVulkan ? SDL_WINDOW_VULKAN : 0);
|
||||||
sdl_flags |= SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_ALLOW_HIGHDPI;
|
sdl_flags |= SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
sdl_flags |= SDL_WINDOW_HIDDEN;
|
sdl_flags |= SDL_WINDOW_HIDDEN;
|
||||||
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
|
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
|
// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
|
||||||
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
// [ ] Platform: Multi-viewport: Missing ImGuiBackendFlags_HasParentViewport support. The viewport->ParentViewportID field is ignored, and therefore io.ConfigViewportsNoDefaultParent has no effect either.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -51,4 +51,11 @@ IMGUI_IMPL_API float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_ind
|
|||||||
enum ImGui_ImplSDL2_GamepadMode { ImGui_ImplSDL2_GamepadMode_AutoFirst, ImGui_ImplSDL2_GamepadMode_AutoAll, ImGui_ImplSDL2_GamepadMode_Manual };
|
enum ImGui_ImplSDL2_GamepadMode { ImGui_ImplSDL2_GamepadMode_AutoFirst, ImGui_ImplSDL2_GamepadMode_AutoAll, ImGui_ImplSDL2_GamepadMode_Manual };
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
|
IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
|
||||||
|
|
||||||
|
// (Advanced, for X11 users) Override Mouse Capture mode. Mouse capture allows receiving updated mouse position after clicking inside our window and dragging outside it.
|
||||||
|
// Having this 'Enabled' is in theory always better. But, on X11 if you crash/break to debugger while capture is active you may temporarily lose access to your mouse.
|
||||||
|
// The best solution is to setup your debugger to automatically release capture, e.g. 'setxkbmap -option grab:break_actions && xdotool key XF86Ungrab' or via a GDB script. See #3650.
|
||||||
|
// But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL2_MouseCaptureMode_Disabled.
|
||||||
|
enum ImGui_ImplSDL2_MouseCaptureMode { ImGui_ImplSDL2_MouseCaptureMode_Enabled, ImGui_ImplSDL2_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL2_MouseCaptureMode_Disabled };
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL2_SetMouseCaptureMode(ImGui_ImplSDL2_MouseCaptureMode mode);
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -23,7 +23,15 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-03-25: [Docking] Use SDL_HAS_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED (SDL 3.4.0+) when available to avoid refreshing monitor work area every frame on Windows. (#8415)
|
||||||
|
// 2026-03-09: [Docking] Fixed an issue dated 2025/04/09 (1.92 WIP) where a refactor+merge caused ImGuiBackendFlags_HasMouseHoveredViewport to never be set, causing foreign windows to be ignored when deciding of hovered viewport. (#9284)
|
||||||
|
// 2026-02-13: Inputs: systems other than X11 are back to starting mouse capture on mouse down (reverts 2025-02-26 change). Only X11 requires waiting for a drag by default (not ideal, but a better default for X11 users). Added ImGui_ImplSDL3_SetMouseCaptureMode() for X11 debugger users. (#3650, #6410, #9235)
|
||||||
|
// 2026-01-15: Changed GetClipboardText() handler to return nullptr on error aka clipboard contents is not text. Consistent with other backends. (#9168)
|
||||||
|
// 2025-11-05: Fixed an issue with missing characters events when an already active text field changes viewports. (#9054)
|
||||||
|
// 2025-10-22: Fixed Platform_OpenInShellFn() return value (unused in core).
|
||||||
|
// 2025-09-24: Skip using the SDL_GetGlobalMouseState() state when one of our window is hovered, as the SDL_EVENT_MOUSE_MOTION data is reliable. Fix macOS notch mouse coordinates issue in fullscreen mode + better perf on X11. (#7919, #7786)
|
||||||
|
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
// 2025-09-15: Use SDL_GetWindowDisplayScale() on Mac to output DisplayFrameBufferScale. The function is more reliable during resolution changes e.g. going fullscreen. (#8703, #4414)
|
// 2025-09-15: Use SDL_GetWindowDisplayScale() on Mac to output DisplayFrameBufferScale. The function is more reliable during resolution changes e.g. going fullscreen. (#8703, #4414)
|
||||||
// 2025-06-27: IME: avoid calling SDL_StartTextInput() again if already active. (#8727)
|
// 2025-06-27: IME: avoid calling SDL_StartTextInput() again if already active. (#8727)
|
||||||
// 2025-05-15: [Docking] Add Platform_GetWindowFramebufferScale() handler, to allow varying Retina display density on multiple monitors.
|
// 2025-05-15: [Docking] Add Platform_GetWindowFramebufferScale() handler, to allow varying Retina display density on multiple monitors.
|
||||||
@@ -34,7 +42,7 @@
|
|||||||
// 2025-03-30: Update for SDL3 api changes: Revert SDL_GetClipboardText() memory ownership change. (#8530, #7801)
|
// 2025-03-30: Update for SDL3 api changes: Revert SDL_GetClipboardText() memory ownership change. (#8530, #7801)
|
||||||
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
|
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
|
||||||
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
||||||
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g.Linux debuggers not claiming capture back. (#6410, #3650)
|
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g. Linux debuggers not claiming capture back. (#6410, #3650)
|
||||||
// 2025-02-25: [Docking] Revert to use SDL_GetDisplayBounds() for WorkPos/WorkRect if SDL_GetDisplayUsableBounds() failed.
|
// 2025-02-25: [Docking] Revert to use SDL_GetDisplayBounds() for WorkPos/WorkRect if SDL_GetDisplayUsableBounds() failed.
|
||||||
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
|
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
|
||||||
// 2025-02-21: [Docking] Update monitors and work areas information every frame, as the later may change regardless of monitor changes. (#8415)
|
// 2025-02-21: [Docking] Update monitors and work areas information every frame, as the later may change regardless of monitor changes. (#8415)
|
||||||
@@ -98,6 +106,7 @@
|
|||||||
#else
|
#else
|
||||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
||||||
#endif
|
#endif
|
||||||
|
#define SDL_HAS_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED SDL_VERSION_ATLEAST(3,4,0)
|
||||||
|
|
||||||
// FIXME-LEGACY: remove when SDL 3.1.3 preview is released.
|
// FIXME-LEGACY: remove when SDL 3.1.3 preview is released.
|
||||||
#ifndef SDLK_APOSTROPHE
|
#ifndef SDLK_APOSTROPHE
|
||||||
@@ -115,12 +124,15 @@ struct ImGui_ImplSDL3_Data
|
|||||||
SDL_Renderer* Renderer;
|
SDL_Renderer* Renderer;
|
||||||
Uint64 Time;
|
Uint64 Time;
|
||||||
char* ClipboardTextData;
|
char* ClipboardTextData;
|
||||||
char BackendPlatformName[48];
|
char BackendPlatformName[64];
|
||||||
bool UseVulkan;
|
bool IsWayland;
|
||||||
|
bool IsVulkan;
|
||||||
bool WantUpdateMonitors;
|
bool WantUpdateMonitors;
|
||||||
|
|
||||||
// IME handling
|
// IME handling
|
||||||
SDL_Window* ImeWindow;
|
SDL_Window* ImeWindow;
|
||||||
|
ImGuiPlatformImeData ImeData;
|
||||||
|
bool ImeDirty;
|
||||||
|
|
||||||
// Mouse handling
|
// Mouse handling
|
||||||
Uint32 MouseWindowID;
|
Uint32 MouseWindowID;
|
||||||
@@ -129,8 +141,8 @@ struct ImGui_ImplSDL3_Data
|
|||||||
SDL_Cursor* MouseLastCursor;
|
SDL_Cursor* MouseLastCursor;
|
||||||
int MousePendingLeaveFrame;
|
int MousePendingLeaveFrame;
|
||||||
bool MouseCanUseGlobalState;
|
bool MouseCanUseGlobalState;
|
||||||
bool MouseCanUseCapture;
|
|
||||||
bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state.
|
bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state.
|
||||||
|
ImGui_ImplSDL3_MouseCaptureMode MouseCaptureMode;
|
||||||
|
|
||||||
// Gamepad handling
|
// Gamepad handling
|
||||||
ImVector<SDL_Gamepad*> Gamepads;
|
ImVector<SDL_Gamepad*> Gamepads;
|
||||||
@@ -150,6 +162,7 @@ static ImGui_ImplSDL3_Data* ImGui_ImplSDL3_GetBackendData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
|
static void ImGui_ImplSDL3_UpdateIme();
|
||||||
static void ImGui_ImplSDL3_UpdateMonitors();
|
static void ImGui_ImplSDL3_UpdateMonitors();
|
||||||
static void ImGui_ImplSDL3_InitMultiViewportSupport(SDL_Window* window, void* sdl_gl_context);
|
static void ImGui_ImplSDL3_InitMultiViewportSupport(SDL_Window* window, void* sdl_gl_context);
|
||||||
static void ImGui_ImplSDL3_ShutdownMultiViewportSupport();
|
static void ImGui_ImplSDL3_ShutdownMultiViewportSupport();
|
||||||
@@ -160,7 +173,10 @@ static const char* ImGui_ImplSDL3_GetClipboardText(ImGuiContext*)
|
|||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
if (bd->ClipboardTextData)
|
if (bd->ClipboardTextData)
|
||||||
SDL_free(bd->ClipboardTextData);
|
SDL_free(bd->ClipboardTextData);
|
||||||
bd->ClipboardTextData = SDL_GetClipboardText();
|
if (SDL_HasClipboardText())
|
||||||
|
bd->ClipboardTextData = SDL_GetClipboardText();
|
||||||
|
else
|
||||||
|
bd->ClipboardTextData = nullptr;
|
||||||
return bd->ClipboardTextData;
|
return bd->ClipboardTextData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,21 +185,45 @@ static void ImGui_ImplSDL3_SetClipboardText(ImGuiContext*, const char* text)
|
|||||||
SDL_SetClipboardText(text);
|
SDL_SetClipboardText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_PlatformSetImeData(ImGuiContext*, ImGuiViewport* viewport, ImGuiPlatformImeData* data)
|
static ImGuiViewport* ImGui_ImplSDL3_GetViewportForWindowID(SDL_WindowID window_id)
|
||||||
|
{
|
||||||
|
return ImGui::FindViewportByPlatformHandle((void*)(intptr_t)window_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_PlatformSetImeData(ImGuiContext*, ImGuiViewport*, ImGuiPlatformImeData* data)
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
SDL_WindowID window_id = (SDL_WindowID)(intptr_t)viewport->PlatformHandle;
|
bd->ImeData = *data;
|
||||||
SDL_Window* window = SDL_GetWindowFromID(window_id);
|
bd->ImeDirty = true;
|
||||||
|
ImGui_ImplSDL3_UpdateIme();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We discard viewport passed via ImGuiPlatformImeData and always call SDL_StartTextInput() on SDL_GetKeyboardFocus().
|
||||||
|
static void ImGui_ImplSDL3_UpdateIme()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
ImGuiPlatformImeData* data = &bd->ImeData;
|
||||||
|
SDL_Window* window = SDL_GetKeyboardFocus();
|
||||||
|
|
||||||
|
// Stop previous input
|
||||||
if ((!(data->WantVisible || data->WantTextInput) || bd->ImeWindow != window) && bd->ImeWindow != nullptr)
|
if ((!(data->WantVisible || data->WantTextInput) || bd->ImeWindow != window) && bd->ImeWindow != nullptr)
|
||||||
{
|
{
|
||||||
SDL_StopTextInput(bd->ImeWindow);
|
SDL_StopTextInput(bd->ImeWindow);
|
||||||
bd->ImeWindow = nullptr;
|
bd->ImeWindow = nullptr;
|
||||||
}
|
}
|
||||||
|
if ((!bd->ImeDirty && bd->ImeWindow == window) || (window == nullptr))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Start/update current input
|
||||||
|
bd->ImeDirty = false;
|
||||||
if (data->WantVisible)
|
if (data->WantVisible)
|
||||||
{
|
{
|
||||||
|
ImVec2 viewport_pos;
|
||||||
|
if (ImGuiViewport* viewport = ImGui_ImplSDL3_GetViewportForWindowID(SDL_GetWindowID(window)))
|
||||||
|
viewport_pos = viewport->Pos;
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
r.x = (int)(data->InputPos.x - viewport->Pos.x);
|
r.x = (int)(data->InputPos.x - viewport_pos.x);
|
||||||
r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight);
|
r.y = (int)(data->InputPos.y - viewport_pos.y);
|
||||||
r.w = 1;
|
r.w = 1;
|
||||||
r.h = (int)data->InputLineHeight;
|
r.h = (int)data->InputLineHeight;
|
||||||
SDL_SetTextInputArea(window, &r, 0);
|
SDL_SetTextInputArea(window, &r, 0);
|
||||||
@@ -355,11 +395,6 @@ static void ImGui_ImplSDL3_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
|
|||||||
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0);
|
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImGuiViewport* ImGui_ImplSDL3_GetViewportForWindowID(SDL_WindowID window_id)
|
|
||||||
{
|
|
||||||
return ImGui::FindViewportByPlatformHandle((void*)(intptr_t)window_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// 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.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.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
@@ -443,6 +478,9 @@ bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
|
|||||||
case SDL_EVENT_DISPLAY_REMOVED:
|
case SDL_EVENT_DISPLAY_REMOVED:
|
||||||
case SDL_EVENT_DISPLAY_MOVED:
|
case SDL_EVENT_DISPLAY_MOVED:
|
||||||
case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED:
|
case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED:
|
||||||
|
#if SDL_HAS_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED
|
||||||
|
case SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED:
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
bd->WantUpdateMonitors = true;
|
bd->WantUpdateMonitors = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -523,20 +561,43 @@ static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void
|
|||||||
//SDL_SetHint(SDL_HINT_EVENT_LOGGING, "2");
|
//SDL_SetHint(SDL_HINT_EVENT_LOGGING, "2");
|
||||||
|
|
||||||
const int ver_linked = SDL_GetVersion();
|
const int ver_linked = SDL_GetVersion();
|
||||||
|
const char* sdl_video_driver = SDL_GetCurrentVideoDriver();
|
||||||
|
|
||||||
// Setup backend capabilities flags
|
// Setup backend capabilities flags
|
||||||
ImGui_ImplSDL3_Data* bd = IM_NEW(ImGui_ImplSDL3_Data)();
|
ImGui_ImplSDL3_Data* bd = IM_NEW(ImGui_ImplSDL3_Data)();
|
||||||
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_sdl3 (%d.%d.%d; %d.%d.%d)",
|
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_sdl3 (%d.%d.%d; %d.%d.%d) (%s)",
|
||||||
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION, SDL_VERSIONNUM_MAJOR(ver_linked), SDL_VERSIONNUM_MINOR(ver_linked), SDL_VERSIONNUM_MICRO(ver_linked));
|
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION, SDL_VERSIONNUM_MAJOR(ver_linked), SDL_VERSIONNUM_MINOR(ver_linked), SDL_VERSIONNUM_MICRO(ver_linked),
|
||||||
|
sdl_video_driver);
|
||||||
io.BackendPlatformUserData = (void*)bd;
|
io.BackendPlatformUserData = (void*)bd;
|
||||||
io.BackendPlatformName = bd->BackendPlatformName;
|
io.BackendPlatformName = bd->BackendPlatformName;
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||||
// (ImGuiBackendFlags_PlatformHasViewports may be set just below)
|
// (ImGuiBackendFlags_PlatformHasViewports and ImGuiBackendFlags_HasParentViewport may be set just below)
|
||||||
|
// (ImGuiBackendFlags_HasMouseHoveredViewport is set dynamically in our _NewFrame function)
|
||||||
|
|
||||||
bd->Window = window;
|
bd->Window = window;
|
||||||
bd->WindowID = SDL_GetWindowID(window);
|
bd->WindowID = SDL_GetWindowID(window);
|
||||||
bd->Renderer = renderer;
|
bd->Renderer = renderer;
|
||||||
|
bd->IsWayland = strcmp(sdl_video_driver, "wayland") == 0;
|
||||||
|
|
||||||
|
// Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse()
|
||||||
|
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
||||||
|
bd->MouseCanUseGlobalState = false;
|
||||||
|
bd->MouseCaptureMode = ImGui_ImplSDL3_MouseCaptureMode_Disabled;
|
||||||
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
|
const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
||||||
|
for (const char* item : capture_and_global_state_whitelist)
|
||||||
|
if (strncmp(sdl_video_driver, item, strlen(item)) == 0)
|
||||||
|
{
|
||||||
|
bd->MouseCanUseGlobalState = true;
|
||||||
|
bd->MouseCaptureMode = (strcmp(item, "x11") == 0) ? ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag : ImGui_ImplSDL3_MouseCaptureMode_Enabled;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (bd->MouseCanUseGlobalState)
|
||||||
|
{
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasParentViewport; // We can honor viewport->ParentViewportId by applying the corresponding parent/child relationship at platform level (optional)
|
||||||
|
}
|
||||||
|
|
||||||
// SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960)
|
// SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960)
|
||||||
// We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame.
|
// We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame.
|
||||||
@@ -546,25 +607,11 @@ static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void
|
|||||||
bd->MouseCanReportHoveredViewport = false;
|
bd->MouseCanReportHoveredViewport = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse()
|
|
||||||
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
|
||||||
bd->MouseCanUseGlobalState = false;
|
|
||||||
bd->MouseCanUseCapture = false;
|
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
|
||||||
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
|
||||||
const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
|
||||||
for (const char* item : capture_and_global_state_whitelist)
|
|
||||||
if (strncmp(sdl_backend, item, strlen(item)) == 0)
|
|
||||||
bd->MouseCanUseGlobalState = bd->MouseCanUseCapture = true;
|
|
||||||
#endif
|
|
||||||
if (bd->MouseCanUseGlobalState)
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
|
|
||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL3_SetClipboardText;
|
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL3_SetClipboardText;
|
||||||
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL3_GetClipboardText;
|
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL3_GetClipboardText;
|
||||||
platform_io.Platform_SetImeDataFn = ImGui_ImplSDL3_PlatformSetImeData;
|
platform_io.Platform_SetImeDataFn = ImGui_ImplSDL3_PlatformSetImeData;
|
||||||
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { return SDL_OpenURL(url) == 0; };
|
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { return SDL_OpenURL(url); };
|
||||||
|
|
||||||
// Update monitor a first time during init
|
// Update monitor a first time during init
|
||||||
ImGui_ImplSDL3_UpdateMonitors();
|
ImGui_ImplSDL3_UpdateMonitors();
|
||||||
@@ -623,7 +670,7 @@ bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window)
|
|||||||
if (!ImGui_ImplSDL3_Init(window, nullptr, nullptr))
|
if (!ImGui_ImplSDL3_Init(window, nullptr, nullptr))
|
||||||
return false;
|
return false;
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
bd->UseVulkan = true;
|
bd->IsVulkan = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,9 +709,9 @@ void ImGui_ImplSDL3_Shutdown()
|
|||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplSDL3_ShutdownMultiViewportSupport();
|
ImGui_ImplSDL3_ShutdownMultiViewportSupport();
|
||||||
|
|
||||||
if (bd->ClipboardTextData)
|
if (bd->ClipboardTextData)
|
||||||
SDL_free(bd->ClipboardTextData);
|
SDL_free(bd->ClipboardTextData);
|
||||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||||
@@ -673,11 +720,19 @@ void ImGui_ImplSDL3_Shutdown()
|
|||||||
|
|
||||||
io.BackendPlatformName = nullptr;
|
io.BackendPlatformName = nullptr;
|
||||||
io.BackendPlatformUserData = nullptr;
|
io.BackendPlatformUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport | ImGuiBackendFlags_HasParentViewport);
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This code is incredibly messy because some of the functions we need for full viewport support are not available in SDL < 2.0.4.
|
void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
if (mode == ImGui_ImplSDL3_MouseCaptureMode_Disabled && bd->MouseCaptureMode != ImGui_ImplSDL3_MouseCaptureMode_Disabled)
|
||||||
|
SDL_CaptureMouse(false);
|
||||||
|
bd->MouseCaptureMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL3_UpdateMouseData()
|
static void ImGui_ImplSDL3_UpdateMouseData()
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
@@ -686,8 +741,12 @@ static void ImGui_ImplSDL3_UpdateMouseData()
|
|||||||
// We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below)
|
// We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below)
|
||||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
|
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
|
||||||
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue we wait until mouse has moved to begin capture.
|
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue on X11 we we wait until mouse has moved to begin capture.
|
||||||
if (bd->MouseCanUseCapture)
|
if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_Enabled)
|
||||||
|
{
|
||||||
|
SDL_CaptureMouse(bd->MouseButtonsDown != 0);
|
||||||
|
}
|
||||||
|
else if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag)
|
||||||
{
|
{
|
||||||
bool want_capture = false;
|
bool want_capture = false;
|
||||||
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
|
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
|
||||||
@@ -715,9 +774,11 @@ static void ImGui_ImplSDL3_UpdateMouseData()
|
|||||||
SDL_WarpMouseInWindow(bd->Window, io.MousePos.x, io.MousePos.y);
|
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)
|
// (Optional) Fallback to provide unclamped mouse position when focused but not hovered (SDL_EVENT_MOUSE_MOTION already provides this when hovered or captured)
|
||||||
|
// Note that SDL_GetGlobalMouseState() is in theory slow on X11, but this only runs on rather specific cases. If a problem we may provide a way to opt-out this feature.
|
||||||
|
SDL_Window* hovered_window = SDL_GetMouseFocus();
|
||||||
const bool is_relative_mouse_mode = SDL_GetWindowRelativeMouseMode(bd->Window);
|
const bool is_relative_mouse_mode = SDL_GetWindowRelativeMouseMode(bd->Window);
|
||||||
if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0 && !is_relative_mouse_mode)
|
if (hovered_window == nullptr && bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0 && !is_relative_mouse_mode)
|
||||||
{
|
{
|
||||||
// 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)
|
// 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)
|
||||||
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
|
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
|
||||||
@@ -727,10 +788,10 @@ static void ImGui_ImplSDL3_UpdateMouseData()
|
|||||||
if (!(io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable))
|
if (!(io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable))
|
||||||
{
|
{
|
||||||
SDL_GetWindowPosition(focused_window, &window_x, &window_y);
|
SDL_GetWindowPosition(focused_window, &window_x, &window_y);
|
||||||
mouse_x -= window_x;
|
mouse_x -= (float)window_x;
|
||||||
mouse_y -= window_y;
|
mouse_y -= (float)window_y;
|
||||||
}
|
}
|
||||||
io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
|
io.AddMousePosEvent(mouse_x, mouse_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -924,8 +985,8 @@ static void ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(SDL_Window* window,
|
|||||||
#else
|
#else
|
||||||
int display_w, display_h;
|
int display_w, display_h;
|
||||||
SDL_GetWindowSizeInPixels(window, &display_w, &display_h);
|
SDL_GetWindowSizeInPixels(window, &display_w, &display_h);
|
||||||
float fb_scale_x = (w > 0) ? (float)display_w / w : 1.0f;
|
float fb_scale_x = (w > 0) ? (float)display_w / (float)w : 1.0f;
|
||||||
float fb_scale_y = (h > 0) ? (float)display_h / h : 1.0f;
|
float fb_scale_y = (h > 0) ? (float)display_h / (float)h : 1.0f;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (out_size != nullptr)
|
if (out_size != nullptr)
|
||||||
@@ -944,7 +1005,7 @@ void ImGui_ImplSDL3_NewFrame()
|
|||||||
ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(bd->Window, &io.DisplaySize, &io.DisplayFramebufferScale);
|
ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(bd->Window, &io.DisplaySize, &io.DisplayFramebufferScale);
|
||||||
|
|
||||||
// Update monitors
|
// Update monitors
|
||||||
#ifdef WIN32
|
#if defined(WIN32) && !SDL_HAS_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED
|
||||||
bd->WantUpdateMonitors = true; // Keep polling under Windows to handle changes of work area when resizing task-bar (#8415)
|
bd->WantUpdateMonitors = true; // Keep polling under Windows to handle changes of work area when resizing task-bar (#8415)
|
||||||
#endif
|
#endif
|
||||||
if (bd->WantUpdateMonitors)
|
if (bd->WantUpdateMonitors)
|
||||||
@@ -956,7 +1017,7 @@ void ImGui_ImplSDL3_NewFrame()
|
|||||||
Uint64 current_time = SDL_GetPerformanceCounter();
|
Uint64 current_time = SDL_GetPerformanceCounter();
|
||||||
if (current_time <= bd->Time)
|
if (current_time <= bd->Time)
|
||||||
current_time = bd->Time + 1;
|
current_time = bd->Time + 1;
|
||||||
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / (double)frequency) : (float)(1.0f / 60.0f);
|
||||||
bd->Time = current_time;
|
bd->Time = current_time;
|
||||||
|
|
||||||
if (bd->MousePendingLeaveFrame && bd->MousePendingLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
if (bd->MousePendingLeaveFrame && bd->MousePendingLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
||||||
@@ -975,6 +1036,7 @@ void ImGui_ImplSDL3_NewFrame()
|
|||||||
|
|
||||||
ImGui_ImplSDL3_UpdateMouseData();
|
ImGui_ImplSDL3_UpdateMouseData();
|
||||||
ImGui_ImplSDL3_UpdateMouseCursor();
|
ImGui_ImplSDL3_UpdateMouseCursor();
|
||||||
|
ImGui_ImplSDL3_UpdateIme();
|
||||||
|
|
||||||
// Update game controllers (if enabled and available)
|
// Update game controllers (if enabled and available)
|
||||||
ImGui_ImplSDL3_UpdateGamepads();
|
ImGui_ImplSDL3_UpdateGamepads();
|
||||||
@@ -999,14 +1061,13 @@ struct ImGui_ImplSDL3_ViewportData
|
|||||||
~ImGui_ImplSDL3_ViewportData() { IM_ASSERT(Window == nullptr && GLContext == nullptr); }
|
~ImGui_ImplSDL3_ViewportData() { IM_ASSERT(Window == nullptr && GLContext == nullptr); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static SDL_Window* ImGui_ImplSDL3_GetSDLWindowFromViewportID(ImGuiID viewport_id)
|
static SDL_Window* ImGui_ImplSDL3_GetSDLWindowFromViewport(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
if (viewport_id != 0)
|
if (viewport != nullptr)
|
||||||
if (ImGuiViewport* viewport = ImGui::FindViewportByID(viewport_id))
|
{
|
||||||
{
|
SDL_WindowID window_id = (SDL_WindowID)(intptr_t)viewport->PlatformHandle;
|
||||||
SDL_WindowID window_id = (SDL_WindowID)(intptr_t)viewport->PlatformHandle;
|
return SDL_GetWindowFromID(window_id);
|
||||||
return SDL_GetWindowFromID(window_id);
|
}
|
||||||
}
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1016,7 +1077,7 @@ static void ImGui_ImplSDL3_CreateWindow(ImGuiViewport* viewport)
|
|||||||
ImGui_ImplSDL3_ViewportData* vd = IM_NEW(ImGui_ImplSDL3_ViewportData)();
|
ImGui_ImplSDL3_ViewportData* vd = IM_NEW(ImGui_ImplSDL3_ViewportData)();
|
||||||
viewport->PlatformUserData = vd;
|
viewport->PlatformUserData = vd;
|
||||||
|
|
||||||
vd->ParentWindow = ImGui_ImplSDL3_GetSDLWindowFromViewportID(viewport->ParentViewportId);
|
vd->ParentWindow = ImGui_ImplSDL3_GetSDLWindowFromViewport(viewport->ParentViewport);
|
||||||
|
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
ImGui_ImplSDL3_ViewportData* main_viewport_data = (ImGui_ImplSDL3_ViewportData*)main_viewport->PlatformUserData;
|
ImGui_ImplSDL3_ViewportData* main_viewport_data = (ImGui_ImplSDL3_ViewportData*)main_viewport->PlatformUserData;
|
||||||
@@ -1033,7 +1094,7 @@ static void ImGui_ImplSDL3_CreateWindow(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
SDL_WindowFlags sdl_flags = 0;
|
SDL_WindowFlags sdl_flags = 0;
|
||||||
sdl_flags |= SDL_WINDOW_HIDDEN;
|
sdl_flags |= SDL_WINDOW_HIDDEN;
|
||||||
sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (bd->UseVulkan ? SDL_WINDOW_VULKAN : 0);
|
sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (bd->IsVulkan ? SDL_WINDOW_VULKAN : 0);
|
||||||
sdl_flags |= SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
sdl_flags |= SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
||||||
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
|
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
|
||||||
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE;
|
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE;
|
||||||
@@ -1105,7 +1166,7 @@ static void ImGui_ImplSDL3_UpdateWindow(ImGuiViewport* viewport)
|
|||||||
#ifndef __APPLE__ // On Mac, SDL3 Parenting appears to prevent viewport from appearing in another monitor
|
#ifndef __APPLE__ // On Mac, SDL3 Parenting appears to prevent viewport from appearing in another monitor
|
||||||
// Update SDL3 parent if it changed _after_ creation.
|
// Update SDL3 parent if it changed _after_ creation.
|
||||||
// This is for advanced apps that are manipulating ParentViewportID manually.
|
// This is for advanced apps that are manipulating ParentViewportID manually.
|
||||||
SDL_Window* new_parent = ImGui_ImplSDL3_GetSDLWindowFromViewportID(viewport->ParentViewportId);
|
SDL_Window* new_parent = ImGui_ImplSDL3_GetSDLWindowFromViewport(viewport->ParentViewport);
|
||||||
if (new_parent != vd->ParentWindow)
|
if (new_parent != vd->ParentWindow)
|
||||||
{
|
{
|
||||||
vd->ParentWindow = new_parent;
|
vd->ParentWindow = new_parent;
|
||||||
|
|||||||
@@ -47,4 +47,11 @@ IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event);
|
|||||||
enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual };
|
enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual };
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
|
IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
|
||||||
|
|
||||||
|
// (Advanced, for X11 users) Override Mouse Capture mode. Mouse capture allows receiving updated mouse position after clicking inside our window and dragging outside it.
|
||||||
|
// Having this 'Enabled' is in theory always better. But, on X11 if you crash/break to debugger while capture is active you may temporarily lose access to your mouse.
|
||||||
|
// The best solution is to setup your debugger to automatically release capture, e.g. 'setxkbmap -option grab:break_actions && xdotool key XF86Ungrab' or via a GDB script. See #3650.
|
||||||
|
// But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL3_MouseCaptureMode_Disabled.
|
||||||
|
enum ImGui_ImplSDL3_MouseCaptureMode { ImGui_ImplSDL3_MouseCaptureMode_Enabled, ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL3_MouseCaptureMode_Disabled };
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode);
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -23,7 +23,12 @@
|
|||||||
// Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
|
// Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
|
||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. Obsoleting samplers from ImGui_ImplSDLGPU3_RenderState. (#9378)
|
||||||
|
// 2026-03-19: Fixed issue in ImGui_ImplSDLGPU3_DestroyTexture() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295, #9310)
|
||||||
|
// 2026-02-25: Removed unnecessary call to SDL_WaitForGPUIdle when releasing vertex/index buffers. (#9262)
|
||||||
|
// 2025-11-26: macOS version can use MSL shaders in order to support macOS 10.14+ (vs Metallib shaders requiring macOS 14+). Requires calling SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL.
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-08-20: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and ImGui_ImplSDLGPU3_InitInfo::PresentMode to configure how secondary viewports are created.
|
// 2025-08-20: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and ImGui_ImplSDLGPU3_InitInfo::PresentMode to configure how secondary viewports are created.
|
||||||
// 2025-08-08: *BREAKING* Changed ImTextureID type from SDL_GPUTextureSamplerBinding* to SDL_GPUTexture*, which is more natural and easier for user to manage. If you need to change the current sampler, you can access the ImGui_ImplSDLGPU3_RenderState struct. (#8866, #8163, #7998, #7988)
|
// 2025-08-08: *BREAKING* Changed ImTextureID type from SDL_GPUTextureSamplerBinding* to SDL_GPUTexture*, which is more natural and easier for user to manage. If you need to change the current sampler, you can access the ImGui_ImplSDLGPU3_RenderState struct. (#8866, #8163, #7998, #7988)
|
||||||
// 2025-08-08: Expose SamplerDefault and SamplerCurrent in ImGui_ImplSDLGPU3_RenderState. Allow callback to change sampler.
|
// 2025-08-08: Expose SamplerDefault and SamplerCurrent in ImGui_ImplSDLGPU3_RenderState. Allow callback to change sampler.
|
||||||
@@ -57,11 +62,16 @@ struct ImGui_ImplSDLGPU3_Data
|
|||||||
{
|
{
|
||||||
ImGui_ImplSDLGPU3_InitInfo InitInfo;
|
ImGui_ImplSDLGPU3_InitInfo InitInfo;
|
||||||
|
|
||||||
|
// Render state
|
||||||
|
ImGui_ImplSDLGPU3_RenderState* RenderState = nullptr; // == ImGui::GetPlatformIO().Renderer_RenderState during rendering.
|
||||||
|
SDL_GPUSampler* CurrentSampler = nullptr;
|
||||||
|
|
||||||
// Graphics pipeline & shaders
|
// Graphics pipeline & shaders
|
||||||
SDL_GPUShader* VertexShader = nullptr;
|
SDL_GPUShader* VertexShader = nullptr;
|
||||||
SDL_GPUShader* FragmentShader = nullptr;
|
SDL_GPUShader* FragmentShader = nullptr;
|
||||||
SDL_GPUGraphicsPipeline* Pipeline = nullptr;
|
SDL_GPUGraphicsPipeline* Pipeline = nullptr;
|
||||||
SDL_GPUSampler* TexSamplerLinear = nullptr;
|
SDL_GPUSampler* TexSamplerLinear = nullptr;
|
||||||
|
SDL_GPUSampler* TexSamplerNearest = nullptr;
|
||||||
SDL_GPUTransferBuffer* TexTransferBuffer = nullptr;
|
SDL_GPUTransferBuffer* TexTransferBuffer = nullptr;
|
||||||
uint32_t TexTransferBufferSize = 0;
|
uint32_t TexTransferBufferSize = 0;
|
||||||
|
|
||||||
@@ -84,10 +94,10 @@ static ImGui_ImplSDLGPU3_Data* ImGui_ImplSDLGPU3_GetBackendData()
|
|||||||
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLGPU3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLGPU3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, ImGui_ImplSDLGPU3_RenderState* render_state, SDL_GPUGraphicsPipeline* pipeline, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, ImGui_ImplSDLGPU3_FrameData* fd, uint32_t fb_width, uint32_t fb_height)
|
static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, SDL_GPUGraphicsPipeline* pipeline, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, ImGui_ImplSDLGPU3_FrameData* fd, uint32_t fb_width, uint32_t fb_height)
|
||||||
{
|
{
|
||||||
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
render_state->SamplerCurrent = bd->TexSamplerLinear;
|
bd->CurrentSampler = bd->TexSamplerLinear;
|
||||||
|
|
||||||
// Bind graphics pipeline
|
// Bind graphics pipeline
|
||||||
SDL_BindGPUGraphicsPipeline(render_pass, pipeline);
|
SDL_BindGPUGraphicsPipeline(render_pass, pipeline);
|
||||||
@@ -130,8 +140,7 @@ static void CreateOrResizeBuffers(SDL_GPUBuffer** buffer, SDL_GPUTransferBuffer*
|
|||||||
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
|
||||||
// FIXME-OPT: Not optimal, but this is fairly rarely called.
|
// There is no need for calling SDL_WaitForGPUIdle here, as SDL3 will handle deferred buffer deletion automatically.
|
||||||
SDL_WaitForGPUIdle(v->Device);
|
|
||||||
SDL_ReleaseGPUBuffer(v->Device, *buffer);
|
SDL_ReleaseGPUBuffer(v->Device, *buffer);
|
||||||
SDL_ReleaseGPUTransferBuffer(v->Device, *transferbuffer);
|
SDL_ReleaseGPUTransferBuffer(v->Device, *transferbuffer);
|
||||||
|
|
||||||
@@ -172,8 +181,8 @@ void ImGui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuff
|
|||||||
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
|
ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
|
||||||
|
|
||||||
uint32_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
|
uint32_t vertex_size = (uint32_t)draw_data->TotalVtxCount * sizeof(ImDrawVert);
|
||||||
uint32_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);
|
uint32_t index_size = (uint32_t)draw_data->TotalIdxCount * sizeof(ImDrawIdx);
|
||||||
if (fd->VertexBuffer == nullptr || fd->VertexBufferSize < vertex_size)
|
if (fd->VertexBuffer == nullptr || fd->VertexBufferSize < vertex_size)
|
||||||
CreateOrResizeBuffers(&fd->VertexBuffer, &fd->VertexTransferBuffer, &fd->VertexBufferSize, vertex_size, SDL_GPU_BUFFERUSAGE_VERTEX);
|
CreateOrResizeBuffers(&fd->VertexBuffer, &fd->VertexTransferBuffer, &fd->VertexBufferSize, vertex_size, SDL_GPU_BUFFERUSAGE_VERTEX);
|
||||||
if (fd->IndexBuffer == nullptr || fd->IndexBufferSize < index_size)
|
if (fd->IndexBuffer == nullptr || fd->IndexBufferSize < index_size)
|
||||||
@@ -214,6 +223,11 @@ void ImGui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuff
|
|||||||
SDL_EndGPUCopyPass(copy_pass);
|
SDL_EndGPUCopyPass(copy_pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplSDLGPU3_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); bd->CurrentSampler = bd->TexSamplerLinear; }
|
||||||
|
static void ImGui_ImplSDLGPU3_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); bd->CurrentSampler = bd->TexSamplerNearest; }
|
||||||
|
|
||||||
void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline)
|
void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline)
|
||||||
{
|
{
|
||||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||||
@@ -236,10 +250,9 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
ImGui_ImplSDLGPU3_RenderState render_state;
|
ImGui_ImplSDLGPU3_RenderState render_state;
|
||||||
render_state.Device = bd->InitInfo.Device;
|
render_state.Device = bd->InitInfo.Device;
|
||||||
render_state.SamplerDefault = render_state.SamplerCurrent = bd->TexSamplerLinear;
|
platform_io.Renderer_RenderState = bd->RenderState = &render_state;
|
||||||
platform_io.Renderer_RenderState = &render_state;
|
|
||||||
|
|
||||||
ImGui_ImplSDLGPU3_SetupRenderState(draw_data, &render_state, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
||||||
|
|
||||||
// Render command lists
|
// Render command lists
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
||||||
@@ -253,9 +266,8 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|||||||
if (pcmd->UserCallback != nullptr)
|
if (pcmd->UserCallback != nullptr)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
||||||
ImGui_ImplSDLGPU3_SetupRenderState(draw_data, &render_state, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
}
|
}
|
||||||
@@ -268,8 +280,8 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|||||||
// Clamp to viewport as SDL_SetGPUScissor() won't accept values that are off bounds
|
// Clamp to viewport as SDL_SetGPUScissor() won't accept values that are off bounds
|
||||||
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
||||||
if (clip_min.y < 0.0f) { clip_min.y = 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.x > (float)fb_width) { clip_max.x = (float)fb_width; }
|
||||||
if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; }
|
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)
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -284,7 +296,7 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|||||||
// Bind DescriptorSet with font or user texture
|
// Bind DescriptorSet with font or user texture
|
||||||
SDL_GPUTextureSamplerBinding texture_sampler_binding;
|
SDL_GPUTextureSamplerBinding texture_sampler_binding;
|
||||||
texture_sampler_binding.texture = (SDL_GPUTexture*)(intptr_t)pcmd->GetTexID();
|
texture_sampler_binding.texture = (SDL_GPUTexture*)(intptr_t)pcmd->GetTexID();
|
||||||
texture_sampler_binding.sampler = render_state.SamplerCurrent;
|
texture_sampler_binding.sampler = bd->CurrentSampler;
|
||||||
SDL_BindGPUFragmentSamplers(render_pass, 0, &texture_sampler_binding, 1);
|
SDL_BindGPUFragmentSamplers(render_pass, 0, &texture_sampler_binding, 1);
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@@ -303,14 +315,16 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|||||||
// We perform a call to SDL_SetGPUScissor() to set back a full viewport which is likely to fix things for 99% users but technically this is not perfect. (See github #4644)
|
// We perform a call to SDL_SetGPUScissor() to set back a full viewport which is likely to fix things for 99% users but technically this is not perfect. (See github #4644)
|
||||||
SDL_Rect scissor_rect { 0, 0, fb_width, fb_height };
|
SDL_Rect scissor_rect { 0, 0, fb_width, fb_height };
|
||||||
SDL_SetGPUScissor(render_pass, &scissor_rect);
|
SDL_SetGPUScissor(render_pass, &scissor_rect);
|
||||||
|
|
||||||
|
platform_io.Renderer_RenderState = bd->RenderState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDLGPU3_DestroyTexture(ImTextureData* tex)
|
static void ImGui_ImplSDLGPU3_DestroyTexture(ImTextureData* tex)
|
||||||
{
|
{
|
||||||
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID();
|
if (tex->GetTexID() != ImTextureID_Invalid)
|
||||||
if (raw_tex != nullptr)
|
if (SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID())
|
||||||
SDL_ReleaseGPUTexture(bd->InitInfo.Device, raw_tex);
|
SDL_ReleaseGPUTexture(bd->InitInfo.Device, raw_tex);
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
@@ -454,14 +468,31 @@ static void ImGui_ImplSDLGPU3_CreateShaders()
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vertex_shader_info.entrypoint = "main0";
|
SDL_GPUShaderFormat supported_formats = SDL_GetGPUShaderFormats(v->Device);
|
||||||
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
if (supported_formats & SDL_GPU_SHADERFORMAT_METALLIB)
|
||||||
vertex_shader_info.code = metallib_vertex;
|
{
|
||||||
vertex_shader_info.code_size = sizeof(metallib_vertex);
|
// Using metallib blobs (macOS 14+, iOS)
|
||||||
fragment_shader_info.entrypoint = "main0";
|
vertex_shader_info.entrypoint = "main0";
|
||||||
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
||||||
fragment_shader_info.code = metallib_fragment;
|
vertex_shader_info.code = metallib_vertex;
|
||||||
fragment_shader_info.code_size = sizeof(metallib_fragment);
|
vertex_shader_info.code_size = sizeof(metallib_vertex);
|
||||||
|
fragment_shader_info.entrypoint = "main0";
|
||||||
|
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
||||||
|
fragment_shader_info.code = metallib_fragment;
|
||||||
|
fragment_shader_info.code_size = sizeof(metallib_fragment);
|
||||||
|
}
|
||||||
|
else if (supported_formats & SDL_GPU_SHADERFORMAT_MSL)
|
||||||
|
{
|
||||||
|
// macOS: using MSL source
|
||||||
|
vertex_shader_info.entrypoint = "main0";
|
||||||
|
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_MSL;
|
||||||
|
vertex_shader_info.code = msl_vertex;
|
||||||
|
vertex_shader_info.code_size = sizeof(msl_vertex);
|
||||||
|
fragment_shader_info.entrypoint = "main0";
|
||||||
|
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_MSL;
|
||||||
|
fragment_shader_info.code = msl_fragment;
|
||||||
|
fragment_shader_info.code_size = sizeof(msl_fragment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info);
|
bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info);
|
||||||
@@ -576,9 +607,14 @@ void ImGui_ImplSDLGPU3_CreateDeviceObjects()
|
|||||||
sampler_info.enable_anisotropy = false;
|
sampler_info.enable_anisotropy = false;
|
||||||
sampler_info.max_anisotropy = 1.0f;
|
sampler_info.max_anisotropy = 1.0f;
|
||||||
sampler_info.enable_compare = false;
|
sampler_info.enable_compare = false;
|
||||||
|
|
||||||
bd->TexSamplerLinear = SDL_CreateGPUSampler(v->Device, &sampler_info);
|
bd->TexSamplerLinear = SDL_CreateGPUSampler(v->Device, &sampler_info);
|
||||||
IM_ASSERT(bd->TexSamplerLinear != nullptr && "Failed to create sampler, call SDL_GetError() for more information");
|
IM_ASSERT(bd->TexSamplerLinear != nullptr && "Failed to create sampler, call SDL_GetError() for more information");
|
||||||
|
|
||||||
|
sampler_info.min_filter = SDL_GPU_FILTER_NEAREST;
|
||||||
|
sampler_info.mag_filter = SDL_GPU_FILTER_NEAREST;
|
||||||
|
sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST;
|
||||||
|
bd->TexSamplerNearest = SDL_CreateGPUSampler(v->Device, &sampler_info);
|
||||||
|
IM_ASSERT(bd->TexSamplerNearest != nullptr && "Failed to create sampler, call SDL_GetError() for more information");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui_ImplSDLGPU3_CreateGraphicsPipeline();
|
ImGui_ImplSDLGPU3_CreateGraphicsPipeline();
|
||||||
@@ -614,6 +650,7 @@ void ImGui_ImplSDLGPU3_DestroyDeviceObjects()
|
|||||||
if (bd->VertexShader) { SDL_ReleaseGPUShader(v->Device, bd->VertexShader); bd->VertexShader = nullptr; }
|
if (bd->VertexShader) { SDL_ReleaseGPUShader(v->Device, bd->VertexShader); bd->VertexShader = nullptr; }
|
||||||
if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->Device, bd->FragmentShader); bd->FragmentShader = nullptr; }
|
if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->Device, bd->FragmentShader); bd->FragmentShader = nullptr; }
|
||||||
if (bd->TexSamplerLinear) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerLinear); bd->TexSamplerLinear = nullptr; }
|
if (bd->TexSamplerLinear) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerLinear); bd->TexSamplerLinear = nullptr; }
|
||||||
|
if (bd->TexSamplerNearest) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerNearest); bd->TexSamplerNearest = nullptr; }
|
||||||
if (bd->Pipeline) { SDL_ReleaseGPUGraphicsPipeline(v->Device, bd->Pipeline); bd->Pipeline = nullptr; }
|
if (bd->Pipeline) { SDL_ReleaseGPUGraphicsPipeline(v->Device, bd->Pipeline); bd->Pipeline = nullptr; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,6 +671,11 @@ bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info)
|
|||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplSDLGPU3_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplSDLGPU3_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
IM_ASSERT(info->Device != nullptr);
|
IM_ASSERT(info->Device != nullptr);
|
||||||
IM_ASSERT(info->ColorTargetFormat != SDL_GPU_TEXTUREFORMAT_INVALID);
|
IM_ASSERT(info->ColorTargetFormat != SDL_GPU_TEXTUREFORMAT_INVALID);
|
||||||
|
|
||||||
@@ -649,12 +691,15 @@ void ImGui_ImplSDLGPU3_Shutdown()
|
|||||||
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport();
|
ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport();
|
||||||
ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
||||||
|
|
||||||
io.BackendRendererName = nullptr;
|
io.BackendRendererName = nullptr;
|
||||||
io.BackendRendererUserData = nullptr;
|
io.BackendRendererUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ IMGUI_IMPL_API void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data,
|
|||||||
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_CreateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
@@ -58,8 +58,6 @@ IMGUI_IMPL_API void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex);
|
|||||||
struct ImGui_ImplSDLGPU3_RenderState
|
struct ImGui_ImplSDLGPU3_RenderState
|
||||||
{
|
{
|
||||||
SDL_GPUDevice* Device;
|
SDL_GPUDevice* Device;
|
||||||
SDL_GPUSampler* SamplerDefault; // Default sampler (bilinear filtering)
|
|
||||||
SDL_GPUSampler* SamplerCurrent; // Current sampler (may be changed by callback)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -221,6 +221,40 @@ const uint8_t metallib_fragment[3787] = {
|
|||||||
148,161,0,0,0,0,109,97,105,110,48,97,105,114,46,115,97,109,112,108,101,95,116,101,120,116,117,114,101,95,50,100,46,118,52,102,51,50,51,50,48,50,51,46,51,54,56,97,105,114,54,52,45,97,
|
148,161,0,0,0,0,109,97,105,110,48,97,105,114,46,115,97,109,112,108,101,95,116,101,120,116,117,114,101,95,50,100,46,118,52,102,51,50,51,50,48,50,51,46,51,54,56,97,105,114,54,52,45,97,
|
||||||
112,112,108,101,45,109,97,99,111,115,120,49,52,46,48,46,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
112,112,108,101,45,109,97,99,111,115,120,49,52,46,48,46,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
};
|
};
|
||||||
|
static uint8_t msl_vertex[800] =
|
||||||
|
{
|
||||||
|
35,105,110,99,108,117,100,101,32,60,109,101,116,97,108,95,115,116,100,108,105,98,62,10,35,105,110,99,108,117,100,101,32,60,115,105,109,100,47,115,105,109,100,46,104,62,10,10,117,115,
|
||||||
|
105,110,103,32,110,97,109,101,115,112,97,99,101,32,109,101,116,97,108,59,10,10,115,116,114,117,99,116,32,95,57,10,123,10,32,32,32,32,102,108,111,97,116,52,32,67,111,108,111,114,59,
|
||||||
|
10,32,32,32,32,102,108,111,97,116,50,32,85,86,59,10,125,59,10,10,115,116,114,117,99,116,32,85,66,79,10,123,10,32,32,32,32,102,108,111,97,116,50,32,117,83,99,97,108,101,59,10,32,32,
|
||||||
|
32,32,102,108,111,97,116,50,32,117,84,114,97,110,115,108,97,116,101,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,111,117,116,10,123,10,32,32,32,32,102,108,111,
|
||||||
|
97,116,52,32,79,117,116,95,67,111,108,111,114,32,91,91,117,115,101,114,40,108,111,99,110,48,41,93,93,59,10,32,32,32,32,102,108,111,97,116,50,32,79,117,116,95,85,86,32,91,91,117,115,
|
||||||
|
101,114,40,108,111,99,110,49,41,93,93,59,10,32,32,32,32,102,108,111,97,116,52,32,103,108,95,80,111,115,105,116,105,111,110,32,91,91,112,111,115,105,116,105,111,110,93,93,59,10,125,
|
||||||
|
59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,105,110,10,123,10,32,32,32,32,102,108,111,97,116,50,32,97,80,111,115,32,91,91,97,116,116,114,105,98,117,116,101,40,48,41,93,
|
||||||
|
93,59,10,32,32,32,32,102,108,111,97,116,50,32,97,85,86,32,91,91,97,116,116,114,105,98,117,116,101,40,49,41,93,93,59,10,32,32,32,32,102,108,111,97,116,52,32,97,67,111,108,111,114,32,
|
||||||
|
91,91,97,116,116,114,105,98,117,116,101,40,50,41,93,93,59,10,125,59,10,10,118,101,114,116,101,120,32,109,97,105,110,48,95,111,117,116,32,109,97,105,110,48,40,109,97,105,110,48,95,105,
|
||||||
|
110,32,105,110,32,91,91,115,116,97,103,101,95,105,110,93,93,44,32,99,111,110,115,116,97,110,116,32,85,66,79,38,32,117,98,111,32,91,91,98,117,102,102,101,114,40,48,41,93,93,41,10,123,
|
||||||
|
10,32,32,32,32,109,97,105,110,48,95,111,117,116,32,111,117,116,32,61,32,123,125,59,10,32,32,32,32,95,57,32,79,117,116,32,61,32,123,125,59,10,32,32,32,32,79,117,116,46,67,111,108,111,
|
||||||
|
114,32,61,32,105,110,46,97,67,111,108,111,114,59,10,32,32,32,32,79,117,116,46,85,86,32,61,32,105,110,46,97,85,86,59,10,32,32,32,32,111,117,116,46,103,108,95,80,111,115,105,116,105,
|
||||||
|
111,110,32,61,32,102,108,111,97,116,52,40,40,105,110,46,97,80,111,115,32,42,32,117,98,111,46,117,83,99,97,108,101,41,32,43,32,117,98,111,46,117,84,114,97,110,115,108,97,116,101,44,
|
||||||
|
32,48,46,48,44,32,49,46,48,41,59,10,32,32,32,32,111,117,116,46,103,108,95,80,111,115,105,116,105,111,110,46,121,32,42,61,32,40,45,49,46,48,41,59,10,32,32,32,32,111,117,116,46,79,117,
|
||||||
|
116,95,67,111,108,111,114,32,61,32,79,117,116,46,67,111,108,111,114,59,10,32,32,32,32,111,117,116,46,79,117,116,95,85,86,32,61,32,79,117,116,46,85,86,59,10,32,32,32,32,114,101,116,
|
||||||
|
117,114,110,32,111,117,116,59,10,125,10,10,
|
||||||
|
};
|
||||||
|
static uint8_t msl_fragment[580] =
|
||||||
|
{
|
||||||
|
35,105,110,99,108,117,100,101,32,60,109,101,116,97,108,95,115,116,100,108,105,98,62,10,35,105,110,99,108,117,100,101,32,60,115,105,109,100,47,115,105,109,100,46,104,62,10,10,117,115,
|
||||||
|
105,110,103,32,110,97,109,101,115,112,97,99,101,32,109,101,116,97,108,59,10,10,115,116,114,117,99,116,32,95,49,49,10,123,10,32,32,32,32,102,108,111,97,116,52,32,67,111,108,111,114,
|
||||||
|
59,10,32,32,32,32,102,108,111,97,116,50,32,85,86,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,111,117,116,10,123,10,32,32,32,32,102,108,111,97,116,52,32,102,67,
|
||||||
|
111,108,111,114,32,91,91,99,111,108,111,114,40,48,41,93,93,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,105,110,10,123,10,32,32,32,32,102,108,111,97,116,52,32,
|
||||||
|
73,110,95,67,111,108,111,114,32,91,91,117,115,101,114,40,108,111,99,110,48,41,93,93,59,10,32,32,32,32,102,108,111,97,116,50,32,73,110,95,85,86,32,91,91,117,115,101,114,40,108,111,99,
|
||||||
|
110,49,41,93,93,59,10,125,59,10,10,102,114,97,103,109,101,110,116,32,109,97,105,110,48,95,111,117,116,32,109,97,105,110,48,40,109,97,105,110,48,95,105,110,32,105,110,32,91,91,115,116,
|
||||||
|
97,103,101,95,105,110,93,93,44,32,116,101,120,116,117,114,101,50,100,60,102,108,111,97,116,62,32,115,84,101,120,116,117,114,101,32,91,91,116,101,120,116,117,114,101,40,48,41,93,93,
|
||||||
|
44,32,115,97,109,112,108,101,114,32,115,84,101,120,116,117,114,101,83,109,112,108,114,32,91,91,115,97,109,112,108,101,114,40,48,41,93,93,41,10,123,10,32,32,32,32,109,97,105,110,48,
|
||||||
|
95,111,117,116,32,111,117,116,32,61,32,123,125,59,10,32,32,32,32,95,49,49,32,73,110,32,61,32,123,125,59,10,32,32,32,32,73,110,46,67,111,108,111,114,32,61,32,105,110,46,73,110,95,67,
|
||||||
|
111,108,111,114,59,10,32,32,32,32,73,110,46,85,86,32,61,32,105,110,46,73,110,95,85,86,59,10,32,32,32,32,111,117,116,46,102,67,111,108,111,114,32,61,32,73,110,46,67,111,108,111,114,
|
||||||
|
32,42,32,115,84,101,120,116,117,114,101,46,115,97,109,112,108,101,40,115,84,101,120,116,117,114,101,83,109,112,108,114,44,32,73,110,46,85,86,41,59,10,32,32,32,32,114,101,116,117,114,
|
||||||
|
110,32,111,117,116,59,10,125,10,10,
|
||||||
|
};
|
||||||
#elif TARGET_OS_IPHONE
|
#elif TARGET_OS_IPHONE
|
||||||
const uint8_t metallib_vertex[3876] = {
|
const uint8_t metallib_vertex[3876] = {
|
||||||
77,84,76,66,1,0,2,0,7,0,0,130,18,0,1,0,36,15,0,0,0,0,0,0,88,0,0,0,0,0,0,0,123,0,0,0,0,0,0,0,219,0,0,0,0,0,0,0,49,0,0,0,0,0,0,0,12,1,0,0,0,0,0,0,8,0,0,0,0,0,0,0,20,1,0,0,0,0,0,0,16,
|
77,84,76,66,1,0,2,0,7,0,0,130,18,0,1,0,36,15,0,0,0,0,0,0,88,0,0,0,0,0,0,0,123,0,0,0,0,0,0,0,219,0,0,0,0,0,0,0,49,0,0,0,0,0,0,0,12,1,0,0,0,0,0,0,8,0,0,0,0,0,0,0,20,1,0,0,0,0,0,0,16,
|
||||||
|
|||||||
@@ -14,10 +14,11 @@
|
|||||||
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
// Missing features:
|
// Missing features or Issues:
|
||||||
// [ ] Renderer: Multi-viewport support (multiple windows).
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
// [ ] Renderer: Missing support for DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest callbacks: SDLRenderer2 does not support changing SDL_SCALE_MODE while rendering.
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// 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:
|
// Learn about Dear ImGui:
|
||||||
// - FAQ https://dearimgui.com/faq
|
// - FAQ https://dearimgui.com/faq
|
||||||
@@ -26,6 +27,10 @@
|
|||||||
// - Introduction, links and more at the top of imgui.cpp
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState (others cannot be supported). (#9378)
|
||||||
|
// 2026-03-12: Fixed invalid assert in ImGui_ImplSDLRenderer2_UpdateTexture() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplSDLRenderer2_CreateFontsTexture() and ImGui_ImplSDLRenderer2_DestroyFontsTexture().
|
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplSDLRenderer2_CreateFontsTexture() and ImGui_ImplSDLRenderer2_DestroyFontsTexture().
|
||||||
// 2025-01-18: Use endian-dependent RGBA32 texture format, to match SDL_Color.
|
// 2025-01-18: Use endian-dependent RGBA32 texture format, to match SDL_Color.
|
||||||
// 2024-10-09: Expose selected render state in ImGui_ImplSDLRenderer2_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
// 2024-10-09: Expose selected render state in ImGui_ImplSDLRenderer2_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
||||||
@@ -72,39 +77,6 @@ static ImGui_ImplSDLRenderer2_Data* ImGui_ImplSDLRenderer2_GetBackendData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
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.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
|
||||||
|
|
||||||
bd->Renderer = 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 | ImGuiBackendFlags_RendererHasTextures);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDLRenderer2_SetupRenderState(SDL_Renderer* renderer)
|
static void ImGui_ImplSDLRenderer2_SetupRenderState(SDL_Renderer* renderer)
|
||||||
{
|
{
|
||||||
// Clear out any viewports and cliprect set by the user
|
// Clear out any viewports and cliprect set by the user
|
||||||
@@ -120,6 +92,9 @@ void ImGui_ImplSDLRenderer2_NewFrame()
|
|||||||
IM_UNUSED(bd);
|
IM_UNUSED(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplSDLRenderer2_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer)
|
void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer)
|
||||||
{
|
{
|
||||||
// If there's a scale factor set by the user, use that instead
|
// If there's a scale factor set by the user, use that instead
|
||||||
@@ -182,8 +157,7 @@ void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data, SDL_Renderer*
|
|||||||
if (pcmd->UserCallback)
|
if (pcmd->UserCallback)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplSDLRenderer2_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplSDLRenderer2_SetupRenderState(renderer);
|
ImGui_ImplSDLRenderer2_SetupRenderState(renderer);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -266,10 +240,9 @@ void ImGui_ImplSDLRenderer2_UpdateTexture(ImTextureData* tex)
|
|||||||
}
|
}
|
||||||
else if (tex->Status == ImTextureStatus_WantDestroy)
|
else if (tex->Status == ImTextureStatus_WantDestroy)
|
||||||
{
|
{
|
||||||
SDL_Texture* sdl_texture = (SDL_Texture*)(intptr_t)tex->TexID;
|
if (tex->TexID != ImTextureID_Invalid)
|
||||||
if (sdl_texture == nullptr)
|
if (SDL_Texture* sdl_texture = (SDL_Texture*)(intptr_t)tex->TexID)
|
||||||
return;
|
SDL_DestroyTexture(sdl_texture);
|
||||||
SDL_DestroyTexture(sdl_texture);
|
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
@@ -292,6 +265,44 @@ void ImGui_ImplSDLRenderer2_DestroyDeviceObjects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
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.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplSDLRenderer2_DrawCallback_ResetRenderState;
|
||||||
|
|
||||||
|
bd->Renderer = 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();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
|||||||
@@ -14,8 +14,9 @@
|
|||||||
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
// Missing features:
|
// Missing features or Issues:
|
||||||
// [ ] Renderer: Multi-viewport support (multiple windows).
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
// [ ] Renderer: Missing support for DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest callbacks: SDLRenderer2 does not support changing SDL_SCALE_MODE while rendering.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
@@ -41,7 +42,7 @@ IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_d
|
|||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_CreateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
// Missing features:
|
// Missing features:
|
||||||
// [ ] Renderer: Multi-viewport support (multiple windows).
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// 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:
|
// Learn about Dear ImGui:
|
||||||
// - FAQ https://dearimgui.com/faq
|
// - FAQ https://dearimgui.com/faq
|
||||||
@@ -26,6 +26,10 @@
|
|||||||
// - Introduction, links and more at the top of imgui.cpp
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. (#9378)
|
||||||
|
// 2026-03-12: Fixed invalid assert in ImGui_ImplSDLRenderer3_UpdateTexture() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplSDLRenderer3_CreateFontsTexture() and ImGui_ImplSDLRenderer3_DestroyFontsTexture().
|
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplSDLRenderer3_CreateFontsTexture() and ImGui_ImplSDLRenderer3_DestroyFontsTexture().
|
||||||
// 2025-01-18: Use endian-dependent RGBA32 texture format, to match SDL_Color.
|
// 2025-01-18: Use endian-dependent RGBA32 texture format, to match SDL_Color.
|
||||||
// 2024-10-09: Expose selected render state in ImGui_ImplSDLRenderer3_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
// 2024-10-09: Expose selected render state in ImGui_ImplSDLRenderer3_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
||||||
@@ -59,6 +63,9 @@ struct ImGui_ImplSDLRenderer3_Data
|
|||||||
SDL_Renderer* Renderer; // Main viewport's renderer
|
SDL_Renderer* Renderer; // Main viewport's renderer
|
||||||
ImVector<SDL_FColor> ColorBuffer;
|
ImVector<SDL_FColor> ColorBuffer;
|
||||||
|
|
||||||
|
// Render State
|
||||||
|
SDL_ScaleMode CurrentScaleMode;
|
||||||
|
|
||||||
ImGui_ImplSDLRenderer3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplSDLRenderer3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,39 +77,6 @@ static ImGui_ImplSDLRenderer3_Data* ImGui_ImplSDLRenderer3_GetBackendData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
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.
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
|
||||||
|
|
||||||
bd->Renderer = 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 | ImGuiBackendFlags_RendererHasTextures);
|
|
||||||
IM_DELETE(bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplSDLRenderer3_SetupRenderState(SDL_Renderer* renderer)
|
static void ImGui_ImplSDLRenderer3_SetupRenderState(SDL_Renderer* renderer)
|
||||||
{
|
{
|
||||||
// Clear out any viewports and cliprect set by the user
|
// Clear out any viewports and cliprect set by the user
|
||||||
@@ -136,6 +110,11 @@ static int SDL_RenderGeometryRaw8BitColor(SDL_Renderer* renderer, ImVector<SDL_F
|
|||||||
return SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color3, sizeof(*color3), uv, uv_stride, num_vertices, indices, num_indices, size_indices);
|
return SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color3, sizeof(*color3), uv, uv_stride, num_vertices, indices, num_indices, size_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplSDLRenderer3_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplSDLRenderer3_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); bd->CurrentScaleMode = SDL_SCALEMODE_LINEAR; }
|
||||||
|
static void ImGui_ImplSDLRenderer3_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); bd->CurrentScaleMode = SDL_SCALEMODE_NEAREST; }
|
||||||
|
|
||||||
void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer)
|
void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer)
|
||||||
{
|
{
|
||||||
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
||||||
@@ -202,8 +181,7 @@ void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data, SDL_Renderer*
|
|||||||
if (pcmd->UserCallback)
|
if (pcmd->UserCallback)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplSDLRenderer3_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplSDLRenderer3_SetupRenderState(renderer);
|
ImGui_ImplSDLRenderer3_SetupRenderState(renderer);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -229,6 +207,7 @@ void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data, SDL_Renderer*
|
|||||||
|
|
||||||
// Bind texture, Draw
|
// Bind texture, Draw
|
||||||
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
||||||
|
SDL_SetTextureScaleMode(tex, bd->CurrentScaleMode);
|
||||||
SDL_RenderGeometryRaw8BitColor(renderer, bd->ColorBuffer, tex,
|
SDL_RenderGeometryRaw8BitColor(renderer, bd->ColorBuffer, tex,
|
||||||
xy, (int)sizeof(ImDrawVert),
|
xy, (int)sizeof(ImDrawVert),
|
||||||
color, (int)sizeof(ImDrawVert),
|
color, (int)sizeof(ImDrawVert),
|
||||||
@@ -253,7 +232,7 @@ void ImGui_ImplSDLRenderer3_UpdateTexture(ImTextureData* tex)
|
|||||||
{
|
{
|
||||||
// Create and upload new texture to graphics system
|
// Create and upload new texture to graphics system
|
||||||
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
||||||
IM_ASSERT(tex->TexID == 0 && tex->BackendUserData == nullptr);
|
IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr);
|
||||||
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
||||||
|
|
||||||
// Create texture
|
// Create texture
|
||||||
@@ -282,10 +261,9 @@ void ImGui_ImplSDLRenderer3_UpdateTexture(ImTextureData* tex)
|
|||||||
}
|
}
|
||||||
else if (tex->Status == ImTextureStatus_WantDestroy)
|
else if (tex->Status == ImTextureStatus_WantDestroy)
|
||||||
{
|
{
|
||||||
SDL_Texture* sdl_texture = (SDL_Texture*)(intptr_t)tex->TexID;
|
if (tex->TexID != ImTextureID_Invalid)
|
||||||
if (sdl_texture == nullptr)
|
if (SDL_Texture* sdl_texture = (SDL_Texture*)(intptr_t)tex->TexID)
|
||||||
return;
|
SDL_DestroyTexture(sdl_texture);
|
||||||
SDL_DestroyTexture(sdl_texture);
|
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
@@ -308,6 +286,46 @@ void ImGui_ImplSDLRenderer3_DestroyDeviceObjects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
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.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplSDLRenderer3_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplSDLRenderer3_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplSDLRenderer3_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
|
bd->Renderer = 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();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplSDLRenderer3_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
// Missing features:
|
// Missing features:
|
||||||
// [ ] Renderer: Multi-viewport support (multiple windows).
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// 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:
|
// Learn about Dear ImGui:
|
||||||
// - FAQ https://dearimgui.com/faq
|
// - FAQ https://dearimgui.com/faq
|
||||||
@@ -41,7 +41,7 @@ IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_d
|
|||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_CreateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_DestroyDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_DestroyDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
|||||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as texture identifier. Call ImGui_ImplVulkan_AddTexture() to register one. Read the FAQ about ImTextureID/ImTextureRef + https://github.com/ocornut/imgui/pull/914 for discussions.
|
// [!] Renderer: User texture binding. Use a VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE 'VkDescriptorSet' as texture identifier. Call ImGui_ImplVulkan_AddTexture() to register one. Read the FAQ about ImTextureID/ImTextureRef + https://github.com/ocornut/imgui/pull/914 for discussions.
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
@@ -42,9 +42,20 @@
|
|||||||
// If you have no idea what this is, leave it alone!
|
// If you have no idea what this is, leave it alone!
|
||||||
//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
||||||
|
|
||||||
// Convenience support for Volk
|
// [Configuration] Convenience support for Volk
|
||||||
// (you can also technically use IMGUI_IMPL_VULKAN_NO_PROTOTYPES + wrap Volk via ImGui_ImplVulkan_LoadFunctions().)
|
// (you can also technically use IMGUI_IMPL_VULKAN_NO_PROTOTYPES + wrap Volk via ImGui_ImplVulkan_LoadFunctions().)
|
||||||
|
// (When using Volk from directory outside your include directories list you can specify full path to the volk.h header,
|
||||||
|
// for example when using Volk from VulkanSDK and using include_directories(${Vulkan_INCLUDE_DIRS})' from 'find_package(Vulkan REQUIRED)')
|
||||||
//#define IMGUI_IMPL_VULKAN_USE_VOLK
|
//#define IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
//#define IMGUI_IMPL_VULKAN_VOLK_FILENAME <Volk/volk.h>
|
||||||
|
//#define IMGUI_IMPL_VULKAN_VOLK_FILENAME <volk.h> // Default
|
||||||
|
// Reminder: make those changes in your imconfig.h file, not here!
|
||||||
|
|
||||||
|
// 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
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
|
#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
|
||||||
#define VK_NO_PROTOTYPES
|
#define VK_NO_PROTOTYPES
|
||||||
@@ -55,7 +66,11 @@
|
|||||||
|
|
||||||
// Vulkan includes
|
// Vulkan includes
|
||||||
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
|
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_VOLK_FILENAME
|
||||||
|
#include IMGUI_IMPL_VULKAN_VOLK_FILENAME
|
||||||
|
#else
|
||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -64,7 +79,26 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Backend uses a small number of descriptors per font atlas + as many as additional calls done to ImGui_ImplVulkan_AddTexture().
|
// Backend uses a small number of descriptors per font atlas + as many as additional calls done to ImGui_ImplVulkan_AddTexture().
|
||||||
#define IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE (8) // Minimum per atlas
|
#define IMGUI_IMPL_VULKAN_MINIMUM_SAMPLED_IMAGE_POOL_SIZE (8) // Minimum per atlas
|
||||||
|
#define IMGUI_IMPL_VULKAN_MINIMUM_SAMPLER_POOL_SIZE (2) // Minimum for linear + nearest
|
||||||
|
|
||||||
|
// Specify settings to create pipeline and swapchain
|
||||||
|
struct ImGui_ImplVulkan_PipelineInfo
|
||||||
|
{
|
||||||
|
// For Main viewport only
|
||||||
|
VkRenderPass RenderPass; // Ignored if using dynamic rendering
|
||||||
|
|
||||||
|
// For Main and Secondary viewports
|
||||||
|
uint32_t Subpass; //
|
||||||
|
VkSampleCountFlagBits MSAASamples = {}; // 0 defaults to VK_SAMPLE_COUNT_1_BIT
|
||||||
|
ImVector<VkDynamicState> ExtraDynamicStates; // Optional, allows to insert more dynamic states into our VkPipeline
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
||||||
|
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// For Secondary viewports only (created/managed by backend)
|
||||||
|
VkImageUsageFlags SwapChainImageUsage; // Extra flags for vkCreateSwapchainKHR() calls for secondary viewports. We automatically add VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT. You can add e.g. VK_IMAGE_USAGE_TRANSFER_SRC_BIT if you need to capture from viewports.
|
||||||
|
};
|
||||||
|
|
||||||
// Initialization data, for ImGui_ImplVulkan_Init()
|
// Initialization data, for ImGui_ImplVulkan_Init()
|
||||||
// [Please zero-clear before use!]
|
// [Please zero-clear before use!]
|
||||||
@@ -73,7 +107,7 @@
|
|||||||
// and must contain a pool size large enough to hold a small number of VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptors.
|
// and must contain a pool size large enough to hold a small number of VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptors.
|
||||||
// - As an convenience, by setting DescriptorPoolSize > 0 the backend will create one for you.
|
// - As an convenience, by setting DescriptorPoolSize > 0 the backend will create one for you.
|
||||||
// - About dynamic rendering:
|
// - About dynamic rendering:
|
||||||
// - When using dynamic rendering, set UseDynamicRendering=true and fill PipelineRenderingCreateInfo structure.
|
// - When using dynamic rendering, set UseDynamicRendering=true + fill PipelineInfoMain.PipelineRenderingCreateInfo structure.
|
||||||
struct ImGui_ImplVulkan_InitInfo
|
struct ImGui_ImplVulkan_InitInfo
|
||||||
{
|
{
|
||||||
uint32_t ApiVersion; // Fill with API version of Instance, e.g. VK_API_VERSION_1_3 or your value of VkApplicationInfo::apiVersion. May be lower than header version (VK_HEADER_VERSION_COMPLETE)
|
uint32_t ApiVersion; // Fill with API version of Instance, e.g. VK_API_VERSION_1_3 or your value of VkApplicationInfo::apiVersion. May be lower than header version (VK_HEADER_VERSION_COMPLETE)
|
||||||
@@ -83,27 +117,33 @@ struct ImGui_ImplVulkan_InitInfo
|
|||||||
uint32_t QueueFamily;
|
uint32_t QueueFamily;
|
||||||
VkQueue Queue;
|
VkQueue Queue;
|
||||||
VkDescriptorPool DescriptorPool; // See requirements in note above; ignored if using DescriptorPoolSize > 0
|
VkDescriptorPool DescriptorPool; // See requirements in note above; ignored if using DescriptorPoolSize > 0
|
||||||
uint32_t DescriptorPoolSize; // Optional: set to create internal descriptor pool automatically instead of using DescriptorPool.
|
uint32_t DescriptorPoolSize; // Optional: set to create internal ImageView descriptor pool automatically instead of using DescriptorPool.
|
||||||
uint32_t MinImageCount; // >= 2
|
uint32_t MinImageCount; // >= 2
|
||||||
uint32_t ImageCount; // >= MinImageCount
|
uint32_t ImageCount; // >= MinImageCount
|
||||||
VkPipelineCache PipelineCache; // Optional
|
VkPipelineCache PipelineCache; // Optional
|
||||||
|
|
||||||
// Pipeline
|
// Pipeline
|
||||||
VkRenderPass RenderPass; // Ignored if using dynamic rendering
|
ImGui_ImplVulkan_PipelineInfo PipelineInfoMain; // Infos for Main Viewport (created by app/user)
|
||||||
uint32_t Subpass;
|
ImGui_ImplVulkan_PipelineInfo PipelineInfoForViewports; // Infos for Secondary Viewports (created by backend)
|
||||||
VkSampleCountFlagBits MSAASamples; // 0 defaults to VK_SAMPLE_COUNT_1_BIT
|
//VkRenderPass RenderPass; // --> Since 2025/09/26: set 'PipelineInfoMain.RenderPass' instead
|
||||||
|
//uint32_t Subpass; // --> Since 2025/09/26: set 'PipelineInfoMain.Subpass' instead
|
||||||
|
//VkSampleCountFlagBits MSAASamples; // --> Since 2025/09/26: set 'PipelineInfoMain.MSAASamples' instead
|
||||||
|
//VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Since 2025/09/26: set 'PipelineInfoMain.PipelineRenderingCreateInfo' instead
|
||||||
|
|
||||||
// (Optional) Dynamic Rendering
|
// (Optional) Dynamic Rendering
|
||||||
// Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3 + setup PipelineRenderingCreateInfo.
|
// Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3 + setup PipelineInfoMain.PipelineRenderingCreateInfo and PipelineInfoViewports.PipelineRenderingCreateInfo.
|
||||||
bool UseDynamicRendering;
|
bool UseDynamicRendering;
|
||||||
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
|
||||||
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// (Optional) Allocation, Debugging
|
// (Optional) Allocation, Debugging
|
||||||
const VkAllocationCallbacks* Allocator;
|
const VkAllocationCallbacks* Allocator;
|
||||||
void (*CheckVkResultFn)(VkResult err);
|
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.
|
VkDeviceSize MinAllocationSize; // Minimum allocation size. Set to 1024*1024 to satisfy zealous best practices validation layer and waste a little memory.
|
||||||
|
|
||||||
|
// (Optional) Customize default vertex/fragment shaders.
|
||||||
|
// - if .sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO we use specified structs, otherwise we use defaults.
|
||||||
|
// - Shader inputs/outputs need to match ours. Code/data pointed to by the structure needs to survive for whole during of backend usage.
|
||||||
|
VkShaderModuleCreateInfo CustomShaderVertCreateInfo;
|
||||||
|
VkShaderModuleCreateInfo CustomShaderFragCreateInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
@@ -116,32 +156,26 @@ IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_i
|
|||||||
// (Advanced) Use e.g. if you need to recreate pipeline without reinitializing the backend (see #8110, #8111)
|
// (Advanced) Use e.g. if you need to recreate pipeline without reinitializing the backend (see #8110, #8111)
|
||||||
// The main window pipeline will be created by ImGui_ImplVulkan_Init() if possible (== RenderPass xor (UseDynamicRendering && PipelineRenderingCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR))
|
// The main window pipeline will be created by ImGui_ImplVulkan_Init() if possible (== RenderPass xor (UseDynamicRendering && PipelineRenderingCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR))
|
||||||
// Else, the pipeline can be created, or re-created, using ImGui_ImplVulkan_CreateMainPipeline() before rendering.
|
// Else, the pipeline can be created, or re-created, using ImGui_ImplVulkan_CreateMainPipeline() before rendering.
|
||||||
struct ImGui_ImplVulkan_MainPipelineCreateInfo
|
IMGUI_IMPL_API void ImGui_ImplVulkan_CreateMainPipeline(const ImGui_ImplVulkan_PipelineInfo* info);
|
||||||
{
|
|
||||||
VkRenderPass RenderPass = VK_NULL_HANDLE;
|
|
||||||
uint32_t Subpass = 0;
|
|
||||||
VkSampleCountFlagBits MSAASamples = {};
|
|
||||||
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
|
||||||
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_CreateMainPipeline(const ImGui_ImplVulkan_MainPipelineCreateInfo& info); // (render_pass xor (p_dynamic_rendering && p_dynamic_rendering is correct (sType and pNext)))
|
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkan_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplVulkan_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// Register a texture (VkDescriptorSet == ImTextureID)
|
// Register a texture (VkDescriptorSet for a VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE == ImTextureID)
|
||||||
// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem
|
IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkImageView image_view, VkImageLayout image_layout);
|
||||||
// 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);
|
IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set);
|
||||||
|
|
||||||
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout); // Ignore VkSampler
|
||||||
|
#endif
|
||||||
|
|
||||||
// Optional: load Vulkan functions with a custom function loader
|
// Optional: load Vulkan functions with a custom function loader
|
||||||
// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES
|
// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES
|
||||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(uint32_t api_version, PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr);
|
IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(uint32_t api_version, PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplVulkan_RenderDrawData() call.
|
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplVulkan_RenderDrawData() call.
|
||||||
|
// ImGui_ImplVulkan_RenderState* render_state = (ImGui_ImplVulkan_RenderState*)ImGui::GetPlatformIO().Renderer_RenderState;
|
||||||
// (Please open an issue if you feel you need access to more data)
|
// (Please open an issue if you feel you need access to more data)
|
||||||
struct ImGui_ImplVulkan_RenderState
|
struct ImGui_ImplVulkan_RenderState
|
||||||
{
|
{
|
||||||
@@ -156,6 +190,7 @@ struct ImGui_ImplVulkan_RenderState
|
|||||||
// Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.
|
// 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.
|
// You probably do NOT need to use or care about those functions.
|
||||||
|
// WE DO NOT PROVIDE STRONG GUARANTEES OF BACKWARD/FORWARD COMPATIBILITY.
|
||||||
// Those functions only exist because:
|
// Those functions only exist because:
|
||||||
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
||||||
// 2) the multi-viewport / platform window implementation needs them internally.
|
// 2) the multi-viewport / platform window implementation needs them internally.
|
||||||
@@ -166,8 +201,6 @@ struct ImGui_ImplVulkan_RenderState
|
|||||||
// render pass, frame buffers, etc.). You may read this code if you are curious, but
|
// render pass, frame buffers, etc.). You may read this code if you are curious, but
|
||||||
// it is recommended you use your own custom tailored code to do equivalent work.
|
// it is recommended you use your own custom tailored code to do equivalent work.
|
||||||
//
|
//
|
||||||
// We don't provide a strong guarantee that we won't change those functions API.
|
|
||||||
//
|
|
||||||
// The ImGui_ImplVulkanH_XXX functions should NOT interact with any of the state used
|
// The ImGui_ImplVulkanH_XXX functions should NOT interact with any of the state used
|
||||||
// by the regular ImGui_ImplVulkan_XXX functions.
|
// by the regular ImGui_ImplVulkan_XXX functions.
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@@ -176,13 +209,14 @@ struct ImGui_ImplVulkanH_Frame;
|
|||||||
struct ImGui_ImplVulkanH_Window;
|
struct ImGui_ImplVulkanH_Window;
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
|
IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count, VkImageUsageFlags image_usage);
|
||||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator);
|
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wd, 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 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 VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
|
||||||
IMGUI_IMPL_API VkPhysicalDevice ImGui_ImplVulkanH_SelectPhysicalDevice(VkInstance instance);
|
IMGUI_IMPL_API VkPhysicalDevice ImGui_ImplVulkanH_SelectPhysicalDevice(VkInstance instance);
|
||||||
IMGUI_IMPL_API uint32_t ImGui_ImplVulkanH_SelectQueueFamilyIndex(VkPhysicalDevice physical_device);
|
IMGUI_IMPL_API uint32_t ImGui_ImplVulkanH_SelectQueueFamilyIndex(VkPhysicalDevice physical_device);
|
||||||
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
||||||
|
IMGUI_IMPL_API ImGui_ImplVulkanH_Window* ImGui_ImplVulkanH_GetWindowDataFromViewport(ImGuiViewport* viewport); // Access to Vulkan objects associated with a viewport (e.g to export a screenshot)
|
||||||
|
|
||||||
// Helper structure to hold the data needed by one rendering frame
|
// 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.)
|
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||||
@@ -207,29 +241,47 @@ struct ImGui_ImplVulkanH_FrameSemaphores
|
|||||||
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||||
struct ImGui_ImplVulkanH_Window
|
struct ImGui_ImplVulkanH_Window
|
||||||
{
|
{
|
||||||
int Width;
|
// Input
|
||||||
int Height;
|
bool UseDynamicRendering;
|
||||||
VkSwapchainKHR Swapchain;
|
VkSurfaceKHR Surface; // Surface created and destroyed by caller.
|
||||||
VkSurfaceKHR Surface;
|
VkSurfaceFormatKHR SurfaceFormat;
|
||||||
VkSurfaceFormatKHR SurfaceFormat;
|
VkPresentModeKHR PresentMode;
|
||||||
VkPresentModeKHR PresentMode;
|
VkAttachmentDescription AttachmentDesc; // RenderPass creation: main attachment description.
|
||||||
VkRenderPass RenderPass;
|
VkClearValue ClearValue; // RenderPass creation: clear value when using VK_ATTACHMENT_LOAD_OP_CLEAR.
|
||||||
bool UseDynamicRendering;
|
|
||||||
bool ClearEnable;
|
// Internal
|
||||||
VkClearValue ClearValue;
|
int Width; // Generally same as passed to ImGui_ImplVulkanH_CreateOrResizeWindow()
|
||||||
uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
|
int Height;
|
||||||
uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
|
VkSwapchainKHR Swapchain;
|
||||||
uint32_t SemaphoreCount; // Number of simultaneous in-flight frames + 1, to be able to use it in vkAcquireNextImageKHR
|
VkRenderPass RenderPass;
|
||||||
uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
|
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 SemaphoreCount; // Number of simultaneous in-flight frames + 1, to be able to use it in vkAcquireNextImageKHR
|
||||||
|
uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
|
||||||
ImVector<ImGui_ImplVulkanH_Frame> Frames;
|
ImVector<ImGui_ImplVulkanH_Frame> Frames;
|
||||||
ImVector<ImGui_ImplVulkanH_FrameSemaphores> FrameSemaphores;
|
ImVector<ImGui_ImplVulkanH_FrameSemaphores> FrameSemaphores;
|
||||||
|
|
||||||
ImGui_ImplVulkanH_Window()
|
ImGui_ImplVulkanH_Window()
|
||||||
{
|
{
|
||||||
memset((void*)this, 0, sizeof(*this));
|
memset((void*)this, 0, sizeof(*this));
|
||||||
PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this.
|
|
||||||
ClearEnable = true;
|
// Parameters to create SwapChain
|
||||||
|
PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; // Ensure we get an error if user doesn't set this.
|
||||||
|
|
||||||
|
// Parameters to create RenderPass
|
||||||
|
AttachmentDesc.format = VK_FORMAT_UNDEFINED; // Will automatically use wd->SurfaceFormat.format.
|
||||||
|
AttachmentDesc.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
AttachmentDesc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
AttachmentDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
AttachmentDesc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
|
AttachmentDesc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
AttachmentDesc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
AttachmentDesc.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// dear imgui: Renderer for WebGPU
|
// dear imgui: Renderer for WebGPU
|
||||||
// This needs to be used along with a Platform Binding (e.g. GLFW)
|
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL2, SDL3)
|
||||||
// (Please note that WebGPU is currently experimental, will not run on non-beta browsers, and may break.)
|
// (Please note that WebGPU is a recent API, may not be supported by all browser, and its ecosystem is generally a mess)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID/ImTextureRef!
|
// [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID/ImTextureRef!
|
||||||
@@ -10,6 +10,8 @@
|
|||||||
// Missing features or Issues:
|
// Missing features or Issues:
|
||||||
// [ ] Renderer: Multi-viewport support (multiple windows), useful for desktop.
|
// [ ] Renderer: Multi-viewport support (multiple windows), useful for desktop.
|
||||||
|
|
||||||
|
// Read imgui_impl_wgpu.h about how to use the IMGUI_IMPL_WEBGPU_BACKEND_WGPU or IMGUI_IMPL_WEBGPU_BACKEND_DAWN flags.
|
||||||
|
|
||||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// 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:
|
// Learn about Dear ImGui:
|
||||||
@@ -20,6 +22,11 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. (#9378)
|
||||||
|
// 2026-03-25: Added support for WGVK native backend via IMGUI_IMPL_WEBGPU_BACKEND_WGVK define, with SPIRV shaders if WGSL is not available. (#9316, #9246, #9257)
|
||||||
|
// 2026-03-09: Removed support for Emscripten < 4.0.10. (#9281)
|
||||||
|
// 2025-10-16: Update to compile with Dawn and Emscripten's 4.0.10+ '--use-port=emdawnwebgpu' ports. (#8381, #8898)
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. (#8465)
|
// 2025-06-12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. (#8465)
|
||||||
// 2025-02-26: Recreate image bind groups during render. (#8426, #8046, #7765, #8027) + Update for latest webgpu-native changes.
|
// 2025-02-26: Recreate image bind groups during render. (#8426, #8046, #7765, #8027) + Update for latest webgpu-native changes.
|
||||||
// 2024-10-14: Update Dawn support for change of string usages. (#8082, #8083)
|
// 2024-10-14: Update Dawn support for change of string usages. (#8082, #8083)
|
||||||
@@ -47,24 +54,20 @@
|
|||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
// When targeting native platforms (i.e. NOT emscripten), one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
|
||||||
// or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. See imgui_impl_wgpu.h for more details.
|
|
||||||
#ifndef __EMSCRIPTEN__
|
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
#error exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be defined!
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
#error neither IMGUI_IMPL_WEBGPU_BACKEND_DAWN nor IMGUI_IMPL_WEBGPU_BACKEND_WGPU may be defined if targeting emscripten!
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef IMGUI_DISABLE
|
#ifndef IMGUI_DISABLE
|
||||||
#include "imgui_impl_wgpu.h"
|
#include "imgui_impl_wgpu.h"
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <webgpu/webgpu.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
// One of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. See imgui_impl_wgpu.h for more details.
|
||||||
|
#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK)
|
||||||
|
#error Exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN, IMGUI_IMPL_WEBGPU_BACKEND_WGPU or IMGUI_IMPL_WEBGPU_BACKEND_WGVK must be defined!
|
||||||
|
#endif
|
||||||
|
#if defined(__EMSCRIPTEN__) && defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
|
#error Emscripten <4.0.10 with '-sUSE_WEBGPU=1' is not supported anymore.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined IMGUI_IMPL_WEBGPU_BACKEND_DAWN || defined IMGUI_IMPL_WEBGPU_BACKEND_WGVK
|
||||||
// Dawn renamed WGPUProgrammableStageDescriptor to WGPUComputeState (see: https://github.com/webgpu-native/webgpu-headers/pull/413)
|
// Dawn renamed WGPUProgrammableStageDescriptor to WGPUComputeState (see: https://github.com/webgpu-native/webgpu-headers/pull/413)
|
||||||
// Using type alias until WGPU adopts the same naming convention (#8369)
|
// Using type alias until WGPU adopts the same naming convention (#8369)
|
||||||
using WGPUProgrammableStageDescriptor = WGPUComputeState;
|
using WGPUProgrammableStageDescriptor = WGPUComputeState;
|
||||||
@@ -83,11 +86,13 @@ struct ImGui_ImplWGPU_Texture
|
|||||||
|
|
||||||
struct RenderResources
|
struct RenderResources
|
||||||
{
|
{
|
||||||
WGPUSampler Sampler = nullptr; // Sampler for textures
|
WGPUSampler SamplerLinear = nullptr; // Bilinear sampler
|
||||||
WGPUBuffer Uniforms = nullptr; // Shader uniforms
|
WGPUSampler SamplerNearest = nullptr; // Nearest/point sampler
|
||||||
WGPUBindGroup CommonBindGroup = nullptr; // Resources bind-group to bind the common resources to pipeline
|
WGPUBuffer Uniforms = nullptr; // Shader uniforms
|
||||||
ImGuiStorage ImageBindGroups; // Resources bind-group to bind the font/image resources to pipeline (this is a key->value map)
|
WGPUBindGroup CommonBindGroupLinear = nullptr; // Common bind-group bound to group 0 (uniforms + SamplerLinear)
|
||||||
WGPUBindGroupLayout ImageBindGroupLayout = nullptr; // Cache layout used for the image bind group. Avoids allocating unnecessary JS objects when working with WebASM
|
WGPUBindGroup CommonBindGroupNearest = nullptr; // Common bind-group bound to group 0 (uniforms + SamplerNearest)
|
||||||
|
ImGuiStorage ImageBindGroups; // Resources bind-group to bind the font/image resources to pipeline (this is a key->value map)
|
||||||
|
WGPUBindGroupLayout ImageBindGroupLayout = nullptr; // Cache layout used for the image bind group. Avoids allocating unnecessary JS objects when working with WebASM
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FrameResources
|
struct FrameResources
|
||||||
@@ -114,6 +119,7 @@ struct ImGui_ImplWGPU_Data
|
|||||||
WGPUTextureFormat renderTargetFormat = WGPUTextureFormat_Undefined;
|
WGPUTextureFormat renderTargetFormat = WGPUTextureFormat_Undefined;
|
||||||
WGPUTextureFormat depthStencilFormat = WGPUTextureFormat_Undefined;
|
WGPUTextureFormat depthStencilFormat = WGPUTextureFormat_Undefined;
|
||||||
WGPURenderPipeline pipelineState = nullptr;
|
WGPURenderPipeline pipelineState = nullptr;
|
||||||
|
ImGui_ImplWGPU_RenderState* RenderState = nullptr; // == ImGui::GetPlatformIO().Renderer_RenderState during rendering.
|
||||||
|
|
||||||
RenderResources renderResources;
|
RenderResources renderResources;
|
||||||
FrameResources* pFrameResources = nullptr;
|
FrameResources* pFrameResources = nullptr;
|
||||||
@@ -186,6 +192,60 @@ fn main(in: VertexOutput) -> @location(0) vec4<f32> {
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
// Same shader as __shader_vert_wgsl[] but compiled as SPIRV.
|
||||||
|
// 'wgslc -o vert.spv vert.wgsl' + 'binary_to_compressed_c -u8 -nocompress vert.spv'
|
||||||
|
static const unsigned char __shader_vert_spirv[1996] =
|
||||||
|
{
|
||||||
|
3,2,35,7,0,3,1,0,1,0,23,0,90,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,12,0,0,0,0,0,78,0,0,0,109,97,105,110,0,0,0,0,8,0,0,0,12,0,0,0,13,0,0,0,16,0,0,0,18,0,0,0,19,
|
||||||
|
0,0,0,21,0,0,0,71,0,4,0,4,0,0,0,6,0,0,0,16,0,0,0,72,0,5,0,3,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,71,0,3,0,3,0,0,0,2,0,0,0,71,0,4,0,1,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,1,0,0,0,33,0,0,0,0,0,
|
||||||
|
0,0,71,0,3,0,1,0,0,0,24,0,0,0,71,0,4,0,8,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,12,0,0,0,30,0,0,0,1,0,0,0,71,0,4,0,13,0,0,0,30,0,0,0,2,0,0,0,71,0,4,0,16,0,0,0,11,0,0,0,0,0,0,0,71,0,4,0,18,
|
||||||
|
0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,19,0,0,0,30,0,0,0,1,0,0,0,71,0,4,0,21,0,0,0,11,0,0,0,1,0,0,0,21,0,4,0,6,0,0,0,32,0,0,0,0,0,0,0,23,0,4,0,5,0,0,0,6,0,0,0,4,0,0,0,43,0,4,0,6,0,0,0,7,0,
|
||||||
|
0,0,5,0,0,0,28,0,4,0,4,0,0,0,5,0,0,0,7,0,0,0,30,0,3,0,3,0,0,0,4,0,0,0,32,0,4,0,2,0,0,0,2,0,0,0,3,0,0,0,59,0,4,0,2,0,0,0,1,0,0,0,2,0,0,0,22,0,3,0,11,0,0,0,32,0,0,0,23,0,4,0,10,0,0,0,
|
||||||
|
11,0,0,0,2,0,0,0,32,0,4,0,9,0,0,0,1,0,0,0,10,0,0,0,59,0,4,0,9,0,0,0,8,0,0,0,1,0,0,0,59,0,4,0,9,0,0,0,12,0,0,0,1,0,0,0,23,0,4,0,15,0,0,0,11,0,0,0,4,0,0,0,32,0,4,0,14,0,0,0,1,0,0,0,15,
|
||||||
|
0,0,0,59,0,4,0,14,0,0,0,13,0,0,0,1,0,0,0,32,0,4,0,17,0,0,0,3,0,0,0,15,0,0,0,59,0,4,0,17,0,0,0,16,0,0,0,3,0,0,0,59,0,4,0,17,0,0,0,18,0,0,0,3,0,0,0,32,0,4,0,20,0,0,0,3,0,0,0,10,0,0,0,
|
||||||
|
59,0,4,0,20,0,0,0,19,0,0,0,3,0,0,0,32,0,4,0,22,0,0,0,3,0,0,0,11,0,0,0,59,0,4,0,22,0,0,0,21,0,0,0,3,0,0,0,30,0,5,0,24,0,0,0,15,0,0,0,15,0,0,0,10,0,0,0,30,0,5,0,25,0,0,0,10,0,0,0,10,
|
||||||
|
0,0,0,15,0,0,0,33,0,4,0,27,0,0,0,24,0,0,0,25,0,0,0,32,0,4,0,30,0,0,0,7,0,0,0,24,0,0,0,46,0,3,0,24,0,0,0,31,0,0,0,32,0,4,0,33,0,0,0,7,0,0,0,15,0,0,0,43,0,4,0,6,0,0,0,34,0,0,0,0,0,0,
|
||||||
|
0,24,0,4,0,36,0,0,0,15,0,0,0,4,0,0,0,43,0,4,0,11,0,0,0,40,0,0,0,0,0,0,0,43,0,4,0,11,0,0,0,41,0,0,0,0,0,128,63,43,0,4,0,6,0,0,0,44,0,0,0,1,0,0,0,32,0,4,0,47,0,0,0,7,0,0,0,10,0,0,0,43,
|
||||||
|
0,4,0,6,0,0,0,48,0,0,0,2,0,0,0,33,0,4,0,52,0,0,0,36,0,0,0,6,0,0,0,43,0,4,0,6,0,0,0,55,0,0,0,16,0,0,0,32,0,4,0,57,0,0,0,2,0,0,0,5,0,0,0,43,0,4,0,6,0,0,0,66,0,0,0,32,0,0,0,43,0,4,0,6,
|
||||||
|
0,0,0,72,0,0,0,48,0,0,0,19,0,2,0,79,0,0,0,33,0,3,0,80,0,0,0,79,0,0,0,54,0,5,0,24,0,0,0,23,0,0,0,0,0,0,0,27,0,0,0,55,0,3,0,25,0,0,0,26,0,0,0,248,0,2,0,28,0,0,0,59,0,5,0,30,0,0,0,29,
|
||||||
|
0,0,0,7,0,0,0,31,0,0,0,65,0,5,0,33,0,0,0,32,0,0,0,29,0,0,0,34,0,0,0,57,0,5,0,36,0,0,0,35,0,0,0,37,0,0,0,34,0,0,0,81,0,5,0,10,0,0,0,38,0,0,0,26,0,0,0,0,0,0,0,80,0,6,0,15,0,0,0,39,0,
|
||||||
|
0,0,38,0,0,0,40,0,0,0,41,0,0,0,145,0,5,0,15,0,0,0,42,0,0,0,35,0,0,0,39,0,0,0,62,0,4,0,32,0,0,0,42,0,0,0,0,0,0,0,65,0,5,0,33,0,0,0,43,0,0,0,29,0,0,0,44,0,0,0,81,0,5,0,15,0,0,0,45,0,
|
||||||
|
0,0,26,0,0,0,2,0,0,0,62,0,4,0,43,0,0,0,45,0,0,0,0,0,0,0,65,0,5,0,47,0,0,0,46,0,0,0,29,0,0,0,48,0,0,0,81,0,5,0,10,0,0,0,49,0,0,0,26,0,0,0,1,0,0,0,62,0,4,0,46,0,0,0,49,0,0,0,0,0,0,0,
|
||||||
|
61,0,5,0,24,0,0,0,50,0,0,0,29,0,0,0,0,0,0,0,254,0,2,0,50,0,0,0,56,0,1,0,54,0,5,0,36,0,0,0,37,0,0,0,0,0,0,0,52,0,0,0,55,0,3,0,6,0,0,0,51,0,0,0,248,0,2,0,53,0,0,0,134,0,5,0,6,0,0,0,54,
|
||||||
|
0,0,0,51,0,0,0,55,0,0,0,65,0,6,0,57,0,0,0,56,0,0,0,1,0,0,0,34,0,0,0,54,0,0,0,61,0,5,0,5,0,0,0,58,0,0,0,56,0,0,0,0,0,0,0,124,0,4,0,15,0,0,0,59,0,0,0,58,0,0,0,128,0,5,0,6,0,0,0,60,0,
|
||||||
|
0,0,55,0,0,0,51,0,0,0,134,0,5,0,6,0,0,0,61,0,0,0,60,0,0,0,55,0,0,0,65,0,6,0,57,0,0,0,62,0,0,0,1,0,0,0,34,0,0,0,61,0,0,0,61,0,5,0,5,0,0,0,63,0,0,0,62,0,0,0,0,0,0,0,124,0,4,0,15,0,0,
|
||||||
|
0,64,0,0,0,63,0,0,0,128,0,5,0,6,0,0,0,65,0,0,0,66,0,0,0,51,0,0,0,134,0,5,0,6,0,0,0,67,0,0,0,65,0,0,0,55,0,0,0,65,0,6,0,57,0,0,0,68,0,0,0,1,0,0,0,34,0,0,0,67,0,0,0,61,0,5,0,5,0,0,0,
|
||||||
|
69,0,0,0,68,0,0,0,0,0,0,0,124,0,4,0,15,0,0,0,70,0,0,0,69,0,0,0,128,0,5,0,6,0,0,0,71,0,0,0,72,0,0,0,51,0,0,0,134,0,5,0,6,0,0,0,73,0,0,0,71,0,0,0,55,0,0,0,65,0,6,0,57,0,0,0,74,0,0,0,
|
||||||
|
1,0,0,0,34,0,0,0,73,0,0,0,61,0,5,0,5,0,0,0,75,0,0,0,74,0,0,0,0,0,0,0,124,0,4,0,15,0,0,0,76,0,0,0,75,0,0,0,80,0,7,0,36,0,0,0,77,0,0,0,59,0,0,0,64,0,0,0,70,0,0,0,76,0,0,0,254,0,2,0,77,
|
||||||
|
0,0,0,56,0,1,0,54,0,5,0,79,0,0,0,78,0,0,0,0,0,0,0,80,0,0,0,248,0,2,0,81,0,0,0,61,0,5,0,10,0,0,0,82,0,0,0,8,0,0,0,0,0,0,0,61,0,5,0,10,0,0,0,83,0,0,0,12,0,0,0,0,0,0,0,61,0,5,0,15,0,0,
|
||||||
|
0,84,0,0,0,13,0,0,0,0,0,0,0,80,0,6,0,25,0,0,0,85,0,0,0,82,0,0,0,83,0,0,0,84,0,0,0,57,0,5,0,24,0,0,0,86,0,0,0,23,0,0,0,85,0,0,0,81,0,5,0,15,0,0,0,87,0,0,0,86,0,0,0,0,0,0,0,62,0,4,0,
|
||||||
|
16,0,0,0,87,0,0,0,0,0,0,0,81,0,5,0,15,0,0,0,88,0,0,0,86,0,0,0,1,0,0,0,62,0,4,0,18,0,0,0,88,0,0,0,0,0,0,0,81,0,5,0,10,0,0,0,89,0,0,0,86,0,0,0,2,0,0,0,62,0,4,0,19,0,0,0,89,0,0,0,0,0,
|
||||||
|
0,0,62,0,4,0,21,0,0,0,41,0,0,0,0,0,0,0,253,0,1,0,56,0,1,0,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Same shader as __shader_frag_wgsl[] but compiled as SPIRV.
|
||||||
|
// 'wgslc -o frag.spv frag.wgsl' + 'binary_to_compressed_c -u8 -nocompress frag.spv'
|
||||||
|
static const unsigned char __shader_frag_spirv[1392] =
|
||||||
|
{
|
||||||
|
3,2,35,7,0,3,1,0,1,0,23,0,60,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,11,0,6,0,48,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,0,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,9,0,4,0,0,0,51,0,0,0,109,
|
||||||
|
97,105,110,0,0,0,0,15,0,0,0,18,0,0,0,19,0,0,0,22,0,0,0,16,0,3,0,51,0,0,0,7,0,0,0,71,0,4,0,4,0,0,0,6,0,0,0,16,0,0,0,72,0,5,0,3,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,71,0,3,0,3,0,0,0,2,0,0,
|
||||||
|
0,71,0,4,0,1,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,1,0,0,0,33,0,0,0,0,0,0,0,71,0,3,0,1,0,0,0,24,0,0,0,71,0,4,0,8,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,8,0,0,0,33,0,0,0,1,0,0,0,71,0,4,0,11,0,0,
|
||||||
|
0,34,0,0,0,1,0,0,0,71,0,4,0,11,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,15,0,0,0,11,0,0,0,15,0,0,0,71,0,4,0,18,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,19,0,0,0,30,0,0,0,1,0,0,0,71,0,4,0,22,0,0,0,30,
|
||||||
|
0,0,0,0,0,0,0,21,0,4,0,6,0,0,0,32,0,0,0,0,0,0,0,23,0,4,0,5,0,0,0,6,0,0,0,4,0,0,0,43,0,4,0,6,0,0,0,7,0,0,0,5,0,0,0,28,0,4,0,4,0,0,0,5,0,0,0,7,0,0,0,30,0,3,0,3,0,0,0,4,0,0,0,32,0,4,0,
|
||||||
|
2,0,0,0,2,0,0,0,3,0,0,0,59,0,4,0,2,0,0,0,1,0,0,0,2,0,0,0,26,0,2,0,10,0,0,0,32,0,4,0,9,0,0,0,0,0,0,0,10,0,0,0,59,0,4,0,9,0,0,0,8,0,0,0,0,0,0,0,22,0,3,0,14,0,0,0,32,0,0,0,25,0,9,0,13,
|
||||||
|
0,0,0,14,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,32,0,4,0,12,0,0,0,0,0,0,0,13,0,0,0,59,0,4,0,12,0,0,0,11,0,0,0,0,0,0,0,23,0,4,0,17,0,0,0,14,0,0,0,4,0,0,0,32,0,4,0,16,
|
||||||
|
0,0,0,1,0,0,0,17,0,0,0,59,0,4,0,16,0,0,0,15,0,0,0,1,0,0,0,59,0,4,0,16,0,0,0,18,0,0,0,1,0,0,0,23,0,4,0,21,0,0,0,14,0,0,0,2,0,0,0,32,0,4,0,20,0,0,0,1,0,0,0,21,0,0,0,59,0,4,0,20,0,0,0,
|
||||||
|
19,0,0,0,1,0,0,0,32,0,4,0,23,0,0,0,3,0,0,0,17,0,0,0,59,0,4,0,23,0,0,0,22,0,0,0,3,0,0,0,30,0,5,0,25,0,0,0,17,0,0,0,17,0,0,0,21,0,0,0,33,0,4,0,27,0,0,0,17,0,0,0,25,0,0,0,27,0,3,0,34,
|
||||||
|
0,0,0,13,0,0,0,23,0,4,0,38,0,0,0,14,0,0,0,3,0,0,0,32,0,4,0,40,0,0,0,2,0,0,0,5,0,0,0,43,0,4,0,6,0,0,0,41,0,0,0,0,0,0,0,43,0,4,0,6,0,0,0,42,0,0,0,4,0,0,0,19,0,2,0,52,0,0,0,33,0,3,0,53,
|
||||||
|
0,0,0,52,0,0,0,54,0,5,0,17,0,0,0,24,0,0,0,0,0,0,0,27,0,0,0,55,0,3,0,25,0,0,0,26,0,0,0,248,0,2,0,28,0,0,0,81,0,5,0,17,0,0,0,29,0,0,0,26,0,0,0,1,0,0,0,61,0,5,0,13,0,0,0,30,0,0,0,11,0,
|
||||||
|
0,0,0,0,0,0,61,0,5,0,10,0,0,0,31,0,0,0,8,0,0,0,0,0,0,0,81,0,5,0,21,0,0,0,32,0,0,0,26,0,0,0,2,0,0,0,86,0,5,0,34,0,0,0,33,0,0,0,30,0,0,0,31,0,0,0,87,0,6,0,17,0,0,0,35,0,0,0,33,0,0,0,
|
||||||
|
32,0,0,0,0,0,0,0,133,0,5,0,17,0,0,0,36,0,0,0,29,0,0,0,35,0,0,0,79,0,8,0,38,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,65,0,6,0,40,0,0,0,39,0,0,0,1,0,0,0,41,0,0,0,42,0,
|
||||||
|
0,0,61,0,5,0,5,0,0,0,43,0,0,0,39,0,0,0,0,0,0,0,81,0,5,0,6,0,0,0,44,0,0,0,43,0,0,0,0,0,0,0,124,0,4,0,14,0,0,0,45,0,0,0,44,0,0,0,80,0,6,0,38,0,0,0,46,0,0,0,45,0,0,0,45,0,0,0,45,0,0,0,
|
||||||
|
12,0,7,0,38,0,0,0,47,0,0,0,48,0,0,0,26,0,0,0,37,0,0,0,46,0,0,0,81,0,5,0,14,0,0,0,49,0,0,0,36,0,0,0,3,0,0,0,80,0,5,0,17,0,0,0,50,0,0,0,47,0,0,0,49,0,0,0,254,0,2,0,50,0,0,0,56,0,1,0,
|
||||||
|
54,0,5,0,52,0,0,0,51,0,0,0,0,0,0,0,53,0,0,0,248,0,2,0,54,0,0,0,61,0,5,0,17,0,0,0,55,0,0,0,15,0,0,0,0,0,0,0,61,0,5,0,17,0,0,0,56,0,0,0,18,0,0,0,0,0,0,0,61,0,5,0,21,0,0,0,57,0,0,0,19,
|
||||||
|
0,0,0,0,0,0,0,80,0,6,0,25,0,0,0,58,0,0,0,55,0,0,0,56,0,0,0,57,0,0,0,57,0,5,0,17,0,0,0,59,0,0,0,24,0,0,0,58,0,0,0,62,0,4,0,22,0,0,0,59,0,0,0,0,0,0,0,253,0,1,0,56,0,1,0,
|
||||||
|
};
|
||||||
|
|
||||||
static void SafeRelease(ImDrawIdx*& res)
|
static void SafeRelease(ImDrawIdx*& res)
|
||||||
{
|
{
|
||||||
if (res)
|
if (res)
|
||||||
@@ -242,9 +302,11 @@ static void SafeRelease(WGPUShaderModule& res)
|
|||||||
}
|
}
|
||||||
static void SafeRelease(RenderResources& res)
|
static void SafeRelease(RenderResources& res)
|
||||||
{
|
{
|
||||||
SafeRelease(res.Sampler);
|
SafeRelease(res.SamplerLinear);
|
||||||
|
SafeRelease(res.SamplerNearest);
|
||||||
SafeRelease(res.Uniforms);
|
SafeRelease(res.Uniforms);
|
||||||
SafeRelease(res.CommonBindGroup);
|
SafeRelease(res.CommonBindGroupLinear);
|
||||||
|
SafeRelease(res.CommonBindGroupNearest);
|
||||||
SafeRelease(res.ImageBindGroupLayout);
|
SafeRelease(res.ImageBindGroupLayout);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -256,31 +318,62 @@ static void SafeRelease(FrameResources& res)
|
|||||||
SafeRelease(res.VertexBufferHost);
|
SafeRelease(res.VertexBufferHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const char* wgsl_source)
|
static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModuleWGSL(const char* wgsl_source)
|
||||||
{
|
{
|
||||||
ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
|
ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
|
||||||
|
IM_UNUSED(bd);
|
||||||
|
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
WGPUShaderSourceWGSL wgsl_desc = {};
|
WGPUShaderSourceWGSL wgsl_desc = {};
|
||||||
wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL;
|
wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL;
|
||||||
wgsl_desc.code = { wgsl_source, WGPU_STRLEN };
|
wgsl_desc.code = { wgsl_source, WGPU_STRLEN };
|
||||||
#else
|
|
||||||
WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
|
|
||||||
wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
|
|
||||||
wgsl_desc.code = wgsl_source;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
WGPUShaderModuleDescriptor desc = {};
|
WGPUShaderModuleDescriptor desc = {};
|
||||||
desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgsl_desc);
|
desc.nextInChain = (WGPUChainedStruct*)&wgsl_desc;
|
||||||
|
|
||||||
|
// Detect shader compilation errors by using an error scope.
|
||||||
|
// Flag to be passed into the validation callback `userdata1` pointer.
|
||||||
|
int validation_error = 0;
|
||||||
|
wgpuDevicePushErrorScope(bd->wgpuDevice, WGPUErrorFilter_Validation);
|
||||||
|
WGPUShaderModule module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc);
|
||||||
|
WGPUPopErrorScopeCallbackInfo pop_cb = {};
|
||||||
|
pop_cb.mode = WGPUCallbackMode_AllowSpontaneous;
|
||||||
|
pop_cb.callback = [](WGPUPopErrorScopeStatus, WGPUErrorType type, WGPUStringView, void* userdata1, void*)
|
||||||
|
{
|
||||||
|
if (type == WGPUErrorType_Validation)
|
||||||
|
*static_cast<int*>(userdata1) = 1;
|
||||||
|
};
|
||||||
|
pop_cb.userdata1 = &validation_error;
|
||||||
|
wgpuDevicePopErrorScope(bd->wgpuDevice, pop_cb);
|
||||||
|
|
||||||
|
WGPUProgrammableStageDescriptor stage_desc = {};
|
||||||
|
if (module && !validation_error)
|
||||||
|
{
|
||||||
|
stage_desc.module = module;
|
||||||
|
stage_desc.entryPoint = { "main", WGPU_STRLEN };
|
||||||
|
}
|
||||||
|
else if (module)
|
||||||
|
{
|
||||||
|
wgpuShaderModuleRelease(module);
|
||||||
|
}
|
||||||
|
return stage_desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModuleSPIRV(const void* spirv_binary, size_t spirv_length)
|
||||||
|
{
|
||||||
|
ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
|
||||||
|
|
||||||
|
WGPUShaderSourceSPIRV spirv_desc = {};
|
||||||
|
spirv_desc.chain.sType = WGPUSType_ShaderSourceSPIRV;
|
||||||
|
spirv_desc.code = (const uint32_t *)spirv_binary;
|
||||||
|
spirv_desc.codeSize = ((uint32_t)(spirv_length / 4));
|
||||||
|
|
||||||
|
WGPUShaderModuleDescriptor desc = {};
|
||||||
|
desc.nextInChain = (WGPUChainedStruct*)&spirv_desc;
|
||||||
|
|
||||||
WGPUProgrammableStageDescriptor stage_desc = {};
|
WGPUProgrammableStageDescriptor stage_desc = {};
|
||||||
stage_desc.module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc);
|
stage_desc.module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc);
|
||||||
|
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
stage_desc.entryPoint = { "main", WGPU_STRLEN };
|
stage_desc.entryPoint = { "main", WGPU_STRLEN };
|
||||||
#else
|
|
||||||
stage_desc.entryPoint = "main";
|
|
||||||
#endif
|
|
||||||
return stage_desc;
|
return stage_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,15 +448,19 @@ static void ImGui_ImplWGPU_SetupRenderState(ImDrawData* draw_data, WGPURenderPas
|
|||||||
wgpuRenderPassEncoderSetVertexBuffer(ctx, 0, fr->VertexBuffer, 0, fr->VertexBufferSize * sizeof(ImDrawVert));
|
wgpuRenderPassEncoderSetVertexBuffer(ctx, 0, fr->VertexBuffer, 0, fr->VertexBufferSize * sizeof(ImDrawVert));
|
||||||
wgpuRenderPassEncoderSetIndexBuffer(ctx, fr->IndexBuffer, sizeof(ImDrawIdx) == 2 ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32, 0, fr->IndexBufferSize * sizeof(ImDrawIdx));
|
wgpuRenderPassEncoderSetIndexBuffer(ctx, fr->IndexBuffer, sizeof(ImDrawIdx) == 2 ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32, 0, fr->IndexBufferSize * sizeof(ImDrawIdx));
|
||||||
wgpuRenderPassEncoderSetPipeline(ctx, bd->pipelineState);
|
wgpuRenderPassEncoderSetPipeline(ctx, bd->pipelineState);
|
||||||
wgpuRenderPassEncoderSetBindGroup(ctx, 0, bd->renderResources.CommonBindGroup, 0, nullptr);
|
wgpuRenderPassEncoderSetBindGroup(ctx, 0, bd->renderResources.CommonBindGroupLinear, 0, nullptr);
|
||||||
|
|
||||||
// Setup blend factor
|
// Setup blend factor
|
||||||
WGPUColor blend_color = { 0.f, 0.f, 0.f, 0.f };
|
WGPUColor blend_color = { 0.f, 0.f, 0.f, 0.f };
|
||||||
wgpuRenderPassEncoderSetBlendConstant(ctx, &blend_color);
|
wgpuRenderPassEncoderSetBlendConstant(ctx, &blend_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplWGPU_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplWGPU_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); wgpuRenderPassEncoderSetBindGroup(bd->RenderState->RenderPassEncoder, 0, bd->renderResources.CommonBindGroupLinear, 0, nullptr); }
|
||||||
|
static void ImGui_ImplWGPU_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); wgpuRenderPassEncoderSetBindGroup(bd->RenderState->RenderPassEncoder, 0, bd->renderResources.CommonBindGroupNearest, 0, nullptr); }
|
||||||
|
|
||||||
// Render function
|
// Render function
|
||||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
|
||||||
void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder)
|
void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder)
|
||||||
{
|
{
|
||||||
// Avoid rendering when minimized
|
// Avoid rendering when minimized
|
||||||
@@ -399,10 +496,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
WGPUBufferDescriptor vb_desc =
|
WGPUBufferDescriptor vb_desc =
|
||||||
{
|
{
|
||||||
nullptr,
|
nullptr,
|
||||||
"Dear ImGui Vertex buffer",
|
{ "Dear ImGui Vertex buffer", WGPU_STRLEN, },
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
WGPU_STRLEN,
|
|
||||||
#endif
|
|
||||||
WGPUBufferUsage_CopyDst | WGPUBufferUsage_Vertex,
|
WGPUBufferUsage_CopyDst | WGPUBufferUsage_Vertex,
|
||||||
MEMALIGN(fr->VertexBufferSize * sizeof(ImDrawVert), 4),
|
MEMALIGN(fr->VertexBufferSize * sizeof(ImDrawVert), 4),
|
||||||
false
|
false
|
||||||
@@ -426,10 +520,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
WGPUBufferDescriptor ib_desc =
|
WGPUBufferDescriptor ib_desc =
|
||||||
{
|
{
|
||||||
nullptr,
|
nullptr,
|
||||||
"Dear ImGui Index buffer",
|
{ "Dear ImGui Index buffer", WGPU_STRLEN, },
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
WGPU_STRLEN,
|
|
||||||
#endif
|
|
||||||
WGPUBufferUsage_CopyDst | WGPUBufferUsage_Index,
|
WGPUBufferUsage_CopyDst | WGPUBufferUsage_Index,
|
||||||
MEMALIGN(fr->IndexBufferSize * sizeof(ImDrawIdx), 4),
|
MEMALIGN(fr->IndexBufferSize * sizeof(ImDrawIdx), 4),
|
||||||
false
|
false
|
||||||
@@ -453,8 +544,8 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
}
|
}
|
||||||
int64_t vb_write_size = MEMALIGN((char*)vtx_dst - (char*)fr->VertexBufferHost, 4);
|
int64_t vb_write_size = MEMALIGN((char*)vtx_dst - (char*)fr->VertexBufferHost, 4);
|
||||||
int64_t ib_write_size = MEMALIGN((char*)idx_dst - (char*)fr->IndexBufferHost, 4);
|
int64_t ib_write_size = MEMALIGN((char*)idx_dst - (char*)fr->IndexBufferHost, 4);
|
||||||
wgpuQueueWriteBuffer(bd->defaultQueue, fr->VertexBuffer, 0, fr->VertexBufferHost, vb_write_size);
|
wgpuQueueWriteBuffer(bd->defaultQueue, fr->VertexBuffer, 0, fr->VertexBufferHost, (size_t)vb_write_size);
|
||||||
wgpuQueueWriteBuffer(bd->defaultQueue, fr->IndexBuffer, 0, fr->IndexBufferHost, ib_write_size);
|
wgpuQueueWriteBuffer(bd->defaultQueue, fr->IndexBuffer, 0, fr->IndexBufferHost, (size_t)ib_write_size);
|
||||||
|
|
||||||
// Setup desired render state
|
// Setup desired render state
|
||||||
ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
|
ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
|
||||||
@@ -464,7 +555,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
ImGui_ImplWGPU_RenderState render_state;
|
ImGui_ImplWGPU_RenderState render_state;
|
||||||
render_state.Device = bd->wgpuDevice;
|
render_state.Device = bd->wgpuDevice;
|
||||||
render_state.RenderPassEncoder = pass_encoder;
|
render_state.RenderPassEncoder = pass_encoder;
|
||||||
platform_io.Renderer_RenderState = &render_state;
|
platform_io.Renderer_RenderState = bd->RenderState = &render_state;
|
||||||
|
|
||||||
// Render command lists
|
// Render command lists
|
||||||
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
||||||
@@ -480,8 +571,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
if (pcmd->UserCallback != nullptr)
|
if (pcmd->UserCallback != nullptr)
|
||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
if (pcmd->UserCallback == ImGui_ImplWGPU_DrawCallback_ResetRenderState)
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
||||||
ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
|
ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(draw_list, pcmd);
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
@@ -492,12 +582,11 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
ImTextureID tex_id = pcmd->GetTexID();
|
ImTextureID tex_id = pcmd->GetTexID();
|
||||||
ImGuiID tex_id_hash = ImHashData(&tex_id, sizeof(tex_id), 0);
|
ImGuiID tex_id_hash = ImHashData(&tex_id, sizeof(tex_id), 0);
|
||||||
WGPUBindGroup bind_group = (WGPUBindGroup)bd->renderResources.ImageBindGroups.GetVoidPtr(tex_id_hash);
|
WGPUBindGroup bind_group = (WGPUBindGroup)bd->renderResources.ImageBindGroups.GetVoidPtr(tex_id_hash);
|
||||||
if (!bind_group)
|
if (!bind_group && tex_id != 0)
|
||||||
{
|
if ((bind_group = ImGui_ImplWGPU_CreateImageBindGroup(bd->renderResources.ImageBindGroupLayout, (WGPUTextureView)tex_id)) != 0)
|
||||||
bind_group = ImGui_ImplWGPU_CreateImageBindGroup(bd->renderResources.ImageBindGroupLayout, (WGPUTextureView)tex_id);
|
bd->renderResources.ImageBindGroups.SetVoidPtr(tex_id_hash, bind_group);
|
||||||
bd->renderResources.ImageBindGroups.SetVoidPtr(tex_id_hash, bind_group);
|
if (bind_group)
|
||||||
}
|
wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, (WGPUBindGroup)bind_group, 0, nullptr);
|
||||||
wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, (WGPUBindGroup)bind_group, 0, nullptr);
|
|
||||||
|
|
||||||
// Project scissor/clipping rectangles into framebuffer space
|
// 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_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
||||||
@@ -506,8 +595,8 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
// Clamp to viewport as wgpuRenderPassEncoderSetScissorRect() won't accept values that are off bounds
|
// Clamp to viewport as wgpuRenderPassEncoderSetScissorRect() won't accept values that are off bounds
|
||||||
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
||||||
if (clip_min.y < 0.0f) { clip_min.y = 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.x > (float)fb_width) { clip_max.x = (float)fb_width; }
|
||||||
if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; }
|
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)
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -529,24 +618,23 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
}
|
}
|
||||||
image_bind_groups.Data.resize(0);
|
image_bind_groups.Data.resize(0);
|
||||||
|
|
||||||
platform_io.Renderer_RenderState = nullptr;
|
platform_io.Renderer_RenderState = bd->RenderState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWGPU_DestroyTexture(ImTextureData* tex)
|
static void ImGui_ImplWGPU_DestroyTexture(ImTextureData* tex)
|
||||||
{
|
{
|
||||||
ImGui_ImplWGPU_Texture* backend_tex = (ImGui_ImplWGPU_Texture*)tex->BackendUserData;
|
if (ImGui_ImplWGPU_Texture* backend_tex = (ImGui_ImplWGPU_Texture*)tex->BackendUserData)
|
||||||
if (backend_tex == nullptr)
|
{
|
||||||
return;
|
IM_ASSERT(backend_tex->TextureView == (WGPUTextureView)(intptr_t)tex->TexID);
|
||||||
|
wgpuTextureViewRelease(backend_tex->TextureView);
|
||||||
|
wgpuTextureRelease(backend_tex->Texture);
|
||||||
|
IM_DELETE(backend_tex);
|
||||||
|
|
||||||
IM_ASSERT(backend_tex->TextureView == (WGPUTextureView)(intptr_t)tex->TexID);
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
wgpuTextureViewRelease(backend_tex->TextureView);
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
wgpuTextureRelease(backend_tex->Texture);
|
tex->BackendUserData = nullptr;
|
||||||
IM_DELETE(backend_tex);
|
}
|
||||||
|
|
||||||
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
|
||||||
tex->SetTexID(ImTextureID_Invalid);
|
|
||||||
tex->SetStatus(ImTextureStatus_Destroyed);
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
tex->BackendUserData = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex)
|
void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex)
|
||||||
@@ -562,11 +650,7 @@ void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex)
|
|||||||
|
|
||||||
// Create texture
|
// Create texture
|
||||||
WGPUTextureDescriptor tex_desc = {};
|
WGPUTextureDescriptor tex_desc = {};
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
tex_desc.label = { "Dear ImGui Texture", WGPU_STRLEN };
|
tex_desc.label = { "Dear ImGui Texture", WGPU_STRLEN };
|
||||||
#else
|
|
||||||
tex_desc.label = "Dear ImGui Texture";
|
|
||||||
#endif
|
|
||||||
tex_desc.dimension = WGPUTextureDimension_2D;
|
tex_desc.dimension = WGPUTextureDimension_2D;
|
||||||
tex_desc.size.width = tex->Width;
|
tex_desc.size.width = tex->Width;
|
||||||
tex_desc.size.height = tex->Height;
|
tex_desc.size.height = tex->Height;
|
||||||
@@ -607,20 +691,12 @@ void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex)
|
|||||||
|
|
||||||
// Update full texture or selected blocks. We only ever write to textures regions which have never been used before!
|
// Update full texture or selected blocks. We only ever write to textures regions which have never been used before!
|
||||||
// This backend choose to use tex->UpdateRect but you can use tex->Updates[] to upload individual regions.
|
// This backend choose to use tex->UpdateRect but you can use tex->Updates[] to upload individual regions.
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
WGPUTexelCopyTextureInfo dst_view = {};
|
WGPUTexelCopyTextureInfo dst_view = {};
|
||||||
#else
|
|
||||||
WGPUImageCopyTexture dst_view = {};
|
|
||||||
#endif
|
|
||||||
dst_view.texture = backend_tex->Texture;
|
dst_view.texture = backend_tex->Texture;
|
||||||
dst_view.mipLevel = 0;
|
dst_view.mipLevel = 0;
|
||||||
dst_view.origin = { (uint32_t)upload_x, (uint32_t)upload_y, 0 };
|
dst_view.origin = { (uint32_t)upload_x, (uint32_t)upload_y, 0 };
|
||||||
dst_view.aspect = WGPUTextureAspect_All;
|
dst_view.aspect = WGPUTextureAspect_All;
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
WGPUTexelCopyBufferLayout layout = {};
|
WGPUTexelCopyBufferLayout layout = {};
|
||||||
#else
|
|
||||||
WGPUTextureDataLayout layout = {};
|
|
||||||
#endif
|
|
||||||
layout.offset = 0;
|
layout.offset = 0;
|
||||||
layout.bytesPerRow = tex->Width * tex->BytesPerPixel;
|
layout.bytesPerRow = tex->Width * tex->BytesPerPixel;
|
||||||
layout.rowsPerImage = upload_h;
|
layout.rowsPerImage = upload_h;
|
||||||
@@ -638,10 +714,7 @@ static void ImGui_ImplWGPU_CreateUniformBuffer()
|
|||||||
WGPUBufferDescriptor ub_desc =
|
WGPUBufferDescriptor ub_desc =
|
||||||
{
|
{
|
||||||
nullptr,
|
nullptr,
|
||||||
"Dear ImGui Uniform buffer",
|
{ "Dear ImGui Uniform buffer", WGPU_STRLEN, },
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
WGPU_STRLEN,
|
|
||||||
#endif
|
|
||||||
WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform,
|
WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform,
|
||||||
MEMALIGN(sizeof(Uniforms), 16),
|
MEMALIGN(sizeof(Uniforms), 16),
|
||||||
false
|
false
|
||||||
@@ -698,14 +771,15 @@ bool ImGui_ImplWGPU_CreateDeviceObjects()
|
|||||||
graphics_pipeline_desc.layout = wgpuDeviceCreatePipelineLayout(bd->wgpuDevice, &layout_desc);
|
graphics_pipeline_desc.layout = wgpuDeviceCreatePipelineLayout(bd->wgpuDevice, &layout_desc);
|
||||||
|
|
||||||
// Create the vertex shader
|
// Create the vertex shader
|
||||||
WGPUProgrammableStageDescriptor vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_vert_wgsl);
|
WGPUProgrammableStageDescriptor vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModuleWGSL(__shader_vert_wgsl);
|
||||||
|
if (!vertex_shader_desc.module) vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModuleSPIRV(__shader_vert_spirv, sizeof(__shader_vert_spirv));
|
||||||
graphics_pipeline_desc.vertex.module = vertex_shader_desc.module;
|
graphics_pipeline_desc.vertex.module = vertex_shader_desc.module;
|
||||||
graphics_pipeline_desc.vertex.entryPoint = vertex_shader_desc.entryPoint;
|
graphics_pipeline_desc.vertex.entryPoint = vertex_shader_desc.entryPoint;
|
||||||
|
|
||||||
// Vertex input configuration
|
// Vertex input configuration
|
||||||
WGPUVertexAttribute attribute_desc[] =
|
WGPUVertexAttribute attribute_desc[] =
|
||||||
{
|
{
|
||||||
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
#if defined IMGUI_IMPL_WEBGPU_BACKEND_DAWN || defined IMGUI_IMPL_WEBGPU_BACKEND_WGVK
|
||||||
{ nullptr, WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, pos), 0 },
|
{ nullptr, WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, pos), 0 },
|
||||||
{ nullptr, WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, uv), 1 },
|
{ nullptr, WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, uv), 1 },
|
||||||
{ nullptr, WGPUVertexFormat_Unorm8x4, (uint64_t)offsetof(ImDrawVert, col), 2 },
|
{ nullptr, WGPUVertexFormat_Unorm8x4, (uint64_t)offsetof(ImDrawVert, col), 2 },
|
||||||
@@ -726,7 +800,8 @@ bool ImGui_ImplWGPU_CreateDeviceObjects()
|
|||||||
graphics_pipeline_desc.vertex.buffers = buffer_layouts;
|
graphics_pipeline_desc.vertex.buffers = buffer_layouts;
|
||||||
|
|
||||||
// Create the pixel shader
|
// Create the pixel shader
|
||||||
WGPUProgrammableStageDescriptor pixel_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_frag_wgsl);
|
WGPUProgrammableStageDescriptor pixel_shader_desc = ImGui_ImplWGPU_CreateShaderModuleWGSL(__shader_frag_wgsl);
|
||||||
|
if (!pixel_shader_desc.module) pixel_shader_desc = ImGui_ImplWGPU_CreateShaderModuleSPIRV(__shader_frag_spirv, sizeof(__shader_frag_spirv));
|
||||||
|
|
||||||
// Create the blending setup
|
// Create the blending setup
|
||||||
WGPUBlendState blend_state = {};
|
WGPUBlendState blend_state = {};
|
||||||
@@ -753,11 +828,7 @@ bool ImGui_ImplWGPU_CreateDeviceObjects()
|
|||||||
// Create depth-stencil State
|
// Create depth-stencil State
|
||||||
WGPUDepthStencilState depth_stencil_state = {};
|
WGPUDepthStencilState depth_stencil_state = {};
|
||||||
depth_stencil_state.format = bd->depthStencilFormat;
|
depth_stencil_state.format = bd->depthStencilFormat;
|
||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
depth_stencil_state.depthWriteEnabled = WGPUOptionalBool_False;
|
depth_stencil_state.depthWriteEnabled = WGPUOptionalBool_False;
|
||||||
#else
|
|
||||||
depth_stencil_state.depthWriteEnabled = false;
|
|
||||||
#endif
|
|
||||||
depth_stencil_state.depthCompare = WGPUCompareFunction_Always;
|
depth_stencil_state.depthCompare = WGPUCompareFunction_Always;
|
||||||
depth_stencil_state.stencilFront.compare = WGPUCompareFunction_Always;
|
depth_stencil_state.stencilFront.compare = WGPUCompareFunction_Always;
|
||||||
depth_stencil_state.stencilFront.failOp = WGPUStencilOperation_Keep;
|
depth_stencil_state.stencilFront.failOp = WGPUStencilOperation_Keep;
|
||||||
@@ -775,29 +846,35 @@ bool ImGui_ImplWGPU_CreateDeviceObjects()
|
|||||||
|
|
||||||
ImGui_ImplWGPU_CreateUniformBuffer();
|
ImGui_ImplWGPU_CreateUniformBuffer();
|
||||||
|
|
||||||
// Create sampler
|
// Create samplers (Linear/Nearest)
|
||||||
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
||||||
WGPUSamplerDescriptor sampler_desc = {};
|
WGPUSamplerDescriptor sampler_desc = {};
|
||||||
sampler_desc.minFilter = WGPUFilterMode_Linear;
|
|
||||||
sampler_desc.magFilter = WGPUFilterMode_Linear;
|
|
||||||
sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Linear;
|
|
||||||
sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
|
sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
|
||||||
sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
|
sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
|
||||||
sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
|
sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
|
||||||
sampler_desc.maxAnisotropy = 1;
|
sampler_desc.maxAnisotropy = 1;
|
||||||
bd->renderResources.Sampler = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc);
|
sampler_desc.minFilter = WGPUFilterMode_Linear;
|
||||||
|
sampler_desc.magFilter = WGPUFilterMode_Linear;
|
||||||
|
sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Linear;
|
||||||
|
bd->renderResources.SamplerLinear = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc);
|
||||||
|
sampler_desc.minFilter = WGPUFilterMode_Nearest;
|
||||||
|
sampler_desc.magFilter = WGPUFilterMode_Nearest;
|
||||||
|
sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Nearest;
|
||||||
|
bd->renderResources.SamplerNearest = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc);
|
||||||
|
|
||||||
// Create resource bind group
|
// Create resource bind groups (one per sampler, otherwise identical)
|
||||||
WGPUBindGroupEntry common_bg_entries[] =
|
WGPUBindGroupEntry common_bg_entries[] =
|
||||||
{
|
{
|
||||||
{ nullptr, 0, bd->renderResources.Uniforms, 0, MEMALIGN(sizeof(Uniforms), 16), 0, 0 },
|
{ nullptr, 0, bd->renderResources.Uniforms, 0, MEMALIGN(sizeof(Uniforms), 16), 0, 0 },
|
||||||
{ nullptr, 1, 0, 0, 0, bd->renderResources.Sampler, 0 },
|
{ nullptr, 1, 0, 0, 0, bd->renderResources.SamplerLinear, 0 },
|
||||||
};
|
};
|
||||||
WGPUBindGroupDescriptor common_bg_descriptor = {};
|
WGPUBindGroupDescriptor common_bg_descriptor = {};
|
||||||
common_bg_descriptor.layout = bg_layouts[0];
|
common_bg_descriptor.layout = bg_layouts[0];
|
||||||
common_bg_descriptor.entryCount = sizeof(common_bg_entries) / sizeof(WGPUBindGroupEntry);
|
common_bg_descriptor.entryCount = sizeof(common_bg_entries) / sizeof(WGPUBindGroupEntry);
|
||||||
common_bg_descriptor.entries = common_bg_entries;
|
common_bg_descriptor.entries = common_bg_entries;
|
||||||
bd->renderResources.CommonBindGroup = wgpuDeviceCreateBindGroup(bd->wgpuDevice, &common_bg_descriptor);
|
bd->renderResources.CommonBindGroupLinear = wgpuDeviceCreateBindGroup(bd->wgpuDevice, &common_bg_descriptor);
|
||||||
|
common_bg_entries[1].sampler = bd->renderResources.SamplerNearest;
|
||||||
|
bd->renderResources.CommonBindGroupNearest = wgpuDeviceCreateBindGroup(bd->wgpuDevice, &common_bg_descriptor);
|
||||||
bd->renderResources.ImageBindGroupLayout = bg_layouts[1];
|
bd->renderResources.ImageBindGroupLayout = bg_layouts[1];
|
||||||
|
|
||||||
SafeRelease(vertex_shader_desc.module);
|
SafeRelease(vertex_shader_desc.module);
|
||||||
@@ -835,18 +912,25 @@ bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info)
|
|||||||
// Setup backend capabilities flags
|
// Setup backend capabilities flags
|
||||||
ImGui_ImplWGPU_Data* bd = IM_NEW(ImGui_ImplWGPU_Data)();
|
ImGui_ImplWGPU_Data* bd = IM_NEW(ImGui_ImplWGPU_Data)();
|
||||||
io.BackendRendererUserData = (void*)bd;
|
io.BackendRendererUserData = (void*)bd;
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
#if defined(__EMSCRIPTEN__)
|
#if defined(__EMSCRIPTEN__)
|
||||||
io.BackendRendererName = "imgui_impl_webgpu_emscripten";
|
io.BackendRendererName = "imgui_impl_wgpu (Dawn, Emscripten)"; // compiled & linked using EMSCRIPTEN with "--use-port=emdawnwebgpu" flag
|
||||||
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
|
||||||
io.BackendRendererName = "imgui_impl_webgpu_dawn";
|
|
||||||
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
|
||||||
io.BackendRendererName = "imgui_impl_webgpu_wgpu";
|
|
||||||
#else
|
#else
|
||||||
io.BackendRendererName = "imgui_impl_webgpu";
|
io.BackendRendererName = "imgui_impl_wgpu (Dawn, Native)";
|
||||||
|
#endif
|
||||||
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
|
io.BackendRendererName = "imgui_impl_wgpu (WGPU, Native)";
|
||||||
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK)
|
||||||
|
io.BackendRendererName = "imgui_impl_wgpu (WGVK, Native)";
|
||||||
#endif
|
#endif
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplWGPU_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplWGPU_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplWGPU_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
bd->initInfo = *init_info;
|
bd->initInfo = *init_info;
|
||||||
bd->wgpuDevice = init_info->Device;
|
bd->wgpuDevice = init_info->Device;
|
||||||
bd->defaultQueue = wgpuDeviceGetQueue(bd->wgpuDevice);
|
bd->defaultQueue = wgpuDeviceGetQueue(bd->wgpuDevice);
|
||||||
@@ -855,11 +939,7 @@ bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info)
|
|||||||
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
||||||
bd->frameIndex = UINT_MAX;
|
bd->frameIndex = UINT_MAX;
|
||||||
|
|
||||||
bd->renderResources.Sampler = nullptr;
|
|
||||||
bd->renderResources.Uniforms = nullptr;
|
|
||||||
bd->renderResources.CommonBindGroup = nullptr;
|
|
||||||
bd->renderResources.ImageBindGroups.Data.reserve(100);
|
bd->renderResources.ImageBindGroups.Data.reserve(100);
|
||||||
bd->renderResources.ImageBindGroupLayout = nullptr;
|
|
||||||
|
|
||||||
// Create buffers with a default size (they will later be grown as needed)
|
// Create buffers with a default size (they will later be grown as needed)
|
||||||
bd->pFrameResources = new FrameResources[bd->numFramesInFlight];
|
bd->pFrameResources = new FrameResources[bd->numFramesInFlight];
|
||||||
@@ -882,6 +962,7 @@ void ImGui_ImplWGPU_Shutdown()
|
|||||||
ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
|
ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
ImGui_ImplWGPU_InvalidateDeviceObjects();
|
ImGui_ImplWGPU_InvalidateDeviceObjects();
|
||||||
delete[] bd->pFrameResources;
|
delete[] bd->pFrameResources;
|
||||||
@@ -894,6 +975,7 @@ void ImGui_ImplWGPU_Shutdown()
|
|||||||
io.BackendRendererName = nullptr;
|
io.BackendRendererName = nullptr;
|
||||||
io.BackendRendererUserData = nullptr;
|
io.BackendRendererUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures);
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -905,6 +987,176 @@ void ImGui_ImplWGPU_NewFrame()
|
|||||||
IM_ASSERT(0 && "ImGui_ImplWGPU_CreateDeviceObjects() failed!");
|
IM_ASSERT(0 && "ImGui_ImplWGPU_CreateDeviceObjects() failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Internal Helpers
|
||||||
|
// Those are currently used by our example applications.
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool ImGui_ImplWGPU_IsSurfaceStatusError(WGPUSurfaceGetCurrentTextureStatus status)
|
||||||
|
{
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK)
|
||||||
|
return (status == WGPUSurfaceGetCurrentTextureStatus_Error);
|
||||||
|
#else
|
||||||
|
return (status == WGPUSurfaceGetCurrentTextureStatus_OutOfMemory || status == WGPUSurfaceGetCurrentTextureStatus_DeviceLost);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplWGPU_IsSurfaceStatusSubOptimal(WGPUSurfaceGetCurrentTextureStatus status)
|
||||||
|
{
|
||||||
|
#if defined(__EMSCRIPTEN__) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
|
return (status == WGPUSurfaceGetCurrentTextureStatus_Timeout || status == WGPUSurfaceGetCurrentTextureStatus_Outdated || status == WGPUSurfaceGetCurrentTextureStatus_Lost);
|
||||||
|
#else
|
||||||
|
return (status == WGPUSurfaceGetCurrentTextureStatus_Timeout || status == WGPUSurfaceGetCurrentTextureStatus_Outdated || status == WGPUSurfaceGetCurrentTextureStatus_Lost || status == WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helpers to obtain a string
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK)
|
||||||
|
const char* ImGui_ImplWGPU_GetErrorTypeName(WGPUErrorType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case WGPUErrorType_Validation: return "Validation";
|
||||||
|
case WGPUErrorType_OutOfMemory: return "OutOfMemory";
|
||||||
|
case WGPUErrorType_Unknown: return "Unknown";
|
||||||
|
case WGPUErrorType_Internal: return "Internal";
|
||||||
|
default: return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const char* ImGui_ImplWGPU_GetDeviceLostReasonName(WGPUDeviceLostReason type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case WGPUDeviceLostReason_Unknown: return "Unknown";
|
||||||
|
case WGPUDeviceLostReason_Destroyed: return "Destroyed";
|
||||||
|
case WGPUDeviceLostReason_CallbackCancelled: return "CallbackCancelled";
|
||||||
|
case WGPUDeviceLostReason_FailedCreation: return "FailedCreation";
|
||||||
|
default: return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif !defined(__EMSCRIPTEN__)
|
||||||
|
const char* ImGui_ImplWGPU_GetLogLevelName(WGPULogLevel level)
|
||||||
|
{
|
||||||
|
switch (level)
|
||||||
|
{
|
||||||
|
case WGPULogLevel_Error: return "Error";
|
||||||
|
case WGPULogLevel_Warn: return "Warn";
|
||||||
|
case WGPULogLevel_Info: return "Info";
|
||||||
|
case WGPULogLevel_Debug: return "Debug";
|
||||||
|
case WGPULogLevel_Trace: return "Trace";
|
||||||
|
default: return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char* ImGui_ImplWGPU_GetBackendTypeName(WGPUBackendType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case WGPUBackendType_WebGPU: return "WebGPU";
|
||||||
|
case WGPUBackendType_D3D11: return "D3D11";
|
||||||
|
case WGPUBackendType_D3D12: return "D3D12";
|
||||||
|
case WGPUBackendType_Metal: return "Metal";
|
||||||
|
case WGPUBackendType_Vulkan: return "Vulkan";
|
||||||
|
case WGPUBackendType_OpenGL: return "OpenGL";
|
||||||
|
case WGPUBackendType_OpenGLES: return "OpenGLES";
|
||||||
|
default: return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* ImGui_ImplWGPU_GetAdapterTypeName(WGPUAdapterType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case WGPUAdapterType_DiscreteGPU: return "DiscreteGPU";
|
||||||
|
case WGPUAdapterType_IntegratedGPU: return "IntegratedGPU";
|
||||||
|
case WGPUAdapterType_CPU: return "CPU";
|
||||||
|
default: return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplWGPU_DebugPrintAdapterInfo(const WGPUAdapter& adapter)
|
||||||
|
{
|
||||||
|
WGPUAdapterInfo info = {};
|
||||||
|
wgpuAdapterGetInfo(adapter, &info);
|
||||||
|
printf("description: \"%.*s\"\n", (int)info.description.length, info.description.data);
|
||||||
|
printf("vendor: \"%.*s\", vendorID: %x\n", (int)info.vendor.length, info.vendor.data, info.vendorID);
|
||||||
|
printf("architecture: \"%.*s\"\n", (int) info.architecture.length, info.architecture.data);
|
||||||
|
printf("device: \"%.*s\", deviceID: %x\n", (int)info.device.length, info.device.data, info.deviceID);
|
||||||
|
printf("backendType: \"%s\"\n", ImGui_ImplWGPU_GetBackendTypeName(info.backendType));
|
||||||
|
printf("adapterType: \"%s\"\n", ImGui_ImplWGPU_GetAdapterTypeName(info.adapterType));
|
||||||
|
wgpuAdapterInfoFreeMembers(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
// MacOS specific: is necessary to compile with "-x objective-c++" flags
|
||||||
|
// (e.g. using cmake: set_source_files_properties(${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++") )
|
||||||
|
#include <TargetConditionals.h>
|
||||||
|
#if TARGET_OS_OSX
|
||||||
|
#include <Cocoa/Cocoa.h>
|
||||||
|
#include <QuartzCore/CAMetalLayer.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WGPUSurface ImGui_ImplWGPU_CreateWGPUSurfaceHelper(ImGui_ImplWGPU_CreateSurfaceInfo* info)
|
||||||
|
{
|
||||||
|
WGPUSurfaceDescriptor surface_descriptor = {};
|
||||||
|
WGPUSurface surface = {};
|
||||||
|
#if defined(__APPLE__) && TARGET_OS_OSX
|
||||||
|
if (strcmp(info->System, "cocoa") == 0)
|
||||||
|
{
|
||||||
|
IM_ASSERT(info->RawWindow != nullptr);
|
||||||
|
NSWindow* ns_window = (NSWindow*)info->RawWindow;
|
||||||
|
id metal_layer = [CAMetalLayer layer];
|
||||||
|
[ns_window.contentView setWantsLayer : YES] ;
|
||||||
|
[ns_window.contentView setLayer : metal_layer] ;
|
||||||
|
WGPUSurfaceSourceMetalLayer surface_src_metal = {};
|
||||||
|
surface_src_metal.chain.sType = WGPUSType_SurfaceSourceMetalLayer;
|
||||||
|
surface_src_metal.layer = metal_layer;
|
||||||
|
surface_descriptor.nextInChain = &surface_src_metal.chain;
|
||||||
|
surface = wgpuInstanceCreateSurface(info->Instance, &surface_descriptor);
|
||||||
|
}
|
||||||
|
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
||||||
|
if (strcmp(info->System, "wayland") == 0)
|
||||||
|
{
|
||||||
|
IM_ASSERT(info->RawDisplay != nullptr && info->RawSurface != nullptr);
|
||||||
|
WGPUSurfaceSourceWaylandSurface surface_src_wayland = {};
|
||||||
|
surface_src_wayland.chain.sType = WGPUSType_SurfaceSourceWaylandSurface;
|
||||||
|
surface_src_wayland.display = info->RawDisplay;
|
||||||
|
surface_src_wayland.surface = info->RawSurface;
|
||||||
|
surface_descriptor.nextInChain = &surface_src_wayland.chain;
|
||||||
|
surface = wgpuInstanceCreateSurface(info->Instance, &surface_descriptor);
|
||||||
|
}
|
||||||
|
else if (strcmp(info->System, "x11") == 0)
|
||||||
|
{
|
||||||
|
IM_ASSERT(info->RawDisplay != nullptr && info->RawWindow != nullptr);
|
||||||
|
WGPUSurfaceSourceXlibWindow surface_src_xlib = {};
|
||||||
|
surface_src_xlib.chain.sType = WGPUSType_SurfaceSourceXlibWindow;
|
||||||
|
surface_src_xlib.display = info->RawDisplay;
|
||||||
|
surface_src_xlib.window = (uint64_t)info->RawWindow;
|
||||||
|
surface_descriptor.nextInChain = &surface_src_xlib.chain;
|
||||||
|
surface = wgpuInstanceCreateSurface(info->Instance, &surface_descriptor);
|
||||||
|
}
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
if (strcmp(info->System, "win32") == 0)
|
||||||
|
{
|
||||||
|
IM_ASSERT(info->RawWindow != nullptr && info->RawInstance != nullptr);
|
||||||
|
WGPUSurfaceSourceWindowsHWND surface_src_hwnd = {};
|
||||||
|
surface_src_hwnd.chain.sType = WGPUSType_SurfaceSourceWindowsHWND;
|
||||||
|
surface_src_hwnd.hinstance = info->RawInstance;
|
||||||
|
surface_src_hwnd.hwnd = info->RawWindow;
|
||||||
|
surface_descriptor.nextInChain = &surface_src_hwnd.chain;
|
||||||
|
surface = wgpuInstanceCreateSurface(info->Instance, &surface_descriptor);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
IM_ASSERT(0 && "Unsupported WebGPU native platform!");
|
||||||
|
#endif
|
||||||
|
return surface;
|
||||||
|
}
|
||||||
|
#endif // #ifndef __EMSCRIPTEN__
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
// dear imgui: Renderer for WebGPU
|
// dear imgui: Renderer for WebGPU
|
||||||
// This needs to be used along with a Platform Binding (e.g. GLFW)
|
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL2, SDL3)
|
||||||
// (Please note that WebGPU is currently experimental, will not run on non-beta browsers, and may break.)
|
// (Please note that WebGPU is a recent API, may not be supported by all browser, and its ecosystem is generally a mess)
|
||||||
|
|
||||||
// Important note to dawn and/or wgpu users: when targeting native platforms (i.e. NOT emscripten),
|
// When targeting native platforms:
|
||||||
// one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided.
|
// - One of IMGUI_IMPL_WEBGPU_BACKEND_DAWN, IMGUI_IMPL_WEBGPU_BACKEND_WGPU or IMGUI_IMPL_WEBGPU_BACKEND_WGVK *must* be provided.
|
||||||
|
// When targeting Emscripten:
|
||||||
|
// - We now defaults to IMGUI_IMPL_WEBGPU_BACKEND_DAWN and requires Emscripten 4.0.10+, which correspond to using Emscripten '--use-port=emdawnwebgpu'.
|
||||||
|
// - Emscripten < 4.0.10 is not supported anymore (old '-sUSE_WEBGPU=1' option).
|
||||||
|
// - We can still define IMGUI_IMPL_WEBGPU_BACKEND_WGPU to use Emscripten '-s USE_WEBGPU=1' which is marked as obsolete by Emscripten.
|
||||||
// Add #define to your imconfig.h file, or as a compilation flag in your build system.
|
// Add #define to your imconfig.h file, or as a compilation flag in your build system.
|
||||||
// This requirement will be removed once WebGPU stabilizes and backends converge on a unified interface.
|
// This requirement may be removed once WebGPU stabilizes and backends converge on a unified interface.
|
||||||
//#define IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
//#define IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
||||||
//#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
//#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
//#define IMGUI_IMPL_WEBGPU_BACKEND_WGVK
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID/ImTextureRef!
|
// [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID/ImTextureRef!
|
||||||
@@ -29,12 +34,21 @@
|
|||||||
#include "imgui.h" // IMGUI_IMPL_API
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
#ifndef IMGUI_DISABLE
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
// Setup Emscripten default if not specified.
|
||||||
|
#if defined(__EMSCRIPTEN__) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
|
#include <emscripten/version.h>
|
||||||
|
#define IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <webgpu/webgpu.h>
|
#include <webgpu/webgpu.h>
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__)
|
||||||
|
#include <webgpu/wgpu.h> // WGPULogLevel
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialization data, for ImGui_ImplWGPU_Init()
|
// Initialization data, for ImGui_ImplWGPU_Init()
|
||||||
struct ImGui_ImplWGPU_InitInfo
|
struct ImGui_ImplWGPU_InitInfo
|
||||||
{
|
{
|
||||||
WGPUDevice Device;
|
WGPUDevice Device = nullptr;
|
||||||
int NumFramesInFlight = 3;
|
int NumFramesInFlight = 3;
|
||||||
WGPUTextureFormat RenderTargetFormat = WGPUTextureFormat_Undefined;
|
WGPUTextureFormat RenderTargetFormat = WGPUTextureFormat_Undefined;
|
||||||
WGPUTextureFormat DepthStencilFormat = WGPUTextureFormat_Undefined;
|
WGPUTextureFormat DepthStencilFormat = WGPUTextureFormat_Undefined;
|
||||||
@@ -58,7 +72,7 @@ IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURen
|
|||||||
IMGUI_IMPL_API bool ImGui_ImplWGPU_CreateDeviceObjects();
|
IMGUI_IMPL_API bool ImGui_ImplWGPU_CreateDeviceObjects();
|
||||||
IMGUI_IMPL_API void ImGui_ImplWGPU_InvalidateDeviceObjects();
|
IMGUI_IMPL_API void ImGui_ImplWGPU_InvalidateDeviceObjects();
|
||||||
|
|
||||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
IMGUI_IMPL_API void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex);
|
IMGUI_IMPL_API void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
// [BETA] Selected render state data shared with callbacks.
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
@@ -70,4 +84,38 @@ struct ImGui_ImplWGPU_RenderState
|
|||||||
WGPURenderPassEncoder RenderPassEncoder;
|
WGPURenderPassEncoder RenderPassEncoder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Internal Helpers
|
||||||
|
// Those are currently used by our example applications.
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// (Optional) Helper to wrap some of the Dawn/WGPU/Emscripten quirks
|
||||||
|
bool ImGui_ImplWGPU_IsSurfaceStatusError(WGPUSurfaceGetCurrentTextureStatus status);
|
||||||
|
bool ImGui_ImplWGPU_IsSurfaceStatusSubOptimal(WGPUSurfaceGetCurrentTextureStatus status); // Return whether the texture is suboptimal and may need to be recreated.
|
||||||
|
|
||||||
|
// (Optional) Helper for debugging/logging
|
||||||
|
void ImGui_ImplWGPU_DebugPrintAdapterInfo(const WGPUAdapter& adapter);
|
||||||
|
const char* ImGui_ImplWGPU_GetBackendTypeName(WGPUBackendType type);
|
||||||
|
const char* ImGui_ImplWGPU_GetAdapterTypeName(WGPUAdapterType type);
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
|
const char* ImGui_ImplWGPU_GetDeviceLostReasonName(WGPUDeviceLostReason type);
|
||||||
|
const char* ImGui_ImplWGPU_GetErrorTypeName(WGPUErrorType type);
|
||||||
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
|
const char* ImGui_ImplWGPU_GetLogLevelName(WGPULogLevel level);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// (Optional) Helper to create a surface on macOS/Wayland/X11/Window
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
|
struct ImGui_ImplWGPU_CreateSurfaceInfo
|
||||||
|
{
|
||||||
|
WGPUInstance Instance;
|
||||||
|
const char* System; // "cocoa" | "wayland" | "x11" | "win32"
|
||||||
|
void* RawWindow; // NSWindow* | 0 | Window | HWND
|
||||||
|
void* RawDisplay; // 0 | wl_display* | Display* | 0
|
||||||
|
void* RawSurface; // | wl_surface* | 0 | 0
|
||||||
|
void* RawInstance; // 0 | 0 | 0 | HINSTANCE
|
||||||
|
};
|
||||||
|
WGPUSurface ImGui_ImplWGPU_CreateWGPUSurfaceHelper(ImGui_ImplWGPU_CreateSurfaceInfo* info);
|
||||||
|
#endif // #ifndef __EMSCRIPTEN__
|
||||||
|
|
||||||
#endif // #ifndef IMGUI_DISABLE
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
|
|||||||
@@ -22,16 +22,24 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
// 2025-06-02: [Docking] WM_DPICHANGED also apply io.ConfigDpiScaleViewports for main viewport instead of letting it be done by application code.
|
// 2026-05-19: DPI: ImGui_ImplWin32_EnableDpiAwareness() helper uses SetProcessDpiAwarenessContext() instead of SetThreadDpiAwarenessContext(), fixes DPI scaling issues with e.g. OpenGL. (#9403)
|
||||||
|
// 2026-03-31: [Viewports] Fixed setting/getting size when viewports have OS decorations (e.g. io.ConfigViewportsNoDecoration = false) and process is running in Per-Monitor V2 DPI mode. (#8897)
|
||||||
|
// 2026-01-28: Inputs: Minor optimization not submitting gamepad input if packet number has not changed (reworked from 2025-09-23 attempt). (#9202, #8556)
|
||||||
|
// 2026-01-26: [Viewports] Fixed an issue from 1.90.5 where newly appearing windows that are not parented to the main viewport don't have task bar icon appear before the windows was explicited refocused. (#7354, #8669)
|
||||||
|
// 2025-12-03: Inputs: handle WM_IME_CHAR/WM_IME_COMPOSITION messages to support Unicode inputs on MBCS (non-Unicode) Windows. (#9099, #3653, #5961)
|
||||||
|
// 2025-10-19: Inputs: Revert previous change to allow for io.ClearInputKeys() on focus-out not losing gamepad state.
|
||||||
|
// 2025-09-23: Inputs: Minor optimization not submitting gamepad input if packet number has not changed.
|
||||||
|
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
|
// 2025-06-02: [Viewports] WM_DPICHANGED also apply io.ConfigDpiScaleViewports for main viewport instead of letting it be done by application code.
|
||||||
// 2025-04-30: Inputs: Fixed an issue where externally losing mouse capture (due to e.g. focus loss) would fail to claim it again the next subsequent click. (#8594)
|
// 2025-04-30: Inputs: Fixed an issue where externally losing mouse capture (due to e.g. focus loss) would fail to claim it again the next subsequent click. (#8594)
|
||||||
// 2025-03-26: [Docking] Viewports: fixed an issue when closing a window from the OS close button (with io.ConfigViewportsNoDecoration = false) while user code was discarding the 'bool* p_open = false' output from Begin(). Because we allowed the Win32 window to close early, Windows destroyed it and our imgui window became not visible even though user code was still submitting it.
|
// 2025-03-26: [Viewports] Viewports: fixed an issue when closing a window from the OS close button (with io.ConfigViewportsNoDecoration = false) while user code was discarding the 'bool* p_open = false' output from Begin(). Because we allowed the Win32 window to close early, Windows destroyed it and our imgui window became not visible even though user code was still submitting it.
|
||||||
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
||||||
// 2025-02-21: [Docking] WM_SETTINGCHANGE's SPI_SETWORKAREA message also triggers a refresh of monitor list. (#8415)
|
// 2025-02-21: [Viewports] WM_SETTINGCHANGE's SPI_SETWORKAREA message also triggers a refresh of monitor list. (#8415)
|
||||||
// 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
|
// 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
|
||||||
// 2024-11-21: [Docking] Fixed a crash when multiple processes are running with multi-viewports, caused by misusage of GetProp(). (#8162, #8069)
|
// 2024-11-21: [Viewports] Fixed a crash when multiple processes are running with multi-viewports, caused by misusage of GetProp(). (#8162, #8069)
|
||||||
// 2024-10-28: [Docking] Rely on property stored inside HWND to retrieve context/viewport, should facilitate attempt to use this for parallel contexts. (#8069)
|
// 2024-10-28: [Viewports] Rely on property stored inside HWND to retrieve context/viewport, should facilitate attempt to use this for parallel contexts. (#8069)
|
||||||
// 2024-09-16: [Docking] Inputs: fixed an issue where a viewport destroyed while clicking would hog mouse tracking and temporary lead to incorrect update of HoveredWindow. (#7971)
|
// 2024-09-16: [Viewports] Inputs: fixed an issue where a viewport destroyed while clicking would hog mouse tracking and temporary lead to incorrect update of HoveredWindow. (#7971)
|
||||||
// 2024-07-08: Inputs: Fixed ImGuiMod_Super being mapped to VK_APPS instead of VK_LWIN||VK_RWIN. (#7768)
|
// 2024-07-08: Inputs: Fixed ImGuiMod_Super being mapped to VK_APPS instead of VK_LWIN||VK_RWIN. (#7768)
|
||||||
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
||||||
// 2023-09-25: Inputs: Synthesize key-down event on key-up for VK_SNAPSHOT / ImGuiKey_PrintScreen as Windows doesn't emit it (same behavior as GLFW/SDL).
|
// 2023-09-25: Inputs: Synthesize key-down event on key-up for VK_SNAPSHOT / ImGuiKey_PrintScreen as Windows doesn't emit it (same behavior as GLFW/SDL).
|
||||||
@@ -102,6 +110,7 @@
|
|||||||
typedef DWORD(WINAPI* PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*);
|
typedef DWORD(WINAPI* PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*);
|
||||||
typedef DWORD(WINAPI* PFN_XInputGetState)(DWORD, XINPUT_STATE*);
|
typedef DWORD(WINAPI* PFN_XInputGetState)(DWORD, XINPUT_STATE*);
|
||||||
#endif
|
#endif
|
||||||
|
typedef BOOL(WINAPI* PFN_AdjustWindowRectExForDpi)(LPRECT, DWORD, BOOL, DWORD, UINT);
|
||||||
|
|
||||||
// Clang/GCC warnings with -Weverything
|
// Clang/GCC warnings with -Weverything
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
@@ -118,6 +127,7 @@ typedef DWORD(WINAPI* PFN_XInputGetState)(DWORD, XINPUT_STATE*);
|
|||||||
static void ImGui_ImplWin32_InitMultiViewportSupport(bool platform_has_own_dc);
|
static void ImGui_ImplWin32_InitMultiViewportSupport(bool platform_has_own_dc);
|
||||||
static void ImGui_ImplWin32_ShutdownMultiViewportSupport();
|
static void ImGui_ImplWin32_ShutdownMultiViewportSupport();
|
||||||
static void ImGui_ImplWin32_UpdateMonitors();
|
static void ImGui_ImplWin32_UpdateMonitors();
|
||||||
|
static bool ImGui_ImplWin32_IsDpiAwarenessPerMonitorAwareV2();
|
||||||
|
|
||||||
struct ImGui_ImplWin32_Data
|
struct ImGui_ImplWin32_Data
|
||||||
{
|
{
|
||||||
@@ -130,6 +140,8 @@ struct ImGui_ImplWin32_Data
|
|||||||
ImGuiMouseCursor LastMouseCursor;
|
ImGuiMouseCursor LastMouseCursor;
|
||||||
UINT32 KeyboardCodePage;
|
UINT32 KeyboardCodePage;
|
||||||
bool WantUpdateMonitors;
|
bool WantUpdateMonitors;
|
||||||
|
bool IsPerMonitorDpiAwareV2;
|
||||||
|
PFN_AdjustWindowRectExForDpi AdjustWindowRectExForDpi;
|
||||||
|
|
||||||
#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD
|
#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD
|
||||||
bool HasGamepad;
|
bool HasGamepad;
|
||||||
@@ -137,6 +149,7 @@ struct ImGui_ImplWin32_Data
|
|||||||
HMODULE XInputDLL;
|
HMODULE XInputDLL;
|
||||||
PFN_XInputGetCapabilities XInputGetCapabilities;
|
PFN_XInputGetCapabilities XInputGetCapabilities;
|
||||||
PFN_XInputGetState XInputGetState;
|
PFN_XInputGetState XInputGetState;
|
||||||
|
DWORD XInputPacketNumber;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ImGui_ImplWin32_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplWin32_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
@@ -186,6 +199,7 @@ static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc)
|
|||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||||
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
|
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional)
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasParentViewport; // We can honor viewport->ParentViewportId by applying the corresponding parent/child relationship at platform levle (optional)
|
||||||
|
|
||||||
bd->hWnd = (HWND)hwnd;
|
bd->hWnd = (HWND)hwnd;
|
||||||
bd->TicksPerSecond = perf_frequency;
|
bd->TicksPerSecond = perf_frequency;
|
||||||
@@ -205,6 +219,10 @@ static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc)
|
|||||||
::SetPropA(bd->hWnd, "IMGUI_CONTEXT", ImGui::GetCurrentContext());
|
::SetPropA(bd->hWnd, "IMGUI_CONTEXT", ImGui::GetCurrentContext());
|
||||||
ImGui_ImplWin32_InitMultiViewportSupport(platform_has_own_dc);
|
ImGui_ImplWin32_InitMultiViewportSupport(platform_has_own_dc);
|
||||||
|
|
||||||
|
if (HINSTANCE user32_dll = ::GetModuleHandleA("user32.dll"))
|
||||||
|
bd->AdjustWindowRectExForDpi = (PFN_AdjustWindowRectExForDpi)::GetProcAddress(user32_dll, "AdjustWindowRectExForDpi");
|
||||||
|
bd->IsPerMonitorDpiAwareV2 = ImGui_ImplWin32_IsDpiAwarenessPerMonitorAwareV2();
|
||||||
|
|
||||||
// Dynamically load XInput library
|
// Dynamically load XInput library
|
||||||
#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD
|
#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD
|
||||||
bd->WantUpdateHasGamepad = true;
|
bd->WantUpdateHasGamepad = true;
|
||||||
@@ -216,7 +234,7 @@ static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc)
|
|||||||
"xinput1_2.dll", // DirectX SDK
|
"xinput1_2.dll", // DirectX SDK
|
||||||
"xinput1_1.dll" // DirectX SDK
|
"xinput1_1.dll" // DirectX SDK
|
||||||
};
|
};
|
||||||
for (int n = 0; n < IM_ARRAYSIZE(xinput_dll_names); n++)
|
for (int n = 0; n < IM_COUNTOF(xinput_dll_names); n++)
|
||||||
if (HMODULE dll = ::LoadLibraryA(xinput_dll_names[n]))
|
if (HMODULE dll = ::LoadLibraryA(xinput_dll_names[n]))
|
||||||
{
|
{
|
||||||
bd->XInputDLL = dll;
|
bd->XInputDLL = dll;
|
||||||
@@ -245,6 +263,7 @@ void ImGui_ImplWin32_Shutdown()
|
|||||||
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
::SetPropA(bd->hWnd, "IMGUI_CONTEXT", nullptr);
|
::SetPropA(bd->hWnd, "IMGUI_CONTEXT", nullptr);
|
||||||
ImGui_ImplWin32_ShutdownMultiViewportSupport();
|
ImGui_ImplWin32_ShutdownMultiViewportSupport();
|
||||||
@@ -257,7 +276,8 @@ void ImGui_ImplWin32_Shutdown()
|
|||||||
|
|
||||||
io.BackendPlatformName = nullptr;
|
io.BackendPlatformName = nullptr;
|
||||||
io.BackendPlatformUserData = nullptr;
|
io.BackendPlatformUserData = nullptr;
|
||||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport | ImGuiBackendFlags_HasParentViewport);
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
IM_DELETE(bd);
|
IM_DELETE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,6 +435,9 @@ static void ImGui_ImplWin32_UpdateGamepads(ImGuiIO& io)
|
|||||||
if (!bd->HasGamepad || bd->XInputGetState == nullptr || bd->XInputGetState(0, &xinput_state) != ERROR_SUCCESS)
|
if (!bd->HasGamepad || bd->XInputGetState == nullptr || bd->XInputGetState(0, &xinput_state) != ERROR_SUCCESS)
|
||||||
return;
|
return;
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||||
|
if (bd->XInputPacketNumber != 0 && bd->XInputPacketNumber == xinput_state.dwPacketNumber)
|
||||||
|
return;
|
||||||
|
bd->XInputPacketNumber = xinput_state.dwPacketNumber;
|
||||||
|
|
||||||
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
|
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
|
||||||
#define MAP_BUTTON(KEY_NO, BUTTON_ENUM) { io.AddKeyEvent(KEY_NO, (gamepad.wButtons & BUTTON_ENUM) != 0); }
|
#define MAP_BUTTON(KEY_NO, BUTTON_ENUM) { io.AddKeyEvent(KEY_NO, (gamepad.wButtons & BUTTON_ENUM) != 0); }
|
||||||
@@ -498,7 +521,7 @@ void ImGui_ImplWin32_NewFrame()
|
|||||||
// Setup time step
|
// Setup time step
|
||||||
INT64 current_time = 0;
|
INT64 current_time = 0;
|
||||||
::QueryPerformanceCounter((LARGE_INTEGER*)¤t_time);
|
::QueryPerformanceCounter((LARGE_INTEGER*)¤t_time);
|
||||||
io.DeltaTime = (float)(current_time - bd->Time) / bd->TicksPerSecond;
|
io.DeltaTime = (float)((double)(current_time - bd->Time) / (double)bd->TicksPerSecond);
|
||||||
bd->Time = current_time;
|
bd->Time = current_time;
|
||||||
|
|
||||||
// Update OS mouse position
|
// Update OS mouse position
|
||||||
@@ -869,6 +892,9 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA
|
|||||||
case WM_SETFOCUS:
|
case WM_SETFOCUS:
|
||||||
case WM_KILLFOCUS:
|
case WM_KILLFOCUS:
|
||||||
io.AddFocusEvent(msg == WM_SETFOCUS);
|
io.AddFocusEvent(msg == WM_SETFOCUS);
|
||||||
|
#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD
|
||||||
|
bd->XInputPacketNumber = 0; // FIXME: Technically, calling io.ClearInputKeys() directly would require this as well.
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
case WM_INPUTLANGCHANGE:
|
case WM_INPUTLANGCHANGE:
|
||||||
ImGui_ImplWin32_UpdateKeyboardCodePage(io);
|
ImGui_ImplWin32_UpdateKeyboardCodePage(io);
|
||||||
@@ -883,10 +909,28 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
wchar_t wch = 0;
|
wchar_t wch = 0;
|
||||||
::MultiByteToWideChar(bd->KeyboardCodePage, MB_PRECOMPOSED, (char*)&wParam, 1, &wch, 1);
|
::MultiByteToWideChar(bd->KeyboardCodePage, MB_PRECOMPOSED, (char*)&wParam, 2, &wch, 1);
|
||||||
io.AddInputCharacter(wch);
|
io.AddInputCharacter(wch);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
case WM_IME_COMPOSITION:
|
||||||
|
{
|
||||||
|
// Handling WM_IME_COMPOSITION ensure that WM_IME_CHAR value is correct even for MBCS apps.
|
||||||
|
// (see #9099, #3653 and https://stackoverflow.com/questions/77450354 topics)
|
||||||
|
LRESULT result = ::DefWindowProcW(hwnd, msg, wParam, lParam);
|
||||||
|
return (lParam & GCS_RESULTSTR) ? 1 : result;
|
||||||
|
}
|
||||||
|
case WM_IME_CHAR:
|
||||||
|
if (::IsWindowUnicode(hwnd) == FALSE)
|
||||||
|
{
|
||||||
|
if (::IsDBCSLeadByte(HIBYTE(wParam)))
|
||||||
|
wParam = (WPARAM)MAKEWORD(HIBYTE(wParam), LOBYTE(wParam));
|
||||||
|
wchar_t wch = 0;
|
||||||
|
::MultiByteToWideChar(bd->KeyboardCodePage, MB_PRECOMPOSED, (char*)&wParam, 2, &wch, 1);
|
||||||
|
io.AddInputCharacterUTF16(wch);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
case WM_SETCURSOR:
|
case WM_SETCURSOR:
|
||||||
// This is required to restore cursor when transitioning from e.g resize borders to client area.
|
// This is required to restore cursor when transitioning from e.g resize borders to client area.
|
||||||
if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor(io, bd->LastMouseCursor))
|
if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor(io, bd->LastMouseCursor))
|
||||||
@@ -907,6 +951,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA
|
|||||||
return 0;
|
return 0;
|
||||||
case WM_DPICHANGED:
|
case WM_DPICHANGED:
|
||||||
{
|
{
|
||||||
|
// FIXME-DPI: see SDL3's WM_GETDPISCALEDSIZE handler.
|
||||||
const RECT* suggested_rect = (RECT*)lParam;
|
const RECT* suggested_rect = (RECT*)lParam;
|
||||||
if (io.ConfigDpiScaleViewports)
|
if (io.ConfigDpiScaleViewports)
|
||||||
::SetWindowPos(hwnd, nullptr, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
|
::SetWindowPos(hwnd, nullptr, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
@@ -924,7 +969,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA
|
|||||||
// - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps.
|
// - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps.
|
||||||
// - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc.
|
// - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc.
|
||||||
// but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime,
|
// but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime,
|
||||||
// neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies.
|
// neither of which we want to require the user to have. So we dynamically select and load those functions to avoid dependencies.
|
||||||
//---------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------
|
||||||
// This is the scheme successfully used by GLFW (from which we borrowed some of the code) and other apps aiming to be highly portable.
|
// This is the scheme successfully used by GLFW (from which we borrowed some of the code) and other apps aiming to be highly portable.
|
||||||
// ImGui_ImplWin32_EnableDpiAwareness() is just a helper called by main.cpp, we don't call it automatically.
|
// ImGui_ImplWin32_EnableDpiAwareness() is just a helper called by main.cpp, we don't call it automatically.
|
||||||
@@ -969,9 +1014,12 @@ DECLARE_HANDLE(DPI_AWARENESS_CONTEXT);
|
|||||||
#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
||||||
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (DPI_AWARENESS_CONTEXT)-4
|
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (DPI_AWARENESS_CONTEXT)-4
|
||||||
#endif
|
#endif
|
||||||
typedef HRESULT(WINAPI* PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS); // Shcore.lib + dll, Windows 8.1+
|
typedef HRESULT(WINAPI* PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS); // Shcore.lib + dll, Windows 8.1+
|
||||||
typedef HRESULT(WINAPI* PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); // Shcore.lib + dll, Windows 8.1+
|
typedef HRESULT(WINAPI* PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); // Shcore.lib + dll, Windows 8.1+
|
||||||
typedef DPI_AWARENESS_CONTEXT(WINAPI* PFN_SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); // User32.lib + dll, Windows 10 v1607+ (Creators Update)
|
typedef DPI_AWARENESS_CONTEXT(WINAPI* PFN_SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); // User32.lib + dll, Windows 10 v1607+ (Creators Update)
|
||||||
|
typedef BOOL (WINAPI* PFN_SetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); // User32.lib + dll, Windows 10 v1703+ (Creators Update)
|
||||||
|
typedef DPI_AWARENESS_CONTEXT(WINAPI* PFN_GetThreadDpiAwarenessContext)(); // "
|
||||||
|
typedef BOOL(WINAPI* PFN_AreDpiAwarenessContextsEqual)(DPI_AWARENESS_CONTEXT, DPI_AWARENESS_CONTEXT); // "
|
||||||
|
|
||||||
// Helper function to enable DPI awareness without setting up a manifest
|
// Helper function to enable DPI awareness without setting up a manifest
|
||||||
void ImGui_ImplWin32_EnableDpiAwareness()
|
void ImGui_ImplWin32_EnableDpiAwareness()
|
||||||
@@ -983,7 +1031,12 @@ void ImGui_ImplWin32_EnableDpiAwareness()
|
|||||||
if (_IsWindows10OrGreater())
|
if (_IsWindows10OrGreater())
|
||||||
{
|
{
|
||||||
static HINSTANCE user32_dll = ::LoadLibraryA("user32.dll"); // Reference counted per-process
|
static HINSTANCE user32_dll = ::LoadLibraryA("user32.dll"); // Reference counted per-process
|
||||||
if (PFN_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContextFn = (PFN_SetThreadDpiAwarenessContext)::GetProcAddress(user32_dll, "SetThreadDpiAwarenessContext"))
|
if (PFN_SetProcessDpiAwarenessContext SetProcessDpiAwarenessContextFn = (PFN_SetProcessDpiAwarenessContext)::GetProcAddress(user32_dll, "SetProcessDpiAwarenessContext")) // Windows 10 v1703+
|
||||||
|
{
|
||||||
|
SetProcessDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PFN_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContextFn = (PFN_SetThreadDpiAwarenessContext)::GetProcAddress(user32_dll, "SetThreadDpiAwarenessContext")) // Windows 10 v1607+
|
||||||
{
|
{
|
||||||
SetThreadDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
SetThreadDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||||
return;
|
return;
|
||||||
@@ -1003,6 +1056,18 @@ void ImGui_ImplWin32_EnableDpiAwareness()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplWin32_IsDpiAwarenessPerMonitorAwareV2()
|
||||||
|
{
|
||||||
|
if (!_IsWindows10OrGreater())
|
||||||
|
return false;
|
||||||
|
static HINSTANCE user32_dll = ::GetModuleHandleA("user32.dll");
|
||||||
|
PFN_GetThreadDpiAwarenessContext GetThreadDpiAwarenessContextFn = (PFN_GetThreadDpiAwarenessContext)::GetProcAddress(user32_dll, "GetThreadDpiAwarenessContext");
|
||||||
|
PFN_AreDpiAwarenessContextsEqual AreDpiAwarenessContextsEqualFn = (PFN_AreDpiAwarenessContextsEqual)::GetProcAddress(user32_dll, "AreDpiAwarenessContextsEqual");
|
||||||
|
if (GetThreadDpiAwarenessContextFn && AreDpiAwarenessContextsEqualFn)
|
||||||
|
return AreDpiAwarenessContextsEqualFn(GetThreadDpiAwarenessContextFn(), DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) != 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(NOGDI)
|
#if defined(_MSC_VER) && !defined(NOGDI)
|
||||||
#pragma comment(lib, "gdi32") // Link with gdi32.lib for GetDeviceCaps(). MinGW will require linking with '-lgdi32'
|
#pragma comment(lib, "gdi32") // Link with gdi32.lib for GetDeviceCaps(). MinGW will require linking with '-lgdi32'
|
||||||
#endif
|
#endif
|
||||||
@@ -1020,7 +1085,7 @@ float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor)
|
|||||||
{
|
{
|
||||||
GetDpiForMonitorFn((HMONITOR)monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi);
|
GetDpiForMonitorFn((HMONITOR)monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi);
|
||||||
IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert!
|
IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert!
|
||||||
return xdpi / 96.0f;
|
return (float)xdpi / 96.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef NOGDI
|
#ifndef NOGDI
|
||||||
@@ -1030,7 +1095,7 @@ float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor)
|
|||||||
IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert!
|
IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert!
|
||||||
::ReleaseDC(nullptr, dc);
|
::ReleaseDC(nullptr, dc);
|
||||||
#endif
|
#endif
|
||||||
return xdpi / 96.0f;
|
return (float)xdpi / 96.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd)
|
float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd)
|
||||||
@@ -1114,14 +1179,25 @@ static void ImGui_ImplWin32_GetWin32StyleFromViewportFlags(ImGuiViewportFlags fl
|
|||||||
*out_ex_style |= WS_EX_TOPMOST;
|
*out_ex_style |= WS_EX_TOPMOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HWND ImGui_ImplWin32_GetHwndFromViewportID(ImGuiID viewport_id)
|
static HWND ImGui_ImplWin32_GetHwndFromViewport(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
if (viewport_id != 0)
|
if (viewport != nullptr)
|
||||||
if (ImGuiViewport* viewport = ImGui::FindViewportByID(viewport_id))
|
return (HWND)viewport->PlatformHandle;
|
||||||
return (HWND)viewport->PlatformHandle;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplWin32_AdjustWindowRect(ImGuiViewport* viewport, RECT* rect, DWORD style, DWORD ex_style)
|
||||||
|
{
|
||||||
|
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
||||||
|
if (bd->AdjustWindowRectExForDpi && bd->IsPerMonitorDpiAwareV2)
|
||||||
|
{
|
||||||
|
UINT dpi = (UINT)(viewport->DpiScale * 96.0f + 0.5f);
|
||||||
|
if (dpi != 0 && bd->AdjustWindowRectExForDpi(rect, style, FALSE, ex_style, dpi))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
::AdjustWindowRectEx(rect, style, FALSE, ex_style);
|
||||||
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplWin32_ViewportData* vd = IM_NEW(ImGui_ImplWin32_ViewportData)();
|
ImGui_ImplWin32_ViewportData* vd = IM_NEW(ImGui_ImplWin32_ViewportData)();
|
||||||
@@ -1129,11 +1205,11 @@ static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
// Select style and parent window
|
// Select style and parent window
|
||||||
ImGui_ImplWin32_GetWin32StyleFromViewportFlags(viewport->Flags, &vd->DwStyle, &vd->DwExStyle);
|
ImGui_ImplWin32_GetWin32StyleFromViewportFlags(viewport->Flags, &vd->DwStyle, &vd->DwExStyle);
|
||||||
vd->HwndParent = ImGui_ImplWin32_GetHwndFromViewportID(viewport->ParentViewportId);
|
vd->HwndParent = ImGui_ImplWin32_GetHwndFromViewport(viewport->ParentViewport);
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
||||||
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle);
|
ImGui_ImplWin32_AdjustWindowRect(viewport, &rect, vd->DwStyle, vd->DwExStyle);
|
||||||
vd->Hwnd = ::CreateWindowExW(
|
vd->Hwnd = ::CreateWindowExW(
|
||||||
vd->DwExStyle, L"ImGui Platform", L"Untitled", vd->DwStyle, // Style, class name, window name
|
vd->DwExStyle, L"ImGui Platform", L"Untitled", vd->DwStyle, // Style, class name, window name
|
||||||
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, // Window area
|
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, // Window area
|
||||||
@@ -1170,9 +1246,10 @@ static void ImGui_ImplWin32_ShowWindow(ImGuiViewport* viewport)
|
|||||||
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(vd->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
|
|
||||||
// ShowParent() also brings parent to front, which is not always desirable,
|
// ShowParent() even with SW_SHOWNA also brings parent to front, which is not always desirable,
|
||||||
// so we temporarily disable parenting. (#7354)
|
// so we temporarily disable parenting. (#7354, #8669)
|
||||||
if (vd->HwndParent != NULL)
|
bool avoid_bringing_parent_to_front = vd->HwndParent != NULL && (viewport->Flags & (ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoTaskBarIcon)) != 0;
|
||||||
|
if (avoid_bringing_parent_to_front)
|
||||||
::SetWindowLongPtr(vd->Hwnd, GWLP_HWNDPARENT, (LONG_PTR)nullptr);
|
::SetWindowLongPtr(vd->Hwnd, GWLP_HWNDPARENT, (LONG_PTR)nullptr);
|
||||||
|
|
||||||
if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
|
if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
|
||||||
@@ -1181,7 +1258,7 @@ static void ImGui_ImplWin32_ShowWindow(ImGuiViewport* viewport)
|
|||||||
::ShowWindow(vd->Hwnd, SW_SHOW);
|
::ShowWindow(vd->Hwnd, SW_SHOW);
|
||||||
|
|
||||||
// Restore
|
// Restore
|
||||||
if (vd->HwndParent != NULL)
|
if (avoid_bringing_parent_to_front)
|
||||||
::SetWindowLongPtr(vd->Hwnd, GWLP_HWNDPARENT, (LONG_PTR)vd->HwndParent);
|
::SetWindowLongPtr(vd->Hwnd, GWLP_HWNDPARENT, (LONG_PTR)vd->HwndParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1192,7 +1269,7 @@ static void ImGui_ImplWin32_UpdateWindow(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
// Update Win32 parent if it changed _after_ creation
|
// Update Win32 parent if it changed _after_ creation
|
||||||
// Unlike style settings derived from configuration flags, this is more likely to change for advanced apps that are manipulating ParentViewportID manually.
|
// Unlike style settings derived from configuration flags, this is more likely to change for advanced apps that are manipulating ParentViewportID manually.
|
||||||
HWND new_parent = ImGui_ImplWin32_GetHwndFromViewportID(viewport->ParentViewportId);
|
HWND new_parent = ImGui_ImplWin32_GetHwndFromViewport(viewport->ParentViewport);
|
||||||
if (new_parent != vd->HwndParent)
|
if (new_parent != vd->HwndParent)
|
||||||
{
|
{
|
||||||
// Win32 windows can either have a "Parent" (for WS_CHILD window) or an "Owner" (which among other thing keeps window above its owner).
|
// Win32 windows can either have a "Parent" (for WS_CHILD window) or an "Owner" (which among other thing keeps window above its owner).
|
||||||
@@ -1225,7 +1302,7 @@ static void ImGui_ImplWin32_UpdateWindow(ImGuiViewport* viewport)
|
|||||||
::SetWindowLong(vd->Hwnd, GWL_STYLE, vd->DwStyle);
|
::SetWindowLong(vd->Hwnd, GWL_STYLE, vd->DwStyle);
|
||||||
::SetWindowLong(vd->Hwnd, GWL_EXSTYLE, vd->DwExStyle);
|
::SetWindowLong(vd->Hwnd, GWL_EXSTYLE, vd->DwExStyle);
|
||||||
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
||||||
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle); // Client to Screen
|
ImGui_ImplWin32_AdjustWindowRect(viewport, &rect, vd->DwStyle, vd->DwExStyle); // Client to Screen
|
||||||
::SetWindowPos(vd->Hwnd, insert_after, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, swp_flag | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
::SetWindowPos(vd->Hwnd, insert_after, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, swp_flag | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
||||||
::ShowWindow(vd->Hwnd, SW_SHOWNA); // This is necessary when we alter the style
|
::ShowWindow(vd->Hwnd, SW_SHOWNA); // This is necessary when we alter the style
|
||||||
viewport->PlatformRequestMove = viewport->PlatformRequestResize = true;
|
viewport->PlatformRequestMove = viewport->PlatformRequestResize = true;
|
||||||
@@ -1255,7 +1332,7 @@ static void ImGui_ImplWin32_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
|
|||||||
RECT rect = { (LONG)pos.x, (LONG)pos.y, (LONG)pos.x, (LONG)pos.y };
|
RECT rect = { (LONG)pos.x, (LONG)pos.y, (LONG)pos.x, (LONG)pos.y };
|
||||||
if (viewport->Flags & ImGuiViewportFlags_OwnedByApp)
|
if (viewport->Flags & ImGuiViewportFlags_OwnedByApp)
|
||||||
ImGui_ImplWin32_UpdateWin32StyleFromWindow(viewport); // Not our window, poll style before using
|
ImGui_ImplWin32_UpdateWin32StyleFromWindow(viewport); // Not our window, poll style before using
|
||||||
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle);
|
ImGui_ImplWin32_AdjustWindowRect(viewport, &rect, vd->DwStyle, vd->DwExStyle);
|
||||||
::SetWindowPos(vd->Hwnd, nullptr, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
|
::SetWindowPos(vd->Hwnd, nullptr, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1275,7 +1352,7 @@ static void ImGui_ImplWin32_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|||||||
RECT rect = { 0, 0, (LONG)size.x, (LONG)size.y };
|
RECT rect = { 0, 0, (LONG)size.x, (LONG)size.y };
|
||||||
if (viewport->Flags & ImGuiViewportFlags_OwnedByApp)
|
if (viewport->Flags & ImGuiViewportFlags_OwnedByApp)
|
||||||
ImGui_ImplWin32_UpdateWin32StyleFromWindow(viewport); // Not our window, poll style before using
|
ImGui_ImplWin32_UpdateWin32StyleFromWindow(viewport); // Not our window, poll style before using
|
||||||
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle); // Client to Screen
|
ImGui_ImplWin32_AdjustWindowRect(viewport, &rect, vd->DwStyle, vd->DwExStyle); // Client to Screen
|
||||||
::SetWindowPos(vd->Hwnd, nullptr, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
|
::SetWindowPos(vd->Hwnd, nullptr, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1367,7 +1444,7 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd,
|
|||||||
// Allow secondary viewport WndProc to be called regardless of current context
|
// Allow secondary viewport WndProc to be called regardless of current context
|
||||||
ImGuiContext* ctx = (ImGuiContext*)::GetPropA(hWnd, "IMGUI_CONTEXT");
|
ImGuiContext* ctx = (ImGuiContext*)::GetPropA(hWnd, "IMGUI_CONTEXT");
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return DefWindowProc(hWnd, msg, wParam, lParam); // unlike ImGui_ImplWin32_WndProcHandler() we are called directly by Windows, we can't just return 0.
|
return ::DefWindowProcW(hWnd, msg, wParam, lParam); // unlike ImGui_ImplWin32_WndProcHandler() we are called directly by Windows, we can't just return 0.
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO(ctx);
|
ImGuiIO& io = ImGui::GetIO(ctx);
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(ctx);
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(ctx);
|
||||||
@@ -1402,7 +1479,7 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
result = DefWindowProc(hWnd, msg, wParam, lParam);
|
result = ::DefWindowProcW(hWnd, msg, wParam, lParam);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd);
|
|||||||
IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown();
|
IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown();
|
||||||
IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame();
|
IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame();
|
||||||
|
|
||||||
// Win32 message handler your application need to call.
|
// Win32 message handler your application needs to call.
|
||||||
// - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on <windows.h> from this helper.
|
// - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on <windows.h> from this helper.
|
||||||
// - You should COPY the line below into your .cpp code to forward declare the function and then you can call it.
|
// - You should COPY the line below into your .cpp code to forward declare the function and then you can call it.
|
||||||
// - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE.
|
// - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE.
|
||||||
@@ -41,7 +41,7 @@ extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg
|
|||||||
// - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps.
|
// - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps.
|
||||||
// - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc.
|
// - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc.
|
||||||
// but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime,
|
// but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime,
|
||||||
// neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies.
|
// neither of which we want to require the user to have. So we dynamically select and load those functions to avoid dependencies.
|
||||||
IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness();
|
IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness();
|
||||||
IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd
|
IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd
|
||||||
IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor
|
IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ Instructions to rebuild imgui_impl_sdlgpu3_shaders.h
|
|||||||
xcrun -sdk macosx metallib -o vertex.metallib -c vertex.ir
|
xcrun -sdk macosx metallib -o vertex.metallib -c vertex.ir
|
||||||
xcrun -sdk macosx metallib -o fragment.metallib -c fragment.ir
|
xcrun -sdk macosx metallib -o fragment.metallib -c fragment.ir
|
||||||
|
|
||||||
|
note: use .metal outputs for updating msl_vertex / msl_fragment variables, and use .metallib outputs for metallib_vertex / metallib_fragment variables
|
||||||
|
|
||||||
Proceed to step 4
|
Proceed to step 4
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
layout(location = 0) out vec4 fColor;
|
layout(location = 0) out vec4 fColor;
|
||||||
|
|
||||||
layout(set=0, binding=0) uniform sampler2D sTexture;
|
layout(set=0, binding=0) uniform texture2D _Texture;
|
||||||
|
layout(set=1, binding=0) uniform sampler _Sampler;
|
||||||
|
|
||||||
layout(location = 0) in struct {
|
layout(location = 0) in struct {
|
||||||
vec4 Color;
|
vec4 Color;
|
||||||
@@ -10,5 +11,5 @@ layout(location = 0) in struct {
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fColor = In.Color * texture(sTexture, In.UV.st);
|
fColor = In.Color * texture(sampler2D(_Texture, _Sampler), In.UV.st);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ List of Renderer Backends:
|
|||||||
imgui_impl_dx11.cpp ; DirectX11
|
imgui_impl_dx11.cpp ; DirectX11
|
||||||
imgui_impl_dx12.cpp ; DirectX12
|
imgui_impl_dx12.cpp ; DirectX12
|
||||||
imgui_impl_metal.mm ; Metal (ObjC or C++)
|
imgui_impl_metal.mm ; Metal (ObjC or C++)
|
||||||
|
imgui_impl_metal4.mm ; Metal 4 (ObjC or C++)
|
||||||
imgui_impl_opengl2.cpp ; OpenGL 2 (legacy fixed pipeline. Don't use with modern OpenGL code!)
|
imgui_impl_opengl2.cpp ; OpenGL 2 (legacy fixed pipeline. Don't use with modern OpenGL code!)
|
||||||
imgui_impl_opengl3.cpp ; OpenGL 3/4, OpenGL ES 2/3, WebGL
|
imgui_impl_opengl3.cpp ; OpenGL 3/4, OpenGL ES 2/3, WebGL
|
||||||
imgui_impl_sdlgpu3.cpp ; SDL_GPU (portable 3D graphics API of SDL3)
|
imgui_impl_sdlgpu3.cpp ; SDL_GPU (portable 3D graphics API of SDL3)
|
||||||
@@ -100,6 +101,7 @@ List of Renderer Backends:
|
|||||||
List of high-level Frameworks Backends (combining Platform + Renderer):
|
List of high-level Frameworks Backends (combining Platform + Renderer):
|
||||||
|
|
||||||
imgui_impl_allegro5.cpp
|
imgui_impl_allegro5.cpp
|
||||||
|
imgui_impl_null.cpp
|
||||||
|
|
||||||
Emscripten is also supported!
|
Emscripten is also supported!
|
||||||
The SDL2+GL, SDL3+GL, GLFW+GL and GLFW+WebGPU examples are all ready to build and run with Emscripten.
|
The SDL2+GL, SDL3+GL, GLFW+GL and GLFW+WebGPU examples are all ready to build and run with Emscripten.
|
||||||
@@ -182,6 +184,7 @@ The Platform backends in impl_impl_XXX.cpp files contain many implementations.
|
|||||||
- `ImGuiBackendFlags_HasSetMousePos`: supports io.WantSetMousePos requests to reposition the OS mouse position (only used if io.ConfigNavMoveSetMousePos is set).
|
- `ImGuiBackendFlags_HasSetMousePos`: supports io.WantSetMousePos requests to reposition the OS mouse position (only used if io.ConfigNavMoveSetMousePos is set).
|
||||||
- `ImGuiBackendFlags_PlatformHasViewports` supports multiple viewports. (multi-viewports only)
|
- `ImGuiBackendFlags_PlatformHasViewports` supports multiple viewports. (multi-viewports only)
|
||||||
- `ImGuiBackendFlags_HasMouseHoveredViewport` supports calling io.AddMouseViewportEvent() with the viewport under the mouse. IF POSSIBLE, ignore viewports with the ImGuiViewportFlags_NoInputs flag. If this cannot be done, Dear ImGui needs to use a flawed heuristic to find the viewport under mouse position, as it doesn't know about foreign windows. (multi-viewports only)
|
- `ImGuiBackendFlags_HasMouseHoveredViewport` supports calling io.AddMouseViewportEvent() with the viewport under the mouse. IF POSSIBLE, ignore viewports with the ImGuiViewportFlags_NoInputs flag. If this cannot be done, Dear ImGui needs to use a flawed heuristic to find the viewport under mouse position, as it doesn't know about foreign windows. (multi-viewports only)
|
||||||
|
- `ImGuiBackendFlags_HasParentViewport` supports honoring viewport->ParentViewportId value, by applying the corresponding parent/child relation at the Platform level.
|
||||||
|
|
||||||
**In your `ImGui_ImplXXX_NewFrame()` function:**
|
**In your `ImGui_ImplXXX_NewFrame()` function:**
|
||||||
- Set `io.DeltaTime` to the time elapsed (in seconds) since last frame.
|
- Set `io.DeltaTime` to the time elapsed (in seconds) since last frame.
|
||||||
@@ -254,8 +257,8 @@ void MyImGuiBackend_RenderDrawData(ImDrawData* draw_data)
|
|||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||||
if (pcmd->UserCallback)
|
if (pcmd->UserCallback)
|
||||||
{
|
{
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
if (pcmd->UserCallback == platform_io.DrawCallback_ResetRenderState)
|
||||||
MyEngineSetupenderState();
|
MyEngineSetupSenderState();
|
||||||
else
|
else
|
||||||
pcmd->UserCallback(cmd_list, pcmd);
|
pcmd->UserCallback(cmd_list, pcmd);
|
||||||
}
|
}
|
||||||
@@ -336,7 +339,7 @@ void MyImGuiBackend_UpdateTexture(ImTextureData* tex)
|
|||||||
{
|
{
|
||||||
// Create texture based on tex->Width, tex->Height.
|
// Create texture based on tex->Width, tex->Height.
|
||||||
// - Most backends only support tex->Format == ImTextureFormat_RGBA32.
|
// - Most backends only support tex->Format == ImTextureFormat_RGBA32.
|
||||||
// - Backends for particularly memory constrainted platforms may support tex->Format == ImTextureFormat_Alpha8.
|
// - Backends for particularly memory constrained platforms may support tex->Format == ImTextureFormat_Alpha8.
|
||||||
|
|
||||||
// Upload all texture pixels
|
// Upload all texture pixels
|
||||||
// - Read from our CPU-side copy of the texture and copy to your graphics API.
|
// - Read from our CPU-side copy of the texture and copy to your graphics API.
|
||||||
|
|||||||
1127
docs/CHANGELOG.txt
1127
docs/CHANGELOG.txt
File diff suppressed because it is too large
Load Diff
@@ -72,7 +72,7 @@ OSX + OpenGL2 example. <BR>
|
|||||||
You may prefer to use the GLFW Or SDL backends, which will also support Windows and Linux.)
|
You may prefer to use the GLFW Or SDL backends, which will also support Windows and Linux.)
|
||||||
|
|
||||||
[example_glfw_wgpu/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_wgpu/) <BR>
|
[example_glfw_wgpu/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_wgpu/) <BR>
|
||||||
GLFW + WebGPU example. Supports Emscripten (web) or Dawn (desktop) <BR>
|
GLFW + WebGPU example. Supports Emscripten (web), Dawn (native), WGPU (native). <BR>
|
||||||
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_wgpu.cpp
|
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_wgpu.cpp
|
||||||
Note that the 'example_glfw_opengl3' and 'example_sdl2_opengl3' examples also supports Emscripten!
|
Note that the 'example_glfw_opengl3' and 'example_sdl2_opengl3' examples also supports Emscripten!
|
||||||
|
|
||||||
@@ -109,9 +109,11 @@ Note that GLUT/FreeGLUT is largely obsolete software, prefer using GLFW or SDL.
|
|||||||
|
|
||||||
[example_null/](https://github.com/ocornut/imgui/blob/master/examples/example_null/) <BR>
|
[example_null/](https://github.com/ocornut/imgui/blob/master/examples/example_null/) <BR>
|
||||||
Null example, compile and link imgui, create context, run headless with no inputs and no graphics output. <BR>
|
Null example, compile and link imgui, create context, run headless with no inputs and no graphics output. <BR>
|
||||||
= main.cpp <BR>
|
= main.cpp + imgui_impl_null.cpp<BR>
|
||||||
This is used to quickly test compilation of core imgui files in as many setups as possible.
|
This is used to quickly test compilation of core imgui files in as many setups as possible.
|
||||||
Because this application doesn't create a window nor a graphic context, there's no graphics output.
|
Because this application doesn't create a window nor a graphic context, there's no graphics output.
|
||||||
|
Please note that imgui_impl_null itself is a rather empty backend. We provide it for consistency but
|
||||||
|
it is similarly easy to create a skeleton application without the null backend.
|
||||||
|
|
||||||
[example_sdl2_directx11/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_directx11/) <BR>
|
[example_sdl2_directx11/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_directx11/) <BR>
|
||||||
SDL2 + DirectX11 example, Windows only. <BR>
|
SDL2 + DirectX11 example, Windows only. <BR>
|
||||||
@@ -149,10 +151,23 @@ SDL2 (Win32, Mac, Linux, etc.) + Vulkan example. <BR>
|
|||||||
This is quite long and tedious, because: Vulkan. <BR>
|
This is quite long and tedious, because: Vulkan. <BR>
|
||||||
For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
|
For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
|
||||||
|
|
||||||
|
[example_sdl2_wgpu/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_wgpu/) <BR>
|
||||||
|
SDL2 + WebGPU example. Supports Emscripten (web), Dawn (native), WGPU (native). <BR>
|
||||||
|
= main.cpp + imgui_impl_sdl2.cpp + imgui_impl_wgpu.cpp
|
||||||
|
(note that the 'example_sdl2_opengl3' example also supports Emscripten!)
|
||||||
|
|
||||||
|
[example_sdl3_directx11/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_directx11/) <BR>
|
||||||
|
SDL3 + DirectX11 examples, Windows only. <BR>
|
||||||
|
= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_dx11.cpp <BR>
|
||||||
|
|
||||||
[example_sdl3_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_metal/) <BR>
|
[example_sdl3_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_metal/) <BR>
|
||||||
SDL3 + Metal example (Mac). <BR>
|
SDL3 + Metal example, Mac only. <BR>
|
||||||
= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_metal.mm <BR>
|
= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_metal.mm <BR>
|
||||||
|
|
||||||
|
[example_sdl3_metal4/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_metal/) <BR>
|
||||||
|
SDL3 + Metal4 example, Mac only. <BR>
|
||||||
|
= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_metal4.mm <BR>
|
||||||
|
|
||||||
[example_sdl3_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_opengl3/) <BR>
|
[example_sdl3_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_opengl3/) <BR>
|
||||||
SDL3 (Win32, Mac, Linux, etc.) + OpenGL3+/ES2/ES3 example. <BR>
|
SDL3 (Win32, Mac, Linux, etc.) + OpenGL3+/ES2/ES3 example. <BR>
|
||||||
= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_opengl3.cpp <BR>
|
= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_opengl3.cpp <BR>
|
||||||
@@ -173,6 +188,11 @@ SDL3 (Win32, Mac, Linux, etc.) + Vulkan example. <BR>
|
|||||||
This is quite long and tedious, because: Vulkan. <BR>
|
This is quite long and tedious, because: Vulkan. <BR>
|
||||||
For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
|
For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
|
||||||
|
|
||||||
|
[example_sdl3_wgpu/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_wgpu/) <BR>
|
||||||
|
SDL3 + WebGPU example. Supports Emscripten (web), Dawn (native), WGPU (native). <BR>
|
||||||
|
= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_wgpu.cpp
|
||||||
|
(note that the 'example_sdl3_opengl3' example also supports Emscripten!)
|
||||||
|
|
||||||
[example_win32_directx9/](https://github.com/ocornut/imgui/blob/master/examples/example_win32_directx9/) <BR>
|
[example_win32_directx9/](https://github.com/ocornut/imgui/blob/master/examples/example_win32_directx9/) <BR>
|
||||||
DirectX9 example, Windows only. <BR>
|
DirectX9 example, Windows only. <BR>
|
||||||
= main.cpp + imgui_impl_win32.cpp + imgui_impl_dx9.cpp
|
= main.cpp + imgui_impl_win32.cpp + imgui_impl_dx9.cpp
|
||||||
|
|||||||
198
docs/FAQ.md
198
docs/FAQ.md
@@ -13,6 +13,7 @@ or view this file with any Markdown viewer.
|
|||||||
:---------------------------------------------------------- |
|
:---------------------------------------------------------- |
|
||||||
| [Where is the documentation?](#q-where-is-the-documentation) |
|
| [Where is the documentation?](#q-where-is-the-documentation) |
|
||||||
| [What is this library called?](#q-what-is-this-library-called) |
|
| [What is this library called?](#q-what-is-this-library-called) |
|
||||||
|
| [What is the difference between Dear ImGui and traditional UI toolkits?](#q-what-is-the-difference-between-dear-imgui-and-traditional-ui-toolkits) |
|
||||||
| [Which version should I get?](#q-which-version-should-i-get) |
|
| [Which version should I get?](#q-which-version-should-i-get) |
|
||||||
| **Q&A: Integration** |
|
| **Q&A: Integration** |
|
||||||
| **[How to get started?](#q-how-to-get-started)** |
|
| **[How to get started?](#q-how-to-get-started)** |
|
||||||
@@ -24,7 +25,7 @@ or view this file with any Markdown viewer.
|
|||||||
| [I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around...](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-clipping-or-disappearing-when-i-move-windows-around) |
|
| [I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around...](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-clipping-or-disappearing-when-i-move-windows-around) |
|
||||||
| [I integrated Dear ImGui in my engine and some elements are displaying outside their expected windows boundaries...](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-displaying-outside-their-expected-windows-boundaries) |
|
| [I integrated Dear ImGui in my engine and some elements are displaying outside their expected windows boundaries...](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-displaying-outside-their-expected-windows-boundaries) |
|
||||||
| **Q&A: Usage** |
|
| **Q&A: Usage** |
|
||||||
| **[About the ID Stack system..<br>Why is my widget not reacting when I click on it?<br>Why is the wrong widget reacting when I click on one?<br>How can I have widgets with an empty label?<br>How can I have multiple widgets with the same label?<br>How can I have multiple windows with the same label?](#q-about-the-id-stack-system)** |
|
| **[About the ID Stack system...](#q-about-the-id-stack-system)**<br>**[How can I have multiple widgets with the same label?](#q-how-can-i-have-multiple-widgets-with-the-same-label) (using `##` or `PushID()`)**<br>**[How can I have widgets with an empty label?](#q-how-can-i-have-widgets-with-an-empty-label) (using `##`)**<br>**[How can I animate the label of an existing widget?](#q-how-can-i-change-the-label-of-an-existing-widget) (using `###`)**<br>**[General description of the label and ID Stack system.](#general-description-of-the-label-and-id-stack-system)** |
|
||||||
| [How can I display an image?](#q-how-can-i-display-an-image)<br>[What are ImTextureID/ImTextureRef?](#q-what-are-imtextureidimtextureref)|
|
| [How can I display an image?](#q-how-can-i-display-an-image)<br>[What are ImTextureID/ImTextureRef?](#q-what-are-imtextureidimtextureref)|
|
||||||
| [How can I use maths operators with ImVec2?](#q-how-can-i-use-maths-operators-with-imvec2) |
|
| [How can I use maths operators with ImVec2?](#q-how-can-i-use-maths-operators-with-imvec2) |
|
||||||
| [How can I use my own maths types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-maths-types-instead-of-imvec2imvec4) |
|
| [How can I use my own maths types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-maths-types-instead-of-imvec2imvec4) |
|
||||||
@@ -54,6 +55,7 @@ or view this file with any Markdown viewer.
|
|||||||
- Handy [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) guide to integrate Dear ImGui in an existing application.
|
- Handy [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) guide to integrate Dear ImGui in an existing application.
|
||||||
- 20+ standalone example applications using e.g. OpenGL/DirectX are provided in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder to explain how to integrate Dear ImGui with your own engine/application. You can run those applications and explore them.
|
- 20+ standalone example applications using e.g. OpenGL/DirectX are provided in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder to explain how to integrate Dear ImGui with your own engine/application. You can run those applications and explore them.
|
||||||
- See demo code in [imgui_demo.cpp](https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp) and particularly the `ImGui::ShowDemoWindow()` function. The demo covers most features of Dear ImGui, so you can read the code and see its output.
|
- See demo code in [imgui_demo.cpp](https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp) and particularly the `ImGui::ShowDemoWindow()` function. The demo covers most features of Dear ImGui, so you can read the code and see its output.
|
||||||
|
- See pthom's online [imgui_explorer](https://pthom.github.io/imgui_explorer) which is a web version of the demo with a source code browser.
|
||||||
- See documentation: [Backends](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md), [Examples](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md), [Fonts](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md).
|
- See documentation: [Backends](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md), [Examples](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md), [Fonts](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md).
|
||||||
- See documentation and comments at the top of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) + general API comments in [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h).
|
- See documentation and comments at the top of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) + general API comments in [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h).
|
||||||
- The [Glossary](https://github.com/ocornut/imgui/wiki/Glossary) page may be useful.
|
- The [Glossary](https://github.com/ocornut/imgui/wiki/Glossary) page may be useful.
|
||||||
@@ -75,6 +77,60 @@ or view this file with any Markdown viewer.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### Q: What is the difference between Dear ImGui and traditional UI toolkits?
|
||||||
|
|
||||||
|
Here's a very simplified comparison between the approach taken by Dear ImGui vs traditional toolkits:
|
||||||
|
|
||||||
|
| Dear ImGui | Qt/GTK/WPF... |
|
||||||
|
|--------------------------|--------------------------|
|
||||||
|
| UI fully issued on every update. | UI issued once then later modified. |
|
||||||
|
| UI layout is fully dynamic and can change at any time.<BR>UI is generally emitted programmatically, which empowers reflecting a dynamic set of data. | UI layout is mostly static.<BR>UI may be emitted programmatically or from data created by offline tools. UI need extra code to evolve, which is often tedious and error-prone if it needs to be reflecting dynamic data and systems. |
|
||||||
|
| Application can submit UI based on arbitrary logic and then forget about it. | Application needs more bookkeeping of UI elements. |
|
||||||
|
| UI library stores minimal amounts of data. At one point in time, it typically doesn't know or remember which other widgets are displayed and which widgets are coming next. As a result, certain layout features (alignment, resizing) are not as easy to implement or require ad-hoc code. | UI library stores entire widgets tree and state. UI library can use this retained data to easily layout things. |
|
||||||
|
| UI code may be added anywhere.<BR>You can even create UI to edit a local variable! | UI code needs to be added in dedicated spots. |
|
||||||
|
| UI layout/logic/action/data bindings are all nearby in the code. | UI layout/logic/action/data bindings in distinct functions, files or formats. |
|
||||||
|
| Data is naturally always synchronized. | Use callback/signal/slot for synchronizing data (error-prone). |
|
||||||
|
| API is simple and easy to learn. In particular, doing basic things is very easy. | API is more complex and specialized. |
|
||||||
|
| API is low-level (raw language types). | API are higher-level (more abstractions, advanced language features). |
|
||||||
|
| Less fancy look and feel. | Standard look and feel. |
|
||||||
|
| Compile yourself. Easy to debug, hack, modify, study. | Mostly use precompiled libraries. Compiling, modifying or studying is daunting if not impossible. |
|
||||||
|
| Run on every platform. | Run on limited desktop platforms. |
|
||||||
|
|
||||||
|
Idiomatic Dear ImGui code:
|
||||||
|
```cpp
|
||||||
|
if (ImGui::Button("Save"))
|
||||||
|
MySaveFunction();
|
||||||
|
|
||||||
|
ImGui::SliderFloat("Slider", &m_MyValue, 0.0f, 1.0f);
|
||||||
|
```
|
||||||
|
Idiomatic code with traditional toolkit:
|
||||||
|
```cpp
|
||||||
|
UiButton* button = new UiButton("Save");
|
||||||
|
button->OnClick = &MySaveFunction;
|
||||||
|
parent->Add(button);
|
||||||
|
|
||||||
|
UiSlider* slider = new UiSlider("Slider");
|
||||||
|
slider->SetRange(0.0f, 1.0f);
|
||||||
|
slider->BindData<float>(&m_MyValue);
|
||||||
|
parent->Add(slider);
|
||||||
|
```
|
||||||
|
This is only meant to give you a intuitive feeling of the main differences, but pros & cons go deeper than that.
|
||||||
|
|
||||||
|
Some of those properties are typically associated to the umbrella term "IMGUI", but the term has no simple and well-agreed definition. There are many erroneous statements and misunderstandings with what IMGUI means. It is partly caused by the fact that most popular IMGUI implementations (including Dear ImGui) have originated from game industry needs and have targeted specific use cases, causing people to conflate IMGUI properties with what a specific library does. However, it is perfectly possible to implement an IMGUI library that would have very different properties than e.g. Dear ImGui. My take on defining what an IMGUI is:
|
||||||
|
|
||||||
|
**IMGUI refers to the API: literally the interface between the application and the UI system.**
|
||||||
|
- An IMGUI API favors the application code owning its data and being the single source of truth for it.
|
||||||
|
- An IMGUI API tries to minimize the application having to retain/manage data related to the UI system.
|
||||||
|
- An IMGUI API tries to minimize the UI system having to retain/manage data related to the application.
|
||||||
|
- Synchronization between application data and UI data is natural and less error-prone.
|
||||||
|
|
||||||
|
**IMGUI does NOT refer to the implementation. Whatever happens inside the UI library code doesn't matter.**
|
||||||
|
<BR>Also see: [Links to many articles about the IMGUI paradigm](https://github.com/ocornut/imgui/wiki/#about-the-imgui-paradigm).
|
||||||
|
|
||||||
|
##### [Return to Index](#index)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Q: Which version should I get?
|
### Q: Which version should I get?
|
||||||
I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported.
|
I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported.
|
||||||
|
|
||||||
@@ -207,15 +263,19 @@ ctx->RSSetScissorRects(1, &r);
|
|||||||
|
|
||||||
# Q&A: Usage
|
# Q&A: Usage
|
||||||
|
|
||||||
### Q: About the ID Stack system...
|
## Q: About the ID Stack system...
|
||||||
### Q: Why is my widget not reacting when I click on it?
|
|
||||||
### Q: Why is the wrong widget reacting when I click on one?
|
|
||||||
### Q: How can I have widgets with an empty label?
|
|
||||||
### Q: How can I have multiple widgets with the same label?
|
|
||||||
### Q: How can I have multiple windows with the same label?
|
|
||||||
|
|
||||||
**USING THE SAME LABEL+ID IS THE MOST COMMON USER MISTAKE!**
|
**USING THE SAME LABEL+ID IS THE MOST COMMON USER MISTAKE!**
|
||||||
<br>**USING AN EMPTY LABEL IS THE SAME AS USING THE SAME LABEL AS YOUR PARENT WIDGET!**
|
<br>**USING AN EMPTY LABEL IS THE SAME AS USING THE SAME LABEL AS YOUR PARENT WIDGET!**
|
||||||
|
<br>Read the questions in this section for a more general understand of how labels and ID works in Dear ImGui.
|
||||||
|
|
||||||
|
TL;DR;
|
||||||
|
- Widgets labels are also used to compute Widgets unique identifiers.
|
||||||
|
- Unique identifiers are hashes of the label + of the parent scope (e.g. parent window or parent tree node labels).
|
||||||
|
- You can use `PushID()` to append to the identifier without making it visible.
|
||||||
|
- You can use `"##something"` in a label to append to the identifier without making it visible.
|
||||||
|
- You can use `"###something"` in a label to make the identifier ignore the visible part.
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td><img src="https://github.com/user-attachments/assets/776a8315-1164-4178-9a8c-df52e0ff28aa"></td>
|
<td><img src="https://github.com/user-attachments/assets/776a8315-1164-4178-9a8c-df52e0ff28aa"></td>
|
||||||
@@ -246,16 +306,99 @@ ImGui::End();
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
A primer on labels and the ID Stack...
|
### Q: How can I have multiple widgets with the same label?
|
||||||
|
|
||||||
|
A. When widgets are in a same scope and finite, you can use a `"##something"` suffix which will be part of the identifier but not visible as a label.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
Button("Play"); // Label = "Play", ID = hash of ("MyWindow", "Play")
|
||||||
|
Button("Play##foo1"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo1") // Different from other buttons
|
||||||
|
Button("Play##foo2"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo2") // Different from other buttons
|
||||||
|
```
|
||||||
|
|
||||||
|
B. More generally, e.g. in loops, you can use `PushID()/PopID()` to push a prefix which will be part of the identifier.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// Using PushID() with a string
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
MyObject* obj = Objects[i];
|
||||||
|
PushID(obj->Name);
|
||||||
|
Button("Click"); // Label = "Click", ID = hash of ("Window", obj->Name, "Click")
|
||||||
|
PopID();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// Using PushID() with an index
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
PushID(i);
|
||||||
|
Button("Click"); // Label = "Click", ID = hash of ("Window", i, "Click")
|
||||||
|
PopID();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Q: How can I have widgets with an empty label?
|
||||||
|
|
||||||
|
If you want to completely hide the label, but still need an ID:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
Checkbox("##On", &b); // Label = "", ID = hash of (..., "##On") // No visible label, just a checkbox!
|
||||||
|
```
|
||||||
|
##### [Return to Index](#index)
|
||||||
|
|
||||||
|
### Q: How can I make a label dynamic?
|
||||||
|
|
||||||
|
Dear ImGui is very dynamic so you can submit different widgets every frame.
|
||||||
|
However, in order to preserve widget state (eg. which tree node is open; which button is focused) the library internaly refers to their unique ID.
|
||||||
|
|
||||||
|
Occasionally you might want to change a label while preserving a constant ID. This allows you to change/animate labels while persisting associated state.
|
||||||
|
For example, you may want to include varying information in a window title bar or button label.
|
||||||
|
|
||||||
|
Using "###" exclude the preceeding part from ID computation:
|
||||||
|
```cpp
|
||||||
|
Button("Hello###ID"); // Label = "Enable", ID = hash of (..., "ID")
|
||||||
|
Button("World###ID"); // Label = "Disable", ID = hash of (..., "ID") // Same ID, different label
|
||||||
|
```
|
||||||
|
Using a same ID ensure that associated related e.g. weither the widget is focused, won't be lost when the label changes.
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><img src="https://github.com/user-attachments/assets/2bf18756-e122-498d-bbd4-5c44bb1018d5"></td>
|
||||||
|
<td>
|
||||||
|
<pre lang="cpp">
|
||||||
|
// Window label has animating FPS counter
|
||||||
|
// Window ID stays the same = hash of "MyGame"
|
||||||
|
char buf[128];
|
||||||
|
sprintf(buf, "My game (%.1f FPS)###MyGame", io.Framerate);
|
||||||
|
ImGui::Begin(buf);
|
||||||
|
|
||||||
|
// Label changes between "Enable" and "Disable"
|
||||||
|
// ID stays the same = hash of ("MyGame", "MyButton")
|
||||||
|
if (ImGui::Button(enabled ? "Disable###MyButton" : "Enable###MyButton", { -FLT_MIN, 0.0f }))
|
||||||
|
enabled = !enabled;
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
</pre>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
(Hint: I'd suggest wrapping sprintf in something more compact to use, e.g. [ocornut/Str](https://github.com/ocornut/Str) for what I personally use).
|
||||||
|
|
||||||
|
##### [Return to Index](#index)
|
||||||
|
|
||||||
|
### General description of the label and ID Stack system
|
||||||
|
|
||||||
Dear ImGui internally needs to uniquely identify UI elements.
|
Dear ImGui internally needs to uniquely identify UI elements.
|
||||||
Elements that are typically not clickable (such as calls to the Text functions) don't need an ID.
|
Elements that are typically not clickable (such as calls to Text() functions) don't need an ID.
|
||||||
Interactive widgets (such as calls to Button buttons) need a unique ID.
|
Interactive widgets (such as calls to Button() functions) need a unique ID.
|
||||||
|
|
||||||
**Unique IDs are used internally to track active widgets and occasionally associate state to widgets.<BR>
|
**Unique IDs are used internally to track active widgets and occasionally associate state to widgets.<BR>
|
||||||
Unique IDs are implicitly built from the hash of multiple elements that identify the "path" to the UI element.**
|
Unique IDs are implicitly built from the hash of multiple elements that identify the "path" to the UI element.**
|
||||||
|
|
||||||
Since Dear ImGui 1.85, you can use `Demo>Tools>ID Stack Tool` or call `ImGui::ShowIDStackToolWindow()`. The tool display intermediate values leading to the creation of a unique ID, making things easier to debug and understand.
|
You can use `Demo>Tools>ID Stack Tool` or call `ImGui::ShowIDStackToolWindow()`. The tool display intermediate values leading to the creation of a unique ID, making things easier to debug and understand.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -309,20 +452,7 @@ Button("Play##foo2"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo
|
|||||||
Button("##foo"); // Label = "", ID = hash of ("MyWindow", "##foo") // Different from window
|
Button("##foo"); // Label = "", ID = hash of ("MyWindow", "##foo") // Different from window
|
||||||
End();
|
End();
|
||||||
```
|
```
|
||||||
- If you want to completely hide the label, but still need an ID:
|
|
||||||
```cpp
|
|
||||||
Checkbox("##On", &b); // Label = "", ID = hash of (..., "##On") // No visible label, just a checkbox!
|
|
||||||
```
|
|
||||||
- Occasionally/rarely you might want to change a label while preserving a constant ID. This allows
|
|
||||||
you to animate labels. For example, you may want to include varying information in a window title bar,
|
|
||||||
but windows are uniquely identified by their ID. Use "###" to pass a label that isn't part of ID:
|
|
||||||
```cpp
|
|
||||||
Button("Hello###ID"); // Label = "Hello", ID = hash of (..., "###ID")
|
|
||||||
Button("World###ID"); // Label = "World", ID = hash of (..., "###ID") // Same ID, different label
|
|
||||||
|
|
||||||
sprintf(buf, "My game (%f FPS)###MyGame", fps);
|
|
||||||
Begin(buf); // Variable title, ID = hash of "MyGame"
|
|
||||||
```
|
|
||||||
- Solving ID conflict in a more general manner:
|
- Solving ID conflict in a more general manner:
|
||||||
Use `PushID()` / `PopID()` to create scopes and manipulate the ID stack, as to avoid ID conflicts
|
Use `PushID()` / `PopID()` to create scopes and manipulate the ID stack, as to avoid ID conflicts
|
||||||
within the same window. This is the most convenient way of distinguishing ID when iterating and
|
within the same window. This is the most convenient way of distinguishing ID when iterating and
|
||||||
@@ -603,22 +733,28 @@ Since 1.92 (June 2025) fonts may be dynamically used at any size.
|
|||||||
|
|
||||||
**Scaling fonts**
|
**Scaling fonts**
|
||||||
|
|
||||||
|
Select default size:
|
||||||
|
```cpp
|
||||||
|
style.FontSizeBase = 20.0f;
|
||||||
|
```
|
||||||
|
Scale all fonts:
|
||||||
|
```cpp
|
||||||
|
style.FontScaleDpi = 2.0f;
|
||||||
|
```
|
||||||
|
|
||||||
To change font size:
|
To change font size:
|
||||||
```cpp
|
```cpp
|
||||||
ImGui::PushFont(NULL, 42.0f);
|
ImGui::PushFont(NULL, 42.0f); // This will be multiplied by style.FontScaleDpi
|
||||||
```
|
```
|
||||||
To change font and font size:
|
To change font and font size:
|
||||||
```cpp
|
```cpp
|
||||||
ImGui::PushFont(new_font, 42.0f);
|
ImGui::PushFont(new_font, 42.0f);
|
||||||
```
|
```
|
||||||
To scale all fonts:
|
|
||||||
```cpp
|
|
||||||
style.FontScaleDpi = 2.0f;
|
|
||||||
```
|
|
||||||
In `docking` branch or with multi-viewports:
|
In `docking` branch or with multi-viewports:
|
||||||
```cpp
|
```cpp
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // (Docking branch only) Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // (Docking branch only) Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Scaling style** (paddings, spacings, thicknesses)
|
**Scaling style** (paddings, spacings, thicknesses)
|
||||||
|
|||||||
@@ -2,10 +2,20 @@ _(You may browse this at https://github.com/ocornut/imgui/blob/master/docs/FONTS
|
|||||||
|
|
||||||
## Dear ImGui: Using Fonts
|
## Dear ImGui: Using Fonts
|
||||||
|
|
||||||
The code in imgui.cpp embeds a copy of [ProggyClean.ttf](http://proggyfonts.net) (by Tristan Grimmer),
|
The code in Dear ImGui embeds a copy of [ProggyClean.ttf](https://github.com/bluescan/proggyfonts) by Tristan Grimmer,
|
||||||
a 13 pixels high, pixel-perfect font used by default. We embed it in the source code so you can use Dear ImGui without any file system access. ProggyClean does not scale smoothly, therefore it is recommended that you load your own file when using Dear ImGui in an application aiming to look nice and wanting to support multiple resolutions.
|
a 13 pixels high, pixel-perfect font used by default. ProggyClean does not scale very nicely.
|
||||||
|
|
||||||
You may also load external .TTF/.OTF files.
|
The code in Dear ImGui embeds a partial copy of [ProggyForever.ttf](https://github.com/ocornut/proggyforever) by Disco Hello & Tristan Grimmer,
|
||||||
|
a new font mimicking ProggyClean which does scale nicely.
|
||||||
|
|
||||||
|
We embed fonts in the code so you can use Dear ImGui without any file system access.
|
||||||
|
If you don't use them you can set `IMGUI_DISABLE_DEFAULT_FONT` in your [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) file to ship binaries without the fonts and save about ~26 KB.
|
||||||
|
|
||||||
|
Calling io.Fonts->AddFontDefaultVector() loads ProggyForever.
|
||||||
|
Calling io.Fonts->AddFontDefaultBitmap() loads ProggyClean.
|
||||||
|
Calling io.Fonts->AddFontDefault() selects one based on the expected default font size (when `style.FontSizeBase * style.FontScaleMain * style.FontSizeDpi >= 15` we use ProggyForever).
|
||||||
|
|
||||||
|
You may also load external .TTF/.OTF files, see instructions on this page.
|
||||||
In the [misc/fonts/](https://github.com/ocornut/imgui/tree/master/misc/fonts) folder you can find a few suggested fonts, provided as a convenience.
|
In the [misc/fonts/](https://github.com/ocornut/imgui/tree/master/misc/fonts) folder you can find a few suggested fonts, provided as a convenience.
|
||||||
|
|
||||||
**Also read the FAQ:** https://www.dearimgui.com/faq (there is a Fonts section!)
|
**Also read the FAQ:** https://www.dearimgui.com/faq (there is a Fonts section!)
|
||||||
@@ -67,6 +77,17 @@ Some solutions:
|
|||||||
You can use the `ImFontGlyphRangesBuilder` for this purpose and rebuilding your atlas between frames when new characters are needed. This will be the biggest win!
|
You can use the `ImFontGlyphRangesBuilder` for this purpose and rebuilding your atlas between frames when new characters are needed. This will be the biggest win!
|
||||||
- Set `io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight;` to disable rounding the texture height to the next power of two.
|
- Set `io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight;` to disable rounding the texture height to the next power of two.
|
||||||
|
|
||||||
|
### (5) Reduce texture resizes/copy on startup
|
||||||
|
|
||||||
|
🆕 Since 1.92, the ImFontAtlas is initially created using a 512x128 texture, then grows as glyphs and fonts are used. Atlas growth leads to alloc+copy, and both the old and new sized textures are present in memory for a short time (typically one frame). If you use known fonts and want to reduce initial growth, you may set `TexMinWidth` and `TexMinHeight` during initializaton.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
ImFontAtlas* atlas = io.Fonts;
|
||||||
|
atlas->TexMinWidth = 1024;
|
||||||
|
atlas->TexMinHeight = 1024;
|
||||||
|
atlas->AddFont(...);
|
||||||
|
```
|
||||||
|
|
||||||
##### [Return to Index](#index)
|
##### [Return to Index](#index)
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
@@ -89,7 +110,10 @@ See [#8465](https://github.com/ocornut/imgui/issues/8465) for more details.
|
|||||||
|
|
||||||
## How should I handle DPI in my application?
|
## How should I handle DPI in my application?
|
||||||
|
|
||||||
See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-should-i-handle-dpi-in-my-application).
|
Since 1.92, with an updated backend, you can set `style.FontScaleDpi = your_content_scale;` to scale all fonts.
|
||||||
|
<BR>You can call `style.ScaleAllSizes(xxx)` at init time or every frame at the beginning of your main loop to scale sizes/paddings.
|
||||||
|
<BR>Since 1.92, with an updated backend, macOS style pixel/backing style scale is automatically handled.
|
||||||
|
<BR>See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-should-i-handle-dpi-in-my-application) for more details.
|
||||||
|
|
||||||
##### [Return to Index](#index)
|
##### [Return to Index](#index)
|
||||||
|
|
||||||
@@ -97,10 +121,22 @@ See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-s
|
|||||||
|
|
||||||
## Fonts Loading Instructions
|
## Fonts Loading Instructions
|
||||||
|
|
||||||
|
**Select base size**
|
||||||
|
```cpp
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
style.FontSizeBase = 20.0f;
|
||||||
|
```
|
||||||
|
|
||||||
**Load default font:**
|
**Load default font:**
|
||||||
```cpp
|
```cpp
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.Fonts->AddFontDefault();
|
io.Fonts->AddFontDefaultVector(); // Load embedded scalable font.
|
||||||
|
```
|
||||||
|
```cpp
|
||||||
|
io.Fonts->AddFontDefaultBitmap(); // Load embedded bitmap font (legacy).
|
||||||
|
```
|
||||||
|
```cpp
|
||||||
|
io.Fonts->AddFontDefault(); // Load embedded font (legacy: auto-selected between the two above).
|
||||||
```
|
```
|
||||||
|
|
||||||
**Load .TTF/.OTF file with:**
|
**Load .TTF/.OTF file with:**
|
||||||
@@ -145,7 +181,7 @@ ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config);
|
|||||||
🆕 **Since 1.92, with an up to date backend: specifying glyph ranges is unnecessary.**
|
🆕 **Since 1.92, with an up to date backend: specifying glyph ranges is unnecessary.**
|
||||||
```cpp
|
```cpp
|
||||||
// Load a first font
|
// Load a first font
|
||||||
ImFont* font = io.Fonts->AddFontDefault();
|
ImFont* font = io.Fonts->AddFontDefaultVector();
|
||||||
ImFontConfig config;
|
ImFontConfig config;
|
||||||
config.MergeMode = true;
|
config.MergeMode = true;
|
||||||
io.Fonts->AddFontFromFileTTF("DroidSans.ttf", 0.0f, &config); // Merge into first font to add e.g. Asian characters
|
io.Fonts->AddFontFromFileTTF("DroidSans.ttf", 0.0f, &config); // Merge into first font to add e.g. Asian characters
|
||||||
@@ -202,7 +238,7 @@ if (ImGui::Button(u8"ロード"))
|
|||||||
{
|
{
|
||||||
// do stuff
|
// do stuff
|
||||||
}
|
}
|
||||||
ImGui::InputText("string", buf, IM_ARRAYSIZE(buf));
|
ImGui::InputText("string", buf, IM_COUNTOF(buf));
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -228,6 +264,7 @@ ImFontConfig font_cfg;
|
|||||||
font_cfg.FontDataOwnedByAtlas = false;
|
font_cfg.FontDataOwnedByAtlas = false;
|
||||||
ImFont* font = io.Fonts->AddFontFromMemoryTTF(data, data_size, size_pixels, &font_cfg);
|
ImFont* font = io.Fonts->AddFontFromMemoryTTF(data, data_size, size_pixels, &font_cfg);
|
||||||
```
|
```
|
||||||
|
IMPORTANT: Since 1.92, when using `FontDataOwnedByAtlas = false`, font data needs to available until `atlas->RemoveFont()`, or more typically until a shutdown of the owning context or font atlas. It was not immediately noticeable in 1.92.0 due to a bug in handling `FontDataOwnedByAtlas = false`, which was fixed in 1.92.6.
|
||||||
|
|
||||||
##### [Return to Index](#index)
|
##### [Return to Index](#index)
|
||||||
|
|
||||||
@@ -268,7 +305,7 @@ Example Setup:
|
|||||||
// Merge icons into default tool font
|
// Merge icons into default tool font
|
||||||
#include "IconsFontAwesome.h"
|
#include "IconsFontAwesome.h"
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.Fonts->AddFontDefault();
|
io.Fonts->AddFontDefaultVector();
|
||||||
ImFontConfig config;
|
ImFontConfig config;
|
||||||
config.MergeMode = true;
|
config.MergeMode = true;
|
||||||
config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
|
config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
|
||||||
@@ -425,7 +462,7 @@ As an alternative to rendering colorful glyphs using imgui_freetype with `ImGuiF
|
|||||||
#### Pseudo-code:
|
#### Pseudo-code:
|
||||||
```cpp
|
```cpp
|
||||||
// Add font, then register two custom 13x13 rectangles mapped to glyph 'a' and 'b' of this font
|
// Add font, then register two custom 13x13 rectangles mapped to glyph 'a' and 'b' of this font
|
||||||
ImFont* font = io.Fonts->AddFontDefault();
|
ImFont* font = io.Fonts->AddFontDefaultVector();
|
||||||
int rect_ids[2];
|
int rect_ids[2];
|
||||||
rect_ids[0] = io.Fonts->AddCustomRectFontGlyph(font, 'a', 13, 13, 13+1);
|
rect_ids[0] = io.Fonts->AddCustomRectFontGlyph(font, 'a', 13, 13, 13+1);
|
||||||
rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, 'b', 13, 13, 13+1);
|
rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, 'b', 13, 13, 13+1);
|
||||||
@@ -438,7 +475,7 @@ unsigned char* tex_pixels = nullptr;
|
|||||||
int tex_width, tex_height;
|
int tex_width, tex_height;
|
||||||
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height);
|
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height);
|
||||||
|
|
||||||
for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++)
|
for (int rect_n = 0; rect_n < IM_COUNTOF(rect_ids); rect_n++)
|
||||||
if (const ImTextureRect* rect = io.Fonts->GetCustomRect(rect_ids[rect_n]))
|
if (const ImTextureRect* rect = io.Fonts->GetCustomRect(rect_ids[rect_n]))
|
||||||
{
|
{
|
||||||
// Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!)
|
// Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!)
|
||||||
@@ -538,7 +575,20 @@ You can use the `UTF-8 Encoding viewer` in `Metrics/Debugger` to verify the cont
|
|||||||
|
|
||||||
## Credits/Licenses For Fonts Included In Repository
|
## Credits/Licenses For Fonts Included In Repository
|
||||||
|
|
||||||
Some fonts files are available in the `misc/fonts/` folder:
|
Embedded in source code:
|
||||||
|
|
||||||
|
**ProggyClean.ttf**, by Tristan Grimmer
|
||||||
|
<br>MIT License
|
||||||
|
<br>(recommended loading setting: Size = 13.0, GlyphOffset.y = +1, PixelSnapH = true)
|
||||||
|
<br>https://github.com/bluescan/proggyfonts
|
||||||
|
|
||||||
|
**ProggyForever.ttf**, by Disco Hello, Tristan Grimmer
|
||||||
|
<BR>MIT License
|
||||||
|
<BR>https://github.com/ocornut/proggyforever
|
||||||
|
|
||||||
|
Extra fonts files are available in the `misc/fonts/` folder.
|
||||||
|
Compared to 2014 when they were first introduced, we now have better font support and we embed ProggyForever.
|
||||||
|
I believe all the files here are unnecessary nowadays. You can find font yourself. They might eventually be removed.
|
||||||
|
|
||||||
**Roboto-Medium.ttf**, by Christian Robetson
|
**Roboto-Medium.ttf**, by Christian Robetson
|
||||||
<br>Apache License 2.0
|
<br>Apache License 2.0
|
||||||
@@ -553,15 +603,10 @@ Some fonts files are available in the `misc/fonts/` folder:
|
|||||||
<br>Apache License 2.0
|
<br>Apache License 2.0
|
||||||
<br>https://www.fontsquirrel.com/fonts/droid-sans
|
<br>https://www.fontsquirrel.com/fonts/droid-sans
|
||||||
|
|
||||||
**ProggyClean.ttf**, by Tristan Grimmer
|
|
||||||
<br>MIT License
|
|
||||||
<br>(recommended loading setting: Size = 13.0, GlyphOffset.y = +1)
|
|
||||||
<br>http://www.proggyfonts.net/
|
|
||||||
|
|
||||||
**ProggyTiny.ttf**, by Tristan Grimmer
|
**ProggyTiny.ttf**, by Tristan Grimmer
|
||||||
<br>MIT License
|
<br>MIT License
|
||||||
<br>(recommended loading setting: Size = 10.0, GlyphOffset.y = +1)
|
<br>(recommended loading setting: Size = 10.0, GlyphOffset.y = +1)
|
||||||
<br>http://www.proggyfonts.net/
|
<br>https://github.com/bluescan/proggyfonts
|
||||||
|
|
||||||
**Karla-Regular.ttf**, by Jonathan Pinhorn
|
**Karla-Regular.ttf**, by Jonathan Pinhorn
|
||||||
<br>SIL OPEN FONT LICENSE Version 1.1
|
<br>SIL OPEN FONT LICENSE Version 1.1
|
||||||
@@ -589,12 +634,8 @@ Some fonts files are available in the `misc/fonts/` folder:
|
|||||||
|
|
||||||
<img width="1172" height="715" alt="image" src="https://github.com/user-attachments/assets/c9702534-4877-41c9-ae0d-252933c26ced" />
|
<img width="1172" height="715" alt="image" src="https://github.com/user-attachments/assets/c9702534-4877-41c9-ae0d-252933c26ced" />
|
||||||
|
|
||||||
Pixel Perfect:
|
- Proggy Fonts, by Tristan Grimmer https://github.com/bluescan/proggyfonts
|
||||||
- Proggy Fonts, by Tristan Grimmer http://www.proggyfonts.net or http://upperboundsinteractive.com/fonts.php
|
- Sweet16, Sweet16 Mono, by Martin Sedlak (Latin + Supplemental + Extended A) https://github.com/kmar/Sweet16Font
|
||||||
- Sweet16, Sweet16 Mono, by Martin Sedlak (Latin + Supplemental + Extended A) https://github.com/kmar/Sweet16Font (also include an .inl file to use directly in dear imgui.)
|
|
||||||
|
|
||||||
Regular:
|
|
||||||
- ProggyVector if you want the old school Dear ImGui font to scale: https://github.com/bluescan/proggyfonts
|
|
||||||
- Google Noto Mono Fonts: https://www.google.com/get/noto/
|
- Google Noto Mono Fonts: https://www.google.com/get/noto/
|
||||||
- Typefaces for source code beautification: https://github.com/chrissimpkins/codeface
|
- Typefaces for source code beautification: https://github.com/chrissimpkins/codeface
|
||||||
- Programmation fonts: http://s9w.github.io/font_compare/
|
- Programmation fonts: http://s9w.github.io/font_compare/
|
||||||
|
|||||||
@@ -39,10 +39,12 @@ Dear ImGui is particularly suited to integration in game engines (for tooling),
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
**The core of Dear ImGui is self-contained within a few platform-agnostic files** which you can easily compile in your application/engine. They are all the files in the root folder of the repository (imgui*.cpp, imgui*.h). **No specific build process is required**. You can add the .cpp files into your existing project.
|
**The core of Dear ImGui is self-contained within a few platform-agnostic files** which you can easily compile in your application/engine. They are all the files in the root folder of the repository (`imgui*.cpp`, `imgui*.h`). **No specific build process is required**: you can add all files into your existing project.
|
||||||
|
|
||||||
**Backends for a variety of graphics API and rendering platforms** are provided in the [backends/](https://github.com/ocornut/imgui/tree/master/backends) folder, along with example applications in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. You may also create your own backend. Anywhere where you can render textured triangles, you can render Dear ImGui.
|
**Backends for a variety of graphics API and rendering platforms** are provided in the [backends/](https://github.com/ocornut/imgui/tree/master/backends) folder, along with example applications in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. You may also create your own backend. Anywhere where you can render textured triangles, you can render Dear ImGui.
|
||||||
|
|
||||||
|
C++20 users wishing to use a module may use the [stripe2933/imgui-module](https://github.com/stripe2933/imgui-module) third-party extension.
|
||||||
|
|
||||||
See the [Getting Started & Integration](#getting-started--integration) section of this document for more details.
|
See the [Getting Started & Integration](#getting-started--integration) section of this document for more details.
|
||||||
|
|
||||||
After Dear ImGui is set up in your application, you can use it from \_anywhere\_ in your program loop:
|
After Dear ImGui is set up in your application, you can use it from \_anywhere\_ in your program loop:
|
||||||
@@ -50,11 +52,11 @@ After Dear ImGui is set up in your application, you can use it from \_anywhere\_
|
|||||||
ImGui::Text("Hello, world %d", 123);
|
ImGui::Text("Hello, world %d", 123);
|
||||||
if (ImGui::Button("Save"))
|
if (ImGui::Button("Save"))
|
||||||
MySaveFunction();
|
MySaveFunction();
|
||||||
ImGui::InputText("string", buf, IM_ARRAYSIZE(buf));
|
ImGui::InputText("string", buf, IM_COUNTOF(buf));
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||||
```
|
```
|
||||||

|
<img width="412" height="236" alt="sample code output (dark)" src="https://github.com/user-attachments/assets/32b838df-6378-498b-84a8-9a79ee6264a7" />
|
||||||

|
<img width="412" height="236" alt="sample code output (light)" src="https://github.com/user-attachments/assets/f075e2b0-98de-4be8-acb4-99ba0c9966cd" />
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// Create a window called "My First Tool", with a menu bar.
|
// Create a window called "My First Tool", with a menu bar.
|
||||||
@@ -88,7 +90,7 @@ for (int n = 0; n < 50; n++)
|
|||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
```
|
```
|
||||||

|

|
||||||
|
|
||||||
Dear ImGui allows you to **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweak variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game-making editor/framework, etc.
|
Dear ImGui allows you to **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweak variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game-making editor/framework, etc.
|
||||||
|
|
||||||
@@ -107,35 +109,11 @@ Reading the changelogs is a good way to keep up to date with the things Dear ImG
|
|||||||
|
|
||||||
### Demo
|
### Demo
|
||||||
|
|
||||||
Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing a variety of features and examples. The code is always available for reference in `imgui_demo.cpp`. [Here's how the demo looks](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png).
|
Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing a variety of features and examples. The code is always available for reference in `imgui_demo.cpp`.
|
||||||
|
- [imgui_explorer](https://pthom.github.io/imgui_explorer): Web version of the demo w/ source code browser, courtesy of [@pthom](https://github.com/pthom).
|
||||||
|
|
||||||
You should be able to build the examples from sources. If you don't, let us know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here:
|
You should be able to build the examples from sources. If you don't, let us know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here:
|
||||||
- [imgui-demo-binaries-20250625.zip](https://www.dearimgui.com/binaries/imgui-demo-binaries-20250625.zip) (Windows, 1.92.0, built 2025/06/25, master) or [older binaries](https://www.dearimgui.com/binaries).
|
- [imgui-demo-binaries-20260225.zip](https://www.dearimgui.com/binaries/imgui-demo-binaries-20260225.zip) (Windows, 1.92.6, built 2026/02/25, master) or [older binaries](https://www.dearimgui.com/binaries).
|
||||||
|
|
||||||
The demo applications are not DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at a different scale and scale your style with `style.ScaleAllSizes()` (see [FAQ](https://www.dearimgui.com/faq)).
|
|
||||||
|
|
||||||
### Getting Started & Integration
|
|
||||||
|
|
||||||
See the [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) guide for details.
|
|
||||||
|
|
||||||
On most platforms and when using C++, **you should be able to use a combination of the [imgui_impl_xxxx](https://github.com/ocornut/imgui/tree/master/backends) backends without modification** (e.g. `imgui_impl_win32.cpp` + `imgui_impl_dx11.cpp`). If your engine supports multiple platforms, consider using more imgui_impl_xxxx files instead of rewriting them: this will be less work for you, and you can get Dear ImGui running immediately. You can _later_ decide to rewrite a custom backend using your custom engine functions if you wish so.
|
|
||||||
|
|
||||||
Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading a texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles, which is essentially what Backends are doing. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that: setting up a window and using backends. If you follow the [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) guide it should in theory take you less than an hour to integrate Dear ImGui. **Make sure to spend time reading the [FAQ](https://www.dearimgui.com/faq), comments, and the examples applications!**
|
|
||||||
|
|
||||||
Officially maintained backends/bindings (in repository):
|
|
||||||
- Renderers: DirectX9, DirectX10, DirectX11, DirectX12, Metal, OpenGL/ES/ES2, SDL_GPU, SDL_Renderer2/3, Vulkan, WebGPU.
|
|
||||||
- Platforms: GLFW, SDL2/SDL3, Win32, Glut, OSX, Android.
|
|
||||||
- Frameworks: Allegro5, Emscripten.
|
|
||||||
|
|
||||||
[Third-party backends/bindings](https://github.com/ocornut/imgui/wiki/Bindings) wiki page:
|
|
||||||
- Languages: C, C# and: Beef, ChaiScript, CovScript, Crystal, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Kotlin, Lobster, Lua, Nim, Odin, Pascal, PureBasic, Python, ReaScript, Ruby, Rust, Swift, Zig...
|
|
||||||
- Frameworks: AGS/Adventure Game Studio, Amethyst, Blender, bsf, Cinder, Cocos2d-x, Defold, Diligent Engine, Ebiten, Flexium, GML/Game Maker Studio, GLEQ, Godot, GTK3, Irrlicht Engine, JUCE, LÖVE+LUA, Mach Engine, Magnum, Marmalade, Monogame, NanoRT, nCine, Nim Game Lib, Nintendo 3DS/Switch/WiiU (homebrew), Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, Photoshop, px_render, Qt/QtDirect3D, raylib, SFML, Sokol, Unity, Unreal Engine 4/5, UWP, vtk, VulkanHpp, VulkanSceneGraph, Win32 GDI, WxWidgets.
|
|
||||||
- Many bindings are auto-generated (by good old [cimgui](https://github.com/cimgui/cimgui) or newer/experimental [dear_bindings](https://github.com/dearimgui/dear_bindings)), you can use their metadata output to generate bindings for other languages.
|
|
||||||
|
|
||||||
[Useful Extensions/Widgets](https://github.com/ocornut/imgui/wiki/Useful-Extensions) wiki page:
|
|
||||||
- Automation/testing, Text editors, node editors, timeline editors, plotting, software renderers, remote network access, memory editors, gizmos, etc. Notable and well supported extensions include [ImPlot](https://github.com/epezent/implot) and [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine).
|
|
||||||
|
|
||||||
Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas.
|
|
||||||
|
|
||||||
### Gallery
|
### Gallery
|
||||||
|
|
||||||
@@ -150,6 +128,35 @@ For a list of third-party widgets and extensions, check out the [Useful Extensio
|
|||||||
| Custom engine [erhe](https://github.com/tksuoran/erhe) (docking branch)<BR>[](https://user-images.githubusercontent.com/994606/147875067-a848991e-2ad2-4fd3-bf71-4aeb8a547bcf.png) | Custom engine for [Wonder Boy: The Dragon's Trap](http://www.TheDragonsTrap.com) (2017)<BR>[](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) |
|
| Custom engine [erhe](https://github.com/tksuoran/erhe) (docking branch)<BR>[](https://user-images.githubusercontent.com/994606/147875067-a848991e-2ad2-4fd3-bf71-4aeb8a547bcf.png) | Custom engine for [Wonder Boy: The Dragon's Trap](http://www.TheDragonsTrap.com) (2017)<BR>[](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) |
|
||||||
| Custom engine (untitled)<BR>[](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) | Tracy Profiler ([github](https://github.com/wolfpld/tracy))<BR>[](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v176/tracy_profiler.png) |
|
| Custom engine (untitled)<BR>[](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) | Tracy Profiler ([github](https://github.com/wolfpld/tracy))<BR>[](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v176/tracy_profiler.png) |
|
||||||
|
|
||||||
|
### Getting Started & Integration
|
||||||
|
|
||||||
|
See the [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) guide for details.
|
||||||
|
|
||||||
|
On most platforms and when using C++, **you should be able to use a combination of the [imgui_impl_xxxx](https://github.com/ocornut/imgui/tree/master/backends) backends without modification** (e.g. `imgui_impl_win32.cpp` + `imgui_impl_dx11.cpp`). If your engine supports multiple platforms, consider using more imgui_impl_xxxx files instead of rewriting them: this will be less work for you, and you can get Dear ImGui running immediately. You can _later_ decide to rewrite a custom backend using your custom engine functions if you wish so.
|
||||||
|
|
||||||
|
Integrating Dear ImGui within your custom engine is a matter of mainly 1) wiring mouse/keyboard/gamepad inputs 2) uploading a texture to your GPU/render engine 3) providing a render function that can create/update textures and render textured triangles. This is exactly what backends are doing.
|
||||||
|
- The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications setting up a window and using standard backends.
|
||||||
|
- The [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) guide has instructions to integrate imgui into an existing application using standard backends. It should in theory take you less than an hour to integrate Dear ImGui into your existing codebase where support libraries are linked. Less if you read carefully.
|
||||||
|
- The [Backends](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md) guide explains what backends are doing, and has instructions to implement a custom backend. You can also refer to the source code of our ~20 backends to understand how they work.
|
||||||
|
- Generally, **make sure to spend time reading the [FAQ](https://www.dearimgui.com/faq), comments, and the examples applications!**
|
||||||
|
|
||||||
|
Officially maintained backends (in repository):
|
||||||
|
- Renderers: DirectX9, DirectX10, DirectX11, DirectX12, Metal 3/4, OpenGL/ES/ES2, SDL_GPU, SDL_Renderer2/3, Vulkan, WebGPU.
|
||||||
|
- Platforms: GLFW, SDL2/SDL3, Win32, Glut, OSX, Android.
|
||||||
|
- Frameworks: Allegro5, Emscripten.
|
||||||
|
|
||||||
|
[Third-party backends/bindings](https://github.com/ocornut/imgui/wiki/Bindings) wiki page:
|
||||||
|
- Languages: C, C# and: Beef, ChaiScript, CovScript, Crystal, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Kotlin, Lobster, Lua, Nim, Odin, Pascal, PureBasic, Python, ReaScript, Ruby, Rust, Swift, Zig...
|
||||||
|
- Frameworks: AGS/Adventure Game Studio, Amethyst, Blender, bsf, Cinder, Cocos2d-x, Defold, Diligent Engine, Ebiten, Flexium, GML/Game Maker Studio, GLEQ, Godot, GTK3, Irrlicht Engine, JUCE, LÖVE+LUA, Mach Engine, Magnum, Marmalade, Monogame, NanoRT, nCine, Nim Game Lib, Nintendo 3DS/Switch/WiiU (homebrew), Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, Photoshop, px_render, Qt/QtDirect3D, raylib, SFML, Sokol, Unity, Unreal Engine 4/5, UWP, vtk, VulkanHpp, VulkanSceneGraph, Win32 GDI, WxWidgets.
|
||||||
|
- Many bindings are auto-generated (by good old [cimgui](https://github.com/cimgui/cimgui) or our newer [dear_bindings](https://github.com/dearimgui/dear_bindings)), you can use their metadata output to generate bindings for other languages.
|
||||||
|
|
||||||
|
[Useful Extensions/Widgets](https://github.com/ocornut/imgui/wiki/Useful-Extensions) wiki page:
|
||||||
|
|
||||||
|
[](https://github.com/ocornut/imgui/wiki/Useful-Extensions)
|
||||||
|
- Automation/testing, Text editors, node editors, timeline editors, plotting, software renderers, remote network access, memory editors, gizmos, etc. Notable and well supported extensions include [ImPlot](https://github.com/epezent/implot), [ImPlot3d](https://github.com/brenocq/implot3d) and [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine).
|
||||||
|
|
||||||
|
Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas.
|
||||||
|
|
||||||
### Support, Frequently Asked Questions (FAQ)
|
### Support, Frequently Asked Questions (FAQ)
|
||||||
|
|
||||||
See: [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) where common questions are answered.
|
See: [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) where common questions are answered.
|
||||||
@@ -203,7 +210,7 @@ Dear ImGui is using software and services provided free of charge for open sourc
|
|||||||
Credits
|
Credits
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Developed by [Omar Cornut](https://www.miracleworld.net) and every direct or indirect [contributors](https://github.com/ocornut/imgui/graphs/contributors) to the GitHub. The early version of this library was developed with the support of [Media Molecule](https://www.mediamolecule.com) and first used internally on the game [Tearaway](https://tearaway.mediamolecule.com) (PS Vita).
|
Developed by [Omar Cornut](https://www.miracleworld.net) and every direct or indirect [contributors](https://github.com/ocornut/imgui/graphs/contributors) to the GitHub. The early version of this library was developed with the support of [Media Molecule](https://www.mediamolecule.com) and first used internally on the game [Tearaway](https://youtu.be/w0oxBviRGlU) (PS Vita).
|
||||||
|
|
||||||
Recurring contributors include Rokas Kupstys [@rokups](https://github.com/rokups) (2020-2022): a good portion of work on automation system and regression tests now available in [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine).
|
Recurring contributors include Rokas Kupstys [@rokups](https://github.com/rokups) (2020-2022): a good portion of work on automation system and regression tests now available in [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine).
|
||||||
|
|
||||||
@@ -211,7 +218,8 @@ Maintenance/support contracts, sponsoring invoices and other B2B transactions ar
|
|||||||
|
|
||||||
Omar: "I first discovered the IMGUI paradigm at [Q-Games](https://www.q-games.com) where Atman Binstock had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating and improving it."
|
Omar: "I first discovered the IMGUI paradigm at [Q-Games](https://www.q-games.com) where Atman Binstock had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating and improving it."
|
||||||
|
|
||||||
Embeds [ProggyClean.ttf](https://www.proggyfonts.net) font by Tristan Grimmer (MIT license).
|
Embeds [ProggyClean](https://www.proggyfonts.net) font by Tristan Grimmer (MIT license).
|
||||||
|
<br>Embeds [ProggyForever](https://github.com/ocornut/proggyforever) fonts by Disco Hello, Tristan Grimmer (MIT license).
|
||||||
<br>Embeds [stb_textedit.h, stb_truetype.h, stb_rect_pack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain).
|
<br>Embeds [stb_textedit.h, stb_truetype.h, stb_rect_pack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain).
|
||||||
|
|
||||||
Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Special thanks to Alex Evans, Patrick Doane, Marco Koegler for kindly helping. Also thank you to everyone posting feedback, questions and patches on GitHub.
|
Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Special thanks to Alex Evans, Patrick Doane, Marco Koegler for kindly helping. Also thank you to everyone posting feedback, questions and patches on GitHub.
|
||||||
|
|||||||
17
docs/SECURITY.md
Normal file
17
docs/SECURITY.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
Dear ImGui is primarily designed for developer tools and technical applications running trusted code and trusted data.
|
||||||
|
|
||||||
|
Given that the library was not designed as a hardened security boundary against hostile or intentionally malformed inputs:
|
||||||
|
consider not using it in a context where a crash (through e.g. intentionally malformed inputs) could lead to privilege elevation.
|
||||||
|
E.g. running in a privileged process and interacting with non-privileged clients feeding code or data to Dear ImGui.
|
||||||
|
|
||||||
|
Dear ImGui development efforts are focused on improving developer experience, usability, correctness, and robustness in real-world applications.
|
||||||
|
We will do our best to reduce e.g. crashes caused by common programmer mistakes.
|
||||||
|
|
||||||
|
However, the project does not specifically focus on adversarial fuzzing scenarios, allocation-failure hardening, or highly artificial edge cases that are unlikely to occur in normal usage.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Considering the above policy, most things may be reported in GitHub Issues.
|
||||||
|
If you have a reason to disclose privately, please reach out to the contact address listed in README.
|
||||||
@@ -2,12 +2,14 @@ dear imgui
|
|||||||
ISSUES & TODO LIST
|
ISSUES & TODO LIST
|
||||||
|
|
||||||
Issue numbers (#) refer to GitHub issues listed at https://github.com/ocornut/imgui/issues/XXXX
|
Issue numbers (#) refer to GitHub issues listed at https://github.com/ocornut/imgui/issues/XXXX
|
||||||
|
|
||||||
THIS LIST IS NOT WELL MAINTAINED. MOST OF THE WORK HAPPENS ON GITHUB NOWADAYS.
|
THIS LIST IS NOT WELL MAINTAINED. MOST OF THE WORK HAPPENS ON GITHUB NOWADAYS.
|
||||||
|
|
||||||
The list below consist mostly of ideas noted down before they are requested/discussed by users (at which point they usually exist on the github issue tracker).
|
The list below consist mostly of ideas noted down before they are requested/discussed by users (at which point they usually exist on the github issue tracker).
|
||||||
It's mostly a bunch of personal notes, probably incomplete. Feel free to query if you have any questions.
|
It's mostly a bunch of personal notes, probably incomplete. Feel free to query if you have any questions.
|
||||||
|
|
||||||
- doc: add a proper documentation system (maybe relying on automation? #435)
|
|
||||||
- doc: checklist app to verify backends/integration of imgui (test inputs, rendering, callback, etc.).
|
- doc: checklist app to verify backends/integration of imgui (test inputs, rendering, callback, etc.).
|
||||||
|
- doc: add a proper documentation system (maybe relying on automation? #435)
|
||||||
- doc/tips: tips of the day: website? applet in imgui_club?
|
- doc/tips: tips of the day: website? applet in imgui_club?
|
||||||
|
|
||||||
- window: preserve/restore relative focus ordering (persistent or not), and e.g. of multiple reappearing windows (#2304) -> also see docking reference to same #.
|
- window: preserve/restore relative focus ordering (persistent or not), and e.g. of multiple reappearing windows (#2304) -> also see docking reference to same #.
|
||||||
@@ -29,9 +31,9 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- window/clipping: some form of clipping when DisplaySize (or corresponding viewport) is zero.
|
- window/clipping: some form of clipping when DisplaySize (or corresponding viewport) is zero.
|
||||||
- window/tabbing: add a way to signify that a window or docked window requires attention (e.g. blinking title bar, trying to click behind a modal).
|
- window/tabbing: add a way to signify that a window or docked window requires attention (e.g. blinking title bar, trying to click behind a modal).
|
||||||
- window/id_stack: add e.g. window->GetIDFromPath() with support for leading / and ../ (#1390, #331) -> model from test engine.
|
- window/id_stack: add e.g. window->GetIDFromPath() with support for leading / and ../ (#1390, #331) -> model from test engine.
|
||||||
! scrolling: exposing horizontal scrolling with Shift+Wheel even when scrollbar is disabled expose lots of issues (#2424, #1463)
|
|
||||||
|
! scrolling: exposing horizontal scrolling with Shift+Wheel even when scrollbar is disabled expose various issues (#2424, #1463)
|
||||||
- scrolling: while holding down a scrollbar, try to keep the same contents visible (at least while not moving mouse)
|
- scrolling: while holding down a scrollbar, try to keep the same contents visible (at least while not moving mouse)
|
||||||
- scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet.
|
|
||||||
- scrolling: forward mouse wheel scrolling to parent window when at the edge of scrolling limits? (useful for listbox,tables?)
|
- scrolling: forward mouse wheel scrolling to parent window when at the edge of scrolling limits? (useful for listbox,tables?)
|
||||||
- scrolling/style: shadows on scrollable areas to denote that there is more contents (see e.g. DaVinci Resolve ui)
|
- scrolling/style: shadows on scrollable areas to denote that there is more contents (see e.g. DaVinci Resolve ui)
|
||||||
|
|
||||||
@@ -51,38 +53,32 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. (#395)
|
- widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. (#395)
|
||||||
- widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h.
|
- widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h.
|
||||||
- widgets: add always-allow-overlap mode. This should perhaps be the default? one problem is that highlight after mouse-wheel scrolling gets deferred, makes scrolling more flickery.
|
- widgets: add always-allow-overlap mode. This should perhaps be the default? one problem is that highlight after mouse-wheel scrolling gets deferred, makes scrolling more flickery.
|
||||||
- widgets: start exposing PushItemFlag() and ImGuiItemFlags
|
|
||||||
- widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260
|
- widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260
|
||||||
- widgets: activate by identifier (trigger button, focus given id)
|
- widgets: activate by identifier (trigger button, focus given id)
|
||||||
- widgets: custom glyph/shapes replacements for stock shapes. (also #6090 #2431 #2235 #6517)
|
- widgets: custom glyph/shapes replacements for stock shapes. (also #6090 #2431 #2235 #6517)
|
||||||
- widgets: coloredit: keep reporting as active when picker is on?
|
- widgets: coloredit: keep reporting as active when picker is on?
|
||||||
- widgets: group/scalarn functions: expose more per-component information. e.g. store NextItemData.ComponentIdx set by scalarn function, groups can expose them back somehow.
|
- widgets: group/ScalarN functions: expose more per-component information. e.g. store NextItemData.ComponentIdx set by scalarn function, groups can expose them back somehow.
|
||||||
- selectable: using (size.x == 0.0f) and (SelectableTextAlign.x > 0.0f) followed by SameLine() is currently not supported.
|
- selectable: using (size.x == 0.0f) and (SelectableTextAlign.x > 0.0f) followed by SameLine() is currently not supported.
|
||||||
- selectable: generic BeginSelectable()/EndSelectable() mechanism. (work out alongside range-select branch)
|
- selectable: generic BeginSelectable()/EndSelectable() mechanism. (work out alongside range-select branch)
|
||||||
- selectable: a way to visualize partial/mixed selection (e.g. parent tree node has children with mixed selection)
|
- selectable: a way to visualize partial/mixed selection (e.g. parent tree node has children with mixed selection)
|
||||||
|
|
||||||
|
- input text: flag to disable live update of the user buffer (also applies to float/int text input) (#701)
|
||||||
- input text: preserve scrolling when unfocused?
|
- input text: preserve scrolling when unfocused?
|
||||||
- input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541)
|
- input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541)
|
||||||
- input text: expose CursorPos in char filter event (#816)
|
|
||||||
- input text: try usage idiom of using InputText with data only exposed through get/set accessors, without extraneous copy/alloc. (#3009)
|
|
||||||
- input text: access public fields via a non-callback API e.g. InputTextGetState("xxx") that may return nullptr if not active (available in internals)
|
|
||||||
- input text: flag to disable live update of the user buffer (also applies to float/int text input) (#701)
|
|
||||||
- input text: hover tooltip could show unclamped text
|
- input text: hover tooltip could show unclamped text
|
||||||
- input text: support for INSERT key to toggle overwrite mode. currently disabled because stb_textedit behavior is unsatisfactory on multi-line. (#2863)
|
- input text: support for INSERT key to toggle overwrite mode. currently disabled because stb_textedit behavior is unsatisfactory on multi-line. (#2863)
|
||||||
- input text: option to Tab after an Enter validation.
|
- input text: option to Tab after an Enter validation.
|
||||||
- input text: add ImGuiInputTextFlags_EnterToApply? (off #218)
|
- input text: add ImGuiInputTextFlags_EnterToApply? (off #218)
|
||||||
- input text: easier ways to update buffer (from source char*) while owned. preserve some sort of cursor position for multi-line text.
|
- input text: easier ways to update buffer (from source char*) while owned. preserve some sort of cursor position for multi-line text.
|
||||||
- input text: add discard flag (e.g. ImGuiInputTextFlags_DiscardActiveBuffer) or make it easier to clear active focus for text replacement during edition (#725)
|
- input text: add discard flag (e.g. ImGuiInputTextFlags_DiscardActiveBuffer) or make it easier to clear active focus for text replacement during edition (#725)
|
||||||
- input text: display bug when clicking a drag/slider after an input text in a different window has all-selected text (order dependent). actually a very old bug but no one appears to have noticed it.
|
|
||||||
- input text: allow centering/positioning text so that ctrl+clicking Drag or Slider keeps the textual value at the same pixel position.
|
- input text: allow centering/positioning text so that ctrl+clicking Drag or Slider keeps the textual value at the same pixel position.
|
||||||
- input text: decorrelate display layout from inputs with custom template - e.g. what's the easiest way to implement a nice IP/Mac address input editor?
|
- input text: decorrelate display layout from inputs with custom template - e.g. what's the easiest way to implement a nice IP/Mac address input editor?
|
||||||
- input text: global callback system so user can plug in an expression evaluator easily. (#1691)
|
- input text: callback system (global) so user can plug in an expression evaluator easily. (#1691)
|
||||||
- input text: force scroll to end or scroll to a given line/contents (so user can implement a log or a search feature)
|
- input text: force scroll to end or scroll to a given line/contents (so user can implement a log or a search feature)
|
||||||
- input text: a way to preview completion (e.g. disabled text completing from the cursor)
|
- input text: a way to preview completion (e.g. disabled text completing from the cursor)
|
||||||
- input text: a side bar that could e.g. preview where errors are. probably left to the user to draw but we'd need to give them the info there.
|
- input text: a side bar that could e.g. preview where errors are. probably left to the user to draw but we'd need to give them the info there.
|
||||||
- input text: a way for the user to provide syntax coloring.
|
- input text: a way for the user to provide syntax coloring.
|
||||||
- input text: Shift+TAB with ImGuiInputTextFlags_AllowTabInput could eat preceding blanks, up to tab_count.
|
- input text: Shift+TAB with ImGuiInputTextFlags_AllowTabInput could eat preceding blanks, up to tab_count.
|
||||||
- input text multi-line: don't directly call AddText() which does an unnecessary vertex reserve for character count prior to clipping. and/or more line-based clipping to AddText(). and/or reorganize TextUnformatted/RenderText for more efficiency for large text (e.g TextUnformatted could clip and log separately, etc).
|
|
||||||
- input text multi-line: support for copy/cut without selection (copy/cut current line?)
|
- input text multi-line: support for copy/cut without selection (copy/cut current line?)
|
||||||
- input text multi-line: line numbers? status bar? (follow up on #200)
|
- input text multi-line: line numbers? status bar? (follow up on #200)
|
||||||
- input text multi-line: behave better when user changes input buffer while editing is active (even though it is illegal behavior). namely, the change of buffer can create a scrollbar glitch (#725)
|
- input text multi-line: behave better when user changes input buffer while editing is active (even though it is illegal behavior). namely, the change of buffer can create a scrollbar glitch (#725)
|
||||||
@@ -111,11 +107,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
!- color: the color conversion helpers/types are a mess and needs sorting out.
|
!- color: the color conversion helpers/types are a mess and needs sorting out.
|
||||||
- color: (api breaking) ImGui::ColorConvertXXX functions should be loose ImColorConvertXX to match imgui_internals.h
|
- color: (api breaking) ImGui::ColorConvertXXX functions should be loose ImColorConvertXX to match imgui_internals.h
|
||||||
|
|
||||||
- plot: full featured plot/graph api w/ scrolling, zooming etc. --> promote using ImPlot
|
|
||||||
- (plot: deleted all other todo lines on 2023-06-28)
|
|
||||||
|
|
||||||
- clipper: ability to disable the clipping through a simple flag/bool.
|
- clipper: ability to disable the clipping through a simple flag/bool.
|
||||||
- clipper: ability to run without knowing full count in advance.
|
|
||||||
- clipper: horizontal clipping support. (#2580)
|
- clipper: horizontal clipping support. (#2580)
|
||||||
|
|
||||||
- separator: expose flags (#759)
|
- separator: expose flags (#759)
|
||||||
@@ -169,22 +161,19 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- knob: rotating knob widget (#942)
|
- knob: rotating knob widget (#942)
|
||||||
- drag float: support for reversed drags (min > max) (removed is_locked, also see fdc526e)
|
- drag float: support for reversed drags (min > max) (removed is_locked, also see fdc526e)
|
||||||
- drag float: up/down axis
|
- drag float: up/down axis
|
||||||
- drag float: power != 0.0f with current value being outside the range keeps the value stuck.
|
|
||||||
- drag float: added leeway on edge (e.g. a few invisible steps past the clamp limits)
|
- drag float: added leeway on edge (e.g. a few invisible steps past the clamp limits)
|
||||||
|
|
||||||
- combo: a way/helper to customize the combo preview (#1658) -> experimental BeginComboPreview()
|
- combo: a way/helper to customize the combo preview (#1658) -> experimental BeginComboPreview()
|
||||||
- combo/listbox: keyboard control. need InputText-like non-active focus + key handling. considering keyboard for custom listbox (pr #203)
|
- combo/listbox: keyboard control. need InputText-like non-active focus + key handling. considering keyboard for custom listbox (pr #203)
|
||||||
- listbox: multiple selection (WIP range-select branch)
|
|
||||||
- listbox: unselect option (#1208)
|
- listbox: unselect option (#1208)
|
||||||
- listbox: make it easier/more natural to implement range-select (need some sort of info/ref about the last clicked/focused item that user can translate to an index?) (WIP range-select branch)
|
|
||||||
- listbox: user may want to initial scroll to focus on the one selected value?
|
- listbox: user may want to initial scroll to focus on the one selected value?
|
||||||
- listbox: disable capturing mouse wheel if the listbox has no scrolling. (#1681)
|
- listbox: disable capturing mouse wheel if the listbox has no scrolling. (#1681)
|
||||||
- listbox: scrolling should track modified selection.
|
- listbox: scrolling should track modified selection.
|
||||||
- listbox: future api should allow to enable horizontal scrolling (#2510)
|
- listbox: future api should allow to enable horizontal scrolling (#2510)
|
||||||
|
|
||||||
!- popups/menus: clarify usage of popups id, how MenuItem/Selectable closing parent popups affects the ID, etc. this is quite fishy needs improvement! (#331, #402)
|
!- popups/menus: clarify usage of popups id, how MenuItem/Selectable closing parent popups affects the ID, etc. this is quite fishy needs improvement! (#331, #402)
|
||||||
- modals: make modal title bar blink when trying to click outside the modal
|
- modals: make modal title bar blink when trying to click outside the modal.
|
||||||
- modals: technically speaking, we could make Begin() with ImGuiWindowFlags_Modal work without involving popup. May help untangle a few things, as modals are more like regular windows than popups.
|
- modals: technically speaking, we could make Begin() with ImGuiWindowFlags_Modal work without involving popup. May help untangle a few things, as modals are more like regular windows than popups. (#402)
|
||||||
- popups: if the popup functions took explicit ImGuiID it would allow the user to manage the scope of those ID. (#331)
|
- popups: if the popup functions took explicit ImGuiID it would allow the user to manage the scope of those ID. (#331)
|
||||||
- popups: clicking outside (to close popup) and holding shouldn't drag window below.
|
- popups: clicking outside (to close popup) and holding shouldn't drag window below.
|
||||||
- popups: add variant using global identifier similar to Begin/End (#402)
|
- popups: add variant using global identifier similar to Begin/End (#402)
|
||||||
@@ -226,7 +215,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- style: FramePadding could be different for up vs down (#584)
|
- style: FramePadding could be different for up vs down (#584)
|
||||||
- style: WindowPadding needs to be EVEN as the 0.5 multiplier used on this value probably have a subtle effect on clip rectangle
|
- style: WindowPadding needs to be EVEN as the 0.5 multiplier used on this value probably have a subtle effect on clip rectangle
|
||||||
- style: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space? (#438, #707, #1223)
|
- style: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space? (#438, #707, #1223)
|
||||||
- style: gradients fill (#1223) ~ 2 bg colors for each fill? tricky with rounded shapes and using textures for corners.
|
- style: gradients fill (#4722, #1223) ~ 2 bg colors for each fill? tricky with rounded shapes and using textures for corners.
|
||||||
- style editor: color child window height expressed in multiple of line height.
|
- style editor: color child window height expressed in multiple of line height.
|
||||||
|
|
||||||
- log: improve logging of ArrowButton, ListBox, TabItem
|
- log: improve logging of ArrowButton, ListBox, TabItem
|
||||||
@@ -242,7 +231,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- filters: fuzzy matches (may use code at blog.forrestthewoods.com/4cffeed33fdb)
|
- filters: fuzzy matches (may use code at blog.forrestthewoods.com/4cffeed33fdb)
|
||||||
|
|
||||||
- drag and drop: focus drag target window on hold (even without open)
|
- drag and drop: focus drag target window on hold (even without open)
|
||||||
- drag and drop: releasing a drop shows the "..." tooltip for one frame - since e13e598 (#1725)
|
|
||||||
- drag and drop: drag source on a group object (would need e.g. an invisible button covering group in EndGroup) https://twitter.com/paniq/status/1121446364909535233
|
- drag and drop: drag source on a group object (would need e.g. an invisible button covering group in EndGroup) https://twitter.com/paniq/status/1121446364909535233
|
||||||
- drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov. (see 2018/01/11 post in #143)
|
- drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov. (see 2018/01/11 post in #143)
|
||||||
- drag and drop: allow preview tooltip to be submitted from a different place than the drag source. (#1725)
|
- drag and drop: allow preview tooltip to be submitted from a different place than the drag source. (#1725)
|
||||||
@@ -275,7 +263,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- font: make it easier to submit own bitmap font (same texture, another texture?). (#2127, #2575)
|
- font: make it easier to submit own bitmap font (same texture, another texture?). (#2127, #2575)
|
||||||
- font: MemoryTTF taking ownership confusing/not obvious, maybe default should be opposite?
|
- font: MemoryTTF taking ownership confusing/not obvious, maybe default should be opposite?
|
||||||
- font: storing MinAdvanceX per font would allow us to skip calculating line width (under a threshold of character count) in loops looking for block width
|
- font: storing MinAdvanceX per font would allow us to skip calculating line width (under a threshold of character count) in loops looking for block width
|
||||||
- font/demo: demonstrate use of ImFontGlyphRangesBuilder.
|
|
||||||
- font/draw: vertical and/or rotated text renderer (#705) - vertical is easier clipping wise
|
- font/draw: vertical and/or rotated text renderer (#705) - vertical is easier clipping wise
|
||||||
- font/draw: need to be able to specify wrap start position.
|
- font/draw: need to be able to specify wrap start position.
|
||||||
- font/draw: better reserve policy for large horizontal block of text (shouldn't reserve for all clipped lines). also see #3349.
|
- font/draw: better reserve policy for large horizontal block of text (shouldn't reserve for all clipped lines). also see #3349.
|
||||||
@@ -301,12 +288,11 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- nav: NavFlattened: ESC on a flattened child should select something.
|
- nav: NavFlattened: ESC on a flattened child should select something.
|
||||||
- nav: NavFlattened: broken: in typical usage scenario, the items of a fully clipped child are currently not considered to enter into a NavFlattened child.
|
- nav: NavFlattened: broken: in typical usage scenario, the items of a fully clipped child are currently not considered to enter into a NavFlattened child.
|
||||||
- nav: NavFlattened: cannot access menu-bar of a flattened child window with Alt/menu key (not a very common use case..).
|
- nav: NavFlattened: cannot access menu-bar of a flattened child window with Alt/menu key (not a very common use case..).
|
||||||
- nav: simulate right-click or context activation? (SHIFT+F10, keyboard Menu key?)
|
|
||||||
- nav/popup: esc/enter default behavior for popups, e.g. be able to mark an "ok" or "cancel" button that would get triggered by those keys, default validation button, etc.
|
- nav/popup: esc/enter default behavior for popups, e.g. be able to mark an "ok" or "cancel" button that would get triggered by those keys, default validation button, etc.
|
||||||
- nav/treenode: left within a tree node block as a fallback (ImGuiTreeNodeFlags_NavLeftJumpsBackHere by default?)
|
- nav/treenode: left within a tree node block as a fallback (ImGuiTreeNodeFlags_NavLeftJumpsBackHere by default?)
|
||||||
- nav/menus: pressing left-right on a vertically clipped menu bar tends to jump to the collapse/close buttons.
|
- nav/menus: pressing left-right on a vertically clipped menu bar tends to jump to the collapse/close buttons.
|
||||||
- nav/menus: allow pressing Menu to leave a sub-menu.
|
- nav/menus: allow pressing Menu to leave a sub-menu.
|
||||||
- nav/menus: a way to access the main menu bar with Alt? (currently needs CTRL+TAB) or last focused window menu bar?
|
! nav/menus: a way to access the main menu bar with Alt? (currently needs CTRL+TAB) or last focused window menu bar?
|
||||||
- nav/menus: when using the main menu bar, even though we restore focus after, the underlying window loses its title bar highlight during menu manipulation. could we prevent it?
|
- nav/menus: when using the main menu bar, even though we restore focus after, the underlying window loses its title bar highlight during menu manipulation. could we prevent it?
|
||||||
- nav/menus: main menu bar currently cannot restore a nullptr focus. Could save NavWindow at the time of being focused, similarly to what popup do?
|
- nav/menus: main menu bar currently cannot restore a nullptr focus. Could save NavWindow at the time of being focused, similarly to what popup do?
|
||||||
- nav/menus: Alt,Up could open the first menu (e.g. "File") currently it tends to nav into the window/collapse menu. Do do that we would need custom transition?
|
- nav/menus: Alt,Up could open the first menu (e.g. "File") currently it tends to nav into the window/collapse menu. Do do that we would need custom transition?
|
||||||
@@ -340,7 +326,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- misc: no way to run a root-most GetID() with ImGui:: api since there's always a Debug window in the stack. (mentioned in #2960)
|
- misc: no way to run a root-most GetID() with ImGui:: api since there's always a Debug window in the stack. (mentioned in #2960)
|
||||||
- misc: make the ImGuiCond values linear (non-power-of-two). internal storage for ImGuiWindow can use integers to combine into flags (Why?)
|
- misc: make the ImGuiCond values linear (non-power-of-two). internal storage for ImGuiWindow can use integers to combine into flags (Why?)
|
||||||
- misc: PushItemFlag(): add a flag to disable keyboard capture when used with mouse? (#1682)
|
- misc: PushItemFlag(): add a flag to disable keyboard capture when used with mouse? (#1682)
|
||||||
- misc: use more size_t in public api?
|
|
||||||
- misc: support for string view/range instead of char* would e.g. facilitate usage with Rust (#683, #3038, WIP string_view branch)
|
- misc: support for string view/range instead of char* would e.g. facilitate usage with Rust (#683, #3038, WIP string_view branch)
|
||||||
|
|
||||||
- demo: demonstrate using PushStyleVar() in more details.
|
- demo: demonstrate using PushStyleVar() in more details.
|
||||||
@@ -351,15 +336,14 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
|
|
||||||
- examples: window minimize, maximize (#583)
|
- examples: window minimize, maximize (#583)
|
||||||
- examples: provide a zero frame-rate/idle example.
|
- examples: provide a zero frame-rate/idle example.
|
||||||
- examples: dx11/dx12: try to use new swapchain blit models (#2970)
|
- examples: dx11/dx12: try to use new swapchain blit models (#2970, #9031)
|
||||||
- backends: report it better when not able to create texture?
|
- backends: report it better when not able to create texture?
|
||||||
- backends: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440)
|
- backends: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440)
|
||||||
- backends: opengl: rename imgui_impl_opengl2 to impl_opengl_legacy and imgui_impl_opengl3 to imgui_impl_opengl? (#1900)
|
- backends: opengl: rename imgui_impl_opengl2 to impl_opengl_legacy and imgui_impl_opengl3 to imgui_impl_opengl? (#1900)
|
||||||
- backends: opengl: could use a single vertex buffer and glBufferSubData for uploads?
|
- backends: opengl: could use a single vertex buffer and glBufferSubData for uploads?
|
||||||
- backends: opengl: explicitly disable GL_STENCIL_TEST in bindings.
|
- backends: opengl: explicitly disable GL_STENCIL_TEST in bindings.
|
||||||
- backends: vulkan: viewport: support for synchronized swapping of multiple swap chains.
|
- backends: vulkan: viewport: support for synchronized swapping of multiple swap chains.
|
||||||
- backends: bgfx: https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0
|
- backends: emscripten: dedicated backend? (#8178, #9120, eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42)
|
||||||
- backends: emscripten: with refactored examples, we could provide a direct imgui_impl_emscripten platform layer (see eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42)
|
|
||||||
|
|
||||||
- bindings: ways to use clang ast dump to generate bindings or helpers for bindings? (e.g. clang++ -Xclang -ast-dump=json imgui.h) (--> use https://github.com/dearimgui/dear_bindings)
|
- bindings: ways to use clang ast dump to generate bindings or helpers for bindings? (e.g. clang++ -Xclang -ast-dump=json imgui.h) (--> use https://github.com/dearimgui/dear_bindings)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
See BACKENDS and EXAMPLES files in the docs/ folder, or on the web at: https://github.com/ocornut/imgui/tree/master/docs
|
New to Dear ImGui?
|
||||||
|
- Check out the Getting Started guide: https://github.com/ocornut/imgui/wiki/Getting-Started
|
||||||
|
- About Backends: docs/BACKENDS.md file, or on the web: https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md
|
||||||
|
- About Examples: docs/EXAMPLES.md file, or on the web: https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md
|
||||||
|
|
||||||
Backends = Helper code to facilitate integration with platforms/graphics api (used by Examples + should be used by your app).
|
Backends = Helper code to facilitate integration with platforms/graphics api (used by Examples + should be used by your app).
|
||||||
Examples = Standalone applications showcasing integration with platforms/graphics api.
|
Examples = Standalone applications showcasing integration with platforms/graphics api.
|
||||||
|
|
||||||
Some Examples have extra README files in their respective directory, please check them too!
|
A few Examples have extra README files in their respective directory, please check them too!
|
||||||
|
|
||||||
Once Dear ImGui is running (in either examples or your own application/game/engine),
|
Once Dear ImGui is running (in either examples or your own application/game/engine),
|
||||||
run and refer to ImGui::ShowDemoWindow() in imgui_demo.cpp for the end-user API.
|
run and refer to ImGui::ShowDemoWindow() in imgui_demo.cpp for the end-user API.
|
||||||
|
|||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -50,14 +50,16 @@ int main(int, char**)
|
|||||||
ImGui_ImplAllegro5_Init(display);
|
ImGui_ImplAllegro5_Init(display);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.kotlin.android)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -25,9 +24,6 @@ android {
|
|||||||
sourceCompatibility JavaVersion.VERSION_11
|
sourceCompatibility JavaVersion.VERSION_11
|
||||||
targetCompatibility JavaVersion.VERSION_11
|
targetCompatibility JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = '11'
|
|
||||||
}
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
path file('../../CMakeLists.txt')
|
path file('../../CMakeLists.txt')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.12.0"
|
agp = "9.2.0"
|
||||||
kotlin = "2.0.21"
|
kotlin = "2.3.21"
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|||||||
@@ -151,42 +151,45 @@ void Init(struct android_app* app)
|
|||||||
ImGui_ImplAndroid_Init(g_App->window);
|
ImGui_ImplAndroid_Init(g_App->window);
|
||||||
ImGui_ImplOpenGL3_Init("#version 300 es");
|
ImGui_ImplOpenGL3_Init("#version 300 es");
|
||||||
|
|
||||||
|
// Setup scaling
|
||||||
|
float main_scale = 2.0f;
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
|
style.FontScaleDpi = main_scale; // Set initial font scale.
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
// - Android: The TTF files have to be placed into the assets/ directory (android/app/src/main/assets), we use our GetAssetData() helper to retrieve them.
|
// - Android: The TTF files have to be placed into the assets/ directory (android/app/src/main/assets), we use our GetAssetData() helper to retrieve them.
|
||||||
|
//style.FontSizeBase = 20.0f;
|
||||||
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
|
|
||||||
// We load the default font with increased size to improve readability on many devices with "high" DPI.
|
|
||||||
// FIXME: Put some effort into DPI awareness.
|
|
||||||
// Important: when calling AddFontFromMemoryTTF(), ownership of font_data is transferred by Dear ImGui by default (deleted is handled by Dear ImGui), unless we set FontDataOwnedByAtlas=false in ImFontConfig
|
// Important: when calling AddFontFromMemoryTTF(), ownership of font_data is transferred by Dear ImGui by default (deleted is handled by Dear ImGui), unless we set FontDataOwnedByAtlas=false in ImFontConfig
|
||||||
ImFontConfig font_cfg;
|
//void* font_data;
|
||||||
font_cfg.SizePixels = 22.0f;
|
//int font_data_size;
|
||||||
io.Fonts->AddFontDefault(&font_cfg);
|
|
||||||
//void* font_data;
|
|
||||||
//int font_data_size;
|
|
||||||
//ImFont* font;
|
//ImFont* font;
|
||||||
//font_data_size = GetAssetData("segoeui.ttf", &font_data);
|
//font_data_size = GetAssetData("segoeui.ttf", &font_data);
|
||||||
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f);
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
|
||||||
//IM_ASSERT(font != nullptr);
|
//IM_ASSERT(font != nullptr);
|
||||||
//font_data_size = GetAssetData("DroidSans.ttf", &font_data);
|
//font_data_size = GetAssetData("DroidSans.ttf", &font_data);
|
||||||
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f);
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
|
||||||
//IM_ASSERT(font != nullptr);
|
//IM_ASSERT(font != nullptr);
|
||||||
//font_data_size = GetAssetData("Roboto-Medium.ttf", &font_data);
|
//font_data_size = GetAssetData("Roboto-Medium.ttf", &font_data);
|
||||||
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f);
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
|
||||||
//IM_ASSERT(font != nullptr);
|
//IM_ASSERT(font != nullptr);
|
||||||
//font_data_size = GetAssetData("Cousine-Regular.ttf", &font_data);
|
//font_data_size = GetAssetData("Cousine-Regular.ttf", &font_data);
|
||||||
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 15.0f);
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
|
||||||
//IM_ASSERT(font != nullptr);
|
//IM_ASSERT(font != nullptr);
|
||||||
//font_data_size = GetAssetData("ArialUni.ttf", &font_data);
|
//font_data_size = GetAssetData("ArialUni.ttf", &font_data);
|
||||||
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 18.0f);
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
|
||||||
//IM_ASSERT(font != nullptr);
|
//IM_ASSERT(font != nullptr);
|
||||||
|
|
||||||
// Arbitrary scale-up
|
|
||||||
// FIXME: Put some effort into DPI awareness
|
|
||||||
ImGui::GetStyle().ScaleAllSizes(3.0f);
|
|
||||||
|
|
||||||
g_Initialized = true;
|
g_Initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,14 +79,16 @@
|
|||||||
ImGui_ImplMetal_Init(_device);
|
ImGui_ImplMetal_Init(_device);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -69,14 +69,16 @@
|
|||||||
ImGui_ImplOpenGL2_Init();
|
ImGui_ImplOpenGL2_Init();
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
@@ -188,7 +190,7 @@
|
|||||||
-(NSWindow*)window
|
-(NSWindow*)window
|
||||||
{
|
{
|
||||||
if (_window != nil)
|
if (_window != nil)
|
||||||
return (_window);
|
return _window;
|
||||||
|
|
||||||
NSRect viewRect = NSMakeRect(100.0, 100.0, 100.0 + 1280.0, 100 + 800.0);
|
NSRect viewRect = NSMakeRect(100.0, 100.0, 100.0 + 1280.0, 100 + 800.0);
|
||||||
|
|
||||||
@@ -198,7 +200,7 @@
|
|||||||
[_window setOpaque:YES];
|
[_window setOpaque:YES];
|
||||||
[_window makeKeyAndOrderFront:NSApp];
|
[_window makeKeyAndOrderFront:NSApp];
|
||||||
|
|
||||||
return (_window);
|
return _window;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setupMenu
|
-(void)setupMenu
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -73,14 +73,16 @@ int main(int, char**)
|
|||||||
ImGui_ImplMetal_Init(device);
|
ImGui_ImplMetal_Init(device);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ LIBS =
|
|||||||
|
|
||||||
ifeq ($(UNAME_S), Linux) #LINUX
|
ifeq ($(UNAME_S), Linux) #LINUX
|
||||||
ECHO_MESSAGE = "Linux"
|
ECHO_MESSAGE = "Linux"
|
||||||
LIBS += $(LINUX_GL_LIBS) -lX11 `pkg-config --static --libs glfw3`
|
LIBS += $(LINUX_GL_LIBS) `pkg-config --static --libs glfw3`
|
||||||
|
|
||||||
CXXFLAGS += `pkg-config --cflags glfw3`
|
CXXFLAGS += `pkg-config --cflags glfw3`
|
||||||
CFLAGS = $(CXXFLAGS)
|
CFLAGS = $(CXXFLAGS)
|
||||||
|
|||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -81,14 +81,16 @@ int main(int, char**)
|
|||||||
ImGui_ImplOpenGL2_Init();
|
ImGui_ImplOpenGL2_Init();
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ LIBS =
|
|||||||
|
|
||||||
ifeq ($(UNAME_S), Linux) #LINUX
|
ifeq ($(UNAME_S), Linux) #LINUX
|
||||||
ECHO_MESSAGE = "Linux"
|
ECHO_MESSAGE = "Linux"
|
||||||
LIBS += $(LINUX_GL_LIBS) -lX11 `pkg-config --static --libs glfw3`
|
LIBS += $(LINUX_GL_LIBS) `pkg-config --static --libs glfw3`
|
||||||
|
|
||||||
CXXFLAGS += `pkg-config --cflags glfw3`
|
CXXFLAGS += `pkg-config --cflags glfw3`
|
||||||
CFLAGS = $(CXXFLAGS)
|
CFLAGS = $(CXXFLAGS)
|
||||||
|
|||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
#if GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR >= 3
|
#if GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR >= 3
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
@@ -117,15 +117,17 @@ int main(int, char**)
|
|||||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ find_package(Vulkan REQUIRED)
|
|||||||
#NAMES vulkan vulkan-1)
|
#NAMES vulkan vulkan-1)
|
||||||
#set(LIBRARIES "glfw;${VULKAN_LIBRARY}")
|
#set(LIBRARIES "glfw;${VULKAN_LIBRARY}")
|
||||||
set(LIBRARIES "glfw;Vulkan::Vulkan")
|
set(LIBRARIES "glfw;Vulkan::Vulkan")
|
||||||
# FIXME: Linux needs linking with "X11" as well?
|
|
||||||
|
|
||||||
# Use vulkan headers from glfw:
|
# Use vulkan headers from glfw:
|
||||||
include_directories(${GLFW_DIR}/deps)
|
include_directories(${GLFW_DIR}/deps)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ LIBS =
|
|||||||
|
|
||||||
ifeq ($(UNAME_S), Linux) #LINUX
|
ifeq ($(UNAME_S), Linux) #LINUX
|
||||||
ECHO_MESSAGE = "Linux"
|
ECHO_MESSAGE = "Linux"
|
||||||
LIBS += $(LINUX_GL_LIBS) -lX11 `pkg-config --static --libs glfw3 vulkan`
|
LIBS += $(LINUX_GL_LIBS) `pkg-config --static --libs glfw3 vulkan`
|
||||||
|
|
||||||
CXXFLAGS += `pkg-config --cflags glfw3 vulkan`
|
CXXFLAGS += `pkg-config --cflags glfw3 vulkan`
|
||||||
CFLAGS = $(CXXFLAGS)
|
CFLAGS = $(CXXFLAGS)
|
||||||
|
|||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
{
|
{
|
||||||
VkDescriptorPoolSize pool_sizes[] =
|
VkDescriptorPoolSize pool_sizes[] =
|
||||||
{
|
{
|
||||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE },
|
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, IMGUI_IMPL_VULKAN_MINIMUM_SAMPLED_IMAGE_POOL_SIZE },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_SAMPLER_POOL_SIZE },
|
||||||
};
|
};
|
||||||
VkDescriptorPoolCreateInfo pool_info = {};
|
VkDescriptorPoolCreateInfo pool_info = {};
|
||||||
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
@@ -201,7 +202,7 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
pool_info.maxSets = 0;
|
pool_info.maxSets = 0;
|
||||||
for (VkDescriptorPoolSize& pool_size : pool_sizes)
|
for (VkDescriptorPoolSize& pool_size : pool_sizes)
|
||||||
pool_info.maxSets += pool_size.descriptorCount;
|
pool_info.maxSets += pool_size.descriptorCount;
|
||||||
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
|
pool_info.poolSizeCount = (uint32_t)IM_COUNTOF(pool_sizes);
|
||||||
pool_info.pPoolSizes = pool_sizes;
|
pool_info.pPoolSizes = pool_sizes;
|
||||||
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);
|
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
@@ -212,11 +213,9 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
// Your real engine/app may not use them.
|
// Your real engine/app may not use them.
|
||||||
static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
|
static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
|
||||||
{
|
{
|
||||||
wd->Surface = surface;
|
|
||||||
|
|
||||||
// Check for WSI support
|
// Check for WSI support
|
||||||
VkBool32 res;
|
VkBool32 res;
|
||||||
vkGetPhysicalDeviceSurfaceSupportKHR(g_PhysicalDevice, g_QueueFamily, wd->Surface, &res);
|
vkGetPhysicalDeviceSurfaceSupportKHR(g_PhysicalDevice, g_QueueFamily, surface, &res);
|
||||||
if (res != VK_TRUE)
|
if (res != VK_TRUE)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error no WSI support on physical device 0\n");
|
fprintf(stderr, "Error no WSI support on physical device 0\n");
|
||||||
@@ -226,7 +225,8 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
|
|||||||
// Select Surface Format
|
// Select Surface Format
|
||||||
const VkFormat requestSurfaceImageFormat[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
|
const VkFormat requestSurfaceImageFormat[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
|
||||||
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
|
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
|
||||||
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace);
|
wd->Surface = surface;
|
||||||
|
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_COUNTOF(requestSurfaceImageFormat), requestSurfaceColorSpace);
|
||||||
|
|
||||||
// Select Present Mode
|
// Select Present Mode
|
||||||
#ifdef APP_USE_UNLIMITED_FRAME_RATE
|
#ifdef APP_USE_UNLIMITED_FRAME_RATE
|
||||||
@@ -234,12 +234,12 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
|
|||||||
#else
|
#else
|
||||||
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_FIFO_KHR };
|
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_FIFO_KHR };
|
||||||
#endif
|
#endif
|
||||||
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(g_PhysicalDevice, wd->Surface, &present_modes[0], IM_ARRAYSIZE(present_modes));
|
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(g_PhysicalDevice, wd->Surface, &present_modes[0], IM_COUNTOF(present_modes));
|
||||||
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
|
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
|
||||||
|
|
||||||
// Create SwapChain, RenderPass, Framebuffer, etc.
|
// Create SwapChain, RenderPass, Framebuffer, etc.
|
||||||
IM_ASSERT(g_MinImageCount >= 2);
|
IM_ASSERT(g_MinImageCount >= 2);
|
||||||
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
|
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CleanupVulkan()
|
static void CleanupVulkan()
|
||||||
@@ -256,9 +256,10 @@ static void CleanupVulkan()
|
|||||||
vkDestroyInstance(g_Instance, g_Allocator);
|
vkDestroyInstance(g_Instance, g_Allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CleanupVulkanWindow()
|
static void CleanupVulkanWindow(ImGui_ImplVulkanH_Window* wd)
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, &g_MainWindowData, g_Allocator);
|
ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, wd, g_Allocator);
|
||||||
|
vkDestroySurfaceKHR(g_Instance, wd->Surface, g_Allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
|
static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
|
||||||
@@ -401,7 +402,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -423,24 +424,26 @@ int main(int, char**)
|
|||||||
init_info.Queue = g_Queue;
|
init_info.Queue = g_Queue;
|
||||||
init_info.PipelineCache = g_PipelineCache;
|
init_info.PipelineCache = g_PipelineCache;
|
||||||
init_info.DescriptorPool = g_DescriptorPool;
|
init_info.DescriptorPool = g_DescriptorPool;
|
||||||
init_info.RenderPass = wd->RenderPass;
|
|
||||||
init_info.Subpass = 0;
|
|
||||||
init_info.MinImageCount = g_MinImageCount;
|
init_info.MinImageCount = g_MinImageCount;
|
||||||
init_info.ImageCount = wd->ImageCount;
|
init_info.ImageCount = wd->ImageCount;
|
||||||
init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
|
||||||
init_info.Allocator = g_Allocator;
|
init_info.Allocator = g_Allocator;
|
||||||
|
init_info.PipelineInfoMain.RenderPass = wd->RenderPass;
|
||||||
|
init_info.PipelineInfoMain.Subpass = 0;
|
||||||
|
init_info.PipelineInfoMain.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
init_info.CheckVkResultFn = check_vk_result;
|
init_info.CheckVkResultFn = check_vk_result;
|
||||||
ImGui_ImplVulkan_Init(&init_info);
|
ImGui_ImplVulkan_Init(&init_info);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
@@ -469,7 +472,7 @@ int main(int, char**)
|
|||||||
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
|
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
|
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
|
||||||
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount);
|
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, 0);
|
||||||
g_MainWindowData.FrameIndex = 0;
|
g_MainWindowData.FrameIndex = 0;
|
||||||
g_SwapChainRebuild = false;
|
g_SwapChainRebuild = false;
|
||||||
}
|
}
|
||||||
@@ -551,7 +554,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
CleanupVulkanWindow();
|
CleanupVulkanWindow(&g_MainWindowData);
|
||||||
CleanupVulkan();
|
CleanupVulkan();
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
|||||||
@@ -1,117 +1,246 @@
|
|||||||
# Building for desktop (WebGPU-native) with Dawn:
|
# Building for desktop with Dawn:
|
||||||
# 1. git clone https://github.com/google/dawn dawn
|
# 1. git clone https://github.com/google/dawn dawn
|
||||||
# 2. cmake -B build -DIMGUI_DAWN_DIR=dawn
|
# 2. cmake -B build -DIMGUI_DAWN_DIR=dawn
|
||||||
# 3. cmake --build build
|
# 3. cmake --build build
|
||||||
# The resulting binary will be found at one of the following locations:
|
# The resulting binary will be found at one of the following locations:
|
||||||
# * build/Debug/example_glfw_wgpu[.exe]
|
# * build/example_glfw_wgpu[.exe] or build/Debug/example_glfw_wgpu[.exe]
|
||||||
# * build/example_glfw_wgpu[.exe]
|
|
||||||
|
# Building for desktop with WGPU-Native:
|
||||||
|
# 1. download WGPU-Native autogenerated binary modules for your platform/compiler from: https://github.com/gfx-rs/wgpu-native/releases
|
||||||
|
# 2. unzip the downloaded file in your_preferred_folder
|
||||||
|
# 3. cmake -B build -DIMGUI_WGPU_DIR=your_preferred_folder ("full path" or "relative" starting from current directory)
|
||||||
|
# 4. cmake --build build
|
||||||
|
# The resulting binary will be found at one of the following locations:
|
||||||
|
# * build/example_glfw_wgpu[.exe] or build/Debug/example_glfw_wgpu[.exe]
|
||||||
|
|
||||||
|
# Building for desktop with WGVK (MUCH EASIER)
|
||||||
|
# 1. git clone https://github.com/manuel5975p/WGVK wgvk
|
||||||
|
# 2. cmake -B build -DIMGUI_WGVK_DIR=wgvk
|
||||||
|
# 3. cmake --build build
|
||||||
|
# The resulting binary will be found at one of the following locations:
|
||||||
|
# * build/example_glfw_wgpu[.exe] or build/Debug/example_glfw_wgpu[.exe]
|
||||||
|
|
||||||
# Building for Emscripten:
|
# Building for Emscripten:
|
||||||
# 1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
|
# 1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
|
||||||
# 2. Install Ninja build system
|
# 2. Install Ninja build system
|
||||||
# 3. emcmake cmake -G Ninja -B build
|
# 3. emcmake cmake -G Ninja -B build
|
||||||
|
# (optional) -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py", see ReadMe.md
|
||||||
# 3. cmake --build build
|
# 3. cmake --build build
|
||||||
# 4. emrun build/index.html
|
# 4. emrun build/index.html
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.10.2)
|
cmake_minimum_required(VERSION 3.22) # Dawn requires CMake >= 3.22
|
||||||
project(imgui_example_glfw_wgpu C CXX)
|
project(imgui_example_glfw_wgpu C CXX)
|
||||||
|
|
||||||
|
set(IMGUI_EXECUTABLE example_glfw_wgpu)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
|
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17) # Dawn requires C++17
|
set(CMAKE_CXX_STANDARD 20) # Dawn requires C++20
|
||||||
|
|
||||||
# Dear ImGui
|
# Dear ImGui
|
||||||
set(IMGUI_DIR ../../)
|
set(IMGUI_DIR ../../)
|
||||||
|
|
||||||
# Libraries
|
set(IMGUI_EXAMPLE_SOURCE_FILES
|
||||||
|
# Example code
|
||||||
|
main.cpp
|
||||||
|
# Dear ImGui Backend files
|
||||||
|
${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
|
||||||
|
${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp
|
||||||
|
# Dear ImGui files
|
||||||
|
${IMGUI_DIR}/imgui.cpp
|
||||||
|
${IMGUI_DIR}/imgui_draw.cpp
|
||||||
|
${IMGUI_DIR}/imgui_demo.cpp
|
||||||
|
${IMGUI_DIR}/imgui_tables.cpp
|
||||||
|
${IMGUI_DIR}/imgui_widgets.cpp
|
||||||
|
)
|
||||||
|
|
||||||
if(EMSCRIPTEN)
|
if(EMSCRIPTEN)
|
||||||
if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "3.1.57")
|
if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.10")
|
||||||
set(IMGUI_EMSCRIPTEN_GLFW3 "--use-port=contrib.glfw3" CACHE STRING "Choose between --use-port=contrib.glfw3 and -sUSE_GLFW=3 for GLFW implementation (default to --use-port=contrib.glfw3)")
|
set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Default to --use-port=emdawnwebgpu. You can override to provide your own local port.")
|
||||||
else()
|
else()
|
||||||
# cannot use contrib.glfw3 prior to 3.1.57
|
message(FATAL_ERROR "emdawnwebgpu needs EMSCRIPTEN version >= 4.0.10")
|
||||||
set(IMGUI_EMSCRIPTEN_GLFW3 "-sUSE_GLFW=3" CACHE STRING "Use -sUSE_GLFW=3 for GLFW implementation" FORCE)
|
endif()
|
||||||
endif()
|
|
||||||
set(LIBRARIES glfw)
|
if(NOT IMGUI_EMSCRIPTEN_GLFW3)
|
||||||
add_compile_options(-sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1)
|
# Defaults to contrib.glfw3 because Emscripten version is > 3.1.57
|
||||||
|
set(IMGUI_EMSCRIPTEN_GLFW3 "--use-port=contrib.glfw3" CACHE STRING "Choose between --use-port=contrib.glfw3 and -sUSE_GLFW=3 for GLFW implementation (default to --use-port=contrib.glfw3)")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(LIBRARIES glfw)
|
||||||
|
add_compile_options(-sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1)
|
||||||
|
else() # Native/Desktop build
|
||||||
|
|
||||||
|
# Check DAWN/WGPU/WGVK directory
|
||||||
|
# If it's Native/Desktop build, IMGUI_DAWN_DIR or IMGUI_WGPU_DIR or IMGUI_WGVK_DIR must be specified
|
||||||
|
if(NOT IMGUI_DAWN_DIR AND NOT IMGUI_WGPU_DIR AND NOT IMGUI_WGVK_DIR)
|
||||||
|
message(FATAL_ERROR "Please specify one of IMGUI_DAWN_DIR/IMGUI_WGPU_DIR/IMGUI_WGVK_DIR base directory.")
|
||||||
|
endif()
|
||||||
|
if((IMGUI_DAWN_DIR AND (IMGUI_WGPU_DIR OR IMGUI_WGVK_DIR)) OR (IMGUI_WGPU_DIR AND IMGUI_WGVK_DIR))
|
||||||
|
message(FATAL_ERROR "Please specify only one of IMGUI_DAWN_DIR/IMGUI_WGPU_DIR/IMGUI_WGVK_DIR base directory.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(APPLE) # Add SDL2 module to get Surface, with libs and file property for MacOS build
|
||||||
|
set_source_files_properties(${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++")
|
||||||
|
set(OS_LIBRARIES "-framework CoreFoundation -framework QuartzCore -framework Metal -framework MetalKit -framework Cocoa")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(glfw3 REQUIRED)
|
||||||
|
|
||||||
|
if(IMGUI_DAWN_DIR)
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH ${IMGUI_DAWN_DIR})
|
||||||
|
find_package(Dawn) # Search for a Dawn installation using IMGUI_DAWN_DIR in CMAKE_PREFIX_PATH
|
||||||
|
if(Dawn_FOUND)
|
||||||
|
message("Dawn Installation has been found!")
|
||||||
|
set(LIBRARIES dawn::webgpu_dawn glfw ${OS_LIBRARIES})
|
||||||
|
else()
|
||||||
|
set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository")
|
||||||
|
|
||||||
|
option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON)
|
||||||
|
set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE STRING "Build monolithic library: SHARED, STATIC, or OFF.")
|
||||||
|
|
||||||
|
option(DAWN_USE_GLFW OFF) # disable builtin GLFW in DAWN when we use SDL2 / SDL3
|
||||||
|
|
||||||
|
# Dawn builds many things by default - disable things we don't need
|
||||||
|
option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF)
|
||||||
|
option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF)
|
||||||
|
option(TINT_BUILD_DOCS "Build documentation" OFF)
|
||||||
|
option(TINT_BUILD_TESTS "Build tests" OFF)
|
||||||
|
if(NOT APPLE)
|
||||||
|
option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF)
|
||||||
|
endif()
|
||||||
|
if(WIN32)
|
||||||
|
option(DAWN_FORCE_SYSTEM_COMPONENT_LOAD "Allow system component fallback" ON)
|
||||||
|
option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF)
|
||||||
|
option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
|
||||||
|
option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF)
|
||||||
|
option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF)
|
||||||
|
option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ON)
|
||||||
|
option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
|
||||||
|
endif()
|
||||||
|
# check if WAYLAND is the current Session Type and enable DAWN_USE_WAYLAND Wayland option @compile time
|
||||||
|
# You can override this using: cmake -DDAWN_USE_WAYLAND=X (X = ON | OFF)
|
||||||
|
if(LINUX)
|
||||||
|
if($ENV{XDG_SESSION_TYPE} MATCHES wayland)
|
||||||
|
option(DAWN_USE_WAYLAND "Enable support for Wayland surface" ON)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory("${IMGUI_DAWN_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/dawn" EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
|
set(LIBRARIES webgpu_dawn glfw)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(IMGUI_WGPU_DIR)
|
||||||
|
set(WGPU_NATIVE_LIB_DIR ${IMGUI_WGPU_DIR}/lib)
|
||||||
|
find_library(WGPU_LIBRARY NAMES libwgpu_native.a wgpu_native.lib wgpu_native HINTS ${WGPU_NATIVE_LIB_DIR} REQUIRED)
|
||||||
|
if(WIN32)
|
||||||
|
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32 Propsys RuntimeObject)
|
||||||
|
elseif(UNIX AND NOT APPLE)
|
||||||
|
set(OS_LIBRARIES "-lm -ldl")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(LIBRARIES glfw ${WGPU_LIBRARY} ${OS_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(IMGUI_WGVK_DIR)
|
||||||
|
find_package(Vulkan REQUIRED)
|
||||||
|
set(WGVK_PLATFORM_LIBS)
|
||||||
|
set(WGVK_PLATFORM_DEFS)
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_WIN32_SURFACE=1)
|
||||||
|
elseif(APPLE)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_METAL_SURFACE=1)
|
||||||
|
elseif(UNIX)
|
||||||
|
find_package(PkgConfig QUIET)
|
||||||
|
pkg_check_modules(WAYLAND_CLIENT QUIET wayland-client)
|
||||||
|
if(WAYLAND_CLIENT_FOUND)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_WAYLAND_SURFACE=1)
|
||||||
|
list(APPEND WGVK_PLATFORM_LIBS ${WAYLAND_CLIENT_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
find_package(X11 QUIET)
|
||||||
|
if(X11_FOUND)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_XLIB_SURFACE=1)
|
||||||
|
list(APPEND WGVK_PLATFORM_LIBS X11::X11)
|
||||||
|
endif()
|
||||||
|
list(APPEND WGVK_PLATFORM_LIBS m dl pthread)
|
||||||
|
endif()
|
||||||
|
set(LIBRARIES glfw Vulkan::Vulkan ${WGVK_PLATFORM_LIBS})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(${IMGUI_EXECUTABLE} ${IMGUI_EXAMPLE_SOURCE_FILES})
|
||||||
|
|
||||||
|
target_include_directories(${IMGUI_EXECUTABLE} PUBLIC
|
||||||
|
${IMGUI_DIR}
|
||||||
|
${IMGUI_DIR}/backends
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_EXAMPLE_GLFW_WGPU")
|
||||||
|
|
||||||
|
# compiler option only for IMGUI_EXAMPLE_SOURCE_FILES
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC /W4) # warning level 4
|
||||||
else()
|
else()
|
||||||
# Dawn wgpu desktop
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC -Wall) # -Wextra -Wpedantic
|
||||||
set(DAWN_FETCH_DEPENDENCIES ON)
|
|
||||||
set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository")
|
|
||||||
if (NOT IMGUI_DAWN_DIR)
|
|
||||||
message(FATAL_ERROR "Please specify the Dawn repository by setting IMGUI_DAWN_DIR")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON)
|
|
||||||
|
|
||||||
# Dawn builds many things by default - disable things we don't need
|
|
||||||
option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF)
|
|
||||||
option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF)
|
|
||||||
option(TINT_BUILD_DOCS "Build documentation" OFF)
|
|
||||||
option(TINT_BUILD_TESTS "Build tests" OFF)
|
|
||||||
if (NOT APPLE)
|
|
||||||
option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF)
|
|
||||||
endif()
|
|
||||||
if(WIN32)
|
|
||||||
option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF)
|
|
||||||
option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
|
|
||||||
option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF)
|
|
||||||
option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF)
|
|
||||||
option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" OFF)
|
|
||||||
option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory("${IMGUI_DAWN_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/dawn" EXCLUDE_FROM_ALL)
|
|
||||||
|
|
||||||
set(LIBRARIES webgpu_dawn webgpu_cpp webgpu_glfw glfw)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(example_glfw_wgpu
|
# In this example IMGUI_IMPL_WEBGPU_BACKEND_DAWN / IMGUI_IMPL_WEBGPU_BACKEND_WGPU internal define is set according to:
|
||||||
main.cpp
|
# EMSCRIPTEN: by used FLAG
|
||||||
# backend files
|
# --use-port=emdawnwebgpu --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN defined
|
||||||
${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
|
# NATIVE: by used SDK installation directory
|
||||||
${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp
|
# if IMGUI_DAWN_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN defined
|
||||||
# Dear ImGui files
|
# if IMGUI_WGPU_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU defined
|
||||||
${IMGUI_DIR}/imgui.cpp
|
|
||||||
${IMGUI_DIR}/imgui_draw.cpp
|
|
||||||
${IMGUI_DIR}/imgui_demo.cpp
|
|
||||||
${IMGUI_DIR}/imgui_tables.cpp
|
|
||||||
${IMGUI_DIR}/imgui_widgets.cpp
|
|
||||||
)
|
|
||||||
IF(NOT EMSCRIPTEN)
|
|
||||||
target_compile_definitions(example_glfw_wgpu PUBLIC
|
|
||||||
"IMGUI_IMPL_WEBGPU_BACKEND_DAWN"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
target_include_directories(example_glfw_wgpu PUBLIC
|
|
||||||
${IMGUI_DIR}
|
|
||||||
${IMGUI_DIR}/backends
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(example_glfw_wgpu PUBLIC ${LIBRARIES})
|
if(NOT EMSCRIPTEN) # WegGPU-Native settings
|
||||||
|
# Set IMGUI_IMPL_WEBGPU_BACKEND_XXXX based on the SDK (directory) used
|
||||||
|
if(IMGUI_DAWN_DIR)
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN")
|
||||||
|
if(NOT Dawn_FOUND)
|
||||||
|
target_link_libraries(${IMGUI_EXECUTABLE} INTERFACE webgpu_cpp)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(IMGUI_WGPU_DIR)
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGPU")
|
||||||
|
target_include_directories(${IMGUI_EXECUTABLE} PUBLIC ${IMGUI_WGPU_DIR}/include)
|
||||||
|
endif()
|
||||||
|
if(IMGUI_WGVK_DIR)
|
||||||
|
target_sources(${IMGUI_EXECUTABLE} PRIVATE ${IMGUI_WGVK_DIR}/src/wgvk.c)
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGVK")
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PRIVATE ${WGVK_PLATFORM_DEFS})
|
||||||
|
target_include_directories(${IMGUI_EXECUTABLE} PUBLIC ${IMGUI_WGVK_DIR}/include)
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC /std:clatest /experimental:c11atomics)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Emscripten settings
|
target_link_libraries(${IMGUI_EXECUTABLE} PUBLIC ${LIBRARIES})
|
||||||
if(EMSCRIPTEN)
|
|
||||||
if("${IMGUI_EMSCRIPTEN_GLFW3}" STREQUAL "--use-port=contrib.glfw3")
|
else() # Emscripten settings
|
||||||
target_compile_options(example_glfw_wgpu PUBLIC
|
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||||
"${IMGUI_EMSCRIPTEN_GLFW3}"
|
|
||||||
|
if("${IMGUI_EMSCRIPTEN_GLFW3}" STREQUAL "--use-port=contrib.glfw3")
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_GLFW3}")
|
||||||
|
endif()
|
||||||
|
message(STATUS "Using ${IMGUI_EMSCRIPTEN_GLFW3} GLFW implementation")
|
||||||
|
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}")
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN")
|
||||||
|
message(STATUS "Using ${IMGUI_EMSCRIPTEN_WEBGPU_FLAG} WebGPU implementation")
|
||||||
|
|
||||||
|
target_link_options(${IMGUI_EXECUTABLE} PRIVATE
|
||||||
|
"${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}"
|
||||||
|
"${IMGUI_EMSCRIPTEN_GLFW3}"
|
||||||
|
"-sWASM=1"
|
||||||
|
"-sASYNCIFY=1"
|
||||||
|
"-sALLOW_MEMORY_GROWTH=1"
|
||||||
|
"-sNO_EXIT_RUNTIME=0"
|
||||||
|
"-sASSERTIONS=1"
|
||||||
|
"-sDISABLE_EXCEPTION_CATCHING=1"
|
||||||
|
"-sNO_FILESYSTEM=1"
|
||||||
|
"--shell-file=${CMAKE_CURRENT_LIST_DIR}/../libs/emscripten/shell_minimal.html"
|
||||||
)
|
)
|
||||||
endif()
|
set_target_properties(${IMGUI_EXECUTABLE} PROPERTIES OUTPUT_NAME "index")
|
||||||
message(STATUS "Using ${IMGUI_EMSCRIPTEN_GLFW3} GLFW implementation")
|
|
||||||
target_link_options(example_glfw_wgpu PRIVATE
|
|
||||||
"-sUSE_WEBGPU=1"
|
|
||||||
"${IMGUI_EMSCRIPTEN_GLFW3}"
|
|
||||||
"-sWASM=1"
|
|
||||||
"-sALLOW_MEMORY_GROWTH=1"
|
|
||||||
"-sNO_EXIT_RUNTIME=0"
|
|
||||||
"-sASSERTIONS=1"
|
|
||||||
"-sDISABLE_EXCEPTION_CATCHING=1"
|
|
||||||
"-sNO_FILESYSTEM=1"
|
|
||||||
)
|
|
||||||
set_target_properties(example_glfw_wgpu PROPERTIES OUTPUT_NAME "index")
|
|
||||||
# copy our custom index.html to build directory
|
|
||||||
add_custom_command(TARGET example_glfw_wgpu POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_LIST_DIR}/web/index.html" $<TARGET_FILE_DIR:example_glfw_wgpu>
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
# This Makefile assumes you have loaded emscripten's environment.
|
# This Makefile assumes you have loaded emscripten's environment.
|
||||||
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
||||||
#
|
#
|
||||||
# Running `make` will produce three files:
|
# Running `make -f Makefile.emscripten` will produce three files:
|
||||||
# - web/index.html (current stored in the repository)
|
# - web/index.html
|
||||||
# - web/index.js
|
# - web/index.js
|
||||||
# - web/index.wasm
|
# - web/index.wasm
|
||||||
#
|
#
|
||||||
@@ -16,11 +16,11 @@
|
|||||||
CC = emcc
|
CC = emcc
|
||||||
CXX = em++
|
CXX = em++
|
||||||
WEB_DIR = web
|
WEB_DIR = web
|
||||||
EXE = $(WEB_DIR)/index.js
|
EXE = $(WEB_DIR)/index.html
|
||||||
IMGUI_DIR = ../..
|
IMGUI_DIR = ../..
|
||||||
SOURCES = main.cpp
|
SOURCES = main.cpp
|
||||||
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
|
|
||||||
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp
|
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp
|
||||||
|
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
|
||||||
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
CPPFLAGS =
|
CPPFLAGS =
|
||||||
@@ -34,8 +34,15 @@ EMS =
|
|||||||
# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
|
# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
|
||||||
# Note: For glfw, we use emscripten-glfw port (contrib.glfw3) instead of (-s USE_GLFW=3) to get a better support for High DPI displays.
|
# Note: For glfw, we use emscripten-glfw port (contrib.glfw3) instead of (-s USE_GLFW=3) to get a better support for High DPI displays.
|
||||||
EMS += -s DISABLE_EXCEPTION_CATCHING=1 --use-port=contrib.glfw3
|
EMS += -s DISABLE_EXCEPTION_CATCHING=1 --use-port=contrib.glfw3
|
||||||
LDFLAGS += -s USE_WEBGPU=1
|
LDFLAGS += -s WASM=1
|
||||||
LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
|
LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
|
||||||
|
LDFLAGS += -s ASYNCIFY=1
|
||||||
|
LDFLAGS += -s NO_EXIT_RUNTIME=0
|
||||||
|
LDFLAGS += -s ASSERTIONS=1
|
||||||
|
|
||||||
|
# Using Dawn-based WebGPU port (requires Emscripten >= 4.0.10)
|
||||||
|
EMS += --use-port=emdawnwebgpu
|
||||||
|
LDFLAGS += --use-port=emdawnwebgpu
|
||||||
|
|
||||||
# Build as single file (binary text encoded in .html file)
|
# Build as single file (binary text encoded in .html file)
|
||||||
#LDFLAGS += -sSINGLE_FILE
|
#LDFLAGS += -sSINGLE_FILE
|
||||||
@@ -60,7 +67,7 @@ endif
|
|||||||
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
||||||
#CPPFLAGS += -g
|
#CPPFLAGS += -g
|
||||||
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
||||||
#LDFLAGS += --shell-file shell_minimal.html
|
LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
|
||||||
LDFLAGS += $(EMS)
|
LDFLAGS += $(EMS)
|
||||||
|
|
||||||
##---------------------------------------------------------------------
|
##---------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,141 @@
|
|||||||
## How to Build
|
## How to Build
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Using CMake
|
||||||
|
#### Building for desktop (WebGPU-native) with Google Dawn:
|
||||||
|
1. `git clone https://github.com/google/dawn dawn`
|
||||||
|
2. `cmake -B build -DIMGUI_DAWN_DIR=dawn`
|
||||||
|
3. `cmake --build build`
|
||||||
|
The resulting binary will be found at one of the following locations:
|
||||||
|
* build/Debug/example_glfw_wgpu[.exe]
|
||||||
|
* build/example_glfw_wgpu[.exe]
|
||||||
|
|
||||||
|
#### Building for desktop (WebGPU-Native) with WGPU:
|
||||||
|
1. download WGPU-Native autogenerated binary modules for your platform/compiler from: https://github.com/gfx-rs/wgpu-native/releases
|
||||||
|
2. unzip the downloaded file in `your_preferred_folder`
|
||||||
|
3. `cmake -B build -DIMGUI_WGPU_DIR=your_preferred_folder` ("full path" or "relative" starting from current directory)
|
||||||
|
4. `cmake --build build`
|
||||||
|
The resulting binary will be found at one of the following locations:
|
||||||
|
* build/Debug/example_glfw_wgpu[.exe]
|
||||||
|
* build/example_glfw_wgpu[.exe]
|
||||||
|
|
||||||
|
#### Building for Emscripten:
|
||||||
|
1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
|
||||||
|
2. Install Ninja build system
|
||||||
|
3. `emcmake cmake -G Ninja -B build`
|
||||||
|
- (optional) `-DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py"`, see below
|
||||||
|
4. `cmake --build build`
|
||||||
|
|
||||||
|
#### Sync Emscripten with latest Google Dawn:
|
||||||
|
If you want to sync Emscripten with latest DAWN release it's necessary to download the `port-emdawnwgpu-package` (released daily by Google) here:
|
||||||
|
https://github.com/google/dawn/releases
|
||||||
|
Unpack it in your preferred folder and to replace the step 3 with:
|
||||||
|
|
||||||
|
3. `emcmake cmake -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py" -G Ninja -B build`
|
||||||
|
|
||||||
|
**N.B.**
|
||||||
|
For the WASM code produced by Emscripten to work correctly, it will also be necessary to have the "corresponding" (or newer) version of Google Canary (nightly build for developers) that includes the latest changes
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### CMake by step
|
||||||
|
|
||||||
|
#### Generate Dawn Native:
|
||||||
|
|
||||||
|
- `cmake -G Ninja -DIMGUI_DAWN_DIR=path_to_sdk_dir -B where_to_build_dir`
|
||||||
|
- Using `IMGUI_DAWN_DIR` set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
|
|
||||||
|
#### Generate WGPU Native:
|
||||||
|
|
||||||
|
- `cmake -G Ninja -DIMGUI_WGPU_DIR=path_to_sdk_dir -B where_to_build_dir`
|
||||||
|
|
||||||
|
- Using `IMGUI_WGPU_DIR` set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define
|
||||||
|
|
||||||
|
#### Generate Emscripten:
|
||||||
|
|
||||||
|
- `emcmake cmake -G Ninja -B where_to_build_dir`\
|
||||||
|
CMake checks the EMSCRIPEN version then:
|
||||||
|
- if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
|
||||||
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
|
- if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend)
|
||||||
|
|
||||||
|
#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
|
||||||
|
|
||||||
|
- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
|
||||||
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
|
- *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
|
||||||
|
- https://github.com/google/dawn/releases
|
||||||
|
|
||||||
|
#### Build time
|
||||||
|
|
||||||
|
Once the procedure for the specific builder is generated, the build command is **always the same**:
|
||||||
|
|
||||||
|
- Build using CMake
|
||||||
|
- `cmake --build where_to_build_dir`
|
||||||
|
- It will use selected builder to build the example.
|
||||||
|
|
||||||
|
- Build explicitly:
|
||||||
|
- `cd where_to_build_dir`
|
||||||
|
- `ninja`
|
||||||
|
- This is the builder chosen during the generation phase
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### CMake useful options
|
||||||
|
#### Generator types (alternative to **ninja** builder):
|
||||||
|
- `-G Ninja` to build with __ninja__ builder
|
||||||
|
- `-G "Unix Makefiles"` to build with __make__ builder
|
||||||
|
- `-G "Visual Studio 17 2022" -A x64` to create a VS 2022 solution (.sln) file, Windows only
|
||||||
|
- **Native build only**
|
||||||
|
- Not **officially** supported to build Google Dawn
|
||||||
|
|
||||||
|
Example:
|
||||||
|
- using **make** instead **ninja**:
|
||||||
|
- `cmake -G "Unix Makefiles" -DIMGUI_DAWN_DIR=path_to_sdk_dir -B where_to_build_dir`
|
||||||
|
|
||||||
|
**Syntax is case sensitive and the "" are necessary in case of spaces between words*
|
||||||
|
|
||||||
|
#### Directories
|
||||||
|
- The directory path can be absolute or relative (starting from the current directory)
|
||||||
|
- It's necessary to use different `where_to_build_dir` for different CMake generations
|
||||||
|
|
||||||
|
|
||||||
|
#### Build type
|
||||||
|
The default build type is **Debug**
|
||||||
|
It is possible to use a different build type using:
|
||||||
|
- `-DCMAKE_BUILD_TYPE=Release`
|
||||||
|
- `-DCMAKE_BUILD_TYPE=MinSizeRel`
|
||||||
|
- `-DCMAKE_BUILD_TYPE=RelWithDebInfo`
|
||||||
|
|
||||||
|
Example:
|
||||||
|
- building **Release**:
|
||||||
|
- `cmake -G ninja -DIMGUI_WGPU_DIR=path_to_sdk_dir -DCMAKE_BUILD_TYPE=Release -B where_to_build_dir `
|
||||||
|
|
||||||
|
#### GLFW / SDL2 / SDL3 includes, libraries, search paths and package manager
|
||||||
|
|
||||||
|
Includes and libraries, by default, are searched in system/compiler paths (environment variables): you can add the path to your development tools to the environment variables without having to modify the `CMakeLists.txt` file.
|
||||||
|
- e.g. CLang search in path specified from the following environment variables:
|
||||||
|
- include files: CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH
|
||||||
|
- library files: LIBRARY_PATH
|
||||||
|
|
||||||
|
If you are using a package manager (**vcpkg** / **conan** / ... ) you need/can to specify it, adding to cmake command:
|
||||||
|
- `-DCMAKE_TOOLCHAIN_FILE=path/to/package_manager.cmake`
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
- using **vcpkg** package manager it's necessary adding:
|
||||||
|
- `-DCMAKE_TOOLCHAIN_FILE=<vcpkg_root_dir>/scripts/buildsystems/vcpkg.cmake`
|
||||||
|
|
||||||
|
- full cmake command using **vcpkg** package manager:
|
||||||
|
- `cmake -G Ninja -DIMGUI_DAWN_DIR=path_to_sdk_dir -DCMAKE_TOOLCHAIN_FILE=<vcpkg_root_dir>/scripts/buildsystems/vcpkg.cmake -B where_to_build_dir`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
### Using makefile
|
||||||
|
|
||||||
- You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions
|
- You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions
|
||||||
|
|
||||||
@@ -10,6 +147,8 @@
|
|||||||
|
|
||||||
- Requires recent Emscripten as WGPU is still a work-in-progress API.
|
- Requires recent Emscripten as WGPU is still a work-in-progress API.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## How to Run
|
## How to Run
|
||||||
|
|
||||||
To run on a local machine:
|
To run on a local machine:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Dear ImGui: standalone example application for using GLFW + WebGPU
|
// Dear ImGui: standalone example application for GLFW + WebGPU
|
||||||
// - Emscripten is supported for publishing on web. See https://emscripten.org.
|
// - Emscripten is supported for publishing on web. See https://emscripten.org.
|
||||||
// - Dawn is used as a WebGPU implementation on desktop.
|
// - Dawn is used as a WebGPU implementation on desktop.
|
||||||
|
|
||||||
@@ -12,54 +12,44 @@
|
|||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_wgpu.h"
|
#include "imgui_impl_wgpu.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
#include <emscripten.h>
|
|
||||||
#include <emscripten/html5.h>
|
|
||||||
#include <emscripten/html5_webgpu.h>
|
|
||||||
#else
|
|
||||||
#include <webgpu/webgpu_glfw.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <webgpu/webgpu.h>
|
|
||||||
#include <webgpu/webgpu_cpp.h>
|
|
||||||
|
|
||||||
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
|
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten.h>
|
||||||
|
#include <emscripten/html5.h>
|
||||||
#include "../libs/emscripten/emscripten_mainloop_stub.h"
|
#include "../libs/emscripten/emscripten_mainloop_stub.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Global WebGPU required states
|
#include <webgpu/webgpu.h>
|
||||||
static WGPUInstance wgpu_instance = nullptr;
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
static WGPUDevice wgpu_device = nullptr;
|
#include <webgpu/webgpu_cpp.h>
|
||||||
static WGPUSurface wgpu_surface = nullptr;
|
#endif
|
||||||
static WGPUTextureFormat wgpu_preferred_fmt = WGPUTextureFormat_RGBA8Unorm;
|
|
||||||
static WGPUSwapChain wgpu_swap_chain = nullptr;
|
// Data
|
||||||
static int wgpu_swap_chain_width = 1280;
|
static WGPUInstance wgpu_instance = nullptr;
|
||||||
static int wgpu_swap_chain_height = 800;
|
static WGPUDevice wgpu_device = nullptr;
|
||||||
|
static WGPUSurface wgpu_surface = nullptr;
|
||||||
|
static WGPUQueue wgpu_queue = nullptr;
|
||||||
|
static WGPUSurfaceConfiguration wgpu_surface_configuration = {};
|
||||||
|
static int wgpu_surface_width = 1280;
|
||||||
|
static int wgpu_surface_height = 800;
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
static bool InitWGPU(GLFWwindow* window);
|
static bool InitWGPU(GLFWwindow* window);
|
||||||
static void CreateSwapChain(int width, int height);
|
WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, GLFWwindow* window);
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description)
|
static void glfw_error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
printf("GLFW Error %d: %s\n", error, description);
|
printf("GLFW Error %d: %s\n", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wgpu_error_callback(WGPUErrorType error_type, const char* message, void*)
|
static void ResizeSurface(int width, int height)
|
||||||
{
|
{
|
||||||
const char* error_type_lbl = "";
|
wgpu_surface_configuration.width = wgpu_surface_width = width;
|
||||||
switch (error_type)
|
wgpu_surface_configuration.height = wgpu_surface_height = height;
|
||||||
{
|
wgpuSurfaceConfigure(wgpu_surface, &wgpu_surface_configuration);
|
||||||
case WGPUErrorType_Validation: error_type_lbl = "Validation"; break;
|
|
||||||
case WGPUErrorType_OutOfMemory: error_type_lbl = "Out of memory"; break;
|
|
||||||
case WGPUErrorType_Unknown: error_type_lbl = "Unknown"; break;
|
|
||||||
case WGPUErrorType_DeviceLost: error_type_lbl = "Device lost"; break;
|
|
||||||
default: error_type_lbl = "Unknown";
|
|
||||||
}
|
|
||||||
printf("%s error: %s\n", error_type_lbl, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main code
|
// Main code
|
||||||
@@ -72,19 +62,23 @@ int main(int, char**)
|
|||||||
// Make sure GLFW does not initialize any graphics context.
|
// Make sure GLFW does not initialize any graphics context.
|
||||||
// This needs to be done explicitly later.
|
// This needs to be done explicitly later.
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
GLFWwindow* window = glfwCreateWindow(wgpu_swap_chain_width, wgpu_swap_chain_height, "Dear ImGui GLFW+WebGPU example", nullptr, nullptr);
|
|
||||||
|
// Create window
|
||||||
|
float main_scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfwGetPrimaryMonitor()); // Valid on GLFW 3.3+ only
|
||||||
|
wgpu_surface_width = (int)(wgpu_surface_width * main_scale);
|
||||||
|
wgpu_surface_height = (int)(wgpu_surface_height * main_scale);
|
||||||
|
GLFWwindow* window = glfwCreateWindow(wgpu_surface_width, wgpu_surface_height, "Dear ImGui GLFW+WebGPU example", nullptr, nullptr);
|
||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Initialize the WebGPU environment
|
// Initialize the WebGPU environment
|
||||||
if (!InitWGPU(window))
|
if (!InitWGPU(window))
|
||||||
{
|
{
|
||||||
if (window)
|
glfwDestroyWindow(window);
|
||||||
glfwDestroyWindow(window);
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
CreateSwapChain(wgpu_swap_chain_width, wgpu_swap_chain_height);
|
|
||||||
glfwShowWindow(window);
|
glfwShowWindow(window);
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
// Setup Dear ImGui context
|
||||||
@@ -99,6 +93,11 @@ int main(int, char**)
|
|||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
//ImGui::StyleColorsLight();
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
|
// Setup scaling
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
// Setup Platform/Renderer backends
|
||||||
ImGui_ImplGlfw_InitForOther(window, true);
|
ImGui_ImplGlfw_InitForOther(window, true);
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
@@ -107,26 +106,27 @@ int main(int, char**)
|
|||||||
ImGui_ImplWGPU_InitInfo init_info;
|
ImGui_ImplWGPU_InitInfo init_info;
|
||||||
init_info.Device = wgpu_device;
|
init_info.Device = wgpu_device;
|
||||||
init_info.NumFramesInFlight = 3;
|
init_info.NumFramesInFlight = 3;
|
||||||
init_info.RenderTargetFormat = wgpu_preferred_fmt;
|
init_info.RenderTargetFormat = wgpu_surface_configuration.format;
|
||||||
init_info.DepthStencilFormat = WGPUTextureFormat_Undefined;
|
init_info.DepthStencilFormat = WGPUTextureFormat_Undefined;
|
||||||
ImGui_ImplWGPU_Init(&init_info);
|
ImGui_ImplWGPU_Init(&init_info);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
// - Emscripten allows preloading a file or folder to be accessible at runtime. See Makefile for details.
|
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
||||||
//io.Fonts->AddFontDefault();
|
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
#ifndef IMGUI_DISABLE_FILE_FUNCTIONS
|
#ifndef IMGUI_DISABLE_FILE_FUNCTIONS
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("fonts/segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("fonts/Roboto-Medium.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/Cousine-Regular.ttf");
|
//io.Fonts->AddFontFromFileTTF("fonts/Cousine-Regular.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/ProggyTiny.ttf");
|
|
||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("fonts/ArialUni.ttf");
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("fonts/ArialUni.ttf");
|
||||||
//IM_ASSERT(font != nullptr);
|
//IM_ASSERT(font != nullptr);
|
||||||
#endif
|
#endif
|
||||||
@@ -161,11 +161,24 @@ int main(int, char**)
|
|||||||
// React to changes in screen size
|
// React to changes in screen size
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetFramebufferSize((GLFWwindow*)window, &width, &height);
|
glfwGetFramebufferSize((GLFWwindow*)window, &width, &height);
|
||||||
if (width != wgpu_swap_chain_width || height != wgpu_swap_chain_height)
|
if (width != wgpu_surface_width || height != wgpu_surface_height)
|
||||||
|
ResizeSurface(width, height);
|
||||||
|
|
||||||
|
// Check surface status for error. If texture is not optimal, try to reconfigure the surface.
|
||||||
|
WGPUSurfaceTexture surface_texture;
|
||||||
|
wgpuSurfaceGetCurrentTexture(wgpu_surface, &surface_texture);
|
||||||
|
if (ImGui_ImplWGPU_IsSurfaceStatusError(surface_texture.status))
|
||||||
{
|
{
|
||||||
ImGui_ImplWGPU_InvalidateDeviceObjects();
|
fprintf(stderr, "Unrecoverable Surface Texture status=%#.8x\n", surface_texture.status);
|
||||||
CreateSwapChain(width, height);
|
abort();
|
||||||
ImGui_ImplWGPU_CreateDeviceObjects();
|
}
|
||||||
|
if (ImGui_ImplWGPU_IsSurfaceStatusSubOptimal(surface_texture.status))
|
||||||
|
{
|
||||||
|
if (surface_texture.texture)
|
||||||
|
wgpuTextureRelease(surface_texture.texture);
|
||||||
|
if (width > 0 && height > 0)
|
||||||
|
ResizeSurface(width, height);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
@@ -213,17 +226,21 @@ int main(int, char**)
|
|||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
WGPUTextureViewDescriptor view_desc = {};
|
||||||
// Tick needs to be called in Dawn to display validation errors
|
view_desc.format = wgpu_surface_configuration.format;
|
||||||
wgpuDeviceTick(wgpu_device);
|
view_desc.dimension = WGPUTextureViewDimension_2D ;
|
||||||
#endif
|
view_desc.mipLevelCount = WGPU_MIP_LEVEL_COUNT_UNDEFINED;
|
||||||
|
view_desc.arrayLayerCount = WGPU_ARRAY_LAYER_COUNT_UNDEFINED;
|
||||||
|
view_desc.aspect = WGPUTextureAspect_All;
|
||||||
|
|
||||||
|
WGPUTextureView texture_view = wgpuTextureCreateView(surface_texture.texture, &view_desc);
|
||||||
|
|
||||||
WGPURenderPassColorAttachment color_attachments = {};
|
WGPURenderPassColorAttachment color_attachments = {};
|
||||||
color_attachments.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
|
color_attachments.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
|
||||||
color_attachments.loadOp = WGPULoadOp_Clear;
|
color_attachments.loadOp = WGPULoadOp_Clear;
|
||||||
color_attachments.storeOp = WGPUStoreOp_Store;
|
color_attachments.storeOp = WGPUStoreOp_Store;
|
||||||
color_attachments.clearValue = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w };
|
color_attachments.clearValue = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w };
|
||||||
color_attachments.view = wgpuSwapChainGetCurrentTextureView(wgpu_swap_chain);
|
color_attachments.view = texture_view;
|
||||||
|
|
||||||
WGPURenderPassDescriptor render_pass_desc = {};
|
WGPURenderPassDescriptor render_pass_desc = {};
|
||||||
render_pass_desc.colorAttachmentCount = 1;
|
render_pass_desc.colorAttachmentCount = 1;
|
||||||
@@ -239,14 +256,16 @@ int main(int, char**)
|
|||||||
|
|
||||||
WGPUCommandBufferDescriptor cmd_buffer_desc = {};
|
WGPUCommandBufferDescriptor cmd_buffer_desc = {};
|
||||||
WGPUCommandBuffer cmd_buffer = wgpuCommandEncoderFinish(encoder, &cmd_buffer_desc);
|
WGPUCommandBuffer cmd_buffer = wgpuCommandEncoderFinish(encoder, &cmd_buffer_desc);
|
||||||
WGPUQueue queue = wgpuDeviceGetQueue(wgpu_device);
|
wgpuQueueSubmit(wgpu_queue, 1, &cmd_buffer);
|
||||||
wgpuQueueSubmit(queue, 1, &cmd_buffer);
|
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
wgpuSwapChainPresent(wgpu_swap_chain);
|
wgpuSurfacePresent(wgpu_surface);
|
||||||
|
// Tick needs to be called in Dawn to display validation errors
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
|
wgpuDeviceTick(wgpu_device);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
wgpuTextureViewRelease(color_attachments.view);
|
wgpuTextureViewRelease(texture_view);
|
||||||
wgpuRenderPassEncoderRelease(pass);
|
wgpuRenderPassEncoderRelease(pass);
|
||||||
wgpuCommandEncoderRelease(encoder);
|
wgpuCommandEncoderRelease(encoder);
|
||||||
wgpuCommandBufferRelease(cmd_buffer);
|
wgpuCommandBufferRelease(cmd_buffer);
|
||||||
@@ -260,92 +279,282 @@ int main(int, char**)
|
|||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
wgpuSurfaceUnconfigure(wgpu_surface);
|
||||||
|
wgpuSurfaceRelease(wgpu_surface);
|
||||||
|
wgpuQueueRelease(wgpu_queue);
|
||||||
|
wgpuDeviceRelease(wgpu_device);
|
||||||
|
wgpuInstanceRelease(wgpu_instance);
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
static WGPUAdapter RequestAdapter(WGPUInstance instance)
|
static WGPUAdapter RequestAdapter(wgpu::Instance& instance)
|
||||||
{
|
{
|
||||||
auto onAdapterRequestEnded = [](WGPURequestAdapterStatus status, WGPUAdapter adapter, const char* message, void* pUserData)
|
wgpu::Adapter acquired_adapter;
|
||||||
|
wgpu::RequestAdapterOptions adapter_options;
|
||||||
|
auto onRequestAdapter = [&](wgpu::RequestAdapterStatus status, wgpu::Adapter adapter, wgpu::StringView message)
|
||||||
{
|
{
|
||||||
if (status == WGPURequestAdapterStatus_Success)
|
if (status != wgpu::RequestAdapterStatus::Success)
|
||||||
*(WGPUAdapter*)(pUserData) = adapter;
|
{
|
||||||
else
|
printf("Failed to get an adapter: %s\n", message.data);
|
||||||
printf("Could not get WebGPU adapter: %s\n", message);
|
return;
|
||||||
};
|
}
|
||||||
WGPUAdapter adapter;
|
acquired_adapter = std::move(adapter);
|
||||||
wgpuInstanceRequestAdapter(instance, nullptr, onAdapterRequestEnded, (void*)&adapter);
|
|
||||||
return adapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
static WGPUDevice RequestDevice(WGPUAdapter& adapter)
|
|
||||||
{
|
|
||||||
auto onDeviceRequestEnded = [](WGPURequestDeviceStatus status, WGPUDevice device, const char* message, void* pUserData)
|
|
||||||
{
|
|
||||||
if (status == WGPURequestDeviceStatus_Success)
|
|
||||||
*(WGPUDevice*)(pUserData) = device;
|
|
||||||
else
|
|
||||||
printf("Could not get WebGPU device: %s\n", message);
|
|
||||||
};
|
};
|
||||||
WGPUDevice device;
|
|
||||||
wgpuAdapterRequestDevice(adapter, nullptr, onDeviceRequestEnded, (void*)&device);
|
// Synchronously (wait until) acquire Adapter
|
||||||
return device;
|
wgpu::Future waitAdapterFunc { instance.RequestAdapter(&adapter_options, wgpu::CallbackMode::WaitAnyOnly, onRequestAdapter) };
|
||||||
|
wgpu::WaitStatus waitStatusAdapter = instance.WaitAny(waitAdapterFunc, UINT64_MAX);
|
||||||
|
IM_ASSERT(acquired_adapter != nullptr && waitStatusAdapter == wgpu::WaitStatus::Success && "Error on Adapter request");
|
||||||
|
return acquired_adapter.MoveToCHandle();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool InitWGPU(GLFWwindow* window)
|
static WGPUDevice RequestDevice(wgpu::Instance& instance, wgpu::Adapter& adapter)
|
||||||
{
|
{
|
||||||
wgpu::Instance instance = wgpuCreateInstance(nullptr);
|
// Set device callback functions
|
||||||
|
wgpu::DeviceDescriptor device_desc;
|
||||||
|
device_desc.SetDeviceLostCallback(wgpu::CallbackMode::AllowSpontaneous,
|
||||||
|
[](const wgpu::Device&, wgpu::DeviceLostReason type, wgpu::StringView msg) { fprintf(stderr, "%s error: %s\n", ImGui_ImplWGPU_GetDeviceLostReasonName((WGPUDeviceLostReason)type), msg.data); }
|
||||||
|
);
|
||||||
|
device_desc.SetUncapturedErrorCallback(
|
||||||
|
[](const wgpu::Device&, wgpu::ErrorType type, wgpu::StringView msg) { fprintf(stderr, "%s error: %s\n", ImGui_ImplWGPU_GetErrorTypeName((WGPUErrorType)type), msg.data); }
|
||||||
|
);
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
wgpu::Device acquired_device;
|
||||||
wgpu_device = emscripten_webgpu_get_device();
|
auto onRequestDevice = [&](wgpu::RequestDeviceStatus status, wgpu::Device local_device, wgpu::StringView message)
|
||||||
if (!wgpu_device)
|
{
|
||||||
return false;
|
if (status != wgpu::RequestDeviceStatus::Success)
|
||||||
#else
|
{
|
||||||
WGPUAdapter adapter = RequestAdapter(instance.Get());
|
printf("Failed to get an device: %s\n", message.data);
|
||||||
if (!adapter)
|
return;
|
||||||
return false;
|
}
|
||||||
wgpu_device = RequestDevice(adapter);
|
acquired_device = std::move(local_device);
|
||||||
#endif
|
};
|
||||||
|
|
||||||
|
// Synchronously (wait until) get Device
|
||||||
|
wgpu::Future waitDeviceFunc { adapter.RequestDevice(&device_desc, wgpu::CallbackMode::WaitAnyOnly, onRequestDevice) };
|
||||||
|
wgpu::WaitStatus waitStatusDevice = instance.WaitAny(waitDeviceFunc, UINT64_MAX);
|
||||||
|
IM_ASSERT(acquired_device != nullptr && waitStatusDevice == wgpu::WaitStatus::Success && "Error on Device request");
|
||||||
|
return acquired_device.MoveToCHandle();
|
||||||
|
}
|
||||||
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK)
|
||||||
|
static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2)
|
||||||
|
{
|
||||||
|
IM_UNUSED(userdata2);
|
||||||
|
if (status == WGPURequestAdapterStatus_Success)
|
||||||
|
{
|
||||||
|
WGPUAdapter* extAdapter = (WGPUAdapter*)userdata1;
|
||||||
|
*extAdapter = adapter;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Request_adapter status=%#.8x message=%.*s\n", status, (int) message.length, message.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, void* userdata1, void* userdata2)
|
||||||
|
{
|
||||||
|
IM_UNUSED(userdata2);
|
||||||
|
if (status == WGPURequestDeviceStatus_Success)
|
||||||
|
{
|
||||||
|
WGPUDevice* extDevice = (WGPUDevice*)userdata1;
|
||||||
|
*extDevice = device;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Request_device status=%#.8x message=%.*s\n", status, (int) message.length, message.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static WGPUAdapter RequestAdapter(WGPUInstance& instance)
|
||||||
|
{
|
||||||
|
WGPURequestAdapterOptions adapter_options = {};
|
||||||
|
|
||||||
|
WGPUAdapter local_adapter = nullptr;
|
||||||
|
WGPURequestAdapterCallbackInfo adapterCallbackInfo = {};
|
||||||
|
adapterCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly;
|
||||||
|
adapterCallbackInfo.callback = handle_request_adapter;
|
||||||
|
adapterCallbackInfo.userdata1 = &local_adapter;
|
||||||
|
|
||||||
|
WGPUFuture future = wgpuInstanceRequestAdapter(instance, &adapter_options, adapterCallbackInfo);
|
||||||
|
WGPUFutureWaitInfo waitInfo = { future, false };
|
||||||
|
wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull);
|
||||||
|
IM_ASSERT(local_adapter && "Error on Adapter request");
|
||||||
|
return local_adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
static WGPUDevice RequestDevice(WGPUInstance& instance, WGPUAdapter& adapter)
|
||||||
|
{
|
||||||
|
WGPUDevice local_device = nullptr;
|
||||||
|
WGPURequestDeviceCallbackInfo deviceCallbackInfo = {};
|
||||||
|
deviceCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly;
|
||||||
|
deviceCallbackInfo.callback = handle_request_device;
|
||||||
|
deviceCallbackInfo.userdata1 = &local_device;
|
||||||
|
WGPUFuture future = wgpuAdapterRequestDevice(adapter, nullptr, deviceCallbackInfo);
|
||||||
|
WGPUFutureWaitInfo waitInfo = { future, false };
|
||||||
|
wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull);
|
||||||
|
IM_ASSERT(local_device && "Error on Device request");
|
||||||
|
return local_device;
|
||||||
|
}
|
||||||
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
|
bool InitWGPU(GLFWwindow* window)
|
||||||
|
{
|
||||||
|
WGPUTextureFormat preferred_fmt = WGPUTextureFormat_Undefined; // acquired from SurfaceCapabilities
|
||||||
|
|
||||||
|
// Google DAWN backend: Adapter and Device acquisition, Surface creation
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
|
wgpu::InstanceDescriptor instance_desc = {};
|
||||||
|
static constexpr wgpu::InstanceFeatureName timedWaitAny = wgpu::InstanceFeatureName::TimedWaitAny;
|
||||||
|
instance_desc.requiredFeatureCount = 1;
|
||||||
|
instance_desc.requiredFeatures = &timedWaitAny;
|
||||||
|
wgpu::Instance instance = wgpu::CreateInstance(&instance_desc);
|
||||||
|
|
||||||
|
wgpu::Adapter adapter = RequestAdapter(instance);
|
||||||
|
ImGui_ImplWGPU_DebugPrintAdapterInfo(adapter.Get());
|
||||||
|
|
||||||
|
wgpu_device = RequestDevice(instance, adapter);
|
||||||
|
|
||||||
|
// Create the surface.
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
wgpu::SurfaceDescriptorFromCanvasHTMLSelector html_surface_desc = {};
|
wgpu::EmscriptenSurfaceSourceCanvasHTMLSelector canvas_desc = {};
|
||||||
html_surface_desc.selector = "#canvas";
|
canvas_desc.selector = "#canvas";
|
||||||
|
|
||||||
wgpu::SurfaceDescriptor surface_desc = {};
|
wgpu::SurfaceDescriptor surface_desc = {};
|
||||||
surface_desc.nextInChain = &html_surface_desc;
|
surface_desc.nextInChain = &canvas_desc;
|
||||||
wgpu::Surface surface = instance.CreateSurface(&surface_desc);
|
wgpu_surface = instance.CreateSurface(&surface_desc).MoveToCHandle();
|
||||||
|
|
||||||
wgpu::Adapter adapter = {};
|
|
||||||
wgpu_preferred_fmt = (WGPUTextureFormat)surface.GetPreferredFormat(adapter);
|
|
||||||
#else
|
#else
|
||||||
wgpu::Surface surface = wgpu::glfw::CreateSurfaceForWindow(instance, window);
|
wgpu_surface = CreateWGPUSurface(instance.Get(), window);
|
||||||
if (!surface)
|
#endif
|
||||||
|
if (!wgpu_surface)
|
||||||
return false;
|
return false;
|
||||||
wgpu_preferred_fmt = WGPUTextureFormat_BGRA8Unorm;
|
|
||||||
|
// Moving Dawn objects into WGPU handles
|
||||||
|
wgpu_instance = instance.MoveToCHandle();
|
||||||
|
|
||||||
|
WGPUSurfaceCapabilities surface_capabilities = {};
|
||||||
|
wgpuSurfaceGetCapabilities(wgpu_surface, adapter.Get(), &surface_capabilities);
|
||||||
|
|
||||||
|
preferred_fmt = surface_capabilities.formats[0];
|
||||||
|
|
||||||
|
// WGPU backend: Adapter and Device acquisition, Surface creation
|
||||||
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK)
|
||||||
|
WGPUInstanceDescriptor instanceDesc = {};
|
||||||
|
WGPUInstanceFeatureName timedWaitAny = WGPUInstanceFeatureName_TimedWaitAny;
|
||||||
|
instanceDesc.requiredFeatureCount = 1;
|
||||||
|
instanceDesc.requiredFeatures = &timedWaitAny;
|
||||||
|
wgpu_instance = wgpuCreateInstance(&instanceDesc);
|
||||||
|
|
||||||
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
|
wgpuSetLogCallback(
|
||||||
|
[](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr
|
||||||
|
);
|
||||||
|
wgpuSetLogLevel(WGPULogLevel_Warn);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wgpu_instance = instance.MoveToCHandle();
|
WGPUAdapter adapter = RequestAdapter(wgpu_instance);
|
||||||
wgpu_surface = surface.MoveToCHandle();
|
ImGui_ImplWGPU_DebugPrintAdapterInfo(adapter);
|
||||||
|
|
||||||
wgpuDeviceSetUncapturedErrorCallback(wgpu_device, wgpu_error_callback, nullptr);
|
wgpu_device = RequestDevice(wgpu_instance, adapter);
|
||||||
|
|
||||||
|
// Create the surface.
|
||||||
|
wgpu_surface = CreateWGPUSurface(wgpu_instance, window);
|
||||||
|
if (!wgpu_surface)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
WGPUSurfaceCapabilities surface_capabilities = {};
|
||||||
|
wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities);
|
||||||
|
|
||||||
|
preferred_fmt = surface_capabilities.formats[0];
|
||||||
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
|
wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo;
|
||||||
|
wgpu_surface_configuration.alphaMode = WGPUCompositeAlphaMode_Auto;
|
||||||
|
wgpu_surface_configuration.usage = WGPUTextureUsage_RenderAttachment;
|
||||||
|
wgpu_surface_configuration.width = wgpu_surface_width;
|
||||||
|
wgpu_surface_configuration.height = wgpu_surface_height;
|
||||||
|
wgpu_surface_configuration.device = wgpu_device;
|
||||||
|
wgpu_surface_configuration.format = preferred_fmt;
|
||||||
|
|
||||||
|
wgpuSurfaceConfigure(wgpu_surface, &wgpu_surface_configuration);
|
||||||
|
wgpu_queue = wgpuDeviceGetQueue(wgpu_device);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CreateSwapChain(int width, int height)
|
// GLFW helper to create a WebGPU surface, used only in WGPU-Native. DAWN-Native already has a built-in function
|
||||||
|
// As of today (2025/10) there is no "official" support in GLFW to create a surface for WebGPU backend
|
||||||
|
// This stub uses "low level" GLFW calls to acquire information from a specific Window Manager.
|
||||||
|
// Currently supported platforms: Windows / Linux (X11 and Wayland) / MacOS. Not necessary nor available with EMSCRIPTEN.
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
|
|
||||||
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
||||||
|
#define GLFW_HAS_X11_OR_WAYLAND 1
|
||||||
|
#else
|
||||||
|
#define GLFW_HAS_X11_OR_WAYLAND 0
|
||||||
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
#undef APIENTRY
|
||||||
|
#ifndef GLFW_EXPOSE_NATIVE_WIN32 // for glfwGetWin32Window()
|
||||||
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
|
#endif
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#ifndef GLFW_EXPOSE_NATIVE_COCOA // for glfwGetCocoaWindow()
|
||||||
|
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||||
|
#endif
|
||||||
|
#elif GLFW_HAS_X11_OR_WAYLAND
|
||||||
|
#ifndef GLFW_EXPOSE_NATIVE_X11 // for glfwGetX11Display(), glfwGetX11Window() on Freedesktop (Linux, BSD, etc.)
|
||||||
|
#define GLFW_EXPOSE_NATIVE_X11
|
||||||
|
#endif
|
||||||
|
#ifndef GLFW_EXPOSE_NATIVE_WAYLAND
|
||||||
|
#if defined(__has_include) && __has_include(<wayland-client.h>)
|
||||||
|
#define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#include <GLFW/glfw3native.h>
|
||||||
|
#undef Status // X11 headers are leaking this and also 'Success', 'Always', 'None', all used in DAWN api. Add #undef if necessary.
|
||||||
|
|
||||||
|
WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, GLFWwindow* window)
|
||||||
{
|
{
|
||||||
if (wgpu_swap_chain)
|
ImGui_ImplWGPU_CreateSurfaceInfo create_info = {};
|
||||||
wgpuSwapChainRelease(wgpu_swap_chain);
|
create_info.Instance = instance;
|
||||||
wgpu_swap_chain_width = width;
|
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
|
||||||
wgpu_swap_chain_height = height;
|
{
|
||||||
WGPUSwapChainDescriptor swap_chain_desc = {};
|
create_info.System = "cocoa";
|
||||||
swap_chain_desc.usage = WGPUTextureUsage_RenderAttachment;
|
create_info.RawWindow = (void*)glfwGetCocoaWindow(window);
|
||||||
swap_chain_desc.format = wgpu_preferred_fmt;
|
return ImGui_ImplWGPU_CreateWGPUSurfaceHelper(&create_info);
|
||||||
swap_chain_desc.width = width;
|
}
|
||||||
swap_chain_desc.height = height;
|
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
|
||||||
swap_chain_desc.presentMode = WGPUPresentMode_Fifo;
|
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
|
||||||
wgpu_swap_chain = wgpuDeviceCreateSwapChain(wgpu_device, wgpu_surface, &swap_chain_desc);
|
{
|
||||||
|
create_info.System = "wayland";
|
||||||
|
create_info.RawDisplay = (void*)glfwGetWaylandDisplay();
|
||||||
|
create_info.RawSurface = (void*)glfwGetWaylandWindow(window);
|
||||||
|
return ImGui_ImplWGPU_CreateWGPUSurfaceHelper(&create_info);
|
||||||
|
}
|
||||||
|
#elif defined(GLFW_EXPOSE_NATIVE_X11)
|
||||||
|
if (glfwGetPlatform() == GLFW_PLATFORM_X11)
|
||||||
|
{
|
||||||
|
create_info.System = "x11";
|
||||||
|
create_info.RawWindow = (void*)glfwGetX11Window(window);
|
||||||
|
create_info.RawDisplay = (void*)glfwGetX11Display();
|
||||||
|
return ImGui_ImplWGPU_CreateWGPUSurfaceHelper(&create_info);
|
||||||
|
}
|
||||||
|
#elif defined(GLFW_EXPOSE_NATIVE_WIN32)
|
||||||
|
{
|
||||||
|
create_info.System = "win32";
|
||||||
|
create_info.RawWindow = (void*)glfwGetWin32Window(window);
|
||||||
|
create_info.RawInstance = (void*)::GetModuleHandle(NULL);
|
||||||
|
return ImGui_ImplWGPU_CreateWGPUSurfaceHelper(&create_info);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error "Unsupported WebGPU native platform!"
|
||||||
|
return nullptr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif // #ifndef __EMSCRIPTEN__
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en-us">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
|
|
||||||
<title>Dear ImGui Emscripten+GLFW+WebGPU example</title>
|
|
||||||
<style>
|
|
||||||
body { margin: 0; background-color: black }
|
|
||||||
.emscripten {
|
|
||||||
position: absolute;
|
|
||||||
top: 0px;
|
|
||||||
left: 0px;
|
|
||||||
margin: 0px;
|
|
||||||
border: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
display: block;
|
|
||||||
image-rendering: optimizeSpeed;
|
|
||||||
image-rendering: -moz-crisp-edges;
|
|
||||||
image-rendering: -o-crisp-edges;
|
|
||||||
image-rendering: -webkit-optimize-contrast;
|
|
||||||
image-rendering: optimize-contrast;
|
|
||||||
image-rendering: crisp-edges;
|
|
||||||
image-rendering: pixelated;
|
|
||||||
-ms-interpolation-mode: nearest-neighbor;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
|
||||||
<script type='text/javascript'>
|
|
||||||
var Module;
|
|
||||||
(async () => {
|
|
||||||
Module = {
|
|
||||||
preRun: [],
|
|
||||||
postRun: [],
|
|
||||||
print: (function() {
|
|
||||||
return function(text) {
|
|
||||||
text = Array.prototype.slice.call(arguments).join(' ');
|
|
||||||
console.log(text);
|
|
||||||
};
|
|
||||||
})(),
|
|
||||||
printErr: function(text) {
|
|
||||||
text = Array.prototype.slice.call(arguments).join(' ');
|
|
||||||
console.error(text);
|
|
||||||
},
|
|
||||||
canvas: (function() {
|
|
||||||
var canvas = document.getElementById('canvas');
|
|
||||||
//canvas.addEventListener("webglcontextlost", function(e) { alert('FIXME: WebGL context lost, please reload the page'); e.preventDefault(); }, false);
|
|
||||||
return canvas;
|
|
||||||
})(),
|
|
||||||
setStatus: function(text) {
|
|
||||||
console.log("status: " + text);
|
|
||||||
},
|
|
||||||
monitorRunDependencies: function(left) {
|
|
||||||
// no run dependencies to log
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.onerror = function() {
|
|
||||||
console.log("onerror: " + event);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialize the graphics adapter
|
|
||||||
{
|
|
||||||
if (!navigator.gpu) {
|
|
||||||
throw Error("WebGPU not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const adapter = await navigator.gpu.requestAdapter();
|
|
||||||
const device = await adapter.requestDevice();
|
|
||||||
Module.preinitializedWebGPUDevice = device;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const js = document.createElement('script');
|
|
||||||
js.async = true;
|
|
||||||
js.src = "index.js";
|
|
||||||
document.body.appendChild(js);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -80,14 +80,16 @@ int main(int argc, char** argv)
|
|||||||
ImGui_ImplGLUT_InstallFuncs();
|
ImGui_ImplGLUT_InstallFuncs();
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
179
examples/example_null/example_null.vcxproj
Normal file
179
examples/example_null/example_null.vcxproj
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>{1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}</ProjectGuid>
|
||||||
|
<RootNamespace>example_win32_directx11</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
||||||
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<AdditionalDependencies>d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
||||||
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<AdditionalDependencies>d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\backends\imgui_impl_null.h" />
|
||||||
|
<ClInclude Include="..\..\imconfig.h" />
|
||||||
|
<ClInclude Include="..\..\imgui.h" />
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\backends\imgui_impl_null.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_tables.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_widgets.cpp" />
|
||||||
|
<ClCompile Include="main.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\..\misc\debuggers\imgui.natstepfilter" />
|
||||||
|
<None Include="..\..\misc\debuggers\imgui.natvis" />
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
57
examples/example_null/example_null.vcxproj.filters
Normal file
57
examples/example_null/example_null.vcxproj.filters
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="imgui">
|
||||||
|
<UniqueIdentifier>{0587d7a3-f2ce-4d56-b84f-a0005d3bfce6}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="sources">
|
||||||
|
<UniqueIdentifier>{08e36723-ce4f-4cff-9662-c40801cf1acf}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\imconfig.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\imgui.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\backends\imgui_impl_null.h">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\imgui.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="main.cpp">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_tables.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_widgets.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\backends\imgui_impl_null.cpp">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
<None Include="..\..\misc\debuggers\imgui.natvis">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\misc\debuggers\imgui.natstepfilter">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -4,23 +4,26 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// For imgui_impl_null: use relative filename + embed implementation directly by including the .cpp file.
|
||||||
|
// This is to simplify casual building of this example from all sorts of test scripts.
|
||||||
|
#include "../../backends/imgui_impl_null.h"
|
||||||
|
#include "../../backends/imgui_impl_null.cpp"
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
|
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
// Build atlas
|
ImGui_ImplNullPlatform_Init();
|
||||||
//unsigned char* tex_pixels = nullptr;
|
ImGui_ImplNullRender_Init();
|
||||||
//int tex_w, tex_h;
|
|
||||||
//io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h);
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures;
|
|
||||||
|
|
||||||
for (int n = 0; n < 20; n++)
|
for (int n = 0; n < 20; n++)
|
||||||
{
|
{
|
||||||
printf("NewFrame() %d\n", n);
|
printf("NewFrame() %d\n", n);
|
||||||
io.DisplaySize = ImVec2(1920, 1080);
|
ImGui_ImplNullPlatform_NewFrame();
|
||||||
io.DeltaTime = 1.0f / 60.0f;
|
ImGui_ImplNullRender_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
static float f = 0.0f;
|
static float f = 0.0f;
|
||||||
@@ -33,6 +36,8 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("DestroyContext()\n");
|
printf("DestroyContext()\n");
|
||||||
|
ImGui_ImplNullRender_Shutdown();
|
||||||
|
ImGui_ImplNullPlatform_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,27 +29,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -54,7 +54,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SysWMinfo wmInfo;
|
SDL_SysWMinfo wmInfo;
|
||||||
@@ -87,7 +87,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -103,14 +103,16 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
|
ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
@@ -230,6 +232,7 @@ int main(int, char**)
|
|||||||
bool CreateDeviceD3D(HWND hWnd)
|
bool CreateDeviceD3D(HWND hWnd)
|
||||||
{
|
{
|
||||||
// Setup swap chain
|
// Setup swap chain
|
||||||
|
// This is a basic setup. Optimally could use e.g. DXGI_SWAP_EFFECT_FLIP_DISCARD and handle fullscreen mode differently. See #8979 for suggestions.
|
||||||
DXGI_SWAP_CHAIN_DESC sd;
|
DXGI_SWAP_CHAIN_DESC sd;
|
||||||
ZeroMemory(&sd, sizeof(sd));
|
ZeroMemory(&sd, sizeof(sd));
|
||||||
sd.BufferCount = 2;
|
sd.BufferCount = 2;
|
||||||
@@ -250,9 +253,22 @@ bool CreateDeviceD3D(HWND hWnd)
|
|||||||
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||||
D3D_FEATURE_LEVEL featureLevel;
|
D3D_FEATURE_LEVEL featureLevel;
|
||||||
const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
|
const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
|
||||||
if (D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
|
HRESULT res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
|
||||||
|
if (res == DXGI_ERROR_UNSUPPORTED) // Try high-performance WARP software driver if hardware is not available.
|
||||||
|
res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_WARP, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
|
||||||
|
if (res != S_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Disable DXGI's default Alt+Enter fullscreen behavior.
|
||||||
|
// - You are free to leave this enabled, but it will not work properly with multiple viewports.
|
||||||
|
// - This must be done for all windows associated to the device. Our DX11 backend does this automatically for secondary viewports that it creates.
|
||||||
|
IDXGIFactory* pSwapChainFactory;
|
||||||
|
if (SUCCEEDED(g_pSwapChain->GetParent(IID_PPV_ARGS(&pSwapChainFactory))))
|
||||||
|
{
|
||||||
|
pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER);
|
||||||
|
pSwapChainFactory->Release();
|
||||||
|
}
|
||||||
|
|
||||||
CreateRenderTarget();
|
CreateRenderTarget();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,16 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
@@ -61,7 +63,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.
|
// Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.
|
||||||
|
|||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -51,7 +51,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
@@ -76,7 +76,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -92,14 +92,16 @@ int main(int, char**)
|
|||||||
ImGui_ImplOpenGL2_Init();
|
ImGui_ImplOpenGL2_Init();
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide GL+GLSL versions
|
// Decide GL+GLSL versions
|
||||||
@@ -85,14 +85,14 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
if (gl_context == nullptr)
|
if (gl_context == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
@@ -116,7 +116,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -132,15 +132,17 @@ int main(int, char**)
|
|||||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -29,27 +29,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
@@ -184,4 +184,4 @@
|
|||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -33,7 +33,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -48,13 +48,13 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||||
if (renderer == nullptr)
|
if (renderer == nullptr)
|
||||||
{
|
{
|
||||||
SDL_Log("Error creating SDL_Renderer!");
|
SDL_Log("Error creating SDL_Renderer!");
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
//SDL_RendererInfo info;
|
//SDL_RendererInfo info;
|
||||||
//SDL_GetRendererInfo(renderer, &info);
|
//SDL_GetRendererInfo(renderer, &info);
|
||||||
@@ -75,7 +75,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -84,14 +84,16 @@ int main(int, char**)
|
|||||||
ImGui_ImplSDLRenderer2_Init(renderer);
|
ImGui_ImplSDLRenderer2_Init(renderer);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
|
|||||||
@@ -28,27 +28,27 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
@@ -187,4 +187,4 @@
|
|||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -184,7 +184,8 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
{
|
{
|
||||||
VkDescriptorPoolSize pool_sizes[] =
|
VkDescriptorPoolSize pool_sizes[] =
|
||||||
{
|
{
|
||||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE },
|
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, IMGUI_IMPL_VULKAN_MINIMUM_SAMPLED_IMAGE_POOL_SIZE },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_SAMPLER_POOL_SIZE },
|
||||||
};
|
};
|
||||||
VkDescriptorPoolCreateInfo pool_info = {};
|
VkDescriptorPoolCreateInfo pool_info = {};
|
||||||
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
@@ -192,7 +193,7 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
pool_info.maxSets = 0;
|
pool_info.maxSets = 0;
|
||||||
for (VkDescriptorPoolSize& pool_size : pool_sizes)
|
for (VkDescriptorPoolSize& pool_size : pool_sizes)
|
||||||
pool_info.maxSets += pool_size.descriptorCount;
|
pool_info.maxSets += pool_size.descriptorCount;
|
||||||
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
|
pool_info.poolSizeCount = (uint32_t)IM_COUNTOF(pool_sizes);
|
||||||
pool_info.pPoolSizes = pool_sizes;
|
pool_info.pPoolSizes = pool_sizes;
|
||||||
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);
|
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
@@ -203,11 +204,9 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
// Your real engine/app may not use them.
|
// Your real engine/app may not use them.
|
||||||
static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
|
static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
|
||||||
{
|
{
|
||||||
wd->Surface = surface;
|
|
||||||
|
|
||||||
// Check for WSI support
|
// Check for WSI support
|
||||||
VkBool32 res;
|
VkBool32 res;
|
||||||
vkGetPhysicalDeviceSurfaceSupportKHR(g_PhysicalDevice, g_QueueFamily, wd->Surface, &res);
|
vkGetPhysicalDeviceSurfaceSupportKHR(g_PhysicalDevice, g_QueueFamily, surface, &res);
|
||||||
if (res != VK_TRUE)
|
if (res != VK_TRUE)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error no WSI support on physical device 0\n");
|
fprintf(stderr, "Error no WSI support on physical device 0\n");
|
||||||
@@ -217,7 +216,8 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
|
|||||||
// Select Surface Format
|
// Select Surface Format
|
||||||
const VkFormat requestSurfaceImageFormat[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
|
const VkFormat requestSurfaceImageFormat[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
|
||||||
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
|
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
|
||||||
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace);
|
wd->Surface = surface;
|
||||||
|
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_COUNTOF(requestSurfaceImageFormat), requestSurfaceColorSpace);
|
||||||
|
|
||||||
// Select Present Mode
|
// Select Present Mode
|
||||||
#ifdef APP_USE_UNLIMITED_FRAME_RATE
|
#ifdef APP_USE_UNLIMITED_FRAME_RATE
|
||||||
@@ -225,12 +225,12 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
|
|||||||
#else
|
#else
|
||||||
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_FIFO_KHR };
|
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_FIFO_KHR };
|
||||||
#endif
|
#endif
|
||||||
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(g_PhysicalDevice, wd->Surface, &present_modes[0], IM_ARRAYSIZE(present_modes));
|
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(g_PhysicalDevice, wd->Surface, &present_modes[0], IM_COUNTOF(present_modes));
|
||||||
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
|
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
|
||||||
|
|
||||||
// Create SwapChain, RenderPass, Framebuffer, etc.
|
// Create SwapChain, RenderPass, Framebuffer, etc.
|
||||||
IM_ASSERT(g_MinImageCount >= 2);
|
IM_ASSERT(g_MinImageCount >= 2);
|
||||||
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
|
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CleanupVulkan()
|
static void CleanupVulkan()
|
||||||
@@ -247,9 +247,10 @@ static void CleanupVulkan()
|
|||||||
vkDestroyInstance(g_Instance, g_Allocator);
|
vkDestroyInstance(g_Instance, g_Allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CleanupVulkanWindow()
|
static void CleanupVulkanWindow(ImGui_ImplVulkanH_Window* wd)
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, &g_MainWindowData, g_Allocator);
|
ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, wd, g_Allocator);
|
||||||
|
vkDestroySurfaceKHR(g_Instance, wd->Surface, g_Allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
|
static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
|
||||||
@@ -349,7 +350,7 @@ int main(int, char**)
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From 2.0.18: Enable native IME.
|
// From 2.0.18: Enable native IME.
|
||||||
@@ -364,7 +365,7 @@ int main(int, char**)
|
|||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVector<const char*> extensions;
|
ImVector<const char*> extensions;
|
||||||
@@ -385,7 +386,7 @@ int main(int, char**)
|
|||||||
|
|
||||||
// Create Framebuffers
|
// Create Framebuffers
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_GetWindowSize(window, &w, &h);
|
SDL_GetWindowSizeInPixels(window, &w, &h);
|
||||||
ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
|
ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
|
||||||
SetupVulkanWindow(wd, surface, w, h);
|
SetupVulkanWindow(wd, surface, w, h);
|
||||||
|
|
||||||
@@ -407,7 +408,7 @@ int main(int, char**)
|
|||||||
// Setup scaling
|
// Setup scaling
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
||||||
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor)
|
||||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||||
|
|
||||||
@@ -429,24 +430,26 @@ int main(int, char**)
|
|||||||
init_info.Queue = g_Queue;
|
init_info.Queue = g_Queue;
|
||||||
init_info.PipelineCache = g_PipelineCache;
|
init_info.PipelineCache = g_PipelineCache;
|
||||||
init_info.DescriptorPool = g_DescriptorPool;
|
init_info.DescriptorPool = g_DescriptorPool;
|
||||||
init_info.RenderPass = wd->RenderPass;
|
|
||||||
init_info.Subpass = 0;
|
|
||||||
init_info.MinImageCount = g_MinImageCount;
|
init_info.MinImageCount = g_MinImageCount;
|
||||||
init_info.ImageCount = wd->ImageCount;
|
init_info.ImageCount = wd->ImageCount;
|
||||||
init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
|
||||||
init_info.Allocator = g_Allocator;
|
init_info.Allocator = g_Allocator;
|
||||||
|
init_info.PipelineInfoMain.RenderPass = wd->RenderPass;
|
||||||
|
init_info.PipelineInfoMain.Subpass = 0;
|
||||||
|
init_info.PipelineInfoMain.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
init_info.CheckVkResultFn = check_vk_result;
|
init_info.CheckVkResultFn = check_vk_result;
|
||||||
ImGui_ImplVulkan_Init(&init_info);
|
ImGui_ImplVulkan_Init(&init_info);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
|
||||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//style.FontSizeBase = 20.0f;
|
//style.FontSizeBase = 20.0f;
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefaultVector();
|
||||||
|
//io.Fonts->AddFontDefaultBitmap();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf");
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf");
|
||||||
@@ -485,11 +488,11 @@ int main(int, char**)
|
|||||||
|
|
||||||
// Resize swap chain?
|
// Resize swap chain?
|
||||||
int fb_width, fb_height;
|
int fb_width, fb_height;
|
||||||
SDL_GetWindowSize(window, &fb_width, &fb_height);
|
SDL_GetWindowSizeInPixels(window, &fb_width, &fb_height);
|
||||||
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
|
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
|
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
|
||||||
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount);
|
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, 0);
|
||||||
g_MainWindowData.FrameIndex = 0;
|
g_MainWindowData.FrameIndex = 0;
|
||||||
g_SwapChainRebuild = false;
|
g_SwapChainRebuild = false;
|
||||||
}
|
}
|
||||||
@@ -566,7 +569,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplSDL2_Shutdown();
|
ImGui_ImplSDL2_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
CleanupVulkanWindow();
|
CleanupVulkanWindow(&g_MainWindowData);
|
||||||
CleanupVulkan();
|
CleanupVulkan();
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
|||||||
237
examples/example_sdl2_wgpu/CMakeLists.txt
Normal file
237
examples/example_sdl2_wgpu/CMakeLists.txt
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
# Building for desktop with Dawn:
|
||||||
|
# 1. git clone https://github.com/google/dawn dawn
|
||||||
|
# 2. cmake -B build -DIMGUI_DAWN_DIR=dawn
|
||||||
|
# 3. cmake --build build
|
||||||
|
# The resulting binary will be found at one of the following locations:
|
||||||
|
# * build/example_sdl2_wgpu[.exe] or build/Debug/example_sdl2_wgpu[.exe]
|
||||||
|
|
||||||
|
# Building for desktop with WGPU-Native:
|
||||||
|
# 1. download WGPU-Native autogenerated binary modules for your platform/compiler from: https://github.com/gfx-rs/wgpu-native/releases
|
||||||
|
# 2. unzip the downloaded file in your_preferred_folder
|
||||||
|
# 3. cmake -B build -DIMGUI_WGPU_DIR=your_preferred_folder ("full path" or "relative" starting from current directory)
|
||||||
|
# 4. cmake --build build
|
||||||
|
# The resulting binary will be found at one of the following locations:
|
||||||
|
# * build/example_sdl2_wgpu[.exe] or build/Debug/example_sdl2_wgpu[.exe]
|
||||||
|
|
||||||
|
# Building for desktop with WGVK (MUCH EASIER)
|
||||||
|
# 1. git clone https://github.com/manuel5975p/WGVK wgvk
|
||||||
|
# 2. cmake -B build -DIMGUI_WGVK_DIR=wgvk
|
||||||
|
# 3. cmake --build build
|
||||||
|
# The resulting binary will be found at one of the following locations:
|
||||||
|
# * build/example_sdl2_wgpu[.exe] or build/Debug/example_sdl2_wgpu[.exe]
|
||||||
|
|
||||||
|
# Building for Emscripten:
|
||||||
|
# 1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
|
||||||
|
# 2. Install Ninja build system
|
||||||
|
# 3. emcmake cmake -G Ninja -B build
|
||||||
|
# (optional) -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py", see ReadMe.md
|
||||||
|
# 3. cmake --build build
|
||||||
|
# 4. emrun build/index.html
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.22) # Dawn requires CMake >= 3.22
|
||||||
|
project(imgui_example_sdl2_wgpu C CXX)
|
||||||
|
|
||||||
|
set(IMGUI_EXECUTABLE example_sdl2_wgpu)
|
||||||
|
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 10) # Dawn requires C++20
|
||||||
|
|
||||||
|
# Dear ImGui
|
||||||
|
set(IMGUI_DIR ../../)
|
||||||
|
|
||||||
|
# ImGui example commons source files
|
||||||
|
set(IMGUI_EXAMPLE_SOURCE_FILES
|
||||||
|
main.cpp
|
||||||
|
# backend files
|
||||||
|
${IMGUI_DIR}/backends/imgui_impl_sdl2.cpp
|
||||||
|
${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp
|
||||||
|
# Dear ImGui files
|
||||||
|
${IMGUI_DIR}/imgui.cpp
|
||||||
|
${IMGUI_DIR}/imgui_draw.cpp
|
||||||
|
${IMGUI_DIR}/imgui_demo.cpp
|
||||||
|
${IMGUI_DIR}/imgui_tables.cpp
|
||||||
|
${IMGUI_DIR}/imgui_widgets.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
if(EMSCRIPTEN)
|
||||||
|
if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.10")
|
||||||
|
set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Default to --use-port=emdawnwebgpu. You can override to provide your own local port.")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "emdawnwebgpu needs EMSCRIPTEN version >= 4.0.10")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_compile_options(-sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1)
|
||||||
|
else() # Native/Desktop build
|
||||||
|
|
||||||
|
# Check DAWN/WGPU/WGVK directory
|
||||||
|
# If it's Native/Desktop build, IMGUI_DAWN_DIR or IMGUI_WGPU_DIR or IMGUI_WGVK_DIR must be specified
|
||||||
|
if(NOT IMGUI_DAWN_DIR AND NOT IMGUI_WGPU_DIR AND NOT IMGUI_WGVK_DIR)
|
||||||
|
message(FATAL_ERROR "Please specify one of IMGUI_DAWN_DIR/IMGUI_WGPU_DIR/IMGUI_WGVK_DIR base directory.")
|
||||||
|
endif()
|
||||||
|
if((IMGUI_DAWN_DIR AND (IMGUI_WGPU_DIR OR IMGUI_WGVK_DIR)) OR (IMGUI_WGPU_DIR AND IMGUI_WGVK_DIR))
|
||||||
|
message(FATAL_ERROR "Please specify only one of IMGUI_DAWN_DIR/IMGUI_WGPU_DIR/IMGUI_WGVK_DIR base directory.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(APPLE) # Add SDL2 module to get Surface, with libs and file property for MacOS build
|
||||||
|
set_source_files_properties(${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++")
|
||||||
|
set(OS_LIBRARIES "-framework CoreFoundation -framework QuartzCore -framework Metal -framework MetalKit -framework Cocoa")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(SDL2 REQUIRED) # SDL_MAIN_HANDLED
|
||||||
|
|
||||||
|
if(IMGUI_DAWN_DIR)
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH ${IMGUI_DAWN_DIR})
|
||||||
|
find_package(Threads) # required from Dawn installation
|
||||||
|
find_package(Dawn) # Search for a Dawn installation using IMGUI_DAWN_DIR in CMAKE_PREFIX_PATH
|
||||||
|
if(Dawn_FOUND)
|
||||||
|
message("Dawn Installation has been found!")
|
||||||
|
set(LIBRARIES dawn::webgpu_dawn ${OS_LIBRARIES})
|
||||||
|
else()
|
||||||
|
set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository")
|
||||||
|
|
||||||
|
option(DAWN_USE_GLFW OFF) # disable builtin GLFW in DAWN when we use SDL2 / SDL3
|
||||||
|
|
||||||
|
option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON)
|
||||||
|
set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE STRING "Build monolithic library: SHARED, STATIC, or OFF.")
|
||||||
|
|
||||||
|
# Dawn builds many things by default - disable things we don't need
|
||||||
|
option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF)
|
||||||
|
option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF)
|
||||||
|
option(TINT_BUILD_DOCS "Build documentation" OFF)
|
||||||
|
option(TINT_BUILD_TESTS "Build tests" OFF)
|
||||||
|
if(NOT APPLE)
|
||||||
|
option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF)
|
||||||
|
endif()
|
||||||
|
if(WIN32)
|
||||||
|
option(DAWN_FORCE_SYSTEM_COMPONENT_LOAD "Allow system component fallback" ON)
|
||||||
|
option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF)
|
||||||
|
option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
|
||||||
|
option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF)
|
||||||
|
option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF)
|
||||||
|
option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ON)
|
||||||
|
option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
|
||||||
|
endif()
|
||||||
|
# check if WAYLAND is the current Session Type and enable DAWN_USE_WAYLAND Wayland option @compile time
|
||||||
|
# You can override this using: cmake -DDAWN_USE_WAYLAND=X (X = ON | OFF)
|
||||||
|
if(LINUX)
|
||||||
|
if($ENV{XDG_SESSION_TYPE} MATCHES wayland)
|
||||||
|
option(DAWN_USE_WAYLAND "Enable support for Wayland surface" ON)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory("${IMGUI_DAWN_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/dawn" EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
|
set(LIBRARIES webgpu_dawn ${OS_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(IMGUI_WGPU_DIR)
|
||||||
|
set(WGPU_NATIVE_LIB_DIR ${IMGUI_WGPU_DIR}/lib)
|
||||||
|
find_library(WGPU_LIBRARY NAMES libwgpu_native.a wgpu_native.lib wgpu_native HINTS ${WGPU_NATIVE_LIB_DIR} REQUIRED)
|
||||||
|
if(WIN32)
|
||||||
|
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32 Propsys RuntimeObject)
|
||||||
|
elseif(UNIX AND NOT APPLE)
|
||||||
|
set(OS_LIBRARIES "-lm -ldl")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(LIBRARIES ${WGPU_LIBRARY} ${OS_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(IMGUI_WGVK_DIR)
|
||||||
|
find_package(Vulkan REQUIRED)
|
||||||
|
set(WGVK_PLATFORM_LIBS)
|
||||||
|
set(WGVK_PLATFORM_DEFS)
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_WIN32_SURFACE=1)
|
||||||
|
elseif(APPLE)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_METAL_SURFACE=1)
|
||||||
|
elseif(UNIX)
|
||||||
|
find_package(PkgConfig QUIET)
|
||||||
|
pkg_check_modules(WAYLAND_CLIENT QUIET wayland-client)
|
||||||
|
if(WAYLAND_CLIENT_FOUND)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_WAYLAND_SURFACE=1)
|
||||||
|
list(APPEND WGVK_PLATFORM_LIBS ${WAYLAND_CLIENT_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
find_package(X11 QUIET)
|
||||||
|
if(X11_FOUND)
|
||||||
|
list(APPEND WGVK_PLATFORM_DEFS SUPPORT_XLIB_SURFACE=1)
|
||||||
|
list(APPEND WGVK_PLATFORM_LIBS X11::X11)
|
||||||
|
endif()
|
||||||
|
list(APPEND WGVK_PLATFORM_LIBS m dl pthread)
|
||||||
|
endif()
|
||||||
|
set(LIBRARIES glfw Vulkan::Vulkan ${WGVK_PLATFORM_LIBS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(${IMGUI_EXECUTABLE} ${IMGUI_EXAMPLE_SOURCE_FILES})
|
||||||
|
|
||||||
|
target_include_directories(${IMGUI_EXECUTABLE} PUBLIC
|
||||||
|
${IMGUI_DIR}
|
||||||
|
${IMGUI_DIR}/backends
|
||||||
|
${SDL2_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_EXAMPLE_SDL2_WGPU")
|
||||||
|
|
||||||
|
# compiler option only for IMGUI_EXAMPLE_SOURCE_FILES
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC /W4) # warning level 4
|
||||||
|
else()
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC -Wall) # -Wextra -Wpedantic
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# IMGUI_IMPL_WEBGPU_BACKEND_DAWN/WGPU internal define is set according to:
|
||||||
|
# EMSCRIPTEN: by used FLAG
|
||||||
|
# --use-port=emdawnwebgpu --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN enabled (+EMSCRIPTEN)
|
||||||
|
# NATIVE: by used SDK installation directory
|
||||||
|
# if IMGUI_DAWN_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN enabled
|
||||||
|
# if IMGUI_WGPU_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU enabled
|
||||||
|
|
||||||
|
if(NOT EMSCRIPTEN) # WegGPU-Native settings
|
||||||
|
if(IMGUI_DAWN_DIR)
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN")
|
||||||
|
if(NOT Dawn_FOUND)
|
||||||
|
target_link_libraries(${IMGUI_EXECUTABLE} INTERFACE webgpu_cpp)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(IMGUI_WGPU_DIR)
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGPU")
|
||||||
|
target_include_directories(${IMGUI_EXECUTABLE} PUBLIC ${IMGUI_WGPU_DIR}/include)
|
||||||
|
endif()
|
||||||
|
if(IMGUI_WGVK_DIR)
|
||||||
|
target_sources(${IMGUI_EXECUTABLE} PRIVATE ${IMGUI_WGVK_DIR}/src/wgvk.c)
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGVK")
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PRIVATE ${WGVK_PLATFORM_DEFS})
|
||||||
|
target_include_directories(${IMGUI_EXECUTABLE} PUBLIC ${IMGUI_WGVK_DIR}/include)
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC /std:clatest /experimental:c11atomics)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(${IMGUI_EXECUTABLE} PUBLIC ${LIBRARIES} ${SDL2_LIBRARIES})
|
||||||
|
else() # Emscripten settings
|
||||||
|
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||||
|
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}")
|
||||||
|
target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN")
|
||||||
|
message(STATUS "Using ${IMGUI_EMSCRIPTEN_WEBGPU_FLAG} WebGPU implementation")
|
||||||
|
|
||||||
|
target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "-sUSE_SDL=2")
|
||||||
|
target_link_options(${IMGUI_EXECUTABLE} PRIVATE
|
||||||
|
"${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}"
|
||||||
|
"-sUSE_SDL=2"
|
||||||
|
"-sWASM=1"
|
||||||
|
"-sASYNCIFY=1"
|
||||||
|
"-sALLOW_MEMORY_GROWTH=1"
|
||||||
|
"-sNO_EXIT_RUNTIME=0"
|
||||||
|
"-sASSERTIONS=1"
|
||||||
|
"-sDISABLE_EXCEPTION_CATCHING=1"
|
||||||
|
"-sNO_FILESYSTEM=1"
|
||||||
|
"--shell-file=${CMAKE_CURRENT_LIST_DIR}/../libs/emscripten/shell_minimal.html"
|
||||||
|
)
|
||||||
|
set_target_properties(${IMGUI_EXECUTABLE} PROPERTIES OUTPUT_NAME "index")
|
||||||
|
endif()
|
||||||
99
examples/example_sdl2_wgpu/Makefile.emscripten
Normal file
99
examples/example_sdl2_wgpu/Makefile.emscripten
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#
|
||||||
|
# Makefile to use with emscripten
|
||||||
|
# See https://emscripten.org/docs/getting_started/downloads.html
|
||||||
|
# for installation instructions.
|
||||||
|
#
|
||||||
|
# This Makefile assumes you have loaded emscripten's environment.
|
||||||
|
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
||||||
|
#
|
||||||
|
# Running `make -f Makefile.emscripten` will produce three files:
|
||||||
|
# - web/index.html
|
||||||
|
# - web/index.js
|
||||||
|
# - web/index.wasm
|
||||||
|
#
|
||||||
|
# All three are needed to run the demo.
|
||||||
|
|
||||||
|
CC = emcc
|
||||||
|
CXX = em++
|
||||||
|
WEB_DIR = web
|
||||||
|
EXE = $(WEB_DIR)/index.html
|
||||||
|
IMGUI_DIR = ../..
|
||||||
|
SOURCES = main.cpp
|
||||||
|
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl2.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp
|
||||||
|
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
|
||||||
|
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
CPPFLAGS =
|
||||||
|
LDFLAGS =
|
||||||
|
EMS =
|
||||||
|
|
||||||
|
##---------------------------------------------------------------------
|
||||||
|
## EMSCRIPTEN OPTIONS
|
||||||
|
##---------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
|
||||||
|
EMS += -s USE_SDL=2
|
||||||
|
EMS += -s DISABLE_EXCEPTION_CATCHING=1
|
||||||
|
LDFLAGS += -s WASM=1
|
||||||
|
LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
|
||||||
|
LDFLAGS += -s ASYNCIFY=1
|
||||||
|
LDFLAGS += -s NO_EXIT_RUNTIME=0
|
||||||
|
LDFLAGS += -s ASSERTIONS=1
|
||||||
|
|
||||||
|
# Using Dawn-based WebGPU port (requires Emscripten >= 4.0.10)
|
||||||
|
EMS += --use-port=emdawnwebgpu
|
||||||
|
LDFLAGS += --use-port=emdawnwebgpu
|
||||||
|
|
||||||
|
# Build as single file (binary text encoded in .html file)
|
||||||
|
#LDFLAGS += -sSINGLE_FILE
|
||||||
|
|
||||||
|
# Emscripten allows preloading a file or folder to be accessible at runtime.
|
||||||
|
# The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
|
||||||
|
# See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
|
||||||
|
# (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
|
||||||
|
USE_FILE_SYSTEM ?= 0
|
||||||
|
ifeq ($(USE_FILE_SYSTEM), 0)
|
||||||
|
LDFLAGS += -s NO_FILESYSTEM=1
|
||||||
|
CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
|
||||||
|
endif
|
||||||
|
ifeq ($(USE_FILE_SYSTEM), 1)
|
||||||
|
LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
|
||||||
|
endif
|
||||||
|
|
||||||
|
##---------------------------------------------------------------------
|
||||||
|
## FINAL BUILD FLAGS
|
||||||
|
##---------------------------------------------------------------------
|
||||||
|
|
||||||
|
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
||||||
|
#CPPFLAGS += -g
|
||||||
|
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
||||||
|
LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
|
||||||
|
LDFLAGS += $(EMS)
|
||||||
|
|
||||||
|
##---------------------------------------------------------------------
|
||||||
|
## BUILD RULES
|
||||||
|
##---------------------------------------------------------------------
|
||||||
|
|
||||||
|
%.o:%.cpp
|
||||||
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
%.o:$(IMGUI_DIR)/%.cpp
|
||||||
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
%.o:$(IMGUI_DIR)/backends/%.cpp
|
||||||
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
all: $(EXE)
|
||||||
|
@echo Build complete for $(EXE)
|
||||||
|
|
||||||
|
$(WEB_DIR):
|
||||||
|
mkdir $@
|
||||||
|
|
||||||
|
serve: all
|
||||||
|
python3 -m http.server -d $(WEB_DIR)
|
||||||
|
|
||||||
|
$(EXE): $(OBJS) $(WEB_DIR)
|
||||||
|
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(EXE) $(OBJS) $(WEB_DIR)/*.js $(WEB_DIR)/*.wasm $(WEB_DIR)/*.wasm.pre
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user