Compare commits
391 Commits
debug_util
...
devel_27_D
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
99939bd83d |
Submodule CMAssetsManage updated: 1e14c1b01d...9582bfafcc
2
CMCore
2
CMCore
Submodule CMCore updated: ac5931ce26...2f93a1bb00
Submodule CMPlatform updated: ef90beb450...c9a1298e02
Submodule CMSceneGraph updated: ee17ef4c80...0c9bdb9fcd
2
CMUtil
2
CMUtil
Submodule CMUtil updated: 9f94d5082b...953ecf8079
@@ -24,6 +24,7 @@ SET(ULRE CMCore
|
||||
CMSceneGraph
|
||||
CMUtil
|
||||
ULRE.Util
|
||||
ULRE.ShaderGen
|
||||
ULRE.SceneGraph
|
||||
${HGL_GLM_LIB}
|
||||
${RENDER_LIBRARY}
|
||||
|
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 TextureColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureColor,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 TextureColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureColor,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 TextureColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=texture(TextureColor,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;
|
||||
}
|
||||
}
|
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
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
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 |
BIN
doc/Gizmo.odg
Normal file
BIN
doc/Gizmo.odg
Normal file
Binary file not shown.
@@ -37,9 +37,9 @@ private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_color_material =nullptr;
|
||||
DeviceBuffer * ubo_line_config =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_color_material =nullptr;
|
||||
DeviceBuffer * ubo_line_config =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
@@ -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;
|
||||
|
@@ -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;
|
||||
|
16
example/Basic/CMakeLists.txt
Normal file
16
example/Basic/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/Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
|
||||
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
|
||||
CreateProject(03_auto_instance auto_instance.cpp)
|
||||
CreateProject(04_auto_merge_material_instance auto_merge_material_instance.cpp)
|
@@ -1,29 +1,32 @@
|
||||
// second_triangle
|
||||
// 该范例主要演示使用场景树系统绘制三角形
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
constexpr uint32_t SCREEN_WIDTH=1024;
|
||||
constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
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}
|
||||
0.0, 0.0,
|
||||
-0.1, 0.9,
|
||||
0.1, 0.9
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{ {1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||
{ {255,0,0,255},
|
||||
{0,255,0,255},
|
||||
{0,0,255,255}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
@@ -42,37 +45,48 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
}
|
||||
|
||||
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);
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
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);
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
render_root.CreateSubNode(render_obj);
|
||||
|
||||
for(uint i=0;i<12;i++)
|
||||
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -102,7 +116,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
151
example/Basic/auto_merge_material_instance.cpp
Normal file
151
example/Basic/auto_merge_material_instance.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1024;
|
||||
constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
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;
|
||||
|
||||
#define USE_MATERIAL_FILE true //是否使用材质文件
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Renderable * r;
|
||||
}render_obj[DRAW_OBJECT_COUNT]{};
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
#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,Prim::Triangles);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
render_root.CreateSubNode(rotate(deg2rad(360/DRAW_OBJECT_COUNT*i),Vector3f(0,0,1)),render_obj[i].r);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&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(!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 **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,12 +1,13 @@
|
||||
// first_triangle
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
// 该范例主要演示使用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/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -61,6 +62,10 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
|
||||
VILConfig vil_config;
|
||||
#endif
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
@@ -68,11 +73,8 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
void InitVIL()
|
||||
{
|
||||
#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
|
||||
@@ -80,24 +82,33 @@ private:
|
||||
#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//
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
// 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;
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
@@ -117,7 +128,12 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
InitVIL();
|
||||
|
||||
if(!InitAutoMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
@@ -129,7 +145,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
134
example/Basic/draw_triangle_use_UBO.cpp
Normal file
134
example/Basic/draw_triangle_use_UBO.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.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 uint16 position_data_u16[VERTEX_COUNT][2]={};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
{
|
||||
255,0,0,255,
|
||||
0,255,0,255,
|
||||
0,0,255,255
|
||||
};
|
||||
|
||||
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
#else
|
||||
cfg.coordinate_system=CoordinateSystem2D::Ortho;
|
||||
|
||||
cfg.position_format =VAT_UVEC2; //这里指定shader中使用uvec2当做顶点输入格式
|
||||
// ^
|
||||
// + 这上下两种格式要配套,否则会出错
|
||||
// v
|
||||
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VBO中使用RG16U当做顶点数据格式
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VBO中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&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,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data_float ))return(false);
|
||||
#else //使用ortho坐标系
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
#ifndef USE_ZERO2ONE_COORD
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data_u16[i][0]=position_data_float[i][0]*w;
|
||||
position_data_u16[i][1]=position_data_float[i][1]*h;
|
||||
}
|
||||
#endif//
|
||||
|
||||
if(!InitMaterial())
|
||||
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 **)
|
||||
{
|
||||
RunApp<TestApp>(1280,720);
|
||||
}
|
@@ -2,6 +2,23 @@
|
||||
|
||||
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()
|
||||
|
||||
|
30
example/Gizmo/BlenderAxis.cpp
Normal file
30
example/Gizmo/BlenderAxis.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Blender axis
|
||||
/**
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* 0+---------->>>> X
|
||||
* 1|
|
||||
* 2|
|
||||
* 3| +--+
|
||||
* 4| +--+
|
||||
* 5|
|
||||
* 6V
|
||||
* 7V
|
||||
*
|
||||
* 坐标轴参考Blender设计
|
||||
*
|
||||
* 单方向坐标轴长度为8
|
||||
* 最终箭头长度为2
|
||||
*
|
||||
* 负责2D平移的方块尺寸为1,位置在3-4
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 缩放工具
|
||||
*/
|
||||
class GizmoScale
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
};//class GizmoScale
|
19
example/Gizmo/CMakeLists.txt
Normal file
19
example/Gizmo/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
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_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(02_RayPicking RayPicking.cpp)
|
||||
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
||||
|
||||
CreateProject(04_Gizmo3DMove Gizmo3DMove.cpp Gizmo.h Gizmo.cpp)
|
||||
|
||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
0
example/Gizmo/Gizmo.cpp
Normal file
0
example/Gizmo/Gizmo.cpp
Normal file
16
example/Gizmo/Gizmo.h
Normal file
16
example/Gizmo/Gizmo.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class Gizmo
|
||||
{
|
||||
Material * material;
|
||||
MaterialInstance * mi;
|
||||
Pipeline * pipeline;
|
||||
Primitive * primitive;
|
||||
|
||||
};//class Gizmo
|
||||
|
||||
VK_NAMESPACE_END
|
228
example/Gizmo/Gizmo3DMove.cpp
Normal file
228
example/Gizmo/Gizmo3DMove.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
// Gizmo 3D Move
|
||||
|
||||
#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/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_vtx_lum =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_vtx_lum =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Material * mtl_vtx_color =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
Pipeline * pipeline_vtx_color =nullptr;
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_vtx_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_vtx_lum)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_vtx_lum,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_vtx_lum=CreatePipeline(mtl_vtx_lum,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline_vtx_lum)
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_vtx_color=db->LoadMaterial("Std3D/VertexColor3D",&cfg);
|
||||
if(!mtl_vtx_color)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(mtl_vtx_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
{
|
||||
const PipelineData *ipd=GetPipelineData(InlinePipeline::Solid3D);
|
||||
|
||||
if(!ipd)
|
||||
return(false);
|
||||
|
||||
PipelineData *pd=new PipelineData(ipd);
|
||||
|
||||
pd->SetLineWidth(2);
|
||||
|
||||
pipeline_vtx_color=CreatePipeline(mtl_vtx_color,pd,Prim::Lines);
|
||||
|
||||
delete pd;
|
||||
|
||||
if(!pipeline_vtx_color)
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
/**
|
||||
* д<><D0B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* \param pos Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
|
||||
* \param max_line <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* \param oa1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
|
||||
* \param oa2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void WriteAxisPosition(Vector3f *pos,const Vector3f &max_line,const Vector3f &oa1,const Vector3f &oa2)
|
||||
{
|
||||
constexpr const float AXIS_LENGTH =4;
|
||||
constexpr const float AXIS_MIN_STEP =1;
|
||||
constexpr const float AXIS_ARROW_SIZE=0.25;
|
||||
|
||||
const Vector3f end_pos =max_line*AXIS_LENGTH; ///<<3C><><EFBFBD>յ<EFBFBD>λ<EFBFBD><CEBB>
|
||||
const Vector3f cross_pos=max_line*AXIS_MIN_STEP; ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
const Vector3f arrow_pos=max_line*(AXIS_LENGTH-AXIS_MIN_STEP); ///<<3C><>ͷĩ<CDB7><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>λ<EFBFBD><CEBB>
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
pos[0]=Vector3f(0, 0, 0);
|
||||
pos[1]=end_pos;
|
||||
|
||||
//<2F>ĸ<EFBFBD><C4B8><EFBFBD>ͷ<EFBFBD><CDB7>
|
||||
pos[2]=end_pos;
|
||||
pos[3]=arrow_pos-oa1*AXIS_ARROW_SIZE;
|
||||
|
||||
pos[4]=end_pos;
|
||||
pos[5]=arrow_pos+oa1*AXIS_ARROW_SIZE;
|
||||
|
||||
pos[6]=end_pos;
|
||||
pos[7]=arrow_pos-oa2*AXIS_ARROW_SIZE;
|
||||
|
||||
pos[8]=end_pos;
|
||||
pos[9]=arrow_pos+oa2*AXIS_ARROW_SIZE;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
pos[10]=cross_pos;
|
||||
pos[11]=cross_pos+oa1*AXIS_MIN_STEP;
|
||||
pos[12]=cross_pos;
|
||||
pos[13]=cross_pos+oa2*AXIS_MIN_STEP;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
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(db,mtl_vtx_lum->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
constexpr const uint AXIS_MAX_LINES =7;
|
||||
constexpr const uint AXIS_MAX_VERTICES =AXIS_MAX_LINES*2*3;
|
||||
|
||||
ro_line=db->CreatePrimitive("Line",AXIS_MAX_VERTICES);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
Vector3f position_data[3][AXIS_MAX_LINES*2];
|
||||
|
||||
WriteAxisPosition(position_data[0],Vector3f(1,0,0),Vector3f(0,1,0),Vector3f(0,0,1));
|
||||
WriteAxisPosition(position_data[1],Vector3f(0,1,0),Vector3f(1,0,0),Vector3f(0,0,1));
|
||||
WriteAxisPosition(position_data[2],Vector3f(0,0,1),Vector3f(1,0,0),Vector3f(0,1,0));
|
||||
|
||||
Color4f color_data[3][AXIS_MAX_LINES*2];
|
||||
|
||||
for(Color4f &c:color_data[0])c=Color4f(1,0,0,1);
|
||||
for(Color4f &c:color_data[1])c=Color4f(0,1,0,1);
|
||||
for(Color4f &c:color_data[2])c=Color4f(0,0,1,1);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, db->CreateVBO(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_vtx_lum);
|
||||
Add(ro_line,mi_line,pipeline_vtx_color);
|
||||
|
||||
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) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
142
example/Gizmo/MetricCellsGrid.cpp
Normal file
142
example/Gizmo/MetricCellsGrid.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
// Metric Cells Grid
|
||||
|
||||
#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/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
struct MetricCellsGridData
|
||||
{
|
||||
Color4f x_color;
|
||||
Color4f y_color;
|
||||
Color4f x_axis_color;
|
||||
Color4f y_axis_color;
|
||||
Color4f center_color;
|
||||
|
||||
Vector2f lum;
|
||||
Vector2f cell_step;
|
||||
Vector2f big_cell_step;
|
||||
Vector2f scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
};
|
||||
|
||||
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
|
||||
|
||||
constexpr const float PLANE_SIZE=1024;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MetricCellsGridData mcg_data;
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"MetricCellsGrid",Prim::Fan);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/MetricCellsGrid",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
{
|
||||
mcg_data.x_color=Color4f(1,1,1,1);
|
||||
mcg_data.y_color=Color4f(1,1,1,1);
|
||||
|
||||
mcg_data.x_axis_color=GetColor4f(COLOR::BlenderAxisRed, 1.0);
|
||||
mcg_data.y_axis_color=GetColor4f(COLOR::BlenderAxisGreen, 1.0);
|
||||
|
||||
mcg_data.center_color=Color4f(1,1,0,1);
|
||||
|
||||
mcg_data.lum =Vector2f(0.1,0.2);
|
||||
mcg_data.cell_step =Vector2f(8,8);
|
||||
mcg_data.big_cell_step =Vector2f(32,32);
|
||||
mcg_data.scale =Vector2f(PLANE_SIZE,PLANE_SIZE);
|
||||
|
||||
mcg_data.axis_line_width=1.0;
|
||||
mcg_data.center_radius =4.0;
|
||||
}
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material,nullptr,&mcg_data);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Fan);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
ro_plane=inline_geometry::CreatePlane(db,material->GetDefaultVIL());
|
||||
|
||||
return ro_plane;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(ro_plane,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
|
||||
|
||||
camera->pos=Vector3f(PLANE_SIZE/2,PLANE_SIZE/2,PLANE_SIZE/4);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
123
example/Gizmo/PlaneGrid3D.cpp
Normal file
123
example/Gizmo/PlaneGrid3D.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
// PlaneGrid3D
|
||||
|
||||
#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/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
MaterialInstance * material_instance[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
Color4f GridColor;
|
||||
COLOR ce=COLOR::BlenderAxisRed;
|
||||
|
||||
for(uint i=0;i<3;i++)
|
||||
{
|
||||
GridColor=GetColor4f(ce,1.0);
|
||||
|
||||
material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor);
|
||||
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
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=0.75;
|
||||
pgci.sub_lum=1.0;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
|
||||
|
||||
return prim_plane_grid;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(prim_plane_grid,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance[0],Matrix4f(1.0f));
|
||||
Add(material_instance[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(material_instance[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
168
example/Gizmo/RayPicking.cpp
Normal file
168
example/Gizmo/RayPicking.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
// 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>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float position_data[2][3]=
|
||||
{
|
||||
{100,100,100},
|
||||
{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 SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
VBO * vbo_pos =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(material,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(material,nullptr,&yellow_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
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(db,material->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
ro_line=db->CreatePrimitive("Line",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::Luminance, db->CreateVBO(VF_V1F,2,lumiance_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid);
|
||||
Add(ro_line,mi_line);
|
||||
|
||||
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(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
const CameraInfo &ci=GetCameraInfo();
|
||||
const ViewportInfo &vi=GetViewportInfo();
|
||||
|
||||
ray.Set(GetMouseCoord(),&ci,&vi); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
217
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
217
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
// 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>
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_blinnphong =nullptr;
|
||||
MaterialInstance * mi_blinnphong =nullptr;
|
||||
Pipeline * p_blinnphong =nullptr;
|
||||
|
||||
Primitive * prim_sphere =nullptr;
|
||||
Primitive * prim_cone =nullptr;
|
||||
Primitive * prim_cylinder =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitVertexLumMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::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,Prim::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->GetDeviceAttribute(),"BlinnPhong3D",Prim::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColor",&cfg);
|
||||
if(!mtl_blinnphong)return(false);
|
||||
|
||||
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_blinnphong->Update();
|
||||
|
||||
float mi_data[4]=
|
||||
{
|
||||
1,0,0, //color
|
||||
4 //gloss
|
||||
};
|
||||
|
||||
mi_blinnphong=db->CreateMaterialInstance(mtl_blinnphong,nullptr,&mi_data);
|
||||
if(!mi_blinnphong)return(false);
|
||||
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
|
||||
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(db,mtl_vertex_lum->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
|
||||
//Sphere
|
||||
prim_sphere=CreateSphere(db,mi_blinnphong->GetVIL(),16);
|
||||
|
||||
//Cone
|
||||
{
|
||||
struct ConeCreateInfo cci;
|
||||
|
||||
cci.radius =1; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=8; //圆锥高度分割数
|
||||
|
||||
prim_cone=CreateCone(db,mi_blinnphong->GetVIL(),&cci);
|
||||
}
|
||||
|
||||
//Cyliner
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =4; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =0.25f; //圆柱半径
|
||||
|
||||
prim_cylinder=CreateCylinder(db,mi_blinnphong->GetVIL(),&cci);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
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,p_blinnphong,translate(Vector3f(0,0,2)));
|
||||
Add(prim_cone, mi_blinnphong,p_blinnphong,Identity4f);
|
||||
Add(prim_cylinder, mi_blinnphong,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(!InitVertexLumMP())
|
||||
return(false);
|
||||
|
||||
if(!CreateBlinnPhongUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitBlinnPhongSunLightMP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//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>
|
||||
@@ -86,35 +87,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)<<data_type_name[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)<<data_type_name[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)<<data_type_name[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 "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
|
||||
else
|
||||
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";
|
||||
|
||||
std::cout<<std::endl;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
// 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/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -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;
|
||||
Renderable * 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->GetDeviceAttribute(),"PureTexture2D",Prim::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,Prim::Fan); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
@@ -73,23 +72,26 @@ private:
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
RenderablePrimitiveCreater rpc(db,"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.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -105,16 +107,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
|
||||
|
134
example/Texture/texture_rect.cpp
Normal file
134
example/Texture/texture_rect.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.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);
|
||||
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;
|
||||
Renderable * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2D",Prim::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,Prim::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::Color, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_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);
|
||||
|
||||
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;
|
||||
}
|
210
example/Texture/texture_rect_array.cpp
Normal file
210
example/Texture/texture_rect_array.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.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(GPUDevice *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;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Renderable * r;
|
||||
}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->GetDeviceAttribute(),"RectTexture2DArray",Prim::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,Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
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()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
|
||||
|
||||
position_data[2]=1.0f/float(TexCount);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
Vector3f offset(1.0f/float(TexCount),0,0);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
offset.x=position_data[2]*float(i);
|
||||
|
||||
render_root.CreateSubNode(translate(offset),render_obj[i].r);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
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;
|
||||
}
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
}
|
@@ -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,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;
|
||||
}
|
@@ -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:
|
||||
@@ -44,7 +55,7 @@ protected:
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
SwapchainRenderTarget * sc_render_target =nullptr;
|
||||
RTSwapchain * sc_render_target =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -59,15 +70,16 @@ protected:
|
||||
RenderResource * db =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
|
||||
ViewportInfo vp_info;
|
||||
DeviceBuffer * ubo_vp_info =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
SAFE_CLEAR(camera);
|
||||
CloseShaderCompiler();
|
||||
|
||||
win->Unjoin(this);
|
||||
|
||||
SAFE_CLEAR(db);
|
||||
@@ -78,9 +90,14 @@ public:
|
||||
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 +122,6 @@ public:
|
||||
|
||||
cili.lunarg.standard_validation = true;
|
||||
cili.khronos.validation = true;
|
||||
//cili.RenderDoc.Capture = true;
|
||||
|
||||
inst=CreateInstance("VulkanTest",nullptr,&cili);
|
||||
|
||||
@@ -113,10 +129,16 @@ public:
|
||||
return(false);
|
||||
}
|
||||
|
||||
device=CreateRenderDevice(inst,win);
|
||||
{
|
||||
VulkanHardwareRequirement vh_req;
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
vh_req.wide_lines=true;
|
||||
|
||||
device=CreateRenderDevice(inst,win,&vh_req);
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
}
|
||||
|
||||
device_render_pass=device->GetRenderPass();
|
||||
|
||||
@@ -127,48 +149,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;
|
||||
ubo_vp_info=db->CreateUBO("Viewport",sizeof(ViewportInfo),&vp_info);
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
camera->RefreshCameraInfo();
|
||||
|
||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
||||
db->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -204,7 +208,7 @@ 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->GetPhysicalDevice()->GetDeviceName()+AnsiString(":RenderCmdBuffer_")+AnsiString::numberOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,20 +216,20 @@ public:
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
const IndexBuffer *ib=ri->GetIndexBuffer();
|
||||
const VertexInputData *vid=ri->GetVertexInputData();
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(rp,fb);
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
cb->BindPipeline(ri->GetPipeline());
|
||||
cb->BindDescriptorSets(ri);
|
||||
cb->BindDescriptorSets(ri->GetMaterial());
|
||||
cb->BindVBO(ri);
|
||||
|
||||
if (ib)
|
||||
cb->DrawIndexed(ib->GetCount(),ri->GetInstanceCount());
|
||||
if (vid->index_buffer->buffer)
|
||||
cb->DrawIndexed(vid->index_buffer->buffer->GetCount());
|
||||
else
|
||||
cb->Draw(ri->GetDrawCount(),ri->GetInstanceCount());
|
||||
cb->Draw(vid->vertex_count);
|
||||
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
@@ -292,7 +296,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:
|
||||
|
||||
@@ -383,7 +402,7 @@ class CameraMouseControl:public MouseEvent
|
||||
Vector2f mouse_pos;
|
||||
Vector2f mouse_last_pos;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
bool OnPressed(int x,int y,MouseButton) override
|
||||
{
|
||||
@@ -453,9 +472,12 @@ public:
|
||||
|
||||
class CameraAppFramework:public VulkanApplicationFramework
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
|
||||
FirstPersonCameraControl *camera_control=nullptr;
|
||||
|
||||
CameraKeyboardControl * ckc=nullptr;
|
||||
@@ -469,9 +491,10 @@ public:
|
||||
{
|
||||
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);
|
||||
@@ -482,7 +505,11 @@ public:
|
||||
|
||||
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 +518,40 @@ 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());
|
||||
|
||||
db->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
|
||||
}
|
||||
|
||||
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 +562,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;
|
||||
}
|
@@ -21,7 +21,7 @@ namespace hgl
|
||||
~Bitmap2DLoader();
|
||||
|
||||
void *OnBegin(uint32 total_bytes) override;
|
||||
void OnEnd() override {}
|
||||
bool OnEnd() override {return(false);}
|
||||
|
||||
BitmapData *GetBitmap();
|
||||
};//class Bitmap2DLoader
|
||||
|
17
inc/hgl/graph/CoordinateSystem.h
Normal file
17
inc/hgl/graph/CoordinateSystem.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/TypeFunc.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
enum class CoordinateSystem2D
|
||||
{
|
||||
NDC,
|
||||
ZeroToOne, //左上角为0,0;右下角为1,1
|
||||
Ortho, //左上角为0,0;右下角为(width-1),(height-1)
|
||||
|
||||
ENUM_CLASS_RANGE(NDC,Ortho)
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@@ -4,6 +4,7 @@
|
||||
#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
|
||||
@@ -59,17 +60,17 @@ namespace hgl
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,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; //边界线条颜色
|
||||
float lum; ///<一般线条颜色
|
||||
float sub_lum; ///<细分及边界线条颜色
|
||||
};//struct PlaneGridCreateInfo
|
||||
|
||||
/**
|
||||
@@ -77,23 +78,10 @@ namespace hgl
|
||||
*/
|
||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
|
||||
|
||||
struct PlaneCreateInfo
|
||||
{
|
||||
Vector2f tile;
|
||||
|
||||
public:
|
||||
|
||||
PlaneCreateInfo()
|
||||
{
|
||||
tile.x=1.0f;
|
||||
tile.y=1.0f;
|
||||
}
|
||||
};//struct PlaneCreateInfo
|
||||
|
||||
/**
|
||||
* 创建一个平面(三角形)
|
||||
*/
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci);
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil);
|
||||
|
||||
struct CubeCreateInfo
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define HGL_GRAPH_LIGHT_INCLUDE
|
||||
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/Color4f.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
|
73
inc/hgl/graph/MaterialRenderList.h
Normal file
73
inc/hgl/graph/MaterialRenderList.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderAssignBuffer;
|
||||
|
||||
/**
|
||||
* 同一材质的对象渲染列表
|
||||
*/
|
||||
class MaterialRenderList
|
||||
{
|
||||
GPUDevice *device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
|
||||
Material *material;
|
||||
|
||||
RenderNodeList rn_list;
|
||||
|
||||
private:
|
||||
|
||||
RenderAssignBuffer *assign_buffer;
|
||||
|
||||
struct RenderItem
|
||||
{
|
||||
uint32_t first;
|
||||
uint32_t count;
|
||||
|
||||
Pipeline * pipeline;
|
||||
MaterialInstance * mi;
|
||||
const VertexInputData * vid;
|
||||
|
||||
public:
|
||||
|
||||
void Set(Renderable *);
|
||||
};
|
||||
|
||||
MaterialInstanceSets mi_set;
|
||||
DataArray<RenderItem> ri_array;
|
||||
uint ri_count;
|
||||
|
||||
void StatMI();
|
||||
void Stat();
|
||||
|
||||
protected:
|
||||
|
||||
VBOList * vbo_list;
|
||||
|
||||
Pipeline * last_pipeline;
|
||||
const VertexInputData * last_vid;
|
||||
uint last_index;
|
||||
|
||||
bool Bind(const VertexInputData *,const uint);
|
||||
|
||||
void Render(RenderItem *);
|
||||
|
||||
public:
|
||||
|
||||
MaterialRenderList(GPUDevice *d,Material *m);
|
||||
~MaterialRenderList();
|
||||
|
||||
void Add(Renderable *ri,const Matrix4f &mat);
|
||||
|
||||
void Clear()
|
||||
{
|
||||
rn_list.Clear();
|
||||
}
|
||||
|
||||
void End();
|
||||
|
||||
void Render(RenderCmdBuffer *);
|
||||
};//class MaterialRenderList
|
||||
VK_NAMESPACE_END
|
32
inc/hgl/graph/MaterialRenderMap.h
Normal file
32
inc/hgl/graph/MaterialRenderMap.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/MaterialRenderList.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
|
||||
{
|
||||
public:
|
||||
|
||||
MaterialRenderMap()=default;
|
||||
virtual ~MaterialRenderMap()=default;
|
||||
|
||||
void Begin()
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
it->value->Clear();
|
||||
}
|
||||
|
||||
void End()
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
it->value->End();
|
||||
}
|
||||
|
||||
void Render(RenderCmdBuffer *rcb)
|
||||
{
|
||||
if(!rcb)return;
|
||||
|
||||
for(auto *it:data_list)
|
||||
it->value->Render(rcb);
|
||||
}
|
||||
};//class MaterialRenderMap
|
||||
VK_NAMESPACE_END
|
@@ -8,28 +8,28 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct ShaderStageBind
|
||||
{
|
||||
AnsiString name;
|
||||
uint binding;
|
||||
VAD * data =nullptr;
|
||||
VBO * vbo =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~ShaderStageBind()
|
||||
{
|
||||
SAFE_CLEAR(data);
|
||||
}
|
||||
};//struct ShaderStageBind
|
||||
|
||||
using ShaderStageBindMap=ObjectMap<AnsiString,ShaderStageBind>;
|
||||
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
struct PrimitiveVertexBuffer
|
||||
{
|
||||
AnsiString name;
|
||||
uint binding;
|
||||
VAD * data =nullptr;
|
||||
VBO * vbo =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~PrimitiveVertexBuffer()
|
||||
{
|
||||
SAFE_CLEAR(data);
|
||||
}
|
||||
};//struct PrimitiveVertexBuffer
|
||||
|
||||
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
|
||||
|
||||
protected:
|
||||
|
||||
RenderResource *db;
|
||||
@@ -42,7 +42,7 @@ namespace hgl
|
||||
uint32 vertices_number;
|
||||
|
||||
IndexBuffer * ibo;
|
||||
ShaderStageBindMap ssb_map;
|
||||
PVBMap vbo_map;
|
||||
|
||||
public:
|
||||
|
||||
@@ -54,9 +54,9 @@ namespace hgl
|
||||
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
||||
|
||||
template<typename T>
|
||||
T * CreateVADA(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||
T * AccessVAD(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||
{
|
||||
const VkFormat format=vil->GetFormat(name);
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
@@ -66,11 +66,11 @@ namespace hgl
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
|
||||
T *vada=T::Create(vad);
|
||||
T *access=T::Create(vad);
|
||||
|
||||
vada->Begin();
|
||||
access->Begin();
|
||||
|
||||
return vada;
|
||||
return access;
|
||||
}
|
||||
|
||||
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
@@ -78,7 +78,7 @@ namespace hgl
|
||||
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
|
||||
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
|
||||
|
||||
virtual Primitive * Finish(); ///<结束并创建可渲染对象
|
||||
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -2,72 +2,42 @@
|
||||
#define HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/MaterialRenderMap.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using MVPArrayBuffer=GPUArrayBuffer<MVPMatrix>;
|
||||
using MaterialSets=SortedSets<Material *>;
|
||||
|
||||
/**
|
||||
* 渲染对象列表<br>
|
||||
* 已经展开的渲染对象列表,产生mvp用UBO/SSBO等数据,最终创建RenderCommandBuffer
|
||||
* 该类会长期保存使用过的材质信息,避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
|
||||
*/
|
||||
class RenderList
|
||||
{
|
||||
GPUDevice * device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
protected:
|
||||
|
||||
private:
|
||||
GPUDevice * device;
|
||||
|
||||
CameraInfo camera_info;
|
||||
|
||||
RenderNodeList render_node_list; ///<场景节点列表
|
||||
MaterialSets material_sets; ///<材质合集
|
||||
|
||||
RenderNodeComparator render_node_comparator;
|
||||
|
||||
private:
|
||||
|
||||
MVPArrayBuffer *mvp_array;
|
||||
List<Renderable *> ri_list;
|
||||
|
||||
VkDescriptorSet ds_list[(size_t)DescriptorSetType::RANGE_SIZE];
|
||||
DescriptorSet *renderable_desc_sets;
|
||||
|
||||
uint32_t ubo_offset;
|
||||
uint32_t ubo_align;
|
||||
uint renderable_count; ///<可渲染对象数量
|
||||
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool Begin();
|
||||
virtual bool Expend(SceneNode *);
|
||||
virtual void End();
|
||||
|
||||
private:
|
||||
|
||||
Pipeline * last_pipeline;
|
||||
MaterialParameters *last_mp[(size_t)DescriptorSetType::RANGE_SIZE];
|
||||
uint32_t last_vbo;
|
||||
|
||||
void Render(Renderable *);
|
||||
virtual bool ExpendNode(SceneNode *);
|
||||
|
||||
public:
|
||||
|
||||
RenderList(GPUDevice *);
|
||||
virtual ~RenderList();
|
||||
|
||||
virtual bool Expend(const CameraInfo &,SceneNode *);
|
||||
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
|
||||
|
||||
virtual bool Render(RenderCmdBuffer *);
|
||||
};//class RenderList
|
||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
};//class RenderList
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
|
@@ -1,39 +1,29 @@
|
||||
#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
#define HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
||||
#include<hgl/math/Vector.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Renderable;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class GPUDevice;
|
||||
struct VertexInputData;
|
||||
struct IndexBufferData;
|
||||
|
||||
struct RenderNode
|
||||
{
|
||||
MVPMatrix matrix;
|
||||
|
||||
Vector3f WorldCenter;
|
||||
|
||||
float distance_to_camera_square;
|
||||
// float distance_to_camera;
|
||||
Matrix4f local_to_world;
|
||||
|
||||
Renderable *ri;
|
||||
};
|
||||
|
||||
public:
|
||||
using RenderNodeList=List<RenderNode>;
|
||||
|
||||
/**
|
||||
* 取得渲染对象ubo独占区大小
|
||||
*/
|
||||
virtual const uint32 GetUBOBytes()const{return sizeof(MVPMatrix);}
|
||||
};//struct RenderNode
|
||||
|
||||
using RenderNodeList=List<RenderNode *>;
|
||||
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
||||
using RenderNodePointer=hgl::graph::RenderNode *;
|
||||
using RenderNodeComparator=Comparator<RenderNodePointer>;
|
||||
|
||||
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
84
inc/hgl/graph/RenderResourceType.h
Normal file
84
inc/hgl/graph/RenderResourceType.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
enum class ResourceType
|
||||
{
|
||||
Unknown=0,
|
||||
|
||||
VkInstance,
|
||||
VkPhysicalDevice,
|
||||
VkDevice,
|
||||
|
||||
VertexInputLayout,
|
||||
Material,
|
||||
MaterialInstance,
|
||||
|
||||
FrameBuffer,
|
||||
|
||||
Texture,
|
||||
Sampler,
|
||||
|
||||
VertexBuffer,
|
||||
IndexBuffer,
|
||||
IndirectBuffer,
|
||||
UniformBuffer,
|
||||
StorageBuffer,
|
||||
|
||||
Skeleton, ///<骨骼信息
|
||||
SkeletonAnime, ///<骨骼动画信息
|
||||
|
||||
Primitive, ///<原始的单个模型数据,由多个VBO+Index组成
|
||||
RawMesh, ///<原始的静态模型数据,由一个Primitive和一个MaterialInstance组成
|
||||
StaticMesh, ///<静态模型数据,由一个或多个RawMesh组成
|
||||
SkeletonMesh, ///<骨骼模型数据,由一个或多个StaticMesh组成
|
||||
|
||||
Font,
|
||||
|
||||
Scene,
|
||||
Animation,
|
||||
Audio,
|
||||
Other,
|
||||
|
||||
ENUM_CLASS_RANGE(Unknown,Other)
|
||||
};
|
||||
|
||||
enum class ResourcePlace
|
||||
{
|
||||
Unknown=0,
|
||||
|
||||
Memory, ///<内存
|
||||
Device, ///<设备(如显存)
|
||||
Disk, ///<硬盘
|
||||
LAN, ///<局域网
|
||||
WAN, ///<广域网
|
||||
Other,
|
||||
|
||||
ENUM_CLASS_RANGE(Device,Other)
|
||||
};
|
||||
|
||||
struct RenderResourceID
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint device:1; ///<在设备
|
||||
uint memory:1; ///<在内存
|
||||
|
||||
uint disk:1; ///<在硬盘
|
||||
uint network:1; ///<在网络
|
||||
};
|
||||
|
||||
uint8 place; ///<数据所在位置
|
||||
};
|
||||
|
||||
uint16 resource_type; ///<资源类型,对应ResourceType枚举
|
||||
|
||||
uint16 thread_id; ///<线程ID
|
||||
|
||||
uint32 id; ///<资源ID
|
||||
};
|
||||
VK_NAMESPACE_END
|
18
inc/hgl/graph/RenderTargetOutputConfig.h
Normal file
18
inc/hgl/graph/RenderTargetOutputConfig.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
|
||||
#define HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct RenderTargetOutputConfig
|
||||
{
|
||||
uint color; ///<要输出几个颜色缓冲区
|
||||
bool depth; ///<是否输出到深度缓冲区
|
||||
bool stencil; ///<是否输出到模板缓冲区
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
|
@@ -7,7 +7,7 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* MVP矩阵
|
||||
*/
|
||||
struct MVPMatrix
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/graph/SceneOrient.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
@@ -43,7 +43,7 @@ namespace hgl
|
||||
|
||||
void Clear()
|
||||
{
|
||||
SubNode.ClearData();
|
||||
SubNode.Clear();
|
||||
render_obj=nullptr;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ namespace hgl
|
||||
|
||||
SceneNode *CreateSubNode(Renderable *ri)
|
||||
{
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
SceneNode *sn=new SceneNode(ri);
|
||||
|
||||
SubNode.Add(sn);
|
||||
@@ -76,6 +79,9 @@ namespace hgl
|
||||
|
||||
SceneNode *CreateSubNode(const Matrix4f &mat,Renderable *ri)
|
||||
{
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
SceneNode *sn=new SceneNode(mat,ri);
|
||||
|
||||
SubNode.Add(sn);
|
||||
|
25
inc/hgl/graph/StaticRenderManager.h
Normal file
25
inc/hgl/graph/StaticRenderManager.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
||||
#define HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class RawMesh
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* 静态渲染管理器<br>
|
||||
* 静态渲染指的是不会产生资源变动的内容,而不是指不会动的内容。
|
||||
*/
|
||||
class StaticRenderManager
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual ~StaticRenderManager()=default;
|
||||
|
||||
};//class StaticRenderManager
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
@@ -3,8 +3,8 @@
|
||||
|
||||
#include<hgl/io/InputStream.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/Bitmap.h>
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/graph/BitmapData.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@@ -86,7 +86,7 @@ namespace hgl
|
||||
protected:
|
||||
|
||||
virtual void *OnBegin(uint32)=0;
|
||||
virtual void OnEnd()=0;
|
||||
virtual bool OnEnd()=0;
|
||||
virtual void OnError(){}
|
||||
|
||||
public:
|
||||
@@ -207,7 +207,7 @@ namespace hgl
|
||||
{
|
||||
protected: // override functions
|
||||
|
||||
uint32 GetPixelsCount()const override{return file_header.length;}
|
||||
uint32 GetPixelsCount()const override{return file_header.length*file_header.layers;}
|
||||
uint32 GetTotalBytes()const override
|
||||
{
|
||||
if(file_header.mipmaps<=1)
|
||||
@@ -230,7 +230,7 @@ namespace hgl
|
||||
{
|
||||
protected: // override functions
|
||||
|
||||
uint32 GetPixelsCount()const override{return file_header.width*file_header.height;}
|
||||
uint32 GetPixelsCount()const override{return file_header.width*file_header.height*file_header.layers;}
|
||||
uint32 GetTotalBytes()const override
|
||||
{
|
||||
if(file_header.mipmaps<=1)
|
||||
|
@@ -1,32 +1,17 @@
|
||||
#ifndef HGL_GRAPH_TILE_DATA_INCLUDE
|
||||
#define HGL_GRAPH_TILE_DATA_INCLUDE
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/Pool.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/graph/Bitmap.h>
|
||||
#include<hgl/graph/BitmapData.h>
|
||||
#include<hgl/graph/ImageRegion.h>
|
||||
#include<hgl/graph/tile/TileObject.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
VK_NAMESPACE_USING
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using TileUVPixel=RectScope2i;
|
||||
using TileUVFloat=RectScope2f;
|
||||
|
||||
using TileUVFloatList=List<TileUVFloat>;
|
||||
using TileUVFloatMap=Map<u32char,TileUVFloat>;
|
||||
|
||||
struct TileObject
|
||||
{
|
||||
int col,row; //当前tile在整个纹理中的tile位置
|
||||
|
||||
TileUVPixel uv_pixel; //以象素为单位的tile位置和尺寸
|
||||
TileUVFloat uv_float; //以浮点为单位的tile位置和尺寸
|
||||
};//struct TileObject
|
||||
|
||||
/**
|
||||
* TileData是一种处理大量等同尺寸及格式贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注:Tile的大小不必符合2次幂)
|
||||
* Tile的增加或删除,程序会自动排序,尽可能小的减少I/O消耗。
|
||||
|
@@ -1,11 +1,10 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INCLUDE
|
||||
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<iostream>
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/graph/VKPrimitiveType.h>
|
||||
@@ -27,18 +26,20 @@ constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_D
|
||||
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
|
||||
|
||||
using CharPointerList=hgl::List<const char *>;
|
||||
using BindingMapping=Map<uint32_t,int>;
|
||||
|
||||
using BindingMap =Map<AnsiString,int>;
|
||||
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
class VulkanInstance;
|
||||
class GPUPhysicalDevice;
|
||||
class GPUDevice;
|
||||
struct GPUDeviceAttribute;
|
||||
class Queue;
|
||||
class DeviceQueue;
|
||||
class ImageView;
|
||||
class Framebuffer;
|
||||
struct Swapchain;
|
||||
class RenderTarget;
|
||||
class SwapchainRenderTarget;
|
||||
class RTSwapchain;
|
||||
|
||||
class Texture;
|
||||
class Texture1D;
|
||||
@@ -60,6 +61,12 @@ using VBO=VertexAttribBuffer;
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
struct IndexBufferData
|
||||
{
|
||||
IndexBuffer *buffer=nullptr;
|
||||
VkDeviceSize offset=0;
|
||||
};
|
||||
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
class TextureCmdBuffer;
|
||||
@@ -70,43 +77,15 @@ class DeviceRenderPassManage;
|
||||
class Fence;
|
||||
class Semaphore;
|
||||
|
||||
enum class DescriptorSetType
|
||||
{
|
||||
//设计使其对应shader中的set
|
||||
|
||||
Global=0, ///<全局参数(如太阳光等)
|
||||
PerFrame, ///<帧参数(如摄像机等)
|
||||
PerMaterialInstance,///<材质实例参数(如纹理等)
|
||||
PerObject, ///<对象参数(如模型矩阵等)
|
||||
|
||||
Instance,
|
||||
Skeleton,
|
||||
|
||||
ENUM_CLASS_RANGE(Global,Skeleton)
|
||||
};//
|
||||
|
||||
constexpr char *DescriptSetsTypeName[]=
|
||||
{
|
||||
"Global","PerFrame","PerMaterialInstance","PerObject","Instance","Skeleton"
|
||||
};
|
||||
|
||||
inline const char *GetDescriptorSetTypeName(const enum class DescriptorSetType &type)
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(type);
|
||||
|
||||
return DescriptSetsTypeName[(size_t)type];
|
||||
}
|
||||
|
||||
struct PipelineLayoutData;
|
||||
class DescriptorSet;
|
||||
|
||||
struct ShaderStage;
|
||||
struct ShaderAttribute;
|
||||
|
||||
class ShaderResource;
|
||||
class ShaderModule;
|
||||
class VertexShaderModule;
|
||||
class ShaderModuleMap;
|
||||
class MaterialDescriptorSets;
|
||||
class MaterialDescriptorManager;
|
||||
|
||||
class Material;
|
||||
class MaterialParameters;
|
||||
@@ -115,39 +94,11 @@ struct PipelineData;
|
||||
enum class InlinePipeline;
|
||||
class Pipeline;
|
||||
|
||||
struct VAConfig
|
||||
{
|
||||
VkFormat format;
|
||||
bool instance;
|
||||
struct VAConfig;
|
||||
class VILConfig;
|
||||
class VertexInput;
|
||||
|
||||
public:
|
||||
|
||||
VAConfig()
|
||||
{
|
||||
format=PF_UNDEFINED;
|
||||
instance=false;
|
||||
}
|
||||
|
||||
VAConfig(const VkFormat fmt,bool inst=false)
|
||||
{
|
||||
format=fmt;
|
||||
instance=inst;
|
||||
}
|
||||
|
||||
CompOperatorMemcmp(const VAConfig &);
|
||||
};
|
||||
|
||||
class VILConfig:public Map<AnsiString,VAConfig>
|
||||
{
|
||||
public:
|
||||
|
||||
using Map<AnsiString,VAConfig>::Map;
|
||||
|
||||
bool Add(const AnsiString &name,const VkFormat fmt,const bool inst=false)
|
||||
{
|
||||
return Map<AnsiString,VAConfig>::Add(name,VAConfig(fmt,inst));
|
||||
}
|
||||
};
|
||||
struct VertexInputFormat;
|
||||
|
||||
class VertexInputLayout;
|
||||
using VIL=VertexInputLayout;
|
||||
@@ -188,51 +139,17 @@ inline const uint32_t GetMipLevel(const VkExtent3D &ext)
|
||||
/**
|
||||
* 索引类型,等同于VkIndexType
|
||||
*/
|
||||
enum IndexType
|
||||
enum IndexType:uint
|
||||
{
|
||||
U16=0,
|
||||
U32
|
||||
U32,
|
||||
U8=VK_INDEX_TYPE_UINT8_EXT,
|
||||
};
|
||||
|
||||
enum class ShaderStageBit
|
||||
{
|
||||
Vertex =VK_SHADER_STAGE_VERTEX_BIT,
|
||||
TessControl =VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
|
||||
TessEval =VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
|
||||
Geometry =VK_SHADER_STAGE_GEOMETRY_BIT,
|
||||
Fragment =VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
Compute =VK_SHADER_STAGE_COMPUTE_BIT
|
||||
};//enum class ShaderStageBit
|
||||
|
||||
inline const uint GetShaderCountByBits(const uint32_t bits)
|
||||
{
|
||||
uint comp=(uint)VK_SHADER_STAGE_VERTEX_BIT;
|
||||
uint result=0;
|
||||
|
||||
for(uint i=0;i<6;i++)
|
||||
{
|
||||
if(bits&comp)
|
||||
++result;
|
||||
|
||||
comp<<=1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* max-lengths:
|
||||
*
|
||||
256 bytes: nvidia,arm
|
||||
128 bytes: amd,intel,powervr,adreno
|
||||
*/
|
||||
struct PushConstant
|
||||
{
|
||||
Matrix4f local_to_world;
|
||||
Matrix4f normal;
|
||||
};
|
||||
|
||||
constexpr uint32_t MAX_PUSH_CONSTANT_BYTES=sizeof(PushConstant);
|
||||
//Push Constant max-lengths:
|
||||
//
|
||||
// 256 bytes: nvidia,arm
|
||||
// 128 bytes: amd,intel,powervr,adreno
|
||||
|
||||
inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
|
||||
{
|
||||
@@ -240,61 +157,5 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
|
||||
e3d.height =e2d.height;
|
||||
e3d.depth =depth;
|
||||
}
|
||||
|
||||
inline void debug_out_vk_version(const uint32_t version)
|
||||
{
|
||||
std::cout<<VK_VERSION_MAJOR(version)<<"."
|
||||
<<VK_VERSION_MINOR(version)<<"."
|
||||
<<VK_VERSION_PATCH(version);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline hgl::String<T> VkUUID2String(const uint8_t *pipelineCacheUUID)
|
||||
{
|
||||
T *hstr=new T[VK_UUID_SIZE*2+1];
|
||||
|
||||
DataToLowerHexStr(hstr,pipelineCacheUUID,VK_UUID_SIZE);
|
||||
|
||||
return hgl::String<T>::newOf(hstr,VK_UUID_SIZE*2);
|
||||
}
|
||||
|
||||
inline void debug_out(const char *front,const hgl::List<VkLayerProperties> &layer_properties)
|
||||
{
|
||||
const int property_count=layer_properties.GetCount();
|
||||
|
||||
if(property_count<=0)return;
|
||||
|
||||
const VkLayerProperties *lp=layer_properties.GetData();
|
||||
|
||||
for(int i=0;i<property_count;i++)
|
||||
{
|
||||
std::cout<<front<<" Layer Propertyes ["<<i<<"] : "<<lp->layerName<<" [spec: ";
|
||||
debug_out_vk_version(lp->specVersion);
|
||||
|
||||
std::cout<<", impl: ";
|
||||
debug_out_vk_version(lp->implementationVersion);
|
||||
|
||||
std::cout<<"] desc: "<<lp->description<<std::endl;
|
||||
++lp;
|
||||
}
|
||||
}
|
||||
|
||||
inline void debug_out(const char *front,const hgl::List<VkExtensionProperties> &extension_properties)
|
||||
{
|
||||
const int extension_count=extension_properties.GetCount();
|
||||
|
||||
if(extension_count<=0)return;
|
||||
|
||||
VkExtensionProperties *ep=extension_properties.GetData();
|
||||
for(int i=0;i<extension_count;i++)
|
||||
{
|
||||
std::cout<<front<<" Extension Propertyes ["<<i<<"] : "<<ep->extensionName<<" ver: ";
|
||||
|
||||
debug_out_vk_version(ep->specVersion);
|
||||
|
||||
std::cout<<std::endl;
|
||||
++ep;
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_INCLUDE
|
||||
|
@@ -1,90 +1,75 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKMemoryAllocator.h>
|
||||
#include<hgl/type/Collection.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDynamicBufferAccess.h>
|
||||
namespace hgl
|
||||
{
|
||||
class Collection;
|
||||
|
||||
namespace graph
|
||||
{
|
||||
class VKMemoryAllocator;
|
||||
|
||||
/**
|
||||
* GPU数据阵列缓冲区<br>
|
||||
* 它用于储存多份相同格式的数据,常用于多物件渲染,instance等
|
||||
*/
|
||||
template<typename T> class GPUArrayBuffer
|
||||
class GPUArrayBuffer
|
||||
{
|
||||
protected:
|
||||
|
||||
GPUDevice *device;
|
||||
VkBufferUsageFlags buffer_usage_flags;
|
||||
VKMemoryAllocator *vk_ma;
|
||||
uint align_size;
|
||||
uint range_size;
|
||||
|
||||
uint32_t ubo_offset_alignment;
|
||||
VKMemoryAllocator *vk_ma;
|
||||
|
||||
Collection *coll;
|
||||
|
||||
protected:
|
||||
|
||||
void * Map(const uint32 start,const uint32 count);
|
||||
void Flush(const uint32 count);
|
||||
|
||||
private:
|
||||
|
||||
GPUArrayBuffer(VKMemoryAllocator *,const uint,const uint);
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags)
|
||||
virtual ~GPUArrayBuffer();
|
||||
|
||||
const uint32_t GetAlignSize()const{return align_size;} ///<数据对齐字节数
|
||||
const uint32_t GetRangeSize()const{return range_size;} ///<单次渲染访问最大字节数
|
||||
|
||||
DeviceBuffer * GetBuffer();
|
||||
|
||||
uint32 Alloc(const uint32 max_count); ///<预分配空间
|
||||
void Clear();
|
||||
|
||||
template<typename T>
|
||||
bool Start(DynamicBufferAccess<T> *dba,const uint32 start,const uint32 count)
|
||||
{
|
||||
device=dev;
|
||||
buffer_usage_flags=flags;
|
||||
if(!dba)return(false);
|
||||
|
||||
{
|
||||
ubo_offset_alignment=device->GetUBOAlign();
|
||||
void *ptr=Map(start,count);
|
||||
|
||||
const uint32_t unit_size=hgl_align<uint32_t>(sizeof(T),ubo_offset_alignment);
|
||||
if(!ptr)return(false);
|
||||
|
||||
vk_ma=new VKMemoryAllocator(device,buffer_usage_flags,unit_size); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
|
||||
MemoryBlock *mb=new MemoryBlock(vk_ma);
|
||||
|
||||
coll=new Collection(unit_size,mb);
|
||||
}
|
||||
dba->Start((uchar *)ptr,align_size,count);
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual ~GPUArrayBuffer()
|
||||
template<typename T>
|
||||
void End(DynamicBufferAccess<T> *dba)
|
||||
{
|
||||
delete coll;
|
||||
}
|
||||
if(!dba)return;
|
||||
|
||||
const uint32_t GetOffsetAlignment()const
|
||||
{
|
||||
return ubo_offset_alignment;
|
||||
}
|
||||
Flush(dba->GetCount());
|
||||
|
||||
const uint32_t GetUnitSize()const
|
||||
{
|
||||
return coll->GetUnitBytes();
|
||||
}
|
||||
|
||||
DeviceBuffer *GetBuffer()
|
||||
{
|
||||
return vk_ma->GetBuffer();
|
||||
}
|
||||
|
||||
uint32 Alloc(const uint32 max_count) ///<预分配空间
|
||||
{
|
||||
if(!coll->Alloc(max_count))
|
||||
return(0);
|
||||
|
||||
return coll->GetAllocCount();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
coll->Clear();
|
||||
}
|
||||
|
||||
T *Map(const uint32 start,const uint32 count)
|
||||
{
|
||||
return (T *)(coll->Map(start,count));
|
||||
}
|
||||
|
||||
void Flush(const uint32 count)
|
||||
{
|
||||
vk_ma->Flush(count*GetUnitSize());
|
||||
dba->Restart();
|
||||
}
|
||||
};//class GPUArrayBuffer
|
||||
}//namespace graph
|
||||
|
@@ -36,6 +36,7 @@ public:
|
||||
|
||||
VkBuffer GetBuffer ()const{return buf.buffer;}
|
||||
DeviceMemory * GetMemory ()const{return buf.memory;}
|
||||
VkDeviceMemory GetVkMemory ()const{return buf.memory->operator VkDeviceMemory();}
|
||||
const VkDescriptorBufferInfo * GetBufferInfo ()const{return &buf.info;}
|
||||
|
||||
void * Map () {return buf.memory->Map();}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
@@ -42,9 +43,7 @@ class RenderCmdBuffer:public GPUCmdBuffer
|
||||
VkClearValue *clear_values;
|
||||
VkRect2D render_area;
|
||||
VkViewport viewport;
|
||||
|
||||
float default_line_width;
|
||||
|
||||
|
||||
Framebuffer *fbo;
|
||||
RenderPassBeginInfo rp_begin;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
@@ -140,14 +139,14 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool BindDescriptorSets(Renderable *ri);
|
||||
bool BindDescriptorSets(Material *);
|
||||
|
||||
bool PushDescriptorSet(VkPipelineLayout pipeline_layout,uint32_t set,uint32_t count,const VkWriteDescriptorSet *write_desc_set)
|
||||
{
|
||||
vkCmdPushDescriptorSetKHR(cmd_buf,VK_PIPELINE_BIND_POINT_GRAPHICS,pipeline_layout,set,count,write_desc_set);
|
||||
}
|
||||
|
||||
void PushConstants(ShaderStageBit shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
|
||||
void PushConstants(VkShaderStageFlagBits shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
|
||||
{
|
||||
vkCmdPushConstants(cmd_buf,pipeline_layout,(VkShaderStageFlagBits)shader_stage_bit,offset,size,pValues);
|
||||
}
|
||||
@@ -155,13 +154,29 @@ public:
|
||||
void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);}
|
||||
void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);}
|
||||
|
||||
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vbo,const VkDeviceSize *offsets)
|
||||
{
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
|
||||
}
|
||||
|
||||
bool BindVBO(VBOList *vbo_list)
|
||||
{
|
||||
if(!vbo_list)return(false);
|
||||
|
||||
if(!vbo_list->IsFull())return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BindIBO(const IndexBufferData *);
|
||||
|
||||
bool BindVBO(Renderable *);
|
||||
|
||||
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
|
||||
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
|
||||
|
||||
void SetLineWidth (float line_width) {vkCmdSetLineWidth(cmd_buf,line_width);}
|
||||
|
||||
void SetDepthBias (float constant_factor,float clamp,float slope_factor) {vkCmdSetDepthBias(cmd_buf,constant_factor,clamp,slope_factor);}
|
||||
void SetDepthBounds (float min_db,float max_db) {vkCmdSetDepthBounds(cmd_buf,min_db,max_db);}
|
||||
void SetBlendConstants (const float constants[4]) {vkCmdSetBlendConstants(cmd_buf,constants);}
|
||||
@@ -176,7 +191,7 @@ public: //draw
|
||||
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
|
||||
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
|
||||
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
|
||||
|
||||
|
||||
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
|
||||
|
@@ -1,86 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct DebugMakerFunction
|
||||
{
|
||||
PFN_vkDebugMarkerSetObjectTagEXT SetObjectTag;
|
||||
PFN_vkDebugMarkerSetObjectNameEXT SetObjectName;
|
||||
PFN_vkCmdDebugMarkerBeginEXT Begin;
|
||||
PFN_vkCmdDebugMarkerEndEXT End;
|
||||
PFN_vkCmdDebugMarkerInsertEXT Insert;
|
||||
};//struct DebugMakerFunction
|
||||
|
||||
class DebugMaker
|
||||
{
|
||||
VkDevice device;
|
||||
|
||||
DebugMakerFunction dmf;
|
||||
|
||||
protected:
|
||||
|
||||
void SetObjectName(uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name);
|
||||
void SetObjectTag(uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag);
|
||||
|
||||
private:
|
||||
|
||||
friend DebugMaker *CreateDebugMaker(VkDevice device);
|
||||
|
||||
DebugMaker(VkDevice dev,const DebugMakerFunction &f)
|
||||
{
|
||||
device=dev;
|
||||
dmf=f;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void Begin(VkCommandBuffer cmdbuffer, const char * pMarkerName, const Color4f &color);
|
||||
void Insert(VkCommandBuffer cmdbuffer, const char *markerName, const Color4f &color);
|
||||
void End(VkCommandBuffer cmdBuffer);
|
||||
|
||||
#define DEBUG_MAKER_SET_FUNC(type,MNAME) void Set##type(Vk##type obj,const char *name){SetObjectName((uint64_t)obj,VK_DEBUG_REPORT_OBJECT_TYPE_##MNAME##_EXT,name);}
|
||||
|
||||
DEBUG_MAKER_SET_FUNC(Instance, INSTANCE)
|
||||
DEBUG_MAKER_SET_FUNC(PhysicalDevice, PHYSICAL_DEVICE)
|
||||
DEBUG_MAKER_SET_FUNC(Device, DEVICE)
|
||||
DEBUG_MAKER_SET_FUNC(Queue, QUEUE)
|
||||
DEBUG_MAKER_SET_FUNC(Semaphore, SEMAPHORE)
|
||||
DEBUG_MAKER_SET_FUNC(CommandBuffer, COMMAND_BUFFER)
|
||||
DEBUG_MAKER_SET_FUNC(Fence, FENCE)
|
||||
DEBUG_MAKER_SET_FUNC(DeviceMemory, DEVICE_MEMORY)
|
||||
DEBUG_MAKER_SET_FUNC(Buffer, BUFFER)
|
||||
DEBUG_MAKER_SET_FUNC(Image, IMAGE)
|
||||
DEBUG_MAKER_SET_FUNC(Event, EVENT)
|
||||
DEBUG_MAKER_SET_FUNC(QueryPool, QUERY_POOL)
|
||||
DEBUG_MAKER_SET_FUNC(BufferView, BUFFER_VIEW)
|
||||
DEBUG_MAKER_SET_FUNC(ShaderModule, SHADER_MODULE)
|
||||
DEBUG_MAKER_SET_FUNC(PipelineCache, PIPELINE_CACHE)
|
||||
DEBUG_MAKER_SET_FUNC(PipelineLayout, PIPELINE_LAYOUT)
|
||||
DEBUG_MAKER_SET_FUNC(RenderPass, RENDER_PASS)
|
||||
DEBUG_MAKER_SET_FUNC(Pipeline, PIPELINE)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorSetLayout, DESCRIPTOR_SET_LAYOUT)
|
||||
DEBUG_MAKER_SET_FUNC(Sampler, SAMPLER)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorPool, DESCRIPTOR_POOL)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorSet, DESCRIPTOR_SET)
|
||||
DEBUG_MAKER_SET_FUNC(Framebuffer, FRAMEBUFFER)
|
||||
DEBUG_MAKER_SET_FUNC(CommandPool, COMMAND_POOL)
|
||||
DEBUG_MAKER_SET_FUNC(SurfaceKHR, SURFACE_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(SwapchainKHR, SWAPCHAIN_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(DebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT)
|
||||
DEBUG_MAKER_SET_FUNC(DisplayKHR, DISPLAY_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(DisplayModeKHR, DISPLAY_MODE_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(ValidationCacheEXT, VALIDATION_CACHE_EXT)
|
||||
DEBUG_MAKER_SET_FUNC(SamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE)
|
||||
DEBUG_MAKER_SET_FUNC(CuModuleNVX, CU_MODULE_NVX)
|
||||
DEBUG_MAKER_SET_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
|
||||
DEBUG_MAKER_SET_FUNC(AccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(AccelerationStructureNV, ACCELERATION_STRUCTURE_NV)
|
||||
|
||||
#undef DEBUG_MAKER_SET_FUNC
|
||||
};//class DebugMaker
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
|
112
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
112
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class Material;
|
||||
class MaterialParameters;
|
||||
|
||||
/**
|
||||
* 描述符绑定器<Br>
|
||||
* 一般用于注册通用数据,为材质进行自动绑定。
|
||||
*/
|
||||
class DescriptorBinding
|
||||
{
|
||||
DescriptorSetType set_type; ///<描述符合集类型
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
Map<AnsiString,Texture *> texture_map;
|
||||
|
||||
public:
|
||||
|
||||
DescriptorBinding(const DescriptorSetType &dst)
|
||||
{
|
||||
set_type=dst;
|
||||
}
|
||||
|
||||
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ubo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ubo_map,name);
|
||||
}
|
||||
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ubo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ssbo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetSSBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ssbo_map,name);
|
||||
}
|
||||
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ssbo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddTexture(const AnsiString &name,Texture *tex)
|
||||
{
|
||||
if(!tex)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return texture_map.Add(name,tex);
|
||||
}
|
||||
|
||||
Texture *GetTexture(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(texture_map,name);
|
||||
}
|
||||
|
||||
void RemoveTexture(Texture *tex)
|
||||
{
|
||||
if(!tex)return;
|
||||
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
|
||||
|
||||
public:
|
||||
|
||||
bool Bind(Material *);
|
||||
};//class DescriptorBinding
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
@@ -1,8 +1,9 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class DeviceBuffer;
|
||||
@@ -23,9 +24,7 @@ class DescriptorSet
|
||||
|
||||
bool is_dirty;
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
public:
|
||||
|
||||
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
|
||||
{
|
||||
@@ -37,8 +36,6 @@ private:
|
||||
is_dirty=true;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~DescriptorSet()=default;
|
||||
|
||||
const uint32_t GetCount ()const{return binding_count;}
|
||||
@@ -59,4 +56,4 @@ public:
|
||||
void Update();
|
||||
};//class DescriptorSet
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
||||
|
@@ -5,8 +5,9 @@
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/graph/ImageRegion.h>
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/Bitmap.h>
|
||||
#include<hgl/graph/BitmapData.h>
|
||||
#include<hgl/graph/font/Font.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
@@ -15,35 +16,21 @@
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/*
|
||||
* GPU设备创建信息
|
||||
*/
|
||||
struct GPUDeviceCreateInfo
|
||||
{
|
||||
VkPhysicalDeviceType device_type =VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM;
|
||||
class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
class GPUArrayBuffer;
|
||||
|
||||
uint32_t swapchain_image_count =0;
|
||||
VkSurfaceFormatKHR color_format ={PF_A2BGR10UN,VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
|
||||
VkFormat depth_format =VK_FORMAT_UNDEFINED;
|
||||
};//struct GPUDeviceCreateInfo
|
||||
struct CopyBufferToImageInfo;
|
||||
|
||||
class GPUDevice
|
||||
{
|
||||
GPUDeviceAttribute *attr;
|
||||
|
||||
Queue *texture_queue;
|
||||
DeviceQueue *texture_queue;
|
||||
TextureCmdBuffer *texture_cmd_buf;
|
||||
|
||||
private:
|
||||
@@ -51,16 +38,16 @@ private:
|
||||
DeviceRenderPassManage *render_pass_manage;
|
||||
RenderPass *device_render_pass;
|
||||
|
||||
SwapchainRenderTarget *swapchainRT;
|
||||
RTSwapchain *sc_rt;
|
||||
|
||||
SwapchainRenderTarget *CreateSwapchainRenderTarget();
|
||||
RTSwapchain *CreateSwapchainRenderTarget();
|
||||
|
||||
void InitRenderPassManage();
|
||||
void ClearRenderPassManage();
|
||||
|
||||
private:
|
||||
|
||||
VkCommandBuffer CreateCommandBuffer();
|
||||
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
|
||||
|
||||
bool CreateSwapchainFBO(Swapchain *);
|
||||
|
||||
@@ -68,7 +55,7 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
friend GPUDevice *CreateRenderDevice(VulkanInstance *inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent);
|
||||
friend class VulkanDeviceCreater;
|
||||
|
||||
GPUDevice(GPUDeviceAttribute *da);
|
||||
|
||||
@@ -92,12 +79,14 @@ public:
|
||||
|
||||
RenderPass * GetRenderPass () {return device_render_pass;}
|
||||
|
||||
SwapchainRenderTarget * GetSwapchainRT () {return swapchainRT;}
|
||||
RTSwapchain * GetSwapchainRT () {return sc_rt;}
|
||||
|
||||
const VkExtent2D & GetSwapchainSize ()const {return swapchainRT->GetExtent();}
|
||||
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
|
||||
|
||||
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
|
||||
|
||||
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
|
||||
|
||||
public:
|
||||
|
||||
bool Resize (const VkExtent2D &);
|
||||
@@ -128,17 +117,22 @@ public: //Buffer相关
|
||||
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
|
||||
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
|
||||
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
|
||||
IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);}
|
||||
IndexBuffer * CreateIBO16 ( uint32_t count,const uint16 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,(void *)data,sm);}
|
||||
IndexBuffer * CreateIBO32 ( uint32_t count,const uint32 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,(void *)data,sm);}
|
||||
|
||||
IndexBuffer * CreateIBO (IndexType type, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(type, count,nullptr,sm);}
|
||||
IndexBuffer * CreateIBO8 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,nullptr,sm);}
|
||||
IndexBuffer * CreateIBO16 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,nullptr,sm);}
|
||||
IndexBuffer * CreateIBO32 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,nullptr,sm);}
|
||||
|
||||
const VkDeviceSize GetUBOAlign();
|
||||
const VkDeviceSize GetSSBOAlign();
|
||||
const VkDeviceSize GetUBORange();
|
||||
const VkDeviceSize GetSSBORange();
|
||||
|
||||
#define CREATE_BUFFER_OBJECT(LargeName,type) DeviceBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
|
||||
DeviceBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
|
||||
@@ -151,6 +145,9 @@ public: //Buffer相关
|
||||
|
||||
#undef CREATE_BUFFER_OBJECT
|
||||
|
||||
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
||||
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
||||
|
||||
public: //Image
|
||||
|
||||
VkImage CreateImage (VkImageCreateInfo *);
|
||||
@@ -158,7 +155,15 @@ public: //Image
|
||||
|
||||
private: //texture
|
||||
|
||||
bool CommitTexture (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
|
||||
|
||||
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
|
||||
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
|
||||
|
||||
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
|
||||
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
|
||||
@@ -177,37 +182,22 @@ public: //Texture
|
||||
Texture2D *CreateTexture2D(TextureData *);
|
||||
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
|
||||
|
||||
Texture2DArray *CreateTexture2DArray(TextureData *);
|
||||
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
|
||||
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
|
||||
|
||||
TextureCube *CreateTextureCube(TextureData *);
|
||||
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
|
||||
|
||||
void Clear(TextureCreateInfo *);
|
||||
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,const List<Image2DRegion> &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,void *data, uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,void *data,const uint32_t size,const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
template<typename T>
|
||||
bool ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope2<T> &rs)
|
||||
{
|
||||
return ChangeTexture2D( tex,
|
||||
buf,
|
||||
rs.GetLeft(),
|
||||
rs.GetTop(),
|
||||
rs.GetWidth(),
|
||||
rs.GetHeight());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ChangeTexture2D(Texture2D *tex,void *data,const RectScope2<T> &rs,uint32_t size)
|
||||
{
|
||||
return ChangeTexture2D( tex,
|
||||
data,
|
||||
rs.GetLeft(),
|
||||
rs.GetTop(),
|
||||
rs.GetWidth(),
|
||||
rs.GetHeight(),
|
||||
size);
|
||||
}
|
||||
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,void *data,const uint32_t size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
public: //
|
||||
|
||||
@@ -216,25 +206,16 @@ public: //
|
||||
|
||||
public: //shader & material
|
||||
|
||||
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorSets *);
|
||||
void Destroy(PipelineLayoutData *);
|
||||
ShaderModule *CreateShaderModule(VkShaderStageFlagBits,const uint32_t *,const size_t);
|
||||
|
||||
DescriptorSet * CreateDescriptorSets(const PipelineLayoutData *,const DescriptorSetType &type)const;
|
||||
MaterialParameters *CreateMP(const MaterialDescriptorSets *,const PipelineLayoutData *,const DescriptorSetType &);
|
||||
MaterialParameters *CreateMP(Material *,const DescriptorSetType &);
|
||||
|
||||
ShaderModule *CreateShaderModule(ShaderResource *);
|
||||
|
||||
Material *CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps,MaterialDescriptorSets *);
|
||||
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
||||
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
||||
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorManager *desc_manager);
|
||||
|
||||
MaterialInstance *CreateMI(Material *,const VILConfig *vil_cfg=nullptr);
|
||||
MaterialParameters *CreateMP(const MaterialDescriptorManager *desc_manager,const PipelineLayoutData *pld,const DescriptorSetType &desc_set_type);
|
||||
|
||||
public: //Command Buffer 相关
|
||||
|
||||
RenderCmdBuffer * CreateRenderCommandBuffer();
|
||||
TextureCmdBuffer *CreateTextureCommandBuffer();
|
||||
RenderCmdBuffer * CreateRenderCommandBuffer(const AnsiString &);
|
||||
TextureCmdBuffer *CreateTextureCommandBuffer(const AnsiString &);
|
||||
|
||||
public:
|
||||
|
||||
@@ -243,27 +224,25 @@ public:
|
||||
Fence * CreateFence(bool);
|
||||
Semaphore * CreateGPUSemaphore();
|
||||
|
||||
Queue * CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
|
||||
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
|
||||
|
||||
public: //FrameBuffer相关
|
||||
|
||||
Framebuffer *CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
|
||||
// Framebuffer *CreateFramebuffer(RenderPass *,List<ImageView *> &color,ImageView *depth);
|
||||
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *color,ImageView *depth);
|
||||
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *);
|
||||
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
|
||||
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *);
|
||||
|
||||
public:
|
||||
|
||||
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
|
||||
|
||||
public:
|
||||
|
||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
|
||||
};//class GPUDevice
|
||||
|
||||
GPUDevice *CreateRenderDevice(VulkanInstance *inst,Window *win,const GPUPhysicalDevice *physical_device=nullptr);
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include<hgl/graph/VKDebugMaker.h>
|
||||
#include<hgl/graph/VKDebugUtils.h>
|
||||
#endif//_DEBUG
|
||||
|
||||
@@ -22,32 +21,32 @@ struct GPUDeviceAttribute
|
||||
VkSurfaceKHR surface =VK_NULL_HANDLE;
|
||||
VkSurfaceCapabilitiesKHR surface_caps;
|
||||
|
||||
uint32_t graphics_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t present_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t compute_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t graphics_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t present_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t compute_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t video_decode_family =ERROR_FAMILY_INDEX;
|
||||
|
||||
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
||||
uint32_t video_encode_family =ERROR_FAMILY_INDEX;
|
||||
#endif//VK_ENABLE_BETA_EXTENSIONS
|
||||
|
||||
VkQueue graphics_queue =VK_NULL_HANDLE;
|
||||
VkQueue present_queue =VK_NULL_HANDLE;
|
||||
|
||||
List<VkQueueFamilyProperties> family_properties;
|
||||
List<VkBool32> supports_present;
|
||||
|
||||
List<VkSurfaceFormatKHR> surface_formats_list;
|
||||
VkSurfaceFormatKHR surface_format;
|
||||
List<VkPresentModeKHR> present_modes;
|
||||
|
||||
VkSurfaceTransformFlagBitsKHR preTransform;
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkCommandPool cmd_pool =VK_NULL_HANDLE;
|
||||
|
||||
VkDescriptorPool desc_pool =VK_NULL_HANDLE;
|
||||
|
||||
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugMaker * debug_maker =nullptr;
|
||||
DebugUtils * debug_utils =nullptr;
|
||||
#endif//_DEBUG
|
||||
|
||||
|
314
inc/hgl/graph/VKDeviceCreater.h
Normal file
314
inc/hgl/graph/VKDeviceCreater.h
Normal file
@@ -0,0 +1,314 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct VulkanHardwareRequirement
|
||||
{
|
||||
uint min_1d_image_size;
|
||||
uint min_2d_image_size;
|
||||
uint min_3d_image_size;
|
||||
uint min_cube_image_size;
|
||||
uint min_array_image_layers;
|
||||
|
||||
uint min_vertex_input_attribute; ///<最小顶点输入属性数量需求
|
||||
uint min_color_attachments; ///<最小颜色输出成份数量需求
|
||||
|
||||
uint min_push_constant_size; ///<最小push constant大小
|
||||
uint min_ubo_range; ///<最小ubo range需求
|
||||
uint min_ssbo_range; ///<最小ssbo range需求
|
||||
|
||||
uint min_draw_indirect_count; ///<最小间接绘制次数需求
|
||||
|
||||
bool geometry_shader; ///<要求支持几何着色器
|
||||
bool tessellation_shader; ///<要求支持细分着色器
|
||||
// bool compute_shader; ///<要求支持计算着色器
|
||||
|
||||
bool multi_draw_indirect; ///<要求支持MultiDrawIndirect
|
||||
|
||||
bool wide_lines; ///<要求支持宽线条
|
||||
bool line_rasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
|
||||
bool large_points; ///<要求支持绘制大点
|
||||
|
||||
bool texture_cube_array; ///<要求支持立方体数组纹理
|
||||
|
||||
bool uint8_draw_index; ///<要求支持8位索引
|
||||
bool uint32_draw_index; ///<要求支持32位索引(不建议使用)
|
||||
|
||||
struct
|
||||
{
|
||||
bool bc,etc2,astc_ldr,astc_hdr,pvrtc; ///<要求支持的压缩纹理格式
|
||||
}texture_compression;
|
||||
|
||||
//dynamic_state VK_EXT_extended_dynamic_state
|
||||
// cull mode
|
||||
// front face
|
||||
// primitive topology
|
||||
// viewport
|
||||
// scissor
|
||||
// bind vbo
|
||||
// depth test
|
||||
// depth write
|
||||
// depth compare op
|
||||
// depth bounds test
|
||||
// stencil test
|
||||
// stencil op
|
||||
//dynamic_state[1] VK_EXT_extended_dynamic_state2
|
||||
// patch control points
|
||||
// rasterizer discard
|
||||
// depth bias
|
||||
// logic op
|
||||
// primitive restart
|
||||
//dynamic_state[2] VK_EXT_extended_dynamic_state3
|
||||
// tess domain origin
|
||||
// depth clamp
|
||||
// discard polygon mode
|
||||
// rasterization samples
|
||||
// sample mask
|
||||
// alpha to coverage
|
||||
// alpha to one
|
||||
// logic op enable
|
||||
// color blend
|
||||
// color blend equation
|
||||
// color write mask
|
||||
// depth clamp
|
||||
// Color blend advanced
|
||||
// line rasterization mode
|
||||
// line stipple
|
||||
// depth clip -1 to 1
|
||||
// shading rate image enable
|
||||
bool dynamic_state[3]; ///<要求支持动态状态
|
||||
|
||||
// 1.3 特性
|
||||
bool dynamic_rendering; ///<要求支持动态渲染
|
||||
|
||||
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
|
||||
|
||||
public:
|
||||
|
||||
VulkanHardwareRequirement()
|
||||
{
|
||||
hgl_zero(*this);
|
||||
|
||||
descriptor_pool=1024;
|
||||
|
||||
geometry_shader=true;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsLDR[]=
|
||||
{
|
||||
PF_RGB5A1,
|
||||
PF_BGR5A1,
|
||||
PF_A1RGB5,
|
||||
PF_RGB565,
|
||||
PF_BGR565,
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsSDR[]=
|
||||
{
|
||||
PF_RGBA8UN,//PF_RGBA8s,
|
||||
PF_BGRA8UN,//PF_BGRA8s,
|
||||
PF_ABGR8UN,//PF_ABGR8s,
|
||||
PF_A2RGB10UN,
|
||||
PF_A2BGR10UN,
|
||||
// PF_B10GR11UF
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsHDR16[]=
|
||||
{
|
||||
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsHDR32[]=
|
||||
{
|
||||
PF_RGB32F,
|
||||
PF_RGBA32F
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsHDR[]=
|
||||
{
|
||||
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F,
|
||||
PF_RGB32F,PF_RGBA32F
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsDepth[]=
|
||||
{
|
||||
PF_D16UN,
|
||||
PF_X8_D24UN,
|
||||
PF_D16UN_S8U,
|
||||
PF_D24UN_S8U,
|
||||
PF_D32F,
|
||||
PF_D32F_S8U
|
||||
};
|
||||
|
||||
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
|
||||
{
|
||||
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
||||
VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_DISPLAY_NATIVE_AMD,
|
||||
};
|
||||
|
||||
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesLinear[]=
|
||||
{
|
||||
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT709_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT2020_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_HDR10_ST2084_EXT,
|
||||
VK_COLOR_SPACE_DOLBYVISION_EXT,
|
||||
VK_COLOR_SPACE_HDR10_HLG_EXT,
|
||||
VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
|
||||
};
|
||||
|
||||
struct PreferFormats
|
||||
{
|
||||
//偏好格式需从低质量到高质量排列
|
||||
const VkFormat *formats;
|
||||
uint count;
|
||||
|
||||
public:
|
||||
|
||||
const int Find(const VkFormat fmt)const
|
||||
{
|
||||
for(uint i=0;i<count;i++)
|
||||
if(fmt==formats[i])
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
struct PreferColorSpaces
|
||||
{
|
||||
//偏好格式需从低质量到高质量排列
|
||||
const VkColorSpaceKHR *colorspaces;
|
||||
uint count;
|
||||
|
||||
public:
|
||||
|
||||
const int Find(const VkColorSpaceKHR cs)const
|
||||
{
|
||||
for(uint i=0;i<count;i++)
|
||||
if(cs==colorspaces[i])
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferSDR {SwapchainPreferFormatsSDR, sizeof(SwapchainPreferFormatsSDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR16{SwapchainPreferFormatsHDR16, sizeof(SwapchainPreferFormatsHDR16 )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(SwapchainPreferFormatsHDR32 )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR {SwapchainPreferFormatsHDR, sizeof(SwapchainPreferFormatsHDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferDepth{SwapchainPreferFormatsDepth, sizeof(SwapchainPreferFormatsDepth )/sizeof(VkFormat)};
|
||||
|
||||
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferColorSpacesNonlinear, sizeof(SwapchainPreferColorSpacesNonlinear )/sizeof(VkColorSpaceKHR)};
|
||||
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferColorSpacesLinear, sizeof(SwapchainPreferColorSpacesLinear )/sizeof(VkColorSpaceKHR)};
|
||||
|
||||
/**
|
||||
* Vulkan设备创建器<br>
|
||||
* 将此功能定义为类是为了让开发者方便重载处理
|
||||
*/
|
||||
class VulkanDeviceCreater
|
||||
{
|
||||
protected:
|
||||
|
||||
VulkanInstance *instance;
|
||||
Window *window;
|
||||
const GPUPhysicalDevice *physical_device;
|
||||
|
||||
VulkanHardwareRequirement require;
|
||||
|
||||
VkExtent2D extent;
|
||||
|
||||
const PreferFormats * perfer_color_formats;
|
||||
const PreferColorSpaces * perfer_color_spaces;
|
||||
const PreferFormats * perfer_depth_formats;
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
|
||||
VkSurfaceFormatKHR surface_format;
|
||||
|
||||
CharPointerList ext_list;
|
||||
VkPhysicalDeviceFeatures features={};
|
||||
|
||||
protected:
|
||||
|
||||
VkDevice CreateDevice(const uint32_t);
|
||||
|
||||
public:
|
||||
|
||||
VulkanDeviceCreater(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req,
|
||||
const PreferFormats *spf_color,
|
||||
const PreferColorSpaces *spf_color_space,
|
||||
const PreferFormats *spf_depth);
|
||||
|
||||
virtual bool ChoosePhysicalDevice();
|
||||
|
||||
virtual bool RequirementCheck();
|
||||
|
||||
virtual void ChooseSurfaceFormat();
|
||||
|
||||
virtual GPUDevice *CreateRenderDevice();
|
||||
|
||||
public:
|
||||
|
||||
virtual GPUDevice *Create();
|
||||
};//class VulkanDeviceCreater
|
||||
|
||||
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr,
|
||||
const PreferFormats * spf_color =&PreferSDR,
|
||||
const PreferColorSpaces * spf_color_space =&PreferNonlinear,
|
||||
const PreferFormats * spf_depth =&PreferDepth)
|
||||
{
|
||||
VulkanDeviceCreater vdc(vi,win,req,spf_color,spf_color_space,spf_depth);
|
||||
|
||||
return vdc.Create();
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceLDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferLDR,&PreferNonlinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceSDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferSDR,&PreferNonlinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR16( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR16,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR32( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR32,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
VK_NAMESPACE_END
|
79
inc/hgl/graph/VKDynamicBufferAccess.h
Normal file
79
inc/hgl/graph/VKDynamicBufferAccess.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
||||
#define HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
template<typename T> class DynamicBufferAccess
|
||||
{
|
||||
uchar *pointer;
|
||||
uchar *current;
|
||||
|
||||
uint align_size;
|
||||
|
||||
uint count;
|
||||
uint index;
|
||||
|
||||
private:
|
||||
|
||||
DynamicBufferAccess()
|
||||
{
|
||||
Restart();
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
pointer=nullptr;
|
||||
current=nullptr;
|
||||
align_size=0;
|
||||
count=0;
|
||||
index=0;
|
||||
}
|
||||
|
||||
void Start(uchar *buf,const uint as,const uint c)
|
||||
{
|
||||
current=pointer=buf;
|
||||
align_size=as;
|
||||
count=c;
|
||||
index=0;
|
||||
}
|
||||
|
||||
friend class GPUArrayBuffer;
|
||||
|
||||
public:
|
||||
|
||||
const uint GetCount()const{return count;}
|
||||
const uint GetCurrentIndex()const{return index;}
|
||||
const uint GetOffsetBytes()const{return index*align_size;}
|
||||
|
||||
bool Write(uchar *src)
|
||||
{
|
||||
if(!src)return(false);
|
||||
if(index>=count)return(false);
|
||||
|
||||
memcpy(current,src,sizeof(T));
|
||||
current+=align_size;
|
||||
++index;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Write(uchar *src,const uint c)
|
||||
{
|
||||
if(!src)return(false);
|
||||
if(c<=0)return(false);
|
||||
if(index+c>count)return(false);
|
||||
|
||||
for(uint i=0;i<c;i++)
|
||||
{
|
||||
memcpy(current,src,sizeof(T));
|
||||
current+=align_size;
|
||||
src+=sizeof(T);
|
||||
}
|
||||
|
||||
index+=c;
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//template<typename T> class DynamicBufferAccess
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
@@ -35,5 +35,7 @@ public:
|
||||
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
|
||||
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
|
||||
};//class Framebuffer
|
||||
|
||||
using FBO=Framebuffer;
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
|
@@ -26,8 +26,8 @@ namespace hgl
|
||||
|
||||
~IndexBuffer()=default;
|
||||
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint32 GetCount()const{return count;}
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint32 GetCount()const{return count;}
|
||||
};//class IndexBuffer:public DeviceBuffer
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKDebugOut.h>
|
||||
@@ -23,9 +23,16 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(synchronization2)
|
||||
VK_BOOL1BIT(validation)
|
||||
VK_BOOL1BIT(profiles)
|
||||
}khronos;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(switchable_graphics)
|
||||
}amd;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(optimus)
|
||||
|
@@ -5,61 +5,59 @@
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
class ActiveMemoryBlockManager;
|
||||
}
|
||||
VK_NAMESPACE_BEGIN
|
||||
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
|
||||
|
||||
using MaterialParameterArray=MaterialParameters *[size_t(DescriptorSetType::RANGE_SIZE)];
|
||||
|
||||
struct MaterialData
|
||||
{
|
||||
UTF8String name;
|
||||
|
||||
ShaderModuleMap *shader_maps;
|
||||
MaterialDescriptorSets *mds;
|
||||
|
||||
VertexShaderModule *vertex_sm;
|
||||
|
||||
ShaderStageCreateInfoList shader_stage_list;
|
||||
|
||||
PipelineLayoutData *pipeline_layout_data;
|
||||
|
||||
MaterialParameterArray mp_array;
|
||||
|
||||
private:
|
||||
|
||||
friend class Material;
|
||||
|
||||
~MaterialData();
|
||||
};//struct MaterialData
|
||||
|
||||
/**
|
||||
* 材质类<br>
|
||||
* 用于管理shader,提供DescriptorSetLayoutCreater
|
||||
*/
|
||||
class Material
|
||||
{
|
||||
MaterialData *data;
|
||||
AnsiString name;
|
||||
|
||||
VertexInput *vertex_input;
|
||||
|
||||
ShaderModuleMap *shader_maps;
|
||||
|
||||
MaterialDescriptorManager *desc_manager;
|
||||
|
||||
ShaderStageCreateInfoList shader_stage_list;
|
||||
|
||||
PipelineLayoutData *pipeline_layout_data;
|
||||
|
||||
MaterialParameters *mp_array[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
uint32_t mi_data_bytes; ///<实例数据大小
|
||||
uint32_t mi_max_count; ///<实例一次渲染最大数量限制
|
||||
|
||||
ActiveMemoryBlockManager *mi_data_manager;
|
||||
|
||||
private:
|
||||
|
||||
friend GPUDevice;
|
||||
friend class RenderResource;
|
||||
|
||||
MaterialData *GetMaterialData(){return data;}
|
||||
Material(const AnsiString &);
|
||||
|
||||
public:
|
||||
|
||||
Material(MaterialData *md):data(md){}
|
||||
~Material();
|
||||
virtual ~Material();
|
||||
|
||||
const UTF8String & GetName ()const{return data->name;}
|
||||
const AnsiString & GetName ()const{return name;}
|
||||
|
||||
VertexShaderModule * GetVertexShaderModule () {return data->vertex_sm;}
|
||||
const VertexInput * GetVertexInput ()const{return vertex_input;}
|
||||
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
||||
|
||||
const MaterialDescriptorSets * GetDescriptorSets ()const{return data->mds;}
|
||||
// const MaterialDescriptorManager * GetDescriptorManager ()const{return desc_manager;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const;
|
||||
const PipelineLayoutData * GetPipelineLayoutData ()const{return data->pipeline_layout_data;}
|
||||
// const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
|
||||
|
||||
public:
|
||||
|
||||
@@ -67,10 +65,37 @@ public:
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(type)
|
||||
|
||||
return data->mp_array[size_t(type)];
|
||||
return mp_array[size_t(type)];
|
||||
}
|
||||
|
||||
const bool hasSet (const DescriptorSetType &type)const;
|
||||
const bool hasAssign ()const;
|
||||
|
||||
const VIL * GetDefaultVIL()const;
|
||||
VIL * CreateVIL(const VILConfig *format_map=nullptr);
|
||||
bool Release(VIL *);
|
||||
const uint GetVILCount();
|
||||
|
||||
public:
|
||||
|
||||
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
|
||||
|
||||
void Update();
|
||||
|
||||
public:
|
||||
|
||||
const bool HasMI ()const{return mi_data_bytes>0;}
|
||||
const uint32_t GetMIDataBytes ()const{return mi_data_bytes;}
|
||||
const uint32_t GetMIMaxCount ()const{return mi_max_count;}
|
||||
|
||||
void ReleaseMI(int); ///<释放材质实例
|
||||
void *GetMIData(int); ///<取得指定ID号的材质实例数据访问指针
|
||||
|
||||
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
|
||||
};//class Material
|
||||
|
||||
using MaterialSets=SortedSets<Material *>;
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
|
53
inc/hgl/graph/VKMaterialDescriptorManager.h
Normal file
53
inc/hgl/graph/VKMaterialDescriptorManager.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialDescriptorManager
|
||||
{
|
||||
UTF8String mtl_name;
|
||||
|
||||
BindingMapArray binding_map[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
private:
|
||||
|
||||
VkDescriptorSetLayoutBinding *all_dslb;
|
||||
|
||||
DescriptorSetLayoutCreateInfo dsl_ci[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
public:
|
||||
|
||||
MaterialDescriptorManager(const UTF8String &,ShaderDescriptor *,const uint);
|
||||
MaterialDescriptorManager(const UTF8String &,const ShaderDescriptorSetArray &);
|
||||
~MaterialDescriptorManager();
|
||||
|
||||
const UTF8String &GetMaterialName()const{return mtl_name;}
|
||||
|
||||
const uint GetBindCount(const DescriptorSetType &set_type)const
|
||||
{
|
||||
RANGE_CHECK_RETURN(set_type,0)
|
||||
|
||||
return dsl_ci[size_t(set_type)].bindingCount;
|
||||
}
|
||||
|
||||
const BindingMapArray &GetBindingMap(const DescriptorSetType &set_type)const
|
||||
{
|
||||
return binding_map[size_t(set_type)];
|
||||
}
|
||||
|
||||
const int GetBinding(const DescriptorSetType &set_type,const VkDescriptorType &desc_type,const AnsiString &name)const;
|
||||
|
||||
const int GetUBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
|
||||
const int GetSSBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
|
||||
const int GetImageSampler (const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
|
||||
const int GetInputAttachment(const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
|
||||
|
||||
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
|
||||
|
||||
const bool hasSet(const DescriptorSetType &type)const{return dsl_ci[size_t(type)].bindingCount>0;}
|
||||
//!sd_list_by_set_type[size_t(type)].IsEmpty();}
|
||||
};//class MaterialDescriptorManager
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
|
@@ -1,61 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct ShaderDescriptor
|
||||
{
|
||||
char name[128];
|
||||
|
||||
VkDescriptorType desc_type;
|
||||
DescriptorSetType set_type;
|
||||
uint32_t set;
|
||||
uint32_t binding;
|
||||
uint32_t stage_flag;
|
||||
};
|
||||
|
||||
using ShaderDescriptorList=List<ShaderDescriptor *>;
|
||||
|
||||
class MaterialDescriptorSets
|
||||
{
|
||||
UTF8String mtl_name;
|
||||
|
||||
ShaderDescriptor *sd_list;
|
||||
uint sd_count;
|
||||
|
||||
ShaderDescriptorList sd_list_by_desc_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
ShaderDescriptorList sd_list_by_set_type[size_t(DescriptorSetType::RANGE_SIZE)];
|
||||
|
||||
// Map<AnsiString,ShaderDescriptor *> sd_by_name;
|
||||
Map<AnsiString,int> binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
// int *binding_list[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
private:
|
||||
|
||||
DescriptorSetLayoutCreateInfo dsl_ci[size_t(DescriptorSetType::RANGE_SIZE)];
|
||||
|
||||
public:
|
||||
|
||||
MaterialDescriptorSets(const UTF8String &,ShaderDescriptor *,const uint);
|
||||
~MaterialDescriptorSets();
|
||||
|
||||
const UTF8String &GetMaterialName()const{return mtl_name;}
|
||||
|
||||
const int GetBinding(const VkDescriptorType &desc_type,const AnsiString &name)const;
|
||||
|
||||
const int GetUBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
|
||||
const int GetSSBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
|
||||
const int GetImageSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
|
||||
const int GetInputAttachment(const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
|
||||
|
||||
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
|
||||
|
||||
const ShaderDescriptorList &GetDescriptorList(const DescriptorSetType &type)const{return sd_list_by_set_type[size_t(type)];}
|
||||
|
||||
const bool hasSet(const DescriptorSetType &type)const{return !sd_list_by_set_type[size_t(type)].IsEmpty();}
|
||||
};//class MaterialDescriptorSets
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
@@ -4,34 +4,79 @@
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* <summary>
|
||||
*
|
||||
* layout(location=?) in uint MaterialInstanceID
|
||||
*
|
||||
* #define MI_MAX_COUNT ??? //该值由引擎根据 UBORange/sizeof(MaterialInstance) 计算出来
|
||||
*
|
||||
* struct MaterialInstance //这部分数据,即为材质实例的具体数据,每一个材质实例类负责提供具体数据。由RenderList合并成一整个UBO
|
||||
* { //该类数据,由DescriptorSetType为PerMaterial的参数构成
|
||||
* vec4 BaseColor;
|
||||
* vec4 Emissive;
|
||||
* vec4 ARM;
|
||||
* };
|
||||
*
|
||||
* layout(set=?,binding=?) uniform Material
|
||||
* {
|
||||
* MaterialInstance mi[MI_MAX_COUNT]
|
||||
* }mtl;
|
||||
*
|
||||
* void main()
|
||||
* {
|
||||
* MaterialInstance mi=mtl.mi[(MaterialInstanceID>=MI_MAX_COUNT)?:0:MaterialInstanceID]; //如果超出范围则使用0号材质实例数据
|
||||
*
|
||||
* vec4 BaseColor =mi.BaseColor;
|
||||
* vec4 Emissive =mi.Emissive;
|
||||
*
|
||||
* float AO =mi.ARM.x;
|
||||
* float Roughness =mi.ARM.y;
|
||||
* float Metallic =mi.ARM.z;
|
||||
*
|
||||
* </summary>
|
||||
*/
|
||||
|
||||
/**
|
||||
* 材质实例类<br>
|
||||
* 材质实例类本质只是提供一个数据区,供RenderList合并成一个大UBO。
|
||||
*/
|
||||
class MaterialInstance
|
||||
{
|
||||
protected:
|
||||
|
||||
Material *material;
|
||||
|
||||
VIL *vil;
|
||||
|
||||
MaterialParameters *mp_per_mi; ///<材质实例独有参数,对应PerMaterial合集
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
MaterialInstance(Material *,VIL *);
|
||||
int mi_id;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~MaterialInstance()=default;
|
||||
Material * GetMaterial () {return material;}
|
||||
|
||||
Material *GetMaterial(){return material;}
|
||||
const VIL * GetVIL ()const {return vil;}
|
||||
|
||||
const VIL *GetVIL()const{return vil;}
|
||||
MaterialParameters *GetMP(){return mp_per_mi;}
|
||||
MaterialParameters *GetMP(const DescriptorSetType &type){return material->GetMP(type);}
|
||||
|
||||
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
|
||||
private:
|
||||
|
||||
friend class Material;
|
||||
|
||||
MaterialInstance(Material *,VIL *,const int);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~MaterialInstance()
|
||||
{
|
||||
material->ReleaseMI(mi_id);
|
||||
}
|
||||
|
||||
const int GetMIID ()const{return mi_id;} ///<取得材质实例ID
|
||||
void * GetMIData (){return material->GetMIData(mi_id);} ///<取得材质实例数据
|
||||
void WriteMIData (const void *data,const int size); ///<写入材质实例数据
|
||||
|
||||
template<typename T>
|
||||
void WriteMIData (const T &data){WriteMIData(&data,sizeof(T));} ///<写入材质实例数据
|
||||
};//class MaterialInstance
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||
|
||||
|
@@ -1,48 +1,54 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
#include<hgl/graph/VKMaterialDescriptorManager.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialParameters
|
||||
{
|
||||
const MaterialDescriptorSets *mds;
|
||||
protected:
|
||||
|
||||
const MaterialDescriptorManager *desc_manager;
|
||||
|
||||
DescriptorSetType set_type;
|
||||
|
||||
DescriptorSet *descriptor_set;
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
MaterialParameters(const MaterialDescriptorSets *,const DescriptorSetType &type,DescriptorSet *);
|
||||
|
||||
public:
|
||||
|
||||
const DescriptorSetType GetType (){return set_type;}
|
||||
DescriptorSet * GetDescriptorSet (){return descriptor_set;}
|
||||
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_set->GetDescriptorSet();}
|
||||
|
||||
const uint32_t GetCount ()const{return descriptor_set->GetCount();}
|
||||
const bool IsReady ()const{return descriptor_set->IsReady();}
|
||||
const uint32_t GetDescriptorCount ()const{return desc_manager->GetBindCount(set_type);} ///<获取总共需要绑定的描述符数量
|
||||
const BindingMapArray & GetBindingMap ()const{return desc_manager->GetBindingMap(set_type);}
|
||||
|
||||
const uint32_t GetBoundCount ()const{return descriptor_set->GetCount();} ///<获取已经绑好的数量
|
||||
const bool IsReady ()const{return descriptor_set->IsReady();} ///<是否全部绑好了
|
||||
|
||||
public:
|
||||
|
||||
#define MP_TYPE_IS(name) const bool is##name()const{return set_type==DescriptorSetType::name;}
|
||||
MP_TYPE_IS(Skeleton)
|
||||
MP_TYPE_IS(Instance)
|
||||
MP_TYPE_IS(PerObject)
|
||||
MP_TYPE_IS(PerMaterialInstance)
|
||||
MP_TYPE_IS(PerMaterial)
|
||||
MP_TYPE_IS(PerFrame)
|
||||
MP_TYPE_IS(Global)
|
||||
#undef MP_TYPE_IS
|
||||
|
||||
public:
|
||||
|
||||
MaterialParameters(const MaterialDescriptorManager *,const DescriptorSetType &type,DescriptorSet *);
|
||||
virtual ~MaterialParameters();
|
||||
|
||||
bool BindUBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const int &index,Texture *tex,Sampler *sampler);
|
||||
bool BindInputAttachment(const int &index,ImageView *);
|
||||
|
||||
bool BindUBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const AnsiString &name,Texture *tex,Sampler *sampler);
|
||||
@@ -51,4 +57,4 @@ public:
|
||||
void Update();
|
||||
};//class MaterialParameters
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
|
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
const uint32_t GetBufferUsageFlagBits ()const{return buffer_usage_flag_bits;}
|
||||
|
||||
DeviceBuffer * GetBuffer (){return gpu_buffer;}
|
||||
DeviceBuffer * GetBuffer (){return gpu_buffer;}
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -48,6 +48,8 @@ public:
|
||||
operator VkPhysicalDevice() {return physical_device;}
|
||||
operator const VkPhysicalDevice()const {return physical_device;}
|
||||
|
||||
const uint32_t GetVulkanVersion()const{return properties.apiVersion;}
|
||||
|
||||
const int GetMemoryType(uint32_t,VkMemoryPropertyFlags)const;
|
||||
|
||||
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
|
||||
@@ -88,8 +90,13 @@ public:
|
||||
const bool isMicrosoft ()const{return HGL_VK_IS_BRAND(Microsoft);}
|
||||
const bool isMesa ()const{return HGL_VK_IS_BRAND(Mesa );}
|
||||
const bool isAMD ()const{return HGL_VK_IS_BRAND(AMD )
|
||||
||HGL_VK_IS_BRAND(ATI );}
|
||||
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia );}
|
||||
||HGL_VK_IS_BRAND(ATI )
|
||||
||HGL_VK_IS_BRAND(Radeon );}
|
||||
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia )
|
||||
||HGL_VK_IS_BRAND(GeForce )
|
||||
||HGL_VK_IS_BRAND(Quadro )
|
||||
||HGL_VK_IS_BRAND(TITAN )
|
||||
||HGL_VK_IS_BRAND(Tegra );}
|
||||
const bool isIntel ()const{return HGL_VK_IS_BRAND(Intel );}
|
||||
const bool isQualcomm ()const{return HGL_VK_IS_BRAND(Adreno );}
|
||||
const bool isApple ()const{return HGL_VK_IS_BRAND(Apple );}
|
||||
@@ -155,8 +162,6 @@ public:
|
||||
const uint32_t GetMaxImage3D ()const{return properties.limits.maxImageDimension3D;}
|
||||
const uint32_t GetMaxImageCube ()const{return properties.limits.maxImageDimensionCube;}
|
||||
const uint32_t GetMaxImageArrayLayers ()const{return properties.limits.maxImageArrayLayers;}
|
||||
const uint32_t GetMaxUBORange ()const{return properties.limits.maxUniformBufferRange;}
|
||||
const uint32_t GetMaxSSBORange ()const{return properties.limits.maxStorageBufferRange;}
|
||||
const uint32_t GetMaxBoundDescriptorSets ()const{return properties.limits.maxBoundDescriptorSets;}
|
||||
|
||||
const uint32_t GetMaxVertexInputAttributes ()const{return properties.limits.maxVertexInputAttributes;}
|
||||
|
@@ -9,6 +9,9 @@ VK_NAMESPACE_BEGIN
|
||||
class Pipeline
|
||||
{
|
||||
VkDevice device;
|
||||
|
||||
AnsiString name;
|
||||
|
||||
VkPipeline pipeline;
|
||||
PipelineData *data;
|
||||
|
||||
@@ -19,8 +22,10 @@ private:
|
||||
|
||||
friend class RenderPass;
|
||||
|
||||
Pipeline(VkDevice dev,VkPipeline p,PipelineData *pd)
|
||||
Pipeline(const AnsiString &n,VkDevice dev,VkPipeline p,PipelineData *pd)
|
||||
{
|
||||
name=n;
|
||||
|
||||
device=dev;
|
||||
pipeline=p;
|
||||
data=pd;
|
||||
@@ -33,8 +38,12 @@ public:
|
||||
|
||||
virtual ~Pipeline();
|
||||
|
||||
const AnsiString &GetName()const{return name;}
|
||||
|
||||
operator VkPipeline(){return pipeline;}
|
||||
|
||||
const PipelineData *GetData()const{return data;}
|
||||
|
||||
const bool IsAlphaTest()const{return data->alpha_test>0;}
|
||||
const bool IsAlphaBlend()const{return data->alpha_blend;}
|
||||
};//class GraphicsPipeline
|
||||
|
@@ -12,6 +12,9 @@ VK_NAMESPACE_BEGIN
|
||||
*/
|
||||
class Primitive
|
||||
{
|
||||
GPUDevice *device;
|
||||
AnsiString prim_name;
|
||||
|
||||
struct VBOData
|
||||
{
|
||||
VBO *buf;
|
||||
@@ -26,10 +29,9 @@ class Primitive
|
||||
|
||||
protected:
|
||||
|
||||
uint32_t draw_count;
|
||||
uint32_t vertex_count;
|
||||
|
||||
IndexBuffer *indices_buffer=nullptr;
|
||||
VkDeviceSize indices_offset=0;
|
||||
IndexBufferData index_buffer_data;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -46,42 +48,33 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
Primitive(const uint32_t dc=0):draw_count(dc){}
|
||||
Primitive(GPUDevice *dev,const AnsiString &n,const uint32_t vc=0)
|
||||
{
|
||||
device=dev;
|
||||
prim_name=n;
|
||||
vertex_count=vc;
|
||||
}
|
||||
|
||||
virtual ~Primitive()=default;
|
||||
|
||||
const uint GetRefCount()const{return ref_count;}
|
||||
|
||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||
const AABB & GetBoundingBox()const {return BoundingBox;}
|
||||
|
||||
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
||||
{
|
||||
if(!ib)return(false);
|
||||
|
||||
indices_buffer=ib;
|
||||
indices_offset=offset;
|
||||
return(true);
|
||||
}
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0);
|
||||
|
||||
public:
|
||||
|
||||
void SetDrawCount(const uint32_t dc){draw_count=dc;} ///<设置当前对象绘制需要多少个顶点
|
||||
virtual const uint32_t GetDrawCount()const ///<取得当前对象绘制需要多少个顶点
|
||||
{
|
||||
if(indices_buffer)
|
||||
return indices_buffer->GetCount();
|
||||
const uint32_t GetVertexCount ()const {return vertex_count;}
|
||||
|
||||
return draw_count;
|
||||
}
|
||||
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
|
||||
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
|
||||
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
||||
|
||||
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
|
||||
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
|
||||
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
||||
|
||||
IndexBuffer * GetIndexBuffer () {return indices_buffer;}
|
||||
const VkDeviceSize GetIndexBufferOffset()const {return indices_offset;}
|
||||
const IndexBufferData * GetIndexBufferData ()const {return &index_buffer_data;}
|
||||
};//class Primitive
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKFence.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Queue
|
||||
class DeviceQueue
|
||||
{
|
||||
protected:
|
||||
|
||||
@@ -21,11 +21,11 @@ private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
Queue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
|
||||
DeviceQueue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Queue();
|
||||
virtual ~DeviceQueue();
|
||||
|
||||
operator VkQueue(){return queue;}
|
||||
|
||||
@@ -35,6 +35,6 @@ public:
|
||||
bool WaitFence(const bool wait_all=true,const uint64_t time_out=HGL_NANO_SEC_PER_SEC);
|
||||
bool Submit(const VkCommandBuffer &cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
};//class SumbitQueue
|
||||
};//class DeviceQueue
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* RenderPass功能封装<br>
|
||||
@@ -25,7 +25,7 @@ protected:
|
||||
|
||||
ObjectList<Pipeline> pipeline_list;
|
||||
|
||||
Pipeline *CreatePipeline(Material *,PipelineData *,const VIL *);
|
||||
Pipeline *CreatePipeline(const AnsiString &,PipelineData *,const ShaderStageCreateInfoList &,VkPipelineLayout,const VIL *);
|
||||
|
||||
private:
|
||||
|
||||
@@ -54,14 +54,15 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &);
|
||||
Pipeline *CreatePipeline(Material *,const VIL *,const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
public:
|
||||
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &,const bool prim_restart=false);
|
||||
};//class RenderPass
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user