From a3d52fab32b1a889853ba07dc1c0ae55ba31b88c Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 18 Jul 2022 18:23:57 +0200 Subject: [PATCH] premultiplied backbuffer for UWP/SwapchainPanel (#2837) * premultiplied backbuffer for UWP/SwapchainPanel * init flag * caps and feedback/opengl premul * reduced #ifdef form * removed ifdef --- bindings/bf/bgfx.bf | 30 ++++++++++++++++-------- bindings/cs/bgfx.cs | 30 ++++++++++++++++-------- bindings/d/types.d | 22 ++++++++++-------- bindings/zig/bgfx.zig | 26 +++++++++++++-------- include/bgfx/defines.h | 20 +++++++++------- scripts/bgfx.idl | 28 +++++++++++----------- src/dxgi.cpp | 1 + src/renderer_d3d11.cpp | 53 +++++++++++++++++++++++++++++++++++++++++- src/renderer_gl.cpp | 42 ++++++++++++++++++++++++++++++++- 9 files changed, 188 insertions(+), 64 deletions(-) diff --git a/bindings/bf/bgfx.bf b/bindings/bf/bgfx.bf index 30c7f4635..a27855846 100644 --- a/bindings/bf/bgfx.bf +++ b/bindings/bf/bgfx.bf @@ -997,6 +997,11 @@ public static class bgfx /// Suspend rendering. /// Suspend = 0x00080000, + + /// + /// Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`. + /// + TransparentBackbuffer = 0x00100000, FullscreenShift = 0, FullscreenMask = 0x00000001, ReservedShift = 31, @@ -1100,52 +1105,57 @@ public static class bgfx /// Texture blit is supported. /// TextureBlit = 0x0000000000040000, - TextureCompareReserved = 0x0000000000080000, + + /// + /// Transparent back buffer supported. + /// + TransparentBackbuffer = 0x0000000000080000, + TextureCompareReserved = 0x0000000000100000, /// /// Texture compare less equal mode is supported. /// - TextureCompareLequal = 0x0000000000100000, + TextureCompareLequal = 0x0000000000200000, /// /// Cubemap texture array is supported. /// - TextureCubeArray = 0x0000000000200000, + TextureCubeArray = 0x0000000000400000, /// /// CPU direct access to GPU texture memory. /// - TextureDirectAccess = 0x0000000000400000, + TextureDirectAccess = 0x0000000000800000, /// /// Read-back texture is supported. /// - TextureReadBack = 0x0000000000800000, + TextureReadBack = 0x0000000001000000, /// /// Vertex attribute half-float is supported. /// - VertexAttribHalf = 0x0000000001000000, + VertexAttribHalf = 0x0000000002000000, /// /// Vertex attribute 10_10_10_2 is supported. /// - VertexAttribUint10 = 0x0000000002000000, + VertexAttribUint10 = 0x0000000004000000, /// /// Rendering with VertexID only is supported. /// - VertexId = 0x0000000004000000, + VertexId = 0x0000000008000000, /// /// Viewport layer is available in vertex shader. /// - ViewportLayerArray = 0x0000000008000000, + ViewportLayerArray = 0x0000000010000000, /// /// All texture compare modes are supported. /// - TextureCompareAll = 0x0000000000180000, + TextureCompareAll = 0x0000000000300000, } [AllowDuplicates] diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index 2dfaaec8b..da9157c11 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -996,6 +996,11 @@ public static partial class bgfx /// Suspend rendering. /// Suspend = 0x00080000, + + /// + /// Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`. + /// + TransparentBackbuffer = 0x00100000, FullscreenShift = 0, FullscreenMask = 0x00000001, ReservedShift = 31, @@ -1099,52 +1104,57 @@ public static partial class bgfx /// Texture blit is supported. /// TextureBlit = 0x0000000000040000, - TextureCompareReserved = 0x0000000000080000, + + /// + /// Transparent back buffer supported. + /// + TransparentBackbuffer = 0x0000000000080000, + TextureCompareReserved = 0x0000000000100000, /// /// Texture compare less equal mode is supported. /// - TextureCompareLequal = 0x0000000000100000, + TextureCompareLequal = 0x0000000000200000, /// /// Cubemap texture array is supported. /// - TextureCubeArray = 0x0000000000200000, + TextureCubeArray = 0x0000000000400000, /// /// CPU direct access to GPU texture memory. /// - TextureDirectAccess = 0x0000000000400000, + TextureDirectAccess = 0x0000000000800000, /// /// Read-back texture is supported. /// - TextureReadBack = 0x0000000000800000, + TextureReadBack = 0x0000000001000000, /// /// Vertex attribute half-float is supported. /// - VertexAttribHalf = 0x0000000001000000, + VertexAttribHalf = 0x0000000002000000, /// /// Vertex attribute 10_10_10_2 is supported. /// - VertexAttribUint10 = 0x0000000002000000, + VertexAttribUint10 = 0x0000000004000000, /// /// Rendering with VertexID only is supported. /// - VertexId = 0x0000000004000000, + VertexId = 0x0000000008000000, /// /// Viewport layer is available in vertex shader. /// - ViewportLayerArray = 0x0000000008000000, + ViewportLayerArray = 0x0000000010000000, /// /// All texture compare modes are supported. /// - TextureCompareAll = 0x0000000000180000, + TextureCompareAll = 0x0000000000300000, } [Flags] diff --git a/bindings/d/types.d b/bindings/d/types.d index fa9b32aa0..658dac3f2 100644 --- a/bindings/d/types.d +++ b/bindings/d/types.d @@ -373,6 +373,7 @@ enum uint BGFX_RESET_HDR10 = 0x00010000; /// Enable HDR10 rendering. enum uint BGFX_RESET_HIDPI = 0x00020000; /// Enable HiDPI rendering. enum uint BGFX_RESET_DEPTH_CLAMP = 0x00040000; /// Enable depth clamp. enum uint BGFX_RESET_SUSPEND = 0x00080000; /// Suspend rendering. +enum uint BGFX_RESET_TRANSPARENT_BACKBUFFER = 0x00100000; /// Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`. enum uint BGFX_RESET_FULLSCREEN_SHIFT = 0; enum uint BGFX_RESET_FULLSCREEN_MASK = 0x00000001; @@ -399,16 +400,17 @@ enum ulong BGFX_CAPS_SWAP_CHAIN = 0x0000000000008000; /// Multiple windows are s enum ulong BGFX_CAPS_TEXTURE_2D_ARRAY = 0x0000000000010000; /// 2D texture array is supported. enum ulong BGFX_CAPS_TEXTURE_3D = 0x0000000000020000; /// 3D textures are supported. enum ulong BGFX_CAPS_TEXTURE_BLIT = 0x0000000000040000; /// Texture blit is supported. -enum ulong BGFX_CAPS_TEXTURE_COMPARE_RESERVED = 0x0000000000080000; -enum ulong BGFX_CAPS_TEXTURE_COMPARE_LEQUAL = 0x0000000000100000; /// Texture compare less equal mode is supported. -enum ulong BGFX_CAPS_TEXTURE_CUBE_ARRAY = 0x0000000000200000; /// Cubemap texture array is supported. -enum ulong BGFX_CAPS_TEXTURE_DIRECT_ACCESS = 0x0000000000400000; /// CPU direct access to GPU texture memory. -enum ulong BGFX_CAPS_TEXTURE_READ_BACK = 0x0000000000800000; /// Read-back texture is supported. -enum ulong BGFX_CAPS_VERTEX_ATTRIB_HALF = 0x0000000001000000; /// Vertex attribute half-float is supported. -enum ulong BGFX_CAPS_VERTEX_ATTRIB_UINT10 = 0x0000000002000000; /// Vertex attribute 10_10_10_2 is supported. -enum ulong BGFX_CAPS_VERTEX_ID = 0x0000000004000000; /// Rendering with VertexID only is supported. -enum ulong BGFX_CAPS_VIEWPORT_LAYER_ARRAY = 0x0000000008000000; /// Viewport layer is available in vertex shader. -enum ulong BGFX_CAPS_TEXTURE_COMPARE_ALL = 0x0000000000180000; /// All texture compare modes are supported. +enum ulong BGFX_CAPS_TRANSPARENT_BACKBUFFER = 0x0000000000080000; /// Transparent back buffer supported. +enum ulong BGFX_CAPS_TEXTURE_COMPARE_RESERVED = 0x0000000000100000; +enum ulong BGFX_CAPS_TEXTURE_COMPARE_LEQUAL = 0x0000000000200000; /// Texture compare less equal mode is supported. +enum ulong BGFX_CAPS_TEXTURE_CUBE_ARRAY = 0x0000000000400000; /// Cubemap texture array is supported. +enum ulong BGFX_CAPS_TEXTURE_DIRECT_ACCESS = 0x0000000000800000; /// CPU direct access to GPU texture memory. +enum ulong BGFX_CAPS_TEXTURE_READ_BACK = 0x0000000001000000; /// Read-back texture is supported. +enum ulong BGFX_CAPS_VERTEX_ATTRIB_HALF = 0x0000000002000000; /// Vertex attribute half-float is supported. +enum ulong BGFX_CAPS_VERTEX_ATTRIB_UINT10 = 0x0000000004000000; /// Vertex attribute 10_10_10_2 is supported. +enum ulong BGFX_CAPS_VERTEX_ID = 0x0000000008000000; /// Rendering with VertexID only is supported. +enum ulong BGFX_CAPS_VIEWPORT_LAYER_ARRAY = 0x0000000010000000; /// Viewport layer is available in vertex shader. +enum ulong BGFX_CAPS_TEXTURE_COMPARE_ALL = 0x0000000000300000; /// All texture compare modes are supported. enum uint BGFX_CAPS_FORMAT_TEXTURE_NONE = 0x00000000; /// Texture format is not supported. enum uint BGFX_CAPS_FORMAT_TEXTURE_2D = 0x00000001; /// Texture format is supported. diff --git a/bindings/zig/bgfx.zig b/bindings/zig/bgfx.zig index 4e4f6fab2..106fb1fed 100644 --- a/bindings/zig/bgfx.zig +++ b/bindings/zig/bgfx.zig @@ -617,6 +617,9 @@ pub const ResetFlags_DepthClamp: ResetFlags = 0x00040000; /// Suspend rendering. pub const ResetFlags_Suspend: ResetFlags = 0x00080000; + +/// Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`. +pub const ResetFlags_TransparentBackbuffer: ResetFlags = 0x00100000; pub const ResetFlags_FullscreenShift: ResetFlags = 0; pub const ResetFlags_FullscreenMask: ResetFlags = 0x00000001; pub const ResetFlags_ReservedShift: ResetFlags = 31; @@ -679,34 +682,37 @@ pub const CapsFlags_Texture3D: CapsFlags = 0x0000000000020000; /// Texture blit is supported. pub const CapsFlags_TextureBlit: CapsFlags = 0x0000000000040000; -pub const CapsFlags_TextureCompareReserved: CapsFlags = 0x0000000000080000; + +/// Transparent back buffer supported. +pub const CapsFlags_TransparentBackbuffer: CapsFlags = 0x0000000000080000; +pub const CapsFlags_TextureCompareReserved: CapsFlags = 0x0000000000100000; /// Texture compare less equal mode is supported. -pub const CapsFlags_TextureCompareLequal: CapsFlags = 0x0000000000100000; +pub const CapsFlags_TextureCompareLequal: CapsFlags = 0x0000000000200000; /// Cubemap texture array is supported. -pub const CapsFlags_TextureCubeArray: CapsFlags = 0x0000000000200000; +pub const CapsFlags_TextureCubeArray: CapsFlags = 0x0000000000400000; /// CPU direct access to GPU texture memory. -pub const CapsFlags_TextureDirectAccess: CapsFlags = 0x0000000000400000; +pub const CapsFlags_TextureDirectAccess: CapsFlags = 0x0000000000800000; /// Read-back texture is supported. -pub const CapsFlags_TextureReadBack: CapsFlags = 0x0000000000800000; +pub const CapsFlags_TextureReadBack: CapsFlags = 0x0000000001000000; /// Vertex attribute half-float is supported. -pub const CapsFlags_VertexAttribHalf: CapsFlags = 0x0000000001000000; +pub const CapsFlags_VertexAttribHalf: CapsFlags = 0x0000000002000000; /// Vertex attribute 10_10_10_2 is supported. -pub const CapsFlags_VertexAttribUint10: CapsFlags = 0x0000000002000000; +pub const CapsFlags_VertexAttribUint10: CapsFlags = 0x0000000004000000; /// Rendering with VertexID only is supported. -pub const CapsFlags_VertexId: CapsFlags = 0x0000000004000000; +pub const CapsFlags_VertexId: CapsFlags = 0x0000000008000000; /// Viewport layer is available in vertex shader. -pub const CapsFlags_ViewportLayerArray: CapsFlags = 0x0000000008000000; +pub const CapsFlags_ViewportLayerArray: CapsFlags = 0x0000000010000000; /// All texture compare modes are supported. -pub const CapsFlags_TextureCompareAll: CapsFlags = 0x0000000000180000; +pub const CapsFlags_TextureCompareAll: CapsFlags = 0x0000000000300000; pub const CapsFormatFlags = u32; /// Texture format is not supported. diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 9e30eeb4b..c586ac631 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -453,6 +453,7 @@ #define BGFX_RESET_HIDPI UINT32_C(0x00020000) //!< Enable HiDPI rendering. #define BGFX_RESET_DEPTH_CLAMP UINT32_C(0x00040000) //!< Enable depth clamp. #define BGFX_RESET_SUSPEND UINT32_C(0x00080000) //!< Suspend rendering. +#define BGFX_RESET_TRANSPARENT_BACKBUFFER UINT32_C(0x00100000) //!< Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`. #define BGFX_RESET_FULLSCREEN_SHIFT 0 @@ -480,15 +481,16 @@ #define BGFX_CAPS_TEXTURE_2D_ARRAY UINT64_C(0x0000000000010000) //!< 2D texture array is supported. #define BGFX_CAPS_TEXTURE_3D UINT64_C(0x0000000000020000) //!< 3D textures are supported. #define BGFX_CAPS_TEXTURE_BLIT UINT64_C(0x0000000000040000) //!< Texture blit is supported. -#define BGFX_CAPS_TEXTURE_COMPARE_RESERVED UINT64_C(0x0000000000080000) -#define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000100000) //!< Texture compare less equal mode is supported. -#define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000200000) //!< Cubemap texture array is supported. -#define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000000400000) //!< CPU direct access to GPU texture memory. -#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000000800000) //!< Read-back texture is supported. -#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000001000000) //!< Vertex attribute half-float is supported. -#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000002000000) //!< Vertex attribute 10_10_10_2 is supported. -#define BGFX_CAPS_VERTEX_ID UINT64_C(0x0000000004000000) //!< Rendering with VertexID only is supported. -#define BGFX_CAPS_VIEWPORT_LAYER_ARRAY UINT64_C(0x0000000008000000) //!< Viewport layer is available in vertex shader. +#define BGFX_CAPS_TRANSPARENT_BACKBUFFER UINT64_C(0x0000000000080000) //!< Transparent back buffer supported. +#define BGFX_CAPS_TEXTURE_COMPARE_RESERVED UINT64_C(0x0000000000100000) +#define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000200000) //!< Texture compare less equal mode is supported. +#define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000400000) //!< Cubemap texture array is supported. +#define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000000800000) //!< CPU direct access to GPU texture memory. +#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000001000000) //!< Read-back texture is supported. +#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000002000000) //!< Vertex attribute half-float is supported. +#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000004000000) //!< Vertex attribute 10_10_10_2 is supported. +#define BGFX_CAPS_VERTEX_ID UINT64_C(0x0000000008000000) //!< Rendering with VertexID only is supported. +#define BGFX_CAPS_VIEWPORT_LAYER_ARRAY UINT64_C(0x0000000010000000) //!< Viewport layer is available in vertex shader. /// All texture compare modes are supported. #define BGFX_CAPS_TEXTURE_COMPARE_ALL (0 \ | BGFX_CAPS_TEXTURE_COMPARE_RESERVED \ diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index 8c904cd1d..fd8f6f2eb 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -343,19 +343,20 @@ flag.ResetMsaa { bits = 32, shift = 4, range = 3, base = 1 } () flag.Reset { bits = 32 } - .None ( 0) --- No reset flags. - .Fullscreen ( 1) --- Not supported yet. - .Vsync ( 8) --- Enable V-Sync. - .Maxanisotropy ( 9) --- Turn on/off max anisotropy. - .Capture (10) --- Begin screen capture. - .FlushAfterRender (14) --- Flush rendering after submitting to GPU. - .FlipAfterRender (15) --- This flag specifies where flip occurs. Default behaviour is that flip occurs - --- before rendering new frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`. - .SrgbBackbuffer (16) --- Enable sRGB backbuffer. - .Hdr10 (17) --- Enable HDR10 rendering. - .Hidpi (18) --- Enable HiDPI rendering. - .DepthClamp (19) --- Enable depth clamp. - .Suspend (20) --- Suspend rendering. + .None ( 0) --- No reset flags. + .Fullscreen ( 1) --- Not supported yet. + .Vsync ( 8) --- Enable V-Sync. + .Maxanisotropy ( 9) --- Turn on/off max anisotropy. + .Capture (10) --- Begin screen capture. + .FlushAfterRender (14) --- Flush rendering after submitting to GPU. + .FlipAfterRender (15) --- This flag specifies where flip occurs. Default behaviour is that flip occurs + --- before rendering new frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`. + .SrgbBackbuffer (16) --- Enable sRGB backbuffer. + .Hdr10 (17) --- Enable HDR10 rendering. + .Hidpi (18) --- Enable HiDPI rendering. + .DepthClamp (19) --- Enable depth clamp. + .Suspend (20) --- Suspend rendering. + .TransparentBackbuffer (21) --- Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`. () flag.ResetFullscreen { bits = 32, shift = 0, range = 1, base = 1 } @@ -383,6 +384,7 @@ flag.Caps { bits = 64, base = 1, name = "Caps" } .Texture_2dArray --- 2D texture array is supported. .Texture_3d --- 3D textures are supported. .TextureBlit --- Texture blit is supported. + .TransparentBackbuffer --- Transparent back buffer supported. .TextureCompareReserved .TextureCompareLequal --- Texture compare less equal mode is supported. .TextureCubeArray --- Cubemap texture array is supported. diff --git a/src/dxgi.cpp b/src/dxgi.cpp index 29b3dc50d..e77fbf8cf 100644 --- a/src/dxgi.cpp +++ b/src/dxgi.cpp @@ -308,6 +308,7 @@ namespace bgfx } _caps.supported |= hdr10 ? BGFX_CAPS_HDR10 : 0; + _caps.supported |= BX_ENABLED(BX_PLATFORM_WINRT) ? BGFX_CAPS_TRANSPARENT_BACKBUFFER : 0; DX_RELEASE(adapter, adapter == m_adapter ? 1 : 0); } diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 787996820..794c369c2 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1035,7 +1035,9 @@ namespace bgfx { namespace d3d11 : DXGI_SCALING_STRETCH ; m_scd.swapEffect = m_swapEffect; - m_scd.alphaMode = DXGI_ALPHA_MODE_IGNORE; + + m_scd.alphaMode = (_init.resolution.reset & BGFX_RESET_TRANSPARENT_BACKBUFFER) ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE; + m_scd.flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; m_scd.maxFrameLatency = bx::min(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY); @@ -3425,6 +3427,50 @@ namespace bgfx { namespace d3d11 } } + void premultiplyBackBuffer(const ClearQuad& _clearQuad) + { + ID3D11DeviceContext* deviceCtx = m_deviceCtx; + + uint64_t state = 0; + state |= BGFX_STATE_WRITE_RGB; + state |= BGFX_STATE_DEPTH_TEST_ALWAYS; + state |= BGFX_STATE_BLEND_FUNC_SEPARATE(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_DST_ALPHA, BGFX_STATE_BLEND_DST_ALPHA, BGFX_STATE_BLEND_ZERO); + + uint64_t stencil = 0; + + setBlendState(state); + setDepthStencilState(state, stencil); + setRasterizerState(state); + + uint32_t numMrt = 1; + if (isValid(_clearQuad.m_program[numMrt-1])) + { + ProgramD3D11& program = m_program[_clearQuad.m_program[numMrt-1].idx]; + m_currentProgram = &program; + + const ShaderD3D11* vsh = program.m_vsh; + deviceCtx->VSSetShader(vsh->m_vertexShader, NULL, 0); + deviceCtx->VSSetConstantBuffers(0, 1, &vsh->m_buffer); + + const ShaderD3D11* fsh = program.m_fsh; + deviceCtx->PSSetShader(fsh->m_pixelShader, NULL, 0); + + VertexBufferD3D11& vb = m_vertexBuffers[_clearQuad.m_vb.idx]; + const VertexLayout& layout = _clearQuad.m_layout; + + const uint32_t stride = layout.m_stride; + const uint32_t offset = 0; + + deviceCtx->IASetVertexBuffers(0, 1, &vb.m_ptr, &stride, &offset); + setInputLayout(layout, program, 0); + + m_deviceCtx->OMSetRenderTargets(1, &m_backBufferColor, m_backBufferDepthStencil); + + deviceCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + deviceCtx->Draw(4, 0); + } + } + void clearQuad(ClearQuad& _clearQuad, const Rect& _rect, const Clear& _clear, const float _palette[][4]) { uint32_t width; @@ -6626,6 +6672,11 @@ namespace bgfx { namespace d3d11 BGFX_D3D11_PROFILER_END(); } + if (m_resolution.reset & BGFX_RESET_TRANSPARENT_BACKBUFFER) + { + premultiplyBackBuffer(_clearQuad); + } + m_deviceCtx->OMSetRenderTargets(1, s_zero.m_rtv, NULL); if (NULL != m_msaaRt) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d3df29e96..81cbaf7ed 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -3028,6 +3028,8 @@ namespace bgfx { namespace gl : 0 ; + g_caps.supported |= BX_ENABLED(BX_PLATFORM_WINRT) ? BGFX_CAPS_TRANSPARENT_BACKBUFFER : 0; + if (s_extension[Extension::ARB_debug_output].m_supported || s_extension[Extension::KHR_debug].m_supported) { @@ -3577,7 +3579,7 @@ namespace bgfx { namespace gl void submitBlit(BlitState& _bs, uint16_t _view); void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override; - + void premultiplyBackBuffer(const ClearQuad& _clearQuad); void blitSetup(TextVideoMemBlitter& _blitter) override { if (0 != m_vao) @@ -7374,6 +7376,39 @@ namespace bgfx { namespace gl } } + void RendererContextGL::premultiplyBackBuffer(const ClearQuad& _clearQuad) + { + const uint32_t numMrt = 1; + if (isValid(_clearQuad.m_program[numMrt - 1])) + { + GL_CHECK(glDisable(GL_SCISSOR_TEST)); + GL_CHECK(glDisable(GL_CULL_FACE)); + GL_CHECK(glEnable(GL_BLEND)); + GL_CHECK(glEnable(GL_BLEND)); + GL_CHECK(glBlendFuncSeparate(GL_DST_COLOR, GL_DST_ALPHA, GL_DST_ALPHA, GL_ZERO)); + + GL_CHECK(glColorMask(true, true, true, false)); + GL_CHECK(glDisable(GL_DEPTH_TEST)); + GL_CHECK(glDisable(GL_STENCIL_TEST)); + + const VertexBufferGL& vb = m_vertexBuffers[_clearQuad.m_vb.idx]; + const VertexLayout& layout = _clearQuad.m_layout; + + GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id)); + + ProgramGL& program = m_program[_clearQuad.m_program[numMrt - 1].idx]; + setProgram(program.m_id); + program.bindAttributesBegin(); + program.bindAttributes(layout, 0); + program.bindAttributesEnd(); + + GL_CHECK(glDrawArrays(GL_TRIANGLE_STRIP + , 0 + , 4 + )); + } + } + void RendererContextGL::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { if (_render->m_capture) @@ -8461,6 +8496,11 @@ namespace bgfx { namespace gl } } + if (m_resolution.reset & BGFX_RESET_TRANSPARENT_BACKBUFFER) + { + premultiplyBackBuffer(_clearQuad); + } + BGFX_GL_PROFILER_END(); m_glctx.makeCurrent(NULL);