| 294 | } |
| 295 | |
| 296 | void SoftwareDrawingEngine::present() |
| 297 | { |
| 298 | // Lock the surface before setting its pixels |
| 299 | if (SDL_MUSTLOCK(_screenSurface)) |
| 300 | { |
| 301 | if (!SDL_LockSurface(_screenSurface)) |
| 302 | { |
| 303 | return; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // Copy pixels from the virtual screen buffer to the surface |
| 308 | auto& rt = getScreenRT(); |
| 309 | if (rt.bits != nullptr) |
| 310 | { |
| 311 | std::memcpy(_screenSurface->pixels, rt.bits, _screenSurface->pitch * _screenSurface->h); |
| 312 | } |
| 313 | |
| 314 | // Unlock the surface |
| 315 | if (SDL_MUSTLOCK(_screenSurface)) |
| 316 | { |
| 317 | SDL_UnlockSurface(_screenSurface); |
| 318 | } |
| 319 | |
| 320 | // Convert colours via palette mapping onto the RGBA surface. |
| 321 | if (!SDL_BlitSurface(_screenSurface, nullptr, _screenRGBASurface, nullptr)) |
| 322 | { |
| 323 | Logging::error("SDL_BlitSurface {}", SDL_GetError()); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | // Copy the RGBA pixels into screen texture. |
| 328 | if (!SDL_UpdateTexture(_screenTexture, nullptr, _screenRGBASurface->pixels, _screenRGBASurface->pitch)) |
| 329 | { |
| 330 | Logging::error("SDL_UpdateTexture {}", SDL_GetError()); |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | const auto scaleFactor = Config::get().scaleFactor; |
| 335 | if (scaleFactor > 1.0f) |
| 336 | { |
| 337 | // Copy screen texture to the scaled texture. |
| 338 | if (!SDL_SetRenderTarget(_renderer, _scaledScreenTexture)) |
| 339 | { |
| 340 | Logging::error("SDL_SetRenderTarget (_scaledScreenTexture) failed: {}", SDL_GetError()); |
| 341 | return; |
| 342 | } |
| 343 | if (!SDL_RenderTexture(_renderer, _screenTexture, nullptr, nullptr)) |
| 344 | { |
| 345 | Logging::error("SDL_RenderTexture (_screenTexture) failed: {}", SDL_GetError()); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | // Copy scaled texture to primary render target. |
| 350 | if (!SDL_SetRenderTarget(_renderer, nullptr)) |
| 351 | { |
| 352 | Logging::error("SDL_SetRenderTarget (nullptr) failed: {}", SDL_GetError()); |
| 353 | return; |
no test coverage detected