mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
Remove dot imports from tests - Remove dot imports (#1837)
Closes #1824
This commit is contained in:
parent
3c8c17eace
commit
57c45a13e4
@ -20,17 +20,17 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/audio"
|
"github.com/hajimehoshi/ebiten/v2/audio"
|
||||||
)
|
)
|
||||||
|
|
||||||
var context *Context
|
var context *audio.Context
|
||||||
|
|
||||||
func setup() {
|
func setup() {
|
||||||
context = NewContext(44100)
|
context = audio.NewContext(44100)
|
||||||
}
|
}
|
||||||
|
|
||||||
func teardown() {
|
func teardown() {
|
||||||
ResetContextForTesting()
|
audio.ResetContextForTesting()
|
||||||
context = nil
|
context = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,14 +39,14 @@ func TestGC(t *testing.T) {
|
|||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
p, _ := NewPlayer(context, bytes.NewReader(make([]byte, 4)))
|
p, _ := audio.NewPlayer(context, bytes.NewReader(make([]byte, 4)))
|
||||||
got := PlayersNumForTesting()
|
got := audio.PlayersNumForTesting()
|
||||||
if want := 0; got != want {
|
if want := 0; got != want {
|
||||||
t.Errorf("PlayersNum(): got: %d, want: %d", got, want)
|
t.Errorf("PlayersNum(): got: %d, want: %d", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Play()
|
p.Play()
|
||||||
got = PlayersNumForTesting()
|
got = audio.PlayersNumForTesting()
|
||||||
if want := 1; got != want {
|
if want := 1; got != want {
|
||||||
t.Errorf("PlayersNum() after Play: got: %d, want: %d", got, want)
|
t.Errorf("PlayersNum() after Play: got: %d, want: %d", got, want)
|
||||||
}
|
}
|
||||||
@ -56,11 +56,11 @@ func TestGC(t *testing.T) {
|
|||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
got = PlayersNumForTesting()
|
got = audio.PlayersNumForTesting()
|
||||||
if want := 0; got == want {
|
if want := 0; got == want {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := UpdateForTesting(); err != nil {
|
if err := audio.UpdateForTesting(); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
// 200[ms] should be enough all the bytes are consumed.
|
// 200[ms] should be enough all the bytes are consumed.
|
||||||
@ -76,24 +76,24 @@ func TestSameSourcePlayers(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
src := bytes.NewReader(make([]byte, 4))
|
src := bytes.NewReader(make([]byte, 4))
|
||||||
p0, err := NewPlayer(context, src)
|
p0, err := audio.NewPlayer(context, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
p1, err := NewPlayer(context, src)
|
p1, err := audio.NewPlayer(context, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// As the player does not play yet, error doesn't happen.
|
// As the player does not play yet, error doesn't happen.
|
||||||
if err := UpdateForTesting(); err != nil {
|
if err := audio.UpdateForTesting(); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p0.Play()
|
p0.Play()
|
||||||
p1.Play()
|
p1.Play()
|
||||||
|
|
||||||
if err := UpdateForTesting(); err == nil {
|
if err := audio.UpdateForTesting(); err == nil {
|
||||||
t.Errorf("got: nil, want: an error")
|
t.Errorf("got: nil, want: an error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ func TestPauseBeforeInit(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
src := bytes.NewReader(make([]byte, 4))
|
src := bytes.NewReader(make([]byte, 4))
|
||||||
p, err := NewPlayer(context, src)
|
p, err := audio.NewPlayer(context, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ func TestPauseBeforeInit(t *testing.T) {
|
|||||||
p.Pause()
|
p.Pause()
|
||||||
p.Play()
|
p.Play()
|
||||||
|
|
||||||
if err := UpdateForTesting(); err != nil {
|
if err := audio.UpdateForTesting(); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
|
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type f32reader struct {
|
type f32reader struct {
|
||||||
@ -37,7 +37,7 @@ func (f *f32reader) Read(buf []float32) (int, error) {
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFloat32Reader(data []float32) Float32Reader {
|
func newFloat32Reader(data []float32) convert.Float32Reader {
|
||||||
return &f32reader{data: data}
|
return &f32reader{data: data}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ func TestFloat32Reader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
r := NewReaderFromFloat32Reader(newFloat32Reader(c.In))
|
r := convert.NewReaderFromFloat32Reader(newFloat32Reader(c.In))
|
||||||
|
|
||||||
got := []byte{}
|
got := []byte{}
|
||||||
for {
|
for {
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
|
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func soundAt(timeInSecond float64) float64 {
|
func soundAt(timeInSecond float64) float64 {
|
||||||
@ -69,7 +69,7 @@ func TestResampling(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
inB := newSoundBytes(c.In)
|
inB := newSoundBytes(c.In)
|
||||||
outS := NewResampling(bytes.NewReader(inB), int64(len(inB)), c.In, c.Out)
|
outS := convert.NewResampling(bytes.NewReader(inB), int64(len(inB)), c.In, c.Out)
|
||||||
gotB, err := ioutil.ReadAll(outS)
|
gotB, err := ioutil.ReadAll(outS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/audio"
|
"github.com/hajimehoshi/ebiten/v2/audio"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInfiniteLoop(t *testing.T) {
|
func TestInfiniteLoop(t *testing.T) {
|
||||||
@ -32,7 +32,7 @@ func TestInfiniteLoop(t *testing.T) {
|
|||||||
for i := range src {
|
for i := range src {
|
||||||
src[i] = indexToByte(i)
|
src[i] = indexToByte(i)
|
||||||
}
|
}
|
||||||
l := NewInfiniteLoop(bytes.NewReader(src), int64(len(src)))
|
l := audio.NewInfiniteLoop(bytes.NewReader(src), int64(len(src)))
|
||||||
|
|
||||||
buf := make([]byte, len(src)*4)
|
buf := make([]byte, len(src)*4)
|
||||||
if _, err := io.ReadFull(l, buf); err != nil {
|
if _, err := io.ReadFull(l, buf); err != nil {
|
||||||
@ -94,8 +94,8 @@ func TestInfiniteLoopWithIntro(t *testing.T) {
|
|||||||
for i := range src {
|
for i := range src {
|
||||||
src[i] = indexToByte(i)
|
src[i] = indexToByte(i)
|
||||||
}
|
}
|
||||||
srcInf := NewInfiniteLoop(bytes.NewReader(src), srcLength)
|
srcInf := audio.NewInfiniteLoop(bytes.NewReader(src), srcLength)
|
||||||
l := NewInfiniteLoopWithIntro(srcInf, introLength, loopLength)
|
l := audio.NewInfiniteLoopWithIntro(srcInf, introLength, loopLength)
|
||||||
|
|
||||||
buf := make([]byte, srcLength*4)
|
buf := make([]byte, srcLength*4)
|
||||||
if _, err := io.ReadFull(l, buf); err != nil {
|
if _, err := io.ReadFull(l, buf); err != nil {
|
||||||
@ -151,7 +151,7 @@ func TestInfiniteLoopWithIntro(t *testing.T) {
|
|||||||
|
|
||||||
func TestInfiniteLoopWithIncompleteSize(t *testing.T) {
|
func TestInfiniteLoopWithIncompleteSize(t *testing.T) {
|
||||||
// s1 should work as if 4092 is given.
|
// s1 should work as if 4092 is given.
|
||||||
s1 := NewInfiniteLoop(bytes.NewReader(make([]byte, 4096)), 4095)
|
s1 := audio.NewInfiniteLoop(bytes.NewReader(make([]byte, 4096)), 4095)
|
||||||
n1, err := s1.Seek(4093, io.SeekStart)
|
n1, err := s1.Seek(4093, io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@ -161,7 +161,7 @@ func TestInfiniteLoopWithIncompleteSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// s2 should work as if 2044 and 2044 are given.
|
// s2 should work as if 2044 and 2044 are given.
|
||||||
s2 := NewInfiniteLoopWithIntro(bytes.NewReader(make([]byte, 4096)), 2047, 2046)
|
s2 := audio.NewInfiniteLoopWithIntro(bytes.NewReader(make([]byte, 4096)), 2047, 2046)
|
||||||
n2, err := s2.Seek(4093, io.SeekStart)
|
n2, err := s2.Seek(4093, io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"github.com/jfreymuth/oggvorbis"
|
"github.com/jfreymuth/oggvorbis"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/audio"
|
"github.com/hajimehoshi/ebiten/v2/audio"
|
||||||
. "github.com/hajimehoshi/ebiten/v2/audio/vorbis"
|
"github.com/hajimehoshi/ebiten/v2/audio/vorbis"
|
||||||
)
|
)
|
||||||
|
|
||||||
var audioContext = audio.NewContext(44100)
|
var audioContext = audio.NewContext(44100)
|
||||||
@ -29,7 +29,7 @@ var audioContext = audio.NewContext(44100)
|
|||||||
func TestMono(t *testing.T) {
|
func TestMono(t *testing.T) {
|
||||||
bs := test_mono_ogg
|
bs := test_mono_ogg
|
||||||
|
|
||||||
s, err := DecodeWithSampleRate(audioContext.SampleRate(), bytes.NewReader(bs))
|
s, err := vorbis.DecodeWithSampleRate(audioContext.SampleRate(), bytes.NewReader(bs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ func TestMono(t *testing.T) {
|
|||||||
func TestTooShort(t *testing.T) {
|
func TestTooShort(t *testing.T) {
|
||||||
bs := test_tooshort_ogg
|
bs := test_tooshort_ogg
|
||||||
|
|
||||||
s, err := DecodeWithSampleRate(audioContext.SampleRate(), bytes.NewReader(bs))
|
s, err := vorbis.DecodeWithSampleRate(audioContext.SampleRate(), bytes.NewReader(bs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,13 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestColorMInit(t *testing.T) {
|
func TestColorMInit(t *testing.T) {
|
||||||
var m ColorM
|
var m ebiten.ColorM
|
||||||
for i := 0; i < ColorMDim-1; i++ {
|
for i := 0; i < ebiten.ColorMDim-1; i++ {
|
||||||
for j := 0; j < ColorMDim; j++ {
|
for j := 0; j < ebiten.ColorMDim; j++ {
|
||||||
got := m.Element(i, j)
|
got := m.Element(i, j)
|
||||||
want := 0.0
|
want := 0.0
|
||||||
if i == j {
|
if i == j {
|
||||||
@ -38,8 +38,8 @@ func TestColorMInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.SetElement(0, 0, 1)
|
m.SetElement(0, 0, 1)
|
||||||
for i := 0; i < ColorMDim-1; i++ {
|
for i := 0; i < ebiten.ColorMDim-1; i++ {
|
||||||
for j := 0; j < ColorMDim; j++ {
|
for j := 0; j < ebiten.ColorMDim; j++ {
|
||||||
got := m.Element(i, j)
|
got := m.Element(i, j)
|
||||||
want := 0.0
|
want := 0.0
|
||||||
if i == j {
|
if i == j {
|
||||||
@ -53,7 +53,7 @@ func TestColorMInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestColorMAssign(t *testing.T) {
|
func TestColorMAssign(t *testing.T) {
|
||||||
m := ColorM{}
|
m := ebiten.ColorM{}
|
||||||
m.SetElement(0, 0, 1)
|
m.SetElement(0, 0, 1)
|
||||||
m2 := m
|
m2 := m
|
||||||
m.SetElement(0, 0, 0)
|
m.SetElement(0, 0, 0)
|
||||||
@ -71,7 +71,7 @@ func TestColorMTranslate(t *testing.T) {
|
|||||||
{0, 0, 1, 0, 2.5},
|
{0, 0, 1, 0, 2.5},
|
||||||
{0, 0, 0, 1, 3.5},
|
{0, 0, 0, 1, 3.5},
|
||||||
}
|
}
|
||||||
m := ColorM{}
|
m := ebiten.ColorM{}
|
||||||
m.Translate(0.5, 1.5, 2.5, 3.5)
|
m.Translate(0.5, 1.5, 2.5, 3.5)
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
for j := 0; j < 5; j++ {
|
for j := 0; j < 5; j++ {
|
||||||
@ -91,7 +91,7 @@ func TestColorMScale(t *testing.T) {
|
|||||||
{0, 0, 2.5, 0, 0},
|
{0, 0, 2.5, 0, 0},
|
||||||
{0, 0, 0, 3.5, 0},
|
{0, 0, 0, 3.5, 0},
|
||||||
}
|
}
|
||||||
m := ColorM{}
|
m := ebiten.ColorM{}
|
||||||
m.Scale(0.5, 1.5, 2.5, 3.5)
|
m.Scale(0.5, 1.5, 2.5, 3.5)
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
for j := 0; j < 5; j++ {
|
for j := 0; j < 5; j++ {
|
||||||
@ -111,7 +111,7 @@ func TestColorMTranslateAndScale(t *testing.T) {
|
|||||||
{0, 0, 1, 0, 0},
|
{0, 0, 1, 0, 0},
|
||||||
{0, 0, 0, 0.5, 0.5},
|
{0, 0, 0, 0.5, 0.5},
|
||||||
}
|
}
|
||||||
m := ColorM{}
|
m := ebiten.ColorM{}
|
||||||
m.Translate(0, 0, 0, 1)
|
m.Translate(0, 0, 0, 1)
|
||||||
m.Scale(1, 1, 1, 0.5)
|
m.Scale(1, 1, 1, 0.5)
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
@ -132,7 +132,7 @@ func TestColorMMonochrome(t *testing.T) {
|
|||||||
{0.2990, 0.5870, 0.1140, 0, 0},
|
{0.2990, 0.5870, 0.1140, 0, 0},
|
||||||
{0, 0, 0, 1, 0},
|
{0, 0, 0, 1, 0},
|
||||||
}
|
}
|
||||||
m := ColorM{}
|
m := ebiten.ColorM{}
|
||||||
m.ChangeHSV(0, 0, 1)
|
m.ChangeHSV(0, 0, 1)
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
for j := 0; j < 5; j++ {
|
for j := 0; j < 5; j++ {
|
||||||
@ -152,7 +152,7 @@ func TestColorMConcatSelf(t *testing.T) {
|
|||||||
{30, 43, 51, 39, 34},
|
{30, 43, 51, 39, 34},
|
||||||
{25, 37, 39, 46, 36},
|
{25, 37, 39, 46, 36},
|
||||||
}
|
}
|
||||||
m := ColorM{}
|
m := ebiten.ColorM{}
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
for j := 0; j < 5; j++ {
|
for j := 0; j < 5; j++ {
|
||||||
m.SetElement(i, j, float64((i+j)%5+1))
|
m.SetElement(i, j, float64((i+j)%5+1))
|
||||||
@ -178,23 +178,23 @@ func absDiffU32(x, y uint32) uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestColorMApply(t *testing.T) {
|
func TestColorMApply(t *testing.T) {
|
||||||
mono := ColorM{}
|
mono := ebiten.ColorM{}
|
||||||
mono.ChangeHSV(0, 0, 1)
|
mono.ChangeHSV(0, 0, 1)
|
||||||
|
|
||||||
shiny := ColorM{}
|
shiny := ebiten.ColorM{}
|
||||||
shiny.Translate(1, 1, 1, 0)
|
shiny.Translate(1, 1, 1, 0)
|
||||||
|
|
||||||
shift := ColorM{}
|
shift := ebiten.ColorM{}
|
||||||
shift.Translate(0.5, 0.5, 0.5, 0.5)
|
shift.Translate(0.5, 0.5, 0.5, 0.5)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
ColorM ColorM
|
ColorM ebiten.ColorM
|
||||||
In color.Color
|
In color.Color
|
||||||
Out color.Color
|
Out color.Color
|
||||||
Delta uint32
|
Delta uint32
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
ColorM: ColorM{},
|
ColorM: ebiten.ColorM{},
|
||||||
In: color.RGBA{1, 2, 3, 4},
|
In: color.RGBA{1, 2, 3, 4},
|
||||||
Out: color.RGBA{1, 2, 3, 4},
|
Out: color.RGBA{1, 2, 3, 4},
|
||||||
Delta: 0x101,
|
Delta: 0x101,
|
||||||
@ -237,7 +237,7 @@ func TestColorMApply(t *testing.T) {
|
|||||||
|
|
||||||
// #1765
|
// #1765
|
||||||
func TestColorMConcat(t *testing.T) {
|
func TestColorMConcat(t *testing.T) {
|
||||||
var a, b ColorM
|
var a, b ebiten.ColorM
|
||||||
a.SetElement(1, 2, -1)
|
a.SetElement(1, 2, -1)
|
||||||
a.Concat(b)
|
a.Concat(b)
|
||||||
if got, want := a.Element(1, 2), -1.0; got != want {
|
if got, want := a.Element(1, 2), -1.0; got != want {
|
||||||
|
@ -15,28 +15,28 @@
|
|||||||
package twenty48_test
|
package twenty48_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "github.com/hajimehoshi/ebiten/v2/examples/2048/2048"
|
"github.com/hajimehoshi/ebiten/v2/examples/2048/2048"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cellsToTiles(cells []int, size int) map[*Tile]struct{} {
|
func cellsToTiles(cells []int, size int) map[*twenty48.Tile]struct{} {
|
||||||
tiles := map[*Tile]struct{}{}
|
tiles := map[*twenty48.Tile]struct{}{}
|
||||||
for j := 0; j < size; j++ {
|
for j := 0; j < size; j++ {
|
||||||
for i := 0; i < size; i++ {
|
for i := 0; i < size; i++ {
|
||||||
c := cells[i+j*size]
|
c := cells[i+j*size]
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t := NewTile(c, i, j)
|
t := twenty48.NewTile(c, i, j)
|
||||||
tiles[t] = struct{}{}
|
tiles[t] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tiles
|
return tiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func tilesToCells(tiles map[*Tile]struct{}, size int) ([]int, []int) {
|
func tilesToCells(tiles map[*twenty48.Tile]struct{}, size int) ([]int, []int) {
|
||||||
cells := make([]int, size*size)
|
cells := make([]int, size*size)
|
||||||
nextCells := make([]int, size*size)
|
nextCells := make([]int, size*size)
|
||||||
for t := range tiles {
|
for t := range tiles {
|
||||||
@ -58,12 +58,12 @@ func tilesToCells(tiles map[*Tile]struct{}, size int) ([]int, []int) {
|
|||||||
func TestMoveTiles(t *testing.T) {
|
func TestMoveTiles(t *testing.T) {
|
||||||
const size = 4
|
const size = 4
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
Dir Dir
|
Dir twenty48.Dir
|
||||||
Input []int
|
Input []int
|
||||||
Want []int
|
Want []int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Dir: DirUp,
|
Dir: twenty48.DirUp,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
0, 0, 0, 0,
|
0, 0, 0, 0,
|
||||||
0, 0, 0, 0,
|
0, 0, 0, 0,
|
||||||
@ -78,7 +78,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirRight,
|
Dir: twenty48.DirRight,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
2, 0, 0, 0,
|
2, 0, 0, 0,
|
||||||
0, 2, 0, 0,
|
0, 2, 0, 0,
|
||||||
@ -93,7 +93,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirUp,
|
Dir: twenty48.DirUp,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
2, 0, 0, 0,
|
2, 0, 0, 0,
|
||||||
0, 2, 0, 0,
|
0, 2, 0, 0,
|
||||||
@ -108,7 +108,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirLeft,
|
Dir: twenty48.DirLeft,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
0, 2, 2, 2,
|
0, 2, 2, 2,
|
||||||
0, 0, 0, 0,
|
0, 0, 0, 0,
|
||||||
@ -123,7 +123,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirRight,
|
Dir: twenty48.DirRight,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
0, 0, 0, 2,
|
0, 0, 0, 2,
|
||||||
0, 0, 2, 2,
|
0, 0, 2, 2,
|
||||||
@ -138,7 +138,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirLeft,
|
Dir: twenty48.DirLeft,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
0, 0, 0, 2,
|
0, 0, 0, 2,
|
||||||
0, 0, 2, 2,
|
0, 0, 2, 2,
|
||||||
@ -153,7 +153,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirRight,
|
Dir: twenty48.DirRight,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
4, 8, 8, 4,
|
4, 8, 8, 4,
|
||||||
8, 8, 4, 4,
|
8, 8, 4, 4,
|
||||||
@ -168,7 +168,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirDown,
|
Dir: twenty48.DirDown,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
4, 8, 8, 4,
|
4, 8, 8, 4,
|
||||||
8, 8, 4, 4,
|
8, 8, 4, 4,
|
||||||
@ -183,7 +183,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirLeft,
|
Dir: twenty48.DirLeft,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
4, 8, 8, 4,
|
4, 8, 8, 4,
|
||||||
8, 8, 4, 4,
|
8, 8, 4, 4,
|
||||||
@ -198,7 +198,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirUp,
|
Dir: twenty48.DirUp,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
4, 8, 8, 4,
|
4, 8, 8, 4,
|
||||||
8, 8, 4, 4,
|
8, 8, 4, 4,
|
||||||
@ -213,7 +213,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dir: DirUp,
|
Dir: twenty48.DirUp,
|
||||||
Input: []int{
|
Input: []int{
|
||||||
2, 4, 2, 4,
|
2, 4, 2, 4,
|
||||||
4, 2, 4, 2,
|
4, 2, 4, 2,
|
||||||
@ -231,7 +231,7 @@ func TestMoveTiles(t *testing.T) {
|
|||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
want, _ := tilesToCells(cellsToTiles(test.Want, size), size)
|
want, _ := tilesToCells(cellsToTiles(test.Want, size), size)
|
||||||
tiles := cellsToTiles(test.Input, size)
|
tiles := cellsToTiles(test.Input, size)
|
||||||
moved := MoveTiles(tiles, size, test.Dir)
|
moved := twenty48.MoveTiles(tiles, size, test.Dir)
|
||||||
input, got := tilesToCells(tiles, size)
|
input, got := tilesToCells(tiles, size)
|
||||||
if !moved {
|
if !moved {
|
||||||
got = input
|
got = input
|
||||||
|
68
geom_test.go
68
geom_test.go
@ -19,13 +19,13 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGeoMInit(t *testing.T) {
|
func TestGeoMInit(t *testing.T) {
|
||||||
var m GeoM
|
var m ebiten.GeoM
|
||||||
for i := 0; i < GeoMDim-1; i++ {
|
for i := 0; i < ebiten.GeoMDim-1; i++ {
|
||||||
for j := 0; j < GeoMDim; j++ {
|
for j := 0; j < ebiten.GeoMDim; j++ {
|
||||||
got := m.Element(i, j)
|
got := m.Element(i, j)
|
||||||
want := 0.0
|
want := 0.0
|
||||||
if i == j {
|
if i == j {
|
||||||
@ -39,7 +39,7 @@ func TestGeoMInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeoMAssign(t *testing.T) {
|
func TestGeoMAssign(t *testing.T) {
|
||||||
m := GeoM{}
|
m := ebiten.GeoM{}
|
||||||
m.SetElement(0, 0, 1)
|
m.SetElement(0, 0, 1)
|
||||||
m2 := m
|
m2 := m
|
||||||
m.SetElement(0, 0, 0)
|
m.SetElement(0, 0, 0)
|
||||||
@ -51,9 +51,9 @@ func TestGeoMAssign(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeoMConcat(t *testing.T) {
|
func TestGeoMConcat(t *testing.T) {
|
||||||
matrix1 := GeoM{}
|
matrix1 := ebiten.GeoM{}
|
||||||
matrix1.Scale(2, 2)
|
matrix1.Scale(2, 2)
|
||||||
matrix2 := GeoM{}
|
matrix2 := ebiten.GeoM{}
|
||||||
matrix2.Translate(1, 1)
|
matrix2.Translate(1, 1)
|
||||||
|
|
||||||
matrix3 := matrix1
|
matrix3 := matrix1
|
||||||
@ -93,7 +93,7 @@ func TestGeoMConcat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeoMConcatSelf(t *testing.T) {
|
func TestGeoMConcatSelf(t *testing.T) {
|
||||||
m := GeoM{}
|
m := ebiten.GeoM{}
|
||||||
m.SetElement(0, 0, 1)
|
m.SetElement(0, 0, 1)
|
||||||
m.SetElement(0, 1, 2)
|
m.SetElement(0, 1, 2)
|
||||||
m.SetElement(0, 2, 3)
|
m.SetElement(0, 2, 3)
|
||||||
@ -117,7 +117,7 @@ func TestGeoMConcatSelf(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func geoMToString(g GeoM) string {
|
func geoMToString(g ebiten.GeoM) string {
|
||||||
a := g.Element(0, 0)
|
a := g.Element(0, 0)
|
||||||
b := g.Element(0, 1)
|
b := g.Element(0, 1)
|
||||||
c := g.Element(1, 0)
|
c := g.Element(1, 0)
|
||||||
@ -128,26 +128,26 @@ func geoMToString(g GeoM) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeoMApply(t *testing.T) {
|
func TestGeoMApply(t *testing.T) {
|
||||||
trans := GeoM{}
|
trans := ebiten.GeoM{}
|
||||||
trans.Translate(1, 2)
|
trans.Translate(1, 2)
|
||||||
|
|
||||||
scale := GeoM{}
|
scale := ebiten.GeoM{}
|
||||||
scale.Scale(1.5, 2.5)
|
scale.Scale(1.5, 2.5)
|
||||||
|
|
||||||
cpx := GeoM{}
|
cpx := ebiten.GeoM{}
|
||||||
cpx.Rotate(math.Pi)
|
cpx.Rotate(math.Pi)
|
||||||
cpx.Scale(1.5, 2.5)
|
cpx.Scale(1.5, 2.5)
|
||||||
cpx.Translate(-2, -3)
|
cpx.Translate(-2, -3)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
GeoM GeoM
|
GeoM ebiten.GeoM
|
||||||
InX float64
|
InX float64
|
||||||
InY float64
|
InY float64
|
||||||
OutX float64
|
OutX float64
|
||||||
OutY float64
|
OutY float64
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
GeoM: GeoM{},
|
GeoM: ebiten.GeoM{},
|
||||||
InX: 3.14159,
|
InX: 3.14159,
|
||||||
InY: 2.81828,
|
InY: 2.81828,
|
||||||
OutX: 3.14159,
|
OutX: 3.14159,
|
||||||
@ -187,30 +187,30 @@ func TestGeoMApply(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeoMIsInvert(t *testing.T) {
|
func TestGeoMIsInvert(t *testing.T) {
|
||||||
zero := GeoM{}
|
zero := ebiten.GeoM{}
|
||||||
zero.Scale(0, 0)
|
zero.Scale(0, 0)
|
||||||
|
|
||||||
trans := GeoM{}
|
trans := ebiten.GeoM{}
|
||||||
trans.Translate(1, 2)
|
trans.Translate(1, 2)
|
||||||
|
|
||||||
scale := GeoM{}
|
scale := ebiten.GeoM{}
|
||||||
scale.Scale(1.5, 2.5)
|
scale.Scale(1.5, 2.5)
|
||||||
|
|
||||||
cpx := GeoM{}
|
cpx := ebiten.GeoM{}
|
||||||
cpx.Rotate(math.Pi)
|
cpx.Rotate(math.Pi)
|
||||||
cpx.Scale(1.5, 2.5)
|
cpx.Scale(1.5, 2.5)
|
||||||
cpx.Translate(-2, -3)
|
cpx.Translate(-2, -3)
|
||||||
|
|
||||||
cpx2 := GeoM{}
|
cpx2 := ebiten.GeoM{}
|
||||||
cpx2.Scale(2, 3)
|
cpx2.Scale(2, 3)
|
||||||
cpx2.Rotate(0.234)
|
cpx2.Rotate(0.234)
|
||||||
cpx2.Translate(100, 100)
|
cpx2.Translate(100, 100)
|
||||||
|
|
||||||
skew := GeoM{}
|
skew := ebiten.GeoM{}
|
||||||
skew.Skew(1, 1)
|
skew.Skew(1, 1)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
GeoM GeoM
|
GeoM ebiten.GeoM
|
||||||
Invertible bool
|
Invertible bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -218,7 +218,7 @@ func TestGeoMIsInvert(t *testing.T) {
|
|||||||
Invertible: false,
|
Invertible: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
GeoM: GeoM{},
|
GeoM: ebiten.GeoM{},
|
||||||
Invertible: true,
|
Invertible: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -286,8 +286,8 @@ func TestGeoMIsInvert(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGeoM(a, b, c, d, tx, ty float64) GeoM {
|
func newGeoM(a, b, c, d, tx, ty float64) ebiten.GeoM {
|
||||||
outp := GeoM{}
|
outp := ebiten.GeoM{}
|
||||||
outp.SetElement(0, 0, a)
|
outp.SetElement(0, 0, a)
|
||||||
outp.SetElement(0, 1, b)
|
outp.SetElement(0, 1, b)
|
||||||
outp.SetElement(0, 2, tx)
|
outp.SetElement(0, 2, tx)
|
||||||
@ -298,7 +298,7 @@ func newGeoM(a, b, c, d, tx, ty float64) GeoM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeomSkew(t *testing.T) {
|
func TestGeomSkew(t *testing.T) {
|
||||||
testSkew := func(skewX, skewY float64, input, expected GeoM) {
|
testSkew := func(skewX, skewY float64, input, expected ebiten.GeoM) {
|
||||||
input.Skew(skewX, skewY)
|
input.Skew(skewX, skewY)
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
for j := 0; j < 3; j++ {
|
for j := 0; j < 3; j++ {
|
||||||
@ -313,15 +313,15 @@ func TestGeomSkew(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// skewX = 0.25
|
// skewX = 0.25
|
||||||
expectedX := newGeoM(1, math.Tan(0.25), math.Tan(0), 1, 0, 0)
|
expectedX := newGeoM(1, math.Tan(0.25), math.Tan(0), 1, 0, 0)
|
||||||
testSkew(0.25, 0, GeoM{}, expectedX)
|
testSkew(0.25, 0, ebiten.GeoM{}, expectedX)
|
||||||
|
|
||||||
// skewY = 0.25
|
// skewY = 0.25
|
||||||
expectedY := newGeoM(1, math.Tan(0), math.Tan(0.5), 1, 0, 0)
|
expectedY := newGeoM(1, math.Tan(0), math.Tan(0.5), 1, 0, 0)
|
||||||
testSkew(0, 0.5, GeoM{}, expectedY)
|
testSkew(0, 0.5, ebiten.GeoM{}, expectedY)
|
||||||
|
|
||||||
// skewX, skewY = 0.3, 0.8
|
// skewX, skewY = 0.3, 0.8
|
||||||
expectedXY := newGeoM(1, math.Tan(0.3), math.Tan(0.8), 1, 0, 0)
|
expectedXY := newGeoM(1, math.Tan(0.3), math.Tan(0.8), 1, 0, 0)
|
||||||
testSkew(0.3, 0.8, GeoM{}, expectedXY)
|
testSkew(0.3, 0.8, ebiten.GeoM{}, expectedXY)
|
||||||
|
|
||||||
// skewX, skewY = 0.4, -1.8 ; b, c = 2, 3
|
// skewX, skewY = 0.4, -1.8 ; b, c = 2, 3
|
||||||
expectedOffDiag := newGeoM(1+3*math.Tan(0.4), 2+math.Tan(0.4), 3+math.Tan(-1.8), 1+2*math.Tan(-1.8), 0, 0)
|
expectedOffDiag := newGeoM(1+3*math.Tan(0.4), 2+math.Tan(0.4), 3+math.Tan(-1.8), 1+2*math.Tan(-1.8), 0, 0)
|
||||||
@ -336,13 +336,13 @@ func TestGeomSkew(t *testing.T) {
|
|||||||
|
|
||||||
func TestGeoMEquals(t *testing.T) {
|
func TestGeoMEquals(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
a GeoM
|
a ebiten.GeoM
|
||||||
b GeoM
|
b ebiten.GeoM
|
||||||
want bool
|
want bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
a: GeoM{},
|
a: ebiten.GeoM{},
|
||||||
b: GeoM{},
|
b: ebiten.GeoM{},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -366,9 +366,9 @@ func TestGeoMEquals(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGeoM(b *testing.B) {
|
func BenchmarkGeoM(b *testing.B) {
|
||||||
var m GeoM
|
var m ebiten.GeoM
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m = GeoM{}
|
m = ebiten.GeoM{}
|
||||||
m.Translate(10, 20)
|
m.Translate(10, 20)
|
||||||
m.Scale(2, 3)
|
m.Scale(2, 3)
|
||||||
m.Rotate(math.Pi / 2)
|
m.Rotate(math.Pi / 2)
|
||||||
|
448
image_test.go
448
image_test.go
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,7 @@ import (
|
|||||||
"image/color/palette"
|
"image/color/palette"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestImageToBytes(t *testing.T) {
|
func TestImageToBytes(t *testing.T) {
|
||||||
@ -93,7 +93,7 @@ func TestImageToBytes(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
got := ImageToBytes(c.In)
|
got := ebiten.ImageToBytes(c.In)
|
||||||
want := c.Out
|
want := c.Out
|
||||||
if !bytes.Equal(got, want) {
|
if !bytes.Equal(got, want) {
|
||||||
t.Errorf("Test %d: got: %v, want: %v", i, got, want)
|
t.Errorf("Test %d: got: %v, want: %v", i, got, want)
|
||||||
@ -105,7 +105,7 @@ func BenchmarkImageToBytesRGBA(b *testing.B) {
|
|||||||
img := image.NewRGBA(image.Rect(0, 0, 4096, 4096))
|
img := image.NewRGBA(image.Rect(0, 0, 4096, 4096))
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ImageToBytes(img)
|
ebiten.ImageToBytes(img)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ func BenchmarkImageToBytesNRGBA(b *testing.B) {
|
|||||||
img := image.NewNRGBA(image.Rect(0, 0, 4096, 4096))
|
img := image.NewNRGBA(image.Rect(0, 0, 4096, 4096))
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ImageToBytes(img)
|
ebiten.ImageToBytes(img)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +121,6 @@ func BenchmarkImageToBytesPaletted(b *testing.B) {
|
|||||||
img := image.NewPaletted(image.Rect(0, 0, 4096, 4096), palette.Plan9)
|
img := image.NewPaletted(image.Rect(0, 0, 4096, 4096), palette.Plan9)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ImageToBytes(img)
|
ebiten.ImageToBytes(img)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,25 +19,25 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/affine"
|
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestColorMScale(t *testing.T) {
|
func TestColorMScale(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
In ColorM
|
In affine.ColorM
|
||||||
Out ColorM
|
Out affine.ColorM
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
ColorMIdentity{},
|
affine.ColorMIdentity{},
|
||||||
ColorMIdentity{}.Scale(0.25, 0.5, 0.75, 1),
|
affine.ColorMIdentity{}.Scale(0.25, 0.5, 0.75, 1),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(0.5, 0.5, 0.5, 0.8),
|
affine.ColorMIdentity{}.Scale(0.5, 0.5, 0.5, 0.8),
|
||||||
ColorMIdentity{}.Scale(0.125, 0.25, 0.375, 0.8),
|
affine.ColorMIdentity{}.Scale(0.125, 0.25, 0.375, 0.8),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Translate(0, 0, 0, 0),
|
affine.ColorMIdentity{}.Translate(0, 0, 0, 0),
|
||||||
ColorMIdentity{}.Scale(0.25, 0.5, 0.75, 1),
|
affine.ColorMIdentity{}.Scale(0.25, 0.5, 0.75, 1),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
@ -51,51 +51,51 @@ func TestColorMScale(t *testing.T) {
|
|||||||
|
|
||||||
func TestColorMScaleOnly(t *testing.T) {
|
func TestColorMScaleOnly(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
In ColorM
|
In affine.ColorM
|
||||||
Out bool
|
Out bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
ColorMIdentity{},
|
affine.ColorMIdentity{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Translate(0, 0, 0, 0),
|
affine.ColorMIdentity{}.Translate(0, 0, 0, 0),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Translate(1, 0, 0, 0),
|
affine.ColorMIdentity{}.Translate(1, 0, 0, 0),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Translate(0, 0, 0, -1),
|
affine.ColorMIdentity{}.Translate(0, 0, 0, -1),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(1, 1, 1, 1),
|
affine.ColorMIdentity{}.Scale(1, 1, 1, 1),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(0, 0, 0, 0),
|
affine.ColorMIdentity{}.Scale(0, 0, 0, 0),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(0.1, 0.2, 0.3, 0.4),
|
affine.ColorMIdentity{}.Scale(0.1, 0.2, 0.3, 0.4),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(0.1, 0.2, 0.3, 0.4).Translate(1, 0, 0, 0),
|
affine.ColorMIdentity{}.Scale(0.1, 0.2, 0.3, 0.4).Translate(1, 0, 0, 0),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ChangeHSV(ColorMIdentity{}, math.Pi/2, 0.5, 0.5),
|
affine.ChangeHSV(affine.ColorMIdentity{}, math.Pi/2, 0.5, 0.5),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMSetElement(ColorMIdentity{}, 0, 0, 2),
|
affine.ColorMSetElement(affine.ColorMIdentity{}, 0, 0, 2),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMSetElement(ColorMIdentity{}, 0, 1, 2),
|
affine.ColorMSetElement(affine.ColorMIdentity{}, 0, 1, 2),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -109,22 +109,22 @@ func TestColorMScaleOnly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestColorMIsInvertible(t *testing.T) {
|
func TestColorMIsInvertible(t *testing.T) {
|
||||||
var m ColorM = ColorMIdentity{}
|
var m affine.ColorM = affine.ColorMIdentity{}
|
||||||
m = ColorMSetElement(m, 1, 0, .5)
|
m = affine.ColorMSetElement(m, 1, 0, .5)
|
||||||
m = ColorMSetElement(m, 1, 1, .5)
|
m = affine.ColorMSetElement(m, 1, 1, .5)
|
||||||
m = ColorMSetElement(m, 1, 2, .5)
|
m = affine.ColorMSetElement(m, 1, 2, .5)
|
||||||
m = ColorMSetElement(m, 1, 3, .5)
|
m = affine.ColorMSetElement(m, 1, 3, .5)
|
||||||
m = ColorMSetElement(m, 1, 4, .5)
|
m = affine.ColorMSetElement(m, 1, 4, .5)
|
||||||
|
|
||||||
var cidentity ColorM = ColorMIdentity{}
|
var cidentity affine.ColorM = affine.ColorMIdentity{}
|
||||||
var cinvalid ColorM = ColorMIdentity{}
|
var cinvalid affine.ColorM = affine.ColorMIdentity{}
|
||||||
cinvalid = ColorMSetElement(cinvalid, 0, 0, 0)
|
cinvalid = affine.ColorMSetElement(cinvalid, 0, 0, 0)
|
||||||
cinvalid = ColorMSetElement(cinvalid, 1, 1, 0)
|
cinvalid = affine.ColorMSetElement(cinvalid, 1, 1, 0)
|
||||||
cinvalid = ColorMSetElement(cinvalid, 2, 2, 0)
|
cinvalid = affine.ColorMSetElement(cinvalid, 2, 2, 0)
|
||||||
cinvalid = ColorMSetElement(cinvalid, 3, 3, 0)
|
cinvalid = affine.ColorMSetElement(cinvalid, 3, 3, 0)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
In ColorM
|
In affine.ColorM
|
||||||
Out bool
|
Out bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -149,11 +149,11 @@ func TestColorMIsInvertible(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func arrayToColorM(es [4][5]float32) ColorM {
|
func arrayToColorM(es [4][5]float32) affine.ColorM {
|
||||||
var a ColorM = ColorMIdentity{}
|
var a affine.ColorM = affine.ColorMIdentity{}
|
||||||
for j := 0; j < 5; j++ {
|
for j := 0; j < 5; j++ {
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
a = ColorMSetElement(a, i, j, es[i][j])
|
a = affine.ColorMSetElement(a, i, j, es[i][j])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return a
|
return a
|
||||||
@ -166,7 +166,7 @@ func abs(x float32) float32 {
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
func equalWithDelta(a, b ColorM, delta float32) bool {
|
func equalWithDelta(a, b affine.ColorM, delta float32) bool {
|
||||||
for j := 0; j < 5; j++ {
|
for j := 0; j < 5; j++ {
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
ea := a.At(i, j)
|
ea := a.At(i, j)
|
||||||
@ -181,12 +181,12 @@ func equalWithDelta(a, b ColorM, delta float32) bool {
|
|||||||
|
|
||||||
func TestColorMInvert(t *testing.T) {
|
func TestColorMInvert(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
In ColorM
|
In affine.ColorM
|
||||||
Out ColorM
|
Out affine.ColorM
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
In: ColorMIdentity{},
|
In: affine.ColorMIdentity{},
|
||||||
Out: ColorMIdentity{},
|
Out: affine.ColorMIdentity{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
In: arrayToColorM([4][5]float32{
|
In: arrayToColorM([4][5]float32{
|
||||||
@ -203,7 +203,7 @@ func TestColorMInvert(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
In: ColorMIdentity{}.Scale(1, 2, 4, 8),
|
In: affine.ColorMIdentity{}.Scale(1, 2, 4, 8),
|
||||||
Out: arrayToColorM([4][5]float32{
|
Out: arrayToColorM([4][5]float32{
|
||||||
{1, 0, 0, 0, 0},
|
{1, 0, 0, 0, 0},
|
||||||
{0, 0.5, 0, 0, 0},
|
{0, 0.5, 0, 0, 0},
|
||||||
@ -252,7 +252,7 @@ func BenchmarkColorMInvert(b *testing.B) {
|
|||||||
r := rand.Float32
|
r := rand.Float32
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
var m ColorM = ColorMIdentity{}
|
var m affine.ColorM = affine.ColorMIdentity{}
|
||||||
for m.IsIdentity() || !m.IsInvertible() {
|
for m.IsIdentity() || !m.IsInvertible() {
|
||||||
m = arrayToColorM([4][5]float32{
|
m = arrayToColorM([4][5]float32{
|
||||||
{r(), r(), r(), r(), r() * 10},
|
{r(), r(), r(), r(), r() * 10},
|
||||||
@ -270,24 +270,24 @@ func BenchmarkColorMInvert(b *testing.B) {
|
|||||||
|
|
||||||
func TestColorMConcat(t *testing.T) {
|
func TestColorMConcat(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
In0 ColorM
|
In0 affine.ColorM
|
||||||
In1 ColorM
|
In1 affine.ColorM
|
||||||
Out ColorM
|
Out affine.ColorM
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
ColorMIdentity{},
|
affine.ColorMIdentity{},
|
||||||
ColorMIdentity{},
|
affine.ColorMIdentity{},
|
||||||
ColorMIdentity{},
|
affine.ColorMIdentity{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(1, 2, 3, 4),
|
affine.ColorMIdentity{}.Scale(1, 2, 3, 4),
|
||||||
ColorMIdentity{}.Scale(5, 6, 7, 8),
|
affine.ColorMIdentity{}.Scale(5, 6, 7, 8),
|
||||||
ColorMIdentity{}.Scale(5, 12, 21, 32),
|
affine.ColorMIdentity{}.Scale(5, 12, 21, 32),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(5, 6, 7, 8),
|
affine.ColorMIdentity{}.Scale(5, 6, 7, 8),
|
||||||
ColorMIdentity{}.Scale(1, 2, 3, 4),
|
affine.ColorMIdentity{}.Scale(1, 2, 3, 4),
|
||||||
ColorMIdentity{}.Scale(5, 12, 21, 32),
|
affine.ColorMIdentity{}.Scale(5, 12, 21, 32),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arrayToColorM([4][5]float32{
|
arrayToColorM([4][5]float32{
|
||||||
@ -296,7 +296,7 @@ func TestColorMConcat(t *testing.T) {
|
|||||||
{4, 5, 1, 2, 3},
|
{4, 5, 1, 2, 3},
|
||||||
{3, 4, 5, 1, 2},
|
{3, 4, 5, 1, 2},
|
||||||
}),
|
}),
|
||||||
ColorMIdentity{}.Scale(1, 2, 3, 4),
|
affine.ColorMIdentity{}.Scale(1, 2, 3, 4),
|
||||||
arrayToColorM([4][5]float32{
|
arrayToColorM([4][5]float32{
|
||||||
{1, 2, 3, 4, 5},
|
{1, 2, 3, 4, 5},
|
||||||
{10, 2, 4, 6, 8},
|
{10, 2, 4, 6, 8},
|
||||||
@ -305,7 +305,7 @@ func TestColorMConcat(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ColorMIdentity{}.Scale(1, 2, 3, 4),
|
affine.ColorMIdentity{}.Scale(1, 2, 3, 4),
|
||||||
arrayToColorM([4][5]float32{
|
arrayToColorM([4][5]float32{
|
||||||
{1, 2, 3, 4, 5},
|
{1, 2, 3, 4, 5},
|
||||||
{5, 1, 2, 3, 4},
|
{5, 1, 2, 3, 4},
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||||
@ -32,8 +32,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
SetImageSizeForTesting(minImageSizeForTesting, maxImageSizeForTesting)
|
atlas.SetImageSizeForTesting(minImageSizeForTesting, maxImageSizeForTesting)
|
||||||
defer ResetImageSizeForTesting()
|
defer atlas.ResetImageSizeForTesting()
|
||||||
t.MainWithRunLoop(m)
|
t.MainWithRunLoop(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,22 +59,22 @@ const bigSize = 2049
|
|||||||
func TestEnsureIsolated(t *testing.T) {
|
func TestEnsureIsolated(t *testing.T) {
|
||||||
// Create img1 and img2 with this size so that the next images are allocated
|
// Create img1 and img2 with this size so that the next images are allocated
|
||||||
// with non-upper-left location.
|
// with non-upper-left location.
|
||||||
img1 := NewImage(bigSize, 100)
|
img1 := atlas.NewImage(bigSize, 100)
|
||||||
defer img1.MarkDisposed()
|
defer img1.MarkDisposed()
|
||||||
// Ensure img1's region is allocated.
|
// Ensure img1's region is allocated.
|
||||||
img1.ReplacePixels(make([]byte, 4*bigSize*100))
|
img1.ReplacePixels(make([]byte, 4*bigSize*100))
|
||||||
|
|
||||||
img2 := NewImage(100, bigSize)
|
img2 := atlas.NewImage(100, bigSize)
|
||||||
defer img2.MarkDisposed()
|
defer img2.MarkDisposed()
|
||||||
img2.ReplacePixels(make([]byte, 4*100*bigSize))
|
img2.ReplacePixels(make([]byte, 4*100*bigSize))
|
||||||
|
|
||||||
const size = 32
|
const size = 32
|
||||||
|
|
||||||
img3 := NewImage(size/2, size/2)
|
img3 := atlas.NewImage(size/2, size/2)
|
||||||
defer img3.MarkDisposed()
|
defer img3.MarkDisposed()
|
||||||
img3.ReplacePixels(make([]byte, (size/2)*(size/2)*4))
|
img3.ReplacePixels(make([]byte, (size/2)*(size/2)*4))
|
||||||
|
|
||||||
img4 := NewImage(size, size)
|
img4 := atlas.NewImage(size, size)
|
||||||
defer img4.MarkDisposed()
|
defer img4.MarkDisposed()
|
||||||
|
|
||||||
pix := make([]byte, size*size*4)
|
pix := make([]byte, size*size*4)
|
||||||
@ -103,7 +103,7 @@ func TestEnsureIsolated(t *testing.T) {
|
|||||||
Width: size,
|
Width: size,
|
||||||
Height: size,
|
Height: size,
|
||||||
}
|
}
|
||||||
img4.DrawTriangles([graphics.ShaderImageNum]*Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
want := false
|
want := false
|
||||||
if got := img4.IsOnAtlasForTesting(); got != want {
|
if got := img4.IsOnAtlasForTesting(); got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
@ -133,24 +133,24 @@ func TestEnsureIsolated(t *testing.T) {
|
|||||||
|
|
||||||
// Check further drawing doesn't cause panic.
|
// Check further drawing doesn't cause panic.
|
||||||
// This bug was fixed by 03dcd948.
|
// This bug was fixed by 03dcd948.
|
||||||
img4.DrawTriangles([graphics.ShaderImageNum]*Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReputOnAtlas(t *testing.T) {
|
func TestReputOnAtlas(t *testing.T) {
|
||||||
const size = 16
|
const size = 16
|
||||||
|
|
||||||
img0 := NewImage(size, size)
|
img0 := atlas.NewImage(size, size)
|
||||||
defer img0.MarkDisposed()
|
defer img0.MarkDisposed()
|
||||||
img0.ReplacePixels(make([]byte, 4*size*size))
|
img0.ReplacePixels(make([]byte, 4*size*size))
|
||||||
|
|
||||||
img1 := NewImage(size, size)
|
img1 := atlas.NewImage(size, size)
|
||||||
defer img1.MarkDisposed()
|
defer img1.MarkDisposed()
|
||||||
img1.ReplacePixels(make([]byte, 4*size*size))
|
img1.ReplacePixels(make([]byte, 4*size*size))
|
||||||
if got, want := img1.IsOnAtlasForTesting(), true; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), true; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
img2 := NewImage(size, size)
|
img2 := atlas.NewImage(size, size)
|
||||||
defer img2.MarkDisposed()
|
defer img2.MarkDisposed()
|
||||||
pix := make([]byte, 4*size*size)
|
pix := make([]byte, 4*size*size)
|
||||||
for j := 0; j < size; j++ {
|
for j := 0; j < size; j++ {
|
||||||
@ -163,7 +163,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
}
|
}
|
||||||
img2.ReplacePixels(pix)
|
img2.ReplacePixels(pix)
|
||||||
|
|
||||||
img3 := NewImage(size, size)
|
img3 := atlas.NewImage(size, size)
|
||||||
img3.SetVolatile(true)
|
img3.SetVolatile(true)
|
||||||
defer img3.MarkDisposed()
|
defer img3.MarkDisposed()
|
||||||
img1.ReplacePixels(make([]byte, 4*size*size))
|
img1.ReplacePixels(make([]byte, 4*size*size))
|
||||||
@ -180,7 +180,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
Width: size,
|
Width: size,
|
||||||
Height: size,
|
Height: size,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*Image{img2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -188,16 +188,16 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
// Use img1 as a render source.
|
// Use img1 as a render source.
|
||||||
// Use the doubled count since img1 was on a texture atlas and became an isolated image once.
|
// Use the doubled count since img1 was on a texture atlas and became an isolated image once.
|
||||||
// Then, img1 requires longer time to recover to be on a textur atlas again.
|
// Then, img1 requires longer time to recover to be on a textur atlas again.
|
||||||
for i := 0; i < BaseCountToPutOnAtlas*2; i++ {
|
for i := 0; i < atlas.BaseCountToPutOnAtlas*2; i++ {
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// img1 is on an atlas again.
|
// img1 is on an atlas again.
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), true; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), true; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -244,39 +244,39 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use img1 as a render target again.
|
// Use img1 as a render target again.
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*Image{img2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use img1 as a render source, but call ReplacePixels.
|
// Use img1 as a render source, but call ReplacePixels.
|
||||||
// Now use 4x count as img1 became an isolated image again.
|
// Now use 4x count as img1 became an isolated image again.
|
||||||
for i := 0; i < BaseCountToPutOnAtlas*4; i++ {
|
for i := 0; i < atlas.BaseCountToPutOnAtlas*4; i++ {
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
img1.ReplacePixels(make([]byte, 4*size*size))
|
img1.ReplacePixels(make([]byte, 4*size*size))
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// img1 is not on an atlas due to ReplacePixels.
|
// img1 is not on an atlas due to ReplacePixels.
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use img3 as a render source. As img3 is volatile, img3 is never on an atlas.
|
// Use img3 as a render source. As img3 is volatile, img3 is never on an atlas.
|
||||||
for i := 0; i < BaseCountToPutOnAtlas*2; i++ {
|
for i := 0; i < atlas.BaseCountToPutOnAtlas*2; i++ {
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img3.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img3.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -287,7 +287,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
|
|
||||||
func TestExtend(t *testing.T) {
|
func TestExtend(t *testing.T) {
|
||||||
const w0, h0 = 100, 100
|
const w0, h0 = 100, 100
|
||||||
img0 := NewImage(w0, h0)
|
img0 := atlas.NewImage(w0, h0)
|
||||||
defer img0.MarkDisposed()
|
defer img0.MarkDisposed()
|
||||||
|
|
||||||
p0 := make([]byte, 4*w0*h0)
|
p0 := make([]byte, 4*w0*h0)
|
||||||
@ -300,7 +300,7 @@ func TestExtend(t *testing.T) {
|
|||||||
img0.ReplacePixels(p0)
|
img0.ReplacePixels(p0)
|
||||||
|
|
||||||
const w1, h1 = minImageSizeForTesting + 1, 100
|
const w1, h1 = minImageSizeForTesting + 1, 100
|
||||||
img1 := NewImage(w1, h1)
|
img1 := atlas.NewImage(w1, h1)
|
||||||
defer img1.MarkDisposed()
|
defer img1.MarkDisposed()
|
||||||
|
|
||||||
p1 := make([]byte, 4*w1*h1)
|
p1 := make([]byte, 4*w1*h1)
|
||||||
@ -354,9 +354,9 @@ func TestExtend(t *testing.T) {
|
|||||||
|
|
||||||
func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
|
func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
|
||||||
const w, h = 256, 256
|
const w, h = 256, 256
|
||||||
src := NewImage(w, h)
|
src := atlas.NewImage(w, h)
|
||||||
defer src.MarkDisposed()
|
defer src.MarkDisposed()
|
||||||
dst := NewImage(w, h)
|
dst := atlas.NewImage(w, h)
|
||||||
defer dst.MarkDisposed()
|
defer dst.MarkDisposed()
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
@ -376,7 +376,7 @@ func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
dst.ReplacePixels(pix)
|
dst.ReplacePixels(pix)
|
||||||
|
|
||||||
pix, err := dst.Pixels(0, 0, w, h)
|
pix, err := dst.Pixels(0, 0, w, h)
|
||||||
@ -402,9 +402,9 @@ func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
|
|||||||
// Issue #887
|
// Issue #887
|
||||||
func TestSmallImages(t *testing.T) {
|
func TestSmallImages(t *testing.T) {
|
||||||
const w, h = 4, 8
|
const w, h = 4, 8
|
||||||
src := NewImage(w, h)
|
src := atlas.NewImage(w, h)
|
||||||
defer src.MarkDisposed()
|
defer src.MarkDisposed()
|
||||||
dst := NewImage(w, h)
|
dst := atlas.NewImage(w, h)
|
||||||
defer dst.MarkDisposed()
|
defer dst.MarkDisposed()
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
@ -424,7 +424,7 @@ func TestSmallImages(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(0, 0, w, h)
|
pix, err := dst.Pixels(0, 0, w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -447,11 +447,11 @@ func TestSmallImages(t *testing.T) {
|
|||||||
// Issue #887
|
// Issue #887
|
||||||
func TestLongImages(t *testing.T) {
|
func TestLongImages(t *testing.T) {
|
||||||
const w, h = 1, 6
|
const w, h = 1, 6
|
||||||
src := NewImage(w, h)
|
src := atlas.NewImage(w, h)
|
||||||
defer src.MarkDisposed()
|
defer src.MarkDisposed()
|
||||||
|
|
||||||
const dstW, dstH = 256, 256
|
const dstW, dstH = 256, 256
|
||||||
dst := NewImage(dstW, dstH)
|
dst := atlas.NewImage(dstW, dstH)
|
||||||
defer dst.MarkDisposed()
|
defer dst.MarkDisposed()
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
@ -472,7 +472,7 @@ func TestLongImages(t *testing.T) {
|
|||||||
Width: dstW,
|
Width: dstW,
|
||||||
Height: dstH,
|
Height: dstH,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(0, 0, dstW, dstH)
|
pix, err := dst.Pixels(0, 0, dstW, dstH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -495,11 +495,11 @@ func TestLongImages(t *testing.T) {
|
|||||||
func TestDisposeImmediately(t *testing.T) {
|
func TestDisposeImmediately(t *testing.T) {
|
||||||
// This tests restorable.Image.ClearPixels is called but ReplacePixels is not called.
|
// This tests restorable.Image.ClearPixels is called but ReplacePixels is not called.
|
||||||
|
|
||||||
img0 := NewImage(16, 16)
|
img0 := atlas.NewImage(16, 16)
|
||||||
img0.EnsureIsolatedForTesting()
|
img0.EnsureIsolatedForTesting()
|
||||||
defer img0.MarkDisposed()
|
defer img0.MarkDisposed()
|
||||||
|
|
||||||
img1 := NewImage(16, 16)
|
img1 := atlas.NewImage(16, 16)
|
||||||
img1.EnsureIsolatedForTesting()
|
img1.EnsureIsolatedForTesting()
|
||||||
defer img1.MarkDisposed()
|
defer img1.MarkDisposed()
|
||||||
|
|
||||||
@ -508,12 +508,12 @@ func TestDisposeImmediately(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #1028
|
// Issue #1028
|
||||||
func TestExtendWithBigImage(t *testing.T) {
|
func TestExtendWithBigImage(t *testing.T) {
|
||||||
img0 := NewImage(1, 1)
|
img0 := atlas.NewImage(1, 1)
|
||||||
defer img0.MarkDisposed()
|
defer img0.MarkDisposed()
|
||||||
|
|
||||||
img0.ReplacePixels(make([]byte, 4*1*1))
|
img0.ReplacePixels(make([]byte, 4*1*1))
|
||||||
|
|
||||||
img1 := NewImage(minImageSizeForTesting+1, minImageSizeForTesting+1)
|
img1 := atlas.NewImage(minImageSizeForTesting+1, minImageSizeForTesting+1)
|
||||||
defer img1.MarkDisposed()
|
defer img1.MarkDisposed()
|
||||||
|
|
||||||
img1.ReplacePixels(make([]byte, 4*(minImageSizeForTesting+1)*(minImageSizeForTesting+1)))
|
img1.ReplacePixels(make([]byte, 4*(minImageSizeForTesting+1)*(minImageSizeForTesting+1)))
|
||||||
@ -522,8 +522,8 @@ func TestExtendWithBigImage(t *testing.T) {
|
|||||||
// Issue #1217
|
// Issue #1217
|
||||||
func TestMaxImageSize(t *testing.T) {
|
func TestMaxImageSize(t *testing.T) {
|
||||||
// This tests that a too-big image is allocated correctly.
|
// This tests that a too-big image is allocated correctly.
|
||||||
s := maxImageSizeForTesting - 2*PaddingSize
|
s := maxImageSizeForTesting - 2*atlas.PaddingSize
|
||||||
img := NewImage(s, s)
|
img := atlas.NewImage(s, s)
|
||||||
defer img.MarkDisposed()
|
defer img.MarkDisposed()
|
||||||
img.ReplacePixels(make([]byte, 4*s*s))
|
img.ReplacePixels(make([]byte, 4*s*s))
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ func Disable_TestMinImageSize(t *testing.T) {
|
|||||||
// This tests that extending a backend works correctly.
|
// This tests that extending a backend works correctly.
|
||||||
// Though the image size is minimum size of the backend, extending the backend happens due to the paddings.
|
// Though the image size is minimum size of the backend, extending the backend happens due to the paddings.
|
||||||
s := minImageSizeForTesting
|
s := minImageSizeForTesting
|
||||||
img := NewImage(s, s)
|
img := atlas.NewImage(s, s)
|
||||||
defer img.MarkDisposed()
|
defer img.MarkDisposed()
|
||||||
img.ReplacePixels(make([]byte, 4*s*s))
|
img.ReplacePixels(make([]byte, 4*s*s))
|
||||||
}
|
}
|
||||||
@ -545,11 +545,11 @@ func Disable_TestMinImageSize(t *testing.T) {
|
|||||||
func TestDisposedAndReputOnAtlas(t *testing.T) {
|
func TestDisposedAndReputOnAtlas(t *testing.T) {
|
||||||
const size = 16
|
const size = 16
|
||||||
|
|
||||||
src := NewImage(size, size)
|
src := atlas.NewImage(size, size)
|
||||||
defer src.MarkDisposed()
|
defer src.MarkDisposed()
|
||||||
src2 := NewImage(size, size)
|
src2 := atlas.NewImage(size, size)
|
||||||
defer src2.MarkDisposed()
|
defer src2.MarkDisposed()
|
||||||
dst := NewImage(size, size)
|
dst := atlas.NewImage(size, size)
|
||||||
defer dst.MarkDisposed()
|
defer dst.MarkDisposed()
|
||||||
|
|
||||||
// Use src as a render target so that src is not on an atlas.
|
// Use src as a render target so that src is not on an atlas.
|
||||||
@ -561,17 +561,17 @@ func TestDisposedAndReputOnAtlas(t *testing.T) {
|
|||||||
Width: size,
|
Width: size,
|
||||||
Height: size,
|
Height: size,
|
||||||
}
|
}
|
||||||
src.DrawTriangles([graphics.ShaderImageNum]*Image{src2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
src.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use src as a render source.
|
// Use src as a render source.
|
||||||
for i := 0; i < BaseCountToPutOnAtlas/2; i++ {
|
for i := 0; i < atlas.BaseCountToPutOnAtlas/2; i++ {
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -581,10 +581,10 @@ func TestDisposedAndReputOnAtlas(t *testing.T) {
|
|||||||
src.MarkDisposed()
|
src.MarkDisposed()
|
||||||
|
|
||||||
// Force to dispose the image.
|
// Force to dispose the image.
|
||||||
ResolveDeferredForTesting()
|
atlas.ResolveDeferredForTesting()
|
||||||
|
|
||||||
// Confirm that PutImagesOnAtlasForTesting doesn't panic.
|
// Confirm that PutImagesOnAtlasForTesting doesn't panic.
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -593,11 +593,11 @@ func TestDisposedAndReputOnAtlas(t *testing.T) {
|
|||||||
func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
||||||
const size = 16
|
const size = 16
|
||||||
|
|
||||||
src := NewImage(size, size)
|
src := atlas.NewImage(size, size)
|
||||||
defer src.MarkDisposed()
|
defer src.MarkDisposed()
|
||||||
src2 := NewImage(size, size)
|
src2 := atlas.NewImage(size, size)
|
||||||
defer src2.MarkDisposed()
|
defer src2.MarkDisposed()
|
||||||
dst := NewImage(size, size)
|
dst := atlas.NewImage(size, size)
|
||||||
defer dst.MarkDisposed()
|
defer dst.MarkDisposed()
|
||||||
|
|
||||||
// Use src as a render target so that src is not on an atlas.
|
// Use src as a render target so that src is not on an atlas.
|
||||||
@ -611,15 +611,15 @@ func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use src2 as a rendering target, and make src2 an independent image.
|
// Use src2 as a rendering target, and make src2 an independent image.
|
||||||
src2.DrawTriangles([graphics.ShaderImageNum]*Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
src2.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the count without using src2 as a rendering source.
|
// Update the count without using src2 as a rendering source.
|
||||||
// This should not affect whether src2 is on an atlas or not.
|
// This should not affect whether src2 is on an atlas or not.
|
||||||
for i := 0; i < BaseCountToPutOnAtlas; i++ {
|
for i := 0; i < atlas.BaseCountToPutOnAtlas; i++ {
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
||||||
@ -628,17 +628,17 @@ func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the count with using src2 as a rendering source.
|
// Update the count with using src2 as a rendering source.
|
||||||
for i := 0; i < BaseCountToPutOnAtlas; i++ {
|
for i := 0; i < atlas.BaseCountToPutOnAtlas; i++ {
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := PutImagesOnAtlasForTesting(); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if got, want := src2.IsOnAtlasForTesting(), true; got != want {
|
if got, want := src2.IsOnAtlasForTesting(), true; got != want {
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||||
@ -28,7 +28,7 @@ import (
|
|||||||
func TestShaderFillTwice(t *testing.T) {
|
func TestShaderFillTwice(t *testing.T) {
|
||||||
const w, h = 1, 1
|
const w, h = 1, 1
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := atlas.NewImage(w, h)
|
||||||
|
|
||||||
vs := quadVertices(w, h, 0, 0, 1)
|
vs := quadVertices(w, h, 0, 0, 1)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
@ -39,14 +39,14 @@ func TestShaderFillTwice(t *testing.T) {
|
|||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
p0 := etesting.ShaderProgramFill(0xff, 0xff, 0xff, 0xff)
|
p0 := etesting.ShaderProgramFill(0xff, 0xff, 0xff, 0xff)
|
||||||
s0 := NewShader(&p0)
|
s0 := atlas.NewShader(&p0)
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s0, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s0, nil, false)
|
||||||
|
|
||||||
// Vertices must be recreated (#1755)
|
// Vertices must be recreated (#1755)
|
||||||
vs = quadVertices(w, h, 0, 0, 1)
|
vs = quadVertices(w, h, 0, 0, 1)
|
||||||
p1 := etesting.ShaderProgramFill(0x80, 0x80, 0x80, 0xff)
|
p1 := etesting.ShaderProgramFill(0x80, 0x80, 0x80, 0xff)
|
||||||
s1 := NewShader(&p1)
|
s1 := atlas.NewShader(&p1)
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s1, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s1, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(0, 0, w, h)
|
pix, err := dst.Pixels(0, 0, w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -60,10 +60,10 @@ func TestShaderFillTwice(t *testing.T) {
|
|||||||
func TestImageDrawTwice(t *testing.T) {
|
func TestImageDrawTwice(t *testing.T) {
|
||||||
const w, h = 1, 1
|
const w, h = 1, 1
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := atlas.NewImage(w, h)
|
||||||
src0 := NewImage(w, h)
|
src0 := atlas.NewImage(w, h)
|
||||||
src0.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff})
|
src0.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff})
|
||||||
src1 := NewImage(w, h)
|
src1 := atlas.NewImage(w, h)
|
||||||
src1.ReplacePixels([]byte{0x80, 0x80, 0x80, 0xff})
|
src1.ReplacePixels([]byte{0x80, 0x80, 0x80, 0xff})
|
||||||
|
|
||||||
vs := quadVertices(w, h, 0, 0, 1)
|
vs := quadVertices(w, h, 0, 0, 1)
|
||||||
@ -74,11 +74,11 @@ func TestImageDrawTwice(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src0}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src0}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
// Vertices must be recreated (#1755)
|
// Vertices must be recreated (#1755)
|
||||||
vs = quadVertices(w, h, 0, 0, 1)
|
vs = quadVertices(w, h, 0, 0, 1)
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(0, 0, w, h)
|
pix, err := dst.Pixels(0, 0, w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,7 +17,7 @@ package graphics_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInternalImageSize(t *testing.T) {
|
func TestInternalImageSize(t *testing.T) {
|
||||||
@ -31,7 +31,7 @@ func TestInternalImageSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
got := InternalImageSize(testCase.arg)
|
got := graphics.InternalImageSize(testCase.arg)
|
||||||
wanted := testCase.expected
|
wanted := testCase.expected
|
||||||
if wanted != got {
|
if wanted != got {
|
||||||
t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted)
|
t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted)
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||||
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ func quadVertices(w, h float32) []float32 {
|
|||||||
|
|
||||||
func TestClear(t *testing.T) {
|
func TestClear(t *testing.T) {
|
||||||
const w, h = 1024, 1024
|
const w, h = 1024, 1024
|
||||||
src := NewImage(w/2, h/2)
|
src := graphicscommand.NewImage(w/2, h/2)
|
||||||
dst := NewImage(w, h)
|
dst := graphicscommand.NewImage(w, h)
|
||||||
|
|
||||||
vs := quadVertices(w/2, h/2)
|
vs := quadVertices(w/2, h/2)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
@ -51,7 +51,7 @@ func TestClear(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels()
|
pix, err := dst.Pixels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -71,9 +71,9 @@ func TestClear(t *testing.T) {
|
|||||||
|
|
||||||
func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
||||||
const w, h = 32, 32
|
const w, h = 32, 32
|
||||||
clr := NewImage(w, h)
|
clr := graphicscommand.NewImage(w, h)
|
||||||
src := NewImage(w/2, h/2)
|
src := graphicscommand.NewImage(w/2, h/2)
|
||||||
dst := NewImage(w, h)
|
dst := graphicscommand.NewImage(w, h)
|
||||||
vs := quadVertices(w/2, h/2)
|
vs := quadVertices(w/2, h/2)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
dr := driver.Region{
|
dr := driver.Region{
|
||||||
@ -82,8 +82,8 @@ func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||||
|
|
||||||
// TODO: Check the result.
|
// TODO: Check the result.
|
||||||
@ -91,8 +91,8 @@ func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
|||||||
|
|
||||||
func TestShader(t *testing.T) {
|
func TestShader(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
clr := NewImage(w, h)
|
clr := graphicscommand.NewImage(w, h)
|
||||||
dst := NewImage(w, h)
|
dst := graphicscommand.NewImage(w, h)
|
||||||
vs := quadVertices(w, h)
|
vs := quadVertices(w, h)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
dr := driver.Region{
|
dr := driver.Region{
|
||||||
@ -101,11 +101,11 @@ func TestShader(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
|
|
||||||
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
||||||
s := NewShader(&ir)
|
s := graphicscommand.NewShader(&ir)
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels()
|
pix, err := dst.Pixels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,7 +17,7 @@ package packing_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/packing"
|
"github.com/hajimehoshi/ebiten/v2/internal/packing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPage(t *testing.T) {
|
func TestPage(t *testing.T) {
|
||||||
@ -211,8 +211,8 @@ func TestPage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
p := NewPage(1024, 1024)
|
p := packing.NewPage(1024, 1024)
|
||||||
nodes := []*Node{}
|
nodes := []*packing.Node{}
|
||||||
nnodes := 0
|
nnodes := 0
|
||||||
for i, in := range c.In {
|
for i, in := range c.In {
|
||||||
if in.FreeNodeID == -1 {
|
if in.FreeNodeID == -1 {
|
||||||
@ -254,7 +254,7 @@ func TestPage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtend(t *testing.T) {
|
func TestExtend(t *testing.T) {
|
||||||
p := NewPage(1024, 4096)
|
p := packing.NewPage(1024, 4096)
|
||||||
s := p.Size()
|
s := p.Size()
|
||||||
p.Alloc(s/2, s/2)
|
p.Alloc(s/2, s/2)
|
||||||
p.Extend(1)
|
p.Extend(1)
|
||||||
@ -289,7 +289,7 @@ func TestExtend(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtend2(t *testing.T) {
|
func TestExtend2(t *testing.T) {
|
||||||
p := NewPage(1024, 4096)
|
p := packing.NewPage(1024, 4096)
|
||||||
s := p.Size()
|
s := p.Size()
|
||||||
p.Alloc(s/2, s/2)
|
p.Alloc(s/2, s/2)
|
||||||
n1 := p.Alloc(s/2, s/2)
|
n1 := p.Alloc(s/2, s/2)
|
||||||
@ -331,7 +331,7 @@ func TestExtend2(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #1454
|
// Issue #1454
|
||||||
func TestExtendTooMuch(t *testing.T) {
|
func TestExtendTooMuch(t *testing.T) {
|
||||||
p := NewPage(1024, 4096)
|
p := packing.NewPage(1024, 4096)
|
||||||
p.Alloc(1, 1)
|
p.Alloc(1, 1)
|
||||||
if got, want := p.Extend(3), false; got != want {
|
if got, want := p.Extend(3), false; got != want {
|
||||||
t.Errorf("got: %t, want: %t", got, want)
|
t.Errorf("got: %t, want: %t", got, want)
|
||||||
@ -339,7 +339,7 @@ func TestExtendTooMuch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendWithoutAllocation(t *testing.T) {
|
func TestExtendWithoutAllocation(t *testing.T) {
|
||||||
p := NewPage(1024, 4096)
|
p := packing.NewPage(1024, 4096)
|
||||||
|
|
||||||
if got, want := p.Extend(2), true; got != want {
|
if got, want := p.Extend(2), true; got != want {
|
||||||
t.Errorf("got: %t, want: %t", got, want)
|
t.Errorf("got: %t, want: %t", got, want)
|
||||||
|
@ -22,16 +22,16 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||||
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
EnableRestoringForTesting()
|
restorable.EnableRestoringForTesting()
|
||||||
t.MainWithRunLoop(m)
|
t.MainWithRunLoop(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pixelsToColor(p *Pixels, i, j int) color.RGBA {
|
func pixelsToColor(p *restorable.Pixels, i, j int) color.RGBA {
|
||||||
r, g, b, a := p.At(i, j)
|
r, g, b, a := p.At(i, j)
|
||||||
return color.RGBA{r, g, b, a}
|
return color.RGBA{r, g, b, a}
|
||||||
}
|
}
|
||||||
@ -56,15 +56,15 @@ func sameColors(c1, c2 color.RGBA, delta int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRestore(t *testing.T) {
|
func TestRestore(t *testing.T) {
|
||||||
img0 := NewImage(1, 1)
|
img0 := restorable.NewImage(1, 1)
|
||||||
defer img0.Dispose()
|
defer img0.Dispose()
|
||||||
|
|
||||||
clr0 := color.RGBA{0x00, 0x00, 0x00, 0xff}
|
clr0 := color.RGBA{0x00, 0x00, 0x00, 0xff}
|
||||||
img0.ReplacePixels([]byte{clr0.R, clr0.G, clr0.B, clr0.A}, 0, 0, 1, 1)
|
img0.ReplacePixels([]byte{clr0.R, clr0.G, clr0.B, clr0.A}, 0, 0, 1, 1)
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
want := clr0
|
want := clr0
|
||||||
@ -75,15 +75,15 @@ func TestRestore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRestoreWithoutDraw(t *testing.T) {
|
func TestRestoreWithoutDraw(t *testing.T) {
|
||||||
img0 := NewImage(1024, 1024)
|
img0 := restorable.NewImage(1024, 1024)
|
||||||
defer img0.Dispose()
|
defer img0.Dispose()
|
||||||
|
|
||||||
// If there is no drawing command on img0, img0 is cleared when restored.
|
// If there is no drawing command on img0, img0 is cleared when restored.
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,9 +117,9 @@ func quadVertices(sw, sh, x, y int) []float32 {
|
|||||||
|
|
||||||
func TestRestoreChain(t *testing.T) {
|
func TestRestoreChain(t *testing.T) {
|
||||||
const num = 10
|
const num = 10
|
||||||
imgs := []*Image{}
|
imgs := []*restorable.Image{}
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
img := NewImage(1, 1)
|
img := restorable.NewImage(1, 1)
|
||||||
imgs = append(imgs, img)
|
imgs = append(imgs, img)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -138,12 +138,12 @@ func TestRestoreChain(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
want := clr
|
want := clr
|
||||||
@ -161,9 +161,9 @@ func TestRestoreChain2(t *testing.T) {
|
|||||||
w = 1
|
w = 1
|
||||||
h = 1
|
h = 1
|
||||||
)
|
)
|
||||||
imgs := []*Image{}
|
imgs := []*restorable.Image{}
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
img := NewImage(w, h)
|
img := restorable.NewImage(w, h)
|
||||||
imgs = append(imgs, img)
|
imgs = append(imgs, img)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -186,16 +186,16 @@ func TestRestoreChain2(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
imgs[8].DrawTriangles([graphics.ShaderImageNum]*Image{imgs[7]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
imgs[8].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[7]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
imgs[9].DrawTriangles([graphics.ShaderImageNum]*Image{imgs[8]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
imgs[9].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[8]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
for i := 0; i < 7; i++ {
|
for i := 0; i < 7; i++ {
|
||||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for i, img := range imgs {
|
for i, img := range imgs {
|
||||||
@ -215,10 +215,10 @@ func TestRestoreOverrideSource(t *testing.T) {
|
|||||||
w = 1
|
w = 1
|
||||||
h = 1
|
h = 1
|
||||||
)
|
)
|
||||||
img0 := NewImage(w, h)
|
img0 := restorable.NewImage(w, h)
|
||||||
img1 := NewImage(w, h)
|
img1 := restorable.NewImage(w, h)
|
||||||
img2 := NewImage(w, h)
|
img2 := restorable.NewImage(w, h)
|
||||||
img3 := NewImage(w, h)
|
img3 := restorable.NewImage(w, h)
|
||||||
defer func() {
|
defer func() {
|
||||||
img3.Dispose()
|
img3.Dispose()
|
||||||
img2.Dispose()
|
img2.Dispose()
|
||||||
@ -235,14 +235,14 @@ func TestRestoreOverrideSource(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
img2.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img2.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
img3.DrawTriangles([graphics.ShaderImageNum]*Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
img0.ReplacePixels([]byte{clr1.R, clr1.G, clr1.B, clr1.A}, 0, 0, w, h)
|
img0.ReplacePixels([]byte{clr1.R, clr1.G, clr1.B, clr1.A}, 0, 0, w, h)
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -300,11 +300,11 @@ func TestRestoreComplexGraph(t *testing.T) {
|
|||||||
img0 := newImageFromImage(base)
|
img0 := newImageFromImage(base)
|
||||||
img1 := newImageFromImage(base)
|
img1 := newImageFromImage(base)
|
||||||
img2 := newImageFromImage(base)
|
img2 := newImageFromImage(base)
|
||||||
img3 := NewImage(w, h)
|
img3 := restorable.NewImage(w, h)
|
||||||
img4 := NewImage(w, h)
|
img4 := restorable.NewImage(w, h)
|
||||||
img5 := NewImage(w, h)
|
img5 := restorable.NewImage(w, h)
|
||||||
img6 := NewImage(w, h)
|
img6 := restorable.NewImage(w, h)
|
||||||
img7 := NewImage(w, h)
|
img7 := restorable.NewImage(w, h)
|
||||||
defer func() {
|
defer func() {
|
||||||
img7.Dispose()
|
img7.Dispose()
|
||||||
img6.Dispose()
|
img6.Dispose()
|
||||||
@ -324,33 +324,33 @@ func TestRestoreComplexGraph(t *testing.T) {
|
|||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageNum - 1][2]float32
|
||||||
img3.DrawTriangles([graphics.ShaderImageNum]*Image{img0}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 1, 0)
|
vs = quadVertices(w, h, 1, 0)
|
||||||
img3.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 1, 0)
|
vs = quadVertices(w, h, 1, 0)
|
||||||
img4.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 2, 0)
|
vs = quadVertices(w, h, 2, 0)
|
||||||
img4.DrawTriangles([graphics.ShaderImageNum]*Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 0, 0)
|
vs = quadVertices(w, h, 0, 0)
|
||||||
img5.DrawTriangles([graphics.ShaderImageNum]*Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img5.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 0, 0)
|
vs = quadVertices(w, h, 0, 0)
|
||||||
img6.DrawTriangles([graphics.ShaderImageNum]*Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 1, 0)
|
vs = quadVertices(w, h, 1, 0)
|
||||||
img6.DrawTriangles([graphics.ShaderImageNum]*Image{img4}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img4}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 0, 0)
|
vs = quadVertices(w, h, 0, 0)
|
||||||
img7.DrawTriangles([graphics.ShaderImageNum]*Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(w, h, 2, 0)
|
vs = quadVertices(w, h, 2, 0)
|
||||||
img7.DrawTriangles([graphics.ShaderImageNum]*Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
out string
|
out string
|
||||||
image *Image
|
image *restorable.Image
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"0",
|
"0",
|
||||||
@ -407,9 +407,9 @@ func TestRestoreComplexGraph(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImageFromImage(rgba *image.RGBA) *Image {
|
func newImageFromImage(rgba *image.RGBA) *restorable.Image {
|
||||||
s := rgba.Bounds().Size()
|
s := rgba.Bounds().Size()
|
||||||
img := NewImage(s.X, s.Y)
|
img := restorable.NewImage(s.X, s.Y)
|
||||||
img.ReplacePixels(rgba.Pix, 0, 0, s.X, s.Y)
|
img.ReplacePixels(rgba.Pix, 0, 0, s.X, s.Y)
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
@ -426,7 +426,7 @@ func TestRestoreRecursive(t *testing.T) {
|
|||||||
base.Pix[3] = 0xff
|
base.Pix[3] = 0xff
|
||||||
|
|
||||||
img0 := newImageFromImage(base)
|
img0 := newImageFromImage(base)
|
||||||
img1 := NewImage(w, h)
|
img1 := restorable.NewImage(w, h)
|
||||||
defer func() {
|
defer func() {
|
||||||
img1.Dispose()
|
img1.Dispose()
|
||||||
img0.Dispose()
|
img0.Dispose()
|
||||||
@ -438,18 +438,18 @@ func TestRestoreRecursive(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
out string
|
out string
|
||||||
image *Image
|
image *restorable.Image
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"0",
|
"0",
|
||||||
@ -477,7 +477,7 @@ func TestRestoreRecursive(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestReplacePixels(t *testing.T) {
|
func TestReplacePixels(t *testing.T) {
|
||||||
img := NewImage(17, 31)
|
img := restorable.NewImage(17, 31)
|
||||||
defer img.Dispose()
|
defer img.Dispose()
|
||||||
|
|
||||||
pix := make([]byte, 4*4*4)
|
pix := make([]byte, 4*4*4)
|
||||||
@ -499,10 +499,10 @@ func TestReplacePixels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for j := 7; j < 11; j++ {
|
for j := 7; j < 11; j++ {
|
||||||
@ -528,7 +528,7 @@ func TestDrawTrianglesAndReplacePixels(t *testing.T) {
|
|||||||
base.Pix[3] = 0xff
|
base.Pix[3] = 0xff
|
||||||
img0 := newImageFromImage(base)
|
img0 := newImageFromImage(base)
|
||||||
defer img0.Dispose()
|
defer img0.Dispose()
|
||||||
img1 := NewImage(2, 1)
|
img1 := restorable.NewImage(2, 1)
|
||||||
defer img1.Dispose()
|
defer img1.Dispose()
|
||||||
|
|
||||||
vs := quadVertices(1, 1, 0, 0)
|
vs := quadVertices(1, 1, 0, 0)
|
||||||
@ -539,13 +539,13 @@ func TestDrawTrianglesAndReplacePixels(t *testing.T) {
|
|||||||
Width: 2,
|
Width: 2,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0, 0, 2, 1)
|
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0, 0, 2, 1)
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, g, b, a, err := img1.At(0, 0)
|
r, g, b, a, err := img1.At(0, 0)
|
||||||
@ -582,14 +582,14 @@ func TestDispose(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
img1.Dispose()
|
img1.Dispose()
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, g, b, a, err := img0.At(0, 0)
|
r, g, b, a, err := img0.At(0, 0)
|
||||||
@ -609,7 +609,7 @@ func TestReplacePixelsPart(t *testing.T) {
|
|||||||
pix[i] = 0xff
|
pix[i] = 0xff
|
||||||
}
|
}
|
||||||
|
|
||||||
img := NewImage(4, 4)
|
img := restorable.NewImage(4, 4)
|
||||||
// This doesn't make the image stale. Its base pixels are available.
|
// This doesn't make the image stale. Its base pixels are available.
|
||||||
img.ReplacePixels(pix, 1, 1, 2, 2)
|
img.ReplacePixels(pix, 1, 1, 2, 2)
|
||||||
|
|
||||||
@ -680,9 +680,9 @@ func TestReplacePixelsPart(t *testing.T) {
|
|||||||
|
|
||||||
func TestReplacePixelsOnly(t *testing.T) {
|
func TestReplacePixelsOnly(t *testing.T) {
|
||||||
const w, h = 128, 128
|
const w, h = 128, 128
|
||||||
img0 := NewImage(w, h)
|
img0 := restorable.NewImage(w, h)
|
||||||
defer img0.Dispose()
|
defer img0.Dispose()
|
||||||
img1 := NewImage(1, 1)
|
img1 := restorable.NewImage(1, 1)
|
||||||
defer img1.Dispose()
|
defer img1.Dispose()
|
||||||
|
|
||||||
for i := 0; i < w*h; i += 5 {
|
for i := 0; i < w*h; i += 5 {
|
||||||
@ -697,7 +697,7 @@ func TestReplacePixelsOnly(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
img0.ReplacePixels([]byte{5, 6, 7, 8}, 0, 0, 1, 1)
|
img0.ReplacePixels([]byte{5, 6, 7, 8}, 0, 0, 1, 1)
|
||||||
|
|
||||||
// BasePixelsForTesting is available without GPU accessing.
|
// BasePixelsForTesting is available without GPU accessing.
|
||||||
@ -718,10 +718,10 @@ func TestReplacePixelsOnly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
want := color.RGBA{1, 2, 3, 4}
|
want := color.RGBA{1, 2, 3, 4}
|
||||||
@ -736,9 +736,9 @@ func TestReplacePixelsOnly(t *testing.T) {
|
|||||||
// Issue #793
|
// Issue #793
|
||||||
func TestReadPixelsFromVolatileImage(t *testing.T) {
|
func TestReadPixelsFromVolatileImage(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst := NewImage(w, h)
|
dst := restorable.NewImage(w, h)
|
||||||
dst.SetVolatile(true)
|
dst.SetVolatile(true)
|
||||||
src := NewImage(w, h)
|
src := restorable.NewImage(w, h)
|
||||||
|
|
||||||
// First, make sure that dst has pixels
|
// First, make sure that dst has pixels
|
||||||
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
||||||
@ -757,7 +757,7 @@ func TestReadPixelsFromVolatileImage(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
|
|
||||||
// Read the pixels. If the implementation is correct, dst tries to read its pixels from GPU due to being
|
// Read the pixels. If the implementation is correct, dst tries to read its pixels from GPU due to being
|
||||||
// stale.
|
// stale.
|
||||||
@ -773,8 +773,8 @@ func TestReadPixelsFromVolatileImage(t *testing.T) {
|
|||||||
|
|
||||||
func TestAllowReplacePixelsAfterDrawTriangles(t *testing.T) {
|
func TestAllowReplacePixelsAfterDrawTriangles(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src := NewImage(w, h)
|
src := restorable.NewImage(w, h)
|
||||||
dst := NewImage(w, h)
|
dst := restorable.NewImage(w, h)
|
||||||
|
|
||||||
vs := quadVertices(w, h, 0, 0)
|
vs := quadVertices(w, h, 0, 0)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
@ -784,7 +784,7 @@ func TestAllowReplacePixelsAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
||||||
// ReplacePixels for a whole image doesn't panic.
|
// ReplacePixels for a whole image doesn't panic.
|
||||||
}
|
}
|
||||||
@ -797,8 +797,8 @@ func TestDisallowReplacePixelsForPartAfterDrawTriangles(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src := NewImage(w, h)
|
src := restorable.NewImage(w, h)
|
||||||
dst := NewImage(w, h)
|
dst := restorable.NewImage(w, h)
|
||||||
|
|
||||||
vs := quadVertices(w, h, 0, 0)
|
vs := quadVertices(w, h, 0, 0)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
@ -808,7 +808,7 @@ func TestDisallowReplacePixelsForPartAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,7 +818,7 @@ func TestExtend(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
orig := NewImage(w, h)
|
orig := restorable.NewImage(w, h)
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -853,7 +853,7 @@ func TestExtend(t *testing.T) {
|
|||||||
|
|
||||||
func TestClearPixels(t *testing.T) {
|
func TestClearPixels(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
img := NewImage(w, h)
|
img := restorable.NewImage(w, h)
|
||||||
img.ReplacePixels(make([]byte, 4*4*4), 0, 0, 4, 4)
|
img.ReplacePixels(make([]byte, 4*4*4), 0, 0, 4, 4)
|
||||||
img.ReplacePixels(make([]byte, 4*4*4), 4, 0, 4, 4)
|
img.ReplacePixels(make([]byte, 4*4*4), 4, 0, 4, 4)
|
||||||
img.ClearPixels(0, 0, 4, 4)
|
img.ClearPixels(0, 0, 4, 4)
|
||||||
@ -865,8 +865,8 @@ func TestClearPixels(t *testing.T) {
|
|||||||
|
|
||||||
func TestMutateSlices(t *testing.T) {
|
func TestMutateSlices(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst := NewImage(w, h)
|
dst := restorable.NewImage(w, h)
|
||||||
src := NewImage(w, h)
|
src := restorable.NewImage(w, h)
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for i := 0; i < w*h; i++ {
|
for i := 0; i < w*h; i++ {
|
||||||
pix[4*i] = byte(i)
|
pix[4*i] = byte(i)
|
||||||
@ -885,17 +885,17 @@ func TestMutateSlices(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
for i := range vs {
|
for i := range vs {
|
||||||
vs[i] = 0
|
vs[i] = 0
|
||||||
}
|
}
|
||||||
for i := range is {
|
for i := range is {
|
||||||
is[i] = 0
|
is[i] = 0
|
||||||
}
|
}
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||||
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func clearImage(img *Image, w, h int) {
|
func clearImage(img *restorable.Image, w, h int) {
|
||||||
emptyImage := NewImage(3, 3)
|
emptyImage := restorable.NewImage(3, 3)
|
||||||
defer emptyImage.Dispose()
|
defer emptyImage.Dispose()
|
||||||
|
|
||||||
dx0 := float32(0)
|
dx0 := float32(0)
|
||||||
@ -50,27 +50,27 @@ func clearImage(img *Image, w, h int) {
|
|||||||
Width: float32(w),
|
Width: float32(w),
|
||||||
Height: float32(h),
|
Height: float32(h),
|
||||||
}
|
}
|
||||||
img.DrawTriangles([graphics.ShaderImageNum]*Image{emptyImage}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{emptyImage}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShader(t *testing.T) {
|
func TestShader(t *testing.T) {
|
||||||
img := NewImage(1, 1)
|
img := restorable.NewImage(1, 1)
|
||||||
defer img.Dispose()
|
defer img.Dispose()
|
||||||
|
|
||||||
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
||||||
s := NewShader(&ir)
|
s := restorable.NewShader(&ir)
|
||||||
dr := driver.Region{
|
dr := driver.Region{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: 0,
|
Y: 0,
|
||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img.DrawTriangles([graphics.ShaderImageNum]*Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,9 +83,9 @@ func TestShader(t *testing.T) {
|
|||||||
|
|
||||||
func TestShaderChain(t *testing.T) {
|
func TestShaderChain(t *testing.T) {
|
||||||
const num = 10
|
const num = 10
|
||||||
imgs := []*Image{}
|
imgs := []*restorable.Image{}
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
img := NewImage(1, 1)
|
img := restorable.NewImage(1, 1)
|
||||||
defer img.Dispose()
|
defer img.Dispose()
|
||||||
imgs = append(imgs, img)
|
imgs = append(imgs, img)
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func TestShaderChain(t *testing.T) {
|
|||||||
imgs[0].ReplacePixels([]byte{0xff, 0, 0, 0xff}, 0, 0, 1, 1)
|
imgs[0].ReplacePixels([]byte{0xff, 0, 0, 0xff}, 0, 0, 1, 1)
|
||||||
|
|
||||||
ir := etesting.ShaderProgramImages(1)
|
ir := etesting.ShaderProgramImages(1)
|
||||||
s := NewShader(&ir)
|
s := restorable.NewShader(&ir)
|
||||||
for i := 0; i < num-1; i++ {
|
for i := 0; i < num-1; i++ {
|
||||||
dr := driver.Region{
|
dr := driver.Region{
|
||||||
X: 0,
|
X: 0,
|
||||||
@ -101,13 +101,13 @@ func TestShaderChain(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,18 +121,18 @@ func TestShaderChain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderMultipleSources(t *testing.T) {
|
func TestShaderMultipleSources(t *testing.T) {
|
||||||
var srcs [graphics.ShaderImageNum]*Image
|
var srcs [graphics.ShaderImageNum]*restorable.Image
|
||||||
for i := range srcs {
|
for i := range srcs {
|
||||||
srcs[i] = NewImage(1, 1)
|
srcs[i] = restorable.NewImage(1, 1)
|
||||||
}
|
}
|
||||||
srcs[0].ReplacePixels([]byte{0x40, 0, 0, 0xff}, 0, 0, 1, 1)
|
srcs[0].ReplacePixels([]byte{0x40, 0, 0, 0xff}, 0, 0, 1, 1)
|
||||||
srcs[1].ReplacePixels([]byte{0, 0x80, 0, 0xff}, 0, 0, 1, 1)
|
srcs[1].ReplacePixels([]byte{0, 0x80, 0, 0xff}, 0, 0, 1, 1)
|
||||||
srcs[2].ReplacePixels([]byte{0, 0, 0xc0, 0xff}, 0, 0, 1, 1)
|
srcs[2].ReplacePixels([]byte{0, 0, 0xc0, 0xff}, 0, 0, 1, 1)
|
||||||
|
|
||||||
dst := NewImage(1, 1)
|
dst := restorable.NewImage(1, 1)
|
||||||
|
|
||||||
ir := etesting.ShaderProgramImages(3)
|
ir := etesting.ShaderProgramImages(3)
|
||||||
s := NewShader(&ir)
|
s := restorable.NewShader(&ir)
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageNum - 1][2]float32
|
||||||
dr := driver.Region{
|
dr := driver.Region{
|
||||||
X: 0,
|
X: 0,
|
||||||
@ -145,10 +145,10 @@ func TestShaderMultipleSources(t *testing.T) {
|
|||||||
// Clear one of the sources after DrawTriangles. dst should not be affected.
|
// Clear one of the sources after DrawTriangles. dst should not be affected.
|
||||||
clearImage(srcs[0], 1, 1)
|
clearImage(srcs[0], 1, 1)
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,18 +160,18 @@ func TestShaderMultipleSources(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderMultipleSourcesOnOneTexture(t *testing.T) {
|
func TestShaderMultipleSourcesOnOneTexture(t *testing.T) {
|
||||||
src := NewImage(3, 1)
|
src := restorable.NewImage(3, 1)
|
||||||
src.ReplacePixels([]byte{
|
src.ReplacePixels([]byte{
|
||||||
0x40, 0, 0, 0xff,
|
0x40, 0, 0, 0xff,
|
||||||
0, 0x80, 0, 0xff,
|
0, 0x80, 0, 0xff,
|
||||||
0, 0, 0xc0, 0xff,
|
0, 0, 0xc0, 0xff,
|
||||||
}, 0, 0, 3, 1)
|
}, 0, 0, 3, 1)
|
||||||
srcs := [graphics.ShaderImageNum]*Image{src, src, src}
|
srcs := [graphics.ShaderImageNum]*restorable.Image{src, src, src}
|
||||||
|
|
||||||
dst := NewImage(1, 1)
|
dst := restorable.NewImage(1, 1)
|
||||||
|
|
||||||
ir := etesting.ShaderProgramImages(3)
|
ir := etesting.ShaderProgramImages(3)
|
||||||
s := NewShader(&ir)
|
s := restorable.NewShader(&ir)
|
||||||
offsets := [graphics.ShaderImageNum - 1][2]float32{
|
offsets := [graphics.ShaderImageNum - 1][2]float32{
|
||||||
{1, 0},
|
{1, 0},
|
||||||
{2, 0},
|
{2, 0},
|
||||||
@ -187,10 +187,10 @@ func TestShaderMultipleSourcesOnOneTexture(t *testing.T) {
|
|||||||
// Clear one of the sources after DrawTriangles. dst should not be affected.
|
// Clear one of the sources after DrawTriangles. dst should not be affected.
|
||||||
clearImage(srcs[0], 3, 1)
|
clearImage(srcs[0], 3, 1)
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,27 +202,27 @@ func TestShaderMultipleSourcesOnOneTexture(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderDispose(t *testing.T) {
|
func TestShaderDispose(t *testing.T) {
|
||||||
img := NewImage(1, 1)
|
img := restorable.NewImage(1, 1)
|
||||||
defer img.Dispose()
|
defer img.Dispose()
|
||||||
|
|
||||||
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
||||||
s := NewShader(&ir)
|
s := restorable.NewShader(&ir)
|
||||||
dr := driver.Region{
|
dr := driver.Region{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: 0,
|
Y: 0,
|
||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img.DrawTriangles([graphics.ShaderImageNum]*Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||||
|
|
||||||
// Dispose the shader. This should invalidates all the images using this shader i.e., all the images become
|
// Dispose the shader. This should invalidates all the images using this shader i.e., all the images become
|
||||||
// stale.
|
// stale.
|
||||||
s.Dispose()
|
s.Dispose()
|
||||||
|
|
||||||
if err := ResolveStaleImages(); err != nil {
|
if err := restorable.ResolveStaleImages(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := RestoreIfNeeded(); err != nil {
|
if err := restorable.RestoreIfNeeded(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/shader"
|
"github.com/hajimehoshi/ebiten/v2/internal/shader"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/glsl"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/glsl"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/metal"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/metal"
|
||||||
)
|
)
|
||||||
@ -150,7 +150,7 @@ func TestCompile(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := Compile(fset, f, "Vertex", "Fragment", 0)
|
s, err := shader.Compile(fset, f, "Vertex", "Fragment", 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -18,59 +18,59 @@ import (
|
|||||||
"go/constant"
|
"go/constant"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/glsl"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/glsl"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/metal"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/metal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func block(localVars []Type, offset int, stmts ...Stmt) *Block {
|
func block(localVars []shaderir.Type, offset int, stmts ...shaderir.Stmt) *shaderir.Block {
|
||||||
return &Block{
|
return &shaderir.Block{
|
||||||
LocalVars: localVars,
|
LocalVars: localVars,
|
||||||
LocalVarIndexOffset: offset,
|
LocalVarIndexOffset: offset,
|
||||||
Stmts: stmts,
|
Stmts: stmts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func exprStmt(expr Expr) Stmt {
|
func exprStmt(expr shaderir.Expr) shaderir.Stmt {
|
||||||
return Stmt{
|
return shaderir.Stmt{
|
||||||
Type: ExprStmt,
|
Type: shaderir.ExprStmt,
|
||||||
Exprs: []Expr{expr},
|
Exprs: []shaderir.Expr{expr},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func blockStmt(block *Block) Stmt {
|
func blockStmt(block *shaderir.Block) shaderir.Stmt {
|
||||||
return Stmt{
|
return shaderir.Stmt{
|
||||||
Type: BlockStmt,
|
Type: shaderir.BlockStmt,
|
||||||
Blocks: []*Block{block},
|
Blocks: []*shaderir.Block{block},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func returnStmt(expr Expr) Stmt {
|
func returnStmt(expr shaderir.Expr) shaderir.Stmt {
|
||||||
return Stmt{
|
return shaderir.Stmt{
|
||||||
Type: Return,
|
Type: shaderir.Return,
|
||||||
Exprs: []Expr{expr},
|
Exprs: []shaderir.Expr{expr},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assignStmt(lhs Expr, rhs Expr) Stmt {
|
func assignStmt(lhs shaderir.Expr, rhs shaderir.Expr) shaderir.Stmt {
|
||||||
return Stmt{
|
return shaderir.Stmt{
|
||||||
Type: Assign,
|
Type: shaderir.Assign,
|
||||||
Exprs: []Expr{lhs, rhs},
|
Exprs: []shaderir.Expr{lhs, rhs},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ifStmt(cond Expr, block *Block, elseBlock *Block) Stmt {
|
func ifStmt(cond shaderir.Expr, block *shaderir.Block, elseBlock *shaderir.Block) shaderir.Stmt {
|
||||||
return Stmt{
|
return shaderir.Stmt{
|
||||||
Type: If,
|
Type: shaderir.If,
|
||||||
Exprs: []Expr{cond},
|
Exprs: []shaderir.Expr{cond},
|
||||||
Blocks: []*Block{block, elseBlock},
|
Blocks: []*shaderir.Block{block, elseBlock},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func forStmt(t Type, index, init, end int, op Op, delta int, block *Block) Stmt {
|
func forStmt(t shaderir.Type, index, init, end int, op shaderir.Op, delta int, block *shaderir.Block) shaderir.Stmt {
|
||||||
return Stmt{
|
return shaderir.Stmt{
|
||||||
Type: For,
|
Type: shaderir.For,
|
||||||
Blocks: []*Block{block},
|
Blocks: []*shaderir.Block{block},
|
||||||
ForVarType: t,
|
ForVarType: t,
|
||||||
ForVarIndex: index,
|
ForVarIndex: index,
|
||||||
ForInit: constant.MakeInt64(int64(init)),
|
ForInit: constant.MakeInt64(int64(init)),
|
||||||
@ -80,74 +80,74 @@ func forStmt(t Type, index, init, end int, op Op, delta int, block *Block) Stmt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func floatExpr(value float32) Expr {
|
func floatExpr(value float32) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: constant.MakeFloat64(float64(value)),
|
Const: constant.MakeFloat64(float64(value)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func uniformVariableExpr(index int) Expr {
|
func uniformVariableExpr(index int) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: UniformVariable,
|
Type: shaderir.UniformVariable,
|
||||||
Index: index,
|
Index: index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func localVariableExpr(index int) Expr {
|
func localVariableExpr(index int) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: LocalVariable,
|
Type: shaderir.LocalVariable,
|
||||||
Index: index,
|
Index: index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func builtinFuncExpr(f BuiltinFunc) Expr {
|
func builtinFuncExpr(f shaderir.BuiltinFunc) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: BuiltinFuncExpr,
|
Type: shaderir.BuiltinFuncExpr,
|
||||||
BuiltinFunc: f,
|
BuiltinFunc: f,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func swizzlingExpr(swizzling string) Expr {
|
func swizzlingExpr(swizzling string) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: SwizzlingExpr,
|
Type: shaderir.SwizzlingExpr,
|
||||||
Swizzling: swizzling,
|
Swizzling: swizzling,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func functionExpr(index int) Expr {
|
func functionExpr(index int) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: FunctionExpr,
|
Type: shaderir.FunctionExpr,
|
||||||
Index: index,
|
Index: index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func binaryExpr(op Op, exprs ...Expr) Expr {
|
func binaryExpr(op shaderir.Op, exprs ...shaderir.Expr) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: Binary,
|
Type: shaderir.Binary,
|
||||||
Op: op,
|
Op: op,
|
||||||
Exprs: exprs,
|
Exprs: exprs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectionExpr(cond, a, b Expr) Expr {
|
func selectionExpr(cond, a, b shaderir.Expr) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: Selection,
|
Type: shaderir.Selection,
|
||||||
Exprs: []Expr{cond, a, b},
|
Exprs: []shaderir.Expr{cond, a, b},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func callExpr(callee Expr, args ...Expr) Expr {
|
func callExpr(callee shaderir.Expr, args ...shaderir.Expr) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: Call,
|
Type: shaderir.Call,
|
||||||
Exprs: append([]Expr{callee}, args...),
|
Exprs: append([]shaderir.Expr{callee}, args...),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fieldSelectorExpr(a, b Expr) Expr {
|
func fieldSelectorExpr(a, b shaderir.Expr) shaderir.Expr {
|
||||||
return Expr{
|
return shaderir.Expr{
|
||||||
Type: FieldSelector,
|
Type: shaderir.FieldSelector,
|
||||||
Exprs: []Expr{a, b},
|
Exprs: []shaderir.Expr{a, b},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,22 +156,22 @@ func TestOutput(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Name string
|
Name string
|
||||||
Program Program
|
Program shaderir.Program
|
||||||
GlslVS string
|
GlslVS string
|
||||||
GlslFS string
|
GlslFS string
|
||||||
Metal string
|
Metal string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "Empty",
|
Name: "Empty",
|
||||||
Program: Program{},
|
Program: shaderir.Program{},
|
||||||
GlslVS: ``,
|
GlslVS: ``,
|
||||||
GlslFS: glsl.FragmentPrelude(glsl.GLSLVersionDefault),
|
GlslFS: glsl.FragmentPrelude(glsl.GLSLVersionDefault),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Uniform",
|
Name: "Uniform",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Uniforms: []Type{
|
Uniforms: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
GlslVS: `uniform float U0;`,
|
GlslVS: `uniform float U0;`,
|
||||||
@ -180,12 +180,12 @@ uniform float U0;`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "UniformStruct",
|
Name: "UniformStruct",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Uniforms: []Type{
|
Uniforms: []shaderir.Type{
|
||||||
{
|
{
|
||||||
Main: Struct,
|
Main: shaderir.Struct,
|
||||||
Sub: []Type{
|
Sub: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -204,15 +204,15 @@ uniform S0 U0;`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Vars",
|
Name: "Vars",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Uniforms: []Type{
|
Uniforms: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Attributes: []Type{
|
Attributes: []shaderir.Type{
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
Varyings: []Type{
|
Varyings: []shaderir.Type{
|
||||||
{Main: Vec3},
|
{Main: shaderir.Vec3},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
GlslVS: `uniform float U0;
|
GlslVS: `uniform float U0;
|
||||||
@ -224,8 +224,8 @@ varying vec3 V0;`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Func",
|
Name: "Func",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
@ -243,17 +243,17 @@ void F0(void) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "FuncParams",
|
Name: "FuncParams",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
{Main: Vec4},
|
{Main: shaderir.Vec4},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Mat4},
|
{Main: shaderir.Mat4},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -270,14 +270,14 @@ void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "FuncReturn",
|
Name: "FuncReturn",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Return: Type{Main: Float},
|
Return: shaderir.Type{Main: shaderir.Float},
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
1,
|
1,
|
||||||
@ -302,19 +302,19 @@ float F0(in float l0) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "FuncLocals",
|
Name: "FuncLocals",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block([]Type{
|
Block: block([]shaderir.Type{
|
||||||
{Main: Mat4},
|
{Main: shaderir.Mat4},
|
||||||
{Main: Mat4},
|
{Main: shaderir.Mat4},
|
||||||
}, 2),
|
}, 2),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -335,27 +335,27 @@ void F0(in float l0, out float l1) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "FuncBlocks",
|
Name: "FuncBlocks",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{Main: Mat4},
|
{Main: shaderir.Mat4},
|
||||||
{Main: Mat4},
|
{Main: shaderir.Mat4},
|
||||||
},
|
},
|
||||||
2,
|
2,
|
||||||
blockStmt(
|
blockStmt(
|
||||||
block(
|
block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{Main: Mat4},
|
{Main: shaderir.Mat4},
|
||||||
{Main: Mat4},
|
{Main: shaderir.Mat4},
|
||||||
},
|
},
|
||||||
4,
|
4,
|
||||||
),
|
),
|
||||||
@ -388,16 +388,16 @@ void F0(in float l0, out float l1) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Add",
|
Name: "Add",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
@ -405,7 +405,7 @@ void F0(in float l0, out float l1) {
|
|||||||
assignStmt(
|
assignStmt(
|
||||||
localVariableExpr(2),
|
localVariableExpr(2),
|
||||||
binaryExpr(
|
binaryExpr(
|
||||||
Add,
|
shaderir.Add,
|
||||||
localVariableExpr(0),
|
localVariableExpr(0),
|
||||||
localVariableExpr(1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
@ -428,17 +428,17 @@ void F0(in float l0, in float l1, out float l2) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Selection",
|
Name: "Selection",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Bool},
|
{Main: shaderir.Bool},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
@ -469,16 +469,16 @@ void F0(in bool l0, in float l1, in float l2, out float l3) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Call",
|
Name: "Call",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
@ -516,16 +516,16 @@ void F0(in float l0, in float l1, out vec2 l2) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "BuiltinFunc",
|
Name: "BuiltinFunc",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
@ -533,7 +533,7 @@ void F0(in float l0, in float l1, out vec2 l2) {
|
|||||||
assignStmt(
|
assignStmt(
|
||||||
localVariableExpr(2),
|
localVariableExpr(2),
|
||||||
callExpr(
|
callExpr(
|
||||||
builtinFuncExpr(Min),
|
builtinFuncExpr(shaderir.Min),
|
||||||
localVariableExpr(0),
|
localVariableExpr(0),
|
||||||
localVariableExpr(1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
@ -556,15 +556,15 @@ void F0(in float l0, in float l1, out float l2) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "FieldSelector",
|
Name: "FieldSelector",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Vec4},
|
{Main: shaderir.Vec4},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
@ -594,23 +594,23 @@ void F0(in vec4 l0, out vec2 l1) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "If",
|
Name: "If",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
3,
|
3,
|
||||||
ifStmt(
|
ifStmt(
|
||||||
binaryExpr(
|
binaryExpr(
|
||||||
EqualOp,
|
shaderir.EqualOp,
|
||||||
localVariableExpr(0),
|
localVariableExpr(0),
|
||||||
floatExpr(0),
|
floatExpr(0),
|
||||||
),
|
),
|
||||||
@ -657,28 +657,28 @@ void F0(in float l0, in float l1, out float l2) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "For",
|
Name: "For",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{},
|
{},
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
forStmt(
|
forStmt(
|
||||||
Type{Main: Int},
|
shaderir.Type{Main: shaderir.Int},
|
||||||
3,
|
3,
|
||||||
0,
|
0,
|
||||||
100,
|
100,
|
||||||
LessThanOp,
|
shaderir.LessThanOp,
|
||||||
1,
|
1,
|
||||||
block(
|
block(
|
||||||
nil,
|
nil,
|
||||||
@ -711,32 +711,32 @@ void F0(in float l0, in float l1, out float l2) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "For2",
|
Name: "For2",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{},
|
{},
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
forStmt(
|
forStmt(
|
||||||
Type{Main: Int},
|
shaderir.Type{Main: shaderir.Int},
|
||||||
3,
|
3,
|
||||||
0,
|
0,
|
||||||
100,
|
100,
|
||||||
LessThanOp,
|
shaderir.LessThanOp,
|
||||||
1,
|
1,
|
||||||
block(
|
block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{Main: Int},
|
{Main: shaderir.Int},
|
||||||
},
|
},
|
||||||
4,
|
4,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
@ -783,33 +783,33 @@ void F0(float l0, float l1, thread float& l2) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "For3",
|
Name: "For3",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Funcs: []Func{
|
Funcs: []shaderir.Func{
|
||||||
{
|
{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
InParams: []Type{
|
InParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
OutParams: []Type{
|
OutParams: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Block: block(
|
Block: block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
forStmt(
|
forStmt(
|
||||||
Type{Main: Int},
|
shaderir.Type{Main: shaderir.Int},
|
||||||
3,
|
3,
|
||||||
0,
|
0,
|
||||||
100,
|
100,
|
||||||
LessThanOp,
|
shaderir.LessThanOp,
|
||||||
1,
|
1,
|
||||||
block(
|
block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{Main: Int},
|
{Main: shaderir.Int},
|
||||||
},
|
},
|
||||||
4,
|
4,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
@ -819,15 +819,15 @@ void F0(float l0, float l1, thread float& l2) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
forStmt(
|
forStmt(
|
||||||
Type{Main: Float},
|
shaderir.Type{Main: shaderir.Float},
|
||||||
4,
|
4,
|
||||||
0,
|
0,
|
||||||
100,
|
100,
|
||||||
LessThanOp,
|
shaderir.LessThanOp,
|
||||||
1,
|
1,
|
||||||
block(
|
block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{Main: Int},
|
{Main: shaderir.Int},
|
||||||
},
|
},
|
||||||
5,
|
5,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
@ -886,20 +886,20 @@ void F0(float l0, float l1, thread float& l2) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "VertexFunc",
|
Name: "VertexFunc",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Uniforms: []Type{
|
Uniforms: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Attributes: []Type{
|
Attributes: []shaderir.Type{
|
||||||
{Main: Vec4},
|
{Main: shaderir.Vec4},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
Varyings: []Type{
|
Varyings: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
VertexFunc: VertexFunc{
|
VertexFunc: shaderir.VertexFunc{
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
4+1,
|
4+1,
|
||||||
@ -937,20 +937,20 @@ varying vec2 V1;`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "FragmentFunc",
|
Name: "FragmentFunc",
|
||||||
Program: Program{
|
Program: shaderir.Program{
|
||||||
Uniforms: []Type{
|
Uniforms: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
},
|
},
|
||||||
Attributes: []Type{
|
Attributes: []shaderir.Type{
|
||||||
{Main: Vec4},
|
{Main: shaderir.Vec4},
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
Varyings: []Type{
|
Varyings: []shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
VertexFunc: VertexFunc{
|
VertexFunc: shaderir.VertexFunc{
|
||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
5+1,
|
5+1,
|
||||||
@ -968,11 +968,11 @@ varying vec2 V1;`,
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
FragmentFunc: FragmentFunc{
|
FragmentFunc: shaderir.FragmentFunc{
|
||||||
Block: block(
|
Block: block(
|
||||||
[]Type{
|
[]shaderir.Type{
|
||||||
{Main: Float},
|
{Main: shaderir.Float},
|
||||||
{Main: Vec2},
|
{Main: shaderir.Vec2},
|
||||||
},
|
},
|
||||||
3+1,
|
3+1,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
|
188
shader_test.go
188
shader_test.go
@ -19,14 +19,14 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestShaderFill(t *testing.T) {
|
func TestShaderFill(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
return vec4(1, 0, 0, 1)
|
return vec4(1, 0, 0, 1)
|
||||||
@ -55,8 +55,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderFillWithDrawImage(t *testing.T) {
|
func TestShaderFillWithDrawImage(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
return vec4(1, 0, 0, 1)
|
return vec4(1, 0, 0, 1)
|
||||||
@ -66,8 +66,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src := NewImage(w/2, h/2)
|
src := ebiten.NewImage(w/2, h/2)
|
||||||
op := &DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
dst.DrawRectShader(w/2, h/2, s, op)
|
dst.DrawRectShader(w/2, h/2, s, op)
|
||||||
|
|
||||||
@ -88,8 +88,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderFillWithDrawTriangles(t *testing.T) {
|
func TestShaderFillWithDrawTriangles(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
return vec4(1, 0, 0, 1)
|
return vec4(1, 0, 0, 1)
|
||||||
@ -99,11 +99,11 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src := NewImage(w/2, h/2)
|
src := ebiten.NewImage(w/2, h/2)
|
||||||
op := &DrawTrianglesShaderOptions{}
|
op := &ebiten.DrawTrianglesShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
|
|
||||||
vs := []Vertex{
|
vs := []ebiten.Vertex{
|
||||||
{
|
{
|
||||||
DstX: 0,
|
DstX: 0,
|
||||||
DstY: 0,
|
DstY: 0,
|
||||||
@ -163,8 +163,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderFunction(t *testing.T) {
|
func TestShaderFunction(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func clr(red float) (float, float, float, float) {
|
func clr(red float) (float, float, float, float) {
|
||||||
return red, 0, 0, 1
|
return red, 0, 0, 1
|
||||||
@ -192,7 +192,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderShadowing(t *testing.T) {
|
func TestShaderShadowing(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var position vec4
|
var position vec4
|
||||||
@ -204,7 +204,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderDuplicatedVariables(t *testing.T) {
|
func TestShaderDuplicatedVariables(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var foo vec4
|
var foo vec4
|
||||||
@ -215,7 +215,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var foo, foo vec4
|
var foo, foo vec4
|
||||||
@ -225,7 +225,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var foo vec4
|
var foo vec4
|
||||||
@ -236,7 +236,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() (vec4, vec4) {
|
func Foo() (vec4, vec4) {
|
||||||
return vec4(0), vec4(0)
|
return vec4(0), vec4(0)
|
||||||
@ -252,7 +252,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderDuplicatedFunctions(t *testing.T) {
|
func TestShaderDuplicatedFunctions(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() {
|
func Foo() {
|
||||||
}
|
}
|
||||||
@ -269,14 +269,14 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderNoMain(t *testing.T) {
|
func TestShaderNoMain(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
`)); err == nil {
|
`)); err == nil {
|
||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderNoNewVariables(t *testing.T) {
|
func TestShaderNoNewVariables(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
_ := 1
|
_ := 1
|
||||||
@ -286,7 +286,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
_, _ := 1, 1
|
_, _ := 1, 1
|
||||||
@ -296,7 +296,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() (int, int) {
|
func Foo() (int, int) {
|
||||||
return 1, 1
|
return 1, 1
|
||||||
@ -310,7 +310,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
a, _ := 1, 1
|
a, _ := 1, 1
|
||||||
@ -321,7 +321,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
_, a := 1, 1
|
_, a := 1, 1
|
||||||
@ -334,7 +334,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderWrongReturn(t *testing.T) {
|
func TestShaderWrongReturn(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
return 0.0
|
return 0.0
|
||||||
@ -343,7 +343,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() (float, float) {
|
func Foo() (float, float) {
|
||||||
return 0
|
return 0
|
||||||
@ -356,7 +356,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
}
|
}
|
||||||
@ -364,7 +364,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() float {
|
func Foo() float {
|
||||||
}
|
}
|
||||||
@ -378,7 +378,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderMultipleValueReturn(t *testing.T) {
|
func TestShaderMultipleValueReturn(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() (float, float) {
|
func Foo() (float, float) {
|
||||||
return 0.0
|
return 0.0
|
||||||
@ -391,7 +391,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() float {
|
func Foo() float {
|
||||||
return 0.0, 0.0
|
return 0.0, 0.0
|
||||||
@ -404,7 +404,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() (float, float, float) {
|
func Foo() (float, float, float) {
|
||||||
return 0.0, 0.0
|
return 0.0, 0.0
|
||||||
@ -417,7 +417,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() (float, float) {
|
func Foo() (float, float) {
|
||||||
return 0.0, 0.0
|
return 0.0, 0.0
|
||||||
@ -434,7 +434,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Foo() (float, float, float) {
|
func Foo() (float, float, float) {
|
||||||
return 0.0, 0.0, 0.0
|
return 0.0, 0.0, 0.0
|
||||||
@ -453,7 +453,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderInit(t *testing.T) {
|
func TestShaderInit(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
}
|
}
|
||||||
@ -467,7 +467,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderUnspportedSyntax(t *testing.T) {
|
func TestShaderUnspportedSyntax(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := func() {
|
x := func() {
|
||||||
@ -479,7 +479,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
go func() {
|
go func() {
|
||||||
@ -490,7 +490,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
ch := make(chan int)
|
ch := make(chan int)
|
||||||
@ -501,7 +501,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := 1i
|
x := 1i
|
||||||
@ -512,7 +512,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var x [4]float
|
var x [4]float
|
||||||
@ -524,7 +524,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var x [4]float
|
var x [4]float
|
||||||
@ -540,8 +540,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderUninitializedUniformVariables(t *testing.T) {
|
func TestShaderUninitializedUniformVariables(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
var U vec4
|
var U vec4
|
||||||
|
|
||||||
@ -567,7 +567,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderForbidAssigningSpecialVariables(t *testing.T) {
|
func TestShaderForbidAssigningSpecialVariables(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
var U vec4
|
var U vec4
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
var U vec4
|
var U vec4
|
||||||
|
|
||||||
@ -591,7 +591,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
var U [2]vec4
|
var U [2]vec4
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
texCoord = vec2(0)
|
texCoord = vec2(0)
|
||||||
@ -613,7 +613,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
texCoord.x = 0
|
texCoord.x = 0
|
||||||
@ -625,7 +625,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderBoolLiteral(t *testing.T) {
|
func TestShaderBoolLiteral(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
true := vec4(0)
|
true := vec4(0)
|
||||||
@ -637,7 +637,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderUnusedVariable(t *testing.T) {
|
func TestShaderUnusedVariable(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := 0
|
x := 0
|
||||||
@ -647,7 +647,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := 0
|
x := 0
|
||||||
@ -658,7 +658,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := vec4(0)
|
x := vec4(0)
|
||||||
@ -671,7 +671,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
|
|
||||||
// Increment statement treats a variable 'used'.
|
// Increment statement treats a variable 'used'.
|
||||||
// https://play.golang.org/p/2RuYMrSLjt3
|
// https://play.golang.org/p/2RuYMrSLjt3
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := 0
|
x := 0
|
||||||
@ -682,7 +682,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var a int
|
var a int
|
||||||
@ -692,7 +692,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var a, b int
|
var a, b int
|
||||||
@ -704,7 +704,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderBlankLhs(t *testing.T) {
|
func TestShaderBlankLhs(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := _
|
x := _
|
||||||
@ -715,7 +715,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var x int = _
|
var x int = _
|
||||||
@ -726,7 +726,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := 1
|
x := 1
|
||||||
@ -738,7 +738,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
x := 1 + _
|
x := 1 + _
|
||||||
@ -749,7 +749,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
_++
|
_++
|
||||||
@ -759,7 +759,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
_ += 1
|
_ += 1
|
||||||
@ -769,7 +769,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
_.x = 1
|
_.x = 1
|
||||||
@ -781,7 +781,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderDuplicatedVarsAndConstants(t *testing.T) {
|
func TestShaderDuplicatedVarsAndConstants(t *testing.T) {
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var a = 0
|
var a = 0
|
||||||
@ -792,7 +792,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
const a = 0
|
const a = 0
|
||||||
@ -803,7 +803,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
const a = 0
|
const a = 0
|
||||||
@ -814,7 +814,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
const U0 = 0
|
const U0 = 0
|
||||||
var U0 float
|
var U0 float
|
||||||
@ -826,7 +826,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := NewShader([]byte(`package main
|
if _, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
var U0 float
|
var U0 float
|
||||||
const U0 = 0
|
const U0 = 0
|
||||||
@ -842,8 +842,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderMatrix(t *testing.T) {
|
func TestShaderMatrix(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
var a, b mat4
|
var a, b mat4
|
||||||
@ -862,8 +862,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src := NewImage(w, h)
|
src := ebiten.NewImage(w, h)
|
||||||
op := &DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
dst.DrawRectShader(w, h, s, op)
|
dst.DrawRectShader(w, h, s, op)
|
||||||
|
|
||||||
@ -881,7 +881,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderSubImage(t *testing.T) {
|
func TestShaderSubImage(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
r := imageSrc0At(texCoord).r
|
r := imageSrc0At(texCoord).r
|
||||||
@ -893,7 +893,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src0 := NewImage(w, h)
|
src0 := ebiten.NewImage(w, h)
|
||||||
pix0 := make([]byte, 4*w*h)
|
pix0 := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -906,9 +906,9 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
src0.ReplacePixels(pix0)
|
src0.ReplacePixels(pix0)
|
||||||
src0 = src0.SubImage(image.Rect(2, 3, 10, 11)).(*Image)
|
src0 = src0.SubImage(image.Rect(2, 3, 10, 11)).(*ebiten.Image)
|
||||||
|
|
||||||
src1 := NewImage(w, h)
|
src1 := ebiten.NewImage(w, h)
|
||||||
pix1 := make([]byte, 4*w*h)
|
pix1 := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -921,9 +921,9 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
src1.ReplacePixels(pix1)
|
src1.ReplacePixels(pix1)
|
||||||
src1 = src1.SubImage(image.Rect(6, 8, 14, 16)).(*Image)
|
src1 = src1.SubImage(image.Rect(6, 8, 14, 16)).(*ebiten.Image)
|
||||||
|
|
||||||
testPixels := func(testname string, dst *Image) {
|
testPixels := func(testname string, dst *ebiten.Image) {
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
got := dst.At(i, j).(color.RGBA)
|
got := dst.At(i, j).(color.RGBA)
|
||||||
@ -939,8 +939,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("DrawRectShader", func(t *testing.T) {
|
t.Run("DrawRectShader", func(t *testing.T) {
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
op := &DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Images[0] = src0
|
op.Images[0] = src0
|
||||||
op.Images[1] = src1
|
op.Images[1] = src1
|
||||||
dst.DrawRectShader(w/2, h/2, s, op)
|
dst.DrawRectShader(w/2, h/2, s, op)
|
||||||
@ -948,8 +948,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("DrawTrianglesShader", func(t *testing.T) {
|
t.Run("DrawTrianglesShader", func(t *testing.T) {
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
vs := []Vertex{
|
vs := []ebiten.Vertex{
|
||||||
{
|
{
|
||||||
DstX: 0,
|
DstX: 0,
|
||||||
DstY: 0,
|
DstY: 0,
|
||||||
@ -993,7 +993,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
is := []uint16{0, 1, 2, 1, 2, 3}
|
is := []uint16{0, 1, 2, 1, 2, 3}
|
||||||
|
|
||||||
op := &DrawTrianglesShaderOptions{}
|
op := &ebiten.DrawTrianglesShaderOptions{}
|
||||||
op.Images[0] = src0
|
op.Images[0] = src0
|
||||||
op.Images[1] = src1
|
op.Images[1] = src1
|
||||||
dst.DrawTrianglesShader(vs, is, s, op)
|
dst.DrawTrianglesShader(vs, is, s, op)
|
||||||
@ -1005,7 +1005,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderDerivatives(t *testing.T) {
|
func TestShaderDerivatives(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
p := imageSrc0At(texCoord)
|
p := imageSrc0At(texCoord)
|
||||||
@ -1016,8 +1016,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
src := NewImage(w, h)
|
src := ebiten.NewImage(w, h)
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -1032,7 +1032,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
src.ReplacePixels(pix)
|
src.ReplacePixels(pix)
|
||||||
|
|
||||||
op := &DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
dst.DrawRectShader(w, h, s, op)
|
dst.DrawRectShader(w, h, s, op)
|
||||||
|
|
||||||
@ -1058,7 +1058,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderDerivatives2(t *testing.T) {
|
func TestShaderDerivatives2(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := ebiten.NewShader([]byte(`package main
|
||||||
|
|
||||||
// This function uses dfdx and then should not be in GLSL's vertex shader (#1701).
|
// This function uses dfdx and then should not be in GLSL's vertex shader (#1701).
|
||||||
func Foo(p vec4) vec4 {
|
func Foo(p vec4) vec4 {
|
||||||
@ -1074,8 +1074,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
src := NewImage(w, h)
|
src := ebiten.NewImage(w, h)
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -1090,7 +1090,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
src.ReplacePixels(pix)
|
src.ReplacePixels(pix)
|
||||||
|
|
||||||
op := &DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
dst.DrawRectShader(w, h, s, op)
|
dst.DrawRectShader(w, h, s, op)
|
||||||
|
|
||||||
@ -1165,13 +1165,13 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Run(shader.Name, func(t *testing.T) {
|
t.Run(shader.Name, func(t *testing.T) {
|
||||||
const w, h = 1, 1
|
const w, h = 1, 1
|
||||||
|
|
||||||
dst := NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
s, err := NewShader([]byte(shader.Shader))
|
s, err := ebiten.NewShader([]byte(shader.Shader))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
op := &DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Uniforms = shader.Uniforms
|
op.Uniforms = shader.Uniforms
|
||||||
dst.DrawRectShader(w, h, s, op)
|
dst.DrawRectShader(w, h, s, op)
|
||||||
if got, want := dst.At(0, 0), (color.RGBA{0xff, 0xff, 0xff, 0xff}); got != want {
|
if got, want := dst.At(0, 0), (color.RGBA{0xff, 0xff, 0xff, 0xff}); got != want {
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||||
. "github.com/hajimehoshi/ebiten/v2/text"
|
"github.com/hajimehoshi/ebiten/v2/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
@ -35,7 +35,7 @@ func TestMain(m *testing.M) {
|
|||||||
func TestTextColor(t *testing.T) {
|
func TestTextColor(t *testing.T) {
|
||||||
clr := color.RGBA{0x80, 0x80, 0x80, 0x80}
|
clr := color.RGBA{0x80, 0x80, 0x80, 0x80}
|
||||||
img := ebiten.NewImage(30, 30)
|
img := ebiten.NewImage(30, 30)
|
||||||
Draw(img, "Hello", bitmapfont.Face, 12, 12, clr)
|
text.Draw(img, "Hello", bitmapfont.Face, 12, 12, clr)
|
||||||
|
|
||||||
w, h := img.Size()
|
w, h := img.Size()
|
||||||
allTransparent := true
|
allTransparent := true
|
||||||
@ -123,7 +123,7 @@ func TestTextOverlap(t *testing.T) {
|
|||||||
|
|
||||||
// With testFace, 'b' is rendered at the previous position as 0xff.
|
// With testFace, 'b' is rendered at the previous position as 0xff.
|
||||||
// 'a' is rendered at the current position as 0x80.
|
// 'a' is rendered at the current position as 0x80.
|
||||||
Draw(dst, "ab", f, 0, 0, color.White)
|
text.Draw(dst, "ab", f, 0, 0, color.White)
|
||||||
for j := 0; j < testFaceSize; j++ {
|
for j := 0; j < testFaceSize; j++ {
|
||||||
for i := 0; i < testFaceSize; i++ {
|
for i := 0; i < testFaceSize; i++ {
|
||||||
got := dst.At(i, j)
|
got := dst.At(i, j)
|
||||||
@ -135,7 +135,7 @@ func TestTextOverlap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The glyph 'a' should be treated correctly.
|
// The glyph 'a' should be treated correctly.
|
||||||
Draw(dst, "a", f, testFaceSize, 0, color.White)
|
text.Draw(dst, "a", f, testFaceSize, 0, color.White)
|
||||||
for j := 0; j < testFaceSize; j++ {
|
for j := 0; j < testFaceSize; j++ {
|
||||||
for i := testFaceSize; i < testFaceSize*2; i++ {
|
for i := testFaceSize; i < testFaceSize*2; i++ {
|
||||||
got := dst.At(i, j)
|
got := dst.At(i, j)
|
||||||
|
Loading…
Reference in New Issue
Block a user