mirror of https://github.com/xemu-project/xemu.git
SQUASHME: review updates
This commit is contained in:
parent
906225d92f
commit
e83b247c75
|
@ -129,7 +129,7 @@ typedef struct ShaderBinding {
|
||||||
GLint material_alpha_loc;
|
GLint material_alpha_loc;
|
||||||
|
|
||||||
GLint color_key_loc[4];
|
GLint color_key_loc[4];
|
||||||
GLint color_key_ignore_alpha_loc[4];
|
GLint color_key_mask_loc[4];
|
||||||
} ShaderBinding;
|
} ShaderBinding;
|
||||||
|
|
||||||
typedef struct VertexKey {
|
typedef struct VertexKey {
|
||||||
|
|
|
@ -210,8 +210,8 @@ static void update_shader_constant_locations(ShaderBinding *binding)
|
||||||
binding->color_key_loc[i] =
|
binding->color_key_loc[i] =
|
||||||
glGetUniformLocation(binding->gl_program, tmp);
|
glGetUniformLocation(binding->gl_program, tmp);
|
||||||
|
|
||||||
snprintf(tmp, sizeof(tmp), "colorKeyIgnoreAlpha[%d]", i);
|
snprintf(tmp, sizeof(tmp), "colorKeyMask[%d]", i);
|
||||||
binding->color_key_ignore_alpha_loc[i] =
|
binding->color_key_mask_loc[i] =
|
||||||
glGetUniformLocation(binding->gl_program, tmp);
|
glGetUniformLocation(binding->gl_program, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,9 +781,9 @@ static void shader_update_constants(PGRAPHState *pg, ShaderBinding *binding,
|
||||||
glUniform1ui(binding->color_key_loc[i],
|
glUniform1ui(binding->color_key_loc[i],
|
||||||
pgraph_reg_r(pg, NV_PGRAPH_COLORKEYCOLOR0 + i * 4));
|
pgraph_reg_r(pg, NV_PGRAPH_COLORKEYCOLOR0 + i * 4));
|
||||||
}
|
}
|
||||||
if (binding->color_key_ignore_alpha_loc[i] != -1) {
|
if (binding->color_key_mask_loc[i] != -1) {
|
||||||
glUniform1i(binding->color_key_ignore_alpha_loc[i],
|
glUniform1ui(binding->color_key_mask_loc[i],
|
||||||
state->psh.colorkey_ignore_alpha[i]);
|
state->psh.colorkey_mask[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,9 +176,9 @@ enum PS_DOTMAPPING
|
||||||
|
|
||||||
enum PS_COLORKEYMODE {
|
enum PS_COLORKEYMODE {
|
||||||
COLOR_KEY_NONE = 0,
|
COLOR_KEY_NONE = 0,
|
||||||
COLOR_KEY_KILL_ALPHA = 0x01,
|
COLOR_KEY_KILL_ALPHA = 1,
|
||||||
COLOR_KEY_KILL_COLOR_AND_ALPHA = 0x02,
|
COLOR_KEY_KILL_COLOR_AND_ALPHA = 2,
|
||||||
COLOR_KEY_DISCARD = 0x03,
|
COLOR_KEY_DISCARD = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -743,12 +743,10 @@ static void define_colorkey_comparator(MString *preflight)
|
||||||
// clang-format off
|
// clang-format off
|
||||||
mstring_append(
|
mstring_append(
|
||||||
preflight,
|
preflight,
|
||||||
"bool check_color_key(vec4 texel, uint color_key, bool ignore_alpha) {\n"
|
"bool check_color_key(vec4 texel, uint color_key, uint color_key_mask) {\n"
|
||||||
" uvec4 components = uvec4(round(texel * 255.0));\n"
|
" uvec4 c = uvec4(texel * 255.0 + 0.5);\n"
|
||||||
" if (ignore_alpha) {\n"
|
" uint color = (c.a << 24) | (c.r << 16) | (c.g << 8) | c.b;\n"
|
||||||
" return uint((components.r << 16) + (components.g << 8) + components.b) == (color_key & 0x00FFFFFFu);\n"
|
" return (color & color_key_mask) == (color_key & color_key_mask);\n"
|
||||||
" }\n"
|
|
||||||
" return uint((components.a << 24) + (components.r << 16) + (components.g << 8) + components.b) == color_key;\n"
|
|
||||||
"}\n");
|
"}\n");
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
@ -777,7 +775,7 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
"%svec4 clipRange;\n"
|
"%svec4 clipRange;\n"
|
||||||
"%sfloat depthOffset;\n"
|
"%sfloat depthOffset;\n"
|
||||||
"%suint colorKey[4];\n"
|
"%suint colorKey[4];\n"
|
||||||
"%sint colorKeyIgnoreAlpha[4];\n",
|
"%suint colorKeyMask[4];\n",
|
||||||
u, u, u, u, u, u, u);
|
u, u, u, u, u, u, u);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
mstring_append_fmt(preflight, "%smat2 bumpMat%d;\n"
|
mstring_append_fmt(preflight, "%smat2 bumpMat%d;\n"
|
||||||
|
@ -1211,7 +1209,7 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
i);
|
i);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PS_COLORKEYMODE color_key_mode = ps->state.colorkeymode[i];
|
enum PS_COLORKEYMODE color_key_mode = ps->state.colorkey_mode[i];
|
||||||
if (color_key_mode != COLOR_KEY_NONE) {
|
if (color_key_mode != COLOR_KEY_NONE) {
|
||||||
if (!color_key_comparator_defined) {
|
if (!color_key_comparator_defined) {
|
||||||
define_colorkey_comparator(preflight);
|
define_colorkey_comparator(preflight);
|
||||||
|
@ -1221,7 +1219,7 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
// clang-format off
|
// clang-format off
|
||||||
mstring_append_fmt(
|
mstring_append_fmt(
|
||||||
vars,
|
vars,
|
||||||
"if (check_color_key(t%d, colorKey[%d], colorKeyIgnoreAlpha[%d] != 0)) {\n",
|
"if (check_color_key(t%d, colorKey[%d], colorKeyMask[%d])) {\n",
|
||||||
i, i, i);
|
i, i, i);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,8 @@ typedef struct PshState {
|
||||||
bool snorm_tex[4];
|
bool snorm_tex[4];
|
||||||
bool compare_mode[4][4];
|
bool compare_mode[4][4];
|
||||||
bool alphakill[4];
|
bool alphakill[4];
|
||||||
int colorkeymode[4];
|
int colorkey_mode[4];
|
||||||
bool colorkey_ignore_alpha[4];
|
uint32_t colorkey_mask[4];
|
||||||
enum ConvolutionFilter conv_tex[4];
|
enum ConvolutionFilter conv_tex[4];
|
||||||
bool tex_x8y24[4];
|
bool tex_x8y24[4];
|
||||||
int dim_tex[4];
|
int dim_tex[4];
|
||||||
|
|
|
@ -27,12 +27,18 @@
|
||||||
// TODO: https://github.com/xemu-project/xemu/issues/2260
|
// TODO: https://github.com/xemu-project/xemu/issues/2260
|
||||||
// Investigate how color keying is handled for components with no alpha or
|
// Investigate how color keying is handled for components with no alpha or
|
||||||
// only alpha.
|
// only alpha.
|
||||||
static bool color_format_ignores_alpha(unsigned int color_format)
|
static uint32_t get_colorkey_mask(unsigned int color_format)
|
||||||
{
|
{
|
||||||
return color_format == NV097_SET_TEXTURE_FORMAT_COLOR_SZ_X1R5G5B5 ||
|
switch (color_format) {
|
||||||
color_format == NV097_SET_TEXTURE_FORMAT_COLOR_SZ_X8R8G8B8 ||
|
case NV097_SET_TEXTURE_FORMAT_COLOR_SZ_X1R5G5B5:
|
||||||
color_format == NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_X1R5G5B5 ||
|
case NV097_SET_TEXTURE_FORMAT_COLOR_SZ_X8R8G8B8:
|
||||||
color_format == NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_X8R8G8B8;
|
case NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_X1R5G5B5:
|
||||||
|
case NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_X8R8G8B8:
|
||||||
|
return 0x00FFFFFF;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0xFFFFFFFF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderState pgraph_get_shader_state(PGRAPHState *pg)
|
ShaderState pgraph_get_shader_state(PGRAPHState *pg)
|
||||||
|
@ -230,7 +236,7 @@ ShaderState pgraph_get_shader_state(PGRAPHState *pg)
|
||||||
}
|
}
|
||||||
|
|
||||||
state.psh.alphakill[i] = ctl_0 & NV_PGRAPH_TEXCTL0_0_ALPHAKILLEN;
|
state.psh.alphakill[i] = ctl_0 & NV_PGRAPH_TEXCTL0_0_ALPHAKILLEN;
|
||||||
state.psh.colorkeymode[i] = ctl_0 & NV_PGRAPH_TEXCTL0_0_COLORKEYMODE;
|
state.psh.colorkey_mode[i] = ctl_0 & NV_PGRAPH_TEXCTL0_0_COLORKEYMODE;
|
||||||
|
|
||||||
uint32_t tex_fmt = pgraph_reg_r(pg, NV_PGRAPH_TEXFMT0 + i * 4);
|
uint32_t tex_fmt = pgraph_reg_r(pg, NV_PGRAPH_TEXFMT0 + i * 4);
|
||||||
state.psh.dim_tex[i] = GET_MASK(tex_fmt, NV_PGRAPH_TEXFMT0_DIMENSIONALITY);
|
state.psh.dim_tex[i] = GET_MASK(tex_fmt, NV_PGRAPH_TEXFMT0_DIMENSIONALITY);
|
||||||
|
@ -240,8 +246,7 @@ ShaderState pgraph_get_shader_state(PGRAPHState *pg)
|
||||||
state.psh.rect_tex[i] = f.linear;
|
state.psh.rect_tex[i] = f.linear;
|
||||||
state.psh.tex_x8y24[i] = color_format == NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_DEPTH_X8_Y24_FIXED ||
|
state.psh.tex_x8y24[i] = color_format == NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_DEPTH_X8_Y24_FIXED ||
|
||||||
color_format == NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_DEPTH_X8_Y24_FLOAT;
|
color_format == NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_DEPTH_X8_Y24_FLOAT;
|
||||||
state.psh.colorkey_ignore_alpha[i] =
|
state.psh.colorkey_mask[i] = get_colorkey_mask(color_format);
|
||||||
color_format_ignores_alpha(color_format);
|
|
||||||
|
|
||||||
uint32_t border_source =
|
uint32_t border_source =
|
||||||
GET_MASK(tex_fmt, NV_PGRAPH_TEXFMT0_BORDER_SOURCE);
|
GET_MASK(tex_fmt, NV_PGRAPH_TEXFMT0_BORDER_SOURCE);
|
||||||
|
|
|
@ -196,7 +196,7 @@ typedef struct ShaderBinding {
|
||||||
int material_alpha_loc;
|
int material_alpha_loc;
|
||||||
|
|
||||||
int color_key_loc;
|
int color_key_loc;
|
||||||
int color_key_ignore_alpha_loc;
|
int color_key_mask_loc;
|
||||||
|
|
||||||
int uniform_attrs_loc;
|
int uniform_attrs_loc;
|
||||||
} ShaderBinding;
|
} ShaderBinding;
|
||||||
|
|
|
@ -315,8 +315,8 @@ static void update_shader_constant_locations(ShaderBinding *binding)
|
||||||
binding->color_key_loc =
|
binding->color_key_loc =
|
||||||
uniform_index(&binding->fragment->uniforms, "colorKey");
|
uniform_index(&binding->fragment->uniforms, "colorKey");
|
||||||
|
|
||||||
binding->color_key_ignore_alpha_loc =
|
binding->color_key_mask_loc =
|
||||||
uniform_index(&binding->fragment->uniforms, "colorKeyIgnoreAlpha");
|
uniform_index(&binding->fragment->uniforms, "colorKeyMask");
|
||||||
|
|
||||||
binding->uniform_attrs_loc =
|
binding->uniform_attrs_loc =
|
||||||
uniform_index(&binding->vertex->uniforms, "inlineValue");
|
uniform_index(&binding->vertex->uniforms, "inlineValue");
|
||||||
|
@ -506,10 +506,9 @@ static void shader_update_constants(PGRAPHState *pg, ShaderBinding *binding,
|
||||||
uniform1uiv(&binding->fragment->uniforms, binding->color_key_loc, 4,
|
uniform1uiv(&binding->fragment->uniforms, binding->color_key_loc, 4,
|
||||||
color_key_colors);
|
color_key_colors);
|
||||||
}
|
}
|
||||||
if (binding->color_key_ignore_alpha_loc != -1) {
|
if (binding->color_key_mask_loc != -1) {
|
||||||
uniform1iv(&binding->fragment->uniforms,
|
uniform1uiv(&binding->fragment->uniforms, binding->color_key_mask_loc,
|
||||||
binding->color_key_ignore_alpha_loc, 4,
|
4, state->psh.colorkey_mask);
|
||||||
(int32_t *)&state->psh.colorkey_ignore_alpha);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For each texture stage */
|
/* For each texture stage */
|
||||||
|
|
Loading…
Reference in New Issue