mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +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)
|
newI := NewImage(i.width, i.height, ImageTypeRegular)
|
||||||
|
|
||||||
if restorable.NeedsRestoring() {
|
// If the underlying graphics driver doesn't require restoring from the context lost, just a regular
|
||||||
// If the underlying graphics driver requires restoring from the context lost, the pixel data is
|
// rendering works.
|
||||||
// needed. An image on an atlas must have its complete pixel data in this case.
|
w, h := float32(i.width), float32(i.height)
|
||||||
pixels := make([]byte, 4*i.width*i.height)
|
vs := graphics.QuadVertices(0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||||
for y := 0; y < i.height; y++ {
|
is := graphics.QuadIndices()
|
||||||
for x := 0; x < i.width; x++ {
|
dr := graphicsdriver.Region{
|
||||||
r, g, b, a, err := i.at(graphicsDriver, x+i.paddingSize(), y+i.paddingSize())
|
X: 0,
|
||||||
if err != nil {
|
Y: 0,
|
||||||
return err
|
Width: w,
|
||||||
}
|
Height: h,
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
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)
|
newI.moveTo(i)
|
||||||
i.usedAsSourceCount = 0
|
i.usedAsSourceCount = 0
|
||||||
|
@ -127,7 +127,7 @@ func ensureEmptyImage() *Image {
|
|||||||
return emptyImage
|
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.
|
// w and h are the empty image's size. They indicate the 1x1 image with 1px padding around.
|
||||||
const w, h = 3, 3
|
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)
|
i.image.ReplacePixels(make([]byte, 4*width*height), nil, x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !NeedsRestoring() || !i.needsRestoring() {
|
if !needsRestoring() || !i.needsRestoring() {
|
||||||
i.makeStale()
|
i.makeStale()
|
||||||
return
|
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()
|
i.makeStale()
|
||||||
} else {
|
} else {
|
||||||
i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, shader, uniforms, evenOdd)
|
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.
|
// resolveStale resolves the image's 'stale' state.
|
||||||
func (i *Image) resolveStale(graphicsDriver graphicsdriver.Graphics) error {
|
func (i *Image) resolveStale(graphicsDriver graphicsdriver.Graphics) error {
|
||||||
if !NeedsRestoring() {
|
if !needsRestoring() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !i.needsRestoring() {
|
if !i.needsRestoring() {
|
||||||
|
@ -29,8 +29,8 @@ var forceRestoring = false
|
|||||||
|
|
||||||
var needsRestoringByGraphicsDriver bool
|
var needsRestoringByGraphicsDriver bool
|
||||||
|
|
||||||
// NeedsRestoring reports whether restoring process works or not.
|
// needsRestoring reports whether restoring process works or not.
|
||||||
func NeedsRestoring() bool {
|
func needsRestoring() bool {
|
||||||
return forceRestoring || needsRestoringByGraphicsDriver
|
return forceRestoring || needsRestoringByGraphicsDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ func ResolveStaleImages(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
if err := graphicscommand.FlushCommands(graphicsDriver); err != nil {
|
if err := graphicscommand.FlushCommands(graphicsDriver); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !NeedsRestoring() {
|
if !needsRestoring() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return theImages.resolveStaleImages(graphicsDriver)
|
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.
|
// Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers.
|
||||||
func RestoreIfNeeded(graphicsDriver graphicsdriver.Graphics) error {
|
func RestoreIfNeeded(graphicsDriver graphicsdriver.Graphics) error {
|
||||||
if !NeedsRestoring() {
|
if !needsRestoring() {
|
||||||
return nil
|
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.
|
// Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers.
|
||||||
func (i *images) restore(graphicsDriver graphicsdriver.Graphics) error {
|
func (i *images) restore(graphicsDriver graphicsdriver.Graphics) error {
|
||||||
if !NeedsRestoring() {
|
if !needsRestoring() {
|
||||||
panic("restorable: restore cannot be called when restoring is disabled")
|
panic("restorable: restore cannot be called when restoring is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user