MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / resize

Method resize

src/OpenLoco/src/Graphics/SoftwareDrawingEngine.cpp:72–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70 }
71
72 void SoftwareDrawingEngine::resize(const int32_t width, const int32_t height)
73 {
74 // Scale the width and height by configured scale factor
75 const auto scaleFactor = Config::get().scaleFactor;
76 const auto scaledWidth = (int32_t)(width / scaleFactor);
77 const auto scaledHeight = (int32_t)(height / scaleFactor);
78
79 // Release old resources.
80 if (_screenSurface != nullptr)
81 {
82 SDL_DestroySurface(_screenSurface);
83 }
84 if (_screenRGBASurface != nullptr)
85 {
86 SDL_DestroySurface(_screenRGBASurface);
87 }
88
89 if (_screenTexture != nullptr)
90 {
91 SDL_DestroyTexture(_screenTexture);
92 _screenTexture = nullptr;
93 }
94
95 if (_scaledScreenTexture != nullptr)
96 {
97 SDL_DestroyTexture(_scaledScreenTexture);
98 _scaledScreenTexture = nullptr;
99 }
100
101 SDL_PixelFormat outputFormat = SDL_GetWindowPixelFormat(_window);
102 if (outputFormat == SDL_PIXELFORMAT_UNKNOWN)
103 {
104 Logging::error("SDL_GetWindowPixelFormat failed: {}", SDL_GetError());
105 return;
106 }
107
108 // Surfaces.
109 _screenSurface = SDL_CreateSurface(scaledWidth, scaledHeight, SDL_PIXELFORMAT_INDEX8);
110 if (_screenSurface == nullptr)
111 {
112 Logging::error("SDL_CreateRGBSurface (_screenSurface) failed: {}", SDL_GetError());
113 return;
114 }
115
116 _screenRGBASurface = SDL_CreateSurface(scaledWidth, scaledHeight, outputFormat);
117 if (_screenRGBASurface == nullptr)
118 {
119 Logging::error("SDL_CreateRGBSurface (_screenRGBASurface) failed: {}", SDL_GetError());
120 return;
121 }
122
123 if (!SDL_SetSurfaceBlendMode(_screenRGBASurface, SDL_BLENDMODE_NONE))
124 {
125 Logging::error("SDL_SetSurfaceBlendMode (_screenRGBASurface) failed: {}", SDL_GetError());
126 }
127 if (!SDL_SetSurfacePalette(_screenSurface, _palette))
128 {
129 Logging::error("SDL_SetSurfacePalette (_screenSurface) failed: {}", SDL_GetError());

Callers 15

createWindowFunction · 0.45
windowSizeChangedFunction · 0.45
CommandLineParserMethod · 0.45
uncompressFileFunction · 0.45
removeRoadFunction · 0.45
prepareGameStateFunction · 0.45
loadSaveFunction · 0.45
readChunkMethod · 0.45
loadG1Function · 0.45
resetMethod · 0.45
allocateMapElementsFunction · 0.45

Calls 5

errorFunction · 0.85
pushRenderTargetMethod · 0.80
clearSingleMethod · 0.80
getFunction · 0.50
resetMethod · 0.45

Tested by

no test coverage detected