From 7bfe51d0d8c689839814bc17739785baa3ad515e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 14 Apr 2015 20:03:05 -0700 Subject: [PATCH] Added flip after submit reset flag. --- examples/common/entry/entry.cpp | 15 +++++++++------ include/bgfx.h | 5 +++++ include/bgfxdefines.h | 1 + src/bgfx.cpp | 11 ++++++++++- src/bgfx_p.h | 4 ++++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index 4eb25a51a..e9d00e32c 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -118,12 +118,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { if (_argc > 1) { - if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv) - || setOrToggle(s_reset, "maxaniso", BGFX_RESET_MAXANISOTROPY, 1, _argc, _argv) - || setOrToggle(s_reset, "hmd", BGFX_RESET_HMD, 1, _argc, _argv) - || setOrToggle(s_reset, "hmddbg", BGFX_RESET_HMD_DEBUG, 1, _argc, _argv) - || setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER, 1, _argc, _argv) - || setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv) ) + if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv) + || setOrToggle(s_reset, "maxaniso", BGFX_RESET_MAXANISOTROPY, 1, _argc, _argv) + || setOrToggle(s_reset, "hmd", BGFX_RESET_HMD, 1, _argc, _argv) + || setOrToggle(s_reset, "hmddbg", BGFX_RESET_HMD_DEBUG, 1, _argc, _argv) + || setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER, 1, _argc, _argv) + || setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv) + || setOrToggle(s_reset, "flip", BGFX_RESET_FLIP_AFTER_SUBMIT, 1, _argc, _argv) + ) { return 0; } @@ -176,6 +178,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { entry::Key::F4, entry::Modifier::LeftCtrl, 1, cmd, "graphics hmddbg" }, { entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" }, { entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" }, + { entry::Key::F9, entry::Modifier::None, 1, cmd, "graphics flip" }, { entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" }, INPUT_BINDING_END diff --git a/include/bgfx.h b/include/bgfx.h index 2577d1d66..5db0a87f9 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -571,7 +571,12 @@ namespace bgfx /// - `BGFX_RESET_FULLSCREEN` - Not supported yet. /// - `BGFX_RESET_MSAA_X[2/4/8/16]` - Enable 2, 4, 8 or 16 x MSAA. /// - `BGFX_RESET_VSYNC` - Enable V-Sync. + /// - `BGFX_RESET_MAXANISOTROPY` - Turn on/off max anisotropy. /// - `BGFX_RESET_CAPTURE` - Begin screen capture. + /// - `BGFX_RESET_HMD` - HMD stereo rendering. + /// - `BGFX_RESET_HMD_DEBUG` - HMD stereo rendering debug mode. + /// - `BGFX_RESET_HMD_RECENTER` - HMD calibration. + /// - `BGFX_RESET_FLIP_AFTER_SUBMIT` - Flip back buffer after submit. /// /// @attention This call doesn't actually change window size, it just /// resizes back-buffer. Windowing code has to change window size. diff --git a/include/bgfxdefines.h b/include/bgfxdefines.h index 1c8a894a3..d35176219 100644 --- a/include/bgfxdefines.h +++ b/include/bgfxdefines.h @@ -303,6 +303,7 @@ #define BGFX_RESET_HMD UINT32_C(0x00000400) #define BGFX_RESET_HMD_DEBUG UINT32_C(0x00000800) #define BGFX_RESET_HMD_RECENTER UINT32_C(0x00001000) +#define BGFX_RESET_FLIP_AFTER_SUBMIT UINT32_C(0x00002000) /// #define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000000001) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 8be7d84d1..1f26f2e85 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1190,6 +1190,8 @@ namespace bgfx m_render = m_submit; m_submit = temp; + memcpy(&m_submit->m_hmd, &m_render->m_hmd, sizeof(HMD) ); + m_frames++; m_submit->start(); @@ -1205,7 +1207,8 @@ namespace bgfx bool Context::renderFrame() { - if (m_rendererInitialized) + if (m_rendererInitialized + && !m_flipAfterSubmit) { m_renderCtx->flip(); } @@ -1221,6 +1224,12 @@ namespace bgfx renderSemPost(); + if (m_rendererInitialized + && m_flipAfterSubmit) + { + m_renderCtx->flip(); + } + return m_exit; } diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 2c91b0b52..96b4756d7 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1893,6 +1893,7 @@ namespace bgfx , m_renderCtx(NULL) , m_rendererInitialized(false) , m_exit(false) + , m_flipAfterSubmit(false) { } @@ -1927,6 +1928,8 @@ namespace bgfx m_resolution.m_height = bx::uint32_max(1, _height); m_resolution.m_flags = _flags; + m_flipAfterSubmit = !!(_flags & BGFX_RESET_FLIP_AFTER_SUBMIT); + memset(m_fb, 0xff, sizeof(m_fb) ); for (uint16_t ii = 0, num = m_textureHandle.getNumHandles(); ii < num; ++ii) @@ -3527,6 +3530,7 @@ namespace bgfx bool m_rendererInitialized; bool m_exit; + bool m_flipAfterSubmit; typedef UpdateBatchT<256> TextureUpdateBatch; BX_ALIGN_DECL_CACHE_LINE(TextureUpdateBatch m_textureUpdateBatch);