| 3306 | } |
| 3307 | |
| 3308 | static HRenderTarget WebGPUNewRenderTarget(HContext _context, uint32_t buffer_type_flags, const RenderTargetCreationParams params) |
| 3309 | { |
| 3310 | TRACE_CALL; |
| 3311 | WebGPUContext* context = (WebGPUContext*)_context; |
| 3312 | WebGPURenderTarget* rt = new WebGPURenderTarget(); |
| 3313 | rt->m_Multisample = 1; |
| 3314 | rt->m_Width = rt->m_Height = 0; |
| 3315 | memcpy(rt->m_Base.m_ColorTextureParams, params.m_ColorBufferParams, sizeof(TextureParams) * MAX_BUFFER_COLOR_ATTACHMENTS); |
| 3316 | rt->m_Base.m_DepthBufferParams = params.m_DepthBufferParams; |
| 3317 | rt->m_Base.m_StencilBufferParams = params.m_StencilBufferParams; |
| 3318 | rt->m_Base.m_DepthStencilTextureParams = (buffer_type_flags & BUFFER_TYPE_DEPTH_BIT) ? params.m_DepthBufferParams : params.m_StencilBufferParams; |
| 3319 | |
| 3320 | // colors |
| 3321 | const BufferType color_buffer_flags[] = { |
| 3322 | BUFFER_TYPE_COLOR0_BIT, |
| 3323 | BUFFER_TYPE_COLOR1_BIT, |
| 3324 | BUFFER_TYPE_COLOR2_BIT, |
| 3325 | BUFFER_TYPE_COLOR3_BIT, |
| 3326 | }; |
| 3327 | for (int i = 0; i < MAX_BUFFER_COLOR_ATTACHMENTS; ++i) |
| 3328 | { |
| 3329 | const BufferType buffer_type = color_buffer_flags[i]; |
| 3330 | if (buffer_type_flags & buffer_type) |
| 3331 | { |
| 3332 | rt->m_ColorBufferLoadOps[rt->m_Base.m_ColorAttachmentCount] = params.m_ColorBufferLoadOps[i]; |
| 3333 | rt->m_ColorBufferStoreOps[rt->m_Base.m_ColorAttachmentCount] = params.m_ColorBufferStoreOps[i]; |
| 3334 | memcpy(rt->m_ColorBufferClearValue + rt->m_Base.m_ColorAttachmentCount, params.m_ColorBufferClearValue + i, sizeof(params.m_ColorBufferClearValue[i])); |
| 3335 | { |
| 3336 | WebGPUTexture* texture = WebGPUNewTextureInternal(params.m_ColorBufferCreationParams[i]); |
| 3337 | texture->m_Base.m_Format = rt->m_Base.m_ColorTextureParams[i].m_Format; |
| 3338 | WebGPURealizeTexture(texture, WebGPUFormatFromTextureFormat(rt->m_Base.m_ColorTextureParams[i].m_Format), 1, 1, g_rendertarget_usage); |
| 3339 | rt->m_Base.m_TextureColor[rt->m_Base.m_ColorAttachmentCount] = StoreAssetInContainer(context->m_BaseContext.m_AssetHandleContainer, texture, ASSET_TYPE_TEXTURE); |
| 3340 | if (!rt->m_Width) |
| 3341 | { |
| 3342 | rt->m_Width = texture->m_Base.m_Width; |
| 3343 | rt->m_Height = texture->m_Base.m_Height; |
| 3344 | } |
| 3345 | assert(rt->m_Width == texture->m_Base.m_Width && rt->m_Height == texture->m_Base.m_Height); |
| 3346 | } |
| 3347 | ++rt->m_Base.m_ColorAttachmentCount; |
| 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | // depth/stencil |
| 3352 | const bool has_depth = buffer_type_flags & dmGraphics::BUFFER_TYPE_DEPTH_BIT, has_stencil = buffer_type_flags & dmGraphics::BUFFER_TYPE_STENCIL_BIT; |
| 3353 | if (has_depth || has_stencil) |
| 3354 | { |
| 3355 | WGPUTextureFormat format; |
| 3356 | WebGPUTexture* texture = NULL; |
| 3357 | if (has_depth) |
| 3358 | { |
| 3359 | texture = WebGPUNewTextureInternal(params.m_DepthBufferCreationParams); |
| 3360 | texture->m_Base.m_Format = rt->m_Base.m_DepthStencilTextureParams.m_Format; |
| 3361 | if (has_stencil) |
| 3362 | format = WGPUTextureFormat_Depth24PlusStencil8; |
| 3363 | else |
| 3364 | format = WGPUTextureFormat_Depth24Plus; |
| 3365 | } |
nothing calls this directly
no test coverage detected