diff options
Diffstat (limited to '3rdparty/bgfx/src/bgfx.cpp')
-rw-r--r-- | 3rdparty/bgfx/src/bgfx.cpp | 325 |
1 files changed, 203 insertions, 122 deletions
diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp index 55a41dfb74f..1137ee04e32 100644 --- a/3rdparty/bgfx/src/bgfx.cpp +++ b/3rdparty/bgfx/src/bgfx.cpp @@ -7,7 +7,7 @@ namespace bgfx { -#define BGFX_MAIN_THREAD_MAGIC 0x78666762 +#define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762) #if BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS # define BGFX_CHECK_MAIN_THREAD() \ @@ -19,56 +19,6 @@ namespace bgfx # define BGFX_CHECK_RENDER_THREAD() #endif // BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS -#if BX_PLATFORM_ANDROID - ::ANativeWindow* g_bgfxAndroidWindow = NULL; - - void androidSetWindow(::ANativeWindow* _window) - { - g_bgfxAndroidWindow = _window; - } -#elif BX_PLATFORM_IOS - void* g_bgfxEaglLayer = NULL; - - void iosSetEaglLayer(void* _layer) - { - g_bgfxEaglLayer = _layer; - } -#elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD - void* g_bgfxX11Display; - uint32_t g_bgfxX11Window; - void* g_bgfxGLX; - - void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx) - { - g_bgfxX11Display = _display; - g_bgfxX11Window = _window; - g_bgfxGLX = _glx; - } -#elif BX_PLATFORM_OSX - void* g_bgfxNSWindow = NULL; - void* g_bgfxNSGL = NULL; - - void osxSetNSWindow(void* _window, void* _nsgl) - { - g_bgfxNSWindow = _window; - g_bgfxNSGL = _nsgl; - } -#elif BX_PLATFORM_WINDOWS - ::HWND g_bgfxHwnd = NULL; - - void winSetHwnd(::HWND _window) - { - g_bgfxHwnd = _window; - } -#elif BX_PLATFORM_WINRT - ::IUnknown* g_bgfxCoreWindow = NULL; - - void winrtSetWindow(::IUnknown* _window) - { - g_bgfxCoreWindow = _window; - } -#endif // BX_PLATFORM_* - #if BGFX_CONFIG_USE_TINYSTL void* TinyStlAllocator::static_allocate(size_t _bytes) { @@ -252,6 +202,22 @@ namespace bgfx static BX_THREAD uint32_t s_threadIndex = 0; static Context* s_ctx = NULL; static bool s_renderFrameCalled = false; + PlatformData g_platformData; + + void setPlatformData(const PlatformData& _pd) + { + if (NULL != s_ctx) + { + BGFX_FATAL(true + && g_platformData.ndt == _pd.ndt + && g_platformData.nwh == _pd.nwh + && g_platformData.context == _pd.context + , Fatal::UnableToInitialize + , "Only backbuffer pointer can be changed after initialization!" + ); + } + memcpy(&g_platformData, &_pd, sizeof(PlatformData) ); + } void setGraphicsDebuggerPresent(bool _present) { @@ -387,7 +353,6 @@ namespace bgfx void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem) { - BGFX_CHECK_RENDER_THREAD(); struct Vertex { float m_x; @@ -796,6 +761,7 @@ namespace bgfx if (NULL == s_ctx) { s_renderFrameCalled = true; + s_threadIndex = ~BGFX_MAIN_THREAD_MAGIC; return RenderFrame::NoContext; } @@ -871,6 +837,7 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_SWAP_CHAIN), CAPS_FLAGS(BGFX_CAPS_HMD), CAPS_FLAGS(BGFX_CAPS_INDEX32), + CAPS_FLAGS(BGFX_CAPS_DRAW_INDIRECT), #undef CAPS_FLAGS }; @@ -890,18 +857,24 @@ namespace bgfx } BX_TRACE("Supported texture formats:"); - BX_TRACE("\t +------ x = supported / * = emulated"); - BX_TRACE("\t |+----- vertex format"); - BX_TRACE("\t || +-- name"); + BX_TRACE("\t +--------- x = supported / * = emulated"); + BX_TRACE("\t |+-------- sRGB format"); + BX_TRACE("\t ||+------- vertex format"); + BX_TRACE("\t |||+------ image"); + BX_TRACE("\t ||||+----- framebuffer"); + BX_TRACE("\t ||||| +-- name"); for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { if (TextureFormat::Unknown != ii && TextureFormat::UnknownDepth != ii) { uint8_t flags = g_caps.formats[ii]; - BX_TRACE("\t[%c%c] %s" - , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' ' - , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' + BX_TRACE("\t[%c%c%c%c%c] %s" + , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB ? 'l' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' ' , getName(TextureFormat::Enum(ii) ) ); BX_UNUSED(flags); @@ -946,16 +919,26 @@ namespace bgfx // When bgfx::renderFrame is called before init render thread // should not be created. BX_TRACE("Application called bgfx::renderFrame directly, not creating render thread."); + m_singleThreaded = true + && !BX_ENABLED(BX_PLATFORM_OSX || BX_PLATFORM_IOS) + && ~BGFX_MAIN_THREAD_MAGIC == s_threadIndex + ; } else { BX_TRACE("Creating rendering thread."); m_thread.init(renderThread, this); + m_singleThreaded = false; } #else BX_TRACE("Multithreaded renderer is disabled."); + m_singleThreaded = true; #endif // BGFX_CONFIG_MULTITHREADED + BX_TRACE("Running in %s-threaded mode", m_singleThreaded ? "single" : "multi"); + + s_threadIndex = BGFX_MAIN_THREAD_MAGIC; + for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii) { m_viewRemap[ii] = uint8_t(ii); @@ -1004,6 +987,10 @@ namespace bgfx g_caps.rendererType = m_renderCtx->getRendererType(); initAttribTypeSizeTable(g_caps.rendererType); + g_caps.supported |= 0 + | (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) && !m_singleThreaded ? BGFX_CAPS_RENDERER_MULTITHREADED : 0) + ; + dumpCaps(); m_textVideoMemBlitter.init(); @@ -1012,9 +999,13 @@ namespace bgfx m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); frame(); - m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); - m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); - frame(); + + if (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) + { + m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); + m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); + frame(); + } } void Context::shutdown() @@ -1060,6 +1051,8 @@ namespace bgfx m_render->destroy(); #endif // BGFX_CONFIG_MULTITHREADED + s_ctx = NULL; + m_submit->destroy(); if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) @@ -1187,7 +1180,8 @@ namespace bgfx bx::xchg(m_render, m_submit); - if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) + if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) + || m_singleThreaded) { renderFrame(); } @@ -1567,7 +1561,7 @@ again: Memory* mem; _cmdbuf.read(mem); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createIndexBuffer(handle, mem, flags); @@ -1617,7 +1611,7 @@ again: VertexDeclHandle declHandle; _cmdbuf.read(declHandle); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createVertexBuffer(handle, mem, declHandle, flags); @@ -1643,7 +1637,7 @@ again: uint32_t size; _cmdbuf.read(size); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createDynamicIndexBuffer(handle, size, flags); @@ -1687,7 +1681,7 @@ again: uint32_t size; _cmdbuf.read(size); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createDynamicVertexBuffer(handle, size, flags); @@ -2007,9 +2001,6 @@ again: BX_TRACE("Init..."); memset(&g_caps, 0, sizeof(g_caps) ); - g_caps.supported = 0 - | (BGFX_CONFIG_MULTITHREADED ? BGFX_CAPS_RENDERER_MULTITHREADED : 0) - ; g_caps.maxViews = BGFX_CONFIG_MAX_VIEWS; g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS; g_caps.maxFBAttachments = 1; @@ -2037,8 +2028,6 @@ again: s_callbackStub = BX_NEW(g_allocator, CallbackStub); } - s_threadIndex = BGFX_MAIN_THREAD_MAGIC; - s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16); s_ctx->init(_type); @@ -2052,6 +2041,7 @@ again: BGFX_CHECK_MAIN_THREAD(); Context* ctx = s_ctx; // it's going to be NULLd inside shutdown. ctx->shutdown(); + BX_CHECK(NULL == s_ctx, "bgfx is should be uninitialized here."); BX_ALIGNED_DELETE(g_allocator, ctx, 16); @@ -2188,7 +2178,7 @@ again: s_ctx->dbgTextImage(_x, _y, _width, _height, _data, _pitch); } - IndexBufferHandle createIndexBuffer(const Memory* _mem, uint8_t _flags) + IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2201,7 +2191,7 @@ again: s_ctx->destroyIndexBuffer(_handle); } - VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags) + VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2215,13 +2205,13 @@ again: s_ctx->destroyVertexBuffer(_handle); } - DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint8_t _flags) + DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); return s_ctx->createDynamicIndexBuffer(_num, _flags); } - DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint8_t _flags) + DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2241,14 +2231,14 @@ again: s_ctx->destroyDynamicIndexBuffer(_handle); } - DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint8_t _flags) + DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl."); return s_ctx->createDynamicVertexBuffer(_num, _decl, _flags); } - DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags) + DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2337,6 +2327,18 @@ again: return s_ctx->allocInstanceDataBuffer(_num, _stride); } + IndirectBufferHandle createIndirectBuffer(uint32_t _num) + { + BGFX_CHECK_MAIN_THREAD(); + return s_ctx->createIndirectBuffer(_num); + } + + void destroyIndirectBuffer(IndirectBufferHandle _handle) + { + BGFX_CHECK_MAIN_THREAD(); + s_ctx->destroyIndirectBuffer(_handle); + } + ShaderHandle createShader(const Memory* _mem) { BGFX_CHECK_MAIN_THREAD(); @@ -2436,7 +2438,7 @@ again: { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); - return s_ctx->createTexture(_mem, _flags, _skip, _info, BackbufferRatio::None); + return s_ctx->createTexture(_mem, _flags, _skip, _info, BackbufferRatio::Count); } void getTextureSizeFromRatio(BackbufferRatio::Enum _ratio, uint16_t& _width, uint16_t& _height) @@ -2482,7 +2484,7 @@ again: uint32_t magic = BGFX_CHUNK_MAGIC_TEX; bx::write(&writer, magic); - if (BackbufferRatio::None != _ratio) + if (BackbufferRatio::Count != _ratio) { _width = uint16_t(s_ctx->m_frame->m_resolution.m_width); _height = uint16_t(s_ctx->m_frame->m_resolution.m_height); @@ -2506,11 +2508,13 @@ again: TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) { - return createTexture2D(BackbufferRatio::None, _width, _height, _numMips, _format, _flags, _mem); + BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height); + return createTexture2D(BackbufferRatio::Count, _width, _height, _numMips, _format, _flags, _mem); } TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags) { + BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); return createTexture2D(_ratio, 0, 0, _numMips, _format, _flags, NULL); } @@ -2552,7 +2556,7 @@ again: tc.m_mem = _mem; bx::write(&writer, tc); - return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::None); + return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count); } TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) @@ -2592,7 +2596,7 @@ again: tc.m_mem = _mem; bx::write(&writer, tc); - return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::None); + return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count); } void destroyTexture(TextureHandle _handle) @@ -2657,6 +2661,7 @@ again: FrameBufferHandle createFrameBuffer(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint32_t _textureFlags) { + BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; TextureHandle th = createTexture2D(_ratio, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); @@ -2960,6 +2965,12 @@ again: return s_ctx->submit(_id, _depth); } + uint32_t submit(uint8_t _id, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth) + { + BGFX_CHECK_MAIN_THREAD(); + return s_ctx->submit(_id, _indirectHandle, _start, _num, _depth); + } + void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) { BGFX_CHECK_MAIN_THREAD(); @@ -2984,6 +2995,12 @@ again: s_ctx->setBuffer(_stage, _handle, _access); } + void setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access) + { + BGFX_CHECK_MAIN_THREAD(); + s_ctx->setBuffer(_stage, _handle, _access); + } + void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) { BGFX_CHECK_MAIN_THREAD(); @@ -2996,10 +3013,16 @@ again: s_ctx->setImage(_stage, _sampler, _handle, _attachment, _access, _format); } - void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) + { + BGFX_CHECK_MAIN_THREAD(); + return s_ctx->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); + } + + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { BGFX_CHECK_MAIN_THREAD(); - s_ctx->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); + return s_ctx->dispatch(_id, _handle, _indirectHandle, _start, _num, _flags); } void discard() @@ -3033,6 +3056,7 @@ BX_STATIC_ASSERT(sizeof(bgfx::TransientVertexBuffer) == sizeof(bgfx_transient_ve BX_STATIC_ASSERT(sizeof(bgfx::InstanceDataBuffer) == sizeof(bgfx_instance_data_buffer_t) ); BX_STATIC_ASSERT(sizeof(bgfx::TextureInfo) == sizeof(bgfx_texture_info_t) ); BX_STATIC_ASSERT(sizeof(bgfx::Caps) == sizeof(bgfx_caps_t) ); +BX_STATIC_ASSERT(sizeof(bgfx::PlatformData) == sizeof(bgfx_platform_data_t) ); BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer) { @@ -3191,10 +3215,10 @@ BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, u bgfx::dbgTextImage(_x, _y, _width, _height, _data, _pitch); } -BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem) +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint16_t _flags) { union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createIndexBuffer( (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createIndexBuffer( (const bgfx::Memory*)_mem, _flags); return handle.c; } @@ -3204,7 +3228,7 @@ BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle) bgfx::destroyIndexBuffer(handle.cpp); } -BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint8_t _flags) +BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle; @@ -3218,17 +3242,17 @@ BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle) bgfx::destroyVertexBuffer(handle.cpp); } -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num) +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint16_t _flags) { union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer(_num); + handle.cpp = bgfx::createDynamicIndexBuffer(_num, _flags); return handle.c; } -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem) +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags) { union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer( (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createDynamicIndexBuffer( (const bgfx::Memory*)_mem, _flags); return handle.c; } @@ -3244,7 +3268,7 @@ BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_hand bgfx::destroyDynamicIndexBuffer(handle.cpp); } -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint8_t _flags) +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle; @@ -3252,11 +3276,11 @@ BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer return handle.c; } -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl) +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicVertexBuffer( (const bgfx::Memory*)_mem, decl); + handle.cpp = bgfx::createDynamicVertexBuffer( (const bgfx::Memory*)_mem, decl, _flags); return handle.c; } @@ -3316,6 +3340,19 @@ BGFX_C_API const bgfx_instance_data_buffer_t* bgfx_alloc_instance_data_buffer(ui return (bgfx_instance_data_buffer_t*)bgfx::allocInstanceDataBuffer(_num, _stride); } +BGFX_C_API bgfx_indirect_buffer_handle_t bgfx_create_indirect_buffer(uint32_t _num) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle; + handle.cpp = bgfx::createIndirectBuffer(_num); + return handle.c; +} + +BGFX_C_API void bgfx_destroy_indirect_buffer(bgfx_indirect_buffer_handle_t _handle) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; + bgfx::destroyIndirectBuffer(handle.cpp); +} + BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem) { union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle; @@ -3344,6 +3381,14 @@ BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, return handle.c; } +BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_t _csh, bool _destroyShaders) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } csh = { _csh }; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle; + handle.cpp = bgfx::createProgram(csh.cpp, _destroyShaders); + return handle.c; +} + BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle) { union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; @@ -3371,6 +3416,13 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_ return handle.c; } +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; + handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _numMips, bgfx::TextureFormat::Enum(_format), _flags); + return handle.c; +} + BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; @@ -3416,6 +3468,13 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, return handle.c; } +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; + handle.cpp = bgfx::createFrameBuffer(bgfx::BackbufferRatio::Enum(_ratio), bgfx::TextureFormat::Enum(_format), _textureFlags); + return handle.c; +} + BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; @@ -3585,6 +3644,18 @@ BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* bgfx::setInstanceDataBuffer( (const bgfx::InstanceDataBuffer*)_idb, _num); } +BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + +BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + BGFX_C_API void bgfx_set_program(bgfx_program_handle_t _handle) { union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; @@ -3610,6 +3681,12 @@ BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth) return bgfx::submit(_id, _depth); } +BGFX_C_API uint32_t bgfx_submit_indirect(uint8_t _id, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + return bgfx::submit(_id, indirectHandle.cpp, _start, _num, _depth); +} + BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format) { union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; @@ -3624,61 +3701,65 @@ BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_ha bgfx::setImage(_stage, sampler.cpp, handle.cpp, _attachment, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) ); } -BGFX_C_API void bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) +BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access) { - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - bgfx::dispatch(_id, handle.cpp, _numX, _numY, _numZ, _flags); + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -BGFX_C_API void bgfx_discard() +BGFX_C_API void bgfx_set_compute_vertex_buffer(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access) { - bgfx::discard(); + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -BGFX_C_API void bgfx_save_screen_shot(const char* _filePath) +BGFX_C_API void bgfx_set_compute_dynamic_index_buffer(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access) { - bgfx::saveScreenShot(_filePath); + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -BGFX_C_API bgfx_render_frame_t bgfx_render_frame() +BGFX_C_API void bgfx_set_compute_dynamic_vertex_buffer(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access) { - return bgfx_render_frame_t(bgfx::renderFrame() ); + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -#if BX_PLATFORM_ANDROID -BGFX_C_API void bgfx_android_set_window(ANativeWindow* _window) +BGFX_C_API void bgfx_set_compute_indirect_buffer(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access) { - bgfx::androidSetWindow(_window); + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -#elif BX_PLATFORM_IOS -BGFX_C_API void bgfx_ios_set_eagl_layer(void* _layer) +BGFX_C_API uint32_t bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) { - bgfx::iosSetEaglLayer(_layer); + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; + return bgfx::dispatch(_id, handle.cpp, _numX, _numY, _numZ, _flags); } -#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI -BGFX_C_API void bgfx_x11_set_display_window(::Display* _display, ::Window _window) +BGFX_C_API uint32_t bgfx_dispatch_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { - bgfx::x11SetDisplayWindow(_display, _window); + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + return bgfx::dispatch(_id, handle.cpp, indirectHandle.cpp, _start, _num, _flags); } -#elif BX_PLATFORM_NACL -BGFX_C_API bool bgfx_nacl_set_interfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, bgfx_post_swap_buffers_fn _postSwapBuffers) +BGFX_C_API void bgfx_discard() { - return bgfx::naclSetInterfaces(_instance, _instInterface, _graphicsInterface, _postSwapBuffers); + bgfx::discard(); } -#elif BX_PLATFORM_OSX -BGFX_C_API void bgfx_osx_set_ns_window(void* _window) +BGFX_C_API void bgfx_save_screen_shot(const char* _filePath) { - bgfx::osxSetNSWindow(_window); + bgfx::saveScreenShot(_filePath); } -#elif BX_PLATFORM_WINDOWS -BGFX_C_API void bgfx_win_set_hwnd(HWND _window) +BGFX_C_API bgfx_render_frame_t bgfx_render_frame() { - bgfx::winSetHwnd(_window); + return bgfx_render_frame_t(bgfx::renderFrame() ); } -#endif // BX_PLATFORM_* +BGFX_C_API void bgfx_set_platform_data(bgfx_platform_data_t* _pd) +{ + bgfx::setPlatformData(*(bgfx::PlatformData*)_pd); +} |