AsyncFetcher::~AsyncFetcher() { if( _window && _sharedWindow ) deleteSharedContextWindow( _window, &_sharedWindow, &_objectManager ); delete [] _tmpTexture; }
/** * Function for creating and holding of shared context. * Generation and uploading of new textures over some period with sleep time. */ void AsyncFetcher::run() { EQASSERT( !_sharedContextWindow ); _sharedContextWindow = initSharedContextWindow( _wnd ); _outQueue.push( TextureId( )); // unlock pipe thread if( !_sharedContextWindow ) return; _objectManager = new ObjectManager( glewGetContext( )); EQINFO << "async fetcher initialized: " << _wnd << std::endl; int i = 0; bool running = true; co::base::sleep( 1000 ); // imitate loading of the first texture while( running ) { // generate new texture eq::util::Texture* tx = _objectManager->newEqTexture( ++i, GL_TEXTURE_2D ); tx->init( GL_RGBA8, 64, 64 ); int j = 0; co::base::RNG rng; for( int y = 0; y < 64; ++y ) { for( int x = 0; x < 64; ++x ) { const GLbyte rnd = rng.get< uint8_t >() % 127; const GLbyte val = (x / 8) % 2 == (y / 8) % 2 ? rnd : 0; _tmpTexture[ j++ ] = val; _tmpTexture[ j++ ] = val; _tmpTexture[ j++ ] = val; _tmpTexture[ j++ ] = val; } } tx->upload( 64, 64, _tmpTexture ); EQ_GL_CALL( glFinish( )); // add new texture to the pool _outQueue.push( TextureId( tx->getName( ), i )); // imitate hard work of loading something else co::base::sleep( rng.get< uint32_t >() % 5000u ); // clean unused textures int keyToDelete = 0; while( _inQueue.tryPop( keyToDelete )) { if( keyToDelete ) { EQWARN << "Deleting eq texture " << keyToDelete << std::endl; _objectManager->deleteEqTexture( keyToDelete ); } else running = false; } } deleteSharedContextWindow( _wnd, &_sharedContextWindow, &_objectManager ); }
/** * Function for creating and holding of shared context. */ void GPUAsyncLoaderBase::run() { LBASSERT( !_sharedContextWindow ); _sharedContextWindow = initSharedContextWindow( _wnd, &_computeCtx ); onInit(); if( !getSharedContextWindow() ) return; runLocal(); cleanup(); deleteSharedContextWindow( _wnd, &_sharedContextWindow, &_computeCtx ); }
GPUAsyncLoaderBase::~GPUAsyncLoaderBase() { if( _wnd && _sharedContextWindow ) deleteSharedContextWindow( _wnd, &_sharedContextWindow, &_computeCtx ); }