Skip to content

Commit

Permalink
Check tex matrix existence before applying
Browse files Browse the repository at this point in the history
  • Loading branch information
Grarak committed Jan 25, 2025
1 parent 1a443de commit b34625b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/graphics/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Gpu {
v_count: 0,
gpu_2d_regs_a: Gpu2DRegisters::new(A),
gpu_2d_regs_b: Gpu2DRegisters::new(B),
gpu_3d_regs: Gpu3DRegisters::default(),
gpu_3d_regs: Gpu3DRegisters::new(),
gpu_renderer: None,
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/core/graphics/gpu_3d/registers_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ macro_rules! unpacked_cmd {
}

impl Gpu3DRegisters {
pub fn new() -> Self {
Gpu3DRegisters {
clip_mtx_push: true,
tex_mtx_push: true,
..Gpu3DRegisters::default()
}
}

fn is_cmd_fifo_full(&self) -> bool {
self.cmd_fifo.len() >= 260
}
Expand Down Expand Up @@ -914,11 +922,11 @@ impl Gpu3DRegisters {
let tex_coord = TexCoord::from(params[0]);
self.cur_vtx.tex_coords[0] = tex_coord.s() as i16;
self.cur_vtx.tex_coords[1] = tex_coord.t() as i16;
if self.tex_mtx_push {
if self.cur_vtx.tex_coord_trans_mode == TextureCoordTransMode::TexCoord && self.tex_mtx_push {
self.tex_matrices.push(self.matrices.tex);
self.tex_mtx_push = false;
}
self.cur_vtx.tex_matrix_index = self.tex_matrices.len() as u16 - 1;
self.cur_vtx.tex_matrix_index = (self.tex_matrices.len() as u16).wrapping_sub(1);
}

fn exe_vtx16(&mut self, params: &[u32; 32]) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/graphics/gpu_3d/renderer_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl Gpu3DRenderer {

let mut tex_coords = vertex.tex_coords;
let tex_coord_trans_mode = TextureCoordTransMode::from(u8::from(polygon.tex_image_param.coord_trans_mode()));
if tex_coord_trans_mode == TextureCoordTransMode::TexCoord {
if tex_coord_trans_mode == TextureCoordTransMode::TexCoord && (vertex.tex_matrix_index as usize) < self.content.tex_matrices.len() {
let mut vector = Vectori32::<4>::new([(tex_coords[0] as i32) << 8, (tex_coords[1] as i32) << 8, 1 << 12, 1 << 12]);
vector *= &self.content.tex_matrices[vertex.tex_matrix_index as usize];
tex_coords[0] = (vector[0] >> 8) as i16;
Expand Down

0 comments on commit b34625b

Please sign in to comment.