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