Skip to content
Permalink
Browse files

render: wrap U coord on texture fetch overflow

render_line: error calculation now mimic HW
  • Loading branch information
JaCzekanski committed Sep 30, 2019
1 parent d31ccc0 commit e0c8ab716b78fbc4984d852e2c1cf51543af83b2
Showing with 6 additions and 4 deletions.
  1. +1 −1 src/device/gpu/render/render_line.cpp
  2. +5 −3 src/device/gpu/render/texture_utils.h
@@ -40,7 +40,7 @@ void Render::drawLine(gpu::GPU* gpu, const primitive::Line& line) {
int dx = x1 - x0;
int dy = y1 - y0;
int derror = std::abs(dy) * 2;
int error = 0;
int error = !steep;
int _y = y0;

float length = sqrtf(powf(x1 - x0, 2) + powf(y1 - y0, 2));
@@ -9,18 +9,20 @@ enum class ColorDepth { NONE, BIT_4, BIT_8, BIT_16 };
namespace {
// Using unsigned vectors allows compiler to generate slightly faster division code
INLINE uint16_t tex4bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage, glm::uvec2 clut) {
uint16_t index = gpuVRAM[texPage.y + tex.y][texPage.x + tex.x / 4];
uint16_t index = gpuVRAM[texPage.y + tex.y][(texPage.x + tex.x / 4) & 1023];
uint8_t entry = (index >> ((tex.x & 3) * 4)) & 0xf;
return gpuVRAM[clut.y][clut.x + entry];
}

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

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

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

0 comments on commit e0c8ab7

Please sign in to comment.
You can’t perform that action at this time.