diff --git a/Source/Core/VideoCommon/BPMemory.cpp b/Source/Core/VideoCommon/BPMemory.cpp index 1665976018..67eeb994b1 100644 --- a/Source/Core/VideoCommon/BPMemory.cpp +++ b/Source/Core/VideoCommon/BPMemory.cpp @@ -4,6 +4,30 @@ #include "VideoCommon/BPMemory.h" +#include + // BP state // STATE_TO_SAVE BPMemory bpmem; + +float FogParam0::GetA() const +{ + // scale mantissa from 11 to 23 bits + const u32 integral = (static_cast(sign) << 31) | (static_cast(exponent) << 23) | + (static_cast(mantissa) << 12); + + float real; + std::memcpy(&real, &integral, sizeof(u32)); + return real; +} + +float FogParam3::GetC() const +{ + // scale mantissa from 11 to 23 bits + const u32 integral = (static_cast(c_sign) << 31) | (static_cast(c_exp) << 23) | + (static_cast(c_mant) << 12); + + float real; + std::memcpy(&real, &integral, sizeof(u32)); + return real; +} diff --git a/Source/Core/VideoCommon/BPMemory.h b/Source/Core/VideoCommon/BPMemory.h index 96a657fced..366dc191a5 100644 --- a/Source/Core/VideoCommon/BPMemory.h +++ b/Source/Core/VideoCommon/BPMemory.h @@ -376,7 +376,7 @@ union TevStageIndirect // If bs and mid are zero, the result of the stage is independent of // the texture sample data, so we can skip sampling the texture. - bool IsActive() { return bs != ITBA_OFF || mid != 0; } + bool IsActive() const { return bs != ITBA_OFF || mid != 0; } }; union TwoTevStageOrders @@ -435,8 +435,8 @@ union RAS1_IREF }; u32 hex; - u32 getTexCoord(int i) { return (hex >> (6 * i + 3)) & 7; } - u32 getTexMap(int i) { return (hex >> (6 * i)) & 7; } + u32 getTexCoord(int i) const { return (hex >> (6 * i + 3)) & 7; } + u32 getTexMap(int i) const { return (hex >> (6 * i)) & 7; } }; // Texture structs @@ -674,17 +674,7 @@ union FogParam0 u32 sign : 1; }; - float GetA() - { - union - { - u32 i; - float f; - } dummy; - dummy.i = ((u32)sign << 31) | ((u32)exponent << 23) | - ((u32)mantissa << 12); // scale mantissa from 11 to 23 bits - return dummy.f; - } + float GetA() const; u32 hex; }; @@ -701,17 +691,7 @@ union FogParam3 }; // amount to subtract from eyespacez after range adjustment - float GetC() - { - union - { - u32 i; - float f; - } dummy; - dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | - ((u32)c_mant << 12); // scale mantissa from 11 to 23 bits - return dummy.f; - } + float GetC() const; u32 hex; }; @@ -726,7 +706,7 @@ union FogRangeKElement }; // TODO: Which scaling coefficient should we use here? This is just a guess! - float GetValue(int i) { return (i ? HI : LO) / 256.f; } + float GetValue(int i) const { return (i ? HI : LO) / 256.f; } u32 HEX; }; @@ -912,8 +892,8 @@ union TevKSel }; u32 hex; - int getKC(int i) { return i ? kcsel1 : kcsel0; } - int getKA(int i) { return i ? kasel1 : kasel0; } + int getKC(int i) const { return i ? kcsel1 : kcsel0; } + int getKA(int i) const { return i ? kasel1 : kasel0; } }; union AlphaTest @@ -1013,7 +993,7 @@ union UPE_Copy BitField<16, 1, u32> auto_conv; // if 0 automatic color conversion by texture format and pixel type - u32 tp_realFormat() { return target_pixel_format / 2 + (target_pixel_format & 1) * 8; } + u32 tp_realFormat() const { return target_pixel_format / 2 + (target_pixel_format & 1) * 8; } }; union BPU_PreloadTileInfo