From 96d9132b29178402d485840ed36e14790087b815 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 23 May 2019 13:29:23 +0800 Subject: [PATCH] =?UTF-8?q?Pipeline=E5=A2=9E=E5=8A=A0alpha=5Ftest/alpha=5F?= =?UTF-8?q?blend=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/vulkan/VKPipeline.h | 32 ++++++++++++++++++- .../Vulkan/POD/VKPipelineCreateInfo.POD.cpp | 15 +++++++++ src/RenderDevice/Vulkan/VKPipeline.cpp | 4 ++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/inc/hgl/graph/vulkan/VKPipeline.h b/inc/hgl/graph/vulkan/VKPipeline.h index 5f224e74..83e4a01e 100644 --- a/inc/hgl/graph/vulkan/VKPipeline.h +++ b/inc/hgl/graph/vulkan/VKPipeline.h @@ -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;iblendEnable) + { + alpha_blend=true; + return(true); + } + + alpha_blend=false; + } + return(true); } diff --git a/src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp b/src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp index 3a84770b..9b1f69de 100644 --- a/src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp +++ b/src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp @@ -41,6 +41,8 @@ bool PipelineCreater::SaveToStream(io::DataOutputStream *dos) for(uint32_t i=0;iattachmentCount;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(sizeblendEnable) + alpha_blend=true; + + ++cba; + } } else { colorBlending.pAttachments=nullptr; + alpha_blend=false; } + CHECK_SIZE_AND_COPY(alpha_test,float); + return(true); } VK_NAMESPACE_END diff --git a/src/RenderDevice/Vulkan/VKPipeline.cpp b/src/RenderDevice/Vulkan/VKPipeline.cpp index 689005ff..9730d909 100644 --- a/src/RenderDevice/Vulkan/VKPipeline.cpp +++ b/src/RenderDevice/Vulkan/VKPipeline.cpp @@ -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