From 9e00fad8b3c07056592a7b6ae2921915f7ebbf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 7 Dec 2017 21:52:52 -0800 Subject: [PATCH] WIP: Init params. --- src/bgfx.cpp | 27 ++++++++++++++++----------- src/bgfx_p.h | 16 +++++++++------- src/renderer_d3d11.cpp | 19 ++++++++++--------- src/renderer_d3d12.cpp | 21 +++++++++++---------- src/renderer_d3d9.cpp | 13 +++++++------ src/renderer_gl.cpp | 11 ++++++----- src/renderer_gnm.cpp | 3 ++- src/renderer_mtl.mm | 9 +++++---- src/renderer_noop.cpp | 3 ++- src/renderer_vk.cpp | 13 +++++++------ 10 files changed, 75 insertions(+), 60 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 7b42ec060..fc6f190c4 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1800,7 +1800,10 @@ namespace bgfx m_frameTimeLast = now; } - RendererContextI* rendererCreate(RendererType::Enum _type); + /// + RendererContextI* rendererCreate(RendererType::Enum _type, const Init& _init); + + /// void rendererDestroy(RendererContextI* _renderCtx); void Context::flip() @@ -1816,7 +1819,8 @@ namespace bgfx // Something horribly went wrong, fallback to noop renderer. rendererDestroy(m_renderCtx); - m_renderCtx = rendererCreate(RendererType::Noop); + Init init; + m_renderCtx = rendererCreate(RendererType::Noop, init); g_caps.rendererType = RendererType::Noop; } } @@ -1971,14 +1975,14 @@ namespace bgfx } } - typedef RendererContextI* (*RendererCreateFn)(); + typedef RendererContextI* (*RendererCreateFn)(const Init& _init); typedef void (*RendererDestroyFn)(); -#define BGFX_RENDERER_CONTEXT(_namespace) \ - namespace _namespace \ - { \ - extern RendererContextI* rendererCreate(); \ - extern void rendererDestroy(); \ +#define BGFX_RENDERER_CONTEXT(_namespace) \ + namespace _namespace \ + { \ + extern RendererContextI* rendererCreate(const Init& _init); \ + extern void rendererDestroy(); \ } BGFX_RENDERER_CONTEXT(noop); @@ -2060,7 +2064,7 @@ namespace bgfx return *(const int32_t*)_rhs - *(const int32_t*)_lhs; } - RendererContextI* rendererCreate(RendererType::Enum _type) + RendererContextI* rendererCreate(RendererType::Enum _type, const Init& _init) { int32_t scores[RendererType::Count]; uint32_t numScores = 0; @@ -2136,7 +2140,7 @@ namespace bgfx for (uint32_t ii = 0; ii < numScores; ++ii) { RendererType::Enum renderer = RendererType::Enum(scores[ii] & 0xff); - renderCtx = s_rendererCreator[renderer].createFn(); + renderCtx = s_rendererCreator[renderer].createFn(_init); if (NULL != renderCtx) { break; @@ -2187,7 +2191,8 @@ namespace bgfx RendererType::Enum type; _cmdbuf.read(type); - m_renderCtx = rendererCreate(type); + Init init; + m_renderCtx = rendererCreate(type, init); m_rendererInitialized = NULL != m_renderCtx; diff --git a/src/bgfx_p.h b/src/bgfx_p.h index ec1fc6880..71df832cf 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -176,9 +176,6 @@ namespace stl = std; # include #endif // BX_PLATFORM_* -#define BGFX_DEFAULT_WIDTH 1280 -#define BGFX_DEFAULT_HEIGHT 720 - #define BGFX_MAX_COMPUTE_BINDINGS 8 #define BGFX_TEXTURE_INTERNAL_DEFAULT_SAMPLER UINT32_C(0x10000000) @@ -473,7 +470,7 @@ namespace bgfx , m_height(0) , m_small(false) { - resize(); + resize(false, 1, 1); clear(); } @@ -482,7 +479,7 @@ namespace bgfx BX_FREE(g_allocator, m_mem); } - void resize(bool _small = false, uint32_t _width = BGFX_DEFAULT_WIDTH, uint32_t _height = BGFX_DEFAULT_HEIGHT) + void resize(bool _small, uint32_t _width, uint32_t _height) { uint32_t width = bx::uint32_imax(1, _width/8); uint32_t height = bx::uint32_imax(1, _height/(_small ? 8 : 16) ); @@ -1560,8 +1557,8 @@ namespace bgfx struct Resolution { Resolution() - : m_width(BGFX_DEFAULT_WIDTH) - , m_height(BGFX_DEFAULT_HEIGHT) + : m_width(1280) + , m_height(720) , m_flags(BGFX_RESET_NONE) { } @@ -1571,6 +1568,11 @@ namespace bgfx uint32_t m_flags; }; + struct Init + { + Resolution resolution; + }; + struct VertexBuffer { uint16_t m_stride; diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 3b21ce1fc..20aea8fa9 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -761,7 +761,7 @@ namespace bgfx { namespace d3d11 { } - bool init() + bool init(const Init& _init) { struct ErrorState { @@ -1260,8 +1260,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } bx::memSet(&m_scd, 0, sizeof(m_scd) ); - m_scd.Width = BGFX_DEFAULT_WIDTH; - m_scd.Height = BGFX_DEFAULT_HEIGHT; + m_scd.Width = _init.resolution.m_width; + m_scd.Height = _init.resolution.m_height; m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; m_scd.Stereo = false; m_scd.SampleDesc.Count = 1; @@ -1320,8 +1320,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } bx::memSet(&m_scd, 0, sizeof(m_scd) ); - m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; - m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; + m_scd.BufferDesc.Width = _init.resolution.m_width; + m_scd.BufferDesc.Height = _init.resolution.m_height; m_scd.BufferDesc.RefreshRate.Numerator = 60; m_scd.BufferDesc.RefreshRate.Denominator = 1; m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; @@ -1385,7 +1385,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); bx::memSet(&m_scd, 0, sizeof(m_scd) ); m_scd.SampleDesc.Count = 1; m_scd.SampleDesc.Quality = 0; - setBufferSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); + setBufferSize(_init.resolution.m_width, _init.resolution.m_height); m_backBufferColor = (ID3D11RenderTargetView*)g_platformData.backBuffer; m_backBufferDepthStencil = (ID3D11DepthStencilView*)g_platformData.backBufferDS; } @@ -3905,10 +3905,10 @@ BX_PRAGMA_DIAGNOSTIC_POP(); static RendererContextD3D11* s_renderD3D11; - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { s_renderD3D11 = BX_NEW(g_allocator, RendererContextD3D11); - if (!s_renderD3D11->init() ) + if (!s_renderD3D11->init(_init) ) { BX_DELETE(g_allocator, s_renderD3D11); s_renderD3D11 = NULL; @@ -6903,8 +6903,9 @@ BX_PRAGMA_DIAGNOSTIC_POP(); namespace bgfx { namespace d3d11 { - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); return NULL; } diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index fc2be9c7f..7b4483ca1 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -561,7 +561,7 @@ namespace bgfx { namespace d3d12 { } - bool init() + bool init(const Init& _init) { struct ErrorState { @@ -888,8 +888,8 @@ namespace bgfx { namespace d3d12 goto error; } - m_scd.Width = BGFX_DEFAULT_WIDTH; - m_scd.Height = BGFX_DEFAULT_HEIGHT; + m_scd.Width = _init.resolution.m_width; + m_scd.Height = _init.resolution.m_height; m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; m_scd.Stereo = false; m_scd.SampleDesc.Count = 1; @@ -937,8 +937,8 @@ namespace bgfx { namespace d3d12 # endif // BX_PLATFORM_WINRT } #else - m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; - m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; + m_scd.BufferDesc.Width = _init.resolution.m_width; + m_scd.BufferDesc.Height = _init.resolution.m_height; m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; m_scd.BufferDesc.Scaling = DXGI_MODE_SCALING_STRETCHED; m_scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; @@ -972,8 +972,8 @@ namespace bgfx { namespace d3d12 m_presentElapsed = 0; { - m_resolution.m_width = BGFX_DEFAULT_WIDTH; - m_resolution.m_height = BGFX_DEFAULT_HEIGHT; + m_resolution.m_width = _init.resolution.m_width; + m_resolution.m_height = _init.resolution.m_height; m_numWindows = 1; @@ -3035,10 +3035,10 @@ data.NumQualityLevels = 0; static RendererContextD3D12* s_renderD3D12; - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { s_renderD3D12 = BX_NEW(g_allocator, RendererContextD3D12); - if (!s_renderD3D12->init() ) + if (!s_renderD3D12->init(_init) ) { BX_DELETE(g_allocator, s_renderD3D12); s_renderD3D12 = NULL; @@ -5970,8 +5970,9 @@ data.NumQualityLevels = 0; namespace bgfx { namespace d3d12 { - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); return NULL; } diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 379437c2e..d46908aee 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -399,7 +399,7 @@ namespace bgfx { namespace d3d9 { } - bool init() + bool init(const Init& _init) { struct ErrorState { @@ -422,8 +422,8 @@ namespace bgfx { namespace d3d9 // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172588%28v=vs.85%29.aspx bx::memSet(&m_params, 0, sizeof(m_params) ); - m_params.BackBufferWidth = BGFX_DEFAULT_WIDTH; - m_params.BackBufferHeight = BGFX_DEFAULT_HEIGHT; + m_params.BackBufferWidth = _init.resolution.m_width; + m_params.BackBufferHeight = _init.resolution.m_height; m_params.BackBufferFormat = adapterFormat; m_params.BackBufferCount = 1; m_params.MultiSampleType = D3DMULTISAMPLE_NONE; @@ -2247,10 +2247,10 @@ namespace bgfx { namespace d3d9 static RendererContextD3D9* s_renderD3D9; - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { s_renderD3D9 = BX_NEW(g_allocator, RendererContextD3D9); - if (!s_renderD3D9->init() ) + if (!s_renderD3D9->init(_init) ) { BX_DELETE(g_allocator, s_renderD3D9); s_renderD3D9 = NULL; @@ -4494,8 +4494,9 @@ namespace bgfx { namespace d3d9 namespace bgfx { namespace d3d9 { - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); return NULL; } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index f9c50b217..f3446dee6 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1750,7 +1750,7 @@ namespace bgfx { namespace gl { } - bool init() + bool init(const Init& _init) { struct ErrorState { @@ -1768,7 +1768,7 @@ namespace bgfx { namespace gl bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); - setRenderContextSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); + setRenderContextSize(_init.resolution.m_width, _init.resolution.m_height); // Must be after context is initialized?! VRImplI* vrImpl = NULL; @@ -3943,10 +3943,10 @@ namespace bgfx { namespace gl RendererContextGL* s_renderGL; - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { s_renderGL = BX_NEW(g_allocator, RendererContextGL); - if (!s_renderGL->init() ) + if (!s_renderGL->init(_init) ) { BX_DELETE(g_allocator, s_renderGL); s_renderGL = NULL; @@ -7821,8 +7821,9 @@ namespace bgfx { namespace gl namespace bgfx { namespace gl { - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); return NULL; } diff --git a/src/renderer_gnm.cpp b/src/renderer_gnm.cpp index 5d7b10715..0420ea5f4 100644 --- a/src/renderer_gnm.cpp +++ b/src/renderer_gnm.cpp @@ -33,8 +33,9 @@ BGFX_DECLARE_EMBEDDED_SHADER(fs_clear7); namespace bgfx { namespace gnm { - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); return NULL; } diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index f5d6f0c9f..a636d968f 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -358,7 +358,7 @@ namespace bgfx { namespace mtl { } - bool init() + bool init(const Init& _init) { BX_TRACE("Init."); @@ -1847,10 +1847,10 @@ namespace bgfx { namespace mtl static RendererContextMtl* s_renderMtl; - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { s_renderMtl = BX_NEW(g_allocator, RendererContextMtl); - if (!s_renderMtl->init() ) + if (!s_renderMtl->init(_init) ) { BX_DELETE(g_allocator, s_renderMtl); s_renderMtl = NULL; @@ -4061,8 +4061,9 @@ namespace bgfx { namespace mtl namespace bgfx { namespace mtl { - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); return NULL; } diff --git a/src/renderer_noop.cpp b/src/renderer_noop.cpp index 7e7e0a7f2..23ec73d13 100644 --- a/src/renderer_noop.cpp +++ b/src/renderer_noop.cpp @@ -224,8 +224,9 @@ namespace bgfx { namespace noop static RendererContextNOOP* s_renderNOOP; - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); s_renderNOOP = BX_NEW(g_allocator, RendererContextNOOP); return s_renderNOOP; } diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index fceba6d3a..95397d943 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -703,7 +703,7 @@ VK_IMPORT_DEVICE { } - bool init() + bool init(const Init& _init) { BX_UNUSED(s_checkMsaa, s_textureAddress); @@ -1361,8 +1361,8 @@ VK_IMPORT_DEVICE m_sci.minImageCount = BX_COUNTOF(m_backBufferColorImage); m_sci.imageFormat = surfaceFormats[surfaceFormatIdx].format; m_sci.imageColorSpace = surfaceFormats[surfaceFormatIdx].colorSpace; - m_sci.imageExtent.width = 1280; - m_sci.imageExtent.height = 720; + m_sci.imageExtent.width = _init.resolution.m_width; + m_sci.imageExtent.height = _init.resolution.m_height; m_sci.imageArrayLayers = 1; m_sci.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; m_sci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; @@ -3056,10 +3056,10 @@ VK_IMPORT_DEVICE static RendererContextVK* s_renderVK; - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { s_renderVK = BX_NEW(g_allocator, RendererContextVK); - if (!s_renderVK->init() ) + if (!s_renderVK->init(_init) ) { BX_DELETE(g_allocator, s_renderVK); s_renderVK = NULL; @@ -4599,8 +4599,9 @@ BX_UNUSED(presentMin, presentMax); namespace bgfx { namespace vk { - RendererContextI* rendererCreate() + RendererContextI* rendererCreate(const Init& _init) { + BX_UNUSED(_init); return NULL; }