mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Use smart pointers in OpenGLDrawingEngine.cpp
Co-authored-by: ζeh Matt <5415177+ZehMatt@users.noreply.github.com>
This commit is contained in:
@@ -56,13 +56,13 @@ class OpenGLDrawingEngine;
|
||||
class OpenGLDrawingContext final : public IDrawingContext
|
||||
{
|
||||
private:
|
||||
OpenGLDrawingEngine* _engine = nullptr;
|
||||
ApplyTransparencyShader* _applyTransparencyShader = nullptr;
|
||||
DrawLineShader* _drawLineShader = nullptr;
|
||||
DrawRectShader* _drawRectShader = nullptr;
|
||||
SwapFramebuffer* _swapFramebuffer = nullptr;
|
||||
OpenGLDrawingEngine& _engine;
|
||||
std::unique_ptr<ApplyTransparencyShader> _applyTransparencyShader;
|
||||
std::unique_ptr<DrawLineShader> _drawLineShader;
|
||||
std::unique_ptr<DrawRectShader> _drawRectShader;
|
||||
std::unique_ptr<SwapFramebuffer> _swapFramebuffer;
|
||||
|
||||
TextureCache* _textureCache = nullptr;
|
||||
std::unique_ptr<TextureCache> _textureCache;
|
||||
|
||||
int32_t _offsetX = 0;
|
||||
int32_t _offsetY = 0;
|
||||
@@ -82,13 +82,13 @@ private:
|
||||
} _commandBuffers;
|
||||
|
||||
public:
|
||||
explicit OpenGLDrawingContext(OpenGLDrawingEngine* engine);
|
||||
explicit OpenGLDrawingContext(OpenGLDrawingEngine& engine);
|
||||
~OpenGLDrawingContext() override;
|
||||
|
||||
IDrawingEngine* GetEngine() override;
|
||||
TextureCache* GetTextureCache() const
|
||||
{
|
||||
return _textureCache;
|
||||
return _textureCache.get();
|
||||
}
|
||||
const OpenGLFramebuffer& GetFinalFramebuffer() const
|
||||
{
|
||||
@@ -183,15 +183,15 @@ private:
|
||||
uint32_t _height = 0;
|
||||
uint32_t _pitch = 0;
|
||||
size_t _bitsSize = 0;
|
||||
uint8_t* _bits = nullptr;
|
||||
std::unique_ptr<uint8_t[]> _bits;
|
||||
|
||||
rct_drawpixelinfo _bitsDPI = {};
|
||||
|
||||
OpenGLDrawingContext* _drawingContext;
|
||||
std::unique_ptr<OpenGLDrawingContext> _drawingContext;
|
||||
|
||||
ApplyPaletteShader* _applyPaletteShader = nullptr;
|
||||
OpenGLFramebuffer* _screenFramebuffer = nullptr;
|
||||
OpenGLFramebuffer* _scaleFramebuffer = nullptr;
|
||||
std::unique_ptr<ApplyPaletteShader> _applyPaletteShader;
|
||||
std::unique_ptr<OpenGLFramebuffer> _screenFramebuffer;
|
||||
std::unique_ptr<OpenGLFramebuffer> _scaleFramebuffer;
|
||||
OpenGLFramebuffer* _smoothScaleFramebuffer = nullptr;
|
||||
OpenGLWeatherDrawer _weatherDrawer;
|
||||
|
||||
@@ -201,8 +201,8 @@ public:
|
||||
|
||||
explicit OpenGLDrawingEngine(const std::shared_ptr<IUiContext>& uiContext)
|
||||
: _uiContext(uiContext)
|
||||
, _drawingContext(new OpenGLDrawingContext(this))
|
||||
, _weatherDrawer(_drawingContext)
|
||||
, _drawingContext(std::make_unique<OpenGLDrawingContext>(*this))
|
||||
, _weatherDrawer(_drawingContext.get())
|
||||
{
|
||||
_window = static_cast<SDL_Window*>(_uiContext->GetWindow());
|
||||
_bitsDPI.DrawingEngine = this;
|
||||
@@ -213,12 +213,6 @@ public:
|
||||
|
||||
~OpenGLDrawingEngine() override
|
||||
{
|
||||
delete _applyPaletteShader;
|
||||
delete _screenFramebuffer;
|
||||
|
||||
delete _drawingContext;
|
||||
delete[] _bits;
|
||||
|
||||
SDL_GL_DeleteContext(_context);
|
||||
}
|
||||
|
||||
@@ -245,7 +239,7 @@ public:
|
||||
|
||||
_drawingContext->Initialise();
|
||||
|
||||
_applyPaletteShader = new ApplyPaletteShader();
|
||||
_applyPaletteShader = std::make_unique<ApplyPaletteShader>();
|
||||
}
|
||||
|
||||
void Resize(uint32_t width, uint32_t height) override
|
||||
@@ -360,7 +354,7 @@ public:
|
||||
|
||||
IDrawingContext* GetDrawingContext() override
|
||||
{
|
||||
return _drawingContext;
|
||||
return _drawingContext.get();
|
||||
}
|
||||
|
||||
rct_drawpixelinfo* GetDrawingPixelInfo() override
|
||||
@@ -400,21 +394,22 @@ private:
|
||||
void ConfigureBits(uint32_t width, uint32_t height, uint32_t pitch)
|
||||
{
|
||||
size_t newBitsSize = pitch * height;
|
||||
uint8_t* newBits = new uint8_t[newBitsSize];
|
||||
|
||||
auto newBits = std::make_unique<uint8_t[]>(newBitsSize);
|
||||
if (_bits == nullptr)
|
||||
{
|
||||
std::fill_n(newBits, newBitsSize, 0);
|
||||
std::fill_n(newBits.get(), newBitsSize, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_pitch == pitch)
|
||||
{
|
||||
std::copy_n(_bits, std::min(_bitsSize, newBitsSize), newBits);
|
||||
std::copy_n(_bits.get(), std::min(_bitsSize, newBitsSize), newBits.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t* src = _bits;
|
||||
uint8_t* dst = newBits;
|
||||
uint8_t* src = _bits.get();
|
||||
uint8_t* dst = newBits.get();
|
||||
|
||||
uint32_t minWidth = std::min(_width, width);
|
||||
uint32_t minHeight = std::min(_height, height);
|
||||
@@ -429,17 +424,16 @@ private:
|
||||
dst += pitch;
|
||||
}
|
||||
}
|
||||
delete[] _bits;
|
||||
}
|
||||
|
||||
_bits = newBits;
|
||||
_bits = std::move(newBits);
|
||||
_bitsSize = newBitsSize;
|
||||
_width = width;
|
||||
_height = height;
|
||||
_pitch = pitch;
|
||||
|
||||
rct_drawpixelinfo* dpi = &_bitsDPI;
|
||||
dpi->bits = _bits;
|
||||
dpi->bits = _bits.get();
|
||||
dpi->x = 0;
|
||||
dpi->y = 0;
|
||||
dpi->width = width;
|
||||
@@ -450,22 +444,10 @@ private:
|
||||
void ConfigureCanvas()
|
||||
{
|
||||
// Re-create screen framebuffer
|
||||
delete _screenFramebuffer;
|
||||
_screenFramebuffer = new OpenGLFramebuffer(_window);
|
||||
|
||||
if (_scaleFramebuffer != nullptr)
|
||||
{
|
||||
delete _scaleFramebuffer;
|
||||
_scaleFramebuffer = nullptr;
|
||||
}
|
||||
if (_smoothScaleFramebuffer != nullptr)
|
||||
{
|
||||
delete _smoothScaleFramebuffer;
|
||||
_smoothScaleFramebuffer = nullptr;
|
||||
}
|
||||
_screenFramebuffer = std::make_unique<OpenGLFramebuffer>(_window);
|
||||
if (GetContext()->GetUiContext()->GetScaleQuality() != ScaleQuality::NearestNeighbour)
|
||||
{
|
||||
_scaleFramebuffer = new OpenGLFramebuffer(_width, _height, false, false);
|
||||
_scaleFramebuffer = std::make_unique<OpenGLFramebuffer>(_width, _height, false, false);
|
||||
}
|
||||
if (GetContext()->GetUiContext()->GetScaleQuality() == ScaleQuality::SmoothNearestNeighbour)
|
||||
{
|
||||
@@ -485,32 +467,26 @@ std::unique_ptr<IDrawingEngine> OpenRCT2::Ui::CreateOpenGLDrawingEngine(const st
|
||||
return std::make_unique<OpenGLDrawingEngine>(uiContext);
|
||||
}
|
||||
|
||||
OpenGLDrawingContext::OpenGLDrawingContext(OpenGLDrawingEngine* engine)
|
||||
OpenGLDrawingContext::OpenGLDrawingContext(OpenGLDrawingEngine& engine)
|
||||
: _engine(engine)
|
||||
{
|
||||
_engine = engine;
|
||||
}
|
||||
|
||||
OpenGLDrawingContext::~OpenGLDrawingContext()
|
||||
{
|
||||
delete _applyTransparencyShader;
|
||||
delete _drawLineShader;
|
||||
delete _drawRectShader;
|
||||
delete _swapFramebuffer;
|
||||
|
||||
delete _textureCache;
|
||||
}
|
||||
|
||||
IDrawingEngine* OpenGLDrawingContext::GetEngine()
|
||||
{
|
||||
return _engine;
|
||||
return &_engine;
|
||||
}
|
||||
|
||||
void OpenGLDrawingContext::Initialise()
|
||||
{
|
||||
_textureCache = new TextureCache();
|
||||
_applyTransparencyShader = new ApplyTransparencyShader();
|
||||
_drawRectShader = new DrawRectShader();
|
||||
_drawLineShader = new DrawLineShader();
|
||||
_textureCache = std::make_unique<TextureCache>();
|
||||
_applyTransparencyShader = std::make_unique<ApplyTransparencyShader>();
|
||||
_drawRectShader = std::make_unique<DrawRectShader>();
|
||||
_drawLineShader = std::make_unique<DrawLineShader>();
|
||||
}
|
||||
|
||||
void OpenGLDrawingContext::Resize(int32_t width, int32_t height)
|
||||
@@ -524,8 +500,7 @@ void OpenGLDrawingContext::Resize(int32_t width, int32_t height)
|
||||
_drawLineShader->SetScreenSize(width, height);
|
||||
|
||||
// Re-create canvas framebuffer
|
||||
delete _swapFramebuffer;
|
||||
_swapFramebuffer = new SwapFramebuffer(width, height);
|
||||
_swapFramebuffer = std::make_unique<SwapFramebuffer>(width, height);
|
||||
}
|
||||
|
||||
void OpenGLDrawingContext::ResetPalette()
|
||||
@@ -1060,7 +1035,7 @@ void OpenGLDrawingContext::HandleTransparency()
|
||||
|
||||
void OpenGLDrawingContext::CalculcateClipping(rct_drawpixelinfo* dpi)
|
||||
{
|
||||
auto screenDPI = _engine->GetDPI();
|
||||
auto screenDPI = _engine.GetDPI();
|
||||
auto bytesPerRow = screenDPI->GetBytesPerRow();
|
||||
auto bitsOffset = static_cast<size_t>(dpi->bits - screenDPI->bits);
|
||||
# ifndef NDEBUG
|
||||
|
||||
Reference in New Issue
Block a user