391 Commits

Author SHA1 Message Date
89b9735f99 improved sample. 2024-03-15 01:38:47 +08:00
7f744d1207 updated test codes. 2024-03-13 00:13:58 +08:00
b9f5c69f85 optimized to get normal in AutoShader 2024-03-12 23:29:38 +08:00
c469fde84a adjusted order of codes in Std2DMaterialLoader.cpp and Std3DMaterialLoader.cpp 2024-03-12 23:29:06 +08:00
dd6b2f4fb3 add "hasInput(const char *name)" in ShaderDescriptorInfo and ShaderCreateInfoVertex classes. 2024-03-12 23:28:23 +08:00
ba8b44659b resume GetNormalMatrix/GetNormal in auto shader. 2024-03-12 23:04:12 +08:00
13b2ca0575 fixed Viewport UBO bug. 2024-03-12 22:54:33 +08:00
9d704eb33d updated comments. 2024-03-12 22:31:58 +08:00
86c3b65a42 fixed -normal bug in InlineGeometry.cpp 2024-03-12 21:53:41 +08:00
f6e61e70ce 更改了specular算法,但是有点问题。。。而且高光区有点象是VS算的一样,怀疑是NORMAL在VS算的原因。但fs没有GetLocalToWorld函数,需要尝试修复。 2024-03-12 00:42:32 +08:00
5347ac7091 specular OK in BlinnPhongDirectionLight sample. but direction error. 2024-03-10 22:45:38 +08:00
f56928d734 Fixed bug about SunLightPureColor.mtl 2024-03-10 01:00:42 +08:00
f3a59c1bb3 test sunlight UBO ok! 2024-03-10 00:35:35 +08:00
5188d4149c added Unknow and Static in DescriptorSetType 2024-03-09 23:35:56 +08:00
d4096735f5 adjusted order of codes in MaterialCreateInfo.h 2024-03-09 23:23:34 +08:00
4fafd938b1 new function, MaterialFileData load UBO OK! to make shader OK. 2024-03-09 22:26:45 +08:00
f0848541c2 added a newly AddUBO() in MaterialCreateInfo 2024-03-09 22:25:03 +08:00
cc9e756ece fixed Load of ubo codes. 2024-03-09 21:23:02 +08:00
cdedc81f9f save codes of UBO in AccumMemoryManager 2024-03-09 20:48:30 +08:00
c229259623 added comments 2024-03-09 19:49:44 +08:00
2c2f11f47e added little safe check of filename in MaterialFileLoader.cpp 2024-03-07 23:04:54 +08:00
c8b3ed0286 preparing blinnphong light sample. added codes of to load ubo. 2024-03-07 13:59:28 +08:00
2ce36ec26c fixed a bug in ShaderCreateInfoVertex.cpp, put "C-style string" in function that it's a bug. 2024-03-07 00:07:49 +08:00
5ba3c1790d removed standalone ".glsl" files ,merge to c++ codes. 2024-03-06 23:24:57 +08:00
3874d771d3 aligned codes, append CreateIBO8 functions in VKRenderResource.h 2024-03-06 22:51:07 +08:00
49eb8f42f0 updated DescriptorBinding::BindUBO, to support dynamic param. 2024-03-06 22:40:51 +08:00
c355f96f9b little codes 2024-03-06 13:54:05 +08:00
dc3d7b7792 removed BindingMapping 2024-03-06 00:29:17 +08:00
5f1c60a24a Improved VKDescriptorBindingManage 2024-03-06 00:26:23 +08:00
ff6a644e8f added BlinnPhong.h 2024-03-04 13:13:33 +08:00
b9e70426a1 removed sun.ubo, next step is UBO in C++ 2024-03-04 13:12:29 +08:00
a7af276a44 updated SunLightPureColor.mtl 2024-03-04 12:58:22 +08:00
8b82c6c25c support the new other codes. 2024-03-02 10:35:27 +08:00
a8d68c295d renamed many values. 2024-02-13 22:27:12 +08:00
f666d5b248 renamed values of BlinnPhongDirectionLight.cpp 2024-02-12 08:23:31 +08:00
55c27a883b init empty BlinnPhongDirectionLight example 2024-02-12 08:20:24 +08:00
6a7f8e7754 fixed access method 2024-02-03 19:53:19 +08:00
1dbf8ae5c7 renamed values. 2023-12-24 01:35:30 +08:00
8dbc1d899c added to Check ubolist in MaterialFileLoader.cpp 2023-12-05 02:24:09 +08:00
d010ee4278 I updated two sub-modules, Platform and Util. 2023-12-05 02:13:21 +08:00
4aeb28c571 added a parse in MaterialFileLoader.cpp that it's UBOParse 2023-12-05 02:08:18 +08:00
775e031422 added VK_LAYER_AMD_switchable_graphics in VKInstance.h/VKProperties.cpp 2023-12-05 02:07:25 +08:00
deefdf1416 used uint instead of int in Size of viewport 2023-11-10 04:24:10 +08:00
ba2d479f05 improved Gizmo3DMove.cpp 2023-11-02 18:51:02 +08:00
b16341c0f9 draw gizmo3d move, next step is mouse to pick the gizmo 2023-11-01 18:37:10 +08:00
d5eeb081e1 removed codes about RenderCmdBuffer::SetLineWidth 2023-11-01 18:36:20 +08:00
4bb66d2746 added "wide_lines" requirment in CreateRenderDevice and VulkanAppFramework 2023-11-01 11:00:55 +08:00
625a7387ae adjusted VulkanHardwareRequirement order in CreateRenderDevice functions. 2023-11-01 10:59:51 +08:00
c4deceebd9 first step for BlinnPhongPureColor 2023-10-31 17:59:12 +08:00
4ed0e281b2 first run MetricCellsGrid OK! 2023-10-13 19:22:11 +08:00
9369ad115b UBO ViewportInfo in All graphics shader. 2023-10-13 19:21:34 +08:00
7788459109 improved and fixed CreatePlane 2023-10-13 19:21:04 +08:00
a58589f01f moved AddBuffer to .h for RenderResource 2023-10-13 10:47:42 +08:00
240b6fb0e3 added UBO/SSBO/INBO debug output. 2023-10-13 10:42:21 +08:00
b72a924853 Merge branch 'devel_27_Default3DMaterial' of http://www.hyzgame.com:3000/hyzboy/ULRE into devel_27_Default3DMaterial 2023-10-13 09:55:20 +08:00
b781ff41a3 removed codes about VkDebugMaker 2023-10-13 02:01:57 +08:00
4ee6962d04 added lot of debug output based VkDebugUtils 2023-10-13 01:48:07 +08:00
7eff39b3b0 draw_triangle_use_UBO support u16 position format and u8 norm color format. 2023-10-12 15:00:39 +08:00
6b13c159d8 added comp operator in MaterialConfig 2023-10-12 14:59:39 +08:00
2f560a28a7 fixed all examples that can RUN OK! 2023-10-12 10:39:43 +08:00
8ba171efda added debug name. 2023-10-12 05:55:39 +08:00
317635877b optimized MaterialRenderList, removed last_vil(pipeline already include vil), don't create assign_buffer if material don't include assign 2023-10-12 02:24:58 +08:00
255c7859f1 optimized DescriptorSets::Update 2023-10-12 01:40:59 +08:00
ae85d3fc66 removed ReverseDirection from CameraMouseControl 2023-10-12 01:39:47 +08:00
a5830e18cb added ReserveDirection 2023-10-11 19:38:12 +08:00
ae88a65315 added newly CreateMaterialInstance that include MIData 2023-10-11 19:14:24 +08:00
77b0266cdc Used SceneAppFramework instead of CameraAppFramework in RayPicking.cpp 2023-10-11 19:06:18 +08:00
c99934fdf9 added RenderResource::LoadMaterial functions, it can't easy CreateMaterial from file. 2023-10-11 19:02:17 +08:00
aa6071a948 added newly files and adjust comments. 2023-10-11 18:50:06 +08:00
6f58475abd added SceneAppFramework, global_descriptor.Bind used auto-mode. 2023-10-11 18:49:29 +08:00
cfed14d746 renamed to require_list instead of require in MaterialFileData 2023-10-11 13:14:34 +08:00
27c409c7fd added To parse "require" of the MaterialBlock in MaterialFileLoader.cpp 2023-10-11 13:12:51 +08:00
bee48890cb optimized codes of MaterialFileLoader.cpp 2023-10-10 19:30:07 +08:00
a2669d2123 adjust class's name in MaterialFileLoader.cpp 2023-10-10 19:21:33 +08:00
737438aaed added Normal.glsl BlinnPhongPureColor.mtl 2023-10-10 19:14:10 +08:00
8a5711154f finished StdMaterialLoader, test all examples ok. 2023-10-10 14:49:33 +08:00
3dd308aff1 added sampler parse in MaterialFileLoader.cpp 2023-10-10 14:46:20 +08:00
bead8128b7 test ok that LoadPureColor2D material from file. 2023-10-10 10:57:29 +08:00
019e9964fa Merge branch 'devel_27_Default3DMaterial' of http://www.hyzgame.com:3000/hyzboy/ULRE into devel_27_Default3DMaterial 2023-10-10 09:49:59 +08:00
7ca81f38e8 Std2DMaterialLoader start ok,,but don't support Sampler2D in material file... 2023-10-10 02:48:02 +08:00
03750832c8 MaterialFileData added origin data. 2023-10-10 01:19:05 +08:00
018a72c09a created MaterialFileData and all material's data in the struct. 2023-10-10 00:24:41 +08:00
55fee1e5d7 renamed few class name; 2023-10-09 21:13:34 +08:00
c5dd359d18 Added Std2DMaterialLoader and Std3DMaterialLoader 2023-10-09 20:57:46 +08:00
85ec666989 used FragColor instead of Color in Fragment shader. 2023-10-09 20:56:56 +08:00
9a5cead33e moved Create to StdMaterial from Std2DMaterial and Std3DMaterial 2023-10-09 20:56:25 +08:00
695f1a22a8 used Block instead of State in MaterialFileLoader.cpp 2023-10-09 18:02:03 +08:00
237c1a469b writed GeometryShaderStateParse, need to test in furture. 2023-10-09 03:15:42 +08:00
5ede824522 MaterialTextParse completed VertexShader/FragmentShader parse. 2023-10-09 02:22:38 +08:00
46781b9627 used "VertexInput" state in .mtl file-format. 2023-10-09 02:21:56 +08:00
aaff0c23c9 improved CodeParse in MaterialFileLoader.cpp 2023-10-09 01:23:06 +08:00
3a3f9d10b7 Parse MaterialInstance filed in MaterialFileLoader.cpp 2023-10-09 01:12:27 +08:00
b6e391762b added MaterialInstanceStateParse 2023-10-08 20:38:54 +08:00
b262fdc645 added MaterialFileLoader.cpp 2023-10-08 20:00:46 +08:00
5e795c4a7f fragment shader output use "FragColor" instead of "Color". 2023-10-08 10:40:01 +08:00
0524c51feb Set Base-class StdMaterial to Std2DMaterial/Std3DMaterial 2023-10-08 10:04:58 +08:00
8dc9846ae8 Merge remote-tracking branch 'github/devel_27_Default3DMaterial' into devel_27_Default3DMaterial 2023-10-07 23:37:20 +08:00
1d866abb48 use List<const char *> instead of AnsiStringList in ShaderCreateInfo::function_list 2023-10-07 23:35:22 +08:00
ece7912f3c removed ShaderCreateInfoFragment::UseDefaultMain 2023-10-07 23:34:36 +08:00
4ef37a430e move Material2DCreateConfig/Material3DCreateConfig 2023-10-07 20:59:44 +08:00
1f91ec94e1 added Std2D/3D material files. 2023-10-07 20:09:16 +08:00
86123827cb moved glsl to standalone .glsl file. 2023-10-07 17:02:00 +08:00
19df201ab5 Added ShaderStage macro in ShaderGen 2023-10-07 16:14:34 +08:00
921d6d157f Update README.md 2023-10-06 23:05:29 +08:00
c0e4128365 Update README.md 2023-10-06 23:03:19 +08:00
8fe5e8dd55 Update README.md 2023-10-06 23:00:09 +08:00
3393a90127 prepare billboard 2023-10-06 22:25:39 +08:00
9b5157594f added MFGetNormal.h 2023-10-05 01:32:00 +08:00
10d4f2f04a fixed RayPicking.cpp, it can RUN ok! 2023-10-05 00:50:31 +08:00
a1e7b105f7 added GetViewportInfo/Buffer in VulkanAppFramework.h 2023-10-05 00:48:38 +08:00
67cf89fef1 improved RenderablePrimitiveCreater 2023-10-05 00:48:00 +08:00
e95cbb28a4 improved PlaneGrid 2023-09-29 02:59:10 +08:00
c9d6774bd3 added SetClearColor(COLOR::MozillaCharcoal) in VulkanApplicationFramework 2023-09-28 18:57:15 +08:00
78946994bb Added VertexLum3D material, test PlaneGrid3D OK! 2023-09-28 18:13:51 +08:00
1a63fa8c76 renamed a func in VertexAttribDataAccess1 2023-09-28 18:12:43 +08:00
db766f33ac fixed PlaneGrid3D example, it RUN OK!!! 2023-09-28 17:44:47 +08:00
3db94948c5 fixed a bug in PrimitiveCreater::Finish 2023-09-28 17:44:20 +08:00
cefea7229d added CreateUBODescriptor 2023-09-28 17:42:14 +08:00
45f50b3bc0 added GetPosition3DCamera/GetPosition3DL2WCamera and to support UBO Camera 2023-09-28 17:41:45 +08:00
dbea7764fb added GetPosition3D in Std3DMaterial 2023-09-28 15:03:34 +08:00
1101bcae9d updated codes with AABB in SceneNode 2023-09-28 15:02:57 +08:00
6c7f9ea9d1 perpare it for VertexColor3D material. 2023-09-27 20:31:46 +08:00
253d113375 adjusted path of examples. 2023-09-27 11:36:39 +08:00
ca1bb80b5f updated M_RectTexture2DArray.cpp 2023-09-26 21:57:03 +08:00
922fc2661b added primitive in Material2DCreateConfig 2023-09-26 21:49:37 +08:00
e9a8e5bbf2 updated texture_quad.cpp 2023-09-26 21:16:00 +08:00
bba00534ba removed DescriptorSetType::MaterialInstance 2023-09-26 14:50:38 +08:00
c15fbf8252 texture_rect_array was run OK! 2023-09-25 21:49:35 +08:00
9a7e711658 LoadTexture2DToArray OK! test ok! 2023-09-25 20:32:12 +08:00
65c3d5cad1 renamed to CreateTexture from GetTexture in TextureLoader<> 2023-09-25 19:49:06 +08:00
7d9192051a added codes about Texture2DArray. 2023-09-25 17:34:36 +08:00
22099b6b84 added CopyBufferToImage2D and use it. 2023-09-25 17:33:59 +08:00
322d24c4ca added GPUDevice::CreateTexture2DArray functions. 2023-09-25 17:01:21 +08:00
5230fbc27f added little codes of texture 2d array, but can't run. 2023-09-25 16:38:02 +08:00
f901708b6c improved codes. 2023-09-25 15:37:41 +08:00
2487cb1f36 added CopyBufferToImage.h 2023-09-25 15:13:30 +08:00
7805494ca9 created a new GPUDevice::CopyBufferToImage(CopyBufferToImageInfo *,..) 2023-09-25 14:44:53 +08:00
ac4c97d33a renamed to CopyBufferToImage from CommitTexture 2023-09-25 12:42:48 +08:00
a87a35b5f8 removed old examples. 2023-09-22 11:32:26 +08:00
d456c2bf92 used DescriptorSetType::MaterialInstance 2023-09-22 01:31:04 +08:00
12e18b517b added MaterialInstance::WriteMIData<>(const T &) 2023-09-22 01:30:44 +08:00
2f00aa8e1e improved codes. 2023-09-22 01:08:32 +08:00
4e144072e4 texture_rect run ok! 2023-09-21 22:11:20 +08:00
907cb3c852 added M_RectTexture2D.cpp 2023-09-21 21:36:55 +08:00
eb51df8dd0 Added few codes of ShaderCreateInfoGeometry 2023-09-21 21:36:37 +08:00
ed9ba3876f added PureTexture2D material and test. 2023-09-21 20:46:08 +08:00
97290ce54c fixed a bug that lost a ; in ShaderCreateInfo::ProcSampler() 2023-09-21 20:45:34 +08:00
bebac2284f used FAN instead of TRIANGLES in texture_quad.cpp 2023-09-21 17:38:02 +08:00
d5d6a6bc74 added example that it's texture_quad.cpp. 2023-09-21 17:15:36 +08:00
5559178e7c fixed a bug about RenderablePrimitiveCreater::SetIBO 2023-09-21 17:15:12 +08:00
f58ce4f98b removed dirty codes 2023-09-21 17:14:49 +08:00
5c2f136689 renamed project's name 2023-09-21 10:09:31 +08:00
6820ee8c74 completed AutoMergeMaterialInstance,test ok. next step is to support texture2d array 2023-09-20 21:53:30 +08:00
ddb5a0b77a use VIL instead of MI in to sort for RenderNode 2023-09-20 18:56:09 +08:00
69646971ce used VIL instead of MI in MaterialRenderList 2023-09-20 17:19:46 +08:00
e71ec4be85 Added few RenderPass::CreatePipeline functions. 2023-09-20 17:15:13 +08:00
dbe2370a44 1.used uvec2/ushort2 in AssignVBO
2.completed first step then merge MI buffer
2023-09-20 15:55:14 +08:00
00d2677066 update RenderAssignBuffer,but can't run. 2023-09-19 22:04:34 +08:00
4208e47534 newly material instance stat,but can't run. 2023-09-19 21:45:54 +08:00
2dedeaad90 layouted codes of VKMaterialInstance.h 2023-09-19 21:45:28 +08:00
083600a95f added mi_max_count in Material 2023-09-19 21:44:48 +08:00
902dc20340 used ActiveMemoryBlockManager to manage data of material instances in Material class. 2023-09-19 21:09:09 +08:00
164498446a fixed crash in RenderAssignBuffer.cpp because not check ubo_mi before use. 2023-09-19 21:07:07 +08:00
cef5ad073b a few update 2023-09-07 18:09:31 +08:00
c2279c553d fixed a spell error in word. 2023-09-06 17:06:12 +08:00
d959e7988d moved few values to VKRenderAssign.h 2023-09-06 16:55:04 +08:00
202bff5870 moved few codes to RenderAssignBuffer.cpp from MaterialRenderList.cpp 2023-09-06 16:24:05 +08:00
8437d8d561 named values and macro about RenderAssignBuffer 2023-09-06 15:57:52 +08:00
714fc3dcb7 use hgl_min in MaterialCreateInfo.cpp 2023-09-05 23:36:59 +08:00
e030738a5f removed old codes of L2W in AssignBuffer 2023-09-05 20:52:55 +08:00
28b2b53d03 renamed to RenderAssignBuffer from RenderExtraBuffer 2023-09-05 20:48:47 +08:00
8bb742f3f4 OK???? 3rd_draw_triangle_use_RenderList run OK!. 2023-09-05 20:19:53 +08:00
6e8932fc2f comments few codes and then start next step. 2023-09-05 10:28:03 +08:00
9661336325 used uint8 color in third_triangle.cpp 2023-08-18 18:39:25 +08:00
ef84e5c699 renamed to RTSwapchain instead of SwapchainRenderTarget 2023-08-17 11:08:21 +08:00
3b106a3b42 updated CMCore, test can Run OK!. 2023-08-15 14:42:08 +08:00
74003df08b updated list/pool/map....,but can't run. 2023-08-14 21:03:20 +08:00
95c67ba857 fixed name of color. 2023-07-29 01:54:01 +08:00
f51c7c6964 optimized Sort() in MaterialRenderList 2023-07-28 20:41:02 +08:00
3fe8d9f90d Merge branch 'new_RenderList' of h 2023-07-28 20:23:46 +08:00
7967150722 upgraded codes and then it can run. 2023-07-28 20:17:46 +08:00
51a6da3d9f update #include, but the codes can't compile. 2023-07-22 12:16:26 +08:00
dd047c1644 added WinVulkan.cpp 2023-07-09 22:32:14 +08:00
df80b1af3b update submodules. 2023-06-21 20:17:12 +08:00
64235b12b6 used AutoDelete<>.Finish() at CreateMaterial. 2023-06-15 16:07:11 +08:00
0557ff2bae added check of brand name 2023-06-14 21:03:30 +08:00
b43d4cc5a3 fixed a bug that error in getting the value of features/properties of vkPhysicalDevice 2023-06-14 20:17:10 +08:00
b72144a28b reordered the creating vkdevice 2023-06-14 19:58:56 +08:00
d05f1109b5 removed MaterialData 2023-06-14 18:20:23 +08:00
3de67f8cf1 updated RenderResource::CreateMaterial 2023-06-14 17:55:06 +08:00
9816592bf6 optimized codes of RenderSource::CreateMaterial 2023-06-14 16:55:22 +08:00
82f3ad070b optimized codes about CreateMaterial 2023-06-14 16:49:19 +08:00
b021b05cb0 renamed values in MaterialCreateInfo::SetMaterialInstance 2023-06-13 18:02:00 +08:00
5749d8ec8a optimized ShaderModuleMapByName in RenderResource 2023-06-12 16:30:16 +08:00
e6560dfe5f renamed values. 2023-06-12 15:45:34 +08:00
8f6260f440 fixed bug at GPUDevice::ChangeTexture2D 2023-06-07 20:25:32 +08:00
18850b0e27 BufferImageCopy supported RectScope2<> 2023-06-07 20:23:13 +08:00
de2926a6d5 standalone GPUDevice::CreateMP 2023-06-06 21:03:13 +08:00
1a8bd0a607 removed GPUDevice::CreateMP(Material *,const DescriptorSetType &) 2023-06-06 20:52:23 +08:00
ffaa6b5362 few about MaterialInstance 2023-06-05 21:39:12 +08:00
9d3ea89861 moved CreateMI to Material from GPUDevice. 2023-06-05 20:17:16 +08:00
7f1532dc6e updated example programs that are second_triangle and third_triangle 2023-06-05 17:10:52 +08:00
01cdb7661b used UTF8String instead of OSString in shader_module_by_name and material_by_name of RenderResource 2023-06-05 17:07:37 +08:00
ab6a8435a1 optimized codes of ShaderCreateInfo::ProcDefine 2023-06-05 17:01:13 +08:00
d17932c7a4 removed source codes about "Load Material file" 2023-06-05 17:00:22 +08:00
f4a8406ad8 support MI_MAX_COUNT in ShaderGen 2023-06-02 20:45:19 +08:00
22bc5f6653 rename params name 2023-06-02 14:23:33 +08:00
fc94ee82b4 layout and renamed value 2023-06-02 14:22:07 +08:00
f8fe0e46d6 added WriteMaterialInstance in RenderExtraBuffer 2023-06-01 21:25:50 +08:00
e076b72f1a splited MaterialRenderList and MaterialRenderMap, RenderExtraBuffer 2023-06-01 15:08:45 +08:00
a04742c347 completed MaterialInstance codes in ShaderGen 2023-06-01 14:47:05 +08:00
1668a0c973 added InitLogger at VulkanAppFramework::Init 2023-06-01 14:46:21 +08:00
e2dd652c3a added few codes about MaterialInstance 2023-05-31 20:14:45 +08:00
a2c3438c58 added main_function value and SetMain function at ShaderCreateInfo class. 2023-05-31 20:14:13 +08:00
5521c53c94 to supported new version of GLSLCompiler.dll 2023-05-31 17:18:14 +08:00
71fd42cfc8 updated VKDeviceCreater.cpp 2023-05-30 17:57:12 +08:00
222ff2961f renamed to AccessVAD from CreateCADA 2023-05-29 21:43:39 +08:00
ed5aac2a9d layout codes. 2023-05-22 21:28:48 +08:00
233523231e Move the ShaderStageBind to the PrimitiveCreate inside, and renamed to PrimitiveVertexBuffer 2023-05-22 21:26:43 +08:00
3523afc6c2 added fourth_triangle.cpp, not ok!!! 2023-05-22 15:29:07 +08:00
6b498d7e91 updated PureColor2D material codes 2023-05-22 14:31:37 +08:00
fa7ecb91ac supported MaterialInstance in ShaderGen module. 2023-05-22 14:30:38 +08:00
d5b719152f removed Material::GetMaterialData() 2023-05-22 14:29:39 +08:00
410a386423 added ShaderDescriptorInfo::AddStruct 2023-05-22 14:29:16 +08:00
641ba4431f changed to UTF8 encode 2023-05-19 22:23:40 +08:00
c485941342 added PureColor2D.cpp 2023-05-19 22:22:55 +08:00
198fe55216 added HandoverMI and GetMI at MFCommon.h 2023-05-19 22:22:30 +08:00
ad7c652cd4 added Interpolation at ShaderCreateInfo 2023-05-19 22:21:49 +08:00
46b6797bce added comments. 2023-05-16 16:56:32 +08:00
c8dbd40333 removed VertexColor2D.h 2023-05-16 15:27:51 +08:00
35844d52bc finished Std2DMaterial and new VertexColor2D, and fixed first_triangle,second_triangle,third_triangle samples. 2023-05-16 15:21:32 +08:00
36d872359e updated README.md 2023-05-16 02:33:19 +08:00
8086fb76f1 fixed a few compile error. 2023-05-16 02:23:45 +08:00
d660691cec added MFGetPosition.h 2023-05-15 22:05:21 +08:00
c5699fd1af 1.splited CoordinateSystem.h, MaterialConfig.h,RenderTargetOutputConfig.h,Material2DConfig.h,StdMaterial.h/.cpp,UBOCommon.h,MFCommon.h
2.adjust namespace.
2023-05-15 21:52:57 +08:00
9316135942 used simply VAT at ShaderCreateInfoVertex.h 2023-05-13 14:59:46 +08:00
8340209697 renamed to JointID/JointWeight instead of BoneID/BoneWeight 2023-05-13 03:14:38 +08:00
aa217c6fc5 added SortedSets<MaterialInstance *> at RenderNode.h/.cpp 2023-05-12 21:37:28 +08:00
d5b69fbe71 removed mi_data from Material 2023-05-12 21:36:52 +08:00
58c62ddb59 renamed two functions that are CreateArrayInUBO and CreateArrayInSSBO 2023-05-12 21:36:17 +08:00
7f3132236f improved MaterialCreateInfo::AddUBO 2023-05-12 20:30:29 +08:00
f8ff6d9cf0 added SBS_MaterialInstance,GetMI at StdMaterial.h 2023-05-12 20:29:27 +08:00
8855f0b880 renamed MaterialID to MaterialInstanceID 2023-05-12 20:28:44 +08:00
254264ac5e moved to .cpp about ChoosePhysicalDevice 2023-05-12 00:32:12 +08:00
9a24aa237d fixed TextureFormat example. 2023-05-12 00:31:20 +08:00
ff184ecd7a added many CreateRenderDevice 2023-05-11 23:40:25 +08:00
81ab733429 added prefer colorspace 2023-05-11 23:33:05 +08:00
05885e443a added VulkanDeviceCreater::ChooseSurfaceFormat 2023-05-11 21:56:07 +08:00
71c543413a fix include 2023-05-11 21:17:06 +08:00
d6d2d337c9 added VKDeviceCreater.h 2023-05-11 21:14:35 +08:00
4ef1283fce added uint8 IndexType 2023-05-11 21:07:26 +08:00
7c4a27771f created VulkanDeviceCreateInfo and added Swapchain prefer formats list. 2023-05-11 00:56:26 +08:00
a97440e1fc renamed to sc_fbo from render_frame 2023-05-11 00:55:44 +08:00
e1cfc1e5b8 created a standalone VKPhysicalDeviceCapsOutput.cpp that from VKDeviceCreater.cpp 2023-05-11 00:54:47 +08:00
2c602e9045 added comments. 2023-05-10 21:58:36 +08:00
f46b1382ee added line_rasterization in VKDevice.h/VKDeviceCreater.cpp 2023-05-10 21:56:32 +08:00
459fb3afc4 added dynamic state check at VKDeviceCreater.cpp 2023-05-10 21:48:26 +08:00
27f33e07cb added "Vulkan hardware requirement" at GPUDevice class. 2023-05-10 21:26:15 +08:00
9c956e1c65 1.added RenderTargetOutputConfig at MaterialCreateInfo.
2.added MaterialInstance's data at MaterialCreateInfo.
2023-05-10 11:26:42 +08:00
004504e027 added comments at VKDeviceMaterial.cpp 2023-05-10 02:32:03 +08:00
7c3d9ecf91 added MIData at Material 2023-05-09 22:03:02 +08:00
3f1b8be5d0 added WIP at MaterialInstance 2023-05-08 22:04:00 +08:00
f3ab0a5608 added AddMaterialID and comments at ShaderCreateInfoVertex.h 2023-05-08 18:24:34 +08:00
8e64816af8 Merge branch 'new_RenderList' of https://github.com/hyzboy/ULRE into new_RenderList 2023-05-08 18:19:15 +08:00
5718b1795f supported material group at MaterialRenderList::Bind 2023-05-08 18:18:34 +08:00
c8cbf020eb updated examples that are first_triangle.cpp and second_triangle.cpp 2023-05-08 09:50:45 +08:00
9535a4486e removed old RenderList 2023-05-07 01:07:26 +08:00
9781e6a9b3 upgraded example/Vulkan/third_triangle.cpp 2023-05-07 00:42:06 +08:00
958183bb29 finished the branch,,,local to world in VertexInputStreaming. 2023-05-06 22:19:50 +08:00
abfc84feff fixed RenderList2D and third_triangle example. 2023-05-06 19:30:08 +08:00
12e64d7ce0 added BindVBO and BindIBO functions at VKCommandBuffer.h/.cpp 2023-05-06 19:29:38 +08:00
34b7937ee2 1.moved IndexBufferData to VK.h from VKPrimitive.h
2.renamed to GetIndexBufferData from GetIndexBuffer of Primitive
2023-05-06 19:28:42 +08:00
2336c7cdf1 optimized names and comment 2023-05-06 10:38:35 +08:00
21201b1695 finished to stat render list,maked buffer list....next step to bind buffer. 2023-05-05 21:12:53 +08:00
2eac17ac61 removed VertexInputDataGroup, Renderable only have basic vertexinputdata 2023-05-05 21:11:39 +08:00
1e03e28f0b updated codes of RenderNode2D/RenderList2D 2023-05-04 22:01:00 +08:00
30c736b7c8 optimized VertexAttribData class 2023-05-04 19:35:09 +08:00
7031270476 VKRenderable and CommandBufferRender supported newly VertexInputLayout 2023-05-04 19:11:18 +08:00
6bdbf87446 PrimitiveCreater supported newly VertexInputLayout 2023-05-04 19:10:22 +08:00
110c141073 ShaderCreateInfoVertex supported VertexInputGroup and VertexInputRate 2023-05-04 19:08:13 +08:00
b9bd4f6c4b renamed a value. 2023-05-02 18:56:55 +08:00
8b0ef244e0 moved VAN to CMSceneGraph from VertexAttribData 2023-04-30 20:42:08 +08:00
c232feb40a temporary to disable the RenderList and RenderNode 2023-04-28 11:10:50 +08:00
db0a8ee256 Created VertexInputData at VKRenderable.h 2023-04-28 11:09:22 +08:00
b26e25df61 newly RenderNode2D/List 2023-04-26 20:52:31 +08:00
cd03ee8211 added RenderNode2D.cpp 2023-04-25 19:18:07 +08:00
48b5479ade first RenderList2D 2023-04-25 18:08:26 +08:00
1ec88c65f8 added comment about memory property in VKDeviceBuffer.cpp 2023-04-25 15:21:23 +08:00
ba6af7a596 renamed to DynamicBufferAccess instead of UBODynamicAccess 2023-04-25 11:43:15 +08:00
d163f914c7 1.added GetRangeSize at VKArrayBuffer
2.renamed to align_size instead of unit_size
2023-04-25 11:36:50 +08:00
0e589e8bcd removed PerObject of DescriptorSetType 2023-04-21 20:27:28 +08:00
011fbdb55d update codes...but can't compile 2023-04-20 21:49:48 +08:00
e488b4c3d3 added half codes. 2023-03-29 21:34:50 +08:00
49f37447d0 added comment at RenderList2D 2023-03-29 21:19:06 +08:00
f280068d50 renamed to InlineDescriptor instead of GlobalDescriptor 2023-03-29 17:27:05 +08:00
137248a274 add lost #include 2023-03-29 16:45:57 +08:00
ec45b977d1 added DescriptorSetType values in AddUBO of MaterialCreateInfo 2023-03-29 16:45:37 +08:00
38f9a2896f optimized codes of VKArrayBuffer 2023-03-29 11:45:15 +08:00
59b02bcb8c optimized VKArrayBuffer 2023-03-28 22:24:22 +08:00
05e96c58ba added VKUBODynamic.h and support from VKArrayBuffer.h 2023-03-28 21:52:08 +08:00
cb09767151 optimized DescriptorBinding::Bind 2023-03-27 12:01:33 +08:00
554220699f added newly functions at MaterialParameters that used index instead of name 2023-03-27 12:00:53 +08:00
3937206fcb upgraded DescriptorBinding 2023-03-27 10:22:55 +08:00
88f23d9a07 Merge branch 'master' of https://github.com/hyzboy/ULRE 2023-03-26 00:04:50 +08:00
15324d9c86 layout codes. 2023-03-26 00:04:31 +08:00
6c3e674d23 used DescriptorBinding in Global Binding 2023-03-25 23:12:08 +08:00
fefdc19674 added GetBindingMap at MaterialDescriptorManager and MaterialParameters 2023-03-25 23:11:43 +08:00
18a4212935 Merge branch 'master' of https://github.com/hyzboy/ULRE 2023-03-25 15:48:09 +08:00
0457d28577 fixed lost of #include 2023-03-25 15:47:08 +08:00
fd39d08fda Update README.md 2023-03-24 22:43:04 +08:00
8e52595123 standalone RenderList2D 2023-03-24 22:14:43 +08:00
19a20411d8 supported SSBAlign in ArrayBuffer 2023-03-24 22:14:05 +08:00
8363275b36 moved codes to .cpp from VKArrayBuffer.h 2023-03-24 20:39:02 +08:00
939bbfeb1f splite RenderNode2D/3D,RenderList2D/3D 2023-03-23 21:43:10 +08:00
f555c77a83 not run. 2023-03-22 21:40:49 +08:00
160ba000d3 want to split RenderList2D/3D 2023-03-22 21:19:23 +08:00
5f830b8d57 changed GPUArrayBuffer to non-template 2023-03-22 21:18:46 +08:00
5d9aab7dda used RenderablePrimitiveCreater and ZeroToOne coordinate system at third_triangle.cpp 2023-03-22 19:41:06 +08:00
cde2d9f86b used AutoDelete<MaterialCreateInfo> instead of delete operator. 2023-03-22 19:39:53 +08:00
d26eb482e7 used DESCRIPTOR_SET_TYPE_COUNT instead of "int(DescriptorSetType::RANGE_SIZE)" 2023-03-22 19:39:03 +08:00
eb8e0a921b used DESCRIPTOR_SET_TYPE_COUNT instead of "(size_t)DescriptorSetType::RANGE_SIZE" 2023-03-22 19:37:48 +08:00
9fd13680d1 used RenderablePrimitiveCreater in second_triangle.cpp 2023-03-22 18:15:45 +08:00
8af96ed4a5 added a test that it's zero2one coordinate system at second_triangle.cpp 2023-03-22 17:56:36 +08:00
57b480754c renamed name of example project 2023-03-22 16:09:11 +08:00
ac42dcdb26 finished auto bound GlobalDescriptor 2023-03-22 15:58:59 +08:00
e1c3b95de7 next work: support 3-way coordinate system in VertexColor2D material. 2023-03-22 02:41:19 +08:00
ee061e4a1a Bind ViewportInfo to Global in VulkanAppFramework 2023-03-22 02:40:26 +08:00
f2c6c24ddf added BindGlobalDescriptor at RenderResource 2023-03-22 02:35:37 +08:00
76f5dcb884 1.added GetDescriptorCount at MaterialParameters
2.renamed to GetBoundCount from GetCount
2023-03-22 02:35:05 +08:00
157c09eff0 added GetBindCount at MaterialDescriptorManager 2023-03-22 02:31:39 +08:00
9f8e63788d used 2d array at binding_map of MaterialDescriptorManager 2023-03-21 22:28:01 +08:00
a7c761e1c5 renamed value. 2023-03-21 21:46:16 +08:00
44620abc21 added SetGlobal/GetGlobal/Free at RenderResource 2023-03-21 21:37:03 +08:00
8bf1ad2a46 added a standard material that it's VertexColor2DNDC. 2023-03-21 21:01:16 +08:00
d26cae0086 removed shadergen namespace 2023-03-21 18:05:48 +08:00
bc9fc9b50f fixed a bug that it don't Add(mtl) at RenderResource::CreateMaterial(MaterialCreateInfo *) 2023-03-21 18:05:27 +08:00
fb4c8ed8c2 removed SPVParseData 2023-03-21 18:04:26 +08:00
0dae30fa06 updated first_triangle.cpp 2023-03-21 14:37:51 +08:00
48b5a978b8 added a newly RenderResource::CreateMaterialInstance(MaterialCreateInfo *,...) 2023-03-21 14:36:48 +08:00
694add27ae first tested ok that AutoMaterial in first_triangle example. 2023-03-21 14:17:33 +08:00
251bbd2705 added "all_dslb=nullptr" at construct function of MaterialDescriptorManager. 2023-03-21 14:16:48 +08:00
3bfc31b57f added a safe check at ~PipelineLayoutData() 2023-03-21 14:15:58 +08:00
8c8a218a3a added GetCount() at MaterialDescriptorInfo class. 2023-03-21 14:15:33 +08:00
9302cbc3ef finished write codes of CreateMaterial from MaterialCreateInfo 2023-03-20 22:09:37 +08:00
696d3259aa renamed to ChangeOrAdd from Update at Map template. 2023-03-20 16:20:32 +08:00
85530e6d57 renamed to MaterialDescriptorManager from MaterialDescriptorSets 2023-03-20 13:55:47 +08:00
81e2aac321 optimized MaterialDescriptorSets 2023-03-20 13:51:25 +08:00
35a282ef5e used DESCRIPTOR_SET_TYPE_COUNT 2023-03-20 13:35:04 +08:00
3a378be660 removed sd_list for MaterialDescriptorSets 2023-03-19 20:41:12 +08:00
aed56a35e0 use GetSPVData/GetSPVSize instead of GetCode/GetCodeSize 2023-03-19 20:23:54 +08:00
09277924f1 comment sd_list_by_set_type array and GetDescriptorList function at MaterialDescriptorSets 2023-03-19 20:18:56 +08:00
c4a4ec5ebc used "uint32_t *" for SPVDATA 2023-03-19 20:18:10 +08:00
703d444cbb added GetInput at ShaderCreateInfoVertex 2023-03-19 20:17:27 +08:00
159c808dad added GetCode/GetCodeSize at ShaderCreateInfo 2023-03-19 20:17:02 +08:00
facdec5556 1.removed VertexShaderModule
2.added VertexInput at MaterialData
3.newly CreateShaderModule/CreateMaterial functions at GPUDevice/RenderResource class.
2023-03-19 19:41:21 +08:00
42f63c5ef1 renamed few values at VKShaderModule 2023-03-19 13:37:55 +08:00
5f4dd09f92 updated ShaderStage 2023-03-18 21:07:21 +08:00
9872f74160 used short funcname. 2023-03-18 17:58:57 +08:00
529d6b7939 used newly ShaderAttributeArray 2023-03-17 21:06:05 +08:00
f748301787 split standalone VKUUID.h/DebugOutProperties.h 2023-03-17 18:15:55 +08:00
165f9d2a5f rename and layout. 2023-03-17 16:21:12 +08:00
4de8139936 reanmed to ShaderAttribute instead of ShaderStage 2023-03-17 16:06:11 +08:00
9ee5f0adaa renamed files of shadergen 2023-03-17 10:14:07 +08:00
555e8fc066 renamed many source of ShaderGen 2023-03-17 10:08:41 +08:00
f564f55e7b added StandardMaterial 2023-03-16 21:54:03 +08:00
31b5bb6d4f added VertexColor2DMaterial at MaterialCreaterTest.cpp 2023-03-15 17:50:33 +08:00
5ba705cd6b updated layout of codes 2023-03-15 14:55:10 +08:00
9cfb88235a fixed a bug that Illegal class copy used 2023-03-15 11:53:13 +08:00
eceaf9ba68 layout codes. 2023-03-15 11:32:38 +08:00
14e7074b3f used ShaderDescriptorManager * instead of ShaderDescriptorManager 2023-03-15 11:09:51 +08:00
f79599b1d4 updated shadergen 2023-03-14 22:22:35 +08:00
2cc0dca050 renamed many values. 2023-03-13 21:58:27 +08:00
ece7fa5f32 writed ProcSubpassInput,ProcStruct,ProcUBO,ProcConst,ProcSampler at ShaderCreater 2023-03-10 02:15:26 +08:00
68b24903bb Added ProcOutput() at ShaderCreaterFragment 2023-03-10 01:47:01 +08:00
6ee832c39f updated ShaderGen->ShaderCreater. 2023-03-09 23:21:52 +08:00
26f7c915c8 update Input/Output 2023-03-08 21:41:57 +08:00
2ac91b80ac added GLSLCompiler.cpp/.h 2023-03-08 14:02:51 +08:00
eed16928e9 optmized layout of shadergen 2023-03-06 21:30:32 +08:00
6b8e76b75f split codes of ShaderGen 2023-03-06 14:06:20 +08:00
ca36b4454b optimized comments 2023-03-04 18:42:25 +08:00
ba65d1abf2 renamed to PerMaterial instead of PerMaterialInstance 2023-03-04 18:21:03 +08:00
ef8f630056 1.define VAT
2.renamed to UBOStruct instead of UBOCodes.
3.moved AddInput/AddOutput to ShaderCreater from VertexShaderCreater
4.moved descriptor object to MDM from SDM
2023-03-04 16:57:50 +08:00
7a0acaf63e 1.moved descriptor to MaterialDescriptorManager from ShaderDescriptorManager.
2.added UBOCodes in MaterialDescriptorManager
2023-03-04 05:11:51 +08:00
d54aff2a42 first added codes of ShaderGen 2023-03-03 23:02:40 +08:00
84d0dc99c8 moved codes of about camera to CameraAppFramework. 2023-03-02 20:33:44 +08:00
b4dccf7814 use standalone DescriptorSetType,ShaderDescriptor,ShaderStage 2023-03-02 20:19:25 +08:00
f2d5209681 used VulkanFormat::BaseType instead of VulkanNumberType 2023-03-01 15:39:20 +08:00
0abe38de98 LoadMaterial use ConstBufferReader 2023-02-23 19:01:01 +08:00
6536b715c3 added comment. 2023-02-23 17:58:08 +08:00
26b907f611 updated CMSceneGraph 2023-02-23 16:14:31 +08:00
99939bd83d optimized CreatePipeline of RenderPass class 2023-02-23 14:43:57 +08:00
244 changed files with 11902 additions and 4075 deletions

2
CMCore

Submodule CMCore updated: ac5931ce26...2f93a1bb00

2
CMUtil

Submodule CMUtil updated: 9f94d5082b...953ecf8079

View File

@@ -24,6 +24,7 @@ SET(ULRE CMCore
CMSceneGraph
CMUtil
ULRE.Util
ULRE.ShaderGen
ULRE.SceneGraph
${HGL_GLM_LIB}
${RENDER_LIBRARY}

BIN
GLSLCompiler.dll Normal file

Binary file not shown.

View File

@@ -1,17 +1,33 @@
# ULRE
experiment project - Ultra Light Rendering Engine
experiment project - Ultra Lightweight Rendering Engine
ULRE is a project of experimental nature,Used to experiment with various rendering related techniques,And do some examples.
ULRE is a project of an experimental nature. Used to experiment with various rendering-related techniques And do some examples.
In the future, its compilicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
In the future, its complicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
Platform: Windows,Linux (WIP: Android)
Platform: Windows, Linux (WIP: Android, macOS, iOS)
Graphics API: Vulkan
Milestone:
2. Texture2DArray was integrated into material instances.
Multiple render instances of the same model use different material instances and textures but are still merged into one render.
Although the changes this time are small, they are more significant.
1. a test was completed, and the entire scene was drawn with only one DrawCall.
Although it still has a lot of unfinished work, it is still a significant milestone.
#
ULRE是一个试验性质的工程用于试验各种渲染相关的技术以及做一些范例。在未来它的复杂化版本会被整合到CMGameEngine中用于替代旧的渲染引擎。
平台: Windows,Linux (开发中: Android)
平台: Windows, Linux (开发中: Android, macOS, iOS)
图形API: Vulkan
里程碑:
2. Texture2DArray集成在材质实例中。同一个模型的多个渲染实例使用不同的材质实例以及不同的纹理
但它们依然被合并成一次渲染。这次的改变虽小,但意义更为重大。
1. 完成了一个测试只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作但它依然是一个非常重要的里程碑。

View File

@@ -0,0 +1,11 @@
mat4 GetJointMatrix()
{
// Joint数据分Joint ID和Joint Weight两部分
// Joint ID是一个uvec4在shader中为整数。在C++端可使用RGBA8UI或是RGBA16UI来传递。
// Joint Weight是权重在shader中为浮点。在C++端使用RGBA8或RGBA4来传递。
return joint.mats[JointID.x]*JointWeight.x+
joint.mats[JointID.y]*JointWeight.y+
joint.mats[JointID.z]*JointWeight.z+
joint.mats[JointID.w]*JointWeight.w;
}

View File

@@ -0,0 +1,9 @@
mat3 GetNormalMatrix()
{
return mat3(camera.view*GetLocalToWorld());
}
vec3 GetNormal(mat3 normal_matrix,vec3 normal)
{
return normalize(normal_matrix*normal);
}

View File

@@ -0,0 +1,38 @@
#Material
Name PureColor2D
Base Std2D
#MaterialInstance
Length 16
Stage Fragment
Code
{
vec4 Color;
}
#Vertex
Code
{
void main()
{
HandoverMI();
gl_Position=GetPosition2D();
}
}
#Fragment
Output
{
vec4 FragColor
}
Code
{
void main()
{
MaterialInstance mi=GetMI();
FragColor=mi.Color;
}
}

View File

@@ -0,0 +1,39 @@
#Material
Name PureTexture2D
Base Std2D
#VertexInput
vec2 TexCoord
#Vertex
Output
{
vec2 TexCoord
}
Code
{
void main()
{
Output.TexCoord=TexCoord;
gl_Position=GetPosition2D();
}
}
#Fragment
sampler2D TextureColor
Output
{
vec4 FragColor;
}
Code
{
void main()
{
FragColor=texture(TextureColor,Input.TexCoord);
}
}

View File

@@ -0,0 +1,68 @@
#Material
Name RectTexture2D
Base Std2D
Prim SolidRectangles,WireRectangles
#VertexInput
vec4 TexCoord
#Vertex
Output
{
vec4 TexCoord
}
Code
{
void main()
{
Output.TexCoord=TexCoord;
gl_Position=GetPosition2D();
}
}
#Geometry
in points
out triangle_strip,4
Output
{
vec2 TexCoord
}
Code
{
void main()
{
vec2 vlt=gl_in[0].gl_Position.xy;
vec2 vrb=gl_in[0].gl_Position.zw;
vec2 tlt=Input[0].TexCoord.xy;
vec2 trb=Input[0].TexCoord.zw;
gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
EndPrimitive();
}
}
#Fragment
sampler2D TextureColor
Output
{
vec4 FragColor;
}
Code
{
void main()
{
FragColor=texture(TextureColor,Input.TexCoord);
}
}

View File

@@ -0,0 +1,79 @@
#Material
Name RectTexture2DArray
Base Std2D
Prim SolidRectangles,WireRectangles
#MaterialInstance
Length 16
Stage Fragment
Code
{
uvec4 id;
}
#VertexInput
vec4 TexCoord
#Vertex
Output
{
vec4 TexCoord
}
Code
{
void main()
{
HandoverMI();
Output.TexCoord=TexCoord;
gl_Position=GetPosition2D();
}
}
#Geometry
in points
out triangle_strip,4
Output
{
vec2 TexCoord
}
Code
{
void main()
{
vec2 vlt=gl_in[0].gl_Position.xy;
vec2 vrb=gl_in[0].gl_Position.zw;
vec2 tlt=Input[0].TexCoord.xy;
vec2 trb=Input[0].TexCoord.zw;
HandoverMI();gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
HandoverMI();gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
HandoverMI();gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
HandoverMI();gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
EndPrimitive();
}
}
#Fragment
sampler2DArray TextureColor
Output
{
vec4 FragColor;
}
Code
{
void main()
{
MaterialInstance mi=GetMI();
FragColor=texture(TextureColor,vec3(Input.TexCoord,mi.id.x));
}
}

View File

@@ -0,0 +1,37 @@
#Material
Name VertexColor2D
Base Std2D
#VertexInput
vec4 Color
#Vertex
Output
{
vec4 Color
}
Code
{
void main()
{
Output.Color=Color;
gl_Position=GetPosition2D();
}
}
#Fragment
Output
{
vec4 FragColor
}
Code
{
void main()
{
FragColor=Input.Color;
}
}

View File

@@ -0,0 +1,2 @@
vec4 direction;
vec4 color;

View File

@@ -0,0 +1,92 @@
#Material
Name BlinnPhong+HalfLambert shading model only color
Reference https://zhuanlan.zhihu.com/p/442023993
Base Std3D/BlinnPhong
//某些Require并不真的存在.ubo文件写成一行一个是为了方便未来改成带路径的
Require LocalToWorld
Require Camera
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
UBO
{
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始没有则表示同一目录
Struct BlinnPhongSun //结构名称
Name sun //在代码中的变量名
Stage Fragment //会引用的shader
Set Global //Descriptor Set
}
#MaterialInstance
Length 16
Stage Fragment
Code
{
vec3 Color;
float Gloss;
}
#VertexInput
vec3 Normal
#Vertex
Output
{
vec4 Position;
vec3 Normal;
}
Code
{
void main()
{
Output.Normal =GetNormal();
Output.Position =GetPosition3D();
HandoverMI();
gl_Position =Output.Position;
}
}
#Fragment
Output
{
vec4 FragColor;
}
Code
{
#define HAVE_SPECULAR
void main()
{
MaterialInstance mi=GetMI();
//点乘法线和光照
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
//直接光颜色
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb;
#ifndef HAVE_SPECULAR
FragColor=vec4(direct_color,1.0);
#else
vec3 spec_color=vec3(0.0);
if(intensity>0.0)
{
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
float specular=max(dot(half_vector,Input.Normal),0.0);
spec_color=specular*pow(specular,mi.Gloss)*sun.color.rgb;
}
FragColor=vec4(direct_color+spec_color,1.0);
#endif//HAVE_SPECULAR
}
}

View File

@@ -0,0 +1,87 @@
#Material
Name MetricCellsGrid
Base Std3D
Reference https://www.shadertoy.com/view/wdSXzm
#VertexInput
vec2 TexCoord
#MaterialInstance
Length 120
Stage Fragment
Code
{
vec4 x_color;
vec4 y_color;
vec4 x_axis_color;
vec4 y_axis_color;
vec4 center_color;
vec2 lum; //x=0.1 sub cell line,y=0.2 big cell line
vec2 cell_step;
vec2 big_cell_step;
vec2 scale;
float axis_line_width;
float center_radius;
}
#Vertex
Output
{
vec2 TexCoord
}
Code
{
void main()
{
HandoverMI();
Output.TexCoord=TexCoord;
gl_Position=GetPosition3D();
}
}
#Fragment
Output
{
vec4 FragColor;
}
Code
{
void main()
{
MaterialInstance mi=GetMI();
float edge=viewport.inv_viewport_resolution.y;
float x=(Input.TexCoord.x-0.5)*mi.scale.x;
float y=(Input.TexCoord.y-0.5)*mi.scale.y;
vec4 color=vec4(0,0,0,1);
// ======= Lines + Bold lines
color.xyz += step(1.0 - 1.0 / mi.cell_step.x, fract(x / mi.cell_step.x )) * mi.x_color.rgb * mi.lum.x;
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.x, fract(x / mi.big_cell_step.x)) * mi.x_color.rgb * mi.lum.y;
color.xyz += step(1.0 - 1.0 / mi.cell_step.y, fract(y / mi.cell_step.y )) * mi.y_color.rgb * mi.lum.x;
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.y, fract(y / mi.big_cell_step.y)) * mi.y_color.rgb * mi.lum.y;
// ======= AXES
float xb = step(abs(x) - mi.axis_line_width, 0.0);
float yb = step(abs(y) - mi.axis_line_width, 0.0);
color.rgb = mix(color.rgb, mi.x_axis_color.rgb, (xb));
color.rgb = mix(color.rgb, mi.y_axis_color.rgb, (yb));
// ======= CENTER
float cb = length(vec2(x,y))-mi.center_radius;
color.rgb = mix(color.rgb, mi.center_color.rgb, cb>0.0?0.0:smoothstep(0,edge*mi.scale.y,abs(cb)));
FragColor=color;
}
}

View File

@@ -0,0 +1,38 @@
#Material
Name PureColor3D
Base Std3D
#MaterialInstance
Length 16
Stage Fragment
Code
{
vec4 Color;
}
#Vertex
Code
{
void main()
{
HandoverMI();
gl_Position=GetPosition3D();
}
}
#Fragment
Output
{
vec4 FragColor;
}
Code
{
void main()
{
MaterialInstance mi=GetMI();
FragColor=mi.Color;
}
}

View File

@@ -0,0 +1,38 @@
#Material
Name VertexColor3D
Base Std3D
#VertexInput
vec4 Color
#Vertex
Output
{
vec4 Color
}
Code
{
void main()
{
Output.Color=Color;
gl_Position=GetPosition3D();
}
}
#Fragment
Output
{
vec4 FragColor;
}
Code
{
void main()
{
FragColor=Input.Color;
}
}

View File

@@ -0,0 +1,47 @@
#Material
Name VertexLum3D
Base Std3D
#MaterialInstance
Length 16
Stage Vertex
Code
{
vec4 Color;
}
#VertexInput
float Luminance
#Vertex
Output
{
vec4 Color
}
Code
{
void main()
{
MaterialInstance mi=GetMI();
Output.Color=Luminance*mi.Color;
gl_Position=GetPosition3D();
}
}
#Fragment
Output
{
vec4 FragColor;
}
Code
{
void main()
{
FragColor=Input.Color;
}
}

BIN
doc/BlenderGizmo/Move.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

BIN
doc/BlenderGizmo/Rotate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

BIN
doc/BlenderGizmo/Scale.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

BIN
doc/Gizmo.odg Normal file

Binary file not shown.

View File

@@ -37,9 +37,9 @@ private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_color_material =nullptr;
DeviceBuffer * ubo_line_config =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_color_material =nullptr;
DeviceBuffer * ubo_line_config =nullptr;
Pipeline * pipeline =nullptr;
@@ -143,7 +143,7 @@ public:
return(true);
}
void Resize(int w,int h)override
void Resize(uint w,uint h)override
{
cam.width=w;
cam.height=h;

View File

@@ -165,7 +165,7 @@ public:
return(true);
}
void Resize(int w,int h)override
void Resize(uint w,uint h)override
{
cam.width=w;
cam.height=h;

View File

@@ -0,0 +1,16 @@
macro(CreateProject name)
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
target_link_libraries(${name} ${ULRE})
IF(MSVC)
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
ENDIF()
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
endmacro()
CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
CreateProject(03_auto_instance auto_instance.cpp)
CreateProject(04_auto_merge_material_instance auto_merge_material_instance.cpp)

View File

@@ -1,29 +1,32 @@
// second_triangle
// 该范例主要演示使用场景树系统绘制三角形
// 该范例主要演示使用RenderList系统绘制多个三角形并利用RenderList进行排序以及自动合并进行Instance渲染
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/graph/RenderList.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t SCREEN_WIDTH=1024;
constexpr uint32_t SCREEN_HEIGHT=1024;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT][2]=
constexpr float position_data[VERTEX_COUNT*2]=
{
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75},
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75}
0.0, 0.0,
-0.1, 0.9,
0.1, 0.9
};
constexpr float color_data[VERTEX_COUNT][4]=
{ {1,0,0,1},
{0,1,0,1},
{0,0,1,1}
constexpr uint8 color_data[VERTEX_COUNT][4]=
{ {255,0,0,255},
{0,255,0,255},
{0,0,255,255}
};
class TestApp:public VulkanApplicationFramework
@@ -42,37 +45,48 @@ private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
VILConfig vil_config;
vil_config.Add(VAN::Color,VF_V4UN8);
material_instance=db->CreateMaterialInstance(mci,&vil_config);
}
if(!material_instance)
return(false);
BindCameraUBO(material_instance);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
render_obj=rpc.Create(material_instance,pipeline);
if(!render_obj)
return(false);
render_root.CreateSubNode(render_obj);
for(uint i=0;i<12;i++)
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
render_root.RefreshMatrix();
render_list->Expend(GetCameraInfo(),&render_root);
render_list->Expend(&render_root);
return(true);
}
@@ -102,7 +116,7 @@ public:
return(true);
}
void Resize(int w,int h)override
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);

View File

@@ -0,0 +1,151 @@
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形并依赖RenderList中的自动合并功能让同一材质下所有不同材质实例的对象一次渲染完成。
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/graph/RenderList.h>
#include<hgl/color/Color.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1024;
constexpr uint32_t SCREEN_HEIGHT=1024;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT*2]=
{
0.0, 0.0,
-0.1, 0.9,
0.1, 0.9
};
constexpr uint DRAW_OBJECT_COUNT=12;
#define USE_MATERIAL_FILE true //是否使用材质文件
class TestApp:public VulkanApplicationFramework
{
private:
SceneNode render_root;
RenderList * render_list =nullptr;
Material * material =nullptr;
struct
{
MaterialInstance * mi;
Renderable * r;
}render_obj[DRAW_OBJECT_COUNT]{};
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;
#ifndef USE_MATERIAL_FILE
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg); //走程序内置材质创建函数
material=db->CreateMaterial(mci);
#else
material=db->LoadMaterial("Std2D/PureColor2D",&cfg); //走材质文件加载
#endif//USE_MATERIAL_FILE
if(!material)
return(false);
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
{
render_obj[i].mi=db->CreateMaterialInstance(material);
if(!render_obj[i].mi)
return(false);
Color4f color=GetColor4f((COLOR)(i+int(COLOR::Blue)),1.0);
render_obj[i].mi->WriteMIData(color); //设置MaterialInstance的数据
}
}
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Triangles);
return pipeline;
}
bool InitVBOAndRenderList()
{
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
{
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
if(!render_obj[i].r)
return(false);
render_root.CreateSubNode(rotate(deg2rad(360/DRAW_OBJECT_COUNT*i),Vector3f(0,0,1)),render_obj[i].r);
}
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitMaterial())
return(false);
if(!InitVBOAndRenderList())
return(false);
BuildCommandBuffer(render_list);
return(true);
}
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_list);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -1,12 +1,13 @@
// first_triangle
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
@@ -61,6 +62,10 @@ class TestApp:public VulkanApplicationFramework
{
private:
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
VILConfig vil_config;
#endif
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
@@ -68,11 +73,8 @@ private:
private:
bool InitMaterial()
void InitVIL()
{
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
VILConfig vil_config;
#ifdef USE_HALF_FLOAT_POSITION
vil_config.Add(VAN::Position,PositionFormat);
#endif//USE_HALF_FLOAT_POSITION
@@ -80,24 +82,33 @@ private:
#ifdef USE_UNORM8_COLOR
vil_config.Add(VAN::Color,ColorFormat);
#endif//USE_HALF_FLOAT_POSITION
}
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"),&vil_config);
#else
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
#endif//
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
if(!material_instance)
return(false);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
material_instance=db->CreateMaterialInstance(mci,&vil_config);
return material_instance;
}
bool InitPipeline()
{
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
return pipeline;
}
bool InitVBO()
{
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
#ifdef USE_HALF_FLOAT_POSITION
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
@@ -117,7 +128,12 @@ public:
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitMaterial())
InitVIL();
if(!InitAutoMaterial())
return(false);
if(!InitPipeline())
return(false);
if(!InitVBO())
@@ -129,7 +145,7 @@ public:
return(true);
}
void Resize(int w,int h)override
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);

View File

@@ -0,0 +1,134 @@
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t VERTEX_COUNT=3;
static float position_data_float[VERTEX_COUNT][2]=
{
{0.5, 0.25},
{0.75, 0.75},
{0.25, 0.75}
};
static uint16 position_data_u16[VERTEX_COUNT][2]={};
constexpr uint8 color_data[VERTEX_COUNT*4]=
{
255,0,0,255,
0,255,0,255,
0,0,255,255
};
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
class TestApp:public VulkanApplicationFramework
{
private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
VILConfig vil_config;
#ifdef USE_ZERO2ONE_COORD
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
#else
cfg.coordinate_system=CoordinateSystem2D::Ortho;
cfg.position_format =VAT_UVEC2; //这里指定shader中使用uvec2当做顶点输入格式
// ^
// + 这上下两种格式要配套,否则会出错
// v
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VBO中使用RG16U当做顶点数据格式
#endif//USE_ZERO2ONE_COORD
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VBO中使用RGBA8UNorm当做颜色数据格式
cfg.local_to_world=false;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
material_instance=db->CreateMaterialInstance(mci,&vil_config);
if(!material_instance)
return(false);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data_float ))return(false);
#else //使用ortho坐标系
if(!rpc.SetVBO(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
#endif//USE_ZERO2ONE_COORD
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
render_obj=rpc.Create(material_instance,pipeline);
return(true);
}
public:
bool Init(uint w,uint h)
{
if(!VulkanApplicationFramework::Init(w,h))
return(false);
#ifndef USE_ZERO2ONE_COORD
for(uint i=0;i<VERTEX_COUNT;i++)
{
position_data_u16[i][0]=position_data_float[i][0]*w;
position_data_u16[i][1]=position_data_float[i][1]*h;
}
#endif//
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
if(!BuildCommandBuffer(render_obj))
return(false);
return(true);
}
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
RunApp<TestApp>(1280,720);
}

View File

@@ -2,6 +2,23 @@
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
add_subdirectory(Basic)
add_subdirectory(Texture)
add_subdirectory(LightBasic)
add_subdirectory(Gizmo)
add_subdirectory(Vulkan)
add_subdirectory(2dVector)
add_subdirectory(GUI)
macro(CreateProject name)
add_executable(${name} ${ARGN})
target_link_libraries(${name} ${ULRE})
IF(WIN32)
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
ENDIF()
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example")
endmacro()

View File

@@ -0,0 +1,30 @@
// Blender axis
/**
* 0 1 2 3 4 5 6 7
* 0+---------->>>> X
* 1|
* 2|
* 3| +--+
* 4| +--+
* 5|
* 6V
* 7V
*
* 坐标轴参考Blender设计
*
* 单方向坐标轴长度为8
* 最终箭头长度为2
*
* 负责2D平移的方块尺寸为1位置在3-4
*
*/
/**
* 缩放工具
*/
class GizmoScale
{
public:
};//class GizmoScale

View File

@@ -0,0 +1,19 @@
macro(CreateProject name)
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
target_link_libraries(${name} ${ULRE})
IF(MSVC)
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
ENDIF()
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
endmacro()
CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
CreateProject(02_RayPicking RayPicking.cpp)
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
CreateProject(04_Gizmo3DMove Gizmo3DMove.cpp Gizmo.h Gizmo.cpp)
#CreateProject(03_BlenderAxis BlenderAxis.cpp)

0
example/Gizmo/Gizmo.cpp Normal file
View File

16
example/Gizmo/Gizmo.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class Gizmo
{
Material * material;
MaterialInstance * mi;
Pipeline * pipeline;
Primitive * primitive;
};//class Gizmo
VK_NAMESPACE_END

View File

@@ -0,0 +1,228 @@
// Gizmo 3D Move
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
static Color4f white_color(1,1,1,1);
static Color4f yellow_color(1,1,0,1);
class TestApp:public SceneAppFramework
{
Color4f color;
DeviceBuffer *ubo_color=nullptr;
private:
Material * mtl_vtx_lum =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
Pipeline * pipeline_vtx_lum =nullptr;
Primitive * prim_plane_grid =nullptr;
Material * mtl_vtx_color =nullptr;
MaterialInstance * mi_line =nullptr;
Pipeline * pipeline_vtx_color =nullptr;
Primitive * ro_line =nullptr;
private:
bool InitMaterialAndPipeline()
{
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
cfg.local_to_world=true;
mtl_vtx_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_vtx_lum)return(false);
mi_plane_grid=db->CreateMaterialInstance(mtl_vtx_lum,nullptr,&white_color);
if(!mi_plane_grid)return(false);
pipeline_vtx_lum=CreatePipeline(mtl_vtx_lum,InlinePipeline::Solid3D,Prim::Lines);
if(!pipeline_vtx_lum)
return(false);
}
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
cfg.local_to_world=true;
mtl_vtx_color=db->LoadMaterial("Std3D/VertexColor3D",&cfg);
if(!mtl_vtx_color)return(false);
mi_line=db->CreateMaterialInstance(mtl_vtx_color);
if(!mi_line)return(false);
{
const PipelineData *ipd=GetPipelineData(InlinePipeline::Solid3D);
if(!ipd)
return(false);
PipelineData *pd=new PipelineData(ipd);
pd->SetLineWidth(2);
pipeline_vtx_color=CreatePipeline(mtl_vtx_color,pd,Prim::Lines);
delete pd;
if(!pipeline_vtx_color)
return(false);
}
}
return(true);
}
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
{
Renderable *ri=db->CreateRenderable(r,mi,p);
if(!ri)
{
LOG_ERROR(OS_TEXT("Create Renderable failed."));
return(nullptr);
}
render_root.CreateSubNode(ri);
return ri;
}
/**
* д<><D0B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
*
* \param pos Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
* \param max_line <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* \param oa1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
* \param oa2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>
*/
void WriteAxisPosition(Vector3f *pos,const Vector3f &max_line,const Vector3f &oa1,const Vector3f &oa2)
{
constexpr const float AXIS_LENGTH =4;
constexpr const float AXIS_MIN_STEP =1;
constexpr const float AXIS_ARROW_SIZE=0.25;
const Vector3f end_pos =max_line*AXIS_LENGTH; ///<<3C><><EFBFBD>յ<EFBFBD>λ<EFBFBD><CEBB>
const Vector3f cross_pos=max_line*AXIS_MIN_STEP; ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
const Vector3f arrow_pos=max_line*(AXIS_LENGTH-AXIS_MIN_STEP); ///<<3C><>ͷĩ<CDB7><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>λ<EFBFBD><CEBB>
//<2F><><EFBFBD><EFBFBD>
pos[0]=Vector3f(0, 0, 0);
pos[1]=end_pos;
//<2F>ĸ<EFBFBD><C4B8><EFBFBD>ͷ<EFBFBD><CDB7>
pos[2]=end_pos;
pos[3]=arrow_pos-oa1*AXIS_ARROW_SIZE;
pos[4]=end_pos;
pos[5]=arrow_pos+oa1*AXIS_ARROW_SIZE;
pos[6]=end_pos;
pos[7]=arrow_pos-oa2*AXIS_ARROW_SIZE;
pos[8]=end_pos;
pos[9]=arrow_pos+oa2*AXIS_ARROW_SIZE;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pos[10]=cross_pos;
pos[11]=cross_pos+oa1*AXIS_MIN_STEP;
pos[12]=cross_pos;
pos[13]=cross_pos+oa2*AXIS_MIN_STEP;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
{
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.5;
pgci.sub_lum=0.75;
prim_plane_grid=CreatePlaneGrid(db,mtl_vtx_lum->GetDefaultVIL(),&pgci);
}
{
constexpr const uint AXIS_MAX_LINES =7;
constexpr const uint AXIS_MAX_VERTICES =AXIS_MAX_LINES*2*3;
ro_line=db->CreatePrimitive("Line",AXIS_MAX_VERTICES);
if(!ro_line)return(false);
Vector3f position_data[3][AXIS_MAX_LINES*2];
WriteAxisPosition(position_data[0],Vector3f(1,0,0),Vector3f(0,1,0),Vector3f(0,0,1));
WriteAxisPosition(position_data[1],Vector3f(0,1,0),Vector3f(1,0,0),Vector3f(0,0,1));
WriteAxisPosition(position_data[2],Vector3f(0,0,1),Vector3f(1,0,0),Vector3f(0,1,0));
Color4f color_data[3][AXIS_MAX_LINES*2];
for(Color4f &c:color_data[0])c=Color4f(1,0,0,1);
for(Color4f &c:color_data[1])c=Color4f(0,1,0,1);
for(Color4f &c:color_data[2])c=Color4f(0,0,1,1);
if(!ro_line->Set(VAN::Position, db->CreateVBO(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
}
return(true);
}
bool InitScene()
{
Add(prim_plane_grid,mi_plane_grid,pipeline_vtx_lum);
Add(ro_line,mi_line,pipeline_vtx_color);
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint w,uint h) override
{
if(!SceneAppFramework::Init(w,h))
return(false);
if(!InitMaterialAndPipeline())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}

View File

@@ -0,0 +1,142 @@
// Metric Cells Grid
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
struct MetricCellsGridData
{
Color4f x_color;
Color4f y_color;
Color4f x_axis_color;
Color4f y_axis_color;
Color4f center_color;
Vector2f lum;
Vector2f cell_step;
Vector2f big_cell_step;
Vector2f scale;
float axis_line_width;
float center_radius;
};
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
constexpr const float PLANE_SIZE=1024;
class TestApp:public SceneAppFramework
{
private:
MetricCellsGridData mcg_data;
Material * material =nullptr;
Pipeline * pipeline =nullptr;
Primitive * ro_plane =nullptr;
MaterialInstance * material_instance =nullptr;
private:
bool InitMDP()
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"MetricCellsGrid",Prim::Fan);
cfg.local_to_world=true;
material=db->LoadMaterial("Std3D/MetricCellsGrid",&cfg);
if(!material)return(false);
{
mcg_data.x_color=Color4f(1,1,1,1);
mcg_data.y_color=Color4f(1,1,1,1);
mcg_data.x_axis_color=GetColor4f(COLOR::BlenderAxisRed, 1.0);
mcg_data.y_axis_color=GetColor4f(COLOR::BlenderAxisGreen, 1.0);
mcg_data.center_color=Color4f(1,1,0,1);
mcg_data.lum =Vector2f(0.1,0.2);
mcg_data.cell_step =Vector2f(8,8);
mcg_data.big_cell_step =Vector2f(32,32);
mcg_data.scale =Vector2f(PLANE_SIZE,PLANE_SIZE);
mcg_data.axis_line_width=1.0;
mcg_data.center_radius =4.0;
}
material_instance=db->CreateMaterialInstance(material,nullptr,&mcg_data);
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Fan);
return pipeline;
}
bool CreateRenderObject()
{
ro_plane=inline_geometry::CreatePlane(db,material->GetDefaultVIL());
return ro_plane;
}
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
{
Renderable *ri=db->CreateRenderable(ro_plane,mi,pipeline);
if(!ri)
return(nullptr);
render_root.CreateSubNode(mat,ri);
return ri;
}
bool InitScene()
{
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
camera->pos=Vector3f(PLANE_SIZE/2,PLANE_SIZE/2,PLANE_SIZE/4);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
// camera_control->SetReserveDirection(true,true); //反转x,y
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint width,uint height) override
{
if(!SceneAppFramework::Init(width,height))
return(false);
if(!InitMDP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}

View File

@@ -0,0 +1,123 @@
// PlaneGrid3D
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
class TestApp:public SceneAppFramework
{
private:
Material * material =nullptr;
Pipeline * pipeline =nullptr;
Primitive * prim_plane_grid =nullptr;
MaterialInstance * material_instance[3]{};
private:
bool InitMDP()
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
cfg.local_to_world=true;
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!material)return(false);
Color4f GridColor;
COLOR ce=COLOR::BlenderAxisRed;
for(uint i=0;i<3;i++)
{
GridColor=GetColor4f(ce,1.0);
material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor);
ce=COLOR((int)ce+1);
}
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
return pipeline;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.75;
pgci.sub_lum=1.0;
prim_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
return prim_plane_grid;
}
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
{
Renderable *ri=db->CreateRenderable(prim_plane_grid,mi,pipeline);
if(!ri)
return(nullptr);
render_root.CreateSubNode(mat,ri);
return ri;
}
bool InitScene()
{
Add(material_instance[0],Matrix4f(1.0f));
Add(material_instance[1],rotate(HGL_RAD_90,0,1,0));
Add(material_instance[2],rotate(HGL_RAD_90,1,0,0));
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
// camera_control->SetReserveDirection(true,true); //反转x,y
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint width,uint height) override
{
if(!SceneAppFramework::Init(width,height))
return(false);
if(!InitMDP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}

View File

@@ -0,0 +1,168 @@
// RayPicking
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/Ray.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
static float position_data[2][3]=
{
{100,100,100},
{0,0,0}
};
static float lumiance_data[2]={1,1};
static Color4f white_color(1,1,1,1);
static Color4f yellow_color(1,1,0,1);
class TestApp:public SceneAppFramework
{
Color4f color;
DeviceBuffer *ubo_color=nullptr;
private:
Material * material =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
MaterialInstance * mi_line =nullptr;
Pipeline * pipeline =nullptr;
Primitive * prim_plane_grid =nullptr;
Primitive * ro_line =nullptr;
VBO * vbo_pos =nullptr;
Ray ray;
private:
bool InitMaterialAndPipeline()
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
cfg.local_to_world=true;
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!material)return(false);
mi_plane_grid=db->CreateMaterialInstance(material,nullptr,&white_color);
if(!mi_plane_grid)return(false);
mi_line=db->CreateMaterialInstance(material,nullptr,&yellow_color);
if(!mi_line)return(false);
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
if(!pipeline)
return(false);
return(true);
}
Renderable *Add(Primitive *r,MaterialInstance *mi)
{
Renderable *ri=db->CreateRenderable(r,mi,pipeline);
if(!ri)
{
LOG_ERROR(OS_TEXT("Create Renderable failed."));
return(nullptr);
}
render_root.CreateSubNode(ri);
return ri;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
{
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.5;
pgci.sub_lum=0.75;
prim_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
}
{
ro_line=db->CreatePrimitive("Line",2);
if(!ro_line)return(false);
if(!ro_line->Set(VAN::Position, vbo_pos= db->CreateVBO(VF_V3F,2,position_data )))return(false);
if(!ro_line->Set(VAN::Luminance, db->CreateVBO(VF_V1F,2,lumiance_data )))return(false);
}
return(true);
}
bool InitScene()
{
Add(prim_plane_grid,mi_plane_grid);
Add(ro_line,mi_line);
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint w,uint h)
{
if(!SceneAppFramework::Init(w,h))
return(false);
if(!InitMaterialAndPipeline())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
void BuildCommandBuffer(uint32 index) override
{
const CameraInfo &ci=GetCameraInfo();
const ViewportInfo &vi=GetViewportInfo();
ray.Set(GetMouseCoord(),&ci,&vi); //设置射线查询的屏幕坐标点
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
SceneAppFramework::BuildCommandBuffer(index);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}

View File

@@ -0,0 +1,217 @@
// BlinnPhong direction light
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/Ray.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/mtl/BlinnPhong.h>
using namespace hgl;
using namespace hgl::graph;
static float lumiance_data[2]={1,1};
static Color4f white_color(1,1,1,1);
static mtl::blinnphong::SunLight sun_light=
{
Vector4f(1,1,1,0), //direction
Vector4f(1,0.95,0.9,1) //color
};
class TestApp:public SceneAppFramework
{
private: //plane grid
Material * mtl_vertex_lum =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
Pipeline * p_line =nullptr;
Primitive * prim_plane_grid =nullptr;
private:
DeviceBuffer * ubo_sun =nullptr;
private: //sphere
Material * mtl_blinnphong =nullptr;
MaterialInstance * mi_blinnphong =nullptr;
Pipeline * p_blinnphong =nullptr;
Primitive * prim_sphere =nullptr;
Primitive * prim_cone =nullptr;
Primitive * prim_cylinder =nullptr;
private:
bool InitVertexLumMP()
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
cfg.local_to_world=true;
mtl_vertex_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_vertex_lum)return(false);
mi_plane_grid=db->CreateMaterialInstance(mtl_vertex_lum,nullptr,&white_color);
if(!mi_plane_grid)return(false);
p_line=CreatePipeline(mtl_vertex_lum,InlinePipeline::Solid3D,Prim::Lines);
if(!p_line)
return(false);
return(true);
}
bool CreateBlinnPhongUBO()
{
ubo_sun=db->CreateUBO("sun",sizeof(sun_light),&sun_light);
if(!ubo_sun)return(false);
return(true);
}
bool InitBlinnPhongSunLightMP()
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",Prim::Triangles);
cfg.local_to_world=true;
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColor",&cfg);
if(!mtl_blinnphong)return(false);
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
mtl_blinnphong->Update();
float mi_data[4]=
{
1,0,0, //color
4 //gloss
};
mi_blinnphong=db->CreateMaterialInstance(mtl_blinnphong,nullptr,&mi_data);
if(!mi_blinnphong)return(false);
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,Prim::Triangles);
if(!p_blinnphong)
return(false);
return(true);
}
bool CreateRenderObject()
{
using namespace inline_geometry;
//Plane Grid
{
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.5;
pgci.sub_lum=0.75;
prim_plane_grid=CreatePlaneGrid(db,mtl_vertex_lum->GetDefaultVIL(),&pgci);
}
//Sphere
prim_sphere=CreateSphere(db,mi_blinnphong->GetVIL(),16);
//Cone
{
struct ConeCreateInfo cci;
cci.radius =1; //圆锥半径
cci.halfExtend =1; //圆锤一半高度
cci.numberSlices=16; //圆锥底部分割数
cci.numberStacks=8; //圆锥高度分割数
prim_cone=CreateCone(db,mi_blinnphong->GetVIL(),&cci);
}
//Cyliner
{
struct CylinderCreateInfo cci;
cci.halfExtend =4; //圆柱一半高度
cci.numberSlices=16; //圆柱底部分割数
cci.radius =0.25f; //圆柱半径
prim_cylinder=CreateCylinder(db,mi_blinnphong->GetVIL(),&cci);
}
return(true);
}
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat)
{
Renderable *ri=db->CreateRenderable(r,mi,p);
if(!ri)
{
LOG_ERROR(OS_TEXT("Create Renderable failed."));
return(nullptr);
}
render_root.CreateSubNode(mat,ri);
return ri;
}
bool InitScene()
{
Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
Add(prim_sphere, mi_blinnphong,p_blinnphong,translate(Vector3f(0,0,2)));
Add(prim_cone, mi_blinnphong,p_blinnphong,Identity4f);
Add(prim_cylinder, mi_blinnphong,p_blinnphong,translate(Vector3f(0,0,-5)));
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint w,uint h)
{
if(!SceneAppFramework::Init(w,h))
return(false);
if(!InitVertexLumMP())
return(false);
if(!CreateBlinnPhongUBO())
return(false);
if(!InitBlinnPhongSunLightMP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}

View File

@@ -0,0 +1,13 @@
macro(CreateProject name)
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
target_link_libraries(${name} ${ULRE})
IF(MSVC)
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
ENDIF()
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Light Basic")
endmacro()
CreateProject(01_BlinnPhongDirectionLight BlinnPhongDirectionLight.cpp)

View File

@@ -0,0 +1,16 @@
macro(CreateProject name)
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
target_link_libraries(${name} ${ULRE})
IF(MSVC)
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
ENDIF()
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Texture")
endmacro()
CreateProject(05_texture_format texture_format_list.cpp)
CreateProject(06_texture_quad texture_quad.cpp)
CreateProject(07_texture_rect texture_rect.cpp)
CreateProject(08_texture_rect_array texture_rect_array.cpp)

View File

@@ -1,4 +1,5 @@
#include<iostream>
#include<iomanip>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKInstance.h>
@@ -86,35 +87,36 @@ int main(int,char **)
for(uint32_t i=0;i<count;i++)
{
std::cout<<i<<". ";
std::cout<<std::setw(4)<<i<<". ";
std::cout<<" Format [ID:"<<vf->format<<"]["<<vf->name<<"] ";
std::cout<<"Format [ID:"<<std::setw(10)<<vf->format<<"]["<<std::setw(16)<<vf->name<<"]";
if(vf->compress_type!=TextureCompressType::NONE)
std::cout<<"use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
else
std::cout<<vf->bytes<<" bytes/pixel.";
if(vf->depth!=VulkanNumberType::NONE)
std::cout<<"[Depth:"<<data_type_name[size_t(vf->depth)]<<"]";
if(vf->depth!=VulkanBaseType::NONE)
std::cout<<"[ Depth:"<<std::setw(8)<<data_type_name[size_t(vf->depth)]<<"]";
if(vf->stencil!=VulkanNumberType::NONE)
std::cout<<"[Stencil:"<<data_type_name[size_t(vf->stencil)]<<"]";
if(vf->stencil!=VulkanBaseType::NONE)
std::cout<<"[Stencil:"<<std::setw(8)<<data_type_name[size_t(vf->stencil)]<<"]";
if((vf->depth==VulkanNumberType::NONE)
&&(vf->stencil==VulkanNumberType::NONE))
std::cout<<"[Color:"<<data_type_name[size_t(vf->color)]<<"]";
if((vf->depth==VulkanBaseType::NONE)
&&(vf->stencil==VulkanBaseType::NONE))
std::cout<<"[ Color:"<<std::setw(8)<<data_type_name[size_t(vf->color)]<<"]";
{
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
std::cout<<"[Optimal]";
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
std::cout<<"[Linear]";
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
std::cout<<"[Buffer]";
char olb[]="[ ]";
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[1]='O';
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='L';
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='B';
std::cout<<olb;
}
if(vf->compress_type!=TextureCompressType::NONE)
std::cout<<" use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
else
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";
std::cout<<std::endl;

View File

@@ -1,10 +1,11 @@
// 2.texture_rect
// 该示例是1.indices_rect的进化演示在矩形上贴上贴图
// 画一个带纹理的四边形
#include"VulkanAppFramework.h"
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/math/Math.h>
using namespace hgl;
@@ -21,26 +22,18 @@ constexpr uint32_t VERTEX_COUNT=4;
constexpr float position_data[VERTEX_COUNT][2]=
{
{0, 0},
{SCREEN_WIDTH, 0},
{0, SCREEN_HEIGHT},
{SCREEN_WIDTH, SCREEN_HEIGHT}
{-1, -1},
{ 1, -1},
{ 1, 1},
{-1, 1},
};
constexpr float tex_coord_data[VERTEX_COUNT][2]=
{
{0,0},
{1,0},
{0,1},
{1,1}
};
constexpr uint32_t INDEX_COUNT=6;
constexpr uint16 index_data[INDEX_COUNT]=
{
0,1,3,
0,3,2
{1,1},
{0,1}
};
class TestApp:public VulkanApplicationFramework
@@ -49,22 +42,28 @@ private:
Texture2D * texture =nullptr;
Sampler * sampler =nullptr;
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
Renderable * renderable =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/Texture2D"));
if(!material_instance)return(false);
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureTexture2D",Prim::Fan);
BindCameraUBO(material_instance);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;
material=db->LoadMaterial("Std2D/PureTexture2D",&cfg);
if(!material)
return(false);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Fan); //等同上一行为Framework重载默认使用swapchain的render target
if(!pipeline)
return(false);
@@ -73,23 +72,26 @@ private:
sampler=db->CreateSampler();
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::Color, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
material_instance=db->CreateMaterialInstance(material);
return(true);
}
bool InitVBO()
{
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
RenderablePrimitiveCreater rpc(db,"Quad",VERTEX_COUNT);
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
if(!primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V2F,VERTEX_COUNT,tex_coord_data)))return(false);
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.SetVBO(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
return(true);
render_obj=rpc.Create(material_instance,pipeline);
return(render_obj);
}
public:
@@ -105,16 +107,16 @@ public:
if(!InitVBO())
return(false);
BuildCommandBuffer(renderable);
BuildCommandBuffer(render_obj);
return(true);
}
void Resize(int w,int h)override
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(renderable);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework

View File

@@ -0,0 +1,134 @@
// 画一个带纹理的矩形2D模式专用
#include"VulkanAppFramework.h"
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/math/Math.h>
using namespace hgl;
using namespace hgl::graph;
VK_NAMESPACE_BEGIN
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
VK_NAMESPACE_END
constexpr uint32_t SCREEN_WIDTH=256;
constexpr uint32_t SCREEN_HEIGHT=256;
constexpr float position_data[4]=
{
0, //left
0, //top
1, //right
1 //bottom
};
constexpr float tex_coord_data[4]=
{
0,0,
1,1
};
class TestApp:public VulkanApplicationFramework
{
private:
Texture2D * texture =nullptr;
Sampler * sampler =nullptr;
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2D",Prim::SolidRectangles);
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
cfg.local_to_world=false;
material=db->LoadMaterial("Std2D/RectTexture2D",&cfg);
if(!material)
return(false);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行为Framework重载默认使用swapchain的render target
if(!pipeline)
return(false);
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
if(!texture)return(false);
sampler=db->CreateSampler();
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::Color, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
material_instance=db->CreateMaterialInstance(material);
return(true);
}
bool InitVBO()
{
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
render_obj=rpc.Create(material_instance,pipeline);
return(render_obj);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
BuildCommandBuffer(render_obj);
return(true);
}
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
#ifdef _DEBUG
if(!CheckStrideBytesByFormat())
return 0xff;
#endif//
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -0,0 +1,210 @@
// 画一个带纹理的矩形2D模式专用
#include"VulkanAppFramework.h"
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/math/Math.h>
#include<hgl/filesystem/Filename.h>
using namespace hgl;
using namespace hgl::graph;
VK_NAMESPACE_BEGIN
//Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
VK_NAMESPACE_END
constexpr uint32_t SCREEN_WIDTH=256;
constexpr uint32_t SCREEN_HEIGHT=256;
float position_data[4]=
{
0, //left
0, //top
1, //right
1 //bottom
};
constexpr float tex_coord_data[4]=
{
0,0,
1,1
};
constexpr const os_char *tex_filename[]=
{
OS_TEXT("001-online resume.Tex2D"),
OS_TEXT("002-salary.Tex2D"),
OS_TEXT("003-application.Tex2D"),
OS_TEXT("004-job interview.Tex2D")
};
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
class TestApp:public VulkanApplicationFramework
{
private:
SceneNode render_root;
RenderList * render_list =nullptr;
Texture2DArray * texture =nullptr;
Sampler * sampler =nullptr;
Material * material =nullptr;
Pipeline * pipeline =nullptr;
DeviceBuffer * tex_id_ubo =nullptr;
struct
{
MaterialInstance * mi;
Renderable * r;
}render_obj[TexCount]{};
private:
bool InitTexture()
{
texture=db->CreateTexture2DArray( "freepik icons",
512,512, ///<纹理尺寸
TexCount, ///<纹理层数
PF_BC1_RGBAUN, ///<纹理格式
false); ///<是否自动产生mipmaps
if(!texture)return(false);
OSString filename;
for(uint i=0;i<TexCount;i++)
{
filename=filesystem::MergeFilename(OS_TEXT("res/image/icon/freepik"),tex_filename[i]);
if(!db->LoadTexture2DToArray(texture,i,filename))
return(false);
}
return(true);
}
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2DArray",Prim::SolidRectangles);
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
cfg.local_to_world=true;
material=db->LoadMaterial("Std2D/RectTexture2DArray",&cfg);
if(!material)
return(false);
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行为Framework重载默认使用swapchain的render target
if(!pipeline)
return(false);
sampler=db->CreateSampler();
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::Color, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
for(uint32_t i=0;i<TexCount;i++)
{
render_obj[i].mi=db->CreateMaterialInstance(material);
if(!render_obj[i].mi)
return(false);
render_obj[i].mi->WriteMIData(i); //设置MaterialInstance的数据
}
return(true);
}
bool InitVBOAndRenderList()
{
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
position_data[2]=1.0f/float(TexCount);
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
Vector3f offset(1.0f/float(TexCount),0,0);
for(uint32_t i=0;i<TexCount;i++)
{
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
if(!render_obj[i].r)
return(false);
offset.x=position_data[2]*float(i);
render_root.CreateSubNode(translate(offset),render_obj[i].r);
}
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH*TexCount,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitTexture())
return(false);
if(!InitMaterial())
return(false);
if(!InitVBOAndRenderList())
return(false);
BuildCommandBuffer(render_list);
return(true);
}
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_list);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
#ifdef _DEBUG
if(!CheckStrideBytesByFormat())
return 0xff;
#endif//
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -10,41 +10,32 @@
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan/${group}")
endmacro()
CreateProject("Basic" 1st_triangle first_triangle.cpp)
CreateProject("Basic" 2nd_triangle second_triangle.cpp)
CreateProject("Basic" 3rd_triangle third_triangle.cpp)
CreateProject("Basic" FragCoord FragCoordTest.cpp)
CreateProject("Basic" indices_rect indices_rect.cpp)
CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
#CreateProject("Basic" FragCoord FragCoordTest.cpp)
CreateProject("Texture" TextureFormat TextureFormat.cpp)
CreateProject("Texture" texture_rect texture_rect.cpp)
#CreateProject("Texture" HQFilterTexture HQFilterTexture.cpp)
#CreateProject(06.Geometry2D Geometry2D.cpp)
CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
CreateProject("Tile" DrawTile DrawTile.cpp)
CreateProject("Tile" DrawText DrawText.cpp)
#CreateProject("Tile" DrawTile DrawTile.cpp)
#CreateProject("Tile" DrawText DrawText.cpp)
CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
#CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
CreateProject("Scene" SceneTree SceneTree.cpp)
#CreateProject("Scene" SceneTree SceneTree.cpp)
#CreateProject("Scene" LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
#CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
#CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
#CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
#CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
#CreateProject(12.PBRBasic PBRBasic.cpp)
#CreateProject(12.Deferred Deferred.cpp)
CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
#CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
#CreateProject(14.AutoMaterial auto_material.cpp)
CreateProject("Texture" Cubemap Cubemap.cpp)
CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
CreateProject("Picking" RayPicking RayPicking.cpp)
#CreateProject("Texture" Cubemap Cubemap.cpp)
#CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
#CreateProject("Picking" RayPicking RayPicking.cpp)
CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)
#CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)

View File

@@ -160,7 +160,7 @@ private:
fbi.SetExtent(SCREEN_WIDTH,SCREEN_HEIGHT);
gbuffer.rt=device->CreateRenderTarget(&fbi);
gbuffer.rt=device->CreateRT(&fbi);
if(!gbuffer.rt)return(false);

View File

@@ -1,87 +0,0 @@
// 全屏三角形
// 该范例用于演示使用索引画一个覆盖全屏的三角形但是不传递任何顶点信息顶点坐标在vertex shader中通过gl_VertexIndex计算出来。
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=256;
constexpr uint32_t SCREEN_HEIGHT=256;
class TestApp:public VulkanApplicationFramework
{
private:
MaterialInstance * material_instance =nullptr;
Renderable *renderable =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/fullscreen"));
if(!material_instance)return(false);
BindCameraUBO(material_instance);
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles);
return pipeline;
}
bool InitVBO()
{
auto primitive=db->CreatePrimitive(3);
if(!primitive)return(false);
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
return(true);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
BuildCommandBuffer(renderable);
return(true);
}
void Resize(int w,int h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(renderable);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
#ifdef _DEBUG
if(!CheckStrideBytesByFormat())
return 0xff;
#endif//
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -1,160 +0,0 @@
// 4.Geometry3D
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
class TestApp:public CameraAppFramework
{
Color4f color;
DeviceBuffer *ubo_color=nullptr;
private:
SceneNode render_root;
RenderList *render_list=nullptr;
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline =nullptr;
Primitive * ro_plane_grid[3];
private:
bool InitMDP()
{
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
if(!material)return(false);
material_instance=db->CreateMaterialInstance(material);
if(!material_instance)return(false);
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
if(!pipeline)
return(false);
return(true);
}
Renderable *Add(Primitive *r,const Matrix4f &mat)
{
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
render_root.CreateSubNode(mat,ri);
return ri;
}
void CreateRenderObject()
{
using namespace inline_geometry;
struct PlaneGridCreateInfo pgci;
pgci.coord[0]=Vector3f(-100,-100,0);
pgci.coord[1]=Vector3f( 100,-100,0);
pgci.coord[2]=Vector3f( 100, 100,0);
pgci.coord[3]=Vector3f(-100, 100,0);
pgci.step.x=32;
pgci.step.y=32;
pgci.side_step.x=8;
pgci.side_step.y=8;
pgci.color.Set(0.5,0,0,1);
pgci.side_color.Set(1,0,0,1);
const VIL *vil=material_instance->GetVIL();
ro_plane_grid[0]=CreatePlaneGrid(db,vil,&pgci);
pgci.color.Set(0,0.5,0,1);
pgci.side_color.Set(0,1,0,1);
ro_plane_grid[1]=CreatePlaneGrid(db,vil,&pgci);
pgci.color.Set(0,0,0.5,1);
pgci.side_color.Set(0,0,1,1);
ro_plane_grid[2]=CreatePlaneGrid(db,vil,&pgci);
}
bool InitScene()
{
Add(ro_plane_grid[0],Matrix4f(1.0f));
Add(ro_plane_grid[1],rotate(HGL_RAD_90,0,1,0));
Add(ro_plane_grid[2],rotate(HGL_RAD_90,1,0,0));
camera->pos=Vector3f(200,200,200);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(camera->info,&render_root);
return(true);
}
public:
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitMDP())
return(false);
CreateRenderObject();
if(!InitScene())
return(false);
return(true);
}
void BuildCommandBuffer(uint32 index)
{
render_root.RefreshMatrix();
render_list->Expend(GetCameraInfo(),&render_root);
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
}
void Resize(int w,int h)override
{
CameraAppFramework::Resize(w,h);
VulkanApplicationFramework::BuildCommandBuffer(render_list);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -1,103 +0,0 @@
// Instance Triangle
// 基本的Instance绘制测试用例,不使用场景树
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_SIZE=512;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT][2]=
{
{0,0},
{0.25,-0.75},
{0,-1}
};
constexpr float color_data[VERTEX_COUNT][4]=
{ {1,0,0,1},
{0,1,0,1},
{0,0,1,1}
};
class TestApp:public VulkanApplicationFramework
{
private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
if(!material_instance)
return(false);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
return(true);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
return(false);
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
if(!BuildCommandBuffer(render_obj))
return(false);
return(true);
}
void Resize(int w,int h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -80,7 +80,7 @@ public:
{
FramebufferInfo fbi(UPF_RGBA8,OFFSCREEN_SIZE,OFFSCREEN_SIZE);
os.render_taget=device->CreateRenderTarget(&fbi);
os.render_taget=device->CreateRT(&fbi);
if(!os.render_taget)return(false);
os.command_buffer=device->CreateRenderCommandBuffer();

View File

@@ -1,191 +0,0 @@
// 18.RayPicking
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/Ray.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
static float position_data[2][3]=
{
{100,100,100},
{0,0,0}
};
static float color_data[2][4]=
{
{1,1,0,1},
{1,1,0,1}
};
class TestApp:public CameraAppFramework
{
Color4f color;
DeviceBuffer *ubo_color=nullptr;
private:
SceneNode render_root;
RenderList * render_list =nullptr;
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline =nullptr;
Primitive * ro_plane_grid =nullptr;
Primitive * ro_line =nullptr;
VBO * vbo_pos =nullptr;
Ray ray;
private:
bool InitMDP()
{
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
if(!material)return(false);
material_instance=db->CreateMaterialInstance(material);
if(!material_instance)return(false);
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
if(!pipeline)
return(false);
return(true);
}
Renderable *Add(Primitive *r,const Matrix4f &mat)
{
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
render_root.CreateSubNode(mat,ri);
return ri;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
{
struct PlaneGridCreateInfo pgci;
pgci.coord[0]=Vector3f(-100,-100,0);
pgci.coord[1]=Vector3f( 100,-100,0);
pgci.coord[2]=Vector3f( 100, 100,0);
pgci.coord[3]=Vector3f(-100, 100,0);
pgci.step.x=32;
pgci.step.y=32;
pgci.side_step.x=8;
pgci.side_step.y=8;
pgci.color.Set(0.25,0,0,1);
pgci.side_color.Set(1,0,0,1);
const VIL *vil=material_instance->GetVIL();
ro_plane_grid=CreatePlaneGrid(db,vil,&pgci);
}
{
ro_line=db->CreatePrimitive(2);
if(!ro_line)return(false);
if(!ro_line->Set(VAN::Position, vbo_pos=db->CreateVBO(VF_V3F,2,position_data )))return(false);
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,2,color_data )))return(false);
}
return(true);
}
bool InitScene()
{
Add(ro_plane_grid,Matrix4f(1.0f));
Add(ro_line,Matrix4f(1.0f));
camera->pos=Vector3f(100,100,50);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(camera->info,&render_root);
return(true);
}
public:
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitMDP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
void BuildCommandBuffer(uint32 index)
{
const CameraInfo &ci=GetCameraInfo();
ray.Set(GetMouseCoord(),&ci); //设置射线查询的屏幕坐标点
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
render_root.RefreshMatrix();
render_list->Expend(ci,&render_root);
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
}
void Resize(int w,int h)override
{
CameraAppFramework::Resize(w,h);
VulkanApplicationFramework::BuildCommandBuffer(render_list);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -1,117 +0,0 @@
// 2.RectanglePrimivate
// 该示例是texture_rect的进化演示使用GeometryShader画矩形
#include"VulkanAppFramework.h"
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/math/Math.h>
using namespace hgl;
using namespace hgl::graph;
VK_NAMESPACE_BEGIN
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
VK_NAMESPACE_END
constexpr uint32_t SCREEN_SIZE=512;
constexpr uint32_t VERTEX_COUNT=1;
constexpr float BORDER=0.1f;
constexpr float position_data[4]=
{
SCREEN_SIZE*BORDER, SCREEN_SIZE*BORDER,
SCREEN_SIZE*(1.0-BORDER), SCREEN_SIZE*(1.0-BORDER)
};
constexpr float tex_coord_data[4]=
{
0,0,1,1
};
class TestApp:public VulkanApplicationFramework
{
private:
Texture2D * texture =nullptr;
Sampler * sampler =nullptr;
MaterialInstance * material_instance =nullptr;
Primitive * primitive =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/TextureRect2D"));
if(!material_instance)return(false);
BindCameraUBO(material_instance);
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::SolidRectangles);
if(!pipeline)return(false);
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"));
if(!texture)return(false);
sampler=db->CreateSampler();
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
return(true);
}
bool InitVBO()
{
primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
primitive->Set(VAN::Position,db->CreateVBO(VF_V4F,VERTEX_COUNT,position_data));
primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V4F,VERTEX_COUNT,tex_coord_data));
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
return(render_obj);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
return(false);
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
BuildCommandBuffer(render_obj);
return(true);
}
void Resize(int w,int h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -1,111 +0,0 @@
// indices_rect
// 该示例演示使用索引数据画一个矩形,并使用了颜色材质
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=256;
constexpr uint32_t SCREEN_HEIGHT=256;
constexpr uint32_t VERTEX_COUNT=4;
static Vector4f color(1,1,1,1);
constexpr float position_data[VERTEX_COUNT][2]=
{
{0,0},
{SCREEN_WIDTH,0},
{0,SCREEN_HEIGHT},
{SCREEN_WIDTH,SCREEN_HEIGHT}
};
constexpr uint32_t INDEX_COUNT=6;
constexpr uint16 index_data[INDEX_COUNT]=
{
0,1,3,
0,3,2
};
class TestApp:public VulkanApplicationFramework
{
private:
MaterialInstance * material_instance =nullptr;
Renderable *renderable =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/FragColor"));
if(!material_instance)return(false);
BindCameraUBO(material_instance);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
return(true);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
BuildCommandBuffer(renderable);
return(true);
}
void Resize(int w,int h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(renderable);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
#ifdef _DEBUG
if(!CheckStrideBytesByFormat())
return 0xff;
#endif//
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -1,106 +0,0 @@
// third_triangle
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT][2]=
{
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75},
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75}
};
constexpr float color_data[VERTEX_COUNT][4]=
{
{1,0,0,1},
{0,1,0,1},
{0,0,1,1}
};
class TestApp:public VulkanApplicationFramework
{
private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
if(!material_instance)
return(false);
BindCameraUBO(material_instance);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
return(true);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
if(!BuildCommandBuffer(render_obj))
return(false);
return(true);
}
void Resize(int w,int h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -2,7 +2,7 @@
#include<hgl/platform/Window.h>
#include<hgl/graph/VKInstance.h>
#include<hgl/graph/VKPhysicalDevice.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKDeviceCreater.h>
#include<hgl/graph/VKSemaphore.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKShaderModule.h>
@@ -19,9 +19,14 @@
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VKRenderTarget.h>
#include<hgl/graph/VKRenderResource.h>
#ifdef _DEBUG
#include<hgl/graph/VKDeviceAttribute.h>
#endif//_DEBUG
#include<hgl/graph/RenderList.h>
#include<hgl/graph/mtl/UBOCommon.h>
#include<hgl/color/Color.h>
#include<hgl/Time.h>
#include<hgl/log/LogInfo.h>
//#include<hgl/graph/LookAtCameraControl.h>
#include<hgl/graph/FirstPersonCameraControl.h>
@@ -33,6 +38,12 @@ using namespace hgl;
using namespace hgl::io;
using namespace hgl::graph;
namespace hgl{namespace graph
{
bool InitShaderCompiler();
void CloseShaderCompiler();
}}//namespace hgl::graph
class VulkanApplicationFramework:WindowEvent
{
protected:
@@ -44,7 +55,7 @@ protected:
GPUDevice * device =nullptr;
RenderPass * device_render_pass =nullptr;
SwapchainRenderTarget * sc_render_target =nullptr;
RTSwapchain * sc_render_target =nullptr;
protected:
@@ -59,15 +70,16 @@ protected:
RenderResource * db =nullptr;
protected:
Camera * camera =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
ViewportInfo vp_info;
DeviceBuffer * ubo_vp_info =nullptr;
public:
virtual ~VulkanApplicationFramework()
{
SAFE_CLEAR(camera);
CloseShaderCompiler();
win->Unjoin(this);
SAFE_CLEAR(db);
@@ -78,9 +90,14 @@ public:
SAFE_CLEAR(inst);
}
virtual bool Init(int w,int h)
virtual bool Init(uint w,uint h)
{
clear_color.Set(0,0,0,1);
logger::InitLogger(OS_TEXT("VulkanTest"));
if(!InitShaderCompiler())
return(false);
SetClearColor(COLOR::MozillaCharcoal);
#ifdef _DEBUG
if(!CheckStrideBytesByFormat())
@@ -105,7 +122,6 @@ public:
cili.lunarg.standard_validation = true;
cili.khronos.validation = true;
//cili.RenderDoc.Capture = true;
inst=CreateInstance("VulkanTest",nullptr,&cili);
@@ -113,10 +129,16 @@ public:
return(false);
}
device=CreateRenderDevice(inst,win);
{
VulkanHardwareRequirement vh_req;
if(!device)
return(false);
vh_req.wide_lines=true;
device=CreateRenderDevice(inst,win,&vh_req);
if(!device)
return(false);
}
device_render_pass=device->GetRenderPass();
@@ -127,48 +149,30 @@ public:
win->Join(this);
{
camera=new Camera;
vp_info.Set(w,h);
camera->width=w;
camera->height=h;
camera->vp_width=w;
camera->vp_height=h;
ubo_vp_info=db->CreateUBO("Viewport",sizeof(ViewportInfo),&vp_info);
camera->pos=Vector3f(10,10,10);
camera->RefreshCameraInfo();
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
db->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
return(true);
}
const CameraInfo &GetCameraInfo()
virtual void Resize(uint w,uint h)
{
return camera->info;
vp_info.Set(w,h);
ubo_vp_info->Write(&vp_info);
}
DeviceBuffer *GetCameraInfoBuffer()
ViewportInfo &GetViewportInfo()
{
return ubo_camera_info;
return vp_info;
}
bool BindCameraUBO(MaterialInstance *mi)
DeviceBuffer *GetViewportInfoBuffer()
{
return mi->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
}
virtual void Resize(int w,int h)
{
camera->width=w;
camera->height=h;
camera->vp_width=w;
camera->vp_height=h;
camera->RefreshCameraInfo();
ubo_camera_info->Write(&camera->info);
return ubo_vp_info;
}
void SetClearColor(const Color4f &cc)
@@ -204,7 +208,7 @@ public:
cmd_buf=hgl_zero_new<RenderCmdBuffer *>(swap_chain_count);
for(int32_t i=0;i<swap_chain_count;i++)
cmd_buf[i]=device->CreateRenderCommandBuffer();
cmd_buf[i]=device->CreateRenderCommandBuffer(device->GetPhysicalDevice()->GetDeviceName()+AnsiString(":RenderCmdBuffer_")+AnsiString::numberOf(i));
}
}
@@ -212,20 +216,20 @@ public:
{
if(!ri)return(false);
const IndexBuffer *ib=ri->GetIndexBuffer();
const VertexInputData *vid=ri->GetVertexInputData();
cb->Begin();
cb->BindFramebuffer(rp,fb);
cb->SetClearColor(0,clear_color);
cb->BeginRenderPass();
cb->BindPipeline(ri->GetPipeline());
cb->BindDescriptorSets(ri);
cb->BindDescriptorSets(ri->GetMaterial());
cb->BindVBO(ri);
if (ib)
cb->DrawIndexed(ib->GetCount(),ri->GetInstanceCount());
if (vid->index_buffer->buffer)
cb->DrawIndexed(vid->index_buffer->buffer->GetCount());
else
cb->Draw(ri->GetDrawCount(),ri->GetInstanceCount());
cb->Draw(vid->vertex_count);
cb->EndRenderPass();
cb->End();
@@ -292,7 +296,22 @@ public:
}
template<typename ...ARGS>
Pipeline *CreatePipeline(ARGS...args){return device_render_pass->CreatePipeline(args...);}
Pipeline *CreatePipeline(ARGS...args)
{
Pipeline *p=device_render_pass->CreatePipeline(args...);
if(!p)
return(nullptr);
#ifdef _DEBUG
DebugUtils *du=device->GetDebugUtils();
if(du)
du->SetPipeline(*p,"Pipeline:"+p->GetName());
#endif//_DEBUG
return p;
}
public:
@@ -383,7 +402,7 @@ class CameraMouseControl:public MouseEvent
Vector2f mouse_pos;
Vector2f mouse_last_pos;
protected:
protected:
bool OnPressed(int x,int y,MouseButton) override
{
@@ -453,9 +472,12 @@ public:
class CameraAppFramework:public VulkanApplicationFramework
{
protected:
Camera * camera =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
FirstPersonCameraControl *camera_control=nullptr;
CameraKeyboardControl * ckc=nullptr;
@@ -469,9 +491,10 @@ public:
{
SAFE_CLEAR(ckc);
SAFE_CLEAR(cmc);
SAFE_CLEAR(camera);
}
virtual bool Init(int w,int h)
virtual bool Init(uint w,uint h) override
{
if(!VulkanApplicationFramework::Init(w,h))
return(false);
@@ -482,7 +505,11 @@ public:
virtual void InitCamera(int w,int h)
{
camera_control=new FirstPersonCameraControl(camera);
camera=new Camera;
camera->pos=Vector3f(10,10,10);
camera_control=new FirstPersonCameraControl(&vp_info,camera);
camera_control->Refresh(); //更新矩阵计算
@@ -491,26 +518,40 @@ public:
win->Join(ckc);
win->Join(cmc);
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
ubo_camera_info=db->CreateUBO("CameraInfo",sizeof(CameraInfo),&camera_control->GetCameraInfo());
db->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
}
void Resize(int w,int h)override
void Resize(uint w,uint h)override
{
camera->width=w;
camera->height=h;
camera->vp_width=w;
camera->vp_height=h;
vp_info.Set(w,h);
camera_control->Refresh();
ubo_camera_info->Write(&camera->info);
ubo_camera_info->Write(&camera_control->GetCameraInfo());
}
CameraInfo &GetCameraInfo()
{
return camera_control->GetCameraInfo();
}
DeviceBuffer *GetCameraInfoBuffer()
{
return ubo_camera_info;
}
virtual void BuildCommandBuffer(uint32_t index)=0;
virtual void Draw()override
{
camera_control->Refresh(); //更新相机矩阵
ubo_camera_info->Write(&camera->info); //写入缓冲区
camera_control->Refresh(); //更新相机矩阵
ubo_camera_info->Write(&camera_control->GetCameraInfo()); //写入缓冲区
const uint32_t index=AcquireNextImage();
@@ -521,4 +562,55 @@ public:
ckc->Update();
cmc->Update();
}
};//class CameraAppFramework
};//class CameraAppFramework
class SceneAppFramework:public CameraAppFramework
{
protected:
SceneNode render_root;
RenderList * render_list =nullptr;
public:
SceneAppFramework()=default;
virtual ~SceneAppFramework()
{
SAFE_CLEAR(render_list);
}
virtual bool Init(uint width,uint height) override
{
if(!CameraAppFramework::Init(width,height))
return(false);
render_list=new RenderList(device);
return(true);
}
virtual void BuildCommandBuffer(uint32 index) override
{
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
}
virtual void Resize(uint w,uint h) override
{
CameraAppFramework::Resize(w,h);
VulkanApplicationFramework::BuildCommandBuffer(render_list);
}
};//class SceneAppFramework:public CameraAppFramework
template<typename T> int RunApp(uint w,uint h)
{
T app;
if(!app.Init(w,h))
return(-1);
while(app.Run());
return 0;
}

View File

@@ -21,7 +21,7 @@ namespace hgl
~Bitmap2DLoader();
void *OnBegin(uint32 total_bytes) override;
void OnEnd() override {}
bool OnEnd() override {return(false);}
BitmapData *GetBitmap();
};//class Bitmap2DLoader

View File

@@ -0,0 +1,17 @@
#pragma once
#include<hgl/TypeFunc.h>
namespace hgl
{
namespace graph
{
enum class CoordinateSystem2D
{
NDC,
ZeroToOne, //左上角为0,0右下角为1,1
Ortho, //左上角为0,0右下角为(width-1),(height-1)
ENUM_CLASS_RANGE(NDC,Ortho)
};
}//namespace graph
}//namespace hgl

View File

@@ -4,6 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/math/Vector.h>
#include<hgl/type/RectScope.h>
#include<hgl/type/Size2.h>
#include<hgl/color/Color4f.h>
#include<hgl/graph/AABB.h>
namespace hgl
@@ -59,17 +60,17 @@ namespace hgl
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci);
/**
* 平面网格创建信息
* 平面网格创建信息<br>
* 会创建一个在XY平面上居中的网格单个格子尺寸为1。
*/
struct PlaneGridCreateInfo
{
Vector3f coord[4];
Vector2u step;
Size2u grid_size; ///<格子数量
Vector2u side_step; //到边界的步数
Size2u sub_count; ///<细分格子数量
Color4f color; //一般线条颜色
Color4f side_color; //边界线条颜色
float lum; ///<一般线条颜色
float sub_lum; ///<细分及边界线条颜色
};//struct PlaneGridCreateInfo
/**
@@ -77,23 +78,10 @@ namespace hgl
*/
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
struct PlaneCreateInfo
{
Vector2f tile;
public:
PlaneCreateInfo()
{
tile.x=1.0f;
tile.y=1.0f;
}
};//struct PlaneCreateInfo
/**
* 创建一个平面(三角形)
*/
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci);
Primitive *CreatePlane(RenderResource *db,const VIL *vil);
struct CubeCreateInfo
{

View File

@@ -2,7 +2,7 @@
#define HGL_GRAPH_LIGHT_INCLUDE
#include<hgl/math/Math.h>
#include<hgl/type/Color4f.h>
#include<hgl/color/Color4f.h>
namespace hgl
{
namespace graph

View File

@@ -0,0 +1,73 @@
#pragma once
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/VKVBOList.h>
VK_NAMESPACE_BEGIN
class RenderAssignBuffer;
/**
* 同一材质的对象渲染列表
*/
class MaterialRenderList
{
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
Material *material;
RenderNodeList rn_list;
private:
RenderAssignBuffer *assign_buffer;
struct RenderItem
{
uint32_t first;
uint32_t count;
Pipeline * pipeline;
MaterialInstance * mi;
const VertexInputData * vid;
public:
void Set(Renderable *);
};
MaterialInstanceSets mi_set;
DataArray<RenderItem> ri_array;
uint ri_count;
void StatMI();
void Stat();
protected:
VBOList * vbo_list;
Pipeline * last_pipeline;
const VertexInputData * last_vid;
uint last_index;
bool Bind(const VertexInputData *,const uint);
void Render(RenderItem *);
public:
MaterialRenderList(GPUDevice *d,Material *m);
~MaterialRenderList();
void Add(Renderable *ri,const Matrix4f &mat);
void Clear()
{
rn_list.Clear();
}
void End();
void Render(RenderCmdBuffer *);
};//class MaterialRenderList
VK_NAMESPACE_END

View File

@@ -0,0 +1,32 @@
#pragma once
#include<hgl/graph/MaterialRenderList.h>
VK_NAMESPACE_BEGIN
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
{
public:
MaterialRenderMap()=default;
virtual ~MaterialRenderMap()=default;
void Begin()
{
for(auto *it:data_list)
it->value->Clear();
}
void End()
{
for(auto *it:data_list)
it->value->End();
}
void Render(RenderCmdBuffer *rcb)
{
if(!rcb)return;
for(auto *it:data_list)
it->value->Render(rcb);
}
};//class MaterialRenderMap
VK_NAMESPACE_END

View File

@@ -8,28 +8,28 @@ namespace hgl
{
namespace graph
{
struct ShaderStageBind
{
AnsiString name;
uint binding;
VAD * data =nullptr;
VBO * vbo =nullptr;
public:
~ShaderStageBind()
{
SAFE_CLEAR(data);
}
};//struct ShaderStageBind
using ShaderStageBindMap=ObjectMap<AnsiString,ShaderStageBind>;
/**
* 可绘制图元创建器
*/
class PrimitiveCreater
{
struct PrimitiveVertexBuffer
{
AnsiString name;
uint binding;
VAD * data =nullptr;
VBO * vbo =nullptr;
public:
~PrimitiveVertexBuffer()
{
SAFE_CLEAR(data);
}
};//struct PrimitiveVertexBuffer
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
protected:
RenderResource *db;
@@ -42,7 +42,7 @@ namespace hgl
uint32 vertices_number;
IndexBuffer * ibo;
ShaderStageBindMap ssb_map;
PVBMap vbo_map;
public:
@@ -54,9 +54,9 @@ namespace hgl
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
template<typename T>
T * CreateVADA(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
T * AccessVAD(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
{
const VkFormat format=vil->GetFormat(name);
const VkFormat format=vil->GetVulkanFormat(name);
if(format!=T::GetVulkanFormat())
return(nullptr);
@@ -66,11 +66,11 @@ namespace hgl
if(!vad)
return(nullptr);
T *vada=T::Create(vad);
T *access=T::Create(vad);
vada->Begin();
access->Begin();
return vada;
return access;
}
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
@@ -78,7 +78,7 @@ namespace hgl
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
virtual Primitive * Finish(); ///<结束并创建可渲染对象
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
};//class PrimitiveCreater
}//namespace graph
}//namespace hgl

View File

@@ -2,72 +2,42 @@
#define HGL_GRAPH_RENDER_LIST_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/MaterialRenderMap.h>
#include<hgl/graph/VKArrayBuffer.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/color/Color4f.h>
#include<hgl/type/SortedSets.h>
#include<hgl/graph/VKMaterial.h>
namespace hgl
{
namespace graph
{
using MVPArrayBuffer=GPUArrayBuffer<MVPMatrix>;
using MaterialSets=SortedSets<Material *>;
/**
* 渲染对象列表<br>
* 已经展开的渲染对象列表产生mvp用UBO/SSBO等数据最终创建RenderCommandBuffer
* 该类会长期保存使用过的材质信息避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
*/
class RenderList
{
GPUDevice * device;
RenderCmdBuffer *cmd_buf;
protected:
private:
GPUDevice * device;
CameraInfo camera_info;
RenderNodeList render_node_list; ///<场景节点列表
MaterialSets material_sets; ///<材质合集
RenderNodeComparator render_node_comparator;
private:
MVPArrayBuffer *mvp_array;
List<Renderable *> ri_list;
VkDescriptorSet ds_list[(size_t)DescriptorSetType::RANGE_SIZE];
DescriptorSet *renderable_desc_sets;
uint32_t ubo_offset;
uint32_t ubo_align;
uint renderable_count; ///<可渲染对象数量
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
protected:
virtual bool Begin();
virtual bool Expend(SceneNode *);
virtual void End();
private:
Pipeline * last_pipeline;
MaterialParameters *last_mp[(size_t)DescriptorSetType::RANGE_SIZE];
uint32_t last_vbo;
void Render(Renderable *);
virtual bool ExpendNode(SceneNode *);
public:
RenderList(GPUDevice *);
virtual ~RenderList();
virtual bool Expend(const CameraInfo &,SceneNode *);
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
virtual bool Render(RenderCmdBuffer *);
};//class RenderList
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void Clear(); ///<彻底清理
};//class RenderList
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE

View File

@@ -1,39 +1,29 @@
#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
#define HGL_GRAPH_RENDER_NODE_INCLUDE
#include<hgl/math/Vector.h>
#include<hgl/type/List.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VK.h>
#include<hgl/type/SortedSets.h>
namespace hgl
{
namespace graph
{
class Renderable;
class Material;
class MaterialInstance;
class GPUDevice;
struct VertexInputData;
struct IndexBufferData;
struct RenderNode
{
MVPMatrix matrix;
Vector3f WorldCenter;
float distance_to_camera_square;
// float distance_to_camera;
Matrix4f local_to_world;
Renderable *ri;
};
public:
using RenderNodeList=List<RenderNode>;
/**
* 取得渲染对象ubo独占区大小
*/
virtual const uint32 GetUBOBytes()const{return sizeof(MVPMatrix);}
};//struct RenderNode
using RenderNodeList=List<RenderNode *>;
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
}//namespace graph
}//namespace hgl
using RenderNodePointer=hgl::graph::RenderNode *;
using RenderNodeComparator=Comparator<RenderNodePointer>;
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE

View File

@@ -0,0 +1,84 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
enum class ResourceType
{
Unknown=0,
VkInstance,
VkPhysicalDevice,
VkDevice,
VertexInputLayout,
Material,
MaterialInstance,
FrameBuffer,
Texture,
Sampler,
VertexBuffer,
IndexBuffer,
IndirectBuffer,
UniformBuffer,
StorageBuffer,
Skeleton, ///<骨骼信息
SkeletonAnime, ///<骨骼动画信息
Primitive, ///<原始的单个模型数据由多个VBO+Index组成
RawMesh, ///<原始的静态模型数据由一个Primitive和一个MaterialInstance组成
StaticMesh, ///<静态模型数据由一个或多个RawMesh组成
SkeletonMesh, ///<骨骼模型数据由一个或多个StaticMesh组成
Font,
Scene,
Animation,
Audio,
Other,
ENUM_CLASS_RANGE(Unknown,Other)
};
enum class ResourcePlace
{
Unknown=0,
Memory, ///<内存
Device, ///<设备(如显存)
Disk, ///<硬盘
LAN, ///<局域网
WAN, ///<广域网
Other,
ENUM_CLASS_RANGE(Device,Other)
};
struct RenderResourceID
{
union
{
struct
{
uint device:1; ///<在设备
uint memory:1; ///<在内存
uint disk:1; ///<在硬盘
uint network:1; ///<在网络
};
uint8 place; ///<数据所在位置
};
uint16 resource_type; ///<资源类型对应ResourceType枚举
uint16 thread_id; ///<线程ID
uint32 id; ///<资源ID
};
VK_NAMESPACE_END

View File

@@ -0,0 +1,18 @@
#ifndef HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
#define HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
#include<hgl/type/DataType.h>
namespace hgl
{
namespace graph
{
struct RenderTargetOutputConfig
{
uint color; ///<要输出几个颜色缓冲区
bool depth; ///<是否输出到深度缓冲区
bool stencil; ///<是否输出到模板缓冲区
};
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE

View File

@@ -7,7 +7,7 @@ namespace hgl
{
namespace graph
{
/**
/**
* MVP矩阵
*/
struct MVPMatrix

View File

@@ -1,7 +1,7 @@
#ifndef HGL_GRAPH_SCENE_NODE_INCLUDE
#define HGL_GRAPH_SCENE_NODE_INCLUDE
#include<hgl/type/List.h>
#include<hgl/type/ObjectList.h>
#include<hgl/graph/SceneOrient.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/AABB.h>
@@ -43,7 +43,7 @@ namespace hgl
void Clear()
{
SubNode.ClearData();
SubNode.Clear();
render_obj=nullptr;
}
@@ -60,6 +60,9 @@ namespace hgl
SceneNode *CreateSubNode(Renderable *ri)
{
if(!ri)
return(nullptr);
SceneNode *sn=new SceneNode(ri);
SubNode.Add(sn);
@@ -76,6 +79,9 @@ namespace hgl
SceneNode *CreateSubNode(const Matrix4f &mat,Renderable *ri)
{
if(!ri)
return(nullptr);
SceneNode *sn=new SceneNode(mat,ri);
SubNode.Add(sn);

View File

@@ -0,0 +1,25 @@
#ifndef HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
#define HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class RawMesh
{
};
/**
* 静态渲染管理器<br>
* 静态渲染指的是不会产生资源变动的内容,而不是指不会动的内容。
*/
class StaticRenderManager
{
public:
virtual ~StaticRenderManager()=default;
};//class StaticRenderManager
VK_NAMESPACE_END
#endif//HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE

View File

@@ -3,8 +3,8 @@
#include<hgl/io/InputStream.h>
#include<hgl/type/String.h>
#include<hgl/graph/Bitmap.h>
#include<hgl/graph/VKFormat.h>
#include<hgl/graph/BitmapData.h>
namespace hgl
{
namespace graph
@@ -86,7 +86,7 @@ namespace hgl
protected:
virtual void *OnBegin(uint32)=0;
virtual void OnEnd()=0;
virtual bool OnEnd()=0;
virtual void OnError(){}
public:
@@ -207,7 +207,7 @@ namespace hgl
{
protected: // override functions
uint32 GetPixelsCount()const override{return file_header.length;}
uint32 GetPixelsCount()const override{return file_header.length*file_header.layers;}
uint32 GetTotalBytes()const override
{
if(file_header.mipmaps<=1)
@@ -230,7 +230,7 @@ namespace hgl
{
protected: // override functions
uint32 GetPixelsCount()const override{return file_header.width*file_header.height;}
uint32 GetPixelsCount()const override{return file_header.width*file_header.height*file_header.layers;}
uint32 GetTotalBytes()const override
{
if(file_header.mipmaps<=1)

View File

@@ -1,32 +1,17 @@
#ifndef HGL_GRAPH_TILE_DATA_INCLUDE
#define HGL_GRAPH_TILE_DATA_INCLUDE
#include<hgl/type/Map.h>
#include<hgl/type/Pool.h>
#include<hgl/type/RectScope.h>
#include<hgl/graph/Bitmap.h>
#include<hgl/graph/BitmapData.h>
#include<hgl/graph/ImageRegion.h>
#include<hgl/graph/tile/TileObject.h>
#include<hgl/graph/VKTexture.h>
VK_NAMESPACE_USING
namespace hgl
{
namespace graph
{
using TileUVPixel=RectScope2i;
using TileUVFloat=RectScope2f;
using TileUVFloatList=List<TileUVFloat>;
using TileUVFloatMap=Map<u32char,TileUVFloat>;
struct TileObject
{
int col,row; //当前tile在整个纹理中的tile位置
TileUVPixel uv_pixel; //以象素为单位的tile位置和尺寸
TileUVFloat uv_float; //以浮点为单位的tile位置和尺寸
};//struct TileObject
/**
* TileData是一种处理大量等同尺寸及格式贴图的管理机制程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注Tile的大小不必符合2次幂)
* Tile的增加或删除程序会自动排序尽可能小的减少I/O消耗。

View File

@@ -1,11 +1,10 @@
#ifndef HGL_GRAPH_VULKAN_INCLUDE
#define HGL_GRAPH_VULKAN_INCLUDE
#include<hgl/math/Math.h>
#include<hgl/type/List.h>
#include<hgl/math/Math.h>
#include<hgl/type/String.h>
#include<hgl/type/Map.h>
#include<iostream>
#include<hgl/graph/VKNamespace.h>
#include<hgl/graph/VKFormat.h>
#include<hgl/graph/VKPrimitiveType.h>
@@ -27,18 +26,20 @@ constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_D
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
using CharPointerList=hgl::List<const char *>;
using BindingMapping=Map<uint32_t,int>;
using BindingMap =Map<AnsiString,int>;
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
class VulkanInstance;
class GPUPhysicalDevice;
class GPUDevice;
struct GPUDeviceAttribute;
class Queue;
class DeviceQueue;
class ImageView;
class Framebuffer;
struct Swapchain;
class RenderTarget;
class SwapchainRenderTarget;
class RTSwapchain;
class Texture;
class Texture1D;
@@ -60,6 +61,12 @@ using VBO=VertexAttribBuffer;
class IndexBuffer;
struct IndexBufferData
{
IndexBuffer *buffer=nullptr;
VkDeviceSize offset=0;
};
class GPUCmdBuffer;
class RenderCmdBuffer;
class TextureCmdBuffer;
@@ -70,43 +77,15 @@ class DeviceRenderPassManage;
class Fence;
class Semaphore;
enum class DescriptorSetType
{
//设计使其对应shader中的set
Global=0, ///<全局参数(如太阳光等)
PerFrame, ///<帧参数(如摄像机等)
PerMaterialInstance,///<材质实例参数(如纹理等)
PerObject, ///<对象参数(如模型矩阵等)
Instance,
Skeleton,
ENUM_CLASS_RANGE(Global,Skeleton)
};//
constexpr char *DescriptSetsTypeName[]=
{
"Global","PerFrame","PerMaterialInstance","PerObject","Instance","Skeleton"
};
inline const char *GetDescriptorSetTypeName(const enum class DescriptorSetType &type)
{
RANGE_CHECK_RETURN_NULLPTR(type);
return DescriptSetsTypeName[(size_t)type];
}
struct PipelineLayoutData;
class DescriptorSet;
struct ShaderStage;
struct ShaderAttribute;
class ShaderResource;
class ShaderModule;
class VertexShaderModule;
class ShaderModuleMap;
class MaterialDescriptorSets;
class MaterialDescriptorManager;
class Material;
class MaterialParameters;
@@ -115,39 +94,11 @@ struct PipelineData;
enum class InlinePipeline;
class Pipeline;
struct VAConfig
{
VkFormat format;
bool instance;
struct VAConfig;
class VILConfig;
class VertexInput;
public:
VAConfig()
{
format=PF_UNDEFINED;
instance=false;
}
VAConfig(const VkFormat fmt,bool inst=false)
{
format=fmt;
instance=inst;
}
CompOperatorMemcmp(const VAConfig &);
};
class VILConfig:public Map<AnsiString,VAConfig>
{
public:
using Map<AnsiString,VAConfig>::Map;
bool Add(const AnsiString &name,const VkFormat fmt,const bool inst=false)
{
return Map<AnsiString,VAConfig>::Add(name,VAConfig(fmt,inst));
}
};
struct VertexInputFormat;
class VertexInputLayout;
using VIL=VertexInputLayout;
@@ -188,51 +139,17 @@ inline const uint32_t GetMipLevel(const VkExtent3D &ext)
/**
* 索引类型,等同于VkIndexType
*/
enum IndexType
enum IndexType:uint
{
U16=0,
U32
U32,
U8=VK_INDEX_TYPE_UINT8_EXT,
};
enum class ShaderStageBit
{
Vertex =VK_SHADER_STAGE_VERTEX_BIT,
TessControl =VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
TessEval =VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
Geometry =VK_SHADER_STAGE_GEOMETRY_BIT,
Fragment =VK_SHADER_STAGE_FRAGMENT_BIT,
Compute =VK_SHADER_STAGE_COMPUTE_BIT
};//enum class ShaderStageBit
inline const uint GetShaderCountByBits(const uint32_t bits)
{
uint comp=(uint)VK_SHADER_STAGE_VERTEX_BIT;
uint result=0;
for(uint i=0;i<6;i++)
{
if(bits&comp)
++result;
comp<<=1;
}
return result;
}
/**
* max-lengths:
*
256 bytes: nvidia,arm
128 bytes: amd,intel,powervr,adreno
*/
struct PushConstant
{
Matrix4f local_to_world;
Matrix4f normal;
};
constexpr uint32_t MAX_PUSH_CONSTANT_BYTES=sizeof(PushConstant);
//Push Constant max-lengths:
//
// 256 bytes: nvidia,arm
// 128 bytes: amd,intel,powervr,adreno
inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
{
@@ -240,61 +157,5 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
e3d.height =e2d.height;
e3d.depth =depth;
}
inline void debug_out_vk_version(const uint32_t version)
{
std::cout<<VK_VERSION_MAJOR(version)<<"."
<<VK_VERSION_MINOR(version)<<"."
<<VK_VERSION_PATCH(version);
}
template<typename T>
inline hgl::String<T> VkUUID2String(const uint8_t *pipelineCacheUUID)
{
T *hstr=new T[VK_UUID_SIZE*2+1];
DataToLowerHexStr(hstr,pipelineCacheUUID,VK_UUID_SIZE);
return hgl::String<T>::newOf(hstr,VK_UUID_SIZE*2);
}
inline void debug_out(const char *front,const hgl::List<VkLayerProperties> &layer_properties)
{
const int property_count=layer_properties.GetCount();
if(property_count<=0)return;
const VkLayerProperties *lp=layer_properties.GetData();
for(int i=0;i<property_count;i++)
{
std::cout<<front<<" Layer Propertyes ["<<i<<"] : "<<lp->layerName<<" [spec: ";
debug_out_vk_version(lp->specVersion);
std::cout<<", impl: ";
debug_out_vk_version(lp->implementationVersion);
std::cout<<"] desc: "<<lp->description<<std::endl;
++lp;
}
}
inline void debug_out(const char *front,const hgl::List<VkExtensionProperties> &extension_properties)
{
const int extension_count=extension_properties.GetCount();
if(extension_count<=0)return;
VkExtensionProperties *ep=extension_properties.GetData();
for(int i=0;i<extension_count;i++)
{
std::cout<<front<<" Extension Propertyes ["<<i<<"] : "<<ep->extensionName<<" ver: ";
debug_out_vk_version(ep->specVersion);
std::cout<<std::endl;
++ep;
}
}
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_INCLUDE

View File

@@ -1,90 +1,75 @@
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKMemoryAllocator.h>
#include<hgl/type/Collection.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDynamicBufferAccess.h>
namespace hgl
{
class Collection;
namespace graph
{
class VKMemoryAllocator;
/**
* GPU数据阵列缓冲区<br>
* 它用于储存多份相同格式的数据常用于多物件渲染instance等
*/
template<typename T> class GPUArrayBuffer
class GPUArrayBuffer
{
protected:
GPUDevice *device;
VkBufferUsageFlags buffer_usage_flags;
VKMemoryAllocator *vk_ma;
uint align_size;
uint range_size;
uint32_t ubo_offset_alignment;
VKMemoryAllocator *vk_ma;
Collection *coll;
protected:
void * Map(const uint32 start,const uint32 count);
void Flush(const uint32 count);
private:
GPUArrayBuffer(VKMemoryAllocator *,const uint,const uint);
friend class GPUDevice;
public:
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags)
virtual ~GPUArrayBuffer();
const uint32_t GetAlignSize()const{return align_size;} ///<数据对齐字节数
const uint32_t GetRangeSize()const{return range_size;} ///<单次渲染访问最大字节数
DeviceBuffer * GetBuffer();
uint32 Alloc(const uint32 max_count); ///<预分配空间
void Clear();
template<typename T>
bool Start(DynamicBufferAccess<T> *dba,const uint32 start,const uint32 count)
{
device=dev;
buffer_usage_flags=flags;
if(!dba)return(false);
{
ubo_offset_alignment=device->GetUBOAlign();
void *ptr=Map(start,count);
const uint32_t unit_size=hgl_align<uint32_t>(sizeof(T),ubo_offset_alignment);
if(!ptr)return(false);
vk_ma=new VKMemoryAllocator(device,buffer_usage_flags,unit_size); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
MemoryBlock *mb=new MemoryBlock(vk_ma);
coll=new Collection(unit_size,mb);
}
dba->Start((uchar *)ptr,align_size,count);
return(true);
}
virtual ~GPUArrayBuffer()
template<typename T>
void End(DynamicBufferAccess<T> *dba)
{
delete coll;
}
if(!dba)return;
const uint32_t GetOffsetAlignment()const
{
return ubo_offset_alignment;
}
Flush(dba->GetCount());
const uint32_t GetUnitSize()const
{
return coll->GetUnitBytes();
}
DeviceBuffer *GetBuffer()
{
return vk_ma->GetBuffer();
}
uint32 Alloc(const uint32 max_count) ///<预分配空间
{
if(!coll->Alloc(max_count))
return(0);
return coll->GetAllocCount();
}
void Clear()
{
coll->Clear();
}
T *Map(const uint32 start,const uint32 count)
{
return (T *)(coll->Map(start,count));
}
void Flush(const uint32 count)
{
vk_ma->Flush(count*GetUnitSize());
dba->Restart();
}
};//class GPUArrayBuffer
}//namespace graph

View File

@@ -36,6 +36,7 @@ public:
VkBuffer GetBuffer ()const{return buf.buffer;}
DeviceMemory * GetMemory ()const{return buf.memory;}
VkDeviceMemory GetVkMemory ()const{return buf.memory->operator VkDeviceMemory();}
const VkDescriptorBufferInfo * GetBufferInfo ()const{return &buf.info;}
void * Map () {return buf.memory->Map();}

View File

@@ -2,6 +2,7 @@
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKVBOList.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/color/Color4f.h>
@@ -42,9 +43,7 @@ class RenderCmdBuffer:public GPUCmdBuffer
VkClearValue *clear_values;
VkRect2D render_area;
VkViewport viewport;
float default_line_width;
Framebuffer *fbo;
RenderPassBeginInfo rp_begin;
VkPipelineLayout pipeline_layout;
@@ -140,14 +139,14 @@ public:
return(true);
}
bool BindDescriptorSets(Renderable *ri);
bool BindDescriptorSets(Material *);
bool PushDescriptorSet(VkPipelineLayout pipeline_layout,uint32_t set,uint32_t count,const VkWriteDescriptorSet *write_desc_set)
{
vkCmdPushDescriptorSetKHR(cmd_buf,VK_PIPELINE_BIND_POINT_GRAPHICS,pipeline_layout,set,count,write_desc_set);
}
void PushConstants(ShaderStageBit shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
void PushConstants(VkShaderStageFlagBits shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
{
vkCmdPushConstants(cmd_buf,pipeline_layout,(VkShaderStageFlagBits)shader_stage_bit,offset,size,pValues);
}
@@ -155,13 +154,29 @@ public:
void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);}
void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);}
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vbo,const VkDeviceSize *offsets)
{
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
}
bool BindVBO(VBOList *vbo_list)
{
if(!vbo_list)return(false);
if(!vbo_list->IsFull())return(false);
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
return(true);
}
void BindIBO(const IndexBufferData *);
bool BindVBO(Renderable *);
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
void SetLineWidth (float line_width) {vkCmdSetLineWidth(cmd_buf,line_width);}
void SetDepthBias (float constant_factor,float clamp,float slope_factor) {vkCmdSetDepthBias(cmd_buf,constant_factor,clamp,slope_factor);}
void SetDepthBounds (float min_db,float max_db) {vkCmdSetDepthBounds(cmd_buf,min_db,max_db);}
void SetBlendConstants (const float constants[4]) {vkCmdSetBlendConstants(cmd_buf,constants);}
@@ -176,7 +191,7 @@ public: //draw
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}

View File

@@ -1,86 +0,0 @@
#ifndef HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
#define HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/color/Color4f.h>
VK_NAMESPACE_BEGIN
struct DebugMakerFunction
{
PFN_vkDebugMarkerSetObjectTagEXT SetObjectTag;
PFN_vkDebugMarkerSetObjectNameEXT SetObjectName;
PFN_vkCmdDebugMarkerBeginEXT Begin;
PFN_vkCmdDebugMarkerEndEXT End;
PFN_vkCmdDebugMarkerInsertEXT Insert;
};//struct DebugMakerFunction
class DebugMaker
{
VkDevice device;
DebugMakerFunction dmf;
protected:
void SetObjectName(uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name);
void SetObjectTag(uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag);
private:
friend DebugMaker *CreateDebugMaker(VkDevice device);
DebugMaker(VkDevice dev,const DebugMakerFunction &f)
{
device=dev;
dmf=f;
}
public:
void Begin(VkCommandBuffer cmdbuffer, const char * pMarkerName, const Color4f &color);
void Insert(VkCommandBuffer cmdbuffer, const char *markerName, const Color4f &color);
void End(VkCommandBuffer cmdBuffer);
#define DEBUG_MAKER_SET_FUNC(type,MNAME) void Set##type(Vk##type obj,const char *name){SetObjectName((uint64_t)obj,VK_DEBUG_REPORT_OBJECT_TYPE_##MNAME##_EXT,name);}
DEBUG_MAKER_SET_FUNC(Instance, INSTANCE)
DEBUG_MAKER_SET_FUNC(PhysicalDevice, PHYSICAL_DEVICE)
DEBUG_MAKER_SET_FUNC(Device, DEVICE)
DEBUG_MAKER_SET_FUNC(Queue, QUEUE)
DEBUG_MAKER_SET_FUNC(Semaphore, SEMAPHORE)
DEBUG_MAKER_SET_FUNC(CommandBuffer, COMMAND_BUFFER)
DEBUG_MAKER_SET_FUNC(Fence, FENCE)
DEBUG_MAKER_SET_FUNC(DeviceMemory, DEVICE_MEMORY)
DEBUG_MAKER_SET_FUNC(Buffer, BUFFER)
DEBUG_MAKER_SET_FUNC(Image, IMAGE)
DEBUG_MAKER_SET_FUNC(Event, EVENT)
DEBUG_MAKER_SET_FUNC(QueryPool, QUERY_POOL)
DEBUG_MAKER_SET_FUNC(BufferView, BUFFER_VIEW)
DEBUG_MAKER_SET_FUNC(ShaderModule, SHADER_MODULE)
DEBUG_MAKER_SET_FUNC(PipelineCache, PIPELINE_CACHE)
DEBUG_MAKER_SET_FUNC(PipelineLayout, PIPELINE_LAYOUT)
DEBUG_MAKER_SET_FUNC(RenderPass, RENDER_PASS)
DEBUG_MAKER_SET_FUNC(Pipeline, PIPELINE)
DEBUG_MAKER_SET_FUNC(DescriptorSetLayout, DESCRIPTOR_SET_LAYOUT)
DEBUG_MAKER_SET_FUNC(Sampler, SAMPLER)
DEBUG_MAKER_SET_FUNC(DescriptorPool, DESCRIPTOR_POOL)
DEBUG_MAKER_SET_FUNC(DescriptorSet, DESCRIPTOR_SET)
DEBUG_MAKER_SET_FUNC(Framebuffer, FRAMEBUFFER)
DEBUG_MAKER_SET_FUNC(CommandPool, COMMAND_POOL)
DEBUG_MAKER_SET_FUNC(SurfaceKHR, SURFACE_KHR)
DEBUG_MAKER_SET_FUNC(SwapchainKHR, SWAPCHAIN_KHR)
DEBUG_MAKER_SET_FUNC(DebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT)
DEBUG_MAKER_SET_FUNC(DisplayKHR, DISPLAY_KHR)
DEBUG_MAKER_SET_FUNC(DisplayModeKHR, DISPLAY_MODE_KHR)
DEBUG_MAKER_SET_FUNC(ValidationCacheEXT, VALIDATION_CACHE_EXT)
DEBUG_MAKER_SET_FUNC(SamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION)
DEBUG_MAKER_SET_FUNC(DescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE)
DEBUG_MAKER_SET_FUNC(CuModuleNVX, CU_MODULE_NVX)
DEBUG_MAKER_SET_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
DEBUG_MAKER_SET_FUNC(AccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR)
DEBUG_MAKER_SET_FUNC(AccelerationStructureNV, ACCELERATION_STRUCTURE_NV)
#undef DEBUG_MAKER_SET_FUNC
};//class DebugMaker
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE

View File

@@ -0,0 +1,112 @@
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
#include<hgl/type/Map.h>
#include<hgl/type/String.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl
{
namespace graph
{
class DeviceBuffer;
class Texture;
class Material;
class MaterialParameters;
/**
* 描述符绑定器<Br>
* 一般用于注册通用数据,为材质进行自动绑定。
*/
class DescriptorBinding
{
DescriptorSetType set_type; ///<描述符合集类型
Map<AnsiString,DeviceBuffer *> ubo_map;
Map<AnsiString,DeviceBuffer *> ssbo_map;
Map<AnsiString,Texture *> texture_map;
public:
DescriptorBinding(const DescriptorSetType &dst)
{
set_type=dst;
}
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
return ubo_map.Add(name,buf);
}
DeviceBuffer *GetUBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetListObject(ubo_map,name);
}
void RemoveUBO(DeviceBuffer *buf)
{
if(!buf)return;
ubo_map.DeleteByValue(buf);
}
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
return ssbo_map.Add(name,buf);
}
DeviceBuffer *GetSSBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetListObject(ssbo_map,name);
}
void RemoveSSBO(DeviceBuffer *buf)
{
if(!buf)return;
ssbo_map.DeleteByValue(buf);
}
bool AddTexture(const AnsiString &name,Texture *tex)
{
if(!tex)return(false);
if(name.IsEmpty())return(false);
return texture_map.Add(name,tex);
}
Texture *GetTexture(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetListObject(texture_map,name);
}
void RemoveTexture(Texture *tex)
{
if(!tex)return;
texture_map.DeleteByValue(tex);
}
private:
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
public:
bool Bind(Material *);
};//class DescriptorBinding
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE

View File

@@ -1,8 +1,9 @@
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/type/ObjectList.h>
#include<hgl/type/SortedSets.h>
VK_NAMESPACE_BEGIN
class DeviceBuffer;
@@ -23,9 +24,7 @@ class DescriptorSet
bool is_dirty;
private:
friend class GPUDevice;
public:
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
{
@@ -37,8 +36,6 @@ private:
is_dirty=true;
}
public:
~DescriptorSet()=default;
const uint32_t GetCount ()const{return binding_count;}
@@ -59,4 +56,4 @@ public:
void Update();
};//class DescriptorSet
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE

View File

@@ -5,8 +5,9 @@
#include<hgl/type/String.h>
#include<hgl/type/Map.h>
#include<hgl/type/RectScope.h>
#include<hgl/graph/ImageRegion.h>
#include<hgl/platform/Window.h>
#include<hgl/graph/Bitmap.h>
#include<hgl/graph/BitmapData.h>
#include<hgl/graph/font/Font.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDeviceAttribute.h>
@@ -15,35 +16,21 @@
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKArrayBuffer.h>
namespace hgl
{
namespace graph
{
class TileData;
class TileFont;
class FontSource;
}//namespace graph
}//namespace hgl
#include<hgl/graph/VKDescriptorSetType.h>
VK_NAMESPACE_BEGIN
/*
* GPU设备创建信息
*/
struct GPUDeviceCreateInfo
{
VkPhysicalDeviceType device_type =VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM;
class TileData;
class TileFont;
class FontSource;
class GPUArrayBuffer;
uint32_t swapchain_image_count =0;
VkSurfaceFormatKHR color_format ={PF_A2BGR10UN,VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
VkFormat depth_format =VK_FORMAT_UNDEFINED;
};//struct GPUDeviceCreateInfo
struct CopyBufferToImageInfo;
class GPUDevice
{
GPUDeviceAttribute *attr;
Queue *texture_queue;
DeviceQueue *texture_queue;
TextureCmdBuffer *texture_cmd_buf;
private:
@@ -51,16 +38,16 @@ private:
DeviceRenderPassManage *render_pass_manage;
RenderPass *device_render_pass;
SwapchainRenderTarget *swapchainRT;
RTSwapchain *sc_rt;
SwapchainRenderTarget *CreateSwapchainRenderTarget();
RTSwapchain *CreateSwapchainRenderTarget();
void InitRenderPassManage();
void ClearRenderPassManage();
private:
VkCommandBuffer CreateCommandBuffer();
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
bool CreateSwapchainFBO(Swapchain *);
@@ -68,7 +55,7 @@ private:
private:
friend GPUDevice *CreateRenderDevice(VulkanInstance *inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent);
friend class VulkanDeviceCreater;
GPUDevice(GPUDeviceAttribute *da);
@@ -92,12 +79,14 @@ public:
RenderPass * GetRenderPass () {return device_render_pass;}
SwapchainRenderTarget * GetSwapchainRT () {return swapchainRT;}
RTSwapchain * GetSwapchainRT () {return sc_rt;}
const VkExtent2D & GetSwapchainSize ()const {return swapchainRT->GetExtent();}
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
public:
bool Resize (const VkExtent2D &);
@@ -128,17 +117,22 @@ public: //Buffer相关
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);}
IndexBuffer * CreateIBO16 ( uint32_t count,const uint16 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,(void *)data,sm);}
IndexBuffer * CreateIBO32 ( uint32_t count,const uint32 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,(void *)data,sm);}
IndexBuffer * CreateIBO (IndexType type, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(type, count,nullptr,sm);}
IndexBuffer * CreateIBO8 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,nullptr,sm);}
IndexBuffer * CreateIBO16 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,nullptr,sm);}
IndexBuffer * CreateIBO32 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,nullptr,sm);}
const VkDeviceSize GetUBOAlign();
const VkDeviceSize GetSSBOAlign();
const VkDeviceSize GetUBORange();
const VkDeviceSize GetSSBORange();
#define CREATE_BUFFER_OBJECT(LargeName,type) DeviceBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
DeviceBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
@@ -151,6 +145,9 @@ public: //Buffer相关
#undef CREATE_BUFFER_OBJECT
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
public: //Image
VkImage CreateImage (VkImageCreateInfo *);
@@ -158,7 +155,15 @@ public: //Image
private: //texture
bool CommitTexture (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
@@ -177,37 +182,22 @@ public: //Texture
Texture2D *CreateTexture2D(TextureData *);
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(TextureData *);
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
TextureCube *CreateTextureCube(TextureData *);
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
void Clear(TextureCreateInfo *);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,const List<Image2DRegion> &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,void *data, uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,void *data,const uint32_t size,const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
template<typename T>
bool ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope2<T> &rs)
{
return ChangeTexture2D( tex,
buf,
rs.GetLeft(),
rs.GetTop(),
rs.GetWidth(),
rs.GetHeight());
}
template<typename T>
bool ChangeTexture2D(Texture2D *tex,void *data,const RectScope2<T> &rs,uint32_t size)
{
return ChangeTexture2D( tex,
data,
rs.GetLeft(),
rs.GetTop(),
rs.GetWidth(),
rs.GetHeight(),
size);
}
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,void *data,const uint32_t size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
public: //
@@ -216,25 +206,16 @@ public: //
public: //shader & material
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorSets *);
void Destroy(PipelineLayoutData *);
ShaderModule *CreateShaderModule(VkShaderStageFlagBits,const uint32_t *,const size_t);
DescriptorSet * CreateDescriptorSets(const PipelineLayoutData *,const DescriptorSetType &type)const;
MaterialParameters *CreateMP(const MaterialDescriptorSets *,const PipelineLayoutData *,const DescriptorSetType &);
MaterialParameters *CreateMP(Material *,const DescriptorSetType &);
ShaderModule *CreateShaderModule(ShaderResource *);
Material *CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps,MaterialDescriptorSets *);
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorManager *desc_manager);
MaterialInstance *CreateMI(Material *,const VILConfig *vil_cfg=nullptr);
MaterialParameters *CreateMP(const MaterialDescriptorManager *desc_manager,const PipelineLayoutData *pld,const DescriptorSetType &desc_set_type);
public: //Command Buffer 相关
RenderCmdBuffer * CreateRenderCommandBuffer();
TextureCmdBuffer *CreateTextureCommandBuffer();
RenderCmdBuffer * CreateRenderCommandBuffer(const AnsiString &);
TextureCmdBuffer *CreateTextureCommandBuffer(const AnsiString &);
public:
@@ -243,27 +224,25 @@ public:
Fence * CreateFence(bool);
Semaphore * CreateGPUSemaphore();
Queue * CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
public: //FrameBuffer相关
Framebuffer *CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
// Framebuffer *CreateFramebuffer(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *);
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *);
public:
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
public:
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class GPUDevice
GPUDevice *CreateRenderDevice(VulkanInstance *inst,Window *win,const GPUPhysicalDevice *physical_device=nullptr);
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE

View File

@@ -4,7 +4,6 @@
#include<hgl/graph/VKTexture.h>
#ifdef _DEBUG
#include<hgl/graph/VKDebugMaker.h>
#include<hgl/graph/VKDebugUtils.h>
#endif//_DEBUG
@@ -22,32 +21,32 @@ struct GPUDeviceAttribute
VkSurfaceKHR surface =VK_NULL_HANDLE;
VkSurfaceCapabilitiesKHR surface_caps;
uint32_t graphics_family =ERROR_FAMILY_INDEX;
uint32_t present_family =ERROR_FAMILY_INDEX;
uint32_t compute_family =ERROR_FAMILY_INDEX;
uint32_t graphics_family =ERROR_FAMILY_INDEX;
uint32_t present_family =ERROR_FAMILY_INDEX;
uint32_t compute_family =ERROR_FAMILY_INDEX;
uint32_t video_decode_family =ERROR_FAMILY_INDEX;
#ifdef VK_ENABLE_BETA_EXTENSIONS
uint32_t video_encode_family =ERROR_FAMILY_INDEX;
#endif//VK_ENABLE_BETA_EXTENSIONS
VkQueue graphics_queue =VK_NULL_HANDLE;
VkQueue present_queue =VK_NULL_HANDLE;
List<VkQueueFamilyProperties> family_properties;
List<VkBool32> supports_present;
List<VkSurfaceFormatKHR> surface_formats_list;
VkSurfaceFormatKHR surface_format;
List<VkPresentModeKHR> present_modes;
VkSurfaceTransformFlagBitsKHR preTransform;
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
VkDevice device =VK_NULL_HANDLE;
VkCommandPool cmd_pool =VK_NULL_HANDLE;
VkDescriptorPool desc_pool =VK_NULL_HANDLE;
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
#ifdef _DEBUG
DebugMaker * debug_maker =nullptr;
DebugUtils * debug_utils =nullptr;
#endif//_DEBUG

View File

@@ -0,0 +1,314 @@
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDevice.h>
VK_NAMESPACE_BEGIN
struct VulkanHardwareRequirement
{
uint min_1d_image_size;
uint min_2d_image_size;
uint min_3d_image_size;
uint min_cube_image_size;
uint min_array_image_layers;
uint min_vertex_input_attribute; ///<最小顶点输入属性数量需求
uint min_color_attachments; ///<最小颜色输出成份数量需求
uint min_push_constant_size; ///<最小push constant大小
uint min_ubo_range; ///<最小ubo range需求
uint min_ssbo_range; ///<最小ssbo range需求
uint min_draw_indirect_count; ///<最小间接绘制次数需求
bool geometry_shader; ///<要求支持几何着色器
bool tessellation_shader; ///<要求支持细分着色器
// bool compute_shader; ///<要求支持计算着色器
bool multi_draw_indirect; ///<要求支持MultiDrawIndirect
bool wide_lines; ///<要求支持宽线条
bool line_rasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
bool large_points; ///<要求支持绘制大点
bool texture_cube_array; ///<要求支持立方体数组纹理
bool uint8_draw_index; ///<要求支持8位索引
bool uint32_draw_index; ///<要求支持32位索引(不建议使用)
struct
{
bool bc,etc2,astc_ldr,astc_hdr,pvrtc; ///<要求支持的压缩纹理格式
}texture_compression;
//dynamic_state VK_EXT_extended_dynamic_state
// cull mode
// front face
// primitive topology
// viewport
// scissor
// bind vbo
// depth test
// depth write
// depth compare op
// depth bounds test
// stencil test
// stencil op
//dynamic_state[1] VK_EXT_extended_dynamic_state2
// patch control points
// rasterizer discard
// depth bias
// logic op
// primitive restart
//dynamic_state[2] VK_EXT_extended_dynamic_state3
// tess domain origin
// depth clamp
// discard polygon mode
// rasterization samples
// sample mask
// alpha to coverage
// alpha to one
// logic op enable
// color blend
// color blend equation
// color write mask
// depth clamp
// Color blend advanced
// line rasterization mode
// line stipple
// depth clip -1 to 1
// shading rate image enable
bool dynamic_state[3]; ///<要求支持动态状态
// 1.3 特性
bool dynamic_rendering; ///<要求支持动态渲染
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
public:
VulkanHardwareRequirement()
{
hgl_zero(*this);
descriptor_pool=1024;
geometry_shader=true;
}
};
constexpr const VkFormat SwapchainPreferFormatsLDR[]=
{
PF_RGB5A1,
PF_BGR5A1,
PF_A1RGB5,
PF_RGB565,
PF_BGR565,
};
constexpr const VkFormat SwapchainPreferFormatsSDR[]=
{
PF_RGBA8UN,//PF_RGBA8s,
PF_BGRA8UN,//PF_BGRA8s,
PF_ABGR8UN,//PF_ABGR8s,
PF_A2RGB10UN,
PF_A2BGR10UN,
// PF_B10GR11UF
};
constexpr const VkFormat SwapchainPreferFormatsHDR16[]=
{
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F
};
constexpr const VkFormat SwapchainPreferFormatsHDR32[]=
{
PF_RGB32F,
PF_RGBA32F
};
constexpr const VkFormat SwapchainPreferFormatsHDR[]=
{
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F,
PF_RGB32F,PF_RGBA32F
};
constexpr const VkFormat SwapchainPreferFormatsDepth[]=
{
PF_D16UN,
PF_X8_D24UN,
PF_D16UN_S8U,
PF_D24UN_S8U,
PF_D32F,
PF_D32F_S8U
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
{
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT,
VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT,
VK_COLOR_SPACE_DISPLAY_NATIVE_AMD,
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesLinear[]=
{
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
VK_COLOR_SPACE_BT709_LINEAR_EXT,
VK_COLOR_SPACE_BT2020_LINEAR_EXT,
VK_COLOR_SPACE_HDR10_ST2084_EXT,
VK_COLOR_SPACE_DOLBYVISION_EXT,
VK_COLOR_SPACE_HDR10_HLG_EXT,
VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
};
struct PreferFormats
{
//偏好格式需从低质量到高质量排列
const VkFormat *formats;
uint count;
public:
const int Find(const VkFormat fmt)const
{
for(uint i=0;i<count;i++)
if(fmt==formats[i])
return i;
return -1;
}
};
struct PreferColorSpaces
{
//偏好格式需从低质量到高质量排列
const VkColorSpaceKHR *colorspaces;
uint count;
public:
const int Find(const VkColorSpaceKHR cs)const
{
for(uint i=0;i<count;i++)
if(cs==colorspaces[i])
return i;
return -1;
}
};
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferSDR {SwapchainPreferFormatsSDR, sizeof(SwapchainPreferFormatsSDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR16{SwapchainPreferFormatsHDR16, sizeof(SwapchainPreferFormatsHDR16 )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(SwapchainPreferFormatsHDR32 )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR {SwapchainPreferFormatsHDR, sizeof(SwapchainPreferFormatsHDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferDepth{SwapchainPreferFormatsDepth, sizeof(SwapchainPreferFormatsDepth )/sizeof(VkFormat)};
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferColorSpacesNonlinear, sizeof(SwapchainPreferColorSpacesNonlinear )/sizeof(VkColorSpaceKHR)};
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferColorSpacesLinear, sizeof(SwapchainPreferColorSpacesLinear )/sizeof(VkColorSpaceKHR)};
/**
* Vulkan设备创建器<br>
* 将此功能定义为类是为了让开发者方便重载处理
*/
class VulkanDeviceCreater
{
protected:
VulkanInstance *instance;
Window *window;
const GPUPhysicalDevice *physical_device;
VulkanHardwareRequirement require;
VkExtent2D extent;
const PreferFormats * perfer_color_formats;
const PreferColorSpaces * perfer_color_spaces;
const PreferFormats * perfer_depth_formats;
VkSurfaceKHR surface;
VkSurfaceFormatKHR surface_format;
CharPointerList ext_list;
VkPhysicalDeviceFeatures features={};
protected:
VkDevice CreateDevice(const uint32_t);
public:
VulkanDeviceCreater(VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req,
const PreferFormats *spf_color,
const PreferColorSpaces *spf_color_space,
const PreferFormats *spf_depth);
virtual bool ChoosePhysicalDevice();
virtual bool RequirementCheck();
virtual void ChooseSurfaceFormat();
virtual GPUDevice *CreateRenderDevice();
public:
virtual GPUDevice *Create();
};//class VulkanDeviceCreater
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr,
const PreferFormats * spf_color =&PreferSDR,
const PreferColorSpaces * spf_color_space =&PreferNonlinear,
const PreferFormats * spf_depth =&PreferDepth)
{
VulkanDeviceCreater vdc(vi,win,req,spf_color,spf_color_space,spf_depth);
return vdc.Create();
}
inline GPUDevice *CreateRenderDeviceLDR(VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,req,&PreferLDR,&PreferNonlinear,&PreferDepth);
}
inline GPUDevice *CreateRenderDeviceSDR(VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,req,&PreferSDR,&PreferNonlinear,&PreferDepth);
}
inline GPUDevice *CreateRenderDeviceHDR16( VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,req,&PreferHDR16,&PreferLinear,&PreferDepth);
}
inline GPUDevice *CreateRenderDeviceHDR32( VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,req,&PreferHDR32,&PreferLinear,&PreferDepth);
}
inline GPUDevice *CreateRenderDeviceHDR(VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,req,&PreferHDR,&PreferLinear,&PreferDepth);
}
VK_NAMESPACE_END

View File

@@ -0,0 +1,79 @@
#ifndef HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
#define HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
#include<hgl/graph/VKArrayBuffer.h>
VK_NAMESPACE_BEGIN
template<typename T> class DynamicBufferAccess
{
uchar *pointer;
uchar *current;
uint align_size;
uint count;
uint index;
private:
DynamicBufferAccess()
{
Restart();
}
void Restart()
{
pointer=nullptr;
current=nullptr;
align_size=0;
count=0;
index=0;
}
void Start(uchar *buf,const uint as,const uint c)
{
current=pointer=buf;
align_size=as;
count=c;
index=0;
}
friend class GPUArrayBuffer;
public:
const uint GetCount()const{return count;}
const uint GetCurrentIndex()const{return index;}
const uint GetOffsetBytes()const{return index*align_size;}
bool Write(uchar *src)
{
if(!src)return(false);
if(index>=count)return(false);
memcpy(current,src,sizeof(T));
current+=align_size;
++index;
return(true);
}
bool Write(uchar *src,const uint c)
{
if(!src)return(false);
if(c<=0)return(false);
if(index+c>count)return(false);
for(uint i=0;i<c;i++)
{
memcpy(current,src,sizeof(T));
current+=align_size;
src+=sizeof(T);
}
index+=c;
return(true);
}
};//template<typename T> class DynamicBufferAccess
VK_NAMESPACE_END
#endif//HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE

View File

@@ -35,5 +35,7 @@ public:
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
};//class Framebuffer
using FBO=Framebuffer;
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE

View File

@@ -26,8 +26,8 @@ namespace hgl
~IndexBuffer()=default;
const IndexType GetType ()const{return index_type;}
const uint32 GetCount()const{return count;}
const IndexType GetType ()const{return index_type;}
const uint32 GetCount()const{return count;}
};//class IndexBuffer:public DeviceBuffer
}//namespace graph
}//namespace hgl

View File

@@ -2,7 +2,7 @@
#define HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
#include<hgl/type/String.h>
#include<hgl/type/List.h>
#include<hgl/type/ObjectList.h>
#include<hgl/platform/Window.h>
#include<hgl/graph/VKPhysicalDevice.h>
#include<hgl/graph/VKDebugOut.h>
@@ -23,9 +23,16 @@ VK_NAMESPACE_BEGIN
struct
{
VK_BOOL1BIT(synchronization2)
VK_BOOL1BIT(validation)
VK_BOOL1BIT(profiles)
}khronos;
struct
{
VK_BOOL1BIT(switchable_graphics)
}amd;
struct
{
VK_BOOL1BIT(optimus)

View File

@@ -5,61 +5,59 @@
#include<hgl/type/Map.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl
{
class ActiveMemoryBlockManager;
}
VK_NAMESPACE_BEGIN
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
using MaterialParameterArray=MaterialParameters *[size_t(DescriptorSetType::RANGE_SIZE)];
struct MaterialData
{
UTF8String name;
ShaderModuleMap *shader_maps;
MaterialDescriptorSets *mds;
VertexShaderModule *vertex_sm;
ShaderStageCreateInfoList shader_stage_list;
PipelineLayoutData *pipeline_layout_data;
MaterialParameterArray mp_array;
private:
friend class Material;
~MaterialData();
};//struct MaterialData
/**
* 材质类<br>
* 用于管理shader提供DescriptorSetLayoutCreater
*/
class Material
{
MaterialData *data;
AnsiString name;
VertexInput *vertex_input;
ShaderModuleMap *shader_maps;
MaterialDescriptorManager *desc_manager;
ShaderStageCreateInfoList shader_stage_list;
PipelineLayoutData *pipeline_layout_data;
MaterialParameters *mp_array[DESCRIPTOR_SET_TYPE_COUNT];
uint32_t mi_data_bytes; ///<实例数据大小
uint32_t mi_max_count; ///<实例一次渲染最大数量限制
ActiveMemoryBlockManager *mi_data_manager;
private:
friend GPUDevice;
friend class RenderResource;
MaterialData *GetMaterialData(){return data;}
Material(const AnsiString &);
public:
Material(MaterialData *md):data(md){}
~Material();
virtual ~Material();
const UTF8String & GetName ()const{return data->name;}
const AnsiString & GetName ()const{return name;}
VertexShaderModule * GetVertexShaderModule () {return data->vertex_sm;}
const VertexInput * GetVertexInput ()const{return vertex_input;}
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
const MaterialDescriptorSets * GetDescriptorSets ()const{return data->mds;}
// const MaterialDescriptorManager * GetDescriptorManager ()const{return desc_manager;}
const VkPipelineLayout GetPipelineLayout ()const;
const PipelineLayoutData * GetPipelineLayoutData ()const{return data->pipeline_layout_data;}
// const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
public:
@@ -67,10 +65,37 @@ public:
{
RANGE_CHECK_RETURN_NULLPTR(type)
return data->mp_array[size_t(type)];
return mp_array[size_t(type)];
}
const bool hasSet (const DescriptorSetType &type)const;
const bool hasAssign ()const;
const VIL * GetDefaultVIL()const;
VIL * CreateVIL(const VILConfig *format_map=nullptr);
bool Release(VIL *);
const uint GetVILCount();
public:
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
void Update();
public:
const bool HasMI ()const{return mi_data_bytes>0;}
const uint32_t GetMIDataBytes ()const{return mi_data_bytes;}
const uint32_t GetMIMaxCount ()const{return mi_max_count;}
void ReleaseMI(int); ///<释放材质实例
void *GetMIData(int); ///<取得指定ID号的材质实例数据访问指针
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
};//class Material
using MaterialSets=SortedSets<Material *>;
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE

View File

@@ -0,0 +1,53 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKShaderDescriptorSet.h>
VK_NAMESPACE_BEGIN
class MaterialDescriptorManager
{
UTF8String mtl_name;
BindingMapArray binding_map[DESCRIPTOR_SET_TYPE_COUNT];
private:
VkDescriptorSetLayoutBinding *all_dslb;
DescriptorSetLayoutCreateInfo dsl_ci[DESCRIPTOR_SET_TYPE_COUNT];
public:
MaterialDescriptorManager(const UTF8String &,ShaderDescriptor *,const uint);
MaterialDescriptorManager(const UTF8String &,const ShaderDescriptorSetArray &);
~MaterialDescriptorManager();
const UTF8String &GetMaterialName()const{return mtl_name;}
const uint GetBindCount(const DescriptorSetType &set_type)const
{
RANGE_CHECK_RETURN(set_type,0)
return dsl_ci[size_t(set_type)].bindingCount;
}
const BindingMapArray &GetBindingMap(const DescriptorSetType &set_type)const
{
return binding_map[size_t(set_type)];
}
const int GetBinding(const DescriptorSetType &set_type,const VkDescriptorType &desc_type,const AnsiString &name)const;
const int GetUBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
const int GetSSBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
const int GetImageSampler (const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
const int GetInputAttachment(const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
const bool hasSet(const DescriptorSetType &type)const{return dsl_ci[size_t(type)].bindingCount>0;}
//!sd_list_by_set_type[size_t(type)].IsEmpty();}
};//class MaterialDescriptorManager
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE

View File

@@ -1,61 +0,0 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
struct ShaderDescriptor
{
char name[128];
VkDescriptorType desc_type;
DescriptorSetType set_type;
uint32_t set;
uint32_t binding;
uint32_t stage_flag;
};
using ShaderDescriptorList=List<ShaderDescriptor *>;
class MaterialDescriptorSets
{
UTF8String mtl_name;
ShaderDescriptor *sd_list;
uint sd_count;
ShaderDescriptorList sd_list_by_desc_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
ShaderDescriptorList sd_list_by_set_type[size_t(DescriptorSetType::RANGE_SIZE)];
// Map<AnsiString,ShaderDescriptor *> sd_by_name;
Map<AnsiString,int> binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
// int *binding_list[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
private:
DescriptorSetLayoutCreateInfo dsl_ci[size_t(DescriptorSetType::RANGE_SIZE)];
public:
MaterialDescriptorSets(const UTF8String &,ShaderDescriptor *,const uint);
~MaterialDescriptorSets();
const UTF8String &GetMaterialName()const{return mtl_name;}
const int GetBinding(const VkDescriptorType &desc_type,const AnsiString &name)const;
const int GetUBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
const int GetSSBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
const int GetImageSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
const int GetInputAttachment(const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
const ShaderDescriptorList &GetDescriptorList(const DescriptorSetType &type)const{return sd_list_by_set_type[size_t(type)];}
const bool hasSet(const DescriptorSetType &type)const{return !sd_list_by_set_type[size_t(type)].IsEmpty();}
};//class MaterialDescriptorSets
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE

View File

@@ -4,34 +4,79 @@
#include<hgl/graph/VKMaterial.h>
VK_NAMESPACE_BEGIN
/**
* <summary>
*
* layout(location=?) in uint MaterialInstanceID
*
* #define MI_MAX_COUNT ??? //该值由引擎根据 UBORange/sizeof(MaterialInstance) 计算出来
*
* struct MaterialInstance //这部分数据即为材质实例的具体数据每一个材质实例类负责提供具体数据。由RenderList合并成一整个UBO
* { //该类数据由DescriptorSetType为PerMaterial的参数构成
* vec4 BaseColor;
* vec4 Emissive;
* vec4 ARM;
* };
*
* layout(set=?,binding=?) uniform Material
* {
* MaterialInstance mi[MI_MAX_COUNT]
* }mtl;
*
* void main()
* {
* MaterialInstance mi=mtl.mi[(MaterialInstanceID>=MI_MAX_COUNT)?:0:MaterialInstanceID]; //如果超出范围则使用0号材质实例数据
*
* vec4 BaseColor =mi.BaseColor;
* vec4 Emissive =mi.Emissive;
*
* float AO =mi.ARM.x;
* float Roughness =mi.ARM.y;
* float Metallic =mi.ARM.z;
*
* </summary>
*/
/**
* 材质实例类<br>
* 材质实例类本质只是提供一个数据区供RenderList合并成一个大UBO。
*/
class MaterialInstance
{
protected:
Material *material;
VIL *vil;
MaterialParameters *mp_per_mi; ///<材质实例独有参数对应PerMaterial合集
private:
friend class GPUDevice;
MaterialInstance(Material *,VIL *);
int mi_id;
public:
virtual ~MaterialInstance()=default;
Material * GetMaterial () {return material;}
Material *GetMaterial(){return material;}
const VIL * GetVIL ()const {return vil;}
const VIL *GetVIL()const{return vil;}
MaterialParameters *GetMP(){return mp_per_mi;}
MaterialParameters *GetMP(const DescriptorSetType &type){return material->GetMP(type);}
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
private:
friend class Material;
MaterialInstance(Material *,VIL *,const int);
public:
virtual ~MaterialInstance()
{
material->ReleaseMI(mi_id);
}
const int GetMIID ()const{return mi_id;} ///<取得材质实例ID
void * GetMIData (){return material->GetMIData(mi_id);} ///<取得材质实例数据
void WriteMIData (const void *data,const int size); ///<写入材质实例数据
template<typename T>
void WriteMIData (const T &data){WriteMIData(&data,sizeof(T));} ///<写入材质实例数据
};//class MaterialInstance
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE

View File

@@ -1,48 +1,54 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/graph/VKMaterialDescriptorManager.h>
#include<hgl/graph/VKArrayBuffer.h>
VK_NAMESPACE_BEGIN
class MaterialParameters
{
const MaterialDescriptorSets *mds;
protected:
const MaterialDescriptorManager *desc_manager;
DescriptorSetType set_type;
DescriptorSet *descriptor_set;
private:
friend class GPUDevice;
MaterialParameters(const MaterialDescriptorSets *,const DescriptorSetType &type,DescriptorSet *);
public:
const DescriptorSetType GetType (){return set_type;}
DescriptorSet * GetDescriptorSet (){return descriptor_set;}
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_set->GetDescriptorSet();}
const uint32_t GetCount ()const{return descriptor_set->GetCount();}
const bool IsReady ()const{return descriptor_set->IsReady();}
const uint32_t GetDescriptorCount ()const{return desc_manager->GetBindCount(set_type);} ///<获取总共需要绑定的描述符数量
const BindingMapArray & GetBindingMap ()const{return desc_manager->GetBindingMap(set_type);}
const uint32_t GetBoundCount ()const{return descriptor_set->GetCount();} ///<获取已经绑好的数量
const bool IsReady ()const{return descriptor_set->IsReady();} ///<是否全部绑好了
public:
#define MP_TYPE_IS(name) const bool is##name()const{return set_type==DescriptorSetType::name;}
MP_TYPE_IS(Skeleton)
MP_TYPE_IS(Instance)
MP_TYPE_IS(PerObject)
MP_TYPE_IS(PerMaterialInstance)
MP_TYPE_IS(PerMaterial)
MP_TYPE_IS(PerFrame)
MP_TYPE_IS(Global)
#undef MP_TYPE_IS
public:
MaterialParameters(const MaterialDescriptorManager *,const DescriptorSetType &type,DescriptorSet *);
virtual ~MaterialParameters();
bool BindUBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
bool BindSSBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const int &index,Texture *tex,Sampler *sampler);
bool BindInputAttachment(const int &index,ImageView *);
bool BindUBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindSSBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const AnsiString &name,Texture *tex,Sampler *sampler);
@@ -51,4 +57,4 @@ public:
void Update();
};//class MaterialParameters
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE

View File

@@ -25,7 +25,7 @@ public:
const uint32_t GetBufferUsageFlagBits ()const{return buffer_usage_flag_bits;}
DeviceBuffer * GetBuffer (){return gpu_buffer;}
DeviceBuffer * GetBuffer (){return gpu_buffer;}
public:

View File

@@ -48,6 +48,8 @@ public:
operator VkPhysicalDevice() {return physical_device;}
operator const VkPhysicalDevice()const {return physical_device;}
const uint32_t GetVulkanVersion()const{return properties.apiVersion;}
const int GetMemoryType(uint32_t,VkMemoryPropertyFlags)const;
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
@@ -88,8 +90,13 @@ public:
const bool isMicrosoft ()const{return HGL_VK_IS_BRAND(Microsoft);}
const bool isMesa ()const{return HGL_VK_IS_BRAND(Mesa );}
const bool isAMD ()const{return HGL_VK_IS_BRAND(AMD )
||HGL_VK_IS_BRAND(ATI );}
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia );}
||HGL_VK_IS_BRAND(ATI )
||HGL_VK_IS_BRAND(Radeon );}
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia )
||HGL_VK_IS_BRAND(GeForce )
||HGL_VK_IS_BRAND(Quadro )
||HGL_VK_IS_BRAND(TITAN )
||HGL_VK_IS_BRAND(Tegra );}
const bool isIntel ()const{return HGL_VK_IS_BRAND(Intel );}
const bool isQualcomm ()const{return HGL_VK_IS_BRAND(Adreno );}
const bool isApple ()const{return HGL_VK_IS_BRAND(Apple );}
@@ -155,8 +162,6 @@ public:
const uint32_t GetMaxImage3D ()const{return properties.limits.maxImageDimension3D;}
const uint32_t GetMaxImageCube ()const{return properties.limits.maxImageDimensionCube;}
const uint32_t GetMaxImageArrayLayers ()const{return properties.limits.maxImageArrayLayers;}
const uint32_t GetMaxUBORange ()const{return properties.limits.maxUniformBufferRange;}
const uint32_t GetMaxSSBORange ()const{return properties.limits.maxStorageBufferRange;}
const uint32_t GetMaxBoundDescriptorSets ()const{return properties.limits.maxBoundDescriptorSets;}
const uint32_t GetMaxVertexInputAttributes ()const{return properties.limits.maxVertexInputAttributes;}

View File

@@ -9,6 +9,9 @@ VK_NAMESPACE_BEGIN
class Pipeline
{
VkDevice device;
AnsiString name;
VkPipeline pipeline;
PipelineData *data;
@@ -19,8 +22,10 @@ private:
friend class RenderPass;
Pipeline(VkDevice dev,VkPipeline p,PipelineData *pd)
Pipeline(const AnsiString &n,VkDevice dev,VkPipeline p,PipelineData *pd)
{
name=n;
device=dev;
pipeline=p;
data=pd;
@@ -33,8 +38,12 @@ public:
virtual ~Pipeline();
const AnsiString &GetName()const{return name;}
operator VkPipeline(){return pipeline;}
const PipelineData *GetData()const{return data;}
const bool IsAlphaTest()const{return data->alpha_test>0;}
const bool IsAlphaBlend()const{return data->alpha_blend;}
};//class GraphicsPipeline

View File

@@ -12,6 +12,9 @@ VK_NAMESPACE_BEGIN
*/
class Primitive
{
GPUDevice *device;
AnsiString prim_name;
struct VBOData
{
VBO *buf;
@@ -26,10 +29,9 @@ class Primitive
protected:
uint32_t draw_count;
uint32_t vertex_count;
IndexBuffer *indices_buffer=nullptr;
VkDeviceSize indices_offset=0;
IndexBufferData index_buffer_data;
protected:
@@ -46,42 +48,33 @@ protected:
public:
Primitive(const uint32_t dc=0):draw_count(dc){}
Primitive(GPUDevice *dev,const AnsiString &n,const uint32_t vc=0)
{
device=dev;
prim_name=n;
vertex_count=vc;
}
virtual ~Primitive()=default;
const uint GetRefCount()const{return ref_count;}
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
const AABB & GetBoundingBox()const {return BoundingBox;}
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
{
if(!ib)return(false);
indices_buffer=ib;
indices_offset=offset;
return(true);
}
bool Set(IndexBuffer *ib,VkDeviceSize offset=0);
public:
void SetDrawCount(const uint32_t dc){draw_count=dc;} ///<设置当前对象绘制需要多少个顶点
virtual const uint32_t GetDrawCount()const ///<取得当前对象绘制需要多少个顶点
{
if(indices_buffer)
return indices_buffer->GetCount();
const uint32_t GetVertexCount ()const {return vertex_count;}
return draw_count;
}
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
const int GetBufferCount ()const {return buffer_list.GetCount();}
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
const int GetBufferCount ()const {return buffer_list.GetCount();}
IndexBuffer * GetIndexBuffer () {return indices_buffer;}
const VkDeviceSize GetIndexBufferOffset()const {return indices_offset;}
const IndexBufferData * GetIndexBufferData ()const {return &index_buffer_data;}
};//class Primitive
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE

View File

@@ -4,7 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKFence.h>
VK_NAMESPACE_BEGIN
class Queue
class DeviceQueue
{
protected:
@@ -21,11 +21,11 @@ private:
friend class GPUDevice;
Queue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
DeviceQueue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
public:
virtual ~Queue();
virtual ~DeviceQueue();
operator VkQueue(){return queue;}
@@ -35,6 +35,6 @@ public:
bool WaitFence(const bool wait_all=true,const uint64_t time_out=HGL_NANO_SEC_PER_SEC);
bool Submit(const VkCommandBuffer &cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem);
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,Semaphore *wait_sem,Semaphore *complete_sem);
};//class SumbitQueue
};//class DeviceQueue
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE

View File

@@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/type/List.h>
#include<hgl/type/ObjectList.h>
VK_NAMESPACE_BEGIN
/**
* RenderPass功能封装<br>
@@ -25,7 +25,7 @@ protected:
ObjectList<Pipeline> pipeline_list;
Pipeline *CreatePipeline(Material *,PipelineData *,const VIL *);
Pipeline *CreatePipeline(const AnsiString &,PipelineData *,const ShaderStageCreateInfoList &,VkPipelineLayout,const VIL *);
private:
@@ -54,14 +54,15 @@ public:
public:
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &);
Pipeline *CreatePipeline(Material *,const VIL *,const PipelineData *, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const Prim &,const bool prim_restart=false);
public:
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &prim,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &,const bool prim_restart=false);
};//class RenderPass
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE

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