mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-04 13:42:55 +01:00
Invert Painter dependency
Make painter call into the drawing engine, rather than the drawing engine create and call the painter.
This commit is contained in:
@@ -122,9 +122,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
void EndDraw() override
|
||||
{
|
||||
X8DrawingEngine::Draw();
|
||||
Display();
|
||||
}
|
||||
|
||||
|
||||
@@ -105,9 +105,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
void EndDraw() override
|
||||
{
|
||||
X8DrawingEngine::Draw();
|
||||
Display();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <openrct2/drawing/IDrawingEngine.h>
|
||||
#include <openrct2/drawing/Rain.h>
|
||||
#include <openrct2/interface/Screenshot.h>
|
||||
#include <openrct2/paint/Painter.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
|
||||
extern "C"
|
||||
@@ -53,7 +52,6 @@ extern "C"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
using namespace OpenRCT2::Paint;
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
struct OpenGLVersion
|
||||
@@ -230,7 +228,6 @@ private:
|
||||
IUiContext * const _uiContext = nullptr;
|
||||
SDL_Window * _window = nullptr;
|
||||
SDL_GLContext _context = nullptr;
|
||||
Painter _painter;
|
||||
|
||||
uint32 _width = 0;
|
||||
uint32 _height = 0;
|
||||
@@ -251,8 +248,7 @@ public:
|
||||
vec4f GLPalette[256];
|
||||
|
||||
OpenGLDrawingEngine(IUiContext * uiContext)
|
||||
: _uiContext(uiContext),
|
||||
_painter(uiContext)
|
||||
: _uiContext(uiContext)
|
||||
{
|
||||
_window = (SDL_Window *)_uiContext->GetWindow();
|
||||
_drawingContext = new OpenGLDrawingContext(this);
|
||||
@@ -334,41 +330,42 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
void BeginDraw() override
|
||||
{
|
||||
assert(_screenFramebuffer != nullptr);
|
||||
assert(_swapFramebuffer != nullptr);
|
||||
|
||||
_swapFramebuffer->Bind();
|
||||
}
|
||||
|
||||
if (gIntroState != INTRO_STATE_NONE) {
|
||||
intro_draw(&_bitsDPI);
|
||||
} else {
|
||||
window_update_all_viewports();
|
||||
window_draw_all(&_bitsDPI, 0, 0, _width, _height);
|
||||
window_update_all();
|
||||
|
||||
gfx_draw_pickedup_peep(&_bitsDPI);
|
||||
|
||||
_drawingContext->FlushCommandBuffers();
|
||||
_swapFramebuffer->SwapCopy();
|
||||
|
||||
_painter.Paint(&_bitsDPI);
|
||||
}
|
||||
|
||||
void EndDraw() override
|
||||
{
|
||||
_drawingContext->FlushCommandBuffers();
|
||||
|
||||
// Scale up to window
|
||||
_screenFramebuffer->Bind();
|
||||
_copyFramebufferShader->Use();
|
||||
_copyFramebufferShader->SetTexture(_swapFramebuffer->GetTargetFramebuffer()
|
||||
->GetTexture());
|
||||
_copyFramebufferShader->SetTexture(_swapFramebuffer->GetTargetFramebuffer()->GetTexture());
|
||||
_copyFramebufferShader->Draw();
|
||||
|
||||
CheckGLError();
|
||||
Display();
|
||||
}
|
||||
|
||||
void PaintWindows() override
|
||||
{
|
||||
window_update_all_viewports();
|
||||
window_draw_all(&_bitsDPI, 0, 0, _width, _height);
|
||||
|
||||
// TODO move this out from drawing
|
||||
window_update_all();
|
||||
}
|
||||
|
||||
void PaintRain() override
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
sint32 Screenshot() override
|
||||
{
|
||||
const OpenGLFramebuffer * framebuffer = _swapFramebuffer->GetTargetFramebuffer();
|
||||
|
||||
@@ -57,7 +57,10 @@ namespace OpenRCT2 { namespace Drawing
|
||||
virtual void SetUncappedFrameRate(bool uncapped) abstract;
|
||||
|
||||
virtual void Invalidate(sint32 left, sint32 top, sint32 right, sint32 bottom) abstract;
|
||||
virtual void Draw() abstract;
|
||||
virtual void BeginDraw() abstract;
|
||||
virtual void EndDraw() abstract;
|
||||
virtual void PaintWindows() abstract;
|
||||
virtual void PaintRain() abstract;
|
||||
virtual void CopyRect(sint32 x, sint32 y, sint32 width, sint32 height, sint32 dx, sint32 dy) abstract;
|
||||
virtual sint32 Screenshot() abstract;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "../core/Exception.hpp"
|
||||
#include "../core/Registration.hpp"
|
||||
#include "../interface/Screenshot.h"
|
||||
#include "../paint/Painter.h"
|
||||
#include "IDrawingContext.h"
|
||||
#include "IDrawingEngine.h"
|
||||
#include "NewDrawing.h"
|
||||
@@ -35,10 +36,13 @@ extern "C"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
using namespace OpenRCT2::Paint;
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
static sint32 _drawingEngineType = DRAWING_ENGINE_SOFTWARE;
|
||||
static IDrawingEngine * _drawingEngine = nullptr;
|
||||
// TODO move this to Context
|
||||
static Painter * _painter = nullptr;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -74,12 +78,16 @@ extern "C"
|
||||
void drawing_engine_init()
|
||||
{
|
||||
assert(_drawingEngine == nullptr);
|
||||
assert(_painter == nullptr);
|
||||
|
||||
_drawingEngineType = gConfigGeneral.drawing_engine;
|
||||
|
||||
IContext * context = GetContext();
|
||||
IUiContext * uiContext = context->GetUiContext();
|
||||
IDrawingEngine * drawingEngine = uiContext->CreateDrawingEngine((DRAWING_ENGINE_TYPE)_drawingEngineType);
|
||||
auto context = GetContext();
|
||||
auto uiContext = context->GetUiContext();
|
||||
auto drawingEngine = uiContext->CreateDrawingEngine((DRAWING_ENGINE_TYPE)_drawingEngineType);
|
||||
|
||||
_painter = new Painter(uiContext);
|
||||
|
||||
if (drawingEngine == nullptr)
|
||||
{
|
||||
if (_drawingEngineType == DRAWING_ENGINE_SOFTWARE)
|
||||
@@ -150,9 +158,11 @@ extern "C"
|
||||
|
||||
void drawing_engine_draw()
|
||||
{
|
||||
if (_drawingEngine != nullptr)
|
||||
if (_drawingEngine != nullptr && _painter != nullptr)
|
||||
{
|
||||
_drawingEngine->Draw();
|
||||
_drawingEngine->BeginDraw();
|
||||
_painter->Paint(_drawingEngine);
|
||||
_drawingEngine->EndDraw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +177,9 @@ extern "C"
|
||||
void drawing_engine_dispose()
|
||||
{
|
||||
delete _drawingEngine;
|
||||
delete _painter;
|
||||
_drawingEngine = nullptr;
|
||||
_painter = nullptr;
|
||||
}
|
||||
|
||||
rct_drawpixelinfo * drawing_engine_get_dpi()
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "../core/Math.hpp"
|
||||
#include "../core/Memory.hpp"
|
||||
#include "../interface/Screenshot.h"
|
||||
#include "../paint/Painter.h"
|
||||
#include "IDrawingContext.h"
|
||||
#include "IDrawingEngine.h"
|
||||
#include "Rain.h"
|
||||
@@ -41,7 +40,6 @@ extern "C"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
using namespace OpenRCT2::Paint;
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
X8RainDrawer::X8RainDrawer()
|
||||
@@ -141,7 +139,6 @@ void X8RainDrawer::Restore()
|
||||
X8DrawingEngine::X8DrawingEngine(Ui::IUiContext * uiContext)
|
||||
{
|
||||
_drawingContext = new X8DrawingContext(this);
|
||||
_painter = new Painter(uiContext);
|
||||
#ifdef __ENABLE_LIGHTFX__
|
||||
_lastLightFXenabled = (gConfigGeneral.enable_light_fx != 0);
|
||||
#endif
|
||||
@@ -149,7 +146,6 @@ X8DrawingEngine::X8DrawingEngine(Ui::IUiContext * uiContext)
|
||||
|
||||
X8DrawingEngine::~X8DrawingEngine()
|
||||
{
|
||||
delete _painter;
|
||||
delete _drawingContext;
|
||||
delete [] _dirtyGrid.Blocks;
|
||||
delete [] _bits;
|
||||
@@ -204,44 +200,45 @@ void X8DrawingEngine::Invalidate(sint32 left, sint32 top, sint32 right, sint32 b
|
||||
}
|
||||
}
|
||||
|
||||
void X8DrawingEngine::Draw()
|
||||
void X8DrawingEngine::BeginDraw()
|
||||
{
|
||||
if (gIntroState != INTRO_STATE_NONE)
|
||||
{
|
||||
intro_draw(&_bitsDPI);
|
||||
}
|
||||
else
|
||||
if (gIntroState == INTRO_STATE_NONE)
|
||||
{
|
||||
#ifdef __ENABLE_LIGHTFX__
|
||||
// HACK we need to re-configure the bits if light fx has been enabled / disabled
|
||||
if (_lastLightFXenabled != (gConfigGeneral.enable_light_fx != 0))
|
||||
{
|
||||
Resize(_width, _height);
|
||||
}
|
||||
// HACK we need to re-configure the bits if light fx has been enabled / disabled
|
||||
if (_lastLightFXenabled != (gConfigGeneral.enable_light_fx != 0))
|
||||
{
|
||||
Resize(_width, _height);
|
||||
}
|
||||
#endif
|
||||
|
||||
_rainDrawer.SetDPI(&_bitsDPI);
|
||||
_rainDrawer.Restore();
|
||||
|
||||
ResetWindowVisbilities();
|
||||
|
||||
// Redraw dirty regions before updating the viewports, otherwise
|
||||
// when viewports get panned, they copy dirty pixels
|
||||
DrawAllDirtyBlocks();
|
||||
|
||||
window_update_all_viewports();
|
||||
DrawAllDirtyBlocks();
|
||||
window_update_all();
|
||||
|
||||
gfx_draw_pickedup_peep(&_bitsDPI);
|
||||
gfx_invalidate_pickedup_peep();
|
||||
|
||||
DrawRain(&_bitsDPI, &_rainDrawer);
|
||||
|
||||
_painter->Paint(&_bitsDPI);
|
||||
}
|
||||
}
|
||||
|
||||
void X8DrawingEngine::EndDraw()
|
||||
{
|
||||
}
|
||||
|
||||
void X8DrawingEngine::PaintWindows()
|
||||
{
|
||||
ResetWindowVisbilities();
|
||||
|
||||
// Redraw dirty regions before updating the viewports, otherwise
|
||||
// when viewports get panned, they copy dirty pixels
|
||||
DrawAllDirtyBlocks();
|
||||
window_update_all_viewports();
|
||||
DrawAllDirtyBlocks();
|
||||
|
||||
// TODO move this out from drawing
|
||||
window_update_all();
|
||||
}
|
||||
|
||||
void X8DrawingEngine::PaintRain()
|
||||
{
|
||||
DrawRain(&_bitsDPI, &_rainDrawer);
|
||||
}
|
||||
|
||||
void X8DrawingEngine::CopyRect(sint32 x, sint32 y, sint32 width, sint32 height, sint32 dx, sint32 dy)
|
||||
{
|
||||
if (dx == 0 && dy == 0) return;
|
||||
|
||||
@@ -22,11 +22,6 @@
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
namespace Paint
|
||||
{
|
||||
class Painter;
|
||||
}
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
interface IUiContext;
|
||||
@@ -75,9 +70,6 @@ namespace OpenRCT2
|
||||
#pragma GCC diagnostic ignored "-Wsuggest-final-types"
|
||||
class X8DrawingEngine : public IDrawingEngine
|
||||
{
|
||||
private:
|
||||
Paint::Painter * _painter = nullptr;
|
||||
|
||||
protected:
|
||||
uint32 _width = 0;
|
||||
uint32 _height = 0;
|
||||
@@ -105,7 +97,10 @@ namespace OpenRCT2
|
||||
void SetPalette(const rct_palette_entry * palette) override;
|
||||
void SetUncappedFrameRate(bool uncapped) override;
|
||||
void Invalidate(sint32 left, sint32 top, sint32 right, sint32 bottom) override;
|
||||
void Draw() override;
|
||||
void BeginDraw() override;
|
||||
void EndDraw() override;
|
||||
void PaintWindows() override;
|
||||
void PaintRain() override;
|
||||
void CopyRect(sint32 x, sint32 y, sint32 width, sint32 height, sint32 dx, sint32 dy) override;
|
||||
sint32 Screenshot() override;
|
||||
IDrawingContext * GetDrawingContext(rct_drawpixelinfo * dpi) override;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#pragma endregion
|
||||
|
||||
#include "../config/Config.h"
|
||||
#include "../drawing/IDrawingEngine.h"
|
||||
#include "../title/TitleScreen.h"
|
||||
#include "../ui/UiContext.h"
|
||||
#include "Painter.h"
|
||||
@@ -30,6 +31,7 @@ extern "C"
|
||||
}
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
using namespace OpenRCT2::Paint;
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
@@ -38,28 +40,36 @@ Painter::Painter(IUiContext * uiContext)
|
||||
{
|
||||
}
|
||||
|
||||
void Painter::Paint(rct_drawpixelinfo * dpi)
|
||||
void Painter::Paint(IDrawingEngine * de)
|
||||
{
|
||||
auto dpi = de->GetDrawingPixelInfo();
|
||||
if (gIntroState != INTRO_STATE_NONE)
|
||||
{
|
||||
return;
|
||||
intro_draw(dpi);
|
||||
}
|
||||
|
||||
update_palette_effects();
|
||||
|
||||
chat_draw(dpi);
|
||||
console_draw(dpi);
|
||||
|
||||
if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !gTitleHideVersionInfo)
|
||||
else
|
||||
{
|
||||
DrawOpenRCT2(dpi, 0, _uiContext->GetHeight() - 20);
|
||||
de->PaintWindows();
|
||||
|
||||
update_palette_effects();
|
||||
chat_draw(dpi);
|
||||
console_draw(dpi);
|
||||
|
||||
if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !gTitleHideVersionInfo)
|
||||
{
|
||||
DrawOpenRCT2(dpi, 0, _uiContext->GetHeight() - 20);
|
||||
}
|
||||
|
||||
gfx_draw_pickedup_peep(dpi);
|
||||
gfx_invalidate_pickedup_peep();
|
||||
|
||||
de->PaintRain();
|
||||
}
|
||||
|
||||
if (gConfigGeneral.show_fps)
|
||||
{
|
||||
PaintFPS(dpi);
|
||||
}
|
||||
|
||||
gCurrentDrawCount++;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ struct rct_drawpixelinfo;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
namespace Drawing
|
||||
{
|
||||
interface IDrawingEngine;
|
||||
}
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
interface IUiContext;
|
||||
@@ -39,7 +44,7 @@ namespace OpenRCT2
|
||||
|
||||
public:
|
||||
Painter(Ui::IUiContext * uiContext);
|
||||
void Paint(rct_drawpixelinfo * dpi);
|
||||
void Paint(Drawing::IDrawingEngine * de);
|
||||
|
||||
private:
|
||||
void PaintFPS(rct_drawpixelinfo * dpi);
|
||||
|
||||
Reference in New Issue
Block a user