MCPcopy Create free account
hub / github.com/axmolengine/axmol / resizeCapacity

Method resizeCapacity

core/renderer/TextureAtlas.cpp:341–420  ·  view source on GitHub ↗

TextureAtlas - Resize

Source from the content-addressed store, hash-verified

339
340// TextureAtlas - Resize
341bool TextureAtlas::resizeCapacity(ssize_t newCapacity)
342{
343 AXASSERT(newCapacity >= 0, "capacity >= 0");
344 if (newCapacity == _capacity)
345 {
346 return true;
347 }
348 auto oldCapacity = _capacity;
349
350 // update capacity and totalQuads
351 _totalQuads = MIN(_totalQuads, newCapacity);
352 _capacity = newCapacity;
353
354 V3F_C4B_T2F_Quad* tmpQuads = nullptr;
355 uint16_t* tmpIndices = nullptr;
356
357 // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return nullptr,
358 // so here must judge whether _quads and _indices is nullptr.
359
360 ssize_t _quads_size = sizeof(_quads[0]);
361 ssize_t new_quads_size = _capacity * _quads_size;
362 if (_quads == nullptr)
363 {
364 tmpQuads = (V3F_C4B_T2F_Quad*)malloc(new_quads_size);
365 if (tmpQuads != nullptr)
366 {
367 memset(tmpQuads, 0, new_quads_size);
368 }
369 }
370 else
371 {
372 tmpQuads = (V3F_C4B_T2F_Quad*)realloc(_quads, new_quads_size);
373 if (tmpQuads != nullptr && _capacity > oldCapacity)
374 {
375 memset(tmpQuads + oldCapacity, 0, (_capacity - oldCapacity) * _quads_size);
376 }
377 _quads = nullptr;
378 }
379
380 ssize_t _indices_size = sizeof(_indices[0]);
381 ssize_t new_size = _capacity * 6 * _indices_size;
382
383 if (_indices == nullptr)
384 {
385 tmpIndices = (uint16_t*)malloc(new_size);
386 if (tmpIndices != nullptr)
387 {
388 memset(tmpIndices, 0, new_size);
389 }
390 }
391 else
392 {
393 tmpIndices = (uint16_t*)realloc(_indices, new_size);
394 if (tmpIndices != nullptr && _capacity > oldCapacity)
395 {
396 memset(tmpIndices + oldCapacity, 0, (_capacity - oldCapacity) * 6 * _indices_size);
397 }
398 _indices = nullptr;

Callers 4

setStringMethod · 0.80
increaseAtlasCapacityMethod · 0.80
reserveCapacityMethod · 0.80

Calls 1

reallocFunction · 0.85

Tested by

no test coverage detected