Skip to content

Commit e0c8ab7

Browse files
committed
render: wrap U coord on texture fetch overflow
render_line: error calculation now mimic HW
1 parent d31ccc0 commit e0c8ab7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/device/gpu/render/render_line.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void Render::drawLine(gpu::GPU* gpu, const primitive::Line& line) {
4040
int dx = x1 - x0;
4141
int dy = y1 - y0;
4242
int derror = std::abs(dy) * 2;
43-
int error = 0;
43+
int error = !steep;
4444
int _y = y0;
4545

4646
float length = sqrtf(powf(x1 - x0, 2) + powf(y1 - y0, 2));

src/device/gpu/render/texture_utils.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ enum class ColorDepth { NONE, BIT_4, BIT_8, BIT_16 };
99
namespace {
1010
// Using unsigned vectors allows compiler to generate slightly faster division code
1111
INLINE uint16_t tex4bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage, glm::uvec2 clut) {
12-
uint16_t index = gpuVRAM[texPage.y + tex.y][texPage.x + tex.x / 4];
12+
uint16_t index = gpuVRAM[texPage.y + tex.y][(texPage.x + tex.x / 4) & 1023];
1313
uint8_t entry = (index >> ((tex.x & 3) * 4)) & 0xf;
1414
return gpuVRAM[clut.y][clut.x + entry];
1515
}
1616

1717
INLINE uint16_t tex8bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage, glm::uvec2 clut) {
18-
uint16_t index = gpuVRAM[texPage.y + tex.y][texPage.x + tex.x / 2];
18+
uint16_t index = gpuVRAM[texPage.y + tex.y][(texPage.x + tex.x / 2) & 1023];
1919
uint8_t entry = (index >> ((tex.x & 1) * 8)) & 0xff;
2020
return gpuVRAM[clut.y][clut.x + entry];
2121
}
2222

23-
INLINE uint16_t tex16bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage) { return gpuVRAM[texPage.y + tex.y][texPage.x + tex.x]; }
23+
INLINE uint16_t tex16bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage) {
24+
return gpuVRAM[texPage.y + tex.y][(texPage.x + tex.x) & 1023];
25+
}
2426

2527
template <ColorDepth bits>
2628
INLINE PSXColor fetchTex(gpu::GPU* gpu, glm::uvec2 texel, const glm::ivec2 texPage, const glm::ivec2 clut) {

0 commit comments

Comments
 (0)