Skip to content

Commit

Permalink
Factor out duplicate code between initVideo and setResolution
Browse files Browse the repository at this point in the history
  • Loading branch information
xordspar0 committed Apr 26, 2023
1 parent 6a1768d commit 15e475f
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/graphics/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ bool Renderer::initVideo(int scale)
{
uint32_t window_flags = SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI;

//TODO: sync this with setResolution
if (widescreen) {
screenWidth = 432;
screenHeight = 243;
} else {
screenWidth = 320;
screenHeight = 240;
}

if (_window)
{
LOG_WARN("second call to Renderer::InitVideo()");
Expand Down Expand Up @@ -133,13 +124,7 @@ bool Renderer::initVideo(int scale)

LOG_INFO("Renderer::initVideo: using: {} renderer", info.name);

if (SDL_RenderSetLogicalSize(_renderer, screenWidth, screenHeight))
{
LOG_ERROR("Renderer::initVideo: SDL_RenderSetLogicalSize failed: {}", SDL_GetError());
return false;
}

if (!createRenderTarget(screenWidth, screenHeight))
if (!setResolution(scale, widescreen))
return false;

std::string spotpath = ResourceManager::getInstance()->getPath("spot.png");
Expand All @@ -152,24 +137,6 @@ bool Renderer::initVideo(int scale)
return true;
}

bool Renderer::createRenderTarget(int width, int height)
{
SDL_RendererInfo info;
SDL_GetRendererInfo(_renderer, &info);

_texture = SDL_CreateTexture(_renderer,
info.texture_formats[0],
SDL_TEXTUREACCESS_TARGET,
width, height);
if (SDL_SetRenderTarget(_renderer, _texture)) {
LOG_ERROR("Renderer::createRenderTarget: SDL_SetRenderTarget failed: {}", SDL_GetError());
return false;
}
SDL_RenderClear(_renderer);

return true;
}

bool Renderer::flushAll()
{
LOG_DEBUG("Renderer::flushAll()");
Expand Down Expand Up @@ -255,6 +222,24 @@ int Renderer::getResolutionCount()
#endif
}

bool Renderer::createRenderTarget(int width, int height)
{
SDL_RendererInfo info;
SDL_GetRendererInfo(_renderer, &info);

_texture = SDL_CreateTexture(_renderer,
info.texture_formats[0],
SDL_TEXTUREACCESS_TARGET,
width, height);
if (SDL_SetRenderTarget(_renderer, _texture)) {
LOG_ERROR("Renderer::createRenderTarget: SDL_SetRenderTarget failed: {}", SDL_GetError());
return false;
}
SDL_RenderClear(_renderer);

return true;
}

void Renderer::showLoadingScreen()
{
Surface loading;
Expand Down

0 comments on commit 15e475f

Please sign in to comment.