Merge math and graphics packages

This commit is contained in:
Hajime Hoshi 2018-11-17 20:20:46 +09:00
parent de745f00fa
commit 14f5a03a79
7 changed files with 13 additions and 16 deletions

View File

@ -28,7 +28,7 @@ import (
. "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/examples/resources/images"
emath "github.com/hajimehoshi/ebiten/internal/math"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/testflock"
)
@ -94,7 +94,7 @@ func TestImagePixels(t *testing.T) {
w, h := img0.Bounds().Size().X, img0.Bounds().Size().Y
// Check out of range part
w2, h2 := emath.NextPowerOf2Int(w), emath.NextPowerOf2Int(h)
w2, h2 := graphics.NextPowerOf2Int(w), graphics.NextPowerOf2Int(h)
for j := -100; j < h2+100; j++ {
for i := -100; i < w2+100; i++ {
got := img0.At(i, j)

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package math
package graphics
// NextPowerOf2Int returns a nearest power of 2 to x.
func NextPowerOf2Int(x int) int {

View File

@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package math_test
package graphics_test
import (
"testing"
. "github.com/hajimehoshi/ebiten/internal/math"
. "github.com/hajimehoshi/ebiten/internal/graphics"
)
func TestNextPowerOf2(t *testing.T) {

View File

@ -20,7 +20,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/internal/math"
)
var theDriver Driver
@ -56,8 +55,8 @@ func (d *Driver) NewImage(width, height int) (graphicsdriver.Image, error) {
width: width,
height: height,
}
w := math.NextPowerOf2Int(width)
h := math.NextPowerOf2Int(height)
w := graphics.NextPowerOf2Int(width)
h := graphics.NextPowerOf2Int(height)
d.checkSize(w, h)
t, err := d.context.newTexture(w, h)
if err != nil {

View File

@ -15,7 +15,7 @@
package opengl
import (
"github.com/hajimehoshi/ebiten/internal/math"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
type Image struct {
@ -83,7 +83,7 @@ func (i *Image) ensureFramebuffer() error {
return nil
}
w, h := math.NextPowerOf2Int(i.width), math.NextPowerOf2Int(i.height)
w, h := graphics.NextPowerOf2Int(i.width), graphics.NextPowerOf2Int(i.height)
f, err := newFramebufferFromTexture(&i.driver.context, i.textureNative, w, h)
if err != nil {
return err

View File

@ -19,7 +19,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics"
emath "github.com/hajimehoshi/ebiten/internal/math"
"github.com/hajimehoshi/ebiten/internal/web"
)
@ -335,8 +334,8 @@ func (d *Driver) useProgram(mode graphics.CompositeMode, colorM *affine.ColorM,
d.state.lastColorMatrixTranslation = esTranslate
}
sw := emath.NextPowerOf2Int(srcW)
sh := emath.NextPowerOf2Int(srcH)
sw := graphics.NextPowerOf2Int(srcW)
sh := graphics.NextPowerOf2Int(srcH)
if d.state.lastSourceWidth != sw || d.state.lastSourceHeight != sh {
d.context.uniformFloats(program, "source_size", []float32{float32(sw), float32(sh)})

View File

@ -22,7 +22,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/internal/math"
)
// drawImageHistoryItem is an item for history of draw-image commands.
@ -117,8 +116,8 @@ func (i *Image) Size() (int, int) {
func (i *Image) SizePowerOf2() (int, int) {
if i.w2 == 0 || i.h2 == 0 {
w, h := i.image.Size()
i.w2 = math.NextPowerOf2Int(w)
i.h2 = math.NextPowerOf2Int(h)
i.w2 = graphics.NextPowerOf2Int(w)
i.h2 = graphics.NextPowerOf2Int(h)
}
return i.w2, i.h2
}