| 146 | } |
| 147 | |
| 148 | bool CopyToTexture( ImageIO::HostBitmap& bitmap, Tr2TextureAL& texture, unsigned int x, unsigned int y, unsigned int margin, Tr2RenderContext& renderContext ) |
| 149 | { |
| 150 | CCP_STATS_ZONE( __FUNCTION__ ); |
| 151 | |
| 152 | if( !bitmap.IsValid() ) |
| 153 | { |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | if( texture.GetFormat() != bitmap.GetFormat() ) |
| 158 | { |
| 159 | CCP_LOGERR( "Tr2ImageHandler::CopyToTexture - formats don't match" ); |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | if( x >= texture.GetWidth() || y >= texture.GetHeight() ) |
| 164 | { |
| 165 | CCP_LOGERR( "Tr2ImageHandler::CopyToTexture - out of bounds" ); |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | if( x + bitmap.GetWidth() > texture.GetWidth() || y + bitmap.GetHeight() > texture.GetHeight() ) |
| 170 | { |
| 171 | CCP_LOGERR( "Tr2ImageHandler::CopyToTexture - out of bounds" ); |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | if( !margin ) |
| 176 | { |
| 177 | const auto result = texture.UpdateSubresource( Tr2TextureSubresource( 0 ).SetRect( x, y, x + bitmap.GetWidth(), y + bitmap.GetHeight() ), bitmap.GetRawData(), bitmap.GetPitch(), 0, renderContext ); |
| 178 | if( FAILED( result ) ) |
| 179 | { |
| 180 | CCP_LOGERR( "Tr2ImageHandler::CopyToTexture - UpdateSubresource failed [no margin]: %08x", result.GetResult() ); |
| 181 | } |
| 182 | return SUCCEEDED( result ); |
| 183 | } |
| 184 | |
| 185 | // Can't expect the Hal to support updating a subresource with automatic replication of border pixels, so do this ourselves in a chunk |
| 186 | // of temporary memory, then send that off to the backend. |
| 187 | |
| 188 | std::vector<unsigned char> pixels; |
| 189 | unsigned pitch = 0; |
| 190 | AddMargin( bitmap.GetFormat(), reinterpret_cast<const uint8_t*>( bitmap.GetRawData() ), bitmap.GetWidth(), bitmap.GetHeight(), margin, pixels, pitch ); |
| 191 | |
| 192 | const auto result = texture.UpdateSubresource( Tr2TextureSubresource( 0 ).SetRect( x, y, x + bitmap.GetWidth() + 2 * margin, y + bitmap.GetHeight() + 2 * margin ), &pixels[0], pitch, 0, renderContext ); |
| 193 | if( FAILED( result ) ) |
| 194 | { |
| 195 | CCP_LOGERR( "Tr2ImageHandler::CopyToTexture - UpdateSubresource failed [margin]: %08x", result.GetResult() ); |
| 196 | } |
| 197 | return SUCCEEDED( result ); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | void AddMargin( const Tr2RenderContextEnum::PixelFormat format, |
no test coverage detected