premultiplied backbuffer for UWP/SwapchainPanel (#2837)

* premultiplied backbuffer for UWP/SwapchainPanel

* init flag

* caps and feedback/opengl premul

* reduced #ifdef form

* removed ifdef
This commit is contained in:
Cedric Guillemet 2022-07-18 18:23:57 +02:00 committed by GitHub
parent 116cea9238
commit a3d52fab32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 188 additions and 64 deletions

View File

@ -997,6 +997,11 @@ public static class bgfx
/// Suspend rendering. /// Suspend rendering.
/// </summary> /// </summary>
Suspend = 0x00080000, Suspend = 0x00080000,
/// <summary>
/// Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`.
/// </summary>
TransparentBackbuffer = 0x00100000,
FullscreenShift = 0, FullscreenShift = 0,
FullscreenMask = 0x00000001, FullscreenMask = 0x00000001,
ReservedShift = 31, ReservedShift = 31,
@ -1100,52 +1105,57 @@ public static class bgfx
/// Texture blit is supported. /// Texture blit is supported.
/// </summary> /// </summary>
TextureBlit = 0x0000000000040000, TextureBlit = 0x0000000000040000,
TextureCompareReserved = 0x0000000000080000,
/// <summary>
/// Transparent back buffer supported.
/// </summary>
TransparentBackbuffer = 0x0000000000080000,
TextureCompareReserved = 0x0000000000100000,
/// <summary> /// <summary>
/// Texture compare less equal mode is supported. /// Texture compare less equal mode is supported.
/// </summary> /// </summary>
TextureCompareLequal = 0x0000000000100000, TextureCompareLequal = 0x0000000000200000,
/// <summary> /// <summary>
/// Cubemap texture array is supported. /// Cubemap texture array is supported.
/// </summary> /// </summary>
TextureCubeArray = 0x0000000000200000, TextureCubeArray = 0x0000000000400000,
/// <summary> /// <summary>
/// CPU direct access to GPU texture memory. /// CPU direct access to GPU texture memory.
/// </summary> /// </summary>
TextureDirectAccess = 0x0000000000400000, TextureDirectAccess = 0x0000000000800000,
/// <summary> /// <summary>
/// Read-back texture is supported. /// Read-back texture is supported.
/// </summary> /// </summary>
TextureReadBack = 0x0000000000800000, TextureReadBack = 0x0000000001000000,
/// <summary> /// <summary>
/// Vertex attribute half-float is supported. /// Vertex attribute half-float is supported.
/// </summary> /// </summary>
VertexAttribHalf = 0x0000000001000000, VertexAttribHalf = 0x0000000002000000,
/// <summary> /// <summary>
/// Vertex attribute 10_10_10_2 is supported. /// Vertex attribute 10_10_10_2 is supported.
/// </summary> /// </summary>
VertexAttribUint10 = 0x0000000002000000, VertexAttribUint10 = 0x0000000004000000,
/// <summary> /// <summary>
/// Rendering with VertexID only is supported. /// Rendering with VertexID only is supported.
/// </summary> /// </summary>
VertexId = 0x0000000004000000, VertexId = 0x0000000008000000,
/// <summary> /// <summary>
/// Viewport layer is available in vertex shader. /// Viewport layer is available in vertex shader.
/// </summary> /// </summary>
ViewportLayerArray = 0x0000000008000000, ViewportLayerArray = 0x0000000010000000,
/// <summary> /// <summary>
/// All texture compare modes are supported. /// All texture compare modes are supported.
/// </summary> /// </summary>
TextureCompareAll = 0x0000000000180000, TextureCompareAll = 0x0000000000300000,
} }
[AllowDuplicates] [AllowDuplicates]

View File

@ -996,6 +996,11 @@ public static partial class bgfx
/// Suspend rendering. /// Suspend rendering.
/// </summary> /// </summary>
Suspend = 0x00080000, Suspend = 0x00080000,
/// <summary>
/// Transparent backbuffer. Availability depends on: `BGFX_CAPS_TRANSPARENT_BACKBUFFER`.
/// </summary>
TransparentBackbuffer = 0x00100000,
FullscreenShift = 0, FullscreenShift = 0,
FullscreenMask = 0x00000001, FullscreenMask = 0x00000001,
ReservedShift = 31, ReservedShift = 31,
@ -1099,52 +1104,57 @@ public static partial class bgfx
/// Texture blit is supported. /// Texture blit is supported.
/// </summary> /// </summary>
TextureBlit = 0x0000000000040000, TextureBlit = 0x0000000000040000,
TextureCompareReserved = 0x0000000000080000,
/// <summary>
/// Transparent back buffer supported.
/// </summary>
TransparentBackbuffer = 0x0000000000080000,
TextureCompareReserved = 0x0000000000100000,
/// <summary> /// <summary>
/// Texture compare less equal mode is supported. /// Texture compare less equal mode is supported.
/// </summary> /// </summary>
TextureCompareLequal = 0x0000000000100000, TextureCompareLequal = 0x0000000000200000,
/// <summary> /// <summary>
/// Cubemap texture array is supported. /// Cubemap texture array is supported.
/// </summary> /// </summary>
TextureCubeArray = 0x0000000000200000, TextureCubeArray = 0x0000000000400000,
/// <summary> /// <summary>
/// CPU direct access to GPU texture memory. /// CPU direct access to GPU texture memory.
/// </summary> /// </summary>
TextureDirectAccess = 0x0000000000400000, TextureDirectAccess = 0x0000000000800000,
/// <summary> /// <summary>
/// Read-back texture is supported. /// Read-back texture is supported.
/// </summary> /// </summary>
TextureReadBack = 0x0000000000800000, TextureReadBack = 0x0000000001000000,
/// <summary> /// <summary>
/// Vertex attribute half-float is supported. /// Vertex attribute half-float is supported.
/// </summary> /// </summary>
VertexAttribHalf = 0x0000000001000000, VertexAttribHalf = 0x0000000002000000,
/// <summary> /// <summary>
/// Vertex attribute 10_10_10_2 is supported. /// Vertex attribute 10_10_10_2 is supported.
/// </summary> /// </summary>
VertexAttribUint10 = 0x0000000002000000, VertexAttribUint10 = 0x0000000004000000,
/// <summary> /// <summary>
/// Rendering with VertexID only is supported. /// Rendering with VertexID only is supported.
/// </summary> /// </summary>
VertexId = 0x0000000004000000, VertexId = 0x0000000008000000,
/// <summary> /// <summary>
/// Viewport layer is available in vertex shader. /// Viewport layer is available in vertex shader.
/// </summary> /// </summary>
ViewportLayerArray = 0x0000000008000000, ViewportLayerArray = 0x0000000010000000,
/// <summary> /// <summary>
/// All texture compare modes are supported. /// All texture compare modes are supported.
/// </summary> /// </summary>
TextureCompareAll = 0x0000000000180000, TextureCompareAll = 0x0000000000300000,
} }
[Flags] [Flags]

View File

@ -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_HIDPI = 0x00020000; /// Enable HiDPI rendering.
enum uint BGFX_RESET_DEPTH_CLAMP = 0x00040000; /// Enable depth clamp. enum uint BGFX_RESET_DEPTH_CLAMP = 0x00040000; /// Enable depth clamp.
enum uint BGFX_RESET_SUSPEND = 0x00080000; /// Suspend rendering. 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_SHIFT = 0;
enum uint BGFX_RESET_FULLSCREEN_MASK = 0x00000001; 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_2D_ARRAY = 0x0000000000010000; /// 2D texture array is supported.
enum ulong BGFX_CAPS_TEXTURE_3D = 0x0000000000020000; /// 3D textures are 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_BLIT = 0x0000000000040000; /// Texture blit is supported.
enum ulong BGFX_CAPS_TEXTURE_COMPARE_RESERVED = 0x0000000000080000; enum ulong BGFX_CAPS_TRANSPARENT_BACKBUFFER = 0x0000000000080000; /// Transparent back buffer supported.
enum ulong BGFX_CAPS_TEXTURE_COMPARE_LEQUAL = 0x0000000000100000; /// Texture compare less equal mode is supported. enum ulong BGFX_CAPS_TEXTURE_COMPARE_RESERVED = 0x0000000000100000;
enum ulong BGFX_CAPS_TEXTURE_CUBE_ARRAY = 0x0000000000200000; /// Cubemap texture array is supported. enum ulong BGFX_CAPS_TEXTURE_COMPARE_LEQUAL = 0x0000000000200000; /// Texture compare less equal mode is supported.
enum ulong BGFX_CAPS_TEXTURE_DIRECT_ACCESS = 0x0000000000400000; /// CPU direct access to GPU texture memory. enum ulong BGFX_CAPS_TEXTURE_CUBE_ARRAY = 0x0000000000400000; /// Cubemap texture array is supported.
enum ulong BGFX_CAPS_TEXTURE_READ_BACK = 0x0000000000800000; /// Read-back texture is supported. enum ulong BGFX_CAPS_TEXTURE_DIRECT_ACCESS = 0x0000000000800000; /// CPU direct access to GPU texture memory.
enum ulong BGFX_CAPS_VERTEX_ATTRIB_HALF = 0x0000000001000000; /// Vertex attribute half-float is supported. enum ulong BGFX_CAPS_TEXTURE_READ_BACK = 0x0000000001000000; /// Read-back texture is supported.
enum ulong BGFX_CAPS_VERTEX_ATTRIB_UINT10 = 0x0000000002000000; /// Vertex attribute 10_10_10_2 is supported. enum ulong BGFX_CAPS_VERTEX_ATTRIB_HALF = 0x0000000002000000; /// Vertex attribute half-float is supported.
enum ulong BGFX_CAPS_VERTEX_ID = 0x0000000004000000; /// Rendering with VertexID only is supported. enum ulong BGFX_CAPS_VERTEX_ATTRIB_UINT10 = 0x0000000004000000; /// Vertex attribute 10_10_10_2 is supported.
enum ulong BGFX_CAPS_VIEWPORT_LAYER_ARRAY = 0x0000000008000000; /// Viewport layer is available in vertex shader. enum ulong BGFX_CAPS_VERTEX_ID = 0x0000000008000000; /// Rendering with VertexID only is supported.
enum ulong BGFX_CAPS_TEXTURE_COMPARE_ALL = 0x0000000000180000; /// All texture compare modes are 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_NONE = 0x00000000; /// Texture format is not supported.
enum uint BGFX_CAPS_FORMAT_TEXTURE_2D = 0x00000001; /// Texture format is supported. enum uint BGFX_CAPS_FORMAT_TEXTURE_2D = 0x00000001; /// Texture format is supported.

View File

@ -617,6 +617,9 @@ pub const ResetFlags_DepthClamp: ResetFlags = 0x00040000;
/// Suspend rendering. /// Suspend rendering.
pub const ResetFlags_Suspend: ResetFlags = 0x00080000; 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_FullscreenShift: ResetFlags = 0;
pub const ResetFlags_FullscreenMask: ResetFlags = 0x00000001; pub const ResetFlags_FullscreenMask: ResetFlags = 0x00000001;
pub const ResetFlags_ReservedShift: ResetFlags = 31; pub const ResetFlags_ReservedShift: ResetFlags = 31;
@ -679,34 +682,37 @@ pub const CapsFlags_Texture3D: CapsFlags = 0x0000000000020000;
/// Texture blit is supported. /// Texture blit is supported.
pub const CapsFlags_TextureBlit: CapsFlags = 0x0000000000040000; 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. /// Texture compare less equal mode is supported.
pub const CapsFlags_TextureCompareLequal: CapsFlags = 0x0000000000100000; pub const CapsFlags_TextureCompareLequal: CapsFlags = 0x0000000000200000;
/// Cubemap texture array is supported. /// Cubemap texture array is supported.
pub const CapsFlags_TextureCubeArray: CapsFlags = 0x0000000000200000; pub const CapsFlags_TextureCubeArray: CapsFlags = 0x0000000000400000;
/// CPU direct access to GPU texture memory. /// CPU direct access to GPU texture memory.
pub const CapsFlags_TextureDirectAccess: CapsFlags = 0x0000000000400000; pub const CapsFlags_TextureDirectAccess: CapsFlags = 0x0000000000800000;
/// Read-back texture is supported. /// Read-back texture is supported.
pub const CapsFlags_TextureReadBack: CapsFlags = 0x0000000000800000; pub const CapsFlags_TextureReadBack: CapsFlags = 0x0000000001000000;
/// Vertex attribute half-float is supported. /// 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. /// 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. /// 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. /// 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. /// All texture compare modes are supported.
pub const CapsFlags_TextureCompareAll: CapsFlags = 0x0000000000180000; pub const CapsFlags_TextureCompareAll: CapsFlags = 0x0000000000300000;
pub const CapsFormatFlags = u32; pub const CapsFormatFlags = u32;
/// Texture format is not supported. /// Texture format is not supported.

View File

@ -453,6 +453,7 @@
#define BGFX_RESET_HIDPI UINT32_C(0x00020000) //!< Enable HiDPI rendering. #define BGFX_RESET_HIDPI UINT32_C(0x00020000) //!< Enable HiDPI rendering.
#define BGFX_RESET_DEPTH_CLAMP UINT32_C(0x00040000) //!< Enable depth clamp. #define BGFX_RESET_DEPTH_CLAMP UINT32_C(0x00040000) //!< Enable depth clamp.
#define BGFX_RESET_SUSPEND UINT32_C(0x00080000) //!< Suspend rendering. #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 #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_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_3D UINT64_C(0x0000000000020000) //!< 3D textures are supported.
#define BGFX_CAPS_TEXTURE_BLIT UINT64_C(0x0000000000040000) //!< Texture blit is 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_TRANSPARENT_BACKBUFFER UINT64_C(0x0000000000080000) //!< Transparent back buffer supported.
#define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000100000) //!< Texture compare less equal mode is supported. #define BGFX_CAPS_TEXTURE_COMPARE_RESERVED UINT64_C(0x0000000000100000)
#define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000200000) //!< Cubemap texture array is supported. #define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000200000) //!< Texture compare less equal mode is supported.
#define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000000400000) //!< CPU direct access to GPU texture memory. #define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000400000) //!< Cubemap texture array is supported.
#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000000800000) //!< Read-back texture is supported. #define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000000800000) //!< CPU direct access to GPU texture memory.
#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000001000000) //!< Vertex attribute half-float is supported. #define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000001000000) //!< Read-back texture is supported.
#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000002000000) //!< Vertex attribute 10_10_10_2 is supported. #define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000002000000) //!< Vertex attribute half-float is supported.
#define BGFX_CAPS_VERTEX_ID UINT64_C(0x0000000004000000) //!< Rendering with VertexID only is supported. #define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000004000000) //!< Vertex attribute 10_10_10_2 is supported.
#define BGFX_CAPS_VIEWPORT_LAYER_ARRAY UINT64_C(0x0000000008000000) //!< Viewport layer is available in vertex shader. #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. /// All texture compare modes are supported.
#define BGFX_CAPS_TEXTURE_COMPARE_ALL (0 \ #define BGFX_CAPS_TEXTURE_COMPARE_ALL (0 \
| BGFX_CAPS_TEXTURE_COMPARE_RESERVED \ | BGFX_CAPS_TEXTURE_COMPARE_RESERVED \

View File

@ -343,19 +343,20 @@ flag.ResetMsaa { bits = 32, shift = 4, range = 3, base = 1 }
() ()
flag.Reset { bits = 32 } flag.Reset { bits = 32 }
.None ( 0) --- No reset flags. .None ( 0) --- No reset flags.
.Fullscreen ( 1) --- Not supported yet. .Fullscreen ( 1) --- Not supported yet.
.Vsync ( 8) --- Enable V-Sync. .Vsync ( 8) --- Enable V-Sync.
.Maxanisotropy ( 9) --- Turn on/off max anisotropy. .Maxanisotropy ( 9) --- Turn on/off max anisotropy.
.Capture (10) --- Begin screen capture. .Capture (10) --- Begin screen capture.
.FlushAfterRender (14) --- Flush rendering after submitting to GPU. .FlushAfterRender (14) --- Flush rendering after submitting to GPU.
.FlipAfterRender (15) --- This flag specifies where flip occurs. Default behaviour is that flip occurs .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`. --- before rendering new frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`.
.SrgbBackbuffer (16) --- Enable sRGB backbuffer. .SrgbBackbuffer (16) --- Enable sRGB backbuffer.
.Hdr10 (17) --- Enable HDR10 rendering. .Hdr10 (17) --- Enable HDR10 rendering.
.Hidpi (18) --- Enable HiDPI rendering. .Hidpi (18) --- Enable HiDPI rendering.
.DepthClamp (19) --- Enable depth clamp. .DepthClamp (19) --- Enable depth clamp.
.Suspend (20) --- Suspend rendering. .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 } 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_2dArray --- 2D texture array is supported.
.Texture_3d --- 3D textures are supported. .Texture_3d --- 3D textures are supported.
.TextureBlit --- Texture blit is supported. .TextureBlit --- Texture blit is supported.
.TransparentBackbuffer --- Transparent back buffer supported.
.TextureCompareReserved .TextureCompareReserved
.TextureCompareLequal --- Texture compare less equal mode is supported. .TextureCompareLequal --- Texture compare less equal mode is supported.
.TextureCubeArray --- Cubemap texture array is supported. .TextureCubeArray --- Cubemap texture array is supported.

View File

@ -308,6 +308,7 @@ namespace bgfx
} }
_caps.supported |= hdr10 ? BGFX_CAPS_HDR10 : 0; _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); DX_RELEASE(adapter, adapter == m_adapter ? 1 : 0);
} }

View File

@ -1035,7 +1035,9 @@ namespace bgfx { namespace d3d11
: DXGI_SCALING_STRETCH : DXGI_SCALING_STRETCH
; ;
m_scd.swapEffect = m_swapEffect; 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.flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
m_scd.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY); m_scd.maxFrameLatency = bx::min<uint8_t>(_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]) void clearQuad(ClearQuad& _clearQuad, const Rect& _rect, const Clear& _clear, const float _palette[][4])
{ {
uint32_t width; uint32_t width;
@ -6626,6 +6672,11 @@ namespace bgfx { namespace d3d11
BGFX_D3D11_PROFILER_END(); BGFX_D3D11_PROFILER_END();
} }
if (m_resolution.reset & BGFX_RESET_TRANSPARENT_BACKBUFFER)
{
premultiplyBackBuffer(_clearQuad);
}
m_deviceCtx->OMSetRenderTargets(1, s_zero.m_rtv, NULL); m_deviceCtx->OMSetRenderTargets(1, s_zero.m_rtv, NULL);
if (NULL != m_msaaRt) if (NULL != m_msaaRt)

View File

@ -3028,6 +3028,8 @@ namespace bgfx { namespace gl
: 0 : 0
; ;
g_caps.supported |= BX_ENABLED(BX_PLATFORM_WINRT) ? BGFX_CAPS_TRANSPARENT_BACKBUFFER : 0;
if (s_extension[Extension::ARB_debug_output].m_supported if (s_extension[Extension::ARB_debug_output].m_supported
|| s_extension[Extension::KHR_debug].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 submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override; void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;
void premultiplyBackBuffer(const ClearQuad& _clearQuad);
void blitSetup(TextVideoMemBlitter& _blitter) override void blitSetup(TextVideoMemBlitter& _blitter) override
{ {
if (0 != m_vao) 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) void RendererContextGL::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter)
{ {
if (_render->m_capture) 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(); BGFX_GL_PROFILER_END();
m_glctx.makeCurrent(NULL); m_glctx.makeCurrent(NULL);