From 7a2f314aa9a226068073176970b48062df6acedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 5 Apr 2025 16:05:14 +0300 Subject: [PATCH] Use invalidation for OpenGL drawing engine --- .../engines/opengl/OpenGLDrawingEngine.cpp | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index b47a07691e..2db7b21d8f 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -31,6 +31,7 @@ #include #include #include + #include #include #include #include @@ -196,6 +197,7 @@ private: std::unique_ptr _scaleFramebuffer; std::unique_ptr _smoothScaleFramebuffer; OpenGLWeatherDrawer _weatherDrawer; + InvalidationGrid _invalidationGrid; public: SDL_Color Palette[256]; @@ -246,10 +248,19 @@ public: { ConfigureBits(width, height, width); ConfigureCanvas(); + ConfigureDirtyGrid(); _drawingContext->Resize(width, height); _drawingContext->Clear(_bitsDPI, PaletteIndex::pi10); } + void ConfigureDirtyGrid() + { + const auto blockWidth = 1u << 7; + const auto blockHeight = 1u << 5; + + _invalidationGrid.reset(_width, _height, blockWidth, blockHeight); + } + void SetPalette(const GamePalette& palette) override { for (int32_t i = 0; i < 256; i++) @@ -281,6 +292,7 @@ public: void Invalidate(int32_t left, int32_t top, int32_t right, int32_t bottom) override { + _invalidationGrid.invalidate(left, top, right, bottom); } void BeginDraw() override @@ -326,7 +338,21 @@ public: void PaintWindows() override { WindowUpdateAllViewports(); - WindowDrawAll(_bitsDPI, 0, 0, _width, _height); + DrawAllDirtyBlocks(); + } + + void DrawAllDirtyBlocks() + { + _invalidationGrid.traverseDirtyCells([this](int32_t left, int32_t top, int32_t right, int32_t bottom) { + // Draw region + DrawDirtyBlocks(left, top, right, bottom); + }); + } + + void DrawDirtyBlocks(int32_t left, int32_t top, int32_t right, int32_t bottom) + { + // Draw region + WindowDrawAll(_bitsDPI, left, top, right, bottom); } void PaintWeather() override