Pipeline增加alpha_test/alpha_blend属性

This commit is contained in:
hyzboy 2019-05-23 13:29:23 +08:00
parent a988f36b92
commit 96d9132b29
3 changed files with 49 additions and 2 deletions

View File

@ -9,12 +9,18 @@ class Pipeline
VkDevice device; VkDevice device;
VkPipeline pipeline; VkPipeline pipeline;
bool alpha_test;
bool alpha_blend;
public: public:
Pipeline(VkDevice dev,VkPipeline p){device=dev;pipeline=p;} Pipeline(VkDevice dev,VkPipeline p,bool at,bool ab):device(dev),pipeline(p),alpha_test(at),alpha_blend(ab){}
virtual ~Pipeline(); virtual ~Pipeline();
operator VkPipeline(){return pipeline;} operator VkPipeline(){return pipeline;}
const bool IsAlphaTest()const{return alpha_test;}
const bool IsAlphaBlend()const{return alpha_blend;}
};//class GraphicsPipeline };//class GraphicsPipeline
constexpr size_t MAX_SAMPLE_MASK_COUNT=(VK_SAMPLE_COUNT_64_BIT+31)/32; constexpr size_t MAX_SAMPLE_MASK_COUNT=(VK_SAMPLE_COUNT_64_BIT+31)/32;
@ -54,6 +60,9 @@ class PipelineCreater
void InitDynamicState(); void InitDynamicState();
float alpha_test=0;
bool alpha_blend=false;
public: public:
PipelineCreater(Device *dev,const Material *,RenderPass *rp,const VkExtent2D &); PipelineCreater(Device *dev,const Material *,RenderPass *rp,const VkExtent2D &);
@ -66,6 +75,8 @@ public:
void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;} 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 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 SetAlphaTest( const float at) {alpha_test=at;}
void SetDepthTest( bool dt) {depthStencilState.depthTestEnable=dt;} void SetDepthTest( bool dt) {depthStencilState.depthTestEnable=dt;}
void SetDepthWrite( bool dw) {depthStencilState.depthWriteEnable=dw;} void SetDepthWrite( bool dw) {depthStencilState.depthWriteEnable=dw;}
@ -115,6 +126,9 @@ public:
colorBlendAttachments.Add(*cba); colorBlendAttachments.Add(*cba);
colorBlending.attachmentCount=colorBlendAttachments.GetCount(); colorBlending.attachmentCount=colorBlendAttachments.GetCount();
if(cba->blendEnable)
alpha_blend=true;
} }
bool SetBlend(uint index,bool blend) bool SetBlend(uint index,bool blend)
@ -125,6 +139,22 @@ public:
cba->blendEnable=blend; cba->blendEnable=blend;
if(blend)
alpha_blend=true;
else
{
cba=colorBlendAttachments.GetData();
for(uint i=0;i<colorBlendAttachments.GetCount();i++)
if(cba->blendEnable)
{
alpha_blend=true;
return(true);
}
alpha_blend=false;
}
return(true); return(true);
} }

View File

@ -41,6 +41,8 @@ bool PipelineCreater::SaveToStream(io::DataOutputStream *dos)
for(uint32_t i=0;i<pipelineInfo.pColorBlendState->attachmentCount;i++) for(uint32_t i=0;i<pipelineInfo.pColorBlendState->attachmentCount;i++)
WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState->pAttachments+i,VkPipelineColorBlendAttachmentState); WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState->pAttachments+i,VkPipelineColorBlendAttachmentState);
if(!dos->WriteFloat(alpha_test))return(false);
return(true); return(true);
} }
@ -89,16 +91,29 @@ bool PipelineCreater::LoadFromMemory(uchar *data,uint size)
if(size<colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState)) if(size<colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState))
return(false); return(false);
VkPipelineColorBlendAttachmentState *cba=(VkPipelineColorBlendAttachmentState *)data;
colorBlendAttachments.SetCount(colorBlending.attachmentCount); colorBlendAttachments.SetCount(colorBlending.attachmentCount);
memcpy(colorBlendAttachments.GetData(),data,colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState)); memcpy(colorBlendAttachments.GetData(),data,colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState));
colorBlending.pAttachments=colorBlendAttachments.GetData(); colorBlending.pAttachments=colorBlendAttachments.GetData();
for(uint i=0;i<colorBlending.attachmentCount;i++)
{
if(cba->blendEnable)
alpha_blend=true;
++cba;
}
} }
else else
{ {
colorBlending.pAttachments=nullptr; colorBlending.pAttachments=nullptr;
alpha_blend=false;
} }
CHECK_SIZE_AND_COPY(alpha_test,float);
return(true); return(true);
} }
VK_NAMESPACE_END VK_NAMESPACE_END

View File

@ -147,6 +147,8 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass
colorBlendAttachments.Add(cba); colorBlendAttachments.Add(cba);
alpha_blend=false;
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
colorBlending.pNext = nullptr; colorBlending.pNext = nullptr;
colorBlending.flags = 0; colorBlending.flags = 0;
@ -231,6 +233,6 @@ Pipeline *PipelineCreater::Create()
if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS)
return(nullptr); return(nullptr);
return(new Pipeline(device,graphicsPipeline)); return(new Pipeline(device,graphicsPipeline,alpha_test>0,alpha_blend));
} }
VK_NAMESPACE_END VK_NAMESPACE_END