diff --git a/image.go b/image.go index bd2f7289a..fd46c4c79 100644 --- a/image.go +++ b/image.go @@ -127,7 +127,7 @@ func (i *Image) At(x, y int) color.Color { } } w, _ := i.Size() - w = graphics.NextPowerOf2Int(w) + w = int(graphics.NextPowerOf2Int32(int32(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] return color.RGBA{r, g, b, a} diff --git a/imageparts.go b/imageparts.go index 9c350fca1..e9b5a439a 100644 --- a/imageparts.go +++ b/imageparts.go @@ -70,11 +70,11 @@ func (w *wholeImage) Src(i int) (x0, y0, x1, y1 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 { - return math.MaxInt16 * y / graphics.NextPowerOf2Int(height) + return math.MaxInt16 * y / int(graphics.NextPowerOf2Int32(int32(height))) } type textureQuads struct { diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index acb7cf82c..220524ad5 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -82,8 +82,8 @@ func (f *Framebuffer) Dispose(c *opengl.Context) { } func (f *Framebuffer) setAsViewport(c *opengl.Context) error { - width := NextPowerOf2Int(f.width) - height := NextPowerOf2Int(f.height) + width := int(NextPowerOf2Int32(int32(f.width))) + height := int(NextPowerOf2Int32(int32(f.height))) return c.SetViewport(f.native, width, height) } @@ -91,12 +91,12 @@ func (f *Framebuffer) projectionMatrix() *[4][4]float64 { if f.proMatrix != nil { return f.proMatrix } - width := NextPowerOf2Int(f.width) - height := NextPowerOf2Int(f.height) + width := int(NextPowerOf2Int32(int32(f.width))) + height := int(NextPowerOf2Int32(int32(f.height))) m := orthoProjectionMatrix(0, width, 0, height) if f.flipY { 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 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) { 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) } diff --git a/internal/graphics/math.go b/internal/graphics/math.go index c563811e2..e0ab3605c 100644 --- a/internal/graphics/math.go +++ b/internal/graphics/math.go @@ -14,7 +14,7 @@ package graphics -func NextPowerOf2Int(x int) int { +func NextPowerOf2Int32(x int32) int32 { x -= 1 x |= (x >> 1) x |= (x >> 2) diff --git a/internal/graphics/math_test.go b/internal/graphics/math_test.go index 13eb8331c..cb28138d5 100644 --- a/internal/graphics/math_test.go +++ b/internal/graphics/math_test.go @@ -21,8 +21,8 @@ import ( func TestNextPowerOf2(t *testing.T) { testCases := []struct { - expected int - arg int + expected int32 + arg int32 }{ {256, 255}, {256, 256}, @@ -30,7 +30,7 @@ func TestNextPowerOf2(t *testing.T) { } for _, testCase := range testCases { - got := NextPowerOf2Int(testCase.arg) + got := NextPowerOf2Int32(testCase.arg) wanted := testCase.expected if wanted != got { t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted) diff --git a/internal/graphics/texture.go b/internal/graphics/texture.go index d6569c791..36d7c1a5f 100644 --- a/internal/graphics/texture.go +++ b/internal/graphics/texture.go @@ -26,8 +26,8 @@ func adjustImageForTexture(img image.Image) *image.RGBA { adjustedImageBounds := image.Rectangle{ image.ZP, image.Point{ - NextPowerOf2Int(width), - NextPowerOf2Int(height), + int(NextPowerOf2Int32(int32(width))), + int(NextPowerOf2Int32(int32(height))), }, } 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) { - w := NextPowerOf2Int(width) - h := NextPowerOf2Int(height) + w := int(NextPowerOf2Int32(int32(width))) + h := int(NextPowerOf2Int32(int32(height))) if w < 4 { return nil, errors.New("width must be equal or more than 4.") }