mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/graphicsdriver: rename ReplacePixels to WritePixels
Updates #2236
This commit is contained in:
parent
ea04e2a9de
commit
70f5e84098
@ -512,22 +512,22 @@ func mightOverlapDstRegions(vertices1, vertices2 []float32) bool {
|
||||
return minX1 < maxX2+mergin && minX2 < maxX1+mergin && minY1 < maxY2+mergin && minY2 < maxY1+mergin
|
||||
}
|
||||
|
||||
// replacePixelsCommand represents a command to replace pixels of an image.
|
||||
type replacePixelsCommand struct {
|
||||
// writePixelsCommand represents a command to replace pixels of an image.
|
||||
type writePixelsCommand struct {
|
||||
dst *Image
|
||||
args []*graphicsdriver.ReplacePixelsArgs
|
||||
args []*graphicsdriver.WritePixelsArgs
|
||||
}
|
||||
|
||||
func (c *replacePixelsCommand) String() string {
|
||||
return fmt.Sprintf("replace-pixels: dst: %d, len(args): %d", c.dst.id, len(c.args))
|
||||
func (c *writePixelsCommand) String() string {
|
||||
return fmt.Sprintf("write-pixels: dst: %d, len(args): %d", c.dst.id, len(c.args))
|
||||
}
|
||||
|
||||
// Exec executes the replacePixelsCommand.
|
||||
func (c *replacePixelsCommand) Exec(graphicsDriver graphicsdriver.Graphics, indexOffset int) error {
|
||||
// Exec executes the writePixelsCommand.
|
||||
func (c *writePixelsCommand) Exec(graphicsDriver graphicsdriver.Graphics, indexOffset int) error {
|
||||
if len(c.args) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := c.dst.image.ReplacePixels(c.args); err != nil {
|
||||
if err := c.dst.image.WritePixels(c.args); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -43,7 +43,7 @@ type Image struct {
|
||||
// have its graphicsdriver.Image.
|
||||
id int
|
||||
|
||||
bufferedRP []*graphicsdriver.ReplacePixelsArgs
|
||||
bufferedRP []*graphicsdriver.WritePixelsArgs
|
||||
}
|
||||
|
||||
var nextID = 1
|
||||
@ -74,11 +74,11 @@ func NewImage(width, height int, screenFramebuffer bool) *Image {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *Image) resolveBufferedReplacePixels() {
|
||||
func (i *Image) resolveBufferedWritePixels() {
|
||||
if len(i.bufferedRP) == 0 {
|
||||
return
|
||||
}
|
||||
c := &replacePixelsCommand{
|
||||
c := &writePixelsCommand{
|
||||
dst: i,
|
||||
args: i.bufferedRP,
|
||||
}
|
||||
@ -134,7 +134,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
|
||||
if img.screen {
|
||||
panic("graphicscommand: the screen image cannot be the rendering source")
|
||||
}
|
||||
img.resolveBufferedReplacePixels()
|
||||
img.resolveBufferedWritePixels()
|
||||
} else {
|
||||
for _, src := range srcs {
|
||||
if src == nil {
|
||||
@ -143,10 +143,10 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
|
||||
if src.screen {
|
||||
panic("graphicscommand: the screen image cannot be the rendering source")
|
||||
}
|
||||
src.resolveBufferedReplacePixels()
|
||||
src.resolveBufferedWritePixels()
|
||||
}
|
||||
}
|
||||
i.resolveBufferedReplacePixels()
|
||||
i.resolveBufferedWritePixels()
|
||||
|
||||
theCommandQueue.EnqueueDrawTrianglesCommand(i, srcs, offsets, vertices, indices, clr, mode, filter, address, dstRegion, srcRegion, shader, uniforms, evenOdd)
|
||||
}
|
||||
@ -154,7 +154,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
|
||||
// ReadPixels reads the image's pixels.
|
||||
// ReadPixels returns an error when an error happens in the graphics driver.
|
||||
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, buf []byte) error {
|
||||
i.resolveBufferedReplacePixels()
|
||||
i.resolveBufferedWritePixels()
|
||||
c := &readPixelsCommand{
|
||||
img: i,
|
||||
result: buf,
|
||||
@ -166,8 +166,8 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, buf []byte) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
i.bufferedRP = append(i.bufferedRP, &graphicsdriver.ReplacePixelsArgs{
|
||||
func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {
|
||||
i.bufferedRP = append(i.bufferedRP, &graphicsdriver.WritePixelsArgs{
|
||||
Pixels: pixels,
|
||||
X: x,
|
||||
Y: y,
|
||||
|
@ -1578,9 +1578,9 @@ func (i *Image) ReadPixels(buf []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) error {
|
||||
func (i *Image) WritePixels(args []*graphicsdriver.WritePixelsArgs) error {
|
||||
if i.screen {
|
||||
return errors.New("directx: ReplacePixels cannot be called on the screen")
|
||||
return errors.New("directx: WritePixels cannot be called on the screen")
|
||||
}
|
||||
|
||||
if err := i.graphics.flushCommandList(i.graphics.drawCommandList); err != nil {
|
||||
|
@ -70,12 +70,12 @@ type Image interface {
|
||||
Dispose()
|
||||
IsInvalidated() bool
|
||||
ReadPixels(buf []byte) error
|
||||
ReplacePixels(args []*ReplacePixelsArgs) error
|
||||
WritePixels(args []*WritePixelsArgs) error
|
||||
}
|
||||
|
||||
type ImageID int
|
||||
|
||||
type ReplacePixelsArgs struct {
|
||||
type WritePixelsArgs struct {
|
||||
Pixels []byte
|
||||
X int
|
||||
Y int
|
||||
|
@ -1199,7 +1199,7 @@ func (i *Image) ReadPixels(buf []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) error {
|
||||
func (i *Image) WritePixels(args []*graphicsdriver.WritePixelsArgs) error {
|
||||
g := i.graphics
|
||||
|
||||
g.flushRenderCommandEncoderIfNeeded()
|
||||
|
@ -487,7 +487,7 @@ func (c *context) needsRestoring() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
for _, a := range args {
|
||||
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(a.Pixels))
|
||||
|
@ -611,7 +611,7 @@ func (c *context) canUsePBO() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
gl := c.gl
|
||||
for _, a := range args {
|
||||
|
@ -457,7 +457,7 @@ func (c *context) canUsePBO() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
for _, a := range args {
|
||||
c.ctx.TexSubImage2D(gles.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), gles.RGBA, gles.UNSIGNED_BYTE, a.Pixels)
|
||||
|
@ -49,7 +49,7 @@ type Graphics struct {
|
||||
nextShaderID graphicsdriver.ShaderID
|
||||
shaders map[graphicsdriver.ShaderID]*Shader
|
||||
|
||||
// drawCalled is true just after Draw is called. This holds true until ReplacePixels is called.
|
||||
// drawCalled is true just after Draw is called. This holds true until WritePixels is called.
|
||||
drawCalled bool
|
||||
|
||||
uniformVariableNameCache map[int]string
|
||||
|
@ -120,9 +120,9 @@ func (i *Image) ensureStencilBuffer() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) error {
|
||||
func (i *Image) WritePixels(args []*graphicsdriver.WritePixelsArgs) error {
|
||||
if i.screen {
|
||||
return errors.New("opengl: ReplacePixels cannot be called on the screen")
|
||||
return errors.New("opengl: WritePixels cannot be called on the screen")
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
|
@ -292,12 +292,12 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
theImages.makeStaleIfDependingOn(i)
|
||||
|
||||
if pixels != nil {
|
||||
i.image.ReplacePixels(pixels, x, y, width, height)
|
||||
i.image.WritePixels(pixels, x, y, width, height)
|
||||
} else {
|
||||
// TODO: When pixels == nil, we don't have to care the pixel state there. In such cases, the image
|
||||
// accepts only ReplacePixels and not Fill or DrawTriangles.
|
||||
// TODO: Separate Image struct into two: images for only-ReplacePixels, and the others.
|
||||
i.image.ReplacePixels(make([]byte, 4*width*height), x, y, width, height)
|
||||
i.image.WritePixels(make([]byte, 4*width*height), x, y, width, height)
|
||||
}
|
||||
|
||||
if !needsRestoring() || !i.needsRestoring() {
|
||||
|
@ -125,6 +125,6 @@ func (pr *pixelsRecords) readPixels(pixels []byte, x, y, width, height, imageWid
|
||||
func (pr *pixelsRecords) apply(img *graphicscommand.Image) {
|
||||
// TODO: Isn't this too heavy? Can we merge the operations?
|
||||
for _, r := range pr.records {
|
||||
img.ReplacePixels(r.pix, r.rect.Min.X, r.rect.Min.Y, r.rect.Dx(), r.rect.Dy())
|
||||
img.WritePixels(r.pix, r.rect.Min.X, r.rect.Min.Y, r.rect.Dx(), r.rect.Dy())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user