| 184 | } |
| 185 | |
| 186 | ::testing::AssertionResult CompareWithBitmap( const char* filePath, Tr2TextureAL& rt, Tr2RenderContextAL& renderContext ) |
| 187 | { |
| 188 | uint32_t width, height; |
| 189 | std::unique_ptr<uint8_t[]> data; |
| 190 | auto loaded = LoadDDS( filePath, width, height, data ); |
| 191 | if( !loaded ) |
| 192 | { |
| 193 | return ::testing::AssertionSuccess(); |
| 194 | } |
| 195 | |
| 196 | if( width != rt.GetWidth() ) |
| 197 | { |
| 198 | return ::testing::AssertionFailure() << "width or DDS image " << width << " is not equal to back buffer width " << rt.GetWidth(); |
| 199 | } |
| 200 | if( height != rt.GetHeight() ) |
| 201 | { |
| 202 | return ::testing::AssertionFailure() << "height or DDS image " << height << " is not equal to back buffer height " << rt.GetHeight(); |
| 203 | } |
| 204 | |
| 205 | const void* rtData; |
| 206 | uint32_t rtPitch; |
| 207 | auto hr = rt.MapForReading( Tr2TextureSubresource( 0 ), rtData, rtPitch, renderContext ); |
| 208 | if( FAILED( hr ) ) |
| 209 | { |
| 210 | return ::testing::AssertionFailure() << "failed to map render target, HR=" << hr.GetResult(); |
| 211 | } |
| 212 | ON_BLOCK_EXIT( [&] { rt.UnmapForReading( renderContext ); } ); |
| 213 | |
| 214 | const uint8_t* rtRow = static_cast<const uint8_t*>( rtData ); |
| 215 | //const uint8_t* flRow = data.get(); |
| 216 | for( uint32_t i = 0; i < rt.GetHeight(); ++i ) |
| 217 | { |
| 218 | for( uint32_t j = 0; j < width; ++j ) |
| 219 | { |
| 220 | if( rtRow[j * 4] != rtRow[j * 4] || rtRow[j * 4 + 1] != rtRow[j * 4 + 1] || rtRow[j * 4 + 2] != rtRow[j * 4 + 2] ) |
| 221 | { |
| 222 | return ::testing::AssertionFailure() << "pixel values in expected DDS and back buffer are different at (" << j << ", " << i << ") pixel"; |
| 223 | } |
| 224 | } |
| 225 | rtRow += rtPitch; |
| 226 | //flRow += 4 * width; |
| 227 | } |
| 228 | return ::testing::AssertionSuccess(); |
| 229 | } |
| 230 | |
| 231 | Tr2TextureAL GetReadableBackBuffer( Tr2PrimaryRenderContextAL& renderContext ) |
| 232 | { |
no test coverage detected