123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926 |
- // Copyright 2020 The Ebiten Authors
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package ebiten_test
- import (
- "image"
- "image/color"
- "testing"
- . "github.com/hajimehoshi/ebiten"
- )
- func TestShaderFill(t *testing.T) {
- const w, h = 16, 16
- dst, _ := NewImage(w, h, FilterDefault)
- s, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(1, 0, 0, 1)
- }
- `))
- if err != nil {
- t.Fatal(err)
- }
- dst.DrawRectShader(w/2, h/2, s, nil)
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- got := dst.At(i, j).(color.RGBA)
- var want color.RGBA
- if i < w/2 && j < h/2 {
- want = color.RGBA{0xff, 0, 0, 0xff}
- }
- if got != want {
- t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
- }
- }
- }
- }
- func TestShaderFillWithDrawImage(t *testing.T) {
- const w, h = 16, 16
- dst, _ := NewImage(w, h, FilterDefault)
- s, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(1, 0, 0, 1)
- }
- `))
- if err != nil {
- t.Fatal(err)
- }
- src, _ := NewImage(w/2, h/2, FilterDefault)
- op := &DrawRectShaderOptions{}
- op.Images[0] = src
- dst.DrawRectShader(w/2, h/2, s, op)
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- got := dst.At(i, j).(color.RGBA)
- var want color.RGBA
- if i < w/2 && j < h/2 {
- want = color.RGBA{0xff, 0, 0, 0xff}
- }
- if got != want {
- t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
- }
- }
- }
- }
- func TestShaderFillWithDrawTriangles(t *testing.T) {
- const w, h = 16, 16
- dst, _ := NewImage(w, h, FilterDefault)
- s, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(1, 0, 0, 1)
- }
- `))
- if err != nil {
- t.Fatal(err)
- }
- src, _ := NewImage(w/2, h/2, FilterDefault)
- op := &DrawTrianglesShaderOptions{}
- op.Images[0] = src
- vs := []Vertex{
- {
- DstX: 0,
- DstY: 0,
- SrcX: 0,
- SrcY: 0,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- {
- DstX: w,
- DstY: 0,
- SrcX: w / 2,
- SrcY: 0,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- {
- DstX: 0,
- DstY: h,
- SrcX: 0,
- SrcY: h / 2,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- {
- DstX: w,
- DstY: h,
- SrcX: w / 2,
- SrcY: h / 2,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- }
- is := []uint16{0, 1, 2, 1, 2, 3}
- dst.DrawTrianglesShader(vs, is, s, op)
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- got := dst.At(i, j).(color.RGBA)
- want := color.RGBA{0xff, 0, 0, 0xff}
- if got != want {
- t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
- }
- }
- }
- }
- func TestShaderFunction(t *testing.T) {
- const w, h = 16, 16
- dst, _ := NewImage(w, h, FilterDefault)
- s, err := NewShader([]byte(`package main
- func clr(red float) (float, float, float, float) {
- return red, 0, 0, 1
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(clr(1))
- }
- `))
- if err != nil {
- t.Fatal(err)
- }
- dst.DrawRectShader(w, h, s, nil)
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- got := dst.At(i, j).(color.RGBA)
- want := color.RGBA{0xff, 0, 0, 0xff}
- if got != want {
- t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
- }
- }
- }
- }
- func TestShaderShadowing(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var position vec4
- return position
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderDuplicatedVariables(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var foo vec4
- var foo vec4
- return foo
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var foo, foo vec4
- return foo
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var foo vec4
- foo := vec4(0)
- return foo
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() (vec4, vec4) {
- return vec4(0), vec4(0)
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- foo, foo := Foo()
- return foo
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderNoMain(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderNoNewVariables(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- _ := 1
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- _, _ := 1, 1
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() (int, int) {
- return 1, 1
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- _, _ := Foo()
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- a, _ := 1, 1
- _ = a
- return vec4(0)
- }
- `)); err != nil {
- t.Error(err)
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- _, a := 1, 1
- _ = a
- return vec4(0)
- }
- `)); err != nil {
- t.Error(err)
- }
- }
- func TestShaderWrongReturn(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return 0.0
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() (float, float) {
- return 0
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() float {
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderMultipleValueReturn(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Foo() (float, float) {
- return 0.0
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() float {
- return 0.0, 0.0
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() (float, float, float) {
- return 0.0, 0.0
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() (float, float) {
- return 0.0, 0.0
- }
- func Foo2() (float, float, float) {
- return Foo()
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Foo() (float, float, float) {
- return 0.0, 0.0, 0.0
- }
- func Foo2() (float, float, float) {
- return Foo()
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0.0)
- }
- `)); err != nil {
- t.Error(err)
- }
- }
- func TestShaderInit(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func init() {
- }
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderUnspportedSyntax(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := func() {
- }
- _ = x
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- go func() {
- }()
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- ch := make(chan int)
- _ = ch
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := 1i
- _ = x
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var x [4]float
- y := x[1:2]
- _ = y
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var x [4]float
- y := x[1:2:3]
- _ = y
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderUninitializedUniformVariables(t *testing.T) {
- const w, h = 16, 16
- dst, _ := NewImage(w, h, FilterDefault)
- s, err := NewShader([]byte(`package main
- var U vec4
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- return U
- }
- `))
- if err != nil {
- t.Fatal(err)
- }
- dst.DrawRectShader(w, h, s, nil)
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- got := dst.At(i, j).(color.RGBA)
- var want color.RGBA
- if got != want {
- t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
- }
- }
- }
- }
- func TestShaderForbidAssigningSpecialVariables(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- var U vec4
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- U = vec4(0)
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- var U vec4
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- U.x = 0
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- var U [2]vec4
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- U[0] = vec4(0)
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- texCoord = vec2(0)
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- texCoord.x = 0
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderBoolLiteral(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- true := vec4(0)
- return true
- }
- `)); err != nil {
- t.Errorf("error must be nil but was non-nil")
- }
- }
- func TestShaderUnusedVariable(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := 0
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := 0
- x = 1
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := vec4(0)
- x.x = 1
- return vec4(0)
- }
- `)); err != nil {
- t.Error(err)
- }
- // Increment statement treats a variable 'used'.
- // https://play.golang.org/p/2RuYMrSLjt3
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := 0
- x++
- return vec4(0)
- }
- `)); err != nil {
- t.Error(err)
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var a int
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var a, b int
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderBlankLhs(t *testing.T) {
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := _
- _ = x
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var x int = _
- _ = x
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := 1
- x = _
- _ = x
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- x := 1 + _
- _ = x
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- _++
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- _ += 1
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- if _, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- _.x = 1
- return vec4(0)
- }
- `)); err == nil {
- t.Errorf("error must be non-nil but was nil")
- }
- }
- func TestShaderMatrix(t *testing.T) {
- const w, h = 16, 16
- dst, _ := NewImage(w, h, FilterDefault)
- s, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- var a, b mat4
- a[0] = vec4(0.125, 0.0625, 0.0625, 0.0625)
- a[1] = vec4(0.25, 0.25, 0.0625, 0.1875)
- a[2] = vec4(0.1875, 0.125, 0.25, 0.25)
- a[3] = vec4(0.0625, 0.1875, 0.125, 0.25)
- b[0] = vec4(0.0625, 0.125, 0.0625, 0.125)
- b[1] = vec4(0.125, 0.1875, 0.25, 0.0625)
- b[2] = vec4(0.125, 0.125, 0.1875, 0.1875)
- b[3] = vec4(0.25, 0.0625, 0.125, 0.0625)
- return vec4((a * b * vec4(1, 1, 1, 1)).xyz, 1)
- }
- `))
- if err != nil {
- t.Fatal(err)
- }
- src, _ := NewImage(w, h, FilterDefault)
- op := &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{87, 82, 71, 255}
- if got != want {
- t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
- }
- }
- }
- }
- func TestShaderSubImage(t *testing.T) {
- const w, h = 16, 16
- s, err := NewShader([]byte(`package main
- func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
- r := imageSrc0At(texCoord).r
- g := imageSrc1At(texCoord).g
- return vec4(r, g, 0, 1)
- }
- `))
- if err != nil {
- t.Fatal(err)
- }
- src0, _ := NewImage(w, h, FilterDefault)
- pix0 := make([]byte, 4*w*h)
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- if 2 <= i && i < 10 && 3 <= j && j < 11 {
- pix0[4*(j*w+i)] = 0xff
- pix0[4*(j*w+i)+1] = 0
- pix0[4*(j*w+i)+2] = 0
- pix0[4*(j*w+i)+3] = 0xff
- }
- }
- }
- src0.ReplacePixels(pix0)
- src0 = src0.SubImage(image.Rect(2, 3, 10, 11)).(*Image)
- src1, _ := NewImage(w, h, FilterDefault)
- pix1 := make([]byte, 4*w*h)
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- if 6 <= i && i < 14 && 8 <= j && j < 16 {
- pix1[4*(j*w+i)] = 0
- pix1[4*(j*w+i)+1] = 0xff
- pix1[4*(j*w+i)+2] = 0
- pix1[4*(j*w+i)+3] = 0xff
- }
- }
- }
- src1.ReplacePixels(pix1)
- src1 = src1.SubImage(image.Rect(6, 8, 14, 16)).(*Image)
- testPixels := func(testname string, dst *Image) {
- for j := 0; j < h; j++ {
- for i := 0; i < w; i++ {
- got := dst.At(i, j).(color.RGBA)
- var want color.RGBA
- if i < w/2 && j < h/2 {
- want = color.RGBA{0xff, 0xff, 0, 0xff}
- }
- if got != want {
- t.Errorf("%s dst.At(%d, %d): got: %v, want: %v", testname, i, j, got, want)
- }
- }
- }
- }
- t.Run("DrawRectShader", func(t *testing.T) {
- dst, _ := NewImage(w, h, FilterDefault)
- op := &DrawRectShaderOptions{}
- op.Images[0] = src0
- op.Images[1] = src1
- dst.DrawRectShader(w/2, h/2, s, op)
- testPixels("DrawRectShader", dst)
- })
- t.Run("DrawTrianglesShader", func(t *testing.T) {
- dst, _ := NewImage(w, h, FilterDefault)
- vs := []Vertex{
- {
- DstX: 0,
- DstY: 0,
- SrcX: 2,
- SrcY: 3,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- {
- DstX: w / 2,
- DstY: 0,
- SrcX: 10,
- SrcY: 3,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- {
- DstX: 0,
- DstY: h / 2,
- SrcX: 2,
- SrcY: 11,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- {
- DstX: w / 2,
- DstY: h / 2,
- SrcX: 10,
- SrcY: 11,
- ColorR: 1,
- ColorG: 1,
- ColorB: 1,
- ColorA: 1,
- },
- }
- is := []uint16{0, 1, 2, 1, 2, 3}
- op := &DrawTrianglesShaderOptions{}
- op.Images[0] = src0
- op.Images[1] = src1
- dst.DrawTrianglesShader(vs, is, s, op)
- testPixels("DrawTrianglesShader", dst)
- })
- }
|