mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +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"
|
"runtime"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/internal/math"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/restorable"
|
"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 {
|
if l := 4 * w * h; len(p) != l {
|
||||||
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", 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)
|
// Copy the pixels so that this works even p is modified just after ReplacePixels.
|
||||||
for j := 0; j < h; j++ {
|
pix := make([]byte, len(p))
|
||||||
copy(pix[j*w2*4:], p[j*w*4:(j+1)*w*4])
|
copy(pix, p)
|
||||||
}
|
|
||||||
i.restorable.ReplacePixels(pix)
|
i.restorable.ReplacePixels(pix)
|
||||||
return nil
|
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).
|
// glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211).
|
||||||
opengl.GetContext().Flush()
|
opengl.GetContext().Flush()
|
||||||
opengl.GetContext().BindTexture(c.dst.texture.native)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ func (i *Image) Pixels() ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func (i *Image) ReplacePixels(p []byte) {
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
emath "github.com/hajimehoshi/ebiten/internal/math"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"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.
|
// Note that this must not be called until context is available.
|
||||||
func (i *Image) At(x, y int) (color.RGBA, error) {
|
func (i *Image) At(x, y int) (color.RGBA, error) {
|
||||||
w, h := i.image.Size()
|
w, h := i.image.Size()
|
||||||
w2, h2 := emath.NextPowerOf2Int(w), emath.NextPowerOf2Int(h)
|
if x < 0 || y < 0 || w <= x || h <= y {
|
||||||
if x < 0 || y < 0 || w2 <= x || h2 <= y {
|
|
||||||
return color.RGBA{}, nil
|
return color.RGBA{}, nil
|
||||||
}
|
}
|
||||||
if i.basePixels == nil || i.drawImageHistory != nil || i.stale {
|
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
|
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]
|
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
|
return color.RGBA{r, g, b, a}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user