point.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 material
  5. import (
  6. "unsafe"
  7. "github.com/g3n/engine/gls"
  8. "github.com/g3n/engine/math32"
  9. )
  10. // Point material is normally used for single point sprites
  11. type Point struct {
  12. Standard // Embedded standard material
  13. }
  14. // NewPoint creates and returns a pointer to a new point material
  15. func NewPoint(color *math32.Color) *Point {
  16. pm := new(Point)
  17. pm.Standard.Init("point", color)
  18. // Sets uniform's initial values
  19. pm.udata.emissive = *color
  20. pm.udata.psize = 1.0
  21. pm.udata.protationZ = 0
  22. return pm
  23. }
  24. // SetEmissiveColor sets the material emissive color
  25. // The default is {0,0,0}
  26. func (pm *Point) SetEmissiveColor(color *math32.Color) {
  27. pm.udata.emissive = *color
  28. }
  29. // SetSize sets the point size
  30. func (pm *Point) SetSize(size float32) {
  31. pm.udata.psize = size
  32. }
  33. // SetRotationZ sets the point rotation around the Z axis.
  34. func (pm *Point) SetRotationZ(rot float32) {
  35. pm.udata.protationZ = rot
  36. }
  37. // RenderSetup is called by the engine before drawing the object
  38. // which uses this material
  39. func (pm *Point) RenderSetup(gs *gls.GLS) {
  40. pm.Material.RenderSetup(gs)
  41. location := pm.uni.Location(gs)
  42. gs.Uniform3fvUP(location, standardVec3Count, unsafe.Pointer(&pm.udata))
  43. }