void init(uint16_t _maxEmitters, bx::AllocatorI* _allocator) { m_allocator = _allocator; if (NULL == _allocator) { static bx::DefaultAllocator allocator; m_allocator = &allocator; } m_emitterAlloc = bx::createHandleAlloc(m_allocator, _maxEmitters); m_emitter = (Emitter*)BX_ALLOC(m_allocator, sizeof(Emitter)*_maxEmitters); PosColorTexCoord0Vertex::init(); m_num = 0; s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1); m_texture = bgfx::createTexture2D( SPRITE_TEXTURE_SIZE , SPRITE_TEXTURE_SIZE , false , 1 , bgfx::TextureFormat::BGRA8 ); bgfx::RendererType::Enum type = bgfx::getRendererType(); m_particleProgram = bgfx::createProgram( bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_particle") , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_particle") , true ); }
void init(uint16_t _maxEmitters, bx::AllocatorI* _allocator) { m_allocator = _allocator; #if BX_CONFIG_ALLOCATOR_CRT if (NULL == _allocator) { static bx::CrtAllocator allocator; m_allocator = &allocator; } #endif // BX_CONFIG_ALLOCATOR_CRT m_emitterAlloc = bx::createHandleAlloc(m_allocator, _maxEmitters); m_emitter = (Emitter*)BX_ALLOC(m_allocator, sizeof(Emitter)*_maxEmitters); PosColorTexCoord0Vertex::init(); m_num = 0; s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1); m_particleTexture = loadTexture("textures/particle.ktx"); bgfx::RendererType::Enum type = bgfx::getRendererType(); m_particleProgram = bgfx::createProgram( bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_particle") , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_particle") , true ); }
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 Emitter::create(EmitterShape::Enum _shape, EmitterDirection::Enum _direction, uint32_t _maxParticles) { reset(); m_shape = _shape; m_direction = _direction; m_max = _maxParticles; m_particles = (Particle*)BX_ALLOC(s_ctx.m_allocator, m_max*sizeof(Particle) ); }
NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, termite::GfxDriverApi* driver, termite::GfxApi_v0* gfxApi, bx::AllocatorI* _allocator) { if (NULL == _allocator) { #if BX_CONFIG_ALLOCATOR_CRT static bx::CrtAllocator allocator; _allocator = &allocator; #else BX_CHECK(false, "No allocator has been passed to nvgCreate(). Either specify a bx::AllocatorI instance or enable BX_CONFIG_ALLOCATOR_CRT directive."); return NULL; #endif // BX_CONFIG_ALLOCATOR_CRT } struct NVGparams params; struct NVGcontext* ctx = NULL; struct GLNVGcontext* gl = (struct GLNVGcontext*)BX_ALLOC(_allocator, sizeof(struct GLNVGcontext) ); if (gl == NULL) goto error; memset(gl, 0, sizeof(struct GLNVGcontext) ); gl->driver = driver; gl->gfxApi = gfxApi; memset(¶ms, 0, sizeof(params) ); params.renderCreate = nvgRenderCreate; params.renderCreateTexture = nvgRenderCreateTexture; params.renderDeleteTexture = nvgRenderDeleteTexture; params.renderUpdateTexture = nvgRenderUpdateTexture; params.renderGetTextureSize = nvgRenderGetTextureSize; params.renderViewport = nvgRenderViewport; params.renderFlush = nvgRenderFlush; params.renderFill = nvgRenderFill; params.renderStroke = nvgRenderStroke; params.renderTriangles = nvgRenderTriangles; params.renderDelete = nvgRenderDelete; params.userPtr = gl; params.edgeAntiAlias = edgeaa; gl->m_allocator = _allocator; gl->edgeAntiAlias = edgeaa; gl->m_viewId = uint8_t(_viewId); ctx = nvgCreateInternal(¶ms); if (ctx == NULL) goto error; return ctx; error: // 'gl' is freed by nvgDeleteInternal. if (ctx != NULL) { nvgDeleteInternal(ctx); } return 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; }
NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator) { if (NULL == _allocator) { static bx::DefaultAllocator allocator; _allocator = &allocator; } struct NVGparams params; struct NVGcontext* ctx = NULL; struct GLNVGcontext* gl = (struct GLNVGcontext*)BX_ALLOC(_allocator, sizeof(struct GLNVGcontext) ); if (gl == NULL) { goto error; } bx::memSet(gl, 0, sizeof(struct GLNVGcontext) ); bx::memSet(¶ms, 0, sizeof(params) ); params.renderCreate = nvgRenderCreate; params.renderCreateTexture = nvgRenderCreateTexture; params.renderDeleteTexture = nvgRenderDeleteTexture; params.renderUpdateTexture = nvgRenderUpdateTexture; params.renderGetTextureSize = nvgRenderGetTextureSize; params.renderViewport = nvgRenderViewport; params.renderFlush = nvgRenderFlush; params.renderFill = nvgRenderFill; params.renderStroke = nvgRenderStroke; params.renderTriangles = nvgRenderTriangles; params.renderDelete = nvgRenderDelete; params.userPtr = gl; params.edgeAntiAlias = _edgeaa; gl->allocator = _allocator; gl->edgeAntiAlias = _edgeaa; gl->viewId = _viewId; ctx = nvgCreateInternal(¶ms); if (ctx == NULL) goto error; return ctx; error: // 'gl' is freed by nvgDeleteInternal. if (ctx != NULL) { nvgDeleteInternal(ctx); } return NULL; }
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* memAlloc(size_t _size) { return BX_ALLOC(s_ctx.m_allocator, _size); }
void* OcornutImguiContext::memAlloc(size_t _size) { return BX_ALLOC(s_ctx.m_allocator, _size); }
void* TinyStlAllocator::static_allocate(size_t _bytes) { return BX_ALLOC(getAllocator(), _bytes); }
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* rmtMalloc(void* /*_context*/, rmtU32 _size) { return BX_ALLOC(s_allocator, _size); }
static void* imguiAlloc(size_t size) { return BX_ALLOC(gIm->alloc, size); }
static void* memAlloc(size_t _size, void* _userData) { BX_UNUSED(_userData); return BX_ALLOC(s_ctx.m_allocator, _size); }