-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_material.go
More file actions
56 lines (46 loc) · 1.18 KB
/
basic_material.go
File metadata and controls
56 lines (46 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pix
import (
"github.com/bluescreen10/pix/glm"
)
type BasicMaterial struct {
Material
}
func (m *BasicMaterial) data() *MaterialData {
return m.renderer.materials.get(m.ref.ID())
}
func (m *BasicMaterial) SetColor(color glm.Color3f) {
data := m.data()
data.uniforms[0].SetVec3("color", glm.Vec3f{color[0], color[1], color[2]})
data.version++
}
func (m *BasicMaterial) Color() glm.Color3f {
v := m.data().uniforms[0].Vec3("color")
return glm.Color3f{v[0], v[1], v[2]}
}
func (m *BasicMaterial) SetColorMap(texture Texture) {
data := m.data()
old := data.textures[0]
data.textures[0] = texture.ref.Copy()
old.Release()
if texture.ref.Valid() {
data.flags |= ColorMapFlag
} else {
data.flags &^= ColorMapFlag
}
data.version++
}
func (m *BasicMaterial) ColorMap() Ref[Texture] {
return m.data().textures[0]
}
func (m *BasicMaterial) NeedsUpdate() {
m.data().version++
}
// Ref returns a new Material handle sharing the same underlying resource.
func (m *BasicMaterial) Ref() Material {
return m.Material.Copy()
}
// Release surrenders the builder's own reference to the material resource.
func (m *BasicMaterial) Release() {
m.Material.Release()
m.Material = Material{}
}