mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +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
|
return minX1 < maxX2+mergin && minX2 < maxX1+mergin && minY1 < maxY2+mergin && minY2 < maxY1+mergin
|
||||||
}
|
}
|
||||||
|
|
||||||
// replacePixelsCommand represents a command to replace pixels of an image.
|
// writePixelsCommand represents a command to replace pixels of an image.
|
||||||
type replacePixelsCommand struct {
|
type writePixelsCommand struct {
|
||||||
dst *Image
|
dst *Image
|
||||||
args []*graphicsdriver.ReplacePixelsArgs
|
args []*graphicsdriver.WritePixelsArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *replacePixelsCommand) String() string {
|
func (c *writePixelsCommand) String() string {
|
||||||
return fmt.Sprintf("replace-pixels: dst: %d, len(args): %d", c.dst.id, len(c.args))
|
return fmt.Sprintf("write-pixels: dst: %d, len(args): %d", c.dst.id, len(c.args))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exec executes the replacePixelsCommand.
|
// Exec executes the writePixelsCommand.
|
||||||
func (c *replacePixelsCommand) Exec(graphicsDriver graphicsdriver.Graphics, indexOffset int) error {
|
func (c *writePixelsCommand) Exec(graphicsDriver graphicsdriver.Graphics, indexOffset int) error {
|
||||||
if len(c.args) == 0 {
|
if len(c.args) == 0 {
|
||||||
return nil
|
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 err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -43,7 +43,7 @@ type Image struct {
|
|||||||
// have its graphicsdriver.Image.
|
// have its graphicsdriver.Image.
|
||||||
id int
|
id int
|
||||||
|
|
||||||
bufferedRP []*graphicsdriver.ReplacePixelsArgs
|
bufferedRP []*graphicsdriver.WritePixelsArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextID = 1
|
var nextID = 1
|
||||||
@ -74,11 +74,11 @@ func NewImage(width, height int, screenFramebuffer bool) *Image {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) resolveBufferedReplacePixels() {
|
func (i *Image) resolveBufferedWritePixels() {
|
||||||
if len(i.bufferedRP) == 0 {
|
if len(i.bufferedRP) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c := &replacePixelsCommand{
|
c := &writePixelsCommand{
|
||||||
dst: i,
|
dst: i,
|
||||||
args: i.bufferedRP,
|
args: i.bufferedRP,
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
|
|||||||
if img.screen {
|
if img.screen {
|
||||||
panic("graphicscommand: the screen image cannot be the rendering source")
|
panic("graphicscommand: the screen image cannot be the rendering source")
|
||||||
}
|
}
|
||||||
img.resolveBufferedReplacePixels()
|
img.resolveBufferedWritePixels()
|
||||||
} else {
|
} else {
|
||||||
for _, src := range srcs {
|
for _, src := range srcs {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
@ -143,10 +143,10 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
|
|||||||
if src.screen {
|
if src.screen {
|
||||||
panic("graphicscommand: the screen image cannot be the rendering source")
|
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)
|
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 reads the image's pixels.
|
||||||
// ReadPixels returns an error when an error happens in the graphics driver.
|
// ReadPixels returns an error when an error happens in the graphics driver.
|
||||||
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, buf []byte) error {
|
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, buf []byte) error {
|
||||||
i.resolveBufferedReplacePixels()
|
i.resolveBufferedWritePixels()
|
||||||
c := &readPixelsCommand{
|
c := &readPixelsCommand{
|
||||||
img: i,
|
img: i,
|
||||||
result: buf,
|
result: buf,
|
||||||
@ -166,8 +166,8 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, buf []byte) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {
|
||||||
i.bufferedRP = append(i.bufferedRP, &graphicsdriver.ReplacePixelsArgs{
|
i.bufferedRP = append(i.bufferedRP, &graphicsdriver.WritePixelsArgs{
|
||||||
Pixels: pixels,
|
Pixels: pixels,
|
||||||
X: x,
|
X: x,
|
||||||
Y: y,
|
Y: y,
|
||||||
|
@ -1578,9 +1578,9 @@ func (i *Image) ReadPixels(buf []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) error {
|
func (i *Image) WritePixels(args []*graphicsdriver.WritePixelsArgs) error {
|
||||||
if i.screen {
|
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 {
|
if err := i.graphics.flushCommandList(i.graphics.drawCommandList); err != nil {
|
||||||
|
@ -70,12 +70,12 @@ type Image interface {
|
|||||||
Dispose()
|
Dispose()
|
||||||
IsInvalidated() bool
|
IsInvalidated() bool
|
||||||
ReadPixels(buf []byte) error
|
ReadPixels(buf []byte) error
|
||||||
ReplacePixels(args []*ReplacePixelsArgs) error
|
WritePixels(args []*WritePixelsArgs) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageID int
|
type ImageID int
|
||||||
|
|
||||||
type ReplacePixelsArgs struct {
|
type WritePixelsArgs struct {
|
||||||
Pixels []byte
|
Pixels []byte
|
||||||
X int
|
X int
|
||||||
Y int
|
Y int
|
||||||
|
@ -1199,7 +1199,7 @@ func (i *Image) ReadPixels(buf []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) error {
|
func (i *Image) WritePixels(args []*graphicsdriver.WritePixelsArgs) error {
|
||||||
g := i.graphics
|
g := i.graphics
|
||||||
|
|
||||||
g.flushRenderCommandEncoderIfNeeded()
|
g.flushRenderCommandEncoderIfNeeded()
|
||||||
|
@ -487,7 +487,7 @@ func (c *context) needsRestoring() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
|
||||||
c.bindTexture(t)
|
c.bindTexture(t)
|
||||||
for _, a := range args {
|
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))
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
|
||||||
c.bindTexture(t)
|
c.bindTexture(t)
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
|
@ -457,7 +457,7 @@ func (c *context) canUsePBO() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
|
||||||
c.bindTexture(t)
|
c.bindTexture(t)
|
||||||
for _, a := range args {
|
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)
|
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
|
nextShaderID graphicsdriver.ShaderID
|
||||||
shaders map[graphicsdriver.ShaderID]*Shader
|
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
|
drawCalled bool
|
||||||
|
|
||||||
uniformVariableNameCache map[int]string
|
uniformVariableNameCache map[int]string
|
||||||
|
@ -120,9 +120,9 @@ func (i *Image) ensureStencilBuffer() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) error {
|
func (i *Image) WritePixels(args []*graphicsdriver.WritePixelsArgs) error {
|
||||||
if i.screen {
|
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 {
|
if len(args) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -292,12 +292,12 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
|||||||
theImages.makeStaleIfDependingOn(i)
|
theImages.makeStaleIfDependingOn(i)
|
||||||
|
|
||||||
if pixels != nil {
|
if pixels != nil {
|
||||||
i.image.ReplacePixels(pixels, x, y, width, height)
|
i.image.WritePixels(pixels, x, y, width, height)
|
||||||
} else {
|
} else {
|
||||||
// TODO: When pixels == nil, we don't have to care the pixel state there. In such cases, the image
|
// 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.
|
// accepts only ReplacePixels and not Fill or DrawTriangles.
|
||||||
// TODO: Separate Image struct into two: images for only-ReplacePixels, and the others.
|
// 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() {
|
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) {
|
func (pr *pixelsRecords) apply(img *graphicscommand.Image) {
|
||||||
// TODO: Isn't this too heavy? Can we merge the operations?
|
// TODO: Isn't this too heavy? Can we merge the operations?
|
||||||
for _, r := range pr.records {
|
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