mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Use the original width/height for glTexSubImage2D
This commit is contained in:
parent
15d2e6b82b
commit
9f6fd0db9a
11
image.go
11
image.go
@ -21,7 +21,6 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/math"
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
"github.com/hajimehoshi/ebiten/internal/restorable"
|
||||
)
|
||||
@ -284,11 +283,11 @@ func (i *Image) ReplacePixels(p []byte) error {
|
||||
if l := 4 * w * h; len(p) != l {
|
||||
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", len(p), l))
|
||||
}
|
||||
w2, h2 := math.NextPowerOf2Int(w), math.NextPowerOf2Int(h)
|
||||
pix := make([]byte, 4*w2*h2)
|
||||
for j := 0; j < h; j++ {
|
||||
copy(pix[j*w2*4:], p[j*w*4:(j+1)*w*4])
|
||||
}
|
||||
|
||||
// Copy the pixels so that this works even p is modified just after ReplacePixels.
|
||||
pix := make([]byte, len(p))
|
||||
copy(pix, p)
|
||||
|
||||
i.restorable.ReplacePixels(pix)
|
||||
return nil
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error {
|
||||
// glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211).
|
||||
opengl.GetContext().Flush()
|
||||
opengl.GetContext().BindTexture(c.dst.texture.native)
|
||||
opengl.GetContext().TexSubImage2D(c.pixels, emath.NextPowerOf2Int(c.dst.width), emath.NextPowerOf2Int(c.dst.height))
|
||||
opengl.GetContext().TexSubImage2D(c.pixels, c.dst.width, c.dst.height)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (i *Image) Pixels() ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return opengl.GetContext().FramebufferPixels(f.native, math.NextPowerOf2Int(i.width), math.NextPowerOf2Int(i.height))
|
||||
return opengl.GetContext().FramebufferPixels(f.native, i.width, i.height)
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(p []byte) {
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
emath "github.com/hajimehoshi/ebiten/internal/math"
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
)
|
||||
|
||||
@ -213,8 +212,7 @@ func (i *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm
|
||||
// Note that this must not be called until context is available.
|
||||
func (i *Image) At(x, y int) (color.RGBA, error) {
|
||||
w, h := i.image.Size()
|
||||
w2, h2 := emath.NextPowerOf2Int(w), emath.NextPowerOf2Int(h)
|
||||
if x < 0 || y < 0 || w2 <= x || h2 <= y {
|
||||
if x < 0 || y < 0 || w <= x || h <= y {
|
||||
return color.RGBA{}, nil
|
||||
}
|
||||
if i.basePixels == nil || i.drawImageHistory != nil || i.stale {
|
||||
@ -222,7 +220,7 @@ func (i *Image) At(x, y int) (color.RGBA, error) {
|
||||
return color.RGBA{}, err
|
||||
}
|
||||
}
|
||||
idx := 4*x + 4*y*w2
|
||||
idx := 4*x + 4*y*w
|
||||
r, g, b, a := i.basePixels[idx], i.basePixels[idx+1], i.basePixels[idx+2], i.basePixels[idx+3]
|
||||
return color.RGBA{r, g, b, a}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user