From a9b2f5f9cac112f2ebd728ce4cefc06742115e6f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 24 Aug 2023 14:13:16 +0900 Subject: [PATCH] Revert "ebiten: panic if a non-existent uniform variable name is given" This reverts commit 1b8580fab777c05750d0aa15af81537f05bf4df1. Reason: some existing applications don't work with this fix. Updates #2710 --- image.go | 4 ---- internal/ui/shader.go | 17 +---------------- shader_test.go | 12 ------------ 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/image.go b/image.go index 9d0ea2dcf..95b74835b 100644 --- a/image.go +++ b/image.go @@ -582,8 +582,6 @@ var _ [len(DrawTrianglesShaderOptions{}.Images) - graphics.ShaderImageCount]stru // // If a specified uniform variable's length or type doesn't match with an expected one, DrawTrianglesShader panics. // -// If a non-existent uniform variable name is specified, DrawTrianglesShader panics. -// // When the image i is disposed, DrawTrianglesShader does nothing. func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader *Shader, options *DrawTrianglesShaderOptions) { i.copyCheck() @@ -736,8 +734,6 @@ var _ [len(DrawRectShaderOptions{}.Images)]struct{} = [graphics.ShaderImageCount // // If a specified uniform variable's length or type doesn't match with an expected one, DrawRectShader panics. // -// If a non-existent uniform variable name is specified, DrawRectShader panics. -// // In a shader, texCoord in Fragment represents a position in a source image. // If no source images are specified, texCoord represents the position from (0, 0) to (width, height) in pixels. // If the unit is pixels by a compiler directive `//kage:unit pixelss`, texCoord values are valid. diff --git a/internal/ui/shader.go b/internal/ui/shader.go index 68898a37e..6d034daac 100644 --- a/internal/ui/shader.go +++ b/internal/ui/shader.go @@ -46,22 +46,6 @@ func (s *Shader) MarkDisposed() { } func (s *Shader) AppendUniforms(dst []uint32, uniforms map[string]any) []uint32 { - // Check the given names are valid. - // This is a linear search and not efficient, but the number of uniform variables should not be so big. - for n := range uniforms { - var found bool - for _, nn := range s.uniformNames { - if n == nn { - found = true - break - } - } - if found { - continue - } - panic(fmt.Sprintf("ui: unexpected uniform name: %s", n)) - } - if s.uniformUint32Count == 0 { for _, typ := range s.uniformTypes { s.uniformUint32Count += typ.Uint32Count() @@ -82,6 +66,7 @@ func (s *Shader) AppendUniforms(dst []uint32, uniforms map[string]any) []uint32 for i, name := range s.uniformNames { typ := s.uniformTypes[i] + // Ignore if an unused name is specified (#2710). if uv, ok := uniforms[name]; ok { v := reflect.ValueOf(uv) t := v.Type() diff --git a/shader_test.go b/shader_test.go index e32549471..a438d7833 100644 --- a/shader_test.go +++ b/shader_test.go @@ -1942,18 +1942,6 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { }, err: true, }, - { - uniforms: map[string]any{ - "W": 1, - }, - err: true, - }, - { - uniforms: map[string]any{ - "W": []int32{1, 2, 3}, - }, - err: true, - }, } for _, tc := range tests { tc := tc