MCPcopy Create free account
hub / github.com/defold/defold / CreateRenderTarget

Function CreateRenderTarget

engine/graphics/src/vulkan/graphics_vulkan.cpp:4111–4241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4109 }
4110
4111 static VkResult CreateRenderTarget(VulkanContext* context, HTexture* color_textures, BufferType* buffer_types, uint8_t num_color_textures, HTexture depth_stencil_texture, uint32_t width, uint32_t height, VulkanRenderTarget* rtOut)
4112 {
4113 assert(rtOut->m_Handle.m_Framebuffer == VK_NULL_HANDLE && rtOut->m_Handle.m_RenderPass == VK_NULL_HANDLE && rtOut->m_Handle.m_RenderPassClear == VK_NULL_HANDLE);
4114 const uint8_t num_attachments = MAX_BUFFER_COLOR_ATTACHMENTS + 1;
4115
4116 RenderPassAttachment rp_attachments[num_attachments];
4117 RenderPassAttachment* rp_attachment_depth_stencil = 0;
4118
4119 VkImageView fb_attachments[num_attachments];
4120 uint16_t fb_attachment_count = 0;
4121 uint16_t fb_width = width;
4122 uint16_t fb_height = height;
4123
4124 for (int i = 0; i < num_color_textures; ++i)
4125 {
4126 VulkanTexture* color_texture_ptr = GetAssetFromContainer<VulkanTexture>(context->m_BaseContext.m_AssetHandleContainer, color_textures[i]);
4127
4128 assert(!color_texture_ptr->m_Destroyed && color_texture_ptr->m_Handle.m_ImageView != VK_NULL_HANDLE && color_texture_ptr->m_Handle.m_Image != VK_NULL_HANDLE);
4129 uint8_t color_buffer_index = GetBufferTypeIndex(buffer_types[i]);
4130 fb_width = rtOut->m_Base.m_ColorTextureParams[color_buffer_index].m_Width;
4131 fb_height = rtOut->m_Base.m_ColorTextureParams[color_buffer_index].m_Height;
4132
4133 RenderPassAttachment* rp_attachment_color = &rp_attachments[i];
4134 rp_attachment_color->m_ImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4135 rp_attachment_color->m_ImageLayoutInitial = VK_IMAGE_LAYOUT_UNDEFINED;
4136 rp_attachment_color->m_Format = color_texture_ptr->m_Format;
4137 rp_attachment_color->m_LoadOp = VulkanLoadOp(rtOut->m_ColorBufferLoadOps[color_buffer_index]);
4138 rp_attachment_color->m_StoreOp = VulkanStoreOp(rtOut->m_ColorBufferStoreOps[color_buffer_index]);
4139
4140 if (rp_attachment_color->m_LoadOp == VK_ATTACHMENT_LOAD_OP_LOAD)
4141 {
4142 rp_attachment_color->m_ImageLayoutInitial = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4143 }
4144
4145 fb_attachments[fb_attachment_count++] = color_texture_ptr->m_Handle.m_ImageView;
4146 }
4147
4148 if (depth_stencil_texture)
4149 {
4150 VulkanTexture* depth_stencil_texture_ptr = GetAssetFromContainer<VulkanTexture>(context->m_BaseContext.m_AssetHandleContainer, depth_stencil_texture);
4151 if (num_color_textures == 0)
4152 {
4153 fb_width = rtOut->m_Base.m_DepthStencilTextureParams.m_Height;
4154 fb_height = rtOut->m_Base.m_DepthStencilTextureParams.m_Height;
4155 }
4156
4157 rp_attachment_depth_stencil = &rp_attachments[fb_attachment_count];
4158 rp_attachment_depth_stencil->m_ImageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4159 rp_attachment_depth_stencil->m_ImageLayoutInitial = VK_IMAGE_LAYOUT_UNDEFINED;
4160 rp_attachment_depth_stencil->m_Format = depth_stencil_texture_ptr->m_Format;
4161 rp_attachment_depth_stencil->m_LoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4162 rp_attachment_depth_stencil->m_StoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4163
4164 fb_attachments[fb_attachment_count++] = depth_stencil_texture_ptr->m_Handle.m_ImageView;
4165 }
4166
4167 VkResult res = CreateRenderPass(context->m_LogicalDevice.m_Device, VK_SAMPLE_COUNT_1_BIT, rp_attachments, num_color_textures, rp_attachment_depth_stencil, 0, &rtOut->m_Handle.m_RenderPass);
4168 if (res != VK_SUCCESS)

Callers 2

VulkanNewRenderTargetFunction · 0.85

Calls 6

GetBufferTypeIndexFunction · 0.85
VulkanLoadOpFunction · 0.85
VulkanStoreOpFunction · 0.85
CreateRenderPassFunction · 0.85
CreateFramebufferFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected