points.go 1.4 KB

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