Compare commits
152 Commits
master
...
devel_27_D
Author | SHA1 | Date | |
---|---|---|---|
89b9735f99 | |||
7f744d1207 | |||
b9f5c69f85 | |||
c469fde84a | |||
dd6b2f4fb3 | |||
ba8b44659b | |||
13b2ca0575 | |||
9d704eb33d | |||
86c3b65a42 | |||
f6e61e70ce | |||
5347ac7091 | |||
f56928d734 | |||
f3a59c1bb3 | |||
5188d4149c | |||
d4096735f5 | |||
4fafd938b1 | |||
f0848541c2 | |||
cc9e756ece | |||
cdedc81f9f | |||
c229259623 | |||
2c2f11f47e | |||
c8b3ed0286 | |||
2ce36ec26c | |||
5ba3c1790d | |||
3874d771d3 | |||
49eb8f42f0 | |||
c355f96f9b | |||
dc3d7b7792 | |||
5f1c60a24a | |||
ff6a644e8f | |||
b9e70426a1 | |||
a7af276a44 | |||
8b82c6c25c | |||
a8d68c295d | |||
f666d5b248 | |||
55c27a883b | |||
6a7f8e7754 | |||
1dbf8ae5c7 | |||
8dbc1d899c | |||
d010ee4278 | |||
4aeb28c571 | |||
775e031422 | |||
deefdf1416 | |||
ba2d479f05 | |||
b16341c0f9 | |||
d5eeb081e1 | |||
4bb66d2746 | |||
625a7387ae | |||
c4deceebd9 | |||
4ed0e281b2 | |||
9369ad115b | |||
7788459109 | |||
a58589f01f | |||
240b6fb0e3 | |||
b72a924853 | |||
b781ff41a3 | |||
4ee6962d04 | |||
7eff39b3b0 | |||
6b13c159d8 | |||
2f560a28a7 | |||
8ba171efda | |||
317635877b | |||
255c7859f1 | |||
ae85d3fc66 | |||
a5830e18cb | |||
ae88a65315 | |||
77b0266cdc | |||
c99934fdf9 | |||
aa6071a948 | |||
6f58475abd | |||
cfed14d746 | |||
27c409c7fd | |||
bee48890cb | |||
a2669d2123 | |||
737438aaed | |||
8a5711154f | |||
3dd308aff1 | |||
bead8128b7 | |||
019e9964fa | |||
7ca81f38e8 | |||
03750832c8 | |||
018a72c09a | |||
55fee1e5d7 | |||
c5dd359d18 | |||
85ec666989 | |||
9a5cead33e | |||
695f1a22a8 | |||
237c1a469b | |||
5ede824522 | |||
46781b9627 | |||
aaff0c23c9 | |||
3a3f9d10b7 | |||
b6e391762b | |||
b262fdc645 | |||
5e795c4a7f | |||
0524c51feb | |||
8dc9846ae8 | |||
1d866abb48 | |||
ece7912f3c | |||
4ef37a430e | |||
1f91ec94e1 | |||
86123827cb | |||
19df201ab5 | |||
921d6d157f | |||
c0e4128365 | |||
8fe5e8dd55 | |||
3393a90127 | |||
9b5157594f | |||
10d4f2f04a | |||
a1e7b105f7 | |||
67cf89fef1 | |||
e95cbb28a4 | |||
c9d6774bd3 | |||
78946994bb | |||
1a63fa8c76 | |||
db766f33ac | |||
3db94948c5 | |||
cefea7229d | |||
45f50b3bc0 | |||
dbea7764fb | |||
1101bcae9d | |||
6c7f9ea9d1 | |||
253d113375 | |||
ca1bb80b5f | |||
922fc2661b | |||
e9a8e5bbf2 | |||
bba00534ba | |||
c15fbf8252 | |||
9a7e711658 | |||
65c3d5cad1 | |||
7d9192051a | |||
22099b6b84 | |||
322d24c4ca | |||
5230fbc27f | |||
f901708b6c | |||
2487cb1f36 | |||
7805494ca9 | |||
ac4c97d33a | |||
a87a35b5f8 | |||
d456c2bf92 | |||
12e18b517b | |||
2f00aa8e1e | |||
4e144072e4 | |||
907cb3c852 | |||
eb51df8dd0 | |||
ed9ba3876f | |||
97290ce54c | |||
bebac2284f | |||
d5d6a6bc74 | |||
5559178e7c | |||
f58ce4f98b | |||
5c2f136689 |
2
CMCore
2
CMCore
Submodule CMCore updated: 072153aa91...2f93a1bb00
Submodule CMPlatform updated: 5e8b83cce4...c9a1298e02
Submodule CMSceneGraph updated: bde86e8016...0c9bdb9fcd
2
CMUtil
2
CMUtil
Submodule CMUtil updated: c0990c52eb...953ecf8079
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 TextureColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureColor,Input.TexCoord);
|
||||
}
|
||||
}
|
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
@@ -0,0 +1,68 @@
|
||||
#Material
|
||||
Name RectTexture2D
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureColor,Input.TexCoord);
|
||||
}
|
||||
}
|
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
@@ -0,0 +1,79 @@
|
||||
#Material
|
||||
Name RectTexture2DArray
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
uvec4 id;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
HandoverMI();gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2DArray TextureColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=texture(TextureColor,vec3(Input.TexCoord,mi.id.x));
|
||||
}
|
||||
}
|
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
@@ -0,0 +1,37 @@
|
||||
#Material
|
||||
Name VertexColor2D
|
||||
Base Std2D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
@@ -0,0 +1,2 @@
|
||||
vec4 direction;
|
||||
vec4 color;
|
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
@@ -0,0 +1,92 @@
|
||||
#Material
|
||||
Name BlinnPhong+HalfLambert shading model only color
|
||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||
Base Std3D/BlinnPhong
|
||||
|
||||
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||
Require LocalToWorld
|
||||
Require Camera
|
||||
|
||||
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec3 Color;
|
||||
float Gloss;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Position;
|
||||
vec3 Normal;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Normal =GetNormal();
|
||||
Output.Position =GetPosition3D();
|
||||
|
||||
HandoverMI();
|
||||
|
||||
gl_Position =Output.Position;
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
#define HAVE_SPECULAR
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
//点乘法线和光照
|
||||
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
FragColor=vec4(direct_color,1.0);
|
||||
#else
|
||||
|
||||
vec3 spec_color=vec3(0.0);
|
||||
|
||||
if(intensity>0.0)
|
||||
{
|
||||
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
|
||||
|
||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||
|
||||
spec_color=specular*pow(specular,mi.Gloss)*sun.color.rgb;
|
||||
}
|
||||
|
||||
FragColor=vec4(direct_color+spec_color,1.0);
|
||||
#endif//HAVE_SPECULAR
|
||||
}
|
||||
}
|
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
@@ -0,0 +1,87 @@
|
||||
#Material
|
||||
Name MetricCellsGrid
|
||||
Base Std3D
|
||||
Reference https://www.shadertoy.com/view/wdSXzm
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#MaterialInstance
|
||||
Length 120
|
||||
Stage Fragment
|
||||
|
||||
Code
|
||||
{
|
||||
vec4 x_color;
|
||||
vec4 y_color;
|
||||
vec4 x_axis_color;
|
||||
vec4 y_axis_color;
|
||||
vec4 center_color;
|
||||
|
||||
vec2 lum; //x=0.1 sub cell line,y=0.2 big cell line
|
||||
vec2 cell_step;
|
||||
vec2 big_cell_step;
|
||||
vec2 scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
float edge=viewport.inv_viewport_resolution.y;
|
||||
|
||||
float x=(Input.TexCoord.x-0.5)*mi.scale.x;
|
||||
float y=(Input.TexCoord.y-0.5)*mi.scale.y;
|
||||
|
||||
vec4 color=vec4(0,0,0,1);
|
||||
|
||||
// ======= Lines + Bold lines
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.x, fract(x / mi.cell_step.x )) * mi.x_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.x, fract(x / mi.big_cell_step.x)) * mi.x_color.rgb * mi.lum.y;
|
||||
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.y, fract(y / mi.cell_step.y )) * mi.y_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.y, fract(y / mi.big_cell_step.y)) * mi.y_color.rgb * mi.lum.y;
|
||||
|
||||
// ======= AXES
|
||||
float xb = step(abs(x) - mi.axis_line_width, 0.0);
|
||||
float yb = step(abs(y) - mi.axis_line_width, 0.0);
|
||||
|
||||
color.rgb = mix(color.rgb, mi.x_axis_color.rgb, (xb));
|
||||
color.rgb = mix(color.rgb, mi.y_axis_color.rgb, (yb));
|
||||
|
||||
// ======= CENTER
|
||||
float cb = length(vec2(x,y))-mi.center_radius;
|
||||
color.rgb = mix(color.rgb, mi.center_color.rgb, cb>0.0?0.0:smoothstep(0,edge*mi.scale.y,abs(cb)));
|
||||
|
||||
FragColor=color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name PureColor3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=mi.Color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name VertexColor3D
|
||||
Base Std3D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
@@ -0,0 +1,47 @@
|
||||
#Material
|
||||
Name VertexLum3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Vertex
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
float Luminance
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.Color=Luminance*mi.Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
BIN
doc/BlenderGizmo/Move.png
Normal file
BIN
doc/BlenderGizmo/Move.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 141 KiB |
BIN
doc/BlenderGizmo/Rotate.png
Normal file
BIN
doc/BlenderGizmo/Rotate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 KiB |
BIN
doc/BlenderGizmo/Scale.png
Normal file
BIN
doc/BlenderGizmo/Scale.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 180 KiB |
BIN
doc/Gizmo.odg
Normal file
BIN
doc/Gizmo.odg
Normal file
Binary file not shown.
@@ -143,7 +143,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
@@ -165,7 +165,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
16
example/Basic/CMakeLists.txt
Normal file
16
example/Basic/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
|
||||
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
|
||||
CreateProject(03_auto_instance auto_instance.cpp)
|
||||
CreateProject(04_auto_merge_material_instance auto_merge_material_instance.cpp)
|
@@ -1,12 +1,11 @@
|
||||
// AutoInstance
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -47,7 +46,7 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
@@ -72,7 +71,7 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
@@ -117,7 +116,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
@@ -1,11 +1,10 @@
|
||||
// AutoMergeMaterialInstance
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
|
||||
#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>
|
||||
|
||||
@@ -26,6 +25,8 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
|
||||
constexpr uint DRAW_OBJECT_COUNT=12;
|
||||
|
||||
#define USE_MATERIAL_FILE true //是否使用材质文件
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
@@ -48,14 +49,17 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D");
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
|
||||
|
||||
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);
|
||||
@@ -69,7 +73,7 @@ private:
|
||||
|
||||
Color4f color=GetColor4f((COLOR)(i+int(COLOR::Blue)),1.0);
|
||||
|
||||
render_obj[i].mi->WriteMIData(color,sizeof(Color4f)); //设置MaterialInstance的数据
|
||||
render_obj[i].mi->WriteMIData(color); //设置MaterialInstance的数据
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,9 +82,9 @@ private:
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
|
||||
@@ -118,7 +122,7 @@ public:
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
@@ -126,7 +130,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
// first_triangle
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
@@ -8,7 +7,7 @@
|
||||
#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/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -87,7 +86,7 @@ private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d");
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
@@ -109,7 +108,7 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
@@ -146,7 +145,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
@@ -1,33 +1,32 @@
|
||||
// second_triangle
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.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的坐标系
|
||||
@@ -45,25 +44,33 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
#else
|
||||
cfg.coordinate_system=CoordinateSystem2D::Ortho;
|
||||
|
||||
cfg.position_format =VAT_UVEC2; //这里指定shader中使用uvec2当做顶点输入格式
|
||||
// ^
|
||||
// + 这上下两种格式要配套,否则会出错
|
||||
// v
|
||||
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VBO中使用RG16U当做顶点数据格式
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VBO中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
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
|
||||
|
||||
@@ -72,20 +79,15 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
|
||||
#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;
|
||||
}
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data_float ))return(false);
|
||||
#else //使用ortho坐标系
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4F, color_data ))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(true);
|
||||
@@ -93,11 +95,19 @@ private:
|
||||
|
||||
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);
|
||||
|
||||
@@ -110,7 +120,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
@@ -120,12 +130,5 @@ public:
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
RunApp<TestApp>(1280,720);
|
||||
}
|
@@ -2,6 +2,11 @@
|
||||
|
||||
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
|
||||
|
||||
add_subdirectory(Basic)
|
||||
add_subdirectory(Texture)
|
||||
add_subdirectory(LightBasic)
|
||||
add_subdirectory(Gizmo)
|
||||
|
||||
add_subdirectory(Vulkan)
|
||||
add_subdirectory(2dVector)
|
||||
add_subdirectory(GUI)
|
||||
@@ -17,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
|
19
example/Gizmo/CMakeLists.txt
Normal file
19
example/Gizmo/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(02_RayPicking RayPicking.cpp)
|
||||
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
||||
|
||||
CreateProject(04_Gizmo3DMove Gizmo3DMove.cpp Gizmo.h Gizmo.cpp)
|
||||
|
||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
0
example/Gizmo/Gizmo.cpp
Normal file
0
example/Gizmo/Gizmo.cpp
Normal file
16
example/Gizmo/Gizmo.h
Normal file
16
example/Gizmo/Gizmo.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class Gizmo
|
||||
{
|
||||
Material * material;
|
||||
MaterialInstance * mi;
|
||||
Pipeline * pipeline;
|
||||
Primitive * primitive;
|
||||
|
||||
};//class Gizmo
|
||||
|
||||
VK_NAMESPACE_END
|
228
example/Gizmo/Gizmo3DMove.cpp
Normal file
228
example/Gizmo/Gizmo3DMove.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
// Gizmo 3D Move
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_vtx_lum =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_vtx_lum =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Material * mtl_vtx_color =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
Pipeline * pipeline_vtx_color =nullptr;
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_vtx_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_vtx_lum)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_vtx_lum,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_vtx_lum=CreatePipeline(mtl_vtx_lum,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline_vtx_lum)
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_vtx_color=db->LoadMaterial("Std3D/VertexColor3D",&cfg);
|
||||
if(!mtl_vtx_color)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(mtl_vtx_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
{
|
||||
const PipelineData *ipd=GetPipelineData(InlinePipeline::Solid3D);
|
||||
|
||||
if(!ipd)
|
||||
return(false);
|
||||
|
||||
PipelineData *pd=new PipelineData(ipd);
|
||||
|
||||
pd->SetLineWidth(2);
|
||||
|
||||
pipeline_vtx_color=CreatePipeline(mtl_vtx_color,pd,Prim::Lines);
|
||||
|
||||
delete pd;
|
||||
|
||||
if(!pipeline_vtx_color)
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
/**
|
||||
* д<><D0B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* \param pos Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
|
||||
* \param max_line <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* \param oa1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
|
||||
* \param oa2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void WriteAxisPosition(Vector3f *pos,const Vector3f &max_line,const Vector3f &oa1,const Vector3f &oa2)
|
||||
{
|
||||
constexpr const float AXIS_LENGTH =4;
|
||||
constexpr const float AXIS_MIN_STEP =1;
|
||||
constexpr const float AXIS_ARROW_SIZE=0.25;
|
||||
|
||||
const Vector3f end_pos =max_line*AXIS_LENGTH; ///<<3C><><EFBFBD>յ<EFBFBD>λ<EFBFBD><CEBB>
|
||||
const Vector3f cross_pos=max_line*AXIS_MIN_STEP; ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
const Vector3f arrow_pos=max_line*(AXIS_LENGTH-AXIS_MIN_STEP); ///<<3C><>ͷĩ<CDB7><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>λ<EFBFBD><CEBB>
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
pos[0]=Vector3f(0, 0, 0);
|
||||
pos[1]=end_pos;
|
||||
|
||||
//<2F>ĸ<EFBFBD><C4B8><EFBFBD>ͷ<EFBFBD><CDB7>
|
||||
pos[2]=end_pos;
|
||||
pos[3]=arrow_pos-oa1*AXIS_ARROW_SIZE;
|
||||
|
||||
pos[4]=end_pos;
|
||||
pos[5]=arrow_pos+oa1*AXIS_ARROW_SIZE;
|
||||
|
||||
pos[6]=end_pos;
|
||||
pos[7]=arrow_pos-oa2*AXIS_ARROW_SIZE;
|
||||
|
||||
pos[8]=end_pos;
|
||||
pos[9]=arrow_pos+oa2*AXIS_ARROW_SIZE;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
pos[10]=cross_pos;
|
||||
pos[11]=cross_pos+oa1*AXIS_MIN_STEP;
|
||||
pos[12]=cross_pos;
|
||||
pos[13]=cross_pos+oa2*AXIS_MIN_STEP;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(db,mtl_vtx_lum->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
constexpr const uint AXIS_MAX_LINES =7;
|
||||
constexpr const uint AXIS_MAX_VERTICES =AXIS_MAX_LINES*2*3;
|
||||
|
||||
ro_line=db->CreatePrimitive("Line",AXIS_MAX_VERTICES);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
Vector3f position_data[3][AXIS_MAX_LINES*2];
|
||||
|
||||
WriteAxisPosition(position_data[0],Vector3f(1,0,0),Vector3f(0,1,0),Vector3f(0,0,1));
|
||||
WriteAxisPosition(position_data[1],Vector3f(0,1,0),Vector3f(1,0,0),Vector3f(0,0,1));
|
||||
WriteAxisPosition(position_data[2],Vector3f(0,0,1),Vector3f(1,0,0),Vector3f(0,1,0));
|
||||
|
||||
Color4f color_data[3][AXIS_MAX_LINES*2];
|
||||
|
||||
for(Color4f &c:color_data[0])c=Color4f(1,0,0,1);
|
||||
for(Color4f &c:color_data[1])c=Color4f(0,1,0,1);
|
||||
for(Color4f &c:color_data[2])c=Color4f(0,0,1,1);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, db->CreateVBO(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_vtx_lum);
|
||||
Add(ro_line,mi_line,pipeline_vtx_color);
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
142
example/Gizmo/MetricCellsGrid.cpp
Normal file
142
example/Gizmo/MetricCellsGrid.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
// Metric Cells Grid
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
struct MetricCellsGridData
|
||||
{
|
||||
Color4f x_color;
|
||||
Color4f y_color;
|
||||
Color4f x_axis_color;
|
||||
Color4f y_axis_color;
|
||||
Color4f center_color;
|
||||
|
||||
Vector2f lum;
|
||||
Vector2f cell_step;
|
||||
Vector2f big_cell_step;
|
||||
Vector2f scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
};
|
||||
|
||||
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
|
||||
|
||||
constexpr const float PLANE_SIZE=1024;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MetricCellsGridData mcg_data;
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"MetricCellsGrid",Prim::Fan);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/MetricCellsGrid",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
{
|
||||
mcg_data.x_color=Color4f(1,1,1,1);
|
||||
mcg_data.y_color=Color4f(1,1,1,1);
|
||||
|
||||
mcg_data.x_axis_color=GetColor4f(COLOR::BlenderAxisRed, 1.0);
|
||||
mcg_data.y_axis_color=GetColor4f(COLOR::BlenderAxisGreen, 1.0);
|
||||
|
||||
mcg_data.center_color=Color4f(1,1,0,1);
|
||||
|
||||
mcg_data.lum =Vector2f(0.1,0.2);
|
||||
mcg_data.cell_step =Vector2f(8,8);
|
||||
mcg_data.big_cell_step =Vector2f(32,32);
|
||||
mcg_data.scale =Vector2f(PLANE_SIZE,PLANE_SIZE);
|
||||
|
||||
mcg_data.axis_line_width=1.0;
|
||||
mcg_data.center_radius =4.0;
|
||||
}
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material,nullptr,&mcg_data);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Fan);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
ro_plane=inline_geometry::CreatePlane(db,material->GetDefaultVIL());
|
||||
|
||||
return ro_plane;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(ro_plane,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
|
||||
|
||||
camera->pos=Vector3f(PLANE_SIZE/2,PLANE_SIZE/2,PLANE_SIZE/4);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
123
example/Gizmo/PlaneGrid3D.cpp
Normal file
123
example/Gizmo/PlaneGrid3D.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
// PlaneGrid3D
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
MaterialInstance * material_instance[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
Color4f GridColor;
|
||||
COLOR ce=COLOR::BlenderAxisRed;
|
||||
|
||||
for(uint i=0;i<3;i++)
|
||||
{
|
||||
GridColor=GetColor4f(ce,1.0);
|
||||
|
||||
material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor);
|
||||
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.75;
|
||||
pgci.sub_lum=1.0;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
|
||||
|
||||
return prim_plane_grid;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(prim_plane_grid,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance[0],Matrix4f(1.0f));
|
||||
Add(material_instance[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(material_instance[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
168
example/Gizmo/RayPicking.cpp
Normal file
168
example/Gizmo/RayPicking.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
// RayPicking
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float position_data[2][3]=
|
||||
{
|
||||
{100,100,100},
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
VBO * vbo_pos =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(material,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(material,nullptr,&yellow_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
ro_line=db->CreatePrimitive("Line",2);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, vbo_pos= db->CreateVBO(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Luminance, db->CreateVBO(VF_V1F,2,lumiance_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid);
|
||||
Add(ro_line,mi_line);
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
const CameraInfo &ci=GetCameraInfo();
|
||||
const ViewportInfo &vi=GetViewportInfo();
|
||||
|
||||
ray.Set(GetMouseCoord(),&ci,&vi); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
217
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
217
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
// BlinnPhong direction light
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/BlinnPhong.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
|
||||
static mtl::blinnphong::SunLight sun_light=
|
||||
{
|
||||
Vector4f(1,1,1,0), //direction
|
||||
Vector4f(1,0.95,0.9,1) //color
|
||||
};
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private: //plane grid
|
||||
|
||||
Material * mtl_vertex_lum =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * p_line =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
DeviceBuffer * ubo_sun =nullptr;
|
||||
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_blinnphong =nullptr;
|
||||
MaterialInstance * mi_blinnphong =nullptr;
|
||||
Pipeline * p_blinnphong =nullptr;
|
||||
|
||||
Primitive * prim_sphere =nullptr;
|
||||
Primitive * prim_cone =nullptr;
|
||||
Primitive * prim_cylinder =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitVertexLumMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_vertex_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_vertex_lum)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_vertex_lum,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
p_line=CreatePipeline(mtl_vertex_lum,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!p_line)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateBlinnPhongUBO()
|
||||
{
|
||||
ubo_sun=db->CreateUBO("sun",sizeof(sun_light),&sun_light);
|
||||
if(!ubo_sun)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitBlinnPhongSunLightMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",Prim::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColor",&cfg);
|
||||
if(!mtl_blinnphong)return(false);
|
||||
|
||||
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_blinnphong->Update();
|
||||
|
||||
float mi_data[4]=
|
||||
{
|
||||
1,0,0, //color
|
||||
4 //gloss
|
||||
};
|
||||
|
||||
mi_blinnphong=db->CreateMaterialInstance(mtl_blinnphong,nullptr,&mi_data);
|
||||
if(!mi_blinnphong)return(false);
|
||||
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
//Plane Grid
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(db,mtl_vertex_lum->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
|
||||
//Sphere
|
||||
prim_sphere=CreateSphere(db,mi_blinnphong->GetVIL(),16);
|
||||
|
||||
//Cone
|
||||
{
|
||||
struct ConeCreateInfo cci;
|
||||
|
||||
cci.radius =1; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=8; //圆锥高度分割数
|
||||
|
||||
prim_cone=CreateCone(db,mi_blinnphong->GetVIL(),&cci);
|
||||
}
|
||||
|
||||
//Cyliner
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =4; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =0.25f; //圆柱半径
|
||||
|
||||
prim_cylinder=CreateCylinder(db,mi_blinnphong->GetVIL(),&cci);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
|
||||
|
||||
Add(prim_sphere, mi_blinnphong,p_blinnphong,translate(Vector3f(0,0,2)));
|
||||
Add(prim_cone, mi_blinnphong,p_blinnphong,Identity4f);
|
||||
Add(prim_cylinder, mi_blinnphong,p_blinnphong,translate(Vector3f(0,0,-5)));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitVertexLumMP())
|
||||
return(false);
|
||||
|
||||
if(!CreateBlinnPhongUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitBlinnPhongSunLightMP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
13
example/LightBasic/CMakeLists.txt
Normal file
13
example/LightBasic/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Light Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_BlinnPhongDirectionLight BlinnPhongDirectionLight.cpp)
|
@@ -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;
|
||||
}
|
16
example/Texture/CMakeLists.txt
Normal file
16
example/Texture/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Texture")
|
||||
endmacro()
|
||||
|
||||
CreateProject(05_texture_format texture_format_list.cpp)
|
||||
CreateProject(06_texture_quad texture_quad.cpp)
|
||||
CreateProject(07_texture_rect texture_rect.cpp)
|
||||
CreateProject(08_texture_rect_array texture_rect_array.cpp)
|
@@ -1,10 +1,11 @@
|
||||
// 2.texture_rect
|
||||
// 该示例是1.indices_rect的进化,演示在矩形上贴上贴图
|
||||
// 画一个带纹理的四边形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -21,26 +22,18 @@ constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0, 0},
|
||||
{SCREEN_WIDTH, 0},
|
||||
{0, SCREEN_HEIGHT},
|
||||
{SCREEN_WIDTH, SCREEN_HEIGHT}
|
||||
{-1, -1},
|
||||
{ 1, -1},
|
||||
{ 1, 1},
|
||||
{-1, 1},
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{1,0},
|
||||
{0,1},
|
||||
{1,1}
|
||||
};
|
||||
|
||||
constexpr uint32_t INDEX_COUNT=6;
|
||||
|
||||
constexpr uint16 index_data[INDEX_COUNT]=
|
||||
{
|
||||
0,1,3,
|
||||
0,3,2
|
||||
{1,1},
|
||||
{0,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
@@ -49,22 +42,28 @@ private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * renderable =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/Texture2D"));
|
||||
if(!material_instance)return(false);
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureTexture2D",Prim::Fan);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material=db->LoadMaterial("Std2D/PureTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Fan); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
@@ -73,23 +72,26 @@ private:
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
RenderablePrimitiveCreater rpc(db,"Quad",VERTEX_COUNT);
|
||||
|
||||
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V2F,VERTEX_COUNT,tex_coord_data)))return(false);
|
||||
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -105,16 +107,16 @@ public:
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
134
example/Texture/texture_rect.cpp
Normal file
134
example/Texture/texture_rect.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
constexpr float position_data[4]=
|
||||
{
|
||||
0, //left
|
||||
0, //top
|
||||
1, //right
|
||||
1 //bottom
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,
|
||||
1,1
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2D",Prim::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material=db->LoadMaterial("Std2D/RectTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
210
example/Texture/texture_rect_array.cpp
Normal file
210
example/Texture/texture_rect_array.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/Filename.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
//Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
float position_data[4]=
|
||||
{
|
||||
0, //left
|
||||
0, //top
|
||||
1, //right
|
||||
1 //bottom
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,
|
||||
1,1
|
||||
};
|
||||
|
||||
constexpr const os_char *tex_filename[]=
|
||||
{
|
||||
OS_TEXT("001-online resume.Tex2D"),
|
||||
OS_TEXT("002-salary.Tex2D"),
|
||||
OS_TEXT("003-application.Tex2D"),
|
||||
OS_TEXT("004-job interview.Tex2D")
|
||||
};
|
||||
|
||||
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Texture2DArray * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
DeviceBuffer * tex_id_ubo =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Renderable * r;
|
||||
}render_obj[TexCount]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->CreateTexture2DArray( "freepik icons",
|
||||
512,512, ///<纹理尺寸
|
||||
TexCount, ///<纹理层数
|
||||
PF_BC1_RGBAUN, ///<纹理格式
|
||||
false); ///<是否自动产生mipmaps
|
||||
|
||||
if(!texture)return(false);
|
||||
|
||||
OSString filename;
|
||||
|
||||
for(uint i=0;i<TexCount;i++)
|
||||
{
|
||||
filename=filesystem::MergeFilename(OS_TEXT("res/image/icon/freepik"),tex_filename[i]);
|
||||
|
||||
if(!db->LoadTexture2DToArray(texture,i,filename))
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2DArray",Prim::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std2D/RectTexture2DArray",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::Color, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].mi=db->CreateMaterialInstance(material);
|
||||
|
||||
if(!render_obj[i].mi)
|
||||
return(false);
|
||||
|
||||
render_obj[i].mi->WriteMIData(i); //设置MaterialInstance的数据
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
|
||||
|
||||
position_data[2]=1.0f/float(TexCount);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
Vector3f offset(1.0f/float(TexCount),0,0);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
offset.x=position_data[2]*float(i);
|
||||
|
||||
render_root.CreateSubNode(translate(offset),render_obj[i].r);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH*TexCount,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -10,22 +10,11 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan/${group}")
|
||||
endmacro()
|
||||
|
||||
CreateProject("Basic" 1st_draw_triangle_in_NDC first_triangle.cpp)
|
||||
CreateProject("Basic" 2nd_draw_triangle_use_UBO second_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_AutoInstance third_triangle.cpp)
|
||||
CreateProject("Basic" 4th_AutoMergeMaterialInstance fourth_triangle.cpp)
|
||||
|
||||
#CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
#CreateProject("Basic" indices_rect indices_rect.cpp)
|
||||
#CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
|
||||
#CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
|
||||
|
||||
CreateProject("Texture" TextureFormat TextureFormat.cpp)
|
||||
#CreateProject("Texture" texture_rect texture_rect.cpp)
|
||||
#CreateProject("Texture" HQFilterTexture HQFilterTexture.cpp)
|
||||
#CreateProject(06.Geometry2D Geometry2D.cpp)
|
||||
|
||||
#CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
|
||||
#CreateProject("Tile" DrawTile DrawTile.cpp)
|
||||
#CreateProject("Tile" DrawText DrawText.cpp)
|
||||
|
||||
|
@@ -1,87 +0,0 @@
|
||||
// 全屏三角形
|
||||
// 该范例用于演示使用索引画一个覆盖全屏的三角形,但是不传递任何顶点信息,顶点坐标在vertex shader中通过gl_VertexIndex计算出来。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable *renderable =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/fullscreen"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(3);
|
||||
if(!primitive)return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,160 +0,0 @@
|
||||
// 4.Geometry3D
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
if(!material)return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
if(!material_instance)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
void CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.coord[0]=Vector3f(-100,-100,0);
|
||||
pgci.coord[1]=Vector3f( 100,-100,0);
|
||||
pgci.coord[2]=Vector3f( 100, 100,0);
|
||||
pgci.coord[3]=Vector3f(-100, 100,0);
|
||||
|
||||
pgci.step.x=32;
|
||||
pgci.step.y=32;
|
||||
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
|
||||
pgci.color.Set(0.5,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
|
||||
ro_plane_grid[0]=CreatePlaneGrid(db,vil,&pgci);
|
||||
|
||||
pgci.color.Set(0,0.5,0,1);
|
||||
pgci.side_color.Set(0,1,0,1);
|
||||
|
||||
ro_plane_grid[1]=CreatePlaneGrid(db,vil,&pgci);
|
||||
|
||||
pgci.color.Set(0,0,0.5,1);
|
||||
pgci.side_color.Set(0,0,1,1);
|
||||
ro_plane_grid[2]=CreatePlaneGrid(db,vil,&pgci);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid[0],Matrix4f(1.0f));
|
||||
Add(ro_plane_grid[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(ro_plane_grid[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
camera->pos=Vector3f(200,200,200);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(camera->info,&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
CreateRenderObject();
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
// Instance Triangle
|
||||
|
||||
// 基本的Instance绘制测试用例,不使用场景树
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_SIZE=512;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{0.25,-0.75},
|
||||
{0,-1}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{ {1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
|
||||
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,191 +0,0 @@
|
||||
// 18.RayPicking
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
static float position_data[2][3]=
|
||||
{
|
||||
{100,100,100},
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static float color_data[2][4]=
|
||||
{
|
||||
{1,1,0,1},
|
||||
{1,1,0,1}
|
||||
};
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid =nullptr;
|
||||
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
VBO * vbo_pos =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
if(!material)return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
if(!material_instance)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.coord[0]=Vector3f(-100,-100,0);
|
||||
pgci.coord[1]=Vector3f( 100,-100,0);
|
||||
pgci.coord[2]=Vector3f( 100, 100,0);
|
||||
pgci.coord[3]=Vector3f(-100, 100,0);
|
||||
|
||||
pgci.step.x=32;
|
||||
pgci.step.y=32;
|
||||
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
|
||||
pgci.color.Set(0.25,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
|
||||
ro_plane_grid=CreatePlaneGrid(db,vil,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
ro_line=db->CreatePrimitive(2);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, vbo_pos=db->CreateVBO(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,2,color_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid,Matrix4f(1.0f));
|
||||
Add(ro_line,Matrix4f(1.0f));
|
||||
|
||||
camera->pos=Vector3f(100,100,50);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(camera->info,&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
const CameraInfo &ci=GetCameraInfo();
|
||||
|
||||
ray.Set(GetMouseCoord(),&ci); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(ci,&render_root);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
// 2.RectanglePrimivate
|
||||
// 该示例是texture_rect的进化,演示使用GeometryShader画矩形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_SIZE=512;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=1;
|
||||
|
||||
constexpr float BORDER=0.1f;
|
||||
|
||||
constexpr float position_data[4]=
|
||||
{
|
||||
SCREEN_SIZE*BORDER, SCREEN_SIZE*BORDER,
|
||||
SCREEN_SIZE*(1.0-BORDER), SCREEN_SIZE*(1.0-BORDER)
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,1,1
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Primitive * primitive =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/TextureRect2D"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::SolidRectangles);
|
||||
if(!pipeline)return(false);
|
||||
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"));
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
|
||||
if(!primitive)return(false);
|
||||
|
||||
primitive->Set(VAN::Position,db->CreateVBO(VF_V4F,VERTEX_COUNT,position_data));
|
||||
primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V4F,VERTEX_COUNT,tex_coord_data));
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
// indices_rect
|
||||
// 该示例演示使用索引数据画一个矩形,并使用了颜色材质
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
static Vector4f color(1,1,1,1);
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{SCREEN_WIDTH,0},
|
||||
{0,SCREEN_HEIGHT},
|
||||
{SCREEN_WIDTH,SCREEN_HEIGHT}
|
||||
};
|
||||
|
||||
constexpr uint32_t INDEX_COUNT=6;
|
||||
|
||||
constexpr uint16 index_data[INDEX_COUNT]=
|
||||
{
|
||||
0,1,3,
|
||||
0,3,2
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable *renderable =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/FragColor"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -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.wide_lines=true;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +296,22 @@ public:
|
||||
}
|
||||
|
||||
template<typename ...ARGS>
|
||||
Pipeline *CreatePipeline(ARGS...args){return device_render_pass->CreatePipeline(args...);}
|
||||
Pipeline *CreatePipeline(ARGS...args)
|
||||
{
|
||||
Pipeline *p=device_render_pass->CreatePipeline(args...);
|
||||
|
||||
if(!p)
|
||||
return(nullptr);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
du->SetPipeline(*p,"Pipeline:"+p->GetName());
|
||||
#endif//_DEBUG
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -368,7 +402,7 @@ class CameraMouseControl:public MouseEvent
|
||||
Vector2f mouse_pos;
|
||||
Vector2f mouse_last_pos;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
bool OnPressed(int x,int y,MouseButton) override
|
||||
{
|
||||
@@ -438,7 +472,6 @@ public:
|
||||
|
||||
class CameraAppFramework:public VulkanApplicationFramework
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
@@ -461,7 +494,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 +505,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 +519,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 +535,7 @@ public:
|
||||
ubo_camera_info->Write(&camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
const CameraInfo &GetCameraInfo()
|
||||
CameraInfo &GetCameraInfo()
|
||||
{
|
||||
return camera_control->GetCameraInfo();
|
||||
}
|
||||
@@ -510,11 +545,6 @@ public:
|
||||
return ubo_camera_info;
|
||||
}
|
||||
|
||||
bool BindCameraUBO(MaterialInstance *mi)
|
||||
{
|
||||
return mi->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||
|
||||
virtual void Draw()override
|
||||
@@ -532,4 +562,55 @@ public:
|
||||
ckc->Update();
|
||||
cmc->Update();
|
||||
}
|
||||
};//class CameraAppFramework
|
||||
};//class CameraAppFramework
|
||||
|
||||
class SceneAppFramework:public CameraAppFramework
|
||||
{
|
||||
protected:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
SceneAppFramework()=default;
|
||||
|
||||
virtual ~SceneAppFramework()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
virtual bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!CameraAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
virtual void Resize(uint w,uint h) override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class SceneAppFramework:public CameraAppFramework
|
||||
|
||||
template<typename T> int RunApp(uint w,uint h)
|
||||
{
|
||||
T app;
|
||||
|
||||
if(!app.Init(w,h))
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -21,7 +21,7 @@ namespace hgl
|
||||
~Bitmap2DLoader();
|
||||
|
||||
void *OnBegin(uint32 total_bytes) override;
|
||||
void OnEnd() override {}
|
||||
bool OnEnd() override {return(false);}
|
||||
|
||||
BitmapData *GetBitmap();
|
||||
};//class Bitmap2DLoader
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/math/Vector.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/type/Size2.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
namespace hgl
|
||||
@@ -59,17 +60,17 @@ namespace hgl
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息
|
||||
* 平面网格创建信息<br>
|
||||
* 会创建一个在XY平面上居中的网格,单个格子尺寸为1。
|
||||
*/
|
||||
struct PlaneGridCreateInfo
|
||||
{
|
||||
Vector3f coord[4];
|
||||
Vector2u step;
|
||||
Size2u grid_size; ///<格子数量
|
||||
|
||||
Vector2u side_step; //到边界的步数
|
||||
Size2u sub_count; ///<细分格子数量
|
||||
|
||||
Color4f color; //一般线条颜色
|
||||
Color4f side_color; //边界线条颜色
|
||||
float lum; ///<一般线条颜色
|
||||
float sub_lum; ///<细分及边界线条颜色
|
||||
};//struct PlaneGridCreateInfo
|
||||
|
||||
/**
|
||||
@@ -77,23 +78,10 @@ namespace hgl
|
||||
*/
|
||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
|
||||
|
||||
struct PlaneCreateInfo
|
||||
{
|
||||
Vector2f tile;
|
||||
|
||||
public:
|
||||
|
||||
PlaneCreateInfo()
|
||||
{
|
||||
tile.x=1.0f;
|
||||
tile.y=1.0f;
|
||||
}
|
||||
};//struct PlaneCreateInfo
|
||||
|
||||
/**
|
||||
* 创建一个平面(三角形)
|
||||
*/
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci);
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil);
|
||||
|
||||
struct CubeCreateInfo
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define HGL_GRAPH_LIGHT_INCLUDE
|
||||
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/Color4f.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
|
@@ -13,7 +13,7 @@ class MaterialRenderList
|
||||
GPUDevice *device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
|
||||
Material *mtl;
|
||||
Material *material;
|
||||
|
||||
RenderNodeList rn_list;
|
||||
|
||||
@@ -46,12 +46,10 @@ protected:
|
||||
|
||||
VBOList * vbo_list;
|
||||
|
||||
const VIL * last_vil;
|
||||
Pipeline * last_pipeline;
|
||||
const VertexInputData * last_vid;
|
||||
uint last_index;
|
||||
|
||||
void Bind(MaterialInstance *);
|
||||
bool Bind(const VertexInputData *,const uint);
|
||||
|
||||
void Render(RenderItem *);
|
||||
|
@@ -78,7 +78,7 @@ namespace hgl
|
||||
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
|
||||
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
|
||||
|
||||
virtual Primitive * Finish(); ///<结束并创建可渲染对象
|
||||
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
84
inc/hgl/graph/RenderResourceType.h
Normal file
84
inc/hgl/graph/RenderResourceType.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
enum class ResourceType
|
||||
{
|
||||
Unknown=0,
|
||||
|
||||
VkInstance,
|
||||
VkPhysicalDevice,
|
||||
VkDevice,
|
||||
|
||||
VertexInputLayout,
|
||||
Material,
|
||||
MaterialInstance,
|
||||
|
||||
FrameBuffer,
|
||||
|
||||
Texture,
|
||||
Sampler,
|
||||
|
||||
VertexBuffer,
|
||||
IndexBuffer,
|
||||
IndirectBuffer,
|
||||
UniformBuffer,
|
||||
StorageBuffer,
|
||||
|
||||
Skeleton, ///<骨骼信息
|
||||
SkeletonAnime, ///<骨骼动画信息
|
||||
|
||||
Primitive, ///<原始的单个模型数据,由多个VBO+Index组成
|
||||
RawMesh, ///<原始的静态模型数据,由一个Primitive和一个MaterialInstance组成
|
||||
StaticMesh, ///<静态模型数据,由一个或多个RawMesh组成
|
||||
SkeletonMesh, ///<骨骼模型数据,由一个或多个StaticMesh组成
|
||||
|
||||
Font,
|
||||
|
||||
Scene,
|
||||
Animation,
|
||||
Audio,
|
||||
Other,
|
||||
|
||||
ENUM_CLASS_RANGE(Unknown,Other)
|
||||
};
|
||||
|
||||
enum class ResourcePlace
|
||||
{
|
||||
Unknown=0,
|
||||
|
||||
Memory, ///<内存
|
||||
Device, ///<设备(如显存)
|
||||
Disk, ///<硬盘
|
||||
LAN, ///<局域网
|
||||
WAN, ///<广域网
|
||||
Other,
|
||||
|
||||
ENUM_CLASS_RANGE(Device,Other)
|
||||
};
|
||||
|
||||
struct RenderResourceID
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint device:1; ///<在设备
|
||||
uint memory:1; ///<在内存
|
||||
|
||||
uint disk:1; ///<在硬盘
|
||||
uint network:1; ///<在网络
|
||||
};
|
||||
|
||||
uint8 place; ///<数据所在位置
|
||||
};
|
||||
|
||||
uint16 resource_type; ///<资源类型,对应ResourceType枚举
|
||||
|
||||
uint16 thread_id; ///<线程ID
|
||||
|
||||
uint32 id; ///<资源ID
|
||||
};
|
||||
VK_NAMESPACE_END
|
@@ -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);
|
||||
|
@@ -86,7 +86,7 @@ namespace hgl
|
||||
protected:
|
||||
|
||||
virtual void *OnBegin(uint32)=0;
|
||||
virtual void OnEnd()=0;
|
||||
virtual bool OnEnd()=0;
|
||||
virtual void OnError(){}
|
||||
|
||||
public:
|
||||
@@ -207,7 +207,7 @@ namespace hgl
|
||||
{
|
||||
protected: // override functions
|
||||
|
||||
uint32 GetPixelsCount()const override{return file_header.length;}
|
||||
uint32 GetPixelsCount()const override{return file_header.length*file_header.layers;}
|
||||
uint32 GetTotalBytes()const override
|
||||
{
|
||||
if(file_header.mipmaps<=1)
|
||||
@@ -230,7 +230,7 @@ namespace hgl
|
||||
{
|
||||
protected: // override functions
|
||||
|
||||
uint32 GetPixelsCount()const override{return file_header.width*file_header.height;}
|
||||
uint32 GetPixelsCount()const override{return file_header.width*file_header.height*file_header.layers;}
|
||||
uint32 GetTotalBytes()const override
|
||||
{
|
||||
if(file_header.mipmaps<=1)
|
||||
|
@@ -26,7 +26,9 @@ constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_D
|
||||
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
|
||||
|
||||
using CharPointerList=hgl::List<const char *>;
|
||||
using BindingMapping=Map<uint32_t,int>;
|
||||
|
||||
using BindingMap =Map<AnsiString,int>;
|
||||
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
class VulkanInstance;
|
||||
class GPUPhysicalDevice;
|
||||
@@ -144,19 +146,10 @@ enum IndexType:uint
|
||||
U8=VK_INDEX_TYPE_UINT8_EXT,
|
||||
};
|
||||
|
||||
/**
|
||||
* max-lengths:
|
||||
*
|
||||
256 bytes: nvidia,arm
|
||||
128 bytes: amd,intel,powervr,adreno
|
||||
*/
|
||||
struct PushConstant
|
||||
{
|
||||
Matrix4f local_to_world;
|
||||
Matrix4f normal;
|
||||
};
|
||||
|
||||
constexpr uint32_t MAX_PUSH_CONSTANT_BYTES=sizeof(PushConstant);
|
||||
//Push Constant max-lengths:
|
||||
//
|
||||
// 256 bytes: nvidia,arm
|
||||
// 128 bytes: amd,intel,powervr,adreno
|
||||
|
||||
inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
|
||||
{
|
||||
|
@@ -36,6 +36,7 @@ public:
|
||||
|
||||
VkBuffer GetBuffer ()const{return buf.buffer;}
|
||||
DeviceMemory * GetMemory ()const{return buf.memory;}
|
||||
VkDeviceMemory GetVkMemory ()const{return buf.memory->operator VkDeviceMemory();}
|
||||
const VkDescriptorBufferInfo * GetBufferInfo ()const{return &buf.info;}
|
||||
|
||||
void * Map () {return buf.memory->Map();}
|
||||
|
@@ -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;
|
||||
@@ -179,8 +177,6 @@ public:
|
||||
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);}
|
||||
|
@@ -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
|
||||
|
@@ -24,6 +24,8 @@ class TileFont;
|
||||
class FontSource;
|
||||
class GPUArrayBuffer;
|
||||
|
||||
struct CopyBufferToImageInfo;
|
||||
|
||||
class GPUDevice
|
||||
{
|
||||
GPUDeviceAttribute *attr;
|
||||
@@ -45,7 +47,7 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
VkCommandBuffer CreateCommandBuffer();
|
||||
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
|
||||
|
||||
bool CreateSwapchainFBO(Swapchain *);
|
||||
|
||||
@@ -83,6 +85,8 @@ public:
|
||||
|
||||
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
|
||||
|
||||
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
|
||||
|
||||
public:
|
||||
|
||||
bool Resize (const VkExtent2D &);
|
||||
@@ -151,7 +155,15 @@ public: //Image
|
||||
|
||||
private: //texture
|
||||
|
||||
bool CommitTexture (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
|
||||
|
||||
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
|
||||
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
|
||||
|
||||
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
|
||||
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
|
||||
@@ -170,6 +182,10 @@ public: //Texture
|
||||
Texture2D *CreateTexture2D(TextureData *);
|
||||
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
|
||||
|
||||
Texture2DArray *CreateTexture2DArray(TextureData *);
|
||||
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
|
||||
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
|
||||
|
||||
TextureCube *CreateTextureCube(TextureData *);
|
||||
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
|
||||
|
||||
@@ -179,6 +195,10 @@ public: //Texture
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,void *data,const uint32_t size,const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,void *data,const uint32_t size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
public: //
|
||||
|
||||
Sampler *CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
@@ -194,8 +214,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
|
||||
|
||||
@@ -48,7 +47,6 @@ struct GPUDeviceAttribute
|
||||
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugMaker * debug_maker =nullptr;
|
||||
DebugUtils * debug_utils =nullptr;
|
||||
#endif//_DEBUG
|
||||
|
||||
|
@@ -92,6 +92,8 @@ public:
|
||||
hgl_zero(*this);
|
||||
|
||||
descriptor_pool=1024;
|
||||
|
||||
geometry_shader=true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -245,10 +247,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();
|
||||
|
||||
@@ -265,12 +267,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();
|
||||
}
|
||||
@@ -279,34 +281,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
|
||||
|
@@ -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:
|
||||
|
||||
@@ -69,12 +69,21 @@ public:
|
||||
}
|
||||
|
||||
const bool hasSet (const DescriptorSetType &type)const;
|
||||
const bool hasAssign ()const;
|
||||
|
||||
const VIL * GetDefaultVIL()const;
|
||||
VIL * CreateVIL(const VILConfig *format_map=nullptr);
|
||||
bool Release(VIL *);
|
||||
const uint GetVILCount();
|
||||
|
||||
public:
|
||||
|
||||
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
|
||||
|
||||
void Update();
|
||||
|
||||
public:
|
||||
|
||||
const bool HasMI ()const{return mi_data_bytes>0;}
|
||||
|
@@ -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;
|
||||
|
@@ -74,10 +74,9 @@ public:
|
||||
const int GetMIID ()const{return mi_id;} ///<取得材质实例ID
|
||||
void * GetMIData (){return material->GetMIData(mi_id);} ///<取得材质实例数据
|
||||
void WriteMIData (const void *data,const int size); ///<写入材质实例数据
|
||||
|
||||
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
|
||||
|
||||
template<typename T>
|
||||
void WriteMIData (const T &data){WriteMIData(&data,sizeof(T));} ///<写入材质实例数据
|
||||
};//class MaterialInstance
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||
|
@@ -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;}
|
||||
|
@@ -12,6 +12,9 @@ VK_NAMESPACE_BEGIN
|
||||
*/
|
||||
class Primitive
|
||||
{
|
||||
GPUDevice *device;
|
||||
AnsiString prim_name;
|
||||
|
||||
struct VBOData
|
||||
{
|
||||
VBO *buf;
|
||||
@@ -45,7 +48,13 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
Primitive(const uint32_t vc=0):vertex_count(vc){}
|
||||
Primitive(GPUDevice *dev,const AnsiString &n,const uint32_t vc=0)
|
||||
{
|
||||
device=dev;
|
||||
prim_name=n;
|
||||
vertex_count=vc;
|
||||
}
|
||||
|
||||
virtual ~Primitive()=default;
|
||||
|
||||
const uint GetRefCount()const{return ref_count;}
|
||||
@@ -55,14 +64,7 @@ public:
|
||||
|
||||
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
||||
{
|
||||
if(!ib)return(false);
|
||||
|
||||
index_buffer_data.buffer=ib;
|
||||
index_buffer_data.offset=offset;
|
||||
return(true);
|
||||
}
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0);
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -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:
|
||||
|
||||
|
@@ -16,8 +16,16 @@
|
||||
#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,14 +60,35 @@ 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:
|
||||
|
||||
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
|
||||
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
|
||||
@@ -75,12 +104,12 @@ public: //Add
|
||||
|
||||
public: // VBO/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);}
|
||||
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);}
|
||||
|
||||
#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,23 +118,36 @@ 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);
|
||||
Primitive * CreatePrimitive(const AnsiString &,const uint32_t vertex_count=0);
|
||||
|
||||
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||
|
||||
@@ -117,6 +159,9 @@ public: //texture
|
||||
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
|
||||
TextureCube * LoadTextureCube(const OSString &,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
|
||||
|
||||
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
||||
|
@@ -14,34 +14,34 @@ class RenderablePrimitiveCreater
|
||||
|
||||
public:
|
||||
|
||||
RenderablePrimitiveCreater(RenderResource *_rr,uint32_t vc)
|
||||
RenderablePrimitiveCreater(RenderResource *_rr,const AnsiString &name,uint32_t vc)
|
||||
{
|
||||
rr=_rr;
|
||||
vertex_count=vc;
|
||||
|
||||
prim=rr->CreatePrimitive(vertex_count);
|
||||
prim=rr->CreatePrimitive(name,vertex_count);
|
||||
}
|
||||
|
||||
bool SetVBO(const AnsiString &name,const VkFormat &fmt,const void *buf)
|
||||
VBO *SetVBO(const AnsiString &name,const VkFormat &fmt,const void *buf)
|
||||
{
|
||||
VBO *vbo=rr->CreateVBO(fmt,vertex_count,buf);
|
||||
|
||||
if(!vbo)
|
||||
return(false);
|
||||
return(nullptr);
|
||||
|
||||
prim->Set(name,vbo);
|
||||
return(true);
|
||||
return(vbo);
|
||||
}
|
||||
|
||||
bool SetIBO(const IndexType &it,const void *buf)
|
||||
IndexBuffer *SetIBO(const IndexType &it,const void *buf,const uint32_t index_count)
|
||||
{
|
||||
IndexBuffer *ibo=rr->CreateIBO(it,vertex_count,buf);
|
||||
IndexBuffer *ibo=rr->CreateIBO(it,index_count,buf);
|
||||
|
||||
if(!ibo)
|
||||
return(false);
|
||||
return(nullptr);
|
||||
|
||||
prim->Set(ibo);
|
||||
return(true);
|
||||
return(ibo);
|
||||
}
|
||||
|
||||
Renderable *Create(MaterialInstance *mi,Pipeline *p)
|
||||
|
@@ -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;}
|
||||
@@ -63,8 +63,8 @@ class Texture2D:public Texture
|
||||
{
|
||||
public:
|
||||
|
||||
Texture2D(VkDevice dev,TextureData *td):Texture(dev,td){}
|
||||
~Texture2D()=default;
|
||||
using Texture::Texture;
|
||||
virtual ~Texture2D()=default;
|
||||
|
||||
static VkImageViewType GetImageViewType(){return VK_IMAGE_VIEW_TYPE_2D;}
|
||||
|
||||
@@ -72,10 +72,19 @@ public:
|
||||
const uint32_t GetHeight()const{return data?data->image_view->GetExtent().height:0;}
|
||||
};//class Texture2D:public Texture
|
||||
|
||||
//class Texture2DArray:public Texture
|
||||
//{
|
||||
// uint32_t width,height,count;
|
||||
//};//class Texture2DArray:public Texture
|
||||
class Texture2DArray:public Texture
|
||||
{
|
||||
public:
|
||||
|
||||
using Texture::Texture;
|
||||
virtual ~Texture2DArray()=default;
|
||||
|
||||
static VkImageViewType GetImageViewType(){return VK_IMAGE_VIEW_TYPE_2D_ARRAY;}
|
||||
|
||||
const uint32_t GetWidth ()const{return data?data->image_view->GetExtent().width:0;}
|
||||
const uint32_t GetHeight()const{return data?data->image_view->GetExtent().height:0;}
|
||||
const uint32_t GetLayer ()const{return data?data->image_view->GetExtent().depth:0;}
|
||||
};//class Texture2DArray:public Texture
|
||||
|
||||
//class Texture3D:public Texture
|
||||
//{
|
||||
|
@@ -20,13 +20,13 @@ struct TextureCreateInfo
|
||||
VkImageLayout image_layout;
|
||||
|
||||
VkImage image; //如果没有IMAGE,则创建。(交换链等会直接提供image,所以存在外部传入现像)
|
||||
DeviceMemory * memory; //同时需分配内存并绑定
|
||||
DeviceMemory * memory; //同时需分配内存并绑定
|
||||
|
||||
ImageView * image_view; //如果没有imageview,则创建
|
||||
|
||||
void * pixels; //如果没有buffer但有pixels,则根据pixels和以上条件创建buffer
|
||||
VkDeviceSize total_bytes;
|
||||
DeviceBuffer * buffer; //如果pixels也没有,则代表不会立即写入图像数据
|
||||
DeviceBuffer * buffer; //如果pixels也没有,则代表不会立即写入图像数据
|
||||
|
||||
public:
|
||||
|
||||
@@ -292,7 +292,7 @@ struct SwapchainDepthTextureCreateInfo:public TextureCreateInfo
|
||||
|
||||
struct TextureData
|
||||
{
|
||||
DeviceMemory * memory;
|
||||
DeviceMemory * memory;
|
||||
VkImage image;
|
||||
VkImageLayout image_layout;
|
||||
ImageView * image_view;
|
||||
|
@@ -197,7 +197,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)
|
||||
{
|
||||
@@ -303,6 +303,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)
|
||||
{
|
||||
|
@@ -1,30 +0,0 @@
|
||||
#ifndef HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
||||
#define HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
||||
|
||||
#include<hgl/graph/mtl/MaterialConfig.h>
|
||||
#include<hgl/graph/CoordinateSystem.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
{
|
||||
CoordinateSystem2D coordinate_system; ///<使用的坐标系
|
||||
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
public:
|
||||
|
||||
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name):MaterialCreateConfig(da,name)
|
||||
{
|
||||
rt_output.color=1; //输出一个颜色
|
||||
rt_output.depth=false; //不输出深度
|
||||
rt_output.stencil=false; //不输出stencil
|
||||
|
||||
coordinate_system=CoordinateSystem2D::NDC;
|
||||
local_to_world=false;
|
||||
}
|
||||
};//struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);
|
||||
MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
||||
STD_MTL_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
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
|
74
inc/hgl/graph/mtl/Material2DCreateConfig.h
Normal file
74
inc/hgl/graph/mtl/Material2DCreateConfig.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
||||
#define HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
||||
|
||||
#include<hgl/graph/mtl/MaterialConfig.h>
|
||||
#include<hgl/graph/CoordinateSystem.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
{
|
||||
CoordinateSystem2D coordinate_system; ///<使用的坐标系
|
||||
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
VAT position_format; ///<position格式
|
||||
|
||||
public:
|
||||
|
||||
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name,p)
|
||||
{
|
||||
rt_output.color=1; //输出一个颜色
|
||||
rt_output.depth=false; //不输出深度
|
||||
rt_output.stencil=false; //不输出stencil
|
||||
|
||||
coordinate_system=CoordinateSystem2D::NDC;
|
||||
local_to_world=false;
|
||||
|
||||
if(prim==Prim::SolidRectangles
|
||||
||prim==Prim::WireRectangles)
|
||||
position_format=VAT_VEC4;
|
||||
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 *);
|
||||
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;
|
||||
@@ -22,16 +23,37 @@ struct MaterialCreateConfig
|
||||
|
||||
uint32 shader_stage_flag_bit; ///<需要的shader
|
||||
|
||||
Prim prim; ///<图元类型
|
||||
|
||||
public:
|
||||
|
||||
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name)
|
||||
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p)
|
||||
{
|
||||
dev_attr=da;
|
||||
|
||||
mtl_name=name;
|
||||
|
||||
shader_stage_flag_bit=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
prim=p;
|
||||
}
|
||||
|
||||
int Comp(const MaterialCreateConfig &cfg)const
|
||||
{
|
||||
int off;
|
||||
|
||||
off=hgl_cmp(rt_output,cfg.rt_output);
|
||||
|
||||
if(off)return(off);
|
||||
|
||||
off=(int)prim-(int)cfg.prim;
|
||||
|
||||
if(off)return(off);
|
||||
|
||||
return shader_stage_flag_bit-cfg.shader_stage_flag_bit;
|
||||
}
|
||||
|
||||
CompOperator(const MaterialCreateConfig &,Comp)
|
||||
};//struct MaterialCreateConfig
|
||||
STD_MTL_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_MTL_CONFIG_INCLUDE
|
||||
|
15
inc/hgl/graph/mtl/SamplerName.h
Normal file
15
inc/hgl/graph/mtl/SamplerName.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
namespace mtl
|
||||
{
|
||||
namespace SamplerName
|
||||
{
|
||||
constexpr const char Color[] = "TextureColor";
|
||||
}//namespace SamplerName
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@@ -1,16 +1,57 @@
|
||||
#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_FUNC_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{namespace func{
|
||||
#define STD_MTL_FUNC_NAMESPACE_END }}}}
|
||||
|
||||
#define STD_MTL_FUNC NAMESPACE_USING using namespace hgl::graph::mtl::func;
|
||||
|
||||
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
|
||||
|
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
|
@@ -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;
|
||||
@@ -46,6 +46,7 @@ protected:
|
||||
virtual bool ProcHeader(){return(true);}
|
||||
|
||||
virtual bool ProcDefine();
|
||||
virtual bool ProcLayout(){return(true);}
|
||||
|
||||
virtual bool ProcSubpassInput();
|
||||
virtual bool ProcInput(ShaderCreateInfo *);
|
||||
@@ -57,7 +58,7 @@ protected:
|
||||
|
||||
virtual bool ProcUBO();
|
||||
virtual bool ProcSSBO();
|
||||
virtual bool ProcConst();
|
||||
virtual bool ProcConstantID();
|
||||
virtual bool ProcSampler();
|
||||
|
||||
bool CompileToSPV();
|
||||
@@ -78,12 +79,18 @@ 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 AddMaterialInstanceOutput();
|
||||
|
||||
void SetLocalToWorld(UBODescriptor *);
|
||||
|
||||
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
|
@@ -5,9 +5,17 @@
|
||||
namespace hgl{namespace graph{
|
||||
class ShaderCreateInfoGeometry:public ShaderCreateInfo
|
||||
{
|
||||
AnsiString input_prim;
|
||||
AnsiString output_prim;
|
||||
uint32_t max_vertices;
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoGeometry(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_GEOMETRY_BIT,m){}
|
||||
~ShaderCreateInfoGeometry()=default;
|
||||
|
||||
bool SetGeom(const Prim &ip,const Prim &op,const uint32_t mv);
|
||||
|
||||
bool ProcLayout() override;
|
||||
};
|
||||
}}//namespace hgl::graph
|
@@ -13,12 +13,14 @@ 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);
|
||||
|
||||
int hasInput(const char *);
|
||||
|
||||
void AddJoint();
|
||||
void AddAssign();
|
||||
};//class ShaderCreateInfoVertex:public ShaderCreateInfo
|
||||
|
@@ -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);
|
||||
|
@@ -106,10 +106,8 @@ SET(VK_INST_SOURCE ${SG_INCLUDE_PATH}/VKInstance.h
|
||||
Vulkan/VKInstance.cpp)
|
||||
|
||||
SET(VK_DEBUG_SOURCE ${SG_INCLUDE_PATH}/VKDebugOut.h
|
||||
${SG_INCLUDE_PATH}/VKDebugMaker.h
|
||||
${SG_INCLUDE_PATH}/VKDebugUtils.h
|
||||
Vulkan/Debug/VKDebugOut.cpp
|
||||
Vulkan/Debug/VKDebugMaker.cpp
|
||||
Vulkan/Debug/VKDebugUtils.cpp)
|
||||
|
||||
SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h
|
||||
@@ -127,11 +125,13 @@ SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
|
||||
Vulkan/Texture/GenMipmaps.cpp
|
||||
Vulkan/Texture/VKDeviceTexture.cpp
|
||||
Vulkan/Texture/VKDeviceTexture2D.cpp
|
||||
Vulkan/Texture/VKDeviceTexture2DArray.cpp
|
||||
Vulkan/Texture/VKDeviceTextureCube.cpp)
|
||||
|
||||
SET(VK_TEXTURE_LOADER_SOURCE ${SG_INCLUDE_PATH}/VKTextureCreateInfo.h
|
||||
Vulkan/Texture/VKTextureLoader.h
|
||||
Vulkan/Texture/VKTexture2DLoader.cpp
|
||||
Vulkan/Texture/VKTexture2DArrayLoader.cpp
|
||||
Vulkan/Texture/VKTextureCubeLoader.cpp)
|
||||
|
||||
SET(VK_DEVICE_CREATER_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
|
||||
|
@@ -28,7 +28,7 @@ namespace hgl
|
||||
|
||||
vertex->WriteRectFan(rci->scope);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Rectangle");
|
||||
}
|
||||
|
||||
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil)
|
||||
@@ -111,7 +111,7 @@ namespace hgl
|
||||
delete[] coord;
|
||||
}
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("RoundRectangle");
|
||||
}
|
||||
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci)
|
||||
@@ -159,57 +159,60 @@ namespace hgl
|
||||
color->Write(cci->border_color);
|
||||
}
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Circle");
|
||||
}
|
||||
|
||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
|
||||
if(!rc.Init(((pgci->step.x+1)+(pgci->step.y+1))*2))
|
||||
if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
for(uint row=0;row<=pgci->step.x;row++)
|
||||
{
|
||||
float pos=float(row)/float(pgci->step.x);
|
||||
|
||||
vertex->WriteLine( to(pgci->coord[0],pgci->coord[1],pos),
|
||||
to(pgci->coord[3],pgci->coord[2],pos));
|
||||
const float right=float(pgci->grid_size.Width())/2.0f;
|
||||
const float left =-right;
|
||||
|
||||
const float bottom=float(pgci->grid_size.Height())/2.0f;
|
||||
const float top =-bottom;
|
||||
|
||||
for(int row=0;row<=pgci->grid_size.Height();row++)
|
||||
{
|
||||
vertex->WriteLine( Vector3f(left ,top+row,0),
|
||||
Vector3f(right,top+row,0));
|
||||
}
|
||||
|
||||
for(uint col=0;col<=pgci->step.y;col++)
|
||||
for(int col=0;col<=pgci->grid_size.Width();col++)
|
||||
{
|
||||
float pos=float(col)/float(pgci->step.y);
|
||||
|
||||
vertex->WriteLine(to(pgci->coord[1],pgci->coord[2],pos),
|
||||
to(pgci->coord[0],pgci->coord[3],pos));
|
||||
vertex->WriteLine(Vector3f(left+col,top, 0),
|
||||
Vector3f(left+col,bottom,0));
|
||||
}
|
||||
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
if(color)
|
||||
AutoDelete<VB1f> lum=rc.AccessVAD<VB1f>(VAN::Luminance);
|
||||
if(lum)
|
||||
{
|
||||
for(uint row=0;row<=pgci->step.x;row++)
|
||||
for(int row=0;row<=pgci->grid_size.Height();row++)
|
||||
{
|
||||
if((row%pgci->side_step.x)==0)
|
||||
color->RepeatWrite(pgci->side_color,2);
|
||||
if((row%pgci->sub_count.Height())==0)
|
||||
lum->RepeatWrite(pgci->sub_lum,2);
|
||||
else
|
||||
color->RepeatWrite(pgci->color,2);
|
||||
lum->RepeatWrite(pgci->lum,2);
|
||||
}
|
||||
|
||||
for(uint col=0;col<=pgci->step.y;col++)
|
||||
for(int col=0;col<=pgci->grid_size.Width();col++)
|
||||
{
|
||||
if((col%pgci->side_step.y)==0)
|
||||
color->RepeatWrite(pgci->side_color,2);
|
||||
if((col%pgci->sub_count.Width())==0)
|
||||
lum->RepeatWrite(pgci->sub_lum,2);
|
||||
else
|
||||
color->RepeatWrite(pgci->color,2);
|
||||
lum->RepeatWrite(pgci->lum,2);
|
||||
}
|
||||
}
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("PlaneGrid");
|
||||
}
|
||||
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci)
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil)
|
||||
{
|
||||
const float xy_vertices [] = { -0.5f,-0.5f,0.0f, +0.5f,-0.5f,0.0f, +0.5f,+0.5f,0.0f, -0.5f,+0.5f,0.0f };
|
||||
float xy_tex_coord[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f };
|
||||
@@ -232,22 +235,17 @@ namespace hgl
|
||||
{
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
|
||||
tangent->RepeatWrite(xy_tangent,4);
|
||||
if(tangent)tangent->RepeatWrite(xy_tangent,4);
|
||||
}
|
||||
|
||||
{
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
if(tex_coord)
|
||||
{
|
||||
xy_tex_coord[2]=xy_tex_coord[4]=pci->tile.x;
|
||||
xy_tex_coord[5]=xy_tex_coord[7]=pci->tile.y;
|
||||
|
||||
tex_coord->Write(xy_tex_coord);
|
||||
}
|
||||
tex_coord->Write(xy_tex_coord,4);
|
||||
}
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Plane");
|
||||
}
|
||||
|
||||
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci)
|
||||
@@ -344,7 +342,7 @@ namespace hgl
|
||||
}
|
||||
|
||||
rc.CreateIBO16(6*2*3,indices);
|
||||
return rc.Finish();
|
||||
return rc.Finish("Cube");
|
||||
}
|
||||
|
||||
template<typename T> void CreateSphereIndices(T *tp,uint numberParallels,const uint numberSlices)
|
||||
@@ -485,9 +483,9 @@ namespace hgl
|
||||
|
||||
if(np)
|
||||
{
|
||||
*np=+x;++np;
|
||||
*np=-y;++np;
|
||||
*np=+z;++np;
|
||||
*np=x;++np;
|
||||
*np=y;++np;
|
||||
*np=z;++np;
|
||||
}
|
||||
|
||||
if(tcp)
|
||||
@@ -515,7 +513,7 @@ namespace hgl
|
||||
else
|
||||
CreateSphereIndices<uint32>(rc.CreateIBO32(numberIndices),numberParallels,numberSlices);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Sphere");
|
||||
}
|
||||
|
||||
Primitive *CreateDome(RenderResource *db,const VIL *vil,const uint numberSlices)
|
||||
@@ -601,7 +599,7 @@ namespace hgl
|
||||
else
|
||||
CreateSphereIndices<uint32>(rc.CreateIBO32(numberIndices),numberParallels,numberSlices);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Dome");
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -714,7 +712,7 @@ namespace hgl
|
||||
// NOTE: cos (2PIx) = cos (x) and sin (2PIx) = sin (x) so, we can use this formula
|
||||
// normal = {cos(2PIs)cos(2PIt) , sin(2PIs)cos(2PIt) ,sin(2PIt)}
|
||||
*np = +cos2PIs * cos2PIt; ++np;
|
||||
*np = -sin2PIt; ++np;
|
||||
*np = +sin2PIt; ++np;
|
||||
*np = +sin2PIs * cos2PIt; ++np;
|
||||
}
|
||||
|
||||
@@ -742,7 +740,7 @@ namespace hgl
|
||||
else
|
||||
CreateTorusIndices<uint32>(rc.CreateIBO32(numberIndices),tci->numberSlices,tci->numberStacks);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Torus");
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -945,7 +943,7 @@ namespace hgl
|
||||
if(np)
|
||||
{
|
||||
*np = cos(currentAngle); ++np;
|
||||
*np = sin(currentAngle); ++np;
|
||||
*np = -sin(currentAngle); ++np;
|
||||
*np = 0.0f; ++np;
|
||||
}
|
||||
|
||||
@@ -971,7 +969,7 @@ namespace hgl
|
||||
else
|
||||
CreateCylinderIndices<uint32>(rc.CreateIBO32(numberIndices),cci->numberSlices);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Cylinder");
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -1114,7 +1112,7 @@ namespace hgl
|
||||
if(np)
|
||||
{
|
||||
*np = h / l * cos(currentAngle); ++np;
|
||||
*np = h / l * sin(currentAngle); ++np;
|
||||
*np =-h / l * sin(currentAngle); ++np;
|
||||
*np = r / l; ++np;
|
||||
}
|
||||
|
||||
@@ -1138,7 +1136,7 @@ namespace hgl
|
||||
else
|
||||
CreateConeIndices<uint32>(rc.CreateIBO32(numberIndices),cci->numberSlices,cci->numberStacks);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Cone");
|
||||
}
|
||||
|
||||
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci)
|
||||
@@ -1165,7 +1163,7 @@ namespace hgl
|
||||
vertex->Write(0,0,0);color->Write(aci->color[2]);
|
||||
vertex->Write(0,0,s);color->Write(aci->color[2]);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("Axis");
|
||||
}
|
||||
|
||||
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci)
|
||||
@@ -1219,7 +1217,7 @@ namespace hgl
|
||||
|
||||
rc.CreateIBO16(24,indices);
|
||||
|
||||
return rc.Finish();
|
||||
return rc.Finish("BoundingBox");
|
||||
}
|
||||
}//namespace inline_geometry
|
||||
}//namespace graph
|
||||
|
@@ -34,15 +34,6 @@ int Comparator<hgl::graph::RenderNode>::compare(const hgl::graph::RenderNode &ob
|
||||
return off;
|
||||
}
|
||||
|
||||
//比较顶点输入格式
|
||||
{
|
||||
off=ri_one->GetMaterialInstance()->GetVIL()
|
||||
-ri_two->GetMaterialInstance()->GetVIL();
|
||||
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
//比较模型
|
||||
{
|
||||
off=ri_one->GetPrimitive()
|
||||
@@ -60,10 +51,14 @@ MaterialRenderList::MaterialRenderList(GPUDevice *d,Material *m)
|
||||
{
|
||||
device=d;
|
||||
cmd_buf=nullptr;
|
||||
mtl=m;
|
||||
assign_buffer=new RenderAssignBuffer(d,mtl->GetMIDataBytes());
|
||||
material=m;
|
||||
|
||||
vbo_list=new VBOList(mtl->GetVertexInput()->GetCount());
|
||||
if(material->hasAssign())
|
||||
assign_buffer=new RenderAssignBuffer(d,material->GetMIDataBytes());
|
||||
else
|
||||
assign_buffer=nullptr;
|
||||
|
||||
vbo_list=new VBOList(material->GetVertexInput()->GetCount());
|
||||
}
|
||||
|
||||
MaterialRenderList::~MaterialRenderList()
|
||||
@@ -91,13 +86,16 @@ void MaterialRenderList::End()
|
||||
|
||||
if(node_count<=0)return;
|
||||
|
||||
if(mtl->HasMI())
|
||||
StatMI();
|
||||
|
||||
Stat();
|
||||
|
||||
//写入LocalToWorld数据
|
||||
assign_buffer->WriteNode(rn_list.GetData(),node_count,mi_set);
|
||||
if(assign_buffer)
|
||||
{
|
||||
if(material->HasMI())
|
||||
StatMI();
|
||||
|
||||
//写入LocalToWorld数据
|
||||
assign_buffer->WriteNode(rn_list.GetData(),node_count,mi_set);
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
||||
@@ -114,7 +112,7 @@ void MaterialRenderList::StatMI()
|
||||
for(RenderNode &rn:rn_list)
|
||||
mi_set.Add(rn.ri->GetMaterialInstance());
|
||||
|
||||
if(mi_set.GetCount()>mtl->GetMIMaxCount())
|
||||
if(mi_set.GetCount()>material->GetMIMaxCount())
|
||||
{
|
||||
//超出最大数量了怎么办???
|
||||
}
|
||||
@@ -137,7 +135,6 @@ void MaterialRenderList::Stat()
|
||||
ri->Set(rn->ri);
|
||||
|
||||
last_pipeline =ri->pipeline;
|
||||
last_vil =ri->mi->GetVIL();
|
||||
last_vid =ri->vid;
|
||||
|
||||
++rn;
|
||||
@@ -145,13 +142,12 @@ void MaterialRenderList::Stat()
|
||||
for(uint i=1;i<count;i++)
|
||||
{
|
||||
if(last_pipeline==rn->ri->GetPipeline())
|
||||
if(last_vil==rn->ri->GetMaterialInstance()->GetVIL())
|
||||
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
||||
{
|
||||
++ri->count;
|
||||
++rn;
|
||||
continue;
|
||||
}
|
||||
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
||||
{
|
||||
++ri->count;
|
||||
++rn;
|
||||
continue;
|
||||
}
|
||||
|
||||
++ri_count;
|
||||
++ri;
|
||||
@@ -161,30 +157,20 @@ void MaterialRenderList::Stat()
|
||||
ri->Set(rn->ri);
|
||||
|
||||
last_pipeline =ri->pipeline;
|
||||
last_vil =ri->mi->GetVIL();
|
||||
last_vid =ri->vid;
|
||||
|
||||
++rn;
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialRenderList::Bind(MaterialInstance *mi)
|
||||
{
|
||||
if(!mi)return;
|
||||
|
||||
assign_buffer->Bind(mi);
|
||||
|
||||
cmd_buf->BindDescriptorSets(mi->GetMaterial());
|
||||
}
|
||||
|
||||
bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
||||
{
|
||||
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
||||
|
||||
const VIL *vil=last_vil;
|
||||
//const VIL *vil=last_vil;
|
||||
|
||||
if(vil->GetCount(VertexInputGroup::Basic)!=vid->binding_count)
|
||||
return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
||||
//if(vil->GetCount(VertexInputGroup::Basic)!=vid->binding_count)
|
||||
// return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
||||
|
||||
vbo_list->Restart();
|
||||
|
||||
@@ -221,17 +207,10 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
||||
// }
|
||||
//}
|
||||
|
||||
if(!vbo_list->IsFull()) //Assign组
|
||||
//if(!vbo_list->IsFull()) //Assign组
|
||||
{
|
||||
const uint assign_binding_count=vil->GetCount(VertexInputGroup::Assign);
|
||||
|
||||
if(assign_binding_count>0)
|
||||
{
|
||||
if(assign_binding_count!=1)
|
||||
return(false);
|
||||
|
||||
if(assign_buffer)
|
||||
vbo_list->Add(assign_buffer->GetAssignVBO(),ASSIGN_VBO_STRIDE_BYTES*ri_index);
|
||||
}
|
||||
}
|
||||
|
||||
//if(count!=binding_count)
|
||||
@@ -258,14 +237,6 @@ void MaterialRenderList::Render(RenderItem *ri)
|
||||
//这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive
|
||||
}
|
||||
|
||||
if(last_vil!=ri->mi->GetVIL())
|
||||
{
|
||||
Bind(ri->mi);
|
||||
last_vil=ri->mi->GetVIL();
|
||||
|
||||
last_vid=nullptr;
|
||||
}
|
||||
|
||||
if(!ri->vid->Comp(last_vid))
|
||||
{
|
||||
Bind(ri->vid,ri->first);
|
||||
@@ -300,9 +271,13 @@ void MaterialRenderList::Render(RenderCmdBuffer *rcb)
|
||||
RenderItem *ri=ri_array.GetData();
|
||||
|
||||
last_pipeline =nullptr;
|
||||
last_vil =nullptr;
|
||||
last_vid =nullptr;
|
||||
|
||||
if(assign_buffer)
|
||||
assign_buffer->Bind(material);
|
||||
|
||||
cmd_buf->BindDescriptorSets(material);
|
||||
|
||||
for(uint i=0;i<ri_count;i++)
|
||||
{
|
||||
Render(ri);
|
||||
|
@@ -105,14 +105,14 @@ namespace hgl
|
||||
return (uint32 *)ibo->Map();
|
||||
}
|
||||
|
||||
Primitive *PrimitiveCreater::Finish()
|
||||
Primitive *PrimitiveCreater::Finish(const AnsiString &prim_name)
|
||||
{
|
||||
const uint si_count=vil->GetCount();
|
||||
const uint si_count=vil->GetCount(VertexInputGroup::Basic);
|
||||
|
||||
if(vbo_map.GetCount()!=si_count)
|
||||
return(nullptr);
|
||||
|
||||
Primitive *primitive=db->CreatePrimitive(vertices_number);
|
||||
Primitive *primitive=db->CreatePrimitive(prim_name,vertices_number);
|
||||
|
||||
const auto *sp=vbo_map.GetDataList();
|
||||
for(uint i=0;i<si_count;i++)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user