mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Merge graphics and graphicsutil
This commit is contained in:
parent
395b46d8da
commit
ce1c616f69
11
image.go
11
image.go
@ -21,7 +21,6 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
|
||||
"github.com/hajimehoshi/ebiten/internal/shareable"
|
||||
)
|
||||
|
||||
@ -90,7 +89,7 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
||||
src = m.level(r, l)
|
||||
vs = src.QuadVertices(0, 0, w, h, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||
}
|
||||
is := graphicsutil.QuadIndices()
|
||||
is := graphics.QuadIndices()
|
||||
s.DrawImage(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterLinear)
|
||||
imgs = append(imgs, s)
|
||||
w = w2
|
||||
@ -393,7 +392,7 @@ func (i *Image) drawImage(img *Image, options *DrawImageOptions) {
|
||||
if math.IsNaN(float64(det)) {
|
||||
return
|
||||
}
|
||||
level = graphicsutil.MipmapLevel(det)
|
||||
level = graphics.MipmapLevel(det)
|
||||
if level < 0 {
|
||||
panic("not reached")
|
||||
}
|
||||
@ -417,7 +416,7 @@ func (i *Image) drawImage(img *Image, options *DrawImageOptions) {
|
||||
if level == 0 {
|
||||
src := img.mipmap.original()
|
||||
vs := src.QuadVertices(sx0, sy0, sx1, sy1, a, b, c, d, tx, ty, cr, cg, cb, ca)
|
||||
is := graphicsutil.QuadIndices()
|
||||
is := graphics.QuadIndices()
|
||||
i.mipmap.original().DrawImage(src, vs, is, colorm, mode, filter)
|
||||
} else if src := img.mipmap.level(image.Rect(sx0, sy0, sx1, sy1), level); src != nil {
|
||||
w, h := src.Size()
|
||||
@ -427,7 +426,7 @@ func (i *Image) drawImage(img *Image, options *DrawImageOptions) {
|
||||
c *= float32(s)
|
||||
d *= float32(s)
|
||||
vs := src.QuadVertices(0, 0, w, h, a, b, c, d, tx, ty, cr, cg, cb, ca)
|
||||
is := graphicsutil.QuadIndices()
|
||||
is := graphics.QuadIndices()
|
||||
i.mipmap.original().DrawImage(src, vs, is, colorm, mode, filter)
|
||||
}
|
||||
i.disposeMipmaps()
|
||||
@ -740,7 +739,7 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
||||
i.addr = i
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
|
||||
_ = i.ReplacePixels(graphicsutil.CopyImage(source))
|
||||
_ = i.ReplacePixels(graphics.CopyImage(source))
|
||||
return i, nil
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphicsutil
|
||||
package graphics
|
||||
|
||||
import (
|
||||
"image"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphicsutil_test
|
||||
package graphics_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"image/color/palette"
|
||||
"testing"
|
||||
|
||||
. "github.com/hajimehoshi/ebiten/internal/graphicsutil"
|
||||
. "github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
)
|
||||
|
||||
func TestCopyImage(t *testing.T) {
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphicsutil
|
||||
package graphics
|
||||
|
||||
import (
|
||||
"math"
|
@ -12,13 +12,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphicsutil_test
|
||||
package graphics_test
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
. "github.com/hajimehoshi/ebiten/internal/graphicsutil"
|
||||
. "github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
)
|
||||
|
||||
func TestMipmapLevel(t *testing.T) {
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphicsutil
|
||||
package graphics
|
||||
|
||||
var (
|
||||
theVerticesBackend = &verticesBackend{}
|
@ -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/graphicsutil"
|
||||
"github.com/hajimehoshi/ebiten/internal/math"
|
||||
)
|
||||
|
||||
@ -161,11 +160,11 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
// and this image can be restored without dummyImage.
|
||||
w, h := dummyImage.Size()
|
||||
colorm := (*affine.ColorM)(nil).Scale(0, 0, 0, 0)
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h,
|
||||
vs := graphics.QuadVertices(w, h, 0, 0, w, h,
|
||||
float32(width)/float32(w), 0, 0, float32(height)/float32(h),
|
||||
float32(x), float32(y),
|
||||
1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
is := graphics.QuadIndices()
|
||||
i.image.DrawImage(dummyImage.image, vs, is, colorm, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
|
||||
. "github.com/hajimehoshi/ebiten/internal/restorable"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
)
|
||||
@ -115,8 +114,8 @@ func TestRestoreChain(t *testing.T) {
|
||||
fill(imgs[0], clr.R, clr.G, clr.B, clr.A)
|
||||
for i := 0; i < num-1; i++ {
|
||||
w, h := imgs[i].Size()
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(w, h, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
imgs[i+1].DrawImage(imgs[i], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
}
|
||||
ResolveStaleImages()
|
||||
@ -157,8 +156,8 @@ func TestRestoreChain2(t *testing.T) {
|
||||
clr8 := color.RGBA{0x00, 0x00, 0xff, 0xff}
|
||||
fill(imgs[8], clr8.R, clr8.G, clr8.B, clr8.A)
|
||||
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
imgs[8].DrawImage(imgs[7], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
imgs[9].DrawImage(imgs[8], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
for i := 0; i < 7; i++ {
|
||||
@ -203,8 +202,8 @@ func TestRestoreOverrideSource(t *testing.T) {
|
||||
clr0 := color.RGBA{0x00, 0x00, 0x00, 0xff}
|
||||
clr1 := color.RGBA{0x00, 0x00, 0x01, 0xff}
|
||||
fill(img1, clr0.R, clr0.G, clr0.B, clr0.A)
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img2.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
img3.DrawImage(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
fill(img0, clr1.R, clr1.G, clr1.B, clr1.A)
|
||||
@ -288,24 +287,24 @@ func TestRestoreComplexGraph(t *testing.T) {
|
||||
img1.Dispose()
|
||||
img0.Dispose()
|
||||
}()
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img3.DrawImage(img0, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
img3.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
img4.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 2, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 2, 0, 1, 1, 1, 1)
|
||||
img4.DrawImage(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
img5.DrawImage(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
img6.DrawImage(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
img6.DrawImage(img4, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
img7.DrawImage(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 2, 0, 1, 1, 1, 1)
|
||||
vs = graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 2, 0, 1, 1, 1, 1)
|
||||
img7.DrawImage(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
ResolveStaleImages()
|
||||
if err := Restore(); err != nil {
|
||||
@ -396,8 +395,8 @@ func TestRestoreRecursive(t *testing.T) {
|
||||
img1.Dispose()
|
||||
img0.Dispose()
|
||||
}()
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawImage(img0, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
ResolveStaleImages()
|
||||
@ -484,8 +483,8 @@ func TestDrawImageAndReplacePixels(t *testing.T) {
|
||||
img1 := NewImage(2, 1, false)
|
||||
defer img1.Dispose()
|
||||
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawImage(img0, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff}, 1, 0, 1, 1)
|
||||
|
||||
@ -516,8 +515,8 @@ func TestDispose(t *testing.T) {
|
||||
img2 := newImageFromImage(base2)
|
||||
defer img2.Dispose()
|
||||
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawImage(img2, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
img1.Dispose()
|
||||
@ -544,8 +543,8 @@ func TestDoubleResolve(t *testing.T) {
|
||||
base.Pix[3] = 0xff
|
||||
img1 := newImageFromImage(base)
|
||||
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
img0.ReplacePixels([]uint8{0x00, 0xff, 0x00, 0xff}, 1, 1, 1, 1)
|
||||
// Now img0 is stale.
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
|
||||
"github.com/hajimehoshi/ebiten/internal/packing"
|
||||
"github.com/hajimehoshi/ebiten/internal/restorable"
|
||||
)
|
||||
@ -62,8 +61,8 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
||||
newImg := restorable.NewImage(s, s, false)
|
||||
oldImg := b.restorable
|
||||
w, h := oldImg.Size()
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
newImg.DrawImage(oldImg, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
oldImg.Dispose()
|
||||
b.restorable = newImg
|
||||
@ -128,8 +127,8 @@ func (i *Image) ensureNotShared() {
|
||||
x, y, w, h := i.region()
|
||||
newImg := restorable.NewImage(w, h, false)
|
||||
vw, vh := i.backend.restorable.Size()
|
||||
vs := graphicsutil.QuadVertices(vw, vh, x, y, x+w, y+h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
vs := graphics.QuadVertices(vw, vh, x, y, x+w, y+h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
newImg.DrawImage(i.backend.restorable, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
|
||||
i.dispose(false)
|
||||
@ -189,7 +188,7 @@ func (i *Image) QuadVertices(sx0, sy0, sx1, sy1 int, a, b, c, d, tx, ty float32,
|
||||
}
|
||||
ox, oy, _, _ := i.region()
|
||||
w, h := i.backend.restorable.SizePowerOf2()
|
||||
return graphicsutil.QuadVertices(w, h, sx0+ox, sy0+oy, sx1+ox, sy1+oy, a, b, c, d, tx, ty, cr, cg, cb, ca)
|
||||
return graphics.QuadVertices(w, h, sx0+ox, sy0+oy, sx1+ox, sy1+oy, a, b, c, d, tx, ty, cr, cg, cb, ca)
|
||||
}
|
||||
|
||||
func (i *Image) Vertex(dx, dy, sx, sy float32, cr, cg, cb, ca float32) []float32 {
|
||||
@ -198,7 +197,7 @@ func (i *Image) Vertex(dx, dy, sx, sy float32, cr, cg, cb, ca float32) []float32
|
||||
}
|
||||
ox, oy, _, _ := i.region()
|
||||
w, h := i.backend.restorable.SizePowerOf2()
|
||||
return graphicsutil.Vertex(w, h, dx, dy, sx+float32(ox), sy+float32(oy), cr, cg, cb, ca)
|
||||
return graphics.Vertex(w, h, dx, dy, sx+float32(ox), sy+float32(oy), cr, cg, cb, ca)
|
||||
}
|
||||
|
||||
const MaxCountForShare = 10
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
|
||||
. "github.com/hajimehoshi/ebiten/internal/shareable"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
)
|
||||
@ -86,7 +85,7 @@ func TestEnsureNotShared(t *testing.T) {
|
||||
)
|
||||
// img4.ensureNotShared() should be called.
|
||||
vs := img3.QuadVertices(0, 0, size/2, size/2, 1, 0, 0, 1, size/4, size/4, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
is := graphics.QuadIndices()
|
||||
img4.DrawImage(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
want := false
|
||||
if got := img4.IsSharedForTesting(); got != want {
|
||||
@ -150,7 +149,7 @@ func Disabled_TestReshared(t *testing.T) {
|
||||
|
||||
// Use img1 as a render target.
|
||||
vs := img2.QuadVertices(0, 0, size, size, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphicsutil.QuadIndices()
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawImage(img2, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
|
||||
want = false
|
||||
if got := img1.IsSharedForTesting(); got != want {
|
||||
|
Loading…
Reference in New Issue
Block a user