Add rain rendering to OpenGL renderer

This commit is contained in:
Matt 2019-06-23 02:06:59 +02:00
parent 4170255296
commit 2cf4a42cbe
No known key found for this signature in database
GPG Key ID: 6D4C24A61C93E208
3 changed files with 71 additions and 13 deletions

View File

@ -56,7 +56,6 @@ class OpenGLDrawingContext final : public IDrawingContext
private:
OpenGLDrawingEngine* _engine = nullptr;
rct_drawpixelinfo* _dpi = nullptr;
ApplyTransparencyShader* _applyTransparencyShader = nullptr;
DrawLineShader* _drawLineShader = nullptr;
DrawRectShader* _drawRectShader = nullptr;
@ -115,6 +114,62 @@ public:
void HandleTransparency();
void SetDPI(rct_drawpixelinfo* dpi);
rct_drawpixelinfo* GetDPI() const
{
return _dpi;
}
};
class OpenGLRainDrawer final : public IRainDrawer
{
OpenGLDrawingContext* _drawingContext;
public:
explicit OpenGLRainDrawer(OpenGLDrawingContext* drawingContext)
: _drawingContext(drawingContext)
{
}
virtual void Draw(int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart)
{
const uint8_t* pattern = RainPattern;
uint8_t patternXSpace = *pattern++;
uint8_t patternYSpace = *pattern++;
uint8_t patternStartXOffset = xStart % patternXSpace;
uint8_t patternStartYOffset = yStart % patternYSpace;
const auto* dpi = _drawingContext->GetDPI();
uint32_t pixelOffset = (dpi->pitch + dpi->width) * y + x;
uint8_t patternYPos = patternStartYOffset % patternYSpace;
for (; height != 0; height--)
{
uint8_t patternX = pattern[patternYPos * 2];
if (patternX != 0xFF)
{
uint32_t finalPixelOffset = width + pixelOffset;
uint32_t xPixelOffset = pixelOffset;
xPixelOffset += ((uint8_t)(patternX - patternStartXOffset)) % patternXSpace;
uint8_t patternPixel = pattern[patternYPos * 2 + 1];
for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace)
{
int32_t pixelX = xPixelOffset % dpi->width;
int32_t pixelY = (xPixelOffset / dpi->width) % dpi->height;
_drawingContext->DrawLine(patternPixel, pixelX, pixelY, pixelX + 1, pixelY + 1);
}
}
pixelOffset += dpi->pitch + dpi->width;
patternYPos++;
patternYPos %= patternYSpace;
}
}
};
class OpenGLDrawingEngine : public IDrawingEngine
@ -138,6 +193,7 @@ private:
OpenGLFramebuffer* _screenFramebuffer = nullptr;
OpenGLFramebuffer* _scaleFramebuffer = nullptr;
OpenGLFramebuffer* _smoothScaleFramebuffer = nullptr;
OpenGLRainDrawer _rainDrawer;
public:
SDL_Color Palette[256];
@ -145,9 +201,10 @@ public:
explicit OpenGLDrawingEngine(const std::shared_ptr<IUiContext>& uiContext)
: _uiContext(uiContext)
, _drawingContext(new OpenGLDrawingContext(this))
, _rainDrawer(_drawingContext)
{
_window = (SDL_Window*)_uiContext->GetWindow();
_drawingContext = new OpenGLDrawingContext(this);
_bitsDPI.DrawingEngine = this;
# ifdef __ENABLE_LIGHTFX__
lightfx_set_available(false);
@ -284,7 +341,8 @@ public:
void PaintRain() override
{
// Not implemented
_drawingContext->SetDPI(&_bitsDPI);
DrawRain(&_bitsDPI, &_rainDrawer);
}
std::string Screenshot() override

View File

@ -18,4 +18,14 @@ namespace OpenRCT2::Drawing
interface IRainDrawer;
}
// clang-format off
static constexpr const uint8_t RainPattern[] =
{
32, 32, 0, 12, 0, 14, 0, 16, 255, 0, 255, 0, 255, 0, 255, 0, 255,
0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0
};
// clang-format on
void DrawRain(rct_drawpixelinfo* dpi, OpenRCT2::Drawing::IRainDrawer* rainDrawer);

View File

@ -47,16 +47,6 @@ void X8RainDrawer::SetDPI(rct_drawpixelinfo* dpi)
void X8RainDrawer::Draw(int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart)
{
// clang-format off
static constexpr const uint8_t RainPattern[] =
{
32, 32, 0, 12, 0, 14, 0, 16, 255, 0, 255, 0, 255, 0, 255, 0, 255,
0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0
};
// clang-format on
const uint8_t* pattern = RainPattern;
uint8_t patternXSpace = *pattern++;
uint8_t patternYSpace = *pattern++;