diff --git a/image.go b/image.go index 1eacf5bc3..ae9868f4c 100644 --- a/image.go +++ b/image.go @@ -505,10 +505,10 @@ type DrawTrianglesShaderOptions struct { // Uniforms is a set of uniform variables for the shader. // The keys are the names of the uniform variables. - // The values must be a numeric type or a slice of a numeric type. + // The values must be a numeric type, or a slice or an array of a numeric type. // If the uniform variable type is an array, a vector or a matrix, - // you have to specify linearly flattened values as a slice. - // For example, if the uniform variable type is [4]vec4, the number of the slice values will be 16. + // you have to specify linearly flattened values as a slice or an array. + // For example, if the uniform variable type is [4]vec4, the length will be 16. Uniforms map[string]any // Images is a set of the source images. @@ -665,10 +665,10 @@ type DrawRectShaderOptions struct { // Uniforms is a set of uniform variables for the shader. // The keys are the names of the uniform variables. - // The values must be a numeric type or a slice of a numeric type. + // The values must be a numeric type, or a slice or an array of a numeric type. // If the uniform variable type is an array, a vector or a matrix, - // you have to specify linearly flattened values as a slice. - // For example, if the uniform variable type is [4]vec4, the number of the slice values will be 16. + // you have to specify linearly flattened values as a slice or an array. + // For example, if the uniform variable type is [4]vec4, the length will be 16. Uniforms map[string]any // Images is a set of the source images. diff --git a/internal/ui/shader.go b/internal/ui/shader.go index 6e5d4786c..d350ecc49 100644 --- a/internal/ui/shader.go +++ b/internal/ui/shader.go @@ -58,8 +58,7 @@ func (s *Shader) ConvertUniforms(uniforms map[string]any) [][]uint32 { nameToU32s[name] = []uint32{uint32(v.Uint())} case reflect.Float32, reflect.Float64: nameToU32s[name] = []uint32{math.Float32bits(float32(v.Float()))} - case reflect.Slice: - // TODO: Allow reflect.Array (#2448) + case reflect.Slice, reflect.Array: u32s := make([]uint32, v.Len()) switch t.Elem().Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: diff --git a/shader_test.go b/shader_test.go index d6e6be8a9..6050d22f5 100644 --- a/shader_test.go +++ b/shader_test.go @@ -1335,7 +1335,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { Want: color.RGBA{0x85, 0xa3, 0x08, 0xd3}, }, { - Name: "0xff,array", + Name: "0xff,slice", Uniforms: map[string]any{ "U": []int{0xff, 0xff, 0xff, 0xff}, }, @@ -1343,7 +1343,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { Want: color.RGBA{0xff, 0xff, 0xff, 0xff}, }, { - Name: "int,array", + Name: "int,slice", Uniforms: map[string]any{ "U": []int16{0x24, 0x3f, 0x6a, 0x88}, }, @@ -1351,13 +1351,37 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { Want: color.RGBA{0x24, 0x3f, 0x6a, 0x88}, }, { - Name: "uint,array", + Name: "uint,slice", Uniforms: map[string]any{ "U": []uint8{0x85, 0xa3, 0x08, 0xd3}, }, Shader: intArray, Want: color.RGBA{0x85, 0xa3, 0x08, 0xd3}, }, + { + Name: "0xff,array", + Uniforms: map[string]any{ + "U": [...]int{0xff, 0xff, 0xff, 0xff}, + }, + Shader: intArray, + Want: color.RGBA{0xff, 0xff, 0xff, 0xff}, + }, + { + Name: "int,array", + Uniforms: map[string]any{ + "U": [...]int16{0x24, 0x3f, 0x6a, 0x88}, + }, + Shader: intArray, + Want: color.RGBA{0x24, 0x3f, 0x6a, 0x88}, + }, + { + Name: "uint,array", + Uniforms: map[string]any{ + "U": [...]uint8{0x85, 0xa3, 0x08, 0xd3}, + }, + Shader: intArray, + Want: color.RGBA{0x85, 0xa3, 0x08, 0xd3}, + }, } for _, tc := range testCases { tc := tc