From 63df6168d97e289905a56cd557c799ede7625eeb Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 1 Aug 2023 11:41:27 +0900 Subject: [PATCH] internal/shader: use plural forms for Kage compiler directives This change renames ``` //kage:unit texel //kage:unit pixel ``` to ``` //kage:unit texels //kage:unit pixels ``` . Closes #2717 --- examples/shader/chromaticaberration.go | 2 +- examples/shader/default.go | 2 +- examples/shader/dissolve.go | 2 +- examples/shader/lighting.go | 2 +- examples/shader/radialblur.go | 2 +- examples/shader/texel.go | 2 +- examples/shader/water.go | 2 +- gameforui.go | 2 +- image.go | 4 +- internal/atlas/image.go | 2 +- internal/builtinshader/shader.go | 2 +- internal/graphics/shader.go | 4 +- internal/graphicscommand/command.go | 4 +- internal/restorable/shader.go | 2 +- internal/shader/shader.go | 10 +-- internal/shader/shader_test.go | 2 +- internal/shader/syntax_test.go | 18 +++--- internal/shaderir/glsl/type.go | 2 +- internal/shaderir/hlsl/hlsl.go | 6 +- internal/shaderir/ir_test.go | 44 +++++++------- internal/shaderir/msl/msl.go | 6 +- internal/shaderir/program.go | 4 +- internal/testing/shader.go | 4 +- shader_test.go | 84 +++++++++++++------------- 24 files changed, 107 insertions(+), 107 deletions(-) diff --git a/examples/shader/chromaticaberration.go b/examples/shader/chromaticaberration.go index 516f785ff..f8bafc483 100644 --- a/examples/shader/chromaticaberration.go +++ b/examples/shader/chromaticaberration.go @@ -14,7 +14,7 @@ //go:build ignore -//kage:unit pixel +//kage:unit pixels package main diff --git a/examples/shader/default.go b/examples/shader/default.go index 15d5d2ca8..483f49da7 100644 --- a/examples/shader/default.go +++ b/examples/shader/default.go @@ -14,7 +14,7 @@ //go:build ignore -//kage:unit pixel +//kage:unit pixels package main diff --git a/examples/shader/dissolve.go b/examples/shader/dissolve.go index 765ed565d..dda65badb 100644 --- a/examples/shader/dissolve.go +++ b/examples/shader/dissolve.go @@ -14,7 +14,7 @@ //go:build ignore -//kage:unit pixel +//kage:unit pixels package main diff --git a/examples/shader/lighting.go b/examples/shader/lighting.go index 01236910f..2786224ff 100644 --- a/examples/shader/lighting.go +++ b/examples/shader/lighting.go @@ -14,7 +14,7 @@ //go:build ignore -//kage:unit pixel +//kage:unit pixels package main diff --git a/examples/shader/radialblur.go b/examples/shader/radialblur.go index 55d0e1f6a..c77058969 100644 --- a/examples/shader/radialblur.go +++ b/examples/shader/radialblur.go @@ -14,7 +14,7 @@ //go:build ignore -//kage:unit pixel +//kage:unit pixels package main diff --git a/examples/shader/texel.go b/examples/shader/texel.go index 7b8d4dab0..74b3c2ec0 100644 --- a/examples/shader/texel.go +++ b/examples/shader/texel.go @@ -14,7 +14,7 @@ //go:build ignore -//kage:unit pixel +//kage:unit pixels package main diff --git a/examples/shader/water.go b/examples/shader/water.go index cb57c3e11..d07aadd4a 100644 --- a/examples/shader/water.go +++ b/examples/shader/water.go @@ -14,7 +14,7 @@ //go:build ignore -//kage:unit pixel +//kage:unit pixels package main diff --git a/gameforui.go b/gameforui.go index edcb27d34..bf56f3790 100644 --- a/gameforui.go +++ b/gameforui.go @@ -24,7 +24,7 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/ui" ) -const screenShaderSrc = `//kage:unit pixel +const screenShaderSrc = `//kage:unit pixels package main diff --git a/image.go b/image.go index a8c7ea52c..9d0ea2dcf 100644 --- a/image.go +++ b/image.go @@ -740,7 +740,7 @@ var _ [len(DrawRectShaderOptions{}.Images)]struct{} = [graphics.ShaderImageCount // // 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 pixels`, texCoord values are valid. +// If the unit is pixels by a compiler directive `//kage:unit pixelss`, texCoord values are valid. // If the unit is texels (default), texCoord values still take from (0, 0) to (width, height), // but these are invalid since texCoord is expected to be in texels in the texel-unit mode. // This behavior is preserved for backward compatibility. It is recommended to use the pixel-unit mode to avoid confusion. @@ -787,7 +787,7 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR b := img.Bounds() sx, sy = img.adjustPosition(b.Min.X, b.Min.Y) sr = img.adjustedRegion() - } else if shader.unit == shaderir.Pixel { + } else if shader.unit == shaderir.Pixels { // Give the source size as pixels only when the unit is pixels so that users can get the source size via imageSrcRegionOnTexture (#2166). // With the texel mode, the imageSrcRegionOnTexture values should be in texels so the source position in pixels would not match. sr = graphicsdriver.Region{ diff --git a/internal/atlas/image.go b/internal/atlas/image.go index c93f9831f..810d9922b 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -412,7 +412,7 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [ vertices[i+2] += oxf vertices[i+3] += oyf } - if shader.unit() == shaderir.Texel { + if shader.unit() == shaderir.Texels { sw, sh := srcs[0].backend.restorable.InternalSize() swf, shf := float32(sw), float32(sh) for i := 0; i < n; i += graphics.VertexFloatCount { diff --git a/internal/builtinshader/shader.go b/internal/builtinshader/shader.go index f07d9d156..ed8fcea0c 100644 --- a/internal/builtinshader/shader.go +++ b/internal/builtinshader/shader.go @@ -52,7 +52,7 @@ var ( shadersM sync.Mutex ) -var tmpl = template.Must(template.New("tmpl").Parse(`//kage:unit pixel +var tmpl = template.Must(template.New("tmpl").Parse(`//kage:unit pixels package main diff --git a/internal/graphics/shader.go b/internal/graphics/shader.go index 782a94126..ed9f922ed 100644 --- a/internal/graphics/shader.go +++ b/internal/graphics/shader.go @@ -79,9 +79,9 @@ func imageSrcRegionOnTexture() (vec2, vec2) { if i >= 1 { // Convert the position in texture0's positions to the target texture positions. switch unit { - case shaderir.Pixel: + case shaderir.Pixels: pos = fmt.Sprintf("pos + __textureSourceOffsets[%d]", i-1) - case shaderir.Texel: + case shaderir.Texels: pos = fmt.Sprintf("(pos * __textureSizes[0] + __textureSourceOffsets[%d]) / __textureSizes[%d]", i-1, i) default: return "", fmt.Errorf("graphics: unexpected unit: %d", unit) diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index aa77f1102..bd10413d8 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -694,7 +694,7 @@ func (q *commandQueue) prependPreservedUniforms(uniforms []uint32, shader *Shade uniforms[9] = math.Float32bits(float32(h)) } - if shader.unit() == shaderir.Texel { + if shader.unit() == shaderir.Texels { dstRegion.X /= float32(dw) dstRegion.Y /= float32(dh) dstRegion.Width /= float32(dw) @@ -707,7 +707,7 @@ func (q *commandQueue) prependPreservedUniforms(uniforms []uint32, shader *Shade uniforms[12] = math.Float32bits(dstRegion.Width) uniforms[13] = math.Float32bits(dstRegion.Height) - if shader.unit() == shaderir.Texel && srcs[0] != nil { + if shader.unit() == shaderir.Texels && srcs[0] != nil { w, h := srcs[0].InternalSize() srcRegion.X /= float32(w) srcRegion.Y /= float32(h) diff --git a/internal/restorable/shader.go b/internal/restorable/shader.go index 6407ce0a3..cc4d1a9f4 100644 --- a/internal/restorable/shader.go +++ b/internal/restorable/shader.go @@ -80,7 +80,7 @@ func init() { return nil }) wg.Go(func() error { - ir, err := graphics.CompileShader([]byte(`//kage:unit pixel + ir, err := graphics.CompileShader([]byte(`//kage:unit pixels package main diff --git a/internal/shader/shader.go b/internal/shader/shader.go index f96a25178..7058c61fc 100644 --- a/internal/shader/shader.go +++ b/internal/shader/shader.go @@ -220,7 +220,7 @@ func Compile(src []byte, vertexEntry, fragmentEntry string, textureCount int) (* func ParseCompilerDirectives(src []byte) (shaderir.Unit, error) { // TODO: Change the unit to pixels in v3 (#2645). - unit := shaderir.Texel + unit := shaderir.Texels reUnit := regexp.MustCompile(`^//kage:unit\s+(.+)$`) var unitParsed bool @@ -236,10 +236,10 @@ func ParseCompilerDirectives(src []byte) (shaderir.Unit, error) { return 0, fmt.Errorf("shader: at most one //kage:unit can exist in a shader") } switch m[1] { - case "pixel": - unit = shaderir.Pixel - case "texel": - unit = shaderir.Texel + case "pixels": + unit = shaderir.Pixels + case "texels": + unit = shaderir.Texels default: return 0, fmt.Errorf("shader: invalid value for //kage:unit: %s", m[1]) } diff --git a/internal/shader/shader_test.go b/internal/shader/shader_test.go index 1199aeff7..45e5b0a43 100644 --- a/internal/shader/shader_test.go +++ b/internal/shader/shader_test.go @@ -53,7 +53,7 @@ func hlslNormalize(str string) string { } func metalNormalize(str string) string { - prelude := msl.Prelude(shaderir.Texel) + prelude := msl.Prelude(shaderir.Texels) if strings.HasPrefix(str, prelude) { str = str[len(prelude):] } diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index 82c32f6d2..0128b07ca 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -3137,29 +3137,29 @@ func TestCompilerDirective(t *testing.T) { func Fragment(position vec4, texCoord vec2, color vec4) vec4 { return position }`, - unit: shaderir.Texel, + unit: shaderir.Texels, err: false, }, { - src: `//kage:unit texel + src: `//kage:unit texels package main func Fragment(position vec4, texCoord vec2, color vec4) vec4 { return position }`, - unit: shaderir.Texel, + unit: shaderir.Texels, err: false, }, { - src: `//kage:unit pixel + src: `//kage:unit pixels package main func Fragment(position vec4, texCoord vec2, color vec4) vec4 { return position }`, - unit: shaderir.Pixel, + unit: shaderir.Pixels, err: false, }, { @@ -3173,8 +3173,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { err: true, }, { - src: `//kage:unit pixel -//kage:unit pixel + src: `//kage:unit pixels +//kage:unit pixels package main @@ -3184,8 +3184,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { err: true, }, { - src: `//kage:unit pixel -//kage:unit texel + src: `//kage:unit pixels +//kage:unit texels package main diff --git a/internal/shaderir/glsl/type.go b/internal/shaderir/glsl/type.go index 9363a45c6..85dfe28f6 100644 --- a/internal/shaderir/glsl/type.go +++ b/internal/shaderir/glsl/type.go @@ -122,7 +122,7 @@ func (c *compileContext) builtinFuncString(f shaderir.BuiltinFunc) string { case shaderir.Dfdy: return "dFdy" case shaderir.TexelAt: - if c.unit == shaderir.Pixel { + if c.unit == shaderir.Pixels { return "texelFetch" } return "texture" diff --git a/internal/shaderir/hlsl/hlsl.go b/internal/shaderir/hlsl/hlsl.go index 374accac5..ca43cad45 100644 --- a/internal/shaderir/hlsl/hlsl.go +++ b/internal/shaderir/hlsl/hlsl.go @@ -121,7 +121,7 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string, offsets []i for i := 0; i < p.TextureCount; i++ { lines = append(lines, fmt.Sprintf("Texture2D T%[1]d : register(t%[1]d);", i)) } - if c.unit == shaderir.Texel { + if c.unit == shaderir.Texels { lines = append(lines, "SamplerState samp : register(s0);") } } @@ -471,9 +471,9 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl } case shaderir.TexelAt: switch c.unit { - case shaderir.Pixel: + case shaderir.Pixels: return fmt.Sprintf("%s.Load(int3(%s, 0))", args[0], strings.Join(args[1:], ", ")) - case shaderir.Texel: + case shaderir.Texels: return fmt.Sprintf("%s.Sample(samp, %s)", args[0], strings.Join(args[1:], ", ")) default: panic(fmt.Sprintf("hlsl: unexpected unit: %d", p.Unit)) diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index 66350fe7d..8bb68bce0 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -181,7 +181,7 @@ func TestOutput(t *testing.T) { { Name: "Empty", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, }, GlslVS: glsl.VertexPrelude(glsl.GLSLVersionDefault), GlslFS: glsl.FragmentPrelude(glsl.GLSLVersionDefault), @@ -189,7 +189,7 @@ func TestOutput(t *testing.T) { { Name: "Uniform", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Uniforms: []shaderir.Type{ {Main: shaderir.Float}, }, @@ -202,7 +202,7 @@ uniform float U0;`, { Name: "UniformStruct", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Uniforms: []shaderir.Type{ { Main: shaderir.Struct, @@ -228,7 +228,7 @@ uniform S0 U0;`, { Name: "Vars", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Uniforms: []shaderir.Type{ {Main: shaderir.Float}, }, @@ -250,7 +250,7 @@ in vec3 V0;`, { Name: "Func", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -271,7 +271,7 @@ void F0(void) { { Name: "FuncParams", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -300,7 +300,7 @@ void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) { { Name: "FuncReturn", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -334,7 +334,7 @@ float F0(in float l0) { { Name: "FuncLocals", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -369,7 +369,7 @@ void F0(in float l0, out float l1) { { Name: "FuncBlocks", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -424,7 +424,7 @@ void F0(in float l0, out float l1) { { Name: "Add", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -466,7 +466,7 @@ void F0(in float l0, in float l1, out float l2) { { Name: "Selection", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -509,7 +509,7 @@ void F0(in bool l0, in float l1, in float l2, out float l3) { { Name: "Call", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -558,7 +558,7 @@ void F0(in float l0, in float l1, out vec2 l2) { { Name: "BuiltinFunc", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -600,7 +600,7 @@ void F0(in float l0, in float l1, out float l2) { { Name: "FieldSelector", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -640,7 +640,7 @@ void F0(in vec4 l0, out vec2 l1) { { Name: "If", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -705,7 +705,7 @@ void F0(in float l0, in float l1, out float l2) { { Name: "For", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -761,7 +761,7 @@ void F0(in float l0, in float l1, out float l2) { { Name: "For2", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -817,7 +817,7 @@ void F0(in float l0, in float l1, out float l2) { l2 = l4; } }`, - Metal: msl.Prelude(shaderir.Pixel) + ` + Metal: msl.Prelude(shaderir.Pixels) + ` void F0(float l0, float l1, thread float& l2); @@ -831,7 +831,7 @@ void F0(float l0, float l1, thread float& l2) { { Name: "For3", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Funcs: []shaderir.Func{ { Index: 0, @@ -914,7 +914,7 @@ void F0(in float l0, in float l1, out float l2) { l2 = l5; } }`, - Metal: msl.Prelude(shaderir.Pixel) + ` + Metal: msl.Prelude(shaderir.Pixels) + ` void F0(float l0, float l1, thread float& l2); @@ -932,7 +932,7 @@ void F0(float l0, float l1, thread float& l2) { { Name: "VertexFunc", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Uniforms: []shaderir.Type{ {Main: shaderir.Float}, }, @@ -985,7 +985,7 @@ in vec2 V1;`, { Name: "FragmentFunc", Program: shaderir.Program{ - Unit: shaderir.Pixel, + Unit: shaderir.Pixels, Uniforms: []shaderir.Type{ {Main: shaderir.Float}, }, diff --git a/internal/shaderir/msl/msl.go b/internal/shaderir/msl/msl.go index 32bf766e0..5951c9186 100644 --- a/internal/shaderir/msl/msl.go +++ b/internal/shaderir/msl/msl.go @@ -57,7 +57,7 @@ template T mod(T x, U y) { return x - y * floor(x/y); }` - if unit == shaderir.Texel { + if unit == shaderir.Texels { str += ` constexpr sampler texture_sampler{filter::nearest};` @@ -396,9 +396,9 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl } if callee.Type == shaderir.BuiltinFuncExpr && callee.BuiltinFunc == shaderir.TexelAt { switch p.Unit { - case shaderir.Texel: + case shaderir.Texels: return fmt.Sprintf("%s.sample(texture_sampler, %s)", args[0], strings.Join(args[1:], ", ")) - case shaderir.Pixel: + case shaderir.Pixels: return fmt.Sprintf("%s.read(static_cast(%s))", args[0], strings.Join(args[1:], ", ")) default: panic(fmt.Sprintf("msl: unexpected unit: %d", p.Unit)) diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index 3c73f912f..10b42da3d 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -25,8 +25,8 @@ import ( type Unit int const ( - Texel Unit = iota - Pixel + Texels Unit = iota + Pixels ) type Program struct { diff --git a/internal/testing/shader.go b/internal/testing/shader.go index 479b20afa..5fc8d0d3d 100644 --- a/internal/testing/shader.go +++ b/internal/testing/shader.go @@ -24,7 +24,7 @@ import ( // ShaderProgramFill returns a shader source to fill the frambuffer. func ShaderProgramFill(r, g, b, a byte) *shaderir.Program { - ir, err := graphics.CompileShader([]byte(fmt.Sprintf(`//kage:unit pixel + ir, err := graphics.CompileShader([]byte(fmt.Sprintf(`//kage:unit pixels package main @@ -49,7 +49,7 @@ func ShaderProgramImages(numImages int) *shaderir.Program { exprs = append(exprs, fmt.Sprintf("imageSrc%dUnsafeAt(texCoord)", i)) } - ir, err := graphics.CompileShader([]byte(fmt.Sprintf(`//kage:unit pixel + ir, err := graphics.CompileShader([]byte(fmt.Sprintf(`//kage:unit pixels package main diff --git a/shader_test.go b/shader_test.go index 7386a6cfa..92d2248e3 100644 --- a/shader_test.go +++ b/shader_test.go @@ -28,7 +28,7 @@ func TestShaderFill(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -60,7 +60,7 @@ func TestShaderFillWithDrawImage(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -97,7 +97,7 @@ func TestShaderWithDrawImageDoesNotWreckTextureUnits(t *testing.T) { rect := image.Rectangle{Max: image.Point{X: w, Y: h}} dst := ebiten.NewImageWithOptions(rect, &ebiten.NewImageOptions{Unmanaged: true}) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -167,7 +167,7 @@ func TestShaderFillWithDrawTriangles(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -244,7 +244,7 @@ func TestShaderFunction(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -277,7 +277,7 @@ func TestShaderUninitializedUniformVariables(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -308,7 +308,7 @@ func TestShaderMatrix(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -348,7 +348,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { func TestShaderSubImage(t *testing.T) { const w, h = 16, 16 - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -476,7 +476,7 @@ func TestShaderDerivatives(t *testing.T) { const w, h = 16, 16 - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -533,7 +533,7 @@ func TestShaderDerivatives2(t *testing.T) { const w, h = 16, 16 - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -598,7 +598,7 @@ func TestShaderUniformFirstElement(t *testing.T) { }{ { Name: "float array", - Shader: `//kage:unit pixel + Shader: `//kage:unit pixels package main @@ -613,7 +613,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { }, { Name: "float one-element array", - Shader: `//kage:unit pixel + Shader: `//kage:unit pixels package main @@ -628,7 +628,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { }, { Name: "matrix array", - Shader: `//kage:unit pixel + Shader: `//kage:unit pixels package main @@ -672,7 +672,7 @@ func TestShaderFuncMod(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -708,7 +708,7 @@ func TestShaderMatrixInitialize(t *testing.T) { src.Fill(color.RGBA{R: 0x10, G: 0x20, B: 0x30, A: 0xff}) dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -740,7 +740,7 @@ func TestShaderModVectorAndFloat(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -773,7 +773,7 @@ func TestShaderTextureAt(t *testing.T) { src.Fill(color.RGBA{R: 0x10, G: 0x20, B: 0x30, A: 0xff}) dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -811,7 +811,7 @@ func TestShaderAtan2(t *testing.T) { src.Fill(color.RGBA{R: 0x10, G: 0x20, B: 0x30, A: 0xff}) dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -845,7 +845,7 @@ func TestShaderUniformMatrix2(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -885,7 +885,7 @@ func TestShaderUniformMatrix2Array(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -927,7 +927,7 @@ func TestShaderUniformMatrix3(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -968,7 +968,7 @@ func TestShaderUniformMatrix3Array(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1012,7 +1012,7 @@ func TestShaderUniformMatrix4(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1054,7 +1054,7 @@ func TestShaderUniformMatrix4Array(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1099,7 +1099,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { func TestShaderOptionsNegativeBounds(t *testing.T) { const w, h = 16, 16 - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1229,7 +1229,7 @@ func TestShaderVectorEqual(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1279,7 +1279,7 @@ func TestShaderDiscard(t *testing.T) { } src.WritePixels(pix) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1326,7 +1326,7 @@ func TestShaderDrawRect(t *testing.T) { dst := ebiten.NewImage(dstW, dstH) src := ebiten.NewImage(srcW, srcH) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1375,7 +1375,7 @@ func TestShaderDrawRectColorScale(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1407,7 +1407,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { } func TestShaderUniformInt(t *testing.T) { - const ints = `//kage:unit pixel + const ints = `//kage:unit pixels package main @@ -1421,7 +1421,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { } ` - const intArray = `//kage:unit pixel + const intArray = `//kage:unit pixels package main @@ -1432,7 +1432,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { } ` - const intVec = `//kage:unit pixel + const intVec = `//kage:unit pixels package main @@ -1609,7 +1609,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { // Issue #2463 func TestShaderUniformVec3Array(t *testing.T) { - const shader = `//kage:unit pixel + const shader = `//kage:unit pixels package main @@ -1682,7 +1682,7 @@ return vec4(b)/255`, } for _, tc := range cases { - shader := fmt.Sprintf(`//kage:unit pixel + shader := fmt.Sprintf(`//kage:unit pixels package main @@ -1716,7 +1716,7 @@ func TestShaderTexelAndPixel(t *testing.T) { dstPixel := ebiten.NewImage(dstW, dstH) src := ebiten.NewImage(srcW, srcH) - shaderTexel, err := ebiten.NewShader([]byte(fmt.Sprintf(`//kage:unit texel + shaderTexel, err := ebiten.NewShader([]byte(fmt.Sprintf(`//kage:unit texels package main @@ -1731,7 +1731,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { if err != nil { t.Fatal(err) } - shaderPixel, err := ebiten.NewShader([]byte(`//kage:unit pixel + shaderPixel, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1776,7 +1776,7 @@ func TestShaderDifferentTextureSizes(t *testing.T) { src0.Fill(color.RGBA{0x10, 0x20, 0x30, 0xff}) src1.Fill(color.RGBA{0x30, 0x20, 0x10, 0xff}) - for _, unit := range []string{"texel", "pixel"} { + for _, unit := range []string{"texels", "pixels"} { unit := unit t.Run(fmt.Sprintf("unit %s", unit), func(t *testing.T) { shader, err := ebiten.NewShader([]byte(fmt.Sprintf(`//kage:unit %s @@ -1830,7 +1830,7 @@ func TestShaderIVec(t *testing.T) { // Test that ivec2 can take any float values that can be casted to integers. // This seems the common behavior in shading languages like GLSL, Metal, and HLSL. - shader, err := ebiten.NewShader([]byte(`//kage:unit pixel + shader, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1859,7 +1859,7 @@ func TestShaderUniformSizes(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -1978,7 +1978,7 @@ func TestShaderUniformDefaultValue(t *testing.T) { const w, h = 16, 16 dst := ebiten.NewImage(w, h) - s, err := ebiten.NewShader([]byte(`//kage:unit pixel + s, err := ebiten.NewShader([]byte(`//kage:unit pixels package main @@ -2036,7 +2036,7 @@ func TestShaderDrawRectWithoutSource(t *testing.T) { src := ebiten.NewImage(srcW, srcH) - for _, unit := range []string{"pixel", "texel"} { + for _, unit := range []string{"pixels", "texels"} { s, err := ebiten.NewShader([]byte(fmt.Sprintf(`//kage:unit %s package main @@ -2094,7 +2094,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { var want color.RGBA if offsetX <= i && i < offsetX+srcW && offsetY <= j && j < offsetY+srcH { var blue byte - if !withSrc && unit == "texel" { + if !withSrc && unit == "texels" { blue = 0xff } if offsetX+srcW/2 <= i && offsetY+srcH/2 <= j {