mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/restorable: integrate Image.DrawTriangles into internal/atlas
Updates #805
This commit is contained in:
parent
bfa2c460a2
commit
3ee905bc4d
@ -343,6 +343,10 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) {
|
func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) {
|
||||||
|
if len(vertices) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
backends := make([]*backend, 0, len(srcs))
|
backends := make([]*backend, 0, len(srcs))
|
||||||
for _, src := range srcs {
|
for _, src := range srcs {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
@ -415,15 +419,15 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
|
|||||||
srcRegions[i] = srcRegions[i].Add(r.Min)
|
srcRegions[i] = srcRegions[i].Add(r.Min)
|
||||||
}
|
}
|
||||||
|
|
||||||
var imgs [graphics.ShaderImageCount]*restorable.Image
|
var imgs [graphics.ShaderImageCount]*graphicscommand.Image
|
||||||
for i, src := range srcs {
|
for i, src := range srcs {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
imgs[i] = src.backend.restorable
|
imgs[i] = src.backend.restorable.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
i.backend.restorable.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.ensureShader(), uniforms, fillRule)
|
i.backend.restorable.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.ensureShader().Shader, uniforms, fillRule)
|
||||||
|
|
||||||
for _, src := range srcs {
|
for _, src := range srcs {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
|
@ -66,12 +66,12 @@ func (i *Image) Extend(width, height int) *Image {
|
|||||||
|
|
||||||
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
|
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
|
||||||
// information.
|
// information.
|
||||||
srcs := [graphics.ShaderImageCount]*Image{i}
|
srcs := [graphics.ShaderImageCount]*graphicscommand.Image{i.Image}
|
||||||
sw, sh := i.Image.InternalSize()
|
sw, sh := i.Image.InternalSize()
|
||||||
vs := quadVertices(0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
vs := quadVertices(0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
dr := image.Rect(0, 0, sw, sh)
|
dr := image.Rect(0, 0, sw, sh)
|
||||||
newImg.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderImageCount]image.Rectangle{}, NearestFilterShader, nil, graphicsdriver.FillAll)
|
newImg.Image.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderImageCount]image.Rectangle{}, NearestFilterShader.Shader, nil, graphicsdriver.FillAll)
|
||||||
i.Image.Dispose()
|
i.Image.Dispose()
|
||||||
i.Image = nil
|
i.Image = nil
|
||||||
|
|
||||||
@ -116,30 +116,3 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl
|
|||||||
|
|
||||||
i.Image.WritePixels(pixels, region)
|
i.Image.WritePixels(pixels, region)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawTriangles draws triangles with the given image.
|
|
||||||
//
|
|
||||||
// The vertex floats are:
|
|
||||||
//
|
|
||||||
// 0: Destination X in pixels
|
|
||||||
// 1: Destination Y in pixels
|
|
||||||
// 2: Source X in texels
|
|
||||||
// 3: Source Y in texels
|
|
||||||
// 4: Color R [0.0-1.0]
|
|
||||||
// 5: Color G
|
|
||||||
// 6: Color B
|
|
||||||
// 7: Color Y
|
|
||||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) {
|
|
||||||
if len(vertices) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var imgs [graphics.ShaderImageCount]*graphicscommand.Image
|
|
||||||
for i, src := range srcs {
|
|
||||||
if src == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
imgs[i] = src.Image
|
|
||||||
}
|
|
||||||
i.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.Shader, uniforms, fillRule)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user