1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-17 13:02:27 +01:00

Refactor drawing

This commit is contained in:
Ted John
2020-08-26 00:59:11 +01:00
parent 653e22bb7b
commit 65e3d20156
4 changed files with 44 additions and 32 deletions

View File

@@ -69,8 +69,7 @@ private:
int32_t _clipTop = 0; int32_t _clipTop = 0;
int32_t _clipRight = 0; int32_t _clipRight = 0;
int32_t _clipBottom = 0; int32_t _clipBottom = 0;
int32_t _spriteOffsetX = 0; ScreenCoordsXY _spriteOffset;
int32_t _spriteOffsetY = 0;
int32_t _drawCount = 0; int32_t _drawCount = 0;
@@ -695,10 +694,10 @@ void OpenGLDrawingContext::DrawSprite(uint32_t image, int32_t x, int32_t y, uint
right = right / _dpi->zoom_level; right = right / _dpi->zoom_level;
bottom = bottom / _dpi->zoom_level; bottom = bottom / _dpi->zoom_level;
left += _spriteOffsetX; left += _spriteOffset.x;
top += _spriteOffsetY; top += _spriteOffset.y;
right += _spriteOffsetX; right += _spriteOffset.x;
bottom += _spriteOffsetY; bottom += _spriteOffset.y;
const auto texture = _textureCache->GetOrLoadImageTexture(image); const auto texture = _textureCache->GetOrLoadImageTexture(image);
@@ -807,10 +806,10 @@ void OpenGLDrawingContext::DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t ma
right = right * _dpi->zoom_level; right = right * _dpi->zoom_level;
bottom = bottom * _dpi->zoom_level; bottom = bottom * _dpi->zoom_level;
left += _spriteOffsetX; left += _spriteOffset.x;
top += _spriteOffsetY; top += _spriteOffset.y;
right += _spriteOffsetX; right += _spriteOffset.x;
bottom += _spriteOffsetY; bottom += _spriteOffset.y;
DrawRectCommand& command = _commandBuffers.rects.allocate(); DrawRectCommand& command = _commandBuffers.rects.allocate();
@@ -911,10 +910,10 @@ void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, const
right = right / _dpi->zoom_level; right = right / _dpi->zoom_level;
bottom = bottom / _dpi->zoom_level; bottom = bottom / _dpi->zoom_level;
left += _spriteOffsetX; left += _spriteOffset.x;
top += _spriteOffsetY; top += _spriteOffset.y;
right += _spriteOffsetX; right += _spriteOffset.x;
bottom += _spriteOffsetY; bottom += _spriteOffset.y;
DrawRectCommand& command = _commandBuffers.rects.allocate(); DrawRectCommand& command = _commandBuffers.rects.allocate();
@@ -1008,22 +1007,22 @@ void OpenGLDrawingContext::HandleTransparency()
void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo* dpi) void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo* dpi)
{ {
rct_drawpixelinfo* screenDPI = _engine->GetDPI(); auto screenDPI = _engine->GetDPI();
auto bytesPerRow = screenDPI->GetBytesPerRow();
auto bitsOffset = static_cast<size_t>(dpi->bits - screenDPI->bits);
# ifndef NDEBUG # ifndef NDEBUG
size_t bitsSize = static_cast<size_t>(screenDPI->height) * static_cast<size_t>(screenDPI->width + screenDPI->pitch); auto bitsSize = static_cast<size_t>(screenDPI->height) * bytesPerRow;
# endif
size_t bitsOffset = static_cast<size_t>(dpi->bits - screenDPI->bits);
assert(bitsOffset < bitsSize); assert(bitsOffset < bitsSize);
# endif
_clipLeft = static_cast<int32_t>(bitsOffset % (screenDPI->width + screenDPI->pitch)) + dpi->remX; _clipLeft = static_cast<int32_t>(bitsOffset % bytesPerRow) + dpi->remX;
_clipTop = static_cast<int32_t>(bitsOffset / (screenDPI->width + screenDPI->pitch)) + dpi->remY; _clipTop = static_cast<int32_t>(bitsOffset / bytesPerRow) + dpi->remY;
_clipRight = _clipLeft + (dpi->width / dpi->zoom_level); _clipRight = _clipLeft + (dpi->width / dpi->zoom_level);
_clipBottom = _clipTop + (dpi->height / dpi->zoom_level); _clipBottom = _clipTop + (dpi->height / dpi->zoom_level);
_offsetX = _clipLeft - dpi->x; _offsetX = _clipLeft - dpi->x;
_offsetY = _clipTop - dpi->y; _offsetY = _clipTop - dpi->y;
_spriteOffsetX = _clipLeft - dpi->remX; _spriteOffset.x = _clipLeft - dpi->remX;
_spriteOffsetY = _clipTop - dpi->remY; _spriteOffset.y = _clipTop - dpi->remY;
_dpi = dpi; _dpi = dpi;
} }

View File

@@ -773,14 +773,24 @@ std::optional<PaletteMap> GetPaletteMapForColour(colour_t paletteId)
return std::nullopt; return std::nullopt;
} }
rct_drawpixelinfo rct_drawpixelinfo::Crop(int32_t newX, int32_t newY, int32_t newWidth, int32_t newHeight) size_t rct_drawpixelinfo::GetBytesPerRow() const
{
return static_cast<size_t>(width) + pitch;
}
uint8_t* rct_drawpixelinfo::GetBitsOffset(const ScreenCoordsXY& pos) const
{
return bits + pos.x + (pos.y * GetBytesPerRow());
}
rct_drawpixelinfo rct_drawpixelinfo::Crop(const ScreenCoordsXY& pos, const ScreenSize& size) const
{ {
rct_drawpixelinfo result = *this; rct_drawpixelinfo result = *this;
result.bits = bits + newX + (((size_t)width + pitch) * newY); result.bits = GetBitsOffset(pos);
result.x = static_cast<int16_t>(newX); result.x = static_cast<int16_t>(pos.x);
result.y = static_cast<int16_t>(newY); result.y = static_cast<int16_t>(pos.y);
result.width = static_cast<int16_t>(newWidth); result.width = static_cast<int16_t>(size.width);
result.height = static_cast<int16_t>(newHeight); result.height = static_cast<int16_t>(size.height);
result.pitch = static_cast<int16_t>(width + pitch - newWidth); result.pitch = static_cast<int16_t>(width + pitch - size.width);
return result; return result;
} }

View File

@@ -13,6 +13,7 @@
#include "../common.h" #include "../common.h"
#include "../interface/Colour.h" #include "../interface/Colour.h"
#include "../interface/ZoomLevel.hpp" #include "../interface/ZoomLevel.hpp"
#include "../world/Location.hpp"
#include "Text.h" #include "Text.h"
#include <optional> #include <optional>
@@ -114,7 +115,9 @@ struct rct_drawpixelinfo
OpenRCT2::Drawing::IDrawingEngine* DrawingEngine{}; OpenRCT2::Drawing::IDrawingEngine* DrawingEngine{};
rct_drawpixelinfo Crop(int32_t newX, int32_t newY, int32_t newWidth, int32_t newHeight); size_t GetBytesPerRow() const;
uint8_t* GetBitsOffset(const ScreenCoordsXY& pos) const;
rct_drawpixelinfo Crop(const ScreenCoordsXY& pos, const ScreenSize& size) const;
}; };
struct rct_g1_element_32bit struct rct_g1_element_32bit

View File

@@ -2019,7 +2019,7 @@ bool window_is_visible(rct_window* w)
*/ */
void window_draw_all(rct_drawpixelinfo* dpi, int16_t left, int16_t top, int16_t right, int16_t bottom) void window_draw_all(rct_drawpixelinfo* dpi, int16_t left, int16_t top, int16_t right, int16_t bottom)
{ {
auto windowDPI = dpi->Crop(left, top, right - left, bottom - top); auto windowDPI = dpi->Crop({ left, top }, { right - left, bottom - top });
window_visit_each([&windowDPI, left, top, right, bottom](rct_window* w) { window_visit_each([&windowDPI, left, top, right, bottom](rct_window* w) {
if (w->flags & WF_TRANSPARENT) if (w->flags & WF_TRANSPARENT)
return; return;