Implement gsDPSetTexturePersp

Had to bump OpenGL version to 3.0
TO-DO: Direct3D 11 doesn't work yet!
This commit is contained in:
Cooliokid956 2025-12-05 03:22:34 -06:00
parent 77ca4db299
commit 16d960ff5d
4 changed files with 22 additions and 18 deletions

View file

@ -78,6 +78,7 @@ struct CombineMode {
uint8_t use_dither : 1;
uint8_t use_2cycle : 1;
uint8_t light_map : 1;
uint8_t tex_persp : 1;
};
uint32_t flags;
};

View file

@ -147,7 +147,8 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
append_line(buf, &len, "struct PSInput {");
append_line(buf, &len, " float4 position : SV_POSITION;");
if (ccf.used_textures[0] || ccf.used_textures[1]) {
append_line(buf, &len, " float2 uv : TEXCOORD;");
// if (!cc.cm.tex_persp) append_str(buf, &len, "linear");
append_line(buf, &len, cc.cm.tex_persp ? " float2 uv : TEXCOORD;" : " linear float2 uv : TEXCOORD;");
num_floats += 2;
}
if ((cc.cm.use_alpha && cc.cm.use_dither) || ccf.do_noise) {

View file

@ -254,6 +254,7 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
bool opt_texture_edge = cc->cm.texture_edge;
bool opt_2cycle = cc->cm.use_2cycle;
bool opt_light_map = cc->cm.light_map;
bool opt_tex_persp = cc->cm.tex_persp;
#ifdef USE_GLES
bool opt_dither = false;
@ -269,29 +270,29 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
// Vertex shader
#ifdef USE_GLES
append_line(vs_buf, &vs_len, "#version 100");
append_line(vs_buf, &vs_len, "#version 300 es");
#else
append_line(vs_buf, &vs_len, "#version 120");
append_line(vs_buf, &vs_len, "#version 130");
#endif
append_line(vs_buf, &vs_len, "attribute vec4 aVtxPos;");
append_line(vs_buf, &vs_len, "in vec4 aVtxPos;");
if (ccf.used_textures[0] || ccf.used_textures[1]) {
append_line(vs_buf, &vs_len, "attribute vec2 aTexCoord;");
append_line(vs_buf, &vs_len, "varying vec2 vTexCoord;");
append_line(vs_buf, &vs_len, "in vec2 aTexCoord;");
append_line(vs_buf, &vs_len, "out vec2 vTexCoord;");
num_floats += 2;
}
if (opt_fog) {
append_line(vs_buf, &vs_len, "attribute vec4 aFog;");
append_line(vs_buf, &vs_len, "varying vec4 vFog;");
append_line(vs_buf, &vs_len, "in vec4 aFog;");
append_line(vs_buf, &vs_len, "out vec4 vFog;");
num_floats += 4;
}
if (opt_light_map) {
append_line(vs_buf, &vs_len, "attribute vec2 aLightMap;");
append_line(vs_buf, &vs_len, "varying vec2 vLightMap;");
append_line(vs_buf, &vs_len, "in vec2 aLightMap;");
append_line(vs_buf, &vs_len, "out vec2 vLightMap;");
num_floats += 2;
}
for (int i = 0; i < ccf.num_inputs; i++) {
vs_len += sprintf(vs_buf + vs_len, "attribute vec%d aInput%d;\n", opt_alpha ? 4 : 3, i + 1);
vs_len += sprintf(vs_buf + vs_len, "varying vec%d vInput%d;\n", opt_alpha ? 4 : 3, i + 1);
vs_len += sprintf(vs_buf + vs_len, "in vec%d aInput%d;\n", opt_alpha ? 4 : 3, i + 1);
vs_len += sprintf(vs_buf + vs_len, "out vec%d vInput%d;\n", opt_alpha ? 4 : 3, i + 1);
num_floats += opt_alpha ? 4 : 3;
}
append_line(vs_buf, &vs_len, "void main() {");
@ -312,23 +313,23 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
// Fragment shader
#ifdef USE_GLES
append_line(fs_buf, &fs_len, "#version 100");
append_line(fs_buf, &fs_len, "#version 300 es");
append_line(fs_buf, &fs_len, "precision mediump float;");
#else
append_line(fs_buf, &fs_len, "#version 120");
append_line(fs_buf, &fs_len, "#version 130");
#endif
if (ccf.used_textures[0] || ccf.used_textures[1]) {
append_line(fs_buf, &fs_len, "varying vec2 vTexCoord;");
append_line(fs_buf, &fs_len, opt_tex_persp ? "in vec2 vTexCoord;" : "noperspective in vec2 vTexCoord;");
}
if (opt_fog) {
append_line(fs_buf, &fs_len, "varying vec4 vFog;");
append_line(fs_buf, &fs_len, "in vec4 vFog;");
}
if (opt_light_map) {
append_line(fs_buf, &fs_len, "varying vec2 vLightMap;");
append_line(fs_buf, &fs_len, "in vec2 vLightMap;");
}
for (int i = 0; i < ccf.num_inputs; i++) {
fs_len += sprintf(fs_buf + fs_len, "varying vec%d vInput%d;\n", opt_alpha ? 4 : 3, i + 1);
fs_len += sprintf(fs_buf + fs_len, "in vec%d vInput%d;\n", opt_alpha ? 4 : 3, i + 1);
}
if (ccf.used_textures[0]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTex0;");

View file

@ -1095,6 +1095,7 @@ static void OPTIMIZE_O3 gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t
cm->use_2cycle = (rdp.other_mode_h & (3U << G_MDSFT_CYCLETYPE)) == G_CYC_2CYCLE;
cm->use_fog = (rdp.other_mode_l >> 30) == G_BL_CLR_FOG;
cm->light_map = (rsp.geometry_mode & G_LIGHT_MAP_EXT) == G_LIGHT_MAP_EXT;
cm->tex_persp = (rdp.other_mode_h & G_TP_PERSP) == G_TP_PERSP;
if (cm->texture_edge) {
cm->use_alpha = true;