2020-07-29 01:00:25 +08:00
|
|
|
|
#ifndef HGL_GRAPH_RENDERABLE_CREATER_INCLUDE
|
2020-07-11 21:35:14 +08:00
|
|
|
|
#define HGL_GRAPH_RENDERABLE_CREATER_INCLUDE
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
2020-07-16 20:36:54 +08:00
|
|
|
|
#include<hgl/graph/VertexAttribDataAccess.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKShaderModule.h>
|
2020-07-11 21:35:14 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace graph
|
|
|
|
|
{
|
2020-07-14 19:41:38 +08:00
|
|
|
|
struct ShaderStageBind
|
|
|
|
|
{
|
2020-07-20 19:19:09 +08:00
|
|
|
|
AnsiString name;
|
|
|
|
|
uint binding;
|
|
|
|
|
VAD * data =nullptr;
|
2021-11-29 15:58:48 +08:00
|
|
|
|
VBO * vbo =nullptr;
|
2020-07-16 17:02:24 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
~ShaderStageBind()
|
|
|
|
|
{
|
2020-07-20 17:33:57 +08:00
|
|
|
|
SAFE_CLEAR(data);
|
2020-07-16 17:02:24 +08:00
|
|
|
|
}
|
2020-07-14 19:41:38 +08:00
|
|
|
|
};//struct ShaderStageBind
|
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
|
using ShaderStageBindMap=MapObject<AnsiString,ShaderStageBind>;
|
2020-07-14 19:41:38 +08:00
|
|
|
|
|
2020-07-11 21:35:14 +08:00
|
|
|
|
/**
|
|
|
|
|
* 可渲染对象创建器
|
|
|
|
|
*/
|
|
|
|
|
class RenderableCreater
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
RenderResource *db;
|
|
|
|
|
Material *mtl;
|
2020-07-11 21:35:14 +08:00
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
|
const VAB *vab;
|
2020-07-11 21:35:14 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
|
uint32 vertices_number;
|
2020-07-11 21:35:14 +08:00
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
|
IndexBuffer * ibo;
|
|
|
|
|
ShaderStageBindMap ssb_map;
|
2020-07-20 17:33:57 +08:00
|
|
|
|
|
2020-07-11 21:35:14 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
|
RenderableCreater(RenderResource *sdb,const VAB *);
|
2020-07-14 19:41:38 +08:00
|
|
|
|
virtual ~RenderableCreater()=default;
|
2020-07-11 21:35:14 +08:00
|
|
|
|
|
2020-07-20 19:19:09 +08:00
|
|
|
|
virtual bool Init(const uint32 count); ///<初始化,参数为顶点数量
|
2020-07-11 21:35:14 +08:00
|
|
|
|
|
2020-07-20 19:19:09 +08:00
|
|
|
|
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
2020-07-20 17:33:57 +08:00
|
|
|
|
|
|
|
|
|
template<typename T>
|
2020-07-20 19:19:09 +08:00
|
|
|
|
T * CreateVADA(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
2020-07-20 17:33:57 +08:00
|
|
|
|
{
|
2021-11-29 20:12:10 +08:00
|
|
|
|
const VkFormat format=vab->GetFormat(name);
|
2020-07-20 17:33:57 +08:00
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
|
if(format!=T::GetVulkanFormat())
|
2020-07-20 17:33:57 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
|
|
VAD *vad=this->CreateVAD(name);
|
|
|
|
|
|
|
|
|
|
if(!vad)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2020-07-20 18:12:02 +08:00
|
|
|
|
T *vada=T::Create(vad);
|
|
|
|
|
|
|
|
|
|
vada->Begin();
|
|
|
|
|
|
|
|
|
|
return vada;
|
2020-07-20 17:33:57 +08:00
|
|
|
|
}
|
2020-07-11 21:35:14 +08:00
|
|
|
|
|
2020-07-20 19:19:09 +08:00
|
|
|
|
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
|
|
|
|
|
|
|
|
|
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
|
|
|
|
|
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
|
2020-07-11 21:35:14 +08:00
|
|
|
|
|
2021-05-31 17:55:55 +08:00
|
|
|
|
virtual Renderable * Finish(); ///<结束并创建可渲染对象
|
2020-07-14 14:03:26 +08:00
|
|
|
|
};//class RenderableCreater
|
2020-07-11 21:35:14 +08:00
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|
|
|
|
|
#endif//HGL_GRAPH_RENDERABLE_CREATER_INCLUDE
|