375 Commits

Author SHA1 Message Date
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
844636a46b optimized first_triangle based on RenderablePrimitiveCreater class. 2023-02-23 13:49:18 +08:00
a6b71a449e optimized name of values. 2023-02-23 13:25:05 +08:00
e31a6cca13 commented binding_list of VKMaterialDescriptorSets, because I don't know it's function. 2023-02-23 12:40:23 +08:00
cce2cab12c renamed to PerMaterialInstance instead of PerMaterial 2023-02-23 12:31:42 +08:00
3dbb1c40b7 updated all descript set in RenderList 2023-02-22 21:59:35 +08:00
af4b9cd6d4 renamed to DescriptorSetType instead of DescriptorSetsType 2023-02-22 21:53:51 +08:00
b35ef27610 upgraded to newly DescriptorSetType 2023-02-22 21:50:18 +08:00
95064488db rename and layout codes. 2023-02-21 22:32:03 +08:00
df8156cfe1 support new VILConfig 2023-02-21 18:36:42 +08:00
f990539633 supported half_float and 8bit unorm format at first_triangle example. 2023-02-21 18:35:08 +08:00
2fb443bcb4 updated codes to support newly CM??? modules. 2023-02-19 19:28:47 +08:00
b8a83a25eb use VKDescriptorSet instead of VKDescriptorSets 2023-02-13 11:50:55 +08:00
251d851f65 upgraded codes based on newly CM... library. 2023-02-13 11:48:53 +08:00
8fc83ba9b3 added PipelineCacheCreateInfo struct. 2022-10-28 17:57:09 +08:00
f8646ca880 renamed Semaphore instead of GPUSemaphore,
renamed Queue instead of GPUQueue
2022-10-14 19:40:16 +08:00
fc2c8021ba renamed Fence instead of GPUFence 2022-10-14 19:27:29 +08:00
b980457ba2 renamed DeviceBuffer/DeviceMemory instead of GPUBuffer/GPUMemory, 2022-10-14 17:52:35 +08:00
2e6a8e794f renamed to BaseColor instead Color in VAN. 2022-10-12 16:30:15 +08:00
1bc810d8e9 Update README.md 2022-10-11 19:19:31 +08:00
cd2f278e84 renamed to VertexInputLayout instead of VertexAttributeBinding 2022-10-11 19:16:06 +08:00
bb3b06f168 added Debug log. 2022-09-29 18:29:21 +08:00
cc02b719e6 improved codes of Debug 2022-09-27 19:41:28 +08:00
981a1adf4c Layouted codes of VKPhysicalDevice.h 2022-09-27 10:43:08 +08:00
28e48a0142 added QueueBegin/End/Insert at DebugUtils 2022-09-26 22:06:17 +08:00
a0a5ab5da4 added more type to DeubgMaker/DebugUtils 2022-09-26 17:06:04 +08:00
d98df3ee9c added DebugUtils/DebugMaker test 2022-09-26 16:11:42 +08:00
12760ab5c5 added VKDebugUtils.h/.cpp 2022-09-26 12:14:52 +08:00
271 changed files with 12192 additions and 4455 deletions

2
CMCore

Submodule CMCore updated: 48abdf2a89...1141f37cc4

2
CMUtil

Submodule CMUtil updated: c3addef6b7...c0990c52eb

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,21 +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
里程碑:
ULRE是一个试验性质的工程用于试验各种渲染相关的技术以及做一些范例。在未来它的复杂化版本会被整合到CMGameEngine中用于替代旧的渲染引擎。
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,4 @@
mat4 GetLocalToWorld()
{
return l2w.mats[Assign.x];
}

8
ShaderLibrary/GetMI.glsl Normal file
View File

@@ -0,0 +1,8 @@
MaterialInstance GetMI()
{
#if ShaderStage == VertexShader
return mtl.mi[Assign.y];
#else
return mtl.mi[Input.MaterialInstanceID];
#endif
}

View File

@@ -0,0 +1,10 @@
void HandoverMI()
{
#if ShaderStage == VertexShader
Output.MaterialInstanceID=Assign.y;
#elif ShaderStage == GeometryShader
Output.MaterialInstanceID=Input[0].MaterialInstanceID;
#else
Output.MaterialInstanceID=Input.MaterialInstanceID;
#endif
}

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,10 @@
#version 460 core
#define VertexShader 0x01
#define TessControlShader 0x02
#define TeseEvalShader 0x04
#define GeometryShader 0x08
#define FragmentShader 0x10
#define ComputeShader 0x20
#define TaskShader 0x40
#define MeshShader 0x80

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,64 @@
#Material
Name BlinnPhong+HalfLambert shading model only color
Reference https://zhuanlan.zhihu.com/p/442023993
Base Std3D
Require LocalToWorld,Camera,Sun
#MaterialInstance
#VertexInput
vec3 Normal
#Vertex
Output
{
vec3 Normal;
}
Code
{
void main()
{
gl_Position=GetPosition3D();
}
}
#Fragment
Output
{
vec4 FragColor;
}
Code
{
void main()
{
//将法线归一化
vec3 world_normal =normalize(Input.Normal);
//对世界坐标下的灯光方法归一化
vec3 world_light_direction =normalize(sun.direction);
//点乘法线和光照
vec3 diffuse =0.5*dot(world_light_direction,world_normal)+0.5;
//直接光颜色
vec3 direct_color =sun.diffuse*diffuse*sun.color;
#ifndef HAVE_SPECULAR
FragColor=vec4(direct_color,1.0);
#else
//归一代视角方向
vec3 view_direction =normalize(camera.pos-world_position);
//世界坐标下的反射光方向
vec3 reflect_direction =normalize(reflect(-world_light_direction,world_normal));
//高光
vec3 specular =sun.specular*pow(saturate(dot(reflect_direction,view_direction)),gloss);
FragColor=vec4(direct_color+specular,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;
GPUBuffer * ubo_camera_info =nullptr;
GPUBuffer * ubo_color_material =nullptr;
GPUBuffer * ubo_line_config =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_color_material =nullptr;
DeviceBuffer * ubo_line_config =nullptr;
Pipeline * pipeline =nullptr;
@@ -62,9 +62,9 @@ private:
return(true);
}
GPUBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
DeviceBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
{
GPUBuffer *ubo=db->CreateUBO(size,data);
DeviceBuffer *ubo=db->CreateUBO(size,data);
if(!ubo)
return(nullptr);
@@ -82,7 +82,7 @@ private:
cam.RefreshCameraInfo();
{
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetType::Global);
if(!mp_global)
return(false);
@@ -95,7 +95,7 @@ private:
{
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_value)
return(false);

View File

@@ -44,8 +44,8 @@ private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
GPUBuffer * ubo_camera_info =nullptr;
GPUBuffer * ubo_rb_config =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_rb_config =nullptr;
Pipeline * pipeline =nullptr;
@@ -54,15 +54,15 @@ private:
bool InitMaterial()
{
//2D渲染Position坐标全部是使用整数这里强制要求Position输入流使用RGBA16I格式
VABConfigInfo vab_config;
VILConfig vil_config;
VAConfig va_cfg;
va_cfg.format=VF_V4I16;
va_cfg.instance=false;
vab_config.Add("Position",va_cfg);
vil_config.Add("Position",va_cfg);
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/RoundedBox"),&vab_config);
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/RoundedBox"),&vil_config);
if(!material_instance)
return(false);
@@ -74,9 +74,9 @@ private:
return(true);
}
GPUBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
DeviceBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
{
GPUBuffer *ubo=db->CreateUBO(size,data);
DeviceBuffer *ubo=db->CreateUBO(size,data);
if(!ubo)
return(nullptr);
@@ -94,7 +94,7 @@ private:
cam.RefreshCameraInfo();
{
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetType::Global);
if(!mp_global)
return(false);
@@ -108,7 +108,7 @@ private:
}
{
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_value)
return(false);

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,13 +45,24 @@ 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
@@ -57,19 +71,22 @@ private:
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);
render_root.CreateSubNode(render_obj);
if(!render_obj)
return(false);
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);
}

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(int w,int 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

@@ -0,0 +1,166 @@
// 该范例主要演示使用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;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data_float[VERTEX_COUNT*2]=
{
0.0, -0.5,
-0.5, 0.5,
0.5, 0.5
};
#define USE_HALF_FLOAT_POSITION
#ifdef USE_HALF_FLOAT_POSITION
constexpr VkFormat PositionFormat=VF_V2HF;
half_float position_data_hf[VERTEX_COUNT*2];
#define position_data position_data_hf
#else
constexpr VkFormat PositionFormat=VF_V2F;
#define position_data position_data_float
#endif//USE_HALF_FLOAT_POSITION
#define USE_UNORM8_COLOR
#ifdef USE_UNORM8_COLOR
constexpr uint8 color_data[VERTEX_COUNT*4]=
{ 255,0,0,255,
0,255,0,255,
0,0,255,255
};
constexpr VkFormat ColorFormat=VF_V4UN8;
#else
constexpr float color_data[VERTEX_COUNT*4]=
{ 1,0,0,1,
0,1,0,1,
0,0,1,1
};
constexpr VkFormat ColorFormat=VF_V4F;
#endif//USE_UNORM8_COLOR
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;
Pipeline * pipeline =nullptr;
private:
void InitVIL()
{
#ifdef USE_HALF_FLOAT_POSITION
vil_config.Add(VAN::Position,PositionFormat);
#endif//USE_HALF_FLOAT_POSITION
#ifdef USE_UNORM8_COLOR
vil_config.Add(VAN::Color,ColorFormat);
#endif//USE_HALF_FLOAT_POSITION
}
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
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;
}
bool InitVBO()
{
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
#ifdef USE_HALF_FLOAT_POSITION
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
#endif//USE_HALF_FLOAT_POSITION
if(!rpc.SetVBO(VAN::Position, PositionFormat, position_data))return(false);
if(!rpc.SetVBO(VAN::Color, ColorFormat, color_data ))return(false);
render_obj=rpc.Create(material_instance,pipeline);
return(render_obj);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
InitVIL();
if(!InitAutoMaterial())
return(false);
if(!InitPipeline())
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

@@ -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(int w,int 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,230 @@
// 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 * ro_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.width =32;
pgci.grid_size.height=32;
pgci.sub_count.width =8;
pgci.sub_count.height=8;
pgci.lum=0.5;
pgci.sub_lum=0.75;
ro_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(ro_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(int w,int 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/2);
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,126 @@
// 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 * ro_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.width =32;
pgci.grid_size.height=32;
pgci.sub_count.width =8;
pgci.sub_count.height=8;
pgci.lum=0.5;
pgci.sub_lum=1.0;
ro_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
return ro_plane_grid;
}
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
{
Renderable *ri=db->CreateRenderable(ro_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,171 @@
// 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 * ro_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.width =32;
pgci.grid_size.height=32;
pgci.sub_count.width =8;
pgci.sub_count.height=8;
pgci.lum=0.5;
pgci.sub_lum=0.75;
ro_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(ro_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,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,36 +87,37 @@ 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!=VulkanBaseType::NONE)
std::cout<<"[ Depth:"<<std::setw(8)<<data_type_name[size_t(vf->depth)]<<"]";
if(vf->depth!=VulkanNumberType::NONE)
std::cout<<"[Depth:"<<data_type_name[size_t(vf->depth)]<<"]";
if(vf->stencil!=VulkanBaseType::NONE)
std::cout<<"[Stencil:"<<std::setw(8)<<data_type_name[size_t(vf->stencil)]<<"]";
if(vf->stencil!=VulkanNumberType::NONE)
std::cout<<"[Stencil:"<<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;
++vf;

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,21 +42,27 @@ 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->BindSampler(DescriptorSetsType::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,7 +107,7 @@ public:
if(!InitVBO())
return(false);
BuildCommandBuffer(renderable);
BuildCommandBuffer(render_obj);
return(true);
}
@@ -114,7 +116,7 @@ public:
{
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(int w,int 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(int w,int 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

@@ -40,7 +40,7 @@ private:
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline_solid =nullptr;
GPUBuffer * ubo_atomsphere =nullptr;
DeviceBuffer * ubo_atomsphere =nullptr;
AtmosphereData atomsphere_data;
Primitive * ro_sphere =nullptr;
@@ -67,7 +67,7 @@ private:
return(false);
{
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=material_instance->GetMP(DescriptorSetType::Value);
if(!mp)return(false);
@@ -81,7 +81,7 @@ private:
bool InitScene()
{
ro_sphere=inline_geometry::CreateSphere(db,material_instance->GetVAB(),128);
ro_sphere=inline_geometry::CreateSphere(db,material_instance->GetVIL(),128);
render_root.CreateSubNode(scale(100),db->CreateRenderable(ro_sphere,material_instance,pipeline_solid));

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

@@ -35,8 +35,8 @@ private:
Pipeline * sky_pipeline =nullptr;
Pipeline * solid_pipeline =nullptr;
GPUBuffer * ubo_light =nullptr;
GPUBuffer * ubo_phong =nullptr;
DeviceBuffer * ubo_light =nullptr;
DeviceBuffer * ubo_phong =nullptr;
Sampler * sampler =nullptr;
TextureCube * texture =nullptr;
@@ -98,7 +98,7 @@ private:
sky_mi=db->CreateMaterialInstance(sky_material);
if(!sky_mi)return(false);
if(!sky_mi->BindSampler(DescriptorSetsType::Value,"tex" ,texture, sampler))return(false);
if(!sky_mi->BindImageSampler(DescriptorSetType::Value,"tex" ,texture, sampler))return(false);
sky_pipeline=CreatePipeline(sky_mi,InlinePipeline::Sky,Prim::Triangles);
if(!sky_pipeline)return(false);
@@ -111,7 +111,7 @@ private:
envmap_mi=db->CreateMaterialInstance(envmap_material);
if(!envmap_mi)return(false);
if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"EnvCubemap" ,texture, sampler))return(false);
if(!envmap_mi->BindImageSampler(DescriptorSetType::Value,"EnvCubemap" ,texture, sampler))return(false);
solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles);
}
@@ -128,17 +128,17 @@ private:
aci.size=GetCameraInfo().zfar;
ro_axis=CreateAxis(db,axis_mi->GetVAB(),&aci);
ro_axis=CreateAxis(db,axis_mi->GetVIL(),&aci);
}
{
struct CubeCreateInfo cci;
ro_cube=CreateCube(db,sky_mi->GetVAB(),&cci);
ro_cube=CreateCube(db,sky_mi->GetVIL(),&cci);
}
{
ro_sphere=CreateSphere(db,envmap_mi->GetVAB(),64);
ro_sphere=CreateSphere(db,envmap_mi->GetVIL(),64);
}
}

View File

@@ -59,7 +59,7 @@ private:
public:
bool Submit(GPUSemaphore *sem)
bool Submit(Semaphore *sem)
{
return rt->Submit(cmd,sem);
}
@@ -67,7 +67,7 @@ private:
PhongPointLight lights;
GPUBuffer *ubo_lights;
DeviceBuffer *ubo_lights;
struct SubpassParam
{
@@ -136,6 +136,22 @@ private:
};
gbuffer.sampler=db->CreateSampler(&sci);
#ifdef _DEBUG
{
auto da=device->GetDeviceAttribute();
if(da->debug_maker)
{
da->debug_maker->SetSampler(*(gbuffer.sampler), "[debug maker] GBuffer_Sampler");
}
if(da->debug_utils)
{
da->debug_utils->SetSampler(*(gbuffer.sampler), "[debug utils] GBuffer_Sampler");
}
}
#endif//_DEBUG
}
bool InitGBuffer()
@@ -144,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);
@@ -154,6 +170,39 @@ private:
CreateGBufferSampler();
#ifdef _DEBUG
{
auto da=device->GetDeviceAttribute();
VkQueue q=*(gbuffer.rt->GetQueue());
VkFramebuffer fbo= gbuffer.rt->GetFramebuffer()->GetFramebuffer();
VkRenderPass rp= gbuffer.rp->GetVkRenderPass();
VkSemaphore sem=*(gbuffer.rt->GetRenderCompleteSemaphore());
VkCommandBuffer cb=*(gbuffer.cmd);
VkSampler s=*(gbuffer.sampler);
if(da->debug_maker)
{
da->debug_maker->SetQueue( q, "[debug maker] GBufferQueue");
da->debug_maker->SetFramebuffer( fbo,"[debug maker] GBufferFBO");
da->debug_maker->SetRenderPass( rp, "[debug maker] GBufferRenderpass");
da->debug_maker->SetCommandBuffer( cb, "[debug maker] GBufferCommandBuffer");
da->debug_maker->SetSampler( s, "[debug maker] GBufferSampler");
da->debug_maker->SetSemaphore( sem,"[debug maker] GBufferSemaphore");
}
if(da->debug_utils)
{
da->debug_utils->SetQueue( q, "[debug utils] GBufferQueue");
da->debug_utils->SetFramebuffer( fbo,"[debug utils] GBufferFBO");
da->debug_utils->SetRenderPass( rp, "[debug utils] GBufferRenderpass");
da->debug_utils->SetCommandBuffer( cb, "[debug utils] GBufferCommandBuffer");
da->debug_utils->SetSampler( s, "[debug utils] GBufferSampler");
da->debug_utils->SetSemaphore( sem,"[debug utils] GBufferSemaphore");
}
}
#endif//_DEBUG
return(gbuffer.rt);
}
@@ -175,9 +224,28 @@ private:
return(false);
sp->pipeline_fan =gbuffer.rp->CreatePipeline(sp->material_instance,InlinePipeline::Solid3D,Prim::Fan);
if(!sp->pipeline_fan)
return(false);
#ifdef _DEBUG
{
auto da=device->GetDeviceAttribute();
return sp->pipeline_fan;
if(da->debug_maker)
{
da->debug_maker->SetPipeline(*(sp->pipeline_triangles), "[debug maker] GBuffer_Pipeline_Triangles");
da->debug_maker->SetPipeline(*(sp->pipeline_fan), "[debug maker] GBuffer_Pipeline_Fan");
}
if(da->debug_utils)
{
da->debug_utils->SetPipeline(*(sp->pipeline_triangles), "[debug utils] GBuffer_Pipeline_Triangles");
da->debug_utils->SetPipeline(*(sp->pipeline_fan), "[debug utils] GBuffer_Pipeline_Fan");
}
}
#endif//_DEBUG
return(true);
}
bool InitCompositionPipeline(SubpassParam *sp)
@@ -243,50 +311,50 @@ private:
BindCameraUBO(sp_gbuffer.material_instance);
{
MaterialParameters *mp=sp_gbuffer.material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=sp_gbuffer.material_instance->GetMP(DescriptorSetType::Value);
if(!mp)
return(false);
mp->BindSampler("TexColor" ,texture.color, texture.color_sampler);
mp->BindSampler("TexNormal" ,texture.normal, texture.normal_sampler);
mp->BindImageSampler("TexColor" ,texture.color, texture.color_sampler);
mp->BindImageSampler("TexNormal" ,texture.normal, texture.normal_sampler);
mp->Update();
}
BindCameraUBO(sp_composition.material_instance);
{
MaterialParameters *mp=sp_composition.material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=sp_composition.material_instance->GetMP(DescriptorSetType::Value);
if(!mp)
return(false);
mp->BindUBO("lights",ubo_lights);
mp->BindSampler("GB_Color" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Color),gbuffer.sampler);
mp->BindSampler("GB_Normal" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Normal),gbuffer.sampler);
mp->BindSampler("GB_Depth" ,gbuffer.rt->GetDepthTexture(),gbuffer.sampler);
mp->BindImageSampler("GB_Color" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Color),gbuffer.sampler);
mp->BindImageSampler("GB_Normal" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Normal),gbuffer.sampler);
mp->BindImageSampler("GB_Depth" ,gbuffer.rt->GetDepthTexture(),gbuffer.sampler);
mp->Update();
}
return(true);
}
void CreateRenderObject(const VAB *vab)
void CreateRenderObject(const VIL *vil)
{
using namespace inline_geometry;
{
struct PlaneCreateInfo pci;
ro_plane=CreatePlane(db,vab,&pci);
ro_plane=CreatePlane(db,vil,&pci);
}
{
struct CubeCreateInfo cci;
ro_cube=CreateCube(db,vab,&cci);
ro_cube=CreateCube(db,vil,&cci);
}
{
ro_sphere=CreateSphere(db,vab,64);
ro_sphere=CreateSphere(db,vil,64);
}
{
@@ -301,7 +369,7 @@ private:
tci.uv_scale.x=4;
tci.uv_scale.y=1;
ro_torus=CreateTorus(db,vab,&tci);
ro_torus=CreateTorus(db,vil,&tci);
}
{
@@ -311,7 +379,7 @@ private:
cci.radius=10;
cci.numberSlices=32;
ro_cylinder=CreateCylinder(db,vab,&cci);
ro_cylinder=CreateCylinder(db,vil,&cci);
}
{
@@ -322,13 +390,13 @@ private:
cci.numberSlices=128;
cci.numberStacks=32;
ro_cone=CreateCone(db,vab,&cci);
ro_cone=CreateCone(db,vil,&cci);
}
}
bool InitCompositionRenderable()
{
ro_gbc_plane=inline_geometry::CreateGBufferCompositionRectangle(db,sp_composition.material_instance->GetVAB());
ro_gbc_plane=inline_geometry::CreateGBufferCompositionRectangle(db,sp_composition.material_instance->GetVIL());
if(!ro_gbc_plane)return(false);
ro_gbc_plane_ri=db->CreateRenderable(ro_gbc_plane,sp_composition.material_instance,sp_composition.pipeline_fan);
@@ -339,7 +407,7 @@ private:
bool InitScene(SubpassParam *sp)
{
CreateRenderObject(sp->material_instance->GetVAB());
CreateRenderObject(sp->material_instance->GetVIL());
render_root.CreateSubNode( scale(100,100,1), db->CreateRenderable(ro_plane ,sp->material_instance,sp->pipeline_fan ));
render_root.CreateSubNode( db->CreateRenderable(ro_torus ,sp->material_instance,sp->pipeline_triangles));
render_root.CreateSubNode( scale(20,20,20), db->CreateRenderable(ro_sphere ,sp->material_instance,sp->pipeline_triangles));
@@ -362,12 +430,14 @@ private:
if(!gbuffer.cmd->BindFramebuffer(gbuffer.rt->GetRenderPass(),gbuffer.rt->GetFramebuffer()))
return(false);
gbuffer.cmd->BeginRegion("GBuffer Begin",Color4f(1,0,0,1));
if(!gbuffer.cmd->BeginRenderPass())
return(false);
render_list->Render(gbuffer.cmd);
gbuffer.cmd->EndRenderPass();
gbuffer.cmd->EndRegion();
gbuffer.cmd->End();
return(true);

View File

@@ -165,7 +165,7 @@ private:
sampler=db->CreateSampler();
if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",tile_data->GetTexture(),sampler))return(false);
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",tile_data->GetTexture(),sampler))return(false);
return(true);
}

View File

@@ -26,8 +26,8 @@ private:
Pipeline * solid_pipeline =nullptr;
GPUBuffer * ubo_light =nullptr;
GPUBuffer * ubo_phong =nullptr;
DeviceBuffer * ubo_light =nullptr;
DeviceBuffer * ubo_phong =nullptr;
Sampler * sampler =nullptr;
Texture2D * texture =nullptr;
@@ -54,7 +54,7 @@ private:
envmap_mi=db->CreateMaterialInstance(OS_TEXT("res/material/EnvEquirectangularMap"));
if(!envmap_mi)return(false);
if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"Envmap" ,texture, sampler))return(false);
if(!envmap_mi->BindImageSampler(DescriptorSetType::Value,"Envmap" ,texture, sampler))return(false);
}
solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles);
@@ -64,7 +64,7 @@ private:
void CreateRenderObject()
{
ro_sphere=inline_geometry::CreateSphere(db,envmap_mi->GetVAB(),128);
ro_sphere=inline_geometry::CreateSphere(db,envmap_mi->GetVIL(),128);
}
bool InitUBO()

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;
GPUBuffer *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 VAB *vab=material_instance->GetVAB();
ro_plane_grid[0]=CreatePlaneGrid(db,vab,&pgci);
pgci.color.Set(0,0.5,0,1);
pgci.side_color.Set(0,1,0,1);
ro_plane_grid[1]=CreatePlaneGrid(db,vab,&pgci);
pgci.color.Set(0,0,0.5,1);
pgci.side_color.Set(0,0,1,1);
ro_plane_grid[2]=CreatePlaneGrid(db,vab,&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

@@ -49,8 +49,8 @@ private:
Pipeline * axis_pipeline =nullptr;
Pipeline * pipeline_solid =nullptr;
GPUBuffer * ubo_light =nullptr;
GPUBuffer * ubo_phong =nullptr;
DeviceBuffer * ubo_light =nullptr;
DeviceBuffer * ubo_phong =nullptr;
struct
{
@@ -129,13 +129,13 @@ private:
if(!material_instance)return(false);
{
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_texture)
return(false);
mp_texture->BindSampler("TexColor" ,texture.color, texture.sampler);
mp_texture->BindSampler("TexNormal" ,texture.normal, texture.sampler);
mp_texture->BindImageSampler("TexColor" ,texture.color, texture.sampler);
mp_texture->BindImageSampler("TexNormal" ,texture.normal, texture.sampler);
}
}
@@ -154,10 +154,10 @@ private:
aci.size=200;
ro_axis=CreateAxis(db,axis_mi->GetVAB(),&aci);
ro_axis=CreateAxis(db,axis_mi->GetVIL(),&aci);
}
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
{
struct CubeCreateInfo cci;
@@ -166,11 +166,11 @@ private:
cci.tex_coord=true;
cci.color_type=CubeCreateInfo::ColorType::SameColor;
cci.color[0]=Vector4f(1,1,1,1);
ro_cube=CreateCube(db,vab,&cci);
ro_cube=CreateCube(db,vil,&cci);
}
{
ro_sphere=CreateSphere(db,vab,64);
ro_sphere=CreateSphere(db,vil,64);
}
{
@@ -185,7 +185,7 @@ private:
tci.uv_scale.x=4;
tci.uv_scale.y=1;
ro_torus=CreateTorus(db,vab,&tci);
ro_torus=CreateTorus(db,vil,&tci);
}
{
@@ -195,7 +195,7 @@ private:
cci.radius=10;
cci.numberSlices=32;
ro_cylinder=CreateCylinder(db,vab,&cci);
ro_cylinder=CreateCylinder(db,vil,&cci);
}
{
@@ -206,7 +206,7 @@ private:
cci.numberSlices=128;
cci.numberStacks=32;
ro_cone=CreateCone(db,vab,&cci);
ro_cone=CreateCone(db,vil,&cci);
}
}
@@ -216,7 +216,7 @@ private:
ubo_phong=db->CreateUBO(sizeof(PhongMaterial),&phong);
{
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_value)
return(false);

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

@@ -16,7 +16,7 @@ class TestApp:public CameraAppFramework
Camera cam;
MaterialInstance * material_instance =nullptr;
GPUBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
};
struct:public RenderObject
@@ -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();
@@ -107,7 +107,7 @@ public:
cci.center_color=Vector4f(1,1,1,1);
cci.border_color=Vector4f(1,1,1,0);
Primitive *primitive=CreateCircle(db,os.material_instance->GetVAB(),&cci);
Primitive *primitive=CreateCircle(db,os.material_instance->GetVIL(),&cci);
if(!primitive)return(false);
os.renderable=db->CreateRenderable(primitive,os.material_instance,os.pipeline);
@@ -135,7 +135,7 @@ public:
cube.sampler=db->CreateSampler();
if(!cube.sampler)return(false);
if(!cube.material_instance->BindSampler(DescriptorSetsType::Value,"tex",os.render_taget->GetColorTexture(),cube.sampler))
if(!cube.material_instance->BindImageSampler(DescriptorSetType::Value,"tex",os.render_taget->GetColorTexture(),cube.sampler))
return(false);
{
@@ -145,7 +145,7 @@ public:
cci.tex_coord=true;
Primitive *primitive=CreateCube(db,cube.material_instance->GetVAB(),&cci);
Primitive *primitive=CreateCube(db,cube.material_instance->GetVIL(),&cci);
if(!primitive)return(false);
cube.renderable=db->CreateRenderable(primitive,cube.material_instance,cube.pipeline);

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;
GPUBuffer *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 VAB *vab=material_instance->GetVAB();
ro_plane_grid=CreatePlaneGrid(db,vab,&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->BindSampler(DescriptorSetsType::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

@@ -33,8 +33,8 @@ private:
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
GPUBuffer * ubo_color =nullptr;
GPUBuffer * ubo_sun =nullptr;
DeviceBuffer * ubo_color =nullptr;
DeviceBuffer * ubo_sun =nullptr;
Primitive * primitive =nullptr;
@@ -67,7 +67,7 @@ private:
void CreateRenderObject()
{
primitive=inline_geometry::CreateSphere(db,material_instance->GetVAB(),40);
primitive=inline_geometry::CreateSphere(db,material_instance->GetVIL(),40);
}
bool InitUBO()
@@ -84,7 +84,7 @@ private:
if(!ubo_sun)return(false);
{
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=material_instance->GetMP(DescriptorSetType::Value);
if(!mp)return(false);

View File

@@ -21,7 +21,7 @@ class TestApp:public CameraAppFramework
{
SkyColorConfig scc;
GPUBuffer *ubo_color=nullptr;
DeviceBuffer *ubo_color=nullptr;
private:
@@ -32,7 +32,7 @@ private:
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline =nullptr;
GPUBuffer * ubo_sky_color =nullptr;
DeviceBuffer * ubo_sky_color =nullptr;
Primitive * ro_skyphere =nullptr;
@@ -71,7 +71,7 @@ private:
if(!ubo_sky_color)
return(false);
if(!material_instance->BindUBO(DescriptorSetsType::Value,"sky_color",ubo_sky_color))
if(!material_instance->BindUBO(DescriptorSetType::Value,"sky_color",ubo_sky_color))
return(false);
return(true);
@@ -88,9 +88,9 @@ private:
void CreateRenderObject()
{
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
ro_skyphere=inline_geometry::CreateDome(db,vab,64);
ro_skyphere=inline_geometry::CreateDome(db,vil,64);
}
bool InitScene()

View File

@@ -28,7 +28,7 @@ constexpr uint32_t SCREEN_HEIGHT=720;
/**
* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
Primitive *CreateRenderableTerrain(RenderResource *db,const VAB *vab,const TerrainCreateInfo *tci)
Primitive *CreateRenderableTerrain(RenderResource *db,const VIL *vil,const TerrainCreateInfo *tci)
{
}
@@ -36,7 +36,7 @@ class TestApp:public CameraAppFramework
{
Color4f color;
GPUBuffer *ubo_color=nullptr;
DeviceBuffer *ubo_color=nullptr;
private:
@@ -95,9 +95,9 @@ private:
pgci.color.Set(0.75,0.75,0.75);
pgci.side_color.Set(1,0,0,1);
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
renderable=CreatePlaneGrid(db,vab,&pgci);
renderable=CreatePlaneGrid(db,vil,&pgci);
}
bool InitScene()

View File

@@ -1,103 +0,0 @@
// first_triangle
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
#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]=
{
{ 0.0, -0.5},
{-0.5, 0.5},
{ 0.5, 0.5}
};
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_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

@@ -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,105 +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,13 +2,13 @@
#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>
#include<hgl/graph/VKImageView.h>
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VKDescriptorSets.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKRenderPass.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKCommandBuffer.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/type/Color.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:
@@ -60,14 +71,15 @@ protected:
protected:
Camera * camera =nullptr;
GPUBuffer * 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);
@@ -80,7 +92,12 @@ public:
virtual bool Init(int w,int 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;
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->global_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
return(true);
}
const CameraInfo &GetCameraInfo()
{
return camera->info;
}
GPUBuffer *GetCameraInfoBuffer()
{
return ubo_camera_info;
}
bool BindCameraUBO(MaterialInstance *mi)
{
return mi->BindUBO(DescriptorSetsType::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;
vp_info.Set(w,h);
ubo_vp_info->Write(&vp_info);
}
camera->RefreshCameraInfo();
ViewportInfo &GetViewportInfo()
{
return vp_info;
}
ubo_camera_info->Write(&camera->info);
DeviceBuffer *GetViewportInfoBuffer()
{
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:
@@ -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(int w,int 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,18 +518,31 @@ 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
{
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;
@@ -510,7 +550,8 @@ public:
virtual void Draw()override
{
camera_control->Refresh(); //更新相机矩阵
ubo_camera_info->Write(&camera->info); //写入缓冲区
ubo_camera_info->Write(&camera_control->GetCameraInfo()); //写入缓冲区
const uint32_t index=AcquireNextImage();
@@ -522,3 +563,54 @@ public:
cmc->Update();
}
};//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(int width,int 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(int w,int 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,7 +4,8 @@
#include<hgl/graph/VK.h>
#include<hgl/math/Vector.h>
#include<hgl/type/RectScope.h>
#include<hgl/type/Color4f.h>
#include<hgl/type/Size2.h>
#include<hgl/color/Color4f.h>
#include<hgl/graph/AABB.h>
namespace hgl
{
@@ -20,12 +21,12 @@ namespace hgl
RectScope2f scope;
};//struct RectangleCreateInfo
Primitive *CreateRectangle(RenderResource *db,const VAB *vab,const RectangleCreateInfo *rci);
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci);
/**
* 创建延迟渲染用全屏平面
*/
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VAB *vab);
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil);
/**
* 圆角矩形创建信息(扇形/线圈)
@@ -36,7 +37,7 @@ namespace hgl
uint32_t round_per; ///<圆角精度
};//struct RoundRectangleCreateInfo:public RectangleCreateInfo
Primitive *CreateRoundRectangle(RenderResource *db,const VAB *vab,const RoundRectangleCreateInfo *rci);
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci);
/**
* 圆形创建信息
@@ -56,44 +57,31 @@ namespace hgl
/**
* 创建一个2D圆形(扇形/线圈)
*/
Primitive *CreateCircle(RenderResource *db,const VAB *vab,const CircleCreateInfo *cci);
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
/**
* 创建一个平面网格(线条)
*/
Primitive *CreatePlaneGrid(RenderResource *db,const VAB *vab,const PlaneGridCreateInfo *pgci);
struct PlaneCreateInfo
{
Vector2f tile;
public:
PlaneCreateInfo()
{
tile.x=1.0f;
tile.y=1.0f;
}
};//struct PlaneCreateInfo
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
/**
* 创建一个平面(三角形)
*/
Primitive *CreatePlane(RenderResource *db,const VAB *vab,const PlaneCreateInfo *pci);
Primitive *CreatePlane(RenderResource *db,const VIL *vil);
struct CubeCreateInfo
{
@@ -129,7 +117,7 @@ namespace hgl
/**
* 创建一个立方体(三角形)
*/
Primitive *CreateCube(RenderResource *db,const VAB *vab,const CubeCreateInfo *cci);
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci);
struct BoundingBoxCreateInfo
{
@@ -160,17 +148,17 @@ namespace hgl
/**
* 创建一个绑定盒(线条)
*/
Primitive *CreateBoundingBox(RenderResource *db,const VAB *vab,const BoundingBoxCreateInfo *cci);
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci);
/**
* 创建一个球心坐标为0,0,0半径为1的球体(三角形)
*/
Primitive *CreateSphere(RenderResource *db,const VAB *vab,const uint numberSlices);
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices);
/**
* 创建一个穹顶(三角形)
*/
Primitive *CreateDome(RenderResource *db,const VAB *vab, const uint numberSlices);
Primitive *CreateDome(RenderResource *db,const VIL *vil, const uint numberSlices);
struct TorusCreateInfo
{
@@ -186,7 +174,7 @@ namespace hgl
/**
* 创建一个圆环(三角形)
*/
Primitive *CreateTorus(RenderResource *db,const VAB *vab,const TorusCreateInfo *tci);
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci);
struct CylinderCreateInfo
{
@@ -198,7 +186,7 @@ namespace hgl
/**
* 创建一个圆柱(三角形)
*/
Primitive *CreateCylinder(RenderResource *db,const VAB *vab,const CylinderCreateInfo *cci);
Primitive *CreateCylinder(RenderResource *db,const VIL *vil,const CylinderCreateInfo *cci);
struct ConeCreateInfo
{
@@ -211,7 +199,7 @@ namespace hgl
/**
* 创建一个圆锥(三角形)
*/
Primitive *CreateCone(RenderResource *db,const VAB *vab,const ConeCreateInfo *cci);
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci);
struct AxisCreateInfo
{
@@ -232,7 +220,7 @@ namespace hgl
/**
* 创建一个坐标线(线条)
*/
Primitive *CreateAxis(RenderResource *db,const VAB *vab,const AxisCreateInfo *aci);
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci);
}//namespace inline_geometry
}//namespace graph
};//namespace hgl

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,7 +8,12 @@ namespace hgl
{
namespace graph
{
struct ShaderStageBind
/**
* 可绘制图元创建器
*/
class PrimitiveCreater
{
struct PrimitiveVertexBuffer
{
AnsiString name;
uint binding;
@@ -17,36 +22,31 @@ namespace hgl
public:
~ShaderStageBind()
~PrimitiveVertexBuffer()
{
SAFE_CLEAR(data);
}
};//struct ShaderStageBind
};//struct PrimitiveVertexBuffer
using ShaderStageBindMap=MapObject<AnsiString,ShaderStageBind>;
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
/**
* 可绘制图元创建器
*/
class PrimitiveCreater
{
protected:
RenderResource *db;
Material *mtl;
const VAB *vab;
const VIL *vil;
protected:
uint32 vertices_number;
IndexBuffer * ibo;
ShaderStageBindMap ssb_map;
PVBMap vbo_map;
public:
PrimitiveCreater(RenderResource *sdb,const VAB *);
PrimitiveCreater(RenderResource *sdb,const VIL *);
virtual ~PrimitiveCreater()=default;
virtual bool Init(const uint32 vertices_count); ///<初始化,参数为顶点数量
@@ -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=vab->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,71 +2,41 @@
#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/type/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
{
protected:
GPUDevice * device;
RenderCmdBuffer *cmd_buf;
private:
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)DescriptorSetsType::RANGE_SIZE];
DescriptorSets *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)DescriptorSetsType::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 *);
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void Clear(); ///<彻底清理
};//class RenderList
}//namespace graph
}//namespace hgl

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

@@ -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消耗。
@@ -48,7 +33,7 @@ namespace hgl
protected:
GPUBuffer *tile_buffer; ///<Tile暂存缓冲区
DeviceBuffer *tile_buffer; ///<Tile暂存缓冲区
List<Image2DRegion> commit_list;
uint8 *commit_ptr;

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>
@@ -33,12 +32,12 @@ class VulkanInstance;
class GPUPhysicalDevice;
class GPUDevice;
struct GPUDeviceAttribute;
class GPUQueue;
class DeviceQueue;
class ImageView;
class Framebuffer;
struct Swapchain;
class RenderTarget;
class SwapchainRenderTarget;
class RTSwapchain;
class Texture;
class Texture1D;
@@ -51,15 +50,21 @@ class TextureCubeArray;
class Sampler;
class GPUMemory;
class GPUBuffer;
struct GPUBufferData;
class DeviceMemory;
class DeviceBuffer;
struct DeviceBufferData;
class VertexAttribBuffer;
using VBO=VertexAttribBuffer;
class IndexBuffer;
struct IndexBufferData
{
IndexBuffer *buffer=nullptr;
VkDeviceSize offset=0;
};
class GPUCmdBuffer;
class RenderCmdBuffer;
class TextureCmdBuffer;
@@ -67,46 +72,18 @@ class TextureCmdBuffer;
class RenderPass;
class DeviceRenderPassManage;
class GPUFence;
class GPUSemaphore;
enum class DescriptorSetsType
{
//设计使其对应shader中的set
Global=0, ///<全局参数(如太阳光等)
Material, ///<材质中永远不变的参数
// Texture, ///<材质中的纹理参数
Value, ///<材质中的变量参数
Primitive, ///<渲染实例参数(如Local2World matrix)
ENUM_CLASS_RANGE(Global,Primitive)
};//
const DescriptorSetsType CheckDescriptorSetsType(const char *str);
constexpr char *DescriptSetsTypeName[]=
{
"Global","Material","Value","Renderable"
};
inline const char *GetDescriptorSetsTypeName(const enum class DescriptorSetsType &type)
{
ENUM_CLASS_RANGE_ERROR_RETURN_NULLPTR(type);
return DescriptSetsTypeName[(size_t)type];
}
class Fence;
class Semaphore;
struct PipelineLayoutData;
class DescriptorSets;
class DescriptorSet;
struct ShaderStage;
struct ShaderAttribute;
class ShaderResource;
class ShaderModule;
class VertexShaderModule;
class ShaderModuleMap;
class MaterialDescriptorSets;
class MaterialDescriptorManager;
class Material;
class MaterialParameters;
@@ -115,20 +92,14 @@ struct PipelineData;
enum class InlinePipeline;
class Pipeline;
struct VAConfig
{
VkFormat format=PF_UNDEFINED;
bool instance=false;
struct VAConfig;
class VILConfig;
class VertexInput;
public:
struct VertexInputFormat;
CompOperatorMemcmp(const VAConfig &);
};
using VABConfigInfo=Map<AnsiString,VAConfig>;
class VertexAttributeBinding;
using VAB=VertexAttributeBinding;
class VertexInputLayout;
using VIL=VertexInputLayout;
class Primitive;
class Renderable;
@@ -166,38 +137,13 @@ 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:
*
@@ -218,61 +164,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();
}
GPUBuffer *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

@@ -4,19 +4,19 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKMemory.h>
VK_NAMESPACE_BEGIN
struct GPUBufferData
struct DeviceBufferData
{
VkBuffer buffer;
GPUMemory * memory=nullptr;
VkBuffer buffer=nullptr;
DeviceMemory * memory=nullptr;
VkDescriptorBufferInfo info;
};//struct GPUBufferData
};//struct DeviceBufferData
class GPUBuffer
class DeviceBuffer
{
protected:
VkDevice device;
GPUBufferData buf;
DeviceBufferData buf;
private:
@@ -24,7 +24,7 @@ private:
friend class VertexAttribBuffer;
friend class IndexBuffer;
GPUBuffer(VkDevice d,const GPUBufferData &b)
DeviceBuffer(VkDevice d,const DeviceBufferData &b)
{
device=d;
buf=b;
@@ -32,10 +32,11 @@ private:
public:
virtual ~GPUBuffer();
virtual ~DeviceBuffer();
VkBuffer GetBuffer ()const{return buf.buffer;}
GPUMemory * GetMemory ()const{return buf.memory;}
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();}
@@ -47,6 +48,6 @@ public:
bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
};//class GPUBuffer
};//class DeviceBuffer
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_BUFFER_INCLUDE

View File

@@ -2,9 +2,10 @@
#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/VKDescriptorSets.h>
#include<hgl/type/Color4f.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/color/Color4f.h>
VK_NAMESPACE_BEGIN
class GPUCmdBuffer
{
@@ -27,11 +28,11 @@ public:
bool End(){return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);}
#ifdef _DEBUG
void SetDebugName(const char *);
void BeginRegion(const char *,const Color4f &);
void SetDebugName(const UTF8String &);
void BeginRegion(const UTF8String &,const Color4f &);
void EndRegion();
#else
void BeginRegion(const char *,const Color4f &){}
void BeginRegion(const UTF8String &,const Color4f &){}
void EndRegion(){}
#endif//_DEBUG
};//class GPUCmdBuffer
@@ -43,8 +44,6 @@ class RenderCmdBuffer:public GPUCmdBuffer
VkRect2D render_area;
VkViewport viewport;
float default_line_width;
Framebuffer *fbo;
RenderPassBeginInfo rp_begin;
VkPipelineLayout pipeline_layout;
@@ -105,7 +104,7 @@ public:
return(true);
}
bool BindDescriptorSets(DescriptorSets *dsl)
bool BindDescriptorSets(DescriptorSet *dsl)
{
if(!dsl)return(false);
@@ -118,7 +117,7 @@ public:
return(true);
}
bool BindDescriptorSets(DescriptorSets *dsl,const uint32_t offset)
bool BindDescriptorSets(DescriptorSet *dsl,const uint32_t offset)
{
if(!dsl)return(false);
@@ -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);}

View File

@@ -1,66 +0,0 @@
#ifndef HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
#define HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/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##Name(Vk##type obj,const char *name){SetObjectName((uint64_t)obj,VK_DEBUG_REPORT_OBJECT_TYPE_##MNAME##_EXT,name);}
DEBUG_MAKER_SET_FUNC(CommandBuffer, COMMAND_BUFFER)
DEBUG_MAKER_SET_FUNC(Queue, QUEUE)
DEBUG_MAKER_SET_FUNC(Image, IMAGE)
DEBUG_MAKER_SET_FUNC(Sampler, SAMPLER)
DEBUG_MAKER_SET_FUNC(Buffer, BUFFER)
DEBUG_MAKER_SET_FUNC(DeviceMemory, DEVICE_MEMORY)
DEBUG_MAKER_SET_FUNC(ShaderModule, SHADER_MODULE)
DEBUG_MAKER_SET_FUNC(Pipeline, PIPELINE)
DEBUG_MAKER_SET_FUNC(PipelineLayout, PIPELINE_LAYOUT)
DEBUG_MAKER_SET_FUNC(RenderPass, RENDER_PASS)
DEBUG_MAKER_SET_FUNC(Framebuffer, FRAMEBUFFER)
DEBUG_MAKER_SET_FUNC(DescriptorSetLayout, DESCRIPTOR_SET_LAYOUT)
DEBUG_MAKER_SET_FUNC(DescriptorSet, DESCRIPTOR_SET)
DEBUG_MAKER_SET_FUNC(Semaphore, SEMAPHORE)
DEBUG_MAKER_SET_FUNC(Fence, FENCE)
DEBUG_MAKER_SET_FUNC(Event, EVENT)
#undef DEBUG_MAKER_SET_FUNC
};//class DebugMaker
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE

View File

@@ -0,0 +1,105 @@
#ifndef HGL_GRAPH_VULKAN_DEBUG_UTILS_INCLUDE
#define HGL_GRAPH_VULKAN_DEBUG_UTILS_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/color/Color4f.h>
VK_NAMESPACE_BEGIN
struct DebugUtilsFunction
{
PFN_vkSetDebugUtilsObjectNameEXT SetName;
PFN_vkSetDebugUtilsObjectTagEXT SetTag;
PFN_vkQueueBeginDebugUtilsLabelEXT QueueBegin;
PFN_vkQueueEndDebugUtilsLabelEXT QueueEnd;
PFN_vkQueueInsertDebugUtilsLabelEXT QueueInsert;
PFN_vkCmdBeginDebugUtilsLabelEXT CmdBegin;
PFN_vkCmdEndDebugUtilsLabelEXT CmdEnd;
PFN_vkCmdInsertDebugUtilsLabelEXT CmdInsert;
};//struct DebugUtilsFunction
class DebugUtils
{
VkDevice device;
DebugUtilsFunction duf;
private:
friend DebugUtils *CreateDebugUtils(VkDevice);
DebugUtils(VkDevice dev,const DebugUtilsFunction &f)
{
device=dev;
duf=f;
}
public:
~DebugUtils()=default;
void SetName(VkObjectType,uint64_t,const char *);
#define DU_FUNC(n,N) void Set##n(Vk##n obj,const char *name){SetName(VK_OBJECT_TYPE_##N,(uint64_t)obj,name);}
DU_FUNC(Instance ,INSTANCE )
DU_FUNC(PhysicalDevice ,PHYSICAL_DEVICE )
DU_FUNC(Device ,DEVICE )
DU_FUNC(Queue ,QUEUE )
DU_FUNC(Semaphore ,SEMAPHORE )
DU_FUNC(CommandBuffer ,COMMAND_BUFFER )
DU_FUNC(Fence ,FENCE )
DU_FUNC(DeviceMemory ,DEVICE_MEMORY )
DU_FUNC(Buffer ,BUFFER )
DU_FUNC(Image ,IMAGE )
DU_FUNC(Event ,EVENT )
DU_FUNC(QueryPool ,QUERY_POOL )
DU_FUNC(BufferView ,BUFFER_VIEW )
DU_FUNC(ImageView ,IMAGE_VIEW )
DU_FUNC(ShaderModule ,SHADER_MODULE )
DU_FUNC(PipelineCache ,PIPELINE_CACHE )
DU_FUNC(PipelineLayout ,PIPELINE_LAYOUT )
DU_FUNC(RenderPass ,RENDER_PASS )
DU_FUNC(Pipeline ,PIPELINE )
DU_FUNC(DescriptorSetLayout ,DESCRIPTOR_SET_LAYOUT )
DU_FUNC(Sampler ,SAMPLER )
DU_FUNC(DescriptorPool ,DESCRIPTOR_POOL )
DU_FUNC(DescriptorSet ,DESCRIPTOR_SET )
DU_FUNC(Framebuffer ,FRAMEBUFFER )
DU_FUNC(CommandPool ,COMMAND_POOL )
DU_FUNC(SamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION)
DU_FUNC(DescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE)
DU_FUNC(PrivateDataSlot, PRIVATE_DATA_SLOT)
DU_FUNC(SurfaceKHR, SURFACE_KHR)
DU_FUNC(SwapchainKHR, SWAPCHAIN_KHR)
DU_FUNC(DisplayKHR, DISPLAY_KHR)
DU_FUNC(DisplayModeKHR, DISPLAY_MODE_KHR)
DU_FUNC(DebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT)
#ifdef VK_ENABLE_BETA_EXTENSIONS
DU_FUNC(VideoSessionKHR, VIDEO_SESSION_KHR)
DU_FUNC(VideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KH)
#endif//VK_ENABLE_BETA_EXTENSIONS
DU_FUNC(CuModuleNVX, CU_MODULE_NVX)
DU_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
DU_FUNC(DebugUtilsMessengerEXT, DEBUG_UTILS_MESSENGER_EXT)
DU_FUNC(AccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR)
DU_FUNC(ValidationCacheEXT, VALIDATION_CACHE_EXT)
DU_FUNC(AccelerationStructureNV, ACCELERATION_STRUCTURE_NV)
DU_FUNC(PerformanceConfigurationINTEL, PERFORMANCE_CONFIGURATION_INTEL)
DU_FUNC(DeferredOperationKHR, DEFERRED_OPERATION_KHR)
DU_FUNC(IndirectCommandsLayoutNV, INDIRECT_COMMANDS_LAYOUT_NV)
// DU_FUNC(BufferCollectionFuchsia, BUFFER_COLLECTION_FUCHSIA)
#undef DU_FUNC
void QueueBegin (VkQueue,const char *,const Color4f &color=Color4f(1,1,1,1));
void QueueEnd (VkQueue q){duf.QueueEnd(q);}
void QueueInsert (VkQueue q,const char *,const Color4f &color=Color4f(1,1,1,1));
void CmdBegin (VkCommandBuffer,const char *,const Color4f &color=Color4f(1,1,1,1));
void CmdEnd (VkCommandBuffer cmd_buf){duf.CmdEnd(cmd_buf);}
void CmdInsert (VkCommandBuffer cmd_buf,const char *,const Color4f &color=Color4f(1,1,1,1));
};//class DebugUtils
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEBUG_UTILS_INCLUDE

View File

@@ -0,0 +1,100 @@
#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/VKDescriptorSetType.h>
namespace hgl
{
namespace graph
{
class DeviceBuffer;
class Texture;
class Material;
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);
}
bool Bind(Material *);
};//class DescriptorBinding
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE

View File

@@ -1,13 +1,14 @@
#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 GPUBuffer;
class DeviceBuffer;
class DescriptorSets
class DescriptorSet
{
VkDevice device;
int binding_count;
@@ -23,11 +24,9 @@ class DescriptorSets
bool is_dirty;
private:
public:
friend class GPUDevice;
DescriptorSets(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
{
device =dev;
binding_count =bc;
@@ -37,9 +36,7 @@ private:
is_dirty=true;
}
public:
~DescriptorSets()=default;
~DescriptorSet()=default;
const uint32_t GetCount ()const{return binding_count;}
const VkDescriptorSet GetDescriptorSet ()const{return desc_set;}
@@ -49,14 +46,14 @@ public:
void Clear();
bool BindUBO (const int binding,const GPUBuffer *buf,bool dynamic=false);
bool BindUBO (const int binding,const GPUBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindSSBO (const int binding,const GPUBuffer *buf,bool dynamic=false);
bool BindSSBO (const int binding,const GPUBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindUBO (const int binding,const DeviceBuffer *buf,bool dynamic=false);
bool BindUBO (const int binding,const DeviceBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindSSBO (const int binding,const DeviceBuffer *buf,bool dynamic=false);
bool BindSSBO (const int binding,const DeviceBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindSampler(const int binding,Texture *,Sampler *);
bool BindImageSampler(const int binding,Texture *,Sampler *);
bool BindInputAttachment(const int binding,ImageView *);
void Update();
};//class DescriptorSets
};//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>
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl
{
namespace graph
{
VK_NAMESPACE_BEGIN
class TileData;
class TileFont;
class FontSource;
}//namespace graph
}//namespace hgl
class GPUArrayBuffer;
VK_NAMESPACE_BEGIN
/*
* GPU设备创建信息
*/
struct GPUDeviceCreateInfo
{
VkPhysicalDeviceType device_type =VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM;
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;
GPUQueue *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 &);
@@ -110,40 +99,45 @@ public:
public: //内存相关
GPUMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);
GPUMemory *CreateMemory(VkImage,const uint32 flag=VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
DeviceMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);
DeviceMemory *CreateMemory(VkImage,const uint32 flag=VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
private: //Buffer相关
bool CreateBuffer(GPUBufferData *buf,VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data,SharingMode sharing_mode);
bool CreateBuffer(GPUBufferData *buf,VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data,SharingMode sharing_mode){return CreateBuffer(buf,buf_usage,size,size,data,sharing_mode);}
bool CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data,SharingMode sharing_mode);
bool CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data,SharingMode sharing_mode){return CreateBuffer(buf,buf_usage,size,size,data,sharing_mode);}
public: //Buffer相关
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive);
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,range,size,nullptr,sm);}
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive);
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,range,size,nullptr,sm);}
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,data,sm);}
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,nullptr,sm);}
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,data,sm);}
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,nullptr,sm);}
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->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) GPUBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
GPUBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
GPUBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,data, sm);} \
GPUBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);}
#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);} \
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,data, sm);} \
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);}
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
@@ -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,13 +155,21 @@ public: //Image
private: //texture
bool CommitTexture (Texture *,GPUBuffer *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 CommitTexture2D (Texture2D *,GPUBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
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 CommitTextureCube (TextureCube *,GPUBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
bool CommitTextureCubeMipmaps (TextureCube *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool CommitTextureCube (TextureCube *,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
bool CommitTextureCubeMipmaps (TextureCube *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
@@ -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 *,GPUBuffer *buf,const List<Image2DRegion> &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,GPUBuffer *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,GPUBuffer *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,46 +206,37 @@ public: //
public: //shader & material
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorSets *);
void Destroy(PipelineLayoutData *);
ShaderModule *CreateShaderModule(VkShaderStageFlagBits,const uint32_t *,const size_t);
DescriptorSets * CreateDescriptorSets(const PipelineLayoutData *,const DescriptorSetsType &type)const;
MaterialParameters *CreateMP(const MaterialDescriptorSets *,const PipelineLayoutData *,const DescriptorSetsType &);
MaterialParameters *CreateMP(Material *,const DescriptorSetsType &);
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorManager *desc_manager);
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 *);
MaterialInstance *CreateMI(Material *,const VABConfigInfo *vab_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:
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
GPUFence * CreateFence(bool);
GPUSemaphore * CreateGPUSemaphore();
Fence * CreateFence(bool);
Semaphore * CreateGPUSemaphore();
GPUQueue * 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:
@@ -263,7 +244,5 @@ public:
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,7 @@
#include<hgl/graph/VKTexture.h>
#ifdef _DEBUG
#include<hgl/graph/VKDebugMaker.h>
#include<hgl/graph/VKDebugUtils.h>
#endif//_DEBUG
VK_NAMESPACE_BEGIN
@@ -24,14 +24,15 @@ struct GPUDeviceAttribute
uint32_t graphics_family =ERROR_FAMILY_INDEX;
uint32_t present_family =ERROR_FAMILY_INDEX;
uint32_t compute_family =ERROR_FAMILY_INDEX;
uint32_t 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;
@@ -46,7 +47,7 @@ struct GPUDeviceAttribute
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
#ifdef _DEBUG
DebugMaker * debug_maker =nullptr;
DebugUtils * debug_utils =nullptr;
#endif//_DEBUG
public:

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

@@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class GPUFence
class Fence
{
VkDevice device;
VkFence fence;
@@ -12,7 +12,7 @@ private:
friend class GPUDevice;
GPUFence(VkDevice d,VkFence f)
Fence(VkDevice d,VkFence f)
{
device=d;
fence=f;
@@ -20,9 +20,9 @@ private:
public:
~GPUFence();
~Fence();
operator VkFence(){return fence;}
};//class GPUFence
};//class Fence
VK_NAMESPACE_END
#endif//HGL_VULKAN_GRAPH_FENCE_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

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