mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
all: rename emptyImage -> whiteImage
This commit is contained in:
parent
418485801f
commit
f04e391cb4
@ -24,12 +24,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
emptyImage = ebiten.NewImage(3, 3)
|
||||
emptySubImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
whiteImage = ebiten.NewImage(3, 3)
|
||||
whiteSubImage = whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
)
|
||||
|
||||
func init() {
|
||||
emptyImage.Fill(color.White)
|
||||
whiteImage.Fill(color.White)
|
||||
}
|
||||
|
||||
// DrawLine draws a line segment on the given destination dst.
|
||||
@ -45,7 +45,7 @@ func DrawLine(dst *ebiten.Image, x1, y1, x2, y2 float64, clr color.Color) {
|
||||
op.ColorM.ScaleWithColor(clr)
|
||||
// Filter must be 'nearest' filter (default).
|
||||
// Linear filtering would make edges blurred.
|
||||
dst.DrawImage(emptySubImage, op)
|
||||
dst.DrawImage(whiteSubImage, op)
|
||||
}
|
||||
|
||||
// DrawRect draws a rectangle on the given destination dst.
|
||||
@ -58,7 +58,7 @@ func DrawRect(dst *ebiten.Image, x, y, width, height float64, clr color.Color) {
|
||||
op.ColorM.ScaleWithColor(clr)
|
||||
// Filter must be 'nearest' filter (default).
|
||||
// Linear filtering would make edges blurred.
|
||||
dst.DrawImage(emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image), op)
|
||||
dst.DrawImage(whiteSubImage, op)
|
||||
}
|
||||
|
||||
// DrawCircle draws a circle on given destination dst.
|
||||
@ -79,5 +79,5 @@ func DrawCircle(dst *ebiten.Image, cx, cy, r float64, clr color.Color) {
|
||||
vertices[i].ColorB = float32(b) / 0xffff
|
||||
vertices[i].ColorA = float32(a) / 0xffff
|
||||
}
|
||||
dst.DrawTriangles(vertices, indices, emptySubImage, nil)
|
||||
dst.DrawTriangles(vertices, indices, whiteSubImage, nil)
|
||||
}
|
||||
|
@ -35,15 +35,15 @@ func min(x, y int) int {
|
||||
}
|
||||
|
||||
var (
|
||||
emptyImage = ebiten.NewImage(3, 3)
|
||||
whiteImage = ebiten.NewImage(3, 3)
|
||||
|
||||
// emptySubImage is an internal sub image of emptyImage.
|
||||
// Use emptySubImage at DrawTriangles instead of emptyImage in order to avoid bleeding edges.
|
||||
emptySubImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
// whiteSubImage is an internal sub image of whiteImage.
|
||||
// Use whiteSubImage at DrawTriangles instead of whiteImage in order to avoid bleeding edges.
|
||||
whiteSubImage = whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
)
|
||||
|
||||
func init() {
|
||||
emptyImage.Fill(color.White)
|
||||
whiteImage.Fill(color.White)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -137,7 +137,7 @@ func (g *Game) drawLine(screen *ebiten.Image, region image.Rectangle, cap vector
|
||||
vs[i].SrcX = 1
|
||||
vs[i].SrcY = 1
|
||||
}
|
||||
screen.DrawTriangles(vs, is, emptySubImage, &ebiten.DrawTrianglesOptions{
|
||||
screen.DrawTriangles(vs, is, whiteSubImage, &ebiten.DrawTrianglesOptions{
|
||||
AntiAlias: g.aa,
|
||||
})
|
||||
|
||||
@ -154,7 +154,7 @@ func (g *Game) drawLine(screen *ebiten.Image, region image.Rectangle, cap vector
|
||||
vs[i].ColorG = 0
|
||||
vs[i].ColorB = 0
|
||||
}
|
||||
screen.DrawTriangles(vs, is, emptySubImage, &ebiten.DrawTrianglesOptions{
|
||||
screen.DrawTriangles(vs, is, whiteSubImage, &ebiten.DrawTrianglesOptions{
|
||||
AntiAlias: g.aa,
|
||||
})
|
||||
}
|
||||
|
@ -35,11 +35,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
emptyImage = ebiten.NewImage(3, 3)
|
||||
whiteImage = ebiten.NewImage(3, 3)
|
||||
)
|
||||
|
||||
func init() {
|
||||
emptyImage.Fill(color.White)
|
||||
whiteImage.Fill(color.White)
|
||||
}
|
||||
|
||||
func genVertices(num int) []ebiten.Vertex {
|
||||
@ -128,7 +128,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
for i := 0; i < g.ngon; i++ {
|
||||
indices = append(indices, uint16(i), uint16(i+1)%uint16(g.ngon), uint16(g.ngon))
|
||||
}
|
||||
screen.DrawTriangles(g.vertices, indices, emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image), op)
|
||||
screen.DrawTriangles(g.vertices, indices, whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image), op)
|
||||
|
||||
msg := fmt.Sprintf("TPS: %0.2f\n%d-gon\nPress <- or -> to change the number of the vertices", ebiten.ActualTPS(), g.ngon)
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
|
@ -34,11 +34,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
emptyImage = ebiten.NewImage(3, 3)
|
||||
whiteImage = ebiten.NewImage(3, 3)
|
||||
)
|
||||
|
||||
func init() {
|
||||
emptyImage.Fill(color.White)
|
||||
whiteImage.Fill(color.White)
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
@ -163,7 +163,7 @@ func (g *Game) Update() error {
|
||||
}
|
||||
|
||||
func (g *Game) Draw(screen *ebiten.Image) {
|
||||
src := emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
src := whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
|
||||
cf := float64(g.count)
|
||||
v, i := line(100, 100, 300, 100, color.RGBA{0xff, 0xff, 0xff, 0xff})
|
||||
|
@ -31,15 +31,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
emptyImage = ebiten.NewImage(3, 3)
|
||||
whiteImage = ebiten.NewImage(3, 3)
|
||||
|
||||
// emptySubImage is an internal sub image of emptyImage.
|
||||
// Use emptySubImage at DrawTriangles instead of emptyImage in order to avoid bleeding edges.
|
||||
emptySubImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
// whiteSubImage is an internal sub image of whiteImage.
|
||||
// Use whiteSubImage at DrawTriangles instead of whiteImage in order to avoid bleeding edges.
|
||||
whiteSubImage = whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
)
|
||||
|
||||
func init() {
|
||||
emptyImage.Fill(color.White)
|
||||
whiteImage.Fill(color.White)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -139,7 +139,7 @@ func drawEbitenText(screen *ebiten.Image, x, y int, aa bool, line bool) {
|
||||
if !line {
|
||||
op.FillRule = ebiten.EvenOdd
|
||||
}
|
||||
screen.DrawTriangles(vs, is, emptySubImage, op)
|
||||
screen.DrawTriangles(vs, is, whiteSubImage, op)
|
||||
}
|
||||
|
||||
func drawEbitenLogo(screen *ebiten.Image, x, y int, aa bool, line bool) {
|
||||
@ -193,7 +193,7 @@ func drawEbitenLogo(screen *ebiten.Image, x, y int, aa bool, line bool) {
|
||||
if !line {
|
||||
op.FillRule = ebiten.EvenOdd
|
||||
}
|
||||
screen.DrawTriangles(vs, is, emptySubImage, op)
|
||||
screen.DrawTriangles(vs, is, whiteSubImage, op)
|
||||
}
|
||||
|
||||
func drawArc(screen *ebiten.Image, count int, aa bool, line bool) {
|
||||
@ -234,7 +234,7 @@ func drawArc(screen *ebiten.Image, count int, aa bool, line bool) {
|
||||
if !line {
|
||||
op.FillRule = ebiten.EvenOdd
|
||||
}
|
||||
screen.DrawTriangles(vs, is, emptySubImage, op)
|
||||
screen.DrawTriangles(vs, is, whiteSubImage, op)
|
||||
}
|
||||
|
||||
func maxCounter(index int) int {
|
||||
@ -290,7 +290,7 @@ func drawWave(screen *ebiten.Image, counter int, aa bool, line bool) {
|
||||
if !line {
|
||||
op.FillRule = ebiten.EvenOdd
|
||||
}
|
||||
screen.DrawTriangles(vs, is, emptySubImage, op)
|
||||
screen.DrawTriangles(vs, is, whiteSubImage, op)
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
|
8
image.go
8
image.go
@ -42,14 +42,6 @@ type Image struct {
|
||||
// This tends to forget resolving the buffer easily (#2362).
|
||||
}
|
||||
|
||||
var emptyImage *Image
|
||||
|
||||
func init() {
|
||||
img := NewImage(3, 3)
|
||||
img.Fill(color.White)
|
||||
emptyImage = img.SubImage(image.Rect(1, 1, 2, 2)).(*Image)
|
||||
}
|
||||
|
||||
func (i *Image) copyCheck() {
|
||||
if i.addr != i {
|
||||
panic("ebiten: illegal use of non-zero Image copied by value")
|
||||
|
@ -2559,9 +2559,9 @@ func TestImageSubImageFill(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImageEvenOdd(t *testing.T) {
|
||||
emptyImage := ebiten.NewImage(3, 3)
|
||||
emptyImage.Fill(color.White)
|
||||
emptySubImage := emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
whiteImage := ebiten.NewImage(3, 3)
|
||||
whiteImage.Fill(color.White)
|
||||
emptySubImage := whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
|
||||
vs0 := []ebiten.Vertex{
|
||||
{
|
||||
|
10
internal/processtest/testdata/issue2138.go
vendored
10
internal/processtest/testdata/issue2138.go
vendored
@ -31,19 +31,19 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
emptyImage = ebiten.NewImage(3, 3)
|
||||
whiteImage = ebiten.NewImage(3, 3)
|
||||
debugCircleImage *ebiten.Image
|
||||
emptyTextureImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
whiteTextureImage = whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||
face font.Face
|
||||
)
|
||||
|
||||
func init() {
|
||||
emptyImage.Fill(color.White)
|
||||
whiteImage.Fill(color.White)
|
||||
|
||||
img := image.NewRGBA(image.Rect(0, 0, 20, 20))
|
||||
debugCircleImage = ebiten.NewImageFromImage(img)
|
||||
|
||||
emptyImage.Fill(color.Black)
|
||||
whiteImage.Fill(color.Black)
|
||||
|
||||
f, _ := opentype.Parse(goregular.TTF)
|
||||
face, _ = opentype.NewFace(f, &opentype.FaceOptions{
|
||||
@ -74,7 +74,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
p := vector.Path{}
|
||||
p.Arc(100, 100, 6, 0, 2*math.Pi, vector.Clockwise)
|
||||
filling, indicies := p.AppendVerticesAndIndicesForFilling(nil, nil)
|
||||
screen.DrawTriangles(filling, indicies, emptyTextureImage, &ebiten.DrawTrianglesOptions{
|
||||
screen.DrawTriangles(filling, indicies, whiteTextureImage, &ebiten.DrawTrianglesOptions{
|
||||
FillRule: ebiten.EvenOdd,
|
||||
})
|
||||
}
|
||||
|
@ -139,18 +139,18 @@ type Image struct {
|
||||
priority bool
|
||||
}
|
||||
|
||||
var emptyImage *Image
|
||||
var whiteImage *Image
|
||||
|
||||
func ensureEmptyImage() *Image {
|
||||
if emptyImage != nil {
|
||||
return emptyImage
|
||||
func ensureWhiteImage() *Image {
|
||||
if whiteImage != nil {
|
||||
return whiteImage
|
||||
}
|
||||
|
||||
// Initialize the empty image lazily. Some functions like needsRestoring might not work at the initial phase.
|
||||
// Initialize the white image lazily. Some functions like needsRestoring might not work at the initial phase.
|
||||
|
||||
// w and h are the empty image's size. They indicate the 1x1 image with 1px padding around.
|
||||
// w and h are the white image's size. They indicate the 1x1 image with 1px padding around.
|
||||
const w, h = 3, 3
|
||||
emptyImage = &Image{
|
||||
whiteImage = &Image{
|
||||
image: graphicscommand.NewImage(w, h, false),
|
||||
width: w,
|
||||
height: h,
|
||||
@ -161,14 +161,14 @@ func ensureEmptyImage() *Image {
|
||||
pix[i] = 0xff
|
||||
}
|
||||
|
||||
// As emptyImage is the source at clearImage, initialize this with WritePixels, not clearImage.
|
||||
// This operation is also important when restoring emptyImage.
|
||||
emptyImage.WritePixels(pix, 0, 0, w, h)
|
||||
theImages.add(emptyImage)
|
||||
return emptyImage
|
||||
// As whiteImage is the source at clearImage, initialize this with WritePixels, not clearImage.
|
||||
// This operation is also important when restoring whiteImage.
|
||||
whiteImage.WritePixels(pix, 0, 0, w, h)
|
||||
theImages.add(whiteImage)
|
||||
return whiteImage
|
||||
}
|
||||
|
||||
// NewImage creates an empty image with the given size.
|
||||
// NewImage creates an white image with the given size.
|
||||
//
|
||||
// The returned image is cleared.
|
||||
//
|
||||
@ -244,19 +244,19 @@ func quadVertices(src *Image, dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, cr, cg, cb
|
||||
}
|
||||
|
||||
func clearImage(i *graphicscommand.Image) {
|
||||
emptyImage := ensureEmptyImage()
|
||||
whiteImage := ensureWhiteImage()
|
||||
|
||||
if i == emptyImage.image {
|
||||
panic("restorable: fillImage cannot be called on emptyImage")
|
||||
if i == whiteImage.image {
|
||||
panic("restorable: fillImage cannot be called on whiteImage")
|
||||
}
|
||||
|
||||
// This needs to use 'InternalSize' to render the whole region, or edges are unexpectedly cleared on some
|
||||
// devices.
|
||||
dw, dh := i.InternalSize()
|
||||
sw, sh := emptyImage.width, emptyImage.height
|
||||
vs := quadVertices(emptyImage, 0, 0, float32(dw), float32(dh), 1, 1, float32(sw-1), float32(sh-1), 0, 0, 0, 0)
|
||||
sw, sh := whiteImage.width, whiteImage.height
|
||||
vs := quadVertices(whiteImage, 0, 0, float32(dw), float32(dh), 1, 1, float32(sw-1), float32(sh-1), 0, 0, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
srcs := [graphics.ShaderImageCount]*graphicscommand.Image{emptyImage.image}
|
||||
srcs := [graphics.ShaderImageCount]*graphicscommand.Image{whiteImage.image}
|
||||
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: 0,
|
||||
@ -602,9 +602,9 @@ func (i *Image) restore(graphicsDriver graphicsdriver.Graphics) error {
|
||||
|
||||
gimg := graphicscommand.NewImage(w, h, false)
|
||||
// Clear the image explicitly.
|
||||
if i != ensureEmptyImage() {
|
||||
// As clearImage uses emptyImage, clearImage cannot be called on emptyImage.
|
||||
// It is OK to skip this since emptyImage has its entire pixel information.
|
||||
if i != ensureWhiteImage() {
|
||||
// As clearImage uses whiteImage, clearImage cannot be called on whiteImage.
|
||||
// It is OK to skip this since whiteImage has its entire pixel information.
|
||||
clearImage(gimg)
|
||||
}
|
||||
i.basePixels.Apply(gimg)
|
||||
|
@ -263,7 +263,7 @@ func (i *Image) flushDotsBufferIfNeeded() {
|
||||
}
|
||||
i.dotsBuffer = nil
|
||||
|
||||
srcs := [graphics.ShaderImageCount]*mipmap.Mipmap{emptyImage.mipmap}
|
||||
srcs := [graphics.ShaderImageCount]*mipmap.Mipmap{whiteImage.mipmap}
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
@ -308,16 +308,16 @@ func DumpImages(dir string) (string, error) {
|
||||
}
|
||||
|
||||
var (
|
||||
emptyImage = NewImage(3, 3, atlas.ImageTypeRegular)
|
||||
whiteImage = NewImage(3, 3, atlas.ImageTypeRegular)
|
||||
)
|
||||
|
||||
func init() {
|
||||
pix := make([]byte, 4*emptyImage.width*emptyImage.height)
|
||||
pix := make([]byte, 4*whiteImage.width*whiteImage.height)
|
||||
for i := range pix {
|
||||
pix[i] = 0xff
|
||||
}
|
||||
// As emptyImage is used at Fill, use WritePixels instead.
|
||||
emptyImage.WritePixels(pix, 0, 0, emptyImage.width, emptyImage.height)
|
||||
// As whiteImage is used at Fill, use WritePixels instead.
|
||||
whiteImage.WritePixels(pix, 0, 0, whiteImage.width, whiteImage.height)
|
||||
}
|
||||
|
||||
func (i *Image) clear() {
|
||||
@ -333,12 +333,12 @@ func (i *Image) Fill(r, g, b, a float32, x, y, width, height int) {
|
||||
}
|
||||
|
||||
vs := graphics.QuadVertices(
|
||||
1, 1, float32(emptyImage.width-1), float32(emptyImage.height-1),
|
||||
1, 1, float32(whiteImage.width-1), float32(whiteImage.height-1),
|
||||
float32(i.width), 0, 0, float32(i.height), 0, 0,
|
||||
r, g, b, a)
|
||||
is := graphics.QuadIndices()
|
||||
|
||||
srcs := [graphics.ShaderImageCount]*Image{emptyImage}
|
||||
srcs := [graphics.ShaderImageCount]*Image{whiteImage}
|
||||
|
||||
i.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, NearestFilterShader, nil, false, true, false)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user