2019-04-18 16:38:58 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
|
|
|
|
|
|
2019-05-07 12:46:25 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VK.h>
|
2019-04-18 16:38:58 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
class Pipeline
|
|
|
|
|
{
|
2019-04-18 16:53:14 +08:00
|
|
|
|
VkDevice device;
|
2019-04-18 16:38:58 +08:00
|
|
|
|
VkPipeline pipeline;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2019-04-28 21:25:52 +08:00
|
|
|
|
Pipeline(VkDevice dev,VkPipeline p){device=dev;pipeline=p;}
|
2019-04-18 16:38:58 +08:00
|
|
|
|
virtual ~Pipeline();
|
2019-04-18 21:02:42 +08:00
|
|
|
|
|
|
|
|
|
operator VkPipeline(){return pipeline;}
|
2019-04-18 16:38:58 +08:00
|
|
|
|
};//class GraphicsPipeline
|
|
|
|
|
|
|
|
|
|
class PipelineCreater
|
|
|
|
|
{
|
2019-04-18 16:53:14 +08:00
|
|
|
|
VkDevice device;
|
2019-04-18 21:02:42 +08:00
|
|
|
|
VkExtent2D extent;
|
2019-04-19 20:40:04 +08:00
|
|
|
|
VkPipelineCache cache;
|
2019-04-18 16:38:58 +08:00
|
|
|
|
VkGraphicsPipelineCreateInfo pipelineInfo;
|
|
|
|
|
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo vis_create_info;
|
2019-04-18 16:53:14 +08:00
|
|
|
|
VkPipelineInputAssemblyStateCreateInfo inputAssembly;
|
|
|
|
|
|
|
|
|
|
VkViewport viewport;
|
|
|
|
|
VkRect2D scissor;
|
|
|
|
|
VkPipelineViewportStateCreateInfo viewportState;
|
2019-04-19 22:27:52 +08:00
|
|
|
|
VkPipelineDepthStencilStateCreateInfo depthStencilState;
|
2019-04-18 16:38:58 +08:00
|
|
|
|
|
2019-04-18 21:02:42 +08:00
|
|
|
|
VkPipelineRasterizationStateCreateInfo rasterizer;
|
|
|
|
|
|
|
|
|
|
VkPipelineMultisampleStateCreateInfo multisampling;
|
|
|
|
|
|
|
|
|
|
VkPipelineColorBlendAttachmentState colorBlendAttachment;
|
|
|
|
|
VkPipelineColorBlendStateCreateInfo colorBlending;
|
|
|
|
|
|
2019-04-19 22:27:52 +08:00
|
|
|
|
VkDynamicState dynamicStateEnables[VK_DYNAMIC_STATE_RANGE_SIZE];
|
|
|
|
|
VkPipelineDynamicStateCreateInfo dynamicState;
|
|
|
|
|
|
2019-04-18 16:38:58 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2019-05-05 11:31:42 +08:00
|
|
|
|
PipelineCreater(Device *dev,const Material *,RenderPass *rp);
|
2019-04-18 21:02:42 +08:00
|
|
|
|
~PipelineCreater()=default;
|
2019-04-18 16:38:58 +08:00
|
|
|
|
|
2019-04-18 16:53:14 +08:00
|
|
|
|
bool Set(const VkPrimitiveTopology,bool=false);
|
2019-04-18 21:02:42 +08:00
|
|
|
|
|
|
|
|
|
void SetViewport( float x,float y,float w,float h){viewport.x=x;viewport.y=y;viewport.width=w;viewport.height=h;}
|
|
|
|
|
void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;}
|
|
|
|
|
void SetScissor( float l,float t,float w,float h){scissor.offset.x=l;scissor.offset.y=t;scissor.extent.width=w;scissor.extent.height=h;}
|
|
|
|
|
|
2019-04-23 11:05:00 +08:00
|
|
|
|
void SetDepthTest( bool dt) {depthStencilState.depthTestEnable=dt;}
|
|
|
|
|
void SetDepthWrite( bool dw) {depthStencilState.depthWriteEnable=dw;}
|
|
|
|
|
|
2019-04-18 21:02:42 +08:00
|
|
|
|
void SetDepthClamp( bool dc) {rasterizer.depthClampEnable=dc;}
|
|
|
|
|
void SetDiscard( bool discard) {rasterizer.rasterizerDiscardEnable=discard;}
|
|
|
|
|
void SetPolygonMode(VkPolygonMode pm) {rasterizer.polygonMode =pm;}
|
|
|
|
|
void SetCullMode( VkCullModeFlagBits cm) {rasterizer.cullMode =cm;}
|
2019-04-23 11:05:00 +08:00
|
|
|
|
void CloseCullFace() {rasterizer.cullMode =VK_CULL_MODE_NONE;}
|
2019-04-18 21:02:42 +08:00
|
|
|
|
void SetFrontFace( VkFrontFace ff) {rasterizer.frontFace =ff;}
|
|
|
|
|
void SetDepthBias( float ConstantFactor,
|
|
|
|
|
float Clamp,
|
|
|
|
|
float SlopeFactor)
|
|
|
|
|
{
|
|
|
|
|
rasterizer.depthBiasEnable =VK_TRUE;
|
|
|
|
|
rasterizer.depthBiasConstantFactor =ConstantFactor;
|
|
|
|
|
rasterizer.depthBiasClamp =Clamp;
|
|
|
|
|
rasterizer.depthBiasSlopeFactor =SlopeFactor;
|
|
|
|
|
}
|
|
|
|
|
void DisableDepthBias() {rasterizer.depthBiasEnable=VK_FALSE;}
|
|
|
|
|
void SetLineWidth( float line_width) {rasterizer.lineWidth =line_width;}
|
|
|
|
|
|
|
|
|
|
void SetSamleCount( VkSampleCountFlagBits sc)
|
|
|
|
|
{
|
|
|
|
|
multisampling.sampleShadingEnable=(sc==VK_SAMPLE_COUNT_1_BIT?VK_FALSE:VK_TRUE);
|
|
|
|
|
multisampling.rasterizationSamples=sc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetColorWriteMask(bool r,bool g,bool b,bool a)
|
|
|
|
|
{
|
|
|
|
|
colorBlendAttachment.colorWriteMask=0;
|
|
|
|
|
|
|
|
|
|
if(r)colorBlendAttachment.colorWriteMask|=VK_COLOR_COMPONENT_R_BIT;
|
|
|
|
|
if(r)colorBlendAttachment.colorWriteMask|=VK_COLOR_COMPONENT_G_BIT;
|
|
|
|
|
if(g)colorBlendAttachment.colorWriteMask|=VK_COLOR_COMPONENT_B_BIT;
|
|
|
|
|
if(a)colorBlendAttachment.colorWriteMask|=VK_COLOR_COMPONENT_A_BIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetBlend( bool blend) {colorBlendAttachment.blendEnable=blend;}
|
|
|
|
|
void SetLogicOp( VkLogicOp logic_op) {colorBlending.logicOpEnable=VK_TRUE;colorBlending.logicOp=logic_op;}
|
|
|
|
|
void DisableLogicOp() {colorBlending.logicOpEnable=VK_FALSE;}
|
|
|
|
|
|
|
|
|
|
void SetBlendConstans(float r,float g,float b,float a)
|
|
|
|
|
{
|
|
|
|
|
colorBlending.blendConstants[0] = r;
|
|
|
|
|
colorBlending.blendConstants[1] = g;
|
|
|
|
|
colorBlending.blendConstants[2] = b;
|
|
|
|
|
colorBlending.blendConstants[3] = a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetBlendConstans(float *blend_constans) {hgl_typecpy(colorBlending.blendConstants,blend_constans,4);}
|
2019-04-18 16:38:58 +08:00
|
|
|
|
|
2019-05-05 17:43:31 +08:00
|
|
|
|
const VkGraphicsPipelineCreateInfo *GetInfo()const{return &pipelineInfo;}
|
2019-04-18 16:38:58 +08:00
|
|
|
|
Pipeline *Create();
|
|
|
|
|
};//class PipelineCreater
|
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
|