updated ebiten version from 2.7.9 to 2.9.9
This commit is contained in:
+67
-50
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
)
|
||||
|
||||
var whiteImage *Image
|
||||
@@ -46,6 +47,8 @@ type Image struct {
|
||||
// pixels is cached pixels for ReadPixels.
|
||||
// pixels might be out of sync with GPU.
|
||||
// The data of pixels is the secondary data of pixels for ReadPixels.
|
||||
//
|
||||
// pixels is always nil when restorable.AlwaysReadPixelsFromGPU() returns false.
|
||||
pixels []byte
|
||||
|
||||
// pixelsUnsynced represents whether the pixels in CPU and GPU are not synced.
|
||||
@@ -68,9 +71,6 @@ func (i *Image) Deallocate() {
|
||||
}
|
||||
|
||||
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte, region image.Rectangle) (bool, error) {
|
||||
// Do not call flushDotsBufferIfNeeded here. This would slow (image/draw).Draw.
|
||||
// See ebiten.TestImageDrawOver.
|
||||
|
||||
if region.Dx() == 1 && region.Dy() == 1 {
|
||||
if c, ok := i.dotsBuffer[region.Min]; ok {
|
||||
copy(pixels, c[:])
|
||||
@@ -78,6 +78,19 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte
|
||||
}
|
||||
}
|
||||
|
||||
// If restorable.AlwaysReadPixelsFromGPU() returns false, the pixel data is cached in the restorable package.
|
||||
if !restorable.AlwaysReadPixelsFromGPU() {
|
||||
i.syncPixelsIfNeeded()
|
||||
ok, err := i.img.ReadPixels(graphicsDriver, pixels, region)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// Do not call syncPixelsIfNeeded here. This would slow (image/draw).Draw.
|
||||
// See ebiten.TestImageDrawOver.
|
||||
|
||||
if i.pixels == nil {
|
||||
pix := make([]byte, 4*i.width*i.height)
|
||||
ok, err := i.img.ReadPixels(graphicsDriver, pix, image.Rect(0, 0, i.width, i.height))
|
||||
@@ -183,7 +196,7 @@ func (i *Image) WritePixels(pix []byte, region image.Rectangle) {
|
||||
// DrawTriangles draws the src image with the given vertices.
|
||||
//
|
||||
// Copying vertices and indices is the caller's responsibility.
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *atlas.Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) {
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderSrcImageCount]image.Rectangle, shader *atlas.Shader, uniforms []uint32, fillRule graphicsdriver.FillRule, hint restorable.Hint) {
|
||||
for _, src := range srcs {
|
||||
if i == src {
|
||||
panic("buffered: Image.DrawTriangles: source images must be different from the receiver")
|
||||
@@ -197,7 +210,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
|
||||
|
||||
i.syncPixelsIfNeeded()
|
||||
|
||||
var imgs [graphics.ShaderImageCount]*atlas.Image
|
||||
var imgs [graphics.ShaderSrcImageCount]*atlas.Image
|
||||
for i, img := range srcs {
|
||||
if img == nil {
|
||||
continue
|
||||
@@ -205,7 +218,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
|
||||
imgs[i] = img.img
|
||||
}
|
||||
|
||||
i.img.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, fillRule)
|
||||
i.img.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, fillRule, hint)
|
||||
|
||||
// After rendering, the pixel cache is no longer valid.
|
||||
i.pixels = nil
|
||||
@@ -246,56 +259,60 @@ func (i *Image) syncPixelsIfNeeded() {
|
||||
cbf := float32(c[2]) / 0xff
|
||||
caf := float32(c[3]) / 0xff
|
||||
|
||||
vs[graphics.VertexFloatCount*4*idx] = dx
|
||||
vs[graphics.VertexFloatCount*4*idx+1] = dy
|
||||
vs[graphics.VertexFloatCount*4*idx+2] = sx
|
||||
vs[graphics.VertexFloatCount*4*idx+3] = sy
|
||||
vs[graphics.VertexFloatCount*4*idx+4] = crf
|
||||
vs[graphics.VertexFloatCount*4*idx+5] = cgf
|
||||
vs[graphics.VertexFloatCount*4*idx+6] = cbf
|
||||
vs[graphics.VertexFloatCount*4*idx+7] = caf
|
||||
vs[graphics.VertexFloatCount*4*idx+8] = dx + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+9] = dy
|
||||
vs[graphics.VertexFloatCount*4*idx+10] = sx + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+11] = sy
|
||||
vs[graphics.VertexFloatCount*4*idx+12] = crf
|
||||
vs[graphics.VertexFloatCount*4*idx+13] = cgf
|
||||
vs[graphics.VertexFloatCount*4*idx+14] = cbf
|
||||
vs[graphics.VertexFloatCount*4*idx+15] = caf
|
||||
vs[graphics.VertexFloatCount*4*idx+16] = dx
|
||||
vs[graphics.VertexFloatCount*4*idx+17] = dy + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+18] = sx
|
||||
vs[graphics.VertexFloatCount*4*idx+19] = sy + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+20] = crf
|
||||
vs[graphics.VertexFloatCount*4*idx+21] = cgf
|
||||
vs[graphics.VertexFloatCount*4*idx+22] = cbf
|
||||
vs[graphics.VertexFloatCount*4*idx+23] = caf
|
||||
vs[graphics.VertexFloatCount*4*idx+24] = dx + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+25] = dy + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+26] = sx + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+27] = sy + 1
|
||||
vs[graphics.VertexFloatCount*4*idx+28] = crf
|
||||
vs[graphics.VertexFloatCount*4*idx+29] = cgf
|
||||
vs[graphics.VertexFloatCount*4*idx+30] = cbf
|
||||
vs[graphics.VertexFloatCount*4*idx+31] = caf
|
||||
vidx := 4 * idx
|
||||
iidx := 6 * idx
|
||||
|
||||
is[6*idx] = uint32(4 * idx)
|
||||
is[6*idx+1] = uint32(4*idx + 1)
|
||||
is[6*idx+2] = uint32(4*idx + 2)
|
||||
is[6*idx+3] = uint32(4*idx + 1)
|
||||
is[6*idx+4] = uint32(4*idx + 2)
|
||||
is[6*idx+5] = uint32(4*idx + 3)
|
||||
vs[graphics.VertexFloatCount*vidx] = dx
|
||||
vs[graphics.VertexFloatCount*vidx+1] = dy
|
||||
vs[graphics.VertexFloatCount*vidx+2] = sx
|
||||
vs[graphics.VertexFloatCount*vidx+3] = sy
|
||||
vs[graphics.VertexFloatCount*vidx+4] = crf
|
||||
vs[graphics.VertexFloatCount*vidx+5] = cgf
|
||||
vs[graphics.VertexFloatCount*vidx+6] = cbf
|
||||
vs[graphics.VertexFloatCount*vidx+7] = caf
|
||||
|
||||
vs[graphics.VertexFloatCount*(vidx+1)] = dx + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+1)+1] = dy
|
||||
vs[graphics.VertexFloatCount*(vidx+1)+2] = sx + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+1)+3] = sy
|
||||
vs[graphics.VertexFloatCount*(vidx+1)+4] = crf
|
||||
vs[graphics.VertexFloatCount*(vidx+1)+5] = cgf
|
||||
vs[graphics.VertexFloatCount*(vidx+1)+6] = cbf
|
||||
vs[graphics.VertexFloatCount*(vidx+1)+7] = caf
|
||||
|
||||
vs[graphics.VertexFloatCount*(vidx+2)] = dx
|
||||
vs[graphics.VertexFloatCount*(vidx+2)+1] = dy + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+2)+2] = sx
|
||||
vs[graphics.VertexFloatCount*(vidx+2)+3] = sy + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+2)+4] = crf
|
||||
vs[graphics.VertexFloatCount*(vidx+2)+5] = cgf
|
||||
vs[graphics.VertexFloatCount*(vidx+2)+6] = cbf
|
||||
vs[graphics.VertexFloatCount*(vidx+2)+7] = caf
|
||||
|
||||
vs[graphics.VertexFloatCount*(vidx+3)] = dx + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+3)+1] = dy + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+3)+2] = sx + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+3)+3] = sy + 1
|
||||
vs[graphics.VertexFloatCount*(vidx+3)+4] = crf
|
||||
vs[graphics.VertexFloatCount*(vidx+3)+5] = cgf
|
||||
vs[graphics.VertexFloatCount*(vidx+3)+6] = cbf
|
||||
vs[graphics.VertexFloatCount*(vidx+3)+7] = caf
|
||||
|
||||
is[iidx] = uint32(vidx)
|
||||
is[iidx+1] = uint32(vidx + 1)
|
||||
is[iidx+2] = uint32(vidx + 2)
|
||||
is[iidx+3] = uint32(vidx + 1)
|
||||
is[iidx+4] = uint32(vidx + 2)
|
||||
is[iidx+5] = uint32(vidx + 3)
|
||||
|
||||
idx++
|
||||
}
|
||||
|
||||
srcs := [graphics.ShaderImageCount]*atlas.Image{whiteImage.img}
|
||||
srcs := [graphics.ShaderSrcImageCount]*atlas.Image{whiteImage.img}
|
||||
dr := image.Rect(0, 0, i.width, i.height)
|
||||
sr := image.Rect(0, 0, whiteImage.width, whiteImage.height)
|
||||
blend := graphicsdriver.BlendCopy
|
||||
i.img.DrawTriangles(srcs, vs, is, blend, dr, [graphics.ShaderImageCount]image.Rectangle{}, atlas.NearestFilterShader, nil, graphicsdriver.FillAll)
|
||||
i.img.DrawTriangles(srcs, vs, is, blend, dr, [graphics.ShaderSrcImageCount]image.Rectangle{sr}, atlas.NearestFilterShader, nil, graphicsdriver.FillRuleFillAll, restorable.HintNone)
|
||||
|
||||
// TODO: Use clear if Go 1.21 is available.
|
||||
for pos := range i.dotsBuffer {
|
||||
delete(i.dotsBuffer, pos)
|
||||
}
|
||||
clear(i.dotsBuffer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user