From b96b75d51ca73a8969ae75fc1edb039007e77b68 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 26 Mar 2022 01:19:20 +0900 Subject: [PATCH] ebiten: add TestShaderMatrixInitialize --- shader_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/shader_test.go b/shader_test.go index 271a88a88..c087732cf 100644 --- a/shader_test.go +++ b/shader_test.go @@ -593,3 +593,35 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { } } } + +func TestShaderMatrixInitialize(t *testing.T) { + const w, h = 16, 16 + + src := ebiten.NewImage(w, h) + src.Fill(color.RGBA{0x10, 0x20, 0x30, 0xff}) + + dst := ebiten.NewImage(w, h) + s, err := ebiten.NewShader([]byte(`package main + +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + return mat4(2) * imageSrc0At(texCoord); +} +`)) + if err != nil { + t.Fatal(err) + } + + op := &ebiten.DrawRectShaderOptions{} + op.Images[0] = src + dst.DrawRectShader(w, h, s, op) + + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + got := dst.At(i, j).(color.RGBA) + want := color.RGBA{0x20, 0x40, 0x60, 0xff} + if !sameColors(got, want, 2) { + t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want) + } + } + } +}