Skip to content

Commit

Permalink
Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into…
Browse files Browse the repository at this point in the history
… port-debugger
  • Loading branch information
fgsfdsfgs committed May 12, 2024
2 parents 86eaa62 + 1d040b1 commit bf1b8da
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 318 deletions.
18 changes: 0 additions & 18 deletions port/fast3d/gfx_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ void gfx_cc_get_features(uint64_t shader_id0, uint32_t shader_id1, struct CCFeat

cc_features->used_textures[0] = false;
cc_features->used_textures[1] = false;
cc_features->used_masks[0] = false;
cc_features->used_masks[1] = false;
cc_features->used_blend[0] = false;
cc_features->used_blend[1] = false;
cc_features->num_inputs = 0;

for (int c = 0; c < 2; c++) {
Expand Down Expand Up @@ -60,18 +56,4 @@ void gfx_cc_get_features(uint64_t shader_id0, uint32_t shader_id1, struct CCFeat
cc_features->color_alpha_same[c] =
((shader_id0 >> c * 32) & 0xffff) == ((shader_id0 >> (c * 32 + 16)) & 0xffff);
}

if (cc_features->used_textures[0] && (shader_id1 & SHADER_OPT_TEXEL0_MASK)) {
cc_features->used_masks[0] = true;
}
if (cc_features->used_textures[1] && (shader_id1 & SHADER_OPT_TEXEL1_MASK)) {
cc_features->used_masks[1] = true;
}

if (cc_features->used_textures[0] && (shader_id1 & SHADER_OPT_TEXEL0_BLEND)) {
cc_features->used_blend[0] = true;
}
if (cc_features->used_textures[1] && (shader_id1 & SHADER_OPT_TEXEL1_BLEND)) {
cc_features->used_blend[1] = true;
}
}
26 changes: 4 additions & 22 deletions port/fast3d/gfx_cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
#include <compare>
#endif

/*enum {
CC_0,
CC_TEXEL0,
CC_TEXEL1,
CC_PRIM,
CC_SHADE,
CC_ENV,
CC_TEXEL0A,
CC_LOD
};*/

enum {
SHADER_0,
SHADER_INPUT_1,
Expand All @@ -34,7 +23,8 @@ enum {
SHADER_TEXEL1A,
SHADER_1,
SHADER_COMBINED,
SHADER_NOISE
SHADER_NOISE,
SHADER_LOD_FRAC,
};

#define SHADER_OPT_ALPHA (1 << 0)
Expand All @@ -49,22 +39,16 @@ enum {
#define SHADER_OPT_TEXEL0_CLAMP_T (1 << 9)
#define SHADER_OPT_TEXEL1_CLAMP_S (1 << 10)
#define SHADER_OPT_TEXEL1_CLAMP_T (1 << 11)
#define SHADER_OPT_TEXEL0_MASK (1 << 12)
#define SHADER_OPT_TEXEL1_MASK (1 << 13)
#define SHADER_OPT_TEXEL0_BLEND (1 << 14)
#define SHADER_OPT_TEXEL1_BLEND (1 << 15)
#define SHADER_OPT_BLUR (1 << 16)
#define SHADER_OPT_BLUR (1 << 12)

struct ColorCombinerKey {
uint64_t combine_mode;
uint64_t options;
auto operator<=>(const ColorCombinerKey&) const = default;
};

#define SHADER_MAX_TEXTURES 6
#define SHADER_MAX_TEXTURES 2
#define SHADER_FIRST_TEXTURE 0
#define SHADER_FIRST_MASK_TEXTURE 2
#define SHADER_FIRST_REPLACEMENT_TEXTURE 4

struct CCFeatures {
uint8_t c[2][2][4];
Expand All @@ -78,8 +62,6 @@ struct CCFeatures {
bool opt_grayscale;
bool opt_blur;
bool used_textures[2];
bool used_masks[2];
bool used_blend[2];
bool clamp[2][2];
int num_inputs;
bool do_single[2][2];
Expand Down
51 changes: 1 addition & 50 deletions port/fast3d/gfx_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,6 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
if (cc_features.used_textures[1]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTex1;");
}
if (cc_features.used_masks[0]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTexMask0;");
}
if (cc_features.used_masks[1]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTexMask1;");
}
if (cc_features.used_blend[0]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTexBlend0;");
}
if (cc_features.used_blend[1]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTexBlend1;");
}

append_line(fs_buf, &fs_len, "uniform int frame_count;");
append_line(fs_buf, &fs_len, "uniform float noise_scale;");
Expand Down Expand Up @@ -473,24 +461,7 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
}
}

fs_len += sprintf(fs_buf + fs_len, "vec4 texVal%d = hookTexture2D(uTex%d, vTexCoordAdj%d, texSize%d);\n", i,
i, i, i);
if (cc_features.used_masks[i]) {
fs_len += sprintf(fs_buf + fs_len, "vec2 maskSize%d = textureSize(uTexMask%d, 0);\n", i, i);

fs_len +=
sprintf(fs_buf + fs_len,
"vec4 maskVal%d = hookTexture2D(uTexMask%d, vTexCoordAdj%d, maskSize%d);\n", i, i, i, i);
if (cc_features.used_blend[i]) {
fs_len += sprintf(fs_buf + fs_len,
"vec4 blendVal%d = hookTexture2D(uTexBlend%d, vTexCoordAdj%d, texSize%d);\n", i,
i, i, i);
} else {
fs_len += sprintf(fs_buf + fs_len, "vec4 blendVal%d = vec4(0, 0, 0, 0);\n", i);
}

fs_len += sprintf(fs_buf + fs_len, "texVal%d = mix(texVal%d, blendVal%d, maskVal%d.a);\n", i, i, i, i);
}
fs_len += sprintf(fs_buf + fs_len, "vec4 texVal%d = hookTexture2D(uTex%d, vTexCoordAdj%d, texSize%d);\n", i, i, i, i);
}
}

Expand Down Expand Up @@ -653,10 +624,6 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
prg->num_inputs = cc_features.num_inputs;
prg->used_textures[0] = cc_features.used_textures[0];
prg->used_textures[1] = cc_features.used_textures[1];
prg->used_textures[2] = cc_features.used_masks[0];
prg->used_textures[3] = cc_features.used_masks[1];
prg->used_textures[4] = cc_features.used_blend[0];
prg->used_textures[5] = cc_features.used_blend[1];
prg->num_floats = num_floats;
prg->num_attribs = cnt;

Expand All @@ -670,22 +637,6 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
GLint sampler_location = glGetUniformLocation(shader_program, "uTex1");
glUniform1i(sampler_location, 1);
}
if (cc_features.used_masks[0]) {
GLint sampler_location = glGetUniformLocation(shader_program, "uTexMask0");
glUniform1i(sampler_location, 2);
}
if (cc_features.used_masks[1]) {
GLint sampler_location = glGetUniformLocation(shader_program, "uTexMask1");
glUniform1i(sampler_location, 3);
}
if (cc_features.used_blend[0]) {
GLint sampler_location = glGetUniformLocation(shader_program, "uTexBlend0");
glUniform1i(sampler_location, 4);
}
if (cc_features.used_blend[1]) {
GLint sampler_location = glGetUniformLocation(shader_program, "uTexBlend1");
glUniform1i(sampler_location, 5);
}

prg->frame_count_location = glGetUniformLocation(shader_program, "frame_count");
prg->noise_scale_location = glGetUniformLocation(shader_program, "noise_scale");
Expand Down
Loading

0 comments on commit bf1b8da

Please sign in to comment.