Compare commits
242 Commits
devel_26_T
...
devel_31_V
Author | SHA1 | Date | |
---|---|---|---|
781e108aa3 | |||
1abe8770d7 | |||
8f9ccc3aa1 | |||
cd01c45980 | |||
941f5ee6ec | |||
66fbe5571e | |||
4fcdd42ce4 | |||
d83f04faab | |||
b71c912fd5 | |||
2efb9c83bf | |||
7b0a185a45 | |||
0a025f0464 | |||
7f8fbbd3a0 | |||
cd4733a491 | |||
c1d54628d1 | |||
0da0290fc6 | |||
01bb4b2153 | |||
66ef3160e1 | |||
16ae849809 | |||
8788b3dd6a | |||
bba5a660a3 | |||
aa853fbdfb | |||
c780662ff6 | |||
611a9fe61d | |||
90152ca74e | |||
22868dafab | |||
6ce713aed5 | |||
ac0d1bee59 | |||
bf7c6bdeac | |||
cc80fe7f39 | |||
55001843ea | |||
8cdf88e2fd | |||
ca8e36687f | |||
86ff7517d9 | |||
742fe201ad | |||
8bb97ef2de | |||
9947d46ab8 | |||
bf5e401566 | |||
0dcf004f4c | |||
8d3cd8d561 | |||
6740764f07 | |||
a5e76988c7 | |||
08a348392d | |||
0dfb7220b5 | |||
4a94d78c1f | |||
9a4e495027 | |||
6de3cf789a | |||
299d3bd019 | |||
78b1982849 | |||
8a0215aee6 | |||
419e0e2574 | |||
cfd67e1a42 | |||
c49feac2e6 | |||
bf50333f5b | |||
40ce978f85 | |||
e27442a0b4 | |||
ecb47dae4d | |||
6892a64393 | |||
3af753ee36 | |||
f31437bf67 | |||
14fbbd6fa6 | |||
4e6adcd765 | |||
ead4ba65c1 | |||
310cc151fa | |||
03491dbed8 | |||
40094a7529 | |||
6ad3b9edb7 | |||
21a63f4a9b | |||
11ebb841be | |||
ad330f3a42 | |||
bbf94767fe | |||
6dba761a80 | |||
5391f0f4aa | |||
a1bf9336a3 | |||
9c6c37c07a | |||
3bbbe18c40 | |||
d8140ae64e | |||
acb69d3bf5 | |||
f0c47cd4f1 | |||
0b1a0cadae | |||
8633a18e01 | |||
2bc6246dc0 | |||
0a752446b0 | |||
c32f56fbe2 | |||
b100b4b9cb | |||
d20e9cf1e3 | |||
621e056315 | |||
4fc74d38ba | |||
f00cb0b815 | |||
e1d45a7c83 | |||
c5b8dbe8f6 | |||
172ee7bb7b | |||
d41530dad3 | |||
6efb50c977 | |||
f4493b09e5 | |||
af8f62ddb4 | |||
fff7fd3af0 | |||
2fdd7e7bd5 | |||
4ebc8a3260 | |||
5892b075c3 | |||
07a478a2ac | |||
8c51d3a52b | |||
c1183d351d | |||
d4c1dd312e | |||
3c22b48f3c | |||
02169963de | |||
ac81e4f8f0 | |||
1d3bec4098 | |||
3252d1581c | |||
01bf8b3dd2 | |||
1c03e838e5 | |||
0f38f94139 | |||
0639440a13 | |||
8492b886c9 | |||
a60ffbb7da | |||
b48ef1ac30 | |||
c363a6fa51 | |||
c873271f6e | |||
68ff8a472c | |||
60ba3e4df2 | |||
35b7c9651f | |||
89b9735f99 | |||
7f744d1207 | |||
b9f5c69f85 | |||
c469fde84a | |||
dd6b2f4fb3 | |||
ba8b44659b | |||
13b2ca0575 | |||
9d704eb33d | |||
86c3b65a42 | |||
f6e61e70ce | |||
5347ac7091 | |||
f56928d734 | |||
f3a59c1bb3 | |||
5188d4149c | |||
d4096735f5 | |||
4fafd938b1 | |||
f0848541c2 | |||
cc9e756ece | |||
cdedc81f9f | |||
c229259623 | |||
2c2f11f47e | |||
c8b3ed0286 | |||
2ce36ec26c | |||
5ba3c1790d | |||
3874d771d3 | |||
49eb8f42f0 | |||
c355f96f9b | |||
dc3d7b7792 | |||
5f1c60a24a | |||
ff6a644e8f | |||
b9e70426a1 | |||
a7af276a44 | |||
8b82c6c25c | |||
a8d68c295d | |||
f666d5b248 | |||
55c27a883b | |||
6a7f8e7754 | |||
1dbf8ae5c7 | |||
8dbc1d899c | |||
d010ee4278 | |||
4aeb28c571 | |||
775e031422 | |||
deefdf1416 | |||
ba2d479f05 | |||
b16341c0f9 | |||
d5eeb081e1 | |||
4bb66d2746 | |||
625a7387ae | |||
c4deceebd9 | |||
4ed0e281b2 | |||
9369ad115b | |||
7788459109 | |||
a58589f01f | |||
240b6fb0e3 | |||
b72a924853 | |||
b781ff41a3 | |||
4ee6962d04 | |||
7eff39b3b0 | |||
6b13c159d8 | |||
2f560a28a7 | |||
8ba171efda | |||
317635877b | |||
255c7859f1 | |||
ae85d3fc66 | |||
a5830e18cb | |||
ae88a65315 | |||
77b0266cdc | |||
c99934fdf9 | |||
aa6071a948 | |||
6f58475abd | |||
cfed14d746 | |||
27c409c7fd | |||
bee48890cb | |||
a2669d2123 | |||
737438aaed | |||
8a5711154f | |||
3dd308aff1 | |||
bead8128b7 | |||
019e9964fa | |||
7ca81f38e8 | |||
03750832c8 | |||
018a72c09a | |||
55fee1e5d7 | |||
c5dd359d18 | |||
85ec666989 | |||
9a5cead33e | |||
695f1a22a8 | |||
237c1a469b | |||
5ede824522 | |||
46781b9627 | |||
aaff0c23c9 | |||
3a3f9d10b7 | |||
b6e391762b | |||
b262fdc645 | |||
5e795c4a7f | |||
0524c51feb | |||
8dc9846ae8 | |||
1d866abb48 | |||
ece7912f3c | |||
4ef37a430e | |||
1f91ec94e1 | |||
86123827cb | |||
19df201ab5 | |||
921d6d157f | |||
c0e4128365 | |||
8fe5e8dd55 | |||
3393a90127 | |||
9b5157594f | |||
10d4f2f04a | |||
a1e7b105f7 | |||
67cf89fef1 | |||
e95cbb28a4 | |||
c9d6774bd3 | |||
78946994bb | |||
1a63fa8c76 | |||
db766f33ac | |||
3db94948c5 | |||
cefea7229d | |||
45f50b3bc0 | |||
dbea7764fb | |||
1101bcae9d |
Submodule CMAssetsManage updated: 9582bfafcc...4b880eb50f
2
CMCore
2
CMCore
Submodule CMCore updated: 416e96c169...ee2bf2b9b8
Submodule CMPlatform updated: 5e8b83cce4...8d091ebfb0
Submodule CMSceneGraph updated: 2c10960ec3...1c8e479181
2
CMUtil
2
CMUtil
Submodule CMUtil updated: c0990c52eb...39faf8b475
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
PROJECT(ULRE)
|
||||
|
||||
@@ -26,7 +26,7 @@ SET(ULRE CMCore
|
||||
ULRE.Util
|
||||
ULRE.ShaderGen
|
||||
ULRE.SceneGraph
|
||||
${HGL_GLM_LIB}
|
||||
${HGL_MATH_LIB}
|
||||
${RENDER_LIBRARY}
|
||||
${Vulkan_LIBRARIES})
|
||||
|
||||
|
20
README.md
20
README.md
@@ -1,25 +1,33 @@
|
||||
# ULRE
|
||||
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,macOS,iOS)
|
||||
Platform: Windows, Linux (WIP: Android, macOS, iOS)
|
||||
|
||||
Graphics API: Vulkan
|
||||
|
||||
Milestone:
|
||||
|
||||
On May 6 of 2023, 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 very important 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,macOS,iOS)
|
||||
平台: Windows, Linux (开发中: Android, macOS, iOS)
|
||||
|
||||
图形API: Vulkan
|
||||
|
||||
里程碑:
|
||||
|
||||
2023年5月6日,完成了一个测试,只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作,但它依然是一个非常重要的里程碑。
|
||||
2. Texture2DArray集成在材质实例中。同一个模型的多个渲染实例使用不同的材质实例以及不同的纹理,
|
||||
但它们依然被合并成一次渲染。这次的改变虽小,但意义更为重大。
|
||||
|
||||
1. 完成了一个测试,只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作,但它依然是一个非常重要的里程碑。
|
||||
|
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
@@ -0,0 +1,11 @@
|
||||
mat4 GetJointMatrix()
|
||||
{
|
||||
// Joint数据分Joint ID和Joint Weight两部分
|
||||
// Joint ID是一个uvec4,在shader中为整数。在C++端可使用RGBA8UI或是RGBA16UI来传递。
|
||||
// Joint Weight是权重,在shader中为浮点。在C++端使用RGBA8或RGBA4来传递。
|
||||
|
||||
return joint.mats[JointID.x]*JointWeight.x+
|
||||
joint.mats[JointID.y]*JointWeight.y+
|
||||
joint.mats[JointID.z]*JointWeight.z+
|
||||
joint.mats[JointID.w]*JointWeight.w;
|
||||
}
|
9
ShaderLibrary/Normal.glsl
Normal file
9
ShaderLibrary/Normal.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
mat3 GetNormalMatrix()
|
||||
{
|
||||
return mat3(camera.view*GetLocalToWorld());
|
||||
}
|
||||
|
||||
vec3 GetNormal(mat3 normal_matrix,vec3 normal)
|
||||
{
|
||||
return normalize(normal_matrix*normal);
|
||||
}
|
38
ShaderLibrary/Std2D/PureColor2D.mtl
Normal file
38
ShaderLibrary/Std2D/PureColor2D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name PureColor2D
|
||||
Base Std2D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=mi.Color;
|
||||
}
|
||||
}
|
39
ShaderLibrary/Std2D/PureTexture2D.mtl
Normal file
39
ShaderLibrary/Std2D/PureTexture2D.mtl
Normal file
@@ -0,0 +1,39 @@
|
||||
#Material
|
||||
Name PureTexture2D
|
||||
Base Std2D
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
@@ -0,0 +1,68 @@
|
||||
#Material
|
||||
Name RectTexture2D
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
@@ -0,0 +1,79 @@
|
||||
#Material
|
||||
Name RectTexture2DArray
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
uvec4 id;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
HandoverMI();gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2DArray TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=texture(TextureBaseColor,vec3(Input.TexCoord,mi.id.x));
|
||||
}
|
||||
}
|
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
@@ -0,0 +1,37 @@
|
||||
#Material
|
||||
Name VertexColor2D
|
||||
Base Std2D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
@@ -0,0 +1,2 @@
|
||||
vec4 direction;
|
||||
vec4 color;
|
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
@@ -0,0 +1,92 @@
|
||||
#Material
|
||||
Name BlinnPhong+HalfLambert shading model only color
|
||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||
Base Std3D/BlinnPhong
|
||||
|
||||
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||
Require LocalToWorld
|
||||
Require Camera
|
||||
|
||||
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec3 Color;
|
||||
float Gloss;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Position;
|
||||
vec3 Normal;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Normal =GetNormal();
|
||||
Output.Position =GetPosition3D();
|
||||
|
||||
HandoverMI();
|
||||
|
||||
gl_Position =Output.Position;
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
#define HAVE_SPECULAR
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
//点乘法线和光照
|
||||
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
FragColor=vec4(direct_color,1.0);
|
||||
#else
|
||||
|
||||
vec3 spec_color=vec3(0.0);
|
||||
|
||||
if(intensity>0.0)
|
||||
{
|
||||
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
|
||||
|
||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||
|
||||
spec_color=specular*pow(specular,mi.Gloss)*sun.color.rgb;
|
||||
}
|
||||
|
||||
FragColor=vec4(direct_color+spec_color,1.0);
|
||||
#endif//HAVE_SPECULAR
|
||||
}
|
||||
}
|
100
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColorTexture.mtl
Normal file
100
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColorTexture.mtl
Normal file
@@ -0,0 +1,100 @@
|
||||
#Material
|
||||
Name BlinnPhong+HalfLambert shading model only color
|
||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||
Base Std3D/BlinnPhong
|
||||
|
||||
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||
Require LocalToWorld
|
||||
Require Camera
|
||||
|
||||
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 32
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
uint tex_id;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
vec2 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Position;
|
||||
vec3 Normal;
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Normal =GetNormal();
|
||||
Output.Position =GetPosition3D();
|
||||
Output.TexCoord =TexCoord;
|
||||
|
||||
HandoverMI();
|
||||
|
||||
gl_Position =Output.Position;
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2DArray TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
#define HAVE_SPECULAR
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
vec4 texture_color=texture(TextureBaseColor,vec3(Input.TexCoord,mi.tex_id));
|
||||
|
||||
//点乘法线和光照
|
||||
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb*texture_color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
FragColor=vec4(direct_color,1.0);
|
||||
#else
|
||||
|
||||
vec3 spec_color=vec3(0.0);
|
||||
|
||||
if(intensity>0.0)
|
||||
{
|
||||
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
|
||||
|
||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||
|
||||
spec_color=specular*pow(specular,8)*sun.color.rgb;
|
||||
}
|
||||
|
||||
FragColor=vec4(direct_color+spec_color,1.0);
|
||||
#endif//HAVE_SPECULAR
|
||||
}
|
||||
}
|
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
@@ -0,0 +1,87 @@
|
||||
#Material
|
||||
Name MetricCellsGrid
|
||||
Base Std3D
|
||||
Reference https://www.shadertoy.com/view/wdSXzm
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#MaterialInstance
|
||||
Length 120
|
||||
Stage Fragment
|
||||
|
||||
Code
|
||||
{
|
||||
vec4 x_color;
|
||||
vec4 y_color;
|
||||
vec4 x_axis_color;
|
||||
vec4 y_axis_color;
|
||||
vec4 center_color;
|
||||
|
||||
vec2 lum; //x=0.1 sub cell line,y=0.2 big cell line
|
||||
vec2 cell_step;
|
||||
vec2 big_cell_step;
|
||||
vec2 scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
float edge=viewport.inv_viewport_resolution.y;
|
||||
|
||||
float x=(Input.TexCoord.x-0.5)*mi.scale.x;
|
||||
float y=(Input.TexCoord.y-0.5)*mi.scale.y;
|
||||
|
||||
vec4 color=vec4(0,0,0,1);
|
||||
|
||||
// ======= Lines + Bold lines
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.x, fract(x / mi.cell_step.x )) * mi.x_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.x, fract(x / mi.big_cell_step.x)) * mi.x_color.rgb * mi.lum.y;
|
||||
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.y, fract(y / mi.cell_step.y )) * mi.y_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.y, fract(y / mi.big_cell_step.y)) * mi.y_color.rgb * mi.lum.y;
|
||||
|
||||
// ======= AXES
|
||||
float xb = step(abs(x) - mi.axis_line_width, 0.0);
|
||||
float yb = step(abs(y) - mi.axis_line_width, 0.0);
|
||||
|
||||
color.rgb = mix(color.rgb, mi.x_axis_color.rgb, (xb));
|
||||
color.rgb = mix(color.rgb, mi.y_axis_color.rgb, (yb));
|
||||
|
||||
// ======= CENTER
|
||||
float cb = length(vec2(x,y))-mi.center_radius;
|
||||
color.rgb = mix(color.rgb, mi.center_color.rgb, cb>0.0?0.0:smoothstep(0,edge*mi.scale.y,abs(cb)));
|
||||
|
||||
FragColor=color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name PureColor3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=mi.Color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name VertexColor3D
|
||||
Base Std3D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
@@ -0,0 +1,47 @@
|
||||
#Material
|
||||
Name VertexLum3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Vertex
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
float Luminance
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.Color=Luminance*mi.Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
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.
@@ -116,7 +116,7 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
@@ -138,7 +138,7 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
@@ -3,9 +3,9 @@
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -16,6 +16,8 @@ constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr uint32_t TRIANGLE_NUMBER=12;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
0.0, 0.0,
|
||||
@@ -24,7 +26,8 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||
{ {255,0,0,255},
|
||||
{
|
||||
{255,0,0,255},
|
||||
{0,255,0,255},
|
||||
{0,0,255,255}
|
||||
};
|
||||
@@ -71,18 +74,28 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
double rad;
|
||||
Matrix4f mat;
|
||||
|
||||
for(uint i=0;i<12;i++)
|
||||
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
|
||||
for(uint i=0;i<TRIANGLE_NUMBER;i++)
|
||||
{
|
||||
rad=deg2rad<double>((360/TRIANGLE_NUMBER)*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
||||
mat=rotate(rad,Vector3f(0,0,1));
|
||||
|
||||
render_root.CreateSubNode(mat,render_obj);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
@@ -116,7 +129,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
|
@@ -3,8 +3,7 @@
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
@@ -25,6 +24,8 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
|
||||
constexpr uint DRAW_OBJECT_COUNT=12;
|
||||
|
||||
#define USE_MATERIAL_FILE true //是否使用材质文件
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
@@ -52,9 +53,12 @@ private:
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg);
|
||||
|
||||
#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);
|
||||
@@ -79,18 +83,28 @@ private:
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!pc.Init("Triangle",VERTEX_COUNT))
|
||||
return(false);
|
||||
|
||||
if(!pc.WriteVAB(VAN::Position, VF_V2F, position_data))
|
||||
return(false);
|
||||
|
||||
Primitive *prim=pc.Create();
|
||||
if(!prim)
|
||||
return(false);
|
||||
|
||||
db->Add(prim);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
render_obj[i].r=db->CreateRenderable(prim,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.CreateSubNode(rotate(deg2rad<double>(double(360/DRAW_OBJECT_COUNT*i)),Vector3f(0,0,1)),render_obj[i].r);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
@@ -125,7 +139,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
|
@@ -6,8 +6,8 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -108,16 +108,18 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
@@ -145,7 +147,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
|
@@ -4,29 +4,29 @@
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
static float position_data[VERTEX_COUNT][2]=
|
||||
static float position_data_float[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0.5, 0.25},
|
||||
{0.75, 0.75},
|
||||
{0.25, 0.75}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
static uint16 position_data_u16[VERTEX_COUNT][2]={};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
{
|
||||
{1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
255,0,0,255,
|
||||
0,255,0,255,
|
||||
0,0,255,255
|
||||
};
|
||||
|
||||
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
||||
@@ -46,23 +46,31 @@ private:
|
||||
{
|
||||
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); //这里指定VAB中使用RG16U当做顶点数据格式
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
db->global_descriptor.Bind(material_instance->GetMaterial());
|
||||
|
||||
|
||||
// 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
|
||||
|
||||
@@ -71,32 +79,37 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
#ifndef USE_ZERO2ONE_COORD //使用ortho坐标系
|
||||
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data[i][0]*=SCREEN_WIDTH;
|
||||
position_data[i][1]*=SCREEN_HEIGHT;
|
||||
}
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data_float ))return(false);
|
||||
#else //使用ortho坐标系
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4F, color_data ))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
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);
|
||||
|
||||
@@ -109,7 +122,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
@@ -119,12 +132,5 @@ public:
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
RunApp<TestApp>(1280,720);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ 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)
|
||||
@@ -21,4 +22,3 @@ macro(CreateProject name)
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example")
|
||||
endmacro()
|
||||
|
||||
CreateProject(MaterialCreaterTest MaterialCreaterTest.cpp)
|
||||
|
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
|
@@ -10,4 +10,10 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
|
||||
endmacro()
|
||||
|
||||
CreateProject(PlaneGrid3D PlaneGrid3D.cpp)
|
||||
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 * prim_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入一个坐标轴的线条数据.
|
||||
*
|
||||
* \param pos 要写入数据的指针
|
||||
* \param max_line 主线条方向
|
||||
* \param oa1 其它轴1方向
|
||||
* \param oa2 其它轴2方向
|
||||
*/
|
||||
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; ///<最终点位置
|
||||
const Vector3f cross_pos=max_line*AXIS_MIN_STEP; ///<坐标轴尾部交叉线位置
|
||||
const Vector3f arrow_pos=max_line*(AXIS_LENGTH-AXIS_MIN_STEP); ///<箭头末端在主线上的位置
|
||||
|
||||
//主线
|
||||
pos[0]=Vector3f(0, 0, 0);
|
||||
pos[1]=end_pos;
|
||||
|
||||
//四根箭头线
|
||||
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;
|
||||
|
||||
//侧边连接其它轴线
|
||||
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;
|
||||
|
||||
prim_line=db->CreatePrimitive("Line",AXIS_MAX_VERTICES);
|
||||
if(!prim_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(!prim_line->Set(VAN::Position, db->CreateVAB(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
|
||||
if(!prim_line->Set(VAN::Color, db->CreateVAB(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_vtx_lum);
|
||||
Add(prim_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/4,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);
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
// 4.Geometry3D
|
||||
// PlaneGrid3D
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
@@ -6,102 +6,95 @@
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
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]{};
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
MaterialInstance * material_instance[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
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);
|
||||
Color4f GridColor;
|
||||
COLOR ce=COLOR::BlenderAxisRed;
|
||||
|
||||
return(true);
|
||||
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;
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
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;
|
||||
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(&pc,&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;
|
||||
}
|
||||
|
||||
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));
|
||||
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(200,200,200);
|
||||
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(camera->info,&render_root);
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -110,51 +103,28 @@ public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
CreateRenderObject();
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
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;
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
||||
|
199
example/Gizmo/RayPicking.cpp
Normal file
199
example/Gizmo/RayPicking.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
// 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>
|
||||
#include<hgl/graph/VertexDataManager.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 * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Material * mtl_line =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
Pipeline * pipeline_line =nullptr;
|
||||
Primitive * prim_line =nullptr;
|
||||
VABMap * prim_line_vab_map =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance2D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
{
|
||||
cfg.mtl_name="VertexLuminance2D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_plane_grid)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_plane_grid=CreatePipeline(mtl_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
{
|
||||
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
|
||||
cfg.position_format=VAT_VEC3;
|
||||
|
||||
mtl_line=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_line)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(mtl_line,nullptr,&yellow_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
pipeline_line=CreatePipeline(mtl_line,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline_line)
|
||||
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;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mtl_plane_grid->GetDefaultVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(&pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mtl_line->GetDefaultVIL());
|
||||
|
||||
if(!pc.Init("Line",2))
|
||||
return(false);
|
||||
|
||||
if(!pc.WriteVAB(VAN::Position, VF_V3F,position_data))return(false);
|
||||
if(!pc.WriteVAB(VAN::Luminance,VF_V1F,lumiance_data))return(false);
|
||||
|
||||
prim_line=pc.Create();
|
||||
|
||||
prim_line_vab_map=prim_line->GetVABMap(VAN::Position);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
Add(prim_line,mi_line,pipeline_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:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
SAFE_CLEAR(prim_line);
|
||||
}
|
||||
|
||||
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)最近的点的坐标
|
||||
|
||||
prim_line_vab_map->Write(&pos, //更新VAB上这个点的位置
|
||||
1); //这里的1代表的数据数量,不是字节数
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
334
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
334
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
@@ -0,0 +1,334 @@
|
||||
// BlinnPhong direction light
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/BlinnPhong.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
|
||||
static mtl::blinnphong::SunLight sun_light=
|
||||
{
|
||||
Vector4f(1,1,1,0), //direction
|
||||
Vector4f(1,0.95,0.9,1) //color
|
||||
};
|
||||
|
||||
constexpr const COLOR AxisColor[4]=
|
||||
{
|
||||
//COLOR::Red, //X轴颜色
|
||||
//COLOR::Green, //Y轴颜色
|
||||
//COLOR::Blue, //Z轴颜色
|
||||
COLOR::White, //全局颜色
|
||||
COLOR::GhostWhite,
|
||||
COLOR::BlanchedAlmond,
|
||||
COLOR::AntiqueWhite
|
||||
|
||||
};
|
||||
|
||||
constexpr const os_char *tex_filename[]=
|
||||
{
|
||||
OS_TEXT("eucalyptus-cross-versailles.Tex2D"),
|
||||
OS_TEXT("tints-ashton-green-stretcher.Tex2D"),
|
||||
OS_TEXT("worn-clay-cobble-in-desert-stretcher.Tex2D"),
|
||||
OS_TEXT("plain-grey-sheer.Tex2D"),
|
||||
};
|
||||
|
||||
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private: //plane grid
|
||||
|
||||
Material * mtl_vertex_lum =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * p_line =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
DeviceBuffer * ubo_sun =nullptr;
|
||||
|
||||
|
||||
Texture2DArray * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_blinnphong =nullptr;
|
||||
PrimitiveCreater * pc_blinnphong =nullptr;
|
||||
VertexDataManager * vdm_blinnphong =nullptr;
|
||||
|
||||
MaterialInstance * mi_blinnphong[4]{};
|
||||
Pipeline * p_blinnphong =nullptr;
|
||||
|
||||
Primitive * prim_sphere =nullptr;
|
||||
Primitive * prim_cone =nullptr;
|
||||
Primitive * prim_cylinder =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->CreateTexture2DArray( "SeamlessBackground",
|
||||
256,256, ///<纹理尺寸
|
||||
TexCount, ///<纹理层数
|
||||
PF_BC1_RGBUN, ///<纹理格式
|
||||
false); ///<是否自动产生mipmaps
|
||||
|
||||
if(!texture)return(false);
|
||||
|
||||
OSString filename;
|
||||
|
||||
for(uint i=0;i<TexCount;i++)
|
||||
{
|
||||
filename=filesystem::MergeFilename(OS_TEXT("res/image/seamless"),tex_filename[i]);
|
||||
|
||||
if(!db->LoadTexture2DToArray(texture,i,filename))
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVertexLumMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->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;
|
||||
cfg.material_instance=true;
|
||||
|
||||
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColorTexture",&cfg);
|
||||
if(!mtl_blinnphong)return(false);
|
||||
|
||||
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_blinnphong->Update();
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!mtl_blinnphong->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
struct MIData
|
||||
{
|
||||
Color4f color;
|
||||
uint32 tex_id[4];
|
||||
}mi_data;
|
||||
|
||||
constexpr const uint MIDataStride=sizeof(MIData);
|
||||
|
||||
for(uint i=0;i<4;i++)
|
||||
{
|
||||
mi_data.color=GetColor4f(AxisColor[i],4);
|
||||
mi_data.tex_id[0]=i;
|
||||
|
||||
mi_blinnphong[i]=db->CreateMaterialInstance(mtl_blinnphong, //材质
|
||||
nullptr, //顶点输入配置,这里使用nullptr,即代表会使用默认配置,那么结果将等同于上面的mtl_blinnphong->GetDefaultVIL()
|
||||
&mi_data); //材质实例参数
|
||||
if(!mi_blinnphong[i])return(false);
|
||||
}
|
||||
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVDMAndPC()
|
||||
{
|
||||
vdm_blinnphong=new VertexDataManager(device,mtl_blinnphong->GetDefaultVIL());
|
||||
if(!vdm_blinnphong->Init( 1024*1024, //VAB最大容量
|
||||
1024*1024, //索引最大容量
|
||||
IndexType::U16)) //索引类型
|
||||
{
|
||||
delete vdm_blinnphong;
|
||||
vdm_blinnphong=nullptr;
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
pc_blinnphong=new PrimitiveCreater(vdm_blinnphong);
|
||||
//pc_blinnphong=new PrimitiveCreater(device,mtl_blinnphong->GetDefaultVIL());
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
//Plane Grid
|
||||
//{
|
||||
// struct PlaneGridCreateInfo pgci;
|
||||
|
||||
// pgci.grid_size.Set(32,32);
|
||||
// pgci.sub_count.Set(8,8);
|
||||
|
||||
// pgci.lum=0.5;
|
||||
// pgci.sub_lum=0.75;
|
||||
|
||||
// prim_plane_grid=CreatePlaneGrid(pc_blinnphong,mtl_vertex_lum->GetDefaultVIL(),&pgci);
|
||||
//}
|
||||
|
||||
//Sphere
|
||||
prim_sphere=CreateSphere(pc_blinnphong,16);
|
||||
|
||||
//Cone
|
||||
{
|
||||
struct ConeCreateInfo cci;
|
||||
|
||||
cci.radius =1; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=8; //圆锥高度分割数
|
||||
|
||||
prim_cone=CreateCone(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
//Cyliner
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =1.25; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =1.25f; //圆柱半径
|
||||
|
||||
prim_cylinder=CreateCylinder(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat=Identity4f)
|
||||
{
|
||||
if(!r)
|
||||
return(nullptr);
|
||||
if(!mi)
|
||||
return(nullptr);
|
||||
if(!p)
|
||||
return(nullptr);
|
||||
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(U8_TEXT("Create Renderable failed! Primitive: ")+r->GetName());
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
//Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
|
||||
|
||||
Add(prim_sphere, mi_blinnphong[0],p_blinnphong,translate(Vector3f(0,0,2)));
|
||||
|
||||
Add(prim_cone, mi_blinnphong[1],p_blinnphong);
|
||||
Add(prim_cylinder, mi_blinnphong[2],p_blinnphong,translate(Vector3f(0,0,-5)));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
//if(!InitVertexLumMP())
|
||||
// return(false);
|
||||
|
||||
if(!CreateBlinnPhongUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitBlinnPhongSunLightMP())
|
||||
return(false);
|
||||
|
||||
if(!InitVDMAndPC())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_cone)
|
||||
SAFE_CLEAR(prim_cylinder)
|
||||
SAFE_CLEAR(prim_sphere)
|
||||
SAFE_CLEAR(prim_plane_grid)
|
||||
|
||||
SAFE_CLEAR(pc_blinnphong)
|
||||
SAFE_CLEAR(vdm_blinnphong)
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
13
example/LightBasic/CMakeLists.txt
Normal file
13
example/LightBasic/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Light Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_BlinnPhongDirectionLight BlinnPhongDirectionLight.cpp)
|
@@ -1,126 +0,0 @@
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
using namespace hgl::shadergen;
|
||||
|
||||
bool PureColor2DMaterial()
|
||||
{
|
||||
MaterialCreateInfo mc("PureColor2D",1,false); //一个新材质,1个RT输出,默认使用Vertex/Fragment shader
|
||||
|
||||
//vertex部分
|
||||
{
|
||||
ShaderCreateInfoVertex *vsc=mc.GetVS(); //获取vertex shader creater
|
||||
|
||||
//以下代码会被展开为
|
||||
/*
|
||||
layout(location=?) in vec3 Position; //位置属性
|
||||
*/
|
||||
vsc->AddInput("vec2","Position"); //添加一个vec3类型的position属性输入
|
||||
|
||||
vsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Position,0,1);
|
||||
})");
|
||||
}
|
||||
|
||||
//添加一个名称为ColorMaterial的UBO定义,其内部有一个vec4 color的属性
|
||||
//该代码会被展开为
|
||||
/*
|
||||
struct ColorMaterial
|
||||
{
|
||||
vec4 color;
|
||||
};
|
||||
*/
|
||||
mc.AddStruct("ColorMaterial","vec4 color;");
|
||||
|
||||
//添加一个UBO,该代码会被展开为
|
||||
/*
|
||||
layout(set=?,binding=?) uniform ColorMaterial mtl;
|
||||
*/
|
||||
mc.AddUBO( VK_SHADER_STAGE_FRAGMENT_BIT, //这个UBO出现在fragment shader
|
||||
DescriptorSetType::PerMaterial, //它属于材质合集
|
||||
"ColorMaterial", //UBO名称为ColorMaterial
|
||||
"mtl"); //UBO变量名称为mtl
|
||||
|
||||
//fragment部分
|
||||
{
|
||||
ShaderCreateInfoFragment *fsc=mc.GetFS(); //获取fragment shader creater
|
||||
|
||||
//以下代码会被展开为
|
||||
/*
|
||||
layout(location=?) out vec4 Color; //颜色输出
|
||||
*/
|
||||
fsc->AddOutput("vec4","Color"); //添加一个vec4类型的color属性输出
|
||||
|
||||
fsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Color=mtl.color;
|
||||
})");
|
||||
}
|
||||
|
||||
mc.CreateShader();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool VertexColor2DMaterial()
|
||||
{
|
||||
MaterialCreateInfo mc("VertexColor2D",1,false);
|
||||
|
||||
//vertex部分
|
||||
{
|
||||
ShaderCreateInfoVertex *vsc=mc.GetVS();
|
||||
|
||||
vsc->AddInput("vec2","Position");
|
||||
vsc->AddInput("vec4","Color");
|
||||
|
||||
vsc->AddOutput("vec4","Color");
|
||||
|
||||
vsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=vec4(Position,0,1);
|
||||
})");
|
||||
}
|
||||
|
||||
//fragment部分
|
||||
{
|
||||
ShaderCreateInfoFragment *fsc=mc.GetFS();
|
||||
|
||||
fsc->AddOutput("vec4","Color");
|
||||
|
||||
fsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Color=Input.Color;
|
||||
})");
|
||||
}
|
||||
|
||||
mc.CreateShader();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
namespace glsl_compiler
|
||||
{
|
||||
bool Init();
|
||||
void Close();
|
||||
}//namespace glsl_compiler
|
||||
|
||||
int main()
|
||||
{
|
||||
if(!glsl_compiler::Init())
|
||||
return -1;
|
||||
|
||||
PureColor2DMaterial();
|
||||
VertexColor2DMaterial();
|
||||
|
||||
glsl_compiler::Close();
|
||||
|
||||
return 0;
|
||||
}
|
@@ -4,8 +4,8 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -56,9 +56,7 @@ private:
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureTexture2D(&cfg);
|
||||
|
||||
material=db->CreateMaterial(mci);
|
||||
material=db->LoadMaterial("Std2D/PureTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
@@ -75,7 +73,7 @@ private:
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
@@ -87,12 +85,14 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Quad",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
|
@@ -4,8 +4,8 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -52,9 +52,7 @@ private:
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateRectTexture2D(&cfg);
|
||||
|
||||
material=db->CreateMaterial(mci);
|
||||
material=db->LoadMaterial("Std2D/RectTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
@@ -71,7 +69,7 @@ private:
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
@@ -83,12 +81,14 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,1);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("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);
|
||||
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
|
@@ -4,8 +4,8 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/Filename.h>
|
||||
|
||||
@@ -56,6 +56,7 @@ private:
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
DeviceBuffer * tex_id_ubo =nullptr;
|
||||
Primitive * prim_rectangle =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
@@ -67,7 +68,8 @@ private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->CreateTexture2DArray( 512,512, ///<纹理尺寸
|
||||
texture=db->CreateTexture2DArray( "freepik icons",
|
||||
512,512, ///<纹理尺寸
|
||||
TexCount, ///<纹理层数
|
||||
PF_BC1_RGBAUN, ///<纹理格式
|
||||
false); ///<是否自动产生mipmaps
|
||||
@@ -94,9 +96,7 @@ private:
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateRectTexture2DArray(&cfg);
|
||||
|
||||
material=db->CreateMaterial(mci);
|
||||
material=db->LoadMaterial("Std2D/RectTexture2DArray",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
@@ -109,7 +109,7 @@ private:
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
@@ -129,18 +129,22 @@ private:
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,1);
|
||||
PrimitiveCreater rpc(device,material->GetDefaultVIL());
|
||||
|
||||
rpc.Init("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);
|
||||
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
prim_rectangle=rpc.Create();
|
||||
|
||||
Vector3f offset(1.0f/float(TexCount),0,0);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
render_obj[i].r=db->CreateRenderable(prim_rectangle,render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
@@ -161,6 +165,7 @@ public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_rectangle);
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
@@ -185,7 +190,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
|
@@ -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;
|
||||
}
|
@@ -19,6 +19,9 @@
|
||||
#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>
|
||||
@@ -87,14 +90,14 @@ public:
|
||||
SAFE_CLEAR(inst);
|
||||
}
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
virtual bool Init(uint w,uint h)
|
||||
{
|
||||
logger::InitLogger(OS_TEXT("VulkanTest"));
|
||||
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
clear_color.Set(0,0,0,1);
|
||||
SetClearColor(COLOR::MozillaCharcoal);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
@@ -126,10 +129,16 @@ public:
|
||||
return(false);
|
||||
}
|
||||
|
||||
device=CreateRenderDevice(inst,win);
|
||||
{
|
||||
VulkanHardwareRequirement vh_req;
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
vh_req.wideLines=VulkanHardwareRequirement::SupportLevel::Want;
|
||||
|
||||
device=CreateRenderDevice(inst,win,&vh_req);
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
}
|
||||
|
||||
device_render_pass=device->GetRenderPass();
|
||||
|
||||
@@ -142,20 +151,30 @@ public:
|
||||
{
|
||||
vp_info.Set(w,h);
|
||||
|
||||
ubo_vp_info=db->CreateUBO(sizeof(ViewportInfo),&vp_info);
|
||||
ubo_vp_info=db->CreateUBO("Viewport",sizeof(ViewportInfo),&vp_info);
|
||||
|
||||
db->global_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
db->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void Resize(int w,int h)
|
||||
virtual void Resize(uint w,uint h)
|
||||
{
|
||||
vp_info.Set(w,h);
|
||||
ubo_vp_info->Write(&vp_info);
|
||||
}
|
||||
|
||||
ViewportInfo &GetViewportInfo()
|
||||
{
|
||||
return vp_info;
|
||||
}
|
||||
|
||||
DeviceBuffer *GetViewportInfoBuffer()
|
||||
{
|
||||
return ubo_vp_info;
|
||||
}
|
||||
|
||||
void SetClearColor(const Color4f &cc)
|
||||
{
|
||||
clear_color=cc;
|
||||
@@ -189,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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,21 +216,14 @@ public:
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
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->GetMaterial());
|
||||
cb->BindVBO(ri);
|
||||
|
||||
if (vid->index_buffer->buffer)
|
||||
cb->DrawIndexed(vid->index_buffer->buffer->GetCount());
|
||||
else
|
||||
cb->Draw(vid->vertex_count);
|
||||
|
||||
cb->BindDataBuffer(ri->GetDataBuffer());
|
||||
cb->Draw(ri->GetDataBuffer(),ri->GetRenderData());
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
|
||||
@@ -277,7 +289,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:
|
||||
|
||||
@@ -368,7 +395,7 @@ class CameraMouseControl:public MouseEvent
|
||||
Vector2f mouse_pos;
|
||||
Vector2f mouse_last_pos;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
bool OnPressed(int x,int y,MouseButton) override
|
||||
{
|
||||
@@ -426,6 +453,7 @@ public:
|
||||
{
|
||||
camera=wc;
|
||||
cur_time=0;
|
||||
last_time=0;
|
||||
}
|
||||
|
||||
const Vector2f &GetMouseCoord()const{return mouse_pos;}
|
||||
@@ -438,7 +466,6 @@ public:
|
||||
|
||||
class CameraAppFramework:public VulkanApplicationFramework
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
@@ -461,7 +488,7 @@ public:
|
||||
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);
|
||||
@@ -472,6 +499,10 @@ public:
|
||||
|
||||
virtual void InitCamera(int w,int h)
|
||||
{
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
camera_control=new FirstPersonCameraControl(&vp_info,camera);
|
||||
|
||||
camera_control->Refresh(); //更新矩阵计算
|
||||
@@ -482,16 +513,14 @@ public:
|
||||
win->Join(ckc);
|
||||
win->Join(cmc);
|
||||
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
|
||||
|
||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera_control->GetCameraInfo());
|
||||
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
|
||||
{
|
||||
vp_info.Set(w,h);
|
||||
|
||||
@@ -500,7 +529,7 @@ public:
|
||||
ubo_camera_info->Write(&camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
const CameraInfo &GetCameraInfo()
|
||||
CameraInfo &GetCameraInfo()
|
||||
{
|
||||
return camera_control->GetCameraInfo();
|
||||
}
|
||||
@@ -510,11 +539,6 @@ public:
|
||||
return ubo_camera_info;
|
||||
}
|
||||
|
||||
bool BindCameraUBO(Material *mtl)
|
||||
{
|
||||
return mtl->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||
|
||||
virtual void Draw()override
|
||||
@@ -532,4 +556,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;
|
||||
}
|
@@ -4,12 +4,15 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/math/Vector.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/type/Size2.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class PrimitiveCreater;
|
||||
|
||||
namespace inline_geometry
|
||||
{
|
||||
/**
|
||||
@@ -20,12 +23,12 @@ namespace hgl
|
||||
RectScope2f scope;
|
||||
};//struct RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci);
|
||||
Primitive *CreateRectangle(PrimitiveCreater *pc,const RectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 创建延迟渲染用全屏平面
|
||||
*/
|
||||
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil);
|
||||
Primitive *CreateGBufferCompositionRectangle(PrimitiveCreater *pc);
|
||||
|
||||
/**
|
||||
* 圆角矩形创建信息(扇形/线圈)
|
||||
@@ -36,7 +39,7 @@ namespace hgl
|
||||
uint32_t round_per; ///<圆角精度
|
||||
};//struct RoundRectangleCreateInfo:public RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci);
|
||||
Primitive *CreateRoundRectangle(PrimitiveCreater *pc,const RoundRectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 圆形创建信息
|
||||
@@ -56,44 +59,31 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个2D圆形(扇形/线圈)
|
||||
*/
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci);
|
||||
Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息
|
||||
* 平面网格创建信息<br>
|
||||
* 会创建一个在XY平面上居中的网格,单个格子尺寸为1。
|
||||
*/
|
||||
struct PlaneGridCreateInfo
|
||||
{
|
||||
Vector3f coord[4];
|
||||
Vector2u step;
|
||||
Size2u grid_size; ///<格子数量
|
||||
|
||||
Vector2u side_step; //到边界的步数
|
||||
Size2u sub_count; ///<细分格子数量
|
||||
|
||||
Color4f color; //一般线条颜色
|
||||
Color4f side_color; //边界线条颜色
|
||||
float lum; ///<一般线条颜色
|
||||
float sub_lum; ///<细分及边界线条颜色
|
||||
};//struct PlaneGridCreateInfo
|
||||
|
||||
/**
|
||||
* 创建一个平面网格(线条)
|
||||
*/
|
||||
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 *CreatePlaneGrid(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci);
|
||||
|
||||
/**
|
||||
* 创建一个平面(三角形)
|
||||
*/
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci);
|
||||
Primitive *CreatePlane(PrimitiveCreater *pc);
|
||||
|
||||
struct CubeCreateInfo
|
||||
{
|
||||
@@ -129,7 +119,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个立方体(三角形)
|
||||
*/
|
||||
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci);
|
||||
Primitive *CreateCube(PrimitiveCreater *pc,const CubeCreateInfo *cci);
|
||||
|
||||
struct BoundingBoxCreateInfo
|
||||
{
|
||||
@@ -160,17 +150,17 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个绑定盒(线条)
|
||||
*/
|
||||
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci);
|
||||
Primitive *CreateBoundingBox(PrimitiveCreater *pc,const BoundingBoxCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个球心坐标为0,0,0,半径为1的球体(三角形)
|
||||
*/
|
||||
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices);
|
||||
Primitive *CreateSphere(PrimitiveCreater *,const uint numberSlices);
|
||||
|
||||
/**
|
||||
* 创建一个穹顶(三角形)
|
||||
*/
|
||||
Primitive *CreateDome(RenderResource *db,const VIL *vil, const uint numberSlices);
|
||||
Primitive *CreateDome(PrimitiveCreater *pc, const uint numberSlices);
|
||||
|
||||
struct TorusCreateInfo
|
||||
{
|
||||
@@ -186,7 +176,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆环(三角形)
|
||||
*/
|
||||
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci);
|
||||
Primitive *CreateTorus(PrimitiveCreater *pc,const TorusCreateInfo *tci);
|
||||
|
||||
struct CylinderCreateInfo
|
||||
{
|
||||
@@ -198,7 +188,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆柱(三角形)
|
||||
*/
|
||||
Primitive *CreateCylinder(RenderResource *db,const VIL *vil,const CylinderCreateInfo *cci);
|
||||
Primitive *CreateCylinder(PrimitiveCreater *,const CylinderCreateInfo *cci);
|
||||
|
||||
struct ConeCreateInfo
|
||||
{
|
||||
@@ -211,7 +201,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆锥(三角形)
|
||||
*/
|
||||
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci);
|
||||
Primitive *CreateCone(PrimitiveCreater *,const ConeCreateInfo *cci);
|
||||
|
||||
struct AxisCreateInfo
|
||||
{
|
||||
@@ -232,7 +222,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个坐标线(线条)
|
||||
*/
|
||||
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci);
|
||||
Primitive *CreateAxis(PrimitiveCreater *pc,const AxisCreateInfo *aci);
|
||||
}//namespace inline_geometry
|
||||
}//namespace graph
|
||||
};//namespace hgl
|
||||
|
@@ -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
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
#include<hgl/graph/VKVABList.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/graph/VKIndirectCommandBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderAssignBuffer;
|
||||
@@ -13,7 +15,7 @@ class MaterialRenderList
|
||||
GPUDevice *device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
|
||||
Material *mtl;
|
||||
Material *material;
|
||||
|
||||
RenderNodeList rn_list;
|
||||
|
||||
@@ -23,42 +25,52 @@ private:
|
||||
|
||||
struct RenderItem
|
||||
{
|
||||
uint32_t first;
|
||||
uint32_t count;
|
||||
uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB)
|
||||
uint32_t instance_count;
|
||||
|
||||
Pipeline * pipeline;
|
||||
MaterialInstance * mi;
|
||||
const VertexInputData * vid;
|
||||
Pipeline * pipeline;
|
||||
MaterialInstance * mi;
|
||||
|
||||
const PrimitiveDataBuffer * pdb;
|
||||
const PrimitiveRenderData * prd;
|
||||
|
||||
public:
|
||||
|
||||
void Set(Renderable *);
|
||||
};
|
||||
|
||||
MaterialInstanceSets mi_set;
|
||||
IndirectDrawBuffer *icb_draw;
|
||||
IndirectDrawIndexedBuffer *icb_draw_indexed;
|
||||
|
||||
void ReallocICB();
|
||||
void WriteICB(VkDrawIndirectCommand *,RenderItem *ri);
|
||||
void WriteICB(VkDrawIndexedIndirectCommand *,RenderItem *ri);
|
||||
|
||||
DataArray<RenderItem> ri_array;
|
||||
uint ri_count;
|
||||
|
||||
void StatMI();
|
||||
void Stat();
|
||||
|
||||
protected:
|
||||
|
||||
VBOList * vbo_list;
|
||||
VABList * vab_list;
|
||||
|
||||
const VIL * last_vil;
|
||||
Pipeline * last_pipeline;
|
||||
const VertexInputData * last_vid;
|
||||
uint last_index;
|
||||
Pipeline * last_pipeline;
|
||||
const PrimitiveDataBuffer * last_data_buffer;
|
||||
const VDM * last_vdm;
|
||||
const PrimitiveRenderData * last_render_data;
|
||||
|
||||
void Bind(MaterialInstance *);
|
||||
bool Bind(const VertexInputData *,const uint);
|
||||
int first_indirect_draw_index=-1;
|
||||
uint indirect_draw_count=0;
|
||||
|
||||
bool BindVAB(const PrimitiveDataBuffer *,const uint);
|
||||
|
||||
void ProcIndirectRender();
|
||||
void Render(RenderItem *);
|
||||
|
||||
public:
|
||||
|
||||
MaterialRenderList(GPUDevice *d,Material *m);
|
||||
MaterialRenderList(GPUDevice *d,bool l2w,Material *m);
|
||||
~MaterialRenderList();
|
||||
|
||||
void Add(Renderable *ri,const Matrix4f &mat);
|
||||
|
@@ -1,85 +1,79 @@
|
||||
#ifndef HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#define HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
namespace hgl
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* 可绘制原始图形创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
struct PrimitiveVertexBuffer
|
||||
{
|
||||
AnsiString name;
|
||||
uint binding;
|
||||
VAD * data =nullptr;
|
||||
VBO * vbo =nullptr;
|
||||
protected:
|
||||
|
||||
public:
|
||||
GPUDevice * device;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
~PrimitiveVertexBuffer()
|
||||
{
|
||||
SAFE_CLEAR(data);
|
||||
}
|
||||
};//struct PrimitiveVertexBuffer
|
||||
const VIL * vil;
|
||||
|
||||
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
AnsiString prim_name;
|
||||
PrimitiveData * prim_data;
|
||||
|
||||
RenderResource *db;
|
||||
Material *mtl;
|
||||
uint32_t vertices_number; ///<顶点数量
|
||||
|
||||
const VIL *vil;
|
||||
uint32_t index_number; ///<索引数量
|
||||
IndexType index_type; ///<索引类型
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
const int InitVAB(const AnsiString &name,const VkFormat format,const void *data); ///<取得顶点属性索引
|
||||
|
||||
uint32 vertices_number;
|
||||
public:
|
||||
|
||||
IndexBuffer * ibo;
|
||||
PVBMap vbo_map;
|
||||
PrimitiveCreater(GPUDevice *,const VIL *);
|
||||
PrimitiveCreater(VertexDataManager *);
|
||||
virtual ~PrimitiveCreater();
|
||||
|
||||
public:
|
||||
/**
|
||||
* 初始化一个原始图形创建
|
||||
* @parama name 原始图形名称
|
||||
* @parama vertices_count 顶点数量
|
||||
* @parama index_count 索引数量
|
||||
* @parama it 索引类型(注:当使用VDM时,此值无效)
|
||||
*/
|
||||
bool Init(const AnsiString &name,
|
||||
const uint32_t vertices_count,
|
||||
const uint32_t index_count=0,IndexType it=IndexType::AUTO);
|
||||
|
||||
PrimitiveCreater(RenderResource *sdb,const VIL *);
|
||||
virtual ~PrimitiveCreater()=default;
|
||||
void Clear(); ///<清除创建器数据
|
||||
|
||||
virtual bool Init(const uint32 vertices_count); ///<初始化,参数为顶点数量
|
||||
public: //顶点缓冲区
|
||||
|
||||
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
||||
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
template<typename T>
|
||||
T * AccessVAD(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||
{
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
VABMap * GetVABMap (const AnsiString &name,const VkFormat format=VK_FORMAT_UNDEFINED);
|
||||
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat format,const void *data); ///<直接写入顶点属性数据
|
||||
|
||||
VAD *vad=this->CreateVAD(name);
|
||||
public: //索引缓冲区
|
||||
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
const IndexType GetIndexType()const{return index_type;} ///<取得索引类型
|
||||
const uint32_t GetIndexCount()const{return index_number;} ///<取得索引数量
|
||||
|
||||
T *access=T::Create(vad);
|
||||
IBMap * GetIBMap();
|
||||
|
||||
access->Begin();
|
||||
bool WriteIBO(const void *data,const uint32_t count);
|
||||
|
||||
return access;
|
||||
}
|
||||
template<typename T>
|
||||
bool WriteIBO(const T *data){return WriteIBO(data,index_number);}
|
||||
|
||||
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
public: //创建可渲染对象
|
||||
|
||||
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
|
||||
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
|
||||
|
||||
virtual Primitive * Finish(); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
|
||||
};//class PrimitiveCreater
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -8,11 +8,7 @@ namespace hgl
|
||||
namespace graph
|
||||
{
|
||||
class Renderable;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class GPUDevice;
|
||||
struct VertexInputData;
|
||||
struct IndexBufferData;
|
||||
|
||||
struct RenderNode
|
||||
{
|
||||
|
@@ -20,7 +20,7 @@ namespace hgl
|
||||
|
||||
AABB BoundingBox; ///<绑定盒
|
||||
AABB LocalBoundingBox; ///<本地坐标绑定盒
|
||||
AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
//AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
|
||||
Vector4f Center; ///<中心点
|
||||
Vector4f LocalCenter; ///<本地坐标中心点
|
||||
@@ -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);
|
||||
@@ -91,7 +97,7 @@ namespace hgl
|
||||
|
||||
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
|
||||
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
|
||||
virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||
|
||||
virtual const Vector4f & GetCenter ()const{return Center;} ///<取得中心点
|
||||
virtual const Vector4f & GetLocalCenter ()const{return LocalCenter;} ///<取得本地坐标中心点
|
||||
|
@@ -25,8 +25,8 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
|
||||
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
|
||||
#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;
|
||||
@@ -54,16 +54,16 @@ class DeviceMemory;
|
||||
class DeviceBuffer;
|
||||
struct DeviceBufferData;
|
||||
|
||||
struct PrimitiveDataBuffer;
|
||||
struct PrimitiveRenderData;
|
||||
|
||||
class VertexAttribBuffer;
|
||||
using VBO=VertexAttribBuffer;
|
||||
using VAB=VertexAttribBuffer;
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
struct IndexBufferData
|
||||
{
|
||||
IndexBuffer *buffer=nullptr;
|
||||
VkDeviceSize offset=0;
|
||||
};
|
||||
class VABMap;
|
||||
class IBMap;
|
||||
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
@@ -97,13 +97,22 @@ class VILConfig;
|
||||
class VertexInput;
|
||||
|
||||
struct VertexInputFormat;
|
||||
using VIF=VertexInputFormat;
|
||||
|
||||
class VertexInputLayout;
|
||||
using VIL=VertexInputLayout;
|
||||
|
||||
class PrimitiveData;
|
||||
class Primitive;
|
||||
class Renderable;
|
||||
|
||||
class VertexDataManager;
|
||||
using VDM=VertexDataManager;
|
||||
|
||||
class IndirectDrawBuffer;
|
||||
class IndirectDrawIndexedBuffer;
|
||||
class IndirectDispatchBuffer;
|
||||
|
||||
class RenderResource;
|
||||
|
||||
enum class SharingMode
|
||||
@@ -137,26 +146,25 @@ inline const uint32_t GetMipLevel(const VkExtent3D &ext)
|
||||
/**
|
||||
* 索引类型,等同于VkIndexType
|
||||
*/
|
||||
enum IndexType:uint
|
||||
enum IndexType:int
|
||||
{
|
||||
AUTO=-1,
|
||||
U16=0,
|
||||
U32,
|
||||
U8=VK_INDEX_TYPE_UINT8_EXT,
|
||||
|
||||
ERR=VK_INDEX_TYPE_MAX_ENUM
|
||||
};
|
||||
|
||||
/**
|
||||
* max-lengths:
|
||||
*
|
||||
256 bytes: nvidia,arm
|
||||
128 bytes: amd,intel,powervr,adreno
|
||||
*/
|
||||
struct PushConstant
|
||||
inline const bool IsIndexType(const IndexType it)
|
||||
{
|
||||
Matrix4f local_to_world;
|
||||
Matrix4f normal;
|
||||
};
|
||||
return it>=U16&&it<=U8;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@@ -23,6 +23,7 @@ private:
|
||||
friend class GPUDevice;
|
||||
friend class VertexAttribBuffer;
|
||||
friend class IndexBuffer;
|
||||
template<typename T> friend class IndirectCommandBuffer;
|
||||
|
||||
DeviceBuffer(VkDevice d,const DeviceBufferData &b)
|
||||
{
|
||||
@@ -36,16 +37,17 @@ 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();}
|
||||
virtual void * Map (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Map(start,size);}
|
||||
void Unmap () {return buf.memory->Unmap();}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);}
|
||||
void Flush (VkDeviceSize size) {return buf.memory->Flush(size);}
|
||||
virtual void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);}
|
||||
virtual void Flush (VkDeviceSize size) {return buf.memory->Flush(size);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
|
||||
bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
virtual bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
|
||||
virtual bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
|
||||
};//class DeviceBuffer
|
||||
VK_NAMESPACE_END
|
||||
|
100
inc/hgl/graph/VKBufferMap.h
Normal file
100
inc/hgl/graph/VKBufferMap.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
template<typename T> class VKBufferMap
|
||||
{
|
||||
protected:
|
||||
|
||||
T *buffer;
|
||||
int32_t offset;
|
||||
uint32_t stride;
|
||||
uint32_t count;
|
||||
|
||||
void *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VKBufferMap()
|
||||
{
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
stride=count=0;
|
||||
}
|
||||
|
||||
virtual ~VKBufferMap()
|
||||
{
|
||||
Unmap();
|
||||
}
|
||||
|
||||
void Set(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
|
||||
{
|
||||
buffer=buf;
|
||||
offset=off;
|
||||
stride=s;
|
||||
count=c;
|
||||
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
const int32_t GetOffset ()const{ return offset;}
|
||||
const uint32_t GetStride ()const{ return stride;}
|
||||
const uint32_t GetCount ()const{ return count; }
|
||||
|
||||
const bool IsValid()const{ return buffer; }
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Unmap();
|
||||
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
stride=count=0;
|
||||
}
|
||||
|
||||
void *Map()
|
||||
{
|
||||
if(map_ptr)
|
||||
return(map_ptr);
|
||||
|
||||
if(!buffer)
|
||||
return(nullptr);
|
||||
|
||||
map_ptr=buffer->Map(offset,count);
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
if(buffer&&map_ptr)
|
||||
{
|
||||
buffer->Unmap();
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Write(const void *data,const uint32_t c)
|
||||
{
|
||||
if(!data||c==0||c>count)return(false);
|
||||
|
||||
if(!map_ptr)
|
||||
{
|
||||
if(!buffer)
|
||||
return(false);
|
||||
|
||||
/*
|
||||
* 注:这里的不管是offset还是c,都会走VAB/IndexBuffer的虚拟版本。
|
||||
* 其中的数据均为单元数据长度而非字节数。
|
||||
*
|
||||
* 如果需要传字节数,就需要buffer->DeviceBuffer::Write()这样操作
|
||||
*/
|
||||
return buffer->Write(data,offset,c);
|
||||
}
|
||||
|
||||
memcpy(map_ptr,data,stride*c);
|
||||
return(true);
|
||||
}
|
||||
};//class VKBufferMap
|
||||
VK_NAMESPACE_END
|
@@ -2,7 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
#include<hgl/graph/VKVABList.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
@@ -43,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;
|
||||
@@ -156,31 +154,33 @@ 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)
|
||||
void BindVAB(const uint32_t first,const uint32_t count,const VkBuffer *vab,const VkDeviceSize *offsets)
|
||||
{
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vab,offsets);
|
||||
}
|
||||
|
||||
bool BindVBO(VBOList *vbo_list)
|
||||
bool BindVAB(VABList *vab_list)
|
||||
{
|
||||
if(!vbo_list)return(false);
|
||||
if(!vab_list)return(false);
|
||||
|
||||
if(!vbo_list->IsFull())return(false);
|
||||
if(!vab_list->IsFull())return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
|
||||
vkCmdBindVertexBuffers(cmd_buf,
|
||||
0, //first binding
|
||||
vab_list->vab_count, //binding count
|
||||
vab_list->vab_list, //buffers
|
||||
vab_list->vab_offset); //buffer offsets
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BindIBO(const IndexBufferData *);
|
||||
void BindIBO(IndexBuffer *,const VkDeviceSize byte_offset=0);
|
||||
|
||||
bool BindVBO(Renderable *);
|
||||
bool BindDataBuffer(const PrimitiveDataBuffer *);
|
||||
|
||||
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);}
|
||||
@@ -195,15 +195,26 @@ 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);}
|
||||
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count,const uint32_t firstIndex,const int32_t vertexOffset,const uint32_t firstInstance)
|
||||
{
|
||||
vkCmdDrawIndexed(cmd_buf,
|
||||
index_count,
|
||||
instance_count,
|
||||
firstIndex,
|
||||
vertexOffset,
|
||||
firstInstance);
|
||||
}
|
||||
|
||||
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
// template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
// template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
|
||||
void DrawIndirect (VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand ));
|
||||
void DrawIndexedIndirect(VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand ));
|
||||
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);}
|
||||
void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
|
||||
|
||||
void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd,const uint32_t instance_count=1,const uint32_t first_instance=0);
|
||||
|
||||
public: //dynamic state
|
||||
};//class RenderCmdBuffer:public GPUCmdBuffer
|
||||
|
||||
|
@@ -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
|
@@ -1,8 +1,9 @@
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#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
|
||||
{
|
||||
@@ -11,10 +12,15 @@ namespace hgl
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class Material;
|
||||
class MaterialParameters;
|
||||
|
||||
/**
|
||||
* 描述符绑定器<Br>
|
||||
* 一般用于注册通用数据,为材质进行自动绑定。
|
||||
*/
|
||||
class DescriptorBinding
|
||||
{
|
||||
DescriptorSetType set_type;
|
||||
DescriptorSetType set_type; ///<描述符合集类型
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
@@ -93,6 +99,12 @@ namespace hgl
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
|
||||
|
||||
public:
|
||||
|
||||
bool Bind(Material *);
|
||||
};//class DescriptorBinding
|
||||
}//namespace graph
|
||||
|
@@ -11,12 +11,12 @@ class DeviceBuffer;
|
||||
class DescriptorSet
|
||||
{
|
||||
VkDevice device;
|
||||
int binding_count;
|
||||
int vab_count;
|
||||
VkDescriptorSet desc_set;
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
ObjectList<VkDescriptorBufferInfo> buffer_list;
|
||||
ObjectList<VkDescriptorBufferInfo> vab_list;
|
||||
ObjectList<VkDescriptorImageInfo> image_list;
|
||||
List<VkWriteDescriptorSet> wds_list;
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
|
||||
{
|
||||
device =dev;
|
||||
binding_count =bc;
|
||||
vab_count =bc;
|
||||
desc_set =ds;
|
||||
pipeline_layout =pl;
|
||||
|
||||
@@ -38,11 +38,11 @@ public:
|
||||
|
||||
~DescriptorSet()=default;
|
||||
|
||||
const uint32_t GetCount ()const{return binding_count;}
|
||||
const uint32_t GetCount ()const{return vab_count;}
|
||||
const VkDescriptorSet GetDescriptorSet ()const{return desc_set;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
|
||||
|
||||
const bool IsReady ()const{return wds_list.GetCount()==binding_count;}
|
||||
const bool IsReady ()const{return wds_list.GetCount()==vab_count;}
|
||||
|
||||
void Clear();
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/VKSwapchain.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
@@ -23,6 +22,9 @@ class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
class GPUArrayBuffer;
|
||||
class IndirectDrawBuffer;
|
||||
class IndirectDrawIndexedBuffer;
|
||||
class IndirectDispatchBuffer;
|
||||
|
||||
struct CopyBufferToImageInfo;
|
||||
|
||||
@@ -47,7 +49,7 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
VkCommandBuffer CreateCommandBuffer();
|
||||
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
|
||||
|
||||
bool CreateSwapchainFBO(Swapchain *);
|
||||
|
||||
@@ -85,6 +87,8 @@ public:
|
||||
|
||||
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
|
||||
|
||||
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
|
||||
|
||||
public:
|
||||
|
||||
bool Resize (const VkExtent2D &);
|
||||
@@ -113,9 +117,11 @@ public: //Buffer相关
|
||||
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,data,sm);}
|
||||
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,nullptr,sm);}
|
||||
|
||||
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->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VAB * CreateVAB (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VAB * CreateVAB (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVAB(format,count,nullptr,sm);}
|
||||
|
||||
const IndexType ChooseIndexType (const VkDeviceSize &vertex_count)const; ///<求一个合适的索引类型
|
||||
const bool CheckIndexType (const IndexType,const VkDeviceSize &vertex_count)const; ///<检测一个索引类型是否合适
|
||||
|
||||
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);}
|
||||
@@ -146,6 +152,14 @@ public: //Buffer相关
|
||||
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
||||
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
||||
|
||||
public: //间接绘制
|
||||
|
||||
bool CreateIndirectCommandBuffer(DeviceBufferData *,const uint32_t cmd_count,const uint32_t cmd_size,SharingMode sm=SharingMode::Exclusive);
|
||||
|
||||
IndirectDrawBuffer * CreateIndirectDrawBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
IndirectDrawIndexedBuffer * CreateIndirectDrawIndexedBuffer(const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
IndirectDispatchBuffer * CreateIndirectDispatchBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
|
||||
public: //Image
|
||||
|
||||
VkImage CreateImage (VkImageCreateInfo *);
|
||||
@@ -212,8 +226,8 @@ public: //shader & material
|
||||
|
||||
public: //Command Buffer 相关
|
||||
|
||||
RenderCmdBuffer * CreateRenderCommandBuffer();
|
||||
TextureCmdBuffer *CreateTextureCommandBuffer();
|
||||
RenderCmdBuffer * CreateRenderCommandBuffer(const AnsiString &);
|
||||
TextureCmdBuffer *CreateTextureCommandBuffer(const AnsiString &);
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include<hgl/graph/VKDebugMaker.h>
|
||||
#include<hgl/graph/VKDebugUtils.h>
|
||||
#endif//_DEBUG
|
||||
|
||||
@@ -40,6 +39,9 @@ struct GPUDeviceAttribute
|
||||
VkSurfaceTransformFlagBitsKHR preTransform;
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
|
||||
bool uint8_index_type=false;
|
||||
bool uint32_index_type=false;
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkCommandPool cmd_pool =VK_NULL_HANDLE;
|
||||
|
||||
@@ -48,7 +50,6 @@ struct GPUDeviceAttribute
|
||||
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugMaker * debug_maker =nullptr;
|
||||
DebugUtils * debug_utils =nullptr;
|
||||
#endif//_DEBUG
|
||||
|
||||
|
@@ -4,41 +4,54 @@
|
||||
#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;
|
||||
enum class SupportLevel
|
||||
{
|
||||
DontCare=0, ///<不介意
|
||||
Want, ///<希望支持
|
||||
Must, ///<必须支持
|
||||
};
|
||||
|
||||
uint min_vertex_input_attribute; ///<最小顶点输入属性数量需求
|
||||
uint min_color_attachments; ///<最小颜色输出成份数量需求
|
||||
//这里使用这种大小写是为了和VulkanSDK中的定义保持一致,cpp中使用宏比较和复制时只使用一个名字即可
|
||||
|
||||
uint min_push_constant_size; ///<最小push constant大小
|
||||
uint min_ubo_range; ///<最小ubo range需求
|
||||
uint min_ssbo_range; ///<最小ssbo range需求
|
||||
uint maxImageDimension1D;
|
||||
uint maxImageDimension2D;
|
||||
uint maxImageDimension3D;
|
||||
uint maxImageDimensionCube;
|
||||
uint maxImageArrayLayers;
|
||||
|
||||
uint min_draw_indirect_count; ///<最小间接绘制次数需求
|
||||
uint maxVertexInputAttributes; ///<最大顶点输入属性数量需求
|
||||
uint maxColorAttachments; ///<最大颜色输出成份数量需求
|
||||
|
||||
bool geometry_shader; ///<要求支持几何着色器
|
||||
bool tessellation_shader; ///<要求支持细分着色器
|
||||
// bool compute_shader; ///<要求支持计算着色器
|
||||
uint maxPushConstantsSize; ///<最大push constant大小
|
||||
uint maxUniformBufferRange; ///<最大ubo range需求
|
||||
uint maxStorageBufferRange; ///<最大ssbo range需求
|
||||
|
||||
bool multi_draw_indirect; ///<要求支持MultiDrawIndirect
|
||||
uint maxDrawIndirectCount; ///<最大间接绘制次数需求
|
||||
|
||||
bool wide_lines; ///<要求支持宽线条
|
||||
bool line_rasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
|
||||
bool large_points; ///<要求支持绘制大点
|
||||
SupportLevel geometryShader; ///<要求支持几何着色器
|
||||
SupportLevel tessellationShader; ///<要求支持细分着色器
|
||||
|
||||
bool texture_cube_array; ///<要求支持立方体数组纹理
|
||||
SupportLevel sampleRateShading; ///<要求支持采样率着色
|
||||
|
||||
bool uint8_draw_index; ///<要求支持8位索引
|
||||
bool uint32_draw_index; ///<要求支持32位索引(不建议使用)
|
||||
SupportLevel multiDrawIndirect; ///<要求支持MultiDrawIndirect
|
||||
|
||||
SupportLevel fillModeNonSolid; ///<要求支持非实体填充模式
|
||||
|
||||
SupportLevel wideLines; ///<要求支持宽线条
|
||||
SupportLevel lineRasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
|
||||
SupportLevel largePoints; ///<要求支持绘制大点
|
||||
|
||||
SupportLevel imageCubeArray; ///<要求支持立方体数组纹理
|
||||
|
||||
SupportLevel fullDrawIndexUint8; ///<要求支持8位索引
|
||||
SupportLevel fullDrawIndexUint32; ///<要求支持32位索引
|
||||
|
||||
struct
|
||||
{
|
||||
bool bc,etc2,astc_ldr,astc_hdr,pvrtc; ///<要求支持的压缩纹理格式
|
||||
SupportLevel BC,ETC2,ASTC_LDR,ASTC_HDR,PVRTC; ///<要求支持的压缩纹理格式
|
||||
}texture_compression;
|
||||
|
||||
//dynamic_state VK_EXT_extended_dynamic_state
|
||||
@@ -47,7 +60,7 @@ struct VulkanHardwareRequirement
|
||||
// primitive topology
|
||||
// viewport
|
||||
// scissor
|
||||
// bind vbo
|
||||
// bind vab
|
||||
// depth test
|
||||
// depth write
|
||||
// depth compare op
|
||||
@@ -78,12 +91,12 @@ struct VulkanHardwareRequirement
|
||||
// line stipple
|
||||
// depth clip -1 to 1
|
||||
// shading rate image enable
|
||||
bool dynamic_state[3]; ///<要求支持动态状态
|
||||
SupportLevel dynamicState[3]; ///<要求支持动态状态
|
||||
|
||||
// 1.3 特性
|
||||
bool dynamic_rendering; ///<要求支持动态渲染
|
||||
SupportLevel dynamicRendering; ///<要求支持动态渲染
|
||||
|
||||
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
|
||||
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
|
||||
|
||||
public:
|
||||
|
||||
@@ -93,7 +106,10 @@ public:
|
||||
|
||||
descriptor_pool=1024;
|
||||
|
||||
geometry_shader=true;
|
||||
geometryShader=SupportLevel::Want;
|
||||
|
||||
fullDrawIndexUint8=SupportLevel::Want;
|
||||
fullDrawIndexUint32=SupportLevel::Want;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -247,10 +263,10 @@ public:
|
||||
|
||||
VulkanDeviceCreater(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req,
|
||||
const PreferFormats *spf_color,
|
||||
const PreferColorSpaces *spf_color_space,
|
||||
const PreferFormats *spf_depth,
|
||||
const VulkanHardwareRequirement *req);
|
||||
const PreferFormats *spf_depth);
|
||||
|
||||
virtual bool ChoosePhysicalDevice();
|
||||
|
||||
@@ -267,12 +283,12 @@ public:
|
||||
|
||||
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,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
const PreferFormats * spf_depth =&PreferDepth)
|
||||
{
|
||||
VulkanDeviceCreater vdc(vi,win,spf_color,spf_color_space,spf_depth,req);
|
||||
VulkanDeviceCreater vdc(vi,win,req,spf_color,spf_color_space,spf_depth);
|
||||
|
||||
return vdc.Create();
|
||||
}
|
||||
@@ -281,34 +297,34 @@ inline GPUDevice *CreateRenderDeviceLDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferLDR,&PreferNonlinear,&PreferDepth,req);
|
||||
return CreateRenderDevice(vi,win,req,&PreferLDR,&PreferNonlinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceSDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferSDR,&PreferNonlinear,&PreferDepth,req);
|
||||
return CreateRenderDevice(vi,win,req,&PreferSDR,&PreferNonlinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR16( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferHDR16,&PreferLinear,&PreferDepth,req);
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR16,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR32( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferHDR32,&PreferLinear,&PreferDepth,req);
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR32,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferHDR,&PreferLinear,&PreferDepth,req);
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,34 +1,98 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
|
||||
namespace hgl
|
||||
VK_NAMESPACE_BEGIN
|
||||
class IndexBuffer:public DeviceBuffer
|
||||
{
|
||||
namespace graph
|
||||
IndexType index_type;
|
||||
uint stride;
|
||||
uint32_t count;
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
IndexBuffer(VkDevice d,const DeviceBufferData &vb,IndexType it,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
class IndexBuffer:public DeviceBuffer
|
||||
{
|
||||
IndexType index_type;
|
||||
uint32_t count;
|
||||
index_type=it;
|
||||
count=_count;
|
||||
|
||||
private:
|
||||
if(index_type==IndexType::U16)stride=2;else
|
||||
if(index_type==IndexType::U32)stride=4;else
|
||||
if(index_type==IndexType::U8)stride=1;else
|
||||
stride=0;
|
||||
}
|
||||
|
||||
friend class GPUDevice;
|
||||
public:
|
||||
|
||||
IndexBuffer(VkDevice d,const DeviceBufferData &vb,IndexType it,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
index_type=it;
|
||||
count=_count;
|
||||
}
|
||||
~IndexBuffer()=default;
|
||||
|
||||
public:
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint GetStride ()const{return stride;}
|
||||
const uint32 GetCount ()const{return count;}
|
||||
|
||||
~IndexBuffer()=default;
|
||||
public:
|
||||
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint32 GetCount()const{return count;}
|
||||
};//class IndexBuffer:public DeviceBuffer
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride); }
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);}
|
||||
bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);}
|
||||
};//class IndexBuffer:public DeviceBuffer
|
||||
|
||||
class IBMap:public VKBufferMap<IndexBuffer>
|
||||
{
|
||||
public:
|
||||
|
||||
using VKBufferMap<IndexBuffer>::VKBufferMap;
|
||||
virtual ~IBMap()=default;
|
||||
|
||||
const IndexType GetType()const{return buffer->GetType();}
|
||||
|
||||
void SetIBO(IndexBuffer *ib,const int32_t index_offset,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<IndexBuffer>::Set(ib,index_offset,ib->GetStride(),count);
|
||||
}
|
||||
};//class IBMap
|
||||
|
||||
/**
|
||||
* 索引缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> class IBTypeMap
|
||||
{
|
||||
IBMap *ib_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
IBTypeMap(IBMap *ibm)
|
||||
{
|
||||
ib_map=ibm;
|
||||
|
||||
if(ib_map&&ib_map->GetStride()==sizeof(T))
|
||||
map_ptr=(T *)(ib_map->Map());
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~IBTypeMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
ib_map->Unmap();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return map_ptr; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class IBTypeMap
|
||||
|
||||
using IBMapU8 =IBTypeMap<uint8>;
|
||||
using IBMapU16=IBTypeMap<uint16>;
|
||||
using IBMapU32=IBTypeMap<uint32>;
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
96
inc/hgl/graph/VKIndirectCommandBuffer.h
Normal file
96
inc/hgl/graph/VKIndirectCommandBuffer.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
template<typename T>
|
||||
class IndirectCommandBuffer:public DeviceBuffer
|
||||
{
|
||||
protected:
|
||||
|
||||
uint32_t max_count;
|
||||
|
||||
public:
|
||||
|
||||
const uint32_t GetMaxCount ()const{ return max_count; } ///<取得最大指令数
|
||||
const uint32_t GetCommandLength()const{ return sizeof(T); } ///<取得单个指令的长度字节数
|
||||
const VkDeviceSize GetTotalBytes ()const{ return sizeof(T)*max_count; } ///<取得缓冲区总计字节数
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
IndirectCommandBuffer(VkDevice d,const DeviceBufferData &vb,const uint32_t mc):DeviceBuffer(d,vb)
|
||||
{
|
||||
max_count=mc;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual ~IndirectCommandBuffer()=default;
|
||||
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override{return DeviceBuffer::Map(start*sizeof(T),size*sizeof(T));}
|
||||
T * MapCmd (VkDeviceSize start,VkDeviceSize size) {return (T *)Map(start,size);}
|
||||
T * MapCmd () {return (T *)Map(0,max_count);}
|
||||
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override{return DeviceBuffer::Flush(start*sizeof(T),size*sizeof(T));}
|
||||
void Flush (VkDeviceSize size) override{return DeviceBuffer::Flush(size*sizeof(T));}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) override{return DeviceBuffer::Write(ptr,start*sizeof(T),size*sizeof(T));}
|
||||
bool Write (const void *ptr,uint32_t size) override{return DeviceBuffer::Write(ptr,0,size*sizeof(T));}
|
||||
|
||||
bool WriteCmd(const T *ptr,uint32_t start,uint32_t size) {return DeviceBuffer::Write(ptr,start*sizeof(T),size*sizeof(T));}
|
||||
bool WriteCmd(const T *ptr,uint32_t size) {return DeviceBuffer::Write(ptr,0,size*sizeof(T));}
|
||||
};//class IndirectCommandBuffer:public DeviceBuffer
|
||||
|
||||
class IndirectDrawBuffer:public IndirectCommandBuffer<VkDrawIndirectCommand>
|
||||
{
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
using IndirectCommandBuffer<VkDrawIndirectCommand>::IndirectCommandBuffer;
|
||||
|
||||
void Draw(VkCommandBuffer cmd_buf,uint32_t cmd_offset,uint32_t draw_count) const
|
||||
{
|
||||
vkCmdDrawIndirect(cmd_buf,
|
||||
buf.buffer,
|
||||
cmd_offset*sizeof(VkDrawIndirectCommand),
|
||||
draw_count,
|
||||
sizeof(VkDrawIndirectCommand));
|
||||
}
|
||||
};//class IndirectDrawBuffer:public IndirectCommandBuffer<VkDrawIndirectCommand>
|
||||
|
||||
class IndirectDrawIndexedBuffer:public IndirectCommandBuffer<VkDrawIndexedIndirectCommand>
|
||||
{
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
using IndirectCommandBuffer<VkDrawIndexedIndirectCommand>::IndirectCommandBuffer;
|
||||
|
||||
void DrawIndexed(VkCommandBuffer cmd_buf,uint32_t cmd_offset,uint32_t draw_count) const
|
||||
{
|
||||
vkCmdDrawIndexedIndirect(cmd_buf,
|
||||
buf.buffer,
|
||||
cmd_offset*sizeof(VkDrawIndexedIndirectCommand),
|
||||
draw_count,
|
||||
sizeof(VkDrawIndexedIndirectCommand));
|
||||
}
|
||||
};//class IndirectDrawIndexedBuffer:public IndirectCommandBuffer<VkDrawIndexedIndirectCommand>
|
||||
|
||||
class IndirectDispatchBuffer:public IndirectCommandBuffer<VkDispatchIndirectCommand>
|
||||
{
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
using IndirectCommandBuffer<VkDispatchIndirectCommand>::IndirectCommandBuffer;
|
||||
|
||||
void Dispatch(VkCommandBuffer cmd_buf,uint32_t offset) const
|
||||
{
|
||||
vkCmdDispatchIndirect(cmd_buf,buf.buffer,offset);
|
||||
}
|
||||
};//class IndirectDispatchBuffer:public IndirectCommandBuffer<VkDispatchIndirectCommand>
|
||||
VK_NAMESPACE_END
|
@@ -28,6 +28,11 @@ VK_NAMESPACE_BEGIN
|
||||
VK_BOOL1BIT(profiles)
|
||||
}khronos;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(switchable_graphics)
|
||||
}amd;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(optimus)
|
||||
|
@@ -49,15 +49,15 @@ public:
|
||||
|
||||
virtual ~Material();
|
||||
|
||||
const UTF8String & GetName ()const{return name;}
|
||||
const AnsiString & GetName ()const{return name;}
|
||||
|
||||
const VertexInput * GetVertexInput ()const{return vertex_input;}
|
||||
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
||||
|
||||
const MaterialDescriptorManager * GetDescriptorSets ()const{return desc_manager;}
|
||||
// const MaterialDescriptorManager * GetDescriptorManager ()const{return desc_manager;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const;
|
||||
const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
|
||||
// const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
|
||||
|
||||
public:
|
||||
|
||||
@@ -81,6 +81,8 @@ public:
|
||||
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;}
|
||||
|
@@ -5,9 +5,6 @@
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
using BindingMap=Map<AnsiString,int>;
|
||||
using BindingMapArray=BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
class MaterialDescriptorManager
|
||||
{
|
||||
UTF8String mtl_name;
|
||||
|
@@ -35,6 +35,8 @@ public:
|
||||
void Free() override {/* DON'T RUN ANY OPERATION.*/}
|
||||
|
||||
void Flush(const VkDeviceSize);
|
||||
|
||||
bool Write(const void *source,const uint64 offset,const uint64 size) override;
|
||||
};//class VKMemoryAllocator:public AbstractMemoryAllocator
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MEMORY_ALLOCATOR_INCLUDE
|
||||
|
@@ -27,6 +27,7 @@ class GPUPhysicalDevice
|
||||
|
||||
private:
|
||||
|
||||
bool support_u8_index=false;
|
||||
bool dynamic_state=false;
|
||||
|
||||
public:
|
||||
@@ -141,8 +142,13 @@ public:
|
||||
public:
|
||||
|
||||
const VkBool32 SupportGeometryShader ()const{return features.geometryShader;}
|
||||
const VkBool32 SupportTessellationShader ()const{return features.tessellationShader;}
|
||||
|
||||
const VkBool32 SupportCubeMapArray ()const{return features.imageCubeArray;}
|
||||
|
||||
const VkBool32 SupportU32Index ()const{return features.fullDrawIndexUint32;}
|
||||
const VkBool32 SupportU8Index ()const{return support_u8_index;}
|
||||
|
||||
// support != open, so please don't direct use GetFeatures().
|
||||
// open any features in CreateDevice()&SetDeviceFeatures() functions.
|
||||
const bool SupportMDI ()const
|
||||
|
@@ -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,6 +38,8 @@ public:
|
||||
|
||||
virtual ~Pipeline();
|
||||
|
||||
const AnsiString &GetName()const{return name;}
|
||||
|
||||
operator VkPipeline(){return pipeline;}
|
||||
|
||||
const PipelineData *GetData()const{return data;}
|
||||
|
@@ -1,78 +1,53 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 单一图元数据
|
||||
* 原始图元数据访问接口<br>
|
||||
* Primitive的存为是为了屏蔽PrimitiveData的初始化之类的访问接口,以便于更好的管理和使用
|
||||
*/
|
||||
class Primitive
|
||||
{
|
||||
struct VBOData
|
||||
{
|
||||
VBO *buf;
|
||||
VkDeviceSize offset;
|
||||
|
||||
public:
|
||||
|
||||
CompOperatorMemcmp(const VBOData &);
|
||||
};
|
||||
|
||||
Map<AnsiString,VBOData> buffer_list;
|
||||
|
||||
protected:
|
||||
|
||||
uint32_t vertex_count;
|
||||
AnsiString prim_name;
|
||||
|
||||
IndexBufferData index_buffer_data;
|
||||
PrimitiveData * prim_data;
|
||||
|
||||
protected:
|
||||
|
||||
AABB BoundingBox;
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
|
||||
friend class RenderableNode;
|
||||
|
||||
uint ref_count=0;
|
||||
|
||||
uint RefInc(){return ++ref_count;}
|
||||
uint RefDec(){return --ref_count;}
|
||||
Primitive(const AnsiString &pn,PrimitiveData *pd);
|
||||
virtual ~Primitive();
|
||||
|
||||
public:
|
||||
|
||||
Primitive(const uint32_t vc=0):vertex_count(vc){}
|
||||
virtual ~Primitive()=default;
|
||||
const AnsiString & GetName ()const{ return prim_name; }
|
||||
|
||||
const uint GetRefCount()const{return ref_count;}
|
||||
const VkDeviceSize GetVertexCount ()const;
|
||||
const int GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VAB * GetVAB (const int);
|
||||
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
||||
const int32_t GetVertexOffset ()const; ///<取得顶点偏移(注意是顶点不是字节)
|
||||
VABMap * GetVABMap (const int); ///<取得VAB映射器
|
||||
VABMap * GetVABMap (const AnsiString &name){return GetVABMap(GetVABIndex(name));}
|
||||
|
||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||
const AABB & GetBoundingBox()const {return BoundingBox;}
|
||||
const uint32_t GetIndexCount ()const;
|
||||
IndexBuffer * GetIBO ();
|
||||
const uint32_t GetFirstIndex ()const; ///<取得第一个索引
|
||||
IBMap * GetIBMap (); ///<取得索引缓冲区映射器
|
||||
|
||||
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||
VertexDataManager * GetVDM (); ///<取得顶点数据管理器
|
||||
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
||||
{
|
||||
if(!ib)return(false);
|
||||
|
||||
index_buffer_data.buffer=ib;
|
||||
index_buffer_data.offset=offset;
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
const uint32_t GetVertexCount ()const {return vertex_count;}
|
||||
|
||||
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
|
||||
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
|
||||
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
||||
|
||||
const IndexBufferData * GetIndexBufferData ()const {return &index_buffer_data;}
|
||||
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
||||
};//class Primitive
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
|
@@ -25,7 +25,7 @@ protected:
|
||||
|
||||
ObjectList<Pipeline> pipeline_list;
|
||||
|
||||
Pipeline *CreatePipeline(PipelineData *,const ShaderStageCreateInfoList &,VkPipelineLayout,const VIL *);
|
||||
Pipeline *CreatePipeline(const AnsiString &,PipelineData *,const ShaderStageCreateInfoList &,VkPipelineLayout,const VIL *);
|
||||
|
||||
private:
|
||||
|
||||
|
@@ -5,19 +5,27 @@
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/font/TextPrimitive.h>
|
||||
#include<hgl/type/ObjectManage.h>
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/VKDescriptorBindingManage.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace mtl
|
||||
{
|
||||
struct Material2DCreateConfig;
|
||||
struct Material3DCreateConfig;
|
||||
}//namespace mtl
|
||||
|
||||
using MaterialID =int;
|
||||
using MaterialInstanceID =int;
|
||||
using BufferID =int;
|
||||
@@ -52,17 +60,40 @@ class RenderResource
|
||||
IDObjectManage<TextureID, Texture> rm_textures; ///<纹理合集
|
||||
IDObjectManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
||||
|
||||
private:
|
||||
|
||||
void AddBuffer(const AnsiString &buf_name,DeviceBuffer *buf)
|
||||
{
|
||||
rm_buffers.Add(buf);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
{
|
||||
du->SetBuffer(buf->GetBuffer(),buf_name+":Buffer");
|
||||
du->SetDeviceMemory(buf->GetVkMemory(),buf_name+":Memory");
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
GPUDevice *GetDevice(){return device;}
|
||||
|
||||
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
|
||||
DescriptorBinding static_descriptor; ///<静态属性描述符绑定管理
|
||||
DescriptorBinding global_descriptor; ///<全局属性描述符绑定管理
|
||||
|
||||
public:
|
||||
|
||||
RenderResource(GPUDevice *dev):device(dev),global_descriptor(DescriptorSetType::Global){}
|
||||
RenderResource(GPUDevice *dev):device(dev),
|
||||
static_descriptor(DescriptorSetType::Static),
|
||||
global_descriptor(DescriptorSetType::Global)
|
||||
{}
|
||||
virtual ~RenderResource()=default;
|
||||
|
||||
public: //Add
|
||||
public: //添加数据到管理器(如果指针为nullptr会返回-1)
|
||||
|
||||
MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
|
||||
MaterialInstanceID Add(MaterialInstance * mi ){return rm_material_instance.Add(mi);}
|
||||
@@ -73,14 +104,13 @@ public: //Add
|
||||
TextureID Add(Texture * t ){return rm_textures.Add(t);}
|
||||
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
||||
|
||||
public: // VBO/VAO
|
||||
public: // VAB/VAO
|
||||
|
||||
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->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VAB *CreateVAB(VkFormat format,uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VAB *CreateVAB(VkFormat format,uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVAB(format, count, nullptr, sm);}
|
||||
|
||||
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
|
||||
DeviceBuffer *Create##name(VkDeviceSize size,SharingMode sm=SharingMode::Exclusive);
|
||||
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
|
||||
DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,SharingMode sm=SharingMode::Exclusive){return Create##name(buf_name,size,nullptr,sm);}
|
||||
|
||||
SCENE_DB_CREATE_FUNC(UBO)
|
||||
SCENE_DB_CREATE_FUNC(SSBO)
|
||||
@@ -89,25 +119,37 @@ public: // VBO/VAO
|
||||
#undef SCENE_DB_CREATE_FUNC
|
||||
|
||||
IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
|
||||
IndexBuffer *CreateIBO8 ( uint32_t count,const uint8 *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 index_type,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(index_type,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);}
|
||||
IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(index_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);}
|
||||
|
||||
public: //Material
|
||||
|
||||
const ShaderModule *CreateShaderModule(const AnsiString &shader_module_name,const ShaderCreateInfo *);
|
||||
|
||||
Material * CreateMaterial(const mtl::MaterialCreateInfo *);
|
||||
Material * LoadMaterial(const AnsiString &,mtl::Material2DCreateConfig *);
|
||||
Material * LoadMaterial(const AnsiString &,mtl::Material3DCreateConfig *);
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg,const void *,const int);
|
||||
|
||||
template<typename T>
|
||||
MaterialInstance * CreateMaterialInstance(Material *mtl,const VILConfig *vil_cfg,const T *data)
|
||||
{
|
||||
return CreateMaterialInstance(mtl,vil_cfg,data,sizeof(T));
|
||||
}
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||
|
||||
Primitive * CreatePrimitive(const uint32_t vertex_count=0);
|
||||
|
||||
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||
Renderable * CreateRenderable(PrimitiveCreater *pc,MaterialInstance *mi,Pipeline *p);
|
||||
|
||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
Sampler * CreateSampler(Texture *);
|
||||
@@ -117,7 +159,7 @@ public: //texture
|
||||
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
|
||||
TextureCube * LoadTextureCube(const OSString &,bool auto_mipmaps=false);
|
||||
|
||||
Texture2DArray * CreateTexture2DArray(const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps=false);
|
||||
Texture2DArray * CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps=false);
|
||||
bool LoadTexture2DToArray(Texture2DArray *,const uint32_t layer,const OSString &);
|
||||
|
||||
public: //Get
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#ifndef HGL_GRAPH_RENDERABLE_INCLUDE
|
||||
#define HGL_GRAPH_RENDERABLE_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
@@ -9,43 +8,64 @@
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct VertexInputData
|
||||
/**
|
||||
* 原始图元数据缓冲区<Br>
|
||||
* 提供在渲染之前的数据绑定信息
|
||||
*/
|
||||
struct PrimitiveDataBuffer
|
||||
{
|
||||
uint32_t binding_count;
|
||||
VkBuffer *buffer_list;
|
||||
VkDeviceSize *buffer_offset;
|
||||
uint32_t vab_count;
|
||||
VkBuffer * vab_list;
|
||||
|
||||
uint32_t vertex_count;
|
||||
// 理论上讲,每个VAB绑定时都是可以指定byte offsets的。但是随后Draw时,又可以指定vertexOffset。
|
||||
// 在我们支持的两种draw模式中,一种是每个模型一批VAB,所有VAB的offset都是0。
|
||||
// 另一种是使用VDM,为了批量渲染,所有的VAB又必须对齐,所以每个VAB单独指定offset也不可行。
|
||||
|
||||
const IndexBufferData *index_buffer;
|
||||
VkDeviceSize * vab_offset; //注意:这里的offset是字节偏移,不是顶点偏移
|
||||
|
||||
IndexBuffer * ibo;
|
||||
|
||||
VertexDataManager *vdm; //只是用来区分和比较的,不实际使用
|
||||
|
||||
public:
|
||||
|
||||
VertexInputData(const uint32_t,const uint32_t,const IndexBufferData *);
|
||||
~VertexInputData();
|
||||
PrimitiveDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr);
|
||||
~PrimitiveDataBuffer();
|
||||
|
||||
const bool Comp(const VertexInputData *vid)const
|
||||
{
|
||||
if(!vid)return(false);
|
||||
|
||||
if(binding_count!=vid->binding_count)return(false);
|
||||
|
||||
for(uint32_t i=0;i<binding_count;i++)
|
||||
{
|
||||
if(buffer_list[i]!=vid->buffer_list[i])return(false);
|
||||
if(buffer_offset[i]!=vid->buffer_offset[i])return(false);
|
||||
}
|
||||
|
||||
if(vertex_count!=vid->vertex_count)return(false);
|
||||
|
||||
if(index_buffer!=vid->index_buffer)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//struct VertexInputData
|
||||
const bool Comp(const PrimitiveDataBuffer *pdb)const;
|
||||
};//struct PrimitiveDataBuffer
|
||||
|
||||
/**
|
||||
* 可渲染对象<br>
|
||||
* 原始图元渲染数据<Br>
|
||||
* 提供在渲染时的数据
|
||||
*/
|
||||
struct PrimitiveRenderData
|
||||
{
|
||||
//因为要VAB是流式访问,所以我们这个结构会被用做排序依据
|
||||
//也因此,把vertex_offset放在最前面
|
||||
|
||||
int32_t vertex_offset; //注意:这里的offset是相对于vertex的,代表第几个顶点,不是字节偏移
|
||||
uint32_t first_index;
|
||||
|
||||
uint32_t vertex_count;
|
||||
uint32_t index_count;
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveRenderData(const uint32_t vc,const uint32_t ic,const int32_t vo=0,const uint32_t fi=0)
|
||||
{
|
||||
vertex_count =vc;
|
||||
index_count =ic;
|
||||
vertex_offset =vo;
|
||||
first_index =fi;
|
||||
}
|
||||
|
||||
CompOperatorMemcmp(const PrimitiveRenderData &);
|
||||
CompOperatorMemcmpPointer(PrimitiveRenderData);
|
||||
};
|
||||
|
||||
/**
|
||||
* 原始可渲染对象(即仅一个模型一个材质)
|
||||
*/
|
||||
class Renderable ///可渲染对象实例
|
||||
{
|
||||
@@ -53,17 +73,24 @@ class Renderable
|
||||
MaterialInstance * mat_inst;
|
||||
Primitive * primitive;
|
||||
|
||||
VertexInputData * vertex_input;
|
||||
PrimitiveDataBuffer * primitive_data_buffer;
|
||||
PrimitiveRenderData * primitive_render_data;
|
||||
|
||||
private:
|
||||
|
||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *);
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,PrimitiveDataBuffer *,PrimitiveRenderData *);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Renderable();
|
||||
virtual ~Renderable()
|
||||
{
|
||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||
|
||||
SAFE_CLEAR(primitive_data_buffer);
|
||||
SAFE_CLEAR(primitive_render_data);
|
||||
}
|
||||
|
||||
void UpdatePipeline (Pipeline *p){pipeline=p;}
|
||||
|
||||
@@ -74,9 +101,9 @@ public:
|
||||
Primitive * GetPrimitive (){return primitive;}
|
||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
||||
|
||||
const VertexInputData * GetVertexInputData ()const{return vertex_input;}
|
||||
const PrimitiveDataBuffer *GetDataBuffer ()const{return primitive_data_buffer;}
|
||||
const PrimitiveRenderData *GetRenderData ()const{return primitive_render_data;}
|
||||
};//class Renderable
|
||||
|
||||
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_RENDERABLE_INCLUDE
|
||||
|
@@ -1,53 +0,0 @@
|
||||
#ifndef HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
||||
#define HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderablePrimitiveCreater
|
||||
{
|
||||
RenderResource *rr;
|
||||
|
||||
uint32_t vertex_count;
|
||||
|
||||
Primitive *prim;
|
||||
|
||||
public:
|
||||
|
||||
RenderablePrimitiveCreater(RenderResource *_rr,uint32_t vc)
|
||||
{
|
||||
rr=_rr;
|
||||
vertex_count=vc;
|
||||
|
||||
prim=rr->CreatePrimitive(vertex_count);
|
||||
}
|
||||
|
||||
bool SetVBO(const AnsiString &name,const VkFormat &fmt,const void *buf)
|
||||
{
|
||||
VBO *vbo=rr->CreateVBO(fmt,vertex_count,buf);
|
||||
|
||||
if(!vbo)
|
||||
return(false);
|
||||
|
||||
prim->Set(name,vbo);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool SetIBO(const IndexType &it,const void *buf,const uint32_t index_count)
|
||||
{
|
||||
IndexBuffer *ibo=rr->CreateIBO(it,index_count,buf);
|
||||
|
||||
if(!ibo)
|
||||
return(false);
|
||||
|
||||
prim->Set(ibo);
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Create(MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
return rr->CreateRenderable(prim,mi,p);
|
||||
}
|
||||
};//class RenderablePrimitiveCreater
|
||||
VK_NAMESPACE_END
|
||||
#endif // HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
TextureData * GetData () {return data;}
|
||||
|
||||
VkDeviceMemory GetDeviceMemory () {return data?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE;}
|
||||
VkDeviceMemory GetDeviceMemory () {return data?(data->memory?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE):VK_NULL_HANDLE;}
|
||||
VkImage GetImage () {return data?data->image:VK_NULL_HANDLE;}
|
||||
VkImageLayout GetImageLayout () {return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;}
|
||||
VkImageView GetVulkanImageView () {return data?data->image_view->GetImageView():VK_NULL_HANDLE;}
|
||||
|
@@ -292,7 +292,7 @@ struct SwapchainDepthTextureCreateInfo:public TextureCreateInfo
|
||||
|
||||
struct TextureData
|
||||
{
|
||||
DeviceMemory * memory;
|
||||
DeviceMemory * memory;
|
||||
VkImage image;
|
||||
VkImageLayout image_layout;
|
||||
ImageView * image_view;
|
||||
|
61
inc/hgl/graph/VKVABList.h
Normal file
61
inc/hgl/graph/VKVABList.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VABList
|
||||
{
|
||||
uint32_t vab_count;
|
||||
VkBuffer *vab_list;
|
||||
VkDeviceSize *vab_offset;
|
||||
|
||||
uint32_t write_count;
|
||||
|
||||
friend class RenderCmdBuffer;
|
||||
|
||||
public:
|
||||
|
||||
VABList(const uint32 bc)
|
||||
{
|
||||
vab_count=bc;
|
||||
vab_list=new VkBuffer[vab_count];
|
||||
vab_offset=new VkDeviceSize[vab_count];
|
||||
|
||||
write_count=0;
|
||||
}
|
||||
|
||||
~VABList()
|
||||
{
|
||||
delete[] vab_offset;
|
||||
delete[] vab_list;
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
write_count=0;
|
||||
}
|
||||
|
||||
const bool IsFull()const
|
||||
{
|
||||
return write_count>=vab_count;
|
||||
}
|
||||
|
||||
void Add(const VkBuffer buf,const VkDeviceSize offset)
|
||||
{
|
||||
vab_list[write_count]=buf;
|
||||
vab_offset[write_count]=offset;
|
||||
|
||||
++write_count;
|
||||
}
|
||||
|
||||
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
|
||||
{
|
||||
hgl_cpy(vab_list +write_count,buf, count);
|
||||
|
||||
if(offset)
|
||||
hgl_cpy(vab_offset+write_count,offset,count);
|
||||
else
|
||||
hgl_set<VkDeviceSize>(vab_offset+write_count,VkDeviceSize(0),count);
|
||||
|
||||
write_count+=count;
|
||||
}
|
||||
};//class VABList
|
||||
VK_NAMESPACE_END
|
@@ -1,57 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VBOList
|
||||
{
|
||||
uint32_t binding_count;
|
||||
VkBuffer *buffer_list;
|
||||
VkDeviceSize *buffer_offset;
|
||||
|
||||
uint32_t write_count;
|
||||
|
||||
friend class RenderCmdBuffer;
|
||||
|
||||
public:
|
||||
|
||||
VBOList(const uint32 bc)
|
||||
{
|
||||
binding_count=bc;
|
||||
buffer_list=new VkBuffer[binding_count];
|
||||
buffer_offset=new VkDeviceSize[binding_count];
|
||||
|
||||
write_count=0;
|
||||
}
|
||||
|
||||
~VBOList()
|
||||
{
|
||||
delete[] buffer_offset;
|
||||
delete[] buffer_list;
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
write_count=0;
|
||||
}
|
||||
|
||||
const bool IsFull()const
|
||||
{
|
||||
return write_count>=binding_count;
|
||||
}
|
||||
|
||||
void Add(const VkBuffer buf,const VkDeviceSize offset)
|
||||
{
|
||||
buffer_list[write_count]=buf;
|
||||
buffer_offset[write_count]=offset;
|
||||
|
||||
++write_count;
|
||||
}
|
||||
|
||||
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
|
||||
{
|
||||
hgl_cpy(buffer_list +write_count,buf, count);
|
||||
hgl_cpy(buffer_offset+write_count,offset,count);
|
||||
|
||||
write_count+=count;
|
||||
}
|
||||
};//class VBOList
|
||||
VK_NAMESPACE_END
|
@@ -1,39 +1,248 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
|
||||
namespace hgl
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VertexAttribBuffer:public DeviceBuffer
|
||||
{
|
||||
namespace graph
|
||||
VkFormat format; ///<数据格式
|
||||
uint32_t stride; ///<单个数据字节数
|
||||
uint32_t count; ///<数据数量
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
VertexAttribBuffer(VkDevice d,const DeviceBufferData &vb,VkFormat fmt,uint32_t _stride,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
class VertexAttribBuffer:public DeviceBuffer
|
||||
format=fmt;
|
||||
stride=_stride;
|
||||
count=_count;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~VertexAttribBuffer()=default;
|
||||
|
||||
const VkFormat GetFormat()const { return format; }
|
||||
const uint32_t GetStride()const { return stride; }
|
||||
const uint32_t GetCount ()const { return count; }
|
||||
|
||||
const VkDeviceSize GetTotalBytes()const { return stride*count; }
|
||||
|
||||
public:
|
||||
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);}
|
||||
bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);}
|
||||
};//class VertexAttribBuffer:public DeviceBuffer
|
||||
|
||||
using VAB=VertexAttribBuffer;
|
||||
|
||||
class VABMap:public VKBufferMap<VAB>
|
||||
{
|
||||
public:
|
||||
|
||||
using VKBufferMap<VAB>::VKBufferMap;
|
||||
virtual ~VABMap()=default;
|
||||
|
||||
const VkFormat GetFormat()const { return buffer->GetFormat(); }
|
||||
|
||||
void SetVAB(VAB *vab,const VkDeviceSize off,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<VAB>::Set(vab,off,vab->GetStride(),count);
|
||||
}
|
||||
};//class VABMap
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区原生数据访问映射
|
||||
*/
|
||||
template<typename T> class VABRawMap
|
||||
{
|
||||
VABMap *vab_map;
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABRawMap(VABMap *map,const VkFormat check_format=VK_FORMAT_UNDEFINED,bool now_map=true)
|
||||
{
|
||||
vab_map=map;
|
||||
map_ptr=nullptr;
|
||||
|
||||
if(vab_map)
|
||||
{
|
||||
VkFormat format; ///<<3C><><EFBFBD>ݸ<EFBFBD>ʽ
|
||||
uint32_t stride; ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
uint32_t count; ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
VertexAttribBuffer(VkDevice d,const DeviceBufferData &vb,VkFormat fmt,uint32_t _stride,uint32_t _count):DeviceBuffer(d,vb)
|
||||
if(check_format==VK_FORMAT_UNDEFINED
|
||||
||check_format==vab_map->GetFormat())
|
||||
{
|
||||
format=fmt;
|
||||
stride=_stride;
|
||||
count=_count;
|
||||
if(now_map)
|
||||
map_ptr=(T *)(vab_map->Map());
|
||||
}
|
||||
else
|
||||
{
|
||||
vab_map=nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
~VABRawMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
vab_map->Unmap();
|
||||
}
|
||||
|
||||
~VertexAttribBuffer()=default;
|
||||
const bool IsValid()const{ return vab_map?vab_map->IsValid():false; }
|
||||
|
||||
const VkFormat GetFormat()const { return format; }
|
||||
const uint32_t GetStride()const { return stride; }
|
||||
const uint32_t GetCount ()const { return count; }
|
||||
};//class VertexAttribBuffer:public DeviceBuffer
|
||||
T *Map()
|
||||
{
|
||||
if(!vab_map)
|
||||
return(nullptr);
|
||||
|
||||
using VBO=VertexAttribBuffer;
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
if(!map_ptr)
|
||||
map_ptr=(T *)(vab_map->Map());
|
||||
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
if(vab_map)
|
||||
{
|
||||
if(map_ptr)
|
||||
vab_map->Unmap();
|
||||
}
|
||||
}
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class VABRawMap
|
||||
|
||||
typedef VABRawMap<int8> VABMapI8, VABMapByte;
|
||||
typedef VABRawMap<int16> VABMapI16, VABMapShort;
|
||||
typedef VABRawMap<int32> VABMapI32, VABMapInt;
|
||||
typedef VABRawMap<uint8> VABMapU8, VABMapUByte;
|
||||
typedef VABRawMap<uint16> VABMapU16, VABMapUShort;
|
||||
typedef VABRawMap<uint32> VABMapU32, VABMapUInt;
|
||||
typedef VABRawMap<float> VABMapFloat;
|
||||
typedef VABRawMap<double> VABMapDouble;
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> class VABFormatMap
|
||||
{
|
||||
VABMap *vab_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABFormatMap(VABMap *map,bool now_map=true)
|
||||
{
|
||||
vab_map=map;
|
||||
|
||||
if(vab_map&&vab_map->GetFormat()==T::GetVulkanFormat())
|
||||
{
|
||||
if(now_map)
|
||||
{
|
||||
map_ptr=T::Create(vab_map->GetCount(),vab_map->Map());
|
||||
map_ptr->Begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
map_ptr=T::Create(vab_map->GetCount(),nullptr);
|
||||
}
|
||||
}
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~VABFormatMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
{
|
||||
vab_map->Unmap();
|
||||
delete map_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return map_ptr?map_ptr->IsValid():false; }
|
||||
|
||||
T *Map()
|
||||
{
|
||||
if(!vab_map)
|
||||
return(nullptr);
|
||||
|
||||
if(!map_ptr)
|
||||
{
|
||||
map_ptr=T::Create(vab_map->GetCount(),vab_map->Map());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!map_ptr->IsValid())
|
||||
map_ptr->SetData(vab_map->Map());
|
||||
}
|
||||
|
||||
map_ptr->Begin();
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
if(vab_map)
|
||||
{
|
||||
if(map_ptr&&map_ptr->IsValid())
|
||||
{
|
||||
vab_map->Unmap();
|
||||
map_ptr->SetData(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
return Map();
|
||||
}
|
||||
|
||||
T *operator->()
|
||||
{
|
||||
return map_ptr;
|
||||
}
|
||||
};//template<typename T> class VABFormatMap
|
||||
|
||||
typedef VABFormatMap<VB1i8> VABMap1i8 ,VABMap1b;
|
||||
typedef VABFormatMap<VB1i16> VABMap1i16,VABMap1s;
|
||||
typedef VABFormatMap<VB1i32> VABMap1i32,VABMap1i;
|
||||
typedef VABFormatMap<VB1u8> VABMap1u8 ,VABMap1ub;
|
||||
typedef VABFormatMap<VB1u16> VABMap1u16,VABMap1us;
|
||||
typedef VABFormatMap<VB1u32> VABMap1u32,VABMap1ui;
|
||||
typedef VABFormatMap<VB1f> VABMap1f;
|
||||
typedef VABFormatMap<VB1d> VABMap1d;
|
||||
|
||||
typedef VABFormatMap<VB2i8> VABMap2i8 ,VABMap2b;
|
||||
typedef VABFormatMap<VB2i16> VABMap2i16,VABMap2s;
|
||||
typedef VABFormatMap<VB2i32> VABMap2i32,VABMap2i;
|
||||
typedef VABFormatMap<VB2u8> VABMap2u8 ,VABMap2ub;
|
||||
typedef VABFormatMap<VB2u16> VABMap2u16,VABMap2us;
|
||||
typedef VABFormatMap<VB2u32> VABMap2u32,VABMap2ui;
|
||||
typedef VABFormatMap<VB2f> VABMap2f;
|
||||
typedef VABFormatMap<VB2d> VABMap2d;
|
||||
|
||||
typedef VABFormatMap<VB3i32> VABMap3i32,VABMap3i;
|
||||
typedef VABFormatMap<VB3u32> VABMap3u32,VABMap3ui;
|
||||
typedef VABFormatMap<VB3f> VABMap3f;
|
||||
typedef VABFormatMap<VB3d> VABMap3d;
|
||||
|
||||
typedef VABFormatMap<VB4i8> VABMap4i8 ,VABMap4b;
|
||||
typedef VABFormatMap<VB4i16> VABMap4i16,VABMap4s;
|
||||
typedef VABFormatMap<VB4i32> VABMap4i32,VABMap4i;
|
||||
typedef VABFormatMap<VB4u8> VABMap4u8, VABMap4ub;
|
||||
typedef VABFormatMap<VB4u16> VABMap4u16,VABMap4us;
|
||||
typedef VABFormatMap<VB4u32> VABMap4u32,VABMap4ui;
|
||||
typedef VABFormatMap<VB4f> VABMap4f;
|
||||
typedef VABFormatMap<VB4d> VABMap4d;
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,57 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
||||
#define HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 顶点属性数据
|
||||
*/
|
||||
class VertexAttribData ///顶点属性数据
|
||||
{
|
||||
void *mem_data; ///<内存中的数据
|
||||
|
||||
protected:
|
||||
|
||||
VkFormat format;
|
||||
|
||||
uint32_t count; ///<数据个数
|
||||
uint32_t total_bytes; ///<字节数
|
||||
|
||||
public:
|
||||
|
||||
VertexAttribData(uint32_t c,const VkFormat vf,const uint32_t t)
|
||||
{
|
||||
count=c;
|
||||
format=vf;
|
||||
total_bytes=t;
|
||||
|
||||
mem_data = hgl_malloc(total_bytes); //在很多情况下,hgl_malloc分配的内存是对齐的,这样有效率上的提升
|
||||
}
|
||||
|
||||
virtual ~VertexAttribData()
|
||||
{
|
||||
if(mem_data)
|
||||
hgl_free(mem_data);
|
||||
}
|
||||
|
||||
const VkFormat GetFormat ()const{return format;} ///<取得数据类型
|
||||
const uint32_t GetCount ()const{return count;} ///<取得数据数量
|
||||
void * GetData ()const{return mem_data;} ///<取得数据指针
|
||||
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
|
||||
};//class VertexAttribData
|
||||
|
||||
using VAD=VertexAttribData;
|
||||
|
||||
/**
|
||||
* 根据格式要求,创建对应的顶点属性数据区(VAD)
|
||||
* @param vertex_count 顶点数量
|
||||
* @param vif 格式
|
||||
*/
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif);
|
||||
//这个函数比较重要,就不搞成CreateVAD的简写了
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
@@ -5,8 +5,9 @@
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@@ -39,11 +40,21 @@ namespace hgl
|
||||
|
||||
access =nullptr;
|
||||
start_access=nullptr;
|
||||
|
||||
}
|
||||
|
||||
virtual ~VertexAttribDataAccess()=default;
|
||||
|
||||
void SetData(T *_data)
|
||||
{
|
||||
data =_data;
|
||||
data_end=_data+count*C;
|
||||
}
|
||||
|
||||
const bool IsValid()const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void Write(const T *ptr)
|
||||
{
|
||||
if(!ptr)return;
|
||||
@@ -53,14 +64,14 @@ namespace hgl
|
||||
|
||||
/**
|
||||
* 取得数据区地址
|
||||
* @param offset 从第几个数据开始访问
|
||||
* @param start 从第几个数据开始访问
|
||||
* @return 访问地址
|
||||
*/
|
||||
T *Get(uint32_t offset=0)
|
||||
{
|
||||
if(!data||offset>=count)
|
||||
{
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,offset:")+OSString::numberOf(offset));
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,start:")+OSString::numberOf(offset));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
@@ -69,14 +80,14 @@ namespace hgl
|
||||
|
||||
/**
|
||||
* 开始访问数据区
|
||||
* @param offset 从第几个数据开始访问
|
||||
* @param start 从第几个数据开始访问
|
||||
* @return 访问地址
|
||||
*/
|
||||
T *Begin(uint32_t offset=0)
|
||||
{
|
||||
if(access)
|
||||
{
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,offset:")+OSString::numberOf(offset));
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,start:")+OSString::numberOf(offset));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
@@ -130,14 +141,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess1<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess1<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess1<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess1<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +203,7 @@ namespace hgl
|
||||
* @param v 值
|
||||
* @param count 写入数量
|
||||
*/
|
||||
bool Write(const T v,const uint32_t count)
|
||||
bool RepeatWrite(const T v,const uint32_t count)
|
||||
{
|
||||
if(!this->access||this->access+count>this->data_end)
|
||||
{
|
||||
@@ -223,14 +229,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess2<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess2<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess2<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess2<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,6 +304,23 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Write(const T *v,const uint count)
|
||||
{
|
||||
if(!this->access||this->access+2>this->data_end)
|
||||
{
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess2::Write(T *) out"));
|
||||
return(false);
|
||||
}
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
*this->access++=*v++;
|
||||
*this->access++=*v++;
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
template<typename V2>
|
||||
bool Write(const V2 &v)
|
||||
{
|
||||
@@ -522,14 +540,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess3<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess3<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess3<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess3<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -794,14 +807,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess4<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess4<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess4<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess4<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
62
inc/hgl/graph/VertexDataManager.h
Normal file
62
inc/hgl/graph/VertexDataManager.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/type/DataChain.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class VertexDataManager
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
protected:
|
||||
|
||||
const VIL * vil; ///<顶点输入格式列表
|
||||
uint vi_count; ///<顶点输入流数量
|
||||
const VIF * vif_list; ///<顶点输入格式列表
|
||||
|
||||
VkDeviceSize vab_max_size; ///<顶点缓冲区分配空间大小(顶点数)
|
||||
VkDeviceSize vab_cur_size; ///<顶点缓冲区当前使用大小
|
||||
VAB ** vab; ///<顶点缓冲区列表
|
||||
|
||||
VkDeviceSize ibo_cur_size; ///<索引缓冲区当前使用大小
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
protected:
|
||||
|
||||
DataChain vbo_data_chain; ///<数据链
|
||||
DataChain ibo_data_chain; ///<数据链
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager(GPUDevice *dev,const VIL *_vil);
|
||||
~VertexDataManager();
|
||||
|
||||
GPUDevice * GetDevice ()const{return device;} ///<取得GPU设备
|
||||
|
||||
const VIL * GetVIL ()const{return vil;} ///<取得顶点输入格式列表
|
||||
|
||||
const VkDeviceSize GetVABMaxCount ()const{return vab_max_size;} ///<取得顶点属性缓冲区分配的空间最大数量
|
||||
const VkDeviceSize GetVABCurCount ()const{return vab_cur_size;} ///<取得顶点属性缓冲区当前数量
|
||||
|
||||
const IndexType GetIndexType ()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引缓冲区类型
|
||||
const VkDeviceSize GetIndexMaxCount ()const{return ibo?ibo->GetCount():-1;} ///<取得索引缓冲区分配的空间最大数量
|
||||
const VkDeviceSize GetIndexCurCount ()const{return ibo?ibo_cur_size:-1;} ///<取得索引缓冲区当前数量
|
||||
|
||||
public:
|
||||
|
||||
bool Init(const VkDeviceSize vbo_size,const VkDeviceSize ibo_size,const IndexType index_type);
|
||||
|
||||
DataChain::UserNode *AcquireIB(const VkDeviceSize count);
|
||||
DataChain::UserNode *AcquireVAB(const VkDeviceSize count);
|
||||
|
||||
bool ReleaseIB(DataChain::UserNode *);
|
||||
bool ReleaseVAB(DataChain::UserNode *);
|
||||
|
||||
IndexBuffer *GetIBO(){return ibo;}
|
||||
VAB *GetVAB(const uint index){return vab[index];}
|
||||
};//class VertexDataManager
|
||||
|
||||
using VDM=VertexDataManager;
|
||||
VK_NAMESPACE_END
|
@@ -16,8 +16,8 @@ namespace hgl
|
||||
|
||||
uint max_count; ///<缓冲区最大容量
|
||||
|
||||
VBO * vbo_position;
|
||||
VBO * vbo_tex_coord;
|
||||
VAB * vab_position;
|
||||
VAB * vab_tex_coord;
|
||||
|
||||
protected:
|
||||
|
||||
|
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/MaterialConfig.h>
|
||||
#include<hgl/graph/CoordinateSystem.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
{
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
VAT position_format; ///<position格式
|
||||
|
||||
public:
|
||||
|
||||
Material3DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name,p)
|
||||
{
|
||||
rt_output.color=1; //输出一个颜色
|
||||
rt_output.depth=true; //不输出深度
|
||||
rt_output.stencil=false; //不输出stencil
|
||||
|
||||
local_to_world=false;
|
||||
|
||||
position_format=VAT_VEC3;
|
||||
}
|
||||
};//struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
//MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);
|
||||
//MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
||||
//MaterialCreateInfo *CreatePureTexture2D(const Material2DCreateConfig *);
|
||||
//MaterialCreateInfo *CreateRectTexture2D(Material2DCreateConfig *);
|
||||
//MaterialCreateInfo *CreateRectTexture2DArray(Material2DCreateConfig *);
|
||||
STD_MTL_NAMESPACE_END
|
26
inc/hgl/graph/mtl/BlinnPhong.h
Normal file
26
inc/hgl/graph/mtl/BlinnPhong.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
#include<hgl/math/Vector.h>
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
namespace blinnphong
|
||||
{
|
||||
struct SunLight
|
||||
{
|
||||
Vector4f direction;
|
||||
Vector4f color;
|
||||
};//struct SunLight
|
||||
|
||||
constexpr const ShaderBufferSource SBS_SunLight=
|
||||
{
|
||||
"SunLight",
|
||||
"sun",
|
||||
|
||||
R"(
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
)"
|
||||
};
|
||||
}//namespace blinnphong
|
||||
STD_MTL_NAMESPACE_END
|
@@ -31,6 +31,25 @@ public:
|
||||
else
|
||||
position_format=VAT_VEC2;
|
||||
}
|
||||
|
||||
int Comp(const Material2DCreateConfig &cfg)const
|
||||
{
|
||||
int off=MaterialCreateConfig::Comp(cfg);
|
||||
|
||||
if(off)return off;
|
||||
|
||||
off=(int)coordinate_system-(int)cfg.coordinate_system;
|
||||
if(off)return off;
|
||||
|
||||
off=local_to_world-cfg.local_to_world;
|
||||
if(off)return off;
|
||||
|
||||
off=position_format.Comp(cfg.position_format);
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
CompOperator(const Material2DCreateConfig &,Comp)
|
||||
};//struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);
|
||||
@@ -38,5 +57,18 @@ MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
||||
MaterialCreateInfo *CreatePureTexture2D(const Material2DCreateConfig *);
|
||||
MaterialCreateInfo *CreateRectTexture2D(Material2DCreateConfig *);
|
||||
MaterialCreateInfo *CreateRectTexture2DArray(Material2DCreateConfig *);
|
||||
|
||||
// 为什么有了LoadMaterialFromFile,还需要保留以上Create系列函数?
|
||||
|
||||
// 1.LoadMaterialFromFile载的材质,是从文件中加载的。但我们要考虑文件损坏不能加载的情况。
|
||||
// 2.从文件加载材质过于复杂,而且不利于调试。所以我们需要保留Create系列函数,以便于调试以及测试一些新的情况。同时让开发人员知道材质具体是如何创建的。
|
||||
|
||||
/**
|
||||
* 从文件加载材质
|
||||
* @param mtl_name 材质名称
|
||||
* @param cfg 材质创建参数
|
||||
* @return 材质创建信息
|
||||
*/
|
||||
MaterialCreateInfo *LoadMaterialFromFile(const AnsiString &mtl_name,Material2DCreateConfig *cfg); ///<从文件加载材质
|
||||
STD_MTL_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
64
inc/hgl/graph/mtl/Material3DCreateConfig.h
Normal file
64
inc/hgl/graph/mtl/Material3DCreateConfig.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/MaterialConfig.h>
|
||||
#include<hgl/graph/CoordinateSystem.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
{
|
||||
bool camera; ///<包含摄像机矩阵信息
|
||||
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
VAT position_format; ///<position格式
|
||||
|
||||
// bool reverse_depth; ///<使用反向深度
|
||||
|
||||
public:
|
||||
|
||||
Material3DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name,p)
|
||||
{
|
||||
rt_output.color=1; //输出一个颜色
|
||||
rt_output.depth=true; //不输出深度
|
||||
rt_output.stencil=false; //不输出stencil
|
||||
|
||||
camera=true;
|
||||
local_to_world=false;
|
||||
|
||||
position_format=VAT_VEC3;
|
||||
|
||||
// reverse_depth=false;
|
||||
}
|
||||
|
||||
int Comp(const Material3DCreateConfig &cfg)const
|
||||
{
|
||||
int off=MaterialCreateConfig::Comp(cfg);
|
||||
|
||||
if(off)return off;
|
||||
|
||||
off=camera-cfg.camera;
|
||||
if(off)return off;
|
||||
|
||||
off=local_to_world-cfg.local_to_world;
|
||||
if(off)return off;
|
||||
|
||||
off=position_format.Comp(cfg.position_format);
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
CompOperator(const Material3DCreateConfig &,Comp)
|
||||
};//struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);
|
||||
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *);
|
||||
|
||||
/**
|
||||
* 从文件加载材质
|
||||
* @param mtl_name 材质名称
|
||||
* @param cfg 材质创建参数
|
||||
* @return 材质创建信息
|
||||
*/
|
||||
MaterialCreateInfo *LoadMaterialFromFile(const AnsiString &name,Material3DCreateConfig *cfg);
|
||||
STD_MTL_NAMESPACE_END
|
@@ -5,6 +5,7 @@
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/RenderTargetOutputConfig.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/mtl/SamplerName.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
class MaterialCreateInfo;
|
||||
@@ -18,6 +19,8 @@ struct MaterialCreateConfig
|
||||
|
||||
AnsiString mtl_name; ///<材质名称
|
||||
|
||||
bool material_instance; ///<是否包含材质实例
|
||||
|
||||
RenderTargetOutputConfig rt_output; ///<渲染目标输出配置
|
||||
|
||||
uint32 shader_stage_flag_bit; ///<需要的shader
|
||||
@@ -32,10 +35,32 @@ public:
|
||||
|
||||
mtl_name=name;
|
||||
|
||||
material_instance=false;
|
||||
|
||||
shader_stage_flag_bit=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
prim=p;
|
||||
}
|
||||
|
||||
virtual int Comp(const MaterialCreateConfig &cfg)const
|
||||
{
|
||||
int off;
|
||||
|
||||
off=material_instance-cfg.material_instance;
|
||||
if(off)return(off);
|
||||
|
||||
off=hgl_cmp(rt_output,cfg.rt_output);
|
||||
if(off)return(off);
|
||||
|
||||
off=(int)prim-(int)cfg.prim;
|
||||
if(off)return(off);
|
||||
|
||||
off=shader_stage_flag_bit-cfg.shader_stage_flag_bit;
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
CompOperator(const MaterialCreateConfig &,Comp)
|
||||
};//struct MaterialCreateConfig
|
||||
STD_MTL_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_MTL_CONFIG_INCLUDE
|
||||
|
@@ -8,7 +8,7 @@ namespace hgl
|
||||
{
|
||||
namespace SamplerName
|
||||
{
|
||||
constexpr const char Color[] = "TextureColor";
|
||||
constexpr const char BaseColor[] = "TextureBaseColor";
|
||||
}//namespace SamplerName
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
|
@@ -1,16 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
|
||||
#define STD_MTL_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{
|
||||
#define STD_MTL_NAMESPACE_END }}}
|
||||
|
||||
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
|
||||
#define STD_MTL_NAMESPACE hgl::graph::mtl
|
||||
#define STD_MTL_NAMESPACE_USING using namespace STD_MTL_NAMESPACE;
|
||||
|
||||
#define STD_MTL_FUNC_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{namespace func{
|
||||
#define STD_MTL_FUNC_NAMESPACE_END }}}}
|
||||
|
||||
#define STD_MTL_FUNC_NAMESPACE hgl::graph::mtl::func
|
||||
#define STD_MTL_FUNC_NAMESPACE_USING using namespace STD_MTL_FUNC_NAMESPACE;
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class ShaderCreateInfoVertex;
|
||||
class ShaderCreateInfoGeometry;
|
||||
class ShaderCreateInfoFragment;
|
||||
|
||||
namespace mtl
|
||||
{
|
||||
namespace func
|
||||
{
|
||||
}//namespace func
|
||||
|
||||
class MaterialCreateInfo;
|
||||
struct MaterialCreateConfig;
|
||||
|
||||
class StdMaterial
|
||||
{
|
||||
protected:
|
||||
|
||||
MaterialCreateInfo *mci;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool BeginCustomShader(){return true;/*some work before create shader*/};
|
||||
|
||||
virtual bool CustomVertexShader(ShaderCreateInfoVertex *)=0;
|
||||
virtual bool CustomGeometryShader(ShaderCreateInfoGeometry *){return false;}
|
||||
virtual bool CustomFragmentShader(ShaderCreateInfoFragment *)=0;
|
||||
|
||||
virtual bool EndCustomShader(){return true;/*some work after create shader*/};
|
||||
|
||||
public:
|
||||
|
||||
StdMaterial(const MaterialCreateConfig *);
|
||||
virtual ~StdMaterial()=default;
|
||||
|
||||
virtual MaterialCreateInfo *Create();
|
||||
};//class StdMaterial
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -42,8 +42,8 @@ constexpr const ShaderBufferSource SBS_CameraInfo=
|
||||
float znear,zfar;)"
|
||||
};
|
||||
|
||||
// UBO必须严格指定数组的大小
|
||||
// SSBO则不需要,使用[]方式指定为动态大小数组
|
||||
constexpr const char LocalToWorldStruct[]="LocalToWorld";
|
||||
constexpr const DescriptorSetType DST_LocalToWorld=DescriptorSetType::PerFrame;
|
||||
|
||||
constexpr const ShaderBufferSource SBS_LocalToWorld=
|
||||
{
|
||||
@@ -51,10 +51,15 @@ constexpr const ShaderBufferSource SBS_LocalToWorld=
|
||||
"l2w",
|
||||
|
||||
R"(
|
||||
mat4 mats[L2W_MAX_COUNT];)"
|
||||
mat4 mats[L2W_MAX_COUNT];
|
||||
)"
|
||||
};
|
||||
|
||||
// UBO必须严格指定数组的大小
|
||||
// SSBO则不需要,使用[]方式指定为动态大小数组
|
||||
|
||||
constexpr const char MaterialInstanceStruct[]="MaterialInstance";
|
||||
constexpr const DescriptorSetType DST_MaterialInstance=DescriptorSetType::PerMaterial;
|
||||
|
||||
constexpr const ShaderBufferSource SBS_MaterialInstance=
|
||||
{
|
||||
|
24
inc/hgl/graph/mtl/UniformBuffer.h
Normal file
24
inc/hgl/graph/mtl/UniformBuffer.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 所有UBO的基类,它即向生成器提供代码,也可以为渲染器提供数据
|
||||
*/
|
||||
class UniformBuffer
|
||||
{
|
||||
private:
|
||||
|
||||
ShaderBufferSource *sbs;
|
||||
|
||||
public:
|
||||
|
||||
virtual const AnsiString &GetStructName ()const{return sbs->struct_name;} ///<取得结构名称
|
||||
virtual const AnsiString &GetDefaultValueName ()const{return sbs->name;} ///<取得默认变量名称
|
||||
virtual const AnsiString &GetShaderCodes ()const{return sbs->codes;} ///<取得Shader代码
|
||||
};//class UniformBuffer
|
||||
|
||||
STD_MTL_NAMESPACE_END
|
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/MaterialDescriptorInfo.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfoVertex.h>
|
||||
@@ -33,8 +33,8 @@ namespace hgl{namespace graph
|
||||
uint32_t mi_max_count;
|
||||
UBODescriptor *mi_ubo;
|
||||
|
||||
uint32_t l2w_shader_stage;
|
||||
uint32_t l2w_max_count;
|
||||
uint32_t l2w_shader_stage;
|
||||
UBODescriptor *l2w_ubo;
|
||||
|
||||
ShaderCreateInfoMap shader_map; ///<着色器列表
|
||||
@@ -83,10 +83,11 @@ namespace hgl{namespace graph
|
||||
bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes);
|
||||
bool AddStruct(const ShaderBufferSource &ss){return AddStruct(ss.struct_name,ss.codes);}
|
||||
|
||||
bool AddUBO(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const AnsiString &type_name,const AnsiString &name);
|
||||
bool AddSampler(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const SamplerType &st,const AnsiString &name);
|
||||
bool AddUBO(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const AnsiString &struct_name,const AnsiString &name);
|
||||
bool AddUBO(const uint32_t flag_bits,const DescriptorSetType &set_type,const AnsiString &struct_name,const AnsiString &name);
|
||||
bool AddUBO(const uint32_t flag_bits,const DescriptorSetType &set_type,const ShaderBufferSource &ss){return AddUBO(flag_bits,set_type,ss.struct_name,ss.name);}
|
||||
|
||||
bool AddUBO(const uint32_t flag_bits,const DescriptorSetType &set_type,const ShaderBufferSource &ss);
|
||||
bool AddSampler(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const SamplerType &st,const AnsiString &name);
|
||||
|
||||
bool CreateShader();
|
||||
};//class MaterialCreateInfo
|
||||
|
@@ -34,7 +34,7 @@ protected:
|
||||
|
||||
AnsiString mi_codes;
|
||||
|
||||
AnsiStringList function_list;
|
||||
List<const char *> function_list;
|
||||
AnsiString main_function;
|
||||
|
||||
AnsiString final_shader;
|
||||
@@ -79,12 +79,16 @@ public:
|
||||
int AddOutput(const graph::VAT &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
int AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
|
||||
void AddFunction(const AnsiString &str){function_list.Add(str);}
|
||||
void AddFunction(const char *str){function_list.Add(str);}
|
||||
|
||||
void SetMaterialInstance(UBODescriptor *,const AnsiString &);
|
||||
void SetLocalToWorld(UBODescriptor *);
|
||||
void AddMaterialInstanceOutput();
|
||||
|
||||
void SetMain(const AnsiString &str){main_function=str;}
|
||||
void SetMain(const char *str,const int len)
|
||||
{
|
||||
main_function.SetString(str,len);
|
||||
}
|
||||
|
||||
const AnsiString &GetOutputStruct()const{return output_struct;}
|
||||
const AnsiString &GetShaderSource()const{return final_shader;}
|
||||
|
@@ -3,10 +3,6 @@
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
enum class MaterialType
|
||||
{
|
||||
Color, ///<<3C><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
class ShaderCreateInfoFragment:public ShaderCreateInfo
|
||||
{
|
||||
@@ -16,7 +12,5 @@ public:
|
||||
|
||||
ShaderCreateInfoFragment(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_FRAGMENT_BIT,m){}
|
||||
~ShaderCreateInfoFragment()=default;
|
||||
|
||||
void UseDefaultMain();
|
||||
};
|
||||
}}//namespace hgl::graph
|
@@ -13,14 +13,17 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoVertex(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_VERTEX_BIT,m){}
|
||||
ShaderCreateInfoVertex(MaterialDescriptorInfo *);
|
||||
~ShaderCreateInfoVertex()=default;
|
||||
|
||||
int AddInput(const graph::VAT &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
int AddInput(const AnsiString &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
|
||||
void AddJoint();
|
||||
int hasInput(const char *);
|
||||
|
||||
void AddAssign();
|
||||
|
||||
void AddJoint();
|
||||
};//class ShaderCreateInfoVertex:public ShaderCreateInfo
|
||||
}//namespace graph
|
||||
}//namespace hgl::graph
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
bool AddInput(ShaderAttribute *);
|
||||
bool AddOutput(ShaderAttribute *);
|
||||
|
||||
bool hasInput(const char *)const; ///<是否有指定输入
|
||||
|
||||
void AddStruct(const AnsiString &);
|
||||
bool AddUBO(DescriptorSetType type,const UBODescriptor *sd);
|
||||
bool AddSampler(DescriptorSetType type,const SamplerDescriptor *sd);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user