diff --git a/internal/math.go b/internal/math.go index 11f77866f..f2ea28c30 100644 --- a/internal/math.go +++ b/internal/math.go @@ -27,6 +27,6 @@ func NextPowerOf2(x uint64) uint64 { return x + 1 } -func AdjustSizeForTexture(size int) int { +func NextPowerOf2Int(size int) int { return int(NextPowerOf2(uint64(size))) } diff --git a/internal/opengl/internal/shader/drawtexture.go b/internal/opengl/internal/shader/drawtexture.go index d87f561dc..29e11a816 100644 --- a/internal/opengl/internal/shader/drawtexture.go +++ b/internal/opengl/internal/shader/drawtexture.go @@ -114,8 +114,8 @@ func DrawTexture(native gl.Texture, target gl.Texture, width, height int, projec u1, v1, ) if program == programColorMatrix.native { - w := float32(internal.AdjustSizeForTexture(width)) - h := float32(internal.AdjustSizeForTexture(height)) + w := float32(internal.NextPowerOf2Int(width)) + h := float32(internal.NextPowerOf2Int(height)) xx0 := x0 / w xx1 := x1 / w yy0 := y0 / h diff --git a/internal/opengl/internal/shader/program.go b/internal/opengl/internal/shader/program.go index b5745ec34..c622d7a8b 100644 --- a/internal/opengl/internal/shader/program.go +++ b/internal/opengl/internal/shader/program.go @@ -97,8 +97,8 @@ func useProgramColorMatrix(projectionMatrix [16]float32, width, height int, geo } getUniformLocation(program.native, "modelview_matrix").UniformMatrix4fv(false, glModelviewMatrix) - txn := tx / float32(internal.AdjustSizeForTexture(width)) - tyn := ty / float32(internal.AdjustSizeForTexture(height)) + txn := tx / float32(internal.NextPowerOf2Int(width)) + tyn := ty / float32(internal.NextPowerOf2Int(height)) glModelviewMatrixN := [...]float32{ a, c, 0, 0, b, d, 0, 0, diff --git a/internal/opengl/rendertarget.go b/internal/opengl/rendertarget.go index 734e20d9f..dd1a0933c 100644 --- a/internal/opengl/rendertarget.go +++ b/internal/opengl/rendertarget.go @@ -100,19 +100,19 @@ func (r *RenderTarget) SetAsViewport() error { return errors.New("glBindFramebuffer failed: the context is different?") } - width := internal.AdjustSizeForTexture(r.width) - height := internal.AdjustSizeForTexture(r.height) + width := internal.NextPowerOf2Int(r.width) + height := internal.NextPowerOf2Int(r.height) gl.Viewport(0, 0, width, height) return nil } func (r *RenderTarget) ProjectionMatrix() [4][4]float64 { - width := internal.AdjustSizeForTexture(r.width) - height := internal.AdjustSizeForTexture(r.height) + width := internal.NextPowerOf2Int(r.width) + height := internal.NextPowerOf2Int(r.height) m := orthoProjectionMatrix(0, width, 0, height) if r.flipY { m[1][1] *= -1 - m[1][3] += float64(r.height) / float64(internal.AdjustSizeForTexture(r.height)) * 2 + m[1][3] += float64(r.height) / float64(internal.NextPowerOf2Int(r.height)) * 2 } return m } diff --git a/internal/opengl/texture.go b/internal/opengl/texture.go index 097a352de..21300571d 100644 --- a/internal/opengl/texture.go +++ b/internal/opengl/texture.go @@ -28,8 +28,8 @@ func adjustImageForTexture(img image.Image) *image.NRGBA { adjustedImageBounds := image.Rectangle{ image.ZP, image.Point{ - internal.AdjustSizeForTexture(width), - internal.AdjustSizeForTexture(height), + internal.NextPowerOf2Int(width), + internal.NextPowerOf2Int(height), }, } if nrgba, ok := img.(*image.NRGBA); ok && img.Bounds() == adjustedImageBounds { @@ -77,8 +77,8 @@ func createNativeTexture(textureWidth, textureHeight int, pixels []uint8, filter } func NewTexture(width, height int, filter int) (*Texture, error) { - w := internal.AdjustSizeForTexture(width) - h := internal.AdjustSizeForTexture(height) + w := internal.NextPowerOf2Int(width) + h := internal.NextPowerOf2Int(height) native := createNativeTexture(w, h, nil, filter) return &Texture{native, width, height}, nil } diff --git a/rendertarget.go b/rendertarget.go index 7e39f9062..b9d581ff5 100644 --- a/rendertarget.go +++ b/rendertarget.go @@ -86,11 +86,11 @@ func (r *innerRenderTarget) DrawTexture(texture *Texture, parts []TexturePart, g } func u(x float64, width int) float32 { - return float32(x) / float32(internal.AdjustSizeForTexture(width)) + return float32(x) / float32(internal.NextPowerOf2Int(width)) } func v(y float64, height int) float32 { - return float32(y) / float32(internal.AdjustSizeForTexture(height)) + return float32(y) / float32(internal.NextPowerOf2Int(height)) } func textureQuads(parts []TexturePart, width, height int) []shader.TextureQuad {