mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 04:22:05 +01:00
internal/shader: bug fix: wrong type conversion for min, max, and clamp
Closes #2922
This commit is contained in:
parent
dc05f2014f
commit
927e025982
@ -1192,6 +1192,10 @@ func resolveConstKind(exprs []shaderir.Expr, ts []shaderir.Type) (kind gconstant
|
||||
}
|
||||
}
|
||||
|
||||
if kind == gconstant.Float {
|
||||
return gconstant.Float, true
|
||||
}
|
||||
|
||||
// Prefer floats over integers for non-typed constant values.
|
||||
// For example, max(1.0, 1) should return a float value.
|
||||
if kind == gconstant.Unknown {
|
||||
|
@ -2188,6 +2188,18 @@ func TestSyntaxBuiltinFuncDoubleArgsType(t *testing.T) {
|
||||
{stmt: "a := {{.Func}}(1, 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.0, 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1, 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), 1); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(int(1), 1.0); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(int(1), 1.1); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(float(1), 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(float(1), 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(float(1), 1.1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1, int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1.0, int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1.1, int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.0, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.1, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, vec2(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, vec3(1)); _ = a", err: true},
|
||||
@ -2248,6 +2260,18 @@ func TestSyntaxBuiltinFuncDoubleArgsType2(t *testing.T) {
|
||||
{stmt: "a := {{.Func}}(1, 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.0, 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1, 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), 1); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(int(1), 1.0); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(int(1), 1.1); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(float(1), 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(float(1), 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(float(1), 1.1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1, int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1.0, int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1.1, int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.0, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.1, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, vec2(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, vec3(1)); _ = a", err: true},
|
||||
@ -2308,11 +2332,19 @@ func TestSyntaxBuiltinFuncArgsMinMax(t *testing.T) {
|
||||
{stmt: "a := {{.Func}}(1, 1.0); var _ float = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.1, 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1, 1.1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), int(1)); var _ int = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), 1); var _ int = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), 1.0); var _ int = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), 1.1); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(float(1), 1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(float(1), 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(float(1), 1.1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1, int(1)); var _ int = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.0, int(1)); var _ int = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.1, int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.0, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(1.1, float(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), int(1)); var _ int = a", err: false},
|
||||
{stmt: "a := {{.Func}}(int(1), float(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(float(1), int(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, vec2(1)); _ = a", err: true},
|
||||
@ -2322,14 +2354,20 @@ func TestSyntaxBuiltinFuncArgsMinMax(t *testing.T) {
|
||||
{stmt: "a := {{.Func}}(1, ivec3(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(1, ivec4(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(vec2(1), 1); _ = a", err: false}, // The second argument can be a scalar.
|
||||
{stmt: "a := {{.Func}}(vec2(1), 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec2(1), 1.1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec2(1), vec2(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec2(1), vec3(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(vec2(1), vec4(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(vec3(1), 1); _ = a", err: false}, // The second argument can be a scalar.
|
||||
{stmt: "a := {{.Func}}(vec3(1), 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec3(1), 1.1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec3(1), vec2(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(vec3(1), vec3(1)); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec3(1), vec4(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(vec4(1), 1); _ = a", err: false}, // The second argument can be a scalar.
|
||||
{stmt: "a := {{.Func}}(vec4(1), 1.0); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec4(1), 1.1); _ = a", err: false},
|
||||
{stmt: "a := {{.Func}}(vec4(1), vec2(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(vec4(1), vec3(1)); _ = a", err: true},
|
||||
{stmt: "a := {{.Func}}(vec4(1), vec4(1)); _ = a", err: false},
|
||||
@ -2504,6 +2542,11 @@ func TestSyntaxBuiltinFuncClampType(t *testing.T) {
|
||||
{stmt: "a := clamp(int(1), 1, 1.0); var _ int = a", err: false},
|
||||
{stmt: "a := clamp(int(1), 1.1, 1); _ = a", err: true},
|
||||
{stmt: "a := clamp(int(1), 1, 1.1); _ = a", err: true},
|
||||
{stmt: "a := clamp(float(1), 1, 1); var _ float = a", err: false},
|
||||
{stmt: "a := clamp(float(1), 1.0, 1); var _ float = a", err: false},
|
||||
{stmt: "a := clamp(float(1), 1, 1.0); var _ float = a", err: false},
|
||||
{stmt: "a := clamp(float(1), 1.1, 1); _ = a", err: false},
|
||||
{stmt: "a := clamp(float(1), 1, 1.1); _ = a", err: false},
|
||||
{stmt: "a := clamp(1.0, 1, 1); var _ float = a", err: false},
|
||||
{stmt: "a := clamp(1, 1.0, 1); var _ float = a", err: false},
|
||||
{stmt: "a := clamp(1, 1, 1.0); var _ float = a", err: false},
|
||||
|
Loading…
Reference in New Issue
Block a user