diff options
Diffstat (limited to 'src/video_core/swrasterizer/texturing.cpp')
| -rw-r--r-- | src/video_core/swrasterizer/texturing.cpp | 244 |
1 files changed, 0 insertions, 244 deletions
diff --git a/src/video_core/swrasterizer/texturing.cpp b/src/video_core/swrasterizer/texturing.cpp deleted file mode 100644 index 79b1ce841..000000000 --- a/src/video_core/swrasterizer/texturing.cpp +++ /dev/null | |||
| @@ -1,244 +0,0 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "common/math_util.h" | ||
| 10 | #include "common/vector_math.h" | ||
| 11 | #include "video_core/regs_texturing.h" | ||
| 12 | #include "video_core/swrasterizer/texturing.h" | ||
| 13 | |||
| 14 | namespace Pica { | ||
| 15 | namespace Rasterizer { | ||
| 16 | |||
| 17 | using TevStageConfig = TexturingRegs::TevStageConfig; | ||
| 18 | |||
| 19 | int GetWrappedTexCoord(TexturingRegs::TextureConfig::WrapMode mode, int val, unsigned size) { | ||
| 20 | switch (mode) { | ||
| 21 | case TexturingRegs::TextureConfig::ClampToEdge2: | ||
| 22 | // For negative coordinate, ClampToEdge2 behaves the same as Repeat | ||
| 23 | if (val < 0) { | ||
| 24 | return static_cast<int>(static_cast<unsigned>(val) % size); | ||
| 25 | } | ||
| 26 | // [[fallthrough]] | ||
| 27 | case TexturingRegs::TextureConfig::ClampToEdge: | ||
| 28 | val = std::max(val, 0); | ||
| 29 | val = std::min(val, static_cast<int>(size) - 1); | ||
| 30 | return val; | ||
| 31 | |||
| 32 | case TexturingRegs::TextureConfig::ClampToBorder: | ||
| 33 | return val; | ||
| 34 | |||
| 35 | case TexturingRegs::TextureConfig::ClampToBorder2: | ||
| 36 | // For ClampToBorder2, the case of positive coordinate beyond the texture size is already | ||
| 37 | // handled outside. Here we only handle the negative coordinate in the same way as Repeat. | ||
| 38 | case TexturingRegs::TextureConfig::Repeat2: | ||
| 39 | case TexturingRegs::TextureConfig::Repeat3: | ||
| 40 | case TexturingRegs::TextureConfig::Repeat: | ||
| 41 | return static_cast<int>(static_cast<unsigned>(val) % size); | ||
| 42 | |||
| 43 | case TexturingRegs::TextureConfig::MirroredRepeat: { | ||
| 44 | unsigned int coord = (static_cast<unsigned>(val) % (2 * size)); | ||
| 45 | if (coord >= size) | ||
| 46 | coord = 2 * size - 1 - coord; | ||
| 47 | return static_cast<int>(coord); | ||
| 48 | } | ||
| 49 | |||
| 50 | default: | ||
| 51 | LOG_ERROR(HW_GPU, "Unknown texture coordinate wrapping mode %x", (int)mode); | ||
| 52 | UNIMPLEMENTED(); | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | }; | ||
| 56 | |||
| 57 | Math::Vec3<u8> GetColorModifier(TevStageConfig::ColorModifier factor, | ||
| 58 | const Math::Vec4<u8>& values) { | ||
| 59 | using ColorModifier = TevStageConfig::ColorModifier; | ||
| 60 | |||
| 61 | switch (factor) { | ||
| 62 | case ColorModifier::SourceColor: | ||
| 63 | return values.rgb(); | ||
| 64 | |||
| 65 | case ColorModifier::OneMinusSourceColor: | ||
| 66 | return (Math::Vec3<u8>(255, 255, 255) - values.rgb()).Cast<u8>(); | ||
| 67 | |||
| 68 | case ColorModifier::SourceAlpha: | ||
| 69 | return values.aaa(); | ||
| 70 | |||
| 71 | case ColorModifier::OneMinusSourceAlpha: | ||
| 72 | return (Math::Vec3<u8>(255, 255, 255) - values.aaa()).Cast<u8>(); | ||
| 73 | |||
| 74 | case ColorModifier::SourceRed: | ||
| 75 | return values.rrr(); | ||
| 76 | |||
| 77 | case ColorModifier::OneMinusSourceRed: | ||
| 78 | return (Math::Vec3<u8>(255, 255, 255) - values.rrr()).Cast<u8>(); | ||
| 79 | |||
| 80 | case ColorModifier::SourceGreen: | ||
| 81 | return values.ggg(); | ||
| 82 | |||
| 83 | case ColorModifier::OneMinusSourceGreen: | ||
| 84 | return (Math::Vec3<u8>(255, 255, 255) - values.ggg()).Cast<u8>(); | ||
| 85 | |||
| 86 | case ColorModifier::SourceBlue: | ||
| 87 | return values.bbb(); | ||
| 88 | |||
| 89 | case ColorModifier::OneMinusSourceBlue: | ||
| 90 | return (Math::Vec3<u8>(255, 255, 255) - values.bbb()).Cast<u8>(); | ||
| 91 | } | ||
| 92 | |||
| 93 | UNREACHABLE(); | ||
| 94 | }; | ||
| 95 | |||
| 96 | u8 GetAlphaModifier(TevStageConfig::AlphaModifier factor, const Math::Vec4<u8>& values) { | ||
| 97 | using AlphaModifier = TevStageConfig::AlphaModifier; | ||
| 98 | |||
| 99 | switch (factor) { | ||
| 100 | case AlphaModifier::SourceAlpha: | ||
| 101 | return values.a(); | ||
| 102 | |||
| 103 | case AlphaModifier::OneMinusSourceAlpha: | ||
| 104 | return 255 - values.a(); | ||
| 105 | |||
| 106 | case AlphaModifier::SourceRed: | ||
| 107 | return values.r(); | ||
| 108 | |||
| 109 | case AlphaModifier::OneMinusSourceRed: | ||
| 110 | return 255 - values.r(); | ||
| 111 | |||
| 112 | case AlphaModifier::SourceGreen: | ||
| 113 | return values.g(); | ||
| 114 | |||
| 115 | case AlphaModifier::OneMinusSourceGreen: | ||
| 116 | return 255 - values.g(); | ||
| 117 | |||
| 118 | case AlphaModifier::SourceBlue: | ||
| 119 | return values.b(); | ||
| 120 | |||
| 121 | case AlphaModifier::OneMinusSourceBlue: | ||
| 122 | return 255 - values.b(); | ||
| 123 | } | ||
| 124 | |||
| 125 | UNREACHABLE(); | ||
| 126 | }; | ||
| 127 | |||
| 128 | Math::Vec3<u8> ColorCombine(TevStageConfig::Operation op, const Math::Vec3<u8> input[3]) { | ||
| 129 | using Operation = TevStageConfig::Operation; | ||
| 130 | |||
| 131 | switch (op) { | ||
| 132 | case Operation::Replace: | ||
| 133 | return input[0]; | ||
| 134 | |||
| 135 | case Operation::Modulate: | ||
| 136 | return ((input[0] * input[1]) / 255).Cast<u8>(); | ||
| 137 | |||
| 138 | case Operation::Add: { | ||
| 139 | auto result = input[0] + input[1]; | ||
| 140 | result.r() = std::min(255, result.r()); | ||
| 141 | result.g() = std::min(255, result.g()); | ||
| 142 | result.b() = std::min(255, result.b()); | ||
| 143 | return result.Cast<u8>(); | ||
| 144 | } | ||
| 145 | |||
| 146 | case Operation::AddSigned: { | ||
| 147 | // TODO(bunnei): Verify that the color conversion from (float) 0.5f to | ||
| 148 | // (byte) 128 is correct | ||
| 149 | auto result = | ||
| 150 | input[0].Cast<int>() + input[1].Cast<int>() - Math::MakeVec<int>(128, 128, 128); | ||
| 151 | result.r() = MathUtil::Clamp<int>(result.r(), 0, 255); | ||
| 152 | result.g() = MathUtil::Clamp<int>(result.g(), 0, 255); | ||
| 153 | result.b() = MathUtil::Clamp<int>(result.b(), 0, 255); | ||
| 154 | return result.Cast<u8>(); | ||
| 155 | } | ||
| 156 | |||
| 157 | case Operation::Lerp: | ||
| 158 | return ((input[0] * input[2] + | ||
| 159 | input[1] * (Math::MakeVec<u8>(255, 255, 255) - input[2]).Cast<u8>()) / | ||
| 160 | 255) | ||
| 161 | .Cast<u8>(); | ||
| 162 | |||
| 163 | case Operation::Subtract: { | ||
| 164 | auto result = input[0].Cast<int>() - input[1].Cast<int>(); | ||
| 165 | result.r() = std::max(0, result.r()); | ||
| 166 | result.g() = std::max(0, result.g()); | ||
| 167 | result.b() = std::max(0, result.b()); | ||
| 168 | return result.Cast<u8>(); | ||
| 169 | } | ||
| 170 | |||
| 171 | case Operation::MultiplyThenAdd: { | ||
| 172 | auto result = (input[0] * input[1] + 255 * input[2].Cast<int>()) / 255; | ||
| 173 | result.r() = std::min(255, result.r()); | ||
| 174 | result.g() = std::min(255, result.g()); | ||
| 175 | result.b() = std::min(255, result.b()); | ||
| 176 | return result.Cast<u8>(); | ||
| 177 | } | ||
| 178 | |||
| 179 | case Operation::AddThenMultiply: { | ||
| 180 | auto result = input[0] + input[1]; | ||
| 181 | result.r() = std::min(255, result.r()); | ||
| 182 | result.g() = std::min(255, result.g()); | ||
| 183 | result.b() = std::min(255, result.b()); | ||
| 184 | result = (result * input[2].Cast<int>()) / 255; | ||
| 185 | return result.Cast<u8>(); | ||
| 186 | } | ||
| 187 | case Operation::Dot3_RGB: | ||
| 188 | case Operation::Dot3_RGBA: { | ||
| 189 | // Not fully accurate. Worst case scenario seems to yield a +/-3 error. Some HW results | ||
| 190 | // indicate that the per-component computation can't have a higher precision than 1/256, | ||
| 191 | // while dot3_rgb((0x80,g0,b0), (0x7F,g1,b1)) and dot3_rgb((0x80,g0,b0), (0x80,g1,b1)) give | ||
| 192 | // different results. | ||
| 193 | int result = ((input[0].r() * 2 - 255) * (input[1].r() * 2 - 255) + 128) / 256 + | ||
| 194 | ((input[0].g() * 2 - 255) * (input[1].g() * 2 - 255) + 128) / 256 + | ||
| 195 | ((input[0].b() * 2 - 255) * (input[1].b() * 2 - 255) + 128) / 256; | ||
| 196 | result = std::max(0, std::min(255, result)); | ||
| 197 | return {(u8)result, (u8)result, (u8)result}; | ||
| 198 | } | ||
| 199 | default: | ||
| 200 | LOG_ERROR(HW_GPU, "Unknown color combiner operation %d", (int)op); | ||
| 201 | UNIMPLEMENTED(); | ||
| 202 | return {0, 0, 0}; | ||
| 203 | } | ||
| 204 | }; | ||
| 205 | |||
| 206 | u8 AlphaCombine(TevStageConfig::Operation op, const std::array<u8, 3>& input) { | ||
| 207 | switch (op) { | ||
| 208 | using Operation = TevStageConfig::Operation; | ||
| 209 | case Operation::Replace: | ||
| 210 | return input[0]; | ||
| 211 | |||
| 212 | case Operation::Modulate: | ||
| 213 | return input[0] * input[1] / 255; | ||
| 214 | |||
| 215 | case Operation::Add: | ||
| 216 | return std::min(255, input[0] + input[1]); | ||
| 217 | |||
| 218 | case Operation::AddSigned: { | ||
| 219 | // TODO(bunnei): Verify that the color conversion from (float) 0.5f to (byte) 128 is correct | ||
| 220 | auto result = static_cast<int>(input[0]) + static_cast<int>(input[1]) - 128; | ||
| 221 | return static_cast<u8>(MathUtil::Clamp<int>(result, 0, 255)); | ||
| 222 | } | ||
| 223 | |||
| 224 | case Operation::Lerp: | ||
| 225 | return (input[0] * input[2] + input[1] * (255 - input[2])) / 255; | ||
| 226 | |||
| 227 | case Operation::Subtract: | ||
| 228 | return std::max(0, (int)input[0] - (int)input[1]); | ||
| 229 | |||
| 230 | case Operation::MultiplyThenAdd: | ||
| 231 | return std::min(255, (input[0] * input[1] + 255 * input[2]) / 255); | ||
| 232 | |||
| 233 | case Operation::AddThenMultiply: | ||
| 234 | return (std::min(255, (input[0] + input[1])) * input[2]) / 255; | ||
| 235 | |||
| 236 | default: | ||
| 237 | LOG_ERROR(HW_GPU, "Unknown alpha combiner operation %d", (int)op); | ||
| 238 | UNIMPLEMENTED(); | ||
| 239 | return 0; | ||
| 240 | } | ||
| 241 | }; | ||
| 242 | |||
| 243 | } // namespace Rasterizer | ||
| 244 | } // namespace Pica | ||