added InstanceTriangle example and few support.
This commit is contained in:
parent
ea93dfcc86
commit
1e0e74da2f
@ -5,94 +5,61 @@
|
|||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/math/Math.h>
|
#include<hgl/math/Math.h>
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/graph/InlineGeometry.h>
|
#include<hgl/graph/SceneInfo.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
constexpr uint32_t SCREEN_SIZE=512;
|
||||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
|
||||||
|
constexpr uint32_t VERTEX_COUNT=3;
|
||||||
|
|
||||||
|
constexpr float position_data[VERTEX_COUNT][2]=
|
||||||
|
{
|
||||||
|
{0,0},
|
||||||
|
{0.25,-0.75},
|
||||||
|
{0,-1}
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr float color_data[VERTEX_COUNT][4]=
|
||||||
|
{ {1,0,0,1},
|
||||||
|
{0,1,0,1},
|
||||||
|
{0,0,1,1}
|
||||||
|
};
|
||||||
|
|
||||||
class TestApp:public VulkanApplicationFramework
|
class TestApp:public VulkanApplicationFramework
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
double start_time;
|
|
||||||
|
|
||||||
MaterialInstance * material_instance =nullptr;
|
MaterialInstance * material_instance =nullptr;
|
||||||
Renderable * renderable_object =nullptr;
|
|
||||||
RenderableInstance *render_instance =nullptr;
|
RenderableInstance *render_instance =nullptr;
|
||||||
|
|
||||||
Pipeline * pipeline =nullptr;
|
Pipeline * pipeline =nullptr;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
TestApp()
|
|
||||||
{
|
|
||||||
start_time=GetDoubleTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
~TestApp()=default;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool InitMaterial()
|
bool InitMaterial()
|
||||||
{
|
{
|
||||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/Vertex2DColor"));
|
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||||
|
|
||||||
if(!material_instance)
|
if(!material_instance)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles);
|
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||||
|
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||||
|
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitUBO()
|
bool InitVBO()
|
||||||
{
|
{
|
||||||
color_material.diffuse.Set(1,1,1);
|
Renderable *render_obj=db->CreateRenderable(VERTEX_COUNT);
|
||||||
color_material.abiment.Set(0.25,0.25,0.25);
|
if(!render_obj)return(false);
|
||||||
|
|
||||||
ubo_color=db->CreateUBO(sizeof(color_material),&color_material);
|
if(!render_obj->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||||
if(!ubo_color)return(false);
|
if(!render_obj->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data)))return(false);
|
||||||
|
|
||||||
sun_direction=normalized(Vector3f(rand(),rand(),rand()));
|
|
||||||
|
|
||||||
ubo_sun=db->CreateUBO(sizeof(sun_direction),&sun_direction);
|
|
||||||
if(!ubo_sun)return(false);
|
|
||||||
|
|
||||||
{
|
|
||||||
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value);
|
|
||||||
|
|
||||||
if(!mp)return(false);
|
|
||||||
|
|
||||||
mp->BindUBO("material",ubo_color);
|
|
||||||
mp->BindUBO("sun",ubo_sun);
|
|
||||||
|
|
||||||
mp->Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
BindCameraUBO(material_instance);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool InitRenderable()
|
|
||||||
{
|
|
||||||
CubeCreateInfo cci;
|
|
||||||
|
|
||||||
cci.tangent=false;
|
|
||||||
cci.tex_coord=false;
|
|
||||||
|
|
||||||
renderable_object=CreateRenderableCube(db,material_instance->GetVAB(),&cci);
|
|
||||||
|
|
||||||
if(!renderable_object)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
render_instance=db->CreateRenderableInstance(renderable_object,material_instance,pipeline);
|
|
||||||
|
|
||||||
if(!render_instance)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
|
render_instance=db->CreateRenderableInstance(render_obj,material_instance,pipeline);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,19 +67,16 @@ public:
|
|||||||
|
|
||||||
bool Init()
|
bool Init()
|
||||||
{
|
{
|
||||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(!InitMaterial())
|
if(!InitMaterial())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(!InitUBO())
|
if(!InitVBO())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(!InitRenderable())
|
if(!BuildCommandBuffer(render_instance))
|
||||||
return(false);
|
|
||||||
|
|
||||||
if(!VulkanApplicationFramework::BuildCommandBuffer(render_instance))
|
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
@ -122,7 +86,7 @@ public:
|
|||||||
{
|
{
|
||||||
VulkanApplicationFramework::Resize(w,h);
|
VulkanApplicationFramework::Resize(w,h);
|
||||||
|
|
||||||
VulkanApplicationFramework::BuildCommandBuffer(render_instance);
|
BuildCommandBuffer(render_instance);
|
||||||
}
|
}
|
||||||
};//class TestApp:public VulkanApplicationFramework
|
};//class TestApp:public VulkanApplicationFramework
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public:
|
|||||||
|
|
||||||
cili.lunarg.standard_validation = true;
|
cili.lunarg.standard_validation = true;
|
||||||
cili.khronos.validation = true;
|
cili.khronos.validation = true;
|
||||||
cili.RenderDoc.Capture = true;
|
//cili.RenderDoc.Capture = true;
|
||||||
|
|
||||||
inst=CreateInstance("VulkanTest",nullptr,&cili);
|
inst=CreateInstance("VulkanTest",nullptr,&cili);
|
||||||
|
|
||||||
@ -223,9 +223,9 @@ public:
|
|||||||
cb->BindVBO(ri);
|
cb->BindVBO(ri);
|
||||||
|
|
||||||
if (ib)
|
if (ib)
|
||||||
cb->DrawIndexed(ib->GetCount());
|
cb->DrawIndexed(ib->GetCount(),ri->GetInstanceCount());
|
||||||
else
|
else
|
||||||
cb->Draw(ri->GetDrawCount());
|
cb->Draw(ri->GetDrawCount(),ri->GetInstanceCount());
|
||||||
|
|
||||||
cb->EndRenderPass();
|
cb->EndRenderPass();
|
||||||
cb->End();
|
cb->End();
|
||||||
|
@ -49,7 +49,7 @@ namespace hgl
|
|||||||
RenderableCreater(RenderResource *sdb,const VAB *);
|
RenderableCreater(RenderResource *sdb,const VAB *);
|
||||||
virtual ~RenderableCreater()=default;
|
virtual ~RenderableCreater()=default;
|
||||||
|
|
||||||
virtual bool Init(const uint32 count); ///<初始化,参数为顶点数量
|
virtual bool Init(const uint32 vertices_count); ///<初始化,参数为顶点数量
|
||||||
|
|
||||||
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
||||||
|
|
||||||
|
@ -158,8 +158,10 @@ public:
|
|||||||
|
|
||||||
public: //draw
|
public: //draw
|
||||||
|
|
||||||
void Draw (const uint32_t vertex_count) {vkCmdDraw(cmd_buf,vertex_count,1,0,0);}
|
void Draw (const uint32_t vertex_count) {vkCmdDraw(cmd_buf,vertex_count,1,0,0);}
|
||||||
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
|
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
|
||||||
|
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
|
||||||
|
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
|
||||||
|
|
||||||
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||||
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||||
|
@ -53,6 +53,10 @@ public:
|
|||||||
const uint32_t GetBufferHash ()const{return buffer_hash;}
|
const uint32_t GetBufferHash ()const{return buffer_hash;}
|
||||||
|
|
||||||
MaterialParameters *GetMP (const DescriptorSetsType &type){return mat_inst->GetMP(type);}
|
MaterialParameters *GetMP (const DescriptorSetsType &type){return mat_inst->GetMP(type);}
|
||||||
|
|
||||||
|
public: //instance support
|
||||||
|
|
||||||
|
virtual const uint32_t GetInstanceCount ()const{return 1;}
|
||||||
};//class RenderableInstance
|
};//class RenderableInstance
|
||||||
|
|
||||||
RenderableInstance *CreateRenderableInstance(Renderable *,MaterialInstance *,Pipeline *);
|
RenderableInstance *CreateRenderableInstance(Renderable *,MaterialInstance *,Pipeline *);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user