Compare commits
No commits in common. "devel_40_World" and "devel_38_GraphManager" have entirely different histories.
devel_40_W
...
devel_38_G
@ -1 +1 @@
|
||||
Subproject commit 0244bff1b60119806f683b54a137cda2cacc17ac
|
||||
Subproject commit 0fae462338cd01c5a26d0a8f0175fe3729a65c94
|
@ -1 +1 @@
|
||||
Subproject commit 6fbc7078181cefc7e5da590c2d4ccc70507934b7
|
||||
Subproject commit 737fe5c80d013f807cbb8f4d333d5a59c82571bc
|
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit c5b37f98353441520374011020dbe63c17796a4d
|
||||
Subproject commit b78d31d8a01ff4e7e86bf433f9046a3f783d63fa
|
@ -1 +1 @@
|
||||
Subproject commit f0ff214289a1265898feecbdbbd2ddf50bff5dca
|
||||
Subproject commit 67e8e956658cb9abbb94cd01f0a465e8275b44dd
|
@ -1 +1 @@
|
||||
Subproject commit 74e33b497274e51c35a5ee19a274b12dc86deecb
|
||||
Subproject commit f74d7045fa0d143b94103e49093fe18a1d5a884c
|
2
CMUtil
2
CMUtil
@ -1 +1 @@
|
||||
Subproject commit 48383e5f63928bab43320c406219365850507246
|
||||
Subproject commit 57ff3a70c99265ed7bb97b3b6840709e84bac0c1
|
@ -1,28 +0,0 @@
|
||||
# AssetPath
|
||||
|
||||
具体源代码参见CMAssetManage中的AssetPath.h
|
||||
|
||||
# 大致规则
|
||||
|
||||
Asset代表的资产,意味应用程序本身所拥有的资源。而AssetPath意味指向这个资产的一个字符串。
|
||||
|
||||
AssetPath的组成规和Windows/UNIX/Linux的路径原则类似,大致如下:
|
||||
|
||||
```C++
|
||||
LOCATION:/abc/123/test_material.mtl
|
||||
```
|
||||
|
||||
LOCATION 它代表资产所在的大范围位置,是可以不存在的,也就是说如下的写法也是可以的
|
||||
```C++
|
||||
:/abc/123/test_material.mtl
|
||||
```
|
||||
这个LOCATION的定义我们暂时有以下几个:
|
||||
|
||||
| LOCATION | 意义 |
|
||||
|----------|------------------|
|
||||
| 不写 | 应用程序本身的资产包 |
|
||||
| Asset | 应用程序本身的资产包 |
|
||||
| Engine | 代表引擎资产 |
|
||||
| PlugIn | 代表插件资产 |
|
||||
| ExtPack | 应用程序扩展资产包(一般用于额外安装或下载的资产包) |
|
||||
| OS | 操作系统真实路径访问 |
|
@ -1,47 +0,0 @@
|
||||
# CreateMaterialInstance
|
||||
|
||||
## 1st
|
||||
|
||||
最早最根本的方法,直接在C++代码层面通过mtl::CreateVertexColor2D()函数来创建MaterialCreateInfo
|
||||
```C++
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",PrimitiveType::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=CreateMaterialInstance(mci);
|
||||
```
|
||||
|
||||
## 2nd
|
||||
注册材质系统引入后的方法,通过名称"VertexColor2D"来创建MaterialCreateInfo
|
||||
```C++
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",PrimitiveType::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateMaterialCreateInfo("VertexColor2D",&cfg);
|
||||
|
||||
material_instance=CreateMaterialInstance(mci);
|
||||
```
|
||||
|
||||
## 3rd
|
||||
其实是第二种方法在WorkObject层面的封装
|
||||
```C++
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",PrimitiveType::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material_instance=CreateMaterialInstance("VertexColor2D",&cfg);
|
||||
```
|
||||
|
||||
## 4th
|
||||
是更进一步的封装,通过材质配置文件连带Material2DCreateConfig的具体配置都进行了封闭。
|
||||
```C++
|
||||
AssetPath path(":/asset/test_material.mtl");
|
||||
|
||||
material_instance=CreateMaterialInstance(path);
|
||||
```
|
@ -1,20 +0,0 @@
|
||||
# 程序内嵌材质/Shader
|
||||
# Material/Shader embedded in program code
|
||||
|
||||
问题(Question):
|
||||
|
||||
```
|
||||
即然可以从文件中加载材质了,那为什么还需要有程序代码中内嵌的材质/Shader呢?
|
||||
|
||||
I can load a material from a file. Why do we need a few materials/shaders embedded in the code?
|
||||
```
|
||||
|
||||
这个问题很好,答案也很简单:
|
||||
|
||||
Good question, the answer is straightforward:
|
||||
|
||||
```
|
||||
我们需要在资产损坏或丢失的情况下,依然可以渲染一些内容, 比如: 一个报错对话框。
|
||||
|
||||
We need to be able to render some content, such as an error dialog box, even if the asset is damaged or lost.
|
||||
```
|
@ -38,7 +38,7 @@ class TestApp:public VulkanApplicationFramework
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
@ -46,7 +46,7 @@ private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"VertexColor2D",PrimitiveType::Lines);
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Lines);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
@ -60,7 +60,7 @@ private:
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,PrimitiveType::Lines);
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
@ -74,7 +74,7 @@ private:
|
||||
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
Camera cam;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_color_material =nullptr;
|
||||
DeviceBuffer * ubo_line_config =nullptr;
|
||||
@ -53,8 +53,8 @@ private:
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
//pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),PrimitiveType::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Alpha2D,PrimitiveType::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
//pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Alpha2D,Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
@ -118,7 +118,7 @@ private:
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateMesh(primitive,material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ private:
|
||||
Camera cam;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_rb_config =nullptr;
|
||||
@ -66,7 +66,7 @@ private:
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),PrimitiveType::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
@ -140,7 +140,7 @@ private:
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateMesh(primitive,material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Billboard
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
@ -11,9 +11,6 @@
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#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;
|
||||
@ -28,7 +25,7 @@ static float lumiance_data[2]={1,1};
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public WorkObject
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
@ -41,7 +38,7 @@ private:
|
||||
|
||||
MaterialInstance * mi_billboard =nullptr;
|
||||
Pipeline * pipeline_billboard =nullptr;
|
||||
Mesh * ro_billboard =nullptr;
|
||||
Renderable * ro_billboard =nullptr;
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
@ -50,7 +47,7 @@ private:
|
||||
|
||||
bool InitPlaneGridMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
@ -67,7 +64,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);
|
||||
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
@ -76,15 +73,17 @@ private:
|
||||
|
||||
bool InitBillboardMP()
|
||||
{
|
||||
mtl::BillboardMaterialCreateConfig cfg(PrimitiveType::Billboard);
|
||||
mtl::BillboardMaterialCreateConfig cfg(device->GetDeviceAttribute(),"Billboard2D",Prim::Billboard);
|
||||
|
||||
{
|
||||
cfg.fixed_size=true;
|
||||
|
||||
mi_billboard=CreateMaterialInstance(mtl::inline_material::Billboard2D,&cfg);
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateBillboard2D(&cfg);
|
||||
|
||||
mi_billboard=db->CreateMaterialInstance(mci);
|
||||
if(!mi_billboard)return(false);
|
||||
|
||||
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D);
|
||||
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D,Prim::Billboard);
|
||||
if(!pipeline_billboard)return(false);
|
||||
}
|
||||
|
||||
@ -93,9 +92,7 @@ private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
TextureManager *tex_manager=GetTextureManager();
|
||||
|
||||
texture=tex_manager->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
@ -113,12 +110,27 @@ private:
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.Add(new SceneNode(ri));
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
auto pc=GetPrimitiveCreater(mi_plane_grid);
|
||||
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
@ -128,19 +140,18 @@ private:
|
||||
pgci.lum=128;
|
||||
pgci.sub_lum=192;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
|
||||
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
auto pc=GetPrimitiveCreater(mi_billboard);
|
||||
PrimitiveCreater pc(device,mi_billboard->GetVIL());
|
||||
|
||||
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->CreateRenderable(&pc,mi_billboard,pipeline_billboard);
|
||||
if(!ro_billboard)
|
||||
return(false);
|
||||
}
|
||||
@ -150,30 +161,32 @@ private:
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
|
||||
CreateComponent<MeshComponent>(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
|
||||
CreateComponent<MeshComponent>(scene_root,ro_billboard);
|
||||
render_root.Add(new SceneNode(ro_billboard));
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitPlaneGridMP())
|
||||
return(false);
|
||||
|
||||
@ -191,9 +204,9 @@ public:
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("Billboard"),1280,720);
|
||||
return RunApp<TestApp>(1920,1080);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
macro(CreateProject name)
|
||||
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
@ -11,8 +10,10 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
|
||||
endmacro()
|
||||
|
||||
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(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(04_Billboard BillboardTest.cpp)
|
||||
CreateProject(05_Billboard BillboardTest.cpp)
|
||||
|
@ -1,6 +0,0 @@
|
||||
#include<hgl/graph/mtl/MaterialLibrary.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
STD_MTL_NAMESPACE_END
|
@ -5,7 +5,6 @@
|
||||
#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;
|
||||
@ -30,10 +29,16 @@ 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;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
@ -42,29 +47,32 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
|
||||
CoordinateSystem2D::NDC,
|
||||
mtl::WithLocalToWorld::With);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8);
|
||||
|
||||
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor2D,&cfg,&vil_config);
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
}
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
render_obj=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position, VF_V2F, position_data},
|
||||
{VAN::Color, VF_V4UN8, color_data }
|
||||
@ -76,34 +84,41 @@ 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); //这里一定要加<double>或<float>,否则结果用int保存会出现问题
|
||||
rad=deg2rad<double>((360.0f/double(TRIANGLE_NUMBER))*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
||||
mat=rotate(rad,Vector3f(0,0,1));
|
||||
|
||||
CreateComponent<MeshComponent>(mat,scene_root,render_obj);
|
||||
render_root.Add(new SceneNode(mat,render_obj));
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
GetRenderer()->SetClearColor(Color4f(0.2f,0.2f,0.2f,1.0f));
|
||||
render_list=rf->CreateRenderList();
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
#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;
|
||||
@ -26,12 +25,20 @@ 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;
|
||||
Renderable * r;
|
||||
}render_obj[DRAW_OBJECT_COUNT]{};
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
@ -41,7 +48,10 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,CoordinateSystem2D::NDC,mtl::WithLocalToWorld::With);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
#ifndef USE_MATERIAL_FILE
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg); //走程序内置材质创建函数
|
||||
@ -66,7 +76,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D);
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Triangles);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
@ -83,38 +93,47 @@ private:
|
||||
|
||||
Matrix4f mat;
|
||||
|
||||
SceneNode *scene_root=GetSceneRoot(); ///<取得场景根节点
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].mesh=db->CreateMesh(prim,render_obj[i].mi,pipeline);
|
||||
render_obj[i].r=db->CreateRenderable(prim,render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].mesh)
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
mat=rotate(deg2rad<double>(TRI_ROTATE_ANGLE*i),AxisVector::Z);
|
||||
|
||||
CreateComponent<MeshComponent>(mat,scene_root,render_obj[i].mesh);
|
||||
render_root.Add(new SceneNode(mat,render_obj[i].r));
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
render_list=rf->CreateRenderList();
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
return;
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
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 VulkanApplicationFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
|
155
example/Basic/draw_triangle_in_NDC.cpp
Normal file
155
example/Basic/draw_triangle_in_NDC.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
// 该范例主要演示使用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;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
void InitVIL()
|
||||
{
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
vil_config.Add(VAN::Position,PositionFormat);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
#ifdef USE_UNORM8_COLOR
|
||||
vil_config.Add(VAN::Color,ColorFormat);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
}
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position,PositionFormat,position_data},
|
||||
{VAN::Color, ColorFormat, color_data}
|
||||
});
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
InitVIL();
|
||||
|
||||
if(!InitAutoMaterial())
|
||||
return;
|
||||
|
||||
if(!InitPipeline())
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return;
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
@ -5,8 +5,6 @@
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
@ -37,8 +35,10 @@ class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * mesh_triangle =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
@ -46,12 +46,12 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
|
||||
CoordinateSystem2D::Ortho,
|
||||
mtl::WithLocalToWorld::With);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
cfg.coordinate_system =CoordinateSystem2D::Ortho;
|
||||
|
||||
cfg.position_format = POSITION_SHADER_FORMAT; //这里指定shader中使用ivec2当做顶点输入格式
|
||||
// ^
|
||||
// + 这上下两种格式要配套,否则会出错
|
||||
@ -60,20 +60,24 @@ private:
|
||||
|
||||
vil_config.Add(VAN::Color, COLOR_DATA_FORMAT); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor2D,&cfg,&vil_config);
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
const auto ext=GetExtent();
|
||||
const auto ext=GetExtent2D();
|
||||
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
@ -81,31 +85,32 @@ private:
|
||||
position_data[i][1]=position_data_float[i][1]*ext.height;
|
||||
}
|
||||
|
||||
mesh_triangle=CreateMesh("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position,POSITION_DATA_FORMAT,position_data},
|
||||
{VAN::Color, COLOR_DATA_FORMAT, color_data}
|
||||
});
|
||||
|
||||
if(!mesh_triangle)
|
||||
return(false);
|
||||
|
||||
return CreateComponent<MeshComponent>(GetSceneRoot(),mesh_triangle); //创建一个静态网格组件
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
103
example/Basic/rf_test.cpp
Normal file
103
example/Basic/rf_test.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#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>
|
||||
|
||||
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;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=CreateMaterialInstance(mci);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position,VF_V2F,position_data},
|
||||
{VAN::Color, VF_V4F,color_data}
|
||||
});
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
if(!InitAutoMaterial())
|
||||
return;
|
||||
|
||||
if(!InitPipeline())
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return;
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
@ -15,7 +15,7 @@ private:
|
||||
TextRender * text_render =nullptr;
|
||||
|
||||
TextPrimitive * text_primitive =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
@ -44,7 +44,7 @@ private:
|
||||
if(!text_primitive)
|
||||
return(false);
|
||||
|
||||
render_obj=text_render->CreateMesh(text_primitive);
|
||||
render_obj=text_render->CreateRenderable(text_primitive);
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
|
30
example/Gizmo/BlenderAxis.cpp
Normal file
30
example/Gizmo/BlenderAxis.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Blender axis
|
||||
/**
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* 0+---------->>>> X
|
||||
* 1|
|
||||
* 2|
|
||||
* 3| +--+
|
||||
* 4| +--+
|
||||
* 5|
|
||||
* 6V
|
||||
* 7V
|
||||
*
|
||||
* 坐标轴参考Blender设计
|
||||
*
|
||||
* 单方向坐标轴长度为8
|
||||
* 最终箭头长度为2
|
||||
*
|
||||
* 负责2D平移的方块尺寸为1,位置在3-4
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 缩放工具
|
||||
*/
|
||||
class GizmoScale
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
};//class GizmoScale
|
@ -10,15 +10,16 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_SimplestAxis SimplestAxis.cpp)
|
||||
CreateProject(02_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(03_RayPicking RayPicking.cpp)
|
||||
CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(02_RayPicking RayPicking.cpp)
|
||||
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
||||
|
||||
CreateProject(04_Gizmo3DTest GizmoTest.cpp
|
||||
Gizmo.h
|
||||
GizmoResource.h
|
||||
GizmoResource.cpp
|
||||
Gizmo3DMove.cpp
|
||||
#Gizmo3DScale.cpp
|
||||
#Gizmo3DRotate.cpp
|
||||
)
|
||||
Gizmo3DScale.cpp
|
||||
Gizmo3DRotate.cpp)
|
||||
|
||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
||||
|
@ -31,13 +31,13 @@ enum class GizmoShape:uint
|
||||
ENUM_CLASS_RANGE(Square,Torus)
|
||||
};
|
||||
|
||||
bool InitGizmoResource(RenderFramework *);
|
||||
bool InitGizmoResource(RenderResource *);
|
||||
void FreeGizmoResource();
|
||||
|
||||
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color);
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color);
|
||||
|
||||
SceneNode *GetGizmoMoveNode();
|
||||
//SceneNode *GetGizmoScaleMesh();
|
||||
//SceneNode *GetGizmoRotateMesh();
|
||||
StaticMesh *GetGizmoMoveStaticMesh();
|
||||
StaticMesh *GetGizmoScaleStaticMesh();
|
||||
StaticMesh *GetGizmoRotateStaticMesh();
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -25,49 +25,46 @@
|
||||
#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 SceneNode *sn_gizmo_move=nullptr;
|
||||
static StaticMesh *sm_gizmo_move=nullptr;
|
||||
}//namespace
|
||||
|
||||
SceneNode *GetGizmoMoveNode()
|
||||
StaticMesh *GetGizmoMoveStaticMesh()
|
||||
{
|
||||
return sn_gizmo_move;
|
||||
return sm_gizmo_move;
|
||||
}
|
||||
|
||||
void ClearGizmoMoveNode()
|
||||
void ClearGizmoMoveStaticMesh()
|
||||
{
|
||||
SAFE_CLEAR(sn_gizmo_move);
|
||||
SAFE_CLEAR(sm_gizmo_move);
|
||||
}
|
||||
|
||||
bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
bool InitGizmoMoveStaticMesh()
|
||||
{
|
||||
Mesh *sphere=GetGizmoMesh(GizmoShape::Sphere,GizmoColor::White);
|
||||
Mesh *cylinder[3]
|
||||
Renderable *sphere=GetGizmoRenderable(GizmoShape::Sphere,GizmoColor::White);
|
||||
Renderable *cylinder[3]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Mesh *cone[3]
|
||||
Renderable *cone[3]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Blue),
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Mesh *square[3]=
|
||||
Renderable *circle[3]=
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
|
||||
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Blue)
|
||||
};
|
||||
|
||||
if(!sphere)
|
||||
@ -81,69 +78,72 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
if(!cone[i])
|
||||
return(false);
|
||||
|
||||
if(!square[i])
|
||||
if(!circle[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
sn_gizmo_move=new SceneNode();
|
||||
SceneNode *root_node=new SceneNode();
|
||||
|
||||
sn_gizmo_move->AttachComponent(render_framework->CreateComponent<MeshComponent>(sphere));
|
||||
root_node->Add(new SceneNode(sphere));
|
||||
|
||||
{
|
||||
Transform tm;
|
||||
|
||||
const Vector3f one_scale(1);
|
||||
const Vector3f square_scale(2);
|
||||
const Vector3f circle_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);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
|
||||
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[2]); //Z 向上圆锥
|
||||
root_node->Add(new SceneNode(tm,cone[2])); //Z 向上圆锥
|
||||
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[2]);
|
||||
root_node->Add(new SceneNode(tm,circle[2]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::Y,90);
|
||||
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[0]); //X 向右圆柱
|
||||
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[0]); //X 向右圆锥
|
||||
root_node->Add(new SceneNode(tm,cone[0])); //X 向右圆锥
|
||||
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[0]);
|
||||
root_node->Add(new SceneNode(tm,circle[0]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::X,-90);
|
||||
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[1]); //Y 向前圆柱
|
||||
|
||||
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[1]); //Y 向前圆锥
|
||||
root_node->Add(new SceneNode(tm,cone[1])); //Y 向前圆锥
|
||||
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[1]);
|
||||
}
|
||||
root_node->Add(new SceneNode(tm,circle[1]));
|
||||
}
|
||||
}
|
||||
|
||||
if(!sn_gizmo_move)
|
||||
sm_gizmo_move=CreateGizmoStaticMesh(root_node);
|
||||
}
|
||||
|
||||
if(!sm_gizmo_move)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
|
@ -22,13 +22,13 @@ void ClearGizmoRotateStaticMesh()
|
||||
|
||||
bool InitGizmoRotateStaticMesh()
|
||||
{
|
||||
Mesh *torus[4]
|
||||
Renderable *torus[4]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::Blue),
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Blue),
|
||||
|
||||
GetGizmoMesh(GizmoShape::Torus,GizmoColor::White),
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::White),
|
||||
};
|
||||
|
||||
for(auto *r:torus)
|
||||
|
@ -45,26 +45,26 @@ void ClearGizmoScaleStaticMesh()
|
||||
|
||||
bool InitGizmoScaleStaticMesh()
|
||||
{
|
||||
Mesh *center_cube=GetGizmoMesh(GizmoShape::Cube,GizmoColor::White);
|
||||
Mesh *cylinder[3]
|
||||
Renderable *center_cube=GetGizmoRenderable(GizmoShape::Cube,GizmoColor::White);
|
||||
Renderable *cylinder[3]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Mesh *cube[3]
|
||||
Renderable *cube[3]
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Blue),
|
||||
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Mesh *square[3]=
|
||||
Renderable *square[3]=
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
|
||||
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Blue)
|
||||
};
|
||||
|
||||
if(!center_cube)
|
||||
|
@ -9,23 +9,21 @@
|
||||
#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 InitGizmoMoveNode(RenderFramework *);
|
||||
void ClearGizmoMoveNode();
|
||||
bool InitGizmoMoveStaticMesh();
|
||||
void ClearGizmoMoveStaticMesh();
|
||||
|
||||
//bool InitGizmoScaleMesh();
|
||||
//void ClearGizmoScaleMesh();
|
||||
//
|
||||
//bool InitGizmoRotateMesh();
|
||||
//void ClearGizmoRotateMesh();
|
||||
bool InitGizmoScaleStaticMesh();
|
||||
void ClearGizmoScaleStaticMesh();
|
||||
|
||||
bool InitGizmoRotateStaticMesh();
|
||||
void ClearGizmoRotateStaticMesh();
|
||||
|
||||
namespace
|
||||
{
|
||||
static RenderFramework *render_framework=nullptr;
|
||||
static RenderResource * gizmo_rr=nullptr;
|
||||
|
||||
struct GizmoResource
|
||||
@ -41,26 +39,26 @@ namespace
|
||||
static GizmoResource gizmo_line{};
|
||||
static GizmoResource gizmo_triangle{};
|
||||
|
||||
struct GizmoMesh
|
||||
struct GizmoRenderable
|
||||
{
|
||||
Primitive *prim;
|
||||
|
||||
Mesh *mesh[size_t(GizmoColor::RANGE_SIZE)];
|
||||
Renderable *renderable[size_t(GizmoColor::RANGE_SIZE)];
|
||||
};
|
||||
|
||||
GizmoMesh gizmo_mesh[size_t(GizmoShape::RANGE_SIZE)]{};
|
||||
GizmoRenderable gizmo_rederable[size_t(GizmoShape::RANGE_SIZE)]{};
|
||||
|
||||
void InitGizmoMesh(const GizmoShape &gs,Primitive *prim,Pipeline *p)
|
||||
void InitGizmoRenderable(const GizmoShape &gs,Primitive *prim,Pipeline *p)
|
||||
{
|
||||
if(!prim)
|
||||
return;
|
||||
|
||||
GizmoMesh *gr=gizmo_mesh+size_t(gs);
|
||||
GizmoRenderable *gr=gizmo_rederable+size_t(gs);
|
||||
|
||||
gr->prim=prim;
|
||||
|
||||
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
||||
gr->mesh[i]=CreateMesh(prim,gizmo_triangle.mi[i],p);
|
||||
gr->renderable[i]=CreateRenderable(prim,gizmo_triangle.mi[i],p);
|
||||
}
|
||||
|
||||
bool InitMI(GizmoResource *gr)
|
||||
@ -82,27 +80,26 @@ namespace
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitGizmoResource2D()
|
||||
bool InitGizmoResource2D(GPUDevice *device)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(false);
|
||||
|
||||
VulkanDevice *device=render_framework->GetDevice();
|
||||
VulkanDevAttr *dev_attr=device->GetDevAttr();
|
||||
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
|
||||
RenderPass *render_pass=device->GetRenderPass();
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC3;
|
||||
|
||||
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(dev_attr,&cfg);
|
||||
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(&cfg);
|
||||
|
||||
if(!mci)
|
||||
return(false);
|
||||
|
||||
gizmo_line.mtl=gizmo_rr->CreateMaterial("GizmoLine",mci);
|
||||
gizmo_line.mtl=gizmo_rr->CreateMaterial(mci);
|
||||
if(!gizmo_line.mtl)
|
||||
return(false);
|
||||
|
||||
@ -110,7 +107,7 @@ namespace
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D);
|
||||
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!gizmo_line.pipeline)
|
||||
return(false);
|
||||
@ -137,27 +134,25 @@ namespace
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitGizmoResource3D()
|
||||
bool InitGizmoResource3D(GPUDevice *device)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(false);
|
||||
|
||||
VulkanDevice *device=render_framework->GetDevice();
|
||||
VulkanDevAttr *dev_attr=device->GetDevAttr();
|
||||
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
|
||||
RenderPass *render_pass=device->GetRenderPass();
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Triangles);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"Gizmo3D",Prim::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.material_instance=true;
|
||||
|
||||
mtl::MaterialCreateInfo *mci=CreateGizmo3D(dev_attr,&cfg);
|
||||
mtl::MaterialCreateInfo *mci=CreateMaterialGizmo3D(&cfg);
|
||||
|
||||
if(!mci)
|
||||
return(false);
|
||||
|
||||
gizmo_triangle.mtl=gizmo_rr->CreateMaterial("GizmoTriangle",mci);
|
||||
gizmo_triangle.mtl=gizmo_rr->CreateMaterial(mci);
|
||||
if(!gizmo_triangle.mtl)
|
||||
return(false);
|
||||
|
||||
@ -165,7 +160,7 @@ namespace
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D);
|
||||
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
if(!gizmo_triangle.pipeline)
|
||||
return(false);
|
||||
}
|
||||
@ -196,7 +191,7 @@ namespace
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
InitGizmoMesh(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
|
||||
InitGizmoRenderable(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@ -207,7 +202,7 @@ namespace
|
||||
cci.field_count=16;
|
||||
cci.has_center=false;
|
||||
|
||||
InitGizmoMesh(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
InitGizmoRenderable(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@ -217,11 +212,11 @@ namespace
|
||||
cci.tangent=false;
|
||||
cci.tex_coord=false;
|
||||
|
||||
InitGizmoMesh(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
InitGizmoRenderable(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
InitGizmoMesh(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
|
||||
InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@ -232,7 +227,7 @@ namespace
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=3; //圆锥高度分割数
|
||||
|
||||
InitGizmoMesh(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@ -242,7 +237,7 @@ namespace
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =1; //圆柱半径
|
||||
|
||||
InitGizmoMesh(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@ -253,12 +248,12 @@ namespace
|
||||
tci.numberSlices=64;
|
||||
tci.numberStacks=8;
|
||||
|
||||
InitGizmoMesh(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
|
||||
InitGizmoRenderable(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
ENUM_CLASS_FOR(GizmoShape,int,i)
|
||||
{
|
||||
if(!gizmo_mesh[i].prim)
|
||||
if(!gizmo_rederable[i].prim)
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
@ -267,40 +262,41 @@ namespace
|
||||
}
|
||||
}//namespace
|
||||
|
||||
bool InitGizmoResource(RenderFramework *rf)
|
||||
bool InitGizmoResource(RenderResource *rr)
|
||||
{
|
||||
if(!rf)
|
||||
if(!rr)
|
||||
return(false);
|
||||
|
||||
render_framework=rf;
|
||||
|
||||
gizmo_rr=render_framework->GetRenderResource();
|
||||
|
||||
VulkanDevice *device=render_framework->GetDevice();
|
||||
|
||||
if(!InitGizmoResource3D())
|
||||
if(gizmo_rr)
|
||||
return(false);
|
||||
|
||||
if(!InitGizmoResource2D())
|
||||
gizmo_rr=rr;
|
||||
|
||||
GPUDevice *device=gizmo_rr->GetDevice();
|
||||
|
||||
if(!InitGizmoResource3D(device))
|
||||
return(false);
|
||||
|
||||
InitGizmoMoveNode(rf);
|
||||
//InitGizmoScaleMesh();
|
||||
//InitGizmoRotateMesh();
|
||||
if(!InitGizmoResource2D(device))
|
||||
return(false);
|
||||
|
||||
InitGizmoMoveStaticMesh();
|
||||
InitGizmoScaleStaticMesh();
|
||||
InitGizmoRotateStaticMesh();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void FreeGizmoResource()
|
||||
{
|
||||
//ClearGizmoRotateMesh();
|
||||
//ClearGizmoScaleMesh();
|
||||
ClearGizmoMoveNode();
|
||||
ClearGizmoRotateStaticMesh();
|
||||
ClearGizmoScaleStaticMesh();
|
||||
ClearGizmoMoveStaticMesh();
|
||||
|
||||
for(GizmoMesh &gr:gizmo_mesh)
|
||||
for(GizmoRenderable &gr:gizmo_rederable)
|
||||
{
|
||||
SAFE_CLEAR(gr.prim)
|
||||
SAFE_CLEAR_OBJECT_ARRAY(gr.mesh)
|
||||
SAFE_CLEAR_OBJECT_ARRAY(gr.renderable)
|
||||
}
|
||||
|
||||
SAFE_CLEAR(gizmo_triangle.prim_creater);
|
||||
@ -310,7 +306,7 @@ void FreeGizmoResource()
|
||||
SAFE_CLEAR(gizmo_line.vdm);
|
||||
}
|
||||
|
||||
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color)
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(nullptr);
|
||||
@ -318,7 +314,18 @@ Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color)
|
||||
RANGE_CHECK_RETURN_NULLPTR(shape)
|
||||
RANGE_CHECK_RETURN_NULLPTR(color)
|
||||
|
||||
return gizmo_mesh[size_t(shape)].mesh[size_t(color)];
|
||||
return gizmo_rederable[size_t(shape)].renderable[size_t(color)];
|
||||
}
|
||||
|
||||
StaticMesh *CreateGizmoStaticMesh(SceneNode *root_node)
|
||||
{
|
||||
if(!root_node)
|
||||
return(nullptr);
|
||||
|
||||
if(root_node->IsEmpty())
|
||||
return(nullptr);
|
||||
|
||||
return(new StaticMesh(root_node));
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include"Gizmo.h"
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
@ -7,7 +6,7 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
class SceneNode;
|
||||
class PrimitiveCreater;
|
||||
class MeshComponent;
|
||||
class StaticMesh;
|
||||
|
||||
constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]=
|
||||
{
|
||||
@ -36,6 +35,8 @@ constexpr const float GIZMO_CYLINDER_OFFSET =GIZMO_CYLINDER_HALF_LENGTH+GIZM
|
||||
|
||||
constexpr const float GIZMO_TWO_AXIS_OFFSET =5.0F; ///<二轴调节点偏移量(方片或圆)
|
||||
|
||||
Mesh *GetGizmoMesh(const GizmoShape &gs,const GizmoColor &);
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &gs,const GizmoColor &);
|
||||
|
||||
StaticMesh *CreateGizmoStaticMesh(SceneNode *);
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/WorkManager.h>
|
||||
#include"VulkanAppFramework.h"
|
||||
#include"Gizmo.h"
|
||||
#include<hgl/graph/Ray.h>
|
||||
|
||||
@ -52,81 +52,94 @@ const Vector3f GizmoPosition(0,0,0);
|
||||
// }
|
||||
//};//class BillboardSceneNode:public SceneNode
|
||||
|
||||
class TestApp:public WorkObject
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
SceneNode *sm_move=nullptr;
|
||||
//StaticMesh *sm_rotate=nullptr;
|
||||
//StaticMesh *sm_scale=nullptr;
|
||||
SceneNode root;
|
||||
|
||||
StaticMesh *sm_move=nullptr;
|
||||
StaticMesh *sm_rotate=nullptr;
|
||||
StaticMesh *sm_scale=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitGizmo()
|
||||
{
|
||||
if(!InitGizmoResource(GetRenderFramework()))
|
||||
if(!InitGizmoResource(db))
|
||||
return(false);
|
||||
|
||||
sm_move =GetGizmoMoveNode();
|
||||
//sm_rotate =GetGizmoRotateStaticMesh();
|
||||
//sm_scale =GetGizmoScaleStaticMesh();
|
||||
sm_move =GetGizmoMoveStaticMesh();
|
||||
sm_rotate =GetGizmoRotateStaticMesh();
|
||||
sm_scale =GetGizmoScaleStaticMesh();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void InitGizmoSceneTree()
|
||||
{
|
||||
SceneNode *root=GetSceneRoot();
|
||||
camera_control->Refresh();
|
||||
CameraInfo *ci=camera_control->GetCameraInfo();
|
||||
|
||||
root->Add(Duplication(sm_move));
|
||||
//root.Add(Duplication(sm_rotate->GetScene()));
|
||||
root.Clear();
|
||||
|
||||
//root.Add(Duplication(sm_move->GetScene()));
|
||||
root.Add(Duplication(sm_rotate->GetScene()));
|
||||
//root.CreateSubNode(sm_scale->GetScene());
|
||||
|
||||
root.RefreshMatrix();
|
||||
render_list->SetCamera(ci);
|
||||
render_list->Expend(&root);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init() override
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitGizmo())
|
||||
return(false);
|
||||
|
||||
InitGizmoSceneTree();
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera->pos=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();
|
||||
|
||||
// const float screen_height=vi->GetViewportHeight();
|
||||
|
||||
// const Vector4f pos=ci->Project(GizmoPosition);
|
||||
|
||||
// //{
|
||||
// // Transform tm;
|
||||
|
||||
// // tm.SetScale(pos.w*16.0f/screen_height);
|
||||
|
||||
// // root.SetLocalTransform(tm);
|
||||
// //}
|
||||
//}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("Gizmo"),1280,720);
|
||||
camera_control->Refresh();
|
||||
|
||||
const CameraInfo *ci=camera_control->GetCameraInfo();
|
||||
const ViewportInfo *vi=GetViewportInfo();
|
||||
|
||||
const float screen_height=vi->GetViewportHeight();
|
||||
|
||||
const Vector4f pos=ci->Project(GizmoPosition);
|
||||
|
||||
//{
|
||||
// Transform tm;
|
||||
|
||||
// tm.SetScale(pos.w*16.0f/screen_height);
|
||||
|
||||
// root.SetLocalTransform(tm);
|
||||
//}
|
||||
|
||||
root.RefreshMatrix();
|
||||
render_list->UpdateLocalToWorld();
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
};//class TestApp:public SceneAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1024,1024);
|
||||
}
|
||||
|
147
example/Gizmo/MetricCellsGrid.cpp
Normal file
147
example/Gizmo/MetricCellsGrid.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
// 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->GetDeviceAttribute(),"MetricCellsGrid",Prim::Fan);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/MetricCellsGrid",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
{
|
||||
mcg_data.x_color=Color4f(1,1,1,1);
|
||||
mcg_data.y_color=Color4f(1,1,1,1);
|
||||
|
||||
mcg_data.x_axis_color=GetColor4f(COLOR::BlenderAxisRed, 1.0);
|
||||
mcg_data.y_axis_color=GetColor4f(COLOR::BlenderAxisGreen, 1.0);
|
||||
|
||||
mcg_data.center_color=Color4f(1,1,0,1);
|
||||
|
||||
mcg_data.lum =Vector2f(0.1,0.2);
|
||||
mcg_data.cell_step =Vector2f(8,8);
|
||||
mcg_data.big_cell_step =Vector2f(32,32);
|
||||
mcg_data.scale =Vector2f(PLANE_SIZE,PLANE_SIZE);
|
||||
|
||||
mcg_data.axis_line_width=1.0;
|
||||
mcg_data.center_radius =4.0;
|
||||
}
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material,nullptr,&mcg_data);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Fan);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
ro_plane=inline_geometry::CreatePlaneSqaure(&pc);
|
||||
|
||||
if(ro_plane)
|
||||
db->Add(ro_plane);
|
||||
|
||||
return ro_plane;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(ro_plane,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
|
||||
|
||||
camera->pos=Vector3f(PLANE_SIZE/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);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// PlaneGrid3D
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
@ -8,14 +8,11 @@
|
||||
#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
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
@ -29,7 +26,7 @@ private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC2;
|
||||
@ -53,7 +50,7 @@ private:
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D);
|
||||
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
@ -70,52 +67,55 @@ private:
|
||||
pgci.lum=180;
|
||||
pgci.sub_lum=255;
|
||||
|
||||
auto pc=GetPrimitiveCreater(material_instance[0]);
|
||||
PrimitiveCreater pc(device,material_instance[0]->GetVIL());
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
|
||||
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
|
||||
|
||||
return prim_plane_grid;
|
||||
}
|
||||
|
||||
void Add(SceneNode *parent_node,MaterialInstance *mi,const Matrix4f &mat)
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(prim_plane_grid,mi,pipeline);
|
||||
Renderable *ri=db->CreateRenderable(prim_plane_grid,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return;
|
||||
return(nullptr);
|
||||
|
||||
CreateComponent<MeshComponent>(mat,parent_node,ri);
|
||||
render_root.Add(new SceneNode(mat,ri));
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
||||
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));
|
||||
|
||||
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->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
@ -129,7 +129,7 @@ public:
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("PlaneGrid3D"),1280,720);
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// RayPicking
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
@ -11,7 +11,6 @@
|
||||
#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;
|
||||
@ -22,12 +21,12 @@ static float position_data[2][3]=
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static uint8 lumiance_data[2]={255,255};
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public WorkObject
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
@ -52,37 +51,39 @@ private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance2D",Prim::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);
|
||||
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
|
||||
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,&vil_config,&yellow_color);
|
||||
mi_line=db->CreateMaterialInstance(mtl_line,nullptr,&yellow_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
pipeline_line=CreatePipeline(mi_line,InlinePipeline::Solid3D);
|
||||
pipeline_line=CreatePipeline(mtl_line,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline_line)
|
||||
return(false);
|
||||
@ -91,17 +92,17 @@ private:
|
||||
return(true);
|
||||
}
|
||||
|
||||
Mesh *Add(SceneNode *parent_node,Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(r,mi,p);
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Mesh failed."));
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
CreateComponent<MeshComponent>(parent_node,ri);
|
||||
render_root.Add(new SceneNode(ri));
|
||||
|
||||
return ri;
|
||||
}
|
||||
@ -111,7 +112,7 @@ private:
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
auto pc=GetPrimitiveCreater(mi_plane_grid);
|
||||
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
@ -121,15 +122,19 @@ private:
|
||||
pgci.lum=128;
|
||||
pgci.sub_lum=196;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
|
||||
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
prim_line=CreatePrimitive("RayLine",2,mi_line->GetVIL(),
|
||||
{
|
||||
{VAN::Position, VF_V3F,position_data},
|
||||
{VAN::Luminance,VF_V1UN8,lumiance_data}
|
||||
});
|
||||
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_vab_map=prim_line->GetVABMap(VAN::Position);
|
||||
}
|
||||
@ -139,30 +144,32 @@ private:
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
Add(prim_line,mi_line,pipeline_line);
|
||||
|
||||
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->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
SAFE_CLEAR(prim_line);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
@ -175,28 +182,23 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Tick(double) override
|
||||
void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
Vector2i mouse_position;
|
||||
const CameraInfo *ci=GetCameraInfo();
|
||||
const ViewportInfo *vi=GetViewportInfo();
|
||||
|
||||
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); //设置射线查询的屏幕坐标点
|
||||
ray.Set(GetMouseCoord(),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);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("RayPicking"),1280,720);
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
||||
|
@ -1,100 +0,0 @@
|
||||
// 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);
|
||||
}
|
@ -104,7 +104,7 @@ private:
|
||||
|
||||
bool InitVertexLumMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"VertexLuminance3D",PrimitiveType::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
@ -114,7 +114,7 @@ private:
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_vertex_lum,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
p_line=CreatePipeline(mtl_vertex_lum,InlinePipeline::Solid3D,PrimitiveType::Lines);
|
||||
p_line=CreatePipeline(mtl_vertex_lum,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!p_line)
|
||||
return(false);
|
||||
@ -132,7 +132,7 @@ private:
|
||||
|
||||
bool InitBlinnPhongSunLightMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"BlinnPhong3D",PrimitiveType::Triangles);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",Prim::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.material_instance=true;
|
||||
@ -170,7 +170,7 @@ private:
|
||||
if(!mi_blinnphong[i])return(false);
|
||||
}
|
||||
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,PrimitiveType::Triangles);
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
@ -243,7 +243,7 @@ private:
|
||||
return(true);
|
||||
}
|
||||
|
||||
Mesh *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat=Identity4f)
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat=Identity4f)
|
||||
{
|
||||
if(!r)
|
||||
return(nullptr);
|
||||
@ -252,11 +252,11 @@ private:
|
||||
if(!p)
|
||||
return(nullptr);
|
||||
|
||||
Mesh *ri=db->CreateMesh(r,mi,p);
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR("Create Mesh failed! Primitive: "+r->GetName());
|
||||
LOG_ERROR("Create Renderable failed! Primitive: "+r->GetName());
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,8 @@ int main(int,char **)
|
||||
{
|
||||
Window * win =nullptr;
|
||||
VulkanInstance * inst =nullptr;
|
||||
VulkanDevice * device =nullptr;
|
||||
const VulkanPhyDevice * physical_device =nullptr;
|
||||
GPUDevice * device =nullptr;
|
||||
const GPUPhysicalDevice * physical_device =nullptr;
|
||||
|
||||
inst=InitVulkanInstance();
|
||||
|
||||
|
@ -12,7 +12,7 @@ using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
@ -44,14 +44,14 @@ private:
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"PureTexture2D",PrimitiveType::Fan);
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureTexture2D",Prim::Fan);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
@ -62,7 +62,7 @@ private:
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,PrimitiveType::Fan); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Fan); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
@ -92,7 +92,7 @@ private:
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
|
||||
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
@ -40,14 +40,14 @@ private:
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Mesh * render_obj =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"RectTexture2D",PrimitiveType::SolidRectangles);
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2D",Prim::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=false;
|
||||
@ -58,7 +58,7 @@ private:
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,PrimitiveType::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
@ -88,7 +88,7 @@ private:
|
||||
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
//Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
//Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
@ -61,7 +61,7 @@ private:
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Mesh * mesh;
|
||||
Renderable * r;
|
||||
}render_obj[TexCount]{};
|
||||
|
||||
private:
|
||||
@ -91,7 +91,7 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDevAttr(),"RectTexture2DArray",PrimitiveType::SolidRectangles);
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2DArray",Prim::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=true;
|
||||
@ -101,7 +101,7 @@ private:
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,PrimitiveType::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
@ -144,14 +144,14 @@ private:
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].mesh=db->CreateMesh(prim_rectangle,render_obj[i].mi,pipeline);
|
||||
render_obj[i].r=db->CreateRenderable(prim_rectangle,render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].mesh)
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
offset.x=position_data[2]*float(i);
|
||||
|
||||
render_root.CreateSubNode(translate(offset),render_obj[i].mesh);
|
||||
render_root.CreateSubNode(translate(offset),render_obj[i].r);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
|
@ -103,7 +103,7 @@ private:
|
||||
|
||||
const VkFormat GetCandidateFormat(const VkFormat *fmt_list, const uint count)
|
||||
{
|
||||
auto pd = device->GetPhyDevice();
|
||||
auto pd = device->GetPhysicalDevice();
|
||||
|
||||
for (uint i = 0; i < count; i++)
|
||||
if (pd->IsColorAttachmentOptimal(fmt_list[i]))
|
||||
@ -118,7 +118,7 @@ private:
|
||||
|
||||
const VkFormat GetDepthCandidateFormat()
|
||||
{
|
||||
auto pd = device->GetPhyDevice();
|
||||
auto pd = device->GetPhysicalDevice();
|
||||
|
||||
for (VkFormat fmt : depth_candidate_format)
|
||||
if (pd->IsDepthAttachmentOptimal(fmt))
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKImageView.h>
|
||||
@ -16,7 +16,7 @@ using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(VulkanDevice *device,const OSString &filename);
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
@ -139,7 +139,7 @@ private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
auto da=device->GetDevAttr();
|
||||
auto da=device->GetDeviceAttribute();
|
||||
|
||||
if(da->debug_maker)
|
||||
{
|
||||
@ -172,7 +172,7 @@ private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
auto da=device->GetDevAttr();
|
||||
auto da=device->GetDeviceAttribute();
|
||||
|
||||
VkQueue q=*(gbuffer.rt->GetQueue());
|
||||
VkFramebuffer fbo= gbuffer.rt->GetFramebuffer()->GetFramebuffer();
|
||||
@ -229,7 +229,7 @@ private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
auto da=device->GetDevAttr();
|
||||
auto da=device->GetDeviceAttribute();
|
||||
|
||||
if(da->debug_maker)
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
@ -109,7 +109,7 @@ private:
|
||||
VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
||||
0.0f,
|
||||
VK_TRUE,
|
||||
device->GetPhyDevice()->GetMaxSamplerAnisotropy(),
|
||||
device->GetPhysicalDevice()->GetMaxSamplerAnisotropy(),
|
||||
false,
|
||||
VK_COMPARE_OP_NEVER,
|
||||
0.0f,
|
||||
|
@ -53,7 +53,7 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
VulkanDevice * device =nullptr;
|
||||
GPUDevice * device =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
SwapchainRenderTarget * sc_render_target =nullptr;
|
||||
|
||||
@ -216,11 +216,11 @@ public:
|
||||
cmd_buf=hgl_zero_new<RenderCmdBuffer *>(swap_chain_count);
|
||||
|
||||
for(int32_t i=0;i<swap_chain_count;i++)
|
||||
cmd_buf[i]=device->CreateRenderCommandBuffer(device->GetPhyDevice()->GetDeviceName()+AnsiString(":RenderCmdBuffer_")+AnsiString::numberOf(i));
|
||||
cmd_buf[i]=device->CreateRenderCommandBuffer(device->GetPhysicalDevice()->GetDeviceName()+AnsiString(":RenderCmdBuffer_")+AnsiString::numberOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,Framebuffer *fbo,Mesh *ri)
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,Framebuffer *fbo,Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
@ -238,7 +238,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(uint32_t index,Mesh *ri)
|
||||
bool BuildCommandBuffer(uint32_t index,Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
@ -246,7 +246,7 @@ public:
|
||||
sc_render_target->GetFramebuffer(),ri);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(Mesh *ri)
|
||||
bool BuildCommandBuffer(Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
@ -256,7 +256,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool BuildCurrentCommandBuffer(Mesh *ri)
|
||||
bool BuildCurrentCommandBuffer(Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
@ -346,6 +346,125 @@ 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=GetDoubleTime();
|
||||
}
|
||||
};
|
||||
|
||||
class CameraAppFramework:public VulkanApplicationFramework
|
||||
{
|
||||
protected:
|
||||
|
@ -80,15 +80,7 @@ namespace hgl
|
||||
|
||||
SwapchainWorkManager wm(&rf);
|
||||
|
||||
WO *wo=new WO(&rf);
|
||||
|
||||
if(!wo->Init())
|
||||
{
|
||||
delete wo;
|
||||
return(-2);
|
||||
}
|
||||
|
||||
wm.Run(wo);
|
||||
wm.Run(new WO(&rf));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,9 +2,6 @@
|
||||
#include<hgl/type/object/TickObject.h>
|
||||
#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>
|
||||
|
||||
@ -23,93 +20,74 @@ 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:
|
||||
|
||||
//以下数据均取自RenderFramework
|
||||
|
||||
graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代
|
||||
|
||||
graph::Scene * scene=nullptr; //场景
|
||||
graph::Renderer * renderer=nullptr; //渲染器
|
||||
|
||||
public:
|
||||
|
||||
graph::RenderFramework * GetRenderFramework (){return render_framework;}
|
||||
graph::VulkanDevice * GetDevice (){return render_framework->GetDevice();}
|
||||
graph::VulkanDevAttr * GetDevAttr (){return render_framework->GetDevAttr();}
|
||||
graph::TextureManager * GetTextureManager (){return render_framework->GetTextureManager();}
|
||||
graph::GPUDevice * GetDevice (){return render_framework->GetDevice();}
|
||||
graph::GPUDeviceAttribute * GetDeviceAttribute (){return render_framework->GetDeviceAttribute();}
|
||||
|
||||
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);}
|
||||
const VkExtent2D & GetExtent2D (){return cur_render_target->GetExtent();}
|
||||
|
||||
public:
|
||||
|
||||
const bool IsDestroy()const{return destroy_flag;}
|
||||
void MarkDestory(){destroy_flag=true;}
|
||||
|
||||
const bool IsRenderable()const{return renderable;}
|
||||
const bool IsRenderDirty()const{return render_dirty;}
|
||||
|
||||
void MarkDestory(){destroy_flag=true;}
|
||||
void SetRenderable(bool r){renderable=r;}
|
||||
void MarkRenderDirty(){render_dirty=true;}
|
||||
|
||||
public:
|
||||
|
||||
WorkObject(graph::RenderFramework *,graph::Renderer *r=nullptr);
|
||||
WorkObject(graph::RenderFramework *,graph::IRenderTarget *);
|
||||
virtual ~WorkObject()=default;
|
||||
|
||||
virtual bool Init()=0;
|
||||
|
||||
virtual void OnRendererChange(graph::RenderFramework *rf,graph::Renderer *r);
|
||||
virtual void OnRenderTargetSwitch(graph::RenderFramework *rf,graph::IRenderTarget *rt);
|
||||
|
||||
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:
|
||||
|
||||
#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;}
|
||||
template<typename ...ARGS>
|
||||
graph::Pipeline *CreatePipeline(ARGS...args)
|
||||
{
|
||||
return render_pass->CreatePipeline(args...);
|
||||
}
|
||||
|
||||
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>)
|
||||
|
||||
#undef WO_FUNC_FROM_RENDER_FRAMEWORK
|
||||
graph::MaterialInstance *CreateMaterialInstance(const graph::mtl::MaterialCreateInfo *mci,const graph::VILConfig *vil_cfg=nullptr)
|
||||
{
|
||||
return db->CreateMaterialInstance(mci,vil_cfg);
|
||||
}
|
||||
|
||||
graph::Primitive *CreatePrimitive( const AnsiString &name,
|
||||
const uint32_t vertices_count,
|
||||
const graph::VIL *vil,
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
|
||||
{
|
||||
return render_framework?render_framework->CreatePrimitive(name,vertices_count,vil,vad_list):nullptr;
|
||||
}
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
|
||||
|
||||
graph::Mesh *CreateMesh(const AnsiString &name,
|
||||
graph::Renderable *CreateRenderable(const AnsiString &name,
|
||||
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; //创建组件
|
||||
}
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
|
||||
};//class WorkObject
|
||||
|
||||
/**
|
||||
|
@ -1,178 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
#include<hgl/type/ArrayList.h>
|
||||
|
||||
/**
|
||||
* Component/Data/Manager 体系设计简要说明
|
||||
*
|
||||
* 本体系参考AMD FidelityFX,但并不完全一致。
|
||||
*
|
||||
* AMD FidelityFX中,Component存放于Entity下,而我方中与其类似的定义为SceneNode。
|
||||
* 不管是Entity还是SceneNode,它们都提供空间变换,以及子节点、Component的管理。
|
||||
* 而AMD FidelityFX中的Scene,类似于我方的Scene,用于储存一个场景世界的根节点及其它世界唯一数据。
|
||||
*
|
||||
* ComponentData是每个Component的数据,用于向Component或是其它模块提供数据。
|
||||
* ComponentManager是Component的管理器,用于管理Component的创建、销毁、更新等。
|
||||
*
|
||||
* 需要注意的是:同AMD FidelityFX一样,大部分ComponentManager与Scene基本无关。
|
||||
* 因为同样的数据可能出现在多个World之中。
|
||||
* 仅有那些与Scene密切相关的Component它对应的Manager才会出现在Scene中,比如CameraManager/LightManager。
|
||||
* 而如MeshComponent之类的纯资源型就会是独立存在的。
|
||||
*
|
||||
* Component是组件的基类,所有组件都从这里派生。
|
||||
*
|
||||
* SceneComponent是场景组件基类,只要是放在场景中的都从它派生,
|
||||
*
|
||||
* PrimitiveComponent是图元组件的基类,所有图元组件都从这里派生。
|
||||
* 它再度派生出的任何Component都必须是一个有3D空间的几何图元。
|
||||
* 引擎中的空间、物理、等都由PrimitiveComponent提供数据进行计算。
|
||||
|
||||
* RenderComponent是可渲染组件的基类,所有可渲染组件都从这里派生。
|
||||
*
|
||||
* MeshComponent是静态网格组件,它是一个具体的RenderComponent实现。
|
||||
*
|
||||
*/
|
||||
|
||||
#define COMPONENT_NAMESPACE hgl::graph
|
||||
#define COMPONENT_NAMESPACE_BEGIN namespace COMPONENT_NAMESPACE {
|
||||
#define COMPONENT_NAMESPACE_END }
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
class ComponentManager;
|
||||
class SceneNode;
|
||||
|
||||
struct ComponentData
|
||||
{
|
||||
public:
|
||||
|
||||
ComponentData()=default;
|
||||
virtual ~ComponentData()=default;
|
||||
};//struct ComponentData
|
||||
|
||||
using ComponentDataPtr=SharedPtr<ComponentData>;
|
||||
|
||||
/**
|
||||
* 基础组件<br>
|
||||
* 是一切组件的基类
|
||||
*/
|
||||
class Component
|
||||
{
|
||||
static uint unique_id_count;
|
||||
|
||||
uint unique_id;
|
||||
|
||||
SceneNode * OwnerNode;
|
||||
ComponentManager * Manager;
|
||||
ComponentDataPtr Data;
|
||||
|
||||
protected:
|
||||
|
||||
friend class ComponentManager;
|
||||
|
||||
virtual void OnDetachManager(ComponentManager *cm)
|
||||
{
|
||||
if(cm==Manager)
|
||||
Manager=nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Component()=delete;
|
||||
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;}
|
||||
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();
|
||||
|
||||
public:
|
||||
|
||||
virtual Component * CreateComponent(ComponentDataPtr)=0;
|
||||
|
||||
const size_t GetComponentCount()const{return component_set.GetCount();}
|
||||
|
||||
ComponentSet & GetComponents(){return component_set;}
|
||||
|
||||
int GetComponents(ComponentList &comp_list,SceneNode *);
|
||||
|
||||
virtual void UpdateComponents(const double delta_time);
|
||||
|
||||
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);
|
||||
|
||||
template<typename T> inline T *GetComponentManager(bool create_default=true)
|
||||
{
|
||||
T *cm=(T *)GetComponentManager(T::StaticHashCode());
|
||||
|
||||
if(!cm&&create_default)
|
||||
{
|
||||
cm=new T;
|
||||
|
||||
RegistryComponentManager(cm);
|
||||
}
|
||||
|
||||
return cm;
|
||||
}
|
||||
COMPONENT_NAMESPACE_END
|
@ -1,90 +0,0 @@
|
||||
#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
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/SceneComponent.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 图元组件<br>
|
||||
* 组件中的元素必须是一个可以明确描述的几何体,可以被明确标记尺寸、参与空间、物理计算等。
|
||||
*/
|
||||
class PrimitiveComponent:public SceneComponent
|
||||
{
|
||||
public:
|
||||
|
||||
using SceneComponent::SceneComponent;
|
||||
|
||||
virtual ~PrimitiveComponent()=default;
|
||||
};//class PrimitiveComponent
|
||||
|
||||
COMPONENT_NAMESPACE_END
|
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/PrimitiveComponent.h>
|
||||
|
||||
COMPONENT_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 可渲染组件
|
||||
*/
|
||||
class RenderComponent:public PrimitiveComponent
|
||||
{
|
||||
public:
|
||||
|
||||
using PrimitiveComponent::PrimitiveComponent;
|
||||
virtual ~RenderComponent()=default;
|
||||
};//class RenderComponent
|
||||
|
||||
COMPONENT_NAMESPACE_END
|
@ -1,31 +0,0 @@
|
||||
#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
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_DB_FIELD_TYPE_INCLUDE
|
||||
#define HGL_DB_FIELD_TYPE_INCLUDE
|
||||
|
||||
#include<hgl/type/ArrayList.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
namespace hgl
|
||||
{
|
||||
|
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/TypeFunc.h>
|
||||
namespace hgl::graph
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
enum class CoordinateSystem2D
|
||||
{
|
||||
@ -11,18 +13,5 @@ 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
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
*/
|
||||
class MaterialRenderList
|
||||
{
|
||||
VulkanDevice *device;
|
||||
GPUDevice *device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
|
||||
RenderPipelineIndex rp_index;
|
||||
@ -68,12 +68,12 @@ private:
|
||||
|
||||
MaterialInstance * mi;
|
||||
|
||||
const MeshDataBuffer * pdb;
|
||||
const MeshRenderData * prd;
|
||||
const PrimitiveDataBuffer * pdb;
|
||||
const PrimitiveRenderData * prd;
|
||||
|
||||
public:
|
||||
|
||||
void Set(Mesh *);
|
||||
void Set(Renderable *);
|
||||
};
|
||||
|
||||
IndirectDrawBuffer *icb_draw;
|
||||
@ -92,24 +92,24 @@ protected:
|
||||
|
||||
VABList * vab_list;
|
||||
|
||||
const MeshDataBuffer * last_data_buffer;
|
||||
const PrimitiveDataBuffer * last_data_buffer;
|
||||
const VDM * last_vdm;
|
||||
const MeshRenderData * last_render_data;
|
||||
const PrimitiveRenderData * last_render_data;
|
||||
|
||||
int first_indirect_draw_index;
|
||||
uint indirect_draw_count;
|
||||
int first_indirect_draw_index=-1;
|
||||
uint indirect_draw_count=0;
|
||||
|
||||
bool BindVAB(const MeshDataBuffer *,const uint);
|
||||
bool BindVAB(const PrimitiveDataBuffer *,const uint);
|
||||
|
||||
void ProcIndirectRender();
|
||||
bool Render(RenderItem *);
|
||||
void Render(RenderItem *);
|
||||
|
||||
public:
|
||||
|
||||
MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi);
|
||||
MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi);
|
||||
~MaterialRenderList();
|
||||
|
||||
void Add(MeshComponent *);
|
||||
void Add(SceneNode *);
|
||||
|
||||
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
|
||||
|
||||
@ -120,6 +120,6 @@ public:
|
||||
void Render(RenderCmdBuffer *);
|
||||
|
||||
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
|
||||
void UpdateMaterialInstance(MeshComponent *);
|
||||
void UpdateMaterialInstance(SceneNode *);
|
||||
};//class MaterialRenderList
|
||||
VK_NAMESPACE_END
|
||||
|
@ -13,7 +13,7 @@ class PrimitiveCreater
|
||||
{
|
||||
protected:
|
||||
|
||||
VulkanDevice * device;
|
||||
GPUDevice * device;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
const VIL * vil;
|
||||
@ -36,7 +36,7 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveCreater(VulkanDevice *,const VIL *);
|
||||
PrimitiveCreater(GPUDevice *,const VIL *);
|
||||
PrimitiveCreater(VertexDataManager *);
|
||||
virtual ~PrimitiveCreater();
|
||||
|
||||
|
@ -6,11 +6,6 @@
|
||||
#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
|
||||
|
||||
@ -22,12 +17,6 @@ class RenderTargetManager;
|
||||
|
||||
class RenderModule;
|
||||
|
||||
class Scene;
|
||||
class Renderer;
|
||||
|
||||
class CameraComponentManager{/*现阶段测试使用*/};
|
||||
class LightComponentManager{/*现阶段测试使用*/};
|
||||
|
||||
class RenderFramework:public io::WindowEvent
|
||||
{
|
||||
OSString app_name;
|
||||
@ -35,7 +24,7 @@ class RenderFramework:public io::WindowEvent
|
||||
Window * win =nullptr;
|
||||
VulkanInstance * inst =nullptr;
|
||||
|
||||
VulkanDevice * device =nullptr;
|
||||
GPUDevice * device =nullptr;
|
||||
|
||||
RenderResource * render_resource =nullptr;
|
||||
|
||||
@ -50,31 +39,13 @@ protected:
|
||||
|
||||
SwapchainModule * sc_module =nullptr;
|
||||
|
||||
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;}
|
||||
GPUDevice * GetDevice ()const{return device;}
|
||||
VkDevice GetVkDevice ()const{return device->GetDevice();}
|
||||
const VulkanPhyDevice * GetPhyDevice ()const{return device->GetPhyDevice();}
|
||||
VulkanDevAttr * GetDevAttr ()const{return device->GetDevAttr();}
|
||||
const GPUPhysicalDevice * GetPhysicalDevice ()const{return device->GetPhysicalDevice();}
|
||||
GPUDeviceAttribute * GetDeviceAttribute ()const{return device->GetDeviceAttribute();}
|
||||
|
||||
RenderResource * GetRenderResource ()const{return render_resource;}
|
||||
|
||||
@ -89,26 +60,6 @@ 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 &);
|
||||
@ -116,18 +67,8 @@ public:
|
||||
|
||||
virtual bool Init(uint w,uint h);
|
||||
|
||||
public: // event
|
||||
|
||||
virtual void OnResize(uint w,uint h);
|
||||
virtual void OnActive(bool);
|
||||
virtual void OnClose();
|
||||
|
||||
public:
|
||||
|
||||
void Tick();
|
||||
|
||||
public: // other
|
||||
|
||||
RenderList *CreateRenderList()
|
||||
{
|
||||
return(new RenderList(device));
|
||||
@ -135,139 +76,12 @@ public: // other
|
||||
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建只使用一种字符的Tile字符管理对象
|
||||
|
||||
public:
|
||||
public: // event
|
||||
|
||||
template<typename ...ARGS>
|
||||
graph::Pipeline *CreatePipeline(ARGS...args)
|
||||
{
|
||||
return GetDefaultRenderPass()->CreatePipeline(args...);
|
||||
}
|
||||
virtual void OnResize(uint w,uint h);
|
||||
virtual void OnActive(bool);
|
||||
virtual void OnClose();
|
||||
|
||||
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()
|
||||
{
|
||||
return COMPONENT_NAMESPACE::GetComponentManager<T>(true);
|
||||
}
|
||||
|
||||
template<> CameraComponentManager *GetComponentManager<CameraComponentManager>()
|
||||
{
|
||||
return camera_component_manager;
|
||||
}
|
||||
|
||||
template<> LightComponentManager *GetComponentManager<LightComponentManager>()
|
||||
{
|
||||
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
|
||||
|
@ -18,7 +18,7 @@ namespace hgl
|
||||
{
|
||||
protected:
|
||||
|
||||
VulkanDevice * device;
|
||||
GPUDevice * device;
|
||||
|
||||
CameraInfo * camera_info; ///<相机信息
|
||||
|
||||
@ -31,22 +31,16 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
const CameraInfo *GetCameraInfo()const{return camera_info;}
|
||||
|
||||
public:
|
||||
|
||||
RenderList(VulkanDevice *);
|
||||
RenderList(GPUDevice *);
|
||||
virtual ~RenderList()=default;
|
||||
|
||||
virtual void SetCameraInfo(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
|
||||
virtual void SetCamera(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(MeshComponent *); ///<有对象互换了材质实例
|
||||
virtual void UpdateMaterialInstance(SceneNode *); ///<有对象互换了材质实例
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
};//class RenderList
|
||||
|
@ -1,21 +1,21 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
#define HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Mesh;
|
||||
class Renderable;
|
||||
class MaterialInstance;
|
||||
class MeshComponent;
|
||||
class SceneNode;
|
||||
|
||||
struct RenderNode:public Comparator<RenderNode>
|
||||
{
|
||||
uint index; ///<在MaterialRenderList中的索引
|
||||
|
||||
MeshComponent *sm_component; ///<静态网格组件
|
||||
SceneNode * scene_node;
|
||||
|
||||
uint32 l2w_version;
|
||||
uint32 l2w_index;
|
||||
@ -27,15 +27,10 @@ namespace hgl
|
||||
|
||||
//该函数位于MaterialRenderList.cpp
|
||||
const int compare(const RenderNode &)const override;
|
||||
|
||||
public:
|
||||
|
||||
Mesh *GetMesh()const;
|
||||
MaterialInstance *GetMaterialInstance()const;
|
||||
};
|
||||
|
||||
using RenderNodeList=ArrayList<RenderNode>;
|
||||
using RenderNodePointerList=ArrayList<RenderNode *>;
|
||||
using RenderNodeList=List<RenderNode>;
|
||||
using RenderNodePointerList=List<RenderNode *>;
|
||||
|
||||
using MaterialInstanceSets=SortedSet<MaterialInstance *>; ///<材质实例集合
|
||||
}//namespace graph
|
||||
@ -45,3 +40,4 @@ namespace hgl
|
||||
return a.compare(b);
|
||||
}
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
@ -1,44 +0,0 @@
|
||||
#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
|
@ -1,57 +0,0 @@
|
||||
#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
|
@ -1,50 +0,0 @@
|
||||
#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
|
31
inc/hgl/graph/SceneManager.h
Normal file
31
inc/hgl/graph/SceneManager.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 场景管理器<Br>
|
||||
* 管理一个场景中的所有资源与场景节点
|
||||
*/
|
||||
class SceneManager
|
||||
{
|
||||
SceneNode *root_node;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
SceneNode *GetSceneRoot() {return root_node;}
|
||||
const SceneNode *GetSceneRoot()const{return root_node;}
|
||||
|
||||
const uint GetNodeCount()const { return node_list.GetCount(); }
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
};//class SceneManager
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/type/IDName.h>
|
||||
#include<hgl/graph/SceneOrient.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
#include<hgl/component/Component.h>
|
||||
|
||||
namespace hgl::graph
|
||||
namespace hgl
|
||||
{
|
||||
using SceneNodeID =int64;
|
||||
|
||||
using SceneNodeList =ObjectList<SceneNode>;
|
||||
|
||||
HGL_DEFINE_U16_IDNAME(SceneNodeName)
|
||||
namespace graph
|
||||
{
|
||||
using SceneNodeID =uint64;
|
||||
using SceneNodeName =U16IDName;
|
||||
|
||||
/**
|
||||
* 场景节点数据类<br>
|
||||
@ -21,33 +19,29 @@ namespace hgl::graph
|
||||
*/
|
||||
class SceneNode:public SceneOrient ///场景节点类
|
||||
{
|
||||
SceneNode *parent_node=nullptr; ///<上级节点
|
||||
SceneNode *Owner; ///<上级节点
|
||||
|
||||
SceneNodeID node_id=-1; ///<节点ID
|
||||
SceneNodeName node_name; ///<节点名称
|
||||
SceneNodeID NodeID; ///<节点ID
|
||||
SceneNodeName NodeName; ///<节点名称
|
||||
|
||||
protected:
|
||||
|
||||
AABB bounding_box; ///<绑定盒
|
||||
AABB local_bounding_box; ///<本地坐标绑定盒
|
||||
AABB BoundingBox; ///<绑定盒
|
||||
AABB LocalBoundingBox; ///<本地坐标绑定盒
|
||||
//AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
|
||||
Renderable *render_obj=nullptr; ///<可渲染实例
|
||||
|
||||
protected:
|
||||
|
||||
SceneNodeList child_nodes; ///<子节点
|
||||
|
||||
/**
|
||||
* 组件合集,一个SceneNode下可能会包含多个组件,同时一个组件也可能被多个SceneNode使用。
|
||||
* 所以这里只保留一个指针,不拥有组件的生命周期,组件的生命周期由其对应的ComponentManager管理。
|
||||
*/
|
||||
ComponentSet component_set; ///<组件合集
|
||||
ObjectList<SceneNode> ChildNode; ///<子节点
|
||||
|
||||
public:
|
||||
|
||||
const SceneNodeID & GetNodeID ()const { return node_id; } ///<取得节点ID
|
||||
const SceneNodeName & GetNodeName ()const { return node_name; } ///<取得节点名称
|
||||
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
|
||||
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
|
||||
|
||||
const SceneNodeList & GetChildNode()const { return child_nodes; } ///<取得子节点列表
|
||||
const ObjectList<SceneNode> &GetChildNode()const { return ChildNode; } ///<取得子节点列表
|
||||
|
||||
public:
|
||||
|
||||
@ -55,88 +49,66 @@ namespace hgl::graph
|
||||
SceneNode(const SceneNode &)=delete;
|
||||
SceneNode(const SceneNode *)=delete;
|
||||
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
|
||||
SceneNode( Renderable *ri ) {render_obj=ri;}
|
||||
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
||||
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
||||
|
||||
public:
|
||||
|
||||
virtual ~SceneNode();
|
||||
virtual ~SceneNode()=default;
|
||||
|
||||
void Clear() override
|
||||
{
|
||||
SceneOrient::Clear();
|
||||
|
||||
parent_node=nullptr;
|
||||
Owner=nullptr;
|
||||
|
||||
bounding_box.SetZero();
|
||||
local_bounding_box.SetZero();
|
||||
BoundingBox.SetZero();
|
||||
LocalBoundingBox.SetZero();
|
||||
|
||||
child_nodes.Clear();
|
||||
component_set.Clear();
|
||||
ChildNode.Clear();
|
||||
render_obj=nullptr;
|
||||
}
|
||||
|
||||
const bool ChildNodeIsEmpty()const
|
||||
const bool IsEmpty()const
|
||||
{
|
||||
if(child_nodes.GetCount())return(false);
|
||||
if(render_obj)return(false);
|
||||
if(ChildNode.GetCount())return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void SetParent(SceneNode *sn) {parent_node=sn;}
|
||||
SceneNode * GetParent() noexcept{return parent_node;}
|
||||
const SceneNode * GetParent()const noexcept{return parent_node;}
|
||||
void SetOwner(SceneNode *sn) {Owner=sn;}
|
||||
SceneNode * GetOwner() noexcept{return Owner;}
|
||||
const SceneNode * GetOwner()const noexcept{return Owner;}
|
||||
|
||||
void SetRenderable(Renderable *);
|
||||
Renderable *GetRenderable() noexcept{return render_obj;}
|
||||
const Renderable *GetRenderable()const noexcept{return render_obj;}
|
||||
|
||||
SceneNode *Add(SceneNode *sn)
|
||||
{
|
||||
if(!sn)
|
||||
return(nullptr);
|
||||
|
||||
child_nodes.Add(sn);
|
||||
sn->SetParent(this);
|
||||
ChildNode.Add(sn);
|
||||
sn->SetOwner(this);
|
||||
return sn;
|
||||
}
|
||||
|
||||
public: //坐标相关方法
|
||||
|
||||
virtual void SetBoundingBox (const AABB &bb){bounding_box=bb;} ///<设置绑定盒
|
||||
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
|
||||
|
||||
virtual void RefreshMatrix () override; ///<刷新世界变换
|
||||
virtual void RefreshBoundingBox (); ///<刷新绑定盒
|
||||
|
||||
virtual const AABB & GetBoundingBox ()const{return bounding_box;} ///<取得绑定盒
|
||||
virtual const AABB & GetLocalBoundingBox ()const{return local_bounding_box;} ///<取得本地坐标绑定盒
|
||||
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
|
||||
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
|
||||
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||
|
||||
public: //组件相关方法
|
||||
|
||||
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 (ComponentList &comp_list,const ComponentManager *); ///<取得所有组件
|
||||
|
||||
const ComponentSet &GetComponents ()const{return component_set;}
|
||||
};//class SceneNode
|
||||
|
||||
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点
|
||||
}//namespace hgl::graph
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
|
@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/SceneMatrix.h>
|
||||
namespace hgl::graph
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 方向定位数据基类<br>
|
||||
@ -46,4 +49,6 @@ namespace hgl::graph
|
||||
|
||||
virtual void RefreshMatrix();
|
||||
};//class SceneOrient
|
||||
}//namespace hgl::graph
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
|
46
inc/hgl/graph/StaticMesh.h
Normal file
46
inc/hgl/graph/StaticMesh.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<hgl/graph/StaticMeshLODPolicy.h>
|
||||
#include<hgl/graph/ShadowPolicy.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class SceneNode;
|
||||
|
||||
class StaticMesh
|
||||
{
|
||||
protected:
|
||||
|
||||
StaticMeshLODPolicy lod_policy; ///<LOD策略
|
||||
|
||||
SceneNode *root_node;
|
||||
|
||||
StaticMesh *shadow_proxy_static_mesh; ///<阴影代理静态网格
|
||||
StaticMesh *physic_proxy_static_mesh; ///<物理代理静态网格
|
||||
|
||||
protected:
|
||||
|
||||
bool two_side; ///<双面渲染
|
||||
|
||||
ObjectDynamicShadowPolicy recommend_dynamic_shadow_policy; ///<动态阴影策略(推荐项,最终可被取代)
|
||||
|
||||
public:
|
||||
|
||||
const StaticMeshLODPolicy GetLODPolicy()const { return lod_policy; } ///<取得LOD策略
|
||||
const ObjectDynamicShadowPolicy GetRecommendDynamicShadowPolicy()const { return recommend_dynamic_shadow_policy; } ///<取得推荐的动态阴影策略
|
||||
|
||||
public:
|
||||
|
||||
StaticMesh(SceneNode *);
|
||||
virtual ~StaticMesh();
|
||||
|
||||
public:
|
||||
|
||||
SceneNode *GetScene(){return root_node;}
|
||||
|
||||
SceneNode *GetShadowNode() { return shadow_proxy_static_mesh?shadow_proxy_static_mesh->GetScene():root_node; } ///<取得阴影渲染节点
|
||||
SceneNode *GetPhysicNode() { return physic_proxy_static_mesh?physic_proxy_static_mesh->GetScene():root_node; } ///<取得物理渲染节点
|
||||
|
||||
};//class StaticMesh
|
||||
VK_NAMESPACE_END
|
30
inc/hgl/graph/StaticMeshLODPolicy.h
Normal file
30
inc/hgl/graph/StaticMeshLODPolicy.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<hgl/TypeFunc.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 静态模型LOD策略
|
||||
*/
|
||||
enum class StaticMeshLODPolicy:uint8
|
||||
{
|
||||
None=0, ///<无LOD
|
||||
|
||||
DiscardDetail, ///<丢弃细节
|
||||
|
||||
AnotherMesh, ///<另一个模型
|
||||
|
||||
Billboard, ///<广告牌
|
||||
|
||||
//Voxel, ///<体素
|
||||
|
||||
//MeshSDF, ///<网格SDF
|
||||
|
||||
//MeshCard, ///<网格卡片
|
||||
|
||||
ENUM_CLASS_RANGE(None,Billboard)
|
||||
};//enum class StaticMeshLODPolicy
|
||||
|
||||
VK_NAMESPACE_END
|
25
inc/hgl/graph/StaticRenderManager.h
Normal file
25
inc/hgl/graph/StaticRenderManager.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
||||
#define HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class RawMesh
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* 静态渲染管理器<br>
|
||||
* 静态渲染指的是不会产生资源变动的内容,而不是指不会动的内容。
|
||||
*/
|
||||
class StaticRenderManager
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual ~StaticRenderManager()=default;
|
||||
|
||||
};//class StaticRenderManager
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
@ -37,7 +37,7 @@ namespace hgl
|
||||
|
||||
DeviceBuffer *tile_buffer; ///<Tile暂存缓冲区
|
||||
|
||||
ArrayList<Image2DRegion> commit_list;
|
||||
List<Image2DRegion> commit_list;
|
||||
uint8 *commit_ptr;
|
||||
|
||||
bool CommitTile(TileObject *,const void *,const uint,const int,const int); ///<提交一个Tile数据
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/ArrayList.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/Map.h>
|
||||
@ -41,9 +41,9 @@ class GraphModule;
|
||||
class RenderFramework;
|
||||
|
||||
class VulkanInstance;
|
||||
class VulkanPhyDevice;
|
||||
class VulkanDevice;
|
||||
struct VulkanDevAttr;
|
||||
class GPUPhysicalDevice;
|
||||
class GPUDevice;
|
||||
struct GPUDeviceAttribute;
|
||||
class DeviceQueue;
|
||||
class ImageView;
|
||||
class Framebuffer;
|
||||
@ -73,8 +73,8 @@ class DeviceBuffer;
|
||||
struct DeviceBufferData;
|
||||
template<typename T> class DeviceBufferMap;
|
||||
|
||||
struct MeshDataBuffer;
|
||||
struct MeshRenderData;
|
||||
struct PrimitiveDataBuffer;
|
||||
struct PrimitiveRenderData;
|
||||
|
||||
class VertexAttribBuffer;
|
||||
using VAB=VertexAttribBuffer;
|
||||
@ -84,7 +84,7 @@ class IndexBuffer;
|
||||
class VABMap;
|
||||
class IBMap;
|
||||
|
||||
class VulkanCmdBuffer;
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
class TextureCmdBuffer;
|
||||
|
||||
@ -96,7 +96,6 @@ class Semaphore;
|
||||
|
||||
struct PipelineLayoutData;
|
||||
class DescriptorSet;
|
||||
enum class DescriptorSetType;
|
||||
|
||||
struct VertexInputAttribute;
|
||||
|
||||
@ -124,7 +123,7 @@ using VIL=VertexInputLayout;
|
||||
|
||||
class PrimitiveData;
|
||||
class Primitive;
|
||||
class Mesh;
|
||||
class Renderable;
|
||||
|
||||
class VertexDataManager;
|
||||
using VDM=VertexDataManager;
|
||||
@ -135,16 +134,7 @@ class IndirectDispatchBuffer;
|
||||
|
||||
class RenderResource;
|
||||
|
||||
class MeshComponent;
|
||||
|
||||
class SceneNode;
|
||||
class Scene;
|
||||
class RenderList;
|
||||
|
||||
struct CameraInfo;
|
||||
struct Camera;
|
||||
|
||||
class Renderer;
|
||||
class StaticMesh;
|
||||
|
||||
enum class SharingMode
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDynamicBufferAccess.h>
|
||||
@ -14,7 +15,7 @@ namespace hgl
|
||||
* GPU数据阵列缓冲区<br>
|
||||
* 它用于储存多份相同格式的数据,常用于多物件渲染,instance等
|
||||
*/
|
||||
class VulkanArrayBuffer
|
||||
class GPUArrayBuffer
|
||||
{
|
||||
protected:
|
||||
|
||||
@ -32,13 +33,13 @@ namespace hgl
|
||||
|
||||
private:
|
||||
|
||||
VulkanArrayBuffer(VKMemoryAllocator *,const uint,const uint);
|
||||
GPUArrayBuffer(VKMemoryAllocator *,const uint,const uint);
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~VulkanArrayBuffer();
|
||||
virtual ~GPUArrayBuffer();
|
||||
|
||||
const uint32_t GetAlignSize()const{return align_size;} ///<数据对齐字节数
|
||||
const uint32_t GetRangeSize()const{return range_size;} ///<单次渲染访问最大字节数
|
||||
@ -70,6 +71,7 @@ namespace hgl
|
||||
|
||||
dba->Restart();
|
||||
}
|
||||
};//class VulkanArrayBuffer
|
||||
};//class GPUArrayBuffer
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKMemory.h>
|
||||
#include<hgl/graph/mtl/ShaderBufferSource.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct DeviceBufferData
|
||||
@ -21,7 +20,7 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
friend class VertexAttribBuffer;
|
||||
friend class IndexBuffer;
|
||||
template<typename T> friend class IndirectCommandBuffer;
|
||||
@ -54,8 +53,6 @@ public:
|
||||
|
||||
template<typename T> class DeviceBufferMap
|
||||
{
|
||||
protected:
|
||||
|
||||
DeviceBuffer *dev_buf;
|
||||
T data_map;
|
||||
|
||||
@ -78,7 +75,7 @@ public:
|
||||
delete dev_buf;
|
||||
}
|
||||
|
||||
DeviceBuffer *GetDeviceBuffer(){return dev_buf;}
|
||||
operator DeviceBuffer *(){return dev_buf;}
|
||||
|
||||
T *data(){return &data_map;}
|
||||
|
||||
@ -87,32 +84,6 @@ 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
|
||||
|
@ -22,7 +22,6 @@ public:
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
stride=count=0;
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
virtual ~VKBufferMap()
|
||||
@ -30,7 +29,7 @@ public:
|
||||
Unmap();
|
||||
}
|
||||
|
||||
void Bind(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
|
||||
void Set(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
|
||||
{
|
||||
buffer=buf;
|
||||
offset=off;
|
||||
|
@ -1,17 +1,18 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKVABList.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VulkanCmdBuffer
|
||||
class GPUCmdBuffer
|
||||
{
|
||||
protected:
|
||||
|
||||
const VulkanDevAttr *dev_attr;
|
||||
const GPUDeviceAttribute *dev_attr;
|
||||
|
||||
VkCommandBuffer cmd_buf;
|
||||
|
||||
@ -19,8 +20,8 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
VulkanCmdBuffer(const VulkanDevAttr *attr,VkCommandBuffer cb);
|
||||
virtual ~VulkanCmdBuffer();
|
||||
GPUCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb);
|
||||
virtual ~GPUCmdBuffer();
|
||||
|
||||
operator VkCommandBuffer(){return cmd_buf;}
|
||||
operator const VkCommandBuffer()const{return cmd_buf;}
|
||||
@ -47,14 +48,11 @@ public:
|
||||
void BeginRegion(const AnsiString &,const Color4f &){}
|
||||
void EndRegion(){}
|
||||
#endif//_DEBUG
|
||||
};//class VulkanCmdBuffer
|
||||
};//class GPUCmdBuffer
|
||||
|
||||
class DescriptorBinding;
|
||||
|
||||
using DescriptorBindingPtr=DescriptorBinding *;
|
||||
using DescriptorBindingPtrArray=DescriptorBindingPtr[size_t(DescriptorSetType::RANGE_SIZE)];
|
||||
|
||||
class RenderCmdBuffer:public VulkanCmdBuffer
|
||||
class RenderCmdBuffer:public GPUCmdBuffer
|
||||
{
|
||||
uint32_t cv_count;
|
||||
VkClearValue *clear_values;
|
||||
@ -64,14 +62,7 @@ class RenderCmdBuffer:public VulkanCmdBuffer
|
||||
RenderPassBeginInfo rp_begin;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
/*
|
||||
* 绝大部分desc绑定会全部使用这些自动绑定器绑定
|
||||
* 该数据在渲染前分别会有各自的模块设置进来
|
||||
* 比如
|
||||
* DescriptSetType::RenderTarget 即该由RenderTarget模块设置
|
||||
* DescriptSetType::Scene 的自然由Scene模块设置
|
||||
*/
|
||||
DescriptorBindingPtrArray desc_binding{};
|
||||
DescriptorBinding *desc_binding=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
@ -79,16 +70,16 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
RenderCmdBuffer(const VulkanDevAttr *attr,VkCommandBuffer cb);
|
||||
RenderCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb);
|
||||
~RenderCmdBuffer();
|
||||
|
||||
bool SetDescriptorBinding(DescriptorBinding *);
|
||||
void SetDescriptorBinding(DescriptorBinding *db) { desc_binding=db; }
|
||||
|
||||
bool End() override
|
||||
{
|
||||
hgl_zero(desc_binding);
|
||||
desc_binding=nullptr;
|
||||
|
||||
return VulkanCmdBuffer::End();
|
||||
return GPUCmdBuffer::End();
|
||||
}
|
||||
|
||||
void SetRenderArea(const VkRect2D &ra){render_area=ra;}
|
||||
@ -212,7 +203,7 @@ public:
|
||||
|
||||
void BindIBO(IndexBuffer *,const VkDeviceSize byte_offset=0);
|
||||
|
||||
bool BindDataBuffer(const MeshDataBuffer *);
|
||||
bool BindDataBuffer(const PrimitiveDataBuffer *);
|
||||
|
||||
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
|
||||
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
|
||||
@ -249,13 +240,13 @@ public: //draw
|
||||
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);}
|
||||
void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
|
||||
|
||||
void Draw (const MeshDataBuffer *prb,const MeshRenderData *prd,const uint32_t instance_count=1,const uint32_t first_instance=0);
|
||||
void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd,const uint32_t instance_count=1,const uint32_t first_instance=0);
|
||||
|
||||
public: //dynamic state
|
||||
|
||||
public:
|
||||
|
||||
void Render(Mesh *ri)
|
||||
void Render(Renderable *ri)
|
||||
{
|
||||
if(!ri)return;
|
||||
|
||||
@ -265,15 +256,15 @@ public:
|
||||
|
||||
Draw(ri->GetDataBuffer(),ri->GetRenderData());
|
||||
}
|
||||
};//class RenderCmdBuffer:public VulkanCmdBuffer
|
||||
};//class RenderCmdBuffer:public GPUCmdBuffer
|
||||
|
||||
class TextureCmdBuffer:public VulkanCmdBuffer
|
||||
class TextureCmdBuffer:public GPUCmdBuffer
|
||||
{
|
||||
VkImageMemoryBarrier imageMemoryBarrier;
|
||||
|
||||
public:
|
||||
|
||||
TextureCmdBuffer(const VulkanDevAttr *attr,VkCommandBuffer cb):VulkanCmdBuffer(attr,cb)
|
||||
TextureCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb):GPUCmdBuffer(attr,cb)
|
||||
{
|
||||
imageMemoryBarrier.sType=VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
imageMemoryBarrier.pNext=nullptr;
|
||||
@ -310,5 +301,6 @@ public:
|
||||
0, nullptr,
|
||||
1, &imageMemoryBarrier);
|
||||
}
|
||||
};//class TextureCmdBuffer:public VulkanCmdBuffer
|
||||
};//class TextureCmdBuffer:public GPUCmdBuffer
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -23,10 +24,6 @@ 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)
|
||||
@ -42,35 +39,11 @@ 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 GetObjectFromMap(ubo_map,name);
|
||||
return GetObjectFromList(ubo_map,name);
|
||||
}
|
||||
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
@ -88,17 +61,11 @@ 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 GetObjectFromMap(ssbo_map,name);
|
||||
return GetObjectFromList(ssbo_map,name);
|
||||
}
|
||||
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
@ -120,7 +87,7 @@ public:
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetObjectFromMap(texture_map,name);
|
||||
return GetObjectFromList(texture_map,name);
|
||||
}
|
||||
|
||||
void RemoveTexture(Texture *tex)
|
||||
|
@ -18,7 +18,7 @@ class DescriptorSet
|
||||
|
||||
ObjectList<VkDescriptorBufferInfo> vab_list;
|
||||
ObjectList<VkDescriptorImageInfo> image_list;
|
||||
ArrayList<VkWriteDescriptorSet> wds_list;
|
||||
List<VkWriteDescriptorSet> wds_list;
|
||||
|
||||
SortedSet<uint32_t> binded_sets;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_VULKAN_DEVICE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DEVICE_INCLUDE
|
||||
|
||||
#include<hgl/type/ArrayList.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
@ -20,16 +21,16 @@ VK_NAMESPACE_BEGIN
|
||||
class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
class VulkanArrayBuffer;
|
||||
class GPUArrayBuffer;
|
||||
class IndirectDrawBuffer;
|
||||
class IndirectDrawIndexedBuffer;
|
||||
class IndirectDispatchBuffer;
|
||||
|
||||
struct CopyBufferToImageInfo;
|
||||
|
||||
class VulkanDevice
|
||||
class GPUDevice
|
||||
{
|
||||
VulkanDevAttr *attr;
|
||||
GPUDeviceAttribute *attr;
|
||||
|
||||
private:
|
||||
|
||||
@ -39,18 +40,18 @@ private:
|
||||
|
||||
friend class VulkanDeviceCreater;
|
||||
|
||||
VulkanDevice(VulkanDevAttr *da);
|
||||
GPUDevice(GPUDeviceAttribute *da);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~VulkanDevice();
|
||||
virtual ~GPUDevice();
|
||||
|
||||
operator VkDevice () {return attr->device;}
|
||||
VulkanDevAttr * GetDevAttr () {return attr;}
|
||||
GPUDeviceAttribute *GetDeviceAttribute () {return attr;}
|
||||
|
||||
VkSurfaceKHR GetSurface () {return attr->surface;}
|
||||
VkDevice GetDevice ()const {return attr->device;}
|
||||
const VulkanPhyDevice * GetPhyDevice ()const {return attr->physical_device;}
|
||||
const GPUPhysicalDevice * GetPhysicalDevice ()const {return attr->physical_device;}
|
||||
|
||||
VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;}
|
||||
VkPipelineCache GetPipelineCache () {return attr->pipeline_cache;}
|
||||
@ -123,18 +124,6 @@ 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)
|
||||
@ -143,8 +132,8 @@ public: //Buffer相关
|
||||
|
||||
#undef CREATE_BUFFER_OBJECT
|
||||
|
||||
VulkanArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
||||
VulkanArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
||||
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
||||
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
||||
|
||||
public: //间接绘制
|
||||
|
||||
@ -184,5 +173,6 @@ public:
|
||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
|
||||
};//class VulkanDevice
|
||||
};//class GPUDevice
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE
|
||||
|
@ -11,10 +11,10 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
constexpr uint32_t ERROR_FAMILY_INDEX=UINT32_MAX;
|
||||
|
||||
struct VulkanDevAttr
|
||||
struct GPUDeviceAttribute
|
||||
{
|
||||
VulkanInstance * instance =nullptr;
|
||||
const VulkanPhyDevice * physical_device =nullptr;
|
||||
const GPUPhysicalDevice * physical_device =nullptr;
|
||||
|
||||
VkPhysicalDeviceDriverPropertiesKHR driver_properties;
|
||||
|
||||
@ -34,7 +34,7 @@ struct VulkanDevAttr
|
||||
VkQueue present_queue =VK_NULL_HANDLE;
|
||||
|
||||
VkSurfaceFormatKHR surface_format;
|
||||
ArrayList<VkPresentModeKHR> present_modes;
|
||||
List<VkPresentModeKHR> present_modes;
|
||||
|
||||
VkSurfaceTransformFlagBitsKHR preTransform;
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
@ -55,8 +55,8 @@ struct VulkanDevAttr
|
||||
|
||||
public:
|
||||
|
||||
VulkanDevAttr(VulkanInstance *inst,const VulkanPhyDevice *pd,VkSurfaceKHR s);
|
||||
~VulkanDevAttr();
|
||||
GPUDeviceAttribute(VulkanInstance *inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s);
|
||||
~GPUDeviceAttribute();
|
||||
|
||||
int GetMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties) const;
|
||||
|
||||
@ -75,5 +75,5 @@ public:
|
||||
{
|
||||
return instance->GetDeviceProc<T>(device,name);
|
||||
}
|
||||
};//class VulkanDevAttr
|
||||
};//class GPUDeviceAttribute
|
||||
VK_NAMESPACE_END
|
||||
|
@ -238,7 +238,7 @@ protected:
|
||||
|
||||
VulkanInstance *instance;
|
||||
Window *window;
|
||||
const VulkanPhyDevice *physical_device;
|
||||
const GPUPhysicalDevice *physical_device;
|
||||
|
||||
VulkanHardwareRequirement require;
|
||||
|
||||
@ -274,14 +274,14 @@ public:
|
||||
|
||||
virtual void ChooseSurfaceFormat();
|
||||
|
||||
virtual VulkanDevice *CreateRenderDevice();
|
||||
virtual GPUDevice *CreateRenderDevice();
|
||||
|
||||
public:
|
||||
|
||||
virtual VulkanDevice *Create();
|
||||
virtual GPUDevice *Create();
|
||||
};//class VulkanDeviceCreater
|
||||
|
||||
inline VulkanDevice *CreateRenderDevice( VulkanInstance *vi,
|
||||
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr,
|
||||
const PreferFormats * spf_color =&PreferSDR,
|
||||
@ -293,35 +293,35 @@ inline VulkanDevice *CreateRenderDevice( VulkanInstance *vi,
|
||||
return vdc.Create();
|
||||
}
|
||||
|
||||
inline VulkanDevice *CreateRenderDeviceLDR(VulkanInstance *vi,
|
||||
inline GPUDevice *CreateRenderDeviceLDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferLDR,&PreferNonlinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline VulkanDevice *CreateRenderDeviceSDR(VulkanInstance *vi,
|
||||
inline GPUDevice *CreateRenderDeviceSDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferSDR,&PreferNonlinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline VulkanDevice *CreateRenderDeviceHDR16( VulkanInstance *vi,
|
||||
inline GPUDevice *CreateRenderDeviceHDR16( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR16,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline VulkanDevice *CreateRenderDeviceHDR32( VulkanInstance *vi,
|
||||
inline GPUDevice *CreateRenderDeviceHDR32( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,req,&PreferHDR32,&PreferLinear,&PreferDepth);
|
||||
}
|
||||
|
||||
inline VulkanDevice *CreateRenderDeviceHDR(VulkanInstance *vi,
|
||||
inline GPUDevice *CreateRenderDeviceHDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ private:
|
||||
index=0;
|
||||
}
|
||||
|
||||
friend class VulkanArrayBuffer;
|
||||
friend class GPUArrayBuffer;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -10,7 +10,7 @@ class Fence
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
Fence(VkDevice d,VkFence f)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ class IndexBuffer:public DeviceBuffer
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
IndexBuffer(VkDevice d,const DeviceBufferData &vb,IndexType it,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
@ -54,7 +54,7 @@ public:
|
||||
|
||||
void SetIBO(IndexBuffer *ib,const int32_t index_offset,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<IndexBuffer>::Bind(ib,index_offset,ib->GetStride(),count);
|
||||
VKBufferMap<IndexBuffer>::Set(ib,index_offset,ib->GetStride(),count);
|
||||
}
|
||||
};//class IBMap
|
||||
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
IndirectCommandBuffer(VkDevice d,const DeviceBufferData &vb,const uint32_t mc):DeviceBuffer(d,vb)
|
||||
{
|
||||
@ -46,7 +46,7 @@ public:
|
||||
|
||||
class IndirectDrawBuffer:public IndirectCommandBuffer<VkDrawIndirectCommand>
|
||||
{
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
@ -64,7 +64,7 @@ public:
|
||||
|
||||
class IndirectDrawIndexedBuffer:public IndirectCommandBuffer<VkDrawIndexedIndirectCommand>
|
||||
{
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
@ -82,7 +82,7 @@ public:
|
||||
|
||||
class IndirectDispatchBuffer:public IndirectCommandBuffer<VkDispatchIndirectCommand>
|
||||
{
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -62,7 +62,7 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
VKDebugOut *debug_out;
|
||||
|
||||
ObjectList<VulkanPhyDevice> physical_devices;
|
||||
ObjectList<GPUPhysicalDevice> physical_devices;
|
||||
|
||||
private:
|
||||
|
||||
@ -80,8 +80,8 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
operator VkInstance (){return inst;}
|
||||
|
||||
const ObjectList<VulkanPhyDevice> &GetDeviceList ()const {return physical_devices;}
|
||||
const VulkanPhyDevice * GetDevice (VkPhysicalDeviceType)const;
|
||||
const ObjectList<GPUPhysicalDevice> &GetDeviceList ()const {return physical_devices;}
|
||||
const GPUPhysicalDevice * GetDevice (VkPhysicalDeviceType)const;
|
||||
|
||||
template<typename T>
|
||||
T *GetInstanceProc(const char *name)
|
||||
@ -101,8 +101,8 @@ VK_NAMESPACE_BEGIN
|
||||
};//class VulkanInstance
|
||||
|
||||
void InitVulkanInstanceProperties();
|
||||
const ArrayList<VkLayerProperties> & GetInstanceLayerProperties();
|
||||
const ArrayList<VkExtensionProperties> & GetInstanceExtensionProperties();
|
||||
const List<VkLayerProperties> & GetInstanceLayerProperties();
|
||||
const List<VkExtensionProperties> & GetInstanceExtensionProperties();
|
||||
const bool CheckInstanceLayerSupport(const AnsiString &);
|
||||
const bool GetInstanceLayerVersion(const AnsiString &,uint32_t &spec,uint32_t &impl);
|
||||
const bool CheckInstanceExtensionSupport(const AnsiString &);
|
||||
|
@ -1,20 +1,18 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
|
||||
#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/mtl/ShaderBufferSource.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
class ActiveMemoryBlockManager;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
using ShaderStageCreateInfoList=ArrayList<VkPipelineShaderStageCreateInfo>;
|
||||
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
|
||||
|
||||
/**
|
||||
* 材质类<br>
|
||||
@ -24,8 +22,6 @@ class Material
|
||||
{
|
||||
AnsiString name;
|
||||
|
||||
PrimitiveType prim; ///<图元类型
|
||||
|
||||
VertexInput *vertex_input;
|
||||
|
||||
ShaderModuleMap *shader_maps;
|
||||
@ -47,7 +43,7 @@ private:
|
||||
|
||||
friend class RenderResource;
|
||||
|
||||
Material(const AnsiString &,const PrimitiveType &);
|
||||
Material(const AnsiString &);
|
||||
|
||||
public:
|
||||
|
||||
@ -55,8 +51,6 @@ 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;}
|
||||
@ -87,11 +81,6 @@ 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:
|
||||
@ -106,5 +95,6 @@ public:
|
||||
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
|
||||
};//class Material
|
||||
|
||||
using MaterialSet=SortedSet<Material *>;
|
||||
using MaterialSets=SortedSet<Material *>;
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
|
@ -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 uint32 size); ///<写入材质实例数据
|
||||
void WriteMIData (const void *data,const int size); ///<写入材质实例数据
|
||||
|
||||
template<typename T>
|
||||
void WriteMIData (const T &data){WriteMIData(&data,sizeof(T));} ///<写入材质实例数据
|
||||
|
@ -16,7 +16,7 @@ class DeviceMemory
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
DeviceMemory(VkDevice dev,VkDeviceMemory dm,const VkMemoryRequirements &mr,const uint32 i,const uint32_t p,const VkDeviceSize cas);
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VKMemoryAllocator:public AbstractMemoryAllocator
|
||||
{
|
||||
VulkanDevice *device;
|
||||
GPUDevice *device;
|
||||
|
||||
uint32_t buffer_usage_flag_bits;
|
||||
|
||||
@ -29,7 +29,7 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
VKMemoryAllocator(VulkanDevice *,const uint32_t flags,const VkDeviceSize r);
|
||||
VKMemoryAllocator(GPUDevice *,const uint32_t flags,const VkDeviceSize r);
|
||||
~VKMemoryAllocator();
|
||||
|
||||
void Free() override {/* DON'T RUN ANY OPERATION.*/}
|
||||
|
@ -2,9 +2,10 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VulkanPhyDevice
|
||||
class GPUPhysicalDevice
|
||||
{
|
||||
VkInstance instance=nullptr;
|
||||
VkPhysicalDevice physical_device=nullptr;
|
||||
@ -22,10 +23,9 @@ class VulkanPhyDevice
|
||||
VkPhysicalDeviceVulkan14Properties properties14;
|
||||
|
||||
VkPhysicalDeviceMemoryProperties memory_properties;
|
||||
|
||||
ArrayList<VkLayerProperties> layer_properties;
|
||||
ArrayList<VkExtensionProperties> extension_properties;
|
||||
ArrayList<VkQueueFamilyProperties> queue_family_properties;
|
||||
List<VkLayerProperties> layer_properties;
|
||||
List<VkExtensionProperties> extension_properties;
|
||||
List<VkQueueFamilyProperties> queue_family_properties;
|
||||
|
||||
private:
|
||||
|
||||
@ -46,8 +46,8 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
VulkanPhyDevice(VkInstance,VkPhysicalDevice);
|
||||
~VulkanPhyDevice()=default;
|
||||
GPUPhysicalDevice(VkInstance,VkPhysicalDevice);
|
||||
~GPUPhysicalDevice()=default;
|
||||
|
||||
operator VkPhysicalDevice() {return physical_device;}
|
||||
operator const VkPhysicalDevice()const {return physical_device;}
|
||||
@ -207,5 +207,5 @@ public:
|
||||
}
|
||||
|
||||
const bool SupportDynamicState() const {return dynamic_state;}
|
||||
};//class VulkanPhyDevice
|
||||
};//class GPUPhysicalDevice
|
||||
VK_NAMESPACE_END
|
||||
|
@ -21,25 +21,19 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
AABB bounding_box;
|
||||
AABB BoundingBox;
|
||||
|
||||
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; }
|
||||
|
||||
const VkDeviceSize GetVertexCount ()const;
|
||||
const uint32_t GetVABCount ()const;
|
||||
const int GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VAB * GetVAB (const int);
|
||||
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
||||
@ -54,6 +48,6 @@ public:
|
||||
|
||||
VertexDataManager * GetVDM (); ///<取得顶点数据管理器
|
||||
|
||||
const AABB & GetBoundingBox ()const{return bounding_box;}
|
||||
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
||||
};//class Primitive
|
||||
VK_NAMESPACE_END
|
||||
|
@ -19,7 +19,7 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
DeviceQueue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
|
||||
|
||||
@ -42,7 +42,7 @@ public:
|
||||
bool WaitFence(const bool wait_all=true,const uint64_t time_out=HGL_NANO_SEC_PER_SEC);
|
||||
|
||||
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
bool Submit(VulkanCmdBuffer *cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
bool Submit(GPUCmdBuffer *cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
};//class DeviceQueue
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||
|
@ -11,13 +11,13 @@ class RenderContext
|
||||
{
|
||||
protected:
|
||||
|
||||
VulkanDevice *device;
|
||||
GPUDevice *device;
|
||||
|
||||
VkExtent2D extent;
|
||||
|
||||
public:
|
||||
|
||||
RenderContext(VulkanDevice *,const VkExtent2D &);
|
||||
RenderContext(GPUDevice *,const VkExtent2D &);
|
||||
virtual ~RenderContext();
|
||||
|
||||
void Prepare(
|
||||
|
@ -16,7 +16,7 @@ class RenderPass
|
||||
VkPipelineCache pipeline_cache;
|
||||
VkRenderPass render_pass;
|
||||
|
||||
ArrayList<VkFormat> color_formats;
|
||||
List<VkFormat> color_formats;
|
||||
VkFormat depth_format;
|
||||
|
||||
VkExtent2D granularity;
|
||||
@ -31,7 +31,7 @@ private:
|
||||
|
||||
friend class RenderPassManager;
|
||||
|
||||
RenderPass(VkDevice d,VkPipelineCache pc,VkRenderPass rp,const ArrayList<VkFormat> &cf,VkFormat df);
|
||||
RenderPass(VkDevice d,VkPipelineCache pc,VkRenderPass rp,const List<VkFormat> &cf,VkFormat df);
|
||||
|
||||
public:
|
||||
|
||||
@ -43,7 +43,7 @@ public:
|
||||
const VkPipelineCache GetPipelineCache()const{return pipeline_cache;}
|
||||
|
||||
const uint GetColorCount()const{return color_formats.GetCount();}
|
||||
const ArrayList<VkFormat> & GetColorFormat()const{return color_formats;}
|
||||
const List<VkFormat> & GetColorFormat()const{return color_formats;}
|
||||
const VkFormat GetColorFormat(int index)const
|
||||
{
|
||||
if(index<0||index>=color_formats.GetCount())return VK_FORMAT_UNDEFINED;
|
||||
@ -56,15 +56,15 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
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 *,const VIL *,const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &,const bool prim_restart=false);
|
||||
};//class RenderPass
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
|
@ -11,8 +11,9 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/font/TextPrimitive.h>
|
||||
#include<hgl/graph/StaticMesh.h>
|
||||
#include<hgl/type/ObjectManage.h>
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/VKDescriptorBindingManage.h>
|
||||
@ -31,7 +32,7 @@ using MaterialInstanceID =int;
|
||||
using BufferID =int;
|
||||
using DescriptorSetID =int;
|
||||
using PrimitiveID =int;
|
||||
using MeshID =int;
|
||||
using RenderableID =int;
|
||||
using SamplerID =int;
|
||||
using StaticMeshID =int;
|
||||
|
||||
@ -43,7 +44,7 @@ constexpr const size_t VK_SHADER_STAGE_TYPE_COUNT=20;//GetBitOffset((uint32_t)VK
|
||||
*/
|
||||
class RenderResource
|
||||
{
|
||||
VulkanDevice *device;
|
||||
GPUDevice *device;
|
||||
|
||||
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
|
||||
Map<AnsiString,Material *> material_by_name;
|
||||
@ -54,7 +55,9 @@ class RenderResource
|
||||
IDObjectManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
|
||||
IDObjectManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
|
||||
IDObjectManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
|
||||
IDObjectManage<MeshID, Mesh> rm_mesh; ///<渲染实例集合集
|
||||
IDObjectManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
||||
|
||||
IDObjectManage<StaticMeshID, StaticMesh> rm_static_mesh; ///<静态网格合集
|
||||
|
||||
private:
|
||||
|
||||
@ -75,11 +78,18 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
VulkanDevice *GetDevice(){return device;}
|
||||
GPUDevice *GetDevice(){return device;}
|
||||
|
||||
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
|
||||
DescriptorBinding static_descriptor; ///<静态属性描述符绑定管理
|
||||
DescriptorBinding global_descriptor; ///<全局属性描述符绑定管理
|
||||
|
||||
public:
|
||||
|
||||
RenderResource(VulkanDevice *dev):device(dev){}
|
||||
RenderResource(GPUDevice *dev):device(dev),
|
||||
static_descriptor(DescriptorSetType::Static),
|
||||
global_descriptor(DescriptorSetType::Global)
|
||||
{}
|
||||
virtual ~RenderResource()=default;
|
||||
|
||||
public: //添加数据到管理器(如果指针为nullptr会返回-1)
|
||||
@ -90,7 +100,8 @@ public: //添加数据到管理器(如果指针为nullptr会返回-1)
|
||||
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
|
||||
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
|
||||
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
|
||||
MeshID Add(Mesh * r ){return rm_mesh.Add(r);}
|
||||
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
||||
StaticMeshID Add(StaticMesh * sm ){return rm_static_mesh.Add(sm);}
|
||||
|
||||
public: // VAB/VAO
|
||||
|
||||
@ -120,7 +131,7 @@ public: //Material
|
||||
|
||||
const ShaderModule *CreateShaderModule(const AnsiString &shader_module_name,const ShaderCreateInfo *);
|
||||
|
||||
Material * CreateMaterial (const AnsiString &,const mtl::MaterialCreateInfo *);
|
||||
Material * CreateMaterial(const mtl::MaterialCreateInfo *);
|
||||
Material * LoadMaterial(const AnsiString &,mtl::Material2DCreateConfig *);
|
||||
Material * LoadMaterial(const AnsiString &,mtl::Material3DCreateConfig *);
|
||||
|
||||
@ -134,10 +145,10 @@ public: //Material
|
||||
return CreateMaterialInstance(mtl,vil_cfg,data,sizeof(T));
|
||||
}
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(const AnsiString &mtl_name,const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||
|
||||
Mesh * CreateMesh(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||
Mesh * CreateMesh(PrimitiveCreater *pc,MaterialInstance *mi,Pipeline *p);
|
||||
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||
Renderable * CreateRenderable(PrimitiveCreater *pc,MaterialInstance *mi,Pipeline *p);
|
||||
|
||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
Sampler * CreateSampler(Texture *);
|
||||
@ -150,7 +161,9 @@ 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 * GetMesh (const MeshID &id){return rm_mesh.Get(id);}
|
||||
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||
|
||||
StaticMesh * GetStaticMesh (const StaticMeshID &id){return rm_static_mesh.Get(id);}
|
||||
|
||||
public: //Release
|
||||
|
||||
@ -160,7 +173,9 @@ 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_mesh.Release(r);}
|
||||
void Release(Renderable * r ){rm_renderables.Release(r);}
|
||||
|
||||
void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);}
|
||||
};//class RenderResource
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,6 @@
|
||||
#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>
|
||||
@ -15,7 +14,7 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
class RenderFramework;
|
||||
|
||||
using UBOViewportInfo=UBOInstance<graph::ViewportInfo>;
|
||||
using UBOViewportInfo=DeviceBufferMap<graph::ViewportInfo>;
|
||||
|
||||
class IRenderTarget
|
||||
{
|
||||
@ -30,7 +29,7 @@ class IRenderTarget
|
||||
public:
|
||||
|
||||
RenderFramework * GetRenderFramework ()const{return render_framework;}
|
||||
VulkanDevice * GetDevice ()const;
|
||||
GPUDevice * GetDevice ()const;
|
||||
VkDevice GetVkDevice ()const;
|
||||
DescriptorBinding * GetDescriptorBinding(){return &desc_binding;}
|
||||
|
||||
@ -73,9 +72,10 @@ public: // Command Buffer
|
||||
|
||||
public:
|
||||
|
||||
virtual ViewportInfo * GetViewportInfo ()
|
||||
virtual void Bind (Material *mtl)
|
||||
{
|
||||
return ubo_vp_info->data();
|
||||
if(mtl)
|
||||
desc_binding.Bind(mtl);
|
||||
}
|
||||
};//class IRenderTarget
|
||||
|
||||
|
@ -12,7 +12,7 @@ VK_NAMESPACE_BEGIN
|
||||
* 原始图元数据缓冲区<Br>
|
||||
* 提供在渲染之前的数据绑定信息
|
||||
*/
|
||||
struct MeshDataBuffer:public Comparator<MeshDataBuffer>
|
||||
struct PrimitiveDataBuffer:public Comparator<PrimitiveDataBuffer>
|
||||
{
|
||||
uint32_t vab_count;
|
||||
VkBuffer * vab_list;
|
||||
@ -29,17 +29,17 @@ struct MeshDataBuffer:public Comparator<MeshDataBuffer>
|
||||
|
||||
public:
|
||||
|
||||
MeshDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr);
|
||||
~MeshDataBuffer();
|
||||
PrimitiveDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr);
|
||||
~PrimitiveDataBuffer();
|
||||
|
||||
const int compare(const MeshDataBuffer &pdb)const override;
|
||||
};//struct MeshDataBuffer
|
||||
const int compare(const PrimitiveDataBuffer &pdb)const override;
|
||||
};//struct PrimitiveDataBuffer
|
||||
|
||||
/**
|
||||
* 原始图元渲染数据<Br>
|
||||
* 提供在渲染时的数据
|
||||
*/
|
||||
struct MeshRenderData:public ComparatorData<MeshRenderData>
|
||||
struct PrimitiveRenderData:public ComparatorData<PrimitiveRenderData>
|
||||
{
|
||||
//因为要VAB是流式访问,所以我们这个结构会被用做排序依据
|
||||
//也因此,把vertex_offset放在最前面
|
||||
@ -52,7 +52,7 @@ struct MeshRenderData:public ComparatorData<MeshRenderData>
|
||||
|
||||
public:
|
||||
|
||||
MeshRenderData(const uint32_t vc,const uint32_t ic,const int32_t vo=0,const uint32_t fi=0)
|
||||
PrimitiveRenderData(const uint32_t vc,const uint32_t ic,const int32_t vo=0,const uint32_t fi=0)
|
||||
{
|
||||
vertex_count =vc;
|
||||
index_count =ic;
|
||||
@ -62,31 +62,31 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* 网格体(网格中的最小渲染单位)
|
||||
* 原始可渲染对象(即仅一个模型一个材质)
|
||||
*/
|
||||
class Mesh
|
||||
class Renderable ///可渲染对象实例
|
||||
{
|
||||
Pipeline * pipeline;
|
||||
MaterialInstance * mat_inst;
|
||||
Primitive * primitive;
|
||||
|
||||
MeshDataBuffer * data_buffer;
|
||||
MeshRenderData * render_data;
|
||||
PrimitiveDataBuffer * primitive_data_buffer;
|
||||
PrimitiveRenderData * primitive_render_data;
|
||||
|
||||
private:
|
||||
|
||||
friend Mesh *CreateMesh(Primitive *,MaterialInstance *,Pipeline *);
|
||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
|
||||
Mesh(Primitive *,MaterialInstance *,Pipeline *,MeshDataBuffer *,MeshRenderData *);
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,PrimitiveDataBuffer *,PrimitiveRenderData *);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Mesh()
|
||||
virtual ~Renderable()
|
||||
{
|
||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||
|
||||
SAFE_CLEAR(data_buffer);
|
||||
SAFE_CLEAR(render_data);
|
||||
SAFE_CLEAR(primitive_data_buffer);
|
||||
SAFE_CLEAR(primitive_render_data);
|
||||
}
|
||||
|
||||
void UpdatePipeline (Pipeline *p){pipeline=p;}
|
||||
@ -98,8 +98,8 @@ public:
|
||||
Primitive * GetPrimitive (){return primitive;}
|
||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
||||
|
||||
const MeshDataBuffer * GetDataBuffer ()const{return data_buffer;}
|
||||
const MeshRenderData * GetRenderData ()const{return render_data;}
|
||||
const PrimitiveDataBuffer *GetDataBuffer ()const{return primitive_data_buffer;}
|
||||
const PrimitiveRenderData *GetRenderData ()const{return primitive_render_data;}
|
||||
|
||||
public:
|
||||
|
||||
@ -114,7 +114,7 @@ public:
|
||||
mat_inst=mi;
|
||||
return(true);
|
||||
}
|
||||
};//class Mesh
|
||||
};//class Renderable
|
||||
|
||||
Mesh *CreateMesh(Primitive *,MaterialInstance *,Pipeline *);
|
||||
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
VK_NAMESPACE_END
|
@ -12,7 +12,7 @@ class Sampler
|
||||
|
||||
protected:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
Sampler(VkDevice dev,VkSampler s)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ class Semaphore
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDevice;
|
||||
friend class GPUDevice;
|
||||
|
||||
Semaphore(VkDevice d,VkSemaphore s)
|
||||
{
|
||||
|
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKVertexInputLayout.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -44,3 +46,4 @@ public:
|
||||
operator VkShaderModule ()const{return stage_create_info->module;}
|
||||
};//class ShaderModule
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user