-------------------------------------------------------------------------------- Description: Syncronous update --------------------------------------------------------------------------------
| 91 | // Syncronous update |
| 92 | // -------------------------------------------------------------------------------- |
| 93 | void Tr2DataTextureManager::Update( EveUpdateContext& updateContext ) |
| 94 | { |
| 95 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 96 | |
| 97 | // 0 |
| 98 | m_maxPixelCount = m_maxBlockCount = 0; |
| 99 | |
| 100 | // do not update anything if data is totally empty |
| 101 | if( m_blockData.empty() ) |
| 102 | { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | // update data texture and keep track of the pixel offsets! |
| 107 | void* data = nullptr; |
| 108 | uint32_t pitch = 0; |
| 109 | int32_t pixelOffset = 0; |
| 110 | m_dataTextureOffsets.clear(); |
| 111 | if( SUCCEEDED( m_dataTexture->GetTexture()->MapForWriting( Tr2TextureSubresource( 0 ), data, pitch, renderContext ) ) ) |
| 112 | { |
| 113 | uint8_t* mem = (uint8_t*)data; |
| 114 | |
| 115 | // encode all the blocks in the texture, go through them by priority |
| 116 | for( auto it = m_blockPriority.rbegin(); it != m_blockPriority.rend(); ++it ) |
| 117 | { |
| 118 | auto finder = m_blockData.find( it->second ); |
| 119 | if( finder != m_blockData.end() ) |
| 120 | { |
| 121 | int32_t blockID = finder->first; |
| 122 | BlockData* block = &finder->second; |
| 123 | |
| 124 | // check if we still have room for one more block |
| 125 | if( pixelOffset + block->blockLength + 1 >= m_textureWidth ) |
| 126 | { |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | // save pixeloffset |
| 131 | m_dataTextureOffsets[blockID] = pixelOffset; |
| 132 | |
| 133 | // header |
| 134 | for( uint32_t y = 0; y < m_textureHeight; ++y ) |
| 135 | { |
| 136 | memcpy( &mem[y * pitch], &block->header[y], sizeof( Vector4 ) ); |
| 137 | } |
| 138 | |
| 139 | // data |
| 140 | mem += sizeof( Vector4 ); |
| 141 | for( uint32_t y = 0; y < m_textureHeight; ++y ) |
| 142 | { |
| 143 | for( uint32_t x = 0; x < block->blockLength; ++x ) |
| 144 | { |
| 145 | memcpy( &mem[y * pitch + x * sizeof( Vector4 )], &block->data[x * m_textureHeight + y], sizeof( Vector4 ) ); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // next |
| 150 | mem += block->blockLength * sizeof( Vector4 ); |
nothing calls this directly
no test coverage detected