mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/driver: rename to internal/graphicsdriver
This commit is contained in:
parent
52f4c409ac
commit
df60c4c92d
@ -348,17 +348,17 @@ package {{.Package}}
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
func convertCh(driverCh chan driver.Event) (chan Event) {
|
||||
func convertCh(driverCh chan graphicsdriver.Event) (chan Event) {
|
||||
ch := make(chan Event)
|
||||
go func() {
|
||||
defer close(ch)
|
||||
|
||||
for v := range driverCh {
|
||||
switch v := v.(type) {
|
||||
{{range .Events}}case driver.{{.Name}}:
|
||||
{{range .Events}}case graphicsdriver.{{.Name}}:
|
||||
ch <- {{.Name}}(v)
|
||||
{{end}}default:
|
||||
panic(fmt.Sprintf("event: unknown event: %v", v))
|
||||
|
36
graphics.go
36
graphics.go
@ -15,7 +15,7 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
// Filter represents the type of texture filter to be used when an image is maginified or minified.
|
||||
@ -23,15 +23,15 @@ type Filter int
|
||||
|
||||
const (
|
||||
// FilterNearest represents nearest (crisp-edged) filter
|
||||
FilterNearest Filter = Filter(driver.FilterNearest)
|
||||
FilterNearest Filter = Filter(graphicsdriver.FilterNearest)
|
||||
|
||||
// FilterLinear represents linear filter
|
||||
FilterLinear Filter = Filter(driver.FilterLinear)
|
||||
FilterLinear Filter = Filter(graphicsdriver.FilterLinear)
|
||||
|
||||
// filterScreen represents a special filter for screen. Inner usage only.
|
||||
//
|
||||
// Some parameters like a color matrix or color vertex values can be ignored when filterScreen is used.
|
||||
filterScreen Filter = Filter(driver.FilterScreen)
|
||||
filterScreen Filter = Filter(graphicsdriver.FilterScreen)
|
||||
)
|
||||
|
||||
// CompositeMode represents Porter-Duff composition mode.
|
||||
@ -44,46 +44,46 @@ type CompositeMode int
|
||||
const (
|
||||
// Regular alpha blending
|
||||
// c_out = c_src + c_dst × (1 - α_src)
|
||||
CompositeModeSourceOver CompositeMode = CompositeMode(driver.CompositeModeSourceOver)
|
||||
CompositeModeSourceOver CompositeMode = CompositeMode(graphicsdriver.CompositeModeSourceOver)
|
||||
|
||||
// c_out = 0
|
||||
CompositeModeClear CompositeMode = CompositeMode(driver.CompositeModeClear)
|
||||
CompositeModeClear CompositeMode = CompositeMode(graphicsdriver.CompositeModeClear)
|
||||
|
||||
// c_out = c_src
|
||||
CompositeModeCopy CompositeMode = CompositeMode(driver.CompositeModeCopy)
|
||||
CompositeModeCopy CompositeMode = CompositeMode(graphicsdriver.CompositeModeCopy)
|
||||
|
||||
// c_out = c_dst
|
||||
CompositeModeDestination CompositeMode = CompositeMode(driver.CompositeModeDestination)
|
||||
CompositeModeDestination CompositeMode = CompositeMode(graphicsdriver.CompositeModeDestination)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst
|
||||
CompositeModeDestinationOver CompositeMode = CompositeMode(driver.CompositeModeDestinationOver)
|
||||
CompositeModeDestinationOver CompositeMode = CompositeMode(graphicsdriver.CompositeModeDestinationOver)
|
||||
|
||||
// c_out = c_src × α_dst
|
||||
CompositeModeSourceIn CompositeMode = CompositeMode(driver.CompositeModeSourceIn)
|
||||
CompositeModeSourceIn CompositeMode = CompositeMode(graphicsdriver.CompositeModeSourceIn)
|
||||
|
||||
// c_out = c_dst × α_src
|
||||
CompositeModeDestinationIn CompositeMode = CompositeMode(driver.CompositeModeDestinationIn)
|
||||
CompositeModeDestinationIn CompositeMode = CompositeMode(graphicsdriver.CompositeModeDestinationIn)
|
||||
|
||||
// c_out = c_src × (1 - α_dst)
|
||||
CompositeModeSourceOut CompositeMode = CompositeMode(driver.CompositeModeSourceOut)
|
||||
CompositeModeSourceOut CompositeMode = CompositeMode(graphicsdriver.CompositeModeSourceOut)
|
||||
|
||||
// c_out = c_dst × (1 - α_src)
|
||||
CompositeModeDestinationOut CompositeMode = CompositeMode(driver.CompositeModeDestinationOut)
|
||||
CompositeModeDestinationOut CompositeMode = CompositeMode(graphicsdriver.CompositeModeDestinationOut)
|
||||
|
||||
// c_out = c_src × α_dst + c_dst × (1 - α_src)
|
||||
CompositeModeSourceAtop CompositeMode = CompositeMode(driver.CompositeModeSourceAtop)
|
||||
CompositeModeSourceAtop CompositeMode = CompositeMode(graphicsdriver.CompositeModeSourceAtop)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst × α_src
|
||||
CompositeModeDestinationAtop CompositeMode = CompositeMode(driver.CompositeModeDestinationAtop)
|
||||
CompositeModeDestinationAtop CompositeMode = CompositeMode(graphicsdriver.CompositeModeDestinationAtop)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src)
|
||||
CompositeModeXor CompositeMode = CompositeMode(driver.CompositeModeXor)
|
||||
CompositeModeXor CompositeMode = CompositeMode(graphicsdriver.CompositeModeXor)
|
||||
|
||||
// Sum of source and destination (a.k.a. 'plus' or 'additive')
|
||||
// c_out = c_src + c_dst
|
||||
CompositeModeLighter CompositeMode = CompositeMode(driver.CompositeModeLighter)
|
||||
CompositeModeLighter CompositeMode = CompositeMode(graphicsdriver.CompositeModeLighter)
|
||||
|
||||
// The product of source and destination (a.k.a 'multiply blend mode')
|
||||
// c_out = c_src * c_dst
|
||||
CompositeModeMultiply CompositeMode = CompositeMode(driver.CompositeModeMultiply)
|
||||
CompositeModeMultiply CompositeMode = CompositeMode(graphicsdriver.CompositeModeMultiply)
|
||||
)
|
||||
|
54
image.go
54
image.go
@ -20,8 +20,8 @@ import (
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/mipmap"
|
||||
)
|
||||
|
||||
@ -106,8 +106,8 @@ func (i *Image) Fill(clr color.Color) {
|
||||
i.DrawImage(emptySubImage, op)
|
||||
}
|
||||
|
||||
func canSkipMipmap(geom GeoM, filter driver.Filter) bool {
|
||||
if filter != driver.FilterLinear {
|
||||
func canSkipMipmap(geom GeoM, filter graphicsdriver.Filter) bool {
|
||||
if filter != graphicsdriver.FilterLinear {
|
||||
return true
|
||||
}
|
||||
return geom.det2x2() >= 0.999
|
||||
@ -178,7 +178,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) {
|
||||
}
|
||||
|
||||
dstBounds := i.Bounds()
|
||||
dstRegion := driver.Region{
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: float32(dstBounds.Min.X),
|
||||
Y: float32(dstBounds.Min.Y),
|
||||
Width: float32(dstBounds.Dx()),
|
||||
@ -192,8 +192,8 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) {
|
||||
}
|
||||
|
||||
bounds := img.Bounds()
|
||||
mode := driver.CompositeMode(options.CompositeMode)
|
||||
filter := driver.Filter(options.Filter)
|
||||
mode := graphicsdriver.CompositeMode(options.CompositeMode)
|
||||
filter := graphicsdriver.Filter(options.Filter)
|
||||
|
||||
a, b, c, d, tx, ty := options.GeoM.elements32()
|
||||
|
||||
@ -206,7 +206,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) {
|
||||
|
||||
srcs := [graphics.ShaderImageNum]*mipmap.Mipmap{img.mipmap}
|
||||
|
||||
i.mipmap.DrawTriangles(srcs, vs, is, options.ColorM.affineColorM(), mode, filter, driver.AddressUnsafe, dstRegion, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, canSkipMipmap(options.GeoM, filter))
|
||||
i.mipmap.DrawTriangles(srcs, vs, is, options.ColorM.affineColorM(), mode, filter, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, canSkipMipmap(options.GeoM, filter))
|
||||
}
|
||||
|
||||
// Vertex represents a vertex passed to DrawTriangles.
|
||||
@ -235,13 +235,13 @@ type Address int
|
||||
|
||||
const (
|
||||
// AddressUnsafe means there is no guarantee when the texture coodinates are out of range.
|
||||
AddressUnsafe Address = Address(driver.AddressUnsafe)
|
||||
AddressUnsafe Address = Address(graphicsdriver.AddressUnsafe)
|
||||
|
||||
// AddressClampToZero means that out-of-range texture coordinates return 0 (transparent).
|
||||
AddressClampToZero Address = Address(driver.AddressClampToZero)
|
||||
AddressClampToZero Address = Address(graphicsdriver.AddressClampToZero)
|
||||
|
||||
// AddressRepeat means that texture coordinates wrap to the other side of the texture.
|
||||
AddressRepeat Address = Address(driver.AddressRepeat)
|
||||
AddressRepeat Address = Address(graphicsdriver.AddressRepeat)
|
||||
)
|
||||
|
||||
// FillRule is the rule whether an overlapped region is rendered with DrawTriangles(Shader).
|
||||
@ -320,7 +320,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
// TODO: Check the maximum value of indices and len(vertices)?
|
||||
|
||||
dstBounds := i.Bounds()
|
||||
dstRegion := driver.Region{
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: float32(dstBounds.Min.X),
|
||||
Y: float32(dstBounds.Min.Y),
|
||||
Width: float32(dstBounds.Dx()),
|
||||
@ -331,13 +331,13 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
options = &DrawTrianglesOptions{}
|
||||
}
|
||||
|
||||
mode := driver.CompositeMode(options.CompositeMode)
|
||||
mode := graphicsdriver.CompositeMode(options.CompositeMode)
|
||||
|
||||
address := driver.Address(options.Address)
|
||||
var sr driver.Region
|
||||
if address != driver.AddressUnsafe {
|
||||
address := graphicsdriver.Address(options.Address)
|
||||
var sr graphicsdriver.Region
|
||||
if address != graphicsdriver.AddressUnsafe {
|
||||
b := img.Bounds()
|
||||
sr = driver.Region{
|
||||
sr = graphicsdriver.Region{
|
||||
X: float32(b.Min.X),
|
||||
Y: float32(b.Min.Y),
|
||||
Width: float32(b.Dx()),
|
||||
@ -345,7 +345,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
}
|
||||
}
|
||||
|
||||
filter := driver.Filter(options.Filter)
|
||||
filter := graphicsdriver.Filter(options.Filter)
|
||||
|
||||
vs := graphics.Vertices(len(vertices))
|
||||
for i, v := range vertices {
|
||||
@ -432,7 +432,7 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
||||
// TODO: Check the maximum value of indices and len(vertices)?
|
||||
|
||||
dstBounds := i.Bounds()
|
||||
dstRegion := driver.Region{
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: float32(dstBounds.Min.X),
|
||||
Y: float32(dstBounds.Min.Y),
|
||||
Width: float32(dstBounds.Dx()),
|
||||
@ -443,7 +443,7 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
||||
options = &DrawTrianglesShaderOptions{}
|
||||
}
|
||||
|
||||
mode := driver.CompositeMode(options.CompositeMode)
|
||||
mode := graphicsdriver.CompositeMode(options.CompositeMode)
|
||||
|
||||
vs := graphics.Vertices(len(vertices))
|
||||
for i, v := range vertices {
|
||||
@ -486,10 +486,10 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
||||
sy = float32(b.Min.Y)
|
||||
}
|
||||
|
||||
var sr driver.Region
|
||||
var sr graphicsdriver.Region
|
||||
if img := options.Images[0]; img != nil {
|
||||
b := img.Bounds()
|
||||
sr = driver.Region{
|
||||
sr = graphicsdriver.Region{
|
||||
X: float32(b.Min.X),
|
||||
Y: float32(b.Min.Y),
|
||||
Width: float32(b.Dx()),
|
||||
@ -509,7 +509,7 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
||||
|
||||
us := shader.convertUniforms(options.Uniforms)
|
||||
|
||||
i.mipmap.DrawTriangles(imgs, vs, is, affine.ColorMIdentity{}, mode, driver.FilterNearest, driver.AddressUnsafe, dstRegion, sr, offsets, shader.shader, us, options.FillRule == EvenOdd, false)
|
||||
i.mipmap.DrawTriangles(imgs, vs, is, affine.ColorMIdentity{}, mode, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, sr, offsets, shader.shader, us, options.FillRule == EvenOdd, false)
|
||||
}
|
||||
|
||||
// DrawRectShaderOptions represents options for DrawRectShader.
|
||||
@ -561,7 +561,7 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
|
||||
}
|
||||
|
||||
dstBounds := i.Bounds()
|
||||
dstRegion := driver.Region{
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: float32(dstBounds.Min.X),
|
||||
Y: float32(dstBounds.Min.Y),
|
||||
Width: float32(dstBounds.Dx()),
|
||||
@ -572,7 +572,7 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
|
||||
options = &DrawRectShaderOptions{}
|
||||
}
|
||||
|
||||
mode := driver.CompositeMode(options.CompositeMode)
|
||||
mode := graphicsdriver.CompositeMode(options.CompositeMode)
|
||||
|
||||
var imgs [graphics.ShaderImageNum]*mipmap.Mipmap
|
||||
for i, img := range options.Images {
|
||||
@ -599,10 +599,10 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
|
||||
vs := graphics.QuadVertices(sx, sy, sx+float32(width), sy+float32(height), a, b, c, d, tx, ty, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
|
||||
var sr driver.Region
|
||||
var sr graphicsdriver.Region
|
||||
if img := options.Images[0]; img != nil {
|
||||
b := img.Bounds()
|
||||
sr = driver.Region{
|
||||
sr = graphicsdriver.Region{
|
||||
X: float32(b.Min.X),
|
||||
Y: float32(b.Min.Y),
|
||||
Width: float32(b.Dx()),
|
||||
@ -621,7 +621,7 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
|
||||
}
|
||||
|
||||
us := shader.convertUniforms(options.Uniforms)
|
||||
i.mipmap.DrawTriangles(imgs, vs, is, affine.ColorMIdentity{}, mode, driver.FilterNearest, driver.AddressUnsafe, dstRegion, sr, offsets, shader.shader, us, false, canSkipMipmap(options.GeoM, driver.FilterNearest))
|
||||
i.mipmap.DrawTriangles(imgs, vs, is, affine.ColorMIdentity{}, mode, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, sr, offsets, shader.shader, us, false, canSkipMipmap(options.GeoM, graphicsdriver.FilterNearest))
|
||||
}
|
||||
|
||||
// SubImage returns an image representing the portion of the image p visible through r.
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/packing"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
@ -299,13 +299,13 @@ func (i *Image) ensureIsolated() {
|
||||
is := graphics.QuadIndices()
|
||||
srcs := [graphics.ShaderImageNum]*restorable.Image{i.backend.restorable}
|
||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
||||
dstRegion := driver.Region{
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: paddingSize,
|
||||
Y: paddingSize,
|
||||
Width: float32(w - 2*paddingSize),
|
||||
Height: float32(h - 2*paddingSize),
|
||||
}
|
||||
newImg.DrawTriangles(srcs, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dstRegion, driver.Region{}, nil, nil, false)
|
||||
newImg.DrawTriangles(srcs, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, nil, nil, false)
|
||||
|
||||
i.dispose(false)
|
||||
i.backend = &backend{
|
||||
@ -355,13 +355,13 @@ func (i *Image) putOnAtlas() error {
|
||||
w, h := float32(i.width), float32(i.height)
|
||||
vs := graphics.QuadVertices(0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
newI.drawTriangles([graphics.ShaderImageNum]*Image{i}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
||||
newI.drawTriangles([graphics.ShaderImageNum]*Image{i}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
||||
}
|
||||
|
||||
newI.moveTo(i)
|
||||
@ -409,13 +409,13 @@ func (i *Image) processSrc(src *Image) {
|
||||
// 5: Color G
|
||||
// 6: Color B
|
||||
// 7: Color Y
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []driver.Uniform, evenOdd bool) {
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool) {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
i.drawTriangles(srcs, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, subimageOffsets, shader, uniforms, evenOdd, false)
|
||||
}
|
||||
|
||||
func (i *Image) drawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []driver.Uniform, evenOdd bool, keepOnAtlas bool) {
|
||||
func (i *Image) drawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool, keepOnAtlas bool) {
|
||||
if i.disposed {
|
||||
panic("atlas: the drawing target image must not be disposed (DrawTriangles)")
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||
)
|
||||
|
||||
@ -97,13 +97,13 @@ func TestEnsureIsolated(t *testing.T) {
|
||||
// img4.EnsureIsolated() should be called.
|
||||
vs := quadVertices(size/2, size/2, size/4, size/4, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: size,
|
||||
Height: size,
|
||||
}
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
want := false
|
||||
if got := img4.IsOnAtlasForTesting(); got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
@ -133,7 +133,7 @@ func TestEnsureIsolated(t *testing.T) {
|
||||
|
||||
// Check further drawing doesn't cause panic.
|
||||
// This bug was fixed by 03dcd948.
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
}
|
||||
|
||||
func TestReputOnAtlas(t *testing.T) {
|
||||
@ -174,13 +174,13 @@ func TestReputOnAtlas(t *testing.T) {
|
||||
// Use img1 as a render target.
|
||||
vs := quadVertices(size, size, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: size,
|
||||
Height: size,
|
||||
}
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -192,7 +192,7 @@ func TestReputOnAtlas(t *testing.T) {
|
||||
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -220,7 +220,7 @@ func TestReputOnAtlas(t *testing.T) {
|
||||
}
|
||||
|
||||
// img1 is on an atlas again.
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := img1.IsOnAtlasForTesting(), true; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -244,7 +244,7 @@ func TestReputOnAtlas(t *testing.T) {
|
||||
}
|
||||
|
||||
// Use img1 as a render target again.
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -256,7 +256,7 @@ func TestReputOnAtlas(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
img1.ReplacePixels(make([]byte, 4*size*size))
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -266,7 +266,7 @@ func TestReputOnAtlas(t *testing.T) {
|
||||
}
|
||||
|
||||
// img1 is not on an atlas due to ReplacePixels.
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -276,7 +276,7 @@ func TestReputOnAtlas(t *testing.T) {
|
||||
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := img3.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -370,13 +370,13 @@ func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w, h, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.ReplacePixels(pix)
|
||||
|
||||
pix, err := dst.Pixels(0, 0, w, h)
|
||||
@ -418,13 +418,13 @@ func TestSmallImages(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w, h, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
|
||||
pix, err := dst.Pixels(0, 0, w, h)
|
||||
if err != nil {
|
||||
@ -466,13 +466,13 @@ func TestLongImages(t *testing.T) {
|
||||
const scale = 120
|
||||
vs := quadVertices(w, h, 0, 0, scale)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: dstW,
|
||||
Height: dstH,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
|
||||
pix, err := dst.Pixels(0, 0, dstW, dstH)
|
||||
if err != nil {
|
||||
@ -555,13 +555,13 @@ func TestDisposedAndReputOnAtlas(t *testing.T) {
|
||||
// Use src as a render target so that src is not on an atlas.
|
||||
vs := quadVertices(size, size, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: size,
|
||||
Height: size,
|
||||
}
|
||||
src.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
src.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -571,7 +571,7 @@ func TestDisposedAndReputOnAtlas(t *testing.T) {
|
||||
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -603,7 +603,7 @@ func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
||||
// Use src as a render target so that src is not on an atlas.
|
||||
vs := quadVertices(size, size, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: size,
|
||||
@ -611,7 +611,7 @@ func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
||||
}
|
||||
|
||||
// Use src2 as a rendering target, and make src2 an independent image.
|
||||
src2.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
src2.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -632,7 +632,7 @@ func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
||||
if err := atlas.PutImagesOnAtlasForTesting(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||
)
|
||||
|
||||
@ -32,7 +32,7 @@ func TestShaderFillTwice(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w, h, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
@ -40,13 +40,13 @@ func TestShaderFillTwice(t *testing.T) {
|
||||
}
|
||||
p0 := etesting.ShaderProgramFill(0xff, 0xff, 0xff, 0xff)
|
||||
s0 := atlas.NewShader(&p0)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s0, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s0, nil, false)
|
||||
|
||||
// Vertices must be recreated (#1755)
|
||||
vs = quadVertices(w, h, 0, 0, 1)
|
||||
p1 := etesting.ShaderProgramFill(0x80, 0x80, 0x80, 0xff)
|
||||
s1 := atlas.NewShader(&p1)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s1, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s1, nil, false)
|
||||
|
||||
pix, err := dst.Pixels(0, 0, w, h)
|
||||
if err != nil {
|
||||
@ -68,17 +68,17 @@ func TestImageDrawTwice(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w, h, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src0}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src0}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
|
||||
// Vertices must be recreated (#1755)
|
||||
vs = quadVertices(w, h, 0, 0, 1)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src1}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
|
||||
pix, err := dst.Pixels(0, 0, w, h)
|
||||
if err != nil {
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
@ -214,7 +214,7 @@ func (i *Image) replacePendingPixels(pix []byte, x, y, width, height int) {
|
||||
// DrawTriangles draws the src image with the given vertices.
|
||||
//
|
||||
// Copying vertices and indices is the caller's responsibility.
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []driver.Uniform, evenOdd bool) {
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool) {
|
||||
for _, src := range srcs {
|
||||
if i == src {
|
||||
panic("buffered: Image.DrawTriangles: source images must be different from the receiver")
|
||||
|
@ -21,14 +21,14 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
var theGraphicsDriver driver.Graphics
|
||||
var theGraphicsDriver graphicsdriver.Graphics
|
||||
|
||||
func SetGraphicsDriver(driver driver.Graphics) {
|
||||
func SetGraphicsDriver(driver graphicsdriver.Graphics) {
|
||||
theGraphicsDriver = driver
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ func mustUseDifferentVertexBuffer(nextNumVertexFloats, nextNumIndices int) bool
|
||||
}
|
||||
|
||||
// EnqueueDrawTrianglesCommand enqueues a drawing-image command.
|
||||
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, color affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, shader *Shader, uniforms []driver.Uniform, evenOdd bool) {
|
||||
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool) {
|
||||
if len(indices) > graphics.IndicesNum {
|
||||
panic(fmt.Sprintf("graphicscommand: len(indices) must be <= graphics.IndicesNum but not at EnqueueDrawTrianglesCommand: len(indices): %d, graphics.IndicesNum: %d", len(indices), graphics.IndicesNum))
|
||||
}
|
||||
@ -363,46 +363,46 @@ type drawTrianglesCommand struct {
|
||||
vertices []float32
|
||||
nindices int
|
||||
color affine.ColorM
|
||||
mode driver.CompositeMode
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
dstRegion driver.Region
|
||||
srcRegion driver.Region
|
||||
mode graphicsdriver.CompositeMode
|
||||
filter graphicsdriver.Filter
|
||||
address graphicsdriver.Address
|
||||
dstRegion graphicsdriver.Region
|
||||
srcRegion graphicsdriver.Region
|
||||
shader *Shader
|
||||
uniforms []driver.Uniform
|
||||
uniforms []graphicsdriver.Uniform
|
||||
evenOdd bool
|
||||
}
|
||||
|
||||
func (c *drawTrianglesCommand) String() string {
|
||||
mode := ""
|
||||
switch c.mode {
|
||||
case driver.CompositeModeSourceOver:
|
||||
case graphicsdriver.CompositeModeSourceOver:
|
||||
mode = "source-over"
|
||||
case driver.CompositeModeClear:
|
||||
case graphicsdriver.CompositeModeClear:
|
||||
mode = "clear"
|
||||
case driver.CompositeModeCopy:
|
||||
case graphicsdriver.CompositeModeCopy:
|
||||
mode = "copy"
|
||||
case driver.CompositeModeDestination:
|
||||
case graphicsdriver.CompositeModeDestination:
|
||||
mode = "destination"
|
||||
case driver.CompositeModeDestinationOver:
|
||||
case graphicsdriver.CompositeModeDestinationOver:
|
||||
mode = "destination-over"
|
||||
case driver.CompositeModeSourceIn:
|
||||
case graphicsdriver.CompositeModeSourceIn:
|
||||
mode = "source-in"
|
||||
case driver.CompositeModeDestinationIn:
|
||||
case graphicsdriver.CompositeModeDestinationIn:
|
||||
mode = "destination-in"
|
||||
case driver.CompositeModeSourceOut:
|
||||
case graphicsdriver.CompositeModeSourceOut:
|
||||
mode = "source-out"
|
||||
case driver.CompositeModeDestinationOut:
|
||||
case graphicsdriver.CompositeModeDestinationOut:
|
||||
mode = "destination-out"
|
||||
case driver.CompositeModeSourceAtop:
|
||||
case graphicsdriver.CompositeModeSourceAtop:
|
||||
mode = "source-atop"
|
||||
case driver.CompositeModeDestinationAtop:
|
||||
case graphicsdriver.CompositeModeDestinationAtop:
|
||||
mode = "destination-atop"
|
||||
case driver.CompositeModeXor:
|
||||
case graphicsdriver.CompositeModeXor:
|
||||
mode = "xor"
|
||||
case driver.CompositeModeLighter:
|
||||
case graphicsdriver.CompositeModeLighter:
|
||||
mode = "lighter"
|
||||
case driver.CompositeModeMultiply:
|
||||
case graphicsdriver.CompositeModeMultiply:
|
||||
mode = "multiply"
|
||||
default:
|
||||
panic(fmt.Sprintf("graphicscommand: invalid composite mode: %d", c.mode))
|
||||
@ -419,11 +419,11 @@ func (c *drawTrianglesCommand) String() string {
|
||||
|
||||
filter := ""
|
||||
switch c.filter {
|
||||
case driver.FilterNearest:
|
||||
case graphicsdriver.FilterNearest:
|
||||
filter = "nearest"
|
||||
case driver.FilterLinear:
|
||||
case graphicsdriver.FilterLinear:
|
||||
filter = "linear"
|
||||
case driver.FilterScreen:
|
||||
case graphicsdriver.FilterScreen:
|
||||
filter = "screen"
|
||||
default:
|
||||
panic(fmt.Sprintf("graphicscommand: invalid filter: %d", c.filter))
|
||||
@ -431,11 +431,11 @@ func (c *drawTrianglesCommand) String() string {
|
||||
|
||||
address := ""
|
||||
switch c.address {
|
||||
case driver.AddressClampToZero:
|
||||
case graphicsdriver.AddressClampToZero:
|
||||
address = "clamp_to_zero"
|
||||
case driver.AddressRepeat:
|
||||
case graphicsdriver.AddressRepeat:
|
||||
address = "repeat"
|
||||
case driver.AddressUnsafe:
|
||||
case graphicsdriver.AddressUnsafe:
|
||||
address = "unsafe"
|
||||
default:
|
||||
panic(fmt.Sprintf("graphicscommand: invalid address: %d", c.address))
|
||||
@ -465,13 +465,13 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var shaderID driver.ShaderID = driver.InvalidShaderID
|
||||
var imgs [graphics.ShaderImageNum]driver.ImageID
|
||||
var shaderID graphicsdriver.ShaderID = graphicsdriver.InvalidShaderID
|
||||
var imgs [graphics.ShaderImageNum]graphicsdriver.ImageID
|
||||
if c.shader != nil {
|
||||
shaderID = c.shader.shader.ID()
|
||||
for i, src := range c.srcs {
|
||||
if src == nil {
|
||||
imgs[i] = driver.InvalidImageID
|
||||
imgs[i] = graphicsdriver.InvalidImageID
|
||||
continue
|
||||
}
|
||||
imgs[i] = src.image.ID()
|
||||
@ -501,7 +501,7 @@ func (c *drawTrianglesCommand) addNumIndices(n int) {
|
||||
|
||||
// CanMergeWithDrawTrianglesCommand returns a boolean value indicating whether the other drawTrianglesCommand can be merged
|
||||
// with the drawTrianglesCommand c.
|
||||
func (c *drawTrianglesCommand) CanMergeWithDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, vertices []float32, color affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, shader *Shader, evenOdd bool) bool {
|
||||
func (c *drawTrianglesCommand) CanMergeWithDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, vertices []float32, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, evenOdd bool) bool {
|
||||
// If a shader is used, commands are not merged.
|
||||
//
|
||||
// TODO: Merge shader commands considering uniform variables.
|
||||
@ -581,7 +581,7 @@ func mightOverlapDstRegions(vertices1, vertices2 []float32) bool {
|
||||
// replacePixelsCommand represents a command to replace pixels of an image.
|
||||
type replacePixelsCommand struct {
|
||||
dst *Image
|
||||
args []*driver.ReplacePixelsArgs
|
||||
args []*graphicsdriver.ReplacePixelsArgs
|
||||
}
|
||||
|
||||
func (c *replacePixelsCommand) String() string {
|
||||
|
@ -23,14 +23,14 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/png"
|
||||
)
|
||||
|
||||
// Image represents an image that is implemented with OpenGL.
|
||||
type Image struct {
|
||||
image driver.Image
|
||||
image graphicsdriver.Image
|
||||
width int
|
||||
height int
|
||||
internalWidth int
|
||||
@ -39,11 +39,11 @@ type Image struct {
|
||||
|
||||
// id is an indentifier for the image. This is used only when dummping the information.
|
||||
//
|
||||
// This is duplicated with driver.Image's ID, but this id is still necessary because this image might not
|
||||
// have its driver.Image.
|
||||
// This is duplicated with graphicsdriver.Image's ID, but this id is still necessary because this image might not
|
||||
// have its graphicsdriver.Image.
|
||||
id int
|
||||
|
||||
bufferedRP []*driver.ReplacePixelsArgs
|
||||
bufferedRP []*graphicsdriver.ReplacePixelsArgs
|
||||
}
|
||||
|
||||
var nextID = 1
|
||||
@ -141,7 +141,7 @@ func (i *Image) InternalSize() (int, int) {
|
||||
//
|
||||
// If the source image is not specified, i.e., src is nil and there is no image in the uniform variables, the
|
||||
// elements for the source image are not used.
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, clr affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, shader *Shader, uniforms []driver.Uniform, evenOdd bool) {
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, clr affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool) {
|
||||
if shader == nil {
|
||||
// Fast path for rendering without a shader (#1355).
|
||||
img := srcs[0]
|
||||
@ -180,7 +180,7 @@ func (i *Image) Pixels() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
i.bufferedRP = append(i.bufferedRP, &driver.ReplacePixelsArgs{
|
||||
i.bufferedRP = append(i.bufferedRP, &graphicsdriver.ReplacePixelsArgs{
|
||||
Pixels: pixels,
|
||||
X: x,
|
||||
Y: y,
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||
)
|
||||
|
||||
@ -45,13 +45,13 @@ func TestClear(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w/2, h/2)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
|
||||
pix, err := dst.Pixels()
|
||||
if err != nil {
|
||||
@ -76,14 +76,14 @@ func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
||||
dst := graphicscommand.NewImage(w, h)
|
||||
vs := quadVertices(w/2, h/2)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||
|
||||
// TODO: Check the result.
|
||||
@ -95,17 +95,17 @@ func TestShader(t *testing.T) {
|
||||
dst := graphicscommand.NewImage(w, h)
|
||||
vs := quadVertices(w, h)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
|
||||
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
||||
s := graphicscommand.NewShader(&ir)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||
|
||||
pix, err := dst.Pixels()
|
||||
if err != nil {
|
||||
|
@ -15,12 +15,12 @@
|
||||
package graphicscommand
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
type Shader struct {
|
||||
shader driver.Shader
|
||||
shader graphicsdriver.Shader
|
||||
}
|
||||
|
||||
func NewShader(ir *shaderir.Program) *Shader {
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package driver
|
||||
package graphicsdriver
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package driver
|
||||
package graphicsdriver
|
||||
|
||||
type Filter int
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package driver
|
||||
package graphicsdriver
|
||||
|
||||
import (
|
||||
"errors"
|
@ -24,8 +24,8 @@ import (
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/ca"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
@ -297,9 +297,9 @@ FragmentShaderFunc(0, FILTER_SCREEN, ADDRESS_UNSAFE)
|
||||
|
||||
type rpsKey struct {
|
||||
useColorM bool
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
compositeMode driver.CompositeMode
|
||||
filter graphicsdriver.Filter
|
||||
address graphicsdriver.Address
|
||||
compositeMode graphicsdriver.CompositeMode
|
||||
stencilMode stencilMode
|
||||
screen bool
|
||||
}
|
||||
@ -325,11 +325,11 @@ type Graphics struct {
|
||||
vb mtl.Buffer
|
||||
ib mtl.Buffer
|
||||
|
||||
images map[driver.ImageID]*Image
|
||||
nextImageID driver.ImageID
|
||||
images map[graphicsdriver.ImageID]*Image
|
||||
nextImageID graphicsdriver.ImageID
|
||||
|
||||
shaders map[driver.ShaderID]*Shader
|
||||
nextShaderID driver.ShaderID
|
||||
shaders map[graphicsdriver.ShaderID]*Shader
|
||||
nextShaderID graphicsdriver.ShaderID
|
||||
|
||||
src *Image
|
||||
dst *Image
|
||||
@ -499,17 +499,17 @@ func (g *Graphics) checkSize(width, height int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Graphics) genNextImageID() driver.ImageID {
|
||||
func (g *Graphics) genNextImageID() graphicsdriver.ImageID {
|
||||
g.nextImageID++
|
||||
return g.nextImageID
|
||||
}
|
||||
|
||||
func (g *Graphics) genNextShaderID() driver.ShaderID {
|
||||
func (g *Graphics) genNextShaderID() graphicsdriver.ShaderID {
|
||||
g.nextShaderID++
|
||||
return g.nextShaderID
|
||||
}
|
||||
|
||||
func (g *Graphics) NewImage(width, height int) (driver.Image, error) {
|
||||
func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
|
||||
g.checkSize(width, height)
|
||||
td := mtl.TextureDescriptor{
|
||||
TextureType: mtl.TextureType2D,
|
||||
@ -531,7 +531,7 @@ func (g *Graphics) NewImage(width, height int) (driver.Image, error) {
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (g *Graphics) NewScreenFramebufferImage(width, height int) (driver.Image, error) {
|
||||
func (g *Graphics) NewScreenFramebufferImage(width, height int) (graphicsdriver.Image, error) {
|
||||
g.view.setDrawableSize(width, height)
|
||||
i := &Image{
|
||||
id: g.genNextImageID(),
|
||||
@ -546,7 +546,7 @@ func (g *Graphics) NewScreenFramebufferImage(width, height int) (driver.Image, e
|
||||
|
||||
func (g *Graphics) addImage(img *Image) {
|
||||
if g.images == nil {
|
||||
g.images = map[driver.ImageID]*Image{}
|
||||
g.images = map[graphicsdriver.ImageID]*Image{}
|
||||
}
|
||||
if _, ok := g.images[img.id]; ok {
|
||||
panic(fmt.Sprintf("opengl: image ID %d was already registered", img.id))
|
||||
@ -562,21 +562,21 @@ func (g *Graphics) SetTransparent(transparent bool) {
|
||||
g.transparent = transparent
|
||||
}
|
||||
|
||||
func operationToBlendFactor(c driver.Operation) mtl.BlendFactor {
|
||||
func operationToBlendFactor(c graphicsdriver.Operation) mtl.BlendFactor {
|
||||
switch c {
|
||||
case driver.Zero:
|
||||
case graphicsdriver.Zero:
|
||||
return mtl.BlendFactorZero
|
||||
case driver.One:
|
||||
case graphicsdriver.One:
|
||||
return mtl.BlendFactorOne
|
||||
case driver.SrcAlpha:
|
||||
case graphicsdriver.SrcAlpha:
|
||||
return mtl.BlendFactorSourceAlpha
|
||||
case driver.DstAlpha:
|
||||
case graphicsdriver.DstAlpha:
|
||||
return mtl.BlendFactorDestinationAlpha
|
||||
case driver.OneMinusSrcAlpha:
|
||||
case graphicsdriver.OneMinusSrcAlpha:
|
||||
return mtl.BlendFactorOneMinusSourceAlpha
|
||||
case driver.OneMinusDstAlpha:
|
||||
case graphicsdriver.OneMinusDstAlpha:
|
||||
return mtl.BlendFactorOneMinusDestinationAlpha
|
||||
case driver.DstColor:
|
||||
case graphicsdriver.DstColor:
|
||||
return mtl.BlendFactorDestinationColor
|
||||
default:
|
||||
panic(fmt.Sprintf("metal: invalid operation: %d", c))
|
||||
@ -607,12 +607,12 @@ func (g *Graphics) Initialize() error {
|
||||
}
|
||||
|
||||
replaces := map[string]string{
|
||||
"{{.FilterNearest}}": fmt.Sprintf("%d", driver.FilterNearest),
|
||||
"{{.FilterLinear}}": fmt.Sprintf("%d", driver.FilterLinear),
|
||||
"{{.FilterScreen}}": fmt.Sprintf("%d", driver.FilterScreen),
|
||||
"{{.AddressClampToZero}}": fmt.Sprintf("%d", driver.AddressClampToZero),
|
||||
"{{.AddressRepeat}}": fmt.Sprintf("%d", driver.AddressRepeat),
|
||||
"{{.AddressUnsafe}}": fmt.Sprintf("%d", driver.AddressUnsafe),
|
||||
"{{.FilterNearest}}": fmt.Sprintf("%d", graphicsdriver.FilterNearest),
|
||||
"{{.FilterLinear}}": fmt.Sprintf("%d", graphicsdriver.FilterLinear),
|
||||
"{{.FilterScreen}}": fmt.Sprintf("%d", graphicsdriver.FilterScreen),
|
||||
"{{.AddressClampToZero}}": fmt.Sprintf("%d", graphicsdriver.AddressClampToZero),
|
||||
"{{.AddressRepeat}}": fmt.Sprintf("%d", graphicsdriver.AddressRepeat),
|
||||
"{{.AddressUnsafe}}": fmt.Sprintf("%d", graphicsdriver.AddressUnsafe),
|
||||
}
|
||||
src := source
|
||||
for k, v := range replaces {
|
||||
@ -628,7 +628,7 @@ func (g *Graphics) Initialize() error {
|
||||
return err
|
||||
}
|
||||
fs, err := lib.MakeFunction(
|
||||
fmt.Sprintf("FragmentShader_%d_%d_%d", 0, driver.FilterScreen, driver.AddressUnsafe))
|
||||
fmt.Sprintf("FragmentShader_%d_%d_%d", 0, graphicsdriver.FilterScreen, graphicsdriver.AddressUnsafe))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -651,16 +651,16 @@ func (g *Graphics) Initialize() error {
|
||||
|
||||
for _, screen := range []bool{false, true} {
|
||||
for _, cm := range []bool{false, true} {
|
||||
for _, a := range []driver.Address{
|
||||
driver.AddressClampToZero,
|
||||
driver.AddressRepeat,
|
||||
driver.AddressUnsafe,
|
||||
for _, a := range []graphicsdriver.Address{
|
||||
graphicsdriver.AddressClampToZero,
|
||||
graphicsdriver.AddressRepeat,
|
||||
graphicsdriver.AddressUnsafe,
|
||||
} {
|
||||
for _, f := range []driver.Filter{
|
||||
driver.FilterNearest,
|
||||
driver.FilterLinear,
|
||||
for _, f := range []graphicsdriver.Filter{
|
||||
graphicsdriver.FilterNearest,
|
||||
graphicsdriver.FilterLinear,
|
||||
} {
|
||||
for c := driver.CompositeModeSourceOver; c <= driver.CompositeModeMax; c++ {
|
||||
for c := graphicsdriver.CompositeModeSourceOver; c <= graphicsdriver.CompositeModeMax; c++ {
|
||||
for _, stencil := range []stencilMode{
|
||||
prepareStencil,
|
||||
drawWithStencil,
|
||||
@ -775,7 +775,7 @@ func (g *Graphics) flushRenderCommandEncoderIfNeeded() {
|
||||
g.lastDst = nil
|
||||
}
|
||||
|
||||
func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion driver.Region, srcs [graphics.ShaderImageNum]*Image, indexLen int, indexOffset int, uniforms []driver.Uniform, stencilMode stencilMode) error {
|
||||
func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion graphicsdriver.Region, srcs [graphics.ShaderImageNum]*Image, indexLen int, indexOffset int, uniforms []graphicsdriver.Uniform, stencilMode stencilMode) error {
|
||||
// When prepareing a stencil buffer, flush the current render command encoder
|
||||
// to make sure the stencil buffer is cleared when loading.
|
||||
// TODO: What about clearing the stencil buffer by vertices?
|
||||
@ -866,7 +866,7 @@ func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion drive
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM driver.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, uniforms []driver.Uniform, evenOdd bool) error {
|
||||
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.ShaderImageNum]graphicsdriver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms []graphicsdriver.Uniform, evenOdd bool) error {
|
||||
dst := g.images[dstID]
|
||||
|
||||
if dst.screen {
|
||||
@ -879,9 +879,9 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
}
|
||||
|
||||
rpss := map[stencilMode]mtl.RenderPipelineState{}
|
||||
var uniformVars []driver.Uniform
|
||||
if shaderID == driver.InvalidShaderID {
|
||||
if dst.screen && filter == driver.FilterScreen {
|
||||
var uniformVars []graphicsdriver.Uniform
|
||||
if shaderID == graphicsdriver.InvalidShaderID {
|
||||
if dst.screen && filter == graphicsdriver.FilterScreen {
|
||||
rpss[noStencil] = g.screenRPS
|
||||
} else {
|
||||
for _, stencil := range []stencilMode{
|
||||
@ -902,7 +902,7 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
|
||||
w, h := dst.internalSize()
|
||||
sourceSize := []float32{0, 0}
|
||||
if filter != driver.FilterNearest {
|
||||
if filter != graphicsdriver.FilterNearest {
|
||||
w, h := srcs[0].internalSize()
|
||||
sourceSize[0] = float32(w)
|
||||
sourceSize[1] = float32(h)
|
||||
@ -911,10 +911,10 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
var esTranslate [4]float32
|
||||
colorM.Elements(&esBody, &esTranslate)
|
||||
scale := float32(0)
|
||||
if filter == driver.FilterScreen {
|
||||
if filter == graphicsdriver.FilterScreen {
|
||||
scale = float32(dst.width) / float32(srcs[0].width)
|
||||
}
|
||||
uniformVars = []driver.Uniform{
|
||||
uniformVars = []graphicsdriver.Uniform{
|
||||
{
|
||||
Float32s: []float32{float32(w), float32(h)},
|
||||
},
|
||||
@ -952,11 +952,11 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
}
|
||||
}
|
||||
|
||||
uniformVars = make([]driver.Uniform, graphics.PreservedUniformVariablesNum+len(uniforms))
|
||||
uniformVars = make([]graphicsdriver.Uniform, graphics.PreservedUniformVariablesNum+len(uniforms))
|
||||
|
||||
// Set the destination texture size.
|
||||
dw, dh := dst.internalSize()
|
||||
uniformVars[graphics.DestinationTextureSizeUniformVariableIndex] = driver.Uniform{
|
||||
uniformVars[graphics.DestinationTextureSizeUniformVariableIndex] = graphicsdriver.Uniform{
|
||||
Float32s: []float32{float32(dw), float32(dh)},
|
||||
}
|
||||
|
||||
@ -969,19 +969,19 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
usizes[2*i+1] = float32(h)
|
||||
}
|
||||
}
|
||||
uniformVars[graphics.TextureSizesUniformVariableIndex] = driver.Uniform{
|
||||
uniformVars[graphics.TextureSizesUniformVariableIndex] = graphicsdriver.Uniform{
|
||||
Float32s: usizes,
|
||||
}
|
||||
|
||||
// Set the destination region's origin.
|
||||
udorigin := []float32{float32(dstRegion.X) / float32(dw), float32(dstRegion.Y) / float32(dh)}
|
||||
uniformVars[graphics.TextureDestinationRegionOriginUniformVariableIndex] = driver.Uniform{
|
||||
uniformVars[graphics.TextureDestinationRegionOriginUniformVariableIndex] = graphicsdriver.Uniform{
|
||||
Float32s: udorigin,
|
||||
}
|
||||
|
||||
// Set the destination region's size.
|
||||
udsize := []float32{float32(dstRegion.Width) / float32(dw), float32(dstRegion.Height) / float32(dh)}
|
||||
uniformVars[graphics.TextureDestinationRegionSizeUniformVariableIndex] = driver.Uniform{
|
||||
uniformVars[graphics.TextureDestinationRegionSizeUniformVariableIndex] = graphicsdriver.Uniform{
|
||||
Float32s: udsize,
|
||||
}
|
||||
|
||||
@ -991,19 +991,19 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
uoffsets[2*i] = offset[0]
|
||||
uoffsets[2*i+1] = offset[1]
|
||||
}
|
||||
uniformVars[graphics.TextureSourceOffsetsUniformVariableIndex] = driver.Uniform{
|
||||
uniformVars[graphics.TextureSourceOffsetsUniformVariableIndex] = graphicsdriver.Uniform{
|
||||
Float32s: uoffsets,
|
||||
}
|
||||
|
||||
// Set the source region's origin of texture0.
|
||||
usorigin := []float32{float32(srcRegion.X), float32(srcRegion.Y)}
|
||||
uniformVars[graphics.TextureSourceRegionOriginUniformVariableIndex] = driver.Uniform{
|
||||
uniformVars[graphics.TextureSourceRegionOriginUniformVariableIndex] = graphicsdriver.Uniform{
|
||||
Float32s: usorigin,
|
||||
}
|
||||
|
||||
// Set the source region's size of texture0.
|
||||
ussize := []float32{float32(srcRegion.Width), float32(srcRegion.Height)}
|
||||
uniformVars[graphics.TextureSourceRegionSizeUniformVariableIndex] = driver.Uniform{
|
||||
uniformVars[graphics.TextureSourceRegionSizeUniformVariableIndex] = graphicsdriver.Uniform{
|
||||
Float32s: ussize,
|
||||
}
|
||||
|
||||
@ -1038,8 +1038,8 @@ func (g *Graphics) SetFullscreen(fullscreen bool) {
|
||||
g.view.setFullscreen(fullscreen)
|
||||
}
|
||||
|
||||
func (g *Graphics) FramebufferYDirection() driver.YDirection {
|
||||
return driver.Downward
|
||||
func (g *Graphics) FramebufferYDirection() graphicsdriver.YDirection {
|
||||
return graphicsdriver.Downward
|
||||
}
|
||||
|
||||
func (g *Graphics) NeedsRestoring() bool {
|
||||
@ -1092,7 +1092,7 @@ func (g *Graphics) MaxImageSize() int {
|
||||
return g.maxImageSize
|
||||
}
|
||||
|
||||
func (g *Graphics) NewShader(program *shaderir.Program) (driver.Shader, error) {
|
||||
func (g *Graphics) NewShader(program *shaderir.Program) (graphicsdriver.Shader, error) {
|
||||
s, err := newShader(g.view.getMTLDevice(), g.genNextShaderID(), program)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1103,7 +1103,7 @@ func (g *Graphics) NewShader(program *shaderir.Program) (driver.Shader, error) {
|
||||
|
||||
func (g *Graphics) addShader(shader *Shader) {
|
||||
if g.shaders == nil {
|
||||
g.shaders = map[driver.ShaderID]*Shader{}
|
||||
g.shaders = map[graphicsdriver.ShaderID]*Shader{}
|
||||
}
|
||||
if _, ok := g.shaders[shader.id]; ok {
|
||||
panic(fmt.Sprintf("metal: shader ID %d was already registered", shader.id))
|
||||
@ -1116,7 +1116,7 @@ func (g *Graphics) removeShader(shader *Shader) {
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
id driver.ImageID
|
||||
id graphicsdriver.ImageID
|
||||
graphics *Graphics
|
||||
width int
|
||||
height int
|
||||
@ -1125,7 +1125,7 @@ type Image struct {
|
||||
stencil mtl.Texture
|
||||
}
|
||||
|
||||
func (i *Image) ID() driver.ImageID {
|
||||
func (i *Image) ID() graphicsdriver.ImageID {
|
||||
return i.id
|
||||
}
|
||||
|
||||
@ -1184,7 +1184,7 @@ func (i *Image) Pixels() ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
g := i.graphics
|
||||
|
||||
g.flushRenderCommandEncoderIfNeeded()
|
||||
|
@ -20,19 +20,19 @@ package metal
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/metal"
|
||||
)
|
||||
|
||||
type shaderRpsKey struct {
|
||||
compositeMode driver.CompositeMode
|
||||
compositeMode graphicsdriver.CompositeMode
|
||||
stencilMode stencilMode
|
||||
}
|
||||
|
||||
type Shader struct {
|
||||
id driver.ShaderID
|
||||
id graphicsdriver.ShaderID
|
||||
|
||||
ir *shaderir.Program
|
||||
fs mtl.Function
|
||||
@ -40,7 +40,7 @@ type Shader struct {
|
||||
rpss map[shaderRpsKey]mtl.RenderPipelineState
|
||||
}
|
||||
|
||||
func newShader(device mtl.Device, id driver.ShaderID, program *shaderir.Program) (*Shader, error) {
|
||||
func newShader(device mtl.Device, id graphicsdriver.ShaderID, program *shaderir.Program) (*Shader, error) {
|
||||
s := &Shader{
|
||||
id: id,
|
||||
ir: program,
|
||||
@ -52,7 +52,7 @@ func newShader(device mtl.Device, id driver.ShaderID, program *shaderir.Program)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Shader) ID() driver.ShaderID {
|
||||
func (s *Shader) ID() graphicsdriver.ShaderID {
|
||||
return s.id
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ func (s *Shader) init(device mtl.Device) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Shader) RenderPipelineState(device mtl.Device, compositeMode driver.CompositeMode, stencilMode stencilMode) (mtl.RenderPipelineState, error) {
|
||||
func (s *Shader) RenderPipelineState(device mtl.Device, compositeMode graphicsdriver.CompositeMode, stencilMode stencilMode) (mtl.RenderPipelineState, error) {
|
||||
if rps, ok := s.rpss[shaderRpsKey{
|
||||
compositeMode: compositeMode,
|
||||
stencilMode: stencilMode,
|
||||
|
@ -18,26 +18,26 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
type operation int
|
||||
|
||||
func convertOperation(op driver.Operation) operation {
|
||||
func convertOperation(op graphicsdriver.Operation) operation {
|
||||
switch op {
|
||||
case driver.Zero:
|
||||
case graphicsdriver.Zero:
|
||||
return zero
|
||||
case driver.One:
|
||||
case graphicsdriver.One:
|
||||
return one
|
||||
case driver.SrcAlpha:
|
||||
case graphicsdriver.SrcAlpha:
|
||||
return srcAlpha
|
||||
case driver.DstAlpha:
|
||||
case graphicsdriver.DstAlpha:
|
||||
return dstAlpha
|
||||
case driver.OneMinusSrcAlpha:
|
||||
case graphicsdriver.OneMinusSrcAlpha:
|
||||
return oneMinusSrcAlpha
|
||||
case driver.OneMinusDstAlpha:
|
||||
case graphicsdriver.OneMinusDstAlpha:
|
||||
return oneMinusDstAlpha
|
||||
case driver.DstColor:
|
||||
case graphicsdriver.DstColor:
|
||||
return dstColor
|
||||
default:
|
||||
panic(fmt.Sprintf("opengl: invalid operation %d at convertOperation", op))
|
||||
@ -52,7 +52,7 @@ type context struct {
|
||||
lastRenderbuffer renderbufferNative
|
||||
lastViewportWidth int
|
||||
lastViewportHeight int
|
||||
lastCompositeMode driver.CompositeMode
|
||||
lastCompositeMode graphicsdriver.CompositeMode
|
||||
maxTextureSize int
|
||||
maxTextureSizeOnce sync.Once
|
||||
highp bool
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
@ -110,11 +110,11 @@ func (c *context) reset() error {
|
||||
c.lastFramebuffer = invalidFramebuffer
|
||||
c.lastViewportWidth = 0
|
||||
c.lastViewportHeight = 0
|
||||
c.lastCompositeMode = driver.CompositeModeUnknown
|
||||
c.lastCompositeMode = graphicsdriver.CompositeModeUnknown
|
||||
gl.Enable(gl.BLEND)
|
||||
gl.Enable(gl.SCISSOR_TEST)
|
||||
|
||||
c.blendFunc(driver.CompositeModeSourceOver)
|
||||
c.blendFunc(graphicsdriver.CompositeModeSourceOver)
|
||||
|
||||
f := int32(0)
|
||||
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
|
||||
@ -122,7 +122,7 @@ func (c *context) reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) blendFunc(mode driver.CompositeMode) {
|
||||
func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
|
||||
if c.lastCompositeMode == mode {
|
||||
return
|
||||
}
|
||||
@ -496,7 +496,7 @@ func (c *context) needsRestoring() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) texSubImage2D(t textureNative, args []*driver.ReplacePixelsArgs) {
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
for _, a := range args {
|
||||
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(a.Pixels))
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"fmt"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/jsutil"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
@ -167,19 +167,19 @@ func (c *context) reset() error {
|
||||
c.lastFramebuffer = framebufferNative(js.Null())
|
||||
c.lastViewportWidth = 0
|
||||
c.lastViewportHeight = 0
|
||||
c.lastCompositeMode = driver.CompositeModeUnknown
|
||||
c.lastCompositeMode = graphicsdriver.CompositeModeUnknown
|
||||
|
||||
if err := c.initGL(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.gl.isContextLost.Invoke().Bool() {
|
||||
return driver.GraphicsNotReady
|
||||
return graphicsdriver.GraphicsNotReady
|
||||
}
|
||||
gl := c.gl
|
||||
gl.enable.Invoke(gles.BLEND)
|
||||
gl.enable.Invoke(gles.SCISSOR_TEST)
|
||||
c.blendFunc(driver.CompositeModeSourceOver)
|
||||
c.blendFunc(graphicsdriver.CompositeModeSourceOver)
|
||||
f := gl.getParameter.Invoke(gles.FRAMEBUFFER_BINDING)
|
||||
c.screenFramebuffer = framebufferNative(f)
|
||||
|
||||
@ -189,7 +189,7 @@ func (c *context) reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) blendFunc(mode driver.CompositeMode) {
|
||||
func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
|
||||
if c.lastCompositeMode == mode {
|
||||
return
|
||||
}
|
||||
@ -620,7 +620,7 @@ func (c *context) canUsePBO() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) texSubImage2D(t textureNative, args []*driver.ReplacePixelsArgs) {
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
gl := c.gl
|
||||
for _, a := range args {
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
@ -102,10 +102,10 @@ func (c *context) reset() error {
|
||||
c.lastFramebuffer = invalidFramebuffer
|
||||
c.lastViewportWidth = 0
|
||||
c.lastViewportHeight = 0
|
||||
c.lastCompositeMode = driver.CompositeModeUnknown
|
||||
c.lastCompositeMode = graphicsdriver.CompositeModeUnknown
|
||||
c.ctx.Enable(gles.BLEND)
|
||||
c.ctx.Enable(gles.SCISSOR_TEST)
|
||||
c.blendFunc(driver.CompositeModeSourceOver)
|
||||
c.blendFunc(graphicsdriver.CompositeModeSourceOver)
|
||||
f := make([]int32, 1)
|
||||
c.ctx.GetIntegerv(f, gles.FRAMEBUFFER_BINDING)
|
||||
c.screenFramebuffer = framebufferNative(f[0])
|
||||
@ -113,7 +113,7 @@ func (c *context) reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) blendFunc(mode driver.CompositeMode) {
|
||||
func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
|
||||
if c.lastCompositeMode == mode {
|
||||
return
|
||||
}
|
||||
@ -464,7 +464,7 @@ func (c *context) canUsePBO() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) texSubImage2D(t textureNative, args []*driver.ReplacePixelsArgs) {
|
||||
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
for _, a := range args {
|
||||
c.ctx.TexSubImage2D(gles.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), gles.RGBA, gles.UNSIGNED_BYTE, a.Pixels)
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
// glslReservedKeywords is a set of reserved keywords that cannot be used as an indentifier on some environments.
|
||||
@ -61,11 +61,11 @@ func vertexShaderStr() string {
|
||||
return src
|
||||
}
|
||||
|
||||
func fragmentShaderStr(useColorM bool, filter driver.Filter, address driver.Address) string {
|
||||
func fragmentShaderStr(useColorM bool, filter graphicsdriver.Filter, address graphicsdriver.Address) string {
|
||||
replaces := map[string]string{
|
||||
"{{.AddressClampToZero}}": fmt.Sprintf("%d", driver.AddressClampToZero),
|
||||
"{{.AddressRepeat}}": fmt.Sprintf("%d", driver.AddressRepeat),
|
||||
"{{.AddressUnsafe}}": fmt.Sprintf("%d", driver.AddressUnsafe),
|
||||
"{{.AddressClampToZero}}": fmt.Sprintf("%d", graphicsdriver.AddressClampToZero),
|
||||
"{{.AddressRepeat}}": fmt.Sprintf("%d", graphicsdriver.AddressRepeat),
|
||||
"{{.AddressUnsafe}}": fmt.Sprintf("%d", graphicsdriver.AddressUnsafe),
|
||||
}
|
||||
src := shaderStrFragment
|
||||
for k, v := range replaces {
|
||||
@ -79,22 +79,22 @@ func fragmentShaderStr(useColorM bool, filter driver.Filter, address driver.Addr
|
||||
}
|
||||
|
||||
switch filter {
|
||||
case driver.FilterNearest:
|
||||
case graphicsdriver.FilterNearest:
|
||||
defs = append(defs, "#define FILTER_NEAREST")
|
||||
case driver.FilterLinear:
|
||||
case graphicsdriver.FilterLinear:
|
||||
defs = append(defs, "#define FILTER_LINEAR")
|
||||
case driver.FilterScreen:
|
||||
case graphicsdriver.FilterScreen:
|
||||
defs = append(defs, "#define FILTER_SCREEN")
|
||||
default:
|
||||
panic(fmt.Sprintf("opengl: invalid filter: %d", filter))
|
||||
}
|
||||
|
||||
switch address {
|
||||
case driver.AddressClampToZero:
|
||||
case graphicsdriver.AddressClampToZero:
|
||||
defs = append(defs, "#define ADDRESS_CLAMP_TO_ZERO")
|
||||
case driver.AddressRepeat:
|
||||
case graphicsdriver.AddressRepeat:
|
||||
defs = append(defs, "#define ADDRESS_REPEAT")
|
||||
case driver.AddressUnsafe:
|
||||
case graphicsdriver.AddressUnsafe:
|
||||
defs = append(defs, "#define ADDRESS_UNSAFE")
|
||||
default:
|
||||
panic(fmt.Sprintf("opengl: invalid address: %d", address))
|
||||
|
@ -17,8 +17,8 @@ package opengl
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
@ -37,11 +37,11 @@ type Graphics struct {
|
||||
state openGLState
|
||||
context context
|
||||
|
||||
nextImageID driver.ImageID
|
||||
images map[driver.ImageID]*Image
|
||||
nextImageID graphicsdriver.ImageID
|
||||
images map[graphicsdriver.ImageID]*Image
|
||||
|
||||
nextShaderID driver.ShaderID
|
||||
shaders map[driver.ShaderID]*Shader
|
||||
nextShaderID graphicsdriver.ShaderID
|
||||
shaders map[graphicsdriver.ShaderID]*Shader
|
||||
|
||||
// drawCalled is true just after Draw is called. This holds true until ReplacePixels is called.
|
||||
drawCalled bool
|
||||
@ -86,17 +86,17 @@ func (g *Graphics) checkSize(width, height int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Graphics) genNextImageID() driver.ImageID {
|
||||
func (g *Graphics) genNextImageID() graphicsdriver.ImageID {
|
||||
g.nextImageID++
|
||||
return g.nextImageID
|
||||
}
|
||||
|
||||
func (g *Graphics) genNextShaderID() driver.ShaderID {
|
||||
func (g *Graphics) genNextShaderID() graphicsdriver.ShaderID {
|
||||
g.nextShaderID++
|
||||
return g.nextShaderID
|
||||
}
|
||||
|
||||
func (g *Graphics) NewImage(width, height int) (driver.Image, error) {
|
||||
func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
|
||||
i := &Image{
|
||||
id: g.genNextImageID(),
|
||||
graphics: g,
|
||||
@ -115,7 +115,7 @@ func (g *Graphics) NewImage(width, height int) (driver.Image, error) {
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (g *Graphics) NewScreenFramebufferImage(width, height int) (driver.Image, error) {
|
||||
func (g *Graphics) NewScreenFramebufferImage(width, height int) (graphicsdriver.Image, error) {
|
||||
g.checkSize(width, height)
|
||||
i := &Image{
|
||||
id: g.genNextImageID(),
|
||||
@ -130,7 +130,7 @@ func (g *Graphics) NewScreenFramebufferImage(width, height int) (driver.Image, e
|
||||
|
||||
func (g *Graphics) addImage(img *Image) {
|
||||
if g.images == nil {
|
||||
g.images = map[driver.ImageID]*Image{}
|
||||
g.images = map[graphicsdriver.ImageID]*Image{}
|
||||
}
|
||||
if _, ok := g.images[img.id]; ok {
|
||||
panic(fmt.Sprintf("opengl: image ID %d was already registered", img.id))
|
||||
@ -171,7 +171,7 @@ func (g *Graphics) uniformVariableName(idx int) string {
|
||||
return name
|
||||
}
|
||||
|
||||
func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM driver.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, uniforms []driver.Uniform, evenOdd bool) error {
|
||||
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.ShaderImageNum]graphicsdriver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms []graphicsdriver.Uniform, evenOdd bool) error {
|
||||
destination := g.images[dstID]
|
||||
|
||||
g.drawCalled = true
|
||||
@ -188,7 +188,7 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
g.context.blendFunc(mode)
|
||||
|
||||
var program program
|
||||
if shaderID == driver.InvalidShaderID {
|
||||
if shaderID == graphicsdriver.InvalidShaderID {
|
||||
program = g.state.programs[programKey{
|
||||
useColorM: !colorM.IsIdentity(),
|
||||
filter: filter,
|
||||
@ -198,13 +198,13 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
dw, dh := destination.framebufferSize()
|
||||
g.uniformVars = append(g.uniformVars, uniformVariable{
|
||||
name: "viewport_size",
|
||||
value: driver.Uniform{
|
||||
value: graphicsdriver.Uniform{
|
||||
Float32s: []float32{float32(dw), float32(dh)},
|
||||
},
|
||||
typ: shaderir.Type{Main: shaderir.Vec2},
|
||||
}, uniformVariable{
|
||||
name: "source_region",
|
||||
value: driver.Uniform{
|
||||
value: graphicsdriver.Uniform{
|
||||
Float32s: []float32{
|
||||
srcRegion.X,
|
||||
srcRegion.Y,
|
||||
@ -222,35 +222,35 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
colorM.Elements(&esBody, &esTranslate)
|
||||
g.uniformVars = append(g.uniformVars, uniformVariable{
|
||||
name: "color_matrix_body",
|
||||
value: driver.Uniform{
|
||||
value: graphicsdriver.Uniform{
|
||||
Float32s: esBody[:],
|
||||
},
|
||||
typ: shaderir.Type{Main: shaderir.Mat4},
|
||||
}, uniformVariable{
|
||||
name: "color_matrix_translation",
|
||||
value: driver.Uniform{
|
||||
value: graphicsdriver.Uniform{
|
||||
Float32s: esTranslate[:],
|
||||
},
|
||||
typ: shaderir.Type{Main: shaderir.Vec4},
|
||||
})
|
||||
}
|
||||
|
||||
if filter != driver.FilterNearest {
|
||||
if filter != graphicsdriver.FilterNearest {
|
||||
sw, sh := g.images[srcIDs[0]].framebufferSize()
|
||||
g.uniformVars = append(g.uniformVars, uniformVariable{
|
||||
name: "source_size",
|
||||
value: driver.Uniform{
|
||||
value: graphicsdriver.Uniform{
|
||||
Float32s: []float32{float32(sw), float32(sh)},
|
||||
},
|
||||
typ: shaderir.Type{Main: shaderir.Vec2},
|
||||
})
|
||||
}
|
||||
|
||||
if filter == driver.FilterScreen {
|
||||
if filter == graphicsdriver.FilterScreen {
|
||||
scale := float32(destination.width) / float32(g.images[srcIDs[0]].width)
|
||||
g.uniformVars = append(g.uniformVars, uniformVariable{
|
||||
name: "scale",
|
||||
value: driver.Uniform{
|
||||
value: graphicsdriver.Uniform{
|
||||
Float32: scale,
|
||||
},
|
||||
typ: shaderir.Type{Main: shaderir.Float},
|
||||
@ -340,7 +340,7 @@ func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderIm
|
||||
|
||||
var imgs [graphics.ShaderImageNum]textureVariable
|
||||
for i, srcID := range srcIDs {
|
||||
if srcID == driver.InvalidImageID {
|
||||
if srcID == graphicsdriver.InvalidImageID {
|
||||
continue
|
||||
}
|
||||
imgs[i].valid = true
|
||||
@ -381,8 +381,8 @@ func (g *Graphics) SetFullscreen(fullscreen bool) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
func (g *Graphics) FramebufferYDirection() driver.YDirection {
|
||||
return driver.Upward
|
||||
func (g *Graphics) FramebufferYDirection() graphicsdriver.YDirection {
|
||||
return graphicsdriver.Upward
|
||||
}
|
||||
|
||||
func (g *Graphics) NeedsRestoring() bool {
|
||||
@ -405,7 +405,7 @@ func (g *Graphics) MaxImageSize() int {
|
||||
return g.context.getMaxTextureSize()
|
||||
}
|
||||
|
||||
func (g *Graphics) NewShader(program *shaderir.Program) (driver.Shader, error) {
|
||||
func (g *Graphics) NewShader(program *shaderir.Program) (graphicsdriver.Shader, error) {
|
||||
s, err := newShader(g.genNextShaderID(), g, program)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -416,7 +416,7 @@ func (g *Graphics) NewShader(program *shaderir.Program) (driver.Shader, error) {
|
||||
|
||||
func (g *Graphics) addShader(shader *Shader) {
|
||||
if g.shaders == nil {
|
||||
g.shaders = map[driver.ShaderID]*Shader{}
|
||||
g.shaders = map[graphicsdriver.ShaderID]*Shader{}
|
||||
}
|
||||
if _, ok := g.shaders[shader.id]; ok {
|
||||
panic(fmt.Sprintf("opengl: shader ID %d was already registered", shader.id))
|
||||
|
@ -15,12 +15,12 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
id driver.ImageID
|
||||
id graphicsdriver.ImageID
|
||||
graphics *Graphics
|
||||
texture textureNative
|
||||
stencil renderbufferNative
|
||||
@ -30,7 +30,7 @@ type Image struct {
|
||||
screen bool
|
||||
}
|
||||
|
||||
func (i *Image) ID() driver.ImageID {
|
||||
func (i *Image) ID() graphicsdriver.ImageID {
|
||||
return i.id
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ func (i *Image) ensureStencilBuffer() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
||||
func (i *Image) ReplacePixels(args []*graphicsdriver.ReplacePixelsArgs) {
|
||||
if i.screen {
|
||||
panic("opengl: ReplacePixels cannot be called on the screen, that doesn't have a texture")
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
@ -116,8 +116,8 @@ func init() {
|
||||
|
||||
type programKey struct {
|
||||
useColorM bool
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
filter graphicsdriver.Filter
|
||||
address graphicsdriver.Address
|
||||
}
|
||||
|
||||
// openGLState is a state for
|
||||
@ -132,7 +132,7 @@ type openGLState struct {
|
||||
programs map[programKey]program
|
||||
|
||||
lastProgram program
|
||||
lastUniforms map[string]driver.Uniform
|
||||
lastUniforms map[string]graphicsdriver.Uniform
|
||||
lastActiveTexture int
|
||||
}
|
||||
|
||||
@ -183,15 +183,15 @@ func (s *openGLState) reset(context *context) error {
|
||||
defer context.deleteShader(shaderVertexModelviewNative)
|
||||
|
||||
for _, c := range []bool{false, true} {
|
||||
for _, a := range []driver.Address{
|
||||
driver.AddressClampToZero,
|
||||
driver.AddressRepeat,
|
||||
driver.AddressUnsafe,
|
||||
for _, a := range []graphicsdriver.Address{
|
||||
graphicsdriver.AddressClampToZero,
|
||||
graphicsdriver.AddressRepeat,
|
||||
graphicsdriver.AddressUnsafe,
|
||||
} {
|
||||
for _, f := range []driver.Filter{
|
||||
driver.FilterNearest,
|
||||
driver.FilterLinear,
|
||||
driver.FilterScreen,
|
||||
for _, f := range []graphicsdriver.Filter{
|
||||
graphicsdriver.FilterNearest,
|
||||
graphicsdriver.FilterLinear,
|
||||
graphicsdriver.FilterScreen,
|
||||
} {
|
||||
shaderFragmentColorMatrixNative, err := context.newFragmentShader(fragmentShaderStr(c, f, a))
|
||||
if err != nil {
|
||||
@ -242,7 +242,7 @@ func areSameFloat32Array(a, b []float32) bool {
|
||||
|
||||
type uniformVariable struct {
|
||||
name string
|
||||
value driver.Uniform
|
||||
value graphicsdriver.Uniform
|
||||
typ shaderir.Type
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textu
|
||||
// TODO: Remember whether the location is available or not.
|
||||
g.context.uniformFloat(program, u.name, u.value.Float32)
|
||||
if g.state.lastUniforms == nil {
|
||||
g.state.lastUniforms = map[string]driver.Uniform{}
|
||||
g.state.lastUniforms = map[string]graphicsdriver.Uniform{}
|
||||
}
|
||||
g.state.lastUniforms[u.name] = u.value
|
||||
} else {
|
||||
@ -313,7 +313,7 @@ func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textu
|
||||
}
|
||||
g.context.uniformFloats(program, u.name, u.value.Float32s, u.typ)
|
||||
if g.state.lastUniforms == nil {
|
||||
g.state.lastUniforms = map[string]driver.Uniform{}
|
||||
g.state.lastUniforms = map[string]graphicsdriver.Uniform{}
|
||||
}
|
||||
g.state.lastUniforms[u.name] = u.value
|
||||
}
|
||||
|
@ -17,20 +17,20 @@ package opengl
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/glsl"
|
||||
)
|
||||
|
||||
type Shader struct {
|
||||
id driver.ShaderID
|
||||
id graphicsdriver.ShaderID
|
||||
graphics *Graphics
|
||||
|
||||
ir *shaderir.Program
|
||||
p program
|
||||
}
|
||||
|
||||
func newShader(id driver.ShaderID, graphics *Graphics, program *shaderir.Program) (*Shader, error) {
|
||||
func newShader(id graphicsdriver.ShaderID, graphics *Graphics, program *shaderir.Program) (*Shader, error) {
|
||||
s := &Shader{
|
||||
id: id,
|
||||
graphics: graphics,
|
||||
@ -42,7 +42,7 @@ func newShader(id driver.ShaderID, graphics *Graphics, program *shaderir.Program
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Shader) ID() driver.ShaderID {
|
||||
func (s *Shader) ID() graphicsdriver.ShaderID {
|
||||
return s.id
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/buffered"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
@ -87,14 +87,14 @@ func (m *Mipmap) Pixels(x, y, width, height int) ([]byte, error) {
|
||||
return m.orig.Pixels(x, y, width, height)
|
||||
}
|
||||
|
||||
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageNum]*Mipmap, vertices []float32, indices []uint16, colorm affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []driver.Uniform, evenOdd bool, canSkipMipmap bool) {
|
||||
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageNum]*Mipmap, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool, canSkipMipmap bool) {
|
||||
if len(indices) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
level := 0
|
||||
// TODO: Do we need to check all the sources' states of being volatile?
|
||||
if !canSkipMipmap && srcs[0] != nil && !srcs[0].volatile && filter != driver.FilterScreen {
|
||||
if !canSkipMipmap && srcs[0] != nil && !srcs[0].volatile && filter != graphicsdriver.FilterScreen {
|
||||
level = math.MaxInt32
|
||||
for i := 0; i < len(indices)/3; i++ {
|
||||
const n = graphics.VertexFloatNum
|
||||
@ -176,12 +176,12 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
||||
|
||||
var src *buffered.Image
|
||||
var vs []float32
|
||||
var filter driver.Filter
|
||||
var filter graphicsdriver.Filter
|
||||
switch {
|
||||
case level == 1:
|
||||
src = m.orig
|
||||
vs = graphics.QuadVertices(0, 0, float32(m.width), float32(m.height), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||
filter = driver.FilterLinear
|
||||
filter = graphicsdriver.FilterLinear
|
||||
case level > 1:
|
||||
src = m.level(level - 1)
|
||||
if src == nil {
|
||||
@ -191,7 +191,7 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
||||
w := sizeForLevel(m.width, level-1)
|
||||
h := sizeForLevel(m.height, level-1)
|
||||
vs = graphics.QuadVertices(0, 0, float32(w), float32(h), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||
filter = driver.FilterLinear
|
||||
filter = graphicsdriver.FilterLinear
|
||||
default:
|
||||
panic(fmt.Sprintf("ebiten: invalid level: %d", level))
|
||||
}
|
||||
@ -213,13 +213,13 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
||||
s := buffered.NewImage(w2, h2)
|
||||
s.SetVolatile(m.volatile)
|
||||
|
||||
dstRegion := driver.Region{
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: float32(w2),
|
||||
Height: float32(h2),
|
||||
}
|
||||
s.DrawTriangles([graphics.ShaderImageNum]*buffered.Image{src}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, filter, driver.AddressUnsafe, dstRegion, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
s.DrawTriangles([graphics.ShaderImageNum]*buffered.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, filter, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
||||
m.setImg(level, s)
|
||||
|
||||
return m.imgs[level]
|
||||
@ -253,10 +253,10 @@ func (m *Mipmap) disposeMipmaps() {
|
||||
}
|
||||
|
||||
// mipmapLevel returns an appropriate mipmap level for the given distance.
|
||||
func mipmapLevelFromDistance(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1 float32, filter driver.Filter) int {
|
||||
func mipmapLevelFromDistance(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1 float32, filter graphicsdriver.Filter) int {
|
||||
const maxLevel = 6
|
||||
|
||||
if filter == driver.FilterScreen {
|
||||
if filter == graphicsdriver.FilterScreen {
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -277,7 +277,7 @@ func mipmapLevelFromDistance(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1 float32, fil
|
||||
return 0
|
||||
}
|
||||
|
||||
if filter != driver.FilterLinear {
|
||||
if filter != graphicsdriver.FilterLinear {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
"image"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
type Pixels struct {
|
||||
@ -70,13 +70,13 @@ type drawTrianglesHistoryItem struct {
|
||||
vertices []float32
|
||||
indices []uint16
|
||||
colorm affine.ColorM
|
||||
mode driver.CompositeMode
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
dstRegion driver.Region
|
||||
srcRegion driver.Region
|
||||
mode graphicsdriver.CompositeMode
|
||||
filter graphicsdriver.Filter
|
||||
address graphicsdriver.Address
|
||||
dstRegion graphicsdriver.Region
|
||||
srcRegion graphicsdriver.Region
|
||||
shader *Shader
|
||||
uniforms []driver.Uniform
|
||||
uniforms []graphicsdriver.Uniform
|
||||
evenOdd bool
|
||||
}
|
||||
|
||||
@ -193,13 +193,13 @@ func (i *Image) Extend(width, height int) *Image {
|
||||
sw, sh := i.image.InternalSize()
|
||||
vs := quadVertices(0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: float32(sw),
|
||||
Height: float32(sh),
|
||||
}
|
||||
newImg.DrawTriangles(srcs, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
newImg.DrawTriangles(srcs, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
|
||||
// Overwrite the history as if the image newImg is created only by ReplacePixels. Now drawTrianglesHistory
|
||||
// and basePixels cannot be mixed.
|
||||
@ -256,13 +256,13 @@ func clearImage(i *graphicscommand.Image) {
|
||||
is := graphics.QuadIndices()
|
||||
srcs := [graphics.ShaderImageNum]*graphicscommand.Image{emptyImage.image}
|
||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
||||
dstRegion := driver.Region{
|
||||
dstRegion := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: float32(dw),
|
||||
Height: float32(dh),
|
||||
}
|
||||
i.DrawTriangles(srcs, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dstRegion, driver.Region{}, nil, nil, false)
|
||||
i.DrawTriangles(srcs, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, nil, nil, false)
|
||||
}
|
||||
|
||||
// BasePixelsForTesting returns the image's basePixels for testing.
|
||||
@ -365,7 +365,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
// 5: Color G
|
||||
// 6: Color B
|
||||
// 7: Color Y
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, shader *Shader, uniforms []driver.Uniform, evenOdd bool) {
|
||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool) {
|
||||
if i.priority {
|
||||
panic("restorable: DrawTriangles cannot be called on a priority image")
|
||||
}
|
||||
@ -410,7 +410,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
|
||||
}
|
||||
|
||||
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
||||
func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, shader *Shader, uniforms []driver.Uniform, evenOdd bool) {
|
||||
func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms []graphicsdriver.Uniform, evenOdd bool) {
|
||||
if i.stale || i.volatile || i.screen {
|
||||
return
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
// forceRestoring reports whether restoring forcely happens or not.
|
||||
@ -112,7 +112,7 @@ func RestoreIfNeeded() error {
|
||||
}
|
||||
|
||||
err := graphicscommand.ResetGraphicsDriverState()
|
||||
if err == driver.GraphicsNotReady {
|
||||
if err == graphicsdriver.GraphicsNotReady {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
t "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||
)
|
||||
@ -132,13 +132,13 @@ func TestRestoreChain(t *testing.T) {
|
||||
for i := 0; i < num-1; i++ {
|
||||
vs := quadVertices(1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
}
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -180,16 +180,16 @@ func TestRestoreChain2(t *testing.T) {
|
||||
imgs[8].ReplacePixels([]byte{clr8.R, clr8.G, clr8.B, clr8.A}, 0, 0, w, h)
|
||||
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
imgs[8].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[7]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
imgs[9].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[8]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
imgs[8].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[7]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
imgs[9].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[8]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
for i := 0; i < 7; i++ {
|
||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
}
|
||||
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
@ -229,16 +229,16 @@ func TestRestoreOverrideSource(t *testing.T) {
|
||||
clr1 := color.RGBA{0x00, 0x00, 0x01, 0xff}
|
||||
img1.ReplacePixels([]byte{clr0.R, clr0.G, clr0.B, clr0.A}, 0, 0, w, h)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
img2.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img2.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
img0.ReplacePixels([]byte{clr1.R, clr1.G, clr1.B, clr1.A}, 0, 0, w, h)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -317,30 +317,30 @@ func TestRestoreComplexGraph(t *testing.T) {
|
||||
}()
|
||||
vs := quadVertices(w, h, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 1, 0)
|
||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 1, 0)
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 2, 0)
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 0, 0)
|
||||
img5.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img5.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 0, 0)
|
||||
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 1, 0)
|
||||
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img4}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img4}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 0, 0)
|
||||
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
vs = quadVertices(w, h, 2, 0)
|
||||
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -432,14 +432,14 @@ func TestRestoreRecursive(t *testing.T) {
|
||||
img0.Dispose()
|
||||
}()
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(w, h, 1, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -533,13 +533,13 @@ func TestDrawTrianglesAndReplacePixels(t *testing.T) {
|
||||
|
||||
vs := quadVertices(1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 2,
|
||||
Height: 1,
|
||||
}
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0, 0, 2, 1)
|
||||
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
@ -576,14 +576,14 @@ func TestDispose(t *testing.T) {
|
||||
defer img2.Dispose()
|
||||
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
img1.Dispose()
|
||||
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
@ -691,13 +691,13 @@ func TestReplacePixelsOnly(t *testing.T) {
|
||||
|
||||
vs := quadVertices(1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
img0.ReplacePixels([]byte{5, 6, 7, 8}, 0, 0, 1, 1)
|
||||
|
||||
// BasePixelsForTesting is available without GPU accessing.
|
||||
@ -751,13 +751,13 @@ func TestReadPixelsFromVolatileImage(t *testing.T) {
|
||||
src.ReplacePixels(pix, 0, 0, w, h)
|
||||
vs := quadVertices(1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
|
||||
// Read the pixels. If the implementation is correct, dst tries to read its pixels from GPU due to being
|
||||
// stale.
|
||||
@ -778,13 +778,13 @@ func TestAllowReplacePixelsAfterDrawTriangles(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w, h, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
||||
// ReplacePixels for a whole image doesn't panic.
|
||||
}
|
||||
@ -802,13 +802,13 @@ func TestDisallowReplacePixelsForPartAfterDrawTriangles(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w, h, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||
}
|
||||
|
||||
@ -879,13 +879,13 @@ func TestMutateSlices(t *testing.T) {
|
||||
vs := quadVertices(w, h, 0, 0)
|
||||
is := make([]uint16, len(graphics.QuadIndices()))
|
||||
copy(is, graphics.QuadIndices())
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: w,
|
||||
Height: h,
|
||||
}
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
for i := range vs {
|
||||
vs[i] = 0
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||
)
|
||||
@ -44,13 +44,13 @@ func clearImage(img *restorable.Image, w, h int) {
|
||||
dx1, dy1, sx1, sy1, 0, 0, 0, 0,
|
||||
}
|
||||
is := graphics.QuadIndices()
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: float32(w),
|
||||
Height: float32(h),
|
||||
}
|
||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{emptyImage}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, driver.CompositeModeClear, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, nil, nil, false)
|
||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{emptyImage}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||
}
|
||||
|
||||
func TestShader(t *testing.T) {
|
||||
@ -59,13 +59,13 @@ func TestShader(t *testing.T) {
|
||||
|
||||
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
||||
s := restorable.NewShader(&ir)
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -95,13 +95,13 @@ func TestShaderChain(t *testing.T) {
|
||||
ir := etesting.ShaderProgramImages(1)
|
||||
s := restorable.NewShader(&ir)
|
||||
for i := 0; i < num-1; i++ {
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||
}
|
||||
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
@ -134,13 +134,13 @@ func TestShaderMultipleSources(t *testing.T) {
|
||||
ir := etesting.ShaderProgramImages(3)
|
||||
s := restorable.NewShader(&ir)
|
||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
dst.DrawTriangles(srcs, offsets, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||
dst.DrawTriangles(srcs, offsets, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||
|
||||
// Clear one of the sources after DrawTriangles. dst should not be affected.
|
||||
clearImage(srcs[0], 1, 1)
|
||||
@ -176,13 +176,13 @@ func TestShaderMultipleSourcesOnOneTexture(t *testing.T) {
|
||||
{1, 0},
|
||||
{2, 0},
|
||||
}
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
dst.DrawTriangles(srcs, offsets, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||
dst.DrawTriangles(srcs, offsets, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||
|
||||
// Clear one of the sources after DrawTriangles. dst should not be affected.
|
||||
clearImage(srcs[0], 3, 1)
|
||||
@ -207,13 +207,13 @@ func TestShaderDispose(t *testing.T) {
|
||||
|
||||
ir := etesting.ShaderProgramFill(0xff, 0, 0, 0xff)
|
||||
s := restorable.NewShader(&ir)
|
||||
dr := driver.Region{
|
||||
dr := graphicsdriver.Region{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
}
|
||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, dr, driver.Region{}, s, nil, false)
|
||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||
|
||||
// Dispose the shader. This should invalidates all the images using this shader i.e., all the images become
|
||||
// stale.
|
||||
|
@ -34,13 +34,13 @@ package ui
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||
)
|
||||
|
||||
var graphics driver.Graphics
|
||||
var graphics graphicsdriver.Graphics
|
||||
|
||||
func supportsMetal() bool {
|
||||
// On old mac devices like iMac 2011, Metal is not supported (#779).
|
||||
@ -64,6 +64,6 @@ func init() {
|
||||
graphics = opengl.Get()
|
||||
}
|
||||
|
||||
func Graphics() driver.Graphics {
|
||||
func Graphics() graphicsdriver.Graphics {
|
||||
return graphics
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ package ui
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
|
||||
)
|
||||
|
||||
func Graphics() driver.Graphics {
|
||||
func Graphics() graphicsdriver.Graphics {
|
||||
if _, err := mtl.CreateSystemDefaultDevice(); err != nil {
|
||||
panic(fmt.Sprintf("mobile: mtl.CreateSystemDefaultDevice failed on iOS: %v", err))
|
||||
}
|
||||
|
@ -18,10 +18,10 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||
)
|
||||
|
||||
func Graphics() driver.Graphics {
|
||||
func Graphics() graphicsdriver.Graphics {
|
||||
return opengl.Get()
|
||||
}
|
||||
|
16
shader.go
16
shader.go
@ -21,8 +21,8 @@ import (
|
||||
"go/token"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/mipmap"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shader"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
@ -173,7 +173,7 @@ func (s *Shader) Dispose() {
|
||||
s.shader = nil
|
||||
}
|
||||
|
||||
func (s *Shader) convertUniforms(uniforms map[string]interface{}) []driver.Uniform {
|
||||
func (s *Shader) convertUniforms(uniforms map[string]interface{}) []graphicsdriver.Uniform {
|
||||
type index struct {
|
||||
resultIndex int
|
||||
shaderUniformIndex int
|
||||
@ -192,16 +192,16 @@ func (s *Shader) convertUniforms(uniforms map[string]interface{}) []driver.Unifo
|
||||
idx++
|
||||
}
|
||||
|
||||
us := make([]driver.Uniform, len(names))
|
||||
us := make([]graphicsdriver.Uniform, len(names))
|
||||
for name, idx := range names {
|
||||
if v, ok := uniforms[name]; ok {
|
||||
switch v := v.(type) {
|
||||
case float32:
|
||||
us[idx.resultIndex] = driver.Uniform{
|
||||
us[idx.resultIndex] = graphicsdriver.Uniform{
|
||||
Float32: v,
|
||||
}
|
||||
case []float32:
|
||||
us[idx.resultIndex] = driver.Uniform{
|
||||
us[idx.resultIndex] = graphicsdriver.Uniform{
|
||||
Float32s: v,
|
||||
}
|
||||
default:
|
||||
@ -219,14 +219,14 @@ func (s *Shader) convertUniforms(uniforms map[string]interface{}) []driver.Unifo
|
||||
return us
|
||||
}
|
||||
|
||||
func zeroUniformValue(name string, t shaderir.Type) driver.Uniform {
|
||||
func zeroUniformValue(name string, t shaderir.Type) graphicsdriver.Uniform {
|
||||
switch t.Main {
|
||||
case shaderir.Float:
|
||||
return driver.Uniform{
|
||||
return graphicsdriver.Uniform{
|
||||
Float32: 0,
|
||||
}
|
||||
case shaderir.Array, shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4:
|
||||
return driver.Uniform{
|
||||
return graphicsdriver.Uniform{
|
||||
Float32s: make([]float32, t.FloatNum()),
|
||||
}
|
||||
default:
|
||||
|
@ -23,8 +23,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/buffered"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/clock"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
@ -209,11 +209,11 @@ func (c *uiContext) updateFrameImpl(updateCount int) error {
|
||||
|
||||
s := c.screenScale(ui.Get().DeviceScaleFactor())
|
||||
switch vd := ui.Graphics().FramebufferYDirection(); vd {
|
||||
case driver.Upward:
|
||||
case graphicsdriver.Upward:
|
||||
op.GeoM.Scale(s, -s)
|
||||
_, h := c.offscreen.Size()
|
||||
op.GeoM.Translate(0, float64(h)*s)
|
||||
case driver.Downward:
|
||||
case graphicsdriver.Downward:
|
||||
op.GeoM.Scale(s, s)
|
||||
default:
|
||||
panic(fmt.Sprintf("ebiten: invalid v-direction: %d", vd))
|
||||
|
Loading…
Reference in New Issue
Block a user