From 5bb48f35398a7badd9af657a98272a7a1965ffdf Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 10 Jun 2017 18:00:15 +0100 Subject: [PATCH] Move SDL part of lightfx blend to drawing engine --- .../engines/HardwareDisplayDrawingEngine.cpp | 8 +++- src/openrct2/drawing/lightfx.c | 42 +++++++++---------- src/openrct2/drawing/lightfx.h | 4 +- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp index 748787a336..c5ef32b2f5 100644 --- a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp @@ -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 diff --git a/src/openrct2/drawing/lightfx.c b/src/openrct2/drawing/lightfx.c index be18c340e7..6a23debbe9 100644 --- a/src/openrct2/drawing/lightfx.c +++ b/src/openrct2/drawing/lightfx.c @@ -997,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, @@ -1014,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); } } diff --git a/src/openrct2/drawing/lightfx.h b/src/openrct2/drawing/lightfx.h index 1e2a0a53e4..bf9ef37701 100644 --- a/src/openrct2/drawing/lightfx.h +++ b/src/openrct2/drawing/lightfx.h @@ -19,7 +19,6 @@ #ifdef __ENABLE_LIGHTFX__ -#include #include "../common.h" #include "drawing.h" @@ -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,