diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index b1709ccd8..354772f31 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -98,6 +98,16 @@ static const uint16_t s_cubeIndices[] = 21, 22, 23, }; BX_STATIC_ASSERT(BX_COUNTOF(s_cubeIndices) == 36); + +bx::Vec3 s_faceColors[] = +{ + { 0.75f, 0.0f, 0.0f }, + { 0.75f, 0.75f, 0.0f }, + { 0.75f, 0.0f, 0.75f }, + { 0.0f, 0.75f, 0.0f }, + { 0.0f, 0.75f, 0.75f }, + { 0.0f, 0.0f, 0.75f }, +}; static void updateTextureCubeRectBgra8( bgfx::TextureHandle _handle @@ -290,6 +300,23 @@ public: , BGFX_TEXTURE_COMPUTE_WRITE ); } + + { + m_textureCube[3] = bgfx::createTextureCube( + kTextureSide + , false + , 1 + , bgfx::TextureFormat::RGBA8 + , BGFX_TEXTURE_RT + ); + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_textureCubeFaceFb); ++ii) + { + bgfx::Attachment at; + at.init(m_textureCube[3], bgfx::Access::Write, ii); + m_textureCubeFaceFb[ii] = bgfx::createFrameBuffer(1, &at); + } + } m_texture2d = bgfx::createTexture2D( kTexture2dSize @@ -347,6 +374,14 @@ public: } } + for (uint32_t ii = 0; iim_backBufferColorMsaa) { - renderPassDescriptor.colorAttachments[0].texture = swapChain->m_backBufferColorMsaa; - renderPassDescriptor.colorAttachments[0].resolveTexture = NULL != m_screenshotTarget + _renderPassDescriptor.colorAttachments[0].texture = swapChain->m_backBufferColorMsaa; + _renderPassDescriptor.colorAttachments[0].resolveTexture = NULL != m_screenshotTarget ? m_screenshotTarget.m_obj : swapChain->currentDrawable().texture ; } else { - renderPassDescriptor.colorAttachments[0].texture = NULL != m_screenshotTarget + _renderPassDescriptor.colorAttachments[0].texture = NULL != m_screenshotTarget ? m_screenshotTarget.m_obj : swapChain->currentDrawable().texture ; } - renderPassDescriptor.depthAttachment.texture = swapChain->m_backBufferDepth; - renderPassDescriptor.stencilAttachment.texture = swapChain->m_backBufferStencil; + _renderPassDescriptor.depthAttachment.texture = swapChain->m_backBufferDepth; + _renderPassDescriptor.stencilAttachment.texture = swapChain->m_backBufferStencil; } else { @@ -1614,35 +1632,40 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < frameBuffer.m_num; ++ii) { const TextureMtl& texture = m_textures[frameBuffer.m_colorHandle[ii].idx]; - renderPassDescriptor.colorAttachments[ii].texture = texture.m_ptrMsaa + _renderPassDescriptor.colorAttachments[ii].texture = texture.m_ptrMsaa ? texture.m_ptrMsaa : texture.m_ptr ; - renderPassDescriptor.colorAttachments[ii].resolveTexture = texture.m_ptrMsaa + _renderPassDescriptor.colorAttachments[ii].resolveTexture = texture.m_ptrMsaa ? texture.m_ptr.m_obj : NULL ; + + setAttachment(_renderPassDescriptor.colorAttachments[ii], frameBuffer.m_colorAttachment[ii], texture.m_type, texture.m_ptrMsaa != NULL); } if (isValid(frameBuffer.m_depthHandle) ) { const TextureMtl& texture = m_textures[frameBuffer.m_depthHandle.idx]; - renderPassDescriptor.depthAttachment.texture = texture.m_ptrMsaa + _renderPassDescriptor.depthAttachment.texture = texture.m_ptrMsaa ? texture.m_ptrMsaa : texture.m_ptr ; - renderPassDescriptor.stencilAttachment.texture = texture.m_ptrStencil; + _renderPassDescriptor.stencilAttachment.texture = texture.m_ptrStencil; + setAttachment(_renderPassDescriptor.depthAttachment, frameBuffer.m_depthAttachment, texture.m_type, NULL != texture.m_ptrMsaa); + setAttachment(_renderPassDescriptor.stencilAttachment, frameBuffer.m_depthAttachment, texture.m_type, NULL != texture.m_ptrMsaa); + if (texture.m_textureFormat == TextureFormat::D24S8) { if (texture.m_ptr.pixelFormat() == 255 /* Depth24Unorm_Stencil8 */ || texture.m_ptr.pixelFormat() == 260 /* Depth32Float_Stencil8 */) { - renderPassDescriptor.stencilAttachment.texture = renderPassDescriptor.depthAttachment.texture; + _renderPassDescriptor.stencilAttachment.texture = _renderPassDescriptor.depthAttachment.texture; } else { - renderPassDescriptor.stencilAttachment.texture = texture.m_ptrMsaa + _renderPassDescriptor.stencilAttachment.texture = texture.m_ptrMsaa ? texture.m_ptrMsaa : texture.m_ptrStencil ; @@ -3089,8 +3112,9 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < _num; ++ii) { - TextureHandle handle = _attachment[ii].handle; - + const Attachment& at = _attachment[ii]; + TextureHandle handle = at.handle; + if (isValid(handle) ) { const TextureMtl& texture = s_renderMtl->m_textures[handle.idx]; @@ -3104,10 +3128,12 @@ namespace bgfx { namespace mtl if (bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) ) { m_depthHandle = handle; + m_depthAttachment = at; } else { m_colorHandle[m_num] = handle; + m_colorAttachment[m_num] = at; m_num++; } }