170 Commits

Author SHA1 Message Date
f23ef6c90e use short name in IDName 2025-01-14 12:54:19 +08:00
baa2e758f2 [WIP] 2025-01-09 00:48:15 +08:00
76103a869b [wip] 2025-01-08 13:26:27 +08:00
5738837008 update String<> names 2025-01-04 14:14:47 +08:00
3337eb6652 Merge branch 'devel_37_RenderFramework' of http://www.hyzgame.com:3000/hyzboy/ULRE into devel_37_RenderFramework
# Conflicts:
#	inc/hgl/graph/module/SwapchainModule.h
#	src/SceneGraph/module/GraphModule.cpp
2024-12-24 13:13:23 +08:00
c7ae16b2c8 created RenderTargetManager they are codes from TextureManager 2024-12-24 13:10:01 +08:00
07b71ec0fe few update 2024-12-24 02:45:02 +08:00
2516e9cfc1 splited InitDependentModules 2024-12-21 17:25:30 +08:00
bd9e587691 remove module_fullname from GraphModule. 2024-12-19 08:37:45 +08:00
260fb1b2ba few update about GraphModulesMap 2024-12-18 08:26:01 +08:00
34846acae0 [DON'T WORK] added dependent modules .... 2024-12-17 13:57:21 +08:00
d1c3934beb Use RenderFramework instead of GPUDevice at Init GraphModuleManager 2024-12-16 23:24:08 +08:00
7dd075b495 Merge branch 'devel_37_RenderFramework' of http://www.hyzgame.com:3000/hyzboy/ULRE into devel_37_RenderFramework
# Conflicts:
#	CMSceneGraph
#	CMUtil
#	inc/hgl/graph/module/GraphModule.h
2024-12-13 22:15:02 +08:00
ff475a69b1 GraphModuleManager construct include RenderFramework; 2024-12-13 00:30:44 +08:00
758acafe88 Added module_init in GraphModule, pareparing to splite "new" and "init" operation, because the dependency is must support. 2024-12-12 13:32:28 +08:00
c45047c482 suppported newly codes about Hash 2024-12-12 13:30:51 +08:00
6c160f5c53 supported new Comparator<> and ItemComparator<> 2024-12-12 13:30:11 +08:00
dd5a78cbaa renamed to Comparator.h from CompOperator.h 2024-12-05 13:55:56 +08:00
a1d8ad52cb use newly Compartor<> 2024-12-05 13:49:44 +08:00
4f335f7230 ordered module_list in RenderFramework 2024-11-19 00:20:35 +08:00
5217df7923 layout codes 2024-11-15 00:11:06 +08:00
abad1784c2 fixed Order for to release graph modules. 2024-11-14 23:40:26 +08:00
fda5b629a2 added to RenderCmdBuffer's Begin and End of Swapchain in RenderFramework::MainLoop 2024-11-14 00:24:13 +08:00
2ab78bf4e6 add transfer_family in DeviceAttribute 2024-11-13 00:16:41 +08:00
43b406ead0 use minImageCount in Swapchain 2024-11-13 00:15:53 +08:00
359c1cdc87 Init OK! but sumbit a null CmdBuffer is a Bug. 2024-11-13 00:01:26 +08:00
2bb1056b2a a part of RenderFramework::Init(..) 2024-11-12 01:51:14 +08:00
66b75aceb9 added InitRenderCmdBuffer/ClearRenderCmdBuffer in SwapchainModule 2024-11-12 01:50:40 +08:00
b775ffa920 BeginFrame/EndFrame for SwapchainModule/RenderFramework 2024-11-11 01:49:48 +08:00
9f37373631 use image_count instead of color_count in Swapchain 2024-11-11 01:18:28 +08:00
adc3c5bd81 all compile OK! but 100% can't run. 2024-11-09 19:28:31 +08:00
64e8410f3f redefrag SwapchainModule 2024-11-09 00:58:13 +08:00
25be75eefa Moved few codes to RenderPassManager from GPUDevice 2024-11-09 00:57:40 +08:00
c9855d7dee use XXHash3 instead of sha1-le in RenderPassManager 2024-11-09 00:41:15 +08:00
e3dccd6b06 Use XXHASH3_128bit instead of SHA1-LittleEndian in hash of RenderPass 2024-11-09 00:30:38 +08:00
21b2a3d5c8 moved new path about RenderPassManager 2024-11-09 00:20:21 +08:00
c5fd711c09 renamed to RenderPassManager from DeviceRenderPassManage 2024-11-09 00:13:21 +08:00
5d3f2cfdfd port DeviceRenderPassManage 2024-11-09 00:12:03 +08:00
6b466f63cf moved CreateFBO/CreateRT to TextureManager 2024-11-09 00:11:43 +08:00
336688b4f0 moved few codes to SwapchainModule 2024-11-09 00:10:27 +08:00
75fb0dd672 removed GraphManager.h/.cpp 2024-11-09 00:09:29 +08:00
c3a5518b38 moved Swapchain's codes to SwapchainModule 2024-11-06 00:34:23 +08:00
173d3e075a To add newly texture to set/map in TextureManager 2024-11-06 00:21:01 +08:00
8ff954b5c2 Added RenderFramework::GetTextureManager() 2024-11-06 00:19:37 +08:00
30d13ec2c7 removed device from VKTexture.h 2024-11-06 00:19:12 +08:00
acdbdcd8b5 few codes about TextureManager 2024-11-05 23:52:53 +08:00
95e9fe79a9 moved few codes to TextureManager 2024-11-05 23:12:35 +08:00
88f5948a2e moved LoadTexture2D/CreateTexture2DArray/LoadTextureCube to TextureManager from VKRenderResource 2024-11-05 23:02:38 +08:00
f6cc1ee619 Added GraphModuleManager::ReleaseModule(GraphModule *) 2024-11-05 23:01:45 +08:00
f1f562c709 restruct codes for TextureManager 2024-11-05 00:04:36 +08:00
1543ed8952 renamed to SortedSet instead of SortedSets 2024-11-04 23:06:57 +08:00
6c6e1c1a8d Renamed to VKTexture.....cpp from VKDeviceTexture....cpp 2024-10-30 22:22:55 +08:00
722faa1a27 added WorldCoord in LightCullMode.h 2024-10-30 00:51:50 +08:00
3e88b0b77f Added RenderBufferName.h,RenderWorkflow.h and few update. 2024-10-30 00:29:20 +08:00
5ba5a331a5 moved Check()/Comp()/From() to .cpp from ShaderVariableType.h 2024-10-29 23:40:32 +08:00
f741825ab7 Added WindowMode.h 2024-10-29 02:25:45 +08:00
6bc9352c80 added BlendOpAdvanced support, but no test. 2024-10-29 01:48:59 +08:00
e99b669ef3 removed graph_module_manager/swapchain_mode from GPUDevice. 2024-10-29 01:48:38 +08:00
ffc6f0a074 split to BlendMode.h/LightCullMode.h from RenderFramework.h 2024-10-29 01:47:24 +08:00
d1ad3f35ac moved few codes to SwapchainModule 2024-10-29 00:50:32 +08:00
4f870edc3b redefined RenderFramework 2024-10-29 00:50:15 +08:00
2ffe402fae update codes of about TextureLoader 2024-10-29 00:49:47 +08:00
d3df8d50ca used GetVkDevice() instead of GetVulkanDevice() 2024-10-29 00:36:48 +08:00
2221e10750 Added GraphManager/TextureManager, moved few codes to they are. 2024-10-29 00:34:02 +08:00
983281f6ad splited to GraphModuleManager.cpp 2024-10-25 23:17:14 +08:00
1183e44221 Added RegistryCommonModule.cpp 2024-10-24 00:29:16 +08:00
e52f7c13a9 use AnsiIDName instead of AnsiString in GraphModuleMap 2024-10-23 23:22:41 +08:00
7d586182c8 Added GraphModuleFactory/SwapchainModule, but can't run 2024-10-23 02:09:01 +08:00
c3522da518 little codes of RenderFramework/RenderModule 2024-10-23 01:13:15 +08:00
7a373d6bc0 InitGraphModuleManager/ClearGraphModuleManager in GPUDevice. 2024-10-23 01:12:36 +08:00
62f2e4f819 first edition of GraphModule/GraphModuleManager 2024-10-23 01:11:57 +08:00
427d337845 Added GraphModule.cpp/.h 2024-10-22 01:51:25 +08:00
a0b0027663 added Component.cpp/StaticMeshComponent.h/.cpp 2024-10-20 23:28:46 +08:00
83c1a067fe Added Owner in SceneNode, and then have few other change. 2024-10-20 23:17:04 +08:00
0df9d64dcf Moved Pipeline to MaterialRenderMap from MaterialRenderList 2024-10-20 21:41:27 +08:00
6e54a4051d litte modified GBufferFormat.cpp/.h 2024-10-20 01:41:38 +08:00
5195f62ac5 few change 2024-10-20 01:41:13 +08:00
4f67c0184d removed ## 2024-10-20 01:40:52 +08:00
dc374c0fc7 added CheckColorAttachmentFormatSupport/CheckDepthStencilAttachFormatSupport in GPUDevice 2024-10-20 01:19:06 +08:00
ceb4e3e5f3 renamed SwapchainPrefer colorspaces 2024-10-20 01:18:42 +08:00
59b3ec6bf3 preparing RenderFramework 2024-10-19 13:08:05 +08:00
2c67990daa little and unimportant update 2024-10-13 00:15:45 +08:00
620d05c6ff added shadow attributes in StaticMesh 2024-10-10 01:59:24 +08:00
d1f1124302 updated SceneNodeAttributes.h 2024-10-10 01:59:05 +08:00
e9d5b369bf Added ShadowPolicy.h 2024-10-10 01:58:47 +08:00
71c0c7e627 Added SceneNodeAttributes.h 2024-10-10 01:23:12 +08:00
2f34d556e4 renamed to ChildNode instead of SubNode 2024-10-06 16:49:08 +08:00
b9fbab56f1 update codes for support new SceneNode 2024-10-06 14:51:38 +08:00
4614562929 optimized SceneNode class. 2024-10-06 02:30:59 +08:00
9450d92784 use Contains instead of IsMember/IsExist 2024-10-05 22:51:27 +08:00
d7f7a7d095 [WIP] preparing SceneManager 2024-09-06 01:04:28 +08:00
59fc27c864 layout codes of GizmoResource.hj 2024-09-02 23:07:20 +08:00
bbbd8b06c2 move the white_torus to GizmoRotate 2024-09-02 00:32:30 +08:00
efd9a447fb use TransformFaceToCamera in GizmoTest.cpp 2024-08-31 15:55:58 +08:00
5e8957b78b TransformFaceToCamera class is finished. 2024-08-31 15:46:11 +08:00
99264b5b0a Split SceneMatrix to standalone files 2024-08-31 00:10:57 +08:00
8ebbd674b2 Moved WorldPosition to SceneMatrix 2024-08-31 00:04:20 +08:00
72ceffeda2 Added UpdateMaterialInstance method. but no any test. 2024-08-30 03:36:01 +08:00
726a8ec635 use circle instead of Square in Gizmo3DMove 2024-08-30 01:29:20 +08:00
cf2efd69b9 Added CreateCircle2D/3D,CreateCircle3DByIndexTriangles functions. 2024-08-30 01:28:49 +08:00
e35abf0051 Added PrimitiveCreater::hasIndex() 2024-08-30 01:28:20 +08:00
e02aaf812d Renamed to Square from plane 2024-08-30 00:38:40 +08:00
ca6d99b6fb gizmo's scale/move/rotate to use same Value. 2024-08-30 00:30:06 +08:00
3f37fec8a8 use hgl_cmp<Matrix4f> instead of IsNearlyEqual 2024-08-29 20:25:57 +08:00
7dc4bb9d76 [BUG FIXED] Fix Bug that to use matrix2f storage local to world matrix. 2024-08-29 13:46:19 +08:00
3fc9971cf7 clear debug code. 2024-08-29 13:45:28 +08:00
442e52e17c [BUG] gizmoMove rootNote's ScaleMatrix's Z is non-work. 2024-08-29 13:37:13 +08:00
8245d83309 TEST CORRECT....WHY? 2024-08-29 13:07:02 +08:00
a9526ce956 Updated to support Newly SceneOrient,compiled all OK! but Non test..next step is test samples. 2024-08-27 01:27:53 +08:00
410b94a127 [WIP] improving SceneOrient 2024-08-25 04:03:57 +08:00
f4e16276ff [WIP] refresh scene orient 2024-08-24 03:08:14 +08:00
8880df8862 preparing Change to new Transform 2024-08-23 02:00:59 +08:00
0a5fb750fa create BillboardSceneNode, but isn't final design. 2024-08-08 01:43:20 +08:00
3589376b79 Layouted SceneOrient.h 2024-08-07 01:12:58 +08:00
9443dd5942 to support GLM_FORCE_AVX2 2024-08-05 01:25:49 +08:00
c0e4c7fe7e updated CMakeModule 2024-08-04 23:55:56 +08:00
ee9bd06f35 Jolt use c++20 2024-08-04 23:55:41 +08:00
421f5f8134 Added source codes of JoltPhysics-5.0.0 2024-08-04 23:43:44 +08:00
5213651054 Used Transform instead of Matrix4f in SceneOrient, MaterialRenderList/RenderAssignBuffer supports updating the L2WMatrix of only the changed objects 2024-08-04 22:35:31 +08:00
3768507169 save full SceneNode in RenderNode,added length sort. 2024-08-02 23:17:07 +08:00
7f074c6c79 Added a white ring outside gizmo_rotate 2024-08-01 01:42:21 +08:00
2137725bd2 Improved Torus codes 2024-07-31 00:17:23 +08:00
f7a0e97e49 test Draw Gizmo Rotate+Move 2024-07-31 00:11:24 +08:00
d5234316ae implement duplication SceneNode 2024-07-31 00:11:04 +08:00
c3a1266da6 Correct draw Gizmo Rotate/Scale, OK!! 2024-07-30 23:54:25 +08:00
e18a6e7a4a improved gizmo3dmove 2024-07-30 13:55:44 +08:00
741e0e8ade OK!OK!OK! Draw Gizmo3DMove model was correct. 2024-07-30 01:01:29 +08:00
f2a6c61c25 [WIP] render gizmo_move, but model is incorrect. 2024-07-30 00:47:28 +08:00
28fcdb6216 preparing LerpLine example. 2024-07-30 00:11:04 +08:00
412ed6f3f2 [WIP] first version of gizmo move test,,can't RUN. 2024-07-29 14:01:10 +08:00
03f7237db3 move StaticMesh.cpp 2024-07-29 13:19:24 +08:00
f79410e434 [WIP] StaticMesh and GizmoMove 2024-07-28 23:34:04 +08:00
eef7f58575 updated texture_format_list.cpp 2024-07-27 20:52:58 +08:00
bd4fc34cbb renamed values's name. 2024-07-27 19:13:35 +08:00
0c669807d7 [WIP]preparing fix DrawText.cpp 2024-07-26 03:27:32 +08:00
8f0cd9f35b use AnsiString in shader 2024-07-26 03:25:09 +08:00
416b7bfcb3 support C++20 2024-07-26 03:24:44 +08:00
fdf073376c fixed BillboardTest.cpp, test run ok! 2024-07-24 23:15:16 +08:00
1a15b93e15 updated codes support new MaterialRenderList::Add 2024-07-20 13:15:12 +08:00
898d01ac62 Change MaterialRenderList::Add 2024-07-18 01:53:23 +08:00
d11b84222f Added IdentityLocalMatrix in SceneOrient 2024-07-17 23:56:10 +08:00
a04752b391 example update. 2024-07-17 01:39:13 +08:00
30bb77d437 removed Center/LocalCenter/WorldCenter from SceneNode. 2024-07-17 01:38:46 +08:00
8ebb3095a7 Added Position/Direction in SceneOrient 2024-07-17 01:38:30 +08:00
6571a27f41 added StaticMesh.cpp/.h in example, they should move to SceneGraph in future 2024-07-15 01:23:13 +08:00
5855b2eb5b use GetObjectFromList instead of GetListObject 2024-07-15 01:21:49 +08:00
ba7be3ff17 fix file's encode 2024-07-15 01:21:28 +08:00
006929e86f splite GizmoResource.h 2024-07-14 23:49:05 +08:00
25957d8d32 fixed RayPicking example 2024-07-10 02:00:18 +08:00
c29346887c added to init 2d gizmo resource. 2024-07-10 01:14:54 +08:00
69b9556ca1 moved GizmoColor/GizmoShape to Gizmo.h 2024-07-10 00:35:57 +08:00
390bd14c7c added AssetFileFormat.md 2024-07-05 01:19:26 +08:00
dcce45a5ce added doc/AssetFileFormat.md 2024-07-05 01:16:13 +08:00
1f7c8fa25b Added frustum_planes in CameraInfo, added FrustumCheck function in MFCamera.h 2024-07-02 23:43:25 +08:00
0ba4674126 removed MIPManager.h 2024-07-02 23:22:46 +08:00
94a0e03c44 [WIP] MIPManager 2024-07-02 00:51:59 +08:00
eb70cb1ea4 [WIP] Gizmo update codes; 2024-07-01 23:31:18 +08:00
7903ac32c1 Update half_float types in VertexAttribBuffer/VertexAttribDataAccess 2024-07-01 23:30:38 +08:00
ac03ae4e44 renamed to SAFE_CLEAR_OBJECT_ARRAY_OBJECT from SAFE_CLEAR_OBJECT_ARRAY 2024-07-01 23:29:59 +08:00
a5fe26b2f0 Fixed little bug in VertexAttribDataAccess, and then added half-float VADA 2024-07-01 21:40:23 +08:00
3a6ec1f589 Added codes of to create shape in GizmoResource.cpp 2024-07-01 13:37:47 +08:00
910a8fa51b Merge branch 'devel_28_Gizmo_Move' into devel_34_Gizmo 2024-07-01 08:43:15 +08:00
cfc3ac8250 Luminance change to ufloat8 instead of float in VertexLum material 2024-07-01 02:57:33 +08:00
9121ebd11b added newly type about VABMap/VADA 2024-07-01 02:56:26 +08:00
107251c9ad Added VIL in Pipeline, add comp VIL in CreateRenderable 2024-07-01 02:55:48 +08:00
04b77cadf9 Added GizmoResource.cpp 2024-06-26 01:51:13 +08:00
0137ef6e0c added M_Gizmo3D.cpp inline material. 2024-06-26 01:50:55 +08:00
fafe6c077b [WIP] Gizmo 2024-06-25 01:17:47 +08:00
09e9e71d59 adjust & layout codes. 2024-06-24 22:30:34 +08:00
a22e802c77 Layout codes 2024-06-21 13:09:20 +08:00
1172 changed files with 189483 additions and 1762 deletions

2
CMCore

Submodule CMCore updated: a82810d58a...29e758f963

2
CMUtil

Submodule CMUtil updated: 39faf8b475...57ff3a70c9

View File

@@ -1,43 +0,0 @@
#Material
Name Billboard2DWay
Base Std3D/Billboard
#VertexInput
vec2 TexCoord
#Vertex
Output
{
vec2 TexCoord
}
Code
{
void main()
{
Output.TexCoord=TexCoord;
vec4 pos=GetPosition3D()
+camera.camera_right*TexCoord.x*Billboard.Size.x
+camera.camera_up *TexCoord.y*Billboard.Size.y;
gl_Position=GetPosition3D();
}
}
#Fragment
sampler2D TextureBaseColor
Output
{
vec4 FragColor;
}
Code
{
void main()
{
FragColor=texture(TextureBaseColor,Input.TexCoord);
}
}

View File

@@ -0,0 +1,82 @@
#Material
Name BillboardFixedSize
Base Std3D/Billboard
#VertexInput
vec2 TexCoord
#MaterialInstance
Length 8
Stage Vertex
Code
{
uvec2 BillboardSize;
}
#Vertex
Output
{
vec2 BillboardSize
}
Code
{
void main()
{
MaterialInstance mi=GetMI();
Output.BillboardSize=mi.BillboardSize/viewport.canvas_resolution;
gl_Position=GetPosition3D();
gl_Position/=gl_Position.w;
}
}
#Geometry
Output
{
vec2 TexCoord
}
Code
{
void main()
{
const vec2 BillboardVertex[4]=vec2[]
(
vec2(-0.5,-0.5),
vec2(-0.5, 0.5),
vec2( 0.5,-0.5),
vec2( 0.5, 0.5)
);
for(int i=0;i<4;i++)
{
gl_Position=gl_in[0].gl_Position;
gl_Position.xy+=BillboardVertex[i]*Input[0].BillboardSize;
Output.TexCoord=BillboardVertex[i]+vec2(0.5);
EmitVertex();
}
EndPrimitive();
}
}
#Fragment
sampler2D TextureBaseColor
Output
{
vec4 FragColor;
}
Code
{
void main()
{
FragColor=texture(TextureBaseColor,Input.TexCoord);
}
}

View File

@@ -81,7 +81,7 @@ Code
#ifndef HAVE_SPECULAR
FragColor=vec4(direct_color,1.0);
#else
#else
vec3 spec_color=vec3(0.0);

34
doc/AssetFileFormat.md Normal file
View File

@@ -0,0 +1,34 @@
# 为什么我们使用INI/TOML做为资产文件格式?
大部分的数据文件,我们会将其分为属性文本部分与二进制数据部分。
其中属性部分我们会使用INI/TOML方式编写。这样利于git/hg/svn等版本控制系统进行差异合并。
比如一个纹理贴图它的二进制部分首先是有它的“原始位图数据阵列”它的属性部分包含“宽、高、象素格式”这样的不可更改数据也包括“sRGB/Linear色彩空间、纹理分组、建议过滤方式、特定平台建议的压缩算法”等可调整数据。还有资产使用过程中产生的“引用资产列表”和“被引用资产列表”。
而这些可调整数据,我们可能是会随时修改的,甚至是不同的人可能会修改不同的部分。
如果我们将这些数据全部放入一个二进制文件中比如png/jpeg中。那么每修改一个小小的属性都需要向git/svn仓库提交整个二进制文件。这是相当愚蠢和不合理的。
而众所周知不管是免费的git/hg/svn还是收费的p4它们针对文本文件都会有一系列的差异化比较合并功能。而这个差异化自动合并都是基于文本行的。
所以,我们的所有资产文件,都会分裂成二进制数据文件和属性文本文件。而在这个属性文本文件中,对于每一项属性,是使用独立的行来保存数据的。
# Why do we use the INI/TOML as an asset file format?
For most files, we will split into the attributes text part and binary data part.
We will use the INI/TOML format to write the properties part. Because the format easily merges diff by git/hg/svn.
For example a texture. It's binary data includes "Raw bitmap data".
Its attributes part include "width, height, pixel format", they can't change.
Also, "sRGB/Linear colour space", "texture group", "recommend filter type" and "recommend compress format of special platform".
We may modify this data at any time. Even many people modify different parts at the same time.
If we use a binary file that it includes all data. for example, .png or .jpeg.
We need commit whole binary data after changed a few attributes. This behaviour is quite stupid and irrational.
Most people know this knowledge: Free git/hg/svn and commercial p4. They both include a merge-diff tool, which is text based.
so, we all asset files, they should split into the attributes text part and binary data part.
In this attribute's text file, a separate line is used to save data for each attribute.

View File

@@ -10,4 +10,6 @@
endmacro()
CreateProject(00.line line.cpp)
CreateProject(01.roundbox roundbox.cpp)
CreateProject(01.LerpLine LerpLine.cpp)
CreateProject(02.roundbox roundbox.cpp)

View File

@@ -0,0 +1,121 @@
// 主要用于测试几种2D插值算法
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT*2]=
{
-1.0, 0.0,
1.0, 0.0,
};
constexpr VkFormat PositionFormat=VF_V2F;
constexpr float color_data[VERTEX_COUNT*4]=
{ 1,0,0,1,
0,1,0,1,
0,0,1,1
};
constexpr VkFormat ColorFormat=VF_V4F;
class TestApp:public VulkanApplicationFramework
{
private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Lines);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
material_instance=db->CreateMaterialInstance(mci);
return material_instance;
}
bool InitPipeline()
{
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Lines);
return pipeline;
}
bool InitVBO()
{
PrimitiveCreater rpc(device,material_instance->GetVIL());
rpc.Init("Triangle",VERTEX_COUNT);
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
return(render_obj);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitAutoMaterial())
return(false);
if(!InitPipeline())
return(false);
if(!InitVBO())
return(false);
if(!BuildCommandBuffer(render_obj))
return(false);
return(true);
}
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -10,6 +10,7 @@
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/VKVertexInputConfig.h>
using namespace hgl;
using namespace hgl::graph;
@@ -55,11 +56,15 @@ private:
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_plane_grid)return(false);
VILConfig vil_config;
vil_config.Add(VAN::Luminance,VF_V1UN8);
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,nullptr,&white_color);
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
if(!mi_plane_grid)return(false);
pipeline_plane_grid=CreatePipeline(mtl_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
if(!pipeline_plane_grid)return(false);
}
@@ -115,7 +120,7 @@ private:
return(nullptr);
}
render_root.CreateSubNode(ri);
render_root.Add(new SceneNode(ri));
return ri;
}
@@ -125,17 +130,17 @@ private:
using namespace inline_geometry;
{
PrimitiveCreater pc(device,mtl_plane_grid->GetDefaultVIL());
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.grid_size.Set(500,500);
pgci.sub_count.Set(5,5);
pgci.lum=0.5;
pgci.sub_lum=0.75;
pgci.lum=128;
pgci.sub_lum=192;
prim_plane_grid=CreatePlaneGrid(&pc,&pgci);
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
}
{
@@ -158,7 +163,7 @@ private:
{
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
render_root.CreateSubNode(ro_billboard);
render_root.Add(new SceneNode(ro_billboard));
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
@@ -203,5 +208,5 @@ public:
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
return RunApp<TestApp>(1920,1080);
}

View File

@@ -10,9 +10,10 @@
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
endmacro()
CreateProject(00_first_app first_app.cpp)
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)
CreateProject(05_Billboard BillboardTest.cpp)
CreateProject(05_Billboard BillboardTest.cpp)

View File

@@ -2,7 +2,6 @@
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
@@ -94,7 +93,7 @@ private:
rad=deg2rad<double>((360/TRIANGLE_NUMBER)*i); //这里一定要加<float>或<float>否则结果用int保存会出现问题
mat=rotate(rad,Vector3f(0,0,1));
render_root.CreateSubNode(mat,render_obj);
render_root.Add(new SceneNode(mat,render_obj));
}
render_root.RefreshMatrix();
@@ -110,10 +109,10 @@ public:
{
SAFE_CLEAR(render_list);
}
bool Init()
bool Init(uint w,uint h)
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
if(!VulkanApplicationFramework::Init(w,h))
return(false);
render_list=new RenderList(device);
@@ -139,12 +138,5 @@ public:
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
}

View File

@@ -96,6 +96,8 @@ private:
return(false);
db->Add(prim);
Matrix4f mat;
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
{
@@ -104,7 +106,9 @@ private:
if(!render_obj[i].r)
return(false);
render_root.CreateSubNode(rotate(deg2rad<double>(double(360/DRAW_OBJECT_COUNT*i)),Vector3f(0,0,1)),render_obj[i].r);
mat=rotate(deg2rad<double>(double(360/DRAW_OBJECT_COUNT*i)),AxisVector::Z);
render_root.Add(new SceneNode(mat,render_obj[i].r));
}
render_root.RefreshMatrix();

View File

@@ -1,10 +1,7 @@
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
@@ -125,9 +122,9 @@ private:
public:
bool Init()
bool Init(uint w,uint h)
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
if(!VulkanApplicationFramework::Init(w,h))
return(false);
InitVIL();
@@ -157,12 +154,5 @@ public:
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
}

View File

@@ -1,9 +1,6 @@
// 该范例主要演示使用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/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
@@ -132,5 +129,5 @@ public:
int main(int,char **)
{
RunApp<TestApp>(1280,720);
return RunApp<TestApp>(1280,720);
}

View File

@@ -0,0 +1,40 @@
#include<hgl/graph/RenderFramework.h>
#include<hgl/graph/module/RenderModule.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/log/Logger.h>
using namespace hgl;
using namespace hgl::graph;
class TestRenderModule:public RenderModule
{
public:
RENDER_MODULE_CONSTRUCT(TestRenderModule)
void OnResize(const VkExtent2D &size) override
{
LOG_INFO(OS_TEXT("Resize: ")+OSString::numberOf(size.width)+OS_TEXT("x")+OSString::numberOf(size.height));
}
void OnFrameRender(const double,RenderCmdBuffer *cmd) override
{
LOG_INFO(OS_TEXT("Execute"));
//cmd->Begin
}
};//class TestGraphModule:public RenderModule
int os_main(int,os_char **)
{
RenderFramework rf;
if(!rf.Init(1280,720,OS_TEXT("FirstApp")))
return 1;
rf.AddModule<TestRenderModule>();
rf.Run();
return 0;
}

View File

@@ -11,3 +11,4 @@ endmacro()
CreateProject(00.control_point_2d control_point_2d.cpp)
CreateProject(01.align_test align_test.cpp)
CreateProject(02.TextDrawTest DrawText.cpp)

View File

@@ -1,4 +1,4 @@
#include<hgl/type/StringList.h>
#include<hgl/io/LoadString.h>
#include<hgl/graph/font/TextRender.h>
#include"VulkanAppFramework.h"
@@ -8,7 +8,7 @@ using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH =1280;
constexpr uint32_t SCREEN_HEIGHT=SCREEN_WIDTH/16*9;
class TestApp:public VulkanApplicationFramework
class TestApp:public CameraAppFramework
{
private:
@@ -28,7 +28,7 @@ private:
bool InitTextRenderable()
{
UTF16String str;
U16String str;
LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt"));
@@ -61,16 +61,21 @@ public:
if(!InitTextRenderable())
return(false);
BuildCommandBuffer(render_obj);
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
return(true);
}
void Resize(int w,int h)override
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
}
void BuildCommandBuffer(uint32_t index)
{
VulkanApplicationFramework::BuildCommandBuffer(index,render_obj);
}
};//class TestApp:public VulkanApplicationFramework

View File

@@ -14,6 +14,12 @@ 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(04_Gizmo3DTest GizmoTest.cpp
Gizmo.h
GizmoResource.h
GizmoResource.cpp
Gizmo3DMove.cpp
Gizmo3DScale.cpp
Gizmo3DRotate.cpp)
#CreateProject(03_BlenderAxis BlenderAxis.cpp)

View File

@@ -1,16 +1,43 @@
#pragma once
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class Gizmo
enum class GizmoColor:uint
{
Material * material;
MaterialInstance * mi;
Pipeline * pipeline;
Primitive * primitive;
Black=0,
White,
};//class Gizmo
Red,
Green,
Blue,
Yellow,
ENUM_CLASS_RANGE(Black,Yellow)
};
enum class GizmoShape:uint
{
Square=0, //方块
Circle, //圆
Cube, //立方体
Sphere, //球
Cone, //圆锥
Cylinder, //圆柱
Torus, //圆环
ENUM_CLASS_RANGE(Square,Torus)
};
bool InitGizmoResource(RenderResource *);
void FreeGizmoResource();
Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color);
StaticMesh *GetGizmoMoveStaticMesh();
StaticMesh *GetGizmoScaleStaticMesh();
StaticMesh *GetGizmoRotateStaticMesh();
VK_NAMESPACE_END

View File

@@ -1,228 +1,151 @@
// Gizmo 3D Move
/*
Gizmo move
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
ref: Blender 4
0 9-10
*----------------->>>>
|
|
| 5+
| +6
|
|
v
假设轴尺寸为10
箭头长度为2直径为2
双轴调节正方形长宽为1位置为5,5
中心球半径为1
*/
#include"GizmoResource.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>
#include<hgl/graph/InlineGeometry.h>
using namespace hgl;
using namespace hgl::graph;
VK_NAMESPACE_BEGIN
static Color4f white_color(1,1,1,1);
static Color4f yellow_color(1,1,0,1);
class TestApp:public SceneAppFramework
namespace
{
Color4f color;
static StaticMesh *sm_gizmo_move=nullptr;
}//namespace
DeviceBuffer *ubo_color=nullptr;
StaticMesh *GetGizmoMoveStaticMesh()
{
return sm_gizmo_move;
}
private:
void ClearGizmoMoveStaticMesh()
{
SAFE_CLEAR(sm_gizmo_move);
}
Material * mtl_vtx_lum =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
Pipeline * pipeline_vtx_lum =nullptr;
Primitive * prim_plane_grid =nullptr;
Material * mtl_vtx_color =nullptr;
MaterialInstance * mi_line =nullptr;
Pipeline * pipeline_vtx_color =nullptr;
Primitive * prim_line =nullptr;
private:
bool InitMaterialAndPipeline()
bool InitGizmoMoveStaticMesh()
{
Renderable *sphere=GetGizmoRenderable(GizmoShape::Sphere,GizmoColor::White);
Renderable *cylinder[3]
{
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
};
cfg.local_to_world=true;
Renderable *cone[3]
{
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Blue),
};
mtl_vtx_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_vtx_lum)return(false);
Renderable *circle[3]=
{
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Blue)
};
mi_plane_grid=db->CreateMaterialInstance(mtl_vtx_lum,nullptr,&white_color);
if(!mi_plane_grid)return(false);
if(!sphere)
return(false);
pipeline_vtx_lum=CreatePipeline(mtl_vtx_lum,InlinePipeline::Solid3D,Prim::Lines);
for(int i=0;i<3;i++)
{
if(!cylinder[i])
return(false);
if(!pipeline_vtx_lum)
return(false);
}
if(!cone[i])
return(false);
if(!circle[i])
return(false);
}
{
SceneNode *root_node=new SceneNode();
root_node->Add(new SceneNode(sphere));
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
Transform tm;
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 Vector3f one_scale(1);
const Vector3f circle_scale(2);
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
{
const PipelineData *ipd=GetPipelineData(InlinePipeline::Solid3D);
tm.SetScale(cylinder_scale);
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
if(!ipd)
return(false);
tm.SetScale(one_scale);
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
root_node->Add(new SceneNode(tm,cone[2])); //Z 向上圆锥
PipelineData *pd=new PipelineData(ipd);
tm.SetScale(circle_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
root_node->Add(new SceneNode(tm,circle[2]));
}
pd->SetLineWidth(2);
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::Y,90);
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
pipeline_vtx_color=CreatePipeline(mtl_vtx_color,pd,Prim::Lines);
tm.SetScale(one_scale);
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cone[0])); //X 向右圆锥
delete pd;
tm.SetScale(circle_scale);
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,circle[0]));
}
if(!pipeline_vtx_color)
return(false);
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::X,-90);
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
root_node->Add(new SceneNode(tm,cone[1])); //Y 向前圆锥
tm.SetScale(circle_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,circle[1]));
}
}
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;
sm_gizmo_move=CreateGizmoStaticMesh(root_node);
}
/**
* 写入一个坐标轴的线条数据.
*
* \param pos 要写入数据的指针
* \param max_line 主线条方向
* \param oa1 其它轴1方向
* \param oa2 其它轴2方向
*/
void WriteAxisPosition(Vector3f *pos,const Vector3f &max_line,const Vector3f &oa1,const Vector3f &oa2)
{
constexpr const float AXIS_LENGTH =4;
constexpr const float AXIS_MIN_STEP =1;
constexpr const float AXIS_ARROW_SIZE=0.25;
if(!sm_gizmo_move)
return(false);
const Vector3f end_pos =max_line*AXIS_LENGTH; ///<最终点位置
const Vector3f cross_pos=max_line*AXIS_MIN_STEP; ///<坐标轴尾部交叉线位置
const Vector3f arrow_pos=max_line*(AXIS_LENGTH-AXIS_MIN_STEP); ///<箭头末端在主线上的位置
//主线
pos[0]=Vector3f(0, 0, 0);
pos[1]=end_pos;
//四根箭头线
pos[2]=end_pos;
pos[3]=arrow_pos-oa1*AXIS_ARROW_SIZE;
pos[4]=end_pos;
pos[5]=arrow_pos+oa1*AXIS_ARROW_SIZE;
pos[6]=end_pos;
pos[7]=arrow_pos-oa2*AXIS_ARROW_SIZE;
pos[8]=end_pos;
pos[9]=arrow_pos+oa2*AXIS_ARROW_SIZE;
//侧边连接其它轴线
pos[10]=cross_pos;
pos[11]=cross_pos+oa1*AXIS_MIN_STEP;
pos[12]=cross_pos;
pos[13]=cross_pos+oa2*AXIS_MIN_STEP;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
{
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.5;
pgci.sub_lum=0.75;
prim_plane_grid=CreatePlaneGrid(db,mtl_vtx_lum->GetDefaultVIL(),&pgci);
}
{
constexpr const uint AXIS_MAX_LINES =7;
constexpr const uint AXIS_MAX_VERTICES =AXIS_MAX_LINES*2*3;
prim_line=db->CreatePrimitive("Line",AXIS_MAX_VERTICES);
if(!prim_line)return(false);
Vector3f position_data[3][AXIS_MAX_LINES*2];
WriteAxisPosition(position_data[0],Vector3f(1,0,0),Vector3f(0,1,0),Vector3f(0,0,1));
WriteAxisPosition(position_data[1],Vector3f(0,1,0),Vector3f(1,0,0),Vector3f(0,0,1));
WriteAxisPosition(position_data[2],Vector3f(0,0,1),Vector3f(1,0,0),Vector3f(0,1,0));
Color4f color_data[3][AXIS_MAX_LINES*2];
for(Color4f &c:color_data[0])c=Color4f(1,0,0,1);
for(Color4f &c:color_data[1])c=Color4f(0,1,0,1);
for(Color4f &c:color_data[2])c=Color4f(0,0,1,1);
if(!prim_line->Set(VAN::Position, db->CreateVAB(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
if(!prim_line->Set(VAN::Color, db->CreateVAB(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
}
return(true);
}
bool InitScene()
{
Add(prim_plane_grid,mi_plane_grid,pipeline_vtx_lum);
Add(prim_line,mi_line,pipeline_vtx_color);
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint w,uint h) override
{
if(!SceneAppFramework::Init(w,h))
return(false);
if(!InitMaterialAndPipeline())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
return(true);
}
VK_NAMESPACE_END

View File

@@ -0,0 +1,79 @@
#include"GizmoResource.h"
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/TransformFaceToCamera.h>
VK_NAMESPACE_BEGIN
namespace
{
static StaticMesh *sm_gizmo_rotate=nullptr;
}//namespace
StaticMesh *GetGizmoRotateStaticMesh()
{
return sm_gizmo_rotate;
}
void ClearGizmoRotateStaticMesh()
{
SAFE_CLEAR(sm_gizmo_rotate);
}
bool InitGizmoRotateStaticMesh()
{
Renderable *torus[4]
{
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Blue),
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::White),
};
for(auto *r:torus)
{
if(!r)
return(false);
}
{
SceneNode *root_node=new SceneNode();
{
Transform tm;
tm.SetScale(GIZMO_ARROW_LENGTH);
root_node->Add(new SceneNode(tm,torus[0]));
tm.SetRotation(AXIS::Z,90);
root_node->Add(new SceneNode(tm,torus[1]));
tm.SetRotation(AXIS::Y,90);
root_node->Add(new SceneNode(tm,torus[2]));
}
{
SceneNode *white_torus=new SceneNode(scale(13),torus[3]);
white_torus->SetLocalNormal(AxisVector::X);
TransformFaceToCamera *rotate_white_torus_tfc=new TransformFaceToCamera();
//暂时因为无法传入Camera所以无法正确计算朝向正在设计Actor/World结构
white_torus->GetTransform().AddTransform(rotate_white_torus_tfc);
root_node->Add(white_torus);
}
sm_gizmo_rotate=CreateGizmoStaticMesh(root_node);
}
if(!sm_gizmo_rotate)
return(false);
return(true);
}
VK_NAMESPACE_END

View File

@@ -0,0 +1,151 @@
/*
Gizmo move
ref: Blender 4
0 9-10
*----------------->>>>
|
|
| 5+
| +6
|
|
v
假设轴尺寸为10
箭头长度为2直径为2
双轴调节正方形长宽为1位置为5,5
中心球半径为1
*/
#include"GizmoResource.h"
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/InlineGeometry.h>
VK_NAMESPACE_BEGIN
namespace
{
static StaticMesh *sm_gizmo_scale=nullptr;
}//namespace
StaticMesh *GetGizmoScaleStaticMesh()
{
return sm_gizmo_scale;
}
void ClearGizmoScaleStaticMesh()
{
SAFE_CLEAR(sm_gizmo_scale);
}
bool InitGizmoScaleStaticMesh()
{
Renderable *center_cube=GetGizmoRenderable(GizmoShape::Cube,GizmoColor::White);
Renderable *cylinder[3]
{
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
};
Renderable *cube[3]
{
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Blue),
};
Renderable *square[3]=
{
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Blue)
};
if(!center_cube)
return(false);
for(int i=0;i<3;i++)
{
if(!cylinder[i])
return(false);
if(!cube[i])
return(false);
if(!square[i])
return(false);
}
{
SceneNode *root_node=new SceneNode();
root_node->Add(new SceneNode(scale(GIZMO_CENTER_SPHERE_RADIUS*2),center_cube));
{
Transform tm;
const Vector3f one_scale(1);
const Vector3f plane_scale(2);
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
{
tm.SetScale(cylinder_scale);
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
root_node->Add(new SceneNode(tm,cube[2])); //Z 向上圆锥
tm.SetScale(plane_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
root_node->Add(new SceneNode(tm,square[2]));
}
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::Y,90);
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
tm.SetScale(one_scale);
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cube[0])); //X 向右圆锥
tm.SetScale(plane_scale);
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,square[0]));
}
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::X,-90);
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
root_node->Add(new SceneNode(tm,cube[1])); //Y 向前圆锥
tm.SetScale(plane_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,square[1]));
}
}
sm_gizmo_scale=CreateGizmoStaticMesh(root_node);
}
if(!sm_gizmo_scale)
return(false);
return(true);
}
VK_NAMESPACE_END

View File

@@ -0,0 +1,330 @@
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/color/Color.h>
#include<hgl/graph/InlineGeometry.h>
#include"GizmoResource.h"
VK_NAMESPACE_BEGIN
bool InitGizmoMoveStaticMesh();
void ClearGizmoMoveStaticMesh();
bool InitGizmoScaleStaticMesh();
void ClearGizmoScaleStaticMesh();
bool InitGizmoRotateStaticMesh();
void ClearGizmoRotateStaticMesh();
namespace
{
static RenderResource * gizmo_rr=nullptr;
struct GizmoResource
{
Material * mtl;
MaterialInstance * mi[size_t(GizmoColor::RANGE_SIZE)];
Pipeline * pipeline;
VertexDataManager * vdm;
PrimitiveCreater * prim_creater;
};
static GizmoResource gizmo_line{};
static GizmoResource gizmo_triangle{};
struct GizmoRenderable
{
Primitive *prim;
Renderable *renderable[size_t(GizmoColor::RANGE_SIZE)];
};
GizmoRenderable gizmo_rederable[size_t(GizmoShape::RANGE_SIZE)]{};
void InitGizmoRenderable(const GizmoShape &gs,Primitive *prim,Pipeline *p)
{
if(!prim)
return;
GizmoRenderable *gr=gizmo_rederable+size_t(gs);
gr->prim=prim;
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
gr->renderable[i]=CreateRenderable(prim,gizmo_triangle.mi[i],p);
}
bool InitMI(GizmoResource *gr)
{
if(!gr||!gr->mtl)
return(false);
Color4f color;
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
{
color=GetColor4f(gizmo_color[i],1.0);
gr->mi[i]=gizmo_rr->CreateMaterialInstance(gr->mtl,nullptr,&color);
if(!gr->mi[i])
return(false);
}
return(true);
}
bool InitGizmoResource2D(GPUDevice *device)
{
if(!gizmo_rr)
return(false);
RenderPass *render_pass=device->GetRenderPass();
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
cfg.local_to_world=true;
cfg.position_format=VAT_VEC3;
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(&cfg);
if(!mci)
return(false);
gizmo_line.mtl=gizmo_rr->CreateMaterial(mci);
if(!gizmo_line.mtl)
return(false);
gizmo_line.mtl->Update();
}
{
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D,Prim::Lines);
if(!gizmo_line.pipeline)
return(false);
}
if(!InitMI(&gizmo_line))
return(false);
{
gizmo_line.vdm=new VertexDataManager(device,gizmo_line.mtl->GetDefaultVIL());
if(!gizmo_line.vdm)
return(false);
if(!gizmo_line.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
HGL_SIZE_1MB, //最大索引数量
IndexType::U16)) //索引类型
return(false);
}
{
}
return(true);
}
bool InitGizmoResource3D(GPUDevice *device)
{
if(!gizmo_rr)
return(false);
RenderPass *render_pass=device->GetRenderPass();
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"Gizmo3D",Prim::Triangles);
cfg.local_to_world=true;
cfg.material_instance=true;
mtl::MaterialCreateInfo *mci=CreateMaterialGizmo3D(&cfg);
if(!mci)
return(false);
gizmo_triangle.mtl=gizmo_rr->CreateMaterial(mci);
if(!gizmo_triangle.mtl)
return(false);
gizmo_triangle.mtl->Update();
}
{
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D,Prim::Triangles);
if(!gizmo_triangle.pipeline)
return(false);
}
if(!InitMI(&gizmo_triangle))
return(false);
{
gizmo_triangle.vdm=new VertexDataManager(device,gizmo_triangle.mtl->GetDefaultVIL());
if(!gizmo_triangle.vdm)
return(false);
if(!gizmo_triangle.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
HGL_SIZE_1MB, //最大索引数量
IndexType::U16)) //索引类型
return(false);
}
{
gizmo_triangle.prim_creater=new PrimitiveCreater(gizmo_triangle.vdm);
if(!gizmo_triangle.prim_creater)
return(false);
}
{
using namespace inline_geometry;
{
InitGizmoRenderable(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
}
{
CircleCreateInfo cci;
cci.center=Vector2f(0,0);
cci.radius=Vector2f(0.5,0.5);
cci.field_count=16;
cci.has_center=false;
InitGizmoRenderable(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
CubeCreateInfo cci;
cci.normal=true;
cci.tangent=false;
cci.tex_coord=false;
InitGizmoRenderable(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
}
{
ConeCreateInfo cci;
cci.radius =GIZMO_CONE_RADIUS; //圆锥半径
cci.halfExtend =1; //圆锤一半高度
cci.numberSlices=16; //圆锥底部分割数
cci.numberStacks=3; //圆锥高度分割数
InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
struct CylinderCreateInfo cci;
cci.halfExtend =1; //圆柱一半高度
cci.numberSlices=16; //圆柱底部分割数
cci.radius =1; //圆柱半径
InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
struct TorusCreateInfo tci;
tci.innerRadius=0.975;
tci.outerRadius=1.0;
tci.numberSlices=64;
tci.numberStacks=8;
InitGizmoRenderable(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
}
ENUM_CLASS_FOR(GizmoShape,int,i)
{
if(!gizmo_rederable[i].prim)
return(false);
}
}
return(true);
}
}//namespace
bool InitGizmoResource(RenderResource *rr)
{
if(!rr)
return(false);
if(gizmo_rr)
return(false);
gizmo_rr=rr;
GPUDevice *device=gizmo_rr->GetDevice();
if(!InitGizmoResource3D(device))
return(false);
if(!InitGizmoResource2D(device))
return(false);
InitGizmoMoveStaticMesh();
InitGizmoScaleStaticMesh();
InitGizmoRotateStaticMesh();
return(true);
}
void FreeGizmoResource()
{
ClearGizmoRotateStaticMesh();
ClearGizmoScaleStaticMesh();
ClearGizmoMoveStaticMesh();
for(GizmoRenderable &gr:gizmo_rederable)
{
SAFE_CLEAR(gr.prim)
SAFE_CLEAR_OBJECT_ARRAY(gr.renderable)
}
SAFE_CLEAR(gizmo_triangle.prim_creater);
SAFE_CLEAR(gizmo_triangle.vdm);
SAFE_CLEAR(gizmo_line.prim_creater);
SAFE_CLEAR(gizmo_line.vdm);
}
Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color)
{
if(!gizmo_rr)
return(nullptr);
RANGE_CHECK_RETURN_NULLPTR(shape)
RANGE_CHECK_RETURN_NULLPTR(color)
return gizmo_rederable[size_t(shape)].renderable[size_t(color)];
}
StaticMesh *CreateGizmoStaticMesh(SceneNode *root_node)
{
if(!root_node)
return(nullptr);
if(root_node->IsEmpty())
return(nullptr);
return(new StaticMesh(root_node));
}
VK_NAMESPACE_END

View File

@@ -0,0 +1,42 @@
#pragma once
#include"Gizmo.h"
#include<hgl/color/Color.h>
VK_NAMESPACE_BEGIN
class SceneNode;
class PrimitiveCreater;
class StaticMesh;
constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]=
{
COLOR::MozillaCharcoal,
COLOR::BlanchedAlmond,
COLOR::BlenderAxisRed,
COLOR::BlenderAxisGreen,
COLOR::BlenderAxisBlue,
COLOR::BlenderYellow,
};
constexpr const float GIZMO_ARROW_LENGTH =10.0f; ///<箭头整体长度
constexpr const float GIZMO_CENTER_SPHERE_RADIUS=1.0f; ///<中心球半径
constexpr const float GIZMO_CONE_LENGTH =1.0f; ///<圆锥高度
constexpr const float GIZMO_CONE_RADIUS =1.0f; ///<圆锥底部半径
constexpr const float GIZMO_CONE_OFFSET =GIZMO_ARROW_LENGTH-(GIZMO_CONE_LENGTH/2.0f); ///<圆锥偏移量
constexpr const float GIZMO_CYLINDER_RADIUS =0.25f; ///<圆柱半径
constexpr const float GIZMO_CYLINDER_LENGTH =GIZMO_ARROW_LENGTH-GIZMO_CENTER_SPHERE_RADIUS-GIZMO_CONE_LENGTH; ///<圆柱长度
constexpr const float GIZMO_CYLINDER_HALF_LENGTH=GIZMO_CYLINDER_LENGTH/2.0f; ///<圆柱一半长度
constexpr const float GIZMO_CYLINDER_OFFSET =GIZMO_CYLINDER_HALF_LENGTH+GIZMO_CENTER_SPHERE_RADIUS; ///<圆柱偏移量
constexpr const float GIZMO_TWO_AXIS_OFFSET =5.0F; ///<二轴调节点偏移量(方片或圆)
Renderable *GetGizmoRenderable(const GizmoShape &gs,const GizmoColor &);
StaticMesh *CreateGizmoStaticMesh(SceneNode *);
VK_NAMESPACE_END

145
example/Gizmo/GizmoTest.cpp Normal file
View File

@@ -0,0 +1,145 @@
#include"VulkanAppFramework.h"
#include"Gizmo.h"
#include<hgl/graph/Ray.h>
using namespace hgl;
using namespace hgl::graph;
const Vector3f GizmoPosition(0,0,0);
///**
//* 一种永远转向正面的变换节点
//*/
//class TransformBillboard:public TransformBase
//{
// CameraInfo *camera_info=nullptr;
// bool face_to_camera=false;
//
// ViewportInfo *viewport_info=nullptr;
// float fixed_scale=1.0;
//
//public:
//
// virtual void SetCameraInfo (CameraInfo * ci ){camera_info =ci;}
// virtual void SetViewportInfo(ViewportInfo * vi ){viewport_info =vi;}
//
// virtual void SetFaceToCamera(bool ftc ){face_to_camera=ftc;}
// virtual void SetFixedScale (const float size){fixed_scale =size;}
//
// virtual bool RefreshTransform(const Transform &tf=IdentityTransform) override
// {
// if(!camera_info)
// {
// return SceneNode::RefreshTransform(tf);
// }
//
// if(face_to_camera)
// {
// LocalTransform.SetRotation(CalculateFacingRotationQuat(GetWorldPosition(),camera_info->view,AxisVector::X));
// }
//
// if(viewport_info)
// {
// const float screen_height=viewport_info->GetViewportHeight();
//
// const Vector4f pos=camera_info->Project(GetWorldPosition());
//
// LocalTransform.SetScale(pos.w*fixed_scale/screen_height);
// }
//
// return SceneNode::RefreshTransform(tf);
// }
//};//class BillboardSceneNode:public SceneNode
class TestApp:public SceneAppFramework
{
SceneNode root;
StaticMesh *sm_move=nullptr;
StaticMesh *sm_rotate=nullptr;
StaticMesh *sm_scale=nullptr;
private:
bool InitGizmo()
{
if(!InitGizmoResource(db))
return(false);
sm_move =GetGizmoMoveStaticMesh();
sm_rotate =GetGizmoRotateStaticMesh();
sm_scale =GetGizmoScaleStaticMesh();
return(true);
}
void InitGizmoSceneTree()
{
camera_control->Refresh();
CameraInfo *ci=camera_control->GetCameraInfo();
root.Clear();
//root.Add(Duplication(sm_move->GetScene()));
root.Add(Duplication(sm_rotate->GetScene()));
//root.CreateSubNode(sm_scale->GetScene());
root.RefreshMatrix();
render_list->SetCamera(ci);
render_list->Expend(&root);
}
public:
bool Init(uint w,uint h)
{
if(!SceneAppFramework::Init(w,h))
return(false);
if(!InitGizmo())
return(false);
InitGizmoSceneTree();
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
return(true);
}
~TestApp()
{
FreeGizmoResource();
}
void BuildCommandBuffer(uint32 index) override
{
camera_control->Refresh();
const CameraInfo *ci=camera_control->GetCameraInfo();
const ViewportInfo *vi=GetViewportInfo();
const float screen_height=vi->GetViewportHeight();
const Vector4f pos=ci->Project(GizmoPosition);
//{
// Transform tm;
// tm.SetScale(pos.w*16.0f/screen_height);
// root.SetLocalTransform(tm);
//}
root.RefreshMatrix();
render_list->UpdateLocalToWorld();
SceneAppFramework::BuildCommandBuffer(index);
}
};//class TestApp:public SceneAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1024,1024);
}

View File

@@ -6,7 +6,7 @@
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
using namespace hgl;
@@ -83,7 +83,12 @@ private:
bool CreateRenderObject()
{
ro_plane=inline_geometry::CreatePlane(db,material->GetDefaultVIL());
PrimitiveCreater pc(device,material->GetDefaultVIL());
ro_plane=inline_geometry::CreatePlaneSqaure(&pc);
if(ro_plane)
db->Add(ro_plane);
return ro_plane;
}

View File

@@ -7,6 +7,7 @@
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VKVertexInputConfig.h>
using namespace hgl;
using namespace hgl::graph;
@@ -33,6 +34,10 @@ private:
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!material)return(false);
VILConfig vil_config;
vil_config.Add(VAN::Luminance,VF_V1UN8);
Color4f GridColor;
COLOR ce=COLOR::BlenderAxisRed;
@@ -40,12 +45,12 @@ private:
{
GridColor=GetColor4f(ce,1.0);
material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor);
material_instance[i]=db->CreateMaterialInstance(material,&vil_config,&GridColor);
ce=COLOR((int)ce+1);
}
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D,Prim::Lines);
return pipeline;
}
@@ -59,12 +64,12 @@ private:
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.75;
pgci.sub_lum=1.0;
pgci.lum=180;
pgci.sub_lum=255;
PrimitiveCreater pc(device,material->GetDefaultVIL());
PrimitiveCreater pc(device,material_instance[0]->GetVIL());
prim_plane_grid=CreatePlaneGrid(&pc,&pgci);
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
return prim_plane_grid;
}
@@ -76,7 +81,7 @@ private:
if(!ri)
return(nullptr);
render_root.CreateSubNode(mat,ri);
render_root.Add(new SceneNode(mat,ri));
return ri;
}

View File

@@ -10,6 +10,7 @@
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/VKVertexInputConfig.h>
using namespace hgl;
using namespace hgl::graph;
@@ -54,17 +55,21 @@ private:
cfg.local_to_world=true;
{
{
cfg.mtl_name="VertexLuminance2D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
cfg.position_format=VAT_VEC2;
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_plane_grid)return(false);
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,nullptr,&white_color);
VILConfig vil_config;
vil_config.Add(VAN::Luminance,VF_V1UN8);
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
if(!mi_plane_grid)return(false);
pipeline_plane_grid=CreatePipeline(mtl_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
if(!pipeline_plane_grid)return(false);
}
@@ -97,7 +102,7 @@ private:
return(nullptr);
}
render_root.CreateSubNode(ri);
render_root.Add(new SceneNode(ri));
return ri;
}
@@ -107,17 +112,17 @@ private:
using namespace inline_geometry;
{
PrimitiveCreater pc(device,mtl_plane_grid->GetDefaultVIL());
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.5;
pgci.sub_lum=0.75;
pgci.lum=128;
pgci.sub_lum=196;
prim_plane_grid=CreatePlaneGrid(&pc,&pgci);
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
}
{
@@ -179,10 +184,10 @@ public:
void BuildCommandBuffer(uint32 index) override
{
const CameraInfo &ci=GetCameraInfo();
const ViewportInfo &vi=GetViewportInfo();
const CameraInfo *ci=GetCameraInfo();
const ViewportInfo *vi=GetViewportInfo();
ray.Set(GetMouseCoord(),&ci,&vi); //设置射线查询的屏幕坐标点
ray.Set(GetMouseCoord(),ci,vi); //设置射线查询的屏幕坐标点
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标

View File

@@ -35,7 +35,6 @@ constexpr const COLOR AxisColor[4]=
COLOR::GhostWhite,
COLOR::BlanchedAlmond,
COLOR::AntiqueWhite
};
constexpr const os_char *tex_filename[]=
@@ -87,7 +86,7 @@ private:
TexCount, ///<纹理层数
PF_BC1_RGBUN, ///<纹理格式
false); ///<是否自动产生mipmaps
if(!texture)return(false);
OSString filename;
@@ -234,7 +233,7 @@ private:
{
struct CylinderCreateInfo cci;
cci.halfExtend =1.25; //圆柱一半高度
cci.halfExtend =1.25; //圆柱一半高度
cci.numberSlices=16; //圆柱底部分割数
cci.radius =1.25f; //圆柱半径
@@ -257,7 +256,7 @@ private:
if(!ri)
{
LOG_ERROR(U8_TEXT("Create Renderable failed! Primitive: ")+r->GetName());
LOG_ERROR("Create Renderable failed! Primitive: "+r->GetName());
return(nullptr);
}

View File

@@ -9,32 +9,6 @@ using namespace hgl::graph;
VK_NAMESPACE_USING;
constexpr char *texture_compress_name[]=
{
"NONE",
"S3TC",
"PVRTC",
"ETC1",
"ETC2",
"EAC",
"ATC",
"ASTC",
"YUV"
};
constexpr char *data_type_name[]
{
"NONE",
"UNORM",
"SNORM",
"USCALED",
"SSCALED",
"UINT",
"SINT",
"UFLOAT",
"SFLOAT",
"SRGB"
};//
VulkanInstance *InitVulkanInstance()
{
@@ -92,14 +66,14 @@ int main(int,char **)
std::cout<<"Format [ID:"<<std::setw(10)<<vf->format<<"]["<<std::setw(16)<<vf->name<<"]";
if(vf->depth!=VulkanBaseType::NONE)
std::cout<<"[ Depth:"<<std::setw(8)<<data_type_name[size_t(vf->depth)]<<"]";
std::cout<<"[ Depth:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->depth)]<<"]";
if(vf->stencil!=VulkanBaseType::NONE)
std::cout<<"[Stencil:"<<std::setw(8)<<data_type_name[size_t(vf->stencil)]<<"]";
std::cout<<"[Stencil:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->stencil)]<<"]";
if((vf->depth==VulkanBaseType::NONE)
&&(vf->stencil==VulkanBaseType::NONE))
std::cout<<"[ Color:"<<std::setw(8)<<data_type_name[size_t(vf->color)]<<"]";
std::cout<<"[ Color:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->color)]<<"]";
{
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
@@ -114,7 +88,7 @@ int main(int,char **)
}
if(vf->compress_type!=TextureCompressType::NONE)
std::cout<<" use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
std::cout<<" use "<<TextureCompressTypeName[size_t(vf->compress_type)]<<" compress.";
else
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";

View File

@@ -38,18 +38,12 @@ using namespace hgl;
using namespace hgl::io;
using namespace hgl::graph;
namespace hgl{namespace graph
{
bool InitShaderCompiler();
void CloseShaderCompiler();
}}//namespace hgl::graph
class VulkanApplicationFramework:WindowEvent
{
protected:
Window * win =nullptr;
VulkanInstance * inst =nullptr;
Window * win =nullptr;
VulkanInstance * inst =nullptr;
protected:
@@ -76,14 +70,25 @@ protected:
public:
virtual void BindRenderResource(RenderResource *rr)
{
if(!rr)
return;
rr->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
VulkanApplicationFramework()
{
RegistryCommonGraphModule();
}
virtual ~VulkanApplicationFramework()
{
CloseShaderCompiler();
win->Unjoin(this);
SAFE_CLEAR(db);
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(cmd_buf,swap_chain_count);
SAFE_CLEAR(device);
SAFE_CLEAR(win);
@@ -94,9 +99,6 @@ public:
{
logger::InitLogger(OS_TEXT("VulkanTest"));
if(!InitShaderCompiler())
return(false);
SetClearColor(COLOR::MozillaCharcoal);
#ifdef _DEBUG
@@ -152,10 +154,10 @@ public:
vp_info.Set(w,h);
ubo_vp_info=db->CreateUBO("Viewport",sizeof(ViewportInfo),&vp_info);
db->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
BindRenderResource(db);
return(true);
}
@@ -165,9 +167,9 @@ public:
ubo_vp_info->Write(&vp_info);
}
ViewportInfo &GetViewportInfo()
ViewportInfo *GetViewportInfo()
{
return vp_info;
return &vp_info;
}
DeviceBuffer *GetViewportInfoBuffer()
@@ -197,7 +199,7 @@ public:
void InitCommandBuffer()
{
if(cmd_buf)
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(cmd_buf,swap_chain_count);
sc_render_target=device->GetSwapchainRT();
@@ -481,6 +483,15 @@ protected:
public:
virtual void BindRenderResource(RenderResource *rr) override
{
if(!rr)return;
VulkanApplicationFramework::BindRenderResource(rr);
rr->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
}
virtual ~CameraAppFramework()
{
SAFE_CLEAR(ckc);
@@ -494,6 +505,8 @@ public:
return(false);
InitCamera(w,h);
BindRenderResource(db);
return(true);
}
@@ -513,11 +526,9 @@ public:
win->Join(ckc);
win->Join(cmc);
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
RefreshCameraInfo(camera_control->GetCameraInfo(),&vp_info,camera);
ubo_camera_info=db->CreateUBO("CameraInfo",sizeof(CameraInfo),&camera_control->GetCameraInfo());
db->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
ubo_camera_info=db->CreateUBO("CameraInfo",sizeof(CameraInfo),camera_control->GetCameraInfo());
}
void Resize(uint w,uint h)override
@@ -526,10 +537,10 @@ public:
camera_control->Refresh();
ubo_camera_info->Write(&camera_control->GetCameraInfo());
ubo_camera_info->Write(camera_control->GetCameraInfo());
}
CameraInfo &GetCameraInfo()
CameraInfo *GetCameraInfo()
{
return camera_control->GetCameraInfo();
}
@@ -545,7 +556,7 @@ public:
{
camera_control->Refresh(); //更新相机矩阵
ubo_camera_info->Write(&camera_control->GetCameraInfo()); //写入缓冲区
ubo_camera_info->Write(camera_control->GetCameraInfo()); //写入缓冲区
const uint32_t index=AcquireNextImage();

View File

@@ -7,7 +7,7 @@ namespace hgl
namespace graph
{
/**
* 2Dλͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* 2D位图加载类
*/
class Bitmap2DLoader:public Texture2DLoader
{
@@ -20,7 +20,7 @@ namespace hgl
Bitmap2DLoader():Texture2DLoader(){}
~Bitmap2DLoader();
void *OnBegin(uint32 total_bytes) override;
void *OnBegin(uint32 total_bytes,const VkFormat &) override;
bool OnEnd() override {return(false);}
BitmapData *GetBitmap();

23
inc/hgl/graph/BlendMode.h Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
enum class BlendMode
{
Opaque,
Mask,
Transparent, ///<普通的Alpha混合透明
PreMulti, ///<预乘的Alpha混合透明
Add, ///<加法混合
Subtract, ///<减法混合
ReverseSubtract, ///<反减混合
Min, ///<最小混合
Max, ///<最大混合
ENUM_CLASS_RANGE(Opaque,Max)
};
VK_NAMESPACE_END

61
inc/hgl/graph/Component.h Normal file
View File

@@ -0,0 +1,61 @@
#pragma once
#include<hgl/type/TypeInfo.h>
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class SceneNode;
class ComponentData
{
};//class ComponentData
class ComponentManager;
class Component
{
ComponentData *data;
SceneNode *owner_node;
ComponentManager *manager;
public:
virtual const size_t GetTypeHash()=0; ///<取得当前组件类型
SceneNode *GetOwnerNode()const{return owner_node;} ///<取得当前组件所属节点
ComponentManager *GetManager()const{return manager;} ///<取得当前组件所属管理器
public:
Component()
{
data=nullptr;
owner_node=nullptr;
manager=nullptr;
}
Component(SceneNode *sn,ComponentData *cd,ComponentManager *cm);
virtual ~Component()=default;
virtual void Update(const double delta_time){}; ///<更新组件
};//class Component
class ComponentManager
{
ObjectList<Component> component_list;
public:
virtual void Update(const double delta_time)
{
for(Component *c:component_list)
{
c->Update(delta_time);
}
}
};//class ComponentManager
VK_NAMESPACE_END

View File

@@ -48,9 +48,9 @@ namespace hgl
{
Vector2f center; ///<圆心坐标
Vector2f radius; ///<半径
uint field_count=8; ///<分段
uint field_count=8; ///<分段数
bool has_color =false;
bool has_center; ///<是否有圆心点
Vector4f center_color; ///<圆心颜色
Vector4f border_color; ///<边缘颜色
@@ -59,7 +59,17 @@ namespace hgl
/**
* 创建一个2D圆形(扇形/线圈)
*/
Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci);
Primitive *CreateCircle2D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
/**
* 创建一个3D圆形(扇形/圆形XYZ永远为0)
*/
Primitive *CreateCircle3D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
/**
* 创建一个使用三角形绘制的3D圆形(扇形/圆形XYZ永远为0)
*/
Primitive *CreateCircle3DByIndexTriangles(PrimitiveCreater *pc,const CircleCreateInfo *cci);
/**
* 平面网格创建信息<br>
@@ -71,19 +81,21 @@ namespace hgl
Size2u sub_count; ///<细分格子数量
float lum; ///<一般线条颜色
float sub_lum; ///<细分及边界线条颜色
uint8 lum; ///<一般线条亮度
uint8 sub_lum; ///<细分及边界线条亮度
};//struct PlaneGridCreateInfo
/**
* 创建一个平面网格(线条)
*/
Primitive *CreatePlaneGrid(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci);
Primitive *CreatePlaneGrid2D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci); //创建一个平面网格(线条)
Primitive *CreatePlaneGrid3D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci);
/**
* 创建一个平面(三角形)
* 创建一个平面正方形(三角形)
*/
Primitive *CreatePlane(PrimitiveCreater *pc);
Primitive *CreatePlaneSqaure(PrimitiveCreater *pc);
struct CubeCreateInfo
{

View File

@@ -0,0 +1,45 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
/**
* 光照剔除模式
*/
enum class LightingCullingMode
{
None, ///<不剔除
/**
* 基于世界坐标的剔除模式
* 一般用于一些空间划分极为规则的场景。每个物件都可以得到较为明确的体积,并可通过世界坐标快速定位。
* 如即时战略游戏,普通的小爆炸,火光,影响的范围完全可以在世界坐标内圈定那些特件受影响,然后直接前向渲染即可。
*/
WorldCoord, ///<世界坐标剔除
/*
* 基于Tile的剔除模式
* 按屏幕XY坐标划分成多个Tile再配合znear/zfar形成一个Volume。所有光源和Volume计算相交性
*/
Tile, ///<瓦片剔除
/**
* 基于Tile的剔除模式的改进型
* 同Tile方法得出Tile后再通过遍历Tile内所有象素得出当前Tile的最远z值和最近z值。
* 根据XY与zNear/zFar得出一个Volume计算所有光源与Volume相交性。
*/
TileVolume, ///<瓦片体积剔除
/**
* 基于Tile的剔除模式的改进型
* 同TileVolume方法得出Volume后再将Volume按深度划分成多个Volume。
* 剔除掉没有象素的Volume再将剩下的Volume与光源计算相交性。
*/
Cluster, ///<集簇剔除
ENUM_CLASS_RANGE(None,Cluster)
};//enum class LightingCullingMode
VK_NAMESPACE_END

View File

@@ -0,0 +1,73 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
enum class LightingModel:uint8
{
Unlit,
Gizmo, ///<Gizmo专用(Blinnphong的特定版本内置假的太阳光方向、高光系数等使其不需要外部UBO传入)
Blinnphong, ///<Blinnphong光照模型
FakePBR, ///<假PBR(使用Blinnphong+HalfLambert模拟)
MicroPBR, ///<微型PBR(只有BaseColor/Normal/Metallic/Roughness四个基础数据的PBR)
WebPBR, ///<Khronos为WebGL提供的PBR
FilamentPBR, ///<Filament引擎所提供的PBR
AMDPBR, ///<AMD Caulrdon框架所提供的PBR
BlenderPBR, ///<Blender所提供的PBR
ENUM_CLASS_RANGE(Unlit,BlenderPBR)
};//enum class LightingModel:uint8
constexpr const char *LightingModelName[]=
{
"Unlit",
"Gizmo",
"Blinnphong",
"FakePBR",
"MicroPBR",
"WebPBR",
"FilamentPBR",
"AMDPBR",
"BlenderPBR"
};
/**
* 天光来源
*/
enum class SkyLightSource:uint8
{
PureColor, ///<纯色
GradientColor, ///<过渡色
Cubemap, ///<立方体贴图
IBL, ///<IBL立方体贴图
ENUM_CLASS_RANGE(PureColor,IBL)
};//enum class SkyLightSource:uint8
/**
* 环境光来源
*/
enum class AmbientLightSource:uint8
{
PureColor, ///<纯色
Distance, ///<距离(用于显示深邃场景比如峡谷、深井、管道越远越黑。理论等同AO)
LightProbe, ///<光线探针(也许也是Cubemap也许不是)
Cubemap, ///<本地Cubemap
};//enum class AmbientLightSource:uint8
VK_NAMESPACE_END

View File

@@ -1,24 +1,62 @@
#pragma once
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/VKVABList.h>
#include<hgl/type/SortedSets.h>
#include<hgl/graph/VKIndirectCommandBuffer.h>
VK_NAMESPACE_BEGIN
class RenderAssignBuffer;
class SceneNode;
struct CameraInfo;
struct RenderPipelineIndex:public Comparator<RenderPipelineIndex>
{
Material *material;
Pipeline *pipeline;
public:
const int compare(const RenderPipelineIndex &rli)const override
{
if(material<rli.material)return(-1);
if(material>rli.material)return(1);
if(pipeline<rli.pipeline)return(-1);
if(pipeline>rli.pipeline)return(1);
return(0);
}
public:
RenderPipelineIndex()
{
material=nullptr;
pipeline=nullptr;
}
RenderPipelineIndex(Material *m,Pipeline *p)
{
material=m;
pipeline=p;
}
};//struct RenderPipelineIndex
/**
* 同一材质的对象渲染列表
* 同一材质与管线的渲染列表
*/
class MaterialRenderList
{
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
Material *material;
RenderPipelineIndex rp_index;
CameraInfo *camera_info;
RenderNodeList rn_list;
RenderNodePointerList rn_update_l2w_list;
private:
RenderAssignBuffer *assign_buffer;
@@ -28,7 +66,6 @@ private:
uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB)
uint32_t instance_count;
Pipeline * pipeline;
MaterialInstance * mi;
const PrimitiveDataBuffer * pdb;
@@ -55,7 +92,6 @@ protected:
VABList * vab_list;
Pipeline * last_pipeline;
const PrimitiveDataBuffer * last_data_buffer;
const VDM * last_vdm;
const PrimitiveRenderData * last_render_data;
@@ -70,18 +106,20 @@ protected:
public:
MaterialRenderList(GPUDevice *d,bool l2w,Material *m);
MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi);
~MaterialRenderList();
void Add(Renderable *ri,const Matrix4f &mat);
void Add(SceneNode *);
void Clear()
{
rn_list.Clear();
}
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
void Clear(){rn_list.Clear();}
void End();
void Render(RenderCmdBuffer *);
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
void UpdateMaterialInstance(SceneNode *);
};//class MaterialRenderList
VK_NAMESPACE_END

View File

@@ -2,17 +2,20 @@
#include<hgl/graph/MaterialRenderList.h>
VK_NAMESPACE_BEGIN
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
class MaterialRenderMap:public ObjectMap<RenderPipelineIndex,MaterialRenderList>
{
public:
MaterialRenderMap()=default;
virtual ~MaterialRenderMap()=default;
void Begin()
void Begin(CameraInfo *ci)
{
for(auto *it:data_list)
{
it->value->SetCameraInfo(ci);
it->value->Clear();
}
}
void End()
@@ -28,5 +31,11 @@ public:
for(auto *it:data_list)
it->value->Render(rcb);
}
void UpdateLocalToWorld()
{
for(auto *it:data_list)
it->value->UpdateLocalToWorld();
}
};//class MaterialRenderMap
VK_NAMESPACE_END

View File

@@ -25,6 +25,7 @@ protected:
uint32_t vertices_number; ///<顶点数量
bool has_index; ///<是否有索引
uint32_t index_number; ///<索引数量
IndexType index_type; ///<索引类型
IndexBuffer * ibo; ///<索引缓冲区
@@ -62,6 +63,7 @@ public: //顶点缓冲区
public: //索引缓冲区
const bool hasIndex()const{return vdm?has_index:index_number>0;} ///<是否有索引缓冲区
const IndexType GetIndexType()const{return index_type;} ///<取得索引类型
const uint32_t GetIndexCount()const{return index_number;} ///<取得索引数量

View File

@@ -0,0 +1,61 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
const RENDER_BUFFER_NAME RenderBuffer_Swapchain ="Swapchain";
const RENDER_BUFFER_NAME RenderBuffer_Depth ="Depth";
const RENDER_BUFFER_NAME RenderBuffer_Stencil ="Stencil";
const RENDER_BUFFER_NAME VBuffer_MeshID ="VB_MeshID"; ///< 所绘制的Mesh编号, RGBA8UI格式
const RENDER_BUFFER_NAME VBuffer_TriangleID ="VB_TriangleID"; ///< 三角形编号, R8UI格式
const RENDER_BUFFER_NAME VBuffer_MaterialID ="VB_MaterialID"; ///< 材质ID与材质实例ID, RG8UI格式
const RENDER_BUFFER_NAME GBuffer_BaseColor ="GB_BaseColor"; ///<基础颜色(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_Luminance ="GB_Luminance"; ///<亮度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_CbCr ="GB_CbCr"; ///<色度(RG8/RG16F)
const RENDER_BUFFER_NAME GBuffer_Normal ="GB_Normal"; ///<法线(RG8,RG16F)
const RENDER_BUFFER_NAME GBuffer_BentNormal ="GB_BentNormal"; ///<弯曲法线(RG8,RG16F)
const RENDER_BUFFER_NAME GBuffer_Metallic ="GB_Metallic"; ///<金属度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Roughness ="GB_Roughness"; ///<粗糙度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Specular ="GB_Specular"; ///<高光(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Glossiness ="GB_Glossiness"; ///<光泽度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Reflection ="GB_Reflection"; ///<反射(R8)
const RENDER_BUFFER_NAME GBuffer_Refraction ="GB_Refraction"; ///<折射(R8)
const RENDER_BUFFER_NAME GBuffer_ClearCoat ="GB_ClearCoat"; ///<透明涂层(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_ClearCoatRoughness ="GB_ClearCoatRoughness"; ///<透明涂层粗糙度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_ClearCoatNormal ="GB_ClearCoatNormal"; ///<透明涂层法线(RG8/RG16F)
const RENDER_BUFFER_NAME GBuffer_IOR ="GB_IOR"; ///<折射率(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Tranmission ="GB_Tranmission"; ///<透射率(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Absorption ="GB_Absorption"; ///<吸收率(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_MicroThickness ="GB_MicroThickness"; ///<微厚度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_AmbientOcclusion ="GB_AmbientOcclusion"; ///<环境光遮蔽(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Anisotropy ="GB_Anisotropy"; ///<各向异性(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_AnisotropyDirection="GB_AnisotropyDirection"; ///<各向异性方向(RG8/RG16F/RG32F)
const RENDER_BUFFER_NAME GBuffer_Emissive ="GB_Emissive"; ///<自发光(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_SheenColor ="GB_SheenColor"; ///<光泽颜色(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_SheenRoughness ="GB_SheenRoughness"; ///<光泽粗糙度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_SubsurfaceColor ="GB_SubsurfaceColor"; ///<次表面颜色(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_ShadingModel ="GB_ShadingModel"; ///<着色模型(R4UI/R8UI)
const RENDER_BUFFER_NAME GBuffer_LightingChannels ="GB_LightingChannels"; ///<光照通道(R8UI)
const RENDER_BUFFER_NAME GBuffer_MotionVector ="GB_MotionVector"; ///<运动矢量(RG16F)
const RENDER_BUFFER_NAME GBuffer_LastScreenPosition ="GB_LastScreenPosition"; ///<上一帧屏幕位置(RG16I)
VK_NAMESPACE_END

View File

@@ -0,0 +1,145 @@
#pragma once
#include<hgl/type/List.h>
#include<hgl/platform/Window.h>
#include<hgl/graph/BlendMode.h>
#include<hgl/graph/ViewportInfo.h>
#include<hgl/graph/module/GraphModuleMap.h>
#include<hgl/graph/VKDevice.h>
VK_NAMESPACE_BEGIN
class GPUDevice;
class TileData;
class TileFont;
class FontSource;
class VulkanInstance;
class RenderPassManager;
class TextureManager;
class SwapchainModule;
/**
* 渲染框架
*/
class RenderFramework:public io::WindowEvent
{
protected:
Window * win =nullptr;
VulkanInstance * inst =nullptr;
GPUDevice * device =nullptr;
protected:
GraphModulesMap graph_module_map;
List<GraphModule *> per_frame_module_list;
List<RenderModule *> render_module_list;
protected:
SwapchainModule * swapchain_module =nullptr;
protected:
RenderPassManager * render_pass_manager =nullptr;
TextureManager * texture_manager =nullptr;
protected:
ViewportInfo viewport_info;
private:
double last_time =0;
double cur_time =0;
int64 frame_count =0;
public:
const int64 GetFrameCount ()const noexcept{return frame_count;} ///<取得当前帧数
void RestartFrameCount ()noexcept{frame_count=0;} ///<重新开始统计帧数
public: //module
template<typename T>
T * GetModule(){return graph_module_map.Get<T>();} ///<获取指定类型的模块
GraphModule * GetModule(const AIDName &name,bool create=false); ///<获取指定名称的模块
//template<typename T> T *AddModule()
//{
// T *tm=new T(graph_module_manager);
// module_list.Add(tm);
// if(tm->IsPerFrame())
// per_frame_module_list.Add(tm);
// if(tm->IsRender())
// render_module_list.Add(tm);
// return tm;
//}
GPUDevice * GetDevice () {return device;}
VkDevice GetVkDevice ()const {return device->GetDevice();}
const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备
GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性
SwapchainModule * GetSwapchain () {return swapchain_module;} ///<取得Swapchain模块
public: //manager
RenderPassManager * GetRenderPassManager(){return render_pass_manager;} ///<取得渲染通道管理器
TextureManager * GetTextureManager (){return texture_manager;} ///<取得纹理管理器
public: //event
virtual void OnResize(uint,uint)override;
virtual void OnActive(bool)override;
virtual void OnClose ()override;
public:
NO_COPY_NO_MOVE(RenderFramework)
private:
RenderFramework();
friend RenderFramework *CreateRenderFramework();
public:
virtual ~RenderFramework();
virtual bool Init(uint w,uint h,const OSString &app_name); ///<初始化
virtual void StartTime();
/**
* @pragma delta_time 本帧时间间隔
*/
virtual void Update(const double delta_time){}
virtual void BeginFrame(); ///<开始当前帧
virtual void EndFrame(); ///<当前帧结束
virtual void MainLoop(); ///<主循环
virtual void Run();
public: //TileData
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class RenderFramework
RenderFramework *CreateRenderFramework();
VK_NAMESPACE_END

View File

@@ -20,6 +20,8 @@ namespace hgl
GPUDevice * device;
CameraInfo * camera_info; ///<相机信息
uint renderable_count; ///<可渲染对象数量
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
@@ -30,13 +32,17 @@ namespace hgl
public:
RenderList(GPUDevice *);
virtual ~RenderList();
virtual ~RenderList()=default;
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
virtual void SetCamera(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void Clear(); ///<彻底清理
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
virtual void UpdateMaterialInstance(SceneNode *); ///<有对象互换了材质实例
virtual void Clear(); ///<彻底清理
};//class RenderList
}//namespace graph
}//namespace hgl

View File

@@ -2,24 +2,37 @@
#define HGL_GRAPH_RENDER_NODE_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
namespace hgl
{
namespace graph
{
class Renderable;
class MaterialInstance;
class SceneNode;
struct RenderNode
struct RenderNode:public Comparator<RenderNode>
{
Matrix4f local_to_world;
uint index; ///<在MaterialRenderList中的索引
Renderable *ri;
SceneNode * scene_node;
uint32 l2w_version;
uint32 l2w_index;
Vector3f world_position;
float to_camera_distance;
public:
//该函数位于MaterialRenderList.cpp
const int compare(const RenderNode &)const override;
};
using RenderNodeList=List<RenderNode>;
using RenderNodePointerList=List<RenderNode *>;
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
using MaterialInstanceSets=SortedSet<MaterialInstance *>; ///<材质实例集合
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE

View File

@@ -0,0 +1,30 @@
#pragma once
#include<hgl/graph/BlendMode.h>
#include<hgl/graph/RenderBufferName.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
enum class RenderOrder
{
First, ///<最先渲染
NearToFar, ///<从近到远
Irrorder, ///<无序渲染
FarToNear, ///<从远到近
Last, ///<最后渲染
ENUM_CLASS_RANGE(First,Last)
};//enum class RenderOrder
struct RenderWorkConfig
{
BlendMode blend_mode;
RenderOrder render_order;
SortedSet<RENDER_BUFFER_NAME> output_buffer;
};//struct RenderWorkConfig;
VK_NAMESPACE_END

View File

@@ -1,38 +0,0 @@
#ifndef HGL_GRAPH_SCENE_INFO_INCLUDE
#define HGL_GRAPH_SCENE_INFO_INCLUDE
#include<hgl/math/Matrix.h>
#include<hgl/CompOperator.h>
namespace hgl
{
namespace graph
{
/**
* MVP矩阵
*/
struct MVPMatrix
{
Matrix4f model; ///< model: Local to World
//Matrix4f normal; ///<transpose(inverse(mat3(model)));
Matrix3x4f normal; ///<这里用3x4在Shader中是3x3(但实际它是3x4保存)
Matrix4f mv; ///< view * model
Matrix4f mvp; ///< projection * view * model
public:
void Set(const Matrix4f &local_to_world,const Matrix4f &view_projection,const Matrix4f &view)
{
model =local_to_world;
normal =transpose(inverse(model));
mv =view*model;
mvp =view_projection*model;
}
CompOperatorMemcmp(const MVPMatrix &);
};//struct MVPMatrix
constexpr size_t MVPMatrixBytes=sizeof(MVPMatrix);
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_SCENE_INFO_INCLUDE

View File

@@ -0,0 +1,31 @@
#pragma once
#include<hgl/graph/SceneNode.h>
namespace hgl
{
namespace graph
{
/**
* 场景管理器<Br>
* 管理一个场景中的所有资源与场景节点
*/
class SceneManager
{
SceneNode *root_node;
public:
SceneNode *GetSceneRoot() {return root_node;}
const SceneNode *GetSceneRoot()const{return root_node;}
const uint GetNodeCount()const { return node_list.GetCount(); }
public:
};//class SceneManager
}//namespace graph
}//namespace hgl

116
inc/hgl/graph/SceneMatrix.h Normal file
View File

@@ -0,0 +1,116 @@
#pragma once
#include<hgl/math/Transform.h>
namespace hgl
{
namespace graph
{
/**
* 场景节点矩阵类<br>
*
* 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。<br>
* 构成说明:<br>
* <ul>
* <li>LocalMatrix 一般用于描述当前节点相对上一级的变换矩阵</li>
* <li>LocalToWorldMatrix 最终用于描述当前节点相对于世界的变换矩阵,在渲染时使用</li>
*
* <li>transform_manager 用于管理当前节点所有的变换情况如果本节点不存在额外变换数量为0。</li>
* </ul>
*
* LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TransformMatrix<br>
*/
class SceneMatrix :public VersionData<Matrix4f>
{
protected:
Matrix4f parent_matrix;
Matrix4f local_matrix;
bool local_is_identity;
Vector3f local_normal;
TransformManager transform_manager;
Matrix4f transform_matrix;
protected:
Vector3f OriginWorldPosition; //变换前世界坐标
Vector3f FinalWorldPosition; //变换后世界坐标
Vector3f OriginWorldNormal; //变换前世界法线
Vector3f FinalWorldNormal; //变换后世界法线
protected:
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵
void MakeNewestData(Matrix4f &local_to_world_matrix) override; ///<生成最新的数据(需要派生类重载)
public:
void Clear();
const Matrix4f &GetLocalMatrix()const{return local_matrix;} ///<取得本地矩阵
const Vector3f &GetLocalNormal()const{return local_normal;} ///<取得本地法线
const Matrix4f &GetLocalToWorldMatrix(){return GetNewestVersionData();} ///<取得本地到世界矩阵
const Matrix4f &GetInverseLocalToWorldMatrix(){UpdateNewestData();return inverse_local_to_world_matrix;} ///<取得世界到本地矩阵
const Matrix4f &GetInverseTransposeLocalToWorldMatrix() ///<取得世界到本地矩阵的转置矩阵
{
UpdateNewestData();
return inverse_transpose_local_to_world_matrix;
}
TransformManager &GetTransform(){return transform_manager;} ///<取得变换管理器
const Vector3f &GetWorldPosition()const{return FinalWorldPosition;} ///<取得世界坐标
const Vector3f &GetWorldNormal()const { return FinalWorldNormal; } ///<取得世界法线
public:
SceneMatrix():VersionData(Identity4f){Clear();}
SceneMatrix(SceneMatrix &so);
SceneMatrix(const Matrix4f &mat):VersionData(Identity4f)
{
SetLocalMatrix(mat);
UpdateVersion();
}
void SetLocalNormal(const Vector3f &normal)
{
//if(IsNearlyEqual(local_normal,normal))
if(!hgl_cmp(local_normal,normal))
return;
local_normal=normal;
UpdateVersion();
}
void SetLocalMatrix(const Matrix4f &mat)
{
//if (IsNearlyEqual(local_matrix,mat))
if(!hgl_cmp(local_matrix,mat))
return;
local_matrix=mat;
local_is_identity=IsIdentityMatrix(mat);
UpdateVersion();
}
void SetParentMatrix(const Matrix4f &pm)
{
//if (IsNearlyEqual(parent_matrix,pm))
if(!hgl_cmp(parent_matrix,pm))
return;
parent_matrix=pm;
UpdateVersion();
}
virtual void Update();
};//class SceneMatrix
}//namespace graph
}//namespace hgl

View File

@@ -2,13 +2,16 @@
#define HGL_GRAPH_SCENE_NODE_INCLUDE
#include<hgl/type/ObjectList.h>
#include<hgl/type/IDName.h>
#include<hgl/graph/SceneOrient.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/AABB.h>
namespace hgl
{
namespace graph
{
using SceneNodeID =uint64;
using SceneNodeName =U16IDName;
/**
* 场景节点数据类<br>
* 从场景坐标变换(SceneOrient)类继承,
@@ -16,75 +19,80 @@ namespace hgl
*/
class SceneNode:public SceneOrient ///场景节点类
{
SceneNode *Owner; ///<上级节点
SceneNodeID NodeID; ///<节点ID
SceneNodeName NodeName; ///<节点名称
protected:
AABB BoundingBox; ///<绑定盒
AABB LocalBoundingBox; ///<本地坐标绑定盒
//AABB WorldBoundingBox; ///<世界坐标绑定盒
Vector4f Center; ///<中心点
Vector4f LocalCenter; ///<本地坐标中心点
Vector4f WorldCenter; ///<世界坐标中心点
Renderable *render_obj=nullptr; ///<可渲染实例
protected:
ObjectList<SceneNode> ChildNode; ///<子节点
public:
ObjectList<SceneNode> SubNode; ///<子节点
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
const ObjectList<SceneNode> &GetChildNode()const { return ChildNode; } ///<取得子节点列表
public:
SceneNode()=default;
SceneNode(const SceneNode &)=delete;
SceneNode(const SceneNode *)=delete;
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
SceneNode( Renderable *ri ) {render_obj=ri;}
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
public:
virtual ~SceneNode()=default;
void Clear()
void Clear() override
{
SubNode.Clear();
SceneOrient::Clear();
Owner=nullptr;
BoundingBox.SetZero();
LocalBoundingBox.SetZero();
ChildNode.Clear();
render_obj=nullptr;
}
Renderable *GetRenderable(){return render_obj;}
void SetRenderable(Renderable *);
SceneNode *CreateSubNode()
const bool IsEmpty()const
{
SceneNode *sn=new SceneNode();
if(render_obj)return(false);
if(ChildNode.GetCount())return(false);
SubNode.Add(sn);
return sn;
return(true);
}
SceneNode *CreateSubNode(Renderable *ri)
void SetOwner(SceneNode *sn) {Owner=sn;}
SceneNode * GetOwner() noexcept{return Owner;}
const SceneNode * GetOwner()const noexcept{return Owner;}
void SetRenderable(Renderable *);
Renderable *GetRenderable() noexcept{return render_obj;}
const Renderable *GetRenderable()const noexcept{return render_obj;}
SceneNode *Add(SceneNode *sn)
{
if(!ri)
if(!sn)
return(nullptr);
SceneNode *sn=new SceneNode(ri);
SubNode.Add(sn);
return sn;
}
SceneNode *CreateSubNode(const Matrix4f &mat)
{
SceneNode *sn=new SceneNode(mat);
SubNode.Add(sn);
return sn;
}
SceneNode *CreateSubNode(const Matrix4f &mat,Renderable *ri)
{
if(!ri)
return(nullptr);
SceneNode *sn=new SceneNode(mat,ri);
SubNode.Add(sn);
ChildNode.Add(sn);
sn->SetOwner(this);
return sn;
}
@@ -92,17 +100,15 @@ namespace hgl
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
virtual void RefreshMatrix (const Matrix4f *mat=nullptr); ///<刷新世界变换矩阵
virtual void RefreshMatrix () override; ///<刷新世界变换
virtual void RefreshBoundingBox (); ///<刷新绑定盒
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
virtual const Vector4f & GetCenter ()const{return Center;} ///<取得中心点
virtual const Vector4f & GetLocalCenter ()const{return LocalCenter;} ///<取得本地坐标中心点
virtual const Vector4f & GetWorldCenter ()const{return WorldCenter;} ///<取得世界坐标中心点
};//class SceneNode
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE

View File

@@ -0,0 +1,88 @@
#pragma once
#include<hgl/type/DataType.h>
#include<hgl/graph/ShadowPolicy.h>
namespace hgl
{
namespace graph
{
#pragma pack(push,1)
/**
* 场景节点变换属性<br>
*/
struct SceneNodeTransformAttributes
{
uint moveable:1; ///<可移动
uint rotatable:1; ///<可旋转
uint scalable:1; ///<可缩放
//为什么要 移动、旋转、缩放 三个分开而不是一个整体
// 一、不可移动、不可旋转、不可缩放的通常用于Lightmap等可以完全预计算的东西
// 二、物理引擎对于可缩放是独立支持的,所以缩放要分开
// 三、逻辑处理对移动一般有特别响应,但旋转不一定(也有可能只处理旋转),所以移动和旋转要分开
// 比如RTS中的激光坦克、电磁坦克由于是圆形范围攻击的所以不需要关心旋转属性只需要关心移动属性即可
// 同理,地面雷达,因为是扇形旋转扫描敌人的,所以只关心旋转
// 而士兵、坦克等单位,既需要移动,又需要旋转,但不会缩放
// 再比如风车,它不能移动,但可以旋转。但我们判断是否靠近是否看到,根本不需要关心旋转属性
};
/**
* 场景节点可视属性<br>
*/
struct SceneNodeVisualAttributes
{
uint visible:1; ///<是否可见
uint render_color:1; ///<渲染颜色
uint render_normal:1; ///<渲染法线
uint render_depth:1; ///<渲染深度
uint render_at_reflect:1; ///<在反射时渲染
uint cast_shadow:1; ///<投射阴影
uint cast_static_shadow:1; ///<投射静态阴影(预计算阴影)
uint cast_dynamic_shadow:1; ///<投射动态阴影
uint receive_static_shadow:1; ///<接收静态阴影
uint receive_dynamic_shadow:1; ///<接收动态阴影
uint receive_static_light:1; ///<接收静态光照
uint receive_dynamic_light:1; ///<接收动态光照
ObjectDynamicShadowPolicy dynamic_shadow_policy:8; ///<动态阴影策略
// uint8 light_channels; ///<接收的光通道
};
constexpr const size_t SceneNodeVisualAttributesBytes=sizeof(SceneNodeVisualAttributes);
/**
* 场景节点裁剪属性<br>
*/
struct SceneNodeCullAttribute
{
uint32 min_distance; ///<最小裁剪距离
uint32 max_distance; ///<最大裁剪距离
uint32 min_volume; ///<最小裁剪体积
uint32 max_volume; ///<最大裁剪体积
};
struct SceneNodeAttributes
{
uint editor_only:1; ///<仅编辑器中使用
uint can_tick:1; ///<可被Tick
SceneNodeTransformAttributes transform; ///<变换属性
SceneNodeVisualAttributes visual; ///<可视属性
SceneNodeCullAttribute cull; ///<裁剪属性
};
constexpr const size_t SceneNodeAttributesBytes=sizeof(SceneNodeAttributes);
#pragma pack(pop)
}//namespace graph
}//namespace hgl

View File

@@ -1,47 +1,53 @@
#ifndef HGL_GRAPH_SCENE_ORIENT_INCLUDE
#define HGL_GRAPH_SCENE_ORIENT_INCLUDE
//#include<hgl/type/List.h>
#include<hgl/math/Math.h>
#include<hgl/graph/VK.h>
//#include<hgl/graph/Transform.h>
#include<hgl/graph/SceneMatrix.h>
namespace hgl
{
namespace graph
{
/**
* 方向定位数据基类
* 方向定位数据基类<br>
*/
class SceneOrient ///场景定位类
class SceneOrient ///场景定位类
{
protected:
//ObjectList<Transform> TransformList;
Matrix4f LocalMatrix; ///<当前矩阵
Matrix4f LocalToWorldMatrix; ///<当前到世界矩阵
Matrix4f InverseLocalMatrix; ///<反向当前矩阵
Matrix4f InverseLocalToWorldMatrix; ///<反向当前到世界矩阵
SceneMatrix scene_matrix;
public:
SceneOrient();
SceneOrient(const Matrix4f &mat);
SceneOrient()=default;
SceneOrient(const SceneOrient &);
SceneOrient(const Matrix4f &);
virtual ~SceneOrient()=default;
Matrix4f & SetLocalMatrix (const Matrix4f &); ///<设定当前节点矩阵
Matrix4f & SetLocalToWorldMatrix (const Matrix4f &); ///<设定当前节点到世界矩阵
virtual void Clear()
{
scene_matrix.Clear();
}
const Matrix4f & GetLocalMatrix ()const {return LocalMatrix;}
const Matrix4f & GetLocalToWorldMatrix ()const {return LocalToWorldMatrix;}
const Matrix4f & GetInverseLocalMatrix ()const {return InverseLocalMatrix;}
const Matrix4f & GetInverseLocalToWorldMatrix()const {return InverseLocalToWorldMatrix;}
void SetLocalNormal(const Vector3f &nor) {scene_matrix.SetLocalNormal(nor);} ///<设置本地法线
void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵
void SetParentMatrix(const Matrix4f &mat){scene_matrix.SetParentMatrix(mat);} ///<设置上级到世界空间变换矩阵
public:
virtual void RefreshLocalToWorldMatrix (const Matrix4f *); ///<刷新到世界空间矩阵
const uint32 GetLocalToWorldMatrixVersion()const {return scene_matrix.GetNewestVersion();} ///<取得版本号
const Vector3f & GetWorldPosition() const {return scene_matrix.GetWorldPosition();} ///<取得世界坐标
const Matrix4f & GetLocalMatrix ()const {return scene_matrix.GetLocalMatrix();} ///<取得本地矩阵
TransformManager & GetTransform () {return scene_matrix.GetTransform();} ///<取得变换管理器
const Matrix4f & GetLocalToWorldMatrix () {return scene_matrix.GetLocalToWorldMatrix();} ///<取得本地到世界矩阵
const Matrix4f & GetInverseLocalToWorldMatrix () {return scene_matrix.GetInverseLocalToWorldMatrix();}
const Matrix4f & GetInverseTransposeLocalToWorldMatrix () {return scene_matrix.GetInverseTransposeLocalToWorldMatrix();}
public:
virtual void RefreshMatrix();
};//class SceneOrient
}//namespace graph
}//namespace hgl

View File

@@ -0,0 +1,43 @@
#pragma once
#include<hgl/TypeFunc.h>
namespace hgl
{
namespace graph
{
/**
* 全局动态阴影策略
*/
enum class GlobalDynamicShadowPolicy
{
None, ///<不产生全局动态阴影
Cascade, ///<级联阴影
ParallelSplit, ///<平行分割阴影
Virtual, ///<虚拟阴影
ENUM_CLASS_RANGE(None,Virtual)
};
/**
* 对象动态阴影策略<br>
* 注动态阴影会使用屏幕空间技术不管使用以下何种技术会全部合成到一个屏幕空间shadow map再统一做blur之类的操作
*/
enum class ObjectDynamicShadowPolicy
{
None, ///<不产生动态阴影
Global, ///<使用全局动态阴影
PerObject, ///<独立对象阴影(就是每个物件独立走普通shadowmap得到一张深度图缓存到硬盘)
Plane, ///<压片阴影(极少三角面的片状物体专用)
Capsule, ///<胶囊体阴影(一般用于骨骼动画模型阴影,每根骨骼一个胶囊)
Cube, ///<立方体阴影(一般用于一些建筑物比如楼房直接使用一个Cube做Raymarch)
MeshSDF, ///<模型3D距离场阴影
ENUM_CLASS_RANGE(None,MeshSDF)
};
}//namespace graph
}//namespace hgl

View File

@@ -85,10 +85,16 @@ namespace hgl
protected:
virtual void *OnBegin(uint32)=0;
virtual void *OnBegin(uint32,const VkFormat &)=0;
virtual bool OnEnd()=0;
virtual void OnError(){}
public:
const TextureFileHeader & GetFileHeader ()const{return file_header;}
const VkFormat & GetTextureFormat()const{return format;}
const uint32 GetZeroMipmapBytes()const{return mipmap_zero_total_bytes;}
public:
TextureLoader()

View File

@@ -12,13 +12,15 @@ namespace hgl
{
namespace graph
{
class TextureManager;
/**
* TileData是一种处理大量等同尺寸及格式贴图的管理机制程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注Tile的大小不必符合2次幂)
* Tile的增加或删除程序会自动排序尽可能小的减少I/O消耗。
*/
class TileData ///Tile纹理管理
{
GPUDevice *device;
TextureManager *texture_manager;
protected:
@@ -52,7 +54,7 @@ namespace hgl
public:
TileData(GPUDevice *,Texture2D *,const uint tw,const uint th);
TileData(TextureManager *,Texture2D *,const uint tw,const uint th);
virtual ~TileData();
void BeginCommit();

View File

@@ -1,10 +1,10 @@
#ifndef HGL_GRAPH_VULKAN_INCLUDE
#define HGL_GRAPH_VULKAN_INCLUDE
#pragma once
#include<hgl/type/List.h>
#include<hgl/math/Math.h>
#include<hgl/type/String.h>
#include<hgl/type/Map.h>
#include<hgl/type/IDName.h>
#include<hgl/graph/VKNamespace.h>
#include<hgl/graph/VKFormat.h>
#include<hgl/graph/VKPrimitiveType.h>
@@ -25,6 +25,20 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
DefineIDName(TEXTURE_NAME,char)
DefineIDName(SHADER_NAME,char)
DefineIDName(RENDER_BUFFER_NAME,char)
class TextureManager;
class GraphModule;
class RenderModule;
class GraphModuleManager;
class SwapchainModule;
void RegistryCommonGraphModule();
using BindingMap =Map<AnsiString,int>;
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
@@ -39,6 +53,12 @@ struct Swapchain;
class RenderTarget;
class RTSwapchain;
struct CopyBufferToImageInfo;
struct TextureData;
struct TextureCreateInfo;
struct Image2DRegion;
class Texture;
class Texture1D;
class Texture1DArray;
@@ -70,7 +90,7 @@ class RenderCmdBuffer;
class TextureCmdBuffer;
class RenderPass;
class DeviceRenderPassManage;
class RenderPassManager;
class Fence;
class Semaphore;
@@ -115,6 +135,8 @@ class IndirectDispatchBuffer;
class RenderResource;
class StaticMesh;
enum class SharingMode
{
Exclusive = 0,
@@ -173,4 +195,3 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
e3d.depth =depth;
}
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_INCLUDE

View File

@@ -28,11 +28,11 @@ public:
bool End(){return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);}
#ifdef _DEBUG
void SetDebugName(const UTF8String &);
void BeginRegion(const UTF8String &,const Color4f &);
void SetDebugName(const AnsiString &);
void BeginRegion(const AnsiString &,const Color4f &);
void EndRegion();
#else
void BeginRegion(const UTF8String &,const Color4f &){}
void BeginRegion(const AnsiString &,const Color4f &){}
void EndRegion(){}
#endif//_DEBUG
};//class GPUCmdBuffer

View File

@@ -36,6 +36,7 @@ private:
}
public:
~DebugUtils()=default;
void SetName(VkObjectType,uint64_t,const char *);
@@ -76,10 +77,10 @@ public:
DU_FUNC(DisplayKHR, DISPLAY_KHR)
DU_FUNC(DisplayModeKHR, DISPLAY_MODE_KHR)
DU_FUNC(DebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT)
#ifdef VK_ENABLE_BETA_EXTENSIONS
DU_FUNC(VideoSessionKHR, VIDEO_SESSION_KHR)
DU_FUNC(VideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KH)
#endif//VK_ENABLE_BETA_EXTENSIONS
DU_FUNC(VideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KHR)
DU_FUNC(CuModuleNVX, CU_MODULE_NVX)
DU_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
DU_FUNC(DebugUtilsMessengerEXT, DEBUG_UTILS_MESSENGER_EXT)

View File

@@ -45,7 +45,7 @@ namespace hgl
{
if(name.IsEmpty())return(nullptr);
return GetListObject(ubo_map,name);
return GetObjectFromList(ubo_map,name);
}
void RemoveUBO(DeviceBuffer *buf)
@@ -67,7 +67,7 @@ namespace hgl
{
if(name.IsEmpty())return(nullptr);
return GetListObject(ssbo_map,name);
return GetObjectFromList(ssbo_map,name);
}
void RemoveSSBO(DeviceBuffer *buf)
@@ -89,7 +89,7 @@ namespace hgl
{
if(name.IsEmpty())return(nullptr);
return GetListObject(texture_map,name);
return GetObjectFromList(texture_map,name);
}
void RemoveTexture(Texture *tex)

View File

@@ -4,7 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/type/ObjectList.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
class DeviceBuffer;
@@ -20,7 +20,7 @@ class DescriptorSet
ObjectList<VkDescriptorImageInfo> image_list;
List<VkWriteDescriptorSet> wds_list;
SortedSets<uint32_t> binded_sets;
SortedSet<uint32_t> binded_sets;
bool is_dirty;

View File

@@ -4,8 +4,6 @@
#include<hgl/type/List.h>
#include<hgl/type/String.h>
#include<hgl/type/Map.h>
#include<hgl/type/RectScope.h>
#include<hgl/graph/ImageRegion.h>
#include<hgl/platform/Window.h>
#include<hgl/graph/BitmapData.h>
#include<hgl/graph/font/Font.h>
@@ -18,6 +16,9 @@
#include<hgl/graph/VKDescriptorSetType.h>
VK_NAMESPACE_BEGIN
class SwapchainModule;
class TileData;
class TileFont;
class FontSource;
@@ -30,31 +31,14 @@ struct CopyBufferToImageInfo;
class GPUDevice
{
GPUDeviceAttribute *attr;
DeviceQueue *texture_queue;
TextureCmdBuffer *texture_cmd_buf;
private:
DeviceRenderPassManage *render_pass_manage;
RenderPass *device_render_pass;
RTSwapchain *sc_rt;
RTSwapchain *CreateSwapchainRenderTarget();
void InitRenderPassManage();
void ClearRenderPassManage();
GPUDeviceAttribute *attr;
private:
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
bool CreateSwapchainFBO(Swapchain *);
Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent);
private:
friend class VulkanDeviceCreater;
@@ -79,26 +63,10 @@ public:
const VkColorSpaceKHR GetColorSpace ()const {return attr->surface_format.colorSpace;}
VkQueue GetGraphicsQueue () {return attr->graphics_queue;}
RenderPass * GetRenderPass () {return device_render_pass;}
RTSwapchain * GetSwapchainRT () {return sc_rt;}
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
public:
bool Resize (const VkExtent2D &);
bool Resize (const uint32_t &w,const uint32_t &h)
{
VkExtent2D extent={w,h};
return Resize(extent);
}
public: //内存相关
DeviceMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);
@@ -160,57 +128,6 @@ public: //间接绘制
IndirectDrawIndexedBuffer * CreateIndirectDrawIndexedBuffer(const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
IndirectDispatchBuffer * CreateIndirectDispatchBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
public: //Image
VkImage CreateImage (VkImageCreateInfo *);
void DestroyImage (VkImage);
private: //texture
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);
bool CommitTextureCube (TextureCube *,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
bool CommitTextureCubeMipmaps (TextureCube *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
public: //Texture
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal)const;
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
Texture2D *CreateTexture2D(TextureData *);
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(TextureData *);
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
TextureCube *CreateTextureCube(TextureData *);
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
void Clear(TextureCreateInfo *);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, 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);
@@ -237,24 +154,6 @@ public:
Semaphore * CreateGPUSemaphore();
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
public: //FrameBuffer相关
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *);
public:
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
public:
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class GPUDevice
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE

View File

@@ -24,11 +24,9 @@ struct GPUDeviceAttribute
uint32_t graphics_family =ERROR_FAMILY_INDEX;
uint32_t present_family =ERROR_FAMILY_INDEX;
uint32_t compute_family =ERROR_FAMILY_INDEX;
uint32_t transfer_family =ERROR_FAMILY_INDEX;
uint32_t video_decode_family =ERROR_FAMILY_INDEX;
#ifdef VK_ENABLE_BETA_EXTENSIONS
uint32_t video_encode_family =ERROR_FAMILY_INDEX;
#endif//VK_ENABLE_BETA_EXTENSIONS
VkQueue graphics_queue =VK_NULL_HANDLE;
VkQueue present_queue =VK_NULL_HANDLE;
@@ -39,6 +37,8 @@ struct GPUDeviceAttribute
VkSurfaceTransformFlagBitsKHR preTransform;
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
bool blendOpAdvance =false;
bool uint8_index_type=false;
bool uint32_index_type=false;

View File

@@ -98,6 +98,8 @@ struct VulkanHardwareRequirement
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
SupportLevel blendOperationAdvanced; ///<要求支持高级混合
public:
VulkanHardwareRequirement()
@@ -110,6 +112,10 @@ public:
fullDrawIndexUint8=SupportLevel::Want;
fullDrawIndexUint32=SupportLevel::Want;
blendOperationAdvanced=SupportLevel::Want;
wideLines=SupportLevel::Want;
}
};
@@ -159,7 +165,7 @@ constexpr const VkFormat SwapchainPreferFormatsDepth[]=
PF_D32F_S8U
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
constexpr const VkColorSpaceKHR SwapchainPreferredNonlinearColorSpaces[]=
{
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
@@ -170,7 +176,7 @@ constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
VK_COLOR_SPACE_DISPLAY_NATIVE_AMD,
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesLinear[]=
constexpr const VkColorSpaceKHR SwapchainPreferredLinearColorSpaces[]=
{
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
@@ -225,8 +231,8 @@ constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(
constexpr const PreferFormats PreferHDR {SwapchainPreferFormatsHDR, sizeof(SwapchainPreferFormatsHDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferDepth{SwapchainPreferFormatsDepth, sizeof(SwapchainPreferFormatsDepth )/sizeof(VkFormat)};
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferColorSpacesNonlinear, sizeof(SwapchainPreferColorSpacesNonlinear )/sizeof(VkColorSpaceKHR)};
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferColorSpacesLinear, sizeof(SwapchainPreferColorSpacesLinear )/sizeof(VkColorSpaceKHR)};
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferredNonlinearColorSpaces, sizeof(SwapchainPreferredNonlinearColorSpaces )/sizeof(VkColorSpaceKHR)};
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferredLinearColorSpaces, sizeof(SwapchainPreferredLinearColorSpaces )/sizeof(VkColorSpaceKHR)};
/**
* Vulkan设备创建器<br>
@@ -283,7 +289,7 @@ public:
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr,
const VulkanHardwareRequirement *req =nullptr,
const PreferFormats * spf_color =&PreferSDR,
const PreferColorSpaces * spf_color_space =&PreferNonlinear,
const PreferFormats * spf_depth =&PreferDepth)

View File

@@ -11,14 +11,14 @@ class Framebuffer
VkExtent2D extent;
uint32_t attachment_count;
uint32_t color_count;
uint32_t image_count;
bool has_depth;
private:
friend class GPUDevice;
friend class TextureManager;
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t color_count,bool depth);
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t image_count,bool depth);
public:
@@ -32,7 +32,7 @@ public:
const VkExtent2D & GetExtent ()const{return extent;}
const uint32_t GetAttachmentCount ()const{return attachment_count;} ///<获取渲染目标成分数量
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
const uint32_t GetColorCount ()const{return image_count;} ///<取得颜色成分数量
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
};//class Framebuffer

View File

@@ -90,11 +90,11 @@ VK_NAMESPACE_BEGIN
}
template<typename T>
T *GetDeviceProc(const char *name)
T *GetDeviceProc(VkDevice *dev,const char *name)
{
if(!GetDeviceProcAddr)return(nullptr);
return reinterpret_cast<T>(GetDeviceProcAddr(name));
return reinterpret_cast<T>(GetDeviceProcAddr(dev,name));
}
void DestroySurface(VkSurfaceKHR);

View File

@@ -95,6 +95,6 @@ public:
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
};//class Material
using MaterialSets=SortedSets<Material *>;
using MaterialSets=SortedSet<Material *>;
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE

View File

@@ -7,7 +7,7 @@
VK_NAMESPACE_BEGIN
class MaterialDescriptorManager
{
UTF8String mtl_name;
AnsiString mtl_name;
BindingMapArray binding_map[DESCRIPTOR_SET_TYPE_COUNT];
@@ -19,11 +19,11 @@ private:
public:
MaterialDescriptorManager(const UTF8String &,ShaderDescriptor *,const uint);
MaterialDescriptorManager(const UTF8String &,const ShaderDescriptorSetArray &);
MaterialDescriptorManager(const AnsiString &,ShaderDescriptor *,const uint);
MaterialDescriptorManager(const AnsiString &,const ShaderDescriptorSetArray &);
~MaterialDescriptorManager();
const UTF8String &GetMaterialName()const{return mtl_name;}
const AnsiString &GetMaterialName()const{return mtl_name;}
const uint GetBindCount(const DescriptorSetType &set_type)const
{

View File

@@ -2,7 +2,7 @@
#include<hgl/graph/VK.h>
#include<hgl/type/String.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
class GPUPhysicalDevice
@@ -19,6 +19,7 @@ class GPUPhysicalDevice
VkPhysicalDeviceVulkan11Properties properties11;
VkPhysicalDeviceVulkan12Properties properties12;
VkPhysicalDeviceVulkan13Properties properties13;
VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendOpAdvProperties;
VkPhysicalDeviceMemoryProperties memory_properties;
List<VkLayerProperties> layer_properties;
@@ -29,8 +30,10 @@ private:
bool support_u8_index=false;
bool dynamic_state=false;
public:
bool blendOpAdvanced=false;
public:
const VkPhysicalDeviceFeatures & GetFeatures10 ()const{return features;}
const VkPhysicalDeviceVulkan11Features &GetFeatures11 ()const{return features11;}
@@ -149,6 +152,13 @@ public:
const VkBool32 SupportU32Index ()const{return features.fullDrawIndexUint32;}
const VkBool32 SupportU8Index ()const{return support_u8_index;}
const VkBool32 SupportBlendOpAdvanced ()const{return blendOpAdvanced;}
const VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT *GetBlendOpAdvancedProperties()const
{
return blendOpAdvanced?&blendOpAdvProperties:nullptr;
}
// support != open, so please don't direct use GetFeatures().
// open any features in CreateDevice()&SetDeviceFeatures() functions.
const bool SupportMDI ()const

View File

@@ -6,6 +6,10 @@
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/io/DataOutputStream.h>
VK_NAMESPACE_BEGIN
/**
* 管线<br>
* 管线管理了一批次渲染的所有基础条件,包括顶点输入、着色器、混合、深度测试等等
*/
class Pipeline
{
VkDevice device;
@@ -13,6 +17,8 @@ class Pipeline
AnsiString name;
VkPipeline pipeline;
const VIL *vil;
PipelineData *data;
bool alpha_test;
@@ -22,12 +28,13 @@ private:
friend class RenderPass;
Pipeline(const AnsiString &n,VkDevice dev,VkPipeline p,PipelineData *pd)
Pipeline(const AnsiString &n,VkDevice dev,VkPipeline p,const VIL *v,PipelineData *pd)
{
name=n;
device=dev;
pipeline=p;
vil=v;
data=pd;
alpha_test=false;
@@ -42,6 +49,7 @@ public:
operator VkPipeline(){return pipeline;}
const VIL *GetVIL()const{return vil;}
const PipelineData *GetData()const{return data;}
const bool IsAlphaTest()const{return data->alpha_test>0;}

View File

@@ -29,7 +29,7 @@ protected:
private:
friend class DeviceRenderPassManage;
friend class RenderPassManager;
RenderPass(VkDevice d,VkPipelineCache pc,VkRenderPass rp,const List<VkFormat> &cf,VkFormat df);

View File

@@ -13,6 +13,7 @@
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VKRenderable.h>
#include<hgl/graph/font/TextPrimitive.h>
#include<hgl/graph/mesh/StaticMesh.h>
#include<hgl/type/ObjectManage.h>
#include<hgl/shadergen/MaterialCreateInfo.h>
#include<hgl/graph/VKDescriptorBindingManage.h>
@@ -33,7 +34,7 @@ using DescriptorSetID =int;
using PrimitiveID =int;
using RenderableID =int;
using SamplerID =int;
using TextureID =int;
using StaticMeshID =int;
class VertexAttribData;
@@ -49,7 +50,6 @@ class RenderResource
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
Map<AnsiString,Material *> material_by_name;
Map<OSString,Texture *> texture_by_name;
IDObjectManage<MaterialID, Material> rm_material; ///<材质合集
IDObjectManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
@@ -57,9 +57,10 @@ class RenderResource
IDObjectManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
IDObjectManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
IDObjectManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
IDObjectManage<TextureID, Texture> rm_textures; ///<纹理合集
IDObjectManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
IDObjectManage<StaticMeshID, StaticMesh> rm_static_mesh; ///<静态网格合集
private:
void AddBuffer(const AnsiString &buf_name,DeviceBuffer *buf)
@@ -101,8 +102,8 @@ public: //添加数据到管理器如果指针为nullptr会返回-1
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
TextureID Add(Texture * t ){return rm_textures.Add(t);}
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
StaticMeshID Add(StaticMesh * sm ){return rm_static_mesh.Add(sm);}
public: // VAB/VAO
@@ -154,14 +155,6 @@ public: //Material
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
Sampler * CreateSampler(Texture *);
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);}
@@ -170,8 +163,40 @@ public: //Get
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);}
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
StaticMesh * GetStaticMesh (const StaticMeshID &id){return rm_static_mesh.Get(id);}
public: //Release
void Release(Material * mtl ){rm_material.Release(mtl);}
void Release(MaterialInstance * mi ){rm_material_instance.Release(mi);}
void Release(DescriptorSet * ds ){rm_desc_sets.Release(ds);}
void Release(Primitive * p ){rm_primitives.Release(p);}
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
void Release(Sampler * s ){rm_samplers.Release(s);}
void Release(Renderable * r ){rm_renderables.Release(r);}
void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);}
};//class RenderResource
/**
* 创建一个渲染资源对像<br>
* 这个函数是临时的,以后会被更好的机制替代
*/
template<typename T,typename ...ARGS>
T *CreateRRObject(RenderResource *rr,ARGS...args)
{
if(!rr)
return(nullptr);
T *obj=T::CreateNewObject(rr,args...);
if(!obj)
return(nullptr);
rr->Add(obj);
return obj;
}
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DATABASE_INCLUDE

View File

@@ -8,6 +8,7 @@
#include<hgl/graph/VKQueue.h>
#include<hgl/graph/VKPipeline.h>
VK_NAMESPACE_BEGIN
/**
* 渲染目标
*/
@@ -32,7 +33,7 @@ protected:
protected:
friend class GPUDevice;
friend class TextureManager;
RenderTarget(DeviceQueue *,Semaphore *);
RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
@@ -82,7 +83,7 @@ public:
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->sc_fbo[index];}
const uint32_t GetColorCount ()const override {return 1;}
const uint32_t GetImageCount ()const {return swapchain->color_count;}
const uint32_t GetImageCount ()const {return swapchain->image_count;}
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_color[index];}
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_depth;}
@@ -98,7 +99,7 @@ public:
* 请求下一帧画面的索引
* @param present_complete_semaphore 推送完成信号
*/
int AcquireNextImage();
uint32_t AcquireNextImage();
/**
* 推送后台画面到前台

View File

@@ -12,7 +12,7 @@ VK_NAMESPACE_BEGIN
* 原始图元数据缓冲区<Br>
* 提供在渲染之前的数据绑定信息
*/
struct PrimitiveDataBuffer
struct PrimitiveDataBuffer:public Comparator<PrimitiveDataBuffer>
{
uint32_t vab_count;
VkBuffer * vab_list;
@@ -32,14 +32,14 @@ public:
PrimitiveDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr);
~PrimitiveDataBuffer();
const bool Comp(const PrimitiveDataBuffer *pdb)const;
const int compare(const PrimitiveDataBuffer &pdb)const override;
};//struct PrimitiveDataBuffer
/**
* 原始图元渲染数据<Br>
* 提供在渲染时的数据
*/
struct PrimitiveRenderData
struct PrimitiveRenderData:public ComparatorData<PrimitiveRenderData>
{
//因为要VAB是流式访问所以我们这个结构会被用做排序依据
//也因此把vertex_offset放在最前面
@@ -59,9 +59,6 @@ public:
vertex_offset =vo;
first_index =fi;
}
CompOperatorMemcmp(const PrimitiveRenderData &);
CompOperatorMemcmpPointer(PrimitiveRenderData);
};
/**
@@ -103,6 +100,20 @@ public:
const PrimitiveDataBuffer *GetDataBuffer ()const{return primitive_data_buffer;}
const PrimitiveRenderData *GetRenderData ()const{return primitive_render_data;}
public:
bool ChangeMaterialInstance(MaterialInstance *mi)
{
if(!mi)
return(false);
if(mi->GetMaterial()!=mat_inst->GetMaterial()) //不能换母材质
return(false);
mat_inst=mi;
return(true);
}
};//class Renderable
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);

View File

@@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKVertexInputLayout.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN

View File

@@ -1,5 +1,4 @@
#ifndef HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
#define HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/VKTexture.h>
@@ -10,12 +9,16 @@ struct Swapchain
public:
VkDevice device =VK_NULL_HANDLE;
VkExtent2D extent;
VkExtent2D extent;
VkSurfaceTransformFlagBitsKHR transform;
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
uint32_t color_count =0;
VkSurfaceFormatKHR surface_format;
VkFormat depth_format;
uint32_t image_count =0;
Texture2D ** sc_color =nullptr;
Texture2D * sc_depth =nullptr;
@@ -27,4 +30,3 @@ public:
virtual ~Swapchain();
};//struct Swapchain
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE

View File

@@ -11,15 +11,22 @@ VK_NAMESPACE_BEGIN
BitmapData *LoadBitmapFromFile(const OSString &filename);
using TextureID=int;
class Texture
{
protected:
VkDevice device;
TextureManager *manager;
TextureID texture_id;
TextureData *data;
public:
TextureManager * GetManager () {return manager;}
const TextureID GetID ()const noexcept {return texture_id;}
TextureData * GetData () {return data;}
VkDeviceMemory GetDeviceMemory () {return data?(data->memory?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE):VK_NULL_HANDLE;}
@@ -40,9 +47,10 @@ public:
public:
Texture(VkDevice dev,TextureData *td)
Texture(TextureManager *tm,const TextureID &id,TextureData *td)
{
device=dev;
manager=tm;
texture_id=id;
data=td;
}
@@ -95,7 +103,7 @@ class TextureCube:public Texture
{
public:
TextureCube(VkDevice dev,TextureData *td):Texture(dev,td){}
using Texture::Texture;
~TextureCube()=default;
static VkImageViewType GetImageViewType(){return VK_IMAGE_VIEW_TYPE_CUBE;}

View File

@@ -128,6 +128,7 @@ typedef VABRawMap<uint16> VABMapU16, VABMapUShort;
typedef VABRawMap<uint32> VABMapU32, VABMapUInt;
typedef VABRawMap<float> VABMapFloat;
typedef VABRawMap<double> VABMapDouble;
typedef VABRawMap<half_float> VABMapHalfFloat;
/**
* 顶点属性缓冲区数据访问映射
@@ -216,12 +217,20 @@ public:
typedef VABFormatMap<VB1i8> VABMap1i8 ,VABMap1b;
typedef VABFormatMap<VB1i16> VABMap1i16,VABMap1s;
typedef VABFormatMap<VB1i32> VABMap1i32,VABMap1i;
typedef VABFormatMap<VB1u8> VABMap1u8 ,VABMap1ub;
typedef VABFormatMap<VB1u16> VABMap1u16,VABMap1us;
typedef VABFormatMap<VB1u32> VABMap1u32,VABMap1ui;
typedef VABFormatMap<VB1f> VABMap1f;
typedef VABFormatMap<VB1d> VABMap1d;
typedef VABFormatMap<VB1sf8> VABMap1sf8;
typedef VABFormatMap<VB1uf8> VABMap1uf8;
typedef VABFormatMap<VB1sf16> VABMap1sf16;
typedef VABFormatMap<VB1uf16> VABMap1uf16;
typedef VABFormatMap<VB1hf> VABMap1hf;
typedef VABFormatMap<VB2i8> VABMap2i8 ,VABMap2b;
typedef VABFormatMap<VB2i16> VABMap2i16,VABMap2s;
typedef VABFormatMap<VB2i32> VABMap2i32,VABMap2i;
@@ -231,6 +240,12 @@ typedef VABFormatMap<VB2u32> VABMap2u32,VABMap2ui;
typedef VABFormatMap<VB2f> VABMap2f;
typedef VABFormatMap<VB2d> VABMap2d;
typedef VABFormatMap<VB2sf8> VABMap2sf8;
typedef VABFormatMap<VB2uf8> VABMap2uf8;
typedef VABFormatMap<VB2sf16> VABMap2sf16;
typedef VABFormatMap<VB2uf16> VABMap2uf16;
typedef VABFormatMap<VB2hf> VABMap2hf;
typedef VABFormatMap<VB3i32> VABMap3i32,VABMap3i;
typedef VABFormatMap<VB3u32> VABMap3u32,VABMap3ui;
typedef VABFormatMap<VB3f> VABMap3f;
@@ -245,4 +260,10 @@ typedef VABFormatMap<VB4u32> VABMap4u32,VABMap4ui;
typedef VABFormatMap<VB4f> VABMap4f;
typedef VABFormatMap<VB4d> VABMap4d;
typedef VABFormatMap<VB4sf8> VABMap4sf8;
typedef VABFormatMap<VB4uf8> VABMap4uf8;
typedef VABFormatMap<VB4sf16> VABMap4sf16;
typedef VABFormatMap<VB4uf16> VABMap4uf16;
typedef VABFormatMap<VB4hf> VABMap4hf;
VK_NAMESPACE_END

View File

@@ -171,7 +171,7 @@ namespace hgl
AABB GetAABB()const
{
vec min_point,max_point;
glm::vec4 min_point,max_point;
GetBoundingBox(min_point,max_point);
@@ -264,7 +264,7 @@ namespace hgl
AABB GetAABB()const
{
vec min_point,max_point;
glm::vec4 min_point,max_point;
GetBoundingBox(min_point,max_point);
@@ -462,10 +462,10 @@ namespace hgl
template<typename V>
bool WriteRect(const T left,const T top,const T width,const T height)
{
const vec2<V> lt(left ,top);
const vec2<V> rt(left+width,top);
const vec2<V> rb(left+width,top+height);
const vec2<V> lb(left ,top+height);
const glm::vec<2,V,glm::defaultp> lt(left ,top);
const glm::vec<2,V,glm::defaultp> rt(left+width,top);
const glm::vec<2,V,glm::defaultp> rb(left+width,top+height);
const glm::vec<2,V,glm::defaultp> lb(left ,top+height);
return WriteQuad(lt,rt,rb,lb);
}
@@ -580,7 +580,7 @@ namespace hgl
AABB GetAABB()const
{
vec min_point,max_point;
glm::vec4 min_point,max_point;
GetBoundingBox(min_point,max_point);
@@ -850,7 +850,7 @@ namespace hgl
AABB GetAABB()const
{
vec min_point,max_point;
glm::vec4 min_point,max_point;
GetBoundingBox(min_point,max_point);
@@ -1151,38 +1151,63 @@ namespace hgl
typedef VertexAttribDataAccess1<int8 ,PF_R8I > VB1i8 ,VB1b;
typedef VertexAttribDataAccess1<int16 ,PF_R16I > VB1i16 ,VB1s;
typedef VertexAttribDataAccess1<int32 ,PF_R32I > VB1i32 ,VB1i;
typedef VertexAttribDataAccess1<uint8 ,PF_R8U > VB1u8 ,VB1ub;
typedef VertexAttribDataAccess1<uint8 ,PF_R8U > VB1u8 ,VB1ub; //输入0-255,使用也为0-255
typedef VertexAttribDataAccess1<uint16,PF_R16U > VB1u16 ,VB1us;
typedef VertexAttribDataAccess1<uint32,PF_R32U > VB1u32 ,VB1ui;
typedef VertexAttribDataAccess1<float ,PF_R32F > VB1f;
typedef VertexAttribDataAccess1<double,PF_R64F > VB1d;
typedef VertexAttribDataAccess1<int8 ,PF_R8SN > VB1sf8; //输入-128 to 127,但使用为-1 to +1
typedef VertexAttribDataAccess1<int16 ,PF_R16SN > VB1sf16; //输入-32768 to 32767,但使用为-1 to +1
typedef VertexAttribDataAccess1<uint8 ,PF_R8UN > VB1uf8; //输入0-255,但使用为0-1
typedef VertexAttribDataAccess1<uint16,PF_R16UN > VB1uf16; //输入0-65535,但使用为0-1
typedef VertexAttribDataAccess1<half_float,PF_R16F > VB1hf; //half float
typedef VertexAttribDataAccess2<int8 ,PF_RG8I > VB2i8 ,VB2b;
typedef VertexAttribDataAccess2<int16 ,PF_RG16I > VB2i16 ,VB2s;
typedef VertexAttribDataAccess2<int32 ,PF_RG32I > VB2i32 ,VB2i;
typedef VertexAttribDataAccess2<uint8 ,PF_RG8U > VB2u8 ,VB2ub;
typedef VertexAttribDataAccess2<uint16,PF_RG16U > VB2u16 ,VB2us;
typedef VertexAttribDataAccess2<uint32,PF_RG32U > VB2u32 ,VB2ui;
typedef VertexAttribDataAccess2<float ,PF_RG32F > VB2f;
typedef VertexAttribDataAccess2<double,PF_RG64F > VB2d;
typedef VertexAttribDataAccess1<int8 ,PF_RG8SN > VB2sf8; //输入-128 to 127,但使用为-1 to +1
typedef VertexAttribDataAccess1<int16 ,PF_RG16SN > VB2sf16; //输入-32768 to 32767,但使用为-1 to +1
typedef VertexAttribDataAccess2<uint8 ,PF_RG8UN > VB2uf8; //输入0-255,但使用为0-1
typedef VertexAttribDataAccess2<uint16,PF_RG16UN > VB2uf16; //输入0-65535,但使用为0-1
typedef VertexAttribDataAccess2<half_float,PF_RG16F > VB2hf; //half float
// typedef VertexAttribDataAccess3<int8 ,PF_RGB8I > VB3i8 ,VB3b;
// typedef VertexAttribDataAccess3<int16 ,PF_RGB16I > VB3i16 ,VB3s;
typedef VertexAttribDataAccess3<int32 ,PF_RGB32I > VB3i32 ,VB3i;
// typedef VertexAttribDataAccess3<uint8 ,PF_RGB8U > VB3u8 ,VB3ub;
// typedef VertexAttribDataAccess3<uint16,PF_RGB16U > VB3u16 ,VB3us;
typedef VertexAttribDataAccess3<uint32,PF_RGB32U > VB3u32 ,VB3ui;
typedef VertexAttribDataAccess3<float ,PF_RGB32F > VB3f;
typedef VertexAttribDataAccess3<double,PF_RGB64F > VB3d;
typedef VertexAttribDataAccess4<int8 ,PF_RGBA8I > VB4i8 ,VB4b;
typedef VertexAttribDataAccess4<int16 ,PF_RGBA16I> VB4i16 ,VB4s;
typedef VertexAttribDataAccess4<int32 ,PF_RGBA32I> VB4i32 ,VB4i;
typedef VertexAttribDataAccess4<uint8 ,PF_RGBA8U > VB4u8 ,VB4ub;
typedef VertexAttribDataAccess4<uint8 ,PF_RGBA8UN> VB4uf;
typedef VertexAttribDataAccess4<uint16,PF_RGBA16U> VB4u16 ,VB4us;
typedef VertexAttribDataAccess4<uint32,PF_RGBA32U> VB4u32 ,VB4ui;
typedef VertexAttribDataAccess4<float ,PF_RGBA32F> VB4f;
typedef VertexAttribDataAccess4<double,PF_RGBA64F> VB4d;
typedef VertexAttribDataAccess4<int8 ,PF_RGBA8SN > VB4sf8; //输入-128 to 127,但使用为-1 to +1
typedef VertexAttribDataAccess4<int16 ,PF_RGBA16SN> VB4sf16; //输入-32768 to 32767,但使用为-1 to +1
typedef VertexAttribDataAccess4<uint8 ,PF_RGBA8UN > VB4uf8; //输入0-255,但使用为0-1
typedef VertexAttribDataAccess4<uint16,PF_RGBA16UN> VB4uf16; //输入0-65535,但使用为0-1
typedef VertexAttribDataAccess4<half_float,PF_RGBA16F > VB4hf; //half float
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_VERTEX_ATTRIB_DATA_ACCESS_INCLUDE

View File

@@ -0,0 +1,39 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
enum class WindowMode
{
/**
* 全屏模式是一种独占模式,它会占用整个屏幕,不允许其它程序显示在其上。
* 这种模式下,程序的画面会直接输出到屏幕,不经过桌面合成器,拥有最高效能。
* 但这种模式下,如果频率切换到其它程序,可能会导致屏幕闪烁或是设备丢失,严重会程序崩溃。
*/
FullScreen, ///<全屏模式
/**
* 窗口模式
* 调试时期最常用的模式。画面会输出到一个FBO再经桌面管理器合成整个桌面画面再输出到屏幕。
*/
Windowed, ///<窗口模式
/**
* 无边框窗口模式
* 只不过是去掉了标题框和边框的窗口模式而己,这些东西一般经过窗口管理器或桌面管理器绘制。
*/
Borderless, ///<无边框窗口模式
/**
* 为什么需要有全屏无边框模式?
* 这个模式虽然看起来是全屏的,但其实它只是一个占满屏幕的窗口而己,所以它的画面依然需要经过桌面合成器,才会输出到屏幕。
* 这种模式对于需要频率切换到其它程序而言(比如修改器,或是需要挂机到后台的网游),拥有良好的兼容性。
*/
FullScreenBorderless, ///<全屏无边框模式
ENUM_CLASS_RANGE(FullScreen,FullScreenBorderless)
};//enum class WindowMode
VK_NAMESPACE_END

View File

@@ -0,0 +1,19 @@
#pragma once
#include<hgl/graph/Component.h>
#include<hgl/graph/mesh/StaticMesh.h>
VK_NAMESPACE_BEGIN
class StaticMeshComponentData:public ComponentData
{
StaticMesh *static_mesh;
};//class StaticMeshComponentData:public ComponentData
class StaticMeshComponent:public Component
{
};//class StaticMeshComponent:public Component
VK_NAMESPACE_END

View File

@@ -0,0 +1,147 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
//Material models from Google Filament
//@see https://google.github.io/filament/Materials.html
enum class MaterialModels:uint8
{
Unlit=0,
Lit,
Subsurface,
Cloth,
};
enum class ColorMode
{
Unknow=0,
RGB,
Luminance,
YCbCr,
ENUM_CLASS_RANGE(Unknow,YCbCr)
};
enum class GBufferComponent:uint8
{
ShadingModel=0,
RGB,
Y,
CbCr,
Normal,
Depth,
Stencil,
Metallic,
Roughness,
Specular,
Glosses,
Emissive,
AmbientOcclusion,
Anisotropy,
Reflectance,
ClearCoat,
ClearCoatRoughness,
Opacity,
MotionVector,
WorldPosition,
ENUM_CLASS_RANGE(ShadingModel,WorldPosition)
};
struct GBufferComponentConfig
{
char name[32]; ///<成分名称
VkFormat format;
uint count; ///<成分数量
uint size[4]; ///<成分长度
GBufferComponent components[4]; ///<具体成份(分别对应xyzw四位)
public:
const uint GetComponentSize(const GBufferComponent &c)const noexcept;
};//struct GBufferComponent
constexpr const size_t GBUFFER_MAX_COMPONENTS=16;
/**
* GBuffer格式配置
*/
class GBufferFormat
{
uint count; ///<成分数量
GBufferComponentConfig components_list[GBUFFER_MAX_COMPONENTS]; ///<成分配置
int components_index[size_t(GBufferComponent::RANGE_SIZE)]; ///<成分索引
private:
friend class GPUDevice;
public:
const uint GetCount()const noexcept{return count;} ///<取得成分数量
const GBufferComponentConfig *GetConfig(const int index)const noexcept ///<通过索引取得成分配置
{
return (index<0||index>=count)?nullptr:components_list+index;
}
const VkFormat GetFormatFromComponent(const GBufferComponent &)const noexcept; ///<通过成分取得格式
const ColorMode GetColorMode()const noexcept; ///<取得颜色模式
const bool IsRGB ()const noexcept{return GetColorMode()==ColorMode::RGB;} ///<是否为RGB模式
const bool IsLuminance ()const noexcept{return GetColorMode()==ColorMode::Luminance;} ///<是否为Luminance模式
const bool IsYCbCr ()const noexcept{return GetColorMode()==ColorMode::YCbCr;} ///<是否为YCbCr模式
const uint GetNormalSize()const noexcept; ///<取得法线数据大小
public:
GBufferFormat()
{
count=0;
hgl_zero(components_list);
hgl_set(components_index,-1,size_t(GBufferComponent::RANGE_SIZE));
}
~GBufferFormat()=default;
};//class GBufferFormat
struct InitGBufferColorFormatConfig
{
};
bool InitGBufferFormat(GPUDevice *,GBufferFormat *);
//void InitGBufferFormat(GBufferFormat &bf)
//{
// bf.BaseColor =PF_A2BGR10UN;
//
// bf.Depth =PF_D24UN_S8U;
// bf.Stencil =PF_D24UN_S8U;
//
// bf.Normal =PF_RG8UN;
//
// bf.MetallicRoughness=PF_RG8UN;
//
// bf.Emissive =PF_A2BGR10UN;
// bf.AmbientOcclusion =PF_R8UN;
//
// bf.MotionVector =PF_RG16SN;
//}
VK_NAMESPACE_END

View File

@@ -12,7 +12,7 @@ namespace hgl
/**
* 字体信息
*/
struct Font
struct Font:public ComparatorData<Font>
{
os_char name[MAX_FONT_NAME_LENGTH]; ///<字体名称
@@ -28,8 +28,6 @@ namespace hgl
Font();
Font(const os_char *,int,int,bool b=false,bool i=false,bool=true);
CompOperatorMemcmp(const Font &); ///<比较操作符重载
};//struct Font
}//namespace graph
}//namespace hgl

View File

@@ -3,7 +3,7 @@
#include<hgl/type/StrChar.h>
#include<hgl/type/Map.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
#include<hgl/graph/font/Font.h>
#include<hgl/type/UnicodeBlocks.h>
@@ -71,7 +71,7 @@ namespace hgl
{
protected:
SortedSets<void *> ref_object;
SortedSet<void *> ref_object;
ObjectMap<u32char,CLA> cla_cache;

View File

@@ -24,10 +24,10 @@ namespace hgl
friend class TextLayout;
friend class TextRender;
SortedSets<u32char> chars_sets;
SortedSet<u32char> chars_sets;
const SortedSets<u32char> &GetCharsSets()const{return chars_sets;}
void SetCharsSets(const SortedSets<u32char> &sl){chars_sets=sl;}
const SortedSet<u32char> &GetCharsSets()const{return chars_sets;}
void SetCharsSets(const SortedSet<u32char> &sl){chars_sets=sl;}
void ClearCharsSets(){chars_sets.Clear();}
private:

View File

@@ -54,9 +54,9 @@ namespace hgl
public:
TextPrimitive *CreatePrimitive();
TextPrimitive *CreatePrimitive(const UTF16String &str);
TextPrimitive *CreatePrimitive(const U16String &str);
bool Layout(TextPrimitive *tr,const UTF16String &str);
bool Layout(TextPrimitive *tr,const U16String &str);
Renderable *CreateRenderable(TextPrimitive *text_primitive);

View File

@@ -24,7 +24,7 @@ namespace hgl
TileResPool to_res;
SortedSets<u32char> not_bitmap_chars;
SortedSet<u32char> not_bitmap_chars;
public:
@@ -37,7 +37,7 @@ namespace hgl
TileFont(TileData *td,FontSource *fs);
virtual ~TileFont();
bool Registry(TileUVFloatMap &,SortedSets<u32char> &chars_sets); ///<注册要使用的字符
bool Registry(TileUVFloatMap &,SortedSet<u32char> &chars_sets); ///<注册要使用的字符
void Unregistry(const List<u32char> &); ///<注销要使用的字符
};//class TileFont
}//namespace graph

View File

@@ -0,0 +1,18 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
VK_NAMESPACE_BEGIN
class MaterialManager:public GraphModule
{
public:
GRAPH_MODULE_CONSTRUCT(MaterialManager)
virtual ~MaterialManager();
};//class MaterialManager:public GraphModule
VK_NAMESPACE_END

View File

@@ -1,16 +1,18 @@
#ifndef HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#define HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/module/GraphModule.h>
#include<hgl/type/Map.h>
#include<hgl/util/hash/Hash.h>
VK_NAMESPACE_BEGIN
using RenderPassHASHCode=util::HashCodeSHA1LE;
class DeviceRenderPassManage
using RenderPassHASHCode=util::HashCode<128/8>;
inline util::Hash *CreateRenderPassHash()
{
return util::CreateHash(util::HASH::xxH3_128);
}
class RenderPassManager:public GraphModule
{
VkDevice device;
VkPipelineCache pipeline_cache;
util::Hash *hash;
@@ -21,8 +23,8 @@ private:
friend class GPUDevice;
DeviceRenderPassManage(VkDevice,VkPipelineCache);
~DeviceRenderPassManage();
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
~RenderPassManager();
private:
@@ -31,7 +33,8 @@ private:
const List<VkSubpassDependency> &dependency,
const RenderbufferInfo *);
public:
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
};//class DeviceRenderPassManage
};//class RenderPassManager
VK_NAMESPACE_END
#endif//HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE

View File

@@ -0,0 +1,27 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
VK_NAMESPACE_BEGIN
class RenderTargetManager:public GraphModule
{
public:
GRAPH_MODULE_CONSTRUCT(RenderTargetManager)
virtual ~RenderTargetManager();
public: //FrameBuffer相关
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint image_count,ImageView *depth);
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *);
public:
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
};//class RenderTargetManager
VK_NAMESPACE_END

View File

@@ -0,0 +1,128 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
#include<hgl/type/SortedSet.h>
#include<hgl/type/IDName.h>
#include<hgl/type/RectScope.h>
#include<hgl/type/object/ObjectBaseInfo.h>
#include<hgl/graph/ImageRegion.h>
#include<hgl/graph/VKTexture.h>
VK_NAMESPACE_BEGIN
struct TextureManagerData
{
};
class TextureManager:public GraphModule
{
DeviceQueue *texture_queue=nullptr;
TextureCmdBuffer *texture_cmd_buf=nullptr;
private:
TextureID texture_serial=0;
const TextureID AcquireID(){return texture_serial++;} ///<取得一个新的纹理ID
private:
SortedSet<VkImage> image_set;
SortedSet<Texture *> texture_set; ///<纹理合集
Map<TextureID,Texture *> texture_by_id;
Map<OSString,Texture *> texture_by_filename;
private:
const TextureID Add(Texture *);
const TextureID Add(Texture *,const OSString &);
public:
GRAPH_MODULE_CONSTRUCT(TextureManager)
virtual ~TextureManager();
const VkFormatProperties GetFormatProperties(const VkFormat)const;
public: //Buffer
DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr);
private: //Image
VkImage CreateImage (VkImageCreateInfo *);
void DestroyImage (VkImage);
private: //texture
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);
bool CommitTextureCube (TextureCube *,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
bool CommitTextureCubeMipmaps (TextureCube *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
public: //Format
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal)const;
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
bool CheckColorAttachmentFormatSupport(const VkFormat fmt)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT,ImageTiling::Optimal);}
bool CheckDepthStencilAttachFormatSupport(const VkFormat fmt)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT,ImageTiling::Optimal);}
public: //Create/Chagne
Texture2D *CreateTexture2D(TextureData *);
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(TextureData *);
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
TextureCube *CreateTextureCube(TextureData *);
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
void Clear(TextureCreateInfo *);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,const void *data,const VkDeviceSize 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 *,const void *data,const VkDeviceSize size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
public:
void Release(Texture *);
void Destory(Texture *tex)
{
if(!tex)return;
Release(tex);
delete tex;
}
public: // Load
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 &);
};//class TextureManager
VK_NAMESPACE_END

View File

@@ -0,0 +1,46 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/graph/mesh/StaticMeshLODPolicy.h>
#include<hgl/graph/ShadowPolicy.h>
VK_NAMESPACE_BEGIN
class SceneNode;
class StaticMesh
{
protected:
StaticMeshLODPolicy lod_policy; ///<LOD策略
SceneNode *root_node;
StaticMesh *shadow_proxy_static_mesh; ///<阴影代理静态网格
StaticMesh *physic_proxy_static_mesh; ///<物理代理静态网格
protected:
bool two_side; ///<双面渲染
ObjectDynamicShadowPolicy recommend_dynamic_shadow_policy; ///<动态阴影策略(推荐项,最终可被取代)
public:
const StaticMeshLODPolicy GetLODPolicy()const { return lod_policy; } ///<取得LOD策略
const ObjectDynamicShadowPolicy GetRecommendDynamicShadowPolicy()const { return recommend_dynamic_shadow_policy; } ///<取得推荐的动态阴影策略
public:
StaticMesh(SceneNode *);
virtual ~StaticMesh();
public:
SceneNode *GetScene(){return root_node;}
SceneNode *GetShadowNode() { return shadow_proxy_static_mesh?shadow_proxy_static_mesh->GetScene():root_node; } ///<取得阴影渲染节点
SceneNode *GetPhysicNode() { return physic_proxy_static_mesh?physic_proxy_static_mesh->GetScene():root_node; } ///<取得物理渲染节点
};//class StaticMesh
VK_NAMESPACE_END

View File

@@ -0,0 +1,30 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
/**
* 静态模型LOD策略
*/
enum class StaticMeshLODPolicy:uint8
{
None=0, ///<无LOD
DiscardDetail, ///<丢弃细节
AnotherMesh, ///<另一个模型
Billboard, ///<广告牌
//Voxel, ///<体素
//MeshSDF, ///<网格SDF
//MeshCard, ///<网格卡片
ENUM_CLASS_RANGE(None,Billboard)
};//enum class StaticMeshLODPolicy
VK_NAMESPACE_END

View File

@@ -0,0 +1,17 @@
#pragma once
#include<hgl/graph/SceneNode.h>
VK_NAMESPACE_BEGIN
class StaticMeshNode:public SceneNode
{
StaticMesh *sm;
public:
};//class StaticMeshNode
VK_NAMESPACE_END

View File

@@ -0,0 +1,118 @@
#pragma once
#include<hgl/graph/RenderFramework.h>
#include<initializer_list>
VK_NAMESPACE_BEGIN
class RenderCmdBuffer;
class RenderFramework;
using GraphModuleHashList=std::initializer_list<size_t>;
class GraphModule
{
RenderFramework *render_framework;
AIDName module_name;
bool module_inited;
bool module_enabled;
bool module_ready;
protected:
template<typename T>
T * GetModule(bool create=false){return render_framework->GetModule<T>(create);} ///<获取指定类型的模块
GraphModule * GetModule(const AIDName &name,bool create=false); ///<获取指定名称的模块
protected:
virtual void SetModuleEnabled(bool e){module_enabled=e;}
virtual void SetModuleReady(bool r){module_ready=r;}
public:
GPUDevice * GetDevice () {return render_framework->GetDevice();} ///<取得GPU设备
VkDevice GetVkDevice ()const {return render_framework->GetVkDevice();} ///<取得VkDevice
const GPUPhysicalDevice * GetPhysicalDevice ()const {return render_framework->GetPhysicalDevice();} ///<取得物理设备
GPUDeviceAttribute *GetDeviceAttribute () {return render_framework->GetDeviceAttribute();} ///<取得设备属性
RenderFramework * GetFramework () {return render_framework;} ///<取得渲染框架
const AIDName & GetName ()const {return module_name;} ///<取得模块名称(标准通用的名称比如Upscale供通用模块使用)
virtual const AIDName & GetFullName ()const {return module_name;} ///<取得名称(完整的私有名称比如FSR3Upscale,DLSS3Upscale)
virtual const bool IsPerFrame () {return false;} ///<是否每帧运行
virtual const bool IsRender () {return false;} ///<是否为渲染模块
const bool IsInited ()const {return module_inited;} ///<是否已经初始化
const bool IsEnabled ()const noexcept{return module_enabled;} ///<当前模块是否启用
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
public:
NO_COPY_NO_MOVE(GraphModule)
protected:
GraphModule(RenderFramework *rf,const AIDName &name);
public:
virtual ~GraphModule();
virtual const size_t GetTypeHash()const=0;
static const GraphModuleHashList GetDependentModules(){return {};} ///<取得依赖的模块列表
public: //回调事件
virtual void OnRenderTarget(RenderTarget *){} ///<设置渲染目标
virtual void OnResize(const VkExtent2D &){} ///<窗口大小改变
virtual void OnPreFrame(){} ///<帧绘制前回调
virtual void OnPostFrame(){} ///<帧绘制后回调
};//class GraphModule
using GraphModuleMapByIDName=Map<AIDName,GraphModule *>;
//template<typename T,typename BASE> class GraphModuleInherit:public BASE
//{
//public:
//
// GraphModuleInherit(RenderFramework *rf):BASE(rf,typeid(T))
// {}
//
// static const size_t StaticHash()
// {
// return typeid(T).hash_code();
// }
//
//};//class GraphModuleInherit
#define GRAPH_MODULE_CREATE_FUNC(name) name *name::CreateModule(RenderFramework *rf,GraphModuleMapByIDName &dep_modules)
#define GRAPH_BASE_MODULE_CONSTRUCT(name,base_class) public:\
NO_COPY_NO_MOVE(name) \
static const size_t StaticHash(){return typeid(name).hash_code();} \
const size_t GetTypeHash()const override{return name::StaticHash();} \
static const AIDName &GetModuleName() \
{ \
static const AIDName id_name(#name); \
return id_name; \
} \
\
private: \
name(RenderFramework *rf):base_class(rf,GetModuleName()){} \
\
public: \
static name *CreateModule(RenderFramework *rf,GraphModuleMapByIDName &); \
static const GraphModuleHashList GetDependentModules();
#define GRAPH_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,GraphModule)
#define RENDER_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,RenderModule)
VK_NAMESPACE_END

View File

@@ -0,0 +1,59 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/type/IDName.h>
#include<hgl/graph/module/GraphModule.h>
#include<hgl/graph/RenderFramework.h>
VK_NAMESPACE_BEGIN
class GraphModuleFactory
{
public:
GraphModuleFactory()=default;
virtual ~GraphModuleFactory()=default;
virtual GraphModule *Create(RenderFramework *)=0;
};//class GraphModuleFactory
bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *);
template<typename T> class RegistryGraphModule:public GraphModuleFactory
{
public:
GraphModule *Create(RenderFramework *rf) override
{
if(!rf)
return(nullptr);
Map<AIDName,GraphModule *> dgm_map;
//检查依赖模块
{
const auto &dependent_modules=T::GetDependentModules();
if(!dependent_modules.IsEmpty())
{
for(const AIDName &name:dependent_modules)
{
GraphModule *dgm=rf->GetModule(name,true);
if(!dgm)
return(nullptr);
dgm_map.Add(name,dgm);
}
}
}
T *gm=T::CreateModule(rf,dgm_map);
return(gm);
}
};//template<typename T> class RegistryGraphModule:public GraphModuleFactory
#define REGISTRY_GRAPH_MODULE(Class) {RegistryGraphModuleFactory(#Class,new RegistryGraphModule<Class>);}
VK_NAMESPACE_END

View File

@@ -0,0 +1,56 @@
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/type/IDName.h>
VK_NAMESPACE_BEGIN
class GraphModule;
class GraphModulesMap
{
SortedSet<GraphModule *> gm_set;
Map<AIDName,GraphModule *> gm_map_by_name;
Map<size_t,GraphModule *> gm_map_by_hash;
List<GraphModule *> gm_list; //按创建顺序记录,用于倒序释放
public:
bool Add(GraphModule *gm);
const bool IsEmpty()const
{
return gm_set.IsEmpty();
}
GraphModule *Get(const AIDName &name)
{
GraphModule *gm;
if(gm_map_by_name.Get(name,gm))
return gm;
return nullptr;
}
template<typename T>
T *Get()
{
GraphModule *gm;
return gm_map_by_hash.Get(GetTypeHash<T>(),gm)?(T *)gm:nullptr;
}
template<typename T>
const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());}
const bool IsLoaded(const AIDName &name)const{return gm_map_by_name.ContainsKey(name);}
bool Release(GraphModule *gm); ///<释放一个模块
void Destory(); ///<销毁所有模块
};//class GraphModulesMap
VK_NAMESPACE_END

View File

@@ -0,0 +1,32 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
#include<hgl/type/Size2.h>
VK_NAMESPACE_BEGIN
/**
* 渲染模块基类
*/
class RenderModule:public GraphModule
{
VkExtent2D current_extent;
public:
const bool IsPerFrame ()const noexcept{return true;} ///<每帧运行
const bool IsRender ()const noexcept{return true;} ///<渲染模块
public:
NO_COPY_NO_MOVE(RenderModule)
using GraphModule::GraphModule;
virtual ~RenderModule()=default;
virtual void OnResize(const VkExtent2D &ext)override{current_extent=ext;}
virtual void OnFrameRender(const double,RenderCmdBuffer *)=0; ///<帧绘制回调
};//class RenderModule
VK_NAMESPACE_END

Some files were not shown because too many files have changed in this diff Show More