From 5bb6a148768a3821ae89876ba27c2bedd0e0d2d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 17 Apr 2018 15:42:18 -0700 Subject: [PATCH] Changed bgfx::init to take init parameters as structure instead of arguments. --- examples/00-helloworld/helloworld.cpp | 9 +- examples/01-cubes/cubes.cpp | 9 +- examples/02-metaballs/metaballs.cpp | 9 +- examples/03-raymarch/raymarch.cpp | 9 +- examples/04-mesh/mesh.cpp | 9 +- examples/05-instancing/instancing.cpp | 9 +- examples/06-bump/bump.cpp | 9 +- examples/07-callback/callback.cpp | 17 +-- examples/08-update/update.cpp | 9 +- examples/09-hdr/hdr.cpp | 9 +- examples/10-font/font.cpp | 9 +- examples/11-fontsdf/fontsdf.cpp | 9 +- examples/12-lod/lod.cpp | 9 +- examples/13-stencil/stencil.cpp | 9 +- examples/14-shadowvolumes/shadowvolumes.cpp | 9 +- .../shadowmaps_simple.cpp | 9 +- examples/16-shadowmaps/shadowmaps.cpp | 9 +- examples/17-drawstress/drawstress.cpp | 9 +- examples/18-ibl/ibl.cpp | 9 +- examples/19-oit/oit.cpp | 9 +- examples/20-nanovg/nanovg.cpp | 9 +- examples/21-deferred/deferred.cpp | 9 +- examples/22-windows/windows.cpp | 9 +- examples/23-vectordisplay/main.cpp | 9 +- examples/24-nbody/nbody.cpp | 9 +- examples/25-c99/helloworld.c | 10 +- examples/26-occlusion/occlusion.cpp | 9 +- examples/27-terrain/terrain.cpp | 9 +- examples/28-wireframe/wireframe.cpp | 9 +- examples/29-debugdraw/debugdraw.cpp | 9 +- examples/30-picking/picking.cpp | 10 +- examples/31-rsm/reflectiveshadowmap.cpp | 10 +- examples/32-particles/particles.cpp | 9 +- examples/33-pom/pom.cpp | 9 +- examples/34-mvs/mvs.cpp | 9 +- examples/35-dynamic/dynamic.cpp | 9 +- examples/36-sky/sky.cpp | 9 +- .../gpudrivenrendering.cpp | 9 +- include/bgfx/bgfx.h | 88 ++++++++---- include/bgfx/c99/bgfx.h | 36 ++++- include/bgfx/c99/platform.h | 3 +- include/bgfx/defines.h | 2 +- src/bgfx.cpp | 133 ++++++++++++------ src/bgfx_p.h | 71 ++++------ src/config.h | 6 +- src/renderer_d3d11.cpp | 68 +++++---- src/renderer_d3d12.cpp | 54 ++++--- src/renderer_d3d9.cpp | 40 +++--- src/renderer_gl.cpp | 68 ++++----- src/renderer_mtl.mm | 68 ++++----- src/renderer_vk.cpp | 28 ++-- 51 files changed, 657 insertions(+), 361 deletions(-) diff --git a/examples/00-helloworld/helloworld.cpp b/examples/00-helloworld/helloworld.cpp index a9d98658e..a6487453c 100644 --- a/examples/00-helloworld/helloworld.cpp +++ b/examples/00-helloworld/helloworld.cpp @@ -29,8 +29,13 @@ public: m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/01-cubes/cubes.cpp b/examples/01-cubes/cubes.cpp index 3c8d95cd5..4c8e249ab 100644 --- a/examples/01-cubes/cubes.cpp +++ b/examples/01-cubes/cubes.cpp @@ -98,8 +98,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/02-metaballs/metaballs.cpp b/examples/02-metaballs/metaballs.cpp index 9ba66b723..0df90a553 100644 --- a/examples/02-metaballs/metaballs.cpp +++ b/examples/02-metaballs/metaballs.cpp @@ -493,8 +493,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/03-raymarch/raymarch.cpp b/examples/03-raymarch/raymarch.cpp index 4d708d313..fcb42991c 100644 --- a/examples/03-raymarch/raymarch.cpp +++ b/examples/03-raymarch/raymarch.cpp @@ -116,8 +116,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/04-mesh/mesh.cpp b/examples/04-mesh/mesh.cpp index 1ec7bbc54..d8b666d6e 100644 --- a/examples/04-mesh/mesh.cpp +++ b/examples/04-mesh/mesh.cpp @@ -27,8 +27,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/05-instancing/instancing.cpp b/examples/05-instancing/instancing.cpp index 80c1caa5d..9c698d7ac 100644 --- a/examples/05-instancing/instancing.cpp +++ b/examples/05-instancing/instancing.cpp @@ -76,8 +76,13 @@ public: m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/06-bump/bump.cpp b/examples/06-bump/bump.cpp index 7a6825dba..9b40e7786 100644 --- a/examples/06-bump/bump.cpp +++ b/examples/06-bump/bump.cpp @@ -99,8 +99,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/07-callback/callback.cpp b/examples/07-callback/callback.cpp index 9a8bea823..5ea3bd2aa 100644 --- a/examples/07-callback/callback.cpp +++ b/examples/07-callback/callback.cpp @@ -323,14 +323,15 @@ public: | BGFX_RESET_MSAA_X16 ; - bgfx::init( - args.m_type - , args.m_pciId - , 0 - , &m_callback // custom callback handler - , &m_allocator // custom allocator - ); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + init.callback = &m_callback; // custom callback handler + init.allocator = &m_allocator; // custom allocator + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index b677153b4..eaa041161 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -136,8 +136,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 287b1a165..c4e7c0c18 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -154,8 +154,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable m_debug text. bgfx::setDebug(m_debug); diff --git a/examples/10-font/font.cpp b/examples/10-font/font.cpp index 618e57c4b..23d68f6e5 100644 --- a/examples/10-font/font.cpp +++ b/examples/10-font/font.cpp @@ -68,8 +68,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/11-fontsdf/fontsdf.cpp b/examples/11-fontsdf/fontsdf.cpp index 63260d164..91f109a17 100644 --- a/examples/11-fontsdf/fontsdf.cpp +++ b/examples/11-fontsdf/fontsdf.cpp @@ -51,8 +51,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/12-lod/lod.cpp b/examples/12-lod/lod.cpp index 1e8ad9deb..f36ba3e66 100644 --- a/examples/12-lod/lod.cpp +++ b/examples/12-lod/lod.cpp @@ -43,8 +43,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/13-stencil/stencil.cpp b/examples/13-stencil/stencil.cpp index 156f034b6..5308757e8 100644 --- a/examples/13-stencil/stencil.cpp +++ b/examples/13-stencil/stencil.cpp @@ -805,8 +805,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_viewState.m_width, m_viewState.m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_viewState.m_width; + init.resolution.height = m_viewState.m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index b2ecb01ad..d19a3e88e 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -1885,8 +1885,13 @@ public: m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_viewState.m_width, m_viewState.m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_viewState.m_width; + init.resolution.height = m_viewState.m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp index 4b914c54e..f401bb832 100644 --- a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp +++ b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp @@ -75,8 +75,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index ca5b7889e..7311722f2 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -1301,8 +1301,13 @@ public: m_viewState = ViewState(uint16_t(m_width), uint16_t(m_height)); m_clearValues = ClearValues(0x00000000, 1.0f, 0); - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_viewState.m_width, m_viewState.m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_viewState.m_width; + init.resolution.height = m_viewState.m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/17-drawstress/drawstress.cpp b/examples/17-drawstress/drawstress.cpp index 5286fe9bb..a3b8c3786 100644 --- a/examples/17-drawstress/drawstress.cpp +++ b/examples/17-drawstress/drawstress.cpp @@ -126,8 +126,13 @@ public: m_deltaTimeAvgNs = 0; m_numFrames = 0; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); const bgfx::Caps* caps = bgfx::getCaps(); m_maxDim = (int32_t)bx::pow(float(caps->limits.maxDrawCalls), 1.0f/3.0f); diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index c93f56fc0..ffd4a9262 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -501,8 +501,13 @@ public: | BGFX_RESET_MSAA_X16 ; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/19-oit/oit.cpp b/examples/19-oit/oit.cpp index 034eae923..d898024ca 100644 --- a/examples/19-oit/oit.cpp +++ b/examples/19-oit/oit.cpp @@ -166,8 +166,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/20-nanovg/nanovg.cpp b/examples/20-nanovg/nanovg.cpp index 418614ab6..8d0e91ee6 100644 --- a/examples/20-nanovg/nanovg.cpp +++ b/examples/20-nanovg/nanovg.cpp @@ -1250,8 +1250,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/21-deferred/deferred.cpp b/examples/21-deferred/deferred.cpp index 526b0cfb1..43a15b5fa 100644 --- a/examples/21-deferred/deferred.cpp +++ b/examples/21-deferred/deferred.cpp @@ -207,8 +207,13 @@ public: m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable m_debug text. bgfx::setDebug(m_debug); diff --git a/examples/22-windows/windows.cpp b/examples/22-windows/windows.cpp index 70c701eed..fffd1f950 100644 --- a/examples/22-windows/windows.cpp +++ b/examples/22-windows/windows.cpp @@ -83,8 +83,13 @@ public: m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); const bgfx::Caps* caps = bgfx::getCaps(); bool swapChainSupported = 0 != (caps->supported & BGFX_CAPS_SWAP_CHAIN); diff --git a/examples/23-vectordisplay/main.cpp b/examples/23-vectordisplay/main.cpp index 3cc87d6c0..13114d7f9 100644 --- a/examples/23-vectordisplay/main.cpp +++ b/examples/23-vectordisplay/main.cpp @@ -50,8 +50,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); const bgfx::RendererType::Enum renderer = bgfx::getRendererType(); float texelHalf = bgfx::RendererType::Direct3D9 == renderer ? 0.5f : 0.0f; diff --git a/examples/24-nbody/nbody.cpp b/examples/24-nbody/nbody.cpp index d2852c08a..a9b905fa0 100644 --- a/examples/24-nbody/nbody.cpp +++ b/examples/24-nbody/nbody.cpp @@ -127,8 +127,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/25-c99/helloworld.c b/examples/25-c99/helloworld.c index d81ffdb35..eb0fc025d 100644 --- a/examples/25-c99/helloworld.c +++ b/examples/25-c99/helloworld.c @@ -22,12 +22,10 @@ int32_t _main_(int32_t _argc, char** _argv) (void)_argc; (void)_argv; - bgfx_init(BGFX_RENDERER_TYPE_COUNT - , BGFX_PCI_ID_NONE - , 0 - , NULL - , NULL - ); + bgfx_init_t init; + bgfx_init_ctor(&init); + + bgfx_init(&init); bgfx_reset(width, height, reset); // Enable debug text. diff --git a/examples/26-occlusion/occlusion.cpp b/examples/26-occlusion/occlusion.cpp index 2c8161ac4..95bb109e6 100644 --- a/examples/26-occlusion/occlusion.cpp +++ b/examples/26-occlusion/occlusion.cpp @@ -79,8 +79,13 @@ public: m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/27-terrain/terrain.cpp b/examples/27-terrain/terrain.cpp index 1044610da..63b5e3035 100644 --- a/examples/27-terrain/terrain.cpp +++ b/examples/27-terrain/terrain.cpp @@ -76,8 +76,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable m_debug text. bgfx::setDebug(m_debug); diff --git a/examples/28-wireframe/wireframe.cpp b/examples/28-wireframe/wireframe.cpp index e3d5c2451..2e49075b9 100644 --- a/examples/28-wireframe/wireframe.cpp +++ b/examples/28-wireframe/wireframe.cpp @@ -303,8 +303,13 @@ public: | BGFX_RESET_MSAA_X16 ; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable m_debug text. bgfx::setDebug(m_debug); diff --git a/examples/29-debugdraw/debugdraw.cpp b/examples/29-debugdraw/debugdraw.cpp index 70f62ce18..5e512a695 100644 --- a/examples/29-debugdraw/debugdraw.cpp +++ b/examples/29-debugdraw/debugdraw.cpp @@ -494,8 +494,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC | BGFX_RESET_MSAA_X16; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable m_debug text. bgfx::setDebug(m_debug); diff --git a/examples/30-picking/picking.cpp b/examples/30-picking/picking.cpp index c0156c082..1785d1bb7 100644 --- a/examples/30-picking/picking.cpp +++ b/examples/30-picking/picking.cpp @@ -35,9 +35,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/31-rsm/reflectiveshadowmap.cpp b/examples/31-rsm/reflectiveshadowmap.cpp index c003a7657..477a07e20 100644 --- a/examples/31-rsm/reflectiveshadowmap.cpp +++ b/examples/31-rsm/reflectiveshadowmap.cpp @@ -208,9 +208,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/32-particles/particles.cpp b/examples/32-particles/particles.cpp index 802f9e9d3..eacceff16 100644 --- a/examples/32-particles/particles.cpp +++ b/examples/32-particles/particles.cpp @@ -246,8 +246,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable m_debug text. bgfx::setDebug(m_debug); diff --git a/examples/33-pom/pom.cpp b/examples/33-pom/pom.cpp index 37bc2cd41..721ce45a5 100644 --- a/examples/33-pom/pom.cpp +++ b/examples/33-pom/pom.cpp @@ -125,8 +125,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/34-mvs/mvs.cpp b/examples/34-mvs/mvs.cpp index 4a7d915a0..b26c1fed2 100644 --- a/examples/34-mvs/mvs.cpp +++ b/examples/34-mvs/mvs.cpp @@ -121,8 +121,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/35-dynamic/dynamic.cpp b/examples/35-dynamic/dynamic.cpp index 5afec974c..68d388c30 100644 --- a/examples/35-dynamic/dynamic.cpp +++ b/examples/35-dynamic/dynamic.cpp @@ -99,8 +99,13 @@ public: m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/examples/36-sky/sky.cpp b/examples/36-sky/sky.cpp index 64ea1795c..8144c6343 100644 --- a/examples/36-sky/sky.cpp +++ b/examples/36-sky/sky.cpp @@ -423,8 +423,13 @@ namespace m_debug = BGFX_DEBUG_NONE; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable m_debug text. bgfx::setDebug(m_debug); diff --git a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp index b1382d7e7..41aa6cb1e 100644 --- a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp +++ b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp @@ -413,8 +413,13 @@ public: m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(m_width, m_height, m_reset); + bgfx::Init init; + init.type = args.m_type; + init.vendorId = args.m_pciId; + init.resolution.width = m_width; + init.resolution.height = m_height; + init.resolution.reset = m_reset; + bgfx::init(init); // Enable debug text. bgfx::setDebug(m_debug); diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index c212984f7..b1180a40c 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -557,6 +557,64 @@ namespace bgfx { } + /// + /// + /// @attention C99 equivalent is `bgfx_resolution_t`. + /// + struct Resolution + { + Resolution(); + + uint32_t width; //!< Backbuffer width. + uint32_t height; //!< Backbuffer height. + uint32_t reset; //!< Reset parameters. + }; + + /// Initialization parameters used by `bgfx::init`. + /// + /// @attention C99 equivalent is `bgfx_init_t`. + /// + struct Init + { + Init(); + + /// Select rendering backend. When set to RendererType::Count + /// a default rendering backend will be selected appropriate to the platform. + /// See: `bgfx::RendererType` + RendererType::Enum type; + + /// Vendor PCI id. If set to `BGFX_PCI_ID_NONE` it will select the first + /// device. + /// - `BGFX_PCI_ID_NONE` - Autoselect adapter. + /// - `BGFX_PCI_ID_SOFTWARE_RASTERIZER` - Software rasterizer. + /// - `BGFX_PCI_ID_AMD` - AMD adapter. + /// - `BGFX_PCI_ID_INTEL` - Intel adapter. + /// - `BGFX_PCI_ID_NVIDIA` - nVidia adapter. + uint16_t vendorId; + + /// Device id. If set to 0 it will select first device, or device with + /// matching id. + uint16_t deviceId; + + Resolution resolution; + + struct Limits + { + uint16_t maxEncoders; //!< Maximum number of encoder threads. + }; + + Limits limits; + + /// Provide application specific callback interface. + /// See: `bgfx::CallbackI` + CallbackI* callback; + + /// Custom allocator. When a custom allocator is not + /// specified, bgfx uses the CRT allocator. Bgfx assumes + /// custom allocator is thread safe. + bx::AllocatorI* allocator; + }; + /// Memory release callback. /// /// param[in] _ptr Pointer to allocated data. @@ -1748,39 +1806,13 @@ namespace bgfx /// Initialize bgfx library. /// - /// @param[in] _type Select rendering backend. When set to RendererType::Count - /// a default rendering backend will be selected appropriate to the platform. - /// See: `bgfx::RendererType` - /// - /// @param[in] _vendorId Vendor PCI id. If set to `BGFX_PCI_ID_NONE` it will select the first - /// device. - /// - `BGFX_PCI_ID_NONE` - Autoselect adapter. - /// - `BGFX_PCI_ID_SOFTWARE_RASTERIZER` - Software rasterizer. - /// - `BGFX_PCI_ID_AMD` - AMD adapter. - /// - `BGFX_PCI_ID_INTEL` - Intel adapter. - /// - `BGFX_PCI_ID_NVIDIA` - nVidia adapter. - /// - /// @param[in] _deviceId Device id. If set to 0 it will select first device, or device with - /// matching id. - /// - /// @param[in] _callback Provide application specific callback interface. - /// See: `bgfx::CallbackI` - /// - /// @param[in] _allocator Custom allocator. When a custom allocator is not - /// specified, bgfx uses the CRT allocator. Bgfx assumes - /// custom allocator is thread safe. + /// @param[in] _init Initialization parameters. See: `bgfx::Init` for more info. /// /// @returns `true` if initialization was successful. /// /// @attention C99 equivalent is `bgfx_init`. /// - bool init( - RendererType::Enum _type = RendererType::Count - , uint16_t _vendorId = BGFX_PCI_ID_NONE - , uint16_t _deviceId = 0 - , CallbackI* _callback = NULL - , bx::AllocatorI* _allocator = NULL - ); + bool init(const Init& _init); /// Shutdown bgfx library. /// diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 700130d8b..5bfb7c96a 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -590,6 +590,37 @@ typedef struct bgfx_allocator_vtbl } bgfx_allocator_vtbl_t; +/**/ +typedef struct bgfx_resolution +{ + uint32_t width; + uint32_t height; + uint32_t flags; + +} bgfx_resolution_t; + +/**/ +typedef struct bgfx_init_limits +{ + uint16_t maxEncoders; + +} bgfx_init_limits_t; + +/**/ +typedef struct bgfx_init +{ + bgfx_renderer_type_t type; + uint16_t vendorId; + uint16_t deviceId; + + bgfx_resolution_t resolution; + bgfx_init_limits_t limits; + + bgfx_callback_interface_t* callback; + bgfx_allocator_interface_t* allocator; + +} bgfx_init_t; + /**/ BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer); @@ -627,7 +658,10 @@ BGFX_C_API uint8_t bgfx_get_supported_renderers(uint8_t _max, bgfx_renderer_type BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type); /**/ -BGFX_C_API bool bgfx_init(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator); +BGFX_C_API void bgfx_init_ctor(bgfx_init_t* _init); + +/**/ +BGFX_C_API bool bgfx_init(const bgfx_init_t* _init); /**/ BGFX_C_API void bgfx_shutdown(void); diff --git a/include/bgfx/c99/platform.h b/include/bgfx/c99/platform.h index 59e6ebbfb..17f0c0623 100644 --- a/include/bgfx/c99/platform.h +++ b/include/bgfx/c99/platform.h @@ -83,7 +83,8 @@ typedef struct bgfx_interface_vtbl void (*topology_sort_tri_list)(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32); uint8_t (*get_supported_renderers)(uint8_t _max, bgfx_renderer_type_t* _enum); const char* (*get_renderer_name)(bgfx_renderer_type_t _type); - bool (*init)(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator); + void (*init_ctor)(bgfx_init_t* _init); + bool (*init)(const bgfx_init_t* _init); void (*shutdown)(); void (*reset)(uint32_t _width, uint32_t _height, uint32_t _flags); uint32_t (*frame)(bool _capture); diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index c8fdc9808..696c10671 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(64) +#define BGFX_API_VERSION UINT32_C(65) /// Color RGB/alpha/depth write. When it's not specified write will be disabled. #define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write. diff --git a/src/bgfx.cpp b/src/bgfx.cpp index a685f7674..67180883e 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1382,10 +1382,13 @@ namespace bgfx TextureFormat::RGBA8, // D3D9 doesn't support RGBA8 }; - bool Context::init(RendererType::Enum _type) + bool Context::init(const Init& _init) { BX_CHECK(!m_rendererInitialized, "Already initialized?"); + m_init = _init; + m_init.resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; + m_exit = false; m_flipped = true; m_frames = 0; @@ -1442,11 +1445,19 @@ namespace bgfx m_declRef.init(); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RendererInit); - cmdbuf.write(_type); + cmdbuf.write(_init); frameNoRenderWait(); - uint16_t idx = m_encoderHandle.alloc(); + m_encoderHandle = bx::createHandleAlloc(g_allocator, _init.limits.maxEncoders); + m_encoder = (EncoderImpl*)BX_ALLOC(g_allocator, sizeof(EncoderImpl)*_init.limits.maxEncoders); + m_encoderStats = (EncoderStats*)BX_ALLOC(g_allocator, sizeof(EncoderStats)*_init.limits.maxEncoders); + for (uint32_t ii = 0, num = _init.limits.maxEncoders; ii < num; ++ii) + { + BX_PLACEMENT_NEW(&m_encoder[ii], EncoderImpl); + } + + uint16_t idx = m_encoderHandle->alloc(); BX_CHECK(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx); m_encoder[0].begin(m_submit, 0); m_encoder0 = reinterpret_cast(&m_encoder[0]); @@ -1537,6 +1548,16 @@ namespace bgfx frame(); m_encoder[0].end(true); + m_encoderHandle->free(0); + bx::destroyHandleAlloc(g_allocator, m_encoderHandle); + m_encoderHandle = NULL; + + for (uint32_t ii = 0, num = g_caps.limits.maxEncoders; ii < num; ++ii) + { + m_encoder[ii].~EncoderImpl(); + } + BX_FREE(g_allocator, m_encoder); + BX_FREE(g_allocator, m_encoderStats); m_dynVertexBufferAllocator.compact(); m_dynIndexBufferAllocator.compact(); @@ -1697,7 +1718,7 @@ namespace bgfx { bx::MutexScope scopeLock(m_encoderApiLock); - uint16_t idx = m_encoderHandle.alloc(); + uint16_t idx = m_encoderHandle->alloc(); if (kInvalidHandle == idx) { return NULL; @@ -1761,8 +1782,8 @@ namespace bgfx void Context::swap() { freeDynamicBuffers(); - m_submit->m_resolution = m_resolution; - m_resolution.m_flags &= ~BGFX_RESET_INTERNAL_FORCE; + m_submit->m_resolution = m_init.resolution; + m_init.resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; m_submit->m_debug = m_debug; m_submit->m_perfStats.numViews = 0; @@ -1795,9 +1816,10 @@ namespace bgfx bx::memSet(m_seq, 0, sizeof(m_seq) ); - m_submit->m_textVideoMem->resize(m_render->m_textVideoMem->m_small - , m_resolution.m_width - , m_resolution.m_height + m_submit->m_textVideoMem->resize( + m_render->m_textVideoMem->m_small + , m_init.resolution.width + , m_init.resolution.height ); int64_t now = bx::getHPCounter(); @@ -1806,7 +1828,7 @@ namespace bgfx } /// - RendererContextI* rendererCreate(RendererType::Enum _type, const Init& _init); + RendererContextI* rendererCreate(const Init& _init); /// void rendererDestroy(RendererContextI* _renderCtx); @@ -1825,7 +1847,8 @@ namespace bgfx rendererDestroy(m_renderCtx); Init init; - m_renderCtx = rendererCreate(RendererType::Noop, init); + init.type = RendererType::Noop; + m_renderCtx = rendererCreate(init); g_caps.rendererType = RendererType::Noop; } } @@ -2060,7 +2083,7 @@ namespace bgfx return *(const int32_t*)_rhs - *(const int32_t*)_lhs; } - RendererContextI* rendererCreate(RendererType::Enum _type, const Init& _init) + RendererContextI* rendererCreate(const Init& _init) { int32_t scores[RendererType::Count]; uint32_t numScores = 0; @@ -2071,7 +2094,7 @@ namespace bgfx if (s_rendererCreator[ii].supported) { int32_t score = 0; - if (_type == renderer) + if (_init.type == renderer) { score += 1000; } @@ -2184,11 +2207,10 @@ namespace bgfx ); BX_CHECK(!m_rendererInitialized, "This shouldn't happen! Bad synchronization?"); - RendererType::Enum type; - _cmdbuf.read(type); - Init init; - m_renderCtx = rendererCreate(type, init); + _cmdbuf.read(init); + + m_renderCtx = rendererCreate(init); m_rendererInitialized = NULL != m_renderCtx; @@ -2741,7 +2763,24 @@ namespace bgfx return s_rendererCreator[_type].name; } - bool init(RendererType::Enum _type, uint16_t _vendorId, uint16_t _deviceId, CallbackI* _callback, bx::AllocatorI* _allocator) + Resolution::Resolution() + : width(1280) + , height(720) + , reset(BGFX_RESET_NONE) + { + } + + Init::Init() + : type(RendererType::Count) + , vendorId(BGFX_PCI_ID_NONE) + , deviceId(0) + , callback(NULL) + , allocator(NULL) + { + limits.maxEncoders = BGFX_CONFIG_DEFAULT_MAX_ENCODERS; + } + + bool init(const Init& _init) { if (NULL != s_ctx) { @@ -2760,9 +2799,9 @@ namespace bgfx ErrorState::Enum errorState = ErrorState::Default; - if (NULL != _allocator) + if (NULL != _init.allocator) { - g_allocator = _allocator; + g_allocator = _init.allocator; } else { @@ -2771,9 +2810,9 @@ namespace bgfx s_allocatorStub = BX_NEW(&allocator, AllocatorStub); } - if (NULL != _callback) + if (NULL != _init.callback) { - g_callback = _callback; + g_callback = _init.callback; } else { @@ -2783,7 +2822,7 @@ namespace bgfx if (true && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_PS4) - && RendererType::Noop != _type + && RendererType::Noop != _init.type && NULL == g_platformData.ndt && NULL == g_platformData.nwh && NULL == g_platformData.context @@ -2815,17 +2854,17 @@ namespace bgfx g_caps.limits.maxUniforms = BGFX_CONFIG_MAX_UNIFORMS; g_caps.limits.maxOcclusionQueries = BGFX_CONFIG_MAX_OCCLUSION_QUERIES; g_caps.limits.maxFBAttachments = 1; - g_caps.limits.maxEncoders = BGFX_CONFIG_MAX_ENCODERS; + g_caps.limits.maxEncoders = (0 != BGFX_CONFIG_MULTITHREADED) ? _init.limits.maxEncoders : 1; - g_caps.vendorId = _vendorId; - g_caps.deviceId = _deviceId; + g_caps.vendorId = _init.vendorId; + g_caps.deviceId = _init.deviceId; BX_TRACE("Init..."); errorState = ErrorState::ContextAllocated; s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 64); - if (s_ctx->init(_type) ) + if (s_ctx->init(_init) ) { BX_TRACE("Init complete."); return true; @@ -2864,6 +2903,19 @@ error: return false; } + bool init(RendererType::Enum _type, uint16_t _vendorId, uint16_t _deviceId, CallbackI* _callback, bx::AllocatorI* _allocator) + { + Init in; + + in.type = _type; + in.vendorId = _vendorId; + in.deviceId = _deviceId; + in.callback = _callback; + in.allocator = _allocator; + + return init(in); + } + void shutdown() { BX_TRACE("Shutdown..."); @@ -3672,8 +3724,8 @@ error: if (BackbufferRatio::Count != _ratio) { - _width = uint16_t(s_ctx->m_resolution.m_width); - _height = uint16_t(s_ctx->m_resolution.m_height); + _width = uint16_t(s_ctx->m_init.resolution.width); + _height = uint16_t(s_ctx->m_init.resolution.height); getTextureSizeFromRatio(_ratio, _width, _height); } @@ -4027,8 +4079,8 @@ error: { 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); + uint16_t width = uint16_t(s_ctx->m_init.resolution.width); + uint16_t height = uint16_t(s_ctx->m_init.resolution.height); getTextureSizeFromRatio(_ratio, width, height); setViewRect(_id, _x, _y, width, height); } @@ -4690,20 +4742,14 @@ BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type) return bgfx::getRendererName(bgfx::RendererType::Enum(_type) ); } -BGFX_C_API bool bgfx_init(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator) +BGFX_C_API void bgfx_init_ctor(bgfx_init_t* _init) { - static bgfx::CallbackC99 s_callback; - s_callback.m_interface = _callback; + BX_PLACEMENT_NEW(_init, bgfx::Init); +} - static bgfx::AllocatorC99 s_allocator; - s_allocator.m_interface = _allocator; - - return bgfx::init(bgfx::RendererType::Enum(_type) - , _vendorId - , _deviceId - , NULL == _callback ? NULL : &s_callback - , NULL == _allocator ? NULL : &s_allocator - ); +BGFX_C_API bool bgfx_init(const bgfx_init_t* _init) +{ + return bgfx::init(*reinterpret_cast(_init) ); } BGFX_C_API void bgfx_shutdown(void) @@ -5663,6 +5709,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) BGFX_IMPORT_FUNC(topology_sort_tri_list) \ BGFX_IMPORT_FUNC(get_supported_renderers) \ BGFX_IMPORT_FUNC(get_renderer_name) \ + BGFX_IMPORT_FUNC(init_ctor) \ BGFX_IMPORT_FUNC(init) \ BGFX_IMPORT_FUNC(shutdown) \ BGFX_IMPORT_FUNC(reset) \ diff --git a/src/bgfx_p.h b/src/bgfx_p.h index adc5ff546..fb444f737 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1629,25 +1629,6 @@ namespace bgfx TextureHandle m_dst; }; - struct Resolution - { - Resolution() - : m_width(1280) - , m_height(720) - , m_flags(BGFX_RESET_NONE) - { - } - - uint32_t m_width; - uint32_t m_height; - uint32_t m_flags; - }; - - struct Init - { - Resolution resolution; - }; - struct IndexBuffer { uint32_t m_size; @@ -1818,9 +1799,15 @@ namespace bgfx void create() { - for (uint32_t ii = 0; ii < BX_COUNTOF(m_uniformBuffer); ++ii) { - m_uniformBuffer[ii] = UniformBuffer::create(); + const uint32_t num = g_caps.limits.maxEncoders; + + m_uniformBuffer = (UniformBuffer**)BX_ALLOC(g_allocator, sizeof(UniformBuffer*)*num); + + for (uint32_t ii = 0; ii < num; ++ii) + { + m_uniformBuffer[ii] = UniformBuffer::create(); + } } reset(); @@ -1830,10 +1817,12 @@ namespace bgfx void destroy() { - for (uint32_t ii = 0; ii < BX_COUNTOF(m_uniformBuffer); ++ii) + for (uint32_t ii = 0, num = g_caps.limits.maxEncoders; ii < num; ++ii) { UniformBuffer::destroy(m_uniformBuffer[ii]); } + + BX_FREE(g_allocator, m_uniformBuffer); BX_DELETE(g_allocator, m_textVideoMem); } @@ -1979,7 +1968,7 @@ namespace bgfx BlitItem m_blitItem[BGFX_CONFIG_MAX_BLIT_ITEMS+1]; FrameCache m_frameCache; - UniformBuffer* m_uniformBuffer[BGFX_CONFIG_MAX_ENCODERS]; + UniformBuffer** m_uniformBuffer; uint32_t m_numRenderItems; uint16_t m_numBlitItems; @@ -2711,7 +2700,7 @@ namespace bgfx } // game thread - bool init(RendererType::Enum _type); + bool init(const Init& _init); void shutdown(); CommandBuffer& getCommandBuffer(CommandBuffer::Enum _cmd) @@ -2731,9 +2720,9 @@ namespace bgfx , _width , _height ); - m_resolution.m_width = bx::clamp(_width, 1u, g_caps.limits.maxTextureSize); - m_resolution.m_height = bx::clamp(_height, 1u, g_caps.limits.maxTextureSize); - m_resolution.m_flags = 0 + m_init.resolution.width = bx::clamp(_width, 1u, g_caps.limits.maxTextureSize); + m_init.resolution.height = bx::clamp(_height, 1u, g_caps.limits.maxTextureSize); + m_init.resolution.reset = 0 | _flags | (g_platformDataChangedSinceReset ? BGFX_RESET_INTERNAL_FORCE : 0) ; @@ -2754,11 +2743,11 @@ namespace bgfx { TextureHandle handle = { textureIdx }; resizeTexture(handle - , uint16_t(m_resolution.m_width) - , uint16_t(m_resolution.m_height) + , uint16_t(m_init.resolution.width) + , uint16_t(m_init.resolution.height) , textureRef.m_numMips ); - m_resolution.m_flags |= BGFX_RESET_INTERNAL_FORCE; + m_init.resolution.reset |= BGFX_RESET_INTERNAL_FORCE; } } } @@ -2772,7 +2761,7 @@ namespace bgfx { BGFX_MUTEX_SCOPE(m_resourceApiLock); - m_submit->m_textVideoMem->resize(_small, (uint16_t)m_resolution.m_width, (uint16_t)m_resolution.m_height); + m_submit->m_textVideoMem->resize(_small, (uint16_t)m_init.resolution.width, (uint16_t)m_init.resolution.height); m_submit->m_textVideoMem->clear(_attr); } @@ -2808,8 +2797,8 @@ namespace bgfx Stats& stats = m_submit->m_perfStats; const Resolution& resolution = m_submit->m_resolution; - stats.width = uint16_t(resolution.m_width); - stats.height = uint16_t(resolution.m_height); + stats.width = uint16_t(resolution.width); + stats.height = uint16_t(resolution.height); const TextVideoMem* tvm = m_submit->m_textVideoMem; stats.textWidth = tvm->m_width; stats.textHeight = tvm->m_height; @@ -4573,7 +4562,7 @@ namespace bgfx void encoderApiWait() { - uint16_t numEncoders = m_encoderHandle.getNumHandles(); + uint16_t numEncoders = m_encoderHandle->getNumHandles(); for (uint16_t ii = 1; ii < numEncoders; ++ii) { @@ -4582,15 +4571,15 @@ namespace bgfx for (uint16_t ii = 0; ii < numEncoders; ++ii) { - uint16_t idx = m_encoderHandle.getHandleAt(ii); + uint16_t idx = m_encoderHandle->getHandleAt(ii); m_encoderStats[ii].cpuTimeBegin = m_encoder[idx].m_cpuTimeBegin; m_encoderStats[ii].cpuTimeEnd = m_encoder[idx].m_cpuTimeEnd; } m_submit->m_perfStats.numEncoders = uint8_t(numEncoders); - m_encoderHandle.reset(); - uint16_t idx = m_encoderHandle.alloc(); + m_encoderHandle->reset(); + uint16_t idx = m_encoderHandle->alloc(); BX_CHECK(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx); } @@ -4627,11 +4616,11 @@ namespace bgfx } #endif // BGFX_CONFIG_MULTITHREADED - EncoderStats m_encoderStats[BGFX_CONFIG_MAX_ENCODERS]; + EncoderStats* m_encoderStats; Encoder* m_encoder0; - EncoderImpl m_encoder[BGFX_CONFIG_MAX_ENCODERS]; + EncoderImpl* m_encoder; uint32_t m_numEncoders; - bx::HandleAllocT m_encoderHandle; + bx::HandleAlloc* m_encoderHandle; Frame m_frame[1+(BGFX_CONFIG_MULTITHREADED ? 1 : 0)]; Frame* m_render; @@ -4762,7 +4751,7 @@ namespace bgfx uint8_t m_colorPaletteDirty; - Resolution m_resolution; + Init m_init; int64_t m_frameTimeLast; uint32_t m_frames; uint32_t m_debug; diff --git a/src/config.h b/src/config.h index 4a8d55562..26f40e485 100644 --- a/src/config.h +++ b/src/config.h @@ -327,8 +327,8 @@ BX_STATIC_ASSERT(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS m # define BGFX_CONFIG_MIP_LOD_BIAS 0 #endif // BGFX_CONFIG_MIP_LOD_BIAS -#ifndef BGFX_CONFIG_MAX_ENCODERS -# define BGFX_CONFIG_MAX_ENCODERS ( (0 != BGFX_CONFIG_MULTITHREADED) ? 8 : 1) -#endif // BGFX_CONFIG_MAX_ENCODERS +#ifndef BGFX_CONFIG_DEFAULT_MAX_ENCODERS +# define BGFX_CONFIG_DEFAULT_MAX_ENCODERS ( (0 != BGFX_CONFIG_MULTITHREADED) ? 8 : 1) +#endif // BGFX_CONFIG_DEFAULT_MAX_ENCODERS #endif // BGFX_CONFIG_H_HEADER_GUARD diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index cdfc7bcba..53f904e5e 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1002,8 +1002,8 @@ namespace bgfx { namespace d3d11 #endif // !BX_PLATFORM_WINDOWS bx::memSet(&m_scd, 0, sizeof(m_scd) ); - m_scd.width = _init.resolution.m_width; - m_scd.height = _init.resolution.m_height; + m_scd.width = _init.resolution.width; + m_scd.height = _init.resolution.height; m_scd.format = DXGI_FORMAT_R8G8B8A8_UNORM; m_scd.sampleDesc.Count = 1; m_scd.sampleDesc.Quality = 0; @@ -1038,6 +1038,14 @@ namespace bgfx { namespace d3d11 , &m_swapChain ); } + else + { + m_resolution = _init.resolution; + m_resolution.reset = _init.resolution.reset & (~BGFX_RESET_INTERNAL_FORCE); + + m_textVideoMem.resize(false, _init.resolution.width, _init.resolution.height); + m_textVideoMem.clear(); + } #if BX_PLATFORM_WINDOWS DX_CHECK(m_dxgi.m_factory->MakeWindowAssociation( (HWND)g_platformData.nwh, 0 @@ -1057,8 +1065,8 @@ namespace bgfx { namespace d3d11 bx::memSet(&m_scd, 0, sizeof(m_scd) ); m_scd.sampleDesc.Count = 1; m_scd.sampleDesc.Quality = 0; - m_scd.width = _init.resolution.m_width; - m_scd.height = _init.resolution.m_height; + m_scd.width = _init.resolution.width; + m_scd.height = _init.resolution.height; m_backBufferColor = (ID3D11RenderTargetView*)g_platformData.backBuffer; m_backBufferDepthStencil = (ID3D11DepthStencilView*)g_platformData.backBufferDS; } @@ -2093,12 +2101,12 @@ namespace bgfx { namespace d3d11 DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&color) ); D3D11_RENDER_TARGET_VIEW_DESC desc; - desc.ViewDimension = (m_resolution.m_flags & BGFX_RESET_MSAA_MASK) + desc.ViewDimension = (m_resolution.reset & BGFX_RESET_MSAA_MASK) ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D ; desc.Texture2D.MipSlice = 0; - desc.Format = (m_resolution.m_flags & BGFX_RESET_SRGB_BACKBUFFER) + desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM ; @@ -2169,7 +2177,7 @@ namespace bgfx { namespace d3d11 HRESULT hr = S_OK; uint32_t syncInterval = BX_ENABLED(!BX_PLATFORM_WINDOWS) ? 1 // sync interval of 0 is not supported on WinRT - : !!(m_resolution.m_flags & BGFX_RESET_VSYNC) + : !!(m_resolution.reset & BGFX_RESET_VSYNC) ; for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii) @@ -2256,8 +2264,8 @@ namespace bgfx { namespace d3d11 bool updateResolution(const Resolution& _resolution) { - const bool suspended = !!( _resolution.m_flags & BGFX_RESET_SUSPEND); - const bool wasSuspended = !!(m_resolution.m_flags & BGFX_RESET_SUSPEND); + const bool suspended = !!( _resolution.reset & BGFX_RESET_SUSPEND); + const bool wasSuspended = !!(m_resolution.reset & BGFX_RESET_SUSPEND); if (suspended && wasSuspended) { return true; @@ -2268,19 +2276,19 @@ namespace bgfx { namespace d3d11 m_deviceCtx->ClearState(); m_dxgi.trim(); suspend(m_device); - m_resolution.m_flags |= BGFX_RESET_SUSPEND; + m_resolution.reset |= BGFX_RESET_SUSPEND; return true; } else if (wasSuspended) { resume(m_device); - m_resolution.m_flags &= ~BGFX_RESET_SUSPEND; + m_resolution.reset &= ~BGFX_RESET_SUSPEND; } - bool recenter = !!(_resolution.m_flags & BGFX_RESET_HMD_RECENTER); + bool recenter = !!(_resolution.reset & BGFX_RESET_HMD_RECENTER); uint32_t maxAnisotropy = 1; - if (!!(_resolution.m_flags & BGFX_RESET_MAXANISOTROPY) ) + if (!!(_resolution.reset & BGFX_RESET_MAXANISOTROPY) ) { maxAnisotropy = (m_featureLevel == D3D_FEATURE_LEVEL_9_1) ? D3D_FL9_1_DEFAULT_MAX_ANISOTROPY @@ -2295,7 +2303,7 @@ namespace bgfx { namespace d3d11 } bool depthClamp = true - && !!(_resolution.m_flags & BGFX_RESET_DEPTH_CLAMP) + && !!(_resolution.reset & BGFX_RESET_DEPTH_CLAMP) && m_featureLevel > D3D_FEATURE_LEVEL_9_3 // disabling depth clamp is only supported on 10_0+ ; @@ -2312,25 +2320,25 @@ namespace bgfx { namespace d3d11 | BGFX_RESET_SUSPEND ); - if (m_resolution.m_width != _resolution.m_width - || m_resolution.m_height != _resolution.m_height - || (m_resolution.m_flags&maskFlags) != (_resolution.m_flags&maskFlags) ) + if (m_resolution.width != _resolution.width + || m_resolution.height != _resolution.height + || (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) ) { - uint32_t flags = _resolution.m_flags & (~BGFX_RESET_INTERNAL_FORCE); + uint32_t flags = _resolution.reset & (~BGFX_RESET_INTERNAL_FORCE); bool resize = true && !BX_ENABLED(BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT) // can't use ResizeBuffers on Windows Phone - && (m_resolution.m_flags&BGFX_RESET_MSAA_MASK) == (flags&BGFX_RESET_MSAA_MASK) + && (m_resolution.reset&BGFX_RESET_MSAA_MASK) == (flags&BGFX_RESET_MSAA_MASK) ; m_resolution = _resolution; - m_resolution.m_flags = flags; + m_resolution.reset = flags; - m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height); + m_textVideoMem.resize(false, _resolution.width, _resolution.height); m_textVideoMem.clear(); - m_scd.width = _resolution.m_width; - m_scd.height = _resolution.m_height; + m_scd.width = _resolution.width; + m_scd.height = _resolution.height; preReset(); @@ -2359,7 +2367,7 @@ namespace bgfx { namespace d3d11 else { updateMsaa(); - m_scd.sampleDesc = s_msaa[(m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; + m_scd.sampleDesc = s_msaa[(m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; DX_RELEASE(m_swapChain, 0); @@ -2376,7 +2384,7 @@ namespace bgfx { namespace d3d11 SwapChainDesc* scd = &m_scd; SwapChainDesc swapChainScd; - if (0 != (m_resolution.m_flags & BGFX_RESET_HMD) + if (0 != (m_resolution.reset & BGFX_RESET_HMD) && m_ovr.isInitialized() ) { swapChainScd = m_scd; @@ -3100,7 +3108,7 @@ namespace bgfx { namespace d3d11 void capturePostReset() { - if (m_resolution.m_flags&BGFX_RESET_CAPTURE) + if (m_resolution.reset&BGFX_RESET_CAPTURE) { ID3D11Texture2D* backBuffer; DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&backBuffer) ); @@ -6322,7 +6330,7 @@ namespace bgfx { namespace d3d11 if (0 < _render->m_numRenderItems) { - if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + if (0 != (m_resolution.reset & BGFX_RESET_FLUSH_AFTER_RENDER) ) { deviceCtx->Flush(); } @@ -6437,13 +6445,13 @@ namespace bgfx { namespace d3d11 char hmd[16]; bx::snprintf(hmd, BX_COUNTOF(hmd), ", [%c] HMD ", hmdEnabled ? '\xfe' : ' '); - const uint32_t msaa = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d%s, [%c] MaxAnisotropy " - , !!(m_resolution.m_flags&BGFX_RESET_VSYNC) ? '\xfe' : ' ' + , !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' ' , 0 != msaa ? '\xfe' : ' ' , 1<>BGFX_RESET_MSAA_SHIFT]; + m_scd.sampleDesc = s_msaa[(m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; DX_RELEASE(m_swapChain, 0); @@ -6164,7 +6172,7 @@ data.NumQualityLevels = 0; if (0 < _render->m_numRenderItems) { - if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + if (0 != (m_resolution.reset & BGFX_RESET_FLUSH_AFTER_RENDER) ) { // deviceCtx->Flush(); } @@ -6327,13 +6335,13 @@ data.NumQualityLevels = 0; char hmd[16]; bx::snprintf(hmd, BX_COUNTOF(hmd), ", [%c] HMD ", hmdEnabled ? '\xfe' : ' '); - const uint32_t msaa = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d%s, [%c] MaxAnisotropy " - , !!(m_resolution.m_flags&BGFX_RESET_VSYNC) ? '\xfe' : ' ' + , !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' ' , 0 != msaa ? '\xfe' : ' ' , 1<>BGFX_RESET_MSAA_SHIFT]; + Msaa& msaa = s_msaa[(m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; m_params.MultiSampleType = msaa.m_type; m_params.MultiSampleQuality = msaa.m_quality; @@ -1465,7 +1465,7 @@ namespace bgfx { namespace d3d9 } DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) ); - DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, 0 != (m_resolution.m_flags & BGFX_RESET_SRGB_BACKBUFFER) ) ); + DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, 0 != (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ) ); } else { @@ -1752,7 +1752,7 @@ namespace bgfx { namespace d3d9 void capturePostReset() { - if (m_resolution.m_flags&BGFX_RESET_CAPTURE) + if (m_resolution.reset&BGFX_RESET_CAPTURE) { uint32_t width = m_params.BackBufferWidth; uint32_t height = m_params.BackBufferHeight; @@ -4338,7 +4338,7 @@ namespace bgfx { namespace d3d9 if (0 < _render->m_numRenderItems) { - if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + if (0 != (m_resolution.reset & BGFX_RESET_FLUSH_AFTER_RENDER) ) { flush(); } @@ -4430,12 +4430,12 @@ namespace bgfx { namespace d3d9 , freq/frameTime ); - const uint32_t msaa = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d, [%c] MaxAnisotropy " - , !!(m_resolution.m_flags&BGFX_RESET_VSYNC) ? '\xfe' : ' ' + , !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' ' , 0 != msaa ? '\xfe' : ' ' , 1<captureBegin(m_resolution.m_width, m_resolution.m_height, m_resolution.m_width*4, TextureFormat::BGRA8, true); + g_callback->captureBegin(m_resolution.width, m_resolution.height, m_resolution.width*4, TextureFormat::BGRA8, true); } else { @@ -3527,8 +3527,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { GL_CHECK(glReadPixels(0 , 0 - , m_resolution.m_width - , m_resolution.m_height + , m_resolution.width + , m_resolution.height , m_readPixelsFmt , GL_UNSIGNED_BYTE , m_capture @@ -3538,11 +3538,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { bimg::imageSwizzleBgra8( m_capture - , m_resolution.m_width*4 - , m_resolution.m_width - , m_resolution.m_height + , m_resolution.width*4 + , m_resolution.width + , m_resolution.height , m_capture - , m_resolution.m_width*4 + , m_resolution.width*4 ); } @@ -6607,7 +6607,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); int32_t resolutionHeight = hmdEnabled ? _render->m_hmd.height - : _render->m_resolution.m_height + : _render->m_resolution.height ; uint32_t blendFactor = 0; @@ -6700,7 +6700,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); fbh = _render->m_view[view].m_fbh; resolutionHeight = hmdEnabled ? _render->m_hmd.height - : _render->m_resolution.m_height + : _render->m_resolution.height ; resolutionHeight = setFrameBuffer(fbh, resolutionHeight, discardFlags); } @@ -7635,7 +7635,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 < _render->m_numRenderItems) { - if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + if (0 != (m_resolution.reset & BGFX_RESET_FLUSH_AFTER_RENDER) ) { GL_CHECK(glFlush() ); } @@ -7728,13 +7728,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); char hmd[16]; bx::snprintf(hmd, BX_COUNTOF(hmd), ", [%c] HMD ", hmdEnabled ? '\xfe' : ' '); - const uint32_t msaa = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d%s, [%c] MaxAnisotropy " - , !!(m_resolution.m_flags&BGFX_RESET_VSYNC) ? '\xfe' : ' ' + , !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' ' , 0 != msaa ? '\xfe' : ' ' , 1<>BGFX_RESET_MSAA_SHIFT]; + int sampleCount = s_msaa[(_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; MTLPixelFormat prevMetalLayerPixelFormat = m_metalLayer.pixelFormat; #if BX_PLATFORM_OSX > 101300 - m_metalLayer.displaySyncEnabled = 0 != (_resolution.m_flags&BGFX_RESET_VSYNC); + m_metalLayer.displaySyncEnabled = 0 != (_resolution.reset&BGFX_RESET_VSYNC); #endif // BX_PLATFORM_OSX > 101300 - m_metalLayer.drawableSize = CGSizeMake(_resolution.m_width, _resolution.m_height); - m_metalLayer.pixelFormat = (m_resolution.m_flags & BGFX_RESET_SRGB_BACKBUFFER) + m_metalLayer.drawableSize = CGSizeMake(_resolution.width, _resolution.height); + m_metalLayer.pixelFormat = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? MTLPixelFormatBGRA8Unorm_sRGB : MTLPixelFormatBGRA8Unorm ; m_resolution = _resolution; - m_resolution.m_flags &= ~BGFX_RESET_INTERNAL_FORCE; + m_resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; m_textureDescriptor.textureType = sampleCount > 1 ? MTLTextureType2DMultisample : MTLTextureType2D; @@ -1172,8 +1172,8 @@ namespace bgfx { namespace mtl m_textureDescriptor.pixelFormat = MTLPixelFormatDepth32Float; } - m_textureDescriptor.width = _resolution.m_width; - m_textureDescriptor.height = _resolution.m_height; + m_textureDescriptor.width = _resolution.width; + m_textureDescriptor.height = _resolution.height; m_textureDescriptor.depth = 1; m_textureDescriptor.mipmapLevelCount = 1; m_textureDescriptor.sampleCount = sampleCount; @@ -1236,7 +1236,7 @@ namespace bgfx { namespace mtl updateCapture(); - m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height); + m_textVideoMem.resize(false, _resolution.width, _resolution.height); m_textVideoMem.clear(); if (prevMetalLayerPixelFormat != m_metalLayer.pixelFormat) @@ -1254,11 +1254,11 @@ namespace bgfx { namespace mtl void updateCapture() { - if (m_resolution.m_flags&BGFX_RESET_CAPTURE) + if (m_resolution.reset&BGFX_RESET_CAPTURE) { - m_captureSize = m_resolution.m_width*m_resolution.m_height*4; + m_captureSize = m_resolution.width*m_resolution.height*4; m_capture = BX_REALLOC(g_allocator, m_capture, m_captureSize); - g_callback->captureBegin(m_resolution.m_width, m_resolution.m_height, m_resolution.m_width*4, TextureFormat::BGRA8, false); + g_callback->captureBegin(m_resolution.width, m_resolution.height, m_resolution.width*4, TextureFormat::BGRA8, false); } else { @@ -1280,9 +1280,9 @@ namespace bgfx { namespace mtl m_cmd.kick(false, true); m_commandBuffer = 0; - MTLRegion region = { { 0, 0, 0 }, { m_resolution.m_width, m_resolution.m_height, 1 } }; + MTLRegion region = { { 0, 0, 0 }, { m_resolution.width, m_resolution.height, 1 } }; - m_screenshotTarget.getBytes(m_capture, 4*m_resolution.m_width, 0, region, 0, 0); + m_screenshotTarget.getBytes(m_capture, 4*m_resolution.width, 0, region, 0, 0); m_commandBuffer = m_cmd.alloc(); @@ -1290,11 +1290,11 @@ namespace bgfx { namespace mtl { bimg::imageSwizzleBgra8( m_capture - , m_resolution.m_width*4 - , m_resolution.m_width - , m_resolution.m_height + , m_resolution.width*4 + , m_resolution.width + , m_resolution.height , m_capture - , m_resolution.m_width*4 + , m_resolution.width*4 ); } @@ -1458,8 +1458,8 @@ namespace bgfx { namespace mtl } else { - width = m_resolution.m_width; - height = m_resolution.m_height; + width = m_resolution.width; + height = m_resolution.height; } @@ -3183,8 +3183,8 @@ namespace bgfx { namespace mtl { if (m_screenshotTarget) { - if (m_screenshotTarget.width() != m_resolution.m_width - || m_screenshotTarget.height() != m_resolution.m_height) + if (m_screenshotTarget.width() != m_resolution.width + || m_screenshotTarget.height() != m_resolution.height) { MTL_RELEASE(m_screenshotTarget); } @@ -3194,8 +3194,8 @@ namespace bgfx { namespace mtl { m_textureDescriptor.textureType = MTLTextureType2D; m_textureDescriptor.pixelFormat = m_metalLayer.pixelFormat; - m_textureDescriptor.width = m_resolution.m_width; - m_textureDescriptor.height = m_resolution.m_height; + m_textureDescriptor.width = m_resolution.width; + m_textureDescriptor.height = m_resolution.height; m_textureDescriptor.depth = 1; m_textureDescriptor.mipmapLevelCount = 1; m_textureDescriptor.sampleCount = 1; @@ -3378,8 +3378,8 @@ namespace bgfx { namespace mtl fbh = _render->m_view[view].m_fbh; - uint32_t width = m_resolution.m_width; - uint32_t height = m_resolution.m_height; + uint32_t width = m_resolution.width; + uint32_t height = m_resolution.height; if (isValid(fbh) ) { @@ -4011,12 +4011,12 @@ namespace bgfx { namespace mtl , freq/frameTime ); - const uint32_t msaa = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d, [%c] MaxAnisotropy " - , !!(m_resolution.m_flags&BGFX_RESET_VSYNC) ? '\xfe' : ' ' + , !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' ' , 0 != msaa ? '\xfe' : ' ' , 1<>BGFX_RESET_MSAA_SHIFT; + const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d%s, [%c] MaxAnisotropy " - , !!(m_resolution.m_flags&BGFX_RESET_VSYNC) ? '\xfe' : ' ' + , !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' ' , 0 != msaa ? '\xfe' : ' ' , 1<