mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Move const definitions to driver package
Let's keep 'graphics' package as a package for utility functions or testable functions as much as possible.
This commit is contained in:
parent
9963ae332e
commit
f40798b586
34
graphics.go
34
graphics.go
@ -15,7 +15,7 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
)
|
||||
|
||||
// Filter represents the type of texture filter to be used when an image is maginified or minified.
|
||||
@ -26,15 +26,15 @@ const (
|
||||
FilterDefault Filter = 0
|
||||
|
||||
// FilterNearest represents nearest (crisp-edged) filter
|
||||
FilterNearest Filter = Filter(graphics.FilterNearest)
|
||||
FilterNearest Filter = Filter(driver.FilterNearest)
|
||||
|
||||
// FilterLinear represents linear filter
|
||||
FilterLinear Filter = Filter(graphics.FilterLinear)
|
||||
FilterLinear Filter = Filter(driver.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(graphics.FilterScreen)
|
||||
filterScreen Filter = Filter(driver.FilterScreen)
|
||||
)
|
||||
|
||||
// CompositeMode represents Porter-Duff composition mode.
|
||||
@ -47,42 +47,42 @@ type CompositeMode int
|
||||
const (
|
||||
// Regular alpha blending
|
||||
// c_out = c_src + c_dst × (1 - α_src)
|
||||
CompositeModeSourceOver CompositeMode = CompositeMode(graphics.CompositeModeSourceOver)
|
||||
CompositeModeSourceOver CompositeMode = CompositeMode(driver.CompositeModeSourceOver)
|
||||
|
||||
// c_out = 0
|
||||
CompositeModeClear CompositeMode = CompositeMode(graphics.CompositeModeClear)
|
||||
CompositeModeClear CompositeMode = CompositeMode(driver.CompositeModeClear)
|
||||
|
||||
// c_out = c_src
|
||||
CompositeModeCopy CompositeMode = CompositeMode(graphics.CompositeModeCopy)
|
||||
CompositeModeCopy CompositeMode = CompositeMode(driver.CompositeModeCopy)
|
||||
|
||||
// c_out = c_dst
|
||||
CompositeModeDestination CompositeMode = CompositeMode(graphics.CompositeModeDestination)
|
||||
CompositeModeDestination CompositeMode = CompositeMode(driver.CompositeModeDestination)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst
|
||||
CompositeModeDestinationOver CompositeMode = CompositeMode(graphics.CompositeModeDestinationOver)
|
||||
CompositeModeDestinationOver CompositeMode = CompositeMode(driver.CompositeModeDestinationOver)
|
||||
|
||||
// c_out = c_src × α_dst
|
||||
CompositeModeSourceIn CompositeMode = CompositeMode(graphics.CompositeModeSourceIn)
|
||||
CompositeModeSourceIn CompositeMode = CompositeMode(driver.CompositeModeSourceIn)
|
||||
|
||||
// c_out = c_dst × α_src
|
||||
CompositeModeDestinationIn CompositeMode = CompositeMode(graphics.CompositeModeDestinationIn)
|
||||
CompositeModeDestinationIn CompositeMode = CompositeMode(driver.CompositeModeDestinationIn)
|
||||
|
||||
// c_out = c_src × (1 - α_dst)
|
||||
CompositeModeSourceOut CompositeMode = CompositeMode(graphics.CompositeModeSourceOut)
|
||||
CompositeModeSourceOut CompositeMode = CompositeMode(driver.CompositeModeSourceOut)
|
||||
|
||||
// c_out = c_dst × (1 - α_src)
|
||||
CompositeModeDestinationOut CompositeMode = CompositeMode(graphics.CompositeModeDestinationOut)
|
||||
CompositeModeDestinationOut CompositeMode = CompositeMode(driver.CompositeModeDestinationOut)
|
||||
|
||||
// c_out = c_src × α_dst + c_dst × (1 - α_src)
|
||||
CompositeModeSourceAtop CompositeMode = CompositeMode(graphics.CompositeModeSourceAtop)
|
||||
CompositeModeSourceAtop CompositeMode = CompositeMode(driver.CompositeModeSourceAtop)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst × α_src
|
||||
CompositeModeDestinationAtop CompositeMode = CompositeMode(graphics.CompositeModeDestinationAtop)
|
||||
CompositeModeDestinationAtop CompositeMode = CompositeMode(driver.CompositeModeDestinationAtop)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src)
|
||||
CompositeModeXor CompositeMode = CompositeMode(graphics.CompositeModeXor)
|
||||
CompositeModeXor CompositeMode = CompositeMode(driver.CompositeModeXor)
|
||||
|
||||
// Sum of source and destination (a.k.a. 'plus' or 'additive')
|
||||
// c_out = c_src + c_dst
|
||||
CompositeModeLighter CompositeMode = CompositeMode(graphics.CompositeModeLighter)
|
||||
CompositeModeLighter CompositeMode = CompositeMode(driver.CompositeModeLighter)
|
||||
)
|
||||
|
31
image.go
31
image.go
@ -21,6 +21,7 @@ import (
|
||||
"math"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/shareable"
|
||||
)
|
||||
@ -80,7 +81,7 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
||||
graphics.PutQuadVertices(vs, src, 0, 0, w, h, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||
}
|
||||
is := graphics.QuadIndices()
|
||||
s.DrawTriangles(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterLinear, graphics.AddressClampToZero)
|
||||
s.DrawTriangles(src, vs, is, nil, driver.CompositeModeCopy, driver.FilterLinear, driver.AddressClampToZero)
|
||||
imgs = append(imgs, s)
|
||||
w = w2
|
||||
h = h2
|
||||
@ -296,19 +297,19 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
}
|
||||
|
||||
geom := &options.GeoM
|
||||
mode := graphics.CompositeMode(options.CompositeMode)
|
||||
mode := driver.CompositeMode(options.CompositeMode)
|
||||
|
||||
filter := graphics.FilterNearest
|
||||
filter := driver.FilterNearest
|
||||
if options.Filter != FilterDefault {
|
||||
filter = graphics.Filter(options.Filter)
|
||||
filter = driver.Filter(options.Filter)
|
||||
} else if img.filter != FilterDefault {
|
||||
filter = graphics.Filter(img.filter)
|
||||
filter = driver.Filter(img.filter)
|
||||
}
|
||||
|
||||
a, b, c, d, tx, ty := geom.elements()
|
||||
|
||||
level := 0
|
||||
if filter == graphics.FilterLinear && !img.mipmap.original().IsVolatile() {
|
||||
if filter == driver.FilterLinear && !img.mipmap.original().IsVolatile() {
|
||||
det := geom.det()
|
||||
if det == 0 {
|
||||
return nil
|
||||
@ -358,7 +359,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
vs := vertexSlice(4)
|
||||
graphics.PutQuadVertices(vs, src, bounds.Min.X, bounds.Min.Y, bounds.Max.X, bounds.Max.Y, a, b, c, d, tx, ty, cr, cg, cb, ca)
|
||||
is := graphics.QuadIndices()
|
||||
i.mipmap.original().DrawTriangles(src, vs, is, colorm, mode, filter, graphics.AddressClampToZero)
|
||||
i.mipmap.original().DrawTriangles(src, vs, is, colorm, mode, filter, driver.AddressClampToZero)
|
||||
} else if src := img.mipmap.level(bounds, level); src != nil {
|
||||
w, h := src.Size()
|
||||
s := 1 << uint(level)
|
||||
@ -369,7 +370,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
vs := vertexSlice(4)
|
||||
graphics.PutQuadVertices(vs, src, 0, 0, w, h, a, b, c, d, tx, ty, cr, cg, cb, ca)
|
||||
is := graphics.QuadIndices()
|
||||
i.mipmap.original().DrawTriangles(src, vs, is, colorm, mode, filter, graphics.AddressClampToZero)
|
||||
i.mipmap.original().DrawTriangles(src, vs, is, colorm, mode, filter, driver.AddressClampToZero)
|
||||
}
|
||||
i.disposeMipmaps()
|
||||
return nil
|
||||
@ -403,10 +404,10 @@ type Address int
|
||||
|
||||
const (
|
||||
// AddressClampToZero means that out-of-range texture coordinates return 0 (transparent).
|
||||
AddressClampToZero Address = Address(graphics.AddressClampToZero)
|
||||
AddressClampToZero Address = Address(driver.AddressClampToZero)
|
||||
|
||||
// AddressRepeat means that texture coordinates wrap to the other side of the texture.
|
||||
AddressRepeat Address = Address(graphics.AddressRepeat)
|
||||
AddressRepeat Address = Address(driver.AddressRepeat)
|
||||
)
|
||||
|
||||
// DrawTrianglesOptions represents options to render triangles on an image.
|
||||
@ -472,13 +473,13 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
options = &DrawTrianglesOptions{}
|
||||
}
|
||||
|
||||
mode := graphics.CompositeMode(options.CompositeMode)
|
||||
mode := driver.CompositeMode(options.CompositeMode)
|
||||
|
||||
filter := graphics.FilterNearest
|
||||
filter := driver.FilterNearest
|
||||
if options.Filter != FilterDefault {
|
||||
filter = graphics.Filter(options.Filter)
|
||||
filter = driver.Filter(options.Filter)
|
||||
} else if img.filter != FilterDefault {
|
||||
filter = graphics.Filter(img.filter)
|
||||
filter = driver.Filter(img.filter)
|
||||
}
|
||||
|
||||
vs := vertexSlice(len(vertices))
|
||||
@ -490,7 +491,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
float32(r.Min.X), float32(r.Min.Y), float32(r.Max.X), float32(r.Max.Y),
|
||||
v.ColorR, v.ColorG, v.ColorB, v.ColorA)
|
||||
}
|
||||
i.mipmap.original().DrawTriangles(img.mipmap.original(), vs, indices, options.ColorM.impl, mode, filter, graphics.Address(options.Address))
|
||||
i.mipmap.original().DrawTriangles(img.mipmap.original(), vs, indices, options.ColorM.impl, mode, filter, driver.Address(options.Address))
|
||||
i.disposeMipmaps()
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphics
|
||||
package driver
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphics
|
||||
package driver
|
||||
|
||||
type Filter int
|
||||
|
@ -16,7 +16,6 @@ package driver
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/thread"
|
||||
)
|
||||
|
||||
@ -30,7 +29,7 @@ type Graphics interface {
|
||||
NewImage(width, height int) (Image, error)
|
||||
NewScreenFramebufferImage(width, height int) (Image, error)
|
||||
Reset() error
|
||||
Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter, address graphics.Address) error
|
||||
Draw(indexLen int, indexOffset int, mode CompositeMode, colorM *affine.ColorM, filter Filter, address Address) error
|
||||
SetVsyncEnabled(enabled bool)
|
||||
VDirection() VDirection
|
||||
NeedsRestoring() bool
|
||||
|
@ -51,7 +51,7 @@ type command interface {
|
||||
NumIndices() int
|
||||
AddNumVertices(n int)
|
||||
AddNumIndices(n int)
|
||||
CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool
|
||||
CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool
|
||||
}
|
||||
|
||||
type size struct {
|
||||
@ -116,7 +116,7 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) {
|
||||
q.nindices += len(indices)
|
||||
}
|
||||
|
||||
func (q *commandQueue) doEnqueueDrawTrianglesCommand(dst, src *Image, nvertices, nindices int, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address, forceNewCommand bool) {
|
||||
func (q *commandQueue) doEnqueueDrawTrianglesCommand(dst, src *Image, nvertices, nindices int, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, forceNewCommand bool) {
|
||||
if nindices > graphics.IndicesNum {
|
||||
panic(fmt.Sprintf("graphicscommand: nindices must be <= graphics.IndicesNum but not at doEnqueueDrawTrianglesCommand: nindices: %d, graphics.IndicesNum: %d", nindices, graphics.IndicesNum))
|
||||
}
|
||||
@ -141,7 +141,7 @@ func (q *commandQueue) doEnqueueDrawTrianglesCommand(dst, src *Image, nvertices,
|
||||
}
|
||||
|
||||
// EnqueueDrawTrianglesCommand enqueues a drawing-image command.
|
||||
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []float32, indices []uint16, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) {
|
||||
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []float32, indices []uint16, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||
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))
|
||||
}
|
||||
@ -259,9 +259,9 @@ type drawTrianglesCommand struct {
|
||||
nvertices int
|
||||
nindices int
|
||||
color *affine.ColorM
|
||||
mode graphics.CompositeMode
|
||||
filter graphics.Filter
|
||||
address graphics.Address
|
||||
mode driver.CompositeMode
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
}
|
||||
|
||||
func (c *drawTrianglesCommand) String() string {
|
||||
@ -301,7 +301,7 @@ func (c *drawTrianglesCommand) AddNumIndices(n int) {
|
||||
|
||||
// CanMerge returns a boolean value indicating whether the other drawTrianglesCommand can be merged
|
||||
// with the drawTrianglesCommand c.
|
||||
func (c *drawTrianglesCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool {
|
||||
func (c *drawTrianglesCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool {
|
||||
if c.dst != dst {
|
||||
return false
|
||||
}
|
||||
@ -357,7 +357,7 @@ func (c *replacePixelsCommand) AddNumVertices(n int) {
|
||||
func (c *replacePixelsCommand) AddNumIndices(n int) {
|
||||
}
|
||||
|
||||
func (c *replacePixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool {
|
||||
func (c *replacePixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -396,7 +396,7 @@ func (c *copyPixelsCommand) AddNumVertices(n int) {
|
||||
func (c *copyPixelsCommand) AddNumIndices(n int) {
|
||||
}
|
||||
|
||||
func (c *copyPixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool {
|
||||
func (c *copyPixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -433,7 +433,7 @@ func (c *pixelsCommand) AddNumVertices(n int) {
|
||||
func (c *pixelsCommand) AddNumIndices(n int) {
|
||||
}
|
||||
|
||||
func (c *pixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool {
|
||||
func (c *pixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -466,7 +466,7 @@ func (c *disposeCommand) AddNumVertices(n int) {
|
||||
func (c *disposeCommand) AddNumIndices(n int) {
|
||||
}
|
||||
|
||||
func (c *disposeCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool {
|
||||
func (c *disposeCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ func (c *newImageCommand) AddNumVertices(n int) {
|
||||
func (c *newImageCommand) AddNumIndices(n int) {
|
||||
}
|
||||
|
||||
func (c *newImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool {
|
||||
func (c *newImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -541,7 +541,7 @@ func (c *newScreenFramebufferImageCommand) AddNumVertices(n int) {
|
||||
func (c *newScreenFramebufferImageCommand) AddNumIndices(n int) {
|
||||
}
|
||||
|
||||
func (c *newScreenFramebufferImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) bool {
|
||||
func (c *newScreenFramebufferImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -92,13 +92,13 @@ func (i *Image) InternalSize() (int, int) {
|
||||
return i.internalWidth, i.internalHeight
|
||||
}
|
||||
|
||||
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) {
|
||||
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||
if src.screen {
|
||||
panic("graphicscommand: the screen image cannot be the rendering source")
|
||||
}
|
||||
|
||||
if i.lastCommand == lastCommandNone {
|
||||
if !i.screen && mode != graphics.CompositeModeClear {
|
||||
if !i.screen && mode != driver.CompositeModeClear {
|
||||
panic("graphicscommand: the image must be cleared first")
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
. "github.com/hajimehoshi/ebiten/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
@ -71,7 +72,7 @@ func TestClear(t *testing.T) {
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, &testVertexPutter{w / 2, h / 2}, 0, 0, w/2, h/2, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(src, vs, is, nil, graphics.CompositeModeClear, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero)
|
||||
|
||||
pix := dst.Pixels()
|
||||
for j := 0; j < h/2; j++ {
|
||||
@ -99,7 +100,7 @@ func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, &testVertexPutter{w / 2, h / 2}, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(clr, vs, is, nil, graphics.CompositeModeClear, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
dst.DrawTriangles(clr, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||
}
|
||||
|
@ -277,9 +277,9 @@ FragmentShaderFunc(0, FILTER_SCREEN, ADDRESS_CLAMP_TO_ZERO)
|
||||
|
||||
type rpsKey struct {
|
||||
useColorM bool
|
||||
filter graphics.Filter
|
||||
address graphics.Address
|
||||
compositeMode graphics.CompositeMode
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
compositeMode driver.CompositeMode
|
||||
}
|
||||
|
||||
type Driver struct {
|
||||
@ -485,11 +485,11 @@ func (d *Driver) Reset() error {
|
||||
}
|
||||
|
||||
replaces := map[string]string{
|
||||
"{{.FilterNearest}}": fmt.Sprintf("%d", graphics.FilterNearest),
|
||||
"{{.FilterLinear}}": fmt.Sprintf("%d", graphics.FilterLinear),
|
||||
"{{.FilterScreen}}": fmt.Sprintf("%d", graphics.FilterScreen),
|
||||
"{{.AddressClampToZero}}": fmt.Sprintf("%d", graphics.AddressClampToZero),
|
||||
"{{.AddressRepeat}}": fmt.Sprintf("%d", graphics.AddressRepeat),
|
||||
"{{.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),
|
||||
}
|
||||
src := source
|
||||
for k, v := range replaces {
|
||||
@ -505,7 +505,7 @@ func (d *Driver) Reset() error {
|
||||
return err
|
||||
}
|
||||
fs, err := lib.MakeFunction(
|
||||
fmt.Sprintf("FragmentShader_%d_%d_%d", 0, graphics.FilterScreen, graphics.AddressClampToZero))
|
||||
fmt.Sprintf("FragmentShader_%d_%d_%d", 0, driver.FilterScreen, driver.AddressClampToZero))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -525,19 +525,19 @@ func (d *Driver) Reset() error {
|
||||
}
|
||||
d.screenRPS = rps
|
||||
|
||||
conv := func(c graphics.Operation) mtl.BlendFactor {
|
||||
conv := func(c driver.Operation) mtl.BlendFactor {
|
||||
switch c {
|
||||
case graphics.Zero:
|
||||
case driver.Zero:
|
||||
return mtl.BlendFactorZero
|
||||
case graphics.One:
|
||||
case driver.One:
|
||||
return mtl.BlendFactorOne
|
||||
case graphics.SrcAlpha:
|
||||
case driver.SrcAlpha:
|
||||
return mtl.BlendFactorSourceAlpha
|
||||
case graphics.DstAlpha:
|
||||
case driver.DstAlpha:
|
||||
return mtl.BlendFactorDestinationAlpha
|
||||
case graphics.OneMinusSrcAlpha:
|
||||
case driver.OneMinusSrcAlpha:
|
||||
return mtl.BlendFactorOneMinusSourceAlpha
|
||||
case graphics.OneMinusDstAlpha:
|
||||
case driver.OneMinusDstAlpha:
|
||||
return mtl.BlendFactorOneMinusDestinationAlpha
|
||||
default:
|
||||
panic(fmt.Sprintf("metal: invalid operation: %d", c))
|
||||
@ -545,15 +545,15 @@ func (d *Driver) Reset() error {
|
||||
}
|
||||
|
||||
for _, cm := range []bool{false, true} {
|
||||
for _, a := range []graphics.Address{
|
||||
graphics.AddressClampToZero,
|
||||
graphics.AddressRepeat,
|
||||
for _, a := range []driver.Address{
|
||||
driver.AddressClampToZero,
|
||||
driver.AddressRepeat,
|
||||
} {
|
||||
for _, f := range []graphics.Filter{
|
||||
graphics.FilterNearest,
|
||||
graphics.FilterLinear,
|
||||
for _, f := range []driver.Filter{
|
||||
driver.FilterNearest,
|
||||
driver.FilterLinear,
|
||||
} {
|
||||
for c := graphics.CompositeModeSourceOver; c <= graphics.CompositeModeMax; c++ {
|
||||
for c := driver.CompositeModeSourceOver; c <= driver.CompositeModeMax; c++ {
|
||||
cmi := 0
|
||||
if cm {
|
||||
cmi = 1
|
||||
@ -598,7 +598,7 @@ func (d *Driver) Reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter, address graphics.Address) error {
|
||||
func (d *Driver) Draw(indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address) error {
|
||||
if err := d.t.Call(func() error {
|
||||
d.view.update()
|
||||
|
||||
@ -633,7 +633,7 @@ func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode
|
||||
}
|
||||
rce := d.cb.MakeRenderCommandEncoder(rpd)
|
||||
|
||||
if d.dst.screen && filter == graphics.FilterScreen {
|
||||
if d.dst.screen && filter == driver.FilterScreen {
|
||||
rce.SetRenderPipelineState(d.screenRPS)
|
||||
} else {
|
||||
rce.SetRenderPipelineState(d.rpss[rpsKey{
|
||||
|
@ -18,23 +18,23 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/thread"
|
||||
)
|
||||
|
||||
func convertOperation(op graphics.Operation) operation {
|
||||
func convertOperation(op driver.Operation) operation {
|
||||
switch op {
|
||||
case graphics.Zero:
|
||||
case driver.Zero:
|
||||
return zero
|
||||
case graphics.One:
|
||||
case driver.One:
|
||||
return one
|
||||
case graphics.SrcAlpha:
|
||||
case driver.SrcAlpha:
|
||||
return srcAlpha
|
||||
case graphics.DstAlpha:
|
||||
case driver.DstAlpha:
|
||||
return dstAlpha
|
||||
case graphics.OneMinusSrcAlpha:
|
||||
case driver.OneMinusSrcAlpha:
|
||||
return oneMinusSrcAlpha
|
||||
case graphics.OneMinusDstAlpha:
|
||||
case driver.OneMinusDstAlpha:
|
||||
return oneMinusDstAlpha
|
||||
default:
|
||||
panic(fmt.Sprintf("opengl: invalid operation %d at convertOperation", op))
|
||||
@ -48,7 +48,7 @@ type context struct {
|
||||
lastTexture textureNative
|
||||
lastViewportWidth int
|
||||
lastViewportHeight int
|
||||
lastCompositeMode graphics.CompositeMode
|
||||
lastCompositeMode driver.CompositeMode
|
||||
maxTextureSize int
|
||||
highp bool
|
||||
highpOnce sync.Once
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl/gl"
|
||||
)
|
||||
|
||||
@ -93,12 +93,12 @@ func (c *context) reset() error {
|
||||
c.lastFramebuffer = invalidFramebuffer
|
||||
c.lastViewportWidth = 0
|
||||
c.lastViewportHeight = 0
|
||||
c.lastCompositeMode = graphics.CompositeModeUnknown
|
||||
c.lastCompositeMode = driver.CompositeModeUnknown
|
||||
_ = c.t.Call(func() error {
|
||||
gl.Enable(gl.BLEND)
|
||||
return nil
|
||||
})
|
||||
c.blendFunc(graphics.CompositeModeSourceOver)
|
||||
c.blendFunc(driver.CompositeModeSourceOver)
|
||||
_ = c.t.Call(func() error {
|
||||
f := int32(0)
|
||||
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
|
||||
@ -108,7 +108,7 @@ func (c *context) reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) blendFunc(mode graphics.CompositeMode) {
|
||||
func (c *context) blendFunc(mode driver.CompositeMode) {
|
||||
_ = c.t.Call(func() error {
|
||||
if c.lastCompositeMode == mode {
|
||||
return nil
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"fmt"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/jsutil"
|
||||
"github.com/hajimehoshi/ebiten/internal/web"
|
||||
)
|
||||
@ -125,7 +125,7 @@ func (c *context) reset() error {
|
||||
c.lastFramebuffer = framebufferNative(js.Null())
|
||||
c.lastViewportWidth = 0
|
||||
c.lastViewportHeight = 0
|
||||
c.lastCompositeMode = graphics.CompositeModeUnknown
|
||||
c.lastCompositeMode = driver.CompositeModeUnknown
|
||||
|
||||
c.gl = js.Value{}
|
||||
c.ensureGL()
|
||||
@ -134,13 +134,13 @@ func (c *context) reset() error {
|
||||
}
|
||||
gl := c.gl
|
||||
gl.Call("enable", blend)
|
||||
c.blendFunc(graphics.CompositeModeSourceOver)
|
||||
c.blendFunc(driver.CompositeModeSourceOver)
|
||||
f := gl.Call("getParameter", framebufferBinding)
|
||||
c.screenFramebuffer = framebufferNative(f)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) blendFunc(mode graphics.CompositeMode) {
|
||||
func (c *context) blendFunc(mode driver.CompositeMode) {
|
||||
if c.lastCompositeMode == mode {
|
||||
return
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
|
||||
mgl "golang.org/x/mobile/gl"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -100,16 +100,16 @@ func (c *context) reset() error {
|
||||
c.lastFramebuffer = invalidFramebuffer
|
||||
c.lastViewportWidth = 0
|
||||
c.lastViewportHeight = 0
|
||||
c.lastCompositeMode = graphics.CompositeModeUnknown
|
||||
c.lastCompositeMode = driver.CompositeModeUnknown
|
||||
c.gl.Enable(mgl.BLEND)
|
||||
c.blendFunc(graphics.CompositeModeSourceOver)
|
||||
c.blendFunc(driver.CompositeModeSourceOver)
|
||||
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
||||
c.screenFramebuffer = framebufferNative(mgl.Framebuffer{uint32(f)})
|
||||
// TODO: Need to update screenFramebufferWidth/Height?
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) blendFunc(mode graphics.CompositeMode) {
|
||||
func (c *context) blendFunc(mode driver.CompositeMode) {
|
||||
gl := c.gl
|
||||
if c.lastCompositeMode == mode {
|
||||
return
|
||||
|
@ -107,7 +107,7 @@ func (d *Driver) SetVertices(vertices []float32, indices []uint16) {
|
||||
d.context.elementArrayBufferSubData(indices)
|
||||
}
|
||||
|
||||
func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter, address graphics.Address) error {
|
||||
func (d *Driver) Draw(indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address) error {
|
||||
if err := d.useProgram(mode, colorM, filter, address); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/web"
|
||||
)
|
||||
@ -117,8 +118,8 @@ func init() {
|
||||
|
||||
type programKey struct {
|
||||
useColorM bool
|
||||
filter graphics.Filter
|
||||
address graphics.Address
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
}
|
||||
|
||||
// openGLState is a state for
|
||||
@ -139,8 +140,8 @@ type openGLState struct {
|
||||
lastColorMatrixTranslation []float32
|
||||
lastSourceWidth int
|
||||
lastSourceHeight int
|
||||
lastFilter *graphics.Filter
|
||||
lastAddress *graphics.Address
|
||||
lastFilter *driver.Filter
|
||||
lastAddress *driver.Address
|
||||
|
||||
source *Image
|
||||
destination *Image
|
||||
@ -197,14 +198,14 @@ func (s *openGLState) reset(context *context) error {
|
||||
defer context.deleteShader(shaderVertexModelviewNative)
|
||||
|
||||
for _, c := range []bool{false, true} {
|
||||
for _, a := range []graphics.Address{
|
||||
graphics.AddressClampToZero,
|
||||
graphics.AddressRepeat,
|
||||
for _, a := range []driver.Address{
|
||||
driver.AddressClampToZero,
|
||||
driver.AddressRepeat,
|
||||
} {
|
||||
for _, f := range []graphics.Filter{
|
||||
graphics.FilterNearest,
|
||||
graphics.FilterLinear,
|
||||
graphics.FilterScreen,
|
||||
for _, f := range []driver.Filter{
|
||||
driver.FilterNearest,
|
||||
driver.FilterLinear,
|
||||
driver.FilterScreen,
|
||||
} {
|
||||
shaderFragmentColorMatrixNative, err := context.newShader(fragmentShader, fragmentShaderStr(c, f, a))
|
||||
if err != nil {
|
||||
@ -254,7 +255,7 @@ func areSameFloat32Array(a, b []float32) bool {
|
||||
}
|
||||
|
||||
// useProgram uses the program (programTexture).
|
||||
func (d *Driver) useProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter, address graphics.Address) error {
|
||||
func (d *Driver) useProgram(mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address) error {
|
||||
destination := d.state.destination
|
||||
if destination == nil {
|
||||
panic("destination image is not set")
|
||||
@ -317,7 +318,7 @@ func (d *Driver) useProgram(mode graphics.CompositeMode, colorM *affine.ColorM,
|
||||
}
|
||||
}
|
||||
|
||||
if filter != graphics.FilterNearest {
|
||||
if filter != driver.FilterNearest {
|
||||
sw := graphics.InternalImageSize(srcW)
|
||||
sh := graphics.InternalImageSize(srcH)
|
||||
if d.state.lastSourceWidth != sw || d.state.lastSourceHeight != sh {
|
||||
@ -327,7 +328,7 @@ func (d *Driver) useProgram(mode graphics.CompositeMode, colorM *affine.ColorM,
|
||||
}
|
||||
}
|
||||
|
||||
if filter == graphics.FilterScreen {
|
||||
if filter == driver.FilterScreen {
|
||||
scale := float32(dstW) / float32(srcW)
|
||||
d.context.uniformFloat(program, "scale", scale)
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
)
|
||||
|
||||
// glslReservedKeywords is a set of reserved keywords that cannot be used as an indentifier on some environments.
|
||||
@ -61,10 +61,10 @@ func vertexShaderStr() string {
|
||||
return src
|
||||
}
|
||||
|
||||
func fragmentShaderStr(useColorM bool, filter graphics.Filter, address graphics.Address) string {
|
||||
func fragmentShaderStr(useColorM bool, filter driver.Filter, address driver.Address) string {
|
||||
replaces := map[string]string{
|
||||
"{{.AddressClampToZero}}": fmt.Sprintf("%d", graphics.AddressClampToZero),
|
||||
"{{.AddressRepeat}}": fmt.Sprintf("%d", graphics.AddressRepeat),
|
||||
"{{.AddressClampToZero}}": fmt.Sprintf("%d", driver.AddressClampToZero),
|
||||
"{{.AddressRepeat}}": fmt.Sprintf("%d", driver.AddressRepeat),
|
||||
}
|
||||
src := shaderStrFragment
|
||||
for k, v := range replaces {
|
||||
@ -78,20 +78,20 @@ func fragmentShaderStr(useColorM bool, filter graphics.Filter, address graphics.
|
||||
}
|
||||
|
||||
switch filter {
|
||||
case graphics.FilterNearest:
|
||||
case driver.FilterNearest:
|
||||
defs = append(defs, "#define FILTER_NEAREST")
|
||||
case graphics.FilterLinear:
|
||||
case driver.FilterLinear:
|
||||
defs = append(defs, "#define FILTER_LINEAR")
|
||||
case graphics.FilterScreen:
|
||||
case driver.FilterScreen:
|
||||
defs = append(defs, "#define FILTER_SCREEN")
|
||||
default:
|
||||
panic(fmt.Sprintf("opengl: invalid filter: %d", filter))
|
||||
}
|
||||
|
||||
switch address {
|
||||
case graphics.AddressClampToZero:
|
||||
case driver.AddressClampToZero:
|
||||
defs = append(defs, "#define ADDRESS_CLAMP_TO_ZERO")
|
||||
case graphics.AddressRepeat:
|
||||
case driver.AddressRepeat:
|
||||
defs = append(defs, "#define ADDRESS_REPEAT")
|
||||
default:
|
||||
panic(fmt.Sprintf("opengl: invalid address: %d", address))
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
|
||||
)
|
||||
@ -84,9 +85,9 @@ type drawTrianglesHistoryItem struct {
|
||||
vertices []float32
|
||||
indices []uint16
|
||||
colorm *affine.ColorM
|
||||
mode graphics.CompositeMode
|
||||
filter graphics.Filter
|
||||
address graphics.Address
|
||||
mode driver.CompositeMode
|
||||
filter driver.Filter
|
||||
address driver.Address
|
||||
}
|
||||
|
||||
// Image represents an image that can be restored when GL context is lost.
|
||||
@ -200,11 +201,11 @@ func (i *Image) fill(r, g, b, a uint8) {
|
||||
float32(dw)/float32(sw), 0, 0, float32(dh)/float32(sh), 0, 0,
|
||||
rf, gf, bf, af)
|
||||
is := graphics.QuadIndices()
|
||||
c := graphics.CompositeModeCopy
|
||||
c := driver.CompositeModeCopy
|
||||
if a == 0 {
|
||||
c = graphics.CompositeModeClear
|
||||
c = driver.CompositeModeClear
|
||||
}
|
||||
i.image.DrawTriangles(emptyImage.image, vs, is, nil, c, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
i.image.DrawTriangles(emptyImage.image, vs, is, nil, c, driver.FilterNearest, driver.AddressClampToZero)
|
||||
|
||||
w, h := i.Size()
|
||||
i.basePixels = &Pixels{
|
||||
@ -353,7 +354,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
}
|
||||
|
||||
// DrawTriangles draws a given image img to the image.
|
||||
func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) {
|
||||
func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||
if i.priority {
|
||||
panic("restorable: DrawTriangles cannot be called on a priority image")
|
||||
}
|
||||
@ -371,7 +372,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
|
||||
}
|
||||
|
||||
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
||||
func (i *Image) appendDrawTrianglesHistory(image *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) {
|
||||
func (i *Image) appendDrawTrianglesHistory(image *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||
if i.stale || i.volatile || i.screen {
|
||||
return
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
. "github.com/hajimehoshi/ebiten/internal/restorable"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
@ -130,7 +131,7 @@ func TestRestoreChain(t *testing.T) {
|
||||
for i := 0; i < num-1; i++ {
|
||||
vs := quadVertices(imgs[i], 1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
imgs[i+1].DrawTriangles(imgs[i], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
imgs[i+1].DrawTriangles(imgs[i], vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
}
|
||||
ResolveStaleImages()
|
||||
if err := RestoreIfNeeded(); err != nil {
|
||||
@ -170,10 +171,10 @@ func TestRestoreChain2(t *testing.T) {
|
||||
imgs[8].Fill(clr8.R, clr8.G, clr8.B, clr8.A)
|
||||
|
||||
is := graphics.QuadIndices()
|
||||
imgs[8].DrawTriangles(imgs[7], quadVertices(imgs[7], w, h, 0, 0), is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
imgs[9].DrawTriangles(imgs[8], quadVertices(imgs[8], w, h, 0, 0), is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
imgs[8].DrawTriangles(imgs[7], quadVertices(imgs[7], w, h, 0, 0), is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
imgs[9].DrawTriangles(imgs[8], quadVertices(imgs[8], w, h, 0, 0), is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
for i := 0; i < 7; i++ {
|
||||
imgs[i+1].DrawTriangles(imgs[i], quadVertices(imgs[i], w, h, 0, 0), is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
imgs[i+1].DrawTriangles(imgs[i], quadVertices(imgs[i], w, h, 0, 0), is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
}
|
||||
|
||||
ResolveStaleImages()
|
||||
@ -211,10 +212,10 @@ func TestRestoreOverrideSource(t *testing.T) {
|
||||
clr1 := color.RGBA{0x00, 0x00, 0x01, 0xff}
|
||||
img1.Fill(clr0.R, clr0.G, clr0.B, clr0.A)
|
||||
is := graphics.QuadIndices()
|
||||
img2.DrawTriangles(img1, quadVertices(img1, w, h, 0, 0), is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img3.DrawTriangles(img2, quadVertices(img2, w, h, 0, 0), is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img2.DrawTriangles(img1, quadVertices(img1, w, h, 0, 0), is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
img3.DrawTriangles(img2, quadVertices(img2, w, h, 0, 0), is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
img0.Fill(clr1.R, clr1.G, clr1.B, clr1.A)
|
||||
img1.DrawTriangles(img0, quadVertices(img0, w, h, 0, 0), is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img1.DrawTriangles(img0, quadVertices(img0, w, h, 0, 0), is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
ResolveStaleImages()
|
||||
if err := RestoreIfNeeded(); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -291,23 +292,23 @@ func TestRestoreComplexGraph(t *testing.T) {
|
||||
}()
|
||||
vs := quadVertices(img0, w, h, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
img3.DrawTriangles(img0, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img3.DrawTriangles(img0, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img1, w, h, 1, 0)
|
||||
img3.DrawTriangles(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img3.DrawTriangles(img1, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img1, w, h, 1, 0)
|
||||
img4.DrawTriangles(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img4.DrawTriangles(img1, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img2, w, h, 2, 0)
|
||||
img4.DrawTriangles(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img4.DrawTriangles(img2, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img3, w, h, 0, 0)
|
||||
img5.DrawTriangles(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img5.DrawTriangles(img3, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img3, w, h, 0, 0)
|
||||
img6.DrawTriangles(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img6.DrawTriangles(img3, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img4, w, h, 1, 0)
|
||||
img6.DrawTriangles(img4, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img6.DrawTriangles(img4, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img2, w, h, 0, 0)
|
||||
img7.DrawTriangles(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img7.DrawTriangles(img2, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
vs = quadVertices(img3, w, h, 2, 0)
|
||||
img7.DrawTriangles(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img7.DrawTriangles(img3, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
ResolveStaleImages()
|
||||
if err := RestoreIfNeeded(); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -397,8 +398,8 @@ func TestRestoreRecursive(t *testing.T) {
|
||||
img0.Dispose()
|
||||
}()
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawTriangles(img0, quadVertices(img0, w, h, 1, 0), is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img0.DrawTriangles(img1, quadVertices(img1, w, h, 1, 0), is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img1.DrawTriangles(img0, quadVertices(img0, w, h, 1, 0), is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
img0.DrawTriangles(img1, quadVertices(img1, w, h, 1, 0), is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
ResolveStaleImages()
|
||||
if err := RestoreIfNeeded(); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -482,7 +483,7 @@ func TestDrawTrianglesAndReplacePixels(t *testing.T) {
|
||||
|
||||
vs := quadVertices(img0, 1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawTriangles(img0, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img1.DrawTriangles(img0, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0, 0, 2, 1)
|
||||
|
||||
ResolveStaleImages()
|
||||
@ -514,8 +515,8 @@ func TestDispose(t *testing.T) {
|
||||
defer img2.Dispose()
|
||||
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawTriangles(img2, quadVertices(img2, 1, 1, 0, 0), is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img0.DrawTriangles(img1, quadVertices(img1, 1, 1, 0, 0), is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img1.DrawTriangles(img2, quadVertices(img2, 1, 1, 0, 0), is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
img0.DrawTriangles(img1, quadVertices(img1, 1, 1, 0, 0), is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
img1.Dispose()
|
||||
|
||||
ResolveStaleImages()
|
||||
@ -608,7 +609,7 @@ func TestReplacePixelsOnly(t *testing.T) {
|
||||
|
||||
vs := quadVertices(img0, 1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawTriangles(img0, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img1.DrawTriangles(img0, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
img0.ReplacePixels([]byte{5, 6, 7, 8}, 0, 0, 1, 1)
|
||||
|
||||
// BasePixelsForTesting is available without GPU accessing.
|
||||
@ -653,7 +654,7 @@ func TestReadPixelsFromVolatileImage(t *testing.T) {
|
||||
src.Fill(0xff, 0xff, 0xff, 0xff)
|
||||
vs := quadVertices(src, 1, 1, 0, 0)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
|
||||
// Read the pixels. If the implementation is correct, dst tries to read its pixels from GPU due to being
|
||||
// stale.
|
||||
|
@ -202,7 +202,7 @@ func (i *Image) ensureNotShared() {
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, i, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
newImg.DrawTriangles(i.backend.restorable, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
newImg.DrawTriangles(i.backend.restorable, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
|
||||
i.dispose(false)
|
||||
i.backend = &backend{
|
||||
@ -265,7 +265,7 @@ func (i *Image) PutVertex(dst []float32, dx, dy, sx, sy float32, bx0, by0, bx1,
|
||||
i.backend.restorable.PutVertex(dst, dx, dy, sx+oxf, sy+oyf, bx0+oxf, by0+oyf, bx1+oxf, by1+oyf, cr, cg, cb, ca)
|
||||
}
|
||||
|
||||
func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) {
|
||||
func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
. "github.com/hajimehoshi/ebiten/internal/shareable"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
@ -87,7 +88,7 @@ func TestEnsureNotShared(t *testing.T) {
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, img3, 0, 0, size/2, size/2, 1, 0, 0, 1, size/4, size/4, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img4.DrawTriangles(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img4.DrawTriangles(img3, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
want := false
|
||||
if got := img4.IsSharedForTesting(); got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
@ -110,7 +111,7 @@ func TestEnsureNotShared(t *testing.T) {
|
||||
|
||||
// Check further drawing doesn't cause panic.
|
||||
// This bug was fixed by 03dcd948.
|
||||
img4.DrawTriangles(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img4.DrawTriangles(img3, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
}
|
||||
|
||||
func TestReshared(t *testing.T) {
|
||||
@ -152,7 +153,7 @@ func TestReshared(t *testing.T) {
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, img2, 0, 0, size, size, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
img1.DrawTriangles(img2, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img1.DrawTriangles(img2, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
if got, want := img1.IsSharedForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -160,7 +161,7 @@ func TestReshared(t *testing.T) {
|
||||
// Use img1 as a render source.
|
||||
for i := 0; i < MaxCountForShare; i++ {
|
||||
MakeImagesSharedForTesting()
|
||||
img0.DrawTriangles(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img0.DrawTriangles(img1, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
if got, want := img1.IsSharedForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -178,7 +179,7 @@ func TestReshared(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
img0.DrawTriangles(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img0.DrawTriangles(img1, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
if got, want := img1.IsSharedForTesting(), true; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -197,7 +198,7 @@ func TestReshared(t *testing.T) {
|
||||
// Use img3 as a render source. img3 never uses a shared texture.
|
||||
for i := 0; i < MaxCountForShare*2; i++ {
|
||||
MakeImagesSharedForTesting()
|
||||
img0.DrawTriangles(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
img0.DrawTriangles(img3, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
if got, want := img3.IsSharedForTesting(), false; got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
@ -279,7 +280,7 @@ func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, src, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero)
|
||||
dst.ReplacePixels(pix)
|
||||
|
||||
for j := 0; j < h; j++ {
|
||||
@ -315,7 +316,7 @@ func TestSmallImages(t *testing.T) {
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, src, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(src, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
|
||||
for j := 0; j < h; j++ {
|
||||
for i := 0; i < w; i++ {
|
||||
|
Loading…
Reference in New Issue
Block a user