Exemple #1
0
func (s *System) init(ctx *scene.Context) {
	s.cmds = make(chan func(), 4)
	go glthread(s.Context, s.cmds)
	s.cmds <- s.glsetup
	s.stepmu.Lock()
	ctx.Stage(scene.OutputStage)
	ctx.Declare(meshCol())
	ctx.Require(&s.meshes)
	s.buckets = make([]renderList, numBuckets)
}
Exemple #2
0
func (s *System) Run(ctx *scene.Context) {
	ctx.Stage(scene.LayoutStage)
	ctx.Declare(meshCol())
	var (
		meshes MeshColumn
	)
	ctx.Require(&meshes)

	for ctx.Step() {
	}
}
Exemple #3
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)
		}
	}
}