lines.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package graphic
  5. import (
  6. "github.com/g3n/engine/core"
  7. "github.com/g3n/engine/geometry"
  8. "github.com/g3n/engine/gls"
  9. "github.com/g3n/engine/material"
  10. )
  11. // Lines is a Graphic which is rendered as a collection of independent lines.
  12. type Lines struct {
  13. Graphic // Embedded graphic object
  14. uniMVPm gls.Uniform // Model view projection matrix uniform location cache
  15. }
  16. // NewLines returns a pointer to a new Lines object.
  17. func NewLines(igeom geometry.IGeometry, imat material.IMaterial) *Lines {
  18. l := new(Lines)
  19. l.Init(igeom, imat)
  20. return l
  21. }
  22. // Init initializes the Lines object and adds the specified material.
  23. func (l *Lines) Init(igeom geometry.IGeometry, imat material.IMaterial) {
  24. l.Graphic.Init(l, igeom, gls.LINES)
  25. l.AddMaterial(l, imat, 0, 0)
  26. l.uniMVPm.Init("MVP")
  27. }
  28. // RenderSetup is called by the engine before drawing this geometry.
  29. func (l *Lines) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {
  30. // Transfer model view projection matrix uniform
  31. mvpm := l.ModelViewProjectionMatrix()
  32. location := l.uniMVPm.Location(gs)
  33. gs.UniformMatrix4fv(location, 1, false, &mvpm[0])
  34. }