-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesh.go
More file actions
50 lines (37 loc) · 1.05 KB
/
mesh.go
File metadata and controls
50 lines (37 loc) · 1.05 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
// +build ignore
package main
import (
"github.com/adinfinit/g"
"github.com/go-gl/gl/v3.3-core/gl"
)
type Program struct {
ID uint32
VertexPositionLoc uint32
ModelPositionLoc uint32
ModelDirectionLoc uint32
}
type Mesh struct {
Program uint32
VAO uint32
VBO uint32
IBO uint32
Vertices []Vertex
Indicies []uint16
}
type Vertex struct {
Position g.Vec3
}
func (mesh *Mesh) Upload() error {
// setup instance data
gl.GenVertexArrays(1, &mesh.VAO)
gl.BindVertexArray(mesh.VAO)
gl.GenBuffers(1, &mesh.VBO)
gl.BindBuffer(gl.ARRAY_BUFFER, mesh.VBO)
gl.BufferData(gl.ARRAY_BUFFER, len(mesh.Vertices)*4, gl.Ptr(mesh.Vertices), gl.STATIC_DRAW)
meshPositionAttrib := uint32(gl.GetAttribLocation(program, gl.Str("VertexPosition\x00")))
gl.EnableVertexAttribArray(meshPositionAttrib)
gl.VertexAttribPointer(meshPositionAttrib, 3, gl.FLOAT, false, 5*4, gl.PtrOffset(0))
gl.GenBuffers(1, &mesh.IBO)
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, mesh.IBO)
gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, 2*len(mesh.Indicies), gl.Ptr(mesh.Indicies), gl.STATIC_DRAW)
}