-
Notifications
You must be signed in to change notification settings - Fork 24
/
attr.go
80 lines (74 loc) · 1.35 KB
/
attr.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package glhf
// AttrFormat defines names and types of OpenGL attributes (vertex format, uniform format, etc.).
//
// Example:
// AttrFormat{{"position", Vec2}, {"color", Vec4}, {"texCoord": Vec2}}
type AttrFormat []Attr
// Size returns the total size of all attributes of the AttrFormat.
func (af AttrFormat) Size() int {
total := 0
for _, attr := range af {
total += attr.Type.Size()
}
return total
}
// Attr represents an arbitrary OpenGL attribute, such as a vertex attribute or a shader
// uniform attribute.
type Attr struct {
Name string
Type AttrType
}
// AttrType represents the type of an OpenGL attribute.
type AttrType int
// List of all possible attribute types.
const (
Int AttrType = iota
Float
Vec2
Vec3
Vec4
Mat2
Mat23
Mat24
Mat3
Mat32
Mat34
Mat4
Mat42
Mat43
)
// Size returns the size of a type in bytes.
func (at AttrType) Size() int {
switch at {
case Int:
return 4
case Float:
return 4
case Vec2:
return 2 * 4
case Vec3:
return 3 * 4
case Vec4:
return 4 * 4
case Mat2:
return 2 * 2 * 4
case Mat23:
return 2 * 3 * 4
case Mat24:
return 2 * 4 * 4
case Mat3:
return 3 * 3 * 4
case Mat32:
return 3 * 2 * 4
case Mat34:
return 3 * 4 * 4
case Mat4:
return 4 * 4 * 4
case Mat42:
return 4 * 2 * 4
case Mat43:
return 4 * 3 * 4
default:
panic("size of vertex attribute type: invalid type")
}
}