diff options
| author | 2017-06-13 21:28:13 -0700 | |
|---|---|---|
| committer | 2017-06-13 21:28:12 -0700 | |
| commit | 5fe5ccac4250d5f001cc29838033e2fef63ebb6c (patch) | |
| tree | 32224370753184eeca64cf9b055351ee599c9e94 /src | |
| parent | Services/UDS: Set the proper bit in the ConnectionStatus structure when creat... (diff) | |
| parent | pica/rasterizer: implement/stub texture wrap mode 4-7 (diff) | |
| download | yuzu-5fe5ccac4250d5f001cc29838033e2fef63ebb6c.tar.gz yuzu-5fe5ccac4250d5f001cc29838033e2fef63ebb6c.tar.xz yuzu-5fe5ccac4250d5f001cc29838033e2fef63ebb6c.zip | |
Merge pull request #2743 from wwylele/wrap-fix
pica/rasterizer: implement/stub texture wrap mode 4-7
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/regs_texturing.h | 8 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/pica_to_gl.h | 13 | ||||
| -rw-r--r-- | src/video_core/swrasterizer/rasterizer.cpp | 20 | ||||
| -rw-r--r-- | src/video_core/swrasterizer/texturing.cpp | 19 |
4 files changed, 48 insertions, 12 deletions
diff --git a/src/video_core/regs_texturing.h b/src/video_core/regs_texturing.h index 3f5355fa9..0b09f2299 100644 --- a/src/video_core/regs_texturing.h +++ b/src/video_core/regs_texturing.h | |||
| @@ -30,10 +30,10 @@ struct TexturingRegs { | |||
| 30 | Repeat = 2, | 30 | Repeat = 2, |
| 31 | MirroredRepeat = 3, | 31 | MirroredRepeat = 3, |
| 32 | // Mode 4-7 produces some weird result and may be just invalid: | 32 | // Mode 4-7 produces some weird result and may be just invalid: |
| 33 | // 4: Positive coord: clamp to edge; negative coord: repeat | 33 | ClampToEdge2 = 4, // Positive coord: clamp to edge; negative coord: repeat |
| 34 | // 5: Positive coord: clamp to border; negative coord: repeat | 34 | ClampToBorder2 = 5, // Positive coord: clamp to border; negative coord: repeat |
| 35 | // 6: Repeat | 35 | Repeat2 = 6, // Same as Repeat |
| 36 | // 7: Repeat | 36 | Repeat3 = 7, // Same as Repeat |
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | enum TextureFilter : u32 { | 39 | enum TextureFilter : u32 { |
diff --git a/src/video_core/renderer_opengl/pica_to_gl.h b/src/video_core/renderer_opengl/pica_to_gl.h index 93d7b0b71..70298e211 100644 --- a/src/video_core/renderer_opengl/pica_to_gl.h +++ b/src/video_core/renderer_opengl/pica_to_gl.h | |||
| @@ -55,6 +55,12 @@ inline GLenum WrapMode(Pica::TexturingRegs::TextureConfig::WrapMode mode) { | |||
| 55 | GL_CLAMP_TO_BORDER, // WrapMode::ClampToBorder | 55 | GL_CLAMP_TO_BORDER, // WrapMode::ClampToBorder |
| 56 | GL_REPEAT, // WrapMode::Repeat | 56 | GL_REPEAT, // WrapMode::Repeat |
| 57 | GL_MIRRORED_REPEAT, // WrapMode::MirroredRepeat | 57 | GL_MIRRORED_REPEAT, // WrapMode::MirroredRepeat |
| 58 | // TODO(wwylele): ClampToEdge2 and ClampToBorder2 are not properly implemented here. See the | ||
| 59 | // comments in enum WrapMode. | ||
| 60 | GL_CLAMP_TO_EDGE, // WrapMode::ClampToEdge2 | ||
| 61 | GL_CLAMP_TO_BORDER, // WrapMode::ClampToBorder2 | ||
| 62 | GL_REPEAT, // WrapMode::Repeat2 | ||
| 63 | GL_REPEAT, // WrapMode::Repeat3 | ||
| 58 | }; | 64 | }; |
| 59 | 65 | ||
| 60 | // Range check table for input | 66 | // Range check table for input |
| @@ -65,6 +71,13 @@ inline GLenum WrapMode(Pica::TexturingRegs::TextureConfig::WrapMode mode) { | |||
| 65 | return GL_CLAMP_TO_EDGE; | 71 | return GL_CLAMP_TO_EDGE; |
| 66 | } | 72 | } |
| 67 | 73 | ||
| 74 | if (static_cast<u32>(mode) > 3) { | ||
| 75 | // It is still unclear whether mode 4-7 are valid, so log it if a game uses them. | ||
| 76 | // TODO(wwylele): telemetry should be added here so we can collect more info about which | ||
| 77 | // game uses this. | ||
| 78 | LOG_WARNING(Render_OpenGL, "Using texture wrap mode %u", static_cast<u32>(mode)); | ||
| 79 | } | ||
| 80 | |||
| 68 | GLenum gl_mode = wrap_mode_table[mode]; | 81 | GLenum gl_mode = wrap_mode_table[mode]; |
| 69 | 82 | ||
| 70 | // Check for dummy values indicating an unknown mode | 83 | // Check for dummy values indicating an unknown mode |
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 8b7b1defb..cd7b6c39d 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp | |||
| @@ -357,10 +357,22 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve | |||
| 357 | int t = (int)(v * float24::FromFloat32(static_cast<float>(texture.config.height))) | 357 | int t = (int)(v * float24::FromFloat32(static_cast<float>(texture.config.height))) |
| 358 | .ToFloat32(); | 358 | .ToFloat32(); |
| 359 | 359 | ||
| 360 | if ((texture.config.wrap_s == TexturingRegs::TextureConfig::ClampToBorder && | 360 | bool use_border_s = false; |
| 361 | (s < 0 || static_cast<u32>(s) >= texture.config.width)) || | 361 | bool use_border_t = false; |
| 362 | (texture.config.wrap_t == TexturingRegs::TextureConfig::ClampToBorder && | 362 | |
| 363 | (t < 0 || static_cast<u32>(t) >= texture.config.height))) { | 363 | if (texture.config.wrap_s == TexturingRegs::TextureConfig::ClampToBorder) { |
| 364 | use_border_s = s < 0 || s >= static_cast<int>(texture.config.width); | ||
| 365 | } else if (texture.config.wrap_s == TexturingRegs::TextureConfig::ClampToBorder2) { | ||
| 366 | use_border_s = s >= static_cast<int>(texture.config.width); | ||
| 367 | } | ||
| 368 | |||
| 369 | if (texture.config.wrap_t == TexturingRegs::TextureConfig::ClampToBorder) { | ||
| 370 | use_border_t = t < 0 || t >= static_cast<int>(texture.config.height); | ||
| 371 | } else if (texture.config.wrap_t == TexturingRegs::TextureConfig::ClampToBorder2) { | ||
| 372 | use_border_t = t >= static_cast<int>(texture.config.height); | ||
| 373 | } | ||
| 374 | |||
| 375 | if (use_border_s || use_border_t) { | ||
| 364 | auto border_color = texture.config.border_color; | 376 | auto border_color = texture.config.border_color; |
| 365 | texture_color[i] = {border_color.r, border_color.g, border_color.b, | 377 | texture_color[i] = {border_color.r, border_color.g, border_color.b, |
| 366 | border_color.a}; | 378 | border_color.a}; |
diff --git a/src/video_core/swrasterizer/texturing.cpp b/src/video_core/swrasterizer/texturing.cpp index aeb6aeb8c..4f02b93f2 100644 --- a/src/video_core/swrasterizer/texturing.cpp +++ b/src/video_core/swrasterizer/texturing.cpp | |||
| @@ -18,22 +18,33 @@ using TevStageConfig = TexturingRegs::TevStageConfig; | |||
| 18 | 18 | ||
| 19 | int GetWrappedTexCoord(TexturingRegs::TextureConfig::WrapMode mode, int val, unsigned size) { | 19 | int GetWrappedTexCoord(TexturingRegs::TextureConfig::WrapMode mode, int val, unsigned size) { |
| 20 | switch (mode) { | 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]] | ||
| 21 | case TexturingRegs::TextureConfig::ClampToEdge: | 27 | case TexturingRegs::TextureConfig::ClampToEdge: |
| 22 | val = std::max(val, 0); | 28 | val = std::max(val, 0); |
| 23 | val = std::min(val, (int)size - 1); | 29 | val = std::min(val, static_cast<int>(size) - 1); |
| 24 | return val; | 30 | return val; |
| 25 | 31 | ||
| 26 | case TexturingRegs::TextureConfig::ClampToBorder: | 32 | case TexturingRegs::TextureConfig::ClampToBorder: |
| 27 | return val; | 33 | return val; |
| 28 | 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: | ||
| 29 | case TexturingRegs::TextureConfig::Repeat: | 40 | case TexturingRegs::TextureConfig::Repeat: |
| 30 | return (int)((unsigned)val % size); | 41 | return static_cast<int>(static_cast<unsigned>(val) % size); |
| 31 | 42 | ||
| 32 | case TexturingRegs::TextureConfig::MirroredRepeat: { | 43 | case TexturingRegs::TextureConfig::MirroredRepeat: { |
| 33 | unsigned int coord = ((unsigned)val % (2 * size)); | 44 | unsigned int coord = (static_cast<unsigned>(val) % (2 * size)); |
| 34 | if (coord >= size) | 45 | if (coord >= size) |
| 35 | coord = 2 * size - 1 - coord; | 46 | coord = 2 * size - 1 - coord; |
| 36 | return (int)coord; | 47 | return static_cast<int>(coord); |
| 37 | } | 48 | } |
| 38 | 49 | ||
| 39 | default: | 50 | default: |