SpiecsEngine
 
Loading...
Searching...
No Matches

◆ AddColorAttachment() [2/2]

template<typename T >
Renderer::RendererPassBuilder & Spices::Renderer::RendererPassBuilder::AddColorAttachment ( const std::string & attachmentName,
const TextureType & type,
T func )

Instance a VkAttachmentDescription.

Write in data.

Parameters
[in]isEnableBlendTrue if This Attachment can be blend.
[inattachmentDescription VkAttachmentDescription.

Instance a VkClearValue.

Instance a VkPipelineColorBlendAttachmentState.

Instance a RendererResourceCreateInfo.

Get layers.

Instance a VkAttachmentReference.

Definition at line 2795 of file Renderer.h.

2800 {
2802
2806 VkAttachmentDescription attachmentDescription{};
2807 attachmentDescription.format = m_Renderer->m_Device->GetSwapChainSupport().format.format;
2808 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
2809 attachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
2810 attachmentDescription.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
2811 attachmentDescription.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
2812 attachmentDescription.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
2813 attachmentDescription.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2814 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2815
2821 bool isEnableBlend = false;
2822 func(isEnableBlend, attachmentDescription);
2823
2827 VkClearValue clearValue{};
2828 clearValue.color = { 0.0f, 0.0f, 0.0f, 1.0f };
2829
2833 VkPipelineColorBlendAttachmentState colorBlend{};
2834 colorBlend.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
2835 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
2836 if (!isEnableBlend)
2837 {
2838 colorBlend.blendEnable = VK_FALSE;
2839 colorBlend.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
2840 colorBlend.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
2841 colorBlend.colorBlendOp = VK_BLEND_OP_ADD;
2842 colorBlend.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
2843 colorBlend.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
2844 colorBlend.alphaBlendOp = VK_BLEND_OP_ADD;
2845 }
2846 else
2847 {
2848 colorBlend.blendEnable = VK_TRUE;
2849 colorBlend.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
2850 colorBlend.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
2851 colorBlend.colorBlendOp = VK_BLEND_OP_ADD;
2852 colorBlend.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
2853 colorBlend.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE; // Stable alpha channel to 1, for ImGui::Image will rendering background wrongly.
2854 colorBlend.alphaBlendOp = VK_BLEND_OP_ADD;
2855 }
2856
2860 RendererResourceCreateInfo Info;
2861 Info.name = attachmentName;
2862 Info.type = type;
2863 Info.description = attachmentDescription;
2864 Info.width = m_Renderer->m_Device->GetSwapChainSupport().surfaceSize.width;
2865 Info.height = m_Renderer->m_Device->GetSwapChainSupport().surfaceSize.height;
2866
2867 VkImageView& view = m_Renderer->m_RendererResourcePool->AccessResource(Info)->imageView;
2868
2872 uint32_t layers = 1;
2873 switch (type)
2874 {
2876 layers = m_Renderer->m_RendererResourcePool->AccessRowResource(Info.name)->GetLayers();
2877 break;
2879 layers = 6;
2880 break;
2881 default:
2882 break;
2883 }
2884
2885 uint32_t index = m_Renderer->m_Pass->AddAttachment(attachmentName, attachmentDescription, clearValue, layers, view);
2886
2890 VkAttachmentReference attachmentRef{};
2891 attachmentRef.attachment = index;
2892 attachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2893
2894 m_HandledRendererSubPass->AddColorAttachmentReference(attachmentRef, colorBlend);
2895
2896 return *this;
2897 }
#define SPICES_PROFILE_ZONE
std::shared_ptr< RendererSubPass > m_HandledRendererSubPass
Handled Sub pass.
Definition Renderer.h:512
Renderer * m_Renderer
Specific Renderer pointer. Passed while this class instanced.
Definition Renderer.h:507
std::shared_ptr< RendererPass > m_Pass
RendererPass.
Definition Renderer.h:2012
std::shared_ptr< RendererResourcePool > m_RendererResourcePool
RendererResourcePool, Passed by instanced.
Definition Renderer.h:2007
std::shared_ptr< VulkanDevice > m_Device
VulkanDevice , Passed by instanced.
Definition Renderer.h:2002

References Spices::RendererResourceCreateInfo::height, m_Renderer, Spices::RendererResourceCreateInfo::name, Spices::Texture2DArray, Spices::Texture2DCube, Spices::RendererResourceCreateInfo::type, and Spices::RendererResourceCreateInfo::width.