2021-08-14 13:05:26 +02:00
|
|
|
// Copyright 2021 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package atlas_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
2021-10-02 12:58:48 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
2021-08-14 13:05:26 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
2022-02-06 12:41:32 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
2021-08-14 13:05:26 +02:00
|
|
|
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
2022-03-19 15:55:14 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
2021-08-14 13:05:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestShaderFillTwice(t *testing.T) {
|
|
|
|
const w, h = 1, 1
|
|
|
|
|
2022-06-07 16:57:56 +02:00
|
|
|
dst := atlas.NewImage(w, h, atlas.ImageTypeRegular)
|
2021-08-14 13:05:26 +02:00
|
|
|
|
|
|
|
vs := quadVertices(w, h, 0, 0, 1)
|
|
|
|
is := graphics.QuadIndices()
|
2022-02-06 12:41:32 +01:00
|
|
|
dr := graphicsdriver.Region{
|
2021-08-14 13:05:26 +02:00
|
|
|
X: 0,
|
|
|
|
Y: 0,
|
|
|
|
Width: w,
|
|
|
|
Height: h,
|
|
|
|
}
|
2022-03-19 15:55:14 +01:00
|
|
|
g := ui.GraphicsDriverForTesting()
|
2022-03-21 09:48:47 +01:00
|
|
|
s0 := atlas.NewShader(etesting.ShaderProgramFill(0xff, 0xff, 0xff, 0xff))
|
2022-02-06 12:41:32 +01:00
|
|
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s0, nil, false)
|
2021-08-14 13:05:26 +02:00
|
|
|
|
|
|
|
// Vertices must be recreated (#1755)
|
|
|
|
vs = quadVertices(w, h, 0, 0, 1)
|
2022-03-21 09:48:47 +01:00
|
|
|
s1 := atlas.NewShader(etesting.ShaderProgramFill(0x80, 0x80, 0x80, 0xff))
|
2022-02-06 12:41:32 +01:00
|
|
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s1, nil, false)
|
2021-08-14 13:05:26 +02:00
|
|
|
|
2022-03-20 10:16:57 +01:00
|
|
|
pix, err := dst.Pixels(g)
|
2021-08-14 13:05:26 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if got, want := (color.RGBA{pix[0], pix[1], pix[2], pix[3]}), (color.RGBA{0x80, 0x80, 0x80, 0xff}); got != want {
|
|
|
|
t.Errorf("got: %v, want: %v", got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImageDrawTwice(t *testing.T) {
|
|
|
|
const w, h = 1, 1
|
|
|
|
|
2022-06-07 16:57:56 +02:00
|
|
|
dst := atlas.NewImage(w, h, atlas.ImageTypeRegular)
|
|
|
|
src0 := atlas.NewImage(w, h, atlas.ImageTypeRegular)
|
2022-07-05 06:26:45 +02:00
|
|
|
src0.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff}, 0, 0, w, h)
|
2022-06-07 16:57:56 +02:00
|
|
|
src1 := atlas.NewImage(w, h, atlas.ImageTypeRegular)
|
2022-07-05 06:26:45 +02:00
|
|
|
src1.ReplacePixels([]byte{0x80, 0x80, 0x80, 0xff}, 0, 0, w, h)
|
2021-08-14 13:05:26 +02:00
|
|
|
|
|
|
|
vs := quadVertices(w, h, 0, 0, 1)
|
|
|
|
is := graphics.QuadIndices()
|
2022-02-06 12:41:32 +01:00
|
|
|
dr := graphicsdriver.Region{
|
2021-08-14 13:05:26 +02:00
|
|
|
X: 0,
|
|
|
|
Y: 0,
|
|
|
|
Width: w,
|
|
|
|
Height: h,
|
|
|
|
}
|
2022-02-06 12:41:32 +01:00
|
|
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src0}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
2021-08-14 13:05:26 +02:00
|
|
|
|
|
|
|
// Vertices must be recreated (#1755)
|
|
|
|
vs = quadVertices(w, h, 0, 0, 1)
|
2022-02-06 12:41:32 +01:00
|
|
|
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
2021-08-14 13:05:26 +02:00
|
|
|
|
2022-03-20 10:16:57 +01:00
|
|
|
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
2021-08-14 13:05:26 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if got, want := (color.RGBA{pix[0], pix[1], pix[2], pix[3]}), (color.RGBA{0x80, 0x80, 0x80, 0xff}); got != want {
|
|
|
|
t.Errorf("got: %v, want: %v", got, want)
|
|
|
|
}
|
|
|
|
}
|