mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: NextPowerOf2Int -> NextPowerOf2Int32
This commit is contained in:
parent
5fe013ddbd
commit
495d7ca0d1
2
image.go
2
image.go
@ -127,7 +127,7 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
w, _ := i.Size()
|
w, _ := i.Size()
|
||||||
w = graphics.NextPowerOf2Int(w)
|
w = int(graphics.NextPowerOf2Int32(int32(w)))
|
||||||
idx := 4*x + 4*y*w
|
idx := 4*x + 4*y*w
|
||||||
r, g, b, a := i.pixels[idx], i.pixels[idx+1], i.pixels[idx+2], i.pixels[idx+3]
|
r, g, b, a := i.pixels[idx], i.pixels[idx+1], i.pixels[idx+2], i.pixels[idx+3]
|
||||||
return color.RGBA{r, g, b, a}
|
return color.RGBA{r, g, b, a}
|
||||||
|
@ -70,11 +70,11 @@ func (w *wholeImage) Src(i int) (x0, y0, x1, y1 int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func u(x int, width int) int {
|
func u(x int, width int) int {
|
||||||
return math.MaxInt16 * x / graphics.NextPowerOf2Int(width)
|
return math.MaxInt16 * x / int(graphics.NextPowerOf2Int32(int32(width)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func v(y int, height int) int {
|
func v(y int, height int) int {
|
||||||
return math.MaxInt16 * y / graphics.NextPowerOf2Int(height)
|
return math.MaxInt16 * y / int(graphics.NextPowerOf2Int32(int32(height)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type textureQuads struct {
|
type textureQuads struct {
|
||||||
|
@ -82,8 +82,8 @@ func (f *Framebuffer) Dispose(c *opengl.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) setAsViewport(c *opengl.Context) error {
|
func (f *Framebuffer) setAsViewport(c *opengl.Context) error {
|
||||||
width := NextPowerOf2Int(f.width)
|
width := int(NextPowerOf2Int32(int32(f.width)))
|
||||||
height := NextPowerOf2Int(f.height)
|
height := int(NextPowerOf2Int32(int32(f.height)))
|
||||||
return c.SetViewport(f.native, width, height)
|
return c.SetViewport(f.native, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,12 +91,12 @@ func (f *Framebuffer) projectionMatrix() *[4][4]float64 {
|
|||||||
if f.proMatrix != nil {
|
if f.proMatrix != nil {
|
||||||
return f.proMatrix
|
return f.proMatrix
|
||||||
}
|
}
|
||||||
width := NextPowerOf2Int(f.width)
|
width := int(NextPowerOf2Int32(int32(f.width)))
|
||||||
height := NextPowerOf2Int(f.height)
|
height := int(NextPowerOf2Int32(int32(f.height)))
|
||||||
m := orthoProjectionMatrix(0, width, 0, height)
|
m := orthoProjectionMatrix(0, width, 0, height)
|
||||||
if f.flipY {
|
if f.flipY {
|
||||||
m[1][1] *= -1
|
m[1][1] *= -1
|
||||||
m[1][3] += float64(f.height) / float64(NextPowerOf2Int(f.height)) * 2
|
m[1][3] += float64(f.height) / float64(NextPowerOf2Int32(int32(f.height))) * 2
|
||||||
}
|
}
|
||||||
f.proMatrix = m
|
f.proMatrix = m
|
||||||
return f.proMatrix
|
return f.proMatrix
|
||||||
@ -125,6 +125,6 @@ func (f *Framebuffer) DrawTexture(c *opengl.Context, t *Texture, quads TextureQu
|
|||||||
|
|
||||||
func (f *Framebuffer) Pixels(c *opengl.Context) ([]uint8, error) {
|
func (f *Framebuffer) Pixels(c *opengl.Context) ([]uint8, error) {
|
||||||
w, h := f.Size()
|
w, h := f.Size()
|
||||||
w, h = NextPowerOf2Int(w), NextPowerOf2Int(h)
|
w, h = int(NextPowerOf2Int32(int32(w))), int(NextPowerOf2Int32(int32(h)))
|
||||||
return c.FramebufferPixels(f.native, w, h)
|
return c.FramebufferPixels(f.native, w, h)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
package graphics
|
package graphics
|
||||||
|
|
||||||
func NextPowerOf2Int(x int) int {
|
func NextPowerOf2Int32(x int32) int32 {
|
||||||
x -= 1
|
x -= 1
|
||||||
x |= (x >> 1)
|
x |= (x >> 1)
|
||||||
x |= (x >> 2)
|
x |= (x >> 2)
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
|
|
||||||
func TestNextPowerOf2(t *testing.T) {
|
func TestNextPowerOf2(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
expected int
|
expected int32
|
||||||
arg int
|
arg int32
|
||||||
}{
|
}{
|
||||||
{256, 255},
|
{256, 255},
|
||||||
{256, 256},
|
{256, 256},
|
||||||
@ -30,7 +30,7 @@ func TestNextPowerOf2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
got := NextPowerOf2Int(testCase.arg)
|
got := NextPowerOf2Int32(testCase.arg)
|
||||||
wanted := testCase.expected
|
wanted := testCase.expected
|
||||||
if wanted != got {
|
if wanted != got {
|
||||||
t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted)
|
t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted)
|
||||||
|
@ -26,8 +26,8 @@ func adjustImageForTexture(img image.Image) *image.RGBA {
|
|||||||
adjustedImageBounds := image.Rectangle{
|
adjustedImageBounds := image.Rectangle{
|
||||||
image.ZP,
|
image.ZP,
|
||||||
image.Point{
|
image.Point{
|
||||||
NextPowerOf2Int(width),
|
int(NextPowerOf2Int32(int32(width))),
|
||||||
NextPowerOf2Int(height),
|
int(NextPowerOf2Int32(int32(height))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if adjustedImage, ok := img.(*image.RGBA); ok && img.Bounds() == adjustedImageBounds {
|
if adjustedImage, ok := img.(*image.RGBA); ok && img.Bounds() == adjustedImageBounds {
|
||||||
@ -54,8 +54,8 @@ func (t *Texture) Size() (width, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTexture(c *opengl.Context, width, height int, filter opengl.Filter) (*Texture, error) {
|
func NewTexture(c *opengl.Context, width, height int, filter opengl.Filter) (*Texture, error) {
|
||||||
w := NextPowerOf2Int(width)
|
w := int(NextPowerOf2Int32(int32(width)))
|
||||||
h := NextPowerOf2Int(height)
|
h := int(NextPowerOf2Int32(int32(height)))
|
||||||
if w < 4 {
|
if w < 4 {
|
||||||
return nil, errors.New("width must be equal or more than 4.")
|
return nil, errors.New("width must be equal or more than 4.")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user