Compare commits
617 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd82f6b04e | ||
|
|
cef3200533 | ||
|
|
634500c398 | ||
|
|
b3e294ac54 | ||
|
|
2bf7535ad0 | ||
|
|
3315f75de9 | ||
|
|
bbe7dbfa92 | ||
|
|
15001524bd | ||
|
|
c1713e7501 | ||
|
|
0181584735 | ||
|
|
df06e8dc41 | ||
|
|
5697922a65 | ||
|
|
4da83df2b9 | ||
|
|
8f156d6588 | ||
|
|
b0ce077ace | ||
|
|
9d29d2e32c | ||
|
|
a29b438161 | ||
|
|
50a042bb16 | ||
|
|
cec0871c11 | ||
|
|
41a809368b | ||
|
|
f690015a88 | ||
|
|
342deb5a64 | ||
|
|
fdc480ff6e | ||
|
|
378b7cd4dd | ||
|
|
f779fc7a0e | ||
|
|
fe11f495d6 | ||
|
|
265876c849 | ||
|
|
c9c52518c0 | ||
|
|
96c9ac6f8b | ||
|
|
bdeb30a847 | ||
|
|
ea53eb9290 | ||
|
|
05875057c9 | ||
|
|
d67210155b | ||
|
|
ae92c50cee | ||
|
|
43429dc0ec | ||
|
|
04cf92a27f | ||
|
|
57a57f50f6 | ||
|
|
5e5a75e6c5 | ||
|
|
109c86aaf7 | ||
|
|
10e7e7727a | ||
|
|
a39775050a | ||
|
|
44125926d1 | ||
|
|
60734349de | ||
|
|
fbfd5ec0ec | ||
|
|
157c0264af | ||
|
|
9bacfdb390 | ||
|
|
f9aaf5c42e | ||
|
|
a74a95cc65 | ||
|
|
21db695e79 | ||
|
|
cf917f1093 | ||
|
|
a8d3a61c25 | ||
|
|
80f13a8149 | ||
|
|
e172f3a67f | ||
|
|
c382c0a9cc | ||
|
|
bc0ea16ff0 | ||
|
|
b2dc8aa84c | ||
|
|
78b29fe967 | ||
|
|
9987e8b6ab | ||
|
|
0d9bdcc008 | ||
|
|
81fa33abeb | ||
|
|
af7f87e19b | ||
|
|
3073b03d56 | ||
|
|
23dab0a013 | ||
|
|
fd68144ba2 | ||
|
|
51e92cd142 | ||
|
|
50f33f7196 | ||
|
|
b5c634045e | ||
|
|
1f05531d53 | ||
|
|
88f382f0e3 | ||
|
|
3e59925900 | ||
|
|
1182d30fb9 | ||
|
|
095179eeb3 | ||
|
|
69b48eaadb | ||
|
|
4031c6f0d3 | ||
|
|
7a22f7dfc5 | ||
|
|
728ebf5023 | ||
|
|
62476d2f06 | ||
|
|
ea404f8d4f | ||
|
|
602a550d93 | ||
|
|
12abbe2d23 | ||
|
|
5fea428243 | ||
|
|
fb0ee97588 | ||
|
|
56ef48c9c3 | ||
|
|
47c3dd3dd1 | ||
|
|
9a3c9ccbf3 | ||
|
|
ef4dfcecd6 | ||
|
|
5943382d23 | ||
|
|
c181648bfa | ||
|
|
0cf78b3abe | ||
|
|
1dcf347b87 | ||
|
|
47714007f7 | ||
|
|
22889a7ad9 | ||
|
|
a14451d0ac | ||
|
|
5dfdab10b7 | ||
|
|
54277572d2 | ||
|
|
52f2c0e107 | ||
|
|
59abc8cc20 | ||
|
|
e15796b348 | ||
|
|
1711eaa4d6 | ||
|
|
acbd6a5ca8 | ||
|
|
775090fdda | ||
|
|
0915b86927 | ||
|
|
c10f7b01f4 | ||
|
|
84142ac506 | ||
|
|
ff190847a1 | ||
|
|
3ceec28189 | ||
|
|
d6f2e3b8e9 | ||
|
|
481038152f | ||
|
|
60bd72730d | ||
|
|
df30517743 | ||
|
|
8f80643c1a | ||
|
|
eabfd08473 | ||
|
|
a66af0ac58 | ||
|
|
15187e9d99 | ||
|
|
681e8f8b59 | ||
|
|
fbb406ca7d | ||
|
|
5aea9be2fb | ||
|
|
aacaf5055e | ||
|
|
a5dbddfd12 | ||
|
|
764a0df669 | ||
|
|
f04864c216 | ||
|
|
11a1b31a4c | ||
|
|
fb86a77cf8 | ||
|
|
d512357928 | ||
|
|
b850bc827e | ||
|
|
0229077293 | ||
|
|
23f2679bbe | ||
|
|
e6243b3df3 | ||
|
|
375b46d866 | ||
|
|
4577c8d57f | ||
|
|
24d1e9c3d2 | ||
|
|
f7a630d614 | ||
|
|
1c1cb11cf5 | ||
|
|
3ac8a6a21c | ||
|
|
c524c39867 | ||
|
|
ad02e483d0 | ||
|
|
f463d53036 | ||
|
|
e203edc12a | ||
|
|
b8d4408524 | ||
|
|
5447baab00 | ||
|
|
904989f7f4 | ||
|
|
4846ccd86d | ||
|
|
0fd1c3182e | ||
|
|
7d80052dae | ||
|
|
b71ee48477 | ||
|
|
7a285dc55a | ||
|
|
a0f3a4d9bb | ||
|
|
304090d39f | ||
|
|
fef70be848 | ||
|
|
bdb12d9b24 | ||
|
|
510f51d934 | ||
|
|
47c9fd67e2 | ||
|
|
43ad283a83 | ||
|
|
1f403fdae0 | ||
|
|
2e4936afc4 | ||
|
|
891ffabd11 | ||
|
|
e2c19498b4 | ||
|
|
c32630b265 | ||
|
|
1a3cee9da9 | ||
|
|
3acfd6fc78 | ||
|
|
bf21e78d02 | ||
|
|
83a9bb3a6f | ||
|
|
0744876327 | ||
|
|
8b92519113 | ||
|
|
525d4e08a3 | ||
|
|
2e9bf6d694 | ||
|
|
1980107925 | ||
|
|
e845f01d85 | ||
|
|
409a84be1f | ||
|
|
b2fef7988e | ||
|
|
82623c8fd4 | ||
|
|
552a3ab103 | ||
|
|
52c376a8a7 | ||
|
|
dd3b7ca65c | ||
|
|
9776a38d48 | ||
|
|
ceeccde92c | ||
|
|
1a8550e8e0 | ||
|
|
2feb0ad325 | ||
|
|
7f2c9c2326 | ||
|
|
9e5f4be85d | ||
|
|
b5874af40b | ||
|
|
bef48be7b4 | ||
|
|
b54fdc9e6e | ||
|
|
cc70b827a8 | ||
|
|
cedbf2e30b | ||
|
|
9ff195ce19 | ||
|
|
8e7aaaa662 | ||
|
|
77a744b20b | ||
|
|
51fd1ef645 | ||
|
|
592f8d1b0d | ||
|
|
29612a684e | ||
|
|
3500cc693d | ||
|
|
807b9882c5 | ||
|
|
b2920a68fb | ||
|
|
f4ef283908 | ||
|
|
09a38f4e43 | ||
|
|
04acd1885a | ||
|
|
d9fde833b4 | ||
|
|
378ba4e1df | ||
|
|
4522ce342b | ||
|
|
04402ed412 | ||
|
|
dc3cf5df49 | ||
|
|
9261769c5a | ||
|
|
f5e74f8d5a | ||
|
|
e87c140255 | ||
|
|
00d36110d5 | ||
|
|
c11364b89f | ||
|
|
89f8b8663c | ||
|
|
6734cdd923 | ||
|
|
3bf4ff78d9 | ||
|
|
b52cef2fd0 | ||
|
|
66747e69c5 | ||
|
|
4085336db5 | ||
|
|
c666a79d12 | ||
|
|
22a464f76f | ||
|
|
60e88a6069 | ||
|
|
ff3a9a46cc | ||
|
|
8c53ad0906 | ||
|
|
93cc32f34d | ||
|
|
dd764d2c3f | ||
|
|
5a7ae8f1c7 | ||
|
|
4ed5085422 | ||
|
|
0e574f3fce | ||
|
|
dcfc27857f | ||
|
|
e6d5807399 | ||
|
|
fa2553251f | ||
|
|
b04c398202 | ||
|
|
fe8e1d0734 | ||
|
|
7387718852 | ||
|
|
a503a6209a | ||
|
|
9f5d6e79da | ||
|
|
ce3e5f74e8 | ||
|
|
9b06ab6084 | ||
|
|
f37112358e | ||
|
|
76d4fc08f1 | ||
|
|
90548a148b | ||
|
|
270bbe4218 | ||
|
|
3f26c8b893 | ||
|
|
f368b14621 | ||
|
|
6960b1148a | ||
|
|
9cea332f61 | ||
|
|
93ce14659a | ||
|
|
2d49b36b3e | ||
|
|
3cc23aac25 | ||
|
|
ab9d132964 | ||
|
|
11dc8740f2 | ||
|
|
b30e4f9a4b | ||
|
|
4b797cff88 | ||
|
|
22afc3a93b | ||
|
|
8aba6f0dcd | ||
|
|
97cee30383 | ||
|
|
7f4832706b | ||
|
|
5f16fe45b1 | ||
|
|
8c8e0ce8a3 | ||
|
|
1b9dea5b75 | ||
|
|
7ed073ec3f | ||
|
|
e2c5bb025b | ||
|
|
a86077e9fe | ||
|
|
cd903b412f | ||
|
|
dd914066f3 | ||
|
|
7af07a1c0f | ||
|
|
b980d0a7fd | ||
|
|
5f10ab56bc | ||
|
|
383da5f661 | ||
|
|
8f0591c9a6 | ||
|
|
afb0ceac57 | ||
|
|
fc2660eb39 | ||
|
|
1b8f4b97dd | ||
|
|
3671469046 | ||
|
|
53d4fa3095 | ||
|
|
94999e55e1 | ||
|
|
ba9415b514 | ||
|
|
fe1c1736cd | ||
|
|
abb6ae304c | ||
|
|
885a69710e | ||
|
|
4058ef5f09 | ||
|
|
d25ca01624 | ||
|
|
e7bebcdea9 | ||
|
|
5ef234153d | ||
|
|
d96f87dbbf | ||
|
|
bbee5599f1 | ||
|
|
a4212d5ace | ||
|
|
6d0e719e06 | ||
|
|
3fa9b08a52 | ||
|
|
4b1a451804 | ||
|
|
f9d7d60f7d | ||
|
|
aaf9d95411 | ||
|
|
90d1ebefae | ||
|
|
a7e4a759e9 | ||
|
|
283992088f | ||
|
|
75c9ee5982 | ||
|
|
4d88ff116c | ||
|
|
cf3cc37392 | ||
|
|
f804c9e346 | ||
|
|
8a2e31023f | ||
|
|
4e33e9c3d1 | ||
|
|
18ac9fd0cc | ||
|
|
d0f28a48a8 | ||
|
|
706780e3a6 | ||
|
|
b5f9c66503 | ||
|
|
41f34b8d55 | ||
|
|
04731b937a | ||
|
|
7278e5b5ba | ||
|
|
891184bc77 | ||
|
|
3d51f9ab23 | ||
|
|
1ea8e171d9 | ||
|
|
e2be3dd0ac | ||
|
|
35c0092b84 | ||
|
|
d249f70750 | ||
|
|
0dc25cd2a8 | ||
|
|
1c51164e7b | ||
|
|
91b5cc4bea | ||
|
|
f190f03530 | ||
|
|
af6f19e390 | ||
|
|
47446e6cfd | ||
|
|
8fada7d6c7 | ||
|
|
8a81486f5d | ||
|
|
e483699fba | ||
|
|
ae40a12f54 | ||
|
|
73d4279f00 | ||
|
|
a0e2f722f6 | ||
|
|
5c0da86e04 | ||
|
|
055fc7cbc1 | ||
|
|
37d8f96927 | ||
|
|
e9e3ce78ca | ||
|
|
2dadad1e87 | ||
|
|
9073fc3dc3 | ||
|
|
8c36e6d95f | ||
|
|
2b6d99f5e7 | ||
|
|
6f29358cb6 | ||
|
|
4e9dcb45ea | ||
|
|
282b6f72c1 | ||
|
|
cd48be5265 | ||
|
|
3cba26a4c5 | ||
|
|
dd2119268b | ||
|
|
5e51ff78d9 | ||
|
|
6bf27c7356 | ||
|
|
3abd4fdf09 | ||
|
|
2409dc9bc4 | ||
|
|
432434e7e9 | ||
|
|
6586c8d70b | ||
|
|
ac0c94da69 | ||
|
|
ba68ea89cd | ||
|
|
26661375ae | ||
|
|
d19d6a72b0 | ||
|
|
c81b5d98ef | ||
|
|
f45b7626eb | ||
|
|
2aa21e2a43 | ||
|
|
ad876b91e7 | ||
|
|
73514f6c91 | ||
|
|
385a05d197 | ||
|
|
306f6e1ca3 | ||
|
|
756866675f | ||
|
|
41baa7bcf0 | ||
|
|
694204d54a | ||
|
|
85bc1c1758 | ||
|
|
0c9cb72e53 | ||
|
|
d113c0f01f | ||
|
|
98b8871f34 | ||
|
|
7cb16afcb5 | ||
|
|
1a79e5463f | ||
|
|
fd444b2fd0 | ||
|
|
15db005dc6 | ||
|
|
a26b05bbbb | ||
|
|
12b9ee46b9 | ||
|
|
ce1eb83a0e | ||
|
|
27529730ca | ||
|
|
7b398c01f6 | ||
|
|
cdb0bb9490 | ||
|
|
ee82f76846 | ||
|
|
b77a23ff9d | ||
|
|
0d8cdab4e4 | ||
|
|
67b53d0115 | ||
|
|
c3291d0137 | ||
|
|
7f2ebd25bc | ||
|
|
fc32fa3a78 | ||
|
|
a3cf2ee61a | ||
|
|
cc287386aa | ||
|
|
9ea1dbad93 | ||
|
|
4a849c7caf | ||
|
|
a77a9ade29 | ||
|
|
090d23434c | ||
|
|
83850c8201 | ||
|
|
ebcd4925f7 | ||
|
|
13bed4fdf9 | ||
|
|
d306bfe147 | ||
|
|
adfc4a5b0c | ||
|
|
1dae5c6b6c | ||
|
|
6b249bde4b | ||
|
|
1036759f39 | ||
|
|
302c07048c | ||
|
|
2686b0bbac | ||
|
|
cece128bb9 | ||
|
|
3e5471d32a | ||
|
|
272f786f35 | ||
|
|
0dd04f6e73 | ||
|
|
a5221fc816 | ||
|
|
29f6616cee | ||
|
|
0d08402004 | ||
|
|
64c2ab7048 | ||
|
|
26a54ba86a | ||
|
|
32b3f16573 | ||
|
|
4080a0a5d5 | ||
|
|
17d67f2a39 | ||
|
|
9c20efd235 | ||
|
|
b46833680d | ||
|
|
4bcd862c0e | ||
|
|
c414ba9b2f | ||
|
|
27a070c8f9 | ||
|
|
c8aea02d7d | ||
|
|
46ff9a433c | ||
|
|
c135b4aa19 | ||
|
|
89d5f4a418 | ||
|
|
003fe86ffb | ||
|
|
94c250a241 | ||
|
|
f1a69c8c36 | ||
|
|
2bd8faaef5 | ||
|
|
94a25452e8 | ||
|
|
505cb39e1c | ||
|
|
127dd8f675 | ||
|
|
fc5837b1b6 | ||
|
|
46e3d10e62 | ||
|
|
64c5dc63ab | ||
|
|
31adb1213e | ||
|
|
8e6663e4b0 | ||
|
|
ba804444b8 | ||
|
|
0344de57e9 | ||
|
|
750252b297 | ||
|
|
58cfb85004 | ||
|
|
ab46481b45 | ||
|
|
4296782399 | ||
|
|
4f28734042 | ||
|
|
4289c03ce5 | ||
|
|
bdbc85773c | ||
|
|
0a2fa36d5a | ||
|
|
0c244bc2ac | ||
|
|
67a49e5770 | ||
|
|
a98395bee7 | ||
|
|
26c9732b4e | ||
|
|
62787de97b | ||
|
|
830c379958 | ||
|
|
1a24de8735 | ||
|
|
121489f2af | ||
|
|
0e7295a469 | ||
|
|
602b3d0796 | ||
|
|
fda06fe8a0 | ||
|
|
92628ade8e | ||
|
|
b399d64024 | ||
|
|
a8e8c04c7b | ||
|
|
313b9944fd | ||
|
|
5a61d28eee | ||
|
|
4eb0937d21 | ||
|
|
a082e94235 | ||
|
|
9bd3684893 | ||
|
|
0cd9fd9ad9 | ||
|
|
efcc690f42 | ||
|
|
1ed1a5efb6 | ||
|
|
2d7de6ecc0 | ||
|
|
4a1edc4281 | ||
|
|
d6b32e5923 | ||
|
|
105ae8abb6 | ||
|
|
1f33dad675 | ||
|
|
90ee59512b | ||
|
|
7f2a189641 | ||
|
|
1ab59ca35a | ||
|
|
5c0826963e | ||
|
|
7555fe6196 | ||
|
|
1dbb9c7ded | ||
|
|
ac798c1350 | ||
|
|
00682bd911 | ||
|
|
ef375a7103 | ||
|
|
fd258b7765 | ||
|
|
ceced43e93 | ||
|
|
55fdc47e66 | ||
|
|
147de8d372 | ||
|
|
eb2a1928b6 | ||
|
|
53a92451e6 | ||
|
|
77016f34a5 | ||
|
|
19db911d46 | ||
|
|
46a88c7ed8 | ||
|
|
ca3b841974 | ||
|
|
e9ff2157bc | ||
|
|
d270c42109 | ||
|
|
f4558fee1d | ||
|
|
86461663d8 | ||
|
|
fcca62ec6a | ||
|
|
f6dde81a16 | ||
|
|
d77e66d1e8 | ||
|
|
702f906d49 | ||
|
|
2f257b54e7 | ||
|
|
c1b9e47a90 | ||
|
|
a93e10308c | ||
|
|
204fc0359c | ||
|
|
eb483281dc | ||
|
|
b841709729 | ||
|
|
35b033102f | ||
|
|
7bc65421a9 | ||
|
|
736514cf37 | ||
|
|
6307fb3563 | ||
|
|
35b3542b2e | ||
|
|
db0158dae8 | ||
|
|
0fa5ca9a6a | ||
|
|
36285f2ca5 | ||
|
|
9e19a1aca4 | ||
|
|
19c7949cc4 | ||
|
|
36d7f6ff94 | ||
|
|
e7b90f9c12 | ||
|
|
8bd499c60c | ||
|
|
0d61d47f28 | ||
|
|
4b5dc5b3af | ||
|
|
61bf472426 | ||
|
|
ef6199a792 | ||
|
|
7bd0b45a2b | ||
|
|
eb0c346969 | ||
|
|
bf2938f345 | ||
|
|
c7e4116154 | ||
|
|
db521e0e5e | ||
|
|
a219629ead | ||
|
|
ba10393f48 | ||
|
|
091e399d0f | ||
|
|
5de6779d72 | ||
|
|
4b3a983b23 | ||
|
|
1b53e78ea7 | ||
|
|
ef08323b25 | ||
|
|
24c6917267 | ||
|
|
9ab25fa19e | ||
|
|
d5f785ff41 | ||
|
|
f2a8e2aef7 | ||
|
|
7bdd1fe096 | ||
|
|
f677eef422 | ||
|
|
70f3824b14 | ||
|
|
11b980832c | ||
|
|
e706695ed1 | ||
|
|
e8877ffe2d | ||
|
|
300e853646 | ||
|
|
a403279fa6 | ||
|
|
1fd5d9dae6 | ||
|
|
8f6f831d5b | ||
|
|
599077b54c | ||
|
|
9b7414b60c | ||
|
|
78430858fe | ||
|
|
fe8528a963 | ||
|
|
f365cb965b | ||
|
|
2b38cf4c65 | ||
|
|
2e9080a179 | ||
|
|
0a50ee989e | ||
|
|
c9c9103ede | ||
|
|
1ce9e96490 | ||
|
|
1f9c802e10 | ||
|
|
c6fda8385a | ||
|
|
d0664bc119 | ||
|
|
e7ed85ec94 | ||
|
|
5d1d4ff4d6 | ||
|
|
57040ebb22 | ||
|
|
03b018e7f3 | ||
|
|
04ada346b0 | ||
|
|
f53c7723fb | ||
|
|
cd48089318 | ||
|
|
0a6a74c78c | ||
|
|
b40982d579 | ||
|
|
2605633e1e | ||
|
|
6379ab22c9 | ||
|
|
0bf02b75d5 | ||
|
|
2f7e873137 | ||
|
|
bb9e23519d | ||
|
|
c4259b5598 | ||
|
|
acfae2882d | ||
|
|
180eb61620 | ||
|
|
a92bb87cd8 | ||
|
|
2c967b821b | ||
|
|
abe9a9731d | ||
|
|
2837a48001 | ||
|
|
4aef84342d | ||
|
|
9be6153875 | ||
|
|
444640afb7 | ||
|
|
122908587b | ||
|
|
c1654537e2 | ||
|
|
984a172cec | ||
|
|
ee2767875c | ||
|
|
fa0a41e62e | ||
|
|
edaf718281 | ||
|
|
7cd5963d3a | ||
|
|
60f5512c5f | ||
|
|
6b3c1179bc | ||
|
|
d1b9a1b996 | ||
|
|
1bd91e7e94 | ||
|
|
5e2f73c74e | ||
|
|
4a269e37c5 | ||
|
|
3eceaf20a2 | ||
|
|
bbc4f4f21d | ||
|
|
c5ef1d6252 | ||
|
|
a4280881d5 | ||
|
|
8ef4c54712 | ||
|
|
5ebc8c3e1a | ||
|
|
c1a0e61e8e | ||
|
|
cbcb3e95c6 | ||
|
|
fc06298ed4 | ||
|
|
02a8cffb18 | ||
|
|
d53f7ecd6a | ||
|
|
e297f65d8c | ||
|
|
5356f65040 | ||
|
|
5056abc357 | ||
|
|
46029acd14 | ||
|
|
28e414c9a5 | ||
|
|
29c036d826 | ||
|
|
831a6d9480 | ||
|
|
fb2a95470a | ||
|
|
4d73583f86 | ||
|
|
9a24c4001f | ||
|
|
4c9ae9dd91 | ||
|
|
384d6921f6 | ||
|
|
e0a8284fcf | ||
|
|
eafbf699a2 | ||
|
|
4d3f10477a | ||
|
|
9a83805f19 | ||
|
|
6fcc2b579d | ||
|
|
e04a3d7d3a |
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -17,6 +17,10 @@ A clear and concise description of what you expected to happen.
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Logs**
|
||||
If applicable, copy logs from your console here. Please *do not*
|
||||
use screenshots of logs, copy them as text.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- GPU: [e.g. NVIDIA GTX 1080]
|
||||
|
||||
3
.github/workflows/mac-continuous.yml
vendored
3
.github/workflows/mac-continuous.yml
vendored
@@ -21,3 +21,6 @@ jobs:
|
||||
with:
|
||||
name: filament-mac
|
||||
path: out/filament-release-darwin.tgz
|
||||
- name: Check public headers
|
||||
run: |
|
||||
build/common/check-headers.sh out/release/filament/include
|
||||
|
||||
45
.github/workflows/release.yml
vendored
45
.github/workflows/release.yml
vendored
@@ -1,14 +1,25 @@
|
||||
name: Release
|
||||
|
||||
# This Workflow can be triggered two ways:
|
||||
# 1. A GitHub release is created (using the GitHub web UI). This triggers all of the platforms to build and upload assets.
|
||||
# 2. A repository_dispatch API event is sent. This triggers a build for only the platform specified in the dispatch event.
|
||||
# 1. A GitHub release is created (using the GitHub web UI). This triggers all of the platforms to
|
||||
# build and upload assets.
|
||||
# 2. A workflow_dispatch event is triggered from the GitHub web UI. This triggers a build for only
|
||||
# the platform specified in the dispatch event.
|
||||
|
||||
env:
|
||||
RELEASE_TAG: ${{ github.event.client_payload.release_tag }}
|
||||
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
|
||||
|
||||
on:
|
||||
repository_dispatch:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
platform:
|
||||
description: 'Platform to build (desktop, web, android, ios, windows)'
|
||||
required: true
|
||||
default: 'desktop'
|
||||
release_tag:
|
||||
description: 'Release tag to build (e.g., v1.13.0)'
|
||||
required: true
|
||||
default: 'v1.13.0'
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
@@ -16,7 +27,7 @@ jobs:
|
||||
build-desktop:
|
||||
name: build-desktop
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: github.event_name == 'release' || github.event.client_payload.platform == 'desktop'
|
||||
if: github.event_name == 'release' || github.event.inputs.platform == 'desktop'
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -51,7 +62,7 @@ jobs:
|
||||
build-web:
|
||||
name: build-web
|
||||
runs-on: macos-latest
|
||||
if: github.event_name == 'release' || github.event.client_payload.platform == 'web'
|
||||
if: github.event_name == 'release' || github.event.inputs.platform == 'web'
|
||||
|
||||
steps:
|
||||
- name: Decide Git ref
|
||||
@@ -80,7 +91,7 @@ jobs:
|
||||
build-android:
|
||||
name: build-android
|
||||
runs-on: macos-latest
|
||||
if: github.event_name == 'release' || github.event.client_payload.platform == 'android'
|
||||
if: github.event_name == 'release' || github.event.inputs.platform == 'android'
|
||||
|
||||
steps:
|
||||
- name: Decide Git ref
|
||||
@@ -96,6 +107,20 @@ jobs:
|
||||
- name: Run build script
|
||||
run: |
|
||||
cd build/android && printf "y" | ./build.sh release
|
||||
- name: Sign sample-gltf-viewer
|
||||
run: |
|
||||
echo "${APK_KEYSTORE_BASE64}" > filament.jks.base64
|
||||
base64 --decode filament.jks.base64 > filament.jks
|
||||
BUILD_TOOLS_VERSION=$(ls ${ANDROID_HOME}/build-tools | sort -V | tail -n 1)
|
||||
APKSIGNER=${ANDROID_HOME}/build-tools/${BUILD_TOOLS_VERSION}/apksigner
|
||||
IN_FILE="out/sample-gltf-viewer-release.apk"
|
||||
OUT_FILE="out/filament-gltf-viewer-${TAG}-android.apk"
|
||||
${APKSIGNER} sign --ks filament.jks --key-pass=pass:${APK_KEYSTORE_PASS} --ks-pass=pass:${APK_KEYSTORE_PASS} --in ${IN_FILE} --out ${OUT_FILE}
|
||||
rm "${IN_FILE}"
|
||||
env:
|
||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
||||
APK_KEYSTORE_BASE64: ${{ secrets.APK_KEYSTORE_BASE64 }}
|
||||
APK_KEYSTORE_PASS: ${{ secrets.APK_KEYSTORE_PASS }}
|
||||
- name: Upload release assets
|
||||
run: |
|
||||
pip3 install setuptools
|
||||
@@ -107,7 +132,7 @@ jobs:
|
||||
mv out/gltfio-android-lite-release.aar out/gltfio-${TAG}-lite-android.aar
|
||||
mv out/filament-utils-android-release.aar out/filament-utils-${TAG}-android.aar
|
||||
mv out/filament-utils-android-lite-release.aar out/filament-utils-${TAG}-lite-android.aar
|
||||
python3 build/common/upload-assets.py ${TAG} out/*.aar
|
||||
python3 build/common/upload-assets.py ${TAG} out/*.aar out/*.apk
|
||||
env:
|
||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
||||
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
|
||||
@@ -115,7 +140,7 @@ jobs:
|
||||
build-ios:
|
||||
name: build-ios
|
||||
runs-on: macos-latest
|
||||
if: github.event_name == 'release' || github.event.client_payload.platform == 'ios'
|
||||
if: github.event_name == 'release' || github.event.inputs.platform == 'ios'
|
||||
|
||||
steps:
|
||||
- name: Decide Git ref
|
||||
@@ -144,7 +169,7 @@ jobs:
|
||||
build-windows:
|
||||
name: build-windows
|
||||
runs-on: windows-latest
|
||||
if: github.event_name == 'release' || github.event.client_payload.platform == 'windows'
|
||||
if: github.event_name == 'release' || github.event.inputs.platform == 'windows'
|
||||
|
||||
steps:
|
||||
- name: Decide Git ref
|
||||
|
||||
52
BUILDING.md
52
BUILDING.md
@@ -8,25 +8,19 @@ To build Filament, you must first install the following tools:
|
||||
- clang 7.0 (or more recent)
|
||||
- [ninja 1.10](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) (or more recent)
|
||||
|
||||
To build the Java based components of the project you can optionally install (recommended):
|
||||
|
||||
- OpenJDK 1.8 (or more recent)
|
||||
|
||||
Additional dependencies may be required for your operating system. Please refer to the appropriate
|
||||
section below.
|
||||
|
||||
To build Filament for Android you must also install the following:
|
||||
|
||||
- Android Studio 4.2.0 or more recent
|
||||
- Android Studio Arctic Fox or more recent
|
||||
- Android SDK
|
||||
- Android NDK "side-by-side" 22.1 or higher
|
||||
- Android NDK "side-by-side" 23.1 or higher
|
||||
|
||||
### Environment variables
|
||||
|
||||
Make sure the environment variable `ANDROID_HOME` points to the location of your Android SDK.
|
||||
|
||||
By default our build system will attempt to compile the Java bindings. To do so, the environment
|
||||
variable `JAVA_HOME` should point to the location of your JDK.
|
||||
To build Filament for Android, make sure the environment variable `ANDROID_HOME` points to the
|
||||
location of your Android SDK.
|
||||
|
||||
When building for WebGL, you'll also need to set `EMSDK`. See [WebAssembly](#webassembly).
|
||||
|
||||
@@ -65,23 +59,10 @@ To install the libraries and executables in `out/debug/` and `out/release/`, add
|
||||
You can force a clean build by adding the `-c` flag. The script offers more features described
|
||||
by executing `build.sh -h`.
|
||||
|
||||
### Disabling Java builds
|
||||
|
||||
By default our build system will attempt to compile the Java bindings. If you wish to skip this
|
||||
compilation step simply pass the `-j` flag to `build.sh`:
|
||||
|
||||
```
|
||||
$ ./build.sh -j release
|
||||
```
|
||||
|
||||
If you use CMake directly instead of the build script, pass `-DFILAMENT_ENABLE_JAVA=OFF`
|
||||
to CMake instead.
|
||||
|
||||
### Filament-specific CMake Options
|
||||
|
||||
The following CMake options are boolean options specific to Filament:
|
||||
|
||||
- `FILAMENT_ENABLE_JAVA`: Compile Java projects: requires a JDK and the JAVA_HOME env var
|
||||
- `FILAMENT_ENABLE_LTO`: Enable link-time optimizations if supported by the compiler
|
||||
- `FILAMENT_BUILD_FILAMAT`: Build filamat and JNI buildings
|
||||
- `FILAMENT_SUPPORTS_OPENGL`: Include the OpenGL backend
|
||||
@@ -163,14 +144,6 @@ make sure the command line tools are setup by running:
|
||||
$ xcode-select --install
|
||||
```
|
||||
|
||||
After installing Java 1.8 you must also ensure that your `JAVA_HOME` environment variable is
|
||||
properly set. If it doesn't already point to the appropriate JDK, you can simply add the following
|
||||
to your `.profile`:
|
||||
|
||||
```
|
||||
export JAVA_HOME="$(/usr/libexec/java_home)"
|
||||
```
|
||||
|
||||
Then run `cmake` and `ninja` to trigger a build:
|
||||
|
||||
```
|
||||
@@ -318,11 +291,11 @@ Alternatively you can build the AAR from the command line by executing the follo
|
||||
`android/` directory:
|
||||
|
||||
```
|
||||
$ ./gradlew -Pfilament_dist_dir=../../out/android-release/filament assembleRelease
|
||||
$ ./gradlew -Pcom.google.android.filament.dist-dir=../../out/android-release/filament assembleRelease
|
||||
```
|
||||
|
||||
The `-Pfilament_dist_dir` can be used to specify a different installation directory (it must match
|
||||
the CMake install prefix used in the previous steps).
|
||||
The `-Pcom.google.android.filament.dist-dir` can be used to specify a different installation
|
||||
directory (it must match the CMake install prefix used in the previous steps).
|
||||
|
||||
#### Using Filament's AAR
|
||||
|
||||
@@ -376,7 +349,7 @@ same version that our continuous builds use.
|
||||
|
||||
```
|
||||
cd <your chosen parent folder for the emscripten SDK>
|
||||
curl -L https://github.com/emscripten-core/emsdk/archive/2.0.17.zip > emsdk.zip
|
||||
curl -L https://github.com/emscripten-core/emsdk/archive/2.0.23.zip > emsdk.zip
|
||||
unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk
|
||||
python ./emsdk.py install latest
|
||||
python ./emsdk.py activate latest
|
||||
@@ -423,12 +396,13 @@ filamesh ./assets/models/monkey/monkey.obj monkey.filamesh
|
||||
```
|
||||
|
||||
Most samples accept an IBL that must be generated using the `cmgen` tool (`./tools/filamesh/cmgen`
|
||||
in your build directory). These sample apps expect a path to a directory containing the '.rgb32f'
|
||||
files for the IBL (which are PNGs containing `R11F_G11F_B10F` data). To generate an IBL simply use
|
||||
this command:
|
||||
in your build directory). These sample apps expect a path to a directory containing the `.rgb32f`
|
||||
files for the IBL (which are PNGs containing `R11F_G11F_B10F` data) or a path to a directory
|
||||
containing two `.ktx` files (one for the IBL itself, one for the skybox). To generate an IBL
|
||||
simply use this command:
|
||||
|
||||
```
|
||||
cmgen -x ./ibls/ my_ibl.exr
|
||||
cmgen -f ktx -x ./ibls/ my_ibl.exr
|
||||
```
|
||||
|
||||
The source environment map can be a PNG (8 or 16 bit), a PSD (16 or 32 bit), an HDR or an OpenEXR
|
||||
|
||||
@@ -11,8 +11,6 @@ project(TNT)
|
||||
# ==================================================================================================
|
||||
# Options
|
||||
# ==================================================================================================
|
||||
option(FILAMENT_ENABLE_JAVA "Compile Java projects, requires a JDK and the JAVA_HOME env var" ON)
|
||||
|
||||
option(FILAMENT_USE_EXTERNAL_GLES3 "Experimental: Compile Filament against OpenGL ES 3" OFF)
|
||||
|
||||
option(FILAMENT_USE_SWIFTSHADER "Compile Filament against SwiftShader" OFF)
|
||||
@@ -41,8 +39,12 @@ set(FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB "1" CACHE STRING
|
||||
"Size of the command-stream buffer. As a rule of thumb use the same value as FILAMENT_PER_FRRAME_COMMANDS_SIZE_IN_MB, default 1."
|
||||
)
|
||||
|
||||
set(FILAMENT_OPENGL_HANDLE_ARENA_SIZE_IN_MB "2" CACHE STRING
|
||||
"Size of the OpenGL handle arena, default 2."
|
||||
set(FILAMENT_OPENGL_HANDLE_ARENA_SIZE_IN_MB "4" CACHE STRING
|
||||
"Size of the OpenGL handle arena, default 4."
|
||||
)
|
||||
|
||||
set(FILAMENT_METAL_HANDLE_ARENA_SIZE_IN_MB "8" CACHE STRING
|
||||
"Size of the Metal handle arena, default 8."
|
||||
)
|
||||
|
||||
# ==================================================================================================
|
||||
@@ -129,27 +131,35 @@ if (WIN32)
|
||||
# __declspec(dllexport) in front of each functions).
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
# The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative
|
||||
# global method here:
|
||||
if (${USE_STATIC_CRT})
|
||||
set(CRT_FLAGS_RELEASE "/MT")
|
||||
set(CRT_FLAGS_DEBUG "/MTd")
|
||||
add_compile_options(
|
||||
$<$<CONFIG:>:/MT>
|
||||
$<$<CONFIG:Debug>:/MTd>
|
||||
$<$<CONFIG:Release>:/MT>
|
||||
)
|
||||
else()
|
||||
set(CRT_FLAGS_RELEASE "/MD")
|
||||
set(CRT_FLAGS_DEBUG "/MDd")
|
||||
add_compile_options(
|
||||
$<$<CONFIG:>:/MD>
|
||||
$<$<CONFIG:Debug>:/MDd>
|
||||
$<$<CONFIG:Release>:/MD>
|
||||
)
|
||||
endif()
|
||||
|
||||
# TODO: Figure out why pdb generation messes with incremental compilaton.
|
||||
# IN RELEASE_WITH_DEBUG_INFO, generate debug info in .obj, no in pdb.
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CRT_FLAGS_RELEASE} /Z7")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CRT_FLAGS_RELEASE} /Z7")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Z7")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /Z7")
|
||||
|
||||
# In RELEASE, also generate PDBs.
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CRT_FLAGS_RELEASE} /Zi")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CRT_FLAGS_RELEASE} /Zi")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
|
||||
|
||||
# In DEBUG, avoid generating a PDB file which seems to mess with incremental compilation.
|
||||
# Instead generate debug info directly inside obj files.
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CRT_FLAGS_DEBUG} /Z7")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CRT_FLAGS_DEBUG} /Z7")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Z7")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Z7")
|
||||
|
||||
# Special settings when building on CI.
|
||||
if (${FILAMENT_WINDOWS_CI_BUILD})
|
||||
@@ -289,6 +299,12 @@ if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
|
||||
endif()
|
||||
|
||||
# Use hidden by default and expose what we need.
|
||||
if (NOT WIN32)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
# Release compiler flags
|
||||
# ==================================================================================================
|
||||
@@ -440,8 +456,9 @@ if (FILAMENT_SUPPORTS_METAL)
|
||||
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a metal)
|
||||
endif()
|
||||
|
||||
# Disable optimizations and enable debug info (preserves names in SPIR-V)
|
||||
if (FILAMENT_DISABLE_MATOPT)
|
||||
set(MATC_OPT_FLAGS -g)
|
||||
set(MATC_OPT_FLAGS -gd)
|
||||
endif()
|
||||
|
||||
set(MATC_BASE_FLAGS ${MATC_API_FLAGS} -p ${MATC_TARGET} ${MATC_OPT_FLAGS})
|
||||
@@ -485,11 +502,15 @@ function(list_licenses OUTPUT MODULES)
|
||||
foreach(module ${_MODULES})
|
||||
set(license_path "../../third_party/${module}/LICENSE")
|
||||
get_filename_component(fullname "${license_path}" ABSOLUTE)
|
||||
string(APPEND CONTENT "${STR_OPENER}License and copyrights for ${module}:\n${STR_CLOSER},\n")
|
||||
file(READ ${license_path} license_long)
|
||||
string(REPLACE "\n" "${STR_CLOSER},\n${STR_OPENER}" license ${license_long})
|
||||
string(APPEND CONTENT ${STR_OPENER}${license}\n${STR_CLOSER},)
|
||||
string(APPEND CONTENT "\n\n")
|
||||
if(EXISTS ${fullname})
|
||||
string(APPEND CONTENT "${STR_OPENER}License and copyrights for ${module}:\n${STR_CLOSER},\n")
|
||||
file(READ ${license_path} license_long)
|
||||
string(REPLACE "\n" "${STR_CLOSER},\n${STR_OPENER}" license ${license_long})
|
||||
string(APPEND CONTENT ${STR_OPENER}${license}\n${STR_CLOSER},)
|
||||
string(APPEND CONTENT "\n\n")
|
||||
else()
|
||||
message(AUTHOR_WARNING "${license_path} not found. You can ignore this warning if you have devendored ${module}.")
|
||||
endif()
|
||||
endforeach()
|
||||
configure_file(${FILAMENT}/build/licenses.inc.in ${OUTPUT})
|
||||
endfunction(list_licenses)
|
||||
@@ -505,7 +526,12 @@ function(combine_static_libs TARGET OUTPUT DEPS)
|
||||
# Loop through the dependent libraries and query their location on disk.
|
||||
set(DEPS_FILES )
|
||||
foreach(DEPENDENCY ${DEPS})
|
||||
list(APPEND DEPS_FILES "$<TARGET_FILE:${DEPENDENCY}>")
|
||||
if(TARGET ${DEPENDENCY})
|
||||
get_property(dep_type TARGET ${DEPENDENCY} PROPERTY TYPE)
|
||||
if(dep_type STREQUAL "STATIC_LIBRARY")
|
||||
list(APPEND DEPS_FILES "$<TARGET_FILE:${DEPENDENCY}>")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_custom_command(
|
||||
@@ -655,10 +681,6 @@ if (IS_HOST_PLATFORM)
|
||||
add_subdirectory(${LIBRARIES}/filamentapp)
|
||||
add_subdirectory(${LIBRARIES}/imageio)
|
||||
|
||||
add_subdirectory(${FILAMENT}/java/filamat)
|
||||
add_subdirectory(${FILAMENT}/java/filament)
|
||||
add_subdirectory(${FILAMENT}/java/gltfio)
|
||||
|
||||
add_subdirectory(${FILAMENT}/samples)
|
||||
|
||||
add_subdirectory(${EXTERNAL}/astcenc/tnt)
|
||||
@@ -678,6 +700,7 @@ if (IS_HOST_PLATFORM)
|
||||
add_subdirectory(${TOOLS}/mipgen)
|
||||
add_subdirectory(${TOOLS}/normal-blending)
|
||||
add_subdirectory(${TOOLS}/resgen)
|
||||
add_subdirectory(${TOOLS}/rgb-to-lmsr)
|
||||
add_subdirectory(${TOOLS}/roughness-prefilter)
|
||||
add_subdirectory(${TOOLS}/specular-color)
|
||||
endif()
|
||||
|
||||
89
README.md
89
README.md
@@ -31,39 +31,28 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.android.filament:filament-android:1.10.2'
|
||||
implementation 'com.google.android.filament:filament-android:1.14.2'
|
||||
}
|
||||
```
|
||||
|
||||
Here are all the libraries available in the group `com.google.android.filament`:
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-android)
|
||||
The Filament rendering engine itself.
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android)
|
||||
A glTF 2.0 loader for Filament, depends on `filament-android` .
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android-lite)
|
||||
Trimmed version of `gltfio` that does not support some glTF features.
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-utils-android)
|
||||
KTX loading, Kotlin math, and camera utilities, depends on `gltfio-android`.
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-utils-android-lite)
|
||||
Trimmed version of `filament-utils` that does not support some glTF features.
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android)
|
||||
A runtime material builder/compiler. This library is large but contains a full shader compiler/validator/optimizer.
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android-lite)
|
||||
A much smaller alternative to `filamat-android` that can only generate OpenGL shaders. It does not provide validation or optimizations.
|
||||
| Artifact | Description |
|
||||
| ------------- | ------------- |
|
||||
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-android) | The Filament rendering engine itself. |
|
||||
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android) | A glTF 2.0 loader for Filament, depends on `filament-android`. |
|
||||
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android-lite) | Trimmed version of `gltfio` that does not support some glTF extensions. |
|
||||
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-utils-android) | KTX loading, Kotlin math, and camera utilities, depends on `gltfio-android`. |
|
||||
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-utils-android-lite) | Trimmed version of `filament-utils` that does not support some glTF features. |
|
||||
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android) | A runtime material builder/compiler. This library is large but contains a full shader compiler/validator/optimizer and supports both OpenGL and Vulkan. |
|
||||
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android-lite) | A much smaller alternative to `filamat-android` that can only generate OpenGL shaders. It does not provide validation or optimizations. |
|
||||
|
||||
### iOS
|
||||
|
||||
iOS projects can use CocoaPods to install the latest release:
|
||||
|
||||
```
|
||||
pod 'Filament', '~> 1.10.2'
|
||||
pod 'Filament', '~> 1.14.2'
|
||||
```
|
||||
|
||||
### Snapshots
|
||||
@@ -97,25 +86,12 @@ steps:
|
||||

|
||||

|
||||
|
||||
|
||||
### Applications
|
||||
|
||||
Here are a few screenshots of applications that use Filament in production:
|
||||
|
||||
#### Google Maps AR Navigation
|
||||
|
||||

|
||||
|
||||
#### Google Search 3D/AR Viewer on Android
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
### APIs
|
||||
|
||||
- Native C++ API for Android, iOS, Linux, macOS and Windows
|
||||
- Java/JNI API for Android, Linux, macOS and Windows
|
||||
- Java/JNI API for Android
|
||||
- JavaScript API
|
||||
|
||||
### Backends
|
||||
@@ -131,6 +107,7 @@ Here are a few screenshots of applications that use Filament in production:
|
||||
- Clustered forward renderer
|
||||
- Cook-Torrance microfacet specular BRDF
|
||||
- Lambertian diffuse BRDF
|
||||
- Custom lighting/surface shading
|
||||
- HDR/linear lighting
|
||||
- Metallic workflow
|
||||
- Clear coat
|
||||
@@ -145,20 +122,22 @@ Here are a few screenshots of applications that use Filament in production:
|
||||
- Specular anti-aliasing
|
||||
- Spot and directional light shadows
|
||||
- Cascaded shadows
|
||||
- VSM or PCF shadows
|
||||
- EVSM or PCF shadows
|
||||
- Transparent shadows
|
||||
- Contact shadows
|
||||
- Screen-space ambient occlusion
|
||||
- Screen-space refraction
|
||||
- Global fog
|
||||
- Dynamic resolution
|
||||
- Dynamic resolution (with support for AMD FidelityFX FSR)
|
||||
|
||||
### Post processing
|
||||
|
||||
- HDR bloom
|
||||
- Depth of field bokeh
|
||||
- Multiple tone mappers: ACES, filmic, etc.
|
||||
- Color grading: white balance, channel mixer, shadows/mid-tones/highlights, ASC CDL,
|
||||
contrast, saturation, etc.
|
||||
- Multiple tone mappers: generic (customizable), ACES, filmic, etc.
|
||||
- Color and tone management: luminance scaling, gamut mapping
|
||||
- Color grading: exposure, night adaptation, white balance, channel mixer,
|
||||
shadows/mid-tones/highlights, ASC CDL, contrast, saturation, etc.
|
||||
- TAA, FXAA, MSAA
|
||||
- Screen-space lens flares
|
||||
|
||||
@@ -189,10 +168,12 @@ Here are a few screenshots of applications that use Filament in production:
|
||||
- [x] KHR_draco_mesh_compression
|
||||
- [x] KHR_lights_punctual
|
||||
- [x] KHR_materials_clearcoat
|
||||
- [x] KHR_materials_ior
|
||||
- [x] KHR_materials_pbrSpecularGlossiness
|
||||
- [x] KHR_materials_sheen
|
||||
- [x] KHR_materials_transmission
|
||||
- [x] KHR_materials_unlit
|
||||
- [x] KHR_materials_volume
|
||||
- [x] KHR_mesh_quantization
|
||||
- [x] KHR_texture_transform
|
||||
|
||||
@@ -260,22 +241,11 @@ if (renderer->beginFrame(swapChain)) {
|
||||
```
|
||||
|
||||
For complete examples of Linux, macOS and Windows Filament applications, look at the source files
|
||||
in the `samples/` directory. These samples are all based on `samples/app/` which contains the code
|
||||
that creates a native window with SDL2 and initializes the Filament engine, renderer and views.
|
||||
in the `samples/` directory. These samples are all based on `libs/filamentapp/` which contains the
|
||||
code that creates a native window with SDL2 and initializes the Filament engine, renderer and views.
|
||||
|
||||
### Java on Linux, macOS and Windows
|
||||
|
||||
After building Filament, you can use `filament-java.jar` and its companion `filament-jni` native
|
||||
library to use Filament in desktop Java applications.
|
||||
|
||||
You must always first initialize Filament by calling `Filament.init()`.
|
||||
|
||||
You can use Filament either with AWT or Swing, using respectively a `FilamentCanvas` or a
|
||||
`FilamentPanel`.
|
||||
|
||||
Following the steps above (how to use Filament from native code), create an `Engine` and a
|
||||
`Renderer`, but instead of calling `beginFrame` and `endFrame` on the renderer itself, call
|
||||
these methods on `FilamentCanvas` or `FilamentPanel`.
|
||||
For more information on how to prepare environment maps for image-based lighting please refer to
|
||||
[BUILDING.md](https://github.com/google/filament/blob/main/BUILDING.md#running-the-native-samples).
|
||||
|
||||
### Android
|
||||
|
||||
@@ -306,6 +276,10 @@ To get started you can use the textures and environment maps found respectively
|
||||
`third_party/textures` and `third_party/environments`. These assets are under CC0 license. Please
|
||||
refer to their respective `URL.txt` files to know more about the original authors.
|
||||
|
||||
Environments must be pre-processed using
|
||||
[`cmgen`](https://github.com/google/filament/blob/main/BUILDING.md#running-the-native-samples) or
|
||||
using the `libiblprefilter` library.
|
||||
|
||||
## How to make contributions
|
||||
|
||||
Please read and follow the steps in [CONTRIBUTING.md](/CONTRIBUTING.md). Make sure you are
|
||||
@@ -328,9 +302,9 @@ and tools.
|
||||
- `docs`: Documentation
|
||||
- `math`: Mathematica notebooks used to explore BRDFs, equations, etc.
|
||||
- `filament`: Filament rendering engine (minimal dependencies)
|
||||
- `backend`: Rendering backends/drivers (Vulkan, Metal, OpenGL/ES)
|
||||
- `ide`: Configuration files for IDEs (CLion, etc.)
|
||||
- `ios`: Sample projects for iOS
|
||||
- `java`: Java bindings for Filament libraries
|
||||
- `libs`: Libraries
|
||||
- `bluegl`: OpenGL bindings for macOS, Linux and Windows
|
||||
- `bluevk`: Vulkan bindings for macOS, Linux, Windows and Android
|
||||
@@ -350,6 +324,7 @@ and tools.
|
||||
- `math`: Math library
|
||||
- `mathio`: Math types support for output streams
|
||||
- `utils`: Utility library (threads, memory, data structures, etc.)
|
||||
- `viewer`: glTF viewer library (requires gltfio)
|
||||
- `samples`: Sample desktop applications
|
||||
- `shaders`: Shaders used by `filamat` and `matc`
|
||||
- `third_party`: External libraries and assets
|
||||
|
||||
209
RELEASE_NOTES.md
209
RELEASE_NOTES.md
@@ -3,7 +3,214 @@
|
||||
This file contains one line summaries of commits that are worthy of mentioning in release notes.
|
||||
A new header is inserted each time a *tag* is created.
|
||||
|
||||
## v1.10.3 (currently main branch)
|
||||
## v1.14.3 (currently main branch)
|
||||
|
||||
## v1.14.2
|
||||
|
||||
- Metal: Fix validation error when rendering to `RenderTarget` without depth attachment.
|
||||
- engine: Fix rendering glitch with zero-scale bone transforms.
|
||||
|
||||
## v1.14.1
|
||||
|
||||
- engine: Improvements to shadowing.
|
||||
|
||||
## v1.14.0
|
||||
|
||||
- engine: Internal materials can use structures as parameters [⚠️ **Material breakage**].
|
||||
- engine: `readPixels` on a `SwapChain` must be called within `beginFrame` / `endFrame` [⚠️ **API
|
||||
Change**].
|
||||
- engine: Fix normal bias and improve spotlight quality.
|
||||
- Java: Fix shadow biases.
|
||||
|
||||
## v1.13.0
|
||||
|
||||
- Android: Gradle configuration caching is now enabled.
|
||||
- Android: Filament's Gradle properties have all been renamed to `com.google.android.filament.xxx`
|
||||
where `xxx` is the property name. See `android/build.gradle` for a complete list [⚠️]
|
||||
- Android: The Gradle property `filament_tools_dir` (now called
|
||||
`com.google.android.filament.tools-dir`) does not have a default value anymore. Please specify one
|
||||
in your `gradle.properties` if you reuse the Gradle plugin in your projects [⚠️]
|
||||
- engine: Fix spotlights direction and falloff [⚠️ **Material breakage**].
|
||||
- engine: Improvements to VSM and spotlight shadows.
|
||||
|
||||
## v1.12.11
|
||||
|
||||
- Metal: Color grading performance improvement on M1 devices.
|
||||
- samples: Fix glitchy animation seen in gltf-viewer iOS sample.
|
||||
|
||||
## v1.12.10
|
||||
|
||||
- engine: rewrite dynamic resolution scaling controller for better accuracy and less jittering.
|
||||
- Java: fix missing ASTC texture enum.
|
||||
- tools: Fix normal map issues in mipgen.
|
||||
- WebGL: expose some `SurfaceOrientation` functions.
|
||||
|
||||
## v1.12.9
|
||||
|
||||
- engine: New API: `MultiSampleAntiAliasingOptions` and HDR-aware MSAA resolve. When `customResolve`
|
||||
is enabled, improves anti-aliasing quality [**NEW API**].
|
||||
- engine: Fixes and improvements for FSR.
|
||||
- engine: All APIs that take a callback as argument now also take a `CallbackHandler*`, a new
|
||||
interface that provides more flexibility around callback dispatch [**NEW API**].
|
||||
- Android: Fix JNI bindings for `DepthOfFieldOptions`.
|
||||
- Android: workarounds for Adreno-specific fraembuffer issue.
|
||||
- JavaScript: updates to JS bindings.
|
||||
|
||||
## v1.12.8
|
||||
|
||||
- engine: Added picking API to `View` [⚠️ **Materials need to be rebuilt to access this new feature**].
|
||||
- engine: A new `Engine::pumpMessageQueues()` method can be used to trigger all pending user
|
||||
callbacks right away [**NEW API**].
|
||||
- engine: new inline helpers to more easily use lambdas, functors and method callbacks with
|
||||
`{Pixel}BufferDescriptor`.
|
||||
- Vulkan: fix vertical offset for `readPixels`.
|
||||
- Vulkan: various internal improvements.
|
||||
- Metal: support integer formats with `readPixels`.
|
||||
|
||||
## v1.12.7
|
||||
|
||||
- engine: Fix, apply emissive after shadowing.
|
||||
|
||||
## v1.12.6
|
||||
|
||||
- engine: Added concept of lod bias to materials.
|
||||
[⚠️ **Materials need to be rebuilt to access this new feature**].
|
||||
- engine: Fix, BGRA ordering respected for external images with OpenGL on iOS.
|
||||
- engine: Use more sensible defaults for spot light inner outer cone angles.
|
||||
- engine: Fix potential race condition that caused stalls in `endFrame`.
|
||||
- gltfio: Improved handling of transparent materials.
|
||||
- Metal: Fix potential crash on earlier versions of iOS (<= 13.0).
|
||||
- Android: Fix `filament-utils-android` 'lite' flavor.
|
||||
- Java: Fix potential crash with `IBLPrefilter`.
|
||||
|
||||
## v1.12.5
|
||||
|
||||
- engine: work around a job scheduling issue in `endFrame` that caused stuttering on some Android
|
||||
devices.
|
||||
|
||||
## v1.12.4
|
||||
|
||||
- engine: New night adaptation API on `ColorGrading`. This API can be used to create an effect that
|
||||
that simulates color and brightness shifts in human vision in low-light conditions.
|
||||
- engine: improved performance of AMD FidelityFX FSR1 by 4.6x, it now runs in about 2ms in 4K.
|
||||
- engine: Dynamic resolution quality `MEDIUM`, `HIGH` and `ULTRA` now all use AMD FidelityFX FSR1.
|
||||
- engine: Fix crash when duplicating material instances.
|
||||
- gltfio: generate tangents if requested by the material.
|
||||
|
||||
## v1.12.3
|
||||
|
||||
- engine: Support AMD FidelityFX Super Resolution for dynamic resolution scaling
|
||||
|
||||
## v1.12.2
|
||||
|
||||
- engine: New API on `ColorGrading` to enable or disable gamut mapping at will [**New API**].
|
||||
- engine: Fix typo causing ShadowOptions::shadowFar to not work properly.
|
||||
- engine: Fix, CSM glitch when using shadowMultiplier materials.
|
||||
- engine: Improve precision when computing camera projection.
|
||||
- engine: Increase the number of supported spot shadows to 14 (from 6).
|
||||
- Metal: Add texture swizzling support for external textures.
|
||||
|
||||
## v1.12.1
|
||||
|
||||
- engine: `double` precision translation support in TransformManager. Disabled by default.
|
||||
Augment model (and view) matrix on `Camera` to accept double precision matrices. When enabled,
|
||||
double precision translations allow filament to handle a very large world space [**New API**].
|
||||
- engine: Fix, Views with custom render targets are now blendable.
|
||||
|
||||
## v1.12.0
|
||||
|
||||
- engine: Option to automatically compute bent normals from SSAO & apply to specular AO
|
||||
[⚠️ **Material breakage**].
|
||||
- engine: New APIs: Light channels. Geometry and lights now have a channel associated to them, at
|
||||
least one channel must match for lighting to occur [⚠️ **Material breakage**].
|
||||
- engine: Fix potential GPU crash with punctual lights near the far clipping plane.
|
||||
- materials: The `inverseTonemap` API is now an exact inverse of the Filmic tonemapper.
|
||||
- Metal: Better support for texture formats on M1 Macs.
|
||||
|
||||
## v1.11.2
|
||||
|
||||
- engine: New API: `ColorGrading::Builder::toneMapper(const ToneMapper*)`.
|
||||
- engine: New tone mapper: `GenericToneMapper`, a configurable tone mapper.
|
||||
- engine: `ColorGrading::Builder::toneMapping(ColorGrading::ToneMapping)` is now deprecated.
|
||||
- engine: Removed `REINHARD` tonemap operator[⚠️ **API Change**].
|
||||
- engine: Improve s3tc_srgb detection on desktop.
|
||||
- engine: Add bilateral threshold in SSAO options.
|
||||
- gltfio: Fix AssetLoader leak, remove unwanted destructor.
|
||||
- Metal/Vulkan: Fix uploading texture data with padding or offset.
|
||||
- Metal: fix GPU crash seen with large amounts of geometry.
|
||||
|
||||
## v1.11.1
|
||||
|
||||
- engine: Luminance scaling can now be used with any tone mapping operator. It was previously tied
|
||||
to the "EVILS" tone mapping operator.
|
||||
- engine: Removed the "EVILS" tone mapping operator [⚠️ **API Change**].
|
||||
- engine: Improvements to Skinning. A new `SkinningBuffer` API allows bone sharing between
|
||||
renderables.
|
||||
- engine: Improvements to internal memory allocation for Metal and Vulkan backends.
|
||||
- engine: Default to OpenGL backend when Windows does not support Vulkan.
|
||||
- samples: Add new sample app: image_viewer.
|
||||
|
||||
## v1.11.0
|
||||
|
||||
- engine: Added support for transparent shadows. Add `transparentShadow : true` in the material file.
|
||||
- engine: honor user-defined precision in material files for non-samplers, rename `SamplerPrecision`
|
||||
to `ParameterPrecicion`. [⚠️ **API Change**]
|
||||
- engine: Work around Qualcomm issue with point lights.
|
||||
- engine: Allow MSAA when post-processing is disabled.
|
||||
- engine: enable up to 6 spot-light shadows.
|
||||
- gltfio: Added support for `KHR_materials_volume`.
|
||||
- gltfio: fix precision in KHR_texture_transform.
|
||||
- java: Removed support for Java desktop targets (macOS, Linux, and Windows) [⚠️ **API Change**].
|
||||
|
||||
## v1.10.7
|
||||
|
||||
- engine: Spot-light position calculation moved to fragment shader.
|
||||
- engine: Small shadow mapping fixes and improvements.
|
||||
- gltfio: Add fast path for native material providers.
|
||||
- gltfio: Allow Java / Kotlin clients to customize MaterialProvider.
|
||||
- engine: Fix out of bounds access with `RenderTarget` java bindings.
|
||||
- Metal: `TextureFormat::DEPTH24_STENCIL8` now maps to a 32 bit depth format on iOS.
|
||||
|
||||
## v1.10.6
|
||||
|
||||
- engine: Use exponential VSM and improve VSM user settings [⚠️ **Recompile Materials for VSM**].
|
||||
- engine: Optional blurring of VSM shadowmaps.
|
||||
- engine: Fix a crash when using lens flares.
|
||||
- engine: Fix backend crashes when using an unsupported sample count.
|
||||
- gltfio: Add new `getAsset`API to `FilamentInstance`.
|
||||
- gltfio: Introduce support for extras strings.
|
||||
- OpenGL: Increase OpenGL backend handle arena from 2 to 4 MiB.
|
||||
- Vulkan: Fix Texture swizzle support.
|
||||
|
||||
## v1.10.5
|
||||
|
||||
- android: AAR libraries now properly include their ProGuard rules.
|
||||
- engine: User materials can now provide custom lighting/surface shading, please consult
|
||||
the [materials documentation](https://google.github.io/filament/Materials.html) for details.
|
||||
- engine: `Backend::DEFAULT` now selects the most appropriate backend for the platform, rather than
|
||||
always `OPENGL`. On Android the default is `OPENGL`, on Apple platforms the default is `METAL` and
|
||||
on all other platforms that default is `VULKAN`.
|
||||
- engine: Fix a potential memory corruption when using more than 4 render targets.
|
||||
- engine: Fix a possible crash when bloom is enabled.
|
||||
- engine: Fix and refactor support for S3TC + SRGB with OpenGL.
|
||||
- engine: Fix automatic clearing of rendertargets.
|
||||
- engine: Fix imported render target discard and clear flags.
|
||||
- engine: Fix opaque blit with imported render targets.
|
||||
|
||||
## v1.10.4
|
||||
|
||||
- engine: improvements to internal job system.
|
||||
- Vulkan: performance improvements on Mali.
|
||||
- gltfio: improvements to load time for large models.
|
||||
- WebGL: remove bogus stride argument, fix `BindingType` TypeScript definition.
|
||||
|
||||
## v1.10.3
|
||||
|
||||
- android: use `debug.filament.backend` system property to select the desired backend.
|
||||
- engine: fix `LightManager::getFalloff`.
|
||||
- gltfio: fix crash with non-triangles.
|
||||
- macOS: fix main thread checker warnings with OpenGL.
|
||||
- vulkan: fix crash on Windows machines with NVIDIA GPUs.
|
||||
|
||||
## v1.10.2
|
||||
|
||||
|
||||
@@ -122,20 +122,20 @@ The Gradle project used to generate the AAR is located at `<filament>\android`.
|
||||
|
||||
```
|
||||
cd android
|
||||
gradlew -Pfilament_dist_dir=..\out\android-release\filament assembleRelease
|
||||
gradlew -Pcom.google.android.filament.dist-dir=..\out\android-release\filament assembleRelease
|
||||
copy filament-android\build\outputs\aar\filament-android-release.aar ..\..\out\
|
||||
```
|
||||
|
||||
If you're only interested in building for a single ABI, you'll need to pass a `filament_abis` parameter:
|
||||
If you're only interested in building for a single ABI, you'll need to pass a `com.google.android.filament.abis` parameter:
|
||||
|
||||
```
|
||||
gradlew -Pfilament_dist_dir=..\out\android-release\filament assembleRelease -Pfilament_abis=x86
|
||||
gradlew -Pcom.google.android.filament.dist-dir=..\out\android-release\filament assembleRelease -Pcom.google.android.filament.abis=x86
|
||||
```
|
||||
|
||||
If you're only interested in building SDK, you may skip samples build by passing a `filament_skip_samples` flag:
|
||||
If you're only interested in building SDK, you may skip samples build by passing a `com.google.android.filament.skip-samples` flag:
|
||||
|
||||
```
|
||||
gradlew -Pfilament_dist_dir=..\out\android-release\filament assembleRelease -Pfilament_skip_samples
|
||||
gradlew -Pcom.google.android.filament.dist-dir=..\out\android-release\filament assembleRelease -Pfilament_skip_samples
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
// This script accepts the following parameters:
|
||||
//
|
||||
// filament_dist_dir
|
||||
// com.google.android.filament.dist-dir
|
||||
// Path to the Filament distribution/install directory for Android
|
||||
// (produced by make/ninja install). This directory must contain lib/arm64-v8a/ etc.
|
||||
//
|
||||
// filament_tools_dir
|
||||
// com.google.android.filament.tools-dir
|
||||
// Path to the Filament distribution/install directory for desktop.
|
||||
// This directory must contain bin/matc.
|
||||
//
|
||||
// filament_exclude_vulkan
|
||||
// com.google.android.filament.exclude-vulkan
|
||||
// When set, support for Vulkan will be excluded.
|
||||
//
|
||||
// filament_skip_samples
|
||||
// com.google.android.filament.skip-samples
|
||||
// Exclude samples from the project. Useful to speed up compilation.
|
||||
//
|
||||
// filament_abis
|
||||
// com.google.android.filament.abis
|
||||
// List of supported ABIs to build as a comma separated list. Available options are:
|
||||
// arm64-v8a, armeabi-v7a, x86_64, x86, all
|
||||
// Defaults to all.
|
||||
//
|
||||
// Example:
|
||||
// ./gradlew -Pfilament_dist_dir=../dist-android-release assembleRelease -Pfilament_abis=x86
|
||||
// ./gradlew -Pcom.google.android.filament.dist-dir=../dist-android-release \
|
||||
// -Pcom.google.android.filament.abis=x86 \
|
||||
// assembleRelease
|
||||
|
||||
// Publishing to Maven Central:
|
||||
// - Build and upload artifacts with ./gradlew publish
|
||||
@@ -40,45 +42,53 @@
|
||||
//
|
||||
|
||||
buildscript {
|
||||
def filamentPath = file("../out/android-release/filament").absolutePath
|
||||
if (project.hasProperty("filament_dist_dir")) {
|
||||
filamentPath = file(project.property("filament_dist_dir")).absolutePath
|
||||
}
|
||||
def path = providers
|
||||
.gradleProperty("com.google.android.filament.dist-dir")
|
||||
.forUseAtConfigurationTime().get()
|
||||
|
||||
def directory = objects.fileProperty().fileValue(new File(path)).getAsFile().get()
|
||||
def filamentPath = directory.absolutePath
|
||||
|
||||
// Our CMake scripts require a forward-slash path for the FILAMENT_DIST_DIR
|
||||
// variable, so here we convert the native path to a forward-slash path.
|
||||
filamentPath = filamentPath.replace(File.separator, '/')
|
||||
|
||||
// Warning: changing this property does not work well with incremental builds.
|
||||
def excludeVulkan = project.hasProperty("filament_exclude_vulkan")
|
||||
def excludeVulkan = providers
|
||||
.gradleProperty("com.google.android.filament.exclude-vulkan")
|
||||
.forUseAtConfigurationTime()
|
||||
.isPresent()
|
||||
|
||||
def abis = ["arm64-v8a", "armeabi-v7a", "x86_64", "x86"]
|
||||
if (project.hasProperty("filament_abis")) {
|
||||
def newAbis = project.property("filament_abis").split(',')
|
||||
if (!newAbis.contains("all")) {
|
||||
abis = newAbis
|
||||
}
|
||||
def newAbis = providers
|
||||
.gradleProperty("com.google.android.filament.abis")
|
||||
.forUseAtConfigurationTime()
|
||||
.get()
|
||||
.split(',')
|
||||
if (!newAbis.contains("all")) {
|
||||
abis = newAbis
|
||||
}
|
||||
|
||||
// Our minSdkVersion is 19.
|
||||
ext.versions = [
|
||||
'minSdk': 19,
|
||||
'targetSdk': 30,
|
||||
'compileSdk': 30,
|
||||
'kotlin': '1.5.0',
|
||||
'buildTools': '30.0.3',
|
||||
'ndk': '22.1.7171670'
|
||||
'targetSdk': 31,
|
||||
'compileSdk': 31,
|
||||
'kotlin': '1.6.0',
|
||||
'buildTools': '31.0.0',
|
||||
'ndk': '23.1.7779620'
|
||||
]
|
||||
|
||||
ext.deps = [
|
||||
'androidx': [
|
||||
'annotations': "androidx.annotation:annotation:1.1.0",
|
||||
'annotations': "androidx.annotation:annotation:1.3.0",
|
||||
'core': "androidx.core:core:1.3.0",
|
||||
],
|
||||
'kotlin': "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
|
||||
]
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.2.0'
|
||||
// NOTE: See TODO in gradle.properties once we move to Gradle 7.2
|
||||
classpath 'com.android.tools.build:gradle:7.0.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
|
||||
}
|
||||
|
||||
@@ -93,8 +103,7 @@ buildscript {
|
||||
ext.cppFlags = [
|
||||
"-std=c++17",
|
||||
"-Wno-unused-command-line-argument",
|
||||
// Required to support API levels below 23
|
||||
"-Wl,--hash-style=both",
|
||||
"-Wl,--hash-style=both", // Required to support API levels below 23
|
||||
"-fno-stack-protector",
|
||||
"-fno-exceptions",
|
||||
"-fno-unwind-tables",
|
||||
@@ -120,7 +129,7 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'io.codearte.nexus-staging' version '0.22.0'
|
||||
id 'io.codearte.nexus-staging' version '0.30.0'
|
||||
}
|
||||
|
||||
// Nexus Staging configuration
|
||||
@@ -161,8 +170,9 @@ subprojects {
|
||||
ndk {
|
||||
abiFilters(*rootProject.ext.abis)
|
||||
}
|
||||
}
|
||||
|
||||
consumerProguardFiles '../proguard-rules.pro'
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
@@ -188,7 +198,8 @@ subprojects {
|
||||
gradle.taskGraph.whenReady {
|
||||
gradle.taskGraph.allTasks.each {
|
||||
it.onlyIf {
|
||||
!it.project.ext.has('isSample') || !project.hasProperty('filament_skip_samples')
|
||||
!it.project.ext.has('isSample') ||
|
||||
!project.hasProperty('com.google.android.filament.skip-samples')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
|
||||
plugins {
|
||||
id 'groovy-gradle-plugin'
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("filament-tools-plugin") {
|
||||
id = "filament-tools-plugin"
|
||||
implementationClass = "FilamentToolsPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
// This plugin accepts the following parameters:
|
||||
//
|
||||
// filament_tools_dir
|
||||
// com.google.android.filament.tools-dir
|
||||
// Path to the Filament distribution/install directory for desktop.
|
||||
// This directory must contain bin/matc.
|
||||
//
|
||||
// filament_exclude_vulkan
|
||||
// com.google.android.filament.exclude-vulkan
|
||||
// When set, support for Vulkan will be excluded.
|
||||
//
|
||||
// Example:
|
||||
// ./gradlew -Pfilament_tools_dir=../../dist-release assembleDebug
|
||||
// ./gradlew -Pcom.google.android.filament.tools-dir=../../dist-release assembleDebug
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.ProviderFactory
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileSystemOperations
|
||||
import org.gradle.api.file.FileType
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.logging.LogLevel
|
||||
@@ -27,14 +29,18 @@ import org.gradle.api.tasks.Optional
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.incremental.InputFileDetails
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
import org.gradle.process.ExecOperations
|
||||
import org.gradle.work.ChangeType
|
||||
import org.gradle.work.Incremental
|
||||
import org.gradle.work.InputChanges
|
||||
|
||||
import java.nio.file.Paths
|
||||
|
||||
class TaskWithBinary extends DefaultTask {
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class TaskWithBinary extends DefaultTask {
|
||||
private final String binaryName
|
||||
private Property<String> binaryPath = null
|
||||
|
||||
@@ -42,15 +48,23 @@ class TaskWithBinary extends DefaultTask {
|
||||
binaryName = name
|
||||
}
|
||||
|
||||
@Inject abstract ObjectFactory getObjects()
|
||||
@Inject abstract ProviderFactory getProviders()
|
||||
|
||||
@Input
|
||||
Property<String> getBinary() {
|
||||
if (binaryPath == null) {
|
||||
def tool = ["/bin/${binaryName}.exe", "/bin/${binaryName}"]
|
||||
def fullPath = tool.collect { path ->
|
||||
Paths.get(project.ext.filamentToolsPath.absolutePath, path).toFile()
|
||||
def filamentToolsPath = providers
|
||||
.gradleProperty("com.google.android.filament.tools-dir")
|
||||
.forUseAtConfigurationTime().get()
|
||||
def directory = objects.fileProperty()
|
||||
.fileValue(new File(filamentToolsPath)).getAsFile().get()
|
||||
Paths.get(directory.absolutePath, path).toFile()
|
||||
}
|
||||
|
||||
binaryPath = project.objects.property(String.class)
|
||||
binaryPath = objects.property(String.class)
|
||||
binaryPath.set(
|
||||
(OperatingSystem.current().isWindows() ? fullPath[0] : fullPath[1]).toString())
|
||||
}
|
||||
@@ -84,6 +98,11 @@ abstract class MaterialCompiler extends TaskWithBinary {
|
||||
@OutputDirectory
|
||||
abstract DirectoryProperty getOutputDir()
|
||||
|
||||
@Inject abstract FileSystemOperations getFs()
|
||||
@Inject abstract ExecOperations getExec()
|
||||
@Inject abstract ObjectFactory getObjects()
|
||||
@Inject abstract ProviderFactory getProviders()
|
||||
|
||||
MaterialCompiler() {
|
||||
super("matc")
|
||||
}
|
||||
@@ -91,7 +110,9 @@ abstract class MaterialCompiler extends TaskWithBinary {
|
||||
@TaskAction
|
||||
void execute(InputChanges inputs) {
|
||||
if (!inputs.incremental) {
|
||||
project.delete(project.fileTree(outputDir.asFile.get()).matching { include '*.filamat' })
|
||||
fs.delete({
|
||||
delete(objects.fileTree().from(outputDir).matching { include '*.filamat' })
|
||||
})
|
||||
}
|
||||
|
||||
inputs.getFileChanges(inputDir).each { InputFileDetails change ->
|
||||
@@ -115,12 +136,15 @@ abstract class MaterialCompiler extends TaskWithBinary {
|
||||
}
|
||||
|
||||
def matcArgs = []
|
||||
if (!project.hasProperty("filament_exclude_vulkan")) {
|
||||
def exclude_vulkan = providers
|
||||
.gradleProperty("com.google.android.filament.exclude-vulkan")
|
||||
.forUseAtConfigurationTime().present
|
||||
if (!exclude_vulkan) {
|
||||
matcArgs += ['-a', 'vulkan']
|
||||
}
|
||||
matcArgs += ['-a', 'opengl', '-p', 'mobile', '-o', getOutputFile(file), file]
|
||||
|
||||
project.exec {
|
||||
exec.exec {
|
||||
standardOutput out
|
||||
errorOutput err
|
||||
executable "${binary.get()}"
|
||||
@@ -149,6 +173,10 @@ abstract class IblGenerator extends TaskWithBinary {
|
||||
@OutputDirectory
|
||||
abstract DirectoryProperty getOutputDir()
|
||||
|
||||
@Inject abstract FileSystemOperations getFs()
|
||||
@Inject abstract ExecOperations getExec()
|
||||
@Inject abstract ObjectFactory getObjects()
|
||||
|
||||
IblGenerator() {
|
||||
super("cmgen")
|
||||
}
|
||||
@@ -156,7 +184,9 @@ abstract class IblGenerator extends TaskWithBinary {
|
||||
@TaskAction
|
||||
void execute(InputChanges inputs) {
|
||||
if (!inputs.incremental) {
|
||||
project.delete(project.fileTree(outputDir.asFile.get()).matching { include '*' })
|
||||
fs.delete({
|
||||
delete(objects.fileTree().from(outputDir).matching { include '*' })
|
||||
})
|
||||
}
|
||||
|
||||
inputs.getFileChanges(inputFile).each { InputFileDetails change ->
|
||||
@@ -188,7 +218,7 @@ abstract class IblGenerator extends TaskWithBinary {
|
||||
}
|
||||
commandArgs = commandArgs + " " + file
|
||||
|
||||
project.exec {
|
||||
exec.exec {
|
||||
standardOutput out
|
||||
errorOutput err
|
||||
executable "${binary.get()}"
|
||||
@@ -213,6 +243,9 @@ abstract class MeshCompiler extends TaskWithBinary {
|
||||
@OutputDirectory
|
||||
abstract DirectoryProperty getOutputDir()
|
||||
|
||||
@Inject abstract FileSystemOperations getFs()
|
||||
@Inject abstract ExecOperations getExec()
|
||||
|
||||
MeshCompiler() {
|
||||
super("filamesh")
|
||||
}
|
||||
@@ -220,7 +253,9 @@ abstract class MeshCompiler extends TaskWithBinary {
|
||||
@TaskAction
|
||||
void execute(InputChanges inputs) {
|
||||
if (!inputs.incremental) {
|
||||
project.delete(project.fileTree(outputDir.asFile.get()).matching { include '*.filamesh' })
|
||||
fs.delete({
|
||||
delete(objects.fileTree().from(outputDir).matching { include '*.filamesh' })
|
||||
})
|
||||
}
|
||||
|
||||
inputs.getFileChanges(inputFile).each { InputFileDetails change ->
|
||||
@@ -243,7 +278,7 @@ abstract class MeshCompiler extends TaskWithBinary {
|
||||
" Ensure Filament has been built/installed before building this app.")
|
||||
}
|
||||
|
||||
project.exec {
|
||||
exec.exec {
|
||||
standardOutput out
|
||||
errorOutput err
|
||||
executable "${binary.get()}"
|
||||
@@ -280,11 +315,6 @@ class FilamentToolsPlugin implements Plugin<Project> {
|
||||
extension.meshInputFile = project.objects.fileProperty()
|
||||
extension.meshOutputDir = project.objects.directoryProperty()
|
||||
|
||||
project.ext.filamentToolsPath = project.file("../../../out/release/filament")
|
||||
if (project.hasProperty("filament_tools_dir")) {
|
||||
project.ext.filamentToolsPath = project.file(project.property("filament_tools_dir"))
|
||||
}
|
||||
|
||||
project.tasks.register("filamentCompileMaterials", MaterialCompiler) {
|
||||
enabled =
|
||||
extension.materialInputDir.isPresent() &&
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "CallbackUtils.h"
|
||||
|
||||
#include "private/backend/VirtualMachineEnv.h"
|
||||
|
||||
void acquireCallbackJni(JNIEnv* env, CallbackJni& callbackUtils) {
|
||||
#ifdef ANDROID
|
||||
callbackUtils.handlerClass = env->FindClass("android/os/Handler");
|
||||
@@ -49,53 +51,6 @@ void releaseCallbackJni(JNIEnv* env, CallbackJni callbackUtils, jobject handler,
|
||||
env->DeleteGlobalRef(callbackUtils.executorClass);
|
||||
}
|
||||
|
||||
JniBufferCallback* JniBufferCallback::make(filament::Engine* engine,
|
||||
JNIEnv* env, jobject handler, jobject callback, AutoBuffer&& buffer) {
|
||||
return new JniBufferCallback(env, handler, callback, std::move(buffer));
|
||||
}
|
||||
|
||||
JniBufferCallback::JniBufferCallback(JNIEnv* env, jobject handler, jobject callback,
|
||||
AutoBuffer&& buffer)
|
||||
: mEnv(env)
|
||||
, mHandler(env->NewGlobalRef(handler))
|
||||
, mCallback(env->NewGlobalRef(callback))
|
||||
, mBuffer(std::move(buffer)) {
|
||||
acquireCallbackJni(env, mCallbackUtils);
|
||||
}
|
||||
|
||||
JniBufferCallback::~JniBufferCallback() {
|
||||
releaseCallbackJni(mEnv, mCallbackUtils, mHandler, mCallback);
|
||||
}
|
||||
|
||||
void JniBufferCallback::invoke(void*, size_t, void* user) {
|
||||
JniBufferCallback* data = reinterpret_cast<JniBufferCallback*>(user);
|
||||
delete data;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
JniImageCallback* JniImageCallback::make(filament::Engine* engine,
|
||||
JNIEnv* env, jobject handler, jobject callback, long image) {
|
||||
return new JniImageCallback(env, handler, callback, image);
|
||||
}
|
||||
|
||||
JniImageCallback::JniImageCallback(JNIEnv* env, jobject handler, jobject callback, long image)
|
||||
: mEnv(env)
|
||||
, mHandler(env->NewGlobalRef(handler))
|
||||
, mCallback(env->NewGlobalRef(callback))
|
||||
, mImage(image) {
|
||||
acquireCallbackJni(env, mCallbackUtils);
|
||||
}
|
||||
|
||||
JniImageCallback::~JniImageCallback() {
|
||||
releaseCallbackJni(mEnv, mCallbackUtils, mHandler, mCallback);
|
||||
}
|
||||
|
||||
void JniImageCallback::invoke(void*, void* user) {
|
||||
JniImageCallback* data = reinterpret_cast<JniImageCallback*>(user);
|
||||
delete data;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
JniCallback* JniCallback::make(JNIEnv* env, jobject handler, jobject callback) {
|
||||
@@ -103,17 +58,65 @@ JniCallback* JniCallback::make(JNIEnv* env, jobject handler, jobject callback) {
|
||||
}
|
||||
|
||||
JniCallback::JniCallback(JNIEnv* env, jobject handler, jobject callback)
|
||||
: mEnv(env)
|
||||
, mHandler(env->NewGlobalRef(handler))
|
||||
, mCallback(env->NewGlobalRef(callback)) {
|
||||
: mHandler(env->NewGlobalRef(handler)),
|
||||
mCallback(env->NewGlobalRef(callback)) {
|
||||
acquireCallbackJni(env, mCallbackUtils);
|
||||
}
|
||||
|
||||
JniCallback::~JniCallback() {
|
||||
releaseCallbackJni(mEnv, mCallbackUtils, mHandler, mCallback);
|
||||
JniCallback::~JniCallback() = default;
|
||||
|
||||
void JniCallback::post(void* user, filament::backend::CallbackHandler::Callback callback) {
|
||||
callback(user);
|
||||
}
|
||||
|
||||
void JniCallback::invoke(void* user) {
|
||||
JniCallback* data = reinterpret_cast<JniCallback*>(user);
|
||||
delete data;
|
||||
void JniCallback::postToJavaAndDestroy(JniCallback* callback) {
|
||||
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
|
||||
releaseCallbackJni(env, callback->mCallbackUtils, callback->mHandler, callback->mCallback);
|
||||
delete callback;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
JniBufferCallback* JniBufferCallback::make(filament::Engine*,
|
||||
JNIEnv* env, jobject handler, jobject callback, AutoBuffer&& buffer) {
|
||||
return new JniBufferCallback(env, handler, callback, std::move(buffer));
|
||||
}
|
||||
|
||||
JniBufferCallback::JniBufferCallback(JNIEnv* env, jobject handler, jobject callback,
|
||||
AutoBuffer&& buffer)
|
||||
: JniCallback(env, handler, callback),
|
||||
mBuffer(std::move(buffer)) {
|
||||
acquireCallbackJni(env, mCallbackUtils);
|
||||
}
|
||||
|
||||
JniBufferCallback::~JniBufferCallback() = default;
|
||||
|
||||
void JniBufferCallback::postToJavaAndDestroy(void*, size_t, void* user) {
|
||||
JniBufferCallback* callback = (JniBufferCallback*)user;
|
||||
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
|
||||
callback->mBuffer.attachToJniThread(env);
|
||||
releaseCallbackJni(env, callback->mCallbackUtils, callback->mHandler, callback->mCallback);
|
||||
delete callback;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
JniImageCallback* JniImageCallback::make(filament::Engine*,
|
||||
JNIEnv* env, jobject handler, jobject callback, long image) {
|
||||
return new JniImageCallback(env, handler, callback, image);
|
||||
}
|
||||
|
||||
JniImageCallback::JniImageCallback(JNIEnv* env, jobject handler, jobject callback, long image)
|
||||
: JniCallback(env, handler, callback),
|
||||
mImage(image) {
|
||||
acquireCallbackJni(env, mCallbackUtils);
|
||||
}
|
||||
|
||||
JniImageCallback::~JniImageCallback() = default;
|
||||
|
||||
void JniImageCallback::postToJavaAndDestroy(void*, void* user) {
|
||||
JniImageCallback* callback = (JniImageCallback*)user;
|
||||
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
|
||||
releaseCallbackJni(env, callback->mCallbackUtils, callback->mHandler, callback->mCallback);
|
||||
delete callback;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
#include <backend/CallbackHandler.h>
|
||||
|
||||
#include <filament/Engine.h>
|
||||
|
||||
struct CallbackJni {
|
||||
@@ -35,57 +36,49 @@ struct CallbackJni {
|
||||
void acquireCallbackJni(JNIEnv* env, CallbackJni& callbackUtils);
|
||||
void releaseCallbackJni(JNIEnv* env, CallbackJni callbackUtils, jobject handler, jobject callback);
|
||||
|
||||
struct JniBufferCallback {
|
||||
struct JniCallback : private filament::backend::CallbackHandler {
|
||||
JniCallback(JniCallback const &) = delete;
|
||||
JniCallback(JniCallback&&) = delete;
|
||||
|
||||
static JniCallback* make(JNIEnv* env, jobject handler, jobject runnable);
|
||||
|
||||
static void postToJavaAndDestroy(JniCallback* callback);
|
||||
|
||||
void post(void* user, Callback callback) override;
|
||||
|
||||
filament::backend::CallbackHandler* getHandler() noexcept { return this; }
|
||||
|
||||
jobject getCallbackObject() { return mCallback; }
|
||||
|
||||
protected:
|
||||
JniCallback(JNIEnv* env, jobject handler, jobject runnable);
|
||||
virtual ~JniCallback();
|
||||
jobject mHandler;
|
||||
jobject mCallback;
|
||||
CallbackJni mCallbackUtils;
|
||||
};
|
||||
|
||||
|
||||
struct JniBufferCallback : public JniCallback {
|
||||
static JniBufferCallback* make(filament::Engine* engine,
|
||||
JNIEnv* env, jobject handler, jobject callback, AutoBuffer&& buffer);
|
||||
|
||||
static void invoke(void* buffer, size_t n, void* user);
|
||||
static void postToJavaAndDestroy(void*, size_t, void* user);
|
||||
|
||||
private:
|
||||
JniBufferCallback(JNIEnv* env, jobject handler, jobject callback, AutoBuffer&& buffer);
|
||||
JniBufferCallback(JniBufferCallback const &) = delete;
|
||||
JniBufferCallback(JniBufferCallback&&) = delete;
|
||||
~JniBufferCallback();
|
||||
|
||||
JNIEnv* mEnv;
|
||||
jobject mHandler;
|
||||
jobject mCallback;
|
||||
virtual ~JniBufferCallback();
|
||||
AutoBuffer mBuffer;
|
||||
CallbackJni mCallbackUtils;
|
||||
};
|
||||
|
||||
struct JniImageCallback {
|
||||
struct JniImageCallback : public JniCallback {
|
||||
static JniImageCallback* make(filament::Engine* engine, JNIEnv* env, jobject handler,
|
||||
jobject runnable, long image);
|
||||
|
||||
static void invoke(void* image, void* user);
|
||||
static void postToJavaAndDestroy(void*, void* user);
|
||||
|
||||
private:
|
||||
JniImageCallback(JNIEnv* env, jobject handler, jobject runnable, long image);
|
||||
JniImageCallback(JniImageCallback const &) = delete;
|
||||
JniImageCallback(JniImageCallback&&) = delete;
|
||||
~JniImageCallback();
|
||||
|
||||
JNIEnv* mEnv;
|
||||
jobject mHandler;
|
||||
jobject mCallback;
|
||||
virtual ~JniImageCallback();
|
||||
long mImage;
|
||||
CallbackJni mCallbackUtils;
|
||||
};
|
||||
|
||||
struct JniCallback {
|
||||
static JniCallback* make(JNIEnv* env, jobject handler, jobject runnable);
|
||||
|
||||
static void invoke(void* user);
|
||||
|
||||
private:
|
||||
JniCallback(JNIEnv* env, jobject handler, jobject runnable);
|
||||
JniCallback(JniCallback const &) = delete;
|
||||
JniCallback(JniCallback&&) = delete;
|
||||
~JniCallback();
|
||||
|
||||
JNIEnv* mEnv;
|
||||
jobject mHandler;
|
||||
jobject mCallback;
|
||||
CallbackJni mCallbackUtils;
|
||||
};
|
||||
|
||||
@@ -38,6 +38,10 @@ public:
|
||||
AutoBuffer(AutoBuffer&& rhs) noexcept;
|
||||
~AutoBuffer() noexcept;
|
||||
|
||||
void attachToJniThread(JNIEnv* env) noexcept {
|
||||
mEnv = env;
|
||||
}
|
||||
|
||||
void* getData() const noexcept {
|
||||
return mUserData;
|
||||
}
|
||||
|
||||
@@ -123,19 +123,22 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderInterpo
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderUniformParameter(
|
||||
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jstring name_) {
|
||||
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jint precision, jstring name_) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
const char* name = env->GetStringUTFChars(name_, nullptr);
|
||||
builder->parameter((MaterialBuilder::UniformType) uniformType, name);
|
||||
builder->parameter((MaterialBuilder::UniformType) uniformType,
|
||||
(MaterialBuilder::ParameterPrecision) precision, name);
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderUniformParameterArray(
|
||||
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jint size, jstring name_) {
|
||||
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jint size, jint precision,
|
||||
jstring name_) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
const char* name = env->GetStringUTFChars(name_, nullptr);
|
||||
builder->parameter((MaterialBuilder::UniformType) uniformType, (size_t) size, name);
|
||||
builder->parameter((MaterialBuilder::UniformType) uniformType, (size_t) size,
|
||||
(MaterialBuilder::ParameterPrecision) precision, name);
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
}
|
||||
|
||||
@@ -146,7 +149,7 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSampler
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
const char* name = env->GetStringUTFChars(name_, nullptr);
|
||||
builder->parameter((MaterialBuilder::SamplerType) samplerType,
|
||||
(MaterialBuilder::SamplerFormat) format, (MaterialBuilder::SamplerPrecision) precision,
|
||||
(MaterialBuilder::SamplerFormat) format, (MaterialBuilder::ParameterPrecision) precision,
|
||||
name);
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
}
|
||||
@@ -255,6 +258,13 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderShadowM
|
||||
builder->shadowMultiplier(shadowMultiplier);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderTransparentShadow(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean transparentShadow) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
builder->transparentShadow(transparentShadow);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecularAntiAliasing(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean specularAntiAliasing) {
|
||||
@@ -291,6 +301,13 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderFlipUV(
|
||||
builder->flipUV(flipUV);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderCustomSurfaceShading(JNIEnv*,
|
||||
jclass, jlong nativeBuilder, jboolean customSurfaceShading) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
builder->customSurfaceShading(customSurfaceShading);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMultiBounceAmbientOcclusion(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean multiBounceAO) {
|
||||
|
||||
@@ -91,7 +91,7 @@ public class MaterialBuilder {
|
||||
SHADOW
|
||||
}
|
||||
|
||||
public enum SamplerPrecision {
|
||||
public enum ParameterPrecision {
|
||||
LOW,
|
||||
MEDIUM,
|
||||
HIGH,
|
||||
@@ -247,19 +247,36 @@ public class MaterialBuilder {
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder uniformParameter(@NonNull UniformType type, String name) {
|
||||
nMaterialBuilderUniformParameter(mNativeObject, type.ordinal(), name);
|
||||
nMaterialBuilderUniformParameter(mNativeObject, type.ordinal(),
|
||||
ParameterPrecision.DEFAULT.ordinal(), name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder uniformParameter(@NonNull UniformType type,
|
||||
ParameterPrecision precision, String name) {
|
||||
nMaterialBuilderUniformParameter(mNativeObject, type.ordinal(), precision.ordinal(), name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder uniformParameterArray(@NonNull UniformType type, int size, String name) {
|
||||
nMaterialBuilderUniformParameterArray(mNativeObject, type.ordinal(), size, name);
|
||||
nMaterialBuilderUniformParameterArray(mNativeObject, type.ordinal(), size,
|
||||
ParameterPrecision.DEFAULT.ordinal(), name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder uniformParameterArray(@NonNull UniformType type, int size,
|
||||
ParameterPrecision precision, String name) {
|
||||
nMaterialBuilderUniformParameterArray(mNativeObject, type.ordinal(), size,
|
||||
precision.ordinal(), name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder samplerParameter(@NonNull SamplerType type, SamplerFormat format,
|
||||
SamplerPrecision precision, String name) {
|
||||
ParameterPrecision precision, String name) {
|
||||
nMaterialBuilderSamplerParameter(
|
||||
mNativeObject, type.ordinal(), format.ordinal(), precision.ordinal(), name);
|
||||
return this;
|
||||
@@ -349,6 +366,12 @@ public class MaterialBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder transparentShadow(boolean transparentShadow) {
|
||||
nMaterialBuilderTransparentShadow(mNativeObject, transparentShadow);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder specularAntiAliasing(boolean specularAntiAliasing) {
|
||||
nMaterialBuilderSpecularAntiAliasing(mNativeObject, specularAntiAliasing);
|
||||
@@ -391,6 +414,12 @@ public class MaterialBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder customSurfaceShading(boolean customSurfaceShading) {
|
||||
nMaterialBuilderCustomSurfaceShading(mNativeObject, customSurfaceShading);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder multiBounceAmbientOcclusion(boolean multiBounceAO) {
|
||||
nMaterialBuilderMultiBounceAmbientOcclusion(mNativeObject, multiBounceAO);
|
||||
@@ -523,9 +552,9 @@ public class MaterialBuilder {
|
||||
private static native void nMaterialBuilderShading(long nativeBuilder, int shading);
|
||||
private static native void nMaterialBuilderInterpolation(long nativeBuilder, int interpolation);
|
||||
private static native void nMaterialBuilderUniformParameter(long nativeBuilder, int type,
|
||||
String name);
|
||||
int precision, String name);
|
||||
private static native void nMaterialBuilderUniformParameterArray(long nativeBuilder, int type,
|
||||
int size, String name);
|
||||
int size, int precision, String name);
|
||||
private static native void nMaterialBuilderSamplerParameter(long nativeBuilder, int type,
|
||||
int format, int precision, String name);
|
||||
private static native void nMaterialBuilderVariable(long nativeBuilder, int variable,
|
||||
@@ -545,6 +574,8 @@ public class MaterialBuilder {
|
||||
|
||||
private static native void nMaterialBuilderShadowMultiplier(long mNativeObject,
|
||||
boolean shadowMultiplier);
|
||||
private static native void nMaterialBuilderTransparentShadow(long mNativeObject,
|
||||
boolean transparentShadow);
|
||||
private static native void nMaterialBuilderSpecularAntiAliasing(long mNativeObject,
|
||||
boolean specularAntiAliasing);
|
||||
private static native void nMaterialBuilderSpecularAntiAliasingVariance(long mNativeObject,
|
||||
@@ -556,6 +587,8 @@ public class MaterialBuilder {
|
||||
private static native void nMaterialBuilderClearCoatIorChange(long mNativeObject,
|
||||
boolean clearCoatIorChange);
|
||||
private static native void nMaterialBuilderFlipUV(long nativeBuilder, boolean flipUV);
|
||||
private static native void nMaterialBuilderCustomSurfaceShading(long nativeBuilder,
|
||||
boolean customSurfaceShading);
|
||||
private static native void nMaterialBuilderMultiBounceAmbientOcclusion(long nativeBuilder,
|
||||
boolean multiBounceAO);
|
||||
private static native void nMaterialBuilderSpecularAmbientOcclusion(long nativeBuilder,
|
||||
|
||||
@@ -27,6 +27,10 @@ add_library(filaflat STATIC IMPORTED)
|
||||
set_target_properties(filaflat PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilaflat.a)
|
||||
|
||||
add_library(filamat STATIC IMPORTED)
|
||||
set_target_properties(filamat PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilamat.a)
|
||||
|
||||
add_library(geometry STATIC IMPORTED)
|
||||
set_target_properties(geometry PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libgeometry.a)
|
||||
@@ -75,11 +79,13 @@ add_library(filament-jni SHARED
|
||||
src/main/cpp/RenderTarget.cpp
|
||||
src/main/cpp/Scene.cpp
|
||||
src/main/cpp/SkyBox.cpp
|
||||
src/main/cpp/SkinningBuffer.cpp
|
||||
src/main/cpp/Stream.cpp
|
||||
src/main/cpp/SurfaceOrientation.cpp
|
||||
src/main/cpp/SwapChain.cpp
|
||||
src/main/cpp/Texture.cpp
|
||||
src/main/cpp/TextureSampler.cpp
|
||||
src/main/cpp/ToneMapper.cpp
|
||||
src/main/cpp/TransformManager.cpp
|
||||
src/main/cpp/VertexBuffer.cpp
|
||||
src/main/cpp/View.cpp
|
||||
@@ -110,6 +116,7 @@ target_link_libraries(filament-jni
|
||||
PUBLIC geometry
|
||||
|
||||
$<$<STREQUAL:${FILAMENT_ENABLE_MATDBG},ON>:matdbg>
|
||||
$<$<STREQUAL:${FILAMENT_ENABLE_MATDBG},ON>:filamat>
|
||||
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:bluevk>
|
||||
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:vkshaders>
|
||||
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:smol-v>
|
||||
@@ -118,6 +125,7 @@ target_link_libraries(filament-jni
|
||||
target_include_directories(filament-jni PRIVATE
|
||||
..
|
||||
${FILAMENT_DIR}/include
|
||||
../../filament/backend/include
|
||||
../../third_party/robin-map
|
||||
../../libs/utils/include)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ LIBFILAMENT {
|
||||
*filament*Renderer*;
|
||||
*filament*RenderTarget*;
|
||||
*filament*Scene*;
|
||||
*filament*ToneMapper*;
|
||||
*filament*Transform*;
|
||||
*filament*Material*;
|
||||
*filament*IndexBuffer*;
|
||||
|
||||
@@ -91,7 +91,8 @@ Java_com_google_android_filament_BufferObject_nSetBuffer(JNIEnv *env, jclass typ
|
||||
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
|
||||
BufferDescriptor desc(data, sizeInBytes, &JniBufferCallback::invoke, callback);
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
bufferObject->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
|
||||
|
||||
|
||||
@@ -102,10 +102,19 @@ Java_com_google_android_filament_Camera_nSetModelMatrix(JNIEnv *env, jclass,
|
||||
jlong nativeCamera, jfloatArray in_) {
|
||||
Camera* camera = (Camera *) nativeCamera;
|
||||
jfloat *in = env->GetFloatArrayElements(in_, NULL);
|
||||
camera->setModelMatrix(*reinterpret_cast<const filament::math::mat4f*>(in));
|
||||
camera->setModelMatrix((math::mat4)*reinterpret_cast<const filament::math::mat4f*>(in));
|
||||
env->ReleaseFloatArrayElements(in_, in, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nSetModelMatrixFp64(JNIEnv *env, jclass,
|
||||
jlong nativeCamera, jdoubleArray in_) {
|
||||
Camera* camera = (Camera *) nativeCamera;
|
||||
jdouble *in = env->GetDoubleArrayElements(in_, NULL);
|
||||
camera->setModelMatrix(*reinterpret_cast<const filament::math::mat4*>(in));
|
||||
env->ReleaseDoubleArrayElements(in_, in, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nGetProjectionMatrix(JNIEnv *env, jclass,
|
||||
jlong nativeCamera, jdoubleArray out_) {
|
||||
@@ -141,21 +150,41 @@ Java_com_google_android_filament_Camera_nGetModelMatrix(JNIEnv *env, jclass,
|
||||
jlong nativeCamera, jfloatArray out_) {
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
jfloat *out = env->GetFloatArrayElements(out_, NULL);
|
||||
const filament::math::mat4f& m = camera->getModelMatrix();
|
||||
const filament::math::mat4f& m = (math::mat4f)camera->getModelMatrix();
|
||||
std::copy_n(&m[0][0], 16, out);
|
||||
env->ReleaseFloatArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nGetModelMatrixFp64(JNIEnv *env, jclass,
|
||||
jlong nativeCamera, jdoubleArray out_) {
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
jdouble *out = env->GetDoubleArrayElements(out_, NULL);
|
||||
const filament::math::mat4& m = camera->getModelMatrix();
|
||||
std::copy_n(&m[0][0], 16, out);
|
||||
env->ReleaseDoubleArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nGetViewMatrix(JNIEnv *env, jclass, jlong nativeCamera,
|
||||
jfloatArray out_) {
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
jfloat *out = env->GetFloatArrayElements(out_, NULL);
|
||||
const filament::math::mat4f& m = camera->getViewMatrix();
|
||||
const filament::math::mat4f& m = (math::mat4f)camera->getViewMatrix();
|
||||
std::copy_n(&m[0][0], 16, out);
|
||||
env->ReleaseFloatArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nGetViewMatrixFp64(JNIEnv *env, jclass, jlong nativeCamera,
|
||||
jdoubleArray out_) {
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
jdouble *out = env->GetDoubleArrayElements(out_, NULL);
|
||||
const filament::math::mat4& m = camera->getViewMatrix();
|
||||
std::copy_n(&m[0][0], 16, out);
|
||||
env->ReleaseDoubleArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nGetPosition(JNIEnv *env, jclass, jlong nativeCamera,
|
||||
jfloatArray out_) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <filament/ColorGrading.h>
|
||||
#include <filament/ToneMapper.h>
|
||||
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
@@ -30,28 +31,35 @@ Java_com_google_android_filament_ColorGrading_nCreateBuilder(JNIEnv*, jclass) {
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nDestroyBuilder(JNIEnv*, jclass,
|
||||
jlong nativeBuilder) {
|
||||
Java_com_google_android_filament_ColorGrading_nDestroyBuilder(JNIEnv*, jclass, jlong nativeBuilder) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
delete builder;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderBuild(JNIEnv*, jclass, jlong nativeBuilder, jlong nativeEngine) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderQuality(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint quality_) {
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderQuality(JNIEnv*, jclass, jlong nativeBuilder, jint quality_) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
ColorGrading::QualityLevel quality = (ColorGrading::QualityLevel) quality_;
|
||||
builder->quality(quality);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderToneMapper(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong toneMapper_) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
const ToneMapper* toneMapper = (const ToneMapper*) toneMapper_;
|
||||
builder->toneMapper(toneMapper);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderToneMapping(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint toneMapping_) {
|
||||
@@ -59,6 +67,35 @@ Java_com_google_android_filament_ColorGrading_nBuilderToneMapping(JNIEnv*, jclas
|
||||
ColorGrading::ToneMapping toneMapping = (ColorGrading::ToneMapping) toneMapping_;
|
||||
builder->toneMapping(toneMapping);
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderLuminanceScaling(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean luminanceScaling) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
builder->luminanceScaling(luminanceScaling);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderGamutMapping(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean gamutMapping) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
builder->gamutMapping(gamutMapping);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderExposure(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat exposure) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
builder->exposure(exposure);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderNightAdaptation(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat adaptation) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
builder->nightAdaptation(adaptation);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderWhiteBalance(JNIEnv*, jclass,
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace filament {
|
||||
extern jint JNI_OnLoad(JavaVM* vm, void* reserved);
|
||||
};
|
||||
#include "private/backend/VirtualMachineEnv.h"
|
||||
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
JNIEnv* env;
|
||||
@@ -26,9 +24,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if ANDROID
|
||||
::filament::JNI_OnLoad(vm, reserved);
|
||||
#endif
|
||||
// This must be called when the library is loaded. We need this to get a reference to the
|
||||
// global VM
|
||||
::filament::VirtualMachineEnv::JNI_OnLoad(vm);
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ Java_com_google_android_filament_IndexBuffer_nSetBuffer(JNIEnv *env, jclass type
|
||||
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
|
||||
BufferDescriptor desc(data, sizeInBytes, &JniBufferCallback::invoke, callback);
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
indexBuffer->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
|
||||
|
||||
|
||||
@@ -76,8 +76,10 @@ extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv* env, jclass,
|
||||
jlong nativeBuilder, jint mapSize, jint cascades, jfloatArray splitPositions,
|
||||
jfloat constantBias, jfloat normalBias, jfloat shadowFar, jfloat shadowNearHint,
|
||||
jfloat shadowFarHint, jboolean stable, jboolean screenSpaceContactShadows, jint stepCount,
|
||||
jfloat maxShadowDistance, jint vsmMsaaSamples) {
|
||||
jfloat shadowFarHint, jboolean stable,
|
||||
jfloat polygonOffsetConstant, jfloat polygonOffsetSlope,
|
||||
jboolean screenSpaceContactShadows, jint stepCount,
|
||||
jfloat maxShadowDistance, jint vsmMsaaSamples, jfloat blurWidth) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
LightManager::ShadowOptions shadowOptions {
|
||||
.mapSize = (uint32_t)mapSize,
|
||||
@@ -88,11 +90,14 @@ Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv* env,
|
||||
.shadowNearHint = shadowNearHint,
|
||||
.shadowFarHint = shadowFarHint,
|
||||
.stable = (bool)stable,
|
||||
.polygonOffsetConstant = polygonOffsetConstant,
|
||||
.polygonOffsetSlope = polygonOffsetConstant,
|
||||
.screenSpaceContactShadows = (bool)screenSpaceContactShadows,
|
||||
.stepCount = uint8_t(stepCount),
|
||||
.maxShadowDistance = maxShadowDistance,
|
||||
.vsm = {
|
||||
.msaaSamples = (uint8_t) vsmMsaaSamples
|
||||
.msaaSamples = (uint8_t) vsmMsaaSamples,
|
||||
.blurWidth = blurWidth
|
||||
}
|
||||
};
|
||||
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
|
||||
@@ -188,6 +193,23 @@ Java_com_google_android_filament_LightManager_nBuilderHaloFalloff(JNIEnv*, jclas
|
||||
builder->sunHaloFalloff(haloFalloff);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderLightChannel(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint channel, jboolean enable) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->lightChannel(channel, (bool)enable);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine, jint entity) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return jboolean(builder->build(*engine, (Entity &) entity) == LightManager::Builder::Success);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nComputeUniformSplits(JNIEnv* env, jclass,
|
||||
jfloatArray splitPositions, jint cascades) {
|
||||
@@ -212,13 +234,7 @@ Java_com_google_android_filament_LightManager_nComputePracticalSplits(JNIEnv* en
|
||||
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine, jint entity) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return jboolean(builder->build(*engine, (Entity &) entity) == LightManager::Builder::Success);
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetType(JNIEnv* env,
|
||||
@@ -393,3 +409,17 @@ Java_com_google_android_filament_LightManager_nGetInnerConeAngle(JNIEnv*, jclass
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return (jfloat)lm->getSpotLightInnerCone((LightManager::Instance) i);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetLightChannel(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jint channel, jboolean enable) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setLightChannel((LightManager::Instance) i, channel, (bool)enable);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetLightChannel(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jint channel) {
|
||||
LightManager const *lm = (LightManager const *) nativeLightManager;
|
||||
return lm->getLightChannel((LightManager::Instance) i, channel);
|
||||
}
|
||||
|
||||
@@ -170,6 +170,14 @@ Java_com_google_android_filament_RenderableManager_nBuilderScreenSpaceContactSha
|
||||
builder->screenSpaceContactShadows(enabled);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nBuilderSkinningBuffer(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeSkinningBuffer, jint boneCount, jint offset) {
|
||||
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
builder->skinning(skinningBuffer, boneCount, offset);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nBuilderSkinning(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint boneCount) {
|
||||
@@ -177,6 +185,13 @@ Java_com_google_android_filament_RenderableManager_nBuilderSkinning(JNIEnv*, jcl
|
||||
builder->skinning((size_t)boneCount);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nEnableSkinningBuffers(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean enabled) {
|
||||
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
|
||||
builder->enableSkinningBuffers(enabled);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nBuilderSkinningBones(JNIEnv* env, jclass,
|
||||
jlong nativeBuilder, jint boneCount, jobject bones, jint remaining) {
|
||||
@@ -199,6 +214,22 @@ Java_com_google_android_filament_RenderableManager_nBuilderMorphing(JNIEnv*, jcl
|
||||
builder->morphing(enabled);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nBuilderLightChannel(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint channel, jboolean enable) {
|
||||
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
|
||||
builder->lightChannel(channel, (bool)enable);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetSkinningBuffer(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jlong nativeSkinningBuffer, jint count, jint offset) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
SkinningBuffer *sb = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
rm->setSkinningBuffer(i, sb, count, offset);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetBonesAsMatrices(JNIEnv* env, jclass,
|
||||
@@ -339,21 +370,13 @@ Java_com_google_android_filament_RenderableManager_nSetMaterialInstanceAt(JNIEnv
|
||||
materialInstance);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT long JNICALL
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nGetMaterialInstanceAt(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jint primitiveIndex) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
return (long) rm->getMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT long JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nGetMaterialAt(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jint primitiveIndex) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
MaterialInstance *mi = rm->getMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
|
||||
return (long) mi->getMaterial();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetGeometryAt__JIIIJJII(JNIEnv*,
|
||||
jclass, jlong nativeRenderableManager, jint i, jint primitiveIndex, jint primitiveType,
|
||||
@@ -390,3 +413,17 @@ Java_com_google_android_filament_RenderableManager_nGetEnabledAttributesAt(JNIEn
|
||||
AttributeBitset enabled = rm->getEnabledAttributesAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
|
||||
return enabled.getValue();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetLightChannel(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jint channel, jboolean enable) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
rm->setLightChannel((RenderableManager::Instance) i, channel, (bool)enable);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nGetLightChannel(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jint channel) {
|
||||
RenderableManager const *rm = (RenderableManager const *) nativeRenderableManager;
|
||||
return rm->getLightChannel((RenderableManager::Instance) i, channel);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,8 @@ Java_com_google_android_filament_Renderer_nReadPixels(JNIEnv *env, jclass,
|
||||
|
||||
PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
|
||||
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
|
||||
(uint32_t) stride, &JniBufferCallback::invoke, callback);
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
renderer->readPixels(uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
|
||||
std::move(desc));
|
||||
@@ -132,7 +133,8 @@ Java_com_google_android_filament_Renderer_nReadPixelsEx(JNIEnv *env, jclass,
|
||||
|
||||
PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
|
||||
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
|
||||
(uint32_t) stride, &JniBufferCallback::invoke, callback);
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
renderer->readPixels(renderTarget,
|
||||
uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
|
||||
|
||||
116
android/filament-android/src/main/cpp/SkinningBuffer.cpp
Normal file
116
android/filament-android/src/main/cpp/SkinningBuffer.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <filament/SkinningBuffer.h>
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nCreateBuilder(JNIEnv*, jclass) {
|
||||
return (jlong) new SkinningBuffer::Builder();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nDestroyBuilder(JNIEnv*, jclass,
|
||||
jlong nativeBuilder) {
|
||||
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
|
||||
delete builder;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nBuilderBoneCount(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint boneCount) {
|
||||
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
|
||||
builder->boneCount((uint32_t)boneCount);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nBuilderInitialize(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean initialize) {
|
||||
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
|
||||
builder->initialize((bool)initialize);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nSetBonesAsMatrices(JNIEnv* env, jclass,
|
||||
jlong nativeSkinningBuffer, jlong nativeEngine, jobject matrices, jint remaining, jint boneCount,
|
||||
jint offset) {
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
AutoBuffer nioBuffer(env, matrices, boneCount * 16);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nSetBonesAsQuaternions(JNIEnv* env, jclass,
|
||||
jlong nativeSkinningBuffer, jlong nativeEngine, jobject quaternions, jint remaining,
|
||||
jint boneCount, jint offset) {
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
AutoBuffer nioBuffer(env, quaternions, boneCount * 8);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nGetBoneCount(JNIEnv*, jclass,
|
||||
jlong nativeSkinningBuffer) {
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
return (jint)skinningBuffer->getBoneCount();
|
||||
}
|
||||
@@ -169,7 +169,8 @@ Java_com_google_android_filament_Stream_nReadPixels(JNIEnv *env, jclass,
|
||||
|
||||
PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
|
||||
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
|
||||
(uint32_t) stride, &JniBufferCallback::invoke, callback);
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
stream->readPixels(uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
|
||||
std::move(desc));
|
||||
@@ -221,5 +222,6 @@ Java_com_google_android_filament_Stream_nSetAcquiredImage(JNIEnv* env, jclass, j
|
||||
|
||||
#endif
|
||||
|
||||
stream->setAcquiredImage((void*) nativeBuffer, &JniImageCallback::invoke, callback);
|
||||
stream->setAcquiredImage((void*) nativeBuffer,
|
||||
callback->getHandler(), &JniImageCallback::postToJavaAndDestroy, callback);
|
||||
}
|
||||
|
||||
@@ -27,5 +27,8 @@ Java_com_google_android_filament_SwapChain_nSetFrameCompletedCallback(JNIEnv* en
|
||||
jlong nativeSwapChain, jobject handler, jobject runnable) {
|
||||
SwapChain* swapChain = (SwapChain*) nativeSwapChain;
|
||||
auto *callback = JniCallback::make(env, handler, runnable);
|
||||
swapChain->setFrameCompletedCallback(&JniCallback::invoke, callback);
|
||||
swapChain->setFrameCompletedCallback([](void* user) {
|
||||
JniCallback* callback = (JniCallback*)user;
|
||||
JniCallback::postToJavaAndDestroy(callback);
|
||||
}, callback);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,8 @@ Java_com_google_android_filament_Texture_nSetImage(JNIEnv* env, jclass, jlong na
|
||||
|
||||
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
|
||||
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
|
||||
(uint32_t) stride, &JniBufferCallback::invoke, callback);
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
texture->setImage(*engine, (size_t) level, (uint32_t) xoffset, (uint32_t) yoffset,
|
||||
(uint32_t) width, (uint32_t) height, std::move(desc));
|
||||
@@ -240,7 +241,7 @@ Java_com_google_android_filament_Texture_nSetImageCompressed(JNIEnv *env, jclass
|
||||
|
||||
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes,
|
||||
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
|
||||
&JniBufferCallback::invoke, callback);
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
texture->setImage(*engine, (size_t) level, (uint32_t) xoffset, (uint32_t) yoffset,
|
||||
(uint32_t) width, (uint32_t) height, std::move(desc));
|
||||
@@ -274,7 +275,8 @@ Java_com_google_android_filament_Texture_nSetImage3D(JNIEnv* env, jclass, jlong
|
||||
|
||||
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
|
||||
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
|
||||
(uint32_t) stride, &JniBufferCallback::invoke, callback);
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
|
||||
@@ -308,7 +310,7 @@ Java_com_google_android_filament_Texture_nSetImage3DCompressed(JNIEnv *env, jcla
|
||||
|
||||
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes,
|
||||
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
|
||||
&JniBufferCallback::invoke, callback);
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
|
||||
@@ -346,7 +348,8 @@ Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
|
||||
|
||||
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
|
||||
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
|
||||
(uint32_t) stride, &JniBufferCallback::invoke, callback);
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
|
||||
|
||||
@@ -381,7 +384,7 @@ Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env,
|
||||
|
||||
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes,
|
||||
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
|
||||
&JniBufferCallback::invoke, callback);
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
|
||||
|
||||
@@ -454,7 +457,7 @@ Java_com_google_android_filament_Texture_nGeneratePrefilterMipmap(JNIEnv *env, j
|
||||
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
|
||||
(backend::PixelDataType) type, (uint8_t) alignment,
|
||||
(uint32_t) left, (uint32_t) top, (uint32_t) stride,
|
||||
&JniBufferCallback::invoke, callback);
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
Texture::PrefilterOptions options;
|
||||
options.sampleCount = sampleCount;
|
||||
@@ -563,7 +566,7 @@ private:
|
||||
jobject mBitmap = nullptr;
|
||||
jobject mHandler = nullptr;
|
||||
jobject mCallback = nullptr;
|
||||
AndroidBitmapInfo mInfo;
|
||||
AndroidBitmapInfo mInfo{};
|
||||
CallbackJni mCallbackUtils;
|
||||
};
|
||||
|
||||
|
||||
109
android/filament-android/src/main/cpp/ToneMapper.cpp
Normal file
109
android/filament-android/src/main/cpp/ToneMapper.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <filament/ToneMapper.h>
|
||||
|
||||
using namespace filament;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nDestroyToneMapper(JNIEnv *env, jclass clazz,
|
||||
jlong toneMapper_) {
|
||||
ToneMapper* toneMapper = (ToneMapper*) toneMapper_;
|
||||
delete toneMapper;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nCreateLinearToneMapper(JNIEnv*, jclass) {
|
||||
return (jlong) new LinearToneMapper();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nCreateACESToneMapper(JNIEnv*, jclass) {
|
||||
return (jlong) new ACESToneMapper();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nCreateACESLegacyToneMapper(JNIEnv*, jclass) {
|
||||
return (jlong) new ACESLegacyToneMapper();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nCreateFilmicToneMapper(JNIEnv*, jclass) {
|
||||
return (jlong) new FilmicToneMapper();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nCreateGenericToneMapper(JNIEnv*, jclass,
|
||||
jfloat contrast, jfloat shoulder, jfloat midGrayIn, jfloat midGrayOut, jfloat hdrMax) {
|
||||
return (jlong) new GenericToneMapper(contrast, shoulder, midGrayIn, midGrayOut, hdrMax);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericGetContrast(JNIEnv*, jclass, jlong nativeObject) {
|
||||
return ((GenericToneMapper*) nativeObject)->getContrast();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericGetShoulder(JNIEnv*, jclass, jlong nativeObject) {
|
||||
return ((GenericToneMapper*) nativeObject)->getShoulder();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericGetMidGrayIn(JNIEnv*, jclass, jlong nativeObject) {
|
||||
return ((GenericToneMapper*) nativeObject)->getMidGrayIn();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericGetMidGrayOut(JNIEnv*, jclass, jlong nativeObject) {
|
||||
return ((GenericToneMapper*) nativeObject)->getMidGrayOut();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericGetHdrMax(JNIEnv*, jclass, jlong nativeObject) {
|
||||
return ((GenericToneMapper*) nativeObject)->getHdrMax();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericSetContrast(JNIEnv*, jclass,
|
||||
jlong nativeObject, jfloat contrast) {
|
||||
((GenericToneMapper*) nativeObject)->setContrast(contrast);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericSetShoulder(JNIEnv*, jclass,
|
||||
jlong nativeObject, jfloat shoulder) {
|
||||
((GenericToneMapper*) nativeObject)->setShoulder(shoulder);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericSetMidGrayIn(JNIEnv*, jclass,
|
||||
jlong nativeObject, jfloat midGrayIn) {
|
||||
((GenericToneMapper*) nativeObject)->setMidGrayIn(midGrayIn);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericSetMidGrayOut(JNIEnv*, jclass,
|
||||
jlong nativeObject, jfloat midGrayOut) {
|
||||
((GenericToneMapper*) nativeObject)->setMidGrayOut(midGrayOut);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_ToneMapper_nGenericSetHdrMax(JNIEnv*, jclass,
|
||||
jlong nativeObject, jfloat hdrMax) {
|
||||
((GenericToneMapper*) nativeObject)->setHdrMax(hdrMax);
|
||||
}
|
||||
@@ -70,6 +70,23 @@ Java_com_google_android_filament_TransformManager_nCreateArray(JNIEnv* env,
|
||||
return tm->getInstance(entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nCreateArrayFp64(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint entity_, jint parent,
|
||||
jdoubleArray localTransform_) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
|
||||
if (localTransform_) {
|
||||
jdouble *localTransform = env->GetDoubleArrayElements(localTransform_, NULL);
|
||||
tm->create(entity, (TransformManager::Instance) parent,
|
||||
*reinterpret_cast<const filament::math::mat4 *>(localTransform));
|
||||
env->ReleaseDoubleArrayElements(localTransform_, localTransform, JNI_ABORT);
|
||||
} else {
|
||||
tm->create(entity, (TransformManager::Instance) parent);
|
||||
}
|
||||
return tm->getInstance(entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nDestroy(JNIEnv*, jclass,
|
||||
jlong nativeTransformManager, jint entity_) {
|
||||
@@ -104,6 +121,17 @@ Java_com_google_android_filament_TransformManager_nSetTransform(JNIEnv* env,
|
||||
env->ReleaseFloatArrayElements(localTransform_, localTransform, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nSetTransformFp64(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint i,
|
||||
jdoubleArray localTransform_) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
jdouble *localTransform = env->GetDoubleArrayElements(localTransform_, NULL);
|
||||
tm->setTransform((TransformManager::Instance) i,
|
||||
*reinterpret_cast<const filament::math::mat4 *>(localTransform));
|
||||
env->ReleaseDoubleArrayElements(localTransform_, localTransform, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nGetTransform(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint i,
|
||||
@@ -115,6 +143,17 @@ Java_com_google_android_filament_TransformManager_nGetTransform(JNIEnv* env,
|
||||
env->ReleaseFloatArrayElements(outLocalTransform_, outLocalTransform, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nGetTransformFp64(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint i,
|
||||
jdoubleArray outLocalTransform_) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
jdouble *outLocalTransform = env->GetDoubleArrayElements(outLocalTransform_, NULL);
|
||||
*reinterpret_cast<filament::math::mat4 *>(outLocalTransform) = tm->getTransformAccurate(
|
||||
(TransformManager::Instance) i);
|
||||
env->ReleaseDoubleArrayElements(outLocalTransform_, outLocalTransform, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nGetWorldTransform(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint i,
|
||||
@@ -126,6 +165,17 @@ Java_com_google_android_filament_TransformManager_nGetWorldTransform(JNIEnv* env
|
||||
env->ReleaseFloatArrayElements(outWorldTransform_, outWorldTransform, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nGetWorldTransformFp64(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint i,
|
||||
jdoubleArray outWorldTransform_) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
jdouble *outWorldTransform = env->GetDoubleArrayElements(outWorldTransform_, NULL);
|
||||
*reinterpret_cast<filament::math::mat4 *>(outWorldTransform) = tm->getWorldTransformAccurate(
|
||||
(TransformManager::Instance) i);
|
||||
env->ReleaseDoubleArrayElements(outWorldTransform_, outWorldTransform, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nOpenLocalTransformTransaction(
|
||||
JNIEnv*, jclass, jlong nativeTransformManager) {
|
||||
@@ -139,3 +189,19 @@ Java_com_google_android_filament_TransformManager_nCommitLocalTransformTransacti
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
tm->commitLocalTransformTransaction();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nSetAccurateTranslationsEnabled(JNIEnv*,
|
||||
jclass, jlong nativeTransformManager, jboolean enable) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
tm->setAccurateTranslationsEnabled((bool)enable);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nIsAccurateTranslationsEnabled(JNIEnv*,
|
||||
jclass, jlong nativeTransformManager) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
return (jboolean)tm->isAccurateTranslationsEnabled();
|
||||
}
|
||||
|
||||
@@ -32,40 +32,40 @@ using namespace filament::math;
|
||||
using namespace backend;
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nCreateBuilder(JNIEnv *env, jclass type) {
|
||||
Java_com_google_android_filament_VertexBuffer_nCreateBuilder(JNIEnv*, jclass) {
|
||||
return (jlong) new VertexBuffer::Builder();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nDestroyBuilder(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nDestroyBuilder(JNIEnv*, jclass,
|
||||
jlong nativeBuilder) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
delete builder;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderVertexCount(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderVertexCount(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint vertexCount) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
builder->vertexCount((uint32_t) vertexCount);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderEnableBufferObjects(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderEnableBufferObjects(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean enabled) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
builder->enableBufferObjects(enabled);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderBufferCount(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderBufferCount(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint bufferCount) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
builder->bufferCount((uint8_t) bufferCount);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderAttribute(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderAttribute(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint attribute, jint bufferIndex, jint attributeType, jint byteOffset,
|
||||
jint byteStride) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
@@ -75,14 +75,14 @@ Java_com_google_android_filament_VertexBuffer_nBuilderAttribute(JNIEnv *env, jcl
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderNormalized(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderNormalized(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint attribute, jboolean normalized) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
builder->normalized((VertexAttribute) attribute, normalized);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
@@ -90,14 +90,14 @@ Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv *env, jclass
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nGetVertexCount(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nGetVertexCount(JNIEnv*, jclass,
|
||||
jlong nativeVertexBuffer) {
|
||||
VertexBuffer *vertexBuffer = (VertexBuffer *) nativeVertexBuffer;
|
||||
return (jint) vertexBuffer->getVertexCount();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass,
|
||||
jlong nativeVertexBuffer, jlong nativeEngine, jint bufferIndex,
|
||||
jobject buffer, jint remaining,
|
||||
jint destOffsetInBytes, jint count, jobject handler, jobject runnable) {
|
||||
@@ -114,7 +114,8 @@ Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass t
|
||||
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
|
||||
BufferDescriptor desc(data, sizeInBytes, &JniBufferCallback::invoke, callback);
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
vertexBuffer->setBufferAt(*engine, (uint8_t) bufferIndex, std::move(desc),
|
||||
(uint32_t) destOffsetInBytes);
|
||||
@@ -123,7 +124,7 @@ Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass t
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nSetBufferObjectAt(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_VertexBuffer_nSetBufferObjectAt(JNIEnv*, jclass,
|
||||
jlong nativeVertexBuffer, jlong nativeEngine, jint bufferIndex, jlong nativeBufferObject) {
|
||||
VertexBuffer *vertexBuffer = (VertexBuffer *) nativeVertexBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
#include <filament/View.h>
|
||||
#include <filament/Viewport.h>
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
|
||||
#include "private/backend/VirtualMachineEnv.h"
|
||||
|
||||
using namespace filament;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -82,13 +86,19 @@ Java_com_google_android_filament_View_nSetRenderTarget(JNIEnv*, jclass,
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetSampleCount(JNIEnv*, jclass, jlong nativeView, jint count) {
|
||||
View* view = (View*) nativeView;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
view->setSampleCount((uint8_t) count);
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_View_nGetSampleCount(JNIEnv*, jclass, jlong nativeView) {
|
||||
View* view = (View*) nativeView;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
return view->getSampleCount();
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -119,13 +129,14 @@ Java_com_google_android_filament_View_nGetDithering(JNIEnv*, jclass,
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetDynamicResolutionOptions(JNIEnv*, jclass, jlong nativeView,
|
||||
jboolean enabled, jboolean homogeneousScaling,
|
||||
jfloat minScale, jfloat maxScale, jint quality) {
|
||||
jfloat minScale, jfloat maxScale, jfloat sharpness, jint quality) {
|
||||
View* view = (View*)nativeView;
|
||||
View::DynamicResolutionOptions options;
|
||||
options.enabled = enabled;
|
||||
options.homogeneousScaling = homogeneousScaling;
|
||||
options.minScale = filament::math::float2{ minScale };
|
||||
options.maxScale = filament::math::float2{ maxScale };
|
||||
options.sharpness = sharpness;
|
||||
options.quality = (View::QualityLevel)quality;
|
||||
view->setDynamicResolutionOptions(options);
|
||||
}
|
||||
@@ -138,10 +149,15 @@ Java_com_google_android_filament_View_nSetShadowType(JNIEnv*, jclass, jlong nati
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetVsmShadowOptions(JNIEnv*, jclass, jlong nativeView,
|
||||
jint anisotropy) {
|
||||
jint anisotropy, jboolean mipmapping, jfloat exponent, jfloat minVarianceScale,
|
||||
jfloat lightBleedReduction) {
|
||||
View* view = (View*) nativeView;
|
||||
View::VsmShadowOptions options;
|
||||
options.anisotropy = (uint8_t) anisotropy;
|
||||
options.anisotropy = (uint8_t)anisotropy;
|
||||
options.mipmapping = (bool)mipmapping;
|
||||
options.exponent = exponent;
|
||||
options.minVarianceScale = minVarianceScale;
|
||||
options.lightBleedReduction = lightBleedReduction;
|
||||
view->setVsmShadowOptions(options);
|
||||
}
|
||||
|
||||
@@ -211,7 +227,9 @@ Java_com_google_android_filament_View_nGetAmbientOcclusion(JNIEnv*, jclass, jlon
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetAmbientOcclusionOptions(JNIEnv*, jclass,
|
||||
jlong nativeView, jfloat radius, jfloat bias, jfloat power, jfloat resolution, jfloat intensity,
|
||||
jint quality, jint lowPassFilter, jint upsampling, jboolean enabled, jfloat minHorizonAngleRad) {
|
||||
jfloat bilateralThreshold,
|
||||
jint quality, jint lowPassFilter, jint upsampling, jboolean enabled, jboolean bentNormals,
|
||||
jfloat minHorizonAngleRad) {
|
||||
View* view = (View*) nativeView;
|
||||
View::AmbientOcclusionOptions options = view->getAmbientOcclusionOptions();
|
||||
options.radius = radius;
|
||||
@@ -219,10 +237,12 @@ Java_com_google_android_filament_View_nSetAmbientOcclusionOptions(JNIEnv*, jclas
|
||||
options.bias = bias;
|
||||
options.resolution = resolution;
|
||||
options.intensity = intensity;
|
||||
options.bilateralThreshold = bilateralThreshold;
|
||||
options.quality = (View::QualityLevel)quality;
|
||||
options.lowPassFilter = (View::QualityLevel)lowPassFilter;
|
||||
options.upsampling = (View::QualityLevel)upsampling;
|
||||
options.enabled = (bool)enabled;
|
||||
options.bentNormals = (bool)bentNormals;
|
||||
options.minHorizonAngleRad = minHorizonAngleRad;
|
||||
view->setAmbientOcclusionOptions(options);
|
||||
}
|
||||
@@ -311,8 +331,8 @@ Java_com_google_android_filament_View_nSetBlendMode(JNIEnv *, jclass , jlong nat
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetDepthOfFieldOptions(JNIEnv *, jclass ,
|
||||
jlong nativeView, jfloat focusDistance, jfloat cocScale, jfloat maxApertureDiameter, jboolean enabled, jint filter,
|
||||
Java_com_google_android_filament_View_nSetDepthOfFieldOptions(JNIEnv *, jclass,
|
||||
jlong nativeView, jfloat cocScale, jfloat maxApertureDiameter, jboolean enabled, jint filter,
|
||||
jboolean nativeResolution, jint foregroundRingCount, jint backgroundRingCount, jint fastGatherRingCount,
|
||||
jint maxForegroundCOC, jint maxBackgroundCOC) {
|
||||
View* view = (View*) nativeView;
|
||||
@@ -341,6 +361,17 @@ Java_com_google_android_filament_View_nSetVignetteOptions(JNIEnv*, jclass, jlong
|
||||
.color = LinearColorA{r, g, b, a}, .enabled = (bool)enabled});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetMultiSampleAntiAliasingOptions(JNIEnv* env, jclass clazz,
|
||||
jlong nativeView, jboolean enabled, jint sampleCount, jboolean customResolve) {
|
||||
View* view = (View*) nativeView;
|
||||
view->setMultiSampleAntiAliasingOptions({
|
||||
.enabled = (bool)enabled,
|
||||
.sampleCount = (uint8_t)sampleCount,
|
||||
.customResolve = (bool)customResolve});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetTemporalAntiAliasingOptions(JNIEnv *, jclass,
|
||||
@@ -372,3 +403,42 @@ Java_com_google_android_filament_View_nIsScreenSpaceRefractionEnabled(JNIEnv *,
|
||||
View* view = (View*) nativeView;
|
||||
return (jboolean)view->isScreenSpaceRefractionEnabled();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nPick(JNIEnv* env, jclass,
|
||||
jlong nativeView,
|
||||
jint x, jint y, jobject handler, jobject internalCallback) {
|
||||
|
||||
// jniState will be initialized the first time this method is called
|
||||
static const struct JniState {
|
||||
jclass internalOnPickCallbackClass;
|
||||
jfieldID renderableFieldId;
|
||||
jfieldID depthFieldId;
|
||||
jfieldID fragCoordXFieldId;
|
||||
jfieldID fragCoordYFieldId;
|
||||
jfieldID fragCoordZFieldId;
|
||||
explicit JniState(JNIEnv* env) noexcept {
|
||||
internalOnPickCallbackClass = env->FindClass("com/google/android/filament/View$InternalOnPickCallback");
|
||||
renderableFieldId = env->GetFieldID(internalOnPickCallbackClass, "mRenderable", "I");
|
||||
depthFieldId = env->GetFieldID(internalOnPickCallbackClass, "mDepth", "F");
|
||||
fragCoordXFieldId = env->GetFieldID(internalOnPickCallbackClass, "mFragCoordsX", "F");
|
||||
fragCoordYFieldId = env->GetFieldID(internalOnPickCallbackClass, "mFragCoordsY", "F");
|
||||
fragCoordZFieldId = env->GetFieldID(internalOnPickCallbackClass, "mFragCoordsZ", "F");
|
||||
}
|
||||
} jniState(env);
|
||||
|
||||
View* view = (View*) nativeView;
|
||||
JniCallback *callback = JniCallback::make(env, handler, internalCallback);
|
||||
view->pick(x, y, [callback](View::PickingQueryResult const& result) {
|
||||
// this is executed on the backend/service thread
|
||||
jobject obj = callback->getCallbackObject();
|
||||
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
|
||||
env->SetIntField(obj, jniState.renderableFieldId, (jint)result.renderable.getId());
|
||||
env->SetFloatField(obj, jniState.depthFieldId, result.depth);
|
||||
env->SetFloatField(obj, jniState.fragCoordXFieldId, result.fragCoords.x);
|
||||
env->SetFloatField(obj, jniState.fragCoordYFieldId, result.fragCoords.y);
|
||||
env->SetFloatField(obj, jniState.fragCoordZFieldId, result.fragCoords.z);
|
||||
JniCallback::postToJavaAndDestroy(callback);
|
||||
}, callback->getHandler());
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <jawt.h>
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<darwin/jawt_md.h>)
|
||||
#include <darwin/jawt_md.h>
|
||||
#else
|
||||
#include <jawt_md.h>
|
||||
#endif
|
||||
#else
|
||||
#include <darwin/jawt_md.h>
|
||||
#endif
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include "JAWTUtils.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "NotReleasedValue"
|
||||
extern "C" {
|
||||
void *getNativeWindow(JNIEnv *env, jclass klass, jobject surface) {
|
||||
void *win = nullptr;
|
||||
JAWT_DrawingSurface *ds = nullptr;
|
||||
JAWT_DrawingSurfaceInfo *dsi = nullptr;
|
||||
|
||||
if (!acquireDrawingSurface(env, surface, &ds, &dsi)) {
|
||||
return win;
|
||||
}
|
||||
NSObject<JAWT_SurfaceLayers>* jawldsip = (NSObject<JAWT_SurfaceLayers>*)dsi->platformInfo;
|
||||
// Use jawt_DrawingSurfaceInfo.bounds for frame dimension.
|
||||
NSView *view = [[NSView alloc] initWithFrame:
|
||||
NSMakeRect(dsi->bounds.x, dsi->bounds.y, dsi->bounds.width, dsi->bounds.height)];
|
||||
view.wantsLayer = true;
|
||||
[jawldsip setLayer:view.layer];
|
||||
|
||||
win = (void*) view;
|
||||
releaseDrawingSurface(ds, dsi);
|
||||
return win;
|
||||
}
|
||||
|
||||
jlong createNativeSurface(jint width, jint height) {
|
||||
NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, width, height)];
|
||||
view.wantsLayer = true;
|
||||
return (jlong) view;
|
||||
}
|
||||
|
||||
void destroyNativeSurface(jlong surface) {
|
||||
NSView *view = reinterpret_cast<NSView*>(surface);
|
||||
[view release];
|
||||
}
|
||||
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "JAWTUtils.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
static std::vector<int> jawtVersions = {
|
||||
0x00010003,
|
||||
0x00010004,
|
||||
0x00010007,
|
||||
0x00010009,
|
||||
};
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wuninitialized"
|
||||
bool acquireDrawingSurface(JNIEnv* env, jobject surface,
|
||||
JAWT_DrawingSurface** ods, JAWT_DrawingSurfaceInfo** odsi) {
|
||||
|
||||
JAWT awt;
|
||||
JAWT_DrawingSurface* ds = nullptr;
|
||||
JAWT_DrawingSurfaceInfo* dsi = nullptr;
|
||||
|
||||
// Search for a valid AWT
|
||||
jboolean foundJawt = JNI_FALSE;
|
||||
for (int jawtVersion : jawtVersions) {
|
||||
awt.version = jawtVersion;
|
||||
#if defined(__APPLE__) && defined(__aarch64__)
|
||||
// FIXME: enable Apple Silicon build. The problem here is that we attempt to link an x86 jdk and that fails
|
||||
// so JAWT_GetAWT doesn't exist at link time.
|
||||
#warning "FIXME: JAWT_GetAWT() not supported"
|
||||
foundJawt = {};
|
||||
#else
|
||||
foundJawt = JAWT_GetAWT(env, &awt);
|
||||
#endif
|
||||
if (foundJawt == JNI_TRUE) {
|
||||
#ifndef NDEBUG
|
||||
printf("Found valid AWT v%08x.\n", jawtVersion);
|
||||
#endif
|
||||
break;
|
||||
} else {
|
||||
#ifndef NDEBUG
|
||||
printf("AWT v%08x not present.\n", jawtVersion);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
if (foundJawt == JNI_FALSE) {
|
||||
printf("AWT Not found\n");
|
||||
fflush(stdout);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the drawing surface
|
||||
ds = awt.GetDrawingSurface(env, surface);
|
||||
if (ds == nullptr) {
|
||||
#ifndef NDEBUG
|
||||
printf("NULL drawing surface\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Lock the drawing
|
||||
jint lock = ds->Lock(ds);
|
||||
if ((lock & JAWT_LOCK_ERROR) != 0) {
|
||||
#ifndef NDEBUG
|
||||
printf("Error locking surface\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
awt.FreeDrawingSurface(ds);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the drawing surface info
|
||||
dsi = ds->GetDrawingSurfaceInfo(ds);
|
||||
if (dsi == nullptr) {
|
||||
#ifndef NDEBUG
|
||||
printf("Error getting surface info\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
ds->Unlock(ds);
|
||||
awt.FreeDrawingSurface(ds);
|
||||
return false;
|
||||
}
|
||||
|
||||
*odsi = dsi;
|
||||
*ods = ds;
|
||||
|
||||
return true;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
void releaseDrawingSurface(JAWT_DrawingSurface* ds, JAWT_DrawingSurfaceInfo* dsi) {
|
||||
// Free the drawing surface info
|
||||
ds->FreeDrawingSurfaceInfo(dsi);
|
||||
// Unlock the drawing surface
|
||||
ds->Unlock(ds);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jawt.h>
|
||||
|
||||
extern "C" {
|
||||
bool acquireDrawingSurface(JNIEnv* env, jobject surface, JAWT_DrawingSurface** ods,
|
||||
JAWT_DrawingSurfaceInfo** odsi);
|
||||
void releaseDrawingSurface(JAWT_DrawingSurface* ds, JAWT_DrawingSurfaceInfo* dsi);
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <jawt.h>
|
||||
#include <linux/jawt_md.h>
|
||||
|
||||
#include "JAWTUtils.h"
|
||||
#include<GL/glx.h>
|
||||
|
||||
extern "C" {
|
||||
void *getNativeWindow(JNIEnv* env, jclass, jobject surface) {
|
||||
void* win = nullptr;
|
||||
JAWT_DrawingSurface* ds = nullptr;
|
||||
JAWT_DrawingSurfaceInfo* dsi = nullptr;
|
||||
|
||||
if (!acquireDrawingSurface(env, surface, &ds, &dsi)) {
|
||||
return win;
|
||||
}
|
||||
JAWT_X11DrawingSurfaceInfo* dsi_x11 = (JAWT_X11DrawingSurfaceInfo*) dsi->platformInfo;
|
||||
|
||||
win = (void*) dsi_x11->drawable;
|
||||
releaseDrawingSurface(ds, dsi);
|
||||
return win;
|
||||
}
|
||||
|
||||
jlong createNativeSurface(jint width, jint height) {
|
||||
Display* display = XOpenDisplay(nullptr);
|
||||
int screen = DefaultScreen(display);
|
||||
Window window = 0;
|
||||
|
||||
#ifndef NDEBUG
|
||||
int major, minor;
|
||||
glXQueryVersion(display, &major, &minor);
|
||||
printf("Using GLX v%d.%d\n", major, minor); fflush(stdout);
|
||||
#endif
|
||||
|
||||
static int visualAttributess[] = {
|
||||
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||
GLX_DOUBLEBUFFER, True,
|
||||
GLX_RED_SIZE, 8,
|
||||
GLX_GREEN_SIZE, 8,
|
||||
GLX_BLUE_SIZE, 8,
|
||||
GLX_DEPTH_SIZE, 24,
|
||||
None
|
||||
};
|
||||
int numConfigs = 0;
|
||||
GLXFBConfig* configs = glXChooseFBConfig( display, screen, visualAttributess, &numConfigs);
|
||||
if (numConfigs == 0) {
|
||||
printf("Unable to find a suitable Framebuffer Configuration.\n"); fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pbufferAttributes[] = {
|
||||
GLX_PBUFFER_WIDTH, width,
|
||||
GLX_PBUFFER_HEIGHT, height,
|
||||
None
|
||||
};
|
||||
window = glXCreatePbuffer( display, configs[0], pbufferAttributes );
|
||||
XFree(configs);
|
||||
// Make sure pbuffer creation has not been buffered in the event queue (we need it NOW).
|
||||
XFlush(display);
|
||||
|
||||
// Camouflage the pbuffer as a window which are both XID anyway.
|
||||
return (jlong) window;
|
||||
}
|
||||
|
||||
void destroyNativeSurface(jlong surface) {
|
||||
const char* displayName = nullptr;
|
||||
Display* display = XOpenDisplay(displayName);
|
||||
GLXPbuffer pBuffer = (GLXPbuffer)surface;
|
||||
glXDestroyPbuffer(display, pBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <jawt.h>
|
||||
#include <win32/jawt_md.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <utils/unwindows.h>
|
||||
|
||||
#include "JAWTUtils.h"
|
||||
#include <filament/Engine.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
void* getNativeWindow(JNIEnv* env, jclass, jobject surface) {
|
||||
JAWT_DrawingSurface* ds = nullptr;
|
||||
JAWT_DrawingSurfaceInfo* dsi = nullptr;
|
||||
|
||||
if (!acquireDrawingSurface(env, surface, &ds, &dsi)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JAWT_Win32DrawingSurfaceInfo* dsi_win32 = (JAWT_Win32DrawingSurfaceInfo*) dsi->platformInfo;
|
||||
HWND hWnd = dsi_win32->hwnd;
|
||||
|
||||
releaseDrawingSurface(ds, dsi);
|
||||
|
||||
return (void*) hWnd;
|
||||
}
|
||||
|
||||
|
||||
jlong createNativeSurface(jint width, jint height) {
|
||||
// We need to adjust the window size so the "client area" matches width and height requested.
|
||||
// Otherwise, the window itself will be of dimension width-height but the "client area" and the
|
||||
// resulting surface will be smaller than requested.
|
||||
RECT dimension = {0, 0, width, height};
|
||||
AdjustWindowRect(&dimension, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
width = dimension.right - dimension.left;
|
||||
height = dimension.bottom - dimension.top;
|
||||
|
||||
HWND window = CreateWindowA("STATIC", "dummy", 0, 0, 0, width, height, NULL, NULL, NULL, NULL);
|
||||
SetWindowLong(window, GWL_STYLE, 0); //remove all window styles
|
||||
|
||||
return (jlong) window;
|
||||
}
|
||||
|
||||
void destroyNativeSurface(jlong surface) {
|
||||
HWND window = (HWND) surface;
|
||||
DestroyWindow(window);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,12 +63,27 @@ final class Asserts {
|
||||
return out;
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 16)
|
||||
static double[] assertMat4(@Nullable double[] out) {
|
||||
if (out == null) out = new double[16];
|
||||
else if (out.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static void assertMat4fIn(@NonNull @Size(min = 16) float[] in) {
|
||||
if (in.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
}
|
||||
|
||||
static void assertMat4In(@NonNull @Size(min = 16) double[] in) {
|
||||
if (in.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 3)
|
||||
static float[] assertFloat3(@Nullable float[] out) {
|
||||
if (out == null) out = new float[3];
|
||||
|
||||
@@ -254,6 +254,9 @@ public class Camera {
|
||||
/**
|
||||
* Sets a custom projection matrix.
|
||||
*
|
||||
* <p>The projection matrix must define an NDC system that must match the OpenGL convention,
|
||||
* that is all 3 axis are mapped to [-1, 1].</p>
|
||||
*
|
||||
* @param inProjection custom projection matrix for rendering and culling
|
||||
*
|
||||
* @param near distance in world units from the camera to the near plane.
|
||||
@@ -279,6 +282,9 @@ public class Camera {
|
||||
/**
|
||||
* Sets a custom projection matrix.
|
||||
*
|
||||
* <p>The projection matrices must define an NDC system that must match the OpenGL convention,
|
||||
* that is all 3 axis are mapped to [-1, 1].</p>
|
||||
*
|
||||
* @param inProjection custom projection matrix for rendering.
|
||||
*
|
||||
* @param inProjectionForCulling custom projection matrix for culling.
|
||||
@@ -413,6 +419,20 @@ public class Camera {
|
||||
nSetModelMatrix(getNativeObject(), viewMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the camera's view matrix.
|
||||
* <p>
|
||||
* Helper method to set the camera's entity transform component.
|
||||
* Remember that the Camera "looks" towards its -z axis.
|
||||
* <p>
|
||||
*
|
||||
* @param viewMatrix The camera position and orientation provided as a <b>rigid transform</b> matrix.
|
||||
*/
|
||||
public void setModelMatrix(@NonNull @Size(min = 16) double[] viewMatrix) {
|
||||
Asserts.assertMat4In(viewMatrix);
|
||||
nSetModelMatrixFp64(getNativeObject(), viewMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the camera's view matrix.
|
||||
*
|
||||
@@ -510,6 +530,22 @@ public class Camera {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the camera's model matrix. The model matrix encodes the camera position and
|
||||
* orientation, or pose.
|
||||
*
|
||||
* @param out A 16-double array where the model matrix will be stored, or null in which
|
||||
* case a new array is allocated.
|
||||
*
|
||||
* @return A 16-double array containing the camera's pose as a column-major matrix.
|
||||
*/
|
||||
@NonNull @Size(min = 16)
|
||||
public double[] getModelMatrix(@Nullable @Size(min = 16) double[] out) {
|
||||
out = Asserts.assertMat4(out);
|
||||
nGetModelMatrixFp64(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the camera's view matrix. The view matrix is the inverse of the model matrix.
|
||||
*
|
||||
@@ -525,6 +561,21 @@ public class Camera {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the camera's view matrix. The view matrix is the inverse of the model matrix.
|
||||
*
|
||||
* @param out A 16-double array where the model view will be stored, or null in which
|
||||
* case a new array is allocated.
|
||||
*
|
||||
* @return A 16-double array containing the camera's view as a column-major matrix.
|
||||
*/
|
||||
@NonNull @Size(min = 16)
|
||||
public double[] getViewMatrix(@Nullable @Size(min = 16) double[] out) {
|
||||
out = Asserts.assertMat4(out);
|
||||
nGetViewMatrixFp64(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the camera position in world space.
|
||||
*
|
||||
@@ -734,6 +785,7 @@ public class Camera {
|
||||
private static native void nSetScaling(long nativeCamera, double x, double y);
|
||||
private static native void nSetShift(long nativeCamera, double x, double y);
|
||||
private static native void nSetModelMatrix(long nativeCamera, float[] in);
|
||||
private static native void nSetModelMatrixFp64(long nativeCamera, double[] in);
|
||||
private static native void nLookAt(long nativeCamera, double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ);
|
||||
private static native float nGetNear(long nativeCamera);
|
||||
private static native float nGetCullingFar(long nativeCamera);
|
||||
@@ -741,7 +793,9 @@ public class Camera {
|
||||
private static native void nGetCullingProjectionMatrix(long nativeCamera, double[] out);
|
||||
private static native void nGetScaling(long nativeCamera, double[] out);
|
||||
private static native void nGetModelMatrix(long nativeCamera, float[] out);
|
||||
private static native void nGetModelMatrixFp64(long nativeCamera, double[] out);
|
||||
private static native void nGetViewMatrix(long nativeCamera, float[] out);
|
||||
private static native void nGetViewMatrixFp64(long nativeCamera, double[] out);
|
||||
private static native void nGetPosition(long nativeCamera, float[] out);
|
||||
private static native void nGetLeftVector(long nativeCamera, float[] out);
|
||||
private static native void nGetUpVector(long nativeCamera, float[] out);
|
||||
|
||||
@@ -54,6 +54,8 @@ import static com.google.android.filament.Asserts.assertFloat4In;
|
||||
*
|
||||
* The various transforms held by ColorGrading are applied in the following order:
|
||||
* <ul>
|
||||
* <li>Exposure</li>
|
||||
* <li>Night adaptation</li>
|
||||
* <li>White balance</li>
|
||||
* <li>Channel mixer</li>
|
||||
* <li>Shadows/mid-tones/highlights</li>
|
||||
@@ -63,12 +65,16 @@ import static com.google.android.filament.Asserts.assertFloat4In;
|
||||
* <li>Saturation</li>
|
||||
* <li>Curves</li>
|
||||
* <li>Tone mapping</li>
|
||||
* <li>Luminance scaling</li>
|
||||
* <li>Gamut mapping</li>
|
||||
* </ul>
|
||||
*
|
||||
* <h1>Defaults</h1>
|
||||
*
|
||||
* Here are the default color grading options:
|
||||
* <ul>
|
||||
* <li>Exposure: 0.0</li>
|
||||
* <li>Night adaptation: 0.0</li>
|
||||
* <li>White balance: temperature <code>0.0</code>, and tint <code>0.0</code></li>
|
||||
* <li>Channel mixer: red <code>{1,0,0}</code>, green <code>{0,1,0}</code>, blue <code>{0,0,1}</code></li>
|
||||
* <li>Shadows/mid-tones/highlights: shadows <code>{1,1,1,0}</code>, mid-tones <code>{1,1,1,0}</code>,
|
||||
@@ -78,11 +84,13 @@ import static com.google.android.filament.Asserts.assertFloat4In;
|
||||
* <li>Vibrance: <code>1.0</code></li>
|
||||
* <li>Saturation: <code>1.0</code></li>
|
||||
* <li>Curves: gamma <code>{1,1,1}</code>, midPoint <code>{1,1,1}</code>, and scale <code>{1,1,1}</code></li>
|
||||
* <li>Tone mapping: {@link ToneMapping#ACES_LEGACY}</li>
|
||||
* <li>Tone mapping: {@link ToneMapper.ACESLegacy}</li>
|
||||
* <li>Luminance scaling: false</li>
|
||||
* <li>Gamut mapping: false</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see View
|
||||
* @see ToneMapping
|
||||
* @see ToneMapper
|
||||
*/
|
||||
public class ColorGrading {
|
||||
long mNativeObject;
|
||||
@@ -99,6 +107,8 @@ public class ColorGrading {
|
||||
|
||||
/**
|
||||
* List of available tone-mapping operators.
|
||||
*
|
||||
* @deprecated Use {@link ColorGrading.Builder#toneMapper(ToneMapper)}
|
||||
*/
|
||||
public enum ToneMapping {
|
||||
/** Linear tone mapping (i.e. no tone mapping). */
|
||||
@@ -109,10 +119,6 @@ public class ColorGrading {
|
||||
ACES,
|
||||
/** Filmic tone mapping, modelled after ACES but applied in sRGB space. */
|
||||
FILMIC,
|
||||
/** Exposure value invariant luminance scaling tone mapping, offers the best behaviors in high intensity areas. */
|
||||
EVILS,
|
||||
/** Reinhard luma-based tone mapping. */
|
||||
REINHARD,
|
||||
/** Tone mapping used to validate/debug scene exposure. */
|
||||
DISPLAY_RANGE,
|
||||
}
|
||||
@@ -156,6 +162,25 @@ public class ColorGrading {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the tone mapping operator to apply to the HDR color buffer as the last
|
||||
* operation of the color grading post-processing step.
|
||||
*
|
||||
* The default tone mapping operator is {@link ToneMapper.ACESLegacy}.
|
||||
*
|
||||
* The specified tone mapper must have a lifecycle that exceeds the lifetime of
|
||||
* this builder. Since the build(Engine&) method is synchronous, it is safe to
|
||||
* delete the tone mapper object after that finishes executing.
|
||||
*
|
||||
* @param toneMapper The tone mapping operator to apply to the HDR color buffer
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
public Builder toneMapper(ToneMapper toneMapper) {
|
||||
nBuilderToneMapper(mNativeBuilder, toneMapper.getNativeObject());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the tone mapping operator to apply to the HDR color buffer as the last
|
||||
* operation of the color grading post-processing step.
|
||||
@@ -165,12 +190,81 @@ public class ColorGrading {
|
||||
* @param toneMapping The tone mapping operator to apply to the HDR color buffer
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*
|
||||
* @deprecated Use {@link #toneMapper(ToneMapper)}
|
||||
*/
|
||||
public Builder toneMapping(ToneMapping toneMapping) {
|
||||
nBuilderToneMapping(mNativeBuilder, toneMapping.ordinal());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the luminance scaling component (LICH) from the exposure value
|
||||
* invariant luminance system (EVILS). When this setting is enabled, pixels with high
|
||||
* chromatic values will roll-off to white to offer a more natural rendering. This step
|
||||
* also helps avoid undesirable hue skews caused by out of gamut colors clipped
|
||||
* to the destination color gamut.
|
||||
*
|
||||
* When luminance scaling is enabled, tone mapping is performed on the luminance of each
|
||||
* pixel instead of per-channel.
|
||||
*
|
||||
* @param luminanceScaling Enables or disables EVILS post-tone mapping
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
public Builder luminanceScaling(boolean luminanceScaling) {
|
||||
nBuilderLuminanceScaling(mNativeBuilder, luminanceScaling);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables gamut mapping to the destination color space's gamut. When gamut
|
||||
* mapping is turned off, out-of-gamut colors are clipped to the destination's gamut,
|
||||
* which may produce hue skews (blue skewing to purple, green to yellow, etc.). When
|
||||
* gamut mapping is enabled, out-of-gamut colors are brought back in gamut by trying to
|
||||
* preserve the perceived chroma and lightness of the original values.
|
||||
*
|
||||
* @param gamutMapping Enables or disables gamut mapping
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
public Builder gamutMapping(boolean gamutMapping) {
|
||||
nBuilderGamutMapping(mNativeBuilder, gamutMapping);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the exposure of this image. The exposure is specified in stops:
|
||||
* each stop brightens (positive values) or darkens (negative values) the image by
|
||||
* a factor of 2. This means that an exposure of 3 will brighten the image 8 times
|
||||
* more than an exposure of 0 (2^3 = 8 and 2^0 = 1). Contrary to the camera's exposure,
|
||||
* this setting is applied after all post-processing (bloom, etc.) are applied.
|
||||
*
|
||||
* @param exposure Value in EV stops. Can be negative, 0, or positive.
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
public Builder exposure(float exposure) {
|
||||
nBuilderExposure(mNativeBuilder, exposure);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls the amount of night adaptation to replicate a more natural representation of
|
||||
* low-light conditions as perceived by the human vision system. In low-light conditions,
|
||||
* peak luminance sensitivity of the eye shifts toward the blue end of the color spectrum:
|
||||
* darker tones appear brighter, reducing contrast, and colors are blue shifted (the darker
|
||||
* the more intense the effect).
|
||||
*
|
||||
* @param adaptation Amount of adaptation, between 0 (no adaptation) and 1 (full adaptation).
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
public Builder nightAdaptation(float adaptation) {
|
||||
nBuilderNightAdaptation(mNativeBuilder, adaptation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the while balance of the image. This can be used to remove color casts
|
||||
* and correct the appearance of the white point in the scene, or to alter the
|
||||
@@ -463,7 +557,12 @@ public class ColorGrading {
|
||||
private static native void nDestroyBuilder(long nativeBuilder);
|
||||
|
||||
private static native void nBuilderQuality(long nativeBuilder, int quality);
|
||||
private static native void nBuilderToneMapping(long nativeBuilder, int toneMapper);
|
||||
private static native void nBuilderToneMapper(long nativeBuilder, long toneMapper);
|
||||
private static native void nBuilderToneMapping(long nativeBuilder, int toneMapping);
|
||||
private static native void nBuilderLuminanceScaling(long nativeBuilder, boolean luminanceScaling);
|
||||
private static native void nBuilderGamutMapping(long nativeBuilder, boolean gamutMapping);
|
||||
private static native void nBuilderExposure(long nativeBuilder, float exposure);
|
||||
private static native void nBuilderNightAdaptation(long nativeBuilder, float adaptation);
|
||||
private static native void nBuilderWhiteBalance(long nativeBuilder, float temperature, float tint);
|
||||
private static native void nBuilderChannelMixer(long nativeBuilder, float[] outRed, float[] outGreen, float[] outBlue);
|
||||
private static native void nBuilderShadowsMidtonesHighlights(long nativeBuilder, float[] shadows, float[] midtones, float[] highlights, float[] ranges);
|
||||
|
||||
@@ -631,7 +631,7 @@ public class Engine {
|
||||
|
||||
/**
|
||||
* Kicks the hardware thread (e.g.: the OpenGL, Vulkan or Metal thread) and blocks until
|
||||
* all commands to this point are executed. Note that this doesn't guarantee that the
|
||||
* all commands to this point are executed. Note that this does guarantee that the
|
||||
* hardware is actually finished.
|
||||
*
|
||||
* <p>This is typically used right after destroying the <code>SwapChain</code>,
|
||||
|
||||
@@ -188,7 +188,7 @@ public class LightManager {
|
||||
* Control the quality / performance of the shadow map associated to this light
|
||||
*/
|
||||
public static class ShadowOptions {
|
||||
/** Size of the shadow map in texels. Must be a power-of-two. */
|
||||
/** Size of the shadow map in texels. Must be a power-of-two and larger or equal to 8. */
|
||||
public int mapSize = 1024;
|
||||
|
||||
/**
|
||||
@@ -242,15 +242,17 @@ public class LightManager {
|
||||
|
||||
/** Constant bias in world units (e.g. meters) by which shadows are moved away from the
|
||||
* light. 1mm by default.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
public float constantBias = 0.05f;
|
||||
public float constantBias = 0.001f;
|
||||
|
||||
/** Amount by which the maximum sampling error is scaled. The resulting value is used
|
||||
* to move the shadow away from the fragment normal. Should be 1.0.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
public float normalBias = 0.4f;
|
||||
public float normalBias = 1.0f;
|
||||
|
||||
/** Distance from the camera after which shadows are clipped. this is used to clip
|
||||
/** Distance from the camera after which shadows are clipped. This is used to clip
|
||||
* shadows that are too far and wouldn't contribute to the scene much, improving
|
||||
* performance and quality. This value is always positive.
|
||||
* Use 0.0f to use the camera far distance.
|
||||
@@ -277,7 +279,24 @@ public class LightManager {
|
||||
* When set to true, all resolution enhancing features that can affect stability are
|
||||
* disabling, resulting in significantly lower resolution shadows, albeit stable ones.
|
||||
*/
|
||||
public boolean stable = true;
|
||||
public boolean stable = false;
|
||||
|
||||
/**
|
||||
* Constant bias in depth-resolution units by which shadows are moved away from the
|
||||
* light. The default value of 0.5 is used to round depth values up.
|
||||
* Generally this value shouldn't be changed or at least be small and positive.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
float polygonOffsetConstant = 0.5f;
|
||||
|
||||
/**
|
||||
* Bias based on the change in depth in depth-resolution units by which shadows are moved
|
||||
* away from the light. The default value of 2.0 works well with SHADOW_SAMPLING_PCF_LOW.
|
||||
* Generally this value is between 0.5 and the size in texel of the PCF filter.
|
||||
* Setting this value correctly is essential for LISPSM shadow-maps.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
float polygonOffsetSlope = 2.0f;
|
||||
|
||||
/**
|
||||
* Whether screen-space contact shadows are used. This applies regardless of whether a
|
||||
@@ -324,6 +343,12 @@ public class LightManager {
|
||||
*/
|
||||
@IntRange(from = 1)
|
||||
public int vsmMsaaSamples = 1;
|
||||
|
||||
/**
|
||||
* Blur width for the VSM blur. Zero do disable.
|
||||
* The maximum value is 125.
|
||||
*/
|
||||
public float blurWidth = 0.0f;
|
||||
}
|
||||
|
||||
public static class ShadowCascades {
|
||||
@@ -422,6 +447,18 @@ public class LightManager {
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables a light channel. Light channel 0 is enabled by default.
|
||||
*
|
||||
* @param channel Light channel to enable or disable, between 0 and 7.
|
||||
* @param enable Whether to enable or disable the light channel.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder lightChannel(@IntRange(from = 0, to = 7) int channel, boolean enable) {
|
||||
nBuilderLightChannel(mNativeBuilder, channel, enable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this Light casts shadows (disabled by default)
|
||||
*
|
||||
@@ -451,8 +488,11 @@ public class LightManager {
|
||||
nBuilderShadowOptions(mNativeBuilder,
|
||||
options.mapSize, options.shadowCascades, options.cascadeSplitPositions,
|
||||
options.constantBias, options.normalBias, options.shadowFar, options.shadowNearHint,
|
||||
options.shadowFarHint, options.stable, options.screenSpaceContactShadows,
|
||||
options.stepCount, options.maxShadowDistance, options.vsmMsaaSamples);
|
||||
options.shadowFarHint, options.stable,
|
||||
options.polygonOffsetConstant, options.polygonOffsetSlope,
|
||||
options.screenSpaceContactShadows,
|
||||
options.stepCount, options.maxShadowDistance, options.vsmMsaaSamples,
|
||||
options.blurWidth);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -776,6 +816,30 @@ public class LightManager {
|
||||
return type == Type.SPOT || type == Type.FOCUSED_SPOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables a light channel.
|
||||
* Light channel 0 is enabled by default.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param channel Light channel to set
|
||||
* @param enable true to enable, false to disable
|
||||
*
|
||||
* @see Builder#lightChannel
|
||||
*/
|
||||
public void setLightChannel(@EntityInstance int i, @IntRange(from = 0, to = 7) int channel, boolean enable) {
|
||||
nSetLightChannel(mNativeObject, i, channel, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a light channel is enabled on a specified renderable.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param channel Light channel to query
|
||||
* @return true if the light channel is enabled, false otherwise
|
||||
*/
|
||||
public boolean getLightChannel(@EntityInstance int i, @IntRange(from = 0, to = 7) int channel) {
|
||||
return nGetLightChannel(mNativeObject, i, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically updates the light's position.
|
||||
*
|
||||
@@ -1086,7 +1150,7 @@ public class LightManager {
|
||||
private static native void nDestroyBuilder(long nativeBuilder);
|
||||
private static native boolean nBuilderBuild(long nativeBuilder, long nativeEngine, int entity);
|
||||
private static native void nBuilderCastShadows(long nativeBuilder, boolean enable);
|
||||
private static native void nBuilderShadowOptions(long nativeBuilder, int mapSize, int cascades, float[] splitPositions, float constantBias, float normalBias, float shadowFar, float shadowNearHint, float shadowFarhint, boolean stable, boolean screenSpaceContactShadows, int stepCount, float maxShadowDistance, int vsmMsaaSamples);
|
||||
private static native void nBuilderShadowOptions(long nativeBuilder, int mapSize, int cascades, float[] splitPositions, float constantBias, float normalBias, float shadowFar, float shadowNearHint, float shadowFarhint, boolean stable, float polygonOffsetConstant, float polygonOffsetSlope, boolean screenSpaceContactShadows, int stepCount, float maxShadowDistance, int vsmMsaaSamples, float blurWidth);
|
||||
private static native void nBuilderCastLight(long nativeBuilder, boolean enabled);
|
||||
private static native void nBuilderPosition(long nativeBuilder, float x, float y, float z);
|
||||
private static native void nBuilderDirection(long nativeBuilder, float x, float y, float z);
|
||||
@@ -1099,6 +1163,7 @@ public class LightManager {
|
||||
private static native void nBuilderAngularRadius(long nativeBuilder, float angularRadius);
|
||||
private static native void nBuilderHaloSize(long nativeBuilder, float haloSize);
|
||||
private static native void nBuilderHaloFalloff(long nativeBuilder, float haloFalloff);
|
||||
private static native void nBuilderLightChannel(long nativeBuilder, int channel, boolean enable);
|
||||
|
||||
private static native void nComputeUniformSplits(float[] splitPositions, int cascades);
|
||||
private static native void nComputeLogSplits(float[] splitPositions, int cascades, float near, float far);
|
||||
@@ -1128,4 +1193,6 @@ public class LightManager {
|
||||
private static native boolean nIsShadowCaster(long nativeLightManager, int i);
|
||||
private static native float nGetOuterConeAngle(long nativeLightManager, int i);
|
||||
private static native float nGetInnerConeAngle(long nativeLightManager, int i);
|
||||
private static native void nSetLightChannel(long nativeLightManager, int i, int channel, boolean enable);
|
||||
private static native boolean nGetLightChannel(long nativeLightManager, int i, int channel);
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ public class Material {
|
||||
}
|
||||
}
|
||||
|
||||
Material(long nativeMaterial) {
|
||||
public Material(long nativeMaterial) {
|
||||
mNativeObject = nativeMaterial;
|
||||
long nativeDefaultInstance = nGetDefaultInstance(nativeMaterial);
|
||||
mDefaultInstance = new MaterialInstance(this, nativeDefaultInstance);
|
||||
|
||||
@@ -56,6 +56,7 @@ public class MaterialInstance {
|
||||
|
||||
MaterialInstance(@NonNull Material material, long nativeMaterialInstance) {
|
||||
mMaterial = material;
|
||||
mNativeMaterial = material.getNativeObject();
|
||||
mNativeObject = nativeMaterialInstance;
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ public class MaterialInstance {
|
||||
public static MaterialInstance duplicate(@NonNull MaterialInstance other, String name) {
|
||||
long nativeInstance = nDuplicate(other.mNativeObject, name);
|
||||
if (nativeInstance == 0) throw new IllegalStateException("Couldn't duplicate MaterialInstance");
|
||||
return new MaterialInstance(other.mMaterial, nativeInstance);
|
||||
return new MaterialInstance(other.getMaterial(), nativeInstance);
|
||||
}
|
||||
|
||||
/** @return the {@link Material} associated with this instance */
|
||||
|
||||
@@ -32,7 +32,7 @@ import androidx.annotation.Nullable;
|
||||
*/
|
||||
public class RenderTarget {
|
||||
private long mNativeObject;
|
||||
private static final int ATTACHMENT_COUNT = 5;
|
||||
private static final int ATTACHMENT_COUNT = AttachmentPoint.values().length;
|
||||
private final Texture[] mTextures = new Texture[ATTACHMENT_COUNT];
|
||||
|
||||
private RenderTarget(long nativeRenderTarget, Builder builder) {
|
||||
@@ -55,6 +55,10 @@ public class RenderTarget {
|
||||
COLOR1,
|
||||
COLOR2,
|
||||
COLOR3,
|
||||
COLOR4,
|
||||
COLOR5,
|
||||
COLOR6,
|
||||
COLOR7,
|
||||
DEPTH
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class RenderableManager {
|
||||
* @param count the number of primitives that will be supplied to the builder
|
||||
*
|
||||
* Note that builders typically do not have a long lifetime since clients should discard
|
||||
* them after calling build(). For a usage example, see {@link RenderableManager}.
|
||||
* them after calling {@link #build}. For a usage example, see {@link RenderableManager}.
|
||||
*/
|
||||
public Builder(@IntRange(from = 1) int count) {
|
||||
mNativeBuilder = nCreateBuilder(count);
|
||||
@@ -128,7 +128,7 @@ public class RenderableManager {
|
||||
* <code>geometry()</code> and <code>material()</code>.
|
||||
*
|
||||
* @param index zero-based index of the primitive, must be less than the count passed to Builder constructor
|
||||
* @param type specifies the topology of the primitive (e.g., PrimitiveType.TRIANGLES)
|
||||
* @param type specifies the topology of the primitive (e.g., {@link PrimitiveType#TRIANGLES})
|
||||
* @param vertices specifies the vertex buffer, which in turn specifies a set of attributes
|
||||
* @param indices specifies the index buffer (either u16 or u32)
|
||||
* @param offset specifies where in the index buffer to start reading (expressed as a number of indices)
|
||||
@@ -147,7 +147,7 @@ public class RenderableManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* For details, see the {@link RenderableManager.Builder#geometry primary overload}.
|
||||
* For details, see the {@link RenderableManager.Builder#geometry} primary overload.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder geometry(@IntRange(from = 0) int index, @NonNull PrimitiveType type,
|
||||
@@ -159,7 +159,7 @@ public class RenderableManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* For details, see the {@link RenderableManager.Builder#geometry primary overload}.
|
||||
* For details, see the {@link RenderableManager.Builder#geometry} primary overload.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder geometry(@IntRange(from = 0) int index, @NonNull PrimitiveType type,
|
||||
@@ -266,6 +266,18 @@ public class RenderableManager {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables a light channel. Light channel 0 is enabled by default.
|
||||
*
|
||||
* @param channel Light channel to enable or disable, between 0 and 7.
|
||||
* @param enable Whether to enable or disable the light channel.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder lightChannel(@IntRange(from = 0, to = 7) int channel, boolean enable) {
|
||||
nBuilderLightChannel(mNativeBuilder, channel, enable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls if this renderable casts shadows, false by default.
|
||||
*
|
||||
@@ -303,6 +315,50 @@ public class RenderableManager {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows bones to be swapped out and shared using SkinningBuffer.
|
||||
*
|
||||
* If skinning buffer mode is enabled, clients must call #setSkinningBuffer() rather than
|
||||
* #setBonesAsQuaternions(). This allows sharing of data between renderables.
|
||||
*
|
||||
* @param enabled If true, enables buffer object mode. False by default.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder enableSkinningBuffers(boolean enabled) {
|
||||
nEnableSkinningBuffers(mNativeBuilder, enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables GPU vertex skinning for up to 255 bones, 0 by default.
|
||||
*
|
||||
*<p>Skinning Buffer mode must be enabled.</p>
|
||||
*
|
||||
*<p>Each vertex can be affected by up to 4 bones simultaneously. The attached
|
||||
* VertexBuffer must provide data in the BONE_INDICES slot (uvec4) and the
|
||||
* BONE_WEIGHTS slot (float4).</p>
|
||||
*
|
||||
*<p>See also {@link #setSkinningBuffer}, {@link SkinningBuffer#setBonesAsMatrices}
|
||||
* or {@link SkinningBuffer#setBonesAsQuaternions},
|
||||
* which can be called on a per-frame basis to advance the animation.</p>
|
||||
*
|
||||
* @see #setSkinningBuffer
|
||||
* @see SkinningBuffer#setBonesAsMatrices
|
||||
* @see SkinningBuffer#setBonesAsQuaternions
|
||||
*
|
||||
* @param skinningBuffer null to disable, otherwise the {@link SkinningBuffer} to use
|
||||
* @param boneCount 0 to disable, otherwise the number of bone transforms (up to 255)
|
||||
* @param offset offset in the {@link SkinningBuffer}
|
||||
* @return this <code>Builder</code> object for chaining calls
|
||||
*/
|
||||
@NonNull
|
||||
public Builder skinning(SkinningBuffer skinningBuffer,
|
||||
@IntRange(from = 0, to = 255) int boneCount, int offset) {
|
||||
nBuilderSkinningBuffer(mNativeBuilder,
|
||||
skinningBuffer != null ? skinningBuffer.getNativeObject() : 0, boneCount, offset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder skinning(@IntRange(from = 0, to = 255) int boneCount) {
|
||||
nBuilderSkinning(mNativeBuilder, boneCount);
|
||||
@@ -312,6 +368,8 @@ public class RenderableManager {
|
||||
/**
|
||||
* Enables GPU vertex skinning for up to 255 bones, 0 by default.
|
||||
*
|
||||
* <p>Skinning Buffer mode must be disabled.</p>
|
||||
*
|
||||
* <p>Each vertex can be affected by up to 4 bones simultaneously. The attached
|
||||
* VertexBuffer must provide data in the <code>BONE_INDICES</code> slot (uvec4) and the
|
||||
* <code>BONE_WEIGHTS</code> slot (float4).</p>
|
||||
@@ -319,6 +377,8 @@ public class RenderableManager {
|
||||
* <p>See also {@link RenderableManager#setBonesAsMatrices}, which can be called on a per-frame basis
|
||||
* to advance the animation.</p>
|
||||
*
|
||||
* @see SkinningBuffer#setBonesAsMatrices
|
||||
*
|
||||
* @param boneCount Number of bones associated with this component
|
||||
* @param bones A FloatBuffer containing boneCount transforms. Each transform consists of 8 float.
|
||||
* float 0 to 3 encode a unit quaternion w+ix+jy+kz stored as x,y,z,w.
|
||||
@@ -379,9 +439,22 @@ public class RenderableManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Associates a {@link SkinningBuffer} to a renderable instance
|
||||
* @param i Instance of the Renderable
|
||||
* @param skinningBuffer {@link SkinningBuffer} to use
|
||||
* @param count Numbers of bones to set
|
||||
* @param offset Offset in the {@link SkinningBuffer}
|
||||
*/
|
||||
public void setSkinningBuffer(@EntityInstance int i, @NonNull SkinningBuffer skinningBuffer,
|
||||
int count, int offset) {
|
||||
nSetSkinningBuffer(mNativeObject, i, skinningBuffer.getNativeObject(), count, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the transforms associated with each bone of a Renderable.
|
||||
*
|
||||
*
|
||||
* @param i Instance of the Renderable
|
||||
* @param matrices A FloatBuffer containing boneCount 4x4 packed matrices (i.e. 16 floats each matrix and no gap between matrices)
|
||||
* @param boneCount Number of bones to set
|
||||
@@ -470,6 +543,30 @@ public class RenderableManager {
|
||||
nSetCulling(mNativeObject, i, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables a light channel.
|
||||
* Light channel 0 is enabled by default.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param channel Light channel to set
|
||||
* @param enable true to enable, false to disable
|
||||
*
|
||||
* @see Builder#lightChannel
|
||||
*/
|
||||
public void setLightChannel(@EntityInstance int i, @IntRange(from = 0, to = 7) int channel, boolean enable) {
|
||||
nSetLightChannel(mNativeObject, i, channel, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a light channel is enabled on a specified renderable.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param channel Light channel to query
|
||||
* @return true if the light channel is enabled, false otherwise
|
||||
*/
|
||||
public boolean getLightChannel(@EntityInstance int i, @IntRange(from = 0, to = 7) int channel) {
|
||||
return nGetLightChannel(mNativeObject, i, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes whether or not the renderable casts shadows.
|
||||
*
|
||||
@@ -654,8 +751,12 @@ public class RenderableManager {
|
||||
private static native void nBuilderScreenSpaceContactShadows(long nativeBuilder, boolean enabled);
|
||||
private static native void nBuilderSkinning(long nativeBuilder, int boneCount);
|
||||
private static native int nBuilderSkinningBones(long nativeBuilder, int boneCount, Buffer bones, int remaining);
|
||||
private static native void nBuilderSkinningBuffer(long nativeBuilder, long nativeSkinningBuffer, int boneCount, int offset);
|
||||
private static native void nBuilderMorphing(long nativeBuilder, boolean enabled);
|
||||
private static native void nEnableSkinningBuffers(long nativeBuilder, boolean enabled);
|
||||
private static native void nBuilderLightChannel(long nativeRenderableManager, int channel, boolean enable);
|
||||
|
||||
private static native void nSetSkinningBuffer(long nativeObject, int i, long nativeSkinningBuffer, int count, int offset);
|
||||
private static native int nSetBonesAsMatrices(long nativeObject, int i, Buffer matrices, int remaining, int boneCount, int offset);
|
||||
private static native int nSetBonesAsQuaternions(long nativeObject, int i, Buffer quaternions, int remaining, int boneCount, int offset);
|
||||
private static native void nSetMorphWeights(long nativeObject, int instance, float[] weights);
|
||||
@@ -663,6 +764,8 @@ public class RenderableManager {
|
||||
private static native void nSetLayerMask(long nativeRenderableManager, int i, int select, int value);
|
||||
private static native void nSetPriority(long nativeRenderableManager, int i, int priority);
|
||||
private static native void nSetCulling(long nativeRenderableManager, int i, boolean enabled);
|
||||
private static native void nSetLightChannel(long nativeRenderableManager, int i, int channel, boolean enable);
|
||||
private static native boolean nGetLightChannel(long nativeRenderableManager, int i, int channel);
|
||||
private static native void nSetCastShadows(long nativeRenderableManager, int i, boolean enabled);
|
||||
private static native void nSetReceiveShadows(long nativeRenderableManager, int i, boolean enabled);
|
||||
private static native void nSetScreenSpaceContactShadows(long nativeRenderableManager, int i, boolean enabled);
|
||||
@@ -672,7 +775,6 @@ public class RenderableManager {
|
||||
private static native int nGetPrimitiveCount(long nativeRenderableManager, int i);
|
||||
private static native void nSetMaterialInstanceAt(long nativeRenderableManager, int i, int primitiveIndex, long nativeMaterialInstance);
|
||||
private static native long nGetMaterialInstanceAt(long nativeRenderableManager, int i, int primitiveIndex);
|
||||
private static native long nGetMaterialAt(long nativeRenderableManager, int i, int primitiveIndex);
|
||||
private static native void nSetGeometryAt(long nativeRenderableManager, int i, int primitiveIndex, int primitiveType, long nativeVertexBuffer, long nativeIndexBuffer, int offset, int count);
|
||||
private static native void nSetGeometryAt(long nativeRenderableManager, int i, int primitiveIndex, int primitiveType, int offset, int count);
|
||||
private static native void nSetBlendOrderAt(long nativeRenderableManager, int i, int primitiveIndex, int blendOrder);
|
||||
|
||||
@@ -107,12 +107,12 @@ public class Renderer {
|
||||
/**
|
||||
* Rate at which the scale will change to reach the target frame rate.
|
||||
*/
|
||||
public float scaleRate = 0.125f;
|
||||
public float scaleRate = 1.0f / 15.0f;
|
||||
|
||||
/**
|
||||
* History size. higher values, tend to filter more (clamped to 30).
|
||||
* History size. higher values, tend to filter more (clamped to 31).
|
||||
*/
|
||||
public int history = 9;
|
||||
public int history = 15;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,8 +437,9 @@ public class Renderer {
|
||||
*</pre>
|
||||
*
|
||||
*
|
||||
* <p>Typically <code>readPixels</code> will be called after {@link #render} and before
|
||||
* {@link #endFrame}.</p>
|
||||
* <p><code>readPixels</code> must be called within a frame, meaning after {@link #beginFrame}
|
||||
* and before {@link #endFrame}. Typically, <code>readPixels</code> will be called after
|
||||
* {@link #render}.</p>
|
||||
* <br>
|
||||
* <p>After calling this method, the callback associated with <code>buffer</code>
|
||||
* will be invoked on the main thread, indicating that the read-back has completed.
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.filament;
|
||||
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class SkinningBuffer {
|
||||
private long mNativeObject;
|
||||
private SkinningBuffer(long nativeSkinningBuffer) {
|
||||
mNativeObject = nativeSkinningBuffer;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
|
||||
// Keep to finalize native resources
|
||||
private final SkinningBuffer.Builder.BuilderFinalizer mFinalizer;
|
||||
private final long mNativeBuilder;
|
||||
|
||||
public Builder() {
|
||||
mNativeBuilder = nCreateBuilder();
|
||||
mFinalizer = new SkinningBuffer.Builder.BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of the skinning buffer in bones.
|
||||
*
|
||||
* <p>Due to limitation in the GLSL, the SkinningBuffer must always by a multiple of
|
||||
* 256, this adjustment is done automatically, but can cause
|
||||
* some memory overhead. This memory overhead can be mitigated by using the same
|
||||
* {@link SkinningBuffer} to store the bone information for multiple RenderPrimitives.</p>
|
||||
*
|
||||
* @param boneCount Number of bones the skinning buffer can hold.
|
||||
* @return this <code>Builder</code> object for chaining calls
|
||||
*/
|
||||
@NonNull
|
||||
public Builder boneCount(@IntRange(from = 1) int boneCount) {
|
||||
nBuilderBoneCount(mNativeBuilder, boneCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The new buffer is created with identity bones
|
||||
*
|
||||
* @param initialize true to initializing the buffer, false to not.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder initialize(boolean initialize) {
|
||||
nBuilderInitialize(mNativeBuilder, initialize);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns the <code>SkinningBuffer</code> object.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this <code>SkinningBuffer</code>
|
||||
* with.
|
||||
*
|
||||
* @return the newly created <code>SkinningBuffer</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the SkinningBuffer could not be created
|
||||
*
|
||||
* @see #setBonesAsMatrices
|
||||
* @see #setBonesAsQuaternions
|
||||
*/
|
||||
@NonNull
|
||||
public SkinningBuffer build(@NonNull Engine engine) {
|
||||
long nativeSkinningBuffer = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
if (nativeSkinningBuffer == 0)
|
||||
throw new IllegalStateException("Couldn't create SkinningBuffer");
|
||||
return new SkinningBuffer(nativeSkinningBuffer);
|
||||
}
|
||||
|
||||
private static class BuilderFinalizer {
|
||||
private final long mNativeObject;
|
||||
|
||||
BuilderFinalizer(long nativeObject) {
|
||||
mNativeObject = nativeObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finalize() {
|
||||
try {
|
||||
super.finalize();
|
||||
} catch (Throwable t) { // Ignore
|
||||
} finally {
|
||||
nDestroyBuilder(mNativeObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the bone transforms in the range [offset, offset + boneCount).
|
||||
*
|
||||
* @param engine {@link Engine} instance
|
||||
* @param matrices A {@link FloatBuffer} containing boneCount 4x4 packed matrices (i.e. 16 floats each matrix and no gap between matrices)
|
||||
* @param boneCount Number of bones to set
|
||||
* @param offset Index of the first bone to set
|
||||
*/
|
||||
public void setBonesAsMatrices(@NonNull Engine engine,
|
||||
@NonNull Buffer matrices, @IntRange(from = 0, to = 255) int boneCount,
|
||||
@IntRange(from = 0) int offset) {
|
||||
int result = nSetBonesAsMatrices(mNativeObject, engine.getNativeObject(),
|
||||
matrices, matrices.remaining(), boneCount, offset);
|
||||
if (result < 0) {
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the bone transforms in the range [offset, offset + boneCount).
|
||||
*
|
||||
* @param engine {@link Engine} instance
|
||||
* @param quaternions A {@link FloatBuffer} containing boneCount transforms. Each transform consists of 8 float.
|
||||
* float 0 to 3 encode a unit quaternion <code>w+ix+jy+kz</code> stored as <code>x,y,z,w</code>.
|
||||
* float 4 to 7 encode a translation stored as <code>x,y,z,1</code>.
|
||||
* @param boneCount Number of bones to set
|
||||
* @param offset Index of the first bone to set
|
||||
*/
|
||||
public void setBonesAsQuaternions(@NonNull Engine engine,
|
||||
@NonNull Buffer quaternions, @IntRange(from = 0, to = 255) int boneCount,
|
||||
@IntRange(from = 0) int offset) {
|
||||
int result = nSetBonesAsQuaternions(mNativeObject, engine.getNativeObject(),
|
||||
quaternions, quaternions.remaining(), boneCount, offset);
|
||||
if (result < 0) {
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of bones in this {@link SkinningBuffer}
|
||||
*/
|
||||
public int getBoneCount() {
|
||||
return nGetBoneCount(mNativeObject);
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed IndexBuffer");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
void clearNativeObject() {
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
private static native long nCreateBuilder();
|
||||
private static native void nDestroyBuilder(long nativeBuilder);
|
||||
private static native void nBuilderBoneCount(long nativeBuilder, int boneCount);
|
||||
private static native void nBuilderInitialize(long nativeBuilder, boolean initialize);
|
||||
private static native long nBuilderBuild(long nativeBuilder, long nativeEngine);
|
||||
|
||||
private static native int nSetBonesAsMatrices(long nativeObject, long nativeEngine, Buffer matrices, int remaining, int boneCount, int offset);
|
||||
private static native int nSetBonesAsQuaternions(long nativeObject, long nativeEngine, Buffer quaternions, int remaining, int boneCount, int offset);
|
||||
private static native int nGetBoneCount(long nativeObject);
|
||||
}
|
||||
@@ -216,7 +216,38 @@ public class Texture {
|
||||
ETC2_EAC_RGBA8, ETC2_EAC_SRGBA8,
|
||||
|
||||
// Available everywhere except Android/iOS
|
||||
DXT1_RGB, DXT1_RGBA, DXT3_RGBA, DXT5_RGBA
|
||||
DXT1_RGB, DXT1_RGBA, DXT3_RGBA, DXT5_RGBA,
|
||||
DXT1_SRGB, DXT1_SRGBA, DXT3_SRGBA, DXT5_SRGBA,
|
||||
|
||||
// ASTC formats are available with a GLES extension
|
||||
RGBA_ASTC_4x4,
|
||||
RGBA_ASTC_5x4,
|
||||
RGBA_ASTC_5x5,
|
||||
RGBA_ASTC_6x5,
|
||||
RGBA_ASTC_6x6,
|
||||
RGBA_ASTC_8x5,
|
||||
RGBA_ASTC_8x6,
|
||||
RGBA_ASTC_8x8,
|
||||
RGBA_ASTC_10x5,
|
||||
RGBA_ASTC_10x6,
|
||||
RGBA_ASTC_10x8,
|
||||
RGBA_ASTC_10x10,
|
||||
RGBA_ASTC_12x10,
|
||||
RGBA_ASTC_12x12,
|
||||
SRGB8_ALPHA8_ASTC_4x4,
|
||||
SRGB8_ALPHA8_ASTC_5x4,
|
||||
SRGB8_ALPHA8_ASTC_5x5,
|
||||
SRGB8_ALPHA8_ASTC_6x5,
|
||||
SRGB8_ALPHA8_ASTC_6x6,
|
||||
SRGB8_ALPHA8_ASTC_8x5,
|
||||
SRGB8_ALPHA8_ASTC_8x6,
|
||||
SRGB8_ALPHA8_ASTC_8x8,
|
||||
SRGB8_ALPHA8_ASTC_10x5,
|
||||
SRGB8_ALPHA8_ASTC_10x6,
|
||||
SRGB8_ALPHA8_ASTC_10x8,
|
||||
SRGB8_ALPHA8_ASTC_10x10,
|
||||
SRGB8_ALPHA8_ASTC_12x10,
|
||||
SRGB8_ALPHA8_ASTC_12x12
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +262,38 @@ public class Texture {
|
||||
ETC2_EAC_RGBA8, ETC2_EAC_SRGBA8,
|
||||
|
||||
// Available everywhere except Android/iOS
|
||||
DXT1_RGB, DXT1_RGBA, DXT3_RGBA, DXT5_RGBA
|
||||
DXT1_RGB, DXT1_RGBA, DXT3_RGBA, DXT5_RGBA,
|
||||
DXT1_SRGB, DXT1_SRGBA, DXT3_SRGBA, DXT5_SRGBA,
|
||||
|
||||
// ASTC formats are available with a GLES extension
|
||||
RGBA_ASTC_4x4,
|
||||
RGBA_ASTC_5x4,
|
||||
RGBA_ASTC_5x5,
|
||||
RGBA_ASTC_6x5,
|
||||
RGBA_ASTC_6x6,
|
||||
RGBA_ASTC_8x5,
|
||||
RGBA_ASTC_8x6,
|
||||
RGBA_ASTC_8x8,
|
||||
RGBA_ASTC_10x5,
|
||||
RGBA_ASTC_10x6,
|
||||
RGBA_ASTC_10x8,
|
||||
RGBA_ASTC_10x10,
|
||||
RGBA_ASTC_12x10,
|
||||
RGBA_ASTC_12x12,
|
||||
SRGB8_ALPHA8_ASTC_4x4,
|
||||
SRGB8_ALPHA8_ASTC_5x4,
|
||||
SRGB8_ALPHA8_ASTC_5x5,
|
||||
SRGB8_ALPHA8_ASTC_6x5,
|
||||
SRGB8_ALPHA8_ASTC_6x6,
|
||||
SRGB8_ALPHA8_ASTC_8x5,
|
||||
SRGB8_ALPHA8_ASTC_8x6,
|
||||
SRGB8_ALPHA8_ASTC_8x8,
|
||||
SRGB8_ALPHA8_ASTC_10x5,
|
||||
SRGB8_ALPHA8_ASTC_10x6,
|
||||
SRGB8_ALPHA8_ASTC_10x8,
|
||||
SRGB8_ALPHA8_ASTC_10x10,
|
||||
SRGB8_ALPHA8_ASTC_12x10,
|
||||
SRGB8_ALPHA8_ASTC_12x12
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.google.android.filament;
|
||||
|
||||
/**
|
||||
* Interface for tone mapping operators. A tone mapping operator, or tone mapper,
|
||||
* is responsible for compressing the dynamic range of the rendered scene to a
|
||||
* dynamic range suitable for display.
|
||||
*
|
||||
* In Filament, tone mapping is a color grading step. ToneMapper instances are
|
||||
* created and passed to the ColorGrading::Builder to produce a 3D LUT that will
|
||||
* be used during post-processing to prepare the final color buffer for display.
|
||||
*
|
||||
* Filament provides several default tone mapping operators that fall into three
|
||||
* categories:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Configurable tone mapping operators</li>
|
||||
* <ul>
|
||||
* <li>GenericToneMapper</li>
|
||||
* </ul>
|
||||
* <li>Fixed-aesthetic tone mapping operators</li>
|
||||
* <ul>
|
||||
* <li>ACESToneMapper</li>
|
||||
* <li>ACESLegacyToneMapper</li>
|
||||
* <li>FilmicToneMapper</li>
|
||||
* </ul>
|
||||
* <li>Debug/validation tone mapping operators</li>
|
||||
* <ul>
|
||||
* <li>LinearToneMapper</li>
|
||||
* <li>DisplayRangeToneMapper</li>
|
||||
* </ul>
|
||||
* </ul>
|
||||
*
|
||||
* You can create custom tone mapping operators by subclassing ToneMapper.
|
||||
*/
|
||||
public class ToneMapper {
|
||||
private final long mNativeObject;
|
||||
|
||||
private ToneMapper(long nativeObject) {
|
||||
mNativeObject = nativeObject;
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed ToneMapper");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
super.finalize();
|
||||
} finally {
|
||||
nDestroyToneMapper(mNativeObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Linear tone mapping operator that returns the input color but clamped to
|
||||
* the 0..1 range. This operator is mostly useful for debugging.
|
||||
*/
|
||||
public static class Linear extends ToneMapper {
|
||||
public Linear() {
|
||||
super(nCreateLinearToneMapper());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ACES tone mapping operator. This operator is an implementation of the
|
||||
* ACES Reference Rendering Transform (RRT) combined with the Output Device
|
||||
* Transform (ODT) for sRGB monitors (dim surround, 100 nits).
|
||||
*/
|
||||
public static class ACES extends ToneMapper {
|
||||
public ACES() {
|
||||
super(nCreateACESToneMapper());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ACES tone mapping operator, modified to match the perceived brightness
|
||||
* of FilmicToneMapper. This operator is the same as ACESToneMapper but
|
||||
* applies a brightness multiplier of ~1.6 to the input color value to
|
||||
* target brighter viewing environments.
|
||||
*/
|
||||
public static class ACESLegacy extends ToneMapper {
|
||||
public ACESLegacy() {
|
||||
super(nCreateACESLegacyToneMapper());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "Filmic" tone mapping operator. This tone mapper was designed to
|
||||
* approximate the aesthetics of the ACES RRT + ODT for Rec.709
|
||||
* and historically Filament's default tone mapping operator. It exists
|
||||
* only for backward compatibility purposes and is not otherwise recommended.
|
||||
*/
|
||||
public static class Filmic extends ToneMapper {
|
||||
public Filmic() {
|
||||
super(nCreateFilmicToneMapper());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic tone mapping operator that gives control over the tone mapping
|
||||
* curve. This operator can be used to control the aesthetics of the final
|
||||
* image. This operator also allows to control the dynamic range of the
|
||||
* scene referred values.
|
||||
*
|
||||
* The tone mapping curve is defined by 5 parameters:
|
||||
* <ul>
|
||||
* <li>contrast: controls the contrast of the curve</li>
|
||||
* <li>shoulder: controls the shoulder of the curve, i.e. how quickly scene
|
||||
* referred values map to output white</li>
|
||||
* <li>midGrayIn: sets the input middle gray</li>
|
||||
* <li>midGrayOut: sets the output middle gray</li>
|
||||
* <li>hdrMax: defines the maximum input value that will be mapped to
|
||||
* output white</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static class Generic extends ToneMapper {
|
||||
/**
|
||||
* Builds a new generic tone mapper parameterized to closely approximate
|
||||
* the {@link ACESLegacy} tone mapper. The default values are:
|
||||
*
|
||||
* <ul>
|
||||
* <li>contrast = 1.585f</li>
|
||||
* <li>shoulder = 0.5f</li>
|
||||
* <li>midGrayIn = 0.18f</li>
|
||||
* <li>midGrayOut = 0.268f</li>
|
||||
* <li>hdrMax = 10.0f</li>
|
||||
* </ul>
|
||||
*/
|
||||
public Generic() {
|
||||
this(1.585f, 0.5f, 0.18f, 0.268f, 10.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a new generic tone mapper.
|
||||
*
|
||||
* @param contrast: controls the contrast of the curve, must be > 0.0, values
|
||||
* in the range 0.5..2.0 are recommended.
|
||||
* @param shoulder: controls the shoulder of the curve, i.e. how quickly scene
|
||||
* referred values map to output white, between 0.0 and 1.0.
|
||||
* @param midGrayIn: sets the input middle gray, between 0.0 and 1.0.
|
||||
* @param midGrayOut: sets the output middle gray, between 0.0 and 1.0.
|
||||
* @param hdrMax: defines the maximum input value that will be mapped to
|
||||
* output white. Must be >= 1.0.
|
||||
*/
|
||||
public Generic(
|
||||
float contrast, float shoulder, float midGrayIn, float midGrayOut, float hdrMax) {
|
||||
super(nCreateGenericToneMapper(contrast, shoulder, midGrayIn, midGrayOut, hdrMax));
|
||||
}
|
||||
|
||||
/** Returns the contrast of the curve as a strictly positive value. */
|
||||
public float getContrast() {
|
||||
return nGenericGetContrast(getNativeObject());
|
||||
}
|
||||
|
||||
/** Sets the contrast of the curve, must be > 0.0, values in the range 0.5..2.0 are recommended. */
|
||||
public void setContrast(float contrast) {
|
||||
nGenericSetContrast(getNativeObject(), contrast);
|
||||
}
|
||||
|
||||
/** Returns how fast scene referred values map to output white as a value between 0.0 and 1.0. */
|
||||
public float getShoulder() {
|
||||
return nGenericGetShoulder(getNativeObject());
|
||||
}
|
||||
|
||||
/** Sets how quickly scene referred values map to output white, between 0.0 and 1.0. */
|
||||
public void setShoulder(float shoulder) {
|
||||
nGenericSetShoulder(getNativeObject(), shoulder);
|
||||
}
|
||||
|
||||
/** Returns the middle gray point for input values as a value between 0.0 and 1.0. */
|
||||
public float getMidGrayIn() {
|
||||
return nGenericGetMidGrayIn(getNativeObject());
|
||||
}
|
||||
|
||||
/** Sets the input middle gray, between 0.0 and 1.0. */
|
||||
public void setMidGrayIn(float midGrayIn) {
|
||||
nGenericSetMidGrayIn(getNativeObject(), midGrayIn);
|
||||
}
|
||||
|
||||
/** Returns the middle gray point for output values as a value between 0.0 and 1.0. */
|
||||
public float getMidGrayOut() {
|
||||
return nGenericGetMidGrayOut(getNativeObject());
|
||||
}
|
||||
|
||||
/** Sets the output middle gray, between 0.0 and 1.0. */
|
||||
public void setMidGrayOut(float midGrayOut) {
|
||||
nGenericSetMidGrayOut(getNativeObject(), midGrayOut);
|
||||
}
|
||||
|
||||
/** Returns the maximum input value that will map to output white, as a value >= 1.0. */
|
||||
public float getHdrMax() {
|
||||
return nGenericGetHdrMax(getNativeObject());
|
||||
}
|
||||
|
||||
/** Defines the maximum input value that will be mapped to output white. Must be >= 1.0. */
|
||||
public void setHdrMax(float hdrMax) {
|
||||
nGenericSetHdrMax(getNativeObject(), hdrMax);
|
||||
}
|
||||
}
|
||||
|
||||
private static native void nDestroyToneMapper(long nativeObject);
|
||||
|
||||
private static native long nCreateLinearToneMapper();
|
||||
private static native long nCreateACESToneMapper();
|
||||
private static native long nCreateACESLegacyToneMapper();
|
||||
private static native long nCreateFilmicToneMapper();
|
||||
private static native long nCreateGenericToneMapper(
|
||||
float contrast, float shoulder, float midGrayIn, float midGrayOut, float hdrMax);
|
||||
|
||||
// Generic tone mappper
|
||||
private static native float nGenericGetContrast(long nativeObject);
|
||||
private static native float nGenericGetShoulder(long nativeObject);
|
||||
private static native float nGenericGetMidGrayIn(long nativeObject);
|
||||
private static native float nGenericGetMidGrayOut(long nativeObject);
|
||||
private static native float nGenericGetHdrMax(long nativeObject);
|
||||
|
||||
private static native void nGenericSetContrast(long nativeObject, float contrast);
|
||||
private static native void nGenericSetShoulder(long nativeObject, float shoulder);
|
||||
private static native void nGenericSetMidGrayIn(long nativeObject, float midGrayIn);
|
||||
private static native void nGenericSetMidGrayOut(long nativeObject, float midGrayOut);
|
||||
private static native void nGenericSetHdrMax(long nativeObject, float hdrMax);
|
||||
}
|
||||
@@ -83,6 +83,35 @@ import androidx.annotation.Size;
|
||||
return nGetInstance(mNativeObject, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disable the accurate translation mode. Disabled by default.
|
||||
*
|
||||
* When accurate translation mode is active, the translation component of all transforms is
|
||||
* maintained at double precision. This is only useful if the mat4 version of setTransform()
|
||||
* is used, as well as getTransformAccurate().
|
||||
*
|
||||
* @param enable true to enable the accurate translation mode, false to disable.
|
||||
*
|
||||
* @see #isAccurateTranslationsEnabled
|
||||
* @see #create(int, int, double[])
|
||||
* @see #setTransform(int, double[])
|
||||
* @see #getTransform(int, double[])
|
||||
* @see #getWorldTransform(int, double[])
|
||||
*/
|
||||
public void setAccurateTranslationsEnabled(boolean enable) {
|
||||
nSetAccurateTranslationsEnabled(mNativeObject, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the high precision translation mode is active.
|
||||
*
|
||||
* @return true if accurate translations mode is active, false otherwise
|
||||
* @see #setAccurateTranslationsEnabled
|
||||
*/
|
||||
public boolean isAccurateTranslationsEnabled() {
|
||||
return nIsAccurateTranslationsEnabled(mNativeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a transform component and associates it with the given entity. The component is
|
||||
* initialized with the identity transform.
|
||||
@@ -114,6 +143,23 @@ import androidx.annotation.Size;
|
||||
return nCreateArray(mNativeObject, entity, parent, localTransform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a transform component with a parent and associates it with the given entity.
|
||||
* If this component already exists on the given entity, it is first
|
||||
* destroyed as if {@link #destroy} was called.
|
||||
*
|
||||
* @param entity an {@link Entity} to associate a transform component to.
|
||||
* @param parent the {@link EntityInstance} of the parent transform
|
||||
* @param localTransform the transform, relative to the parent, to initialize the transform
|
||||
* component with.
|
||||
* @see #destroy
|
||||
*/
|
||||
@EntityInstance
|
||||
public int create(@Entity int entity, @EntityInstance int parent,
|
||||
@Nullable @Size(min = 16) double[] localTransform) {
|
||||
return nCreateArrayFp64(mNativeObject, entity, parent, localTransform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys this component from the given entity, children are orphaned.
|
||||
*
|
||||
@@ -170,6 +216,24 @@ import androidx.annotation.Size;
|
||||
nSetTransform(mNativeObject, i, localTransform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a local transform of a transform component.
|
||||
* <p>This operation can be slow if the hierarchy of transform is too deep, and this
|
||||
* will be particularly bad when updating a lot of transforms. In that case,
|
||||
* consider using {@link #openLocalTransformTransaction} / {@link #commitLocalTransformTransaction}.</p>
|
||||
*
|
||||
* @param i the {@link EntityInstance} of the transform component to set the local
|
||||
* transform to.
|
||||
* @param localTransform the local transform (i.e. relative to the parent).
|
||||
* @see #getTransform(int, double[])
|
||||
* @see #getWorldTransform(int, double[])
|
||||
*/
|
||||
public void setTransform(@EntityInstance int i,
|
||||
@NonNull @Size(min = 16) double[] localTransform) {
|
||||
Asserts.assertMat4In(localTransform);
|
||||
nSetTransformFp64(mNativeObject, i, localTransform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local transform of a transform component.
|
||||
*
|
||||
@@ -190,6 +254,26 @@ import androidx.annotation.Size;
|
||||
return outLocalTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local transform of a transform component.
|
||||
*
|
||||
* @param i the {@link EntityInstance} of the transform component to query the
|
||||
* local transform from.
|
||||
* @param outLocalTransform a 16 <code>float</code> array to receive the result.
|
||||
* If <code>null</code> is given, a new suitable array is allocated.
|
||||
* @return the local transform of the component (i.e. relative to the parent). This always
|
||||
* returns the value set by setTransform().
|
||||
* @see #setTransform
|
||||
*/
|
||||
@NonNull
|
||||
@Size(min = 16)
|
||||
public double[] getTransform(@EntityInstance int i,
|
||||
@Nullable @Size(min = 16) double[] outLocalTransform) {
|
||||
outLocalTransform = Asserts.assertMat4(outLocalTransform);
|
||||
nGetTransformFp64(mNativeObject, i, outLocalTransform);
|
||||
return outLocalTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the world transform of a transform component.
|
||||
*
|
||||
@@ -210,6 +294,26 @@ import androidx.annotation.Size;
|
||||
return outWorldTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the world transform of a transform component.
|
||||
*
|
||||
* @param i the {@link EntityInstance} of the transform component to query the
|
||||
* world transform from.
|
||||
* @param outWorldTransform a 16 <code>float</code> array to receive the result.
|
||||
* If <code>null</code> is given, a new suitable array is allocated
|
||||
* @return The world transform of the component (i.e. relative to the root). This is the
|
||||
* composition of this component's local transform with its parent's world transform.
|
||||
* @see #setTransform
|
||||
*/
|
||||
@NonNull
|
||||
@Size(min = 16)
|
||||
public double[] getWorldTransform(@EntityInstance int i,
|
||||
@Nullable @Size(min = 16) double[] outWorldTransform) {
|
||||
outWorldTransform = Asserts.assertMat4(outWorldTransform);
|
||||
nGetWorldTransformFp64(mNativeObject, i, outWorldTransform);
|
||||
return outWorldTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a local transform transaction. During a transaction, {@link #getWorldTransform} can
|
||||
* return an invalid transform until {@link #commitLocalTransformTransaction} is called.
|
||||
@@ -252,12 +356,18 @@ import androidx.annotation.Size;
|
||||
private static native int nGetInstance(long nativeTransformManager, int entity);
|
||||
private static native int nCreate(long nativeTransformManager, int entity);
|
||||
private static native int nCreateArray(long mNativeObject, int entity, int parent, float[] localTransform);
|
||||
private static native int nCreateArrayFp64(long mNativeObject, int entity, int parent, double[] localTransform);
|
||||
private static native void nDestroy(long nativeTransformManager, int entity);
|
||||
private static native void nSetParent(long nativeTransformManager, int i, int newParent);
|
||||
private static native int nGetParent(long nativeTransformManager, int i);
|
||||
private static native void nSetTransform(long nativeTransformManager, int i, float[] localTransform);
|
||||
private static native void nSetTransformFp64(long nativeTransformManager, int i, double[] localTransform);
|
||||
private static native void nGetTransform(long nativeTransformManager, int i, float[] outLocalTransform);
|
||||
private static native void nGetTransformFp64(long nativeTransformManager, int i, double[] outLocalTransform);
|
||||
private static native void nGetWorldTransform(long nativeTransformManager, int i, float[] outWorldTransform);
|
||||
private static native void nGetWorldTransformFp64(long nativeTransformManager, int i, double[] outWorldTransform);
|
||||
private static native void nOpenLocalTransformTransaction(long nativeTransformManager);
|
||||
private static native void nCommitLocalTransformTransaction(long nativeTransformManager);
|
||||
private static native void nSetAccurateTranslationsEnabled(long nativeTransformManager, boolean enable);
|
||||
private static native boolean nIsAccurateTranslationsEnabled(long nativeTransformManager);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ public class View {
|
||||
private VignetteOptions mVignetteOptions;
|
||||
private ColorGrading mColorGrading;
|
||||
private TemporalAntiAliasingOptions mTemporalAntiAliasingOptions;
|
||||
private MultiSampleAntiAliasingOptions mMultiSampleAntiAliasingOptions;
|
||||
private VsmShadowOptions mVsmShadowOptions;
|
||||
|
||||
/**
|
||||
@@ -131,8 +132,20 @@ public class View {
|
||||
public float maxScale = 1.0f;
|
||||
|
||||
/**
|
||||
* Upscaling quality. LOW: 1 bilinear tap, MEDIUM: 4 bilinear taps, HIGH: 9 bilinear taps.
|
||||
* If minScale needs to be very low, it might help to use MEDIUM or HIGH here.
|
||||
* Sharpness when QualityLevel.MEDIUM or higher is used [0, 1].
|
||||
* 0 is disabled, 1 is the sharpest setting.
|
||||
* The default is set to 0.9
|
||||
*/
|
||||
public float sharpness = 0.9f;
|
||||
|
||||
/**
|
||||
* Upscaling quality
|
||||
* LOW: bilinear filtered blit. Fastest, poor quality
|
||||
* MEDIUM: AMD FidelityFX FSR1 w/ mobile optimizations no RCAS sharpening pass
|
||||
* HIGH: AMD FidelityFX FSR1 w/ mobile optimizations + RCAS
|
||||
* ULTRA: AMD FidelityFX FSR1
|
||||
* FSR1 require a well anti-aliased (MSAA or TAA), noise free scene.
|
||||
*
|
||||
* The default upscaling quality is set to LOW.
|
||||
*/
|
||||
@NonNull
|
||||
@@ -169,6 +182,16 @@ public class View {
|
||||
*/
|
||||
public float intensity = 1.0f;
|
||||
|
||||
/**
|
||||
* Depth distance that constitute an edge for filtering. Must be positive.
|
||||
* Default is 5cm.
|
||||
* This must be adjusted with the scene's scale and/or units.
|
||||
* A value too low will result in high frequency noise, while a value too high will
|
||||
* result in the loss of geometry edges. For AO, it is generally better to be too
|
||||
* blurry than not enough.
|
||||
*/
|
||||
public float bilateralThreshold = 0.05f;
|
||||
|
||||
/**
|
||||
* The quality setting controls the number of samples used for evaluating Ambient
|
||||
* occlusion. The default is QualityLevel.LOW which is sufficient for most mobile
|
||||
@@ -198,6 +221,11 @@ public class View {
|
||||
*/
|
||||
public boolean enabled = false;
|
||||
|
||||
/**
|
||||
* enables bent normals computation from AO, and specular AO
|
||||
*/
|
||||
public boolean bentNormals = false;
|
||||
|
||||
/**
|
||||
* Minimal angle to consider in radian. This is used to reduce the creases that can
|
||||
* appear due to insufficiently tessellated geometry.
|
||||
@@ -264,6 +292,29 @@ public class View {
|
||||
public boolean ssctEnabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for Multi-sample Anti-aliasing (MSAA)
|
||||
* @see View#setMultiSampleAntiAliasingOptions
|
||||
*/
|
||||
public static class MultiSampleAntiAliasingOptions {
|
||||
/** enables or disables temporal anti-aliasing */
|
||||
public boolean enabled = false;
|
||||
|
||||
/**
|
||||
* number of samples to use for multi-sampled anti-aliasing.\n
|
||||
* 0: treated as 1
|
||||
* 1: no anti-aliasing
|
||||
* n: sample count. Effective sample could be different depending on the
|
||||
* GPU capabilities.
|
||||
*/
|
||||
public int sampleCount = 4;
|
||||
|
||||
/**
|
||||
* custom resolve improves quality for HDR scenes, but may impact performance.
|
||||
*/
|
||||
public boolean customResolve = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for Temporal Anti-aliasing (TAA)
|
||||
* @see View#setTemporalAntiAliasingOptions
|
||||
@@ -284,11 +335,11 @@ public class View {
|
||||
*
|
||||
* enabled: Enable or disable the bloom post-processing effect. Disabled by default.
|
||||
* levels: Number of successive blurs to achieve the blur effect, the minimum is 3 and the
|
||||
* maximum is 12. This value together with resolution influences the spread of the
|
||||
* maximum is 11. This value together with resolution influences the spread of the
|
||||
* blur effect. This value can be silently reduced to accommodate the original
|
||||
* image size.
|
||||
* resolution: Resolution of bloom's minor axis. The minimum value is 2^levels and the
|
||||
* the maximum is lower of the original resolution and 4096. This parameter is
|
||||
* resolution: Resolution of bloom's vertical axis. The minimum value is 2^levels and the
|
||||
* the maximum is lower of the original resolution and 2048. This parameter is
|
||||
* silently clamped to the minimum and maximum.
|
||||
* It is highly recommended that this value be smaller than the target resolution
|
||||
* after dynamic resolution is applied (horizontally and vertically).
|
||||
@@ -329,7 +380,7 @@ public class View {
|
||||
public float strength = 0.10f;
|
||||
|
||||
/**
|
||||
* Resolution of minor axis (2^levels to 4096)
|
||||
* Resolution of minor axis (2^levels to 2048)
|
||||
*/
|
||||
public int resolution = 360;
|
||||
|
||||
@@ -339,7 +390,7 @@ public class View {
|
||||
public float anamorphism = 1.0f;
|
||||
|
||||
/**
|
||||
* Number of blur levels (3 to 12)
|
||||
* Number of blur levels (3 to 11)
|
||||
*/
|
||||
public int levels = 6;
|
||||
|
||||
@@ -687,20 +738,44 @@ public class View {
|
||||
/**
|
||||
* View-level options for VSM shadowing.
|
||||
*
|
||||
* <strong>Warning: This API is still experimental and subject to change.</strong>
|
||||
*
|
||||
* @see View#setVsmShadowOptions
|
||||
*/
|
||||
public static class VsmShadowOptions {
|
||||
/**
|
||||
* Sets the number of anisotropic samples to use when sampling a VSM shadow map. If greater
|
||||
* than 0, mipmaps will automatically be generated each frame for all lights.
|
||||
* This implies mipmapping below.
|
||||
*
|
||||
* <p>
|
||||
* The number of anisotropic samples = 2 ^ vsmAnisotropy.
|
||||
* </p>
|
||||
*
|
||||
* <strong>Warning: This API is still experimental and subject to change.</strong>
|
||||
*/
|
||||
public int anisotropy = 0;
|
||||
|
||||
/**
|
||||
* Whether to generate mipmaps for all VSM shadow maps.
|
||||
*/
|
||||
public boolean mipmapping = false;
|
||||
|
||||
/**
|
||||
* EVSM exponent
|
||||
* The maximum value permissible is 5.54 for a shadow map in fp16, or 42.0 for a
|
||||
* shadow map in fp32. Currently the shadow map bit depth is always fp16.
|
||||
*/
|
||||
public float exponent = 5.54f;
|
||||
|
||||
/**
|
||||
* VSM minimum variance scale, must be positive.
|
||||
*/
|
||||
public float minVarianceScale = 1.0f;
|
||||
|
||||
/**
|
||||
* VSM light bleeding reduction amount, between 0 and 1.
|
||||
*/
|
||||
public float lightBleedReduction = 0.2f;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -996,7 +1071,10 @@ public class View {
|
||||
* </p>
|
||||
*
|
||||
* @param count number of samples to use for multi-sampled anti-aliasing.
|
||||
*
|
||||
* @deprecated use setMultiSampleAntiAliasingOptions instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSampleCount(int count) {
|
||||
nSetSampleCount(getNativeObject(), count);
|
||||
}
|
||||
@@ -1009,7 +1087,10 @@ public class View {
|
||||
* </p>
|
||||
*
|
||||
* @return value set by {@link #setSampleCount}
|
||||
*
|
||||
* @deprecated use getMultiSampleAntiAliasingOptions instead
|
||||
*/
|
||||
@Deprecated
|
||||
public int getSampleCount() {
|
||||
return nGetSampleCount(getNativeObject());
|
||||
}
|
||||
@@ -1038,6 +1119,30 @@ public class View {
|
||||
return AntiAliasing.values()[nGetAntiAliasing(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disable multi-sample anti-aliasing (MSAA). Disabled by default.
|
||||
*
|
||||
* @param options multi-sample anti-aliasing options
|
||||
*/
|
||||
public void setMultiSampleAntiAliasingOptions(@NonNull MultiSampleAntiAliasingOptions options) {
|
||||
mMultiSampleAntiAliasingOptions = options;
|
||||
nSetMultiSampleAntiAliasingOptions(getNativeObject(),
|
||||
options.enabled, options.sampleCount, options.customResolve);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns multi-sample anti-aliasing options.
|
||||
*
|
||||
* @return multi-sample anti-aliasing options
|
||||
*/
|
||||
@NonNull
|
||||
public MultiSampleAntiAliasingOptions getMultiSampleAntiAliasingOptions() {
|
||||
if (mMultiSampleAntiAliasingOptions == null) {
|
||||
mMultiSampleAntiAliasingOptions = new MultiSampleAntiAliasingOptions();
|
||||
}
|
||||
return mMultiSampleAntiAliasingOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disable temporal anti-aliasing (TAA). Disabled by default.
|
||||
*
|
||||
@@ -1149,6 +1254,7 @@ public class View {
|
||||
options.homogeneousScaling,
|
||||
options.minScale,
|
||||
options.maxScale,
|
||||
options.sharpness,
|
||||
options.quality.ordinal());
|
||||
}
|
||||
|
||||
@@ -1308,7 +1414,8 @@ public class View {
|
||||
*/
|
||||
public void setVsmShadowOptions(@NonNull VsmShadowOptions options) {
|
||||
mVsmShadowOptions = options;
|
||||
nSetVsmShadowOptions(getNativeObject(), options.anisotropy);
|
||||
nSetVsmShadowOptions(getNativeObject(), options.anisotropy, options.mipmapping,
|
||||
options.exponent, options.minVarianceScale, options.lightBleedReduction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1353,9 +1460,11 @@ public class View {
|
||||
public void setAmbientOcclusionOptions(@NonNull AmbientOcclusionOptions options) {
|
||||
mAmbientOcclusionOptions = options;
|
||||
nSetAmbientOcclusionOptions(getNativeObject(), options.radius, options.bias, options.power,
|
||||
options.resolution, options.intensity, options.quality.ordinal(), options.lowPassFilter.ordinal(), options.upsampling.ordinal(),
|
||||
options.enabled, options.minHorizonAngleRad);
|
||||
nSetSSCTOptions(getNativeObject(), options.ssctLightConeRad, options.ssctStartTraceDistance, options.ssctContactDistanceMax, options.ssctIntensity,
|
||||
options.resolution, options.intensity, options.bilateralThreshold,
|
||||
options.quality.ordinal(), options.lowPassFilter.ordinal(), options.upsampling.ordinal(),
|
||||
options.enabled, options.bentNormals, options.minHorizonAngleRad);
|
||||
nSetSSCTOptions(getNativeObject(), options.ssctLightConeRad, options.ssctStartTraceDistance,
|
||||
options.ssctContactDistanceMax, options.ssctIntensity,
|
||||
options.ssctLightDirection[0], options.ssctLightDirection[1], options.ssctLightDirection[2],
|
||||
options.ssctDepthBias, options.ssctDepthSlopeBias, options.ssctSampleCount,
|
||||
options.ssctRayCount, options.ssctEnabled);
|
||||
@@ -1493,6 +1602,71 @@ public class View {
|
||||
return mDepthOfFieldOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class containing the result of a picking query
|
||||
*/
|
||||
public static class PickingQueryResult {
|
||||
/** The entity of the renderable at the picking query location */
|
||||
@Entity public int renderable;
|
||||
/** The value of the depth buffer at the picking query location */
|
||||
public float depth;
|
||||
/** The fragment coordinate in GL convention at the picking query location */
|
||||
@NonNull public float[] fragCoords = new float[3];
|
||||
};
|
||||
|
||||
/**
|
||||
* An interface to implement a custom class to receive results of picking queries.
|
||||
*/
|
||||
public interface OnPickCallback {
|
||||
/**
|
||||
* onPick() is called by the specified Handler in {@link View#pick} when the picking query
|
||||
* result is available.
|
||||
* @param result An instance of {@link PickingQueryResult}.
|
||||
*/
|
||||
void onPick(@NonNull PickingQueryResult result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a picking query. Multiple queries can be created (e.g.: multi-touch).
|
||||
* Picking queries are all executed when {@link Renderer#render} is called on this View.
|
||||
* The provided callback is guaranteed to be called at some point in the future.
|
||||
*
|
||||
* Typically it takes a couple frames to receive the result of a picking query.
|
||||
*
|
||||
* @param x Horizontal coordinate to query in the viewport with origin on the left.
|
||||
* @param y Vertical coordinate to query on the viewport with origin at the bottom.
|
||||
* @param handler An {@link java.util.concurrent.Executor Executor}.
|
||||
* On Android this can also be a {@link android.os.Handler Handler}.
|
||||
* @param callback User callback executed by <code>handler</code> when the picking query
|
||||
* result is available.
|
||||
*/
|
||||
public void pick(int x, int y,
|
||||
@Nullable Object handler, @Nullable OnPickCallback callback) {
|
||||
InternalOnPickCallback internalCallback = new InternalOnPickCallback(callback);
|
||||
nPick(getNativeObject(), x, y, handler, internalCallback);
|
||||
}
|
||||
|
||||
private static class InternalOnPickCallback implements Runnable {
|
||||
public InternalOnPickCallback(OnPickCallback mUserCallback) {
|
||||
this.mUserCallback = mUserCallback;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
mPickingQueryResult.renderable = mRenderable;
|
||||
mPickingQueryResult.depth = mDepth;
|
||||
mPickingQueryResult.fragCoords[0] = mFragCoordsX;
|
||||
mPickingQueryResult.fragCoords[1] = mFragCoordsY;
|
||||
mPickingQueryResult.fragCoords[2] = mFragCoordsZ;
|
||||
mUserCallback.onPick(mPickingQueryResult);
|
||||
}
|
||||
private final OnPickCallback mUserCallback;
|
||||
private final PickingQueryResult mPickingQueryResult = new PickingQueryResult();
|
||||
@Entity int mRenderable;
|
||||
float mDepth;
|
||||
float mFragCoordsX;
|
||||
float mFragCoordsY;
|
||||
float mFragCoordsZ;
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
@@ -1518,11 +1692,11 @@ public class View {
|
||||
private static native int nGetAntiAliasing(long nativeView);
|
||||
private static native void nSetDithering(long nativeView, int dithering);
|
||||
private static native int nGetDithering(long nativeView);
|
||||
private static native void nSetDynamicResolutionOptions(long nativeView, boolean enabled, boolean homogeneousScaling, float minScale, float maxScale, int quality);
|
||||
private static native void nSetDynamicResolutionOptions(long nativeView, boolean enabled, boolean homogeneousScaling, float minScale, float maxScale, float sharpness, int quality);
|
||||
private static native void nSetRenderQuality(long nativeView, int hdrColorBufferQuality);
|
||||
private static native void nSetDynamicLightingOptions(long nativeView, float zLightNear, float zLightFar);
|
||||
private static native void nSetShadowType(long nativeView, int type);
|
||||
private static native void nSetVsmShadowOptions(long nativeView, int anisotropy);
|
||||
private static native void nSetVsmShadowOptions(long nativeView, int anisotropy, boolean mipmapping, float exponent, float minVarianceScale, float lightBleedReduction);
|
||||
private static native void nSetColorGrading(long nativeView, long nativeColorGrading);
|
||||
private static native void nSetPostProcessingEnabled(long nativeView, boolean enabled);
|
||||
private static native boolean nIsPostProcessingEnabled(long nativeView);
|
||||
@@ -1530,7 +1704,7 @@ public class View {
|
||||
private static native boolean nIsFrontFaceWindingInverted(long nativeView);
|
||||
private static native void nSetAmbientOcclusion(long nativeView, int ordinal);
|
||||
private static native int nGetAmbientOcclusion(long nativeView);
|
||||
private static native void nSetAmbientOcclusionOptions(long nativeView, float radius, float bias, float power, float resolution, float intensity, int quality, int lowPassFilter, int upsampling, boolean enabled, float minHorizonAngleRad);
|
||||
private static native void nSetAmbientOcclusionOptions(long nativeView, float radius, float bias, float power, float resolution, float intensity, float bilateralThreshold, int quality, int lowPassFilter, int upsampling, boolean enabled, boolean bentNormals, float minHorizonAngleRad);
|
||||
private static native void nSetSSCTOptions(long nativeView, float ssctLightConeRad, float ssctStartTraceDistance, float ssctContactDistanceMax, float ssctIntensity, float v, float v1, float v2, float ssctDepthBias, float ssctDepthSlopeBias, int ssctSampleCount, int ssctRayCount, boolean ssctEnabled);
|
||||
private static native void nSetBloomOptions(long nativeView, long dirtNativeObject, float dirtStrength, float strength, int resolution, float anamorphism, int levels, int blendMode, boolean threshold, boolean enabled, float highlight,
|
||||
boolean lensFlare, boolean starburst, float chromaticAberration, int ghostCount, float ghostSpacing, float ghostThreshold, float haloThickness, float haloRadius, float haloThreshold);
|
||||
@@ -1540,7 +1714,9 @@ public class View {
|
||||
boolean nativeResolution, int foregroundRingCount, int backgroundRingCount, int fastGatherRingCount, int maxForegroundCOC, int maxBackgroundCOC);
|
||||
private static native void nSetVignetteOptions(long nativeView, float midPoint, float roundness, float feather, float r, float g, float b, float a, boolean enabled);
|
||||
private static native void nSetTemporalAntiAliasingOptions(long nativeView, float feedback, float filterWidth, boolean enabled);
|
||||
private static native void nSetMultiSampleAntiAliasingOptions(long nativeView, boolean enabled, int sampleCount, boolean customResolve);
|
||||
private static native boolean nIsShadowingEnabled(long nativeView);
|
||||
private static native void nSetScreenSpaceRefractionEnabled(long nativeView, boolean enabled);
|
||||
private static native boolean nIsScreenSpaceRefractionEnabled(long nativeView);
|
||||
private static native void nPick(long nativeView, int x, int y, Object handler, InternalOnPickCallback internalCallback);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ target_compile_definitions(filament-utils-jni PUBLIC IMAGEIO_LITE=1)
|
||||
target_include_directories(filament-utils-jni PRIVATE
|
||||
${FILAMENT_DIR}/include
|
||||
..
|
||||
../../filament/backend/include
|
||||
${IMAGEIO_DIR}/include
|
||||
../../libs/utils/include)
|
||||
|
||||
|
||||
@@ -9,6 +9,13 @@ android {
|
||||
|
||||
lite {
|
||||
dimension "functionality"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
// hack: this is needed because filament-utils-android/CMakeLists.txt builds
|
||||
// gltfio from source, which needs this defined
|
||||
arguments.add("-DGLTFIO_LITE=ON")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,13 +50,14 @@ configurations.all { config ->
|
||||
dependencies {
|
||||
implementation deps.kotlin
|
||||
implementation deps.androidx.annotations
|
||||
implementation project(':filament-android')
|
||||
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
|
||||
|
||||
fullImplementation module("com.google.android.filament:gltfio-android:${VERSION_NAME}")
|
||||
liteImplementation module("com.google.android.filament:gltfio-android-lite:${VERSION_NAME}")
|
||||
api project(':filament-android')
|
||||
|
||||
fullApi module("com.google.android.filament:gltfio-android:${VERSION_NAME}")
|
||||
liteApi module("com.google.android.filament:gltfio-android-lite:${VERSION_NAME}")
|
||||
}
|
||||
|
||||
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
|
||||
|
||||
@@ -84,7 +84,13 @@ Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclas
|
||||
}
|
||||
}
|
||||
AutomationEngine* automation = (AutomationEngine*) nativeAutomation;
|
||||
automation->tick((View*) view, ptrMaterials, materialCount, (Renderer*) renderer, deltaTime);
|
||||
AutomationEngine::ViewerContent content = {
|
||||
.view = (View*) view,
|
||||
.renderer = (Renderer*) renderer,
|
||||
.materials = ptrMaterials,
|
||||
.materialCount = (size_t) materialCount,
|
||||
};
|
||||
automation->tick(content, deltaTime);
|
||||
if (longMaterials) {
|
||||
env->ReleaseLongArrayElements(materials, longMaterials, 0);
|
||||
delete[] ptrMaterials;
|
||||
@@ -94,8 +100,9 @@ Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclas
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_utils_AutomationEngine_nApplySettings(JNIEnv* env, jclass klass,
|
||||
jlong nativeAutomation, jstring json, jlong view, jlongArray materials, jlong nativeIbl,
|
||||
jint lightEntity, jlong nativeLm, jlong scene, jlong renderer) {
|
||||
jint sunlightEntity, jintArray assetLights, jlong nativeLm, jlong scene, jlong renderer) {
|
||||
using MaterialPointer = MaterialInstance*;
|
||||
|
||||
jsize materialCount = 0;
|
||||
jlong* longMaterials = nullptr;
|
||||
MaterialPointer* ptrMaterials = nullptr;
|
||||
@@ -107,17 +114,42 @@ Java_com_google_android_filament_utils_AutomationEngine_nApplySettings(JNIEnv* e
|
||||
ptrMaterials[i] = (MaterialPointer) longMaterials[i];
|
||||
}
|
||||
}
|
||||
|
||||
jsize lightCount = 0;
|
||||
jint* intLights = nullptr;
|
||||
if (assetLights) {
|
||||
lightCount = env->GetArrayLength(assetLights);
|
||||
intLights = env->GetIntArrayElements(assetLights, nullptr);
|
||||
}
|
||||
|
||||
static_assert(sizeof(jint) == sizeof(Entity));
|
||||
|
||||
AutomationEngine* automation = (AutomationEngine*) nativeAutomation;
|
||||
const char* nativeJson = env->GetStringUTFChars(json, 0);
|
||||
size_t jsonLength = env->GetStringUTFLength(json);
|
||||
automation->applySettings(nativeJson, jsonLength, (View*) view, ptrMaterials, materialCount,
|
||||
(IndirectLight*) nativeIbl, (Entity&) lightEntity, (LightManager*) nativeLm,
|
||||
(Scene*) scene, (Renderer*) renderer);
|
||||
|
||||
AutomationEngine::ViewerContent content = {
|
||||
.view = (View*) view,
|
||||
.renderer = (Renderer*) renderer,
|
||||
.materials = ptrMaterials,
|
||||
.materialCount = (size_t) materialCount,
|
||||
.lightManager = (LightManager*) nativeLm,
|
||||
.scene = (Scene*) scene,
|
||||
.indirectLight = (IndirectLight*) nativeIbl,
|
||||
.sunlight = (Entity&) sunlightEntity,
|
||||
.assetLights = (Entity*) intLights,
|
||||
.assetLightCount = (size_t) lightCount,
|
||||
};
|
||||
|
||||
automation->applySettings(nativeJson, jsonLength, content);
|
||||
env->ReleaseStringUTFChars(json, nativeJson);
|
||||
if (longMaterials) {
|
||||
env->ReleaseLongArrayElements(materials, longMaterials, 0);
|
||||
delete[] ptrMaterials;
|
||||
}
|
||||
if (intLights) {
|
||||
env->ReleaseIntArrayElements(assetLights, intLights, 0);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -136,6 +168,7 @@ Java_com_google_android_filament_utils_AutomationEngine_nGetViewerOptions(JNIEnv
|
||||
const jfieldID skyboxEnabled = env->GetFieldID(klass, "skyboxEnabled", "Z");
|
||||
const jfieldID cameraFocalLength = env->GetFieldID(klass, "cameraFocalLength", "F");
|
||||
const jfieldID cameraFocusDistance = env->GetFieldID(klass, "cameraFocusDistance", "F");
|
||||
const jfieldID autoScaleEnabled = env->GetFieldID(klass, "autoScaleEnabled", "Z");
|
||||
|
||||
env->SetFloatField(result, cameraAperture, options.cameraAperture);
|
||||
env->SetFloatField(result, cameraSpeed, options.cameraSpeed);
|
||||
@@ -145,6 +178,7 @@ Java_com_google_android_filament_utils_AutomationEngine_nGetViewerOptions(JNIEnv
|
||||
env->SetBooleanField(result, skyboxEnabled, options.skyboxEnabled);
|
||||
env->SetFloatField(result, cameraFocalLength, options.cameraFocalLength);
|
||||
env->SetFloatField(result, cameraFocusDistance, options.cameraFocusDistance);
|
||||
env->SetBooleanField(result, autoScaleEnabled, options.autoScaleEnabled);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
|
||||
@@ -102,10 +102,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
jclass ktxloaderClass = env->FindClass("com/google/android/filament/utils/KTXLoader");
|
||||
if (ktxloaderClass == nullptr) return JNI_ERR;
|
||||
static const JNINativeMethod ktxMethods[] = {
|
||||
{"nCreateKTXTexture", "(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateKTXTexture)},
|
||||
{"nCreateIndirectLight", "(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateIndirectLight)},
|
||||
{"nCreateSkybox", "(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateSkybox)},
|
||||
{"nGetSphericalHarmonics", "(Ljava/nio/Buffer;I[F)Z", reinterpret_cast<void*>(nGetSphericalHarmonics)},
|
||||
{(char*)"nCreateKTXTexture", (char*)"(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateKTXTexture)},
|
||||
{(char*)"nCreateIndirectLight", (char*)"(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateIndirectLight)},
|
||||
{(char*)"nCreateSkybox", (char*)"(JLjava/nio/Buffer;IZ)J", reinterpret_cast<void*>(nCreateSkybox)},
|
||||
{(char*)"nGetSphericalHarmonics", (char*)"(Ljava/nio/Buffer;I[F)Z", reinterpret_cast<void*>(nGetSphericalHarmonics)},
|
||||
};
|
||||
rc = env->RegisterNatives(ktxloaderClass, ktxMethods, sizeof(ktxMethods) / sizeof(JNINativeMethod));
|
||||
if (rc != JNI_OK) return rc;
|
||||
@@ -114,7 +114,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
jclass hdrloaderClass = env->FindClass("com/google/android/filament/utils/HDRLoader");
|
||||
if (hdrloaderClass == nullptr) return JNI_ERR;
|
||||
static const JNINativeMethod hdrMethods[] = {
|
||||
{"nCreateHDRTexture", "(JLjava/nio/Buffer;II)J", reinterpret_cast<void*>(nCreateHDRTexture)},
|
||||
{(char*)"nCreateHDRTexture", (char*)"(JLjava/nio/Buffer;II)J", reinterpret_cast<void*>(nCreateHDRTexture)},
|
||||
};
|
||||
rc = env->RegisterNatives(hdrloaderClass, hdrMethods, sizeof(hdrMethods) / sizeof(JNINativeMethod));
|
||||
if (rc != JNI_OK) return rc;
|
||||
|
||||
@@ -51,7 +51,7 @@ import com.google.android.filament.Renderer;
|
||||
* (shouldClose) that is triggered after the last test has been invoked.
|
||||
*/
|
||||
public class AutomationEngine {
|
||||
private long mNativeObject;
|
||||
private final long mNativeObject;
|
||||
private ColorGrading mColorGrading;
|
||||
|
||||
/**
|
||||
@@ -76,6 +76,20 @@ public class AutomationEngine {
|
||||
public boolean verbose = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection of Filament objects that can be modified by the automation engine.
|
||||
*/
|
||||
public static class ViewerContent {
|
||||
public View view;
|
||||
public Renderer renderer;
|
||||
public MaterialInstance[] materials;
|
||||
public LightManager lightManager;
|
||||
public Scene scene;
|
||||
public IndirectLight indirectLight;
|
||||
public @Entity int sunlight;
|
||||
public @Entity int[] assetLights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows remote control for the viewer.
|
||||
*/
|
||||
@@ -88,6 +102,7 @@ public class AutomationEngine {
|
||||
public boolean skyboxEnabled = true;
|
||||
public float cameraFocalLength = 28.0f;
|
||||
public float cameraFocusDistance = 0.0f;
|
||||
public boolean autoScaleEnabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,22 +155,22 @@ public class AutomationEngine {
|
||||
* This is when settings get applied, screenshots are (optionally) exported, and the internal
|
||||
* test counter is potentially incremented.
|
||||
*
|
||||
* @param view The Filament View that automation pushes changes to.
|
||||
* @param materials Optional set of of materials that can receive parameter tweaks.
|
||||
* @param renderer The Filament Renderer that can be used to take screenshots.
|
||||
* @param content Contains the Filament View, Materials, and Renderer that get modified.
|
||||
* @param deltaTime The amount of time that has passed since the previous tick in seconds.
|
||||
*/
|
||||
public void tick(@NonNull View view, @Nullable MaterialInstance[] materials,
|
||||
@NonNull Renderer renderer, float deltaTime) {
|
||||
public void tick(@NonNull ViewerContent content, float deltaTime) {
|
||||
if (content.view == null || content.renderer == null) {
|
||||
throw new IllegalStateException("Must provide a View and Renderer");
|
||||
}
|
||||
long[] nativeMaterialInstances = null;
|
||||
if (materials != null) {
|
||||
nativeMaterialInstances = new long[materials.length];
|
||||
if (content.materials != null) {
|
||||
nativeMaterialInstances = new long[content.materials.length];
|
||||
for (int i = 0; i < nativeMaterialInstances.length; i++) {
|
||||
nativeMaterialInstances[i] = materials[i].getNativeObject();
|
||||
nativeMaterialInstances[i] = content.materials[i].getNativeObject();
|
||||
}
|
||||
}
|
||||
long nativeView = view.getNativeObject();
|
||||
long nativeRenderer = renderer.getNativeObject();
|
||||
long nativeView = content.view.getNativeObject();
|
||||
long nativeRenderer = content.renderer.getNativeObject();
|
||||
nTick(mNativeObject, nativeView, nativeMaterialInstances, nativeRenderer, deltaTime);
|
||||
}
|
||||
|
||||
@@ -167,24 +182,32 @@ public class AutomationEngine {
|
||||
*
|
||||
* This updates the stashed Settings object, then pushes those settings to the given
|
||||
* Filament objects. Clients can optionally call getColorGrading() after calling this method.
|
||||
*
|
||||
* @param settingsJson Contains the JSON string with a set of changes that need to be pushed.
|
||||
* @param content Contains a set of Filament objects that you want to mutate.
|
||||
*/
|
||||
public void applySettings(@NonNull String settingsJson, @NonNull View view,
|
||||
@Nullable MaterialInstance[] materials, @Nullable IndirectLight ibl, @Entity int light,
|
||||
@NonNull LightManager lm, @NonNull Scene scene, @NonNull Renderer renderer) {
|
||||
public void applySettings(@NonNull String settingsJson, @NonNull ViewerContent content) {
|
||||
if (content.view == null || content.renderer == null) {
|
||||
throw new IllegalStateException("Must provide a View and Renderer");
|
||||
}
|
||||
long[] nativeMaterialInstances = null;
|
||||
if (materials != null) {
|
||||
nativeMaterialInstances = new long[materials.length];
|
||||
if (content.lightManager == null || content.scene == null) {
|
||||
throw new IllegalStateException("Must provide a LightManager and Scene");
|
||||
}
|
||||
if (content.materials != null) {
|
||||
nativeMaterialInstances = new long[content.materials.length];
|
||||
for (int i = 0; i < nativeMaterialInstances.length; i++) {
|
||||
nativeMaterialInstances[i] = materials[i].getNativeObject();
|
||||
nativeMaterialInstances[i] = content.materials[i].getNativeObject();
|
||||
}
|
||||
}
|
||||
long nativeView = view.getNativeObject();
|
||||
long nativeIbl = ibl == null ? 0 : ibl.getNativeObject();
|
||||
long nativeLm = lm.getNativeObject();
|
||||
long nativeScene = scene.getNativeObject();
|
||||
long nativeRenderer = renderer.getNativeObject();
|
||||
long nativeView = content.view.getNativeObject();
|
||||
long nativeIbl = content.indirectLight == null ? 0 : content.indirectLight.getNativeObject();
|
||||
long nativeLm = content.lightManager.getNativeObject();
|
||||
long nativeScene = content.scene.getNativeObject();
|
||||
long nativeRenderer = content.renderer.getNativeObject();
|
||||
nApplySettings(mNativeObject, settingsJson, nativeView, nativeMaterialInstances,
|
||||
nativeIbl, light, nativeLm, nativeScene, nativeRenderer);
|
||||
nativeIbl, content.sunlight, content.assetLights, nativeLm, nativeScene,
|
||||
nativeRenderer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +269,8 @@ public class AutomationEngine {
|
||||
private static native void nTick(long nativeObject, long view, long[] materials, long renderer,
|
||||
float deltaTime);
|
||||
private static native void nApplySettings(long nativeObject, String jsonSettings, long view,
|
||||
long[] materials, long ibl, int light, long lightManager, long scene, long renderer);
|
||||
long[] materials, long ibl, int sunlight, int[] assetLights, long lightManager,
|
||||
long scene, long renderer);
|
||||
private static native void nGetViewerOptions(long nativeObject, Object result);
|
||||
private static native long nGetColorGrading(long nativeObject, long nativeEngine);
|
||||
private static native void nSignalBatchMode(long nativeObject);
|
||||
|
||||
@@ -32,9 +32,13 @@ import com.google.android.filament.Texture;
|
||||
* Texture equirect = HDRLoader.createTexture("foo.hdr");
|
||||
* Texture skyboxTexture = equirectangularToCubemap.run(equirect);
|
||||
* engine.destroy(equirect);
|
||||
* equirectangularToCubemap.destroy();
|
||||
*
|
||||
* specularFilter = new IBLPrefilterContext.SpecularFilter(context);
|
||||
* Texture reflections = specularFilter.run(skyboxTexture);
|
||||
* specularFilter.destroy();
|
||||
*
|
||||
* context.destroy();
|
||||
*
|
||||
* IndirectLight ibl = IndirectLight.Builder()
|
||||
* .reflections(reflections)
|
||||
@@ -43,81 +47,74 @@ import com.google.android.filament.Texture;
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
public class IBLPrefilterContext {
|
||||
private final long mNativeObject;
|
||||
private long mNativeObject;
|
||||
|
||||
public IBLPrefilterContext(Engine engine) {
|
||||
mNativeObject = nCreate(engine.getNativeObject());
|
||||
if (mNativeObject == 0) throw new IllegalStateException("Couldn't create IBLPrefilterContext");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
nDestroy(mNativeObject);
|
||||
super.finalize();
|
||||
public void destroy() {
|
||||
nDestroy(getNativeObject());
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
public static class EquirectangularToCubemap {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
|
||||
private final HelperFinalizer mFinalizer;
|
||||
private final long mNativeHelper;
|
||||
private long mNativeObject;
|
||||
|
||||
public EquirectangularToCubemap(IBLPrefilterContext context) {
|
||||
mNativeHelper = nCreateEquirectHelper(context.mNativeObject);
|
||||
mFinalizer = new HelperFinalizer(mNativeHelper);
|
||||
mNativeObject = nCreateEquirectHelper(context.getNativeObject());
|
||||
}
|
||||
|
||||
public Texture run(Texture equirect) {
|
||||
long nativeTexture = nEquirectHelperRun(mNativeHelper, equirect.getNativeObject());
|
||||
long nativeTexture = nEquirectHelperRun(getNativeObject(), equirect.getNativeObject());
|
||||
return new Texture(nativeTexture);
|
||||
}
|
||||
|
||||
private static class HelperFinalizer {
|
||||
private final long mNativeObject;
|
||||
public void destroy() {
|
||||
nDestroyEquirectHelper(getNativeObject());
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
HelperFinalizer(long nativeObject) { mNativeObject = nativeObject; }
|
||||
|
||||
@Override
|
||||
public void finalize() {
|
||||
try {
|
||||
super.finalize();
|
||||
} catch (Throwable t) { // Ignore
|
||||
} finally {
|
||||
nDestroyEquirectHelper(mNativeObject);
|
||||
}
|
||||
protected long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed EquirectangularToCubemap");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpecularFilter {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
|
||||
private final HelperFinalizer mFinalizer;
|
||||
private final long mNativeHelper;
|
||||
private long mNativeObject;
|
||||
|
||||
public SpecularFilter(IBLPrefilterContext context) {
|
||||
mNativeHelper = nCreateSpecularFilter(context.mNativeObject);
|
||||
mFinalizer = new HelperFinalizer(mNativeHelper);
|
||||
mNativeObject = nCreateSpecularFilter(context.getNativeObject());
|
||||
}
|
||||
|
||||
public Texture run(Texture skybox) {
|
||||
long nativeTexture = nSpecularFilterRun(mNativeHelper, skybox.getNativeObject());
|
||||
long nativeTexture = nSpecularFilterRun(getNativeObject(), skybox.getNativeObject());
|
||||
return new Texture(nativeTexture);
|
||||
}
|
||||
|
||||
private static class HelperFinalizer {
|
||||
private final long mNativeObject;
|
||||
|
||||
HelperFinalizer(long nativeObject) { mNativeObject = nativeObject; }
|
||||
|
||||
@Override
|
||||
public void finalize() {
|
||||
try {
|
||||
super.finalize();
|
||||
} catch (Throwable t) { // Ignore
|
||||
} finally {
|
||||
nDestroySpecularFilter(mNativeObject);
|
||||
}
|
||||
}
|
||||
public void destroy() {
|
||||
nDestroySpecularFilter(getNativeObject());
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
protected long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed SpecularFilter");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed IBLPrefilterContext");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
private static native long nCreate(long nativeEngine);
|
||||
|
||||
@@ -80,18 +80,22 @@ data class Mat2(
|
||||
operator fun times(v: Float) = Mat2(x * v, y * v)
|
||||
operator fun div(v: Float) = Mat2(x / v, y / v)
|
||||
|
||||
operator fun times(m: Mat2): Mat2 {
|
||||
val t = transpose(this)
|
||||
return Mat2(
|
||||
Float2(dot(t.x, m.x), dot(t.y, m.x)),
|
||||
Float2(dot(t.x, m.y), dot(t.y, m.y))
|
||||
)
|
||||
}
|
||||
operator fun times(m: Mat2) = Mat2(
|
||||
Float2(
|
||||
x.x * m.x.x + y.x * m.x.y,
|
||||
x.y * m.x.x + y.y * m.x.y,
|
||||
),
|
||||
Float2(
|
||||
x.x * m.y.x + y.x * m.y.y,
|
||||
x.y * m.y.x + y.y * m.y.y,
|
||||
)
|
||||
)
|
||||
|
||||
operator fun times(v: Float2) = Float2(
|
||||
x.x * v.x + y.x * v.y,
|
||||
x.y * v.x + y.y * v.y,
|
||||
)
|
||||
|
||||
operator fun times(v: Float2): Float2 {
|
||||
val t = transpose(this)
|
||||
return Float2(dot(t.x, v), dot(t.y, v))
|
||||
}
|
||||
|
||||
fun toFloatArray() = floatArrayOf(
|
||||
x.x, y.x,
|
||||
@@ -171,19 +175,29 @@ data class Mat3(
|
||||
operator fun times(v: Float) = Mat3(x * v, y * v, z * v)
|
||||
operator fun div(v: Float) = Mat3(x / v, y / v, z / v)
|
||||
|
||||
operator fun times(m: Mat3): Mat3 {
|
||||
val t = transpose(this)
|
||||
return Mat3(
|
||||
Float3(dot(t.x, m.x), dot(t.y, m.x), dot(t.z, m.x)),
|
||||
Float3(dot(t.x, m.y), dot(t.y, m.y), dot(t.z, m.y)),
|
||||
Float3(dot(t.x, m.z), dot(t.y, m.z), dot(t.z, m.z))
|
||||
)
|
||||
}
|
||||
operator fun times(m: Mat3) = Mat3(
|
||||
Float3(
|
||||
x.x * m.x.x + y.x * m.x.y + z.x * m.x.z,
|
||||
x.y * m.x.x + y.y * m.x.y + z.y * m.x.z,
|
||||
x.z * m.x.x + y.z * m.x.y + z.z * m.x.z,
|
||||
),
|
||||
Float3(
|
||||
x.x * m.y.x + y.x * m.y.y + z.x * m.y.z,
|
||||
x.y * m.y.x + y.y * m.y.y + z.y * m.y.z,
|
||||
x.z * m.y.x + y.z * m.y.y + z.z * m.y.z,
|
||||
),
|
||||
Float3(
|
||||
x.x * m.z.x + y.x * m.z.y + z.x * m.z.z,
|
||||
x.y * m.z.x + y.y * m.z.y + z.y * m.z.z,
|
||||
x.z * m.z.x + y.z * m.z.y + z.z * m.z.z,
|
||||
)
|
||||
)
|
||||
|
||||
operator fun times(v: Float3): Float3 {
|
||||
val t = transpose(this)
|
||||
return Float3(dot(t.x, v), dot(t.y, v), dot(t.z, v))
|
||||
}
|
||||
operator fun times(v: Float3) = Float3(
|
||||
x.x * v.x + y.x * v.y + z.x * v.z,
|
||||
x.y * v.x + y.y * v.y + z.y * v.z,
|
||||
x.z * v.x + y.z * v.y + z.z * v.z,
|
||||
)
|
||||
|
||||
fun toFloatArray() = floatArrayOf(
|
||||
x.x, y.x, z.x,
|
||||
@@ -313,20 +327,39 @@ data class Mat4(
|
||||
operator fun times(v: Float) = Mat4(x * v, y * v, z * v, w * v)
|
||||
operator fun div(v: Float) = Mat4(x / v, y / v, z / v, w / v)
|
||||
|
||||
operator fun times(m: Mat4): Mat4 {
|
||||
val t = transpose(this)
|
||||
return Mat4(
|
||||
Float4(dot(t.x, m.x), dot(t.y, m.x), dot(t.z, m.x), dot(t.w, m.x)),
|
||||
Float4(dot(t.x, m.y), dot(t.y, m.y), dot(t.z, m.y), dot(t.w, m.y)),
|
||||
Float4(dot(t.x, m.z), dot(t.y, m.z), dot(t.z, m.z), dot(t.w, m.z)),
|
||||
Float4(dot(t.x, m.w), dot(t.y, m.w), dot(t.z, m.w), dot(t.w, m.w))
|
||||
)
|
||||
}
|
||||
operator fun times(m: Mat4) = Mat4(
|
||||
Float4(
|
||||
x.x * m.x.x + y.x * m.x.y + z.x * m.x.z + w.x * m.x.w,
|
||||
x.y * m.x.x + y.y * m.x.y + z.y * m.x.z + w.y * m.x.w,
|
||||
x.z * m.x.x + y.z * m.x.y + z.z * m.x.z + w.z * m.x.w,
|
||||
x.w * m.x.x + y.w * m.x.y + z.w * m.x.z + w.w * m.x.w,
|
||||
),
|
||||
Float4(
|
||||
x.x * m.y.x + y.x * m.y.y + z.x * m.y.z + w.x * m.y.w,
|
||||
x.y * m.y.x + y.y * m.y.y + z.y * m.y.z + w.y * m.y.w,
|
||||
x.z * m.y.x + y.z * m.y.y + z.z * m.y.z + w.z * m.y.w,
|
||||
x.w * m.y.x + y.w * m.y.y + z.w * m.y.z + w.w * m.y.w,
|
||||
),
|
||||
Float4(
|
||||
x.x * m.z.x + y.x * m.z.y + z.x * m.z.z + w.x * m.z.w,
|
||||
x.y * m.z.x + y.y * m.z.y + z.y * m.z.z + w.y * m.z.w,
|
||||
x.z * m.z.x + y.z * m.z.y + z.z * m.z.z + w.z * m.z.w,
|
||||
x.w * m.z.x + y.w * m.z.y + z.w * m.z.z + w.w * m.z.w,
|
||||
),
|
||||
Float4(
|
||||
x.x * m.w.x + y.x * m.w.y + z.x * m.w.z + w.x * m.w.w,
|
||||
x.y * m.w.x + y.y * m.w.y + z.y * m.w.z + w.y * m.w.w,
|
||||
x.z * m.w.x + y.z * m.w.y + z.z * m.w.z + w.z * m.w.w,
|
||||
x.w * m.w.x + y.w * m.w.y + z.w * m.w.z + w.w * m.w.w,
|
||||
)
|
||||
)
|
||||
|
||||
operator fun times(v: Float4): Float4 {
|
||||
val t = transpose(this)
|
||||
return Float4(dot(t.x, v), dot(t.y, v), dot(t.z, v), dot(t.w, v))
|
||||
}
|
||||
operator fun times(v: Float4) = Float4(
|
||||
x.x * v.x + y.x * v.y + z.x * v.z+ w.x * v.w,
|
||||
x.y * v.x + y.y * v.y + z.y * v.z+ w.y * v.w,
|
||||
x.z * v.x + y.z * v.y + z.z * v.z+ w.z * v.w,
|
||||
x.w * v.x + y.w * v.y + z.w * v.z+ w.w * v.w
|
||||
)
|
||||
|
||||
fun toFloatArray() = floatArrayOf(
|
||||
x.x, y.x, z.x, w.x,
|
||||
@@ -355,6 +388,8 @@ fun transpose(m: Mat3) = Mat3(
|
||||
Float3(m.x.y, m.y.y, m.z.y),
|
||||
Float3(m.x.z, m.y.z, m.z.z)
|
||||
)
|
||||
|
||||
@Suppress("LocalVariableName")
|
||||
fun inverse(m: Mat3): Mat3 {
|
||||
val a = m.x.x
|
||||
val b = m.x.y
|
||||
@@ -385,6 +420,7 @@ fun transpose(m: Mat4) = Mat4(
|
||||
Float4(m.x.z, m.y.z, m.z.z, m.w.z),
|
||||
Float4(m.x.w, m.y.w, m.z.w, m.w.w)
|
||||
)
|
||||
|
||||
fun inverse(m: Mat4): Mat4 {
|
||||
val result = Mat4()
|
||||
|
||||
@@ -462,8 +498,8 @@ fun translation(m: Mat4) = translation(m.translation)
|
||||
fun rotation(m: Mat4) = Mat4(normalize(m.right), normalize(m.up), normalize(m.forward))
|
||||
fun rotation(d: Float3): Mat4 {
|
||||
val r = transform(d, ::radians)
|
||||
val c = transform(r, { x -> cos(x) })
|
||||
val s = transform(r, { x -> sin(x) })
|
||||
val c = transform(r) { x -> cos(x) }
|
||||
val s = transform(r) { x -> sin(x) }
|
||||
|
||||
return Mat4.of(
|
||||
c.y * c.z, -c.x * s.z + s.x * s.y * c.z, s.x * s.z + c.x * s.y * c.z, 0.0f,
|
||||
|
||||
@@ -110,7 +110,7 @@ class ModelViewer(val engine: Engine) : android.view.View.OnTouchListener {
|
||||
view.scene = scene
|
||||
view.camera = camera
|
||||
|
||||
assetLoader = AssetLoader(engine, MaterialProvider(engine), EntityManager.get())
|
||||
assetLoader = AssetLoader(engine, UbershaderLoader(engine), EntityManager.get())
|
||||
resourceLoader = ResourceLoader(engine, normalizeSkinningWeights, recomputeBoundingBoxes)
|
||||
|
||||
// Always add a direct light source since it is required for shadowing.
|
||||
@@ -225,6 +225,16 @@ class ModelViewer(val engine: Engine) : android.view.View.OnTouchListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the transformation that was set up via transformToUnitCube.
|
||||
*/
|
||||
fun clearRootTransform() {
|
||||
asset?.let {
|
||||
val tm = engine.transformManager
|
||||
tm.setTransform(tm.getInstance(it.root), Mat4().toFloatArray())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees all entities associated with the most recently-loaded model.
|
||||
*/
|
||||
|
||||
@@ -61,7 +61,9 @@ set(GLTFIO_SRCS
|
||||
src/main/cpp/AssetLoader.cpp
|
||||
src/main/cpp/FilamentAsset.cpp
|
||||
src/main/cpp/FilamentInstance.cpp
|
||||
src/main/cpp/MaterialProvider.cpp
|
||||
src/main/cpp/MaterialKey.cpp
|
||||
src/main/cpp/MaterialKey.h
|
||||
src/main/cpp/UbershaderLoader.cpp
|
||||
src/main/cpp/ResourceLoader.cpp
|
||||
|
||||
${FILAMENT_DIR}/include/gltfio/resources/gltfresources_lite.h
|
||||
@@ -74,6 +76,8 @@ set(GLTFIO_INCLUDE_DIRS
|
||||
..
|
||||
${FILAMENT_DIR}/include
|
||||
${FILAMENT_DIR}/include/gltfio/resources
|
||||
../../filament/backend/include
|
||||
../../libs/gltfio/include
|
||||
../../third_party/cgltf
|
||||
../../third_party/robin-map
|
||||
../../third_party/hat-trie
|
||||
|
||||
@@ -27,7 +27,8 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation deps.androidx.annotations
|
||||
implementation project(':filament-android')
|
||||
|
||||
api project(':filament-android')
|
||||
}
|
||||
|
||||
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,27 +23,178 @@
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/MaterialProvider.h>
|
||||
#include <utils/debug.h>
|
||||
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
#include "MaterialKey.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace gltfio;
|
||||
using namespace utils;
|
||||
|
||||
class JavaMaterialProvider : public MaterialProvider {
|
||||
JNIEnv* const mEnv;
|
||||
const jobject mJavaProvider;
|
||||
mutable Material** mPreviousMaterials = nullptr;
|
||||
|
||||
jclass mMaterialKeyClass;
|
||||
|
||||
jmethodID mMaterialKeyConstructor;
|
||||
jmethodID mCreateMaterialInstance;
|
||||
jmethodID mGetMaterials;
|
||||
jmethodID mNeedsDummyData;
|
||||
jmethodID mDestroyMaterials;
|
||||
jmethodID mMaterialInstanceGetNativeObject;
|
||||
jmethodID mMaterialGetNativeObject;
|
||||
|
||||
public:
|
||||
JavaMaterialProvider(JNIEnv* env, jobject provider) : mEnv(env),
|
||||
mJavaProvider(env->NewGlobalRef(provider)) {
|
||||
mMaterialKeyClass = env->FindClass(JAVA_MATERIAL_KEY);
|
||||
mMaterialKeyClass = (jclass) env->NewGlobalRef(mMaterialKeyClass);
|
||||
assert_invariant(mMaterialKeyClass);
|
||||
|
||||
mMaterialKeyConstructor = env->GetMethodID(mMaterialKeyClass, "<init>", "()V");
|
||||
assert_invariant(mMaterialKeyConstructor);
|
||||
|
||||
jclass materialInstanceClass = env->FindClass("com/google/android/filament/MaterialInstance");
|
||||
mMaterialInstanceGetNativeObject = env->GetMethodID(materialInstanceClass, "getNativeObject", "()J");
|
||||
assert_invariant(mMaterialInstanceGetNativeObject);
|
||||
|
||||
jclass materialClass = env->FindClass("com/google/android/filament/Material");
|
||||
mMaterialGetNativeObject = env->GetMethodID(materialClass, "getNativeObject", "()J");
|
||||
assert_invariant(mMaterialGetNativeObject);
|
||||
|
||||
jclass providerClass = env->GetObjectClass(provider);
|
||||
|
||||
mCreateMaterialInstance = env->GetMethodID(providerClass, "createMaterialInstance",
|
||||
"(L" JAVA_MATERIAL_KEY ";[ILjava/lang/String;)Lcom/google/android/filament/MaterialInstance;");
|
||||
assert_invariant(mCreateMaterialInstance);
|
||||
|
||||
mGetMaterials = env->GetMethodID(providerClass, "getMaterials",
|
||||
"()[Lcom/google/android/filament/Material;");
|
||||
assert_invariant(mGetMaterials);
|
||||
|
||||
mNeedsDummyData = env->GetMethodID(providerClass, "needsDummyData","(I)Z");
|
||||
assert_invariant(mNeedsDummyData);
|
||||
|
||||
mDestroyMaterials = env->GetMethodID(providerClass, "destroyMaterials", "()V");
|
||||
assert_invariant(mDestroyMaterials);
|
||||
}
|
||||
|
||||
~JavaMaterialProvider() override {
|
||||
mEnv->DeleteGlobalRef(mMaterialKeyClass);
|
||||
mEnv->DeleteGlobalRef(mJavaProvider);
|
||||
delete mPreviousMaterials;
|
||||
}
|
||||
|
||||
MaterialInstance* createMaterialInstance(MaterialKey* config, UvMap* uvmap, const char* label) override {
|
||||
// Create a Java object for the material key and copy the native fields into it.
|
||||
jobject javaKey = mEnv->NewObject(mMaterialKeyClass, mMaterialKeyConstructor);
|
||||
|
||||
auto& helper = MaterialKeyHelper::get();
|
||||
helper.copy(mEnv, javaKey, *config);
|
||||
|
||||
// Convert the optional label into a Java string.
|
||||
jstring stringLabel = label ? mEnv->NewStringUTF(label) : nullptr;
|
||||
|
||||
// Allocate space for the output argument.
|
||||
jintArray uvMapArray = mEnv->NewIntArray(8);
|
||||
|
||||
// Call the Java-based material provider.
|
||||
jobject materialInstance = mEnv->CallObjectMethod(mJavaProvider, mCreateMaterialInstance,
|
||||
javaKey, uvMapArray, stringLabel);
|
||||
|
||||
// Copy the UvMap results from the JVM array into the native array.
|
||||
if (uvmap) {
|
||||
jint* elements = mEnv->GetIntArrayElements(uvMapArray, nullptr);
|
||||
for (size_t i = 0; i < uvmap->size(); i++) {
|
||||
(*uvmap)[i] = (UvSet) elements[i];
|
||||
}
|
||||
mEnv->ReleaseIntArrayElements(uvMapArray, elements, JNI_ABORT);
|
||||
}
|
||||
|
||||
// The config parameter is an in-out parameter so we need to copy the results from Java.
|
||||
helper.copy(mEnv, *config, javaKey);
|
||||
|
||||
mEnv->DeleteLocalRef(javaKey);
|
||||
mEnv->DeleteLocalRef(uvMapArray);
|
||||
|
||||
if (stringLabel) {
|
||||
mEnv->DeleteLocalRef(stringLabel);
|
||||
}
|
||||
|
||||
if (materialInstance == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (MaterialInstance*) mEnv->CallLongMethod(materialInstance, mMaterialInstanceGetNativeObject);
|
||||
}
|
||||
|
||||
const Material* const* getMaterials() const noexcept override {
|
||||
jobjectArray javaMaterials = (jobjectArray) mEnv->CallObjectMethod(mJavaProvider, mGetMaterials);
|
||||
|
||||
const size_t count = mEnv->GetArrayLength(javaMaterials);
|
||||
|
||||
delete mPreviousMaterials;
|
||||
using MaterialPointer = Material*;
|
||||
mPreviousMaterials = new MaterialPointer[count];
|
||||
|
||||
// Call "getNativeObject" on each material in order to pass them up into the native layer.
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
jobject javaMaterial = mEnv->GetObjectArrayElement(javaMaterials, i);
|
||||
jlong matPointer = mEnv->CallLongMethod(javaMaterial, mMaterialGetNativeObject);
|
||||
mPreviousMaterials[i] = (Material*) matPointer;
|
||||
}
|
||||
|
||||
return mPreviousMaterials;
|
||||
}
|
||||
|
||||
size_t getMaterialsCount() const noexcept override {
|
||||
jobjectArray javaMaterials = (jobjectArray) mEnv->CallObjectMethod(mJavaProvider, mGetMaterials);
|
||||
return mEnv->GetArrayLength(javaMaterials);
|
||||
}
|
||||
|
||||
void destroyMaterials() override {
|
||||
mEnv->CallObjectMethod(mJavaProvider, mDestroyMaterials);
|
||||
}
|
||||
|
||||
bool needsDummyData(VertexAttribute attrib) const noexcept override {
|
||||
return mEnv->CallBooleanMethod(mJavaProvider, mNeedsDummyData, (int) attrib);
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nCreateAssetLoader(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeProvider, jlong nativeEntities) {
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nCreateAssetLoader(JNIEnv* env, jclass,
|
||||
jlong nativeEngine, jobject provider, jlong nativeEntities) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
MaterialProvider* materials = (MaterialProvider*) nativeProvider;
|
||||
MaterialProvider* materialProvider = nullptr;
|
||||
|
||||
// First check for a fast path that passes a native MaterialProvider into the loader.
|
||||
// This drastically reduces the number of JNI calls while the asset is being loaded.
|
||||
jclass klass = env->GetObjectClass(provider);
|
||||
jmethodID getNativeObject = env->GetMethodID(klass, "getNativeObject", "()J");
|
||||
if (getNativeObject) {
|
||||
materialProvider = (MaterialProvider*) env->CallLongMethod(provider, getNativeObject);
|
||||
} else {
|
||||
env->ExceptionClear();
|
||||
}
|
||||
|
||||
if (materialProvider == nullptr) {
|
||||
materialProvider = new JavaMaterialProvider(env, provider);
|
||||
}
|
||||
|
||||
EntityManager* entities = (EntityManager*) nativeEntities;
|
||||
NameComponentManager* names = new NameComponentManager(*entities);
|
||||
return (jlong) AssetLoader::create({engine, materials, names, entities});
|
||||
return (jlong) AssetLoader::create({engine, materialProvider, names, entities});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nDestroyAssetLoader(JNIEnv*, jclass,
|
||||
jlong nativeLoader) {
|
||||
AssetLoader* loader = (AssetLoader*) nativeLoader;
|
||||
delete loader->getMaterialProvider();
|
||||
NameComponentManager* names = loader->getNames();
|
||||
AssetLoader::destroy(&loader);
|
||||
delete names;
|
||||
|
||||
@@ -192,6 +192,15 @@ Java_com_google_android_filament_gltfio_FilamentAsset_nGetName(JNIEnv* env, jcla
|
||||
return val ? env->NewStringUTF(val) : nullptr;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetExtras(JNIEnv* env, jclass,
|
||||
jlong nativeAsset, jint entityId) {
|
||||
Entity entity = Entity::import(entityId);
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
const auto val = asset->getExtras(entity);
|
||||
return val ? env->NewStringUTF(val) : nullptr;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetAnimator(JNIEnv* , jclass,
|
||||
jlong nativeAsset) {
|
||||
|
||||
177
android/gltfio-android/src/main/cpp/MaterialKey.cpp
Normal file
177
android/gltfio-android/src/main/cpp/MaterialKey.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <gltfio/MaterialProvider.h>
|
||||
|
||||
#include "MaterialKey.h"
|
||||
|
||||
using namespace gltfio;
|
||||
|
||||
MaterialKeyHelper& MaterialKeyHelper::get() {
|
||||
static MaterialKeyHelper helper;
|
||||
return helper;
|
||||
}
|
||||
|
||||
void MaterialKeyHelper::init(JNIEnv* env) {
|
||||
const jclass materialKeyClass = env->FindClass(JAVA_MATERIAL_KEY);
|
||||
auto field = [materialKeyClass, env](const char* fieldName, const char* signature) {
|
||||
return env->GetFieldID(materialKeyClass, fieldName, signature);
|
||||
};
|
||||
doubleSided = field("doubleSided", "Z");
|
||||
unlit = field("unlit", "Z");
|
||||
hasVertexColors = field("hasVertexColors", "Z");
|
||||
hasBaseColorTexture = field("hasBaseColorTexture", "Z");
|
||||
hasNormalTexture = field("hasNormalTexture", "Z");
|
||||
hasOcclusionTexture = field("hasOcclusionTexture", "Z");
|
||||
hasEmissiveTexture = field("hasEmissiveTexture", "Z");
|
||||
useSpecularGlossiness = field("useSpecularGlossiness", "Z");
|
||||
alphaMode = field("alphaMode", "I");
|
||||
enableDiagnostics = field("enableDiagnostics", "Z");
|
||||
hasMetallicRoughnessTexture = field("hasMetallicRoughnessTexture", "Z");
|
||||
metallicRoughnessUV = field("metallicRoughnessUV", "I");
|
||||
baseColorUV = field("baseColorUV", "I");
|
||||
hasClearCoatTexture = field("hasClearCoatTexture", "Z");
|
||||
clearCoatUV = field("clearCoatUV", "I");
|
||||
hasClearCoatRoughnessTexture = field("hasClearCoatRoughnessTexture", "Z");
|
||||
clearCoatRoughnessUV = field("clearCoatRoughnessUV", "I");
|
||||
hasClearCoatNormalTexture = field("hasClearCoatNormalTexture", "Z");
|
||||
clearCoatNormalUV = field("clearCoatNormalUV", "I");
|
||||
hasClearCoat = field("hasClearCoat", "Z");
|
||||
hasTransmission = field("hasTransmission", "Z");
|
||||
hasTextureTransforms = field("hasTextureTransforms", "Z");
|
||||
emissiveUV = field("emissiveUV", "I");
|
||||
aoUV = field("aoUV", "I");
|
||||
normalUV = field("normalUV", "I");
|
||||
hasTransmissionTexture = field("hasTransmissionTexture", "Z");
|
||||
transmissionUV = field("transmissionUV", "I");
|
||||
hasSheenColorTexture = field("hasSheenColorTexture", "Z");
|
||||
sheenColorUV = field("sheenColorUV", "I");
|
||||
hasSheenRoughnessTexture = field("hasSheenRoughnessTexture", "Z");
|
||||
sheenRoughnessUV = field("sheenRoughnessUV", "I");
|
||||
hasVolumeThicknessTexture = field("hasVolumeThicknessTexture", "Z");
|
||||
volumeThicknessUV = field("volumeThicknessUV", "I");
|
||||
hasSheen = field("hasSheen", "Z");
|
||||
hasIOR = field("hasIOR", "Z");
|
||||
}
|
||||
|
||||
void MaterialKeyHelper::copy(JNIEnv* env, MaterialKey& dst, jobject src) {
|
||||
dst.doubleSided = env->GetBooleanField(src, doubleSided);
|
||||
dst.unlit = env->GetBooleanField(src, unlit);
|
||||
dst.hasVertexColors = env->GetBooleanField(src, hasVertexColors);
|
||||
dst.hasBaseColorTexture = env->GetBooleanField(src, hasBaseColorTexture);
|
||||
dst.hasNormalTexture = env->GetBooleanField(src, hasNormalTexture);
|
||||
dst.hasOcclusionTexture = env->GetBooleanField(src, hasOcclusionTexture);
|
||||
dst.hasEmissiveTexture = env->GetBooleanField(src, hasEmissiveTexture);
|
||||
dst.useSpecularGlossiness = env->GetBooleanField(src, useSpecularGlossiness);
|
||||
dst.alphaMode = (AlphaMode) env->GetIntField(src, alphaMode);
|
||||
dst.enableDiagnostics = env->GetBooleanField(src, enableDiagnostics);
|
||||
dst.hasMetallicRoughnessTexture = env->GetBooleanField(src, hasMetallicRoughnessTexture);
|
||||
dst.metallicRoughnessUV = env->GetIntField(src, metallicRoughnessUV);
|
||||
dst.baseColorUV = env->GetIntField(src, baseColorUV);
|
||||
dst.hasClearCoatTexture = env->GetBooleanField(src, hasClearCoatTexture);
|
||||
dst.clearCoatUV = env->GetIntField(src, clearCoatUV);
|
||||
dst.hasClearCoatRoughnessTexture = env->GetBooleanField(src, hasClearCoatRoughnessTexture);
|
||||
dst.clearCoatRoughnessUV = env->GetIntField(src, clearCoatRoughnessUV);
|
||||
dst.hasClearCoatNormalTexture = env->GetBooleanField(src, hasClearCoatNormalTexture);
|
||||
dst.clearCoatNormalUV = env->GetIntField(src, clearCoatNormalUV);
|
||||
dst.hasClearCoat = env->GetBooleanField(src, hasClearCoat);
|
||||
dst.hasTransmission = env->GetBooleanField(src, hasTransmission);
|
||||
dst.hasTextureTransforms = env->GetBooleanField(src, hasTextureTransforms);
|
||||
dst.emissiveUV = env->GetIntField(src, emissiveUV);
|
||||
dst.aoUV = env->GetIntField(src, aoUV);
|
||||
dst.normalUV = env->GetIntField(src, normalUV);
|
||||
dst.hasTransmissionTexture = env->GetBooleanField(src, hasTransmissionTexture);
|
||||
dst.transmissionUV = env->GetIntField(src, transmissionUV);
|
||||
dst.hasSheenColorTexture = env->GetBooleanField(src, hasSheenColorTexture);
|
||||
dst.sheenColorUV = env->GetIntField(src, sheenColorUV);
|
||||
dst.hasSheenRoughnessTexture = env->GetBooleanField(src, hasSheenRoughnessTexture);
|
||||
dst.sheenRoughnessUV = env->GetIntField(src, sheenRoughnessUV);
|
||||
dst.hasVolumeThicknessTexture = env->GetBooleanField(src, hasVolumeThicknessTexture);
|
||||
dst.volumeThicknessUV = env->GetIntField(src, volumeThicknessUV);
|
||||
dst.hasSheen = env->GetBooleanField(src, hasSheen);
|
||||
dst.hasIOR = env->GetBooleanField(src, hasIOR);
|
||||
}
|
||||
|
||||
void MaterialKeyHelper::copy(JNIEnv* env, jobject dst, const MaterialKey& src) {
|
||||
env->SetBooleanField(dst, doubleSided, src.doubleSided);
|
||||
env->SetBooleanField(dst, unlit, src.unlit);
|
||||
env->SetBooleanField(dst, hasVertexColors, src.hasVertexColors);
|
||||
env->SetBooleanField(dst, hasBaseColorTexture, src.hasBaseColorTexture);
|
||||
env->SetBooleanField(dst, hasNormalTexture, src.hasNormalTexture);
|
||||
env->SetBooleanField(dst, hasOcclusionTexture, src.hasOcclusionTexture);
|
||||
env->SetBooleanField(dst, hasEmissiveTexture, src.hasEmissiveTexture);
|
||||
env->SetBooleanField(dst, useSpecularGlossiness, src.useSpecularGlossiness);
|
||||
env->SetIntField(dst, alphaMode, (int) src.alphaMode);
|
||||
env->SetBooleanField(dst, enableDiagnostics, src.enableDiagnostics);
|
||||
env->SetBooleanField(dst, hasMetallicRoughnessTexture, src.hasMetallicRoughnessTexture);
|
||||
env->SetIntField(dst, metallicRoughnessUV, src.metallicRoughnessUV);
|
||||
env->SetIntField(dst, baseColorUV, src.baseColorUV);
|
||||
env->SetBooleanField(dst, hasClearCoatTexture, src.hasClearCoatTexture);
|
||||
env->SetIntField(dst, clearCoatUV, src.clearCoatUV);
|
||||
env->SetBooleanField(dst, hasClearCoatRoughnessTexture, src.hasClearCoatRoughnessTexture);
|
||||
env->SetIntField(dst, clearCoatRoughnessUV, src.clearCoatRoughnessUV);
|
||||
env->SetBooleanField(dst, hasClearCoatNormalTexture, src.hasClearCoatNormalTexture);
|
||||
env->SetIntField(dst, clearCoatNormalUV, src.clearCoatNormalUV);
|
||||
env->SetBooleanField(dst, hasClearCoat, src.hasClearCoat);
|
||||
env->SetBooleanField(dst, hasTransmission, src.hasTransmission);
|
||||
env->SetBooleanField(dst, hasTextureTransforms, src.hasTextureTransforms);
|
||||
env->SetIntField(dst, emissiveUV, src.emissiveUV);
|
||||
env->SetIntField(dst, aoUV, src.aoUV);
|
||||
env->SetIntField(dst, normalUV, src.normalUV);
|
||||
env->SetBooleanField(dst, hasTransmissionTexture, src.hasTransmissionTexture);
|
||||
env->SetIntField(dst, transmissionUV, src.transmissionUV);
|
||||
env->SetBooleanField(dst, hasSheenColorTexture, src.hasSheenColorTexture);
|
||||
env->SetIntField(dst, sheenColorUV, src.sheenColorUV);
|
||||
env->SetBooleanField(dst, hasSheenRoughnessTexture, src.hasSheenRoughnessTexture);
|
||||
env->SetIntField(dst, sheenRoughnessUV, src.sheenRoughnessUV);
|
||||
env->SetBooleanField(dst, hasVolumeThicknessTexture, src.hasVolumeThicknessTexture);
|
||||
env->SetIntField(dst, volumeThicknessUV, src.volumeThicknessUV);
|
||||
env->SetBooleanField(dst, hasSheen, src.hasSheen);
|
||||
env->SetBooleanField(dst, hasIOR, src.hasIOR);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_MaterialProvider_00024MaterialKey_nGlobalInit(JNIEnv* env, jclass) {
|
||||
MaterialKeyHelper::get().init(env);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_MaterialProvider_00024MaterialKey_nConstrainMaterial(JNIEnv* env, jclass,
|
||||
jobject materialKey, jintArray uvMap) {
|
||||
MaterialKey nativeMaterialKey = {};
|
||||
|
||||
auto& helper = MaterialKeyHelper::get();
|
||||
helper.copy(env, nativeMaterialKey, materialKey);
|
||||
|
||||
UvMap nativeUvMap = {};
|
||||
constrainMaterial(&nativeMaterialKey, &nativeUvMap);
|
||||
|
||||
// Copy the UvMap results from the native array into the JVM array.
|
||||
jint* elements = env->GetIntArrayElements(uvMap, nullptr);
|
||||
if (elements) {
|
||||
const size_t javaSize = env->GetArrayLength(uvMap);
|
||||
for (int i = 0, n = std::min(javaSize, nativeUvMap.size()); i < n; ++i) {
|
||||
elements[i] = nativeUvMap[i];
|
||||
}
|
||||
env->ReleaseIntArrayElements(uvMap, elements, 0);
|
||||
}
|
||||
|
||||
// The config parameter is an in-out parameter so we need to copy the results back to Java.
|
||||
helper.copy(env, materialKey, nativeMaterialKey);
|
||||
}
|
||||
68
android/gltfio-android/src/main/cpp/MaterialKey.h
Normal file
68
android/gltfio-android/src/main/cpp/MaterialKey.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <gltfio/MaterialProvider.h>
|
||||
|
||||
#define JAVA_MATERIAL_KEY "com/google/android/filament/gltfio/MaterialProvider$MaterialKey"
|
||||
|
||||
class MaterialKeyHelper {
|
||||
public:
|
||||
static MaterialKeyHelper& get();
|
||||
|
||||
void copy(JNIEnv* env, gltfio::MaterialKey& dst, jobject src);
|
||||
void copy(JNIEnv* env, jobject dst, const gltfio::MaterialKey& src);
|
||||
|
||||
void init(JNIEnv* env); // called only from the Java static class constructor
|
||||
|
||||
private:
|
||||
jfieldID doubleSided;
|
||||
jfieldID unlit;
|
||||
jfieldID hasVertexColors;
|
||||
jfieldID hasBaseColorTexture;
|
||||
jfieldID hasNormalTexture;
|
||||
jfieldID hasOcclusionTexture;
|
||||
jfieldID hasEmissiveTexture;
|
||||
jfieldID useSpecularGlossiness;
|
||||
jfieldID alphaMode;
|
||||
jfieldID enableDiagnostics;
|
||||
jfieldID hasMetallicRoughnessTexture;
|
||||
jfieldID metallicRoughnessUV;
|
||||
jfieldID baseColorUV;
|
||||
jfieldID hasClearCoatTexture;
|
||||
jfieldID clearCoatUV;
|
||||
jfieldID hasClearCoatRoughnessTexture;
|
||||
jfieldID clearCoatRoughnessUV;
|
||||
jfieldID hasClearCoatNormalTexture;
|
||||
jfieldID clearCoatNormalUV;
|
||||
jfieldID hasClearCoat;
|
||||
jfieldID hasTransmission;
|
||||
jfieldID hasTextureTransforms;
|
||||
jfieldID emissiveUV;
|
||||
jfieldID aoUV;
|
||||
jfieldID normalUV;
|
||||
jfieldID hasTransmissionTexture;
|
||||
jfieldID transmissionUV;
|
||||
jfieldID hasSheenColorTexture;
|
||||
jfieldID sheenColorUV;
|
||||
jfieldID hasSheenRoughnessTexture;
|
||||
jfieldID sheenRoughnessUV;
|
||||
jfieldID hasVolumeThicknessTexture;
|
||||
jfieldID volumeThicknessUV;
|
||||
jfieldID hasSheen;
|
||||
jfieldID hasIOR;
|
||||
};
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <gltfio/MaterialProvider.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace gltfio;
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_MaterialProvider_nCreateMaterialProvider(JNIEnv*, jclass,
|
||||
jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return (jlong) createUbershaderLoader(engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_MaterialProvider_nDestroyMaterialProvider(JNIEnv*, jclass,
|
||||
jlong nativeProvider) {
|
||||
auto provider = (MaterialProvider*) nativeProvider;
|
||||
delete provider;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_MaterialProvider_nDestroyMaterials(JNIEnv*, jclass,
|
||||
jlong nativeProvider) {
|
||||
auto provider = (MaterialProvider*) nativeProvider;
|
||||
provider->destroyMaterials();
|
||||
}
|
||||
102
android/gltfio-android/src/main/cpp/UbershaderLoader.cpp
Normal file
102
android/gltfio-android/src/main/cpp/UbershaderLoader.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <gltfio/MaterialProvider.h>
|
||||
|
||||
#include <utils/debug.h>
|
||||
|
||||
#include "MaterialKey.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace gltfio;
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_UbershaderLoader_nCreateUbershaderLoader(JNIEnv*, jclass,
|
||||
jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return (jlong) createUbershaderLoader(engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_UbershaderLoader_nDestroyUbershaderLoader(JNIEnv*, jclass,
|
||||
jlong nativeProvider) {
|
||||
auto provider = (MaterialProvider*) nativeProvider;
|
||||
delete provider;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_UbershaderLoader_nDestroyMaterials(JNIEnv*, jclass,
|
||||
jlong nativeProvider) {
|
||||
auto provider = (MaterialProvider*) nativeProvider;
|
||||
provider->destroyMaterials();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT long JNICALL
|
||||
Java_com_google_android_filament_gltfio_UbershaderLoader_nCreateMaterialInstance(JNIEnv* env, jclass,
|
||||
jlong nativeProvider, jobject materialKey, jintArray uvmap, jstring label) {
|
||||
MaterialKey nativeKey = {};
|
||||
|
||||
auto& helper = MaterialKeyHelper::get();
|
||||
helper.copy(env, nativeKey, materialKey);
|
||||
|
||||
const char* nativeLabel = label ? env->GetStringUTFChars(label, nullptr) : nullptr;
|
||||
UvMap nativeUvMap = {};
|
||||
auto provider = (MaterialProvider*) nativeProvider;
|
||||
MaterialInstance* instance = provider->createMaterialInstance(&nativeKey, &nativeUvMap, nativeLabel);
|
||||
|
||||
// Copy the UvMap results from the native array into the JVM array.
|
||||
jint* elements = env->GetIntArrayElements(uvmap, nullptr);
|
||||
if (elements) {
|
||||
const size_t javaSize = env->GetArrayLength(uvmap);
|
||||
for (int i = 0, n = std::min(javaSize, nativeUvMap.size()); i < n; ++i) {
|
||||
elements[i] = nativeUvMap[i];
|
||||
}
|
||||
env->ReleaseIntArrayElements(uvmap, elements, 0);
|
||||
}
|
||||
|
||||
// The config parameter is an in-out parameter so we need to copy the results back to Java.
|
||||
helper.copy(env, materialKey, nativeKey);
|
||||
|
||||
if (label) {
|
||||
env->ReleaseStringUTFChars(label, nativeLabel);
|
||||
}
|
||||
|
||||
return (long) instance;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT int JNICALL
|
||||
Java_com_google_android_filament_gltfio_UbershaderLoader_nGetMaterialCount(JNIEnv*, jclass,
|
||||
jlong nativeProvider) {
|
||||
auto provider = (MaterialProvider*) nativeProvider;
|
||||
return provider->getMaterialsCount();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_UbershaderLoader_nGetMaterials(JNIEnv* env, jclass,
|
||||
jlong nativeProvider, jlongArray result) {
|
||||
auto provider = (MaterialProvider *) nativeProvider;
|
||||
auto materials = provider->getMaterials();
|
||||
jlong *resultElements = env->GetLongArrayElements(result, nullptr);
|
||||
if (resultElements) {
|
||||
const size_t javaSize = env->GetArrayLength(result);
|
||||
for (int i = 0, n = std::min(javaSize, provider->getMaterialsCount()); i < n; ++i) {
|
||||
resultElements[i] = (jlong) materials[i];
|
||||
}
|
||||
env->ReleaseLongArrayElements(result, resultElements, JNI_ABORT);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ import java.nio.Buffer;
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* assetLoader = AssetLoader(engine, MaterialProvider(engine), EntityManager.get())
|
||||
* assetLoader = AssetLoader(engine, UbershaderLoader(engine), EntityManager.get())
|
||||
*
|
||||
* filamentAsset = assets.open("models/lucy.gltf").use { input ->
|
||||
* val bytes = ByteArray(input.available())
|
||||
@@ -85,31 +85,30 @@ public class AssetLoader {
|
||||
* {@link FilamentAsset}.
|
||||
*
|
||||
* @param engine the engine that the loader should pass to builder objects
|
||||
* @param generator specifies if materials should be generated or loaded from a pre-built set
|
||||
* @param provider an object that provides Filament materials corresponding to glTF materials
|
||||
* @param entities the EntityManager that should be used to create entities
|
||||
*/
|
||||
public AssetLoader(@NonNull Engine engine, @NonNull MaterialProvider generator,
|
||||
public AssetLoader(@NonNull Engine engine, @NonNull MaterialProvider provider,
|
||||
@NonNull EntityManager entities) {
|
||||
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
long nativeMaterials = generator.getNativeObject();
|
||||
long nativeEntities = entities.getNativeObject();
|
||||
mNativeObject = nCreateAssetLoader(nativeEngine, nativeMaterials, nativeEntities);
|
||||
mNativeObject = nCreateAssetLoader(nativeEngine, provider, nativeEntities);
|
||||
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Unable to parse glTF asset.");
|
||||
}
|
||||
|
||||
mEngine = engine;
|
||||
mMaterialCache = generator;
|
||||
mMaterialCache = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees all memory consumed by the native <code>AssetLoader</code> and its material cache.
|
||||
*/
|
||||
public void destroy() {
|
||||
nDestroyAssetLoader(mNativeObject);
|
||||
mMaterialCache.destroyMaterials();
|
||||
nDestroyAssetLoader(mNativeObject);
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
@@ -149,10 +148,11 @@ public class AssetLoader {
|
||||
if (nativeAsset == 0) {
|
||||
return null;
|
||||
}
|
||||
FilamentAsset asset = new FilamentAsset(mEngine, nativeAsset);
|
||||
for (int i = 0; i < nativeInstances.length; i++) {
|
||||
instances[i] = new FilamentInstance(nativeInstances[i]);
|
||||
instances[i] = new FilamentInstance(asset, nativeInstances[i]);
|
||||
}
|
||||
return new FilamentAsset(mEngine, nativeAsset);
|
||||
return asset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +178,7 @@ public class AssetLoader {
|
||||
if (nativeInstance == 0) {
|
||||
return null;
|
||||
}
|
||||
return new FilamentInstance(nativeInstance);
|
||||
return new FilamentInstance(asset, nativeInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +197,7 @@ public class AssetLoader {
|
||||
asset.clearNativeObject();
|
||||
}
|
||||
|
||||
private static native long nCreateAssetLoader(long nativeEngine, long nativeGenerator,
|
||||
private static native long nCreateAssetLoader(long nativeEngine, Object provider,
|
||||
long nativeEntities);
|
||||
private static native void nDestroyAssetLoader(long nativeLoader);
|
||||
private static native long nCreateAssetFromBinary(long nativeLoader, Buffer buffer, int remaining);
|
||||
|
||||
@@ -186,6 +186,16 @@ public class FilamentAsset {
|
||||
return nGetName(getNativeObject(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the glTF extras string for the asset or a specific node.
|
||||
*
|
||||
* @param entity the entity corresponding to the glTF node, or 0 to get the asset-level string.
|
||||
* @return the requested extras string, or null if it does not exist.
|
||||
*/
|
||||
public @Nullable String getExtras(@Entity int entity) {
|
||||
return nGetExtras(mNativeObject, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates or retrieves the <code>Animator</code> interface for this asset.
|
||||
*
|
||||
@@ -252,6 +262,7 @@ public class FilamentAsset {
|
||||
|
||||
private static native void nGetBoundingBox(long nativeAsset, float[] box);
|
||||
private static native String nGetName(long nativeAsset, int entity);
|
||||
private static native String nGetExtras(long nativeAsset, int entity);
|
||||
private static native long nGetAnimator(long nativeAsset);
|
||||
private static native int nGetResourceUriCount(long nativeAsset);
|
||||
private static native void nGetResourceUris(long nativeAsset, String[] result);
|
||||
|
||||
@@ -28,10 +28,12 @@ import com.google.android.filament.Entity;
|
||||
* @see AssetLoader
|
||||
*/
|
||||
public class FilamentInstance {
|
||||
private FilamentAsset mAsset;
|
||||
private long mNativeObject;
|
||||
private Animator mAnimator;
|
||||
|
||||
FilamentInstance(long nativeObject) {
|
||||
FilamentInstance(FilamentAsset asset, long nativeObject) {
|
||||
mAsset = asset;
|
||||
mNativeObject = nativeObject;
|
||||
mAnimator = null;
|
||||
}
|
||||
@@ -46,6 +48,11 @@ public class FilamentInstance {
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public @NonNull FilamentAsset getAsset() {
|
||||
return mAsset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transform root for the asset, which has no matching glTF node.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,36 +16,108 @@
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import com.google.android.filament.Engine;
|
||||
import com.google.android.filament.MaterialInstance;
|
||||
import com.google.android.filament.Material;
|
||||
import com.google.android.filament.VertexBuffer;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.Size;
|
||||
|
||||
/**
|
||||
* Loads pre-generated ubershader materials that fulfill glTF requirements.
|
||||
*
|
||||
* <p>This class is used by {@link AssetLoader} to create Filament materials.
|
||||
* Client applications do not need to call methods on it.</p>
|
||||
*/
|
||||
public class MaterialProvider {
|
||||
private long mNativeObject;
|
||||
public interface MaterialProvider {
|
||||
|
||||
/**
|
||||
* Constructs an ubershader loader using the supplied {@link Engine}.
|
||||
*
|
||||
* @param engine the engine used to create materials
|
||||
* MaterialKey specifies the requirements for a requested glTF material.
|
||||
* The provider creates Filament materials that fulfill these requirements.
|
||||
*/
|
||||
public MaterialProvider(Engine engine) {
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
mNativeObject = nCreateMaterialProvider(nativeEngine);
|
||||
}
|
||||
public static class MaterialKey {
|
||||
public boolean doubleSided;
|
||||
public boolean unlit;
|
||||
public boolean hasVertexColors;
|
||||
public boolean hasBaseColorTexture;
|
||||
public boolean hasNormalTexture;
|
||||
public boolean hasOcclusionTexture;
|
||||
public boolean hasEmissiveTexture;
|
||||
public boolean useSpecularGlossiness;
|
||||
public int alphaMode; // 0 = OPAQUE, 1 = MASK, 2 = BLEND
|
||||
public boolean enableDiagnostics;
|
||||
public boolean hasMetallicRoughnessTexture; // piggybacks with specularRoughness
|
||||
public int metallicRoughnessUV; // piggybacks with specularRoughness
|
||||
public int baseColorUV;
|
||||
public boolean hasClearCoatTexture;
|
||||
public int clearCoatUV;
|
||||
public boolean hasClearCoatRoughnessTexture;
|
||||
public int clearCoatRoughnessUV;
|
||||
public boolean hasClearCoatNormalTexture;
|
||||
public int clearCoatNormalUV;
|
||||
public boolean hasClearCoat;
|
||||
public boolean hasTransmission;
|
||||
public boolean hasTextureTransforms;
|
||||
public int emissiveUV;
|
||||
public int aoUV;
|
||||
public int normalUV;
|
||||
public boolean hasTransmissionTexture;
|
||||
public int transmissionUV;
|
||||
public boolean hasSheenColorTexture;
|
||||
public int sheenColorUV;
|
||||
public boolean hasSheenRoughnessTexture;
|
||||
public int sheenRoughnessUV;
|
||||
public boolean hasVolumeThicknessTexture;
|
||||
public int volumeThicknessUV;
|
||||
public boolean hasSheen;
|
||||
public boolean hasIOR;
|
||||
|
||||
public MaterialKey() {}
|
||||
static {
|
||||
nGlobalInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate UV map according to the material key, altering latter if required.
|
||||
*
|
||||
* Filament supports up to 2 UV sets. glTF has arbitrary texcoord set indices, but it
|
||||
* allows implementations to support only 2 simultaneous sets. Here we build a mapping
|
||||
* table with 1-based indices where 0 means unused. Note that the order in which we drop
|
||||
* textures can affect the look of certain assets. This "order of degradation" is
|
||||
* stipulated by the glTF 2.0 specification.
|
||||
*
|
||||
* @param uvmap Output argument that gets populated with a small table that maps from a
|
||||
* glTF uv index to a Filament uv index (0 = UNUSED, 1 = UV0, 2 = UV1).
|
||||
*/
|
||||
public void constrainMaterial(@NonNull @Size(min = 8) int[] uvmap) {
|
||||
nConstrainMaterial(this, uvmap);
|
||||
}
|
||||
|
||||
private static native void nGlobalInit();
|
||||
private static native void nConstrainMaterial(MaterialKey materialKey, int[] uvmap);
|
||||
};
|
||||
|
||||
/**
|
||||
* Frees memory associated with the native material provider.
|
||||
* */
|
||||
public void destroy() {
|
||||
nDestroyMaterialProvider(mNativeObject);
|
||||
mNativeObject = 0;
|
||||
}
|
||||
* Creates or fetches a compiled Filament material, then creates an instance from it.
|
||||
*
|
||||
* @param config Specifies requirements; might be mutated due to resource constraints.
|
||||
* @param uvmap Output argument that gets populated with a small table that maps from a glTF uv
|
||||
* index to a Filament uv index (0 = UNUSED, 1 = UV0, 2 = UV1).
|
||||
* @param label Optional tag that is not a part of the cache key.
|
||||
*/
|
||||
public @Nullable MaterialInstance createMaterialInstance(MaterialKey config,
|
||||
@NonNull @Size(min = 8) int[] uvmap, @Nullable String label);
|
||||
|
||||
/**
|
||||
* Creates and returns an array containing all cached materials.
|
||||
*/
|
||||
public @NonNull Material[] getMaterials();
|
||||
|
||||
/**
|
||||
* Returns true if the presence of the given vertex attribute is required.
|
||||
*
|
||||
* Some types of providers (e.g. ubershader) require dummy attribute values
|
||||
* if the glTF model does not provide them.
|
||||
*
|
||||
* NOTE: The given attribute is the VertexAttribute enum casted to an integer.
|
||||
* This is done to streamline the JNI work between Java and Native layers.
|
||||
*/
|
||||
public boolean needsDummyData(int attrib);
|
||||
|
||||
/**
|
||||
* Destroys all cached materials.
|
||||
@@ -53,15 +125,5 @@ public class MaterialProvider {
|
||||
* This is not called automatically when MaterialProvider is destroyed, which allows
|
||||
* clients to take ownership of the cache if desired.
|
||||
*/
|
||||
public void destroyMaterials() {
|
||||
nDestroyMaterials(mNativeObject);
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
private static native long nCreateMaterialProvider(long nativeEngine);
|
||||
private static native void nDestroyMaterialProvider(long nativeProvider);
|
||||
private static native void nDestroyMaterials(long nativeProvider);
|
||||
public void destroyMaterials();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import com.google.android.filament.Engine;
|
||||
import com.google.android.filament.MaterialInstance;
|
||||
import com.google.android.filament.Material;
|
||||
import com.google.android.filament.VertexBuffer;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.Size;
|
||||
|
||||
/**
|
||||
* Loads pre-generated ubershader materials that fulfill glTF requirements.
|
||||
*
|
||||
* <p>This class is used by {@link AssetLoader} to create Filament materials.
|
||||
* Client applications do not need to call methods on it.</p>
|
||||
*/
|
||||
public class UbershaderLoader implements MaterialProvider {
|
||||
private long mNativeObject;
|
||||
|
||||
/**
|
||||
* Constructs an ubershader loader using the supplied {@link Engine}.
|
||||
*
|
||||
* @param engine the engine used to create materials
|
||||
*/
|
||||
public UbershaderLoader(Engine engine) {
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
mNativeObject = nCreateUbershaderLoader(nativeEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees memory associated with the native material provider.
|
||||
* */
|
||||
public void destroy() {
|
||||
nDestroyUbershaderLoader(mNativeObject);
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
public @Nullable MaterialInstance createMaterialInstance(MaterialKey config,
|
||||
@NonNull @Size(min = 8) int[] uvmap, @Nullable String label) {
|
||||
long nativeMaterialInstance = nCreateMaterialInstance(mNativeObject, config, uvmap, label);
|
||||
return nativeMaterialInstance == 0 ? null : new MaterialInstance(null, nativeMaterialInstance);
|
||||
}
|
||||
|
||||
public @NonNull Material[] getMaterials() {
|
||||
final int count = nGetMaterialCount(mNativeObject);
|
||||
Material[] result = new Material[count];
|
||||
long[] natives = new long[count];
|
||||
nGetMaterials(mNativeObject, natives);
|
||||
for (int i = 0; i < count; i++) {
|
||||
result[i] = new Material(natives[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean needsDummyData(int attrib) {
|
||||
VertexBuffer.VertexAttribute vattrib = VertexBuffer.VertexAttribute.values()[attrib];
|
||||
switch (vattrib) {
|
||||
case UV0:
|
||||
case UV1:
|
||||
case COLOR:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void destroyMaterials() {
|
||||
nDestroyMaterials(mNativeObject);
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
private static native long nCreateUbershaderLoader(long nativeEngine);
|
||||
private static native void nDestroyUbershaderLoader(long nativeProvider);
|
||||
private static native void nDestroyMaterials(long nativeProvider);
|
||||
private static native long nCreateMaterialInstance(long nativeProvider, MaterialKey config, int[] uvmap, String label);
|
||||
private static native int nGetMaterialCount(long nativeProvider);
|
||||
private static native void nGetMaterials(long nativeProvider, long[] result);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
GROUP=com.google.android.filament
|
||||
VERSION_NAME=1.10.2
|
||||
VERSION_NAME=1.14.2
|
||||
|
||||
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
|
||||
|
||||
@@ -18,3 +18,11 @@ POM_DEVELOPER_NAME=Filament Team
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
android.useAndroidX=true
|
||||
|
||||
org.gradle.unsafe.configuration-cache=true
|
||||
# TODO: Remove this when we switch to Gradle 7.4
|
||||
org.gradle.unsafe.configuration-cache.max-problems=3
|
||||
|
||||
com.google.android.filament.tools-dir=../../../out/release/filament
|
||||
com.google.android.filament.dist-dir=../out/android-release/filament
|
||||
com.google.android.filament.abis=all
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#Wed Nov 17 10:40:18 PST 2021
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -10,6 +12,7 @@ filamentTools {
|
||||
iblOutputDir = project.layout.projectDirectory.dir("src/main/assets/envs")
|
||||
}
|
||||
|
||||
// don't forget to update MainACtivity.kt when/if changing this.
|
||||
task copyMesh(type: Copy) {
|
||||
from "../../../third_party/models/BusterDrone"
|
||||
into "src/main/assets/models"
|
||||
@@ -29,6 +32,11 @@ android {
|
||||
targetSdkVersion versions.targetSdk
|
||||
missingDimensionStrategy 'functionality', 'full'
|
||||
}
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -36,5 +44,5 @@ dependencies {
|
||||
implementation project(':filament-android')
|
||||
implementation project(':gltfio-android')
|
||||
implementation project(':filament-utils-android')
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
android:supportsRtl="true"
|
||||
android:largeHeap="true"
|
||||
android:theme="@android:style/Theme.NoTitleBar">
|
||||
<activity android:name="com.google.android.filament.gltf.MainActivity"
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name="com.google.android.filament.gltf.MainActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden">
|
||||
<intent-filter>
|
||||
|
||||
@@ -24,8 +24,10 @@ import android.view.*
|
||||
import android.view.GestureDetector
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.google.android.filament.Fence
|
||||
import com.google.android.filament.IndirectLight
|
||||
import com.google.android.filament.Skybox
|
||||
import com.google.android.filament.View
|
||||
import com.google.android.filament.utils.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -59,6 +61,9 @@ class MainActivity : Activity() {
|
||||
private var statusText: String? = null
|
||||
private var latestDownload: String? = null
|
||||
private val automation = AutomationEngine()
|
||||
private var loadStartTime = 0L
|
||||
private var loadStartFence: Fence? = null
|
||||
private val viewerContent = AutomationEngine.ViewerContent()
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -73,6 +78,11 @@ class MainActivity : Activity() {
|
||||
doubleTapDetector = GestureDetector(applicationContext, doubleTapListener)
|
||||
|
||||
modelViewer = ModelViewer(surfaceView)
|
||||
viewerContent.view = modelViewer.view
|
||||
viewerContent.sunlight = modelViewer.light
|
||||
viewerContent.lightManager = modelViewer.engine.lightManager
|
||||
viewerContent.scene = modelViewer.scene
|
||||
viewerContent.renderer = modelViewer.renderer
|
||||
|
||||
surfaceView.setOnTouchListener { _, event ->
|
||||
modelViewer.onTouchEvent(event)
|
||||
@@ -80,20 +90,42 @@ class MainActivity : Activity() {
|
||||
true
|
||||
}
|
||||
|
||||
createRenderables()
|
||||
createDefaultRenderables()
|
||||
createIndirectLight()
|
||||
|
||||
setStatusText("To load a new model, go to the above URL on your host machine.")
|
||||
|
||||
val view = modelViewer.view
|
||||
|
||||
/*
|
||||
* Note: The settings below are overriden when connecting to the remote UI.
|
||||
*/
|
||||
|
||||
// on mobile, better use lower quality color buffer
|
||||
view.renderQuality = view.renderQuality.apply {
|
||||
hdrColorBuffer = View.QualityLevel.MEDIUM
|
||||
}
|
||||
|
||||
// dynamic resolution often helps a lot
|
||||
view.dynamicResolutionOptions = view.dynamicResolutionOptions.apply {
|
||||
enabled = true
|
||||
quality = View.QualityLevel.MEDIUM
|
||||
}
|
||||
|
||||
// MSAA is needed with dynamic resolution MEDIUM
|
||||
view.multiSampleAntiAliasingOptions = view.multiSampleAntiAliasingOptions.apply {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
// FXAA is pretty cheap and helps a lot
|
||||
view.antiAliasing = View.AntiAliasing.FXAA;
|
||||
|
||||
// ambient occlusion is the cheapest effect that adds a lot of quality
|
||||
view.ambientOcclusionOptions = view.ambientOcclusionOptions.apply {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
// bloom is pretty expensive but adds a fair amount of realism
|
||||
view.bloomOptions = view.bloomOptions.apply {
|
||||
enabled = true
|
||||
}
|
||||
@@ -101,7 +133,7 @@ class MainActivity : Activity() {
|
||||
remoteServer = RemoteServer(8082)
|
||||
}
|
||||
|
||||
private fun createRenderables() {
|
||||
private fun createDefaultRenderables() {
|
||||
val buffer = assets.open("models/scene.gltf").use { input ->
|
||||
val bytes = ByteArray(input.available())
|
||||
input.read(bytes)
|
||||
@@ -109,7 +141,7 @@ class MainActivity : Activity() {
|
||||
}
|
||||
|
||||
modelViewer.loadModelGltfAsync(buffer) { uri -> readCompressedAsset("models/$uri") }
|
||||
modelViewer.transformToUnitCube()
|
||||
updateRootTransform()
|
||||
}
|
||||
|
||||
private fun createIndirectLight() {
|
||||
@@ -119,6 +151,7 @@ class MainActivity : Activity() {
|
||||
readCompressedAsset("envs/$ibl/${ibl}_ibl.ktx").let {
|
||||
scene.indirectLight = KTXLoader.createIndirectLight(engine, it)
|
||||
scene.indirectLight!!.intensity = 30_000.0f
|
||||
viewerContent.indirectLight = modelViewer.scene.indirectLight
|
||||
}
|
||||
readCompressedAsset("envs/$ibl/${ibl}_skybox.ktx").let {
|
||||
scene.skybox = KTXLoader.createSkybox(engine, it)
|
||||
@@ -154,7 +187,9 @@ class MainActivity : Activity() {
|
||||
withContext(Dispatchers.Main) {
|
||||
modelViewer.destroyModel()
|
||||
modelViewer.loadModelGlb(message.buffer)
|
||||
modelViewer.transformToUnitCube()
|
||||
updateRootTransform()
|
||||
loadStartTime = System.nanoTime()
|
||||
loadStartFence = modelViewer.engine.createFence()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,6 +217,10 @@ class MainActivity : Activity() {
|
||||
|
||||
val sky = Skybox.Builder().environment(skyboxTexture).build(engine)
|
||||
|
||||
specularFilter.destroy();
|
||||
equirectToCubemap.destroy();
|
||||
context.destroy();
|
||||
|
||||
modelViewer.scene.skybox = sky
|
||||
modelViewer.scene.indirectLight = ibl
|
||||
}
|
||||
@@ -272,7 +311,9 @@ class MainActivity : Activity() {
|
||||
pathToBufferMapping[path]
|
||||
}
|
||||
}
|
||||
modelViewer.transformToUnitCube()
|
||||
updateRootTransform()
|
||||
loadStartTime = System.nanoTime()
|
||||
loadStartFence = modelViewer.engine.createFence()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,11 +350,19 @@ class MainActivity : Activity() {
|
||||
|
||||
fun loadSettings(message: RemoteServer.ReceivedMessage) {
|
||||
val json = StandardCharsets.UTF_8.decode(message.buffer).toString()
|
||||
automation.applySettings(json, modelViewer.view, null,
|
||||
modelViewer.scene.indirectLight, modelViewer.light, modelViewer.engine.lightManager,
|
||||
modelViewer.scene, modelViewer.renderer)
|
||||
modelViewer.view.colorGrading = automation.getColorGrading((modelViewer.engine))
|
||||
viewerContent.assetLights = modelViewer.asset?.lightEntities
|
||||
automation.applySettings(json, viewerContent)
|
||||
modelViewer.view.colorGrading = automation.getColorGrading(modelViewer.engine)
|
||||
modelViewer.cameraFocalLength = automation.viewerOptions.cameraFocalLength
|
||||
updateRootTransform()
|
||||
}
|
||||
|
||||
private fun updateRootTransform() {
|
||||
if (automation.viewerOptions.autoScaleEnabled) {
|
||||
modelViewer.transformToUnitCube()
|
||||
} else {
|
||||
modelViewer.clearRootTransform()
|
||||
}
|
||||
}
|
||||
|
||||
inner class FrameCallback : Choreographer.FrameCallback {
|
||||
@@ -321,6 +370,16 @@ class MainActivity : Activity() {
|
||||
override fun doFrame(frameTimeNanos: Long) {
|
||||
choreographer.postFrameCallback(this)
|
||||
|
||||
loadStartFence?.let {
|
||||
if (it.wait(Fence.Mode.FLUSH, 0) == Fence.FenceStatus.CONDITION_SATISFIED) {
|
||||
val end = System.nanoTime()
|
||||
val total = (end - loadStartTime) / 1_000_000
|
||||
Log.i(TAG, "The Filament backend took $total ms to load the model geometry.")
|
||||
modelViewer.engine.destroyFence(it)
|
||||
loadStartFence = null
|
||||
}
|
||||
}
|
||||
|
||||
modelViewer.animator?.apply {
|
||||
if (animationCount > 0) {
|
||||
val elapsedTimeSeconds = (frameTimeNanos - startTime).toDouble() / 1_000_000_000
|
||||
@@ -354,11 +413,11 @@ class MainActivity : Activity() {
|
||||
}
|
||||
}
|
||||
|
||||
// Just for testing purposes, this releases the model and reloads it.
|
||||
// Just for testing purposes, this releases the current model and reloads the default model.
|
||||
inner class DoubleTapListener : GestureDetector.SimpleOnGestureListener() {
|
||||
override fun onDoubleTap(e: MotionEvent?): Boolean {
|
||||
modelViewer.destroyModel()
|
||||
createRenderables()
|
||||
createDefaultRenderables()
|
||||
return super.onDoubleTap(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -17,10 +19,16 @@ android {
|
||||
compileSdkVersion versions.compileSdk
|
||||
defaultConfig {
|
||||
applicationId "com.google.android.filament.hellocamera"
|
||||
minSdkVersion versions.minSdk
|
||||
minSdkVersion 23
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -33,7 +33,9 @@ import android.graphics.ImageFormat
|
||||
import android.hardware.HardwareBuffer
|
||||
import android.media.ImageReader
|
||||
import android.opengl.Matrix
|
||||
import android.view.Display
|
||||
import android.os.Build
|
||||
import android.os.Looper
|
||||
import androidx.annotation.RequiresApi
|
||||
|
||||
import com.google.android.filament.*
|
||||
|
||||
@@ -44,7 +46,7 @@ import java.util.concurrent.TimeUnit
|
||||
* Toy class that handles all interaction with the Android camera2 API.
|
||||
* Sets the "textureTransform" and "videoTexture" parameters on the given Filament material.
|
||||
*/
|
||||
class CameraHelper(val activity: Activity, private val filamentEngine: Engine, private val filamentMaterial: MaterialInstance, private val display: Display) {
|
||||
class CameraHelper(val activity: Activity, private val filamentEngine: Engine, private val filamentMaterial: MaterialInstance) {
|
||||
private lateinit var cameraId: String
|
||||
private lateinit var captureRequest: CaptureRequest
|
||||
|
||||
@@ -63,6 +65,20 @@ class CameraHelper(val activity: Activity, private val filamentEngine: Engine, p
|
||||
kImageReaderMaxImages,
|
||||
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE)
|
||||
|
||||
@Suppress("deprecation")
|
||||
private val display = if (Build.VERSION.SDK_INT >= 30) {
|
||||
Api30Impl.getDisplay(activity)
|
||||
} else {
|
||||
activity.windowManager.defaultDisplay!!
|
||||
}
|
||||
|
||||
@RequiresApi(30)
|
||||
class Api30Impl {
|
||||
companion object {
|
||||
fun getDisplay(context: Context) = context.display!!
|
||||
}
|
||||
}
|
||||
|
||||
private val cameraCallback = object : CameraDevice.StateCallback() {
|
||||
override fun onOpened(cameraDevice: CameraDevice) {
|
||||
cameraOpenCloseLock.release()
|
||||
@@ -87,7 +103,9 @@ class CameraHelper(val activity: Activity, private val filamentEngine: Engine, p
|
||||
val stream = filamentStream
|
||||
if (stream != null) {
|
||||
imageReader.acquireLatestImage()?.also {
|
||||
stream.setAcquiredImage(it.hardwareBuffer, Handler()) { it.close() }
|
||||
stream.setAcquiredImage(it.hardwareBuffer, Handler(Looper.getMainLooper())) {
|
||||
it.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class MainActivity : Activity(), ActivityCompat.OnRequestPermissionsResultCallba
|
||||
setupView()
|
||||
setupScene()
|
||||
|
||||
cameraHelper = CameraHelper(this, engine, materialInstance, windowManager.defaultDisplay)
|
||||
cameraHelper = CameraHelper(this, engine, materialInstance)
|
||||
cameraHelper.openCamera()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -21,6 +23,12 @@ android {
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -27,6 +29,12 @@ android {
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -20,6 +22,12 @@ android {
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -10,9 +10,16 @@ android {
|
||||
minSdkVersion versions.minSdk
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation deps.kotlin
|
||||
implementation deps.androidx.annotations
|
||||
implementation project(':filament-android')
|
||||
}
|
||||
|
||||
@@ -18,19 +18,21 @@ package com.google.android.filament.livewallpaper
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.PixelFormat
|
||||
import android.os.Build
|
||||
import android.service.wallpaper.WallpaperService
|
||||
import android.view.Choreographer
|
||||
import android.view.Surface
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.WindowManager
|
||||
import android.view.animation.LinearInterpolator
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.google.android.filament.*
|
||||
import com.google.android.filament.android.DisplayHelper
|
||||
import com.google.android.filament.android.UiHelper
|
||||
|
||||
|
||||
class FilamentLiveWallpaper : WallpaperService() {
|
||||
// Make sure to initialize Filament first
|
||||
// This loads the JNI library needed by most API calls
|
||||
@@ -196,9 +198,14 @@ class FilamentLiveWallpaper : WallpaperService() {
|
||||
override fun onNativeWindowChanged(surface: Surface) {
|
||||
swapChain?.let { engine.destroySwapChain(it) }
|
||||
swapChain = engine.createSwapChain(surface)
|
||||
val display =
|
||||
(application.getSystemService(Service.WINDOW_SERVICE) as WindowManager)
|
||||
.defaultDisplay
|
||||
|
||||
@Suppress("deprecation")
|
||||
val display = if (Build.VERSION.SDK_INT >= 30) {
|
||||
Api30Impl.getDisplay(displayContext!!)
|
||||
} else {
|
||||
(getSystemService(Service.WINDOW_SERVICE) as WindowManager).defaultDisplay
|
||||
}
|
||||
|
||||
displayHelper.attach(renderer, display)
|
||||
}
|
||||
|
||||
@@ -222,4 +229,11 @@ class FilamentLiveWallpaper : WallpaperService() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(30)
|
||||
class Api30Impl {
|
||||
companion object {
|
||||
fun getDisplay(context: Context) = context.display!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -31,6 +33,12 @@ android {
|
||||
missingDimensionStrategy 'functionality', 'full'
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -20,6 +22,12 @@ android {
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -22,6 +25,12 @@ android {
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
@@ -31,5 +40,5 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation project(':filament-android')
|
||||
implementation 'androidx.annotation:annotation:1.1.0'
|
||||
implementation deps.androidx.annotations
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -70,11 +70,11 @@ public class MainActivity extends Activity
|
||||
private Page mPage;
|
||||
private PageMaterials mPageMaterials;
|
||||
private Scene mScene;
|
||||
private Texture[] mTextures = new Texture[2];
|
||||
private final Texture[] mTextures = new Texture[2];
|
||||
private @Entity int mLight;
|
||||
private IndirectLight mIndirectLight;
|
||||
|
||||
private float[] mTouchDownPoint = new float[2];
|
||||
private final float[] mTouchDownPoint = new float[2];
|
||||
private float mTouchDownValue = 0;
|
||||
private float mPageAnimationRadians = 0;
|
||||
private float mPageAnimationValue = 0;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: FilamentToolsPlugin
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'filament-tools-plugin'
|
||||
}
|
||||
|
||||
project.ext.isSample = true
|
||||
|
||||
@@ -17,10 +19,16 @@ android {
|
||||
compileSdkVersion versions.compileSdk
|
||||
defaultConfig {
|
||||
applicationId "com.google.android.filament.streamtest"
|
||||
minSdkVersion versions.minSdk
|
||||
minSdkVersion 23
|
||||
targetSdkVersion versions.targetSdk
|
||||
}
|
||||
|
||||
// NOTE: This is a workaround required because the AGP task collectReleaseDependencies
|
||||
// is not configuration-cache friendly yet; this is only useful for Play publication
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user