Exemplo n.º 1
0
func (c *controlsys) Run(ctx *scene.Context) {
	var (
		ctls   controlColumn
		meshes graphics.MeshColumn
	)
	ctx.Stage(scene.DefaultStage - 1)
	ctx.Declare(&controlColumn{
		ctls:   map[scene.Ref]control{},
		meshes: map[scene.Ref]scene.Ref{},
		dirty:  map[scene.Ref]struct{}{},
	})
	ctx.Require(&ctls, &meshes)
	for ctx.Step() {
		dirty := make([]scene.Ref, len(ctls.dirty))
		for ref := range ctls.dirty {
			ctl := ctls.ctls[ref]
			meshref := ctls.meshes[ref]
			if meshref == 0 {
				meshref = ctx.Alloc(&meshes)
				gfx.DefaultVertexAttributes[gfx.VertexPosition] = "Position"
				gfx.DefaultVertexAttributes[gfx.VertexColor] = "Color"
				gfx.DefaultVertexAttributes[gfx.VertexTexcoord] = "UV"
				// diffuse = white texture
				// color = white, but by default i guess?
				meshes.Add(meshref, graphics.Mesh{
					G: graphics.Geometry{geometry.NewBuilder(gfx.DefaultVertexAttributes.Format())},
					M: graphics.M().Diffuse(0),
				})
				ctls.meshes[ref] = meshref
			}
			g := meshes.ModifyGeom(meshref)
			buildRect(g, ctl.Rect)
			dirty = append(dirty, ref)
		}
		for _, ref := range dirty {
			delete(ctls.dirty, ref)
		}
	}
}