1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Move SDL part of lightfx blend to drawing engine

This commit is contained in:
Ted John
2017-06-10 18:00:15 +01:00
parent 90aad2e2ec
commit 5bb48f3539
3 changed files with 28 additions and 26 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -19,7 +19,6 @@
#ifdef __ENABLE_LIGHTFX__
#include <SDL.h>
#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,