return pointers from constructors of Triangles/PictureData
This commit is contained in:
parent
69a3c17cfc
commit
c91d49dadf
18
batch.go
18
batch.go
|
@ -68,7 +68,7 @@ func (b *Batch) MakeTriangles(t Triangles) TargetTriangles {
|
||||||
b: b,
|
b: b,
|
||||||
}
|
}
|
||||||
bt.orig.Update(t)
|
bt.orig.Update(t)
|
||||||
bt.trans.Update(&bt.orig)
|
bt.trans.Update(bt.orig)
|
||||||
return bt
|
return bt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,26 +82,26 @@ func (b *Batch) MakePicture(p Picture) TargetPicture {
|
||||||
|
|
||||||
type batchTriangles struct {
|
type batchTriangles struct {
|
||||||
Triangles
|
Triangles
|
||||||
orig, trans TrianglesData
|
orig, trans *TrianglesData
|
||||||
|
|
||||||
b *Batch
|
b *Batch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bt *batchTriangles) draw(bp *batchPicture) {
|
func (bt *batchTriangles) draw(bp *batchPicture) {
|
||||||
for i := range bt.trans {
|
for i := range *bt.trans {
|
||||||
transPos := bt.b.mat.Mul3x1(mgl32.Vec3{
|
transPos := bt.b.mat.Mul3x1(mgl32.Vec3{
|
||||||
float32(bt.orig[i].Position.X()),
|
float32((*bt.orig)[i].Position.X()),
|
||||||
float32(bt.orig[i].Position.Y()),
|
float32((*bt.orig)[i].Position.Y()),
|
||||||
1,
|
1,
|
||||||
})
|
})
|
||||||
bt.trans[i].Position = V(float64(transPos.X()), float64(transPos.Y()))
|
(*bt.trans)[i].Position = V(float64(transPos.X()), float64(transPos.Y()))
|
||||||
bt.trans[i].Color = bt.orig[i].Color.Mul(bt.b.col)
|
(*bt.trans)[i].Color = (*bt.orig)[i].Color.Mul(bt.b.col)
|
||||||
if bp == nil {
|
if bp == nil {
|
||||||
bt.trans[i].Picture = V(math.Inf(+1), math.Inf(+1))
|
(*bt.trans)[i].Picture = V(math.Inf(+1), math.Inf(+1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bt.Triangles.Update(&bt.trans)
|
bt.Triangles.Update(bt.trans)
|
||||||
|
|
||||||
cont := bt.b.cont.Triangles
|
cont := bt.b.cont.Triangles
|
||||||
cont.SetLen(cont.Len() + bt.Triangles.Len())
|
cont.SetLen(cont.Len() + bt.Triangles.Len())
|
||||||
|
|
14
data.go
14
data.go
|
@ -21,8 +21,8 @@ type TrianglesData []struct {
|
||||||
//
|
//
|
||||||
// Prefer this function to make(TrianglesData, len), because make zeros them, while this function
|
// Prefer this function to make(TrianglesData, len), because make zeros them, while this function
|
||||||
// does a correct intialization.
|
// does a correct intialization.
|
||||||
func MakeTrianglesData(len int) TrianglesData {
|
func MakeTrianglesData(len int) *TrianglesData {
|
||||||
td := TrianglesData{}
|
td := &TrianglesData{}
|
||||||
td.SetLen(len)
|
td.SetLen(len)
|
||||||
return td
|
return td
|
||||||
}
|
}
|
||||||
|
@ -132,10 +132,10 @@ type PictureData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakePictureData creates a zero-initialized PictureData covering the given rectangle.
|
// MakePictureData creates a zero-initialized PictureData covering the given rectangle.
|
||||||
func MakePictureData(rect Rect) PictureData {
|
func MakePictureData(rect Rect) *PictureData {
|
||||||
w := int(math.Ceil(rect.Pos.X()+rect.Size.X())) - int(math.Floor(rect.Pos.X()))
|
w := int(math.Ceil(rect.Pos.X()+rect.Size.X())) - int(math.Floor(rect.Pos.X()))
|
||||||
h := int(math.Ceil(rect.Pos.Y()+rect.Size.Y())) - int(math.Floor(rect.Pos.Y()))
|
h := int(math.Ceil(rect.Pos.Y()+rect.Size.Y())) - int(math.Floor(rect.Pos.Y()))
|
||||||
pd := PictureData{
|
pd := &PictureData{
|
||||||
Stride: w,
|
Stride: w,
|
||||||
Rect: rect,
|
Rect: rect,
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func verticalFlip(nrgba *image.NRGBA) {
|
||||||
// PictureDataFromImage converts an image.Image into PictureData.
|
// PictureDataFromImage converts an image.Image into PictureData.
|
||||||
//
|
//
|
||||||
// The resulting PictureData's Bounds will be the equivalent of the supplied image.Image's Bounds.
|
// The resulting PictureData's Bounds will be the equivalent of the supplied image.Image's Bounds.
|
||||||
func PictureDataFromImage(img image.Image) PictureData {
|
func PictureDataFromImage(img image.Image) *PictureData {
|
||||||
var nrgba *image.NRGBA
|
var nrgba *image.NRGBA
|
||||||
if nrgbaImg, ok := img.(*image.NRGBA); ok {
|
if nrgbaImg, ok := img.(*image.NRGBA); ok {
|
||||||
nrgba = nrgbaImg
|
nrgba = nrgbaImg
|
||||||
|
@ -195,9 +195,9 @@ func PictureDataFromImage(img image.Image) PictureData {
|
||||||
// lossy, because PictureData works with unit-sized pixels).
|
// lossy, because PictureData works with unit-sized pixels).
|
||||||
//
|
//
|
||||||
// Bounds are preserved.
|
// Bounds are preserved.
|
||||||
func PictureDataFromPicture(pic Picture) PictureData {
|
func PictureDataFromPicture(pic Picture) *PictureData {
|
||||||
if pd, ok := pic.(*PictureData); ok {
|
if pd, ok := pic.(*PictureData); ok {
|
||||||
return *pd
|
return pd
|
||||||
}
|
}
|
||||||
|
|
||||||
bounds := pic.Bounds()
|
bounds := pic.Bounds()
|
||||||
|
|
Loading…
Reference in New Issue