mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/atlas: always use DrawTriangles at putOnAtlas
DrawTriangles was introduced at #1508, and apparently there is no reason we should use ReplacePixels here. So, simplify the logic by using only DrawTriangles.
This commit is contained in:
parent
bdae45be8f
commit
6b814888b5
@ -341,37 +341,18 @@ func (i *Image) putOnAtlas(graphicsDriver graphicsdriver.Graphics) error {
|
||||
|
||||
newI := NewImage(i.width, i.height, ImageTypeRegular)
|
||||
|
||||
if restorable.NeedsRestoring() {
|
||||
// If the underlying graphics driver requires restoring from the context lost, the pixel data is
|
||||
// needed. An image on an atlas must have its complete pixel data in this case.
|
||||
pixels := make([]byte, 4*i.width*i.height)
|
||||
for y := 0; y < i.height; y++ {
|
||||
for x := 0; x < i.width; x++ {
|
||||
r, g, b, a, err := i.at(graphicsDriver, x+i.paddingSize(), y+i.paddingSize())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pixels[4*(i.width*y+x)] = r
|
||||
pixels[4*(i.width*y+x)+1] = g
|
||||
pixels[4*(i.width*y+x)+2] = b
|
||||
pixels[4*(i.width*y+x)+3] = a
|
||||
}
|
||||
}
|
||||
newI.replacePixels(pixels, nil)
|
||||
} else {
|
||||
// If the underlying graphics driver doesn't require restoring from the context lost, just a regular
|
||||
// rendering works.
|
||||
w, h := float32(i.width), float32(i.height)
|
||||
vs := graphics.QuadVertices(0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
newI.drawTriangles([graphics.ShaderImageNum]*Image{i}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
||||
// If the underlying graphics driver doesn't require restoring from the context lost, just a regular
|
||||
// rendering works.
|
||||
w, h := float32(i.width), float32(i.height)
|
||||
vs := graphics.QuadVertices(0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
newI.drawTriangles([graphics.ShaderImageNum]*Image{i}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
||||
|
||||
newI.moveTo(i)
|
||||
i.usedAsSourceCount = 0
|
||||
|
@ -127,7 +127,7 @@ func ensureEmptyImage() *Image {
|
||||
return emptyImage
|
||||
}
|
||||
|
||||
// Initialize the empty image lazily. Some functions like NeedsRestoring might not work at the initial phase.
|
||||
// Initialize the empty 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.
|
||||
const w, h = 3, 3
|
||||
@ -299,7 +299,7 @@ func (i *Image) ReplacePixels(pixels []byte, mask []byte, x, y, width, height in
|
||||
i.image.ReplacePixels(make([]byte, 4*width*height), nil, x, y, width, height)
|
||||
}
|
||||
|
||||
if !NeedsRestoring() || !i.needsRestoring() {
|
||||
if !needsRestoring() || !i.needsRestoring() {
|
||||
i.makeStale()
|
||||
return
|
||||
}
|
||||
@ -373,7 +373,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
|
||||
}
|
||||
}
|
||||
|
||||
if srcstale || !NeedsRestoring() || !i.needsRestoring() {
|
||||
if srcstale || !needsRestoring() || !i.needsRestoring() {
|
||||
i.makeStale()
|
||||
} else {
|
||||
i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, shader, uniforms, evenOdd)
|
||||
@ -498,7 +498,7 @@ func (i *Image) readPixelsFromGPU(graphicsDriver graphicsdriver.Graphics) error
|
||||
|
||||
// resolveStale resolves the image's 'stale' state.
|
||||
func (i *Image) resolveStale(graphicsDriver graphicsdriver.Graphics) error {
|
||||
if !NeedsRestoring() {
|
||||
if !needsRestoring() {
|
||||
return nil
|
||||
}
|
||||
if !i.needsRestoring() {
|
||||
|
@ -29,8 +29,8 @@ var forceRestoring = false
|
||||
|
||||
var needsRestoringByGraphicsDriver bool
|
||||
|
||||
// NeedsRestoring reports whether restoring process works or not.
|
||||
func NeedsRestoring() bool {
|
||||
// needsRestoring reports whether restoring process works or not.
|
||||
func needsRestoring() bool {
|
||||
return forceRestoring || needsRestoringByGraphicsDriver
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func ResolveStaleImages(graphicsDriver graphicsdriver.Graphics) error {
|
||||
if err := graphicscommand.FlushCommands(graphicsDriver); err != nil {
|
||||
return err
|
||||
}
|
||||
if !NeedsRestoring() {
|
||||
if !needsRestoring() {
|
||||
return nil
|
||||
}
|
||||
return theImages.resolveStaleImages(graphicsDriver)
|
||||
@ -80,7 +80,7 @@ func ResolveStaleImages(graphicsDriver graphicsdriver.Graphics) error {
|
||||
//
|
||||
// Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers.
|
||||
func RestoreIfNeeded(graphicsDriver graphicsdriver.Graphics) error {
|
||||
if !NeedsRestoring() {
|
||||
if !needsRestoring() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ func (i *images) makeStaleIfDependingOnShader(shader *Shader) {
|
||||
//
|
||||
// Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers.
|
||||
func (i *images) restore(graphicsDriver graphicsdriver.Graphics) error {
|
||||
if !NeedsRestoring() {
|
||||
if !needsRestoring() {
|
||||
panic("restorable: restore cannot be called when restoring is disabled")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user