From 589becbcdb11ae91d82ed852fcc2ad3ed8d27680 Mon Sep 17 00:00:00 2001 From: faiface Date: Fri, 24 Feb 2017 14:25:35 +0100 Subject: [PATCH] fix a bug + doc --- batch.go | 10 +++++++++- interface.go | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/batch.go b/batch.go index 05c1adf..34fc0ea 100644 --- a/batch.go +++ b/batch.go @@ -1,6 +1,7 @@ package pixel import ( + "fmt" "image/color" "math" @@ -75,6 +76,7 @@ func (b *Batch) MakeTriangles(t Triangles) TargetTriangles { func (b *Batch) MakePicture(p Picture) TargetPicture { return &batchPicture{ Picture: p, + b: b, } } @@ -113,6 +115,8 @@ func (bt *batchTriangles) Draw() { type batchPicture struct { Picture + + b *Batch } func (bp *batchPicture) Slice(r Rect) Picture { @@ -122,5 +126,9 @@ func (bp *batchPicture) Slice(r Rect) Picture { } func (bp *batchPicture) Draw(t TargetTriangles) { - t.(*batchTriangles).draw(bp) + bt := t.(*batchTriangles) + if bp.b != bt.b { + panic(fmt.Sprintf("%T.Draw: TargetTriangles generated by different Batch", bp)) + } + bt.draw(bp) } diff --git a/interface.go b/interface.go index 18dfe91..e41397d 100644 --- a/interface.go +++ b/interface.go @@ -19,7 +19,11 @@ type Target interface { // present) when making new TargetTriangles. This varies from Target to Target. MakeTriangles(Triangles) TargetTriangles - //TODO: doc + // MakePicture generates a specialized copy of the provided Picture. + // + // When calling Draw method on the returned TargetPicture, the TargetPicture will be drawn + // onto the Target that generated it together with the TargetTriangles supplied to the Draw + // method. MakePicture(Picture) TargetPicture } @@ -116,6 +120,9 @@ type Picture interface { type TargetPicture interface { Picture + // Draw draws the supplied TargetTriangles (which must be generated by the same Target as + // this TargetPicture) with this TargetPicture. The TargetTriangles should utilize the data + // from this TargetPicture in some way. Draw(TargetTriangles) }