mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Added headless validation for bgfx::init and bgfx::reset.
This commit is contained in:
38
src/bgfx.cpp
38
src/bgfx.cpp
@@ -1889,27 +1889,37 @@ namespace bgfx
|
||||
|
||||
bool Context::init(const Init& _init)
|
||||
{
|
||||
BX_ASSERT(!m_rendererInitialized, "Already initialized?");
|
||||
if (m_rendererInitialized)
|
||||
{
|
||||
BX_TRACE("Already initialized!");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_headless = true
|
||||
&& RendererType::Noop != _init.type
|
||||
&& NULL == _init.platformData.ndt
|
||||
&& NULL == _init.platformData.nwh
|
||||
&& NULL == _init.platformData.context
|
||||
&& NULL == _init.platformData.backBuffer
|
||||
&& NULL == _init.platformData.backBufferDS
|
||||
;
|
||||
BX_WARN(!m_headless, "bgfx platform data like window handle or backbuffer is not set, creating headless device.");
|
||||
|
||||
if (m_headless
|
||||
&& 0 != _init.resolution.width
|
||||
&& 0 != _init.resolution.height)
|
||||
{
|
||||
BX_TRACE("Initializing headless mode, resolution of non-existing backbuffer can't be larger than 0x0!");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_init = _init;
|
||||
m_init.resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE;
|
||||
m_init.resolution.numBackBuffers = bx::clamp<uint8_t>(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS);
|
||||
m_init.resolution.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY);
|
||||
m_init.resolution.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY);
|
||||
m_init.resolution.debugTextScale = bx::clamp<uint8_t>(_init.resolution.debugTextScale, 1, BGFX_CONFIG_DEBUG_TEXT_MAX_SCALE);
|
||||
dump(m_init.resolution);
|
||||
|
||||
if (true
|
||||
&& RendererType::Noop != m_init.type
|
||||
&& NULL == m_init.platformData.ndt
|
||||
&& NULL == m_init.platformData.nwh
|
||||
&& NULL == m_init.platformData.context
|
||||
&& NULL == m_init.platformData.backBuffer
|
||||
&& NULL == m_init.platformData.backBufferDS
|
||||
)
|
||||
{
|
||||
BX_TRACE("bgfx platform data like window handle or backbuffer is not set, creating headless device.");
|
||||
}
|
||||
|
||||
bx::memCopy(&g_platformData, &m_init.platformData, sizeof(PlatformData) );
|
||||
|
||||
m_exit = false;
|
||||
|
||||
@@ -3130,6 +3130,7 @@ namespace bgfx
|
||||
, m_rtMemoryUsed(0)
|
||||
, m_textureMemoryUsed(0)
|
||||
, m_renderCtx(NULL)
|
||||
, m_headless(false)
|
||||
, m_rendererInitialized(false)
|
||||
, m_exit(false)
|
||||
, m_flipAfterRender(false)
|
||||
@@ -3168,6 +3169,13 @@ namespace bgfx
|
||||
{
|
||||
BGFX_MUTEX_SCOPE(m_resourceApiLock);
|
||||
|
||||
BX_ASSERT(false
|
||||
|| !m_headless
|
||||
|| 0 == _width
|
||||
|| 0 == _height
|
||||
, "Running in headless mode, resolution of non-existing backbuffer can't be larger than 0x0!"
|
||||
);
|
||||
|
||||
const TextureFormat::Enum format = TextureFormat::Count != _format ? _format : m_init.resolution.format;
|
||||
|
||||
if (!g_platformDataChangedSinceReset
|
||||
@@ -5363,6 +5371,7 @@ namespace bgfx
|
||||
|
||||
RendererContextI* m_renderCtx;
|
||||
|
||||
bool m_headless;
|
||||
bool m_rendererInitialized;
|
||||
bool m_exit;
|
||||
bool m_flipAfterRender;
|
||||
|
||||
@@ -300,8 +300,8 @@ EGL_IMPORT
|
||||
{
|
||||
EGLint pbAttribs[] =
|
||||
{
|
||||
EGL_WIDTH, EGLint(_width),
|
||||
EGL_HEIGHT, EGLint(_height),
|
||||
EGL_WIDTH, EGLint(1),
|
||||
EGL_HEIGHT, EGLint(1),
|
||||
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
@@ -4138,29 +4138,25 @@ namespace bgfx { namespace gl
|
||||
|
||||
void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _flags = 0)
|
||||
{
|
||||
if (_width != 0
|
||||
|| _height != 0)
|
||||
if (!m_glctx.isValid() )
|
||||
{
|
||||
if (!m_glctx.isValid() )
|
||||
{
|
||||
m_glctx.create(_width, _height, _flags);
|
||||
m_glctx.create(_width, _height, _flags);
|
||||
|
||||
#if BX_PLATFORM_IOS
|
||||
// iOS: need to figure out how to deal with FBO created by context.
|
||||
m_backBufferFbo = m_msaaBackBufferFbo = m_glctx.getFbo();
|
||||
// iOS: need to figure out how to deal with FBO created by context.
|
||||
m_backBufferFbo = m_msaaBackBufferFbo = m_glctx.getFbo();
|
||||
#endif // BX_PLATFORM_IOS
|
||||
}
|
||||
else
|
||||
{
|
||||
destroyMsaaFbo();
|
||||
}
|
||||
else
|
||||
{
|
||||
destroyMsaaFbo();
|
||||
|
||||
m_glctx.resize(_width, _height, _flags);
|
||||
m_glctx.resize(_width, _height, _flags);
|
||||
|
||||
uint32_t msaa = (_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
|
||||
msaa = bx::uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
|
||||
uint32_t msaa = (_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
|
||||
msaa = bx::uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
|
||||
|
||||
createMsaaFbo(_width, _height, msaa);
|
||||
}
|
||||
createMsaaFbo(_width, _height, msaa);
|
||||
}
|
||||
|
||||
m_flip = true;
|
||||
|
||||
Reference in New Issue
Block a user