Compare commits

...

60 Commits

Author SHA1 Message Date
368056bb96 调整好坐标轴方向以及裁剪面,并增加最简易坐标轴绘制范例 2025-06-18 01:55:53 +08:00
d1a1437e6f 删除废弃不要的范例 2025-06-18 00:38:35 +08:00
15da48eede 部分内置几何体增加BoundingBox数据计算 2025-06-17 01:17:57 +08:00
585fd41966 VKBufferMap::Set改名为Bind,VABMap::SetVAB改名为BindVAB 2025-06-17 00:58:36 +08:00
91b056bacb 定义using SceneNodeList =ObjectList<SceneNode> 2025-06-17 00:42:50 +08:00
7d41722baa ComponentData改用SharedPtr保存,这样在复制Component时,不会对数据产生真正的复制 2025-06-17 00:34:42 +08:00
dd083bb82b 实现了由Component实现的自我复制,而无需关心具体的Component派生类. 2025-06-16 00:28:21 +08:00
a23654c73a 恢复Duplication(SceneNode *),并实现MeshComponent::Duplication...下一步Component::Duplication()改成由基类实现. 2025-06-16 00:02:07 +08:00
dd2ee57954 迁移Gizmo3DMove成功可绘制,但是退出崩溃。疑似重复delete 2025-06-15 23:25:08 +08:00
e9c3961aa5 更新兼容性 2025-06-15 22:59:24 +08:00
dfa0b4033d 迁移CreatePipeline/CreateMaterialInstance/GetPrimitiveCreater到RenderFramework 2025-06-15 22:26:30 +08:00
d384f06ee2 CreatePrimitive/CreateMesh迁移到RenderFramework 2025-06-15 22:03:03 +08:00
93937c0394 CreateComponent函数迁移到RenderFramework 2025-06-15 21:58:07 +08:00
db15096943 重建渲染器时不删除mouse_event,以修正窗口调整大小后mouse_event丢失问题 2025-06-15 21:08:49 +08:00
97040176d6 StaticMeshComponent改为MeshComponent 2025-06-15 17:53:15 +08:00
ec4125776a 准备修复Gizmo 2025-06-15 07:43:13 +08:00
a180970eb6 迁移auto_merge_material_instance,BillboardTest,PlaneGrid3D,RayPicking四个测试范例到新的Component结构 2025-06-15 02:03:38 +08:00
cfda1fceb2 ComponentManager增加自动释放功能 2025-06-15 00:49:23 +08:00
c1420e257d SceneComponent增加了SceneOrient父类,所有SceneComponent增加变换属性 2025-06-14 23:42:50 +08:00
f9675fc1e5 迁移到StaticMeshComponent渲染 2025-06-14 21:05:36 +08:00
92f612f675 改进Component/Manager设计,在WorkObject封装Component相关模板函数,以减化使用部分。当前版本可运行,下一版迁移旧的Renderable渲染到StaticMeshComponent. 2025-06-14 18:47:54 +08:00
edaf5aa3ca 尝试制作StaticMeshComponent 2025-06-14 04:13:49 +08:00
8ee9cdc396 尝试初建StaticMeshComponent 2025-06-14 02:32:15 +08:00
87c150d1bd 准备开始实现StaticMeshComponent 2025-06-12 03:01:50 +08:00
3fd6f98ef7 材质保存来自MaterialCreateInfo传递而来的PrimitiveType信息,并在创建Pipeline时传递.
减少在使用中的第二次手写传递,避免失误。
2025-06-12 00:00:14 +08:00
5935c3140f 黄线也改用V1UN8格式的亮度 2025-06-11 23:22:09 +08:00
f24e4704a1 使用新的prim_line创建方式在RayPicking 2025-06-11 01:17:04 +08:00
709c8be94d 迁移RayPicking范例到新架构上 2025-06-11 01:12:14 +08:00
660d8fff6d RenderResource缓存材质增加HashString以解决同名不同配置冲突问题 2025-06-11 01:11:54 +08:00
0fbe85290b 增加MaterialCreateConfig::ToHashString函数,用于在未来生成区分同一材质不同配置的字串 2025-06-11 01:11:12 +08:00
0c3cc5a320 增加CoordinateSystem2DName和GetCoordinateSystem2DName 2025-06-11 01:10:15 +08:00
3057fc7b6f 传递MouseCoord到WorkObject 2025-06-11 01:05:24 +08:00
73027ffd9a WorkObject增加GetPrimitiveCreater函数,并连带更新BillboardTest/PlaneGrid3D 2025-06-10 23:46:19 +08:00
6635d33461 更新BillboardTest/PlaneGrid3D,支持新的CameraControl::SetPosition/SetTarget,简化初始化设置操作 2025-06-10 23:36:46 +08:00
0170a8d7c6 更新PlaneGrid3D到可运行 2025-06-10 23:11:30 +08:00
b7627f392c RenderFramework接入键盘鼠标控制 2025-06-10 01:34:13 +08:00
3dfb2c65fd 定义UBOInstance,并将ViewportInfo/CameraInfo两个UBO应用迁移到上面 2025-06-09 23:34:31 +08:00
18d391f01e MaterialCreateInfo增加AddUBOStruct封装 2025-06-09 23:01:41 +08:00
784e7f0e0b SBS增加DescriptorSetType数据,未来所有绑定地方使用此参数以避免对不上 2025-06-09 22:52:10 +08:00
b5a5cb16c0 代码排版与补齐未初始化变量 2025-06-09 22:47:54 +08:00
0be9cb3f74 支持新的CameraControl,并实现自动绑定,现BillboardTest已可正常渲染。只是鼠标键盘输入尚未接入 2025-06-07 05:49:07 +08:00
c4720e8cdb WriteMIData数据长度类型调整 2025-06-07 05:45:00 +08:00
272bb4a4b3 IDName定义更新 2025-06-07 05:43:31 +08:00
5b2f2dbb9f 改进命名和注释 2025-06-07 01:39:27 +08:00
304c3a9bf4 为RenderCmdBuffer中的desc_binding增加详细的注释 2025-06-06 23:42:55 +08:00
eeb4492023 增加Camera数据在渲染器中的定义 2025-06-06 23:39:57 +08:00
55204779ba RenderCmdBuffer中记录的DescriptorBinding改为按SetType分类为多个 2025-06-06 23:39:20 +08:00
5e541e2f46 迁移Auto_merge_material_instance.cpp到新架构 2025-06-06 22:20:18 +08:00
2138f9046a RenderResource中的Renderable/RenderableID改名为Mesh/MeshID 2025-06-06 00:28:13 +08:00
a04adb897e draw_triangle_use_UBO迁移到新框架 2025-06-06 00:24:26 +08:00
8436e57ed7 RenderResource中移除static_descriptor/global_descriptor 2025-06-06 00:24:06 +08:00
bc987e7d7b 清除RenderTask/MaterialRenderList多余代码 2025-06-06 00:23:27 +08:00
427340132f VABList数据写入增加越界检查 2025-06-06 00:22:45 +08:00
f762d77b1d [OK] AutoInstance 范例完成迁移并测试成功。新结构下不再需要自己管理RenderList/SceneRoot。接下来请迁移其它范例。 2025-06-04 01:09:05 +08:00
118ee6e570 变量改名 2025-06-04 00:18:32 +08:00
520b7cae9e SceneWorld文件改名为Scene 2025-06-04 00:10:27 +08:00
839e187cb2 临时可运行版本。已将SceneWorld改名为Scene,下一步改文件名。并将default_scene,default_renderer放在RenderFramework中 2025-06-04 00:04:46 +08:00
5c186fdb95 [WIP] Renderer/RenderTask 2025-05-30 00:32:45 +08:00
8f1b891f9e 初步定义RenderTask 2025-05-28 02:27:59 +08:00
75da8cabef 建立最基础的SceneWorldManager 2025-05-22 01:42:16 +08:00
107 changed files with 3605 additions and 2904 deletions

@ -1 +1 @@
Subproject commit 737fe5c80d013f807cbb8f4d333d5a59c82571bc
Subproject commit 6fbc7078181cefc7e5da590c2d4ccc70507934b7

2
CMCore

@ -1 +1 @@
Subproject commit 511dd86c56383bc14078602f5e5baab1a3109ae5
Subproject commit c5b37f98353441520374011020dbe63c17796a4d

@ -1 +1 @@
Subproject commit 46ae04cd50d09dfb00d9945c5f43d29a2744bcae
Subproject commit f0ff214289a1265898feecbdbbd2ddf50bff5dca

@ -1 +1 @@
Subproject commit 76aff5d55628a87baa35498520296d65ab70e995
Subproject commit 74e33b497274e51c35a5ee19a274b12dc86deecb

2
CMUtil

@ -1 +1 @@
Subproject commit 6173c16bf1744eb15472aa198d3a2a5c4513e78e
Subproject commit 48383e5f63928bab43320c406219365850507246

View File

@ -12,6 +12,8 @@
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/module/TextureManager.h>
#include<hgl/graph/FirstPersonCameraControl.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
@ -32,10 +34,6 @@ class TestApp:public WorkObject
private:
AutoDelete<RenderList> render_list =nullptr;
SceneNode render_root;
Material * mtl_plane_grid =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
Pipeline * pipeline_plane_grid =nullptr;
@ -69,7 +67,7 @@ private:
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
if(!mi_plane_grid)return(false);
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,PrimitiveType::Lines);
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D);
if(!pipeline_plane_grid)return(false);
}
@ -86,7 +84,7 @@ private:
mi_billboard=CreateMaterialInstance(mtl::inline_material::Billboard2D,&cfg);
if(!mi_billboard)return(false);
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D,PrimitiveType::Billboard);
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D);
if(!pipeline_billboard)return(false);
}
@ -115,27 +113,12 @@ private:
return(true);
}
Mesh *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
{
Mesh *ri=db->CreateMesh(r,mi,p);
if(!ri)
{
LOG_ERROR(OS_TEXT("Create Mesh failed."));
return(nullptr);
}
render_root.Add(new SceneNode(ri));
return ri;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
{
PrimitiveCreater pc(GetDevice(),mi_plane_grid->GetVIL());
auto pc=GetPrimitiveCreater(mi_plane_grid);
struct PlaneGridCreateInfo pgci;
@ -145,18 +128,18 @@ private:
pgci.lum=128;
pgci.sub_lum=192;
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
}
{
PrimitiveCreater pc(GetDevice(),mi_billboard->GetVIL());
auto pc=GetPrimitiveCreater(mi_billboard);
pc.Init("Billboard",1);
pc->Init("Billboard",1);
if(!pc.WriteVAB(VAN::Position,VF_V3F,position_data))
if(!pc->WriteVAB(VAN::Position,VF_V3F,position_data))
return(false);
ro_billboard=db->CreateMesh(&pc,mi_billboard,pipeline_billboard);
ro_billboard=db->CreateMesh(pc,mi_billboard,pipeline_billboard);
if(!ro_billboard)
return(false);
@ -167,16 +150,15 @@ private:
bool InitScene()
{
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
render_root.Add(new SceneNode(ro_billboard));
CreateComponent<MeshComponent>(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
CreateComponent<MeshComponent>(scene_root,ro_billboard);
camera->pos=Vector3f(32,32,32);
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(Vector3f(32,32,32));
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
@ -190,8 +172,8 @@ public:
SAFE_CLEAR(prim_plane_grid);
}
bool Init()
{
bool Init() override
{
if(!InitPlaneGridMP())
return(false);
@ -213,5 +195,5 @@ public:
int os_main(int,os_char **)
{
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
return RunFramework<TestApp>(OS_TEXT("Billboard"),1280,720);
}

View File

@ -11,10 +11,8 @@
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
endmacro()
CreateProject(00_RenderFrameworkTest rf_test.cpp)
CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
CreateProject(03_auto_instance auto_instance.cpp)
CreateProject(04_auto_merge_material_instance auto_merge_material_instance.cpp)
CreateProject(01_draw_triangle draw_triangle_use_UBO.cpp)
CreateProject(02_auto_instance auto_instance.cpp)
CreateProject(03_auto_merge_material_instance auto_merge_material_instance.cpp)
CreateProject(05_Billboard BillboardTest.cpp)
CreateProject(04_Billboard BillboardTest.cpp)

View File

@ -5,6 +5,7 @@
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
@ -29,14 +30,8 @@ constexpr uint8 color_data[VERTEX_COUNT][4]=
class TestApp:public WorkObject
{
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
private:
AutoDelete<RenderList> render_list =nullptr;
SceneNode render_root;
MaterialInstance * material_instance =nullptr;
Mesh * render_obj =nullptr;
@ -62,7 +57,7 @@ private:
return(false);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,PrimitiveType::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
@ -80,19 +75,17 @@ private:
double rad;
Matrix4f mat;
SceneNode *scene_root=GetSceneRoot(); ///<取得场景根节点
for(uint i=0;i<TRIANGLE_NUMBER;i++)
{
rad=deg2rad<double>((360.0f/double(TRIANGLE_NUMBER))*i); //这里一定要加<float>或<float>否则结果用int保存会出现问题
rad=deg2rad<double>((360.0f/double(TRIANGLE_NUMBER))*i); //这里一定要加<double>或<float>否则结果用int保存会出现问题
mat=rotate(rad,Vector3f(0,0,1));
render_root.Add(new SceneNode(mat,render_obj));
CreateComponent<MeshComponent>(mat,scene_root,render_obj);
}
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
@ -102,10 +95,7 @@ public:
bool Init() override
{
render_list=GetRenderFramework()->CreateRenderList();
if(!render_list)
return(false);
GetRenderer()->SetClearColor(Color4f(0.2f,0.2f,0.2f,1.0f));
if(!InitMaterial())
return(false);
@ -115,15 +105,6 @@ public:
return(true);
}
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
{
cmd->SetClearColor(0,clear_color);
cmd->BeginRenderPass();
render_list->Render(cmd);
cmd->EndRenderPass();
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)

View File

@ -5,6 +5,7 @@
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/color/Color.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
@ -25,20 +26,12 @@ constexpr double TRI_ROTATE_ANGLE=360.0f/DRAW_OBJECT_COUNT;
class TestApp:public WorkObject
{
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
private:
AutoDelete<RenderList> render_list =nullptr;
SceneNode render_root;
Material * material =nullptr;
struct
{
MaterialInstance * mi;
Mesh * mesh;
Mesh * mesh;
}render_obj[DRAW_OBJECT_COUNT]{};
Pipeline * pipeline =nullptr;
@ -73,7 +66,7 @@ private:
}
}
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,PrimitiveType::Triangles);
pipeline=CreatePipeline(material,InlinePipeline::Solid2D);
return pipeline;
}
@ -89,6 +82,8 @@ private:
db->Add(prim);
Matrix4f mat;
SceneNode *scene_root=GetSceneRoot(); ///<取得场景根节点
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
{
@ -99,13 +94,9 @@ private:
mat=rotate(deg2rad<double>(TRI_ROTATE_ANGLE*i),AxisVector::Z);
render_root.Add(new SceneNode(mat,render_obj[i].mesh));
CreateComponent<MeshComponent>(mat,scene_root,render_obj[i].mesh);
}
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
@ -115,11 +106,6 @@ public:
bool Init() override
{
render_list=GetRenderFramework()->CreateRenderList();
if(!render_list)
return(false);
if(!InitMaterial())
return(false);
@ -128,15 +114,6 @@ public:
return(true);
}
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
{
cmd->SetClearColor(0,clear_color);
cmd->BeginRenderPass();
render_list->Render(cmd);
cmd->EndRenderPass();
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)

View File

@ -1,156 +0,0 @@
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
#include<hgl/WorkManager.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data_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 WorkObject
{
private:
Color4f clear_color=Color4f(0.2f,0.2f,0.2f,1.0f);
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
VILConfig vil_config;
#endif
MaterialInstance * material_instance =nullptr;
Mesh * 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(PrimitiveType::Triangles,
CoordinateSystem2D::NDC,
mtl::WithLocalToWorld::Without);
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor2D,&cfg,&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,PrimitiveType::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
#ifdef USE_HALF_FLOAT_POSITION
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
#endif//USE_HALF_FLOAT_POSITION
render_obj=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
{
{VAN::Position,PositionFormat,position_data},
{VAN::Color, ColorFormat, color_data}
});
return(render_obj);
}
public:
using WorkObject::WorkObject;
bool Init() override
{
InitVIL();
if(!InitAutoMaterial())
return(false);
if(!InitPipeline())
return(false);
if(!InitVBO())
return(false);
return(true);
}
void Tick(double)override{}
void Render(double delta_time,graph::RenderCmdBuffer *cmd)
{
cmd->SetClearColor(0,clear_color);
cmd->BeginRenderPass();
cmd->Render(render_obj);
cmd->EndRenderPass();
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)
{
return RunFramework<TestApp>(OS_TEXT("Draw triangle in NDC space"));
}

View File

@ -5,6 +5,8 @@
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
@ -35,10 +37,8 @@ class TestApp:public WorkObject
{
private:
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
MaterialInstance * material_instance =nullptr;
Mesh * render_obj =nullptr;
Mesh * mesh_triangle =nullptr;
Pipeline * pipeline =nullptr;
@ -48,7 +48,7 @@ private:
{
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
CoordinateSystem2D::Ortho,
mtl::WithLocalToWorld::Without);
mtl::WithLocalToWorld::With);
VILConfig vil_config;
@ -66,14 +66,14 @@ private:
return(false);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,PrimitiveType::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
const auto ext=GetExtent2D();
const auto ext=GetExtent();
for(uint i=0;i<VERTEX_COUNT;i++)
{
@ -81,12 +81,16 @@ private:
position_data[i][1]=position_data_float[i][1]*ext.height;
}
render_obj=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
mesh_triangle=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
{
{VAN::Position,POSITION_DATA_FORMAT,position_data},
{VAN::Color, COLOR_DATA_FORMAT, color_data}
});
return(render_obj);
if(!mesh_triangle)
return(false);
return CreateComponent<MeshComponent>(GetSceneRoot(),mesh_triangle); //创建一个静态网格组件
}
public:
@ -103,15 +107,6 @@ public:
return(true);
}
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
{
cmd->SetClearColor(0,clear_color);
cmd->BeginRenderPass();
cmd->Render(render_obj);
cmd->EndRenderPass();
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)

View File

@ -1,105 +0,0 @@
#include<hgl/WorkManager.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/mtl/MaterialLibrary.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 WorkObject
{
private:
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
MaterialInstance * material_instance =nullptr;
Mesh * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
CoordinateSystem2D::NDC,
mtl::WithLocalToWorld::Without);
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor2D,&cfg); //这个是使用名称创建
return material_instance;
}
bool InitPipeline()
{
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,PrimitiveType::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
render_obj=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
{
{VAN::Position,VF_V2F,position_data},
{VAN::Color, VF_V4F,color_data}
});
return(render_obj);
}
public:
using WorkObject::WorkObject;
bool Init() override
{
if(!InitAutoMaterial())
return(false);
if(!InitPipeline())
return(false);
if(!InitVBO())
return(false);
return(true);
}
void Tick(double)override{}
void Render(double delta_time,graph::RenderCmdBuffer *cmd)
{
cmd->SetClearColor(0,clear_color);
cmd->BeginRenderPass();
cmd->Render(render_obj);
cmd->EndRenderPass();
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)
{
return RunFramework<TestApp>(OS_TEXT("RenderFramework Test"));
}

View File

@ -1,30 +0,0 @@
// Blender axis
/**
* 0 1 2 3 4 5 6 7
* 0+---------->>>> X
* 1|
* 2|
* 3| +--+
* 4| +--+
* 5|
* 6V
* 7V
*
* Blender设计
*
* 8
* 2
*
* 2D平移的方块尺寸为13-4
*
*/
/**
*
*/
class GizmoScale
{
public:
};//class GizmoScale

View File

@ -10,16 +10,15 @@
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(01_SimplestAxis SimplestAxis.cpp)
CreateProject(02_PlaneGrid3D PlaneGrid3D.cpp)
CreateProject(03_RayPicking RayPicking.cpp)
CreateProject(04_Gizmo3DTest GizmoTest.cpp
Gizmo.h
GizmoResource.h
GizmoResource.cpp
Gizmo3DMove.cpp
Gizmo3DScale.cpp
Gizmo3DRotate.cpp)
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
#Gizmo3DScale.cpp
#Gizmo3DRotate.cpp
)

View File

@ -31,13 +31,13 @@ enum class GizmoShape:uint
ENUM_CLASS_RANGE(Square,Torus)
};
bool InitGizmoResource(RenderResource *);
bool InitGizmoResource(RenderFramework *);
void FreeGizmoResource();
Mesh *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color);
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color);
StaticMesh *GetGizmoMoveStaticMesh();
StaticMesh *GetGizmoScaleStaticMesh();
StaticMesh *GetGizmoRotateStaticMesh();
SceneNode *GetGizmoMoveNode();
//SceneNode *GetGizmoScaleMesh();
//SceneNode *GetGizmoRotateMesh();
VK_NAMESPACE_END

View File

@ -25,46 +25,49 @@
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/RenderFramework.h>
#include<hgl/component/MeshComponent.h>
VK_NAMESPACE_BEGIN
namespace
{
static StaticMesh *sm_gizmo_move=nullptr;
static SceneNode *sn_gizmo_move=nullptr;
}//namespace
StaticMesh *GetGizmoMoveStaticMesh()
SceneNode *GetGizmoMoveNode()
{
return sm_gizmo_move;
return sn_gizmo_move;
}
void ClearGizmoMoveStaticMesh()
void ClearGizmoMoveNode()
{
SAFE_CLEAR(sm_gizmo_move);
SAFE_CLEAR(sn_gizmo_move);
}
bool InitGizmoMoveStaticMesh()
bool InitGizmoMoveNode(RenderFramework *render_framework)
{
Mesh *sphere=GetGizmoRenderable(GizmoShape::Sphere,GizmoColor::White);
Mesh *sphere=GetGizmoMesh(GizmoShape::Sphere,GizmoColor::White);
Mesh *cylinder[3]
{
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
};
Mesh *cone[3]
{
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Blue),
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Blue),
};
Mesh *circle[3]=
Mesh *square[3]=
{
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Blue)
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
};
if(!sphere)
@ -78,72 +81,69 @@ bool InitGizmoMoveStaticMesh()
if(!cone[i])
return(false);
if(!circle[i])
if(!square[i])
return(false);
}
{
SceneNode *root_node=new SceneNode();
sn_gizmo_move=new SceneNode();
root_node->Add(new SceneNode(sphere));
sn_gizmo_move->AttachComponent(render_framework->CreateComponent<MeshComponent>(sphere));
{
Transform tm;
const Vector3f one_scale(1);
const Vector3f circle_scale(2);
const Vector3f square_scale(2);
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
{
tm.SetScale(cylinder_scale);
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
root_node->Add(new SceneNode(tm,cone[2])); //Z 向上圆锥
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[2]); //Z 向上圆锥
tm.SetScale(circle_scale);
tm.SetScale(square_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
root_node->Add(new SceneNode(tm,circle[2]));
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[2]);
}
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::Y,90);
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[0]); //X 向右圆柱
tm.SetScale(one_scale);
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cone[0])); //X 向右圆锥
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[0]); //X 向右圆锥
tm.SetScale(circle_scale);
tm.SetScale(square_scale);
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,circle[0]));
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[0]);
}
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::X,-90);
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[1]); //Y 向前圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
root_node->Add(new SceneNode(tm,cone[1])); //Y 向前圆锥
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[1]); //Y 向前圆锥
tm.SetScale(circle_scale);
tm.SetScale(square_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,circle[1]));
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[1]);
}
}
sm_gizmo_move=CreateGizmoStaticMesh(root_node);
}
if(!sm_gizmo_move)
if(!sn_gizmo_move)
return(false);
return(true);

View File

@ -24,11 +24,11 @@ bool InitGizmoRotateStaticMesh()
{
Mesh *torus[4]
{
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Blue),
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Blue),
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::White),
GetGizmoMesh(GizmoShape::Torus,GizmoColor::White),
};
for(auto *r:torus)

View File

@ -45,26 +45,26 @@ void ClearGizmoScaleStaticMesh()
bool InitGizmoScaleStaticMesh()
{
Mesh *center_cube=GetGizmoRenderable(GizmoShape::Cube,GizmoColor::White);
Mesh *center_cube=GetGizmoMesh(GizmoShape::Cube,GizmoColor::White);
Mesh *cylinder[3]
{
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
};
Mesh *cube[3]
{
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Blue),
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Blue),
};
Mesh *square[3]=
{
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Red),
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Green),
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Blue)
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
};
if(!center_cube)

View File

@ -9,22 +9,24 @@
#include<hgl/color/Color.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/RenderFramework.h>
#include"GizmoResource.h"
VK_NAMESPACE_BEGIN
bool InitGizmoMoveStaticMesh();
void ClearGizmoMoveStaticMesh();
bool InitGizmoMoveNode(RenderFramework *);
void ClearGizmoMoveNode();
bool InitGizmoScaleStaticMesh();
void ClearGizmoScaleStaticMesh();
bool InitGizmoRotateStaticMesh();
void ClearGizmoRotateStaticMesh();
//bool InitGizmoScaleMesh();
//void ClearGizmoScaleMesh();
//
//bool InitGizmoRotateMesh();
//void ClearGizmoRotateMesh();
namespace
{
static RenderResource * gizmo_rr=nullptr;
static RenderFramework *render_framework=nullptr;
static RenderResource * gizmo_rr=nullptr;
struct GizmoResource
{
@ -39,26 +41,26 @@ namespace
static GizmoResource gizmo_line{};
static GizmoResource gizmo_triangle{};
struct GizmoRenderable
struct GizmoMesh
{
Primitive *prim;
Mesh *renderable[size_t(GizmoColor::RANGE_SIZE)];
Mesh *mesh[size_t(GizmoColor::RANGE_SIZE)];
};
GizmoRenderable gizmo_rederable[size_t(GizmoShape::RANGE_SIZE)]{};
GizmoMesh gizmo_mesh[size_t(GizmoShape::RANGE_SIZE)]{};
void InitGizmoRenderable(const GizmoShape &gs,Primitive *prim,Pipeline *p)
void InitGizmoMesh(const GizmoShape &gs,Primitive *prim,Pipeline *p)
{
if(!prim)
return;
GizmoRenderable *gr=gizmo_rederable+size_t(gs);
GizmoMesh *gr=gizmo_mesh+size_t(gs);
gr->prim=prim;
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
gr->renderable[i]=CreateMesh(prim,gizmo_triangle.mi[i],p);
gr->mesh[i]=CreateMesh(prim,gizmo_triangle.mi[i],p);
}
bool InitMI(GizmoResource *gr)
@ -80,26 +82,27 @@ namespace
return(true);
}
bool InitGizmoResource2D(VulkanDevice *device)
bool InitGizmoResource2D()
{
if(!gizmo_rr)
return(false);
RenderPass *render_pass=device->GetRenderPass();
VulkanDevice *device=render_framework->GetDevice();
VulkanDevAttr *dev_attr=device->GetDevAttr();
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
{
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"VertexLuminance3D",PrimitiveType::Lines);
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
cfg.local_to_world=true;
cfg.position_format=VAT_VEC3;
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(&cfg);
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(dev_attr,&cfg);
if(!mci)
return(false);
gizmo_line.mtl=gizmo_rr->CreateMaterial(mci);
gizmo_line.mtl=gizmo_rr->CreateMaterial("GizmoLine",mci);
if(!gizmo_line.mtl)
return(false);
@ -107,7 +110,7 @@ namespace
}
{
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D,PrimitiveType::Lines);
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D);
if(!gizmo_line.pipeline)
return(false);
@ -134,25 +137,27 @@ namespace
return(true);
}
bool InitGizmoResource3D(VulkanDevice *device)
bool InitGizmoResource3D()
{
if(!gizmo_rr)
return(false);
RenderPass *render_pass=device->GetRenderPass();
VulkanDevice *device=render_framework->GetDevice();
VulkanDevAttr *dev_attr=device->GetDevAttr();
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
{
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"Gizmo3D",PrimitiveType::Triangles);
mtl::Material3DCreateConfig cfg(PrimitiveType::Triangles);
cfg.local_to_world=true;
cfg.material_instance=true;
mtl::MaterialCreateInfo *mci=CreateMaterialGizmo3D(&cfg);
mtl::MaterialCreateInfo *mci=CreateGizmo3D(dev_attr,&cfg);
if(!mci)
return(false);
gizmo_triangle.mtl=gizmo_rr->CreateMaterial(mci);
gizmo_triangle.mtl=gizmo_rr->CreateMaterial("GizmoTriangle",mci);
if(!gizmo_triangle.mtl)
return(false);
@ -160,7 +165,7 @@ namespace
}
{
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D,PrimitiveType::Triangles);
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D);
if(!gizmo_triangle.pipeline)
return(false);
}
@ -191,7 +196,7 @@ namespace
using namespace inline_geometry;
{
InitGizmoRenderable(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
InitGizmoMesh(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
}
{
@ -202,7 +207,7 @@ namespace
cci.field_count=16;
cci.has_center=false;
InitGizmoRenderable(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
InitGizmoMesh(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
@ -212,11 +217,11 @@ namespace
cci.tangent=false;
cci.tex_coord=false;
InitGizmoRenderable(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
InitGizmoMesh(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
InitGizmoMesh(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
}
{
@ -227,7 +232,7 @@ namespace
cci.numberSlices=16; //圆锥底部分割数
cci.numberStacks=3; //圆锥高度分割数
InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
InitGizmoMesh(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
@ -237,7 +242,7 @@ namespace
cci.numberSlices=16; //圆柱底部分割数
cci.radius =1; //圆柱半径
InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
InitGizmoMesh(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
@ -248,12 +253,12 @@ namespace
tci.numberSlices=64;
tci.numberStacks=8;
InitGizmoRenderable(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
InitGizmoMesh(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
}
ENUM_CLASS_FOR(GizmoShape,int,i)
{
if(!gizmo_rederable[i].prim)
if(!gizmo_mesh[i].prim)
return(false);
}
}
@ -262,41 +267,40 @@ namespace
}
}//namespace
bool InitGizmoResource(RenderResource *rr)
bool InitGizmoResource(RenderFramework *rf)
{
if(!rr)
if(!rf)
return(false);
if(gizmo_rr)
render_framework=rf;
gizmo_rr=render_framework->GetRenderResource();
VulkanDevice *device=render_framework->GetDevice();
if(!InitGizmoResource3D())
return(false);
gizmo_rr=rr;
VulkanDevice *device=gizmo_rr->GetDevice();
if(!InitGizmoResource3D(device))
if(!InitGizmoResource2D())
return(false);
if(!InitGizmoResource2D(device))
return(false);
InitGizmoMoveStaticMesh();
InitGizmoScaleStaticMesh();
InitGizmoRotateStaticMesh();
InitGizmoMoveNode(rf);
//InitGizmoScaleMesh();
//InitGizmoRotateMesh();
return(true);
}
void FreeGizmoResource()
{
ClearGizmoRotateStaticMesh();
ClearGizmoScaleStaticMesh();
ClearGizmoMoveStaticMesh();
//ClearGizmoRotateMesh();
//ClearGizmoScaleMesh();
ClearGizmoMoveNode();
for(GizmoRenderable &gr:gizmo_rederable)
for(GizmoMesh &gr:gizmo_mesh)
{
SAFE_CLEAR(gr.prim)
SAFE_CLEAR_OBJECT_ARRAY(gr.renderable)
SAFE_CLEAR_OBJECT_ARRAY(gr.mesh)
}
SAFE_CLEAR(gizmo_triangle.prim_creater);
@ -306,7 +310,7 @@ void FreeGizmoResource()
SAFE_CLEAR(gizmo_line.vdm);
}
Mesh *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color)
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color)
{
if(!gizmo_rr)
return(nullptr);
@ -314,18 +318,7 @@ Mesh *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color)
RANGE_CHECK_RETURN_NULLPTR(shape)
RANGE_CHECK_RETURN_NULLPTR(color)
return gizmo_rederable[size_t(shape)].renderable[size_t(color)];
}
StaticMesh *CreateGizmoStaticMesh(SceneNode *root_node)
{
if(!root_node)
return(nullptr);
if(root_node->IsEmpty())
return(nullptr);
return(new StaticMesh(root_node));
return gizmo_mesh[size_t(shape)].mesh[size_t(color)];
}
VK_NAMESPACE_END

View File

@ -1,4 +1,5 @@
#pragma once
#include"Gizmo.h"
#include<hgl/color/Color.h>
@ -6,7 +7,7 @@ VK_NAMESPACE_BEGIN
class SceneNode;
class PrimitiveCreater;
class StaticMesh;
class MeshComponent;
constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]=
{
@ -35,8 +36,6 @@ constexpr const float GIZMO_CYLINDER_OFFSET =GIZMO_CYLINDER_HALF_LENGTH+GIZM
constexpr const float GIZMO_TWO_AXIS_OFFSET =5.0F; ///<二轴调节点偏移量(方片或圆)
Mesh *GetGizmoRenderable(const GizmoShape &gs,const GizmoColor &);
StaticMesh *CreateGizmoStaticMesh(SceneNode *);
Mesh *GetGizmoMesh(const GizmoShape &gs,const GizmoColor &);
VK_NAMESPACE_END

View File

@ -1,4 +1,4 @@
#include"VulkanAppFramework.h"
#include<hgl/WorkManager.h>
#include"Gizmo.h"
#include<hgl/graph/Ray.h>
@ -52,94 +52,81 @@ const Vector3f GizmoPosition(0,0,0);
// }
//};//class BillboardSceneNode:public SceneNode
class TestApp:public SceneAppFramework
class TestApp:public WorkObject
{
SceneNode root;
StaticMesh *sm_move=nullptr;
StaticMesh *sm_rotate=nullptr;
StaticMesh *sm_scale=nullptr;
SceneNode *sm_move=nullptr;
//StaticMesh *sm_rotate=nullptr;
//StaticMesh *sm_scale=nullptr;
private:
bool InitGizmo()
{
if(!InitGizmoResource(db))
if(!InitGizmoResource(GetRenderFramework()))
return(false);
sm_move =GetGizmoMoveStaticMesh();
sm_rotate =GetGizmoRotateStaticMesh();
sm_scale =GetGizmoScaleStaticMesh();
sm_move =GetGizmoMoveNode();
//sm_rotate =GetGizmoRotateStaticMesh();
//sm_scale =GetGizmoScaleStaticMesh();
return(true);
}
void InitGizmoSceneTree()
{
camera_control->Refresh();
CameraInfo *ci=camera_control->GetCameraInfo();
SceneNode *root=GetSceneRoot();
root.Clear();
//root.Add(Duplication(sm_move->GetScene()));
root.Add(Duplication(sm_rotate->GetScene()));
root->Add(Duplication(sm_move));
//root.Add(Duplication(sm_rotate->GetScene()));
//root.CreateSubNode(sm_scale->GetScene());
root.RefreshMatrix();
render_list->SetCamera(ci);
render_list->Expend(&root);
}
public:
bool Init(uint w,uint h)
{
if(!SceneAppFramework::Init(w,h))
return(false);
bool Init() override
{
if(!InitGizmo())
return(false);
InitGizmoSceneTree();
camera->pos=Vector3f(32,32,32);
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(Vector3f(32,32,32));
camera_control->SetTarget(Vector3f(0,0,0));
return(true);
}
using WorkObject::WorkObject;
~TestApp()
{
FreeGizmoResource();
}
void BuildCommandBuffer(uint32 index) override
{
camera_control->Refresh();
const CameraInfo *ci=camera_control->GetCameraInfo();
const ViewportInfo *vi=GetViewportInfo();
//void BuildCommandBuffer(uint32 index) override
//{
// camera_control->Refresh();
//
// const CameraInfo *ci=camera_control->GetCameraInfo();
// const ViewportInfo *vi=GetViewportInfo();
const float screen_height=vi->GetViewportHeight();
// const float screen_height=vi->GetViewportHeight();
const Vector4f pos=ci->Project(GizmoPosition);
// const Vector4f pos=ci->Project(GizmoPosition);
//{
// Transform tm;
// //{
// // Transform tm;
// tm.SetScale(pos.w*16.0f/screen_height);
// // tm.SetScale(pos.w*16.0f/screen_height);
// root.SetLocalTransform(tm);
//}
// // root.SetLocalTransform(tm);
// //}
//}
};//class TestApp:public WorkObject
root.RefreshMatrix();
render_list->UpdateLocalToWorld();
SceneAppFramework::BuildCommandBuffer(index);
}
};//class TestApp:public SceneAppFramework
int main(int,char **)
int os_main(int,os_char **)
{
return RunApp<TestApp>(1024,1024);
return RunFramework<TestApp>(OS_TEXT("Gizmo"),1280,720);
}

View File

@ -1,147 +0,0 @@
// 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/PrimitiveCreater.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->GetDevAttr(),"MetricCellsGrid",PrimitiveType::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,PrimitiveType::Fan);
return pipeline;
}
bool CreateRenderObject()
{
PrimitiveCreater pc(device,material->GetDefaultVIL());
ro_plane=inline_geometry::CreatePlaneSqaure(&pc);
if(ro_plane)
db->Add(ro_plane);
return ro_plane;
}
Mesh *Add(MaterialInstance *mi,const Matrix4f &mat)
{
Mesh *ri=db->CreateMesh(ro_plane,mi,pipeline);
if(!ri)
return(nullptr);
render_root.CreateSubNode(mat,ri);
return ri;
}
bool InitScene()
{
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
camera->pos=Vector3f(PLANE_SIZE/4,PLANE_SIZE/2,PLANE_SIZE/4);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
// camera_control->SetReserveDirection(true,true); //反转x,y
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint width,uint height) override
{
if(!SceneAppFramework::Init(width,height))
return(false);
if(!InitMDP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}

View File

@ -1,6 +1,6 @@
// PlaneGrid3D
#include"VulkanAppFramework.h"
#include<hgl/WorkManager.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
@ -8,11 +8,14 @@
#include<hgl/graph/Camera.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/FirstPersonCameraControl.h>
#include<hgl/color/Color.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
class TestApp:public SceneAppFramework
class TestApp:public WorkObject
{
private:
@ -26,7 +29,7 @@ private:
bool InitMDP()
{
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"VertexLuminance3D",PrimitiveType::Lines);
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
cfg.local_to_world=true;
cfg.position_format=VAT_VEC2;
@ -50,7 +53,7 @@ private:
ce=COLOR((int)ce+1);
}
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D,PrimitiveType::Lines);
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D);
return pipeline;
}
@ -67,55 +70,52 @@ private:
pgci.lum=180;
pgci.sub_lum=255;
PrimitiveCreater pc(device,material_instance[0]->GetVIL());
auto pc=GetPrimitiveCreater(material_instance[0]);
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
return prim_plane_grid;
}
Mesh *Add(MaterialInstance *mi,const Matrix4f &mat)
void Add(SceneNode *parent_node,MaterialInstance *mi,const Matrix4f &mat)
{
Mesh *ri=db->CreateMesh(prim_plane_grid,mi,pipeline);
if(!ri)
return(nullptr);
return;
render_root.Add(new SceneNode(mat,ri));
return ri;
CreateComponent<MeshComponent>(mat,parent_node,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));
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
camera->pos=Vector3f(32,32,32);
Add(scene_root,material_instance[0],Matrix4f(1.0f));
Add(scene_root,material_instance[1],rotate(HGL_RAD_90,0,1,0));
Add(scene_root,material_instance[2],rotate(HGL_RAD_90,1,0,0));
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(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:
using WorkObject::WorkObject;
~TestApp()
{
SAFE_CLEAR(prim_plane_grid);
}
bool Init(uint width,uint height) override
bool Init() override
{
if(!SceneAppFramework::Init(width,height))
return(false);
if(!InitMDP())
return(false);
@ -129,7 +129,7 @@ public:
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
int os_main(int,os_char **)
{
return RunApp<TestApp>(1280,720);
return RunFramework<TestApp>(OS_TEXT("PlaneGrid3D"),1280,720);
}

View File

@ -1,6 +1,6 @@
// RayPicking
#include"VulkanAppFramework.h"
#include<hgl/WorkManager.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
@ -11,6 +11,7 @@
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
@ -21,12 +22,12 @@ static float position_data[2][3]=
{0,0,0}
};
static float lumiance_data[2]={1,1};
static uint8 lumiance_data[2]={255,255};
static Color4f white_color(1,1,1,1);
static Color4f yellow_color(1,1,0,1);
class TestApp:public SceneAppFramework
class TestApp:public WorkObject
{
Color4f color;
@ -51,39 +52,37 @@ private:
bool InitMaterialAndPipeline()
{
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"VertexLuminance2D",PrimitiveType::Lines);
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
cfg.local_to_world=true;
VILConfig vil_config;
vil_config.Add(VAN::Luminance,VF_V1UN8);
{
cfg.mtl_name="VertexLuminance2D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
cfg.position_format=VAT_VEC2;
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_plane_grid)return(false);
VILConfig vil_config;
vil_config.Add(VAN::Luminance,VF_V1UN8);
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
if(!mi_plane_grid)return(false);
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,PrimitiveType::Lines);
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D);
if(!pipeline_plane_grid)return(false);
}
{
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
cfg.position_format=VAT_VEC3;
mtl_line=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_line)return(false);
mi_line=db->CreateMaterialInstance(mtl_line,nullptr,&yellow_color);
mi_line=db->CreateMaterialInstance(mtl_line,&vil_config,&yellow_color);
if(!mi_line)return(false);
pipeline_line=CreatePipeline(mtl_line,InlinePipeline::Solid3D,PrimitiveType::Lines);
pipeline_line=CreatePipeline(mi_line,InlinePipeline::Solid3D);
if(!pipeline_line)
return(false);
@ -92,7 +91,7 @@ private:
return(true);
}
Mesh *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
Mesh *Add(SceneNode *parent_node,Primitive *r,MaterialInstance *mi,Pipeline *p)
{
Mesh *ri=db->CreateMesh(r,mi,p);
@ -102,7 +101,7 @@ private:
return(nullptr);
}
render_root.Add(new SceneNode(ri));
CreateComponent<MeshComponent>(parent_node,ri);
return ri;
}
@ -112,7 +111,7 @@ private:
using namespace inline_geometry;
{
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
auto pc=GetPrimitiveCreater(mi_plane_grid);
struct PlaneGridCreateInfo pgci;
@ -122,19 +121,15 @@ private:
pgci.lum=128;
pgci.sub_lum=196;
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
}
{
PrimitiveCreater pc(device,mtl_line->GetDefaultVIL());
if(!pc.Init("Line",2))
return(false);
if(!pc.WriteVAB(VAN::Position, VF_V3F,position_data))return(false);
if(!pc.WriteVAB(VAN::Luminance,VF_V1F,lumiance_data))return(false);
prim_line=pc.Create();
prim_line=CreatePrimitive("RayLine",2,mi_line->GetVIL(),
{
{VAN::Position, VF_V3F,position_data},
{VAN::Luminance,VF_V1UN8,lumiance_data}
});
prim_line_vab_map=prim_line->GetVABMap(VAN::Position);
}
@ -144,32 +139,30 @@ private:
bool InitScene()
{
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
Add(prim_line,mi_line,pipeline_line);
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
camera->pos=Vector3f(32,32,32);
Add(scene_root,prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
Add(scene_root,prim_line,mi_line,pipeline_line);
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(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:
using WorkObject::WorkObject;
~TestApp()
{
SAFE_CLEAR(prim_plane_grid);
SAFE_CLEAR(prim_line);
}
bool Init(uint w,uint h)
{
if(!SceneAppFramework::Init(w,h))
return(false);
bool Init() override
{
if(!InitMaterialAndPipeline())
return(false);
@ -182,23 +175,28 @@ public:
return(true);
}
void BuildCommandBuffer(uint32 index) override
void Tick(double) override
{
const CameraInfo *ci=GetCameraInfo();
const ViewportInfo *vi=GetViewportInfo();
Vector2i mouse_position;
ray.Set(GetMouseCoord(),ci,vi); //设置射线查询的屏幕坐标点
if(!GetMouseCoord(&mouse_position))
return;
CameraControl *camera_control=GetCameraControl();
const CameraInfo *ci=camera_control->GetCameraInfo();
const ViewportInfo *vi=camera_control->GetViewportInfo();
ray.Set(mouse_position,ci,vi); //设置射线查询的屏幕坐标点
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
prim_line_vab_map->Write(&pos, //更新VAB上这个点的位置
1); //这里的1代表的数据数量,不是字节数
SceneAppFramework::BuildCommandBuffer(index);
1); //这里的1代表的数据数量,不是字节数
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
int os_main(int,os_char **)
{
return RunApp<TestApp>(1280,720);
return RunFramework<TestApp>(OS_TEXT("RayPicking"),1280,720);
}

View File

@ -0,0 +1,100 @@
// SimplestAxis
// 直接从0,0,0向三个方向画一条直线用于确认坐标轴方向
#include<hgl/WorkManager.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/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/FirstPersonCameraControl.h>
#include<hgl/color/Color.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
class TestApp:public WorkObject
{
private:
Material * material =nullptr;
Pipeline * pipeline =nullptr;
Primitive * prim_axis =nullptr;
MaterialInstance * material_instance =nullptr;
private:
bool InitMDP()
{
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
cfg.local_to_world=true;
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor3D,&cfg);
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D);
return pipeline;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
auto pc=GetPrimitiveCreater(material_instance);
inline_geometry::AxisCreateInfo aci;
prim_axis=CreateAxis(pc,&aci);
return prim_axis;
}
bool InitScene()
{
Mesh *ri=db->CreateMesh(prim_axis,material_instance,pipeline);
CreateComponent<MeshComponent>(GetSceneRoot(),ri);
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(Vector3f(32,32,32));
camera_control->SetTarget(Vector3f(0,0,0));
// camera_control->SetReserveDirection(true,true); //反转x,y
return(true);
}
public:
using WorkObject::WorkObject;
~TestApp()
{
SAFE_CLEAR(prim_axis);
}
bool Init() override
{
if(!InitMDP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int os_main(int,os_char **)
{
return RunFramework<TestApp>(OS_TEXT("SimplestAxis"),1280,720);
}

View File

@ -346,125 +346,6 @@ public:
}
};//class VulkanApplicationFramework
class CameraKeyboardControl:public KeyboardStateEvent
{
FirstPersonCameraControl *camera;
float move_speed;
public:
CameraKeyboardControl(FirstPersonCameraControl *wc)
{
camera=wc;
move_speed=1.0f;
}
bool OnPressed(const KeyboardButton &kb)override
{
if(!KeyboardStateEvent::OnPressed(kb))
return(false);
if(kb==KeyboardButton::Minus )move_speed*=0.9f;else
if(kb==KeyboardButton::Equals )move_speed*=1.1f;
return(true);
}
void Update()
{
if(HasPressed(KeyboardButton::W ))camera->Forward (move_speed);else
if(HasPressed(KeyboardButton::S ))camera->Backward (move_speed);else
if(HasPressed(KeyboardButton::A ))camera->Left (move_speed);else
if(HasPressed(KeyboardButton::D ))camera->Right (move_speed);else
//if(HasPressed(KeyboardButton::R ))camera->Up (move_speed);else
//if(HasPressed(KeyboardButton::F ))camera->Down (move_speed);else
//if(HasPressed(KeyboardButton::Left ))camera->HoriRotate( move_speed);else
//if(HasPressed(KeyboardButton::Right ))camera->HoriRotate(-move_speed);else
//if(HasPressed(KeyboardButton::Up ))camera->VertRotate( move_speed);else
//if(HasPressed(KeyboardButton::Down ))camera->VertRotate(-move_speed);else
return;
}
};
class CameraMouseControl:public MouseEvent
{
FirstPersonCameraControl *camera;
double cur_time;
double last_time;
Vector2f mouse_pos;
Vector2f mouse_last_pos;
protected:
bool OnPressed(int x,int y,MouseButton) override
{
mouse_last_pos.x=x;
mouse_last_pos.y=y;
last_time=cur_time;
return(true);
}
bool OnWheel(int,int y) override
{
if(y==0)return(false);
camera->Forward(float(y)/10.0f);
return(true);
}
bool OnMove(int x,int y) override
{
mouse_pos.x=x;
mouse_pos.y=y;
bool left=HasPressed(MouseButton::Left);
bool right=HasPressed(MouseButton::Right);
Vector2f pos(x,y);
Vector2f gap=pos-mouse_last_pos;
if(left)
{
gap/=-5.0f;
camera->Rotate(gap);
}
else
if(right)
{
gap/=10.0f;
camera->Move(Vector3f(gap.x,0,gap.y));
}
last_time=cur_time;
mouse_last_pos=Vector2f(x,y);
return(true);
}
public:
CameraMouseControl(FirstPersonCameraControl *wc)
{
camera=wc;
cur_time=0;
last_time=0;
}
const Vector2f &GetMouseCoord()const{return mouse_pos;}
void Update()
{
cur_time=GetPreciseTime();
}
};
class CameraAppFramework:public VulkanApplicationFramework
{
protected:

View File

@ -3,6 +3,8 @@
#include<hgl/graph/RenderFramework.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/mtl/MaterialLibrary.h>
#include<hgl/graph/Renderer.h>
#include<hgl/graph/Scene.h>
#include<hgl/Time.h>
//#include<iostream>
@ -21,17 +23,18 @@ namespace hgl
class WorkObject:public TickObject
{
graph::RenderFramework *render_framework=nullptr;
graph::IRenderTarget *cur_render_target=nullptr;
graph::RenderPass *render_pass=nullptr;
bool destroy_flag=false;
bool renderable=true;
bool render_dirty=true;
protected:
graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代
//以下数据均取自RenderFramework
graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代
graph::Scene * scene=nullptr; //场景
graph::Renderer * renderer=nullptr; //渲染器
public:
@ -40,65 +43,73 @@ namespace hgl
graph::VulkanDevAttr * GetDevAttr (){return render_framework->GetDevAttr();}
graph::TextureManager * GetTextureManager (){return render_framework->GetTextureManager();}
const VkExtent2D & GetExtent2D (){return cur_render_target->GetExtent();}
const VkExtent2D & GetExtent (){return renderer->GetExtent();}
graph::Scene * GetScene (){return scene;}
graph::SceneNode * GetSceneRoot (){return scene->GetRootNode();}
graph::Renderer * GetRenderer (){return renderer;}
graph::Camera * GetCamera (){return renderer->GetCamera();}
graph::CameraControl * GetCameraControl (){return render_framework->GetDefaultCameraControl();}
bool GetMouseCoord (Vector2i *mc)const{return render_framework->GetMouseCoord(mc);}
public:
const bool IsDestroy()const{return destroy_flag;}
const bool IsRenderable()const{return renderable;}
const bool IsRenderDirty()const{return render_dirty;}
const bool IsDestroy ()const{return destroy_flag;}
void MarkDestory(){destroy_flag=true;}
void MarkDestory(){destroy_flag=true;}
void SetRenderable(bool r){renderable=r;}
void MarkRenderDirty(){render_dirty=true;}
const bool IsRenderDirty ()const{return render_dirty;}
void MarkRenderDirty(){render_dirty=true;}
public:
WorkObject(graph::RenderFramework *,graph::IRenderTarget *rt=nullptr);
WorkObject(graph::RenderFramework *,graph::Renderer *r=nullptr);
virtual ~WorkObject()=default;
virtual bool Init()=0;
virtual void OnRenderTargetSwitch(graph::RenderFramework *rf,graph::IRenderTarget *rt);
virtual void OnRendererChange(graph::RenderFramework *rf,graph::Renderer *r);
virtual void OnResize(const VkExtent2D &){}
virtual void Tick(double){}
virtual void Render(double delta_time,graph::RenderCmdBuffer *cmd)=0;
virtual void Render(double delta_time);
public:
template<typename ...ARGS>
graph::Pipeline *CreatePipeline(ARGS...args)
{
return render_pass->CreatePipeline(args...);
}
#define WO_FUNC_FROM_RENDER_FRAMEWORK(name,return_type) template<typename ...ARGS> return_type name(ARGS...args){return render_framework?render_framework->name(args...):nullptr;}
graph::MaterialInstance *CreateMaterialInstance(const AnsiString &mi_name,const graph::mtl::MaterialCreateInfo *mci,const graph::VILConfig *vil_cfg=nullptr)
{
return db->CreateMaterialInstance(mi_name,mci,vil_cfg);
}
WO_FUNC_FROM_RENDER_FRAMEWORK(CreatePipeline,graph::Pipeline *)
WO_FUNC_FROM_RENDER_FRAMEWORK(CreateMaterialInstance,graph::MaterialInstance *)
WO_FUNC_FROM_RENDER_FRAMEWORK(GetPrimitiveCreater,SharedPtr<graph::PrimitiveCreater>)
graph::MaterialInstance *CreateMaterialInstance(const AnsiString &mtl_name,graph::mtl::MaterialCreateConfig *mtl_cfg,const graph::VILConfig *vil_cfg=nullptr)
{
AutoDelete<graph::mtl::MaterialCreateInfo> mci=graph::mtl::CreateMaterialCreateInfo(GetDevAttr(),mtl_name,mtl_cfg);
#undef WO_FUNC_FROM_RENDER_FRAMEWORK
return db->CreateMaterialInstance(mtl_name,mci,vil_cfg);
}
graph::Primitive *CreatePrimitive( const AnsiString &name,
graph::Primitive *CreatePrimitive(const AnsiString &name,
const uint32_t vertices_count,
const graph::VIL *vil,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
{
return render_framework?render_framework->CreatePrimitive(name,vertices_count,vil,vad_list):nullptr;
}
graph::Mesh *CreateMesh(const AnsiString &name,
const uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
const uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
{
return render_framework?render_framework->CreateMesh(name,vertices_count,mi,pipeline,vad_list):nullptr;
}
public: //Component 相关
template<typename C,typename ...ARGS>
inline C *CreateComponent(ARGS...args)
{
return render_framework?render_framework->CreateComponent<C>(args...):nullptr; //创建组件
}
};//class WorkObject
/**

View File

@ -11,26 +11,27 @@
*
* AMD FidelityFX中Component存放于Entity下SceneNode
* Entity还是SceneNodeComponent的管理
* AMD FidelityFX中的SceneSceneWorld
* AMD FidelityFX中的SceneScene
*
* ComponentData是每个Component的数据Component或是其它模块提供数据
* ComponentManager是Component的管理器Component的创建
*
* AMD FidelityFX一样ComponentManager与SceneWorld基本无关
* AMD FidelityFX一样ComponentManager与Scene基本无关
* World之中
* SceneWorld密切相关的Component它对应的Manager才会出现在SceneWorldCameraManager/LightManager
* StaticMeshComponent之类的纯资源型就会是独立存在的
* Scene密切相关的Component它对应的Manager才会出现在Scene中CameraManager/LightManager
* MeshComponent之类的纯资源型就会是独立存在的
*
* Component是组件的基类
*
*
* RenderComponent是可渲染组件的基类Component
*
* PrimitiveComponent是图元组件的基类RenderComponent
* SceneComponent是场景组件基类
*
* PrimitiveComponent是图元组件的基类
* Component都必须是一个有3D空间的几何图元
* PrimitiveComponent提供数据进行计算
* RenderComponent是可渲染组件的基类
*
* StaticMeshComponent是静态网格组件PrimitiveComponent实现
* MeshComponent是静态网格组件RenderComponent实现
*
*/
@ -43,7 +44,15 @@ COMPONENT_NAMESPACE_BEGIN
class ComponentManager;
class SceneNode;
struct ComponentData{};
struct ComponentData
{
public:
ComponentData()=default;
virtual ~ComponentData()=default;
};//struct ComponentData
using ComponentDataPtr=SharedPtr<ComponentData>;
/**
* <br>
@ -51,77 +60,105 @@ struct ComponentData{};
*/
class Component
{
static uint unique_id_count;
uint unique_id;
SceneNode * OwnerNode;
ComponentManager * Manager;
ComponentData * Data;
ComponentDataPtr Data;
protected:
friend class ComponentManager;
virtual void OnDetachManager(ComponentManager *cm)
{
if(cm==Manager)
Manager=nullptr;
}
public:
Component()=delete;
Component(SceneNode *sn,ComponentData *cd,ComponentManager *cm)
{
OwnerNode=sn;
Data=cd;
Manager=cm;
}
virtual ~Component()
{
SAFE_CLEAR(Data);
}
Component(ComponentDataPtr,ComponentManager *);
virtual ~Component();
virtual const size_t GetHashCode()const=0;
public:
uint GetUniqueID ()const{return unique_id;}
SceneNode * GetOwnerNode()const{return OwnerNode;}
ComponentManager * GetManager ()const{return Manager;}
ComponentData * GetData ()const{return Data;}
ComponentDataPtr GetData ()const{return Data;}
public:
virtual Component *Duplication();
//virtual void Update(const double delta_time)=0;
public: //事件
virtual void OnAttach(SceneNode *node){if(node)OwnerNode=node;} ///<附加到节点事件
virtual void OnDetach(SceneNode *){OwnerNode=nullptr;} ///<从节点分离事件
virtual void OnFocusLost(){} ///<焦点丢失事件
virtual void OnFocusGained(){} ///<焦点获得事件
};//class Component
#define COMPONENT_CLASS_BODY(name) static name##ComponentManager *GetDefaultManager () {return name##ComponentManager::GetDefaultManager();} \
name##ComponentManager *GetManager ()const {return (name##ComponentManager *)Component::GetManager();} \
static constexpr const size_t StaticHashCode () {return hgl::GetTypeHash<name##Component>();} \
const size_t GetHashCode ()const override{return name##Component::StaticHashCode();}
using ComponentSet=SortedSet<Component *>;
using ComponentList=ArrayList<Component *>;
class ComponentManager
{
ComponentSet component_set;
protected:
friend class Component; //Component可以直接访问ComponentManager的成员
virtual void AttachComponent(Component *c){if(!c)return;component_set.Add(c);}
virtual void DetachComponent(Component *c){if(!c)return;component_set.Delete(c);}
public:
virtual const size_t GetComponentHashCode()const=0;
virtual const size_t GetHashCode()const=0;
virtual ~ComponentManager()=default;
virtual ~ComponentManager();
public:
virtual Component * CreateComponent(SceneNode *,ComponentData *)=0;
virtual Component * CreateComponent(ComponentDataPtr)=0;
int GetComponentCount()const{return component_set.GetCount();}
const size_t GetComponentCount()const{return component_set.GetCount();}
ComponentSet & GetComponents(){return component_set;}
int GetComponents(ArrayList<Component *> &comp_list,SceneNode *);
int GetComponents(ComponentList &comp_list,SceneNode *);
virtual void UpdateComponents(const double delta_time);
virtual void AttachComponent(Component *c){if(!c)return;component_set.Add(c);}
virtual void DetachComponent(Component *c){if(!c)return;component_set.Delete(c);}
public: //事件
virtual void OnFocusLost(){} ///<焦点丢失事件
virtual void OnFocusGained(){} ///<焦点获得事件
};//class ComponentManager
#define COMPONENT_MANAGER_CLASS_BODY(name) static name##ComponentManager * GetDefaultManager () {return GetComponentManager<name##ComponentManager>(true);} \
static constexpr const size_t StaticHashCode () {return hgl::GetTypeHash<name##ComponentManager>();} \
static constexpr const size_t StaticComponentHashCode () {return hgl::GetTypeHash<name##Component>();} \
const size_t GetComponentHashCode ()const override{return name##ComponentManager::StaticComponentHashCode();} \
const size_t GetHashCode ()const override{return name##ComponentManager::StaticHashCode();} \
bool RegistryComponentManager(ComponentManager *);
ComponentManager *GetComponentManager(const size_t hash_code);

View File

@ -0,0 +1,90 @@
#pragma once
#include<hgl/component/RenderComponent.h>
#include<hgl/graph/Mesh.h>
//#include<hgl/log/LogInfo.h>
COMPONENT_NAMESPACE_BEGIN
struct MeshComponentData:public ComponentData
{
//static uint unique_id_count;
//uint unique_id;
Mesh *mesh;
public:
MeshComponentData()
{
mesh=nullptr;
// unique_id=++unique_id_count;
// LOG_INFO(AnsiString("MeshComponentData():")+AnsiString::numberOf(unique_id));
}
MeshComponentData(Mesh *m)
{
mesh=m;
// unique_id=++unique_id_count;
// LOG_INFO(AnsiString("MeshComponentData(Mesh *):")+AnsiString::numberOf(unique_id));
}
virtual ~MeshComponentData();
};//struct MeshComponentData
class MeshComponent;
class MeshComponentManager:public ComponentManager
{
public:
COMPONENT_MANAGER_CLASS_BODY(Mesh)
public:
MeshComponentManager()=default;
Component *CreateComponent(ComponentDataPtr cdp) override;
MeshComponent *CreateComponent(Mesh *);
};//class MeshComponentManager
class MeshComponent:public RenderComponent
{
WeakPtr<ComponentData> sm_data;
public:
COMPONENT_CLASS_BODY(Mesh)
public:
MeshComponent(ComponentDataPtr cdp,MeshComponentManager *cm):RenderComponent(cdp,cm)
{
sm_data=cdp;
}
virtual ~MeshComponent()=default;
MeshComponentData *GetData() {return dynamic_cast< MeshComponentData *>(sm_data.get());}
const MeshComponentData *GetData()const {return dynamic_cast<const MeshComponentData *>(sm_data.const_get());}
Mesh *GetMesh()const
{
if(!sm_data.valid())
return(nullptr);
const MeshComponentData *mcd=dynamic_cast<const MeshComponentData *>(sm_data.const_get());
if(!mcd)
return(nullptr);
return mcd->mesh;
}
};//class MeshComponent
COMPONENT_NAMESPACE_END

View File

@ -1,6 +1,6 @@
#pragma once
#include<hgl/component/RenderComponent.h>
#include<hgl/component/SceneComponent.h>
COMPONENT_NAMESPACE_BEGIN
@ -8,12 +8,12 @@ COMPONENT_NAMESPACE_BEGIN
* <br>
*
*/
class PrimitiveComponent:public RenderComponent
class PrimitiveComponent:public SceneComponent
{
public:
PrimitiveComponent(SceneNode *psn,ComponentData *cd,ComponentManager *cm)
:RenderComponent(psn,cd,cm){}
using SceneComponent::SceneComponent;
virtual ~PrimitiveComponent()=default;
};//class PrimitiveComponent

View File

@ -1,18 +1,17 @@
#pragma once
#include<hgl/component/Component.h>
#include<hgl/component/PrimitiveComponent.h>
COMPONENT_NAMESPACE_BEGIN
/**
*
*/
class RenderComponent: public Component
class RenderComponent:public PrimitiveComponent
{
public:
RenderComponent(SceneNode *psn,ComponentData *cd,ComponentManager *cm)
:Component(psn,cd,cm){}
using PrimitiveComponent::PrimitiveComponent;
virtual ~RenderComponent()=default;
};//class RenderComponent

View File

@ -0,0 +1,31 @@
#pragma once
#include<hgl/component/Component.h>
#include<hgl/graph/SceneOrient.h>
COMPONENT_NAMESPACE_BEGIN
/**
* <br>
*
*/
class SceneComponent:public Component,public SceneOrient
{
public:
using Component::Component;
virtual ~SceneComponent()=default;
virtual Component *Duplication() override
{
SceneComponent *sc=(SceneComponent *)Component::Duplication();
if(!sc)
return(sc);
sc->SetLocalMatrix(GetLocalMatrix());
return sc;
}
};//class SceneComponent
COMPONENT_NAMESPACE_END

View File

@ -1,68 +0,0 @@
#pragma once
#include<hgl/component/PrimitiveComponent.h>
#include<hgl/graph/Mesh.h>
COMPONENT_NAMESPACE_BEGIN
struct StaticMeshComponentData:public ComponentData
{
Mesh *renderable;
};//struct StaticMeshComponentData
class StaticMeshComponent;
class StaticMeshComponentManager:public ComponentManager
{
public:
static StaticMeshComponentManager *GetDefaultManager()
{
return GetComponentManager<StaticMeshComponentManager>(true);
}
static constexpr const size_t StaticHashCode (){return hgl::GetTypeHash<StaticMeshComponentManager>();}
static constexpr const size_t StaticComponentHashCode (){return hgl::GetTypeHash<StaticMeshComponent>();}
const size_t GetComponentHashCode ()const override{return StaticMeshComponentManager::StaticComponentHashCode();}
const size_t GetHashCode ()const override{return StaticMeshComponentManager::StaticHashCode();}
public:
StaticMeshComponentManager()=default;
StaticMeshComponent *CreateStaticMeshComponent(SceneNode *psn,StaticMeshComponentData *data);
virtual Component *CreateComponent(SceneNode *psn,ComponentData *data) override;
};//class StaticMeshComponentManager
class StaticMeshComponent:public PrimitiveComponent
{
StaticMeshComponentData *sm_data;
public:
StaticMeshComponent(SceneNode *psn,ComponentData *cd,ComponentManager *cm)
:PrimitiveComponent(psn,cd,cm)
{
sm_data=reinterpret_cast<StaticMeshComponentData *>(cd);
}
virtual ~StaticMeshComponent()=default;
static constexpr const size_t StaticHashCode()
{
return hgl::GetTypeHash<StaticMeshComponent>();
}
const size_t GetHashCode()const override
{
return StaticMeshComponent::StaticHashCode();
}
StaticMeshComponentData &GetData() {return *sm_data;}
const StaticMeshComponentData &GetData()const {return *sm_data;}
};//class StaticMeshComponent
COMPONENT_NAMESPACE_END

View File

@ -11,4 +11,18 @@ namespace hgl::graph
ENUM_CLASS_RANGE(NDC,Ortho)
};
constexpr const char *CoordinateSystem2DName[]=
{
"NDC",
"0to1",
"Ortho"
};
inline const char *GetCoordinateSystem2DName(const enum class CoordinateSystem2D &cs)
{
RANGE_CHECK_RETURN_NULLPTR(cs)
return CoordinateSystem2DName[size_t(cs)];
}
}//namespace hgl::graph

View File

@ -102,14 +102,14 @@ protected:
bool BindVAB(const MeshDataBuffer *,const uint);
void ProcIndirectRender();
void Render(RenderItem *);
bool Render(RenderItem *);
public:
MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi);
~MaterialRenderList();
void Add(SceneNode *);
void Add(MeshComponent *);
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
@ -120,6 +120,6 @@ public:
void Render(RenderCmdBuffer *);
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
void UpdateMaterialInstance(SceneNode *);
void UpdateMaterialInstance(MeshComponent *);
};//class MaterialRenderList
VK_NAMESPACE_END

View File

@ -13,7 +13,7 @@ class PrimitiveCreater
{
protected:
VulkanDevice * device;
VulkanDevice * device;
VertexDataManager * vdm;
const VIL * vil;

View File

@ -6,6 +6,11 @@
#include<hgl/graph/module/SwapchainModule.h>
#include<hgl/graph/module/GraphModuleManager.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/CameraControl.h>
#include<hgl/graph/Renderer.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/mtl/MaterialLibrary.h>
#include<hgl/io/event/MouseEvent.h>
VK_NAMESPACE_BEGIN
@ -17,6 +22,9 @@ class RenderTargetManager;
class RenderModule;
class Scene;
class Renderer;
class CameraComponentManager{/*现阶段测试使用*/};
class LightComponentManager{/*现阶段测试使用*/};
@ -27,7 +35,7 @@ class RenderFramework:public io::WindowEvent
Window * win =nullptr;
VulkanInstance * inst =nullptr;
VulkanDevice * device =nullptr;
VulkanDevice * device =nullptr;
RenderResource * render_resource =nullptr;
@ -47,15 +55,28 @@ protected:
CameraComponentManager *camera_component_manager=nullptr;
LightComponentManager *light_component_manager =nullptr;
protected: //RenderContext,未来合并成一个RenderContext结构
Scene * default_scene =nullptr;
Camera * default_camera =nullptr;
CameraControl * default_camera_control =nullptr;
Renderer * default_renderer =nullptr;
void CreateDefaultRenderer();
protected: //InputEvent
io::MouseEvent *mouse_event=nullptr;
public:
Window * GetWindow ()const{return win;}
VulkanDevice * GetDevice ()const{return device;}
VkDevice GetVkDevice ()const{return device->GetDevice();}
const VulkanPhyDevice * GetPhyDevice ()const{return device->GetPhyDevice();}
VulkanDevAttr * GetDevAttr ()const{return device->GetDevAttr();}
Window * GetWindow ()const{return win;}
VulkanDevice * GetDevice ()const{return device;}
VkDevice GetVkDevice ()const{return device->GetDevice();}
const VulkanPhyDevice * GetPhyDevice ()const{return device->GetPhyDevice();}
VulkanDevAttr * GetDevAttr ()const{return device->GetDevAttr();}
RenderResource * GetRenderResource ()const{return render_resource;}
RenderResource * GetRenderResource ()const{return render_resource;}
public:
@ -68,6 +89,26 @@ public:
SwapchainModule * GetSwapchainModule (){return sc_module;}
SwapchainRenderTarget * GetSwapchainRenderTarget(){return sc_module?sc_module->GetRenderTarget():nullptr;}
public:
Scene * GetDefaultScene (){return default_scene;}
Camera * GetDefaultCamera (){return default_camera;}
CameraControl * GetDefaultCameraControl (){return default_camera_control;}
Renderer * GetDefaultRenderer (){return default_renderer;}
RenderPass * GetDefaultRenderPass (){return default_renderer->GetRenderPass();}
public:
bool GetMouseCoord(Vector2i *mc)const
{
if(!mouse_event||!mc)
return(false);
*mc=mouse_event->GetMouseCoord();
return(true);
}
public:
RenderFramework(const OSString &);
@ -81,6 +122,10 @@ public: // event
virtual void OnActive(bool);
virtual void OnClose();
public:
void Tick();
public: // other
RenderList *CreateRenderList()
@ -90,6 +135,55 @@ public: // other
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建只使用一种字符的Tile字符管理对象
public:
template<typename ...ARGS>
graph::Pipeline *CreatePipeline(ARGS...args)
{
return GetDefaultRenderPass()->CreatePipeline(args...);
}
graph::MaterialInstance *CreateMaterialInstance(const AnsiString &mi_name,const graph::mtl::MaterialCreateInfo *mci,const graph::VILConfig *vil_cfg=nullptr)
{
return render_resource->CreateMaterialInstance(mi_name,mci,vil_cfg);
}
graph::MaterialInstance *CreateMaterialInstance(const AnsiString &mtl_name,graph::mtl::MaterialCreateConfig *mtl_cfg,const graph::VILConfig *vil_cfg=nullptr)
{
AutoDelete<graph::mtl::MaterialCreateInfo> mci=graph::mtl::CreateMaterialCreateInfo(GetDevAttr(),mtl_name,mtl_cfg);
return render_resource->CreateMaterialInstance(mtl_name,mci,vil_cfg);
}
SharedPtr<graph::PrimitiveCreater> GetPrimitiveCreater(graph::Material *mtl)
{
if(!mtl)
return(nullptr);
return(new graph::PrimitiveCreater(GetDevice(),mtl->GetDefaultVIL()));
}
SharedPtr<graph::PrimitiveCreater> GetPrimitiveCreater(graph::MaterialInstance *mi)
{
if(!mi)
return(nullptr);
return(new graph::PrimitiveCreater(GetDevice(),mi->GetVIL()));
}
public: // Primitive, Mesh
graph::Primitive *CreatePrimitive(const AnsiString &name,
const uint32_t vertices_count,
const graph::VIL *vil,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
graph::Mesh *CreateMesh(const AnsiString &name,
const uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
public: // ComponentManager
template<typename T> T *GetComponentManager()
@ -106,6 +200,74 @@ public: // ComponentManager
{
return light_component_manager;
}
public: //Component 相关
template<typename C,typename ...ARGS>
inline C *CreateComponent(ARGS...args)
{
auto manager=C::GetDefaultManager(); //取得默认管理器
if(!manager)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, no default manager!"));
return(nullptr);
}
return manager->CreateComponent(args...); //创建组件
}
template<typename C,typename ...ARGS>
inline C *CreateComponent(graph::SceneNode *parent_node,ARGS...args)
{
if(!parent_node)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, parent node is null!"));
return(nullptr);
}
C *c=this->CreateComponent<C>(args...); //创建组件
if(!c)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, create component failed!"));
return(nullptr);
}
/**
* Component头文件
*/
parent_node->AttachComponent(c); //将组件附加到父节点
return c;
}
template<typename C,typename ...ARGS>
inline C *CreateComponent(const graph::Matrix4f &mat,graph::SceneNode *parent_node,ARGS...args)
{
if(!parent_node)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, parent node is null!"));
return(nullptr);
}
C *c=this->CreateComponent<C>(args...); //创建组件
if(!c)
{
// LOG_ERROR(OS_TEXT("CreateComponent failed, create component failed!"));
return(nullptr);
}
/**
* Component头文件
*/
parent_node->AttachComponent(c); //将组件附加到父节点
c->graph::SceneOrient::SetLocalMatrix(mat);
return c;
}
};//class RenderFramework
VK_NAMESPACE_END

View File

@ -29,18 +29,24 @@ namespace hgl
virtual bool ExpendNode(SceneNode *);
public:
const CameraInfo *GetCameraInfo()const{return camera_info;}
public:
RenderList(VulkanDevice *);
virtual ~RenderList()=default;
virtual void SetCamera(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
virtual void SetCameraInfo(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
bool IsEmpty()const{return !renderable_count;} ///<是否是空的
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
virtual void UpdateMaterialInstance(SceneNode *); ///<有对象互换了材质实例
virtual void UpdateMaterialInstance(MeshComponent *); ///<有对象互换了材质实例
virtual void Clear(); ///<彻底清理
};//class RenderList

View File

@ -9,13 +9,13 @@ namespace hgl
{
class Mesh;
class MaterialInstance;
class SceneNode;
class MeshComponent;
struct RenderNode:public Comparator<RenderNode>
{
uint index; ///<在MaterialRenderList中的索引
SceneNode * scene_node;
MeshComponent *sm_component; ///<静态网格组件
uint32 l2w_version;
uint32 l2w_index;
@ -27,6 +27,11 @@ namespace hgl
//该函数位于MaterialRenderList.cpp
const int compare(const RenderNode &)const override;
public:
Mesh *GetMesh()const;
MaterialInstance *GetMaterialInstance()const;
};
using RenderNodeList=ArrayList<RenderNode>;

View File

@ -0,0 +1,44 @@
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/type/IDName.h>
namespace hgl::graph
{
HGL_DEFINE_IDNAME(RenderTaskName,char)
/**
*
*/
class RenderTask
{
RenderTaskName task_name;
IRenderTarget * render_target;
RenderList * render_list;
CameraInfo * camera_info;
public:
const RenderTaskName &GetName ()const;
IRenderTarget * GetRenderTarget ()const{return render_target;}
RenderList * GetRenderList ()const{return render_list;}
CameraInfo * GetCameraInfo ()const{return camera_info;}
public:
RenderTask(const RenderTaskName &tn,IRenderTarget *rt=nullptr,CameraInfo *ci=nullptr);
virtual ~RenderTask();
bool SetRenderTarget(IRenderTarget *);
void SetCameraInfo(CameraInfo *);
bool RebuildRenderList(SceneNode *);
bool IsEmpty()const; ///<是否是空的,不可渲染或是没啥可渲染的
bool Render(RenderCmdBuffer *);
};//class RenderTask
}//namespace hgl::graph

57
inc/hgl/graph/Renderer.h Normal file
View File

@ -0,0 +1,57 @@
#pragma once
#include<hgl/graph/RenderTask.h>
#include<hgl/graph/VKRenderTarget.h>
#include<hgl/graph/CameraControl.h>
#include<hgl/type/Map.h>
namespace hgl::graph
{
class Scene;
class CameraControl;
using RenderTaskNameMap=Map<RenderTaskName,RenderTask *>;
/**
*
*/
class Renderer
{
IRenderTarget *render_target;
Scene *scene;
CameraControl *camera_control;
//RenderTaskNameMap static_render_task_list; ///<静态渲染任务列表
//RenderTaskNameMap dynamic_render_task_list; ///<动态渲染任务列表
RenderTask *render_task; ///<当前渲染任务
Color4f clear_color; ///<清屏颜色
bool build_frame=false;
public:
RenderPass *GetRenderPass (){return render_target->GetRenderPass();} ///<取得当前渲染器RenderPass
const VkExtent2D &GetExtent ()const{return render_target->GetExtent();} ///<取得当前渲染器画面尺寸
Scene * GetScene ()const{return scene;} ///<获取场景世界
Camera * GetCamera ()const{return camera_control->GetCamera();} ///<获取当前相机
public:
Renderer(IRenderTarget *);
virtual ~Renderer();
bool SetRenderTarget(IRenderTarget *);
void SetScene(Scene *);
void SetCameraControl(CameraControl *);
void SetClearColor(const Color4f &c){clear_color=c;}
bool RenderFrame(); ///<重新重成这一帧的CommandList
bool Submit(); ///<提交CommandList到GPU
};//class Renderer
}//namespace hgl::graph

50
inc/hgl/graph/Scene.h Normal file
View File

@ -0,0 +1,50 @@
#pragma once
#include<hgl/graph/SceneNode.h>
#include<hgl/type/Pool.h>
namespace hgl::graph
{
/**
* <Br>
*
*/
class Scene
{
U8String SceneName; ///<场景名称
ObjectList<SceneNode> SceneNodePool; ///<场景节点池
SceneNode *root_node; ///<场景根节点
public:
const U8String & GetSceneName()const{return SceneName;} ///<获取场景名称
SceneNode * GetRootNode (){return root_node;} ///<获取场景根节点
public:
Scene()
{
root_node=new SceneNode;
}
virtual ~Scene()
{
SAFE_CLEAR(root_node);
}
};//class Scene
bool RegistryScene(Scene *sw); ///<注册场景
bool UnregistryScene(const U8String &scene_name); ///<注销场景
inline bool UnregistryScene(Scene *sw) ///<注销场景
{
if(!sw)return(false);
return UnregistryScene(sw->GetSceneName());
}
Scene *GetScene(const U8String &scene_name); ///<获取指定名称的场景
}//namespace hgl::graph

View File

@ -8,8 +8,11 @@
namespace hgl::graph
{
using SceneNodeID =uint64;
using SceneNodeName =U16IDName;
using SceneNodeID =int64;
using SceneNodeList =ObjectList<SceneNode>;
HGL_DEFINE_U16_IDNAME(SceneNodeName)
/**
* <br>
@ -18,30 +21,33 @@ namespace hgl::graph
*/
class SceneNode:public SceneOrient ///场景节点类
{
SceneNode *ParentNode; ///<上级节点
SceneNode *parent_node=nullptr; ///<上级节点
SceneNodeID NodeID; ///<节点ID
SceneNodeName NodeName; ///<节点名称
SceneNodeID node_id=-1; ///<节点ID
SceneNodeName node_name; ///<节点名称
protected:
AABB BoundingBox; ///<绑定盒
AABB LocalBoundingBox; ///<本地坐标绑定盒
AABB bounding_box; ///<绑定盒
AABB local_bounding_box; ///<本地坐标绑定盒
//AABB WorldBoundingBox; ///<世界坐标绑定盒
Mesh *render_obj=nullptr; ///<可渲染实例
protected:
ObjectList<SceneNode> ChildNode; ///<子节点
ObjectList<Component> ComponentList; ///<组件列表
SceneNodeList child_nodes; ///<子节点
/**
* SceneNode下可能会包含多个组件SceneNode使用
* ComponentManager管理
*/
ComponentSet component_set; ///<组件合集
public:
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
const SceneNodeID & GetNodeID ()const { return node_id; } ///<取得节点ID
const SceneNodeName & GetNodeName ()const { return node_name; } ///<取得节点名称
const ObjectList<SceneNode> &GetChildNode()const { return ChildNode; } ///<取得子节点列表
const SceneNodeList & GetChildNode()const { return child_nodes; } ///<取得子节点列表
public:
@ -49,76 +55,87 @@ namespace hgl::graph
SceneNode(const SceneNode &)=delete;
SceneNode(const SceneNode *)=delete;
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
SceneNode( Mesh *ri ) {render_obj=ri;}
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
SceneNode(const Matrix4f &mat, Mesh *ri ):SceneOrient(mat) {render_obj=ri;}
public:
virtual ~SceneNode()=default;
virtual ~SceneNode();
void Clear() override
{
SceneOrient::Clear();
ParentNode=nullptr;
parent_node=nullptr;
BoundingBox.SetZero();
LocalBoundingBox.SetZero();
bounding_box.SetZero();
local_bounding_box.SetZero();
ChildNode.Clear();
ComponentList.Clear();
render_obj=nullptr;
child_nodes.Clear();
component_set.Clear();
}
const bool ChildNodeIsEmpty()const
{
if(render_obj)return(false);
if(ChildNode.GetCount())return(false);
if(child_nodes.GetCount())return(false);
return(true);
}
void SetParent(SceneNode *sn) {ParentNode=sn;}
SceneNode * GetParent() noexcept{return ParentNode;}
const SceneNode * GetParent()const noexcept{return ParentNode;}
void SetRenderable(Mesh *);
Mesh * GetRenderable() noexcept{return render_obj;}
const Mesh * GetRenderable()const noexcept{return render_obj;}
void SetParent(SceneNode *sn) {parent_node=sn;}
SceneNode * GetParent() noexcept{return parent_node;}
const SceneNode * GetParent()const noexcept{return parent_node;}
SceneNode *Add(SceneNode *sn)
{
if(!sn)
return(nullptr);
ChildNode.Add(sn);
child_nodes.Add(sn);
sn->SetParent(this);
return sn;
}
public: //坐标相关方法
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
virtual void SetBoundingBox (const AABB &bb){bounding_box=bb;} ///<设置绑定盒
virtual void RefreshMatrix () override; ///<刷新世界变换
virtual void RefreshBoundingBox (); ///<刷新绑定盒
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
virtual const AABB & GetBoundingBox ()const{return bounding_box;} ///<取得绑定盒
virtual const AABB & GetLocalBoundingBox ()const{return local_bounding_box;} ///<取得本地坐标绑定盒
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
public: //组件相关方法
bool ComponentIsEmpty ()const {return ComponentList.GetCount()==0;} ///<是否没有组件
virtual int GetComponentCount ()const {return ComponentList.GetCount();} ///<取得组件数量
virtual void AddComponent (Component *comp) {ComponentList.Add(comp);} ///<添加一个组件
virtual void RemoveComponent (Component *comp) {ComponentList.DeleteByValue(comp);} ///<删除一个组件
bool Contains (Component *comp) {return ComponentList.Contains(comp);} ///<是否包含指定组件
bool ComponentIsEmpty ()const{return component_set.IsEmpty();} ///<是否没有组件
virtual const int64 GetComponentCount ()const{return component_set.GetCount();} ///<取得组件数量
virtual bool AttachComponent (Component *comp) ///<添加一个组件
{
if(!comp)return(false);
if(component_set.Add(comp)<0)
return(false);
comp->OnAttach(this); //调用组件的OnAttach方法
return(true);
}
virtual void DetachComponent (Component *comp) ///<删除一个组件
{
if (!comp)return;
component_set.Delete(comp);
comp->OnDetach(this); //调用组件的OnDetach方法
}
bool Contains (Component *comp){return component_set.Contains(comp);} ///<是否包含指定组件
bool HasComponent (const ComponentManager *); ///<是否有指定组件管理器的组件
virtual int GetComponents (ArrayList<Component *> &comp_list,const ComponentManager *); ///<取得所有组件
virtual int GetComponents (ComponentList &comp_list,const ComponentManager *); ///<取得所有组件
const ComponentSet &GetComponents ()const{return component_set;}
};//class SceneNode
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点

View File

@ -1,38 +0,0 @@
#pragma once
#include<hgl/graph/SceneNode.h>
namespace hgl::graph
{
class CameraData
{
};
class CameraManager
{
public:
};
/**
* <Br>
*
*/
class SceneWorld
{
SceneNode *root_node; ///<世界根节点
public:
SceneWorld()
{
root_node=new SceneNode;
}
virtual ~SceneWorld()
{
SAFE_CLEAR(root_node);
}
SceneNode *GetRootNode(){return root_node;}
};//class SceneWorld
}//namespace hgl::graph

View File

@ -96,6 +96,7 @@ class Semaphore;
struct PipelineLayoutData;
class DescriptorSet;
enum class DescriptorSetType;
struct VertexInputAttribute;
@ -134,7 +135,16 @@ class IndirectDispatchBuffer;
class RenderResource;
class StaticMesh;
class MeshComponent;
class SceneNode;
class Scene;
class RenderList;
struct CameraInfo;
struct Camera;
class Renderer;
enum class SharingMode
{

View File

@ -2,6 +2,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKMemory.h>
#include<hgl/graph/mtl/ShaderBufferSource.h>
VK_NAMESPACE_BEGIN
struct DeviceBufferData
@ -53,6 +54,8 @@ public:
template<typename T> class DeviceBufferMap
{
protected:
DeviceBuffer *dev_buf;
T data_map;
@ -75,7 +78,7 @@ public:
delete dev_buf;
}
operator DeviceBuffer *(){return dev_buf;}
DeviceBuffer *GetDeviceBuffer(){return dev_buf;}
T *data(){return &data_map;}
@ -84,6 +87,32 @@ public:
if(dev_buf)
dev_buf->Write(&data_map,sizeof(T));
}
};
};//template<typename T> class DeviceBufferMap
template<typename T> class UBOInstance:public DeviceBufferMap<T>
{
DescriptorSetType desc_set_type;
AnsiString ubo_name;
public:
const DescriptorSetType & set_type()const{return desc_set_type;}
const AnsiString & name ()const{return ubo_name;}
DeviceBuffer * ubo ()const{return this->dev_buf;}
public:
UBOInstance(DeviceBuffer *buf,const DescriptorSetType dst,const AnsiString &n):DeviceBufferMap<T>(buf)
{
desc_set_type=dst;
ubo_name=n;
}
UBOInstance(DeviceBuffer *buf,const ShaderBufferDesc *desc):DeviceBufferMap<T>(buf)
{
desc_set_type=desc->set_type;
ubo_name=desc->name;
}
};//template<typename T> class UBOInstance:public DeviceBufferMap<T>
VK_NAMESPACE_END

View File

@ -22,6 +22,7 @@ public:
buffer=nullptr;
offset=0;
stride=count=0;
map_ptr=nullptr;
}
virtual ~VKBufferMap()
@ -29,7 +30,7 @@ public:
Unmap();
}
void Set(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
void Bind(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
{
buffer=buf;
offset=off;

View File

@ -51,6 +51,9 @@ public:
class DescriptorBinding;
using DescriptorBindingPtr=DescriptorBinding *;
using DescriptorBindingPtrArray=DescriptorBindingPtr[size_t(DescriptorSetType::RANGE_SIZE)];
class RenderCmdBuffer:public VulkanCmdBuffer
{
uint32_t cv_count;
@ -61,7 +64,14 @@ class RenderCmdBuffer:public VulkanCmdBuffer
RenderPassBeginInfo rp_begin;
VkPipelineLayout pipeline_layout;
DescriptorBinding *desc_binding=nullptr;
/*
* desc绑定会全部使用这些自动绑定器绑定
*
*
* DescriptSetType::RenderTarget RenderTarget模块设置
* DescriptSetType::Scene Scene模块设置
*/
DescriptorBindingPtrArray desc_binding{};
private:
@ -72,11 +82,11 @@ public:
RenderCmdBuffer(const VulkanDevAttr *attr,VkCommandBuffer cb);
~RenderCmdBuffer();
void SetDescriptorBinding(DescriptorBinding *db) { desc_binding=db; }
bool SetDescriptorBinding(DescriptorBinding *);
bool End() override
{
desc_binding=nullptr;
hgl_zero(desc_binding);
return VulkanCmdBuffer::End();
}

View File

@ -2,8 +2,7 @@
#include<hgl/type/Map.h>
#include<hgl/type/String.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/graph/VKBuffer.h>
VK_NAMESPACE_BEGIN
@ -24,6 +23,10 @@ class DescriptorBinding
Map<AnsiString,DeviceBuffer *> ssbo_map;
Map<AnsiString,Texture *> texture_map;
public:
const DescriptorSetType GetType()const{return set_type;}
public:
DescriptorBinding(const DescriptorSetType &dst)
@ -39,11 +42,35 @@ public:
return ubo_map.Add(name,buf);
}
template<typename T>
bool AddUBO(const AnsiString &name,DeviceBufferMap<T> *dbm)
{
if(name.IsEmpty()||!dbm)
return(false);
return ubo_map.Add(name,dbm->GetDeviceBuffer());
}
template<typename T>
bool AddUBO(const UBOInstance<T> *ubo_instance)
{
if(!ubo_instance)
return(false);
if(ubo_instance->set_type()!=set_type)
return(false);
if(ubo_instance->name().IsEmpty())
return(false);
return ubo_map.Add(ubo_instance->name(),ubo_instance->ubo());
}
DeviceBuffer *GetUBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetObjectFromList(ubo_map,name);
return GetObjectFromMap(ubo_map,name);
}
void RemoveUBO(DeviceBuffer *buf)
@ -61,11 +88,17 @@ public:
return ssbo_map.Add(name,buf);
}
template<typename T>
bool AddSSBO(const AnsiString &name,DeviceBufferMap<T> *dbm)
{
return AddSSBO(name,dbm->GetDeviceBuffer());
}
DeviceBuffer *GetSSBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetObjectFromList(ssbo_map,name);
return GetObjectFromMap(ssbo_map,name);
}
void RemoveSSBO(DeviceBuffer *buf)
@ -87,7 +120,7 @@ public:
{
if(name.IsEmpty())return(nullptr);
return GetObjectFromList(texture_map,name);
return GetObjectFromMap(texture_map,name);
}
void RemoveTexture(Texture *tex)

View File

@ -123,6 +123,18 @@ public: //Buffer相关
{ \
DeviceBuffer *buf=Create##LargeName(T::GetSize()); \
return(buf?new T(buf):nullptr); \
} \
\
template<typename T> T *Create##LargeName(const ShaderBufferDesc *desc) \
{ \
DeviceBuffer *buf=Create##LargeName(T::GetSize()); \
return(buf?new T(buf,desc):nullptr); \
} \
\
template<typename T> T *Create##LargeName(const DescriptorSetType &set_type,const AnsiString &name) \
{ \
DeviceBuffer *buf=Create##LargeName(T::GetSize()); \
return(buf?new T(buf,set_type,name):nullptr); \
}
CREATE_BUFFER_OBJECT(UBO,UNIFORM)

View File

@ -54,7 +54,7 @@ public:
void SetIBO(IndexBuffer *ib,const int32_t index_offset,const uint32_t count)
{
VKBufferMap<IndexBuffer>::Set(ib,index_offset,ib->GetStride(),count);
VKBufferMap<IndexBuffer>::Bind(ib,index_offset,ib->GetStride(),count);
}
};//class IBMap

View File

@ -1,11 +1,11 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/type/SortedSet.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/graph/mtl/ShaderBufferSource.h>
namespace hgl
{
@ -24,6 +24,8 @@ class Material
{
AnsiString name;
PrimitiveType prim; ///<图元类型
VertexInput *vertex_input;
ShaderModuleMap *shader_maps;
@ -45,7 +47,7 @@ private:
friend class RenderResource;
Material(const AnsiString &);
Material(const AnsiString &,const PrimitiveType &);
public:
@ -53,6 +55,8 @@ public:
const AnsiString & GetName ()const{return name;}
const PrimitiveType & GetPrimitiveType ()const{return prim;}
const VertexInput * GetVertexInput ()const{return vertex_input;}
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
@ -83,6 +87,11 @@ public:
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
bool BindUBO(const ShaderBufferDesc *sbd,DeviceBuffer *ubo,bool dynamic=false)
{
return BindUBO(sbd->set_type,sbd->name,ubo,dynamic);
}
void Update();
public:
@ -97,6 +106,5 @@ public:
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
};//class Material
using MaterialSets=SortedSet<Material *>;
using MaterialSet=SortedSet<Material *>;
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE

View File

@ -73,7 +73,7 @@ public:
const int GetMIID ()const{return mi_id;} ///<取得材质实例ID
void * GetMIData (){return material->GetMIData(mi_id);} ///<取得材质实例数据
void WriteMIData (const void *data,const int size); ///<写入材质实例数据
void WriteMIData (const void *data,const uint32 size); ///<写入材质实例数据
template<typename T>
void WriteMIData (const T &data){WriteMIData(&data,sizeof(T));} ///<写入材质实例数据

View File

@ -2,7 +2,6 @@
#include<hgl/graph/VK.h>
#include<hgl/type/String.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
class VulkanPhyDevice

View File

@ -21,13 +21,19 @@ protected:
protected:
AABB BoundingBox;
AABB bounding_box;
public:
Primitive(const AnsiString &pn,PrimitiveData *pd);
virtual ~Primitive();
void SetBoundingBox(const AABB &bb) { bounding_box=bb; } ///<设置包围盒
void SetBoundingBox(const Vector3f &box_min,const Vector3f &box_max)
{
bounding_box.SetMinMax(box_min,box_max);
}
public:
const AnsiString & GetName ()const{ return prim_name; }
@ -48,6 +54,6 @@ public:
VertexDataManager * GetVDM (); ///<取得顶点数据管理器
const AABB & GetBoundingBox ()const{return BoundingBox;}
const AABB & GetBoundingBox ()const{return bounding_box;}
};//class Primitive
VK_NAMESPACE_END

View File

@ -56,15 +56,15 @@ public:
public:
Pipeline *CreatePipeline(Material *,const VIL *,const PipelineData *, const PrimitiveType &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const PrimitiveType &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *,const VIL *,const PipelineData *, const bool prim_restart=false);
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const bool prim_restart=false);
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const PrimitiveType &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const PrimitiveType &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const bool prim_restart=false);
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const PrimitiveType &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const PrimitiveType &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const PrimitiveType &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const bool prim_restart=false);
};//class RenderPass
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE

View File

@ -31,7 +31,7 @@ using MaterialInstanceID =int;
using BufferID =int;
using DescriptorSetID =int;
using PrimitiveID =int;
using RenderableID =int;
using MeshID =int;
using SamplerID =int;
using StaticMeshID =int;
@ -54,7 +54,7 @@ class RenderResource
IDObjectManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
IDObjectManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
IDObjectManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
IDObjectManage<RenderableID, Mesh> rm_renderables; ///<渲染实例集合集
IDObjectManage<MeshID, Mesh> rm_mesh; ///<渲染实例集合集
private:
@ -77,16 +77,9 @@ public:
VulkanDevice *GetDevice(){return device;}
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
DescriptorBinding static_descriptor; ///<静态属性描述符绑定管理
DescriptorBinding global_descriptor; ///<全局属性描述符绑定管理
public:
RenderResource(VulkanDevice *dev):device(dev),
static_descriptor(DescriptorSetType::Static),
global_descriptor(DescriptorSetType::Global)
{}
RenderResource(VulkanDevice *dev):device(dev){}
virtual ~RenderResource()=default;
public: //添加数据到管理器如果指针为nullptr会返回-1
@ -97,7 +90,7 @@ public: //添加数据到管理器如果指针为nullptr会返回-1
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
RenderableID Add(Mesh * r ){return rm_renderables.Add(r);}
MeshID Add(Mesh * r ){return rm_mesh.Add(r);}
public: // VAB/VAO
@ -157,7 +150,7 @@ public: //Get
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
Mesh * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
Mesh * GetMesh (const MeshID &id){return rm_mesh.Get(id);}
public: //Release
@ -167,7 +160,7 @@ public: //Release
void Release(Primitive * p ){rm_primitives.Release(p);}
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
void Release(Sampler * s ){rm_samplers.Release(s);}
void Release(Mesh * r ){rm_renderables.Release(r);}
void Release(Mesh * r ){rm_mesh.Release(r);}
};//class RenderResource
/**

View File

@ -5,6 +5,7 @@
#include<hgl/graph/VKFramebuffer.h>
#include<hgl/graph/VKSwapchain.h>
#include<hgl/graph/VKQueue.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKDescriptorBindingManage.h>
@ -14,7 +15,7 @@ VK_NAMESPACE_BEGIN
class RenderFramework;
using UBOViewportInfo=DeviceBufferMap<graph::ViewportInfo>;
using UBOViewportInfo=UBOInstance<graph::ViewportInfo>;
class IRenderTarget
{
@ -29,7 +30,7 @@ class IRenderTarget
public:
RenderFramework * GetRenderFramework ()const{return render_framework;}
VulkanDevice * GetDevice ()const;
VulkanDevice * GetDevice ()const;
VkDevice GetVkDevice ()const;
DescriptorBinding * GetDescriptorBinding(){return &desc_binding;}
@ -72,10 +73,9 @@ public: // Command Buffer
public:
virtual void Bind (Material *mtl)
virtual ViewportInfo * GetViewportInfo ()
{
if(mtl)
desc_binding.Bind(mtl);
return ubo_vp_info->data();
}
};//class IRenderTarget

View File

@ -1,9 +1,7 @@
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
#define HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/VKVertexInputLayout.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
@ -46,4 +44,3 @@ public:
operator VkShaderModule ()const{return stage_create_info->module;}
};//class ShaderModule
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE

View File

@ -38,16 +38,31 @@ public:
return write_count>=vab_count;
}
void Add(const VkBuffer buf,const VkDeviceSize offset)
bool Add(const VkBuffer buf,const VkDeviceSize offset)
{
if(IsFull())
{
//如果在这里出现错误一般是材质的VertexInput与实现要使用的不匹配。很多时候是由于引擎自动添加的VertexInput但材质里没有。
//比较典型的情况是创建材质时设置了不需要L2W,但实际又进行了传递
return(false); //列表已满
}
vab_list[write_count]=buf;
vab_offset[write_count]=offset;
++write_count;
return(true);
}
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
bool Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
{
if(!buf||!offset||!count)
return(false);
if(write_count+count>vab_count)
return(false); //列表已满
hgl_cpy(vab_list +write_count,buf, count);
if(offset)
@ -56,6 +71,7 @@ public:
hgl_set<VkDeviceSize>(vab_offset+write_count,VkDeviceSize(0),count);
write_count+=count;
return(true);
}
};//class VABList
VK_NAMESPACE_END

View File

@ -52,9 +52,9 @@ public:
const VkFormat GetFormat()const { return buffer->GetFormat(); }
void SetVAB(VAB *vab,const VkDeviceSize off,const uint32_t count)
void BindVAB(VAB *vab,const VkDeviceSize off,const uint32_t count)
{
VKBufferMap<VAB>::Set(vab,off,vab->GetStride(),count);
VKBufferMap<VAB>::Bind(vab,off,vab->GetStride(),count);
}
};//class VABMap

View File

@ -27,7 +27,7 @@ public:
public:
GraphModule * Get(const size_t type_hash) {return GetObjectFromList(module_map,type_hash);} ///<取得指定类型的模块
GraphModule * Get(const size_t type_hash) {return GetObjectFromMap(module_map,type_hash);} ///<取得指定类型的模块
template<typename T>
T * Get() {return((T *)Get(typeid(T).hash_code()));} ///<取得指定类型的模块

View File

@ -14,9 +14,12 @@ namespace blinnphong
constexpr const ShaderBufferSource SBS_SunLight=
{
"SunLight",
DescriptorSetType::Scene,
"sun",
"SunLight",
R"(
vec4 direction;
vec4 color;

View File

@ -1,7 +1,7 @@
#pragma once
#include<hgl/graph/mtl/MaterialLibrary.h>
#include<hgl/graph/mtl/MaterialConfig.h>
#include<hgl/graph/mtl/MaterialCreateConfig.h>
#include<hgl/graph/CoordinateSystem.h>
#include<hgl/graph/VertexAttrib.h>
@ -51,6 +51,8 @@ public:
return off;
}
const AnsiString ToHashString() override;
};//struct Material2DCreateConfig:public MaterialCreateConfig
DEFINE_MATERIAL_FACTORY_CLASS(VertexColor2D, const Material2DCreateConfig)

View File

@ -1,7 +1,7 @@
#pragma once
#include<hgl/graph/mtl/MaterialLibrary.h>
#include<hgl/graph/mtl/MaterialConfig.h>
#include<hgl/graph/mtl/MaterialCreateConfig.h>
#include<hgl/graph/CoordinateSystem.h>
#include<hgl/graph/VertexAttrib.h>
@ -19,14 +19,17 @@ struct Material3DCreateConfig:public MaterialCreateConfig,public Comparator<Mate
public:
Material3DCreateConfig(const PrimitiveType &p):MaterialCreateConfig(p)
Material3DCreateConfig(const PrimitiveType &p,
const WithCamera &wc=WithCamera::With,
const WithLocalToWorld &l2w=WithLocalToWorld::With)
:MaterialCreateConfig(p)
{
rt_output.color=1; //输出一个颜色
rt_output.depth=true; //不输出深度
rt_output.stencil=false; //不输出stencil
camera=true;
local_to_world=false;
camera=(wc==WithCamera::With);
local_to_world=(l2w==WithLocalToWorld::With);
position_format=VAT_VEC3;
@ -49,6 +52,8 @@ public:
return off;
}
const AnsiString ToHashString() override;
};//struct Material3DCreateConfig:public MaterialCreateConfig
DEFINE_MATERIAL_FACTORY_CLASS(VertexColor3D, const Material3DCreateConfig);

View File

@ -52,5 +52,7 @@ public:
return off;
}
virtual const AnsiString ToHashString();
};//struct MaterialCreateConfig
STD_MTL_NAMESPACE_END

View File

@ -7,7 +7,7 @@
STD_MTL_NAMESPACE_BEGIN
DefineIDName(MaterialName, char)
HGL_DEFINE_ANSI_IDNAME(MaterialName)
class MaterialFactory
{

View File

@ -1,11 +1,19 @@
#pragma once
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl::graph
{
struct ShaderBufferSource
struct ShaderBufferDesc
{
const DescriptorSetType set_type;
const char *name;
};
struct ShaderBufferSource:public ShaderBufferDesc
{
const char *struct_name;
const char *name;
const char *codes;
};
}//namespace hgl::graph

View File

@ -23,6 +23,12 @@ namespace hgl::graph
namespace mtl
{
enum class WithCamera:uint8
{
Without=0,
With
};
enum class WithLocalToWorld:uint8
{
Without=0,

View File

@ -6,8 +6,10 @@
STD_MTL_NAMESPACE_BEGIN
constexpr const ShaderBufferSource SBS_ViewportInfo=
{
"ViewportInfo",
DescriptorSetType::RenderTarget,
"viewport",
"ViewportInfo",
R"(
mat4 ortho_matrix;
@ -20,8 +22,10 @@ constexpr const ShaderBufferSource SBS_ViewportInfo=
constexpr const ShaderBufferSource SBS_CameraInfo=
{
"CameraInfo",
DescriptorSetType::Camera,
"camera",
"CameraInfo",
R"(
mat4 projection;
@ -48,12 +52,13 @@ constexpr const ShaderBufferSource SBS_CameraInfo=
};
constexpr const char LocalToWorldStruct[]="LocalToWorld";
constexpr const DescriptorSetType DST_LocalToWorld=DescriptorSetType::PerFrame;
constexpr const ShaderBufferSource SBS_LocalToWorld=
{
"LocalToWorldData",
DescriptorSetType::PerFrame,
"l2w",
"LocalToWorldData",
R"(
mat4 mats[L2W_MAX_COUNT];
@ -64,12 +69,13 @@ constexpr const ShaderBufferSource SBS_LocalToWorld=
// SSBO则不需要使用[]方式指定为动态大小数组
constexpr const char MaterialInstanceStruct[]="MaterialInstance";
constexpr const DescriptorSetType DST_MaterialInstance=DescriptorSetType::PerMaterial;
constexpr const ShaderBufferSource SBS_MaterialInstance=
{
"MaterialInstanceData",
DescriptorSetType::PerMaterial,
"mtl",
"MaterialInstanceData",
R"(
MaterialInstance mi[MI_MAX_COUNT];)"
@ -77,11 +83,13 @@ constexpr const ShaderBufferSource SBS_MaterialInstance=
constexpr const ShaderBufferSource SBS_JointInfo=
{
"JointInfo",
"joint",
DescriptorSetType::PerFrame,
R"(
mat4 mats[];
)"
"joint",
"JointInfo",
R"(
mat4 mats[];
)"
};
STD_MTL_NAMESPACE_END

View File

@ -6,7 +6,7 @@
#include<hgl/shadergen/ShaderCreateInfoFragment.h>
#include<hgl/shadergen/ShaderCreateInfoMap.h>
#include<hgl/graph/RenderTargetOutputConfig.h>
#include<hgl/graph/mtl/MaterialConfig.h>
#include<hgl/graph/mtl/MaterialCreateConfig.h>
#include<hgl/graph/mtl/ShaderBufferSource.h>
#include<hgl/graph/VKSamplerType.h>
@ -45,6 +45,8 @@ namespace hgl::graph
public:
const PrimitiveType GetPrimitiveType()const{return config->prim;}
const uint32 GetShaderStage ()const{return config->shader_stage_flag_bit;}
bool hasShader (const VkShaderStageFlagBits ss)const{return config->shader_stage_flag_bit&ss;}
@ -81,11 +83,11 @@ namespace hgl::graph
bool SetLocalToWorld(const uint32_t shader_stage_flag_bits);
bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes);
bool AddStruct(const ShaderBufferSource &ss){return AddStruct(ss.struct_name,ss.codes);}
bool AddUBO(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const AnsiString &struct_name,const AnsiString &name);
bool AddUBO(const uint32_t flag_bits,const DescriptorSetType &set_type,const AnsiString &struct_name,const AnsiString &name);
bool AddUBO(const uint32_t flag_bits,const DescriptorSetType &set_type,const ShaderBufferSource &ss){return AddUBO(flag_bits,set_type,ss.struct_name,ss.name);}
bool AddUBOStruct(const uint32_t flag_bits,const ShaderBufferSource &ss);
bool AddSampler(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const SamplerType &st,const AnsiString &name);

View File

@ -2,6 +2,7 @@
SET REPO="hyzgame"
SET BRANCH=master
git pull
call pull.bat CMAssetsManage %REPO% %BRANCH%
call pull.bat CMCMakeModule %REPO% %BRANCH%
call pull.bat CMCore %REPO% %BRANCH%

View File

@ -67,19 +67,20 @@ SET(GRAPH_MODULE_FILES ${SGM_HEADER_PATH}/GraphModule.h
source_group("Framework\\Module" FILES ${GRAPH_MODULE_FILES})
SET(GRAPH_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h
RenderFramework.cpp)
RenderFramework.cpp
CameraControl.cpp)
source_group("Framework" FILES ${GRAPH_FRAMEWORK_FILES})
SET(SG_SCENE_SOURCE ${SG_INCLUDE_PATH}/SceneWorld.h
SET(SG_SCENE_SOURCE ${SG_INCLUDE_PATH}/Scene.h
${SG_INCLUDE_PATH}/SceneNodeAttributes.h
${SG_INCLUDE_PATH}/SceneNode.h
${SG_INCLUDE_PATH}/SceneNode.h
${SG_INCLUDE_PATH}/SceneMatrix.h
${SG_INCLUDE_PATH}/SceneOrient.h
Scene/SceneNode.cpp
Scene/SceneOrient.cpp
Scene/SceneMatrix.cpp
Scene/SceneWorld.cpp
Scene/Scene.cpp
)
SET(SG_RENDER_SOURCE ${SG_INCLUDE_PATH}/RenderNode.h
@ -87,6 +88,11 @@ SET(SG_RENDER_SOURCE ${SG_INCLUDE_PATH}/RenderNode.h
${SG_INCLUDE_PATH}/MaterialRenderList.h
${SG_INCLUDE_PATH}/MaterialRenderMap.h
# ${SG_INCLUDE_PATH}/ShadowPolicy.h
${SG_INCLUDE_PATH}/RenderTask.h
${SG_INCLUDE_PATH}/Renderer.h
render/Renderer.cpp
render/RenderNode.cpp
render/RenderTask.cpp
render/RenderList.cpp
render/MaterialRenderList.cpp
render/RenderAssignBuffer.h
@ -292,11 +298,14 @@ SOURCE_GROUP("Vulkan\\Mesh" FILES ${VK_MESH_SOURCE})
set(COMPONENT_INCLUDE_PATH ${ROOT_INCLUDE_PATH}/hgl/component)
SET(COMPONENT_FILES ${COMPONENT_INCLUDE_PATH}/Component.h
${COMPONENT_INCLUDE_PATH}/RenderComponent.h
${COMPONENT_INCLUDE_PATH}/SceneComponent.h
${COMPONENT_INCLUDE_PATH}/PrimitiveComponent.h
${COMPONENT_INCLUDE_PATH}/StaticMeshComponent.h
${COMPONENT_INCLUDE_PATH}/RenderComponent.h
${COMPONENT_INCLUDE_PATH}/MeshComponent.h
component/Component.cpp
component/ComponentManager.cpp
component/StaticMeshComponentManager.cpp
component/SceneComponent.cpp
component/MeshComponentManager.cpp
)
SOURCE_GROUP("Component" FILES ${COMPONENT_FILES})

View File

@ -0,0 +1,24 @@
#include<hgl/graph/CameraControl.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/graph/VKDescriptorBindingManage.h>
#include<hgl/graph/mtl/UBOCommon.h>
namespace hgl::graph
{
CameraControl::CameraControl(ViewportInfo *v,Camera *c,UBOCameraInfo *ci)
{
vi=v;
camera=c;
ubo_camera_info=ci;
camera_info=ubo_camera_info->data();
desc_binding_camera=new DescriptorBinding(DescriptorSetType::Camera);
desc_binding_camera->AddUBO(ubo_camera_info);
}
CameraControl::~CameraControl()
{
delete desc_binding_camera;
delete ubo_camera_info;
}
}//namespace hgl::graph

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,15 @@
#include<hgl/graph/module/TextureManager.h>
#include<hgl/graph/module/RenderTargetManager.h>
#include<hgl/graph/module/SwapchainModule.h>
#include<hgl/graph/VKRenderTargetSwapchain.h>
#include<hgl/graph/module/RenderModule.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/Scene.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/FirstPersonCameraControl.h>
#include<hgl/graph/Renderer.h>
#include<hgl/graph/mtl/UBOCommon.h>
#include<hgl/log/Logger.h>
#include<hgl/Time.h>
@ -16,6 +22,9 @@ VK_NAMESPACE_BEGIN
bool InitShaderCompiler();
void CloseShaderCompiler();
void InitializeComponentManager();
void UninitializeComponentManager();
namespace mtl
{
void ClearMaterialFactory();
@ -47,6 +56,10 @@ RenderFramework::RenderFramework(const OSString &an)
RenderFramework::~RenderFramework()
{
SAFE_CLEAR(default_renderer)
SAFE_CLEAR(default_camera_control)
SAFE_CLEAR(default_camera)
SAFE_CLEAR(default_scene)
SAFE_CLEAR(render_resource)
SAFE_CLEAR(module_manager)
@ -54,6 +67,7 @@ RenderFramework::~RenderFramework()
if(RENDER_FRAMEWORK_COUNT==0)
{
UninitializeComponentManager();
STD_MTL_NAMESPACE::ClearMaterialFactory();
CloseShaderCompiler();
}
@ -69,6 +83,8 @@ bool RenderFramework::Init(uint w,uint h)
logger::InitLogger(app_name);
InitNativeWindowSystem();
InitializeComponentManager();
}
++RENDER_FRAMEWORK_COUNT;
@ -117,14 +133,51 @@ bool RenderFramework::Init(uint w,uint h)
render_resource=new RenderResource(device);
default_scene=new Scene;
default_camera=new Camera();
CreateDefaultRenderer();
return(true);
}
void RenderFramework::CreateDefaultRenderer()
{
SAFE_CLEAR(default_renderer)
IRenderTarget *rt=GetSwapchainRenderTarget();
default_renderer=new Renderer(rt);
default_renderer->SetScene(default_scene);
if(!default_camera_control)
{
auto ubo_camera_info=device->CreateUBO<UBOCameraInfo>(&mtl::SBS_CameraInfo);
auto fpcc=new FirstPersonCameraControl(rt->GetViewportInfo(),default_camera,ubo_camera_info);
auto ckc=new CameraKeyboardControl(fpcc);
auto cmc=new CameraMouseControl(fpcc);
this->Join(ckc);
this->Join(cmc);
default_camera_control=fpcc;
mouse_event=cmc;
}
default_renderer->SetCameraControl(default_camera_control);
}
void RenderFramework::OnResize(uint w,uint h)
{
VkExtent2D ext(w,h);
sc_module->OnResize(ext); //其实swapchain_module并不需要传递尺寸数据过去
CreateDefaultRenderer();
}
void RenderFramework::OnActive(bool)
@ -135,4 +188,51 @@ void RenderFramework::OnClose()
{
}
void RenderFramework::Tick()
{
if(default_camera_control)
{
default_camera_control->Refresh();
}
}
graph::Primitive *RenderFramework::CreatePrimitive( const AnsiString &name,
const uint32_t vertices_count,
const graph::VIL *vil,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
{
auto *pc=new graph::PrimitiveCreater(GetDevice(),vil);
pc->Init(name,vertices_count);
for(const auto &vad:vad_list)
{
if(!pc->WriteVAB(vad.name,vad.format,vad.data))
{
delete pc;
return(nullptr);
}
}
auto *prim=pc->Create();
if(prim)
render_resource->Add(prim);
return prim;
}
graph::Mesh *RenderFramework::CreateMesh( const AnsiString &name,
const uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
{
auto *prim=this->CreatePrimitive(name,vertices_count,mi->GetVIL(),vad_list);
if(!prim)
return(nullptr);
return render_resource->CreateMesh(prim,mi,pipeline);
}
VK_NAMESPACE_END

View File

@ -25,6 +25,18 @@ RenderCmdBuffer::~RenderCmdBuffer()
hgl_free(clear_values);
}
bool RenderCmdBuffer::SetDescriptorBinding(DescriptorBinding *db)
{
if(!db)
return(false);
const int index=int(db->GetType())-int(DescriptorSetType::BEGIN_RANGE);
desc_binding[index]=db;
return(true);
}
void RenderCmdBuffer::SetClear()
{
if(cv_count>0)
@ -91,8 +103,11 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
{
if(!mtl)return(false);
if(desc_binding)
desc_binding->Bind(mtl);
ENUM_CLASS_FOR(DescriptorSetType,int,i)
{
if(desc_binding[i])
desc_binding[i]->Bind(mtl);
}
{
uint32_t count=0;

View File

@ -9,9 +9,10 @@ VK_NAMESPACE_BEGIN
void ReleaseVertexInput(VertexInput *vi);
Material::Material(const AnsiString &n)
Material::Material(const AnsiString &n,const PrimitiveType &pt)
{
name=n;
prim=pt;
vertex_input=nullptr;
shader_maps=new ShaderModuleMap;
@ -22,6 +23,7 @@ Material::Material(const AnsiString &n)
mi_data_bytes=0;
mi_data_manager=nullptr;
mi_max_count=0;
}
Material::~Material()

View File

@ -36,9 +36,9 @@ void *Material::GetMIData(int id)
return mi_data_manager->GetData(id);
}
void MaterialInstance::WriteMIData(const void *data,const int size)
void MaterialInstance::WriteMIData(const void *data,const uint32 size)
{
if(!data||size<=0||size>material->GetMIDataBytes())return;
if(!data||!size||size>material->GetMIDataBytes())return;
void *tp=GetMIData();

View File

@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/type/Map.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
struct PipelineLayoutData
{
@ -21,4 +21,4 @@ public:
~PipelineLayoutData();
};//class PipelineLayoutData
VK_NAMESPACE_END
VK_NAMESPACE_END

View File

@ -12,6 +12,7 @@ PrimitiveData::PrimitiveData(const VIL *_vil,const uint32_t vc)
vil=_vil;
vertex_count=vc;
index_count=0;
vab_list=hgl_zero_new<VAB *>(_vil->GetVertexAttribCount());
vab_map_list=new VABMap[_vil->GetVertexAttribCount()];
@ -60,7 +61,7 @@ VAB *PrimitiveData::InitVAB(const int vab_index,const void *data)
vab_list[vab_index]=CreateVAB(vab_index,vif->format,data);
if(!vab_list[vab_index])
return(nullptr);
return(nullptr);
}
else
{
@ -73,7 +74,7 @@ VAB *PrimitiveData::InitVAB(const int vab_index,const void *data)
VABMap *PrimitiveData::GetVABMap(const int vab_index)
{
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())return nullptr;
VABMap *vab_map=vab_map_list+vab_index;
if(!vab_map->IsValid())
@ -81,13 +82,13 @@ VABMap *PrimitiveData::GetVABMap(const int vab_index)
if(!vab_list[vab_index])
return(nullptr);
vab_map->SetVAB(vab_list[vab_index],GetVertexOffset(),vertex_count);
vab_map->BindVAB(vab_list[vab_index],GetVertexOffset(),vertex_count);
}
return vab_map;
}
IndexBuffer *PrimitiveData::InitIBO(const uint32_t ic,IndexType it)
IndexBuffer *PrimitiveData::InitIBO(const int ic,IndexType it)
{
if(ibo)delete ibo;
@ -105,7 +106,7 @@ IndexBuffer *PrimitiveData::InitIBO(const uint32_t ic,IndexType it)
void PrimitiveData::UnmapAll()
{
for(int i=0;i<vil->GetVertexAttribCount();i++)
for(uint32_t i=0;i<vil->GetVertexAttribCount();i++)
vab_map_list[i].Unmap();
ibo_map.Unmap();
@ -151,12 +152,12 @@ namespace
}
IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it) override
{
{
if(!device)return(nullptr);
return device->CreateIBO(it,ic);
}
VAB *CreateVAB(const int vab_index,const VkFormat format,const void *data) override
{
if(!device)return(nullptr);
@ -177,9 +178,9 @@ namespace
public:
int32_t GetVertexOffset()const override { return vab_node->GetStart(); }
uint32_t GetFirstIndex ()const override { return ib_node->GetStart(); }
VertexDataManager * GetVDM()const override{return vdm;} ///<取得顶点数据管理器
int32_t GetVertexOffset ()const override{return vab_node->GetStart();}
uint32_t GetFirstIndex ()const override{return ib_node->GetStart();}
VertexDataManager * GetVDM ()const override{return vdm;} ///<取得顶点数据管理器
public:
@ -199,7 +200,7 @@ namespace
if(vab_node)
vdm->ReleaseVAB(vab_node);
}
IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it) override
{
if(!vdm)

View File

@ -54,7 +54,7 @@ public:
VAB * InitVAB (const int vab_index,const void *data);
VABMap * GetVABMap (const int vab_index);
IndexBuffer * InitIBO(const uint32_t index_count,IndexType it);
IndexBuffer * InitIBO (const int index_count,IndexType it);
IndexBuffer * GetIBO (){return ibo;}
IBMap * GetIBMap (){return &ibo_map;}
uint32_t GetIndexCount ()const{return index_count;}

View File

@ -56,11 +56,11 @@ Pipeline *RenderPass::CreatePipeline(const AnsiString &name,PipelineData *pd,con
return(new Pipeline(name,device,graphicsPipeline,vil,pd));
}
Pipeline *RenderPass::CreatePipeline(Material *mtl,const VIL *vil,const PipelineData *cpd,const PrimitiveType &prim,const bool prim_restart)
Pipeline *RenderPass::CreatePipeline(Material *mtl,const VIL *vil,const PipelineData *cpd,const bool prim_restart)
{
PipelineData *pd=new PipelineData(cpd);
pd->SetPrim(prim,prim_restart);
pd->SetPrim(mtl->GetPrimitiveType(),prim_restart);
Pipeline *p=CreatePipeline(mtl->GetName(),pd,mtl->GetStageList(),mtl->GetPipelineLayout(),vil);
@ -70,41 +70,41 @@ Pipeline *RenderPass::CreatePipeline(Material *mtl,const VIL *vil,const Pipeline
return(p);
}
Pipeline *RenderPass::CreatePipeline(Material *mtl,const VIL *vil,const InlinePipeline &ip,const PrimitiveType &prim,const bool prim_restart)
Pipeline *RenderPass::CreatePipeline(Material *mtl,const VIL *vil,const InlinePipeline &ip,const bool prim_restart)
{
if(!mtl)return(nullptr);
return CreatePipeline(mtl,vil,GetPipelineData(ip),prim,prim_restart);
return CreatePipeline(mtl,vil,GetPipelineData(ip),prim_restart);
}
Pipeline *RenderPass::CreatePipeline(Material *mtl,const PipelineData *pd, const PrimitiveType &prim,const bool prim_restart)
Pipeline *RenderPass::CreatePipeline(Material *mtl,const PipelineData *pd,const bool prim_restart)
{
return CreatePipeline(mtl,mtl->GetDefaultVIL(),pd,prim,prim_restart);
return CreatePipeline(mtl,mtl->GetDefaultVIL(),pd,prim_restart);
}
Pipeline *RenderPass::CreatePipeline(Material *mtl,const InlinePipeline &ip, const PrimitiveType &prim,const bool prim_restart)
Pipeline *RenderPass::CreatePipeline(Material *mtl,const InlinePipeline &ip,const bool prim_restart)
{
return CreatePipeline(mtl,mtl->GetDefaultVIL(),ip,prim,prim_restart);
return CreatePipeline(mtl,mtl->GetDefaultVIL(),ip,prim_restart);
}
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const PrimitiveType &prim,const bool prim_restart)
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const bool prim_restart)
{
if(!mi)return(nullptr);
return CreatePipeline(mi->GetMaterial(),mi->GetVIL(),ip,prim,prim_restart);
return CreatePipeline(mi->GetMaterial(),mi->GetVIL(),ip,prim_restart);
}
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const PipelineData *cpd,const PrimitiveType &prim,const bool prim_restart)
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const PipelineData *cpd,const bool prim_restart)
{
return CreatePipeline(mi->GetMaterial(),mi->GetVIL(),cpd,prim,prim_restart);
return CreatePipeline(mi->GetMaterial(),mi->GetVIL(),cpd,prim_restart);
}
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const OSString &pipeline_filename,const PrimitiveType &prim,const bool prim_restart)
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const OSString &pipeline_filename,const bool prim_restart)
{
const PipelineData *pd=GetPipelineData(pipeline_filename);
if(!pd)return(nullptr);
return CreatePipeline(mi,pd,prim,prim_restart);
return CreatePipeline(mi,pd,prim_restart);
}
VK_NAMESPACE_END

View File

@ -11,6 +11,9 @@
#include<hgl/shadergen/ShaderDescriptorInfo.h>
#include<hgl/type/ActiveMemoryBlockManager.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#ifdef _DEBUG
#include"VKPipelineLayoutData.h"
#endif//_DEBUG
@ -95,7 +98,7 @@ Material *RenderResource::CreateMaterial(const AnsiString &mtl_name,const mtl::M
if(!mci->GetFS())
return(nullptr);
AutoDelete<Material> mtl=new Material(mtl_name);
AutoDelete<Material> mtl=new Material(mtl_name,mci->GetPrimitiveType());
{
const ShaderModule *sm;
@ -172,9 +175,6 @@ Material *RenderResource::CreateMaterial(const AnsiString &mtl_name,const mtl::M
Add(mtl);
static_descriptor.Bind(mtl);
global_descriptor.Bind(mtl);
material_by_name.Add(mtl_name,mtl);
return mtl.Finish();
}
@ -190,7 +190,10 @@ Material *RenderResource::LoadMaterial(const AnsiString &mtl_name,mtl::Material2
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::LoadMaterialFromFile(device->GetDevAttr(),mtl_name,cfg);
//这里直接用这个mtl_name有些不太对因为同一个材质也有可能因为不同的cfg会有不同的版本所以这里不能直接使用mtl_name.目前只是做一个暂时方案
return this->CreateMaterial(mtl_name,mci);
AnsiString hash_name=mtl_name+"?"+cfg->ToHashString();
return this->CreateMaterial(hash_name,mci);
}
Material *RenderResource::LoadMaterial(const AnsiString &mtl_name,mtl::Material3DCreateConfig *cfg)
@ -198,6 +201,9 @@ Material *RenderResource::LoadMaterial(const AnsiString &mtl_name,mtl::Material3
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::LoadMaterialFromFile(device->GetDevAttr(),mtl_name,cfg);
//这里直接用这个mtl_name有些不太对因为同一个材质也有可能因为不同的cfg会有不同的版本所以这里不能直接使用mtl_name.目前只是做一个暂时方案
return this->CreateMaterial(mtl_name,mci);
AnsiString hash_name=mtl_name+"?"+cfg->ToHashString();
return this->CreateMaterial(hash_name,mci);
}
VK_NAMESPACE_END

View File

@ -13,9 +13,9 @@ IRenderTarget::IRenderTarget(RenderFramework *rf,const VkExtent2D &ext):desc_bin
{
render_framework=rf;
ubo_vp_info=GetDevice()->CreateUBO<UBOViewportInfo>();
ubo_vp_info=GetDevice()->CreateUBO<UBOViewportInfo>(&mtl::SBS_ViewportInfo);
desc_binding.AddUBO(mtl::SBS_ViewportInfo.name,*ubo_vp_info);
desc_binding.AddUBO(ubo_vp_info);
OnResize(ext);
}

View File

@ -0,0 +1,40 @@
#include<hgl/component/Component.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/log/LogInfo.h>
namespace hgl::graph
{
uint Component::unique_id_count=0;
Component::Component(ComponentDataPtr cdp,ComponentManager *cm)
{
unique_id=++unique_id_count;
OwnerNode=nullptr;
Data=cdp;
Manager=cm;
Manager->AttachComponent(this);
LOG_INFO(AnsiString("Component::Component ")+AnsiString::numberOf(unique_id)+AnsiString(" ")+ToHexString<char>(this));
}
Component::~Component()
{
LOG_INFO(AnsiString("Component::~Component ")+AnsiString::numberOf(unique_id)+AnsiString(" ")+ToHexString<char>(this));
if(OwnerNode)
{
OwnerNode->DetachComponent(this);
OwnerNode=nullptr;
}
if(Manager)
Manager->DetachComponent(this);
}
Component *Component::Duplication()
{
return GetManager()->CreateComponent(Data);
}
}//namespace hgl::graph

View File

@ -1,48 +1,93 @@
#include<hgl/component/Component.h>
#include<tsl/robin_map.h>
#include<hgl/type/String.h>
#include<hgl/log/LogInfo.h>
namespace hgl::graph
{
namespace
{
tsl::robin_map<size_t,ComponentManager *> component_manager_map;
using ComponentManagerMap=tsl::robin_map<size_t,ComponentManager *>;
ComponentManagerMap *component_manager_map=nullptr;
}//namespace
void InitializeComponentManager()
{
if(component_manager_map)
return;
component_manager_map=new ComponentManagerMap;
}
void UninitializeComponentManager()
{
if(!component_manager_map)
return;
for(auto &cm : *component_manager_map)
delete cm.second;
delete component_manager_map;
component_manager_map=nullptr;
}
bool RegistryComponentManager(ComponentManager *cm)
{
if(!cm)return(false);
const size_t hash_code=cm->GetHashCode();
if(component_manager_map.contains(hash_code))
if(!component_manager_map)
return(false);
component_manager_map.emplace(hash_code,cm);
const size_t hash_code=cm->GetHashCode();
if(component_manager_map->contains(hash_code))
return(false);
component_manager_map->emplace(hash_code,cm);
return(true);
}
ComponentManager *GetComponentManager(const size_t hash_code)
{
if(!component_manager_map.contains(hash_code))
if(!component_manager_map)
return(nullptr);
//[]对于不存的会自行插入一个,所以不要把下面的.at改成[]
return component_manager_map.at(hash_code);
if(!component_manager_map->contains(hash_code))
return(nullptr);
//tsl::robin_map的[]对于不存在的会自行插入一个,所以不要把下面的.at改成[]
return component_manager_map->at(hash_code);
}
int ComponentManager::GetComponents(ArrayList<Component *> &comp_list,SceneNode *node)
ComponentManager::~ComponentManager()
{
for(auto *c:component_set)
{
c->OnDetach(nullptr);
//Component::~Component()函数会再次调用ComponentManager->DetachComponent其中会执行component_set的删除整个流程就会出现问题。
//所以这里先OnDetachManager掉Component中的Manager属性然后再执行删除
c->OnDetachManager(this);
LOG_INFO(AnsiString("~ComponentManager delete ")+AnsiString::numberOf(c->GetUniqueID()));
delete c;
}
}
int ComponentManager::GetComponents(ComponentList &comp_list,SceneNode *node)
{
if(!node)return(-1);
Component **cc=component_set.GetData();
if(comp_list.IsEmpty())return(-2);
if(!component_manager_map)return(-3);
int result=0;
for(int i=0;i<component_set.GetCount();i++)
if(cc[i]->GetOwnerNode()==node)
for(auto cc:component_set)
if(cc->GetOwnerNode()==node)
{
comp_list.Add(cc[i]);
comp_list.Add(cc);
++result;
}

View File

@ -0,0 +1,40 @@
#include<hgl/component/MeshComponent.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/Mesh.h>
COMPONENT_NAMESPACE_BEGIN
//uint MeshComponentData::unique_id_count=0;
MeshComponentData::~MeshComponentData()
{
// LOG_INFO(AnsiString("~MeshComponentData():")+AnsiString::numberOf(unique_id));
if(mesh)
{
//mesh->Release(); //外面有RenderResource管理不需要在这里释放.但未来要考虑是增加Release函数通知这里释放了一次使用权
mesh=nullptr;
}
}
Component *MeshComponentManager::CreateComponent(ComponentDataPtr cdp)
{
if(!cdp)return(nullptr);
if(!dynamic_cast<MeshComponentData *>(cdp.get()))
{
//LOG_ERROR(OS_TEXT("MeshComponentManager::CreateMeshComponent: invalid component data type."));
return(nullptr);
}
return(new MeshComponent(cdp,this));
}
MeshComponent *MeshComponentManager::CreateComponent(Mesh *m)
{
ComponentDataPtr cdp=new MeshComponentData(m);
return dynamic_cast<MeshComponent *>(CreateComponent(cdp));
}
COMPONENT_NAMESPACE_END

View File

@ -0,0 +1,5 @@
#include<hgl/component/SceneComponent.h>
COMPONENT_NAMESPACE_BEGIN
COMPONENT_NAMESPACE_END

View File

@ -1,22 +0,0 @@
#include<hgl/component/StaticMeshComponent.h>
#include<hgl/graph/SceneNode.h>
COMPONENT_NAMESPACE_BEGIN
StaticMeshComponent *StaticMeshComponentManager::CreateStaticMeshComponent(SceneNode *psn,StaticMeshComponentData *data)
{
if(!psn||!data)return(nullptr);
StaticMeshComponent *smc=new StaticMeshComponent(psn,data,this);
psn->AddComponent(smc);
return smc;
}
Component *StaticMeshComponentManager::CreateComponent(SceneNode *psn,ComponentData *data)
{
return CreateStaticMeshComponent(psn,reinterpret_cast<StaticMeshComponentData *>(data));
}
COMPONENT_NAMESPACE_END

View File

@ -6,72 +6,11 @@
#include<hgl/graph/VKRenderAssign.h>
#include<hgl/util/sort/Sort.h>
#include"RenderAssignBuffer.h"
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/CameraInfo.h>
/**
*
*
*
* for(material)
* for(pipeline)
* for(material_instance)
* for(vab)
*
*
* Indirect Command Buffer
IndirectCommandBuffer使Indirect渲染的
VBOINDIRECT缓冲区便
*/
#include<hgl/component/MeshComponent.h>
VK_NAMESPACE_BEGIN
const int RenderNode::compare(const RenderNode &other)const
{
hgl::int64 off;
hgl::graph::Mesh *ri_one=other.scene_node->GetRenderable();
hgl::graph::Mesh *ri_two=scene_node->GetRenderable();
auto *prim_one=ri_one->GetPrimitive();
auto *prim_two=ri_two->GetPrimitive();
//比较VDM
if(prim_one->GetVDM()) //有VDM
{
off=prim_one->GetVDM()
-prim_two->GetVDM();
if(off)
return off;
//比较模型
{
off=prim_one
-prim_two;
if(off)
{
off=prim_one->GetVertexOffset()-prim_two->GetVertexOffset(); //保证vertex offset小的在前面
return off;
}
}
}
//比较距离。。。。。。。。。。。。。。。。。。。。。还不知道这个是正了还是反了,等测出来确认后修改下面的返回值和这里的注释
float foff=other.to_camera_distance
-to_camera_distance;
if(foff>0)
return 1;
else
return -1;
}
MaterialRenderList::MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi)
{
device=d;
@ -106,18 +45,21 @@ MaterialRenderList::~MaterialRenderList()
SAFE_CLEAR(assign_buffer);
}
void MaterialRenderList::Add(SceneNode *sn)
void MaterialRenderList::Add(MeshComponent *smc)
{
if(!smc)
return;
RenderNode rn;
rn.index =rn_list.GetCount();
rn.scene_node =sn;
rn.sm_component =smc;
rn.l2w_version =sn->GetLocalToWorldMatrixVersion();
rn.l2w_version =smc->GetLocalToWorldMatrixVersion();
rn.l2w_index =0;
rn.world_position =sn->GetWorldPosition();
rn.world_position =smc->GetWorldPosition();
if(camera_info)
rn.to_camera_distance=length(camera_info->pos,rn.world_position);
@ -160,7 +102,7 @@ void MaterialRenderList::UpdateLocalToWorld()
for(int i=0;i<node_count;i++)
{
l2w_version=rn->scene_node->GetLocalToWorldMatrixVersion();
l2w_version=rn->sm_component->GetLocalToWorldMatrixVersion();
if(rn->l2w_version!=l2w_version) //版本不对,需要更新
{
@ -188,9 +130,9 @@ void MaterialRenderList::UpdateLocalToWorld()
}
}
void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn)
void MaterialRenderList::UpdateMaterialInstance(MeshComponent *smc)
{
if(!sn)return;
if(!smc)return;
if(!assign_buffer)
return;
@ -202,7 +144,7 @@ void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn)
for(int i=0;i<node_count;i++)
{
if(rn->scene_node==sn)
if(rn->sm_component==smc)
{
assign_buffer->UpdateMaterialInstance(rn);
return;
@ -270,7 +212,7 @@ void MaterialRenderList::Stat()
ri_array.Alloc(count);
RenderItem *ri=ri_array.GetData();
Mesh *ro=rn->scene_node->GetRenderable();
Mesh *ro=rn->sm_component->GetMesh();
ri_count=1;
@ -286,7 +228,7 @@ void MaterialRenderList::Stat()
for(uint i=1;i<count;i++)
{
ro=rn->scene_node->GetRenderable();
ro=rn->sm_component->GetMesh();
if(*last_data_buffer==*ro->GetDataBuffer())
if(*last_render_data==*ro->GetRenderData())
@ -346,13 +288,21 @@ bool MaterialRenderList::BindVAB(const MeshDataBuffer *pdb,const uint ri_index)
//Basic组它所有的VAB信息均来自于Primitive由vid参数传递进来
{
vab_list->Add(pdb->vab_list,
pdb->vab_offset,
pdb->vab_count);
if(!vab_list->Add(pdb->vab_list,pdb->vab_offset,pdb->vab_count))
{
//这个情况很严重哦!
return(false);
}
}
if(assign_buffer) //L2W/MI分发组
vab_list->Add(assign_buffer->GetVAB(),0);//ASSIGN_VAB_STRIDE_BYTES*ri_index);
if (assign_buffer) //L2W/MI分发组
{
if(!vab_list->Add(assign_buffer->GetVAB(),0))//ASSIGN_VAB_STRIDE_BYTES*ri_index);
{
//一般出现这个情况是因为材质中没有配置需要L2W
return(false);
}
}
//if(!vab_list.IsFull()) //Joint组暂未支持
//{
@ -405,7 +355,7 @@ void MaterialRenderList::ProcIndirectRender()
indirect_draw_count=0;
}
void MaterialRenderList::Render(RenderItem *ri)
bool MaterialRenderList::Render(RenderItem *ri)
{
if(!last_data_buffer||*(ri->pdb)!=*last_data_buffer) //换buf了
{
@ -415,7 +365,11 @@ void MaterialRenderList::Render(RenderItem *ri)
last_data_buffer=ri->pdb;
last_render_data=nullptr;
BindVAB(ri->pdb,ri->first_instance);
if(!BindVAB(ri->pdb,ri->first_instance))
{
//这个问题很严重哦
return(false);
}
if(ri->pdb->ibo)
cmd_buf->BindIBO(ri->pdb->ibo);
@ -432,6 +386,8 @@ void MaterialRenderList::Render(RenderItem *ri)
{
cmd_buf->Draw(ri->pdb,ri->prd,ri->instance_count,ri->first_instance);
}
return(true);
}
void MaterialRenderList::Render(RenderCmdBuffer *rcb)

View File

@ -7,6 +7,7 @@
#include<hgl/graph/Mesh.h>
#include<hgl/graph/VKRenderAssign.h>
#include<hgl/graph/mtl/UBOCommon.h>
#include<hgl/component/MeshComponent.h>
VK_NAMESPACE_BEGIN
RenderAssignBuffer::RenderAssignBuffer(VulkanDevice *dev,Material *mtl)
@ -30,8 +31,8 @@ void RenderAssignBuffer::Bind(Material *mtl)const
{
if(!mtl)return;
mtl->BindUBO(mtl::DST_LocalToWorld, mtl::SBS_LocalToWorld.name, l2w_buffer);
mtl->BindUBO(mtl::DST_MaterialInstance, mtl::SBS_MaterialInstance.name, mi_buffer);
mtl->BindUBO(&mtl::SBS_LocalToWorld, l2w_buffer);
mtl->BindUBO(&mtl::SBS_MaterialInstance, mi_buffer);
}
void RenderAssignBuffer::Clear()
@ -73,7 +74,7 @@ void RenderAssignBuffer::StatL2W(const RenderNodeList &rn_list)
for(int i=0;i<rn_list.GetCount();i++)
{
*l2wp=rn->scene_node->GetLocalToWorldMatrix();
*l2wp=rn->sm_component->GetLocalToWorldMatrix();
++l2wp;
++rn;
}
@ -97,7 +98,7 @@ void RenderAssignBuffer::UpdateLocalToWorld(const RenderNodePointerList &rnp_lis
for(uint i=0;i<count;i++)
{
l2wp[(*rn)->l2w_index-first]=(*rn)->scene_node->GetLocalToWorldMatrix();
l2wp[(*rn)->l2w_index-first]=(*rn)->sm_component->GetLocalToWorldMatrix();
++rn;
}
@ -112,7 +113,7 @@ void RenderAssignBuffer::UpdateMaterialInstance(const RenderNode *rn)
AssignData *adp=(AssignData *)(assign_vab->DeviceBuffer::Map(sizeof(AssignData)*rn->index,sizeof(AssignData)));
adp->mi=mi_set.Find(rn->scene_node->GetRenderable()->GetMaterialInstance());
adp->mi=mi_set.Find(rn->sm_component->GetMesh()->GetMaterialInstance());
assign_vab->Unmap();
}
@ -152,7 +153,7 @@ void RenderAssignBuffer::StatMI(const RenderNodeList &rn_list)
mi_set.PreAlloc(rn_list.GetCount());
for(RenderNode &rn:rn_list)
mi_set.Add(rn.scene_node->GetRenderable()->GetMaterialInstance());
mi_set.Add(rn.sm_component->GetMesh()->GetMaterialInstance());
if(mi_set.GetCount()>material->GetMIMaxCount())
{
@ -220,7 +221,7 @@ void RenderAssignBuffer::WriteNode(const RenderNodeList &rn_list)
rn->l2w_index=i;
adp->l2w=i;
adp->mi=mi_set.Find(rn->scene_node->GetRenderable()->GetMaterialInstance());
adp->mi=mi_set.Find(rn->sm_component->GetMesh()->GetMaterialInstance());
++adp;
++rn;

View File

@ -5,6 +5,7 @@
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/Mesh.h>
#include<hgl/component/MeshComponent.h>
namespace hgl
{
@ -22,11 +23,19 @@ namespace hgl
{
if(!sn)return(false);
Mesh *ri=sn->GetRenderable();
if(ri)
for(auto component:sn->GetComponents())
{
RenderPipelineIndex rpi(ri->GetMaterial(),ri->GetPipeline());
if(component->GetHashCode()!=MeshComponent::StaticHashCode()) //暂时只支持MeshComponent
continue;
MeshComponent *smc=dynamic_cast<MeshComponent *>(component);
if(!smc)
continue;
Mesh *mesh=smc->GetMesh();
RenderPipelineIndex rpi(mesh->GetMaterial(),mesh->GetPipeline());
MaterialRenderList *mrl;
@ -36,8 +45,8 @@ namespace hgl
mrl_map.Add(rpi,mrl);
}
mrl->Add(sn);
mrl->Add(smc);
++renderable_count;
}
@ -85,11 +94,11 @@ namespace hgl
mrl_map.UpdateLocalToWorld();
}
void RenderList::UpdateMaterialInstance(SceneNode *sn)
void RenderList::UpdateMaterialInstance(MeshComponent *smc)
{
if(!sn)return;
if(!smc)return;
Mesh *ri=sn->GetRenderable();
Mesh *ri=smc->GetMesh();
if(!ri)return;
@ -99,7 +108,7 @@ namespace hgl
if(!mrl_map.Get(rli,mrl)) //找到对应的
return;
mrl->UpdateMaterialInstance(sn);
mrl->UpdateMaterialInstance(smc);
}
}//namespace graph
}//namespace hgl

View File

@ -0,0 +1,79 @@
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/VertexDataManager.h>
#include<hgl/component/MeshComponent.h>
VK_NAMESPACE_BEGIN
/**
*
*
*
* for(material)
* for(pipeline)
* for(material_instance)
* for(vab)
*
*
* Indirect Command Buffer
IndirectCommandBuffer使Indirect渲染的
VBOINDIRECT缓冲区便
*/
const int RenderNode::compare(const RenderNode &other)const
{
hgl::int64 off;
hgl::graph::Mesh *ri_one=other.sm_component->GetMesh();
hgl::graph::Mesh *ri_two=sm_component->GetMesh();
auto *prim_one=ri_one->GetPrimitive();
auto *prim_two=ri_two->GetPrimitive();
//比较VDM
if(prim_one->GetVDM()) //有VDM
{
off=prim_one->GetVDM()
-prim_two->GetVDM();
if(off)
return off;
//比较模型
{
off=prim_one
-prim_two;
if(off)
{
off=prim_one->GetVertexOffset()-prim_two->GetVertexOffset(); //保证vertex offset小的在前面
return off;
}
}
}
//比较距离。。。。。。。。。。。。。。。。。。。。。还不知道这个是正了还是反了,等测出来确认后修改下面的返回值和这里的注释
float foff=other.to_camera_distance
-to_camera_distance;
if(foff>0)
return 1;
else
return -1;
}
Mesh *RenderNode::GetMesh()const
{
return sm_component?sm_component->GetMesh():nullptr;
}
MaterialInstance *RenderNode::GetMaterialInstance()const
{
if(!sm_component)return(nullptr);
if(!sm_component->GetMesh())return(nullptr);
return sm_component->GetMesh()->GetMaterialInstance();
}
VK_NAMESPACE_END

View File

@ -0,0 +1,100 @@
#include<hgl/graph/RenderTask.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKRenderTarget.h>
namespace hgl::graph
{
RenderTask::RenderTask(const RenderTaskName &tn,IRenderTarget *rt,CameraInfo *ci)
{
task_name=tn;
camera_info=ci;
render_target=nullptr;
render_list=nullptr;
SetRenderTarget(rt);
}
RenderTask::~RenderTask()
{
SAFE_CLEAR(render_list)
}
bool RenderTask::SetRenderTarget(IRenderTarget *rt)
{
if(render_target)
{
if(render_target->GetDevice()!=rt->GetDevice())
{
//换Device是不允许的当然这一般也不可能
return(false);
}
}
render_target=rt;
if(!render_list)
{
render_list=new RenderList(rt->GetDevice());
if(camera_info)
render_list->SetCameraInfo(camera_info);
}
return(true);
}
void RenderTask::SetCameraInfo(CameraInfo *ci)
{
if(camera_info==ci)return;
camera_info=ci;
render_list->SetCameraInfo(ci);
}
bool RenderTask::RebuildRenderList(SceneNode *root)
{
if(!root)
return(false);
if(!render_list)
return(false);
if(!render_list->GetCameraInfo()&&camera_info)
render_list->SetCameraInfo(camera_info);
//记往不需要也千万不要手动render_list->Clear因为那会释放内存。再次使用时重新分配
//render_list->Expend会自己复位所有数据且并不会释放内存
render_list->Expend(root);
return(true);
}
bool RenderTask::IsEmpty()const
{
if(!render_list)
return(true);
return render_list->IsEmpty();
}
bool RenderTask::Render(RenderCmdBuffer *cmd)
{
if(!cmd)
return(false);
if(!render_target)
return(false);
if(!render_list)
return(false);
if(render_list->IsEmpty())
return(false);
render_list->Render(cmd);
return(true);
}
}//namespace hgl::graph

View File

@ -0,0 +1,144 @@
#include<hgl/graph/Renderer.h>
#include<hgl/graph/Scene.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/Camera.h>
namespace hgl::graph
{
Renderer::Renderer(IRenderTarget *rt)
{
render_target=rt;
scene=nullptr;
camera_control=nullptr;
render_task=new RenderTask("DefaultRenderTask",rt);
clear_color.Set(0,0,0,1);
}
Renderer::~Renderer()
{
delete render_task;
}
bool Renderer::SetRenderTarget(IRenderTarget *rt)
{
if(render_target==rt)
return(true);
if(render_target)
{
if(render_target->GetDevice()!=rt->GetDevice())
{
//换Device是不允许的当然这一般也不可能
return(false);
}
}
render_target=rt;
render_task->SetRenderTarget(rt);
return(true);
}
void Renderer::SetScene(Scene *sw)
{
if(scene==sw)
return;
//if(scene)
//{
// scene->Unjoin(this);
//}
scene=sw;
//if(scene)
//{
// scene->Join(this);
//}
}
void Renderer::SetCameraControl(CameraControl *cc)
{
if(!scene||!cc)
return;
//if(camera)
//{
// if(scene)
// camera->Unjoin(scene);
// camera->Unjoin(this);
//}
camera_control=cc;
//if(camera)
//{
// if(scene)
// camera->Unjoin(scene);
// camera->Join(this);
//}
render_task->SetCameraInfo(camera_control->GetCameraInfo());
}
bool Renderer::RenderFrame()
{
if(!scene)
return(false);
SceneNode *root=scene->GetRootNode();
if(!root)
return(false);
root->RefreshMatrix();
if(camera_control)
{
camera_control->SetViewport(render_target->GetViewportInfo());
camera_control->Refresh();
}
// 这里内部会将Scene tree展开成RenderList,而RenderList排序是需要CameraInfo的
render_task->RebuildRenderList(root);
bool result=false;
graph::RenderCmdBuffer *cmd=render_target->BeginRender();
if(camera_control)
{
cmd->SetDescriptorBinding(camera_control->GetDescriptorBinding());
}
cmd->SetClearColor(0,clear_color);
cmd->BeginRenderPass();
result=render_task->Render(cmd);
cmd->EndRenderPass();
render_target->EndRender();
build_frame=result;
return(result);
}
bool Renderer::Submit()
{
if(!render_target)
return(false);
if(!build_frame)
return(false);
return render_target->Submit();
}
}//namespace hgl::graph

View File

@ -0,0 +1,39 @@
#include<hgl/graph/Scene.h>
#include<hgl/type/Map.h>
namespace hgl::graph
{
namespace
{
Map<U8String,Scene *> scene_world_map;///<场景列表
}//namespace
bool RegistryScene(Scene *sw)
{
if(!sw)return(false);
const U8String &scene_name=sw->GetSceneName();
if(scene_world_map.Find(scene_name))
return false;///<已经注册过了
scene_world_map.Add(scene_name,sw);
return true;
}
Scene *GetScene(const U8String &scene_name)
{
if(scene_name.IsEmpty())
return(nullptr);
return GetObjectFromMap(scene_world_map,scene_name);
}
bool UnregistryScene(const U8String &scene_name)
{
if(scene_name.IsEmpty())
return(false);
return scene_world_map.DeleteByKey(scene_name);
}
}//namespace hgl::graph

View File

@ -1,125 +1,140 @@
#include<hgl/graph/SceneNode.h>
#include<hgl/component/SceneComponent.h>
#include<hgl/graph/Mesh.h>
namespace hgl
namespace hgl::graph
{
namespace graph
SceneNode *Duplication(SceneNode *src_node)
{
SceneNode *Duplication(SceneNode *src_node)
if(!src_node)
return nullptr;
SceneNode *node=new SceneNode(*(SceneOrient *)src_node);
for(SceneNode *sn:src_node->GetChildNode())
{
if(!src_node)
return nullptr;
SceneNode *node=new SceneNode(*(SceneOrient *)src_node);
node->SetRenderable(src_node->GetRenderable());
for(SceneNode *sn:src_node->GetChildNode())
{
node->Add(Duplication(sn));
}
return node;
node->Add(Duplication(sn));
}
void SceneNode::SetRenderable(Mesh *ri)
for(Component *c:src_node->GetComponents())
{
render_obj=ri;
if(render_obj)
{
SetBoundingBox(render_obj->GetBoundingBox());
}
else
{
BoundingBox.SetZero();
//WorldBoundingBox=
LocalBoundingBox=BoundingBox;
}
node->AttachComponent(c->Duplication());
}
/**
*
*/
void SceneNode::RefreshMatrix()
{
SceneOrient::RefreshMatrix();
return node;
}
//void SceneNode::SetRenderable(Mesh *ri)
//{
// render_obj=ri;
// if(render_obj)
// {
// SetBoundingBox(render_obj->GetBoundingBox());
// }
// else
// {
// bounding_box.SetZero();
// //WorldBoundingBox=
// local_bounding_box=bounding_box;
// }
//}
/**
*
*/
void SceneNode::RefreshMatrix()
{
SceneOrient::RefreshMatrix();
// if (scene_matrix.IsNewestVersion()) //自己不变,不代表下面不变
//return;
//return;
const Matrix4f &l2w=scene_matrix.GetLocalToWorldMatrix();
const Matrix4f &l2w=scene_matrix.GetLocalToWorldMatrix();
const int count=ChildNode.GetCount();
SceneNode **sub=ChildNode.GetData();
for(int i=0;i<count;i++)
{
(*sub)->SetParentMatrix(l2w);
(*sub)->RefreshMatrix();
sub++;
}
for(SceneNode *sub:child_nodes)
{
sub->SetParentMatrix(l2w);
sub->RefreshMatrix();
}
/**
*
*/
void SceneNode::RefreshBoundingBox()
for(Component *com:component_set)
{
int count=ChildNode.GetCount();
SceneNode **sub=ChildNode.GetData();
SceneComponent *sc=dynamic_cast<SceneComponent *>(com);
AABB local,world;
if(!sc)
continue;
sc->SetParentMatrix(l2w);
sc->RefreshMatrix();
}
}
/**
*
*/
void SceneNode::RefreshBoundingBox()
{
int count=child_nodes.GetCount();
SceneNode **sub=child_nodes.GetData();
AABB local,world;
(*sub)->RefreshBoundingBox();
local=(*sub)->GetLocalBoundingBox();
++sub;
for(int i=1;i<count;i++)
{
(*sub)->RefreshBoundingBox();
local=(*sub)->GetLocalBoundingBox();
local.Enclose((*sub)->GetLocalBoundingBox());
++sub;
for(int i=1;i<count;i++)
{
(*sub)->RefreshBoundingBox();
local.Enclose((*sub)->GetLocalBoundingBox());
++sub;
}
LocalBoundingBox=local;
}
int SceneNode::GetComponents(ArrayList<Component *> &comp_list,const ComponentManager *mgr)
local_bounding_box=local;
}
int SceneNode::GetComponents(ComponentList &comp_list,const ComponentManager *mgr)
{
if(!mgr)return(-1);
if(ComponentIsEmpty())return(0);
int result=0;
for(Component *c:component_set)
{
if(!mgr)return(-1);
if(ComponentIsEmpty())return(0);
int result=0;
for(Component *c:ComponentList)
if(c->GetManager()==mgr)
{
if(c->GetManager()==mgr)
{
comp_list.Add(c);
++result;
}
comp_list.Add(c);
++result;
}
return result;
}
bool SceneNode::HasComponent(const ComponentManager *mgr)
return result;
}
bool SceneNode::HasComponent(const ComponentManager *mgr)
{
if(!mgr)return(false);
if(ComponentIsEmpty())return(false);
for(Component *c:component_set)
{
if(!mgr)return(false);
if(ComponentIsEmpty())return(false);
for(Component *c:ComponentList)
{
if(c->GetManager()==mgr)
return(true);
}
return(false);
if(c->GetManager()==mgr)
return(true);
}
}//namespace graph
}//namespace hgl
return(false);
}
SceneNode::~SceneNode()
{
for(Component *c:component_set)
{
c->OnDetach(this);
}
}
}//namespace hgl::graph

View File

@ -17,9 +17,7 @@ bool Std2DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
if(cfg->local_to_world
||cfg->material_instance)
{
mci->AddStruct(SBS_LocalToWorld);
mci->AddUBO(VK_SHADER_STAGE_ALL_GRAPHICS,DescriptorSetType::PerFrame,SBS_LocalToWorld);
mci->AddUBOStruct(VK_SHADER_STAGE_ALL_GRAPHICS,SBS_LocalToWorld);
vsc->AddAssign();
}
@ -43,11 +41,7 @@ bool Std2DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
if(cfg->coordinate_system==CoordinateSystem2D::Ortho)
{
mci->AddStruct(SBS_ViewportInfo);
mci->AddUBO(VK_SHADER_STAGE_ALL_GRAPHICS,
DescriptorSetType::RenderTarget,
SBS_ViewportInfo);
mci->AddUBOStruct(VK_SHADER_STAGE_ALL_GRAPHICS,SBS_ViewportInfo);
}
return(true);

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