mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
internal/graphicscommand: use a slice to values instead of pointers
This should reduce heap allocations.
This commit is contained in:
parent
377b0b8502
commit
842c3cbfcd
@ -466,7 +466,7 @@ func mightOverlapDstRegions(vertices1, vertices2 []float32) bool {
|
|||||||
// writePixelsCommand represents a command to replace pixels of an image.
|
// writePixelsCommand represents a command to replace pixels of an image.
|
||||||
type writePixelsCommand struct {
|
type writePixelsCommand struct {
|
||||||
dst *Image
|
dst *Image
|
||||||
args []*graphicsdriver.PixelsArgs
|
args []graphicsdriver.PixelsArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *writePixelsCommand) String() string {
|
func (c *writePixelsCommand) String() string {
|
||||||
|
@ -43,7 +43,7 @@ type Image struct {
|
|||||||
// have its graphicsdriver.Image.
|
// have its graphicsdriver.Image.
|
||||||
id int
|
id int
|
||||||
|
|
||||||
bufferedWP []*graphicsdriver.PixelsArgs
|
bufferedWritePixelsArgs []graphicsdriver.PixelsArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextID = 1
|
var nextID = 1
|
||||||
@ -93,19 +93,20 @@ func NewImage(width, height int, screenFramebuffer bool) *Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) flushBufferedWritePixels() {
|
func (i *Image) flushBufferedWritePixels() {
|
||||||
if len(i.bufferedWP) == 0 {
|
if len(i.bufferedWritePixelsArgs) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c := &writePixelsCommand{
|
c := &writePixelsCommand{
|
||||||
dst: i,
|
dst: i,
|
||||||
args: i.bufferedWP,
|
args: i.bufferedWritePixelsArgs,
|
||||||
}
|
}
|
||||||
currentCommandQueue().Enqueue(c)
|
currentCommandQueue().Enqueue(c)
|
||||||
i.bufferedWP = nil
|
|
||||||
|
i.bufferedWritePixelsArgs = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Dispose() {
|
func (i *Image) Dispose() {
|
||||||
i.bufferedWP = nil
|
i.bufferedWritePixelsArgs = nil
|
||||||
c := &disposeImageCommand{
|
c := &disposeImageCommand{
|
||||||
target: i,
|
target: i,
|
||||||
}
|
}
|
||||||
@ -178,7 +179,7 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, buf []byte, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) WritePixels(pixels []byte, region image.Rectangle) {
|
func (i *Image) WritePixels(pixels []byte, region image.Rectangle) {
|
||||||
i.bufferedWP = append(i.bufferedWP, &graphicsdriver.PixelsArgs{
|
i.bufferedWritePixelsArgs = append(i.bufferedWritePixelsArgs, graphicsdriver.PixelsArgs{
|
||||||
Pixels: pixels,
|
Pixels: pixels,
|
||||||
Region: region,
|
Region: region,
|
||||||
})
|
})
|
||||||
|
@ -130,7 +130,7 @@ func (i *image11) ReadPixels(buf []byte, region image.Rectangle) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *image11) WritePixels(args []*graphicsdriver.PixelsArgs) error {
|
func (i *image11) WritePixels(args []graphicsdriver.PixelsArgs) error {
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
i.graphics.deviceContext.UpdateSubresource(unsafe.Pointer(i.texture), 0, &_D3D11_BOX{
|
i.graphics.deviceContext.UpdateSubresource(unsafe.Pointer(i.texture), 0, &_D3D11_BOX{
|
||||||
left: uint32(a.Region.Min.X),
|
left: uint32(a.Region.Min.X),
|
||||||
|
@ -149,7 +149,7 @@ func (i *image12) ReadPixels(buf []byte, region image.Rectangle) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *image12) WritePixels(args []*graphicsdriver.PixelsArgs) error {
|
func (i *image12) WritePixels(args []graphicsdriver.PixelsArgs) error {
|
||||||
if i.screen {
|
if i.screen {
|
||||||
return errors.New("directx: WritePixels cannot be called on the screen")
|
return errors.New("directx: WritePixels cannot be called on the screen")
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ type Image interface {
|
|||||||
Dispose()
|
Dispose()
|
||||||
IsInvalidated() bool
|
IsInvalidated() bool
|
||||||
ReadPixels(buf []byte, region image.Rectangle) error
|
ReadPixels(buf []byte, region image.Rectangle) error
|
||||||
WritePixels(args []*PixelsArgs) error
|
WritePixels(args []PixelsArgs) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageID int
|
type ImageID int
|
||||||
|
@ -831,7 +831,7 @@ func (i *Image) ReadPixels(buf []byte, region image.Rectangle) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) WritePixels(args []*graphicsdriver.PixelsArgs) error {
|
func (i *Image) WritePixels(args []graphicsdriver.PixelsArgs) error {
|
||||||
g := i.graphics
|
g := i.graphics
|
||||||
|
|
||||||
g.flushRenderCommandEncoderIfNeeded()
|
g.flushRenderCommandEncoderIfNeeded()
|
||||||
|
@ -131,7 +131,7 @@ func (i *Image) ensureStencilBuffer() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) WritePixels(args []*graphicsdriver.PixelsArgs) error {
|
func (i *Image) WritePixels(args []graphicsdriver.PixelsArgs) error {
|
||||||
if i.screen {
|
if i.screen {
|
||||||
return errors.New("opengl: WritePixels cannot be called on the screen")
|
return errors.New("opengl: WritePixels cannot be called on the screen")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user