points.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // Points represents a geometry containing only points
  12. type Points struct {
  13. Graphic // Embedded graphic
  14. uniMVPm gls.Uniform // Model view projection matrix uniform location cache
  15. }
  16. // NewPoints creates and returns a graphic points object with the specified
  17. // geometry and material.
  18. func NewPoints(igeom geometry.IGeometry, imat material.IMaterial) *Points {
  19. p := new(Points)
  20. p.Graphic.Init(p, igeom, gls.POINTS)
  21. if imat != nil {
  22. p.AddMaterial(p, imat, 0, 0)
  23. }
  24. p.uniMVPm.Init("MVP")
  25. return p
  26. }
  27. // RenderSetup is called by the engine before rendering this graphic.
  28. func (p *Points) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {
  29. // Transfer model view projection matrix uniform
  30. mvpm := p.ModelViewProjectionMatrix()
  31. location := p.uniMVPm.Location(gs)
  32. gs.UniformMatrix4fv(location, 1, false, &mvpm[0])
  33. }