Compare commits

..

No commits in common. "devel_40_World" and "devel_30_ResumeAssignBuffer" have entirely different histories.

1293 changed files with 6155 additions and 197159 deletions

View File

@ -1,8 +0,0 @@
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

@ -1 +1 @@
Subproject commit 0244bff1b60119806f683b54a137cda2cacc17ac
Subproject commit 4b880eb50f5ef7436e72b8a0a03d528da3fd76a3

@ -1 +1 @@
Subproject commit 6fbc7078181cefc7e5da590c2d4ccc70507934b7
Subproject commit ca9aece201dd581c0576fe5448162686081261ff

2
CMCore

@ -1 +1 @@
Subproject commit c5b37f98353441520374011020dbe63c17796a4d
Subproject commit d70d31288f601061a69f93b4970af6692e53a34b

@ -1 +1 @@
Subproject commit f0ff214289a1265898feecbdbbd2ddf50bff5dca
Subproject commit 8d091ebfb0fb02c320789357f66bf84d1c80682f

@ -1 +1 @@
Subproject commit 74e33b497274e51c35a5ee19a274b12dc86deecb
Subproject commit a6a368031209ce23dc14e88acf45dd8298a19886

2
CMUtil

@ -1 +1 @@
Subproject commit 48383e5f63928bab43320c406219365850507246
Subproject commit 39faf8b4751ad890bee3a0f5d827a0c619353c35

View File

@ -8,35 +8,35 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMCMakeModule)
set(ULRE_3RDPTY_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdpty)
include_directories(${ULRE_3RDPTY_ROOT_PATH}/NvTriStrip)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
SET(ULRE_RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include(math)
include(vulkan)
include(use_cm_module)
SET(ULRE CMCore
CMPlatform
CMAssetsManage
CMSceneGraph
CMUtil
ULRE.Work
ULRE.Util
ULRE.ShaderGen
ULRE.SceneGraph
${HGL_MATH_LIB}
${RENDER_LIBRARY}
${Vulkan_LIBRARIES})
use_cm_module(Core)
use_cm_module(Util)
use_cm_module(Platform)
use_cm_module(AssetsManage)
use_cm_module(SceneGraph)
SET(ULRE CMCore
CMPlatform
CMAssetsManage
CMSceneGraph
CMUtil
ULRE.Util
ULRE.ShaderGen
ULRE.SceneGraph
${HGL_MATH_LIB}
${RENDER_LIBRARY}
${Vulkan_LIBRARIES})
include_directories(${ULRE_3RDPTY_ROOT_PATH}/NvTriStrip)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
SET(ULRE_RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(src)
add_subdirectory(example)

View File

@ -23,7 +23,7 @@ Code
#Fragment
sampler2D TextureBaseColor
sampler2D TextureColor
Output
{
@ -34,6 +34,6 @@ Code
{
void main()
{
FragColor=texture(TextureBaseColor,Input.TexCoord);
FragColor=texture(TextureColor,Input.TexCoord);
}
}

View File

@ -52,7 +52,7 @@ Code
#Fragment
sampler2D TextureBaseColor
sampler2D TextureColor
Output
{
@ -63,6 +63,6 @@ Code
{
void main()
{
FragColor=texture(TextureBaseColor,Input.TexCoord);
FragColor=texture(TextureColor,Input.TexCoord);
}
}

View File

@ -61,7 +61,7 @@ Code
#Fragment
sampler2DArray TextureBaseColor
sampler2DArray TextureColor
Output
{
@ -74,6 +74,6 @@ Code
{
MaterialInstance mi=GetMI();
FragColor=texture(TextureBaseColor,vec3(Input.TexCoord,mi.id.x));
FragColor=texture(TextureColor,vec3(Input.TexCoord,mi.id.x));
}
}

View File

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

View File

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

View File

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

View File

@ -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 | 操作系统真实路径访问 |

View File

@ -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);
```

View File

@ -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.
```

View File

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

View File

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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -1,199 +0,0 @@
// Billboard
#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/Ray.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#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;
static float position_data[3]=
{
0,0,0
};
static float lumiance_data[2]={1,1};
static Color4f white_color(1,1,1,1);
static Color4f yellow_color(1,1,0,1);
class TestApp:public WorkObject
{
Color4f color;
private:
Material * mtl_plane_grid =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
Pipeline * pipeline_plane_grid =nullptr;
Primitive * prim_plane_grid =nullptr;
MaterialInstance * mi_billboard =nullptr;
Pipeline * pipeline_billboard =nullptr;
Mesh * ro_billboard =nullptr;
Texture2D * texture =nullptr;
Sampler * sampler =nullptr;
private:
bool InitPlaneGridMP()
{
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
cfg.local_to_world=true;
{
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);
if(!pipeline_plane_grid)return(false);
}
return(true);
}
bool InitBillboardMP()
{
mtl::BillboardMaterialCreateConfig cfg(PrimitiveType::Billboard);
{
cfg.fixed_size=true;
mi_billboard=CreateMaterialInstance(mtl::inline_material::Billboard2D,&cfg);
if(!mi_billboard)return(false);
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D);
if(!pipeline_billboard)return(false);
}
return(true);
}
bool InitTexture()
{
TextureManager *tex_manager=GetTextureManager();
texture=tex_manager->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
if(!texture)return(false);
sampler=db->CreateSampler();
if(!mi_billboard->GetMaterial()->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::BaseColor, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
Vector2u texture_size(texture->GetWidth(),texture->GetHeight());
mi_billboard->WriteMIData(texture_size);
return(true);
}
bool CreateRenderObject()
{
using namespace inline_geometry;
{
auto pc=GetPrimitiveCreater(mi_plane_grid);
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(500,500);
pgci.sub_count.Set(5,5);
pgci.lum=128;
pgci.sub_lum=192;
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
}
{
auto pc=GetPrimitiveCreater(mi_billboard);
pc->Init("Billboard",1);
if(!pc->WriteVAB(VAN::Position,VF_V3F,position_data))
return(false);
ro_billboard=db->CreateMesh(pc,mi_billboard,pipeline_billboard);
if(!ro_billboard)
return(false);
}
return(true);
}
bool InitScene()
{
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
CreateComponent<MeshComponent>(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
CreateComponent<MeshComponent>(scene_root,ro_billboard);
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(Vector3f(32,32,32));
camera_control->SetTarget(Vector3f(0,0,0));
return(true);
}
public:
using WorkObject::WorkObject;
~TestApp()
{
SAFE_CLEAR(prim_plane_grid);
}
bool Init() override
{
if(!InitPlaneGridMP())
return(false);
if(!InitBillboardMP())
return(false);
if(!InitTexture())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)
{
return RunFramework<TestApp>(OS_TEXT("Billboard"),1280,720);
}

View File

@ -1,5 +1,4 @@
macro(CreateProject name)
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
target_link_libraries(${name} ${ULRE})
@ -11,8 +10,7 @@
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(04_Billboard BillboardTest.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)

View File

@ -1,6 +0,0 @@
#include<hgl/graph/mtl/MaterialLibrary.h>
STD_MTL_NAMESPACE_BEGIN
STD_MTL_NAMESPACE_END

View File

@ -1,18 +1,20 @@
// 该范例主要演示使用RenderList系统绘制多个三角形并利用RenderList进行排序以及自动合并进行Instance渲染
#include<hgl/WorkManager.h>
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/component/MeshComponent.h>
#include<hgl/graph/RenderList.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t VERTEX_COUNT=3;
constexpr uint32_t SCREEN_WIDTH=1024;
constexpr uint32_t SCREEN_HEIGHT=1024;
constexpr uint32_t TRIANGLE_NUMBER=12;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT*2]=
{
@ -28,12 +30,15 @@ constexpr uint8 color_data[VERTEX_COUNT][4]=
{0,0,255,255}
};
class TestApp:public WorkObject
class TestApp:public VulkanApplicationFramework
{
private:
SceneNode render_root;
RenderList * render_list =nullptr;
MaterialInstance * material_instance =nullptr;
Mesh * render_obj =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
@ -42,60 +47,64 @@ private:
bool InitMaterial()
{
{
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
CoordinateSystem2D::NDC,
mtl::WithLocalToWorld::With);
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
VILConfig vil_config;
vil_config.Add(VAN::Color,VF_V4UN8);
material_instance=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,
{
{VAN::Position, VF_V2F, position_data},
{VAN::Color, VF_V4UN8, color_data }
});
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.SetVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
render_obj=rpc.Create(material_instance,pipeline);
if(!render_obj)
return(false);
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保存会出现问题
mat=rotate(rad,Vector3f(0,0,1));
for(uint i=0;i<12;i++)
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
CreateComponent<MeshComponent>(mat,scene_root,render_obj);
}
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
using WorkObject::WorkObject;
bool Init() override
~TestApp()
{
GetRenderer()->SetClearColor(Color4f(0.2f,0.2f,0.2f,1.0f));
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitMaterial())
return(false);
@ -103,11 +112,27 @@ public:
if(!InitVBO())
return(false);
BuildCommandBuffer(render_list);
return(true);
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_list);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@ -1,15 +1,19 @@
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形并依赖RenderList中的自动合并功能让同一材质下所有不同材质实例的对象一次渲染完成。
#include<hgl/WorkManager.h>
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/graph/RenderList.h>
#include<hgl/color/Color.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1024;
constexpr uint32_t SCREEN_HEIGHT=1024;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT*2]=
@ -20,18 +24,22 @@ constexpr float position_data[VERTEX_COUNT*2]=
};
constexpr uint DRAW_OBJECT_COUNT=12;
constexpr double TRI_ROTATE_ANGLE=360.0f/DRAW_OBJECT_COUNT;
#define USE_MATERIAL_FILE true //是否使用材质文件
class TestApp:public WorkObject
class TestApp:public VulkanApplicationFramework
{
private:
SceneNode render_root;
RenderList * render_list =nullptr;
Material * material =nullptr;
struct
{
MaterialInstance * mi;
Mesh * mesh;
Renderable * r;
}render_obj[DRAW_OBJECT_COUNT]{};
Pipeline * pipeline =nullptr;
@ -41,7 +49,10 @@ private:
bool InitMaterial()
{
{
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,CoordinateSystem2D::NDC,mtl::WithLocalToWorld::With);
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;
#ifndef USE_MATERIAL_FILE
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg); //走程序内置材质创建函数
@ -66,57 +77,75 @@ private:
}
}
pipeline=CreatePipeline(material,InlinePipeline::Solid2D);
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Triangles);
return pipeline;
}
bool InitVBOAndRenderList()
{
Primitive *prim=CreatePrimitive("Triangle",VERTEX_COUNT,material->GetDefaultVIL(),
{{VAN::Position, VF_V2F, position_data}});
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
if(!prim)
return(false);
db->Add(prim);
Matrix4f mat;
SceneNode *scene_root=GetSceneRoot(); ///<取得场景根节点
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
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=rpc.Create(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.CreateSubNode(rotate(deg2rad(double(360/DRAW_OBJECT_COUNT*i)),Vector3f(0,0,1)),render_obj[i].r);
}
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
using WorkObject::WorkObject;
bool Init() override
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitMaterial())
return(false);
if(!InitVBOAndRenderList())
return(false);
BuildCommandBuffer(render_list);
return(true);
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_list);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@ -0,0 +1,166 @@
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data_float[VERTEX_COUNT*2]=
{
0.0, -0.5,
-0.5, 0.5,
0.5, 0.5
};
#define USE_HALF_FLOAT_POSITION
#ifdef USE_HALF_FLOAT_POSITION
constexpr VkFormat PositionFormat=VF_V2HF;
half_float position_data_hf[VERTEX_COUNT*2];
#define position_data position_data_hf
#else
constexpr VkFormat PositionFormat=VF_V2F;
#define position_data position_data_float
#endif//USE_HALF_FLOAT_POSITION
#define USE_UNORM8_COLOR
#ifdef USE_UNORM8_COLOR
constexpr uint8 color_data[VERTEX_COUNT*4]=
{ 255,0,0,255,
0,255,0,255,
0,0,255,255
};
constexpr VkFormat ColorFormat=VF_V4UN8;
#else
constexpr float color_data[VERTEX_COUNT*4]=
{ 1,0,0,1,
0,1,0,1,
0,0,1,1
};
constexpr VkFormat ColorFormat=VF_V4F;
#endif//USE_UNORM8_COLOR
class TestApp:public VulkanApplicationFramework
{
private:
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
VILConfig vil_config;
#endif
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
private:
void InitVIL()
{
#ifdef USE_HALF_FLOAT_POSITION
vil_config.Add(VAN::Position,PositionFormat);
#endif//USE_HALF_FLOAT_POSITION
#ifdef USE_UNORM8_COLOR
vil_config.Add(VAN::Color,ColorFormat);
#endif//USE_HALF_FLOAT_POSITION
}
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
material_instance=db->CreateMaterialInstance(mci,&vil_config);
return material_instance;
}
bool InitPipeline()
{
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
#ifdef USE_HALF_FLOAT_POSITION
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
#endif//USE_HALF_FLOAT_POSITION
if(!rpc.SetVAB(VAN::Position, PositionFormat, position_data))return(false);
if(!rpc.SetVAB(VAN::Color, ColorFormat, color_data ))return(false);
render_obj=rpc.Create(material_instance,pipeline);
return(render_obj);
}
public:
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
InitVIL();
if(!InitAutoMaterial())
return(false);
if(!InitPipeline())
return(false);
if(!InitVBO())
return(false);
if(!BuildCommandBuffer(render_obj))
return(false);
return(true);
}
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@ -1,12 +1,13 @@
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
#include<hgl/WorkManager.h>
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
@ -19,7 +20,7 @@ static float position_data_float[VERTEX_COUNT][2]=
{0.25, 0.75}
};
static int16 position_data[VERTEX_COUNT][2]={};
static uint16 position_data_u16[VERTEX_COUNT][2]={};
constexpr uint8 color_data[VERTEX_COUNT*4]=
{
@ -28,17 +29,14 @@ constexpr uint8 color_data[VERTEX_COUNT*4]=
0,0,255,255
};
constexpr VAType POSITION_SHADER_FORMAT =VAT_IVEC2;
constexpr VkFormat POSITION_DATA_FORMAT =VF_V2I16;
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
constexpr VkFormat COLOR_DATA_FORMAT =VF_V4UN8;
class TestApp:public WorkObject
class TestApp:public VulkanApplicationFramework
{
private:
MaterialInstance * material_instance =nullptr;
Mesh * mesh_triangle =nullptr;
Renderable * render_obj =nullptr;
Pipeline * pipeline =nullptr;
@ -46,70 +44,91 @@ private:
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(PrimitiveType::Triangles,
CoordinateSystem2D::Ortho,
mtl::WithLocalToWorld::With);
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
VILConfig vil_config;
cfg.position_format = POSITION_SHADER_FORMAT; //这里指定shader中使用ivec2当做顶点输入格式
#ifdef USE_ZERO2ONE_COORD
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
#else
cfg.coordinate_system=CoordinateSystem2D::Ortho;
cfg.position_format =VAT_UVEC2; //这里指定shader中使用uvec2当做顶点输入格式
// ^
// + 这上下两种格式要配套,否则会出错
// v
vil_config.Add(VAN::Position, POSITION_DATA_FORMAT); //这里指定VAB中使用RG16I当做顶点数据格式
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VAB中使用RG16U当做顶点数据格式
#endif//USE_ZERO2ONE_COORD
vil_config.Add(VAN::Color, COLOR_DATA_FORMAT); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定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();
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
for(uint i=0;i<VERTEX_COUNT;i++)
{
position_data[i][0]=position_data_float[i][0]*ext.width;
position_data[i][1]=position_data_float[i][1]*ext.height;
}
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data_float ))return(false);
#else //使用ortho坐标系
if(!rpc.SetVAB(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
#endif//USE_ZERO2ONE_COORD
mesh_triangle=CreateMesh("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); //创建一个静态网格组件
if(!rpc.SetVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
render_obj=rpc.Create(material_instance,pipeline);
return(true);
}
public:
using WorkObject::WorkObject;
bool Init() override
bool Init(uint w,uint h)
{
if(!VulkanApplicationFramework::Init(w,h))
return(false);
#ifndef USE_ZERO2ONE_COORD
for(uint i=0;i<VERTEX_COUNT;i++)
{
position_data_u16[i][0]=position_data_float[i][0]*w;
position_data_u16[i][1]=position_data_float[i][1]*h;
}
#endif//
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
if(!BuildCommandBuffer(render_obj))
return(false);
return(true);
}
};//class TestApp:public WorkObject
int os_main(int,os_char **)
void Resize(uint w,uint h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_obj);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
return RunFramework<TestApp>(OS_TEXT("Draw triangle use UBO"));
RunApp<TestApp>(1280,720);
}

View File

@ -1,6 +1,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
add_subdirectory(Basic)
add_subdirectory(Texture)

View File

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

View File

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

View File

@ -10,15 +10,10 @@
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
)
CreateProject(04_Gizmo3DMove Gizmo3DMove.cpp Gizmo.h Gizmo.cpp)
#CreateProject(03_BlenderAxis BlenderAxis.cpp)

View File

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

View File

@ -1,152 +1,228 @@
/*
Gizmo move
// Gizmo 3D Move
ref: Blender 4
0 9-10
*----------------->>>>
|
|
| 5+
| +6
|
|
v
10
22
15,5
1
*/
#include"GizmoResource.h"
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/VKRenderResource.h>
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/RenderFramework.h>
#include<hgl/component/MeshComponent.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
VK_NAMESPACE_BEGIN
using namespace hgl;
using namespace hgl::graph;
namespace
static Color4f white_color(1,1,1,1);
static Color4f yellow_color(1,1,0,1);
class TestApp:public SceneAppFramework
{
Color4f color;
static SceneNode *sn_gizmo_move=nullptr;
}//namespace
DeviceBuffer *ubo_color=nullptr;
SceneNode *GetGizmoMoveNode()
{
return sn_gizmo_move;
}
private:
void ClearGizmoMoveNode()
{
SAFE_CLEAR(sn_gizmo_move);
}
Material * mtl_vtx_lum =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
Pipeline * pipeline_vtx_lum =nullptr;
Primitive * prim_plane_grid =nullptr;
bool InitGizmoMoveNode(RenderFramework *render_framework)
{
Mesh *sphere=GetGizmoMesh(GizmoShape::Sphere,GizmoColor::White);
Mesh *cylinder[3]
Material * mtl_vtx_color =nullptr;
MaterialInstance * mi_line =nullptr;
Pipeline * pipeline_vtx_color =nullptr;
Primitive * ro_line =nullptr;
private:
bool InitMaterialAndPipeline()
{
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
};
{
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
Mesh *cone[3]
{
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Blue),
};
cfg.local_to_world=true;
Mesh *square[3]=
{
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
};
mtl_vtx_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_vtx_lum)return(false);
if(!sphere)
return(false);
mi_plane_grid=db->CreateMaterialInstance(mtl_vtx_lum,nullptr,&white_color);
if(!mi_plane_grid)return(false);
for(int i=0;i<3;i++)
{
if(!cylinder[i])
return(false);
pipeline_vtx_lum=CreatePipeline(mtl_vtx_lum,InlinePipeline::Solid3D,Prim::Lines);
if(!cone[i])
return(false);
if(!square[i])
return(false);
}
{
sn_gizmo_move=new SceneNode();
sn_gizmo_move->AttachComponent(render_framework->CreateComponent<MeshComponent>(sphere));
if(!pipeline_vtx_lum)
return(false);
}
{
Transform tm;
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
const Vector3f one_scale(1);
const Vector3f square_scale(2);
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
cfg.local_to_world=true;
mtl_vtx_color=db->LoadMaterial("Std3D/VertexColor3D",&cfg);
if(!mtl_vtx_color)return(false);
mi_line=db->CreateMaterialInstance(mtl_vtx_color);
if(!mi_line)return(false);
{
tm.SetScale(cylinder_scale);
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
const PipelineData *ipd=GetPipelineData(InlinePipeline::Solid3D);
tm.SetScale(one_scale);
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[2]); //Z 向上圆锥
if(!ipd)
return(false);
tm.SetScale(square_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[2]);
}
PipelineData *pd=new PipelineData(ipd);
{
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 向右圆柱
pd->SetLineWidth(2);
tm.SetScale(one_scale);
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[0]); //X 向右圆锥
pipeline_vtx_color=CreatePipeline(mtl_vtx_color,pd,Prim::Lines);
tm.SetScale(square_scale);
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[0]);
}
delete pd;
{
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 向前圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[1]); //Y 向前圆锥
tm.SetScale(square_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[1]);
if(!pipeline_vtx_color)
return(false);
}
}
return(true);
}
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
{
Renderable *ri=db->CreateRenderable(r,mi,p);
if(!ri)
{
LOG_ERROR(OS_TEXT("Create Renderable failed."));
return(nullptr);
}
render_root.CreateSubNode(ri);
return ri;
}
if(!sn_gizmo_move)
return(false);
/**
* 线.
*
* \param pos
* \param max_line 线
* \param oa1 1
* \param oa2 2
*/
void WriteAxisPosition(Vector3f *pos,const Vector3f &max_line,const Vector3f &oa1,const Vector3f &oa2)
{
constexpr const float AXIS_LENGTH =4;
constexpr const float AXIS_MIN_STEP =1;
constexpr const float AXIS_ARROW_SIZE=0.25;
return(true);
const Vector3f end_pos =max_line*AXIS_LENGTH; ///<最终点位置
const Vector3f cross_pos=max_line*AXIS_MIN_STEP; ///<坐标轴尾部交叉线位置
const Vector3f arrow_pos=max_line*(AXIS_LENGTH-AXIS_MIN_STEP); ///<箭头末端在主线上的位置
//主线
pos[0]=Vector3f(0, 0, 0);
pos[1]=end_pos;
//四根箭头线
pos[2]=end_pos;
pos[3]=arrow_pos-oa1*AXIS_ARROW_SIZE;
pos[4]=end_pos;
pos[5]=arrow_pos+oa1*AXIS_ARROW_SIZE;
pos[6]=end_pos;
pos[7]=arrow_pos-oa2*AXIS_ARROW_SIZE;
pos[8]=end_pos;
pos[9]=arrow_pos+oa2*AXIS_ARROW_SIZE;
//侧边连接其它轴线
pos[10]=cross_pos;
pos[11]=cross_pos+oa1*AXIS_MIN_STEP;
pos[12]=cross_pos;
pos[13]=cross_pos+oa2*AXIS_MIN_STEP;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
{
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=0.5;
pgci.sub_lum=0.75;
prim_plane_grid=CreatePlaneGrid(db,mtl_vtx_lum->GetDefaultVIL(),&pgci);
}
{
constexpr const uint AXIS_MAX_LINES =7;
constexpr const uint AXIS_MAX_VERTICES =AXIS_MAX_LINES*2*3;
ro_line=db->CreatePrimitive("Line",AXIS_MAX_VERTICES);
if(!ro_line)return(false);
Vector3f position_data[3][AXIS_MAX_LINES*2];
WriteAxisPosition(position_data[0],Vector3f(1,0,0),Vector3f(0,1,0),Vector3f(0,0,1));
WriteAxisPosition(position_data[1],Vector3f(0,1,0),Vector3f(1,0,0),Vector3f(0,0,1));
WriteAxisPosition(position_data[2],Vector3f(0,0,1),Vector3f(1,0,0),Vector3f(0,1,0));
Color4f color_data[3][AXIS_MAX_LINES*2];
for(Color4f &c:color_data[0])c=Color4f(1,0,0,1);
for(Color4f &c:color_data[1])c=Color4f(0,1,0,1);
for(Color4f &c:color_data[2])c=Color4f(0,0,1,1);
if(!ro_line->Set(VAN::Position, db->CreateVAB(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
if(!ro_line->Set(VAN::Color, db->CreateVAB(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
}
return(true);
}
bool InitScene()
{
Add(prim_plane_grid,mi_plane_grid,pipeline_vtx_lum);
Add(ro_line,mi_line,pipeline_vtx_color);
camera->pos=Vector3f(32,32,32);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint w,uint h) override
{
if(!SceneAppFramework::Init(w,h))
return(false);
if(!InitMaterialAndPipeline())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}
VK_NAMESPACE_END

View File

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

View File

@ -1,152 +0,0 @@
/*
Gizmo move
ref: Blender 4
0 9-10
*----------------->>>>
|
|
| 5+
| +6
|
|
v
10
22
15,5
1
*/
#include"GizmoResource.h"
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/InlineGeometry.h>
VK_NAMESPACE_BEGIN
namespace
{
static StaticMesh *sm_gizmo_scale=nullptr;
}//namespace
StaticMesh *GetGizmoScaleStaticMesh()
{
return sm_gizmo_scale;
}
void ClearGizmoScaleStaticMesh()
{
SAFE_CLEAR(sm_gizmo_scale);
}
bool InitGizmoScaleStaticMesh()
{
Mesh *center_cube=GetGizmoMesh(GizmoShape::Cube,GizmoColor::White);
Mesh *cylinder[3]
{
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
};
Mesh *cube[3]
{
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Cube,GizmoColor::Blue),
};
Mesh *square[3]=
{
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
};
if(!center_cube)
return(false);
for(int i=0;i<3;i++)
{
if(!cylinder[i])
return(false);
if(!cube[i])
return(false);
if(!square[i])
return(false);
}
{
SceneNode *root_node=new SceneNode();
root_node->Add(new SceneNode(scale(GIZMO_CENTER_SPHERE_RADIUS*2),center_cube));
{
Transform tm;
const Vector3f one_scale(1);
const Vector3f plane_scale(2);
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
{
tm.SetScale(cylinder_scale);
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
root_node->Add(new SceneNode(tm,cube[2])); //Z 向上圆锥
tm.SetScale(plane_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
root_node->Add(new SceneNode(tm,square[2]));
}
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::Y,90);
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
tm.SetScale(one_scale);
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
root_node->Add(new SceneNode(tm,cube[0])); //X 向右圆锥
tm.SetScale(plane_scale);
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,square[0]));
}
{
tm.SetScale(cylinder_scale);
tm.SetRotation(AxisVector::X,-90);
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
root_node->Add(new SceneNode(tm,cube[1])); //Y 向前圆锥
tm.SetScale(plane_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
root_node->Add(new SceneNode(tm,square[1]));
}
}
sm_gizmo_scale=CreateGizmoStaticMesh(root_node);
}
if(!sm_gizmo_scale)
return(false);
return(true);
}
VK_NAMESPACE_END

View File

@ -1,324 +0,0 @@
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/color/Color.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/RenderFramework.h>
#include"GizmoResource.h"
VK_NAMESPACE_BEGIN
bool InitGizmoMoveNode(RenderFramework *);
void ClearGizmoMoveNode();
//bool InitGizmoScaleMesh();
//void ClearGizmoScaleMesh();
//
//bool InitGizmoRotateMesh();
//void ClearGizmoRotateMesh();
namespace
{
static RenderFramework *render_framework=nullptr;
static RenderResource * gizmo_rr=nullptr;
struct GizmoResource
{
Material * mtl;
MaterialInstance * mi[size_t(GizmoColor::RANGE_SIZE)];
Pipeline * pipeline;
VertexDataManager * vdm;
PrimitiveCreater * prim_creater;
};
static GizmoResource gizmo_line{};
static GizmoResource gizmo_triangle{};
struct GizmoMesh
{
Primitive *prim;
Mesh *mesh[size_t(GizmoColor::RANGE_SIZE)];
};
GizmoMesh gizmo_mesh[size_t(GizmoShape::RANGE_SIZE)]{};
void InitGizmoMesh(const GizmoShape &gs,Primitive *prim,Pipeline *p)
{
if(!prim)
return;
GizmoMesh *gr=gizmo_mesh+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);
}
bool InitMI(GizmoResource *gr)
{
if(!gr||!gr->mtl)
return(false);
Color4f color;
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
{
color=GetColor4f(gizmo_color[i],1.0);
gr->mi[i]=gizmo_rr->CreateMaterialInstance(gr->mtl,nullptr,&color);
if(!gr->mi[i])
return(false);
}
return(true);
}
bool InitGizmoResource2D()
{
if(!gizmo_rr)
return(false);
VulkanDevice *device=render_framework->GetDevice();
VulkanDevAttr *dev_attr=device->GetDevAttr();
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
{
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
cfg.local_to_world=true;
cfg.position_format=VAT_VEC3;
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(dev_attr,&cfg);
if(!mci)
return(false);
gizmo_line.mtl=gizmo_rr->CreateMaterial("GizmoLine",mci);
if(!gizmo_line.mtl)
return(false);
gizmo_line.mtl->Update();
}
{
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D);
if(!gizmo_line.pipeline)
return(false);
}
if(!InitMI(&gizmo_line))
return(false);
{
gizmo_line.vdm=new VertexDataManager(device,gizmo_line.mtl->GetDefaultVIL());
if(!gizmo_line.vdm)
return(false);
if(!gizmo_line.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
HGL_SIZE_1MB, //最大索引数量
IndexType::U16)) //索引类型
return(false);
}
{
}
return(true);
}
bool InitGizmoResource3D()
{
if(!gizmo_rr)
return(false);
VulkanDevice *device=render_framework->GetDevice();
VulkanDevAttr *dev_attr=device->GetDevAttr();
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
{
mtl::Material3DCreateConfig cfg(PrimitiveType::Triangles);
cfg.local_to_world=true;
cfg.material_instance=true;
mtl::MaterialCreateInfo *mci=CreateGizmo3D(dev_attr,&cfg);
if(!mci)
return(false);
gizmo_triangle.mtl=gizmo_rr->CreateMaterial("GizmoTriangle",mci);
if(!gizmo_triangle.mtl)
return(false);
gizmo_triangle.mtl->Update();
}
{
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D);
if(!gizmo_triangle.pipeline)
return(false);
}
if(!InitMI(&gizmo_triangle))
return(false);
{
gizmo_triangle.vdm=new VertexDataManager(device,gizmo_triangle.mtl->GetDefaultVIL());
if(!gizmo_triangle.vdm)
return(false);
if(!gizmo_triangle.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
HGL_SIZE_1MB, //最大索引数量
IndexType::U16)) //索引类型
return(false);
}
{
gizmo_triangle.prim_creater=new PrimitiveCreater(gizmo_triangle.vdm);
if(!gizmo_triangle.prim_creater)
return(false);
}
{
using namespace inline_geometry;
{
InitGizmoMesh(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
}
{
CircleCreateInfo cci;
cci.center=Vector2f(0,0);
cci.radius=Vector2f(0.5,0.5);
cci.field_count=16;
cci.has_center=false;
InitGizmoMesh(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
CubeCreateInfo cci;
cci.normal=true;
cci.tangent=false;
cci.tex_coord=false;
InitGizmoMesh(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
InitGizmoMesh(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
}
{
ConeCreateInfo cci;
cci.radius =GIZMO_CONE_RADIUS; //圆锥半径
cci.halfExtend =1; //圆锤一半高度
cci.numberSlices=16; //圆锥底部分割数
cci.numberStacks=3; //圆锥高度分割数
InitGizmoMesh(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
struct CylinderCreateInfo cci;
cci.halfExtend =1; //圆柱一半高度
cci.numberSlices=16; //圆柱底部分割数
cci.radius =1; //圆柱半径
InitGizmoMesh(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
}
{
struct TorusCreateInfo tci;
tci.innerRadius=0.975;
tci.outerRadius=1.0;
tci.numberSlices=64;
tci.numberStacks=8;
InitGizmoMesh(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
}
ENUM_CLASS_FOR(GizmoShape,int,i)
{
if(!gizmo_mesh[i].prim)
return(false);
}
}
return(true);
}
}//namespace
bool InitGizmoResource(RenderFramework *rf)
{
if(!rf)
return(false);
render_framework=rf;
gizmo_rr=render_framework->GetRenderResource();
VulkanDevice *device=render_framework->GetDevice();
if(!InitGizmoResource3D())
return(false);
if(!InitGizmoResource2D())
return(false);
InitGizmoMoveNode(rf);
//InitGizmoScaleMesh();
//InitGizmoRotateMesh();
return(true);
}
void FreeGizmoResource()
{
//ClearGizmoRotateMesh();
//ClearGizmoScaleMesh();
ClearGizmoMoveNode();
for(GizmoMesh &gr:gizmo_mesh)
{
SAFE_CLEAR(gr.prim)
SAFE_CLEAR_OBJECT_ARRAY(gr.mesh)
}
SAFE_CLEAR(gizmo_triangle.prim_creater);
SAFE_CLEAR(gizmo_triangle.vdm);
SAFE_CLEAR(gizmo_line.prim_creater);
SAFE_CLEAR(gizmo_line.vdm);
}
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color)
{
if(!gizmo_rr)
return(nullptr);
RANGE_CHECK_RETURN_NULLPTR(shape)
RANGE_CHECK_RETURN_NULLPTR(color)
return gizmo_mesh[size_t(shape)].mesh[size_t(color)];
}
VK_NAMESPACE_END

View File

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

View File

@ -1,132 +0,0 @@
#include<hgl/WorkManager.h>
#include"Gizmo.h"
#include<hgl/graph/Ray.h>
using namespace hgl;
using namespace hgl::graph;
const Vector3f GizmoPosition(0,0,0);
///**
//* 一种永远转向正面的变换节点
//*/
//class TransformBillboard:public TransformBase
//{
// CameraInfo *camera_info=nullptr;
// bool face_to_camera=false;
//
// ViewportInfo *viewport_info=nullptr;
// float fixed_scale=1.0;
//
//public:
//
// virtual void SetCameraInfo (CameraInfo * ci ){camera_info =ci;}
// virtual void SetViewportInfo(ViewportInfo * vi ){viewport_info =vi;}
//
// virtual void SetFaceToCamera(bool ftc ){face_to_camera=ftc;}
// virtual void SetFixedScale (const float size){fixed_scale =size;}
//
// virtual bool RefreshTransform(const Transform &tf=IdentityTransform) override
// {
// if(!camera_info)
// {
// return SceneNode::RefreshTransform(tf);
// }
//
// if(face_to_camera)
// {
// LocalTransform.SetRotation(CalculateFacingRotationQuat(GetWorldPosition(),camera_info->view,AxisVector::X));
// }
//
// if(viewport_info)
// {
// const float screen_height=viewport_info->GetViewportHeight();
//
// const Vector4f pos=camera_info->Project(GetWorldPosition());
//
// LocalTransform.SetScale(pos.w*fixed_scale/screen_height);
// }
//
// return SceneNode::RefreshTransform(tf);
// }
//};//class BillboardSceneNode:public SceneNode
class TestApp:public WorkObject
{
SceneNode *sm_move=nullptr;
//StaticMesh *sm_rotate=nullptr;
//StaticMesh *sm_scale=nullptr;
private:
bool InitGizmo()
{
if(!InitGizmoResource(GetRenderFramework()))
return(false);
sm_move =GetGizmoMoveNode();
//sm_rotate =GetGizmoRotateStaticMesh();
//sm_scale =GetGizmoScaleStaticMesh();
return(true);
}
void InitGizmoSceneTree()
{
SceneNode *root=GetSceneRoot();
root->Add(Duplication(sm_move));
//root.Add(Duplication(sm_rotate->GetScene()));
//root.CreateSubNode(sm_scale->GetScene());
}
public:
bool Init() override
{
if(!InitGizmo())
return(false);
InitGizmoSceneTree();
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(Vector3f(32,32,32));
camera_control->SetTarget(Vector3f(0,0,0));
return(true);
}
using WorkObject::WorkObject;
~TestApp()
{
FreeGizmoResource();
}
//void BuildCommandBuffer(uint32 index) override
//{
// camera_control->Refresh();
//
// const CameraInfo *ci=camera_control->GetCameraInfo();
// const ViewportInfo *vi=GetViewportInfo();
// 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 **)
{
return RunFramework<TestApp>(OS_TEXT("Gizmo"),1280,720);
}

View File

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

View File

@ -1,21 +1,17 @@
// PlaneGrid3D
#include<hgl/WorkManager.h>
#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/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,18 +25,13 @@ 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;
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!material)return(false);
VILConfig vil_config;
vil_config.Add(VAN::Luminance,VF_V1UN8);
Color4f GridColor;
COLOR ce=COLOR::BlenderAxisRed;
@ -48,12 +39,12 @@ private:
{
GridColor=GetColor4f(ce,1.0);
material_instance[i]=db->CreateMaterialInstance(material,&vil_config,&GridColor);
material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor);
ce=COLOR((int)ce+1);
}
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D);
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
return pipeline;
}
@ -67,55 +58,51 @@ private:
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=180;
pgci.sub_lum=255;
pgci.lum=0.75;
pgci.sub_lum=1.0;
auto pc=GetPrimitiveCreater(material_instance[0]);
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
prim_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&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.CreateSubNode(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()
bool Init(uint width,uint height) override
{
SAFE_CLEAR(prim_plane_grid);
}
if(!SceneAppFramework::Init(width,height))
return(false);
bool Init() override
{
if(!InitMDP())
return(false);
@ -129,7 +116,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);
}

View File

@ -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>
@ -9,9 +9,6 @@
#include<hgl/graph/Ray.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#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 +19,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;
@ -35,16 +32,17 @@ class TestApp:public WorkObject
private:
Material * mtl_plane_grid =nullptr;
Material * material =nullptr;
MaterialInstance * mi_plane_grid =nullptr;
Pipeline * pipeline_plane_grid =nullptr;
MaterialInstance * mi_line =nullptr;
Pipeline * pipeline =nullptr;
Primitive * prim_plane_grid =nullptr;
Material * mtl_line =nullptr;
MaterialInstance * mi_line =nullptr;
Pipeline * pipeline_line =nullptr;
Primitive * prim_line =nullptr;
VABMap * prim_line_vab_map =nullptr;
Primitive * ro_line =nullptr;
VAB * vab_pos =nullptr;
Ray ray;
@ -52,56 +50,38 @@ private:
bool InitMaterialAndPipeline()
{
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
cfg.local_to_world=true;
VILConfig vil_config;
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!material)return(false);
vil_config.Add(VAN::Luminance,VF_V1UN8);
mi_plane_grid=db->CreateMaterialInstance(material,nullptr,&white_color);
if(!mi_plane_grid)return(false);
{
cfg.position_format=VAT_VEC2;
mi_line=db->CreateMaterialInstance(material,nullptr,&yellow_color);
if(!mi_line)return(false);
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
if(!mtl_plane_grid)return(false);
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
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);
if(!pipeline_plane_grid)return(false);
}
{
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);
if(!mi_line)return(false);
pipeline_line=CreatePipeline(mi_line,InlinePipeline::Solid3D);
if(!pipeline_line)
return(false);
}
if(!pipeline)
return(false);
return(true);
}
Mesh *Add(SceneNode *parent_node,Primitive *r,MaterialInstance *mi,Pipeline *p)
Renderable *Add(Primitive *r,MaterialInstance *mi)
{
Mesh *ri=db->CreateMesh(r,mi,p);
Renderable *ri=db->CreateRenderable(r,mi,pipeline);
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.CreateSubNode(ri);
return ri;
}
@ -109,29 +89,25 @@ private:
bool CreateRenderObject()
{
using namespace inline_geometry;
{
auto pc=GetPrimitiveCreater(mi_plane_grid);
{
struct PlaneGridCreateInfo pgci;
pgci.grid_size.Set(32,32);
pgci.sub_count.Set(8,8);
pgci.lum=128;
pgci.sub_lum=196;
pgci.lum=0.5;
pgci.sub_lum=0.75;
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
prim_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
}
{
prim_line=CreatePrimitive("RayLine",2,mi_line->GetVIL(),
{
{VAN::Position, VF_V3F,position_data},
{VAN::Luminance,VF_V1UN8,lumiance_data}
});
prim_line_vab_map=prim_line->GetVABMap(VAN::Position);
ro_line=db->CreatePrimitive("Line",2);
if(!ro_line)return(false);
if(!ro_line->Set(VAN::Position, vab_pos= db->CreateVAB(VF_V3F,2,position_data )))return(false);
if(!ro_line->Set(VAN::Luminance, db->CreateVAB(VF_V1F,2,lumiance_data )))return(false);
}
return(true);
@ -139,30 +115,26 @@ private:
bool InitScene()
{
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
Add(prim_plane_grid,mi_plane_grid);
Add(ro_line,mi_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;
bool Init(uint w,uint h)
{
if(!SceneAppFramework::Init(w,h))
return(false);
~TestApp()
{
SAFE_CLEAR(prim_plane_grid);
}
bool Init() override
{
if(!InitMaterialAndPipeline())
return(false);
@ -175,28 +147,22 @@ 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代表的数据数量,不是字节数
vab_pos->Write(&pos,3*sizeof(float)); //更新VAB上这个点的位置
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);
}

View File

@ -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);
}

View File

@ -28,25 +28,12 @@ static mtl::blinnphong::SunLight sun_light=
constexpr const COLOR AxisColor[4]=
{
//COLOR::Red, //X轴颜色
//COLOR::Green, //Y轴颜色
//COLOR::Blue, //Z轴颜色
COLOR::White, //全局颜色
COLOR::GhostWhite,
COLOR::BlanchedAlmond,
COLOR::AntiqueWhite
COLOR::Red, //X轴颜色
COLOR::Green, //Y轴颜色
COLOR::Blue, //Z轴颜色
COLOR::White //全局颜色
};
constexpr const os_char *tex_filename[]=
{
OS_TEXT("eucalyptus-cross-versailles.Tex2D"),
OS_TEXT("tints-ashton-green-stretcher.Tex2D"),
OS_TEXT("worn-clay-cobble-in-desert-stretcher.Tex2D"),
OS_TEXT("plain-grey-sheer.Tex2D"),
};
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
class TestApp:public SceneAppFramework
{
private: //plane grid
@ -60,10 +47,6 @@ private:
DeviceBuffer * ubo_sun =nullptr;
Texture2DArray * texture =nullptr;
Sampler * sampler =nullptr;
private: //sphere
Material * mtl_blinnphong =nullptr;
@ -78,33 +61,10 @@ private: //sphere
Primitive * prim_cylinder =nullptr;
private:
bool InitTexture()
{
texture=db->CreateTexture2DArray( "SeamlessBackground",
256,256, ///<纹理尺寸
TexCount, ///<纹理层数
PF_BC1_RGBUN, ///<纹理格式
false); ///<是否自动产生mipmaps
if(!texture)return(false);
OSString filename;
for(uint i=0;i<TexCount;i++)
{
filename=filesystem::MergeFilename(OS_TEXT("res/image/seamless"),tex_filename[i]);
if(!db->LoadTexture2DToArray(texture,i,filename))
return(false);
}
return(true);
}
bool InitVertexLumMP()
{
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"VertexLuminance3D",PrimitiveType::Lines);
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",false,Prim::Lines);
cfg.local_to_world=true;
@ -114,7 +74,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,37 +92,20 @@ private:
bool InitBlinnPhongSunLightMP()
{
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"BlinnPhong3D",PrimitiveType::Triangles);
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",true,Prim::Triangles);
cfg.local_to_world=true;
cfg.material_instance=true;
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColorTexture",&cfg);
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColor",&cfg);
if(!mtl_blinnphong)return(false);
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
mtl_blinnphong->Update();
sampler=db->CreateSampler();
if(!mtl_blinnphong->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::BaseColor, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
struct MIData
{
Color4f color;
uint32 tex_id[4];
}mi_data;
constexpr const uint MIDataStride=sizeof(MIData);
Color4f mi_data;
for(uint i=0;i<4;i++)
{
mi_data.color=GetColor4f(AxisColor[i],4);
mi_data.tex_id[0]=i;
mi_data=GetColor4f(AxisColor[i],4);
mi_blinnphong[i]=db->CreateMaterialInstance(mtl_blinnphong, //材质
nullptr, //顶点输入配置,这里使用nullptr即代表会使用默认配置那么结果将等同于上面的mtl_blinnphong->GetDefaultVIL()
@ -170,7 +113,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);
@ -233,9 +176,9 @@ private:
{
struct CylinderCreateInfo cci;
cci.halfExtend =1.25; //圆柱一半高度
cci.halfExtend =4; //圆柱一半高度
cci.numberSlices=16; //圆柱底部分割数
cci.radius =1.25f; //圆柱半径
cci.radius =0.25f; //圆柱半径
prim_cylinder=CreateCylinder(pc_blinnphong,&cci);
}
@ -243,7 +186,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 +195,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(U8_TEXT("Create Renderable failed! Primitive: ")+r->GetName());
return(nullptr);
}
@ -291,11 +234,8 @@ public:
if(!SceneAppFramework::Init(w,h))
return(false);
if(!InitTexture())
if(!InitVertexLumMP())
return(false);
//if(!InitVertexLumMP())
// return(false);
if(!CreateBlinnPhongUBO())
return(false);

View File

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

View File

@ -4,7 +4,7 @@
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/math/Math.h>
@ -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);
@ -73,7 +73,7 @@ private:
sampler=db->CreateSampler();
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::BaseColor, ///<采样器名称
mtl::SamplerName::Color, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
@ -85,14 +85,12 @@ private:
bool InitVBO()
{
PrimitiveCreater rpc(device,material_instance->GetVIL());
rpc.Init("Quad",VERTEX_COUNT);
RenderablePrimitiveCreater rpc(db,"Quad",VERTEX_COUNT);
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.WriteVAB(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.SetVAB(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
render_obj=rpc.Create(material_instance,pipeline);
return(render_obj);
}

View File

@ -4,7 +4,7 @@
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/math/Math.h>
@ -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);
@ -69,7 +69,7 @@ private:
sampler=db->CreateSampler();
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::BaseColor, ///<采样器名称
mtl::SamplerName::Color, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
@ -81,14 +81,12 @@ private:
bool InitVBO()
{
PrimitiveCreater rpc(device,material_instance->GetVIL());
rpc.Init("Rectangle",1);
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
if(!rpc.SetVAB(VAN::Position,VF_V4F,position_data))return(false);
if(!rpc.SetVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
render_obj=db->CreateMesh(&rpc,material_instance,pipeline);
render_obj=rpc.Create(material_instance,pipeline);
return(render_obj);
}

View File

@ -4,7 +4,7 @@
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/math/Math.h>
#include<hgl/filesystem/Filename.h>
@ -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;
@ -56,12 +56,11 @@ private:
Pipeline * pipeline =nullptr;
DeviceBuffer * tex_id_ubo =nullptr;
Primitive * prim_rectangle =nullptr;
struct
{
MaterialInstance * mi;
Mesh * mesh;
Renderable * r;
}render_obj[TexCount]{};
private:
@ -91,7 +90,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 +100,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);
@ -109,7 +108,7 @@ private:
sampler=db->CreateSampler();
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
mtl::SamplerName::BaseColor, ///<采样器名称
mtl::SamplerName::Color, ///<采样器名称
texture, ///<纹理
sampler)) ///<采样器
return(false);
@ -129,29 +128,25 @@ private:
bool InitVBOAndRenderList()
{
PrimitiveCreater rpc(device,material->GetDefaultVIL());
rpc.Init("Rectangle",1);
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
position_data[2]=1.0f/float(TexCount);
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
prim_rectangle=rpc.Create();
if(!rpc.SetVAB(VAN::Position,VF_V4F,position_data))return(false);
if(!rpc.SetVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
Vector3f offset(1.0f/float(TexCount),0,0);
for(uint32_t i=0;i<TexCount;i++)
{
render_obj[i].mesh=db->CreateMesh(prim_rectangle,render_obj[i].mi,pipeline);
render_obj[i].r=rpc.Create(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();
@ -165,7 +160,6 @@ public:
~TestApp()
{
SAFE_CLEAR(prim_rectangle);
SAFE_CLEAR(render_list);
}

View File

@ -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;

View File

@ -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>

View File

@ -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))

View File

@ -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)
{

View File

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

View File

@ -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>

View File

@ -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,

View File

@ -53,9 +53,9 @@ protected:
protected:
VulkanDevice * device =nullptr;
GPUDevice * device =nullptr;
RenderPass * device_render_pass =nullptr;
SwapchainRenderTarget * sc_render_target =nullptr;
RTSwapchain * sc_render_target =nullptr;
protected:
@ -76,14 +76,6 @@ protected:
public:
virtual void BindRenderResource(RenderResource *rr)
{
if(!rr)
return;
rr->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
virtual ~VulkanApplicationFramework()
{
CloseShaderCompiler();
@ -91,7 +83,7 @@ public:
win->Unjoin(this);
SAFE_CLEAR(db);
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(cmd_buf,swap_chain_count);
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
SAFE_CLEAR(device);
SAFE_CLEAR(win);
@ -160,9 +152,9 @@ public:
vp_info.Set(w,h);
ubo_vp_info=db->CreateUBO("Viewport",sizeof(ViewportInfo),&vp_info);
}
BindRenderResource(db);
db->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
return(true);
}
@ -173,9 +165,9 @@ public:
ubo_vp_info->Write(&vp_info);
}
ViewportInfo *GetViewportInfo()
ViewportInfo &GetViewportInfo()
{
return &vp_info;
return vp_info;
}
DeviceBuffer *GetViewportInfoBuffer()
@ -205,7 +197,7 @@ public:
void InitCommandBuffer()
{
if(cmd_buf)
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(cmd_buf,swap_chain_count);
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
sc_render_target=device->GetSwapchainRT();
@ -216,37 +208,46 @@ 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,RenderPass *rp,Framebuffer *fb,Renderable *ri)
{
if(!ri)return(false);
const VertexInputData *vid=ri->GetVertexInputData();
cb->Begin();
cb->BindFramebuffer(fbo);
cb->BindFramebuffer(rp,fb);
cb->SetClearColor(0,clear_color);
cb->BeginRenderPass();
cb->BindPipeline(ri->GetPipeline());
cb->BindDescriptorSets(ri->GetMaterial());
cb->BindDataBuffer(ri->GetDataBuffer());
cb->Draw(ri->GetDataBuffer(),ri->GetRenderData());
cb->BindVBO(ri);
cb->Draw(vid);
cb->EndRenderPass();
cb->End();
return(true);
}
bool BuildCommandBuffer(uint32_t index,Mesh *ri)
void BuildCommandBuffer(RenderCmdBuffer *cb,RenderTarget *rt,Renderable *ri)
{
if(!cb||!rt||!ri)
return;
BuildCommandBuffer(cb,rt->GetRenderPass(),rt->GetFramebuffer(),ri);
}
bool BuildCommandBuffer(uint32_t index,Renderable *ri)
{
if(!ri)return(false);
return BuildCommandBuffer(cmd_buf[index],
sc_render_target->GetFramebuffer(),ri);
return BuildCommandBuffer(cmd_buf[index],sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index),ri);
}
bool BuildCommandBuffer(Mesh *ri)
bool BuildCommandBuffer(Renderable *ri)
{
if(!ri)return(false);
@ -256,7 +257,7 @@ public:
return(true);
}
bool BuildCurrentCommandBuffer(Mesh *ri)
bool BuildCurrentCommandBuffer(Renderable *ri)
{
if(!ri)return(false);
@ -270,7 +271,7 @@ public:
RenderCmdBuffer *cb=cmd_buf[index];
cb->Begin();
cb->BindFramebuffer(sc_render_target->GetFramebuffer(index));
cb->BindFramebuffer(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
cb->SetClearColor(0,clear_color);
cb->BeginRenderPass();
rl->Render(cb);
@ -346,6 +347,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:
@ -363,15 +483,6 @@ protected:
public:
virtual void BindRenderResource(RenderResource *rr) override
{
if(!rr)return;
VulkanApplicationFramework::BindRenderResource(rr);
rr->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
}
virtual ~CameraAppFramework()
{
SAFE_CLEAR(ckc);
@ -385,8 +496,6 @@ public:
return(false);
InitCamera(w,h);
BindRenderResource(db);
return(true);
}
@ -406,9 +515,11 @@ public:
win->Join(ckc);
win->Join(cmc);
RefreshCameraInfo(camera_control->GetCameraInfo(),&vp_info,camera);
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
ubo_camera_info=db->CreateUBO("CameraInfo",sizeof(CameraInfo),camera_control->GetCameraInfo());
ubo_camera_info=db->CreateUBO("CameraInfo",sizeof(CameraInfo),&camera_control->GetCameraInfo());
db->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
}
void Resize(uint w,uint h)override
@ -417,10 +528,10 @@ public:
camera_control->Refresh();
ubo_camera_info->Write(camera_control->GetCameraInfo());
ubo_camera_info->Write(&camera_control->GetCameraInfo());
}
CameraInfo *GetCameraInfo()
CameraInfo &GetCameraInfo()
{
return camera_control->GetCameraInfo();
}
@ -436,7 +547,7 @@ public:
{
camera_control->Refresh(); //更新相机矩阵
ubo_camera_info->Write(camera_control->GetCameraInfo()); //写入缓冲区
ubo_camera_info->Write(&camera_control->GetCameraInfo()); //写入缓冲区
const uint32_t index=AcquireNextImage();
@ -498,4 +609,4 @@ template<typename T> int RunApp(uint w,uint h)
while(app.Run());
return 0;
}
}

View File

@ -1,95 +0,0 @@
#pragma once
#include<hgl/WorkObject.h>
#include<hgl/graph/VKRenderTargetSwapchain.h>
namespace hgl
{
/**
* WorkObject<br>
*/
class WorkManager
{
protected:
graph::RenderFramework *render_framework;
uint fps=60;
double frame_time=1.0f/double(fps);
double last_update_time=0;
double last_render_time=0;
double cur_time=0;
WorkObject *cur_work_object=nullptr;
public:
WorkManager(graph::RenderFramework *rf)
{
render_framework=rf;
}
virtual ~WorkManager()
{
SAFE_CLEAR(cur_work_object);
}
void SetFPS(uint f)
{
fps=f;
frame_time=1.0f/double(fps);
}
void Tick(WorkObject *wo);
virtual void Render(WorkObject *wo);
void Run(WorkObject *wo);
};//class WorkManager
class SwapchainWorkManager:public WorkManager,public io::WindowEvent
{
graph::SwapchainModule *swapchain_module;
public:
SwapchainWorkManager(graph::RenderFramework *rf):WorkManager(rf)
{
swapchain_module=rf->GetSwapchainModule();
render_framework->Join(this);
}
~SwapchainWorkManager()
{
render_framework->Unjoin(this);
}
void Render(WorkObject *wo) override;
void OnResize(uint w,uint h) override;
};
template<typename WO> int RunFramework(const OSString &title,uint width=1280,uint height=720)
{
graph::RenderFramework rf(title);
if(!rf.Init(width,height))
return(-1);
SwapchainWorkManager wm(&rf);
WO *wo=new WO(&rf);
if(!wo->Init())
{
delete wo;
return(-2);
}
wm.Run(wo);
return 0;
}
}//namespcae hgl

View File

@ -1,123 +0,0 @@
#pragma once
#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>
namespace hgl
{
namespace graph::mtl
{
class MaterialCreateInfo;
}
/**
* </p>
*
* WorkObject被定义为工作对象WorkObject的Render函数下
*/
class WorkObject:public TickObject
{
graph::RenderFramework *render_framework=nullptr;
bool destroy_flag=false;
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();}
const VkExtent2D & GetExtent (){return renderer->GetExtent();}
graph::Scene * GetScene (){return scene;}
graph::SceneNode * GetSceneRoot (){return scene->GetRootNode();}
graph::Renderer * GetRenderer (){return renderer;}
graph::Camera * GetCamera (){return renderer->GetCamera();}
graph::CameraControl * GetCameraControl (){return render_framework->GetDefaultCameraControl();}
bool GetMouseCoord (Vector2i *mc)const{return render_framework->GetMouseCoord(mc);}
public:
const bool IsDestroy ()const{return destroy_flag;}
void MarkDestory(){destroy_flag=true;}
const bool IsRenderDirty ()const{return render_dirty;}
void MarkRenderDirty(){render_dirty=true;}
public:
WorkObject(graph::RenderFramework *,graph::Renderer *r=nullptr);
virtual ~WorkObject()=default;
virtual bool Init()=0;
virtual void OnRendererChange(graph::RenderFramework *rf,graph::Renderer *r);
virtual void OnResize(const VkExtent2D &){}
virtual void Tick(double){}
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;}
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::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;
}
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)
{
return render_framework?render_framework->CreateMesh(name,vertices_count,mi,pipeline,vad_list):nullptr;
}
public: //Component 相关
template<typename C,typename ...ARGS>
inline C *CreateComponent(ARGS...args)
{
return render_framework?render_framework->CreateComponent<C>(args...):nullptr; //创建组件
}
};//class WorkObject
/**
* .
* WorkObject的基础上再提供RenderWorkObject派生类
*
*
* 使WorkObject
* */
}//namespcae hgl

View File

@ -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还是SceneNodeComponent的管理
* AMD FidelityFX中的SceneScene
*
* 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
{

View File

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

View File

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

View File

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

View File

@ -1,45 +0,0 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
/**
*
*/
enum class LightingCullingMode
{
None, ///<不剔除
/**
*
*
*
*/
WorldCoord, ///<世界坐标剔除
/*
* Tile的剔除模式
* XY坐标划分成多个Tileznear/zfar形成一个VolumeVolume计算相交性
*/
Tile, ///<瓦片剔除
/**
* Tile的剔除模式的改进型
* Tile方法Tile后Tile内所有象素Tile的最远z值和最近z值
* XY与zNear/zFar得出一个VolumeVolume相交性
*/
TileVolume, ///<瓦片体积剔除
/**
* Tile的剔除模式的改进型
* TileVolume方法得出Volume后Volume按深度划分成多个Volume
* VolumeVolume与光源计算相交性
*/
Cluster, ///<集簇剔除
ENUM_CLASS_RANGE(None,Cluster)
};//enum class LightingCullingMode
VK_NAMESPACE_END

View File

@ -1,88 +1,41 @@
#pragma once
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/VKVABList.h>
#include<hgl/graph/VKIndirectCommandBuffer.h>
#include<hgl/graph/VKVBOList.h>
VK_NAMESPACE_BEGIN
class RenderL2WBuffer;
class RenderAssignBuffer;
class SceneNode;
struct CameraInfo;
struct RenderPipelineIndex:public Comparator<RenderPipelineIndex>
{
Material *material;
Pipeline *pipeline;
public:
const int compare(const RenderPipelineIndex &rli)const override
{
if(material<rli.material)return(-1);
if(material>rli.material)return(1);
if(pipeline<rli.pipeline)return(-1);
if(pipeline>rli.pipeline)return(1);
return(0);
}
public:
RenderPipelineIndex()
{
material=nullptr;
pipeline=nullptr;
}
RenderPipelineIndex(Material *m,Pipeline *p)
{
material=m;
pipeline=p;
}
};//struct RenderPipelineIndex
/**
* 线
*
*/
class MaterialRenderList
{
VulkanDevice *device;
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
RenderPipelineIndex rp_index;
CameraInfo *camera_info;
Material *material;
RenderNodeList rn_list;
RenderNodePointerList rn_update_l2w_list;
private:
RenderAssignBuffer *assign_buffer;
struct RenderItem
{
uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB)
uint32_t instance_count;
uint32_t first;
uint32_t count;
MaterialInstance * mi;
const MeshDataBuffer * pdb;
const MeshRenderData * prd;
Pipeline * pipeline;
MaterialInstance * mi;
const VertexInputData * vid;
public:
void Set(Mesh *);
void Set(Renderable *);
};
IndirectDrawBuffer *icb_draw;
IndirectDrawIndexedBuffer *icb_draw_indexed;
void ReallocICB();
void WriteICB(VkDrawIndirectCommand *,RenderItem *ri);
void WriteICB(VkDrawIndexedIndirectCommand *,RenderItem *ri);
DataArray<RenderItem> ri_array;
uint ri_count;
@ -90,36 +43,30 @@ private:
protected:
VABList * vab_list;
VBOList * vbo_list;
const MeshDataBuffer * last_data_buffer;
const VDM * last_vdm;
const MeshRenderData * last_render_data;
Pipeline * last_pipeline;
const VertexInputData * last_vid;
uint last_index;
int first_indirect_draw_index;
uint indirect_draw_count;
bool Bind(const VertexInputData *,const uint);
bool BindVAB(const MeshDataBuffer *,const uint);
void ProcIndirectRender();
bool Render(RenderItem *);
void Render(RenderItem *);
public:
MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi);
MaterialRenderList(GPUDevice *d,bool l2w,Material *m);
~MaterialRenderList();
void Add(MeshComponent *);
void Add(Renderable *ri,const Matrix4f &mat);
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
void Clear(){rn_list.Clear();}
void Clear()
{
rn_list.Clear();
}
void End();
void Render(RenderCmdBuffer *);
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
void UpdateMaterialInstance(MeshComponent *);
};//class MaterialRenderList
VK_NAMESPACE_END

View File

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

View File

@ -1,120 +0,0 @@
#pragma once
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/VKMaterialParameters.h>
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VertexAttrib.h>
VK_NAMESPACE_BEGIN
/**
* <Br>
*
*/
struct MeshDataBuffer:public Comparator<MeshDataBuffer>
{
uint32_t vab_count;
VkBuffer * vab_list;
// 理论上讲每个VAB绑定时都是可以指定byte offsets的。但是随后Draw时又可以指定vertexOffset。
// 在我们支持的两种draw模式中一种是每个模型一批VAB所有VAB的offset都是0。
// 另一种是使用VDM为了批量渲染所有的VAB又必须对齐所以每个VAB单独指定offset也不可行。
VkDeviceSize * vab_offset; //注意这里的offset是字节偏移不是顶点偏移
IndexBuffer * ibo;
VertexDataManager *vdm; //只是用来区分和比较的,不实际使用
public:
MeshDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr);
~MeshDataBuffer();
const int compare(const MeshDataBuffer &pdb)const override;
};//struct MeshDataBuffer
/**
* <Br>
*
*/
struct MeshRenderData:public ComparatorData<MeshRenderData>
{
//因为要VAB是流式访问所以我们这个结构会被用做排序依据
//也因此把vertex_offset放在最前面
int32_t vertex_offset; //注意这里的offset是相对于vertex的代表第几个顶点不是字节偏移
uint32_t first_index;
uint32_t vertex_count;
uint32_t index_count;
public:
MeshRenderData(const uint32_t vc,const uint32_t ic,const int32_t vo=0,const uint32_t fi=0)
{
vertex_count =vc;
index_count =ic;
vertex_offset =vo;
first_index =fi;
}
};
/**
* ()
*/
class Mesh
{
Pipeline * pipeline;
MaterialInstance * mat_inst;
Primitive * primitive;
MeshDataBuffer * data_buffer;
MeshRenderData * render_data;
private:
friend Mesh *CreateMesh(Primitive *,MaterialInstance *,Pipeline *);
Mesh(Primitive *,MaterialInstance *,Pipeline *,MeshDataBuffer *,MeshRenderData *);
public:
virtual ~Mesh()
{
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
SAFE_CLEAR(data_buffer);
SAFE_CLEAR(render_data);
}
void UpdatePipeline (Pipeline *p){pipeline=p;}
Pipeline * GetPipeline (){return pipeline;}
VkPipelineLayout GetPipelineLayout (){return mat_inst->GetMaterial()->GetPipelineLayout();}
Material * GetMaterial (){return mat_inst->GetMaterial();}
MaterialInstance * GetMaterialInstance (){return mat_inst;}
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;}
public:
bool ChangeMaterialInstance(MaterialInstance *mi)
{
if(!mi)
return(false);
if(mi->GetMaterial()!=mat_inst->GetMaterial()) //不能换母材质
return(false);
mat_inst=mi;
return(true);
}
};//class Mesh
Mesh *CreateMesh(Primitive *,MaterialInstance *,Pipeline *);
VK_NAMESPACE_END

View File

@ -1,19 +1,19 @@
#pragma once
#include<hgl/graph/VKBufferMap.h>
#include<hgl/graph/VertexAttribDataAccess.h>
#include<hgl/graph/VKShaderModule.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/VKIndexBuffer.h>
VK_NAMESPACE_BEGIN
/**
*
*
*/
class PrimitiveCreater
{
protected:
VulkanDevice * device;
GPUDevice * device;
VertexDataManager * vdm;
const VIL * vil;
@ -22,60 +22,200 @@ protected:
AnsiString prim_name;
PrimitiveData * prim_data;
uint32_t vertices_number; ///<顶点数量
bool has_index; ///<是否有索引
uint32_t index_number; ///<索引数量
IndexType index_type; ///<索引类型
IndexBuffer * ibo; ///<索引缓冲区
protected:
const int InitVAB(const AnsiString &name,const VkFormat format,const void *data); ///<取得顶点属性索引
VkDeviceSize vertices_number; ///<顶点数量
VkDeviceSize index_number; ///<索引数量
IndexType index_type; ///<索引类型
IBAccess * iba; ///<索引缓冲区
public:
PrimitiveCreater(VulkanDevice *,const VIL *);
PrimitiveCreater(GPUDevice *,const VIL *);
PrimitiveCreater(VertexDataManager *);
virtual ~PrimitiveCreater();
/**
*
* @parama name
* @parama vertices_count
* @parama index_count
* @parama it (使VDM时)
*/
bool Init(const AnsiString &name,
const uint32_t vertices_count,
const uint32_t index_count=0,IndexType it=IndexType::AUTO);
void Clear(); ///<清除创建器数据
virtual bool Init(const AnsiString &name,const VkDeviceSize vertices_count,const VkDeviceSize index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
void Clear(); ///<清除创建器数据
public: //顶点缓冲区
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
const VkDeviceSize GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
VABMap * GetVABMap (const AnsiString &name,const VkFormat format=VK_FORMAT_UNDEFINED);
bool WriteVAB (const AnsiString &name,const VkFormat format,const void *data); ///<直接写入顶点属性数据
VABAccess * AcquireVAB (const AnsiString &name,const VkFormat &format,const void *data=nullptr); ///<请求一个顶点属性数据区
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data) ///<直接写入顶点属性数据
{
return AcquireVAB(name,format,data);
}
public: //索引缓冲区
const bool hasIndex()const{return vdm?has_index:index_number>0;} ///<是否有索引缓冲区
const IndexType GetIndexType()const{return index_type;} ///<取得索引类型
const uint32_t GetIndexCount()const{return index_number;} ///<取得索引数量
const IndexType GetIndexType()const{return index_type;}
IBMap * GetIBMap();
void * MapIBO();
void UnmapIBO();
bool WriteIBO(const void *data,const uint32_t count);
bool WriteIBO(const void *data,const VkDeviceSize count);
template<typename T>
bool WriteIBO(const T *data){return WriteIBO(data,index_number);}
template<typename T>
bool WriteIBO(const T *data){return WriteIBO(data,index_number);}
public: //创建可渲染对象
Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
virtual Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
};//class PrimitiveCreater
VK_NAMESPACE_END
/**
* VAB原生数据访问映射
*/
template<typename T> class VABRawMap
{
VABAccess *vaba;
T *map_ptr;
public:
VABRawMap(PrimitiveCreater *pc,const VkFormat &format,const AnsiString &name)
{
vaba=pc->AcquireVAB(name,format);
if(vaba)
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
else
map_ptr=nullptr;
}
~VABRawMap()
{
if(vaba)
vaba->vab->Unmap();
}
const bool IsValid()const{ return vaba; }
operator T *(){ return map_ptr; }
};//template<typename T> class VABRawMap
typedef VABRawMap<int8> VABRawMapi8, VABRawMapByte;
typedef VABRawMap<int16> VABRawMapi16,VABRawMapShort;
typedef VABRawMap<int32> VABRawMapi32,VABRawMapInt;
typedef VABRawMap<uint8> VABRawMapu8, VABRawMapUByte;
typedef VABRawMap<uint16> VABRawMapu16,VABRawMapUShort;
typedef VABRawMap<uint32> VABRawMapu32,VABRawMapUInt;
typedef VABRawMap<float> VABRawMapFloat;
typedef VABRawMap<double> VABRawMapDouble;
/**
* VAB VertexAttribDataAccess数据访问映射
*/
template<typename T> class VABMap
{
VABAccess *vaba;
T *vb;
public:
VABMap(PrimitiveCreater *pc,const AnsiString &name)
{
vaba=pc->AcquireVAB(name,T::GetVulkanFormat(),nullptr);
if(vaba)
{
void *map_ptr=vaba->vab->Map(vaba->start,vaba->count);
vb=T::Create(pc->GetVertexCount(),map_ptr);
vb->Begin();
}
else
{
vb=nullptr;
}
}
~VABMap()
{
if(vaba)
vaba->vab->Unmap();
}
void Restart()
{
if(vb)
vb->Begin();
}
const bool IsValid()const{ return vb; }
T *operator->(){ return vb; }
};//template<typename T> class VABMap
typedef VABMap<VB1i8> VABMap1i8 ,VABMap1b;
typedef VABMap<VB1i16> VABMap1i16,VABMap1s;
typedef VABMap<VB1i32> VABMap1i32,VABMap1i;
typedef VABMap<VB1u8> VABMap1u8 ,VABMap1ub;
typedef VABMap<VB1u16> VABMap1u16,VABMap1us;
typedef VABMap<VB1u32> VABMap1u32,VABMap1ui;
typedef VABMap<VB1f> VABMap1f;
typedef VABMap<VB1d> VABMap1d;
typedef VABMap<VB2i8> VABMap2i8 ,VABMap2b;
typedef VABMap<VB2i16> VABMap2i16,VABMap2s;
typedef VABMap<VB2i32> VABMap2i32,VABMap2i;
typedef VABMap<VB2u8> VABMap2u8 ,VABMap2ub;
typedef VABMap<VB2u16> VABMap2u16,VABMap2us;
typedef VABMap<VB2u32> VABMap2u32,VABMap2ui;
typedef VABMap<VB2f> VABMap2f;
typedef VABMap<VB2d> VABMap2d;
typedef VABMap<VB3i32> VABMap3i32,VABMap3i;
typedef VABMap<VB3u32> VABMap3u32,VABMap3ui;
typedef VABMap<VB3f> VABMap3f;
typedef VABMap<VB3d> VABMap3d;
typedef VABMap<VB4i8> VABMap4i8 ,VABMap4b;
typedef VABMap<VB4i16> VABMap4i16,VABMap4s;
typedef VABMap<VB4i32> VABMap4i32,VABMap4i;
typedef VABMap<VB4u8> VABMap4u8, VABMap4ub;
typedef VABMap<VB4u16> VABMap4u16,VABMap4us;
typedef VABMap<VB4u32> VABMap4u32,VABMap4ui;
typedef VABMap<VB4f> VABMap4f;
typedef VABMap<VB4d> VABMap4d;
/**
* 访
*/
template<typename T> class IBMap
{
PrimitiveCreater *pc;
T *map_ptr;
public:
IBMap(PrimitiveCreater *c)
{
pc=c;
if(pc)
map_ptr=(T *)(pc->MapIBO());
else
map_ptr=nullptr;
}
~IBMap()
{
if(map_ptr&&pc)
pc->UnmapIBO();
}
const bool IsValid()const{ return map_ptr; }
operator T *(){ return map_ptr; }
};//template<typename T> class IBMap
using IBMapU8=IBMap<uint8>;
using IBMapU16=IBMap<uint16>;
using IBMapU32=IBMap<uint32>;
VK_NAMESPACE_END

View File

@ -1,273 +0,0 @@
#pragma once
#include<hgl/platform/Window.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKCommandBuffer.h>
#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
class FontSource;
class TileFont;
class RenderPassManager;
class TextureManager;
class RenderTargetManager;
class RenderModule;
class Scene;
class Renderer;
class CameraComponentManager{/*现阶段测试使用*/};
class LightComponentManager{/*现阶段测试使用*/};
class RenderFramework:public io::WindowEvent
{
OSString app_name;
Window * win =nullptr;
VulkanInstance * inst =nullptr;
VulkanDevice * device =nullptr;
RenderResource * render_resource =nullptr;
protected:
GraphModuleManager * module_manager =nullptr;
RenderPassManager * rp_manager =nullptr;
TextureManager * tex_manager =nullptr;
RenderTargetManager * rt_manager =nullptr;
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;}
VkDevice GetVkDevice ()const{return device->GetDevice();}
const VulkanPhyDevice * GetPhyDevice ()const{return device->GetPhyDevice();}
VulkanDevAttr * GetDevAttr ()const{return device->GetDevAttr();}
RenderResource * GetRenderResource ()const{return render_resource;}
public:
GraphModuleManager * GetModuleManager (){return module_manager;}
RenderPassManager * GetRenderPassManager (){return rp_manager;}
TextureManager * GetTextureManager (){return tex_manager;}
RenderTargetManager * GetRenderTargetManager (){return rt_manager;}
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 &);
virtual ~RenderFramework();
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));
}
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建只使用一种字符的Tile字符管理对象
public:
template<typename ...ARGS>
graph::Pipeline *CreatePipeline(ARGS...args)
{
return GetDefaultRenderPass()->CreatePipeline(args...);
}
graph::MaterialInstance *CreateMaterialInstance(const AnsiString &mi_name,const graph::mtl::MaterialCreateInfo *mci,const graph::VILConfig *vil_cfg=nullptr)
{
return render_resource->CreateMaterialInstance(mi_name,mci,vil_cfg);
}
graph::MaterialInstance *CreateMaterialInstance(const AnsiString &mtl_name,graph::mtl::MaterialCreateConfig *mtl_cfg,const graph::VILConfig *vil_cfg=nullptr)
{
AutoDelete<graph::mtl::MaterialCreateInfo> mci=graph::mtl::CreateMaterialCreateInfo(GetDevAttr(),mtl_name,mtl_cfg);
return render_resource->CreateMaterialInstance(mtl_name,mci,vil_cfg);
}
SharedPtr<graph::PrimitiveCreater> GetPrimitiveCreater(graph::Material *mtl)
{
if(!mtl)
return(nullptr);
return(new graph::PrimitiveCreater(GetDevice(),mtl->GetDefaultVIL()));
}
SharedPtr<graph::PrimitiveCreater> GetPrimitiveCreater(graph::MaterialInstance *mi)
{
if(!mi)
return(nullptr);
return(new graph::PrimitiveCreater(GetDevice(),mi->GetVIL()));
}
public: // Primitive, Mesh
graph::Primitive *CreatePrimitive(const AnsiString &name,
const uint32_t vertices_count,
const graph::VIL *vil,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
graph::Mesh *CreateMesh(const AnsiString &name,
const uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
public: // ComponentManager
template<typename T> T *GetComponentManager()
{
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

View File

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

View File

@ -1,47 +1,25 @@
#pragma once
#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
#define HGL_GRAPH_RENDER_NODE_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/SortedSet.h>
#include<hgl/type/SortedSets.h>
namespace hgl
{
namespace graph
{
class Mesh;
class Renderable;
class MaterialInstance;
class MeshComponent;
struct RenderNode:public Comparator<RenderNode>
struct RenderNode
{
uint index; ///<在MaterialRenderList中的索引
Matrix4f local_to_world;
MeshComponent *sm_component; ///<静态网格组件
uint32 l2w_version;
uint32 l2w_index;
Vector3f world_position;
float to_camera_distance;
public:
//该函数位于MaterialRenderList.cpp
const int compare(const RenderNode &)const override;
public:
Mesh *GetMesh()const;
MaterialInstance *GetMaterialInstance()const;
Renderable *ri;
};
using RenderNodeList=ArrayList<RenderNode>;
using RenderNodePointerList=ArrayList<RenderNode *>;
using RenderNodeList=List<RenderNode>;
using MaterialInstanceSets=SortedSet<MaterialInstance *>; ///<材质实例集合
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
}//namespace graph
template<> inline const int ItemComparator<graph::RenderNode>::compare(const graph::RenderNode &a,const graph::RenderNode &b)
{
return a.compare(b);
}
}//namespace hgl
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE

View File

@ -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

View File

@ -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

View File

@ -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

38
inc/hgl/graph/SceneInfo.h Normal file
View File

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

View File

@ -1,116 +0,0 @@
#pragma once
#include<hgl/math/Transform.h>
namespace hgl
{
namespace graph
{
/**
* <br>
*
* 3D空间中的位置<br>
* :<br>
* <ul>
* <li>LocalMatrix </li>
* <li>LocalToWorldMatrix 使</li>
*
* <li>transform_manager 0</li>
* </ul>
*
* LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TransformMatrix<br>
*/
class SceneMatrix :public VersionData<Matrix4f>
{
protected:
Matrix4f parent_matrix;
Matrix4f local_matrix;
bool local_is_identity;
Vector3f local_normal;
TransformManager transform_manager;
Matrix4f transform_matrix;
protected:
Vector3f OriginWorldPosition; //变换前世界坐标
Vector3f FinalWorldPosition; //变换后世界坐标
Vector3f OriginWorldNormal; //变换前世界法线
Vector3f FinalWorldNormal; //变换后世界法线
protected:
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵
void MakeNewestData(Matrix4f &local_to_world_matrix) override; ///<生成最新的数据(需要派生类重载)
public:
void Clear();
const Matrix4f &GetLocalMatrix()const{return local_matrix;} ///<取得本地矩阵
const Vector3f &GetLocalNormal()const{return local_normal;} ///<取得本地法线
const Matrix4f &GetLocalToWorldMatrix(){return GetNewestVersionData();} ///<取得本地到世界矩阵
const Matrix4f &GetInverseLocalToWorldMatrix(){UpdateNewestData();return inverse_local_to_world_matrix;} ///<取得世界到本地矩阵
const Matrix4f &GetInverseTransposeLocalToWorldMatrix() ///<取得世界到本地矩阵的转置矩阵
{
UpdateNewestData();
return inverse_transpose_local_to_world_matrix;
}
TransformManager &GetTransform(){return transform_manager;} ///<取得变换管理器
const Vector3f &GetWorldPosition()const{return FinalWorldPosition;} ///<取得世界坐标
const Vector3f &GetWorldNormal()const { return FinalWorldNormal; } ///<取得世界法线
public:
SceneMatrix():VersionData(Identity4f){Clear();}
SceneMatrix(SceneMatrix &so);
SceneMatrix(const Matrix4f &mat):VersionData(Identity4f)
{
SetLocalMatrix(mat);
UpdateVersion();
}
void SetLocalNormal(const Vector3f &normal)
{
//if(IsNearlyEqual(local_normal,normal))
if(!hgl_cmp(local_normal,normal))
return;
local_normal=normal;
UpdateVersion();
}
void SetLocalMatrix(const Matrix4f &mat)
{
//if (IsNearlyEqual(local_matrix,mat))
if(!hgl_cmp(local_matrix,mat))
return;
local_matrix=mat;
local_is_identity=IsIdentityMatrix(mat);
UpdateVersion();
}
void SetParentMatrix(const Matrix4f &pm)
{
//if (IsNearlyEqual(parent_matrix,pm))
if(!hgl_cmp(parent_matrix,pm))
return;
parent_matrix=pm;
UpdateVersion();
}
virtual void Update();
};//class SceneMatrix
}//namespace graph
}//namespace hgl

View File

@ -1,142 +1,108 @@
#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/VK.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)
/**
* <br>
* (SceneOrient)
* (/)
*/
class SceneNode:public SceneOrient ///场景节点类
namespace graph
{
SceneNode *parent_node=nullptr; ///<上级节点
SceneNodeID node_id=-1; ///<节点ID
SceneNodeName node_name; ///<节点名称
protected:
AABB bounding_box; ///<绑定盒
AABB local_bounding_box; ///<本地坐标绑定盒
//AABB WorldBoundingBox; ///<世界坐标绑定盒
protected:
SceneNodeList child_nodes; ///<子节点
/**
* SceneNode下可能会包含多个组件SceneNode使用
* ComponentManager管理
* <br>
* (SceneOrient)
* (/)
*/
ComponentSet component_set; ///<组件合集
public:
const SceneNodeID & GetNodeID ()const { return node_id; } ///<取得节点ID
const SceneNodeName & GetNodeName ()const { return node_name; } ///<取得节点名称
const SceneNodeList & GetChildNode()const { return child_nodes; } ///<取得子节点列表
public:
SceneNode()=default;
SceneNode(const SceneNode &)=delete;
SceneNode(const SceneNode *)=delete;
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
public:
virtual ~SceneNode();
void Clear() override
class SceneNode:public SceneOrient ///场景节点类
{
SceneOrient::Clear();
protected:
parent_node=nullptr;
AABB BoundingBox; ///<绑定盒
AABB LocalBoundingBox; ///<本地坐标绑定盒
//AABB WorldBoundingBox; ///<世界坐标绑定盒
bounding_box.SetZero();
local_bounding_box.SetZero();
Vector4f Center; ///<中心点
Vector4f LocalCenter; ///<本地坐标中心点
Vector4f WorldCenter; ///<世界坐标中心点
child_nodes.Clear();
component_set.Clear();
}
Renderable *render_obj=nullptr; ///<可渲染实例
const bool ChildNodeIsEmpty()const
{
if(child_nodes.GetCount())return(false);
public:
return(true);
}
ObjectList<SceneNode> SubNode; ///<子节点
void SetParent(SceneNode *sn) {parent_node=sn;}
SceneNode * GetParent() noexcept{return parent_node;}
const SceneNode * GetParent()const noexcept{return parent_node;}
public:
SceneNode *Add(SceneNode *sn)
{
if(!sn)
return(nullptr);
SceneNode()=default;
SceneNode( Renderable *ri ) {render_obj=ri;}
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
child_nodes.Add(sn);
sn->SetParent(this);
return sn;
}
virtual ~SceneNode()=default;
public: //坐标相关方法
void Clear()
{
SubNode.Clear();
render_obj=nullptr;
}
virtual void SetBoundingBox (const AABB &bb){bounding_box=bb;} ///<设置绑定盒
Renderable *GetRenderable(){return render_obj;}
void SetRenderable(Renderable *);
virtual void RefreshMatrix () override; ///<刷新世界变换
virtual void RefreshBoundingBox (); ///<刷新绑定盒
SceneNode *CreateSubNode()
{
SceneNode *sn=new SceneNode();
virtual const AABB & GetBoundingBox ()const{return bounding_box;} ///<取得绑定盒
virtual const AABB & GetLocalBoundingBox ()const{return local_bounding_box;} ///<取得本地坐标绑定盒
SubNode.Add(sn);
return sn;
}
SceneNode *CreateSubNode(Renderable *ri)
{
if(!ri)
return(nullptr);
SceneNode *sn=new SceneNode(ri);
SubNode.Add(sn);
return sn;
}
SceneNode *CreateSubNode(const Matrix4f &mat)
{
SceneNode *sn=new SceneNode(mat);
SubNode.Add(sn);
return sn;
}
SceneNode *CreateSubNode(const Matrix4f &mat,Renderable *ri)
{
if(!ri)
return(nullptr);
SceneNode *sn=new SceneNode(mat,ri);
SubNode.Add(sn);
return sn;
}
public: //坐标相关方法
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
virtual void RefreshMatrix (const Matrix4f *mat=nullptr); ///<刷新世界变换矩阵
virtual void RefreshBoundingBox (); ///<刷新绑定盒
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
virtual const Vector4f & GetCenter ()const{return Center;} ///<取得中心点
virtual const Vector4f & GetLocalCenter ()const{return LocalCenter;} ///<取得本地坐标中心点
virtual const Vector4f & GetWorldCenter ()const{return WorldCenter;} ///<取得世界坐标中心点
};//class SceneNode
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE

View File

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

View File

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

View File

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

View File

@ -0,0 +1,25 @@
#ifndef HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
#define HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class RawMesh
{
};
/**
* <br>
*
*/
class StaticRenderManager
{
public:
virtual ~StaticRenderManager()=default;
};//class StaticRenderManager
VK_NAMESPACE_END
#endif//HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE

View File

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

View File

@ -12,15 +12,13 @@ namespace hgl
{
namespace graph
{
class TextureManager;
/**
* TileData是一种处理大量等同尺寸及格式贴图的管理机制(Tile的大小不必符合2次幂)
* Tile的增加或删除I/O消耗
*/
class TileData ///Tile纹理管理
{
TextureManager *tex_manager;
GPUDevice *device;
protected:
@ -37,7 +35,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数据
@ -53,8 +51,8 @@ namespace hgl
Texture2D * GetTexture ()const{return tile_texture;} ///<取得贴图
public:
TileData(TextureManager *,Texture2D *,const uint tw,const uint th);
TileData(GPUDevice *,Texture2D *,const uint tw,const uint th);
virtual ~TileData();
void BeginCommit();

View File

@ -1,6 +1,7 @@
#pragma once
#ifndef HGL_GRAPH_VULKAN_INCLUDE
#define HGL_GRAPH_VULKAN_INCLUDE
#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>
@ -8,7 +9,6 @@
#include<hgl/graph/VKFormat.h>
#include<hgl/graph/VKPrimitiveType.h>
#include<hgl/graph/VKStruct.h>
#include<hgl/graph/ViewportInfo.h>
#include<hgl/graph/VKRenderbufferInfo.h>
VK_NAMESPACE_BEGIN
@ -25,35 +25,19 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
struct VertexAttribDataPtr
{
const char * name;
const VkFormat format;
const void * data;
};
using BindingMap =Map<AnsiString,int>;
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
class DescriptorBinding;
class GraphModule;
class RenderFramework;
class VulkanInstance;
class VulkanPhyDevice;
class VulkanDevice;
struct VulkanDevAttr;
class GPUPhysicalDevice;
class GPUDevice;
struct GPUDeviceAttribute;
class DeviceQueue;
class ImageView;
class Framebuffer;
struct Swapchain;
class IRenderTarget;
class RenderTarget;
class MultiFrameRenderTarget;
class SwapchainRenderTarget;
struct CopyBufferToImageInfo;
class RTSwapchain;
class Texture;
class Texture1D;
@ -66,25 +50,38 @@ class TextureCubeArray;
class Sampler;
class TileData;
class DeviceMemory;
class DeviceBuffer;
struct DeviceBufferData;
template<typename T> class DeviceBufferMap;
struct MeshDataBuffer;
struct MeshRenderData;
struct VertexInputData;
class VertexAttribBuffer;
using VAB=VertexAttribBuffer;
struct VABAccess
{
VAB *vab;
VkDeviceSize start;
VkDeviceSize count;
public:
CompOperatorMemcmp(const VABAccess &);
};//class VABAccess
class IndexBuffer;
class VABMap;
class IBMap;
struct IndexBufferAccess
{
IndexBuffer *buffer;
VkDeviceSize start;
VkDeviceSize count;
};
class VulkanCmdBuffer;
using IBAccess=IndexBufferAccess;
class GPUCmdBuffer;
class RenderCmdBuffer;
class TextureCmdBuffer;
@ -96,9 +93,8 @@ class Semaphore;
struct PipelineLayoutData;
class DescriptorSet;
enum class DescriptorSetType;
struct VertexInputAttribute;
struct ShaderAttribute;
class ShaderResource;
class ShaderModule;
@ -124,28 +120,11 @@ using VIL=VertexInputLayout;
class PrimitiveData;
class Primitive;
class Mesh;
class Renderable;
class VertexDataManager;
using VDM=VertexDataManager;
class IndirectDrawBuffer;
class IndirectDrawIndexedBuffer;
class IndirectDispatchBuffer;
class RenderResource;
class MeshComponent;
class SceneNode;
class Scene;
class RenderList;
struct CameraInfo;
struct Camera;
class Renderer;
enum class SharingMode
{
Exclusive = 0,
@ -203,5 +182,5 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
e3d.height =e2d.height;
e3d.depth =depth;
}
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_INCLUDE

View File

@ -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

View File

@ -1,9 +1,8 @@
#pragma once
#ifndef HGL_GRAPH_VULKAN_BUFFER_INCLUDE
#define HGL_GRAPH_VULKAN_BUFFER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKMemory.h>
#include<hgl/graph/mtl/ShaderBufferSource.h>
VK_NAMESPACE_BEGIN
struct DeviceBufferData
{
@ -21,10 +20,9 @@ protected:
private:
friend class VulkanDevice;
friend class GPUDevice;
friend class VertexAttribBuffer;
friend class IndexBuffer;
template<typename T> friend class IndirectCommandBuffer;
DeviceBuffer(VkDevice d,const DeviceBufferData &b)
{
@ -51,68 +49,5 @@ public:
virtual bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
};//class DeviceBuffer
template<typename T> class DeviceBufferMap
{
protected:
DeviceBuffer *dev_buf;
T data_map;
public:
static const VkDeviceSize GetSize()
{
return sizeof(T);
}
public:
DeviceBufferMap(DeviceBuffer *buf)
{
dev_buf=buf;
}
virtual ~DeviceBufferMap()
{
delete dev_buf;
}
DeviceBuffer *GetDeviceBuffer(){return dev_buf;}
T *data(){return &data_map;}
void Update()
{
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
#endif//HGL_GRAPH_VULKAN_BUFFER_INCLUDE

View File

@ -1,101 +0,0 @@
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/VertexAttribDataAccess.h>
VK_NAMESPACE_BEGIN
template<typename T> class VKBufferMap
{
protected:
T *buffer;
int32_t offset;
uint32_t stride;
uint32_t count;
void *map_ptr;
public:
VKBufferMap()
{
buffer=nullptr;
offset=0;
stride=count=0;
map_ptr=nullptr;
}
virtual ~VKBufferMap()
{
Unmap();
}
void Bind(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
{
buffer=buf;
offset=off;
stride=s;
count=c;
map_ptr=nullptr;
}
const int32_t GetOffset ()const{ return offset;}
const uint32_t GetStride ()const{ return stride;}
const uint32_t GetCount ()const{ return count; }
const bool IsValid()const{ return buffer; }
void Clear()
{
Unmap();
buffer=nullptr;
offset=0;
stride=count=0;
}
void *Map()
{
if(map_ptr)
return(map_ptr);
if(!buffer)
return(nullptr);
map_ptr=buffer->Map(offset,count);
return map_ptr;
}
void Unmap()
{
if(buffer&&map_ptr)
{
buffer->Unmap();
map_ptr=nullptr;
}
}
bool Write(const void *data,const uint32_t c)
{
if(!data||c==0||c>count)return(false);
if(!map_ptr)
{
if(!buffer)
return(false);
/*
* offset还是cVAB/IndexBuffer的虚拟版本
*
*
* buffer->DeviceBuffer::Write()
*/
return buffer->Write(data,offset,c);
}
memcpy(map_ptr,data,stride*c);
return(true);
}
};//class VKBufferMap
VK_NAMESPACE_END

View File

@ -1,96 +1,60 @@
#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/VKVBOList.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/Mesh.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;
bool cmd_begin;
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;}
operator const VkCommandBuffer *()const{return &cmd_buf;}
const bool IsBegin()const{return cmd_begin;}
virtual bool Begin();
virtual bool End()
{
if(!cmd_begin)
return(false);
cmd_begin=false;
return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);
}
bool Begin();
bool End(){return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);}
#ifdef _DEBUG
void SetDebugName(const AnsiString &);
void BeginRegion(const AnsiString &,const Color4f &);
void SetDebugName(const UTF8String &);
void BeginRegion(const UTF8String &,const Color4f &);
void EndRegion();
#else
void BeginRegion(const AnsiString &,const Color4f &){}
void BeginRegion(const UTF8String &,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;
VkRect2D render_area;
VkViewport viewport;
Framebuffer *fbo;
RenderPassBeginInfo rp_begin;
VkPipelineLayout pipeline_layout;
/*
* desc绑定会全部使用这些自动绑定器绑定
*
*
* DescriptSetType::RenderTarget RenderTarget模块设置
* DescriptSetType::Scene Scene模块设置
*/
DescriptorBindingPtrArray desc_binding{};
private:
void SetClear();
void SetFBO(Framebuffer *);
public:
RenderCmdBuffer(const VulkanDevAttr *attr,VkCommandBuffer cb);
RenderCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb);
~RenderCmdBuffer();
bool SetDescriptorBinding(DescriptorBinding *);
bool End() override
{
hgl_zero(desc_binding);
return VulkanCmdBuffer::End();
}
void SetRenderArea(const VkRect2D &ra){render_area=ra;}
void SetRenderArea(const VkExtent2D &);
void SetViewport(const VkViewport &vp){viewport=vp;}
@ -114,7 +78,7 @@ public:
//以上设定在Begin开始后即不可改变
bool BindFramebuffer(Framebuffer *);
bool BindFramebuffer(RenderPass *rp,Framebuffer *fb);
bool BeginRenderPass();
void NextSubpass(){vkCmdNextSubpass(cmd_buf,VK_SUBPASS_CONTENTS_INLINE);}
@ -190,29 +154,25 @@ public:
void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);}
void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);}
void BindVAB(const uint32_t first,const uint32_t count,const VkBuffer *vab,const VkDeviceSize *offsets)
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vab,const VkDeviceSize *offsets)
{
vkCmdBindVertexBuffers(cmd_buf,first,count,vab,offsets);
}
bool BindVAB(VABList *vab_list)
bool BindVBO(VBOList *vbo_list)
{
if(!vab_list)return(false);
if(!vbo_list)return(false);
if(!vab_list->IsFull())return(false);
if(!vbo_list->IsFull())return(false);
vkCmdBindVertexBuffers(cmd_buf,
0, //first binding
vab_list->vab_count, //binding count
vab_list->vab_list, //buffers
vab_list->vab_offset); //buffer offsets
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
return(true);
}
void BindIBO(IndexBuffer *,const VkDeviceSize byte_offset=0);
// void BindIBO(const IBAccess *);
bool BindDataBuffer(const MeshDataBuffer *);
bool BindVBO(Renderable *);
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
@ -231,15 +191,6 @@ public: //draw
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count,const uint32_t firstIndex,const int32_t vertexOffset,const uint32_t firstInstance)
{
vkCmdDrawIndexed(cmd_buf,
index_count,
instance_count,
firstIndex,
vertexOffset,
firstInstance);
}
// template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
// template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
@ -249,31 +200,19 @@ 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 VertexInputData *vid);
void DrawIndexed (const IBAccess *iba,const uint32_t instance_count);
public: //dynamic state
};//class RenderCmdBuffer:public GPUCmdBuffer
public:
void Render(Mesh *ri)
{
if(!ri)return;
BindPipeline(ri->GetPipeline());
BindDescriptorSets(ri->GetMaterial());
BindDataBuffer(ri->GetDataBuffer());
Draw(ri->GetDataBuffer(),ri->GetRenderData());
}
};//class RenderCmdBuffer:public VulkanCmdBuffer
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 +249,6 @@ public:
0, nullptr,
1, &imageMemoryBarrier);
}
};//class TextureCmdBuffer:public VulkanCmdBuffer
};//class TextureCmdBuffer:public GPUCmdBuffer
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE

View File

@ -3,7 +3,6 @@
#include<hgl/graph/VK.h>
#include<hgl/color/Color4f.h>
#include<hgl/graph/VKTexture.h>
VK_NAMESPACE_BEGIN
struct DebugUtilsFunction
@ -93,13 +92,6 @@ public:
// DU_FUNC(BufferCollectionFuchsia, BUFFER_COLLECTION_FUCHSIA)
#undef DU_FUNC
void SetTexture(Texture *tex,const AnsiString &info)
{
SetImage( tex->GetImage(), info+"_Image" );
SetImageView( tex->GetVulkanImageView(), info+"_ImageView" );
SetDeviceMemory(tex->GetDeviceMemory(), info+"_Memory" );
}
void QueueBegin (VkQueue,const char *,const Color4f &color=Color4f(1,1,1,1));
void QueueEnd (VkQueue q){duf.QueueEnd(q);}

View File

@ -1,142 +1,112 @@
#pragma once
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
#include<hgl/type/Map.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKBuffer.h>
VK_NAMESPACE_BEGIN
class DeviceBuffer;
class Texture;
class Material;
class MaterialParameters;
/**
* <Br>
*
*/
class DescriptorBinding
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl
{
DescriptorSetType set_type; ///<描述符合集类型
Map<AnsiString,DeviceBuffer *> ubo_map;
Map<AnsiString,DeviceBuffer *> ssbo_map;
Map<AnsiString,Texture *> texture_map;
public:
const DescriptorSetType GetType()const{return set_type;}
public:
DescriptorBinding(const DescriptorSetType &dst)
namespace graph
{
set_type=dst;
}
class DeviceBuffer;
class Texture;
class Material;
class MaterialParameters;
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
/**
* <Br>
*
*/
class DescriptorBinding
{
DescriptorSetType set_type; ///<描述符合集类型
return ubo_map.Add(name,buf);
}
Map<AnsiString,DeviceBuffer *> ubo_map;
Map<AnsiString,DeviceBuffer *> ssbo_map;
Map<AnsiString,Texture *> texture_map;
template<typename T>
bool AddUBO(const AnsiString &name,DeviceBufferMap<T> *dbm)
{
if(name.IsEmpty()||!dbm)
return(false);
public:
return ubo_map.Add(name,dbm->GetDeviceBuffer());
}
DescriptorBinding(const DescriptorSetType &dst)
{
set_type=dst;
}
template<typename T>
bool AddUBO(const UBOInstance<T> *ubo_instance)
{
if(!ubo_instance)
return(false);
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
if(ubo_instance->set_type()!=set_type)
return(false);
return ubo_map.Add(name,buf);
}
if(ubo_instance->name().IsEmpty())
return(false);
DeviceBuffer *GetUBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return ubo_map.Add(ubo_instance->name(),ubo_instance->ubo());
}
return GetListObject(ubo_map,name);
}
DeviceBuffer *GetUBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
void RemoveUBO(DeviceBuffer *buf)
{
if(!buf)return;
return GetObjectFromMap(ubo_map,name);
}
ubo_map.DeleteByValue(buf);
}
void RemoveUBO(DeviceBuffer *buf)
{
if(!buf)return;
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
ubo_map.DeleteByValue(buf);
}
return ssbo_map.Add(name,buf);
}
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
DeviceBuffer *GetSSBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return ssbo_map.Add(name,buf);
}
return GetListObject(ssbo_map,name);
}
template<typename T>
bool AddSSBO(const AnsiString &name,DeviceBufferMap<T> *dbm)
{
return AddSSBO(name,dbm->GetDeviceBuffer());
}
void RemoveSSBO(DeviceBuffer *buf)
{
if(!buf)return;
DeviceBuffer *GetSSBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
ssbo_map.DeleteByValue(buf);
}
return GetObjectFromMap(ssbo_map,name);
}
bool AddTexture(const AnsiString &name,Texture *tex)
{
if(!tex)return(false);
if(name.IsEmpty())return(false);
void RemoveSSBO(DeviceBuffer *buf)
{
if(!buf)return;
return texture_map.Add(name,tex);
}
ssbo_map.DeleteByValue(buf);
}
Texture *GetTexture(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
bool AddTexture(const AnsiString &name,Texture *tex)
{
if(!tex)return(false);
if(name.IsEmpty())return(false);
return GetListObject(texture_map,name);
}
return texture_map.Add(name,tex);
}
void RemoveTexture(Texture *tex)
{
if(!tex)return;
Texture *GetTexture(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
texture_map.DeleteByValue(tex);
}
return GetObjectFromMap(texture_map,name);
}
private:
void RemoveTexture(Texture *tex)
{
if(!tex)return;
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
texture_map.DeleteByValue(tex);
}
public:
private:
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
public:
bool Bind(Material *);
};//class DescriptorBinding
VK_NAMESPACE_END
bool Bind(Material *);
};//class DescriptorBinding
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE

View File

@ -4,23 +4,23 @@
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/type/ObjectList.h>
#include<hgl/type/SortedSet.h>
#include<hgl/type/SortedSets.h>
VK_NAMESPACE_BEGIN
class DeviceBuffer;
class DescriptorSet
{
VkDevice device;
int vab_count;
int binding_count;
VkDescriptorSet desc_set;
VkPipelineLayout pipeline_layout;
ObjectList<VkDescriptorBufferInfo> vab_list;
ObjectList<VkDescriptorBufferInfo> buffer_list;
ObjectList<VkDescriptorImageInfo> image_list;
ArrayList<VkWriteDescriptorSet> wds_list;
List<VkWriteDescriptorSet> wds_list;
SortedSet<uint32_t> binded_sets;
SortedSets<uint32_t> binded_sets;
bool is_dirty;
@ -29,7 +29,7 @@ public:
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
{
device =dev;
vab_count =bc;
binding_count =bc;
desc_set =ds;
pipeline_layout =pl;
@ -38,11 +38,11 @@ public:
~DescriptorSet()=default;
const uint32_t GetCount ()const{return vab_count;}
const uint32_t GetCount ()const{return binding_count;}
const VkDescriptorSet GetDescriptorSet ()const{return desc_set;}
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
const bool IsReady ()const{return wds_list.GetCount()==vab_count;}
const bool IsReady ()const{return wds_list.GetCount()==binding_count;}
void Clear();

View File

@ -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,37 +21,53 @@ VK_NAMESPACE_BEGIN
class TileData;
class TileFont;
class FontSource;
class VulkanArrayBuffer;
class IndirectDrawBuffer;
class IndirectDrawIndexedBuffer;
class IndirectDispatchBuffer;
class GPUArrayBuffer;
struct CopyBufferToImageInfo;
class VulkanDevice
class GPUDevice
{
VulkanDevAttr *attr;
GPUDeviceAttribute *attr;
DeviceQueue *texture_queue;
TextureCmdBuffer *texture_cmd_buf;
private:
DeviceRenderPassManage *render_pass_manage;
RenderPass *device_render_pass;
RTSwapchain *sc_rt;
RTSwapchain *CreateSwapchainRenderTarget();
void InitRenderPassManage();
void ClearRenderPassManage();
private:
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
bool CreateSwapchainFBO(Swapchain *);
Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent);
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;}
@ -59,11 +76,15 @@ public:
const VkColorSpaceKHR GetColorSpace ()const {return attr->surface_format.colorSpace;}
VkQueue GetGraphicsQueue () {return attr->graphics_queue;}
RenderPass * GetRenderPass () {return device_render_pass;}
RTSwapchain * GetSwapchainRT () {return sc_rt;}
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
#ifdef _DEBUG
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
#endif//_DEBUG
public:
@ -117,25 +138,7 @@ public: //Buffer相关
#define CREATE_BUFFER_OBJECT(LargeName,type) DeviceBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
DeviceBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,data, sm);} \
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);} \
\
template<typename T> T *Create##LargeName() \
{ \
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); \
}
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);}
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
@ -143,16 +146,59 @@ 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: //间接绘制
public: //Image
bool CreateIndirectCommandBuffer(DeviceBufferData *,const uint32_t cmd_count,const uint32_t cmd_size,SharingMode sm=SharingMode::Exclusive);
VkImage CreateImage (VkImageCreateInfo *);
void DestroyImage (VkImage);
IndirectDrawBuffer * CreateIndirectDrawBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
IndirectDrawIndexedBuffer * CreateIndirectDrawIndexedBuffer(const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
IndirectDispatchBuffer * CreateIndirectDispatchBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
private: //texture
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool CommitTextureCube (TextureCube *,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
bool CommitTextureCubeMipmaps (TextureCube *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
public: //Texture
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal)const;
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
Texture2D *CreateTexture2D(TextureData *);
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(TextureData *);
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
TextureCube *CreateTextureCube(TextureData *);
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
void Clear(TextureCreateInfo *);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,void *data,const uint32_t size,const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,void *data,const uint32_t size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
public: //
@ -174,15 +220,30 @@ public: //Command Buffer 相关
public:
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
Fence * CreateFence(bool);
Semaphore * CreateGPUSemaphore();
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
public: //FrameBuffer相关
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *);
public:
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
public:
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class VulkanDevice
};//class GPUDevice
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE

View File

@ -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

View File

@ -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)
{

View File

@ -0,0 +1,37 @@
#ifndef HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#define HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/util/hash/Hash.h>
VK_NAMESPACE_BEGIN
using RenderPassHASHCode=util::HashCodeSHA1LE;
class DeviceRenderPassManage
{
VkDevice device;
VkPipelineCache pipeline_cache;
util::Hash *hash;
Map<RenderPassHASHCode,RenderPass *> RenderPassList;
private:
friend class GPUDevice;
DeviceRenderPassManage(VkDevice,VkPipelineCache);
~DeviceRenderPassManage();
private:
RenderPass * CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
const List<VkSubpassDescription> &subpass,
const List<VkSubpassDependency> &dependency,
const RenderbufferInfo *);
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
};//class DeviceRenderPassManage
VK_NAMESPACE_END
#endif//HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE

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