mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-04 13:42:55 +01:00
Merge pull request #5587 from IntelOrca/refactor/nosdl/lightfx
Remove SDL from drawing engine and lightfx
This commit is contained in:
@@ -102,7 +102,7 @@ public:
|
||||
}
|
||||
|
||||
// Window
|
||||
SDL_Window * GetWindow() override
|
||||
void * GetWindow() override
|
||||
{
|
||||
return _window;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
explicit HardwareDisplayDrawingEngine(IUiContext * uiContext)
|
||||
: _uiContext(uiContext)
|
||||
{
|
||||
UNUSED(_uiContext); // Will be used in due course to retrieve window information
|
||||
_window = (SDL_Window *)_uiContext->GetWindow();
|
||||
}
|
||||
|
||||
~HardwareDisplayDrawingEngine() override
|
||||
@@ -65,10 +65,9 @@ public:
|
||||
SDL_DestroyRenderer(_sdlRenderer);
|
||||
}
|
||||
|
||||
void Initialise(SDL_Window * window) override
|
||||
void Initialise() override
|
||||
{
|
||||
_window = window;
|
||||
_sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
_sdlRenderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
}
|
||||
|
||||
void Resize(uint32 width, uint32 height) override
|
||||
@@ -111,10 +110,11 @@ public:
|
||||
#ifdef __ENABLE_LIGHTFX__
|
||||
if (gConfigGeneral.enable_light_fx)
|
||||
{
|
||||
const SDL_Color * lightPalette = lightfx_get_palette();
|
||||
auto lightPalette = lightfx_get_palette();
|
||||
for (sint32 i = 0; i < 256; i++)
|
||||
{
|
||||
_lightPaletteHWMapped[i] = SDL_MapRGBA(_screenTextureFormat, lightPalette[i].r, lightPalette[i].g, lightPalette[i].b, lightPalette[i].a);
|
||||
auto src = &lightPalette->entries[i];
|
||||
_lightPaletteHWMapped[i] = SDL_MapRGBA(_screenTextureFormat, src->red, src->green, src->blue, src->alpha);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -133,7 +133,13 @@ private:
|
||||
#ifdef __ENABLE_LIGHTFX__
|
||||
if (gConfigGeneral.enable_light_fx)
|
||||
{
|
||||
lightfx_render_to_texture(_screenTexture, _bits, _width, _height, _paletteHWMapped, _lightPaletteHWMapped);
|
||||
void * pixels;
|
||||
sint32 pitch;
|
||||
if (SDL_LockTexture(_screenTexture, NULL, &pixels, &pitch) == 0)
|
||||
{
|
||||
lightfx_render_to_texture(pixels, pitch, _bits, _width, _height, _paletteHWMapped, _lightPaletteHWMapped);
|
||||
SDL_UnlockTexture(_screenTexture);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
explicit SoftwareDrawingEngine(IUiContext * uiContext)
|
||||
: _uiContext(uiContext)
|
||||
{
|
||||
UNUSED(_uiContext); // Will be used in due course to retrieve window information
|
||||
_window = (SDL_Window *)_uiContext->GetWindow();
|
||||
}
|
||||
|
||||
~SoftwareDrawingEngine() override
|
||||
@@ -56,9 +56,8 @@ public:
|
||||
SDL_FreePalette(_palette);
|
||||
}
|
||||
|
||||
void Initialise(SDL_Window * window) override
|
||||
void Initialise() override
|
||||
{
|
||||
_window = window;
|
||||
}
|
||||
|
||||
void Resize(uint32 width, uint32 height) override
|
||||
|
||||
@@ -250,7 +250,7 @@ public:
|
||||
OpenGLDrawingEngine(IUiContext * uiContext)
|
||||
: _uiContext(uiContext)
|
||||
{
|
||||
UNUSED(_uiContext); // Will be used in due course to retrieve window information
|
||||
_window = (SDL_Window *)_uiContext->GetWindow();
|
||||
_drawingContext = new OpenGLDrawingContext(this);
|
||||
}
|
||||
|
||||
@@ -266,10 +266,8 @@ public:
|
||||
SDL_GL_DeleteContext(_context);
|
||||
}
|
||||
|
||||
void Initialise(SDL_Window * window) override
|
||||
void Initialise() override
|
||||
{
|
||||
_window = window;
|
||||
|
||||
OpenGLVersion requiredVersion = OPENGL_MINIMUM_REQUIRED_VERSION;
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, requiredVersion.Major);
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRCT2 { namespace Drawing
|
||||
{
|
||||
virtual ~IDrawingEngine() { }
|
||||
|
||||
virtual void Initialise(SDL_Window * window) abstract;
|
||||
virtual void Initialise() abstract;
|
||||
virtual void Resize(uint32 width, uint32 height) abstract;
|
||||
virtual void SetPalette(const rct_palette_entry * colours) abstract;
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ extern "C"
|
||||
{
|
||||
try
|
||||
{
|
||||
drawingEngine->Initialise(uiContext->GetWindow());
|
||||
drawingEngine->Initialise();
|
||||
drawingEngine->SetUncappedFrameRate(gConfigGeneral.uncap_fps == 1);
|
||||
_drawingEngine = drawingEngine;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ X8DrawingEngine::~X8DrawingEngine()
|
||||
delete [] _bits;
|
||||
}
|
||||
|
||||
void X8DrawingEngine::Initialise(SDL_Window * window)
|
||||
void X8DrawingEngine::Initialise()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace OpenRCT2 { namespace Drawing
|
||||
explicit X8DrawingEngine();
|
||||
~X8DrawingEngine() override;
|
||||
|
||||
void Initialise(SDL_Window * window) override;
|
||||
void Initialise() override;
|
||||
void Resize(uint32 width, uint32 height) override;
|
||||
void SetPalette(const rct_palette_entry * palette) override;
|
||||
void SetUncappedFrameRate(bool uncapped) override;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#ifdef __ENABLE_LIGHTFX__
|
||||
|
||||
#include "../common.h"
|
||||
#include <SDL.h>
|
||||
#include "../game.h"
|
||||
#include "../rct2.h"
|
||||
#include "../interface/viewport.h"
|
||||
@@ -72,7 +71,7 @@ static uint8 _current_view_rotation_back = 0;
|
||||
static uint8 _current_view_zoom_back = 0;
|
||||
static uint8 _current_view_zoom_back_delay = 0;
|
||||
|
||||
static SDL_Color gPalette_light[256];
|
||||
static rct_palette gPalette_light;
|
||||
|
||||
static uint8 soft_light(uint8 a, uint8 b);
|
||||
static uint8 lerp(uint8 a, uint8 b, float t);
|
||||
@@ -610,9 +609,9 @@ void* lightfx_get_front_buffer()
|
||||
return _light_rendered_buffer_front;
|
||||
}
|
||||
|
||||
const SDL_Color * lightfx_get_palette()
|
||||
const rct_palette * lightfx_get_palette()
|
||||
{
|
||||
return gPalette_light;
|
||||
return &gPalette_light;
|
||||
}
|
||||
|
||||
void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 x, sint16 y, uint16 z, uint8 lightType)
|
||||
@@ -947,9 +946,11 @@ void lightfx_apply_palette_filter(uint8 i, uint8 *r, uint8 *g, uint8 *b)
|
||||
*r = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(*r) * reduceColourNat * natLightR + envFog * fogR + addLightNatR))));
|
||||
*g = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(*g) * reduceColourNat * natLightG + envFog * fogG + addLightNatG))));
|
||||
*b = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(*b) * reduceColourNat * natLightB + envFog * fogB + addLightNatB))));
|
||||
gPalette_light[i].r = (uint8)(min(0xFF, ((float)(*r) * reduceColourLit * boost + lightFog) * elecMultR));
|
||||
gPalette_light[i].g = (uint8)(min(0xFF, ((float)(*g) * reduceColourLit * boost + lightFog) * elecMultG));
|
||||
gPalette_light[i].b = (uint8)(min(0xFF, ((float)(*b) * reduceColourLit * boost + lightFog) * elecMultB));
|
||||
|
||||
rct_palette_entry * dstEntry = &gPalette_light.entries[i];
|
||||
dstEntry->red = (uint8)(min(0xFF, ((float)(*r) * reduceColourLit * boost + lightFog) * elecMultR));
|
||||
dstEntry->green = (uint8)(min(0xFF, ((float)(*g) * reduceColourLit * boost + lightFog) * elecMultG));
|
||||
dstEntry->blue = (uint8)(min(0xFF, ((float)(*b) * reduceColourLit * boost + lightFog) * elecMultB));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -996,7 +997,8 @@ static uint8 mix_light(uint32 a, uint32 b, uint32 intensity)
|
||||
}
|
||||
|
||||
void lightfx_render_to_texture(
|
||||
SDL_Texture * texture,
|
||||
void * dstPixels,
|
||||
uint32 dstPitch,
|
||||
uint8 * bits,
|
||||
uint32 width,
|
||||
uint32 height,
|
||||
@@ -1013,31 +1015,26 @@ void lightfx_render_to_texture(
|
||||
return;
|
||||
}
|
||||
|
||||
void * pixels;
|
||||
sint32 pitch;
|
||||
if (SDL_LockTexture(texture, NULL, &pixels, &pitch) == 0) {
|
||||
for (uint32 y = 0; y < height; y++) {
|
||||
uintptr_t dstOffset = (uintptr_t)(y * pitch);
|
||||
uint32 * dst = (uint32 *)((uintptr_t)pixels + dstOffset);
|
||||
for (uint32 x = 0; x < width; x++) {
|
||||
uint8 * src = &bits[y * width + x];
|
||||
uint32 darkColour = palette[*src];
|
||||
uint32 lightColour = lightPalette[*src];
|
||||
uint8 lightIntensity = lightBits[y * width + x];
|
||||
for (uint32 y = 0; y < height; y++) {
|
||||
uintptr_t dstOffset = (uintptr_t)(y * dstPitch);
|
||||
uint32 * dst = (uint32 *)((uintptr_t)dstPixels + dstOffset);
|
||||
for (uint32 x = 0; x < width; x++) {
|
||||
uint8 * src = &bits[y * width + x];
|
||||
uint32 darkColour = palette[*src];
|
||||
uint32 lightColour = lightPalette[*src];
|
||||
uint8 lightIntensity = lightBits[y * width + x];
|
||||
|
||||
uint32 colour = 0;
|
||||
if (lightIntensity == 0) {
|
||||
colour = darkColour;
|
||||
} else {
|
||||
colour |= mix_light((darkColour >> 0) & 0xFF, (lightColour >> 0) & 0xFF, lightIntensity);
|
||||
colour |= mix_light((darkColour >> 8) & 0xFF, (lightColour >> 8) & 0xFF, lightIntensity) << 8;
|
||||
colour |= mix_light((darkColour >> 16) & 0xFF, (lightColour >> 16) & 0xFF, lightIntensity) << 16;
|
||||
colour |= mix_light((darkColour >> 24) & 0xFF, (lightColour >> 24) & 0xFF, lightIntensity) << 24;
|
||||
}
|
||||
*dst++ = colour;
|
||||
uint32 colour = 0;
|
||||
if (lightIntensity == 0) {
|
||||
colour = darkColour;
|
||||
} else {
|
||||
colour |= mix_light((darkColour >> 0) & 0xFF, (lightColour >> 0) & 0xFF, lightIntensity);
|
||||
colour |= mix_light((darkColour >> 8) & 0xFF, (lightColour >> 8) & 0xFF, lightIntensity) << 8;
|
||||
colour |= mix_light((darkColour >> 16) & 0xFF, (lightColour >> 16) & 0xFF, lightIntensity) << 16;
|
||||
colour |= mix_light((darkColour >> 24) & 0xFF, (lightColour >> 24) & 0xFF, lightIntensity) << 24;
|
||||
}
|
||||
*dst++ = colour;
|
||||
}
|
||||
SDL_UnlockTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#ifdef __ENABLE_LIGHTFX__
|
||||
|
||||
#include <SDL.h>
|
||||
#include "../common.h"
|
||||
#include "drawing.h"
|
||||
|
||||
@@ -55,7 +54,7 @@ void lightfx_render_lights_to_frontbuffer();
|
||||
void lightfx_update_viewport_settings();
|
||||
|
||||
void* lightfx_get_front_buffer();
|
||||
const SDL_Color * lightfx_get_palette();
|
||||
const rct_palette * lightfx_get_palette();
|
||||
|
||||
void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 x, sint16 y, uint16 z, uint8 lightType);
|
||||
|
||||
@@ -67,7 +66,8 @@ uint32 lightfx_get_light_polution();
|
||||
|
||||
void lightfx_apply_palette_filter(uint8 i, uint8 *r, uint8 *g, uint8 *b);
|
||||
void lightfx_render_to_texture(
|
||||
struct SDL_Texture * texture,
|
||||
void * dstPixels,
|
||||
uint32 dstPitch,
|
||||
uint8 * bits,
|
||||
uint32 width,
|
||||
uint32 height,
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRCT2 { namespace Ui
|
||||
{
|
||||
void CreateWindow() override { }
|
||||
void CloseWindow() override { }
|
||||
SDL_Window * GetWindow() override { return nullptr; }
|
||||
void * GetWindow() override { return nullptr; }
|
||||
sint32 GetWidth() override { return 0; }
|
||||
sint32 GetHeight() override { return 0; }
|
||||
void SetFullscreenMode(FULLSCREEN_MODE mode) override { }
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include "../Context.h"
|
||||
#include "../interface/Cursors.h"
|
||||
|
||||
struct SDL_Window;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
namespace Drawing
|
||||
@@ -92,9 +90,9 @@ namespace OpenRCT2
|
||||
virtual ~IUiContext() = default;
|
||||
|
||||
// Window
|
||||
virtual void CreateWindow() abstract;
|
||||
virtual void CloseWindow() abstract;
|
||||
virtual SDL_Window * GetWindow() abstract;
|
||||
virtual void CreateWindow() abstract;
|
||||
virtual void CloseWindow() abstract;
|
||||
virtual void * GetWindow() abstract;
|
||||
virtual sint32 GetWidth() abstract;
|
||||
virtual sint32 GetHeight() abstract;
|
||||
virtual void SetFullscreenMode(FULLSCREEN_MODE mode) abstract;
|
||||
|
||||
Reference in New Issue
Block a user