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