mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-20 22:03:12 +01:00
Added ability to expose internal data (D3D device/GL context).
This commit is contained in:
26
src/bgfx.cpp
26
src/bgfx.cpp
@@ -277,6 +277,7 @@ namespace bgfx
|
||||
|
||||
static Context* s_ctx = NULL;
|
||||
static bool s_renderFrameCalled = false;
|
||||
InternalData g_internalData;
|
||||
PlatformData g_platformData;
|
||||
|
||||
void AllocatorStub::checkLeaks()
|
||||
@@ -292,19 +293,24 @@ namespace bgfx
|
||||
#endif // BGFX_CONFIG_MEMORY_TRACKING
|
||||
}
|
||||
|
||||
void setPlatformData(const PlatformData& _pd)
|
||||
void setPlatformData(const PlatformData& _data)
|
||||
{
|
||||
if (NULL != s_ctx)
|
||||
{
|
||||
BGFX_FATAL(true
|
||||
&& g_platformData.ndt == _pd.ndt
|
||||
&& g_platformData.nwh == _pd.nwh
|
||||
&& g_platformData.context == _pd.context
|
||||
&& g_platformData.ndt == _data.ndt
|
||||
&& g_platformData.nwh == _data.nwh
|
||||
&& g_platformData.context == _data.context
|
||||
, Fatal::UnableToInitialize
|
||||
, "Only backbuffer pointer can be changed after initialization!"
|
||||
);
|
||||
}
|
||||
memcpy(&g_platformData, &_pd, sizeof(PlatformData) );
|
||||
memcpy(&g_platformData, &_data, sizeof(PlatformData) );
|
||||
}
|
||||
|
||||
const InternalData* getInternalData()
|
||||
{
|
||||
return &g_internalData;
|
||||
}
|
||||
|
||||
void setGraphicsDebuggerPresent(bool _present)
|
||||
@@ -4364,9 +4370,14 @@ BGFX_C_API bgfx_render_frame_t bgfx_render_frame()
|
||||
return bgfx_render_frame_t(bgfx::renderFrame() );
|
||||
}
|
||||
|
||||
BGFX_C_API void bgfx_set_platform_data(bgfx_platform_data_t* _pd)
|
||||
BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t* _data)
|
||||
{
|
||||
bgfx::setPlatformData(*(bgfx::PlatformData*)_pd);
|
||||
bgfx::setPlatformData(*(const bgfx::PlatformData*)_data);
|
||||
}
|
||||
|
||||
BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data()
|
||||
{
|
||||
return (const bgfx_internal_data_t*)bgfx::getInternalData();
|
||||
}
|
||||
|
||||
BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
|
||||
@@ -4376,6 +4387,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
|
||||
#define BGFX_IMPORT \
|
||||
BGFX_IMPORT_FUNC(render_frame) \
|
||||
BGFX_IMPORT_FUNC(set_platform_data) \
|
||||
BGFX_IMPORT_FUNC(get_internal_data) \
|
||||
BGFX_IMPORT_FUNC(vertex_decl_begin) \
|
||||
BGFX_IMPORT_FUNC(vertex_decl_add) \
|
||||
BGFX_IMPORT_FUNC(vertex_decl_skip) \
|
||||
|
||||
@@ -256,6 +256,7 @@ namespace stl
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
extern InternalData g_internalData;
|
||||
extern PlatformData g_platformData;
|
||||
|
||||
#if BGFX_CONFIG_MAX_DRAW_CALLS < (64<<10)
|
||||
|
||||
@@ -314,6 +314,8 @@ EGL_IMPORT
|
||||
}
|
||||
|
||||
import();
|
||||
|
||||
g_internalData.context = m_context;
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
|
||||
@@ -211,6 +211,8 @@ namespace bgfx { namespace gl
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glXSwapBuffers( (::Display*)g_platformData.ndt, (::Window)g_platformData.nwh);
|
||||
|
||||
g_internalData.context = m_context;
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
|
||||
@@ -191,6 +191,8 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
BX_UNUSED(_width, _height);
|
||||
BX_TRACE("GlContext::create");
|
||||
|
||||
g_internalData.context = m_context;
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
|
||||
@@ -268,6 +268,8 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
|
||||
import();
|
||||
|
||||
g_internalData.context = m_context;
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
|
||||
@@ -1465,6 +1465,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
}
|
||||
|
||||
BGFX_GPU_PROFILER_BIND(m_device, m_deviceCtx);
|
||||
|
||||
g_internalData.context = m_device;
|
||||
return true;
|
||||
|
||||
error:
|
||||
|
||||
@@ -1042,6 +1042,8 @@ namespace bgfx { namespace d3d12
|
||||
m_gpuTimer.init();
|
||||
m_occlusionQuery.init();
|
||||
}
|
||||
|
||||
g_internalData.context = m_device;
|
||||
return true;
|
||||
|
||||
error:
|
||||
|
||||
@@ -752,6 +752,7 @@ namespace bgfx { namespace d3d9
|
||||
|
||||
m_initialized = true;
|
||||
|
||||
g_internalData.context = m_device;
|
||||
return true;
|
||||
|
||||
error:
|
||||
|
||||
Reference in New Issue
Block a user