graphics: NextPowerOf2Int -> NextPowerOf2Int32

This commit is contained in:
Hajime Hoshi 2016-02-27 02:35:05 +09:00
parent 5fe013ddbd
commit 495d7ca0d1
6 changed files with 17 additions and 17 deletions

View File

@ -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}

View File

@ -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 {

View File

@ -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)
}

View File

@ -14,7 +14,7 @@
package graphics
func NextPowerOf2Int(x int) int {
func NextPowerOf2Int32(x int32) int32 {
x -= 1
x |= (x >> 1)
x |= (x >> 2)

View File

@ -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)

View File

@ -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.")
}