diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 77d4e6e3..dd141e7c 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -363,7 +363,7 @@ class HDR : public entry::AppI // Set views. for (uint32_t ii = 0; ii < 6; ++ii) { - bgfx::setViewRect(ii, 0, 0, m_width, m_height); + bgfx::setViewRect(ii, 0, 0, bgfx::BackbufferRatio::Equal); } bgfx::setViewFrameBuffer(0, m_fbh); bgfx::setViewFrameBuffer(1, m_fbh); @@ -384,13 +384,13 @@ class HDR : public entry::AppI bgfx::setViewRect(6, 0, 0, 1, 1); bgfx::setViewFrameBuffer(6, m_lum[4]); - bgfx::setViewRect(7, 0, 0, m_width/2, m_height/2); + bgfx::setViewRect(7, 0, 0, bgfx::BackbufferRatio::Half); bgfx::setViewFrameBuffer(7, m_bright); - bgfx::setViewRect(8, 0, 0, m_width/8, m_height/8); + bgfx::setViewRect(8, 0, 0, bgfx::BackbufferRatio::Eighth); bgfx::setViewFrameBuffer(8, m_blur); - bgfx::setViewRect(9, 0, 0, m_width, m_height); + bgfx::setViewRect(9, 0, 0, bgfx::BackbufferRatio::Equal); float view[16]; float proj[16]; diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 6eb57abb..06a117ad 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -1569,6 +1569,9 @@ namespace bgfx /// void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + /// + void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio); + /// Set view scissor. Draw primitive outside view will be clipped. When /// _x, _y, _width and _height are set to 0, scissor will be disabled. /// diff --git a/src/bgfx.cpp b/src/bgfx.cpp index f3989bae..a5fc1d56 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1320,6 +1320,7 @@ namespace bgfx { freeDynamicBuffers(); m_submit->m_resolution = m_resolution; + m_resolution.m_flags &= ~BGFX_RESET_FORCE; m_submit->m_debug = m_debug; memcpy(m_submit->m_viewRemap, m_viewRemap, sizeof(m_viewRemap) ); @@ -3034,6 +3035,17 @@ again: s_ctx->setViewRect(_id, _x, _y, _width, _height); } + void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio) + { + BGFX_CHECK_MAIN_THREAD(); + BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + + uint16_t width = uint16_t(s_ctx->m_resolution.m_width); + uint16_t height = uint16_t(s_ctx->m_resolution.m_height); + getTextureSizeFromRatio(_ratio, width, height); + setViewRect(_id, _x, _y, width, height); + } + void setViewScissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { BGFX_CHECK_MAIN_THREAD(); diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 5c2834c2..066e0269 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -174,6 +174,7 @@ namespace stl #define BGFX_MAX_COMPUTE_BINDINGS 8 #define BGFX_SAMPLER_DEFAULT_FLAGS UINT32_C(0x10000000) +#define BGFX_RESET_FORCE UINT32_C(0x80000000) #define BGFX_RENDERER_DIRECT3D9_NAME "Direct3D 9" #define BGFX_RENDERER_DIRECT3D11_NAME "Direct3D 11" @@ -2036,6 +2037,7 @@ namespace bgfx , uint16_t(m_resolution.m_width) , uint16_t(m_resolution.m_height) ); + m_resolution.m_flags |= BGFX_RESET_FORCE; } } } diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 760befa7..44a75590 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -56,6 +56,7 @@ namespace bgfx { namespace d3d11 ID3D11UnorderedAccessView* m_uav[D3D11_PS_CS_UAV_REGISTER_COUNT]; ID3D11ShaderResourceView* m_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]; ID3D11SamplerState* m_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT]; + ID3D11RenderTargetView* m_rtv[BGFX_CONFIG_MAX_FRAME_BUFFERS]; uint32_t m_zero[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; float m_zerof[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; }; @@ -569,7 +570,6 @@ namespace bgfx { namespace d3d11 , m_captureTexture(NULL) , m_captureResolve(NULL) , m_wireframe(false) - , m_flags(BGFX_RESET_NONE) , m_maxAnisotropy(1) , m_currentProgram(NULL) , m_vsChanges(0) @@ -1967,12 +1967,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&color) ); D3D11_RENDER_TARGET_VIEW_DESC desc; - desc.ViewDimension = (m_flags & BGFX_RESET_MSAA_MASK) + desc.ViewDimension = (m_resolution.m_flags & BGFX_RESET_MSAA_MASK) ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D ; desc.Texture2D.MipSlice = 0; - desc.Format = (m_flags & BGFX_RESET_SRGB_BACKBUFFER) + desc.Format = (m_resolution.m_flags & BGFX_RESET_SRGB_BACKBUFFER) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM ; @@ -2036,7 +2036,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); HRESULT hr = S_OK; uint32_t syncInterval = BX_ENABLED(BX_PLATFORM_WINRT) ? 1 // sync interval of 0 is not supported on WinRT - : !!(m_flags & BGFX_RESET_VSYNC) + : !!(m_resolution.m_flags & BGFX_RESET_VSYNC) ; for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii) @@ -2129,15 +2129,16 @@ BX_PRAGMA_DIAGNOSTIC_POP(); uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY); - if ( getBufferWidth() != _resolution.m_width - || getBufferHeight() != _resolution.m_height - || m_flags != flags) + if ( getBufferWidth() != _resolution.m_width + || getBufferHeight() != _resolution.m_height + || m_resolution.m_flags != flags) { + flags &= ~BGFX_RESET_FORCE; + bool resize = true && !BX_ENABLED(BX_PLATFORM_WINRT) // can't use ResizeBuffers on Windows Phone - && (m_flags&BGFX_RESET_MSAA_MASK) == (flags&BGFX_RESET_MSAA_MASK) + && (m_resolution.m_flags&BGFX_RESET_MSAA_MASK) == (flags&BGFX_RESET_MSAA_MASK) ; - m_flags = flags; m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height); m_textVideoMem.clear(); @@ -2159,6 +2160,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { if (resize) { + m_deviceCtx->OMSetRenderTargets(1, s_zero.m_rtv, NULL); DX_CHECK(m_swapChain->ResizeBuffers(2 , getBufferWidth() , getBufferHeight() @@ -2169,13 +2171,13 @@ BX_PRAGMA_DIAGNOSTIC_POP(); else { updateMsaa(); - m_scd.SampleDesc = s_msaa[(m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; + m_scd.SampleDesc = s_msaa[(m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; DX_RELEASE(m_swapChain, 0); SwapChainDesc* scd = &m_scd; SwapChainDesc swapChainScd; - if (0 != (m_flags & BGFX_RESET_HMD) + if (0 != (m_resolution.m_flags & BGFX_RESET_HMD) && m_ovr.isInitialized() ) { swapChainScd = m_scd; @@ -2948,7 +2950,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void capturePostReset() { - if (m_flags&BGFX_RESET_CAPTURE) + if (m_resolution.m_flags&BGFX_RESET_CAPTURE) { ID3D11Texture2D* backBuffer; DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&backBuffer) ); @@ -3287,7 +3289,6 @@ BX_PRAGMA_DIAGNOSTIC_POP(); #endif // BX_PLATFORM_WINRT SwapChainDesc m_scd; - uint32_t m_flags; uint32_t m_maxAnisotropy; IndexBufferD3D11 m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 5d194bba..a8def426 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -457,7 +457,6 @@ namespace bgfx { namespace d3d12 { RendererContextD3D12() : m_wireframe(false) - , m_flags(BGFX_RESET_NONE) , m_maxAnisotropy(1) , m_fsChanges(0) , m_vsChanges(0) @@ -1121,7 +1120,7 @@ namespace bgfx { namespace d3d12 int64_t start = bx::getHPCounter(); HRESULT hr = 0; - uint32_t syncInterval = !!(m_flags & BGFX_RESET_VSYNC); + uint32_t syncInterval = !!(m_resolution.m_flags & BGFX_RESET_VSYNC); uint32_t flags = 0 == syncInterval ? DXGI_PRESENT_RESTART : 0; for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii) { @@ -1643,17 +1642,17 @@ data.NumQualityLevels = 0; m_maxAnisotropy = 1; } - if ( (uint32_t)m_scd.BufferDesc.Width != _resolution.m_width + if ( (uint32_t)m_scd.BufferDesc.Width != _resolution.m_width || (uint32_t)m_scd.BufferDesc.Height != _resolution.m_height - || m_flags != _resolution.m_flags) + || m_resolution.m_flags != _resolution.m_flags) { - bool resize = (m_flags&BGFX_RESET_MSAA_MASK) == (_resolution.m_flags&BGFX_RESET_MSAA_MASK); - m_flags = _resolution.m_flags; + bool resize = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK) == (_resolution.m_flags&BGFX_RESET_MSAA_MASK); m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height); m_textVideoMem.clear(); m_resolution = _resolution; + m_resolution.m_flags &= ~BGFX_RESET_FORCE; m_scd.BufferDesc.Width = _resolution.m_width; m_scd.BufferDesc.Height = _resolution.m_height; @@ -1678,7 +1677,7 @@ data.NumQualityLevels = 0; else { updateMsaa(); - m_scd.SampleDesc = s_msaa[(m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; + m_scd.SampleDesc = s_msaa[(m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; DX_RELEASE(m_swapChain, 0); @@ -2537,7 +2536,6 @@ data.NumQualityLevels = 0; bool m_wireframe; DXGI_SWAP_CHAIN_DESC m_scd; - uint32_t m_flags; uint32_t m_maxAnisotropy; BufferD3D12 m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index d043090c..41b4e7d1 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -281,7 +281,6 @@ namespace bgfx { namespace d3d9 , m_captureTexture(NULL) , m_captureSurface(NULL) , m_captureResolve(NULL) - , m_flags(BGFX_RESET_NONE) , m_maxAnisotropy(1) , m_initialized(false) , m_amd(false) @@ -1176,9 +1175,11 @@ namespace bgfx { namespace d3d9 if (m_params.BackBufferWidth != _resolution.m_width || m_params.BackBufferHeight != _resolution.m_height - || m_flags != flags) + || m_resolution.m_flags != flags) { - m_flags = flags; + flags &= ~BGFX_RESET_FORCE; + + m_resolution.m_flags = flags; m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height); m_textVideoMem.clear(); @@ -1195,12 +1196,12 @@ namespace bgfx { namespace d3d9 m_params.BackBufferWidth = _resolution.m_width; m_params.BackBufferHeight = _resolution.m_height; - m_params.FullScreen_RefreshRateInHz = BGFX_RESET_FULLSCREEN == (m_flags&BGFX_RESET_FULLSCREEN_MASK) ? 60 : 0; - m_params.PresentationInterval = !!(m_flags&BGFX_RESET_VSYNC) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; + m_params.FullScreen_RefreshRateInHz = BGFX_RESET_FULLSCREEN == (m_resolution.m_flags&BGFX_RESET_FULLSCREEN_MASK) ? 60 : 0; + m_params.PresentationInterval = !!(m_resolution.m_flags&BGFX_RESET_VSYNC) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; updateMsaa(); - Msaa& msaa = s_msaa[(m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; + Msaa& msaa = s_msaa[(m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; m_params.MultiSampleType = msaa.m_type; m_params.MultiSampleQuality = msaa.m_quality; @@ -1231,7 +1232,7 @@ namespace bgfx { namespace d3d9 } DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) ); - DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, 0 != (m_flags & BGFX_RESET_SRGB_BACKBUFFER) ) ); + DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, 0 != (m_resolution.m_flags & BGFX_RESET_SRGB_BACKBUFFER) ) ); } else { @@ -1514,7 +1515,7 @@ namespace bgfx { namespace d3d9 void capturePostReset() { - if (m_flags&BGFX_RESET_CAPTURE) + if (m_resolution.m_flags&BGFX_RESET_CAPTURE) { uint32_t width = m_params.BackBufferWidth; uint32_t height = m_params.BackBufferHeight; @@ -1918,7 +1919,6 @@ namespace bgfx { namespace d3d9 uint32_t m_adapter; D3DDEVTYPE m_deviceType; D3DPRESENT_PARAMETERS m_params; - uint32_t m_flags; uint32_t m_maxAnisotropy; D3DADAPTER_IDENTIFIER9 m_identifier; Resolution m_resolution; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index db3a5d28..7d8201ad 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2346,6 +2346,8 @@ namespace bgfx { namespace gl || m_resolution.m_height != _resolution.m_height || m_resolution.m_flags != flags) { + flags &= ~BGFX_RESET_FORCE; + m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height); m_textVideoMem.clear();