void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/) { if (NULL != _ptr) { BX_FREE(getAllocator(), _ptr); } }
static uint32_t topologyConvertTriListToLineList(void* _dst, uint32_t _dstSize, const IndexT* _indices, uint32_t _numIndices, bx::AllocatorI* _allocator) { IndexT* temp = (IndexT*)BX_ALLOC(_allocator, _numIndices*2*sizeof(IndexT)*2); SortT* tempSort = (SortT*)&temp[_numIndices*2]; uint32_t num = topologyConvertTriListToLineList(_dst, _dstSize, _indices, _numIndices, temp, tempSort); BX_FREE(_allocator, temp); return num; }
void shutdown() { bgfx::destroyProgram(m_particleProgram); bgfx::destroyTexture(m_particleTexture); bgfx::destroyUniform(s_texColor); bx::destroyHandleAlloc(m_allocator, m_emitterAlloc); BX_FREE(m_allocator, m_emitter); m_allocator = NULL; }
int32_t Settings::read(ReaderSeekerI* _reader, Error* _err) { int32_t size = int32_t(getRemain(_reader) ); void* data = BX_ALLOC(m_allocator, size); int32_t total = bx::read(_reader, data, size, _err); load(data, size); BX_FREE(m_allocator, data); return total; }
int32_t Settings::write(WriterI* _writer, Error* _err) const { ini_t* ini = INI_T(m_ini); int32_t size = ini_save(ini, NULL, 0); void* data = BX_ALLOC(m_allocator, size); ini_save(ini, (char*)data, size); int32_t total = bx::write(_writer, data, size-1, _err); BX_FREE(m_allocator, data); return total; }
static void memFree(void* _ptr) { BX_FREE(s_ctx.m_allocator, _ptr); }
void OcornutImguiContext::memFree(void* _ptr) { BX_FREE(s_ctx.m_allocator, _ptr); }
void Emitter::destroy() { BX_FREE(s_ctx.m_allocator, m_particles); m_particles = NULL; }
void render(uint8_t _view, const float* _mtxView, const float* _eye) { if (0 != m_num) { bgfx::TransientVertexBuffer tvb; bgfx::TransientIndexBuffer tib; const uint32_t numVertices = bgfx::getAvailTransientVertexBuffer(m_num*4, PosColorTexCoord0Vertex::ms_decl); const uint32_t numIndices = bgfx::getAvailTransientIndexBuffer(m_num*6); const uint32_t max = bx::uint32_min(numVertices/4, numIndices/6); BX_WARN(m_num == max , "Truncating transient buffer for particles to maximum available (requested %d, available %d)." , m_num , max ); if (0 < max) { bgfx::allocTransientBuffers(&tvb , PosColorTexCoord0Vertex::ms_decl , max*4 , &tib , max*6 ); PosColorTexCoord0Vertex* vertices = (PosColorTexCoord0Vertex*)tvb.data; ParticleSort* particleSort = (ParticleSort*)BX_ALLOC(m_allocator, max*sizeof(ParticleSort) ); uint32_t pos = 0; for (uint16_t ii = 0, numEmitters = m_emitterAlloc->getNumHandles(); ii < numEmitters; ++ii) { const uint16_t idx = m_emitterAlloc->getHandleAt(ii); Emitter& emitter = m_emitter[idx]; pos += emitter.render(_mtxView, _eye, pos, max, particleSort, vertices); } qsort(particleSort , max , sizeof(ParticleSort) , particleSortFn ); uint16_t* indices = (uint16_t*)tib.data; for (uint32_t ii = 0; ii < max; ++ii) { const ParticleSort& sort = particleSort[ii]; uint16_t* index = &indices[ii*6]; uint16_t idx = (uint16_t)sort.idx; index[0] = idx*4+0; index[1] = idx*4+1; index[2] = idx*4+2; index[3] = idx*4+2; index[4] = idx*4+3; index[5] = idx*4+0; } BX_FREE(m_allocator, particleSort); bgfx::setState(0 | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE | BGFX_STATE_DEPTH_TEST_LESS | BGFX_STATE_CULL_CW | BGFX_STATE_BLEND_NORMAL ); bgfx::setVertexBuffer(&tvb); bgfx::setIndexBuffer(&tib); bgfx::setTexture(0, s_texColor, m_particleTexture); bgfx::submit(_view, m_particleProgram); } } }
void rmtFree(void* /*_context*/, void* _ptr) { BX_FREE(s_allocator, _ptr); }
static void imguiFree(void* ptr) { if (gIm) BX_FREE(gIm->alloc, ptr); }
static void memFree(void* _ptr, void* _userData) { BX_UNUSED(_userData); BX_FREE(s_ctx.m_allocator, _ptr); }