MCPcopy Create free account
hub / github.com/SpartanJ/eepp / packTextures

Method packTextures

src/eepp/graphics/texturepacker.cpp:510–608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

508}
509
510Int32 TexturePacker::packTextures() {
511 TexturePackerTex* t = NULL;
512
513 addBorderToTextures( (Int32)mPixelBorder );
514
515 newFree( 0, 0, mWidth, mHeight );
516
517 mCount = (Int32)mTextures.size();
518
519 // We must place each texture
520 std::vector<TexturePackerTex*>::iterator it;
521 for ( it = mTextures.begin(); it != mTextures.end(); ++it ) {
522 // For the texture with the longest edge we place it according to this criteria.
523 // (1) If it is a perfect match, we always accept it as it causes the least amount of
524 // fragmentation. (2) A match of one edge with the minimum area left over after the split.
525 // (3) No edges match, so look for the node which leaves the least amount of area left
526 // over after the split.
527
528 if ( PackBig == mStrategy ) {
529 t = getLongestEdge();
530 } else if ( PackTiny == mStrategy ) {
531 t = getShortestEdge();
532 }
533
534 TexturePackerNode* previousBestFit = NULL;
535 Int32 edgeCount = 0;
536 TexturePackerNode* bestFit = getBestFit( t, &previousBestFit, &edgeCount );
537
538 if ( NULL == bestFit ) {
539 if ( PackBig == mStrategy ) {
540 Log::debug( "TexturePacker: Changing Strategy to Tiny. %s faults.",
541 t->name().c_str() );
542 reset();
543 addBorderToTextures( -( (Int32)mPixelBorder ) );
544 mStrategy = PackTiny;
545 return packTextures();
546 } else if ( PackTiny == mStrategy ) {
547 mStrategy = PackFail;
548 Log::warning( "TexturePacker: Strategy fail, must expand image or create a new "
549 "one. %s faults.",
550 t->name().c_str() );
551 }
552 } else {
553 insertTexture( t, bestFit, edgeCount, previousBestFit );
554 mCount--;
555 }
556
557 if ( PackFail == mStrategy ) {
558 if ( mWidth < mMaxSize.getWidth() || mHeight < mMaxSize.getHeight() ) {
559 reset();
560 addBorderToTextures( -( (Int32)mPixelBorder ) );
561
562 if ( mWidth <= mHeight ) {
563 mWidth *= 2;
564
565 if ( mWidth > mMaxSize.getWidth() )
566 mWidth = mMaxSize.getWidth();
567 } else {

Callers 5

mainFunction · 0.80
updateTextureAtlasMethod · 0.80
createChildMethod · 0.80
textureAtlasSaveMethod · 0.80

Calls 11

debugFunction · 0.85
resetFunction · 0.85
warningFunction · 0.85
c_strMethod · 0.80
placedMethod · 0.80
areaMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45

Tested by 1