2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:09:55 +02:00
|
|
|
// Refer to the license.txt file included.
|
2009-06-22 11:31:30 +02:00
|
|
|
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoCommon/BPMemory.h"
|
2009-06-22 11:31:30 +02:00
|
|
|
|
2018-05-18 20:25:40 +02:00
|
|
|
#include "Common/BitUtils.h"
|
2017-01-23 21:48:14 +01:00
|
|
|
|
2009-07-26 11:52:35 +02:00
|
|
|
// BP state
|
2009-06-22 11:31:30 +02:00
|
|
|
// STATE_TO_SAVE
|
|
|
|
BPMemory bpmem;
|
2017-01-23 21:48:14 +01:00
|
|
|
|
2017-09-03 08:32:37 +02:00
|
|
|
bool BlendMode::UseLogicOp() const
|
|
|
|
{
|
|
|
|
// Logicop bit has lowest priority.
|
|
|
|
if (subtract || blendenable || !logicopenable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Fast path for Kirby's Return to Dreamland, they use it with dstAlpha.
|
|
|
|
if (logicmode == BlendMode::NOOP)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-01 08:36:30 +01:00
|
|
|
bool FogParams::IsNaNCase() const
|
2017-01-23 21:48:14 +01:00
|
|
|
{
|
2018-02-01 08:36:30 +01:00
|
|
|
// Check for the case where both a and c are infinity or NaN.
|
|
|
|
// On hardware, this results in the following colors:
|
|
|
|
//
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// | A | C | Result | A | C | Result |
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// | inf | inf | Fogged | inf | nan | Fogged |
|
|
|
|
// | inf | -inf | Unfogged | inf | -nan | Unfogged |
|
|
|
|
// | -inf | inf | Unfogged | -inf | nan | Unfogged |
|
|
|
|
// | -inf | -inf | Unfogged | -inf | -nan | Unfogged |
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// | nan | inf | Fogged | nan | nan | Fogged |
|
|
|
|
// | nan | -inf | Unfogged | nan | -nan | Unfogged |
|
|
|
|
// | -nan | inf | Unfogged | -nan | nan | Unfogged |
|
|
|
|
// | -nan | -inf | Unfogged | -nan | -nan | Unfogged |
|
|
|
|
// -------------------------------------------------------
|
|
|
|
//
|
|
|
|
// We replicate this by returning A=0, and C=inf for the inf/inf case, otherwise -inf.
|
|
|
|
// This ensures we do not pass a NaN to the GPU, and -inf/inf clamp to 0/1 respectively.
|
|
|
|
return a.exp == 255 && c_proj_fsel.c_exp == 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
float FogParams::GetA() const
|
|
|
|
{
|
|
|
|
if (IsNaNCase())
|
|
|
|
return 0.0f;
|
|
|
|
|
2017-01-23 21:48:14 +01:00
|
|
|
// scale mantissa from 11 to 23 bits
|
2018-02-01 08:36:30 +01:00
|
|
|
const u32 integral = (static_cast<u32>(a.sign) << 31) | (static_cast<u32>(a.exp) << 23) |
|
|
|
|
(static_cast<u32>(a.mant) << 12);
|
2017-01-23 21:48:14 +01:00
|
|
|
|
2018-05-18 20:25:40 +02:00
|
|
|
return Common::BitCast<float>(integral);
|
2017-01-23 21:48:14 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 08:36:30 +01:00
|
|
|
float FogParams::GetC() const
|
2017-01-23 21:48:14 +01:00
|
|
|
{
|
2018-02-01 08:36:30 +01:00
|
|
|
if (IsNaNCase())
|
|
|
|
{
|
|
|
|
constexpr float inf = std::numeric_limits<float>::infinity();
|
|
|
|
return !a.sign && !c_proj_fsel.c_sign ? -inf : inf;
|
|
|
|
}
|
|
|
|
|
2017-01-23 21:48:14 +01:00
|
|
|
// scale mantissa from 11 to 23 bits
|
2018-02-01 08:36:30 +01:00
|
|
|
const u32 integral = (c_proj_fsel.c_sign.Value() << 31) | (c_proj_fsel.c_exp.Value() << 23) |
|
|
|
|
(c_proj_fsel.c_mant.Value() << 12);
|
2017-01-23 21:48:14 +01:00
|
|
|
|
2018-05-18 20:25:40 +02:00
|
|
|
return Common::BitCast<float>(integral);
|
2017-01-23 21:48:14 +01:00
|
|
|
}
|