mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
hwr2: Extract BlendMode enum from twodee
This enum is usable across multiple parts of hwr2 so it would be easier to just keep it separate.
This commit is contained in:
parent
20002f83c4
commit
8d390c58d4
7 changed files with 72 additions and 50 deletions
|
|
@ -1,4 +1,5 @@
|
|||
target_sources(SRB2SDL2 PRIVATE
|
||||
blendmode.hpp
|
||||
pass_blit_postimg_screens.cpp
|
||||
pass_blit_postimg_screens.hpp
|
||||
pass_blit_rect.cpp
|
||||
|
|
|
|||
28
src/hwr2/blendmode.hpp
Normal file
28
src/hwr2/blendmode.hpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// SONIC ROBO BLAST 2
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2023 by Ronald "Eidolon" Kinard
|
||||
//
|
||||
// This program is free software distributed under the
|
||||
// terms of the GNU General Public License, version 2.
|
||||
// See the 'LICENSE' file for more details.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __SRB2_HWR2_BLENDMODE_HPP__
|
||||
#define __SRB2_HWR2_BLENDMODE_HPP__
|
||||
|
||||
namespace srb2::hwr2
|
||||
{
|
||||
|
||||
enum class BlendMode
|
||||
{
|
||||
kAlphaTransparent,
|
||||
kModulate,
|
||||
kAdditive,
|
||||
kSubtractive,
|
||||
kReverseSubtractive,
|
||||
kInvertDest
|
||||
};
|
||||
|
||||
} // namespace srb2::hwr2
|
||||
|
||||
#endif // __SRB2_HWR2_BLENDMODE_HPP__
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include <stb_rect_pack.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include "blendmode.hpp"
|
||||
#include "../r_patch.h"
|
||||
#include "../v_video.h"
|
||||
#include "../z_zone.h"
|
||||
|
|
@ -61,7 +62,7 @@ static PipelineDesc make_pipeline_desc(TwodeePipelineKey key)
|
|||
BlendDesc blend_desc;
|
||||
switch (key.blend)
|
||||
{
|
||||
case Draw2dBlend::kAlphaTransparent:
|
||||
case BlendMode::kAlphaTransparent:
|
||||
blend_desc.source_factor_color = BlendFactor::kSourceAlpha;
|
||||
blend_desc.dest_factor_color = BlendFactor::kOneMinusSourceAlpha;
|
||||
blend_desc.color_function = BlendFunction::kAdd;
|
||||
|
|
@ -69,7 +70,7 @@ static PipelineDesc make_pipeline_desc(TwodeePipelineKey key)
|
|||
blend_desc.dest_factor_alpha = BlendFactor::kOneMinusSourceAlpha;
|
||||
blend_desc.alpha_function = BlendFunction::kAdd;
|
||||
break;
|
||||
case Draw2dBlend::kModulate:
|
||||
case BlendMode::kModulate:
|
||||
blend_desc.source_factor_color = BlendFactor::kDest;
|
||||
blend_desc.dest_factor_color = BlendFactor::kZero;
|
||||
blend_desc.color_function = BlendFunction::kAdd;
|
||||
|
|
@ -77,7 +78,7 @@ static PipelineDesc make_pipeline_desc(TwodeePipelineKey key)
|
|||
blend_desc.dest_factor_alpha = BlendFactor::kZero;
|
||||
blend_desc.alpha_function = BlendFunction::kAdd;
|
||||
break;
|
||||
case Draw2dBlend::kAdditive:
|
||||
case BlendMode::kAdditive:
|
||||
blend_desc.source_factor_color = BlendFactor::kSourceAlpha;
|
||||
blend_desc.dest_factor_color = BlendFactor::kOne;
|
||||
blend_desc.color_function = BlendFunction::kAdd;
|
||||
|
|
@ -85,7 +86,7 @@ static PipelineDesc make_pipeline_desc(TwodeePipelineKey key)
|
|||
blend_desc.dest_factor_alpha = BlendFactor::kOneMinusSourceAlpha;
|
||||
blend_desc.alpha_function = BlendFunction::kAdd;
|
||||
break;
|
||||
case Draw2dBlend::kSubtractive:
|
||||
case BlendMode::kSubtractive:
|
||||
blend_desc.source_factor_color = BlendFactor::kSourceAlpha;
|
||||
blend_desc.dest_factor_color = BlendFactor::kOne;
|
||||
blend_desc.color_function = BlendFunction::kSubtract;
|
||||
|
|
@ -93,7 +94,7 @@ static PipelineDesc make_pipeline_desc(TwodeePipelineKey key)
|
|||
blend_desc.dest_factor_alpha = BlendFactor::kOneMinusSourceAlpha;
|
||||
blend_desc.alpha_function = BlendFunction::kAdd;
|
||||
break;
|
||||
case Draw2dBlend::kReverseSubtractive:
|
||||
case BlendMode::kReverseSubtractive:
|
||||
blend_desc.source_factor_color = BlendFactor::kSourceAlpha;
|
||||
blend_desc.dest_factor_color = BlendFactor::kOne;
|
||||
blend_desc.color_function = BlendFunction::kReverseSubtract;
|
||||
|
|
@ -101,7 +102,7 @@ static PipelineDesc make_pipeline_desc(TwodeePipelineKey key)
|
|||
blend_desc.dest_factor_alpha = BlendFactor::kOneMinusSourceAlpha;
|
||||
blend_desc.alpha_function = BlendFunction::kAdd;
|
||||
break;
|
||||
case Draw2dBlend::kInvertDest:
|
||||
case BlendMode::kInvertDest:
|
||||
blend_desc.source_factor_color = BlendFactor::kOne;
|
||||
blend_desc.dest_factor_color = BlendFactor::kOne;
|
||||
blend_desc.color_function = BlendFunction::kSubtract;
|
||||
|
|
@ -248,18 +249,18 @@ void TwodeePass::prepass(Rhi& rhi)
|
|||
|
||||
if (data_->pipelines.size() == 0)
|
||||
{
|
||||
TwodeePipelineKey alpha_transparent_tris = {Draw2dBlend::kAlphaTransparent, false};
|
||||
TwodeePipelineKey modulate_tris = {Draw2dBlend::kModulate, false};
|
||||
TwodeePipelineKey additive_tris = {Draw2dBlend::kAdditive, false};
|
||||
TwodeePipelineKey subtractive_tris = {Draw2dBlend::kSubtractive, false};
|
||||
TwodeePipelineKey revsubtractive_tris = {Draw2dBlend::kReverseSubtractive, false};
|
||||
TwodeePipelineKey invertdest_tris = {Draw2dBlend::kInvertDest, false};
|
||||
TwodeePipelineKey alpha_transparent_lines = {Draw2dBlend::kAlphaTransparent, true};
|
||||
TwodeePipelineKey modulate_lines = {Draw2dBlend::kModulate, true};
|
||||
TwodeePipelineKey additive_lines = {Draw2dBlend::kAdditive, true};
|
||||
TwodeePipelineKey subtractive_lines = {Draw2dBlend::kSubtractive, true};
|
||||
TwodeePipelineKey revsubtractive_lines = {Draw2dBlend::kReverseSubtractive, true};
|
||||
TwodeePipelineKey invertdest_lines = {Draw2dBlend::kInvertDest, true};
|
||||
TwodeePipelineKey alpha_transparent_tris = {BlendMode::kAlphaTransparent, false};
|
||||
TwodeePipelineKey modulate_tris = {BlendMode::kModulate, false};
|
||||
TwodeePipelineKey additive_tris = {BlendMode::kAdditive, false};
|
||||
TwodeePipelineKey subtractive_tris = {BlendMode::kSubtractive, false};
|
||||
TwodeePipelineKey revsubtractive_tris = {BlendMode::kReverseSubtractive, false};
|
||||
TwodeePipelineKey invertdest_tris = {BlendMode::kInvertDest, false};
|
||||
TwodeePipelineKey alpha_transparent_lines = {BlendMode::kAlphaTransparent, true};
|
||||
TwodeePipelineKey modulate_lines = {BlendMode::kModulate, true};
|
||||
TwodeePipelineKey additive_lines = {BlendMode::kAdditive, true};
|
||||
TwodeePipelineKey subtractive_lines = {BlendMode::kSubtractive, true};
|
||||
TwodeePipelineKey revsubtractive_lines = {BlendMode::kReverseSubtractive, true};
|
||||
TwodeePipelineKey invertdest_lines = {BlendMode::kInvertDest, true};
|
||||
data_->pipelines.insert({alpha_transparent_tris, rhi.create_pipeline(make_pipeline_desc(alpha_transparent_tris))});
|
||||
data_->pipelines.insert({modulate_tris, rhi.create_pipeline(make_pipeline_desc(modulate_tris))});
|
||||
data_->pipelines.insert({additive_tris, rhi.create_pipeline(make_pipeline_desc(additive_tris))});
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ struct TwodeePassData;
|
|||
/// @brief Hash map key for caching pipelines
|
||||
struct TwodeePipelineKey
|
||||
{
|
||||
Draw2dBlend blend;
|
||||
BlendMode blend;
|
||||
bool lines;
|
||||
|
||||
bool operator==(const TwodeePipelineKey& r) const noexcept { return !(blend != r.blend || lines != r.lines); }
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ void Draw2dVerticesBuilder::done()
|
|||
list.cmds.push_back(tris_);
|
||||
}
|
||||
|
||||
Draw2dBlend srb2::hwr2::get_blend_mode(const Draw2dCmd& cmd) noexcept
|
||||
BlendMode srb2::hwr2::get_blend_mode(const Draw2dCmd& cmd) noexcept
|
||||
{
|
||||
auto visitor = srb2::Overload {
|
||||
[&](const Draw2dPatchQuad& cmd) { return cmd.blend; },
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <tcb/span.hpp>
|
||||
|
||||
#include "blendmode.hpp"
|
||||
#include "../cxxutil.hpp"
|
||||
#include "../doomtype.h"
|
||||
|
||||
|
|
@ -38,16 +39,6 @@ struct TwodeeVertex
|
|||
float a;
|
||||
};
|
||||
|
||||
enum class Draw2dBlend
|
||||
{
|
||||
kAlphaTransparent,
|
||||
kModulate,
|
||||
kAdditive,
|
||||
kSubtractive,
|
||||
kReverseSubtractive,
|
||||
kInvertDest
|
||||
};
|
||||
|
||||
struct Draw2dPatchQuad
|
||||
{
|
||||
std::size_t begin_index = 0;
|
||||
|
|
@ -56,7 +47,7 @@ struct Draw2dPatchQuad
|
|||
// A null patch ptr means no patch is drawn
|
||||
const patch_t* patch = nullptr;
|
||||
const uint8_t* colormap = nullptr;
|
||||
Draw2dBlend blend;
|
||||
BlendMode blend;
|
||||
float r = 0.f;
|
||||
float g = 0.f;
|
||||
float b = 0.f;
|
||||
|
|
@ -81,14 +72,14 @@ struct Draw2dVertices
|
|||
std::size_t begin_index = 0;
|
||||
std::size_t begin_element = 0;
|
||||
std::size_t elements = 0;
|
||||
Draw2dBlend blend = Draw2dBlend::kAlphaTransparent;
|
||||
BlendMode blend = BlendMode::kAlphaTransparent;
|
||||
lumpnum_t flat_lump = UINT32_MAX; // LUMPERROR but not loading w_wad.h from this header
|
||||
bool lines = false;
|
||||
};
|
||||
|
||||
using Draw2dCmd = std::variant<Draw2dPatchQuad, Draw2dVertices>;
|
||||
|
||||
Draw2dBlend get_blend_mode(const Draw2dCmd& cmd) noexcept;
|
||||
BlendMode get_blend_mode(const Draw2dCmd& cmd) noexcept;
|
||||
bool is_draw_lines(const Draw2dCmd& cmd) noexcept;
|
||||
std::size_t elements(const Draw2dCmd& cmd) noexcept;
|
||||
|
||||
|
|
@ -194,7 +185,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
Draw2dQuadBuilder& blend(Draw2dBlend blend)
|
||||
Draw2dQuadBuilder& blend(BlendMode blend)
|
||||
{
|
||||
quad_.blend = blend;
|
||||
return *this;
|
||||
|
|
@ -245,7 +236,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
Draw2dVerticesBuilder& blend(Draw2dBlend blend)
|
||||
Draw2dVerticesBuilder& blend(BlendMode blend)
|
||||
{
|
||||
tris_.blend = blend;
|
||||
return *this;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "m_misc.h"
|
||||
#include "m_random.h"
|
||||
#include "doomstat.h"
|
||||
#include "hwr2/blendmode.hpp"
|
||||
|
||||
#ifdef HWRENDER
|
||||
#include "hardware/hw_glob.h"
|
||||
|
|
@ -914,27 +915,27 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
|||
{
|
||||
falpha = (10 - alphalevel) / 10.f;
|
||||
}
|
||||
hwr2::Draw2dBlend blend = hwr2::Draw2dBlend::kAlphaTransparent;
|
||||
hwr2::BlendMode blend = hwr2::BlendMode::kAlphaTransparent;
|
||||
switch (blendmode)
|
||||
{
|
||||
case AST_MODULATE:
|
||||
blend = hwr2::Draw2dBlend::kModulate;
|
||||
blend = hwr2::BlendMode::kModulate;
|
||||
break;
|
||||
case AST_ADD:
|
||||
blend = hwr2::Draw2dBlend::kAdditive;
|
||||
blend = hwr2::BlendMode::kAdditive;
|
||||
break;
|
||||
|
||||
// Note: SRB2 has these blend modes flipped compared to GL and Vulkan.
|
||||
// SRB2's Subtract is Dst - Src. OpenGL is Src - Dst. And vice versa for reverse.
|
||||
// Twodee will use the GL definitions.
|
||||
case AST_SUBTRACT:
|
||||
blend = hwr2::Draw2dBlend::kReverseSubtractive;
|
||||
blend = hwr2::BlendMode::kReverseSubtractive;
|
||||
break;
|
||||
case AST_REVERSESUBTRACT:
|
||||
blend = hwr2::Draw2dBlend::kSubtractive;
|
||||
blend = hwr2::BlendMode::kSubtractive;
|
||||
break;
|
||||
default:
|
||||
blend = hwr2::Draw2dBlend::kAlphaTransparent;
|
||||
blend = hwr2::BlendMode::kAlphaTransparent;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1187,7 +1188,7 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
|
|||
float a = 0.5f; // alphalevel is unused in GL??
|
||||
g_2d.begin_quad()
|
||||
.rect(x, y, w, h)
|
||||
.blend(hwr2::Draw2dBlend::kAlphaTransparent)
|
||||
.blend(hwr2::BlendMode::kAlphaTransparent)
|
||||
.color(r, g, b, a)
|
||||
.done();
|
||||
}
|
||||
|
|
@ -1332,7 +1333,7 @@ void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, U
|
|||
float g;
|
||||
float b;
|
||||
float a;
|
||||
hwr2::Draw2dBlend blendmode;
|
||||
hwr2::BlendMode blendmode;
|
||||
|
||||
if (color & 0xFF00)
|
||||
{
|
||||
|
|
@ -1345,7 +1346,7 @@ void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, U
|
|||
b = std::clamp((fstrength - (2.f / 3.f)) * 3.f, 0.f, 1.f);
|
||||
a = 1;
|
||||
|
||||
blendmode = hwr2::Draw2dBlend::kReverseSubtractive;
|
||||
blendmode = hwr2::BlendMode::kReverseSubtractive;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1356,7 +1357,7 @@ void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, U
|
|||
g = bc.green / 255.f;
|
||||
b = bc.blue / 255.f;
|
||||
a = softwaretranstohwr[std::clamp(static_cast<int>(strength), 0, 10)] / 255.f;
|
||||
blendmode = hwr2::Draw2dBlend::kAlphaTransparent;
|
||||
blendmode = hwr2::BlendMode::kAlphaTransparent;
|
||||
}
|
||||
|
||||
g_2d.begin_quad()
|
||||
|
|
@ -1529,7 +1530,7 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength)
|
|||
float g;
|
||||
float b;
|
||||
float a;
|
||||
hwr2::Draw2dBlend blendmode;
|
||||
hwr2::BlendMode blendmode;
|
||||
|
||||
if (color & 0xFF00)
|
||||
{
|
||||
|
|
@ -1542,7 +1543,7 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength)
|
|||
b = std::clamp((fstrength - (2.f / 3.f)) * 3.f, 0.f, 1.f);
|
||||
a = 1;
|
||||
|
||||
blendmode = hwr2::Draw2dBlend::kReverseSubtractive;
|
||||
blendmode = hwr2::BlendMode::kReverseSubtractive;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1553,7 +1554,7 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength)
|
|||
g = bc.green / 255.f;
|
||||
b = bc.blue / 255.f;
|
||||
a = softwaretranstohwr[std::clamp(static_cast<int>(strength), 0, 10)] / 255.f;
|
||||
blendmode = hwr2::Draw2dBlend::kAlphaTransparent;
|
||||
blendmode = hwr2::BlendMode::kAlphaTransparent;
|
||||
}
|
||||
|
||||
g_2d.begin_quad()
|
||||
|
|
@ -1629,7 +1630,7 @@ void V_DrawFadeConsBack(INT32 plines)
|
|||
float a = 0.5f;
|
||||
g_2d.begin_quad()
|
||||
.rect(0, 0, vid.width, plines)
|
||||
.blend(hwr2::Draw2dBlend::kAlphaTransparent)
|
||||
.blend(hwr2::BlendMode::kAlphaTransparent)
|
||||
.color(r, g, b, a)
|
||||
.done();
|
||||
}
|
||||
|
|
@ -1649,7 +1650,7 @@ void V_EncoreInvertScreen(void)
|
|||
#endif
|
||||
|
||||
g_2d.begin_quad()
|
||||
.blend(hwr2::Draw2dBlend::kInvertDest)
|
||||
.blend(hwr2::BlendMode::kInvertDest)
|
||||
.color(1, 1, 1, 1)
|
||||
.rect(0, 0, vid.width, vid.height)
|
||||
.done();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue