forked from google/gxui
/
primitive_type.go
57 lines (50 loc) · 1.09 KB
/
primitive_type.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
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gl
import (
"fmt"
"reflect"
"github.com/goxjs/gl"
)
type primitiveType int
const (
ptFloat primitiveType = gl.FLOAT
ptInt primitiveType = gl.INT
ptUint primitiveType = gl.UNSIGNED_INT
ptUshort primitiveType = gl.UNSIGNED_SHORT
ptUbyte primitiveType = gl.UNSIGNED_BYTE
)
func (p primitiveType) sizeInBytes() int {
switch p {
case ptFloat:
return 4
case ptInt:
return 4
case ptUint:
return 4
case ptUshort:
return 2
case ptUbyte:
return 1
default:
panic(fmt.Errorf("Unknown primitiveType 0x%.4x", p))
}
}
func (p primitiveType) isArrayOfType(array interface{}) bool {
ty := reflect.TypeOf(array).Elem()
switch p {
case ptFloat:
return ty.Name() == "float32"
case ptInt:
return ty.Name() == "int32"
case ptUint:
return ty.Name() == "uint32"
case ptUshort:
return ty.Name() == "uint16"
case ptUbyte:
return ty.Name() == "uint8"
default:
panic(fmt.Errorf("Unknown primitiveType 0x%.4x", p))
}
}