mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 10:19:47 -04:00
34561b5418
New [video] texture_filtering = "nearest" | "bilinear" (default nearest). Bilinear smooths textures and 2D backgrounds by sampling the 4 neighbouring texels and blending them. Done correctly for PSX: - blends in RGB after the CLUT lookup (never interpolates palette indices) - transparency-aware: keeps cutouts where the nearest texel is transparent, and replaces transparent neighbours with the nearest colour so edges don't bleed to black - neighbours wrap within the 256-texel page, so the blend stays inside one texture instead of bleeding across packed VRAM Applied to all textured primitives (triangles, shaded triangles, sprites, scaled sprites); independent of supersampling and resolution, so cost is in texel fetches only, not pixel count. Nearest path is byte-identical when off. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
98 lines
4.4 KiB
C
98 lines
4.4 KiB
C
#ifndef PSX_GPU_SW_RENDERER_H
|
|
#define PSX_GPU_SW_RENDERER_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Maximum internal-resolution supersampling factor (linear, per axis). */
|
|
#define SW_MAX_INTERNAL_SCALE 4
|
|
|
|
/* Initialize software renderer */
|
|
void sw_renderer_init(uint16_t* vram);
|
|
|
|
/* Internal-resolution supersampling (SSAA).
|
|
* scale == 1 : disabled, renderer behaves exactly as native VRAM only.
|
|
* scale > 1 : maintain an S*-scaled mirror of VRAM; the display reads the
|
|
* mirror (sw_render_display_hires) and the present path
|
|
* downsamples to the window. Clamped to SW_MAX_INTERNAL_SCALE.
|
|
* Must be called once after sw_renderer_init, before drawing begins. */
|
|
void sw_renderer_set_scale(int scale);
|
|
int sw_renderer_scale(void);
|
|
|
|
/* Texture filtering. 0 = nearest (native PSX look, default), 1 = bilinear
|
|
* (smooths textures/2D backgrounds; blends in RGB after the CLUT lookup,
|
|
* transparency-aware). Independent of supersampling. */
|
|
void sw_set_texture_filter(int bilinear);
|
|
int sw_texture_filter(void);
|
|
|
|
/* Draw state — must be set by gpu.c before each primitive */
|
|
void sw_set_semi_transparency(int enabled, int mode);
|
|
void sw_set_mask_bits(int set_bit, int check_bit);
|
|
void sw_set_texture_window(uint32_t raw);
|
|
void sw_set_color_modulation(int r, int g, int b, int raw_texture);
|
|
|
|
/* Drawing primitives — called from gpu.c command processing */
|
|
void sw_fill_rect(int x, int y, int w, int h, uint16_t color);
|
|
void sw_copy_rect(int src_x, int src_y, int dst_x, int dst_y, int w, int h);
|
|
void sw_draw_flat_triangle(int x0, int y0, int x1, int y1, int x2, int y2,
|
|
uint16_t color);
|
|
void sw_draw_gouraud_triangle(int x0, int y0, uint16_t c0,
|
|
int x1, int y1, uint16_t c1,
|
|
int x2, int y2, uint16_t c2);
|
|
void sw_draw_textured_triangle(int x0, int y0, int u0, int v0,
|
|
int x1, int y1, int u1, int v1,
|
|
int x2, int y2, int u2, int v2,
|
|
uint16_t clut_x, uint16_t clut_y,
|
|
uint16_t texpage);
|
|
void sw_draw_shaded_textured_triangle(int x0, int y0, int u0, int v0,
|
|
uint32_t color0,
|
|
int x1, int y1, int u1, int v1,
|
|
uint32_t color1,
|
|
int x2, int y2, int u2, int v2,
|
|
uint32_t color2,
|
|
uint16_t clut_x, uint16_t clut_y,
|
|
uint16_t texpage, int raw_texture);
|
|
void sw_draw_flat_rect(int x, int y, int w, int h, uint16_t color);
|
|
void sw_draw_textured_rect(int x, int y, int w, int h,
|
|
int u, int v,
|
|
uint16_t clut_x, uint16_t clut_y,
|
|
uint16_t texpage);
|
|
void sw_draw_textured_rect_scaled(int x, int y, int w, int h,
|
|
int u0, int v0, int u1, int v1,
|
|
uint16_t clut_x, uint16_t clut_y,
|
|
uint16_t texpage);
|
|
void sw_draw_line(int x0, int y0, int x1, int y1, uint16_t color);
|
|
void sw_draw_shaded_line(int x0, int y0, uint16_t c0,
|
|
int x1, int y1, uint16_t c1);
|
|
|
|
/* Copy display region to a 32-bit RGBA buffer for SDL presentation.
|
|
Returns number of pixels written. */
|
|
int sw_render_display(uint32_t* out_pixels, int out_pitch,
|
|
int disp_x, int disp_y, int disp_w, int disp_h);
|
|
|
|
/* Like sw_render_display, but reads the hi-res mirror and emits the region
|
|
at (disp_w*scale x disp_h*scale). Falls back to sw_render_display when
|
|
supersampling is disabled. Returns number of pixels written. */
|
|
int sw_render_display_hires(uint32_t* out_pixels, int out_pitch,
|
|
int disp_x, int disp_y, int disp_w, int disp_h);
|
|
|
|
/* VRAM transfer (CPU->VRAM, VRAM->CPU) */
|
|
void sw_vram_write(int x, int y, uint16_t pixel);
|
|
uint16_t sw_vram_read(int x, int y);
|
|
void sw_vram_transfer_in(int x, int y, int w, int h, const uint16_t* data);
|
|
void sw_vram_transfer_out(int x, int y, int w, int h, uint16_t* data);
|
|
|
|
/* Set draw area and draw offset */
|
|
void sw_set_draw_area(int x1, int y1, int x2, int y2);
|
|
void sw_get_draw_area(int *x1, int *y1, int *x2, int *y2);
|
|
void sw_set_draw_offset(int x, int y);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* PSX_GPU_SW_RENDERER_H */
|