MCPcopy Create free account
hub / github.com/cinder/Cinder / cache

Method cache

src/cinder/gl/Texture.cpp:1583–1606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1581}
1582
1583gl::TextureRef Texture2dCache::cache( const Surface8u &originalData )
1584{
1585 const Surface8u &surfaceData = ( mIntermediateSurface ) ? *mIntermediateSurface : originalData;
1586 // If mIntermediateSurface isn't null then we need to use that instead.
1587 // This is to accommodate rowBytes values which aren't the same as width * bytesPerPixel
1588 if( mIntermediateSurface )
1589 mIntermediateSurface->copyFrom( originalData, originalData.getBounds() );
1590
1591 // find an available slot and update that if possible
1592 for( vector<pair<int,TextureRef>>::iterator texIt = mTextures.begin(); texIt != mTextures.end(); ++texIt ) {
1593 if( texIt->first == -1 ) { // this texture is available, let's use it!
1594 texIt->second->update( surfaceData );
1595 texIt->first = mNextId++;
1596 // normally this would be very wrong, but when the result TextureRef is destroyed, it calls markTextureAsFree rather than deleting the master texture
1597 return TextureRef( texIt->second.get(), std::bind( &Texture2dCache::markTextureAsFree, shared_from_this(), texIt->first ) );
1598 }
1599 }
1600
1601 // we didn't find an available slot, so let's make a new texture
1602 TextureRef masterTex( new Texture( surfaceData, mFormat ) );
1603 mTextures.push_back( make_pair( mNextId++, masterTex ) );
1604 // normally this would be very wrong, but when the result TextureRef is destroyed, it calls markTextureAsFree rather than deleting the master texture
1605 return TextureRef( mTextures.back().second.get(), std::bind( &Texture2dCache::markTextureAsFree, shared_from_this(), mTextures.back().first ) );
1606}
1607
1608void Texture2dCache::markTextureAsFree( int id )
1609{

Callers 1

newFrameMethod · 0.80

Calls 9

backMethod · 0.80
bindFunction · 0.50
copyFromMethod · 0.45
getBoundsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
updateMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected