Compare commits
807 Commits
optimize_p
...
devel_40_W
Author | SHA1 | Date | |
---|---|---|---|
1af89ca37b | |||
e2a61e175f | |||
27e5d0bdca | |||
eb2be07ee1 | |||
52509d6f57 | |||
9e74d19220 | |||
f9b6acb56c | |||
c3d9e26cde | |||
fa7a0fca62 | |||
3bcaf0e012 | |||
19aee81063 | |||
5ee42c2ae2 | |||
090f4576e0 | |||
c69fe080dc | |||
368056bb96 | |||
d1a1437e6f | |||
15da48eede | |||
585fd41966 | |||
91b056bacb | |||
7d41722baa | |||
dd083bb82b | |||
a23654c73a | |||
dd2ee57954 | |||
e9c3961aa5 | |||
dfa0b4033d | |||
d384f06ee2 | |||
93937c0394 | |||
db15096943 | |||
97040176d6 | |||
ec4125776a | |||
a180970eb6 | |||
cfda1fceb2 | |||
c1420e257d | |||
f9675fc1e5 | |||
92f612f675 | |||
edaf5aa3ca | |||
8ee9cdc396 | |||
87c150d1bd | |||
3fd6f98ef7 | |||
5935c3140f | |||
f24e4704a1 | |||
709c8be94d | |||
660d8fff6d | |||
0fbe85290b | |||
0c3cc5a320 | |||
3057fc7b6f | |||
73027ffd9a | |||
6635d33461 | |||
0170a8d7c6 | |||
b7627f392c | |||
3dfb2c65fd | |||
18d391f01e | |||
784e7f0e0b | |||
b5a5cb16c0 | |||
0be9cb3f74 | |||
c4720e8cdb | |||
272bb4a4b3 | |||
5b2f2dbb9f | |||
304c3a9bf4 | |||
eeb4492023 | |||
55204779ba | |||
5e541e2f46 | |||
2138f9046a | |||
a04adb897e | |||
8436e57ed7 | |||
bc987e7d7b | |||
427340132f | |||
f762d77b1d | |||
118ee6e570 | |||
520b7cae9e | |||
839e187cb2 | |||
5c186fdb95 | |||
8f1b891f9e | |||
75da8cabef | |||
8a99a331c0 | |||
66bb363035 | |||
455cb0aa63 | |||
e778f64f00 | |||
a641c56381 | |||
4b2f344c5c | |||
014fce2c8e | |||
692eeff4a3 | |||
5a04295f17 | |||
f1972908a1 | |||
2e7c2663e0 | |||
0e789b6f47 | |||
29aa76a917 | |||
2dd60fee7f | |||
fd1a629941 | |||
4a4326826e | |||
e8e6c20305 | |||
104e5ff615 | |||
5fec0732f3 | |||
b030684cbd | |||
33976d9bf6 | |||
e88facf834 | |||
9be5de0f57 | |||
2b251f06d4 | |||
7169429ede | |||
a858fcab99 | |||
aed57437f9 | |||
10d0c2c473 | |||
0e6546b514 | |||
44b1f13048 | |||
a50c3ef10b | |||
964c17cf94 | |||
87989a8e42 | |||
efed9ff0dd | |||
f0512edb5a | |||
ab3f771455 | |||
0b172bfc81 | |||
ee5d633596 | |||
6d211b3840 | |||
b05538b501 | |||
ada6a41fc6 | |||
d43a877be1 | |||
a4cc34d03b | |||
b77ede95e5 | |||
be3a8a2b00 | |||
b6a92e8cd3 | |||
7306581616 | |||
2e2f306b6b | |||
cf81e7bcff | |||
68089e13bc | |||
eee00f3c8c | |||
52b6e88522 | |||
383a568daa | |||
ce095f97f2 | |||
774f106738 | |||
0706f27354 | |||
62e9d2f904 | |||
d5df06dca3 | |||
9c3e16032e | |||
55765cf112 | |||
c5e9f151fc | |||
2f1ccda442 | |||
f88f6378b7 | |||
b63edb2f89 | |||
21c7f36d03 | |||
54d8726145 | |||
9f0625ed4e | |||
e5a46f3ee8 | |||
7ec1c095cc | |||
3807d9fcbf | |||
0d67993326 | |||
052e2c673a | |||
7c745df910 | |||
a03770fd00 | |||
3c2f7ad705 | |||
93e38fc14f | |||
dd0cf9bf51 | |||
dcefb261ad | |||
d63af2d8de | |||
fda6001451 | |||
f0a582271e | |||
74a5847bbc | |||
2576675265 | |||
ffaa038f99 | |||
768ebde879 | |||
af03f2967c | |||
e24286a87f | |||
99f833ef42 | |||
0735e783e6 | |||
053e579071 | |||
6e12a411b1 | |||
022cc4a2f3 | |||
906aba2459 | |||
b47b096039 | |||
63dac1ef74 | |||
0a072d846b | |||
7326765057 | |||
a569d08269 | |||
6fdf0e1fbd | |||
2e53b48fff | |||
aafdbdd4ea | |||
82a3ec4922 | |||
6141dbf4d5 | |||
c8adc9af24 | |||
79b0b2ef76 | |||
ab36f67412 | |||
487d3c4978 | |||
0a2862a051 | |||
10fbcfef14 | |||
414142283b | |||
96c3718b2a | |||
014d783e73 | |||
ff8222c256 | |||
911afc06f6 | |||
bd0a3d8be1 | |||
d810540b81 | |||
3259f1af4c | |||
62d370e508 | |||
2c67990daa | |||
620d05c6ff | |||
d1f1124302 | |||
e9d5b369bf | |||
71c0c7e627 | |||
2f34d556e4 | |||
b9fbab56f1 | |||
4614562929 | |||
9450d92784 | |||
d7f7a7d095 | |||
59fc27c864 | |||
bbbd8b06c2 | |||
efd9a447fb | |||
5e8957b78b | |||
99264b5b0a | |||
8ebbd674b2 | |||
72ceffeda2 | |||
726a8ec635 | |||
cf2efd69b9 | |||
e35abf0051 | |||
e02aaf812d | |||
ca6d99b6fb | |||
3f37fec8a8 | |||
7dc4bb9d76 | |||
3fc9971cf7 | |||
442e52e17c | |||
8245d83309 | |||
a9526ce956 | |||
410b94a127 | |||
f4e16276ff | |||
8880df8862 | |||
0a5fb750fa | |||
3589376b79 | |||
9443dd5942 | |||
c0e4c7fe7e | |||
ee9bd06f35 | |||
421f5f8134 | |||
5213651054 | |||
3768507169 | |||
7f074c6c79 | |||
2137725bd2 | |||
f7a0e97e49 | |||
d5234316ae | |||
c3a1266da6 | |||
e18a6e7a4a | |||
741e0e8ade | |||
f2a6c61c25 | |||
28fcdb6216 | |||
412ed6f3f2 | |||
03f7237db3 | |||
f79410e434 | |||
eef7f58575 | |||
bd4fc34cbb | |||
0c669807d7 | |||
8f0cd9f35b | |||
416b7bfcb3 | |||
fdf073376c | |||
1a15b93e15 | |||
898d01ac62 | |||
d11b84222f | |||
a04752b391 | |||
30bb77d437 | |||
8ebb3095a7 | |||
6571a27f41 | |||
5855b2eb5b | |||
ba7be3ff17 | |||
006929e86f | |||
25957d8d32 | |||
c29346887c | |||
69b9556ca1 | |||
390bd14c7c | |||
dcce45a5ce | |||
1f7c8fa25b | |||
0ba4674126 | |||
94a0e03c44 | |||
eb70cb1ea4 | |||
7903ac32c1 | |||
ac03ae4e44 | |||
a5fe26b2f0 | |||
3a6ec1f589 | |||
910a8fa51b | |||
cfc3ac8250 | |||
9121ebd11b | |||
107251c9ad | |||
04b77cadf9 | |||
0137ef6e0c | |||
fafe6c077b | |||
09e9e71d59 | |||
a22e802c77 | |||
1b5d4aabb0 | |||
af5988d96e | |||
56b8798122 | |||
2f49e80122 | |||
806bf5dfdd | |||
90a4f1d49f | |||
3927b3c788 | |||
6b9ac3220b | |||
4251493415 | |||
686372b60f | |||
150b27c6e6 | |||
c61e4dfdb8 | |||
23197e147c | |||
f1f0843bee | |||
8d45c87cfd | |||
781e108aa3 | |||
1abe8770d7 | |||
8f9ccc3aa1 | |||
cd01c45980 | |||
941f5ee6ec | |||
66fbe5571e | |||
4fcdd42ce4 | |||
d83f04faab | |||
b71c912fd5 | |||
2efb9c83bf | |||
7b0a185a45 | |||
0a025f0464 | |||
7f8fbbd3a0 | |||
cd4733a491 | |||
c1d54628d1 | |||
0da0290fc6 | |||
01bb4b2153 | |||
66ef3160e1 | |||
16ae849809 | |||
8788b3dd6a | |||
bba5a660a3 | |||
aa853fbdfb | |||
c780662ff6 | |||
611a9fe61d | |||
90152ca74e | |||
22868dafab | |||
6ce713aed5 | |||
ac0d1bee59 | |||
bf7c6bdeac | |||
cc80fe7f39 | |||
55001843ea | |||
8cdf88e2fd | |||
ca8e36687f | |||
86ff7517d9 | |||
742fe201ad | |||
8bb97ef2de | |||
9947d46ab8 | |||
bf5e401566 | |||
0dcf004f4c | |||
8d3cd8d561 | |||
6740764f07 | |||
a5e76988c7 | |||
08a348392d | |||
0dfb7220b5 | |||
4a94d78c1f | |||
9a4e495027 | |||
6de3cf789a | |||
299d3bd019 | |||
78b1982849 | |||
8a0215aee6 | |||
419e0e2574 | |||
cfd67e1a42 | |||
c49feac2e6 | |||
bf50333f5b | |||
40ce978f85 | |||
e27442a0b4 | |||
ecb47dae4d | |||
6892a64393 | |||
3af753ee36 | |||
f31437bf67 | |||
14fbbd6fa6 | |||
4e6adcd765 | |||
ead4ba65c1 | |||
310cc151fa | |||
03491dbed8 | |||
40094a7529 | |||
6ad3b9edb7 | |||
21a63f4a9b | |||
11ebb841be | |||
ad330f3a42 | |||
bbf94767fe | |||
6dba761a80 | |||
5391f0f4aa | |||
a1bf9336a3 | |||
9c6c37c07a | |||
3bbbe18c40 | |||
d8140ae64e | |||
acb69d3bf5 | |||
f0c47cd4f1 | |||
0b1a0cadae | |||
8633a18e01 | |||
2bc6246dc0 | |||
0a752446b0 | |||
c32f56fbe2 | |||
b100b4b9cb | |||
d20e9cf1e3 | |||
621e056315 | |||
4fc74d38ba | |||
f00cb0b815 | |||
e1d45a7c83 | |||
c5b8dbe8f6 | |||
172ee7bb7b | |||
d41530dad3 | |||
6efb50c977 | |||
f4493b09e5 | |||
af8f62ddb4 | |||
fff7fd3af0 | |||
2fdd7e7bd5 | |||
4ebc8a3260 | |||
5892b075c3 | |||
07a478a2ac | |||
8c51d3a52b | |||
c1183d351d | |||
d4c1dd312e | |||
3c22b48f3c | |||
02169963de | |||
ac81e4f8f0 | |||
1d3bec4098 | |||
3252d1581c | |||
01bf8b3dd2 | |||
1c03e838e5 | |||
0f38f94139 | |||
0639440a13 | |||
8492b886c9 | |||
a60ffbb7da | |||
b48ef1ac30 | |||
c363a6fa51 | |||
c873271f6e | |||
68ff8a472c | |||
60ba3e4df2 | |||
35b7c9651f | |||
89b9735f99 | |||
7f744d1207 | |||
b9f5c69f85 | |||
c469fde84a | |||
dd6b2f4fb3 | |||
ba8b44659b | |||
13b2ca0575 | |||
9d704eb33d | |||
86c3b65a42 | |||
f6e61e70ce | |||
5347ac7091 | |||
f56928d734 | |||
f3a59c1bb3 | |||
5188d4149c | |||
d4096735f5 | |||
4fafd938b1 | |||
f0848541c2 | |||
cc9e756ece | |||
cdedc81f9f | |||
c229259623 | |||
2c2f11f47e | |||
c8b3ed0286 | |||
2ce36ec26c | |||
5ba3c1790d | |||
3874d771d3 | |||
49eb8f42f0 | |||
c355f96f9b | |||
dc3d7b7792 | |||
5f1c60a24a | |||
ff6a644e8f | |||
b9e70426a1 | |||
a7af276a44 | |||
8b82c6c25c | |||
a8d68c295d | |||
f666d5b248 | |||
55c27a883b | |||
6a7f8e7754 | |||
1dbf8ae5c7 | |||
8dbc1d899c | |||
d010ee4278 | |||
4aeb28c571 | |||
775e031422 | |||
deefdf1416 | |||
ba2d479f05 | |||
b16341c0f9 | |||
d5eeb081e1 | |||
4bb66d2746 | |||
625a7387ae | |||
c4deceebd9 | |||
4ed0e281b2 | |||
9369ad115b | |||
7788459109 | |||
a58589f01f | |||
240b6fb0e3 | |||
b72a924853 | |||
b781ff41a3 | |||
4ee6962d04 | |||
7eff39b3b0 | |||
6b13c159d8 | |||
2f560a28a7 | |||
8ba171efda | |||
317635877b | |||
255c7859f1 | |||
ae85d3fc66 | |||
a5830e18cb | |||
ae88a65315 | |||
77b0266cdc | |||
c99934fdf9 | |||
aa6071a948 | |||
6f58475abd | |||
cfed14d746 | |||
27c409c7fd | |||
bee48890cb | |||
a2669d2123 | |||
737438aaed | |||
8a5711154f | |||
3dd308aff1 | |||
bead8128b7 | |||
019e9964fa | |||
7ca81f38e8 | |||
03750832c8 | |||
018a72c09a | |||
55fee1e5d7 | |||
c5dd359d18 | |||
85ec666989 | |||
9a5cead33e | |||
695f1a22a8 | |||
237c1a469b | |||
5ede824522 | |||
46781b9627 | |||
aaff0c23c9 | |||
3a3f9d10b7 | |||
b6e391762b | |||
b262fdc645 | |||
5e795c4a7f | |||
0524c51feb | |||
8dc9846ae8 | |||
1d866abb48 | |||
ece7912f3c | |||
4ef37a430e | |||
1f91ec94e1 | |||
86123827cb | |||
19df201ab5 | |||
921d6d157f | |||
c0e4128365 | |||
8fe5e8dd55 | |||
3393a90127 | |||
9b5157594f | |||
10d4f2f04a | |||
a1e7b105f7 | |||
67cf89fef1 | |||
e95cbb28a4 | |||
c9d6774bd3 | |||
78946994bb | |||
1a63fa8c76 | |||
db766f33ac | |||
3db94948c5 | |||
cefea7229d | |||
45f50b3bc0 | |||
dbea7764fb | |||
1101bcae9d | |||
6c7f9ea9d1 | |||
253d113375 | |||
ca1bb80b5f | |||
922fc2661b | |||
e9a8e5bbf2 | |||
bba00534ba | |||
c15fbf8252 | |||
9a7e711658 | |||
65c3d5cad1 | |||
7d9192051a | |||
22099b6b84 | |||
322d24c4ca | |||
5230fbc27f | |||
f901708b6c | |||
2487cb1f36 | |||
7805494ca9 | |||
ac4c97d33a | |||
a87a35b5f8 | |||
d456c2bf92 | |||
12e18b517b | |||
2f00aa8e1e | |||
4e144072e4 | |||
907cb3c852 | |||
eb51df8dd0 | |||
ed9ba3876f | |||
97290ce54c | |||
bebac2284f | |||
d5d6a6bc74 | |||
5559178e7c | |||
f58ce4f98b | |||
5c2f136689 | |||
6820ee8c74 | |||
ddb5a0b77a | |||
69646971ce | |||
e71ec4be85 | |||
dbe2370a44 | |||
00d2677066 | |||
4208e47534 | |||
2dedeaad90 | |||
083600a95f | |||
902dc20340 | |||
164498446a | |||
cef5ad073b | |||
c2279c553d | |||
d959e7988d | |||
202bff5870 | |||
8437d8d561 | |||
714fc3dcb7 | |||
e030738a5f | |||
28b2b53d03 | |||
8bb742f3f4 | |||
6e8932fc2f | |||
9661336325 | |||
ef84e5c699 | |||
3b106a3b42 | |||
74003df08b | |||
95c67ba857 | |||
f51c7c6964 | |||
3fe8d9f90d | |||
7967150722 | |||
51a6da3d9f | |||
dd047c1644 | |||
df80b1af3b | |||
64235b12b6 | |||
0557ff2bae | |||
b43d4cc5a3 | |||
b72144a28b | |||
d05f1109b5 | |||
3de67f8cf1 | |||
9816592bf6 | |||
82f3ad070b | |||
b021b05cb0 | |||
5749d8ec8a | |||
e6560dfe5f | |||
8f6260f440 | |||
18850b0e27 | |||
de2926a6d5 | |||
1a8bd0a607 | |||
ffaa6b5362 | |||
9d3ea89861 | |||
7f1532dc6e | |||
01cdb7661b | |||
ab6a8435a1 | |||
d17932c7a4 | |||
f4a8406ad8 | |||
22bc5f6653 | |||
fc94ee82b4 | |||
f8fe0e46d6 | |||
e076b72f1a | |||
a04742c347 | |||
1668a0c973 | |||
e2dd652c3a | |||
a2c3438c58 | |||
5521c53c94 | |||
71fd42cfc8 | |||
222ff2961f | |||
ed5aac2a9d | |||
233523231e | |||
3523afc6c2 | |||
6b498d7e91 | |||
fa7ecb91ac | |||
d5b719152f | |||
410a386423 | |||
641ba4431f | |||
c485941342 | |||
198fe55216 | |||
ad7c652cd4 | |||
46b6797bce | |||
c8dbd40333 | |||
35844d52bc | |||
36d872359e | |||
8086fb76f1 | |||
d660691cec | |||
c5699fd1af | |||
9316135942 | |||
8340209697 | |||
aa217c6fc5 | |||
d5b69fbe71 | |||
58c62ddb59 | |||
7f3132236f | |||
f8ff6d9cf0 | |||
8855f0b880 | |||
254264ac5e | |||
9a24aa237d | |||
ff184ecd7a | |||
81ab733429 | |||
05885e443a | |||
71c543413a | |||
d6d2d337c9 | |||
4ef1283fce | |||
7c4a27771f | |||
a97440e1fc | |||
e1cfc1e5b8 | |||
2c602e9045 | |||
f46b1382ee | |||
459fb3afc4 | |||
27f33e07cb | |||
9c956e1c65 | |||
004504e027 | |||
7c3d9ecf91 | |||
3f1b8be5d0 | |||
f3ab0a5608 | |||
8e64816af8 | |||
5718b1795f | |||
c8cbf020eb | |||
9535a4486e | |||
9781e6a9b3 | |||
958183bb29 | |||
abfc84feff | |||
12e64d7ce0 | |||
34b7937ee2 | |||
2336c7cdf1 | |||
21201b1695 | |||
2eac17ac61 | |||
1e03e28f0b | |||
30c736b7c8 | |||
7031270476 | |||
6bdbf87446 | |||
110c141073 | |||
b9bd4f6c4b | |||
8b0ef244e0 | |||
c232feb40a | |||
db0a8ee256 | |||
b26e25df61 | |||
cd03ee8211 | |||
48b5479ade | |||
1ec88c65f8 | |||
ba6af7a596 | |||
d163f914c7 | |||
0e589e8bcd | |||
011fbdb55d | |||
e488b4c3d3 | |||
49f37447d0 | |||
f280068d50 | |||
137248a274 | |||
ec45b977d1 | |||
38f9a2896f | |||
59b02bcb8c | |||
05e96c58ba | |||
cb09767151 | |||
554220699f | |||
3937206fcb | |||
88f23d9a07 | |||
15324d9c86 | |||
6c3e674d23 | |||
fefdc19674 | |||
18a4212935 | |||
0457d28577 | |||
fd39d08fda | |||
8e52595123 | |||
19a20411d8 | |||
8363275b36 | |||
939bbfeb1f | |||
f555c77a83 | |||
160ba000d3 | |||
5f830b8d57 | |||
5d9aab7dda | |||
cde2d9f86b | |||
d26eb482e7 | |||
eb8e0a921b | |||
9fd13680d1 | |||
8af96ed4a5 | |||
57b480754c | |||
ac42dcdb26 | |||
e1c3b95de7 | |||
ee061e4a1a | |||
f2c6c24ddf | |||
76f5dcb884 | |||
157c09eff0 | |||
9f8e63788d | |||
a7c761e1c5 | |||
44620abc21 | |||
8bf1ad2a46 | |||
d26cae0086 | |||
bc9fc9b50f | |||
fb4c8ed8c2 | |||
0dae30fa06 | |||
48b5a978b8 | |||
694add27ae | |||
251bbd2705 | |||
3bfc31b57f | |||
8c8a218a3a | |||
9302cbc3ef | |||
696d3259aa | |||
85530e6d57 | |||
81e2aac321 | |||
35a282ef5e | |||
3a378be660 | |||
aed56a35e0 | |||
09277924f1 | |||
c4a4ec5ebc | |||
703d444cbb | |||
159c808dad | |||
facdec5556 | |||
42f63c5ef1 | |||
5f4dd09f92 | |||
9872f74160 | |||
529d6b7939 | |||
f748301787 | |||
165f9d2a5f | |||
4de8139936 | |||
9ee5f0adaa | |||
555e8fc066 | |||
f564f55e7b | |||
31b5bb6d4f | |||
5ba705cd6b | |||
9cfb88235a | |||
eceaf9ba68 | |||
14e7074b3f | |||
f79599b1d4 | |||
2cc0dca050 | |||
ece7fa5f32 | |||
68b24903bb | |||
6ee832c39f | |||
26f7c915c8 | |||
2ac91b80ac | |||
eed16928e9 | |||
6b8e76b75f | |||
ca36b4454b | |||
ba65d1abf2 | |||
ef8f630056 | |||
7a0acaf63e | |||
d54aff2a42 | |||
84d0dc99c8 | |||
b4dccf7814 | |||
f2d5209681 | |||
0abe38de98 | |||
6536b715c3 | |||
26b907f611 |
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 1e14c1b01dd9b1e6590110cdf5fb239da30d00c1
|
||||
Subproject commit 0244bff1b60119806f683b54a137cda2cacc17ac
|
@ -1 +1 @@
|
||||
Subproject commit ca9aece201dd581c0576fe5448162686081261ff
|
||||
Subproject commit 6fbc7078181cefc7e5da590c2d4ccc70507934b7
|
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit ac5931ce2602d45149e1c8baacf0805fa39f73f6
|
||||
Subproject commit 71b459c0246d70d0bba5dd49662b5534c579251e
|
@ -1 +1 @@
|
||||
Subproject commit ef90beb4501fe8712ab93e4c775612e172598fa3
|
||||
Subproject commit f0ff214289a1265898feecbdbbd2ddf50bff5dca
|
@ -1 +1 @@
|
||||
Subproject commit 09fe2f07ba212393a4b8d3eeffe82f01a058ddc3
|
||||
Subproject commit 1e7e4a025cdd03125144e167b62f70a8efdaf245
|
2
CMUtil
2
CMUtil
@ -1 +1 @@
|
||||
Subproject commit 9f94d5082bbbba65d55ae259deebbfc72b4a672a
|
||||
Subproject commit 48383e5f63928bab43320c406219365850507246
|
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
PROJECT(ULRE)
|
||||
|
||||
@ -8,34 +8,35 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMCMakeModule)
|
||||
|
||||
set(ULRE_3RDPTY_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdpty)
|
||||
|
||||
include_directories(${ULRE_3RDPTY_ROOT_PATH}/NvTriStrip)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
|
||||
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
SET(ULRE_RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include(math)
|
||||
include(vulkan)
|
||||
include(use_cm_module)
|
||||
|
||||
SET(ULRE CMCore
|
||||
CMPlatform
|
||||
CMAssetsManage
|
||||
CMSceneGraph
|
||||
CMUtil
|
||||
ULRE.Work
|
||||
ULRE.Util
|
||||
ULRE.ShaderGen
|
||||
ULRE.SceneGraph
|
||||
${HGL_MATH_LIB}
|
||||
${RENDER_LIBRARY}
|
||||
${Vulkan_LIBRARIES})
|
||||
|
||||
use_cm_module(Core)
|
||||
use_cm_module(Util)
|
||||
use_cm_module(Platform)
|
||||
use_cm_module(AssetsManage)
|
||||
use_cm_module(SceneGraph)
|
||||
|
||||
SET(ULRE CMCore
|
||||
CMPlatform
|
||||
CMAssetsManage
|
||||
CMSceneGraph
|
||||
CMUtil
|
||||
ULRE.Util
|
||||
ULRE.SceneGraph
|
||||
${HGL_GLM_LIB}
|
||||
${RENDER_LIBRARY}
|
||||
${Vulkan_LIBRARIES})
|
||||
|
||||
include_directories(${ULRE_3RDPTY_ROOT_PATH}/NvTriStrip)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
|
||||
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
|
||||
SET(ULRE_RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
add_subdirectory(example)
|
||||
|
BIN
GLSLCompiler.dll
Normal file
BIN
GLSLCompiler.dll
Normal file
Binary file not shown.
26
README.md
26
README.md
@ -1,17 +1,33 @@
|
||||
# ULRE
|
||||
experiment project - Ultra Light Rendering Engine
|
||||
experiment project - Ultra Lightweight Rendering Engine
|
||||
|
||||
ULRE is a project of experimental nature,Used to experiment with various rendering related techniques,And do some examples.
|
||||
ULRE is a project of an experimental nature. Used to experiment with various rendering-related techniques And do some examples.
|
||||
|
||||
In the future, its compilicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
|
||||
In the future, its complicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
|
||||
|
||||
Platform: Windows,Linux (WIP: Android)
|
||||
Platform: Windows, Linux (WIP: Android, macOS, iOS)
|
||||
|
||||
Graphics API: Vulkan
|
||||
|
||||
Milestone:
|
||||
|
||||
2. Texture2DArray was integrated into material instances.
|
||||
Multiple render instances of the same model use different material instances and textures but are still merged into one render.
|
||||
Although the changes this time are small, they are more significant.
|
||||
|
||||
1. a test was completed, and the entire scene was drawn with only one DrawCall.
|
||||
Although it still has a lot of unfinished work, it is still a significant milestone.
|
||||
|
||||
#
|
||||
ULRE是一个试验性质的工程,用于试验各种渲染相关的技术,以及做一些范例。在未来它的复杂化版本会被整合到CMGameEngine中,用于替代旧的渲染引擎。
|
||||
|
||||
平台: Windows,Linux (开发中: Android)
|
||||
平台: Windows, Linux (开发中: Android, macOS, iOS)
|
||||
|
||||
图形API: Vulkan
|
||||
|
||||
里程碑:
|
||||
|
||||
2. Texture2DArray集成在材质实例中。同一个模型的多个渲染实例使用不同的材质实例以及不同的纹理,
|
||||
但它们依然被合并成一次渲染。这次的改变虽小,但意义更为重大。
|
||||
|
||||
1. 完成了一个测试,只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作,但它依然是一个非常重要的里程碑。
|
||||
|
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
@ -0,0 +1,11 @@
|
||||
mat4 GetJointMatrix()
|
||||
{
|
||||
// Joint数据分Joint ID和Joint Weight两部分
|
||||
// Joint ID是一个uvec4,在shader中为整数。在C++端可使用RGBA8UI或是RGBA16UI来传递。
|
||||
// Joint Weight是权重,在shader中为浮点。在C++端使用RGBA8或RGBA4来传递。
|
||||
|
||||
return joint.mats[JointID.x]*JointWeight.x+
|
||||
joint.mats[JointID.y]*JointWeight.y+
|
||||
joint.mats[JointID.z]*JointWeight.z+
|
||||
joint.mats[JointID.w]*JointWeight.w;
|
||||
}
|
9
ShaderLibrary/Normal.glsl
Normal file
9
ShaderLibrary/Normal.glsl
Normal file
@ -0,0 +1,9 @@
|
||||
mat3 GetNormalMatrix()
|
||||
{
|
||||
return mat3(camera.view*GetLocalToWorld());
|
||||
}
|
||||
|
||||
vec3 GetNormal(mat3 normal_matrix,vec3 normal)
|
||||
{
|
||||
return normalize(normal_matrix*normal);
|
||||
}
|
38
ShaderLibrary/Std2D/PureColor2D.mtl
Normal file
38
ShaderLibrary/Std2D/PureColor2D.mtl
Normal file
@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name PureColor2D
|
||||
Base Std2D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=mi.Color;
|
||||
}
|
||||
}
|
39
ShaderLibrary/Std2D/PureTexture2D.mtl
Normal file
39
ShaderLibrary/Std2D/PureTexture2D.mtl
Normal file
@ -0,0 +1,39 @@
|
||||
#Material
|
||||
Name PureTexture2D
|
||||
Base Std2D
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
@ -0,0 +1,68 @@
|
||||
#Material
|
||||
Name RectTexture2D
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
@ -0,0 +1,79 @@
|
||||
#Material
|
||||
Name RectTexture2DArray
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
uvec4 id;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
HandoverMI();gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2DArray TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=texture(TextureBaseColor,vec3(Input.TexCoord,mi.id.x));
|
||||
}
|
||||
}
|
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
@ -0,0 +1,37 @@
|
||||
#Material
|
||||
Name VertexColor2D
|
||||
Base Std2D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
82
ShaderLibrary/Std3D/Billboard/FixedSize.mtl
Normal file
82
ShaderLibrary/Std3D/Billboard/FixedSize.mtl
Normal file
@ -0,0 +1,82 @@
|
||||
#Material
|
||||
Name BillboardFixedSize
|
||||
Base Std3D/Billboard
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#MaterialInstance
|
||||
Length 8
|
||||
Stage Vertex
|
||||
|
||||
Code
|
||||
{
|
||||
uvec2 BillboardSize;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 BillboardSize
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.BillboardSize=mi.BillboardSize/viewport.canvas_resolution;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
gl_Position/=gl_Position.w;
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
const vec2 BillboardVertex[4]=vec2[]
|
||||
(
|
||||
vec2(-0.5,-0.5),
|
||||
vec2(-0.5, 0.5),
|
||||
vec2( 0.5,-0.5),
|
||||
vec2( 0.5, 0.5)
|
||||
);
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
gl_Position=gl_in[0].gl_Position;
|
||||
gl_Position.xy+=BillboardVertex[i]*Input[0].BillboardSize;
|
||||
|
||||
Output.TexCoord=BillboardVertex[i]+vec2(0.5);
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
@ -0,0 +1,2 @@
|
||||
vec4 direction;
|
||||
vec4 color;
|
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
@ -0,0 +1,92 @@
|
||||
#Material
|
||||
Name BlinnPhong+HalfLambert shading model only color
|
||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||
Base Std3D/BlinnPhong
|
||||
|
||||
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||
Require LocalToWorld
|
||||
Require Camera
|
||||
|
||||
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec3 Color;
|
||||
float Gloss;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Position;
|
||||
vec3 Normal;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Normal =GetNormal();
|
||||
Output.Position =GetPosition3D();
|
||||
|
||||
HandoverMI();
|
||||
|
||||
gl_Position =Output.Position;
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
#define HAVE_SPECULAR
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
//点乘法线和光照
|
||||
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
FragColor=vec4(direct_color,1.0);
|
||||
#else
|
||||
|
||||
vec3 spec_color=vec3(0.0);
|
||||
|
||||
if(intensity>0.0)
|
||||
{
|
||||
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
|
||||
|
||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||
|
||||
spec_color=specular*pow(specular,mi.Gloss)*sun.color.rgb;
|
||||
}
|
||||
|
||||
FragColor=vec4(direct_color+spec_color,1.0);
|
||||
#endif//HAVE_SPECULAR
|
||||
}
|
||||
}
|
100
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColorTexture.mtl
Normal file
100
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColorTexture.mtl
Normal file
@ -0,0 +1,100 @@
|
||||
#Material
|
||||
Name BlinnPhong+HalfLambert shading model only color
|
||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||
Base Std3D/BlinnPhong
|
||||
|
||||
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||
Require LocalToWorld
|
||||
Require Camera
|
||||
|
||||
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 32
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
uint tex_id;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
vec2 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Position;
|
||||
vec3 Normal;
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Normal =GetNormal();
|
||||
Output.Position =GetPosition3D();
|
||||
Output.TexCoord =TexCoord;
|
||||
|
||||
HandoverMI();
|
||||
|
||||
gl_Position =Output.Position;
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2DArray TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
#define HAVE_SPECULAR
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
vec4 texture_color=texture(TextureBaseColor,vec3(Input.TexCoord,mi.tex_id));
|
||||
|
||||
//点乘法线和光照
|
||||
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb*texture_color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
FragColor=vec4(direct_color,1.0);
|
||||
#else
|
||||
|
||||
vec3 spec_color=vec3(0.0);
|
||||
|
||||
if(intensity>0.0)
|
||||
{
|
||||
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
|
||||
|
||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||
|
||||
spec_color=specular*pow(specular,8)*sun.color.rgb;
|
||||
}
|
||||
|
||||
FragColor=vec4(direct_color+spec_color,1.0);
|
||||
#endif//HAVE_SPECULAR
|
||||
}
|
||||
}
|
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
@ -0,0 +1,87 @@
|
||||
#Material
|
||||
Name MetricCellsGrid
|
||||
Base Std3D
|
||||
Reference https://www.shadertoy.com/view/wdSXzm
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#MaterialInstance
|
||||
Length 120
|
||||
Stage Fragment
|
||||
|
||||
Code
|
||||
{
|
||||
vec4 x_color;
|
||||
vec4 y_color;
|
||||
vec4 x_axis_color;
|
||||
vec4 y_axis_color;
|
||||
vec4 center_color;
|
||||
|
||||
vec2 lum; //x=0.1 sub cell line,y=0.2 big cell line
|
||||
vec2 cell_step;
|
||||
vec2 big_cell_step;
|
||||
vec2 scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
float edge=viewport.inv_viewport_resolution.y;
|
||||
|
||||
float x=(Input.TexCoord.x-0.5)*mi.scale.x;
|
||||
float y=(Input.TexCoord.y-0.5)*mi.scale.y;
|
||||
|
||||
vec4 color=vec4(0,0,0,1);
|
||||
|
||||
// ======= Lines + Bold lines
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.x, fract(x / mi.cell_step.x )) * mi.x_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.x, fract(x / mi.big_cell_step.x)) * mi.x_color.rgb * mi.lum.y;
|
||||
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.y, fract(y / mi.cell_step.y )) * mi.y_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.y, fract(y / mi.big_cell_step.y)) * mi.y_color.rgb * mi.lum.y;
|
||||
|
||||
// ======= AXES
|
||||
float xb = step(abs(x) - mi.axis_line_width, 0.0);
|
||||
float yb = step(abs(y) - mi.axis_line_width, 0.0);
|
||||
|
||||
color.rgb = mix(color.rgb, mi.x_axis_color.rgb, (xb));
|
||||
color.rgb = mix(color.rgb, mi.y_axis_color.rgb, (yb));
|
||||
|
||||
// ======= CENTER
|
||||
float cb = length(vec2(x,y))-mi.center_radius;
|
||||
color.rgb = mix(color.rgb, mi.center_color.rgb, cb>0.0?0.0:smoothstep(0,edge*mi.scale.y,abs(cb)));
|
||||
|
||||
FragColor=color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name PureColor3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=mi.Color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name VertexColor3D
|
||||
Base Std3D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
@ -0,0 +1,47 @@
|
||||
#Material
|
||||
Name VertexLum3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Vertex
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
float Luminance
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.Color=Luminance*mi.Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
34
doc/AssetFileFormat.md
Normal file
34
doc/AssetFileFormat.md
Normal file
@ -0,0 +1,34 @@
|
||||
# 为什么我们使用INI/TOML做为资产文件格式?
|
||||
|
||||
大部分的数据文件,我们会将其分为属性文本部分与二进制数据部分。
|
||||
|
||||
其中属性部分,我们会使用INI/TOML方式编写。这样利于git/hg/svn等版本控制系统进行差异合并。
|
||||
|
||||
比如一个纹理贴图,它的二进制部分首先是有它的“原始位图数据阵列”,它的属性部分包含“宽、高、象素格式”这样的不可更改数据,也包括“sRGB/Linear色彩空间、纹理分组、建议过滤方式、特定平台建议的压缩算法”等可调整数据。还有资产使用过程中产生的“引用资产列表”和“被引用资产列表”。
|
||||
|
||||
而这些可调整数据,我们可能是会随时修改的,甚至是不同的人可能会修改不同的部分。
|
||||
|
||||
如果我们将这些数据,全部放入一个二进制文件中,比如png/jpeg中。那么每修改一个小小的属性,都需要向git/svn仓库提交整个二进制文件。这是相当愚蠢和不合理的。
|
||||
|
||||
而众所周知:不管是免费的git/hg/svn,还是收费的p4,它们针对文本文件都会有一系列的差异化比较合并功能。而这个差异化自动合并,都是基于文本行的。
|
||||
所以,我们的所有资产文件,都会分裂成二进制数据文件和属性文本文件。而在这个属性文本文件中,对于每一项属性,是使用独立的行来保存数据的。
|
||||
|
||||
|
||||
# Why do we use the INI/TOML as an asset file format?
|
||||
For most files, we will split into the attributes text part and binary data part.
|
||||
|
||||
We will use the INI/TOML format to write the properties part. Because the format easily merges diff by git/hg/svn.
|
||||
|
||||
For example a texture. It's binary data includes "Raw bitmap data".
|
||||
Its attributes part include "width, height, pixel format", they can't change.
|
||||
Also, "sRGB/Linear colour space", "texture group", "recommend filter type" and "recommend compress format of special platform".
|
||||
|
||||
We may modify this data at any time. Even many people modify different parts at the same time.
|
||||
|
||||
If we use a binary file that it includes all data. for example, .png or .jpeg.
|
||||
We need commit whole binary data after changed a few attributes. This behaviour is quite stupid and irrational.
|
||||
|
||||
Most people know this knowledge: Free git/hg/svn and commercial p4. They both include a merge-diff tool, which is text based.
|
||||
so, we all asset files, they should split into the attributes text part and binary data part.
|
||||
In this attribute's text file, a separate line is used to save data for each attribute.
|
||||
|
28
doc/AssetPath.md
Normal file
28
doc/AssetPath.md
Normal file
@ -0,0 +1,28 @@
|
||||
# AssetPath
|
||||
|
||||
具体源代码参见CMAssetManage中的AssetPath.h
|
||||
|
||||
# 大致规则
|
||||
|
||||
Asset代表的资产,意味应用程序本身所拥有的资源。而AssetPath意味指向这个资产的一个字符串。
|
||||
|
||||
AssetPath的组成规和Windows/UNIX/Linux的路径原则类似,大致如下:
|
||||
|
||||
```C++
|
||||
LOCATION:/abc/123/test_material.mtl
|
||||
```
|
||||
|
||||
LOCATION 它代表资产所在的大范围位置,是可以不存在的,也就是说如下的写法也是可以的
|
||||
```C++
|
||||
:/abc/123/test_material.mtl
|
||||
```
|
||||
这个LOCATION的定义我们暂时有以下几个:
|
||||
|
||||
| LOCATION | 意义 |
|
||||
|----------|------------------|
|
||||
| 不写 | 应用程序本身的资产包 |
|
||||
| Asset | 应用程序本身的资产包 |
|
||||
| Engine | 代表引擎资产 |
|
||||
| PlugIn | 代表插件资产 |
|
||||
| ExtPack | 应用程序扩展资产包(一般用于额外安装或下载的资产包) |
|
||||
| OS | 操作系统真实路径访问 |
|
BIN
doc/BlenderGizmo/Move.png
Normal file
BIN
doc/BlenderGizmo/Move.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 141 KiB |
BIN
doc/BlenderGizmo/Rotate.png
Normal file
BIN
doc/BlenderGizmo/Rotate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 KiB |
BIN
doc/BlenderGizmo/Scale.png
Normal file
BIN
doc/BlenderGizmo/Scale.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 180 KiB |
47
doc/CreateMaterialInstance.md
Normal file
47
doc/CreateMaterialInstance.md
Normal file
@ -0,0 +1,47 @@
|
||||
# CreateMaterialInstance
|
||||
|
||||
## 1st
|
||||
|
||||
最早最根本的方法,直接在C++代码层面通过mtl::CreateVertexColor2D()函数来创建MaterialCreateInfo
|
||||
```C++
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",PrimitiveType::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=CreateMaterialInstance(mci);
|
||||
```
|
||||
|
||||
## 2nd
|
||||
注册材质系统引入后的方法,通过名称"VertexColor2D"来创建MaterialCreateInfo
|
||||
```C++
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",PrimitiveType::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateMaterialCreateInfo("VertexColor2D",&cfg);
|
||||
|
||||
material_instance=CreateMaterialInstance(mci);
|
||||
```
|
||||
|
||||
## 3rd
|
||||
其实是第二种方法在WorkObject层面的封装
|
||||
```C++
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",PrimitiveType::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material_instance=CreateMaterialInstance("VertexColor2D",&cfg);
|
||||
```
|
||||
|
||||
## 4th
|
||||
是更进一步的封装,通过材质配置文件连带Material2DCreateConfig的具体配置都进行了封闭。
|
||||
```C++
|
||||
AssetPath path(":/asset/test_material.mtl");
|
||||
|
||||
material_instance=CreateMaterialInstance(path);
|
||||
```
|
BIN
doc/Gizmo.odg
Normal file
BIN
doc/Gizmo.odg
Normal file
Binary file not shown.
20
doc/InlineMaterial.md
Normal file
20
doc/InlineMaterial.md
Normal file
@ -0,0 +1,20 @@
|
||||
# 程序内嵌材质/Shader
|
||||
# Material/Shader embedded in program code
|
||||
|
||||
问题(Question):
|
||||
|
||||
```
|
||||
即然可以从文件中加载材质了,那为什么还需要有程序代码中内嵌的材质/Shader呢?
|
||||
|
||||
I can load a material from a file. Why do we need a few materials/shaders embedded in the code?
|
||||
```
|
||||
|
||||
这个问题很好,答案也很简单:
|
||||
|
||||
Good question, the answer is straightforward:
|
||||
|
||||
```
|
||||
我们需要在资产损坏或丢失的情况下,依然可以渲染一些内容, 比如: 一个报错对话框。
|
||||
|
||||
We need to be able to render some content, such as an error dialog box, even if the asset is damaged or lost.
|
||||
```
|
@ -10,4 +10,6 @@
|
||||
endmacro()
|
||||
|
||||
CreateProject(00.line line.cpp)
|
||||
CreateProject(01.roundbox roundbox.cpp)
|
||||
CreateProject(01.LerpLine LerpLine.cpp)
|
||||
|
||||
CreateProject(02.roundbox roundbox.cpp)
|
||||
|
121
example/2dVector/LerpLine.cpp
Normal file
121
example/2dVector/LerpLine.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
// 主要用于测试几种2D插值算法
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/math/HalfFloat.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
-1.0, 0.0,
|
||||
1.0, 0.0,
|
||||
};
|
||||
|
||||
constexpr VkFormat PositionFormat=VF_V2F;
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT*4]=
|
||||
{ 1,0,0,1,
|
||||
0,1,0,1,
|
||||
0,0,1,1
|
||||
};
|
||||
|
||||
constexpr VkFormat ColorFormat=VF_V4F;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"VertexColor2D",PrimitiveType::Lines);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,PrimitiveType::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitAutoMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -36,10 +36,10 @@ private:
|
||||
Camera cam;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_color_material =nullptr;
|
||||
DeviceBuffer * ubo_line_config =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_color_material =nullptr;
|
||||
DeviceBuffer * ubo_line_config =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
@ -53,8 +53,8 @@ private:
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
//pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Alpha2D,Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
//pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),PrimitiveType::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Alpha2D,PrimitiveType::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
@ -116,9 +116,9 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
render_obj=db->CreateMesh(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
@ -42,7 +42,7 @@ private:
|
||||
Camera cam;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_rb_config =nullptr;
|
||||
@ -66,7 +66,7 @@ private:
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),PrimitiveType::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
@ -138,9 +138,9 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
render_obj=db->CreateMesh(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
199
example/Basic/BillboardTest.cpp
Normal file
199
example/Basic/BillboardTest.cpp
Normal file
@ -0,0 +1,199 @@
|
||||
// Billboard
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float position_data[3]=
|
||||
{
|
||||
0,0,0
|
||||
};
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
MaterialInstance * mi_billboard =nullptr;
|
||||
Pipeline * pipeline_billboard =nullptr;
|
||||
Mesh * ro_billboard =nullptr;
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitPlaneGridMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
{
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_plane_grid)return(false);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Luminance,VF_V1UN8);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitBillboardMP()
|
||||
{
|
||||
mtl::BillboardMaterialCreateConfig cfg(PrimitiveType::Billboard);
|
||||
|
||||
{
|
||||
cfg.fixed_size=true;
|
||||
|
||||
mi_billboard=CreateMaterialInstance(mtl::inline_material::Billboard2D,&cfg);
|
||||
if(!mi_billboard)return(false);
|
||||
|
||||
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D);
|
||||
if(!pipeline_billboard)return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
TextureManager *tex_manager=GetTextureManager();
|
||||
|
||||
texture=tex_manager->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!mi_billboard->GetMaterial()->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
Vector2u texture_size(texture->GetWidth(),texture->GetHeight());
|
||||
|
||||
mi_billboard->WriteMIData(texture_size);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
auto pc=GetPrimitiveCreater(mi_plane_grid);
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(500,500);
|
||||
pgci.sub_count.Set(5,5);
|
||||
|
||||
pgci.lum=128;
|
||||
pgci.sub_lum=192;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
auto pc=GetPrimitiveCreater(mi_billboard);
|
||||
|
||||
pc->Init("Billboard",1);
|
||||
|
||||
if(!pc->WriteVAB(VAN::Position,VF_V3F,position_data))
|
||||
return(false);
|
||||
|
||||
ro_billboard=db->CreateMesh(pc,mi_billboard,pipeline_billboard);
|
||||
|
||||
if(!ro_billboard)
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
CreateComponentInfo cci(GetSceneRoot());
|
||||
|
||||
CreateComponent<MeshComponent>(&cci,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
|
||||
CreateComponent<MeshComponent>(&cci,ro_billboard);
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitPlaneGridMP())
|
||||
return(false);
|
||||
|
||||
if(!InitBillboardMP())
|
||||
return(false);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("Billboard"),1280,720);
|
||||
}
|
18
example/Basic/CMakeLists.txt
Normal file
18
example/Basic/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
macro(CreateProject name)
|
||||
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_draw_triangle draw_triangle_use_UBO.cpp)
|
||||
CreateProject(02_auto_instance auto_instance.cpp)
|
||||
CreateProject(03_auto_merge_material_instance auto_merge_material_instance.cpp)
|
||||
|
||||
CreateProject(04_Billboard BillboardTest.cpp)
|
6
example/Basic/MaterialLoader/MaterialLoader.cpp
Normal file
6
example/Basic/MaterialLoader/MaterialLoader.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include<hgl/graph/mtl/MaterialLibrary.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
STD_MTL_NAMESPACE_END
|
112
example/Basic/auto_instance.cpp
Normal file
112
example/Basic/auto_instance.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr uint32_t TRIANGLE_NUMBER=12;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
0.0, 0.0,
|
||||
-0.1, 0.9,
|
||||
0.1, 0.9
|
||||
};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||
{
|
||||
{255,0,0,255},
|
||||
{0,255,0,255},
|
||||
{0,0,255,255}
|
||||
};
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
|
||||
CoordinateSystem2D::NDC,
|
||||
mtl::WithLocalToWorld::With);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8);
|
||||
|
||||
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor2D,&cfg,&vil_config);
|
||||
}
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
render_obj=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position, VF_V2F, position_data},
|
||||
{VAN::Color, VF_V4UN8, color_data }
|
||||
});
|
||||
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
double rad;
|
||||
|
||||
CreateComponentInfo cci(GetSceneRoot());
|
||||
|
||||
for(uint i=0;i<TRIANGLE_NUMBER;i++)
|
||||
{
|
||||
rad=deg2rad<double>((360.0f/double(TRIANGLE_NUMBER))*i); //这里一定要加<double>或<float>,否则结果用int保存会出现问题
|
||||
cci.mat=rotate(rad,Vector3f(0,0,1));
|
||||
|
||||
CreateComponent<MeshComponent>(&cci,render_obj);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
GetRenderer()->SetClearColor(Color4f(0.2f,0.2f,0.2f,1.0f));
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
|
||||
}
|
120
example/Basic/auto_merge_material_instance.cpp
Normal file
120
example/Basic/auto_merge_material_instance.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
0.0, 0.0,
|
||||
-0.1, 0.9,
|
||||
0.1, 0.9
|
||||
};
|
||||
|
||||
constexpr uint DRAW_OBJECT_COUNT=12;
|
||||
constexpr double TRI_ROTATE_ANGLE=360.0f/DRAW_OBJECT_COUNT;
|
||||
|
||||
#define USE_MATERIAL_FILE true //是否使用材质文件
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
Material * material =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Mesh * mesh;
|
||||
}render_obj[DRAW_OBJECT_COUNT]{};
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,CoordinateSystem2D::NDC,mtl::WithLocalToWorld::With);
|
||||
|
||||
#ifndef USE_MATERIAL_FILE
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg); //走程序内置材质创建函数
|
||||
material=db->CreateMaterial(mci);
|
||||
#else
|
||||
material=db->LoadMaterial("Std2D/PureColor2D",&cfg); //走材质文件加载
|
||||
#endif//USE_MATERIAL_FILE
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].mi=db->CreateMaterialInstance(material);
|
||||
|
||||
if(!render_obj[i].mi)
|
||||
return(false);
|
||||
|
||||
Color4f color=GetColor4f((COLOR)(i+int(COLOR::Blue)),1.0);
|
||||
|
||||
render_obj[i].mi->WriteMIData(color); //设置MaterialInstance的数据
|
||||
}
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
Primitive *prim=CreatePrimitive("Triangle",VERTEX_COUNT,material->GetDefaultVIL(),
|
||||
{{VAN::Position, VF_V2F, position_data}});
|
||||
|
||||
if(!prim)
|
||||
return(false);
|
||||
|
||||
db->Add(prim);
|
||||
|
||||
CreateComponentInfo cci(GetSceneRoot());
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].mesh=db->CreateMesh(prim,render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].mesh)
|
||||
return(false);
|
||||
|
||||
cci.mat=rotate(deg2rad<double>(TRI_ROTATE_ANGLE*i),AxisVector::Z);
|
||||
|
||||
CreateComponent<MeshComponent>(&cci,render_obj[i].mesh);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
|
||||
}
|
117
example/Basic/draw_triangle_use_UBO.cpp
Normal file
117
example/Basic/draw_triangle_use_UBO.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
static float position_data_float[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0.5, 0.25},
|
||||
{0.75, 0.75},
|
||||
{0.25, 0.75}
|
||||
};
|
||||
|
||||
static int16 position_data[VERTEX_COUNT][2]={};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
{
|
||||
255,0,0,255,
|
||||
0,255,0,255,
|
||||
0,0,255,255
|
||||
};
|
||||
|
||||
constexpr VAType POSITION_SHADER_FORMAT =VAT_IVEC2;
|
||||
constexpr VkFormat POSITION_DATA_FORMAT =VF_V2I16;
|
||||
|
||||
constexpr VkFormat COLOR_DATA_FORMAT =VF_V4UN8;
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * mesh_triangle =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
|
||||
CoordinateSystem2D::Ortho,
|
||||
mtl::WithLocalToWorld::With);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
cfg.position_format = POSITION_SHADER_FORMAT; //这里指定shader中使用ivec2当做顶点输入格式
|
||||
// ^
|
||||
// + 这上下两种格式要配套,否则会出错
|
||||
// v
|
||||
vil_config.Add(VAN::Position, POSITION_DATA_FORMAT); //这里指定VAB中使用RG16I当做顶点数据格式
|
||||
|
||||
vil_config.Add(VAN::Color, COLOR_DATA_FORMAT); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor2D,&cfg,&vil_config);
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
const auto ext=GetExtent();
|
||||
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data[i][0]=position_data_float[i][0]*ext.width;
|
||||
position_data[i][1]=position_data_float[i][1]*ext.height;
|
||||
}
|
||||
|
||||
mesh_triangle=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position,POSITION_DATA_FORMAT,position_data},
|
||||
{VAN::Color, COLOR_DATA_FORMAT, color_data}
|
||||
});
|
||||
|
||||
if(!mesh_triangle)
|
||||
return(false);
|
||||
|
||||
CreateComponentInfo cci(GetSceneRoot());
|
||||
|
||||
return CreateComponent<MeshComponent>(&cci,mesh_triangle); //创建一个静态网格组件
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("Draw triangle use UBO"));
|
||||
}
|
@ -1,7 +1,24 @@
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
|
||||
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
|
||||
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
|
||||
|
||||
add_subdirectory(Basic)
|
||||
add_subdirectory(Texture)
|
||||
add_subdirectory(LightBasic)
|
||||
add_subdirectory(Gizmo)
|
||||
|
||||
add_subdirectory(Vulkan)
|
||||
add_subdirectory(2dVector)
|
||||
add_subdirectory(GUI)
|
||||
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(WIN32)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example")
|
||||
endmacro()
|
||||
|
||||
|
@ -11,3 +11,4 @@ endmacro()
|
||||
|
||||
CreateProject(00.control_point_2d control_point_2d.cpp)
|
||||
CreateProject(01.align_test align_test.cpp)
|
||||
CreateProject(02.TextDrawTest DrawText.cpp)
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/type/StringList.h>
|
||||
#include<hgl/io/LoadString.h>
|
||||
#include<hgl/graph/font/TextRender.h>
|
||||
#include"VulkanAppFramework.h"
|
||||
|
||||
@ -8,14 +8,14 @@ using namespace hgl::graph;
|
||||
constexpr uint32_t SCREEN_WIDTH =1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=SCREEN_WIDTH/16*9;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
TextRender * text_render =nullptr;
|
||||
|
||||
TextPrimitive * text_primitive =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
@ -28,7 +28,7 @@ private:
|
||||
|
||||
bool InitTextRenderable()
|
||||
{
|
||||
UTF16String str;
|
||||
U16String str;
|
||||
|
||||
LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt"));
|
||||
|
||||
@ -44,7 +44,7 @@ private:
|
||||
if(!text_primitive)
|
||||
return(false);
|
||||
|
||||
render_obj=text_render->CreateRenderable(text_primitive);
|
||||
render_obj=text_render->CreateMesh(text_primitive);
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
@ -61,16 +61,21 @@ public:
|
||||
if(!InitTextRenderable())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32_t index)
|
||||
{
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
24
example/Gizmo/CMakeLists.txt
Normal file
24
example/Gizmo/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_SimplestAxis SimplestAxis.cpp)
|
||||
CreateProject(02_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(03_RayPicking RayPicking.cpp)
|
||||
|
||||
CreateProject(04_Gizmo3DTest GizmoTest.cpp
|
||||
Gizmo.h
|
||||
GizmoResource.h
|
||||
GizmoResource.cpp
|
||||
Gizmo3DMove.cpp
|
||||
#Gizmo3DScale.cpp
|
||||
#Gizmo3DRotate.cpp
|
||||
)
|
44
example/Gizmo/Gizmo.h
Normal file
44
example/Gizmo/Gizmo.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/component/Component.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
enum class GizmoColor:uint
|
||||
{
|
||||
Black=0,
|
||||
White,
|
||||
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
|
||||
Yellow,
|
||||
|
||||
ENUM_CLASS_RANGE(Black,Yellow)
|
||||
};
|
||||
|
||||
enum class GizmoShape:uint
|
||||
{
|
||||
Square=0, //方块
|
||||
Circle, //圆
|
||||
Cube, //立方体
|
||||
Sphere, //球
|
||||
Cone, //圆锥
|
||||
Cylinder, //圆柱
|
||||
Torus, //圆环
|
||||
|
||||
ENUM_CLASS_RANGE(Square,Torus)
|
||||
};
|
||||
|
||||
bool InitGizmoResource(RenderFramework *);
|
||||
void FreeGizmoResource();
|
||||
|
||||
ComponentDataPtr GetGizmoMeshComponentDataPtr(const GizmoShape &shape,const GizmoColor &color);
|
||||
|
||||
SceneNode *GetGizmoMoveNode();
|
||||
//SceneNode *GetGizmoScaleMesh();
|
||||
//SceneNode *GetGizmoRotateMesh();
|
||||
|
||||
VK_NAMESPACE_END
|
198
example/Gizmo/Gizmo3DMove.cpp
Normal file
198
example/Gizmo/Gizmo3DMove.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
Gizmo move
|
||||
|
||||
ref: Blender 4
|
||||
|
||||
|
||||
0 9-10
|
||||
*----------------->>>>
|
||||
|
|
||||
|
|
||||
| 5+
|
||||
| +6
|
||||
|
|
||||
|
|
||||
v
|
||||
|
||||
假设轴尺寸为10
|
||||
箭头长度为2,直径为2
|
||||
双轴调节正方形,长宽为1,位置为5,5
|
||||
|
||||
中心球半径为1
|
||||
*/
|
||||
|
||||
#include"GizmoResource.h"
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
* 移动 Gizmo 节点
|
||||
*/
|
||||
class GizmoMoveNode:public SceneNode
|
||||
{
|
||||
struct GizmoMoveAxis
|
||||
{
|
||||
MeshComponent *cylinder; //圆柱
|
||||
MeshComponent *cone; //圆锥
|
||||
MeshComponent *square; //双轴调节正方形
|
||||
};
|
||||
|
||||
MeshComponent *sphere=nullptr;
|
||||
GizmoMoveAxis axis[3]{}; //X,Y,Z 三个轴
|
||||
|
||||
public:
|
||||
|
||||
using SceneNode::SceneNode;
|
||||
|
||||
SceneNode *CreateNode()const override
|
||||
{
|
||||
return(new GizmoMoveNode);
|
||||
}
|
||||
|
||||
bool Init(RenderFramework *render_framework)
|
||||
{
|
||||
ComponentDataPtr sphere=GetGizmoMeshComponentDataPtr(GizmoShape::Sphere,GizmoColor::White);
|
||||
|
||||
ComponentDataPtr cylinder[3]
|
||||
{
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
ComponentDataPtr cone[3]
|
||||
{
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Cone,GizmoColor::Red),
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Cone,GizmoColor::Green),
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Cone,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
ComponentDataPtr square[3]=
|
||||
{
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Square,GizmoColor::Red),
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Square,GizmoColor::Green),
|
||||
GetGizmoMeshComponentDataPtr(GizmoShape::Square,GizmoColor::Blue)
|
||||
};
|
||||
|
||||
if(!sphere)
|
||||
return(false);
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
if(!cylinder[i])
|
||||
return(false);
|
||||
|
||||
if(!cone[i])
|
||||
return(false);
|
||||
|
||||
if(!square[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
CreateComponentInfo cci(this);
|
||||
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,sphere);
|
||||
|
||||
{
|
||||
Transform tm;
|
||||
|
||||
const Vector3f one_scale(1);
|
||||
const Vector3f square_scale(2);
|
||||
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,cylinder[2]); //Z 向上圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,cone[2]); //Z 向上圆锥
|
||||
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,square[2]);
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::Y,90);
|
||||
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,cylinder[0]); //X 向右圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,cone[0]); //X 向右圆锥
|
||||
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,square[0]);
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::X,-90);
|
||||
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,cylinder[1]); //Y 向前圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,cone[1]); //Y 向前圆锥
|
||||
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
|
||||
cci.mat=tm;
|
||||
render_framework->CreateComponent<MeshComponent>(&cci,square[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class GizmoMoveNode:public SceneNode
|
||||
|
||||
static GizmoMoveNode *sn_gizmo_move=nullptr;
|
||||
}//namespace
|
||||
|
||||
SceneNode *GetGizmoMoveNode()
|
||||
{
|
||||
return sn_gizmo_move;
|
||||
}
|
||||
|
||||
void ClearGizmoMoveNode()
|
||||
{
|
||||
SAFE_CLEAR(sn_gizmo_move);
|
||||
}
|
||||
|
||||
bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
{
|
||||
if(sn_gizmo_move)
|
||||
return(false);
|
||||
|
||||
sn_gizmo_move=new GizmoMoveNode;
|
||||
|
||||
if(!sn_gizmo_move->Init(render_framework))
|
||||
{
|
||||
delete sn_gizmo_move;
|
||||
sn_gizmo_move=nullptr;
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
80
example/Gizmo/Gizmo3DRotate.cpp
Normal file
80
example/Gizmo/Gizmo3DRotate.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include"GizmoResource.h"
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/TransformFaceToCamera.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
static StaticMesh *sm_gizmo_rotate=nullptr;
|
||||
}//namespace
|
||||
|
||||
StaticMesh *GetGizmoRotateStaticMesh()
|
||||
{
|
||||
return sm_gizmo_rotate;
|
||||
}
|
||||
|
||||
void ClearGizmoRotateStaticMesh()
|
||||
{
|
||||
SAFE_CLEAR(sm_gizmo_rotate);
|
||||
}
|
||||
|
||||
bool InitGizmoRotateStaticMesh()
|
||||
{
|
||||
Mesh *torus[4]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Blue),
|
||||
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::White),
|
||||
};
|
||||
|
||||
for(auto *r:torus)
|
||||
{
|
||||
if(!r)
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *root_node=new SceneNode();
|
||||
|
||||
{
|
||||
Transform tm;
|
||||
|
||||
tm.SetScale(GIZMO_ARROW_LENGTH);
|
||||
|
||||
root_node->Add(new SceneNode(tm,torus[0]));
|
||||
|
||||
tm.SetRotation(AXIS::Z,90);
|
||||
root_node->Add(new SceneNode(tm,torus[1]));
|
||||
|
||||
tm.SetRotation(AXIS::Y,90);
|
||||
root_node->Add(new SceneNode(tm,torus[2]));
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *white_torus=new SceneNode(scale(13),torus[3]);
|
||||
|
||||
white_torus->SetLocalNormal(AxisVector::X);
|
||||
|
||||
TransformFaceToCamera *rotate_white_torus_tfc=new TransformFaceToCamera();
|
||||
|
||||
//暂时因为无法传入Camera所以无法正确计算朝向,正在设计Actor/World结构
|
||||
|
||||
white_torus->GetTransform().AddTransform(rotate_white_torus_tfc);
|
||||
|
||||
root_node->Add(white_torus);
|
||||
}
|
||||
|
||||
sm_gizmo_rotate=CreateGizmoStaticMesh(root_node);
|
||||
}
|
||||
|
||||
if(!sm_gizmo_rotate)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
152
example/Gizmo/Gizmo3DScale.cpp
Normal file
152
example/Gizmo/Gizmo3DScale.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
Gizmo move
|
||||
|
||||
ref: Blender 4
|
||||
|
||||
|
||||
0 9-10
|
||||
*----------------->>>>
|
||||
|
|
||||
|
|
||||
| 5+
|
||||
| +6
|
||||
|
|
||||
|
|
||||
v
|
||||
|
||||
假设轴尺寸为10
|
||||
箭头长度为2,直径为2
|
||||
双轴调节正方形,长宽为1,位置为5,5
|
||||
|
||||
中心球半径为1
|
||||
*/
|
||||
|
||||
#include"GizmoResource.h"
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
static StaticMesh *sm_gizmo_scale=nullptr;
|
||||
}//namespace
|
||||
|
||||
StaticMesh *GetGizmoScaleStaticMesh()
|
||||
{
|
||||
return sm_gizmo_scale;
|
||||
}
|
||||
|
||||
void ClearGizmoScaleStaticMesh()
|
||||
{
|
||||
SAFE_CLEAR(sm_gizmo_scale);
|
||||
}
|
||||
|
||||
bool InitGizmoScaleStaticMesh()
|
||||
{
|
||||
Mesh *center_cube=GetGizmoMesh(GizmoShape::Cube,GizmoColor::White);
|
||||
Mesh *cylinder[3]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Mesh *cube[3]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Mesh *square[3]=
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
|
||||
};
|
||||
|
||||
if(!center_cube)
|
||||
return(false);
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
if(!cylinder[i])
|
||||
return(false);
|
||||
|
||||
if(!cube[i])
|
||||
return(false);
|
||||
|
||||
if(!square[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *root_node=new SceneNode();
|
||||
|
||||
root_node->Add(new SceneNode(scale(GIZMO_CENTER_SPHERE_RADIUS*2),center_cube));
|
||||
|
||||
{
|
||||
Transform tm;
|
||||
|
||||
const Vector3f one_scale(1);
|
||||
const Vector3f plane_scale(2);
|
||||
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,cube[2])); //Z 向上圆锥
|
||||
|
||||
tm.SetScale(plane_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
|
||||
root_node->Add(new SceneNode(tm,square[2]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::Y,90);
|
||||
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
|
||||
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
|
||||
root_node->Add(new SceneNode(tm,cube[0])); //X 向右圆锥
|
||||
|
||||
tm.SetScale(plane_scale);
|
||||
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,square[0]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::X,-90);
|
||||
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
|
||||
|
||||
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
|
||||
root_node->Add(new SceneNode(tm,cube[1])); //Y 向前圆锥
|
||||
|
||||
tm.SetScale(plane_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,square[1]));
|
||||
}
|
||||
}
|
||||
|
||||
sm_gizmo_scale=CreateGizmoStaticMesh(root_node);
|
||||
}
|
||||
|
||||
if(!sm_gizmo_scale)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
352
example/Gizmo/GizmoResource.cpp
Normal file
352
example/Gizmo/GizmoResource.cpp
Normal file
@ -0,0 +1,352 @@
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
#include"GizmoResource.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
bool InitGizmoMoveNode(RenderFramework *);
|
||||
void ClearGizmoMoveNode();
|
||||
|
||||
//bool InitGizmoScaleMesh();
|
||||
//void ClearGizmoScaleMesh();
|
||||
//
|
||||
//bool InitGizmoRotateMesh();
|
||||
//void ClearGizmoRotateMesh();
|
||||
|
||||
namespace
|
||||
{
|
||||
static RenderFramework *render_framework=nullptr;
|
||||
static RenderResource * gizmo_rr=nullptr;
|
||||
|
||||
struct GizmoResource
|
||||
{
|
||||
Material * mtl;
|
||||
MaterialInstance * mi[size_t(GizmoColor::RANGE_SIZE)];
|
||||
Pipeline * pipeline;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
PrimitiveCreater * prim_creater;
|
||||
};
|
||||
|
||||
static GizmoResource gizmo_line{};
|
||||
static GizmoResource gizmo_triangle{};
|
||||
|
||||
struct GizmoMesh
|
||||
{
|
||||
Primitive *prim;
|
||||
|
||||
struct
|
||||
{
|
||||
Mesh *mesh;
|
||||
MeshComponentData *mcd;
|
||||
ComponentDataPtr cdp;
|
||||
|
||||
public:
|
||||
|
||||
void Create(Primitive *prim,MaterialInstance *mi,Pipeline *ppl)
|
||||
{
|
||||
mesh=CreateMesh(prim,mi,ppl);
|
||||
mcd=new MeshComponentData(mesh);
|
||||
cdp=mcd;
|
||||
}
|
||||
}mesh_data[size_t(GizmoColor::RANGE_SIZE)];
|
||||
|
||||
public:
|
||||
|
||||
void Create(Primitive *p)
|
||||
{
|
||||
prim=p;
|
||||
|
||||
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
||||
mesh_data[i].Create(prim,gizmo_triangle.mi[i],gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
SAFE_CLEAR(prim)
|
||||
|
||||
for(auto &md:mesh_data)
|
||||
{
|
||||
md.cdp.unref();
|
||||
SAFE_CLEAR(md.mesh);
|
||||
}
|
||||
}
|
||||
};//class GizmoMesh
|
||||
|
||||
GizmoMesh gizmo_mesh[size_t(GizmoShape::RANGE_SIZE)]{};
|
||||
|
||||
void InitGizmoMesh(const GizmoShape &gs,Primitive *prim)
|
||||
{
|
||||
if(!prim)
|
||||
return;
|
||||
|
||||
gizmo_mesh[size_t(gs)].Create(prim);
|
||||
}
|
||||
|
||||
bool InitMI(GizmoResource *gr)
|
||||
{
|
||||
if(!gr||!gr->mtl)
|
||||
return(false);
|
||||
|
||||
Color4f color;
|
||||
|
||||
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
||||
{
|
||||
color=GetColor4f(gizmo_color[i],1.0);
|
||||
|
||||
gr->mi[i]=gizmo_rr->CreateMaterialInstance(gr->mtl,nullptr,&color);
|
||||
if(!gr->mi[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitGizmoResource2D()
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(false);
|
||||
|
||||
VulkanDevice *device=render_framework->GetDevice();
|
||||
VulkanDevAttr *dev_attr=device->GetDevAttr();
|
||||
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC3;
|
||||
|
||||
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(dev_attr,&cfg);
|
||||
|
||||
if(!mci)
|
||||
return(false);
|
||||
|
||||
gizmo_line.mtl=gizmo_rr->CreateMaterial("GizmoLine",mci);
|
||||
if(!gizmo_line.mtl)
|
||||
return(false);
|
||||
|
||||
gizmo_line.mtl->Update();
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D);
|
||||
|
||||
if(!gizmo_line.pipeline)
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(!InitMI(&gizmo_line))
|
||||
return(false);
|
||||
|
||||
{
|
||||
gizmo_line.vdm=new VertexDataManager(device,gizmo_line.mtl->GetDefaultVIL());
|
||||
|
||||
if(!gizmo_line.vdm)
|
||||
return(false);
|
||||
|
||||
if(!gizmo_line.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
||||
HGL_SIZE_1MB, //最大索引数量
|
||||
IndexType::U16)) //索引类型
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitGizmoResource3D()
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(false);
|
||||
|
||||
VulkanDevice *device=render_framework->GetDevice();
|
||||
VulkanDevAttr *dev_attr=device->GetDevAttr();
|
||||
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.material_instance=true;
|
||||
|
||||
mtl::MaterialCreateInfo *mci=CreateGizmo3D(dev_attr,&cfg);
|
||||
|
||||
if(!mci)
|
||||
return(false);
|
||||
|
||||
gizmo_triangle.mtl=gizmo_rr->CreateMaterial("GizmoTriangle",mci);
|
||||
if(!gizmo_triangle.mtl)
|
||||
return(false);
|
||||
|
||||
gizmo_triangle.mtl->Update();
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D);
|
||||
if(!gizmo_triangle.pipeline)
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(!InitMI(&gizmo_triangle))
|
||||
return(false);
|
||||
|
||||
{
|
||||
gizmo_triangle.vdm=new VertexDataManager(device,gizmo_triangle.mtl->GetDefaultVIL());
|
||||
|
||||
if(!gizmo_triangle.vdm)
|
||||
return(false);
|
||||
|
||||
if(!gizmo_triangle.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
||||
HGL_SIZE_1MB, //最大索引数量
|
||||
IndexType::U16)) //索引类型
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_triangle.prim_creater=new PrimitiveCreater(gizmo_triangle.vdm);
|
||||
|
||||
if(!gizmo_triangle.prim_creater)
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
InitGizmoMesh(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater));
|
||||
}
|
||||
|
||||
{
|
||||
CircleCreateInfo cci;
|
||||
|
||||
cci.center=Vector2f(0,0);
|
||||
cci.radius=Vector2f(0.5,0.5);
|
||||
cci.field_count=16;
|
||||
cci.has_center=false;
|
||||
|
||||
InitGizmoMesh(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci));
|
||||
}
|
||||
|
||||
{
|
||||
CubeCreateInfo cci;
|
||||
|
||||
cci.normal=true;
|
||||
cci.tangent=false;
|
||||
cci.tex_coord=false;
|
||||
|
||||
InitGizmoMesh(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci));
|
||||
}
|
||||
|
||||
{
|
||||
InitGizmoMesh(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16));
|
||||
}
|
||||
|
||||
{
|
||||
ConeCreateInfo cci;
|
||||
|
||||
cci.radius =GIZMO_CONE_RADIUS; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=3; //圆锥高度分割数
|
||||
|
||||
InitGizmoMesh(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci));
|
||||
}
|
||||
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =1; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =1; //圆柱半径
|
||||
|
||||
InitGizmoMesh(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci));
|
||||
}
|
||||
|
||||
{
|
||||
struct TorusCreateInfo tci;
|
||||
|
||||
tci.innerRadius=0.975;
|
||||
tci.outerRadius=1.0;
|
||||
tci.numberSlices=64;
|
||||
tci.numberStacks=8;
|
||||
|
||||
InitGizmoMesh(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci));
|
||||
}
|
||||
|
||||
ENUM_CLASS_FOR(GizmoShape,int,i)
|
||||
{
|
||||
if(!gizmo_mesh[i].prim)
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
}//namespace
|
||||
|
||||
bool InitGizmoResource(RenderFramework *rf)
|
||||
{
|
||||
if(!rf)
|
||||
return(false);
|
||||
|
||||
render_framework=rf;
|
||||
|
||||
gizmo_rr=render_framework->GetRenderResource();
|
||||
|
||||
VulkanDevice *device=render_framework->GetDevice();
|
||||
|
||||
if(!InitGizmoResource3D())
|
||||
return(false);
|
||||
|
||||
if(!InitGizmoResource2D())
|
||||
return(false);
|
||||
|
||||
InitGizmoMoveNode(rf);
|
||||
//InitGizmoScaleMesh();
|
||||
//InitGizmoRotateMesh();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void FreeGizmoResource()
|
||||
{
|
||||
//ClearGizmoRotateMesh();
|
||||
//ClearGizmoScaleMesh();
|
||||
ClearGizmoMoveNode();
|
||||
|
||||
for(GizmoMesh &gr:gizmo_mesh)
|
||||
gr.Clear();
|
||||
|
||||
SAFE_CLEAR(gizmo_triangle.prim_creater);
|
||||
SAFE_CLEAR(gizmo_triangle.vdm);
|
||||
|
||||
SAFE_CLEAR(gizmo_line.prim_creater);
|
||||
SAFE_CLEAR(gizmo_line.vdm);
|
||||
}
|
||||
|
||||
ComponentDataPtr GetGizmoMeshComponentDataPtr(const GizmoShape &shape,const GizmoColor &color)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(nullptr);
|
||||
|
||||
RANGE_CHECK_RETURN_NULLPTR(shape)
|
||||
RANGE_CHECK_RETURN_NULLPTR(color)
|
||||
|
||||
return gizmo_mesh[size_t(shape)].mesh_data[size_t(color)].cdp;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
41
example/Gizmo/GizmoResource.h
Normal file
41
example/Gizmo/GizmoResource.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include"Gizmo.h"
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class SceneNode;
|
||||
class PrimitiveCreater;
|
||||
class MeshComponent;
|
||||
|
||||
constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]=
|
||||
{
|
||||
COLOR::MozillaCharcoal,
|
||||
COLOR::BlanchedAlmond,
|
||||
|
||||
COLOR::BlenderAxisRed,
|
||||
COLOR::BlenderAxisGreen,
|
||||
COLOR::BlenderAxisBlue,
|
||||
|
||||
COLOR::BlenderYellow,
|
||||
};
|
||||
|
||||
constexpr const float GIZMO_ARROW_LENGTH =10.0f; ///<箭头整体长度
|
||||
constexpr const float GIZMO_CENTER_SPHERE_RADIUS=1.0f; ///<中心球半径
|
||||
|
||||
constexpr const float GIZMO_CONE_LENGTH =1.0f; ///<圆锥高度
|
||||
constexpr const float GIZMO_CONE_RADIUS =1.0f; ///<圆锥底部半径
|
||||
constexpr const float GIZMO_CONE_OFFSET =GIZMO_ARROW_LENGTH-(GIZMO_CONE_LENGTH/2.0f); ///<圆锥偏移量
|
||||
|
||||
constexpr const float GIZMO_CYLINDER_RADIUS =0.25f; ///<圆柱半径
|
||||
constexpr const float GIZMO_CYLINDER_LENGTH =GIZMO_ARROW_LENGTH-GIZMO_CENTER_SPHERE_RADIUS-GIZMO_CONE_LENGTH; ///<圆柱长度
|
||||
|
||||
constexpr const float GIZMO_CYLINDER_HALF_LENGTH=GIZMO_CYLINDER_LENGTH/2.0f; ///<圆柱一半长度
|
||||
constexpr const float GIZMO_CYLINDER_OFFSET =GIZMO_CYLINDER_HALF_LENGTH+GIZMO_CENTER_SPHERE_RADIUS; ///<圆柱偏移量
|
||||
|
||||
constexpr const float GIZMO_TWO_AXIS_OFFSET =5.0F; ///<二轴调节点偏移量(方片或圆)
|
||||
|
||||
Mesh *GetGizmoMesh(const GizmoShape &gs,const GizmoColor &);
|
||||
|
||||
VK_NAMESPACE_END
|
132
example/Gizmo/GizmoTest.cpp
Normal file
132
example/Gizmo/GizmoTest.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
#include<hgl/WorkManager.h>
|
||||
#include"Gizmo.h"
|
||||
#include<hgl/graph/Ray.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
const Vector3f GizmoPosition(0,0,0);
|
||||
|
||||
|
||||
///**
|
||||
//* 一种永远转向正面的变换节点
|
||||
//*/
|
||||
//class TransformBillboard:public TransformBase
|
||||
//{
|
||||
// CameraInfo *camera_info=nullptr;
|
||||
// bool face_to_camera=false;
|
||||
//
|
||||
// ViewportInfo *viewport_info=nullptr;
|
||||
// float fixed_scale=1.0;
|
||||
//
|
||||
//public:
|
||||
//
|
||||
// virtual void SetCameraInfo (CameraInfo * ci ){camera_info =ci;}
|
||||
// virtual void SetViewportInfo(ViewportInfo * vi ){viewport_info =vi;}
|
||||
//
|
||||
// virtual void SetFaceToCamera(bool ftc ){face_to_camera=ftc;}
|
||||
// virtual void SetFixedScale (const float size){fixed_scale =size;}
|
||||
//
|
||||
// virtual bool RefreshTransform(const Transform &tf=IdentityTransform) override
|
||||
// {
|
||||
// if(!camera_info)
|
||||
// {
|
||||
// return SceneNode::RefreshTransform(tf);
|
||||
// }
|
||||
//
|
||||
// if(face_to_camera)
|
||||
// {
|
||||
// LocalTransform.SetRotation(CalculateFacingRotationQuat(GetWorldPosition(),camera_info->view,AxisVector::X));
|
||||
// }
|
||||
//
|
||||
// if(viewport_info)
|
||||
// {
|
||||
// const float screen_height=viewport_info->GetViewportHeight();
|
||||
//
|
||||
// const Vector4f pos=camera_info->Project(GetWorldPosition());
|
||||
//
|
||||
// LocalTransform.SetScale(pos.w*fixed_scale/screen_height);
|
||||
// }
|
||||
//
|
||||
// return SceneNode::RefreshTransform(tf);
|
||||
// }
|
||||
//};//class BillboardSceneNode:public SceneNode
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
SceneNode *sm_move=nullptr;
|
||||
//StaticMesh *sm_rotate=nullptr;
|
||||
//StaticMesh *sm_scale=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitGizmo()
|
||||
{
|
||||
if(!InitGizmoResource(GetRenderFramework()))
|
||||
return(false);
|
||||
|
||||
sm_move =GetGizmoMoveNode();
|
||||
//sm_rotate =GetGizmoRotateStaticMesh();
|
||||
//sm_scale =GetGizmoScaleStaticMesh();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void InitGizmoSceneTree()
|
||||
{
|
||||
SceneNode *root=GetSceneRoot();
|
||||
|
||||
root->Add(sm_move->Duplication());
|
||||
//root.Add(Duplication(sm_rotate->GetScene()));
|
||||
//root.CreateSubNode(sm_scale->GetScene());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitGizmo())
|
||||
return(false);
|
||||
|
||||
InitGizmoSceneTree();
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
FreeGizmoResource();
|
||||
}
|
||||
|
||||
//void BuildCommandBuffer(uint32 index) override
|
||||
//{
|
||||
// camera_control->Refresh();
|
||||
//
|
||||
// const CameraInfo *ci=camera_control->GetCameraInfo();
|
||||
// const ViewportInfo *vi=GetViewportInfo();
|
||||
|
||||
// const float screen_height=vi->GetViewportHeight();
|
||||
|
||||
// const Vector4f pos=ci->Project(GizmoPosition);
|
||||
|
||||
// //{
|
||||
// // Transform tm;
|
||||
|
||||
// // tm.SetScale(pos.w*16.0f/screen_height);
|
||||
|
||||
// // root.SetLocalTransform(tm);
|
||||
// //}
|
||||
//}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("Gizmo"),1280,720);
|
||||
}
|
137
example/Gizmo/PlaneGrid3D.cpp
Normal file
137
example/Gizmo/PlaneGrid3D.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
// PlaneGrid3D
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
MaterialInstance * material_instance[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Luminance,VF_V1UN8);
|
||||
|
||||
Color4f GridColor;
|
||||
COLOR ce=COLOR::BlenderAxisRed;
|
||||
|
||||
for(uint i=0;i<3;i++)
|
||||
{
|
||||
GridColor=GetColor4f(ce,1.0);
|
||||
|
||||
material_instance[i]=db->CreateMaterialInstance(material,&vil_config,&GridColor);
|
||||
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=180;
|
||||
pgci.sub_lum=255;
|
||||
|
||||
auto pc=GetPrimitiveCreater(material_instance[0]);
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
|
||||
|
||||
return prim_plane_grid;
|
||||
}
|
||||
|
||||
void Add(SceneNode *parent_node,MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(prim_plane_grid,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return;
|
||||
|
||||
CreateComponentInfo cci(parent_node,mat);
|
||||
|
||||
CreateComponent<MeshComponent>(&cci,ri);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
||||
|
||||
Add(scene_root,material_instance[0],Matrix4f(1.0f));
|
||||
Add(scene_root,material_instance[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(scene_root,material_instance[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("PlaneGrid3D"),1280,720);
|
||||
}
|
204
example/Gizmo/RayPicking.cpp
Normal file
204
example/Gizmo/RayPicking.cpp
Normal file
@ -0,0 +1,204 @@
|
||||
// RayPicking
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float position_data[2][3]=
|
||||
{
|
||||
{100,100,100},
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static uint8 lumiance_data[2]={255,255};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Material * mtl_line =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
Pipeline * pipeline_line =nullptr;
|
||||
Primitive * prim_line =nullptr;
|
||||
VABMap * prim_line_vab_map =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Luminance,VF_V1UN8);
|
||||
|
||||
{
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_plane_grid)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
{
|
||||
cfg.position_format=VAT_VEC3;
|
||||
|
||||
mtl_line=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_line)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(mtl_line,&vil_config,&yellow_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
pipeline_line=CreatePipeline(mi_line,InlinePipeline::Solid3D);
|
||||
|
||||
if(!pipeline_line)
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Mesh *Add(SceneNode *parent_node,Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Mesh failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
CreateComponentInfo cci(parent_node);
|
||||
|
||||
CreateComponent<MeshComponent>(&cci,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
auto pc=GetPrimitiveCreater(mi_plane_grid);
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=128;
|
||||
pgci.sub_lum=196;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
prim_line=CreatePrimitive("RayLine",2,mi_line->GetVIL(),
|
||||
{
|
||||
{VAN::Position, VF_V3F,position_data},
|
||||
{VAN::Luminance,VF_V1UN8,lumiance_data}
|
||||
});
|
||||
|
||||
prim_line_vab_map=prim_line->GetVABMap(VAN::Position);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
||||
|
||||
Add(scene_root,prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
Add(scene_root,prim_line,mi_line,pipeline_line);
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Tick(double) override
|
||||
{
|
||||
Vector2i mouse_position;
|
||||
|
||||
if(!GetMouseCoord(&mouse_position))
|
||||
return;
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
const CameraInfo *ci=camera_control->GetCameraInfo();
|
||||
const ViewportInfo *vi=camera_control->GetViewportInfo();
|
||||
|
||||
ray.Set(mouse_position,ci,vi); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
prim_line_vab_map->Write(&pos, //更新VAB上这个点的位置
|
||||
1); //这里的1代表的数据数量,不是字节数
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("RayPicking"),1280,720);
|
||||
}
|
102
example/Gizmo/SimplestAxis.cpp
Normal file
102
example/Gizmo/SimplestAxis.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
// SimplestAxis
|
||||
// 直接从0,0,0向三个方向画一条直线,用于确认坐标轴方向
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_axis =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor3D,&cfg);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
auto pc=GetPrimitiveCreater(material_instance);
|
||||
|
||||
inline_geometry::AxisCreateInfo aci;
|
||||
|
||||
prim_axis=CreateAxis(pc,&aci);
|
||||
|
||||
return prim_axis;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(prim_axis,material_instance,pipeline);
|
||||
|
||||
CreateComponentInfo cci(GetSceneRoot());
|
||||
|
||||
CreateComponent<MeshComponent>(&cci,ri);
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_axis);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("SimplestAxis"),1280,720);
|
||||
}
|
333
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
333
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
@ -0,0 +1,333 @@
|
||||
// BlinnPhong direction light
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/BlinnPhong.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
|
||||
static mtl::blinnphong::SunLight sun_light=
|
||||
{
|
||||
Vector4f(1,1,1,0), //direction
|
||||
Vector4f(1,0.95,0.9,1) //color
|
||||
};
|
||||
|
||||
constexpr const COLOR AxisColor[4]=
|
||||
{
|
||||
//COLOR::Red, //X轴颜色
|
||||
//COLOR::Green, //Y轴颜色
|
||||
//COLOR::Blue, //Z轴颜色
|
||||
COLOR::White, //全局颜色
|
||||
COLOR::GhostWhite,
|
||||
COLOR::BlanchedAlmond,
|
||||
COLOR::AntiqueWhite
|
||||
};
|
||||
|
||||
constexpr const os_char *tex_filename[]=
|
||||
{
|
||||
OS_TEXT("eucalyptus-cross-versailles.Tex2D"),
|
||||
OS_TEXT("tints-ashton-green-stretcher.Tex2D"),
|
||||
OS_TEXT("worn-clay-cobble-in-desert-stretcher.Tex2D"),
|
||||
OS_TEXT("plain-grey-sheer.Tex2D"),
|
||||
};
|
||||
|
||||
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private: //plane grid
|
||||
|
||||
Material * mtl_vertex_lum =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * p_line =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
DeviceBuffer * ubo_sun =nullptr;
|
||||
|
||||
|
||||
Texture2DArray * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_blinnphong =nullptr;
|
||||
PrimitiveCreater * pc_blinnphong =nullptr;
|
||||
VertexDataManager * vdm_blinnphong =nullptr;
|
||||
|
||||
MaterialInstance * mi_blinnphong[4]{};
|
||||
Pipeline * p_blinnphong =nullptr;
|
||||
|
||||
Primitive * prim_sphere =nullptr;
|
||||
Primitive * prim_cone =nullptr;
|
||||
Primitive * prim_cylinder =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->CreateTexture2DArray( "SeamlessBackground",
|
||||
256,256, ///<纹理尺寸
|
||||
TexCount, ///<纹理层数
|
||||
PF_BC1_RGBUN, ///<纹理格式
|
||||
false); ///<是否自动产生mipmaps
|
||||
|
||||
if(!texture)return(false);
|
||||
|
||||
OSString filename;
|
||||
|
||||
for(uint i=0;i<TexCount;i++)
|
||||
{
|
||||
filename=filesystem::MergeFilename(OS_TEXT("res/image/seamless"),tex_filename[i]);
|
||||
|
||||
if(!db->LoadTexture2DToArray(texture,i,filename))
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVertexLumMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"VertexLuminance3D",PrimitiveType::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_vertex_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_vertex_lum)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_vertex_lum,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
p_line=CreatePipeline(mtl_vertex_lum,InlinePipeline::Solid3D,PrimitiveType::Lines);
|
||||
|
||||
if(!p_line)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateBlinnPhongUBO()
|
||||
{
|
||||
ubo_sun=db->CreateUBO("sun",sizeof(sun_light),&sun_light);
|
||||
if(!ubo_sun)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitBlinnPhongSunLightMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"BlinnPhong3D",PrimitiveType::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.material_instance=true;
|
||||
|
||||
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColorTexture",&cfg);
|
||||
if(!mtl_blinnphong)return(false);
|
||||
|
||||
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_blinnphong->Update();
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!mtl_blinnphong->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
struct MIData
|
||||
{
|
||||
Color4f color;
|
||||
uint32 tex_id[4];
|
||||
}mi_data;
|
||||
|
||||
constexpr const uint MIDataStride=sizeof(MIData);
|
||||
|
||||
for(uint i=0;i<4;i++)
|
||||
{
|
||||
mi_data.color=GetColor4f(AxisColor[i],4);
|
||||
mi_data.tex_id[0]=i;
|
||||
|
||||
mi_blinnphong[i]=db->CreateMaterialInstance(mtl_blinnphong, //材质
|
||||
nullptr, //顶点输入配置,这里使用nullptr,即代表会使用默认配置,那么结果将等同于上面的mtl_blinnphong->GetDefaultVIL()
|
||||
&mi_data); //材质实例参数
|
||||
if(!mi_blinnphong[i])return(false);
|
||||
}
|
||||
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,PrimitiveType::Triangles);
|
||||
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVDMAndPC()
|
||||
{
|
||||
vdm_blinnphong=new VertexDataManager(device,mtl_blinnphong->GetDefaultVIL());
|
||||
if(!vdm_blinnphong->Init( 1024*1024, //VAB最大容量
|
||||
1024*1024, //索引最大容量
|
||||
IndexType::U16)) //索引类型
|
||||
{
|
||||
delete vdm_blinnphong;
|
||||
vdm_blinnphong=nullptr;
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
pc_blinnphong=new PrimitiveCreater(vdm_blinnphong);
|
||||
//pc_blinnphong=new PrimitiveCreater(device,mtl_blinnphong->GetDefaultVIL());
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
//Plane Grid
|
||||
//{
|
||||
// struct PlaneGridCreateInfo pgci;
|
||||
|
||||
// pgci.grid_size.Set(32,32);
|
||||
// pgci.sub_count.Set(8,8);
|
||||
|
||||
// pgci.lum=0.5;
|
||||
// pgci.sub_lum=0.75;
|
||||
|
||||
// prim_plane_grid=CreatePlaneGrid(pc_blinnphong,mtl_vertex_lum->GetDefaultVIL(),&pgci);
|
||||
//}
|
||||
|
||||
//Sphere
|
||||
prim_sphere=CreateSphere(pc_blinnphong,16);
|
||||
|
||||
//Cone
|
||||
{
|
||||
struct ConeCreateInfo cci;
|
||||
|
||||
cci.radius =1; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=8; //圆锥高度分割数
|
||||
|
||||
prim_cone=CreateCone(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
//Cyliner
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =1.25; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =1.25f; //圆柱半径
|
||||
|
||||
prim_cylinder=CreateCylinder(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Mesh *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat=Identity4f)
|
||||
{
|
||||
if(!r)
|
||||
return(nullptr);
|
||||
if(!mi)
|
||||
return(nullptr);
|
||||
if(!p)
|
||||
return(nullptr);
|
||||
|
||||
Mesh *ri=db->CreateMesh(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR("Create Mesh failed! Primitive: "+r->GetName());
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
//Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
|
||||
|
||||
Add(prim_sphere, mi_blinnphong[0],p_blinnphong,translate(Vector3f(0,0,2)));
|
||||
|
||||
Add(prim_cone, mi_blinnphong[1],p_blinnphong);
|
||||
Add(prim_cylinder, mi_blinnphong[2],p_blinnphong,translate(Vector3f(0,0,-5)));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
//if(!InitVertexLumMP())
|
||||
// return(false);
|
||||
|
||||
if(!CreateBlinnPhongUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitBlinnPhongSunLightMP())
|
||||
return(false);
|
||||
|
||||
if(!InitVDMAndPC())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_cone)
|
||||
SAFE_CLEAR(prim_cylinder)
|
||||
SAFE_CLEAR(prim_sphere)
|
||||
SAFE_CLEAR(prim_plane_grid)
|
||||
|
||||
SAFE_CLEAR(pc_blinnphong)
|
||||
SAFE_CLEAR(vdm_blinnphong)
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
13
example/LightBasic/CMakeLists.txt
Normal file
13
example/LightBasic/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Light Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_BlinnPhongDirectionLight BlinnPhongDirectionLight.cpp)
|
16
example/Texture/CMakeLists.txt
Normal file
16
example/Texture/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Texture")
|
||||
endmacro()
|
||||
|
||||
CreateProject(05_texture_format texture_format_list.cpp)
|
||||
CreateProject(06_texture_quad texture_quad.cpp)
|
||||
CreateProject(07_texture_rect texture_rect.cpp)
|
||||
CreateProject(08_texture_rect_array texture_rect_array.cpp)
|
@ -1,4 +1,5 @@
|
||||
#include<iostream>
|
||||
#include<iomanip>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKInstance.h>
|
||||
@ -8,32 +9,6 @@ using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_USING;
|
||||
|
||||
constexpr char *texture_compress_name[]=
|
||||
{
|
||||
"NONE",
|
||||
"S3TC",
|
||||
"PVRTC",
|
||||
"ETC1",
|
||||
"ETC2",
|
||||
"EAC",
|
||||
"ATC",
|
||||
"ASTC",
|
||||
"YUV"
|
||||
};
|
||||
|
||||
constexpr char *data_type_name[]
|
||||
{
|
||||
"NONE",
|
||||
"UNORM",
|
||||
"SNORM",
|
||||
"USCALED",
|
||||
"SSCALED",
|
||||
"UINT",
|
||||
"SINT",
|
||||
"UFLOAT",
|
||||
"SFLOAT",
|
||||
"SRGB"
|
||||
};//
|
||||
|
||||
VulkanInstance *InitVulkanInstance()
|
||||
{
|
||||
@ -63,8 +38,8 @@ int main(int,char **)
|
||||
{
|
||||
Window * win =nullptr;
|
||||
VulkanInstance * inst =nullptr;
|
||||
GPUDevice * device =nullptr;
|
||||
const GPUPhysicalDevice * physical_device =nullptr;
|
||||
VulkanDevice * device =nullptr;
|
||||
const VulkanPhyDevice * physical_device =nullptr;
|
||||
|
||||
inst=InitVulkanInstance();
|
||||
|
||||
@ -86,35 +61,36 @@ int main(int,char **)
|
||||
|
||||
for(uint32_t i=0;i<count;i++)
|
||||
{
|
||||
std::cout<<i<<". ";
|
||||
std::cout<<std::setw(4)<<i<<". ";
|
||||
|
||||
std::cout<<" Format [ID:"<<vf->format<<"]["<<vf->name<<"] ";
|
||||
std::cout<<"Format [ID:"<<std::setw(10)<<vf->format<<"]["<<std::setw(16)<<vf->name<<"]";
|
||||
|
||||
if(vf->compress_type!=TextureCompressType::NONE)
|
||||
std::cout<<"use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
|
||||
else
|
||||
std::cout<<vf->bytes<<" bytes/pixel.";
|
||||
|
||||
if(vf->depth!=VulkanNumberType::NONE)
|
||||
std::cout<<"[Depth:"<<data_type_name[size_t(vf->depth)]<<"]";
|
||||
if(vf->depth!=VulkanBaseType::NONE)
|
||||
std::cout<<"[ Depth:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->depth)]<<"]";
|
||||
|
||||
if(vf->stencil!=VulkanNumberType::NONE)
|
||||
std::cout<<"[Stencil:"<<data_type_name[size_t(vf->stencil)]<<"]";
|
||||
if(vf->stencil!=VulkanBaseType::NONE)
|
||||
std::cout<<"[Stencil:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->stencil)]<<"]";
|
||||
|
||||
if((vf->depth==VulkanNumberType::NONE)
|
||||
&&(vf->stencil==VulkanNumberType::NONE))
|
||||
std::cout<<"[Color:"<<data_type_name[size_t(vf->color)]<<"]";
|
||||
if((vf->depth==VulkanBaseType::NONE)
|
||||
&&(vf->stencil==VulkanBaseType::NONE))
|
||||
std::cout<<"[ Color:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->color)]<<"]";
|
||||
|
||||
{
|
||||
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
|
||||
|
||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
std::cout<<"[Optimal]";
|
||||
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
std::cout<<"[Linear]";
|
||||
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
std::cout<<"[Buffer]";
|
||||
char olb[]="[ ]";
|
||||
|
||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[1]='O';
|
||||
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='L';
|
||||
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='B';
|
||||
|
||||
std::cout<<olb;
|
||||
}
|
||||
|
||||
if(vf->compress_type!=TextureCompressType::NONE)
|
||||
std::cout<<" use "<<TextureCompressTypeName[size_t(vf->compress_type)]<<" compress.";
|
||||
else
|
||||
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";
|
||||
|
||||
std::cout<<std::endl;
|
||||
|
||||
@ -124,4 +100,4 @@ int main(int,char **)
|
||||
delete inst;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,17 +1,18 @@
|
||||
// 2.texture_rect
|
||||
// 该示例是1.indices_rect的进化,演示在矩形上贴上贴图
|
||||
// 画一个带纹理的四边形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
@ -21,26 +22,18 @@ constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0, 0},
|
||||
{SCREEN_WIDTH, 0},
|
||||
{0, SCREEN_HEIGHT},
|
||||
{SCREEN_WIDTH, SCREEN_HEIGHT}
|
||||
{-1, -1},
|
||||
{ 1, -1},
|
||||
{ 1, 1},
|
||||
{-1, 1},
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{1,0},
|
||||
{0,1},
|
||||
{1,1}
|
||||
};
|
||||
|
||||
constexpr uint32_t INDEX_COUNT=6;
|
||||
|
||||
constexpr uint16 index_data[INDEX_COUNT]=
|
||||
{
|
||||
0,1,3,
|
||||
0,3,2
|
||||
{1,1},
|
||||
{0,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
@ -49,22 +42,28 @@ private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * renderable =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/Texture2D"));
|
||||
if(!material_instance)return(false);
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"PureTexture2D",PrimitiveType::Fan);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material=db->LoadMaterial("Std2D/PureTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,PrimitiveType::Fan); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
@ -73,23 +72,28 @@ private:
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Quad",VERTEX_COUNT);
|
||||
|
||||
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V2F,VERTEX_COUNT,tex_coord_data)))return(false);
|
||||
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -105,16 +109,16 @@ public:
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
136
example/Texture/texture_rect.cpp
Normal file
136
example/Texture/texture_rect.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
constexpr float position_data[4]=
|
||||
{
|
||||
0, //left
|
||||
0, //top
|
||||
1, //right
|
||||
1 //bottom
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,
|
||||
1,1
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"RectTexture2D",PrimitiveType::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material=db->LoadMaterial("Std2D/RectTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,PrimitiveType::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Rectangle",1);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
216
example/Texture/texture_rect_array.cpp
Normal file
216
example/Texture/texture_rect_array.cpp
Normal file
@ -0,0 +1,216 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/Filename.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
//Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
float position_data[4]=
|
||||
{
|
||||
0, //left
|
||||
0, //top
|
||||
1, //right
|
||||
1 //bottom
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,
|
||||
1,1
|
||||
};
|
||||
|
||||
constexpr const os_char *tex_filename[]=
|
||||
{
|
||||
OS_TEXT("001-online resume.Tex2D"),
|
||||
OS_TEXT("002-salary.Tex2D"),
|
||||
OS_TEXT("003-application.Tex2D"),
|
||||
OS_TEXT("004-job interview.Tex2D")
|
||||
};
|
||||
|
||||
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Texture2DArray * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
DeviceBuffer * tex_id_ubo =nullptr;
|
||||
Primitive * prim_rectangle =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Mesh * mesh;
|
||||
}render_obj[TexCount]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->CreateTexture2DArray( "freepik icons",
|
||||
512,512, ///<纹理尺寸
|
||||
TexCount, ///<纹理层数
|
||||
PF_BC1_RGBAUN, ///<纹理格式
|
||||
false); ///<是否自动产生mipmaps
|
||||
|
||||
if(!texture)return(false);
|
||||
|
||||
OSString filename;
|
||||
|
||||
for(uint i=0;i<TexCount;i++)
|
||||
{
|
||||
filename=filesystem::MergeFilename(OS_TEXT("res/image/icon/freepik"),tex_filename[i]);
|
||||
|
||||
if(!db->LoadTexture2DToArray(texture,i,filename))
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"RectTexture2DArray",PrimitiveType::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std2D/RectTexture2DArray",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,PrimitiveType::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].mi=db->CreateMaterialInstance(material);
|
||||
|
||||
if(!render_obj[i].mi)
|
||||
return(false);
|
||||
|
||||
render_obj[i].mi->WriteMIData(i); //设置MaterialInstance的数据
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material->GetDefaultVIL());
|
||||
|
||||
rpc.Init("Rectangle",1);
|
||||
|
||||
position_data[2]=1.0f/float(TexCount);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
prim_rectangle=rpc.Create();
|
||||
|
||||
Vector3f offset(1.0f/float(TexCount),0,0);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].mesh=db->CreateMesh(prim_rectangle,render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].mesh)
|
||||
return(false);
|
||||
|
||||
offset.x=position_data[2]*float(i);
|
||||
|
||||
render_root.CreateSubNode(translate(offset),render_obj[i].mesh);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_rectangle);
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH*TexCount,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
|
@ -10,41 +10,32 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan/${group}")
|
||||
endmacro()
|
||||
|
||||
CreateProject("Basic" 1st_triangle first_triangle.cpp)
|
||||
CreateProject("Basic" 2nd_triangle second_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_triangle third_triangle.cpp)
|
||||
CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
CreateProject("Basic" indices_rect indices_rect.cpp)
|
||||
CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
|
||||
CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
|
||||
#CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
|
||||
CreateProject("Texture" TextureFormat TextureFormat.cpp)
|
||||
CreateProject("Texture" texture_rect texture_rect.cpp)
|
||||
#CreateProject("Texture" HQFilterTexture HQFilterTexture.cpp)
|
||||
#CreateProject(06.Geometry2D Geometry2D.cpp)
|
||||
|
||||
CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
|
||||
CreateProject("Tile" DrawTile DrawTile.cpp)
|
||||
CreateProject("Tile" DrawText DrawText.cpp)
|
||||
#CreateProject("Tile" DrawTile DrawTile.cpp)
|
||||
#CreateProject("Tile" DrawText DrawText.cpp)
|
||||
|
||||
CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
|
||||
#CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
|
||||
|
||||
CreateProject("Scene" SceneTree SceneTree.cpp)
|
||||
#CreateProject("Scene" SceneTree SceneTree.cpp)
|
||||
#CreateProject("Scene" LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
|
||||
CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
|
||||
#CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
|
||||
|
||||
CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
|
||||
CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
|
||||
#CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
|
||||
#CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
|
||||
|
||||
CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
|
||||
#CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
|
||||
|
||||
#CreateProject(12.PBRBasic PBRBasic.cpp)
|
||||
#CreateProject(12.Deferred Deferred.cpp)
|
||||
CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
|
||||
#CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
|
||||
#CreateProject(14.AutoMaterial auto_material.cpp)
|
||||
|
||||
CreateProject("Texture" Cubemap Cubemap.cpp)
|
||||
CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
|
||||
CreateProject("Picking" RayPicking RayPicking.cpp)
|
||||
#CreateProject("Texture" Cubemap Cubemap.cpp)
|
||||
#CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
|
||||
#CreateProject("Picking" RayPicking RayPicking.cpp)
|
||||
|
||||
CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)
|
||||
#CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
|
@ -103,7 +103,7 @@ private:
|
||||
|
||||
const VkFormat GetCandidateFormat(const VkFormat *fmt_list, const uint count)
|
||||
{
|
||||
auto pd = device->GetPhysicalDevice();
|
||||
auto pd = device->GetPhyDevice();
|
||||
|
||||
for (uint i = 0; i < count; i++)
|
||||
if (pd->IsColorAttachmentOptimal(fmt_list[i]))
|
||||
@ -118,7 +118,7 @@ private:
|
||||
|
||||
const VkFormat GetDepthCandidateFormat()
|
||||
{
|
||||
auto pd = device->GetPhysicalDevice();
|
||||
auto pd = device->GetPhyDevice();
|
||||
|
||||
for (VkFormat fmt : depth_candidate_format)
|
||||
if (pd->IsDepthAttachmentOptimal(fmt))
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKImageView.h>
|
||||
@ -16,7 +16,7 @@ using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
@ -139,7 +139,7 @@ private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
auto da=device->GetDeviceAttribute();
|
||||
auto da=device->GetDevAttr();
|
||||
|
||||
if(da->debug_maker)
|
||||
{
|
||||
@ -160,7 +160,7 @@ private:
|
||||
|
||||
fbi.SetExtent(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||
|
||||
gbuffer.rt=device->CreateRenderTarget(&fbi);
|
||||
gbuffer.rt=device->CreateRT(&fbi);
|
||||
|
||||
if(!gbuffer.rt)return(false);
|
||||
|
||||
@ -172,7 +172,7 @@ private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
auto da=device->GetDeviceAttribute();
|
||||
auto da=device->GetDevAttr();
|
||||
|
||||
VkQueue q=*(gbuffer.rt->GetQueue());
|
||||
VkFramebuffer fbo= gbuffer.rt->GetFramebuffer()->GetFramebuffer();
|
||||
@ -229,7 +229,7 @@ private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
auto da=device->GetDeviceAttribute();
|
||||
auto da=device->GetDevAttr();
|
||||
|
||||
if(da->debug_maker)
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
|
@ -1,87 +0,0 @@
|
||||
// 全屏三角形
|
||||
// 该范例用于演示使用索引画一个覆盖全屏的三角形,但是不传递任何顶点信息,顶点坐标在vertex shader中通过gl_VertexIndex计算出来。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable *renderable =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/fullscreen"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(3);
|
||||
if(!primitive)return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
// 4.Geometry3D
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList *render_list=nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid[3];
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
if(!material)return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
if(!material_instance)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
void CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.coord[0]=Vector3f(-100,-100,0);
|
||||
pgci.coord[1]=Vector3f( 100,-100,0);
|
||||
pgci.coord[2]=Vector3f( 100, 100,0);
|
||||
pgci.coord[3]=Vector3f(-100, 100,0);
|
||||
|
||||
pgci.step.x=32;
|
||||
pgci.step.y=32;
|
||||
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
|
||||
pgci.color.Set(0.5,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
|
||||
ro_plane_grid[0]=CreatePlaneGrid(db,vil,&pgci);
|
||||
|
||||
pgci.color.Set(0,0.5,0,1);
|
||||
pgci.side_color.Set(0,1,0,1);
|
||||
|
||||
ro_plane_grid[1]=CreatePlaneGrid(db,vil,&pgci);
|
||||
|
||||
pgci.color.Set(0,0,0.5,1);
|
||||
pgci.side_color.Set(0,0,1,1);
|
||||
ro_plane_grid[2]=CreatePlaneGrid(db,vil,&pgci);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid[0],Matrix4f(1.0f));
|
||||
Add(ro_plane_grid[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(ro_plane_grid[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
camera->pos=Vector3f(200,200,200);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(camera->info,&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
CreateRenderObject();
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
@ -109,7 +109,7 @@ private:
|
||||
VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
||||
0.0f,
|
||||
VK_TRUE,
|
||||
device->GetPhysicalDevice()->GetMaxSamplerAnisotropy(),
|
||||
device->GetPhyDevice()->GetMaxSamplerAnisotropy(),
|
||||
false,
|
||||
VK_COMPARE_OP_NEVER,
|
||||
0.0f,
|
||||
|
@ -1,103 +0,0 @@
|
||||
// Instance Triangle
|
||||
|
||||
// 基本的Instance绘制测试用例,不使用场景树
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_SIZE=512;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{0.25,-0.75},
|
||||
{0,-1}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{ {1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
|
||||
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -80,7 +80,7 @@ public:
|
||||
{
|
||||
FramebufferInfo fbi(UPF_RGBA8,OFFSCREEN_SIZE,OFFSCREEN_SIZE);
|
||||
|
||||
os.render_taget=device->CreateRenderTarget(&fbi);
|
||||
os.render_taget=device->CreateRT(&fbi);
|
||||
if(!os.render_taget)return(false);
|
||||
|
||||
os.command_buffer=device->CreateRenderCommandBuffer();
|
||||
|
@ -1,191 +0,0 @@
|
||||
// 18.RayPicking
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
static float position_data[2][3]=
|
||||
{
|
||||
{100,100,100},
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static float color_data[2][4]=
|
||||
{
|
||||
{1,1,0,1},
|
||||
{1,1,0,1}
|
||||
};
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid =nullptr;
|
||||
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
VBO * vbo_pos =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
if(!material)return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
if(!material_instance)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.coord[0]=Vector3f(-100,-100,0);
|
||||
pgci.coord[1]=Vector3f( 100,-100,0);
|
||||
pgci.coord[2]=Vector3f( 100, 100,0);
|
||||
pgci.coord[3]=Vector3f(-100, 100,0);
|
||||
|
||||
pgci.step.x=32;
|
||||
pgci.step.y=32;
|
||||
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
|
||||
pgci.color.Set(0.25,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
|
||||
ro_plane_grid=CreatePlaneGrid(db,vil,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
ro_line=db->CreatePrimitive(2);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, vbo_pos=db->CreateVBO(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,2,color_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid,Matrix4f(1.0f));
|
||||
Add(ro_line,Matrix4f(1.0f));
|
||||
|
||||
camera->pos=Vector3f(100,100,50);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(camera->info,&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
const CameraInfo &ci=GetCameraInfo();
|
||||
|
||||
ray.Set(GetMouseCoord(),&ci); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(ci,&render_root);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
// 2.RectanglePrimivate
|
||||
// 该示例是texture_rect的进化,演示使用GeometryShader画矩形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_SIZE=512;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=1;
|
||||
|
||||
constexpr float BORDER=0.1f;
|
||||
|
||||
constexpr float position_data[4]=
|
||||
{
|
||||
SCREEN_SIZE*BORDER, SCREEN_SIZE*BORDER,
|
||||
SCREEN_SIZE*(1.0-BORDER), SCREEN_SIZE*(1.0-BORDER)
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,1,1
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Primitive * primitive =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/TextureRect2D"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::SolidRectangles);
|
||||
if(!pipeline)return(false);
|
||||
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"));
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
|
||||
if(!primitive)return(false);
|
||||
|
||||
primitive->Set(VAN::Position,db->CreateVBO(VF_V4F,VERTEX_COUNT,position_data));
|
||||
primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V4F,VERTEX_COUNT,tex_coord_data));
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
// first_triangle
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/math/HalfFloat.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data_float[VERTEX_COUNT*2]=
|
||||
{
|
||||
0.0, -0.5,
|
||||
-0.5, 0.5,
|
||||
0.5, 0.5
|
||||
};
|
||||
|
||||
#define USE_HALF_FLOAT_POSITION
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
constexpr VkFormat PositionFormat=VF_V2HF;
|
||||
|
||||
half_float position_data_hf[VERTEX_COUNT*2];
|
||||
|
||||
#define position_data position_data_hf
|
||||
#else
|
||||
constexpr VkFormat PositionFormat=VF_V2F;
|
||||
|
||||
#define position_data position_data_float
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
#define USE_UNORM8_COLOR
|
||||
|
||||
#ifdef USE_UNORM8_COLOR
|
||||
constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
{ 255,0,0,255,
|
||||
0,255,0,255,
|
||||
0,0,255,255
|
||||
};
|
||||
|
||||
constexpr VkFormat ColorFormat=VF_V4UN8;
|
||||
#else
|
||||
constexpr float color_data[VERTEX_COUNT*4]=
|
||||
{ 1,0,0,1,
|
||||
0,1,0,1,
|
||||
0,0,1,1
|
||||
};
|
||||
|
||||
constexpr VkFormat ColorFormat=VF_V4F;
|
||||
#endif//USE_UNORM8_COLOR
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
|
||||
VILConfig vil_config;
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
vil_config.Add(VAN::Position,PositionFormat);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
#ifdef USE_UNORM8_COLOR
|
||||
vil_config.Add(VAN::Color,ColorFormat);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"),&vil_config);
|
||||
#else
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||
#endif//
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
// indices_rect
|
||||
// 该示例演示使用索引数据画一个矩形,并使用了颜色材质
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
static Vector4f color(1,1,1,1);
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{SCREEN_WIDTH,0},
|
||||
{0,SCREEN_HEIGHT},
|
||||
{SCREEN_WIDTH,SCREEN_HEIGHT}
|
||||
};
|
||||
|
||||
constexpr uint32_t INDEX_COUNT=6;
|
||||
|
||||
constexpr uint16 index_data[INDEX_COUNT]=
|
||||
{
|
||||
0,1,3,
|
||||
0,3,2
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable *renderable =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/FragColor"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
// third_triangle
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75},
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{
|
||||
{1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
|
||||
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
// second_triangle
|
||||
// 该范例主要演示使用场景树系统绘制三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{ {1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
|
||||
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
render_root.CreateSubNode(render_obj);
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/VKInstance.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKDeviceCreater.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
@ -19,9 +19,14 @@
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#ifdef _DEBUG
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#endif//_DEBUG
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/Time.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
//#include<hgl/graph/LookAtCameraControl.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
@ -33,6 +38,12 @@ using namespace hgl;
|
||||
using namespace hgl::io;
|
||||
using namespace hgl::graph;
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
bool InitShaderCompiler();
|
||||
void CloseShaderCompiler();
|
||||
}}//namespace hgl::graph
|
||||
|
||||
class VulkanApplicationFramework:WindowEvent
|
||||
{
|
||||
protected:
|
||||
@ -42,7 +53,7 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
VulkanDevice * device =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
SwapchainRenderTarget * sc_render_target =nullptr;
|
||||
|
||||
@ -59,28 +70,42 @@ protected:
|
||||
RenderResource * db =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
|
||||
ViewportInfo vp_info;
|
||||
DeviceBuffer * ubo_vp_info =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
virtual void BindRenderResource(RenderResource *rr)
|
||||
{
|
||||
if(!rr)
|
||||
return;
|
||||
|
||||
rr->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
}
|
||||
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
SAFE_CLEAR(camera);
|
||||
CloseShaderCompiler();
|
||||
|
||||
win->Unjoin(this);
|
||||
|
||||
SAFE_CLEAR(db);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(cmd_buf,swap_chain_count);
|
||||
|
||||
SAFE_CLEAR(device);
|
||||
SAFE_CLEAR(win);
|
||||
SAFE_CLEAR(inst);
|
||||
}
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
virtual bool Init(uint w,uint h)
|
||||
{
|
||||
clear_color.Set(0,0,0,1);
|
||||
logger::InitLogger(OS_TEXT("VulkanTest"));
|
||||
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
SetClearColor(COLOR::MozillaCharcoal);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
@ -105,7 +130,6 @@ public:
|
||||
|
||||
cili.lunarg.standard_validation = true;
|
||||
cili.khronos.validation = true;
|
||||
//cili.RenderDoc.Capture = true;
|
||||
|
||||
inst=CreateInstance("VulkanTest",nullptr,&cili);
|
||||
|
||||
@ -113,10 +137,16 @@ public:
|
||||
return(false);
|
||||
}
|
||||
|
||||
device=CreateRenderDevice(inst,win);
|
||||
{
|
||||
VulkanHardwareRequirement vh_req;
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
vh_req.wideLines=VulkanHardwareRequirement::SupportLevel::Want;
|
||||
|
||||
device=CreateRenderDevice(inst,win,&vh_req);
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
}
|
||||
|
||||
device_render_pass=device->GetRenderPass();
|
||||
|
||||
@ -127,48 +157,30 @@ public:
|
||||
win->Join(this);
|
||||
|
||||
{
|
||||
camera=new Camera;
|
||||
vp_info.Set(w,h);
|
||||
|
||||
camera->width=w;
|
||||
camera->height=h;
|
||||
camera->vp_width=w;
|
||||
camera->vp_height=h;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
camera->RefreshCameraInfo();
|
||||
|
||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
||||
ubo_vp_info=db->CreateUBO("Viewport",sizeof(ViewportInfo),&vp_info);
|
||||
}
|
||||
|
||||
BindRenderResource(db);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
const CameraInfo &GetCameraInfo()
|
||||
virtual void Resize(uint w,uint h)
|
||||
{
|
||||
return camera->info;
|
||||
vp_info.Set(w,h);
|
||||
ubo_vp_info->Write(&vp_info);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetCameraInfoBuffer()
|
||||
ViewportInfo *GetViewportInfo()
|
||||
{
|
||||
return ubo_camera_info;
|
||||
return &vp_info;
|
||||
}
|
||||
|
||||
bool BindCameraUBO(MaterialInstance *mi)
|
||||
DeviceBuffer *GetViewportInfoBuffer()
|
||||
{
|
||||
return mi->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual void Resize(int w,int h)
|
||||
{
|
||||
camera->width=w;
|
||||
camera->height=h;
|
||||
camera->vp_width=w;
|
||||
camera->vp_height=h;
|
||||
|
||||
camera->RefreshCameraInfo();
|
||||
|
||||
ubo_camera_info->Write(&camera->info);
|
||||
return ubo_vp_info;
|
||||
}
|
||||
|
||||
void SetClearColor(const Color4f &cc)
|
||||
@ -193,7 +205,7 @@ public:
|
||||
void InitCommandBuffer()
|
||||
{
|
||||
if(cmd_buf)
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(cmd_buf,swap_chain_count);
|
||||
|
||||
sc_render_target=device->GetSwapchainRT();
|
||||
|
||||
@ -204,51 +216,37 @@ public:
|
||||
cmd_buf=hgl_zero_new<RenderCmdBuffer *>(swap_chain_count);
|
||||
|
||||
for(int32_t i=0;i<swap_chain_count;i++)
|
||||
cmd_buf[i]=device->CreateRenderCommandBuffer();
|
||||
cmd_buf[i]=device->CreateRenderCommandBuffer(device->GetPhyDevice()->GetDeviceName()+AnsiString(":RenderCmdBuffer_")+AnsiString::numberOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,RenderPass *rp,Framebuffer *fb,Renderable *ri)
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,Framebuffer *fbo,Mesh *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
const IndexBuffer *ib=ri->GetIndexBuffer();
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(rp,fb);
|
||||
cb->BindFramebuffer(fbo);
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
cb->BindPipeline(ri->GetPipeline());
|
||||
cb->BindDescriptorSets(ri);
|
||||
cb->BindVBO(ri);
|
||||
|
||||
if (ib)
|
||||
cb->DrawIndexed(ib->GetCount(),ri->GetInstanceCount());
|
||||
else
|
||||
cb->Draw(ri->GetDrawCount(),ri->GetInstanceCount());
|
||||
|
||||
cb->BindDescriptorSets(ri->GetMaterial());
|
||||
cb->BindDataBuffer(ri->GetDataBuffer());
|
||||
cb->Draw(ri->GetDataBuffer(),ri->GetRenderData());
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(RenderCmdBuffer *cb,RenderTarget *rt,Renderable *ri)
|
||||
{
|
||||
if(!cb||!rt||!ri)
|
||||
return;
|
||||
|
||||
BuildCommandBuffer(cb,rt->GetRenderPass(),rt->GetFramebuffer(),ri);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(uint32_t index,Renderable *ri)
|
||||
bool BuildCommandBuffer(uint32_t index,Mesh *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
return BuildCommandBuffer(cmd_buf[index],sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index),ri);
|
||||
return BuildCommandBuffer(cmd_buf[index],
|
||||
sc_render_target->GetFramebuffer(),ri);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(Renderable *ri)
|
||||
bool BuildCommandBuffer(Mesh *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
@ -258,7 +256,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool BuildCurrentCommandBuffer(Renderable *ri)
|
||||
bool BuildCurrentCommandBuffer(Mesh *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
@ -272,7 +270,7 @@ public:
|
||||
RenderCmdBuffer *cb=cmd_buf[index];
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
||||
cb->BindFramebuffer(sc_render_target->GetFramebuffer(index));
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
rl->Render(cb);
|
||||
@ -292,7 +290,22 @@ public:
|
||||
}
|
||||
|
||||
template<typename ...ARGS>
|
||||
Pipeline *CreatePipeline(ARGS...args){return device_render_pass->CreatePipeline(args...);}
|
||||
Pipeline *CreatePipeline(ARGS...args)
|
||||
{
|
||||
Pipeline *p=device_render_pass->CreatePipeline(args...);
|
||||
|
||||
if(!p)
|
||||
return(nullptr);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
du->SetPipeline(*p,"Pipeline:"+p->GetName());
|
||||
#endif//_DEBUG
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@ -333,129 +346,14 @@ public:
|
||||
}
|
||||
};//class VulkanApplicationFramework
|
||||
|
||||
class CameraKeyboardControl:public KeyboardStateEvent
|
||||
{
|
||||
FirstPersonCameraControl *camera;
|
||||
float move_speed;
|
||||
|
||||
public:
|
||||
|
||||
CameraKeyboardControl(FirstPersonCameraControl *wc)
|
||||
{
|
||||
camera=wc;
|
||||
move_speed=1.0f;
|
||||
}
|
||||
|
||||
bool OnPressed(const KeyboardButton &kb)override
|
||||
{
|
||||
if(!KeyboardStateEvent::OnPressed(kb))
|
||||
return(false);
|
||||
|
||||
if(kb==KeyboardButton::Minus )move_speed*=0.9f;else
|
||||
if(kb==KeyboardButton::Equals )move_speed*=1.1f;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(HasPressed(KeyboardButton::W ))camera->Forward (move_speed);else
|
||||
if(HasPressed(KeyboardButton::S ))camera->Backward (move_speed);else
|
||||
if(HasPressed(KeyboardButton::A ))camera->Left (move_speed);else
|
||||
if(HasPressed(KeyboardButton::D ))camera->Right (move_speed);else
|
||||
//if(HasPressed(KeyboardButton::R ))camera->Up (move_speed);else
|
||||
//if(HasPressed(KeyboardButton::F ))camera->Down (move_speed);else
|
||||
|
||||
//if(HasPressed(KeyboardButton::Left ))camera->HoriRotate( move_speed);else
|
||||
//if(HasPressed(KeyboardButton::Right ))camera->HoriRotate(-move_speed);else
|
||||
//if(HasPressed(KeyboardButton::Up ))camera->VertRotate( move_speed);else
|
||||
//if(HasPressed(KeyboardButton::Down ))camera->VertRotate(-move_speed);else
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
class CameraMouseControl:public MouseEvent
|
||||
{
|
||||
FirstPersonCameraControl *camera;
|
||||
double cur_time;
|
||||
double last_time;
|
||||
|
||||
Vector2f mouse_pos;
|
||||
Vector2f mouse_last_pos;
|
||||
|
||||
protected:
|
||||
|
||||
bool OnPressed(int x,int y,MouseButton) override
|
||||
{
|
||||
mouse_last_pos.x=x;
|
||||
mouse_last_pos.y=y;
|
||||
|
||||
last_time=cur_time;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool OnWheel(int,int y) override
|
||||
{
|
||||
if(y==0)return(false);
|
||||
|
||||
camera->Forward(float(y)/10.0f);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool OnMove(int x,int y) override
|
||||
{
|
||||
mouse_pos.x=x;
|
||||
mouse_pos.y=y;
|
||||
|
||||
bool left=HasPressed(MouseButton::Left);
|
||||
bool right=HasPressed(MouseButton::Right);
|
||||
|
||||
Vector2f pos(x,y);
|
||||
Vector2f gap=pos-mouse_last_pos;
|
||||
|
||||
if(left)
|
||||
{
|
||||
gap/=-5.0f;
|
||||
|
||||
camera->Rotate(gap);
|
||||
}
|
||||
else
|
||||
if(right)
|
||||
{
|
||||
gap/=10.0f;
|
||||
|
||||
camera->Move(Vector3f(gap.x,0,gap.y));
|
||||
}
|
||||
|
||||
last_time=cur_time;
|
||||
mouse_last_pos=Vector2f(x,y);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
CameraMouseControl(FirstPersonCameraControl *wc)
|
||||
{
|
||||
camera=wc;
|
||||
cur_time=0;
|
||||
}
|
||||
|
||||
const Vector2f &GetMouseCoord()const{return mouse_pos;}
|
||||
|
||||
void Update()
|
||||
{
|
||||
cur_time=GetDoubleTime();
|
||||
}
|
||||
};
|
||||
|
||||
class CameraAppFramework:public VulkanApplicationFramework
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
|
||||
FirstPersonCameraControl *camera_control=nullptr;
|
||||
|
||||
CameraKeyboardControl * ckc=nullptr;
|
||||
@ -465,24 +363,40 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
virtual void BindRenderResource(RenderResource *rr) override
|
||||
{
|
||||
if(!rr)return;
|
||||
|
||||
VulkanApplicationFramework::BindRenderResource(rr);
|
||||
|
||||
rr->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual ~CameraAppFramework()
|
||||
{
|
||||
SAFE_CLEAR(ckc);
|
||||
SAFE_CLEAR(cmc);
|
||||
SAFE_CLEAR(camera);
|
||||
}
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
virtual bool Init(uint w,uint h) override
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
InitCamera(w,h);
|
||||
|
||||
BindRenderResource(db);
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void InitCamera(int w,int h)
|
||||
{
|
||||
camera_control=new FirstPersonCameraControl(camera);
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
camera_control=new FirstPersonCameraControl(&vp_info,camera);
|
||||
|
||||
camera_control->Refresh(); //更新矩阵计算
|
||||
|
||||
@ -491,26 +405,38 @@ public:
|
||||
|
||||
win->Join(ckc);
|
||||
win->Join(cmc);
|
||||
|
||||
RefreshCameraInfo(camera_control->GetCameraInfo(),&vp_info,camera);
|
||||
|
||||
ubo_camera_info=db->CreateUBO("CameraInfo",sizeof(CameraInfo),camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
camera->width=w;
|
||||
camera->height=h;
|
||||
camera->vp_width=w;
|
||||
camera->vp_height=h;
|
||||
vp_info.Set(w,h);
|
||||
|
||||
camera_control->Refresh();
|
||||
|
||||
ubo_camera_info->Write(&camera->info);
|
||||
ubo_camera_info->Write(camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
CameraInfo *GetCameraInfo()
|
||||
{
|
||||
return camera_control->GetCameraInfo();
|
||||
}
|
||||
|
||||
DeviceBuffer *GetCameraInfoBuffer()
|
||||
{
|
||||
return ubo_camera_info;
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||
|
||||
virtual void Draw()override
|
||||
{
|
||||
camera_control->Refresh(); //更新相机矩阵
|
||||
ubo_camera_info->Write(&camera->info); //写入缓冲区
|
||||
camera_control->Refresh(); //更新相机矩阵
|
||||
|
||||
ubo_camera_info->Write(camera_control->GetCameraInfo()); //写入缓冲区
|
||||
|
||||
const uint32_t index=AcquireNextImage();
|
||||
|
||||
@ -521,4 +447,55 @@ public:
|
||||
ckc->Update();
|
||||
cmc->Update();
|
||||
}
|
||||
};//class CameraAppFramework
|
||||
};//class CameraAppFramework
|
||||
|
||||
class SceneAppFramework:public CameraAppFramework
|
||||
{
|
||||
protected:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
SceneAppFramework()=default;
|
||||
|
||||
virtual ~SceneAppFramework()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
virtual bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!CameraAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
virtual void Resize(uint w,uint h) override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class SceneAppFramework:public CameraAppFramework
|
||||
|
||||
template<typename T> int RunApp(uint w,uint h)
|
||||
{
|
||||
T app;
|
||||
|
||||
if(!app.Init(w,h))
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
95
inc/hgl/WorkManager.h
Normal file
95
inc/hgl/WorkManager.h
Normal file
@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/WorkObject.h>
|
||||
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
* 工作管理器,管理一个序列的WorkObject<br>
|
||||
*/
|
||||
class WorkManager
|
||||
{
|
||||
protected:
|
||||
|
||||
graph::RenderFramework *render_framework;
|
||||
|
||||
uint fps=60;
|
||||
double frame_time=1.0f/double(fps);
|
||||
|
||||
double last_update_time=0;
|
||||
double last_render_time=0;
|
||||
double cur_time=0;
|
||||
|
||||
WorkObject *cur_work_object=nullptr;
|
||||
|
||||
public:
|
||||
|
||||
WorkManager(graph::RenderFramework *rf)
|
||||
{
|
||||
render_framework=rf;
|
||||
}
|
||||
|
||||
virtual ~WorkManager()
|
||||
{
|
||||
SAFE_CLEAR(cur_work_object);
|
||||
}
|
||||
|
||||
void SetFPS(uint f)
|
||||
{
|
||||
fps=f;
|
||||
frame_time=1.0f/double(fps);
|
||||
}
|
||||
|
||||
void Tick(WorkObject *wo);
|
||||
|
||||
virtual void Render(WorkObject *wo);
|
||||
|
||||
void Run(WorkObject *wo);
|
||||
};//class WorkManager
|
||||
|
||||
class SwapchainWorkManager:public WorkManager,public io::WindowEvent
|
||||
{
|
||||
graph::SwapchainModule *swapchain_module;
|
||||
|
||||
public:
|
||||
|
||||
SwapchainWorkManager(graph::RenderFramework *rf):WorkManager(rf)
|
||||
{
|
||||
swapchain_module=rf->GetSwapchainModule();
|
||||
|
||||
render_framework->Join(this);
|
||||
}
|
||||
|
||||
~SwapchainWorkManager()
|
||||
{
|
||||
render_framework->Unjoin(this);
|
||||
}
|
||||
|
||||
void Render(WorkObject *wo) override;
|
||||
|
||||
void OnResize(uint w,uint h) override;
|
||||
};
|
||||
|
||||
template<typename WO> int RunFramework(const OSString &title,uint width=1280,uint height=720)
|
||||
{
|
||||
graph::RenderFramework rf(title);
|
||||
|
||||
if(!rf.Init(width,height))
|
||||
return(-1);
|
||||
|
||||
SwapchainWorkManager wm(&rf);
|
||||
|
||||
WO *wo=new WO(&rf);
|
||||
|
||||
if(!wo->Init())
|
||||
{
|
||||
delete wo;
|
||||
return(-2);
|
||||
}
|
||||
|
||||
wm.Run(wo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}//namespcae hgl
|
123
inc/hgl/WorkObject.h
Normal file
123
inc/hgl/WorkObject.h
Normal file
@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
#include<hgl/type/object/TickObject.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/mtl/MaterialLibrary.h>
|
||||
#include<hgl/graph/Renderer.h>
|
||||
#include<hgl/graph/Scene.h>
|
||||
#include<hgl/Time.h>
|
||||
//#include<iostream>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph::mtl
|
||||
{
|
||||
class MaterialCreateInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工作对象</p>
|
||||
*
|
||||
* WorkObject被定义为工作对象,所有的渲染控制都需要被写在WorkObject的Render函数下。
|
||||
*/
|
||||
class WorkObject:public TickObject
|
||||
{
|
||||
graph::RenderFramework *render_framework=nullptr;
|
||||
|
||||
bool destroy_flag=false;
|
||||
bool render_dirty=true;
|
||||
|
||||
protected:
|
||||
|
||||
//以下数据均取自RenderFramework
|
||||
|
||||
graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代
|
||||
|
||||
graph::Scene * scene=nullptr; //场景
|
||||
graph::Renderer * renderer=nullptr; //渲染器
|
||||
|
||||
public:
|
||||
|
||||
graph::RenderFramework * GetRenderFramework (){return render_framework;}
|
||||
graph::VulkanDevice * GetDevice (){return render_framework->GetDevice();}
|
||||
graph::VulkanDevAttr * GetDevAttr (){return render_framework->GetDevAttr();}
|
||||
graph::TextureManager * GetTextureManager (){return render_framework->GetTextureManager();}
|
||||
|
||||
const VkExtent2D & GetExtent (){return renderer->GetExtent();}
|
||||
|
||||
graph::Scene * GetScene (){return scene;}
|
||||
graph::SceneNode * GetSceneRoot (){return scene->GetRootNode();}
|
||||
graph::Renderer * GetRenderer (){return renderer;}
|
||||
graph::Camera * GetCamera (){return renderer->GetCamera();}
|
||||
graph::CameraControl * GetCameraControl (){return render_framework->GetDefaultCameraControl();}
|
||||
|
||||
bool GetMouseCoord (Vector2i *mc)const{return render_framework->GetMouseCoord(mc);}
|
||||
|
||||
public:
|
||||
|
||||
const bool IsDestroy ()const{return destroy_flag;}
|
||||
void MarkDestory(){destroy_flag=true;}
|
||||
|
||||
const bool IsRenderDirty ()const{return render_dirty;}
|
||||
void MarkRenderDirty(){render_dirty=true;}
|
||||
|
||||
public:
|
||||
|
||||
WorkObject(graph::RenderFramework *,graph::Renderer *r=nullptr);
|
||||
virtual ~WorkObject()=default;
|
||||
|
||||
virtual bool Init()=0;
|
||||
|
||||
virtual void OnRendererChange(graph::RenderFramework *rf,graph::Renderer *r);
|
||||
|
||||
virtual void OnResize(const VkExtent2D &){}
|
||||
|
||||
virtual void Tick(double){}
|
||||
|
||||
virtual void Render(double delta_time);
|
||||
|
||||
public:
|
||||
|
||||
#define WO_FUNC_FROM_RENDER_FRAMEWORK(name,return_type) template<typename ...ARGS> return_type name(ARGS...args){return render_framework?render_framework->name(args...):nullptr;}
|
||||
|
||||
WO_FUNC_FROM_RENDER_FRAMEWORK(CreatePipeline,graph::Pipeline *)
|
||||
WO_FUNC_FROM_RENDER_FRAMEWORK(CreateMaterialInstance,graph::MaterialInstance *)
|
||||
WO_FUNC_FROM_RENDER_FRAMEWORK(GetPrimitiveCreater,SharedPtr<graph::PrimitiveCreater>)
|
||||
|
||||
#undef WO_FUNC_FROM_RENDER_FRAMEWORK
|
||||
|
||||
graph::Primitive *CreatePrimitive(const AnsiString &name,
|
||||
const uint32_t vertices_count,
|
||||
const graph::VIL *vil,
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
|
||||
{
|
||||
return render_framework?render_framework->CreatePrimitive(name,vertices_count,vil,vad_list):nullptr;
|
||||
}
|
||||
|
||||
graph::Mesh *CreateMesh(const AnsiString &name,
|
||||
const uint32_t vertices_count,
|
||||
graph::MaterialInstance *mi,
|
||||
graph::Pipeline *pipeline,
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
|
||||
{
|
||||
return render_framework?render_framework->CreateMesh(name,vertices_count,mi,pipeline,vad_list):nullptr;
|
||||
}
|
||||
|
||||
public: //Component 相关
|
||||
|
||||
template<typename C,typename ...ARGS>
|
||||
inline C *CreateComponent(const graph::CreateComponentInfo *cci,ARGS...args)
|
||||
{
|
||||
return render_framework?render_framework->CreateComponent<C>(cci,args...):nullptr; //创建组件
|
||||
}
|
||||
};//class WorkObject
|
||||
|
||||
/**
|
||||
* 但我们认为游戏开发者不应该关注如何控制渲染,而应该关注如何处理游戏逻辑.
|
||||
* 所以我们在WorkObject的基础上再提供RenderWorkObject派生类,用于直接封装好的渲染场景树控制。
|
||||
*
|
||||
* 开发者仅需要将要渲染的物件放置于场景树即可。
|
||||
|
||||
* 但开发者也可以直接使用WorkObject,自行管理这些事。
|
||||
* */
|
||||
}//namespcae hgl
|
209
inc/hgl/component/Component.h
Normal file
209
inc/hgl/component/Component.h
Normal file
@ -0,0 +1,209 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
#include<hgl/type/ArrayList.h>
|
||||
|
||||
/**
|
||||
* Component/Data/Manager 体系设计简要说明
|
||||
*
|
||||
* 本体系参考AMD FidelityFX,但并不完全一致。
|
||||
*
|
||||
* AMD FidelityFX中,Component存放于Entity下,而我方中与其类似的定义为SceneNode。
|
||||
* 不管是Entity还是SceneNode,它们都提供空间变换,以及子节点、Component的管理。
|
||||
* 而AMD FidelityFX中的Scene,类似于我方的Scene,用于储存一个场景世界的根节点及其它世界唯一数据。
|
||||
*
|
||||
* ComponentData是每个Component的数据,用于向Component或是其它模块提供数据。
|
||||
* ComponentManager是Component的管理器,用于管理Component的创建、销毁、更新等。
|
||||
*
|
||||
* 需要注意的是:同AMD FidelityFX一样,大部分ComponentManager与Scene基本无关。
|
||||
* 因为同样的数据可能出现在多个World之中。
|
||||
* 仅有那些与Scene密切相关的Component它对应的Manager才会出现在Scene中,比如CameraManager/LightManager。
|
||||
* 而如MeshComponent之类的纯资源型就会是独立存在的。
|
||||
*
|
||||
* Component是组件的基类,所有组件都从这里派生。
|
||||
*
|
||||
* SceneComponent是场景组件基类,只要是放在场景中的都从它派生,
|
||||
*
|
||||
* PrimitiveComponent是图元组件的基类,所有图元组件都从这里派生。
|
||||
* 它再度派生出的任何Component都必须是一个有3D空间的几何图元。
|
||||
* 引擎中的空间、物理、等都由PrimitiveComponent提供数据进行计算。
|
||||
|
||||
* RenderComponent是可渲染组件的基类,所有可渲染组件都从这里派生。
|
||||
*
|
||||
* MeshComponent是静态网格组件,它是一个具体的RenderComponent实现。
|
||||
*/
|
||||
|
||||
#define COMPONENT_NAMESPACE hgl::graph
|
||||
#define COMPONENT_NAMESPACE_BEGIN namespace COMPONENT_NAMESPACE {
|
||||
#define COMPONENT_NAMESPACE_END }
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
class ComponentManager;
|
||||
class SceneNode;
|
||||
|
||||
struct ComponentData
|
||||
{
|
||||
public:
|
||||
|
||||
ComponentData()=default;
|
||||
virtual ~ComponentData()=default;
|
||||
|
||||
virtual const size_t GetTypeHash()const=0; ///<取得ComponentData的类型哈希值
|
||||
virtual const size_t GetComponentTypeHash()const=0; ///<取得Component的类型哈希值
|
||||
virtual const size_t GetManagerTypeHash()const=0; ///<取得ComponentManager的类型哈希值
|
||||
};//struct ComponentData
|
||||
|
||||
#define COMPONENT_DATA_CLASS_BODY(name) static constexpr const size_t StaticTypeHash (){return hgl::GetTypeHash<name##ComponentData>();} \
|
||||
static constexpr const size_t StaticComponentTypeHash(){return hgl::GetTypeHash<name##Component>();} \
|
||||
static constexpr const size_t StaticManagerTypeHash (){return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||
const size_t GetTypeHash ()const override{return StaticTypeHash();} \
|
||||
const size_t GetComponentTypeHash ()const override{return StaticComponentTypeHash();} \
|
||||
const size_t GetManagerTypeHash ()const override{return StaticManagerTypeHash();}
|
||||
|
||||
using ComponentDataPtr=SharedPtr<ComponentData>;
|
||||
|
||||
/**
|
||||
* 为什么要ComponentData与Component分离?
|
||||
*
|
||||
* ComponentData是Component的一个数据载体,但它也仅仅代表数据。
|
||||
* 它不参与任何的逻辑、事件、更新、渲染操作,而且同一份数据可以被多个Component使用。
|
||||
* 同时,Component也可以在运行时更换ComponentData。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 基础组件<br>
|
||||
* 是一切组件的基类
|
||||
*/
|
||||
class Component
|
||||
{
|
||||
static uint unique_id_count;
|
||||
|
||||
uint unique_id;
|
||||
|
||||
SceneNode * OwnerNode;
|
||||
ComponentManager * Manager;
|
||||
ComponentDataPtr Data;
|
||||
|
||||
protected:
|
||||
|
||||
friend class ComponentManager;
|
||||
|
||||
virtual void OnDetachManager(ComponentManager *cm)
|
||||
{
|
||||
if(cm==Manager)
|
||||
Manager=nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Component()=delete;
|
||||
Component(ComponentDataPtr,ComponentManager *);
|
||||
virtual ~Component();
|
||||
|
||||
virtual const size_t GetTypeHash()const=0; ///<取得Component的类型哈希值
|
||||
virtual const size_t GetDataTypeHash()const=0; ///<取得ComponentData的类型哈希值
|
||||
virtual const size_t GetManagerTypeHash()const=0; ///<取得ComponentManager的类型哈希值
|
||||
|
||||
public:
|
||||
|
||||
uint GetUniqueID ()const{return unique_id;}
|
||||
|
||||
SceneNode * GetOwnerNode()const{return OwnerNode;}
|
||||
ComponentManager * GetManager ()const{return Manager;}
|
||||
ComponentDataPtr GetData ()const{return Data;}
|
||||
|
||||
public:
|
||||
|
||||
virtual bool ChangeData(ComponentDataPtr cdp);
|
||||
|
||||
public:
|
||||
|
||||
virtual Component *Duplication();
|
||||
|
||||
//virtual void Update(const double delta_time)=0;
|
||||
|
||||
public: //事件
|
||||
|
||||
virtual void OnAttach(SceneNode *node){if(node)OwnerNode=node;} ///<附加到节点事件
|
||||
virtual void OnDetach(SceneNode *){OwnerNode=nullptr;} ///<从节点分离事件
|
||||
|
||||
virtual void OnFocusLost(){} ///<焦点丢失事件
|
||||
virtual void OnFocusGained(){} ///<焦点获得事件
|
||||
};//class Component
|
||||
|
||||
#define COMPONENT_CLASS_BODY(name) static name##ComponentManager *GetDefaultManager () {return name##ComponentManager::GetDefaultManager();} \
|
||||
name##ComponentManager *GetManager ()const {return (name##ComponentManager *)Component::GetManager();} \
|
||||
static constexpr const size_t StaticTypeHash () {return hgl::GetTypeHash<name##Component>();} \
|
||||
static constexpr const size_t StaticDataTypeHash () {return hgl::GetTypeHash<name##ComponentData>();} \
|
||||
static constexpr const size_t StaticManagerTypeHash () {return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||
const size_t GetTypeHash ()const override{return StaticTypeHash();} \
|
||||
const size_t GetDataTypeHash ()const override{return StaticDataTypeHash();} \
|
||||
const size_t GetManagerTypeHash ()const override{return StaticManagerTypeHash();}
|
||||
|
||||
using ComponentSet=SortedSet<Component *>;
|
||||
using ComponentList=ArrayList<Component *>;
|
||||
|
||||
class ComponentManager
|
||||
{
|
||||
ComponentSet component_set;
|
||||
|
||||
protected:
|
||||
|
||||
friend class Component; //Component可以直接访问ComponentManager的成员
|
||||
|
||||
virtual void AttachComponent(Component *c){if(!c)return;component_set.Add(c);}
|
||||
virtual void DetachComponent(Component *c){if(!c)return;component_set.Delete(c);}
|
||||
|
||||
public:
|
||||
|
||||
virtual const size_t GetComponentTypeHash()const=0; ///<取得Component的类型哈希值
|
||||
virtual const size_t GetDataTypeHash()const=0; ///<取得ComponentData的类型哈希值
|
||||
virtual const size_t GetTypeHash()const=0; ///<取得ComponentManager的类型哈希值
|
||||
|
||||
virtual ~ComponentManager();
|
||||
|
||||
public:
|
||||
|
||||
virtual Component * CreateComponent(ComponentDataPtr)=0;
|
||||
|
||||
const size_t GetComponentCount()const{return component_set.GetCount();}
|
||||
|
||||
ComponentSet & GetComponents(){return component_set;}
|
||||
|
||||
int GetComponents(ComponentList &comp_list,SceneNode *);
|
||||
|
||||
virtual void UpdateComponents(const double delta_time);
|
||||
|
||||
public: //事件
|
||||
|
||||
virtual void OnFocusLost(){} ///<焦点丢失事件
|
||||
virtual void OnFocusGained(){} ///<焦点获得事件
|
||||
};//class ComponentManager
|
||||
|
||||
#define COMPONENT_MANAGER_CLASS_BODY(name) static name##ComponentManager * GetDefaultManager () {return GetComponentManager<name##ComponentManager>(true);} \
|
||||
static constexpr const size_t StaticTypeHash () {return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||
static constexpr const size_t StaticDataTypeHash () {return hgl::GetTypeHash<name##ComponentData>();} \
|
||||
static constexpr const size_t StaticComponentTypeHash () {return hgl::GetTypeHash<name##Component>();} \
|
||||
const size_t GetComponentTypeHash ()const override{return StaticComponentTypeHash();} \
|
||||
const size_t GetDataTypeHash ()const override{return StaticDataTypeHash();} \
|
||||
const size_t GetTypeHash ()const override{return StaticTypeHash();}
|
||||
|
||||
bool RegistryComponentManager(ComponentManager *);
|
||||
ComponentManager *GetComponentManager(const size_t hash_code);
|
||||
|
||||
template<typename T> inline T *GetComponentManager(bool create_default=true)
|
||||
{
|
||||
T *cm=(T *)GetComponentManager(T::StaticTypeHash());
|
||||
|
||||
if(!cm&&create_default)
|
||||
{
|
||||
cm=new T;
|
||||
|
||||
RegistryComponentManager(cm);
|
||||
}
|
||||
|
||||
return cm;
|
||||
}
|
||||
COMPONENT_NAMESPACE_END
|
93
inc/hgl/component/MeshComponent.h
Normal file
93
inc/hgl/component/MeshComponent.h
Normal file
@ -0,0 +1,93 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/RenderComponent.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
|
||||
//#include<hgl/log/LogInfo.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
class MeshComponent;
|
||||
class MeshComponentManager;
|
||||
|
||||
struct MeshComponentData:public ComponentData
|
||||
{
|
||||
//static uint unique_id_count;
|
||||
|
||||
//uint unique_id;
|
||||
|
||||
Mesh *mesh;
|
||||
|
||||
public:
|
||||
|
||||
MeshComponentData()
|
||||
{
|
||||
mesh=nullptr;
|
||||
|
||||
// unique_id=++unique_id_count;
|
||||
// LOG_INFO(AnsiString("MeshComponentData():")+AnsiString::numberOf(unique_id));
|
||||
}
|
||||
|
||||
MeshComponentData(Mesh *m)
|
||||
{
|
||||
mesh=m;
|
||||
|
||||
// unique_id=++unique_id_count;
|
||||
// LOG_INFO(AnsiString("MeshComponentData(Mesh *):")+AnsiString::numberOf(unique_id));
|
||||
}
|
||||
|
||||
virtual ~MeshComponentData();
|
||||
|
||||
COMPONENT_DATA_CLASS_BODY(Mesh)
|
||||
};//struct MeshComponentData
|
||||
|
||||
class MeshComponentManager:public ComponentManager
|
||||
{
|
||||
public:
|
||||
|
||||
COMPONENT_MANAGER_CLASS_BODY(Mesh)
|
||||
|
||||
public:
|
||||
|
||||
MeshComponentManager()=default;
|
||||
|
||||
Component *CreateComponent(ComponentDataPtr cdp) override;
|
||||
|
||||
Component *CreateComponent(Mesh *);
|
||||
};//class MeshComponentManager
|
||||
|
||||
class MeshComponent:public RenderComponent
|
||||
{
|
||||
WeakPtr<ComponentData> sm_data;
|
||||
|
||||
public:
|
||||
|
||||
COMPONENT_CLASS_BODY(Mesh)
|
||||
|
||||
public:
|
||||
|
||||
MeshComponent(ComponentDataPtr cdp,MeshComponentManager *cm):RenderComponent(cdp,cm)
|
||||
{
|
||||
sm_data=cdp;
|
||||
}
|
||||
|
||||
virtual ~MeshComponent()=default;
|
||||
|
||||
MeshComponentData *GetData() {return dynamic_cast< MeshComponentData *>(sm_data.get());}
|
||||
const MeshComponentData *GetData()const {return dynamic_cast<const MeshComponentData *>(sm_data.const_get());}
|
||||
|
||||
Mesh *GetMesh()const
|
||||
{
|
||||
if(!sm_data.valid())
|
||||
return(nullptr);
|
||||
|
||||
const MeshComponentData *mcd=dynamic_cast<const MeshComponentData *>(sm_data.const_get());
|
||||
|
||||
if(!mcd)
|
||||
return(nullptr);
|
||||
|
||||
return mcd->mesh;
|
||||
}
|
||||
};//class MeshComponent
|
||||
|
||||
COMPONENT_NAMESPACE_END
|
20
inc/hgl/component/PrimitiveComponent.h
Normal file
20
inc/hgl/component/PrimitiveComponent.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/SceneComponent.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 图元组件<br>
|
||||
* 组件中的元素必须是一个可以明确描述的几何体,可以被明确标记尺寸、参与空间、物理计算等。
|
||||
*/
|
||||
class PrimitiveComponent:public SceneComponent
|
||||
{
|
||||
public:
|
||||
|
||||
using SceneComponent::SceneComponent;
|
||||
|
||||
virtual ~PrimitiveComponent()=default;
|
||||
};//class PrimitiveComponent
|
||||
|
||||
COMPONENT_NAMESPACE_END
|
18
inc/hgl/component/RenderComponent.h
Normal file
18
inc/hgl/component/RenderComponent.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/PrimitiveComponent.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 可渲染组件
|
||||
*/
|
||||
class RenderComponent:public PrimitiveComponent
|
||||
{
|
||||
public:
|
||||
|
||||
using PrimitiveComponent::PrimitiveComponent;
|
||||
virtual ~RenderComponent()=default;
|
||||
};//class RenderComponent
|
||||
|
||||
COMPONENT_NAMESPACE_END
|
31
inc/hgl/component/SceneComponent.h
Normal file
31
inc/hgl/component/SceneComponent.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/Component.h>
|
||||
#include<hgl/graph/SceneOrient.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 场景组件<br>
|
||||
* 场景组件中的元素必须是针对场景起作用的,并不一定需要自己绘出来,但也对场景产生影响。比如太阳光、全局风场
|
||||
*/
|
||||
class SceneComponent:public Component,public SceneOrient
|
||||
{
|
||||
public:
|
||||
|
||||
using Component::Component;
|
||||
virtual ~SceneComponent()=default;
|
||||
|
||||
virtual Component *Duplication() override
|
||||
{
|
||||
SceneComponent *sc=(SceneComponent *)Component::Duplication();
|
||||
|
||||
if(!sc)
|
||||
return(sc);
|
||||
|
||||
sc->SetLocalMatrix(GetLocalMatrix());
|
||||
return sc;
|
||||
}
|
||||
};//class SceneComponent
|
||||
|
||||
COMPONENT_NAMESPACE_END
|
0
inc/hgl/component/collision/BoxCollisionComponent.h
Normal file
0
inc/hgl/component/collision/BoxCollisionComponent.h
Normal file
0
inc/hgl/component/collision/CollisionComponent.h
Normal file
0
inc/hgl/component/collision/CollisionComponent.h
Normal file
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_DB_FIELD_TYPE_INCLUDE
|
||||
#define HGL_DB_FIELD_TYPE_INCLUDE
|
||||
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/ArrayList.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
namespace hgl
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ namespace hgl
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 2Dλͼ¼ÓÔØ
|
||||
* 2D位图加载类
|
||||
*/
|
||||
class Bitmap2DLoader:public Texture2DLoader
|
||||
{
|
||||
@ -20,8 +20,8 @@ namespace hgl
|
||||
Bitmap2DLoader():Texture2DLoader(){}
|
||||
~Bitmap2DLoader();
|
||||
|
||||
void *OnBegin(uint32 total_bytes) override;
|
||||
void OnEnd() override {}
|
||||
void *OnBegin(uint32 total_bytes,const VkFormat &) override;
|
||||
bool OnEnd() override {return(false);}
|
||||
|
||||
BitmapData *GetBitmap();
|
||||
};//class Bitmap2DLoader
|
||||
|
28
inc/hgl/graph/CoordinateSystem.h
Normal file
28
inc/hgl/graph/CoordinateSystem.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/TypeFunc.h>
|
||||
namespace hgl::graph
|
||||
{
|
||||
enum class CoordinateSystem2D
|
||||
{
|
||||
NDC,
|
||||
ZeroToOne, //左上角为0,0;右下角为1,1
|
||||
Ortho, //左上角为0,0;右下角为(width-1),(height-1)
|
||||
|
||||
ENUM_CLASS_RANGE(NDC,Ortho)
|
||||
};
|
||||
|
||||
constexpr const char *CoordinateSystem2DName[]=
|
||||
{
|
||||
"NDC",
|
||||
"0to1",
|
||||
"Ortho"
|
||||
};
|
||||
|
||||
inline const char *GetCoordinateSystem2DName(const enum class CoordinateSystem2D &cs)
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(cs)
|
||||
|
||||
return CoordinateSystem2DName[size_t(cs)];
|
||||
}
|
||||
}//namespace hgl::graph
|
@ -4,12 +4,15 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/math/Vector.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/type/Size2.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class PrimitiveCreater;
|
||||
|
||||
namespace inline_geometry
|
||||
{
|
||||
/**
|
||||
@ -20,12 +23,12 @@ namespace hgl
|
||||
RectScope2f scope;
|
||||
};//struct RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci);
|
||||
Primitive *CreateRectangle(PrimitiveCreater *pc,const RectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 创建延迟渲染用全屏平面
|
||||
*/
|
||||
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil);
|
||||
Primitive *CreateGBufferCompositionRectangle(PrimitiveCreater *pc);
|
||||
|
||||
/**
|
||||
* 圆角矩形创建信息(扇形/线圈)
|
||||
@ -36,7 +39,7 @@ namespace hgl
|
||||
uint32_t round_per; ///<圆角精度
|
||||
};//struct RoundRectangleCreateInfo:public RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci);
|
||||
Primitive *CreateRoundRectangle(PrimitiveCreater *pc,const RoundRectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 圆形创建信息
|
||||
@ -45,9 +48,9 @@ namespace hgl
|
||||
{
|
||||
Vector2f center; ///<圆心坐标
|
||||
Vector2f radius; ///<半径
|
||||
uint field_count=8; ///<分段次数
|
||||
uint field_count=8; ///<分段数量
|
||||
|
||||
bool has_color =false;
|
||||
bool has_center; ///<是否有圆心点
|
||||
|
||||
Vector4f center_color; ///<圆心颜色
|
||||
Vector4f border_color; ///<边缘颜色
|
||||
@ -56,44 +59,43 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个2D圆形(扇形/线圈)
|
||||
*/
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci);
|
||||
Primitive *CreateCircle2D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个3D圆形(扇形/圆形,XY,Z永远为0)
|
||||
*/
|
||||
Primitive *CreateCircle3D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息
|
||||
* 创建一个使用三角形绘制的3D圆形(扇形/圆形,XY,Z永远为0)
|
||||
*/
|
||||
Primitive *CreateCircle3DByIndexTriangles(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息<br>
|
||||
* 会创建一个在XY平面上居中的网格,单个格子尺寸为1。
|
||||
*/
|
||||
struct PlaneGridCreateInfo
|
||||
{
|
||||
Vector3f coord[4];
|
||||
Vector2u step;
|
||||
Size2u grid_size; ///<格子数量
|
||||
|
||||
Vector2u side_step; //到边界的步数
|
||||
Size2u sub_count; ///<细分格子数量
|
||||
|
||||
Color4f color; //一般线条颜色
|
||||
Color4f side_color; //边界线条颜色
|
||||
uint8 lum; ///<一般线条亮度
|
||||
uint8 sub_lum; ///<细分及边界线条亮度
|
||||
};//struct PlaneGridCreateInfo
|
||||
|
||||
/**
|
||||
* 创建一个平面网格(线条)
|
||||
*/
|
||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
|
||||
Primitive *CreatePlaneGrid2D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci); //创建一个平面网格(线条)
|
||||
|
||||
struct PlaneCreateInfo
|
||||
{
|
||||
Vector2f tile;
|
||||
|
||||
public:
|
||||
|
||||
PlaneCreateInfo()
|
||||
{
|
||||
tile.x=1.0f;
|
||||
tile.y=1.0f;
|
||||
}
|
||||
};//struct PlaneCreateInfo
|
||||
Primitive *CreatePlaneGrid3D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci);
|
||||
|
||||
/**
|
||||
* 创建一个平面(三角形)
|
||||
* 创建一个平面正方形(三角形)
|
||||
*/
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci);
|
||||
Primitive *CreatePlaneSqaure(PrimitiveCreater *pc);
|
||||
|
||||
struct CubeCreateInfo
|
||||
{
|
||||
@ -129,7 +131,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个立方体(三角形)
|
||||
*/
|
||||
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci);
|
||||
Primitive *CreateCube(PrimitiveCreater *pc,const CubeCreateInfo *cci);
|
||||
|
||||
struct BoundingBoxCreateInfo
|
||||
{
|
||||
@ -160,17 +162,17 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个绑定盒(线条)
|
||||
*/
|
||||
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci);
|
||||
Primitive *CreateBoundingBox(PrimitiveCreater *pc,const BoundingBoxCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个球心坐标为0,0,0,半径为1的球体(三角形)
|
||||
*/
|
||||
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices);
|
||||
Primitive *CreateSphere(PrimitiveCreater *,const uint numberSlices);
|
||||
|
||||
/**
|
||||
* 创建一个穹顶(三角形)
|
||||
*/
|
||||
Primitive *CreateDome(RenderResource *db,const VIL *vil, const uint numberSlices);
|
||||
Primitive *CreateDome(PrimitiveCreater *pc, const uint numberSlices);
|
||||
|
||||
struct TorusCreateInfo
|
||||
{
|
||||
@ -186,7 +188,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆环(三角形)
|
||||
*/
|
||||
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci);
|
||||
Primitive *CreateTorus(PrimitiveCreater *pc,const TorusCreateInfo *tci);
|
||||
|
||||
struct CylinderCreateInfo
|
||||
{
|
||||
@ -198,7 +200,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆柱(三角形)
|
||||
*/
|
||||
Primitive *CreateCylinder(RenderResource *db,const VIL *vil,const CylinderCreateInfo *cci);
|
||||
Primitive *CreateCylinder(PrimitiveCreater *,const CylinderCreateInfo *cci);
|
||||
|
||||
struct ConeCreateInfo
|
||||
{
|
||||
@ -211,7 +213,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆锥(三角形)
|
||||
*/
|
||||
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci);
|
||||
Primitive *CreateCone(PrimitiveCreater *,const ConeCreateInfo *cci);
|
||||
|
||||
struct AxisCreateInfo
|
||||
{
|
||||
@ -232,7 +234,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个坐标线(线条)
|
||||
*/
|
||||
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci);
|
||||
Primitive *CreateAxis(PrimitiveCreater *pc,const AxisCreateInfo *aci);
|
||||
}//namespace inline_geometry
|
||||
}//namespace graph
|
||||
};//namespace hgl
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user