Pipeline增加alpha_test/alpha_blend属性
This commit is contained in:
parent
a988f36b92
commit
96d9132b29
@ -9,12 +9,18 @@ class Pipeline
|
||||
VkDevice device;
|
||||
VkPipeline pipeline;
|
||||
|
||||
bool alpha_test;
|
||||
bool alpha_blend;
|
||||
|
||||
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();
|
||||
|
||||
operator VkPipeline(){return pipeline;}
|
||||
|
||||
const bool IsAlphaTest()const{return alpha_test;}
|
||||
const bool IsAlphaBlend()const{return alpha_blend;}
|
||||
};//class GraphicsPipeline
|
||||
|
||||
constexpr size_t MAX_SAMPLE_MASK_COUNT=(VK_SAMPLE_COUNT_64_BIT+31)/32;
|
||||
@ -54,6 +60,9 @@ class PipelineCreater
|
||||
|
||||
void InitDynamicState();
|
||||
|
||||
float alpha_test=0;
|
||||
bool alpha_blend=false;
|
||||
|
||||
public:
|
||||
|
||||
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 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 SetDepthWrite( bool dw) {depthStencilState.depthWriteEnable=dw;}
|
||||
|
||||
@ -115,6 +126,9 @@ public:
|
||||
|
||||
colorBlendAttachments.Add(*cba);
|
||||
colorBlending.attachmentCount=colorBlendAttachments.GetCount();
|
||||
|
||||
if(cba->blendEnable)
|
||||
alpha_blend=true;
|
||||
}
|
||||
|
||||
bool SetBlend(uint index,bool blend)
|
||||
@ -125,6 +139,22 @@ public:
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,8 @@ bool PipelineCreater::SaveToStream(io::DataOutputStream *dos)
|
||||
for(uint32_t i=0;i<pipelineInfo.pColorBlendState->attachmentCount;i++)
|
||||
WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState->pAttachments+i,VkPipelineColorBlendAttachmentState);
|
||||
|
||||
if(!dos->WriteFloat(alpha_test))return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -89,16 +91,29 @@ bool PipelineCreater::LoadFromMemory(uchar *data,uint size)
|
||||
if(size<colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState))
|
||||
return(false);
|
||||
|
||||
VkPipelineColorBlendAttachmentState *cba=(VkPipelineColorBlendAttachmentState *)data;
|
||||
|
||||
colorBlendAttachments.SetCount(colorBlending.attachmentCount);
|
||||
memcpy(colorBlendAttachments.GetData(),data,colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState));
|
||||
|
||||
colorBlending.pAttachments=colorBlendAttachments.GetData();
|
||||
|
||||
for(uint i=0;i<colorBlending.attachmentCount;i++)
|
||||
{
|
||||
if(cba->blendEnable)
|
||||
alpha_blend=true;
|
||||
|
||||
++cba;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
colorBlending.pAttachments=nullptr;
|
||||
alpha_blend=false;
|
||||
}
|
||||
|
||||
CHECK_SIZE_AND_COPY(alpha_test,float);
|
||||
|
||||
return(true);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -147,6 +147,8 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass
|
||||
|
||||
colorBlendAttachments.Add(cba);
|
||||
|
||||
alpha_blend=false;
|
||||
|
||||
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||
colorBlending.pNext = nullptr;
|
||||
colorBlending.flags = 0;
|
||||
@ -231,6 +233,6 @@ Pipeline *PipelineCreater::Create()
|
||||
if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new Pipeline(device,graphicsPipeline));
|
||||
return(new Pipeline(device,graphicsPipeline,alpha_test>0,alpha_blend));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user