From 77a388e90893b1810ce43aaf1c565938f642ed9c Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 11 Mar 2017 18:31:53 +0100 Subject: [PATCH] Fix default palette for voxel BGRA slab data and support translated 8-bit slab data in true color mode --- src/r_data/voxels.cpp | 10 ++++++---- src/swrenderer/things/r_voxel.cpp | 3 +-- src/swrenderer/viewport/r_spritedrawer.h | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/r_data/voxels.cpp b/src/r_data/voxels.cpp index 70975c7a4..3c6f8b1f9 100644 --- a/src/r_data/voxels.cpp +++ b/src/r_data/voxels.cpp @@ -401,7 +401,9 @@ FVoxel::~FVoxel() void FVoxel::CreateBgraSlabData() { - assert(Palette != NULL); + uint8_t *palette = Palette; + if (palette == nullptr) + palette = (uint8_t *)GPalette.BaseColors; for (int i = 0; i < NumMips; ++i) { @@ -424,9 +426,9 @@ void FVoxel::CreateBgraSlabData() { int colorIndex = src->col[j]; - uint32_t red = (Palette[colorIndex * 3 + 0] << 2) | (Palette[colorIndex * 3 + 0] >> 4); - uint32_t green = (Palette[colorIndex * 3 + 1] << 2) | (Palette[colorIndex * 3 + 1] >> 4); - uint32_t blue = (Palette[colorIndex * 3 + 2] << 2) | (Palette[colorIndex * 3 + 2] >> 4); + uint32_t red = (palette[colorIndex * 3 + 0] << 2) | (palette[colorIndex * 3 + 0] >> 4); + uint32_t green = (palette[colorIndex * 3 + 1] << 2) | (palette[colorIndex * 3 + 1] >> 4); + uint32_t blue = (palette[colorIndex * 3 + 2] << 2) | (palette[colorIndex * 3 + 2] >> 4); dest->col[j] = 0xff000000 | (red << 16) | (green << 8) | blue; } diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index 597aa7a84..3d27ac903 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -532,8 +532,7 @@ namespace swrenderer } const uint8_t *columnColors = col; - bool bgra = viewport->RenderTarget->IsBgra(); - if (bgra) + if (!drawerargs.DrawerNeedsPalInput() && viewport->RenderTarget->IsBgra()) { // The true color slab data array is identical, except its using uint32_t instead of uint8. // diff --git a/src/swrenderer/viewport/r_spritedrawer.h b/src/swrenderer/viewport/r_spritedrawer.h index 31d3861d9..eaee87805 100644 --- a/src/swrenderer/viewport/r_spritedrawer.h +++ b/src/swrenderer/viewport/r_spritedrawer.h @@ -53,6 +53,8 @@ namespace swrenderer uint32_t DynamicLight() const { return dynlightcolor; } + bool DrawerNeedsPalInput() const { return drawer_needs_pal_input; } + private: bool SetBlendFunc(int op, fixed_t fglevel, fixed_t bglevel, int flags); static fixed_t GetAlpha(int type, fixed_t alpha);