ULRE/inc/hgl/graph/vulkan/VKPipeline.h

117 lines
4.5 KiB
C
Raw Normal View History

2019-04-18 16:38:58 +08:00
#ifndef HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
#define HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
#include"VK.h"
VK_NAMESPACE_BEGIN
2019-04-18 22:10:24 +08:00
class Device;
2019-04-18 21:02:42 +08:00
class RenderPass;
class VertexAttributeBinding;
class Material;
2019-04-18 21:02:42 +08:00
2019-04-18 16:38:58 +08:00
class Pipeline
{
VkDevice device;
2019-04-18 16:38:58 +08:00
VkPipeline pipeline;
public:
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
{
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;
VkPipelineInputAssemblyStateCreateInfo inputAssembly;
VkViewport viewport;
VkRect2D scissor;
VkPipelineViewportStateCreateInfo viewportState;
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;
VkDynamicState dynamicStateEnables[VK_DYNAMIC_STATE_RANGE_SIZE];
VkPipelineDynamicStateCreateInfo dynamicState;
2019-04-18 16:38:58 +08:00
public:
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
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;}
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;}
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
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