Compare commits
731 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a82d93914e | ||
|
|
389349198f | ||
|
|
225a844e0f | ||
|
|
f018c719a6 | ||
|
|
2a229571ad | ||
|
|
35959b547c | ||
|
|
796007377d | ||
|
|
5c73d0ae75 | ||
|
|
bb90103e74 | ||
|
|
0149bc504d | ||
|
|
3db035520b | ||
|
|
618b59932c | ||
|
|
9ef05ad456 | ||
|
|
c8a0dbb59a | ||
|
|
35a0b045f8 | ||
|
|
a4369c833d | ||
|
|
354f1da708 | ||
|
|
7e47d257d1 | ||
|
|
c3d2b3578d | ||
|
|
783aa06a46 | ||
|
|
faa82ff35a | ||
|
|
3008123d6b | ||
|
|
2d2987066d | ||
|
|
c84ec04efa | ||
|
|
197b45c1d1 | ||
|
|
af9ecf0a61 | ||
|
|
530fb58337 | ||
|
|
6a891021b1 | ||
|
|
0e7c68b50d | ||
|
|
32a32d3d21 | ||
|
|
fca71813d4 | ||
|
|
3618f14531 | ||
|
|
9de3e76a53 | ||
|
|
e472fdbce4 | ||
|
|
c9fcedb40b | ||
|
|
bd8c3e9181 | ||
|
|
26d0aa76f8 | ||
|
|
20f4ec6576 | ||
|
|
d0bc23473c | ||
|
|
c33f6adf62 | ||
|
|
d4efa105b7 | ||
|
|
e8641ce257 | ||
|
|
d7a4bdc3f1 | ||
|
|
e66215295c | ||
|
|
552bb3e6db | ||
|
|
a96da05ab8 | ||
|
|
fb5ee4a9d0 | ||
|
|
da13067b57 | ||
|
|
d48d69c765 | ||
|
|
5098b2af77 | ||
|
|
5576d6b014 | ||
|
|
b072399229 | ||
|
|
4f0ab43d58 | ||
|
|
3f742880b5 | ||
|
|
0704194460 | ||
|
|
56e747f558 | ||
|
|
61c22f2295 | ||
|
|
c4bbaeda86 | ||
|
|
678ffc7503 | ||
|
|
a080a47268 | ||
|
|
82e8104539 | ||
|
|
11bd8e72ef | ||
|
|
03c2a90206 | ||
|
|
c38ab64b6a | ||
|
|
2548da9aed | ||
|
|
2fa08123a0 | ||
|
|
20c3d45b9c | ||
|
|
c8af3226de | ||
|
|
4b669fb1c7 | ||
|
|
340f6d721a | ||
|
|
489f3ff3c9 | ||
|
|
566d3613d1 | ||
|
|
e691cfa9e3 | ||
|
|
a4a1bf07aa | ||
|
|
7ea7d1d5f2 | ||
|
|
686c68c627 | ||
|
|
c652dcfd2a | ||
|
|
01fab5a6e4 | ||
|
|
16a5adcfde | ||
|
|
d550d36637 | ||
|
|
3857c1a9b2 | ||
|
|
2f8bc9239b | ||
|
|
9de934e2bd | ||
|
|
769f1db011 | ||
|
|
da72c58146 | ||
|
|
ef34dd2461 | ||
|
|
90fdb95429 | ||
|
|
d5c0d11404 | ||
|
|
b0d116632c | ||
|
|
a67d92c2ca | ||
|
|
21b208398b | ||
|
|
65b3e956df | ||
|
|
c8d0715b16 | ||
|
|
16d307e543 | ||
|
|
5ed07639af | ||
|
|
e2655e93bc | ||
|
|
3a20be1d1a | ||
|
|
8244f8e9cb | ||
|
|
c575fd7395 | ||
|
|
6a67cf0009 | ||
|
|
79292481b3 | ||
|
|
829f341de3 | ||
|
|
b509ef4dad | ||
|
|
422c8d9a64 | ||
|
|
d0b5c5cee8 | ||
|
|
9b9548306d | ||
|
|
b28e535540 | ||
|
|
1f7584ace2 | ||
|
|
21512e8228 | ||
|
|
a34903aa33 | ||
|
|
4eba402adb | ||
|
|
64c5f5aee7 | ||
|
|
1bda37776b | ||
|
|
1c5d7d6cc3 | ||
|
|
b81ff060ae | ||
|
|
0cebbfca23 | ||
|
|
b9c7814dfd | ||
|
|
ba9fd6719a | ||
|
|
f0ad12ce2e | ||
|
|
21acf53d3f | ||
|
|
2f5927d531 | ||
|
|
cf950a8d6f | ||
|
|
48b73ad998 | ||
|
|
8fc94f127b | ||
|
|
ce33f42e62 | ||
|
|
61032e55b5 | ||
|
|
6160d3f51e | ||
|
|
5d725f6de9 | ||
|
|
020e9e59ed | ||
|
|
bd777c1e56 | ||
|
|
087b12c802 | ||
|
|
42f2642d72 | ||
|
|
9c8d0ed5a1 | ||
|
|
9fd1705acf | ||
|
|
c981b52832 | ||
|
|
d074b6fd1a | ||
|
|
7da5a25e2f | ||
|
|
b96b8eb787 | ||
|
|
a25be5ee6e | ||
|
|
bf9d1f1967 | ||
|
|
561221fdc3 | ||
|
|
8548afa231 | ||
|
|
803e695d5c | ||
|
|
5c58776313 | ||
|
|
0db39ea08a | ||
|
|
d76fb5d7e5 | ||
|
|
f37ab8158c | ||
|
|
33db5acd13 | ||
|
|
e068204876 | ||
|
|
d849231caf | ||
|
|
996bd58fcb | ||
|
|
9b70dc5253 | ||
|
|
31af9ca80f | ||
|
|
08aa2ec4ca | ||
|
|
95be2e24ce | ||
|
|
7b200ec85e | ||
|
|
cf1b45c052 | ||
|
|
57e7280ac9 | ||
|
|
64d432cb34 | ||
|
|
fde23c89e2 | ||
|
|
0e3bc8a443 | ||
|
|
88bcd133f2 | ||
|
|
2072b67e04 | ||
|
|
2a2974580c | ||
|
|
65f72a48fb | ||
|
|
65674c7c51 | ||
|
|
8d1b630b24 | ||
|
|
1235a66f83 | ||
|
|
411e7f4511 | ||
|
|
cf095cbdd2 | ||
|
|
394db90ec9 | ||
|
|
72644f1416 | ||
|
|
ed2fc0e391 | ||
|
|
c9f4d983a0 | ||
|
|
694db54d9d | ||
|
|
15b663ba0b | ||
|
|
23ee5e276c | ||
|
|
7c24a1bbaa | ||
|
|
32eee2cdf1 | ||
|
|
7dbad8928f | ||
|
|
0e81207758 | ||
|
|
c67266833a | ||
|
|
d6b0b6ff52 | ||
|
|
9d0ad3586d | ||
|
|
7393d5d98c | ||
|
|
7a819a60ae | ||
|
|
c735659592 | ||
|
|
c36745db97 | ||
|
|
a5284af2b8 | ||
|
|
4989c3dc48 | ||
|
|
3925b0a8ec | ||
|
|
356610ba1d | ||
|
|
9eae72f99d | ||
|
|
1d12fc1aaa | ||
|
|
f9bd085757 | ||
|
|
1003926665 | ||
|
|
709180932e | ||
|
|
132326f8f2 | ||
|
|
92e86de630 | ||
|
|
3e8a145fce | ||
|
|
a5db6a84b6 | ||
|
|
f192b89ef9 | ||
|
|
637395b075 | ||
|
|
b03172f4a2 | ||
|
|
24225315fa | ||
|
|
2bc9256a7a | ||
|
|
264cf020b6 | ||
|
|
ceafc7835b | ||
|
|
db8d4ee076 | ||
|
|
26f7907b17 | ||
|
|
c35f1e0b29 | ||
|
|
e2ee00e36e | ||
|
|
d87f77c41a | ||
|
|
13fcce2d9a | ||
|
|
216761656f | ||
|
|
05e9d708ed | ||
|
|
cc321385cd | ||
|
|
038d39f294 | ||
|
|
3555a01541 | ||
|
|
5d52266eac | ||
|
|
5368756983 | ||
|
|
f74e136f46 | ||
|
|
040c1c686a | ||
|
|
e74c33ce04 | ||
|
|
ab24634637 | ||
|
|
8f3bdc20ba | ||
|
|
74aaaed4db | ||
|
|
9c64c20ceb | ||
|
|
b92c748fcc | ||
|
|
844dde4e6d | ||
|
|
c0de0ca36d | ||
|
|
ad3bc4a6f7 | ||
|
|
572b2cff57 | ||
|
|
fb9cf43768 | ||
|
|
f41db8bb91 | ||
|
|
89c8e7c51a | ||
|
|
0ad21cd47a | ||
|
|
7dbf81fe3d | ||
|
|
3072309574 | ||
|
|
573e9220a2 | ||
|
|
e22f02d228 | ||
|
|
b620b7efa1 | ||
|
|
d1593326cb | ||
|
|
6a8e6d45b5 | ||
|
|
11336964a1 | ||
|
|
71e98d54f5 | ||
|
|
417ba87fcb | ||
|
|
f71fea4ef5 | ||
|
|
dc062305b9 | ||
|
|
bc94269e73 | ||
|
|
876534330a | ||
|
|
2af8ef81b3 | ||
|
|
8da553db58 | ||
|
|
83e9857b30 | ||
|
|
088ed2d472 | ||
|
|
c826b03411 | ||
|
|
f1257994d1 | ||
|
|
efb9e005b2 | ||
|
|
6f30ff31c8 | ||
|
|
d0f38c2d5d | ||
|
|
d4943cc70b | ||
|
|
9a47ea1ef0 | ||
|
|
ac33331fd6 | ||
|
|
a65998bbc1 | ||
|
|
5120c18977 | ||
|
|
21347eaa88 | ||
|
|
a191cc8171 | ||
|
|
ad3d823fa3 | ||
|
|
8d7c00b0d9 | ||
|
|
99d9ea73ac | ||
|
|
c4b0edbfe3 | ||
|
|
6d74d31ecd | ||
|
|
bd22bed2fb | ||
|
|
f8aa17c245 | ||
|
|
6ba20f29d4 | ||
|
|
95ef8d85db | ||
|
|
eca381a5be | ||
|
|
ea47f0bd87 | ||
|
|
b849008ce5 | ||
|
|
5389ac963f | ||
|
|
0fd16d760a | ||
|
|
6754e80c75 | ||
|
|
fb95d8e7a4 | ||
|
|
40efd5fd23 | ||
|
|
d440775775 | ||
|
|
e1d9f26dbd | ||
|
|
ee048d259f | ||
|
|
d7e5f2c26b | ||
|
|
c11a61aa15 | ||
|
|
b859b57797 | ||
|
|
76cca21c65 | ||
|
|
a09c3b154a | ||
|
|
2460f9e721 | ||
|
|
d30429e891 | ||
|
|
c23c3d48b2 | ||
|
|
046809cee0 | ||
|
|
c9750dd633 | ||
|
|
18a0bd70fb | ||
|
|
38955a91e5 | ||
|
|
eac2ad7e05 | ||
|
|
5df53f733e | ||
|
|
50abcf6bfa | ||
|
|
4d41b83448 | ||
|
|
d2324d253c | ||
|
|
cf9e87a892 | ||
|
|
829db244f2 | ||
|
|
772af1e897 | ||
|
|
52a8f50539 | ||
|
|
9f1cadf77a | ||
|
|
308935d706 | ||
|
|
67f75f0ecf | ||
|
|
f728776714 | ||
|
|
10259f80f4 | ||
|
|
c65239aec2 | ||
|
|
0bd9515b3d | ||
|
|
442315aaa8 | ||
|
|
614a7d6de8 | ||
|
|
d28189c173 | ||
|
|
dc75c10014 | ||
|
|
91ff1d87eb | ||
|
|
6b415273ba | ||
|
|
4ce2a03f64 | ||
|
|
f67a71d849 | ||
|
|
55d8d93be9 | ||
|
|
5d57dee18d | ||
|
|
1d1a0c16ba | ||
|
|
71e2434717 | ||
|
|
f876e6165f | ||
|
|
54e224e9fa | ||
|
|
8e76259bac | ||
|
|
13224d9c6e | ||
|
|
34ef2a871f | ||
|
|
6f143b1b54 | ||
|
|
46e85804b1 | ||
|
|
0fe8035309 | ||
|
|
b3feafe320 | ||
|
|
ec623e7c1b | ||
|
|
a38f2754ce | ||
|
|
932d2746f3 | ||
|
|
e176dea383 | ||
|
|
8f15964ee6 | ||
|
|
53a12c3f01 | ||
|
|
2c953b9f08 | ||
|
|
b1cdd5452f | ||
|
|
cb66324095 | ||
|
|
b16dc443ff | ||
|
|
8798d367c5 | ||
|
|
c9921cac3d | ||
|
|
485711f7c6 | ||
|
|
81df9dd705 | ||
|
|
0faa391470 | ||
|
|
cd59d6cd23 | ||
|
|
d46ba48293 | ||
|
|
7d84f97dc1 | ||
|
|
3263c46355 | ||
|
|
44c7d3ac34 | ||
|
|
7dad09dbc4 | ||
|
|
401bc4b486 | ||
|
|
2b1f9290a4 | ||
|
|
90c17ccbad | ||
|
|
f8f947addb | ||
|
|
85449a08fb | ||
|
|
115ce0cb42 | ||
|
|
edc2b49196 | ||
|
|
a47b5c21cf | ||
|
|
ada148b819 | ||
|
|
5d5d9af4df | ||
|
|
064441732e | ||
|
|
7b80b31365 | ||
|
|
b439ddc5f4 | ||
|
|
5b9351354a | ||
|
|
9bcf10cf44 | ||
|
|
ff72598b7d | ||
|
|
79aeaf3250 | ||
|
|
261dafa924 | ||
|
|
90792e7032 | ||
|
|
6e375b1bba | ||
|
|
4d7ab6547c | ||
|
|
58b7084c8b | ||
|
|
d313fe13fb | ||
|
|
4d41c9bde3 | ||
|
|
6c4157767f | ||
|
|
5cceda4155 | ||
|
|
8f45f4ec35 | ||
|
|
f3e5b46bf9 | ||
|
|
497c544f33 | ||
|
|
2e4a825fec | ||
|
|
244c83a77c | ||
|
|
41e5bb4f78 | ||
|
|
2265eca82d | ||
|
|
82c7e4d988 | ||
|
|
793198f96a | ||
|
|
f139589423 | ||
|
|
f929b6cee7 | ||
|
|
4d6f8c281a | ||
|
|
943af435aa | ||
|
|
f028af3186 | ||
|
|
b15abe9e5e | ||
|
|
5281f2a511 | ||
|
|
c2c546d671 | ||
|
|
6fc10c1dda | ||
|
|
80f3afaac6 | ||
|
|
725c978545 | ||
|
|
a9091570b7 | ||
|
|
4e8dac2680 | ||
|
|
da81e857a0 | ||
|
|
111b3320c0 | ||
|
|
665703dbd8 | ||
|
|
8170ca7cd1 | ||
|
|
2df639133b | ||
|
|
fc1d39334f | ||
|
|
af16e43830 | ||
|
|
801c5b57a5 | ||
|
|
19d7a3d21f | ||
|
|
6af77db79d | ||
|
|
efb2f9a1d8 | ||
|
|
3b3f52f48c | ||
|
|
ba5b9c733d | ||
|
|
e009dbbf96 | ||
|
|
073a6c7696 | ||
|
|
b30f6e5332 | ||
|
|
384651e21a | ||
|
|
22dcdc770f | ||
|
|
fd4d6c0d44 | ||
|
|
ca5b52b2ce | ||
|
|
cc4e9db81b | ||
|
|
2bfea16459 | ||
|
|
927662ea4d | ||
|
|
5b2dc1d3de | ||
|
|
097feb0372 | ||
|
|
9cd2971b65 | ||
|
|
fb16516480 | ||
|
|
76027cab85 | ||
|
|
64c95c615a | ||
|
|
31745f6025 | ||
|
|
2a8f04c791 | ||
|
|
3fdecfdefa | ||
|
|
26cbef7452 | ||
|
|
571a9b1ff3 | ||
|
|
b84117eb92 | ||
|
|
6af0c72d0d | ||
|
|
12fde30f31 | ||
|
|
56c2d6338e | ||
|
|
10c8ff352d | ||
|
|
53ea1a00ec | ||
|
|
62a458099a | ||
|
|
826d52bca2 | ||
|
|
299a600377 | ||
|
|
a4ebf23baa | ||
|
|
d23a703ca5 | ||
|
|
2beb9c5588 | ||
|
|
a7fc4d8fbb | ||
|
|
a5dc89b071 | ||
|
|
2bfec9f4af | ||
|
|
1aa7fac8c2 | ||
|
|
c01107fd52 | ||
|
|
5b27361ef0 | ||
|
|
494ddc10e4 | ||
|
|
6151f78d28 | ||
|
|
46c67632c7 | ||
|
|
3f7cf2f971 | ||
|
|
84cc8ff9c8 | ||
|
|
921c2bcd61 | ||
|
|
6ea8ed07ed | ||
|
|
a5addd2257 | ||
|
|
8b1d4ee06a | ||
|
|
3e23d9742b | ||
|
|
847d7dd71a | ||
|
|
10dc3a24e8 | ||
|
|
c6c1cfef3c | ||
|
|
cc8a2f736b | ||
|
|
7fcd3e1a4f | ||
|
|
481fe5a087 | ||
|
|
2d690ac585 | ||
|
|
a118299cfb | ||
|
|
bc01475920 | ||
|
|
56e9d8eda5 | ||
|
|
902e7021fd | ||
|
|
1773c42398 | ||
|
|
ae88536f0c | ||
|
|
b4d6583901 | ||
|
|
b31e420064 | ||
|
|
e4e439e2bf | ||
|
|
a79a83d6da | ||
|
|
50d4dc6499 | ||
|
|
cbc662085e | ||
|
|
02a5541fed | ||
|
|
14248621fe | ||
|
|
8c299d7b0b | ||
|
|
57d6bdff1b | ||
|
|
957ec9be60 | ||
|
|
76147a7231 | ||
|
|
eff3d1a09b | ||
|
|
5f6d7a279c | ||
|
|
9bce361b3e | ||
|
|
925e414e7b | ||
|
|
aeec6f2df5 | ||
|
|
9358650bd4 | ||
|
|
54d44a76a7 | ||
|
|
cc22183f20 | ||
|
|
2ded1c955f | ||
|
|
d955e733bf | ||
|
|
99a501f0c3 | ||
|
|
cdb2b47e0f | ||
|
|
366e20cbe8 | ||
|
|
d5179bd9ed | ||
|
|
12506784da | ||
|
|
4fee4d8da2 | ||
|
|
b1242163f7 | ||
|
|
8cd44fb2e8 | ||
|
|
33a8c9da7e | ||
|
|
37facf7f7b | ||
|
|
1d20973363 | ||
|
|
0cb08cd114 | ||
|
|
c97ba45eed | ||
|
|
74fcc456dc | ||
|
|
b17d606ed2 | ||
|
|
3e97ac5268 | ||
|
|
a7ab0d98fa | ||
|
|
94b4f92bc5 | ||
|
|
77d058cf76 | ||
|
|
52f815e240 | ||
|
|
83b329c123 | ||
|
|
909806b8ce | ||
|
|
d67d5cc267 | ||
|
|
0b95f61549 | ||
|
|
6620edebb3 | ||
|
|
4e4f7fd4ac | ||
|
|
f3769d8e86 | ||
|
|
5caf9b9575 | ||
|
|
6d927f61aa | ||
|
|
65a20df7c1 | ||
|
|
8ba0849bcf | ||
|
|
55abd67e81 | ||
|
|
8cb38344ae | ||
|
|
d90d30d10b | ||
|
|
709c5884ea | ||
|
|
5795bef02a | ||
|
|
1f72b3ac24 | ||
|
|
0949e0a6f3 | ||
|
|
1139209551 | ||
|
|
9c4fecb5c6 | ||
|
|
8142ffdfb7 | ||
|
|
961ad36443 | ||
|
|
11309a8cf2 | ||
|
|
7fadc438ec | ||
|
|
7388aeff55 | ||
|
|
c886d5bcfd | ||
|
|
58187f5c2c | ||
|
|
6129930fb0 | ||
|
|
505bb391c6 | ||
|
|
3483eed412 | ||
|
|
aee938b51e | ||
|
|
ba95e522c4 | ||
|
|
4c4303eacf | ||
|
|
6a7b1e8cb0 | ||
|
|
62cab7710c | ||
|
|
96d34349ec | ||
|
|
e4c6dcf3bc | ||
|
|
0f23633809 | ||
|
|
53adfedc83 | ||
|
|
2f736bee19 | ||
|
|
ae37ace15b | ||
|
|
1aed2379b9 | ||
|
|
f93046308c | ||
|
|
1d514e6bf6 | ||
|
|
62e51649fa | ||
|
|
edb1beac3d | ||
|
|
f441e4ec4e | ||
|
|
70d569029b | ||
|
|
018d6461f5 | ||
|
|
413ce37681 | ||
|
|
9d31b7c008 | ||
|
|
fb004a1990 | ||
|
|
0262a38c7e | ||
|
|
d3f784d4f9 | ||
|
|
475cd80faf | ||
|
|
37ff2d903f | ||
|
|
a900851abc | ||
|
|
3ae91957be | ||
|
|
be11944f99 | ||
|
|
f3a70d82cd | ||
|
|
61423f6900 | ||
|
|
29d2f51fca | ||
|
|
bfaa2bdd4e | ||
|
|
ce4a3edf7b | ||
|
|
6c153b046f | ||
|
|
7a732eb9c4 | ||
|
|
fdfb8862eb | ||
|
|
8df3253955 | ||
|
|
78ec315b69 | ||
|
|
13fc64470a | ||
|
|
97b5d43bd5 | ||
|
|
c2fcb39336 | ||
|
|
4e718f592c | ||
|
|
d780e8b2a0 | ||
|
|
e1b773958f | ||
|
|
326a67acdb | ||
|
|
2c36d0aaae | ||
|
|
1b45f253eb | ||
|
|
7a2b5125ed | ||
|
|
da39dbcb57 | ||
|
|
fab70e878a | ||
|
|
0d2fe62d68 | ||
|
|
bafa62cdec | ||
|
|
fd318826c5 | ||
|
|
5403a19076 | ||
|
|
89c4647c3c | ||
|
|
9befaeb3ae | ||
|
|
122eb8c82e | ||
|
|
81b3f1b244 | ||
|
|
cc89b6ad1e | ||
|
|
0f7aa70f2d | ||
|
|
b7304084d9 | ||
|
|
a99d3b613f | ||
|
|
e896ed9d87 | ||
|
|
975395ce98 | ||
|
|
761b407159 | ||
|
|
5bdbf63ff6 | ||
|
|
d3753ca463 | ||
|
|
ca20ae3851 | ||
|
|
ea6d8dd212 | ||
|
|
92dfeb63dc | ||
|
|
68d6b5718e | ||
|
|
8f1d4ffa4d | ||
|
|
3b2d75e129 | ||
|
|
2d2be0a214 | ||
|
|
1716f9e7cd | ||
|
|
da0d94caf2 | ||
|
|
1b41ef78cd | ||
|
|
83c523256d | ||
|
|
507aeb1e34 | ||
|
|
43115e1f3b | ||
|
|
0a5c068cb6 | ||
|
|
af559a1344 | ||
|
|
0f69dbb0cf | ||
|
|
d7778e29b0 | ||
|
|
9388aab32e | ||
|
|
6d3cbb8d32 | ||
|
|
dd0e0840b8 | ||
|
|
5a5b6720b0 | ||
|
|
a4a26ef528 | ||
|
|
9fe60a6368 | ||
|
|
e2c3dfd341 | ||
|
|
2687bf99d6 | ||
|
|
3d39f64c0d | ||
|
|
60bc860e76 | ||
|
|
2377287890 | ||
|
|
cabdc255f5 | ||
|
|
ac11e2b79a | ||
|
|
8f0fcc4efd | ||
|
|
399f7c24ac | ||
|
|
fdefa16cae | ||
|
|
95b4cdf819 | ||
|
|
517bfc54c5 | ||
|
|
e840e72755 | ||
|
|
992e27c4e0 | ||
|
|
cfb6a1c917 | ||
|
|
0347fb0441 | ||
|
|
24a77023bd | ||
|
|
07be9d1721 | ||
|
|
88f6f4827c | ||
|
|
9a72831a33 | ||
|
|
59f929c7d3 | ||
|
|
f0aab6e46a | ||
|
|
8d7d10ae81 | ||
|
|
c112b3ce40 | ||
|
|
affc947ce0 | ||
|
|
cbfb364c41 | ||
|
|
c84c60112e | ||
|
|
a9ef45dc9a | ||
|
|
bdd3e343ba | ||
|
|
cd364b029c | ||
|
|
3e1ed97187 | ||
|
|
daddc25de8 | ||
|
|
4237ff42c9 | ||
|
|
3291fb6a1b | ||
|
|
f5b47dc95e | ||
|
|
4f6d15d849 | ||
|
|
c35c1b6426 | ||
|
|
80f6f18e54 | ||
|
|
ac8f55099d | ||
|
|
3987da830c | ||
|
|
cbae6120e1 | ||
|
|
011daa952e | ||
|
|
cb98b75400 | ||
|
|
9a87b05570 | ||
|
|
725ea06400 | ||
|
|
facaa3326b | ||
|
|
062ec48ee6 | ||
|
|
6e0dc1dd2c | ||
|
|
64afe136f6 | ||
|
|
e7749c59ce | ||
|
|
841f76f510 | ||
|
|
2e391b01fe | ||
|
|
57fffab7b6 | ||
|
|
45636e5afe | ||
|
|
843372ace3 | ||
|
|
511a11a573 | ||
|
|
13ae670568 | ||
|
|
97850c62c7 | ||
|
|
5b4ec6fd7d | ||
|
|
e4107201a3 | ||
|
|
b9879cf23b | ||
|
|
2bc0e49bc7 | ||
|
|
f6767b59f5 | ||
|
|
5228aba5dd | ||
|
|
9a69a755bc | ||
|
|
c688874064 | ||
|
|
9e6d5f7727 | ||
|
|
59f1fb8956 | ||
|
|
224faeacb6 | ||
|
|
f0465e442f | ||
|
|
849bc91506 | ||
|
|
f15667838b | ||
|
|
9ae2fe84f4 | ||
|
|
0398aa4c67 | ||
|
|
409f95b50a | ||
|
|
510451a35e | ||
|
|
a781fb6f2b | ||
|
|
a429f361b8 | ||
|
|
be5d06d3c8 | ||
|
|
ce6baeb714 | ||
|
|
85122d3fa9 | ||
|
|
5255871f1a | ||
|
|
bd145cf18b | ||
|
|
04859da116 | ||
|
|
1b41a73eb0 | ||
|
|
9081a0b657 | ||
|
|
d87714e4ef | ||
|
|
45fae716de |
108
.github/workflows/presubmit.yml
vendored
Normal file
108
.github/workflows/presubmit.yml
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
name: Presubmit
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build-desktop:
|
||||
name: build-desktop
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest]
|
||||
|
||||
steps:
|
||||
- name: Checkout Filament
|
||||
run: |
|
||||
git version
|
||||
git init $GITHUB_WORKSPACE
|
||||
cd $GITHUB_WORKSPACE
|
||||
git remote add origin https://github.com/google/filament
|
||||
git config gc.auto 0
|
||||
git fetch --tags --prune --progress --no-recurse-submodules origin +${GITHUB_REF}:${GITHUB_REF/refs\//refs\/remote\/}
|
||||
git checkout --progress --force ${GITHUB_REF/refs\//refs\/remote\/}
|
||||
- name: Run build script
|
||||
run: |
|
||||
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
|
||||
cd build/$WORKFLOW_OS && ./build.sh ${TARGET}
|
||||
env:
|
||||
TARGET: presubmit
|
||||
|
||||
build-windows:
|
||||
name: build-windows
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Filament
|
||||
run: |
|
||||
git version
|
||||
git init %GITHUB_WORKSPACE%
|
||||
cd %GITHUB_WORKSPACE%
|
||||
git remote add origin https://github.com/google/filament
|
||||
git config gc.auto 0
|
||||
git fetch --tags --prune --progress --no-recurse-submodules origin +%GITHUB_REF%:%GITHUB_REF:refs/=refs/remote/%
|
||||
git checkout --progress --force %GITHUB_REF:refs/=refs/remote/%
|
||||
shell: cmd
|
||||
- name: Run build script
|
||||
run: |
|
||||
build\windows\build-github.bat
|
||||
|
||||
build-android:
|
||||
name: build-android
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Filament
|
||||
run: |
|
||||
git version
|
||||
git init $GITHUB_WORKSPACE
|
||||
cd $GITHUB_WORKSPACE
|
||||
git remote add origin https://github.com/google/filament
|
||||
git config gc.auto 0
|
||||
git fetch --tags --prune --progress --no-recurse-submodules origin +${GITHUB_REF}:${GITHUB_REF/refs\//refs\/remote\/}
|
||||
git checkout --progress --force ${GITHUB_REF/refs\//refs\/remote\/}
|
||||
- name: Run build script
|
||||
run: |
|
||||
cd build/android && ./build.sh ${TARGET}
|
||||
env:
|
||||
TARGET: presubmit
|
||||
|
||||
build-ios:
|
||||
name: build-iOS
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Filament
|
||||
run: |
|
||||
git version
|
||||
git init $GITHUB_WORKSPACE
|
||||
cd $GITHUB_WORKSPACE
|
||||
git remote add origin https://github.com/google/filament
|
||||
git config gc.auto 0
|
||||
git fetch --tags --prune --progress --no-recurse-submodules origin +${GITHUB_REF}:${GITHUB_REF/refs\//refs\/remote\/}
|
||||
git checkout --progress --force ${GITHUB_REF/refs\//refs\/remote\/}
|
||||
- name: Run build script
|
||||
run: |
|
||||
cd build/ios && ./build.sh ${TARGET}
|
||||
env:
|
||||
TARGET: presubmit
|
||||
|
||||
build-web:
|
||||
name: build-web
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Filament
|
||||
run: |
|
||||
git version
|
||||
git init $GITHUB_WORKSPACE
|
||||
cd $GITHUB_WORKSPACE
|
||||
git remote add origin https://github.com/google/filament
|
||||
git config gc.auto 0
|
||||
git fetch --tags --prune --progress --no-recurse-submodules origin +${GITHUB_REF}:${GITHUB_REF/refs\//refs\/remote\/}
|
||||
git checkout --progress --force ${GITHUB_REF/refs\//refs\/remote\/}
|
||||
- name: Run build script
|
||||
run: |
|
||||
cd build/web && ./build.sh ${TARGET}
|
||||
env:
|
||||
TARGET: presubmit
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,9 +3,13 @@
|
||||
imgui.ini
|
||||
cmake-*
|
||||
ImportExecutables-*.cmake
|
||||
out
|
||||
/out*
|
||||
dist
|
||||
dist-*
|
||||
toolchains
|
||||
filament/docs/html/**
|
||||
.vscode
|
||||
gltf_baker.ini
|
||||
*tmp*.png
|
||||
civetweb.txt
|
||||
/TAGS
|
||||
|
||||
191
CMakeLists.txt
191
CMakeLists.txt
@@ -1,7 +1,7 @@
|
||||
# ==================================================================================================
|
||||
# CMake
|
||||
# ==================================================================================================
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
# ==================================================================================================
|
||||
# Project declaration
|
||||
@@ -18,6 +18,8 @@ option(USE_EXTERNAL_GLES3 "Experimental: Compile Filament against OpenGL ES 3" O
|
||||
|
||||
option(GENERATE_JS_DOCS "Build WebGL documentation and tutorials" OFF)
|
||||
|
||||
option(ENABLE_LTO "Enable link-time optimizations if supported by the compiler" OFF)
|
||||
|
||||
# ==================================================================================================
|
||||
# OS specific
|
||||
# ==================================================================================================
|
||||
@@ -25,6 +27,10 @@ if (UNIX AND NOT APPLE AND NOT ANDROID AND NOT WEBGL)
|
||||
set(LINUX TRUE)
|
||||
endif()
|
||||
|
||||
if (ANDROID OR WEBGL OR IOS)
|
||||
set(IS_MOBILE_TARGET TRUE)
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
# Link statically against c/c++ lib to avoid missing redistriburable such as
|
||||
# "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users
|
||||
@@ -44,19 +50,46 @@ if (WIN32)
|
||||
set(CRT_FLAGS_DEBUG "/MDd")
|
||||
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")
|
||||
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
# 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")
|
||||
|
||||
# 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")
|
||||
endif()
|
||||
|
||||
# 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")
|
||||
|
||||
# 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")
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
# Check if embree is available.
|
||||
# This is an optional dependency and can be installed with homebrew, apt-get, etc.
|
||||
# ==================================================================================================
|
||||
|
||||
find_package(embree 3.0 QUIET PATHS /usr/lib64/cmake)
|
||||
if (embree_FOUND AND NOT ANDROID AND NOT IOS)
|
||||
message("Found embree in ${embree_DIR}")
|
||||
set(MKLDNN_THREADING "TBB")
|
||||
include(third_party/OpenImageDenoise/cmake/resource.cmake)
|
||||
include(third_party/OpenImageDenoise/mkl-dnn/cmake/Threading.cmake)
|
||||
include(third_party/OpenImageDenoise/mkl-dnn/cmake/TBB.cmake)
|
||||
find_package(TBB QUIET)
|
||||
if (TBB_FOUND AND "${TBB_VERSION_MAJOR}" VERSION_EQUAL 2019)
|
||||
message("Found TBB ${TBB_VERSION}")
|
||||
add_definitions(-DFILAMENT_HAS_EMBREE)
|
||||
set(DENOISE_LIBRARY OpenImageDenoise)
|
||||
else()
|
||||
message("TBB 2019 not found.")
|
||||
endif()
|
||||
else()
|
||||
message("Embree not found, pipeline features are disabled.")
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
@@ -77,13 +110,13 @@ set(TOOLS ${CMAKE_CURRENT_SOURCE_DIR}/tools)
|
||||
# ==================================================================================================
|
||||
# Compiler check
|
||||
# ==================================================================================================
|
||||
set(MIN_CLANG_VERSION "5.0")
|
||||
set(MIN_CLANG_VERSION "6.0")
|
||||
|
||||
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
if (CMAKE_C_COMPILER_VERSION VERSION_LESS MIN_CLANG_VERSION)
|
||||
message(FATAL_ERROR "Detected C compiler Clang ${CMAKE_C_COMPILER_VERSION} < ${MIN_CLANG_VERSION}")
|
||||
endif()
|
||||
else()
|
||||
elseif (NOT MSVC)
|
||||
message(FATAL_ERROR "Detected C compiler ${CMAKE_C_COMPILER_ID} is unsupported")
|
||||
endif()
|
||||
|
||||
@@ -91,13 +124,31 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS MIN_CLANG_VERSION)
|
||||
message(FATAL_ERROR "Detected CXX compiler Clang ${CMAKE_CXX_COMPILER_VERSION} < ${MIN_CLANG_VERSION}")
|
||||
endif()
|
||||
else()
|
||||
elseif (NOT MSVC)
|
||||
message(FATAL_ERROR "Detected CXX compiler ${CMAKE_CXX_COMPILER_ID} is unsupported")
|
||||
endif()
|
||||
|
||||
# Detect use of the clang-cl.exe frontend, which does not support all of clangs normal options
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
|
||||
set(CLANG_CL true)
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
if ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
|
||||
set(CLANG_CL true)
|
||||
endif()
|
||||
elseif (MSVC)
|
||||
set(MSVC_NATIVE true)
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
# Link time optimizations (LTO)
|
||||
# ==================================================================================================
|
||||
if (ENABLE_LTO)
|
||||
include(CheckIPOSupported)
|
||||
|
||||
check_ipo_supported(RESULT IPO_SUPPORT)
|
||||
|
||||
if (IPO_SUPPORT)
|
||||
message(STATUS "LTO support is enabled")
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
@@ -108,7 +159,12 @@ if (WIN32)
|
||||
set(CXX_STANDARD "/std:c++14")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} -fstrict-aliasing -Wno-unknown-pragmas -Wno-unused-function")
|
||||
if (MSVC_NATIVE)
|
||||
set(CXX_STANDARD "/std:c++latest")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} /W0 /Zc:__cplusplus")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} -fstrict-aliasing -Wno-unknown-pragmas -Wno-unused-function")
|
||||
endif()
|
||||
|
||||
if (USE_EXTERNAL_GLES3)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_EXTERNAL_GLES3")
|
||||
@@ -120,25 +176,16 @@ endif()
|
||||
|
||||
if (LINUX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
if (FILAMENT_REQUIRES_CXXABI)
|
||||
# Required in CI environment with custom libc++ and libc++abi
|
||||
link_libraries(libc++abi.a)
|
||||
endif()
|
||||
# To distribute our binaries, we must remove the dependency on libc++ and libgcc.
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
link_libraries("-static-libgcc -static-libstdc++")
|
||||
endif()
|
||||
else()
|
||||
if (FILAMENT_REQUIRES_CXXABI)
|
||||
message("The option FILAMENT_REQUIRES_CXXABI is unsupported on this platform")
|
||||
endif()
|
||||
link_libraries("-static-libgcc -static-libstdc++")
|
||||
link_libraries(libc++.a)
|
||||
link_libraries(libc++abi.a)
|
||||
endif()
|
||||
|
||||
if (CYGWIN)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
||||
endif()
|
||||
|
||||
if (CLANG_CL)
|
||||
if (CLANG_CL OR MSVC)
|
||||
# Since the "secure" replacements that MSVC suggests are not portable, disable
|
||||
# the deprecation warnings. Also disable warnings about use of POSIX functions (i.e. "unlink").
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE")
|
||||
@@ -154,7 +201,7 @@ endif()
|
||||
# ==================================================================================================
|
||||
# Release compiler flags
|
||||
# ==================================================================================================
|
||||
if (NOT CLANG_CL)
|
||||
if (NOT CLANG_CL AND NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -ffunction-sections -fdata-sections")
|
||||
endif()
|
||||
|
||||
@@ -172,7 +219,7 @@ endif()
|
||||
# -fsanitize=address causes a crash with assimp, which we can't explain for now
|
||||
#set(EXTRA_SANITIZE_OPTIONS "-fsanitize=undefined -fsanitize=address")
|
||||
# clang-cl.exe on Windows does not support -fstack-protector.
|
||||
if (NOT CLANG_CL)
|
||||
if (NOT CLANG_CL AND NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_SANITIZE_OPTIONS}")
|
||||
@@ -245,6 +292,36 @@ else()
|
||||
option(FILAMENT_BUILD_FILAMAT "Build filamat and JNI buildings" OFF)
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
# Material compilation flags
|
||||
# ==================================================================================================
|
||||
|
||||
# Target system.
|
||||
if (IS_MOBILE_TARGET)
|
||||
set(MATC_TARGET mobile)
|
||||
else()
|
||||
set(MATC_TARGET desktop)
|
||||
endif()
|
||||
|
||||
set(MATC_API_FLAGS )
|
||||
|
||||
# TODO: Add a flag to build Filament without support for OpenGL.
|
||||
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a opengl)
|
||||
|
||||
if (FILAMENT_SUPPORTS_VULKAN)
|
||||
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a vulkan)
|
||||
endif()
|
||||
if (FILAMENT_SUPPORTS_METAL)
|
||||
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a metal)
|
||||
endif()
|
||||
|
||||
# Only optimize materials in Release mode (so error message lines match the source code)
|
||||
if (NOT CMAKE_BUILD_TYPE MATCHES Release)
|
||||
set(MATC_OPT_FLAGS -g)
|
||||
endif()
|
||||
|
||||
set(MATC_BASE_FLAGS ${MATC_API_FLAGS} -p ${MATC_TARGET} ${MATC_OPT_FLAGS})
|
||||
|
||||
# ==================================================================================================
|
||||
# Distribution
|
||||
# ==================================================================================================
|
||||
@@ -259,20 +336,47 @@ endif()
|
||||
# ==================================================================================================
|
||||
# Functions
|
||||
# ==================================================================================================
|
||||
## The MSVC compiler has a limitation on literal string length which is reached when all the
|
||||
## licenses are concatenated together into a large string... so split them into multiple strings.
|
||||
function(list_licenses OUTPUT MODULES)
|
||||
file(WRITE ${OUTPUT} "R\"FILAMENT__(\n")
|
||||
set(STR_OPENER "R\"FILAMENT__(")
|
||||
set(STR_CLOSER ")FILAMENT__\"")
|
||||
set(CONTENT)
|
||||
set(_MODULES ${MODULES} ${ARGN})
|
||||
foreach(module ${_MODULES})
|
||||
set(license_path "../../third_party/${module}/LICENSE")
|
||||
get_filename_component(fullname "${license_path}" ABSOLUTE)
|
||||
file(APPEND ${OUTPUT} "License and copyrights for ${module}:\n\n")
|
||||
file(READ ${license_path} license)
|
||||
file(APPEND ${OUTPUT} ${license})
|
||||
file(APPEND ${OUTPUT} "\n\n")
|
||||
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")
|
||||
endforeach()
|
||||
file(APPEND ${OUTPUT} ")FILAMENT__\"\n")
|
||||
configure_file(${FILAMENT}/build/licenses.inc.in ${OUTPUT})
|
||||
endfunction(list_licenses)
|
||||
|
||||
set(COMBINE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/build/linux/combine-static-libs.sh")
|
||||
if (WIN32)
|
||||
set(COMBINE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/build/windows/combine-static-libs.bat")
|
||||
set(CMAKE_AR "lib.exe")
|
||||
endif()
|
||||
|
||||
# Add a custom command to TARGET that combines the static libraries in DEPS into a single archive.
|
||||
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}>")
|
||||
endforeach()
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${TARGET} POST_BUILD
|
||||
COMMAND "${COMBINE_SCRIPT}" "${CMAKE_AR}" "${OUTPUT}" ${DEPS_FILES}
|
||||
COMMENT "Combining ${target} dependencies into single shared library"
|
||||
VERBATIM
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# ==================================================================================================
|
||||
# Configuration for CMAKE_CROSSCOMPILING.
|
||||
# ==================================================================================================
|
||||
@@ -312,7 +416,9 @@ function(get_resgen_vars ARCHIVE_DIR ARCHIVE_NAME)
|
||||
${ARCHIVE_DIR}/${ARCHIVE_NAME}.apple.S
|
||||
${ARCHIVE_DIR}/${ARCHIVE_NAME}.h
|
||||
)
|
||||
set(ASM_ARCH_FLAG "-arch ${DIST_ARCH}")
|
||||
if (IOS)
|
||||
set(ASM_ARCH_FLAG "-arch ${DIST_ARCH}")
|
||||
endif()
|
||||
if (APPLE)
|
||||
set(ASM_SUFFIX ".apple")
|
||||
endif()
|
||||
@@ -344,6 +450,7 @@ add_subdirectory(${LIBRARIES}/geometry)
|
||||
add_subdirectory(${LIBRARIES}/gltfio)
|
||||
add_subdirectory(${LIBRARIES}/ibl)
|
||||
add_subdirectory(${LIBRARIES}/image)
|
||||
add_subdirectory(${LIBRARIES}/rays)
|
||||
add_subdirectory(${LIBRARIES}/math)
|
||||
add_subdirectory(${LIBRARIES}/utils)
|
||||
add_subdirectory(${FILAMENT}/filament)
|
||||
@@ -353,7 +460,9 @@ add_subdirectory(${EXTERNAL}/smol-v/tnt)
|
||||
add_subdirectory(${EXTERNAL}/benchmark/tnt)
|
||||
add_subdirectory(${EXTERNAL}/meshoptimizer)
|
||||
add_subdirectory(${EXTERNAL}/cgltf/tnt)
|
||||
add_subdirectory(${EXTERNAL}/xatlas/tnt)
|
||||
add_subdirectory(${EXTERNAL}/stb/tnt)
|
||||
add_subdirectory(${EXTERNAL}/getopt)
|
||||
|
||||
if (FILAMENT_BUILD_FILAMAT)
|
||||
# spirv-tools must come before filamat, as filamat relies on the presence of the
|
||||
@@ -390,14 +499,15 @@ if (NOT ANDROID AND NOT WEBGL AND NOT IOS)
|
||||
add_subdirectory(${LIBRARIES}/bluegl)
|
||||
add_subdirectory(${LIBRARIES}/filagui)
|
||||
add_subdirectory(${LIBRARIES}/imageio)
|
||||
add_subdirectory(${LIBRARIES}/matdbg)
|
||||
|
||||
add_subdirectory(${FILAMENT}/java/filamat)
|
||||
add_subdirectory(${FILAMENT}/java/filament)
|
||||
add_subdirectory(${FILAMENT}/samples)
|
||||
|
||||
add_subdirectory(${EXTERNAL}/astcenc/tnt)
|
||||
add_subdirectory(${EXTERNAL}/civetweb/tnt)
|
||||
add_subdirectory(${EXTERNAL}/etc2comp)
|
||||
add_subdirectory(${EXTERNAL}/getopt)
|
||||
add_subdirectory(${EXTERNAL}/imgui/tnt)
|
||||
add_subdirectory(${EXTERNAL}/libassimp/tnt)
|
||||
add_subdirectory(${EXTERNAL}/libpng/tnt)
|
||||
@@ -417,6 +527,11 @@ if (NOT ANDROID AND NOT WEBGL AND NOT IOS)
|
||||
add_subdirectory(${TOOLS}/roughness-prefilter)
|
||||
add_subdirectory(${TOOLS}/skygen)
|
||||
add_subdirectory(${TOOLS}/specular-color)
|
||||
|
||||
if (DENOISE_LIBRARY)
|
||||
add_subdirectory(${EXTERNAL}/OpenImageDenoise/tnt)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
# Generate exported executables for cross-compiled builds (Android, WebGL, and iOS)
|
||||
|
||||
103
README.md
103
README.md
@@ -43,13 +43,23 @@ Here are a few sample materials rendered with Filament:
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## 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
|
||||
@@ -75,17 +85,18 @@ Here are a few sample materials rendered with Filament:
|
||||
- Metallic workflow
|
||||
- Clear coat
|
||||
- Anisotropic lighting
|
||||
- Approximated translucent (subsurface) materials (direct and indirect lighting)
|
||||
- Approximated translucent (subsurface) materials
|
||||
- Cloth shading
|
||||
- Normal mapping & ambient occlusion mapping
|
||||
- Image-based lighting
|
||||
- Physically-based camera (shutter speed, sensitivity and aperture)
|
||||
- Physical light units
|
||||
- Point light, spot light and directional light
|
||||
- SSAO
|
||||
- ACES-like tone-mapping
|
||||
- Temporal dithering
|
||||
- FXAA or MSAA
|
||||
- Dynamic resolution (on Android)
|
||||
- FXAA, MSAA and specular anti-aliasing
|
||||
- Dynamic resolution (on Android and iOS)
|
||||
|
||||
### Future
|
||||
|
||||
@@ -127,11 +138,13 @@ and tools.
|
||||
- `filamat`: Material generation library
|
||||
- `filameshio`: Tiny filamesh parsing library (see also `tools/filamesh`)
|
||||
- `geometry`: Mesh-related utilities
|
||||
- `gltfio`: Loader for glTF 2.0
|
||||
- `gltfio`: Loader and optional pipeline for glTF 2.0
|
||||
- `ibl`: IBL generation tools
|
||||
- `image`: Image filtering and simple transforms
|
||||
- `imageio`: Image file reading / writing, only intended for internal use
|
||||
- `matdbg`: DebugServer for inspecting shaders at run-time (debug builds only)
|
||||
- `math`: Math library
|
||||
- `rays`: Simple path tracer used for baking ambient occlusion, etc.
|
||||
- `utils`: Utility library (threads, memory, data structures, etc.)
|
||||
- `samples`: Sample desktop applications
|
||||
- `shaders`: Shaders used by `filamat` and `matc`
|
||||
@@ -170,11 +183,16 @@ To build the Java based components of the project you can optionally install (re
|
||||
Additional dependencies may be required for your operating system. Please refer to the appropriate
|
||||
section below.
|
||||
|
||||
Building the `rays` library (used for light baking) is optional and requires the following packages:
|
||||
|
||||
- embree 3.0+
|
||||
- libtbb-dev
|
||||
|
||||
To build Filament for Android you must also install the following:
|
||||
|
||||
- Android Studio 3.3
|
||||
- Android Studio 3.5
|
||||
- Android SDK
|
||||
- Android NDK 19 or higher
|
||||
- Android NDK "side-by-side" 20 or higher
|
||||
|
||||
### Environment variables
|
||||
|
||||
@@ -231,14 +249,36 @@ $ ./build.sh -j release
|
||||
|
||||
If you use CMake directly instead of the build script, pass `-DENABLE_JAVA=OFF` to CMake instead.
|
||||
|
||||
### Filament-specific CMake Options
|
||||
|
||||
The following CMake options are boolean options specific to Filament:
|
||||
|
||||
- `ENABLE_JAVA`: Compile Java projects: requires a JDK and the JAVA_HOME env var
|
||||
- `ENABLE_LTO`: Enable link-time optimizations if supported by the compiler
|
||||
- `FILAMENT_BUILD_FILAMAT`: Build filamat and JNI buildings
|
||||
- `FILAMENT_SUPPORTS_METAL`: Include the Metal backend
|
||||
- `FILAMENT_SUPPORTS_VULKAN`: Include the Vulkan backend
|
||||
- `GENERATE_JS_DOCS`: Build WebGL documentation and tutorials
|
||||
- `INSTALL_BACKEND_TEST`: Install the backend test library so it can be consumed on iOS
|
||||
- `USE_EXTERNAL_GLES3`: Experimental: Compile Filament against OpenGL ES 3
|
||||
|
||||
To turn an option on or off:
|
||||
|
||||
```
|
||||
$ cd <cmake-build-directory>
|
||||
$ cmake . -DOPTION=ON # Relace OPTION with the option name, set to ON / OFF
|
||||
```
|
||||
|
||||
Options can also be set with the CMake GUI.
|
||||
|
||||
### Linux
|
||||
|
||||
Make sure you've installed the following dependencies:
|
||||
|
||||
- `clang-7`
|
||||
- `clang-7` or higher
|
||||
- `libglu1-mesa-dev`
|
||||
- `libc++-7-dev` (`libcxx-devel` and `libcxx-static` on Fedora)
|
||||
- `libc++abi-7-dev` (`libcxxabi-static` on Fedora)
|
||||
- `libc++-7-dev` (`libcxx-devel` and `libcxx-static` on Fedora) or higher
|
||||
- `libc++abi-7-dev` (`libcxxabi-static` on Fedora) or higher
|
||||
- `ninja-build`
|
||||
- `libxi-dev`
|
||||
|
||||
@@ -254,13 +294,6 @@ $ cd out/cmake-release
|
||||
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
|
||||
```
|
||||
|
||||
If you experience link errors you must ensure that you are using `libc++abi` by passing this
|
||||
extra parameter to `cmake`:
|
||||
|
||||
```
|
||||
-DFILAMENT_REQUIRES_CXXABI=true
|
||||
```
|
||||
|
||||
Your Linux distribution might default to `gcc` instead of `clang`, if that's the case invoke
|
||||
`cmake` with the following command:
|
||||
|
||||
@@ -330,6 +363,33 @@ See [ios/samples/README.md](./ios/samples/README.md) for more information.
|
||||
|
||||
### Windows
|
||||
|
||||
#### Building on Windows with the Visual Studio 2019 compiler
|
||||
|
||||
Install the following components:
|
||||
|
||||
- [Visual Studio 2019](https://www.visualstudio.com/downloads)
|
||||
- [Python 3.7](https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe)
|
||||
- [CMake 3.14 or later](https://github.com/Kitware/CMake/releases/download/v3.14.7/cmake-3.14.7-win64-x64.msi)
|
||||
|
||||
Open the `x64 Native Tools Command Prompt for VS 2019`.
|
||||
|
||||
Create a working directory, and run cmake in it:
|
||||
|
||||
```
|
||||
> mkdir out
|
||||
> cd out
|
||||
> cmake ..
|
||||
```
|
||||
|
||||
Then, you should be able to load the generated solution file `TNT.sln` in Visual Studio and build the `material_sandbox` project.
|
||||
|
||||
Run it from the `out` directory with:
|
||||
```
|
||||
> samples\Debug\material_sandbox.exe ..\assets\models\monkey\monkey.obj
|
||||
```
|
||||
|
||||
#### Building on Windows with the Clang compiler
|
||||
|
||||
The following instructions have been tested on a machine running Windows 10. They should take you
|
||||
from a machine with only the operating system to a machine able to build and run Filament.
|
||||
|
||||
@@ -706,8 +766,9 @@ 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 RGBM files
|
||||
for the IBL. 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). To generate an IBL simply use
|
||||
this command:
|
||||
|
||||
```
|
||||
cmgen -x ./ibls/ my_ibl.exr
|
||||
@@ -723,7 +784,7 @@ pre-filtered environment map (one file per cubemap face and per mip level), the
|
||||
texture for the skybox and a text file containing the spherical harmonics for indirect diffuse
|
||||
lighting.
|
||||
|
||||
If you prefer a blurred background, run `cmgen` with this flag: `--extract-blur=0.5`. The numerical
|
||||
If you prefer a blurred background, run `cmgen` with this flag: `--extract-blur=0.1`. The numerical
|
||||
value is the desired roughness between 0 and 1.
|
||||
|
||||
## Rendering with Filament
|
||||
|
||||
113
RELEASE_NOTES.md
Normal file
113
RELEASE_NOTES.md
Normal file
@@ -0,0 +1,113 @@
|
||||
# Filament Release Notes log
|
||||
|
||||
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.4.2
|
||||
|
||||
- Cleaned up the validation strategy in Engine (checks for use-after-destroy etc).
|
||||
- OpenGL: Fixed ES 3.0 support on iOS.
|
||||
- OpenGL: Added support for KHR_debug in debug builds.
|
||||
- gltfio: Added Java / Kotlin bindings for Animator.
|
||||
- gltfio: Fixed panic with the Android gltf-bloom demo.
|
||||
- gltfio: Java clients should no longer call Filament#init.
|
||||
|
||||
## v1.4.1
|
||||
|
||||
- Added missing API documentation.
|
||||
- Fixed crash for sandboxed macOS apps using Filament.
|
||||
- Fixed an issue that limited the camera near plane to ~1mm.
|
||||
- Added Android sample for Camera Stream.
|
||||
- Fixed an Xcode assertion when rendering skinned meshes using the Metal backend.
|
||||
- Added support for Core Animation / Metal frame synchronization with Metal backend.
|
||||
- Fixed an issue with culling in `MaterialInstance`.
|
||||
- Fix additional compatibility issues with MSVC, including the Vulkan backend.
|
||||
- matdbg: fixed missing symbol issue when linking against debug builds.
|
||||
- filamat: fixed crash when using the "lite" version of the library.
|
||||
- matinfo: Fix a crash with on Windows.
|
||||
- gltfio: fixed an animation loop bug.
|
||||
- gltfio: added support for sparse accessors.
|
||||
- Add JS binding to unary `Camera::setExposure`.
|
||||
|
||||
## v1.4.0
|
||||
|
||||
- API Breakage: Simplified public-facing Fence API.
|
||||
- Minimum API level on Android is now API 19 instead of API 21.
|
||||
- Filament can now be built with msvc 2019.
|
||||
- Added the ability to modify clip space coordinates in the vertex shader.
|
||||
- Added missing API documentation.
|
||||
- Improved existing API documentation.
|
||||
- Added `Camera::setExposure(float)` to directly control the camera's exposure.
|
||||
- Backface culling can now be toggled on material instances.
|
||||
- Face direction is now reversed when transforms have negative scale.
|
||||
- Dielectrics now behave properly under a white furnace (energy preserving and conserving).
|
||||
- Clear coat roughness now remains in the 0..1 (previously remapped to the 0..0.6 range).
|
||||
- gltfio: Fixed several limitations with ubershader mode.
|
||||
- gltfio: Fixed a transforms issue with non-uniform scale.
|
||||
- webgl: Fixed an issue with JPEG textures.
|
||||
- Windows: Fix link error in debug builds.
|
||||
- matdbg: Web server must now be enabled with an environment variable.
|
||||
- matdbg: Added support for editing GLSL and MSL code.
|
||||
|
||||
## v1.3.2
|
||||
|
||||
- Added optional web server for real-time inspection of shader code.
|
||||
- Added basic #include support in material files.
|
||||
- Fixed potential Metal memory leak.
|
||||
- Fixed intermittent memory overflow in wasm builds.
|
||||
- Fix bad normal mapping with skinning.
|
||||
- Java clients can now call getNativeObject().
|
||||
|
||||
## v1.3.1
|
||||
|
||||
- Unified Filament Sceneform and npm releases.
|
||||
- Improved cmgen SH with HDR images.
|
||||
- IndirectLight can now be queried for dominant direction and color.
|
||||
- Added support for vertex morphing.
|
||||
- Introduced custom attributes, accessible from the vertex shader.
|
||||
- Added Java / Kotlin bindings for KtxLoader.
|
||||
- Added JavaScript / Typescript bindings for the new `RenderTarget` class.
|
||||
- Added base path to glTF loadResources method for JavaScript.
|
||||
- Added support for iOS `CVPixelBuffer` external images with the OpenGL backend.
|
||||
|
||||
## sceneform-1.9pr4
|
||||
|
||||
- Added `gltf_bloom` Android sample to show gltfio and the `RenderTarget` API.
|
||||
- Added `getMaterialInstanceAt` to the Java version of RenderableManager.
|
||||
- Fix JNI bindings for setting values in parameter arrays.
|
||||
- Added JNI bindings for the gltfio library.
|
||||
- Fix support for parameter arrays in `.mat` files.
|
||||
- Added support for `RGB_11_11_10`
|
||||
- Removed support for `RGBM` (**warning:** source compatibility breakage)
|
||||
- IBL cubemap can now be of any size
|
||||
- `Texture::generatePrefilterMipmap` can be used for runtime generation of a reflection cubemap
|
||||
|
||||
## sceneform-1.9pr3
|
||||
|
||||
- Added `Scene.addEntities()` to the Java / Kotlin bindings.
|
||||
- Improved robustness in the tangents utility for meshes that have tangents *and* normals.
|
||||
- Introduced `RenderTarget` API that allows View to reference an offscreen render target.
|
||||
- Added `lucy_bloom` sample to demonstrate the new `RenderTarget` API.
|
||||
- Added Screen Space Ambient Occlusion support (SAO)
|
||||
- New blending modes: `multiply` and `screen`
|
||||
- Fixed an issue when sorting blended objects with different blending modes
|
||||
- The material property `curvatureToRoughness` has been replaced with `specularAntiAliasing`.
|
||||
This new specular anti-aliasing solution offers more control via two new properties:
|
||||
`specularAntiAliasingVariance` and `specularAntiAliasingThreshold`. They can also be set on
|
||||
material instances if needed
|
||||
- Added specular ambient occlusion to compute a new AO term applied to specular reflections
|
||||
(see `specularAmbientOcclusion` property in materials)
|
||||
- Added multi-bounce ambient occlusion to brighten AO and preserve local color
|
||||
(see `multiBounceAmbientOcclusion` property in materials)
|
||||
- Micro-shadowing is now applied to material ambient occlusion
|
||||
- Use a smaller 64x64 DFG LUT on mobile to reduce binary size
|
||||
- Added a distance field generator to libimage.
|
||||
- JavaScript MaterialInstance now supports vec4 colors.
|
||||
- Further reduced `filamat` binary size by removing reliance on stdlib.
|
||||
- Added a new, smaller, version of the `filamat` library, `filamat_lite`. Material optimization and
|
||||
compiling for non-OpenGL backends have been removed in favor of a smaller binary size.
|
||||
- Implemented hard fences for the Metal backend, enablying dynamic resolution support.
|
||||
- Improved `SurfaceOrientation` robustness when using UVs to generate tangents.
|
||||
- Created a `RELEASE_NOTES.md` file, to be updated with significant PRs.
|
||||
|
||||
## sceneform-1.9pr2
|
||||
@@ -33,6 +33,7 @@ List<File> getBinaries(String name, File toolsPath) {
|
||||
ext.matcFullPath = getBinaries('matc', filamentToolsPath)
|
||||
ext.cmgenFullPath = getBinaries('cmgen', filamentToolsPath)
|
||||
ext.filameshFullPath = getBinaries('filamesh', filamentToolsPath)
|
||||
ext.resgenFullPath = getBinaries('resgen', filamentToolsPath)
|
||||
|
||||
class LogOutputStream extends ByteArrayOutputStream {
|
||||
private final Logger logger;
|
||||
@@ -115,6 +116,7 @@ class MaterialCompiler extends DefaultTask {
|
||||
// This task handles incremental builds
|
||||
class IblGenerator extends DefaultTask {
|
||||
File cmgenPath
|
||||
String cmgenArgs = null;
|
||||
|
||||
@SuppressWarnings("GroovyUnusedDeclaration")
|
||||
@InputFile
|
||||
@@ -154,9 +156,13 @@ class IblGenerator extends DefaultTask {
|
||||
|
||||
project.exec {
|
||||
standardOutput out
|
||||
if (!cmgenArgs) {
|
||||
cmgenArgs = '--format=rgb32f --extract-blur=0.08 --extract=' + outputDir.absolutePath
|
||||
}
|
||||
cmgenArgs = cmgenArgs + " " + file
|
||||
errorOutput err
|
||||
executable "${cmgenPath}"
|
||||
args('--format=rgbm', '--extract-blur=0.08', "--extract=${outputDir.absolutePath}", file)
|
||||
args(cmgenArgs.split())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "CallbackUtils.h"
|
||||
#include "NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
#include <filament/Engine.h>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "NioUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
1
android/filamat-android/.gitignore
vendored
1
android/filamat-android/.gitignore
vendored
@@ -9,3 +9,4 @@
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
/.cxx
|
||||
@@ -1,10 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
set(FILAMENT_DIR ${FILAMENT_DIST_DIR})
|
||||
|
||||
add_library(filamat STATIC IMPORTED)
|
||||
set_target_properties(filamat PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilamat.a)
|
||||
set(FILAMAT_FLAVOR "filamat")
|
||||
if(FILAMAT_LITE)
|
||||
set(FILAMAT_FLAVOR "filamat_lite")
|
||||
endif()
|
||||
|
||||
add_library(${FILAMAT_FLAVOR} STATIC IMPORTED)
|
||||
set_target_properties(${FILAMAT_FLAVOR} PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/lib${FILAMAT_FLAVOR}.a)
|
||||
|
||||
add_library(utils STATIC IMPORTED)
|
||||
set_target_properties(utils PROPERTIES IMPORTED_LOCATION
|
||||
@@ -14,10 +19,6 @@ add_library(filabridge STATIC IMPORTED)
|
||||
set_target_properties(filabridge PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilabridge.a)
|
||||
|
||||
add_library(backend STATIC IMPORTED)
|
||||
set_target_properties(backend PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libbackend.a)
|
||||
|
||||
add_library(smol-v STATIC IMPORTED)
|
||||
set_target_properties(smol-v PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libsmol-v.a)
|
||||
@@ -44,9 +45,8 @@ add_library(filamat-jni SHARED
|
||||
)
|
||||
|
||||
target_link_libraries(filamat-jni
|
||||
filamat
|
||||
${FILAMAT_FLAVOR}
|
||||
filabridge
|
||||
backend
|
||||
shaders
|
||||
utils
|
||||
log
|
||||
|
||||
@@ -13,7 +13,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "com.google.android.filament"
|
||||
version = "0.1"
|
||||
version = "1.3"
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
@@ -35,10 +35,10 @@ if (project.hasProperty("filament_dist_dir")) {
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
compileSdkVersion 29
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -47,7 +47,7 @@ android {
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments.add("-DANDROID_PIE=ON")
|
||||
arguments.add("-DANDROID_PLATFORM=android-21")
|
||||
arguments.add("-DANDROID_PLATFORM=android-19")
|
||||
arguments.add("-DANDROID_STL=c++_static")
|
||||
arguments.add("-DFILAMENT_DIST_DIR=${filament_path}".toString())
|
||||
cppFlags.add("-std=c++14")
|
||||
@@ -65,6 +65,23 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
flavorDimensions "functionality"
|
||||
productFlavors {
|
||||
full {
|
||||
dimension "functionality"
|
||||
}
|
||||
|
||||
lite {
|
||||
dimension "functionality"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments.add("-DFILAMAT_LITE=ON")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "CMakeLists.txt"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -226,17 +226,24 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderShadowM
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderCurvatureToRoughness(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean curvatureToRoughness) {
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecularAntiAliasing(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean specularAntiAliasing) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
builder->curvatureToRoughness(curvatureToRoughness);
|
||||
builder->specularAntiAliasing(specularAntiAliasing);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderLimitOverInterpolation(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean limitOverInterpolation) {
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecularAntiAliasingVariance(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jfloat variance) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
builder->limitOverInterpolation(limitOverInterpolation);
|
||||
builder->specularAntiAliasingVariance(variance);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecularAntiAliasingThreshold(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jfloat threshold) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
builder->specularAntiAliasingThreshold(threshold);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -253,6 +260,20 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderFlipUV(
|
||||
builder->flipUV(flipUV);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMultiBounceAmbientOcclusion(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean multiBounceAO) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
builder->multiBounceAmbientOcclusion(multiBounceAO);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecularAmbientOcclusion(
|
||||
JNIEnv*, jclass, jlong nativeBuilder, jboolean specularAO) {
|
||||
auto builder = (MaterialBuilder*) nativeBuilder;
|
||||
builder->specularAmbientOcclusion(specularAO);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderTransparencyMode(
|
||||
JNIEnv* env, jclass, jlong nativeBuilder, jint mode) {
|
||||
|
||||
@@ -98,7 +98,16 @@ public class MaterialBuilder {
|
||||
UV0, // texture coordinates (float2)
|
||||
UV1, // texture coordinates (float2)
|
||||
BONE_INDICES, // indices of 4 bones (uvec4)
|
||||
BONE_WEIGHTS // weights of the 4 bones (normalized float4)
|
||||
BONE_WEIGHTS, // weights of the 4 bones (normalized float4)
|
||||
UNUSED, // reserved for future use
|
||||
CUSTOM0, // custom or MORPH_POSITION_0
|
||||
CUSTOM1, // custom or MORPH_POSITION_1
|
||||
CUSTOM2, // custom or MORPH_POSITION_2
|
||||
CUSTOM3, // custom or MORPH_POSITION_3
|
||||
CUSTOM4, // custom or MORPH_TANGENTS_0
|
||||
CUSTOM5, // custom or MORPH_TANGENTS_1
|
||||
CUSTOM6, // custom or MORPH_TANGENTS_2
|
||||
CUSTOM7 // custom or MORPH_TANGENTS_3
|
||||
}
|
||||
|
||||
public enum BlendingMode {
|
||||
@@ -107,8 +116,10 @@ public class MaterialBuilder {
|
||||
// affects diffuse lighting only
|
||||
ADD, // material is additive (e.g.: hologram)
|
||||
MASKED, // material is masked (i.e. alpha tested)
|
||||
FADE // material is transparent and color is alpha-pre-multiplied,
|
||||
FADE, // material is transparent and color is alpha-pre-multiplied,
|
||||
// affects specular lighting
|
||||
MULTIPLY, // material darkens what's behind it
|
||||
SCREN // material brightens what's behind it
|
||||
}
|
||||
|
||||
public enum VertexDomain {
|
||||
@@ -142,9 +153,16 @@ public class MaterialBuilder {
|
||||
}
|
||||
|
||||
public enum TargetApi {
|
||||
ALL,
|
||||
OPENGL,
|
||||
VULKAN,
|
||||
OPENGL (0x1),
|
||||
VULKAN (0x2),
|
||||
METAL (0x4),
|
||||
ALL (0x7);
|
||||
|
||||
final int number;
|
||||
|
||||
private TargetApi(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Optimization {
|
||||
@@ -290,14 +308,20 @@ public class MaterialBuilder {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder curvatureToRoughness(boolean curvatureToRoughness) {
|
||||
nMaterialBuilderCurvatureToRoughness(mNativeObject, curvatureToRoughness);
|
||||
public MaterialBuilder specularAntiAliasing(boolean specularAntiAliasing) {
|
||||
nMaterialBuilderSpecularAntiAliasing(mNativeObject, specularAntiAliasing);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder limitOverInterpolation(boolean limitOverInterpolation) {
|
||||
nMaterialBuilderLimitOverInterpolation(mNativeObject, limitOverInterpolation);
|
||||
public MaterialBuilder specularAntiAliasingVariance(float variance) {
|
||||
nMaterialBuilderSpecularAntiAliasingVariance(mNativeObject, variance);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder specularAntiAliasingThreshold(float threshold) {
|
||||
nMaterialBuilderSpecularAntiAliasingThreshold(mNativeObject, threshold);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -313,6 +337,18 @@ public class MaterialBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder multiBounceAmbientOcclusion(boolean multiBounceAO) {
|
||||
nMaterialBuilderMultiBounceAmbientOcclusion(mNativeObject, multiBounceAO);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder specularAmbientOcclusion(boolean specularAO) {
|
||||
nMaterialBuilderSpecularAmbientOcclusion(mNativeObject, specularAO);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder transparencyMode(@NonNull TransparencyMode mode) {
|
||||
nMaterialBuilderTransparencyMode(mNativeObject, mode.ordinal());
|
||||
@@ -327,7 +363,7 @@ public class MaterialBuilder {
|
||||
|
||||
@NonNull
|
||||
public MaterialBuilder targetApi(@NonNull TargetApi api) {
|
||||
nMaterialBuilderTargetApi(mNativeObject, api.ordinal());
|
||||
nMaterialBuilderTargetApi(mNativeObject, api.number);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -408,13 +444,19 @@ public class MaterialBuilder {
|
||||
|
||||
private static native void nMaterialBuilderShadowMultiplier(long mNativeObject,
|
||||
boolean shadowMultiplier);
|
||||
private static native void nMaterialBuilderCurvatureToRoughness(long mNativeObject,
|
||||
boolean curvatureToRoughness);
|
||||
private static native void nMaterialBuilderLimitOverInterpolation(long mNativeObject,
|
||||
boolean limitOverInterpolation);
|
||||
private static native void nMaterialBuilderSpecularAntiAliasing(long mNativeObject,
|
||||
boolean specularAntiAliasing);
|
||||
private static native void nMaterialBuilderSpecularAntiAliasingVariance(long mNativeObject,
|
||||
float variance);
|
||||
private static native void nMaterialBuilderSpecularAntiAliasingThreshold(long mNativeObject,
|
||||
float threshold);
|
||||
private static native void nMaterialBuilderClearCoatIorChange(long mNativeObject,
|
||||
boolean clearCoatIorChange);
|
||||
private static native void nMaterialBuilderFlipUV(long nativeBuilder, boolean flipUV);
|
||||
private static native void nMaterialBuilderMultiBounceAmbientOcclusion(long nativeBuilder,
|
||||
boolean multiBounceAO);
|
||||
private static native void nMaterialBuilderSpecularAmbientOcclusion(long nativeBuilder,
|
||||
boolean specularAO);
|
||||
private static native void nMaterialBuilderTransparencyMode(long nativeBuilder, int mode);
|
||||
private static native void nMaterialBuilderPlatform(long nativeBuilder, int platform);
|
||||
private static native void nMaterialBuilderTargetApi(long nativeBuilder, int api);
|
||||
|
||||
1
android/filament-android/.gitignore
vendored
1
android/filament-android/.gitignore
vendored
@@ -9,3 +9,4 @@
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
/.cxx
|
||||
Binary file not shown.
134
android/filament-android/.idea/codeStyles/Project.xml
generated
134
android/filament-android/.idea/codeStyles/Project.xml
generated
@@ -1,29 +1,113 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<Objective-C-extensions>
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="h" fileNamingConvention="NONE" />
|
||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
<codeStyleSettings language="XML">
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
@@ -1,5 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Google Configuration Checker Style" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
set(FILAMENT_DIR ${FILAMENT_DIST_DIR})
|
||||
|
||||
@@ -14,6 +14,10 @@ add_library(utils STATIC IMPORTED)
|
||||
set_target_properties(utils PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libutils.a)
|
||||
|
||||
add_library(ibl STATIC IMPORTED)
|
||||
set_target_properties(ibl PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libibl.a)
|
||||
|
||||
add_library(filaflat STATIC IMPORTED)
|
||||
set_target_properties(filaflat PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilaflat.a)
|
||||
@@ -35,7 +39,7 @@ set_target_properties(smol-v PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libsmol-v.a)
|
||||
|
||||
|
||||
include_directories(${FILAMENT_DIR}/include)
|
||||
include_directories(.. ${FILAMENT_DIR}/include)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-stack-protector")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti")
|
||||
@@ -46,54 +50,66 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -ff
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${CMAKE_SOURCE_DIR}/libfilament-jni.map")
|
||||
|
||||
add_library(filament-jni SHARED
|
||||
src/main/cpp/Camera.cpp
|
||||
src/main/cpp/Colors.cpp
|
||||
src/main/cpp/VertexBuffer.cpp
|
||||
src/main/cpp/Engine.cpp
|
||||
src/main/cpp/EntityManager.cpp
|
||||
src/main/cpp/Fence.cpp
|
||||
src/main/cpp/IndexBuffer.cpp
|
||||
src/main/cpp/IndirectLight.cpp
|
||||
src/main/cpp/LightManager.cpp
|
||||
src/main/cpp/Material.cpp
|
||||
src/main/cpp/MaterialInstance.cpp
|
||||
src/main/cpp/MathUtils.cpp
|
||||
src/main/cpp/RenderableManager.cpp
|
||||
src/main/cpp/Renderer.cpp
|
||||
src/main/cpp/Scene.cpp
|
||||
src/main/cpp/SkyBox.cpp
|
||||
src/main/cpp/Stream.cpp
|
||||
src/main/cpp/Texture.cpp
|
||||
src/main/cpp/TextureSampler.cpp
|
||||
src/main/cpp/TransformManager.cpp
|
||||
src/main/cpp/View.cpp
|
||||
# Android specific
|
||||
src/main/cpp/nativewindow/Android.cpp
|
||||
# Private utils
|
||||
src/main/cpp/CallbackUtils.cpp
|
||||
src/main/cpp/Filament.cpp
|
||||
src/main/cpp/NioUtils.cpp
|
||||
add_library(filament-jni-obj OBJECT
|
||||
src/main/cpp/Camera.cpp
|
||||
src/main/cpp/Colors.cpp
|
||||
src/main/cpp/VertexBuffer.cpp
|
||||
src/main/cpp/Engine.cpp
|
||||
src/main/cpp/EntityManager.cpp
|
||||
src/main/cpp/Fence.cpp
|
||||
src/main/cpp/IndexBuffer.cpp
|
||||
src/main/cpp/IndirectLight.cpp
|
||||
src/main/cpp/LightManager.cpp
|
||||
src/main/cpp/Material.cpp
|
||||
src/main/cpp/MaterialInstance.cpp
|
||||
src/main/cpp/MathUtils.cpp
|
||||
src/main/cpp/RenderableManager.cpp
|
||||
src/main/cpp/Renderer.cpp
|
||||
src/main/cpp/RenderTarget.cpp
|
||||
src/main/cpp/Scene.cpp
|
||||
src/main/cpp/SkyBox.cpp
|
||||
src/main/cpp/Stream.cpp
|
||||
src/main/cpp/Texture.cpp
|
||||
src/main/cpp/TextureSampler.cpp
|
||||
src/main/cpp/TransformManager.cpp
|
||||
src/main/cpp/View.cpp
|
||||
# Android specific
|
||||
src/main/cpp/nativewindow/Android.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(filament-jni
|
||||
filament
|
||||
backend
|
||||
filaflat
|
||||
filabridge
|
||||
geometry
|
||||
utils
|
||||
log
|
||||
GLESv3
|
||||
EGL
|
||||
android
|
||||
jnigraphics
|
||||
)
|
||||
if (NOT DISABLE_FILAMENT_JNI)
|
||||
|
||||
option(FILAMENT_SUPPORTS_VULKAN "Enables Vulkan on Android" OFF)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libfilament-jni.map")
|
||||
|
||||
add_library(filament-jni SHARED
|
||||
$<TARGET_OBJECTS:filament-jni-obj>
|
||||
# Private utils
|
||||
src/main/cpp/Filament.cpp
|
||||
# Common utils
|
||||
../common/CallbackUtils.cpp
|
||||
../common/NioUtils.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(filament-jni
|
||||
filament
|
||||
backend
|
||||
filaflat
|
||||
filabridge
|
||||
geometry
|
||||
ibl
|
||||
utils
|
||||
log
|
||||
GLESv3
|
||||
EGL
|
||||
android
|
||||
jnigraphics
|
||||
)
|
||||
|
||||
option(FILAMENT_SUPPORTS_VULKAN "Enables Vulkan on Android" OFF)
|
||||
|
||||
if (FILAMENT_SUPPORTS_VULKAN)
|
||||
target_link_libraries(filament-jni bluevk smol-v)
|
||||
endif()
|
||||
|
||||
if (FILAMENT_SUPPORTS_VULKAN)
|
||||
target_link_libraries(filament-jni bluevk smol-v)
|
||||
endif()
|
||||
|
||||
@@ -13,7 +13,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "com.google.android.filament"
|
||||
version = "0.1"
|
||||
version = "1.3"
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
@@ -35,13 +35,13 @@ if (project.hasProperty("filament_dist_dir")) {
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
compileSdkVersion 29
|
||||
defaultConfig {
|
||||
// Our minSdkVersion is actually 21, we lie and say 14 here so apps don't have
|
||||
// Our minSdkVersion is actually 19, we lie and say 14 here so apps don't have
|
||||
// to increase their minSdkVersion unnecessarily. It is however up to them to
|
||||
// ensure they do not initialize Filament on API levels < 21.
|
||||
// ensure they do not initialize Filament on API levels < 19.
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -50,7 +50,7 @@ android {
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments.add("-DANDROID_PIE=ON")
|
||||
arguments.add("-DANDROID_PLATFORM=android-21")
|
||||
arguments.add("-DANDROID_PLATFORM=android-19")
|
||||
arguments.add("-DANDROID_STL=c++_static")
|
||||
arguments.add("-DFILAMENT_DIST_DIR=${filament_path}".toString())
|
||||
cppFlags.add("-std=c++14")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
25
android/filament-android/proguard-rules.pro
vendored
25
android/filament-android/proguard-rules.pro
vendored
@@ -5,17 +5,18 @@
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
# JNI is an entry point that's hard to keep track of, so there's
|
||||
# an annotation to mark fields and methods used by native code.
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
# Keep the annotations that proguard needs to process.
|
||||
-keep class com.google.android.filament.proguard.UsedBy*
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
# Just because native code accesses members of a class, does not mean that the
|
||||
# class itself needs to be annotated - only annotate classes that are
|
||||
# referenced themselves in native code.
|
||||
-keep @com.google.android.filament.proguard.UsedBy* class * {
|
||||
<init>();
|
||||
}
|
||||
-keepclassmembers class * {
|
||||
@com.google.android.filament.proguard.UsedBy* *;
|
||||
}
|
||||
|
||||
@@ -154,9 +154,9 @@ Java_com_google_android_filament_Engine_nDestroyScene(JNIEnv*, jclass,
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_Engine_nCreateFence(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jint fenceType) {
|
||||
jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return (jlong) engine->createFence((Fence::Type) fenceType);
|
||||
return (jlong) engine->createFence();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -236,6 +236,14 @@ Java_com_google_android_filament_Engine_nDestroyTexture(JNIEnv*, jclass,
|
||||
engine->destroy(texture);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyRenderTarget(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeTarget) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
RenderTarget* target = (RenderTarget*) nativeTarget;
|
||||
engine->destroy(target);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyEntity(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jint entity_) {
|
||||
@@ -244,6 +252,13 @@ Java_com_google_android_filament_Engine_nDestroyEntity(JNIEnv*, jclass,
|
||||
engine->destroy(entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nFlushAndWait(JNIEnv *env, jclass clazz,
|
||||
jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
engine->flushAndWait();
|
||||
}
|
||||
|
||||
// Managers...
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include <filament/IndexBuffer.h>
|
||||
|
||||
#include "CallbackUtils.h"
|
||||
#include "NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <filament/IndirectLight.h>
|
||||
#include <filament/Texture.h>
|
||||
#include <common/NioUtils.h>
|
||||
#include <common/CallbackUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
|
||||
@@ -57,6 +60,15 @@ Java_com_google_android_filament_IndirectLight_nIrradiance(JNIEnv* env, jclass,
|
||||
env->ReleaseFloatArrayElements(sh_, sh, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nRadiance(JNIEnv* env, jclass,
|
||||
jlong nativeBuilder, jint bands, jfloatArray sh_) {
|
||||
IndirectLight::Builder* builder = (IndirectLight::Builder*) nativeBuilder;
|
||||
jfloat* sh = env->GetFloatArrayElements(sh_, NULL);
|
||||
builder->radiance((uint8_t) bands, (const filament::math::float3*) sh);
|
||||
env->ReleaseFloatArrayElements(sh_, sh, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nIrradianceAsTexture(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeTexture) {
|
||||
@@ -80,8 +92,6 @@ Java_com_google_android_filament_IndirectLight_nRotation(JNIEnv *, jclass, jlong
|
||||
builder->rotation(filament::math::mat3f{v0, v1, v2, v3, v4, v5, v6, v7, v8});
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nSetIntensity(JNIEnv*, jclass,
|
||||
jlong nativeIndirectLight, jfloat intensity) {
|
||||
@@ -97,9 +107,38 @@ Java_com_google_android_filament_IndirectLight_nGetIntensity(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nSetRotation(JNIEnv *env, jclass type,
|
||||
jlong nativeIndirectLight, jfloat v0, jfloat v1, jfloat v2, jfloat v3, jfloat v4, jfloat v5,
|
||||
jfloat v6, jfloat v7, jfloat v8) {
|
||||
Java_com_google_android_filament_IndirectLight_nSetRotation(JNIEnv*, jclass,
|
||||
jlong nativeIndirectLight, jfloat v0, jfloat v1, jfloat v2,
|
||||
jfloat v3, jfloat v4, jfloat v5, jfloat v6, jfloat v7, jfloat v8) {
|
||||
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
|
||||
indirectLight->setRotation(filament::math::mat3f{v0, v1, v2, v3, v4, v5, v6, v7, v8});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nGetRotation(JNIEnv* env, jclass,
|
||||
jlong nativeIndirectLight, jfloatArray outRotation_) {
|
||||
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
|
||||
jfloat *outRotation = env->GetFloatArrayElements(outRotation_, NULL);
|
||||
*reinterpret_cast<filament::math::mat3f*>(outRotation) = indirectLight->getRotation();
|
||||
env->ReleaseFloatArrayElements(outRotation_, outRotation, 0);
|
||||
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nGetDirectionEstimate(JNIEnv* env, jclass,
|
||||
jlong nativeIndirectLight, jfloatArray outDirection_) {
|
||||
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
|
||||
jfloat *outDirection = env->GetFloatArrayElements(outDirection_, NULL);
|
||||
*reinterpret_cast<filament::math::float3*>(outDirection) = indirectLight->getDirectionEstimate();
|
||||
env->ReleaseFloatArrayElements(outDirection_, outDirection, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nGetColorEstimate(JNIEnv* env, jclass,
|
||||
jlong nativeIndirectLight, jfloatArray outColor_, float x, float y, float z) {
|
||||
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
|
||||
jfloat *outColor = env->GetFloatArrayElements(outColor_, NULL);
|
||||
*reinterpret_cast<filament::math::float4*>(outColor) =
|
||||
indirectLight->getColorEstimate(math::float3{x, y, z});
|
||||
env->ReleaseFloatArrayElements(outColor_, outColor, 0);
|
||||
}
|
||||
|
||||
@@ -22,48 +22,47 @@ using namespace filament;
|
||||
using namespace utils;
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_LightManager_nHasComponent(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nHasComponent(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint entity) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return (jboolean) lm->hasComponent((Entity &) entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetInstance(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetInstance(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint entity) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return lm->getInstance((Entity &) entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nDestroy(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nDestroy(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint entity) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->destroy((Entity &) entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_LightManager_nCreateBuilder(JNIEnv *env, jclass type,
|
||||
jint lightType) {
|
||||
Java_com_google_android_filament_LightManager_nCreateBuilder(JNIEnv*, jclass, jint lightType) {
|
||||
return (jlong) new LightManager::Builder((LightManager::Type) lightType);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nDestroyBuilder(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nDestroyBuilder(JNIEnv*, jclass,
|
||||
jlong nativeBuilder) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
delete builder;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderCastShadows(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderCastShadows(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean enable) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->castShadows(enable);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint mapSize, jfloat constantBias, jfloat normalBias, jfloat shadowFar,
|
||||
jfloat shadowNearHint, jfloat shadowFarHint, jboolean stable) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
@@ -78,84 +77,84 @@ Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv *env,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderCastLight(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderCastLight(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean enabled) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->castLight(enabled);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderPosition(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderPosition(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat x, jfloat y, jfloat z) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->position({x, y, z});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderDirection(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderDirection(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat x, jfloat y, jfloat z) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->direction({x, y, z});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderColor(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderColor(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat linearR, jfloat linearG, jfloat linearB) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->color({linearR, linearG, linearB});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderIntensity__JF(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderIntensity__JF(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat intensity) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->intensity(intensity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderIntensity__JFF(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderIntensity__JFF(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat watts, jfloat efficiency) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->intensity(watts, efficiency);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderFalloff(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderFalloff(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat radius) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->falloff(radius);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderSpotLightCone(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderSpotLightCone(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat inner, jfloat outer) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->spotLightCone(inner, outer);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderAngularRadius(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderAngularRadius(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat angularRadius) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->sunAngularRadius(angularRadius);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderHaloSize(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderHaloSize(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat haloSize) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->sunHaloSize(haloSize);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderHaloFalloff(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nBuilderHaloFalloff(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jfloat haloFalloff) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
builder->sunHaloFalloff(haloFalloff);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderBuild(JNIEnv *env, jclass type,
|
||||
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;
|
||||
@@ -170,133 +169,147 @@ Java_com_google_android_filament_LightManager_nGetType(JNIEnv* env,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetPosition(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetPosition(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat x, jfloat y, jfloat z) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setPosition((LightManager::Instance) i, {x, y, z});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetPosition(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetPosition(JNIEnv* env, jclass,
|
||||
jlong nativeLightManager, jint i, jfloatArray out_) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
jfloat *out = env->GetFloatArrayElements(out_, NULL);
|
||||
jfloat *out = env->GetFloatArrayElements(out_, nullptr);
|
||||
*reinterpret_cast<filament::math::float3 *>(out) = lm->getPosition((LightManager::Instance) i);
|
||||
env->ReleaseFloatArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetDirection(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetDirection(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat x, jfloat y, jfloat z) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setDirection((LightManager::Instance) i, {x, y, z});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetDirection(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetDirection(JNIEnv *env, jclass,
|
||||
jlong nativeLightManager, jint i, jfloatArray out_) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
jfloat *out = env->GetFloatArrayElements(out_, NULL);
|
||||
jfloat *out = env->GetFloatArrayElements(out_, nullptr);
|
||||
*reinterpret_cast<filament::math::float3 *>(out) = lm->getDirection((LightManager::Instance) i);
|
||||
env->ReleaseFloatArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetColor(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetColor(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat linearR, jfloat linearG, jfloat linearB) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setColor((LightManager::Instance) i, {linearR, linearG, linearB});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetColor(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetColor(JNIEnv *env, jclass,
|
||||
jlong nativeLightManager, jint i, jfloatArray out_) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
jfloat *out = env->GetFloatArrayElements(out_, NULL);
|
||||
jfloat *out = env->GetFloatArrayElements(out_, nullptr);
|
||||
*reinterpret_cast<filament::math::float3 *>(out) = lm->getColor((LightManager::Instance) i);
|
||||
env->ReleaseFloatArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetIntensity__JIF(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetIntensity__JIF(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat intensity) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setIntensity((LightManager::Instance) i, intensity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetIntensity__JIFF(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetIntensity__JIFF(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat watts, jfloat efficiency) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setIntensity((LightManager::Instance) i, watts, efficiency);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetIntensity(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetIntensity(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return lm->getIntensity((LightManager::Instance) i);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetFalloff(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetFalloff(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat falloff) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setFalloff((LightManager::Instance) i, falloff);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetFalloff(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetFalloff(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return lm->getFalloff((LightManager::Instance) i);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetSpotLightCone(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetSpotLightCone(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat inner, jfloat outer) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setSpotLightCone((LightManager::Instance) i, inner, outer);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetSunAngularRadius(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetSunAngularRadius(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat angularRadius) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setSunAngularRadius((LightManager::Instance) i, angularRadius);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetSunAngularRadius(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetSunAngularRadius(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return lm->getSunAngularRadius((LightManager::Instance) i);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetSunHaloSize(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetSunHaloSize(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat haloSize) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setSunHaloSize((LightManager::Instance) i, haloSize);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetHaloSize(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetHaloSize(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return lm->getSunHaloSize((LightManager::Instance) i);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetSunHaloFalloff(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nSetSunHaloFalloff(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat haloFalloff) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setSunHaloFalloff((LightManager::Instance) i, haloFalloff);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetHaloFalloff(JNIEnv *env, jclass type,
|
||||
Java_com_google_android_filament_LightManager_nGetHaloFalloff(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return lm->getSunHaloFalloff((LightManager::Instance) i);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nSetShadowCaster(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i, jfloat shadowCaster) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
lm->setShadowCaster((LightManager::Instance) i, shadowCaster);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_LightManager_nIsShadowCaster(JNIEnv*, jclass,
|
||||
jlong nativeLightManager, jint i) {
|
||||
LightManager *lm = (LightManager *) nativeLightManager;
|
||||
return lm->isShadowCaster((LightManager::Instance) i);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <filament/Material.h>
|
||||
|
||||
#include "NioUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
|
||||
@@ -140,6 +140,22 @@ Java_com_google_android_filament_Material_nGetMaskThreshold(JNIEnv*, jclass,
|
||||
return material->getMaskThreshold();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_Material_nGetSpecularAntiAliasingVariance(JNIEnv*, jclass,
|
||||
jlong nativeMaterial) {
|
||||
Material* material = (Material*) nativeMaterial;
|
||||
return material->getSpecularAntiAliasingVariance();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_Material_nGetSpecularAntiAliasingThreshold(JNIEnv*, jclass,
|
||||
jlong nativeMaterial) {
|
||||
Material* material = (Material*) nativeMaterial;
|
||||
return material->getSpecularAntiAliasingThreshold();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_Material_nGetParameterCount(JNIEnv*, jclass,
|
||||
|
||||
@@ -27,6 +27,30 @@
|
||||
#include <math/vec4.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
|
||||
enum BooleanElement {
|
||||
BOOL,
|
||||
BOOL2,
|
||||
BOOL3,
|
||||
BOOL4
|
||||
};
|
||||
|
||||
enum IntElement {
|
||||
INT,
|
||||
INT2,
|
||||
INT3,
|
||||
INT4
|
||||
};
|
||||
|
||||
enum FloatElement {
|
||||
FLOAT,
|
||||
FLOAT2,
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
MAT3,
|
||||
MAT4
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static void setParameter(JNIEnv* env, jlong nativeMaterialInstance, jstring name_, T v) {
|
||||
@@ -47,14 +71,14 @@ extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterBool2(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_, jboolean x, jboolean y) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::bool2{x, y});
|
||||
setParameter(env, nativeMaterialInstance, name_, bool2{x, y});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterBool3(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_, jboolean x, jboolean y, jboolean z) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::bool3{x, y, z});
|
||||
setParameter(env, nativeMaterialInstance, name_, bool3{x, y, z});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -62,7 +86,7 @@ JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterBool4(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_,
|
||||
jboolean x, jboolean y, jboolean z, jboolean w) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::bool4{x, y, z, w});
|
||||
setParameter(env, nativeMaterialInstance, name_, bool4{x, y, z, w});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -76,14 +100,14 @@ extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterInt2(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_, jint x, jint y) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::int2{x, y});
|
||||
setParameter(env, nativeMaterialInstance, name_, int2{x, y});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterInt3(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_, jint x, jint y, jint z) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::int3{x, y, z});
|
||||
setParameter(env, nativeMaterialInstance, name_, int3{x, y, z});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -91,7 +115,7 @@ JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterInt4(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_,
|
||||
jint x, jint y, jint z, jint w) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::int4{x, y, z, w});
|
||||
setParameter(env, nativeMaterialInstance, name_, int4{x, y, z, w});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -105,14 +129,14 @@ extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterFloat2(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_, jfloat x, jfloat y) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::float2{x, y});
|
||||
setParameter(env, nativeMaterialInstance, name_, float2{x, y});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterFloat3(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_, jfloat x, jfloat y, jfloat z) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::float3{x, y, z});
|
||||
setParameter(env, nativeMaterialInstance, name_, float3{x, y, z});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -120,7 +144,7 @@ JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetParameterFloat4(JNIEnv *env, jclass,
|
||||
jlong nativeMaterialInstance, jstring name_,
|
||||
jfloat x, jfloat y, jfloat z, jfloat w) {
|
||||
setParameter(env, nativeMaterialInstance, name_, filament::math::float4{x, y, z, w});
|
||||
setParameter(env, nativeMaterialInstance, name_, float4{x, y, z, w});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -131,9 +155,26 @@ Java_com_google_android_filament_MaterialInstance_nSetBooleanParameterArray(JNIE
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
|
||||
const char* name = env->GetStringUTFChars(name_, 0);
|
||||
size_t size = (size_t) element + 1;
|
||||
jboolean* v = env->GetBooleanArrayElements(v_, NULL);
|
||||
instance->setParameter(name, (bool*) (v + offset * size), (size_t) (count * size));
|
||||
|
||||
// NOTE: In C++, bool has an implementation-defined size. Here we assume
|
||||
// it has the same size as jboolean, which is 1 byte.
|
||||
|
||||
switch ((BooleanElement) element) {
|
||||
case BOOL:
|
||||
instance->setParameter(name, ((const bool*) v) + offset, count);
|
||||
break;
|
||||
case BOOL2:
|
||||
instance->setParameter(name, ((const bool2*) v) + offset, count);
|
||||
break;
|
||||
case BOOL3:
|
||||
instance->setParameter(name, ((const bool3*) v) + offset, count);
|
||||
break;
|
||||
case BOOL4:
|
||||
instance->setParameter(name, ((const bool4*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
|
||||
env->ReleaseBooleanArrayElements(v_, v, 0);
|
||||
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
@@ -147,10 +188,23 @@ Java_com_google_android_filament_MaterialInstance_nSetIntParameterArray(JNIEnv *
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
|
||||
const char* name = env->GetStringUTFChars(name_, 0);
|
||||
size_t size = (size_t) element + 1;
|
||||
jint* v = env->GetIntArrayElements(v_, NULL);
|
||||
instance->setParameter(name, reinterpret_cast<int32_t*>(v + offset * size),
|
||||
(size_t) (count * size));
|
||||
|
||||
switch ((IntElement) element) {
|
||||
case INT:
|
||||
instance->setParameter(name, ((const int32_t*) v) + offset, count);
|
||||
break;
|
||||
case INT2:
|
||||
instance->setParameter(name, ((const int2*) v) + offset, count);
|
||||
break;
|
||||
case INT3:
|
||||
instance->setParameter(name, ((const int3*) v) + offset, count);
|
||||
break;
|
||||
case INT4:
|
||||
instance->setParameter(name, ((const int4*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
|
||||
env->ReleaseIntArrayElements(v_, v, 0);
|
||||
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
@@ -164,16 +218,29 @@ Java_com_google_android_filament_MaterialInstance_nSetFloatParameterArray(JNIEnv
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
|
||||
const char* name = env->GetStringUTFChars(name_, 0);
|
||||
size_t size = (size_t) element + 1;
|
||||
if (size == 5) {
|
||||
// mat3
|
||||
size = 9;
|
||||
} else if (size == 6) {
|
||||
// mat4
|
||||
size = 16;
|
||||
}
|
||||
jfloat* v = env->GetFloatArrayElements(v_, NULL);
|
||||
instance->setParameter(name, v + offset * size, (size_t) (count * size));
|
||||
|
||||
switch ((FloatElement) element) {
|
||||
case FLOAT:
|
||||
instance->setParameter(name, ((const float*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT2:
|
||||
instance->setParameter(name, ((const float2*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT3:
|
||||
instance->setParameter(name, ((const float3*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT4:
|
||||
instance->setParameter(name, ((const float4*) v) + offset, count);
|
||||
break;
|
||||
case MAT3:
|
||||
instance->setParameter(name, ((const mat3f*) v) + offset, count);
|
||||
break;
|
||||
case MAT4:
|
||||
instance->setParameter(name, ((const mat4f*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
|
||||
env->ReleaseFloatArrayElements(v_, v, 0);
|
||||
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
@@ -226,6 +293,22 @@ Java_com_google_android_filament_MaterialInstance_nSetMaskThreshold(JNIEnv*,
|
||||
instance->setMaskThreshold(threshold);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetSpecularAntiAliasingVariance(JNIEnv*,
|
||||
jclass, jlong nativeMaterialInstance, jfloat variance) {
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
instance->setSpecularAntiAliasingVariance(variance);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetSpecularAntiAliasingThreshold(JNIEnv*,
|
||||
jclass, jlong nativeMaterialInstance, jfloat threshold) {
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
instance->setSpecularAntiAliasingThreshold(threshold);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetDoubleSided(JNIEnv*,
|
||||
@@ -233,3 +316,11 @@ Java_com_google_android_filament_MaterialInstance_nSetDoubleSided(JNIEnv*,
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
instance->setDoubleSided(doubleSided);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nSetCullingMode(JNIEnv*,
|
||||
jclass, jlong nativeMaterialInstance, jlong cullingMode) {
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
instance->setCullingMode((MaterialInstance::CullingMode) cullingMode);
|
||||
}
|
||||
|
||||
83
android/filament-android/src/main/cpp/RenderTarget.cpp
Normal file
83
android/filament-android/src/main/cpp/RenderTarget.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 <functional>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <filament/RenderTarget.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nCreateBuilder(JNIEnv *env, jclass type) {
|
||||
return (jlong) new RenderTarget::Builder();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nDestroyBuilder(JNIEnv *env, jclass type,
|
||||
jlong nativeBuilder) {
|
||||
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
|
||||
delete builder;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nBuilderTexture(JNIEnv *env, jclass type,
|
||||
jlong nativeBuilder, jlong attachment, jlong nativeTexture) {
|
||||
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
|
||||
Texture* texture = (Texture*) nativeTexture;
|
||||
builder->texture(RenderTarget::AttachmentPoint(attachment), texture);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nBuilderMipLevel(JNIEnv *env, jclass type,
|
||||
jlong nativeBuilder, jlong attachment, jint level) {
|
||||
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
|
||||
builder->mipLevel(RenderTarget::AttachmentPoint(attachment), level);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nBuilderFace(JNIEnv *env, jclass type,
|
||||
jlong nativeBuilder, jlong attachment, jint face) {
|
||||
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
|
||||
RenderTarget::CubemapFace cubeface = (RenderTarget::CubemapFace) face;
|
||||
builder->face(RenderTarget::AttachmentPoint(attachment), cubeface);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nBuilderLayer(JNIEnv *env, jclass type,
|
||||
jlong nativeBuilder, jlong attachment, jint layer) {
|
||||
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
|
||||
builder->layer(RenderTarget::AttachmentPoint(attachment), layer);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nBuilderBuild(JNIEnv *env, jclass type,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_RenderTarget_nGetMipLevel(JNIEnv *env, jclass type,
|
||||
jlong nativeTarget, jlong attachment) {
|
||||
RenderTarget* target = (RenderTarget*) nativeTarget;
|
||||
return (jint) target->getMipLevel(RenderTarget::AttachmentPoint(attachment));
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <filament/RenderableManager.h>
|
||||
#include "NioUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
@@ -182,6 +182,12 @@ Java_com_google_android_filament_RenderableManager_nBuilderSkinningBones(JNIEnv*
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nBuilderMorphing(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean enabled) {
|
||||
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
|
||||
builder->morphing(enabled);
|
||||
}
|
||||
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -218,6 +224,16 @@ Java_com_google_android_filament_RenderableManager_nSetBonesAsQuaternions(JNIEnv
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetMorphWeights(JNIEnv* env, jclass,
|
||||
jlong nativeRenderableManager, jint instance, jfloatArray weights) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
jfloat* vec = env->GetFloatArrayElements(weights, NULL);
|
||||
math::float4 floatvec(vec[0], vec[1], vec[2], vec[3]);
|
||||
env->ReleaseFloatArrayElements(weights, vec, JNI_ABORT);
|
||||
rm->setMorphWeights((RenderableManager::Instance)instance, floatvec);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetAxisAlignedBoundingBox(JNIEnv*,
|
||||
jclass, jlong nativeRenderableManager, jint i, jfloat cx, jfloat cy, jfloat cz,
|
||||
@@ -299,6 +315,21 @@ Java_com_google_android_filament_RenderableManager_nSetMaterialInstanceAt(JNIEnv
|
||||
materialInstance);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT long 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,
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#include <filament/Viewport.h>
|
||||
#include <backend/PixelBufferDescriptor.h>
|
||||
|
||||
#include "CallbackUtils.h"
|
||||
#include "NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
@@ -51,7 +51,7 @@ Java_com_google_android_filament_Renderer_nRender(JNIEnv *, jclass, jlong native
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nMirrorFrame(JNIEnv *, jclass, jlong nativeRenderer,
|
||||
Java_com_google_android_filament_Renderer_nCopyFrame(JNIEnv *, jclass, jlong nativeRenderer,
|
||||
jlong nativeDstSwapChain,
|
||||
jint dstLeft, jint dstBottom, jint dstWidth, jint dstHeight,
|
||||
jint srcLeft, jint srcBottom, jint srcWidth, jint srcHeight,
|
||||
@@ -60,7 +60,7 @@ Java_com_google_android_filament_Renderer_nMirrorFrame(JNIEnv *, jclass, jlong n
|
||||
SwapChain *dstSwapChain = (SwapChain *) nativeDstSwapChain;
|
||||
const filament::Viewport dstViewport {dstLeft, dstBottom, (uint32_t) dstWidth, (uint32_t) dstHeight};
|
||||
const filament::Viewport srcViewport {srcLeft, srcBottom, (uint32_t) srcWidth, (uint32_t) srcHeight};
|
||||
renderer->mirrorFrame(dstSwapChain, dstViewport, srcViewport, (uint32_t) flags);
|
||||
renderer->copyFrame(dstSwapChain, dstViewport, srcViewport, (uint32_t) flags);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
|
||||
@@ -44,6 +44,15 @@ Java_com_google_android_filament_Scene_nAddEntity(JNIEnv *env, jclass type, jlon
|
||||
scene->addEntity((Entity&) entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Scene_nAddEntities(JNIEnv *env, jclass type, jlong nativeScene,
|
||||
jintArray entities) {
|
||||
Scene* scene = (Scene*) nativeScene;
|
||||
Entity* nativeEntities = (Entity*) env->GetIntArrayElements(entities, nullptr);
|
||||
scene->addEntities(nativeEntities, env->GetArrayLength(entities));
|
||||
env->ReleaseIntArrayElements(entities, (jint*) nativeEntities, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Scene_nRemove(JNIEnv *env, jclass type, jlong nativeScene,
|
||||
jint entity) {
|
||||
|
||||
@@ -47,6 +47,13 @@ Java_com_google_android_filament_Skybox_nBuilderShowSun(JNIEnv *env, jclass type
|
||||
builder->showSun(show);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Skybox_nBuilderIntensity(JNIEnv *env, jclass clazz,
|
||||
jlong nativeSkyBoxBuilder, jfloat intensity) {
|
||||
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
|
||||
builder->intensity(intensity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_Skybox_nBuilderBuild(JNIEnv *env, jclass type,
|
||||
jlong nativeSkyBoxBuilder, jlong nativeEngine) {
|
||||
@@ -68,3 +75,10 @@ Java_com_google_android_filament_Skybox_nGetLayerMask(JNIEnv *env, jclass type,
|
||||
Skybox *skybox = (Skybox *) nativeSkybox;
|
||||
return static_cast<jint>(skybox->getLayerMask());
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_Skybox_nGetIntensity(JNIEnv *env, jclass clazz,
|
||||
jlong nativeSkybox) {
|
||||
Skybox *skybox = (Skybox *) nativeSkybox;
|
||||
return static_cast<jint>(skybox->getIntensity());
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <filament/Stream.h>
|
||||
#include <backend/PixelBufferDescriptor.h>
|
||||
|
||||
#include "NioUtils.h"
|
||||
#include "CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include <filament/Stream.h>
|
||||
#include <filament/Texture.h>
|
||||
|
||||
#include "CallbackUtils.h"
|
||||
#include "NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
@@ -107,10 +107,10 @@ Java_com_google_android_filament_Texture_nBuilderFormat(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Texture_nBuilderRgbm(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jboolean enable) {
|
||||
Java_com_google_android_filament_Texture_nBuilderUsage(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jint flags) {
|
||||
Texture::Builder *builder = (Texture::Builder *) nativeBuilder;
|
||||
builder->rgbm(enable);
|
||||
builder->usage((Texture::Usage) flags);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
@@ -163,12 +163,6 @@ Java_com_google_android_filament_Texture_nGetInternalFormat(JNIEnv*, jclass,
|
||||
return (jint) texture->getFormat();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Texture_nGetRgbm(JNIEnv*, jclass, jlong nativeTexture) {
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
return static_cast<jboolean>(texture->isRgbm());
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_Texture_nSetImage(JNIEnv* env, jclass, jlong nativeTexture,
|
||||
jlong nativeEngine, jint level, jint xoffset, jint yoffset, jint width, jint height,
|
||||
@@ -183,7 +177,7 @@ Java_com_google_android_filament_Texture_nSetImage(JNIEnv* env, jclass, jlong na
|
||||
(Texture::Type) type, (size_t) stride, (size_t) alignment);
|
||||
|
||||
AutoBuffer nioBuffer(env, storage, 0);
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
@@ -205,8 +199,7 @@ extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_Texture_nSetImageCompressed(JNIEnv *env, jclass,
|
||||
jlong nativeTexture, jlong nativeEngine, jint level, jint xoffset, jint yoffset,
|
||||
jint width, jint height, jobject storage, jint remaining,
|
||||
jint left, jint bottom, jint type, jint alignment,
|
||||
jint compressedSizeInBytes, jint compressedFormat,
|
||||
jint, jint, jint, jint, jint compressedSizeInBytes, jint compressedFormat,
|
||||
jobject handler, jobject runnable) {
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
@@ -214,7 +207,7 @@ Java_com_google_android_filament_Texture_nSetImageCompressed(JNIEnv *env, jclass
|
||||
size_t sizeInBytes = (size_t) compressedSizeInBytes;
|
||||
|
||||
AutoBuffer nioBuffer(env, storage, 0);
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
@@ -241,7 +234,7 @@ Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
|
||||
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, NULL);
|
||||
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, nullptr);
|
||||
Texture::FaceOffsets faceOffsets;
|
||||
std::copy_n(faceOffsetsInBytes, 6, faceOffsets.offsets);
|
||||
env->ReleaseIntArrayElements(faceOffsetsInBytes_, faceOffsetsInBytes, JNI_ABORT);
|
||||
@@ -250,7 +243,7 @@ Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
|
||||
(Texture::Type) type, (size_t) stride, (size_t) alignment);
|
||||
|
||||
AutoBuffer nioBuffer(env, storage, 0);
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
@@ -277,7 +270,7 @@ Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env,
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
|
||||
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, NULL);
|
||||
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, nullptr);
|
||||
Texture::FaceOffsets faceOffsets;
|
||||
std::copy_n(faceOffsetsInBytes, 6, faceOffsets.offsets);
|
||||
env->ReleaseIntArrayElements(faceOffsetsInBytes_, faceOffsetsInBytes, JNI_ABORT);
|
||||
@@ -285,7 +278,7 @@ Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env,
|
||||
size_t sizeInBytes = 6 * (size_t) compressedSizeInBytes;
|
||||
|
||||
AutoBuffer nioBuffer(env, storage, 0);
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
@@ -335,6 +328,49 @@ Java_com_google_android_filament_Texture_nIsStreamValidForTexture(JNIEnv*, jclas
|
||||
return (jboolean) (texture->getTarget() == SamplerType::SAMPLER_EXTERNAL);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_Texture_nGeneratePrefilterMipmap(JNIEnv *env, jclass,
|
||||
jlong nativeTexture, jlong nativeEngine, jint width, jint height,
|
||||
jobject storage, jint remaining, jint left,
|
||||
jint top, jint type, jint alignment, jint stride, jint format,
|
||||
jintArray faceOffsetsInBytes_, jobject handler, jobject runnable, jint sampleCount,
|
||||
jboolean mirror) {
|
||||
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
|
||||
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, nullptr);
|
||||
Texture::FaceOffsets faceOffsets;
|
||||
std::copy_n(faceOffsetsInBytes, 6, faceOffsets.offsets);
|
||||
env->ReleaseIntArrayElements(faceOffsetsInBytes_, faceOffsetsInBytes, JNI_ABORT);
|
||||
|
||||
stride = stride ? stride : width;
|
||||
size_t sizeInBytes = 6 *
|
||||
Texture::computeTextureDataSize((Texture::Format) format, (Texture::Type) type,
|
||||
(size_t) stride, (size_t) height, (size_t) alignment);
|
||||
|
||||
AutoBuffer nioBuffer(env, storage, 0);
|
||||
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* buffer = nioBuffer.getData();
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
|
||||
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);
|
||||
|
||||
Texture::PrefilterOptions options;
|
||||
options.sampleCount = sampleCount;
|
||||
options.mirror = mirror;
|
||||
texture->generatePrefilterMipmap(*engine, std::move(desc), faceOffsets, &options);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ANDROID SPECIFIC BITS
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include "CallbackUtils.h"
|
||||
#include "NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
|
||||
@@ -94,6 +94,13 @@ Java_com_google_android_filament_View_nSetShadowsEnabled(JNIEnv*, jclass,
|
||||
view->setShadowsEnabled(enabled);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetRenderTarget(JNIEnv*, jclass,
|
||||
jlong nativeView, jlong nativeTarget) {
|
||||
View* view = (View*) nativeView;
|
||||
view->setRenderTarget((RenderTarget*) nativeTarget);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetSampleCount(JNIEnv*, jclass,
|
||||
jlong nativeView, jint count) {
|
||||
@@ -219,3 +226,23 @@ Java_com_google_android_filament_View_nIsFrontFaceWindingInverted(JNIEnv*,
|
||||
View* view = (View*) nativeView;
|
||||
return static_cast<jboolean>(view->isFrontFaceWindingInverted());
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetAmbientOcclusion(JNIEnv*, jclass, jlong nativeView, jint ordinal) {
|
||||
View* view = (View*) nativeView;
|
||||
view->setAmbientOcclusion((View::AmbientOcclusion)ordinal);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_View_nGetAmbientOcclusion(JNIEnv*, jclass, jlong nativeView) {
|
||||
View* view = (View*) nativeView;
|
||||
return (jint)view->getAmbientOcclusion();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetAmbientOcclusionOptions(JNIEnv*, jclass,
|
||||
jlong nativeView, jfloat radius, jfloat bias, jfloat power, jfloat resolution) {
|
||||
View* view = (View*) nativeView;
|
||||
View::AmbientOcclusionOptions options = { .radius = radius, .bias = bias, .power = power, .resolution = resolution};
|
||||
view->setAmbientOcclusionOptions(options);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ package com.google.android.filament;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.opengl.EGL14;
|
||||
import android.opengl.EGLContext;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
final class AndroidPlatform extends Platform {
|
||||
private static final String LOG_TAG = "Filament";
|
||||
@@ -59,6 +61,20 @@ final class AndroidPlatform extends Platform {
|
||||
|
||||
@Override
|
||||
long getSharedContextNativeHandle(Object sharedContext) {
|
||||
return ((EGLContext) sharedContext).getNativeHandle();
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
return AndroidPlatform21.getSharedContextNativeHandle(sharedContext);
|
||||
} else {
|
||||
try {
|
||||
//noinspection JavaReflectionMemberAccess
|
||||
Method method = EGLContext.class.getDeclaredMethod("getHandle");
|
||||
Integer handle = (Integer) method.invoke(sharedContext);
|
||||
//noinspection ConstantConditions
|
||||
return handle.longValue();
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, "Could not access shared context's native handle", e);
|
||||
}
|
||||
// Should not happen
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament;
|
||||
|
||||
import android.opengl.EGLContext;
|
||||
|
||||
final class AndroidPlatform21 {
|
||||
static long getSharedContextNativeHandle(Object sharedContext) {
|
||||
return ((EGLContext) sharedContext).getNativeHandle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
final class Asserts {
|
||||
private Asserts() {
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 9)
|
||||
static float[] assertMat3f(@Nullable float[] out) {
|
||||
if (out == null) out = new float[9];
|
||||
else if (out.length < 9) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 9");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static void assertMat3fIn(@NonNull @Size(min = 9) float[] in) {
|
||||
if (in.length < 9) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 9");
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 16)
|
||||
static double[] assertMat4d(@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 assertMat4dIn(@NonNull @Size(min = 16) double[] in) {
|
||||
if (in.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 16)
|
||||
static float[] assertMat4f(@Nullable float[] out) {
|
||||
if (out == null) out = new float[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");
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 3)
|
||||
static float[] assertFloat3(@Nullable float[] out) {
|
||||
if (out == null) out = new float[3];
|
||||
else if (out.length < 3) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 3");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 4)
|
||||
static float[] assertFloat4(@Nullable float[] out) {
|
||||
if (out == null) out = new float[4];
|
||||
else if (out.length < 4) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 4");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,25 @@ package com.google.android.filament;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
/**
|
||||
* An axis-aligned 3D box represented by its center and half-extent.
|
||||
*
|
||||
* The half-extent is a vector representing the distance from the center to the edge of the box in
|
||||
* each dimension. For example, a box of size 2 units in X, 4 units in Y, and 10 units in Z would
|
||||
* have a half-extent of (1, 2, 5).
|
||||
*/
|
||||
public class Box {
|
||||
private final float[] mCenter = new float[3];
|
||||
private final float[] mHalfExtent = new float[3];
|
||||
|
||||
/**
|
||||
* Default-initializes the 3D box to have a center and half-extent of (0,0,0).
|
||||
*/
|
||||
public Box() { }
|
||||
|
||||
/**
|
||||
* Initializes the 3D box from its center and half-extent.
|
||||
*/
|
||||
public Box(float centerX, float centerY, float centerZ,
|
||||
float halfExtentX, float halfExtentY, float halfExtentZ) {
|
||||
mCenter[0] = centerX;
|
||||
@@ -35,6 +48,13 @@ public class Box {
|
||||
mHalfExtent[2] = halfExtentZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the 3D box from its center and half-extent.
|
||||
*
|
||||
* @param center a float array with XYZ coordinates representing the center of the box
|
||||
* @param halfExtent a float array with XYZ coordinates representing half the size of the box in
|
||||
* each dimension
|
||||
*/
|
||||
public Box(@NonNull @Size(min = 3) float[] center, @NonNull @Size(min = 3) float[] halfExtent) {
|
||||
mCenter[0] = center[0];
|
||||
mCenter[1] = center[1];
|
||||
@@ -44,21 +64,37 @@ public class Box {
|
||||
mHalfExtent[2] = halfExtent[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the center of of the 3D box.
|
||||
*/
|
||||
public void setCenter(float centerX, float centerY, float centerZ) {
|
||||
mCenter[0] = centerX;
|
||||
mCenter[1] = centerY;
|
||||
mCenter[2] = centerZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the half-extent of the 3D box.
|
||||
*/
|
||||
public void setHalfExtent(float halfExtentX, float halfExtentY, float halfExtentZ) {
|
||||
mHalfExtent[0] = halfExtentX;
|
||||
mHalfExtent[1] = halfExtentY;
|
||||
mHalfExtent[2] = halfExtentZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the center of the 3D box.
|
||||
*
|
||||
* @return an XYZ float array of size 3
|
||||
*/
|
||||
@NonNull @Size(min = 3)
|
||||
public float[] getCenter() { return mCenter; }
|
||||
|
||||
/**
|
||||
* Returns the half-extent from the center of the 3D box.
|
||||
*
|
||||
* @return an XYZ float array of size 3
|
||||
*/
|
||||
@NonNull @Size(min = 3)
|
||||
public float[] getHalfExtent() { return mHalfExtent; }
|
||||
}
|
||||
|
||||
@@ -157,26 +157,30 @@ public class Camera {
|
||||
* @param projection type of projection to use
|
||||
*
|
||||
* @param left distance in world units from the camera to the left plane,
|
||||
* at the near plane. Precondition: left != right.
|
||||
* at the near plane. Precondition: <code>left</code> != <code>right</code>
|
||||
*
|
||||
* @param right distance in world units from the camera to the right plane,
|
||||
* at the near plane. Precondition: left != right.
|
||||
* at the near plane. Precondition: <code>left</code> != <code>right</code>
|
||||
*
|
||||
* @param bottom distance in world units from the camera to the bottom plane,
|
||||
* at the near plane. Precondition: bottom != top.
|
||||
* at the near plane. Precondition: <code>bottom</code> != <code>top</code>
|
||||
*
|
||||
* @param top distance in world units from the camera to the top plane,
|
||||
* at the near plane. Precondition: left != right.
|
||||
* at the near plane. Precondition: <code>bottom</code> != <code>top</code>
|
||||
*
|
||||
* @param near distance in world units from the camera to the near plane.
|
||||
* The near plane's position in view space is z = -near.
|
||||
* Precondition: near > 0 for {@link Projection#PERSPECTIVE} or
|
||||
* near != far for {@link Projection#ORTHO}.
|
||||
* The near plane's position in view space is z = -<code>near</code>.
|
||||
* Precondition:
|
||||
* <code>near</code> > 0 for {@link Projection#PERSPECTIVE} or
|
||||
* <code>near</code> != <code>far</code> for {@link Projection#ORTHO}.
|
||||
*
|
||||
* @param far distance in world units from the camera to the far plane.
|
||||
* The far plane's position in view space is z = -far.
|
||||
* Precondition: far > near for {@link Projection#PERSPECTIVE} or
|
||||
* far != near for {@link Projection#ORTHO}.
|
||||
* The far plane's position in view space is z = -<code>far</code>.
|
||||
* Precondition:
|
||||
* <code>far</code> > <code>near</code>
|
||||
* for {@link Projection#PERSPECTIVE} or
|
||||
* <code>far</code> != <code>near</code>
|
||||
* for {@link Projection#ORTHO}.
|
||||
*
|
||||
* <p>
|
||||
* These parameters are silently modified to meet the preconditions above.
|
||||
@@ -189,12 +193,32 @@ public class Camera {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the projection matrix from the field-of-view.
|
||||
*
|
||||
* @param fovInDegrees
|
||||
* @param aspect
|
||||
* @param near
|
||||
* @param far
|
||||
* @param direction
|
||||
* @param fovInDegrees field-of-view in degrees from the camera center axis.
|
||||
* 0 < <code>fovInDegrees</code> < 180
|
||||
*
|
||||
* @param aspect aspect ratio width/height. <code>aspect</code> > 0
|
||||
*
|
||||
* @param near distance in world units from the camera to the near plane.
|
||||
* The near plane's position in view space is z = -<code>near</code>.
|
||||
* Precondition:
|
||||
* <code>near</code> > 0 for {@link Projection#PERSPECTIVE} or
|
||||
* <code>near</code> != <code>far</code> for {@link Projection#ORTHO}.
|
||||
*
|
||||
* @param far distance in world units from the camera to the far plane.
|
||||
* The far plane's position in view space is z = -<code>far</code>.
|
||||
* Precondition:
|
||||
* <code>far</code> > <code>near</code>
|
||||
* for {@link Projection#PERSPECTIVE} or
|
||||
* <code>far</code> != <code>near</code>
|
||||
* for {@link Projection#ORTHO}.
|
||||
*
|
||||
* @param direction direction of the field-of-view parameter.
|
||||
* <p>
|
||||
* These parameters are silently modified to meet the preconditions above.
|
||||
*
|
||||
* @see Fov
|
||||
*/
|
||||
public void setProjection(double fovInDegrees, double aspect, double near, double far,
|
||||
@NonNull Fov direction) {
|
||||
@@ -202,47 +226,86 @@ public class Camera {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the projection matrix from the focal length
|
||||
*
|
||||
* @param focalLength lense's focal length in millimeters. <code>focalLength</code> > 0
|
||||
*
|
||||
* @param near distance in world units from the camera to the near plane.
|
||||
* The near plane's position in view space is z = -<code>near</code>.
|
||||
* Precondition:
|
||||
* <code>near</code> > 0 for {@link Projection#PERSPECTIVE} or
|
||||
* <code>near</code> != <code>far</code> for {@link Projection#ORTHO}.
|
||||
*
|
||||
* @param far distance in world units from the camera to the far plane.
|
||||
* The far plane's position in view space is z = -<code>far</code>.
|
||||
* Precondition:
|
||||
* <code>far</code> > <code>near</code>
|
||||
* for {@link Projection#PERSPECTIVE} or
|
||||
* <code>far</code> != <code>near</code>
|
||||
* for {@link Projection#ORTHO}.
|
||||
*
|
||||
* @param focalLength
|
||||
* @param near
|
||||
* @param far
|
||||
*/
|
||||
public void setLensProjection(double focalLength, double near, double far) {
|
||||
nSetLensProjection(getNativeObject(), focalLength, near, far);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the projection matrix.
|
||||
*
|
||||
* @param inMatrix
|
||||
* @param near
|
||||
* @param far
|
||||
* @param inMatrix custom projection matrix.
|
||||
*
|
||||
* @param near distance in world units from the camera to the near plane.
|
||||
* The near plane's position in view space is z = -<code>near</code>.
|
||||
* Precondition:
|
||||
* <code>near</code> > 0 for {@link Projection#PERSPECTIVE} or
|
||||
* <code>near</code> != <code>far</code> for {@link Projection#ORTHO}.
|
||||
*
|
||||
* @param far distance in world units from the camera to the far plane.
|
||||
* The far plane's position in view space is z = -<code>far</code>.
|
||||
* Precondition:
|
||||
* <code>far</code> > <code>near</code>
|
||||
* for {@link Projection#PERSPECTIVE} or
|
||||
* <code>far</code> != <code>near</code>
|
||||
* for {@link Projection#ORTHO}.
|
||||
*/
|
||||
public void setCustomProjection(@NonNull @Size(min = 16) double inMatrix[],
|
||||
public void setCustomProjection(@NonNull @Size(min = 16) double[] inMatrix,
|
||||
double near, double far) {
|
||||
assertMat4dIn(inMatrix);
|
||||
Asserts.assertMat4dIn(inMatrix);
|
||||
nSetCustomProjection(getNativeObject(), inMatrix, near, far);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>
|
||||
* This has the same effect as calling:
|
||||
*
|
||||
* @param in
|
||||
* <pre>
|
||||
* engine.getTransformManager().setTransform(
|
||||
* engine.getTransformManager().getInstance(camera->getEntity()), viewMatrix);
|
||||
* </pre>
|
||||
*
|
||||
* @param viewMatrix The camera position and orientation provided as a <b>rigid transform</b> matrix.
|
||||
*/
|
||||
public void setModelMatrix(@NonNull @Size(min = 16) float in[]) {
|
||||
assertMat4fIn(in);
|
||||
nSetModelMatrix(getNativeObject(), in);
|
||||
public void setModelMatrix(@NonNull @Size(min = 16) float[] viewMatrix) {
|
||||
Asserts.assertMat4fIn(viewMatrix);
|
||||
nSetModelMatrix(getNativeObject(), viewMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the camera's view matrix.
|
||||
*
|
||||
* @param eyeX
|
||||
* @param eyeY
|
||||
* @param eyeZ
|
||||
* @param centerX
|
||||
* @param centerY
|
||||
* @param centerZ
|
||||
* @param upX
|
||||
* @param upY
|
||||
* @param upZ
|
||||
* @param eyeX x-axis position of the camera in world space
|
||||
* @param eyeY y-axis position of the camera in world space
|
||||
* @param eyeZ z-axis position of the camera in world space
|
||||
* @param centerX x-axis position of the point in world space the camera is looking at
|
||||
* @param centerY y-axis position of the point in world space the camera is looking at
|
||||
* @param centerZ z-axis position of the point in world space the camera is looking at
|
||||
* @param upX x-axis coordinate of a unit vector denoting the camera's "up" direction
|
||||
* @param upY y-axis coordinate of a unit vector denoting the camera's "up" direction
|
||||
* @param upZ z-axis coordinate of a unit vector denoting the camera's "up" direction
|
||||
*/
|
||||
public void lookAt(double eyeX, double eyeY, double eyeZ,
|
||||
double centerX, double centerY, double centerZ, double upX, double upY, double upZ) {
|
||||
@@ -250,16 +313,14 @@ public class Camera {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Distance to the near plane.
|
||||
* @return Distance to the near plane
|
||||
*/
|
||||
public float getNear() {
|
||||
return nGetNear(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Distance to the far plane.
|
||||
* @return Distance to the far plane
|
||||
*/
|
||||
public float getCullingFar() {
|
||||
return nGetCullingFar(getNativeObject());
|
||||
@@ -267,13 +328,15 @@ public class Camera {
|
||||
|
||||
/**
|
||||
* Retrieves the camera's projection matrix.
|
||||
*
|
||||
* @param out A 16-float array where the projection matrix will be stored, or null in which
|
||||
* case a new array is allocated.
|
||||
*
|
||||
* @return A 16-float array containing the camera's projection as a column-major matrix.
|
||||
*/
|
||||
@NonNull @Size(min = 16)
|
||||
public double[] getProjectionMatrix(@Nullable @Size(min = 16) double out[]) {
|
||||
out = assertMat4d(out);
|
||||
public double[] getProjectionMatrix(@Nullable @Size(min = 16) double[] out) {
|
||||
out = Asserts.assertMat4d(out);
|
||||
nGetProjectionMatrix(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
@@ -281,13 +344,15 @@ public class Camera {
|
||||
/**
|
||||
* Retrieves the camera's model matrix. The model matrix encodes the camera position and
|
||||
* orientation, or pose.
|
||||
*
|
||||
* @param out A 16-float array where the model matrix will be stored, or null in which
|
||||
* case a new array is allocated.
|
||||
*
|
||||
* @return A 16-float array containing the camera's pose as a column-major matrix.
|
||||
*/
|
||||
@NonNull @Size(min = 16)
|
||||
public float[] getModelMatrix(@Nullable @Size(min = 16) float out[]) {
|
||||
out = assertMat4f(out);
|
||||
public float[] getModelMatrix(@Nullable @Size(min = 16) float[] out) {
|
||||
out = Asserts.assertMat4f(out);
|
||||
nGetModelMatrix(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
@@ -297,24 +362,27 @@ public class Camera {
|
||||
*
|
||||
* @param out A 16-float array where the model view will be stored, or null in which
|
||||
* case a new array is allocated.
|
||||
*
|
||||
* @return A 16-float array containing the camera's view as a column-major matrix.
|
||||
*/
|
||||
@NonNull @Size(min = 16)
|
||||
public float[] getViewMatrix(@Nullable @Size(min = 16) float out[]) {
|
||||
out = assertMat4f(out);
|
||||
public float[] getViewMatrix(@Nullable @Size(min = 16) float[] out) {
|
||||
out = Asserts.assertMat4f(out);
|
||||
nGetViewMatrix(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the camera position in world space.
|
||||
*
|
||||
* @param out A 3-float array where the position will be stored, or null in which case a new
|
||||
* array is allocated.
|
||||
*
|
||||
* @return A 3-float array containing the camera's position in world units.
|
||||
*/
|
||||
@NonNull @Size(min = 3)
|
||||
public float[] getPosition(@Nullable @Size(min = 3) float out[]) {
|
||||
out = assertFloat3(out);
|
||||
public float[] getPosition(@Nullable @Size(min = 3) float[] out) {
|
||||
out = Asserts.assertFloat3(out);
|
||||
nGetPosition(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
@@ -322,13 +390,15 @@ public class Camera {
|
||||
/**
|
||||
* Retrieves the camera left unit vector in world space, that is a unit vector that points to
|
||||
* the left of the camera.
|
||||
*
|
||||
* @param out A 3-float array where the left vector will be stored, or null in which case a new
|
||||
* array is allocated.
|
||||
*
|
||||
* @return A 3-float array containing the camera's left vector in world units.
|
||||
*/
|
||||
@NonNull @Size(min = 3)
|
||||
public float[] getLeftVector(@Nullable @Size(min = 3) float out[]) {
|
||||
out = assertFloat3(out);
|
||||
public float[] getLeftVector(@Nullable @Size(min = 3) float[] out) {
|
||||
out = Asserts.assertFloat3(out);
|
||||
nGetLeftVector(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
@@ -336,13 +406,15 @@ public class Camera {
|
||||
/**
|
||||
* Retrieves the camera up unit vector in world space, that is a unit vector that points up with
|
||||
* respect to the camera.
|
||||
*
|
||||
* @param out A 3-float array where the up vector will be stored, or null in which case a new
|
||||
* array is allocated.
|
||||
*
|
||||
* @return A 3-float array containing the camera's up vector in world units.
|
||||
*/
|
||||
@NonNull @Size(min = 3)
|
||||
public float[] getUpVector(@Nullable @Size(min = 3) float out[]) {
|
||||
out = assertFloat3(out);
|
||||
public float[] getUpVector(@Nullable @Size(min = 3) float[] out) {
|
||||
out = Asserts.assertFloat3(out);
|
||||
nGetUpVector(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
@@ -350,52 +422,89 @@ public class Camera {
|
||||
/**
|
||||
* Retrieves the camera forward unit vector in world space, that is a unit vector that points
|
||||
* in the direction the camera is looking at.
|
||||
*
|
||||
* @param out A 3-float array where the forward vector will be stored, or null in which case a
|
||||
* new array is allocated.
|
||||
*
|
||||
* @return A 3-float array containing the camera's forward vector in world units.
|
||||
*/
|
||||
@NonNull @Size(min = 3)
|
||||
public float[] getForwardVector(@Nullable @Size(min = 3) float out[]) {
|
||||
out = assertFloat3(out);
|
||||
public float[] getForwardVector(@Nullable @Size(min = 3) float[] out) {
|
||||
out = Asserts.assertFloat3(out);
|
||||
nGetForwardVector(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this camera's exposure (default is f/16, 1/125s, 100 ISO)
|
||||
*
|
||||
* @param aperture
|
||||
* @param shutterSpeed
|
||||
* @param sensitivity
|
||||
* The exposure ultimately controls the scene's brightness, just like with a real camera.
|
||||
* The default values provide adequate exposure for a camera placed outdoors on a sunny day
|
||||
* with the sun at the zenith.
|
||||
*
|
||||
* With the default parameters, the scene must contain at least one Light of intensity
|
||||
* similar to the sun (e.g.: a 100,000 lux directional light) and/or an indirect light
|
||||
* of appropriate intensity (30,000).
|
||||
*
|
||||
* @param aperture Aperture in f-stops, clamped between 0.5 and 64.
|
||||
* A lower aperture value increases the exposure, leading to
|
||||
* a brighter scene. Realistic values are between 0.95 and 32.
|
||||
*
|
||||
* @param shutterSpeed Shutter speed in seconds, clamped between 1/25,000 and 60.
|
||||
* A lower shutter speed increases the exposure. Realistic values are
|
||||
* between 1/8000 and 30.
|
||||
*
|
||||
* @param sensitivity Sensitivity in ISO, clamped between 10 and 204,800.
|
||||
* A higher sensitivity increases the exposure. Realistic values are
|
||||
* between 50 and 25600.
|
||||
*
|
||||
* @see LightManager
|
||||
* @see #setExposure(float)
|
||||
*/
|
||||
public void setExposure(float aperture, float shutterSpeed, float sensitivity) {
|
||||
nSetExposure(getNativeObject(), aperture, shutterSpeed, sensitivity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this camera's exposure directly. Calling this method will set the aperture
|
||||
* to 1.0, the shutter speed to 1.2 and the sensitivity will be computed to match
|
||||
* the requested exposure (for a desired exposure of 1.0, the sensitivity will be
|
||||
* set to 100 ISO).
|
||||
*
|
||||
* @return
|
||||
* This method is useful when trying to match the lighting of other engines or tools.
|
||||
* Many engines/tools use unit-less light intensities, which can be matched by setting
|
||||
* the exposure manually. This can be typically achieved by setting the exposure to
|
||||
* 1.0.
|
||||
*
|
||||
* @see LightManager
|
||||
* @see #setExposure(float, float, float)
|
||||
*/
|
||||
public void setExposure(float exposure) {
|
||||
setExposure(1.0f, 1.2f, 100.0f * (1.0f / exposure));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Aperture in f-stops
|
||||
*/
|
||||
public float getAperture() {
|
||||
return nGetAperture(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @return Shutter speed in seconds
|
||||
*/
|
||||
public float getShutterSpeed() {
|
||||
return nGetShutterSpeed(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @return Sensitivity in ISO
|
||||
*/
|
||||
public float getSensitivity() {
|
||||
return nGetSensitivity(getNativeObject());
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Camera");
|
||||
}
|
||||
@@ -406,45 +515,6 @@ public class Camera {
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 16)
|
||||
private static double[] assertMat4d(@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;
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 16)
|
||||
private static float[] assertMat4f(@Nullable float[] out) {
|
||||
if (out == null) out = new float[16];
|
||||
else if (out.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static void assertMat4dIn(@NonNull @Size(min = 16) double[] in) {
|
||||
if (in.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertMat4fIn(@NonNull @Size(min = 16) float[] in) {
|
||||
if (in.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 3)
|
||||
private static float[] assertFloat3(@Nullable float[] out) {
|
||||
if (out == null) out = new float[3];
|
||||
else if (out.length < 3) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 3");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static native void nSetProjection(long nativeCamera, int projection, double left, double right, double bottom, double top, double near, double far);
|
||||
private static native void nSetProjectionFov(long nativeCamera, double fovInDegrees, double aspect, double near, double far, int fov);
|
||||
private static native void nSetLensProjection(long nativeCamera, double focalLength, double near, double far);
|
||||
|
||||
@@ -28,6 +28,9 @@ import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||
|
||||
/**
|
||||
* Utilities to manipulate and convert colors.
|
||||
*/
|
||||
public class Colors {
|
||||
private Colors() {
|
||||
}
|
||||
@@ -37,23 +40,67 @@ public class Colors {
|
||||
public @interface LinearColor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Types of RGB colors.
|
||||
*/
|
||||
public enum RgbType {
|
||||
/** The color is defined in sRGB space. */
|
||||
SRGB,
|
||||
|
||||
/** The color is defined in linear space. */
|
||||
LINEAR
|
||||
}
|
||||
|
||||
/**
|
||||
* Types of RGBA colors.
|
||||
*/
|
||||
public enum RgbaType {
|
||||
/**
|
||||
* The color is defined in sRGB space and the RGB values have not been premultiplied by the
|
||||
* alpha (for instance, a 50% transparent red is <1,0,0,0.5>).
|
||||
*/
|
||||
SRGB,
|
||||
|
||||
/**
|
||||
* The color is defined in linear space and the RGB values have not been premultiplied by
|
||||
* the alpha (for instance, a 50% transparent red is <1,0,0,0.5>).
|
||||
*/
|
||||
LINEAR,
|
||||
|
||||
/**
|
||||
* The color is defined in sRGB space and the RGB values have been premultiplied by the
|
||||
* alpha (for instance, a 50% transparent red is <0.5,0,0,0.5>).
|
||||
*/
|
||||
PREMULTIPLIED_SRGB,
|
||||
|
||||
/**
|
||||
* The color is defined in linear space and the RGB values have been premultiplied by the
|
||||
* alpha (for instance, a 50% transparent red is <0.5,0,0,0.5>).
|
||||
*/
|
||||
PREMULTIPLIED_LINEAR
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of color conversion to use when converting to/from sRGB and linear spaces.
|
||||
*/
|
||||
public enum Conversion {
|
||||
/** Accurate conversion using the sRGB standard. */
|
||||
ACCURATE,
|
||||
|
||||
/** Fast conversion using a simple gamma 2.2 curve. */
|
||||
FAST
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an RGB color to linear space, the conversion depends on the specified type.
|
||||
*
|
||||
* @param type the color space of the RGB color values provided
|
||||
* @param r the red component
|
||||
* @param g the green component
|
||||
* @param b the blue component
|
||||
*
|
||||
* @return an RGB float array of size 3 with the result of the conversion
|
||||
*/
|
||||
@NonNull
|
||||
@Size(3)
|
||||
@LinearColor
|
||||
@@ -61,6 +108,14 @@ public class Colors {
|
||||
return toLinear(type, new float[] { r, g, b });
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an RGB color to linear space, the conversion depends on the specified type.
|
||||
*
|
||||
* @param type the color space of the RGB color values provided
|
||||
* @param rgb an RGB float array of size 3, will be modified
|
||||
*
|
||||
* @return the passed-in <code>rgb</code> array, after applying the conversion
|
||||
*/
|
||||
@NonNull
|
||||
@Size(min = 3)
|
||||
@LinearColor
|
||||
@@ -68,6 +123,17 @@ public class Colors {
|
||||
return (type == RgbType.LINEAR) ? rgb : toLinear(Conversion.ACCURATE, rgb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an RGBA color to linear space, with pre-multiplied alpha.
|
||||
*
|
||||
* @param type the color space and type of RGBA color values provided
|
||||
* @param r the red component
|
||||
* @param g the green component
|
||||
* @param b the blue component
|
||||
* @param a the alpha component
|
||||
*
|
||||
* @return an RGBA float array of size 4 with the result of the conversion
|
||||
*/
|
||||
@NonNull
|
||||
@Size(4)
|
||||
@LinearColor
|
||||
@@ -75,6 +141,14 @@ public class Colors {
|
||||
return toLinear(type, new float[] { r, g, b, a });
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an RGBA color to linear space, with pre-multiplied alpha.
|
||||
*
|
||||
* @param type the color space of the RGBA color values provided
|
||||
* @param rgba an RGBA float array of size 4, will be modified
|
||||
*
|
||||
* @return the passed-in <code>rgba</code> array, after applying the conversion
|
||||
*/
|
||||
@NonNull
|
||||
@Size(min = 4)
|
||||
@LinearColor
|
||||
@@ -97,6 +171,15 @@ public class Colors {
|
||||
return rgba;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an RGB color in sRGB space to an RGB color in linear space.
|
||||
*
|
||||
* @param conversion the conversion algorithm to use
|
||||
* @param rgb an RGB float array of at least size 3, will be modified
|
||||
*
|
||||
* @return the passed-in <code>rgb</code> array, after applying the conversion. The alpha
|
||||
* channel, if present, is left unmodified.
|
||||
*/
|
||||
@NonNull
|
||||
@LinearColor
|
||||
public static float[] toLinear(@NonNull Conversion conversion, @NonNull @Size(min = 3) float[] rgb) {
|
||||
@@ -116,6 +199,14 @@ public class Colors {
|
||||
return rgb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a correlated color temperature to a linear RGB color in sRGB space. The temperature
|
||||
* must be expressed in Kelvin and must be in the range 1,000K to 15,000K.
|
||||
*
|
||||
* @param temperature the temperature, in Kelvin
|
||||
*
|
||||
* @return an RGB float array of size 3 with the result of the conversion
|
||||
*/
|
||||
@NonNull
|
||||
@Size(3)
|
||||
@LinearColor
|
||||
@@ -125,6 +216,14 @@ public class Colors {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a CIE standard illuminant series D to a linear RGB color in sRGB space. The
|
||||
* temperature must be expressed in Kelvin and must be in the range 4,000K to 25,000K.
|
||||
*
|
||||
* @param temperature the temperature, in Kelvin
|
||||
*
|
||||
* @return an RGB float array of size 3 with the result of the conversion
|
||||
*/
|
||||
@NonNull
|
||||
@Size(3)
|
||||
@LinearColor
|
||||
|
||||
@@ -18,17 +18,118 @@ package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.android.filament.proguard.UsedByReflection;
|
||||
|
||||
/**
|
||||
* Engine is filament's main entry-point.
|
||||
* <p>
|
||||
* An Engine instance main function is to keep track of all resources created by the user and
|
||||
* manage the rendering thread as well as the hardware renderer.
|
||||
* <p>
|
||||
* To use filament, an Engine instance must be created first:
|
||||
*
|
||||
* <pre>
|
||||
* import com.google.android.filament.*
|
||||
*
|
||||
* Engine engine = Engine.create();
|
||||
* </pre>
|
||||
* <p>
|
||||
* Engine essentially represents (or is associated to) a hardware context
|
||||
* (e.g. an OpenGL ES context).
|
||||
* <p>
|
||||
* Rendering typically happens in an operating system's window (which can be full screen), such
|
||||
* window is managed by a {@link Renderer}.
|
||||
* <p>
|
||||
* A typical filament render loop looks like this:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* import com.google.android.filament.*
|
||||
*
|
||||
* Engin engine = Engine.create();
|
||||
* SwapChain swapChain = engine.createSwapChain(nativeWindow);
|
||||
* Renderer renderer = engine.createRenderer();
|
||||
* Scene scene = engine.createScene();
|
||||
* View view = engine.createView();
|
||||
*
|
||||
* view.setScene(scene);
|
||||
*
|
||||
* do {
|
||||
* // typically we wait for VSYNC and user input events
|
||||
* if (renderer.beginFrame(swapChain)) {
|
||||
* renderer.render(view);
|
||||
* renderer.endFrame();
|
||||
* }
|
||||
* } while (!quit);
|
||||
*
|
||||
* engine.destroyView(view);
|
||||
* engine.destroyScene(scene);
|
||||
* engine.destroyRenderer(renderer);
|
||||
* engine.destroySwapChain(swapChain);
|
||||
* engine.destroy();
|
||||
* </pre>
|
||||
*
|
||||
* <h1><u>Resource Tracking</u></h1>
|
||||
* <p>
|
||||
* Each <code>Engine</code> instance keeps track of all objects created by the user, such as vertex
|
||||
* and index buffers, lights, cameras, etc...
|
||||
* The user is expected to free those resources, however, leaked resources are freed when the
|
||||
* engine instance is destroyed and a warning is emitted in the console.
|
||||
*
|
||||
* <h1><u>Thread safety</u></h1>
|
||||
* <p>
|
||||
* An <code>Engine</code> instance is not thread-safe. The implementation makes no attempt to
|
||||
* synchronize calls to an <code>Engine</code> instance methods.
|
||||
* If multi-threading is needed, synchronization must be external.
|
||||
*
|
||||
* <h1><u>Multi-threading</u></h1>
|
||||
* <p>
|
||||
* When created, the <code>Engine</code> instance starts a render thread as well as multiple worker
|
||||
* threads, these threads have an elevated priority appropriate for rendering, based on the
|
||||
* platform's best practices. The number of worker threads depends on the platform and is
|
||||
* automatically chosen for best performance.
|
||||
* <p>
|
||||
* On platforms with asymmetric cores (e.g. ARM's Big.Little), <code>Engine</code> makes some
|
||||
* educated guesses as to which cores to use for the render thread and worker threads. For example,
|
||||
* it'll try to keep an OpenGL ES thread on a Big core.
|
||||
*
|
||||
* <h1><u>Swap Chains</u></h1>
|
||||
* <p>
|
||||
* A swap chain represents an Operating System's <b>native</b> renderable surface.
|
||||
* Typically it's a window or a view. Because a {@link SwapChain} is initialized from a native
|
||||
* object, it is given to filament as an <code>Object</code>, which must be of the proper type for
|
||||
* each platform filament is running on.
|
||||
* <p>
|
||||
*
|
||||
* @see SwapChain
|
||||
* @see Renderer
|
||||
*/
|
||||
public class Engine {
|
||||
private long mNativeObject;
|
||||
@NonNull private final TransformManager mTransformManager;
|
||||
@NonNull private final LightManager mLightManager;
|
||||
@NonNull private final RenderableManager mRenderableManager;
|
||||
|
||||
/**
|
||||
* Denotes a backend
|
||||
*/
|
||||
public enum Backend {
|
||||
DEFAULT, // Automatically selects an appropriate driver for the platform.
|
||||
OPENGL, // Selects the OpenGL ES driver.
|
||||
VULKAN, // Selects the experimental Vulkan driver.
|
||||
NOOP, // Selects the no-op driver for testing purposes.
|
||||
/**
|
||||
* Automatically selects an appropriate driver for the platform.
|
||||
*/
|
||||
DEFAULT,
|
||||
/**
|
||||
* Selects the OpenGL ES driver.
|
||||
*/
|
||||
OPENGL,
|
||||
/**
|
||||
* Selects the experimental Vulkan driver.
|
||||
*/
|
||||
VULKAN,
|
||||
/**
|
||||
* Selects the no-op driver for testing purposes.
|
||||
*/
|
||||
NOOP,
|
||||
}
|
||||
|
||||
private Engine(long nativeEngine) {
|
||||
@@ -38,6 +139,19 @@ public class Engine {
|
||||
mRenderableManager = new RenderableManager(nGetRenderableManager(nativeEngine));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of Engine using the default {@link Backend}
|
||||
* <p>
|
||||
* This method is one of the few thread-safe methods.
|
||||
*
|
||||
* @return A newly created <code>Engine</code>, or <code>null</code> if the GPU driver couldn't
|
||||
* be initialized, for instance if it doesn't support the right version of OpenGL or
|
||||
* OpenGL ES.
|
||||
*
|
||||
* @exception IllegalStateException can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer.
|
||||
*
|
||||
*/
|
||||
@NonNull
|
||||
public static Engine create() {
|
||||
long nativeEngine = nCreateEngine(0, 0);
|
||||
@@ -45,6 +159,21 @@ public class Engine {
|
||||
return new Engine(nativeEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of Engine using the specified {@link Backend}
|
||||
* <p>
|
||||
* This method is one of the few thread-safe methods.
|
||||
*
|
||||
* @param backend driver backend to use
|
||||
*
|
||||
* @return A newly created <code>Engine</code>, or <code>null</code> if the GPU driver couldn't
|
||||
* be initialized, for instance if it doesn't support the right version of OpenGL or
|
||||
* OpenGL ES.
|
||||
*
|
||||
* @exception IllegalStateException can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer.
|
||||
*
|
||||
*/
|
||||
@NonNull
|
||||
public static Engine create(@NonNull Backend backend) {
|
||||
long nativeEngine = nCreateEngine(backend.ordinal(), 0);
|
||||
@@ -53,9 +182,21 @@ public class Engine {
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid shared context:
|
||||
* - Android: EGLContext
|
||||
* - Other: none
|
||||
* Creates an instance of Engine using the {@link Backend#OPENGL} and a shared OpenGL context.
|
||||
* <p>
|
||||
* This method is one of the few thread-safe methods.
|
||||
*
|
||||
* @param sharedContext A platform-dependant OpenGL context used as a shared context
|
||||
* when creating filament's internal context. On Android this parameter
|
||||
* <b>must be</b> an instance of {@link android.opengl.EGLContext}.
|
||||
*
|
||||
* @return A newly created <code>Engine</code>, or <code>null</code> if the GPU driver couldn't
|
||||
* be initialized, for instance if it doesn't support the right version of OpenGL or
|
||||
* OpenGL ES.
|
||||
*
|
||||
* @exception IllegalStateException can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer.
|
||||
*
|
||||
*/
|
||||
@NonNull
|
||||
public static Engine create(@NonNull Object sharedContext) {
|
||||
@@ -68,15 +209,41 @@ public class Engine {
|
||||
throw new IllegalArgumentException("Invalid shared context " + sharedContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this <code>Engine</code> is initialized properly.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return mNativeObject != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the <code>Engine</code> instance and all associated resources.
|
||||
* <p>
|
||||
* This method is one of the few thread-safe methods.
|
||||
* <p>
|
||||
* {@link Engine#destroy()} should be called last and after all other resources have been
|
||||
* destroyed, it ensures all filament resources are freed.
|
||||
* <p>
|
||||
* <code>Destroy</code> performs the following tasks:
|
||||
* <li>Destroy all internal software and hardware resources.</li>
|
||||
* <li>Free all user allocated resources that are not already destroyed and logs a warning.
|
||||
* <p>This indicates a "leak" in the user's code.</li>
|
||||
* <li>Terminate the rendering engine's thread.</li>
|
||||
*
|
||||
* <pre>
|
||||
* Engine engine = Engine.create();
|
||||
* engine.destroy();
|
||||
* </pre>
|
||||
*/
|
||||
public void destroy() {
|
||||
nDestroyEngine(getNativeObject());
|
||||
clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the backend used by this <code>Engine</code>
|
||||
*/
|
||||
@NonNull
|
||||
public Backend getBackend() {
|
||||
return Backend.values()[(int) nGetBackend(getNativeObject())];
|
||||
}
|
||||
@@ -84,25 +251,36 @@ public class Engine {
|
||||
// SwapChain
|
||||
|
||||
/**
|
||||
* Valid surface types:
|
||||
* - Android: Surface
|
||||
* - Other: none
|
||||
* Creates an opaque {@link SwapChain} from the given OS native window handle.
|
||||
*
|
||||
* @param surface on Android, <b>must be</b> an instance of {@link android.view.Surface}
|
||||
*
|
||||
* @return a newly created {@link SwapChain} object
|
||||
*
|
||||
* @exception IllegalStateException can be thrown if the SwapChain couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public SwapChain createSwapChain(@NonNull Object surface) {
|
||||
return createSwapChain(surface, SwapChain.CONFIG_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid surface types:
|
||||
* - Android: Surface
|
||||
* - Other: none
|
||||
* Creates a {@link SwapChain} from the given OS native window handle.
|
||||
*
|
||||
* Flags: see CONFIG flags in SwapChain.
|
||||
* @param surface on Android, <b>must be</b> an instance of {@link android.view.Surface}
|
||||
*
|
||||
* @param flags configuration flags, see {@link SwapChain}
|
||||
*
|
||||
* @return a newly created {@link SwapChain} object
|
||||
*
|
||||
* @exception IllegalStateException can be thrown if the SwapChain couldn't be created
|
||||
*
|
||||
* @see SwapChain#CONFIG_DEFAULT
|
||||
* @see SwapChain#CONFIG_TRANSPARENT
|
||||
* @see SwapChain#CONFIG_READABLE
|
||||
*
|
||||
*/
|
||||
@NonNull
|
||||
public SwapChain createSwapChain(@NonNull Object surface, long flags) {
|
||||
if (Platform.get().validateSurface(surface)) {
|
||||
long nativeSwapChain = nCreateSwapChain(getNativeObject(), surface, flags);
|
||||
@@ -112,6 +290,18 @@ public class Engine {
|
||||
throw new IllegalArgumentException("Invalid surface " + surface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link SwapChain} from a {@link NativeSurface}.
|
||||
*
|
||||
* @param surface a properly initialized {@link NativeSurface}
|
||||
*
|
||||
* @param flags configuration flags, see {@link SwapChain}
|
||||
*
|
||||
* @return a newly created {@link SwapChain} object
|
||||
*
|
||||
* @exception IllegalStateException can be thrown if the {@link SwapChain} couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public SwapChain createSwapChainFromNativeSurface(@NonNull NativeSurface surface, long flags) {
|
||||
long nativeSwapChain =
|
||||
nCreateSwapChainFromRawPointer(getNativeObject(), surface.getNativeObject(), flags);
|
||||
@@ -119,6 +309,10 @@ public class Engine {
|
||||
return new SwapChain(nativeSwapChain, surface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link SwapChain} and frees all its associated resources.
|
||||
* @param swapChain the {@link SwapChain} to destroy
|
||||
*/
|
||||
public void destroySwapChain(@NonNull SwapChain swapChain) {
|
||||
nDestroySwapChain(getNativeObject(), swapChain.getNativeObject());
|
||||
swapChain.clearNativeObject();
|
||||
@@ -126,6 +320,11 @@ public class Engine {
|
||||
|
||||
// View
|
||||
|
||||
/**
|
||||
* Creates a {@link View}.
|
||||
* @return a newly created {@link View}
|
||||
* @exception IllegalStateException can be thrown if the {@link View} couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public View createView() {
|
||||
long nativeView = nCreateView(getNativeObject());
|
||||
@@ -133,6 +332,10 @@ public class Engine {
|
||||
return new View(nativeView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link View} and frees all its associated resources.
|
||||
* @param view the {@link View} to destroy
|
||||
*/
|
||||
public void destroyView(@NonNull View view) {
|
||||
nDestroyView(getNativeObject(), view.getNativeObject());
|
||||
view.clearNativeObject();
|
||||
@@ -140,6 +343,11 @@ public class Engine {
|
||||
|
||||
// Renderer
|
||||
|
||||
/**
|
||||
* Creates a {@link Renderer}.
|
||||
* @return a newly created {@link Renderer}
|
||||
* @exception IllegalStateException can be thrown if the {@link Renderer} couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public Renderer createRenderer() {
|
||||
long nativeRenderer = nCreateRenderer(getNativeObject());
|
||||
@@ -147,6 +355,10 @@ public class Engine {
|
||||
return new Renderer(this, nativeRenderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link Renderer} and frees all its associated resources.
|
||||
* @param renderer the {@link Renderer} to destroy
|
||||
*/
|
||||
public void destroyRenderer(@NonNull Renderer renderer) {
|
||||
nDestroyRenderer(getNativeObject(), renderer.getNativeObject());
|
||||
renderer.clearNativeObject();
|
||||
@@ -154,6 +366,12 @@ public class Engine {
|
||||
|
||||
// Camera
|
||||
|
||||
/**
|
||||
* Creates a new <code>entity</code> and adds a {@link Camera} component to it.
|
||||
*
|
||||
* @return A newly created {@link Camera}
|
||||
* @exception IllegalStateException can be thrown if the {@link Camera} couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public Camera createCamera() {
|
||||
long nativeCamera = nCreateCamera(getNativeObject());
|
||||
@@ -161,6 +379,13 @@ public class Engine {
|
||||
return new Camera(nativeCamera);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and adds a {@link Camera} component to a given <code>entity</code>.
|
||||
*
|
||||
* @param entity <code>entity</code> to add the camera component to
|
||||
* @return A newly created {@link Camera}
|
||||
* @exception IllegalStateException can be thrown if the {@link Camera} couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public Camera createCamera(@Entity int entity) {
|
||||
long nativeCamera = nCreateCameraWithEntity(getNativeObject(), entity);
|
||||
@@ -168,6 +393,10 @@ public class Engine {
|
||||
return new Camera(nativeCamera);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link Camera} component and frees all its associated resources.
|
||||
* @param camera the {@link Camera} to destroy
|
||||
*/
|
||||
public void destroyCamera(@NonNull Camera camera) {
|
||||
nDestroyCamera(getNativeObject(), camera.getNativeObject());
|
||||
camera.clearNativeObject();
|
||||
@@ -175,6 +404,11 @@ public class Engine {
|
||||
|
||||
// Scene
|
||||
|
||||
/**
|
||||
* Creates a {@link Scene}.
|
||||
* @return a newly created {@link Scene}
|
||||
* @exception IllegalStateException can be thrown if the {@link Scene} couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public Scene createScene() {
|
||||
long nativeScene = nCreateScene(getNativeObject());
|
||||
@@ -182,6 +416,10 @@ public class Engine {
|
||||
return new Scene(nativeScene);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link Scene} and frees all its associated resources.
|
||||
* @param scene the {@link Scene} to destroy
|
||||
*/
|
||||
public void destroyScene(@NonNull Scene scene) {
|
||||
nDestroyScene(getNativeObject(), scene.getNativeObject());
|
||||
scene.clearNativeObject();
|
||||
@@ -189,6 +427,10 @@ public class Engine {
|
||||
|
||||
// Stream
|
||||
|
||||
/**
|
||||
* Destroys a {@link Stream} and frees all its associated resources.
|
||||
* @param stream the {@link Stream} to destroy
|
||||
*/
|
||||
public void destroyStream(@NonNull Stream stream) {
|
||||
nDestroyStream(getNativeObject(), stream.getNativeObject());
|
||||
stream.clearNativeObject();
|
||||
@@ -196,13 +438,22 @@ public class Engine {
|
||||
|
||||
// Fence
|
||||
|
||||
/**
|
||||
* Creates a {@link Fence}.
|
||||
* @return a newly created {@link Fence}
|
||||
* @exception IllegalStateException can be thrown if the {@link Fence} couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public Fence createFence(@NonNull Fence.Type type) {
|
||||
long nativeFence = nCreateFence(getNativeObject(), type.ordinal());
|
||||
public Fence createFence() {
|
||||
long nativeFence = nCreateFence(getNativeObject());
|
||||
if (nativeFence == 0) throw new IllegalStateException("Couldn't create Fence");
|
||||
return new Fence(nativeFence);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link Fence} and frees all its associated resources.
|
||||
* @param fence the {@link Fence} to destroy
|
||||
*/
|
||||
public void destroyFence(@NonNull Fence fence) {
|
||||
nDestroyFence(getNativeObject(), fence.getNativeObject());
|
||||
fence.clearNativeObject();
|
||||
@@ -210,67 +461,139 @@ public class Engine {
|
||||
|
||||
// others...
|
||||
|
||||
/**
|
||||
* Destroys a {@link IndexBuffer} and frees all its associated resources.
|
||||
* @param indexBuffer the {@link IndexBuffer} to destroy
|
||||
*/
|
||||
public void destroyIndexBuffer(@NonNull IndexBuffer indexBuffer) {
|
||||
nDestroyIndexBuffer(getNativeObject(), indexBuffer.getNativeObject());
|
||||
indexBuffer.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link VertexBuffer} and frees all its associated resources.
|
||||
* @param vertexBuffer the {@link VertexBuffer} to destroy
|
||||
*/
|
||||
public void destroyVertexBuffer(@NonNull VertexBuffer vertexBuffer) {
|
||||
nDestroyVertexBuffer(getNativeObject(), vertexBuffer.getNativeObject());
|
||||
vertexBuffer.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link IndirectLight} and frees all its associated resources.
|
||||
* @param ibl the {@link IndirectLight} to destroy
|
||||
*/
|
||||
public void destroyIndirectLight(@NonNull IndirectLight ibl) {
|
||||
nDestroyIndirectLight(getNativeObject(), ibl.getNativeObject());
|
||||
ibl.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link Material} and frees all its associated resources.
|
||||
* <p>
|
||||
* All {@link MaterialInstance} of the specified {@link Material} must be destroyed before
|
||||
* destroying it; if some {@link MaterialInstance} remain, this method fails silently.
|
||||
*
|
||||
* @param material the {@link Material} to destroy
|
||||
*/
|
||||
public void destroyMaterial(@NonNull Material material) {
|
||||
nDestroyMaterial(getNativeObject(), material.getNativeObject());
|
||||
material.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link MaterialInstance} and frees all its associated resources.
|
||||
* @param materialInstance the {@link MaterialInstance} to destroy
|
||||
*/
|
||||
public void destroyMaterialInstance(@NonNull MaterialInstance materialInstance) {
|
||||
nDestroyMaterialInstance(getNativeObject(), materialInstance.getNativeObject());
|
||||
materialInstance.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link Skybox} and frees all its associated resources.
|
||||
* @param skybox the {@link Skybox} to destroy
|
||||
*/
|
||||
public void destroySkybox(@NonNull Skybox skybox) {
|
||||
nDestroySkybox(getNativeObject(), skybox.getNativeObject());
|
||||
skybox.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link Texture} and frees all its associated resources.
|
||||
* @param texture the {@link Texture} to destroy
|
||||
*/
|
||||
public void destroyTexture(@NonNull Texture texture) {
|
||||
nDestroyTexture(getNativeObject(), texture.getNativeObject());
|
||||
texture.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a {@link RenderTarget} and frees all its associated resources.
|
||||
* @param target the {@link RenderTarget} to destroy
|
||||
*/
|
||||
public void destroyRenderTarget(@NonNull RenderTarget target) {
|
||||
nDestroyRenderTarget(getNativeObject(), target.getNativeObject());
|
||||
target.clearNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys an <code>entity</code> and all its components.
|
||||
* <p>
|
||||
* It is recommended to destroy components individually before destroying their
|
||||
* <code>entity</code>, this gives more control as to when the destruction really happens.
|
||||
* Otherwise, orphaned components are garbage collected, which can happen at a later time.
|
||||
* Even when component are garbage collected, the destruction of their <code>entity</code>
|
||||
* terminates their participation immediately.
|
||||
*
|
||||
* @param entity the <code>entity</code> to destroy
|
||||
*/
|
||||
public void destroyEntity(@Entity int entity) {
|
||||
nDestroyEntity(getNativeObject(), entity);
|
||||
}
|
||||
|
||||
// Managers
|
||||
|
||||
/**
|
||||
* @return the {@link TransformManager} used by this {@link Engine}
|
||||
*/
|
||||
@NonNull
|
||||
public TransformManager getTransformManager() {
|
||||
return mTransformManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link LightManager} used by this {@link Engine}
|
||||
*/
|
||||
@NonNull
|
||||
public LightManager getLightManager() {
|
||||
return mLightManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link RenderableManager} used by this {@link Engine}
|
||||
*/
|
||||
@NonNull
|
||||
public RenderableManager getRenderableManager() {
|
||||
return mRenderableManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* hardware is actually finished.
|
||||
*
|
||||
* <p>This is typically used right after destroying the <code>SwapChain</code>,
|
||||
* in cases where a guarantee about the SwapChain destruction is needed in a timely fashion,
|
||||
* such as when responding to Android's
|
||||
* {@link android.view.SurfaceHolder.Callback#surfaceDestroyed surfaceDestroyed}.</p>
|
||||
*/
|
||||
public void flushAndWait() {
|
||||
Fence.waitAndDestroy(createFence(Fence.Type.HARD), Fence.Mode.FLUSH);
|
||||
nFlushAndWait(getNativeObject());
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
@UsedByReflection("TextureHelper.java")
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Engine");
|
||||
}
|
||||
@@ -296,7 +619,7 @@ public class Engine {
|
||||
private static native void nDestroyCamera(long nativeEngine, long nativeCamera);
|
||||
private static native long nCreateScene(long nativeEngine);
|
||||
private static native void nDestroyScene(long nativeEngine, long nativeScene);
|
||||
private static native long nCreateFence(long nativeEngine, int fenceType);
|
||||
private static native long nCreateFence(long nativeEngine);
|
||||
private static native void nDestroyFence(long nativeEngine, long nativeFence);
|
||||
private static native void nDestroyStream(long nativeEngine, long nativeStream);
|
||||
private static native void nDestroyIndexBuffer(long nativeEngine, long nativeIndexBuffer);
|
||||
@@ -306,7 +629,9 @@ public class Engine {
|
||||
private static native void nDestroyMaterialInstance(long nativeEngine, long nativeMaterialInstance);
|
||||
private static native void nDestroySkybox(long nativeEngine, long nativeSkybox);
|
||||
private static native void nDestroyTexture(long nativeEngine, long nativeTexture);
|
||||
private static native void nDestroyRenderTarget(long nativeEngine, long nativeTarget);
|
||||
private static native void nDestroyEntity(long nativeEngine, int entity);
|
||||
private static native void nFlushAndWait(long nativeEngine);
|
||||
private static native long nGetTransformManager(long nativeEngine);
|
||||
private static native long nGetLightManager(long nativeEngine);
|
||||
private static native long nGetRenderableManager(long nativeEngine);
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.google.android.filament;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.android.filament.proguard.UsedByReflection;
|
||||
|
||||
public class EntityManager {
|
||||
private long mNativeObject = nGetEntityManager();
|
||||
|
||||
@@ -66,6 +68,11 @@ public class EntityManager {
|
||||
return nIsAlive(mNativeObject, entity);
|
||||
}
|
||||
|
||||
@UsedByReflection("AssetLoader.java")
|
||||
public long getNativeObject() {
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
private static native long nGetEntityManager();
|
||||
private static native void nCreateArray(long nativeEntityManager, int n, int[] entities);
|
||||
private static native int nCreate(long nativeEntityManager);
|
||||
|
||||
@@ -26,11 +26,6 @@ public class Fence {
|
||||
|
||||
public static final long WAIT_FOR_EVER = -1;
|
||||
|
||||
public enum Type {
|
||||
SOFT,
|
||||
HARD
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
FLUSH,
|
||||
DONT_FLUSH
|
||||
@@ -70,7 +65,7 @@ public class Fence {
|
||||
}
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Fence");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,17 @@ import android.support.annotation.Nullable;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
|
||||
/**
|
||||
* A buffer containing vertex indices into a <code>VertexBuffer</code>. Indices can be 16 or 32 bit.
|
||||
* The buffer itself is a GPU resource, therefore mutating the data can be relatively slow.
|
||||
* Typically these buffers are constant.
|
||||
*
|
||||
* It is possible, and even encouraged, to use a single index buffer for several
|
||||
* <code>Renderables</code>.
|
||||
*
|
||||
* @see VertexBuffer
|
||||
* @see RenderableManager
|
||||
*/
|
||||
public class IndexBuffer {
|
||||
private long mNativeObject;
|
||||
|
||||
@@ -30,21 +41,20 @@ public class IndexBuffer {
|
||||
mNativeObject = nativeIndexBuffer;
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed IndexBuffer");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
|
||||
// Keep to finalize native resources
|
||||
private final BuilderFinalizer mFinalizer;
|
||||
private final long mNativeBuilder;
|
||||
|
||||
/**
|
||||
* Type of the index buffer.
|
||||
*/
|
||||
public enum IndexType {
|
||||
/** 16-bit indices */
|
||||
USHORT,
|
||||
|
||||
/** 32-bit indices */
|
||||
UINT,
|
||||
}
|
||||
|
||||
@@ -53,18 +63,45 @@ public class IndexBuffer {
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of the index buffer in elements.
|
||||
*
|
||||
* @param indexCount number of indices the <code>IndexBuffer</code> can hold
|
||||
*
|
||||
* @return this <code>Builder</code> object for chaining calls
|
||||
*/
|
||||
@NonNull
|
||||
public Builder indexCount(@IntRange(from = 1) int indexCount) {
|
||||
nBuilderIndexCount(mNativeBuilder, indexCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of the index buffer, 16-bit or 32-bit.
|
||||
*
|
||||
* @param indexType type of indices stored in the <code>IndexBuffer</code>
|
||||
*
|
||||
* @return this <code>Builder</code> object for chaining calls
|
||||
*/
|
||||
@NonNull
|
||||
public Builder bufferType(@NonNull IndexType indexType) {
|
||||
nBuilderBufferType(mNativeBuilder, indexType.ordinal());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns the <code>IndexBuffer</code> object. After creation, the index buffer
|
||||
* is uninitialized. Use {@link #setBuffer} to initialized the <code>IndexBuffer</code>.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this <code>IndexBuffer</code>
|
||||
* with
|
||||
*
|
||||
* @return the newly created <code>IndexBuffer</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the IndexBuffer could not be created
|
||||
*
|
||||
* @see #setBuffer
|
||||
*/
|
||||
@NonNull
|
||||
public IndexBuffer build(@NonNull Engine engine) {
|
||||
long nativeIndexBuffer = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
@@ -92,24 +129,69 @@ public class IndexBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of this <code>IndexBuffer</code> in elements.
|
||||
*
|
||||
* @return the number of indices the <code>IndexBuffer</code> holds
|
||||
*/
|
||||
@IntRange(from = 0)
|
||||
public int getIndexCount() {
|
||||
return nGetIndexCount(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously copy-initializes this <code>IndexBuffer</code> from the data provided.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this
|
||||
* <code>IndexBuffer</code> with
|
||||
* @param buffer a CPU-side {@link Buffer} with the data used to initialize the
|
||||
* <code>IndexBuffer</code>. <code>buffer</code> should contain raw,
|
||||
* untyped data that will be interpreted as either 16-bit or 32-bits
|
||||
* indices based on the <code>IndexType</code> of this
|
||||
* <code>IndexBuffer</code>.
|
||||
*/
|
||||
public void setBuffer(@NonNull Engine engine, @NonNull Buffer buffer) {
|
||||
setBuffer(engine, buffer, 0, 0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously copy-initializes a region of this <code>IndexBuffer</code> from the data
|
||||
* provided.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this
|
||||
* <code>IndexBuffer</code> with
|
||||
* @param buffer a CPU-side {@link Buffer} with the data used to initialize the
|
||||
* <code>IndexBuffer</code>. <code>buffer</code> should contain raw,
|
||||
* untyped data that will be interpreted as either 16-bit or 32-bits
|
||||
* indices based on the <code>IndexType</code> of this
|
||||
* <code>IndexBuffer</code>.
|
||||
* @param destOffsetInBytes offset in <i>bytes</i> into the <code>IndexBuffer</code>
|
||||
* @param count number of buffer elements to consume, defaults to
|
||||
* <code>buffer.remaining()</code>
|
||||
*/
|
||||
public void setBuffer(@NonNull Engine engine, @NonNull Buffer buffer,
|
||||
@IntRange(from = 0) int destOffsetInBytes, @IntRange(from = 0) int count) {
|
||||
setBuffer(engine, buffer, destOffsetInBytes, count, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid handler types:
|
||||
* - Android: Handler, Executor
|
||||
* - Other: Executor
|
||||
* Asynchronously copy-initializes a region of this <code>IndexBuffer</code> from the data
|
||||
* provided.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this
|
||||
* <code>IndexBuffer</code> with
|
||||
* @param buffer a CPU-side {@link Buffer} with the data used to initialize the
|
||||
* <code>IndexBuffer</code>. <code>buffer</code> should contain raw,
|
||||
* untyped data that will be interpreted as either 16-bit or 32-bits
|
||||
* indices based on the <code>IndexType</code> of this
|
||||
* <code>IndexBuffer</code>.
|
||||
* @param destOffsetInBytes offset in <i>bytes</i> into the <code>IndexBuffer</code>
|
||||
* @param count number of buffer elements to consume, defaults to
|
||||
* <code>buffer.remaining()</code>
|
||||
* @param handler an {@link java.util.concurrent.Executor Executor}. On Android this
|
||||
* can also be a {@link android.os.Handler Handler}.
|
||||
* @param callback a callback executed by <code>handler</code> when <code>buffer</code>
|
||||
* is no longer needed.
|
||||
*/
|
||||
public void setBuffer(@NonNull Engine engine, @NonNull Buffer buffer,
|
||||
@IntRange(from = 0) int destOffsetInBytes, @IntRange(from = 0) int count,
|
||||
@@ -121,6 +203,13 @@ public class IndexBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed IndexBuffer");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
void clearNativeObject() {
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
@@ -18,31 +18,167 @@ package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
import com.google.android.filament.proguard.UsedByReflection;
|
||||
|
||||
/**
|
||||
* <code>IndirectLight</code> is used to simulate environment lighting, a form of global illumination.
|
||||
*
|
||||
* <p>Environment lighting has a two components:</p>
|
||||
* <ol>
|
||||
* <li>irradiance</li>
|
||||
* <li>reflections (specular component)</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>Environments are usually captured as high-resolution HDR equirectangular images and processed
|
||||
* by the <b>cmgen</b> tool to generate the data needed by {@link IndirectLight}.</p>
|
||||
*
|
||||
* <p>Currently {@link IndirectLight} is intended to be used for "distant probes", that is, to represent
|
||||
* global illumination from a distant (i.e. at infinity) environment, such as the sky or distant
|
||||
* mountains. Only a single {@link IndirectLight} can be used in a {@link Scene}.
|
||||
* This limitation will be lifted in the future.</p>
|
||||
*
|
||||
*
|
||||
* <h1>Creation and destruction</h1>
|
||||
*
|
||||
* <p>An {@link IndirectLight} object is created using the {@link IndirectLight.Builder} and
|
||||
* destroyed by calling {@link Engine#destroyIndirectLight}.</p>
|
||||
*
|
||||
* <pre>
|
||||
* Engine engine = Engine.create();
|
||||
*
|
||||
* Scene scene = engine.createScene();
|
||||
*
|
||||
* IndirectLight environment = new IndirectLight.Builder()
|
||||
* .reflections(cubemap)
|
||||
* .irradiance(numBands, sphericalHarmonicsCoefficients)
|
||||
* .build(engine);
|
||||
*
|
||||
* scene.setIndirectLight(environment);
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* <h1>Irradiance</h1>
|
||||
*
|
||||
* <p>The irradiance represents the light that comes from the environment and shines an
|
||||
* object's surface. It is represented as
|
||||
* <a href="https://en.wikipedia.org/wiki/Spherical_harmonics">Spherical Harmonics</a> (SH) of 1, 2 or
|
||||
* 3 bands, respectively 1, 4 or 9 coefficients.</p>
|
||||
*
|
||||
* <p>Use the <b>cmgen</b> tool to generate the Spherical Harmonics for a given environment.</p>
|
||||
*
|
||||
*
|
||||
* <h1>Reflections</h1>
|
||||
*
|
||||
* <p>The reflections on object surfaces (specular component) is calculated from a specially
|
||||
* filtered cubemap pyramid generated by the <b>cmgen</b> tool.</p>
|
||||
*
|
||||
* @see Scene
|
||||
* @see LightManager
|
||||
* @see Texture
|
||||
* @see Skybox
|
||||
*/
|
||||
public class IndirectLight {
|
||||
long mNativeObject;
|
||||
|
||||
private IndirectLight(long indirectLight) {
|
||||
@UsedByReflection("KtxLoader.java")
|
||||
IndirectLight(long indirectLight) {
|
||||
mNativeObject = indirectLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct an <code>IndirectLight</code> object instance.
|
||||
*/
|
||||
public static class Builder {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
|
||||
private final BuilderFinalizer mFinalizer;
|
||||
private final long mNativeBuilder;
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct an <code>IndirectLight</code> object instance.
|
||||
*/
|
||||
public Builder() {
|
||||
mNativeBuilder = nCreateBuilder();
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the reflections cubemap mipmap chain.
|
||||
*
|
||||
* @param cubemap A mip-mapped cubemap generated by <b>cmgen</b>. Each cubemap level
|
||||
* encodes the irradiance for a roughness level.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
*/
|
||||
@NonNull
|
||||
public Builder reflections(@NonNull Texture cubemap) {
|
||||
nBuilderReflections(mNativeBuilder, cubemap.getNativeObject());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the irradiance as Spherical Harmonics.
|
||||
*
|
||||
* <p>The irradiance coefficients must be pre-convolved by <code>< n &sdot l ></code> and
|
||||
* pre-multiplied by the Lambertian diffuse BRDF <code>1/&pi</code> and
|
||||
* specified as Spherical Harmonics coefficients.</p>
|
||||
*
|
||||
* <p>Additionally, these Spherical Harmonics coefficients must be pre-scaled by the
|
||||
* reconstruction factors A<sup>l,m</sup>.</p>
|
||||
*
|
||||
* <p>The final coefficients can be generated using the <code>cmgen</code> tool.</p>
|
||||
*
|
||||
* <p>The index in the <code>sh</code> array is given by:
|
||||
* <br><code>index(l, m) = 3 × (l * (l + 1) + m)</code>
|
||||
* <br><code>sh[index(l,m) + 0] = L<sub>R</sub><sup>l,m</sup>
|
||||
* × 1/&pi
|
||||
* × A<sup>l,m</sup>
|
||||
* × C<sup>l</sup> </code>
|
||||
* <br><code>sh[index(l,m) + 1] = L<sub>G</sub><sup>l,m</sup>
|
||||
* × 1/&pi
|
||||
* × A<sup>l,m</sup>
|
||||
* × C<sup>l</sup> </code>
|
||||
* <br><code>sh[index(l,m) + 2] = L<sub>B</sub><sup>l,m</sup>
|
||||
* × 1/&pi
|
||||
* × A<sup>l,m</sup>
|
||||
* × C<sup>l</sup> </code>
|
||||
* </p>
|
||||
*
|
||||
* <center>
|
||||
* <table border="1" cellpadding="3">
|
||||
* <tr><th> index </th><th> l </th><th> m </th><th> A<sup>l,m</sup> </th><th> C<sup>l</sup> </th>
|
||||
* <th> 1/&pi × A<sup>l,m</sup> × C<sup>l</sup></th></tr>
|
||||
* <tr align="right"><td>0</td><td>0</td><td> 0</td><td> 0.282095</td><td>3.1415926</td><td> 0.282095</td></tr>
|
||||
* <tr align="right"><td>1</td><td>1</td><td>-1</td><td>-0.488602</td><td>2.0943951</td><td>-0.325735</td></tr>
|
||||
* <tr align="right"><td>2</td><td>1</td><td> 0</td><td> 0.488602</td><td>2.0943951</td><td> 0.325735</td></tr>
|
||||
* <tr align="right"><td>3</td><td>1</td><td> 1</td><td>-0.488602</td><td>2.0943951</td><td>-0.325735</td></tr>
|
||||
* <tr align="right"><td>4</td><td>2</td><td>-2</td><td> 1.092548</td><td>0.785398 </td><td> 0.273137</td></tr>
|
||||
* <tr align="right"><td>5</td><td>2</td><td>-1</td><td>-1.092548</td><td>0.785398 </td><td>-0.273137</td></tr>
|
||||
* <tr align="right"><td>6</td><td>2</td><td> 0</td><td> 0.315392</td><td>0.785398 </td><td> 0.078848</td></tr>
|
||||
* <tr align="right"><td>7</td><td>2</td><td> 1</td><td>-1.092548</td><td>0.785398 </td><td>-0.273137</td></tr>
|
||||
* <tr align="right"><td>8</td><td>2</td><td> 2</td><td> 0.546274</td><td>0.785398 </td><td> 0.136569</td></tr>
|
||||
* </table>
|
||||
* </center>
|
||||
*
|
||||
*
|
||||
* <p>Only 1, 2 or 3 bands are allowed.</p>
|
||||
*
|
||||
* <p>Because the coefficients are pre-scaled, <code>sh[0]</code> is the environment's
|
||||
* average irradiance.</p>
|
||||
*
|
||||
* @param bands Number of spherical harmonics bands. Must be 1, 2 or 3.
|
||||
* @param sh Array containing the spherical harmonics coefficients.
|
||||
* The size of the array must be <code>3 × bands<sup>2</sup></code>
|
||||
* (i.e. 1, 4 or 9 <code>float3</code> coefficients respectively).
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @exception ArrayIndexOutOfBoundsException if the <code>sh</code> array length is smaller
|
||||
* than 3 × bands<sup>2</sup>
|
||||
*/
|
||||
@NonNull
|
||||
public Builder irradiance(@IntRange(from=1, to=3) int bands, @NonNull float[] sh) {
|
||||
switch (bands) {
|
||||
@@ -61,20 +197,110 @@ public class IndirectLight {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the irradiance from the radiance expressed as Spherical Harmonics.
|
||||
*
|
||||
* <p>The radiance must be specified as Spherical Harmonics coefficients L<sup>l,m</sup>, where
|
||||
* each coefficient is comprised of three floats for red, green and blue components, respectively</p>
|
||||
*
|
||||
* <p>The index in the <code>sh</code> array is given by:
|
||||
* <br><code>index(l, m) = 3 × (l * (l + 1) + m)</code>
|
||||
* <br><code>sh[index(l,m) + 0] = L<sub>R</sub><sup>l,m</sup></code>
|
||||
* <br><code>sh[index(l,m) + 1] = L<sub>G</sub><sup>l,m</sup></code>
|
||||
* <br><code>sh[index(l,m) + 2] = L<sub>B</sub><sup>l,m</sup></code>
|
||||
* </p>
|
||||
*
|
||||
* <center>
|
||||
* <table border="1" cellpadding="3">
|
||||
* <tr><th> index </th><th> l </th><th> m </th>
|
||||
* <tr align="right"><td>0</td><td>0</td><td> 0</td>
|
||||
* <tr align="right"><td>1</td><td>1</td><td>-1</td>
|
||||
* <tr align="right"><td>2</td><td>1</td><td> 0</td>
|
||||
* <tr align="right"><td>3</td><td>1</td><td> 1</td>
|
||||
* <tr align="right"><td>4</td><td>2</td><td>-2</td>
|
||||
* <tr align="right"><td>5</td><td>2</td><td>-1</td>
|
||||
* <tr align="right"><td>6</td><td>2</td><td> 0</td>
|
||||
* <tr align="right"><td>7</td><td>2</td><td> 1</td>
|
||||
* <tr align="right"><td>8</td><td>2</td><td> 2</td>
|
||||
* </table>
|
||||
* </center>
|
||||
*
|
||||
* @param bands Number of spherical harmonics bands. Must be 1, 2 or 3.
|
||||
* @param sh Array containing the spherical harmonics coefficients.
|
||||
* The size of the array must be 3 × <code>bands<sup>2</sup></code>
|
||||
* (i.e. 1, 4 or 9 <code>float3</code> coefficients respectively).
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @exception ArrayIndexOutOfBoundsException if the <code>sh</code> array length is smaller
|
||||
* than 3 × bands<sup>2</sup>
|
||||
*/
|
||||
@NonNull
|
||||
public Builder radiance(@IntRange(from=1, to=3) int bands, @NonNull float[] sh) {
|
||||
switch (bands) {
|
||||
case 1: if (sh.length < 3)
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"1 band SH, array must be at least 1 x float3"); else break;
|
||||
case 2: if (sh.length < 4 * 3)
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"2 bands SH, array must be at least 4 x float3"); else break;
|
||||
case 3: if (sh.length < 9 * 3)
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"3 bands SH, array must be at least 9 x float3"); else break;
|
||||
default: throw new IllegalArgumentException("bands must be 1, 2 or 3");
|
||||
}
|
||||
nRadiance(mNativeBuilder, bands, sh);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the irradiance as a cubemap.
|
||||
* <p></p>
|
||||
* The irradiance can alternatively be specified as a cubemap instead of Spherical
|
||||
* Harmonics coefficients. It may or may not be more efficient, depending on your
|
||||
* hardware (essentially, it's trading ALU for bandwidth).
|
||||
* <p></p>
|
||||
* This irradiance cubemap can be generated with the <code>cmgen</code> tool.
|
||||
*
|
||||
* @param cubemap Cubemap representing the Irradiance pre-convolved by
|
||||
* <code>< n &sdot l ></code>.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @see #irradiance(int bands, float[] sh)
|
||||
*/
|
||||
@NonNull
|
||||
public Builder irradiance(@NonNull Texture cubemap) {
|
||||
nIrradianceAsTexture(mNativeBuilder, cubemap.getNativeObject());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Environment intensity (optional).
|
||||
*
|
||||
* <p>Because the environment is encoded usually relative to some reference, the
|
||||
* range can be adjusted with this method.</p>
|
||||
*
|
||||
* @param envIntensity Scale factor applied to the environment and irradiance such that
|
||||
* the result is in cd/m^2 (lux) units (default = 30000)
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder intensity(float envIntensity) {
|
||||
nIntensity(mNativeBuilder, envIntensity);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the rigid-body transformation to apply to the IBL.
|
||||
*
|
||||
* @param rotation 3x3 rotation matrix. Must be a rigid-body transform.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder rotation(@NonNull @Size(min = 9) float rotation[]) {
|
||||
public Builder rotation(@NonNull @Size(min = 9) float[] rotation) {
|
||||
nRotation(mNativeBuilder,
|
||||
rotation[0], rotation[1], rotation[2],
|
||||
rotation[3], rotation[4], rotation[5],
|
||||
@@ -82,6 +308,15 @@ public class IndirectLight {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the IndirectLight object and returns a pointer to it.
|
||||
*
|
||||
* @param engine The {@link Engine} to associate this <code>IndirectLight</code> with.
|
||||
*
|
||||
* @return A newly created <code>IndirectLight</code>
|
||||
*
|
||||
* @exception IllegalStateException if a parameter to a builder function was invalid.
|
||||
*/
|
||||
@NonNull
|
||||
public IndirectLight build(@NonNull Engine engine) {
|
||||
long nativeIndirectLight = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
@@ -106,22 +341,110 @@ public class IndirectLight {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the environment's intensity.
|
||||
*
|
||||
* <p>Because the environment is encoded usually relative to some reference, the
|
||||
* range can be adjusted with this method.</p>
|
||||
*
|
||||
* @param intensity Scale factor applied to the environment and irradiance such that
|
||||
* the result is in cd/m^2 units (default = 30000)
|
||||
*/
|
||||
public void setIntensity(float intensity) {
|
||||
nSetIntensity(getNativeObject(), intensity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment's intensity in cd/m<sup>2</sup>.
|
||||
*/
|
||||
public float getIntensity() {
|
||||
return nGetIntensity(getNativeObject());
|
||||
}
|
||||
|
||||
public void setRotation(@NonNull @Size(min = 9) float rotation[]) {
|
||||
/**
|
||||
* Sets the rigid-body transformation to apply to the IBL.
|
||||
*
|
||||
* @param rotation 3x3 rotation matrix. Must be a rigid-body transform.
|
||||
*/
|
||||
public void setRotation(@NonNull @Size(min = 9) float[] rotation) {
|
||||
Asserts.assertMat3fIn(rotation);
|
||||
nSetRotation(getNativeObject(),
|
||||
rotation[0], rotation[1], rotation[2],
|
||||
rotation[3], rotation[4], rotation[5],
|
||||
rotation[6], rotation[7], rotation[8]);
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
/**
|
||||
* Returns the rigid-body transformation applied to the IBL.
|
||||
*
|
||||
* @param rotation an array of 9 floats to receive the rigid-body transformation applied to
|
||||
* the IBL or <code>null</code>
|
||||
* @return the <code>rotation</code> paramter if it was provided, or a newly allocated float
|
||||
* array containing the rigid-body transformation applied to the IBL
|
||||
*/
|
||||
@NonNull @Size(min = 9)
|
||||
public float[] getRotation(@Nullable @Size(min = 9) float[] rotation) {
|
||||
rotation = Asserts.assertMat3f(rotation);
|
||||
nGetRotation(getNativeObject(), rotation);
|
||||
return rotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to estimate the direction of the dominant light in the environment.
|
||||
*
|
||||
* <p>This assumes that there is only a single dominant light (such as the sun in outdoors
|
||||
* environments), if it's not the case the direction returned will be an average of the
|
||||
* various lights based on their intensity.</p>
|
||||
*
|
||||
* <p>If there are no clear dominant light, as is often the case with low dynamic range (LDR)
|
||||
* environments, this method may return a wrong or unexpected direction.</p>
|
||||
*
|
||||
* <p>The dominant light direction can be used to set a directional light's direction,
|
||||
* for instance to produce shadows that match the environment.</p>
|
||||
*
|
||||
* @param direction an array of 3 floats to receive a unit vector representing the direction of
|
||||
* the dominant light or <code>null</code>
|
||||
* @return the <code>direction</code> paramter if it was provided, or a newly allocated float
|
||||
* array containing a unit vector representing the direction of the dominant light
|
||||
*
|
||||
* @see LightManager.Builder#direction
|
||||
* @see #getColorEstimate
|
||||
*/
|
||||
@NonNull @Size(min = 3)
|
||||
public float[] getDirectionEstimate(@Nullable @Size(min = 3) float[] direction) {
|
||||
direction = Asserts.assertFloat3(direction);
|
||||
nGetDirectionEstimate(getNativeObject(), direction);
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to estimate the color and relative intensity of the environment in a given direction.
|
||||
*
|
||||
* <p>This can be used to set the color and intensity of a directional light. In this case
|
||||
* make sure to multiply this relative intensity by the the intensity of this indirect light.</p>
|
||||
*
|
||||
* @param colorIntensity an array of 4 floats to receive the result or <code>null</code>
|
||||
* @param x the x coordinate of a unit vector representing the direction of the light
|
||||
* @param y the x coordinate of a unit vector representing the direction of the light
|
||||
* @param z the x coordinate of a unit vector representing the direction of the light
|
||||
*
|
||||
* @return A vector of 4 floats where the first 3 components represent the linear color and
|
||||
* the 4th component represents the intensity of the dominant light
|
||||
*
|
||||
* @see LightManager.Builder#color
|
||||
* @see LightManager.Builder#intensity
|
||||
* @see #getDirectionEstimate
|
||||
* @see #getIntensity
|
||||
* @see #setIntensity
|
||||
*/
|
||||
@NonNull @Size(min = 4)
|
||||
public float[] getColorEstimate(@Nullable @Size(min = 4) float[] colorIntensity, float x, float y, float z) {
|
||||
colorIntensity = Asserts.assertFloat4(colorIntensity);
|
||||
nGetColorEstimate(getNativeObject(), colorIntensity, x, y, z);
|
||||
return colorIntensity;
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed IndirectLight");
|
||||
}
|
||||
@@ -138,6 +461,7 @@ public class IndirectLight {
|
||||
private static native long nBuilderBuild(long nativeBuilder, long nativeEngine);
|
||||
private static native void nBuilderReflections(long nativeBuilder, long nativeTexture);
|
||||
private static native void nIrradiance(long nativeBuilder, int bands, float[] sh);
|
||||
private static native void nRadiance(long nativeBuilder, int bands, float[] sh);
|
||||
private static native void nIrradianceAsTexture(long nativeBuilder, long nativeTexture);
|
||||
private static native void nIntensity(long nativeBuilder, float envIntensity);
|
||||
private static native void nRotation(long nativeBuilder, float v0, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8) ;
|
||||
@@ -145,5 +469,7 @@ public class IndirectLight {
|
||||
private static native void nSetIntensity(long nativeIndirectLight, float intensity);
|
||||
private static native float nGetIntensity(long nativeIndirectLight);
|
||||
private static native void nSetRotation(long nativeIndirectLight, float v0, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8);
|
||||
|
||||
private static native void nGetRotation(long nativeIndirectLight, float[] outRotation);
|
||||
private static native void nGetDirectionEstimate(long nativeIndirectLight, float[] outDirection);
|
||||
private static native void nGetColorEstimate(long nativeIndirectLight, float[] outColor, float x, float y, float z);
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public class LightManager {
|
||||
|
||||
@NonNull
|
||||
public float[] getPosition(@EntityInstance int i, @Nullable @Size(min = 3) float[] out) {
|
||||
out = assertFloat3(out);
|
||||
out = Asserts.assertFloat3(out);
|
||||
nGetPosition(mNativeObject, i, out);
|
||||
return out;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ public class LightManager {
|
||||
|
||||
@NonNull
|
||||
public float[] getDirection(@EntityInstance int i, @Nullable @Size(min = 3) float[] out) {
|
||||
out = assertFloat3(out);
|
||||
out = Asserts.assertFloat3(out);
|
||||
nGetDirection(mNativeObject, i, out);
|
||||
return out;
|
||||
}
|
||||
@@ -209,7 +209,7 @@ public class LightManager {
|
||||
|
||||
@NonNull
|
||||
public float[] getColor(@EntityInstance int i, @Nullable @Size(min = 3) float[] out) {
|
||||
out = assertFloat3(out);
|
||||
out = Asserts.assertFloat3(out);
|
||||
nGetColor(mNativeObject, i, out);
|
||||
return out;
|
||||
}
|
||||
@@ -262,13 +262,16 @@ public class LightManager {
|
||||
return nGetSunHaloFalloff(mNativeObject, i);
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 3)
|
||||
private static float[] assertFloat3(@Nullable float[] out) {
|
||||
if (out == null) out = new float[3];
|
||||
else if (out.length < 3) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 3");
|
||||
}
|
||||
return out;
|
||||
public void setShadowCaster(@EntityInstance int i, boolean shadowCaster) {
|
||||
nSetShadowCaster(mNativeObject, i, shadowCaster);
|
||||
}
|
||||
|
||||
public boolean isShadowCaster(@EntityInstance int i) {
|
||||
return nIsShadowCaster(mNativeObject, i);
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
private static native boolean nHasComponent(long nativeLightManager, int entity);
|
||||
@@ -292,7 +295,6 @@ public class LightManager {
|
||||
private static native void nBuilderHaloSize(long nativeBuilder, float haloSize);
|
||||
private static native void nBuilderHaloFalloff(long nativeBuilder, float haloFalloff);
|
||||
|
||||
|
||||
private static native int nGetType(long nativeLightManager, int i);
|
||||
private static native void nSetPosition(long nativeLightManager, int i, float x, float y, float z);
|
||||
private static native void nGetPosition(long nativeLightManager, int i, float[] out);
|
||||
@@ -312,4 +314,6 @@ public class LightManager {
|
||||
private static native float nGetSunHaloSize(long nativeLightManager, int i);
|
||||
private static native void nSetSunHaloFalloff(long nativeLightManager, int i, float haloFalloff);
|
||||
private static native float nGetSunHaloFalloff(long nativeLightManager, int i);
|
||||
private static native void nSetShadowCaster(long nativeLightManager, int i, boolean shadowCaster);
|
||||
private static native boolean nIsShadowCaster(long nativeLightManager, int i);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
import com.google.android.filament.proguard.UsedByNative;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -27,48 +29,161 @@ import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A Filament Material defines the visual appearance of an object. Materials function as a
|
||||
* templates from which {@link MaterialInstance}s can be spawned. Use {@link Builder} to construct
|
||||
* a Material object.
|
||||
*
|
||||
* @see <a href="https://google.github.io/filament/Materials.html">Filament Materials Guide</a>
|
||||
*/
|
||||
public class Material {
|
||||
private long mNativeObject;
|
||||
private final MaterialInstance mDefaultInstance;
|
||||
|
||||
private Set<VertexBuffer.VertexAttribute> mRequiredAttributes;
|
||||
|
||||
/** Supported shading models */
|
||||
public enum Shading {
|
||||
/**
|
||||
* No lighting applied, emissive possible
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialmodels/unlitmodel">
|
||||
* Unlit model</a>
|
||||
*/
|
||||
UNLIT,
|
||||
|
||||
/**
|
||||
* Default, standard lighting
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialmodels/litmodel">
|
||||
* Lit model</a>
|
||||
*/
|
||||
LIT,
|
||||
|
||||
/**
|
||||
* Subsurface lighting model
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialmodels/subsurfacemodel">
|
||||
* Subsurface model</a>
|
||||
*/
|
||||
SUBSURFACE,
|
||||
|
||||
/**
|
||||
* Cloth lighting model
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialmodels/clothmodel">
|
||||
* Cloth model</a>
|
||||
*/
|
||||
CLOTH,
|
||||
|
||||
/**
|
||||
* Legacy lighting model
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialmodels/specularglossiness">
|
||||
* Specular glossiness</a>
|
||||
*/
|
||||
SPECULAR_GLOSSINESS
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute interpolation types in the fragment shader
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/vertexandattributes:interpolation">
|
||||
* Vertex and attributes: interpolation</a>
|
||||
*/
|
||||
public enum Interpolation {
|
||||
/** Default, smooth interpolation */
|
||||
SMOOTH,
|
||||
|
||||
/** Flat interpolation */
|
||||
FLAT
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported blending modes
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/blendingandtransparency:blending">
|
||||
* Blending and transparency: blending</a>
|
||||
*/
|
||||
public enum BlendingMode {
|
||||
/** Material is opaque. */
|
||||
OPAQUE,
|
||||
|
||||
/**
|
||||
* Material is transparent and color is alpha-pre-multiplied.
|
||||
* Affects diffuse lighting only.
|
||||
*/
|
||||
TRANSPARENT,
|
||||
|
||||
/** Material is additive (e.g.: hologram). */
|
||||
ADD,
|
||||
MODULATE,
|
||||
|
||||
/** Material is masked (i.e. alpha tested). */
|
||||
MASKED,
|
||||
FADE
|
||||
|
||||
/**
|
||||
* Material is transparent and color is alpha-pre-multiplied.
|
||||
* Affects specular lighting.
|
||||
*/
|
||||
FADE,
|
||||
|
||||
/** Material darkens what's behind it. */
|
||||
MULTIPLY,
|
||||
|
||||
/** Material brightens what's behind it. */
|
||||
SCREEN,
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported types of vertex domains
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/vertexandattributes:vertexdomain">
|
||||
* Vertex and attributes: vertexDomain</a>
|
||||
*/
|
||||
public enum VertexDomain {
|
||||
/** Vertices are in object space, default. */
|
||||
OBJECT,
|
||||
|
||||
/** Vertices are in world space. */
|
||||
WORLD,
|
||||
|
||||
/** Vertices are in view space. */
|
||||
VIEW,
|
||||
|
||||
/** Vertices are in normalized device space. */
|
||||
DEVICE
|
||||
}
|
||||
|
||||
/**
|
||||
* Face culling Mode
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:culling">
|
||||
* Rasterization: culling</a>
|
||||
*/
|
||||
public enum CullingMode {
|
||||
/** No culling. Front and back faces are visible. */
|
||||
NONE,
|
||||
|
||||
/** Front face culling. Only back faces are visible. */
|
||||
FRONT,
|
||||
|
||||
/** Back face culling. Only front faces are visible. */
|
||||
BACK,
|
||||
|
||||
/** Front and back culling. Geometry is not visible. */
|
||||
FRONT_AND_BACK
|
||||
}
|
||||
|
||||
@UsedByNative("Material.cpp")
|
||||
public static class Parameter {
|
||||
public enum Type {
|
||||
BOOL,
|
||||
@@ -101,8 +216,8 @@ public class Material {
|
||||
DEFAULT
|
||||
}
|
||||
|
||||
// Used by native code
|
||||
@SuppressWarnings("unused")
|
||||
@UsedByNative("Material.cpp")
|
||||
private static final int SAMPLER_OFFSET = Type.MAT4.ordinal() + 1;
|
||||
|
||||
@NonNull
|
||||
@@ -122,8 +237,8 @@ public class Material {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
// Used by native code
|
||||
@SuppressWarnings("unused")
|
||||
@UsedByNative("Material.cpp")
|
||||
private static void add(@NonNull List<Parameter> parameters, @NonNull String name,
|
||||
@IntRange(from = 0) int type, @IntRange(from = 0) int precision,
|
||||
@IntRange(from = 1) int count) {
|
||||
@@ -132,8 +247,9 @@ public class Material {
|
||||
}
|
||||
}
|
||||
|
||||
private Material(long nativeMaterial, long nativeDefaultInstance) {
|
||||
Material(long nativeMaterial) {
|
||||
mNativeObject = nativeMaterial;
|
||||
long nativeDefaultInstance = nGetDefaultInstance(nativeMaterial);
|
||||
mDefaultInstance = new MaterialInstance(this, nativeDefaultInstance);
|
||||
}
|
||||
|
||||
@@ -141,6 +257,13 @@ public class Material {
|
||||
private Buffer mBuffer;
|
||||
private int mSize;
|
||||
|
||||
/**
|
||||
* Specifies the material data. The material data is a binary blob produced by
|
||||
* libfilamat or by matc.
|
||||
*
|
||||
* @param buffer buffer containing material data
|
||||
* @param size size of the material data in bytes
|
||||
*/
|
||||
@NonNull
|
||||
public Builder payload(@NonNull Buffer buffer, @IntRange(from = 0) int size) {
|
||||
mBuffer = buffer;
|
||||
@@ -148,15 +271,29 @@ public class Material {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns the Material object.
|
||||
*
|
||||
* @param engine reference to the Engine instance to associate this Material with
|
||||
*
|
||||
* @return the newly created object
|
||||
*
|
||||
* @exception IllegalStateException if the material could not be created
|
||||
*/
|
||||
@NonNull
|
||||
public Material build(@NonNull Engine engine) {
|
||||
long nativeMaterial = nBuilderBuild(engine.getNativeObject(), mBuffer, mSize);
|
||||
if (nativeMaterial == 0) throw new IllegalStateException("Couldn't create Material");
|
||||
long nativeDefaultInstance = nGetDefaultInstance(nativeMaterial);
|
||||
return new Material(nativeMaterial, nativeDefaultInstance);
|
||||
return new Material(nativeMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of this material. Material instances should be freed using
|
||||
* {@link Engine#destroyMaterialInstance(MaterialInstance)}.
|
||||
*
|
||||
* @return the new instance
|
||||
*/
|
||||
@NonNull
|
||||
public MaterialInstance createInstance() {
|
||||
long nativeInstance = nCreateInstance(getNativeObject());
|
||||
@@ -164,55 +301,163 @@ public class Material {
|
||||
return new MaterialInstance(this, nativeInstance);
|
||||
}
|
||||
|
||||
/** Returns the material's default instance. */
|
||||
@NonNull
|
||||
public MaterialInstance getDefaultInstance() {
|
||||
return mDefaultInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this material. The material name is used for debugging purposes.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/general:name">
|
||||
* General: name</a>
|
||||
*/
|
||||
public String getName() {
|
||||
return nGetName(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shading model of this material.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialmodels">
|
||||
* Material Models</a>
|
||||
*/
|
||||
public Shading getShading() {
|
||||
return Shading.values()[nGetShading(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the interpolation mode of this material. This affects how variables are interpolated.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/vertexandattributes:interpolation">
|
||||
* Vertex and attributes: interpolation</a>
|
||||
*/
|
||||
public Interpolation getInterpolation() {
|
||||
return Interpolation.values()[nGetInterpolation(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blending mode of this material.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/blendingandtransparency:blending">
|
||||
* Blending and transparency: blending</a>
|
||||
*/
|
||||
public BlendingMode getBlendingMode() {
|
||||
return BlendingMode.values()[nGetBlendingMode(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertex domain of this material.
|
||||
*
|
||||
* @se
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/vertexandattributes:vertexdomain">
|
||||
* Vertex and attributes: vertexDomain</a>
|
||||
* @return
|
||||
*/
|
||||
public VertexDomain getVertexDomain() {
|
||||
return VertexDomain.values()[nGetVertexDomain(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default culling mode of this material.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:culling">
|
||||
* Rasterization: culling</a>
|
||||
*/
|
||||
public CullingMode getCullingMode() {
|
||||
return CullingMode.values()[nGetCullingMode(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this material will write to the color buffer.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:colorwrite">
|
||||
* Rasterization: colorWrite</a>
|
||||
*/
|
||||
public boolean isColorWriteEnabled() {
|
||||
return nIsColorWriteEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this material will write to the depth buffer.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:depthwrite">
|
||||
* Rasterization: depthWrite</a>
|
||||
*/
|
||||
public boolean isDepthWriteEnabled() {
|
||||
return nIsDepthWriteEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this material will use depth testing.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:depthculling">
|
||||
* Rasterization: depthCulling</a>
|
||||
*/
|
||||
public boolean isDepthCullingEnabled() {
|
||||
return nIsDepthCullingEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this material is double-sided.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:doublesided">
|
||||
* Rasterization: doubleSided</a>
|
||||
*/
|
||||
public boolean isDoubleSided() {
|
||||
return nIsDoubleSided(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alpha mask threshold used when the blending mode is set to masked.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/blendingandtransparency:maskthreshold">
|
||||
* Blending and transparency: maskThreshold</a>
|
||||
*/
|
||||
public float getMaskThreshold() {
|
||||
return nGetMaskThreshold(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the screen-space variance for specular-antialiasing. This value is between 0 and 1.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/anti-aliasing:specularantialiasingvariance">
|
||||
* Anti-aliasing: specularAntiAliasingVariance</a>
|
||||
*/
|
||||
public float getSpecularAntiAliasingVariance() {
|
||||
return nGetSpecularAntiAliasingVariance(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the clamping threshold for specular-antialiasing. This value is between 0 and 1.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/anti-aliasing:specularantialiasingthreshold">
|
||||
* Anti-aliasing: specularAntiAliasingThreshold</a>
|
||||
*/
|
||||
public float getSpecularAntiAliasingThreshold() {
|
||||
return nGetSpecularAntiAliasingThreshold(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of {@link VertexBuffer.VertexAttribute}s that are required by this material.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/vertexandattributes:requires">
|
||||
* Vertex and attributes: requires</a>
|
||||
*/
|
||||
public Set<VertexBuffer.VertexAttribute> getRequiredAttributes() {
|
||||
if (mRequiredAttributes == null) {
|
||||
int bitSet = nGetRequiredAttributes(getNativeObject());
|
||||
@@ -228,14 +473,38 @@ public class Material {
|
||||
return mRequiredAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bit set representing the set of {@link VertexBuffer.VertexAttribute}s that are
|
||||
* required by this material. Use {@link #getRequiredAttributes()} to get these as a Set object.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/vertexandattributes:requires">
|
||||
* Vertex and attributes: requires</a>
|
||||
*/
|
||||
int getRequiredAttributesAsInt() {
|
||||
return nGetRequiredAttributes(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of parameters declared by this material.
|
||||
* The returned value can be 0.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/general:parameters">
|
||||
* General: parameters</a>
|
||||
*/
|
||||
public int getParameterCount() {
|
||||
return nGetParameterCount(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of Parameter objects representing this material's parameters.
|
||||
* The list may be empty if the material has no declared parameters.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/general:parameters">
|
||||
* General: parameters</a>
|
||||
*/
|
||||
public List<Parameter> getParameters() {
|
||||
int count = getParameterCount();
|
||||
List<Parameter> parameters = new ArrayList<>(count);
|
||||
@@ -243,92 +512,314 @@ public class Material {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether a parameter of the given name exists on this material.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/general:parameters">
|
||||
* General: parameters</a>
|
||||
*/
|
||||
public boolean hasParameter(@NonNull String name) {
|
||||
return nHasParameter(getNativeObject(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, boolean x) {
|
||||
mDefaultInstance.setParameter(name, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, float x) {
|
||||
mDefaultInstance.setParameter(name, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of an int parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, int x) {
|
||||
mDefaultInstance.setParameter(name, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool2 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, boolean x, boolean y) {
|
||||
mDefaultInstance.setParameter(name, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float2 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, float x, float y) {
|
||||
mDefaultInstance.setParameter(name, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of an int2 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, int x, int y) {
|
||||
mDefaultInstance.setParameter(name, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool3 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, boolean x, boolean y, boolean z) {
|
||||
mDefaultInstance.setParameter(name, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float3 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, float x, float y, float z) {
|
||||
mDefaultInstance.setParameter(name, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a int3 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, int x, int y, int z) {
|
||||
mDefaultInstance.setParameter(name, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool4 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, boolean x, boolean y, boolean z, boolean w) {
|
||||
mDefaultInstance.setParameter(name, x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float4 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, float x, float y, float z, float w) {
|
||||
mDefaultInstance.setParameter(name, x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a int4 parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, int x, int y, int z, int w) {
|
||||
mDefaultInstance.setParameter(name, x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a bool parameter array by name.
|
||||
*
|
||||
* @param name name of the parameter array as defined by this Material
|
||||
* @param type the number of components for each individual parameter
|
||||
* @param v array of values to set to the named parameter array
|
||||
* @param offset the number of elements to skip
|
||||
* @param count the number of elements in the parameter array to set
|
||||
*
|
||||
* <p>For example, to set a parameter array of 4 bool4s:
|
||||
* <pre>{@code
|
||||
* boolean[] a = new boolean[4 * 4];
|
||||
* material.setDefaultParameter("param", MaterialInstance.BooleanElement.BOOL4, a, 0, 4);
|
||||
* }</pre>
|
||||
* To only set the last 3 elements, specify an offset of 1 and a count of 3:
|
||||
* <pre>{@code
|
||||
* boolean[] a = new boolean[4 * 3];
|
||||
* material.setDefaultParameter("param", MaterialInstance.BooleanElement.BOOL4, a, 1, 3);
|
||||
* }</pre>
|
||||
* </p>
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name,
|
||||
@NonNull MaterialInstance.BooleanElement type, @NonNull @Size(min = 1) boolean[] v,
|
||||
@IntRange(from = 0) int offset, @IntRange(from = 1) int count) {
|
||||
mDefaultInstance.setParameter(name, type, v, offset, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an int parameter array by name.
|
||||
*
|
||||
* @param name name of the parameter array as defined by this Material
|
||||
* @param type the number of components for each individual parameter
|
||||
* @param v array of values to set to the named parameter array
|
||||
* @param offset the number of elements to skip
|
||||
* @param count the number of elements in the parameter array to set
|
||||
*
|
||||
* <p>For example, to set a parameter array of 4 int4s:
|
||||
* <pre>{@code
|
||||
* int[] a = new int[4 * 4];
|
||||
* material.setDefaultParameter("param", MaterialInstance.IntElement.INT4, a, 0, 4);
|
||||
* }</pre>
|
||||
* To only set the last 3 elements, specify an offset of 1 and a count of 3:
|
||||
* <pre>{@code
|
||||
* int[] a = new int[4 * 3];
|
||||
* material.setDefaultParameter("param", MaterialInstance.IntElement.INT4, a, 1, 3);
|
||||
* }</pre>
|
||||
* </p>
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name,
|
||||
@NonNull MaterialInstance.IntElement type, @NonNull @Size(min = 1) int[] v,
|
||||
@IntRange(from = 0) int offset, @IntRange(from = 1) int count) {
|
||||
mDefaultInstance.setParameter(name, type, v, offset, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a float parameter array by name.
|
||||
*
|
||||
* @param name name of the parameter array as defined by this Material
|
||||
* @param type the number of components for each individual parameter
|
||||
* @param v array of values to set to the named parameter array
|
||||
* @param offset the number of elements to skip
|
||||
* @param count the number of elements in the parameter array to set
|
||||
*
|
||||
* <p>For example, to set a parameter array of 4 float4s:
|
||||
* <pre>{@code
|
||||
* float[] a = new float[4 * 4];
|
||||
* material.setDefaultParameter("param", MaterialInstance.FloatElement.FLOAT4, a, 0, 4);
|
||||
* }</pre>
|
||||
* To only set the last 3 elements, specify an offset of 1 and a count of 3:
|
||||
* <pre>{@code
|
||||
* float[] a = new float[4 * 3];
|
||||
* material.setDefaultParameter("param", MaterialInstance.FloatElement.FLOAT4, a, 1, 3);
|
||||
* }</pre>
|
||||
* </p>
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name,
|
||||
@NonNull MaterialInstance.FloatElement type, @NonNull @Size(min = 1) float[] v,
|
||||
@IntRange(from = 0) int offset, @IntRange(from = 1) int count) {
|
||||
mDefaultInstance.setParameter(name, type, v, offset, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the given parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material color parameter
|
||||
* @param type whether the color is specified in the linear or sRGB space
|
||||
* @param r red component
|
||||
* @param g green component
|
||||
* @param b blue component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, @NonNull Colors.RgbType type,
|
||||
float r, float g, float b) {
|
||||
mDefaultInstance.setParameter(name, type, r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the given parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material color parameter
|
||||
* @param type whether the color is specified in the linear or sRGB space
|
||||
* @param r red component
|
||||
* @param g green component
|
||||
* @param b blue component
|
||||
* @param a alpha component
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name, @NonNull Colors.RgbaType type,
|
||||
float r, float g, float b, float a) {
|
||||
mDefaultInstance.setParameter(name, type, r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a texture and sampler parameter on this material's default instance.
|
||||
*
|
||||
* @param name The name of the material texture parameter
|
||||
* @param texture The texture to set as parameter
|
||||
* @param sampler The sampler to be used with this texture
|
||||
*
|
||||
* @see Material#getDefaultInstance()
|
||||
*/
|
||||
public void setDefaultParameter(@NonNull String name,
|
||||
@NonNull Texture texture, @NonNull TextureSampler sampler) {
|
||||
mDefaultInstance.setParameter(name, texture, sampler);
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Material");
|
||||
}
|
||||
@@ -354,6 +845,8 @@ public class Material {
|
||||
private static native boolean nIsDepthCullingEnabled(long nativeMaterial);
|
||||
private static native boolean nIsDoubleSided(long nativeMaterial);
|
||||
private static native float nGetMaskThreshold(long nativeMaterial);
|
||||
private static native float nGetSpecularAntiAliasingVariance(long nativeMaterial);
|
||||
private static native float nGetSpecularAntiAliasingThreshold(long nativeMaterial);
|
||||
|
||||
private static native int nGetParameterCount(long nativeMaterial);
|
||||
private static native void nGetParameters(long nativeMaterial,
|
||||
|
||||
@@ -21,8 +21,9 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
public class MaterialInstance {
|
||||
private final Material mMaterial;
|
||||
private Material mMaterial;
|
||||
private long mNativeObject;
|
||||
private long mNativeMaterial;
|
||||
|
||||
public enum BooleanElement {
|
||||
BOOL,
|
||||
@@ -52,114 +53,384 @@ public class MaterialInstance {
|
||||
mNativeObject = nativeMaterialInstance;
|
||||
}
|
||||
|
||||
MaterialInstance(long nativeMaterial, long nativeMaterialInstance) {
|
||||
mNativeMaterial = nativeMaterial;
|
||||
mNativeObject = nativeMaterialInstance;
|
||||
}
|
||||
|
||||
/** @return the {@link Material} associated with this instance */
|
||||
@NonNull
|
||||
public Material getMaterial() {
|
||||
if (mMaterial == null) {
|
||||
mMaterial = new Material(mNativeMaterial);
|
||||
}
|
||||
return mMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x) {
|
||||
nSetParameterBool(getNativeObject(), name, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x) {
|
||||
nSetParameterFloat(getNativeObject(), name, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of an int parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x) {
|
||||
nSetParameterInt(getNativeObject(), name, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool2 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x, boolean y) {
|
||||
nSetParameterBool2(getNativeObject(), name, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float2 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x, float y) {
|
||||
nSetParameterFloat2(getNativeObject(), name, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of an int2 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x, int y) {
|
||||
nSetParameterInt2(getNativeObject(), name, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool3 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x, boolean y, boolean z) {
|
||||
nSetParameterBool3(getNativeObject(), name, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float3 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x, float y, float z) {
|
||||
nSetParameterFloat3(getNativeObject(), name, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a int3 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x, int y, int z) {
|
||||
nSetParameterInt3(getNativeObject(), name, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a bool4 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x, boolean y, boolean z, boolean w) {
|
||||
nSetParameterBool4(getNativeObject(), name, x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a float4 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x, float y, float z, float w) {
|
||||
nSetParameterFloat4(getNativeObject(), name, x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a int4 parameter.
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x, int y, int z, int w) {
|
||||
nSetParameterInt4(getNativeObject(), name, x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a texture and sampler parameter on this material's default instance.
|
||||
*
|
||||
* @param name The name of the material texture parameter
|
||||
* @param texture The texture to set as parameter
|
||||
* @param sampler The sampler to be used with this texture
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull Texture texture, @NonNull TextureSampler sampler) {
|
||||
nSetParameterTexture(getNativeObject(), name, texture.getNativeObject(), sampler.mSampler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a bool parameter array by name.
|
||||
*
|
||||
* @param name name of the parameter array as defined by this Material
|
||||
* @param type the number of components for each individual parameter
|
||||
* @param v array of values to set to the named parameter array
|
||||
* @param offset the number of elements to skip
|
||||
* @param count the number of elements in the parameter array to set
|
||||
*
|
||||
* <p>For example, to set a parameter array of 4 bool4s:
|
||||
* <pre>{@code
|
||||
* boolean[] a = new boolean[4 * 4];
|
||||
* instance.setParameter("param", MaterialInstance.BooleanElement.BOOL4, a, 0, 4);
|
||||
* }</pre>
|
||||
* To only set the last 3 elements, specify an offset of 1 and a count of 3:
|
||||
* <pre>{@code
|
||||
* boolean[] a = new boolean[4 * 3];
|
||||
* instance.setParameter("param", MaterialInstance.BooleanElement.BOOL4, a, 1, 3);
|
||||
* }</pre>
|
||||
* </p>
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull BooleanElement type, @NonNull boolean[] v,
|
||||
@IntRange(from = 0) int offset, @IntRange(from = 1) int count) {
|
||||
nSetBooleanParameterArray(getNativeObject(), name, type.ordinal(), v, offset, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an int parameter array by name.
|
||||
*
|
||||
* @param name name of the parameter array as defined by this Material
|
||||
* @param type the number of components for each individual parameter
|
||||
* @param v array of values to set to the named parameter array
|
||||
* @param offset the number of elements to skip
|
||||
* @param count the number of elements in the parameter array to set
|
||||
*
|
||||
* <p>For example, to set a parameter array of 4 int4s:
|
||||
* <pre>{@code
|
||||
* int[] a = new int[4 * 4];
|
||||
* instance.setParameter("param", MaterialInstance.IntElement.INT4, a, 0, 4);
|
||||
* }</pre>
|
||||
* To only set the last 3 elements, specify an offset of 1 and a count of 3:
|
||||
* <pre>{@code
|
||||
* int[] a = new int[4 * 3];
|
||||
* instance.setParameter("param", MaterialInstance.IntElement.INT4, a, 1, 3);
|
||||
* }</pre>
|
||||
* </p>
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull IntElement type, @NonNull int[] v,
|
||||
@IntRange(from = 0) int offset, @IntRange(from = 1) int count) {
|
||||
nSetIntParameterArray(getNativeObject(), name, type.ordinal(), v, offset, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a float parameter array by name.
|
||||
*
|
||||
* @param name name of the parameter array as defined by this Material
|
||||
* @param type the number of components for each individual parameter
|
||||
* @param v array of values to set to the named parameter array
|
||||
* @param offset the number of elements to skip
|
||||
* @param count the number of elements in the parameter array to set
|
||||
*
|
||||
* <p>For example, to set a parameter array of 4 float4s:
|
||||
* <pre>{@code
|
||||
* float[] a = new float[4 * 4];
|
||||
* material.setDefaultParameter("param", MaterialInstance.FloatElement.FLOAT4, a, 0, 4);
|
||||
* }</pre>
|
||||
* To only set the last 3 elements, specify an offset of 1 and a count of 3:
|
||||
* <pre>{@code
|
||||
* float[] a = new float[4 * 3];
|
||||
* material.setDefaultParameter("param", MaterialInstance.FloatElement.FLOAT4, a, 1, 3);
|
||||
* }</pre>
|
||||
* </p>
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull FloatElement type, @NonNull float[] v,
|
||||
@IntRange(from = 0) int offset, @IntRange(from = 1) int count) {
|
||||
nSetFloatParameterArray(getNativeObject(), name, type.ordinal(), v, offset, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the given parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material color parameter
|
||||
* @param type whether the color is specified in the linear or sRGB space
|
||||
* @param r red component
|
||||
* @param g green component
|
||||
* @param b blue component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, @NonNull Colors.RgbType type,
|
||||
float r, float g, float b) {
|
||||
setParameter(name, FloatElement.FLOAT3, Colors.toLinear(type, r, g, b), 0, 1);
|
||||
float[] color = Colors.toLinear(type, r, g, b);
|
||||
nSetParameterFloat3(getNativeObject(), name, color[0], color[1], color[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the given parameter on this material's default instance.
|
||||
*
|
||||
* @param name the name of the material color parameter
|
||||
* @param type whether the color is specified in the linear or sRGB space
|
||||
* @param r red component
|
||||
* @param g green component
|
||||
* @param b blue component
|
||||
* @param a alpha component
|
||||
*/
|
||||
public void setParameter(@NonNull String name, @NonNull Colors.RgbaType type,
|
||||
float r, float g, float b, float a) {
|
||||
setParameter(name, FloatElement.FLOAT4, Colors.toLinear(type, r, g, b, a), 0, 1);
|
||||
float[] color = Colors.toLinear(type, r, g, b, a);
|
||||
nSetParameterFloat4(getNativeObject(), name, color[0], color[1], color[2], color[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up a custom scissor rectangle; by default this encompasses the View.
|
||||
*
|
||||
* @param left left coordinate of the scissor box
|
||||
* @param bottom bottom coordinate of the scissor box
|
||||
* @param width width of the scissor box
|
||||
* @param height height of the scissor box
|
||||
*/
|
||||
public void setScissor(@IntRange(from = 0) int left, @IntRange(from = 0) int bottom,
|
||||
@IntRange(from = 0) int width, @IntRange(from = 0) int height) {
|
||||
nSetScissor(getNativeObject(), left, bottom, width, height);
|
||||
}
|
||||
|
||||
/** Returns the scissor rectangle to its default setting, which encompasses the View. */
|
||||
public void unsetScissor() {
|
||||
nUnsetScissor(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a polygon offset that will be applied to all renderables drawn with this material
|
||||
* instance.
|
||||
*
|
||||
* The value of the offset is scale * dz + r * constant, where dz is the change in depth
|
||||
* relative to the screen area of the triangle, and r is the smallest value that is guaranteed
|
||||
* to produce a resolvable offset for a given implementation. This offset is added before the
|
||||
* depth test.
|
||||
*
|
||||
* @warning using a polygon offset other than zero has a significant negative performance
|
||||
* impact, as most implementations have to disable early depth culling. DO NOT USE unless
|
||||
* absolutely necessary.
|
||||
*
|
||||
* @param scale scale factor used to create a variable depth offset for each triangle
|
||||
* @param constant scale factor used to create a constant depth offset for each triangle
|
||||
*/
|
||||
public void setPolygonOffset(float scale, float constant) {
|
||||
nSetPolygonOffset(getNativeObject(), scale, constant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the minimum alpha value a fragment must have to not be discarded when the blend
|
||||
* mode is MASKED. Defaults to 0.4 if it has not been set in the parent Material. The specified
|
||||
* value should be between 0 and 1 and will be clamped if necessary.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/blendingandtransparency:maskthreshold">
|
||||
* Blending and transparency: maskThreshold</a>
|
||||
*/
|
||||
public void setMaskThreshold(float threshold) {
|
||||
nSetMaskThreshold(getNativeObject(), threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the screen space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing. The default value is set to 0.15. The specified value should be between
|
||||
* 0 and 1 and will be clamped if necessary.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/anti-aliasing:specularantialiasingvariance">
|
||||
* Anti-aliasing: specularAntiAliasingVariance</a>
|
||||
*/
|
||||
public void setSpecularAntiAliasingVariance(float variance) {
|
||||
nSetSpecularAntiAliasingVariance(getNativeObject(), variance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing. The default value is set to 0.2. The specified value should be between 0
|
||||
* and 1 and will be clamped if necessary.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/anti-aliasing:specularantialiasingthreshold">
|
||||
* Anti-aliasing: specularAntiAliasingThreshold</a>
|
||||
*/
|
||||
public void setSpecularAntiAliasingThreshold(float threshold) {
|
||||
nSetSpecularAntiAliasingThreshold(getNativeObject(), threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables double-sided lighting if the parent Material has double-sided capability,
|
||||
* otherwise prints a warning. If double-sided lighting is enabled, backface culling is
|
||||
* automatically disabled.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:doublesided">
|
||||
* Rasterization: doubleSided</a>
|
||||
*/
|
||||
public void setDoubleSided(boolean doubleSided) {
|
||||
nSetDoubleSided(getNativeObject(), doubleSided);
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
/**
|
||||
* Overrides the default triangle culling state that was set on the material.
|
||||
*
|
||||
* @see
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:culling">
|
||||
* Rasterization: culling</a>
|
||||
*/
|
||||
public void setCullingMode(Material.CullingMode mode) {
|
||||
nSetCullingMode(getNativeObject(), mode.ordinal());
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed MaterialInstance");
|
||||
}
|
||||
@@ -218,9 +489,16 @@ public class MaterialInstance {
|
||||
private static native void nUnsetScissor(long nativeMaterialInstance);
|
||||
|
||||
private static native void nSetPolygonOffset(long nativeMaterialInstance,
|
||||
float scale, float constant);
|
||||
float scale, float constant);
|
||||
|
||||
private static native void nSetMaskThreshold(long nativeMaterialInstance, float threshold);
|
||||
|
||||
private static native void nSetSpecularAntiAliasingVariance(long nativeMaterialInstance,
|
||||
float variance);
|
||||
private static native void nSetSpecularAntiAliasingThreshold(long nativeMaterialInstance,
|
||||
float threshold);
|
||||
|
||||
private static native void nSetDoubleSided(long nativeMaterialInstance, boolean doubleSided);
|
||||
|
||||
private static native void nSetCullingMode(long nativeMaterialInstance, long mode);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,29 @@ import android.support.annotation.Size;
|
||||
public final class MathUtils {
|
||||
private MathUtils() { }
|
||||
|
||||
/**
|
||||
* Packs the tangent frame represented by the specified tangent, bitangent, and normal into a
|
||||
* quaternion.
|
||||
*
|
||||
* <p>
|
||||
* Reflection is preserved by encoding it as the sign of the w component in the resulting
|
||||
* quaternion. Since -0 cannot always be represented on the GPU, this function computes a bias
|
||||
* to ensure values are always either positive or negative, never 0. The bias is computed based
|
||||
* on a per-element storage size of 2 bytes, making the resulting quaternion suitable for
|
||||
* storage into an SNORM16 vector.
|
||||
* </p>
|
||||
*
|
||||
* @param tangentX the X component of the tangent
|
||||
* @param tangentY the Y component of the tangent
|
||||
* @param tangentZ the Z component of the tangent
|
||||
* @param bitangentX the X component of the bitangent
|
||||
* @param bitangentY the Y component of the bitangent
|
||||
* @param bitangentZ the Z component of the bitangent
|
||||
* @param normalX the X component of the normal
|
||||
* @param normalY the Y component of the normal
|
||||
* @param normalZ the Z component of the normal
|
||||
* @param quaternion a float array of at least size 4 for the quaternion result to be stored
|
||||
*/
|
||||
public static void packTangentFrame(
|
||||
float tangentX, float tangentY, float tangentZ,
|
||||
float bitangentX, float bitangentY, float bitangentZ,
|
||||
@@ -34,6 +57,30 @@ public final class MathUtils {
|
||||
normalX, normalY, normalZ, quaternion, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Packs the tangent frame represented by the specified tangent, bitangent, and normal into a
|
||||
* quaternion.
|
||||
*
|
||||
* <p>
|
||||
* Reflection is preserved by encoding it as the sign of the w component in the resulting
|
||||
* quaternion. Since -0 cannot always be represented on the GPU, this function computes a bias
|
||||
* to ensure values are always either positive or negative, never 0. The bias is computed based
|
||||
* on a per-element storage size of 2 bytes, making the resulting quaternion suitable for
|
||||
* storage into an SNORM16 vector.
|
||||
* </p>
|
||||
*
|
||||
* @param tangentX the X component of the tangent
|
||||
* @param tangentY the Y component of the tangent
|
||||
* @param tangentZ the Z component of the tangent
|
||||
* @param bitangentX the X component of the bitangent
|
||||
* @param bitangentY the Y component of the bitangent
|
||||
* @param bitangentZ the Z component of the bitangent
|
||||
* @param normalX the X component of the normal
|
||||
* @param normalY the Y component of the normal
|
||||
* @param normalZ the Z component of the normal
|
||||
* @param quaternion a float array of at least size 4 for the quaternion result to be stored
|
||||
* @param offset offset, in elements, into the quaternion array to store the results
|
||||
*/
|
||||
public static void packTangentFrame(
|
||||
float tangentX, float tangentY, float tangentZ,
|
||||
float bitangentX, float bitangentY, float bitangentZ,
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.android.filament.proguard.UsedByNative;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
@@ -26,6 +28,7 @@ import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
@UsedByNative("NioUtils.cpp")
|
||||
final class NioUtils {
|
||||
|
||||
enum BufferType {
|
||||
@@ -41,18 +44,22 @@ final class NioUtils {
|
||||
private NioUtils() {
|
||||
}
|
||||
|
||||
@UsedByNative("NioUtils.cpp")
|
||||
static long getBasePointer(@NonNull Buffer b, long address, int sizeShift) {
|
||||
return address != 0 ? address + (b.position() << sizeShift) : 0;
|
||||
}
|
||||
|
||||
@UsedByNative("NioUtils.cpp")
|
||||
static Object getBaseArray(@NonNull Buffer b) {
|
||||
return b.hasArray() ? b.array() : null;
|
||||
}
|
||||
|
||||
@UsedByNative("NioUtils.cpp")
|
||||
static int getBaseArrayOffset(@NonNull Buffer b, int sizeShift) {
|
||||
return b.hasArray() ? ((b.arrayOffset() + b.position()) << sizeShift) : 0;
|
||||
}
|
||||
|
||||
@UsedByNative("NioUtils.cpp")
|
||||
static int getBufferType(@NonNull Buffer b) {
|
||||
if (b instanceof ByteBuffer) {
|
||||
return BufferType.BYTE.ordinal();
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* An offscreen render target that can be associated with a {@link View} and contains
|
||||
* weak references to a set of attached {@link Texture} objects.
|
||||
*
|
||||
* <p>
|
||||
* Clients are responsible for the lifetime of all associated <code>Texture</code> attachments.
|
||||
* </p>
|
||||
*
|
||||
* @see View
|
||||
*/
|
||||
public class RenderTarget {
|
||||
private long mNativeObject;
|
||||
private final Texture[] mTextures = new Texture[2];
|
||||
|
||||
private RenderTarget(long nativeRenderTarget, Builder builder) {
|
||||
mNativeObject = nativeRenderTarget;
|
||||
mTextures[0] = builder.mTextures[0];
|
||||
mTextures[1] = builder.mTextures[1];
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed RenderTarget");
|
||||
}
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* An attachment point is a slot that can be assigned to a {@link Texture}.
|
||||
*/
|
||||
public enum AttachmentPoint {
|
||||
COLOR,
|
||||
DEPTH,
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs <code>RenderTarget</code> objects using a builder pattern.
|
||||
*/
|
||||
public static class Builder {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
|
||||
private final BuilderFinalizer mFinalizer;
|
||||
private final long mNativeBuilder;
|
||||
private final Texture[] mTextures = new Texture[2];
|
||||
|
||||
public Builder() {
|
||||
mNativeBuilder = nCreateBuilder();
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a texture to a given attachment point.
|
||||
*
|
||||
* <p>All RenderTargets must have a non-null <code>COLOR</code> attachment.</p>
|
||||
*
|
||||
* @param attachment The attachment point of the texture.
|
||||
* @param texture The associated texture object.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder texture(@NonNull AttachmentPoint attachment, @Nullable Texture texture) {
|
||||
mTextures[attachment.ordinal()] = texture;
|
||||
nBuilderTexture(mNativeBuilder, attachment.ordinal(), texture != null ? texture.getNativeObject() : 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mipmap level for a given attachment point.
|
||||
*
|
||||
* @param attachment The attachment point of the texture.
|
||||
* @param level The associated mipmap level, 0 by default.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder mipLevel(@NonNull AttachmentPoint attachment, @IntRange(from = 0) int level) {
|
||||
nBuilderMipLevel(mNativeBuilder, attachment.ordinal(), level);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cubemap face for a given attachment point.
|
||||
*
|
||||
* @param attachment The attachment point.
|
||||
* @param face The associated cubemap face.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder face(@NonNull AttachmentPoint attachment, Texture.CubemapFace face) {
|
||||
nBuilderFace(mNativeBuilder, attachment.ordinal(), face.ordinal());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the layer for a given attachment point (for 3D textures).
|
||||
*
|
||||
* @param attachment The attachment point.
|
||||
* @param layer The associated cubemap layer.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder layer(@NonNull AttachmentPoint attachment, @IntRange(from = 0) int layer) {
|
||||
nBuilderLayer(mNativeBuilder, attachment.ordinal(), layer);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the RenderTarget object and returns a pointer to it.
|
||||
*
|
||||
* @return pointer to the newly created object or nullptr if exceptions are disabled and
|
||||
* an error occurred.
|
||||
*/
|
||||
@NonNull
|
||||
public RenderTarget build(@NonNull Engine engine) {
|
||||
long nativeRenderTarget = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
if (nativeRenderTarget == 0)
|
||||
throw new IllegalStateException("Couldn't create RenderTarget");
|
||||
return new RenderTarget(nativeRenderTarget, this);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the texture set on the given attachment point.
|
||||
*
|
||||
* @param attachment Attachment point
|
||||
* @return A Texture object or nullptr if no texture is set for this attachment point
|
||||
*/
|
||||
@Nullable
|
||||
public Texture getTexture(@NonNull AttachmentPoint attachment) {
|
||||
return mTextures[attachment.ordinal()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mipmap level set on the given attachment point.
|
||||
*
|
||||
* @param attachment Attachment point
|
||||
* @return the mipmap level set on the given attachment point
|
||||
*/
|
||||
@IntRange(from = 0)
|
||||
public int getMipLevel(@NonNull AttachmentPoint attachment) {
|
||||
return nGetMipLevel(getNativeObject(), attachment.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the face of a cubemap set on the given attachment point.
|
||||
*
|
||||
* @param attachment Attachment point
|
||||
* @return A cubemap face identifier. This is only relevant if the attachment's texture is
|
||||
* a cubemap.
|
||||
*/
|
||||
public Texture.CubemapFace getFace(AttachmentPoint attachment) {
|
||||
return Texture.CubemapFace.values()[nGetFace(getNativeObject(), attachment.ordinal())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the texture-layer set on the given attachment point.
|
||||
*
|
||||
* @param attachment Attachment point
|
||||
* @return A texture layer. This is only relevant if the attachment's texture is a 3D texture.
|
||||
*/
|
||||
@IntRange(from = 0)
|
||||
public int getLayer(@NonNull AttachmentPoint attachment) {
|
||||
return nGetLayer(getNativeObject(), attachment.ordinal());
|
||||
}
|
||||
|
||||
void clearNativeObject() {
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
private static native long nCreateBuilder();
|
||||
private static native long nDestroyBuilder(long nativeBuilder);
|
||||
private static native long nBuilderTexture(long nativeBuilder, int attachment, long nativeTexture);
|
||||
private static native long nBuilderMipLevel(long nativeBuilder, int attachment, int level);
|
||||
private static native long nBuilderFace(long nativeBuilder, int attachment, int face);
|
||||
private static native long nBuilderLayer(long nativeBuilder, int attachment, int layer);
|
||||
private static native long nBuilderBuild(long nativeBuilder, long nativeEngine);
|
||||
|
||||
private static native int nGetMipLevel(long nativeRenderTarget, int attachment);
|
||||
private static native int nGetFace(long nativeRenderTarget, int attachment);
|
||||
private static native int nGetLayer(long nativeRenderTarget, int attachment);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,12 +23,51 @@ import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ReadOnlyBufferException;
|
||||
|
||||
/**
|
||||
* A <code>Renderer</code> instance represents an operating system's window.
|
||||
*
|
||||
* <p>
|
||||
* Typically, applications create a <code>Renderer</code> per window. The <code>Renderer</code> generates
|
||||
* drawing commands for the render thread and manages frame latency.
|
||||
* <br>
|
||||
* A Renderer generates drawing commands from a View, itself containing a Scene description.
|
||||
* </p>
|
||||
*
|
||||
* <h1>Creation and Destruction</h1>
|
||||
*
|
||||
* <p>A <code>Renderer</code> is created using {@link Engine#createRenderer} and destroyed
|
||||
* using {@link Engine#destroyRenderer}.</p>
|
||||
*
|
||||
* @see Engine
|
||||
* @see View
|
||||
*/
|
||||
public class Renderer {
|
||||
private final Engine mEngine;
|
||||
private long mNativeObject;
|
||||
|
||||
/**
|
||||
* Indicates that the <code>dstSwapChain</code> passed into {@link #copyFrame} should be
|
||||
* committed after the frame has been copied.
|
||||
*
|
||||
* @see #copyFrame
|
||||
*/
|
||||
public static final int MIRROR_FRAME_FLAG_COMMIT = 0x1;
|
||||
|
||||
/**
|
||||
* Indicates that the presentation time should be set on the <code>dstSwapChain</code>
|
||||
* passed into {@link #copyFrame} to the monotonic clock time when the frame is
|
||||
* copied.
|
||||
*
|
||||
* @see #copyFrame
|
||||
*/
|
||||
public static final int MIRROR_FRAME_FLAG_SET_PRESENTATION_TIME = 0x2;
|
||||
|
||||
/**
|
||||
* Indicates that the <code>dstSwapChain</code> passed into {@link #copyFrame} should be
|
||||
* cleared to black before the frame is copied into the specified viewport.
|
||||
*
|
||||
* @see #copyFrame
|
||||
*/
|
||||
public static final int MIRROR_FRAME_FLAG_CLEAR = 0x4;
|
||||
|
||||
Renderer(@NonNull Engine engine, long nativeRenderer) {
|
||||
@@ -36,37 +75,208 @@ public class Renderer {
|
||||
mNativeObject = nativeRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Engine} that created this <code>Renderer</code>.
|
||||
*
|
||||
* @return {@link Engine} instance this <code>Renderer</code> is associated to.
|
||||
*/
|
||||
@NonNull
|
||||
public Engine getEngine() {
|
||||
return mEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a frame for this <code>Renderer</code>.
|
||||
* <p><code>beginFrame</code> manages frame pacing, and returns whether or not a frame should be
|
||||
* drawn. The goal of this is to skip frames when the GPU falls behind in order to keep the frame
|
||||
* latency low.</p>
|
||||
*
|
||||
* <p>If a given frame takes too much time in the GPU, the CPU will get ahead of the GPU. The
|
||||
* display will draw the same frame twice producing a stutter. At this point, the CPU is
|
||||
* ahead of the GPU and depending on how many frames are buffered, latency increases.
|
||||
* beginFrame() attempts to detect this situation and returns <code>false</code> in that case,
|
||||
* indicating to the caller to skip the current frame.</p>
|
||||
*
|
||||
* <p>All calls to render() must happen <b>after</b> beginFrame().</p>
|
||||
*
|
||||
* @param swapChain the {@link SwapChain} instance to use
|
||||
*
|
||||
* @return <code>false</code> if the current frame must be skipped<br>
|
||||
* When skipping a frame, the whole frame is canceled, and {@link #endFrame} must not
|
||||
* be called.
|
||||
*
|
||||
* @see #endFrame
|
||||
* @see #render
|
||||
*/
|
||||
public boolean beginFrame(@NonNull SwapChain swapChain) {
|
||||
return nBeginFrame(getNativeObject(), swapChain.getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes the current frame and schedules it for display.
|
||||
* <p>
|
||||
* <code>endFrame()</code> schedules the current frame to be displayed on the
|
||||
* <code>Renderer</code>'s window.
|
||||
* </p>
|
||||
*
|
||||
* <br><p>All calls to render() must happen <b>before</b> endFrame().</p>
|
||||
*
|
||||
* @see #beginFrame
|
||||
* @see #render
|
||||
*/
|
||||
public void endFrame() {
|
||||
nEndFrame(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a {@link View} into this <code>Renderer</code>'s window.
|
||||
*
|
||||
* <p>
|
||||
* This is filament's main rendering method, most of the CPU-side heavy lifting is performed
|
||||
* here. The purpose of the <code>render()</code> function is to generate render commands which
|
||||
* are asynchronously executed by the {@link Engine}'s render thread.
|
||||
* </p>
|
||||
*
|
||||
* <p><code>render()</code> generates commands for each of the following stages:</p>
|
||||
* <ul>
|
||||
* <li>Shadow map pass, if needed (currently only a single shadow map is supported)</li>
|
||||
* <li>Depth pre-pass</li>
|
||||
* <li>SSAO pass, if enabled</li>
|
||||
* <li>Color pass</li>
|
||||
* <li>Post-processing pass</li>
|
||||
* </ul>
|
||||
*
|
||||
* A typical render loop looks like this:
|
||||
*
|
||||
* <pre>
|
||||
* void renderLoop(Renderer renderer, SwapChain swapChain) {
|
||||
* do {
|
||||
* // typically we wait for VSYNC and user input events
|
||||
* if (renderer.beginFrame(swapChain)) {
|
||||
* renderer.render(mView);
|
||||
* renderer.endFrame();
|
||||
* }
|
||||
* } while (!quit());
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <ul>
|
||||
*<li><code>render()</code> must be called <b>after</b> {@link #beginFrame} and <b>before</b>
|
||||
*{@link #endFrame}.</li>
|
||||
*
|
||||
*<li><code>render()</code> must be called from the {@link Engine}'s main thread
|
||||
*(or external synchronization must be provided). In particular, calls to <code>render()</code>
|
||||
*on different <code>Renderer</code> instances <b>must</b> be synchronized.</li>
|
||||
*
|
||||
*<li><code>render()</code> performs potentially heavy computations and cannot be multi-threaded.
|
||||
*However, internally, it is highly multi-threaded to both improve performance and mitigate
|
||||
*the call's latency.</li>
|
||||
*
|
||||
*<li><code>render()</code> is typically called once per frame (but not necessarily).</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param view the {@link View} to render
|
||||
*
|
||||
* @see #beginFrame
|
||||
* @see #endFrame
|
||||
* @see View
|
||||
*
|
||||
*/
|
||||
public void render(@NonNull View view) {
|
||||
nRender(getNativeObject(), view.getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method MUST be called before endFrame.
|
||||
* Copies the currently rendered {@link View} to the indicated {@link SwapChain}, using the
|
||||
* indicated source and destination rectangle.
|
||||
*
|
||||
* <p><code>copyFrame()</code> should be called after a frame is rendered using {@link #render}
|
||||
* but before {@link #endFrame} is called.</p>
|
||||
*
|
||||
* @param dstSwapChain the {@link SwapChain} into which the frame should be copied
|
||||
* @param dstViewport the destination rectangle in which to draw the view
|
||||
* @param srcViewport the source rectangle to be copied
|
||||
* @param flags one or more <code>CopyFrameFlag</code> behavior configuration flags
|
||||
*/
|
||||
public void mirrorFrame(
|
||||
public void copyFrame(
|
||||
@NonNull SwapChain dstSwapChain, @NonNull Viewport dstViewport,
|
||||
@NonNull Viewport srcViewport, int flags) {
|
||||
nMirrorFrame(getNativeObject(), dstSwapChain.getNativeObject(),
|
||||
nCopyFrame(getNativeObject(), dstSwapChain.getNativeObject(),
|
||||
dstViewport.left, dstViewport.bottom, dstViewport.width, dstViewport.height,
|
||||
srcViewport.left, srcViewport.bottom, srcViewport.width, srcViewport.height,
|
||||
flags);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void mirrorFrame(
|
||||
@NonNull SwapChain dstSwapChain, @NonNull Viewport dstViewport,
|
||||
@NonNull Viewport srcViewport, int flags) {
|
||||
copyFrame(dstSwapChain, dstViewport, srcViewport, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method MUST be called before endFrame.
|
||||
* Reads back the content of the {@link SwapChain} associated with this <code>Renderer</code>.
|
||||
*
|
||||
*<pre>
|
||||
*
|
||||
* Framebuffer as seen on User buffer (PixelBufferDescriptor)
|
||||
* screen
|
||||
* +--------------------+
|
||||
* | | .stride .alignment
|
||||
* | | ----------------------->-->
|
||||
* | | O----------------------+--+ low addresses
|
||||
* | | | | | |
|
||||
* | w | | | .top | |
|
||||
* | <---------> | | V | |
|
||||
* | +---------+ | | +---------+ | |
|
||||
* | | ^ | | ======> | | | | |
|
||||
* | x | h| | | |.left| | | |
|
||||
* +------>| v | | +---->| | | |
|
||||
* | +.........+ | | +.........+ | |
|
||||
* | ^ | | | |
|
||||
* | y | | +----------------------+--+ high addresses
|
||||
* O------------+-------+
|
||||
*
|
||||
*</pre>
|
||||
*
|
||||
*
|
||||
* <p>Typically <code>readPixels</code> will be called after {@link #render} and before
|
||||
* {@link #endFrame}.</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.
|
||||
* Typically, this will happen after multiple calls to {@link #beginFrame},
|
||||
* {@link #render}, {@link #endFrame}.</p>
|
||||
* <br>
|
||||
* <p><code>readPixels</code> is intended for debugging and testing.
|
||||
* It will impact performance significantly.</p>
|
||||
*
|
||||
* @param xoffset left offset of the sub-region to read back
|
||||
* @param yoffset bottom offset of the sub-region to read back
|
||||
* @param width width of the sub-region to read back
|
||||
* @param height height of the sub-region to read back
|
||||
* @param buffer client-side buffer where the read-back will be written
|
||||
*
|
||||
* <p>
|
||||
* The following format are always supported:
|
||||
* <li>{@link Texture.Format#RGBA}</li>
|
||||
* <li>{@link Texture.Format#RGBA_INTEGER}</li>
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The following types are always supported:
|
||||
* <li>{@link Texture.Type#UBYTE}</li>
|
||||
* <li>{@link Texture.Type#UINT}</li>
|
||||
* <li>{@link Texture.Type#INT}</li>
|
||||
* <li>{@link Texture.Type#FLOAT}</li>
|
||||
* </p>
|
||||
*
|
||||
* <p>Other combination of format/type may be supported. If a combination is
|
||||
* not supported, this operation may fail silently. Use a DEBUG build
|
||||
* to get some logs about the failure.</p>
|
||||
*
|
||||
* @exception BufferOverflowException if the specified parameters would result in reading
|
||||
* outside of <code>buffer</code>.
|
||||
*/
|
||||
public void readPixels(
|
||||
@IntRange(from = 0) int xoffset, @IntRange(from = 0) int yoffset,
|
||||
@@ -89,15 +299,71 @@ public class Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
double getUserTime() {
|
||||
/**
|
||||
* Returns a timestamp (in seconds) for the last call to {@link #beginFrame}. This value is
|
||||
* constant for all {@link View views} rendered during a frame. The epoch is set with
|
||||
* {@link #resetUserTime}.
|
||||
* <br>
|
||||
* <p>In materials, this value can be queried using <code>vec4 getUserTime()</code>. The value
|
||||
* returned is a <code>highp vec4</code> encoded as follows:</p>
|
||||
* <pre>
|
||||
* time.x = (float)Renderer.getUserTime();
|
||||
* time.y = Renderer.getUserTime() - time.x;
|
||||
* </pre>
|
||||
*
|
||||
* It follows that the following invariants are true:
|
||||
* <pre>
|
||||
* (double)time.x + (double)time.y == Renderer.getUserTime()
|
||||
* time.x == (float)Renderer.getUserTime()
|
||||
* </pre>
|
||||
*
|
||||
* This encoding allows the shader code to perform high precision (i.e. double) time
|
||||
* calculations when needed despite the lack of double precision in the shader, e.g.:
|
||||
* <br>
|
||||
* To compute <code>(double)time * vertex</code> in the material, use the following construct:
|
||||
* <pre>
|
||||
* vec3 result = time.x * vertex + time.y * vertex;
|
||||
* </pre>
|
||||
*
|
||||
* Most of the time, high precision computations are not required, but be aware that the
|
||||
* precision of <code>time.x</code> rapidly diminishes as time passes:
|
||||
*
|
||||
* <center>
|
||||
* <table border="1">
|
||||
* <tr align="center"><th> time </th><th> precision </th></tr>
|
||||
* <tr align="center"><td> 16.7s </td><td> us </td></tr>
|
||||
* <tr align="center"><td> 4h39.7s </td><td> ms </td></tr>
|
||||
* <tr align="center"><td> 77h </td><td> 1/60s </td></tr>
|
||||
* </table>
|
||||
* </center>
|
||||
* <p>
|
||||
*
|
||||
* In other words, it is only possible to get microsecond accuracy for about 16s or millisecond
|
||||
* accuracy for just under 5h. This problem can be mitigated by calling {@link #resetUserTime},
|
||||
* or using high precision time as described above.
|
||||
*
|
||||
* @return the time in seconds since {@link #resetUserTime} was last called
|
||||
*
|
||||
* @see #resetUserTime
|
||||
*/
|
||||
public double getUserTime() {
|
||||
return nGetUserTime(getNativeObject());
|
||||
}
|
||||
|
||||
void resetUserTime() {
|
||||
/**
|
||||
* Sets the user time epoch to now, i.e. resets the user time to zero.
|
||||
* <br>
|
||||
* <p>Use this method used to keep the precision of time high in materials, in practice it should
|
||||
* be called at least when the application is paused, e.g.
|
||||
* {@link android.app.Activity#onPause() Activity.onPause} in Android.</p>
|
||||
*
|
||||
* @see #getUserTime
|
||||
*/
|
||||
public void resetUserTime() {
|
||||
nResetUserTime(getNativeObject());
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Renderer");
|
||||
}
|
||||
@@ -111,7 +377,7 @@ public class Renderer {
|
||||
private static native boolean nBeginFrame(long nativeRenderer, long nativeSwapChain);
|
||||
private static native void nEndFrame(long nativeRenderer);
|
||||
private static native void nRender(long nativeRenderer, long nativeView);
|
||||
private static native void nMirrorFrame(long nativeRenderer, long nativeDstSwapChain,
|
||||
private static native void nCopyFrame(long nativeRenderer, long nativeDstSwapChain,
|
||||
int dstLeft, int dstBottom, int dstWidth, int dstHeight,
|
||||
int srcLeft, int srcBottom, int srcWidth, int srcHeight,
|
||||
int flags);
|
||||
|
||||
@@ -18,6 +18,28 @@ package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A <code>Scene</code> is a flat container of {@link RenderableManager} and {@link LightManager}
|
||||
* components.
|
||||
* <br>
|
||||
* <p>A <code>Scene</code> doesn't provide a hierarchy of objects, i.e.: it's not a scene-graph.
|
||||
* However, it manages the list of objects to render and the list of lights. These can
|
||||
* be added or removed from a <code>Scene</code> at any time.
|
||||
* Moreover clients can use {@link TransformManager} to create a graph of transforms.</p>
|
||||
* <br>
|
||||
* <p>A {@link RenderableManager} component <b>must</b> be added to a <code>Scene</code> in order
|
||||
* to be rendered, and the <code>Scene</code> must be provided to a {@link View}.</p>
|
||||
*
|
||||
* <h1>Creation and Destruction</h1>
|
||||
*
|
||||
* A <code>Scene</code> is created using {@link Engine#createScene} and destroyed using
|
||||
* {@link Engine#destroyScene(Scene)}.
|
||||
*
|
||||
* @see View
|
||||
* @see LightManager
|
||||
* @see RenderableManager
|
||||
* @see TransformManager
|
||||
*/
|
||||
public class Scene {
|
||||
private long mNativeObject;
|
||||
private @Nullable Skybox mSkybox;
|
||||
@@ -27,31 +49,78 @@ public class Scene {
|
||||
mNativeObject = nativeScene;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link Skybox} or <code>null</code> if none is set
|
||||
* @see #setSkybox(Skybox)
|
||||
*/
|
||||
@Nullable
|
||||
public Skybox getSkybox() {
|
||||
return mSkybox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Skybox}.
|
||||
*
|
||||
* The {@link Skybox} is drawn last and covers all pixels not touched by geometry.
|
||||
*
|
||||
* @param skybox the {@link Skybox} to use to fill untouched pixels,
|
||||
* or <code>null</code> to unset the {@link Skybox}.
|
||||
*/
|
||||
public void setSkybox(@Nullable Skybox skybox) {
|
||||
mSkybox = skybox;
|
||||
nSetSkybox(getNativeObject(), mSkybox != null ? mSkybox.getNativeObject() : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link IndirectLight} or <code>null</code> if none is set
|
||||
* @see #setIndirectLight(IndirectLight)
|
||||
*/
|
||||
@Nullable
|
||||
public IndirectLight getIndirectLight() {
|
||||
return mIndirectLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link IndirectLight} to use when rendering the <code>Scene</code>.
|
||||
*
|
||||
* Currently, a <code>Scene</code> may only have a single {@link IndirectLight}.
|
||||
* This call replaces the current {@link IndirectLight}.
|
||||
*
|
||||
* @param ibl the {@link IndirectLight} to use when rendering the <code>Scene</code>
|
||||
* or <code>null</code> to unset.
|
||||
*/
|
||||
public void setIndirectLight(@Nullable IndirectLight ibl) {
|
||||
mIndirectLight = ibl;
|
||||
nSetIndirectLight(getNativeObject(),
|
||||
mIndirectLight != null ? mIndirectLight.getNativeObject() : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an {@link Entity} to the <code>Scene</code>.
|
||||
*
|
||||
* @param entity the entity is ignored if it doesn't have a {@link RenderableManager} component
|
||||
* or {@link LightManager} component.<br>
|
||||
* A given {@link Entity} object can only be added once to a <code>Scene</code>.
|
||||
*/
|
||||
public void addEntity(@Entity int entity) {
|
||||
nAddEntity(getNativeObject(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of entities to the <code>Scene</code>.
|
||||
*
|
||||
* @param entities array containing entities to add to the <code>Scene</code>.
|
||||
*/
|
||||
public void addEntities(@Entity int[] entities) {
|
||||
nAddEntities(getNativeObject(), entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an {@link Entity} from the <code>Scene</code>.
|
||||
*
|
||||
* @param entity the {@link Entity} to remove from the <code>Scene</code>. If the specified
|
||||
* <code>entity</code> doesn't exist, this call is ignored.
|
||||
*/
|
||||
public void removeEntity(@Entity int entity) {
|
||||
nRemove(getNativeObject(), entity);
|
||||
}
|
||||
@@ -63,15 +132,25 @@ public class Scene {
|
||||
removeEntity(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of {@link RenderableManager} components in the <code>Scene</code>.
|
||||
*
|
||||
* @return number of {@link RenderableManager} components in the <code>Scene</code>..
|
||||
*/
|
||||
public int getRenderableCount() {
|
||||
return nGetRenderableCount(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of {@link LightManager} components in the <code>Scene</code>.
|
||||
*
|
||||
* @return number of {@link LightManager} components in the <code>Scene</code>..
|
||||
*/
|
||||
public int getLightCount() {
|
||||
return nGetLightCount(getNativeObject());
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Scene");
|
||||
}
|
||||
@@ -85,6 +164,7 @@ public class Scene {
|
||||
private static native void nSetSkybox(long nativeScene, long nativeSkybox);
|
||||
private static native void nSetIndirectLight(long nativeScene, long nativeIndirectLight);
|
||||
private static native void nAddEntity(long nativeScene, int entity);
|
||||
private static native void nAddEntities(long nativeScene, int[] entities);
|
||||
private static native void nRemove(long nativeScene, int entity);
|
||||
private static native int nGetRenderableCount(long nativeScene);
|
||||
private static native int nGetLightCount(long nativeScene);
|
||||
|
||||
@@ -19,35 +19,123 @@ package com.google.android.filament;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.android.filament.proguard.UsedByReflection;
|
||||
|
||||
/**
|
||||
* Skybox
|
||||
* <p>When added to a {@link Scene}, the <code>Skybox</code> fills all untouched pixels.</p>
|
||||
*
|
||||
* <h1>Creation and destruction</h1>
|
||||
*
|
||||
* A <code>Skybox</code> object is created using the {@link Skybox.Builder} and destroyed by calling
|
||||
* {@link Engine#destroySkybox}.<br>
|
||||
* <pre>
|
||||
* Engine engine = Engine.create();
|
||||
*
|
||||
* Scene scene = engine.createScene();
|
||||
*
|
||||
* Skybox skybox = new Skybox.Builder()
|
||||
* .environment(cubemap)
|
||||
* .build(engine);
|
||||
*
|
||||
* scene.setSkybox(skybox);
|
||||
* </pre>
|
||||
*
|
||||
* Currently only {@link Texture} based sky boxes are supported.
|
||||
*
|
||||
* @see Scene
|
||||
* @see IndirectLight
|
||||
*/
|
||||
public class Skybox {
|
||||
private long mNativeObject;
|
||||
|
||||
private Skybox(long nativeSkybox) {
|
||||
@UsedByReflection("KtxLoader.java")
|
||||
Skybox(long nativeSkybox) {
|
||||
mNativeObject = nativeSkybox;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct a <code>Skybox</code> object instance.
|
||||
*/
|
||||
public static class Builder {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
|
||||
private final BuilderFinalizer mFinalizer;
|
||||
private final long mNativeBuilder;
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct a <code>Skybox</code> object instance.
|
||||
*/
|
||||
public Builder() {
|
||||
mNativeBuilder = nCreateBuilder();
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the environment map (i.e. the skybox content).
|
||||
*
|
||||
* <p>The <code>Skybox</code> is rendered as though it were an infinitely large cube with the
|
||||
* camera inside it. This means that the cubemap which is mapped onto the cube's exterior
|
||||
* will appear mirrored. This follows the OpenGL conventions.</p>
|
||||
*
|
||||
* <p>The <code>cmgen</code> tool generates reflection maps by default which are therefore
|
||||
* ideal to use as skyboxes.</p>
|
||||
*
|
||||
* @param cubemap A cubemap {@link Texture}
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @see Texture
|
||||
*/
|
||||
@NonNull
|
||||
public Builder environment(@NonNull Texture texture) {
|
||||
nBuilderEnvironment(mNativeBuilder, texture.getNativeObject());
|
||||
public Builder environment(@NonNull Texture cubemap) {
|
||||
nBuilderEnvironment(mNativeBuilder, cubemap.getNativeObject());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the sun should be rendered. The sun can only be
|
||||
* rendered if there is at least one light of type {@link LightManager.Type#SUN} in
|
||||
* the {@link Scene}. The default value is <code>false</code>.
|
||||
*
|
||||
* @param show <code>true</code> if the sun should be rendered, <code>false</code> otherwise
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder showSun(boolean show) {
|
||||
nBuilderShowSun(mNativeBuilder, show);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <code>Skybox</code> intensity when no {@link IndirectLight} is set
|
||||
*
|
||||
* <p>This call is ignored when an {@link IndirectLight} is set, otherwise it is used in
|
||||
* its place.</p>
|
||||
*
|
||||
* @param envIntensity Scale factor applied to the skybox texel values such that
|
||||
* the result is in cd/m<sup>2</sup> (lux) units (default = 30000)
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @see IndirectLight.Builder#intensity
|
||||
*/
|
||||
@NonNull
|
||||
public Builder intensity(float envIntensity) {
|
||||
nBuilderIntensity(mNativeBuilder, envIntensity);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>Skybox</code> object
|
||||
*
|
||||
* @param engine the {@link Engine} to associate this <code>Skybox</code> with.
|
||||
*
|
||||
* @return A newly created <code>Skybox</code>object
|
||||
*
|
||||
* @exception IllegalStateException can be thrown if the <code>Skybox</code> couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public Skybox build(@NonNull Engine engine) {
|
||||
long nativeSkybox = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
@@ -72,15 +160,36 @@ public class Skybox {
|
||||
}
|
||||
}
|
||||
|
||||
public void setLayerMask(@IntRange(from = 0, to = 255) int select, @IntRange(from = 0, to = 255) int value) {
|
||||
nSetLayerMask(getNativeObject(), select & 0xff, value & 0xff);
|
||||
/**
|
||||
* Sets bits in a visibility mask. By default, this is <code>0x1</code>.
|
||||
* <p>This provides a simple mechanism for hiding or showing this <code>Skybox</code> in a
|
||||
* {@link Scene}.</p>
|
||||
*
|
||||
* <p>For example, to set bit 1 and reset bits 0 and 2 while leaving all other bits unaffected,
|
||||
* call: <code>setLayerMask(7, 2)</code>.</p>
|
||||
*
|
||||
* @param select the set of bits to affect
|
||||
* @param values the replacement values for the affected bits
|
||||
*
|
||||
* @see View#setVisibleLayers
|
||||
*/
|
||||
public void setLayerMask(@IntRange(from = 0, to = 255) int select, @IntRange(from = 0, to = 255) int values) {
|
||||
nSetLayerMask(getNativeObject(), select & 0xff, values & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the visibility mask bits
|
||||
*/
|
||||
public int getLayerMask() {
|
||||
return nGetLayerMask(getNativeObject());
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
/**
|
||||
* Returns the <code>Skybox</code>'s intensity in cd/m<sup>2</sup>.
|
||||
*/
|
||||
public float getIntensity() { return nGetIntensity(getNativeObject()); }
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Skybox");
|
||||
}
|
||||
@@ -95,7 +204,9 @@ public class Skybox {
|
||||
private static native void nDestroyBuilder(long nativeSkyboxBuilder);
|
||||
private static native void nBuilderEnvironment(long nativeSkyboxBuilder, long nativeTexture);
|
||||
private static native void nBuilderShowSun(long nativeSkyboxBuilder, boolean show);
|
||||
private static native void nBuilderIntensity(long nativeSkyboxBuilder, float intensity);
|
||||
private static native long nBuilderBuild(long nativeSkyboxBuilder, long nativeEngine);
|
||||
private static native void nSetLayerMask(long nativeSkybox, int select, int value);
|
||||
private static native int nGetLayerMask(long nativeSkybox);
|
||||
private static native float nGetIntensity(long nativeSkybox);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@ import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ReadOnlyBufferException;
|
||||
|
||||
/**
|
||||
* <code>Stream</code> is used to attach a native video stream to a filament {@link Texture}.
|
||||
*
|
||||
* @see Texture#setExternalStream
|
||||
* @see Engine#destroyStream
|
||||
*/
|
||||
public class Stream {
|
||||
private long mNativeObject;
|
||||
private long mNativeEngine;
|
||||
@@ -32,20 +38,31 @@ public class Stream {
|
||||
mNativeEngine = engine.getNativeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct an Stream object instance.
|
||||
*/
|
||||
public static class Builder {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
|
||||
private final BuilderFinalizer mFinalizer;
|
||||
private final long mNativeBuilder;
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct an Stream object instance.
|
||||
*/
|
||||
public Builder() {
|
||||
mNativeBuilder = nCreateBuilder();
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepted types for the stream source:
|
||||
* - Android: SurfaceView
|
||||
* - Other: none
|
||||
* Creates a native stream. Native streams can sample data directly from an
|
||||
* opaque platform object such as a {@link android.graphics.SurfaceTexture SurfaceTexture}
|
||||
* on Android.
|
||||
*
|
||||
* @param streamSource an opaque native stream handle, e.g.: on Android this must be a
|
||||
* {@link android.graphics.SurfaceTexture SurfaceTexture} object
|
||||
* @return This Builder, for chaining calls.
|
||||
* @see Texture#setExternalStream
|
||||
*/
|
||||
@NonNull
|
||||
public Builder stream(@NonNull Object streamSource) {
|
||||
@@ -56,24 +73,57 @@ public class Stream {
|
||||
throw new IllegalArgumentException("Invalid stream source: " + streamSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy stream. A copy stream will sample data from the supplied
|
||||
* external texture and copy it into an internal private texture.
|
||||
*
|
||||
* <p>Currently only OpenGL external texture ids are supported.</p>
|
||||
*
|
||||
* @param externalTextureId An opaque texture id (typically a GLuint created with
|
||||
* <code>glGenTextures()</code>) in a context shared with
|
||||
* filament -- in that case this texture's target must be
|
||||
* <code>GL_TEXTURE_EXTERNAL_OES.</code>
|
||||
* @return This Builder, for chaining calls.
|
||||
* @see Texture#setExternalStream
|
||||
*/
|
||||
@NonNull
|
||||
public Builder stream(long externalTextureId) {
|
||||
nBuilderStream(mNativeBuilder, externalTextureId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param width initial width of the incoming stream. Whether this value is used is
|
||||
* stream dependent. On Android, it must be set when using
|
||||
* {@link #stream(long)}
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder width(int width) {
|
||||
nBuilderWidth(mNativeBuilder, width);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param height initial height of the incoming stream. Whether this value is used is
|
||||
* stream dependent. On Android, it must be set when using
|
||||
* {@link #stream(long)}
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder height(int height) {
|
||||
nBuilderHeight(mNativeBuilder, height);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Stream</code> object instance.
|
||||
*
|
||||
* @param engine {@link Engine} instance to associate this <code>Stream</code> with.
|
||||
*
|
||||
* @return newly created <code>Stream</code> object
|
||||
* @exception IllegalStateException if the <code>Stream</code> couldn't be created
|
||||
*/
|
||||
@NonNull
|
||||
public Stream build(@NonNull Engine engine) {
|
||||
long nativeStream = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
@@ -99,14 +149,92 @@ public class Stream {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this <code>Stream</code> is a native stream or a copy stream.
|
||||
*
|
||||
* @return true if this is a native <code>Stream</code>, false otherwise.
|
||||
*/
|
||||
public boolean isNative() {
|
||||
return nIsNative(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the size of the incoming stream. Whether this value is used is
|
||||
* stream dependent. On Android, it must be set when using
|
||||
* {@link Builder#stream(long)}
|
||||
*
|
||||
* @param width new width of the incoming stream
|
||||
* @param height new height of the incoming stream
|
||||
*/
|
||||
public void setDimensions(@IntRange(from = 0) int width, @IntRange(from = 0) int height) {
|
||||
nSetDimensions(getNativeObject(), width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads back the content of the last frame of a <code>Stream</code> since the last call to
|
||||
* {@link Renderer#beginFrame}.
|
||||
*
|
||||
* <p>The Stream must be a copy stream, which can be checked with {@link #isNative()}.
|
||||
* This function is a no-op otherwise.</p>
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* Stream buffer User buffer (PixelBufferDescriptor)
|
||||
* +--------------------+
|
||||
* | | .stride .alignment
|
||||
* | | ----------------------->-->
|
||||
* | | O----------------------+--+ low addresses
|
||||
* | | | | | |
|
||||
* | w | | | .top | |
|
||||
* | <---------> | | V | |
|
||||
* | +---------+ | | +---------+ | |
|
||||
* | | ^ | | ======> | | | | |
|
||||
* | x | h| | | |.left| | | |
|
||||
* +------>| v | | +---->| | | |
|
||||
* | +.........+ | | +.........+ | |
|
||||
* | ^ | | | |
|
||||
* | y | | +----------------------+--+ high addresses
|
||||
* O------------+-------+
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* <p>Typically readPixels() will be called after {@link Renderer#beginFrame}.</p>
|
||||
*
|
||||
* <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.
|
||||
* Typically, this will happen after multiple calls to {@link Renderer#beginFrame},
|
||||
* {@link Renderer#render}, {@link Renderer#endFrame}.</p>
|
||||
*
|
||||
* <p><code>readPixels</code> is intended for debugging and testing.
|
||||
* It will impact performance significantly.</p>
|
||||
*
|
||||
* @param xoffset left offset of the sub-region to read back
|
||||
* @param yoffset bottom offset of the sub-region to read back
|
||||
* @param width width of the sub-region to read back
|
||||
* @param height height of the sub-region to read back
|
||||
* @param buffer client-side buffer where the read-back will be written
|
||||
*
|
||||
* <p>
|
||||
* The following format are always supported:
|
||||
* <li>{@link Texture.Format#RGBA}</li>
|
||||
* <li>{@link Texture.Format#RGBA_INTEGER}</li>
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The following types are always supported:
|
||||
* <li>{@link Texture.Type#UBYTE}</li>
|
||||
* <li>{@link Texture.Type#UINT}</li>
|
||||
* <li>{@link Texture.Type#INT}</li>
|
||||
* <li>{@link Texture.Type#FLOAT}</li>
|
||||
* </p>
|
||||
*
|
||||
* <p>Other combination of format/type may be supported. If a combination is
|
||||
* not supported, this operation may fail silently. Use a DEBUG build
|
||||
* to get some logs about the failure.</p>
|
||||
*
|
||||
* @exception BufferOverflowException if the specified parameters would result in reading
|
||||
* outside of <code>buffer</code>.
|
||||
*/
|
||||
public void readPixels(
|
||||
@IntRange(from = 0) int xoffset, @IntRange(from = 0) int yoffset,
|
||||
@IntRange(from = 0) int width, @IntRange(from = 0) int height,
|
||||
@@ -128,11 +256,18 @@ public class Stream {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the presentation time of the currently displayed frame in nanosecond.
|
||||
*
|
||||
* This value can change at any time.
|
||||
*
|
||||
* @return timestamp in nanosecond.
|
||||
*/
|
||||
public long getTimestamp() {
|
||||
return nGetTimestamp(getNativeObject());
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Stream");
|
||||
}
|
||||
|
||||
@@ -18,12 +18,71 @@ package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* A <code>SwapChain</code> represents an Operating System's <b>native</b> renderable surface.
|
||||
*
|
||||
* <p>Typically it's a native window or a view. Because a <code>SwapChain</code> is initialized
|
||||
* from a native object, it is given to filament as an <code>Object</code>, which must be of the
|
||||
* proper type for each platform filament is running on.</p>
|
||||
*
|
||||
* <code>
|
||||
* SwapChain swapChain = engine.createSwapChain(nativeWindow);
|
||||
* </code>
|
||||
*
|
||||
* <p>The <code>nativeWindow</code> parameter above must be of type:</p>
|
||||
*
|
||||
* <center>
|
||||
* <table border="1">
|
||||
* <tr><th> Platform </th><th> nativeWindow type </th></tr>
|
||||
* <tr><td> Android </td><td>{@link android.view.Surface Surface}</td></tr>
|
||||
* </table>
|
||||
* </center>
|
||||
* <p>
|
||||
*
|
||||
* <h1>Examples</h1>
|
||||
*
|
||||
* <h2>Android</h2>
|
||||
*
|
||||
*
|
||||
* <p>A {@link android.view.Surface Surface} can be retrieved from a
|
||||
* {@link android.view.SurfaceView SurfaceView} or {@link android.view.SurfaceHolder SurfaceHolder}
|
||||
* easily using {@link android.view.SurfaceHolder#getSurface SurfaceHolder.getSurface()} and/or
|
||||
* {@link android.view.SurfaceView#getHolder SurfaceView.getHolder()}.</p>
|
||||
*
|
||||
* <p>To use a {@link android.view.TextureView Textureview} as a <code>SwapChain</code>, it is
|
||||
* necessary to first get its {@link android.graphics.SurfaceTexture SurfaceTexture},
|
||||
* for instance using {@link android.view.TextureView.SurfaceTextureListener SurfaceTextureListener}
|
||||
* and then create a {@link android.view.Surface Surface}:</p>
|
||||
*
|
||||
* <pre>
|
||||
* // using a TextureView.SurfaceTextureListener:
|
||||
* public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
|
||||
* mSurface = new Surface(surfaceTexture);
|
||||
* // mSurface can now be used with Engine.createSwapChain()
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see Engine
|
||||
*/
|
||||
public class SwapChain {
|
||||
private final Object mSurface;
|
||||
private long mNativeObject;
|
||||
|
||||
public static final long CONFIG_DEFAULT = 0x0;
|
||||
|
||||
/**
|
||||
* This flag indicates that the <code>SwapChain</code> must be allocated with an
|
||||
* alpha-channel.
|
||||
*/
|
||||
public static final long CONFIG_TRANSPARENT = 0x1;
|
||||
|
||||
/**
|
||||
* This flag indicates that the <code>SwapChain</code> may be used as a source surface
|
||||
* for reading back render results. This config must be set when creating
|
||||
* any <code>SwapChain</code> that will be used as the source for a blit operation.
|
||||
*
|
||||
* @see Renderer#copyFrame
|
||||
*/
|
||||
public static final long CONFIG_READABLE = 0x2;
|
||||
|
||||
SwapChain(long nativeSwapChain, @NonNull Object surface) {
|
||||
@@ -31,12 +90,15 @@ public class SwapChain {
|
||||
mSurface = surface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the native <code>Object</code> this <code>SwapChain</code> was created from.
|
||||
*/
|
||||
@NonNull
|
||||
public Object getNativeWindow() {
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed SwapChain");
|
||||
}
|
||||
|
||||
@@ -21,25 +21,152 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
import com.google.android.filament.proguard.UsedByReflection;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.google.android.filament.Texture.Type.COMPRESSED;
|
||||
|
||||
/**
|
||||
* Texture
|
||||
* <p>The <code>Texture</code> class supports:</p>
|
||||
* <ul>
|
||||
* <li>2D textures</li>
|
||||
* <li>3D textures</li>
|
||||
* <li>Cube maps</li>
|
||||
* <li>mip mapping</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <h1>Usage example</h1>
|
||||
*
|
||||
* A <code>Texture</code> object is created using the {@link Texture.Builder} and destroyed by
|
||||
* calling {@link Engine#destroyTexture}. They're bound using {@link MaterialInstance#setParameter}.
|
||||
*
|
||||
* <pre>
|
||||
* Engine engine = Engine.create();
|
||||
*
|
||||
* Material material = new Material.Builder()
|
||||
* .payload( ... )
|
||||
* .build(ending);
|
||||
*
|
||||
* MaterialInstance mi = material.getDefaultInstance();
|
||||
*
|
||||
* Texture texture = new Texture.Builder()
|
||||
* .width(64)
|
||||
* .height(64)
|
||||
* .build(engine);
|
||||
*
|
||||
*
|
||||
* texture.setImage(engine, 0,
|
||||
* new Texture.PixelBufferDescriptor( ... ));
|
||||
*
|
||||
* mi.setParameter("parameterName", texture, new TextureSampler());
|
||||
* </pre>
|
||||
*
|
||||
* @see #setImage
|
||||
* @see PixelBufferDescriptor
|
||||
* @see MaterialInstance#setParameter(String, Texture, TextureSampler)
|
||||
*/
|
||||
public class Texture {
|
||||
private long mNativeObject;
|
||||
|
||||
@UsedByReflection("KtxLoader.java")
|
||||
Texture(long nativeTexture) {
|
||||
mNativeObject = nativeTexture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of sampler
|
||||
*/
|
||||
public enum Sampler {
|
||||
/** 2D sampler */
|
||||
SAMPLER_2D,
|
||||
/** Cubemap sampler */
|
||||
SAMPLER_CUBEMAP,
|
||||
/** External texture sampler */
|
||||
SAMPLER_EXTERNAL
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal texel formats
|
||||
*
|
||||
* <p>These formats are used to specify a texture's internal storage format.</p>
|
||||
*
|
||||
* <h1>Enumerants syntax format</h1>
|
||||
*
|
||||
* <code>[components][size][type]</code>
|
||||
* <br><code>components</code> : List of stored components by this format
|
||||
* <br><code>size</code> : Size in bit of each component
|
||||
* <br><code>type</code> : Type this format is stored as
|
||||
*
|
||||
* <center>
|
||||
* <table border="1">
|
||||
* <tr><th> Name </th><th> Component </th></tr>
|
||||
* <tr><td> R </td><td> Linear Red </td></tr>
|
||||
* <tr><td> RG </td><td> Linear Red, Green </td></tr>
|
||||
* <tr><td> RGB </td><td> Linear Red, Green, Blue </td></tr>
|
||||
* <tr><td> RGBA </td><td> Linear Red, Green Blue, Alpha </td></tr>
|
||||
* <tr><td> SRGB </td><td> sRGB encoded Red, Green, Blue </td></tr>
|
||||
* <tr><td> DEPTH </td><td> Depth </td></tr>
|
||||
* <tr><td> STENCIL </td><td> Stencil </td></tr>
|
||||
* </table>
|
||||
* </center>
|
||||
* <br>
|
||||
*
|
||||
* <center>
|
||||
* <table border="1">
|
||||
* <tr><th> Name </th><th> Type </th></tr>
|
||||
* <tr><td> (none) </td><td> Unsigned Normalized Integer [0, 1] </th></tr>
|
||||
* <tr><td> _SNORM </td><td> Signed Normalized Integer [-1, 1] </td></tr>
|
||||
* <tr><td> UI </td><td> Unsigned Integer [0, 2<sup>size</sup>] </td></tr>
|
||||
* <tr><td> I </td><td> Signed Integer [-2<sup>size-1</sup>, 2<sup>size-1</sup>-1] </td></tr>
|
||||
* <tr><td> F </td><td> Floating-point </td></tr>
|
||||
* </table>
|
||||
* </center>
|
||||
* <br>
|
||||
*
|
||||
* <h1>Special color formats</h1>
|
||||
*
|
||||
* There are a few special color formats that don't follow the convention above:
|
||||
*
|
||||
* <center>
|
||||
* <table border="1">
|
||||
* <tr><th> Name </th><th> Format </th></tr>
|
||||
* <tr><td> RGB565 </td><td> 5-bits for R and B, 6-bits for G. </td></tr>
|
||||
* <tr><td> RGB5_A1 </td><td> 5-bits for R, G and B, 1-bit for A. </td></tr>
|
||||
* <tr><td> RGB10_A2 </td><td> 10-bits for R, G and B, 2-bits for A. </td></tr>
|
||||
* <tr><td> RGB9_E5 </td><td> <b>Unsigned</b> floating point. 9-bits mantissa for RGB, 5-bits shared exponent </td></tr>
|
||||
* <tr><td> R11F_G11F_B10F </td><td> <b>Unsigned</b> floating point. 6-bits mantissa, for R and G, 5-bits for B. 5-bits exponent. </td></tr>
|
||||
* <tr><td> SRGB8_A8 </td><td> sRGB 8-bits with linear 8-bits alpha. </td></tr>
|
||||
* <tr><td> DEPTH24_STENCIL8 </td><td> 24-bits unsigned normalized integer depth, 8-bits stencil. </td></tr>
|
||||
* </table>
|
||||
* </center>
|
||||
* <br>
|
||||
*
|
||||
* <h1>Compressed texture formats</h1>
|
||||
*
|
||||
* Many compressed texture formats are supported as well, which include (but are not limited to)
|
||||
* the following list:
|
||||
*
|
||||
* <center>
|
||||
* <table border="1">
|
||||
* <tr><th> Name </th><th> Format </th></tr>
|
||||
* <tr><td> EAC_R11 </td><td> Compresses R11UI </td></tr>
|
||||
* <tr><td> EAC_R11_SIGNED </td><td> Compresses R11I </td></tr>
|
||||
* <tr><td> EAC_RG11 </td><td> Compresses RG11UI </td></tr>
|
||||
* <tr><td> EAC_RG11_SIGNED </td><td> Compresses RG11I </td></tr>
|
||||
* <tr><td> ETC2_RGB8 </td><td> Compresses RGB8 </td></tr>
|
||||
* <tr><td> ETC2_SRGB8 </td><td> compresses SRGB8 </td></tr>
|
||||
* <tr><td> ETC2_EAC_RGBA8 </td><td> Compresses RGBA8 </td></tr>
|
||||
* <tr><td> ETC2_EAC_SRGBA8 </td><td> Compresses SRGB8_A8 </td></tr>
|
||||
* <tr><td> ETC2_RGB8_A1 </td><td> Compresses RGB8 with 1-bit alpha </td></tr>
|
||||
* <tr><td> ETC2_SRGB8_A1 </td><td> Compresses sRGB8 with 1-bit alpha </td></tr>
|
||||
* </table>
|
||||
* </center>
|
||||
*/
|
||||
public enum InternalFormat {
|
||||
// 8-bits per element
|
||||
R8, R8_SNORM, R8UI, R8I, STENCIL8,
|
||||
@@ -60,7 +187,7 @@ public class Texture {
|
||||
RG16F, RG16UI, RG16I,
|
||||
R11F_G11F_B10F,
|
||||
RGBA8, SRGB8_A8, RGBA8_SNORM,
|
||||
UNUSED, // The RGBM InternalFormat has been replaced with a flag (Texture.Builder.rgbm)
|
||||
UNUSED, // used to be rgbm
|
||||
RGB10_A2, RGBA8UI, RGBA8I,
|
||||
DEPTH32F, DEPTH24_STENCIL8, DEPTH32F_STENCIL8,
|
||||
|
||||
@@ -89,6 +216,10 @@ public class Texture {
|
||||
DXT1_RGB, DXT1_RGBA, DXT3_RGBA, DXT5_RGBA
|
||||
}
|
||||
|
||||
/**
|
||||
* Compressed data types for use with {@link PixelBufferDescriptor}
|
||||
* @see InternalFormat
|
||||
*/
|
||||
public enum CompressedFormat {
|
||||
// Mandatory in GLES 3.0 and GL 4.3
|
||||
EAC_R11, EAC_R11_SIGNED, EAC_RG11, EAC_RG11_SIGNED,
|
||||
@@ -100,15 +231,27 @@ public class Texture {
|
||||
DXT1_RGB, DXT1_RGBA, DXT3_RGBA, DXT5_RGBA
|
||||
}
|
||||
|
||||
/**
|
||||
* Cubemap faces
|
||||
*/
|
||||
public enum CubemapFace {
|
||||
/** +x face */
|
||||
POSITIVE_X,
|
||||
/** -x face */
|
||||
NEGATIVE_X,
|
||||
/** +y face */
|
||||
POSITIVE_Y,
|
||||
/** -y face */
|
||||
NEGATIVE_Y,
|
||||
/** +z face */
|
||||
POSITIVE_Z,
|
||||
/** -z face */
|
||||
NEGATIVE_Z
|
||||
}
|
||||
|
||||
/**
|
||||
* Pixel color format
|
||||
*/
|
||||
public enum Format {
|
||||
R,
|
||||
R_INTEGER,
|
||||
@@ -118,25 +261,50 @@ public class Texture {
|
||||
RGB_INTEGER,
|
||||
RGBA,
|
||||
RGBA_INTEGER,
|
||||
RGBM,
|
||||
UNUSED,
|
||||
DEPTH_COMPONENT,
|
||||
DEPTH_STENCIL,
|
||||
STENCIL_INDEX,
|
||||
ALPHA
|
||||
}
|
||||
|
||||
/**
|
||||
* Pixel data type
|
||||
*/
|
||||
public enum Type {
|
||||
/** unsigned byte, 8-bits */
|
||||
UBYTE,
|
||||
/** signed byte, 8-bits */
|
||||
BYTE,
|
||||
/** unsigned short, 16-bits */
|
||||
USHORT,
|
||||
/** signed short, 16-bits */
|
||||
SHORT,
|
||||
/** unsigned int, 32-bits */
|
||||
UINT,
|
||||
/** signed int, 32-bits */
|
||||
INT,
|
||||
/** half-float, 16-bits float with 10 bits mantissa */
|
||||
HALF,
|
||||
/** float, 32-bits float, with 24 bits mantissa */
|
||||
FLOAT,
|
||||
COMPRESSED
|
||||
/** a compessed type */
|
||||
COMPRESSED,
|
||||
/** unsigned 5.6 (5.5 for blue) float packed in 32-bits */
|
||||
UINT_10F_11F_11F_REV
|
||||
}
|
||||
|
||||
/**
|
||||
* A descriptor to an image in main memory, typically used to transfer image data from the CPU
|
||||
* to the GPU.
|
||||
* <p>A <code>PixelBufferDescriptor</code> owns the memory buffer it references,
|
||||
* therefore <code>PixelBufferDescriptor</code> cannot be copied, but can be moved.</p>
|
||||
*
|
||||
* <code>PixelBufferDescriptor</code> releases ownership of the memory-buffer when it's
|
||||
* destroyed.
|
||||
*
|
||||
* @see #setImage
|
||||
*/
|
||||
public static class PixelBufferDescriptor {
|
||||
public Buffer storage;
|
||||
|
||||
@@ -161,6 +329,20 @@ public class Texture {
|
||||
* - Android: Handler, Executor
|
||||
* - Other: Executor
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a <code>PixelBufferDescriptor</code>
|
||||
*
|
||||
* @param storage CPU-side buffer containing the image data to upload into the texture
|
||||
* @param format Pixel {@link Format format} of the CPU-side image
|
||||
* @param type Pixel data {@link Type type} of the CPU-side image
|
||||
* @param alignment Row-alignment in bytes of the CPU-side image (1 to 8 bytes)
|
||||
* @param left Left coordinate in pixels of the CPU-side image
|
||||
* @param top Top coordinate in pixels of the CPU-side image
|
||||
* @param stride Stride in pixels of the CPU-side image (i.e. distance in pixels to the next row)
|
||||
* @param handler An {@link java.util.concurrent.Executor Executor}. On Android this can also be a {@link android.os.Handler Handler}.
|
||||
* @param callback A callback executed by <code>handler</code> when <code>storage</code> is no longer needed.
|
||||
*/
|
||||
public PixelBufferDescriptor(@NonNull Buffer storage,
|
||||
@NonNull Format format, @NonNull Type type,
|
||||
@IntRange(from = 1, to = 8) int alignment,
|
||||
@@ -178,17 +360,48 @@ public class Texture {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>PixelBufferDescriptor</code> with some default values and no callback.
|
||||
*
|
||||
* @param storage CPU-side buffer containing the image data to upload into the texture
|
||||
* @param format Pixel {@link Format format} of the CPU-side image
|
||||
* @param type Pixel data {@link Type type} of the CPU-side image
|
||||
*
|
||||
* @see #setCallback
|
||||
*/
|
||||
public PixelBufferDescriptor(@NonNull Buffer storage,
|
||||
@NonNull Format format, @NonNull Type type) {
|
||||
this(storage, format, type, 1, 0, 0, 0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>PixelBufferDescriptor</code> with some default values and no callback.
|
||||
*
|
||||
* @param storage CPU-side buffer containing the image data to upload into the texture
|
||||
* @param format Pixel {@link Format format} of the CPU-side image
|
||||
* @param type Pixel data {@link Type type} of the CPU-side image
|
||||
* @param alignment Row-alignment in bytes of the CPU-side image (1 to 8 bytes)
|
||||
*
|
||||
* @see #setCallback
|
||||
*/
|
||||
public PixelBufferDescriptor(@NonNull Buffer storage,
|
||||
@NonNull Format format, @NonNull Type type,
|
||||
@IntRange(from = 1, to = 8) int alignment) {
|
||||
this(storage, format, type, alignment, 0, 0, 0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>PixelBufferDescriptor</code> with some default values and no callback.
|
||||
*
|
||||
* @param storage CPU-side buffer containing the image data to upload into the texture
|
||||
* @param format Pixel {@link Format format} of the CPU-side image
|
||||
* @param type Pixel data {@link Type type} of the CPU-side image
|
||||
* @param alignment Row-alignment in bytes of the CPU-side image (1 to 8 bytes)
|
||||
* @param left Left coordinate in pixels of the CPU-side image
|
||||
* @param top Top coordinate in pixels of the CPU-side image
|
||||
*
|
||||
* @see #setCallback
|
||||
*/
|
||||
public PixelBufferDescriptor(@NonNull Buffer storage,
|
||||
@NonNull Format format, @NonNull Type type,
|
||||
@IntRange(from = 1, to = 8) int alignment,
|
||||
@@ -196,6 +409,14 @@ public class Texture {
|
||||
this(storage, format, type, alignment, left, top, 0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param storage CPU-side buffer containing the image data to upload into the texture
|
||||
* @param format Compressed pixel {@link CompressedFormat format} of the CPU-side image
|
||||
* @param compressedSizeInBytes Size of the compressed data in bytes
|
||||
*
|
||||
* @see #setCallback
|
||||
*/
|
||||
public PixelBufferDescriptor(@NonNull ByteBuffer storage,
|
||||
@NonNull CompressedFormat format,
|
||||
@IntRange(from = 0) int compressedSizeInBytes) {
|
||||
@@ -207,9 +428,10 @@ public class Texture {
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid handler types:
|
||||
* - Android: Handler, Executor
|
||||
* - Other: Executor
|
||||
* Set or replace the callback called when the CPU-side data is no longer needed.
|
||||
*
|
||||
* @param handler An {@link java.util.concurrent.Executor Executor}. On Android this can also be a {@link android.os.Handler Handler}.
|
||||
* @param callback A callback executed by <code>handler</code> when <code>storage</code> is no longer needed.
|
||||
*/
|
||||
public void setCallback(@Nullable Object handler, @Nullable Runnable callback) {
|
||||
this.handler = handler;
|
||||
@@ -252,7 +474,6 @@ public class Texture {
|
||||
break;
|
||||
case RGBA:
|
||||
case RGBA_INTEGER:
|
||||
case RGBM:
|
||||
n = 4;
|
||||
break;
|
||||
}
|
||||
@@ -273,6 +494,10 @@ public class Texture {
|
||||
case FLOAT:
|
||||
bpp *= 4;
|
||||
break;
|
||||
case UINT_10F_11F_11F_REV:
|
||||
// Special case, format must be RGB and uses 4 bytes
|
||||
bpp = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
int bpr = bpp * stride;
|
||||
@@ -281,64 +506,133 @@ public class Texture {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options of {@link #generatePrefilterMipmap}
|
||||
*/
|
||||
public static class PrefilterOptions {
|
||||
/** number of samples for roughness pre-filtering */
|
||||
public int sampleCount = 8;
|
||||
/** whether to generate a reflection map (mirror) */
|
||||
public boolean mirror = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given format is supported for texturing in this {@link Engine}.
|
||||
* This depends on the selected backend.
|
||||
*
|
||||
* @param engine {@link Engine} to test the {@link InternalFormat InternalFormat} against
|
||||
* @param format format to check
|
||||
* @return <code>true</code> if this format is supported for texturing.
|
||||
*/
|
||||
public static boolean isTextureFormatSupported(@NonNull Engine engine,
|
||||
@NonNull InternalFormat format) {
|
||||
return nIsTextureFormatSupported(engine.getNativeObject(), format.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct a <code>Texture</code> object instance.
|
||||
*/
|
||||
public static class Builder {
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
|
||||
// Keep to finalize native resources
|
||||
private final BuilderFinalizer mFinalizer;
|
||||
private final long mNativeBuilder;
|
||||
|
||||
/**
|
||||
* Use <code>Builder</code> to construct a <code>Texture</code> object instance.
|
||||
*/
|
||||
public Builder() {
|
||||
mNativeBuilder = nCreateBuilder();
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the width of the texture in texels.
|
||||
* @param width texture width in texels, must be at least 1. Default is 1.
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder width(@IntRange(from = 1) int width) {
|
||||
nBuilderWidth(mNativeBuilder, width);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the height of the texture in texels.
|
||||
* @param height texture height in texels, must be at least 1. Default is 1.
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder height(@IntRange(from = 1) int height) {
|
||||
nBuilderHeight(mNativeBuilder, height);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the texture's number of layers. This creates a 3D texture.
|
||||
* @param depth texture number of layer, must be at least 1. Default is 1.
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder depth(@IntRange(from = 1) int depth) {
|
||||
nBuilderDepth(mNativeBuilder, depth);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the number of mipmap levels
|
||||
* @param levels must be at least 1 and less or equal to <code>floor(log<sub>2</sub>(max(width, height))) + 1</code>. Default is 1.
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder levels(@IntRange(from = 1) int levels) {
|
||||
nBuilderLevels(mNativeBuilder, levels);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the type of sampler to use.
|
||||
* @param target {@link Sampler Sampler} type
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder sampler(@NonNull Sampler target) {
|
||||
nBuilderSampler(mNativeBuilder, target.ordinal());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the texture's internal format.
|
||||
* <p>The internal format specifies how texels are stored (which may be different from how
|
||||
* they're specified in {@link #setImage}). {@link InternalFormat InternalFormat} specifies
|
||||
* both the color components and the data type used.</p>
|
||||
* @param format texture's {@link InternalFormat internal format}.
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder format(@NonNull InternalFormat format) {
|
||||
nBuilderFormat(mNativeBuilder, format.ordinal());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the usage flags, which is necessary when attaching to {@link RenderTarget}.
|
||||
*
|
||||
* The flags argument much be a combination of {@link Usage} flags.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder rgbm(boolean enabled) {
|
||||
nBuilderRgbm(mNativeBuilder, enabled);
|
||||
public Builder usage(int flags) {
|
||||
nBuilderUsage(mNativeBuilder, flags);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Texture</code> instance.
|
||||
* @param engine The {@link Engine} to associate this <code>Texture</code> with.
|
||||
* @return A newly created <code>Texture</code>
|
||||
* @exception IllegalStateException if a parameter to a builder function was invalid.
|
||||
* A mode detailed message about the error is output in the system log.
|
||||
*/
|
||||
@NonNull
|
||||
public Texture build(@NonNull Engine engine) {
|
||||
long nativeTexture = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
@@ -365,29 +659,71 @@ public class Texture {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A bitmask to specify how the texture will be used.
|
||||
*/
|
||||
public static class Usage {
|
||||
/** The texture will be used as a color attachment */
|
||||
public static final int COLOR_ATTACHMENT = 0x1;
|
||||
/** The texture will be used as a depth attachment */
|
||||
public static final int DEPTH_ATTACHMENT = 0x2;
|
||||
/** The texture will be used as a stencil attachment */
|
||||
public static final int STENCIL_ATTACHMENT = 0x4;
|
||||
/** The texture content can be set with {@link #setImage} */
|
||||
public static final int UPLOADABLE = 0x8;
|
||||
/** The texture can be read from a shader or blitted from */
|
||||
public static final int SAMPLEABLE = 0x10;
|
||||
/** by default textures are <code>UPLOADABLE</code> and <code>SAMPLEABLE</code>*/
|
||||
public static final int DEFAULT = UPLOADABLE | SAMPLEABLE;
|
||||
}
|
||||
|
||||
public static final int BASE_LEVEL = 0;
|
||||
|
||||
/**
|
||||
* Queries the width of a given level of this texture.
|
||||
* @param level to query the with of. Must be between 0 and {@link #getLevels}
|
||||
* @return The width in texel of the given level
|
||||
*/
|
||||
public int getWidth(@IntRange(from = 0) int level) {
|
||||
return nGetWidth(getNativeObject(), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the height of a given level of this texture.
|
||||
* @param level to query the height of. Must be between 0 and {@link #getLevels}
|
||||
* @return The height in texel of the given level
|
||||
*/
|
||||
public int getHeight(@IntRange(from = 0) int level) {
|
||||
return nGetHeight(getNativeObject(), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the number of layers of given level of this texture has.
|
||||
* @param level to query the number of layers of. Must be between 0 and {@link #getLevels}
|
||||
* @return The number of layers of the given level
|
||||
*/
|
||||
public int getDepth(@IntRange(from = 0) int level) {
|
||||
return nGetDepth(getNativeObject(), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of mipmap levels of this texture
|
||||
*/
|
||||
public int getLevels() {
|
||||
return nGetLevels(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return This texture {@link Sampler Sampler} type.
|
||||
*/
|
||||
@NonNull
|
||||
public Sampler getTarget() {
|
||||
return Sampler.values()[nGetTarget(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return This texture's {@link InternalFormat InternalFormat}.
|
||||
*/
|
||||
@NonNull
|
||||
public InternalFormat getFormat() {
|
||||
return InternalFormat.values()[nGetInternalFormat(getNativeObject())];
|
||||
@@ -395,12 +731,65 @@ public class Texture {
|
||||
|
||||
// TODO: add a setImage() version that takes an android Bitmap
|
||||
|
||||
/**
|
||||
* <code>setImage</code> is used to modify the whole content of the texure from a CPU-buffer.
|
||||
*
|
||||
* <p>This <code>Texture</code> instance must use {@link Sampler#SAMPLER_2D SAMPLER_2D} or
|
||||
* {@link Sampler#SAMPLER_EXTERNAL SAMPLER_EXTERNAL}. If the later is specified
|
||||
* and external textures are supported by the driver implementation,
|
||||
* this method will have no effect, otherwise it will behave as if the
|
||||
* texture was specified with {@link Sampler#SAMPLER_2D SAMPLER_2D}.</p>
|
||||
*
|
||||
* This is equivalent to calling: <br>
|
||||
*
|
||||
* <code>setImage(engine, level, 0, 0, getWidth(level), getHeight(level), buffer)</code>
|
||||
*
|
||||
* @param engine {@link Engine} this texture is associated to. Must be the
|
||||
* instance passed to {@link Builder#build Builder.build()}.
|
||||
* @param level Level to set the image for. Must be less than {@link #getLevels()}.
|
||||
* @param buffer Client-side buffer containing the image to set.
|
||||
* <code>buffer</code>'s {@link Format format} must match that
|
||||
* of {@link #getFormat()}
|
||||
*
|
||||
* @exception BufferOverflowException if the specified parameters would result in reading
|
||||
* outside of <code>buffer</code>.
|
||||
*
|
||||
* @see Builder#sampler
|
||||
* @see PixelBufferDescriptor
|
||||
*/
|
||||
public void setImage(@NonNull Engine engine,
|
||||
@IntRange(from = 0) int level,
|
||||
@NonNull PixelBufferDescriptor buffer) {
|
||||
setImage(engine, level, 0, 0, getWidth(level), getHeight(level), buffer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <code>setImage</code> is used to modify a sub-region of the texure from a CPU-buffer.
|
||||
*
|
||||
* <p>This <code>Texture</code> instance must use {@link Sampler#SAMPLER_2D SAMPLER_2D} or
|
||||
* {@link Sampler#SAMPLER_EXTERNAL SAMPLER_EXTERNAL}. If the later is specified
|
||||
* and external textures are supported by the driver implementation,
|
||||
* this method will have no effect, otherwise it will behave as if the
|
||||
* texture was specified with {@link Sampler#SAMPLER_2D SAMPLER_2D}.</p>
|
||||
*
|
||||
* @param engine {@link Engine} this texture is associated to. Must be the
|
||||
* instance passed to {@link Builder#build Builder.build()}.
|
||||
* @param level Level to set the image for. Must be less than {@link #getLevels()}.
|
||||
* @param xoffset x-offset in texel of the region to modify
|
||||
* @param yoffset y-offset in texel of the region to modify
|
||||
* @param width width in texel of the region to modify
|
||||
* @param height height in texel of the region to modify
|
||||
* @param buffer Client-side buffer containing the image to set.
|
||||
* <code>buffer</code>'s {@link Format format} must match that
|
||||
* of {@link #getFormat()}
|
||||
*
|
||||
* @exception BufferOverflowException if the specified parameters would result in reading
|
||||
* outside of <code>buffer</code>.
|
||||
*
|
||||
* @see Builder#sampler
|
||||
* @see PixelBufferDescriptor
|
||||
*/
|
||||
public void setImage(@NonNull Engine engine,
|
||||
@IntRange(from = 0) int level,
|
||||
@IntRange(from = 0) int xoffset, @IntRange(from = 0) int yoffset,
|
||||
@@ -427,9 +816,33 @@ public class Texture {
|
||||
}
|
||||
}
|
||||
|
||||
// note: faceOffsetsInBytes are offsets in byte in the buffer relative to the current position()
|
||||
// note: use Texture CubemapFace to index the faceOffsetsInBytes array
|
||||
// note: we assume all 6 faces are tightly packed
|
||||
/**
|
||||
* <code>setImage</code> is used to specify all six images of a cubemap level and
|
||||
* follows exactly the OpenGL conventions
|
||||
*
|
||||
* <p>This <code>Texture</code> instance must use
|
||||
* {@link Sampler#SAMPLER_CUBEMAP SAMPLER_CUBEMAP}.</p>
|
||||
*
|
||||
* @param engine {@link Engine} this texture is associated to. Must be the
|
||||
* instance passed to {@link Builder#build Builder.build()}.
|
||||
* @param level Level to set the image for. Must be less than {@link #getLevels()}.
|
||||
* @param buffer Client-side buffer containing the image to set.
|
||||
* <code>buffer</code>'s {@link Format format} must match that
|
||||
* of {@link #getFormat()}
|
||||
* @param faceOffsetsInBytes Offsets in bytes into <code>buffer</code> for all six images.
|
||||
* The offsets are specified in the following order:
|
||||
* +x, -x, +y, -y, +z, -z.
|
||||
*
|
||||
* <p><code>faceOffsetsInBytes</code> are offsets in byte in the <code>buffer</code> relative
|
||||
* to the current {@link Buffer#position()}. Use {@link CubemapFace} to index the
|
||||
* <code>faceOffsetsInBytes</code> array. All six faces must be tightly packed.</p>
|
||||
*
|
||||
* @exception BufferOverflowException if the specified parameters would result in reading
|
||||
* outside of <code>buffer</code>.
|
||||
*
|
||||
* @see Builder#sampler
|
||||
* @see PixelBufferDescriptor
|
||||
*/
|
||||
public void setImage(@NonNull Engine engine, @IntRange(from = 0) int level,
|
||||
@NonNull PixelBufferDescriptor buffer,
|
||||
@NonNull @Size(min = 6) int[] faceOffsetsInBytes) {
|
||||
@@ -452,10 +865,60 @@ public class Texture {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the external image to associate with this <code>Texture</code>.
|
||||
*
|
||||
* <p>This <code>Texture</code> instance must use
|
||||
* {@link Sampler#SAMPLER_EXTERNAL SAMPLER_EXTERNAL}.</p>
|
||||
* <p>Typically the external image is OS specific, and can be a video or camera frame.
|
||||
* There are many restrictions when using an external image as a texture, such as:</p>
|
||||
* <ul>
|
||||
* <li> only the level of detail (LOD) 0 can be specified</li>
|
||||
* <li> only {@link TextureSampler.MagFilter#NEAREST NEAREST} or
|
||||
* {@link TextureSampler.MagFilter#LINEAR LINEAR} filtering is supported</li>
|
||||
* <li> the size and format of the texture is defined by the external image</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param engine {@link Engine} this texture is associated to. Must be the
|
||||
* instance passed to {@link Builder#build Builder.build()}.
|
||||
* @param eglImage An opaque handle to a platform specific image. Supported types are
|
||||
* <code>eglImageOES</code> on Android and <code>CVPixelBufferRef</code> on iOS.
|
||||
* <p>On iOS the following pixel formats are supported: <ul>
|
||||
* <li><code>kCVPixelFormatType_32BGRA</code></li>
|
||||
* <li><code>kCVPixelFormatType_420YpCbCr8BiPlanarFullRange</code></li>
|
||||
* </ul></p>
|
||||
*
|
||||
* @see Builder#sampler
|
||||
*/
|
||||
public void setExternalImage(@NonNull Engine engine, long eglImage) {
|
||||
nSetExternalImage(getNativeObject(), engine.getNativeObject(), eglImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the external stream to associate with this <code>Texture</code>.
|
||||
*
|
||||
* <p>This <code>Texture</code> instance must use
|
||||
* {@link Sampler#SAMPLER_EXTERNAL SAMPLER_EXTERNAL}.</p>
|
||||
* <p>Typically the external image is OS specific, and can be a video or camera frame.
|
||||
* There are many restrictions when using an external image as a texture, such as:</p>
|
||||
* <ul>
|
||||
* <li> only the level of detail (LOD) 0 can be specified</li>
|
||||
* <li> only {@link TextureSampler.MagFilter#NEAREST NEAREST} or
|
||||
* {@link TextureSampler.MagFilter#LINEAR LINEAR} filtering is supported</li>
|
||||
* <li> the size and format of the texture is defined by the external image</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param engine {@link Engine} this texture is associated to. Must be the
|
||||
* instance passed to {@link Builder#build Builder.build()}.
|
||||
* @param stream A {@link Stream} object
|
||||
*
|
||||
* @exception IllegalStateException if the sampler type is not
|
||||
* {@link Sampler#SAMPLER_EXTERNAL SAMPLER_EXTERNAL}
|
||||
*
|
||||
* @see Stream
|
||||
* @see Builder#sampler
|
||||
*
|
||||
*/
|
||||
public void setExternalStream(@NonNull Engine engine, @NonNull Stream stream) {
|
||||
long nativeObject = getNativeObject();
|
||||
long streamNativeObject = stream.getNativeObject();
|
||||
@@ -466,11 +929,97 @@ public class Texture {
|
||||
nSetExternalStream(nativeObject, engine.getNativeObject(), streamNativeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates all the mipmap levels automatically. This requires the texture to have a
|
||||
* color-renderable format.
|
||||
*
|
||||
* <p>This <code>Texture</code> instance must <b>not</b> use
|
||||
* {@link Sampler#SAMPLER_CUBEMAP SAMPLER_CUBEMAP}, or it has no effect.</p>
|
||||
*
|
||||
* @param engine {@link Engine} this texture is associated to. Must be the
|
||||
* instance passed to {@link Builder#build Builder.build()}.
|
||||
*/
|
||||
public void generateMipmaps(@NonNull Engine engine) {
|
||||
nGenerateMipmaps(getNativeObject(), engine.getNativeObject());
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
/**
|
||||
* Creates a reflection map from an environment map.
|
||||
*
|
||||
* <p>This is a utility function that replaces calls to {@link #setImage}.
|
||||
* The provided environment map is processed and all mipmap levels are populated. The
|
||||
* processing is similar to the offline tool <code>cmgen</code> at a lower quality setting.</p>
|
||||
*
|
||||
* <p>This function is intended to be used when the environment cannot be processed offline,
|
||||
* for instance if it's generated at runtime.</p>
|
||||
*
|
||||
* <p>The source data must obey to some constraints:</p>
|
||||
* <ul>
|
||||
* <li>the data {@link Format format} must be {@link Format#RGB}</li>
|
||||
* <li>the data {@link Type type} must be one of
|
||||
* <ul>
|
||||
* <li>{@link Type#FLOAT}</li>
|
||||
* <li>{@link Type#HALF}</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>The current texture must be a cubemap.</p>
|
||||
*
|
||||
* <p>The reflections cubemap's {@link InternalFormat internal format} cannot be a compressed format.</p>
|
||||
*
|
||||
* <p>The reflections cubemap's dimension must be a power-of-two.</p>
|
||||
*
|
||||
* <p>This operation is computationally intensive, especially with large environments and
|
||||
* is currently <b>synchronous</b>. Expect about 1ms for a 16 × 16 cubemap.</p>
|
||||
*
|
||||
* @param engine {@link Engine} this texture is associated to. Must be the
|
||||
* instance passed to {@link Builder#build Builder.build()}.
|
||||
* @param buffer Client-side buffer containing the image to set.
|
||||
* <code>buffer</code>'s {@link Format format} and {@link Type type} must match
|
||||
* the constraints above.
|
||||
* @param faceOffsetsInBytes Offsets in bytes into <code>buffer</code> for all six images.
|
||||
* The offsets are specified in the following order:
|
||||
* +x, -x, +y, -y, +z, -z.
|
||||
*
|
||||
* @param options Optional parameter to control user-specified quality and options.
|
||||
*
|
||||
* <p><code>faceOffsetsInBytes</code> are offsets in byte in the <code>buffer</code> relative
|
||||
* to the current {@link Buffer#position()}. Use {@link CubemapFace} to index the
|
||||
* <code>faceOffsetsInBytes</code> array. All six faces must be tightly packed.</p>
|
||||
*
|
||||
* @exception BufferOverflowException if the specified parameters would result in reading
|
||||
* outside of <code>buffer</code>.
|
||||
*/
|
||||
public void generatePrefilterMipmap(@NonNull Engine engine,
|
||||
@NonNull PixelBufferDescriptor buffer, @NonNull @Size(min = 6) int[] faceOffsetsInBytes,
|
||||
PrefilterOptions options) {
|
||||
|
||||
int width = getWidth(0);
|
||||
int height= getHeight(0);
|
||||
int sampleCount = 8;
|
||||
boolean mirror = true;
|
||||
if (options != null) {
|
||||
sampleCount = options.sampleCount;
|
||||
mirror = options.mirror;
|
||||
}
|
||||
|
||||
int result = nGeneratePrefilterMipmap(getNativeObject(), engine.getNativeObject(),
|
||||
width, height,
|
||||
buffer.storage, buffer.storage.remaining(),
|
||||
buffer.left, buffer.top, buffer.type.ordinal(), buffer.alignment,
|
||||
buffer.stride, buffer.format.ordinal(), faceOffsetsInBytes,
|
||||
buffer.handler, buffer.callback,
|
||||
sampleCount, mirror);
|
||||
|
||||
if (result < 0) {
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@UsedByReflection("TextureHelper.java")
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed Texture");
|
||||
}
|
||||
@@ -492,7 +1041,7 @@ public class Texture {
|
||||
private static native void nBuilderLevels(long nativeBuilder, int levels);
|
||||
private static native void nBuilderSampler(long nativeBuilder, int sampler);
|
||||
private static native void nBuilderFormat(long nativeBuilder, int format);
|
||||
private static native void nBuilderRgbm(long nativeBuilder, boolean enabled);
|
||||
private static native void nBuilderUsage(long nativeBuilder, int flags);
|
||||
private static native long nBuilderBuild(long nativeBuilder, long nativeEngine);
|
||||
|
||||
private static native int nGetWidth(long nativeTexture, int level);
|
||||
@@ -533,4 +1082,9 @@ public class Texture {
|
||||
private static native void nGenerateMipmaps(long nativeTexture, long nativeEngine);
|
||||
|
||||
private static native boolean nIsStreamValidForTexture(long nativeTexture, long nativeStream);
|
||||
|
||||
private static native int nGeneratePrefilterMipmap(long nativeIndirectLight, long nativeEngine,
|
||||
int width, int height, Buffer storage, int remaining, int left, int top,
|
||||
int type, int alignment, int stride, int format, int[] faceOffsetsInBytes,
|
||||
Object handler, Runnable callback, int sampleCount, boolean mirror);
|
||||
}
|
||||
|
||||
@@ -18,24 +18,60 @@ package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* <code>TextureSampler</code> defines how a texture is accessed.
|
||||
*/
|
||||
public class TextureSampler {
|
||||
public enum WrapMode {
|
||||
/**
|
||||
* The edge of the texture extends to infinity.
|
||||
*/
|
||||
CLAMP_TO_EDGE,
|
||||
/**
|
||||
* The texture infinitely repeats in the wrap direction.
|
||||
*/
|
||||
REPEAT,
|
||||
/**
|
||||
* The texture infinitely repeats and mirrors in the wrap direction.
|
||||
*/
|
||||
MIRRORED_REPEAT
|
||||
}
|
||||
|
||||
public enum MinFilter {
|
||||
/**
|
||||
* No filtering. Nearest neighbor is used.
|
||||
*/
|
||||
NEAREST,
|
||||
/**
|
||||
* Box filtering. Weighted average of 4 neighbors is used.
|
||||
*/
|
||||
LINEAR,
|
||||
/**
|
||||
* Mip-mapping is activated. But no filtering occurs.
|
||||
*/
|
||||
NEAREST_MIPMAP_NEAREST,
|
||||
/**
|
||||
* Box filtering within a mip-map level.
|
||||
*/
|
||||
LINEAR_MIPMAP_NEAREST,
|
||||
/**
|
||||
* Mip-map levels are interpolated, but no other filtering occurs.
|
||||
*/
|
||||
NEAREST_MIPMAP_LINEAR,
|
||||
/**
|
||||
* Both interpolated Mip-mapping and linear filtering are used.
|
||||
*/
|
||||
LINEAR_MIPMAP_LINEAR,
|
||||
}
|
||||
|
||||
public enum MagFilter {
|
||||
/**
|
||||
* No filtering. Nearest neighbor is used.
|
||||
*/
|
||||
NEAREST,
|
||||
/**
|
||||
* Box filtering. Weighted average of 4 neighbors is used.
|
||||
*/
|
||||
LINEAR
|
||||
}
|
||||
|
||||
@@ -44,114 +80,246 @@ public class TextureSampler {
|
||||
COMPARE_TO_TEXTURE
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison functions for the depth sampler.
|
||||
*/
|
||||
public enum CompareFunction {
|
||||
/**
|
||||
* Less or equal
|
||||
*/
|
||||
LESS_EQUAL,
|
||||
/**
|
||||
* Greater or equal
|
||||
*/
|
||||
GREATER_EQUAL,
|
||||
/**
|
||||
* Strictly less than
|
||||
*/
|
||||
LESS,
|
||||
/**
|
||||
* Strictly greater than
|
||||
*/
|
||||
GREATER,
|
||||
/**
|
||||
* Equal
|
||||
*/
|
||||
EQUAL,
|
||||
/**
|
||||
* Not equal
|
||||
*/
|
||||
NOT_EQUAL,
|
||||
/**
|
||||
* Always. Depth testing is deactivated.
|
||||
*/
|
||||
ALWAYS,
|
||||
/**
|
||||
* Never. The depth test always fails.
|
||||
*/
|
||||
NEVER
|
||||
}
|
||||
|
||||
int mSampler = 0; // bit field used by native
|
||||
|
||||
/**
|
||||
* Min filter: LINEAR_MIPMAP_LINEAR
|
||||
* Mag filter: LINEAR
|
||||
* Wrap mode: REPEAT
|
||||
* Initializes the <code>TextureSampler</code> with default values.
|
||||
* <br>Minification filter: {@link MinFilter#LINEAR_MIPMAP_LINEAR}
|
||||
* <br>Magnification filter: {@link MagFilter#LINEAR}
|
||||
* <br>Wrap modes: {@link WrapMode#REPEAT}
|
||||
*/
|
||||
public TextureSampler() {
|
||||
this(MinFilter.LINEAR_MIPMAP_LINEAR, MagFilter.LINEAR, WrapMode.REPEAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>TextureSampler</code> with default values, but specifying the
|
||||
* minification and magnification filters.
|
||||
*
|
||||
* @param minMag {@link MagFilter magnification filter},
|
||||
* the minification filter will be set to the same value.
|
||||
*/
|
||||
public TextureSampler(@NonNull MagFilter minMag) {
|
||||
this(minMag, WrapMode.CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>TextureSampler</code> with user specified values.
|
||||
*
|
||||
* @param minMag {@link MagFilter magnification filter},
|
||||
* the minification filter will be set to the same value.
|
||||
* @param wrap {@link WrapMode wrapping mode} for all directions
|
||||
*/
|
||||
public TextureSampler(@NonNull MagFilter minMag, @NonNull WrapMode wrap) {
|
||||
this(minFilterFromMagFilter(minMag), minMag, wrap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>TextureSampler</code> with user specified values.
|
||||
*
|
||||
* @param min {@link MagFilter magnification filter}
|
||||
* @param mag {@link MinFilter minification filter}
|
||||
* @param wrap {@link WrapMode wrapping mode} for all directions
|
||||
*/
|
||||
public TextureSampler(@NonNull MinFilter min, @NonNull MagFilter mag, @NonNull WrapMode wrap) {
|
||||
this(min, mag, wrap, wrap, wrap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>TextureSampler</code> with user specified values.
|
||||
*
|
||||
* @param min {@link MagFilter magnification filter}
|
||||
* @param mag {@link MinFilter minification filter}
|
||||
* @param s {@link WrapMode wrapping mode} for the s (horizontal) direction
|
||||
* @param t {@link WrapMode wrapping mode} for the t (vertical) direction
|
||||
* @param r {@link WrapMode wrapping mode} fot the r (depth) direction
|
||||
*/
|
||||
public TextureSampler(@NonNull MinFilter min, @NonNull MagFilter mag,
|
||||
@NonNull WrapMode s, @NonNull WrapMode t, @NonNull WrapMode r) {
|
||||
mSampler = nCreateSampler(min.ordinal(), mag.ordinal(),
|
||||
s.ordinal(), t.ordinal(), r.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>TextureSampler</code> with user specified comparison mode. The
|
||||
* comparison fonction is set to {@link CompareFunction#LESS_EQUAL}.
|
||||
*
|
||||
* @param mode {@link CompareMode comparison mode}
|
||||
*/
|
||||
public TextureSampler(@NonNull CompareMode mode) {
|
||||
this(mode, CompareFunction.LESS_EQUAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>TextureSampler</code> with user specified comparison mode and function.
|
||||
*
|
||||
* @param mode {@link CompareMode comparison mode}
|
||||
* @param function {@link CompareFunction comparison function}
|
||||
*/
|
||||
public TextureSampler(@NonNull CompareMode mode, @NonNull CompareFunction function) {
|
||||
mSampler = nCreateCompareSampler(mode.ordinal(), function.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minification filter
|
||||
*/
|
||||
public MinFilter getMinFilter() {
|
||||
return MinFilter.values()[nGetMinFilter(mSampler)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minification filter.
|
||||
*
|
||||
* @param filter minification filter
|
||||
*/
|
||||
public void setMinFilter(MinFilter filter) {
|
||||
mSampler = nSetMinFilter(mSampler, filter.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the magnification filter
|
||||
*/
|
||||
public MagFilter getMagFilter() {
|
||||
return MagFilter.values()[nGetMagFilter(mSampler)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the magnification filter.
|
||||
*
|
||||
* @param filter magnification filter
|
||||
*/
|
||||
public void setMagFilter(MagFilter filter) {
|
||||
mSampler = nSetMagFilter(mSampler, filter.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wrapping mode in the s (horizontal) direction
|
||||
*/
|
||||
public WrapMode getWrapModeS() {
|
||||
return WrapMode.values()[nGetWrapModeS(mSampler)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapping mode in the s (horizontal) direction.
|
||||
* @param mode wrapping mode
|
||||
*/
|
||||
public void setWrapModeS(WrapMode mode) {
|
||||
mSampler = nSetWrapModeS(mSampler, mode.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wrapping mode in the t (vertical) direction
|
||||
*/
|
||||
public WrapMode getWrapModeT() {
|
||||
return WrapMode.values()[nGetWrapModeT(mSampler)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapping mode in the t (vertical) direction.
|
||||
* @param mode wrapping mode
|
||||
*/
|
||||
public void setWrapModeT(WrapMode mode) {
|
||||
mSampler = nSetWrapModeT(mSampler, mode.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wrapping mode in the r (depth) direction
|
||||
*/
|
||||
public WrapMode getWrapModeR() {
|
||||
return WrapMode.values()[nGetWrapModeR(mSampler)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapping mode in the t (depth) direction.
|
||||
* @param mode wrapping mode
|
||||
*/
|
||||
public void setWrapModeR(WrapMode mode) {
|
||||
mSampler = nSetWrapModeR(mSampler, mode.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the anisotropy value
|
||||
* @see #setAnisotropy
|
||||
*/
|
||||
public float getAnisotropy() {
|
||||
return nGetAnisotropy(mSampler);
|
||||
}
|
||||
|
||||
/**
|
||||
* This controls anisotropic filtering.
|
||||
*
|
||||
* @param anisotropy Amount of anisotropy, should be a power-of-two. The default is 0.
|
||||
* The maximum permissible value is 7.
|
||||
*/
|
||||
public void setAnisotropy(float anisotropy) {
|
||||
mSampler = nSetAnisotropy(mSampler, anisotropy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comparison mode
|
||||
*/
|
||||
public CompareMode getCompareMode() {
|
||||
return CompareMode.values()[nGetCompareMode(mSampler)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comparison mode.
|
||||
*
|
||||
* @param mode comparison mode
|
||||
*/
|
||||
public void setCompareMode(CompareMode mode) {
|
||||
mSampler = nSetCompareMode(mSampler, mode.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comparison function
|
||||
*/
|
||||
public CompareFunction getCompareFunction() {
|
||||
return CompareFunction.values()[nGetCompareFunction(mSampler)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comparison function.
|
||||
* @param function the comparison function
|
||||
*/
|
||||
public void setCompareFunction(CompareFunction function) {
|
||||
mSampler = nSetCompareFunction(mSampler, function.ordinal());
|
||||
}
|
||||
|
||||
@@ -20,82 +20,219 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
public class TransformManager {
|
||||
/**
|
||||
* <code>TransformManager</code> is used to add transform components to entities.
|
||||
*
|
||||
* <p>A transform component gives an entity a position and orientation in space in the coordinate
|
||||
* space of its parent transform. The <code>TransformManager</code> takes care of computing the
|
||||
* world-space transform of each component (i.e. its transform relative to the root).</p>
|
||||
*
|
||||
* <h1>Creation and destruction</h1>
|
||||
*
|
||||
* A transform component is created using {@link TransformManager#create} and destroyed by calling
|
||||
* {@link TransformManager#destroy}.
|
||||
*
|
||||
* <pre>
|
||||
* Engine engine = Engine.create();
|
||||
* EntityManager entityManager = EntityManager().get();
|
||||
* int object = entityManager.create();
|
||||
*
|
||||
* TransformManager tcm = engine.getTransformManager();
|
||||
*
|
||||
* // create the transform component
|
||||
* tcm.create(object);
|
||||
*
|
||||
* // set its transform
|
||||
* float[] transform = ...; // transform to set
|
||||
* EntityInstance i = tcm.getInstance(object);
|
||||
* tcm.setTransform(i, transform));
|
||||
*
|
||||
* // destroy the transform component
|
||||
* tcm.destroy(object);
|
||||
* </pre>
|
||||
*
|
||||
*/public class TransformManager {
|
||||
private long mNativeObject;
|
||||
|
||||
TransformManager(long nativeTransformManager) {
|
||||
mNativeObject = nativeTransformManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a particular {@link Entity} is associated with a component of this
|
||||
* <code>TransformManager</code>
|
||||
*
|
||||
* @param entity an {@link Entity}
|
||||
* @return true if this {@link Entity} has a component associated with this manager
|
||||
*/
|
||||
public boolean hasComponent(@Entity int entity) {
|
||||
return nHasComponent(mNativeObject, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link EntityInstance} representing the transform component associated with the
|
||||
* given {@link Entity}.
|
||||
*
|
||||
* @param entity an {@link Entity}
|
||||
* @return an {@link EntityInstance}, which represents the transform component associated with
|
||||
* the {@link Entity} <code>entity</code>
|
||||
* @see #hasComponent
|
||||
*/
|
||||
@EntityInstance
|
||||
public int getInstance(@Entity int entity) {
|
||||
return nGetInstance(mNativeObject, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a transform component and associates it with the given entity. The component is
|
||||
* initialized with the identity transform.
|
||||
* 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.
|
||||
* @see #destroy
|
||||
*/
|
||||
@EntityInstance
|
||||
public int create(@Entity int entity) {
|
||||
return nCreate(mNativeObject, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) float[] localTransform) {
|
||||
return nCreateArray(mNativeObject, entity, parent, localTransform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys this component from the given entity, children are orphaned.
|
||||
*
|
||||
* @param entity an {@link Entity}.
|
||||
* If this transform had children, these are orphaned, which means their local
|
||||
* transform becomes a world transform. Usually it's nonsensical.
|
||||
* It's recommended to make sure that a destroyed transform doesn't have children.
|
||||
* @see #create
|
||||
*/
|
||||
public void destroy(@Entity int entity) {
|
||||
nDestroy(mNativeObject, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-parents an entity to a new one.
|
||||
*
|
||||
* @param i the {@link EntityInstance} of the transform component to re-parent
|
||||
* @param newParent the {@link EntityInstance} of the new parent transform.
|
||||
* It is an error to re-parent an entity to a descendant and will cause
|
||||
* undefined behaviour.
|
||||
* @see #getInstance
|
||||
*/
|
||||
public void setParent(@EntityInstance int i, @EntityInstance int newParent) {
|
||||
nSetParent(mNativeObject, i, newParent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void setTransform(@EntityInstance int i,
|
||||
@NonNull @Size(min = 16) float[] localTransform) {
|
||||
if (localTransform.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
Asserts.assertMat4fIn(localTransform);
|
||||
nSetTransform(mNativeObject, i, localTransform);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 float[] getTransform(@EntityInstance int i,
|
||||
@Nullable @Size(min = 16) float[] outLocalTransform) {
|
||||
outLocalTransform = assertMat4f(outLocalTransform);
|
||||
outLocalTransform = Asserts.assertMat4f(outLocalTransform);
|
||||
nGetTransform(mNativeObject, i, outLocalTransform);
|
||||
return outLocalTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 float[] getWorldTransform(@EntityInstance int i,
|
||||
@Nullable @Size(min = 16) float[] outWorldTransform) {
|
||||
outWorldTransform = assertMat4f(outWorldTransform);
|
||||
outWorldTransform = Asserts.assertMat4f(outWorldTransform);
|
||||
nGetWorldTransform(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.
|
||||
* However, {@link #setTransform} will perform significantly better and in constant time.
|
||||
*
|
||||
* <p>This is useful when updating many transforms and the transform hierarchy is deep (say more
|
||||
* than 4 or 5 levels).</p>
|
||||
*
|
||||
* <p>If the local transform transaction is already open, this is a no-op.</p>
|
||||
*
|
||||
* @see #commitLocalTransformTransaction
|
||||
* @see #setTransform
|
||||
*/
|
||||
public void openLocalTransformTransaction() {
|
||||
nOpenLocalTransformTransaction(mNativeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits the currently open local transform transaction. When this returns, calls
|
||||
* to {@link #getWorldTransform} will return the proper value.
|
||||
*
|
||||
* <p>Failing to call this method when done updating the local transform will cause
|
||||
* a lot of rendering problems. The system never closes the transaction
|
||||
* automatically.</p>
|
||||
*
|
||||
* <p>If the local transform transaction is not open, this is a no-op.</p>
|
||||
*
|
||||
* @see #openLocalTransformTransaction
|
||||
* @see #setTransform
|
||||
*/
|
||||
public void commitLocalTransformTransaction() {
|
||||
nCommitLocalTransformTransaction(mNativeObject);
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 16)
|
||||
private static float[] assertMat4f(@Nullable float[] out) {
|
||||
if (out == null) out = new float[16];
|
||||
else if (out.length < 16) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
|
||||
}
|
||||
return out;
|
||||
public long getNativeObject() {
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
private static native boolean nHasComponent(long nativeTransformManager, int entity);
|
||||
|
||||
@@ -23,6 +23,33 @@ import android.support.annotation.Nullable;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
|
||||
/**
|
||||
* Holds a set of buffers that define the geometry of a <code>Renderable</code>.
|
||||
*
|
||||
* <p>
|
||||
* The geometry of the <code>Renderable</code> itself is defined by a set of vertex attributes such as
|
||||
* position, color, normals, tangents, etc...
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* There is no need to have a 1-to-1 mapping between attributes and buffer. A buffer can hold the
|
||||
* data of several attributes -- attributes are then referred as being "interleaved".
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The buffers themselves are GPU resources, therefore mutating their data can be relatively slow.
|
||||
* For this reason, it is best to separate the constant data from the dynamic data into multiple
|
||||
* buffers.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* It is possible, and even encouraged, to use a single vertex buffer for several
|
||||
* <code>Renderable</code>s.
|
||||
* </p>
|
||||
*
|
||||
* @see IndexBuffer
|
||||
* @see RenderableManager
|
||||
*/
|
||||
public class VertexBuffer {
|
||||
private long mNativeObject;
|
||||
|
||||
@@ -31,13 +58,22 @@ public class VertexBuffer {
|
||||
}
|
||||
|
||||
public enum VertexAttribute {
|
||||
POSITION, // XYZ position (float3)
|
||||
TANGENTS, // tangent, bitangent and normal, encoded as a quaternion (4 floats or half floats)
|
||||
COLOR, // vertex color (float4)
|
||||
UV0, // texture coordinates (float2)
|
||||
UV1, // texture coordinates (float2)
|
||||
POSITION, // XYZ position (float3)
|
||||
TANGENTS, // tangent, bitangent and normal, encoded as a quaternion (4 floats or half floats)
|
||||
COLOR, // vertex color (float4)
|
||||
UV0, // texture coordinates (float2)
|
||||
UV1, // texture coordinates (float2)
|
||||
BONE_INDICES, // indices of 4 bones (uvec4)
|
||||
BONE_WEIGHTS // weights of the 4 bones (normalized float4)
|
||||
BONE_WEIGHTS, // weights of the 4 bones (normalized float4)
|
||||
UNUSED, // reserved for future use
|
||||
CUSTOM0, // custom or MORPH_POSITION_0
|
||||
CUSTOM1, // custom or MORPH_POSITION_1
|
||||
CUSTOM2, // custom or MORPH_POSITION_2
|
||||
CUSTOM3, // custom or MORPH_POSITION_3
|
||||
CUSTOM4, // custom or MORPH_TANGENTS_0
|
||||
CUSTOM5, // custom or MORPH_TANGENTS_1
|
||||
CUSTOM6, // custom or MORPH_TANGENTS_2
|
||||
CUSTOM7 // custom or MORPH_TANGENTS_3
|
||||
}
|
||||
|
||||
public enum AttributeType {
|
||||
@@ -68,22 +104,47 @@ public class VertexBuffer {
|
||||
HALF3,
|
||||
HALF4,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the quaternion type for the {@link #populateTangentQuaternions} utility.
|
||||
*/
|
||||
public enum QuatType {
|
||||
HALF4, // 2 bytes per component as half-floats (8 bytes per quat)
|
||||
SHORT4, // 2 bytes per component as normalized integers (8 bytes per quat)
|
||||
FLOAT4, // 4 bytes per component as floats (16 bytes per quat)
|
||||
/** 2 bytes per component as half-floats (8 bytes per quat) */
|
||||
HALF4,
|
||||
|
||||
/** 2 bytes per component as normalized integers (8 bytes per quat) */
|
||||
SHORT4,
|
||||
|
||||
/** 4 bytes per component as floats (16 bytes per quat) */
|
||||
FLOAT4,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the parameters for the {@link #populateTangentQuaternions} utility.
|
||||
*/
|
||||
public static class QuatTangentContext {
|
||||
public QuatType quatType; // desired quaternion type (required)
|
||||
public int quatCount; // number of quaternions (required)
|
||||
public Buffer outBuffer; // pre-allocated output buffer (required)
|
||||
public int outStride; // desired stride in bytes (optional)
|
||||
public Buffer normals; // source normals (required)
|
||||
public int normalsStride; // normals stride in bytes (optional)
|
||||
public Buffer tangents; // source tangents (optional)
|
||||
public int tangentsStride; // tangents stride in bytes (optional)
|
||||
/** desired quaternion type (required) */
|
||||
public QuatType quatType;
|
||||
|
||||
/** number of quaternions (required) */
|
||||
public int quatCount;
|
||||
|
||||
/** pre-allocated output buffer (required) */
|
||||
public Buffer outBuffer;
|
||||
|
||||
/** desired stride in bytes (optional) */
|
||||
public int outStride;
|
||||
|
||||
/** source normals (required) */
|
||||
public Buffer normals;
|
||||
|
||||
/** normals stride in bytes (optional) */
|
||||
public int normalsStride;
|
||||
|
||||
/** source tangents (optional) */
|
||||
public Buffer tangents;
|
||||
|
||||
/** tangents stride in bytes (optional) */
|
||||
public int tangentsStride;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -96,18 +157,64 @@ public class VertexBuffer {
|
||||
mFinalizer = new BuilderFinalizer(mNativeBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of each buffer in this set, expressed in in number of vertices.
|
||||
*
|
||||
* @param vertexCount number of vertices in each buffer in this set
|
||||
*
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder vertexCount(@IntRange(from = 1) int vertexCount) {
|
||||
nBuilderVertexCount(mNativeBuilder, vertexCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines how many buffers will be created in this vertex buffer set. These buffers are
|
||||
* later referenced by index from 0 to <code>bufferCount</code> - 1.
|
||||
*
|
||||
* This call is mandatory. The default is 0.
|
||||
*
|
||||
* @param bufferCount number of buffers in this vertex buffer set. The maximum value is 8.
|
||||
*
|
||||
* @return this <code>Builder</code> for chaining calls
|
||||
*/
|
||||
@NonNull
|
||||
public Builder bufferCount(@IntRange(from = 1) int bufferCount) {
|
||||
nBuilderBufferCount(mNativeBuilder, bufferCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up an attribute for this vertex buffer set.
|
||||
*
|
||||
* Using <code>byteOffset</code> and <code>byteStride</code>, attributes can be interleaved
|
||||
* in the same buffer.
|
||||
*
|
||||
* <p>
|
||||
* This is a no-op if the <code>attribute</code> is an invalid enum.
|
||||
* This is a no-op if the <code>bufferIndex</code> is out of bounds.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Warning: <code>VertexAttribute.TANGENTS</code> must be specified as a quaternion and is
|
||||
* how normals are specified.
|
||||
* </p>
|
||||
*
|
||||
* @param attribute the attribute to set up
|
||||
* @param bufferIndex the index of the buffer containing the data for this attribute. Must
|
||||
* be between 0 and bufferCount() - 1.
|
||||
* @param attributeType the type of the attribute data (e.g. byte, float3, etc...)
|
||||
* @param byteOffset offset in <i>bytes</i> into the buffer <code>bufferIndex</code>
|
||||
* @param byteStride stride in <i>bytes</i> to the next element of this attribute. When
|
||||
* set to zero the attribute size, as defined by
|
||||
* <code>attributeType</code> is used.
|
||||
*
|
||||
* @return A reference to this <code>Builder</code> for chaining calls.
|
||||
*
|
||||
* @see VertexAttribute
|
||||
*/
|
||||
@NonNull
|
||||
public Builder attribute(@NonNull VertexAttribute attribute,
|
||||
@IntRange(from = 0) int bufferIndex, @NonNull AttributeType attributeType,
|
||||
@@ -117,24 +224,82 @@ public class VertexBuffer {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up an attribute for this vertex buffer set.
|
||||
*
|
||||
* Using <code>byteOffset</code> and <code>byteStride</code>, attributes can be interleaved
|
||||
* in the same buffer.
|
||||
*
|
||||
* <p>
|
||||
* This is a no-op if the <code>attribute</code> is an invalid enum.
|
||||
* This is a no-op if the <code>bufferIndex</code> is out of bounds.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Warning: <code>VertexAttribute.TANGENTS</code> must be specified as a quaternion and is
|
||||
* how normals are specified.
|
||||
* </p>
|
||||
*
|
||||
* @param attribute the attribute to set up
|
||||
* @param bufferIndex the index of the buffer containing the data for this attribute. Must
|
||||
* be between 0 and bufferCount() - 1.
|
||||
* @param attributeType the type of the attribute data (e.g. byte, float3, etc...)
|
||||
*
|
||||
* @return A reference to this <code>Builder</code> for chaining calls.
|
||||
*
|
||||
* @see VertexAttribute
|
||||
*/
|
||||
@NonNull
|
||||
public Builder attribute(@NonNull VertexAttribute attribute,
|
||||
@IntRange(from = 0) int bufferIndex, @NonNull AttributeType attributeType) {
|
||||
return attribute(attribute, bufferIndex, attributeType, 0, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether a given attribute should be normalized. By default attributes are not
|
||||
* normalized. A normalized attribute is mapped between 0 and 1 in the shader. This applies
|
||||
* only to integer types.
|
||||
*
|
||||
* @param attribute enum of the attribute to set the normalization flag to
|
||||
*
|
||||
* @return this <code>Builder</code> object for chaining calls.
|
||||
*
|
||||
* This is a no-op if the <code>attribute</code> is an invalid enum.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder normalized(@NonNull VertexAttribute attribute) {
|
||||
nBuilderNormalized(mNativeBuilder, attribute.ordinal(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether a given attribute should be normalized. By default attributes are not
|
||||
* normalized. A normalized attribute is mapped between 0 and 1 in the shader. This applies
|
||||
* only to integer types.
|
||||
*
|
||||
* @param attribute enum of the attribute to set the normalization flag to
|
||||
* @param enabled true to automatically normalize the given attribute
|
||||
*
|
||||
* @return this <code>Builder</code> object for chaining calls.
|
||||
*
|
||||
* This is a no-op if the <code>attribute</code> is an invalid enum.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder normalized(@NonNull VertexAttribute attribute, boolean enabled) {
|
||||
nBuilderNormalized(mNativeBuilder, attribute.ordinal(), enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the <code>VertexBuffer</code> object and returns a pointer to it.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this <code>VertexBuffer</code>
|
||||
* with
|
||||
*
|
||||
* @return the newly created <code>VertexBuffer</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the VertexBuffer could not be created
|
||||
*/
|
||||
@NonNull
|
||||
public VertexBuffer build(@NonNull Engine engine) {
|
||||
long nativeVertexBuffer = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
|
||||
@@ -159,24 +324,68 @@ public class VertexBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertex count.
|
||||
*
|
||||
* @return number of vertices in this vertex buffer set
|
||||
*/
|
||||
@IntRange(from = 0)
|
||||
public int getVertexCount() {
|
||||
return nGetVertexCount(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously copy-initializes the specified buffer from the given buffer data.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this
|
||||
* <code>VertexBuffer</code> with
|
||||
* @param bufferIndex index of the buffer to initialize. Must be between 0 and
|
||||
* bufferCount() - 1.
|
||||
* @param buffer a CPU-side {@link Buffer} representing the data used to initialize
|
||||
* the <code>VertexBuffer</code> at index <code>bufferIndex</code>.
|
||||
* <code>buffer</code> should contain raw, untyped data that will
|
||||
* be copied as-is into the buffer.
|
||||
*/
|
||||
public void setBufferAt(@NonNull Engine engine, int bufferIndex, @NonNull Buffer buffer) {
|
||||
setBufferAt(engine, bufferIndex, buffer, 0, 0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously copy-initializes a region of the specified buffer from the given buffer data.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this
|
||||
* <code>VertexBuffer</code> with
|
||||
* @param bufferIndex index of the buffer to initialize. Must be between 0 and
|
||||
* bufferCount() - 1.
|
||||
* @param buffer a CPU-side {@link Buffer} representing the data used to initialize
|
||||
* the <code>VertexBuffer</code> at index <code>bufferIndex</code>.
|
||||
* <code>buffer</code> should contain raw, untyped data that will
|
||||
* be copied as-is into the buffer.
|
||||
* @param destOffsetInBytes offset in <i>bytes</i> into the buffer at index
|
||||
* <code>bufferIndex</code> of this vertex buffer set.
|
||||
*/
|
||||
public void setBufferAt(@NonNull Engine engine, int bufferIndex, @NonNull Buffer buffer,
|
||||
@IntRange(from = 0) int destOffsetInBytes, @IntRange(from = 0) int count) {
|
||||
setBufferAt(engine, bufferIndex, buffer, destOffsetInBytes, count, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid handler types:
|
||||
* - Android: Handler, Executor
|
||||
* - Other: Executor
|
||||
* Asynchronously copy-initializes a region of the specified buffer from the given buffer data.
|
||||
*
|
||||
* @param engine reference to the {@link Engine} to associate this
|
||||
* <code>VertexBuffer</code> with
|
||||
* @param bufferIndex index of the buffer to initialize. Must be between 0 and
|
||||
* bufferCount() - 1.
|
||||
* @param buffer a CPU-side {@link Buffer} representing the data used to initialize
|
||||
* the <code>VertexBuffer</code> at index <code>bufferIndex</code>.
|
||||
* <code>buffer</code> should contain raw, untyped data that will
|
||||
* be copied as-is into the buffer.
|
||||
* @param destOffsetInBytes offset in <i>bytes</i> into the buffer at index
|
||||
* <code>bufferIndex</code> of this vertex buffer set.
|
||||
* @param handler an {@link java.util.concurrent.Executor Executor}. On Android this
|
||||
* can also be a {@link android.os.Handler Handler}.
|
||||
* @param callback a callback executed by <code>handler</code> when <code>buffer</code>
|
||||
* is no longer needed.
|
||||
*/
|
||||
public void setBufferAt(@NonNull Engine engine, int bufferIndex, @NonNull Buffer buffer,
|
||||
@IntRange(from = 0) int destOffsetInBytes, @IntRange(from = 0) int count,
|
||||
@@ -188,7 +397,27 @@ public class VertexBuffer {
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function that consumes normal vectors (and, optionally, tangent vectors) and
|
||||
* produces quaternions that can be passed into a TANGENTS buffer.
|
||||
*
|
||||
* <p>
|
||||
* The given output buffer must be preallocated with at least quatCount * outStride bytes.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* Normals are required but tangents are optional, in which case this function tries to generate
|
||||
* reasonable tangents. The given normals should be unit length.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If supplied, the tangent vectors should be unit length and should be orthogonal to the
|
||||
* normals. The w component of the tangent is a sign (-1 or +1) indicating handedness of the
|
||||
* basis.
|
||||
* </p>
|
||||
*
|
||||
* @param context an initialized QuatTangentContext object
|
||||
*/
|
||||
public static void populateTangentQuaternions(@NonNull QuatTangentContext context) {
|
||||
nPopulateTangentQuaternions(context.quatType.ordinal(), context.quatCount,
|
||||
context.outBuffer, context.outBuffer.remaining(), context.outStride,
|
||||
@@ -197,7 +426,7 @@ public class VertexBuffer {
|
||||
context.tangentsStride);
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed VertexBuffer");
|
||||
}
|
||||
|
||||
@@ -21,8 +21,39 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
import static com.google.android.filament.Colors.*;
|
||||
import static com.google.android.filament.Colors.LinearColor;
|
||||
|
||||
/**
|
||||
* Encompasses all the state needed for rendering a {@link Scene}.
|
||||
*
|
||||
* <p>
|
||||
* {@link Renderer#render} operates on <code>View</code> objects. These <code>View</code> objects
|
||||
* specify important parameters such as:
|
||||
* </p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>The Scene</li>
|
||||
* <li>The Camera</li>
|
||||
* <li>The Viewport</li>
|
||||
* <li>Some rendering parameters</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* <code>View</code> instances are heavy objects that internally cache a lot of data needed for
|
||||
* rendering. It is not advised for an application to use many View objects.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* For example, in a game, a <code>View</code> could be used for the main scene and another one for
|
||||
* the game's user interface. More <code>View</code> instances could be used for creating special
|
||||
* effects (e.g. a <code>View</code> is akin to a rendering pass).
|
||||
* </p>
|
||||
*
|
||||
* @see Renderer
|
||||
* @see Scene
|
||||
* @see Camera
|
||||
* @see RenderTarget
|
||||
*/
|
||||
public class View {
|
||||
private long mNativeObject;
|
||||
private String mName;
|
||||
@@ -32,18 +63,105 @@ public class View {
|
||||
private DynamicResolutionOptions mDynamicResolution;
|
||||
private RenderQuality mRenderQuality;
|
||||
private DepthPrepass mDepthPrepass = DepthPrepass.DEFAULT;
|
||||
private AmbientOcclusionOptions mAmbientOcclusionOptions;
|
||||
private RenderTarget mRenderTarget;
|
||||
|
||||
/**
|
||||
* Dynamic resolution can be used to either reach a desired target frame rate by lowering the
|
||||
* resolution of a <code>View</code>, or to increase the quality when the rendering is faster
|
||||
* than the target frame rate.
|
||||
*
|
||||
* <p>
|
||||
* This structure can be used to specify the minimum scale factor used when lowering the
|
||||
* resolution of a <code>View</code>, and the maximum scale factor used when increasing the
|
||||
* resolution for higher quality rendering. The scale factors can be controlled on each X and Y
|
||||
* axis independently. By default, all scale factors are set to 1.0.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Dynamic resolution is only supported on platforms where the time to render a frame can be
|
||||
* measured accurately. Dynamic resolution is currently only supported on Android.
|
||||
* </p>
|
||||
*/
|
||||
public static class DynamicResolutionOptions {
|
||||
/**
|
||||
* Enables or disables dynamic resolution on a View.
|
||||
*/
|
||||
public boolean enabled = false;
|
||||
|
||||
/**
|
||||
* If false, the system scales the major axis first.
|
||||
*/
|
||||
public boolean homogeneousScaling = false;
|
||||
|
||||
/**
|
||||
* Desired frame time in milliseconds.
|
||||
*/
|
||||
public float targetFrameTimeMilli = 1000.0f / 60.0f;
|
||||
|
||||
/**
|
||||
* Additional headroom for the GPU as a ratio of the targetFrameTime.
|
||||
*/
|
||||
public float headRoomRatio = 0.0f;
|
||||
|
||||
/**
|
||||
* Rate at which the scale will change to reach the target frame rate.
|
||||
*/
|
||||
public float scaleRate = 0.125f;
|
||||
|
||||
/**
|
||||
* The minimum scale in X and Y this View should use.
|
||||
*/
|
||||
public float minScale = 0.5f;
|
||||
|
||||
/**
|
||||
* The maximum scale in X and Y this View should use.
|
||||
*/
|
||||
public float maxScale = 1.0f;
|
||||
|
||||
/**
|
||||
* History size. higher values, tend to filter more (clamped to 30).
|
||||
*/
|
||||
public int history = 9;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for Ambient Occlusion
|
||||
* @see #setAmbientOcclusion
|
||||
*/
|
||||
public static class AmbientOcclusionOptions {
|
||||
/**
|
||||
* Ambient Occlusion radius in meters, between 0 and ~10.
|
||||
*/
|
||||
public float radius = 0.3f;
|
||||
|
||||
/**
|
||||
* Self-occlusion bias in meters. Use to avoid self-occlusion. Between 0 and a few mm.
|
||||
*/
|
||||
public float bias = 0.005f;
|
||||
|
||||
/**
|
||||
* Controls ambient occlusion's contrast. Between 0 (linear) and 1 (squared)
|
||||
*/
|
||||
public float power = 0.0f;
|
||||
|
||||
/**
|
||||
* How each dimension of the AO buffer is scaled. Must be positive and <= 1.
|
||||
*/
|
||||
public float resolution = 0.5f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the quality of the HDR color buffer.
|
||||
*
|
||||
* <p>
|
||||
* A quality of <code>HIGH</code> or <code>ULTRA</code> means using an RGB16F or RGBA16F color
|
||||
* buffer. This means colors in the LDR range (0..1) have 10 bit precision. A quality of
|
||||
* <code>LOW</code> or <code>MEDIUM</code> means using an R11G11B10F opaque color buffer or an
|
||||
* RGBA16F transparent color buffer. With R11G11B10F colors in the LDR range have a precision of
|
||||
* either 6 bits (red and green channels) or 5 bits (blue channel).
|
||||
* </p>
|
||||
*/
|
||||
public enum QualityLevel {
|
||||
LOW,
|
||||
MEDIUM,
|
||||
@@ -51,25 +169,73 @@ public class View {
|
||||
ULTRA
|
||||
}
|
||||
|
||||
/**
|
||||
* Structure used to set the color precision for the rendering of a <code>View</code>.
|
||||
*
|
||||
* <p>
|
||||
* This structure offers separate quality settings for different parts of the rendering
|
||||
* pipeline.
|
||||
* </p>
|
||||
*
|
||||
* @see #setRenderQuality
|
||||
* @see #getRenderQuality
|
||||
*/
|
||||
public static class RenderQuality {
|
||||
public QualityLevel hdrColorBuffer = QualityLevel.HIGH;
|
||||
}
|
||||
|
||||
public enum AntiAliasing {
|
||||
/**
|
||||
* List of available ambient occlusion techniques.
|
||||
*
|
||||
* @see #setAmbientOcclusion
|
||||
*/
|
||||
public enum AmbientOcclusion {
|
||||
NONE,
|
||||
SSAO
|
||||
}
|
||||
|
||||
/**
|
||||
* List of available post-processing anti-aliasing techniques.
|
||||
*
|
||||
* @see #setAntiAliasing
|
||||
* @see #getAntiAliasing
|
||||
*/
|
||||
public enum AntiAliasing {
|
||||
/**
|
||||
* No anti aliasing performed as part of post-processing.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* FXAA is a low-quality but very efficient type of anti-aliasing. (default).
|
||||
*/
|
||||
FXAA
|
||||
}
|
||||
|
||||
/**
|
||||
* List of available tone-mapping operators
|
||||
*/
|
||||
public enum ToneMapping {
|
||||
/**
|
||||
* Equivalent to disabling tone-mapping.
|
||||
*/
|
||||
LINEAR,
|
||||
|
||||
/**
|
||||
* The Academy Color Encoding System (ACES).
|
||||
*/
|
||||
ACES
|
||||
}
|
||||
|
||||
/**
|
||||
* List of available post-processing dithering techniques.
|
||||
*/
|
||||
public enum Dithering {
|
||||
NONE,
|
||||
TEMPORAL
|
||||
}
|
||||
|
||||
/** @see #setDepthPrepass */
|
||||
public enum DepthPrepass {
|
||||
DEFAULT(-1),
|
||||
DISABLED(0),
|
||||
@@ -86,108 +252,314 @@ public class View {
|
||||
mNativeObject = nativeView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the View's name. Only useful for debugging.
|
||||
*/
|
||||
public void setName(@NonNull String name) {
|
||||
mName = name;
|
||||
nSetName(getNativeObject(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the View's name.
|
||||
*/
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this View instance's Scene.
|
||||
*
|
||||
* <p>
|
||||
* This method associates the specified Scene with this View. Note that a particular scene can
|
||||
* be associated with several View instances. To remove an existing association, simply pass
|
||||
* null.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The View does not take ownership of the Scene pointer. Before destroying a Scene, be sure
|
||||
* to remove it from all assoicated Views.
|
||||
* </p>
|
||||
*
|
||||
* @see #getScene
|
||||
*/
|
||||
public void setScene(@Nullable Scene scene) {
|
||||
mScene = scene;
|
||||
nSetScene(getNativeObject(), scene == null ? 0 : scene.getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this View's associated Scene, or null if none has been assigned.
|
||||
*
|
||||
* @see #setScene
|
||||
*/
|
||||
@Nullable
|
||||
public Scene getScene() {
|
||||
return mScene;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this View's Camera.
|
||||
*
|
||||
* <p>
|
||||
* This method associates the specified Camera with this View. A Camera can be associated with
|
||||
* several View instances. To remove an existing association, simply pass
|
||||
* null.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The View does not take ownership of the Scene pointer. Before destroying a Camera, be sure
|
||||
* to remove it from all assoicated Views.
|
||||
* </p>
|
||||
*
|
||||
* @see #getCamera
|
||||
*/
|
||||
public void setCamera(@Nullable Camera camera) {
|
||||
mCamera = camera;
|
||||
nSetCamera(getNativeObject(), camera == null ? 0 : camera.getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this View's associated Camera, or null if none has been assigned.
|
||||
*
|
||||
* @see #setCamera
|
||||
*/
|
||||
@Nullable
|
||||
public Camera getCamera() {
|
||||
return mCamera;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the rectangular rendering area.
|
||||
*
|
||||
* <p>
|
||||
* The viewport specifies where the content of the View (i.e. the Scene) is rendered in
|
||||
* the render target. The render target is automatically clipped to the Viewport.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If you wish subsequent changes to take effect please call this method again in order to
|
||||
* propagate the changes down to the native layer.
|
||||
* </p>
|
||||
*
|
||||
* @param viewport The Viewport to render the Scene into.
|
||||
*/
|
||||
public void setViewport(@NonNull Viewport viewport) {
|
||||
mViewport = viewport;
|
||||
nSetViewport(getNativeObject(),
|
||||
mViewport.left, mViewport.bottom, mViewport.width, mViewport.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rectangular rendering area.
|
||||
*
|
||||
* @see #setViewport
|
||||
*/
|
||||
@NonNull
|
||||
public Viewport getViewport() {
|
||||
return mViewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color used to clear the Viewport when rendering this View.
|
||||
*
|
||||
* <p>This is ignored if a {@link Skybox} is present or if clearing has been disabled
|
||||
* via {@link #setClearTargets}. Defaults to black.</p>
|
||||
*
|
||||
* @see #getClearColor
|
||||
*/
|
||||
public void setClearColor(
|
||||
@LinearColor float r, @LinearColor float g, @LinearColor float b, float a) {
|
||||
nSetClearColor(getNativeObject(), r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the View clear color in a provided 4-tuple.
|
||||
*
|
||||
* @return A reference to the passed-in array.
|
||||
*
|
||||
* @see #setClearColor
|
||||
*/
|
||||
@NonNull @Size(min = 4)
|
||||
public float[] getClearColor(@NonNull @Size(min = 4) float[] out) {
|
||||
out = assertFloat4(out);
|
||||
out = Asserts.assertFloat4(out);
|
||||
nGetClearColor(getNativeObject(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets which targets to clear (default: true, true, false)
|
||||
*
|
||||
* @see #setClearColor
|
||||
*/
|
||||
public void setClearTargets(boolean color, boolean depth, boolean stencil) {
|
||||
nSetClearTargets(getNativeObject(), color, depth, stencil);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets which layers are visible.
|
||||
*
|
||||
* <p>
|
||||
* Renderable objects can have one or several layers associated to them. Layers are
|
||||
* represented with an 8-bits bitmask, where each bit corresponds to a layer.
|
||||
* By default all layers are visible.
|
||||
* </p>
|
||||
*
|
||||
* @see RenderableManager#setLayerMask
|
||||
*
|
||||
* @param select a bitmask specifying which layer to set or clear using <code>values</code>.
|
||||
* @param values a bitmask where each bit sets the visibility of the corresponding layer
|
||||
* (1: visible, 0: invisible), only layers in <code>select</code> are affected.
|
||||
*/
|
||||
public void setVisibleLayers(
|
||||
@IntRange(from = 0, to = 255) int select,
|
||||
@IntRange(from = 0, to = 255) int values) {
|
||||
nSetVisibleLayers(getNativeObject(), select & 0xFF, values & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables shadow mapping. Enabled by default.
|
||||
*
|
||||
* @see LightManager.Builder#castShadows
|
||||
* @see RenderableManager.Builder#receiveShadows
|
||||
* @see RenderableManager.Builder#castShadows
|
||||
*/
|
||||
public void setShadowsEnabled(boolean enabled) {
|
||||
nSetShadowsEnabled(getNativeObject(), enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies an offscreen render target to render into.
|
||||
*
|
||||
* <p>
|
||||
* By default, the view's associated render target is null, which corresponds to the
|
||||
* SwapChain associated with the engine.
|
||||
* </p>
|
||||
*
|
||||
* @param target render target associated with view, or null for the swap chain
|
||||
*/
|
||||
public void setRenderTarget(@Nullable RenderTarget target) {
|
||||
mRenderTarget = target;
|
||||
nSetRenderTarget(getNativeObject(), target != null ? target.getNativeObject() : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the offscreen render target associated with this view.
|
||||
*
|
||||
* Returns null if the render target is the swap chain (which is default).
|
||||
*
|
||||
* @see #setRenderTarget
|
||||
*/
|
||||
@Nullable
|
||||
public RenderTarget getRenderTarget() {
|
||||
return mRenderTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets how many samples are to be used for MSAA in the post-process stage.
|
||||
* Default is 1 and disables MSAA.
|
||||
*
|
||||
* <p>
|
||||
* Note that anti-aliasing can also be performed in the post-processing stage, generally at
|
||||
* lower cost. See the FXAA option in {@link #setAntiAliasing}.
|
||||
* </p>
|
||||
*
|
||||
* @param count number of samples to use for multi-sampled anti-aliasing.
|
||||
*/
|
||||
public void setSampleCount(int count) {
|
||||
nSetSampleCount(getNativeObject(), count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective MSAA sample count.
|
||||
*
|
||||
* <p>
|
||||
* A value of 0 or 1 means MSAA is disabled.
|
||||
* </p>
|
||||
*
|
||||
* @return value set by {@link #setSampleCount}
|
||||
*/
|
||||
public int getSampleCount() {
|
||||
return nGetSampleCount(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables anti-aliasing in the post-processing stage. Enabled by default.
|
||||
*
|
||||
* <p>
|
||||
* For MSAA anti-aliasing, see {@link #setSampleCount}.
|
||||
* </p>
|
||||
*
|
||||
* @param type FXAA for enabling, NONE for disabling anti-aliasing.
|
||||
*/
|
||||
public void setAntiAliasing(@NonNull AntiAliasing type) {
|
||||
nSetAntiAliasing(getNativeObject(), type.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries whether anti-aliasing is enabled during the post-processing stage. To query
|
||||
* whether MSAA is enabled, see {@link #getSampleCount}.
|
||||
*
|
||||
* @return The post-processing anti-aliasing method.
|
||||
*/
|
||||
@NonNull
|
||||
public AntiAliasing getAntiAliasing() {
|
||||
return AntiAliasing.values()[nGetAntiAliasing(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables tone-mapping in the post-processing stage. Enabled by default.
|
||||
*
|
||||
* @param type Tone-mapping function.
|
||||
*/
|
||||
public void setToneMapping(@NonNull ToneMapping type) {
|
||||
nSetToneMapping(getNativeObject(), type.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tone-mapping function.
|
||||
* @return tone-mapping function.
|
||||
*/
|
||||
@NonNull
|
||||
public ToneMapping getToneMapping() {
|
||||
return ToneMapping.values()[nGetToneMapping(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables dithering in the post-processing stage. Enabled by default.
|
||||
*
|
||||
* @param dithering dithering type
|
||||
*/
|
||||
public void setDithering(@NonNull Dithering dithering) {
|
||||
nSetDithering(getNativeObject(), dithering.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries whether dithering is enabled during the post-processing stage.
|
||||
*
|
||||
* @return the current dithering type for this view.
|
||||
*/
|
||||
@NonNull
|
||||
public Dithering getDithering() {
|
||||
return Dithering.values()[nGetDithering(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dynamic resolution options for this view.
|
||||
*
|
||||
* <p>
|
||||
* Dynamic resolution options controls whether dynamic resolution is enabled, and if it is,
|
||||
* how it behaves.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If you wish subsequent changes to take effect please call this method again in order to
|
||||
* propagate the changes down to the native layer.
|
||||
* </p>
|
||||
*
|
||||
* @param options The dynamic resolution options to use on this view
|
||||
*/
|
||||
public void setDynamicResolutionOptions(@NonNull DynamicResolutionOptions options) {
|
||||
mDynamicResolution = options;
|
||||
nSetDynamicResolutionOptions(getNativeObject(),
|
||||
@@ -201,6 +573,10 @@ public class View {
|
||||
options.history);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dynamic resolution options associated with this view.
|
||||
* @return value set by {@link #setDynamicResolutionOptions}.
|
||||
*/
|
||||
@NonNull
|
||||
public DynamicResolutionOptions getDynamicResolutionOptions() {
|
||||
if (mDynamicResolution == null) {
|
||||
@@ -209,11 +585,20 @@ public class View {
|
||||
return mDynamicResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rendering quality for this view (e.g. color precision).
|
||||
*
|
||||
* @param renderQuality The render quality to use on this view
|
||||
*/
|
||||
public void setRenderQuality(@NonNull RenderQuality renderQuality) {
|
||||
mRenderQuality = renderQuality;
|
||||
nSetRenderQuality(getNativeObject(), renderQuality.hdrColorBuffer.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the render quality used by this view.
|
||||
* @return value set by {@link #setRenderQuality}.
|
||||
*/
|
||||
@NonNull
|
||||
public RenderQuality getRenderQuality() {
|
||||
if (mRenderQuality == null) {
|
||||
@@ -222,37 +607,177 @@ public class View {
|
||||
return mRenderQuality;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this view is rendered with a depth-only prepass.
|
||||
*
|
||||
* @return the value set by {@link #setDepthPrepass}.
|
||||
*/
|
||||
@NonNull
|
||||
public DepthPrepass getDepthPrepass() {
|
||||
return mDepthPrepass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this view is rendered with or without a depth pre-pass.
|
||||
*
|
||||
* <p>
|
||||
* By default, the system picks the most appropriate strategy for your platform; this method
|
||||
* lets you override that strategy.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When the depth pre-pass is enabled, the renderer will first draw all objects in the
|
||||
* depth buffer from front to back, and then draw the objects again but sorted to minimize
|
||||
* state changes. With the depth pre-pass disabled, objects are drawn only once, but it may
|
||||
* result in more state changes or more overdraw.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The best strategy may depend on the scene and/or GPU.
|
||||
* </p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>DepthPrepass::DEFAULT uses the most appropriate strategy</li>
|
||||
* <li>DepthPrepass::DISABLED disables the depth pre-pass</li>
|
||||
* <li>DepthPrepass::ENABLE enables the depth pre-pass</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void setDepthPrepass(@NonNull DepthPrepass depthPrepass) {
|
||||
mDepthPrepass = depthPrepass;
|
||||
nSetDepthPrepass(getNativeObject(), depthPrepass.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if post-processing is enabled.
|
||||
*
|
||||
* @see #setPostProcessingEnabled
|
||||
*/
|
||||
public boolean isPostProcessingEnabled() {
|
||||
return nIsPostProcessingEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables post processing. Enabled by default.
|
||||
*
|
||||
* <p>Post-processing includes:</p>
|
||||
* <ul>
|
||||
* <li>Tone-mapping & gamma encoding</li>
|
||||
* <li>Dithering</li>
|
||||
* <li>MSAA</li>
|
||||
* <li>FXAA</li>
|
||||
* <li>Dynamic scaling</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* Disabling post-processing forgoes color correctness as well as anti-aliasing and
|
||||
* should only be used experimentally (e.g., for UI overlays).
|
||||
* </p>
|
||||
*
|
||||
* @param enabled true enables post processing, false disables it
|
||||
*
|
||||
* @see #setToneMapping
|
||||
* @see #setAntiAliasing
|
||||
* @see #setDithering
|
||||
* @see #setSampleCount
|
||||
*/
|
||||
public void setPostProcessingEnabled(boolean enabled) {
|
||||
nSetPostProcessingEnabled(getNativeObject(), enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if post-processing is enabled.
|
||||
*
|
||||
* @see #setPostProcessingEnabled
|
||||
*/
|
||||
public boolean isFrontFaceWindingInverted() {
|
||||
return nIsFrontFaceWindingInverted(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts the winding order of front faces. By default front faces use a counter-clockwise
|
||||
* winding order. When the winding order is inverted, front faces are faces with a clockwise
|
||||
* winding order.
|
||||
*
|
||||
* Changing the winding order will directly affect the culling mode in materials
|
||||
* (see Material#getCullingMode).
|
||||
*
|
||||
* Inverting the winding order of front faces is useful when rendering mirrored reflections
|
||||
* (water, mirror surfaces, front camera in AR, etc.).
|
||||
*
|
||||
* @param inverted True to invert front faces, false otherwise.
|
||||
*/
|
||||
public void setFrontFaceWindingInverted(boolean inverted) {
|
||||
nSetFrontFaceWindingInverted(getNativeObject(), inverted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets options relative to dynamic lighting for this view.
|
||||
*
|
||||
* <p>
|
||||
* Together <code>zLightNear</code> and <code>zLightFar</code> must be chosen so that the
|
||||
* visible influence of lights is spread between these two values.
|
||||
* </p>
|
||||
*
|
||||
* @param zLightNear Distance from the camera where the lights are expected to shine.
|
||||
* This parameter can affect performance and is useful because depending
|
||||
* on the scene, lights that shine close to the camera may not be
|
||||
* visible -- in this case, using a larger value can improve performance.
|
||||
* e.g. when standing and looking straight, several meters of the ground
|
||||
* isn't visible and if lights are expected to shine there, there is no
|
||||
* point using a short zLightNear. (Default 5m).
|
||||
*
|
||||
* @param zLightFar Distance from the camera after which lights are not expected to be visible.
|
||||
* Similarly to zLightNear, setting this value properly can improve
|
||||
* performance. (Default 100m).
|
||||
*
|
||||
*/
|
||||
public void setDynamicLightingOptions(float zLightNear, float zLightFar) {
|
||||
nSetDynamicLightingOptions(getNativeObject(), zLightNear, zLightFar);
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
/**
|
||||
* Activates or deactivates ambient occlusion.
|
||||
*
|
||||
* @param ao Type of ambient occlusion to use.
|
||||
*/
|
||||
public void setAmbientOcclusion(@NonNull AmbientOcclusion ao) {
|
||||
nSetAmbientOcclusion(getNativeObject(), ao.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the type of ambient occlusion active for this View.
|
||||
*
|
||||
* @return ambient occlusion type.
|
||||
*/
|
||||
@NonNull
|
||||
public AmbientOcclusion getAmbientOcclusion() {
|
||||
return AmbientOcclusion.values()[nGetAmbientOcclusion(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ambient occlusion options.
|
||||
*
|
||||
* @param options Options for ambient occlusion.
|
||||
*/
|
||||
public void setAmbientOcclusionOptions(@NonNull AmbientOcclusionOptions options) {
|
||||
mAmbientOcclusionOptions = options;
|
||||
nSetAmbientOcclusionOptions(getNativeObject(), options.radius, options.bias, options.power, options.resolution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ambient occlusion options.
|
||||
*
|
||||
* @return ambient occlusion options currently set.
|
||||
*/
|
||||
@NonNull
|
||||
public AmbientOcclusionOptions getAmbientOcclusionOptions() {
|
||||
if (mAmbientOcclusionOptions == null) {
|
||||
mAmbientOcclusionOptions = new AmbientOcclusionOptions();
|
||||
}
|
||||
return mAmbientOcclusionOptions;
|
||||
}
|
||||
|
||||
public long getNativeObject() {
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Calling method on destroyed View");
|
||||
}
|
||||
@@ -263,15 +788,6 @@ public class View {
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
@NonNull @Size(min = 4)
|
||||
private static float[] assertFloat4(@Nullable float[] out) {
|
||||
if (out == null) out = new float[4];
|
||||
else if (out.length < 4) {
|
||||
throw new ArrayIndexOutOfBoundsException("Array length must be at least 4");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static native void nSetName(long nativeView, String name);
|
||||
private static native void nSetScene(long nativeView, long nativeScene);
|
||||
private static native void nSetCamera(long nativeView, long nativeCamera);
|
||||
@@ -281,6 +797,7 @@ public class View {
|
||||
private static native void nSetClearTargets(long nativeView, boolean color, boolean depth, boolean stencil);
|
||||
private static native void nSetVisibleLayers(long nativeView, int select, int value);
|
||||
private static native void nSetShadowsEnabled(long nativeView, boolean enabled);
|
||||
private static native void nSetRenderTarget(long nativeView, long nativeRenderTarget);
|
||||
private static native void nSetSampleCount(long nativeView, int count);
|
||||
private static native int nGetSampleCount(long nativeView);
|
||||
private static native void nSetAntiAliasing(long nativeView, int type);
|
||||
@@ -300,4 +817,7 @@ public class View {
|
||||
private static native boolean nIsPostProcessingEnabled(long nativeView);
|
||||
private static native void nSetFrontFaceWindingInverted(long nativeView, boolean inverted);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,16 @@ package com.google.android.filament;
|
||||
|
||||
import android.support.annotation.IntRange;
|
||||
|
||||
/**
|
||||
* Specifies a rectangular region within a render target in terms of pixel coordinates.
|
||||
*
|
||||
* <p>
|
||||
* The rectangle spans from <code>(left,bottom)</code> to <code>(left+width-1, top+height-1)</code>,
|
||||
* inclusive. Width and height must be non-negative.
|
||||
* </p>
|
||||
*
|
||||
* @see View#setViewport
|
||||
*/
|
||||
public class Viewport {
|
||||
public Viewport(int left, int bottom, @IntRange(from = 0) int width, @IntRange(from = 0) int height) {
|
||||
this.left = left;
|
||||
|
||||
@@ -34,21 +34,6 @@ public final class TextureHelper {
|
||||
private static final int BITMAP_CONFIG_RGBA_F16 = 4;
|
||||
private static final int BITMAP_CONFIG_HARDWARE = 5;
|
||||
|
||||
private static Method sEngineGetNativeObject;
|
||||
private static Method sTextureGetNativeObject;
|
||||
|
||||
static {
|
||||
try {
|
||||
sEngineGetNativeObject = Engine.class.getDeclaredMethod("getNativeObject");
|
||||
sTextureGetNativeObject = Texture.class.getDeclaredMethod("getNativeObject");
|
||||
|
||||
sEngineGetNativeObject.setAccessible(true);
|
||||
sTextureGetNativeObject.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Cannot happen
|
||||
}
|
||||
}
|
||||
|
||||
private TextureHelper() {
|
||||
}
|
||||
|
||||
@@ -69,14 +54,10 @@ public final class TextureHelper {
|
||||
throw new IllegalArgumentException("Unsupported config: ARGB_4444 or HARDWARE");
|
||||
}
|
||||
|
||||
try {
|
||||
long nativeTexture = (Long) sTextureGetNativeObject.invoke(texture);
|
||||
long nativeEngine = (Long) sEngineGetNativeObject.invoke(engine);
|
||||
nSetBitmap(nativeTexture, nativeEngine, level, xoffset, yoffset, width, height,
|
||||
bitmap, format);
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
long nativeTexture = texture.getNativeObject();
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
nSetBitmap(nativeTexture, nativeEngine, level, xoffset, yoffset, width, height,
|
||||
bitmap, format);
|
||||
}
|
||||
|
||||
private static int toNativeFormat(Bitmap.Config config) {
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.google.android.filament.android;
|
||||
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.SurfaceTexture;
|
||||
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -27,6 +26,7 @@ import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.TextureView;
|
||||
|
||||
import com.google.android.filament.SwapChain;
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ import com.google.android.filament.SwapChain;
|
||||
* mUiHelper = new UiHelper(UiHelper.ContextErrorPolicy.DONT_CHECK);
|
||||
*
|
||||
* // Attach the SurfaceView to the helper, you could do the same with a TextureView
|
||||
* mUiHelper.attachTo(surfaceView)
|
||||
* mUiHelper.attachTo(mSurfaceView);
|
||||
*
|
||||
* // Set a rendering callback that we will use to invoke Filament
|
||||
* mUiHelper.setRenderCallback(new UiHelper.RendererCallback() {
|
||||
@@ -95,15 +95,11 @@ import com.google.android.filament.SwapChain;
|
||||
* }
|
||||
*
|
||||
* public void onDestroy() {
|
||||
* super.onDestroy()
|
||||
* super.onDestroy();
|
||||
* // Always detach the surface before destroying the engine
|
||||
* mUiHelper.detach()
|
||||
* mUiHelper.detach();
|
||||
*
|
||||
* // This ensures that all the commands we've sent to Filament have
|
||||
* // been processed before we attempt to destroy anything
|
||||
* Fence.waitAndDestroy(mEngine.createFence(Fence.Type.SOFT), Fence.Mode.FLUSH);
|
||||
*
|
||||
* mEngine.destroy()
|
||||
* mEngine.destroy();
|
||||
* }
|
||||
*
|
||||
* // This is an example of a render function. You will most likely invoke this from
|
||||
@@ -113,8 +109,8 @@ import com.google.android.filament.SwapChain;
|
||||
* // If beginFrame() returns false you should skip the frame
|
||||
* // This means you are sending frames too quickly to the GPU
|
||||
* if (mRenderer.beginFrame(swapChain)) {
|
||||
* mRenderer.render(mView)
|
||||
* mRenderer.endFrame()
|
||||
* mRenderer.render(mView);
|
||||
* mRenderer.endFrame();
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.proguard;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation used for marking methods and fields that are called from native
|
||||
* code. Useful for keeping components that would otherwise be removed by
|
||||
* Proguard. Use the value parameter to mention a file that calls this method.
|
||||
*
|
||||
* Note that adding this annotation to a method is not enough to guarantee that
|
||||
* it is kept - either its class must be referenced elsewhere in the program, or
|
||||
* the class must be annotated with this as well. Usage example:
|
||||
* <pre>
|
||||
*
|
||||
* @UsedByNative("NativeCrashHandler.cpp")
|
||||
* public static void reportCrash(int signal, int code, int address) {
|
||||
* ...
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@Target({
|
||||
ElementType.METHOD,
|
||||
ElementType.FIELD,
|
||||
ElementType.TYPE,
|
||||
ElementType.CONSTRUCTOR})
|
||||
public @interface UsedByNative {
|
||||
String value();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.proguard;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation used for marking methods and fields that are called by reflection. Useful for keeping
|
||||
* components that would otherwise be removed by Proguard. Use the value parameter to mention a file
|
||||
* that calls this method.
|
||||
*
|
||||
* Note that adding this annotation to a method is not enough to guarantee that
|
||||
* it is kept - either its class must be referenced elsewhere in the program, or
|
||||
* the class must be annotated with this as well. Usage example:
|
||||
* <pre>
|
||||
*
|
||||
* @UsedByReflection("PeopleListItemView.java")
|
||||
* public PeopleListItemViewV11(Context context) {
|
||||
* super(context);
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@Target({
|
||||
ElementType.METHOD,
|
||||
ElementType.FIELD,
|
||||
ElementType.TYPE,
|
||||
ElementType.CONSTRUCTOR})
|
||||
public @interface UsedByReflection {
|
||||
String value();
|
||||
}
|
||||
12
android/gltfio-android/.gitignore
vendored
Normal file
12
android/gltfio-android/.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
/.idea/caches
|
||||
/.idea/gradle.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
/.cxx
|
||||
101
android/gltfio-android/CMakeLists.txt
Normal file
101
android/gltfio-android/CMakeLists.txt
Normal file
@@ -0,0 +1,101 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
set(FILAMENT_DIR ${FILAMENT_DIST_DIR})
|
||||
|
||||
set(DISABLE_FILAMENT_JNI TRUE)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../filament-android ${CMAKE_CURRENT_BINARY_DIR}/filament-android)
|
||||
|
||||
add_library(filament STATIC IMPORTED)
|
||||
set_target_properties(filament PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilament.a)
|
||||
|
||||
add_library(backend STATIC IMPORTED)
|
||||
set_target_properties(backend PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libbackend.a)
|
||||
|
||||
add_library(utils STATIC IMPORTED)
|
||||
set_target_properties(utils PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libutils.a)
|
||||
|
||||
add_library(filaflat STATIC IMPORTED)
|
||||
set_target_properties(filaflat PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilaflat.a)
|
||||
|
||||
add_library(image STATIC IMPORTED)
|
||||
set_target_properties(image PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libimage.a)
|
||||
|
||||
add_library(ibl STATIC IMPORTED)
|
||||
set_target_properties(ibl PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libibl.a)
|
||||
|
||||
add_library(geometry STATIC IMPORTED)
|
||||
set_target_properties(geometry PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libgeometry.a)
|
||||
|
||||
add_library(filabridge STATIC IMPORTED)
|
||||
set_target_properties(filabridge PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilabridge.a)
|
||||
|
||||
add_library(gltfio STATIC IMPORTED)
|
||||
set_target_properties(gltfio PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libgltfio_core.a)
|
||||
|
||||
add_library(gltfio_resources STATIC IMPORTED)
|
||||
set_target_properties(gltfio_resources PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libgltfio_resources.a)
|
||||
|
||||
add_library(bluevk STATIC IMPORTED)
|
||||
set_target_properties(bluevk PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libbluevk.a)
|
||||
|
||||
add_library(smol-v STATIC IMPORTED)
|
||||
set_target_properties(smol-v PROPERTIES IMPORTED_LOCATION
|
||||
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libsmol-v.a)
|
||||
|
||||
include_directories(${FILAMENT_DIR}/include
|
||||
..
|
||||
../../libs/utils/include)
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${CMAKE_SOURCE_DIR}/libgltfio-jni.map")
|
||||
|
||||
add_library(gltfio-jni SHARED
|
||||
src/main/cpp/Animator.cpp
|
||||
src/main/cpp/AssetLoader.cpp
|
||||
src/main/cpp/FilamentAsset.cpp
|
||||
src/main/cpp/KtxLoader.cpp
|
||||
src/main/cpp/MaterialProvider.cpp
|
||||
src/main/cpp/ResourceLoader.cpp
|
||||
|
||||
../common/CallbackUtils.cpp
|
||||
../common/NioUtils.cpp
|
||||
|
||||
$<TARGET_OBJECTS:filament-jni-obj>
|
||||
)
|
||||
|
||||
set_target_properties(gltfio-jni PROPERTIES LINK_DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libgltfio-jni.symbols)
|
||||
|
||||
# The ordering in the following list is important because CMake does not have dependency information.
|
||||
target_link_libraries(gltfio-jni
|
||||
gltfio
|
||||
filament
|
||||
backend
|
||||
filaflat
|
||||
filabridge
|
||||
geometry
|
||||
image
|
||||
ibl
|
||||
utils
|
||||
log
|
||||
GLESv3
|
||||
EGL
|
||||
android
|
||||
jnigraphics
|
||||
gltfio_resources
|
||||
m
|
||||
)
|
||||
|
||||
if (FILAMENT_SUPPORTS_VULKAN)
|
||||
target_link_libraries(gltfio-jni bluevk smol-v)
|
||||
endif()
|
||||
90
android/gltfio-android/build.gradle
Normal file
90
android/gltfio-android/build.gradle
Normal file
@@ -0,0 +1,90 @@
|
||||
// This script accepts the following parameters:
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Example:
|
||||
// ./gradlew -Pfilament_dist_dir=../../dist-android-release assembleRelease
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
group = "com.google.android.filament"
|
||||
version = "1.3"
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
def filament_path = file("../../out/android-release/filament").absolutePath
|
||||
if (project.hasProperty("filament_dist_dir")) {
|
||||
filament_path = file("$filament_dist_dir").absolutePath
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments.add("-DANDROID_PIE=ON")
|
||||
arguments.add("-DANDROID_PLATFORM=android-19")
|
||||
arguments.add("-DANDROID_STL=c++_static")
|
||||
arguments.add("-DFILAMENT_DIST_DIR=${filament_path}".toString())
|
||||
cppFlags.add("-std=c++14")
|
||||
if (project.hasProperty('extra_cmake_args')) {
|
||||
arguments.add(extra_cmake_args)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
jni.srcDirs "src/main/cpp"
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.android.support:support-annotations:28.0.0'
|
||||
implementation 'com.google.android.filament:filament-android'
|
||||
}
|
||||
BIN
android/gltfio-android/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
android/gltfio-android/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
android/gltfio-android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
android/gltfio-android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
172
android/gltfio-android/gradlew
vendored
Executable file
172
android/gltfio-android/gradlew
vendored
Executable file
@@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
84
android/gltfio-android/gradlew.bat
vendored
Normal file
84
android/gltfio-android/gradlew.bat
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
4
android/gltfio-android/libgltfio-jni.map
Normal file
4
android/gltfio-android/libgltfio-jni.map
Normal file
@@ -0,0 +1,4 @@
|
||||
LIBGLTFIO {
|
||||
global: Java_com_google_android_filament_*; JNI*;
|
||||
local: *;
|
||||
};
|
||||
1
android/gltfio-android/libgltfio-jni.symbols
Normal file
1
android/gltfio-android/libgltfio-jni.symbols
Normal file
@@ -0,0 +1 @@
|
||||
_Java_com_google_android_filament_*
|
||||
12
android/gltfio-android/settings.gradle
Normal file
12
android/gltfio-android/settings.gradle
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user guide at https://docs.gradle.org/4.6/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
includeBuild '../filament-android'
|
||||
|
||||
rootProject.name = 'gltfio-android'
|
||||
18
android/gltfio-android/src/main/AndroidManifest.xml
Normal file
18
android/gltfio-android/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.google.android.filament.gltfio" />
|
||||
59
android/gltfio-android/src/main/cpp/Animator.cpp
Normal file
59
android/gltfio-android/src/main/cpp/Animator.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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/Animator.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
using namespace gltfio;
|
||||
using namespace utils;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_Animator_nApplyAnimation(JNIEnv*, jclass, jlong nativeAnimator,
|
||||
jint index, jfloat time) {
|
||||
Animator* animator = (Animator*) nativeAnimator;
|
||||
animator->applyAnimation(index, time);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_Animator_nUpdateBoneMatrices(JNIEnv*, jclass, jlong nativeAnimator) {
|
||||
Animator* animator = (Animator*) nativeAnimator;
|
||||
animator->updateBoneMatrices();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_gltfio_Animator_nGetAnimationCount(JNIEnv*, jclass, jlong nativeAnimator) {
|
||||
Animator* animator = (Animator*) nativeAnimator;
|
||||
return animator->getAnimationCount();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT float JNICALL
|
||||
Java_com_google_android_filament_gltfio_Animator_nGetAnimationDuration(JNIEnv*, jclass,
|
||||
jlong nativeAnimator, jint index) {
|
||||
Animator* animator = (Animator*) nativeAnimator;
|
||||
return animator->getAnimationDuration(index);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_google_android_filament_gltfio_Animator_nGetAnimationName(JNIEnv* env, jclass,
|
||||
jlong nativeAnimator, jint index) {
|
||||
Animator* animator = (Animator*) nativeAnimator;
|
||||
const char* val = animator->getAnimationName(index);
|
||||
return val ? env->NewStringUTF(val) : nullptr;
|
||||
|
||||
}
|
||||
85
android/gltfio-android/src/main/cpp/AssetLoader.cpp
Normal file
85
android/gltfio-android/src/main/cpp/AssetLoader.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 <filament/Engine.h>
|
||||
|
||||
#include <utils/EntityManager.h>
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/MaterialProvider.h>
|
||||
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace gltfio;
|
||||
using namespace utils;
|
||||
|
||||
extern void registerCallbackUtils(JNIEnv*);
|
||||
extern void registerNioUtils(JNIEnv*);
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
JNIEnv* env;
|
||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
registerCallbackUtils(env);
|
||||
registerNioUtils(env);
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nCreateAssetLoader(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeProvider, jlong nativeEntities) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
MaterialProvider* materials = (MaterialProvider*) nativeProvider;
|
||||
EntityManager* entities = (EntityManager*) nativeEntities;
|
||||
return (jlong) AssetLoader::create({engine, materials, nullptr, entities});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nDestroyAssetLoader(JNIEnv*, jclass,
|
||||
jlong nativeLoader) {
|
||||
AssetLoader* loader = (AssetLoader*) nativeLoader;
|
||||
AssetLoader::destroy(&loader);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nCreateAssetFromBinary(JNIEnv* env, jclass,
|
||||
jlong nativeLoader, jobject javaBuffer, jint remaining) {
|
||||
AssetLoader* loader = (AssetLoader*) nativeLoader;
|
||||
AutoBuffer buffer(env, javaBuffer, remaining);
|
||||
return (jlong) loader->createAssetFromBinary((const uint8_t *) buffer.getData(),
|
||||
buffer.getSize());
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nEnableDiagnostics(JNIEnv*, jclass,
|
||||
jlong nativeLoader, jboolean enable) {
|
||||
AssetLoader* loader = (AssetLoader*) nativeLoader;
|
||||
loader->enableDiagnostics(enable);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_AssetLoader_nDestroyAsset(JNIEnv*, jclass,
|
||||
jlong nativeLoader, jlong nativeAsset) {
|
||||
AssetLoader* loader = (AssetLoader*) nativeLoader;
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
loader->destroyAsset(asset);
|
||||
}
|
||||
80
android/gltfio-android/src/main/cpp/FilamentAsset.cpp
Normal file
80
android/gltfio-android/src/main/cpp/FilamentAsset.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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/FilamentAsset.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
using namespace gltfio;
|
||||
using namespace utils;
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetRoot(JNIEnv*, jclass, jlong nativeAsset) {
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
return asset->getRoot().getId();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetEntityCount(JNIEnv*, jclass,
|
||||
jlong nativeAsset) {
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
return asset->getEntityCount();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetEntities(JNIEnv* env, jclass,
|
||||
jlong nativeAsset, jintArray result) {
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
Entity* entities = (Entity*) env->GetIntArrayElements(result, nullptr);
|
||||
std::copy_n(asset->getEntities(), asset->getEntityCount(), entities);
|
||||
env->ReleaseIntArrayElements(result, (jint*) entities, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetBoundingBox(JNIEnv* env, jclass,
|
||||
jlong nativeAsset, jfloatArray result) {
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
float* values = (float*) env->GetFloatArrayElements(result, nullptr);
|
||||
const filament::Aabb box = asset->getBoundingBox();
|
||||
const float3 center = box.center();
|
||||
const float3 extent = box.extent();
|
||||
values[0] = center.x;
|
||||
values[1] = center.y;
|
||||
values[2] = center.z;
|
||||
values[3] = extent.x;
|
||||
values[4] = extent.y;
|
||||
values[5] = extent.z;
|
||||
env->ReleaseFloatArrayElements(result, (jfloat*) values, 0);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetName(JNIEnv* env, jclass,
|
||||
jlong nativeAsset, jint entityId) {
|
||||
uint32_t id = entityId;
|
||||
Entity* entity = (Entity*) &id;
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
const char* val = asset->getName(*entity);
|
||||
return val ? env->NewStringUTF(val) : nullptr;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_FilamentAsset_nGetAnimator(JNIEnv* env, jclass,
|
||||
jlong nativeAsset) {
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
return (jlong) asset->getAnimator();
|
||||
}
|
||||
77
android/gltfio-android/src/main/cpp/KtxLoader.cpp
Normal file
77
android/gltfio-android/src/main/cpp/KtxLoader.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 <filament/Engine.h>
|
||||
#include <filament/IndirectLight.h>
|
||||
#include <filament/Skybox.h>
|
||||
|
||||
#include <image/KtxUtility.h>
|
||||
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
using namespace image;
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_KtxLoader_nCreateTexture(JNIEnv* env, jclass,
|
||||
jlong nativeEngine, jobject javaBuffer, jint remaining, jboolean srgb) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
AutoBuffer buffer(env, javaBuffer, remaining);
|
||||
KtxBundle* bundle = new KtxBundle((const uint8_t*) buffer.getData(), buffer.getSize());
|
||||
return (jlong) ktx::createTexture(engine, *bundle, srgb, [](void* userdata) {
|
||||
KtxBundle* bundle = (KtxBundle*) userdata;
|
||||
delete bundle;
|
||||
}, bundle);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_KtxLoader_nCreateIndirectLight(JNIEnv* env, jclass,
|
||||
jlong nativeEngine, jobject javaBuffer, jint remaining, jboolean srgb) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
AutoBuffer buffer(env, javaBuffer, remaining);
|
||||
KtxBundle* bundle = new KtxBundle((const uint8_t*) buffer.getData(), buffer.getSize());
|
||||
Texture* cubemap = ktx::createTexture(engine, *bundle, srgb, [](void* userdata) {
|
||||
KtxBundle* bundle = (KtxBundle*) userdata;
|
||||
delete bundle;
|
||||
}, bundle);
|
||||
|
||||
float3 harmonics[9];
|
||||
bundle->getSphericalHarmonics(harmonics);
|
||||
|
||||
IndirectLight* indirectLight = IndirectLight::Builder()
|
||||
.reflections(cubemap)
|
||||
.irradiance(3, harmonics)
|
||||
.intensity(30000)
|
||||
.build(*engine);
|
||||
|
||||
return (jlong) indirectLight;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_KtxLoader_nCreateSkybox(JNIEnv* env, jclass,
|
||||
jlong nativeEngine, jobject javaBuffer, jint remaining, jboolean srgb) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
AutoBuffer buffer(env, javaBuffer, remaining);
|
||||
KtxBundle* bundle = new KtxBundle((const uint8_t*) buffer.getData(), buffer.getSize());
|
||||
Texture* cubemap = ktx::createTexture(engine, *bundle, srgb, [](void* userdata) {
|
||||
KtxBundle* bundle = (KtxBundle*) userdata;
|
||||
delete bundle;
|
||||
}, bundle);
|
||||
return (jlong) Skybox::Builder().environment(cubemap).showSun(true).build(*engine);
|
||||
}
|
||||
36
android/gltfio-android/src/main/cpp/MaterialProvider.cpp
Normal file
36
android/gltfio-android/src/main/cpp/MaterialProvider.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
67
android/gltfio-android/src/main/cpp/ResourceLoader.cpp
Normal file
67
android/gltfio-android/src/main/cpp/ResourceLoader.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 <filament/Engine.h>
|
||||
|
||||
#include <gltfio/ResourceLoader.h>
|
||||
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace gltfio;
|
||||
using namespace utils;
|
||||
|
||||
static void destroy(void* data, size_t size, void *userData) {
|
||||
AutoBuffer* buffer = (AutoBuffer*) userData;
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_gltfio_ResourceLoader_nCreateResourceLoader(JNIEnv*, jclass,
|
||||
jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return (jlong) new ResourceLoader({ engine, utils::Path(), true, true });
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_ResourceLoader_nDestroyResourceLoader(JNIEnv*, jclass,
|
||||
jlong nativeLoader) {
|
||||
ResourceLoader* loader = (ResourceLoader*) nativeLoader;
|
||||
delete loader;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_ResourceLoader_nAddResourceData(JNIEnv* env, jclass,
|
||||
jlong nativeLoader, jstring url, jobject javaBuffer, jint remaining) {
|
||||
ResourceLoader* loader = (ResourceLoader*) nativeLoader;
|
||||
AutoBuffer* buffer = new AutoBuffer(env, javaBuffer, remaining);
|
||||
const char* curl = env->GetStringUTFChars(url, nullptr);
|
||||
loader->addResourceData(curl,
|
||||
ResourceLoader::BufferDescriptor(buffer->getData(), buffer->getSize(), &destroy,
|
||||
buffer));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_gltfio_ResourceLoader_nLoadResources(JNIEnv*, jclass,
|
||||
jlong nativeLoader, jlong nativeAsset) {
|
||||
ResourceLoader* loader = (ResourceLoader*) nativeLoader;
|
||||
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
|
||||
loader->loadResources(asset);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Updates matrices according to glTF <code>animation</code> and <code>skin</code> definitions.
|
||||
*
|
||||
* <p>Animator can be used for two things:
|
||||
* <ul>
|
||||
* <li>Updating matrices in <code>TransformManager</code> components according to glTF <code>animation</code> definitions.</li>
|
||||
* <li>Updating bone matrices in <code>RenderableManager</code> components according to glTF <code>skin</code> definitions.</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @see AssetLoader
|
||||
* @see FilamentAsset
|
||||
* @see ResourceLoader
|
||||
*/
|
||||
public class Animator {
|
||||
private long mNativeObject;
|
||||
|
||||
Animator(long nativeObject) {
|
||||
mNativeObject = nativeObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies rotation, translation, and scale to entities that have been targeted by the given
|
||||
* animation definition. Uses <code>TransformManager</code>.
|
||||
*
|
||||
* @param animationIndex Zero-based index for the <code>animation</code> of interest.
|
||||
* @param time Elapsed time of interest in seconds.
|
||||
*
|
||||
* @see #getAnimationCount
|
||||
*/
|
||||
public void applyAnimation(@IntRange(from = 0) int animationIndex, float time) {
|
||||
nApplyAnimation(mNativeObject, animationIndex, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes root-to-node transforms for all bone nodes, then passes
|
||||
* the results into {@see RenderableManager#setBones}.
|
||||
* Uses <code>TransformManager</code> and <code>RenderableManager</code>.
|
||||
*
|
||||
* <p>NOTE: this operation is independent of <code>animation</code>.</p>
|
||||
*/
|
||||
public void updateBoneMatrices() {
|
||||
nUpdateBoneMatrices(mNativeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of <code>animation</code> definitions in the glTF asset.
|
||||
*/
|
||||
public int getAnimationCount() {
|
||||
return nGetAnimationCount(mNativeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the duration of the specified glTF <code>animation</code> in seconds.
|
||||
*
|
||||
* @param animationIndex Zero-based index for the <code>animation</code> of interest.
|
||||
*
|
||||
* @see #getAnimationCount
|
||||
* */
|
||||
public float getAnimationDuration(@IntRange(from = 0) int animationIndex) {
|
||||
return nGetAnimationDuration(mNativeObject, animationIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a weak reference to the string name of the specified <code>animation</code>, or an
|
||||
* empty string if none was specified.
|
||||
*
|
||||
* @param animationIndex Zero-based index for the <code>animation</code> of interest.
|
||||
*
|
||||
* @see #getAnimationCount
|
||||
*/
|
||||
public String getAnimationName(@IntRange(from = 0) int animationIndex) {
|
||||
return nGetAnimationName(mNativeObject, animationIndex);
|
||||
}
|
||||
|
||||
private static native void nApplyAnimation(long nativeAnimator, int index, float time);
|
||||
private static native void nUpdateBoneMatrices(long nativeAnimator);
|
||||
private static native int nGetAnimationCount(long nativeAnimator);
|
||||
private static native float nGetAnimationDuration(long nativeAnimator, int index);
|
||||
private static native String nGetAnimationName(long nativeAnimator, int index);
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.android.filament.Engine;
|
||||
import com.google.android.filament.EntityManager;
|
||||
|
||||
import java.nio.Buffer;
|
||||
|
||||
/**
|
||||
* Consumes a blob of glTF 2.0 content (either JSON or GLB) and produces {@link FilamentAsset}
|
||||
* objects, which are bundles of Filament entities, material instances, textures, vertex buffers,
|
||||
* and index buffers.
|
||||
*
|
||||
* <p>AssetLoader does not fetch external buffer data or create textures on its own. Clients can use
|
||||
* the provided {@link ResourceLoader} class for this, which obtains the URI list from the asset.
|
||||
* This is demonstrated in the Kotlin snippet below.</p>
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* companion object {
|
||||
* init {
|
||||
* Filament.init()
|
||||
* AssetLoader.init()
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* override fun onCreate(savedInstanceState: Bundle?) {
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* assetLoader = AssetLoader(engine, MaterialProvider(engine), EntityManager.get())
|
||||
*
|
||||
* filamentAsset = assets.open("models/lucy.glb").use { input ->
|
||||
* val bytes = ByteArray(input.available())
|
||||
* input.read(bytes)
|
||||
* assetLoader.createAssetFromBinary(ByteBuffer.wrap(bytes))!!
|
||||
* }
|
||||
*
|
||||
* ResourceLoader(engine).loadResources(filamentAsset).destroy()
|
||||
* animator = asset.getAnimator()
|
||||
*
|
||||
* scene.addEntities(filamentAsset.entities)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see Animator
|
||||
* @see FilamentAsset
|
||||
* @see ResourceLoader
|
||||
*/
|
||||
public class AssetLoader {
|
||||
private long mNativeObject;
|
||||
|
||||
/**
|
||||
* Initializes the gltfio JNI layer. Must be called before using any gltfio functionality.
|
||||
*/
|
||||
public static void init() {
|
||||
System.loadLibrary("gltfio-jni");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an <code>AssetLoader </code>that can be used to create and destroy instances of
|
||||
* {@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 entities the EntityManager that should be used to create entities
|
||||
*/
|
||||
public AssetLoader(@NonNull Engine engine, @NonNull MaterialProvider generator,
|
||||
@NonNull EntityManager entities) {
|
||||
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
long nativeMaterials = generator.getNativeObject();
|
||||
long nativeEntities = entities.getNativeObject();
|
||||
mNativeObject = nCreateAssetLoader(nativeEngine, nativeMaterials, nativeEntities);
|
||||
|
||||
if (mNativeObject == 0) {
|
||||
throw new IllegalStateException("Unable to parse glTF asset.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees all memory consumed by the native <code>AssetLoader</code> and its material cache.
|
||||
*/
|
||||
public void destroy() {
|
||||
nDestroyAssetLoader(mNativeObject);
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link FilamentAsset} from the contents of a GLB file.
|
||||
*/
|
||||
@Nullable
|
||||
public FilamentAsset createAssetFromBinary(@NonNull Buffer buffer) {
|
||||
long nativeAsset = nCreateAssetFromBinary(mNativeObject, buffer, buffer.remaining());
|
||||
return new FilamentAsset(nativeAsset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows clients to enable diagnostic shading on newly-loaded assets.
|
||||
*/
|
||||
public void enableDiagnostics(boolean enable) {
|
||||
nEnableDiagnostics(mNativeObject, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees all memory associated with the given {@link FilamentAsset}.
|
||||
*/
|
||||
public void destroyAsset(@Nullable FilamentAsset asset) {
|
||||
nDestroyAsset(mNativeObject, asset.getNativeObject());
|
||||
asset.clearNativeObject();
|
||||
}
|
||||
|
||||
private static native long nCreateAssetLoader(long nativeEngine, long nativeGenerator,
|
||||
long nativeEntities);
|
||||
private static native void nDestroyAssetLoader(long nativeLoader);
|
||||
private static native long nCreateAssetFromBinary(long nativeLoader, Buffer buffer, int remaining);
|
||||
private static native void nEnableDiagnostics(long nativeLoader, boolean enable);
|
||||
private static native void nDestroyAsset(long nativeLoader, long nativeAsset);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.android.filament.Box;
|
||||
import com.google.android.filament.Entity;
|
||||
|
||||
/**
|
||||
* Owns a bundle of Filament objects that have been created by <code>AssetLoader</code>.
|
||||
*
|
||||
* <p>For usage instructions, see the documentation for {@link AssetLoader}.</p>
|
||||
*
|
||||
* <p>This class owns a hierarchy of entities that have been loaded from a glTF asset. Every entity has
|
||||
* a <code>TransformManager</code> component, and some entities also have
|
||||
* <code>NameComponentManager</code> and/or <code>RenderableManager</code> components.</p>
|
||||
*
|
||||
* <p>In addition to the aforementioned entities, an asset has strong ownership over a list of
|
||||
* <code>VertexBuffer</code>, <code>IndexBuffer</code>, <code>MaterialInstance</code>, and
|
||||
* <code>Texture</code>.</p>
|
||||
*
|
||||
* <p>Clients can use {@link ResourceLoader} to create textures, compute tangent quaternions, and
|
||||
* upload data into vertex buffers and index buffers.</p>
|
||||
*
|
||||
* @see ResourceLoader
|
||||
* @see Animator
|
||||
* @see AssetLoader
|
||||
*/
|
||||
public class FilamentAsset {
|
||||
private long mNativeObject;
|
||||
private Animator mAnimator;
|
||||
|
||||
FilamentAsset(long nativeObject) {
|
||||
mNativeObject = nativeObject;
|
||||
mAnimator = null;
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transform root for the asset, which has no matching glTF node.
|
||||
*/
|
||||
public @Entity int getRoot() {
|
||||
return nGetRoot(mNativeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of entities, one for each glTF node.
|
||||
*
|
||||
* <p>All of these have a transform component. Some of the returned entities may also have a
|
||||
* renderable component.</p>
|
||||
*/
|
||||
public @Entity int[] getEntities() {
|
||||
int[] result = new int[nGetEntityCount(mNativeObject)];
|
||||
nGetEntities(mNativeObject, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounding box computed from the supplied min / max values in glTF accessors.
|
||||
*/
|
||||
public @NonNull Box getBoundingBox() {
|
||||
float[] box = new float[6];
|
||||
nGetBoundingBox(mNativeObject, box);
|
||||
return new Box(box[0], box[1], box[2], box[3], box[4], box[5]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <code>NameComponentManager</code> label for the given entity, if it exists.
|
||||
*/
|
||||
public String getName(@Entity int entity) {
|
||||
return nGetName(getNativeObject(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates or retrieves the <code>Animator</code> for this asset.
|
||||
*
|
||||
* <p>When calling this for the first time, this must be called after
|
||||
* {@see ResourceLoader#loadResources}.</p>
|
||||
*/
|
||||
public Animator getAnimator() {
|
||||
if (mAnimator != null) {
|
||||
return mAnimator;
|
||||
}
|
||||
mAnimator = new Animator(nGetAnimator(getNativeObject()));
|
||||
return mAnimator;
|
||||
}
|
||||
|
||||
void clearNativeObject() {
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
private static native int nGetRoot(long nativeAsset);
|
||||
private static native int nGetEntityCount(long nativeAsset);
|
||||
private static native void nGetEntities(long nativeAsset, int[] result);
|
||||
private static native void nGetBoundingBox(long nativeAsset, float[] box);
|
||||
private static native String nGetName(long nativeAsset, int entity);
|
||||
private static native long nGetAnimator(long nativeAsset);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.android.filament.Engine;
|
||||
import com.google.android.filament.IndirectLight;
|
||||
import com.google.android.filament.Skybox;
|
||||
import com.google.android.filament.Texture;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.Buffer;
|
||||
|
||||
/**
|
||||
* Utilities for consuming KTX files and producing Filament textures, IBLs, and sky boxes.
|
||||
*
|
||||
* <p>KTX is a simple container format that makes it easy to bundle miplevels and cubemap faces
|
||||
* into a single file.</p>
|
||||
*/
|
||||
public class KtxLoader {
|
||||
private static Constructor<Texture> sTextureConstructor;
|
||||
private static Constructor<IndirectLight> sIndirectLightConstructor;
|
||||
private static Constructor<Skybox> sSkyboxConstructor;
|
||||
|
||||
static {
|
||||
try {
|
||||
sTextureConstructor = Texture.class.getDeclaredConstructor(long.class);
|
||||
sTextureConstructor.setAccessible(true);
|
||||
|
||||
sIndirectLightConstructor = IndirectLight.class.getDeclaredConstructor(long.class);
|
||||
sIndirectLightConstructor.setAccessible(true);
|
||||
|
||||
sSkyboxConstructor = Skybox.class.getDeclaredConstructor(long.class);
|
||||
sSkyboxConstructor.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Cannot happen
|
||||
}
|
||||
}
|
||||
|
||||
public static class Options {
|
||||
public boolean srgb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes the content of a KTX file and produces a {@link Texture} object.
|
||||
*
|
||||
* @param engine Gets passed to the builder.
|
||||
* @param buffer The content of the KTX File.
|
||||
* @param options Loader options.
|
||||
* @return The resulting Filament texture, or null on failure.
|
||||
*/
|
||||
@Nullable
|
||||
public static Texture createTexture(@NonNull Engine engine, @NonNull Buffer buffer, @NonNull Options options) {
|
||||
try {
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
long nativeTexture = nCreateTexture(nativeEngine, buffer, buffer.remaining(), options.srgb);
|
||||
return sTextureConstructor.newInstance(nativeTexture);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes the content of a KTX file and produces an {@link IndirectLight} object.
|
||||
*
|
||||
* @param engine Gets passed to the builder.
|
||||
* @param buffer The content of the KTX File.
|
||||
* @param options Loader options.
|
||||
* @return The resulting Filament texture, or null on failure.
|
||||
*/
|
||||
@Nullable
|
||||
public static IndirectLight createIndirectLight(@NonNull Engine engine, @NonNull Buffer buffer, @NonNull Options options) {
|
||||
try {
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
long nativeIndirectLight = nCreateIndirectLight(nativeEngine, buffer, buffer.remaining(), options.srgb);
|
||||
return sIndirectLightConstructor.newInstance(nativeIndirectLight);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes the content of a KTX file and produces a {@link Skybox} object.
|
||||
*
|
||||
* @param engine Gets passed to the builder.
|
||||
* @param buffer The content of the KTX File.
|
||||
* @param options Loader options.
|
||||
* @return The resulting Filament texture, or null on failure.
|
||||
*/
|
||||
@Nullable
|
||||
public static Skybox createSkybox(@NonNull Engine engine, @NonNull Buffer buffer, @NonNull Options options) {
|
||||
try {
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
long nativeSkybox = nCreateSkybox(nativeEngine, buffer, buffer.remaining(), options.srgb);
|
||||
return sSkyboxConstructor.newInstance(nativeSkybox);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static native long nCreateTexture(long nativeEngine, Buffer buffer, int remaining, boolean srgb);
|
||||
private static native long nCreateIndirectLight(long nativeEngine, Buffer buffer, int remaining, boolean srgb);
|
||||
private static native long nCreateSkybox(long nativeEngine, Buffer buffer, int remaining, boolean srgb);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import com.google.android.filament.Engine;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Constructs an ubershader loader using the supplied {@link Engine}.
|
||||
*
|
||||
* @param engine the engine used to create materials
|
||||
*/
|
||||
public MaterialProvider(Engine engine) {
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
mNativeObject = nCreateMaterialProvider(nativeEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees memory associated with the native material provider.
|
||||
* */
|
||||
public void destroy() {
|
||||
nDestroyMaterialProvider(mNativeObject);
|
||||
mNativeObject = 0;
|
||||
}
|
||||
|
||||
long getNativeObject() {
|
||||
return mNativeObject;
|
||||
}
|
||||
|
||||
private static native long nCreateMaterialProvider(long nativeEngine);
|
||||
private static native void nDestroyMaterialProvider(long nativeProvider);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.android.filament.gltfio;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.filament.Engine;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.Buffer;
|
||||
|
||||
/**
|
||||
* Uploads vertex buffers and textures to the GPU and computes tangents.
|
||||
*
|
||||
* <p>For a usage example, see the documentation for {@link AssetLoader}.</p>
|
||||
*
|
||||
* @see AssetLoader
|
||||
* @see FilamentAsset
|
||||
*/
|
||||
public class ResourceLoader {
|
||||
private final long mNativeObject;
|
||||
|
||||
/**
|
||||
* Constructs a resource loader tied to the given Filament engine.
|
||||
*
|
||||
* @param engine the engine that gets passed to all builder methods
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
*/
|
||||
public ResourceLoader(@NonNull Engine engine) {
|
||||
long nativeEngine = engine.getNativeObject();
|
||||
mNativeObject = nCreateResourceLoader(nativeEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees all memory associated with the native resource loader.
|
||||
*/
|
||||
public void destroy() {
|
||||
nDestroyResourceLoader(mNativeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Feeds the binary content of an external resource into the loader's URI cache.
|
||||
*
|
||||
* <p><code>ResourceLoader</code> does not know how to download external resources on its own
|
||||
* (for example, external resources might come from a filesystem, a database, or the internet)
|
||||
* so this method allows clients to download external resources and push them to the loader.</p>
|
||||
*
|
||||
* <p>When loading GLB files (as opposed to JSON-based glTF files), clients typically do not
|
||||
* need to call this method.</p>
|
||||
*
|
||||
* @param uri the string path that matches an image URI or buffer URI in the glTF
|
||||
* @param buffer the binary blob corresponding to the given URI
|
||||
* @return self (for daisy chaining)
|
||||
*/
|
||||
@NonNull
|
||||
public ResourceLoader addResourceData(@NonNull String uri, @NonNull Buffer buffer) {
|
||||
nAddResourceData(mNativeObject, uri, buffer, buffer.remaining());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates through all external buffers and images and creates corresponding Filament objects
|
||||
* (vertex buffers, textures, etc), which become owned by the asset.
|
||||
*
|
||||
* <p>This is the main entry point for <code>ResourceLoader</code>, and only needs to be called
|
||||
* once.</p>
|
||||
*
|
||||
* @param asset the Filament asset that contains URI-based resources
|
||||
* @return self (for daisy chaining)
|
||||
*/
|
||||
@NonNull
|
||||
public ResourceLoader loadResources(@NonNull FilamentAsset asset) {
|
||||
nLoadResources(mNativeObject, asset.getNativeObject());
|
||||
return this;
|
||||
}
|
||||
|
||||
private static native long nCreateResourceLoader(long nativeEngine);
|
||||
private static native void nDestroyResourceLoader(long nativeLoader);
|
||||
private static native void nAddResourceData(long nativeLoader, String url, Buffer buffer,
|
||||
int remaining);
|
||||
private static native void nLoadResources(long nativeLoader, long nativeAsset);
|
||||
}
|
||||
@@ -46,6 +46,18 @@ host machine:
|
||||
|
||||

|
||||
|
||||
### `gltf-bloom`
|
||||
|
||||
Demonstrates how to load glTF models and render to an offscreen buffer:
|
||||
|
||||

|
||||
|
||||
### `hello-camera`
|
||||
|
||||
Demonstrates how to use `Stream` with Android's Camera2 API:
|
||||
|
||||

|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you start, make sure to read [Filament's README](../../README.md). You need to be able to
|
||||
|
||||
12
android/samples/gltf-bloom/.gitignore
vendored
Normal file
12
android/samples/gltf-bloom/.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
/.idea/caches
|
||||
/.idea/gradle.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/app/src/main/assets
|
||||
.externalNativeBuild
|
||||
1
android/samples/gltf-bloom/app/.gitignore
vendored
Normal file
1
android/samples/gltf-bloom/app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
68
android/samples/gltf-bloom/app/build.gradle
Normal file
68
android/samples/gltf-bloom/app/build.gradle
Normal file
@@ -0,0 +1,68 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
apply from: '../../../build/filament-tasks.gradle'
|
||||
|
||||
compileMaterials {
|
||||
group 'Filament'
|
||||
description 'Compile materials'
|
||||
|
||||
inputDir = file("src/main/materials")
|
||||
outputDir = file("src/main/assets/materials")
|
||||
}
|
||||
|
||||
task copyMesh(type: Copy) {
|
||||
from file("../../../../third_party/models/lucy/lucy.glb")
|
||||
into file("src/main/assets/models")
|
||||
}
|
||||
|
||||
generateIbl {
|
||||
group 'Filament'
|
||||
description 'Generate IBL'
|
||||
|
||||
cmgenArgs = "--format=ktx --size=256 --extract-blur=0.1 --deploy=src/main/assets/envs"
|
||||
inputFile = file("../../../../third_party/environments/venetian_crossroads_2k.hdr")
|
||||
outputDir = file("src/main/assets/envs")
|
||||
}
|
||||
|
||||
preBuild.dependsOn compileMaterials
|
||||
preBuild.dependsOn copyMesh
|
||||
preBuild.dependsOn generateIbl
|
||||
|
||||
clean.doFirst {
|
||||
delete "src/main/assets"
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
defaultConfig {
|
||||
applicationId "com.google.android.filament.gltf"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
// We use the .filamat extension for materials compiled with matc
|
||||
// Telling aapt to not compress them allows to load them efficiently
|
||||
aaptOptions {
|
||||
noCompress 'filamat', 'ktx'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
// Depend on Filament
|
||||
implementation 'com.google.android.filament:filament-android'
|
||||
implementation 'com.google.android.filament:gltfio-android'
|
||||
}
|
||||
21
android/samples/gltf-bloom/app/proguard-rules.pro
vendored
Normal file
21
android/samples/gltf-bloom/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user