From f4c7f69ed7d09602f1749e5bc8173ddc9aa2616c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 23 Sep 2014 20:35:39 -0700 Subject: [PATCH] Added swap chain caps. --- examples/22-windows/windows.cpp | 21 +++++- examples/common/entry/entry_windows.cpp | 3 +- include/bgfxdefines.h | 1 + src/bgfx_p.h | 4 +- src/glcontext_eagl.h | 1 + src/glcontext_eagl.mm | 5 ++ src/glcontext_egl.cpp | 5 ++ src/glcontext_egl.h | 1 + src/glcontext_glx.cpp | 5 ++ src/glcontext_glx.h | 1 + src/glcontext_nsgl.h | 1 + src/glcontext_nsgl.mm | 5 ++ src/glcontext_ppapi.cpp | 5 ++ src/glcontext_ppapi.h | 1 + src/glcontext_wgl.cpp | 5 ++ src/glcontext_wgl.h | 1 + src/renderer_d3d11.cpp | 1 + src/renderer_d3d9.cpp | 87 +++++++++++++------------ src/renderer_gl.cpp | 16 ++++- 19 files changed, 117 insertions(+), 52 deletions(-) diff --git a/examples/22-windows/windows.cpp b/examples/22-windows/windows.cpp index d2212c4c..dbf59440 100644 --- a/examples/22-windows/windows.cpp +++ b/examples/22-windows/windows.cpp @@ -94,8 +94,6 @@ static const InputBinding s_bindings[] = int _main_(int /*_argc*/, char** /*_argv*/) { - inputAddBindings("22-windows", s_bindings); - uint32_t width = 1280; uint32_t height = 720; uint32_t debug = BGFX_DEBUG_TEXT; @@ -104,6 +102,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::init(); bgfx::reset(width, height, reset); + const bgfx::Caps* caps = bgfx::getCaps(); + bool swapChainSupported = 0 != (caps->supported & BGFX_CAPS_SWAP_CHAIN); + + if (swapChainSupported) + { + inputAddBindings("22-windows", s_bindings); + } + // Enable debug text. bgfx::setDebug(debug); @@ -234,7 +240,16 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/22-windows"); bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Rendering into multiple windows."); bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); - bgfx::dbgTextPrintf(0, 5, 0x2f, "Press 'c' to create or 'd' to destroy window."); + + if (swapChainSupported) + { + bgfx::dbgTextPrintf(0, 5, 0x2f, "Press 'c' to create or 'd' to destroy window."); + } + else + { + bool blink = uint32_t(time*3.0f)&1; + bgfx::dbgTextPrintf(0, 5, blink ? 0x1f : 0x01, " Multiple windows is not supported by `%s` renderer. ", bgfx::getRendererName(caps->rendererType) ); + } uint32_t count = 0; diff --git a/examples/common/entry/entry_windows.cpp b/examples/common/entry/entry_windows.cpp index 90fd4a82..e0133ac6 100644 --- a/examples/common/entry/entry_windows.cpp +++ b/examples/common/entry/entry_windows.cpp @@ -276,7 +276,8 @@ namespace entry ); clear(hwnd); - m_hwnd[_wparam] = hwnd; + m_hwnd[_wparam] = hwnd; + m_flags[_wparam] = msg->m_flags; WindowHandle handle = { (uint16_t)_wparam }; m_eventQueue.postSizeEvent(handle, msg->m_width, msg->m_height); m_eventQueue.postWindowEvent(handle, hwnd); diff --git a/include/bgfxdefines.h b/include/bgfxdefines.h index 6430c4ed..24ae5b73 100644 --- a/include/bgfxdefines.h +++ b/include/bgfxdefines.h @@ -275,5 +275,6 @@ #define BGFX_CAPS_BLEND_INDEPENDENT UINT64_C(0x0000000000000080) #define BGFX_CAPS_COMPUTE UINT64_C(0x0000000000000100) #define BGFX_CAPS_FRAGMENT_ORDERING UINT64_C(0x0000000000000200) +#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000400) #endif // BGFX_DEFINES_H_HEADER_GUARD diff --git a/src/bgfx_p.h b/src/bgfx_p.h index a4e42153..410658fd 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1770,9 +1770,9 @@ namespace bgfx BGFX_API_FUNC(void reset(uint32_t _width, uint32_t _height, uint32_t _flags) ) { BX_WARN(0 != _width && 0 != _height, "Frame buffer resolution width or height cannot be 0 (width %d, height %d).", _width, _height); - m_resolution.m_width = bx::uint32_max(1, _width); + m_resolution.m_width = bx::uint32_max(1, _width); m_resolution.m_height = bx::uint32_max(1, _height); - m_resolution.m_flags = _flags; + m_resolution.m_flags = _flags; memset(m_fb, 0xff, sizeof(m_fb) ); } diff --git a/src/glcontext_eagl.h b/src/glcontext_eagl.h index 32490116..91674ff9 100644 --- a/src/glcontext_eagl.h +++ b/src/glcontext_eagl.h @@ -23,6 +23,7 @@ namespace bgfx void destroy(); void resize(uint32_t _width, uint32_t _height, bool _vsync); + static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); void destorySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_eagl.mm b/src/glcontext_eagl.mm index 38804757..420a95de 100644 --- a/src/glcontext_eagl.mm +++ b/src/glcontext_eagl.mm @@ -91,6 +91,11 @@ namespace bgfx BX_TRACE("resize context"); } + bool GlContext::isSwapChainSupported() + { + return false; + } + SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/) { BX_CHECK(false, "Shouldn't be called!"); diff --git a/src/glcontext_egl.cpp b/src/glcontext_egl.cpp index eb4025a2..b8ec6d0f 100644 --- a/src/glcontext_egl.cpp +++ b/src/glcontext_egl.cpp @@ -237,6 +237,11 @@ EGL_IMPORT eglSwapInterval(m_display, _vsync ? 1 : 0); } + bool GlContext::isSwapChainSupported() + { + return false; + } + SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/) { BX_CHECK(false, "Shouldn't be called!"); diff --git a/src/glcontext_egl.h b/src/glcontext_egl.h index 2d86e266..40ddf13b 100644 --- a/src/glcontext_egl.h +++ b/src/glcontext_egl.h @@ -27,6 +27,7 @@ namespace bgfx void destroy(); void resize(uint32_t _width, uint32_t _height, bool _vsync); + static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); void destorySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_glx.cpp b/src/glcontext_glx.cpp index c132dc76..60545ce8 100644 --- a/src/glcontext_glx.cpp +++ b/src/glcontext_glx.cpp @@ -212,6 +212,11 @@ namespace bgfx } } + bool GlContext::isSwapChainSupported() + { + return false; + } + SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/) { BX_CHECK(false, "Shouldn't be called!"); diff --git a/src/glcontext_glx.h b/src/glcontext_glx.h index 1999bb24..da61d241 100644 --- a/src/glcontext_glx.h +++ b/src/glcontext_glx.h @@ -26,6 +26,7 @@ namespace bgfx void destroy(); void resize(uint32_t _width, uint32_t _height, bool _vsync); + static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); void destorySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_nsgl.h b/src/glcontext_nsgl.h index 169faa80..e33fe940 100644 --- a/src/glcontext_nsgl.h +++ b/src/glcontext_nsgl.h @@ -23,6 +23,7 @@ namespace bgfx void destroy(); void resize(uint32_t _width, uint32_t _height, bool _vsync); + static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); void destorySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_nsgl.mm b/src/glcontext_nsgl.mm index f2da698c..1cddcdbc 100644 --- a/src/glcontext_nsgl.mm +++ b/src/glcontext_nsgl.mm @@ -88,6 +88,11 @@ namespace bgfx [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; } + bool GlContext::isSwapChainSupported() + { + return false; + } + SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/) { BX_CHECK(false, "Shouldn't be called!"); diff --git a/src/glcontext_ppapi.cpp b/src/glcontext_ppapi.cpp index 37e2dfbc..74524fa9 100644 --- a/src/glcontext_ppapi.cpp +++ b/src/glcontext_ppapi.cpp @@ -158,6 +158,11 @@ namespace bgfx s_ppapi.resize(_width, _height, _vsync); } + bool GlContext::isSwapChainSupported() + { + return false; + } + SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/) { BX_CHECK(false, "Shouldn't be called!"); diff --git a/src/glcontext_ppapi.h b/src/glcontext_ppapi.h index 230d088f..53fd801a 100644 --- a/src/glcontext_ppapi.h +++ b/src/glcontext_ppapi.h @@ -27,6 +27,7 @@ namespace bgfx void destroy(); void resize(uint32_t _width, uint32_t _height, bool _vsync); + static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); void destorySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_wgl.cpp b/src/glcontext_wgl.cpp index 8ca05aac..7f015b2d 100644 --- a/src/glcontext_wgl.cpp +++ b/src/glcontext_wgl.cpp @@ -292,6 +292,11 @@ namespace bgfx } } + bool GlContext::isSwapChainSupported() + { + return true; + } + SwapChainGL* GlContext::createSwapChain(void* _nwh) { SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(_nwh); diff --git a/src/glcontext_wgl.h b/src/glcontext_wgl.h index d2d726a9..249a4126 100644 --- a/src/glcontext_wgl.h +++ b/src/glcontext_wgl.h @@ -71,6 +71,7 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z void destroy(); void resize(uint32_t _width, uint32_t _height, bool _vsync); + static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); void destorySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 10947762..15bca8dc 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -611,6 +611,7 @@ namespace bgfx | BGFX_CAPS_BLEND_INDEPENDENT | BGFX_CAPS_COMPUTE | (getIntelExtensions(m_device) ? BGFX_CAPS_FRAGMENT_ORDERING : 0) + | BGFX_CAPS_SWAP_CHAIN ); g_caps.maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; g_caps.maxFBAttachments = bx::uint32_min(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index a7ac0ce3..7ecf1ac8 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -432,58 +432,59 @@ namespace bgfx | BGFX_CAPS_TEXTURE_COMPARE_LEQUAL | BGFX_CAPS_VERTEX_ATTRIB_HALF | BGFX_CAPS_FRAGMENT_DEPTH + | BGFX_CAPS_SWAP_CHAIN ); g_caps.maxTextureSize = bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight); m_caps.NumSimultaneousRTs = bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); g_caps.maxFBAttachments = (uint8_t)m_caps.NumSimultaneousRTs; -#if BGFX_CONFIG_RENDERER_USE_EXTENSIONS - BX_TRACE("Extended formats:"); - for (uint32_t ii = 0; ii < ExtendedFormat::Count; ++ii) + if (BX_ENABLED(BGFX_CONFIG_RENDERER_USE_EXTENSIONS) ) { - ExtendedFormat& fmt = s_extendedFormats[ii]; - fmt.m_supported = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, fmt.m_usage, fmt.m_type, fmt.m_fmt) ); - const char* fourcc = (const char*)&fmt.m_fmt; - BX_TRACE("\t%2d: %c%c%c%c %s", ii, fourcc[0], fourcc[1], fourcc[2], fourcc[3], fmt.m_supported ? "supported" : ""); - BX_UNUSED(fourcc); + BX_TRACE("Extended formats:"); + for (uint32_t ii = 0; ii < ExtendedFormat::Count; ++ii) + { + ExtendedFormat& fmt = s_extendedFormats[ii]; + fmt.m_supported = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, fmt.m_usage, fmt.m_type, fmt.m_fmt) ); + const char* fourcc = (const char*)&fmt.m_fmt; + BX_TRACE("\t%2d: %c%c%c%c %s", ii, fourcc[0], fourcc[1], fourcc[2], fourcc[3], fmt.m_supported ? "supported" : ""); + BX_UNUSED(fourcc); + } + + m_instancing = false + || s_extendedFormats[ExtendedFormat::Inst].m_supported + || (m_caps.VertexShaderVersion >= D3DVS_VERSION(3, 0) ) + ; + + if (m_amd + && s_extendedFormats[ExtendedFormat::Inst].m_supported) + { // AMD only + m_device->SetRenderState(D3DRS_POINTSIZE, D3DFMT_INST); + } + + if (s_extendedFormats[ExtendedFormat::Intz].m_supported) + { + s_textureFormat[TextureFormat::D24].m_fmt = D3DFMT_INTZ; + s_textureFormat[TextureFormat::D32].m_fmt = D3DFMT_INTZ; + } + + s_textureFormat[TextureFormat::BC4].m_fmt = s_extendedFormats[ExtendedFormat::Ati1].m_supported ? D3DFMT_ATI1 : D3DFMT_UNKNOWN; + s_textureFormat[TextureFormat::BC5].m_fmt = s_extendedFormats[ExtendedFormat::Ati2].m_supported ? D3DFMT_ATI2 : D3DFMT_UNKNOWN; + + g_caps.supported |= m_instancing ? BGFX_CAPS_INSTANCING : 0; + + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) + { + g_caps.formats[ii] = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter + , m_deviceType + , adapterFormat + , 0 + , D3DRTYPE_TEXTURE + , s_textureFormat[ii].m_fmt + ) ) ? 1 : 0; + } } - m_instancing = false - || s_extendedFormats[ExtendedFormat::Inst].m_supported - || (m_caps.VertexShaderVersion >= D3DVS_VERSION(3, 0) ) - ; - - if (m_amd - && s_extendedFormats[ExtendedFormat::Inst].m_supported) - { - // AMD only - m_device->SetRenderState(D3DRS_POINTSIZE, D3DFMT_INST); - } - - if (s_extendedFormats[ExtendedFormat::Intz].m_supported) - { - s_textureFormat[TextureFormat::D24].m_fmt = D3DFMT_INTZ; - s_textureFormat[TextureFormat::D32].m_fmt = D3DFMT_INTZ; - } - - s_textureFormat[TextureFormat::BC4].m_fmt = s_extendedFormats[ExtendedFormat::Ati1].m_supported ? D3DFMT_ATI1 : D3DFMT_UNKNOWN; - s_textureFormat[TextureFormat::BC5].m_fmt = s_extendedFormats[ExtendedFormat::Ati2].m_supported ? D3DFMT_ATI2 : D3DFMT_UNKNOWN; - - g_caps.supported |= m_instancing ? BGFX_CAPS_INSTANCING : 0; - - for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) - { - g_caps.formats[ii] = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter - , m_deviceType - , adapterFormat - , 0 - , D3DRTYPE_TEXTURE - , s_textureFormat[ii].m_fmt - ) ) ? 1 : 0; - } -#endif // BGFX_CONFIG_RENDERER_USE_EXTENSIONS - uint32_t index = 1; for (const D3DFORMAT* fmt = &s_checkColorFormats[index]; *fmt != D3DFMT_UNKNOWN; ++fmt, ++index) { diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d16145bc..7e461da2 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1187,6 +1187,8 @@ namespace bgfx || s_extension[Extension::OES_vertex_array_object].m_supported ; +m_vaoSupport &= false; + if (BX_ENABLED(BX_PLATFORM_NACL) ) { m_vaoSupport &= NULL != glGenVertexArrays @@ -1240,6 +1242,11 @@ namespace bgfx : 0 ; + g_caps.supported |= GlContext::isSwapChainSupported() + ? BGFX_CAPS_SWAP_CHAIN + : 0 + ; + if (s_extension[Extension::EXT_texture_filter_anisotropic].m_supported) { GL_CHECK(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &m_maxAnisotropy) ); @@ -3871,9 +3878,12 @@ namespace bgfx uint16_t FrameBufferGL::destroy() { - GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) ); - memset(m_fbo, 0, sizeof(m_fbo) ); - m_num = 0; + if (0 != m_num) + { + GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) ); + memset(m_fbo, 0, sizeof(m_fbo) ); + m_num = 0; + } if (NULL != m_swapChain) {