mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/graphics: change the naming convention: Num -> Count
This change also renames ebiten.MaxIndicesNum -> ebiten.MaxIndicesCount.
This commit is contained in:
parent
c77e5884aa
commit
afed6a83c6
141
image.go
141
image.go
@ -82,38 +82,38 @@ func (i *Image) resolveSetVerticesCacheIfNeeded() {
|
|||||||
caf = float32(c[3]) / 0xff
|
caf = float32(c[3]) / 0xff
|
||||||
}
|
}
|
||||||
|
|
||||||
vs[graphics.VertexFloatNum*4*idx] = dx
|
vs[graphics.VertexFloatCount*4*idx] = dx
|
||||||
vs[graphics.VertexFloatNum*4*idx+1] = dy
|
vs[graphics.VertexFloatCount*4*idx+1] = dy
|
||||||
vs[graphics.VertexFloatNum*4*idx+2] = sx
|
vs[graphics.VertexFloatCount*4*idx+2] = sx
|
||||||
vs[graphics.VertexFloatNum*4*idx+3] = sy
|
vs[graphics.VertexFloatCount*4*idx+3] = sy
|
||||||
vs[graphics.VertexFloatNum*4*idx+4] = crf
|
vs[graphics.VertexFloatCount*4*idx+4] = crf
|
||||||
vs[graphics.VertexFloatNum*4*idx+5] = cgf
|
vs[graphics.VertexFloatCount*4*idx+5] = cgf
|
||||||
vs[graphics.VertexFloatNum*4*idx+6] = cbf
|
vs[graphics.VertexFloatCount*4*idx+6] = cbf
|
||||||
vs[graphics.VertexFloatNum*4*idx+7] = caf
|
vs[graphics.VertexFloatCount*4*idx+7] = caf
|
||||||
vs[graphics.VertexFloatNum*4*idx+8] = dx + 1
|
vs[graphics.VertexFloatCount*4*idx+8] = dx + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+9] = dy
|
vs[graphics.VertexFloatCount*4*idx+9] = dy
|
||||||
vs[graphics.VertexFloatNum*4*idx+10] = sx + 1
|
vs[graphics.VertexFloatCount*4*idx+10] = sx + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+11] = sy
|
vs[graphics.VertexFloatCount*4*idx+11] = sy
|
||||||
vs[graphics.VertexFloatNum*4*idx+12] = crf
|
vs[graphics.VertexFloatCount*4*idx+12] = crf
|
||||||
vs[graphics.VertexFloatNum*4*idx+13] = cgf
|
vs[graphics.VertexFloatCount*4*idx+13] = cgf
|
||||||
vs[graphics.VertexFloatNum*4*idx+14] = cbf
|
vs[graphics.VertexFloatCount*4*idx+14] = cbf
|
||||||
vs[graphics.VertexFloatNum*4*idx+15] = caf
|
vs[graphics.VertexFloatCount*4*idx+15] = caf
|
||||||
vs[graphics.VertexFloatNum*4*idx+16] = dx
|
vs[graphics.VertexFloatCount*4*idx+16] = dx
|
||||||
vs[graphics.VertexFloatNum*4*idx+17] = dy + 1
|
vs[graphics.VertexFloatCount*4*idx+17] = dy + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+18] = sx
|
vs[graphics.VertexFloatCount*4*idx+18] = sx
|
||||||
vs[graphics.VertexFloatNum*4*idx+19] = sy + 1
|
vs[graphics.VertexFloatCount*4*idx+19] = sy + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+20] = crf
|
vs[graphics.VertexFloatCount*4*idx+20] = crf
|
||||||
vs[graphics.VertexFloatNum*4*idx+21] = cgf
|
vs[graphics.VertexFloatCount*4*idx+21] = cgf
|
||||||
vs[graphics.VertexFloatNum*4*idx+22] = cbf
|
vs[graphics.VertexFloatCount*4*idx+22] = cbf
|
||||||
vs[graphics.VertexFloatNum*4*idx+23] = caf
|
vs[graphics.VertexFloatCount*4*idx+23] = caf
|
||||||
vs[graphics.VertexFloatNum*4*idx+24] = dx + 1
|
vs[graphics.VertexFloatCount*4*idx+24] = dx + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+25] = dy + 1
|
vs[graphics.VertexFloatCount*4*idx+25] = dy + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+26] = sx + 1
|
vs[graphics.VertexFloatCount*4*idx+26] = sx + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+27] = sy + 1
|
vs[graphics.VertexFloatCount*4*idx+27] = sy + 1
|
||||||
vs[graphics.VertexFloatNum*4*idx+28] = crf
|
vs[graphics.VertexFloatCount*4*idx+28] = crf
|
||||||
vs[graphics.VertexFloatNum*4*idx+29] = cgf
|
vs[graphics.VertexFloatCount*4*idx+29] = cgf
|
||||||
vs[graphics.VertexFloatNum*4*idx+30] = cbf
|
vs[graphics.VertexFloatCount*4*idx+30] = cbf
|
||||||
vs[graphics.VertexFloatNum*4*idx+31] = caf
|
vs[graphics.VertexFloatCount*4*idx+31] = caf
|
||||||
|
|
||||||
is[6*idx] = uint16(4 * idx)
|
is[6*idx] = uint16(4 * idx)
|
||||||
is[6*idx+1] = uint16(4*idx + 1)
|
is[6*idx+1] = uint16(4*idx + 1)
|
||||||
@ -126,8 +126,8 @@ func (i *Image) resolveSetVerticesCacheIfNeeded() {
|
|||||||
}
|
}
|
||||||
i.setVerticesCache = nil
|
i.setVerticesCache = nil
|
||||||
|
|
||||||
srcs := [graphics.ShaderImageNum]*ui.Image{emptyImage.image}
|
srcs := [graphics.ShaderImageCount]*ui.Image{emptyImage.image}
|
||||||
i.image.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, i.adjustedRegion(), graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
i.image.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, i.adjustedRegion(), graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size returns the size of the image.
|
// Size returns the size of the image.
|
||||||
@ -310,9 +310,9 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) {
|
|||||||
vs := graphics.QuadVertices(float32(sx0), float32(sy0), float32(sx1), float32(sy1), a, b, c, d, tx, ty, cr, cg, cb, ca)
|
vs := graphics.QuadVertices(float32(sx0), float32(sy0), float32(sx1), float32(sy1), a, b, c, d, tx, ty, cr, cg, cb, ca)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
|
|
||||||
srcs := [graphics.ShaderImageNum]*ui.Image{img.image}
|
srcs := [graphics.ShaderImageCount]*ui.Image{img.image}
|
||||||
|
|
||||||
i.image.DrawTriangles(srcs, vs, is, colorm, mode, filter, graphicsdriver.AddressUnsafe, i.adjustedRegion(), graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, canSkipMipmap(options.GeoM, filter))
|
i.image.DrawTriangles(srcs, vs, is, colorm, mode, filter, graphicsdriver.AddressUnsafe, i.adjustedRegion(), graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false, canSkipMipmap(options.GeoM, filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vertex represents a vertex passed to DrawTriangles.
|
// Vertex represents a vertex passed to DrawTriangles.
|
||||||
@ -398,8 +398,13 @@ type DrawTrianglesOptions struct {
|
|||||||
FillRule FillRule
|
FillRule FillRule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaxIndicesCount is the maximum number of indices for DrawTriangles.
|
||||||
|
const MaxIndicesCount = graphics.IndicesCount
|
||||||
|
|
||||||
// MaxIndicesNum is the maximum number of indices for DrawTriangles.
|
// MaxIndicesNum is the maximum number of indices for DrawTriangles.
|
||||||
const MaxIndicesNum = graphics.IndicesNum
|
//
|
||||||
|
// Deprecated: as of v2.4. Use MaxIndicesCount instead.
|
||||||
|
const MaxIndicesNum = graphics.IndicesCount
|
||||||
|
|
||||||
// DrawTriangles draws triangles with the specified vertices and their indices.
|
// DrawTriangles draws triangles with the specified vertices and their indices.
|
||||||
//
|
//
|
||||||
@ -412,7 +417,7 @@ const MaxIndicesNum = graphics.IndicesNum
|
|||||||
//
|
//
|
||||||
// If len(indices) is not multiple of 3, DrawTriangles panics.
|
// If len(indices) is not multiple of 3, DrawTriangles panics.
|
||||||
//
|
//
|
||||||
// If len(indices) is more than MaxIndicesNum, DrawTriangles panics.
|
// If len(indices) is more than MaxIndicesCount, DrawTriangles panics.
|
||||||
//
|
//
|
||||||
// The rule in which DrawTriangles works effectively is same as DrawImage's.
|
// The rule in which DrawTriangles works effectively is same as DrawImage's.
|
||||||
//
|
//
|
||||||
@ -432,8 +437,8 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
|||||||
if len(indices)%3 != 0 {
|
if len(indices)%3 != 0 {
|
||||||
panic("ebiten: len(indices) % 3 must be 0")
|
panic("ebiten: len(indices) % 3 must be 0")
|
||||||
}
|
}
|
||||||
if len(indices) > MaxIndicesNum {
|
if len(indices) > MaxIndicesCount {
|
||||||
panic("ebiten: len(indices) must be <= MaxIndicesNum")
|
panic("ebiten: len(indices) must be <= MaxIndicesCount")
|
||||||
}
|
}
|
||||||
// TODO: Check the maximum value of indices and len(vertices)?
|
// TODO: Check the maximum value of indices and len(vertices)?
|
||||||
|
|
||||||
@ -460,22 +465,22 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
|||||||
dst := i
|
dst := i
|
||||||
for i, v := range vertices {
|
for i, v := range vertices {
|
||||||
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
||||||
vs[i*graphics.VertexFloatNum] = dx
|
vs[i*graphics.VertexFloatCount] = dx
|
||||||
vs[i*graphics.VertexFloatNum+1] = dy
|
vs[i*graphics.VertexFloatCount+1] = dy
|
||||||
sx, sy := img.adjustPositionF32(v.SrcX, v.SrcY)
|
sx, sy := img.adjustPositionF32(v.SrcX, v.SrcY)
|
||||||
vs[i*graphics.VertexFloatNum+2] = sx
|
vs[i*graphics.VertexFloatCount+2] = sx
|
||||||
vs[i*graphics.VertexFloatNum+3] = sy
|
vs[i*graphics.VertexFloatCount+3] = sy
|
||||||
vs[i*graphics.VertexFloatNum+4] = v.ColorR * cr
|
vs[i*graphics.VertexFloatCount+4] = v.ColorR * cr
|
||||||
vs[i*graphics.VertexFloatNum+5] = v.ColorG * cg
|
vs[i*graphics.VertexFloatCount+5] = v.ColorG * cg
|
||||||
vs[i*graphics.VertexFloatNum+6] = v.ColorB * cb
|
vs[i*graphics.VertexFloatCount+6] = v.ColorB * cb
|
||||||
vs[i*graphics.VertexFloatNum+7] = v.ColorA * ca
|
vs[i*graphics.VertexFloatCount+7] = v.ColorA * ca
|
||||||
}
|
}
|
||||||
is := make([]uint16, len(indices))
|
is := make([]uint16, len(indices))
|
||||||
copy(is, indices)
|
copy(is, indices)
|
||||||
|
|
||||||
srcs := [graphics.ShaderImageNum]*ui.Image{img.image}
|
srcs := [graphics.ShaderImageCount]*ui.Image{img.image}
|
||||||
|
|
||||||
i.image.DrawTriangles(srcs, vs, is, colorm, mode, filter, address, i.adjustedRegion(), sr, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, options.FillRule == EvenOdd, false)
|
i.image.DrawTriangles(srcs, vs, is, colorm, mode, filter, address, i.adjustedRegion(), sr, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, options.FillRule == EvenOdd, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawTrianglesShaderOptions represents options for DrawTrianglesShader.
|
// DrawTrianglesShaderOptions represents options for DrawTrianglesShader.
|
||||||
@ -510,7 +515,7 @@ type DrawTrianglesShaderOptions struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var op DrawTrianglesShaderOptions
|
var op DrawTrianglesShaderOptions
|
||||||
if got, want := len(op.Images), graphics.ShaderImageNum; got != want {
|
if got, want := len(op.Images), graphics.ShaderImageCount; got != want {
|
||||||
panic(fmt.Sprintf("ebiten: len((DrawTrianglesShaderOptions{}).Images) must be %d but %d", want, got))
|
panic(fmt.Sprintf("ebiten: len((DrawTrianglesShaderOptions{}).Images) must be %d but %d", want, got))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -523,7 +528,7 @@ func init() {
|
|||||||
//
|
//
|
||||||
// If len(indices) is not multiple of 3, DrawTrianglesShader panics.
|
// If len(indices) is not multiple of 3, DrawTrianglesShader panics.
|
||||||
//
|
//
|
||||||
// If len(indices) is more than MaxIndicesNum, DrawTrianglesShader panics.
|
// If len(indices) is more than MaxIndicesCount, DrawTrianglesShader panics.
|
||||||
//
|
//
|
||||||
// When a specified image is non-nil and is disposed, DrawTrianglesShader panics.
|
// When a specified image is non-nil and is disposed, DrawTrianglesShader panics.
|
||||||
//
|
//
|
||||||
@ -540,8 +545,8 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
|||||||
if len(indices)%3 != 0 {
|
if len(indices)%3 != 0 {
|
||||||
panic("ebiten: len(indices) % 3 must be 0")
|
panic("ebiten: len(indices) % 3 must be 0")
|
||||||
}
|
}
|
||||||
if len(indices) > MaxIndicesNum {
|
if len(indices) > MaxIndicesCount {
|
||||||
panic("ebiten: len(indices) must be <= MaxIndicesNum")
|
panic("ebiten: len(indices) must be <= MaxIndicesCount")
|
||||||
}
|
}
|
||||||
// TODO: Check the maximum value of indices and len(vertices)?
|
// TODO: Check the maximum value of indices and len(vertices)?
|
||||||
|
|
||||||
@ -558,23 +563,23 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
|||||||
src := options.Images[0]
|
src := options.Images[0]
|
||||||
for i, v := range vertices {
|
for i, v := range vertices {
|
||||||
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
||||||
vs[i*graphics.VertexFloatNum] = dx
|
vs[i*graphics.VertexFloatCount] = dx
|
||||||
vs[i*graphics.VertexFloatNum+1] = dy
|
vs[i*graphics.VertexFloatCount+1] = dy
|
||||||
sx, sy := v.SrcX, v.SrcY
|
sx, sy := v.SrcX, v.SrcY
|
||||||
if src != nil {
|
if src != nil {
|
||||||
sx, sy = src.adjustPositionF32(sx, sy)
|
sx, sy = src.adjustPositionF32(sx, sy)
|
||||||
}
|
}
|
||||||
vs[i*graphics.VertexFloatNum+2] = sx
|
vs[i*graphics.VertexFloatCount+2] = sx
|
||||||
vs[i*graphics.VertexFloatNum+3] = sy
|
vs[i*graphics.VertexFloatCount+3] = sy
|
||||||
vs[i*graphics.VertexFloatNum+4] = v.ColorR
|
vs[i*graphics.VertexFloatCount+4] = v.ColorR
|
||||||
vs[i*graphics.VertexFloatNum+5] = v.ColorG
|
vs[i*graphics.VertexFloatCount+5] = v.ColorG
|
||||||
vs[i*graphics.VertexFloatNum+6] = v.ColorB
|
vs[i*graphics.VertexFloatCount+6] = v.ColorB
|
||||||
vs[i*graphics.VertexFloatNum+7] = v.ColorA
|
vs[i*graphics.VertexFloatCount+7] = v.ColorA
|
||||||
}
|
}
|
||||||
is := make([]uint16, len(indices))
|
is := make([]uint16, len(indices))
|
||||||
copy(is, indices)
|
copy(is, indices)
|
||||||
|
|
||||||
var imgs [graphics.ShaderImageNum]*ui.Image
|
var imgs [graphics.ShaderImageCount]*ui.Image
|
||||||
var imgw, imgh int
|
var imgw, imgh int
|
||||||
for i, img := range options.Images {
|
for i, img := range options.Images {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
@ -603,7 +608,7 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
|||||||
sr = img.adjustedRegion()
|
sr = img.adjustedRegion()
|
||||||
}
|
}
|
||||||
|
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
for i, img := range options.Images[1:] {
|
for i, img := range options.Images[1:] {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
continue
|
continue
|
||||||
@ -646,7 +651,7 @@ type DrawRectShaderOptions struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var op DrawRectShaderOptions
|
var op DrawRectShaderOptions
|
||||||
if got, want := len(op.Images), graphics.ShaderImageNum; got != want {
|
if got, want := len(op.Images), graphics.ShaderImageCount; got != want {
|
||||||
panic(fmt.Sprintf("ebiten: len((DrawRectShaderOptions{}).Images) must be %d but %d", want, got))
|
panic(fmt.Sprintf("ebiten: len((DrawRectShaderOptions{}).Images) must be %d but %d", want, got))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -675,7 +680,7 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
|
|||||||
|
|
||||||
mode := graphicsdriver.CompositeMode(options.CompositeMode)
|
mode := graphicsdriver.CompositeMode(options.CompositeMode)
|
||||||
|
|
||||||
var imgs [graphics.ShaderImageNum]*ui.Image
|
var imgs [graphics.ShaderImageCount]*ui.Image
|
||||||
for i, img := range options.Images {
|
for i, img := range options.Images {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
continue
|
continue
|
||||||
@ -705,7 +710,7 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
|
|||||||
vs := graphics.QuadVertices(float32(sx), float32(sy), float32(sx+width), float32(sy+height), a, b, c, d, tx, ty, 1, 1, 1, 1)
|
vs := graphics.QuadVertices(float32(sx), float32(sy), float32(sx+width), float32(sy+height), a, b, c, d, tx, ty, 1, 1, 1, 1)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
|
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
for i, img := range options.Images[1:] {
|
for i, img := range options.Images[1:] {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
continue
|
continue
|
||||||
@ -843,7 +848,7 @@ func (i *Image) Set(x, y int, clr color.Color) {
|
|||||||
cr, cg, cb, ca := clr.RGBA()
|
cr, cg, cb, ca := clr.RGBA()
|
||||||
i.setVerticesCache[[2]int{dx, dy}] = [4]byte{byte(cr / 0x101), byte(cg / 0x101), byte(cb / 0x101), byte(ca / 0x101)}
|
i.setVerticesCache[[2]int{dx, dy}] = [4]byte{byte(cr / 0x101), byte(cg / 0x101), byte(cb / 0x101), byte(ca / 0x101)}
|
||||||
// One square requires 6 indices (= 2 triangles).
|
// One square requires 6 indices (= 2 triangles).
|
||||||
if len(i.setVerticesCache) >= graphics.IndicesNum/6 {
|
if len(i.setVerticesCache) >= graphics.IndicesCount/6 {
|
||||||
i.resolveSetVerticesCacheIfNeeded()
|
i.resolveSetVerticesCacheIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2699,7 +2699,7 @@ func TestIndicesOverflow(t *testing.T) {
|
|||||||
|
|
||||||
op := &ebiten.DrawTrianglesOptions{}
|
op := &ebiten.DrawTrianglesOptions{}
|
||||||
vs := make([]ebiten.Vertex, 3)
|
vs := make([]ebiten.Vertex, 3)
|
||||||
is := make([]uint16, graphics.IndicesNum/3*3)
|
is := make([]uint16, graphics.IndicesCount/3*3)
|
||||||
dst.DrawTriangles(vs, is, src, op)
|
dst.DrawTriangles(vs, is, src, op)
|
||||||
|
|
||||||
// Cause an overflow for indices.
|
// Cause an overflow for indices.
|
||||||
@ -2770,7 +2770,7 @@ func TestVerticesOverflow(t *testing.T) {
|
|||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
|
|
||||||
op := &ebiten.DrawTrianglesOptions{}
|
op := &ebiten.DrawTrianglesOptions{}
|
||||||
vs := make([]ebiten.Vertex, graphics.IndicesNum-1)
|
vs := make([]ebiten.Vertex, graphics.IndicesCount-1)
|
||||||
is := make([]uint16, 3)
|
is := make([]uint16, 3)
|
||||||
dst.DrawTriangles(vs, is, src, op)
|
dst.DrawTriangles(vs, is, src, op)
|
||||||
|
|
||||||
@ -2842,7 +2842,7 @@ func TestTooManyVertices(t *testing.T) {
|
|||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
|
|
||||||
op := &ebiten.DrawTrianglesOptions{}
|
op := &ebiten.DrawTrianglesOptions{}
|
||||||
vs := make([]ebiten.Vertex, graphics.IndicesNum+1)
|
vs := make([]ebiten.Vertex, graphics.IndicesCount+1)
|
||||||
is := make([]uint16, 3)
|
is := make([]uint16, 3)
|
||||||
dst.DrawTriangles(vs, is, src, op)
|
dst.DrawTriangles(vs, is, src, op)
|
||||||
|
|
||||||
|
@ -303,8 +303,8 @@ func (i *Image) ensureIsolated() {
|
|||||||
dx1, dy1, sx1, sy1, 1, 1, 1, 1,
|
dx1, dy1, sx1, sy1, 1, 1, 1, 1,
|
||||||
}
|
}
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
srcs := [graphics.ShaderImageNum]*restorable.Image{i.backend.restorable}
|
srcs := [graphics.ShaderImageCount]*restorable.Image{i.backend.restorable}
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
dstRegion := graphicsdriver.Region{
|
dstRegion := graphicsdriver.Region{
|
||||||
X: float32(i.paddingSize()),
|
X: float32(i.paddingSize()),
|
||||||
Y: float32(i.paddingSize()),
|
Y: float32(i.paddingSize()),
|
||||||
@ -350,7 +350,7 @@ func (i *Image) putOnAtlas(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
newI.drawTriangles([graphics.ShaderImageNum]*Image{i}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
newI.drawTriangles([graphics.ShaderImageCount]*Image{i}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false, true)
|
||||||
|
|
||||||
newI.moveTo(i)
|
newI.moveTo(i)
|
||||||
i.usedAsSourceCount = 0
|
i.usedAsSourceCount = 0
|
||||||
@ -397,13 +397,13 @@ func (i *Image) processSrc(src *Image) {
|
|||||||
// 5: Color G
|
// 5: Color G
|
||||||
// 6: Color B
|
// 6: Color B
|
||||||
// 7: Color Y
|
// 7: Color Y
|
||||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
defer backendsM.Unlock()
|
defer backendsM.Unlock()
|
||||||
i.drawTriangles(srcs, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, subimageOffsets, shader, uniforms, evenOdd, false)
|
i.drawTriangles(srcs, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, subimageOffsets, shader, uniforms, evenOdd, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) drawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, keepOnAtlas bool) {
|
func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, keepOnAtlas bool) {
|
||||||
if i.disposed {
|
if i.disposed {
|
||||||
panic("atlas: the drawing target image must not be disposed (DrawTriangles)")
|
panic("atlas: the drawing target image must not be disposed (DrawTriangles)")
|
||||||
}
|
}
|
||||||
@ -436,7 +436,7 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
|
|||||||
sw, sh := srcs[0].backend.restorable.InternalSize()
|
sw, sh := srcs[0].backend.restorable.InternalSize()
|
||||||
swf, shf := float32(sw), float32(sh)
|
swf, shf := float32(sw), float32(sh)
|
||||||
n := len(vertices)
|
n := len(vertices)
|
||||||
for i := 0; i < n; i += graphics.VertexFloatNum {
|
for i := 0; i < n; i += graphics.VertexFloatCount {
|
||||||
vertices[i] = adjustDestinationPixel(vertices[i] + dx)
|
vertices[i] = adjustDestinationPixel(vertices[i] + dx)
|
||||||
vertices[i+1] = adjustDestinationPixel(vertices[i+1] + dy)
|
vertices[i+1] = adjustDestinationPixel(vertices[i+1] + dy)
|
||||||
vertices[i+2] = (vertices[i+2] + oxf) / swf
|
vertices[i+2] = (vertices[i+2] + oxf) / swf
|
||||||
@ -450,15 +450,15 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
n := len(vertices)
|
n := len(vertices)
|
||||||
for i := 0; i < n; i += graphics.VertexFloatNum {
|
for i := 0; i < n; i += graphics.VertexFloatCount {
|
||||||
vertices[i] = adjustDestinationPixel(vertices[i] + dx)
|
vertices[i] = adjustDestinationPixel(vertices[i] + dx)
|
||||||
vertices[i+1] = adjustDestinationPixel(vertices[i+1] + dy)
|
vertices[i+1] = adjustDestinationPixel(vertices[i+1] + dy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
var s *restorable.Shader
|
var s *restorable.Shader
|
||||||
var imgs [graphics.ShaderImageNum]*restorable.Image
|
var imgs [graphics.ShaderImageCount]*restorable.Image
|
||||||
if shader == nil {
|
if shader == nil {
|
||||||
// Fast path for rendering without a shader (#1355).
|
// Fast path for rendering without a shader (#1355).
|
||||||
imgs[0] = srcs[0].backend.restorable
|
imgs[0] = srcs[0].backend.restorable
|
||||||
|
@ -107,7 +107,7 @@ func TestEnsureIsolated(t *testing.T) {
|
|||||||
Width: size,
|
Width: size,
|
||||||
Height: size,
|
Height: size,
|
||||||
}
|
}
|
||||||
img4.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img4.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img4.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func TestEnsureIsolated(t *testing.T) {
|
|||||||
Width: size / 2,
|
Width: size / 2,
|
||||||
Height: size / 2,
|
Height: size / 2,
|
||||||
}
|
}
|
||||||
img3.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img5}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img3.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img5}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img3.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img3.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ func TestEnsureIsolated(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([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReputOnAtlas(t *testing.T) {
|
func TestReputOnAtlas(t *testing.T) {
|
||||||
@ -196,7 +196,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
Width: size,
|
Width: size,
|
||||||
Height: size,
|
Height: size,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// img1 is on an atlas again.
|
// img1 is on an atlas again.
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), true; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), true; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -260,7 +260,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use img1 as a render target again.
|
// Use img1 as a render target again.
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
img1.ReplacePixels(make([]byte, 4*size*size), 0, 0, size, size)
|
img1.ReplacePixels(make([]byte, 4*size*size), 0, 0, size, size)
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// img1 is not on an atlas due to ReplacePixels.
|
// img1 is not on an atlas due to ReplacePixels.
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img1.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ func TestReputOnAtlas(t *testing.T) {
|
|||||||
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img3}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := img3.IsOnAtlasForTesting(), false; got != want {
|
if got, want := img3.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -392,7 +392,7 @@ func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
dst.ReplacePixels(pix, 0, 0, w, h)
|
dst.ReplacePixels(pix, 0, 0, w, h)
|
||||||
|
|
||||||
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
||||||
@ -440,7 +440,7 @@ func TestSmallImages(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -488,7 +488,7 @@ func TestLongImages(t *testing.T) {
|
|||||||
Width: dstW,
|
Width: dstW,
|
||||||
Height: dstH,
|
Height: dstH,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -605,7 +605,7 @@ func TestDisposedAndReputOnAtlas(t *testing.T) {
|
|||||||
Width: size,
|
Width: size,
|
||||||
Height: size,
|
Height: size,
|
||||||
}
|
}
|
||||||
src.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
src.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -615,7 +615,7 @@ func TestDisposedAndReputOnAtlas(t *testing.T) {
|
|||||||
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -655,7 +655,7 @@ func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use src2 as a rendering target, and make src2 an independent image.
|
// Use src2 as a rendering target, and make src2 an independent image.
|
||||||
src2.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
src2.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
@ -676,7 +676,7 @@ func TestImageIsNotReputOnAtlasWithoutUsingAsSource(t *testing.T) {
|
|||||||
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
if err := atlas.PutImagesOnAtlasForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src2}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
if got, want := src2.IsOnAtlasForTesting(), false; got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ func TestShaderFillTwice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
g := ui.GraphicsDriverForTesting()
|
g := ui.GraphicsDriverForTesting()
|
||||||
s0 := atlas.NewShader(etesting.ShaderProgramFill(0xff, 0xff, 0xff, 0xff))
|
s0 := atlas.NewShader(etesting.ShaderProgramFill(0xff, 0xff, 0xff, 0xff))
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s0, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, s0, nil, false)
|
||||||
|
|
||||||
// Vertices must be recreated (#1755)
|
// Vertices must be recreated (#1755)
|
||||||
vs = quadVertices(w, h, 0, 0, 1)
|
vs = quadVertices(w, h, 0, 0, 1)
|
||||||
s1 := atlas.NewShader(etesting.ShaderProgramFill(0x80, 0x80, 0x80, 0xff))
|
s1 := atlas.NewShader(etesting.ShaderProgramFill(0x80, 0x80, 0x80, 0xff))
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, s1, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, s1, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(g)
|
pix, err := dst.Pixels(g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -74,11 +74,11 @@ func TestImageDrawTwice(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src0}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src0}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
// Vertices must be recreated (#1755)
|
// Vertices must be recreated (#1755)
|
||||||
vs = quadVertices(w, h, 0, 0, 1)
|
vs = quadVertices(w, h, 0, 0, 1)
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*atlas.Image{src1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{src1}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
|
|
||||||
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
pix, err := dst.Pixels(ui.GraphicsDriverForTesting())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -124,7 +124,7 @@ func (i *Image) ReplacePixels(pix []byte, x, y, width, height int) {
|
|||||||
// DrawTriangles draws the src image with the given vertices.
|
// DrawTriangles draws the src image with the given vertices.
|
||||||
//
|
//
|
||||||
// Copying vertices and indices is the caller's responsibility.
|
// Copying vertices and indices is the caller's responsibility.
|
||||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
||||||
for _, src := range srcs {
|
for _, src := range srcs {
|
||||||
if i == src {
|
if i == src {
|
||||||
panic("buffered: Image.DrawTriangles: source images must be different from the receiver")
|
panic("buffered: Image.DrawTriangles: source images must be different from the receiver")
|
||||||
@ -141,7 +141,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
|
|||||||
}
|
}
|
||||||
|
|
||||||
var s *atlas.Shader
|
var s *atlas.Shader
|
||||||
var imgs [graphics.ShaderImageNum]*atlas.Image
|
var imgs [graphics.ShaderImageCount]*atlas.Image
|
||||||
if shader == nil {
|
if shader == nil {
|
||||||
// Fast path for rendering without a shader (#1355).
|
// Fast path for rendering without a shader (#1355).
|
||||||
img := srcs[0]
|
img := srcs[0]
|
||||||
|
@ -76,9 +76,9 @@ var __textureSourceRegionSize vec2
|
|||||||
func imageSrcRegionOnTexture() (vec2, vec2) {
|
func imageSrcRegionOnTexture() (vec2, vec2) {
|
||||||
return __textureSourceRegionOrigin, __textureSourceRegionSize
|
return __textureSourceRegionOrigin, __textureSourceRegionSize
|
||||||
}
|
}
|
||||||
`, ShaderImageNum, ShaderImageNum-1)
|
`, ShaderImageCount, ShaderImageCount-1)
|
||||||
|
|
||||||
for i := 0; i < ShaderImageNum; i++ {
|
for i := 0; i < ShaderImageCount; i++ {
|
||||||
pos := "pos"
|
pos := "pos"
|
||||||
if i >= 1 {
|
if i >= 1 {
|
||||||
// Convert the position in texture0's texels to the target texture texels.
|
// Convert the position in texture0's texels to the target texture texels.
|
||||||
@ -124,7 +124,7 @@ func CompileShader(src []byte) (*shaderir.Program, error) {
|
|||||||
vert = "__vertex"
|
vert = "__vertex"
|
||||||
frag = "Fragment"
|
frag = "Fragment"
|
||||||
)
|
)
|
||||||
ir, err := shader.Compile(fs, f, vert, frag, ShaderImageNum)
|
ir, err := shader.Compile(fs, f, vert, frag, ShaderImageCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ShaderImageNum = 4
|
ShaderImageCount = 4
|
||||||
|
|
||||||
// PreservedUniformVariablesNum represents the number of preserved uniform variables.
|
// PreservedUniformVariablesCount represents the number of preserved uniform variables.
|
||||||
// Any shaders in Ebiten must have these uniform variables.
|
// Any shaders in Ebiten must have these uniform variables.
|
||||||
PreservedUniformVariablesNum = 1 + // the destination texture size
|
PreservedUniformVariablesCount = 1 + // the destination texture size
|
||||||
1 + // the texture sizes array
|
1 + // the texture sizes array
|
||||||
1 + // the texture destination region's origin
|
1 + // the texture destination region's origin
|
||||||
1 + // the texture destination region's size
|
1 + // the texture destination region's size
|
||||||
@ -43,8 +43,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IndicesNum = (1 << 16) / 3 * 3 // Adjust num for triangles.
|
IndicesCount = (1 << 16) / 3 * 3 // Adjust num for triangles.
|
||||||
VertexFloatNum = 8
|
VertexFloatCount = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -70,7 +70,7 @@ type verticesBackend struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func verticesBackendFloat32Size(size int) int {
|
func verticesBackendFloat32Size(size int) int {
|
||||||
l := 128 * VertexFloatNum
|
l := 128 * VertexFloatCount
|
||||||
for l < size {
|
for l < size {
|
||||||
l *= 2
|
l *= 2
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ func (v *verticesBackend) slice(n int) []float32 {
|
|||||||
v.m.Lock()
|
v.m.Lock()
|
||||||
defer v.m.Unlock()
|
defer v.m.Unlock()
|
||||||
|
|
||||||
need := n * VertexFloatNum
|
need := n * VertexFloatCount
|
||||||
if len(v.backend) < v.pos+need {
|
if len(v.backend) < v.pos+need {
|
||||||
v.backend = make([]float32, max(len(v.backend)*2, verticesBackendFloat32Size(need)))
|
v.backend = make([]float32, max(len(v.backend)*2, verticesBackendFloat32Size(need)))
|
||||||
v.pos = 0
|
v.pos = 0
|
||||||
@ -148,7 +148,7 @@ func QuadVertices(sx0, sy0, sx1, sy1 float32, a, b, c, d, tx, ty float32, cr, cg
|
|||||||
vs := theVerticesBackend.slice(4)
|
vs := theVerticesBackend.slice(4)
|
||||||
|
|
||||||
// This function is very performance-sensitive and implement in a very dumb way.
|
// This function is very performance-sensitive and implement in a very dumb way.
|
||||||
_ = vs[:4*VertexFloatNum]
|
_ = vs[:4*VertexFloatCount]
|
||||||
|
|
||||||
vs[0] = tx
|
vs[0] = tx
|
||||||
vs[1] = ty
|
vs[1] = ty
|
||||||
|
@ -109,13 +109,13 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) {
|
|||||||
|
|
||||||
// mustUseDifferentVertexBuffer reports whether a differnt vertex buffer must be used.
|
// mustUseDifferentVertexBuffer reports whether a differnt vertex buffer must be used.
|
||||||
func mustUseDifferentVertexBuffer(nextNumVertexFloats, nextNumIndices int) bool {
|
func mustUseDifferentVertexBuffer(nextNumVertexFloats, nextNumIndices int) bool {
|
||||||
return nextNumVertexFloats > graphics.IndicesNum*graphics.VertexFloatNum || nextNumIndices > graphics.IndicesNum
|
return nextNumVertexFloats > graphics.IndicesCount*graphics.VertexFloatCount || nextNumIndices > graphics.IndicesCount
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnqueueDrawTrianglesCommand enqueues a drawing-image command.
|
// EnqueueDrawTrianglesCommand enqueues a drawing-image command.
|
||||||
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
||||||
if len(indices) > graphics.IndicesNum {
|
if len(indices) > graphics.IndicesCount {
|
||||||
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.IndicesCount but not at EnqueueDrawTrianglesCommand: len(indices): %d, graphics.IndicesCount: %d", len(indices), graphics.IndicesCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
split := false
|
split := false
|
||||||
@ -128,7 +128,7 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.Sh
|
|||||||
// Assume that all the image sizes are same.
|
// Assume that all the image sizes are same.
|
||||||
// Assume that the images are packed from the front in the slice srcs.
|
// Assume that the images are packed from the front in the slice srcs.
|
||||||
q.appendVertices(vertices, srcs[0])
|
q.appendVertices(vertices, srcs[0])
|
||||||
q.appendIndices(indices, uint16(q.tmpNumVertexFloats/graphics.VertexFloatNum))
|
q.appendIndices(indices, uint16(q.tmpNumVertexFloats/graphics.VertexFloatCount))
|
||||||
q.tmpNumVertexFloats += len(vertices)
|
q.tmpNumVertexFloats += len(vertices)
|
||||||
q.tmpNumIndices += len(indices)
|
q.tmpNumIndices += len(indices)
|
||||||
|
|
||||||
@ -214,8 +214,8 @@ func (q *commandQueue) flush(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
nc := 0
|
nc := 0
|
||||||
for _, c := range cs {
|
for _, c := range cs {
|
||||||
if dtc, ok := c.(*drawTrianglesCommand); ok {
|
if dtc, ok := c.(*drawTrianglesCommand); ok {
|
||||||
if dtc.numIndices() > graphics.IndicesNum {
|
if dtc.numIndices() > graphics.IndicesCount {
|
||||||
panic(fmt.Sprintf("graphicscommand: dtc.NumIndices() must be <= graphics.IndicesNum but not at Flush: dtc.NumIndices(): %d, graphics.IndicesNum: %d", dtc.numIndices(), graphics.IndicesNum))
|
panic(fmt.Sprintf("graphicscommand: dtc.NumIndices() must be <= graphics.IndicesCount but not at Flush: dtc.NumIndices(): %d, graphics.IndicesCount: %d", dtc.numIndices(), graphics.IndicesCount))
|
||||||
}
|
}
|
||||||
if nc > 0 && mustUseDifferentVertexBuffer(nv+dtc.numVertices(), ne+dtc.numIndices()) {
|
if nc > 0 && mustUseDifferentVertexBuffer(nv+dtc.numVertices(), ne+dtc.numIndices()) {
|
||||||
break
|
break
|
||||||
@ -279,8 +279,8 @@ func FlushCommands(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
// drawTrianglesCommand represents a drawing command to draw an image on another image.
|
// drawTrianglesCommand represents a drawing command to draw an image on another image.
|
||||||
type drawTrianglesCommand struct {
|
type drawTrianglesCommand struct {
|
||||||
dst *Image
|
dst *Image
|
||||||
srcs [graphics.ShaderImageNum]*Image
|
srcs [graphics.ShaderImageCount]*Image
|
||||||
offsets [graphics.ShaderImageNum - 1][2]float32
|
offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
vertices []float32
|
vertices []float32
|
||||||
nindices int
|
nindices int
|
||||||
color affine.ColorM
|
color affine.ColorM
|
||||||
@ -363,7 +363,7 @@ func (c *drawTrianglesCommand) String() string {
|
|||||||
panic(fmt.Sprintf("graphicscommand: invalid address: %d", c.address))
|
panic(fmt.Sprintf("graphicscommand: invalid address: %d", c.address))
|
||||||
}
|
}
|
||||||
|
|
||||||
var srcstrs [graphics.ShaderImageNum]string
|
var srcstrs [graphics.ShaderImageCount]string
|
||||||
for i, src := range c.srcs {
|
for i, src := range c.srcs {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
srcstrs[i] = "(nil)"
|
srcstrs[i] = "(nil)"
|
||||||
@ -388,7 +388,7 @@ func (c *drawTrianglesCommand) Exec(graphicsDriver graphicsdriver.Graphics, inde
|
|||||||
}
|
}
|
||||||
|
|
||||||
var shaderID graphicsdriver.ShaderID = graphicsdriver.InvalidShaderID
|
var shaderID graphicsdriver.ShaderID = graphicsdriver.InvalidShaderID
|
||||||
var imgs [graphics.ShaderImageNum]graphicsdriver.ImageID
|
var imgs [graphics.ShaderImageCount]graphicsdriver.ImageID
|
||||||
if c.shader != nil {
|
if c.shader != nil {
|
||||||
shaderID = c.shader.shader.ID()
|
shaderID = c.shader.shader.ID()
|
||||||
for i, src := range c.srcs {
|
for i, src := range c.srcs {
|
||||||
@ -423,7 +423,7 @@ func (c *drawTrianglesCommand) addNumIndices(n int) {
|
|||||||
|
|
||||||
// CanMergeWithDrawTrianglesCommand returns a boolean value indicating whether the other drawTrianglesCommand can be merged
|
// CanMergeWithDrawTrianglesCommand returns a boolean value indicating whether the other drawTrianglesCommand can be merged
|
||||||
// with the drawTrianglesCommand c.
|
// with the drawTrianglesCommand c.
|
||||||
func (c *drawTrianglesCommand) CanMergeWithDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, vertices []float32, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) bool {
|
func (c *drawTrianglesCommand) CanMergeWithDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageCount]*Image, vertices []float32, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) bool {
|
||||||
if c.shader != shader {
|
if c.shader != shader {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -486,9 +486,9 @@ func dstRegionFromVertices(vertices []float32) (minX, minY, maxX, maxY float32)
|
|||||||
maxX = negInf32
|
maxX = negInf32
|
||||||
maxY = negInf32
|
maxY = negInf32
|
||||||
|
|
||||||
for i := 0; i < len(vertices)/graphics.VertexFloatNum; i++ {
|
for i := 0; i < len(vertices)/graphics.VertexFloatCount; i++ {
|
||||||
x := vertices[graphics.VertexFloatNum*i]
|
x := vertices[graphics.VertexFloatCount*i]
|
||||||
y := vertices[graphics.VertexFloatNum*i+1]
|
y := vertices[graphics.VertexFloatCount*i+1]
|
||||||
if x < minX {
|
if x < minX {
|
||||||
minX = x
|
minX = x
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func (i *Image) InternalSize() (int, int) {
|
|||||||
//
|
//
|
||||||
// If the source image is not specified, i.e., src is nil and there is no image in the uniform variables, the
|
// If the source image is not specified, i.e., src is nil and there is no image in the uniform variables, the
|
||||||
// elements for the source image are not used.
|
// elements for the source image are not used.
|
||||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, clr affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, clr affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
||||||
if shader == nil {
|
if shader == nil {
|
||||||
// Fast path for rendering without a shader (#1355).
|
// Fast path for rendering without a shader (#1355).
|
||||||
img := srcs[0]
|
img := srcs[0]
|
||||||
|
@ -54,7 +54,7 @@ func TestClear(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*graphicscommand.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
if err := dst.ReadPixels(ui.GraphicsDriverForTesting(), pix); err != nil {
|
if err := dst.ReadPixels(ui.GraphicsDriverForTesting(), pix); err != nil {
|
||||||
@ -85,8 +85,8 @@ func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*graphicscommand.Image{clr}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*graphicscommand.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||||
|
|
||||||
// TODO: Check the result.
|
// TODO: Check the result.
|
||||||
@ -104,11 +104,11 @@ func TestShader(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{clr}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*graphicscommand.Image{clr}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
|
|
||||||
g := ui.GraphicsDriverForTesting()
|
g := ui.GraphicsDriverForTesting()
|
||||||
s := graphicscommand.NewShader(etesting.ShaderProgramFill(0xff, 0, 0, 0xff))
|
s := graphicscommand.NewShader(etesting.ShaderProgramFill(0xff, 0, 0, 0xff))
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*graphicscommand.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*graphicscommand.Image{}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
if err := dst.ReadPixels(g, pix); err != nil {
|
if err := dst.ReadPixels(g, pix); err != nil {
|
||||||
|
@ -956,7 +956,7 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint16) (ferr error
|
|||||||
}
|
}
|
||||||
if g.vertices[g.frameIndex][vidx] == nil {
|
if g.vertices[g.frameIndex][vidx] == nil {
|
||||||
// TODO: Use the default heap for efficienty. See the official example HelloTriangle.
|
// TODO: Use the default heap for efficienty. See the official example HelloTriangle.
|
||||||
vs, err := createBuffer(g.device, graphics.IndicesNum*graphics.VertexFloatNum*uint64(unsafe.Sizeof(float32(0))), _D3D12_HEAP_TYPE_UPLOAD)
|
vs, err := createBuffer(g.device, graphics.IndicesCount*graphics.VertexFloatCount*uint64(unsafe.Sizeof(float32(0))), _D3D12_HEAP_TYPE_UPLOAD)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -976,7 +976,7 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint16) (ferr error
|
|||||||
g.indices[g.frameIndex] = append(g.indices[g.frameIndex], nil)
|
g.indices[g.frameIndex] = append(g.indices[g.frameIndex], nil)
|
||||||
}
|
}
|
||||||
if g.indices[g.frameIndex][iidx] == nil {
|
if g.indices[g.frameIndex][iidx] == nil {
|
||||||
is, err := createBuffer(g.device, graphics.IndicesNum*uint64(unsafe.Sizeof(uint16(0))), _D3D12_HEAP_TYPE_UPLOAD)
|
is, err := createBuffer(g.device, graphics.IndicesCount*uint64(unsafe.Sizeof(uint16(0))), _D3D12_HEAP_TYPE_UPLOAD)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1150,7 +1150,7 @@ func (g *Graphics) NewShader(program *shaderir.Program) (graphicsdriver.Shader,
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.ShaderImageNum]graphicsdriver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms [][]float32, evenOdd bool) error {
|
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.ShaderImageCount]graphicsdriver.ImageID, offsets [graphics.ShaderImageCount - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms [][]float32, evenOdd bool) error {
|
||||||
if err := g.flushCommandList(g.copyCommandList); err != nil {
|
if err := g.flushCommandList(g.copyCommandList); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1165,7 +1165,7 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.Sh
|
|||||||
shader = g.shaders[shaderID]
|
shader = g.shaders[shaderID]
|
||||||
}
|
}
|
||||||
|
|
||||||
var srcImages [graphics.ShaderImageNum]*Image
|
var srcImages [graphics.ShaderImageCount]*Image
|
||||||
for i, srcID := range srcs {
|
for i, srcID := range srcs {
|
||||||
src := g.images[srcID]
|
src := g.images[srcID]
|
||||||
if src == nil {
|
if src == nil {
|
||||||
@ -1226,7 +1226,7 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.Sh
|
|||||||
} else {
|
} else {
|
||||||
// TODO: This logic is very similar to Metal's. Let's unify them.
|
// TODO: This logic is very similar to Metal's. Let's unify them.
|
||||||
dw, dh := dst.internalSize()
|
dw, dh := dst.internalSize()
|
||||||
us := make([][]float32, graphics.PreservedUniformVariablesNum+len(uniforms))
|
us := make([][]float32, graphics.PreservedUniformVariablesCount+len(uniforms))
|
||||||
us[graphics.TextureDestinationSizeUniformVariableIndex] = []float32{float32(dw), float32(dh)}
|
us[graphics.TextureDestinationSizeUniformVariableIndex] = []float32{float32(dw), float32(dh)}
|
||||||
usizes := make([]float32, 2*len(srcs))
|
usizes := make([]float32, 2*len(srcs))
|
||||||
for i, src := range srcImages {
|
for i, src := range srcImages {
|
||||||
@ -1259,7 +1259,7 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.Sh
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, u := range uniforms {
|
for i, u := range uniforms {
|
||||||
us[graphics.PreservedUniformVariablesNum+i] = u
|
us[graphics.PreservedUniformVariablesCount+i] = u
|
||||||
}
|
}
|
||||||
|
|
||||||
flattenUniforms = shader.uniformsToFloat32s(us)
|
flattenUniforms = shader.uniformsToFloat32s(us)
|
||||||
@ -1290,13 +1290,13 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.Sh
|
|||||||
g.drawCommandList.IASetVertexBuffers(0, []_D3D12_VERTEX_BUFFER_VIEW{
|
g.drawCommandList.IASetVertexBuffers(0, []_D3D12_VERTEX_BUFFER_VIEW{
|
||||||
{
|
{
|
||||||
BufferLocation: g.vertices[g.frameIndex][len(g.vertices[g.frameIndex])-1].GetGPUVirtualAddress(),
|
BufferLocation: g.vertices[g.frameIndex][len(g.vertices[g.frameIndex])-1].GetGPUVirtualAddress(),
|
||||||
SizeInBytes: graphics.IndicesNum * graphics.VertexFloatNum * uint32(unsafe.Sizeof(float32(0))),
|
SizeInBytes: graphics.IndicesCount * graphics.VertexFloatCount * uint32(unsafe.Sizeof(float32(0))),
|
||||||
StrideInBytes: graphics.VertexFloatNum * uint32(unsafe.Sizeof(float32(0))),
|
StrideInBytes: graphics.VertexFloatCount * uint32(unsafe.Sizeof(float32(0))),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
g.drawCommandList.IASetIndexBuffer(&_D3D12_INDEX_BUFFER_VIEW{
|
g.drawCommandList.IASetIndexBuffer(&_D3D12_INDEX_BUFFER_VIEW{
|
||||||
BufferLocation: g.indices[g.frameIndex][len(g.indices[g.frameIndex])-1].GetGPUVirtualAddress(),
|
BufferLocation: g.indices[g.frameIndex][len(g.indices[g.frameIndex])-1].GetGPUVirtualAddress(),
|
||||||
SizeInBytes: graphics.IndicesNum * uint32(unsafe.Sizeof(uint16(0))),
|
SizeInBytes: graphics.IndicesCount * uint32(unsafe.Sizeof(uint16(0))),
|
||||||
Format: _DXGI_FORMAT_R16_UINT,
|
Format: _DXGI_FORMAT_R16_UINT,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1378,7 +1378,7 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.Sh
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) drawTriangles(pipelineState *_ID3D12PipelineState, srcs [graphics.ShaderImageNum]*Image, flattenUniforms []float32, indexLen int, indexOffset int) error {
|
func (g *Graphics) drawTriangles(pipelineState *_ID3D12PipelineState, srcs [graphics.ShaderImageCount]*Image, flattenUniforms []float32, indexLen int, indexOffset int) error {
|
||||||
if err := g.pipelineStates.useGraphicsPipelineState(g.device, g.drawCommandList, g.frameIndex, pipelineState, srcs, flattenUniforms); err != nil {
|
if err := g.pipelineStates.useGraphicsPipelineState(g.device, g.drawCommandList, g.frameIndex, pipelineState, srcs, flattenUniforms); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ type pipelineStates struct {
|
|||||||
constantBufferMaps [frameCount][]uintptr
|
constantBufferMaps [frameCount][]uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
const numConstantBufferAndSourceTextures = 1 + graphics.ShaderImageNum
|
const numConstantBufferAndSourceTextures = 1 + graphics.ShaderImageCount
|
||||||
|
|
||||||
func (p *pipelineStates) initialize(device *_ID3D12Device) (ferr error) {
|
func (p *pipelineStates) initialize(device *_ID3D12Device) (ferr error) {
|
||||||
// Create a CBV/SRV/UAV descriptor heap.
|
// Create a CBV/SRV/UAV descriptor heap.
|
||||||
@ -359,7 +359,7 @@ func (p *pipelineStates) builtinGraphicsPipelineState(device *_ID3D12Device, key
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pipelineStates) useGraphicsPipelineState(device *_ID3D12Device, commandList *_ID3D12GraphicsCommandList, frameIndex int, pipelineState *_ID3D12PipelineState, srcs [graphics.ShaderImageNum]*Image, uniforms []float32) error {
|
func (p *pipelineStates) useGraphicsPipelineState(device *_ID3D12Device, commandList *_ID3D12GraphicsCommandList, frameIndex int, pipelineState *_ID3D12PipelineState, srcs [graphics.ShaderImageCount]*Image, uniforms []float32) error {
|
||||||
idx := len(p.constantBuffers[frameIndex])
|
idx := len(p.constantBuffers[frameIndex])
|
||||||
if idx >= numDescriptorsPerFrame*2 {
|
if idx >= numDescriptorsPerFrame*2 {
|
||||||
return fmt.Errorf("directx: too many constant buffers")
|
return fmt.Errorf("directx: too many constant buffers")
|
||||||
@ -486,7 +486,7 @@ func (p *pipelineStates) ensureRootSignature(device *_ID3D12Device) (rootSignatu
|
|||||||
}
|
}
|
||||||
srv := _D3D12_DESCRIPTOR_RANGE{
|
srv := _D3D12_DESCRIPTOR_RANGE{
|
||||||
RangeType: _D3D12_DESCRIPTOR_RANGE_TYPE_SRV, // t0
|
RangeType: _D3D12_DESCRIPTOR_RANGE_TYPE_SRV, // t0
|
||||||
NumDescriptors: graphics.ShaderImageNum,
|
NumDescriptors: graphics.ShaderImageCount,
|
||||||
BaseShaderRegister: 0,
|
BaseShaderRegister: 0,
|
||||||
RegisterSpace: 0,
|
RegisterSpace: 0,
|
||||||
OffsetInDescriptorsFromTableStart: _D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND,
|
OffsetInDescriptorsFromTableStart: _D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND,
|
||||||
|
@ -59,7 +59,7 @@ type Graphics interface {
|
|||||||
NewShader(program *shaderir.Program) (Shader, error)
|
NewShader(program *shaderir.Program) (Shader, error)
|
||||||
|
|
||||||
// DrawTriangles draws an image onto another image with the given parameters.
|
// DrawTriangles draws an image onto another image with the given parameters.
|
||||||
DrawTriangles(dst ImageID, srcs [graphics.ShaderImageNum]ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader ShaderID, indexLen int, indexOffset int, mode CompositeMode, colorM ColorM, filter Filter, address Address, dstRegion, srcRegion Region, uniforms [][]float32, evenOdd bool) error
|
DrawTriangles(dst ImageID, srcs [graphics.ShaderImageCount]ImageID, offsets [graphics.ShaderImageCount - 1][2]float32, shader ShaderID, indexLen int, indexOffset int, mode CompositeMode, colorM ColorM, filter Filter, address Address, dstRegion, srcRegion Region, uniforms [][]float32, evenOdd bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost.
|
// GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost.
|
||||||
|
@ -792,7 +792,7 @@ func (g *Graphics) flushRenderCommandEncoderIfNeeded() {
|
|||||||
g.lastDst = nil
|
g.lastDst = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion graphicsdriver.Region, srcs [graphics.ShaderImageNum]*Image, indexLen int, indexOffset int, uniforms [][]float32, stencilMode stencilMode) error {
|
func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion graphicsdriver.Region, srcs [graphics.ShaderImageCount]*Image, indexLen int, indexOffset int, uniforms [][]float32, stencilMode stencilMode) error {
|
||||||
// When prepareing a stencil buffer, flush the current render command encoder
|
// When prepareing a stencil buffer, flush the current render command encoder
|
||||||
// to make sure the stencil buffer is cleared when loading.
|
// to make sure the stencil buffer is cleared when loading.
|
||||||
// TODO: What about clearing the stencil buffer by vertices?
|
// TODO: What about clearing the stencil buffer by vertices?
|
||||||
@ -874,14 +874,14 @@ func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion graph
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.ShaderImageNum]graphicsdriver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms [][]float32, evenOdd bool) error {
|
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.ShaderImageCount]graphicsdriver.ImageID, offsets [graphics.ShaderImageCount - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms [][]float32, evenOdd bool) error {
|
||||||
dst := g.images[dstID]
|
dst := g.images[dstID]
|
||||||
|
|
||||||
if dst.screen {
|
if dst.screen {
|
||||||
g.view.update()
|
g.view.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
var srcs [graphics.ShaderImageNum]*Image
|
var srcs [graphics.ShaderImageCount]*Image
|
||||||
for i, srcID := range srcIDs {
|
for i, srcID := range srcIDs {
|
||||||
srcs[i] = g.images[srcID]
|
srcs[i] = g.images[srcID]
|
||||||
}
|
}
|
||||||
@ -948,7 +948,7 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uniformVars = make([][]float32, graphics.PreservedUniformVariablesNum+len(uniforms))
|
uniformVars = make([][]float32, graphics.PreservedUniformVariablesCount+len(uniforms))
|
||||||
|
|
||||||
// Set the destination texture size.
|
// Set the destination texture size.
|
||||||
dw, dh := dst.internalSize()
|
dw, dh := dst.internalSize()
|
||||||
@ -998,7 +998,7 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.
|
|||||||
|
|
||||||
// Set the additional uniform variables.
|
// Set the additional uniform variables.
|
||||||
for i, v := range uniforms {
|
for i, v := range uniforms {
|
||||||
const offset = graphics.PreservedUniformVariablesNum
|
const offset = graphics.PreservedUniformVariablesCount
|
||||||
t := g.shaders[shaderID].ir.Uniforms[offset+i]
|
t := g.shaders[shaderID].ir.Uniforms[offset+i]
|
||||||
switch t.Main {
|
switch t.Main {
|
||||||
case shaderir.Mat3:
|
case shaderir.Mat3:
|
||||||
|
@ -180,7 +180,7 @@ func (g *Graphics) uniformVariableName(idx int) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.ShaderImageNum]graphicsdriver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms [][]float32, evenOdd bool) error {
|
func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.ShaderImageCount]graphicsdriver.ImageID, offsets [graphics.ShaderImageCount - 1][2]float32, shaderID graphicsdriver.ShaderID, indexLen int, indexOffset int, mode graphicsdriver.CompositeMode, colorM graphicsdriver.ColorM, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, uniforms [][]float32, evenOdd bool) error {
|
||||||
destination := g.images[dstID]
|
destination := g.images[dstID]
|
||||||
|
|
||||||
g.drawCalled = true
|
g.drawCalled = true
|
||||||
@ -257,7 +257,7 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.
|
|||||||
shader := g.shaders[shaderID]
|
shader := g.shaders[shaderID]
|
||||||
program = shader.p
|
program = shader.p
|
||||||
|
|
||||||
ulen := graphics.PreservedUniformVariablesNum + len(uniforms)
|
ulen := graphics.PreservedUniformVariablesCount + len(uniforms)
|
||||||
if cap(g.uniformVars) < ulen {
|
if cap(g.uniformVars) < ulen {
|
||||||
g.uniformVars = make([]uniformVariable, ulen)
|
g.uniformVars = make([]uniformVariable, ulen)
|
||||||
} else {
|
} else {
|
||||||
@ -339,14 +339,14 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcIDs [graphics.
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, v := range uniforms {
|
for i, v := range uniforms {
|
||||||
const offset = graphics.PreservedUniformVariablesNum
|
const offset = graphics.PreservedUniformVariablesCount
|
||||||
g.uniformVars[i+offset].name = g.uniformVariableName(i + offset)
|
g.uniformVars[i+offset].name = g.uniformVariableName(i + offset)
|
||||||
g.uniformVars[i+offset].value = v
|
g.uniformVars[i+offset].value = v
|
||||||
g.uniformVars[i+offset].typ = shader.ir.Uniforms[i+offset]
|
g.uniformVars[i+offset].typ = shader.ir.Uniforms[i+offset]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var imgs [graphics.ShaderImageNum]textureVariable
|
var imgs [graphics.ShaderImageCount]textureVariable
|
||||||
for i, srcID := range srcIDs {
|
for i, srcID := range srcIDs {
|
||||||
if srcID == graphicsdriver.InvalidImageID {
|
if srcID == graphicsdriver.InvalidImageID {
|
||||||
continue
|
continue
|
||||||
|
@ -64,7 +64,7 @@ func (a *arrayBufferLayout) totalBytes() int {
|
|||||||
|
|
||||||
// newArrayBuffer creates OpenGL's buffer object for the array buffer.
|
// newArrayBuffer creates OpenGL's buffer object for the array buffer.
|
||||||
func (a *arrayBufferLayout) newArrayBuffer(context *context) buffer {
|
func (a *arrayBufferLayout) newArrayBuffer(context *context) buffer {
|
||||||
return context.newArrayBuffer(a.totalBytes() * graphics.IndicesNum)
|
return context.newArrayBuffer(a.totalBytes() * graphics.IndicesCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable starts using the array buffer.
|
// enable starts using the array buffer.
|
||||||
@ -108,9 +108,9 @@ var theArrayBufferLayout = arrayBufferLayout{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
vertexFloatNum := theArrayBufferLayout.totalBytes() / floatSizeInBytes
|
vertexFloatCount := theArrayBufferLayout.totalBytes() / floatSizeInBytes
|
||||||
if graphics.VertexFloatNum != vertexFloatNum {
|
if graphics.VertexFloatCount != vertexFloatCount {
|
||||||
panic(fmt.Sprintf("vertex float num must be %d but %d", graphics.VertexFloatNum, vertexFloatNum))
|
panic(fmt.Sprintf("vertex float num must be %d but %d", graphics.VertexFloatCount, vertexFloatCount))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ func (s *openGLState) reset(context *context) error {
|
|||||||
// Note that the indices passed to NewElementArrayBuffer is not under GC management
|
// Note that the indices passed to NewElementArrayBuffer is not under GC management
|
||||||
// in opengl package due to unsafe-way.
|
// in opengl package due to unsafe-way.
|
||||||
// See NewElementArrayBuffer in context_mobile.go.
|
// See NewElementArrayBuffer in context_mobile.go.
|
||||||
s.elementArrayBuffer = context.newElementArrayBuffer(graphics.IndicesNum * 2)
|
s.elementArrayBuffer = context.newElementArrayBuffer(graphics.IndicesCount * 2)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ func (g *Graphics) textureVariableName(idx int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// useProgram uses the program (programTexture).
|
// useProgram uses the program (programTexture).
|
||||||
func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textures [graphics.ShaderImageNum]textureVariable) error {
|
func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textures [graphics.ShaderImageCount]textureVariable) error {
|
||||||
if !g.state.lastProgram.equal(program) {
|
if !g.state.lastProgram.equal(program) {
|
||||||
g.context.useProgram(program)
|
g.context.useProgram(program)
|
||||||
if g.state.lastProgram.equal(zeroProgram) {
|
if g.state.lastProgram.equal(zeroProgram) {
|
||||||
|
@ -58,7 +58,7 @@ func (m *Mipmap) At(graphicsDriver graphicsdriver.Graphics, x, y int) (r, g, b,
|
|||||||
return m.orig.At(graphicsDriver, x, y)
|
return m.orig.At(graphicsDriver, x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageNum]*Mipmap, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, canSkipMipmap bool) {
|
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageCount]*Mipmap, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, canSkipMipmap bool) {
|
||||||
if len(indices) == 0 {
|
if len(indices) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageNum]*Mipmap, vertices [
|
|||||||
if !canSkipMipmap && srcs[0] != nil && !srcs[0].volatile && filter != graphicsdriver.FilterScreen {
|
if !canSkipMipmap && srcs[0] != nil && !srcs[0].volatile && filter != graphicsdriver.FilterScreen {
|
||||||
level = math.MaxInt32
|
level = math.MaxInt32
|
||||||
for i := 0; i < len(indices)/3; i++ {
|
for i := 0; i < len(indices)/3; i++ {
|
||||||
const n = graphics.VertexFloatNum
|
const n = graphics.VertexFloatCount
|
||||||
dx0 := vertices[n*indices[3*i]+0]
|
dx0 := vertices[n*indices[3*i]+0]
|
||||||
dy0 := vertices[n*indices[3*i]+1]
|
dy0 := vertices[n*indices[3*i]+1]
|
||||||
sx0 := vertices[n*indices[3*i]+2]
|
sx0 := vertices[n*indices[3*i]+2]
|
||||||
@ -101,14 +101,14 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageNum]*Mipmap, vertices [
|
|||||||
s = shader.shader
|
s = shader.shader
|
||||||
}
|
}
|
||||||
|
|
||||||
var imgs [graphics.ShaderImageNum]*buffered.Image
|
var imgs [graphics.ShaderImageCount]*buffered.Image
|
||||||
for i, src := range srcs {
|
for i, src := range srcs {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if level != 0 {
|
if level != 0 {
|
||||||
if img := src.level(level); img != nil {
|
if img := src.level(level); img != nil {
|
||||||
const n = graphics.VertexFloatNum
|
const n = graphics.VertexFloatCount
|
||||||
s := float32(pow2(level))
|
s := float32(pow2(level))
|
||||||
for i := 0; i < len(vertices)/n; i++ {
|
for i := 0; i < len(vertices)/n; i++ {
|
||||||
vertices[i*n+2] /= s
|
vertices[i*n+2] /= s
|
||||||
@ -189,7 +189,7 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
|||||||
Width: float32(w2),
|
Width: float32(w2),
|
||||||
Height: float32(h2),
|
Height: float32(h2),
|
||||||
}
|
}
|
||||||
s.DrawTriangles([graphics.ShaderImageNum]*buffered.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, filter, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false)
|
s.DrawTriangles([graphics.ShaderImageCount]*buffered.Image{src}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, filter, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false)
|
||||||
m.setImg(level, s)
|
m.setImg(level, s)
|
||||||
|
|
||||||
return m.imgs[level]
|
return m.imgs[level]
|
||||||
|
@ -65,8 +65,8 @@ func (p *Pixels) At(i, j int) (byte, byte, byte, byte) {
|
|||||||
|
|
||||||
// drawTrianglesHistoryItem is an item for history of draw-image commands.
|
// drawTrianglesHistoryItem is an item for history of draw-image commands.
|
||||||
type drawTrianglesHistoryItem struct {
|
type drawTrianglesHistoryItem struct {
|
||||||
images [graphics.ShaderImageNum]*Image
|
images [graphics.ShaderImageCount]*Image
|
||||||
offsets [graphics.ShaderImageNum - 1][2]float32
|
offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
vertices []float32
|
vertices []float32
|
||||||
indices []uint16
|
indices []uint16
|
||||||
colorm affine.ColorM
|
colorm affine.ColorM
|
||||||
@ -188,8 +188,8 @@ func (i *Image) Extend(width, height int) *Image {
|
|||||||
|
|
||||||
// Use DrawTriangles instead of ReplacePixels because the image i might be stale and not have its pixels
|
// Use DrawTriangles instead of ReplacePixels because the image i might be stale and not have its pixels
|
||||||
// information.
|
// information.
|
||||||
srcs := [graphics.ShaderImageNum]*Image{i}
|
srcs := [graphics.ShaderImageCount]*Image{i}
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
sw, sh := i.image.InternalSize()
|
sw, sh := i.image.InternalSize()
|
||||||
vs := quadVertices(i, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
vs := quadVertices(i, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
@ -237,8 +237,8 @@ func clearImage(i *graphicscommand.Image) {
|
|||||||
sw, sh := emptyImage.width, emptyImage.height
|
sw, sh := emptyImage.width, emptyImage.height
|
||||||
vs := quadVertices(emptyImage, 0, 0, float32(dw), float32(dh), 1, 1, float32(sw-1), float32(sh-1), 0, 0, 0, 0)
|
vs := quadVertices(emptyImage, 0, 0, float32(dw), float32(dh), 1, 1, float32(sw-1), float32(sh-1), 0, 0, 0, 0)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
srcs := [graphics.ShaderImageNum]*graphicscommand.Image{emptyImage.image}
|
srcs := [graphics.ShaderImageCount]*graphicscommand.Image{emptyImage.image}
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
dstRegion := graphicsdriver.Region{
|
dstRegion := graphicsdriver.Region{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: 0,
|
Y: 0,
|
||||||
@ -352,7 +352,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
|||||||
// 5: Color G
|
// 5: Color G
|
||||||
// 6: Color B
|
// 6: Color B
|
||||||
// 7: Color Y
|
// 7: Color Y
|
||||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
||||||
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")
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
|
|||||||
}
|
}
|
||||||
|
|
||||||
var s *graphicscommand.Shader
|
var s *graphicscommand.Shader
|
||||||
var imgs [graphics.ShaderImageNum]*graphicscommand.Image
|
var imgs [graphics.ShaderImageCount]*graphicscommand.Image
|
||||||
if shader == nil {
|
if shader == nil {
|
||||||
// Fast path for rendering without a shader (#1355).
|
// Fast path for rendering without a shader (#1355).
|
||||||
imgs[0] = srcs[0].image
|
imgs[0] = srcs[0].image
|
||||||
@ -397,7 +397,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
|
|||||||
}
|
}
|
||||||
|
|
||||||
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
||||||
func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
||||||
if i.stale || !i.needsRestoring() {
|
if i.stale || !i.needsRestoring() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -596,7 +596,7 @@ func (i *Image) restore(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
s = c.shader.shader
|
s = c.shader.shader
|
||||||
}
|
}
|
||||||
|
|
||||||
var imgs [graphics.ShaderImageNum]*graphicscommand.Image
|
var imgs [graphics.ShaderImageCount]*graphicscommand.Image
|
||||||
for i, img := range c.images {
|
for i, img := range c.images {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
continue
|
continue
|
||||||
|
@ -145,7 +145,7 @@ func TestRestoreChain(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
imgs[i+1].DrawTriangles([graphics.ShaderImageCount]*restorable.Image{imgs[i]}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -193,10 +193,10 @@ func TestRestoreChain2(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
imgs[8].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[7]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(imgs[7], w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
imgs[8].DrawTriangles([graphics.ShaderImageCount]*restorable.Image{imgs[7]}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(imgs[7], w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
imgs[9].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[8]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(imgs[8], w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
imgs[9].DrawTriangles([graphics.ShaderImageCount]*restorable.Image{imgs[8]}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(imgs[8], w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
for i := 0; i < 7; i++ {
|
for i := 0; i < 7; i++ {
|
||||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(imgs[i], w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
imgs[i+1].DrawTriangles([graphics.ShaderImageCount]*restorable.Image{imgs[i]}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(imgs[i], w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
@ -242,10 +242,10 @@ func TestRestoreOverrideSource(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
img2.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(img1, w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img2.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img1}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(img1, w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(img2, w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img3.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img2}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(img2, w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
img0.ReplacePixels([]byte{clr1.R, clr1.G, clr1.B, clr1.A}, 0, 0, w, h)
|
img0.ReplacePixels([]byte{clr1.R, clr1.G, clr1.B, clr1.A}, 0, 0, w, h)
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(img0, w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img0}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(img0, w, h, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -329,25 +329,25 @@ func TestRestoreComplexGraph(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
vs := quadVertices(img0, w, h, 0, 0)
|
vs := quadVertices(img0, w, h, 0, 0)
|
||||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img3.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img0}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img1, w, h, 1, 0)
|
vs = quadVertices(img1, w, h, 1, 0)
|
||||||
img3.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img3.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img1, w, h, 1, 0)
|
vs = quadVertices(img1, w, h, 1, 0)
|
||||||
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img1}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img2, w, h, 2, 0)
|
vs = quadVertices(img2, w, h, 2, 0)
|
||||||
img4.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img4.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img3, w, h, 0, 0)
|
vs = quadVertices(img3, w, h, 0, 0)
|
||||||
img5.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img5.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img3, w, h, 0, 0)
|
vs = quadVertices(img3, w, h, 0, 0)
|
||||||
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img6.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img4, w, h, 1, 0)
|
vs = quadVertices(img4, w, h, 1, 0)
|
||||||
img6.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img4}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img6.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img4}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img2, w, h, 0, 0)
|
vs = quadVertices(img2, w, h, 0, 0)
|
||||||
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img7.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img2}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
vs = quadVertices(img3, w, h, 2, 0)
|
vs = quadVertices(img3, w, h, 2, 0)
|
||||||
img7.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img7.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img3}, offsets, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -445,8 +445,8 @@ func TestRestoreRecursive(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(img0, w, h, 1, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img0}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(img0, w, h, 1, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(img1, w, h, 1, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img1}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(img1, w, h, 1, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -546,7 +546,7 @@ func TestDrawTrianglesAndReplacePixels(t *testing.T) {
|
|||||||
Width: 2,
|
Width: 2,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img0}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0, 0, 2, 1)
|
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0, 0, 2, 1)
|
||||||
|
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
@ -589,8 +589,8 @@ func TestDispose(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img2}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(img2, 1, 1, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img2}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(img2, 1, 1, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
img0.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img1}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(img1, 1, 1, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img0.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img1}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(img1, 1, 1, 0, 0), is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
img1.Dispose()
|
img1.Dispose()
|
||||||
|
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
@ -704,7 +704,7 @@ func TestReplacePixelsOnly(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img1.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{img0}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img1.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{img0}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
img0.ReplacePixels([]byte{5, 6, 7, 8}, 0, 0, 1, 1)
|
img0.ReplacePixels([]byte{5, 6, 7, 8}, 0, 0, 1, 1)
|
||||||
|
|
||||||
// BasePixelsForTesting is available without GPU accessing.
|
// BasePixelsForTesting is available without GPU accessing.
|
||||||
@ -763,7 +763,7 @@ func TestReadPixelsFromVolatileImage(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
|
|
||||||
// Read the pixels. If the implementation is correct, dst tries to read its pixels from GPU due to being
|
// Read the pixels. If the implementation is correct, dst tries to read its pixels from GPU due to being
|
||||||
// stale.
|
// stale.
|
||||||
@ -790,7 +790,7 @@ func TestAllowReplacePixelsAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
||||||
// ReplacePixels for a whole image doesn't panic.
|
// ReplacePixels for a whole image doesn't panic.
|
||||||
}
|
}
|
||||||
@ -814,7 +814,7 @@ func TestDisallowReplacePixelsForPartAfterDrawTriangles(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,7 +891,7 @@ func TestMutateSlices(t *testing.T) {
|
|||||||
Width: w,
|
Width: w,
|
||||||
Height: h,
|
Height: h,
|
||||||
}
|
}
|
||||||
dst.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{src}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
dst.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
for i := range vs {
|
for i := range vs {
|
||||||
vs[i] = 0
|
vs[i] = 0
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func clearImage(img *restorable.Image, w, h int) {
|
|||||||
Width: float32(w),
|
Width: float32(w),
|
||||||
Height: float32(h),
|
Height: float32(h),
|
||||||
}
|
}
|
||||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{emptyImage}, [graphics.ShaderImageNum - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
img.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{emptyImage}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeClear, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShader(t *testing.T) {
|
func TestShader(t *testing.T) {
|
||||||
@ -65,7 +65,7 @@ func TestShader(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(nil, 1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
img.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(nil, 1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||||
|
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -100,7 +100,7 @@ func TestShaderChain(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
imgs[i+1].DrawTriangles([graphics.ShaderImageNum]*restorable.Image{imgs[i]}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(imgs[i], 1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
imgs[i+1].DrawTriangles([graphics.ShaderImageCount]*restorable.Image{imgs[i]}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(imgs[i], 1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
@ -120,7 +120,7 @@ func TestShaderChain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShaderMultipleSources(t *testing.T) {
|
func TestShaderMultipleSources(t *testing.T) {
|
||||||
var srcs [graphics.ShaderImageNum]*restorable.Image
|
var srcs [graphics.ShaderImageCount]*restorable.Image
|
||||||
for i := range srcs {
|
for i := range srcs {
|
||||||
srcs[i] = restorable.NewImage(1, 1, restorable.ImageTypeRegular)
|
srcs[i] = restorable.NewImage(1, 1, restorable.ImageTypeRegular)
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func TestShaderMultipleSources(t *testing.T) {
|
|||||||
dst := restorable.NewImage(1, 1, restorable.ImageTypeRegular)
|
dst := restorable.NewImage(1, 1, restorable.ImageTypeRegular)
|
||||||
|
|
||||||
s := restorable.NewShader(etesting.ShaderProgramImages(3))
|
s := restorable.NewShader(etesting.ShaderProgramImages(3))
|
||||||
var offsets [graphics.ShaderImageNum - 1][2]float32
|
var offsets [graphics.ShaderImageCount - 1][2]float32
|
||||||
dr := graphicsdriver.Region{
|
dr := graphicsdriver.Region{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: 0,
|
Y: 0,
|
||||||
@ -164,12 +164,12 @@ func TestShaderMultipleSourcesOnOneTexture(t *testing.T) {
|
|||||||
0, 0x80, 0, 0xff,
|
0, 0x80, 0, 0xff,
|
||||||
0, 0, 0xc0, 0xff,
|
0, 0, 0xc0, 0xff,
|
||||||
}, 0, 0, 3, 1)
|
}, 0, 0, 3, 1)
|
||||||
srcs := [graphics.ShaderImageNum]*restorable.Image{src, src, src}
|
srcs := [graphics.ShaderImageCount]*restorable.Image{src, src, src}
|
||||||
|
|
||||||
dst := restorable.NewImage(1, 1, restorable.ImageTypeRegular)
|
dst := restorable.NewImage(1, 1, restorable.ImageTypeRegular)
|
||||||
|
|
||||||
s := restorable.NewShader(etesting.ShaderProgramImages(3))
|
s := restorable.NewShader(etesting.ShaderProgramImages(3))
|
||||||
offsets := [graphics.ShaderImageNum - 1][2]float32{
|
offsets := [graphics.ShaderImageCount - 1][2]float32{
|
||||||
{1, 0},
|
{1, 0},
|
||||||
{2, 0},
|
{2, 0},
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ func TestShaderDispose(t *testing.T) {
|
|||||||
Width: 1,
|
Width: 1,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
}
|
}
|
||||||
img.DrawTriangles([graphics.ShaderImageNum]*restorable.Image{}, [graphics.ShaderImageNum - 1][2]float32{}, quadVertices(nil, 1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
img.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{}, [graphics.ShaderImageCount - 1][2]float32{}, quadVertices(nil, 1, 1, 0, 0), graphics.QuadIndices(), nil, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, s, nil, false)
|
||||||
|
|
||||||
// Dispose the shader. This should invalidates all the images using this shader i.e., all the images become
|
// Dispose the shader. This should invalidates all the images using this shader i.e., all the images become
|
||||||
// stale.
|
// stale.
|
||||||
|
@ -212,8 +212,8 @@ func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics) {
|
|||||||
1, 1, 1, 1)
|
1, 1, 1, 1)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
|
|
||||||
srcs := [graphics.ShaderImageNum]*Image{c.offscreen}
|
srcs := [graphics.ShaderImageCount]*Image{c.offscreen}
|
||||||
c.screen.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, filter, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
c.screen.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, filter, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) {
|
func (c *context) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) {
|
||||||
|
@ -54,8 +54,8 @@ func (i *Image) MarkDisposed() {
|
|||||||
i.mipmap = nil
|
i.mipmap = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageNum - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, canSkipMipmap bool) {
|
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, canSkipMipmap bool) {
|
||||||
var srcMipmaps [graphics.ShaderImageNum]*mipmap.Mipmap
|
var srcMipmaps [graphics.ShaderImageCount]*mipmap.Mipmap
|
||||||
for i, src := range srcs {
|
for i, src := range srcs {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
continue
|
continue
|
||||||
@ -131,7 +131,7 @@ func (i *Image) Fill(r, g, b, a float32, x, y, width, height int) {
|
|||||||
r, g, b, a)
|
r, g, b, a)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
|
|
||||||
srcs := [graphics.ShaderImageNum]*Image{emptyImage}
|
srcs := [graphics.ShaderImageCount]*Image{emptyImage}
|
||||||
|
|
||||||
i.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
|
i.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nil, nil, false, true)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user