shaderdefines.go 1.4 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 gls
  5. // ShaderDefines is a store of shader defines ("#define <key> <value>").
  6. type ShaderDefines map[string]string
  7. // NewShaderDefines creates and returns a pointer to a ShaderDefines object.
  8. func NewShaderDefines() *ShaderDefines {
  9. sd := ShaderDefines(make(map[string]string))
  10. return &sd
  11. }
  12. // Set sets a shader define with the specified value.
  13. func (sd *ShaderDefines) Set(name, value string) {
  14. (*sd)[name] = value
  15. }
  16. // Unset removes the specified name from the shader defines.
  17. func (sd *ShaderDefines) Unset(name string) {
  18. delete(*sd, name)
  19. }
  20. // Add adds to this ShaderDefines all the key-value pairs in the specified ShaderDefines.
  21. func (sd *ShaderDefines) Add(other *ShaderDefines) {
  22. for k, v := range map[string]string(*other){
  23. (*sd)[k] = v
  24. }
  25. }
  26. // Equals compares two ShaderDefines and return true if they contain the same key-value pairs.
  27. func (sd *ShaderDefines) Equals(other *ShaderDefines) bool {
  28. if sd == nil && other == nil {
  29. return true
  30. }
  31. if sd != nil && other != nil {
  32. if len(*sd) != len(*other) {
  33. return false
  34. }
  35. for k := range map[string]string(*sd) {
  36. v1, ok1 := (*sd)[k]
  37. v2, ok2 := (*other)[k]
  38. if v1 != v2 || ok1 != ok2 {
  39. return false
  40. }
  41. }
  42. return true
  43. }
  44. // One is nil and the other is not nil
  45. return false
  46. }