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