From 3e285d22615873686b86b406c97f1e3084044086 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 19:02:14 +0200 Subject: [PATCH] - moved renderstyle and colortables code to 'common'. --- src/CMakeLists.txt | 3 +- src/{r_data => common/engine}/renderstyle.cpp | 6 - src/{r_data => common/engine}/renderstyle.h | 0 src/common/engine/v_colortables.cpp | 103 ++++++++++++++++++ src/{r_data => common/engine}/v_colortables.h | 5 + src/g_statusbar/sbar.h | 2 +- src/gamedata/decallib.h | 2 +- src/gamedata/textures/textures.h | 8 +- src/playsim/actor.h | 2 +- src/playsim/p_pspr.h | 2 +- src/r_data/v_palette.cpp | 62 ----------- src/rendering/2d/v_2ddrawer.h | 2 +- .../hwrenderer/scene/hw_drawstructs.h | 2 +- .../polyrenderer/drawers/screen_triangle.h | 2 +- src/rendering/v_video.h | 4 +- src/rendering/vulkan/renderer/vk_renderpass.h | 2 +- src/rendering/vulkan/system/vk_builders.cpp | 2 +- src/serializer.cpp | 6 + 18 files changed, 128 insertions(+), 87 deletions(-) rename src/{r_data => common/engine}/renderstyle.cpp (96%) rename src/{r_data => common/engine}/renderstyle.h (100%) create mode 100644 src/common/engine/v_colortables.cpp rename src/{r_data => common/engine}/v_colortables.h (95%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1756109a..b3951da9c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1060,7 +1060,6 @@ set (PCH_SOURCES r_data/sprites.cpp r_data/portalgroups.cpp r_data/voxels.cpp - r_data/renderstyle.cpp r_data/r_canvastexture.cpp r_data/r_interpolate.cpp r_data/r_vanillatrans.cpp @@ -1149,6 +1148,8 @@ set (PCH_SOURCES common/engine/palettecontainer.cpp common/engine/stringtable.cpp common/engine/i_interface.cpp + common/engine/renderstyle.cpp + common/engine/v_colortables.cpp utility/m_random.cpp utility/nodebuilder/nodebuild.cpp diff --git a/src/r_data/renderstyle.cpp b/src/common/engine/renderstyle.cpp similarity index 96% rename from src/r_data/renderstyle.cpp rename to src/common/engine/renderstyle.cpp index 80bc00539..1a29292ea 100644 --- a/src/r_data/renderstyle.cpp +++ b/src/common/engine/renderstyle.cpp @@ -35,7 +35,6 @@ #include "templates.h" #include "renderstyle.h" #include "c_cvars.h" -#include "serializer.h" CVAR (Bool, r_drawtrans, true, 0) CVAR (Int, r_drawfuzz, 1, CVAR_ARCHIVE) @@ -158,8 +157,3 @@ void FRenderStyle::CheckFuzz() BlendOp = STYLEOP_Fuzz; } } - -FSerializer &Serialize(FSerializer &arc, const char *key, FRenderStyle &style, FRenderStyle *def) -{ - return arc.Array(key, &style.BlendOp, def ? &def->BlendOp : nullptr, 4); -} diff --git a/src/r_data/renderstyle.h b/src/common/engine/renderstyle.h similarity index 100% rename from src/r_data/renderstyle.h rename to src/common/engine/renderstyle.h diff --git a/src/common/engine/v_colortables.cpp b/src/common/engine/v_colortables.cpp new file mode 100644 index 000000000..36849862b --- /dev/null +++ b/src/common/engine/v_colortables.cpp @@ -0,0 +1,103 @@ +/* +** v_colortables.cpp +** Various color blending tables +** +**--------------------------------------------------------------------------- +** Copyright 1998-2006 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + + +#include "v_colortables.h" +#include "colormatcher.h" + +uint32_t Col2RGB8[65][256]; +uint32_t *Col2RGB8_LessPrecision[65]; +uint32_t Col2RGB8_Inverse[65][256]; +uint32_t Col2RGB8_2[63][256]; // this array's second dimension is called up by pointer as Col2RGB8_LessPrecision[] elsewhere. +ColorTable32k RGB32k; +ColorTable256k RGB256k; + + + +//========================================================================== +// +// BuildTransTable +// +// Build the tables necessary for blending - used by software rendering and +// texture composition +// +//========================================================================== + +void BuildTransTable (const PalEntry *palette) +{ + int r, g, b; + + // create the RGB555 lookup table + for (r = 0; r < 32; r++) + for (g = 0; g < 32; g++) + for (b = 0; b < 32; b++) + RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2)); + // create the RGB666 lookup table + for (r = 0; r < 64; r++) + for (g = 0; g < 64; g++) + for (b = 0; b < 64; b++) + RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4)); + + int x, y; + + // create the swizzled palette + for (x = 0; x < 65; x++) + for (y = 0; y < 256; y++) + Col2RGB8[x][y] = (((palette[y].r*x)>>4)<<20) | + ((palette[y].g*x)>>4) | + (((palette[y].b*x)>>4)<<10); + + // create the swizzled palette with the lsb of red and blue forced to 0 + // (for green, a 1 is okay since it never gets added into) + for (x = 1; x < 64; x++) + { + Col2RGB8_LessPrecision[x] = Col2RGB8_2[x-1]; + for (y = 0; y < 256; y++) + { + Col2RGB8_2[x-1][y] = Col2RGB8[x][y] & 0x3feffbff; + } + } + Col2RGB8_LessPrecision[0] = Col2RGB8[0]; + Col2RGB8_LessPrecision[64] = Col2RGB8[64]; + + // create the inverse swizzled palette + for (x = 0; x < 65; x++) + for (y = 0; y < 256; y++) + { + Col2RGB8_Inverse[x][y] = (((((255-palette[y].r)*x)>>4)<<20) | + (((255-palette[y].g)*x)>>4) | + ((((255-palette[y].b)*x)>>4)<<10)) & 0x3feffbff; + } +} + diff --git a/src/r_data/v_colortables.h b/src/common/engine/v_colortables.h similarity index 95% rename from src/r_data/v_colortables.h rename to src/common/engine/v_colortables.h index 42135229b..3f237147f 100644 --- a/src/r_data/v_colortables.h +++ b/src/common/engine/v_colortables.h @@ -1,5 +1,8 @@ #pragma once +#include +#include "palentry.h" + // extracted from v_video.h because this caused circular dependencies between v_video.h and textures.h // Translucency tables @@ -50,3 +53,5 @@ extern uint32_t Col2RGB8_Inverse[65][256]; // ------10000000001000000000100000 = 0x40100400 >> 5 // --11111-----11111-----11111----- = 0x40100400 - (0x40100400 >> 5) aka "white" // --111111111111111111111111111111 = 0x3FFFFFFF + +void BuildTransTable (const PalEntry *palette); diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 350d13502..ee96bdd11 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -38,7 +38,7 @@ #include "dobject.h" #include "v_collection.h" #include "v_text.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" class player_t; struct FRemapTable; diff --git a/src/gamedata/decallib.h b/src/gamedata/decallib.h index 04c0ea0e6..3a6ede299 100644 --- a/src/gamedata/decallib.h +++ b/src/gamedata/decallib.h @@ -37,7 +37,7 @@ #include #include "doomtype.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" class FScanner; class FDecalTemplate; diff --git a/src/gamedata/textures/textures.h b/src/gamedata/textures/textures.h index 8f4b620ec..26b79d023 100644 --- a/src/gamedata/textures/textures.h +++ b/src/gamedata/textures/textures.h @@ -38,17 +38,11 @@ #include "basics.h" #include "vectors.h" #include "colormatcher.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include "textureid.h" #include #include "hwrenderer/textures/hw_texcontainer.h" -/* -#include "v_palette.h" -#include "r_data/v_colortables.h" -#include "r_data/r_translate.h" -*/ - // 15 because 0th texture is our texture #define MAX_CUSTOM_HW_SHADER_TEXTURES 15 diff --git a/src/playsim/actor.h b/src/playsim/actor.h index b022c5167..f992dd777 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -41,7 +41,7 @@ #include "doomdef.h" #include "textures/textures.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include "s_sound.h" #include "memarena.h" #include "g_level.h" diff --git a/src/playsim/p_pspr.h b/src/playsim/p_pspr.h index b807e4f09..f35bb7123 100644 --- a/src/playsim/p_pspr.h +++ b/src/playsim/p_pspr.h @@ -30,7 +30,7 @@ #ifndef __P_PSPR_H__ #define __P_PSPR_H__ -#include "r_data/renderstyle.h" +#include "renderstyle.h" // Basic data types. // Needs fixed point, and BAM angles. diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index f290f2a2c..800e0fab3 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -50,13 +50,6 @@ #include "g_levellocals.h" #include "m_png.h" -uint32_t Col2RGB8[65][256]; -uint32_t *Col2RGB8_LessPrecision[65]; -uint32_t Col2RGB8_Inverse[65][256]; -uint32_t Col2RGB8_2[63][256]; // this array's second dimension is called up by pointer as Col2RGB8_LessPrecision[] elsewhere. -ColorTable32k RGB32k; -ColorTable256k RGB256k; - /* Current color blending values */ int BlendR, BlendG, BlendB, BlendA; @@ -94,61 +87,6 @@ CCMD (bumpgamma) } -//========================================================================== -// -// BuildTransTable -// -// Build the tables necessary for blending -// -//========================================================================== - -static void BuildTransTable (const PalEntry *palette) -{ - int r, g, b; - - // create the RGB555 lookup table - for (r = 0; r < 32; r++) - for (g = 0; g < 32; g++) - for (b = 0; b < 32; b++) - RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2)); - // create the RGB666 lookup table - for (r = 0; r < 64; r++) - for (g = 0; g < 64; g++) - for (b = 0; b < 64; b++) - RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4)); - - int x, y; - - // create the swizzled palette - for (x = 0; x < 65; x++) - for (y = 0; y < 256; y++) - Col2RGB8[x][y] = (((palette[y].r*x)>>4)<<20) | - ((palette[y].g*x)>>4) | - (((palette[y].b*x)>>4)<<10); - - // create the swizzled palette with the lsb of red and blue forced to 0 - // (for green, a 1 is okay since it never gets added into) - for (x = 1; x < 64; x++) - { - Col2RGB8_LessPrecision[x] = Col2RGB8_2[x-1]; - for (y = 0; y < 256; y++) - { - Col2RGB8_2[x-1][y] = Col2RGB8[x][y] & 0x3feffbff; - } - } - Col2RGB8_LessPrecision[0] = Col2RGB8[0]; - Col2RGB8_LessPrecision[64] = Col2RGB8[64]; - - // create the inverse swizzled palette - for (x = 0; x < 65; x++) - for (y = 0; y < 256; y++) - { - Col2RGB8_Inverse[x][y] = (((((255-palette[y].r)*x)>>4)<<20) | - (((255-palette[y].g)*x)>>4) | - ((((255-palette[y].b)*x)>>4)<<10)) & 0x3feffbff; - } -} - void InitPalette () { diff --git a/src/rendering/2d/v_2ddrawer.h b/src/rendering/2d/v_2ddrawer.h index 53ea596c9..f669656c1 100644 --- a/src/rendering/2d/v_2ddrawer.h +++ b/src/rendering/2d/v_2ddrawer.h @@ -4,7 +4,7 @@ #include "tarray.h" #include "textures.h" #include "v_palette.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include "r_data/colormaps.h" struct DrawParms; diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 4c9730844..72ab1d04f 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -5,7 +5,7 @@ // //========================================================================== #include "r_defs.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include "textures/textures.h" #include "r_data/colormaps.h" diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.h b/src/rendering/polyrenderer/drawers/screen_triangle.h index 40674ab14..7ccd64400 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.h +++ b/src/rendering/polyrenderer/drawers/screen_triangle.h @@ -24,7 +24,7 @@ #include #include -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include "rendering/swrenderer/drawers/r_draw.h" class FString; diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index f72a65c7a..6ffa0c2e2 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -41,9 +41,9 @@ #include "doomdef.h" #include "m_png.h" #include "dobject.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include "c_cvars.h" -#include "r_data/v_colortables.h" +#include "v_colortables.h" #include "v_2ddrawer.h" #include "hwrenderer/dynlights/hw_shadowmap.h" diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/rendering/vulkan/renderer/vk_renderpass.h index 47b21769a..37fd05ed6 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.h +++ b/src/rendering/vulkan/renderer/vk_renderpass.h @@ -2,7 +2,7 @@ #pragma once #include "vulkan/system/vk_objects.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include "hwrenderer/data/buffers.h" #include "hwrenderer/scene/hw_renderstate.h" #include diff --git a/src/rendering/vulkan/system/vk_builders.cpp b/src/rendering/vulkan/system/vk_builders.cpp index 981aba053..cd7aeeae8 100644 --- a/src/rendering/vulkan/system/vk_builders.cpp +++ b/src/rendering/vulkan/system/vk_builders.cpp @@ -22,7 +22,7 @@ #include "vk_builders.h" #include "engineerrors.h" -#include "r_data/renderstyle.h" +#include "renderstyle.h" #include #include diff --git a/src/serializer.cpp b/src/serializer.cpp index ed1eb5266..bca340231 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -2302,3 +2302,9 @@ FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &value, N } return arc; } + +#include "renderstyle.h" +FSerializer& Serialize(FSerializer& arc, const char* key, FRenderStyle& style, FRenderStyle* def) +{ + return arc.Array(key, &style.BlendOp, def ? &def->BlendOp : nullptr, 4); +}